stallion.c 131 KB

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