dgap.c 168 KB

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