dgap.c 160 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079
  1. /*
  2. * Copyright 2003 Digi International (www.digi.com)
  3. * Scott H Kilau <Scott_Kilau at digi dot com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2, or (at your option)
  8. * any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED; without even the
  12. * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. * PURPOSE. See the GNU General Public License for more details.
  14. *
  15. */
  16. /*
  17. * In the original out of kernel Digi dgap driver, firmware
  18. * loading was done via user land to driver handshaking.
  19. *
  20. * For cards that support a concentrator (port expander),
  21. * I believe the concentrator its self told the card which
  22. * concentrator is actually attached and then that info
  23. * was used to tell user land which concentrator firmware
  24. * image was to be downloaded. I think even the BIOS or
  25. * FEP images required could change with the connection
  26. * of a particular concentrator.
  27. *
  28. * Since I have no access to any of these cards or
  29. * concentrators, I cannot put the correct concentrator
  30. * firmware file names into the firmware_info structure
  31. * as is now done for the BIOS and FEP images.
  32. *
  33. * I think, but am not certain, that the cards supporting
  34. * concentrators will function without them. So support
  35. * of these cards has been left in this driver.
  36. *
  37. * In order to fully support those cards, they would
  38. * either have to be acquired for dissection or maybe
  39. * Digi International could provide some assistance.
  40. */
  41. #undef DIGI_CONCENTRATORS_SUPPORTED
  42. #define pr_fmt(fmt) "dgap: " fmt
  43. #include <linux/kernel.h>
  44. #include <linux/module.h>
  45. #include <linux/pci.h>
  46. #include <linux/delay.h> /* For udelay */
  47. #include <linux/slab.h>
  48. #include <linux/uaccess.h>
  49. #include <linux/sched.h>
  50. #include <linux/interrupt.h> /* For tasklet and interrupt structs/defines */
  51. #include <linux/ctype.h>
  52. #include <linux/tty.h>
  53. #include <linux/tty_flip.h>
  54. #include <linux/serial_reg.h>
  55. #include <linux/io.h> /* For read[bwl]/write[bwl] */
  56. #include <linux/string.h>
  57. #include <linux/device.h>
  58. #include <linux/kdev_t.h>
  59. #include <linux/firmware.h>
  60. #include "dgap.h"
  61. /*
  62. * File operations permitted on Control/Management major.
  63. */
  64. static const struct file_operations dgap_board_fops = {
  65. .owner = THIS_MODULE,
  66. };
  67. static uint dgap_numboards;
  68. static struct board_t *dgap_board[MAXBOARDS];
  69. static ulong dgap_poll_counter;
  70. static int dgap_driver_state = DRIVER_INITIALIZED;
  71. static int dgap_poll_tick = 20; /* Poll interval - 20 ms */
  72. static struct class *dgap_class;
  73. static uint dgap_count = 500;
  74. /*
  75. * Poller stuff
  76. */
  77. static DEFINE_SPINLOCK(dgap_poll_lock); /* Poll scheduling lock */
  78. static ulong dgap_poll_time; /* Time of next poll */
  79. static uint dgap_poll_stop; /* Used to tell poller to stop */
  80. static struct timer_list dgap_poll_timer;
  81. /*
  82. SUPPORTED PRODUCTS
  83. Card Model Number of Ports Interface
  84. ----------------------------------------------------------------
  85. Acceleport Xem 4 - 64 (EIA232 & EIA422)
  86. Acceleport Xr 4 & 8 (EIA232)
  87. Acceleport Xr 920 4 & 8 (EIA232)
  88. Acceleport C/X 8 - 128 (EIA232)
  89. Acceleport EPC/X 8 - 224 (EIA232)
  90. Acceleport Xr/422 4 & 8 (EIA422)
  91. Acceleport 2r/920 2 (EIA232)
  92. Acceleport 4r/920 4 (EIA232)
  93. Acceleport 8r/920 8 (EIA232)
  94. IBM 8-Port Asynchronous PCI Adapter (EIA232)
  95. IBM 128-Port Asynchronous PCI Adapter (EIA232 & EIA422)
  96. */
  97. static struct pci_device_id dgap_pci_tbl[] = {
  98. { DIGI_VID, PCI_DEV_XEM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  99. { DIGI_VID, PCI_DEV_CX_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },
  100. { DIGI_VID, PCI_DEV_CX_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2 },
  101. { DIGI_VID, PCI_DEV_EPCJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3 },
  102. { DIGI_VID, PCI_DEV_920_2_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
  103. { DIGI_VID, PCI_DEV_920_4_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
  104. { DIGI_VID, PCI_DEV_920_8_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 6 },
  105. { DIGI_VID, PCI_DEV_XR_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 7 },
  106. { DIGI_VID, PCI_DEV_XRJ_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 },
  107. { DIGI_VID, PCI_DEV_XR_422_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 9 },
  108. { DIGI_VID, PCI_DEV_XR_IBM_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 10 },
  109. { DIGI_VID, PCI_DEV_XR_SAIP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 11 },
  110. { DIGI_VID, PCI_DEV_XR_BULL_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 12 },
  111. { DIGI_VID, PCI_DEV_920_8_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 13 },
  112. { DIGI_VID, PCI_DEV_XEM_HP_DID, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 14 },
  113. {0,} /* 0 terminated list. */
  114. };
  115. MODULE_DEVICE_TABLE(pci, dgap_pci_tbl);
  116. /*
  117. * A generic list of Product names, PCI Vendor ID, and PCI Device ID.
  118. */
  119. struct board_id {
  120. uint config_type;
  121. u8 *name;
  122. uint maxports;
  123. uint dpatype;
  124. };
  125. static struct board_id dgap_ids[] = {
  126. {PPCM, PCI_DEV_XEM_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS)},
  127. {PCX, PCI_DEV_CX_NAME, 128, (T_CX | T_PCIBUS) },
  128. {PCX, PCI_DEV_CX_IBM_NAME, 128, (T_CX | T_PCIBUS) },
  129. {PEPC, PCI_DEV_EPCJ_NAME, 224, (T_EPC | T_PCIBUS) },
  130. {APORT2_920P, PCI_DEV_920_2_NAME, 2, (T_PCXR | T_PCLITE | T_PCIBUS)},
  131. {APORT4_920P, PCI_DEV_920_4_NAME, 4, (T_PCXR | T_PCLITE | T_PCIBUS)},
  132. {APORT8_920P, PCI_DEV_920_8_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
  133. {PAPORT8, PCI_DEV_XR_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
  134. {PAPORT8, PCI_DEV_XRJ_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
  135. {PAPORT8, PCI_DEV_XR_422_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
  136. {PAPORT8, PCI_DEV_XR_IBM_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
  137. {PAPORT8, PCI_DEV_XR_SAIP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
  138. {PAPORT8, PCI_DEV_XR_BULL_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
  139. {APORT8_920P, PCI_DEV_920_8_HP_NAME, 8, (T_PCXR | T_PCLITE | T_PCIBUS)},
  140. {PPCM, PCI_DEV_XEM_HP_NAME, 64, (T_PCXM | T_PCLITE | T_PCIBUS)},
  141. {0,} /* 0 terminated list. */
  142. };
  143. struct firmware_info {
  144. u8 *conf_name; /* dgap.conf */
  145. u8 *bios_name; /* BIOS filename */
  146. u8 *fep_name; /* FEP filename */
  147. u8 *con_name; /* Concentrator filename FIXME*/
  148. int num; /* sequence number */
  149. };
  150. /*
  151. * Firmware - BIOS, FEP, and CONC filenames
  152. */
  153. static struct firmware_info fw_info[] = {
  154. { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 0 },
  155. { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 1 },
  156. { "dgap/dgap.conf", "dgap/cxpbios.bin", "dgap/cxpfep.bin", NULL, 2 },
  157. { "dgap/dgap.conf", "dgap/pcibios.bin", "dgap/pcifep.bin", NULL, 3 },
  158. { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 4 },
  159. { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 5 },
  160. { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 6 },
  161. { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 7 },
  162. { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 8 },
  163. { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 9 },
  164. { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 10 },
  165. { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 11 },
  166. { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 12 },
  167. { "dgap/dgap.conf", "dgap/xrbios.bin", "dgap/xrfep.bin", NULL, 13 },
  168. { "dgap/dgap.conf", "dgap/sxbios.bin", "dgap/sxfep.bin", NULL, 14 },
  169. {NULL,}
  170. };
  171. /*
  172. * Default transparent print information.
  173. */
  174. static struct digi_t dgap_digi_init = {
  175. .digi_flags = DIGI_COOK, /* Flags */
  176. .digi_maxcps = 100, /* Max CPS */
  177. .digi_maxchar = 50, /* Max chars in print queue */
  178. .digi_bufsize = 100, /* Printer buffer size */
  179. .digi_onlen = 4, /* size of printer on string */
  180. .digi_offlen = 4, /* size of printer off string */
  181. .digi_onstr = "\033[5i", /* ANSI printer on string ] */
  182. .digi_offstr = "\033[4i", /* ANSI printer off string ] */
  183. .digi_term = "ansi" /* default terminal type */
  184. };
  185. /*
  186. * Define a local default termios struct. All ports will be created
  187. * with this termios initially.
  188. *
  189. * This defines a raw port at 9600 baud, 8 data bits, no parity,
  190. * 1 stop bit.
  191. */
  192. static struct ktermios dgap_default_termios = {
  193. .c_iflag = (DEFAULT_IFLAGS), /* iflags */
  194. .c_oflag = (DEFAULT_OFLAGS), /* oflags */
  195. .c_cflag = (DEFAULT_CFLAGS), /* cflags */
  196. .c_lflag = (DEFAULT_LFLAGS), /* lflags */
  197. .c_cc = INIT_C_CC,
  198. .c_line = 0,
  199. };
  200. /*
  201. * Our needed internal static variables from dgap_parse.c
  202. */
  203. static struct cnode dgap_head;
  204. #define MAXCWORD 200
  205. static char dgap_cword[MAXCWORD];
  206. struct toklist {
  207. int token;
  208. char *string;
  209. };
  210. static struct toklist dgap_brdtype[] = {
  211. { PCX, "Digi_AccelePort_C/X_PCI" },
  212. { PEPC, "Digi_AccelePort_EPC/X_PCI" },
  213. { PPCM, "Digi_AccelePort_Xem_PCI" },
  214. { APORT2_920P, "Digi_AccelePort_2r_920_PCI" },
  215. { APORT4_920P, "Digi_AccelePort_4r_920_PCI" },
  216. { APORT8_920P, "Digi_AccelePort_8r_920_PCI" },
  217. { PAPORT4, "Digi_AccelePort_4r_PCI(EIA-232/RS-422)" },
  218. { PAPORT8, "Digi_AccelePort_8r_PCI(EIA-232/RS-422)" },
  219. { 0, NULL }
  220. };
  221. static struct toklist dgap_tlist[] = {
  222. { BEGIN, "config_begin" },
  223. { END, "config_end" },
  224. { BOARD, "board" },
  225. { PCIINFO, "pciinfo" },
  226. { LINE, "line" },
  227. { CONC, "conc" },
  228. { CONC, "concentrator" },
  229. { CX, "cx" },
  230. { CX, "ccon" },
  231. { EPC, "epccon" },
  232. { EPC, "epc" },
  233. { MOD, "module" },
  234. { ID, "id" },
  235. { STARTO, "start" },
  236. { SPEED, "speed" },
  237. { CABLE, "cable" },
  238. { CONNECT, "connect" },
  239. { METHOD, "method" },
  240. { STATUS, "status" },
  241. { CUSTOM, "Custom" },
  242. { BASIC, "Basic" },
  243. { MEM, "mem" },
  244. { MEM, "memory" },
  245. { PORTS, "ports" },
  246. { MODEM, "modem" },
  247. { NPORTS, "nports" },
  248. { TTYN, "ttyname" },
  249. { CU, "cuname" },
  250. { PRINT, "prname" },
  251. { CMAJOR, "major" },
  252. { ALTPIN, "altpin" },
  253. { USEINTR, "useintr" },
  254. { TTSIZ, "ttysize" },
  255. { CHSIZ, "chsize" },
  256. { BSSIZ, "boardsize" },
  257. { UNTSIZ, "schedsize" },
  258. { F2SIZ, "f2200size" },
  259. { VPSIZ, "vpixsize" },
  260. { 0, NULL }
  261. };
  262. /*
  263. * get a word from the input stream, also keep track of current line number.
  264. * words are separated by whitespace.
  265. */
  266. static char *dgap_getword(char **in)
  267. {
  268. char *ret_ptr = *in;
  269. char *ptr = strpbrk(*in, " \t\n");
  270. /* If no word found, return null */
  271. if (!ptr)
  272. return NULL;
  273. /* Mark new location for our buffer */
  274. *ptr = '\0';
  275. *in = ptr + 1;
  276. /* Eat any extra spaces/tabs/newlines that might be present */
  277. while (*in && **in && ((**in == ' ') ||
  278. (**in == '\t') ||
  279. (**in == '\n'))) {
  280. **in = '\0';
  281. *in = *in + 1;
  282. }
  283. return ret_ptr;
  284. }
  285. /*
  286. * Get a token from the input file; return 0 if end of file is reached
  287. */
  288. static int dgap_gettok(char **in)
  289. {
  290. char *w;
  291. struct toklist *t;
  292. if (strstr(dgap_cword, "board")) {
  293. w = dgap_getword(in);
  294. if (!w)
  295. return 0;
  296. snprintf(dgap_cword, MAXCWORD, "%s", w);
  297. for (t = dgap_brdtype; t->token != 0; t++) {
  298. if (!strcmp(w, t->string))
  299. return t->token;
  300. }
  301. } else {
  302. while ((w = dgap_getword(in))) {
  303. snprintf(dgap_cword, MAXCWORD, "%s", w);
  304. for (t = dgap_tlist; t->token != 0; t++) {
  305. if (!strcmp(w, t->string))
  306. return t->token;
  307. }
  308. }
  309. }
  310. return 0;
  311. }
  312. /*
  313. * dgap_checknode: see if all the necessary info has been supplied for a node
  314. * before creating the next node.
  315. */
  316. static int dgap_checknode(struct cnode *p)
  317. {
  318. switch (p->type) {
  319. case LNODE:
  320. if (p->u.line.v_speed == 0) {
  321. pr_err("line speed not specified");
  322. return 1;
  323. }
  324. return 0;
  325. case CNODE:
  326. if (p->u.conc.v_speed == 0) {
  327. pr_err("concentrator line speed not specified");
  328. return 1;
  329. }
  330. if (p->u.conc.v_nport == 0) {
  331. pr_err("number of ports on concentrator not specified");
  332. return 1;
  333. }
  334. if (p->u.conc.v_id == 0) {
  335. pr_err("concentrator id letter not specified");
  336. return 1;
  337. }
  338. return 0;
  339. case MNODE:
  340. if (p->u.module.v_nport == 0) {
  341. pr_err("number of ports on EBI module not specified");
  342. return 1;
  343. }
  344. if (p->u.module.v_id == 0) {
  345. pr_err("EBI module id letter not specified");
  346. return 1;
  347. }
  348. return 0;
  349. }
  350. return 0;
  351. }
  352. /*
  353. * Given a board pointer, returns whether we should use interrupts or not.
  354. */
  355. static uint dgap_config_get_useintr(struct board_t *bd)
  356. {
  357. struct cnode *p;
  358. if (!bd)
  359. return 0;
  360. for (p = bd->bd_config; p; p = p->next) {
  361. if (p->type == INTRNODE) {
  362. /*
  363. * check for pcxr types.
  364. */
  365. return p->u.useintr;
  366. }
  367. }
  368. /* If not found, then don't turn on interrupts. */
  369. return 0;
  370. }
  371. /*
  372. * Given a board pointer, returns whether we turn on altpin or not.
  373. */
  374. static uint dgap_config_get_altpin(struct board_t *bd)
  375. {
  376. struct cnode *p;
  377. if (!bd)
  378. return 0;
  379. for (p = bd->bd_config; p; p = p->next) {
  380. if (p->type == ANODE) {
  381. /*
  382. * check for pcxr types.
  383. */
  384. return p->u.altpin;
  385. }
  386. }
  387. /* If not found, then don't turn on interrupts. */
  388. return 0;
  389. }
  390. /*
  391. * Given a specific type of board, if found, detached link and
  392. * returns the first occurrence in the list.
  393. */
  394. static struct cnode *dgap_find_config(int type, int bus, int slot)
  395. {
  396. struct cnode *p, *prev, *prev2, *found;
  397. p = &dgap_head;
  398. while (p->next) {
  399. prev = p;
  400. p = p->next;
  401. if (p->type != BNODE)
  402. continue;
  403. if (p->u.board.type != type)
  404. continue;
  405. if (p->u.board.v_pcibus &&
  406. p->u.board.pcibus != bus)
  407. continue;
  408. if (p->u.board.v_pcislot &&
  409. p->u.board.pcislot != slot)
  410. continue;
  411. found = p;
  412. /*
  413. * Keep walking thru the list till we
  414. * find the next board.
  415. */
  416. while (p->next) {
  417. prev2 = p;
  418. p = p->next;
  419. if (p->type != BNODE)
  420. continue;
  421. /*
  422. * Mark the end of our 1 board
  423. * chain of configs.
  424. */
  425. prev2->next = NULL;
  426. /*
  427. * Link the "next" board to the
  428. * previous board, effectively
  429. * "unlinking" our board from
  430. * the main config.
  431. */
  432. prev->next = p;
  433. return found;
  434. }
  435. /*
  436. * It must be the last board in the list.
  437. */
  438. prev->next = NULL;
  439. return found;
  440. }
  441. return NULL;
  442. }
  443. /*
  444. * Given a board pointer, walks the config link, counting up
  445. * all ports user specified should be on the board.
  446. * (This does NOT mean they are all actually present right now tho)
  447. */
  448. static uint dgap_config_get_num_prts(struct board_t *bd)
  449. {
  450. int count = 0;
  451. struct cnode *p;
  452. if (!bd)
  453. return 0;
  454. for (p = bd->bd_config; p; p = p->next) {
  455. switch (p->type) {
  456. case BNODE:
  457. /*
  458. * check for pcxr types.
  459. */
  460. if (p->u.board.type > EPCFE)
  461. count += p->u.board.nport;
  462. break;
  463. case CNODE:
  464. count += p->u.conc.nport;
  465. break;
  466. case MNODE:
  467. count += p->u.module.nport;
  468. break;
  469. }
  470. }
  471. return count;
  472. }
  473. static char *dgap_create_config_string(struct board_t *bd, char *string)
  474. {
  475. char *ptr = string;
  476. struct cnode *p;
  477. struct cnode *q;
  478. int speed;
  479. if (!bd) {
  480. *ptr = 0xff;
  481. return string;
  482. }
  483. for (p = bd->bd_config; p; p = p->next) {
  484. switch (p->type) {
  485. case LNODE:
  486. *ptr = '\0';
  487. ptr++;
  488. *ptr = p->u.line.speed;
  489. ptr++;
  490. break;
  491. case CNODE:
  492. /*
  493. * Because the EPC/con concentrators can have EM modules
  494. * hanging off of them, we have to walk ahead in the
  495. * list and keep adding the number of ports on each EM
  496. * to the config. UGH!
  497. */
  498. speed = p->u.conc.speed;
  499. q = p->next;
  500. if (q && (q->type == MNODE)) {
  501. *ptr = (p->u.conc.nport + 0x80);
  502. ptr++;
  503. p = q;
  504. while (q->next && (q->next->type) == MNODE) {
  505. *ptr = (q->u.module.nport + 0x80);
  506. ptr++;
  507. p = q;
  508. q = q->next;
  509. }
  510. *ptr = q->u.module.nport;
  511. ptr++;
  512. } else {
  513. *ptr = p->u.conc.nport;
  514. ptr++;
  515. }
  516. *ptr = speed;
  517. ptr++;
  518. break;
  519. }
  520. }
  521. *ptr = 0xff;
  522. return string;
  523. }
  524. /*
  525. * Parse a configuration file read into memory as a string.
  526. */
  527. static int dgap_parsefile(char **in)
  528. {
  529. struct cnode *p, *brd, *line, *conc;
  530. int rc;
  531. char *s;
  532. int linecnt = 0;
  533. p = &dgap_head;
  534. brd = line = conc = NULL;
  535. /* perhaps we are adding to an existing list? */
  536. while (p->next)
  537. p = p->next;
  538. /* file must start with a BEGIN */
  539. while ((rc = dgap_gettok(in)) != BEGIN) {
  540. if (rc == 0) {
  541. pr_err("unexpected EOF");
  542. return -1;
  543. }
  544. }
  545. for (; ;) {
  546. int board_type = 0;
  547. int conc_type = 0;
  548. int module_type = 0;
  549. rc = dgap_gettok(in);
  550. if (rc == 0) {
  551. pr_err("unexpected EOF");
  552. return -1;
  553. }
  554. switch (rc) {
  555. case BEGIN: /* should only be 1 begin */
  556. pr_err("unexpected config_begin\n");
  557. return -1;
  558. case END:
  559. return 0;
  560. case BOARD: /* board info */
  561. if (dgap_checknode(p))
  562. return -1;
  563. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  564. if (!p->next)
  565. return -ENOMEM;
  566. p = p->next;
  567. p->type = BNODE;
  568. p->u.board.status = kstrdup("No", GFP_KERNEL);
  569. line = conc = NULL;
  570. brd = p;
  571. linecnt = -1;
  572. board_type = dgap_gettok(in);
  573. if (board_type == 0) {
  574. pr_err("board !!type not specified");
  575. return -1;
  576. }
  577. p->u.board.type = board_type;
  578. break;
  579. case MEM: /* memory address */
  580. if (p->type != BNODE) {
  581. pr_err("memory address only valid for boards");
  582. return -1;
  583. }
  584. s = dgap_getword(in);
  585. if (!s) {
  586. pr_err("unexpected end of file");
  587. return -1;
  588. }
  589. kfree(p->u.board.addrstr);
  590. p->u.board.addrstr = kstrdup(s, GFP_KERNEL);
  591. if (kstrtoul(s, 0, &p->u.board.addr)) {
  592. pr_err("bad number for memory address");
  593. return -1;
  594. }
  595. p->u.board.v_addr = 1;
  596. break;
  597. case PCIINFO: /* pci information */
  598. if (p->type != BNODE) {
  599. pr_err("memory address only valid for boards");
  600. return -1;
  601. }
  602. s = dgap_getword(in);
  603. if (!s) {
  604. pr_err("unexpected end of file");
  605. return -1;
  606. }
  607. kfree(p->u.board.pcibusstr);
  608. p->u.board.pcibusstr = kstrdup(s, GFP_KERNEL);
  609. if (kstrtoul(s, 0, &p->u.board.pcibus)) {
  610. pr_err("bad number for pci bus");
  611. return -1;
  612. }
  613. p->u.board.v_pcibus = 1;
  614. s = dgap_getword(in);
  615. if (!s) {
  616. pr_err("unexpected end of file");
  617. return -1;
  618. }
  619. kfree(p->u.board.pcislotstr);
  620. p->u.board.pcislotstr = kstrdup(s, GFP_KERNEL);
  621. if (kstrtoul(s, 0, &p->u.board.pcislot)) {
  622. pr_err("bad number for pci slot");
  623. return -1;
  624. }
  625. p->u.board.v_pcislot = 1;
  626. break;
  627. case METHOD:
  628. if (p->type != BNODE) {
  629. pr_err("install method only valid for boards");
  630. return -1;
  631. }
  632. s = dgap_getword(in);
  633. if (!s) {
  634. pr_err("unexpected end of file");
  635. return -1;
  636. }
  637. kfree(p->u.board.method);
  638. p->u.board.method = kstrdup(s, GFP_KERNEL);
  639. p->u.board.v_method = 1;
  640. break;
  641. case STATUS:
  642. if (p->type != BNODE) {
  643. pr_err("config status only valid for boards");
  644. return -1;
  645. }
  646. s = dgap_getword(in);
  647. if (!s) {
  648. pr_err("unexpected end of file");
  649. return -1;
  650. }
  651. kfree(p->u.board.status);
  652. p->u.board.status = kstrdup(s, GFP_KERNEL);
  653. break;
  654. case NPORTS: /* number of ports */
  655. if (p->type == BNODE) {
  656. s = dgap_getword(in);
  657. if (!s) {
  658. pr_err("unexpected end of file");
  659. return -1;
  660. }
  661. if (kstrtol(s, 0, &p->u.board.nport)) {
  662. pr_err("bad number for number of ports");
  663. return -1;
  664. }
  665. p->u.board.v_nport = 1;
  666. } else if (p->type == CNODE) {
  667. s = dgap_getword(in);
  668. if (!s) {
  669. pr_err("unexpected end of file");
  670. return -1;
  671. }
  672. if (kstrtol(s, 0, &p->u.conc.nport)) {
  673. pr_err("bad number for number of ports");
  674. return -1;
  675. }
  676. p->u.conc.v_nport = 1;
  677. } else if (p->type == MNODE) {
  678. s = dgap_getword(in);
  679. if (!s) {
  680. pr_err("unexpected end of file");
  681. return -1;
  682. }
  683. if (kstrtol(s, 0, &p->u.module.nport)) {
  684. pr_err("bad number for number of ports");
  685. return -1;
  686. }
  687. p->u.module.v_nport = 1;
  688. } else {
  689. pr_err("nports only valid for concentrators or modules");
  690. return -1;
  691. }
  692. break;
  693. case ID: /* letter ID used in tty name */
  694. s = dgap_getword(in);
  695. if (!s) {
  696. pr_err("unexpected end of file");
  697. return -1;
  698. }
  699. kfree(p->u.board.status);
  700. p->u.board.status = kstrdup(s, GFP_KERNEL);
  701. if (p->type == CNODE) {
  702. kfree(p->u.conc.id);
  703. p->u.conc.id = kstrdup(s, GFP_KERNEL);
  704. p->u.conc.v_id = 1;
  705. } else if (p->type == MNODE) {
  706. kfree(p->u.module.id);
  707. p->u.module.id = kstrdup(s, GFP_KERNEL);
  708. p->u.module.v_id = 1;
  709. } else {
  710. pr_err("id only valid for concentrators or modules");
  711. return -1;
  712. }
  713. break;
  714. case STARTO: /* start offset of ID */
  715. if (p->type == BNODE) {
  716. s = dgap_getword(in);
  717. if (!s) {
  718. pr_err("unexpected end of file");
  719. return -1;
  720. }
  721. if (kstrtol(s, 0, &p->u.board.start)) {
  722. pr_err("bad number for start of tty count");
  723. return -1;
  724. }
  725. p->u.board.v_start = 1;
  726. } else if (p->type == CNODE) {
  727. s = dgap_getword(in);
  728. if (!s) {
  729. pr_err("unexpected end of file");
  730. return -1;
  731. }
  732. if (kstrtol(s, 0, &p->u.conc.start)) {
  733. pr_err("bad number for start of tty count");
  734. return -1;
  735. }
  736. p->u.conc.v_start = 1;
  737. } else if (p->type == MNODE) {
  738. s = dgap_getword(in);
  739. if (!s) {
  740. pr_err("unexpected end of file");
  741. return -1;
  742. }
  743. if (kstrtol(s, 0, &p->u.module.start)) {
  744. pr_err("bad number for start of tty count");
  745. return -1;
  746. }
  747. p->u.module.v_start = 1;
  748. } else {
  749. pr_err("start only valid for concentrators or modules");
  750. return -1;
  751. }
  752. break;
  753. case TTYN: /* tty name prefix */
  754. if (dgap_checknode(p))
  755. return -1;
  756. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  757. if (!p->next)
  758. return -ENOMEM;
  759. p = p->next;
  760. p->type = TNODE;
  761. s = dgap_getword(in);
  762. if (!s) {
  763. pr_err("unexpeced end of file");
  764. return -1;
  765. }
  766. p->u.ttyname = kstrdup(s, GFP_KERNEL);
  767. if (!p->u.ttyname)
  768. return -1;
  769. break;
  770. case CU: /* cu name prefix */
  771. if (dgap_checknode(p))
  772. return -1;
  773. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  774. if (!p->next)
  775. return -ENOMEM;
  776. p = p->next;
  777. p->type = CUNODE;
  778. s = dgap_getword(in);
  779. if (!s) {
  780. pr_err("unexpeced end of file");
  781. return -1;
  782. }
  783. p->u.cuname = kstrdup(s, GFP_KERNEL);
  784. if (!p->u.cuname)
  785. return -1;
  786. break;
  787. case LINE: /* line information */
  788. if (dgap_checknode(p))
  789. return -1;
  790. if (!brd) {
  791. pr_err("must specify board before line info");
  792. return -1;
  793. }
  794. switch (brd->u.board.type) {
  795. case PPCM:
  796. pr_err("line not valid for PC/em");
  797. return -1;
  798. }
  799. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  800. if (!p->next)
  801. return -ENOMEM;
  802. p = p->next;
  803. p->type = LNODE;
  804. conc = NULL;
  805. line = p;
  806. linecnt++;
  807. break;
  808. case CONC: /* concentrator information */
  809. if (dgap_checknode(p))
  810. return -1;
  811. if (!line) {
  812. pr_err("must specify line info before concentrator");
  813. return -1;
  814. }
  815. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  816. if (!p->next)
  817. return -ENOMEM;
  818. p = p->next;
  819. p->type = CNODE;
  820. conc = p;
  821. if (linecnt)
  822. brd->u.board.conc2++;
  823. else
  824. brd->u.board.conc1++;
  825. conc_type = dgap_gettok(in);
  826. if (conc_type == 0 ||
  827. (conc_type != CX && conc_type != EPC)) {
  828. pr_err("failed to set a type of concentratros");
  829. return -1;
  830. }
  831. p->u.conc.type = conc_type;
  832. break;
  833. case MOD: /* EBI module */
  834. if (dgap_checknode(p))
  835. return -1;
  836. if (!brd) {
  837. pr_err("must specify board info before EBI modules");
  838. return -1;
  839. }
  840. switch (brd->u.board.type) {
  841. case PPCM:
  842. linecnt = 0;
  843. break;
  844. default:
  845. if (!conc) {
  846. pr_err("must specify concentrator info before EBI module");
  847. return -1;
  848. }
  849. }
  850. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  851. if (!p->next)
  852. return -ENOMEM;
  853. p = p->next;
  854. p->type = MNODE;
  855. if (linecnt)
  856. brd->u.board.module2++;
  857. else
  858. brd->u.board.module1++;
  859. module_type = dgap_gettok(in);
  860. if (module_type == 0 ||
  861. (module_type != PORTS && module_type != MODEM)) {
  862. pr_err("failed to set a type of module");
  863. return -1;
  864. }
  865. p->u.module.type = module_type;
  866. break;
  867. case CABLE:
  868. if (p->type == LNODE) {
  869. s = dgap_getword(in);
  870. if (!s) {
  871. pr_err("unexpected end of file");
  872. return -1;
  873. }
  874. kfree(p->u.line.cable);
  875. p->u.line.cable = kstrdup(s, GFP_KERNEL);
  876. p->u.line.v_cable = 1;
  877. }
  878. break;
  879. case SPEED: /* sync line speed indication */
  880. if (p->type == LNODE) {
  881. s = dgap_getword(in);
  882. if (!s) {
  883. pr_err("unexpected end of file");
  884. return -1;
  885. }
  886. if (kstrtol(s, 0, &p->u.line.speed)) {
  887. pr_err("bad number for line speed");
  888. return -1;
  889. }
  890. p->u.line.v_speed = 1;
  891. } else if (p->type == CNODE) {
  892. s = dgap_getword(in);
  893. if (!s) {
  894. pr_err("unexpected end of file");
  895. return -1;
  896. }
  897. if (kstrtol(s, 0, &p->u.conc.speed)) {
  898. pr_err("bad number for line speed");
  899. return -1;
  900. }
  901. p->u.conc.v_speed = 1;
  902. } else {
  903. pr_err("speed valid only for lines or concentrators.");
  904. return -1;
  905. }
  906. break;
  907. case CONNECT:
  908. if (p->type == CNODE) {
  909. s = dgap_getword(in);
  910. if (!s) {
  911. pr_err("unexpected end of file");
  912. return -1;
  913. }
  914. kfree(p->u.conc.connect);
  915. p->u.conc.connect = kstrdup(s, GFP_KERNEL);
  916. p->u.conc.v_connect = 1;
  917. }
  918. break;
  919. case PRINT: /* transparent print name prefix */
  920. if (dgap_checknode(p))
  921. return -1;
  922. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  923. if (!p->next)
  924. return -ENOMEM;
  925. p = p->next;
  926. p->type = PNODE;
  927. s = dgap_getword(in);
  928. if (!s) {
  929. pr_err("unexpeced end of file");
  930. return -1;
  931. }
  932. p->u.printname = kstrdup(s, GFP_KERNEL);
  933. if (!p->u.printname)
  934. return -1;
  935. break;
  936. case CMAJOR: /* major number */
  937. if (dgap_checknode(p))
  938. return -1;
  939. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  940. if (!p->next)
  941. return -ENOMEM;
  942. p = p->next;
  943. p->type = JNODE;
  944. s = dgap_getword(in);
  945. if (!s) {
  946. pr_err("unexpected end of file");
  947. return -1;
  948. }
  949. if (kstrtol(s, 0, &p->u.majornumber)) {
  950. pr_err("bad number for major number");
  951. return -1;
  952. }
  953. break;
  954. case ALTPIN: /* altpin setting */
  955. if (dgap_checknode(p))
  956. return -1;
  957. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  958. if (!p->next)
  959. return -ENOMEM;
  960. p = p->next;
  961. p->type = ANODE;
  962. s = dgap_getword(in);
  963. if (!s) {
  964. pr_err("unexpected end of file");
  965. return -1;
  966. }
  967. if (kstrtol(s, 0, &p->u.altpin)) {
  968. pr_err("bad number for altpin");
  969. return -1;
  970. }
  971. break;
  972. case USEINTR: /* enable interrupt setting */
  973. if (dgap_checknode(p))
  974. return -1;
  975. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  976. if (!p->next)
  977. return -ENOMEM;
  978. p = p->next;
  979. p->type = INTRNODE;
  980. s = dgap_getword(in);
  981. if (!s) {
  982. pr_err("unexpected end of file");
  983. return -1;
  984. }
  985. if (kstrtol(s, 0, &p->u.useintr)) {
  986. pr_err("bad number for useintr");
  987. return -1;
  988. }
  989. break;
  990. case TTSIZ: /* size of tty structure */
  991. if (dgap_checknode(p))
  992. return -1;
  993. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  994. if (!p->next)
  995. return -ENOMEM;
  996. p = p->next;
  997. p->type = TSNODE;
  998. s = dgap_getword(in);
  999. if (!s) {
  1000. pr_err("unexpected end of file");
  1001. return -1;
  1002. }
  1003. if (kstrtol(s, 0, &p->u.ttysize)) {
  1004. pr_err("bad number for ttysize");
  1005. return -1;
  1006. }
  1007. break;
  1008. case CHSIZ: /* channel structure size */
  1009. if (dgap_checknode(p))
  1010. return -1;
  1011. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  1012. if (!p->next)
  1013. return -ENOMEM;
  1014. p = p->next;
  1015. p->type = CSNODE;
  1016. s = dgap_getword(in);
  1017. if (!s) {
  1018. pr_err("unexpected end of file");
  1019. return -1;
  1020. }
  1021. if (kstrtol(s, 0, &p->u.chsize)) {
  1022. pr_err("bad number for chsize");
  1023. return -1;
  1024. }
  1025. break;
  1026. case BSSIZ: /* board structure size */
  1027. if (dgap_checknode(p))
  1028. return -1;
  1029. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  1030. if (!p->next)
  1031. return -ENOMEM;
  1032. p = p->next;
  1033. p->type = BSNODE;
  1034. s = dgap_getword(in);
  1035. if (!s) {
  1036. pr_err("unexpected end of file");
  1037. return -1;
  1038. }
  1039. if (kstrtol(s, 0, &p->u.bssize)) {
  1040. pr_err("bad number for bssize");
  1041. return -1;
  1042. }
  1043. break;
  1044. case UNTSIZ: /* sched structure size */
  1045. if (dgap_checknode(p))
  1046. return -1;
  1047. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  1048. if (!p->next)
  1049. return -ENOMEM;
  1050. p = p->next;
  1051. p->type = USNODE;
  1052. s = dgap_getword(in);
  1053. if (!s) {
  1054. pr_err("unexpected end of file");
  1055. return -1;
  1056. }
  1057. if (kstrtol(s, 0, &p->u.unsize)) {
  1058. pr_err("bad number for schedsize");
  1059. return -1;
  1060. }
  1061. break;
  1062. case F2SIZ: /* f2200 structure size */
  1063. if (dgap_checknode(p))
  1064. return -1;
  1065. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  1066. if (!p->next)
  1067. return -ENOMEM;
  1068. p = p->next;
  1069. p->type = FSNODE;
  1070. s = dgap_getword(in);
  1071. if (!s) {
  1072. pr_err("unexpected end of file");
  1073. return -1;
  1074. }
  1075. if (kstrtol(s, 0, &p->u.f2size)) {
  1076. pr_err("bad number for f2200size");
  1077. return -1;
  1078. }
  1079. break;
  1080. case VPSIZ: /* vpix structure size */
  1081. if (dgap_checknode(p))
  1082. return -1;
  1083. p->next = kzalloc(sizeof(struct cnode), GFP_KERNEL);
  1084. if (!p->next)
  1085. return -ENOMEM;
  1086. p = p->next;
  1087. p->type = VSNODE;
  1088. s = dgap_getword(in);
  1089. if (!s) {
  1090. pr_err("unexpected end of file");
  1091. return -1;
  1092. }
  1093. if (kstrtol(s, 0, &p->u.vpixsize)) {
  1094. pr_err("bad number for vpixsize");
  1095. return -1;
  1096. }
  1097. break;
  1098. }
  1099. }
  1100. }
  1101. static void dgap_cleanup_nodes(void)
  1102. {
  1103. struct cnode *p;
  1104. p = &dgap_head;
  1105. while (p) {
  1106. struct cnode *tmp = p->next;
  1107. if (p->type == NULLNODE) {
  1108. p = tmp;
  1109. continue;
  1110. }
  1111. switch (p->type) {
  1112. case BNODE:
  1113. kfree(p->u.board.addrstr);
  1114. kfree(p->u.board.pcibusstr);
  1115. kfree(p->u.board.pcislotstr);
  1116. kfree(p->u.board.method);
  1117. break;
  1118. case CNODE:
  1119. kfree(p->u.conc.id);
  1120. kfree(p->u.conc.connect);
  1121. break;
  1122. case MNODE:
  1123. kfree(p->u.module.id);
  1124. break;
  1125. case TNODE:
  1126. kfree(p->u.ttyname);
  1127. break;
  1128. case CUNODE:
  1129. kfree(p->u.cuname);
  1130. break;
  1131. case LNODE:
  1132. kfree(p->u.line.cable);
  1133. break;
  1134. case PNODE:
  1135. kfree(p->u.printname);
  1136. break;
  1137. }
  1138. kfree(p->u.board.status);
  1139. kfree(p);
  1140. p = tmp;
  1141. }
  1142. }
  1143. /*
  1144. * Retrives the current custom baud rate from FEP memory,
  1145. * and returns it back to the user.
  1146. * Returns 0 on error.
  1147. */
  1148. static uint dgap_get_custom_baud(struct channel_t *ch)
  1149. {
  1150. u8 __iomem *vaddr;
  1151. ulong offset;
  1152. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  1153. return 0;
  1154. if (!ch->ch_bd || ch->ch_bd->magic != DGAP_BOARD_MAGIC)
  1155. return 0;
  1156. if (!(ch->ch_bd->bd_flags & BD_FEP5PLUS))
  1157. return 0;
  1158. vaddr = ch->ch_bd->re_map_membase;
  1159. if (!vaddr)
  1160. return 0;
  1161. /*
  1162. * Go get from fep mem, what the fep
  1163. * believes the custom baud rate is.
  1164. */
  1165. offset = (ioread16(vaddr + ECS_SEG) << 4) + (ch->ch_portnum * 0x28)
  1166. + LINE_SPEED;
  1167. return readw(vaddr + offset);
  1168. }
  1169. /*
  1170. * Remap PCI memory.
  1171. */
  1172. static int dgap_remap(struct board_t *brd)
  1173. {
  1174. if (!brd || brd->magic != DGAP_BOARD_MAGIC)
  1175. return -EIO;
  1176. if (!request_mem_region(brd->membase, 0x200000, "dgap"))
  1177. return -ENOMEM;
  1178. if (!request_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000, "dgap"))
  1179. goto err_req_mem;
  1180. brd->re_map_membase = ioremap(brd->membase, 0x200000);
  1181. if (!brd->re_map_membase)
  1182. goto err_remap_mem;
  1183. brd->re_map_port = ioremap((brd->membase + PCI_IO_OFFSET), 0x200000);
  1184. if (!brd->re_map_port)
  1185. goto err_remap_port;
  1186. return 0;
  1187. err_remap_port:
  1188. iounmap(brd->re_map_membase);
  1189. err_remap_mem:
  1190. release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
  1191. err_req_mem:
  1192. release_mem_region(brd->membase, 0x200000);
  1193. return -ENOMEM;
  1194. }
  1195. static void dgap_unmap(struct board_t *brd)
  1196. {
  1197. iounmap(brd->re_map_port);
  1198. iounmap(brd->re_map_membase);
  1199. release_mem_region(brd->membase + PCI_IO_OFFSET, 0x200000);
  1200. release_mem_region(brd->membase, 0x200000);
  1201. }
  1202. /*
  1203. * dgap_parity_scan()
  1204. *
  1205. * Convert the FEP5 way of reporting parity errors and breaks into
  1206. * the Linux line discipline way.
  1207. */
  1208. static void dgap_parity_scan(struct channel_t *ch, unsigned char *cbuf,
  1209. unsigned char *fbuf, int *len)
  1210. {
  1211. int l = *len;
  1212. int count = 0;
  1213. unsigned char *in, *cout, *fout;
  1214. unsigned char c;
  1215. in = cbuf;
  1216. cout = cbuf;
  1217. fout = fbuf;
  1218. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  1219. return;
  1220. while (l--) {
  1221. c = *in++;
  1222. switch (ch->pscan_state) {
  1223. default:
  1224. /* reset to sanity and fall through */
  1225. ch->pscan_state = 0;
  1226. case 0:
  1227. /* No FF seen yet */
  1228. if (c == (unsigned char)'\377')
  1229. /* delete this character from stream */
  1230. ch->pscan_state = 1;
  1231. else {
  1232. *cout++ = c;
  1233. *fout++ = TTY_NORMAL;
  1234. count += 1;
  1235. }
  1236. break;
  1237. case 1:
  1238. /* first FF seen */
  1239. if (c == (unsigned char)'\377') {
  1240. /* doubled ff, transform to single ff */
  1241. *cout++ = c;
  1242. *fout++ = TTY_NORMAL;
  1243. count += 1;
  1244. ch->pscan_state = 0;
  1245. } else {
  1246. /* save value examination in next state */
  1247. ch->pscan_savechar = c;
  1248. ch->pscan_state = 2;
  1249. }
  1250. break;
  1251. case 2:
  1252. /* third character of ff sequence */
  1253. *cout++ = c;
  1254. if (ch->pscan_savechar == 0x0) {
  1255. if (c == 0x0) {
  1256. ch->ch_err_break++;
  1257. *fout++ = TTY_BREAK;
  1258. } else {
  1259. ch->ch_err_parity++;
  1260. *fout++ = TTY_PARITY;
  1261. }
  1262. }
  1263. count += 1;
  1264. ch->pscan_state = 0;
  1265. }
  1266. }
  1267. *len = count;
  1268. }
  1269. /*=======================================================================
  1270. *
  1271. * dgap_input - Process received data.
  1272. *
  1273. * ch - Pointer to channel structure.
  1274. *
  1275. *=======================================================================*/
  1276. static void dgap_input(struct channel_t *ch)
  1277. {
  1278. struct board_t *bd;
  1279. struct bs_t __iomem *bs;
  1280. struct tty_struct *tp;
  1281. struct tty_ldisc *ld;
  1282. uint rmask;
  1283. uint head;
  1284. uint tail;
  1285. int data_len;
  1286. ulong lock_flags;
  1287. ulong lock_flags2;
  1288. int flip_len;
  1289. int len;
  1290. int n;
  1291. u8 *buf;
  1292. u8 tmpchar;
  1293. int s;
  1294. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  1295. return;
  1296. tp = ch->ch_tun.un_tty;
  1297. bs = ch->ch_bs;
  1298. if (!bs)
  1299. return;
  1300. bd = ch->ch_bd;
  1301. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  1302. return;
  1303. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  1304. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  1305. /*
  1306. * Figure the number of characters in the buffer.
  1307. * Exit immediately if none.
  1308. */
  1309. rmask = ch->ch_rsize - 1;
  1310. head = readw(&bs->rx_head);
  1311. head &= rmask;
  1312. tail = readw(&bs->rx_tail);
  1313. tail &= rmask;
  1314. data_len = (head - tail) & rmask;
  1315. if (data_len == 0) {
  1316. writeb(1, &bs->idata);
  1317. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  1318. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1319. return;
  1320. }
  1321. /*
  1322. * If the device is not open, or CREAD is off, flush
  1323. * input data and return immediately.
  1324. */
  1325. if ((bd->state != BOARD_READY) || !tp ||
  1326. (tp->magic != TTY_MAGIC) ||
  1327. !(ch->ch_tun.un_flags & UN_ISOPEN) ||
  1328. !(tp->termios.c_cflag & CREAD) ||
  1329. (ch->ch_tun.un_flags & UN_CLOSING)) {
  1330. writew(head, &bs->rx_tail);
  1331. writeb(1, &bs->idata);
  1332. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  1333. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1334. return;
  1335. }
  1336. /*
  1337. * If we are throttled, simply don't read any data.
  1338. */
  1339. if (ch->ch_flags & CH_RXBLOCK) {
  1340. writeb(1, &bs->idata);
  1341. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  1342. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1343. return;
  1344. }
  1345. /*
  1346. * Ignore oruns.
  1347. */
  1348. tmpchar = readb(&bs->orun);
  1349. if (tmpchar) {
  1350. ch->ch_err_overrun++;
  1351. writeb(0, &bs->orun);
  1352. }
  1353. /* Decide how much data we can send into the tty layer */
  1354. flip_len = TTY_FLIPBUF_SIZE;
  1355. /* Chop down the length, if needed */
  1356. len = min(data_len, flip_len);
  1357. len = min(len, (N_TTY_BUF_SIZE - 1));
  1358. ld = tty_ldisc_ref(tp);
  1359. #ifdef TTY_DONT_FLIP
  1360. /*
  1361. * If the DONT_FLIP flag is on, don't flush our buffer, and act
  1362. * like the ld doesn't have any space to put the data right now.
  1363. */
  1364. if (test_bit(TTY_DONT_FLIP, &tp->flags))
  1365. len = 0;
  1366. #endif
  1367. /*
  1368. * If we were unable to get a reference to the ld,
  1369. * don't flush our buffer, and act like the ld doesn't
  1370. * have any space to put the data right now.
  1371. */
  1372. if (!ld) {
  1373. len = 0;
  1374. } else {
  1375. /*
  1376. * If ld doesn't have a pointer to a receive_buf function,
  1377. * flush the data, then act like the ld doesn't have any
  1378. * space to put the data right now.
  1379. */
  1380. if (!ld->ops->receive_buf) {
  1381. writew(head, &bs->rx_tail);
  1382. len = 0;
  1383. }
  1384. }
  1385. if (len <= 0) {
  1386. writeb(1, &bs->idata);
  1387. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  1388. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1389. if (ld)
  1390. tty_ldisc_deref(ld);
  1391. return;
  1392. }
  1393. buf = ch->ch_bd->flipbuf;
  1394. n = len;
  1395. /*
  1396. * n now contains the most amount of data we can copy,
  1397. * bounded either by our buffer size or the amount
  1398. * of data the card actually has pending...
  1399. */
  1400. while (n) {
  1401. s = ((head >= tail) ? head : ch->ch_rsize) - tail;
  1402. s = min(s, n);
  1403. if (s <= 0)
  1404. break;
  1405. memcpy_fromio(buf, ch->ch_raddr + tail, s);
  1406. tail += s;
  1407. buf += s;
  1408. n -= s;
  1409. /* Flip queue if needed */
  1410. tail &= rmask;
  1411. }
  1412. writew(tail, &bs->rx_tail);
  1413. writeb(1, &bs->idata);
  1414. ch->ch_rxcount += len;
  1415. /*
  1416. * If we are completely raw, we don't need to go through a lot
  1417. * of the tty layers that exist.
  1418. * In this case, we take the shortest and fastest route we
  1419. * can to relay the data to the user.
  1420. *
  1421. * On the other hand, if we are not raw, we need to go through
  1422. * the tty layer, which has its API more well defined.
  1423. */
  1424. if (I_PARMRK(tp) || I_BRKINT(tp) || I_INPCK(tp)) {
  1425. dgap_parity_scan(ch, ch->ch_bd->flipbuf,
  1426. ch->ch_bd->flipflagbuf, &len);
  1427. len = tty_buffer_request_room(tp->port, len);
  1428. tty_insert_flip_string_flags(tp->port, ch->ch_bd->flipbuf,
  1429. ch->ch_bd->flipflagbuf, len);
  1430. } else {
  1431. len = tty_buffer_request_room(tp->port, len);
  1432. tty_insert_flip_string(tp->port, ch->ch_bd->flipbuf, len);
  1433. }
  1434. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  1435. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1436. /* Tell the tty layer its okay to "eat" the data now */
  1437. tty_flip_buffer_push(tp->port);
  1438. if (ld)
  1439. tty_ldisc_deref(ld);
  1440. }
  1441. static void dgap_write_wakeup(struct board_t *bd, struct channel_t *ch,
  1442. struct un_t *un, u32 mask,
  1443. unsigned long *irq_flags1,
  1444. unsigned long *irq_flags2)
  1445. {
  1446. if (!(un->un_flags & mask))
  1447. return;
  1448. un->un_flags &= ~mask;
  1449. if (!(un->un_flags & UN_ISOPEN))
  1450. return;
  1451. if ((un->un_tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  1452. un->un_tty->ldisc->ops->write_wakeup) {
  1453. spin_unlock_irqrestore(&ch->ch_lock, *irq_flags2);
  1454. spin_unlock_irqrestore(&bd->bd_lock, *irq_flags1);
  1455. (un->un_tty->ldisc->ops->write_wakeup)(un->un_tty);
  1456. spin_lock_irqsave(&bd->bd_lock, *irq_flags1);
  1457. spin_lock_irqsave(&ch->ch_lock, *irq_flags2);
  1458. }
  1459. wake_up_interruptible(&un->un_tty->write_wait);
  1460. wake_up_interruptible(&un->un_flags_wait);
  1461. }
  1462. /************************************************************************
  1463. * Determines when CARRIER changes state and takes appropriate
  1464. * action.
  1465. ************************************************************************/
  1466. static void dgap_carrier(struct channel_t *ch)
  1467. {
  1468. struct board_t *bd;
  1469. int virt_carrier = 0;
  1470. int phys_carrier = 0;
  1471. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  1472. return;
  1473. bd = ch->ch_bd;
  1474. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  1475. return;
  1476. /* Make sure altpin is always set correctly */
  1477. if (ch->ch_digi.digi_flags & DIGI_ALTPIN) {
  1478. ch->ch_dsr = DM_CD;
  1479. ch->ch_cd = DM_DSR;
  1480. } else {
  1481. ch->ch_dsr = DM_DSR;
  1482. ch->ch_cd = DM_CD;
  1483. }
  1484. if (ch->ch_mistat & D_CD(ch))
  1485. phys_carrier = 1;
  1486. if (ch->ch_digi.digi_flags & DIGI_FORCEDCD)
  1487. virt_carrier = 1;
  1488. if (ch->ch_c_cflag & CLOCAL)
  1489. virt_carrier = 1;
  1490. /*
  1491. * Test for a VIRTUAL carrier transition to HIGH.
  1492. */
  1493. if (((ch->ch_flags & CH_FCAR) == 0) && (virt_carrier == 1)) {
  1494. /*
  1495. * When carrier rises, wake any threads waiting
  1496. * for carrier in the open routine.
  1497. */
  1498. if (waitqueue_active(&(ch->ch_flags_wait)))
  1499. wake_up_interruptible(&ch->ch_flags_wait);
  1500. }
  1501. /*
  1502. * Test for a PHYSICAL carrier transition to HIGH.
  1503. */
  1504. if (((ch->ch_flags & CH_CD) == 0) && (phys_carrier == 1)) {
  1505. /*
  1506. * When carrier rises, wake any threads waiting
  1507. * for carrier in the open routine.
  1508. */
  1509. if (waitqueue_active(&(ch->ch_flags_wait)))
  1510. wake_up_interruptible(&ch->ch_flags_wait);
  1511. }
  1512. /*
  1513. * Test for a PHYSICAL transition to low, so long as we aren't
  1514. * currently ignoring physical transitions (which is what "virtual
  1515. * carrier" indicates).
  1516. *
  1517. * The transition of the virtual carrier to low really doesn't
  1518. * matter... it really only means "ignore carrier state", not
  1519. * "make pretend that carrier is there".
  1520. */
  1521. if ((virt_carrier == 0) &&
  1522. ((ch->ch_flags & CH_CD) != 0) &&
  1523. (phys_carrier == 0)) {
  1524. /*
  1525. * When carrier drops:
  1526. *
  1527. * Drop carrier on all open units.
  1528. *
  1529. * Flush queues, waking up any task waiting in the
  1530. * line discipline.
  1531. *
  1532. * Send a hangup to the control terminal.
  1533. *
  1534. * Enable all select calls.
  1535. */
  1536. if (waitqueue_active(&(ch->ch_flags_wait)))
  1537. wake_up_interruptible(&ch->ch_flags_wait);
  1538. if (ch->ch_tun.un_open_count > 0)
  1539. tty_hangup(ch->ch_tun.un_tty);
  1540. if (ch->ch_pun.un_open_count > 0)
  1541. tty_hangup(ch->ch_pun.un_tty);
  1542. }
  1543. /*
  1544. * Make sure that our cached values reflect the current reality.
  1545. */
  1546. if (virt_carrier == 1)
  1547. ch->ch_flags |= CH_FCAR;
  1548. else
  1549. ch->ch_flags &= ~CH_FCAR;
  1550. if (phys_carrier == 1)
  1551. ch->ch_flags |= CH_CD;
  1552. else
  1553. ch->ch_flags &= ~CH_CD;
  1554. }
  1555. /*=======================================================================
  1556. *
  1557. * dgap_event - FEP to host event processing routine.
  1558. *
  1559. * bd - Board of current event.
  1560. *
  1561. *=======================================================================*/
  1562. static int dgap_event(struct board_t *bd)
  1563. {
  1564. struct channel_t *ch;
  1565. ulong lock_flags;
  1566. ulong lock_flags2;
  1567. struct bs_t __iomem *bs;
  1568. u8 __iomem *event;
  1569. u8 __iomem *vaddr;
  1570. struct ev_t __iomem *eaddr;
  1571. uint head;
  1572. uint tail;
  1573. int port;
  1574. int reason;
  1575. int modem;
  1576. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  1577. return -EIO;
  1578. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  1579. vaddr = bd->re_map_membase;
  1580. if (!vaddr) {
  1581. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1582. return -EIO;
  1583. }
  1584. eaddr = (struct ev_t __iomem *)(vaddr + EVBUF);
  1585. /* Get our head and tail */
  1586. head = readw(&eaddr->ev_head);
  1587. tail = readw(&eaddr->ev_tail);
  1588. /*
  1589. * Forget it if pointers out of range.
  1590. */
  1591. if (head >= EVMAX - EVSTART || tail >= EVMAX - EVSTART ||
  1592. (head | tail) & 03) {
  1593. /* Let go of board lock */
  1594. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1595. return -EIO;
  1596. }
  1597. /*
  1598. * Loop to process all the events in the buffer.
  1599. */
  1600. while (tail != head) {
  1601. /*
  1602. * Get interrupt information.
  1603. */
  1604. event = bd->re_map_membase + tail + EVSTART;
  1605. port = ioread8(event);
  1606. reason = ioread8(event + 1);
  1607. modem = ioread8(event + 2);
  1608. ioread8(event + 3);
  1609. /*
  1610. * Make sure the interrupt is valid.
  1611. */
  1612. if (port >= bd->nasync)
  1613. goto next;
  1614. if (!(reason & (IFMODEM | IFBREAK | IFTLW | IFTEM | IFDATA)))
  1615. goto next;
  1616. ch = bd->channels[port];
  1617. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  1618. goto next;
  1619. /*
  1620. * If we have made it here, the event was valid.
  1621. * Lock down the channel.
  1622. */
  1623. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  1624. bs = ch->ch_bs;
  1625. if (!bs) {
  1626. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  1627. goto next;
  1628. }
  1629. /*
  1630. * Process received data.
  1631. */
  1632. if (reason & IFDATA) {
  1633. /*
  1634. * ALL LOCKS *MUST* BE DROPPED BEFORE CALLING INPUT!
  1635. * input could send some data to ld, which in turn
  1636. * could do a callback to one of our other functions.
  1637. */
  1638. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  1639. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1640. dgap_input(ch);
  1641. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  1642. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  1643. if (ch->ch_flags & CH_RACTIVE)
  1644. ch->ch_flags |= CH_RENABLE;
  1645. else
  1646. writeb(1, &bs->idata);
  1647. if (ch->ch_flags & CH_RWAIT) {
  1648. ch->ch_flags &= ~CH_RWAIT;
  1649. wake_up_interruptible
  1650. (&ch->ch_tun.un_flags_wait);
  1651. }
  1652. }
  1653. /*
  1654. * Process Modem change signals.
  1655. */
  1656. if (reason & IFMODEM) {
  1657. ch->ch_mistat = modem;
  1658. dgap_carrier(ch);
  1659. }
  1660. /*
  1661. * Process break.
  1662. */
  1663. if (reason & IFBREAK) {
  1664. if (ch->ch_tun.un_tty) {
  1665. /* A break has been indicated */
  1666. ch->ch_err_break++;
  1667. tty_buffer_request_room
  1668. (ch->ch_tun.un_tty->port, 1);
  1669. tty_insert_flip_char(ch->ch_tun.un_tty->port,
  1670. 0, TTY_BREAK);
  1671. tty_flip_buffer_push(ch->ch_tun.un_tty->port);
  1672. }
  1673. }
  1674. /*
  1675. * Process Transmit low.
  1676. */
  1677. if (reason & IFTLW) {
  1678. dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_LOW,
  1679. &lock_flags, &lock_flags2);
  1680. dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_LOW,
  1681. &lock_flags, &lock_flags2);
  1682. if (ch->ch_flags & CH_WLOW) {
  1683. ch->ch_flags &= ~CH_WLOW;
  1684. wake_up_interruptible(&ch->ch_flags_wait);
  1685. }
  1686. }
  1687. /*
  1688. * Process Transmit empty.
  1689. */
  1690. if (reason & IFTEM) {
  1691. dgap_write_wakeup(bd, ch, &ch->ch_tun, UN_EMPTY,
  1692. &lock_flags, &lock_flags2);
  1693. dgap_write_wakeup(bd, ch, &ch->ch_pun, UN_EMPTY,
  1694. &lock_flags, &lock_flags2);
  1695. if (ch->ch_flags & CH_WEMPTY) {
  1696. ch->ch_flags &= ~CH_WEMPTY;
  1697. wake_up_interruptible(&ch->ch_flags_wait);
  1698. }
  1699. }
  1700. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  1701. next:
  1702. tail = (tail + 4) & (EVMAX - EVSTART - 4);
  1703. }
  1704. writew(tail, &eaddr->ev_tail);
  1705. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1706. return 0;
  1707. }
  1708. /*
  1709. * Our board poller function.
  1710. */
  1711. static void dgap_poll_tasklet(unsigned long data)
  1712. {
  1713. struct board_t *bd = (struct board_t *)data;
  1714. ulong lock_flags;
  1715. char __iomem *vaddr;
  1716. u16 head, tail;
  1717. if (!bd || (bd->magic != DGAP_BOARD_MAGIC))
  1718. return;
  1719. if (bd->inhibit_poller)
  1720. return;
  1721. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  1722. vaddr = bd->re_map_membase;
  1723. /*
  1724. * If board is ready, parse deeper to see if there is anything to do.
  1725. */
  1726. if (bd->state == BOARD_READY) {
  1727. struct ev_t __iomem *eaddr;
  1728. if (!bd->re_map_membase) {
  1729. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1730. return;
  1731. }
  1732. if (!bd->re_map_port) {
  1733. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1734. return;
  1735. }
  1736. if (!bd->nasync)
  1737. goto out;
  1738. eaddr = (struct ev_t __iomem *)(vaddr + EVBUF);
  1739. /* Get our head and tail */
  1740. head = readw(&eaddr->ev_head);
  1741. tail = readw(&eaddr->ev_tail);
  1742. /*
  1743. * If there is an event pending. Go service it.
  1744. */
  1745. if (head != tail) {
  1746. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1747. dgap_event(bd);
  1748. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  1749. }
  1750. out:
  1751. /*
  1752. * If board is doing interrupts, ACK the interrupt.
  1753. */
  1754. if (bd->intr_running)
  1755. readb(bd->re_map_port + 2);
  1756. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1757. return;
  1758. }
  1759. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  1760. }
  1761. /*
  1762. * dgap_found_board()
  1763. *
  1764. * A board has been found, init it.
  1765. */
  1766. static struct board_t *dgap_found_board(struct pci_dev *pdev, int id,
  1767. int boardnum)
  1768. {
  1769. struct board_t *brd;
  1770. unsigned int pci_irq;
  1771. int i;
  1772. int ret;
  1773. /* get the board structure and prep it */
  1774. brd = kzalloc(sizeof(struct board_t), GFP_KERNEL);
  1775. if (!brd)
  1776. return ERR_PTR(-ENOMEM);
  1777. /* store the info for the board we've found */
  1778. brd->magic = DGAP_BOARD_MAGIC;
  1779. brd->boardnum = boardnum;
  1780. brd->vendor = dgap_pci_tbl[id].vendor;
  1781. brd->device = dgap_pci_tbl[id].device;
  1782. brd->pdev = pdev;
  1783. brd->pci_bus = pdev->bus->number;
  1784. brd->pci_slot = PCI_SLOT(pdev->devfn);
  1785. brd->name = dgap_ids[id].name;
  1786. brd->maxports = dgap_ids[id].maxports;
  1787. brd->type = dgap_ids[id].config_type;
  1788. brd->dpatype = dgap_ids[id].dpatype;
  1789. brd->dpastatus = BD_NOFEP;
  1790. init_waitqueue_head(&brd->state_wait);
  1791. spin_lock_init(&brd->bd_lock);
  1792. brd->inhibit_poller = FALSE;
  1793. brd->wait_for_bios = 0;
  1794. brd->wait_for_fep = 0;
  1795. for (i = 0; i < MAXPORTS; i++)
  1796. brd->channels[i] = NULL;
  1797. /* store which card & revision we have */
  1798. pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &brd->subvendor);
  1799. pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &brd->subdevice);
  1800. pci_read_config_byte(pdev, PCI_REVISION_ID, &brd->rev);
  1801. pci_irq = pdev->irq;
  1802. brd->irq = pci_irq;
  1803. /* get the PCI Base Address Registers */
  1804. /* Xr Jupiter and EPC use BAR 2 */
  1805. if (brd->device == PCI_DEV_XRJ_DID || brd->device == PCI_DEV_EPCJ_DID) {
  1806. brd->membase = pci_resource_start(pdev, 2);
  1807. brd->membase_end = pci_resource_end(pdev, 2);
  1808. }
  1809. /* Everyone else uses BAR 0 */
  1810. else {
  1811. brd->membase = pci_resource_start(pdev, 0);
  1812. brd->membase_end = pci_resource_end(pdev, 0);
  1813. }
  1814. if (!brd->membase) {
  1815. ret = -ENODEV;
  1816. goto free_brd;
  1817. }
  1818. if (brd->membase & 1)
  1819. brd->membase &= ~3;
  1820. else
  1821. brd->membase &= ~15;
  1822. /*
  1823. * On the PCI boards, there is no IO space allocated
  1824. * The I/O registers will be in the first 3 bytes of the
  1825. * upper 2MB of the 4MB memory space. The board memory
  1826. * will be mapped into the low 2MB of the 4MB memory space
  1827. */
  1828. brd->port = brd->membase + PCI_IO_OFFSET;
  1829. brd->port_end = brd->port + PCI_IO_SIZE_DGAP;
  1830. /*
  1831. * Special initialization for non-PLX boards
  1832. */
  1833. if (brd->device != PCI_DEV_XRJ_DID && brd->device != PCI_DEV_EPCJ_DID) {
  1834. unsigned short cmd;
  1835. pci_write_config_byte(pdev, 0x40, 0);
  1836. pci_write_config_byte(pdev, 0x46, 0);
  1837. /* Limit burst length to 2 doubleword transactions */
  1838. pci_write_config_byte(pdev, 0x42, 1);
  1839. /*
  1840. * Enable IO and mem if not already done.
  1841. * This was needed for support on Itanium.
  1842. */
  1843. pci_read_config_word(pdev, PCI_COMMAND, &cmd);
  1844. cmd |= (PCI_COMMAND_IO | PCI_COMMAND_MEMORY);
  1845. pci_write_config_word(pdev, PCI_COMMAND, cmd);
  1846. }
  1847. /* init our poll helper tasklet */
  1848. tasklet_init(&brd->helper_tasklet, dgap_poll_tasklet,
  1849. (unsigned long)brd);
  1850. ret = dgap_remap(brd);
  1851. if (ret)
  1852. goto free_brd;
  1853. pr_info("dgap: board %d: %s (rev %d), irq %ld\n",
  1854. boardnum, brd->name, brd->rev, brd->irq);
  1855. return brd;
  1856. free_brd:
  1857. kfree(brd);
  1858. return ERR_PTR(ret);
  1859. }
  1860. /*
  1861. * dgap_intr()
  1862. *
  1863. * Driver interrupt handler.
  1864. */
  1865. static irqreturn_t dgap_intr(int irq, void *voidbrd)
  1866. {
  1867. struct board_t *brd = voidbrd;
  1868. if (!brd)
  1869. return IRQ_NONE;
  1870. /*
  1871. * Check to make sure its for us.
  1872. */
  1873. if (brd->magic != DGAP_BOARD_MAGIC)
  1874. return IRQ_NONE;
  1875. brd->intr_count++;
  1876. /*
  1877. * Schedule tasklet to run at a better time.
  1878. */
  1879. tasklet_schedule(&brd->helper_tasklet);
  1880. return IRQ_HANDLED;
  1881. }
  1882. /*****************************************************************************
  1883. *
  1884. * Function:
  1885. *
  1886. * dgap_poll_handler
  1887. *
  1888. * Author:
  1889. *
  1890. * Scott H Kilau
  1891. *
  1892. * Parameters:
  1893. *
  1894. * dummy -- ignored
  1895. *
  1896. * Return Values:
  1897. *
  1898. * none
  1899. *
  1900. * Description:
  1901. *
  1902. * As each timer expires, it determines (a) whether the "transmit"
  1903. * waiter needs to be woken up, and (b) whether the poller needs to
  1904. * be rescheduled.
  1905. *
  1906. ******************************************************************************/
  1907. static void dgap_poll_handler(ulong dummy)
  1908. {
  1909. unsigned int i;
  1910. struct board_t *brd;
  1911. unsigned long lock_flags;
  1912. ulong new_time;
  1913. dgap_poll_counter++;
  1914. /*
  1915. * Do not start the board state machine until
  1916. * driver tells us its up and running, and has
  1917. * everything it needs.
  1918. */
  1919. if (dgap_driver_state != DRIVER_READY)
  1920. goto schedule_poller;
  1921. /*
  1922. * If we have just 1 board, or the system is not SMP,
  1923. * then use the typical old style poller.
  1924. * Otherwise, use our new tasklet based poller, which should
  1925. * speed things up for multiple boards.
  1926. */
  1927. if ((dgap_numboards == 1) || (num_online_cpus() <= 1)) {
  1928. for (i = 0; i < dgap_numboards; i++) {
  1929. brd = dgap_board[i];
  1930. if (brd->state == BOARD_FAILED)
  1931. continue;
  1932. if (!brd->intr_running)
  1933. /* Call the real board poller directly */
  1934. dgap_poll_tasklet((unsigned long)brd);
  1935. }
  1936. } else {
  1937. /*
  1938. * Go thru each board, kicking off a
  1939. * tasklet for each if needed
  1940. */
  1941. for (i = 0; i < dgap_numboards; i++) {
  1942. brd = dgap_board[i];
  1943. /*
  1944. * Attempt to grab the board lock.
  1945. *
  1946. * If we can't get it, no big deal, the next poll
  1947. * will get it. Basically, I just really don't want
  1948. * to spin in here, because I want to kick off my
  1949. * tasklets as fast as I can, and then get out the
  1950. * poller.
  1951. */
  1952. if (!spin_trylock(&brd->bd_lock))
  1953. continue;
  1954. /*
  1955. * If board is in a failed state, don't bother
  1956. * scheduling a tasklet
  1957. */
  1958. if (brd->state == BOARD_FAILED) {
  1959. spin_unlock(&brd->bd_lock);
  1960. continue;
  1961. }
  1962. /* Schedule a poll helper task */
  1963. if (!brd->intr_running)
  1964. tasklet_schedule(&brd->helper_tasklet);
  1965. /*
  1966. * Can't do DGAP_UNLOCK here, as we don't have
  1967. * lock_flags because we did a trylock above.
  1968. */
  1969. spin_unlock(&brd->bd_lock);
  1970. }
  1971. }
  1972. schedule_poller:
  1973. /*
  1974. * Schedule ourself back at the nominal wakeup interval.
  1975. */
  1976. spin_lock_irqsave(&dgap_poll_lock, lock_flags);
  1977. dgap_poll_time += dgap_jiffies_from_ms(dgap_poll_tick);
  1978. new_time = dgap_poll_time - jiffies;
  1979. if ((ulong)new_time >= 2 * dgap_poll_tick) {
  1980. dgap_poll_time =
  1981. jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
  1982. }
  1983. dgap_poll_timer.function = dgap_poll_handler;
  1984. dgap_poll_timer.data = 0;
  1985. dgap_poll_timer.expires = dgap_poll_time;
  1986. spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
  1987. if (!dgap_poll_stop)
  1988. add_timer(&dgap_poll_timer);
  1989. }
  1990. /*=======================================================================
  1991. *
  1992. * dgap_cmdb - Sends a 2 byte command to the FEP.
  1993. *
  1994. * ch - Pointer to channel structure.
  1995. * cmd - Command to be sent.
  1996. * byte1 - Integer containing first byte to be sent.
  1997. * byte2 - Integer containing second byte to be sent.
  1998. * ncmds - Wait until ncmds or fewer cmds are left
  1999. * in the cmd buffer before returning.
  2000. *
  2001. *=======================================================================*/
  2002. static void dgap_cmdb(struct channel_t *ch, u8 cmd, u8 byte1,
  2003. u8 byte2, uint ncmds)
  2004. {
  2005. char __iomem *vaddr;
  2006. struct __iomem cm_t *cm_addr;
  2007. uint count;
  2008. uint n;
  2009. u16 head;
  2010. u16 tail;
  2011. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2012. return;
  2013. /*
  2014. * Check if board is still alive.
  2015. */
  2016. if (ch->ch_bd->state == BOARD_FAILED)
  2017. return;
  2018. /*
  2019. * Make sure the pointers are in range before
  2020. * writing to the FEP memory.
  2021. */
  2022. vaddr = ch->ch_bd->re_map_membase;
  2023. if (!vaddr)
  2024. return;
  2025. cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF);
  2026. head = readw(&cm_addr->cm_head);
  2027. /*
  2028. * Forget it if pointers out of range.
  2029. */
  2030. if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
  2031. ch->ch_bd->state = BOARD_FAILED;
  2032. return;
  2033. }
  2034. /*
  2035. * Put the data in the circular command buffer.
  2036. */
  2037. writeb(cmd, (vaddr + head + CMDSTART + 0));
  2038. writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1));
  2039. writeb(byte1, (vaddr + head + CMDSTART + 2));
  2040. writeb(byte2, (vaddr + head + CMDSTART + 3));
  2041. head = (head + 4) & (CMDMAX - CMDSTART - 4);
  2042. writew(head, &cm_addr->cm_head);
  2043. /*
  2044. * Wait if necessary before updating the head
  2045. * pointer to limit the number of outstanding
  2046. * commands to the FEP. If the time spent waiting
  2047. * is outlandish, declare the FEP dead.
  2048. */
  2049. for (count = dgap_count ;;) {
  2050. head = readw(&cm_addr->cm_head);
  2051. tail = readw(&cm_addr->cm_tail);
  2052. n = (head - tail) & (CMDMAX - CMDSTART - 4);
  2053. if (n <= ncmds * sizeof(struct cm_t))
  2054. break;
  2055. if (--count == 0) {
  2056. ch->ch_bd->state = BOARD_FAILED;
  2057. return;
  2058. }
  2059. udelay(10);
  2060. }
  2061. }
  2062. /*=======================================================================
  2063. *
  2064. * dgap_cmdw - Sends a 1 word command to the FEP.
  2065. *
  2066. * ch - Pointer to channel structure.
  2067. * cmd - Command to be sent.
  2068. * word - Integer containing word to be sent.
  2069. * ncmds - Wait until ncmds or fewer cmds are left
  2070. * in the cmd buffer before returning.
  2071. *
  2072. *=======================================================================*/
  2073. static void dgap_cmdw(struct channel_t *ch, u8 cmd, u16 word, uint ncmds)
  2074. {
  2075. char __iomem *vaddr;
  2076. struct __iomem cm_t *cm_addr;
  2077. uint count;
  2078. uint n;
  2079. u16 head;
  2080. u16 tail;
  2081. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2082. return;
  2083. /*
  2084. * Check if board is still alive.
  2085. */
  2086. if (ch->ch_bd->state == BOARD_FAILED)
  2087. return;
  2088. /*
  2089. * Make sure the pointers are in range before
  2090. * writing to the FEP memory.
  2091. */
  2092. vaddr = ch->ch_bd->re_map_membase;
  2093. if (!vaddr)
  2094. return;
  2095. cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF);
  2096. head = readw(&cm_addr->cm_head);
  2097. /*
  2098. * Forget it if pointers out of range.
  2099. */
  2100. if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
  2101. ch->ch_bd->state = BOARD_FAILED;
  2102. return;
  2103. }
  2104. /*
  2105. * Put the data in the circular command buffer.
  2106. */
  2107. writeb(cmd, (vaddr + head + CMDSTART + 0));
  2108. writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1));
  2109. writew((u16)word, (vaddr + head + CMDSTART + 2));
  2110. head = (head + 4) & (CMDMAX - CMDSTART - 4);
  2111. writew(head, &cm_addr->cm_head);
  2112. /*
  2113. * Wait if necessary before updating the head
  2114. * pointer to limit the number of outstanding
  2115. * commands to the FEP. If the time spent waiting
  2116. * is outlandish, declare the FEP dead.
  2117. */
  2118. for (count = dgap_count ;;) {
  2119. head = readw(&cm_addr->cm_head);
  2120. tail = readw(&cm_addr->cm_tail);
  2121. n = (head - tail) & (CMDMAX - CMDSTART - 4);
  2122. if (n <= ncmds * sizeof(struct cm_t))
  2123. break;
  2124. if (--count == 0) {
  2125. ch->ch_bd->state = BOARD_FAILED;
  2126. return;
  2127. }
  2128. udelay(10);
  2129. }
  2130. }
  2131. /*=======================================================================
  2132. *
  2133. * dgap_cmdw_ext - Sends a extended word command to the FEP.
  2134. *
  2135. * ch - Pointer to channel structure.
  2136. * cmd - Command to be sent.
  2137. * word - Integer containing word to be sent.
  2138. * ncmds - Wait until ncmds or fewer cmds are left
  2139. * in the cmd buffer before returning.
  2140. *
  2141. *=======================================================================*/
  2142. static void dgap_cmdw_ext(struct channel_t *ch, u16 cmd, u16 word, uint ncmds)
  2143. {
  2144. char __iomem *vaddr;
  2145. struct __iomem cm_t *cm_addr;
  2146. uint count;
  2147. uint n;
  2148. u16 head;
  2149. u16 tail;
  2150. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2151. return;
  2152. /*
  2153. * Check if board is still alive.
  2154. */
  2155. if (ch->ch_bd->state == BOARD_FAILED)
  2156. return;
  2157. /*
  2158. * Make sure the pointers are in range before
  2159. * writing to the FEP memory.
  2160. */
  2161. vaddr = ch->ch_bd->re_map_membase;
  2162. if (!vaddr)
  2163. return;
  2164. cm_addr = (struct cm_t __iomem *)(vaddr + CMDBUF);
  2165. head = readw(&cm_addr->cm_head);
  2166. /*
  2167. * Forget it if pointers out of range.
  2168. */
  2169. if (head >= (CMDMAX - CMDSTART) || (head & 03)) {
  2170. ch->ch_bd->state = BOARD_FAILED;
  2171. return;
  2172. }
  2173. /*
  2174. * Put the data in the circular command buffer.
  2175. */
  2176. /* Write an FF to tell the FEP that we want an extended command */
  2177. writeb((u8)0xff, (vaddr + head + CMDSTART + 0));
  2178. writeb((u8)ch->ch_portnum, (vaddr + head + CMDSTART + 1));
  2179. writew((u16)cmd, (vaddr + head + CMDSTART + 2));
  2180. /*
  2181. * If the second part of the command won't fit,
  2182. * put it at the beginning of the circular buffer.
  2183. */
  2184. if (((head + 4) >= ((CMDMAX - CMDSTART)) || (head & 03)))
  2185. writew((u16)word, (vaddr + CMDSTART));
  2186. else
  2187. writew((u16)word, (vaddr + head + CMDSTART + 4));
  2188. head = (head + 8) & (CMDMAX - CMDSTART - 4);
  2189. writew(head, &cm_addr->cm_head);
  2190. /*
  2191. * Wait if necessary before updating the head
  2192. * pointer to limit the number of outstanding
  2193. * commands to the FEP. If the time spent waiting
  2194. * is outlandish, declare the FEP dead.
  2195. */
  2196. for (count = dgap_count ;;) {
  2197. head = readw(&cm_addr->cm_head);
  2198. tail = readw(&cm_addr->cm_tail);
  2199. n = (head - tail) & (CMDMAX - CMDSTART - 4);
  2200. if (n <= ncmds * sizeof(struct cm_t))
  2201. break;
  2202. if (--count == 0) {
  2203. ch->ch_bd->state = BOARD_FAILED;
  2204. return;
  2205. }
  2206. udelay(10);
  2207. }
  2208. }
  2209. /*=======================================================================
  2210. *
  2211. * dgap_wmove - Write data to FEP buffer.
  2212. *
  2213. * ch - Pointer to channel structure.
  2214. * buf - Pointer to characters to be moved.
  2215. * cnt - Number of characters to move.
  2216. *
  2217. *=======================================================================*/
  2218. static void dgap_wmove(struct channel_t *ch, char *buf, uint cnt)
  2219. {
  2220. int n;
  2221. char __iomem *taddr;
  2222. struct bs_t __iomem *bs;
  2223. u16 head;
  2224. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2225. return;
  2226. /*
  2227. * Check parameters.
  2228. */
  2229. bs = ch->ch_bs;
  2230. head = readw(&bs->tx_head);
  2231. /*
  2232. * If pointers are out of range, just return.
  2233. */
  2234. if ((cnt > ch->ch_tsize) ||
  2235. (unsigned)(head - ch->ch_tstart) >= ch->ch_tsize)
  2236. return;
  2237. /*
  2238. * If the write wraps over the top of the circular buffer,
  2239. * move the portion up to the wrap point, and reset the
  2240. * pointers to the bottom.
  2241. */
  2242. n = ch->ch_tstart + ch->ch_tsize - head;
  2243. if (cnt >= n) {
  2244. cnt -= n;
  2245. taddr = ch->ch_taddr + head;
  2246. memcpy_toio(taddr, buf, n);
  2247. head = ch->ch_tstart;
  2248. buf += n;
  2249. }
  2250. /*
  2251. * Move rest of data.
  2252. */
  2253. taddr = ch->ch_taddr + head;
  2254. n = cnt;
  2255. memcpy_toio(taddr, buf, n);
  2256. head += cnt;
  2257. writew(head, &bs->tx_head);
  2258. }
  2259. /*
  2260. * Calls the firmware to reset this channel.
  2261. */
  2262. static void dgap_firmware_reset_port(struct channel_t *ch)
  2263. {
  2264. dgap_cmdb(ch, CHRESET, 0, 0, 0);
  2265. /*
  2266. * Now that the channel is reset, we need to make sure
  2267. * all the current settings get reapplied to the port
  2268. * in the firmware.
  2269. *
  2270. * So we will set the driver's cache of firmware
  2271. * settings all to 0, and then call param.
  2272. */
  2273. ch->ch_fepiflag = 0;
  2274. ch->ch_fepcflag = 0;
  2275. ch->ch_fepoflag = 0;
  2276. ch->ch_fepstartc = 0;
  2277. ch->ch_fepstopc = 0;
  2278. ch->ch_fepastartc = 0;
  2279. ch->ch_fepastopc = 0;
  2280. ch->ch_mostat = 0;
  2281. ch->ch_hflow = 0;
  2282. }
  2283. /*=======================================================================
  2284. *
  2285. * dgap_param - Set Digi parameters.
  2286. *
  2287. * struct tty_struct * - TTY for port.
  2288. *
  2289. *=======================================================================*/
  2290. static int dgap_param(struct channel_t *ch, struct board_t *bd, u32 un_type)
  2291. {
  2292. u16 head;
  2293. u16 cflag;
  2294. u16 iflag;
  2295. u8 mval;
  2296. u8 hflow;
  2297. /*
  2298. * If baud rate is zero, flush queues, and set mval to drop DTR.
  2299. */
  2300. if ((ch->ch_c_cflag & (CBAUD)) == 0) {
  2301. /* flush rx */
  2302. head = readw(&ch->ch_bs->rx_head);
  2303. writew(head, &ch->ch_bs->rx_tail);
  2304. /* flush tx */
  2305. head = readw(&ch->ch_bs->tx_head);
  2306. writew(head, &ch->ch_bs->tx_tail);
  2307. ch->ch_flags |= (CH_BAUD0);
  2308. /* Drop RTS and DTR */
  2309. ch->ch_mval &= ~(D_RTS(ch) | D_DTR(ch));
  2310. mval = D_DTR(ch) | D_RTS(ch);
  2311. ch->ch_baud_info = 0;
  2312. } else if (ch->ch_custom_speed && (bd->bd_flags & BD_FEP5PLUS)) {
  2313. /*
  2314. * Tell the fep to do the command
  2315. */
  2316. dgap_cmdw_ext(ch, 0xff01, ch->ch_custom_speed, 0);
  2317. /*
  2318. * Now go get from fep mem, what the fep
  2319. * believes the custom baud rate is.
  2320. */
  2321. ch->ch_custom_speed = dgap_get_custom_baud(ch);
  2322. ch->ch_baud_info = ch->ch_custom_speed;
  2323. /* Handle transition from B0 */
  2324. if (ch->ch_flags & CH_BAUD0) {
  2325. ch->ch_flags &= ~(CH_BAUD0);
  2326. ch->ch_mval |= (D_RTS(ch) | D_DTR(ch));
  2327. }
  2328. mval = D_DTR(ch) | D_RTS(ch);
  2329. } else {
  2330. /*
  2331. * Set baud rate, character size, and parity.
  2332. */
  2333. int iindex = 0;
  2334. int jindex = 0;
  2335. int baud = 0;
  2336. ulong bauds[4][16] = {
  2337. { /* slowbaud */
  2338. 0, 50, 75, 110,
  2339. 134, 150, 200, 300,
  2340. 600, 1200, 1800, 2400,
  2341. 4800, 9600, 19200, 38400 },
  2342. { /* slowbaud & CBAUDEX */
  2343. 0, 57600, 115200, 230400,
  2344. 460800, 150, 200, 921600,
  2345. 600, 1200, 1800, 2400,
  2346. 4800, 9600, 19200, 38400 },
  2347. { /* fastbaud */
  2348. 0, 57600, 76800, 115200,
  2349. 14400, 57600, 230400, 76800,
  2350. 115200, 230400, 28800, 460800,
  2351. 921600, 9600, 19200, 38400 },
  2352. { /* fastbaud & CBAUDEX */
  2353. 0, 57600, 115200, 230400,
  2354. 460800, 150, 200, 921600,
  2355. 600, 1200, 1800, 2400,
  2356. 4800, 9600, 19200, 38400 }
  2357. };
  2358. /*
  2359. * Only use the TXPrint baud rate if the
  2360. * terminal unit is NOT open
  2361. */
  2362. if (!(ch->ch_tun.un_flags & UN_ISOPEN) &&
  2363. un_type == DGAP_PRINT)
  2364. baud = C_BAUD(ch->ch_pun.un_tty) & 0xff;
  2365. else
  2366. baud = C_BAUD(ch->ch_tun.un_tty) & 0xff;
  2367. if (ch->ch_c_cflag & CBAUDEX)
  2368. iindex = 1;
  2369. if (ch->ch_digi.digi_flags & DIGI_FAST)
  2370. iindex += 2;
  2371. jindex = baud;
  2372. if ((iindex >= 0) && (iindex < 4) &&
  2373. (jindex >= 0) && (jindex < 16))
  2374. baud = bauds[iindex][jindex];
  2375. else
  2376. baud = 0;
  2377. if (baud == 0)
  2378. baud = 9600;
  2379. ch->ch_baud_info = baud;
  2380. /*
  2381. * CBAUD has bit position 0x1000 set these days to
  2382. * indicate Linux baud rate remap.
  2383. * We use a different bit assignment for high speed.
  2384. * Clear this bit out while grabbing the parts of
  2385. * "cflag" we want.
  2386. */
  2387. cflag = ch->ch_c_cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB |
  2388. CSTOPB | CSIZE);
  2389. /*
  2390. * HUPCL bit is used by FEP to indicate fast baud
  2391. * table is to be used.
  2392. */
  2393. if ((ch->ch_digi.digi_flags & DIGI_FAST) ||
  2394. (ch->ch_c_cflag & CBAUDEX))
  2395. cflag |= HUPCL;
  2396. if ((ch->ch_c_cflag & CBAUDEX) &&
  2397. !(ch->ch_digi.digi_flags & DIGI_FAST)) {
  2398. /*
  2399. * The below code is trying to guarantee that only
  2400. * baud rates 115200, 230400, 460800, 921600 are
  2401. * remapped. We use exclusive or because the various
  2402. * baud rates share common bit positions and therefore
  2403. * can't be tested for easily.
  2404. */
  2405. tcflag_t tcflag = (ch->ch_c_cflag & CBAUD) | CBAUDEX;
  2406. int baudpart = 0;
  2407. /*
  2408. * Map high speed requests to index
  2409. * into FEP's baud table
  2410. */
  2411. switch (tcflag) {
  2412. case B57600:
  2413. baudpart = 1;
  2414. break;
  2415. #ifdef B76800
  2416. case B76800:
  2417. baudpart = 2;
  2418. break;
  2419. #endif
  2420. case B115200:
  2421. baudpart = 3;
  2422. break;
  2423. case B230400:
  2424. baudpart = 9;
  2425. break;
  2426. case B460800:
  2427. baudpart = 11;
  2428. break;
  2429. #ifdef B921600
  2430. case B921600:
  2431. baudpart = 12;
  2432. break;
  2433. #endif
  2434. default:
  2435. baudpart = 0;
  2436. }
  2437. if (baudpart)
  2438. cflag = (cflag & ~(CBAUD | CBAUDEX)) | baudpart;
  2439. }
  2440. cflag &= 0xffff;
  2441. if (cflag != ch->ch_fepcflag) {
  2442. ch->ch_fepcflag = (u16)(cflag & 0xffff);
  2443. /*
  2444. * Okay to have channel and board
  2445. * locks held calling this
  2446. */
  2447. dgap_cmdw(ch, SCFLAG, (u16)cflag, 0);
  2448. }
  2449. /* Handle transition from B0 */
  2450. if (ch->ch_flags & CH_BAUD0) {
  2451. ch->ch_flags &= ~(CH_BAUD0);
  2452. ch->ch_mval |= (D_RTS(ch) | D_DTR(ch));
  2453. }
  2454. mval = D_DTR(ch) | D_RTS(ch);
  2455. }
  2456. /*
  2457. * Get input flags.
  2458. */
  2459. iflag = ch->ch_c_iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
  2460. INPCK | ISTRIP | IXON | IXANY | IXOFF);
  2461. if ((ch->ch_startc == _POSIX_VDISABLE) ||
  2462. (ch->ch_stopc == _POSIX_VDISABLE)) {
  2463. iflag &= ~(IXON | IXOFF);
  2464. ch->ch_c_iflag &= ~(IXON | IXOFF);
  2465. }
  2466. /*
  2467. * Only the IBM Xr card can switch between
  2468. * 232 and 422 modes on the fly
  2469. */
  2470. if (bd->device == PCI_DEV_XR_IBM_DID) {
  2471. if (ch->ch_digi.digi_flags & DIGI_422)
  2472. dgap_cmdb(ch, SCOMMODE, MODE_422, 0, 0);
  2473. else
  2474. dgap_cmdb(ch, SCOMMODE, MODE_232, 0, 0);
  2475. }
  2476. if (ch->ch_digi.digi_flags & DIGI_ALTPIN)
  2477. iflag |= IALTPIN;
  2478. if (iflag != ch->ch_fepiflag) {
  2479. ch->ch_fepiflag = iflag;
  2480. /* Okay to have channel and board locks held calling this */
  2481. dgap_cmdw(ch, SIFLAG, (u16)ch->ch_fepiflag, 0);
  2482. }
  2483. /*
  2484. * Select hardware handshaking.
  2485. */
  2486. hflow = 0;
  2487. if (ch->ch_c_cflag & CRTSCTS)
  2488. hflow |= (D_RTS(ch) | D_CTS(ch));
  2489. if (ch->ch_digi.digi_flags & RTSPACE)
  2490. hflow |= D_RTS(ch);
  2491. if (ch->ch_digi.digi_flags & DTRPACE)
  2492. hflow |= D_DTR(ch);
  2493. if (ch->ch_digi.digi_flags & CTSPACE)
  2494. hflow |= D_CTS(ch);
  2495. if (ch->ch_digi.digi_flags & DSRPACE)
  2496. hflow |= D_DSR(ch);
  2497. if (ch->ch_digi.digi_flags & DCDPACE)
  2498. hflow |= D_CD(ch);
  2499. if (hflow != ch->ch_hflow) {
  2500. ch->ch_hflow = hflow;
  2501. /* Okay to have channel and board locks held calling this */
  2502. dgap_cmdb(ch, SHFLOW, (u8)hflow, 0xff, 0);
  2503. }
  2504. /*
  2505. * Set RTS and/or DTR Toggle if needed,
  2506. * but only if product is FEP5+ based.
  2507. */
  2508. if (bd->bd_flags & BD_FEP5PLUS) {
  2509. u16 hflow2 = 0;
  2510. if (ch->ch_digi.digi_flags & DIGI_RTS_TOGGLE)
  2511. hflow2 |= (D_RTS(ch));
  2512. if (ch->ch_digi.digi_flags & DIGI_DTR_TOGGLE)
  2513. hflow2 |= (D_DTR(ch));
  2514. dgap_cmdw_ext(ch, 0xff03, hflow2, 0);
  2515. }
  2516. /*
  2517. * Set modem control lines.
  2518. */
  2519. mval ^= ch->ch_mforce & (mval ^ ch->ch_mval);
  2520. if (ch->ch_mostat ^ mval) {
  2521. ch->ch_mostat = mval;
  2522. /* Okay to have channel and board locks held calling this */
  2523. dgap_cmdb(ch, SMODEM, (u8)mval, D_RTS(ch) | D_DTR(ch), 0);
  2524. }
  2525. /*
  2526. * Read modem signals, and then call carrier function.
  2527. */
  2528. ch->ch_mistat = readb(&ch->ch_bs->m_stat);
  2529. dgap_carrier(ch);
  2530. /*
  2531. * Set the start and stop characters.
  2532. */
  2533. if (ch->ch_startc != ch->ch_fepstartc ||
  2534. ch->ch_stopc != ch->ch_fepstopc) {
  2535. ch->ch_fepstartc = ch->ch_startc;
  2536. ch->ch_fepstopc = ch->ch_stopc;
  2537. /* Okay to have channel and board locks held calling this */
  2538. dgap_cmdb(ch, SFLOWC, ch->ch_fepstartc, ch->ch_fepstopc, 0);
  2539. }
  2540. /*
  2541. * Set the Auxiliary start and stop characters.
  2542. */
  2543. if (ch->ch_astartc != ch->ch_fepastartc ||
  2544. ch->ch_astopc != ch->ch_fepastopc) {
  2545. ch->ch_fepastartc = ch->ch_astartc;
  2546. ch->ch_fepastopc = ch->ch_astopc;
  2547. /* Okay to have channel and board locks held calling this */
  2548. dgap_cmdb(ch, SAFLOWC, ch->ch_fepastartc, ch->ch_fepastopc, 0);
  2549. }
  2550. return 0;
  2551. }
  2552. /*
  2553. * dgap_block_til_ready()
  2554. *
  2555. * Wait for DCD, if needed.
  2556. */
  2557. static int dgap_block_til_ready(struct tty_struct *tty, struct file *file,
  2558. struct channel_t *ch)
  2559. {
  2560. int retval = 0;
  2561. struct un_t *un;
  2562. ulong lock_flags;
  2563. uint old_flags;
  2564. int sleep_on_un_flags;
  2565. if (!tty || tty->magic != TTY_MAGIC || !file || !ch ||
  2566. ch->magic != DGAP_CHANNEL_MAGIC)
  2567. return -EIO;
  2568. un = tty->driver_data;
  2569. if (!un || un->magic != DGAP_UNIT_MAGIC)
  2570. return -EIO;
  2571. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  2572. ch->ch_wopen++;
  2573. /* Loop forever */
  2574. while (1) {
  2575. sleep_on_un_flags = 0;
  2576. /*
  2577. * If board has failed somehow during our sleep,
  2578. * bail with error.
  2579. */
  2580. if (ch->ch_bd->state == BOARD_FAILED) {
  2581. retval = -EIO;
  2582. break;
  2583. }
  2584. /* If tty was hung up, break out of loop and set error. */
  2585. if (tty_hung_up_p(file)) {
  2586. retval = -EAGAIN;
  2587. break;
  2588. }
  2589. /*
  2590. * If either unit is in the middle of the fragile part of close,
  2591. * we just cannot touch the channel safely.
  2592. * Go back to sleep, knowing that when the channel can be
  2593. * touched safely, the close routine will signal the
  2594. * ch_wait_flags to wake us back up.
  2595. */
  2596. if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) &
  2597. UN_CLOSING)) {
  2598. /*
  2599. * Our conditions to leave cleanly and happily:
  2600. * 1) NONBLOCKING on the tty is set.
  2601. * 2) CLOCAL is set.
  2602. * 3) DCD (fake or real) is active.
  2603. */
  2604. if (file->f_flags & O_NONBLOCK)
  2605. break;
  2606. if (tty->flags & (1 << TTY_IO_ERROR))
  2607. break;
  2608. if (ch->ch_flags & CH_CD)
  2609. break;
  2610. if (ch->ch_flags & CH_FCAR)
  2611. break;
  2612. } else {
  2613. sleep_on_un_flags = 1;
  2614. }
  2615. /*
  2616. * If there is a signal pending, the user probably
  2617. * interrupted (ctrl-c) us.
  2618. * Leave loop with error set.
  2619. */
  2620. if (signal_pending(current)) {
  2621. retval = -ERESTARTSYS;
  2622. break;
  2623. }
  2624. /*
  2625. * Store the flags before we let go of channel lock
  2626. */
  2627. if (sleep_on_un_flags)
  2628. old_flags = ch->ch_tun.un_flags | ch->ch_pun.un_flags;
  2629. else
  2630. old_flags = ch->ch_flags;
  2631. /*
  2632. * Let go of channel lock before calling schedule.
  2633. * Our poller will get any FEP events and wake us up when DCD
  2634. * eventually goes active.
  2635. */
  2636. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  2637. /*
  2638. * Wait for something in the flags to change
  2639. * from the current value.
  2640. */
  2641. if (sleep_on_un_flags) {
  2642. retval = wait_event_interruptible(un->un_flags_wait,
  2643. (old_flags != (ch->ch_tun.un_flags |
  2644. ch->ch_pun.un_flags)));
  2645. } else {
  2646. retval = wait_event_interruptible(ch->ch_flags_wait,
  2647. (old_flags != ch->ch_flags));
  2648. }
  2649. /*
  2650. * We got woken up for some reason.
  2651. * Before looping around, grab our channel lock.
  2652. */
  2653. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  2654. }
  2655. ch->ch_wopen--;
  2656. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  2657. return retval;
  2658. }
  2659. /*
  2660. * dgap_tty_flush_buffer()
  2661. *
  2662. * Flush Tx buffer (make in == out)
  2663. */
  2664. static void dgap_tty_flush_buffer(struct tty_struct *tty)
  2665. {
  2666. struct board_t *bd;
  2667. struct channel_t *ch;
  2668. struct un_t *un;
  2669. ulong lock_flags;
  2670. ulong lock_flags2;
  2671. u16 head;
  2672. if (!tty || tty->magic != TTY_MAGIC)
  2673. return;
  2674. un = tty->driver_data;
  2675. if (!un || un->magic != DGAP_UNIT_MAGIC)
  2676. return;
  2677. ch = un->un_ch;
  2678. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2679. return;
  2680. bd = ch->ch_bd;
  2681. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  2682. return;
  2683. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  2684. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  2685. ch->ch_flags &= ~CH_STOP;
  2686. head = readw(&ch->ch_bs->tx_head);
  2687. dgap_cmdw(ch, FLUSHTX, (u16)head, 0);
  2688. dgap_cmdw(ch, RESUMETX, 0, 0);
  2689. if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
  2690. ch->ch_tun.un_flags &= ~(UN_LOW | UN_EMPTY);
  2691. wake_up_interruptible(&ch->ch_tun.un_flags_wait);
  2692. }
  2693. if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) {
  2694. ch->ch_pun.un_flags &= ~(UN_LOW | UN_EMPTY);
  2695. wake_up_interruptible(&ch->ch_pun.un_flags_wait);
  2696. }
  2697. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  2698. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  2699. if (waitqueue_active(&tty->write_wait))
  2700. wake_up_interruptible(&tty->write_wait);
  2701. tty_wakeup(tty);
  2702. }
  2703. /*
  2704. * dgap_tty_hangup()
  2705. *
  2706. * Hangup the port. Like a close, but don't wait for output to drain.
  2707. */
  2708. static void dgap_tty_hangup(struct tty_struct *tty)
  2709. {
  2710. struct board_t *bd;
  2711. struct channel_t *ch;
  2712. struct un_t *un;
  2713. if (!tty || tty->magic != TTY_MAGIC)
  2714. return;
  2715. un = tty->driver_data;
  2716. if (!un || un->magic != DGAP_UNIT_MAGIC)
  2717. return;
  2718. ch = un->un_ch;
  2719. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2720. return;
  2721. bd = ch->ch_bd;
  2722. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  2723. return;
  2724. /* flush the transmit queues */
  2725. dgap_tty_flush_buffer(tty);
  2726. }
  2727. /*
  2728. * dgap_tty_chars_in_buffer()
  2729. *
  2730. * Return number of characters that have not been transmitted yet.
  2731. *
  2732. * This routine is used by the line discipline to determine if there
  2733. * is data waiting to be transmitted/drained/flushed or not.
  2734. */
  2735. static int dgap_tty_chars_in_buffer(struct tty_struct *tty)
  2736. {
  2737. struct board_t *bd;
  2738. struct channel_t *ch;
  2739. struct un_t *un;
  2740. struct bs_t __iomem *bs;
  2741. u8 tbusy;
  2742. uint chars;
  2743. u16 thead, ttail, tmask, chead, ctail;
  2744. ulong lock_flags = 0;
  2745. ulong lock_flags2 = 0;
  2746. if (!tty)
  2747. return 0;
  2748. un = tty->driver_data;
  2749. if (!un || un->magic != DGAP_UNIT_MAGIC)
  2750. return 0;
  2751. ch = un->un_ch;
  2752. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2753. return 0;
  2754. bd = ch->ch_bd;
  2755. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  2756. return 0;
  2757. bs = ch->ch_bs;
  2758. if (!bs)
  2759. return 0;
  2760. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  2761. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  2762. tmask = (ch->ch_tsize - 1);
  2763. /* Get Transmit queue pointers */
  2764. thead = readw(&bs->tx_head) & tmask;
  2765. ttail = readw(&bs->tx_tail) & tmask;
  2766. /* Get tbusy flag */
  2767. tbusy = readb(&bs->tbusy);
  2768. /* Get Command queue pointers */
  2769. chead = readw(&ch->ch_cm->cm_head);
  2770. ctail = readw(&ch->ch_cm->cm_tail);
  2771. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  2772. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  2773. /*
  2774. * The only way we know for sure if there is no pending
  2775. * data left to be transferred, is if:
  2776. * 1) Transmit head and tail are equal (empty).
  2777. * 2) Command queue head and tail are equal (empty).
  2778. * 3) The "TBUSY" flag is 0. (Transmitter not busy).
  2779. */
  2780. if ((ttail == thead) && (tbusy == 0) && (chead == ctail)) {
  2781. chars = 0;
  2782. } else {
  2783. if (thead >= ttail)
  2784. chars = thead - ttail;
  2785. else
  2786. chars = thead - ttail + ch->ch_tsize;
  2787. /*
  2788. * Fudge factor here.
  2789. * If chars is zero, we know that the command queue had
  2790. * something in it or tbusy was set. Because we cannot
  2791. * be sure if there is still some data to be transmitted,
  2792. * lets lie, and tell ld we have 1 byte left.
  2793. */
  2794. if (chars == 0) {
  2795. /*
  2796. * If TBUSY is still set, and our tx buffers are empty,
  2797. * force the firmware to send me another wakeup after
  2798. * TBUSY has been cleared.
  2799. */
  2800. if (tbusy != 0) {
  2801. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  2802. un->un_flags |= UN_EMPTY;
  2803. writeb(1, &bs->iempty);
  2804. spin_unlock_irqrestore(&ch->ch_lock,
  2805. lock_flags);
  2806. }
  2807. chars = 1;
  2808. }
  2809. }
  2810. return chars;
  2811. }
  2812. static int dgap_wait_for_drain(struct tty_struct *tty)
  2813. {
  2814. struct channel_t *ch;
  2815. struct un_t *un;
  2816. struct bs_t __iomem *bs;
  2817. int ret = 0;
  2818. uint count = 1;
  2819. ulong lock_flags = 0;
  2820. if (!tty || tty->magic != TTY_MAGIC)
  2821. return -EIO;
  2822. un = tty->driver_data;
  2823. if (!un || un->magic != DGAP_UNIT_MAGIC)
  2824. return -EIO;
  2825. ch = un->un_ch;
  2826. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2827. return -EIO;
  2828. bs = ch->ch_bs;
  2829. if (!bs)
  2830. return -EIO;
  2831. /* Loop until data is drained */
  2832. while (count != 0) {
  2833. count = dgap_tty_chars_in_buffer(tty);
  2834. if (count == 0)
  2835. break;
  2836. /* Set flag waiting for drain */
  2837. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  2838. un->un_flags |= UN_EMPTY;
  2839. writeb(1, &bs->iempty);
  2840. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  2841. /* Go to sleep till we get woken up */
  2842. ret = wait_event_interruptible(un->un_flags_wait,
  2843. ((un->un_flags & UN_EMPTY) == 0));
  2844. /* If ret is non-zero, user ctrl-c'ed us */
  2845. if (ret)
  2846. break;
  2847. }
  2848. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  2849. un->un_flags &= ~(UN_EMPTY);
  2850. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  2851. return ret;
  2852. }
  2853. /*
  2854. * dgap_maxcps_room
  2855. *
  2856. * Reduces bytes_available to the max number of characters
  2857. * that can be sent currently given the maxcps value, and
  2858. * returns the new bytes_available. This only affects printer
  2859. * output.
  2860. */
  2861. static int dgap_maxcps_room(struct channel_t *ch, struct un_t *un,
  2862. int bytes_available)
  2863. {
  2864. /*
  2865. * If its not the Transparent print device, return
  2866. * the full data amount.
  2867. */
  2868. if (un->un_type != DGAP_PRINT)
  2869. return bytes_available;
  2870. if (ch->ch_digi.digi_maxcps > 0 && ch->ch_digi.digi_bufsize > 0) {
  2871. int cps_limit = 0;
  2872. unsigned long current_time = jiffies;
  2873. unsigned long buffer_time = current_time +
  2874. (HZ * ch->ch_digi.digi_bufsize) /
  2875. ch->ch_digi.digi_maxcps;
  2876. if (ch->ch_cpstime < current_time) {
  2877. /* buffer is empty */
  2878. ch->ch_cpstime = current_time; /* reset ch_cpstime */
  2879. cps_limit = ch->ch_digi.digi_bufsize;
  2880. } else if (ch->ch_cpstime < buffer_time) {
  2881. /* still room in the buffer */
  2882. cps_limit = ((buffer_time - ch->ch_cpstime) *
  2883. ch->ch_digi.digi_maxcps) / HZ;
  2884. } else {
  2885. /* no room in the buffer */
  2886. cps_limit = 0;
  2887. }
  2888. bytes_available = min(cps_limit, bytes_available);
  2889. }
  2890. return bytes_available;
  2891. }
  2892. static inline void dgap_set_firmware_event(struct un_t *un, unsigned int event)
  2893. {
  2894. struct channel_t *ch;
  2895. struct bs_t __iomem *bs;
  2896. if (!un || un->magic != DGAP_UNIT_MAGIC)
  2897. return;
  2898. ch = un->un_ch;
  2899. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2900. return;
  2901. bs = ch->ch_bs;
  2902. if (!bs)
  2903. return;
  2904. if ((event & UN_LOW) != 0) {
  2905. if ((un->un_flags & UN_LOW) == 0) {
  2906. un->un_flags |= UN_LOW;
  2907. writeb(1, &bs->ilow);
  2908. }
  2909. }
  2910. if ((event & UN_LOW) != 0) {
  2911. if ((un->un_flags & UN_EMPTY) == 0) {
  2912. un->un_flags |= UN_EMPTY;
  2913. writeb(1, &bs->iempty);
  2914. }
  2915. }
  2916. }
  2917. /*
  2918. * dgap_tty_write_room()
  2919. *
  2920. * Return space available in Tx buffer
  2921. */
  2922. static int dgap_tty_write_room(struct tty_struct *tty)
  2923. {
  2924. struct channel_t *ch;
  2925. struct un_t *un;
  2926. struct bs_t __iomem *bs;
  2927. u16 head, tail, tmask;
  2928. int ret;
  2929. ulong lock_flags = 0;
  2930. if (!tty)
  2931. return 0;
  2932. un = tty->driver_data;
  2933. if (!un || un->magic != DGAP_UNIT_MAGIC)
  2934. return 0;
  2935. ch = un->un_ch;
  2936. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2937. return 0;
  2938. bs = ch->ch_bs;
  2939. if (!bs)
  2940. return 0;
  2941. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  2942. tmask = ch->ch_tsize - 1;
  2943. head = readw(&bs->tx_head) & tmask;
  2944. tail = readw(&bs->tx_tail) & tmask;
  2945. ret = tail - head - 1;
  2946. if (ret < 0)
  2947. ret += ch->ch_tsize;
  2948. /* Limit printer to maxcps */
  2949. ret = dgap_maxcps_room(ch, un, ret);
  2950. /*
  2951. * If we are printer device, leave space for
  2952. * possibly both the on and off strings.
  2953. */
  2954. if (un->un_type == DGAP_PRINT) {
  2955. if (!(ch->ch_flags & CH_PRON))
  2956. ret -= ch->ch_digi.digi_onlen;
  2957. ret -= ch->ch_digi.digi_offlen;
  2958. } else {
  2959. if (ch->ch_flags & CH_PRON)
  2960. ret -= ch->ch_digi.digi_offlen;
  2961. }
  2962. if (ret < 0)
  2963. ret = 0;
  2964. /*
  2965. * Schedule FEP to wake us up if needed.
  2966. *
  2967. * TODO: This might be overkill...
  2968. * Do we really need to schedule callbacks from the FEP
  2969. * in every case? Can we get smarter based on ret?
  2970. */
  2971. dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
  2972. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  2973. return ret;
  2974. }
  2975. /*
  2976. * dgap_tty_write()
  2977. *
  2978. * Take data from the user or kernel and send it out to the FEP.
  2979. * In here exists all the Transparent Print magic as well.
  2980. */
  2981. static int dgap_tty_write(struct tty_struct *tty, const unsigned char *buf,
  2982. int count)
  2983. {
  2984. struct channel_t *ch;
  2985. struct un_t *un;
  2986. struct bs_t __iomem *bs;
  2987. char __iomem *vaddr;
  2988. u16 head, tail, tmask, remain;
  2989. int bufcount, n;
  2990. ulong lock_flags;
  2991. if (!tty)
  2992. return 0;
  2993. un = tty->driver_data;
  2994. if (!un || un->magic != DGAP_UNIT_MAGIC)
  2995. return 0;
  2996. ch = un->un_ch;
  2997. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  2998. return 0;
  2999. bs = ch->ch_bs;
  3000. if (!bs)
  3001. return 0;
  3002. if (!count)
  3003. return 0;
  3004. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  3005. /* Get our space available for the channel from the board */
  3006. tmask = ch->ch_tsize - 1;
  3007. head = readw(&(bs->tx_head)) & tmask;
  3008. tail = readw(&(bs->tx_tail)) & tmask;
  3009. bufcount = tail - head - 1;
  3010. if (bufcount < 0)
  3011. bufcount += ch->ch_tsize;
  3012. /*
  3013. * Limit printer output to maxcps overall, with bursts allowed
  3014. * up to bufsize characters.
  3015. */
  3016. bufcount = dgap_maxcps_room(ch, un, bufcount);
  3017. /*
  3018. * Take minimum of what the user wants to send, and the
  3019. * space available in the FEP buffer.
  3020. */
  3021. count = min(count, bufcount);
  3022. /*
  3023. * Bail if no space left.
  3024. */
  3025. if (count <= 0) {
  3026. dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
  3027. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3028. return 0;
  3029. }
  3030. /*
  3031. * Output the printer ON string, if we are in terminal mode, but
  3032. * need to be in printer mode.
  3033. */
  3034. if ((un->un_type == DGAP_PRINT) && !(ch->ch_flags & CH_PRON)) {
  3035. dgap_wmove(ch, ch->ch_digi.digi_onstr,
  3036. (int)ch->ch_digi.digi_onlen);
  3037. head = readw(&bs->tx_head) & tmask;
  3038. ch->ch_flags |= CH_PRON;
  3039. }
  3040. /*
  3041. * On the other hand, output the printer OFF string, if we are
  3042. * currently in printer mode, but need to output to the terminal.
  3043. */
  3044. if ((un->un_type != DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
  3045. dgap_wmove(ch, ch->ch_digi.digi_offstr,
  3046. (int)ch->ch_digi.digi_offlen);
  3047. head = readw(&bs->tx_head) & tmask;
  3048. ch->ch_flags &= ~CH_PRON;
  3049. }
  3050. n = count;
  3051. /*
  3052. * If the write wraps over the top of the circular buffer,
  3053. * move the portion up to the wrap point, and reset the
  3054. * pointers to the bottom.
  3055. */
  3056. remain = ch->ch_tstart + ch->ch_tsize - head;
  3057. if (n >= remain) {
  3058. n -= remain;
  3059. vaddr = ch->ch_taddr + head;
  3060. memcpy_toio(vaddr, (u8 *)buf, remain);
  3061. head = ch->ch_tstart;
  3062. buf += remain;
  3063. }
  3064. if (n > 0) {
  3065. /*
  3066. * Move rest of data.
  3067. */
  3068. vaddr = ch->ch_taddr + head;
  3069. remain = n;
  3070. memcpy_toio(vaddr, (u8 *)buf, remain);
  3071. head += remain;
  3072. }
  3073. if (count) {
  3074. ch->ch_txcount += count;
  3075. head &= tmask;
  3076. writew(head, &bs->tx_head);
  3077. }
  3078. dgap_set_firmware_event(un, UN_LOW | UN_EMPTY);
  3079. /*
  3080. * If this is the print device, and the
  3081. * printer is still on, we need to turn it
  3082. * off before going idle. If the buffer is
  3083. * non-empty, wait until it goes empty.
  3084. * Otherwise turn it off right now.
  3085. */
  3086. if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
  3087. tail = readw(&bs->tx_tail) & tmask;
  3088. if (tail != head) {
  3089. un->un_flags |= UN_EMPTY;
  3090. writeb(1, &bs->iempty);
  3091. } else {
  3092. dgap_wmove(ch, ch->ch_digi.digi_offstr,
  3093. (int)ch->ch_digi.digi_offlen);
  3094. head = readw(&bs->tx_head) & tmask;
  3095. ch->ch_flags &= ~CH_PRON;
  3096. }
  3097. }
  3098. /* Update printer buffer empty time. */
  3099. if ((un->un_type == DGAP_PRINT) && (ch->ch_digi.digi_maxcps > 0)
  3100. && (ch->ch_digi.digi_bufsize > 0)) {
  3101. ch->ch_cpstime += (HZ * count) / ch->ch_digi.digi_maxcps;
  3102. }
  3103. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3104. return count;
  3105. }
  3106. /*
  3107. * dgap_tty_put_char()
  3108. *
  3109. * Put a character into ch->ch_buf
  3110. *
  3111. * - used by the line discipline for OPOST processing
  3112. */
  3113. static int dgap_tty_put_char(struct tty_struct *tty, unsigned char c)
  3114. {
  3115. /*
  3116. * Simply call tty_write.
  3117. */
  3118. dgap_tty_write(tty, &c, 1);
  3119. return 1;
  3120. }
  3121. /*
  3122. * Return modem signals to ld.
  3123. */
  3124. static int dgap_tty_tiocmget(struct tty_struct *tty)
  3125. {
  3126. struct channel_t *ch;
  3127. struct un_t *un;
  3128. int result;
  3129. u8 mstat;
  3130. ulong lock_flags;
  3131. if (!tty || tty->magic != TTY_MAGIC)
  3132. return -EIO;
  3133. un = tty->driver_data;
  3134. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3135. return -EIO;
  3136. ch = un->un_ch;
  3137. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3138. return -EIO;
  3139. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  3140. mstat = readb(&ch->ch_bs->m_stat);
  3141. /* Append any outbound signals that might be pending... */
  3142. mstat |= ch->ch_mostat;
  3143. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3144. result = 0;
  3145. if (mstat & D_DTR(ch))
  3146. result |= TIOCM_DTR;
  3147. if (mstat & D_RTS(ch))
  3148. result |= TIOCM_RTS;
  3149. if (mstat & D_CTS(ch))
  3150. result |= TIOCM_CTS;
  3151. if (mstat & D_DSR(ch))
  3152. result |= TIOCM_DSR;
  3153. if (mstat & D_RI(ch))
  3154. result |= TIOCM_RI;
  3155. if (mstat & D_CD(ch))
  3156. result |= TIOCM_CD;
  3157. return result;
  3158. }
  3159. /*
  3160. * dgap_tty_tiocmset()
  3161. *
  3162. * Set modem signals, called by ld.
  3163. */
  3164. static int dgap_tty_tiocmset(struct tty_struct *tty,
  3165. unsigned int set, unsigned int clear)
  3166. {
  3167. struct board_t *bd;
  3168. struct channel_t *ch;
  3169. struct un_t *un;
  3170. ulong lock_flags;
  3171. ulong lock_flags2;
  3172. if (!tty || tty->magic != TTY_MAGIC)
  3173. return -EIO;
  3174. un = tty->driver_data;
  3175. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3176. return -EIO;
  3177. ch = un->un_ch;
  3178. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3179. return -EIO;
  3180. bd = ch->ch_bd;
  3181. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3182. return -EIO;
  3183. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3184. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3185. if (set & TIOCM_RTS) {
  3186. ch->ch_mforce |= D_RTS(ch);
  3187. ch->ch_mval |= D_RTS(ch);
  3188. }
  3189. if (set & TIOCM_DTR) {
  3190. ch->ch_mforce |= D_DTR(ch);
  3191. ch->ch_mval |= D_DTR(ch);
  3192. }
  3193. if (clear & TIOCM_RTS) {
  3194. ch->ch_mforce |= D_RTS(ch);
  3195. ch->ch_mval &= ~(D_RTS(ch));
  3196. }
  3197. if (clear & TIOCM_DTR) {
  3198. ch->ch_mforce |= D_DTR(ch);
  3199. ch->ch_mval &= ~(D_DTR(ch));
  3200. }
  3201. dgap_param(ch, bd, un->un_type);
  3202. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3203. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3204. return 0;
  3205. }
  3206. /*
  3207. * dgap_tty_send_break()
  3208. *
  3209. * Send a Break, called by ld.
  3210. */
  3211. static int dgap_tty_send_break(struct tty_struct *tty, int msec)
  3212. {
  3213. struct board_t *bd;
  3214. struct channel_t *ch;
  3215. struct un_t *un;
  3216. ulong lock_flags;
  3217. ulong lock_flags2;
  3218. if (!tty || tty->magic != TTY_MAGIC)
  3219. return -EIO;
  3220. un = tty->driver_data;
  3221. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3222. return -EIO;
  3223. ch = un->un_ch;
  3224. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3225. return -EIO;
  3226. bd = ch->ch_bd;
  3227. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3228. return -EIO;
  3229. switch (msec) {
  3230. case -1:
  3231. msec = 0xFFFF;
  3232. break;
  3233. case 0:
  3234. msec = 1;
  3235. break;
  3236. default:
  3237. msec /= 10;
  3238. break;
  3239. }
  3240. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3241. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3242. #if 0
  3243. dgap_cmdw(ch, SBREAK, (u16) SBREAK_TIME, 0);
  3244. #endif
  3245. dgap_cmdw(ch, SBREAK, (u16)msec, 0);
  3246. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3247. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3248. return 0;
  3249. }
  3250. /*
  3251. * dgap_tty_wait_until_sent()
  3252. *
  3253. * wait until data has been transmitted, called by ld.
  3254. */
  3255. static void dgap_tty_wait_until_sent(struct tty_struct *tty, int timeout)
  3256. {
  3257. dgap_wait_for_drain(tty);
  3258. }
  3259. /*
  3260. * dgap_send_xchar()
  3261. *
  3262. * send a high priority character, called by ld.
  3263. */
  3264. static void dgap_tty_send_xchar(struct tty_struct *tty, char c)
  3265. {
  3266. struct board_t *bd;
  3267. struct channel_t *ch;
  3268. struct un_t *un;
  3269. ulong lock_flags;
  3270. ulong lock_flags2;
  3271. if (!tty || tty->magic != TTY_MAGIC)
  3272. return;
  3273. un = tty->driver_data;
  3274. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3275. return;
  3276. ch = un->un_ch;
  3277. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3278. return;
  3279. bd = ch->ch_bd;
  3280. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3281. return;
  3282. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3283. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3284. /*
  3285. * This is technically what we should do.
  3286. * However, the NIST tests specifically want
  3287. * to see each XON or XOFF character that it
  3288. * sends, so lets just send each character
  3289. * by hand...
  3290. */
  3291. #if 0
  3292. if (c == STOP_CHAR(tty))
  3293. dgap_cmdw(ch, RPAUSE, 0, 0);
  3294. else if (c == START_CHAR(tty))
  3295. dgap_cmdw(ch, RRESUME, 0, 0);
  3296. else
  3297. dgap_wmove(ch, &c, 1);
  3298. #else
  3299. dgap_wmove(ch, &c, 1);
  3300. #endif
  3301. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3302. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3303. }
  3304. /*
  3305. * Return modem signals to ld.
  3306. */
  3307. static int dgap_get_modem_info(struct channel_t *ch, unsigned int __user *value)
  3308. {
  3309. int result;
  3310. u8 mstat;
  3311. ulong lock_flags;
  3312. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  3313. mstat = readb(&ch->ch_bs->m_stat);
  3314. /* Append any outbound signals that might be pending... */
  3315. mstat |= ch->ch_mostat;
  3316. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3317. result = 0;
  3318. if (mstat & D_DTR(ch))
  3319. result |= TIOCM_DTR;
  3320. if (mstat & D_RTS(ch))
  3321. result |= TIOCM_RTS;
  3322. if (mstat & D_CTS(ch))
  3323. result |= TIOCM_CTS;
  3324. if (mstat & D_DSR(ch))
  3325. result |= TIOCM_DSR;
  3326. if (mstat & D_RI(ch))
  3327. result |= TIOCM_RI;
  3328. if (mstat & D_CD(ch))
  3329. result |= TIOCM_CD;
  3330. return put_user(result, value);
  3331. }
  3332. /*
  3333. * dgap_set_modem_info()
  3334. *
  3335. * Set modem signals, called by ld.
  3336. */
  3337. static int dgap_set_modem_info(struct channel_t *ch, struct board_t *bd,
  3338. struct un_t *un, unsigned int command,
  3339. unsigned int __user *value)
  3340. {
  3341. int ret;
  3342. unsigned int arg;
  3343. ulong lock_flags;
  3344. ulong lock_flags2;
  3345. ret = get_user(arg, value);
  3346. if (ret)
  3347. return ret;
  3348. switch (command) {
  3349. case TIOCMBIS:
  3350. if (arg & TIOCM_RTS) {
  3351. ch->ch_mforce |= D_RTS(ch);
  3352. ch->ch_mval |= D_RTS(ch);
  3353. }
  3354. if (arg & TIOCM_DTR) {
  3355. ch->ch_mforce |= D_DTR(ch);
  3356. ch->ch_mval |= D_DTR(ch);
  3357. }
  3358. break;
  3359. case TIOCMBIC:
  3360. if (arg & TIOCM_RTS) {
  3361. ch->ch_mforce |= D_RTS(ch);
  3362. ch->ch_mval &= ~(D_RTS(ch));
  3363. }
  3364. if (arg & TIOCM_DTR) {
  3365. ch->ch_mforce |= D_DTR(ch);
  3366. ch->ch_mval &= ~(D_DTR(ch));
  3367. }
  3368. break;
  3369. case TIOCMSET:
  3370. ch->ch_mforce = D_DTR(ch) | D_RTS(ch);
  3371. if (arg & TIOCM_RTS)
  3372. ch->ch_mval |= D_RTS(ch);
  3373. else
  3374. ch->ch_mval &= ~(D_RTS(ch));
  3375. if (arg & TIOCM_DTR)
  3376. ch->ch_mval |= (D_DTR(ch));
  3377. else
  3378. ch->ch_mval &= ~(D_DTR(ch));
  3379. break;
  3380. default:
  3381. return -EINVAL;
  3382. }
  3383. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3384. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3385. dgap_param(ch, bd, un->un_type);
  3386. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3387. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3388. return 0;
  3389. }
  3390. /*
  3391. * dgap_tty_digigeta()
  3392. *
  3393. * Ioctl to get the information for ditty.
  3394. *
  3395. *
  3396. *
  3397. */
  3398. static int dgap_tty_digigeta(struct channel_t *ch,
  3399. struct digi_t __user *retinfo)
  3400. {
  3401. struct digi_t tmp;
  3402. ulong lock_flags;
  3403. if (!retinfo)
  3404. return -EFAULT;
  3405. memset(&tmp, 0, sizeof(tmp));
  3406. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  3407. memcpy(&tmp, &ch->ch_digi, sizeof(tmp));
  3408. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3409. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  3410. return -EFAULT;
  3411. return 0;
  3412. }
  3413. /*
  3414. * dgap_tty_digiseta()
  3415. *
  3416. * Ioctl to set the information for ditty.
  3417. *
  3418. *
  3419. *
  3420. */
  3421. static int dgap_tty_digiseta(struct channel_t *ch, struct board_t *bd,
  3422. struct un_t *un, struct digi_t __user *new_info)
  3423. {
  3424. struct digi_t new_digi;
  3425. ulong lock_flags = 0;
  3426. unsigned long lock_flags2;
  3427. if (copy_from_user(&new_digi, new_info, sizeof(struct digi_t)))
  3428. return -EFAULT;
  3429. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3430. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3431. memcpy(&ch->ch_digi, &new_digi, sizeof(struct digi_t));
  3432. if (ch->ch_digi.digi_maxcps < 1)
  3433. ch->ch_digi.digi_maxcps = 1;
  3434. if (ch->ch_digi.digi_maxcps > 10000)
  3435. ch->ch_digi.digi_maxcps = 10000;
  3436. if (ch->ch_digi.digi_bufsize < 10)
  3437. ch->ch_digi.digi_bufsize = 10;
  3438. if (ch->ch_digi.digi_maxchar < 1)
  3439. ch->ch_digi.digi_maxchar = 1;
  3440. if (ch->ch_digi.digi_maxchar > ch->ch_digi.digi_bufsize)
  3441. ch->ch_digi.digi_maxchar = ch->ch_digi.digi_bufsize;
  3442. if (ch->ch_digi.digi_onlen > DIGI_PLEN)
  3443. ch->ch_digi.digi_onlen = DIGI_PLEN;
  3444. if (ch->ch_digi.digi_offlen > DIGI_PLEN)
  3445. ch->ch_digi.digi_offlen = DIGI_PLEN;
  3446. dgap_param(ch, bd, un->un_type);
  3447. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3448. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3449. return 0;
  3450. }
  3451. /*
  3452. * dgap_tty_digigetedelay()
  3453. *
  3454. * Ioctl to get the current edelay setting.
  3455. *
  3456. *
  3457. *
  3458. */
  3459. static int dgap_tty_digigetedelay(struct tty_struct *tty, int __user *retinfo)
  3460. {
  3461. struct channel_t *ch;
  3462. struct un_t *un;
  3463. int tmp;
  3464. ulong lock_flags;
  3465. if (!retinfo)
  3466. return -EFAULT;
  3467. if (!tty || tty->magic != TTY_MAGIC)
  3468. return -EFAULT;
  3469. un = tty->driver_data;
  3470. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3471. return -EFAULT;
  3472. ch = un->un_ch;
  3473. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3474. return -EFAULT;
  3475. memset(&tmp, 0, sizeof(tmp));
  3476. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  3477. tmp = readw(&ch->ch_bs->edelay);
  3478. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3479. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  3480. return -EFAULT;
  3481. return 0;
  3482. }
  3483. /*
  3484. * dgap_tty_digisetedelay()
  3485. *
  3486. * Ioctl to set the EDELAY setting
  3487. *
  3488. */
  3489. static int dgap_tty_digisetedelay(struct channel_t *ch, struct board_t *bd,
  3490. struct un_t *un, int __user *new_info)
  3491. {
  3492. int new_digi;
  3493. ulong lock_flags;
  3494. ulong lock_flags2;
  3495. if (copy_from_user(&new_digi, new_info, sizeof(int)))
  3496. return -EFAULT;
  3497. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3498. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3499. writew((u16)new_digi, &ch->ch_bs->edelay);
  3500. dgap_param(ch, bd, un->un_type);
  3501. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3502. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3503. return 0;
  3504. }
  3505. /*
  3506. * dgap_tty_digigetcustombaud()
  3507. *
  3508. * Ioctl to get the current custom baud rate setting.
  3509. */
  3510. static int dgap_tty_digigetcustombaud(struct channel_t *ch, struct un_t *un,
  3511. int __user *retinfo)
  3512. {
  3513. int tmp;
  3514. ulong lock_flags;
  3515. if (!retinfo)
  3516. return -EFAULT;
  3517. memset(&tmp, 0, sizeof(tmp));
  3518. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  3519. tmp = dgap_get_custom_baud(ch);
  3520. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3521. if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
  3522. return -EFAULT;
  3523. return 0;
  3524. }
  3525. /*
  3526. * dgap_tty_digisetcustombaud()
  3527. *
  3528. * Ioctl to set the custom baud rate setting
  3529. */
  3530. static int dgap_tty_digisetcustombaud(struct channel_t *ch, struct board_t *bd,
  3531. struct un_t *un, int __user *new_info)
  3532. {
  3533. uint new_rate;
  3534. ulong lock_flags;
  3535. ulong lock_flags2;
  3536. if (copy_from_user(&new_rate, new_info, sizeof(unsigned int)))
  3537. return -EFAULT;
  3538. if (bd->bd_flags & BD_FEP5PLUS) {
  3539. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3540. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3541. ch->ch_custom_speed = new_rate;
  3542. dgap_param(ch, bd, un->un_type);
  3543. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3544. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3545. }
  3546. return 0;
  3547. }
  3548. /*
  3549. * dgap_set_termios()
  3550. */
  3551. static void dgap_tty_set_termios(struct tty_struct *tty,
  3552. struct ktermios *old_termios)
  3553. {
  3554. struct board_t *bd;
  3555. struct channel_t *ch;
  3556. struct un_t *un;
  3557. unsigned long lock_flags;
  3558. unsigned long lock_flags2;
  3559. if (!tty || tty->magic != TTY_MAGIC)
  3560. return;
  3561. un = tty->driver_data;
  3562. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3563. return;
  3564. ch = un->un_ch;
  3565. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3566. return;
  3567. bd = ch->ch_bd;
  3568. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3569. return;
  3570. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3571. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3572. ch->ch_c_cflag = tty->termios.c_cflag;
  3573. ch->ch_c_iflag = tty->termios.c_iflag;
  3574. ch->ch_c_oflag = tty->termios.c_oflag;
  3575. ch->ch_c_lflag = tty->termios.c_lflag;
  3576. ch->ch_startc = tty->termios.c_cc[VSTART];
  3577. ch->ch_stopc = tty->termios.c_cc[VSTOP];
  3578. dgap_carrier(ch);
  3579. dgap_param(ch, bd, un->un_type);
  3580. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3581. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3582. }
  3583. static void dgap_tty_throttle(struct tty_struct *tty)
  3584. {
  3585. struct board_t *bd;
  3586. struct channel_t *ch;
  3587. struct un_t *un;
  3588. ulong lock_flags;
  3589. ulong lock_flags2;
  3590. if (!tty || tty->magic != TTY_MAGIC)
  3591. return;
  3592. un = tty->driver_data;
  3593. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3594. return;
  3595. ch = un->un_ch;
  3596. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3597. return;
  3598. bd = ch->ch_bd;
  3599. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3600. return;
  3601. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3602. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3603. ch->ch_flags |= (CH_RXBLOCK);
  3604. #if 1
  3605. dgap_cmdw(ch, RPAUSE, 0, 0);
  3606. #endif
  3607. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3608. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3609. }
  3610. static void dgap_tty_unthrottle(struct tty_struct *tty)
  3611. {
  3612. struct board_t *bd;
  3613. struct channel_t *ch;
  3614. struct un_t *un;
  3615. ulong lock_flags;
  3616. ulong lock_flags2;
  3617. if (!tty || tty->magic != TTY_MAGIC)
  3618. return;
  3619. un = tty->driver_data;
  3620. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3621. return;
  3622. ch = un->un_ch;
  3623. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3624. return;
  3625. bd = ch->ch_bd;
  3626. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3627. return;
  3628. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3629. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3630. ch->ch_flags &= ~(CH_RXBLOCK);
  3631. #if 1
  3632. dgap_cmdw(ch, RRESUME, 0, 0);
  3633. #endif
  3634. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3635. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3636. }
  3637. static struct board_t *find_board_by_major(unsigned int major)
  3638. {
  3639. unsigned int i;
  3640. for (i = 0; i < MAXBOARDS; i++) {
  3641. struct board_t *brd = dgap_board[i];
  3642. if (!brd)
  3643. return NULL;
  3644. if (major == brd->serial_driver->major ||
  3645. major == brd->print_driver->major)
  3646. return brd;
  3647. }
  3648. return NULL;
  3649. }
  3650. /************************************************************************
  3651. *
  3652. * TTY Entry points and helper functions
  3653. *
  3654. ************************************************************************/
  3655. /*
  3656. * dgap_tty_open()
  3657. *
  3658. */
  3659. static int dgap_tty_open(struct tty_struct *tty, struct file *file)
  3660. {
  3661. struct board_t *brd;
  3662. struct channel_t *ch;
  3663. struct un_t *un;
  3664. struct bs_t __iomem *bs;
  3665. uint major;
  3666. uint minor;
  3667. int rc;
  3668. ulong lock_flags;
  3669. ulong lock_flags2;
  3670. u16 head;
  3671. major = MAJOR(tty_devnum(tty));
  3672. minor = MINOR(tty_devnum(tty));
  3673. brd = find_board_by_major(major);
  3674. if (!brd)
  3675. return -EIO;
  3676. /*
  3677. * If board is not yet up to a state of READY, go to
  3678. * sleep waiting for it to happen or they cancel the open.
  3679. */
  3680. rc = wait_event_interruptible(brd->state_wait,
  3681. (brd->state & BOARD_READY));
  3682. if (rc)
  3683. return rc;
  3684. spin_lock_irqsave(&brd->bd_lock, lock_flags);
  3685. /* The wait above should guarantee this cannot happen */
  3686. if (brd->state != BOARD_READY) {
  3687. spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
  3688. return -EIO;
  3689. }
  3690. /* If opened device is greater than our number of ports, bail. */
  3691. if (MINOR(tty_devnum(tty)) > brd->nasync) {
  3692. spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
  3693. return -EIO;
  3694. }
  3695. ch = brd->channels[minor];
  3696. if (!ch) {
  3697. spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
  3698. return -EIO;
  3699. }
  3700. /* Grab channel lock */
  3701. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3702. /* Figure out our type */
  3703. if (major == brd->serial_driver->major) {
  3704. un = &brd->channels[minor]->ch_tun;
  3705. un->un_type = DGAP_SERIAL;
  3706. } else if (major == brd->print_driver->major) {
  3707. un = &brd->channels[minor]->ch_pun;
  3708. un->un_type = DGAP_PRINT;
  3709. } else {
  3710. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3711. spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
  3712. return -EIO;
  3713. }
  3714. /* Store our unit into driver_data, so we always have it available. */
  3715. tty->driver_data = un;
  3716. /*
  3717. * Error if channel info pointer is NULL.
  3718. */
  3719. bs = ch->ch_bs;
  3720. if (!bs) {
  3721. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3722. spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
  3723. return -EIO;
  3724. }
  3725. /*
  3726. * Initialize tty's
  3727. */
  3728. if (!(un->un_flags & UN_ISOPEN)) {
  3729. /* Store important variables. */
  3730. un->un_tty = tty;
  3731. /* Maybe do something here to the TTY struct as well? */
  3732. }
  3733. /*
  3734. * Initialize if neither terminal or printer is open.
  3735. */
  3736. if (!((ch->ch_tun.un_flags | ch->ch_pun.un_flags) & UN_ISOPEN)) {
  3737. ch->ch_mforce = 0;
  3738. ch->ch_mval = 0;
  3739. /*
  3740. * Flush input queue.
  3741. */
  3742. head = readw(&bs->rx_head);
  3743. writew(head, &bs->rx_tail);
  3744. ch->ch_flags = 0;
  3745. ch->pscan_state = 0;
  3746. ch->pscan_savechar = 0;
  3747. ch->ch_c_cflag = tty->termios.c_cflag;
  3748. ch->ch_c_iflag = tty->termios.c_iflag;
  3749. ch->ch_c_oflag = tty->termios.c_oflag;
  3750. ch->ch_c_lflag = tty->termios.c_lflag;
  3751. ch->ch_startc = tty->termios.c_cc[VSTART];
  3752. ch->ch_stopc = tty->termios.c_cc[VSTOP];
  3753. /* TODO: flush our TTY struct here? */
  3754. }
  3755. dgap_carrier(ch);
  3756. /*
  3757. * Run param in case we changed anything
  3758. */
  3759. dgap_param(ch, brd, un->un_type);
  3760. /*
  3761. * follow protocol for opening port
  3762. */
  3763. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3764. spin_unlock_irqrestore(&brd->bd_lock, lock_flags);
  3765. rc = dgap_block_til_ready(tty, file, ch);
  3766. if (!un->un_tty)
  3767. return -ENODEV;
  3768. /* No going back now, increment our unit and channel counters */
  3769. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  3770. ch->ch_open_count++;
  3771. un->un_open_count++;
  3772. un->un_flags |= (UN_ISOPEN);
  3773. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3774. return rc;
  3775. }
  3776. /*
  3777. * dgap_tty_close()
  3778. *
  3779. */
  3780. static void dgap_tty_close(struct tty_struct *tty, struct file *file)
  3781. {
  3782. struct board_t *bd;
  3783. struct channel_t *ch;
  3784. struct un_t *un;
  3785. ulong lock_flags;
  3786. if (!tty || tty->magic != TTY_MAGIC)
  3787. return;
  3788. un = tty->driver_data;
  3789. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3790. return;
  3791. ch = un->un_ch;
  3792. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3793. return;
  3794. bd = ch->ch_bd;
  3795. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3796. return;
  3797. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  3798. /*
  3799. * Determine if this is the last close or not - and if we agree about
  3800. * which type of close it is with the Line Discipline
  3801. */
  3802. if ((tty->count == 1) && (un->un_open_count != 1)) {
  3803. /*
  3804. * Uh, oh. tty->count is 1, which means that the tty
  3805. * structure will be freed. un_open_count should always
  3806. * be one in these conditions. If it's greater than
  3807. * one, we've got real problems, since it means the
  3808. * serial port won't be shutdown.
  3809. */
  3810. un->un_open_count = 1;
  3811. }
  3812. if (--un->un_open_count < 0)
  3813. un->un_open_count = 0;
  3814. ch->ch_open_count--;
  3815. if (ch->ch_open_count && un->un_open_count) {
  3816. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3817. return;
  3818. }
  3819. /* OK, its the last close on the unit */
  3820. un->un_flags |= UN_CLOSING;
  3821. tty->closing = 1;
  3822. /*
  3823. * Only officially close channel if count is 0 and
  3824. * DIGI_PRINTER bit is not set.
  3825. */
  3826. if ((ch->ch_open_count == 0) &&
  3827. !(ch->ch_digi.digi_flags & DIGI_PRINTER)) {
  3828. ch->ch_flags &= ~(CH_RXBLOCK);
  3829. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3830. /* wait for output to drain */
  3831. /* This will also return if we take an interrupt */
  3832. dgap_wait_for_drain(tty);
  3833. dgap_tty_flush_buffer(tty);
  3834. tty_ldisc_flush(tty);
  3835. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  3836. tty->closing = 0;
  3837. /*
  3838. * If we have HUPCL set, lower DTR and RTS
  3839. */
  3840. if (ch->ch_c_cflag & HUPCL) {
  3841. ch->ch_mostat &= ~(D_RTS(ch) | D_DTR(ch));
  3842. dgap_cmdb(ch, SMODEM, 0, D_DTR(ch) | D_RTS(ch), 0);
  3843. /*
  3844. * Go to sleep to ensure RTS/DTR
  3845. * have been dropped for modems to see it.
  3846. */
  3847. spin_unlock_irqrestore(&ch->ch_lock,
  3848. lock_flags);
  3849. /* .25 second delay for dropping RTS/DTR */
  3850. schedule_timeout_interruptible(msecs_to_jiffies(250));
  3851. spin_lock_irqsave(&ch->ch_lock, lock_flags);
  3852. }
  3853. ch->pscan_state = 0;
  3854. ch->pscan_savechar = 0;
  3855. ch->ch_baud_info = 0;
  3856. }
  3857. /*
  3858. * turn off print device when closing print device.
  3859. */
  3860. if ((un->un_type == DGAP_PRINT) && (ch->ch_flags & CH_PRON)) {
  3861. dgap_wmove(ch, ch->ch_digi.digi_offstr,
  3862. (int)ch->ch_digi.digi_offlen);
  3863. ch->ch_flags &= ~CH_PRON;
  3864. }
  3865. un->un_tty = NULL;
  3866. un->un_flags &= ~(UN_ISOPEN | UN_CLOSING);
  3867. tty->driver_data = NULL;
  3868. wake_up_interruptible(&ch->ch_flags_wait);
  3869. wake_up_interruptible(&un->un_flags_wait);
  3870. spin_unlock_irqrestore(&ch->ch_lock, lock_flags);
  3871. }
  3872. static void dgap_tty_start(struct tty_struct *tty)
  3873. {
  3874. struct board_t *bd;
  3875. struct channel_t *ch;
  3876. struct un_t *un;
  3877. ulong lock_flags;
  3878. ulong lock_flags2;
  3879. if (!tty || tty->magic != TTY_MAGIC)
  3880. return;
  3881. un = tty->driver_data;
  3882. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3883. return;
  3884. ch = un->un_ch;
  3885. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3886. return;
  3887. bd = ch->ch_bd;
  3888. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3889. return;
  3890. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3891. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3892. dgap_cmdw(ch, RESUMETX, 0, 0);
  3893. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3894. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3895. }
  3896. static void dgap_tty_stop(struct tty_struct *tty)
  3897. {
  3898. struct board_t *bd;
  3899. struct channel_t *ch;
  3900. struct un_t *un;
  3901. ulong lock_flags;
  3902. ulong lock_flags2;
  3903. if (!tty || tty->magic != TTY_MAGIC)
  3904. return;
  3905. un = tty->driver_data;
  3906. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3907. return;
  3908. ch = un->un_ch;
  3909. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3910. return;
  3911. bd = ch->ch_bd;
  3912. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3913. return;
  3914. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3915. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3916. dgap_cmdw(ch, PAUSETX, 0, 0);
  3917. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3918. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3919. }
  3920. /*
  3921. * dgap_tty_flush_chars()
  3922. *
  3923. * Flush the cook buffer
  3924. *
  3925. * Note to self, and any other poor souls who venture here:
  3926. *
  3927. * flush in this case DOES NOT mean dispose of the data.
  3928. * instead, it means "stop buffering and send it if you
  3929. * haven't already." Just guess how I figured that out... SRW 2-Jun-98
  3930. *
  3931. * It is also always called in interrupt context - JAR 8-Sept-99
  3932. */
  3933. static void dgap_tty_flush_chars(struct tty_struct *tty)
  3934. {
  3935. struct board_t *bd;
  3936. struct channel_t *ch;
  3937. struct un_t *un;
  3938. ulong lock_flags;
  3939. ulong lock_flags2;
  3940. if (!tty || tty->magic != TTY_MAGIC)
  3941. return;
  3942. un = tty->driver_data;
  3943. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3944. return;
  3945. ch = un->un_ch;
  3946. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3947. return;
  3948. bd = ch->ch_bd;
  3949. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3950. return;
  3951. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3952. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3953. /* TODO: Do something here */
  3954. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3955. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3956. }
  3957. /*****************************************************************************
  3958. *
  3959. * The IOCTL function and all of its helpers
  3960. *
  3961. *****************************************************************************/
  3962. /*
  3963. * dgap_tty_ioctl()
  3964. *
  3965. * The usual assortment of ioctl's
  3966. */
  3967. static int dgap_tty_ioctl(struct tty_struct *tty, unsigned int cmd,
  3968. unsigned long arg)
  3969. {
  3970. struct board_t *bd;
  3971. struct channel_t *ch;
  3972. struct un_t *un;
  3973. int rc;
  3974. u16 head;
  3975. ulong lock_flags = 0;
  3976. ulong lock_flags2 = 0;
  3977. void __user *uarg = (void __user *)arg;
  3978. if (!tty || tty->magic != TTY_MAGIC)
  3979. return -ENODEV;
  3980. un = tty->driver_data;
  3981. if (!un || un->magic != DGAP_UNIT_MAGIC)
  3982. return -ENODEV;
  3983. ch = un->un_ch;
  3984. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  3985. return -ENODEV;
  3986. bd = ch->ch_bd;
  3987. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  3988. return -ENODEV;
  3989. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  3990. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  3991. if (un->un_open_count <= 0) {
  3992. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  3993. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  3994. return -EIO;
  3995. }
  3996. switch (cmd) {
  3997. /* Here are all the standard ioctl's that we MUST implement */
  3998. case TCSBRK:
  3999. /*
  4000. * TCSBRK is SVID version: non-zero arg --> no break
  4001. * this behaviour is exploited by tcdrain().
  4002. *
  4003. * According to POSIX.1 spec (7.2.2.1.2) breaks should be
  4004. * between 0.25 and 0.5 seconds so we'll ask for something
  4005. * in the middle: 0.375 seconds.
  4006. */
  4007. rc = tty_check_change(tty);
  4008. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4009. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4010. if (rc)
  4011. return rc;
  4012. rc = dgap_wait_for_drain(tty);
  4013. if (rc)
  4014. return -EINTR;
  4015. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  4016. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  4017. if (((cmd == TCSBRK) && (!arg)) || (cmd == TCSBRKP))
  4018. dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0);
  4019. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4020. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4021. return 0;
  4022. case TCSBRKP:
  4023. /* support for POSIX tcsendbreak()
  4024. * According to POSIX.1 spec (7.2.2.1.2) breaks should be
  4025. * between 0.25 and 0.5 seconds so we'll ask for something
  4026. * in the middle: 0.375 seconds.
  4027. */
  4028. rc = tty_check_change(tty);
  4029. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4030. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4031. if (rc)
  4032. return rc;
  4033. rc = dgap_wait_for_drain(tty);
  4034. if (rc)
  4035. return -EINTR;
  4036. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  4037. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  4038. dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0);
  4039. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4040. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4041. return 0;
  4042. case TIOCSBRK:
  4043. /*
  4044. * FEP5 doesn't support turning on a break unconditionally.
  4045. * The FEP5 device will stop sending a break automatically
  4046. * after the specified time value that was sent when turning on
  4047. * the break.
  4048. */
  4049. rc = tty_check_change(tty);
  4050. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4051. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4052. if (rc)
  4053. return rc;
  4054. rc = dgap_wait_for_drain(tty);
  4055. if (rc)
  4056. return -EINTR;
  4057. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  4058. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  4059. dgap_cmdw(ch, SBREAK, (u16)SBREAK_TIME, 0);
  4060. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4061. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4062. return 0;
  4063. case TIOCCBRK:
  4064. /*
  4065. * FEP5 doesn't support turning off a break unconditionally.
  4066. * The FEP5 device will stop sending a break automatically
  4067. * after the specified time value that was sent when turning on
  4068. * the break.
  4069. */
  4070. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4071. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4072. return 0;
  4073. case TIOCGSOFTCAR:
  4074. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4075. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4076. return put_user(C_CLOCAL(tty) ? 1 : 0,
  4077. (unsigned long __user *)arg);
  4078. case TIOCSSOFTCAR:
  4079. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4080. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4081. rc = get_user(arg, (unsigned long __user *)arg);
  4082. if (rc)
  4083. return rc;
  4084. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  4085. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  4086. tty->termios.c_cflag = ((tty->termios.c_cflag & ~CLOCAL) |
  4087. (arg ? CLOCAL : 0));
  4088. dgap_param(ch, bd, un->un_type);
  4089. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4090. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4091. return 0;
  4092. case TIOCMGET:
  4093. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4094. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4095. return dgap_get_modem_info(ch, uarg);
  4096. case TIOCMBIS:
  4097. case TIOCMBIC:
  4098. case TIOCMSET:
  4099. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4100. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4101. return dgap_set_modem_info(ch, bd, un, cmd, uarg);
  4102. /*
  4103. * Here are any additional ioctl's that we want to implement
  4104. */
  4105. case TCFLSH:
  4106. /*
  4107. * The linux tty driver doesn't have a flush
  4108. * input routine for the driver, assuming all backed
  4109. * up data is in the line disc. buffers. However,
  4110. * we all know that's not the case. Here, we
  4111. * act on the ioctl, but then lie and say we didn't
  4112. * so the line discipline will process the flush
  4113. * also.
  4114. */
  4115. rc = tty_check_change(tty);
  4116. if (rc) {
  4117. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4118. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4119. return rc;
  4120. }
  4121. if ((arg == TCIFLUSH) || (arg == TCIOFLUSH)) {
  4122. if (!(un->un_type == DGAP_PRINT)) {
  4123. head = readw(&ch->ch_bs->rx_head);
  4124. writew(head, &ch->ch_bs->rx_tail);
  4125. writeb(0, &ch->ch_bs->orun);
  4126. }
  4127. }
  4128. if ((arg != TCOFLUSH) && (arg != TCIOFLUSH)) {
  4129. /* pretend we didn't recognize this IOCTL */
  4130. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4131. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4132. return -ENOIOCTLCMD;
  4133. }
  4134. ch->ch_flags &= ~CH_STOP;
  4135. head = readw(&ch->ch_bs->tx_head);
  4136. dgap_cmdw(ch, FLUSHTX, (u16)head, 0);
  4137. dgap_cmdw(ch, RESUMETX, 0, 0);
  4138. if (ch->ch_tun.un_flags & (UN_LOW | UN_EMPTY)) {
  4139. ch->ch_tun.un_flags &= ~(UN_LOW | UN_EMPTY);
  4140. wake_up_interruptible(&ch->ch_tun.un_flags_wait);
  4141. }
  4142. if (ch->ch_pun.un_flags & (UN_LOW | UN_EMPTY)) {
  4143. ch->ch_pun.un_flags &= ~(UN_LOW | UN_EMPTY);
  4144. wake_up_interruptible(&ch->ch_pun.un_flags_wait);
  4145. }
  4146. if (waitqueue_active(&tty->write_wait))
  4147. wake_up_interruptible(&tty->write_wait);
  4148. /* Can't hold any locks when calling tty_wakeup! */
  4149. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4150. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4151. tty_wakeup(tty);
  4152. /* pretend we didn't recognize this IOCTL */
  4153. return -ENOIOCTLCMD;
  4154. case TCSETSF:
  4155. case TCSETSW:
  4156. /*
  4157. * The linux tty driver doesn't have a flush
  4158. * input routine for the driver, assuming all backed
  4159. * up data is in the line disc. buffers. However,
  4160. * we all know that's not the case. Here, we
  4161. * act on the ioctl, but then lie and say we didn't
  4162. * so the line discipline will process the flush
  4163. * also.
  4164. */
  4165. if (cmd == TCSETSF) {
  4166. /* flush rx */
  4167. ch->ch_flags &= ~CH_STOP;
  4168. head = readw(&ch->ch_bs->rx_head);
  4169. writew(head, &ch->ch_bs->rx_tail);
  4170. }
  4171. /* now wait for all the output to drain */
  4172. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4173. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4174. rc = dgap_wait_for_drain(tty);
  4175. if (rc)
  4176. return -EINTR;
  4177. /* pretend we didn't recognize this */
  4178. return -ENOIOCTLCMD;
  4179. case TCSETAW:
  4180. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4181. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4182. rc = dgap_wait_for_drain(tty);
  4183. if (rc)
  4184. return -EINTR;
  4185. /* pretend we didn't recognize this */
  4186. return -ENOIOCTLCMD;
  4187. case TCXONC:
  4188. /*
  4189. * The Linux Line Discipline (LD) would do this for us if we
  4190. * let it, but we have the special firmware options to do this
  4191. * the "right way" regardless of hardware or software flow
  4192. * control so we'll do it outselves instead of letting the LD
  4193. * do it.
  4194. */
  4195. rc = tty_check_change(tty);
  4196. if (rc) {
  4197. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4198. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4199. return rc;
  4200. }
  4201. switch (arg) {
  4202. case TCOON:
  4203. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4204. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4205. dgap_tty_start(tty);
  4206. return 0;
  4207. case TCOOFF:
  4208. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4209. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4210. dgap_tty_stop(tty);
  4211. return 0;
  4212. case TCION:
  4213. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4214. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4215. /* Make the ld do it */
  4216. return -ENOIOCTLCMD;
  4217. case TCIOFF:
  4218. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4219. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4220. /* Make the ld do it */
  4221. return -ENOIOCTLCMD;
  4222. default:
  4223. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4224. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4225. return -EINVAL;
  4226. }
  4227. case DIGI_GETA:
  4228. /* get information for ditty */
  4229. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4230. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4231. return dgap_tty_digigeta(ch, uarg);
  4232. case DIGI_SETAW:
  4233. case DIGI_SETAF:
  4234. /* set information for ditty */
  4235. if (cmd == (DIGI_SETAW)) {
  4236. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4237. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4238. rc = dgap_wait_for_drain(tty);
  4239. if (rc)
  4240. return -EINTR;
  4241. spin_lock_irqsave(&bd->bd_lock, lock_flags);
  4242. spin_lock_irqsave(&ch->ch_lock, lock_flags2);
  4243. } else
  4244. tty_ldisc_flush(tty);
  4245. /* fall thru */
  4246. case DIGI_SETA:
  4247. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4248. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4249. return dgap_tty_digiseta(ch, bd, un, uarg);
  4250. case DIGI_GEDELAY:
  4251. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4252. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4253. return dgap_tty_digigetedelay(tty, uarg);
  4254. case DIGI_SEDELAY:
  4255. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4256. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4257. return dgap_tty_digisetedelay(ch, bd, un, uarg);
  4258. case DIGI_GETCUSTOMBAUD:
  4259. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4260. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4261. return dgap_tty_digigetcustombaud(ch, un, uarg);
  4262. case DIGI_SETCUSTOMBAUD:
  4263. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4264. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4265. return dgap_tty_digisetcustombaud(ch, bd, un, uarg);
  4266. case DIGI_RESET_PORT:
  4267. dgap_firmware_reset_port(ch);
  4268. dgap_param(ch, bd, un->un_type);
  4269. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4270. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4271. return 0;
  4272. default:
  4273. spin_unlock_irqrestore(&ch->ch_lock, lock_flags2);
  4274. spin_unlock_irqrestore(&bd->bd_lock, lock_flags);
  4275. return -ENOIOCTLCMD;
  4276. }
  4277. }
  4278. static const struct tty_operations dgap_tty_ops = {
  4279. .open = dgap_tty_open,
  4280. .close = dgap_tty_close,
  4281. .write = dgap_tty_write,
  4282. .write_room = dgap_tty_write_room,
  4283. .flush_buffer = dgap_tty_flush_buffer,
  4284. .chars_in_buffer = dgap_tty_chars_in_buffer,
  4285. .flush_chars = dgap_tty_flush_chars,
  4286. .ioctl = dgap_tty_ioctl,
  4287. .set_termios = dgap_tty_set_termios,
  4288. .stop = dgap_tty_stop,
  4289. .start = dgap_tty_start,
  4290. .throttle = dgap_tty_throttle,
  4291. .unthrottle = dgap_tty_unthrottle,
  4292. .hangup = dgap_tty_hangup,
  4293. .put_char = dgap_tty_put_char,
  4294. .tiocmget = dgap_tty_tiocmget,
  4295. .tiocmset = dgap_tty_tiocmset,
  4296. .break_ctl = dgap_tty_send_break,
  4297. .wait_until_sent = dgap_tty_wait_until_sent,
  4298. .send_xchar = dgap_tty_send_xchar
  4299. };
  4300. /************************************************************************
  4301. *
  4302. * TTY Initialization/Cleanup Functions
  4303. *
  4304. ************************************************************************/
  4305. /*
  4306. * dgap_tty_register()
  4307. *
  4308. * Init the tty subsystem for this board.
  4309. */
  4310. static int dgap_tty_register(struct board_t *brd)
  4311. {
  4312. int rc;
  4313. brd->serial_driver = tty_alloc_driver(MAXPORTS,
  4314. TTY_DRIVER_REAL_RAW |
  4315. TTY_DRIVER_DYNAMIC_DEV |
  4316. TTY_DRIVER_HARDWARE_BREAK);
  4317. if (IS_ERR(brd->serial_driver))
  4318. return PTR_ERR(brd->serial_driver);
  4319. snprintf(brd->serial_name, MAXTTYNAMELEN, "tty_dgap_%d_",
  4320. brd->boardnum);
  4321. brd->serial_driver->name = brd->serial_name;
  4322. brd->serial_driver->name_base = 0;
  4323. brd->serial_driver->major = 0;
  4324. brd->serial_driver->minor_start = 0;
  4325. brd->serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  4326. brd->serial_driver->subtype = SERIAL_TYPE_NORMAL;
  4327. brd->serial_driver->init_termios = dgap_default_termios;
  4328. brd->serial_driver->driver_name = DRVSTR;
  4329. /*
  4330. * Entry points for driver. Called by the kernel from
  4331. * tty_io.c and n_tty.c.
  4332. */
  4333. tty_set_operations(brd->serial_driver, &dgap_tty_ops);
  4334. /*
  4335. * If we're doing transparent print, we have to do all of the above
  4336. * again, separately so we don't get the LD confused about what major
  4337. * we are when we get into the dgap_tty_open() routine.
  4338. */
  4339. brd->print_driver = tty_alloc_driver(MAXPORTS,
  4340. TTY_DRIVER_REAL_RAW |
  4341. TTY_DRIVER_DYNAMIC_DEV |
  4342. TTY_DRIVER_HARDWARE_BREAK);
  4343. if (IS_ERR(brd->print_driver)) {
  4344. rc = PTR_ERR(brd->print_driver);
  4345. goto free_serial_drv;
  4346. }
  4347. snprintf(brd->print_name, MAXTTYNAMELEN, "pr_dgap_%d_",
  4348. brd->boardnum);
  4349. brd->print_driver->name = brd->print_name;
  4350. brd->print_driver->name_base = 0;
  4351. brd->print_driver->major = 0;
  4352. brd->print_driver->minor_start = 0;
  4353. brd->print_driver->type = TTY_DRIVER_TYPE_SERIAL;
  4354. brd->print_driver->subtype = SERIAL_TYPE_NORMAL;
  4355. brd->print_driver->init_termios = dgap_default_termios;
  4356. brd->print_driver->driver_name = DRVSTR;
  4357. /*
  4358. * Entry points for driver. Called by the kernel from
  4359. * tty_io.c and n_tty.c.
  4360. */
  4361. tty_set_operations(brd->print_driver, &dgap_tty_ops);
  4362. /* Register tty devices */
  4363. rc = tty_register_driver(brd->serial_driver);
  4364. if (rc < 0)
  4365. goto free_print_drv;
  4366. /* Register Transparent Print devices */
  4367. rc = tty_register_driver(brd->print_driver);
  4368. if (rc < 0)
  4369. goto unregister_serial_drv;
  4370. return 0;
  4371. unregister_serial_drv:
  4372. tty_unregister_driver(brd->serial_driver);
  4373. free_print_drv:
  4374. put_tty_driver(brd->print_driver);
  4375. free_serial_drv:
  4376. put_tty_driver(brd->serial_driver);
  4377. return rc;
  4378. }
  4379. static void dgap_tty_unregister(struct board_t *brd)
  4380. {
  4381. tty_unregister_driver(brd->print_driver);
  4382. tty_unregister_driver(brd->serial_driver);
  4383. put_tty_driver(brd->print_driver);
  4384. put_tty_driver(brd->serial_driver);
  4385. }
  4386. static int dgap_alloc_flipbuf(struct board_t *brd)
  4387. {
  4388. /*
  4389. * allocate flip buffer for board.
  4390. */
  4391. brd->flipbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
  4392. if (!brd->flipbuf)
  4393. return -ENOMEM;
  4394. brd->flipflagbuf = kmalloc(MYFLIPLEN, GFP_KERNEL);
  4395. if (!brd->flipflagbuf) {
  4396. kfree(brd->flipbuf);
  4397. return -ENOMEM;
  4398. }
  4399. return 0;
  4400. }
  4401. static void dgap_free_flipbuf(struct board_t *brd)
  4402. {
  4403. kfree(brd->flipbuf);
  4404. kfree(brd->flipflagbuf);
  4405. }
  4406. static struct board_t *dgap_verify_board(struct device *p)
  4407. {
  4408. struct board_t *bd;
  4409. if (!p)
  4410. return NULL;
  4411. bd = dev_get_drvdata(p);
  4412. if (!bd || bd->magic != DGAP_BOARD_MAGIC || bd->state != BOARD_READY)
  4413. return NULL;
  4414. return bd;
  4415. }
  4416. static ssize_t dgap_ports_state_show(struct device *p,
  4417. struct device_attribute *attr,
  4418. char *buf)
  4419. {
  4420. struct board_t *bd;
  4421. int count = 0;
  4422. unsigned int i;
  4423. bd = dgap_verify_board(p);
  4424. if (!bd)
  4425. return 0;
  4426. for (i = 0; i < bd->nasync; i++) {
  4427. count += snprintf(buf + count, PAGE_SIZE - count,
  4428. "%d %s\n", bd->channels[i]->ch_portnum,
  4429. bd->channels[i]->ch_open_count ? "Open" : "Closed");
  4430. }
  4431. return count;
  4432. }
  4433. static DEVICE_ATTR(ports_state, S_IRUSR, dgap_ports_state_show, NULL);
  4434. static ssize_t dgap_ports_baud_show(struct device *p,
  4435. struct device_attribute *attr,
  4436. char *buf)
  4437. {
  4438. struct board_t *bd;
  4439. int count = 0;
  4440. unsigned int i;
  4441. bd = dgap_verify_board(p);
  4442. if (!bd)
  4443. return 0;
  4444. for (i = 0; i < bd->nasync; i++) {
  4445. count += snprintf(buf + count, PAGE_SIZE - count, "%d %d\n",
  4446. bd->channels[i]->ch_portnum,
  4447. bd->channels[i]->ch_baud_info);
  4448. }
  4449. return count;
  4450. }
  4451. static DEVICE_ATTR(ports_baud, S_IRUSR, dgap_ports_baud_show, NULL);
  4452. static ssize_t dgap_ports_msignals_show(struct device *p,
  4453. struct device_attribute *attr,
  4454. char *buf)
  4455. {
  4456. struct board_t *bd;
  4457. int count = 0;
  4458. unsigned int i;
  4459. bd = dgap_verify_board(p);
  4460. if (!bd)
  4461. return 0;
  4462. for (i = 0; i < bd->nasync; i++) {
  4463. if (bd->channels[i]->ch_open_count)
  4464. count += snprintf(buf + count, PAGE_SIZE - count,
  4465. "%d %s %s %s %s %s %s\n",
  4466. bd->channels[i]->ch_portnum,
  4467. (bd->channels[i]->ch_mostat &
  4468. UART_MCR_RTS) ? "RTS" : "",
  4469. (bd->channels[i]->ch_mistat &
  4470. UART_MSR_CTS) ? "CTS" : "",
  4471. (bd->channels[i]->ch_mostat &
  4472. UART_MCR_DTR) ? "DTR" : "",
  4473. (bd->channels[i]->ch_mistat &
  4474. UART_MSR_DSR) ? "DSR" : "",
  4475. (bd->channels[i]->ch_mistat &
  4476. UART_MSR_DCD) ? "DCD" : "",
  4477. (bd->channels[i]->ch_mistat &
  4478. UART_MSR_RI) ? "RI" : "");
  4479. else
  4480. count += snprintf(buf + count, PAGE_SIZE - count,
  4481. "%d\n", bd->channels[i]->ch_portnum);
  4482. }
  4483. return count;
  4484. }
  4485. static DEVICE_ATTR(ports_msignals, S_IRUSR, dgap_ports_msignals_show, NULL);
  4486. static ssize_t dgap_ports_iflag_show(struct device *p,
  4487. struct device_attribute *attr,
  4488. char *buf)
  4489. {
  4490. struct board_t *bd;
  4491. int count = 0;
  4492. unsigned int i;
  4493. bd = dgap_verify_board(p);
  4494. if (!bd)
  4495. return 0;
  4496. for (i = 0; i < bd->nasync; i++)
  4497. count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
  4498. bd->channels[i]->ch_portnum,
  4499. bd->channels[i]->ch_c_iflag);
  4500. return count;
  4501. }
  4502. static DEVICE_ATTR(ports_iflag, S_IRUSR, dgap_ports_iflag_show, NULL);
  4503. static ssize_t dgap_ports_cflag_show(struct device *p,
  4504. struct device_attribute *attr,
  4505. char *buf)
  4506. {
  4507. struct board_t *bd;
  4508. int count = 0;
  4509. unsigned int i;
  4510. bd = dgap_verify_board(p);
  4511. if (!bd)
  4512. return 0;
  4513. for (i = 0; i < bd->nasync; i++)
  4514. count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
  4515. bd->channels[i]->ch_portnum,
  4516. bd->channels[i]->ch_c_cflag);
  4517. return count;
  4518. }
  4519. static DEVICE_ATTR(ports_cflag, S_IRUSR, dgap_ports_cflag_show, NULL);
  4520. static ssize_t dgap_ports_oflag_show(struct device *p,
  4521. struct device_attribute *attr,
  4522. char *buf)
  4523. {
  4524. struct board_t *bd;
  4525. int count = 0;
  4526. unsigned int i;
  4527. bd = dgap_verify_board(p);
  4528. if (!bd)
  4529. return 0;
  4530. for (i = 0; i < bd->nasync; i++)
  4531. count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
  4532. bd->channels[i]->ch_portnum,
  4533. bd->channels[i]->ch_c_oflag);
  4534. return count;
  4535. }
  4536. static DEVICE_ATTR(ports_oflag, S_IRUSR, dgap_ports_oflag_show, NULL);
  4537. static ssize_t dgap_ports_lflag_show(struct device *p,
  4538. struct device_attribute *attr,
  4539. char *buf)
  4540. {
  4541. struct board_t *bd;
  4542. int count = 0;
  4543. unsigned int i;
  4544. bd = dgap_verify_board(p);
  4545. if (!bd)
  4546. return 0;
  4547. for (i = 0; i < bd->nasync; i++)
  4548. count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
  4549. bd->channels[i]->ch_portnum,
  4550. bd->channels[i]->ch_c_lflag);
  4551. return count;
  4552. }
  4553. static DEVICE_ATTR(ports_lflag, S_IRUSR, dgap_ports_lflag_show, NULL);
  4554. static ssize_t dgap_ports_digi_flag_show(struct device *p,
  4555. struct device_attribute *attr,
  4556. char *buf)
  4557. {
  4558. struct board_t *bd;
  4559. int count = 0;
  4560. unsigned int i;
  4561. bd = dgap_verify_board(p);
  4562. if (!bd)
  4563. return 0;
  4564. for (i = 0; i < bd->nasync; i++)
  4565. count += snprintf(buf + count, PAGE_SIZE - count, "%d %x\n",
  4566. bd->channels[i]->ch_portnum,
  4567. bd->channels[i]->ch_digi.digi_flags);
  4568. return count;
  4569. }
  4570. static DEVICE_ATTR(ports_digi_flag, S_IRUSR, dgap_ports_digi_flag_show, NULL);
  4571. static ssize_t dgap_ports_rxcount_show(struct device *p,
  4572. struct device_attribute *attr,
  4573. char *buf)
  4574. {
  4575. struct board_t *bd;
  4576. int count = 0;
  4577. unsigned int i;
  4578. bd = dgap_verify_board(p);
  4579. if (!bd)
  4580. return 0;
  4581. for (i = 0; i < bd->nasync; i++)
  4582. count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
  4583. bd->channels[i]->ch_portnum,
  4584. bd->channels[i]->ch_rxcount);
  4585. return count;
  4586. }
  4587. static DEVICE_ATTR(ports_rxcount, S_IRUSR, dgap_ports_rxcount_show, NULL);
  4588. static ssize_t dgap_ports_txcount_show(struct device *p,
  4589. struct device_attribute *attr,
  4590. char *buf)
  4591. {
  4592. struct board_t *bd;
  4593. int count = 0;
  4594. unsigned int i;
  4595. bd = dgap_verify_board(p);
  4596. if (!bd)
  4597. return 0;
  4598. for (i = 0; i < bd->nasync; i++)
  4599. count += snprintf(buf + count, PAGE_SIZE - count, "%d %ld\n",
  4600. bd->channels[i]->ch_portnum,
  4601. bd->channels[i]->ch_txcount);
  4602. return count;
  4603. }
  4604. static DEVICE_ATTR(ports_txcount, S_IRUSR, dgap_ports_txcount_show, NULL);
  4605. static ssize_t dgap_tty_state_show(struct device *d,
  4606. struct device_attribute *attr,
  4607. char *buf)
  4608. {
  4609. struct board_t *bd;
  4610. struct channel_t *ch;
  4611. struct un_t *un;
  4612. if (!d)
  4613. return 0;
  4614. un = dev_get_drvdata(d);
  4615. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4616. return 0;
  4617. ch = un->un_ch;
  4618. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4619. return 0;
  4620. bd = ch->ch_bd;
  4621. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4622. return 0;
  4623. if (bd->state != BOARD_READY)
  4624. return 0;
  4625. return snprintf(buf, PAGE_SIZE, "%s", un->un_open_count ?
  4626. "Open" : "Closed");
  4627. }
  4628. static DEVICE_ATTR(state, S_IRUSR, dgap_tty_state_show, NULL);
  4629. static ssize_t dgap_tty_baud_show(struct device *d,
  4630. struct device_attribute *attr,
  4631. char *buf)
  4632. {
  4633. struct board_t *bd;
  4634. struct channel_t *ch;
  4635. struct un_t *un;
  4636. if (!d)
  4637. return 0;
  4638. un = dev_get_drvdata(d);
  4639. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4640. return 0;
  4641. ch = un->un_ch;
  4642. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4643. return 0;
  4644. bd = ch->ch_bd;
  4645. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4646. return 0;
  4647. if (bd->state != BOARD_READY)
  4648. return 0;
  4649. return snprintf(buf, PAGE_SIZE, "%d\n", ch->ch_baud_info);
  4650. }
  4651. static DEVICE_ATTR(baud, S_IRUSR, dgap_tty_baud_show, NULL);
  4652. static ssize_t dgap_tty_msignals_show(struct device *d,
  4653. struct device_attribute *attr,
  4654. char *buf)
  4655. {
  4656. struct board_t *bd;
  4657. struct channel_t *ch;
  4658. struct un_t *un;
  4659. if (!d)
  4660. return 0;
  4661. un = dev_get_drvdata(d);
  4662. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4663. return 0;
  4664. ch = un->un_ch;
  4665. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4666. return 0;
  4667. bd = ch->ch_bd;
  4668. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4669. return 0;
  4670. if (bd->state != BOARD_READY)
  4671. return 0;
  4672. if (ch->ch_open_count) {
  4673. return snprintf(buf, PAGE_SIZE, "%s %s %s %s %s %s\n",
  4674. (ch->ch_mostat & UART_MCR_RTS) ? "RTS" : "",
  4675. (ch->ch_mistat & UART_MSR_CTS) ? "CTS" : "",
  4676. (ch->ch_mostat & UART_MCR_DTR) ? "DTR" : "",
  4677. (ch->ch_mistat & UART_MSR_DSR) ? "DSR" : "",
  4678. (ch->ch_mistat & UART_MSR_DCD) ? "DCD" : "",
  4679. (ch->ch_mistat & UART_MSR_RI) ? "RI" : "");
  4680. }
  4681. return 0;
  4682. }
  4683. static DEVICE_ATTR(msignals, S_IRUSR, dgap_tty_msignals_show, NULL);
  4684. static ssize_t dgap_tty_iflag_show(struct device *d,
  4685. struct device_attribute *attr,
  4686. char *buf)
  4687. {
  4688. struct board_t *bd;
  4689. struct channel_t *ch;
  4690. struct un_t *un;
  4691. if (!d)
  4692. return 0;
  4693. un = dev_get_drvdata(d);
  4694. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4695. return 0;
  4696. ch = un->un_ch;
  4697. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4698. return 0;
  4699. bd = ch->ch_bd;
  4700. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4701. return 0;
  4702. if (bd->state != BOARD_READY)
  4703. return 0;
  4704. return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_iflag);
  4705. }
  4706. static DEVICE_ATTR(iflag, S_IRUSR, dgap_tty_iflag_show, NULL);
  4707. static ssize_t dgap_tty_cflag_show(struct device *d,
  4708. struct device_attribute *attr,
  4709. char *buf)
  4710. {
  4711. struct board_t *bd;
  4712. struct channel_t *ch;
  4713. struct un_t *un;
  4714. if (!d)
  4715. return 0;
  4716. un = dev_get_drvdata(d);
  4717. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4718. return 0;
  4719. ch = un->un_ch;
  4720. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4721. return 0;
  4722. bd = ch->ch_bd;
  4723. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4724. return 0;
  4725. if (bd->state != BOARD_READY)
  4726. return 0;
  4727. return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_cflag);
  4728. }
  4729. static DEVICE_ATTR(cflag, S_IRUSR, dgap_tty_cflag_show, NULL);
  4730. static ssize_t dgap_tty_oflag_show(struct device *d,
  4731. struct device_attribute *attr,
  4732. char *buf)
  4733. {
  4734. struct board_t *bd;
  4735. struct channel_t *ch;
  4736. struct un_t *un;
  4737. if (!d)
  4738. return 0;
  4739. un = dev_get_drvdata(d);
  4740. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4741. return 0;
  4742. ch = un->un_ch;
  4743. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4744. return 0;
  4745. bd = ch->ch_bd;
  4746. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4747. return 0;
  4748. if (bd->state != BOARD_READY)
  4749. return 0;
  4750. return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_oflag);
  4751. }
  4752. static DEVICE_ATTR(oflag, S_IRUSR, dgap_tty_oflag_show, NULL);
  4753. static ssize_t dgap_tty_lflag_show(struct device *d,
  4754. struct device_attribute *attr,
  4755. char *buf)
  4756. {
  4757. struct board_t *bd;
  4758. struct channel_t *ch;
  4759. struct un_t *un;
  4760. if (!d)
  4761. return 0;
  4762. un = dev_get_drvdata(d);
  4763. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4764. return 0;
  4765. ch = un->un_ch;
  4766. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4767. return 0;
  4768. bd = ch->ch_bd;
  4769. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4770. return 0;
  4771. if (bd->state != BOARD_READY)
  4772. return 0;
  4773. return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_c_lflag);
  4774. }
  4775. static DEVICE_ATTR(lflag, S_IRUSR, dgap_tty_lflag_show, NULL);
  4776. static ssize_t dgap_tty_digi_flag_show(struct device *d,
  4777. struct device_attribute *attr,
  4778. char *buf)
  4779. {
  4780. struct board_t *bd;
  4781. struct channel_t *ch;
  4782. struct un_t *un;
  4783. if (!d)
  4784. return 0;
  4785. un = dev_get_drvdata(d);
  4786. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4787. return 0;
  4788. ch = un->un_ch;
  4789. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4790. return 0;
  4791. bd = ch->ch_bd;
  4792. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4793. return 0;
  4794. if (bd->state != BOARD_READY)
  4795. return 0;
  4796. return snprintf(buf, PAGE_SIZE, "%x\n", ch->ch_digi.digi_flags);
  4797. }
  4798. static DEVICE_ATTR(digi_flag, S_IRUSR, dgap_tty_digi_flag_show, NULL);
  4799. static ssize_t dgap_tty_rxcount_show(struct device *d,
  4800. struct device_attribute *attr,
  4801. char *buf)
  4802. {
  4803. struct board_t *bd;
  4804. struct channel_t *ch;
  4805. struct un_t *un;
  4806. if (!d)
  4807. return 0;
  4808. un = dev_get_drvdata(d);
  4809. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4810. return 0;
  4811. ch = un->un_ch;
  4812. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4813. return 0;
  4814. bd = ch->ch_bd;
  4815. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4816. return 0;
  4817. if (bd->state != BOARD_READY)
  4818. return 0;
  4819. return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_rxcount);
  4820. }
  4821. static DEVICE_ATTR(rxcount, S_IRUSR, dgap_tty_rxcount_show, NULL);
  4822. static ssize_t dgap_tty_txcount_show(struct device *d,
  4823. struct device_attribute *attr,
  4824. char *buf)
  4825. {
  4826. struct board_t *bd;
  4827. struct channel_t *ch;
  4828. struct un_t *un;
  4829. if (!d)
  4830. return 0;
  4831. un = dev_get_drvdata(d);
  4832. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4833. return 0;
  4834. ch = un->un_ch;
  4835. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4836. return 0;
  4837. bd = ch->ch_bd;
  4838. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4839. return 0;
  4840. if (bd->state != BOARD_READY)
  4841. return 0;
  4842. return snprintf(buf, PAGE_SIZE, "%ld\n", ch->ch_txcount);
  4843. }
  4844. static DEVICE_ATTR(txcount, S_IRUSR, dgap_tty_txcount_show, NULL);
  4845. static ssize_t dgap_tty_name_show(struct device *d,
  4846. struct device_attribute *attr,
  4847. char *buf)
  4848. {
  4849. struct board_t *bd;
  4850. struct channel_t *ch;
  4851. struct un_t *un;
  4852. int cn;
  4853. int bn;
  4854. struct cnode *cptr;
  4855. int found = FALSE;
  4856. int ncount = 0;
  4857. int starto = 0;
  4858. int i;
  4859. if (!d)
  4860. return 0;
  4861. un = dev_get_drvdata(d);
  4862. if (!un || un->magic != DGAP_UNIT_MAGIC)
  4863. return 0;
  4864. ch = un->un_ch;
  4865. if (!ch || ch->magic != DGAP_CHANNEL_MAGIC)
  4866. return 0;
  4867. bd = ch->ch_bd;
  4868. if (!bd || bd->magic != DGAP_BOARD_MAGIC)
  4869. return 0;
  4870. if (bd->state != BOARD_READY)
  4871. return 0;
  4872. bn = bd->boardnum;
  4873. cn = ch->ch_portnum;
  4874. for (cptr = bd->bd_config; cptr; cptr = cptr->next) {
  4875. if ((cptr->type == BNODE) &&
  4876. ((cptr->u.board.type == APORT2_920P) ||
  4877. (cptr->u.board.type == APORT4_920P) ||
  4878. (cptr->u.board.type == APORT8_920P) ||
  4879. (cptr->u.board.type == PAPORT4) ||
  4880. (cptr->u.board.type == PAPORT8))) {
  4881. found = TRUE;
  4882. if (cptr->u.board.v_start)
  4883. starto = cptr->u.board.start;
  4884. else
  4885. starto = 1;
  4886. }
  4887. if (cptr->type == TNODE && found == TRUE) {
  4888. char *ptr1;
  4889. if (strstr(cptr->u.ttyname, "tty")) {
  4890. ptr1 = cptr->u.ttyname;
  4891. ptr1 += 3;
  4892. } else
  4893. ptr1 = cptr->u.ttyname;
  4894. for (i = 0; i < dgap_config_get_num_prts(bd); i++) {
  4895. if (cn != i)
  4896. continue;
  4897. return snprintf(buf, PAGE_SIZE, "%s%s%02d\n",
  4898. (un->un_type == DGAP_PRINT) ?
  4899. "pr" : "tty",
  4900. ptr1, i + starto);
  4901. }
  4902. }
  4903. if (cptr->type == CNODE) {
  4904. for (i = 0; i < cptr->u.conc.nport; i++) {
  4905. if (cn != (i + ncount))
  4906. continue;
  4907. return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
  4908. (un->un_type == DGAP_PRINT) ?
  4909. "pr" : "tty",
  4910. cptr->u.conc.id,
  4911. i + (cptr->u.conc.v_start ?
  4912. cptr->u.conc.start : 1));
  4913. }
  4914. ncount += cptr->u.conc.nport;
  4915. }
  4916. if (cptr->type == MNODE) {
  4917. for (i = 0; i < cptr->u.module.nport; i++) {
  4918. if (cn != (i + ncount))
  4919. continue;
  4920. return snprintf(buf, PAGE_SIZE, "%s%s%02ld\n",
  4921. (un->un_type == DGAP_PRINT) ?
  4922. "pr" : "tty",
  4923. cptr->u.module.id,
  4924. i + (cptr->u.module.v_start ?
  4925. cptr->u.module.start : 1));
  4926. }
  4927. ncount += cptr->u.module.nport;
  4928. }
  4929. }
  4930. return snprintf(buf, PAGE_SIZE, "%s_dgap_%d_%d\n",
  4931. (un->un_type == DGAP_PRINT) ? "pr" : "tty", bn, cn);
  4932. }
  4933. static DEVICE_ATTR(custom_name, S_IRUSR, dgap_tty_name_show, NULL);
  4934. static struct attribute *dgap_sysfs_tty_entries[] = {
  4935. &dev_attr_state.attr,
  4936. &dev_attr_baud.attr,
  4937. &dev_attr_msignals.attr,
  4938. &dev_attr_iflag.attr,
  4939. &dev_attr_cflag.attr,
  4940. &dev_attr_oflag.attr,
  4941. &dev_attr_lflag.attr,
  4942. &dev_attr_digi_flag.attr,
  4943. &dev_attr_rxcount.attr,
  4944. &dev_attr_txcount.attr,
  4945. &dev_attr_custom_name.attr,
  4946. NULL
  4947. };
  4948. /* this function creates the sys files that will export each signal status
  4949. * to sysfs each value will be put in a separate filename
  4950. */
  4951. static void dgap_create_ports_sysfiles(struct board_t *bd)
  4952. {
  4953. dev_set_drvdata(&bd->pdev->dev, bd);
  4954. device_create_file(&bd->pdev->dev, &dev_attr_ports_state);
  4955. device_create_file(&bd->pdev->dev, &dev_attr_ports_baud);
  4956. device_create_file(&bd->pdev->dev, &dev_attr_ports_msignals);
  4957. device_create_file(&bd->pdev->dev, &dev_attr_ports_iflag);
  4958. device_create_file(&bd->pdev->dev, &dev_attr_ports_cflag);
  4959. device_create_file(&bd->pdev->dev, &dev_attr_ports_oflag);
  4960. device_create_file(&bd->pdev->dev, &dev_attr_ports_lflag);
  4961. device_create_file(&bd->pdev->dev, &dev_attr_ports_digi_flag);
  4962. device_create_file(&bd->pdev->dev, &dev_attr_ports_rxcount);
  4963. device_create_file(&bd->pdev->dev, &dev_attr_ports_txcount);
  4964. }
  4965. /* removes all the sys files created for that port */
  4966. static void dgap_remove_ports_sysfiles(struct board_t *bd)
  4967. {
  4968. device_remove_file(&bd->pdev->dev, &dev_attr_ports_state);
  4969. device_remove_file(&bd->pdev->dev, &dev_attr_ports_baud);
  4970. device_remove_file(&bd->pdev->dev, &dev_attr_ports_msignals);
  4971. device_remove_file(&bd->pdev->dev, &dev_attr_ports_iflag);
  4972. device_remove_file(&bd->pdev->dev, &dev_attr_ports_cflag);
  4973. device_remove_file(&bd->pdev->dev, &dev_attr_ports_oflag);
  4974. device_remove_file(&bd->pdev->dev, &dev_attr_ports_lflag);
  4975. device_remove_file(&bd->pdev->dev, &dev_attr_ports_digi_flag);
  4976. device_remove_file(&bd->pdev->dev, &dev_attr_ports_rxcount);
  4977. device_remove_file(&bd->pdev->dev, &dev_attr_ports_txcount);
  4978. }
  4979. /*
  4980. * Copies the BIOS code from the user to the board,
  4981. * and starts the BIOS running.
  4982. */
  4983. static void dgap_do_bios_load(struct board_t *brd, const u8 *ubios, int len)
  4984. {
  4985. u8 __iomem *addr;
  4986. uint offset;
  4987. unsigned int i;
  4988. if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
  4989. return;
  4990. addr = brd->re_map_membase;
  4991. /*
  4992. * clear POST area
  4993. */
  4994. for (i = 0; i < 16; i++)
  4995. writeb(0, addr + POSTAREA + i);
  4996. /*
  4997. * Download bios
  4998. */
  4999. offset = 0x1000;
  5000. memcpy_toio(addr + offset, ubios, len);
  5001. writel(0x0bf00401, addr);
  5002. writel(0, (addr + 4));
  5003. /* Clear the reset, and change states. */
  5004. writeb(FEPCLR, brd->re_map_port);
  5005. }
  5006. /*
  5007. * Checks to see if the BIOS completed running on the card.
  5008. */
  5009. static int dgap_test_bios(struct board_t *brd)
  5010. {
  5011. u8 __iomem *addr;
  5012. u16 word;
  5013. u16 err1;
  5014. u16 err2;
  5015. if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
  5016. return -EINVAL;
  5017. addr = brd->re_map_membase;
  5018. word = readw(addr + POSTAREA);
  5019. /*
  5020. * It can take 5-6 seconds for a board to
  5021. * pass the bios self test and post results.
  5022. * Give it 10 seconds.
  5023. */
  5024. brd->wait_for_bios = 0;
  5025. while (brd->wait_for_bios < 1000) {
  5026. /* Check to see if BIOS thinks board is good. (GD). */
  5027. if (word == *(u16 *)"GD")
  5028. return 0;
  5029. msleep_interruptible(10);
  5030. brd->wait_for_bios++;
  5031. word = readw(addr + POSTAREA);
  5032. }
  5033. /* Gave up on board after too long of time taken */
  5034. err1 = readw(addr + SEQUENCE);
  5035. err2 = readw(addr + ERROR);
  5036. dev_warn(&brd->pdev->dev, "%s failed diagnostics. Error #(%x,%x).\n",
  5037. brd->name, err1, err2);
  5038. brd->state = BOARD_FAILED;
  5039. brd->dpastatus = BD_NOBIOS;
  5040. return -EIO;
  5041. }
  5042. /*
  5043. * Copies the FEP code from the user to the board,
  5044. * and starts the FEP running.
  5045. */
  5046. static void dgap_do_fep_load(struct board_t *brd, const u8 *ufep, int len)
  5047. {
  5048. u8 __iomem *addr;
  5049. uint offset;
  5050. if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
  5051. return;
  5052. addr = brd->re_map_membase;
  5053. /*
  5054. * Download FEP
  5055. */
  5056. offset = 0x1000;
  5057. memcpy_toio(addr + offset, ufep, len);
  5058. /*
  5059. * If board is a concentrator product, we need to give
  5060. * it its config string describing how the concentrators look.
  5061. */
  5062. if ((brd->type == PCX) || (brd->type == PEPC)) {
  5063. u8 string[100];
  5064. u8 __iomem *config;
  5065. u8 *xconfig;
  5066. unsigned int i = 0;
  5067. xconfig = dgap_create_config_string(brd, string);
  5068. /* Write string to board memory */
  5069. config = addr + CONFIG;
  5070. for (; i < CONFIGSIZE; i++, config++, xconfig++) {
  5071. writeb(*xconfig, config);
  5072. if ((*xconfig & 0xff) == 0xff)
  5073. break;
  5074. }
  5075. }
  5076. writel(0xbfc01004, (addr + 0xc34));
  5077. writel(0x3, (addr + 0xc30));
  5078. }
  5079. /*
  5080. * Waits for the FEP to report thats its ready for us to use.
  5081. */
  5082. static int dgap_test_fep(struct board_t *brd)
  5083. {
  5084. u8 __iomem *addr;
  5085. u16 word;
  5086. u16 err1;
  5087. u16 err2;
  5088. if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
  5089. return -EINVAL;
  5090. addr = brd->re_map_membase;
  5091. word = readw(addr + FEPSTAT);
  5092. /*
  5093. * It can take 2-3 seconds for the FEP to
  5094. * be up and running. Give it 5 secs.
  5095. */
  5096. brd->wait_for_fep = 0;
  5097. while (brd->wait_for_fep < 500) {
  5098. /* Check to see if FEP is up and running now. */
  5099. if (word == *(u16 *)"OS") {
  5100. /*
  5101. * Check to see if the board can support FEP5+ commands.
  5102. */
  5103. word = readw(addr + FEP5_PLUS);
  5104. if (word == *(u16 *)"5A")
  5105. brd->bd_flags |= BD_FEP5PLUS;
  5106. return 0;
  5107. }
  5108. msleep_interruptible(10);
  5109. brd->wait_for_fep++;
  5110. word = readw(addr + FEPSTAT);
  5111. }
  5112. /* Gave up on board after too long of time taken */
  5113. err1 = readw(addr + SEQUENCE);
  5114. err2 = readw(addr + ERROR);
  5115. dev_warn(&brd->pdev->dev,
  5116. "FEPOS for %s not functioning. Error #(%x,%x).\n",
  5117. brd->name, err1, err2);
  5118. brd->state = BOARD_FAILED;
  5119. brd->dpastatus = BD_NOFEP;
  5120. return -EIO;
  5121. }
  5122. /*
  5123. * Physically forces the FEP5 card to reset itself.
  5124. */
  5125. static void dgap_do_reset_board(struct board_t *brd)
  5126. {
  5127. u8 check;
  5128. u32 check1;
  5129. u32 check2;
  5130. unsigned int i;
  5131. if (!brd || (brd->magic != DGAP_BOARD_MAGIC) ||
  5132. !brd->re_map_membase || !brd->re_map_port)
  5133. return;
  5134. /* FEPRST does not vary among supported boards */
  5135. writeb(FEPRST, brd->re_map_port);
  5136. for (i = 0; i <= 1000; i++) {
  5137. check = readb(brd->re_map_port) & 0xe;
  5138. if (check == FEPRST)
  5139. break;
  5140. udelay(10);
  5141. }
  5142. if (i > 1000) {
  5143. dev_warn(&brd->pdev->dev,
  5144. "dgap: Board not resetting... Failing board.\n");
  5145. brd->state = BOARD_FAILED;
  5146. brd->dpastatus = BD_NOFEP;
  5147. return;
  5148. }
  5149. /*
  5150. * Make sure there really is memory out there.
  5151. */
  5152. writel(0xa55a3cc3, (brd->re_map_membase + LOWMEM));
  5153. writel(0x5aa5c33c, (brd->re_map_membase + HIGHMEM));
  5154. check1 = readl(brd->re_map_membase + LOWMEM);
  5155. check2 = readl(brd->re_map_membase + HIGHMEM);
  5156. if ((check1 != 0xa55a3cc3) || (check2 != 0x5aa5c33c)) {
  5157. dev_warn(&brd->pdev->dev,
  5158. "No memory at %p for board.\n",
  5159. brd->re_map_membase);
  5160. brd->state = BOARD_FAILED;
  5161. brd->dpastatus = BD_NOFEP;
  5162. return;
  5163. }
  5164. }
  5165. #ifdef DIGI_CONCENTRATORS_SUPPORTED
  5166. /*
  5167. * Sends a concentrator image into the FEP5 board.
  5168. */
  5169. static void dgap_do_conc_load(struct board_t *brd, u8 *uaddr, int len)
  5170. {
  5171. char __iomem *vaddr;
  5172. u16 offset;
  5173. struct downld_t *to_dp;
  5174. if (!brd || (brd->magic != DGAP_BOARD_MAGIC) || !brd->re_map_membase)
  5175. return;
  5176. vaddr = brd->re_map_membase;
  5177. offset = readw((u16 *)(vaddr + DOWNREQ));
  5178. to_dp = (struct downld_t *)(vaddr + (int)offset);
  5179. memcpy_toio(to_dp, uaddr, len);
  5180. /* Tell card we have data for it */
  5181. writew(0, vaddr + (DOWNREQ));
  5182. brd->conc_dl_status = NO_PENDING_CONCENTRATOR_REQUESTS;
  5183. }
  5184. #endif
  5185. #define EXPANSION_ROM_SIZE (64 * 1024)
  5186. #define FEP5_ROM_MAGIC (0xFEFFFFFF)
  5187. static void dgap_get_vpd(struct board_t *brd)
  5188. {
  5189. u32 magic;
  5190. u32 base_offset;
  5191. u16 rom_offset;
  5192. u16 vpd_offset;
  5193. u16 image_length;
  5194. u16 i;
  5195. u8 byte1;
  5196. u8 byte2;
  5197. /*
  5198. * Poke the magic number at the PCI Rom Address location.
  5199. * If VPD is supported, the value read from that address
  5200. * will be non-zero.
  5201. */
  5202. magic = FEP5_ROM_MAGIC;
  5203. pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
  5204. pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
  5205. /* VPD not supported, bail */
  5206. if (!magic)
  5207. return;
  5208. /*
  5209. * To get to the OTPROM memory, we have to send the boards base
  5210. * address or'ed with 1 into the PCI Rom Address location.
  5211. */
  5212. magic = brd->membase | 0x01;
  5213. pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
  5214. pci_read_config_dword(brd->pdev, PCI_ROM_ADDRESS, &magic);
  5215. byte1 = readb(brd->re_map_membase);
  5216. byte2 = readb(brd->re_map_membase + 1);
  5217. /*
  5218. * If the board correctly swapped to the OTPROM memory,
  5219. * the first 2 bytes (header) should be 0x55, 0xAA
  5220. */
  5221. if (byte1 == 0x55 && byte2 == 0xAA) {
  5222. base_offset = 0;
  5223. /*
  5224. * We have to run through all the OTPROM memory looking
  5225. * for the VPD offset.
  5226. */
  5227. while (base_offset <= EXPANSION_ROM_SIZE) {
  5228. /*
  5229. * Lots of magic numbers here.
  5230. *
  5231. * The VPD offset is located inside the ROM Data
  5232. * Structure.
  5233. *
  5234. * We also have to remember the length of each
  5235. * ROM Data Structure, so we can "hop" to the next
  5236. * entry if the VPD isn't in the current
  5237. * ROM Data Structure.
  5238. */
  5239. rom_offset = readw(brd->re_map_membase +
  5240. base_offset + 0x18);
  5241. image_length = readw(brd->re_map_membase +
  5242. rom_offset + 0x10) * 512;
  5243. vpd_offset = readw(brd->re_map_membase +
  5244. rom_offset + 0x08);
  5245. /* Found the VPD entry */
  5246. if (vpd_offset)
  5247. break;
  5248. /* We didn't find a VPD entry, go to next ROM entry. */
  5249. base_offset += image_length;
  5250. byte1 = readb(brd->re_map_membase + base_offset);
  5251. byte2 = readb(brd->re_map_membase + base_offset + 1);
  5252. /*
  5253. * If the new ROM offset doesn't have 0x55, 0xAA
  5254. * as its header, we have run out of ROM.
  5255. */
  5256. if (byte1 != 0x55 || byte2 != 0xAA)
  5257. break;
  5258. }
  5259. /*
  5260. * If we have a VPD offset, then mark the board
  5261. * as having a valid VPD, and copy VPDSIZE (512) bytes of
  5262. * that VPD to the buffer we have in our board structure.
  5263. */
  5264. if (vpd_offset) {
  5265. brd->bd_flags |= BD_HAS_VPD;
  5266. for (i = 0; i < VPDSIZE; i++) {
  5267. brd->vpd[i] = readb(brd->re_map_membase +
  5268. vpd_offset + i);
  5269. }
  5270. }
  5271. }
  5272. /*
  5273. * We MUST poke the magic number at the PCI Rom Address location again.
  5274. * This makes the card report the regular board memory back to us,
  5275. * rather than the OTPROM memory.
  5276. */
  5277. magic = FEP5_ROM_MAGIC;
  5278. pci_write_config_dword(brd->pdev, PCI_ROM_ADDRESS, magic);
  5279. }
  5280. static ssize_t dgap_driver_version_show(struct device_driver *ddp, char *buf)
  5281. {
  5282. return snprintf(buf, PAGE_SIZE, "%s\n", DG_PART);
  5283. }
  5284. static DRIVER_ATTR(version, S_IRUSR, dgap_driver_version_show, NULL);
  5285. static ssize_t dgap_driver_boards_show(struct device_driver *ddp, char *buf)
  5286. {
  5287. return snprintf(buf, PAGE_SIZE, "%d\n", dgap_numboards);
  5288. }
  5289. static DRIVER_ATTR(boards, S_IRUSR, dgap_driver_boards_show, NULL);
  5290. static ssize_t dgap_driver_maxboards_show(struct device_driver *ddp, char *buf)
  5291. {
  5292. return snprintf(buf, PAGE_SIZE, "%d\n", MAXBOARDS);
  5293. }
  5294. static DRIVER_ATTR(maxboards, S_IRUSR, dgap_driver_maxboards_show, NULL);
  5295. static ssize_t dgap_driver_pollcounter_show(struct device_driver *ddp,
  5296. char *buf)
  5297. {
  5298. return snprintf(buf, PAGE_SIZE, "%ld\n", dgap_poll_counter);
  5299. }
  5300. static DRIVER_ATTR(pollcounter, S_IRUSR, dgap_driver_pollcounter_show, NULL);
  5301. static ssize_t dgap_driver_pollrate_show(struct device_driver *ddp, char *buf)
  5302. {
  5303. return snprintf(buf, PAGE_SIZE, "%dms\n", dgap_poll_tick);
  5304. }
  5305. static ssize_t dgap_driver_pollrate_store(struct device_driver *ddp,
  5306. const char *buf, size_t count)
  5307. {
  5308. if (sscanf(buf, "%d\n", &dgap_poll_tick) != 1)
  5309. return -EINVAL;
  5310. return count;
  5311. }
  5312. static DRIVER_ATTR(pollrate, (S_IRUSR | S_IWUSR), dgap_driver_pollrate_show,
  5313. dgap_driver_pollrate_store);
  5314. static int dgap_create_driver_sysfiles(struct pci_driver *dgap_driver)
  5315. {
  5316. int rc = 0;
  5317. struct device_driver *driverfs = &dgap_driver->driver;
  5318. rc |= driver_create_file(driverfs, &driver_attr_version);
  5319. rc |= driver_create_file(driverfs, &driver_attr_boards);
  5320. rc |= driver_create_file(driverfs, &driver_attr_maxboards);
  5321. rc |= driver_create_file(driverfs, &driver_attr_pollrate);
  5322. rc |= driver_create_file(driverfs, &driver_attr_pollcounter);
  5323. return rc;
  5324. }
  5325. static void dgap_remove_driver_sysfiles(struct pci_driver *dgap_driver)
  5326. {
  5327. struct device_driver *driverfs = &dgap_driver->driver;
  5328. driver_remove_file(driverfs, &driver_attr_version);
  5329. driver_remove_file(driverfs, &driver_attr_boards);
  5330. driver_remove_file(driverfs, &driver_attr_maxboards);
  5331. driver_remove_file(driverfs, &driver_attr_pollrate);
  5332. driver_remove_file(driverfs, &driver_attr_pollcounter);
  5333. }
  5334. static struct attribute_group dgap_tty_attribute_group = {
  5335. .name = NULL,
  5336. .attrs = dgap_sysfs_tty_entries,
  5337. };
  5338. static void dgap_create_tty_sysfs(struct un_t *un, struct device *c)
  5339. {
  5340. int ret;
  5341. ret = sysfs_create_group(&c->kobj, &dgap_tty_attribute_group);
  5342. if (ret)
  5343. return;
  5344. dev_set_drvdata(c, un);
  5345. }
  5346. static void dgap_remove_tty_sysfs(struct device *c)
  5347. {
  5348. sysfs_remove_group(&c->kobj, &dgap_tty_attribute_group);
  5349. }
  5350. /*
  5351. * Create pr and tty device entries
  5352. */
  5353. static int dgap_tty_register_ports(struct board_t *brd)
  5354. {
  5355. struct channel_t *ch;
  5356. int i;
  5357. int ret;
  5358. brd->serial_ports = kcalloc(brd->nasync, sizeof(*brd->serial_ports),
  5359. GFP_KERNEL);
  5360. if (!brd->serial_ports)
  5361. return -ENOMEM;
  5362. brd->printer_ports = kcalloc(brd->nasync, sizeof(*brd->printer_ports),
  5363. GFP_KERNEL);
  5364. if (!brd->printer_ports) {
  5365. ret = -ENOMEM;
  5366. goto free_serial_ports;
  5367. }
  5368. for (i = 0; i < brd->nasync; i++) {
  5369. tty_port_init(&brd->serial_ports[i]);
  5370. tty_port_init(&brd->printer_ports[i]);
  5371. }
  5372. ch = brd->channels[0];
  5373. for (i = 0; i < brd->nasync; i++, ch = brd->channels[i]) {
  5374. struct device *classp;
  5375. classp = tty_port_register_device(&brd->serial_ports[i],
  5376. brd->serial_driver,
  5377. i, NULL);
  5378. if (IS_ERR(classp)) {
  5379. ret = PTR_ERR(classp);
  5380. goto unregister_ttys;
  5381. }
  5382. dgap_create_tty_sysfs(&ch->ch_tun, classp);
  5383. ch->ch_tun.un_sysfs = classp;
  5384. classp = tty_port_register_device(&brd->printer_ports[i],
  5385. brd->print_driver,
  5386. i, NULL);
  5387. if (IS_ERR(classp)) {
  5388. ret = PTR_ERR(classp);
  5389. goto unregister_ttys;
  5390. }
  5391. dgap_create_tty_sysfs(&ch->ch_pun, classp);
  5392. ch->ch_pun.un_sysfs = classp;
  5393. }
  5394. dgap_create_ports_sysfiles(brd);
  5395. return 0;
  5396. unregister_ttys:
  5397. while (i >= 0) {
  5398. ch = brd->channels[i];
  5399. if (ch->ch_tun.un_sysfs) {
  5400. dgap_remove_tty_sysfs(ch->ch_tun.un_sysfs);
  5401. tty_unregister_device(brd->serial_driver, i);
  5402. }
  5403. if (ch->ch_pun.un_sysfs) {
  5404. dgap_remove_tty_sysfs(ch->ch_pun.un_sysfs);
  5405. tty_unregister_device(brd->print_driver, i);
  5406. }
  5407. i--;
  5408. }
  5409. for (i = 0; i < brd->nasync; i++) {
  5410. tty_port_destroy(&brd->serial_ports[i]);
  5411. tty_port_destroy(&brd->printer_ports[i]);
  5412. }
  5413. kfree(brd->printer_ports);
  5414. brd->printer_ports = NULL;
  5415. free_serial_ports:
  5416. kfree(brd->serial_ports);
  5417. brd->serial_ports = NULL;
  5418. return ret;
  5419. }
  5420. /*
  5421. * dgap_cleanup_tty()
  5422. *
  5423. * Uninitialize the TTY portion of this driver. Free all memory and
  5424. * resources.
  5425. */
  5426. static void dgap_cleanup_tty(struct board_t *brd)
  5427. {
  5428. struct device *dev;
  5429. unsigned int i;
  5430. for (i = 0; i < brd->nasync; i++) {
  5431. tty_port_destroy(&brd->serial_ports[i]);
  5432. dev = brd->channels[i]->ch_tun.un_sysfs;
  5433. dgap_remove_tty_sysfs(dev);
  5434. tty_unregister_device(brd->serial_driver, i);
  5435. }
  5436. tty_unregister_driver(brd->serial_driver);
  5437. put_tty_driver(brd->serial_driver);
  5438. kfree(brd->serial_ports);
  5439. for (i = 0; i < brd->nasync; i++) {
  5440. tty_port_destroy(&brd->printer_ports[i]);
  5441. dev = brd->channels[i]->ch_pun.un_sysfs;
  5442. dgap_remove_tty_sysfs(dev);
  5443. tty_unregister_device(brd->print_driver, i);
  5444. }
  5445. tty_unregister_driver(brd->print_driver);
  5446. put_tty_driver(brd->print_driver);
  5447. kfree(brd->printer_ports);
  5448. }
  5449. static int dgap_request_irq(struct board_t *brd)
  5450. {
  5451. int rc;
  5452. if (!brd || brd->magic != DGAP_BOARD_MAGIC)
  5453. return -ENODEV;
  5454. /*
  5455. * Set up our interrupt handler if we are set to do interrupts.
  5456. */
  5457. if (dgap_config_get_useintr(brd) && brd->irq) {
  5458. rc = request_irq(brd->irq, dgap_intr, IRQF_SHARED, "DGAP", brd);
  5459. if (!rc)
  5460. brd->intr_used = 1;
  5461. }
  5462. return 0;
  5463. }
  5464. static void dgap_free_irq(struct board_t *brd)
  5465. {
  5466. if (brd->intr_used && brd->irq)
  5467. free_irq(brd->irq, brd);
  5468. }
  5469. static int dgap_firmware_load(struct pci_dev *pdev, int card_type,
  5470. struct board_t *brd)
  5471. {
  5472. const struct firmware *fw;
  5473. char *tmp_ptr;
  5474. int ret;
  5475. char *dgap_config_buf;
  5476. dgap_get_vpd(brd);
  5477. dgap_do_reset_board(brd);
  5478. if (fw_info[card_type].conf_name) {
  5479. ret = request_firmware(&fw, fw_info[card_type].conf_name,
  5480. &pdev->dev);
  5481. if (ret) {
  5482. dev_err(&pdev->dev, "config file %s not found\n",
  5483. fw_info[card_type].conf_name);
  5484. return ret;
  5485. }
  5486. dgap_config_buf = kzalloc(fw->size + 1, GFP_KERNEL);
  5487. if (!dgap_config_buf) {
  5488. release_firmware(fw);
  5489. return -ENOMEM;
  5490. }
  5491. memcpy(dgap_config_buf, fw->data, fw->size);
  5492. release_firmware(fw);
  5493. /*
  5494. * preserve dgap_config_buf
  5495. * as dgap_parsefile would
  5496. * otherwise alter it.
  5497. */
  5498. tmp_ptr = dgap_config_buf;
  5499. if (dgap_parsefile(&tmp_ptr) != 0) {
  5500. kfree(dgap_config_buf);
  5501. return -EINVAL;
  5502. }
  5503. kfree(dgap_config_buf);
  5504. }
  5505. /*
  5506. * Match this board to a config the user created for us.
  5507. */
  5508. brd->bd_config =
  5509. dgap_find_config(brd->type, brd->pci_bus, brd->pci_slot);
  5510. /*
  5511. * Because the 4 port Xr products share the same PCI ID
  5512. * as the 8 port Xr products, if we receive a NULL config
  5513. * back, and this is a PAPORT8 board, retry with a
  5514. * PAPORT4 attempt as well.
  5515. */
  5516. if (brd->type == PAPORT8 && !brd->bd_config)
  5517. brd->bd_config =
  5518. dgap_find_config(PAPORT4, brd->pci_bus, brd->pci_slot);
  5519. if (!brd->bd_config) {
  5520. dev_err(&pdev->dev, "No valid configuration found\n");
  5521. return -EINVAL;
  5522. }
  5523. if (fw_info[card_type].bios_name) {
  5524. ret = request_firmware(&fw, fw_info[card_type].bios_name,
  5525. &pdev->dev);
  5526. if (ret) {
  5527. dev_err(&pdev->dev, "bios file %s not found\n",
  5528. fw_info[card_type].bios_name);
  5529. return ret;
  5530. }
  5531. dgap_do_bios_load(brd, fw->data, fw->size);
  5532. release_firmware(fw);
  5533. /* Wait for BIOS to test board... */
  5534. ret = dgap_test_bios(brd);
  5535. if (ret)
  5536. return ret;
  5537. }
  5538. if (fw_info[card_type].fep_name) {
  5539. ret = request_firmware(&fw, fw_info[card_type].fep_name,
  5540. &pdev->dev);
  5541. if (ret) {
  5542. dev_err(&pdev->dev, "dgap: fep file %s not found\n",
  5543. fw_info[card_type].fep_name);
  5544. return ret;
  5545. }
  5546. dgap_do_fep_load(brd, fw->data, fw->size);
  5547. release_firmware(fw);
  5548. /* Wait for FEP to load on board... */
  5549. ret = dgap_test_fep(brd);
  5550. if (ret)
  5551. return ret;
  5552. }
  5553. #ifdef DIGI_CONCENTRATORS_SUPPORTED
  5554. /*
  5555. * If this is a CX or EPCX, we need to see if the firmware
  5556. * is requesting a concentrator image from us.
  5557. */
  5558. if ((bd->type == PCX) || (bd->type == PEPC)) {
  5559. chk_addr = (u16 *)(vaddr + DOWNREQ);
  5560. /* Nonzero if FEP is requesting concentrator image. */
  5561. check = readw(chk_addr);
  5562. vaddr = brd->re_map_membase;
  5563. }
  5564. if (fw_info[card_type].con_name && check && vaddr) {
  5565. ret = request_firmware(&fw, fw_info[card_type].con_name,
  5566. &pdev->dev);
  5567. if (ret) {
  5568. dev_err(&pdev->dev, "conc file %s not found\n",
  5569. fw_info[card_type].con_name);
  5570. return ret;
  5571. }
  5572. /* Put concentrator firmware loading code here */
  5573. offset = readw((u16 *)(vaddr + DOWNREQ));
  5574. memcpy_toio(offset, fw->data, fw->size);
  5575. dgap_do_conc_load(brd, (char *)fw->data, fw->size)
  5576. release_firmware(fw);
  5577. }
  5578. #endif
  5579. return 0;
  5580. }
  5581. /*
  5582. * dgap_tty_init()
  5583. *
  5584. * Init the tty subsystem. Called once per board after board has been
  5585. * downloaded and init'ed.
  5586. */
  5587. static int dgap_tty_init(struct board_t *brd)
  5588. {
  5589. int i;
  5590. int tlw;
  5591. uint true_count;
  5592. u8 __iomem *vaddr;
  5593. u8 modem;
  5594. struct channel_t *ch;
  5595. struct bs_t __iomem *bs;
  5596. struct cm_t __iomem *cm;
  5597. int ret;
  5598. /*
  5599. * Initialize board structure elements.
  5600. */
  5601. vaddr = brd->re_map_membase;
  5602. true_count = readw((vaddr + NCHAN));
  5603. brd->nasync = dgap_config_get_num_prts(brd);
  5604. if (!brd->nasync)
  5605. brd->nasync = brd->maxports;
  5606. if (brd->nasync > brd->maxports)
  5607. brd->nasync = brd->maxports;
  5608. if (true_count != brd->nasync) {
  5609. dev_warn(&brd->pdev->dev,
  5610. "%s configured for %d ports, has %d ports.\n",
  5611. brd->name, brd->nasync, true_count);
  5612. if ((brd->type == PPCM) &&
  5613. (true_count == 64 || true_count == 0)) {
  5614. dev_warn(&brd->pdev->dev,
  5615. "Please make SURE the EBI cable running from the card\n");
  5616. dev_warn(&brd->pdev->dev,
  5617. "to each EM module is plugged into EBI IN!\n");
  5618. }
  5619. brd->nasync = true_count;
  5620. /* If no ports, don't bother going any further */
  5621. if (!brd->nasync) {
  5622. brd->state = BOARD_FAILED;
  5623. brd->dpastatus = BD_NOFEP;
  5624. return -EIO;
  5625. }
  5626. }
  5627. /*
  5628. * Allocate channel memory that might not have been allocated
  5629. * when the driver was first loaded.
  5630. */
  5631. for (i = 0; i < brd->nasync; i++) {
  5632. brd->channels[i] =
  5633. kzalloc(sizeof(struct channel_t), GFP_KERNEL);
  5634. if (!brd->channels[i]) {
  5635. ret = -ENOMEM;
  5636. goto free_chan;
  5637. }
  5638. }
  5639. ch = brd->channels[0];
  5640. vaddr = brd->re_map_membase;
  5641. bs = (struct bs_t __iomem *)((ulong)vaddr + CHANBUF);
  5642. cm = (struct cm_t __iomem *)((ulong)vaddr + CMDBUF);
  5643. brd->bd_bs = bs;
  5644. /* Set up channel variables */
  5645. for (i = 0; i < brd->nasync; i++, ch = brd->channels[i], bs++) {
  5646. spin_lock_init(&ch->ch_lock);
  5647. /* Store all our magic numbers */
  5648. ch->magic = DGAP_CHANNEL_MAGIC;
  5649. ch->ch_tun.magic = DGAP_UNIT_MAGIC;
  5650. ch->ch_tun.un_type = DGAP_SERIAL;
  5651. ch->ch_tun.un_ch = ch;
  5652. ch->ch_tun.un_dev = i;
  5653. ch->ch_pun.magic = DGAP_UNIT_MAGIC;
  5654. ch->ch_pun.un_type = DGAP_PRINT;
  5655. ch->ch_pun.un_ch = ch;
  5656. ch->ch_pun.un_dev = i;
  5657. ch->ch_vaddr = vaddr;
  5658. ch->ch_bs = bs;
  5659. ch->ch_cm = cm;
  5660. ch->ch_bd = brd;
  5661. ch->ch_portnum = i;
  5662. ch->ch_digi = dgap_digi_init;
  5663. /*
  5664. * Set up digi dsr and dcd bits based on altpin flag.
  5665. */
  5666. if (dgap_config_get_altpin(brd)) {
  5667. ch->ch_dsr = DM_CD;
  5668. ch->ch_cd = DM_DSR;
  5669. ch->ch_digi.digi_flags |= DIGI_ALTPIN;
  5670. } else {
  5671. ch->ch_cd = DM_CD;
  5672. ch->ch_dsr = DM_DSR;
  5673. }
  5674. ch->ch_taddr = vaddr + (ioread16(&ch->ch_bs->tx_seg) << 4);
  5675. ch->ch_raddr = vaddr + (ioread16(&ch->ch_bs->rx_seg) << 4);
  5676. ch->ch_tx_win = 0;
  5677. ch->ch_rx_win = 0;
  5678. ch->ch_tsize = readw(&ch->ch_bs->tx_max) + 1;
  5679. ch->ch_rsize = readw(&ch->ch_bs->rx_max) + 1;
  5680. ch->ch_tstart = 0;
  5681. ch->ch_rstart = 0;
  5682. /*
  5683. * Set queue water marks, interrupt mask,
  5684. * and general tty parameters.
  5685. */
  5686. tlw = ch->ch_tsize >= 2000 ? ((ch->ch_tsize * 5) / 8) :
  5687. ch->ch_tsize / 2;
  5688. ch->ch_tlw = tlw;
  5689. dgap_cmdw(ch, STLOW, tlw, 0);
  5690. dgap_cmdw(ch, SRLOW, ch->ch_rsize / 2, 0);
  5691. dgap_cmdw(ch, SRHIGH, 7 * ch->ch_rsize / 8, 0);
  5692. ch->ch_mistat = readb(&ch->ch_bs->m_stat);
  5693. init_waitqueue_head(&ch->ch_flags_wait);
  5694. init_waitqueue_head(&ch->ch_tun.un_flags_wait);
  5695. init_waitqueue_head(&ch->ch_pun.un_flags_wait);
  5696. /* Turn on all modem interrupts for now */
  5697. modem = (DM_CD | DM_DSR | DM_CTS | DM_RI);
  5698. writeb(modem, &ch->ch_bs->m_int);
  5699. /*
  5700. * Set edelay to 0 if interrupts are turned on,
  5701. * otherwise set edelay to the usual 100.
  5702. */
  5703. if (brd->intr_used)
  5704. writew(0, &ch->ch_bs->edelay);
  5705. else
  5706. writew(100, &ch->ch_bs->edelay);
  5707. writeb(1, &ch->ch_bs->idata);
  5708. }
  5709. return 0;
  5710. free_chan:
  5711. while (--i >= 0) {
  5712. kfree(brd->channels[i]);
  5713. brd->channels[i] = NULL;
  5714. }
  5715. return ret;
  5716. }
  5717. /*
  5718. * dgap_tty_free()
  5719. *
  5720. * Free the channles which are allocated in dgap_tty_init().
  5721. */
  5722. static void dgap_tty_free(struct board_t *brd)
  5723. {
  5724. int i;
  5725. for (i = 0; i < brd->nasync; i++)
  5726. kfree(brd->channels[i]);
  5727. }
  5728. static int dgap_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  5729. {
  5730. int rc;
  5731. struct board_t *brd;
  5732. if (dgap_numboards >= MAXBOARDS)
  5733. return -EPERM;
  5734. rc = pci_enable_device(pdev);
  5735. if (rc)
  5736. return -EIO;
  5737. brd = dgap_found_board(pdev, ent->driver_data, dgap_numboards);
  5738. if (IS_ERR(brd))
  5739. return PTR_ERR(brd);
  5740. rc = dgap_firmware_load(pdev, ent->driver_data, brd);
  5741. if (rc)
  5742. goto cleanup_brd;
  5743. rc = dgap_alloc_flipbuf(brd);
  5744. if (rc)
  5745. goto cleanup_brd;
  5746. rc = dgap_tty_register(brd);
  5747. if (rc)
  5748. goto free_flipbuf;
  5749. rc = dgap_request_irq(brd);
  5750. if (rc)
  5751. goto unregister_tty;
  5752. /*
  5753. * Do tty device initialization.
  5754. */
  5755. rc = dgap_tty_init(brd);
  5756. if (rc < 0)
  5757. goto free_irq;
  5758. rc = dgap_tty_register_ports(brd);
  5759. if (rc)
  5760. goto tty_free;
  5761. brd->state = BOARD_READY;
  5762. brd->dpastatus = BD_RUNNING;
  5763. dgap_board[dgap_numboards++] = brd;
  5764. return 0;
  5765. tty_free:
  5766. dgap_tty_free(brd);
  5767. free_irq:
  5768. dgap_free_irq(brd);
  5769. unregister_tty:
  5770. dgap_tty_unregister(brd);
  5771. free_flipbuf:
  5772. dgap_free_flipbuf(brd);
  5773. cleanup_brd:
  5774. dgap_cleanup_nodes();
  5775. dgap_unmap(brd);
  5776. kfree(brd);
  5777. return rc;
  5778. }
  5779. /*
  5780. * dgap_cleanup_board()
  5781. *
  5782. * Free all the memory associated with a board
  5783. */
  5784. static void dgap_cleanup_board(struct board_t *brd)
  5785. {
  5786. unsigned int i;
  5787. if (!brd || brd->magic != DGAP_BOARD_MAGIC)
  5788. return;
  5789. dgap_free_irq(brd);
  5790. tasklet_kill(&brd->helper_tasklet);
  5791. dgap_unmap(brd);
  5792. /* Free all allocated channels structs */
  5793. for (i = 0; i < MAXPORTS ; i++)
  5794. kfree(brd->channels[i]);
  5795. kfree(brd->flipbuf);
  5796. kfree(brd->flipflagbuf);
  5797. dgap_board[brd->boardnum] = NULL;
  5798. kfree(brd);
  5799. }
  5800. static void dgap_stop(bool removesys, struct pci_driver *drv)
  5801. {
  5802. unsigned long lock_flags;
  5803. spin_lock_irqsave(&dgap_poll_lock, lock_flags);
  5804. dgap_poll_stop = 1;
  5805. spin_unlock_irqrestore(&dgap_poll_lock, lock_flags);
  5806. del_timer_sync(&dgap_poll_timer);
  5807. if (removesys)
  5808. dgap_remove_driver_sysfiles(drv);
  5809. device_destroy(dgap_class, MKDEV(DIGI_DGAP_MAJOR, 0));
  5810. class_destroy(dgap_class);
  5811. unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
  5812. }
  5813. static void dgap_remove_one(struct pci_dev *dev)
  5814. {
  5815. unsigned int i;
  5816. struct pci_driver *drv = to_pci_driver(dev->dev.driver);
  5817. dgap_stop(true, drv);
  5818. for (i = 0; i < dgap_numboards; ++i) {
  5819. dgap_remove_ports_sysfiles(dgap_board[i]);
  5820. dgap_cleanup_tty(dgap_board[i]);
  5821. dgap_cleanup_board(dgap_board[i]);
  5822. }
  5823. dgap_cleanup_nodes();
  5824. }
  5825. static struct pci_driver dgap_driver = {
  5826. .name = "dgap",
  5827. .probe = dgap_init_one,
  5828. .id_table = dgap_pci_tbl,
  5829. .remove = dgap_remove_one,
  5830. };
  5831. /*
  5832. * Start of driver.
  5833. */
  5834. static int dgap_start(void)
  5835. {
  5836. int rc;
  5837. unsigned long flags;
  5838. struct device *device;
  5839. dgap_numboards = 0;
  5840. pr_info("For the tools package please visit http://www.digi.com\n");
  5841. /*
  5842. * Register our base character device into the kernel.
  5843. */
  5844. /*
  5845. * Register management/dpa devices
  5846. */
  5847. rc = register_chrdev(DIGI_DGAP_MAJOR, "dgap", &dgap_board_fops);
  5848. if (rc < 0)
  5849. return rc;
  5850. dgap_class = class_create(THIS_MODULE, "dgap_mgmt");
  5851. if (IS_ERR(dgap_class)) {
  5852. rc = PTR_ERR(dgap_class);
  5853. goto failed_class;
  5854. }
  5855. device = device_create(dgap_class, NULL,
  5856. MKDEV(DIGI_DGAP_MAJOR, 0),
  5857. NULL, "dgap_mgmt");
  5858. if (IS_ERR(device)) {
  5859. rc = PTR_ERR(device);
  5860. goto failed_device;
  5861. }
  5862. /* Start the poller */
  5863. spin_lock_irqsave(&dgap_poll_lock, flags);
  5864. setup_timer(&dgap_poll_timer, dgap_poll_handler, 0);
  5865. dgap_poll_timer.data = 0;
  5866. dgap_poll_time = jiffies + dgap_jiffies_from_ms(dgap_poll_tick);
  5867. dgap_poll_timer.expires = dgap_poll_time;
  5868. spin_unlock_irqrestore(&dgap_poll_lock, flags);
  5869. add_timer(&dgap_poll_timer);
  5870. return rc;
  5871. failed_device:
  5872. class_destroy(dgap_class);
  5873. failed_class:
  5874. unregister_chrdev(DIGI_DGAP_MAJOR, "dgap");
  5875. return rc;
  5876. }
  5877. /************************************************************************
  5878. *
  5879. * Driver load/unload functions
  5880. *
  5881. ************************************************************************/
  5882. /*
  5883. * init_module()
  5884. *
  5885. * Module load. This is where it all starts.
  5886. */
  5887. static int dgap_init_module(void)
  5888. {
  5889. int rc;
  5890. pr_info("%s, Digi International Part Number %s\n", DG_NAME, DG_PART);
  5891. rc = dgap_start();
  5892. if (rc)
  5893. return rc;
  5894. rc = pci_register_driver(&dgap_driver);
  5895. if (rc) {
  5896. dgap_stop(false, NULL);
  5897. return rc;
  5898. }
  5899. rc = dgap_create_driver_sysfiles(&dgap_driver);
  5900. if (rc)
  5901. goto err_unregister;
  5902. dgap_driver_state = DRIVER_READY;
  5903. return 0;
  5904. err_unregister:
  5905. pci_unregister_driver(&dgap_driver);
  5906. return rc;
  5907. }
  5908. /*
  5909. * dgap_cleanup_module()
  5910. *
  5911. * Module unload. This is where it all ends.
  5912. */
  5913. static void dgap_cleanup_module(void)
  5914. {
  5915. if (dgap_numboards)
  5916. pci_unregister_driver(&dgap_driver);
  5917. }
  5918. module_init(dgap_init_module);
  5919. module_exit(dgap_cleanup_module);
  5920. MODULE_LICENSE("GPL");
  5921. MODULE_AUTHOR("Digi International, http://www.digi.com");
  5922. MODULE_DESCRIPTION("Driver for the Digi International EPCA PCI based product line");
  5923. MODULE_SUPPORTED_DEVICE("dgap");