istallion.c 136 KB

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