istallion.c 124 KB

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