stallion.c 131 KB

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