istallion.c 136 KB

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