istallion.c 125 KB

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