istallion.c 123 KB

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