istallion.c 119 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507
  1. /*****************************************************************************/
  2. /*
  3. * istallion.c -- stallion intelligent multiport serial driver.
  4. *
  5. * Copyright (C) 1996-1999 Stallion Technologies
  6. * Copyright (C) 1994-1996 Greg Ungerer.
  7. *
  8. * This code is loosely based on the Linux serial driver, written by
  9. * Linus Torvalds, Theodore T'so and others.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. */
  17. /*****************************************************************************/
  18. #include <linux/module.h>
  19. #include <linux/sched.h>
  20. #include <linux/slab.h>
  21. #include <linux/smp_lock.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/tty.h>
  24. #include <linux/tty_flip.h>
  25. #include <linux/serial.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/cdk.h>
  28. #include <linux/comstats.h>
  29. #include <linux/istallion.h>
  30. #include <linux/ioport.h>
  31. #include <linux/delay.h>
  32. #include <linux/init.h>
  33. #include <linux/device.h>
  34. #include <linux/wait.h>
  35. #include <linux/eisa.h>
  36. #include <linux/ctype.h>
  37. #include <asm/io.h>
  38. #include <asm/uaccess.h>
  39. #include <linux/pci.h>
  40. /*****************************************************************************/
  41. /*
  42. * Define different board types. Not all of the following board types
  43. * are supported by this driver. But I will use the standard "assigned"
  44. * board numbers. Currently supported boards are abbreviated as:
  45. * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
  46. * STAL = Stallion.
  47. */
  48. #define BRD_UNKNOWN 0
  49. #define BRD_STALLION 1
  50. #define BRD_BRUMBY4 2
  51. #define BRD_ONBOARD2 3
  52. #define BRD_ONBOARD 4
  53. #define BRD_ONBOARDE 7
  54. #define BRD_ECP 23
  55. #define BRD_ECPE 24
  56. #define BRD_ECPMC 25
  57. #define BRD_ECPPCI 29
  58. #define BRD_BRUMBY BRD_BRUMBY4
  59. /*
  60. * Define a configuration structure to hold the board configuration.
  61. * Need to set this up in the code (for now) with the boards that are
  62. * to be configured into the system. This is what needs to be modified
  63. * when adding/removing/modifying boards. Each line entry in the
  64. * stli_brdconf[] array is a board. Each line contains io/irq/memory
  65. * ranges for that board (as well as what type of board it is).
  66. * Some examples:
  67. * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
  68. * This line will configure an EasyConnection 8/64 at io address 2a0,
  69. * and shared memory address of cc000. Multiple EasyConnection 8/64
  70. * boards can share the same shared memory address space. No interrupt
  71. * is required for this board type.
  72. * Another example:
  73. * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
  74. * This line will configure an EasyConnection 8/64 EISA in slot 5 and
  75. * shared memory address of 0x80000000 (2 GByte). Multiple
  76. * EasyConnection 8/64 EISA boards can share the same shared memory
  77. * address space. No interrupt is required for this board type.
  78. * Another example:
  79. * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
  80. * This line will configure an ONboard (ISA type) at io address 240,
  81. * and shared memory address of d0000. Multiple ONboards can share
  82. * the same shared memory address space. No interrupt required.
  83. * Another example:
  84. * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
  85. * This line will configure a Brumby board (any number of ports!) at
  86. * io address 360 and shared memory address of c8000. All Brumby boards
  87. * configured into a system must have their own separate io and memory
  88. * addresses. No interrupt is required.
  89. * Another example:
  90. * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
  91. * This line will configure an original Stallion board at io address 330
  92. * and shared memory address d0000 (this would only be valid for a "V4.0"
  93. * or Rev.O Stallion board). All Stallion boards configured into the
  94. * system must have their own separate io and memory addresses. No
  95. * interrupt is required.
  96. */
  97. struct stlconf {
  98. int brdtype;
  99. int ioaddr1;
  100. int ioaddr2;
  101. unsigned long memaddr;
  102. int irq;
  103. int irqtype;
  104. };
  105. static unsigned int stli_nrbrds;
  106. /* stli_lock must NOT be taken holding brd_lock */
  107. static spinlock_t stli_lock; /* TTY logic lock */
  108. static spinlock_t brd_lock; /* Board logic lock */
  109. /*
  110. * There is some experimental EISA board detection code in this driver.
  111. * By default it is disabled, but for those that want to try it out,
  112. * then set the define below to be 1.
  113. */
  114. #define STLI_EISAPROBE 0
  115. /*****************************************************************************/
  116. /*
  117. * Define some important driver characteristics. Device major numbers
  118. * allocated as per Linux Device Registry.
  119. */
  120. #ifndef STL_SIOMEMMAJOR
  121. #define STL_SIOMEMMAJOR 28
  122. #endif
  123. #ifndef STL_SERIALMAJOR
  124. #define STL_SERIALMAJOR 24
  125. #endif
  126. #ifndef STL_CALLOUTMAJOR
  127. #define STL_CALLOUTMAJOR 25
  128. #endif
  129. /*****************************************************************************/
  130. /*
  131. * Define our local driver identity first. Set up stuff to deal with
  132. * all the local structures required by a serial tty driver.
  133. */
  134. static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
  135. static char *stli_drvname = "istallion";
  136. static char *stli_drvversion = "5.6.0";
  137. static char *stli_serialname = "ttyE";
  138. static struct tty_driver *stli_serial;
  139. static const struct tty_port_operations stli_port_ops;
  140. #define STLI_TXBUFSIZE 4096
  141. /*
  142. * Use a fast local buffer for cooked characters. Typically a whole
  143. * bunch of cooked characters come in for a port, 1 at a time. So we
  144. * save those up into a local buffer, then write out the whole lot
  145. * with a large memcpy. Just use 1 buffer for all ports, since its
  146. * use it is only need for short periods of time by each port.
  147. */
  148. static char *stli_txcookbuf;
  149. static int stli_txcooksize;
  150. static int stli_txcookrealsize;
  151. static struct tty_struct *stli_txcooktty;
  152. /*
  153. * Define a local default termios struct. All ports will be created
  154. * with this termios initially. Basically all it defines is a raw port
  155. * at 9600 baud, 8 data bits, no parity, 1 stop bit.
  156. */
  157. static struct ktermios stli_deftermios = {
  158. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  159. .c_cc = INIT_C_CC,
  160. .c_ispeed = 9600,
  161. .c_ospeed = 9600,
  162. };
  163. /*
  164. * Define global stats structures. Not used often, and can be
  165. * re-used for each stats call.
  166. */
  167. static comstats_t stli_comstats;
  168. static combrd_t stli_brdstats;
  169. static struct asystats stli_cdkstats;
  170. /*****************************************************************************/
  171. static DEFINE_MUTEX(stli_brdslock);
  172. static struct stlibrd *stli_brds[STL_MAXBRDS];
  173. static int stli_shared;
  174. /*
  175. * Per board state flags. Used with the state field of the board struct.
  176. * Not really much here... All we need to do is keep track of whether
  177. * the board has been detected, and whether it is actually running a slave
  178. * or not.
  179. */
  180. #define BST_FOUND 0
  181. #define BST_STARTED 1
  182. #define BST_PROBED 2
  183. /*
  184. * Define the set of port state flags. These are marked for internal
  185. * state purposes only, usually to do with the state of communications
  186. * with the slave. Most of them need to be updated atomically, so always
  187. * use the bit setting operations (unless protected by cli/sti).
  188. */
  189. #define ST_OPENING 2
  190. #define ST_CLOSING 3
  191. #define ST_CMDING 4
  192. #define ST_TXBUSY 5
  193. #define ST_RXING 6
  194. #define ST_DOFLUSHRX 7
  195. #define ST_DOFLUSHTX 8
  196. #define ST_DOSIGS 9
  197. #define ST_RXSTOP 10
  198. #define ST_GETSIGS 11
  199. /*
  200. * Define an array of board names as printable strings. Handy for
  201. * referencing boards when printing trace and stuff.
  202. */
  203. static char *stli_brdnames[] = {
  204. "Unknown",
  205. "Stallion",
  206. "Brumby",
  207. "ONboard-MC",
  208. "ONboard",
  209. "Brumby",
  210. "Brumby",
  211. "ONboard-EI",
  212. NULL,
  213. "ONboard",
  214. "ONboard-MC",
  215. "ONboard-MC",
  216. NULL,
  217. NULL,
  218. NULL,
  219. NULL,
  220. NULL,
  221. NULL,
  222. NULL,
  223. NULL,
  224. "EasyIO",
  225. "EC8/32-AT",
  226. "EC8/32-MC",
  227. "EC8/64-AT",
  228. "EC8/64-EI",
  229. "EC8/64-MC",
  230. "EC8/32-PCI",
  231. "EC8/64-PCI",
  232. "EasyIO-PCI",
  233. "EC/RA-PCI",
  234. };
  235. /*****************************************************************************/
  236. /*
  237. * Define some string labels for arguments passed from the module
  238. * load line. These allow for easy board definitions, and easy
  239. * modification of the io, memory and irq resoucres.
  240. */
  241. static char *board0[8];
  242. static char *board1[8];
  243. static char *board2[8];
  244. static char *board3[8];
  245. static char **stli_brdsp[] = {
  246. (char **) &board0,
  247. (char **) &board1,
  248. (char **) &board2,
  249. (char **) &board3
  250. };
  251. /*
  252. * Define a set of common board names, and types. This is used to
  253. * parse any module arguments.
  254. */
  255. static struct stlibrdtype {
  256. char *name;
  257. int type;
  258. } stli_brdstr[] = {
  259. { "stallion", BRD_STALLION },
  260. { "1", BRD_STALLION },
  261. { "brumby", BRD_BRUMBY },
  262. { "brumby4", BRD_BRUMBY },
  263. { "brumby/4", BRD_BRUMBY },
  264. { "brumby-4", BRD_BRUMBY },
  265. { "brumby8", BRD_BRUMBY },
  266. { "brumby/8", BRD_BRUMBY },
  267. { "brumby-8", BRD_BRUMBY },
  268. { "brumby16", BRD_BRUMBY },
  269. { "brumby/16", BRD_BRUMBY },
  270. { "brumby-16", BRD_BRUMBY },
  271. { "2", BRD_BRUMBY },
  272. { "onboard2", BRD_ONBOARD2 },
  273. { "onboard-2", BRD_ONBOARD2 },
  274. { "onboard/2", BRD_ONBOARD2 },
  275. { "onboard-mc", BRD_ONBOARD2 },
  276. { "onboard/mc", BRD_ONBOARD2 },
  277. { "onboard-mca", BRD_ONBOARD2 },
  278. { "onboard/mca", BRD_ONBOARD2 },
  279. { "3", BRD_ONBOARD2 },
  280. { "onboard", BRD_ONBOARD },
  281. { "onboardat", BRD_ONBOARD },
  282. { "4", BRD_ONBOARD },
  283. { "onboarde", BRD_ONBOARDE },
  284. { "onboard-e", BRD_ONBOARDE },
  285. { "onboard/e", BRD_ONBOARDE },
  286. { "onboard-ei", BRD_ONBOARDE },
  287. { "onboard/ei", BRD_ONBOARDE },
  288. { "7", BRD_ONBOARDE },
  289. { "ecp", BRD_ECP },
  290. { "ecpat", BRD_ECP },
  291. { "ec8/64", BRD_ECP },
  292. { "ec8/64-at", BRD_ECP },
  293. { "ec8/64-isa", BRD_ECP },
  294. { "23", BRD_ECP },
  295. { "ecpe", BRD_ECPE },
  296. { "ecpei", BRD_ECPE },
  297. { "ec8/64-e", BRD_ECPE },
  298. { "ec8/64-ei", BRD_ECPE },
  299. { "24", BRD_ECPE },
  300. { "ecpmc", BRD_ECPMC },
  301. { "ec8/64-mc", BRD_ECPMC },
  302. { "ec8/64-mca", BRD_ECPMC },
  303. { "25", BRD_ECPMC },
  304. { "ecppci", BRD_ECPPCI },
  305. { "ec/ra", BRD_ECPPCI },
  306. { "ec/ra-pc", BRD_ECPPCI },
  307. { "ec/ra-pci", BRD_ECPPCI },
  308. { "29", BRD_ECPPCI },
  309. };
  310. /*
  311. * Define the module agruments.
  312. */
  313. MODULE_AUTHOR("Greg Ungerer");
  314. MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
  315. MODULE_LICENSE("GPL");
  316. module_param_array(board0, charp, NULL, 0);
  317. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
  318. module_param_array(board1, charp, NULL, 0);
  319. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
  320. module_param_array(board2, charp, NULL, 0);
  321. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
  322. module_param_array(board3, charp, NULL, 0);
  323. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
  324. #if STLI_EISAPROBE != 0
  325. /*
  326. * Set up a default memory address table for EISA board probing.
  327. * The default addresses are all bellow 1Mbyte, which has to be the
  328. * case anyway. They should be safe, since we only read values from
  329. * them, and interrupts are disabled while we do it. If the higher
  330. * memory support is compiled in then we also try probing around
  331. * the 1Gb, 2Gb and 3Gb areas as well...
  332. */
  333. static unsigned long stli_eisamemprobeaddrs[] = {
  334. 0xc0000, 0xd0000, 0xe0000, 0xf0000,
  335. 0x80000000, 0x80010000, 0x80020000, 0x80030000,
  336. 0x40000000, 0x40010000, 0x40020000, 0x40030000,
  337. 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
  338. 0xff000000, 0xff010000, 0xff020000, 0xff030000,
  339. };
  340. static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
  341. #endif
  342. /*
  343. * Define the Stallion PCI vendor and device IDs.
  344. */
  345. #ifndef PCI_DEVICE_ID_ECRA
  346. #define PCI_DEVICE_ID_ECRA 0x0004
  347. #endif
  348. static struct pci_device_id istallion_pci_tbl[] = {
  349. { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
  350. { 0 }
  351. };
  352. MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
  353. static struct pci_driver stli_pcidriver;
  354. /*****************************************************************************/
  355. /*
  356. * Hardware configuration info for ECP boards. These defines apply
  357. * to the directly accessible io ports of the ECP. There is a set of
  358. * defines for each ECP board type, ISA, EISA, MCA and PCI.
  359. */
  360. #define ECP_IOSIZE 4
  361. #define ECP_MEMSIZE (128 * 1024)
  362. #define ECP_PCIMEMSIZE (256 * 1024)
  363. #define ECP_ATPAGESIZE (4 * 1024)
  364. #define ECP_MCPAGESIZE (4 * 1024)
  365. #define ECP_EIPAGESIZE (64 * 1024)
  366. #define ECP_PCIPAGESIZE (64 * 1024)
  367. #define STL_EISAID 0x8c4e
  368. /*
  369. * Important defines for the ISA class of ECP board.
  370. */
  371. #define ECP_ATIREG 0
  372. #define ECP_ATCONFR 1
  373. #define ECP_ATMEMAR 2
  374. #define ECP_ATMEMPR 3
  375. #define ECP_ATSTOP 0x1
  376. #define ECP_ATINTENAB 0x10
  377. #define ECP_ATENABLE 0x20
  378. #define ECP_ATDISABLE 0x00
  379. #define ECP_ATADDRMASK 0x3f000
  380. #define ECP_ATADDRSHFT 12
  381. /*
  382. * Important defines for the EISA class of ECP board.
  383. */
  384. #define ECP_EIIREG 0
  385. #define ECP_EIMEMARL 1
  386. #define ECP_EICONFR 2
  387. #define ECP_EIMEMARH 3
  388. #define ECP_EIENABLE 0x1
  389. #define ECP_EIDISABLE 0x0
  390. #define ECP_EISTOP 0x4
  391. #define ECP_EIEDGE 0x00
  392. #define ECP_EILEVEL 0x80
  393. #define ECP_EIADDRMASKL 0x00ff0000
  394. #define ECP_EIADDRSHFTL 16
  395. #define ECP_EIADDRMASKH 0xff000000
  396. #define ECP_EIADDRSHFTH 24
  397. #define ECP_EIBRDENAB 0xc84
  398. #define ECP_EISAID 0x4
  399. /*
  400. * Important defines for the Micro-channel class of ECP board.
  401. * (It has a lot in common with the ISA boards.)
  402. */
  403. #define ECP_MCIREG 0
  404. #define ECP_MCCONFR 1
  405. #define ECP_MCSTOP 0x20
  406. #define ECP_MCENABLE 0x80
  407. #define ECP_MCDISABLE 0x00
  408. /*
  409. * Important defines for the PCI class of ECP board.
  410. * (It has a lot in common with the other ECP boards.)
  411. */
  412. #define ECP_PCIIREG 0
  413. #define ECP_PCICONFR 1
  414. #define ECP_PCISTOP 0x01
  415. /*
  416. * Hardware configuration info for ONboard and Brumby boards. These
  417. * defines apply to the directly accessible io ports of these boards.
  418. */
  419. #define ONB_IOSIZE 16
  420. #define ONB_MEMSIZE (64 * 1024)
  421. #define ONB_ATPAGESIZE (64 * 1024)
  422. #define ONB_MCPAGESIZE (64 * 1024)
  423. #define ONB_EIMEMSIZE (128 * 1024)
  424. #define ONB_EIPAGESIZE (64 * 1024)
  425. /*
  426. * Important defines for the ISA class of ONboard board.
  427. */
  428. #define ONB_ATIREG 0
  429. #define ONB_ATMEMAR 1
  430. #define ONB_ATCONFR 2
  431. #define ONB_ATSTOP 0x4
  432. #define ONB_ATENABLE 0x01
  433. #define ONB_ATDISABLE 0x00
  434. #define ONB_ATADDRMASK 0xff0000
  435. #define ONB_ATADDRSHFT 16
  436. #define ONB_MEMENABLO 0
  437. #define ONB_MEMENABHI 0x02
  438. /*
  439. * Important defines for the EISA class of ONboard board.
  440. */
  441. #define ONB_EIIREG 0
  442. #define ONB_EIMEMARL 1
  443. #define ONB_EICONFR 2
  444. #define ONB_EIMEMARH 3
  445. #define ONB_EIENABLE 0x1
  446. #define ONB_EIDISABLE 0x0
  447. #define ONB_EISTOP 0x4
  448. #define ONB_EIEDGE 0x00
  449. #define ONB_EILEVEL 0x80
  450. #define ONB_EIADDRMASKL 0x00ff0000
  451. #define ONB_EIADDRSHFTL 16
  452. #define ONB_EIADDRMASKH 0xff000000
  453. #define ONB_EIADDRSHFTH 24
  454. #define ONB_EIBRDENAB 0xc84
  455. #define ONB_EISAID 0x1
  456. /*
  457. * Important defines for the Brumby boards. They are pretty simple,
  458. * there is not much that is programmably configurable.
  459. */
  460. #define BBY_IOSIZE 16
  461. #define BBY_MEMSIZE (64 * 1024)
  462. #define BBY_PAGESIZE (16 * 1024)
  463. #define BBY_ATIREG 0
  464. #define BBY_ATCONFR 1
  465. #define BBY_ATSTOP 0x4
  466. /*
  467. * Important defines for the Stallion boards. They are pretty simple,
  468. * there is not much that is programmably configurable.
  469. */
  470. #define STAL_IOSIZE 16
  471. #define STAL_MEMSIZE (64 * 1024)
  472. #define STAL_PAGESIZE (64 * 1024)
  473. /*
  474. * Define the set of status register values for EasyConnection panels.
  475. * The signature will return with the status value for each panel. From
  476. * this we can determine what is attached to the board - before we have
  477. * actually down loaded any code to it.
  478. */
  479. #define ECH_PNLSTATUS 2
  480. #define ECH_PNL16PORT 0x20
  481. #define ECH_PNLIDMASK 0x07
  482. #define ECH_PNLXPID 0x40
  483. #define ECH_PNLINTRPEND 0x80
  484. /*
  485. * Define some macros to do things to the board. Even those these boards
  486. * are somewhat related there is often significantly different ways of
  487. * doing some operation on it (like enable, paging, reset, etc). So each
  488. * board class has a set of functions which do the commonly required
  489. * operations. The macros below basically just call these functions,
  490. * generally checking for a NULL function - which means that the board
  491. * needs nothing done to it to achieve this operation!
  492. */
  493. #define EBRDINIT(brdp) \
  494. if (brdp->init != NULL) \
  495. (* brdp->init)(brdp)
  496. #define EBRDENABLE(brdp) \
  497. if (brdp->enable != NULL) \
  498. (* brdp->enable)(brdp);
  499. #define EBRDDISABLE(brdp) \
  500. if (brdp->disable != NULL) \
  501. (* brdp->disable)(brdp);
  502. #define EBRDINTR(brdp) \
  503. if (brdp->intr != NULL) \
  504. (* brdp->intr)(brdp);
  505. #define EBRDRESET(brdp) \
  506. if (brdp->reset != NULL) \
  507. (* brdp->reset)(brdp);
  508. #define EBRDGETMEMPTR(brdp,offset) \
  509. (* brdp->getmemptr)(brdp, offset, __LINE__)
  510. /*
  511. * Define the maximal baud rate, and the default baud base for ports.
  512. */
  513. #define STL_MAXBAUD 460800
  514. #define STL_BAUDBASE 115200
  515. #define STL_CLOSEDELAY (5 * HZ / 10)
  516. /*****************************************************************************/
  517. /*
  518. * Define macros to extract a brd or port number from a minor number.
  519. */
  520. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  521. #define MINOR2PORT(min) ((min) & 0x3f)
  522. /*****************************************************************************/
  523. /*
  524. * Prototype all functions in this driver!
  525. */
  526. static int stli_parsebrd(struct stlconf *confp, char **argp);
  527. static int stli_open(struct tty_struct *tty, struct file *filp);
  528. static void stli_close(struct tty_struct *tty, struct file *filp);
  529. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
  530. static int stli_putchar(struct tty_struct *tty, unsigned char ch);
  531. static void stli_flushchars(struct tty_struct *tty);
  532. static int stli_writeroom(struct tty_struct *tty);
  533. static int stli_charsinbuffer(struct tty_struct *tty);
  534. static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  535. static void stli_settermios(struct tty_struct *tty, struct ktermios *old);
  536. static void stli_throttle(struct tty_struct *tty);
  537. static void stli_unthrottle(struct tty_struct *tty);
  538. static void stli_stop(struct tty_struct *tty);
  539. static void stli_start(struct tty_struct *tty);
  540. static void stli_flushbuffer(struct tty_struct *tty);
  541. static int stli_breakctl(struct tty_struct *tty, int state);
  542. static void stli_waituntilsent(struct tty_struct *tty, int timeout);
  543. static void stli_sendxchar(struct tty_struct *tty, char ch);
  544. static void stli_hangup(struct tty_struct *tty);
  545. static int stli_brdinit(struct stlibrd *brdp);
  546. static int stli_startbrd(struct stlibrd *brdp);
  547. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
  548. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
  549. static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg);
  550. static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp);
  551. static void stli_poll(unsigned long arg);
  552. static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
  553. static int stli_initopen(struct tty_struct *tty, struct stlibrd *brdp, struct stliport *portp);
  554. static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
  555. static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
  556. static int stli_setport(struct tty_struct *tty);
  557. static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
  558. static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
  559. static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
  560. static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp);
  561. static void stli_mkasyport(struct tty_struct *tty, struct stliport *portp, asyport_t *pp, struct ktermios *tiosp);
  562. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
  563. static long stli_mktiocm(unsigned long sigvalue);
  564. static void stli_read(struct stlibrd *brdp, struct stliport *portp);
  565. static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp);
  566. static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *sp);
  567. static int stli_getbrdstats(combrd_t __user *bp);
  568. static int stli_getportstats(struct tty_struct *tty, struct stliport *portp, comstats_t __user *cp);
  569. static int stli_portcmdstats(struct tty_struct *tty, struct stliport *portp);
  570. static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp);
  571. static int stli_getportstruct(struct stliport __user *arg);
  572. static int stli_getbrdstruct(struct stlibrd __user *arg);
  573. static struct stlibrd *stli_allocbrd(void);
  574. static void stli_ecpinit(struct stlibrd *brdp);
  575. static void stli_ecpenable(struct stlibrd *brdp);
  576. static void stli_ecpdisable(struct stlibrd *brdp);
  577. static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  578. static void stli_ecpreset(struct stlibrd *brdp);
  579. static void stli_ecpintr(struct stlibrd *brdp);
  580. static void stli_ecpeiinit(struct stlibrd *brdp);
  581. static void stli_ecpeienable(struct stlibrd *brdp);
  582. static void stli_ecpeidisable(struct stlibrd *brdp);
  583. static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  584. static void stli_ecpeireset(struct stlibrd *brdp);
  585. static void stli_ecpmcenable(struct stlibrd *brdp);
  586. static void stli_ecpmcdisable(struct stlibrd *brdp);
  587. static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  588. static void stli_ecpmcreset(struct stlibrd *brdp);
  589. static void stli_ecppciinit(struct stlibrd *brdp);
  590. static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  591. static void stli_ecppcireset(struct stlibrd *brdp);
  592. static void stli_onbinit(struct stlibrd *brdp);
  593. static void stli_onbenable(struct stlibrd *brdp);
  594. static void stli_onbdisable(struct stlibrd *brdp);
  595. static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  596. static void stli_onbreset(struct stlibrd *brdp);
  597. static void stli_onbeinit(struct stlibrd *brdp);
  598. static void stli_onbeenable(struct stlibrd *brdp);
  599. static void stli_onbedisable(struct stlibrd *brdp);
  600. static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  601. static void stli_onbereset(struct stlibrd *brdp);
  602. static void stli_bbyinit(struct stlibrd *brdp);
  603. static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  604. static void stli_bbyreset(struct stlibrd *brdp);
  605. static void stli_stalinit(struct stlibrd *brdp);
  606. static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line);
  607. static void stli_stalreset(struct stlibrd *brdp);
  608. static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr, unsigned int portnr);
  609. static int stli_initecp(struct stlibrd *brdp);
  610. static int stli_initonb(struct stlibrd *brdp);
  611. #if STLI_EISAPROBE != 0
  612. static int stli_eisamemprobe(struct stlibrd *brdp);
  613. #endif
  614. static int stli_initports(struct stlibrd *brdp);
  615. /*****************************************************************************/
  616. /*
  617. * Define the driver info for a user level shared memory device. This
  618. * device will work sort of like the /dev/kmem device - except that it
  619. * will give access to the shared memory on the Stallion intelligent
  620. * board. This is also a very useful debugging tool.
  621. */
  622. static const struct file_operations stli_fsiomem = {
  623. .owner = THIS_MODULE,
  624. .read = stli_memread,
  625. .write = stli_memwrite,
  626. .unlocked_ioctl = stli_memioctl,
  627. };
  628. /*****************************************************************************/
  629. /*
  630. * Define a timer_list entry for our poll routine. The slave board
  631. * is polled every so often to see if anything needs doing. This is
  632. * much cheaper on host cpu than using interrupts. It turns out to
  633. * not increase character latency by much either...
  634. */
  635. static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
  636. static int stli_timeron;
  637. /*
  638. * Define the calculation for the timeout routine.
  639. */
  640. #define STLI_TIMEOUT (jiffies + 1)
  641. /*****************************************************************************/
  642. static struct class *istallion_class;
  643. static void stli_cleanup_ports(struct stlibrd *brdp)
  644. {
  645. struct stliport *portp;
  646. unsigned int j;
  647. struct tty_struct *tty;
  648. for (j = 0; j < STL_MAXPORTS; j++) {
  649. portp = brdp->ports[j];
  650. if (portp != NULL) {
  651. tty = tty_port_tty_get(&portp->port);
  652. if (tty != NULL) {
  653. tty_hangup(tty);
  654. tty_kref_put(tty);
  655. }
  656. kfree(portp);
  657. }
  658. }
  659. }
  660. /*****************************************************************************/
  661. /*
  662. * Parse the supplied argument string, into the board conf struct.
  663. */
  664. static int stli_parsebrd(struct stlconf *confp, char **argp)
  665. {
  666. unsigned int i;
  667. char *sp;
  668. if (argp[0] == NULL || *argp[0] == 0)
  669. return 0;
  670. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  671. *sp = tolower(*sp);
  672. for (i = 0; i < ARRAY_SIZE(stli_brdstr); i++) {
  673. if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
  674. break;
  675. }
  676. if (i == ARRAY_SIZE(stli_brdstr)) {
  677. printk(KERN_WARNING "istallion: unknown board name, %s?\n", argp[0]);
  678. return 0;
  679. }
  680. confp->brdtype = stli_brdstr[i].type;
  681. if (argp[1] != NULL && *argp[1] != 0)
  682. confp->ioaddr1 = simple_strtoul(argp[1], NULL, 0);
  683. if (argp[2] != NULL && *argp[2] != 0)
  684. confp->memaddr = simple_strtoul(argp[2], NULL, 0);
  685. return(1);
  686. }
  687. /*****************************************************************************/
  688. /*
  689. * On the first open of the device setup the port hardware, and
  690. * initialize the per port data structure. Since initializing the port
  691. * requires several commands to the board we will need to wait for any
  692. * other open that is already initializing the port.
  693. *
  694. * Locking: protected by the port mutex.
  695. */
  696. static int stli_activate(struct tty_port *port, struct tty_struct *tty)
  697. {
  698. struct stliport *portp = container_of(port, struct stliport, port);
  699. struct stlibrd *brdp = stli_brds[portp->brdnr];
  700. int rc;
  701. if ((rc = stli_initopen(tty, brdp, portp)) >= 0)
  702. clear_bit(TTY_IO_ERROR, &tty->flags);
  703. wake_up_interruptible(&portp->raw_wait);
  704. return rc;
  705. }
  706. static int stli_open(struct tty_struct *tty, struct file *filp)
  707. {
  708. struct stlibrd *brdp;
  709. struct stliport *portp;
  710. unsigned int minordev, brdnr, portnr;
  711. minordev = tty->index;
  712. brdnr = MINOR2BRD(minordev);
  713. if (brdnr >= stli_nrbrds)
  714. return -ENODEV;
  715. brdp = stli_brds[brdnr];
  716. if (brdp == NULL)
  717. return -ENODEV;
  718. if (!test_bit(BST_STARTED, &brdp->state))
  719. return -ENODEV;
  720. portnr = MINOR2PORT(minordev);
  721. if (portnr > brdp->nrports)
  722. return -ENODEV;
  723. portp = brdp->ports[portnr];
  724. if (portp == NULL)
  725. return -ENODEV;
  726. if (portp->devnr < 1)
  727. return -ENODEV;
  728. tty->driver_data = portp;
  729. return tty_port_open(&portp->port, tty, filp);
  730. }
  731. /*****************************************************************************/
  732. static void stli_shutdown(struct tty_port *port)
  733. {
  734. struct stlibrd *brdp;
  735. unsigned long ftype;
  736. unsigned long flags;
  737. struct stliport *portp = container_of(port, struct stliport, port);
  738. if (portp->brdnr >= stli_nrbrds)
  739. return;
  740. brdp = stli_brds[portp->brdnr];
  741. if (brdp == NULL)
  742. return;
  743. /*
  744. * May want to wait for data to drain before closing. The BUSY
  745. * flag keeps track of whether we are still transmitting or not.
  746. * It is updated by messages from the slave - indicating when all
  747. * chars really have drained.
  748. */
  749. if (!test_bit(ST_CLOSING, &portp->state))
  750. stli_rawclose(brdp, portp, 0, 0);
  751. spin_lock_irqsave(&stli_lock, flags);
  752. clear_bit(ST_TXBUSY, &portp->state);
  753. clear_bit(ST_RXSTOP, &portp->state);
  754. spin_unlock_irqrestore(&stli_lock, flags);
  755. ftype = FLUSHTX | FLUSHRX;
  756. stli_cmdwait(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
  757. }
  758. static void stli_close(struct tty_struct *tty, struct file *filp)
  759. {
  760. struct stliport *portp = tty->driver_data;
  761. unsigned long flags;
  762. if (portp == NULL)
  763. return;
  764. spin_lock_irqsave(&stli_lock, flags);
  765. /* Flush any internal buffering out first */
  766. if (tty == stli_txcooktty)
  767. stli_flushchars(tty);
  768. spin_unlock_irqrestore(&stli_lock, flags);
  769. tty_port_close(&portp->port, tty, filp);
  770. }
  771. /*****************************************************************************/
  772. /*
  773. * Carry out first open operations on a port. This involves a number of
  774. * commands to be sent to the slave. We need to open the port, set the
  775. * notification events, set the initial port settings, get and set the
  776. * initial signal values. We sleep and wait in between each one. But
  777. * this still all happens pretty quickly.
  778. */
  779. static int stli_initopen(struct tty_struct *tty,
  780. struct stlibrd *brdp, struct stliport *portp)
  781. {
  782. asynotify_t nt;
  783. asyport_t aport;
  784. int rc;
  785. if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
  786. return rc;
  787. memset(&nt, 0, sizeof(asynotify_t));
  788. nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
  789. nt.signal = SG_DCD;
  790. if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
  791. sizeof(asynotify_t), 0)) < 0)
  792. return rc;
  793. stli_mkasyport(tty, portp, &aport, tty->termios);
  794. if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
  795. sizeof(asyport_t), 0)) < 0)
  796. return rc;
  797. set_bit(ST_GETSIGS, &portp->state);
  798. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
  799. sizeof(asysigs_t), 1)) < 0)
  800. return rc;
  801. if (test_and_clear_bit(ST_GETSIGS, &portp->state))
  802. portp->sigs = stli_mktiocm(portp->asig.sigvalue);
  803. stli_mkasysigs(&portp->asig, 1, 1);
  804. if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  805. sizeof(asysigs_t), 0)) < 0)
  806. return rc;
  807. return 0;
  808. }
  809. /*****************************************************************************/
  810. /*
  811. * Send an open message to the slave. This will sleep waiting for the
  812. * acknowledgement, so must have user context. We need to co-ordinate
  813. * with close events here, since we don't want open and close events
  814. * to overlap.
  815. */
  816. static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
  817. {
  818. cdkhdr_t __iomem *hdrp;
  819. cdkctrl_t __iomem *cp;
  820. unsigned char __iomem *bits;
  821. unsigned long flags;
  822. int rc;
  823. /*
  824. * Send a message to the slave to open this port.
  825. */
  826. /*
  827. * Slave is already closing this port. This can happen if a hangup
  828. * occurs on this port. So we must wait until it is complete. The
  829. * order of opens and closes may not be preserved across shared
  830. * memory, so we must wait until it is complete.
  831. */
  832. wait_event_interruptible_tty(portp->raw_wait,
  833. !test_bit(ST_CLOSING, &portp->state));
  834. if (signal_pending(current)) {
  835. return -ERESTARTSYS;
  836. }
  837. /*
  838. * Everything is ready now, so write the open message into shared
  839. * memory. Once the message is in set the service bits to say that
  840. * this port wants service.
  841. */
  842. spin_lock_irqsave(&brd_lock, flags);
  843. EBRDENABLE(brdp);
  844. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  845. writel(arg, &cp->openarg);
  846. writeb(1, &cp->open);
  847. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  848. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  849. portp->portidx;
  850. writeb(readb(bits) | portp->portbit, bits);
  851. EBRDDISABLE(brdp);
  852. if (wait == 0) {
  853. spin_unlock_irqrestore(&brd_lock, flags);
  854. return 0;
  855. }
  856. /*
  857. * Slave is in action, so now we must wait for the open acknowledgment
  858. * to come back.
  859. */
  860. rc = 0;
  861. set_bit(ST_OPENING, &portp->state);
  862. spin_unlock_irqrestore(&brd_lock, flags);
  863. wait_event_interruptible_tty(portp->raw_wait,
  864. !test_bit(ST_OPENING, &portp->state));
  865. if (signal_pending(current))
  866. rc = -ERESTARTSYS;
  867. if ((rc == 0) && (portp->rc != 0))
  868. rc = -EIO;
  869. return rc;
  870. }
  871. /*****************************************************************************/
  872. /*
  873. * Send a close message to the slave. Normally this will sleep waiting
  874. * for the acknowledgement, but if wait parameter is 0 it will not. If
  875. * wait is true then must have user context (to sleep).
  876. */
  877. static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait)
  878. {
  879. cdkhdr_t __iomem *hdrp;
  880. cdkctrl_t __iomem *cp;
  881. unsigned char __iomem *bits;
  882. unsigned long flags;
  883. int rc;
  884. /*
  885. * Slave is already closing this port. This can happen if a hangup
  886. * occurs on this port.
  887. */
  888. if (wait) {
  889. wait_event_interruptible_tty(portp->raw_wait,
  890. !test_bit(ST_CLOSING, &portp->state));
  891. if (signal_pending(current)) {
  892. return -ERESTARTSYS;
  893. }
  894. }
  895. /*
  896. * Write the close command into shared memory.
  897. */
  898. spin_lock_irqsave(&brd_lock, flags);
  899. EBRDENABLE(brdp);
  900. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  901. writel(arg, &cp->closearg);
  902. writeb(1, &cp->close);
  903. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  904. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  905. portp->portidx;
  906. writeb(readb(bits) |portp->portbit, bits);
  907. EBRDDISABLE(brdp);
  908. set_bit(ST_CLOSING, &portp->state);
  909. spin_unlock_irqrestore(&brd_lock, flags);
  910. if (wait == 0)
  911. return 0;
  912. /*
  913. * Slave is in action, so now we must wait for the open acknowledgment
  914. * to come back.
  915. */
  916. rc = 0;
  917. wait_event_interruptible_tty(portp->raw_wait,
  918. !test_bit(ST_CLOSING, &portp->state));
  919. if (signal_pending(current))
  920. rc = -ERESTARTSYS;
  921. if ((rc == 0) && (portp->rc != 0))
  922. rc = -EIO;
  923. return rc;
  924. }
  925. /*****************************************************************************/
  926. /*
  927. * Send a command to the slave and wait for the response. This must
  928. * have user context (it sleeps). This routine is generic in that it
  929. * can send any type of command. Its purpose is to wait for that command
  930. * to complete (as opposed to initiating the command then returning).
  931. */
  932. static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
  933. {
  934. /*
  935. * no need for wait_event_tty because clearing ST_CMDING cannot block
  936. * on BTM
  937. */
  938. wait_event_interruptible(portp->raw_wait,
  939. !test_bit(ST_CMDING, &portp->state));
  940. if (signal_pending(current))
  941. return -ERESTARTSYS;
  942. stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
  943. wait_event_interruptible(portp->raw_wait,
  944. !test_bit(ST_CMDING, &portp->state));
  945. if (signal_pending(current))
  946. return -ERESTARTSYS;
  947. if (portp->rc != 0)
  948. return -EIO;
  949. return 0;
  950. }
  951. /*****************************************************************************/
  952. /*
  953. * Send the termios settings for this port to the slave. This sleeps
  954. * waiting for the command to complete - so must have user context.
  955. */
  956. static int stli_setport(struct tty_struct *tty)
  957. {
  958. struct stliport *portp = tty->driver_data;
  959. struct stlibrd *brdp;
  960. asyport_t aport;
  961. if (portp == NULL)
  962. return -ENODEV;
  963. if (portp->brdnr >= stli_nrbrds)
  964. return -ENODEV;
  965. brdp = stli_brds[portp->brdnr];
  966. if (brdp == NULL)
  967. return -ENODEV;
  968. stli_mkasyport(tty, portp, &aport, tty->termios);
  969. return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
  970. }
  971. /*****************************************************************************/
  972. static int stli_carrier_raised(struct tty_port *port)
  973. {
  974. struct stliport *portp = container_of(port, struct stliport, port);
  975. return (portp->sigs & TIOCM_CD) ? 1 : 0;
  976. }
  977. static void stli_dtr_rts(struct tty_port *port, int on)
  978. {
  979. struct stliport *portp = container_of(port, struct stliport, port);
  980. struct stlibrd *brdp = stli_brds[portp->brdnr];
  981. stli_mkasysigs(&portp->asig, on, on);
  982. if (stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  983. sizeof(asysigs_t), 0) < 0)
  984. printk(KERN_WARNING "istallion: dtr set failed.\n");
  985. }
  986. /*****************************************************************************/
  987. /*
  988. * Write routine. Take the data and put it in the shared memory ring
  989. * queue. If port is not already sending chars then need to mark the
  990. * service bits for this port.
  991. */
  992. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
  993. {
  994. cdkasy_t __iomem *ap;
  995. cdkhdr_t __iomem *hdrp;
  996. unsigned char __iomem *bits;
  997. unsigned char __iomem *shbuf;
  998. unsigned char *chbuf;
  999. struct stliport *portp;
  1000. struct stlibrd *brdp;
  1001. unsigned int len, stlen, head, tail, size;
  1002. unsigned long flags;
  1003. if (tty == stli_txcooktty)
  1004. stli_flushchars(tty);
  1005. portp = tty->driver_data;
  1006. if (portp == NULL)
  1007. return 0;
  1008. if (portp->brdnr >= stli_nrbrds)
  1009. return 0;
  1010. brdp = stli_brds[portp->brdnr];
  1011. if (brdp == NULL)
  1012. return 0;
  1013. chbuf = (unsigned char *) buf;
  1014. /*
  1015. * All data is now local, shove as much as possible into shared memory.
  1016. */
  1017. spin_lock_irqsave(&brd_lock, flags);
  1018. EBRDENABLE(brdp);
  1019. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1020. head = (unsigned int) readw(&ap->txq.head);
  1021. tail = (unsigned int) readw(&ap->txq.tail);
  1022. if (tail != ((unsigned int) readw(&ap->txq.tail)))
  1023. tail = (unsigned int) readw(&ap->txq.tail);
  1024. size = portp->txsize;
  1025. if (head >= tail) {
  1026. len = size - (head - tail) - 1;
  1027. stlen = size - head;
  1028. } else {
  1029. len = tail - head - 1;
  1030. stlen = len;
  1031. }
  1032. len = min(len, (unsigned int)count);
  1033. count = 0;
  1034. shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
  1035. while (len > 0) {
  1036. stlen = min(len, stlen);
  1037. memcpy_toio(shbuf + head, chbuf, stlen);
  1038. chbuf += stlen;
  1039. len -= stlen;
  1040. count += stlen;
  1041. head += stlen;
  1042. if (head >= size) {
  1043. head = 0;
  1044. stlen = tail;
  1045. }
  1046. }
  1047. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1048. writew(head, &ap->txq.head);
  1049. if (test_bit(ST_TXBUSY, &portp->state)) {
  1050. if (readl(&ap->changed.data) & DT_TXEMPTY)
  1051. writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
  1052. }
  1053. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1054. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1055. portp->portidx;
  1056. writeb(readb(bits) | portp->portbit, bits);
  1057. set_bit(ST_TXBUSY, &portp->state);
  1058. EBRDDISABLE(brdp);
  1059. spin_unlock_irqrestore(&brd_lock, flags);
  1060. return(count);
  1061. }
  1062. /*****************************************************************************/
  1063. /*
  1064. * Output a single character. We put it into a temporary local buffer
  1065. * (for speed) then write out that buffer when the flushchars routine
  1066. * is called. There is a safety catch here so that if some other port
  1067. * writes chars before the current buffer has been, then we write them
  1068. * first them do the new ports.
  1069. */
  1070. static int stli_putchar(struct tty_struct *tty, unsigned char ch)
  1071. {
  1072. if (tty != stli_txcooktty) {
  1073. if (stli_txcooktty != NULL)
  1074. stli_flushchars(stli_txcooktty);
  1075. stli_txcooktty = tty;
  1076. }
  1077. stli_txcookbuf[stli_txcooksize++] = ch;
  1078. return 0;
  1079. }
  1080. /*****************************************************************************/
  1081. /*
  1082. * Transfer characters from the local TX cooking buffer to the board.
  1083. * We sort of ignore the tty that gets passed in here. We rely on the
  1084. * info stored with the TX cook buffer to tell us which port to flush
  1085. * the data on. In any case we clean out the TX cook buffer, for re-use
  1086. * by someone else.
  1087. */
  1088. static void stli_flushchars(struct tty_struct *tty)
  1089. {
  1090. cdkhdr_t __iomem *hdrp;
  1091. unsigned char __iomem *bits;
  1092. cdkasy_t __iomem *ap;
  1093. struct tty_struct *cooktty;
  1094. struct stliport *portp;
  1095. struct stlibrd *brdp;
  1096. unsigned int len, stlen, head, tail, size, count, cooksize;
  1097. unsigned char *buf;
  1098. unsigned char __iomem *shbuf;
  1099. unsigned long flags;
  1100. cooksize = stli_txcooksize;
  1101. cooktty = stli_txcooktty;
  1102. stli_txcooksize = 0;
  1103. stli_txcookrealsize = 0;
  1104. stli_txcooktty = NULL;
  1105. if (cooktty == NULL)
  1106. return;
  1107. if (tty != cooktty)
  1108. tty = cooktty;
  1109. if (cooksize == 0)
  1110. return;
  1111. portp = tty->driver_data;
  1112. if (portp == NULL)
  1113. return;
  1114. if (portp->brdnr >= stli_nrbrds)
  1115. return;
  1116. brdp = stli_brds[portp->brdnr];
  1117. if (brdp == NULL)
  1118. return;
  1119. spin_lock_irqsave(&brd_lock, flags);
  1120. EBRDENABLE(brdp);
  1121. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1122. head = (unsigned int) readw(&ap->txq.head);
  1123. tail = (unsigned int) readw(&ap->txq.tail);
  1124. if (tail != ((unsigned int) readw(&ap->txq.tail)))
  1125. tail = (unsigned int) readw(&ap->txq.tail);
  1126. size = portp->txsize;
  1127. if (head >= tail) {
  1128. len = size - (head - tail) - 1;
  1129. stlen = size - head;
  1130. } else {
  1131. len = tail - head - 1;
  1132. stlen = len;
  1133. }
  1134. len = min(len, cooksize);
  1135. count = 0;
  1136. shbuf = EBRDGETMEMPTR(brdp, portp->txoffset);
  1137. buf = stli_txcookbuf;
  1138. while (len > 0) {
  1139. stlen = min(len, stlen);
  1140. memcpy_toio(shbuf + head, buf, stlen);
  1141. buf += stlen;
  1142. len -= stlen;
  1143. count += stlen;
  1144. head += stlen;
  1145. if (head >= size) {
  1146. head = 0;
  1147. stlen = tail;
  1148. }
  1149. }
  1150. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1151. writew(head, &ap->txq.head);
  1152. if (test_bit(ST_TXBUSY, &portp->state)) {
  1153. if (readl(&ap->changed.data) & DT_TXEMPTY)
  1154. writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
  1155. }
  1156. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1157. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1158. portp->portidx;
  1159. writeb(readb(bits) | portp->portbit, bits);
  1160. set_bit(ST_TXBUSY, &portp->state);
  1161. EBRDDISABLE(brdp);
  1162. spin_unlock_irqrestore(&brd_lock, flags);
  1163. }
  1164. /*****************************************************************************/
  1165. static int stli_writeroom(struct tty_struct *tty)
  1166. {
  1167. cdkasyrq_t __iomem *rp;
  1168. struct stliport *portp;
  1169. struct stlibrd *brdp;
  1170. unsigned int head, tail, len;
  1171. unsigned long flags;
  1172. if (tty == stli_txcooktty) {
  1173. if (stli_txcookrealsize != 0) {
  1174. len = stli_txcookrealsize - stli_txcooksize;
  1175. return len;
  1176. }
  1177. }
  1178. portp = tty->driver_data;
  1179. if (portp == NULL)
  1180. return 0;
  1181. if (portp->brdnr >= stli_nrbrds)
  1182. return 0;
  1183. brdp = stli_brds[portp->brdnr];
  1184. if (brdp == NULL)
  1185. return 0;
  1186. spin_lock_irqsave(&brd_lock, flags);
  1187. EBRDENABLE(brdp);
  1188. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1189. head = (unsigned int) readw(&rp->head);
  1190. tail = (unsigned int) readw(&rp->tail);
  1191. if (tail != ((unsigned int) readw(&rp->tail)))
  1192. tail = (unsigned int) readw(&rp->tail);
  1193. len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
  1194. len--;
  1195. EBRDDISABLE(brdp);
  1196. spin_unlock_irqrestore(&brd_lock, flags);
  1197. if (tty == stli_txcooktty) {
  1198. stli_txcookrealsize = len;
  1199. len -= stli_txcooksize;
  1200. }
  1201. return len;
  1202. }
  1203. /*****************************************************************************/
  1204. /*
  1205. * Return the number of characters in the transmit buffer. Normally we
  1206. * will return the number of chars in the shared memory ring queue.
  1207. * We need to kludge around the case where the shared memory buffer is
  1208. * empty but not all characters have drained yet, for this case just
  1209. * return that there is 1 character in the buffer!
  1210. */
  1211. static int stli_charsinbuffer(struct tty_struct *tty)
  1212. {
  1213. cdkasyrq_t __iomem *rp;
  1214. struct stliport *portp;
  1215. struct stlibrd *brdp;
  1216. unsigned int head, tail, len;
  1217. unsigned long flags;
  1218. if (tty == stli_txcooktty)
  1219. stli_flushchars(tty);
  1220. portp = tty->driver_data;
  1221. if (portp == NULL)
  1222. return 0;
  1223. if (portp->brdnr >= stli_nrbrds)
  1224. return 0;
  1225. brdp = stli_brds[portp->brdnr];
  1226. if (brdp == NULL)
  1227. return 0;
  1228. spin_lock_irqsave(&brd_lock, flags);
  1229. EBRDENABLE(brdp);
  1230. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1231. head = (unsigned int) readw(&rp->head);
  1232. tail = (unsigned int) readw(&rp->tail);
  1233. if (tail != ((unsigned int) readw(&rp->tail)))
  1234. tail = (unsigned int) readw(&rp->tail);
  1235. len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
  1236. if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
  1237. len = 1;
  1238. EBRDDISABLE(brdp);
  1239. spin_unlock_irqrestore(&brd_lock, flags);
  1240. return len;
  1241. }
  1242. /*****************************************************************************/
  1243. /*
  1244. * Generate the serial struct info.
  1245. */
  1246. static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp)
  1247. {
  1248. struct serial_struct sio;
  1249. struct stlibrd *brdp;
  1250. memset(&sio, 0, sizeof(struct serial_struct));
  1251. sio.type = PORT_UNKNOWN;
  1252. sio.line = portp->portnr;
  1253. sio.irq = 0;
  1254. sio.flags = portp->port.flags;
  1255. sio.baud_base = portp->baud_base;
  1256. sio.close_delay = portp->port.close_delay;
  1257. sio.closing_wait = portp->closing_wait;
  1258. sio.custom_divisor = portp->custom_divisor;
  1259. sio.xmit_fifo_size = 0;
  1260. sio.hub6 = 0;
  1261. brdp = stli_brds[portp->brdnr];
  1262. if (brdp != NULL)
  1263. sio.port = brdp->iobase;
  1264. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
  1265. -EFAULT : 0;
  1266. }
  1267. /*****************************************************************************/
  1268. /*
  1269. * Set port according to the serial struct info.
  1270. * At this point we do not do any auto-configure stuff, so we will
  1271. * just quietly ignore any requests to change irq, etc.
  1272. */
  1273. static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *sp)
  1274. {
  1275. struct serial_struct sio;
  1276. int rc;
  1277. struct stliport *portp = tty->driver_data;
  1278. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1279. return -EFAULT;
  1280. if (!capable(CAP_SYS_ADMIN)) {
  1281. if ((sio.baud_base != portp->baud_base) ||
  1282. (sio.close_delay != portp->port.close_delay) ||
  1283. ((sio.flags & ~ASYNC_USR_MASK) !=
  1284. (portp->port.flags & ~ASYNC_USR_MASK)))
  1285. return -EPERM;
  1286. }
  1287. portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) |
  1288. (sio.flags & ASYNC_USR_MASK);
  1289. portp->baud_base = sio.baud_base;
  1290. portp->port.close_delay = sio.close_delay;
  1291. portp->closing_wait = sio.closing_wait;
  1292. portp->custom_divisor = sio.custom_divisor;
  1293. if ((rc = stli_setport(tty)) < 0)
  1294. return rc;
  1295. return 0;
  1296. }
  1297. /*****************************************************************************/
  1298. static int stli_tiocmget(struct tty_struct *tty, struct file *file)
  1299. {
  1300. struct stliport *portp = tty->driver_data;
  1301. struct stlibrd *brdp;
  1302. int rc;
  1303. if (portp == NULL)
  1304. return -ENODEV;
  1305. if (portp->brdnr >= stli_nrbrds)
  1306. return 0;
  1307. brdp = stli_brds[portp->brdnr];
  1308. if (brdp == NULL)
  1309. return 0;
  1310. if (tty->flags & (1 << TTY_IO_ERROR))
  1311. return -EIO;
  1312. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
  1313. &portp->asig, sizeof(asysigs_t), 1)) < 0)
  1314. return rc;
  1315. return stli_mktiocm(portp->asig.sigvalue);
  1316. }
  1317. static int stli_tiocmset(struct tty_struct *tty, struct file *file,
  1318. unsigned int set, unsigned int clear)
  1319. {
  1320. struct stliport *portp = tty->driver_data;
  1321. struct stlibrd *brdp;
  1322. int rts = -1, dtr = -1;
  1323. if (portp == NULL)
  1324. return -ENODEV;
  1325. if (portp->brdnr >= stli_nrbrds)
  1326. return 0;
  1327. brdp = stli_brds[portp->brdnr];
  1328. if (brdp == NULL)
  1329. return 0;
  1330. if (tty->flags & (1 << TTY_IO_ERROR))
  1331. return -EIO;
  1332. if (set & TIOCM_RTS)
  1333. rts = 1;
  1334. if (set & TIOCM_DTR)
  1335. dtr = 1;
  1336. if (clear & TIOCM_RTS)
  1337. rts = 0;
  1338. if (clear & TIOCM_DTR)
  1339. dtr = 0;
  1340. stli_mkasysigs(&portp->asig, dtr, rts);
  1341. return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1342. sizeof(asysigs_t), 0);
  1343. }
  1344. static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1345. {
  1346. struct stliport *portp;
  1347. struct stlibrd *brdp;
  1348. int rc;
  1349. void __user *argp = (void __user *)arg;
  1350. portp = tty->driver_data;
  1351. if (portp == NULL)
  1352. return -ENODEV;
  1353. if (portp->brdnr >= stli_nrbrds)
  1354. return 0;
  1355. brdp = stli_brds[portp->brdnr];
  1356. if (brdp == NULL)
  1357. return 0;
  1358. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1359. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1360. if (tty->flags & (1 << TTY_IO_ERROR))
  1361. return -EIO;
  1362. }
  1363. rc = 0;
  1364. switch (cmd) {
  1365. case TIOCGSERIAL:
  1366. rc = stli_getserial(portp, argp);
  1367. break;
  1368. case TIOCSSERIAL:
  1369. rc = stli_setserial(tty, argp);
  1370. break;
  1371. case STL_GETPFLAG:
  1372. rc = put_user(portp->pflag, (unsigned __user *)argp);
  1373. break;
  1374. case STL_SETPFLAG:
  1375. if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
  1376. stli_setport(tty);
  1377. break;
  1378. case COM_GETPORTSTATS:
  1379. rc = stli_getportstats(tty, portp, argp);
  1380. break;
  1381. case COM_CLRPORTSTATS:
  1382. rc = stli_clrportstats(portp, argp);
  1383. break;
  1384. case TIOCSERCONFIG:
  1385. case TIOCSERGWILD:
  1386. case TIOCSERSWILD:
  1387. case TIOCSERGETLSR:
  1388. case TIOCSERGSTRUCT:
  1389. case TIOCSERGETMULTI:
  1390. case TIOCSERSETMULTI:
  1391. default:
  1392. rc = -ENOIOCTLCMD;
  1393. break;
  1394. }
  1395. return rc;
  1396. }
  1397. /*****************************************************************************/
  1398. /*
  1399. * This routine assumes that we have user context and can sleep.
  1400. * Looks like it is true for the current ttys implementation..!!
  1401. */
  1402. static void stli_settermios(struct tty_struct *tty, struct ktermios *old)
  1403. {
  1404. struct stliport *portp;
  1405. struct stlibrd *brdp;
  1406. struct ktermios *tiosp;
  1407. asyport_t aport;
  1408. portp = tty->driver_data;
  1409. if (portp == NULL)
  1410. return;
  1411. if (portp->brdnr >= stli_nrbrds)
  1412. return;
  1413. brdp = stli_brds[portp->brdnr];
  1414. if (brdp == NULL)
  1415. return;
  1416. tiosp = tty->termios;
  1417. stli_mkasyport(tty, portp, &aport, tiosp);
  1418. stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
  1419. stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
  1420. stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1421. sizeof(asysigs_t), 0);
  1422. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
  1423. tty->hw_stopped = 0;
  1424. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1425. wake_up_interruptible(&portp->port.open_wait);
  1426. }
  1427. /*****************************************************************************/
  1428. /*
  1429. * Attempt to flow control who ever is sending us data. We won't really
  1430. * do any flow control action here. We can't directly, and even if we
  1431. * wanted to we would have to send a command to the slave. The slave
  1432. * knows how to flow control, and will do so when its buffers reach its
  1433. * internal high water marks. So what we will do is set a local state
  1434. * bit that will stop us sending any RX data up from the poll routine
  1435. * (which is the place where RX data from the slave is handled).
  1436. */
  1437. static void stli_throttle(struct tty_struct *tty)
  1438. {
  1439. struct stliport *portp = tty->driver_data;
  1440. if (portp == NULL)
  1441. return;
  1442. set_bit(ST_RXSTOP, &portp->state);
  1443. }
  1444. /*****************************************************************************/
  1445. /*
  1446. * Unflow control the device sending us data... That means that all
  1447. * we have to do is clear the RXSTOP state bit. The next poll call
  1448. * will then be able to pass the RX data back up.
  1449. */
  1450. static void stli_unthrottle(struct tty_struct *tty)
  1451. {
  1452. struct stliport *portp = tty->driver_data;
  1453. if (portp == NULL)
  1454. return;
  1455. clear_bit(ST_RXSTOP, &portp->state);
  1456. }
  1457. /*****************************************************************************/
  1458. /*
  1459. * Stop the transmitter.
  1460. */
  1461. static void stli_stop(struct tty_struct *tty)
  1462. {
  1463. }
  1464. /*****************************************************************************/
  1465. /*
  1466. * Start the transmitter again.
  1467. */
  1468. static void stli_start(struct tty_struct *tty)
  1469. {
  1470. }
  1471. /*****************************************************************************/
  1472. /*
  1473. * Hangup this port. This is pretty much like closing the port, only
  1474. * a little more brutal. No waiting for data to drain. Shutdown the
  1475. * port and maybe drop signals. This is rather tricky really. We want
  1476. * to close the port as well.
  1477. */
  1478. static void stli_hangup(struct tty_struct *tty)
  1479. {
  1480. struct stliport *portp = tty->driver_data;
  1481. tty_port_hangup(&portp->port);
  1482. }
  1483. /*****************************************************************************/
  1484. /*
  1485. * Flush characters from the lower buffer. We may not have user context
  1486. * so we cannot sleep waiting for it to complete. Also we need to check
  1487. * if there is chars for this port in the TX cook buffer, and flush them
  1488. * as well.
  1489. */
  1490. static void stli_flushbuffer(struct tty_struct *tty)
  1491. {
  1492. struct stliport *portp;
  1493. struct stlibrd *brdp;
  1494. unsigned long ftype, flags;
  1495. portp = tty->driver_data;
  1496. if (portp == NULL)
  1497. return;
  1498. if (portp->brdnr >= stli_nrbrds)
  1499. return;
  1500. brdp = stli_brds[portp->brdnr];
  1501. if (brdp == NULL)
  1502. return;
  1503. spin_lock_irqsave(&brd_lock, flags);
  1504. if (tty == stli_txcooktty) {
  1505. stli_txcooktty = NULL;
  1506. stli_txcooksize = 0;
  1507. stli_txcookrealsize = 0;
  1508. }
  1509. if (test_bit(ST_CMDING, &portp->state)) {
  1510. set_bit(ST_DOFLUSHTX, &portp->state);
  1511. } else {
  1512. ftype = FLUSHTX;
  1513. if (test_bit(ST_DOFLUSHRX, &portp->state)) {
  1514. ftype |= FLUSHRX;
  1515. clear_bit(ST_DOFLUSHRX, &portp->state);
  1516. }
  1517. __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
  1518. }
  1519. spin_unlock_irqrestore(&brd_lock, flags);
  1520. tty_wakeup(tty);
  1521. }
  1522. /*****************************************************************************/
  1523. static int stli_breakctl(struct tty_struct *tty, int state)
  1524. {
  1525. struct stlibrd *brdp;
  1526. struct stliport *portp;
  1527. long arg;
  1528. portp = tty->driver_data;
  1529. if (portp == NULL)
  1530. return -EINVAL;
  1531. if (portp->brdnr >= stli_nrbrds)
  1532. return -EINVAL;
  1533. brdp = stli_brds[portp->brdnr];
  1534. if (brdp == NULL)
  1535. return -EINVAL;
  1536. arg = (state == -1) ? BREAKON : BREAKOFF;
  1537. stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
  1538. return 0;
  1539. }
  1540. /*****************************************************************************/
  1541. static void stli_waituntilsent(struct tty_struct *tty, int timeout)
  1542. {
  1543. struct stliport *portp;
  1544. unsigned long tend;
  1545. portp = tty->driver_data;
  1546. if (portp == NULL)
  1547. return;
  1548. if (timeout == 0)
  1549. timeout = HZ;
  1550. tend = jiffies + timeout;
  1551. while (test_bit(ST_TXBUSY, &portp->state)) {
  1552. if (signal_pending(current))
  1553. break;
  1554. msleep_interruptible(20);
  1555. if (time_after_eq(jiffies, tend))
  1556. break;
  1557. }
  1558. }
  1559. /*****************************************************************************/
  1560. static void stli_sendxchar(struct tty_struct *tty, char ch)
  1561. {
  1562. struct stlibrd *brdp;
  1563. struct stliport *portp;
  1564. asyctrl_t actrl;
  1565. portp = tty->driver_data;
  1566. if (portp == NULL)
  1567. return;
  1568. if (portp->brdnr >= stli_nrbrds)
  1569. return;
  1570. brdp = stli_brds[portp->brdnr];
  1571. if (brdp == NULL)
  1572. return;
  1573. memset(&actrl, 0, sizeof(asyctrl_t));
  1574. if (ch == STOP_CHAR(tty)) {
  1575. actrl.rxctrl = CT_STOPFLOW;
  1576. } else if (ch == START_CHAR(tty)) {
  1577. actrl.rxctrl = CT_STARTFLOW;
  1578. } else {
  1579. actrl.txctrl = CT_SENDCHR;
  1580. actrl.tximdch = ch;
  1581. }
  1582. stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
  1583. }
  1584. static void stli_portinfo(struct seq_file *m, struct stlibrd *brdp, struct stliport *portp, int portnr)
  1585. {
  1586. char *uart;
  1587. int rc;
  1588. rc = stli_portcmdstats(NULL, portp);
  1589. uart = "UNKNOWN";
  1590. if (test_bit(BST_STARTED, &brdp->state)) {
  1591. switch (stli_comstats.hwid) {
  1592. case 0: uart = "2681"; break;
  1593. case 1: uart = "SC26198"; break;
  1594. default:uart = "CD1400"; break;
  1595. }
  1596. }
  1597. seq_printf(m, "%d: uart:%s ", portnr, uart);
  1598. if (test_bit(BST_STARTED, &brdp->state) && rc >= 0) {
  1599. char sep;
  1600. seq_printf(m, "tx:%d rx:%d", (int) stli_comstats.txtotal,
  1601. (int) stli_comstats.rxtotal);
  1602. if (stli_comstats.rxframing)
  1603. seq_printf(m, " fe:%d",
  1604. (int) stli_comstats.rxframing);
  1605. if (stli_comstats.rxparity)
  1606. seq_printf(m, " pe:%d",
  1607. (int) stli_comstats.rxparity);
  1608. if (stli_comstats.rxbreaks)
  1609. seq_printf(m, " brk:%d",
  1610. (int) stli_comstats.rxbreaks);
  1611. if (stli_comstats.rxoverrun)
  1612. seq_printf(m, " oe:%d",
  1613. (int) stli_comstats.rxoverrun);
  1614. sep = ' ';
  1615. if (stli_comstats.signals & TIOCM_RTS) {
  1616. seq_printf(m, "%c%s", sep, "RTS");
  1617. sep = '|';
  1618. }
  1619. if (stli_comstats.signals & TIOCM_CTS) {
  1620. seq_printf(m, "%c%s", sep, "CTS");
  1621. sep = '|';
  1622. }
  1623. if (stli_comstats.signals & TIOCM_DTR) {
  1624. seq_printf(m, "%c%s", sep, "DTR");
  1625. sep = '|';
  1626. }
  1627. if (stli_comstats.signals & TIOCM_CD) {
  1628. seq_printf(m, "%c%s", sep, "DCD");
  1629. sep = '|';
  1630. }
  1631. if (stli_comstats.signals & TIOCM_DSR) {
  1632. seq_printf(m, "%c%s", sep, "DSR");
  1633. sep = '|';
  1634. }
  1635. }
  1636. seq_putc(m, '\n');
  1637. }
  1638. /*****************************************************************************/
  1639. /*
  1640. * Port info, read from the /proc file system.
  1641. */
  1642. static int stli_proc_show(struct seq_file *m, void *v)
  1643. {
  1644. struct stlibrd *brdp;
  1645. struct stliport *portp;
  1646. unsigned int brdnr, portnr, totalport;
  1647. totalport = 0;
  1648. seq_printf(m, "%s: version %s\n", stli_drvtitle, stli_drvversion);
  1649. /*
  1650. * We scan through for each board, panel and port. The offset is
  1651. * calculated on the fly, and irrelevant ports are skipped.
  1652. */
  1653. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  1654. brdp = stli_brds[brdnr];
  1655. if (brdp == NULL)
  1656. continue;
  1657. if (brdp->state == 0)
  1658. continue;
  1659. totalport = brdnr * STL_MAXPORTS;
  1660. for (portnr = 0; (portnr < brdp->nrports); portnr++,
  1661. totalport++) {
  1662. portp = brdp->ports[portnr];
  1663. if (portp == NULL)
  1664. continue;
  1665. stli_portinfo(m, brdp, portp, totalport);
  1666. }
  1667. }
  1668. return 0;
  1669. }
  1670. static int stli_proc_open(struct inode *inode, struct file *file)
  1671. {
  1672. return single_open(file, stli_proc_show, NULL);
  1673. }
  1674. static const struct file_operations stli_proc_fops = {
  1675. .owner = THIS_MODULE,
  1676. .open = stli_proc_open,
  1677. .read = seq_read,
  1678. .llseek = seq_lseek,
  1679. .release = single_release,
  1680. };
  1681. /*****************************************************************************/
  1682. /*
  1683. * Generic send command routine. This will send a message to the slave,
  1684. * of the specified type with the specified argument. Must be very
  1685. * careful of data that will be copied out from shared memory -
  1686. * containing command results. The command completion is all done from
  1687. * a poll routine that does not have user context. Therefore you cannot
  1688. * copy back directly into user space, or to the kernel stack of a
  1689. * process. This routine does not sleep, so can be called from anywhere.
  1690. *
  1691. * The caller must hold the brd_lock (see also stli_sendcmd the usual
  1692. * entry point)
  1693. */
  1694. static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
  1695. {
  1696. cdkhdr_t __iomem *hdrp;
  1697. cdkctrl_t __iomem *cp;
  1698. unsigned char __iomem *bits;
  1699. if (test_bit(ST_CMDING, &portp->state)) {
  1700. printk(KERN_ERR "istallion: command already busy, cmd=%x!\n",
  1701. (int) cmd);
  1702. return;
  1703. }
  1704. EBRDENABLE(brdp);
  1705. cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  1706. if (size > 0) {
  1707. memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
  1708. if (copyback) {
  1709. portp->argp = arg;
  1710. portp->argsize = size;
  1711. }
  1712. }
  1713. writel(0, &cp->status);
  1714. writel(cmd, &cp->cmd);
  1715. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1716. bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
  1717. portp->portidx;
  1718. writeb(readb(bits) | portp->portbit, bits);
  1719. set_bit(ST_CMDING, &portp->state);
  1720. EBRDDISABLE(brdp);
  1721. }
  1722. static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback)
  1723. {
  1724. unsigned long flags;
  1725. spin_lock_irqsave(&brd_lock, flags);
  1726. __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
  1727. spin_unlock_irqrestore(&brd_lock, flags);
  1728. }
  1729. /*****************************************************************************/
  1730. /*
  1731. * Read data from shared memory. This assumes that the shared memory
  1732. * is enabled and that interrupts are off. Basically we just empty out
  1733. * the shared memory buffer into the tty buffer. Must be careful to
  1734. * handle the case where we fill up the tty buffer, but still have
  1735. * more chars to unload.
  1736. */
  1737. static void stli_read(struct stlibrd *brdp, struct stliport *portp)
  1738. {
  1739. cdkasyrq_t __iomem *rp;
  1740. char __iomem *shbuf;
  1741. struct tty_struct *tty;
  1742. unsigned int head, tail, size;
  1743. unsigned int len, stlen;
  1744. if (test_bit(ST_RXSTOP, &portp->state))
  1745. return;
  1746. tty = tty_port_tty_get(&portp->port);
  1747. if (tty == NULL)
  1748. return;
  1749. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  1750. head = (unsigned int) readw(&rp->head);
  1751. if (head != ((unsigned int) readw(&rp->head)))
  1752. head = (unsigned int) readw(&rp->head);
  1753. tail = (unsigned int) readw(&rp->tail);
  1754. size = portp->rxsize;
  1755. if (head >= tail) {
  1756. len = head - tail;
  1757. stlen = len;
  1758. } else {
  1759. len = size - (tail - head);
  1760. stlen = size - tail;
  1761. }
  1762. len = tty_buffer_request_room(tty, len);
  1763. shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
  1764. while (len > 0) {
  1765. unsigned char *cptr;
  1766. stlen = min(len, stlen);
  1767. tty_prepare_flip_string(tty, &cptr, stlen);
  1768. memcpy_fromio(cptr, shbuf + tail, stlen);
  1769. len -= stlen;
  1770. tail += stlen;
  1771. if (tail >= size) {
  1772. tail = 0;
  1773. stlen = head;
  1774. }
  1775. }
  1776. rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  1777. writew(tail, &rp->tail);
  1778. if (head != tail)
  1779. set_bit(ST_RXING, &portp->state);
  1780. tty_schedule_flip(tty);
  1781. tty_kref_put(tty);
  1782. }
  1783. /*****************************************************************************/
  1784. /*
  1785. * Set up and carry out any delayed commands. There is only a small set
  1786. * of slave commands that can be done "off-level". So it is not too
  1787. * difficult to deal with them here.
  1788. */
  1789. static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp)
  1790. {
  1791. int cmd;
  1792. if (test_bit(ST_DOSIGS, &portp->state)) {
  1793. if (test_bit(ST_DOFLUSHTX, &portp->state) &&
  1794. test_bit(ST_DOFLUSHRX, &portp->state))
  1795. cmd = A_SETSIGNALSF;
  1796. else if (test_bit(ST_DOFLUSHTX, &portp->state))
  1797. cmd = A_SETSIGNALSFTX;
  1798. else if (test_bit(ST_DOFLUSHRX, &portp->state))
  1799. cmd = A_SETSIGNALSFRX;
  1800. else
  1801. cmd = A_SETSIGNALS;
  1802. clear_bit(ST_DOFLUSHTX, &portp->state);
  1803. clear_bit(ST_DOFLUSHRX, &portp->state);
  1804. clear_bit(ST_DOSIGS, &portp->state);
  1805. memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
  1806. sizeof(asysigs_t));
  1807. writel(0, &cp->status);
  1808. writel(cmd, &cp->cmd);
  1809. set_bit(ST_CMDING, &portp->state);
  1810. } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
  1811. test_bit(ST_DOFLUSHRX, &portp->state)) {
  1812. cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
  1813. cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
  1814. clear_bit(ST_DOFLUSHTX, &portp->state);
  1815. clear_bit(ST_DOFLUSHRX, &portp->state);
  1816. memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
  1817. writel(0, &cp->status);
  1818. writel(A_FLUSH, &cp->cmd);
  1819. set_bit(ST_CMDING, &portp->state);
  1820. }
  1821. }
  1822. /*****************************************************************************/
  1823. /*
  1824. * Host command service checking. This handles commands or messages
  1825. * coming from the slave to the host. Must have board shared memory
  1826. * enabled and interrupts off when called. Notice that by servicing the
  1827. * read data last we don't need to change the shared memory pointer
  1828. * during processing (which is a slow IO operation).
  1829. * Return value indicates if this port is still awaiting actions from
  1830. * the slave (like open, command, or even TX data being sent). If 0
  1831. * then port is still busy, otherwise no longer busy.
  1832. */
  1833. static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp)
  1834. {
  1835. cdkasy_t __iomem *ap;
  1836. cdkctrl_t __iomem *cp;
  1837. struct tty_struct *tty;
  1838. asynotify_t nt;
  1839. unsigned long oldsigs;
  1840. int rc, donerx;
  1841. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  1842. cp = &ap->ctrl;
  1843. /*
  1844. * Check if we are waiting for an open completion message.
  1845. */
  1846. if (test_bit(ST_OPENING, &portp->state)) {
  1847. rc = readl(&cp->openarg);
  1848. if (readb(&cp->open) == 0 && rc != 0) {
  1849. if (rc > 0)
  1850. rc--;
  1851. writel(0, &cp->openarg);
  1852. portp->rc = rc;
  1853. clear_bit(ST_OPENING, &portp->state);
  1854. wake_up_interruptible(&portp->raw_wait);
  1855. }
  1856. }
  1857. /*
  1858. * Check if we are waiting for a close completion message.
  1859. */
  1860. if (test_bit(ST_CLOSING, &portp->state)) {
  1861. rc = (int) readl(&cp->closearg);
  1862. if (readb(&cp->close) == 0 && rc != 0) {
  1863. if (rc > 0)
  1864. rc--;
  1865. writel(0, &cp->closearg);
  1866. portp->rc = rc;
  1867. clear_bit(ST_CLOSING, &portp->state);
  1868. wake_up_interruptible(&portp->raw_wait);
  1869. }
  1870. }
  1871. /*
  1872. * Check if we are waiting for a command completion message. We may
  1873. * need to copy out the command results associated with this command.
  1874. */
  1875. if (test_bit(ST_CMDING, &portp->state)) {
  1876. rc = readl(&cp->status);
  1877. if (readl(&cp->cmd) == 0 && rc != 0) {
  1878. if (rc > 0)
  1879. rc--;
  1880. if (portp->argp != NULL) {
  1881. memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
  1882. portp->argsize);
  1883. portp->argp = NULL;
  1884. }
  1885. writel(0, &cp->status);
  1886. portp->rc = rc;
  1887. clear_bit(ST_CMDING, &portp->state);
  1888. stli_dodelaycmd(portp, cp);
  1889. wake_up_interruptible(&portp->raw_wait);
  1890. }
  1891. }
  1892. /*
  1893. * Check for any notification messages ready. This includes lots of
  1894. * different types of events - RX chars ready, RX break received,
  1895. * TX data low or empty in the slave, modem signals changed state.
  1896. */
  1897. donerx = 0;
  1898. if (ap->notify) {
  1899. nt = ap->changed;
  1900. ap->notify = 0;
  1901. tty = tty_port_tty_get(&portp->port);
  1902. if (nt.signal & SG_DCD) {
  1903. oldsigs = portp->sigs;
  1904. portp->sigs = stli_mktiocm(nt.sigvalue);
  1905. clear_bit(ST_GETSIGS, &portp->state);
  1906. if ((portp->sigs & TIOCM_CD) &&
  1907. ((oldsigs & TIOCM_CD) == 0))
  1908. wake_up_interruptible(&portp->port.open_wait);
  1909. if ((oldsigs & TIOCM_CD) &&
  1910. ((portp->sigs & TIOCM_CD) == 0)) {
  1911. if (portp->port.flags & ASYNC_CHECK_CD) {
  1912. if (tty)
  1913. tty_hangup(tty);
  1914. }
  1915. }
  1916. }
  1917. if (nt.data & DT_TXEMPTY)
  1918. clear_bit(ST_TXBUSY, &portp->state);
  1919. if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
  1920. if (tty != NULL) {
  1921. tty_wakeup(tty);
  1922. EBRDENABLE(brdp);
  1923. }
  1924. }
  1925. if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
  1926. if (tty != NULL) {
  1927. tty_insert_flip_char(tty, 0, TTY_BREAK);
  1928. if (portp->port.flags & ASYNC_SAK) {
  1929. do_SAK(tty);
  1930. EBRDENABLE(brdp);
  1931. }
  1932. tty_schedule_flip(tty);
  1933. }
  1934. }
  1935. tty_kref_put(tty);
  1936. if (nt.data & DT_RXBUSY) {
  1937. donerx++;
  1938. stli_read(brdp, portp);
  1939. }
  1940. }
  1941. /*
  1942. * It might seem odd that we are checking for more RX chars here.
  1943. * But, we need to handle the case where the tty buffer was previously
  1944. * filled, but we had more characters to pass up. The slave will not
  1945. * send any more RX notify messages until the RX buffer has been emptied.
  1946. * But it will leave the service bits on (since the buffer is not empty).
  1947. * So from here we can try to process more RX chars.
  1948. */
  1949. if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
  1950. clear_bit(ST_RXING, &portp->state);
  1951. stli_read(brdp, portp);
  1952. }
  1953. return((test_bit(ST_OPENING, &portp->state) ||
  1954. test_bit(ST_CLOSING, &portp->state) ||
  1955. test_bit(ST_CMDING, &portp->state) ||
  1956. test_bit(ST_TXBUSY, &portp->state) ||
  1957. test_bit(ST_RXING, &portp->state)) ? 0 : 1);
  1958. }
  1959. /*****************************************************************************/
  1960. /*
  1961. * Service all ports on a particular board. Assumes that the boards
  1962. * shared memory is enabled, and that the page pointer is pointed
  1963. * at the cdk header structure.
  1964. */
  1965. static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp)
  1966. {
  1967. struct stliport *portp;
  1968. unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
  1969. unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
  1970. unsigned char __iomem *slavep;
  1971. int bitpos, bitat, bitsize;
  1972. int channr, nrdevs, slavebitchange;
  1973. bitsize = brdp->bitsize;
  1974. nrdevs = brdp->nrdevs;
  1975. /*
  1976. * Check if slave wants any service. Basically we try to do as
  1977. * little work as possible here. There are 2 levels of service
  1978. * bits. So if there is nothing to do we bail early. We check
  1979. * 8 service bits at a time in the inner loop, so we can bypass
  1980. * the lot if none of them want service.
  1981. */
  1982. memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
  1983. bitsize);
  1984. memset(&slavebits[0], 0, bitsize);
  1985. slavebitchange = 0;
  1986. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  1987. if (hostbits[bitpos] == 0)
  1988. continue;
  1989. channr = bitpos * 8;
  1990. for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
  1991. if (hostbits[bitpos] & bitat) {
  1992. portp = brdp->ports[(channr - 1)];
  1993. if (stli_hostcmd(brdp, portp)) {
  1994. slavebitchange++;
  1995. slavebits[bitpos] |= bitat;
  1996. }
  1997. }
  1998. }
  1999. }
  2000. /*
  2001. * If any of the ports are no longer busy then update them in the
  2002. * slave request bits. We need to do this after, since a host port
  2003. * service may initiate more slave requests.
  2004. */
  2005. if (slavebitchange) {
  2006. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2007. slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
  2008. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  2009. if (readb(slavebits + bitpos))
  2010. writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
  2011. }
  2012. }
  2013. }
  2014. /*****************************************************************************/
  2015. /*
  2016. * Driver poll routine. This routine polls the boards in use and passes
  2017. * messages back up to host when necessary. This is actually very
  2018. * CPU efficient, since we will always have the kernel poll clock, it
  2019. * adds only a few cycles when idle (since board service can be
  2020. * determined very easily), but when loaded generates no interrupts
  2021. * (with their expensive associated context change).
  2022. */
  2023. static void stli_poll(unsigned long arg)
  2024. {
  2025. cdkhdr_t __iomem *hdrp;
  2026. struct stlibrd *brdp;
  2027. unsigned int brdnr;
  2028. mod_timer(&stli_timerlist, STLI_TIMEOUT);
  2029. /*
  2030. * Check each board and do any servicing required.
  2031. */
  2032. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  2033. brdp = stli_brds[brdnr];
  2034. if (brdp == NULL)
  2035. continue;
  2036. if (!test_bit(BST_STARTED, &brdp->state))
  2037. continue;
  2038. spin_lock(&brd_lock);
  2039. EBRDENABLE(brdp);
  2040. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2041. if (readb(&hdrp->hostreq))
  2042. stli_brdpoll(brdp, hdrp);
  2043. EBRDDISABLE(brdp);
  2044. spin_unlock(&brd_lock);
  2045. }
  2046. }
  2047. /*****************************************************************************/
  2048. /*
  2049. * Translate the termios settings into the port setting structure of
  2050. * the slave.
  2051. */
  2052. static void stli_mkasyport(struct tty_struct *tty, struct stliport *portp,
  2053. asyport_t *pp, struct ktermios *tiosp)
  2054. {
  2055. memset(pp, 0, sizeof(asyport_t));
  2056. /*
  2057. * Start of by setting the baud, char size, parity and stop bit info.
  2058. */
  2059. pp->baudout = tty_get_baud_rate(tty);
  2060. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2061. if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2062. pp->baudout = 57600;
  2063. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2064. pp->baudout = 115200;
  2065. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2066. pp->baudout = 230400;
  2067. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2068. pp->baudout = 460800;
  2069. else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2070. pp->baudout = (portp->baud_base / portp->custom_divisor);
  2071. }
  2072. if (pp->baudout > STL_MAXBAUD)
  2073. pp->baudout = STL_MAXBAUD;
  2074. pp->baudin = pp->baudout;
  2075. switch (tiosp->c_cflag & CSIZE) {
  2076. case CS5:
  2077. pp->csize = 5;
  2078. break;
  2079. case CS6:
  2080. pp->csize = 6;
  2081. break;
  2082. case CS7:
  2083. pp->csize = 7;
  2084. break;
  2085. default:
  2086. pp->csize = 8;
  2087. break;
  2088. }
  2089. if (tiosp->c_cflag & CSTOPB)
  2090. pp->stopbs = PT_STOP2;
  2091. else
  2092. pp->stopbs = PT_STOP1;
  2093. if (tiosp->c_cflag & PARENB) {
  2094. if (tiosp->c_cflag & PARODD)
  2095. pp->parity = PT_ODDPARITY;
  2096. else
  2097. pp->parity = PT_EVENPARITY;
  2098. } else {
  2099. pp->parity = PT_NOPARITY;
  2100. }
  2101. /*
  2102. * Set up any flow control options enabled.
  2103. */
  2104. if (tiosp->c_iflag & IXON) {
  2105. pp->flow |= F_IXON;
  2106. if (tiosp->c_iflag & IXANY)
  2107. pp->flow |= F_IXANY;
  2108. }
  2109. if (tiosp->c_cflag & CRTSCTS)
  2110. pp->flow |= (F_RTSFLOW | F_CTSFLOW);
  2111. pp->startin = tiosp->c_cc[VSTART];
  2112. pp->stopin = tiosp->c_cc[VSTOP];
  2113. pp->startout = tiosp->c_cc[VSTART];
  2114. pp->stopout = tiosp->c_cc[VSTOP];
  2115. /*
  2116. * Set up the RX char marking mask with those RX error types we must
  2117. * catch. We can get the slave to help us out a little here, it will
  2118. * ignore parity errors and breaks for us, and mark parity errors in
  2119. * the data stream.
  2120. */
  2121. if (tiosp->c_iflag & IGNPAR)
  2122. pp->iflag |= FI_IGNRXERRS;
  2123. if (tiosp->c_iflag & IGNBRK)
  2124. pp->iflag |= FI_IGNBREAK;
  2125. portp->rxmarkmsk = 0;
  2126. if (tiosp->c_iflag & (INPCK | PARMRK))
  2127. pp->iflag |= FI_1MARKRXERRS;
  2128. if (tiosp->c_iflag & BRKINT)
  2129. portp->rxmarkmsk |= BRKINT;
  2130. /*
  2131. * Set up clocal processing as required.
  2132. */
  2133. if (tiosp->c_cflag & CLOCAL)
  2134. portp->port.flags &= ~ASYNC_CHECK_CD;
  2135. else
  2136. portp->port.flags |= ASYNC_CHECK_CD;
  2137. /*
  2138. * Transfer any persistent flags into the asyport structure.
  2139. */
  2140. pp->pflag = (portp->pflag & 0xffff);
  2141. pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
  2142. pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
  2143. pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
  2144. }
  2145. /*****************************************************************************/
  2146. /*
  2147. * Construct a slave signals structure for setting the DTR and RTS
  2148. * signals as specified.
  2149. */
  2150. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
  2151. {
  2152. memset(sp, 0, sizeof(asysigs_t));
  2153. if (dtr >= 0) {
  2154. sp->signal |= SG_DTR;
  2155. sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
  2156. }
  2157. if (rts >= 0) {
  2158. sp->signal |= SG_RTS;
  2159. sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
  2160. }
  2161. }
  2162. /*****************************************************************************/
  2163. /*
  2164. * Convert the signals returned from the slave into a local TIOCM type
  2165. * signals value. We keep them locally in TIOCM format.
  2166. */
  2167. static long stli_mktiocm(unsigned long sigvalue)
  2168. {
  2169. long tiocm = 0;
  2170. tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
  2171. tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
  2172. tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
  2173. tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
  2174. tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
  2175. tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
  2176. return(tiocm);
  2177. }
  2178. /*****************************************************************************/
  2179. /*
  2180. * All panels and ports actually attached have been worked out. All
  2181. * we need to do here is set up the appropriate per port data structures.
  2182. */
  2183. static int stli_initports(struct stlibrd *brdp)
  2184. {
  2185. struct stliport *portp;
  2186. unsigned int i, panelnr, panelport;
  2187. for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
  2188. portp = kzalloc(sizeof(struct stliport), GFP_KERNEL);
  2189. if (!portp) {
  2190. printk(KERN_WARNING "istallion: failed to allocate port structure\n");
  2191. continue;
  2192. }
  2193. tty_port_init(&portp->port);
  2194. portp->port.ops = &stli_port_ops;
  2195. portp->magic = STLI_PORTMAGIC;
  2196. portp->portnr = i;
  2197. portp->brdnr = brdp->brdnr;
  2198. portp->panelnr = panelnr;
  2199. portp->baud_base = STL_BAUDBASE;
  2200. portp->port.close_delay = STL_CLOSEDELAY;
  2201. portp->closing_wait = 30 * HZ;
  2202. init_waitqueue_head(&portp->port.open_wait);
  2203. init_waitqueue_head(&portp->port.close_wait);
  2204. init_waitqueue_head(&portp->raw_wait);
  2205. panelport++;
  2206. if (panelport >= brdp->panels[panelnr]) {
  2207. panelport = 0;
  2208. panelnr++;
  2209. }
  2210. brdp->ports[i] = portp;
  2211. }
  2212. return 0;
  2213. }
  2214. /*****************************************************************************/
  2215. /*
  2216. * All the following routines are board specific hardware operations.
  2217. */
  2218. static void stli_ecpinit(struct stlibrd *brdp)
  2219. {
  2220. unsigned long memconf;
  2221. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2222. udelay(10);
  2223. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2224. udelay(100);
  2225. memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
  2226. outb(memconf, (brdp->iobase + ECP_ATMEMAR));
  2227. }
  2228. /*****************************************************************************/
  2229. static void stli_ecpenable(struct stlibrd *brdp)
  2230. {
  2231. outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
  2232. }
  2233. /*****************************************************************************/
  2234. static void stli_ecpdisable(struct stlibrd *brdp)
  2235. {
  2236. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2237. }
  2238. /*****************************************************************************/
  2239. static void __iomem *stli_ecpgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2240. {
  2241. void __iomem *ptr;
  2242. unsigned char val;
  2243. if (offset > brdp->memsize) {
  2244. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2245. "range at line=%d(%d), brd=%d\n",
  2246. (int) offset, line, __LINE__, brdp->brdnr);
  2247. ptr = NULL;
  2248. val = 0;
  2249. } else {
  2250. ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
  2251. val = (unsigned char) (offset / ECP_ATPAGESIZE);
  2252. }
  2253. outb(val, (brdp->iobase + ECP_ATMEMPR));
  2254. return(ptr);
  2255. }
  2256. /*****************************************************************************/
  2257. static void stli_ecpreset(struct stlibrd *brdp)
  2258. {
  2259. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2260. udelay(10);
  2261. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2262. udelay(500);
  2263. }
  2264. /*****************************************************************************/
  2265. static void stli_ecpintr(struct stlibrd *brdp)
  2266. {
  2267. outb(0x1, brdp->iobase);
  2268. }
  2269. /*****************************************************************************/
  2270. /*
  2271. * The following set of functions act on ECP EISA boards.
  2272. */
  2273. static void stli_ecpeiinit(struct stlibrd *brdp)
  2274. {
  2275. unsigned long memconf;
  2276. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  2277. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2278. udelay(10);
  2279. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2280. udelay(500);
  2281. memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
  2282. outb(memconf, (brdp->iobase + ECP_EIMEMARL));
  2283. memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
  2284. outb(memconf, (brdp->iobase + ECP_EIMEMARH));
  2285. }
  2286. /*****************************************************************************/
  2287. static void stli_ecpeienable(struct stlibrd *brdp)
  2288. {
  2289. outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
  2290. }
  2291. /*****************************************************************************/
  2292. static void stli_ecpeidisable(struct stlibrd *brdp)
  2293. {
  2294. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2295. }
  2296. /*****************************************************************************/
  2297. static void __iomem *stli_ecpeigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2298. {
  2299. void __iomem *ptr;
  2300. unsigned char val;
  2301. if (offset > brdp->memsize) {
  2302. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2303. "range at line=%d(%d), brd=%d\n",
  2304. (int) offset, line, __LINE__, brdp->brdnr);
  2305. ptr = NULL;
  2306. val = 0;
  2307. } else {
  2308. ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
  2309. if (offset < ECP_EIPAGESIZE)
  2310. val = ECP_EIENABLE;
  2311. else
  2312. val = ECP_EIENABLE | 0x40;
  2313. }
  2314. outb(val, (brdp->iobase + ECP_EICONFR));
  2315. return(ptr);
  2316. }
  2317. /*****************************************************************************/
  2318. static void stli_ecpeireset(struct stlibrd *brdp)
  2319. {
  2320. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2321. udelay(10);
  2322. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2323. udelay(500);
  2324. }
  2325. /*****************************************************************************/
  2326. /*
  2327. * The following set of functions act on ECP MCA boards.
  2328. */
  2329. static void stli_ecpmcenable(struct stlibrd *brdp)
  2330. {
  2331. outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
  2332. }
  2333. /*****************************************************************************/
  2334. static void stli_ecpmcdisable(struct stlibrd *brdp)
  2335. {
  2336. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2337. }
  2338. /*****************************************************************************/
  2339. static void __iomem *stli_ecpmcgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2340. {
  2341. void __iomem *ptr;
  2342. unsigned char val;
  2343. if (offset > brdp->memsize) {
  2344. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2345. "range at line=%d(%d), brd=%d\n",
  2346. (int) offset, line, __LINE__, brdp->brdnr);
  2347. ptr = NULL;
  2348. val = 0;
  2349. } else {
  2350. ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
  2351. val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
  2352. }
  2353. outb(val, (brdp->iobase + ECP_MCCONFR));
  2354. return(ptr);
  2355. }
  2356. /*****************************************************************************/
  2357. static void stli_ecpmcreset(struct stlibrd *brdp)
  2358. {
  2359. outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
  2360. udelay(10);
  2361. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2362. udelay(500);
  2363. }
  2364. /*****************************************************************************/
  2365. /*
  2366. * The following set of functions act on ECP PCI boards.
  2367. */
  2368. static void stli_ecppciinit(struct stlibrd *brdp)
  2369. {
  2370. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  2371. udelay(10);
  2372. outb(0, (brdp->iobase + ECP_PCICONFR));
  2373. udelay(500);
  2374. }
  2375. /*****************************************************************************/
  2376. static void __iomem *stli_ecppcigetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2377. {
  2378. void __iomem *ptr;
  2379. unsigned char val;
  2380. if (offset > brdp->memsize) {
  2381. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2382. "range at line=%d(%d), board=%d\n",
  2383. (int) offset, line, __LINE__, brdp->brdnr);
  2384. ptr = NULL;
  2385. val = 0;
  2386. } else {
  2387. ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
  2388. val = (offset / ECP_PCIPAGESIZE) << 1;
  2389. }
  2390. outb(val, (brdp->iobase + ECP_PCICONFR));
  2391. return(ptr);
  2392. }
  2393. /*****************************************************************************/
  2394. static void stli_ecppcireset(struct stlibrd *brdp)
  2395. {
  2396. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  2397. udelay(10);
  2398. outb(0, (brdp->iobase + ECP_PCICONFR));
  2399. udelay(500);
  2400. }
  2401. /*****************************************************************************/
  2402. /*
  2403. * The following routines act on ONboards.
  2404. */
  2405. static void stli_onbinit(struct stlibrd *brdp)
  2406. {
  2407. unsigned long memconf;
  2408. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  2409. udelay(10);
  2410. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  2411. mdelay(1000);
  2412. memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
  2413. outb(memconf, (brdp->iobase + ONB_ATMEMAR));
  2414. outb(0x1, brdp->iobase);
  2415. mdelay(1);
  2416. }
  2417. /*****************************************************************************/
  2418. static void stli_onbenable(struct stlibrd *brdp)
  2419. {
  2420. outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
  2421. }
  2422. /*****************************************************************************/
  2423. static void stli_onbdisable(struct stlibrd *brdp)
  2424. {
  2425. outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
  2426. }
  2427. /*****************************************************************************/
  2428. static void __iomem *stli_onbgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2429. {
  2430. void __iomem *ptr;
  2431. if (offset > brdp->memsize) {
  2432. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2433. "range at line=%d(%d), brd=%d\n",
  2434. (int) offset, line, __LINE__, brdp->brdnr);
  2435. ptr = NULL;
  2436. } else {
  2437. ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
  2438. }
  2439. return(ptr);
  2440. }
  2441. /*****************************************************************************/
  2442. static void stli_onbreset(struct stlibrd *brdp)
  2443. {
  2444. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  2445. udelay(10);
  2446. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  2447. mdelay(1000);
  2448. }
  2449. /*****************************************************************************/
  2450. /*
  2451. * The following routines act on ONboard EISA.
  2452. */
  2453. static void stli_onbeinit(struct stlibrd *brdp)
  2454. {
  2455. unsigned long memconf;
  2456. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  2457. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  2458. udelay(10);
  2459. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2460. mdelay(1000);
  2461. memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
  2462. outb(memconf, (brdp->iobase + ONB_EIMEMARL));
  2463. memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
  2464. outb(memconf, (brdp->iobase + ONB_EIMEMARH));
  2465. outb(0x1, brdp->iobase);
  2466. mdelay(1);
  2467. }
  2468. /*****************************************************************************/
  2469. static void stli_onbeenable(struct stlibrd *brdp)
  2470. {
  2471. outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
  2472. }
  2473. /*****************************************************************************/
  2474. static void stli_onbedisable(struct stlibrd *brdp)
  2475. {
  2476. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2477. }
  2478. /*****************************************************************************/
  2479. static void __iomem *stli_onbegetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2480. {
  2481. void __iomem *ptr;
  2482. unsigned char val;
  2483. if (offset > brdp->memsize) {
  2484. printk(KERN_ERR "istallion: shared memory pointer=%x out of "
  2485. "range at line=%d(%d), brd=%d\n",
  2486. (int) offset, line, __LINE__, brdp->brdnr);
  2487. ptr = NULL;
  2488. val = 0;
  2489. } else {
  2490. ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
  2491. if (offset < ONB_EIPAGESIZE)
  2492. val = ONB_EIENABLE;
  2493. else
  2494. val = ONB_EIENABLE | 0x40;
  2495. }
  2496. outb(val, (brdp->iobase + ONB_EICONFR));
  2497. return(ptr);
  2498. }
  2499. /*****************************************************************************/
  2500. static void stli_onbereset(struct stlibrd *brdp)
  2501. {
  2502. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  2503. udelay(10);
  2504. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2505. mdelay(1000);
  2506. }
  2507. /*****************************************************************************/
  2508. /*
  2509. * The following routines act on Brumby boards.
  2510. */
  2511. static void stli_bbyinit(struct stlibrd *brdp)
  2512. {
  2513. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  2514. udelay(10);
  2515. outb(0, (brdp->iobase + BBY_ATCONFR));
  2516. mdelay(1000);
  2517. outb(0x1, brdp->iobase);
  2518. mdelay(1);
  2519. }
  2520. /*****************************************************************************/
  2521. static void __iomem *stli_bbygetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2522. {
  2523. void __iomem *ptr;
  2524. unsigned char val;
  2525. BUG_ON(offset > brdp->memsize);
  2526. ptr = brdp->membase + (offset % BBY_PAGESIZE);
  2527. val = (unsigned char) (offset / BBY_PAGESIZE);
  2528. outb(val, (brdp->iobase + BBY_ATCONFR));
  2529. return(ptr);
  2530. }
  2531. /*****************************************************************************/
  2532. static void stli_bbyreset(struct stlibrd *brdp)
  2533. {
  2534. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  2535. udelay(10);
  2536. outb(0, (brdp->iobase + BBY_ATCONFR));
  2537. mdelay(1000);
  2538. }
  2539. /*****************************************************************************/
  2540. /*
  2541. * The following routines act on original old Stallion boards.
  2542. */
  2543. static void stli_stalinit(struct stlibrd *brdp)
  2544. {
  2545. outb(0x1, brdp->iobase);
  2546. mdelay(1000);
  2547. }
  2548. /*****************************************************************************/
  2549. static void __iomem *stli_stalgetmemptr(struct stlibrd *brdp, unsigned long offset, int line)
  2550. {
  2551. BUG_ON(offset > brdp->memsize);
  2552. return brdp->membase + (offset % STAL_PAGESIZE);
  2553. }
  2554. /*****************************************************************************/
  2555. static void stli_stalreset(struct stlibrd *brdp)
  2556. {
  2557. u32 __iomem *vecp;
  2558. vecp = (u32 __iomem *) (brdp->membase + 0x30);
  2559. writel(0xffff0000, vecp);
  2560. outb(0, brdp->iobase);
  2561. mdelay(1000);
  2562. }
  2563. /*****************************************************************************/
  2564. /*
  2565. * Try to find an ECP board and initialize it. This handles only ECP
  2566. * board types.
  2567. */
  2568. static int stli_initecp(struct stlibrd *brdp)
  2569. {
  2570. cdkecpsig_t sig;
  2571. cdkecpsig_t __iomem *sigsp;
  2572. unsigned int status, nxtid;
  2573. char *name;
  2574. int retval, panelnr, nrports;
  2575. if ((brdp->iobase == 0) || (brdp->memaddr == 0)) {
  2576. retval = -ENODEV;
  2577. goto err;
  2578. }
  2579. brdp->iosize = ECP_IOSIZE;
  2580. if (!request_region(brdp->iobase, brdp->iosize, "istallion")) {
  2581. retval = -EIO;
  2582. goto err;
  2583. }
  2584. /*
  2585. * Based on the specific board type setup the common vars to access
  2586. * and enable shared memory. Set all board specific information now
  2587. * as well.
  2588. */
  2589. switch (brdp->brdtype) {
  2590. case BRD_ECP:
  2591. brdp->memsize = ECP_MEMSIZE;
  2592. brdp->pagesize = ECP_ATPAGESIZE;
  2593. brdp->init = stli_ecpinit;
  2594. brdp->enable = stli_ecpenable;
  2595. brdp->reenable = stli_ecpenable;
  2596. brdp->disable = stli_ecpdisable;
  2597. brdp->getmemptr = stli_ecpgetmemptr;
  2598. brdp->intr = stli_ecpintr;
  2599. brdp->reset = stli_ecpreset;
  2600. name = "serial(EC8/64)";
  2601. break;
  2602. case BRD_ECPE:
  2603. brdp->memsize = ECP_MEMSIZE;
  2604. brdp->pagesize = ECP_EIPAGESIZE;
  2605. brdp->init = stli_ecpeiinit;
  2606. brdp->enable = stli_ecpeienable;
  2607. brdp->reenable = stli_ecpeienable;
  2608. brdp->disable = stli_ecpeidisable;
  2609. brdp->getmemptr = stli_ecpeigetmemptr;
  2610. brdp->intr = stli_ecpintr;
  2611. brdp->reset = stli_ecpeireset;
  2612. name = "serial(EC8/64-EI)";
  2613. break;
  2614. case BRD_ECPMC:
  2615. brdp->memsize = ECP_MEMSIZE;
  2616. brdp->pagesize = ECP_MCPAGESIZE;
  2617. brdp->init = NULL;
  2618. brdp->enable = stli_ecpmcenable;
  2619. brdp->reenable = stli_ecpmcenable;
  2620. brdp->disable = stli_ecpmcdisable;
  2621. brdp->getmemptr = stli_ecpmcgetmemptr;
  2622. brdp->intr = stli_ecpintr;
  2623. brdp->reset = stli_ecpmcreset;
  2624. name = "serial(EC8/64-MCA)";
  2625. break;
  2626. case BRD_ECPPCI:
  2627. brdp->memsize = ECP_PCIMEMSIZE;
  2628. brdp->pagesize = ECP_PCIPAGESIZE;
  2629. brdp->init = stli_ecppciinit;
  2630. brdp->enable = NULL;
  2631. brdp->reenable = NULL;
  2632. brdp->disable = NULL;
  2633. brdp->getmemptr = stli_ecppcigetmemptr;
  2634. brdp->intr = stli_ecpintr;
  2635. brdp->reset = stli_ecppcireset;
  2636. name = "serial(EC/RA-PCI)";
  2637. break;
  2638. default:
  2639. retval = -EINVAL;
  2640. goto err_reg;
  2641. }
  2642. /*
  2643. * The per-board operations structure is all set up, so now let's go
  2644. * and get the board operational. Firstly initialize board configuration
  2645. * registers. Set the memory mapping info so we can get at the boards
  2646. * shared memory.
  2647. */
  2648. EBRDINIT(brdp);
  2649. brdp->membase = ioremap_nocache(brdp->memaddr, brdp->memsize);
  2650. if (brdp->membase == NULL) {
  2651. retval = -ENOMEM;
  2652. goto err_reg;
  2653. }
  2654. /*
  2655. * Now that all specific code is set up, enable the shared memory and
  2656. * look for the a signature area that will tell us exactly what board
  2657. * this is, and what it is connected to it.
  2658. */
  2659. EBRDENABLE(brdp);
  2660. sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  2661. memcpy_fromio(&sig, sigsp, sizeof(cdkecpsig_t));
  2662. EBRDDISABLE(brdp);
  2663. if (sig.magic != cpu_to_le32(ECP_MAGIC)) {
  2664. retval = -ENODEV;
  2665. goto err_unmap;
  2666. }
  2667. /*
  2668. * Scan through the signature looking at the panels connected to the
  2669. * board. Calculate the total number of ports as we go.
  2670. */
  2671. for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  2672. status = sig.panelid[nxtid];
  2673. if ((status & ECH_PNLIDMASK) != nxtid)
  2674. break;
  2675. brdp->panelids[panelnr] = status;
  2676. nrports = (status & ECH_PNL16PORT) ? 16 : 8;
  2677. if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
  2678. nxtid++;
  2679. brdp->panels[panelnr] = nrports;
  2680. brdp->nrports += nrports;
  2681. nxtid++;
  2682. brdp->nrpanels++;
  2683. }
  2684. set_bit(BST_FOUND, &brdp->state);
  2685. return 0;
  2686. err_unmap:
  2687. iounmap(brdp->membase);
  2688. brdp->membase = NULL;
  2689. err_reg:
  2690. release_region(brdp->iobase, brdp->iosize);
  2691. err:
  2692. return retval;
  2693. }
  2694. /*****************************************************************************/
  2695. /*
  2696. * Try to find an ONboard, Brumby or Stallion board and initialize it.
  2697. * This handles only these board types.
  2698. */
  2699. static int stli_initonb(struct stlibrd *brdp)
  2700. {
  2701. cdkonbsig_t sig;
  2702. cdkonbsig_t __iomem *sigsp;
  2703. char *name;
  2704. int i, retval;
  2705. /*
  2706. * Do a basic sanity check on the IO and memory addresses.
  2707. */
  2708. if (brdp->iobase == 0 || brdp->memaddr == 0) {
  2709. retval = -ENODEV;
  2710. goto err;
  2711. }
  2712. brdp->iosize = ONB_IOSIZE;
  2713. if (!request_region(brdp->iobase, brdp->iosize, "istallion")) {
  2714. retval = -EIO;
  2715. goto err;
  2716. }
  2717. /*
  2718. * Based on the specific board type setup the common vars to access
  2719. * and enable shared memory. Set all board specific information now
  2720. * as well.
  2721. */
  2722. switch (brdp->brdtype) {
  2723. case BRD_ONBOARD:
  2724. case BRD_ONBOARD2:
  2725. brdp->memsize = ONB_MEMSIZE;
  2726. brdp->pagesize = ONB_ATPAGESIZE;
  2727. brdp->init = stli_onbinit;
  2728. brdp->enable = stli_onbenable;
  2729. brdp->reenable = stli_onbenable;
  2730. brdp->disable = stli_onbdisable;
  2731. brdp->getmemptr = stli_onbgetmemptr;
  2732. brdp->intr = stli_ecpintr;
  2733. brdp->reset = stli_onbreset;
  2734. if (brdp->memaddr > 0x100000)
  2735. brdp->enabval = ONB_MEMENABHI;
  2736. else
  2737. brdp->enabval = ONB_MEMENABLO;
  2738. name = "serial(ONBoard)";
  2739. break;
  2740. case BRD_ONBOARDE:
  2741. brdp->memsize = ONB_EIMEMSIZE;
  2742. brdp->pagesize = ONB_EIPAGESIZE;
  2743. brdp->init = stli_onbeinit;
  2744. brdp->enable = stli_onbeenable;
  2745. brdp->reenable = stli_onbeenable;
  2746. brdp->disable = stli_onbedisable;
  2747. brdp->getmemptr = stli_onbegetmemptr;
  2748. brdp->intr = stli_ecpintr;
  2749. brdp->reset = stli_onbereset;
  2750. name = "serial(ONBoard/E)";
  2751. break;
  2752. case BRD_BRUMBY4:
  2753. brdp->memsize = BBY_MEMSIZE;
  2754. brdp->pagesize = BBY_PAGESIZE;
  2755. brdp->init = stli_bbyinit;
  2756. brdp->enable = NULL;
  2757. brdp->reenable = NULL;
  2758. brdp->disable = NULL;
  2759. brdp->getmemptr = stli_bbygetmemptr;
  2760. brdp->intr = stli_ecpintr;
  2761. brdp->reset = stli_bbyreset;
  2762. name = "serial(Brumby)";
  2763. break;
  2764. case BRD_STALLION:
  2765. brdp->memsize = STAL_MEMSIZE;
  2766. brdp->pagesize = STAL_PAGESIZE;
  2767. brdp->init = stli_stalinit;
  2768. brdp->enable = NULL;
  2769. brdp->reenable = NULL;
  2770. brdp->disable = NULL;
  2771. brdp->getmemptr = stli_stalgetmemptr;
  2772. brdp->intr = stli_ecpintr;
  2773. brdp->reset = stli_stalreset;
  2774. name = "serial(Stallion)";
  2775. break;
  2776. default:
  2777. retval = -EINVAL;
  2778. goto err_reg;
  2779. }
  2780. /*
  2781. * The per-board operations structure is all set up, so now let's go
  2782. * and get the board operational. Firstly initialize board configuration
  2783. * registers. Set the memory mapping info so we can get at the boards
  2784. * shared memory.
  2785. */
  2786. EBRDINIT(brdp);
  2787. brdp->membase = ioremap_nocache(brdp->memaddr, brdp->memsize);
  2788. if (brdp->membase == NULL) {
  2789. retval = -ENOMEM;
  2790. goto err_reg;
  2791. }
  2792. /*
  2793. * Now that all specific code is set up, enable the shared memory and
  2794. * look for the a signature area that will tell us exactly what board
  2795. * this is, and how many ports.
  2796. */
  2797. EBRDENABLE(brdp);
  2798. sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  2799. memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
  2800. EBRDDISABLE(brdp);
  2801. if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
  2802. sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
  2803. sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
  2804. sig.magic3 != cpu_to_le16(ONB_MAGIC3)) {
  2805. retval = -ENODEV;
  2806. goto err_unmap;
  2807. }
  2808. /*
  2809. * Scan through the signature alive mask and calculate how many ports
  2810. * there are on this board.
  2811. */
  2812. brdp->nrpanels = 1;
  2813. if (sig.amask1) {
  2814. brdp->nrports = 32;
  2815. } else {
  2816. for (i = 0; (i < 16); i++) {
  2817. if (((sig.amask0 << i) & 0x8000) == 0)
  2818. break;
  2819. }
  2820. brdp->nrports = i;
  2821. }
  2822. brdp->panels[0] = brdp->nrports;
  2823. set_bit(BST_FOUND, &brdp->state);
  2824. return 0;
  2825. err_unmap:
  2826. iounmap(brdp->membase);
  2827. brdp->membase = NULL;
  2828. err_reg:
  2829. release_region(brdp->iobase, brdp->iosize);
  2830. err:
  2831. return retval;
  2832. }
  2833. /*****************************************************************************/
  2834. /*
  2835. * Start up a running board. This routine is only called after the
  2836. * code has been down loaded to the board and is operational. It will
  2837. * read in the memory map, and get the show on the road...
  2838. */
  2839. static int stli_startbrd(struct stlibrd *brdp)
  2840. {
  2841. cdkhdr_t __iomem *hdrp;
  2842. cdkmem_t __iomem *memp;
  2843. cdkasy_t __iomem *ap;
  2844. unsigned long flags;
  2845. unsigned int portnr, nrdevs, i;
  2846. struct stliport *portp;
  2847. int rc = 0;
  2848. u32 memoff;
  2849. spin_lock_irqsave(&brd_lock, flags);
  2850. EBRDENABLE(brdp);
  2851. hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2852. nrdevs = hdrp->nrdevs;
  2853. #if 0
  2854. printk("%s(%d): CDK version %d.%d.%d --> "
  2855. "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
  2856. __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
  2857. readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
  2858. readl(&hdrp->slavep));
  2859. #endif
  2860. if (nrdevs < (brdp->nrports + 1)) {
  2861. printk(KERN_ERR "istallion: slave failed to allocate memory for "
  2862. "all devices, devices=%d\n", nrdevs);
  2863. brdp->nrports = nrdevs - 1;
  2864. }
  2865. brdp->nrdevs = nrdevs;
  2866. brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
  2867. brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
  2868. brdp->bitsize = (nrdevs + 7) / 8;
  2869. memoff = readl(&hdrp->memp);
  2870. if (memoff > brdp->memsize) {
  2871. printk(KERN_ERR "istallion: corrupted shared memory region?\n");
  2872. rc = -EIO;
  2873. goto stli_donestartup;
  2874. }
  2875. memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
  2876. if (readw(&memp->dtype) != TYP_ASYNCTRL) {
  2877. printk(KERN_ERR "istallion: no slave control device found\n");
  2878. goto stli_donestartup;
  2879. }
  2880. memp++;
  2881. /*
  2882. * Cycle through memory allocation of each port. We are guaranteed to
  2883. * have all ports inside the first page of slave window, so no need to
  2884. * change pages while reading memory map.
  2885. */
  2886. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
  2887. if (readw(&memp->dtype) != TYP_ASYNC)
  2888. break;
  2889. portp = brdp->ports[portnr];
  2890. if (portp == NULL)
  2891. break;
  2892. portp->devnr = i;
  2893. portp->addr = readl(&memp->offset);
  2894. portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
  2895. portp->portidx = (unsigned char) (i / 8);
  2896. portp->portbit = (unsigned char) (0x1 << (i % 8));
  2897. }
  2898. writeb(0xff, &hdrp->slavereq);
  2899. /*
  2900. * For each port setup a local copy of the RX and TX buffer offsets
  2901. * and sizes. We do this separate from the above, because we need to
  2902. * move the shared memory page...
  2903. */
  2904. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
  2905. portp = brdp->ports[portnr];
  2906. if (portp == NULL)
  2907. break;
  2908. if (portp->addr == 0)
  2909. break;
  2910. ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
  2911. if (ap != NULL) {
  2912. portp->rxsize = readw(&ap->rxq.size);
  2913. portp->txsize = readw(&ap->txq.size);
  2914. portp->rxoffset = readl(&ap->rxq.offset);
  2915. portp->txoffset = readl(&ap->txq.offset);
  2916. }
  2917. }
  2918. stli_donestartup:
  2919. EBRDDISABLE(brdp);
  2920. spin_unlock_irqrestore(&brd_lock, flags);
  2921. if (rc == 0)
  2922. set_bit(BST_STARTED, &brdp->state);
  2923. if (! stli_timeron) {
  2924. stli_timeron++;
  2925. mod_timer(&stli_timerlist, STLI_TIMEOUT);
  2926. }
  2927. return rc;
  2928. }
  2929. /*****************************************************************************/
  2930. /*
  2931. * Probe and initialize the specified board.
  2932. */
  2933. static int __devinit stli_brdinit(struct stlibrd *brdp)
  2934. {
  2935. int retval;
  2936. switch (brdp->brdtype) {
  2937. case BRD_ECP:
  2938. case BRD_ECPE:
  2939. case BRD_ECPMC:
  2940. case BRD_ECPPCI:
  2941. retval = stli_initecp(brdp);
  2942. break;
  2943. case BRD_ONBOARD:
  2944. case BRD_ONBOARDE:
  2945. case BRD_ONBOARD2:
  2946. case BRD_BRUMBY4:
  2947. case BRD_STALLION:
  2948. retval = stli_initonb(brdp);
  2949. break;
  2950. default:
  2951. printk(KERN_ERR "istallion: board=%d is unknown board "
  2952. "type=%d\n", brdp->brdnr, brdp->brdtype);
  2953. retval = -ENODEV;
  2954. }
  2955. if (retval)
  2956. return retval;
  2957. stli_initports(brdp);
  2958. printk(KERN_INFO "istallion: %s found, board=%d io=%x mem=%x "
  2959. "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
  2960. brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
  2961. brdp->nrpanels, brdp->nrports);
  2962. return 0;
  2963. }
  2964. #if STLI_EISAPROBE != 0
  2965. /*****************************************************************************/
  2966. /*
  2967. * Probe around trying to find where the EISA boards shared memory
  2968. * might be. This is a bit if hack, but it is the best we can do.
  2969. */
  2970. static int stli_eisamemprobe(struct stlibrd *brdp)
  2971. {
  2972. cdkecpsig_t ecpsig, __iomem *ecpsigp;
  2973. cdkonbsig_t onbsig, __iomem *onbsigp;
  2974. int i, foundit;
  2975. /*
  2976. * First up we reset the board, to get it into a known state. There
  2977. * is only 2 board types here we need to worry about. Don;t use the
  2978. * standard board init routine here, it programs up the shared
  2979. * memory address, and we don't know it yet...
  2980. */
  2981. if (brdp->brdtype == BRD_ECPE) {
  2982. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  2983. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2984. udelay(10);
  2985. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2986. udelay(500);
  2987. stli_ecpeienable(brdp);
  2988. } else if (brdp->brdtype == BRD_ONBOARDE) {
  2989. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  2990. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  2991. udelay(10);
  2992. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  2993. mdelay(100);
  2994. outb(0x1, brdp->iobase);
  2995. mdelay(1);
  2996. stli_onbeenable(brdp);
  2997. } else {
  2998. return -ENODEV;
  2999. }
  3000. foundit = 0;
  3001. brdp->memsize = ECP_MEMSIZE;
  3002. /*
  3003. * Board shared memory is enabled, so now we have a poke around and
  3004. * see if we can find it.
  3005. */
  3006. for (i = 0; (i < stli_eisamempsize); i++) {
  3007. brdp->memaddr = stli_eisamemprobeaddrs[i];
  3008. brdp->membase = ioremap_nocache(brdp->memaddr, brdp->memsize);
  3009. if (brdp->membase == NULL)
  3010. continue;
  3011. if (brdp->brdtype == BRD_ECPE) {
  3012. ecpsigp = stli_ecpeigetmemptr(brdp,
  3013. CDK_SIGADDR, __LINE__);
  3014. memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
  3015. if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
  3016. foundit = 1;
  3017. } else {
  3018. onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
  3019. CDK_SIGADDR, __LINE__);
  3020. memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
  3021. if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
  3022. (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
  3023. (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
  3024. (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
  3025. foundit = 1;
  3026. }
  3027. iounmap(brdp->membase);
  3028. if (foundit)
  3029. break;
  3030. }
  3031. /*
  3032. * Regardless of whether we found the shared memory or not we must
  3033. * disable the region. After that return success or failure.
  3034. */
  3035. if (brdp->brdtype == BRD_ECPE)
  3036. stli_ecpeidisable(brdp);
  3037. else
  3038. stli_onbedisable(brdp);
  3039. if (! foundit) {
  3040. brdp->memaddr = 0;
  3041. brdp->membase = NULL;
  3042. printk(KERN_ERR "istallion: failed to probe shared memory "
  3043. "region for %s in EISA slot=%d\n",
  3044. stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
  3045. return -ENODEV;
  3046. }
  3047. return 0;
  3048. }
  3049. #endif
  3050. static int stli_getbrdnr(void)
  3051. {
  3052. unsigned int i;
  3053. for (i = 0; i < STL_MAXBRDS; i++) {
  3054. if (!stli_brds[i]) {
  3055. if (i >= stli_nrbrds)
  3056. stli_nrbrds = i + 1;
  3057. return i;
  3058. }
  3059. }
  3060. return -1;
  3061. }
  3062. #if STLI_EISAPROBE != 0
  3063. /*****************************************************************************/
  3064. /*
  3065. * Probe around and try to find any EISA boards in system. The biggest
  3066. * problem here is finding out what memory address is associated with
  3067. * an EISA board after it is found. The registers of the ECPE and
  3068. * ONboardE are not readable - so we can't read them from there. We
  3069. * don't have access to the EISA CMOS (or EISA BIOS) so we don't
  3070. * actually have any way to find out the real value. The best we can
  3071. * do is go probing around in the usual places hoping we can find it.
  3072. */
  3073. static int __init stli_findeisabrds(void)
  3074. {
  3075. struct stlibrd *brdp;
  3076. unsigned int iobase, eid, i;
  3077. int brdnr, found = 0;
  3078. /*
  3079. * Firstly check if this is an EISA system. If this is not an EISA system then
  3080. * don't bother going any further!
  3081. */
  3082. if (EISA_bus)
  3083. return 0;
  3084. /*
  3085. * Looks like an EISA system, so go searching for EISA boards.
  3086. */
  3087. for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
  3088. outb(0xff, (iobase + 0xc80));
  3089. eid = inb(iobase + 0xc80);
  3090. eid |= inb(iobase + 0xc81) << 8;
  3091. if (eid != STL_EISAID)
  3092. continue;
  3093. /*
  3094. * We have found a board. Need to check if this board was
  3095. * statically configured already (just in case!).
  3096. */
  3097. for (i = 0; (i < STL_MAXBRDS); i++) {
  3098. brdp = stli_brds[i];
  3099. if (brdp == NULL)
  3100. continue;
  3101. if (brdp->iobase == iobase)
  3102. break;
  3103. }
  3104. if (i < STL_MAXBRDS)
  3105. continue;
  3106. /*
  3107. * We have found a Stallion board and it is not configured already.
  3108. * Allocate a board structure and initialize it.
  3109. */
  3110. if ((brdp = stli_allocbrd()) == NULL)
  3111. return found ? : -ENOMEM;
  3112. brdnr = stli_getbrdnr();
  3113. if (brdnr < 0)
  3114. return found ? : -ENOMEM;
  3115. brdp->brdnr = (unsigned int)brdnr;
  3116. eid = inb(iobase + 0xc82);
  3117. if (eid == ECP_EISAID)
  3118. brdp->brdtype = BRD_ECPE;
  3119. else if (eid == ONB_EISAID)
  3120. brdp->brdtype = BRD_ONBOARDE;
  3121. else
  3122. brdp->brdtype = BRD_UNKNOWN;
  3123. brdp->iobase = iobase;
  3124. outb(0x1, (iobase + 0xc84));
  3125. if (stli_eisamemprobe(brdp))
  3126. outb(0, (iobase + 0xc84));
  3127. if (stli_brdinit(brdp) < 0) {
  3128. kfree(brdp);
  3129. continue;
  3130. }
  3131. stli_brds[brdp->brdnr] = brdp;
  3132. found++;
  3133. for (i = 0; i < brdp->nrports; i++)
  3134. tty_register_device(stli_serial,
  3135. brdp->brdnr * STL_MAXPORTS + i, NULL);
  3136. }
  3137. return found;
  3138. }
  3139. #else
  3140. static inline int stli_findeisabrds(void) { return 0; }
  3141. #endif
  3142. /*****************************************************************************/
  3143. /*
  3144. * Find the next available board number that is free.
  3145. */
  3146. /*****************************************************************************/
  3147. /*
  3148. * We have a Stallion board. Allocate a board structure and
  3149. * initialize it. Read its IO and MEMORY resources from PCI
  3150. * configuration space.
  3151. */
  3152. static int __devinit stli_pciprobe(struct pci_dev *pdev,
  3153. const struct pci_device_id *ent)
  3154. {
  3155. struct stlibrd *brdp;
  3156. unsigned int i;
  3157. int brdnr, retval = -EIO;
  3158. retval = pci_enable_device(pdev);
  3159. if (retval)
  3160. goto err;
  3161. brdp = stli_allocbrd();
  3162. if (brdp == NULL) {
  3163. retval = -ENOMEM;
  3164. goto err;
  3165. }
  3166. mutex_lock(&stli_brdslock);
  3167. brdnr = stli_getbrdnr();
  3168. if (brdnr < 0) {
  3169. printk(KERN_INFO "istallion: too many boards found, "
  3170. "maximum supported %d\n", STL_MAXBRDS);
  3171. mutex_unlock(&stli_brdslock);
  3172. retval = -EIO;
  3173. goto err_fr;
  3174. }
  3175. brdp->brdnr = (unsigned int)brdnr;
  3176. stli_brds[brdp->brdnr] = brdp;
  3177. mutex_unlock(&stli_brdslock);
  3178. brdp->brdtype = BRD_ECPPCI;
  3179. /*
  3180. * We have all resources from the board, so lets setup the actual
  3181. * board structure now.
  3182. */
  3183. brdp->iobase = pci_resource_start(pdev, 3);
  3184. brdp->memaddr = pci_resource_start(pdev, 2);
  3185. retval = stli_brdinit(brdp);
  3186. if (retval)
  3187. goto err_null;
  3188. set_bit(BST_PROBED, &brdp->state);
  3189. pci_set_drvdata(pdev, brdp);
  3190. EBRDENABLE(brdp);
  3191. brdp->enable = NULL;
  3192. brdp->disable = NULL;
  3193. for (i = 0; i < brdp->nrports; i++)
  3194. tty_register_device(stli_serial, brdp->brdnr * STL_MAXPORTS + i,
  3195. &pdev->dev);
  3196. return 0;
  3197. err_null:
  3198. stli_brds[brdp->brdnr] = NULL;
  3199. err_fr:
  3200. kfree(brdp);
  3201. err:
  3202. return retval;
  3203. }
  3204. static void __devexit stli_pciremove(struct pci_dev *pdev)
  3205. {
  3206. struct stlibrd *brdp = pci_get_drvdata(pdev);
  3207. stli_cleanup_ports(brdp);
  3208. iounmap(brdp->membase);
  3209. if (brdp->iosize > 0)
  3210. release_region(brdp->iobase, brdp->iosize);
  3211. stli_brds[brdp->brdnr] = NULL;
  3212. kfree(brdp);
  3213. }
  3214. static struct pci_driver stli_pcidriver = {
  3215. .name = "istallion",
  3216. .id_table = istallion_pci_tbl,
  3217. .probe = stli_pciprobe,
  3218. .remove = __devexit_p(stli_pciremove)
  3219. };
  3220. /*****************************************************************************/
  3221. /*
  3222. * Allocate a new board structure. Fill out the basic info in it.
  3223. */
  3224. static struct stlibrd *stli_allocbrd(void)
  3225. {
  3226. struct stlibrd *brdp;
  3227. brdp = kzalloc(sizeof(struct stlibrd), GFP_KERNEL);
  3228. if (!brdp) {
  3229. printk(KERN_ERR "istallion: failed to allocate memory "
  3230. "(size=%Zd)\n", sizeof(struct stlibrd));
  3231. return NULL;
  3232. }
  3233. brdp->magic = STLI_BOARDMAGIC;
  3234. return brdp;
  3235. }
  3236. /*****************************************************************************/
  3237. /*
  3238. * Scan through all the boards in the configuration and see what we
  3239. * can find.
  3240. */
  3241. static int __init stli_initbrds(void)
  3242. {
  3243. struct stlibrd *brdp, *nxtbrdp;
  3244. struct stlconf conf;
  3245. unsigned int i, j, found = 0;
  3246. int retval;
  3247. for (stli_nrbrds = 0; stli_nrbrds < ARRAY_SIZE(stli_brdsp);
  3248. stli_nrbrds++) {
  3249. memset(&conf, 0, sizeof(conf));
  3250. if (stli_parsebrd(&conf, stli_brdsp[stli_nrbrds]) == 0)
  3251. continue;
  3252. if ((brdp = stli_allocbrd()) == NULL)
  3253. continue;
  3254. brdp->brdnr = stli_nrbrds;
  3255. brdp->brdtype = conf.brdtype;
  3256. brdp->iobase = conf.ioaddr1;
  3257. brdp->memaddr = conf.memaddr;
  3258. if (stli_brdinit(brdp) < 0) {
  3259. kfree(brdp);
  3260. continue;
  3261. }
  3262. stli_brds[brdp->brdnr] = brdp;
  3263. found++;
  3264. for (i = 0; i < brdp->nrports; i++)
  3265. tty_register_device(stli_serial,
  3266. brdp->brdnr * STL_MAXPORTS + i, NULL);
  3267. }
  3268. retval = stli_findeisabrds();
  3269. if (retval > 0)
  3270. found += retval;
  3271. /*
  3272. * All found boards are initialized. Now for a little optimization, if
  3273. * no boards are sharing the "shared memory" regions then we can just
  3274. * leave them all enabled. This is in fact the usual case.
  3275. */
  3276. stli_shared = 0;
  3277. if (stli_nrbrds > 1) {
  3278. for (i = 0; (i < stli_nrbrds); i++) {
  3279. brdp = stli_brds[i];
  3280. if (brdp == NULL)
  3281. continue;
  3282. for (j = i + 1; (j < stli_nrbrds); j++) {
  3283. nxtbrdp = stli_brds[j];
  3284. if (nxtbrdp == NULL)
  3285. continue;
  3286. if ((brdp->membase >= nxtbrdp->membase) &&
  3287. (brdp->membase <= (nxtbrdp->membase +
  3288. nxtbrdp->memsize - 1))) {
  3289. stli_shared++;
  3290. break;
  3291. }
  3292. }
  3293. }
  3294. }
  3295. if (stli_shared == 0) {
  3296. for (i = 0; (i < stli_nrbrds); i++) {
  3297. brdp = stli_brds[i];
  3298. if (brdp == NULL)
  3299. continue;
  3300. if (test_bit(BST_FOUND, &brdp->state)) {
  3301. EBRDENABLE(brdp);
  3302. brdp->enable = NULL;
  3303. brdp->disable = NULL;
  3304. }
  3305. }
  3306. }
  3307. retval = pci_register_driver(&stli_pcidriver);
  3308. if (retval && found == 0) {
  3309. printk(KERN_ERR "Neither isa nor eisa cards found nor pci "
  3310. "driver can be registered!\n");
  3311. goto err;
  3312. }
  3313. return 0;
  3314. err:
  3315. return retval;
  3316. }
  3317. /*****************************************************************************/
  3318. /*
  3319. * Code to handle an "staliomem" read operation. This device is the
  3320. * contents of the board shared memory. It is used for down loading
  3321. * the slave image (and debugging :-)
  3322. */
  3323. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
  3324. {
  3325. unsigned long flags;
  3326. void __iomem *memptr;
  3327. struct stlibrd *brdp;
  3328. unsigned int brdnr;
  3329. int size, n;
  3330. void *p;
  3331. loff_t off = *offp;
  3332. brdnr = iminor(fp->f_path.dentry->d_inode);
  3333. if (brdnr >= stli_nrbrds)
  3334. return -ENODEV;
  3335. brdp = stli_brds[brdnr];
  3336. if (brdp == NULL)
  3337. return -ENODEV;
  3338. if (brdp->state == 0)
  3339. return -ENODEV;
  3340. if (off >= brdp->memsize || off + count < off)
  3341. return 0;
  3342. size = min(count, (size_t)(brdp->memsize - off));
  3343. /*
  3344. * Copy the data a page at a time
  3345. */
  3346. p = (void *)__get_free_page(GFP_KERNEL);
  3347. if(p == NULL)
  3348. return -ENOMEM;
  3349. while (size > 0) {
  3350. spin_lock_irqsave(&brd_lock, flags);
  3351. EBRDENABLE(brdp);
  3352. memptr = EBRDGETMEMPTR(brdp, off);
  3353. n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
  3354. n = min(n, (int)PAGE_SIZE);
  3355. memcpy_fromio(p, memptr, n);
  3356. EBRDDISABLE(brdp);
  3357. spin_unlock_irqrestore(&brd_lock, flags);
  3358. if (copy_to_user(buf, p, n)) {
  3359. count = -EFAULT;
  3360. goto out;
  3361. }
  3362. off += n;
  3363. buf += n;
  3364. size -= n;
  3365. }
  3366. out:
  3367. *offp = off;
  3368. free_page((unsigned long)p);
  3369. return count;
  3370. }
  3371. /*****************************************************************************/
  3372. /*
  3373. * Code to handle an "staliomem" write operation. This device is the
  3374. * contents of the board shared memory. It is used for down loading
  3375. * the slave image (and debugging :-)
  3376. *
  3377. * FIXME: copy under lock
  3378. */
  3379. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
  3380. {
  3381. unsigned long flags;
  3382. void __iomem *memptr;
  3383. struct stlibrd *brdp;
  3384. char __user *chbuf;
  3385. unsigned int brdnr;
  3386. int size, n;
  3387. void *p;
  3388. loff_t off = *offp;
  3389. brdnr = iminor(fp->f_path.dentry->d_inode);
  3390. if (brdnr >= stli_nrbrds)
  3391. return -ENODEV;
  3392. brdp = stli_brds[brdnr];
  3393. if (brdp == NULL)
  3394. return -ENODEV;
  3395. if (brdp->state == 0)
  3396. return -ENODEV;
  3397. if (off >= brdp->memsize || off + count < off)
  3398. return 0;
  3399. chbuf = (char __user *) buf;
  3400. size = min(count, (size_t)(brdp->memsize - off));
  3401. /*
  3402. * Copy the data a page at a time
  3403. */
  3404. p = (void *)__get_free_page(GFP_KERNEL);
  3405. if(p == NULL)
  3406. return -ENOMEM;
  3407. while (size > 0) {
  3408. n = min(size, (int)(brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
  3409. n = min(n, (int)PAGE_SIZE);
  3410. if (copy_from_user(p, chbuf, n)) {
  3411. if (count == 0)
  3412. count = -EFAULT;
  3413. goto out;
  3414. }
  3415. spin_lock_irqsave(&brd_lock, flags);
  3416. EBRDENABLE(brdp);
  3417. memptr = EBRDGETMEMPTR(brdp, off);
  3418. memcpy_toio(memptr, p, n);
  3419. EBRDDISABLE(brdp);
  3420. spin_unlock_irqrestore(&brd_lock, flags);
  3421. off += n;
  3422. chbuf += n;
  3423. size -= n;
  3424. }
  3425. out:
  3426. free_page((unsigned long) p);
  3427. *offp = off;
  3428. return count;
  3429. }
  3430. /*****************************************************************************/
  3431. /*
  3432. * Return the board stats structure to user app.
  3433. */
  3434. static int stli_getbrdstats(combrd_t __user *bp)
  3435. {
  3436. struct stlibrd *brdp;
  3437. unsigned int i;
  3438. if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
  3439. return -EFAULT;
  3440. if (stli_brdstats.brd >= STL_MAXBRDS)
  3441. return -ENODEV;
  3442. brdp = stli_brds[stli_brdstats.brd];
  3443. if (brdp == NULL)
  3444. return -ENODEV;
  3445. memset(&stli_brdstats, 0, sizeof(combrd_t));
  3446. stli_brdstats.brd = brdp->brdnr;
  3447. stli_brdstats.type = brdp->brdtype;
  3448. stli_brdstats.hwid = 0;
  3449. stli_brdstats.state = brdp->state;
  3450. stli_brdstats.ioaddr = brdp->iobase;
  3451. stli_brdstats.memaddr = brdp->memaddr;
  3452. stli_brdstats.nrpanels = brdp->nrpanels;
  3453. stli_brdstats.nrports = brdp->nrports;
  3454. for (i = 0; (i < brdp->nrpanels); i++) {
  3455. stli_brdstats.panels[i].panel = i;
  3456. stli_brdstats.panels[i].hwid = brdp->panelids[i];
  3457. stli_brdstats.panels[i].nrports = brdp->panels[i];
  3458. }
  3459. if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
  3460. return -EFAULT;
  3461. return 0;
  3462. }
  3463. /*****************************************************************************/
  3464. /*
  3465. * Resolve the referenced port number into a port struct pointer.
  3466. */
  3467. static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr,
  3468. unsigned int portnr)
  3469. {
  3470. struct stlibrd *brdp;
  3471. unsigned int i;
  3472. if (brdnr >= STL_MAXBRDS)
  3473. return NULL;
  3474. brdp = stli_brds[brdnr];
  3475. if (brdp == NULL)
  3476. return NULL;
  3477. for (i = 0; (i < panelnr); i++)
  3478. portnr += brdp->panels[i];
  3479. if (portnr >= brdp->nrports)
  3480. return NULL;
  3481. return brdp->ports[portnr];
  3482. }
  3483. /*****************************************************************************/
  3484. /*
  3485. * Return the port stats structure to user app. A NULL port struct
  3486. * pointer passed in means that we need to find out from the app
  3487. * what port to get stats for (used through board control device).
  3488. */
  3489. static int stli_portcmdstats(struct tty_struct *tty, struct stliport *portp)
  3490. {
  3491. unsigned long flags;
  3492. struct stlibrd *brdp;
  3493. int rc;
  3494. memset(&stli_comstats, 0, sizeof(comstats_t));
  3495. if (portp == NULL)
  3496. return -ENODEV;
  3497. brdp = stli_brds[portp->brdnr];
  3498. if (brdp == NULL)
  3499. return -ENODEV;
  3500. mutex_lock(&portp->port.mutex);
  3501. if (test_bit(BST_STARTED, &brdp->state)) {
  3502. if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
  3503. &stli_cdkstats, sizeof(asystats_t), 1)) < 0) {
  3504. mutex_unlock(&portp->port.mutex);
  3505. return rc;
  3506. }
  3507. } else {
  3508. memset(&stli_cdkstats, 0, sizeof(asystats_t));
  3509. }
  3510. stli_comstats.brd = portp->brdnr;
  3511. stli_comstats.panel = portp->panelnr;
  3512. stli_comstats.port = portp->portnr;
  3513. stli_comstats.state = portp->state;
  3514. stli_comstats.flags = portp->port.flags;
  3515. spin_lock_irqsave(&brd_lock, flags);
  3516. if (tty != NULL) {
  3517. if (portp->port.tty == tty) {
  3518. stli_comstats.ttystate = tty->flags;
  3519. stli_comstats.rxbuffered = -1;
  3520. if (tty->termios != NULL) {
  3521. stli_comstats.cflags = tty->termios->c_cflag;
  3522. stli_comstats.iflags = tty->termios->c_iflag;
  3523. stli_comstats.oflags = tty->termios->c_oflag;
  3524. stli_comstats.lflags = tty->termios->c_lflag;
  3525. }
  3526. }
  3527. }
  3528. spin_unlock_irqrestore(&brd_lock, flags);
  3529. stli_comstats.txtotal = stli_cdkstats.txchars;
  3530. stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
  3531. stli_comstats.txbuffered = stli_cdkstats.txringq;
  3532. stli_comstats.rxbuffered += stli_cdkstats.rxringq;
  3533. stli_comstats.rxoverrun = stli_cdkstats.overruns;
  3534. stli_comstats.rxparity = stli_cdkstats.parity;
  3535. stli_comstats.rxframing = stli_cdkstats.framing;
  3536. stli_comstats.rxlost = stli_cdkstats.ringover;
  3537. stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
  3538. stli_comstats.txbreaks = stli_cdkstats.txbreaks;
  3539. stli_comstats.txxon = stli_cdkstats.txstart;
  3540. stli_comstats.txxoff = stli_cdkstats.txstop;
  3541. stli_comstats.rxxon = stli_cdkstats.rxstart;
  3542. stli_comstats.rxxoff = stli_cdkstats.rxstop;
  3543. stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
  3544. stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
  3545. stli_comstats.modem = stli_cdkstats.dcdcnt;
  3546. stli_comstats.hwid = stli_cdkstats.hwid;
  3547. stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
  3548. mutex_unlock(&portp->port.mutex);
  3549. return 0;
  3550. }
  3551. /*****************************************************************************/
  3552. /*
  3553. * Return the port stats structure to user app. A NULL port struct
  3554. * pointer passed in means that we need to find out from the app
  3555. * what port to get stats for (used through board control device).
  3556. */
  3557. static int stli_getportstats(struct tty_struct *tty, struct stliport *portp,
  3558. comstats_t __user *cp)
  3559. {
  3560. struct stlibrd *brdp;
  3561. int rc;
  3562. if (!portp) {
  3563. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  3564. return -EFAULT;
  3565. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  3566. stli_comstats.port);
  3567. if (!portp)
  3568. return -ENODEV;
  3569. }
  3570. brdp = stli_brds[portp->brdnr];
  3571. if (!brdp)
  3572. return -ENODEV;
  3573. if ((rc = stli_portcmdstats(tty, portp)) < 0)
  3574. return rc;
  3575. return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
  3576. -EFAULT : 0;
  3577. }
  3578. /*****************************************************************************/
  3579. /*
  3580. * Clear the port stats structure. We also return it zeroed out...
  3581. */
  3582. static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp)
  3583. {
  3584. struct stlibrd *brdp;
  3585. int rc;
  3586. if (!portp) {
  3587. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  3588. return -EFAULT;
  3589. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  3590. stli_comstats.port);
  3591. if (!portp)
  3592. return -ENODEV;
  3593. }
  3594. brdp = stli_brds[portp->brdnr];
  3595. if (!brdp)
  3596. return -ENODEV;
  3597. mutex_lock(&portp->port.mutex);
  3598. if (test_bit(BST_STARTED, &brdp->state)) {
  3599. if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0) {
  3600. mutex_unlock(&portp->port.mutex);
  3601. return rc;
  3602. }
  3603. }
  3604. memset(&stli_comstats, 0, sizeof(comstats_t));
  3605. stli_comstats.brd = portp->brdnr;
  3606. stli_comstats.panel = portp->panelnr;
  3607. stli_comstats.port = portp->portnr;
  3608. mutex_unlock(&portp->port.mutex);
  3609. if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
  3610. return -EFAULT;
  3611. return 0;
  3612. }
  3613. /*****************************************************************************/
  3614. /*
  3615. * Return the entire driver ports structure to a user app.
  3616. */
  3617. static int stli_getportstruct(struct stliport __user *arg)
  3618. {
  3619. struct stliport stli_dummyport;
  3620. struct stliport *portp;
  3621. if (copy_from_user(&stli_dummyport, arg, sizeof(struct stliport)))
  3622. return -EFAULT;
  3623. portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
  3624. stli_dummyport.portnr);
  3625. if (!portp)
  3626. return -ENODEV;
  3627. if (copy_to_user(arg, portp, sizeof(struct stliport)))
  3628. return -EFAULT;
  3629. return 0;
  3630. }
  3631. /*****************************************************************************/
  3632. /*
  3633. * Return the entire driver board structure to a user app.
  3634. */
  3635. static int stli_getbrdstruct(struct stlibrd __user *arg)
  3636. {
  3637. struct stlibrd stli_dummybrd;
  3638. struct stlibrd *brdp;
  3639. if (copy_from_user(&stli_dummybrd, arg, sizeof(struct stlibrd)))
  3640. return -EFAULT;
  3641. if (stli_dummybrd.brdnr >= STL_MAXBRDS)
  3642. return -ENODEV;
  3643. brdp = stli_brds[stli_dummybrd.brdnr];
  3644. if (!brdp)
  3645. return -ENODEV;
  3646. if (copy_to_user(arg, brdp, sizeof(struct stlibrd)))
  3647. return -EFAULT;
  3648. return 0;
  3649. }
  3650. /*****************************************************************************/
  3651. /*
  3652. * The "staliomem" device is also required to do some special operations on
  3653. * the board. We need to be able to send an interrupt to the board,
  3654. * reset it, and start/stop it.
  3655. */
  3656. static long stli_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
  3657. {
  3658. struct stlibrd *brdp;
  3659. int brdnr, rc, done;
  3660. void __user *argp = (void __user *)arg;
  3661. /*
  3662. * First up handle the board independent ioctls.
  3663. */
  3664. done = 0;
  3665. rc = 0;
  3666. switch (cmd) {
  3667. case COM_GETPORTSTATS:
  3668. rc = stli_getportstats(NULL, NULL, argp);
  3669. done++;
  3670. break;
  3671. case COM_CLRPORTSTATS:
  3672. rc = stli_clrportstats(NULL, argp);
  3673. done++;
  3674. break;
  3675. case COM_GETBRDSTATS:
  3676. rc = stli_getbrdstats(argp);
  3677. done++;
  3678. break;
  3679. case COM_READPORT:
  3680. rc = stli_getportstruct(argp);
  3681. done++;
  3682. break;
  3683. case COM_READBOARD:
  3684. rc = stli_getbrdstruct(argp);
  3685. done++;
  3686. break;
  3687. }
  3688. if (done)
  3689. return rc;
  3690. /*
  3691. * Now handle the board specific ioctls. These all depend on the
  3692. * minor number of the device they were called from.
  3693. */
  3694. brdnr = iminor(fp->f_dentry->d_inode);
  3695. if (brdnr >= STL_MAXBRDS)
  3696. return -ENODEV;
  3697. brdp = stli_brds[brdnr];
  3698. if (!brdp)
  3699. return -ENODEV;
  3700. if (brdp->state == 0)
  3701. return -ENODEV;
  3702. switch (cmd) {
  3703. case STL_BINTR:
  3704. EBRDINTR(brdp);
  3705. break;
  3706. case STL_BSTART:
  3707. rc = stli_startbrd(brdp);
  3708. break;
  3709. case STL_BSTOP:
  3710. clear_bit(BST_STARTED, &brdp->state);
  3711. break;
  3712. case STL_BRESET:
  3713. clear_bit(BST_STARTED, &brdp->state);
  3714. EBRDRESET(brdp);
  3715. if (stli_shared == 0) {
  3716. if (brdp->reenable != NULL)
  3717. (* brdp->reenable)(brdp);
  3718. }
  3719. break;
  3720. default:
  3721. rc = -ENOIOCTLCMD;
  3722. break;
  3723. }
  3724. return rc;
  3725. }
  3726. static const struct tty_operations stli_ops = {
  3727. .open = stli_open,
  3728. .close = stli_close,
  3729. .write = stli_write,
  3730. .put_char = stli_putchar,
  3731. .flush_chars = stli_flushchars,
  3732. .write_room = stli_writeroom,
  3733. .chars_in_buffer = stli_charsinbuffer,
  3734. .ioctl = stli_ioctl,
  3735. .set_termios = stli_settermios,
  3736. .throttle = stli_throttle,
  3737. .unthrottle = stli_unthrottle,
  3738. .stop = stli_stop,
  3739. .start = stli_start,
  3740. .hangup = stli_hangup,
  3741. .flush_buffer = stli_flushbuffer,
  3742. .break_ctl = stli_breakctl,
  3743. .wait_until_sent = stli_waituntilsent,
  3744. .send_xchar = stli_sendxchar,
  3745. .tiocmget = stli_tiocmget,
  3746. .tiocmset = stli_tiocmset,
  3747. .proc_fops = &stli_proc_fops,
  3748. };
  3749. static const struct tty_port_operations stli_port_ops = {
  3750. .carrier_raised = stli_carrier_raised,
  3751. .dtr_rts = stli_dtr_rts,
  3752. .activate = stli_activate,
  3753. .shutdown = stli_shutdown,
  3754. };
  3755. /*****************************************************************************/
  3756. /*
  3757. * Loadable module initialization stuff.
  3758. */
  3759. static void istallion_cleanup_isa(void)
  3760. {
  3761. struct stlibrd *brdp;
  3762. unsigned int j;
  3763. for (j = 0; (j < stli_nrbrds); j++) {
  3764. if ((brdp = stli_brds[j]) == NULL ||
  3765. test_bit(BST_PROBED, &brdp->state))
  3766. continue;
  3767. stli_cleanup_ports(brdp);
  3768. iounmap(brdp->membase);
  3769. if (brdp->iosize > 0)
  3770. release_region(brdp->iobase, brdp->iosize);
  3771. kfree(brdp);
  3772. stli_brds[j] = NULL;
  3773. }
  3774. }
  3775. static int __init istallion_module_init(void)
  3776. {
  3777. unsigned int i;
  3778. int retval;
  3779. printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
  3780. spin_lock_init(&stli_lock);
  3781. spin_lock_init(&brd_lock);
  3782. stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
  3783. if (!stli_txcookbuf) {
  3784. printk(KERN_ERR "istallion: failed to allocate memory "
  3785. "(size=%d)\n", STLI_TXBUFSIZE);
  3786. retval = -ENOMEM;
  3787. goto err;
  3788. }
  3789. stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  3790. if (!stli_serial) {
  3791. retval = -ENOMEM;
  3792. goto err_free;
  3793. }
  3794. stli_serial->owner = THIS_MODULE;
  3795. stli_serial->driver_name = stli_drvname;
  3796. stli_serial->name = stli_serialname;
  3797. stli_serial->major = STL_SERIALMAJOR;
  3798. stli_serial->minor_start = 0;
  3799. stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
  3800. stli_serial->subtype = SERIAL_TYPE_NORMAL;
  3801. stli_serial->init_termios = stli_deftermios;
  3802. stli_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  3803. tty_set_operations(stli_serial, &stli_ops);
  3804. retval = tty_register_driver(stli_serial);
  3805. if (retval) {
  3806. printk(KERN_ERR "istallion: failed to register serial driver\n");
  3807. goto err_ttyput;
  3808. }
  3809. retval = stli_initbrds();
  3810. if (retval)
  3811. goto err_ttyunr;
  3812. /*
  3813. * Set up a character driver for the shared memory region. We need this
  3814. * to down load the slave code image. Also it is a useful debugging tool.
  3815. */
  3816. retval = register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem);
  3817. if (retval) {
  3818. printk(KERN_ERR "istallion: failed to register serial memory "
  3819. "device\n");
  3820. goto err_deinit;
  3821. }
  3822. istallion_class = class_create(THIS_MODULE, "staliomem");
  3823. for (i = 0; i < 4; i++)
  3824. device_create(istallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i),
  3825. NULL, "staliomem%d", i);
  3826. return 0;
  3827. err_deinit:
  3828. pci_unregister_driver(&stli_pcidriver);
  3829. istallion_cleanup_isa();
  3830. err_ttyunr:
  3831. tty_unregister_driver(stli_serial);
  3832. err_ttyput:
  3833. put_tty_driver(stli_serial);
  3834. err_free:
  3835. kfree(stli_txcookbuf);
  3836. err:
  3837. return retval;
  3838. }
  3839. /*****************************************************************************/
  3840. static void __exit istallion_module_exit(void)
  3841. {
  3842. unsigned int j;
  3843. printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
  3844. stli_drvversion);
  3845. if (stli_timeron) {
  3846. stli_timeron = 0;
  3847. del_timer_sync(&stli_timerlist);
  3848. }
  3849. unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
  3850. for (j = 0; j < 4; j++)
  3851. device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, j));
  3852. class_destroy(istallion_class);
  3853. pci_unregister_driver(&stli_pcidriver);
  3854. istallion_cleanup_isa();
  3855. tty_unregister_driver(stli_serial);
  3856. put_tty_driver(stli_serial);
  3857. kfree(stli_txcookbuf);
  3858. }
  3859. module_init(istallion_module_init);
  3860. module_exit(istallion_module_exit);