stallion.c 131 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126
  1. /*****************************************************************************/
  2. /*
  3. * stallion.c -- stallion 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/cd1400.h>
  34. #include <linux/sc26198.h>
  35. #include <linux/comstats.h>
  36. #include <linux/stallion.h>
  37. #include <linux/ioport.h>
  38. #include <linux/init.h>
  39. #include <linux/smp_lock.h>
  40. #include <linux/devfs_fs_kernel.h>
  41. #include <linux/device.h>
  42. #include <linux/delay.h>
  43. #include <asm/io.h>
  44. #include <asm/uaccess.h>
  45. #ifdef CONFIG_PCI
  46. #include <linux/pci.h>
  47. #endif
  48. /*****************************************************************************/
  49. /*
  50. * Define different board types. Use the standard Stallion "assigned"
  51. * board numbers. Boards supported in this driver are abbreviated as
  52. * EIO = EasyIO and ECH = EasyConnection 8/32.
  53. */
  54. #define BRD_EASYIO 20
  55. #define BRD_ECH 21
  56. #define BRD_ECHMC 22
  57. #define BRD_ECHPCI 26
  58. #define BRD_ECH64PCI 27
  59. #define BRD_EASYIOPCI 28
  60. /*
  61. * Define a configuration structure to hold the board configuration.
  62. * Need to set this up in the code (for now) with the boards that are
  63. * to be configured into the system. This is what needs to be modified
  64. * when adding/removing/modifying boards. Each line entry in the
  65. * stl_brdconf[] array is a board. Each line contains io/irq/memory
  66. * ranges for that board (as well as what type of board it is).
  67. * Some examples:
  68. * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
  69. * This line would configure an EasyIO board (4 or 8, no difference),
  70. * at io address 2a0 and irq 10.
  71. * Another example:
  72. * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
  73. * This line will configure an EasyConnection 8/32 board at primary io
  74. * address 2a8, secondary io address 280 and irq 12.
  75. * Enter as many lines into this array as you want (only the first 4
  76. * will actually be used!). Any combination of EasyIO and EasyConnection
  77. * boards can be specified. EasyConnection 8/32 boards can share their
  78. * secondary io addresses between each other.
  79. *
  80. * NOTE: there is no need to put any entries in this table for PCI
  81. * boards. They will be found automatically by the driver - provided
  82. * PCI BIOS32 support is compiled into the kernel.
  83. */
  84. typedef struct {
  85. int brdtype;
  86. int ioaddr1;
  87. int ioaddr2;
  88. unsigned long memaddr;
  89. int irq;
  90. int irqtype;
  91. } stlconf_t;
  92. static stlconf_t stl_brdconf[] = {
  93. /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
  94. };
  95. static int stl_nrbrds = ARRAY_SIZE(stl_brdconf);
  96. /*****************************************************************************/
  97. /*
  98. * Define some important driver characteristics. Device major numbers
  99. * allocated as per Linux Device Registry.
  100. */
  101. #ifndef STL_SIOMEMMAJOR
  102. #define STL_SIOMEMMAJOR 28
  103. #endif
  104. #ifndef STL_SERIALMAJOR
  105. #define STL_SERIALMAJOR 24
  106. #endif
  107. #ifndef STL_CALLOUTMAJOR
  108. #define STL_CALLOUTMAJOR 25
  109. #endif
  110. /*
  111. * Set the TX buffer size. Bigger is better, but we don't want
  112. * to chew too much memory with buffers!
  113. */
  114. #define STL_TXBUFLOW 512
  115. #define STL_TXBUFSIZE 4096
  116. /*****************************************************************************/
  117. /*
  118. * Define our local driver identity first. Set up stuff to deal with
  119. * all the local structures required by a serial tty driver.
  120. */
  121. static char *stl_drvtitle = "Stallion Multiport Serial Driver";
  122. static char *stl_drvname = "stallion";
  123. static char *stl_drvversion = "5.6.0";
  124. static struct tty_driver *stl_serial;
  125. /*
  126. * Define a local default termios struct. All ports will be created
  127. * with this termios initially. Basically all it defines is a raw port
  128. * at 9600, 8 data bits, 1 stop bit.
  129. */
  130. static struct termios stl_deftermios = {
  131. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  132. .c_cc = INIT_C_CC,
  133. };
  134. /*
  135. * Define global stats structures. Not used often, and can be
  136. * re-used for each stats call.
  137. */
  138. static comstats_t stl_comstats;
  139. static combrd_t stl_brdstats;
  140. static stlbrd_t stl_dummybrd;
  141. static stlport_t stl_dummyport;
  142. /*
  143. * Define global place to put buffer overflow characters.
  144. */
  145. static char stl_unwanted[SC26198_RXFIFOSIZE];
  146. /*****************************************************************************/
  147. static stlbrd_t *stl_brds[STL_MAXBRDS];
  148. /*
  149. * Per board state flags. Used with the state field of the board struct.
  150. * Not really much here!
  151. */
  152. #define BRD_FOUND 0x1
  153. /*
  154. * Define the port structure istate flags. These set of flags are
  155. * modified at interrupt time - so setting and reseting them needs
  156. * to be atomic. Use the bit clear/setting routines for this.
  157. */
  158. #define ASYI_TXBUSY 1
  159. #define ASYI_TXLOW 2
  160. #define ASYI_DCDCHANGE 3
  161. #define ASYI_TXFLOWED 4
  162. /*
  163. * Define an array of board names as printable strings. Handy for
  164. * referencing boards when printing trace and stuff.
  165. */
  166. static char *stl_brdnames[] = {
  167. (char *) NULL,
  168. (char *) NULL,
  169. (char *) NULL,
  170. (char *) NULL,
  171. (char *) NULL,
  172. (char *) NULL,
  173. (char *) NULL,
  174. (char *) NULL,
  175. (char *) NULL,
  176. (char *) NULL,
  177. (char *) NULL,
  178. (char *) NULL,
  179. (char *) NULL,
  180. (char *) NULL,
  181. (char *) NULL,
  182. (char *) NULL,
  183. (char *) NULL,
  184. (char *) NULL,
  185. (char *) NULL,
  186. (char *) NULL,
  187. "EasyIO",
  188. "EC8/32-AT",
  189. "EC8/32-MC",
  190. (char *) NULL,
  191. (char *) NULL,
  192. (char *) NULL,
  193. "EC8/32-PCI",
  194. "EC8/64-PCI",
  195. "EasyIO-PCI",
  196. };
  197. /*****************************************************************************/
  198. /*
  199. * Define some string labels for arguments passed from the module
  200. * load line. These allow for easy board definitions, and easy
  201. * modification of the io, memory and irq resoucres.
  202. */
  203. static int stl_nargs = 0;
  204. static char *board0[4];
  205. static char *board1[4];
  206. static char *board2[4];
  207. static char *board3[4];
  208. static char **stl_brdsp[] = {
  209. (char **) &board0,
  210. (char **) &board1,
  211. (char **) &board2,
  212. (char **) &board3
  213. };
  214. /*
  215. * Define a set of common board names, and types. This is used to
  216. * parse any module arguments.
  217. */
  218. typedef struct stlbrdtype {
  219. char *name;
  220. int type;
  221. } stlbrdtype_t;
  222. static stlbrdtype_t stl_brdstr[] = {
  223. { "easyio", BRD_EASYIO },
  224. { "eio", BRD_EASYIO },
  225. { "20", BRD_EASYIO },
  226. { "ec8/32", BRD_ECH },
  227. { "ec8/32-at", BRD_ECH },
  228. { "ec8/32-isa", BRD_ECH },
  229. { "ech", BRD_ECH },
  230. { "echat", BRD_ECH },
  231. { "21", BRD_ECH },
  232. { "ec8/32-mc", BRD_ECHMC },
  233. { "ec8/32-mca", BRD_ECHMC },
  234. { "echmc", BRD_ECHMC },
  235. { "echmca", BRD_ECHMC },
  236. { "22", BRD_ECHMC },
  237. { "ec8/32-pc", BRD_ECHPCI },
  238. { "ec8/32-pci", BRD_ECHPCI },
  239. { "26", BRD_ECHPCI },
  240. { "ec8/64-pc", BRD_ECH64PCI },
  241. { "ec8/64-pci", BRD_ECH64PCI },
  242. { "ech-pci", BRD_ECH64PCI },
  243. { "echpci", BRD_ECH64PCI },
  244. { "echpc", BRD_ECH64PCI },
  245. { "27", BRD_ECH64PCI },
  246. { "easyio-pc", BRD_EASYIOPCI },
  247. { "easyio-pci", BRD_EASYIOPCI },
  248. { "eio-pci", BRD_EASYIOPCI },
  249. { "eiopci", BRD_EASYIOPCI },
  250. { "28", BRD_EASYIOPCI },
  251. };
  252. /*
  253. * Define the module agruments.
  254. */
  255. MODULE_AUTHOR("Greg Ungerer");
  256. MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
  257. MODULE_LICENSE("GPL");
  258. module_param_array(board0, charp, &stl_nargs, 0);
  259. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
  260. module_param_array(board1, charp, &stl_nargs, 0);
  261. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
  262. module_param_array(board2, charp, &stl_nargs, 0);
  263. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
  264. module_param_array(board3, charp, &stl_nargs, 0);
  265. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
  266. /*****************************************************************************/
  267. /*
  268. * Hardware ID bits for the EasyIO and ECH boards. These defines apply
  269. * to the directly accessible io ports of these boards (not the uarts -
  270. * they are in cd1400.h and sc26198.h).
  271. */
  272. #define EIO_8PORTRS 0x04
  273. #define EIO_4PORTRS 0x05
  274. #define EIO_8PORTDI 0x00
  275. #define EIO_8PORTM 0x06
  276. #define EIO_MK3 0x03
  277. #define EIO_IDBITMASK 0x07
  278. #define EIO_BRDMASK 0xf0
  279. #define ID_BRD4 0x10
  280. #define ID_BRD8 0x20
  281. #define ID_BRD16 0x30
  282. #define EIO_INTRPEND 0x08
  283. #define EIO_INTEDGE 0x00
  284. #define EIO_INTLEVEL 0x08
  285. #define EIO_0WS 0x10
  286. #define ECH_ID 0xa0
  287. #define ECH_IDBITMASK 0xe0
  288. #define ECH_BRDENABLE 0x08
  289. #define ECH_BRDDISABLE 0x00
  290. #define ECH_INTENABLE 0x01
  291. #define ECH_INTDISABLE 0x00
  292. #define ECH_INTLEVEL 0x02
  293. #define ECH_INTEDGE 0x00
  294. #define ECH_INTRPEND 0x01
  295. #define ECH_BRDRESET 0x01
  296. #define ECHMC_INTENABLE 0x01
  297. #define ECHMC_BRDRESET 0x02
  298. #define ECH_PNLSTATUS 2
  299. #define ECH_PNL16PORT 0x20
  300. #define ECH_PNLIDMASK 0x07
  301. #define ECH_PNLXPID 0x40
  302. #define ECH_PNLINTRPEND 0x80
  303. #define ECH_ADDR2MASK 0x1e0
  304. /*
  305. * Define the vector mapping bits for the programmable interrupt board
  306. * hardware. These bits encode the interrupt for the board to use - it
  307. * is software selectable (except the EIO-8M).
  308. */
  309. static unsigned char stl_vecmap[] = {
  310. 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
  311. 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
  312. };
  313. /*
  314. * Lock ordering is that you may not take stallion_lock holding
  315. * brd_lock.
  316. */
  317. static spinlock_t brd_lock; /* Guard the board mapping */
  318. static spinlock_t stallion_lock; /* Guard the tty driver */
  319. /*
  320. * Set up enable and disable macros for the ECH boards. They require
  321. * the secondary io address space to be activated and deactivated.
  322. * This way all ECH boards can share their secondary io region.
  323. * If this is an ECH-PCI board then also need to set the page pointer
  324. * to point to the correct page.
  325. */
  326. #define BRDENABLE(brdnr,pagenr) \
  327. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  328. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
  329. stl_brds[(brdnr)]->ioctrl); \
  330. else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
  331. outb((pagenr), stl_brds[(brdnr)]->ioctrl);
  332. #define BRDDISABLE(brdnr) \
  333. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  334. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
  335. stl_brds[(brdnr)]->ioctrl);
  336. #define STL_CD1400MAXBAUD 230400
  337. #define STL_SC26198MAXBAUD 460800
  338. #define STL_BAUDBASE 115200
  339. #define STL_CLOSEDELAY (5 * HZ / 10)
  340. /*****************************************************************************/
  341. #ifdef CONFIG_PCI
  342. /*
  343. * Define the Stallion PCI vendor and device IDs.
  344. */
  345. #ifndef PCI_VENDOR_ID_STALLION
  346. #define PCI_VENDOR_ID_STALLION 0x124d
  347. #endif
  348. #ifndef PCI_DEVICE_ID_ECHPCI832
  349. #define PCI_DEVICE_ID_ECHPCI832 0x0000
  350. #endif
  351. #ifndef PCI_DEVICE_ID_ECHPCI864
  352. #define PCI_DEVICE_ID_ECHPCI864 0x0002
  353. #endif
  354. #ifndef PCI_DEVICE_ID_EIOPCI
  355. #define PCI_DEVICE_ID_EIOPCI 0x0003
  356. #endif
  357. /*
  358. * Define structure to hold all Stallion PCI boards.
  359. */
  360. typedef struct stlpcibrd {
  361. unsigned short vendid;
  362. unsigned short devid;
  363. int brdtype;
  364. } stlpcibrd_t;
  365. static stlpcibrd_t stl_pcibrds[] = {
  366. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
  367. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
  368. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
  369. { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
  370. };
  371. static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
  372. #endif
  373. /*****************************************************************************/
  374. /*
  375. * Define macros to extract a brd/port number from a minor number.
  376. */
  377. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  378. #define MINOR2PORT(min) ((min) & 0x3f)
  379. /*
  380. * Define a baud rate table that converts termios baud rate selector
  381. * into the actual baud rate value. All baud rate calculations are
  382. * based on the actual baud rate required.
  383. */
  384. static unsigned int stl_baudrates[] = {
  385. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  386. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
  387. };
  388. /*
  389. * Define some handy local macros...
  390. */
  391. #undef MIN
  392. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  393. #undef TOLOWER
  394. #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
  395. /*****************************************************************************/
  396. /*
  397. * Declare all those functions in this driver!
  398. */
  399. static void stl_argbrds(void);
  400. static int stl_parsebrd(stlconf_t *confp, char **argp);
  401. static unsigned long stl_atol(char *str);
  402. static int stl_init(void);
  403. static int stl_open(struct tty_struct *tty, struct file *filp);
  404. static void stl_close(struct tty_struct *tty, struct file *filp);
  405. static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
  406. static void stl_putchar(struct tty_struct *tty, unsigned char ch);
  407. static void stl_flushchars(struct tty_struct *tty);
  408. static int stl_writeroom(struct tty_struct *tty);
  409. static int stl_charsinbuffer(struct tty_struct *tty);
  410. static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  411. static void stl_settermios(struct tty_struct *tty, struct termios *old);
  412. static void stl_throttle(struct tty_struct *tty);
  413. static void stl_unthrottle(struct tty_struct *tty);
  414. static void stl_stop(struct tty_struct *tty);
  415. static void stl_start(struct tty_struct *tty);
  416. static void stl_flushbuffer(struct tty_struct *tty);
  417. static void stl_breakctl(struct tty_struct *tty, int state);
  418. static void stl_waituntilsent(struct tty_struct *tty, int timeout);
  419. static void stl_sendxchar(struct tty_struct *tty, char ch);
  420. static void stl_hangup(struct tty_struct *tty);
  421. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
  422. static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
  423. static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
  424. static int stl_brdinit(stlbrd_t *brdp);
  425. static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
  426. static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
  427. static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
  428. static int stl_getbrdstats(combrd_t __user *bp);
  429. static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
  430. static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
  431. static int stl_getportstruct(stlport_t __user *arg);
  432. static int stl_getbrdstruct(stlbrd_t __user *arg);
  433. static int stl_waitcarrier(stlport_t *portp, struct file *filp);
  434. static int stl_eiointr(stlbrd_t *brdp);
  435. static int stl_echatintr(stlbrd_t *brdp);
  436. static int stl_echmcaintr(stlbrd_t *brdp);
  437. static int stl_echpciintr(stlbrd_t *brdp);
  438. static int stl_echpci64intr(stlbrd_t *brdp);
  439. static void stl_offintr(void *private);
  440. static stlbrd_t *stl_allocbrd(void);
  441. static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
  442. static inline int stl_initbrds(void);
  443. static inline int stl_initeio(stlbrd_t *brdp);
  444. static inline int stl_initech(stlbrd_t *brdp);
  445. static inline int stl_getbrdnr(void);
  446. #ifdef CONFIG_PCI
  447. static inline int stl_findpcibrds(void);
  448. static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
  449. #endif
  450. /*
  451. * CD1400 uart specific handling functions.
  452. */
  453. static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
  454. static int stl_cd1400getreg(stlport_t *portp, int regnr);
  455. static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
  456. static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
  457. static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  458. static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
  459. static int stl_cd1400getsignals(stlport_t *portp);
  460. static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
  461. static void stl_cd1400ccrwait(stlport_t *portp);
  462. static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
  463. static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
  464. static void stl_cd1400disableintrs(stlport_t *portp);
  465. static void stl_cd1400sendbreak(stlport_t *portp, int len);
  466. static void stl_cd1400flowctrl(stlport_t *portp, int state);
  467. static void stl_cd1400sendflow(stlport_t *portp, int state);
  468. static void stl_cd1400flush(stlport_t *portp);
  469. static int stl_cd1400datastate(stlport_t *portp);
  470. static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
  471. static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
  472. static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
  473. static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
  474. static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
  475. static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
  476. /*
  477. * SC26198 uart specific handling functions.
  478. */
  479. static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
  480. static int stl_sc26198getreg(stlport_t *portp, int regnr);
  481. static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
  482. static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
  483. static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
  484. static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  485. static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
  486. static int stl_sc26198getsignals(stlport_t *portp);
  487. static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
  488. static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
  489. static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
  490. static void stl_sc26198disableintrs(stlport_t *portp);
  491. static void stl_sc26198sendbreak(stlport_t *portp, int len);
  492. static void stl_sc26198flowctrl(stlport_t *portp, int state);
  493. static void stl_sc26198sendflow(stlport_t *portp, int state);
  494. static void stl_sc26198flush(stlport_t *portp);
  495. static int stl_sc26198datastate(stlport_t *portp);
  496. static void stl_sc26198wait(stlport_t *portp);
  497. static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
  498. static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
  499. static void stl_sc26198txisr(stlport_t *port);
  500. static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
  501. static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
  502. static void stl_sc26198rxbadchars(stlport_t *portp);
  503. static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
  504. /*****************************************************************************/
  505. /*
  506. * Generic UART support structure.
  507. */
  508. typedef struct uart {
  509. int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
  510. void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  511. void (*setport)(stlport_t *portp, struct termios *tiosp);
  512. int (*getsignals)(stlport_t *portp);
  513. void (*setsignals)(stlport_t *portp, int dtr, int rts);
  514. void (*enablerxtx)(stlport_t *portp, int rx, int tx);
  515. void (*startrxtx)(stlport_t *portp, int rx, int tx);
  516. void (*disableintrs)(stlport_t *portp);
  517. void (*sendbreak)(stlport_t *portp, int len);
  518. void (*flowctrl)(stlport_t *portp, int state);
  519. void (*sendflow)(stlport_t *portp, int state);
  520. void (*flush)(stlport_t *portp);
  521. int (*datastate)(stlport_t *portp);
  522. void (*intr)(stlpanel_t *panelp, unsigned int iobase);
  523. } uart_t;
  524. /*
  525. * Define some macros to make calling these functions nice and clean.
  526. */
  527. #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
  528. #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
  529. #define stl_setport (* ((uart_t *) portp->uartp)->setport)
  530. #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
  531. #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
  532. #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
  533. #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
  534. #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
  535. #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
  536. #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
  537. #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
  538. #define stl_flush (* ((uart_t *) portp->uartp)->flush)
  539. #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
  540. /*****************************************************************************/
  541. /*
  542. * CD1400 UART specific data initialization.
  543. */
  544. static uart_t stl_cd1400uart = {
  545. stl_cd1400panelinit,
  546. stl_cd1400portinit,
  547. stl_cd1400setport,
  548. stl_cd1400getsignals,
  549. stl_cd1400setsignals,
  550. stl_cd1400enablerxtx,
  551. stl_cd1400startrxtx,
  552. stl_cd1400disableintrs,
  553. stl_cd1400sendbreak,
  554. stl_cd1400flowctrl,
  555. stl_cd1400sendflow,
  556. stl_cd1400flush,
  557. stl_cd1400datastate,
  558. stl_cd1400eiointr
  559. };
  560. /*
  561. * Define the offsets within the register bank of a cd1400 based panel.
  562. * These io address offsets are common to the EasyIO board as well.
  563. */
  564. #define EREG_ADDR 0
  565. #define EREG_DATA 4
  566. #define EREG_RXACK 5
  567. #define EREG_TXACK 6
  568. #define EREG_MDACK 7
  569. #define EREG_BANKSIZE 8
  570. #define CD1400_CLK 25000000
  571. #define CD1400_CLK8M 20000000
  572. /*
  573. * Define the cd1400 baud rate clocks. These are used when calculating
  574. * what clock and divisor to use for the required baud rate. Also
  575. * define the maximum baud rate allowed, and the default base baud.
  576. */
  577. static int stl_cd1400clkdivs[] = {
  578. CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
  579. };
  580. /*****************************************************************************/
  581. /*
  582. * SC26198 UART specific data initization.
  583. */
  584. static uart_t stl_sc26198uart = {
  585. stl_sc26198panelinit,
  586. stl_sc26198portinit,
  587. stl_sc26198setport,
  588. stl_sc26198getsignals,
  589. stl_sc26198setsignals,
  590. stl_sc26198enablerxtx,
  591. stl_sc26198startrxtx,
  592. stl_sc26198disableintrs,
  593. stl_sc26198sendbreak,
  594. stl_sc26198flowctrl,
  595. stl_sc26198sendflow,
  596. stl_sc26198flush,
  597. stl_sc26198datastate,
  598. stl_sc26198intr
  599. };
  600. /*
  601. * Define the offsets within the register bank of a sc26198 based panel.
  602. */
  603. #define XP_DATA 0
  604. #define XP_ADDR 1
  605. #define XP_MODID 2
  606. #define XP_STATUS 2
  607. #define XP_IACK 3
  608. #define XP_BANKSIZE 4
  609. /*
  610. * Define the sc26198 baud rate table. Offsets within the table
  611. * represent the actual baud rate selector of sc26198 registers.
  612. */
  613. static unsigned int sc26198_baudtable[] = {
  614. 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
  615. 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
  616. 230400, 460800, 921600
  617. };
  618. #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
  619. /*****************************************************************************/
  620. /*
  621. * Define the driver info for a user level control device. Used mainly
  622. * to get at port stats - only not using the port device itself.
  623. */
  624. static struct file_operations stl_fsiomem = {
  625. .owner = THIS_MODULE,
  626. .ioctl = stl_memioctl,
  627. };
  628. /*****************************************************************************/
  629. static struct class *stallion_class;
  630. /*
  631. * Loadable module initialization stuff.
  632. */
  633. static int __init stallion_module_init(void)
  634. {
  635. stl_init();
  636. return 0;
  637. }
  638. /*****************************************************************************/
  639. static void __exit stallion_module_exit(void)
  640. {
  641. stlbrd_t *brdp;
  642. stlpanel_t *panelp;
  643. stlport_t *portp;
  644. int i, j, k;
  645. #ifdef DEBUG
  646. printk("cleanup_module()\n");
  647. #endif
  648. printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
  649. stl_drvversion);
  650. /*
  651. * Free up all allocated resources used by the ports. This includes
  652. * memory and interrupts. As part of this process we will also do
  653. * a hangup on every open port - to try to flush out any processes
  654. * hanging onto ports.
  655. */
  656. i = tty_unregister_driver(stl_serial);
  657. put_tty_driver(stl_serial);
  658. if (i) {
  659. printk("STALLION: failed to un-register tty driver, "
  660. "errno=%d\n", -i);
  661. return;
  662. }
  663. for (i = 0; i < 4; i++) {
  664. devfs_remove("staliomem/%d", i);
  665. class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
  666. }
  667. devfs_remove("staliomem");
  668. if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
  669. printk("STALLION: failed to un-register serial memory device, "
  670. "errno=%d\n", -i);
  671. class_destroy(stallion_class);
  672. for (i = 0; (i < stl_nrbrds); i++) {
  673. if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
  674. continue;
  675. free_irq(brdp->irq, brdp);
  676. for (j = 0; (j < STL_MAXPANELS); j++) {
  677. panelp = brdp->panels[j];
  678. if (panelp == (stlpanel_t *) NULL)
  679. continue;
  680. for (k = 0; (k < STL_PORTSPERPANEL); k++) {
  681. portp = panelp->ports[k];
  682. if (portp == (stlport_t *) NULL)
  683. continue;
  684. if (portp->tty != (struct tty_struct *) NULL)
  685. stl_hangup(portp->tty);
  686. kfree(portp->tx.buf);
  687. kfree(portp);
  688. }
  689. kfree(panelp);
  690. }
  691. release_region(brdp->ioaddr1, brdp->iosize1);
  692. if (brdp->iosize2 > 0)
  693. release_region(brdp->ioaddr2, brdp->iosize2);
  694. kfree(brdp);
  695. stl_brds[i] = (stlbrd_t *) NULL;
  696. }
  697. }
  698. module_init(stallion_module_init);
  699. module_exit(stallion_module_exit);
  700. /*****************************************************************************/
  701. /*
  702. * Check for any arguments passed in on the module load command line.
  703. */
  704. static void stl_argbrds(void)
  705. {
  706. stlconf_t conf;
  707. stlbrd_t *brdp;
  708. int i;
  709. #ifdef DEBUG
  710. printk("stl_argbrds()\n");
  711. #endif
  712. for (i = stl_nrbrds; (i < stl_nargs); i++) {
  713. memset(&conf, 0, sizeof(conf));
  714. if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
  715. continue;
  716. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  717. continue;
  718. stl_nrbrds = i + 1;
  719. brdp->brdnr = i;
  720. brdp->brdtype = conf.brdtype;
  721. brdp->ioaddr1 = conf.ioaddr1;
  722. brdp->ioaddr2 = conf.ioaddr2;
  723. brdp->irq = conf.irq;
  724. brdp->irqtype = conf.irqtype;
  725. stl_brdinit(brdp);
  726. }
  727. }
  728. /*****************************************************************************/
  729. /*
  730. * Convert an ascii string number into an unsigned long.
  731. */
  732. static unsigned long stl_atol(char *str)
  733. {
  734. unsigned long val;
  735. int base, c;
  736. char *sp;
  737. val = 0;
  738. sp = str;
  739. if ((*sp == '0') && (*(sp+1) == 'x')) {
  740. base = 16;
  741. sp += 2;
  742. } else if (*sp == '0') {
  743. base = 8;
  744. sp++;
  745. } else {
  746. base = 10;
  747. }
  748. for (; (*sp != 0); sp++) {
  749. c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
  750. if ((c < 0) || (c >= base)) {
  751. printk("STALLION: invalid argument %s\n", str);
  752. val = 0;
  753. break;
  754. }
  755. val = (val * base) + c;
  756. }
  757. return val;
  758. }
  759. /*****************************************************************************/
  760. /*
  761. * Parse the supplied argument string, into the board conf struct.
  762. */
  763. static int stl_parsebrd(stlconf_t *confp, char **argp)
  764. {
  765. char *sp;
  766. int i;
  767. #ifdef DEBUG
  768. printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
  769. #endif
  770. if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
  771. return 0;
  772. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  773. *sp = TOLOWER(*sp);
  774. for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
  775. if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
  776. break;
  777. }
  778. if (i == ARRAY_SIZE(stl_brdstr)) {
  779. printk("STALLION: unknown board name, %s?\n", argp[0]);
  780. return 0;
  781. }
  782. confp->brdtype = stl_brdstr[i].type;
  783. i = 1;
  784. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  785. confp->ioaddr1 = stl_atol(argp[i]);
  786. i++;
  787. if (confp->brdtype == BRD_ECH) {
  788. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  789. confp->ioaddr2 = stl_atol(argp[i]);
  790. i++;
  791. }
  792. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  793. confp->irq = stl_atol(argp[i]);
  794. return 1;
  795. }
  796. /*****************************************************************************/
  797. /*
  798. * Allocate a new board structure. Fill out the basic info in it.
  799. */
  800. static stlbrd_t *stl_allocbrd(void)
  801. {
  802. stlbrd_t *brdp;
  803. brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
  804. if (!brdp) {
  805. printk("STALLION: failed to allocate memory (size=%Zd)\n",
  806. sizeof(stlbrd_t));
  807. return NULL;
  808. }
  809. brdp->magic = STL_BOARDMAGIC;
  810. return brdp;
  811. }
  812. /*****************************************************************************/
  813. static int stl_open(struct tty_struct *tty, struct file *filp)
  814. {
  815. stlport_t *portp;
  816. stlbrd_t *brdp;
  817. unsigned int minordev;
  818. int brdnr, panelnr, portnr, rc;
  819. #ifdef DEBUG
  820. printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
  821. (int) filp, tty->name);
  822. #endif
  823. minordev = tty->index;
  824. brdnr = MINOR2BRD(minordev);
  825. if (brdnr >= stl_nrbrds)
  826. return -ENODEV;
  827. brdp = stl_brds[brdnr];
  828. if (brdp == (stlbrd_t *) NULL)
  829. return -ENODEV;
  830. minordev = MINOR2PORT(minordev);
  831. for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  832. if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
  833. break;
  834. if (minordev < brdp->panels[panelnr]->nrports) {
  835. portnr = minordev;
  836. break;
  837. }
  838. minordev -= brdp->panels[panelnr]->nrports;
  839. }
  840. if (portnr < 0)
  841. return -ENODEV;
  842. portp = brdp->panels[panelnr]->ports[portnr];
  843. if (portp == (stlport_t *) NULL)
  844. return -ENODEV;
  845. /*
  846. * On the first open of the device setup the port hardware, and
  847. * initialize the per port data structure.
  848. */
  849. portp->tty = tty;
  850. tty->driver_data = portp;
  851. portp->refcount++;
  852. if ((portp->flags & ASYNC_INITIALIZED) == 0) {
  853. if (!portp->tx.buf) {
  854. portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
  855. if (!portp->tx.buf)
  856. return -ENOMEM;
  857. portp->tx.head = portp->tx.buf;
  858. portp->tx.tail = portp->tx.buf;
  859. }
  860. stl_setport(portp, tty->termios);
  861. portp->sigs = stl_getsignals(portp);
  862. stl_setsignals(portp, 1, 1);
  863. stl_enablerxtx(portp, 1, 1);
  864. stl_startrxtx(portp, 1, 0);
  865. clear_bit(TTY_IO_ERROR, &tty->flags);
  866. portp->flags |= ASYNC_INITIALIZED;
  867. }
  868. /*
  869. * Check if this port is in the middle of closing. If so then wait
  870. * until it is closed then return error status, based on flag settings.
  871. * The sleep here does not need interrupt protection since the wakeup
  872. * for it is done with the same context.
  873. */
  874. if (portp->flags & ASYNC_CLOSING) {
  875. interruptible_sleep_on(&portp->close_wait);
  876. if (portp->flags & ASYNC_HUP_NOTIFY)
  877. return -EAGAIN;
  878. return -ERESTARTSYS;
  879. }
  880. /*
  881. * Based on type of open being done check if it can overlap with any
  882. * previous opens still in effect. If we are a normal serial device
  883. * then also we might have to wait for carrier.
  884. */
  885. if (!(filp->f_flags & O_NONBLOCK)) {
  886. if ((rc = stl_waitcarrier(portp, filp)) != 0)
  887. return rc;
  888. }
  889. portp->flags |= ASYNC_NORMAL_ACTIVE;
  890. return 0;
  891. }
  892. /*****************************************************************************/
  893. /*
  894. * Possibly need to wait for carrier (DCD signal) to come high. Say
  895. * maybe because if we are clocal then we don't need to wait...
  896. */
  897. static int stl_waitcarrier(stlport_t *portp, struct file *filp)
  898. {
  899. unsigned long flags;
  900. int rc, doclocal;
  901. #ifdef DEBUG
  902. printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
  903. #endif
  904. rc = 0;
  905. doclocal = 0;
  906. spin_lock_irqsave(&stallion_lock, flags);
  907. if (portp->tty->termios->c_cflag & CLOCAL)
  908. doclocal++;
  909. portp->openwaitcnt++;
  910. if (! tty_hung_up_p(filp))
  911. portp->refcount--;
  912. for (;;) {
  913. /* Takes brd_lock internally */
  914. stl_setsignals(portp, 1, 1);
  915. if (tty_hung_up_p(filp) ||
  916. ((portp->flags & ASYNC_INITIALIZED) == 0)) {
  917. if (portp->flags & ASYNC_HUP_NOTIFY)
  918. rc = -EBUSY;
  919. else
  920. rc = -ERESTARTSYS;
  921. break;
  922. }
  923. if (((portp->flags & ASYNC_CLOSING) == 0) &&
  924. (doclocal || (portp->sigs & TIOCM_CD))) {
  925. break;
  926. }
  927. if (signal_pending(current)) {
  928. rc = -ERESTARTSYS;
  929. break;
  930. }
  931. /* FIXME */
  932. interruptible_sleep_on(&portp->open_wait);
  933. }
  934. if (! tty_hung_up_p(filp))
  935. portp->refcount++;
  936. portp->openwaitcnt--;
  937. spin_unlock_irqrestore(&stallion_lock, flags);
  938. return rc;
  939. }
  940. /*****************************************************************************/
  941. static void stl_close(struct tty_struct *tty, struct file *filp)
  942. {
  943. stlport_t *portp;
  944. unsigned long flags;
  945. #ifdef DEBUG
  946. printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
  947. #endif
  948. portp = tty->driver_data;
  949. if (portp == (stlport_t *) NULL)
  950. return;
  951. spin_lock_irqsave(&stallion_lock, flags);
  952. if (tty_hung_up_p(filp)) {
  953. spin_unlock_irqrestore(&stallion_lock, flags);
  954. return;
  955. }
  956. if ((tty->count == 1) && (portp->refcount != 1))
  957. portp->refcount = 1;
  958. if (portp->refcount-- > 1) {
  959. spin_unlock_irqrestore(&stallion_lock, flags);
  960. return;
  961. }
  962. portp->refcount = 0;
  963. portp->flags |= ASYNC_CLOSING;
  964. /*
  965. * May want to wait for any data to drain before closing. The BUSY
  966. * flag keeps track of whether we are still sending or not - it is
  967. * very accurate for the cd1400, not quite so for the sc26198.
  968. * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
  969. */
  970. tty->closing = 1;
  971. spin_unlock_irqrestore(&stallion_lock, flags);
  972. if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  973. tty_wait_until_sent(tty, portp->closing_wait);
  974. stl_waituntilsent(tty, (HZ / 2));
  975. spin_lock_irqsave(&stallion_lock, flags);
  976. portp->flags &= ~ASYNC_INITIALIZED;
  977. spin_unlock_irqrestore(&stallion_lock, flags);
  978. stl_disableintrs(portp);
  979. if (tty->termios->c_cflag & HUPCL)
  980. stl_setsignals(portp, 0, 0);
  981. stl_enablerxtx(portp, 0, 0);
  982. stl_flushbuffer(tty);
  983. portp->istate = 0;
  984. if (portp->tx.buf != (char *) NULL) {
  985. kfree(portp->tx.buf);
  986. portp->tx.buf = (char *) NULL;
  987. portp->tx.head = (char *) NULL;
  988. portp->tx.tail = (char *) NULL;
  989. }
  990. set_bit(TTY_IO_ERROR, &tty->flags);
  991. tty_ldisc_flush(tty);
  992. tty->closing = 0;
  993. portp->tty = (struct tty_struct *) NULL;
  994. if (portp->openwaitcnt) {
  995. if (portp->close_delay)
  996. msleep_interruptible(jiffies_to_msecs(portp->close_delay));
  997. wake_up_interruptible(&portp->open_wait);
  998. }
  999. portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1000. wake_up_interruptible(&portp->close_wait);
  1001. }
  1002. /*****************************************************************************/
  1003. /*
  1004. * Write routine. Take data and stuff it in to the TX ring queue.
  1005. * If transmit interrupts are not running then start them.
  1006. */
  1007. static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
  1008. {
  1009. stlport_t *portp;
  1010. unsigned int len, stlen;
  1011. unsigned char *chbuf;
  1012. char *head, *tail;
  1013. #ifdef DEBUG
  1014. printk("stl_write(tty=%x,buf=%x,count=%d)\n",
  1015. (int) tty, (int) buf, count);
  1016. #endif
  1017. portp = tty->driver_data;
  1018. if (portp == (stlport_t *) NULL)
  1019. return 0;
  1020. if (portp->tx.buf == (char *) NULL)
  1021. return 0;
  1022. /*
  1023. * If copying direct from user space we must cater for page faults,
  1024. * causing us to "sleep" here for a while. To handle this copy in all
  1025. * the data we need now, into a local buffer. Then when we got it all
  1026. * copy it into the TX buffer.
  1027. */
  1028. chbuf = (unsigned char *) buf;
  1029. head = portp->tx.head;
  1030. tail = portp->tx.tail;
  1031. if (head >= tail) {
  1032. len = STL_TXBUFSIZE - (head - tail) - 1;
  1033. stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
  1034. } else {
  1035. len = tail - head - 1;
  1036. stlen = len;
  1037. }
  1038. len = MIN(len, count);
  1039. count = 0;
  1040. while (len > 0) {
  1041. stlen = MIN(len, stlen);
  1042. memcpy(head, chbuf, stlen);
  1043. len -= stlen;
  1044. chbuf += stlen;
  1045. count += stlen;
  1046. head += stlen;
  1047. if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
  1048. head = portp->tx.buf;
  1049. stlen = tail - head;
  1050. }
  1051. }
  1052. portp->tx.head = head;
  1053. clear_bit(ASYI_TXLOW, &portp->istate);
  1054. stl_startrxtx(portp, -1, 1);
  1055. return count;
  1056. }
  1057. /*****************************************************************************/
  1058. static void stl_putchar(struct tty_struct *tty, unsigned char ch)
  1059. {
  1060. stlport_t *portp;
  1061. unsigned int len;
  1062. char *head, *tail;
  1063. #ifdef DEBUG
  1064. printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
  1065. #endif
  1066. if (tty == (struct tty_struct *) NULL)
  1067. return;
  1068. portp = tty->driver_data;
  1069. if (portp == (stlport_t *) NULL)
  1070. return;
  1071. if (portp->tx.buf == (char *) NULL)
  1072. return;
  1073. head = portp->tx.head;
  1074. tail = portp->tx.tail;
  1075. len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
  1076. len--;
  1077. if (len > 0) {
  1078. *head++ = ch;
  1079. if (head >= (portp->tx.buf + STL_TXBUFSIZE))
  1080. head = portp->tx.buf;
  1081. }
  1082. portp->tx.head = head;
  1083. }
  1084. /*****************************************************************************/
  1085. /*
  1086. * If there are any characters in the buffer then make sure that TX
  1087. * interrupts are on and get'em out. Normally used after the putchar
  1088. * routine has been called.
  1089. */
  1090. static void stl_flushchars(struct tty_struct *tty)
  1091. {
  1092. stlport_t *portp;
  1093. #ifdef DEBUG
  1094. printk("stl_flushchars(tty=%x)\n", (int) tty);
  1095. #endif
  1096. if (tty == (struct tty_struct *) NULL)
  1097. return;
  1098. portp = tty->driver_data;
  1099. if (portp == (stlport_t *) NULL)
  1100. return;
  1101. if (portp->tx.buf == (char *) NULL)
  1102. return;
  1103. stl_startrxtx(portp, -1, 1);
  1104. }
  1105. /*****************************************************************************/
  1106. static int stl_writeroom(struct tty_struct *tty)
  1107. {
  1108. stlport_t *portp;
  1109. char *head, *tail;
  1110. #ifdef DEBUG
  1111. printk("stl_writeroom(tty=%x)\n", (int) tty);
  1112. #endif
  1113. if (tty == (struct tty_struct *) NULL)
  1114. return 0;
  1115. portp = tty->driver_data;
  1116. if (portp == (stlport_t *) NULL)
  1117. return 0;
  1118. if (portp->tx.buf == (char *) NULL)
  1119. return 0;
  1120. head = portp->tx.head;
  1121. tail = portp->tx.tail;
  1122. return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
  1123. }
  1124. /*****************************************************************************/
  1125. /*
  1126. * Return number of chars in the TX buffer. Normally we would just
  1127. * calculate the number of chars in the buffer and return that, but if
  1128. * the buffer is empty and TX interrupts are still on then we return
  1129. * that the buffer still has 1 char in it. This way whoever called us
  1130. * will not think that ALL chars have drained - since the UART still
  1131. * must have some chars in it (we are busy after all).
  1132. */
  1133. static int stl_charsinbuffer(struct tty_struct *tty)
  1134. {
  1135. stlport_t *portp;
  1136. unsigned int size;
  1137. char *head, *tail;
  1138. #ifdef DEBUG
  1139. printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
  1140. #endif
  1141. if (tty == (struct tty_struct *) NULL)
  1142. return 0;
  1143. portp = tty->driver_data;
  1144. if (portp == (stlport_t *) NULL)
  1145. return 0;
  1146. if (portp->tx.buf == (char *) NULL)
  1147. return 0;
  1148. head = portp->tx.head;
  1149. tail = portp->tx.tail;
  1150. size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  1151. if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
  1152. size = 1;
  1153. return size;
  1154. }
  1155. /*****************************************************************************/
  1156. /*
  1157. * Generate the serial struct info.
  1158. */
  1159. static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
  1160. {
  1161. struct serial_struct sio;
  1162. stlbrd_t *brdp;
  1163. #ifdef DEBUG
  1164. printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
  1165. #endif
  1166. memset(&sio, 0, sizeof(struct serial_struct));
  1167. sio.line = portp->portnr;
  1168. sio.port = portp->ioaddr;
  1169. sio.flags = portp->flags;
  1170. sio.baud_base = portp->baud_base;
  1171. sio.close_delay = portp->close_delay;
  1172. sio.closing_wait = portp->closing_wait;
  1173. sio.custom_divisor = portp->custom_divisor;
  1174. sio.hub6 = 0;
  1175. if (portp->uartp == &stl_cd1400uart) {
  1176. sio.type = PORT_CIRRUS;
  1177. sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
  1178. } else {
  1179. sio.type = PORT_UNKNOWN;
  1180. sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
  1181. }
  1182. brdp = stl_brds[portp->brdnr];
  1183. if (brdp != (stlbrd_t *) NULL)
  1184. sio.irq = brdp->irq;
  1185. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
  1186. }
  1187. /*****************************************************************************/
  1188. /*
  1189. * Set port according to the serial struct info.
  1190. * At this point we do not do any auto-configure stuff, so we will
  1191. * just quietly ignore any requests to change irq, etc.
  1192. */
  1193. static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
  1194. {
  1195. struct serial_struct sio;
  1196. #ifdef DEBUG
  1197. printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
  1198. #endif
  1199. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1200. return -EFAULT;
  1201. if (!capable(CAP_SYS_ADMIN)) {
  1202. if ((sio.baud_base != portp->baud_base) ||
  1203. (sio.close_delay != portp->close_delay) ||
  1204. ((sio.flags & ~ASYNC_USR_MASK) !=
  1205. (portp->flags & ~ASYNC_USR_MASK)))
  1206. return -EPERM;
  1207. }
  1208. portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
  1209. (sio.flags & ASYNC_USR_MASK);
  1210. portp->baud_base = sio.baud_base;
  1211. portp->close_delay = sio.close_delay;
  1212. portp->closing_wait = sio.closing_wait;
  1213. portp->custom_divisor = sio.custom_divisor;
  1214. stl_setport(portp, portp->tty->termios);
  1215. return 0;
  1216. }
  1217. /*****************************************************************************/
  1218. static int stl_tiocmget(struct tty_struct *tty, struct file *file)
  1219. {
  1220. stlport_t *portp;
  1221. if (tty == (struct tty_struct *) NULL)
  1222. return -ENODEV;
  1223. portp = tty->driver_data;
  1224. if (portp == (stlport_t *) NULL)
  1225. return -ENODEV;
  1226. if (tty->flags & (1 << TTY_IO_ERROR))
  1227. return -EIO;
  1228. return stl_getsignals(portp);
  1229. }
  1230. static int stl_tiocmset(struct tty_struct *tty, struct file *file,
  1231. unsigned int set, unsigned int clear)
  1232. {
  1233. stlport_t *portp;
  1234. int rts = -1, dtr = -1;
  1235. if (tty == (struct tty_struct *) NULL)
  1236. return -ENODEV;
  1237. portp = tty->driver_data;
  1238. if (portp == (stlport_t *) NULL)
  1239. return -ENODEV;
  1240. if (tty->flags & (1 << TTY_IO_ERROR))
  1241. return -EIO;
  1242. if (set & TIOCM_RTS)
  1243. rts = 1;
  1244. if (set & TIOCM_DTR)
  1245. dtr = 1;
  1246. if (clear & TIOCM_RTS)
  1247. rts = 0;
  1248. if (clear & TIOCM_DTR)
  1249. dtr = 0;
  1250. stl_setsignals(portp, dtr, rts);
  1251. return 0;
  1252. }
  1253. static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1254. {
  1255. stlport_t *portp;
  1256. unsigned int ival;
  1257. int rc;
  1258. void __user *argp = (void __user *)arg;
  1259. #ifdef DEBUG
  1260. printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
  1261. (int) tty, (int) file, cmd, (int) arg);
  1262. #endif
  1263. if (tty == (struct tty_struct *) NULL)
  1264. return -ENODEV;
  1265. portp = tty->driver_data;
  1266. if (portp == (stlport_t *) NULL)
  1267. return -ENODEV;
  1268. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1269. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1270. if (tty->flags & (1 << TTY_IO_ERROR))
  1271. return -EIO;
  1272. }
  1273. rc = 0;
  1274. switch (cmd) {
  1275. case TIOCGSOFTCAR:
  1276. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  1277. (unsigned __user *) argp);
  1278. break;
  1279. case TIOCSSOFTCAR:
  1280. if (get_user(ival, (unsigned int __user *) arg))
  1281. return -EFAULT;
  1282. tty->termios->c_cflag =
  1283. (tty->termios->c_cflag & ~CLOCAL) |
  1284. (ival ? CLOCAL : 0);
  1285. break;
  1286. case TIOCGSERIAL:
  1287. rc = stl_getserial(portp, argp);
  1288. break;
  1289. case TIOCSSERIAL:
  1290. rc = stl_setserial(portp, argp);
  1291. break;
  1292. case COM_GETPORTSTATS:
  1293. rc = stl_getportstats(portp, argp);
  1294. break;
  1295. case COM_CLRPORTSTATS:
  1296. rc = stl_clrportstats(portp, argp);
  1297. break;
  1298. case TIOCSERCONFIG:
  1299. case TIOCSERGWILD:
  1300. case TIOCSERSWILD:
  1301. case TIOCSERGETLSR:
  1302. case TIOCSERGSTRUCT:
  1303. case TIOCSERGETMULTI:
  1304. case TIOCSERSETMULTI:
  1305. default:
  1306. rc = -ENOIOCTLCMD;
  1307. break;
  1308. }
  1309. return rc;
  1310. }
  1311. /*****************************************************************************/
  1312. static void stl_settermios(struct tty_struct *tty, struct termios *old)
  1313. {
  1314. stlport_t *portp;
  1315. struct termios *tiosp;
  1316. #ifdef DEBUG
  1317. printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
  1318. #endif
  1319. if (tty == (struct tty_struct *) NULL)
  1320. return;
  1321. portp = tty->driver_data;
  1322. if (portp == (stlport_t *) NULL)
  1323. return;
  1324. tiosp = tty->termios;
  1325. if ((tiosp->c_cflag == old->c_cflag) &&
  1326. (tiosp->c_iflag == old->c_iflag))
  1327. return;
  1328. stl_setport(portp, tiosp);
  1329. stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
  1330. -1);
  1331. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
  1332. tty->hw_stopped = 0;
  1333. stl_start(tty);
  1334. }
  1335. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1336. wake_up_interruptible(&portp->open_wait);
  1337. }
  1338. /*****************************************************************************/
  1339. /*
  1340. * Attempt to flow control who ever is sending us data. Based on termios
  1341. * settings use software or/and hardware flow control.
  1342. */
  1343. static void stl_throttle(struct tty_struct *tty)
  1344. {
  1345. stlport_t *portp;
  1346. #ifdef DEBUG
  1347. printk("stl_throttle(tty=%x)\n", (int) tty);
  1348. #endif
  1349. if (tty == (struct tty_struct *) NULL)
  1350. return;
  1351. portp = tty->driver_data;
  1352. if (portp == (stlport_t *) NULL)
  1353. return;
  1354. stl_flowctrl(portp, 0);
  1355. }
  1356. /*****************************************************************************/
  1357. /*
  1358. * Unflow control the device sending us data...
  1359. */
  1360. static void stl_unthrottle(struct tty_struct *tty)
  1361. {
  1362. stlport_t *portp;
  1363. #ifdef DEBUG
  1364. printk("stl_unthrottle(tty=%x)\n", (int) tty);
  1365. #endif
  1366. if (tty == (struct tty_struct *) NULL)
  1367. return;
  1368. portp = tty->driver_data;
  1369. if (portp == (stlport_t *) NULL)
  1370. return;
  1371. stl_flowctrl(portp, 1);
  1372. }
  1373. /*****************************************************************************/
  1374. /*
  1375. * Stop the transmitter. Basically to do this we will just turn TX
  1376. * interrupts off.
  1377. */
  1378. static void stl_stop(struct tty_struct *tty)
  1379. {
  1380. stlport_t *portp;
  1381. #ifdef DEBUG
  1382. printk("stl_stop(tty=%x)\n", (int) tty);
  1383. #endif
  1384. if (tty == (struct tty_struct *) NULL)
  1385. return;
  1386. portp = tty->driver_data;
  1387. if (portp == (stlport_t *) NULL)
  1388. return;
  1389. stl_startrxtx(portp, -1, 0);
  1390. }
  1391. /*****************************************************************************/
  1392. /*
  1393. * Start the transmitter again. Just turn TX interrupts back on.
  1394. */
  1395. static void stl_start(struct tty_struct *tty)
  1396. {
  1397. stlport_t *portp;
  1398. #ifdef DEBUG
  1399. printk("stl_start(tty=%x)\n", (int) tty);
  1400. #endif
  1401. if (tty == (struct tty_struct *) NULL)
  1402. return;
  1403. portp = tty->driver_data;
  1404. if (portp == (stlport_t *) NULL)
  1405. return;
  1406. stl_startrxtx(portp, -1, 1);
  1407. }
  1408. /*****************************************************************************/
  1409. /*
  1410. * Hangup this port. This is pretty much like closing the port, only
  1411. * a little more brutal. No waiting for data to drain. Shutdown the
  1412. * port and maybe drop signals.
  1413. */
  1414. static void stl_hangup(struct tty_struct *tty)
  1415. {
  1416. stlport_t *portp;
  1417. #ifdef DEBUG
  1418. printk("stl_hangup(tty=%x)\n", (int) tty);
  1419. #endif
  1420. if (tty == (struct tty_struct *) NULL)
  1421. return;
  1422. portp = tty->driver_data;
  1423. if (portp == (stlport_t *) NULL)
  1424. return;
  1425. portp->flags &= ~ASYNC_INITIALIZED;
  1426. stl_disableintrs(portp);
  1427. if (tty->termios->c_cflag & HUPCL)
  1428. stl_setsignals(portp, 0, 0);
  1429. stl_enablerxtx(portp, 0, 0);
  1430. stl_flushbuffer(tty);
  1431. portp->istate = 0;
  1432. set_bit(TTY_IO_ERROR, &tty->flags);
  1433. if (portp->tx.buf != (char *) NULL) {
  1434. kfree(portp->tx.buf);
  1435. portp->tx.buf = (char *) NULL;
  1436. portp->tx.head = (char *) NULL;
  1437. portp->tx.tail = (char *) NULL;
  1438. }
  1439. portp->tty = (struct tty_struct *) NULL;
  1440. portp->flags &= ~ASYNC_NORMAL_ACTIVE;
  1441. portp->refcount = 0;
  1442. wake_up_interruptible(&portp->open_wait);
  1443. }
  1444. /*****************************************************************************/
  1445. static void stl_flushbuffer(struct tty_struct *tty)
  1446. {
  1447. stlport_t *portp;
  1448. #ifdef DEBUG
  1449. printk("stl_flushbuffer(tty=%x)\n", (int) tty);
  1450. #endif
  1451. if (tty == (struct tty_struct *) NULL)
  1452. return;
  1453. portp = tty->driver_data;
  1454. if (portp == (stlport_t *) NULL)
  1455. return;
  1456. stl_flush(portp);
  1457. tty_wakeup(tty);
  1458. }
  1459. /*****************************************************************************/
  1460. static void stl_breakctl(struct tty_struct *tty, int state)
  1461. {
  1462. stlport_t *portp;
  1463. #ifdef DEBUG
  1464. printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
  1465. #endif
  1466. if (tty == (struct tty_struct *) NULL)
  1467. return;
  1468. portp = tty->driver_data;
  1469. if (portp == (stlport_t *) NULL)
  1470. return;
  1471. stl_sendbreak(portp, ((state == -1) ? 1 : 2));
  1472. }
  1473. /*****************************************************************************/
  1474. static void stl_waituntilsent(struct tty_struct *tty, int timeout)
  1475. {
  1476. stlport_t *portp;
  1477. unsigned long tend;
  1478. #ifdef DEBUG
  1479. printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
  1480. #endif
  1481. if (tty == (struct tty_struct *) NULL)
  1482. return;
  1483. portp = tty->driver_data;
  1484. if (portp == (stlport_t *) NULL)
  1485. return;
  1486. if (timeout == 0)
  1487. timeout = HZ;
  1488. tend = jiffies + timeout;
  1489. while (stl_datastate(portp)) {
  1490. if (signal_pending(current))
  1491. break;
  1492. msleep_interruptible(20);
  1493. if (time_after_eq(jiffies, tend))
  1494. break;
  1495. }
  1496. }
  1497. /*****************************************************************************/
  1498. static void stl_sendxchar(struct tty_struct *tty, char ch)
  1499. {
  1500. stlport_t *portp;
  1501. #ifdef DEBUG
  1502. printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
  1503. #endif
  1504. if (tty == (struct tty_struct *) NULL)
  1505. return;
  1506. portp = tty->driver_data;
  1507. if (portp == (stlport_t *) NULL)
  1508. return;
  1509. if (ch == STOP_CHAR(tty))
  1510. stl_sendflow(portp, 0);
  1511. else if (ch == START_CHAR(tty))
  1512. stl_sendflow(portp, 1);
  1513. else
  1514. stl_putchar(tty, ch);
  1515. }
  1516. /*****************************************************************************/
  1517. #define MAXLINE 80
  1518. /*
  1519. * Format info for a specified port. The line is deliberately limited
  1520. * to 80 characters. (If it is too long it will be truncated, if too
  1521. * short then padded with spaces).
  1522. */
  1523. static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
  1524. {
  1525. char *sp;
  1526. int sigs, cnt;
  1527. sp = pos;
  1528. sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
  1529. portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
  1530. (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
  1531. if (portp->stats.rxframing)
  1532. sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
  1533. if (portp->stats.rxparity)
  1534. sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
  1535. if (portp->stats.rxbreaks)
  1536. sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
  1537. if (portp->stats.rxoverrun)
  1538. sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
  1539. sigs = stl_getsignals(portp);
  1540. cnt = sprintf(sp, "%s%s%s%s%s ",
  1541. (sigs & TIOCM_RTS) ? "|RTS" : "",
  1542. (sigs & TIOCM_CTS) ? "|CTS" : "",
  1543. (sigs & TIOCM_DTR) ? "|DTR" : "",
  1544. (sigs & TIOCM_CD) ? "|DCD" : "",
  1545. (sigs & TIOCM_DSR) ? "|DSR" : "");
  1546. *sp = ' ';
  1547. sp += cnt;
  1548. for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
  1549. *sp++ = ' ';
  1550. if (cnt >= MAXLINE)
  1551. pos[(MAXLINE - 2)] = '+';
  1552. pos[(MAXLINE - 1)] = '\n';
  1553. return MAXLINE;
  1554. }
  1555. /*****************************************************************************/
  1556. /*
  1557. * Port info, read from the /proc file system.
  1558. */
  1559. static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
  1560. {
  1561. stlbrd_t *brdp;
  1562. stlpanel_t *panelp;
  1563. stlport_t *portp;
  1564. int brdnr, panelnr, portnr, totalport;
  1565. int curoff, maxoff;
  1566. char *pos;
  1567. #ifdef DEBUG
  1568. printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
  1569. "data=%x\n", (int) page, (int) start, (int) off, count,
  1570. (int) eof, (int) data);
  1571. #endif
  1572. pos = page;
  1573. totalport = 0;
  1574. curoff = 0;
  1575. if (off == 0) {
  1576. pos += sprintf(pos, "%s: version %s", stl_drvtitle,
  1577. stl_drvversion);
  1578. while (pos < (page + MAXLINE - 1))
  1579. *pos++ = ' ';
  1580. *pos++ = '\n';
  1581. }
  1582. curoff = MAXLINE;
  1583. /*
  1584. * We scan through for each board, panel and port. The offset is
  1585. * calculated on the fly, and irrelevant ports are skipped.
  1586. */
  1587. for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
  1588. brdp = stl_brds[brdnr];
  1589. if (brdp == (stlbrd_t *) NULL)
  1590. continue;
  1591. if (brdp->state == 0)
  1592. continue;
  1593. maxoff = curoff + (brdp->nrports * MAXLINE);
  1594. if (off >= maxoff) {
  1595. curoff = maxoff;
  1596. continue;
  1597. }
  1598. totalport = brdnr * STL_MAXPORTS;
  1599. for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
  1600. panelp = brdp->panels[panelnr];
  1601. if (panelp == (stlpanel_t *) NULL)
  1602. continue;
  1603. maxoff = curoff + (panelp->nrports * MAXLINE);
  1604. if (off >= maxoff) {
  1605. curoff = maxoff;
  1606. totalport += panelp->nrports;
  1607. continue;
  1608. }
  1609. for (portnr = 0; (portnr < panelp->nrports); portnr++,
  1610. totalport++) {
  1611. portp = panelp->ports[portnr];
  1612. if (portp == (stlport_t *) NULL)
  1613. continue;
  1614. if (off >= (curoff += MAXLINE))
  1615. continue;
  1616. if ((pos - page + MAXLINE) > count)
  1617. goto stl_readdone;
  1618. pos += stl_portinfo(portp, totalport, pos);
  1619. }
  1620. }
  1621. }
  1622. *eof = 1;
  1623. stl_readdone:
  1624. *start = page;
  1625. return (pos - page);
  1626. }
  1627. /*****************************************************************************/
  1628. /*
  1629. * All board interrupts are vectored through here first. This code then
  1630. * calls off to the approrpriate board interrupt handlers.
  1631. */
  1632. static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
  1633. {
  1634. stlbrd_t *brdp = (stlbrd_t *) dev_id;
  1635. #ifdef DEBUG
  1636. printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
  1637. (int) regs);
  1638. #endif
  1639. return IRQ_RETVAL((* brdp->isr)(brdp));
  1640. }
  1641. /*****************************************************************************/
  1642. /*
  1643. * Interrupt service routine for EasyIO board types.
  1644. */
  1645. static int stl_eiointr(stlbrd_t *brdp)
  1646. {
  1647. stlpanel_t *panelp;
  1648. unsigned int iobase;
  1649. int handled = 0;
  1650. spin_lock(&brd_lock);
  1651. panelp = brdp->panels[0];
  1652. iobase = panelp->iobase;
  1653. while (inb(brdp->iostatus) & EIO_INTRPEND) {
  1654. handled = 1;
  1655. (* panelp->isr)(panelp, iobase);
  1656. }
  1657. spin_unlock(&brd_lock);
  1658. return handled;
  1659. }
  1660. /*****************************************************************************/
  1661. /*
  1662. * Interrupt service routine for ECH-AT board types.
  1663. */
  1664. static int stl_echatintr(stlbrd_t *brdp)
  1665. {
  1666. stlpanel_t *panelp;
  1667. unsigned int ioaddr;
  1668. int bnknr;
  1669. int handled = 0;
  1670. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  1671. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1672. handled = 1;
  1673. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1674. ioaddr = brdp->bnkstataddr[bnknr];
  1675. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1676. panelp = brdp->bnk2panel[bnknr];
  1677. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1678. }
  1679. }
  1680. }
  1681. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  1682. return handled;
  1683. }
  1684. /*****************************************************************************/
  1685. /*
  1686. * Interrupt service routine for ECH-MCA board types.
  1687. */
  1688. static int stl_echmcaintr(stlbrd_t *brdp)
  1689. {
  1690. stlpanel_t *panelp;
  1691. unsigned int ioaddr;
  1692. int bnknr;
  1693. int handled = 0;
  1694. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1695. handled = 1;
  1696. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1697. ioaddr = brdp->bnkstataddr[bnknr];
  1698. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1699. panelp = brdp->bnk2panel[bnknr];
  1700. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1701. }
  1702. }
  1703. }
  1704. return handled;
  1705. }
  1706. /*****************************************************************************/
  1707. /*
  1708. * Interrupt service routine for ECH-PCI board types.
  1709. */
  1710. static int stl_echpciintr(stlbrd_t *brdp)
  1711. {
  1712. stlpanel_t *panelp;
  1713. unsigned int ioaddr;
  1714. int bnknr, recheck;
  1715. int handled = 0;
  1716. while (1) {
  1717. recheck = 0;
  1718. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1719. outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
  1720. ioaddr = brdp->bnkstataddr[bnknr];
  1721. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1722. panelp = brdp->bnk2panel[bnknr];
  1723. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1724. recheck++;
  1725. handled = 1;
  1726. }
  1727. }
  1728. if (! recheck)
  1729. break;
  1730. }
  1731. return handled;
  1732. }
  1733. /*****************************************************************************/
  1734. /*
  1735. * Interrupt service routine for ECH-8/64-PCI board types.
  1736. */
  1737. static int stl_echpci64intr(stlbrd_t *brdp)
  1738. {
  1739. stlpanel_t *panelp;
  1740. unsigned int ioaddr;
  1741. int bnknr;
  1742. int handled = 0;
  1743. while (inb(brdp->ioctrl) & 0x1) {
  1744. handled = 1;
  1745. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1746. ioaddr = brdp->bnkstataddr[bnknr];
  1747. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1748. panelp = brdp->bnk2panel[bnknr];
  1749. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1750. }
  1751. }
  1752. }
  1753. return handled;
  1754. }
  1755. /*****************************************************************************/
  1756. /*
  1757. * Service an off-level request for some channel.
  1758. */
  1759. static void stl_offintr(void *private)
  1760. {
  1761. stlport_t *portp;
  1762. struct tty_struct *tty;
  1763. unsigned int oldsigs;
  1764. portp = private;
  1765. #ifdef DEBUG
  1766. printk("stl_offintr(portp=%x)\n", (int) portp);
  1767. #endif
  1768. if (portp == (stlport_t *) NULL)
  1769. return;
  1770. tty = portp->tty;
  1771. if (tty == (struct tty_struct *) NULL)
  1772. return;
  1773. lock_kernel();
  1774. if (test_bit(ASYI_TXLOW, &portp->istate)) {
  1775. tty_wakeup(tty);
  1776. }
  1777. if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
  1778. clear_bit(ASYI_DCDCHANGE, &portp->istate);
  1779. oldsigs = portp->sigs;
  1780. portp->sigs = stl_getsignals(portp);
  1781. if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
  1782. wake_up_interruptible(&portp->open_wait);
  1783. if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
  1784. if (portp->flags & ASYNC_CHECK_CD)
  1785. tty_hangup(tty); /* FIXME: module removal race here - AKPM */
  1786. }
  1787. }
  1788. unlock_kernel();
  1789. }
  1790. /*****************************************************************************/
  1791. /*
  1792. * Initialize all the ports on a panel.
  1793. */
  1794. static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
  1795. {
  1796. stlport_t *portp;
  1797. int chipmask, i;
  1798. #ifdef DEBUG
  1799. printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
  1800. #endif
  1801. chipmask = stl_panelinit(brdp, panelp);
  1802. /*
  1803. * All UART's are initialized (if found!). Now go through and setup
  1804. * each ports data structures.
  1805. */
  1806. for (i = 0; (i < panelp->nrports); i++) {
  1807. portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
  1808. if (!portp) {
  1809. printk("STALLION: failed to allocate memory "
  1810. "(size=%Zd)\n", sizeof(stlport_t));
  1811. break;
  1812. }
  1813. portp->magic = STL_PORTMAGIC;
  1814. portp->portnr = i;
  1815. portp->brdnr = panelp->brdnr;
  1816. portp->panelnr = panelp->panelnr;
  1817. portp->uartp = panelp->uartp;
  1818. portp->clk = brdp->clk;
  1819. portp->baud_base = STL_BAUDBASE;
  1820. portp->close_delay = STL_CLOSEDELAY;
  1821. portp->closing_wait = 30 * HZ;
  1822. INIT_WORK(&portp->tqueue, stl_offintr, portp);
  1823. init_waitqueue_head(&portp->open_wait);
  1824. init_waitqueue_head(&portp->close_wait);
  1825. portp->stats.brd = portp->brdnr;
  1826. portp->stats.panel = portp->panelnr;
  1827. portp->stats.port = portp->portnr;
  1828. panelp->ports[i] = portp;
  1829. stl_portinit(brdp, panelp, portp);
  1830. }
  1831. return(0);
  1832. }
  1833. /*****************************************************************************/
  1834. /*
  1835. * Try to find and initialize an EasyIO board.
  1836. */
  1837. static inline int stl_initeio(stlbrd_t *brdp)
  1838. {
  1839. stlpanel_t *panelp;
  1840. unsigned int status;
  1841. char *name;
  1842. int rc;
  1843. #ifdef DEBUG
  1844. printk("stl_initeio(brdp=%x)\n", (int) brdp);
  1845. #endif
  1846. brdp->ioctrl = brdp->ioaddr1 + 1;
  1847. brdp->iostatus = brdp->ioaddr1 + 2;
  1848. status = inb(brdp->iostatus);
  1849. if ((status & EIO_IDBITMASK) == EIO_MK3)
  1850. brdp->ioctrl++;
  1851. /*
  1852. * Handle board specific stuff now. The real difference is PCI
  1853. * or not PCI.
  1854. */
  1855. if (brdp->brdtype == BRD_EASYIOPCI) {
  1856. brdp->iosize1 = 0x80;
  1857. brdp->iosize2 = 0x80;
  1858. name = "serial(EIO-PCI)";
  1859. outb(0x41, (brdp->ioaddr2 + 0x4c));
  1860. } else {
  1861. brdp->iosize1 = 8;
  1862. name = "serial(EIO)";
  1863. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1864. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1865. printk("STALLION: invalid irq=%d for brd=%d\n",
  1866. brdp->irq, brdp->brdnr);
  1867. return(-EINVAL);
  1868. }
  1869. outb((stl_vecmap[brdp->irq] | EIO_0WS |
  1870. ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
  1871. brdp->ioctrl);
  1872. }
  1873. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  1874. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  1875. "%x conflicts with another device\n", brdp->brdnr,
  1876. brdp->ioaddr1);
  1877. return(-EBUSY);
  1878. }
  1879. if (brdp->iosize2 > 0)
  1880. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  1881. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  1882. "address %x conflicts with another device\n",
  1883. brdp->brdnr, brdp->ioaddr2);
  1884. printk(KERN_WARNING "STALLION: Warning, also "
  1885. "releasing board %d I/O address %x \n",
  1886. brdp->brdnr, brdp->ioaddr1);
  1887. release_region(brdp->ioaddr1, brdp->iosize1);
  1888. return(-EBUSY);
  1889. }
  1890. /*
  1891. * Everything looks OK, so let's go ahead and probe for the hardware.
  1892. */
  1893. brdp->clk = CD1400_CLK;
  1894. brdp->isr = stl_eiointr;
  1895. switch (status & EIO_IDBITMASK) {
  1896. case EIO_8PORTM:
  1897. brdp->clk = CD1400_CLK8M;
  1898. /* fall thru */
  1899. case EIO_8PORTRS:
  1900. case EIO_8PORTDI:
  1901. brdp->nrports = 8;
  1902. break;
  1903. case EIO_4PORTRS:
  1904. brdp->nrports = 4;
  1905. break;
  1906. case EIO_MK3:
  1907. switch (status & EIO_BRDMASK) {
  1908. case ID_BRD4:
  1909. brdp->nrports = 4;
  1910. break;
  1911. case ID_BRD8:
  1912. brdp->nrports = 8;
  1913. break;
  1914. case ID_BRD16:
  1915. brdp->nrports = 16;
  1916. break;
  1917. default:
  1918. return(-ENODEV);
  1919. }
  1920. break;
  1921. default:
  1922. return(-ENODEV);
  1923. }
  1924. /*
  1925. * We have verified that the board is actually present, so now we
  1926. * can complete the setup.
  1927. */
  1928. panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
  1929. if (!panelp) {
  1930. printk(KERN_WARNING "STALLION: failed to allocate memory "
  1931. "(size=%Zd)\n", sizeof(stlpanel_t));
  1932. return -ENOMEM;
  1933. }
  1934. panelp->magic = STL_PANELMAGIC;
  1935. panelp->brdnr = brdp->brdnr;
  1936. panelp->panelnr = 0;
  1937. panelp->nrports = brdp->nrports;
  1938. panelp->iobase = brdp->ioaddr1;
  1939. panelp->hwid = status;
  1940. if ((status & EIO_IDBITMASK) == EIO_MK3) {
  1941. panelp->uartp = (void *) &stl_sc26198uart;
  1942. panelp->isr = stl_sc26198intr;
  1943. } else {
  1944. panelp->uartp = (void *) &stl_cd1400uart;
  1945. panelp->isr = stl_cd1400eiointr;
  1946. }
  1947. brdp->panels[0] = panelp;
  1948. brdp->nrpanels = 1;
  1949. brdp->state |= BRD_FOUND;
  1950. brdp->hwid = status;
  1951. if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
  1952. printk("STALLION: failed to register interrupt "
  1953. "routine for %s irq=%d\n", name, brdp->irq);
  1954. rc = -ENODEV;
  1955. } else {
  1956. rc = 0;
  1957. }
  1958. return rc;
  1959. }
  1960. /*****************************************************************************/
  1961. /*
  1962. * Try to find an ECH board and initialize it. This code is capable of
  1963. * dealing with all types of ECH board.
  1964. */
  1965. static inline int stl_initech(stlbrd_t *brdp)
  1966. {
  1967. stlpanel_t *panelp;
  1968. unsigned int status, nxtid, ioaddr, conflict;
  1969. int panelnr, banknr, i;
  1970. char *name;
  1971. #ifdef DEBUG
  1972. printk("stl_initech(brdp=%x)\n", (int) brdp);
  1973. #endif
  1974. status = 0;
  1975. conflict = 0;
  1976. /*
  1977. * Set up the initial board register contents for boards. This varies a
  1978. * bit between the different board types. So we need to handle each
  1979. * separately. Also do a check that the supplied IRQ is good.
  1980. */
  1981. switch (brdp->brdtype) {
  1982. case BRD_ECH:
  1983. brdp->isr = stl_echatintr;
  1984. brdp->ioctrl = brdp->ioaddr1 + 1;
  1985. brdp->iostatus = brdp->ioaddr1 + 1;
  1986. status = inb(brdp->iostatus);
  1987. if ((status & ECH_IDBITMASK) != ECH_ID)
  1988. return(-ENODEV);
  1989. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1990. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1991. printk("STALLION: invalid irq=%d for brd=%d\n",
  1992. brdp->irq, brdp->brdnr);
  1993. return(-EINVAL);
  1994. }
  1995. status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
  1996. status |= (stl_vecmap[brdp->irq] << 1);
  1997. outb((status | ECH_BRDRESET), brdp->ioaddr1);
  1998. brdp->ioctrlval = ECH_INTENABLE |
  1999. ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
  2000. for (i = 0; (i < 10); i++)
  2001. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  2002. brdp->iosize1 = 2;
  2003. brdp->iosize2 = 32;
  2004. name = "serial(EC8/32)";
  2005. outb(status, brdp->ioaddr1);
  2006. break;
  2007. case BRD_ECHMC:
  2008. brdp->isr = stl_echmcaintr;
  2009. brdp->ioctrl = brdp->ioaddr1 + 0x20;
  2010. brdp->iostatus = brdp->ioctrl;
  2011. status = inb(brdp->iostatus);
  2012. if ((status & ECH_IDBITMASK) != ECH_ID)
  2013. return(-ENODEV);
  2014. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  2015. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  2016. printk("STALLION: invalid irq=%d for brd=%d\n",
  2017. brdp->irq, brdp->brdnr);
  2018. return(-EINVAL);
  2019. }
  2020. outb(ECHMC_BRDRESET, brdp->ioctrl);
  2021. outb(ECHMC_INTENABLE, brdp->ioctrl);
  2022. brdp->iosize1 = 64;
  2023. name = "serial(EC8/32-MC)";
  2024. break;
  2025. case BRD_ECHPCI:
  2026. brdp->isr = stl_echpciintr;
  2027. brdp->ioctrl = brdp->ioaddr1 + 2;
  2028. brdp->iosize1 = 4;
  2029. brdp->iosize2 = 8;
  2030. name = "serial(EC8/32-PCI)";
  2031. break;
  2032. case BRD_ECH64PCI:
  2033. brdp->isr = stl_echpci64intr;
  2034. brdp->ioctrl = brdp->ioaddr2 + 0x40;
  2035. outb(0x43, (brdp->ioaddr1 + 0x4c));
  2036. brdp->iosize1 = 0x80;
  2037. brdp->iosize2 = 0x80;
  2038. name = "serial(EC8/64-PCI)";
  2039. break;
  2040. default:
  2041. printk("STALLION: unknown board type=%d\n", brdp->brdtype);
  2042. return(-EINVAL);
  2043. break;
  2044. }
  2045. /*
  2046. * Check boards for possible IO address conflicts and return fail status
  2047. * if an IO conflict found.
  2048. */
  2049. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  2050. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  2051. "%x conflicts with another device\n", brdp->brdnr,
  2052. brdp->ioaddr1);
  2053. return(-EBUSY);
  2054. }
  2055. if (brdp->iosize2 > 0)
  2056. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  2057. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  2058. "address %x conflicts with another device\n",
  2059. brdp->brdnr, brdp->ioaddr2);
  2060. printk(KERN_WARNING "STALLION: Warning, also "
  2061. "releasing board %d I/O address %x \n",
  2062. brdp->brdnr, brdp->ioaddr1);
  2063. release_region(brdp->ioaddr1, brdp->iosize1);
  2064. return(-EBUSY);
  2065. }
  2066. /*
  2067. * Scan through the secondary io address space looking for panels.
  2068. * As we find'em allocate and initialize panel structures for each.
  2069. */
  2070. brdp->clk = CD1400_CLK;
  2071. brdp->hwid = status;
  2072. ioaddr = brdp->ioaddr2;
  2073. banknr = 0;
  2074. panelnr = 0;
  2075. nxtid = 0;
  2076. for (i = 0; (i < STL_MAXPANELS); i++) {
  2077. if (brdp->brdtype == BRD_ECHPCI) {
  2078. outb(nxtid, brdp->ioctrl);
  2079. ioaddr = brdp->ioaddr2;
  2080. }
  2081. status = inb(ioaddr + ECH_PNLSTATUS);
  2082. if ((status & ECH_PNLIDMASK) != nxtid)
  2083. break;
  2084. panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
  2085. if (!panelp) {
  2086. printk("STALLION: failed to allocate memory "
  2087. "(size=%Zd)\n", sizeof(stlpanel_t));
  2088. break;
  2089. }
  2090. panelp->magic = STL_PANELMAGIC;
  2091. panelp->brdnr = brdp->brdnr;
  2092. panelp->panelnr = panelnr;
  2093. panelp->iobase = ioaddr;
  2094. panelp->pagenr = nxtid;
  2095. panelp->hwid = status;
  2096. brdp->bnk2panel[banknr] = panelp;
  2097. brdp->bnkpageaddr[banknr] = nxtid;
  2098. brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
  2099. if (status & ECH_PNLXPID) {
  2100. panelp->uartp = (void *) &stl_sc26198uart;
  2101. panelp->isr = stl_sc26198intr;
  2102. if (status & ECH_PNL16PORT) {
  2103. panelp->nrports = 16;
  2104. brdp->bnk2panel[banknr] = panelp;
  2105. brdp->bnkpageaddr[banknr] = nxtid;
  2106. brdp->bnkstataddr[banknr++] = ioaddr + 4 +
  2107. ECH_PNLSTATUS;
  2108. } else {
  2109. panelp->nrports = 8;
  2110. }
  2111. } else {
  2112. panelp->uartp = (void *) &stl_cd1400uart;
  2113. panelp->isr = stl_cd1400echintr;
  2114. if (status & ECH_PNL16PORT) {
  2115. panelp->nrports = 16;
  2116. panelp->ackmask = 0x80;
  2117. if (brdp->brdtype != BRD_ECHPCI)
  2118. ioaddr += EREG_BANKSIZE;
  2119. brdp->bnk2panel[banknr] = panelp;
  2120. brdp->bnkpageaddr[banknr] = ++nxtid;
  2121. brdp->bnkstataddr[banknr++] = ioaddr +
  2122. ECH_PNLSTATUS;
  2123. } else {
  2124. panelp->nrports = 8;
  2125. panelp->ackmask = 0xc0;
  2126. }
  2127. }
  2128. nxtid++;
  2129. ioaddr += EREG_BANKSIZE;
  2130. brdp->nrports += panelp->nrports;
  2131. brdp->panels[panelnr++] = panelp;
  2132. if ((brdp->brdtype != BRD_ECHPCI) &&
  2133. (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
  2134. break;
  2135. }
  2136. brdp->nrpanels = panelnr;
  2137. brdp->nrbnks = banknr;
  2138. if (brdp->brdtype == BRD_ECH)
  2139. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  2140. brdp->state |= BRD_FOUND;
  2141. if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
  2142. printk("STALLION: failed to register interrupt "
  2143. "routine for %s irq=%d\n", name, brdp->irq);
  2144. i = -ENODEV;
  2145. } else {
  2146. i = 0;
  2147. }
  2148. return(i);
  2149. }
  2150. /*****************************************************************************/
  2151. /*
  2152. * Initialize and configure the specified board.
  2153. * Scan through all the boards in the configuration and see what we
  2154. * can find. Handle EIO and the ECH boards a little differently here
  2155. * since the initial search and setup is very different.
  2156. */
  2157. static int __init stl_brdinit(stlbrd_t *brdp)
  2158. {
  2159. int i;
  2160. #ifdef DEBUG
  2161. printk("stl_brdinit(brdp=%x)\n", (int) brdp);
  2162. #endif
  2163. switch (brdp->brdtype) {
  2164. case BRD_EASYIO:
  2165. case BRD_EASYIOPCI:
  2166. stl_initeio(brdp);
  2167. break;
  2168. case BRD_ECH:
  2169. case BRD_ECHMC:
  2170. case BRD_ECHPCI:
  2171. case BRD_ECH64PCI:
  2172. stl_initech(brdp);
  2173. break;
  2174. default:
  2175. printk("STALLION: board=%d is unknown board type=%d\n",
  2176. brdp->brdnr, brdp->brdtype);
  2177. return(ENODEV);
  2178. }
  2179. stl_brds[brdp->brdnr] = brdp;
  2180. if ((brdp->state & BRD_FOUND) == 0) {
  2181. printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
  2182. stl_brdnames[brdp->brdtype], brdp->brdnr,
  2183. brdp->ioaddr1, brdp->irq);
  2184. return(ENODEV);
  2185. }
  2186. for (i = 0; (i < STL_MAXPANELS); i++)
  2187. if (brdp->panels[i] != (stlpanel_t *) NULL)
  2188. stl_initports(brdp, brdp->panels[i]);
  2189. printk("STALLION: %s found, board=%d io=%x irq=%d "
  2190. "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
  2191. brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
  2192. brdp->nrports);
  2193. return(0);
  2194. }
  2195. /*****************************************************************************/
  2196. /*
  2197. * Find the next available board number that is free.
  2198. */
  2199. static inline int stl_getbrdnr(void)
  2200. {
  2201. int i;
  2202. for (i = 0; (i < STL_MAXBRDS); i++) {
  2203. if (stl_brds[i] == (stlbrd_t *) NULL) {
  2204. if (i >= stl_nrbrds)
  2205. stl_nrbrds = i + 1;
  2206. return(i);
  2207. }
  2208. }
  2209. return(-1);
  2210. }
  2211. /*****************************************************************************/
  2212. #ifdef CONFIG_PCI
  2213. /*
  2214. * We have a Stallion board. Allocate a board structure and
  2215. * initialize it. Read its IO and IRQ resources from PCI
  2216. * configuration space.
  2217. */
  2218. static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
  2219. {
  2220. stlbrd_t *brdp;
  2221. #ifdef DEBUG
  2222. printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
  2223. devp->bus->number, devp->devfn);
  2224. #endif
  2225. if (pci_enable_device(devp))
  2226. return(-EIO);
  2227. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  2228. return(-ENOMEM);
  2229. if ((brdp->brdnr = stl_getbrdnr()) < 0) {
  2230. printk("STALLION: too many boards found, "
  2231. "maximum supported %d\n", STL_MAXBRDS);
  2232. return(0);
  2233. }
  2234. brdp->brdtype = brdtype;
  2235. /*
  2236. * Different Stallion boards use the BAR registers in different ways,
  2237. * so set up io addresses based on board type.
  2238. */
  2239. #ifdef DEBUG
  2240. printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
  2241. pci_resource_start(devp, 0), pci_resource_start(devp, 1),
  2242. pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
  2243. #endif
  2244. /*
  2245. * We have all resources from the board, so let's setup the actual
  2246. * board structure now.
  2247. */
  2248. switch (brdtype) {
  2249. case BRD_ECHPCI:
  2250. brdp->ioaddr2 = pci_resource_start(devp, 0);
  2251. brdp->ioaddr1 = pci_resource_start(devp, 1);
  2252. break;
  2253. case BRD_ECH64PCI:
  2254. brdp->ioaddr2 = pci_resource_start(devp, 2);
  2255. brdp->ioaddr1 = pci_resource_start(devp, 1);
  2256. break;
  2257. case BRD_EASYIOPCI:
  2258. brdp->ioaddr1 = pci_resource_start(devp, 2);
  2259. brdp->ioaddr2 = pci_resource_start(devp, 1);
  2260. break;
  2261. default:
  2262. printk("STALLION: unknown PCI board type=%d\n", brdtype);
  2263. break;
  2264. }
  2265. brdp->irq = devp->irq;
  2266. stl_brdinit(brdp);
  2267. return(0);
  2268. }
  2269. /*****************************************************************************/
  2270. /*
  2271. * Find all Stallion PCI boards that might be installed. Initialize each
  2272. * one as it is found.
  2273. */
  2274. static inline int stl_findpcibrds(void)
  2275. {
  2276. struct pci_dev *dev = NULL;
  2277. int i, rc;
  2278. #ifdef DEBUG
  2279. printk("stl_findpcibrds()\n");
  2280. #endif
  2281. for (i = 0; (i < stl_nrpcibrds); i++)
  2282. while ((dev = pci_find_device(stl_pcibrds[i].vendid,
  2283. stl_pcibrds[i].devid, dev))) {
  2284. /*
  2285. * Found a device on the PCI bus that has our vendor and
  2286. * device ID. Need to check now that it is really us.
  2287. */
  2288. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  2289. continue;
  2290. rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
  2291. if (rc)
  2292. return(rc);
  2293. }
  2294. return(0);
  2295. }
  2296. #endif
  2297. /*****************************************************************************/
  2298. /*
  2299. * Scan through all the boards in the configuration and see what we
  2300. * can find. Handle EIO and the ECH boards a little differently here
  2301. * since the initial search and setup is too different.
  2302. */
  2303. static inline int stl_initbrds(void)
  2304. {
  2305. stlbrd_t *brdp;
  2306. stlconf_t *confp;
  2307. int i;
  2308. #ifdef DEBUG
  2309. printk("stl_initbrds()\n");
  2310. #endif
  2311. if (stl_nrbrds > STL_MAXBRDS) {
  2312. printk("STALLION: too many boards in configuration table, "
  2313. "truncating to %d\n", STL_MAXBRDS);
  2314. stl_nrbrds = STL_MAXBRDS;
  2315. }
  2316. /*
  2317. * Firstly scan the list of static boards configured. Allocate
  2318. * resources and initialize the boards as found.
  2319. */
  2320. for (i = 0; (i < stl_nrbrds); i++) {
  2321. confp = &stl_brdconf[i];
  2322. stl_parsebrd(confp, stl_brdsp[i]);
  2323. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  2324. return(-ENOMEM);
  2325. brdp->brdnr = i;
  2326. brdp->brdtype = confp->brdtype;
  2327. brdp->ioaddr1 = confp->ioaddr1;
  2328. brdp->ioaddr2 = confp->ioaddr2;
  2329. brdp->irq = confp->irq;
  2330. brdp->irqtype = confp->irqtype;
  2331. stl_brdinit(brdp);
  2332. }
  2333. /*
  2334. * Find any dynamically supported boards. That is via module load
  2335. * line options or auto-detected on the PCI bus.
  2336. */
  2337. stl_argbrds();
  2338. #ifdef CONFIG_PCI
  2339. stl_findpcibrds();
  2340. #endif
  2341. return(0);
  2342. }
  2343. /*****************************************************************************/
  2344. /*
  2345. * Return the board stats structure to user app.
  2346. */
  2347. static int stl_getbrdstats(combrd_t __user *bp)
  2348. {
  2349. stlbrd_t *brdp;
  2350. stlpanel_t *panelp;
  2351. int i;
  2352. if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
  2353. return -EFAULT;
  2354. if (stl_brdstats.brd >= STL_MAXBRDS)
  2355. return(-ENODEV);
  2356. brdp = stl_brds[stl_brdstats.brd];
  2357. if (brdp == (stlbrd_t *) NULL)
  2358. return(-ENODEV);
  2359. memset(&stl_brdstats, 0, sizeof(combrd_t));
  2360. stl_brdstats.brd = brdp->brdnr;
  2361. stl_brdstats.type = brdp->brdtype;
  2362. stl_brdstats.hwid = brdp->hwid;
  2363. stl_brdstats.state = brdp->state;
  2364. stl_brdstats.ioaddr = brdp->ioaddr1;
  2365. stl_brdstats.ioaddr2 = brdp->ioaddr2;
  2366. stl_brdstats.irq = brdp->irq;
  2367. stl_brdstats.nrpanels = brdp->nrpanels;
  2368. stl_brdstats.nrports = brdp->nrports;
  2369. for (i = 0; (i < brdp->nrpanels); i++) {
  2370. panelp = brdp->panels[i];
  2371. stl_brdstats.panels[i].panel = i;
  2372. stl_brdstats.panels[i].hwid = panelp->hwid;
  2373. stl_brdstats.panels[i].nrports = panelp->nrports;
  2374. }
  2375. return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
  2376. }
  2377. /*****************************************************************************/
  2378. /*
  2379. * Resolve the referenced port number into a port struct pointer.
  2380. */
  2381. static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
  2382. {
  2383. stlbrd_t *brdp;
  2384. stlpanel_t *panelp;
  2385. if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
  2386. return((stlport_t *) NULL);
  2387. brdp = stl_brds[brdnr];
  2388. if (brdp == (stlbrd_t *) NULL)
  2389. return((stlport_t *) NULL);
  2390. if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
  2391. return((stlport_t *) NULL);
  2392. panelp = brdp->panels[panelnr];
  2393. if (panelp == (stlpanel_t *) NULL)
  2394. return((stlport_t *) NULL);
  2395. if ((portnr < 0) || (portnr >= panelp->nrports))
  2396. return((stlport_t *) NULL);
  2397. return(panelp->ports[portnr]);
  2398. }
  2399. /*****************************************************************************/
  2400. /*
  2401. * Return the port stats structure to user app. A NULL port struct
  2402. * pointer passed in means that we need to find out from the app
  2403. * what port to get stats for (used through board control device).
  2404. */
  2405. static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
  2406. {
  2407. unsigned char *head, *tail;
  2408. unsigned long flags;
  2409. if (!portp) {
  2410. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2411. return -EFAULT;
  2412. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2413. stl_comstats.port);
  2414. if (portp == (stlport_t *) NULL)
  2415. return(-ENODEV);
  2416. }
  2417. portp->stats.state = portp->istate;
  2418. portp->stats.flags = portp->flags;
  2419. portp->stats.hwid = portp->hwid;
  2420. portp->stats.ttystate = 0;
  2421. portp->stats.cflags = 0;
  2422. portp->stats.iflags = 0;
  2423. portp->stats.oflags = 0;
  2424. portp->stats.lflags = 0;
  2425. portp->stats.rxbuffered = 0;
  2426. spin_lock_irqsave(&stallion_lock, flags);
  2427. if (portp->tty != (struct tty_struct *) NULL) {
  2428. if (portp->tty->driver_data == portp) {
  2429. portp->stats.ttystate = portp->tty->flags;
  2430. /* No longer available as a statistic */
  2431. portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
  2432. if (portp->tty->termios != (struct termios *) NULL) {
  2433. portp->stats.cflags = portp->tty->termios->c_cflag;
  2434. portp->stats.iflags = portp->tty->termios->c_iflag;
  2435. portp->stats.oflags = portp->tty->termios->c_oflag;
  2436. portp->stats.lflags = portp->tty->termios->c_lflag;
  2437. }
  2438. }
  2439. }
  2440. spin_unlock_irqrestore(&stallion_lock, flags);
  2441. head = portp->tx.head;
  2442. tail = portp->tx.tail;
  2443. portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
  2444. (STL_TXBUFSIZE - (tail - head)));
  2445. portp->stats.signals = (unsigned long) stl_getsignals(portp);
  2446. return copy_to_user(cp, &portp->stats,
  2447. sizeof(comstats_t)) ? -EFAULT : 0;
  2448. }
  2449. /*****************************************************************************/
  2450. /*
  2451. * Clear the port stats structure. We also return it zeroed out...
  2452. */
  2453. static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
  2454. {
  2455. if (!portp) {
  2456. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2457. return -EFAULT;
  2458. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2459. stl_comstats.port);
  2460. if (portp == (stlport_t *) NULL)
  2461. return(-ENODEV);
  2462. }
  2463. memset(&portp->stats, 0, sizeof(comstats_t));
  2464. portp->stats.brd = portp->brdnr;
  2465. portp->stats.panel = portp->panelnr;
  2466. portp->stats.port = portp->portnr;
  2467. return copy_to_user(cp, &portp->stats,
  2468. sizeof(comstats_t)) ? -EFAULT : 0;
  2469. }
  2470. /*****************************************************************************/
  2471. /*
  2472. * Return the entire driver ports structure to a user app.
  2473. */
  2474. static int stl_getportstruct(stlport_t __user *arg)
  2475. {
  2476. stlport_t *portp;
  2477. if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
  2478. return -EFAULT;
  2479. portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
  2480. stl_dummyport.portnr);
  2481. if (!portp)
  2482. return -ENODEV;
  2483. return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
  2484. }
  2485. /*****************************************************************************/
  2486. /*
  2487. * Return the entire driver board structure to a user app.
  2488. */
  2489. static int stl_getbrdstruct(stlbrd_t __user *arg)
  2490. {
  2491. stlbrd_t *brdp;
  2492. if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
  2493. return -EFAULT;
  2494. if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
  2495. return -ENODEV;
  2496. brdp = stl_brds[stl_dummybrd.brdnr];
  2497. if (!brdp)
  2498. return(-ENODEV);
  2499. return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
  2500. }
  2501. /*****************************************************************************/
  2502. /*
  2503. * The "staliomem" device is also required to do some special operations
  2504. * on the board and/or ports. In this driver it is mostly used for stats
  2505. * collection.
  2506. */
  2507. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  2508. {
  2509. int brdnr, rc;
  2510. void __user *argp = (void __user *)arg;
  2511. #ifdef DEBUG
  2512. printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
  2513. (int) fp, cmd, (int) arg);
  2514. #endif
  2515. brdnr = iminor(ip);
  2516. if (brdnr >= STL_MAXBRDS)
  2517. return(-ENODEV);
  2518. rc = 0;
  2519. switch (cmd) {
  2520. case COM_GETPORTSTATS:
  2521. rc = stl_getportstats(NULL, argp);
  2522. break;
  2523. case COM_CLRPORTSTATS:
  2524. rc = stl_clrportstats(NULL, argp);
  2525. break;
  2526. case COM_GETBRDSTATS:
  2527. rc = stl_getbrdstats(argp);
  2528. break;
  2529. case COM_READPORT:
  2530. rc = stl_getportstruct(argp);
  2531. break;
  2532. case COM_READBOARD:
  2533. rc = stl_getbrdstruct(argp);
  2534. break;
  2535. default:
  2536. rc = -ENOIOCTLCMD;
  2537. break;
  2538. }
  2539. return(rc);
  2540. }
  2541. static struct tty_operations stl_ops = {
  2542. .open = stl_open,
  2543. .close = stl_close,
  2544. .write = stl_write,
  2545. .put_char = stl_putchar,
  2546. .flush_chars = stl_flushchars,
  2547. .write_room = stl_writeroom,
  2548. .chars_in_buffer = stl_charsinbuffer,
  2549. .ioctl = stl_ioctl,
  2550. .set_termios = stl_settermios,
  2551. .throttle = stl_throttle,
  2552. .unthrottle = stl_unthrottle,
  2553. .stop = stl_stop,
  2554. .start = stl_start,
  2555. .hangup = stl_hangup,
  2556. .flush_buffer = stl_flushbuffer,
  2557. .break_ctl = stl_breakctl,
  2558. .wait_until_sent = stl_waituntilsent,
  2559. .send_xchar = stl_sendxchar,
  2560. .read_proc = stl_readproc,
  2561. .tiocmget = stl_tiocmget,
  2562. .tiocmset = stl_tiocmset,
  2563. };
  2564. /*****************************************************************************/
  2565. static int __init stl_init(void)
  2566. {
  2567. int i;
  2568. printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
  2569. spin_lock_init(&stallion_lock);
  2570. spin_lock_init(&brd_lock);
  2571. stl_initbrds();
  2572. stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  2573. if (!stl_serial)
  2574. return -1;
  2575. /*
  2576. * Set up a character driver for per board stuff. This is mainly used
  2577. * to do stats ioctls on the ports.
  2578. */
  2579. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
  2580. printk("STALLION: failed to register serial board device\n");
  2581. devfs_mk_dir("staliomem");
  2582. stallion_class = class_create(THIS_MODULE, "staliomem");
  2583. for (i = 0; i < 4; i++) {
  2584. devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
  2585. S_IFCHR|S_IRUSR|S_IWUSR,
  2586. "staliomem/%d", i);
  2587. class_device_create(stallion_class, NULL,
  2588. MKDEV(STL_SIOMEMMAJOR, i), NULL,
  2589. "staliomem%d", i);
  2590. }
  2591. stl_serial->owner = THIS_MODULE;
  2592. stl_serial->driver_name = stl_drvname;
  2593. stl_serial->name = "ttyE";
  2594. stl_serial->devfs_name = "tts/E";
  2595. stl_serial->major = STL_SERIALMAJOR;
  2596. stl_serial->minor_start = 0;
  2597. stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
  2598. stl_serial->subtype = SERIAL_TYPE_NORMAL;
  2599. stl_serial->init_termios = stl_deftermios;
  2600. stl_serial->flags = TTY_DRIVER_REAL_RAW;
  2601. tty_set_operations(stl_serial, &stl_ops);
  2602. if (tty_register_driver(stl_serial)) {
  2603. put_tty_driver(stl_serial);
  2604. printk("STALLION: failed to register serial driver\n");
  2605. return -1;
  2606. }
  2607. return 0;
  2608. }
  2609. /*****************************************************************************/
  2610. /* CD1400 HARDWARE FUNCTIONS */
  2611. /*****************************************************************************/
  2612. /*
  2613. * These functions get/set/update the registers of the cd1400 UARTs.
  2614. * Access to the cd1400 registers is via an address/data io port pair.
  2615. * (Maybe should make this inline...)
  2616. */
  2617. static int stl_cd1400getreg(stlport_t *portp, int regnr)
  2618. {
  2619. outb((regnr + portp->uartaddr), portp->ioaddr);
  2620. return inb(portp->ioaddr + EREG_DATA);
  2621. }
  2622. static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
  2623. {
  2624. outb((regnr + portp->uartaddr), portp->ioaddr);
  2625. outb(value, portp->ioaddr + EREG_DATA);
  2626. }
  2627. static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
  2628. {
  2629. outb((regnr + portp->uartaddr), portp->ioaddr);
  2630. if (inb(portp->ioaddr + EREG_DATA) != value) {
  2631. outb(value, portp->ioaddr + EREG_DATA);
  2632. return 1;
  2633. }
  2634. return 0;
  2635. }
  2636. /*****************************************************************************/
  2637. /*
  2638. * Inbitialize the UARTs in a panel. We don't care what sort of board
  2639. * these ports are on - since the port io registers are almost
  2640. * identical when dealing with ports.
  2641. */
  2642. static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
  2643. {
  2644. unsigned int gfrcr;
  2645. int chipmask, i, j;
  2646. int nrchips, uartaddr, ioaddr;
  2647. unsigned long flags;
  2648. #ifdef DEBUG
  2649. printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
  2650. #endif
  2651. spin_lock_irqsave(&brd_lock, flags);
  2652. BRDENABLE(panelp->brdnr, panelp->pagenr);
  2653. /*
  2654. * Check that each chip is present and started up OK.
  2655. */
  2656. chipmask = 0;
  2657. nrchips = panelp->nrports / CD1400_PORTS;
  2658. for (i = 0; (i < nrchips); i++) {
  2659. if (brdp->brdtype == BRD_ECHPCI) {
  2660. outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
  2661. ioaddr = panelp->iobase;
  2662. } else {
  2663. ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
  2664. }
  2665. uartaddr = (i & 0x01) ? 0x080 : 0;
  2666. outb((GFRCR + uartaddr), ioaddr);
  2667. outb(0, (ioaddr + EREG_DATA));
  2668. outb((CCR + uartaddr), ioaddr);
  2669. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2670. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2671. outb((GFRCR + uartaddr), ioaddr);
  2672. for (j = 0; (j < CCR_MAXWAIT); j++) {
  2673. if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
  2674. break;
  2675. }
  2676. if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
  2677. printk("STALLION: cd1400 not responding, "
  2678. "brd=%d panel=%d chip=%d\n",
  2679. panelp->brdnr, panelp->panelnr, i);
  2680. continue;
  2681. }
  2682. chipmask |= (0x1 << i);
  2683. outb((PPR + uartaddr), ioaddr);
  2684. outb(PPR_SCALAR, (ioaddr + EREG_DATA));
  2685. }
  2686. BRDDISABLE(panelp->brdnr);
  2687. spin_unlock_irqrestore(&brd_lock, flags);
  2688. return chipmask;
  2689. }
  2690. /*****************************************************************************/
  2691. /*
  2692. * Initialize hardware specific port registers.
  2693. */
  2694. static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
  2695. {
  2696. unsigned long flags;
  2697. #ifdef DEBUG
  2698. printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
  2699. (int) brdp, (int) panelp, (int) portp);
  2700. #endif
  2701. if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
  2702. (portp == (stlport_t *) NULL))
  2703. return;
  2704. spin_lock_irqsave(&brd_lock, flags);
  2705. portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
  2706. (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
  2707. portp->uartaddr = (portp->portnr & 0x04) << 5;
  2708. portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
  2709. BRDENABLE(portp->brdnr, portp->pagenr);
  2710. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2711. stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
  2712. portp->hwid = stl_cd1400getreg(portp, GFRCR);
  2713. BRDDISABLE(portp->brdnr);
  2714. spin_unlock_irqrestore(&brd_lock, flags);
  2715. }
  2716. /*****************************************************************************/
  2717. /*
  2718. * Wait for the command register to be ready. We will poll this,
  2719. * since it won't usually take too long to be ready.
  2720. */
  2721. static void stl_cd1400ccrwait(stlport_t *portp)
  2722. {
  2723. int i;
  2724. for (i = 0; (i < CCR_MAXWAIT); i++) {
  2725. if (stl_cd1400getreg(portp, CCR) == 0) {
  2726. return;
  2727. }
  2728. }
  2729. printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
  2730. portp->portnr, portp->panelnr, portp->brdnr);
  2731. }
  2732. /*****************************************************************************/
  2733. /*
  2734. * Set up the cd1400 registers for a port based on the termios port
  2735. * settings.
  2736. */
  2737. static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
  2738. {
  2739. stlbrd_t *brdp;
  2740. unsigned long flags;
  2741. unsigned int clkdiv, baudrate;
  2742. unsigned char cor1, cor2, cor3;
  2743. unsigned char cor4, cor5, ccr;
  2744. unsigned char srer, sreron, sreroff;
  2745. unsigned char mcor1, mcor2, rtpr;
  2746. unsigned char clk, div;
  2747. cor1 = 0;
  2748. cor2 = 0;
  2749. cor3 = 0;
  2750. cor4 = 0;
  2751. cor5 = 0;
  2752. ccr = 0;
  2753. rtpr = 0;
  2754. clk = 0;
  2755. div = 0;
  2756. mcor1 = 0;
  2757. mcor2 = 0;
  2758. sreron = 0;
  2759. sreroff = 0;
  2760. brdp = stl_brds[portp->brdnr];
  2761. if (brdp == (stlbrd_t *) NULL)
  2762. return;
  2763. /*
  2764. * Set up the RX char ignore mask with those RX error types we
  2765. * can ignore. We can get the cd1400 to help us out a little here,
  2766. * it will ignore parity errors and breaks for us.
  2767. */
  2768. portp->rxignoremsk = 0;
  2769. if (tiosp->c_iflag & IGNPAR) {
  2770. portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
  2771. cor1 |= COR1_PARIGNORE;
  2772. }
  2773. if (tiosp->c_iflag & IGNBRK) {
  2774. portp->rxignoremsk |= ST_BREAK;
  2775. cor4 |= COR4_IGNBRK;
  2776. }
  2777. portp->rxmarkmsk = ST_OVERRUN;
  2778. if (tiosp->c_iflag & (INPCK | PARMRK))
  2779. portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
  2780. if (tiosp->c_iflag & BRKINT)
  2781. portp->rxmarkmsk |= ST_BREAK;
  2782. /*
  2783. * Go through the char size, parity and stop bits and set all the
  2784. * option register appropriately.
  2785. */
  2786. switch (tiosp->c_cflag & CSIZE) {
  2787. case CS5:
  2788. cor1 |= COR1_CHL5;
  2789. break;
  2790. case CS6:
  2791. cor1 |= COR1_CHL6;
  2792. break;
  2793. case CS7:
  2794. cor1 |= COR1_CHL7;
  2795. break;
  2796. default:
  2797. cor1 |= COR1_CHL8;
  2798. break;
  2799. }
  2800. if (tiosp->c_cflag & CSTOPB)
  2801. cor1 |= COR1_STOP2;
  2802. else
  2803. cor1 |= COR1_STOP1;
  2804. if (tiosp->c_cflag & PARENB) {
  2805. if (tiosp->c_cflag & PARODD)
  2806. cor1 |= (COR1_PARENB | COR1_PARODD);
  2807. else
  2808. cor1 |= (COR1_PARENB | COR1_PAREVEN);
  2809. } else {
  2810. cor1 |= COR1_PARNONE;
  2811. }
  2812. /*
  2813. * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
  2814. * space for hardware flow control and the like. This should be set to
  2815. * VMIN. Also here we will set the RX data timeout to 10ms - this should
  2816. * really be based on VTIME.
  2817. */
  2818. cor3 |= FIFO_RXTHRESHOLD;
  2819. rtpr = 2;
  2820. /*
  2821. * Calculate the baud rate timers. For now we will just assume that
  2822. * the input and output baud are the same. Could have used a baud
  2823. * table here, but this way we can generate virtually any baud rate
  2824. * we like!
  2825. */
  2826. baudrate = tiosp->c_cflag & CBAUD;
  2827. if (baudrate & CBAUDEX) {
  2828. baudrate &= ~CBAUDEX;
  2829. if ((baudrate < 1) || (baudrate > 4))
  2830. tiosp->c_cflag &= ~CBAUDEX;
  2831. else
  2832. baudrate += 15;
  2833. }
  2834. baudrate = stl_baudrates[baudrate];
  2835. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2836. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2837. baudrate = 57600;
  2838. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2839. baudrate = 115200;
  2840. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2841. baudrate = 230400;
  2842. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2843. baudrate = 460800;
  2844. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2845. baudrate = (portp->baud_base / portp->custom_divisor);
  2846. }
  2847. if (baudrate > STL_CD1400MAXBAUD)
  2848. baudrate = STL_CD1400MAXBAUD;
  2849. if (baudrate > 0) {
  2850. for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
  2851. clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
  2852. if (clkdiv < 0x100)
  2853. break;
  2854. }
  2855. div = (unsigned char) clkdiv;
  2856. }
  2857. /*
  2858. * Check what form of modem signaling is required and set it up.
  2859. */
  2860. if ((tiosp->c_cflag & CLOCAL) == 0) {
  2861. mcor1 |= MCOR1_DCD;
  2862. mcor2 |= MCOR2_DCD;
  2863. sreron |= SRER_MODEM;
  2864. portp->flags |= ASYNC_CHECK_CD;
  2865. } else {
  2866. portp->flags &= ~ASYNC_CHECK_CD;
  2867. }
  2868. /*
  2869. * Setup cd1400 enhanced modes if we can. In particular we want to
  2870. * handle as much of the flow control as possible automatically. As
  2871. * well as saving a few CPU cycles it will also greatly improve flow
  2872. * control reliability.
  2873. */
  2874. if (tiosp->c_iflag & IXON) {
  2875. cor2 |= COR2_TXIBE;
  2876. cor3 |= COR3_SCD12;
  2877. if (tiosp->c_iflag & IXANY)
  2878. cor2 |= COR2_IXM;
  2879. }
  2880. if (tiosp->c_cflag & CRTSCTS) {
  2881. cor2 |= COR2_CTSAE;
  2882. mcor1 |= FIFO_RTSTHRESHOLD;
  2883. }
  2884. /*
  2885. * All cd1400 register values calculated so go through and set
  2886. * them all up.
  2887. */
  2888. #ifdef DEBUG
  2889. printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  2890. portp->portnr, portp->panelnr, portp->brdnr);
  2891. printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
  2892. cor1, cor2, cor3, cor4, cor5);
  2893. printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
  2894. mcor1, mcor2, rtpr, sreron, sreroff);
  2895. printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
  2896. printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  2897. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  2898. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  2899. #endif
  2900. spin_lock_irqsave(&brd_lock, flags);
  2901. BRDENABLE(portp->brdnr, portp->pagenr);
  2902. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
  2903. srer = stl_cd1400getreg(portp, SRER);
  2904. stl_cd1400setreg(portp, SRER, 0);
  2905. if (stl_cd1400updatereg(portp, COR1, cor1))
  2906. ccr = 1;
  2907. if (stl_cd1400updatereg(portp, COR2, cor2))
  2908. ccr = 1;
  2909. if (stl_cd1400updatereg(portp, COR3, cor3))
  2910. ccr = 1;
  2911. if (ccr) {
  2912. stl_cd1400ccrwait(portp);
  2913. stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
  2914. }
  2915. stl_cd1400setreg(portp, COR4, cor4);
  2916. stl_cd1400setreg(portp, COR5, cor5);
  2917. stl_cd1400setreg(portp, MCOR1, mcor1);
  2918. stl_cd1400setreg(portp, MCOR2, mcor2);
  2919. if (baudrate > 0) {
  2920. stl_cd1400setreg(portp, TCOR, clk);
  2921. stl_cd1400setreg(portp, TBPR, div);
  2922. stl_cd1400setreg(portp, RCOR, clk);
  2923. stl_cd1400setreg(portp, RBPR, div);
  2924. }
  2925. stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
  2926. stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
  2927. stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
  2928. stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
  2929. stl_cd1400setreg(portp, RTPR, rtpr);
  2930. mcor1 = stl_cd1400getreg(portp, MSVR1);
  2931. if (mcor1 & MSVR1_DCD)
  2932. portp->sigs |= TIOCM_CD;
  2933. else
  2934. portp->sigs &= ~TIOCM_CD;
  2935. stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
  2936. BRDDISABLE(portp->brdnr);
  2937. spin_unlock_irqrestore(&brd_lock, flags);
  2938. }
  2939. /*****************************************************************************/
  2940. /*
  2941. * Set the state of the DTR and RTS signals.
  2942. */
  2943. static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
  2944. {
  2945. unsigned char msvr1, msvr2;
  2946. unsigned long flags;
  2947. #ifdef DEBUG
  2948. printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
  2949. (int) portp, dtr, rts);
  2950. #endif
  2951. msvr1 = 0;
  2952. msvr2 = 0;
  2953. if (dtr > 0)
  2954. msvr1 = MSVR1_DTR;
  2955. if (rts > 0)
  2956. msvr2 = MSVR2_RTS;
  2957. spin_lock_irqsave(&brd_lock, flags);
  2958. BRDENABLE(portp->brdnr, portp->pagenr);
  2959. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2960. if (rts >= 0)
  2961. stl_cd1400setreg(portp, MSVR2, msvr2);
  2962. if (dtr >= 0)
  2963. stl_cd1400setreg(portp, MSVR1, msvr1);
  2964. BRDDISABLE(portp->brdnr);
  2965. spin_unlock_irqrestore(&brd_lock, flags);
  2966. }
  2967. /*****************************************************************************/
  2968. /*
  2969. * Return the state of the signals.
  2970. */
  2971. static int stl_cd1400getsignals(stlport_t *portp)
  2972. {
  2973. unsigned char msvr1, msvr2;
  2974. unsigned long flags;
  2975. int sigs;
  2976. #ifdef DEBUG
  2977. printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
  2978. #endif
  2979. spin_lock_irqsave(&brd_lock, flags);
  2980. BRDENABLE(portp->brdnr, portp->pagenr);
  2981. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2982. msvr1 = stl_cd1400getreg(portp, MSVR1);
  2983. msvr2 = stl_cd1400getreg(portp, MSVR2);
  2984. BRDDISABLE(portp->brdnr);
  2985. spin_unlock_irqrestore(&brd_lock, flags);
  2986. sigs = 0;
  2987. sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
  2988. sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
  2989. sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
  2990. sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
  2991. #if 0
  2992. sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
  2993. sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
  2994. #else
  2995. sigs |= TIOCM_DSR;
  2996. #endif
  2997. return sigs;
  2998. }
  2999. /*****************************************************************************/
  3000. /*
  3001. * Enable/Disable the Transmitter and/or Receiver.
  3002. */
  3003. static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
  3004. {
  3005. unsigned char ccr;
  3006. unsigned long flags;
  3007. #ifdef DEBUG
  3008. printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
  3009. (int) portp, rx, tx);
  3010. #endif
  3011. ccr = 0;
  3012. if (tx == 0)
  3013. ccr |= CCR_TXDISABLE;
  3014. else if (tx > 0)
  3015. ccr |= CCR_TXENABLE;
  3016. if (rx == 0)
  3017. ccr |= CCR_RXDISABLE;
  3018. else if (rx > 0)
  3019. ccr |= CCR_RXENABLE;
  3020. spin_lock_irqsave(&brd_lock, flags);
  3021. BRDENABLE(portp->brdnr, portp->pagenr);
  3022. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3023. stl_cd1400ccrwait(portp);
  3024. stl_cd1400setreg(portp, CCR, ccr);
  3025. stl_cd1400ccrwait(portp);
  3026. BRDDISABLE(portp->brdnr);
  3027. spin_unlock_irqrestore(&brd_lock, flags);
  3028. }
  3029. /*****************************************************************************/
  3030. /*
  3031. * Start/stop the Transmitter and/or Receiver.
  3032. */
  3033. static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
  3034. {
  3035. unsigned char sreron, sreroff;
  3036. unsigned long flags;
  3037. #ifdef DEBUG
  3038. printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
  3039. (int) portp, rx, tx);
  3040. #endif
  3041. sreron = 0;
  3042. sreroff = 0;
  3043. if (tx == 0)
  3044. sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
  3045. else if (tx == 1)
  3046. sreron |= SRER_TXDATA;
  3047. else if (tx >= 2)
  3048. sreron |= SRER_TXEMPTY;
  3049. if (rx == 0)
  3050. sreroff |= SRER_RXDATA;
  3051. else if (rx > 0)
  3052. sreron |= SRER_RXDATA;
  3053. spin_lock_irqsave(&brd_lock, flags);
  3054. BRDENABLE(portp->brdnr, portp->pagenr);
  3055. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3056. stl_cd1400setreg(portp, SRER,
  3057. ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
  3058. BRDDISABLE(portp->brdnr);
  3059. if (tx > 0)
  3060. set_bit(ASYI_TXBUSY, &portp->istate);
  3061. spin_unlock_irqrestore(&brd_lock, flags);
  3062. }
  3063. /*****************************************************************************/
  3064. /*
  3065. * Disable all interrupts from this port.
  3066. */
  3067. static void stl_cd1400disableintrs(stlport_t *portp)
  3068. {
  3069. unsigned long flags;
  3070. #ifdef DEBUG
  3071. printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
  3072. #endif
  3073. spin_lock_irqsave(&brd_lock, flags);
  3074. BRDENABLE(portp->brdnr, portp->pagenr);
  3075. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3076. stl_cd1400setreg(portp, SRER, 0);
  3077. BRDDISABLE(portp->brdnr);
  3078. spin_unlock_irqrestore(&brd_lock, flags);
  3079. }
  3080. /*****************************************************************************/
  3081. static void stl_cd1400sendbreak(stlport_t *portp, int len)
  3082. {
  3083. unsigned long flags;
  3084. #ifdef DEBUG
  3085. printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
  3086. #endif
  3087. spin_lock_irqsave(&brd_lock, flags);
  3088. BRDENABLE(portp->brdnr, portp->pagenr);
  3089. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3090. stl_cd1400setreg(portp, SRER,
  3091. ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
  3092. SRER_TXEMPTY));
  3093. BRDDISABLE(portp->brdnr);
  3094. portp->brklen = len;
  3095. if (len == 1)
  3096. portp->stats.txbreaks++;
  3097. spin_unlock_irqrestore(&brd_lock, flags);
  3098. }
  3099. /*****************************************************************************/
  3100. /*
  3101. * Take flow control actions...
  3102. */
  3103. static void stl_cd1400flowctrl(stlport_t *portp, int state)
  3104. {
  3105. struct tty_struct *tty;
  3106. unsigned long flags;
  3107. #ifdef DEBUG
  3108. printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
  3109. #endif
  3110. if (portp == (stlport_t *) NULL)
  3111. return;
  3112. tty = portp->tty;
  3113. if (tty == (struct tty_struct *) NULL)
  3114. return;
  3115. spin_lock_irqsave(&brd_lock, flags);
  3116. BRDENABLE(portp->brdnr, portp->pagenr);
  3117. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3118. if (state) {
  3119. if (tty->termios->c_iflag & IXOFF) {
  3120. stl_cd1400ccrwait(portp);
  3121. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  3122. portp->stats.rxxon++;
  3123. stl_cd1400ccrwait(portp);
  3124. }
  3125. /*
  3126. * Question: should we return RTS to what it was before? It may
  3127. * have been set by an ioctl... Suppose not, since if you have
  3128. * hardware flow control set then it is pretty silly to go and
  3129. * set the RTS line by hand.
  3130. */
  3131. if (tty->termios->c_cflag & CRTSCTS) {
  3132. stl_cd1400setreg(portp, MCOR1,
  3133. (stl_cd1400getreg(portp, MCOR1) |
  3134. FIFO_RTSTHRESHOLD));
  3135. stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
  3136. portp->stats.rxrtson++;
  3137. }
  3138. } else {
  3139. if (tty->termios->c_iflag & IXOFF) {
  3140. stl_cd1400ccrwait(portp);
  3141. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  3142. portp->stats.rxxoff++;
  3143. stl_cd1400ccrwait(portp);
  3144. }
  3145. if (tty->termios->c_cflag & CRTSCTS) {
  3146. stl_cd1400setreg(portp, MCOR1,
  3147. (stl_cd1400getreg(portp, MCOR1) & 0xf0));
  3148. stl_cd1400setreg(portp, MSVR2, 0);
  3149. portp->stats.rxrtsoff++;
  3150. }
  3151. }
  3152. BRDDISABLE(portp->brdnr);
  3153. spin_unlock_irqrestore(&brd_lock, flags);
  3154. }
  3155. /*****************************************************************************/
  3156. /*
  3157. * Send a flow control character...
  3158. */
  3159. static void stl_cd1400sendflow(stlport_t *portp, int state)
  3160. {
  3161. struct tty_struct *tty;
  3162. unsigned long flags;
  3163. #ifdef DEBUG
  3164. printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
  3165. #endif
  3166. if (portp == (stlport_t *) NULL)
  3167. return;
  3168. tty = portp->tty;
  3169. if (tty == (struct tty_struct *) NULL)
  3170. return;
  3171. spin_lock_irqsave(&brd_lock, flags);
  3172. BRDENABLE(portp->brdnr, portp->pagenr);
  3173. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3174. if (state) {
  3175. stl_cd1400ccrwait(portp);
  3176. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  3177. portp->stats.rxxon++;
  3178. stl_cd1400ccrwait(portp);
  3179. } else {
  3180. stl_cd1400ccrwait(portp);
  3181. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  3182. portp->stats.rxxoff++;
  3183. stl_cd1400ccrwait(portp);
  3184. }
  3185. BRDDISABLE(portp->brdnr);
  3186. spin_unlock_irqrestore(&brd_lock, flags);
  3187. }
  3188. /*****************************************************************************/
  3189. static void stl_cd1400flush(stlport_t *portp)
  3190. {
  3191. unsigned long flags;
  3192. #ifdef DEBUG
  3193. printk("stl_cd1400flush(portp=%x)\n", (int) portp);
  3194. #endif
  3195. if (portp == (stlport_t *) NULL)
  3196. return;
  3197. spin_lock_irqsave(&brd_lock, flags);
  3198. BRDENABLE(portp->brdnr, portp->pagenr);
  3199. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3200. stl_cd1400ccrwait(portp);
  3201. stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
  3202. stl_cd1400ccrwait(portp);
  3203. portp->tx.tail = portp->tx.head;
  3204. BRDDISABLE(portp->brdnr);
  3205. spin_unlock_irqrestore(&brd_lock, flags);
  3206. }
  3207. /*****************************************************************************/
  3208. /*
  3209. * Return the current state of data flow on this port. This is only
  3210. * really interresting when determining if data has fully completed
  3211. * transmission or not... This is easy for the cd1400, it accurately
  3212. * maintains the busy port flag.
  3213. */
  3214. static int stl_cd1400datastate(stlport_t *portp)
  3215. {
  3216. #ifdef DEBUG
  3217. printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
  3218. #endif
  3219. if (portp == (stlport_t *) NULL)
  3220. return 0;
  3221. return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
  3222. }
  3223. /*****************************************************************************/
  3224. /*
  3225. * Interrupt service routine for cd1400 EasyIO boards.
  3226. */
  3227. static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
  3228. {
  3229. unsigned char svrtype;
  3230. #ifdef DEBUG
  3231. printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
  3232. (int) panelp, iobase);
  3233. #endif
  3234. spin_lock(&brd_lock);
  3235. outb(SVRR, iobase);
  3236. svrtype = inb(iobase + EREG_DATA);
  3237. if (panelp->nrports > 4) {
  3238. outb((SVRR + 0x80), iobase);
  3239. svrtype |= inb(iobase + EREG_DATA);
  3240. }
  3241. if (svrtype & SVRR_RX)
  3242. stl_cd1400rxisr(panelp, iobase);
  3243. else if (svrtype & SVRR_TX)
  3244. stl_cd1400txisr(panelp, iobase);
  3245. else if (svrtype & SVRR_MDM)
  3246. stl_cd1400mdmisr(panelp, iobase);
  3247. spin_unlock(&brd_lock);
  3248. }
  3249. /*****************************************************************************/
  3250. /*
  3251. * Interrupt service routine for cd1400 panels.
  3252. */
  3253. static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
  3254. {
  3255. unsigned char svrtype;
  3256. #ifdef DEBUG
  3257. printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
  3258. iobase);
  3259. #endif
  3260. outb(SVRR, iobase);
  3261. svrtype = inb(iobase + EREG_DATA);
  3262. outb((SVRR + 0x80), iobase);
  3263. svrtype |= inb(iobase + EREG_DATA);
  3264. if (svrtype & SVRR_RX)
  3265. stl_cd1400rxisr(panelp, iobase);
  3266. else if (svrtype & SVRR_TX)
  3267. stl_cd1400txisr(panelp, iobase);
  3268. else if (svrtype & SVRR_MDM)
  3269. stl_cd1400mdmisr(panelp, iobase);
  3270. }
  3271. /*****************************************************************************/
  3272. /*
  3273. * Unfortunately we need to handle breaks in the TX data stream, since
  3274. * this is the only way to generate them on the cd1400.
  3275. */
  3276. static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
  3277. {
  3278. if (portp->brklen == 1) {
  3279. outb((COR2 + portp->uartaddr), ioaddr);
  3280. outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
  3281. (ioaddr + EREG_DATA));
  3282. outb((TDR + portp->uartaddr), ioaddr);
  3283. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3284. outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
  3285. outb((SRER + portp->uartaddr), ioaddr);
  3286. outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
  3287. (ioaddr + EREG_DATA));
  3288. return 1;
  3289. } else if (portp->brklen > 1) {
  3290. outb((TDR + portp->uartaddr), ioaddr);
  3291. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3292. outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
  3293. portp->brklen = -1;
  3294. return 1;
  3295. } else {
  3296. outb((COR2 + portp->uartaddr), ioaddr);
  3297. outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
  3298. (ioaddr + EREG_DATA));
  3299. portp->brklen = 0;
  3300. }
  3301. return 0;
  3302. }
  3303. /*****************************************************************************/
  3304. /*
  3305. * Transmit interrupt handler. This has gotta be fast! Handling TX
  3306. * chars is pretty simple, stuff as many as possible from the TX buffer
  3307. * into the cd1400 FIFO. Must also handle TX breaks here, since they
  3308. * are embedded as commands in the data stream. Oh no, had to use a goto!
  3309. * This could be optimized more, will do when I get time...
  3310. * In practice it is possible that interrupts are enabled but that the
  3311. * port has been hung up. Need to handle not having any TX buffer here,
  3312. * this is done by using the side effect that head and tail will also
  3313. * be NULL if the buffer has been freed.
  3314. */
  3315. static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
  3316. {
  3317. stlport_t *portp;
  3318. int len, stlen;
  3319. char *head, *tail;
  3320. unsigned char ioack, srer;
  3321. #ifdef DEBUG
  3322. printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
  3323. #endif
  3324. ioack = inb(ioaddr + EREG_TXACK);
  3325. if (((ioack & panelp->ackmask) != 0) ||
  3326. ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
  3327. printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
  3328. return;
  3329. }
  3330. portp = panelp->ports[(ioack >> 3)];
  3331. /*
  3332. * Unfortunately we need to handle breaks in the data stream, since
  3333. * this is the only way to generate them on the cd1400. Do it now if
  3334. * a break is to be sent.
  3335. */
  3336. if (portp->brklen != 0)
  3337. if (stl_cd1400breakisr(portp, ioaddr))
  3338. goto stl_txalldone;
  3339. head = portp->tx.head;
  3340. tail = portp->tx.tail;
  3341. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  3342. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  3343. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  3344. set_bit(ASYI_TXLOW, &portp->istate);
  3345. schedule_work(&portp->tqueue);
  3346. }
  3347. if (len == 0) {
  3348. outb((SRER + portp->uartaddr), ioaddr);
  3349. srer = inb(ioaddr + EREG_DATA);
  3350. if (srer & SRER_TXDATA) {
  3351. srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
  3352. } else {
  3353. srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
  3354. clear_bit(ASYI_TXBUSY, &portp->istate);
  3355. }
  3356. outb(srer, (ioaddr + EREG_DATA));
  3357. } else {
  3358. len = MIN(len, CD1400_TXFIFOSIZE);
  3359. portp->stats.txtotal += len;
  3360. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  3361. outb((TDR + portp->uartaddr), ioaddr);
  3362. outsb((ioaddr + EREG_DATA), tail, stlen);
  3363. len -= stlen;
  3364. tail += stlen;
  3365. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  3366. tail = portp->tx.buf;
  3367. if (len > 0) {
  3368. outsb((ioaddr + EREG_DATA), tail, len);
  3369. tail += len;
  3370. }
  3371. portp->tx.tail = tail;
  3372. }
  3373. stl_txalldone:
  3374. outb((EOSRR + portp->uartaddr), ioaddr);
  3375. outb(0, (ioaddr + EREG_DATA));
  3376. }
  3377. /*****************************************************************************/
  3378. /*
  3379. * Receive character interrupt handler. Determine if we have good chars
  3380. * or bad chars and then process appropriately. Good chars are easy
  3381. * just shove the lot into the RX buffer and set all status byte to 0.
  3382. * If a bad RX char then process as required. This routine needs to be
  3383. * fast! In practice it is possible that we get an interrupt on a port
  3384. * that is closed. This can happen on hangups - since they completely
  3385. * shutdown a port not in user context. Need to handle this case.
  3386. */
  3387. static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
  3388. {
  3389. stlport_t *portp;
  3390. struct tty_struct *tty;
  3391. unsigned int ioack, len, buflen;
  3392. unsigned char status;
  3393. char ch;
  3394. #ifdef DEBUG
  3395. printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
  3396. #endif
  3397. ioack = inb(ioaddr + EREG_RXACK);
  3398. if ((ioack & panelp->ackmask) != 0) {
  3399. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3400. return;
  3401. }
  3402. portp = panelp->ports[(ioack >> 3)];
  3403. tty = portp->tty;
  3404. if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
  3405. outb((RDCR + portp->uartaddr), ioaddr);
  3406. len = inb(ioaddr + EREG_DATA);
  3407. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  3408. len = MIN(len, sizeof(stl_unwanted));
  3409. outb((RDSR + portp->uartaddr), ioaddr);
  3410. insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
  3411. portp->stats.rxlost += len;
  3412. portp->stats.rxtotal += len;
  3413. } else {
  3414. len = MIN(len, buflen);
  3415. if (len > 0) {
  3416. unsigned char *ptr;
  3417. outb((RDSR + portp->uartaddr), ioaddr);
  3418. tty_prepare_flip_string(tty, &ptr, len);
  3419. insb((ioaddr + EREG_DATA), ptr, len);
  3420. tty_schedule_flip(tty);
  3421. portp->stats.rxtotal += len;
  3422. }
  3423. }
  3424. } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
  3425. outb((RDSR + portp->uartaddr), ioaddr);
  3426. status = inb(ioaddr + EREG_DATA);
  3427. ch = inb(ioaddr + EREG_DATA);
  3428. if (status & ST_PARITY)
  3429. portp->stats.rxparity++;
  3430. if (status & ST_FRAMING)
  3431. portp->stats.rxframing++;
  3432. if (status & ST_OVERRUN)
  3433. portp->stats.rxoverrun++;
  3434. if (status & ST_BREAK)
  3435. portp->stats.rxbreaks++;
  3436. if (status & ST_SCHARMASK) {
  3437. if ((status & ST_SCHARMASK) == ST_SCHAR1)
  3438. portp->stats.txxon++;
  3439. if ((status & ST_SCHARMASK) == ST_SCHAR2)
  3440. portp->stats.txxoff++;
  3441. goto stl_rxalldone;
  3442. }
  3443. if (tty != NULL && (portp->rxignoremsk & status) == 0) {
  3444. if (portp->rxmarkmsk & status) {
  3445. if (status & ST_BREAK) {
  3446. status = TTY_BREAK;
  3447. if (portp->flags & ASYNC_SAK) {
  3448. do_SAK(tty);
  3449. BRDENABLE(portp->brdnr, portp->pagenr);
  3450. }
  3451. } else if (status & ST_PARITY) {
  3452. status = TTY_PARITY;
  3453. } else if (status & ST_FRAMING) {
  3454. status = TTY_FRAME;
  3455. } else if(status & ST_OVERRUN) {
  3456. status = TTY_OVERRUN;
  3457. } else {
  3458. status = 0;
  3459. }
  3460. } else {
  3461. status = 0;
  3462. }
  3463. tty_insert_flip_char(tty, ch, status);
  3464. tty_schedule_flip(tty);
  3465. }
  3466. } else {
  3467. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3468. return;
  3469. }
  3470. stl_rxalldone:
  3471. outb((EOSRR + portp->uartaddr), ioaddr);
  3472. outb(0, (ioaddr + EREG_DATA));
  3473. }
  3474. /*****************************************************************************/
  3475. /*
  3476. * Modem interrupt handler. The is called when the modem signal line
  3477. * (DCD) has changed state. Leave most of the work to the off-level
  3478. * processing routine.
  3479. */
  3480. static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
  3481. {
  3482. stlport_t *portp;
  3483. unsigned int ioack;
  3484. unsigned char misr;
  3485. #ifdef DEBUG
  3486. printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
  3487. #endif
  3488. ioack = inb(ioaddr + EREG_MDACK);
  3489. if (((ioack & panelp->ackmask) != 0) ||
  3490. ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
  3491. printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
  3492. return;
  3493. }
  3494. portp = panelp->ports[(ioack >> 3)];
  3495. outb((MISR + portp->uartaddr), ioaddr);
  3496. misr = inb(ioaddr + EREG_DATA);
  3497. if (misr & MISR_DCD) {
  3498. set_bit(ASYI_DCDCHANGE, &portp->istate);
  3499. schedule_work(&portp->tqueue);
  3500. portp->stats.modem++;
  3501. }
  3502. outb((EOSRR + portp->uartaddr), ioaddr);
  3503. outb(0, (ioaddr + EREG_DATA));
  3504. }
  3505. /*****************************************************************************/
  3506. /* SC26198 HARDWARE FUNCTIONS */
  3507. /*****************************************************************************/
  3508. /*
  3509. * These functions get/set/update the registers of the sc26198 UARTs.
  3510. * Access to the sc26198 registers is via an address/data io port pair.
  3511. * (Maybe should make this inline...)
  3512. */
  3513. static int stl_sc26198getreg(stlport_t *portp, int regnr)
  3514. {
  3515. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3516. return inb(portp->ioaddr + XP_DATA);
  3517. }
  3518. static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
  3519. {
  3520. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3521. outb(value, (portp->ioaddr + XP_DATA));
  3522. }
  3523. static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
  3524. {
  3525. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3526. if (inb(portp->ioaddr + XP_DATA) != value) {
  3527. outb(value, (portp->ioaddr + XP_DATA));
  3528. return 1;
  3529. }
  3530. return 0;
  3531. }
  3532. /*****************************************************************************/
  3533. /*
  3534. * Functions to get and set the sc26198 global registers.
  3535. */
  3536. static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
  3537. {
  3538. outb(regnr, (portp->ioaddr + XP_ADDR));
  3539. return inb(portp->ioaddr + XP_DATA);
  3540. }
  3541. #if 0
  3542. static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
  3543. {
  3544. outb(regnr, (portp->ioaddr + XP_ADDR));
  3545. outb(value, (portp->ioaddr + XP_DATA));
  3546. }
  3547. #endif
  3548. /*****************************************************************************/
  3549. /*
  3550. * Inbitialize the UARTs in a panel. We don't care what sort of board
  3551. * these ports are on - since the port io registers are almost
  3552. * identical when dealing with ports.
  3553. */
  3554. static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
  3555. {
  3556. int chipmask, i;
  3557. int nrchips, ioaddr;
  3558. #ifdef DEBUG
  3559. printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
  3560. (int) brdp, (int) panelp);
  3561. #endif
  3562. BRDENABLE(panelp->brdnr, panelp->pagenr);
  3563. /*
  3564. * Check that each chip is present and started up OK.
  3565. */
  3566. chipmask = 0;
  3567. nrchips = (panelp->nrports + 4) / SC26198_PORTS;
  3568. if (brdp->brdtype == BRD_ECHPCI)
  3569. outb(panelp->pagenr, brdp->ioctrl);
  3570. for (i = 0; (i < nrchips); i++) {
  3571. ioaddr = panelp->iobase + (i * 4);
  3572. outb(SCCR, (ioaddr + XP_ADDR));
  3573. outb(CR_RESETALL, (ioaddr + XP_DATA));
  3574. outb(TSTR, (ioaddr + XP_ADDR));
  3575. if (inb(ioaddr + XP_DATA) != 0) {
  3576. printk("STALLION: sc26198 not responding, "
  3577. "brd=%d panel=%d chip=%d\n",
  3578. panelp->brdnr, panelp->panelnr, i);
  3579. continue;
  3580. }
  3581. chipmask |= (0x1 << i);
  3582. outb(GCCR, (ioaddr + XP_ADDR));
  3583. outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
  3584. outb(WDTRCR, (ioaddr + XP_ADDR));
  3585. outb(0xff, (ioaddr + XP_DATA));
  3586. }
  3587. BRDDISABLE(panelp->brdnr);
  3588. return chipmask;
  3589. }
  3590. /*****************************************************************************/
  3591. /*
  3592. * Initialize hardware specific port registers.
  3593. */
  3594. static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
  3595. {
  3596. #ifdef DEBUG
  3597. printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
  3598. (int) brdp, (int) panelp, (int) portp);
  3599. #endif
  3600. if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
  3601. (portp == (stlport_t *) NULL))
  3602. return;
  3603. portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
  3604. portp->uartaddr = (portp->portnr & 0x07) << 4;
  3605. portp->pagenr = panelp->pagenr;
  3606. portp->hwid = 0x1;
  3607. BRDENABLE(portp->brdnr, portp->pagenr);
  3608. stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
  3609. BRDDISABLE(portp->brdnr);
  3610. }
  3611. /*****************************************************************************/
  3612. /*
  3613. * Set up the sc26198 registers for a port based on the termios port
  3614. * settings.
  3615. */
  3616. static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
  3617. {
  3618. stlbrd_t *brdp;
  3619. unsigned long flags;
  3620. unsigned int baudrate;
  3621. unsigned char mr0, mr1, mr2, clk;
  3622. unsigned char imron, imroff, iopr, ipr;
  3623. mr0 = 0;
  3624. mr1 = 0;
  3625. mr2 = 0;
  3626. clk = 0;
  3627. iopr = 0;
  3628. imron = 0;
  3629. imroff = 0;
  3630. brdp = stl_brds[portp->brdnr];
  3631. if (brdp == (stlbrd_t *) NULL)
  3632. return;
  3633. /*
  3634. * Set up the RX char ignore mask with those RX error types we
  3635. * can ignore.
  3636. */
  3637. portp->rxignoremsk = 0;
  3638. if (tiosp->c_iflag & IGNPAR)
  3639. portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
  3640. SR_RXOVERRUN);
  3641. if (tiosp->c_iflag & IGNBRK)
  3642. portp->rxignoremsk |= SR_RXBREAK;
  3643. portp->rxmarkmsk = SR_RXOVERRUN;
  3644. if (tiosp->c_iflag & (INPCK | PARMRK))
  3645. portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
  3646. if (tiosp->c_iflag & BRKINT)
  3647. portp->rxmarkmsk |= SR_RXBREAK;
  3648. /*
  3649. * Go through the char size, parity and stop bits and set all the
  3650. * option register appropriately.
  3651. */
  3652. switch (tiosp->c_cflag & CSIZE) {
  3653. case CS5:
  3654. mr1 |= MR1_CS5;
  3655. break;
  3656. case CS6:
  3657. mr1 |= MR1_CS6;
  3658. break;
  3659. case CS7:
  3660. mr1 |= MR1_CS7;
  3661. break;
  3662. default:
  3663. mr1 |= MR1_CS8;
  3664. break;
  3665. }
  3666. if (tiosp->c_cflag & CSTOPB)
  3667. mr2 |= MR2_STOP2;
  3668. else
  3669. mr2 |= MR2_STOP1;
  3670. if (tiosp->c_cflag & PARENB) {
  3671. if (tiosp->c_cflag & PARODD)
  3672. mr1 |= (MR1_PARENB | MR1_PARODD);
  3673. else
  3674. mr1 |= (MR1_PARENB | MR1_PAREVEN);
  3675. } else {
  3676. mr1 |= MR1_PARNONE;
  3677. }
  3678. mr1 |= MR1_ERRBLOCK;
  3679. /*
  3680. * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
  3681. * space for hardware flow control and the like. This should be set to
  3682. * VMIN.
  3683. */
  3684. mr2 |= MR2_RXFIFOHALF;
  3685. /*
  3686. * Calculate the baud rate timers. For now we will just assume that
  3687. * the input and output baud are the same. The sc26198 has a fixed
  3688. * baud rate table, so only discrete baud rates possible.
  3689. */
  3690. baudrate = tiosp->c_cflag & CBAUD;
  3691. if (baudrate & CBAUDEX) {
  3692. baudrate &= ~CBAUDEX;
  3693. if ((baudrate < 1) || (baudrate > 4))
  3694. tiosp->c_cflag &= ~CBAUDEX;
  3695. else
  3696. baudrate += 15;
  3697. }
  3698. baudrate = stl_baudrates[baudrate];
  3699. if ((tiosp->c_cflag & CBAUD) == B38400) {
  3700. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  3701. baudrate = 57600;
  3702. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  3703. baudrate = 115200;
  3704. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  3705. baudrate = 230400;
  3706. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  3707. baudrate = 460800;
  3708. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  3709. baudrate = (portp->baud_base / portp->custom_divisor);
  3710. }
  3711. if (baudrate > STL_SC26198MAXBAUD)
  3712. baudrate = STL_SC26198MAXBAUD;
  3713. if (baudrate > 0) {
  3714. for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
  3715. if (baudrate <= sc26198_baudtable[clk])
  3716. break;
  3717. }
  3718. }
  3719. /*
  3720. * Check what form of modem signaling is required and set it up.
  3721. */
  3722. if (tiosp->c_cflag & CLOCAL) {
  3723. portp->flags &= ~ASYNC_CHECK_CD;
  3724. } else {
  3725. iopr |= IOPR_DCDCOS;
  3726. imron |= IR_IOPORT;
  3727. portp->flags |= ASYNC_CHECK_CD;
  3728. }
  3729. /*
  3730. * Setup sc26198 enhanced modes if we can. In particular we want to
  3731. * handle as much of the flow control as possible automatically. As
  3732. * well as saving a few CPU cycles it will also greatly improve flow
  3733. * control reliability.
  3734. */
  3735. if (tiosp->c_iflag & IXON) {
  3736. mr0 |= MR0_SWFTX | MR0_SWFT;
  3737. imron |= IR_XONXOFF;
  3738. } else {
  3739. imroff |= IR_XONXOFF;
  3740. }
  3741. if (tiosp->c_iflag & IXOFF)
  3742. mr0 |= MR0_SWFRX;
  3743. if (tiosp->c_cflag & CRTSCTS) {
  3744. mr2 |= MR2_AUTOCTS;
  3745. mr1 |= MR1_AUTORTS;
  3746. }
  3747. /*
  3748. * All sc26198 register values calculated so go through and set
  3749. * them all up.
  3750. */
  3751. #ifdef DEBUG
  3752. printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  3753. portp->portnr, portp->panelnr, portp->brdnr);
  3754. printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
  3755. printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
  3756. printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  3757. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  3758. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  3759. #endif
  3760. spin_lock_irqsave(&brd_lock, flags);
  3761. BRDENABLE(portp->brdnr, portp->pagenr);
  3762. stl_sc26198setreg(portp, IMR, 0);
  3763. stl_sc26198updatereg(portp, MR0, mr0);
  3764. stl_sc26198updatereg(portp, MR1, mr1);
  3765. stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
  3766. stl_sc26198updatereg(portp, MR2, mr2);
  3767. stl_sc26198updatereg(portp, IOPIOR,
  3768. ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
  3769. if (baudrate > 0) {
  3770. stl_sc26198setreg(portp, TXCSR, clk);
  3771. stl_sc26198setreg(portp, RXCSR, clk);
  3772. }
  3773. stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
  3774. stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
  3775. ipr = stl_sc26198getreg(portp, IPR);
  3776. if (ipr & IPR_DCD)
  3777. portp->sigs &= ~TIOCM_CD;
  3778. else
  3779. portp->sigs |= TIOCM_CD;
  3780. portp->imr = (portp->imr & ~imroff) | imron;
  3781. stl_sc26198setreg(portp, IMR, portp->imr);
  3782. BRDDISABLE(portp->brdnr);
  3783. spin_unlock_irqrestore(&brd_lock, flags);
  3784. }
  3785. /*****************************************************************************/
  3786. /*
  3787. * Set the state of the DTR and RTS signals.
  3788. */
  3789. static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
  3790. {
  3791. unsigned char iopioron, iopioroff;
  3792. unsigned long flags;
  3793. #ifdef DEBUG
  3794. printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
  3795. (int) portp, dtr, rts);
  3796. #endif
  3797. iopioron = 0;
  3798. iopioroff = 0;
  3799. if (dtr == 0)
  3800. iopioroff |= IPR_DTR;
  3801. else if (dtr > 0)
  3802. iopioron |= IPR_DTR;
  3803. if (rts == 0)
  3804. iopioroff |= IPR_RTS;
  3805. else if (rts > 0)
  3806. iopioron |= IPR_RTS;
  3807. spin_lock_irqsave(&brd_lock, flags);
  3808. BRDENABLE(portp->brdnr, portp->pagenr);
  3809. stl_sc26198setreg(portp, IOPIOR,
  3810. ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
  3811. BRDDISABLE(portp->brdnr);
  3812. spin_unlock_irqrestore(&brd_lock, flags);
  3813. }
  3814. /*****************************************************************************/
  3815. /*
  3816. * Return the state of the signals.
  3817. */
  3818. static int stl_sc26198getsignals(stlport_t *portp)
  3819. {
  3820. unsigned char ipr;
  3821. unsigned long flags;
  3822. int sigs;
  3823. #ifdef DEBUG
  3824. printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
  3825. #endif
  3826. spin_lock_irqsave(&brd_lock, flags);
  3827. BRDENABLE(portp->brdnr, portp->pagenr);
  3828. ipr = stl_sc26198getreg(portp, IPR);
  3829. BRDDISABLE(portp->brdnr);
  3830. spin_unlock_irqrestore(&brd_lock, flags);
  3831. sigs = 0;
  3832. sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
  3833. sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
  3834. sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
  3835. sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
  3836. sigs |= TIOCM_DSR;
  3837. return sigs;
  3838. }
  3839. /*****************************************************************************/
  3840. /*
  3841. * Enable/Disable the Transmitter and/or Receiver.
  3842. */
  3843. static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
  3844. {
  3845. unsigned char ccr;
  3846. unsigned long flags;
  3847. #ifdef DEBUG
  3848. printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
  3849. (int) portp, rx, tx);
  3850. #endif
  3851. ccr = portp->crenable;
  3852. if (tx == 0)
  3853. ccr &= ~CR_TXENABLE;
  3854. else if (tx > 0)
  3855. ccr |= CR_TXENABLE;
  3856. if (rx == 0)
  3857. ccr &= ~CR_RXENABLE;
  3858. else if (rx > 0)
  3859. ccr |= CR_RXENABLE;
  3860. spin_lock_irqsave(&brd_lock, flags);
  3861. BRDENABLE(portp->brdnr, portp->pagenr);
  3862. stl_sc26198setreg(portp, SCCR, ccr);
  3863. BRDDISABLE(portp->brdnr);
  3864. portp->crenable = ccr;
  3865. spin_unlock_irqrestore(&brd_lock, flags);
  3866. }
  3867. /*****************************************************************************/
  3868. /*
  3869. * Start/stop the Transmitter and/or Receiver.
  3870. */
  3871. static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
  3872. {
  3873. unsigned char imr;
  3874. unsigned long flags;
  3875. #ifdef DEBUG
  3876. printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
  3877. (int) portp, rx, tx);
  3878. #endif
  3879. imr = portp->imr;
  3880. if (tx == 0)
  3881. imr &= ~IR_TXRDY;
  3882. else if (tx == 1)
  3883. imr |= IR_TXRDY;
  3884. if (rx == 0)
  3885. imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
  3886. else if (rx > 0)
  3887. imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
  3888. spin_lock_irqsave(&brd_lock, flags);
  3889. BRDENABLE(portp->brdnr, portp->pagenr);
  3890. stl_sc26198setreg(portp, IMR, imr);
  3891. BRDDISABLE(portp->brdnr);
  3892. portp->imr = imr;
  3893. if (tx > 0)
  3894. set_bit(ASYI_TXBUSY, &portp->istate);
  3895. spin_unlock_irqrestore(&brd_lock, flags);
  3896. }
  3897. /*****************************************************************************/
  3898. /*
  3899. * Disable all interrupts from this port.
  3900. */
  3901. static void stl_sc26198disableintrs(stlport_t *portp)
  3902. {
  3903. unsigned long flags;
  3904. #ifdef DEBUG
  3905. printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
  3906. #endif
  3907. spin_lock_irqsave(&brd_lock, flags);
  3908. BRDENABLE(portp->brdnr, portp->pagenr);
  3909. portp->imr = 0;
  3910. stl_sc26198setreg(portp, IMR, 0);
  3911. BRDDISABLE(portp->brdnr);
  3912. spin_unlock_irqrestore(&brd_lock, flags);
  3913. }
  3914. /*****************************************************************************/
  3915. static void stl_sc26198sendbreak(stlport_t *portp, int len)
  3916. {
  3917. unsigned long flags;
  3918. #ifdef DEBUG
  3919. printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
  3920. #endif
  3921. spin_lock_irqsave(&brd_lock, flags);
  3922. BRDENABLE(portp->brdnr, portp->pagenr);
  3923. if (len == 1) {
  3924. stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
  3925. portp->stats.txbreaks++;
  3926. } else {
  3927. stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
  3928. }
  3929. BRDDISABLE(portp->brdnr);
  3930. spin_unlock_irqrestore(&brd_lock, flags);
  3931. }
  3932. /*****************************************************************************/
  3933. /*
  3934. * Take flow control actions...
  3935. */
  3936. static void stl_sc26198flowctrl(stlport_t *portp, int state)
  3937. {
  3938. struct tty_struct *tty;
  3939. unsigned long flags;
  3940. unsigned char mr0;
  3941. #ifdef DEBUG
  3942. printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
  3943. #endif
  3944. if (portp == (stlport_t *) NULL)
  3945. return;
  3946. tty = portp->tty;
  3947. if (tty == (struct tty_struct *) NULL)
  3948. return;
  3949. spin_lock_irqsave(&brd_lock, flags);
  3950. BRDENABLE(portp->brdnr, portp->pagenr);
  3951. if (state) {
  3952. if (tty->termios->c_iflag & IXOFF) {
  3953. mr0 = stl_sc26198getreg(portp, MR0);
  3954. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3955. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  3956. mr0 |= MR0_SWFRX;
  3957. portp->stats.rxxon++;
  3958. stl_sc26198wait(portp);
  3959. stl_sc26198setreg(portp, MR0, mr0);
  3960. }
  3961. /*
  3962. * Question: should we return RTS to what it was before? It may
  3963. * have been set by an ioctl... Suppose not, since if you have
  3964. * hardware flow control set then it is pretty silly to go and
  3965. * set the RTS line by hand.
  3966. */
  3967. if (tty->termios->c_cflag & CRTSCTS) {
  3968. stl_sc26198setreg(portp, MR1,
  3969. (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
  3970. stl_sc26198setreg(portp, IOPIOR,
  3971. (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
  3972. portp->stats.rxrtson++;
  3973. }
  3974. } else {
  3975. if (tty->termios->c_iflag & IXOFF) {
  3976. mr0 = stl_sc26198getreg(portp, MR0);
  3977. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3978. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  3979. mr0 &= ~MR0_SWFRX;
  3980. portp->stats.rxxoff++;
  3981. stl_sc26198wait(portp);
  3982. stl_sc26198setreg(portp, MR0, mr0);
  3983. }
  3984. if (tty->termios->c_cflag & CRTSCTS) {
  3985. stl_sc26198setreg(portp, MR1,
  3986. (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
  3987. stl_sc26198setreg(portp, IOPIOR,
  3988. (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
  3989. portp->stats.rxrtsoff++;
  3990. }
  3991. }
  3992. BRDDISABLE(portp->brdnr);
  3993. spin_unlock_irqrestore(&brd_lock, flags);
  3994. }
  3995. /*****************************************************************************/
  3996. /*
  3997. * Send a flow control character.
  3998. */
  3999. static void stl_sc26198sendflow(stlport_t *portp, int state)
  4000. {
  4001. struct tty_struct *tty;
  4002. unsigned long flags;
  4003. unsigned char mr0;
  4004. #ifdef DEBUG
  4005. printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
  4006. #endif
  4007. if (portp == (stlport_t *) NULL)
  4008. return;
  4009. tty = portp->tty;
  4010. if (tty == (struct tty_struct *) NULL)
  4011. return;
  4012. spin_lock_irqsave(&brd_lock, flags);
  4013. BRDENABLE(portp->brdnr, portp->pagenr);
  4014. if (state) {
  4015. mr0 = stl_sc26198getreg(portp, MR0);
  4016. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4017. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  4018. mr0 |= MR0_SWFRX;
  4019. portp->stats.rxxon++;
  4020. stl_sc26198wait(portp);
  4021. stl_sc26198setreg(portp, MR0, mr0);
  4022. } else {
  4023. mr0 = stl_sc26198getreg(portp, MR0);
  4024. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4025. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  4026. mr0 &= ~MR0_SWFRX;
  4027. portp->stats.rxxoff++;
  4028. stl_sc26198wait(portp);
  4029. stl_sc26198setreg(portp, MR0, mr0);
  4030. }
  4031. BRDDISABLE(portp->brdnr);
  4032. spin_unlock_irqrestore(&brd_lock, flags);
  4033. }
  4034. /*****************************************************************************/
  4035. static void stl_sc26198flush(stlport_t *portp)
  4036. {
  4037. unsigned long flags;
  4038. #ifdef DEBUG
  4039. printk("stl_sc26198flush(portp=%x)\n", (int) portp);
  4040. #endif
  4041. if (portp == (stlport_t *) NULL)
  4042. return;
  4043. spin_lock_irqsave(&brd_lock, flags);
  4044. BRDENABLE(portp->brdnr, portp->pagenr);
  4045. stl_sc26198setreg(portp, SCCR, CR_TXRESET);
  4046. stl_sc26198setreg(portp, SCCR, portp->crenable);
  4047. BRDDISABLE(portp->brdnr);
  4048. portp->tx.tail = portp->tx.head;
  4049. spin_unlock_irqrestore(&brd_lock, flags);
  4050. }
  4051. /*****************************************************************************/
  4052. /*
  4053. * Return the current state of data flow on this port. This is only
  4054. * really interresting when determining if data has fully completed
  4055. * transmission or not... The sc26198 interrupt scheme cannot
  4056. * determine when all data has actually drained, so we need to
  4057. * check the port statusy register to be sure.
  4058. */
  4059. static int stl_sc26198datastate(stlport_t *portp)
  4060. {
  4061. unsigned long flags;
  4062. unsigned char sr;
  4063. #ifdef DEBUG
  4064. printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
  4065. #endif
  4066. if (portp == (stlport_t *) NULL)
  4067. return 0;
  4068. if (test_bit(ASYI_TXBUSY, &portp->istate))
  4069. return 1;
  4070. spin_lock_irqsave(&brd_lock, flags);
  4071. BRDENABLE(portp->brdnr, portp->pagenr);
  4072. sr = stl_sc26198getreg(portp, SR);
  4073. BRDDISABLE(portp->brdnr);
  4074. spin_unlock_irqrestore(&brd_lock, flags);
  4075. return (sr & SR_TXEMPTY) ? 0 : 1;
  4076. }
  4077. /*****************************************************************************/
  4078. /*
  4079. * Delay for a small amount of time, to give the sc26198 a chance
  4080. * to process a command...
  4081. */
  4082. static void stl_sc26198wait(stlport_t *portp)
  4083. {
  4084. int i;
  4085. #ifdef DEBUG
  4086. printk("stl_sc26198wait(portp=%x)\n", (int) portp);
  4087. #endif
  4088. if (portp == (stlport_t *) NULL)
  4089. return;
  4090. for (i = 0; (i < 20); i++)
  4091. stl_sc26198getglobreg(portp, TSTR);
  4092. }
  4093. /*****************************************************************************/
  4094. /*
  4095. * If we are TX flow controlled and in IXANY mode then we may
  4096. * need to unflow control here. We gotta do this because of the
  4097. * automatic flow control modes of the sc26198.
  4098. */
  4099. static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
  4100. {
  4101. unsigned char mr0;
  4102. mr0 = stl_sc26198getreg(portp, MR0);
  4103. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4104. stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
  4105. stl_sc26198wait(portp);
  4106. stl_sc26198setreg(portp, MR0, mr0);
  4107. clear_bit(ASYI_TXFLOWED, &portp->istate);
  4108. }
  4109. /*****************************************************************************/
  4110. /*
  4111. * Interrupt service routine for sc26198 panels.
  4112. */
  4113. static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
  4114. {
  4115. stlport_t *portp;
  4116. unsigned int iack;
  4117. spin_lock(&brd_lock);
  4118. /*
  4119. * Work around bug in sc26198 chip... Cannot have A6 address
  4120. * line of UART high, else iack will be returned as 0.
  4121. */
  4122. outb(0, (iobase + 1));
  4123. iack = inb(iobase + XP_IACK);
  4124. portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
  4125. if (iack & IVR_RXDATA)
  4126. stl_sc26198rxisr(portp, iack);
  4127. else if (iack & IVR_TXDATA)
  4128. stl_sc26198txisr(portp);
  4129. else
  4130. stl_sc26198otherisr(portp, iack);
  4131. spin_unlock(&brd_lock);
  4132. }
  4133. /*****************************************************************************/
  4134. /*
  4135. * Transmit interrupt handler. This has gotta be fast! Handling TX
  4136. * chars is pretty simple, stuff as many as possible from the TX buffer
  4137. * into the sc26198 FIFO.
  4138. * In practice it is possible that interrupts are enabled but that the
  4139. * port has been hung up. Need to handle not having any TX buffer here,
  4140. * this is done by using the side effect that head and tail will also
  4141. * be NULL if the buffer has been freed.
  4142. */
  4143. static void stl_sc26198txisr(stlport_t *portp)
  4144. {
  4145. unsigned int ioaddr;
  4146. unsigned char mr0;
  4147. int len, stlen;
  4148. char *head, *tail;
  4149. #ifdef DEBUG
  4150. printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
  4151. #endif
  4152. ioaddr = portp->ioaddr;
  4153. head = portp->tx.head;
  4154. tail = portp->tx.tail;
  4155. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  4156. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  4157. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  4158. set_bit(ASYI_TXLOW, &portp->istate);
  4159. schedule_work(&portp->tqueue);
  4160. }
  4161. if (len == 0) {
  4162. outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
  4163. mr0 = inb(ioaddr + XP_DATA);
  4164. if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
  4165. portp->imr &= ~IR_TXRDY;
  4166. outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
  4167. outb(portp->imr, (ioaddr + XP_DATA));
  4168. clear_bit(ASYI_TXBUSY, &portp->istate);
  4169. } else {
  4170. mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
  4171. outb(mr0, (ioaddr + XP_DATA));
  4172. }
  4173. } else {
  4174. len = MIN(len, SC26198_TXFIFOSIZE);
  4175. portp->stats.txtotal += len;
  4176. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  4177. outb(GTXFIFO, (ioaddr + XP_ADDR));
  4178. outsb((ioaddr + XP_DATA), tail, stlen);
  4179. len -= stlen;
  4180. tail += stlen;
  4181. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  4182. tail = portp->tx.buf;
  4183. if (len > 0) {
  4184. outsb((ioaddr + XP_DATA), tail, len);
  4185. tail += len;
  4186. }
  4187. portp->tx.tail = tail;
  4188. }
  4189. }
  4190. /*****************************************************************************/
  4191. /*
  4192. * Receive character interrupt handler. Determine if we have good chars
  4193. * or bad chars and then process appropriately. Good chars are easy
  4194. * just shove the lot into the RX buffer and set all status byte to 0.
  4195. * If a bad RX char then process as required. This routine needs to be
  4196. * fast! In practice it is possible that we get an interrupt on a port
  4197. * that is closed. This can happen on hangups - since they completely
  4198. * shutdown a port not in user context. Need to handle this case.
  4199. */
  4200. static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
  4201. {
  4202. struct tty_struct *tty;
  4203. unsigned int len, buflen, ioaddr;
  4204. #ifdef DEBUG
  4205. printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
  4206. #endif
  4207. tty = portp->tty;
  4208. ioaddr = portp->ioaddr;
  4209. outb(GIBCR, (ioaddr + XP_ADDR));
  4210. len = inb(ioaddr + XP_DATA) + 1;
  4211. if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
  4212. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  4213. len = MIN(len, sizeof(stl_unwanted));
  4214. outb(GRXFIFO, (ioaddr + XP_ADDR));
  4215. insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
  4216. portp->stats.rxlost += len;
  4217. portp->stats.rxtotal += len;
  4218. } else {
  4219. len = MIN(len, buflen);
  4220. if (len > 0) {
  4221. unsigned char *ptr;
  4222. outb(GRXFIFO, (ioaddr + XP_ADDR));
  4223. tty_prepare_flip_string(tty, &ptr, len);
  4224. insb((ioaddr + XP_DATA), ptr, len);
  4225. tty_schedule_flip(tty);
  4226. portp->stats.rxtotal += len;
  4227. }
  4228. }
  4229. } else {
  4230. stl_sc26198rxbadchars(portp);
  4231. }
  4232. /*
  4233. * If we are TX flow controlled and in IXANY mode then we may need
  4234. * to unflow control here. We gotta do this because of the automatic
  4235. * flow control modes of the sc26198.
  4236. */
  4237. if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
  4238. if ((tty != (struct tty_struct *) NULL) &&
  4239. (tty->termios != (struct termios *) NULL) &&
  4240. (tty->termios->c_iflag & IXANY)) {
  4241. stl_sc26198txunflow(portp, tty);
  4242. }
  4243. }
  4244. }
  4245. /*****************************************************************************/
  4246. /*
  4247. * Process an RX bad character.
  4248. */
  4249. static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
  4250. {
  4251. struct tty_struct *tty;
  4252. unsigned int ioaddr;
  4253. tty = portp->tty;
  4254. ioaddr = portp->ioaddr;
  4255. if (status & SR_RXPARITY)
  4256. portp->stats.rxparity++;
  4257. if (status & SR_RXFRAMING)
  4258. portp->stats.rxframing++;
  4259. if (status & SR_RXOVERRUN)
  4260. portp->stats.rxoverrun++;
  4261. if (status & SR_RXBREAK)
  4262. portp->stats.rxbreaks++;
  4263. if ((tty != (struct tty_struct *) NULL) &&
  4264. ((portp->rxignoremsk & status) == 0)) {
  4265. if (portp->rxmarkmsk & status) {
  4266. if (status & SR_RXBREAK) {
  4267. status = TTY_BREAK;
  4268. if (portp->flags & ASYNC_SAK) {
  4269. do_SAK(tty);
  4270. BRDENABLE(portp->brdnr, portp->pagenr);
  4271. }
  4272. } else if (status & SR_RXPARITY) {
  4273. status = TTY_PARITY;
  4274. } else if (status & SR_RXFRAMING) {
  4275. status = TTY_FRAME;
  4276. } else if(status & SR_RXOVERRUN) {
  4277. status = TTY_OVERRUN;
  4278. } else {
  4279. status = 0;
  4280. }
  4281. } else {
  4282. status = 0;
  4283. }
  4284. tty_insert_flip_char(tty, ch, status);
  4285. tty_schedule_flip(tty);
  4286. if (status == 0)
  4287. portp->stats.rxtotal++;
  4288. }
  4289. }
  4290. /*****************************************************************************/
  4291. /*
  4292. * Process all characters in the RX FIFO of the UART. Check all char
  4293. * status bytes as well, and process as required. We need to check
  4294. * all bytes in the FIFO, in case some more enter the FIFO while we
  4295. * are here. To get the exact character error type we need to switch
  4296. * into CHAR error mode (that is why we need to make sure we empty
  4297. * the FIFO).
  4298. */
  4299. static void stl_sc26198rxbadchars(stlport_t *portp)
  4300. {
  4301. unsigned char status, mr1;
  4302. char ch;
  4303. /*
  4304. * To get the precise error type for each character we must switch
  4305. * back into CHAR error mode.
  4306. */
  4307. mr1 = stl_sc26198getreg(portp, MR1);
  4308. stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
  4309. while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
  4310. stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
  4311. ch = stl_sc26198getreg(portp, RXFIFO);
  4312. stl_sc26198rxbadch(portp, status, ch);
  4313. }
  4314. /*
  4315. * To get correct interrupt class we must switch back into BLOCK
  4316. * error mode.
  4317. */
  4318. stl_sc26198setreg(portp, MR1, mr1);
  4319. }
  4320. /*****************************************************************************/
  4321. /*
  4322. * Other interrupt handler. This includes modem signals, flow
  4323. * control actions, etc. Most stuff is left to off-level interrupt
  4324. * processing time.
  4325. */
  4326. static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
  4327. {
  4328. unsigned char cir, ipr, xisr;
  4329. #ifdef DEBUG
  4330. printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
  4331. #endif
  4332. cir = stl_sc26198getglobreg(portp, CIR);
  4333. switch (cir & CIR_SUBTYPEMASK) {
  4334. case CIR_SUBCOS:
  4335. ipr = stl_sc26198getreg(portp, IPR);
  4336. if (ipr & IPR_DCDCHANGE) {
  4337. set_bit(ASYI_DCDCHANGE, &portp->istate);
  4338. schedule_work(&portp->tqueue);
  4339. portp->stats.modem++;
  4340. }
  4341. break;
  4342. case CIR_SUBXONXOFF:
  4343. xisr = stl_sc26198getreg(portp, XISR);
  4344. if (xisr & XISR_RXXONGOT) {
  4345. set_bit(ASYI_TXFLOWED, &portp->istate);
  4346. portp->stats.txxoff++;
  4347. }
  4348. if (xisr & XISR_RXXOFFGOT) {
  4349. clear_bit(ASYI_TXFLOWED, &portp->istate);
  4350. portp->stats.txxon++;
  4351. }
  4352. break;
  4353. case CIR_SUBBREAK:
  4354. stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
  4355. stl_sc26198rxbadchars(portp);
  4356. break;
  4357. default:
  4358. break;
  4359. }
  4360. }
  4361. /*****************************************************************************/