synclinkmp.c 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660
  1. /*
  2. * $Id: synclinkmp.c,v 4.38 2005/07/15 13:29:44 paulkf Exp $
  3. *
  4. * Device driver for Microgate SyncLink Multiport
  5. * high speed multiprotocol serial adapter.
  6. *
  7. * written by Paul Fulghum for Microgate Corporation
  8. * paulkf@microgate.com
  9. *
  10. * Microgate and SyncLink are trademarks of Microgate Corporation
  11. *
  12. * Derived from serial.c written by Theodore Ts'o and Linus Torvalds
  13. * This code is released under the GNU General Public License (GPL)
  14. *
  15. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  16. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  19. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  25. * OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #define VERSION(ver,rel,seq) (((ver)<<16) | ((rel)<<8) | (seq))
  28. #if defined(__i386__)
  29. # define BREAKPOINT() asm(" int $3");
  30. #else
  31. # define BREAKPOINT() { }
  32. #endif
  33. #define MAX_DEVICES 12
  34. #include <linux/config.h>
  35. #include <linux/module.h>
  36. #include <linux/errno.h>
  37. #include <linux/signal.h>
  38. #include <linux/sched.h>
  39. #include <linux/timer.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/pci.h>
  42. #include <linux/tty.h>
  43. #include <linux/tty_flip.h>
  44. #include <linux/serial.h>
  45. #include <linux/major.h>
  46. #include <linux/string.h>
  47. #include <linux/fcntl.h>
  48. #include <linux/ptrace.h>
  49. #include <linux/ioport.h>
  50. #include <linux/mm.h>
  51. #include <linux/slab.h>
  52. #include <linux/netdevice.h>
  53. #include <linux/vmalloc.h>
  54. #include <linux/init.h>
  55. #include <linux/delay.h>
  56. #include <linux/ioctl.h>
  57. #include <asm/system.h>
  58. #include <asm/io.h>
  59. #include <asm/irq.h>
  60. #include <asm/dma.h>
  61. #include <linux/bitops.h>
  62. #include <asm/types.h>
  63. #include <linux/termios.h>
  64. #include <linux/workqueue.h>
  65. #include <linux/hdlc.h>
  66. #ifdef CONFIG_HDLC_MODULE
  67. #define CONFIG_HDLC 1
  68. #endif
  69. #define GET_USER(error,value,addr) error = get_user(value,addr)
  70. #define COPY_FROM_USER(error,dest,src,size) error = copy_from_user(dest,src,size) ? -EFAULT : 0
  71. #define PUT_USER(error,value,addr) error = put_user(value,addr)
  72. #define COPY_TO_USER(error,dest,src,size) error = copy_to_user(dest,src,size) ? -EFAULT : 0
  73. #include <asm/uaccess.h>
  74. #include "linux/synclink.h"
  75. static MGSL_PARAMS default_params = {
  76. MGSL_MODE_HDLC, /* unsigned long mode */
  77. 0, /* unsigned char loopback; */
  78. HDLC_FLAG_UNDERRUN_ABORT15, /* unsigned short flags; */
  79. HDLC_ENCODING_NRZI_SPACE, /* unsigned char encoding; */
  80. 0, /* unsigned long clock_speed; */
  81. 0xff, /* unsigned char addr_filter; */
  82. HDLC_CRC_16_CCITT, /* unsigned short crc_type; */
  83. HDLC_PREAMBLE_LENGTH_8BITS, /* unsigned char preamble_length; */
  84. HDLC_PREAMBLE_PATTERN_NONE, /* unsigned char preamble; */
  85. 9600, /* unsigned long data_rate; */
  86. 8, /* unsigned char data_bits; */
  87. 1, /* unsigned char stop_bits; */
  88. ASYNC_PARITY_NONE /* unsigned char parity; */
  89. };
  90. /* size in bytes of DMA data buffers */
  91. #define SCABUFSIZE 1024
  92. #define SCA_MEM_SIZE 0x40000
  93. #define SCA_BASE_SIZE 512
  94. #define SCA_REG_SIZE 16
  95. #define SCA_MAX_PORTS 4
  96. #define SCAMAXDESC 128
  97. #define BUFFERLISTSIZE 4096
  98. /* SCA-I style DMA buffer descriptor */
  99. typedef struct _SCADESC
  100. {
  101. u16 next; /* lower l6 bits of next descriptor addr */
  102. u16 buf_ptr; /* lower 16 bits of buffer addr */
  103. u8 buf_base; /* upper 8 bits of buffer addr */
  104. u8 pad1;
  105. u16 length; /* length of buffer */
  106. u8 status; /* status of buffer */
  107. u8 pad2;
  108. } SCADESC, *PSCADESC;
  109. typedef struct _SCADESC_EX
  110. {
  111. /* device driver bookkeeping section */
  112. char *virt_addr; /* virtual address of data buffer */
  113. u16 phys_entry; /* lower 16-bits of physical address of this descriptor */
  114. } SCADESC_EX, *PSCADESC_EX;
  115. /* The queue of BH actions to be performed */
  116. #define BH_RECEIVE 1
  117. #define BH_TRANSMIT 2
  118. #define BH_STATUS 4
  119. #define IO_PIN_SHUTDOWN_LIMIT 100
  120. #define RELEVANT_IFLAG(iflag) (iflag & (IGNBRK|BRKINT|IGNPAR|PARMRK|INPCK))
  121. struct _input_signal_events {
  122. int ri_up;
  123. int ri_down;
  124. int dsr_up;
  125. int dsr_down;
  126. int dcd_up;
  127. int dcd_down;
  128. int cts_up;
  129. int cts_down;
  130. };
  131. /*
  132. * Device instance data structure
  133. */
  134. typedef struct _synclinkmp_info {
  135. void *if_ptr; /* General purpose pointer (used by SPPP) */
  136. int magic;
  137. int flags;
  138. int count; /* count of opens */
  139. int line;
  140. unsigned short close_delay;
  141. unsigned short closing_wait; /* time to wait before closing */
  142. struct mgsl_icount icount;
  143. struct tty_struct *tty;
  144. int timeout;
  145. int x_char; /* xon/xoff character */
  146. int blocked_open; /* # of blocked opens */
  147. u16 read_status_mask1; /* break detection (SR1 indications) */
  148. u16 read_status_mask2; /* parity/framing/overun (SR2 indications) */
  149. unsigned char ignore_status_mask1; /* break detection (SR1 indications) */
  150. unsigned char ignore_status_mask2; /* parity/framing/overun (SR2 indications) */
  151. unsigned char *tx_buf;
  152. int tx_put;
  153. int tx_get;
  154. int tx_count;
  155. wait_queue_head_t open_wait;
  156. wait_queue_head_t close_wait;
  157. wait_queue_head_t status_event_wait_q;
  158. wait_queue_head_t event_wait_q;
  159. struct timer_list tx_timer; /* HDLC transmit timeout timer */
  160. struct _synclinkmp_info *next_device; /* device list link */
  161. struct timer_list status_timer; /* input signal status check timer */
  162. spinlock_t lock; /* spinlock for synchronizing with ISR */
  163. struct work_struct task; /* task structure for scheduling bh */
  164. u32 max_frame_size; /* as set by device config */
  165. u32 pending_bh;
  166. int bh_running; /* Protection from multiple */
  167. int isr_overflow;
  168. int bh_requested;
  169. int dcd_chkcount; /* check counts to prevent */
  170. int cts_chkcount; /* too many IRQs if a signal */
  171. int dsr_chkcount; /* is floating */
  172. int ri_chkcount;
  173. char *buffer_list; /* virtual address of Rx & Tx buffer lists */
  174. unsigned long buffer_list_phys;
  175. unsigned int rx_buf_count; /* count of total allocated Rx buffers */
  176. SCADESC *rx_buf_list; /* list of receive buffer entries */
  177. SCADESC_EX rx_buf_list_ex[SCAMAXDESC]; /* list of receive buffer entries */
  178. unsigned int current_rx_buf;
  179. unsigned int tx_buf_count; /* count of total allocated Tx buffers */
  180. SCADESC *tx_buf_list; /* list of transmit buffer entries */
  181. SCADESC_EX tx_buf_list_ex[SCAMAXDESC]; /* list of transmit buffer entries */
  182. unsigned int last_tx_buf;
  183. unsigned char *tmp_rx_buf;
  184. unsigned int tmp_rx_buf_count;
  185. int rx_enabled;
  186. int rx_overflow;
  187. int tx_enabled;
  188. int tx_active;
  189. u32 idle_mode;
  190. unsigned char ie0_value;
  191. unsigned char ie1_value;
  192. unsigned char ie2_value;
  193. unsigned char ctrlreg_value;
  194. unsigned char old_signals;
  195. char device_name[25]; /* device instance name */
  196. int port_count;
  197. int adapter_num;
  198. int port_num;
  199. struct _synclinkmp_info *port_array[SCA_MAX_PORTS];
  200. unsigned int bus_type; /* expansion bus type (ISA,EISA,PCI) */
  201. unsigned int irq_level; /* interrupt level */
  202. unsigned long irq_flags;
  203. int irq_requested; /* nonzero if IRQ requested */
  204. MGSL_PARAMS params; /* communications parameters */
  205. unsigned char serial_signals; /* current serial signal states */
  206. int irq_occurred; /* for diagnostics use */
  207. unsigned int init_error; /* Initialization startup error */
  208. u32 last_mem_alloc;
  209. unsigned char* memory_base; /* shared memory address (PCI only) */
  210. u32 phys_memory_base;
  211. int shared_mem_requested;
  212. unsigned char* sca_base; /* HD64570 SCA Memory address */
  213. u32 phys_sca_base;
  214. u32 sca_offset;
  215. int sca_base_requested;
  216. unsigned char* lcr_base; /* local config registers (PCI only) */
  217. u32 phys_lcr_base;
  218. u32 lcr_offset;
  219. int lcr_mem_requested;
  220. unsigned char* statctrl_base; /* status/control register memory */
  221. u32 phys_statctrl_base;
  222. u32 statctrl_offset;
  223. int sca_statctrl_requested;
  224. u32 misc_ctrl_value;
  225. char flag_buf[MAX_ASYNC_BUFFER_SIZE];
  226. char char_buf[MAX_ASYNC_BUFFER_SIZE];
  227. BOOLEAN drop_rts_on_tx_done;
  228. struct _input_signal_events input_signal_events;
  229. /* SPPP/Cisco HDLC device parts */
  230. int netcount;
  231. int dosyncppp;
  232. spinlock_t netlock;
  233. #ifdef CONFIG_HDLC
  234. struct net_device *netdev;
  235. #endif
  236. } SLMP_INFO;
  237. #define MGSL_MAGIC 0x5401
  238. /*
  239. * define serial signal status change macros
  240. */
  241. #define MISCSTATUS_DCD_LATCHED (SerialSignal_DCD<<8) /* indicates change in DCD */
  242. #define MISCSTATUS_RI_LATCHED (SerialSignal_RI<<8) /* indicates change in RI */
  243. #define MISCSTATUS_CTS_LATCHED (SerialSignal_CTS<<8) /* indicates change in CTS */
  244. #define MISCSTATUS_DSR_LATCHED (SerialSignal_DSR<<8) /* change in DSR */
  245. /* Common Register macros */
  246. #define LPR 0x00
  247. #define PABR0 0x02
  248. #define PABR1 0x03
  249. #define WCRL 0x04
  250. #define WCRM 0x05
  251. #define WCRH 0x06
  252. #define DPCR 0x08
  253. #define DMER 0x09
  254. #define ISR0 0x10
  255. #define ISR1 0x11
  256. #define ISR2 0x12
  257. #define IER0 0x14
  258. #define IER1 0x15
  259. #define IER2 0x16
  260. #define ITCR 0x18
  261. #define INTVR 0x1a
  262. #define IMVR 0x1c
  263. /* MSCI Register macros */
  264. #define TRB 0x20
  265. #define TRBL 0x20
  266. #define TRBH 0x21
  267. #define SR0 0x22
  268. #define SR1 0x23
  269. #define SR2 0x24
  270. #define SR3 0x25
  271. #define FST 0x26
  272. #define IE0 0x28
  273. #define IE1 0x29
  274. #define IE2 0x2a
  275. #define FIE 0x2b
  276. #define CMD 0x2c
  277. #define MD0 0x2e
  278. #define MD1 0x2f
  279. #define MD2 0x30
  280. #define CTL 0x31
  281. #define SA0 0x32
  282. #define SA1 0x33
  283. #define IDL 0x34
  284. #define TMC 0x35
  285. #define RXS 0x36
  286. #define TXS 0x37
  287. #define TRC0 0x38
  288. #define TRC1 0x39
  289. #define RRC 0x3a
  290. #define CST0 0x3c
  291. #define CST1 0x3d
  292. /* Timer Register Macros */
  293. #define TCNT 0x60
  294. #define TCNTL 0x60
  295. #define TCNTH 0x61
  296. #define TCONR 0x62
  297. #define TCONRL 0x62
  298. #define TCONRH 0x63
  299. #define TMCS 0x64
  300. #define TEPR 0x65
  301. /* DMA Controller Register macros */
  302. #define DARL 0x80
  303. #define DARH 0x81
  304. #define DARB 0x82
  305. #define BAR 0x80
  306. #define BARL 0x80
  307. #define BARH 0x81
  308. #define BARB 0x82
  309. #define SAR 0x84
  310. #define SARL 0x84
  311. #define SARH 0x85
  312. #define SARB 0x86
  313. #define CPB 0x86
  314. #define CDA 0x88
  315. #define CDAL 0x88
  316. #define CDAH 0x89
  317. #define EDA 0x8a
  318. #define EDAL 0x8a
  319. #define EDAH 0x8b
  320. #define BFL 0x8c
  321. #define BFLL 0x8c
  322. #define BFLH 0x8d
  323. #define BCR 0x8e
  324. #define BCRL 0x8e
  325. #define BCRH 0x8f
  326. #define DSR 0x90
  327. #define DMR 0x91
  328. #define FCT 0x93
  329. #define DIR 0x94
  330. #define DCMD 0x95
  331. /* combine with timer or DMA register address */
  332. #define TIMER0 0x00
  333. #define TIMER1 0x08
  334. #define TIMER2 0x10
  335. #define TIMER3 0x18
  336. #define RXDMA 0x00
  337. #define TXDMA 0x20
  338. /* SCA Command Codes */
  339. #define NOOP 0x00
  340. #define TXRESET 0x01
  341. #define TXENABLE 0x02
  342. #define TXDISABLE 0x03
  343. #define TXCRCINIT 0x04
  344. #define TXCRCEXCL 0x05
  345. #define TXEOM 0x06
  346. #define TXABORT 0x07
  347. #define MPON 0x08
  348. #define TXBUFCLR 0x09
  349. #define RXRESET 0x11
  350. #define RXENABLE 0x12
  351. #define RXDISABLE 0x13
  352. #define RXCRCINIT 0x14
  353. #define RXREJECT 0x15
  354. #define SEARCHMP 0x16
  355. #define RXCRCEXCL 0x17
  356. #define RXCRCCALC 0x18
  357. #define CHRESET 0x21
  358. #define HUNT 0x31
  359. /* DMA command codes */
  360. #define SWABORT 0x01
  361. #define FEICLEAR 0x02
  362. /* IE0 */
  363. #define TXINTE BIT7
  364. #define RXINTE BIT6
  365. #define TXRDYE BIT1
  366. #define RXRDYE BIT0
  367. /* IE1 & SR1 */
  368. #define UDRN BIT7
  369. #define IDLE BIT6
  370. #define SYNCD BIT4
  371. #define FLGD BIT4
  372. #define CCTS BIT3
  373. #define CDCD BIT2
  374. #define BRKD BIT1
  375. #define ABTD BIT1
  376. #define GAPD BIT1
  377. #define BRKE BIT0
  378. #define IDLD BIT0
  379. /* IE2 & SR2 */
  380. #define EOM BIT7
  381. #define PMP BIT6
  382. #define SHRT BIT6
  383. #define PE BIT5
  384. #define ABT BIT5
  385. #define FRME BIT4
  386. #define RBIT BIT4
  387. #define OVRN BIT3
  388. #define CRCE BIT2
  389. /*
  390. * Global linked list of SyncLink devices
  391. */
  392. static SLMP_INFO *synclinkmp_device_list = NULL;
  393. static int synclinkmp_adapter_count = -1;
  394. static int synclinkmp_device_count = 0;
  395. /*
  396. * Set this param to non-zero to load eax with the
  397. * .text section address and breakpoint on module load.
  398. * This is useful for use with gdb and add-symbol-file command.
  399. */
  400. static int break_on_load=0;
  401. /*
  402. * Driver major number, defaults to zero to get auto
  403. * assigned major number. May be forced as module parameter.
  404. */
  405. static int ttymajor=0;
  406. /*
  407. * Array of user specified options for ISA adapters.
  408. */
  409. static int debug_level = 0;
  410. static int maxframe[MAX_DEVICES] = {0,};
  411. static int dosyncppp[MAX_DEVICES] = {0,};
  412. module_param(break_on_load, bool, 0);
  413. module_param(ttymajor, int, 0);
  414. module_param(debug_level, int, 0);
  415. module_param_array(maxframe, int, NULL, 0);
  416. module_param_array(dosyncppp, int, NULL, 0);
  417. static char *driver_name = "SyncLink MultiPort driver";
  418. static char *driver_version = "$Revision: 4.38 $";
  419. static int synclinkmp_init_one(struct pci_dev *dev,const struct pci_device_id *ent);
  420. static void synclinkmp_remove_one(struct pci_dev *dev);
  421. static struct pci_device_id synclinkmp_pci_tbl[] = {
  422. { PCI_VENDOR_ID_MICROGATE, PCI_DEVICE_ID_MICROGATE_SCA, PCI_ANY_ID, PCI_ANY_ID, },
  423. { 0, }, /* terminate list */
  424. };
  425. MODULE_DEVICE_TABLE(pci, synclinkmp_pci_tbl);
  426. MODULE_LICENSE("GPL");
  427. static struct pci_driver synclinkmp_pci_driver = {
  428. .name = "synclinkmp",
  429. .id_table = synclinkmp_pci_tbl,
  430. .probe = synclinkmp_init_one,
  431. .remove = __devexit_p(synclinkmp_remove_one),
  432. };
  433. static struct tty_driver *serial_driver;
  434. /* number of characters left in xmit buffer before we ask for more */
  435. #define WAKEUP_CHARS 256
  436. /* tty callbacks */
  437. static int open(struct tty_struct *tty, struct file * filp);
  438. static void close(struct tty_struct *tty, struct file * filp);
  439. static void hangup(struct tty_struct *tty);
  440. static void set_termios(struct tty_struct *tty, struct termios *old_termios);
  441. static int write(struct tty_struct *tty, const unsigned char *buf, int count);
  442. static void put_char(struct tty_struct *tty, unsigned char ch);
  443. static void send_xchar(struct tty_struct *tty, char ch);
  444. static void wait_until_sent(struct tty_struct *tty, int timeout);
  445. static int write_room(struct tty_struct *tty);
  446. static void flush_chars(struct tty_struct *tty);
  447. static void flush_buffer(struct tty_struct *tty);
  448. static void tx_hold(struct tty_struct *tty);
  449. static void tx_release(struct tty_struct *tty);
  450. static int ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  451. static int read_proc(char *page, char **start, off_t off, int count,int *eof, void *data);
  452. static int chars_in_buffer(struct tty_struct *tty);
  453. static void throttle(struct tty_struct * tty);
  454. static void unthrottle(struct tty_struct * tty);
  455. static void set_break(struct tty_struct *tty, int break_state);
  456. #ifdef CONFIG_HDLC
  457. #define dev_to_port(D) (dev_to_hdlc(D)->priv)
  458. static void hdlcdev_tx_done(SLMP_INFO *info);
  459. static void hdlcdev_rx(SLMP_INFO *info, char *buf, int size);
  460. static int hdlcdev_init(SLMP_INFO *info);
  461. static void hdlcdev_exit(SLMP_INFO *info);
  462. #endif
  463. /* ioctl handlers */
  464. static int get_stats(SLMP_INFO *info, struct mgsl_icount __user *user_icount);
  465. static int get_params(SLMP_INFO *info, MGSL_PARAMS __user *params);
  466. static int set_params(SLMP_INFO *info, MGSL_PARAMS __user *params);
  467. static int get_txidle(SLMP_INFO *info, int __user *idle_mode);
  468. static int set_txidle(SLMP_INFO *info, int idle_mode);
  469. static int tx_enable(SLMP_INFO *info, int enable);
  470. static int tx_abort(SLMP_INFO *info);
  471. static int rx_enable(SLMP_INFO *info, int enable);
  472. static int modem_input_wait(SLMP_INFO *info,int arg);
  473. static int wait_mgsl_event(SLMP_INFO *info, int __user *mask_ptr);
  474. static int tiocmget(struct tty_struct *tty, struct file *file);
  475. static int tiocmset(struct tty_struct *tty, struct file *file,
  476. unsigned int set, unsigned int clear);
  477. static void set_break(struct tty_struct *tty, int break_state);
  478. static void add_device(SLMP_INFO *info);
  479. static void device_init(int adapter_num, struct pci_dev *pdev);
  480. static int claim_resources(SLMP_INFO *info);
  481. static void release_resources(SLMP_INFO *info);
  482. static int startup(SLMP_INFO *info);
  483. static int block_til_ready(struct tty_struct *tty, struct file * filp,SLMP_INFO *info);
  484. static void shutdown(SLMP_INFO *info);
  485. static void program_hw(SLMP_INFO *info);
  486. static void change_params(SLMP_INFO *info);
  487. static int init_adapter(SLMP_INFO *info);
  488. static int register_test(SLMP_INFO *info);
  489. static int irq_test(SLMP_INFO *info);
  490. static int loopback_test(SLMP_INFO *info);
  491. static int adapter_test(SLMP_INFO *info);
  492. static int memory_test(SLMP_INFO *info);
  493. static void reset_adapter(SLMP_INFO *info);
  494. static void reset_port(SLMP_INFO *info);
  495. static void async_mode(SLMP_INFO *info);
  496. static void hdlc_mode(SLMP_INFO *info);
  497. static void rx_stop(SLMP_INFO *info);
  498. static void rx_start(SLMP_INFO *info);
  499. static void rx_reset_buffers(SLMP_INFO *info);
  500. static void rx_free_frame_buffers(SLMP_INFO *info, unsigned int first, unsigned int last);
  501. static int rx_get_frame(SLMP_INFO *info);
  502. static void tx_start(SLMP_INFO *info);
  503. static void tx_stop(SLMP_INFO *info);
  504. static void tx_load_fifo(SLMP_INFO *info);
  505. static void tx_set_idle(SLMP_INFO *info);
  506. static void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count);
  507. static void get_signals(SLMP_INFO *info);
  508. static void set_signals(SLMP_INFO *info);
  509. static void enable_loopback(SLMP_INFO *info, int enable);
  510. static void set_rate(SLMP_INFO *info, u32 data_rate);
  511. static int bh_action(SLMP_INFO *info);
  512. static void bh_handler(void* Context);
  513. static void bh_receive(SLMP_INFO *info);
  514. static void bh_transmit(SLMP_INFO *info);
  515. static void bh_status(SLMP_INFO *info);
  516. static void isr_timer(SLMP_INFO *info);
  517. static void isr_rxint(SLMP_INFO *info);
  518. static void isr_rxrdy(SLMP_INFO *info);
  519. static void isr_txint(SLMP_INFO *info);
  520. static void isr_txrdy(SLMP_INFO *info);
  521. static void isr_rxdmaok(SLMP_INFO *info);
  522. static void isr_rxdmaerror(SLMP_INFO *info);
  523. static void isr_txdmaok(SLMP_INFO *info);
  524. static void isr_txdmaerror(SLMP_INFO *info);
  525. static void isr_io_pin(SLMP_INFO *info, u16 status);
  526. static int alloc_dma_bufs(SLMP_INFO *info);
  527. static void free_dma_bufs(SLMP_INFO *info);
  528. static int alloc_buf_list(SLMP_INFO *info);
  529. static int alloc_frame_bufs(SLMP_INFO *info, SCADESC *list, SCADESC_EX *list_ex,int count);
  530. static int alloc_tmp_rx_buf(SLMP_INFO *info);
  531. static void free_tmp_rx_buf(SLMP_INFO *info);
  532. static void load_pci_memory(SLMP_INFO *info, char* dest, const char* src, unsigned short count);
  533. static void trace_block(SLMP_INFO *info, const char* data, int count, int xmit);
  534. static void tx_timeout(unsigned long context);
  535. static void status_timeout(unsigned long context);
  536. static unsigned char read_reg(SLMP_INFO *info, unsigned char addr);
  537. static void write_reg(SLMP_INFO *info, unsigned char addr, unsigned char val);
  538. static u16 read_reg16(SLMP_INFO *info, unsigned char addr);
  539. static void write_reg16(SLMP_INFO *info, unsigned char addr, u16 val);
  540. static unsigned char read_status_reg(SLMP_INFO * info);
  541. static void write_control_reg(SLMP_INFO * info);
  542. static unsigned char rx_active_fifo_level = 16; // rx request FIFO activation level in bytes
  543. static unsigned char tx_active_fifo_level = 16; // tx request FIFO activation level in bytes
  544. static unsigned char tx_negate_fifo_level = 32; // tx request FIFO negation level in bytes
  545. static u32 misc_ctrl_value = 0x007e4040;
  546. static u32 lcr1_brdr_value = 0x00800028;
  547. static u32 read_ahead_count = 8;
  548. /* DPCR, DMA Priority Control
  549. *
  550. * 07..05 Not used, must be 0
  551. * 04 BRC, bus release condition: 0=all transfers complete
  552. * 1=release after 1 xfer on all channels
  553. * 03 CCC, channel change condition: 0=every cycle
  554. * 1=after each channel completes all xfers
  555. * 02..00 PR<2..0>, priority 100=round robin
  556. *
  557. * 00000100 = 0x00
  558. */
  559. static unsigned char dma_priority = 0x04;
  560. // Number of bytes that can be written to shared RAM
  561. // in a single write operation
  562. static u32 sca_pci_load_interval = 64;
  563. /*
  564. * 1st function defined in .text section. Calling this function in
  565. * init_module() followed by a breakpoint allows a remote debugger
  566. * (gdb) to get the .text address for the add-symbol-file command.
  567. * This allows remote debugging of dynamically loadable modules.
  568. */
  569. static void* synclinkmp_get_text_ptr(void);
  570. static void* synclinkmp_get_text_ptr(void) {return synclinkmp_get_text_ptr;}
  571. static inline int sanity_check(SLMP_INFO *info,
  572. char *name, const char *routine)
  573. {
  574. #ifdef SANITY_CHECK
  575. static const char *badmagic =
  576. "Warning: bad magic number for synclinkmp_struct (%s) in %s\n";
  577. static const char *badinfo =
  578. "Warning: null synclinkmp_struct for (%s) in %s\n";
  579. if (!info) {
  580. printk(badinfo, name, routine);
  581. return 1;
  582. }
  583. if (info->magic != MGSL_MAGIC) {
  584. printk(badmagic, name, routine);
  585. return 1;
  586. }
  587. #else
  588. if (!info)
  589. return 1;
  590. #endif
  591. return 0;
  592. }
  593. /**
  594. * line discipline callback wrappers
  595. *
  596. * The wrappers maintain line discipline references
  597. * while calling into the line discipline.
  598. *
  599. * ldisc_receive_buf - pass receive data to line discipline
  600. */
  601. static void ldisc_receive_buf(struct tty_struct *tty,
  602. const __u8 *data, char *flags, int count)
  603. {
  604. struct tty_ldisc *ld;
  605. if (!tty)
  606. return;
  607. ld = tty_ldisc_ref(tty);
  608. if (ld) {
  609. if (ld->receive_buf)
  610. ld->receive_buf(tty, data, flags, count);
  611. tty_ldisc_deref(ld);
  612. }
  613. }
  614. /* tty callbacks */
  615. /* Called when a port is opened. Init and enable port.
  616. */
  617. static int open(struct tty_struct *tty, struct file *filp)
  618. {
  619. SLMP_INFO *info;
  620. int retval, line;
  621. unsigned long flags;
  622. line = tty->index;
  623. if ((line < 0) || (line >= synclinkmp_device_count)) {
  624. printk("%s(%d): open with invalid line #%d.\n",
  625. __FILE__,__LINE__,line);
  626. return -ENODEV;
  627. }
  628. info = synclinkmp_device_list;
  629. while(info && info->line != line)
  630. info = info->next_device;
  631. if (sanity_check(info, tty->name, "open"))
  632. return -ENODEV;
  633. if ( info->init_error ) {
  634. printk("%s(%d):%s device is not allocated, init error=%d\n",
  635. __FILE__,__LINE__,info->device_name,info->init_error);
  636. return -ENODEV;
  637. }
  638. tty->driver_data = info;
  639. info->tty = tty;
  640. if (debug_level >= DEBUG_LEVEL_INFO)
  641. printk("%s(%d):%s open(), old ref count = %d\n",
  642. __FILE__,__LINE__,tty->driver->name, info->count);
  643. /* If port is closing, signal caller to try again */
  644. if (tty_hung_up_p(filp) || info->flags & ASYNC_CLOSING){
  645. if (info->flags & ASYNC_CLOSING)
  646. interruptible_sleep_on(&info->close_wait);
  647. retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
  648. -EAGAIN : -ERESTARTSYS);
  649. goto cleanup;
  650. }
  651. info->tty->low_latency = (info->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
  652. spin_lock_irqsave(&info->netlock, flags);
  653. if (info->netcount) {
  654. retval = -EBUSY;
  655. spin_unlock_irqrestore(&info->netlock, flags);
  656. goto cleanup;
  657. }
  658. info->count++;
  659. spin_unlock_irqrestore(&info->netlock, flags);
  660. if (info->count == 1) {
  661. /* 1st open on this device, init hardware */
  662. retval = startup(info);
  663. if (retval < 0)
  664. goto cleanup;
  665. }
  666. retval = block_til_ready(tty, filp, info);
  667. if (retval) {
  668. if (debug_level >= DEBUG_LEVEL_INFO)
  669. printk("%s(%d):%s block_til_ready() returned %d\n",
  670. __FILE__,__LINE__, info->device_name, retval);
  671. goto cleanup;
  672. }
  673. if (debug_level >= DEBUG_LEVEL_INFO)
  674. printk("%s(%d):%s open() success\n",
  675. __FILE__,__LINE__, info->device_name);
  676. retval = 0;
  677. cleanup:
  678. if (retval) {
  679. if (tty->count == 1)
  680. info->tty = NULL; /* tty layer will release tty struct */
  681. if(info->count)
  682. info->count--;
  683. }
  684. return retval;
  685. }
  686. /* Called when port is closed. Wait for remaining data to be
  687. * sent. Disable port and free resources.
  688. */
  689. static void close(struct tty_struct *tty, struct file *filp)
  690. {
  691. SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
  692. if (sanity_check(info, tty->name, "close"))
  693. return;
  694. if (debug_level >= DEBUG_LEVEL_INFO)
  695. printk("%s(%d):%s close() entry, count=%d\n",
  696. __FILE__,__LINE__, info->device_name, info->count);
  697. if (!info->count)
  698. return;
  699. if (tty_hung_up_p(filp))
  700. goto cleanup;
  701. if ((tty->count == 1) && (info->count != 1)) {
  702. /*
  703. * tty->count is 1 and the tty structure will be freed.
  704. * info->count should be one in this case.
  705. * if it's not, correct it so that the port is shutdown.
  706. */
  707. printk("%s(%d):%s close: bad refcount; tty->count is 1, "
  708. "info->count is %d\n",
  709. __FILE__,__LINE__, info->device_name, info->count);
  710. info->count = 1;
  711. }
  712. info->count--;
  713. /* if at least one open remaining, leave hardware active */
  714. if (info->count)
  715. goto cleanup;
  716. info->flags |= ASYNC_CLOSING;
  717. /* set tty->closing to notify line discipline to
  718. * only process XON/XOFF characters. Only the N_TTY
  719. * discipline appears to use this (ppp does not).
  720. */
  721. tty->closing = 1;
  722. /* wait for transmit data to clear all layers */
  723. if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE) {
  724. if (debug_level >= DEBUG_LEVEL_INFO)
  725. printk("%s(%d):%s close() calling tty_wait_until_sent\n",
  726. __FILE__,__LINE__, info->device_name );
  727. tty_wait_until_sent(tty, info->closing_wait);
  728. }
  729. if (info->flags & ASYNC_INITIALIZED)
  730. wait_until_sent(tty, info->timeout);
  731. if (tty->driver->flush_buffer)
  732. tty->driver->flush_buffer(tty);
  733. tty_ldisc_flush(tty);
  734. shutdown(info);
  735. tty->closing = 0;
  736. info->tty = NULL;
  737. if (info->blocked_open) {
  738. if (info->close_delay) {
  739. msleep_interruptible(jiffies_to_msecs(info->close_delay));
  740. }
  741. wake_up_interruptible(&info->open_wait);
  742. }
  743. info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  744. wake_up_interruptible(&info->close_wait);
  745. cleanup:
  746. if (debug_level >= DEBUG_LEVEL_INFO)
  747. printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
  748. tty->driver->name, info->count);
  749. }
  750. /* Called by tty_hangup() when a hangup is signaled.
  751. * This is the same as closing all open descriptors for the port.
  752. */
  753. static void hangup(struct tty_struct *tty)
  754. {
  755. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  756. if (debug_level >= DEBUG_LEVEL_INFO)
  757. printk("%s(%d):%s hangup()\n",
  758. __FILE__,__LINE__, info->device_name );
  759. if (sanity_check(info, tty->name, "hangup"))
  760. return;
  761. flush_buffer(tty);
  762. shutdown(info);
  763. info->count = 0;
  764. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  765. info->tty = NULL;
  766. wake_up_interruptible(&info->open_wait);
  767. }
  768. /* Set new termios settings
  769. */
  770. static void set_termios(struct tty_struct *tty, struct termios *old_termios)
  771. {
  772. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  773. unsigned long flags;
  774. if (debug_level >= DEBUG_LEVEL_INFO)
  775. printk("%s(%d):%s set_termios()\n", __FILE__,__LINE__,
  776. tty->driver->name );
  777. /* just return if nothing has changed */
  778. if ((tty->termios->c_cflag == old_termios->c_cflag)
  779. && (RELEVANT_IFLAG(tty->termios->c_iflag)
  780. == RELEVANT_IFLAG(old_termios->c_iflag)))
  781. return;
  782. change_params(info);
  783. /* Handle transition to B0 status */
  784. if (old_termios->c_cflag & CBAUD &&
  785. !(tty->termios->c_cflag & CBAUD)) {
  786. info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
  787. spin_lock_irqsave(&info->lock,flags);
  788. set_signals(info);
  789. spin_unlock_irqrestore(&info->lock,flags);
  790. }
  791. /* Handle transition away from B0 status */
  792. if (!(old_termios->c_cflag & CBAUD) &&
  793. tty->termios->c_cflag & CBAUD) {
  794. info->serial_signals |= SerialSignal_DTR;
  795. if (!(tty->termios->c_cflag & CRTSCTS) ||
  796. !test_bit(TTY_THROTTLED, &tty->flags)) {
  797. info->serial_signals |= SerialSignal_RTS;
  798. }
  799. spin_lock_irqsave(&info->lock,flags);
  800. set_signals(info);
  801. spin_unlock_irqrestore(&info->lock,flags);
  802. }
  803. /* Handle turning off CRTSCTS */
  804. if (old_termios->c_cflag & CRTSCTS &&
  805. !(tty->termios->c_cflag & CRTSCTS)) {
  806. tty->hw_stopped = 0;
  807. tx_release(tty);
  808. }
  809. }
  810. /* Send a block of data
  811. *
  812. * Arguments:
  813. *
  814. * tty pointer to tty information structure
  815. * buf pointer to buffer containing send data
  816. * count size of send data in bytes
  817. *
  818. * Return Value: number of characters written
  819. */
  820. static int write(struct tty_struct *tty,
  821. const unsigned char *buf, int count)
  822. {
  823. int c, ret = 0;
  824. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  825. unsigned long flags;
  826. if (debug_level >= DEBUG_LEVEL_INFO)
  827. printk("%s(%d):%s write() count=%d\n",
  828. __FILE__,__LINE__,info->device_name,count);
  829. if (sanity_check(info, tty->name, "write"))
  830. goto cleanup;
  831. if (!tty || !info->tx_buf)
  832. goto cleanup;
  833. if (info->params.mode == MGSL_MODE_HDLC) {
  834. if (count > info->max_frame_size) {
  835. ret = -EIO;
  836. goto cleanup;
  837. }
  838. if (info->tx_active)
  839. goto cleanup;
  840. if (info->tx_count) {
  841. /* send accumulated data from send_char() calls */
  842. /* as frame and wait before accepting more data. */
  843. tx_load_dma_buffer(info, info->tx_buf, info->tx_count);
  844. goto start;
  845. }
  846. ret = info->tx_count = count;
  847. tx_load_dma_buffer(info, buf, count);
  848. goto start;
  849. }
  850. for (;;) {
  851. c = min_t(int, count,
  852. min(info->max_frame_size - info->tx_count - 1,
  853. info->max_frame_size - info->tx_put));
  854. if (c <= 0)
  855. break;
  856. memcpy(info->tx_buf + info->tx_put, buf, c);
  857. spin_lock_irqsave(&info->lock,flags);
  858. info->tx_put += c;
  859. if (info->tx_put >= info->max_frame_size)
  860. info->tx_put -= info->max_frame_size;
  861. info->tx_count += c;
  862. spin_unlock_irqrestore(&info->lock,flags);
  863. buf += c;
  864. count -= c;
  865. ret += c;
  866. }
  867. if (info->params.mode == MGSL_MODE_HDLC) {
  868. if (count) {
  869. ret = info->tx_count = 0;
  870. goto cleanup;
  871. }
  872. tx_load_dma_buffer(info, info->tx_buf, info->tx_count);
  873. }
  874. start:
  875. if (info->tx_count && !tty->stopped && !tty->hw_stopped) {
  876. spin_lock_irqsave(&info->lock,flags);
  877. if (!info->tx_active)
  878. tx_start(info);
  879. spin_unlock_irqrestore(&info->lock,flags);
  880. }
  881. cleanup:
  882. if (debug_level >= DEBUG_LEVEL_INFO)
  883. printk( "%s(%d):%s write() returning=%d\n",
  884. __FILE__,__LINE__,info->device_name,ret);
  885. return ret;
  886. }
  887. /* Add a character to the transmit buffer.
  888. */
  889. static void put_char(struct tty_struct *tty, unsigned char ch)
  890. {
  891. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  892. unsigned long flags;
  893. if ( debug_level >= DEBUG_LEVEL_INFO ) {
  894. printk( "%s(%d):%s put_char(%d)\n",
  895. __FILE__,__LINE__,info->device_name,ch);
  896. }
  897. if (sanity_check(info, tty->name, "put_char"))
  898. return;
  899. if (!tty || !info->tx_buf)
  900. return;
  901. spin_lock_irqsave(&info->lock,flags);
  902. if ( (info->params.mode != MGSL_MODE_HDLC) ||
  903. !info->tx_active ) {
  904. if (info->tx_count < info->max_frame_size - 1) {
  905. info->tx_buf[info->tx_put++] = ch;
  906. if (info->tx_put >= info->max_frame_size)
  907. info->tx_put -= info->max_frame_size;
  908. info->tx_count++;
  909. }
  910. }
  911. spin_unlock_irqrestore(&info->lock,flags);
  912. }
  913. /* Send a high-priority XON/XOFF character
  914. */
  915. static void send_xchar(struct tty_struct *tty, char ch)
  916. {
  917. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  918. unsigned long flags;
  919. if (debug_level >= DEBUG_LEVEL_INFO)
  920. printk("%s(%d):%s send_xchar(%d)\n",
  921. __FILE__,__LINE__, info->device_name, ch );
  922. if (sanity_check(info, tty->name, "send_xchar"))
  923. return;
  924. info->x_char = ch;
  925. if (ch) {
  926. /* Make sure transmit interrupts are on */
  927. spin_lock_irqsave(&info->lock,flags);
  928. if (!info->tx_enabled)
  929. tx_start(info);
  930. spin_unlock_irqrestore(&info->lock,flags);
  931. }
  932. }
  933. /* Wait until the transmitter is empty.
  934. */
  935. static void wait_until_sent(struct tty_struct *tty, int timeout)
  936. {
  937. SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
  938. unsigned long orig_jiffies, char_time;
  939. if (!info )
  940. return;
  941. if (debug_level >= DEBUG_LEVEL_INFO)
  942. printk("%s(%d):%s wait_until_sent() entry\n",
  943. __FILE__,__LINE__, info->device_name );
  944. if (sanity_check(info, tty->name, "wait_until_sent"))
  945. return;
  946. if (!(info->flags & ASYNC_INITIALIZED))
  947. goto exit;
  948. orig_jiffies = jiffies;
  949. /* Set check interval to 1/5 of estimated time to
  950. * send a character, and make it at least 1. The check
  951. * interval should also be less than the timeout.
  952. * Note: use tight timings here to satisfy the NIST-PCTS.
  953. */
  954. if ( info->params.data_rate ) {
  955. char_time = info->timeout/(32 * 5);
  956. if (!char_time)
  957. char_time++;
  958. } else
  959. char_time = 1;
  960. if (timeout)
  961. char_time = min_t(unsigned long, char_time, timeout);
  962. if ( info->params.mode == MGSL_MODE_HDLC ) {
  963. while (info->tx_active) {
  964. msleep_interruptible(jiffies_to_msecs(char_time));
  965. if (signal_pending(current))
  966. break;
  967. if (timeout && time_after(jiffies, orig_jiffies + timeout))
  968. break;
  969. }
  970. } else {
  971. //TODO: determine if there is something similar to USC16C32
  972. // TXSTATUS_ALL_SENT status
  973. while ( info->tx_active && info->tx_enabled) {
  974. msleep_interruptible(jiffies_to_msecs(char_time));
  975. if (signal_pending(current))
  976. break;
  977. if (timeout && time_after(jiffies, orig_jiffies + timeout))
  978. break;
  979. }
  980. }
  981. exit:
  982. if (debug_level >= DEBUG_LEVEL_INFO)
  983. printk("%s(%d):%s wait_until_sent() exit\n",
  984. __FILE__,__LINE__, info->device_name );
  985. }
  986. /* Return the count of free bytes in transmit buffer
  987. */
  988. static int write_room(struct tty_struct *tty)
  989. {
  990. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  991. int ret;
  992. if (sanity_check(info, tty->name, "write_room"))
  993. return 0;
  994. if (info->params.mode == MGSL_MODE_HDLC) {
  995. ret = (info->tx_active) ? 0 : HDLC_MAX_FRAME_SIZE;
  996. } else {
  997. ret = info->max_frame_size - info->tx_count - 1;
  998. if (ret < 0)
  999. ret = 0;
  1000. }
  1001. if (debug_level >= DEBUG_LEVEL_INFO)
  1002. printk("%s(%d):%s write_room()=%d\n",
  1003. __FILE__, __LINE__, info->device_name, ret);
  1004. return ret;
  1005. }
  1006. /* enable transmitter and send remaining buffered characters
  1007. */
  1008. static void flush_chars(struct tty_struct *tty)
  1009. {
  1010. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1011. unsigned long flags;
  1012. if ( debug_level >= DEBUG_LEVEL_INFO )
  1013. printk( "%s(%d):%s flush_chars() entry tx_count=%d\n",
  1014. __FILE__,__LINE__,info->device_name,info->tx_count);
  1015. if (sanity_check(info, tty->name, "flush_chars"))
  1016. return;
  1017. if (info->tx_count <= 0 || tty->stopped || tty->hw_stopped ||
  1018. !info->tx_buf)
  1019. return;
  1020. if ( debug_level >= DEBUG_LEVEL_INFO )
  1021. printk( "%s(%d):%s flush_chars() entry, starting transmitter\n",
  1022. __FILE__,__LINE__,info->device_name );
  1023. spin_lock_irqsave(&info->lock,flags);
  1024. if (!info->tx_active) {
  1025. if ( (info->params.mode == MGSL_MODE_HDLC) &&
  1026. info->tx_count ) {
  1027. /* operating in synchronous (frame oriented) mode */
  1028. /* copy data from circular tx_buf to */
  1029. /* transmit DMA buffer. */
  1030. tx_load_dma_buffer(info,
  1031. info->tx_buf,info->tx_count);
  1032. }
  1033. tx_start(info);
  1034. }
  1035. spin_unlock_irqrestore(&info->lock,flags);
  1036. }
  1037. /* Discard all data in the send buffer
  1038. */
  1039. static void flush_buffer(struct tty_struct *tty)
  1040. {
  1041. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1042. unsigned long flags;
  1043. if (debug_level >= DEBUG_LEVEL_INFO)
  1044. printk("%s(%d):%s flush_buffer() entry\n",
  1045. __FILE__,__LINE__, info->device_name );
  1046. if (sanity_check(info, tty->name, "flush_buffer"))
  1047. return;
  1048. spin_lock_irqsave(&info->lock,flags);
  1049. info->tx_count = info->tx_put = info->tx_get = 0;
  1050. del_timer(&info->tx_timer);
  1051. spin_unlock_irqrestore(&info->lock,flags);
  1052. wake_up_interruptible(&tty->write_wait);
  1053. tty_wakeup(tty);
  1054. }
  1055. /* throttle (stop) transmitter
  1056. */
  1057. static void tx_hold(struct tty_struct *tty)
  1058. {
  1059. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1060. unsigned long flags;
  1061. if (sanity_check(info, tty->name, "tx_hold"))
  1062. return;
  1063. if ( debug_level >= DEBUG_LEVEL_INFO )
  1064. printk("%s(%d):%s tx_hold()\n",
  1065. __FILE__,__LINE__,info->device_name);
  1066. spin_lock_irqsave(&info->lock,flags);
  1067. if (info->tx_enabled)
  1068. tx_stop(info);
  1069. spin_unlock_irqrestore(&info->lock,flags);
  1070. }
  1071. /* release (start) transmitter
  1072. */
  1073. static void tx_release(struct tty_struct *tty)
  1074. {
  1075. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1076. unsigned long flags;
  1077. if (sanity_check(info, tty->name, "tx_release"))
  1078. return;
  1079. if ( debug_level >= DEBUG_LEVEL_INFO )
  1080. printk("%s(%d):%s tx_release()\n",
  1081. __FILE__,__LINE__,info->device_name);
  1082. spin_lock_irqsave(&info->lock,flags);
  1083. if (!info->tx_enabled)
  1084. tx_start(info);
  1085. spin_unlock_irqrestore(&info->lock,flags);
  1086. }
  1087. /* Service an IOCTL request
  1088. *
  1089. * Arguments:
  1090. *
  1091. * tty pointer to tty instance data
  1092. * file pointer to associated file object for device
  1093. * cmd IOCTL command code
  1094. * arg command argument/context
  1095. *
  1096. * Return Value: 0 if success, otherwise error code
  1097. */
  1098. static int ioctl(struct tty_struct *tty, struct file *file,
  1099. unsigned int cmd, unsigned long arg)
  1100. {
  1101. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1102. int error;
  1103. struct mgsl_icount cnow; /* kernel counter temps */
  1104. struct serial_icounter_struct __user *p_cuser; /* user space */
  1105. unsigned long flags;
  1106. void __user *argp = (void __user *)arg;
  1107. if (debug_level >= DEBUG_LEVEL_INFO)
  1108. printk("%s(%d):%s ioctl() cmd=%08X\n", __FILE__,__LINE__,
  1109. info->device_name, cmd );
  1110. if (sanity_check(info, tty->name, "ioctl"))
  1111. return -ENODEV;
  1112. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1113. (cmd != TIOCMIWAIT) && (cmd != TIOCGICOUNT)) {
  1114. if (tty->flags & (1 << TTY_IO_ERROR))
  1115. return -EIO;
  1116. }
  1117. switch (cmd) {
  1118. case MGSL_IOCGPARAMS:
  1119. return get_params(info, argp);
  1120. case MGSL_IOCSPARAMS:
  1121. return set_params(info, argp);
  1122. case MGSL_IOCGTXIDLE:
  1123. return get_txidle(info, argp);
  1124. case MGSL_IOCSTXIDLE:
  1125. return set_txidle(info, (int)arg);
  1126. case MGSL_IOCTXENABLE:
  1127. return tx_enable(info, (int)arg);
  1128. case MGSL_IOCRXENABLE:
  1129. return rx_enable(info, (int)arg);
  1130. case MGSL_IOCTXABORT:
  1131. return tx_abort(info);
  1132. case MGSL_IOCGSTATS:
  1133. return get_stats(info, argp);
  1134. case MGSL_IOCWAITEVENT:
  1135. return wait_mgsl_event(info, argp);
  1136. case MGSL_IOCLOOPTXDONE:
  1137. return 0; // TODO: Not supported, need to document
  1138. /* Wait for modem input (DCD,RI,DSR,CTS) change
  1139. * as specified by mask in arg (TIOCM_RNG/DSR/CD/CTS)
  1140. */
  1141. case TIOCMIWAIT:
  1142. return modem_input_wait(info,(int)arg);
  1143. /*
  1144. * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  1145. * Return: write counters to the user passed counter struct
  1146. * NB: both 1->0 and 0->1 transitions are counted except for
  1147. * RI where only 0->1 is counted.
  1148. */
  1149. case TIOCGICOUNT:
  1150. spin_lock_irqsave(&info->lock,flags);
  1151. cnow = info->icount;
  1152. spin_unlock_irqrestore(&info->lock,flags);
  1153. p_cuser = argp;
  1154. PUT_USER(error,cnow.cts, &p_cuser->cts);
  1155. if (error) return error;
  1156. PUT_USER(error,cnow.dsr, &p_cuser->dsr);
  1157. if (error) return error;
  1158. PUT_USER(error,cnow.rng, &p_cuser->rng);
  1159. if (error) return error;
  1160. PUT_USER(error,cnow.dcd, &p_cuser->dcd);
  1161. if (error) return error;
  1162. PUT_USER(error,cnow.rx, &p_cuser->rx);
  1163. if (error) return error;
  1164. PUT_USER(error,cnow.tx, &p_cuser->tx);
  1165. if (error) return error;
  1166. PUT_USER(error,cnow.frame, &p_cuser->frame);
  1167. if (error) return error;
  1168. PUT_USER(error,cnow.overrun, &p_cuser->overrun);
  1169. if (error) return error;
  1170. PUT_USER(error,cnow.parity, &p_cuser->parity);
  1171. if (error) return error;
  1172. PUT_USER(error,cnow.brk, &p_cuser->brk);
  1173. if (error) return error;
  1174. PUT_USER(error,cnow.buf_overrun, &p_cuser->buf_overrun);
  1175. if (error) return error;
  1176. return 0;
  1177. default:
  1178. return -ENOIOCTLCMD;
  1179. }
  1180. return 0;
  1181. }
  1182. /*
  1183. * /proc fs routines....
  1184. */
  1185. static inline int line_info(char *buf, SLMP_INFO *info)
  1186. {
  1187. char stat_buf[30];
  1188. int ret;
  1189. unsigned long flags;
  1190. ret = sprintf(buf, "%s: SCABase=%08x Mem=%08X StatusControl=%08x LCR=%08X\n"
  1191. "\tIRQ=%d MaxFrameSize=%u\n",
  1192. info->device_name,
  1193. info->phys_sca_base,
  1194. info->phys_memory_base,
  1195. info->phys_statctrl_base,
  1196. info->phys_lcr_base,
  1197. info->irq_level,
  1198. info->max_frame_size );
  1199. /* output current serial signal states */
  1200. spin_lock_irqsave(&info->lock,flags);
  1201. get_signals(info);
  1202. spin_unlock_irqrestore(&info->lock,flags);
  1203. stat_buf[0] = 0;
  1204. stat_buf[1] = 0;
  1205. if (info->serial_signals & SerialSignal_RTS)
  1206. strcat(stat_buf, "|RTS");
  1207. if (info->serial_signals & SerialSignal_CTS)
  1208. strcat(stat_buf, "|CTS");
  1209. if (info->serial_signals & SerialSignal_DTR)
  1210. strcat(stat_buf, "|DTR");
  1211. if (info->serial_signals & SerialSignal_DSR)
  1212. strcat(stat_buf, "|DSR");
  1213. if (info->serial_signals & SerialSignal_DCD)
  1214. strcat(stat_buf, "|CD");
  1215. if (info->serial_signals & SerialSignal_RI)
  1216. strcat(stat_buf, "|RI");
  1217. if (info->params.mode == MGSL_MODE_HDLC) {
  1218. ret += sprintf(buf+ret, "\tHDLC txok:%d rxok:%d",
  1219. info->icount.txok, info->icount.rxok);
  1220. if (info->icount.txunder)
  1221. ret += sprintf(buf+ret, " txunder:%d", info->icount.txunder);
  1222. if (info->icount.txabort)
  1223. ret += sprintf(buf+ret, " txabort:%d", info->icount.txabort);
  1224. if (info->icount.rxshort)
  1225. ret += sprintf(buf+ret, " rxshort:%d", info->icount.rxshort);
  1226. if (info->icount.rxlong)
  1227. ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxlong);
  1228. if (info->icount.rxover)
  1229. ret += sprintf(buf+ret, " rxover:%d", info->icount.rxover);
  1230. if (info->icount.rxcrc)
  1231. ret += sprintf(buf+ret, " rxlong:%d", info->icount.rxcrc);
  1232. } else {
  1233. ret += sprintf(buf+ret, "\tASYNC tx:%d rx:%d",
  1234. info->icount.tx, info->icount.rx);
  1235. if (info->icount.frame)
  1236. ret += sprintf(buf+ret, " fe:%d", info->icount.frame);
  1237. if (info->icount.parity)
  1238. ret += sprintf(buf+ret, " pe:%d", info->icount.parity);
  1239. if (info->icount.brk)
  1240. ret += sprintf(buf+ret, " brk:%d", info->icount.brk);
  1241. if (info->icount.overrun)
  1242. ret += sprintf(buf+ret, " oe:%d", info->icount.overrun);
  1243. }
  1244. /* Append serial signal status to end */
  1245. ret += sprintf(buf+ret, " %s\n", stat_buf+1);
  1246. ret += sprintf(buf+ret, "\ttxactive=%d bh_req=%d bh_run=%d pending_bh=%x\n",
  1247. info->tx_active,info->bh_requested,info->bh_running,
  1248. info->pending_bh);
  1249. return ret;
  1250. }
  1251. /* Called to print information about devices
  1252. */
  1253. int read_proc(char *page, char **start, off_t off, int count,
  1254. int *eof, void *data)
  1255. {
  1256. int len = 0, l;
  1257. off_t begin = 0;
  1258. SLMP_INFO *info;
  1259. len += sprintf(page, "synclinkmp driver:%s\n", driver_version);
  1260. info = synclinkmp_device_list;
  1261. while( info ) {
  1262. l = line_info(page + len, info);
  1263. len += l;
  1264. if (len+begin > off+count)
  1265. goto done;
  1266. if (len+begin < off) {
  1267. begin += len;
  1268. len = 0;
  1269. }
  1270. info = info->next_device;
  1271. }
  1272. *eof = 1;
  1273. done:
  1274. if (off >= len+begin)
  1275. return 0;
  1276. *start = page + (off-begin);
  1277. return ((count < begin+len-off) ? count : begin+len-off);
  1278. }
  1279. /* Return the count of bytes in transmit buffer
  1280. */
  1281. static int chars_in_buffer(struct tty_struct *tty)
  1282. {
  1283. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1284. if (sanity_check(info, tty->name, "chars_in_buffer"))
  1285. return 0;
  1286. if (debug_level >= DEBUG_LEVEL_INFO)
  1287. printk("%s(%d):%s chars_in_buffer()=%d\n",
  1288. __FILE__, __LINE__, info->device_name, info->tx_count);
  1289. return info->tx_count;
  1290. }
  1291. /* Signal remote device to throttle send data (our receive data)
  1292. */
  1293. static void throttle(struct tty_struct * tty)
  1294. {
  1295. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1296. unsigned long flags;
  1297. if (debug_level >= DEBUG_LEVEL_INFO)
  1298. printk("%s(%d):%s throttle() entry\n",
  1299. __FILE__,__LINE__, info->device_name );
  1300. if (sanity_check(info, tty->name, "throttle"))
  1301. return;
  1302. if (I_IXOFF(tty))
  1303. send_xchar(tty, STOP_CHAR(tty));
  1304. if (tty->termios->c_cflag & CRTSCTS) {
  1305. spin_lock_irqsave(&info->lock,flags);
  1306. info->serial_signals &= ~SerialSignal_RTS;
  1307. set_signals(info);
  1308. spin_unlock_irqrestore(&info->lock,flags);
  1309. }
  1310. }
  1311. /* Signal remote device to stop throttling send data (our receive data)
  1312. */
  1313. static void unthrottle(struct tty_struct * tty)
  1314. {
  1315. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  1316. unsigned long flags;
  1317. if (debug_level >= DEBUG_LEVEL_INFO)
  1318. printk("%s(%d):%s unthrottle() entry\n",
  1319. __FILE__,__LINE__, info->device_name );
  1320. if (sanity_check(info, tty->name, "unthrottle"))
  1321. return;
  1322. if (I_IXOFF(tty)) {
  1323. if (info->x_char)
  1324. info->x_char = 0;
  1325. else
  1326. send_xchar(tty, START_CHAR(tty));
  1327. }
  1328. if (tty->termios->c_cflag & CRTSCTS) {
  1329. spin_lock_irqsave(&info->lock,flags);
  1330. info->serial_signals |= SerialSignal_RTS;
  1331. set_signals(info);
  1332. spin_unlock_irqrestore(&info->lock,flags);
  1333. }
  1334. }
  1335. /* set or clear transmit break condition
  1336. * break_state -1=set break condition, 0=clear
  1337. */
  1338. static void set_break(struct tty_struct *tty, int break_state)
  1339. {
  1340. unsigned char RegValue;
  1341. SLMP_INFO * info = (SLMP_INFO *)tty->driver_data;
  1342. unsigned long flags;
  1343. if (debug_level >= DEBUG_LEVEL_INFO)
  1344. printk("%s(%d):%s set_break(%d)\n",
  1345. __FILE__,__LINE__, info->device_name, break_state);
  1346. if (sanity_check(info, tty->name, "set_break"))
  1347. return;
  1348. spin_lock_irqsave(&info->lock,flags);
  1349. RegValue = read_reg(info, CTL);
  1350. if (break_state == -1)
  1351. RegValue |= BIT3;
  1352. else
  1353. RegValue &= ~BIT3;
  1354. write_reg(info, CTL, RegValue);
  1355. spin_unlock_irqrestore(&info->lock,flags);
  1356. }
  1357. #ifdef CONFIG_HDLC
  1358. /**
  1359. * called by generic HDLC layer when protocol selected (PPP, frame relay, etc.)
  1360. * set encoding and frame check sequence (FCS) options
  1361. *
  1362. * dev pointer to network device structure
  1363. * encoding serial encoding setting
  1364. * parity FCS setting
  1365. *
  1366. * returns 0 if success, otherwise error code
  1367. */
  1368. static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
  1369. unsigned short parity)
  1370. {
  1371. SLMP_INFO *info = dev_to_port(dev);
  1372. unsigned char new_encoding;
  1373. unsigned short new_crctype;
  1374. /* return error if TTY interface open */
  1375. if (info->count)
  1376. return -EBUSY;
  1377. switch (encoding)
  1378. {
  1379. case ENCODING_NRZ: new_encoding = HDLC_ENCODING_NRZ; break;
  1380. case ENCODING_NRZI: new_encoding = HDLC_ENCODING_NRZI_SPACE; break;
  1381. case ENCODING_FM_MARK: new_encoding = HDLC_ENCODING_BIPHASE_MARK; break;
  1382. case ENCODING_FM_SPACE: new_encoding = HDLC_ENCODING_BIPHASE_SPACE; break;
  1383. case ENCODING_MANCHESTER: new_encoding = HDLC_ENCODING_BIPHASE_LEVEL; break;
  1384. default: return -EINVAL;
  1385. }
  1386. switch (parity)
  1387. {
  1388. case PARITY_NONE: new_crctype = HDLC_CRC_NONE; break;
  1389. case PARITY_CRC16_PR1_CCITT: new_crctype = HDLC_CRC_16_CCITT; break;
  1390. case PARITY_CRC32_PR1_CCITT: new_crctype = HDLC_CRC_32_CCITT; break;
  1391. default: return -EINVAL;
  1392. }
  1393. info->params.encoding = new_encoding;
  1394. info->params.crc_type = new_crctype;;
  1395. /* if network interface up, reprogram hardware */
  1396. if (info->netcount)
  1397. program_hw(info);
  1398. return 0;
  1399. }
  1400. /**
  1401. * called by generic HDLC layer to send frame
  1402. *
  1403. * skb socket buffer containing HDLC frame
  1404. * dev pointer to network device structure
  1405. *
  1406. * returns 0 if success, otherwise error code
  1407. */
  1408. static int hdlcdev_xmit(struct sk_buff *skb, struct net_device *dev)
  1409. {
  1410. SLMP_INFO *info = dev_to_port(dev);
  1411. struct net_device_stats *stats = hdlc_stats(dev);
  1412. unsigned long flags;
  1413. if (debug_level >= DEBUG_LEVEL_INFO)
  1414. printk(KERN_INFO "%s:hdlc_xmit(%s)\n",__FILE__,dev->name);
  1415. /* stop sending until this frame completes */
  1416. netif_stop_queue(dev);
  1417. /* copy data to device buffers */
  1418. info->tx_count = skb->len;
  1419. tx_load_dma_buffer(info, skb->data, skb->len);
  1420. /* update network statistics */
  1421. stats->tx_packets++;
  1422. stats->tx_bytes += skb->len;
  1423. /* done with socket buffer, so free it */
  1424. dev_kfree_skb(skb);
  1425. /* save start time for transmit timeout detection */
  1426. dev->trans_start = jiffies;
  1427. /* start hardware transmitter if necessary */
  1428. spin_lock_irqsave(&info->lock,flags);
  1429. if (!info->tx_active)
  1430. tx_start(info);
  1431. spin_unlock_irqrestore(&info->lock,flags);
  1432. return 0;
  1433. }
  1434. /**
  1435. * called by network layer when interface enabled
  1436. * claim resources and initialize hardware
  1437. *
  1438. * dev pointer to network device structure
  1439. *
  1440. * returns 0 if success, otherwise error code
  1441. */
  1442. static int hdlcdev_open(struct net_device *dev)
  1443. {
  1444. SLMP_INFO *info = dev_to_port(dev);
  1445. int rc;
  1446. unsigned long flags;
  1447. if (debug_level >= DEBUG_LEVEL_INFO)
  1448. printk("%s:hdlcdev_open(%s)\n",__FILE__,dev->name);
  1449. /* generic HDLC layer open processing */
  1450. if ((rc = hdlc_open(dev)))
  1451. return rc;
  1452. /* arbitrate between network and tty opens */
  1453. spin_lock_irqsave(&info->netlock, flags);
  1454. if (info->count != 0 || info->netcount != 0) {
  1455. printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
  1456. spin_unlock_irqrestore(&info->netlock, flags);
  1457. return -EBUSY;
  1458. }
  1459. info->netcount=1;
  1460. spin_unlock_irqrestore(&info->netlock, flags);
  1461. /* claim resources and init adapter */
  1462. if ((rc = startup(info)) != 0) {
  1463. spin_lock_irqsave(&info->netlock, flags);
  1464. info->netcount=0;
  1465. spin_unlock_irqrestore(&info->netlock, flags);
  1466. return rc;
  1467. }
  1468. /* assert DTR and RTS, apply hardware settings */
  1469. info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
  1470. program_hw(info);
  1471. /* enable network layer transmit */
  1472. dev->trans_start = jiffies;
  1473. netif_start_queue(dev);
  1474. /* inform generic HDLC layer of current DCD status */
  1475. spin_lock_irqsave(&info->lock, flags);
  1476. get_signals(info);
  1477. spin_unlock_irqrestore(&info->lock, flags);
  1478. hdlc_set_carrier(info->serial_signals & SerialSignal_DCD, dev);
  1479. return 0;
  1480. }
  1481. /**
  1482. * called by network layer when interface is disabled
  1483. * shutdown hardware and release resources
  1484. *
  1485. * dev pointer to network device structure
  1486. *
  1487. * returns 0 if success, otherwise error code
  1488. */
  1489. static int hdlcdev_close(struct net_device *dev)
  1490. {
  1491. SLMP_INFO *info = dev_to_port(dev);
  1492. unsigned long flags;
  1493. if (debug_level >= DEBUG_LEVEL_INFO)
  1494. printk("%s:hdlcdev_close(%s)\n",__FILE__,dev->name);
  1495. netif_stop_queue(dev);
  1496. /* shutdown adapter and release resources */
  1497. shutdown(info);
  1498. hdlc_close(dev);
  1499. spin_lock_irqsave(&info->netlock, flags);
  1500. info->netcount=0;
  1501. spin_unlock_irqrestore(&info->netlock, flags);
  1502. return 0;
  1503. }
  1504. /**
  1505. * called by network layer to process IOCTL call to network device
  1506. *
  1507. * dev pointer to network device structure
  1508. * ifr pointer to network interface request structure
  1509. * cmd IOCTL command code
  1510. *
  1511. * returns 0 if success, otherwise error code
  1512. */
  1513. static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  1514. {
  1515. const size_t size = sizeof(sync_serial_settings);
  1516. sync_serial_settings new_line;
  1517. sync_serial_settings __user *line = ifr->ifr_settings.ifs_ifsu.sync;
  1518. SLMP_INFO *info = dev_to_port(dev);
  1519. unsigned int flags;
  1520. if (debug_level >= DEBUG_LEVEL_INFO)
  1521. printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
  1522. /* return error if TTY interface open */
  1523. if (info->count)
  1524. return -EBUSY;
  1525. if (cmd != SIOCWANDEV)
  1526. return hdlc_ioctl(dev, ifr, cmd);
  1527. switch(ifr->ifr_settings.type) {
  1528. case IF_GET_IFACE: /* return current sync_serial_settings */
  1529. ifr->ifr_settings.type = IF_IFACE_SYNC_SERIAL;
  1530. if (ifr->ifr_settings.size < size) {
  1531. ifr->ifr_settings.size = size; /* data size wanted */
  1532. return -ENOBUFS;
  1533. }
  1534. flags = info->params.flags & (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
  1535. HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
  1536. HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
  1537. HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
  1538. switch (flags){
  1539. case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN): new_line.clock_type = CLOCK_EXT; break;
  1540. case (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_INT; break;
  1541. case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG): new_line.clock_type = CLOCK_TXINT; break;
  1542. case (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN): new_line.clock_type = CLOCK_TXFROMRX; break;
  1543. default: new_line.clock_type = CLOCK_DEFAULT;
  1544. }
  1545. new_line.clock_rate = info->params.clock_speed;
  1546. new_line.loopback = info->params.loopback ? 1:0;
  1547. if (copy_to_user(line, &new_line, size))
  1548. return -EFAULT;
  1549. return 0;
  1550. case IF_IFACE_SYNC_SERIAL: /* set sync_serial_settings */
  1551. if(!capable(CAP_NET_ADMIN))
  1552. return -EPERM;
  1553. if (copy_from_user(&new_line, line, size))
  1554. return -EFAULT;
  1555. switch (new_line.clock_type)
  1556. {
  1557. case CLOCK_EXT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_TXCPIN; break;
  1558. case CLOCK_TXFROMRX: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_RXCPIN; break;
  1559. case CLOCK_INT: flags = HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG; break;
  1560. case CLOCK_TXINT: flags = HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_TXC_BRG; break;
  1561. case CLOCK_DEFAULT: flags = info->params.flags &
  1562. (HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
  1563. HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
  1564. HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
  1565. HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN); break;
  1566. default: return -EINVAL;
  1567. }
  1568. if (new_line.loopback != 0 && new_line.loopback != 1)
  1569. return -EINVAL;
  1570. info->params.flags &= ~(HDLC_FLAG_RXC_RXCPIN | HDLC_FLAG_RXC_DPLL |
  1571. HDLC_FLAG_RXC_BRG | HDLC_FLAG_RXC_TXCPIN |
  1572. HDLC_FLAG_TXC_TXCPIN | HDLC_FLAG_TXC_DPLL |
  1573. HDLC_FLAG_TXC_BRG | HDLC_FLAG_TXC_RXCPIN);
  1574. info->params.flags |= flags;
  1575. info->params.loopback = new_line.loopback;
  1576. if (flags & (HDLC_FLAG_RXC_BRG | HDLC_FLAG_TXC_BRG))
  1577. info->params.clock_speed = new_line.clock_rate;
  1578. else
  1579. info->params.clock_speed = 0;
  1580. /* if network interface up, reprogram hardware */
  1581. if (info->netcount)
  1582. program_hw(info);
  1583. return 0;
  1584. default:
  1585. return hdlc_ioctl(dev, ifr, cmd);
  1586. }
  1587. }
  1588. /**
  1589. * called by network layer when transmit timeout is detected
  1590. *
  1591. * dev pointer to network device structure
  1592. */
  1593. static void hdlcdev_tx_timeout(struct net_device *dev)
  1594. {
  1595. SLMP_INFO *info = dev_to_port(dev);
  1596. struct net_device_stats *stats = hdlc_stats(dev);
  1597. unsigned long flags;
  1598. if (debug_level >= DEBUG_LEVEL_INFO)
  1599. printk("hdlcdev_tx_timeout(%s)\n",dev->name);
  1600. stats->tx_errors++;
  1601. stats->tx_aborted_errors++;
  1602. spin_lock_irqsave(&info->lock,flags);
  1603. tx_stop(info);
  1604. spin_unlock_irqrestore(&info->lock,flags);
  1605. netif_wake_queue(dev);
  1606. }
  1607. /**
  1608. * called by device driver when transmit completes
  1609. * reenable network layer transmit if stopped
  1610. *
  1611. * info pointer to device instance information
  1612. */
  1613. static void hdlcdev_tx_done(SLMP_INFO *info)
  1614. {
  1615. if (netif_queue_stopped(info->netdev))
  1616. netif_wake_queue(info->netdev);
  1617. }
  1618. /**
  1619. * called by device driver when frame received
  1620. * pass frame to network layer
  1621. *
  1622. * info pointer to device instance information
  1623. * buf pointer to buffer contianing frame data
  1624. * size count of data bytes in buf
  1625. */
  1626. static void hdlcdev_rx(SLMP_INFO *info, char *buf, int size)
  1627. {
  1628. struct sk_buff *skb = dev_alloc_skb(size);
  1629. struct net_device *dev = info->netdev;
  1630. struct net_device_stats *stats = hdlc_stats(dev);
  1631. if (debug_level >= DEBUG_LEVEL_INFO)
  1632. printk("hdlcdev_rx(%s)\n",dev->name);
  1633. if (skb == NULL) {
  1634. printk(KERN_NOTICE "%s: can't alloc skb, dropping packet\n", dev->name);
  1635. stats->rx_dropped++;
  1636. return;
  1637. }
  1638. memcpy(skb_put(skb, size),buf,size);
  1639. skb->protocol = hdlc_type_trans(skb, info->netdev);
  1640. stats->rx_packets++;
  1641. stats->rx_bytes += size;
  1642. netif_rx(skb);
  1643. info->netdev->last_rx = jiffies;
  1644. }
  1645. /**
  1646. * called by device driver when adding device instance
  1647. * do generic HDLC initialization
  1648. *
  1649. * info pointer to device instance information
  1650. *
  1651. * returns 0 if success, otherwise error code
  1652. */
  1653. static int hdlcdev_init(SLMP_INFO *info)
  1654. {
  1655. int rc;
  1656. struct net_device *dev;
  1657. hdlc_device *hdlc;
  1658. /* allocate and initialize network and HDLC layer objects */
  1659. if (!(dev = alloc_hdlcdev(info))) {
  1660. printk(KERN_ERR "%s:hdlc device allocation failure\n",__FILE__);
  1661. return -ENOMEM;
  1662. }
  1663. /* for network layer reporting purposes only */
  1664. dev->mem_start = info->phys_sca_base;
  1665. dev->mem_end = info->phys_sca_base + SCA_BASE_SIZE - 1;
  1666. dev->irq = info->irq_level;
  1667. /* network layer callbacks and settings */
  1668. dev->do_ioctl = hdlcdev_ioctl;
  1669. dev->open = hdlcdev_open;
  1670. dev->stop = hdlcdev_close;
  1671. dev->tx_timeout = hdlcdev_tx_timeout;
  1672. dev->watchdog_timeo = 10*HZ;
  1673. dev->tx_queue_len = 50;
  1674. /* generic HDLC layer callbacks and settings */
  1675. hdlc = dev_to_hdlc(dev);
  1676. hdlc->attach = hdlcdev_attach;
  1677. hdlc->xmit = hdlcdev_xmit;
  1678. /* register objects with HDLC layer */
  1679. if ((rc = register_hdlc_device(dev))) {
  1680. printk(KERN_WARNING "%s:unable to register hdlc device\n",__FILE__);
  1681. free_netdev(dev);
  1682. return rc;
  1683. }
  1684. info->netdev = dev;
  1685. return 0;
  1686. }
  1687. /**
  1688. * called by device driver when removing device instance
  1689. * do generic HDLC cleanup
  1690. *
  1691. * info pointer to device instance information
  1692. */
  1693. static void hdlcdev_exit(SLMP_INFO *info)
  1694. {
  1695. unregister_hdlc_device(info->netdev);
  1696. free_netdev(info->netdev);
  1697. info->netdev = NULL;
  1698. }
  1699. #endif /* CONFIG_HDLC */
  1700. /* Return next bottom half action to perform.
  1701. * Return Value: BH action code or 0 if nothing to do.
  1702. */
  1703. int bh_action(SLMP_INFO *info)
  1704. {
  1705. unsigned long flags;
  1706. int rc = 0;
  1707. spin_lock_irqsave(&info->lock,flags);
  1708. if (info->pending_bh & BH_RECEIVE) {
  1709. info->pending_bh &= ~BH_RECEIVE;
  1710. rc = BH_RECEIVE;
  1711. } else if (info->pending_bh & BH_TRANSMIT) {
  1712. info->pending_bh &= ~BH_TRANSMIT;
  1713. rc = BH_TRANSMIT;
  1714. } else if (info->pending_bh & BH_STATUS) {
  1715. info->pending_bh &= ~BH_STATUS;
  1716. rc = BH_STATUS;
  1717. }
  1718. if (!rc) {
  1719. /* Mark BH routine as complete */
  1720. info->bh_running = 0;
  1721. info->bh_requested = 0;
  1722. }
  1723. spin_unlock_irqrestore(&info->lock,flags);
  1724. return rc;
  1725. }
  1726. /* Perform bottom half processing of work items queued by ISR.
  1727. */
  1728. void bh_handler(void* Context)
  1729. {
  1730. SLMP_INFO *info = (SLMP_INFO*)Context;
  1731. int action;
  1732. if (!info)
  1733. return;
  1734. if ( debug_level >= DEBUG_LEVEL_BH )
  1735. printk( "%s(%d):%s bh_handler() entry\n",
  1736. __FILE__,__LINE__,info->device_name);
  1737. info->bh_running = 1;
  1738. while((action = bh_action(info)) != 0) {
  1739. /* Process work item */
  1740. if ( debug_level >= DEBUG_LEVEL_BH )
  1741. printk( "%s(%d):%s bh_handler() work item action=%d\n",
  1742. __FILE__,__LINE__,info->device_name, action);
  1743. switch (action) {
  1744. case BH_RECEIVE:
  1745. bh_receive(info);
  1746. break;
  1747. case BH_TRANSMIT:
  1748. bh_transmit(info);
  1749. break;
  1750. case BH_STATUS:
  1751. bh_status(info);
  1752. break;
  1753. default:
  1754. /* unknown work item ID */
  1755. printk("%s(%d):%s Unknown work item ID=%08X!\n",
  1756. __FILE__,__LINE__,info->device_name,action);
  1757. break;
  1758. }
  1759. }
  1760. if ( debug_level >= DEBUG_LEVEL_BH )
  1761. printk( "%s(%d):%s bh_handler() exit\n",
  1762. __FILE__,__LINE__,info->device_name);
  1763. }
  1764. void bh_receive(SLMP_INFO *info)
  1765. {
  1766. if ( debug_level >= DEBUG_LEVEL_BH )
  1767. printk( "%s(%d):%s bh_receive()\n",
  1768. __FILE__,__LINE__,info->device_name);
  1769. while( rx_get_frame(info) );
  1770. }
  1771. void bh_transmit(SLMP_INFO *info)
  1772. {
  1773. struct tty_struct *tty = info->tty;
  1774. if ( debug_level >= DEBUG_LEVEL_BH )
  1775. printk( "%s(%d):%s bh_transmit() entry\n",
  1776. __FILE__,__LINE__,info->device_name);
  1777. if (tty) {
  1778. tty_wakeup(tty);
  1779. wake_up_interruptible(&tty->write_wait);
  1780. }
  1781. }
  1782. void bh_status(SLMP_INFO *info)
  1783. {
  1784. if ( debug_level >= DEBUG_LEVEL_BH )
  1785. printk( "%s(%d):%s bh_status() entry\n",
  1786. __FILE__,__LINE__,info->device_name);
  1787. info->ri_chkcount = 0;
  1788. info->dsr_chkcount = 0;
  1789. info->dcd_chkcount = 0;
  1790. info->cts_chkcount = 0;
  1791. }
  1792. void isr_timer(SLMP_INFO * info)
  1793. {
  1794. unsigned char timer = (info->port_num & 1) ? TIMER2 : TIMER0;
  1795. /* IER2<7..4> = timer<3..0> interrupt enables (0=disabled) */
  1796. write_reg(info, IER2, 0);
  1797. /* TMCS, Timer Control/Status Register
  1798. *
  1799. * 07 CMF, Compare match flag (read only) 1=match
  1800. * 06 ECMI, CMF Interrupt Enable: 0=disabled
  1801. * 05 Reserved, must be 0
  1802. * 04 TME, Timer Enable
  1803. * 03..00 Reserved, must be 0
  1804. *
  1805. * 0000 0000
  1806. */
  1807. write_reg(info, (unsigned char)(timer + TMCS), 0);
  1808. info->irq_occurred = TRUE;
  1809. if ( debug_level >= DEBUG_LEVEL_ISR )
  1810. printk("%s(%d):%s isr_timer()\n",
  1811. __FILE__,__LINE__,info->device_name);
  1812. }
  1813. void isr_rxint(SLMP_INFO * info)
  1814. {
  1815. struct tty_struct *tty = info->tty;
  1816. struct mgsl_icount *icount = &info->icount;
  1817. unsigned char status = read_reg(info, SR1) & info->ie1_value & (FLGD + IDLD + CDCD + BRKD);
  1818. unsigned char status2 = read_reg(info, SR2) & info->ie2_value & OVRN;
  1819. /* clear status bits */
  1820. if (status)
  1821. write_reg(info, SR1, status);
  1822. if (status2)
  1823. write_reg(info, SR2, status2);
  1824. if ( debug_level >= DEBUG_LEVEL_ISR )
  1825. printk("%s(%d):%s isr_rxint status=%02X %02x\n",
  1826. __FILE__,__LINE__,info->device_name,status,status2);
  1827. if (info->params.mode == MGSL_MODE_ASYNC) {
  1828. if (status & BRKD) {
  1829. icount->brk++;
  1830. /* process break detection if tty control
  1831. * is not set to ignore it
  1832. */
  1833. if ( tty ) {
  1834. if (!(status & info->ignore_status_mask1)) {
  1835. if (info->read_status_mask1 & BRKD) {
  1836. *tty->flip.flag_buf_ptr = TTY_BREAK;
  1837. if (info->flags & ASYNC_SAK)
  1838. do_SAK(tty);
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. else {
  1845. if (status & (FLGD|IDLD)) {
  1846. if (status & FLGD)
  1847. info->icount.exithunt++;
  1848. else if (status & IDLD)
  1849. info->icount.rxidle++;
  1850. wake_up_interruptible(&info->event_wait_q);
  1851. }
  1852. }
  1853. if (status & CDCD) {
  1854. /* simulate a common modem status change interrupt
  1855. * for our handler
  1856. */
  1857. get_signals( info );
  1858. isr_io_pin(info,
  1859. MISCSTATUS_DCD_LATCHED|(info->serial_signals&SerialSignal_DCD));
  1860. }
  1861. }
  1862. /*
  1863. * handle async rx data interrupts
  1864. */
  1865. void isr_rxrdy(SLMP_INFO * info)
  1866. {
  1867. u16 status;
  1868. unsigned char DataByte;
  1869. struct tty_struct *tty = info->tty;
  1870. struct mgsl_icount *icount = &info->icount;
  1871. if ( debug_level >= DEBUG_LEVEL_ISR )
  1872. printk("%s(%d):%s isr_rxrdy\n",
  1873. __FILE__,__LINE__,info->device_name);
  1874. while((status = read_reg(info,CST0)) & BIT0)
  1875. {
  1876. DataByte = read_reg(info,TRB);
  1877. if ( tty ) {
  1878. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  1879. continue;
  1880. *tty->flip.char_buf_ptr = DataByte;
  1881. *tty->flip.flag_buf_ptr = 0;
  1882. }
  1883. icount->rx++;
  1884. if ( status & (PE + FRME + OVRN) ) {
  1885. printk("%s(%d):%s rxerr=%04X\n",
  1886. __FILE__,__LINE__,info->device_name,status);
  1887. /* update error statistics */
  1888. if (status & PE)
  1889. icount->parity++;
  1890. else if (status & FRME)
  1891. icount->frame++;
  1892. else if (status & OVRN)
  1893. icount->overrun++;
  1894. /* discard char if tty control flags say so */
  1895. if (status & info->ignore_status_mask2)
  1896. continue;
  1897. status &= info->read_status_mask2;
  1898. if ( tty ) {
  1899. if (status & PE)
  1900. *tty->flip.flag_buf_ptr = TTY_PARITY;
  1901. else if (status & FRME)
  1902. *tty->flip.flag_buf_ptr = TTY_FRAME;
  1903. if (status & OVRN) {
  1904. /* Overrun is special, since it's
  1905. * reported immediately, and doesn't
  1906. * affect the current character
  1907. */
  1908. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  1909. tty->flip.count++;
  1910. tty->flip.flag_buf_ptr++;
  1911. tty->flip.char_buf_ptr++;
  1912. *tty->flip.flag_buf_ptr = TTY_OVERRUN;
  1913. }
  1914. }
  1915. }
  1916. } /* end of if (error) */
  1917. if ( tty ) {
  1918. tty->flip.flag_buf_ptr++;
  1919. tty->flip.char_buf_ptr++;
  1920. tty->flip.count++;
  1921. }
  1922. }
  1923. if ( debug_level >= DEBUG_LEVEL_ISR ) {
  1924. printk("%s(%d):%s isr_rxrdy() flip count=%d\n",
  1925. __FILE__,__LINE__,info->device_name,
  1926. tty ? tty->flip.count : 0);
  1927. printk("%s(%d):%s rx=%d brk=%d parity=%d frame=%d overrun=%d\n",
  1928. __FILE__,__LINE__,info->device_name,
  1929. icount->rx,icount->brk,icount->parity,
  1930. icount->frame,icount->overrun);
  1931. }
  1932. if ( tty && tty->flip.count )
  1933. tty_flip_buffer_push(tty);
  1934. }
  1935. static void isr_txeom(SLMP_INFO * info, unsigned char status)
  1936. {
  1937. if ( debug_level >= DEBUG_LEVEL_ISR )
  1938. printk("%s(%d):%s isr_txeom status=%02x\n",
  1939. __FILE__,__LINE__,info->device_name,status);
  1940. write_reg(info, TXDMA + DIR, 0x00); /* disable Tx DMA IRQs */
  1941. write_reg(info, TXDMA + DSR, 0xc0); /* clear IRQs and disable DMA */
  1942. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  1943. if (status & UDRN) {
  1944. write_reg(info, CMD, TXRESET);
  1945. write_reg(info, CMD, TXENABLE);
  1946. } else
  1947. write_reg(info, CMD, TXBUFCLR);
  1948. /* disable and clear tx interrupts */
  1949. info->ie0_value &= ~TXRDYE;
  1950. info->ie1_value &= ~(IDLE + UDRN);
  1951. write_reg16(info, IE0, (unsigned short)((info->ie1_value << 8) + info->ie0_value));
  1952. write_reg(info, SR1, (unsigned char)(UDRN + IDLE));
  1953. if ( info->tx_active ) {
  1954. if (info->params.mode != MGSL_MODE_ASYNC) {
  1955. if (status & UDRN)
  1956. info->icount.txunder++;
  1957. else if (status & IDLE)
  1958. info->icount.txok++;
  1959. }
  1960. info->tx_active = 0;
  1961. info->tx_count = info->tx_put = info->tx_get = 0;
  1962. del_timer(&info->tx_timer);
  1963. if (info->params.mode != MGSL_MODE_ASYNC && info->drop_rts_on_tx_done ) {
  1964. info->serial_signals &= ~SerialSignal_RTS;
  1965. info->drop_rts_on_tx_done = 0;
  1966. set_signals(info);
  1967. }
  1968. #ifdef CONFIG_HDLC
  1969. if (info->netcount)
  1970. hdlcdev_tx_done(info);
  1971. else
  1972. #endif
  1973. {
  1974. if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
  1975. tx_stop(info);
  1976. return;
  1977. }
  1978. info->pending_bh |= BH_TRANSMIT;
  1979. }
  1980. }
  1981. }
  1982. /*
  1983. * handle tx status interrupts
  1984. */
  1985. void isr_txint(SLMP_INFO * info)
  1986. {
  1987. unsigned char status = read_reg(info, SR1) & info->ie1_value & (UDRN + IDLE + CCTS);
  1988. /* clear status bits */
  1989. write_reg(info, SR1, status);
  1990. if ( debug_level >= DEBUG_LEVEL_ISR )
  1991. printk("%s(%d):%s isr_txint status=%02x\n",
  1992. __FILE__,__LINE__,info->device_name,status);
  1993. if (status & (UDRN + IDLE))
  1994. isr_txeom(info, status);
  1995. if (status & CCTS) {
  1996. /* simulate a common modem status change interrupt
  1997. * for our handler
  1998. */
  1999. get_signals( info );
  2000. isr_io_pin(info,
  2001. MISCSTATUS_CTS_LATCHED|(info->serial_signals&SerialSignal_CTS));
  2002. }
  2003. }
  2004. /*
  2005. * handle async tx data interrupts
  2006. */
  2007. void isr_txrdy(SLMP_INFO * info)
  2008. {
  2009. if ( debug_level >= DEBUG_LEVEL_ISR )
  2010. printk("%s(%d):%s isr_txrdy() tx_count=%d\n",
  2011. __FILE__,__LINE__,info->device_name,info->tx_count);
  2012. if (info->params.mode != MGSL_MODE_ASYNC) {
  2013. /* disable TXRDY IRQ, enable IDLE IRQ */
  2014. info->ie0_value &= ~TXRDYE;
  2015. info->ie1_value |= IDLE;
  2016. write_reg16(info, IE0, (unsigned short)((info->ie1_value << 8) + info->ie0_value));
  2017. return;
  2018. }
  2019. if (info->tty && (info->tty->stopped || info->tty->hw_stopped)) {
  2020. tx_stop(info);
  2021. return;
  2022. }
  2023. if ( info->tx_count )
  2024. tx_load_fifo( info );
  2025. else {
  2026. info->tx_active = 0;
  2027. info->ie0_value &= ~TXRDYE;
  2028. write_reg(info, IE0, info->ie0_value);
  2029. }
  2030. if (info->tx_count < WAKEUP_CHARS)
  2031. info->pending_bh |= BH_TRANSMIT;
  2032. }
  2033. void isr_rxdmaok(SLMP_INFO * info)
  2034. {
  2035. /* BIT7 = EOT (end of transfer)
  2036. * BIT6 = EOM (end of message/frame)
  2037. */
  2038. unsigned char status = read_reg(info,RXDMA + DSR) & 0xc0;
  2039. /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
  2040. write_reg(info, RXDMA + DSR, (unsigned char)(status | 1));
  2041. if ( debug_level >= DEBUG_LEVEL_ISR )
  2042. printk("%s(%d):%s isr_rxdmaok(), status=%02x\n",
  2043. __FILE__,__LINE__,info->device_name,status);
  2044. info->pending_bh |= BH_RECEIVE;
  2045. }
  2046. void isr_rxdmaerror(SLMP_INFO * info)
  2047. {
  2048. /* BIT5 = BOF (buffer overflow)
  2049. * BIT4 = COF (counter overflow)
  2050. */
  2051. unsigned char status = read_reg(info,RXDMA + DSR) & 0x30;
  2052. /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
  2053. write_reg(info, RXDMA + DSR, (unsigned char)(status | 1));
  2054. if ( debug_level >= DEBUG_LEVEL_ISR )
  2055. printk("%s(%d):%s isr_rxdmaerror(), status=%02x\n",
  2056. __FILE__,__LINE__,info->device_name,status);
  2057. info->rx_overflow = TRUE;
  2058. info->pending_bh |= BH_RECEIVE;
  2059. }
  2060. void isr_txdmaok(SLMP_INFO * info)
  2061. {
  2062. unsigned char status_reg1 = read_reg(info, SR1);
  2063. write_reg(info, TXDMA + DIR, 0x00); /* disable Tx DMA IRQs */
  2064. write_reg(info, TXDMA + DSR, 0xc0); /* clear IRQs and disable DMA */
  2065. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  2066. if ( debug_level >= DEBUG_LEVEL_ISR )
  2067. printk("%s(%d):%s isr_txdmaok(), status=%02x\n",
  2068. __FILE__,__LINE__,info->device_name,status_reg1);
  2069. /* program TXRDY as FIFO empty flag, enable TXRDY IRQ */
  2070. write_reg16(info, TRC0, 0);
  2071. info->ie0_value |= TXRDYE;
  2072. write_reg(info, IE0, info->ie0_value);
  2073. }
  2074. void isr_txdmaerror(SLMP_INFO * info)
  2075. {
  2076. /* BIT5 = BOF (buffer overflow)
  2077. * BIT4 = COF (counter overflow)
  2078. */
  2079. unsigned char status = read_reg(info,TXDMA + DSR) & 0x30;
  2080. /* clear IRQ (BIT0 must be 1 to prevent clearing DE bit) */
  2081. write_reg(info, TXDMA + DSR, (unsigned char)(status | 1));
  2082. if ( debug_level >= DEBUG_LEVEL_ISR )
  2083. printk("%s(%d):%s isr_txdmaerror(), status=%02x\n",
  2084. __FILE__,__LINE__,info->device_name,status);
  2085. }
  2086. /* handle input serial signal changes
  2087. */
  2088. void isr_io_pin( SLMP_INFO *info, u16 status )
  2089. {
  2090. struct mgsl_icount *icount;
  2091. if ( debug_level >= DEBUG_LEVEL_ISR )
  2092. printk("%s(%d):isr_io_pin status=%04X\n",
  2093. __FILE__,__LINE__,status);
  2094. if (status & (MISCSTATUS_CTS_LATCHED | MISCSTATUS_DCD_LATCHED |
  2095. MISCSTATUS_DSR_LATCHED | MISCSTATUS_RI_LATCHED) ) {
  2096. icount = &info->icount;
  2097. /* update input line counters */
  2098. if (status & MISCSTATUS_RI_LATCHED) {
  2099. icount->rng++;
  2100. if ( status & SerialSignal_RI )
  2101. info->input_signal_events.ri_up++;
  2102. else
  2103. info->input_signal_events.ri_down++;
  2104. }
  2105. if (status & MISCSTATUS_DSR_LATCHED) {
  2106. icount->dsr++;
  2107. if ( status & SerialSignal_DSR )
  2108. info->input_signal_events.dsr_up++;
  2109. else
  2110. info->input_signal_events.dsr_down++;
  2111. }
  2112. if (status & MISCSTATUS_DCD_LATCHED) {
  2113. if ((info->dcd_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) {
  2114. info->ie1_value &= ~CDCD;
  2115. write_reg(info, IE1, info->ie1_value);
  2116. }
  2117. icount->dcd++;
  2118. if (status & SerialSignal_DCD) {
  2119. info->input_signal_events.dcd_up++;
  2120. } else
  2121. info->input_signal_events.dcd_down++;
  2122. #ifdef CONFIG_HDLC
  2123. if (info->netcount)
  2124. hdlc_set_carrier(status & SerialSignal_DCD, info->netdev);
  2125. #endif
  2126. }
  2127. if (status & MISCSTATUS_CTS_LATCHED)
  2128. {
  2129. if ((info->cts_chkcount)++ >= IO_PIN_SHUTDOWN_LIMIT) {
  2130. info->ie1_value &= ~CCTS;
  2131. write_reg(info, IE1, info->ie1_value);
  2132. }
  2133. icount->cts++;
  2134. if ( status & SerialSignal_CTS )
  2135. info->input_signal_events.cts_up++;
  2136. else
  2137. info->input_signal_events.cts_down++;
  2138. }
  2139. wake_up_interruptible(&info->status_event_wait_q);
  2140. wake_up_interruptible(&info->event_wait_q);
  2141. if ( (info->flags & ASYNC_CHECK_CD) &&
  2142. (status & MISCSTATUS_DCD_LATCHED) ) {
  2143. if ( debug_level >= DEBUG_LEVEL_ISR )
  2144. printk("%s CD now %s...", info->device_name,
  2145. (status & SerialSignal_DCD) ? "on" : "off");
  2146. if (status & SerialSignal_DCD)
  2147. wake_up_interruptible(&info->open_wait);
  2148. else {
  2149. if ( debug_level >= DEBUG_LEVEL_ISR )
  2150. printk("doing serial hangup...");
  2151. if (info->tty)
  2152. tty_hangup(info->tty);
  2153. }
  2154. }
  2155. if ( (info->flags & ASYNC_CTS_FLOW) &&
  2156. (status & MISCSTATUS_CTS_LATCHED) ) {
  2157. if ( info->tty ) {
  2158. if (info->tty->hw_stopped) {
  2159. if (status & SerialSignal_CTS) {
  2160. if ( debug_level >= DEBUG_LEVEL_ISR )
  2161. printk("CTS tx start...");
  2162. info->tty->hw_stopped = 0;
  2163. tx_start(info);
  2164. info->pending_bh |= BH_TRANSMIT;
  2165. return;
  2166. }
  2167. } else {
  2168. if (!(status & SerialSignal_CTS)) {
  2169. if ( debug_level >= DEBUG_LEVEL_ISR )
  2170. printk("CTS tx stop...");
  2171. info->tty->hw_stopped = 1;
  2172. tx_stop(info);
  2173. }
  2174. }
  2175. }
  2176. }
  2177. }
  2178. info->pending_bh |= BH_STATUS;
  2179. }
  2180. /* Interrupt service routine entry point.
  2181. *
  2182. * Arguments:
  2183. * irq interrupt number that caused interrupt
  2184. * dev_id device ID supplied during interrupt registration
  2185. * regs interrupted processor context
  2186. */
  2187. static irqreturn_t synclinkmp_interrupt(int irq, void *dev_id,
  2188. struct pt_regs *regs)
  2189. {
  2190. SLMP_INFO * info;
  2191. unsigned char status, status0, status1=0;
  2192. unsigned char dmastatus, dmastatus0, dmastatus1=0;
  2193. unsigned char timerstatus0, timerstatus1=0;
  2194. unsigned char shift;
  2195. unsigned int i;
  2196. unsigned short tmp;
  2197. if ( debug_level >= DEBUG_LEVEL_ISR )
  2198. printk("%s(%d): synclinkmp_interrupt(%d)entry.\n",
  2199. __FILE__,__LINE__,irq);
  2200. info = (SLMP_INFO *)dev_id;
  2201. if (!info)
  2202. return IRQ_NONE;
  2203. spin_lock(&info->lock);
  2204. for(;;) {
  2205. /* get status for SCA0 (ports 0-1) */
  2206. tmp = read_reg16(info, ISR0); /* get ISR0 and ISR1 in one read */
  2207. status0 = (unsigned char)tmp;
  2208. dmastatus0 = (unsigned char)(tmp>>8);
  2209. timerstatus0 = read_reg(info, ISR2);
  2210. if ( debug_level >= DEBUG_LEVEL_ISR )
  2211. printk("%s(%d):%s status0=%02x, dmastatus0=%02x, timerstatus0=%02x\n",
  2212. __FILE__,__LINE__,info->device_name,
  2213. status0,dmastatus0,timerstatus0);
  2214. if (info->port_count == 4) {
  2215. /* get status for SCA1 (ports 2-3) */
  2216. tmp = read_reg16(info->port_array[2], ISR0);
  2217. status1 = (unsigned char)tmp;
  2218. dmastatus1 = (unsigned char)(tmp>>8);
  2219. timerstatus1 = read_reg(info->port_array[2], ISR2);
  2220. if ( debug_level >= DEBUG_LEVEL_ISR )
  2221. printk("%s(%d):%s status1=%02x, dmastatus1=%02x, timerstatus1=%02x\n",
  2222. __FILE__,__LINE__,info->device_name,
  2223. status1,dmastatus1,timerstatus1);
  2224. }
  2225. if (!status0 && !dmastatus0 && !timerstatus0 &&
  2226. !status1 && !dmastatus1 && !timerstatus1)
  2227. break;
  2228. for(i=0; i < info->port_count ; i++) {
  2229. if (info->port_array[i] == NULL)
  2230. continue;
  2231. if (i < 2) {
  2232. status = status0;
  2233. dmastatus = dmastatus0;
  2234. } else {
  2235. status = status1;
  2236. dmastatus = dmastatus1;
  2237. }
  2238. shift = i & 1 ? 4 :0;
  2239. if (status & BIT0 << shift)
  2240. isr_rxrdy(info->port_array[i]);
  2241. if (status & BIT1 << shift)
  2242. isr_txrdy(info->port_array[i]);
  2243. if (status & BIT2 << shift)
  2244. isr_rxint(info->port_array[i]);
  2245. if (status & BIT3 << shift)
  2246. isr_txint(info->port_array[i]);
  2247. if (dmastatus & BIT0 << shift)
  2248. isr_rxdmaerror(info->port_array[i]);
  2249. if (dmastatus & BIT1 << shift)
  2250. isr_rxdmaok(info->port_array[i]);
  2251. if (dmastatus & BIT2 << shift)
  2252. isr_txdmaerror(info->port_array[i]);
  2253. if (dmastatus & BIT3 << shift)
  2254. isr_txdmaok(info->port_array[i]);
  2255. }
  2256. if (timerstatus0 & (BIT5 | BIT4))
  2257. isr_timer(info->port_array[0]);
  2258. if (timerstatus0 & (BIT7 | BIT6))
  2259. isr_timer(info->port_array[1]);
  2260. if (timerstatus1 & (BIT5 | BIT4))
  2261. isr_timer(info->port_array[2]);
  2262. if (timerstatus1 & (BIT7 | BIT6))
  2263. isr_timer(info->port_array[3]);
  2264. }
  2265. for(i=0; i < info->port_count ; i++) {
  2266. SLMP_INFO * port = info->port_array[i];
  2267. /* Request bottom half processing if there's something
  2268. * for it to do and the bh is not already running.
  2269. *
  2270. * Note: startup adapter diags require interrupts.
  2271. * do not request bottom half processing if the
  2272. * device is not open in a normal mode.
  2273. */
  2274. if ( port && (port->count || port->netcount) &&
  2275. port->pending_bh && !port->bh_running &&
  2276. !port->bh_requested ) {
  2277. if ( debug_level >= DEBUG_LEVEL_ISR )
  2278. printk("%s(%d):%s queueing bh task.\n",
  2279. __FILE__,__LINE__,port->device_name);
  2280. schedule_work(&port->task);
  2281. port->bh_requested = 1;
  2282. }
  2283. }
  2284. spin_unlock(&info->lock);
  2285. if ( debug_level >= DEBUG_LEVEL_ISR )
  2286. printk("%s(%d):synclinkmp_interrupt(%d)exit.\n",
  2287. __FILE__,__LINE__,irq);
  2288. return IRQ_HANDLED;
  2289. }
  2290. /* Initialize and start device.
  2291. */
  2292. static int startup(SLMP_INFO * info)
  2293. {
  2294. if ( debug_level >= DEBUG_LEVEL_INFO )
  2295. printk("%s(%d):%s tx_releaseup()\n",__FILE__,__LINE__,info->device_name);
  2296. if (info->flags & ASYNC_INITIALIZED)
  2297. return 0;
  2298. if (!info->tx_buf) {
  2299. info->tx_buf = (unsigned char *)kmalloc(info->max_frame_size, GFP_KERNEL);
  2300. if (!info->tx_buf) {
  2301. printk(KERN_ERR"%s(%d):%s can't allocate transmit buffer\n",
  2302. __FILE__,__LINE__,info->device_name);
  2303. return -ENOMEM;
  2304. }
  2305. }
  2306. info->pending_bh = 0;
  2307. memset(&info->icount, 0, sizeof(info->icount));
  2308. /* program hardware for current parameters */
  2309. reset_port(info);
  2310. change_params(info);
  2311. info->status_timer.expires = jiffies + msecs_to_jiffies(10);
  2312. add_timer(&info->status_timer);
  2313. if (info->tty)
  2314. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  2315. info->flags |= ASYNC_INITIALIZED;
  2316. return 0;
  2317. }
  2318. /* Called by close() and hangup() to shutdown hardware
  2319. */
  2320. static void shutdown(SLMP_INFO * info)
  2321. {
  2322. unsigned long flags;
  2323. if (!(info->flags & ASYNC_INITIALIZED))
  2324. return;
  2325. if (debug_level >= DEBUG_LEVEL_INFO)
  2326. printk("%s(%d):%s synclinkmp_shutdown()\n",
  2327. __FILE__,__LINE__, info->device_name );
  2328. /* clear status wait queue because status changes */
  2329. /* can't happen after shutting down the hardware */
  2330. wake_up_interruptible(&info->status_event_wait_q);
  2331. wake_up_interruptible(&info->event_wait_q);
  2332. del_timer(&info->tx_timer);
  2333. del_timer(&info->status_timer);
  2334. if (info->tx_buf) {
  2335. kfree(info->tx_buf);
  2336. info->tx_buf = NULL;
  2337. }
  2338. spin_lock_irqsave(&info->lock,flags);
  2339. reset_port(info);
  2340. if (!info->tty || info->tty->termios->c_cflag & HUPCL) {
  2341. info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
  2342. set_signals(info);
  2343. }
  2344. spin_unlock_irqrestore(&info->lock,flags);
  2345. if (info->tty)
  2346. set_bit(TTY_IO_ERROR, &info->tty->flags);
  2347. info->flags &= ~ASYNC_INITIALIZED;
  2348. }
  2349. static void program_hw(SLMP_INFO *info)
  2350. {
  2351. unsigned long flags;
  2352. spin_lock_irqsave(&info->lock,flags);
  2353. rx_stop(info);
  2354. tx_stop(info);
  2355. info->tx_count = info->tx_put = info->tx_get = 0;
  2356. if (info->params.mode == MGSL_MODE_HDLC || info->netcount)
  2357. hdlc_mode(info);
  2358. else
  2359. async_mode(info);
  2360. set_signals(info);
  2361. info->dcd_chkcount = 0;
  2362. info->cts_chkcount = 0;
  2363. info->ri_chkcount = 0;
  2364. info->dsr_chkcount = 0;
  2365. info->ie1_value |= (CDCD|CCTS);
  2366. write_reg(info, IE1, info->ie1_value);
  2367. get_signals(info);
  2368. if (info->netcount || (info->tty && info->tty->termios->c_cflag & CREAD) )
  2369. rx_start(info);
  2370. spin_unlock_irqrestore(&info->lock,flags);
  2371. }
  2372. /* Reconfigure adapter based on new parameters
  2373. */
  2374. static void change_params(SLMP_INFO *info)
  2375. {
  2376. unsigned cflag;
  2377. int bits_per_char;
  2378. if (!info->tty || !info->tty->termios)
  2379. return;
  2380. if (debug_level >= DEBUG_LEVEL_INFO)
  2381. printk("%s(%d):%s change_params()\n",
  2382. __FILE__,__LINE__, info->device_name );
  2383. cflag = info->tty->termios->c_cflag;
  2384. /* if B0 rate (hangup) specified then negate DTR and RTS */
  2385. /* otherwise assert DTR and RTS */
  2386. if (cflag & CBAUD)
  2387. info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
  2388. else
  2389. info->serial_signals &= ~(SerialSignal_RTS + SerialSignal_DTR);
  2390. /* byte size and parity */
  2391. switch (cflag & CSIZE) {
  2392. case CS5: info->params.data_bits = 5; break;
  2393. case CS6: info->params.data_bits = 6; break;
  2394. case CS7: info->params.data_bits = 7; break;
  2395. case CS8: info->params.data_bits = 8; break;
  2396. /* Never happens, but GCC is too dumb to figure it out */
  2397. default: info->params.data_bits = 7; break;
  2398. }
  2399. if (cflag & CSTOPB)
  2400. info->params.stop_bits = 2;
  2401. else
  2402. info->params.stop_bits = 1;
  2403. info->params.parity = ASYNC_PARITY_NONE;
  2404. if (cflag & PARENB) {
  2405. if (cflag & PARODD)
  2406. info->params.parity = ASYNC_PARITY_ODD;
  2407. else
  2408. info->params.parity = ASYNC_PARITY_EVEN;
  2409. #ifdef CMSPAR
  2410. if (cflag & CMSPAR)
  2411. info->params.parity = ASYNC_PARITY_SPACE;
  2412. #endif
  2413. }
  2414. /* calculate number of jiffies to transmit a full
  2415. * FIFO (32 bytes) at specified data rate
  2416. */
  2417. bits_per_char = info->params.data_bits +
  2418. info->params.stop_bits + 1;
  2419. /* if port data rate is set to 460800 or less then
  2420. * allow tty settings to override, otherwise keep the
  2421. * current data rate.
  2422. */
  2423. if (info->params.data_rate <= 460800) {
  2424. info->params.data_rate = tty_get_baud_rate(info->tty);
  2425. }
  2426. if ( info->params.data_rate ) {
  2427. info->timeout = (32*HZ*bits_per_char) /
  2428. info->params.data_rate;
  2429. }
  2430. info->timeout += HZ/50; /* Add .02 seconds of slop */
  2431. if (cflag & CRTSCTS)
  2432. info->flags |= ASYNC_CTS_FLOW;
  2433. else
  2434. info->flags &= ~ASYNC_CTS_FLOW;
  2435. if (cflag & CLOCAL)
  2436. info->flags &= ~ASYNC_CHECK_CD;
  2437. else
  2438. info->flags |= ASYNC_CHECK_CD;
  2439. /* process tty input control flags */
  2440. info->read_status_mask2 = OVRN;
  2441. if (I_INPCK(info->tty))
  2442. info->read_status_mask2 |= PE | FRME;
  2443. if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
  2444. info->read_status_mask1 |= BRKD;
  2445. if (I_IGNPAR(info->tty))
  2446. info->ignore_status_mask2 |= PE | FRME;
  2447. if (I_IGNBRK(info->tty)) {
  2448. info->ignore_status_mask1 |= BRKD;
  2449. /* If ignoring parity and break indicators, ignore
  2450. * overruns too. (For real raw support).
  2451. */
  2452. if (I_IGNPAR(info->tty))
  2453. info->ignore_status_mask2 |= OVRN;
  2454. }
  2455. program_hw(info);
  2456. }
  2457. static int get_stats(SLMP_INFO * info, struct mgsl_icount __user *user_icount)
  2458. {
  2459. int err;
  2460. if (debug_level >= DEBUG_LEVEL_INFO)
  2461. printk("%s(%d):%s get_params()\n",
  2462. __FILE__,__LINE__, info->device_name);
  2463. if (!user_icount) {
  2464. memset(&info->icount, 0, sizeof(info->icount));
  2465. } else {
  2466. COPY_TO_USER(err, user_icount, &info->icount, sizeof(struct mgsl_icount));
  2467. if (err)
  2468. return -EFAULT;
  2469. }
  2470. return 0;
  2471. }
  2472. static int get_params(SLMP_INFO * info, MGSL_PARAMS __user *user_params)
  2473. {
  2474. int err;
  2475. if (debug_level >= DEBUG_LEVEL_INFO)
  2476. printk("%s(%d):%s get_params()\n",
  2477. __FILE__,__LINE__, info->device_name);
  2478. COPY_TO_USER(err,user_params, &info->params, sizeof(MGSL_PARAMS));
  2479. if (err) {
  2480. if ( debug_level >= DEBUG_LEVEL_INFO )
  2481. printk( "%s(%d):%s get_params() user buffer copy failed\n",
  2482. __FILE__,__LINE__,info->device_name);
  2483. return -EFAULT;
  2484. }
  2485. return 0;
  2486. }
  2487. static int set_params(SLMP_INFO * info, MGSL_PARAMS __user *new_params)
  2488. {
  2489. unsigned long flags;
  2490. MGSL_PARAMS tmp_params;
  2491. int err;
  2492. if (debug_level >= DEBUG_LEVEL_INFO)
  2493. printk("%s(%d):%s set_params\n",
  2494. __FILE__,__LINE__,info->device_name );
  2495. COPY_FROM_USER(err,&tmp_params, new_params, sizeof(MGSL_PARAMS));
  2496. if (err) {
  2497. if ( debug_level >= DEBUG_LEVEL_INFO )
  2498. printk( "%s(%d):%s set_params() user buffer copy failed\n",
  2499. __FILE__,__LINE__,info->device_name);
  2500. return -EFAULT;
  2501. }
  2502. spin_lock_irqsave(&info->lock,flags);
  2503. memcpy(&info->params,&tmp_params,sizeof(MGSL_PARAMS));
  2504. spin_unlock_irqrestore(&info->lock,flags);
  2505. change_params(info);
  2506. return 0;
  2507. }
  2508. static int get_txidle(SLMP_INFO * info, int __user *idle_mode)
  2509. {
  2510. int err;
  2511. if (debug_level >= DEBUG_LEVEL_INFO)
  2512. printk("%s(%d):%s get_txidle()=%d\n",
  2513. __FILE__,__LINE__, info->device_name, info->idle_mode);
  2514. COPY_TO_USER(err,idle_mode, &info->idle_mode, sizeof(int));
  2515. if (err) {
  2516. if ( debug_level >= DEBUG_LEVEL_INFO )
  2517. printk( "%s(%d):%s get_txidle() user buffer copy failed\n",
  2518. __FILE__,__LINE__,info->device_name);
  2519. return -EFAULT;
  2520. }
  2521. return 0;
  2522. }
  2523. static int set_txidle(SLMP_INFO * info, int idle_mode)
  2524. {
  2525. unsigned long flags;
  2526. if (debug_level >= DEBUG_LEVEL_INFO)
  2527. printk("%s(%d):%s set_txidle(%d)\n",
  2528. __FILE__,__LINE__,info->device_name, idle_mode );
  2529. spin_lock_irqsave(&info->lock,flags);
  2530. info->idle_mode = idle_mode;
  2531. tx_set_idle( info );
  2532. spin_unlock_irqrestore(&info->lock,flags);
  2533. return 0;
  2534. }
  2535. static int tx_enable(SLMP_INFO * info, int enable)
  2536. {
  2537. unsigned long flags;
  2538. if (debug_level >= DEBUG_LEVEL_INFO)
  2539. printk("%s(%d):%s tx_enable(%d)\n",
  2540. __FILE__,__LINE__,info->device_name, enable);
  2541. spin_lock_irqsave(&info->lock,flags);
  2542. if ( enable ) {
  2543. if ( !info->tx_enabled ) {
  2544. tx_start(info);
  2545. }
  2546. } else {
  2547. if ( info->tx_enabled )
  2548. tx_stop(info);
  2549. }
  2550. spin_unlock_irqrestore(&info->lock,flags);
  2551. return 0;
  2552. }
  2553. /* abort send HDLC frame
  2554. */
  2555. static int tx_abort(SLMP_INFO * info)
  2556. {
  2557. unsigned long flags;
  2558. if (debug_level >= DEBUG_LEVEL_INFO)
  2559. printk("%s(%d):%s tx_abort()\n",
  2560. __FILE__,__LINE__,info->device_name);
  2561. spin_lock_irqsave(&info->lock,flags);
  2562. if ( info->tx_active && info->params.mode == MGSL_MODE_HDLC ) {
  2563. info->ie1_value &= ~UDRN;
  2564. info->ie1_value |= IDLE;
  2565. write_reg(info, IE1, info->ie1_value); /* disable tx status interrupts */
  2566. write_reg(info, SR1, (unsigned char)(IDLE + UDRN)); /* clear pending */
  2567. write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
  2568. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  2569. write_reg(info, CMD, TXABORT);
  2570. }
  2571. spin_unlock_irqrestore(&info->lock,flags);
  2572. return 0;
  2573. }
  2574. static int rx_enable(SLMP_INFO * info, int enable)
  2575. {
  2576. unsigned long flags;
  2577. if (debug_level >= DEBUG_LEVEL_INFO)
  2578. printk("%s(%d):%s rx_enable(%d)\n",
  2579. __FILE__,__LINE__,info->device_name,enable);
  2580. spin_lock_irqsave(&info->lock,flags);
  2581. if ( enable ) {
  2582. if ( !info->rx_enabled )
  2583. rx_start(info);
  2584. } else {
  2585. if ( info->rx_enabled )
  2586. rx_stop(info);
  2587. }
  2588. spin_unlock_irqrestore(&info->lock,flags);
  2589. return 0;
  2590. }
  2591. /* wait for specified event to occur
  2592. */
  2593. static int wait_mgsl_event(SLMP_INFO * info, int __user *mask_ptr)
  2594. {
  2595. unsigned long flags;
  2596. int s;
  2597. int rc=0;
  2598. struct mgsl_icount cprev, cnow;
  2599. int events;
  2600. int mask;
  2601. struct _input_signal_events oldsigs, newsigs;
  2602. DECLARE_WAITQUEUE(wait, current);
  2603. COPY_FROM_USER(rc,&mask, mask_ptr, sizeof(int));
  2604. if (rc) {
  2605. return -EFAULT;
  2606. }
  2607. if (debug_level >= DEBUG_LEVEL_INFO)
  2608. printk("%s(%d):%s wait_mgsl_event(%d)\n",
  2609. __FILE__,__LINE__,info->device_name,mask);
  2610. spin_lock_irqsave(&info->lock,flags);
  2611. /* return immediately if state matches requested events */
  2612. get_signals(info);
  2613. s = info->serial_signals;
  2614. events = mask &
  2615. ( ((s & SerialSignal_DSR) ? MgslEvent_DsrActive:MgslEvent_DsrInactive) +
  2616. ((s & SerialSignal_DCD) ? MgslEvent_DcdActive:MgslEvent_DcdInactive) +
  2617. ((s & SerialSignal_CTS) ? MgslEvent_CtsActive:MgslEvent_CtsInactive) +
  2618. ((s & SerialSignal_RI) ? MgslEvent_RiActive :MgslEvent_RiInactive) );
  2619. if (events) {
  2620. spin_unlock_irqrestore(&info->lock,flags);
  2621. goto exit;
  2622. }
  2623. /* save current irq counts */
  2624. cprev = info->icount;
  2625. oldsigs = info->input_signal_events;
  2626. /* enable hunt and idle irqs if needed */
  2627. if (mask & (MgslEvent_ExitHuntMode+MgslEvent_IdleReceived)) {
  2628. unsigned char oldval = info->ie1_value;
  2629. unsigned char newval = oldval +
  2630. (mask & MgslEvent_ExitHuntMode ? FLGD:0) +
  2631. (mask & MgslEvent_IdleReceived ? IDLD:0);
  2632. if ( oldval != newval ) {
  2633. info->ie1_value = newval;
  2634. write_reg(info, IE1, info->ie1_value);
  2635. }
  2636. }
  2637. set_current_state(TASK_INTERRUPTIBLE);
  2638. add_wait_queue(&info->event_wait_q, &wait);
  2639. spin_unlock_irqrestore(&info->lock,flags);
  2640. for(;;) {
  2641. schedule();
  2642. if (signal_pending(current)) {
  2643. rc = -ERESTARTSYS;
  2644. break;
  2645. }
  2646. /* get current irq counts */
  2647. spin_lock_irqsave(&info->lock,flags);
  2648. cnow = info->icount;
  2649. newsigs = info->input_signal_events;
  2650. set_current_state(TASK_INTERRUPTIBLE);
  2651. spin_unlock_irqrestore(&info->lock,flags);
  2652. /* if no change, wait aborted for some reason */
  2653. if (newsigs.dsr_up == oldsigs.dsr_up &&
  2654. newsigs.dsr_down == oldsigs.dsr_down &&
  2655. newsigs.dcd_up == oldsigs.dcd_up &&
  2656. newsigs.dcd_down == oldsigs.dcd_down &&
  2657. newsigs.cts_up == oldsigs.cts_up &&
  2658. newsigs.cts_down == oldsigs.cts_down &&
  2659. newsigs.ri_up == oldsigs.ri_up &&
  2660. newsigs.ri_down == oldsigs.ri_down &&
  2661. cnow.exithunt == cprev.exithunt &&
  2662. cnow.rxidle == cprev.rxidle) {
  2663. rc = -EIO;
  2664. break;
  2665. }
  2666. events = mask &
  2667. ( (newsigs.dsr_up != oldsigs.dsr_up ? MgslEvent_DsrActive:0) +
  2668. (newsigs.dsr_down != oldsigs.dsr_down ? MgslEvent_DsrInactive:0) +
  2669. (newsigs.dcd_up != oldsigs.dcd_up ? MgslEvent_DcdActive:0) +
  2670. (newsigs.dcd_down != oldsigs.dcd_down ? MgslEvent_DcdInactive:0) +
  2671. (newsigs.cts_up != oldsigs.cts_up ? MgslEvent_CtsActive:0) +
  2672. (newsigs.cts_down != oldsigs.cts_down ? MgslEvent_CtsInactive:0) +
  2673. (newsigs.ri_up != oldsigs.ri_up ? MgslEvent_RiActive:0) +
  2674. (newsigs.ri_down != oldsigs.ri_down ? MgslEvent_RiInactive:0) +
  2675. (cnow.exithunt != cprev.exithunt ? MgslEvent_ExitHuntMode:0) +
  2676. (cnow.rxidle != cprev.rxidle ? MgslEvent_IdleReceived:0) );
  2677. if (events)
  2678. break;
  2679. cprev = cnow;
  2680. oldsigs = newsigs;
  2681. }
  2682. remove_wait_queue(&info->event_wait_q, &wait);
  2683. set_current_state(TASK_RUNNING);
  2684. if (mask & (MgslEvent_ExitHuntMode + MgslEvent_IdleReceived)) {
  2685. spin_lock_irqsave(&info->lock,flags);
  2686. if (!waitqueue_active(&info->event_wait_q)) {
  2687. /* disable enable exit hunt mode/idle rcvd IRQs */
  2688. info->ie1_value &= ~(FLGD|IDLD);
  2689. write_reg(info, IE1, info->ie1_value);
  2690. }
  2691. spin_unlock_irqrestore(&info->lock,flags);
  2692. }
  2693. exit:
  2694. if ( rc == 0 )
  2695. PUT_USER(rc, events, mask_ptr);
  2696. return rc;
  2697. }
  2698. static int modem_input_wait(SLMP_INFO *info,int arg)
  2699. {
  2700. unsigned long flags;
  2701. int rc;
  2702. struct mgsl_icount cprev, cnow;
  2703. DECLARE_WAITQUEUE(wait, current);
  2704. /* save current irq counts */
  2705. spin_lock_irqsave(&info->lock,flags);
  2706. cprev = info->icount;
  2707. add_wait_queue(&info->status_event_wait_q, &wait);
  2708. set_current_state(TASK_INTERRUPTIBLE);
  2709. spin_unlock_irqrestore(&info->lock,flags);
  2710. for(;;) {
  2711. schedule();
  2712. if (signal_pending(current)) {
  2713. rc = -ERESTARTSYS;
  2714. break;
  2715. }
  2716. /* get new irq counts */
  2717. spin_lock_irqsave(&info->lock,flags);
  2718. cnow = info->icount;
  2719. set_current_state(TASK_INTERRUPTIBLE);
  2720. spin_unlock_irqrestore(&info->lock,flags);
  2721. /* if no change, wait aborted for some reason */
  2722. if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
  2723. cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
  2724. rc = -EIO;
  2725. break;
  2726. }
  2727. /* check for change in caller specified modem input */
  2728. if ((arg & TIOCM_RNG && cnow.rng != cprev.rng) ||
  2729. (arg & TIOCM_DSR && cnow.dsr != cprev.dsr) ||
  2730. (arg & TIOCM_CD && cnow.dcd != cprev.dcd) ||
  2731. (arg & TIOCM_CTS && cnow.cts != cprev.cts)) {
  2732. rc = 0;
  2733. break;
  2734. }
  2735. cprev = cnow;
  2736. }
  2737. remove_wait_queue(&info->status_event_wait_q, &wait);
  2738. set_current_state(TASK_RUNNING);
  2739. return rc;
  2740. }
  2741. /* return the state of the serial control and status signals
  2742. */
  2743. static int tiocmget(struct tty_struct *tty, struct file *file)
  2744. {
  2745. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  2746. unsigned int result;
  2747. unsigned long flags;
  2748. spin_lock_irqsave(&info->lock,flags);
  2749. get_signals(info);
  2750. spin_unlock_irqrestore(&info->lock,flags);
  2751. result = ((info->serial_signals & SerialSignal_RTS) ? TIOCM_RTS:0) +
  2752. ((info->serial_signals & SerialSignal_DTR) ? TIOCM_DTR:0) +
  2753. ((info->serial_signals & SerialSignal_DCD) ? TIOCM_CAR:0) +
  2754. ((info->serial_signals & SerialSignal_RI) ? TIOCM_RNG:0) +
  2755. ((info->serial_signals & SerialSignal_DSR) ? TIOCM_DSR:0) +
  2756. ((info->serial_signals & SerialSignal_CTS) ? TIOCM_CTS:0);
  2757. if (debug_level >= DEBUG_LEVEL_INFO)
  2758. printk("%s(%d):%s tiocmget() value=%08X\n",
  2759. __FILE__,__LINE__, info->device_name, result );
  2760. return result;
  2761. }
  2762. /* set modem control signals (DTR/RTS)
  2763. */
  2764. static int tiocmset(struct tty_struct *tty, struct file *file,
  2765. unsigned int set, unsigned int clear)
  2766. {
  2767. SLMP_INFO *info = (SLMP_INFO *)tty->driver_data;
  2768. unsigned long flags;
  2769. if (debug_level >= DEBUG_LEVEL_INFO)
  2770. printk("%s(%d):%s tiocmset(%x,%x)\n",
  2771. __FILE__,__LINE__,info->device_name, set, clear);
  2772. if (set & TIOCM_RTS)
  2773. info->serial_signals |= SerialSignal_RTS;
  2774. if (set & TIOCM_DTR)
  2775. info->serial_signals |= SerialSignal_DTR;
  2776. if (clear & TIOCM_RTS)
  2777. info->serial_signals &= ~SerialSignal_RTS;
  2778. if (clear & TIOCM_DTR)
  2779. info->serial_signals &= ~SerialSignal_DTR;
  2780. spin_lock_irqsave(&info->lock,flags);
  2781. set_signals(info);
  2782. spin_unlock_irqrestore(&info->lock,flags);
  2783. return 0;
  2784. }
  2785. /* Block the current process until the specified port is ready to open.
  2786. */
  2787. static int block_til_ready(struct tty_struct *tty, struct file *filp,
  2788. SLMP_INFO *info)
  2789. {
  2790. DECLARE_WAITQUEUE(wait, current);
  2791. int retval;
  2792. int do_clocal = 0, extra_count = 0;
  2793. unsigned long flags;
  2794. if (debug_level >= DEBUG_LEVEL_INFO)
  2795. printk("%s(%d):%s block_til_ready()\n",
  2796. __FILE__,__LINE__, tty->driver->name );
  2797. if (filp->f_flags & O_NONBLOCK || tty->flags & (1 << TTY_IO_ERROR)){
  2798. /* nonblock mode is set or port is not enabled */
  2799. /* just verify that callout device is not active */
  2800. info->flags |= ASYNC_NORMAL_ACTIVE;
  2801. return 0;
  2802. }
  2803. if (tty->termios->c_cflag & CLOCAL)
  2804. do_clocal = 1;
  2805. /* Wait for carrier detect and the line to become
  2806. * free (i.e., not in use by the callout). While we are in
  2807. * this loop, info->count is dropped by one, so that
  2808. * close() knows when to free things. We restore it upon
  2809. * exit, either normal or abnormal.
  2810. */
  2811. retval = 0;
  2812. add_wait_queue(&info->open_wait, &wait);
  2813. if (debug_level >= DEBUG_LEVEL_INFO)
  2814. printk("%s(%d):%s block_til_ready() before block, count=%d\n",
  2815. __FILE__,__LINE__, tty->driver->name, info->count );
  2816. spin_lock_irqsave(&info->lock, flags);
  2817. if (!tty_hung_up_p(filp)) {
  2818. extra_count = 1;
  2819. info->count--;
  2820. }
  2821. spin_unlock_irqrestore(&info->lock, flags);
  2822. info->blocked_open++;
  2823. while (1) {
  2824. if ((tty->termios->c_cflag & CBAUD)) {
  2825. spin_lock_irqsave(&info->lock,flags);
  2826. info->serial_signals |= SerialSignal_RTS + SerialSignal_DTR;
  2827. set_signals(info);
  2828. spin_unlock_irqrestore(&info->lock,flags);
  2829. }
  2830. set_current_state(TASK_INTERRUPTIBLE);
  2831. if (tty_hung_up_p(filp) || !(info->flags & ASYNC_INITIALIZED)){
  2832. retval = (info->flags & ASYNC_HUP_NOTIFY) ?
  2833. -EAGAIN : -ERESTARTSYS;
  2834. break;
  2835. }
  2836. spin_lock_irqsave(&info->lock,flags);
  2837. get_signals(info);
  2838. spin_unlock_irqrestore(&info->lock,flags);
  2839. if (!(info->flags & ASYNC_CLOSING) &&
  2840. (do_clocal || (info->serial_signals & SerialSignal_DCD)) ) {
  2841. break;
  2842. }
  2843. if (signal_pending(current)) {
  2844. retval = -ERESTARTSYS;
  2845. break;
  2846. }
  2847. if (debug_level >= DEBUG_LEVEL_INFO)
  2848. printk("%s(%d):%s block_til_ready() count=%d\n",
  2849. __FILE__,__LINE__, tty->driver->name, info->count );
  2850. schedule();
  2851. }
  2852. set_current_state(TASK_RUNNING);
  2853. remove_wait_queue(&info->open_wait, &wait);
  2854. if (extra_count)
  2855. info->count++;
  2856. info->blocked_open--;
  2857. if (debug_level >= DEBUG_LEVEL_INFO)
  2858. printk("%s(%d):%s block_til_ready() after, count=%d\n",
  2859. __FILE__,__LINE__, tty->driver->name, info->count );
  2860. if (!retval)
  2861. info->flags |= ASYNC_NORMAL_ACTIVE;
  2862. return retval;
  2863. }
  2864. int alloc_dma_bufs(SLMP_INFO *info)
  2865. {
  2866. unsigned short BuffersPerFrame;
  2867. unsigned short BufferCount;
  2868. // Force allocation to start at 64K boundary for each port.
  2869. // This is necessary because *all* buffer descriptors for a port
  2870. // *must* be in the same 64K block. All descriptors on a port
  2871. // share a common 'base' address (upper 8 bits of 24 bits) programmed
  2872. // into the CBP register.
  2873. info->port_array[0]->last_mem_alloc = (SCA_MEM_SIZE/4) * info->port_num;
  2874. /* Calculate the number of DMA buffers necessary to hold the */
  2875. /* largest allowable frame size. Note: If the max frame size is */
  2876. /* not an even multiple of the DMA buffer size then we need to */
  2877. /* round the buffer count per frame up one. */
  2878. BuffersPerFrame = (unsigned short)(info->max_frame_size/SCABUFSIZE);
  2879. if ( info->max_frame_size % SCABUFSIZE )
  2880. BuffersPerFrame++;
  2881. /* calculate total number of data buffers (SCABUFSIZE) possible
  2882. * in one ports memory (SCA_MEM_SIZE/4) after allocating memory
  2883. * for the descriptor list (BUFFERLISTSIZE).
  2884. */
  2885. BufferCount = (SCA_MEM_SIZE/4 - BUFFERLISTSIZE)/SCABUFSIZE;
  2886. /* limit number of buffers to maximum amount of descriptors */
  2887. if (BufferCount > BUFFERLISTSIZE/sizeof(SCADESC))
  2888. BufferCount = BUFFERLISTSIZE/sizeof(SCADESC);
  2889. /* use enough buffers to transmit one max size frame */
  2890. info->tx_buf_count = BuffersPerFrame + 1;
  2891. /* never use more than half the available buffers for transmit */
  2892. if (info->tx_buf_count > (BufferCount/2))
  2893. info->tx_buf_count = BufferCount/2;
  2894. if (info->tx_buf_count > SCAMAXDESC)
  2895. info->tx_buf_count = SCAMAXDESC;
  2896. /* use remaining buffers for receive */
  2897. info->rx_buf_count = BufferCount - info->tx_buf_count;
  2898. if (info->rx_buf_count > SCAMAXDESC)
  2899. info->rx_buf_count = SCAMAXDESC;
  2900. if ( debug_level >= DEBUG_LEVEL_INFO )
  2901. printk("%s(%d):%s Allocating %d TX and %d RX DMA buffers.\n",
  2902. __FILE__,__LINE__, info->device_name,
  2903. info->tx_buf_count,info->rx_buf_count);
  2904. if ( alloc_buf_list( info ) < 0 ||
  2905. alloc_frame_bufs(info,
  2906. info->rx_buf_list,
  2907. info->rx_buf_list_ex,
  2908. info->rx_buf_count) < 0 ||
  2909. alloc_frame_bufs(info,
  2910. info->tx_buf_list,
  2911. info->tx_buf_list_ex,
  2912. info->tx_buf_count) < 0 ||
  2913. alloc_tmp_rx_buf(info) < 0 ) {
  2914. printk("%s(%d):%s Can't allocate DMA buffer memory\n",
  2915. __FILE__,__LINE__, info->device_name);
  2916. return -ENOMEM;
  2917. }
  2918. rx_reset_buffers( info );
  2919. return 0;
  2920. }
  2921. /* Allocate DMA buffers for the transmit and receive descriptor lists.
  2922. */
  2923. int alloc_buf_list(SLMP_INFO *info)
  2924. {
  2925. unsigned int i;
  2926. /* build list in adapter shared memory */
  2927. info->buffer_list = info->memory_base + info->port_array[0]->last_mem_alloc;
  2928. info->buffer_list_phys = info->port_array[0]->last_mem_alloc;
  2929. info->port_array[0]->last_mem_alloc += BUFFERLISTSIZE;
  2930. memset(info->buffer_list, 0, BUFFERLISTSIZE);
  2931. /* Save virtual address pointers to the receive and */
  2932. /* transmit buffer lists. (Receive 1st). These pointers will */
  2933. /* be used by the processor to access the lists. */
  2934. info->rx_buf_list = (SCADESC *)info->buffer_list;
  2935. info->tx_buf_list = (SCADESC *)info->buffer_list;
  2936. info->tx_buf_list += info->rx_buf_count;
  2937. /* Build links for circular buffer entry lists (tx and rx)
  2938. *
  2939. * Note: links are physical addresses read by the SCA device
  2940. * to determine the next buffer entry to use.
  2941. */
  2942. for ( i = 0; i < info->rx_buf_count; i++ ) {
  2943. /* calculate and store physical address of this buffer entry */
  2944. info->rx_buf_list_ex[i].phys_entry =
  2945. info->buffer_list_phys + (i * sizeof(SCABUFSIZE));
  2946. /* calculate and store physical address of */
  2947. /* next entry in cirular list of entries */
  2948. info->rx_buf_list[i].next = info->buffer_list_phys;
  2949. if ( i < info->rx_buf_count - 1 )
  2950. info->rx_buf_list[i].next += (i + 1) * sizeof(SCADESC);
  2951. info->rx_buf_list[i].length = SCABUFSIZE;
  2952. }
  2953. for ( i = 0; i < info->tx_buf_count; i++ ) {
  2954. /* calculate and store physical address of this buffer entry */
  2955. info->tx_buf_list_ex[i].phys_entry = info->buffer_list_phys +
  2956. ((info->rx_buf_count + i) * sizeof(SCADESC));
  2957. /* calculate and store physical address of */
  2958. /* next entry in cirular list of entries */
  2959. info->tx_buf_list[i].next = info->buffer_list_phys +
  2960. info->rx_buf_count * sizeof(SCADESC);
  2961. if ( i < info->tx_buf_count - 1 )
  2962. info->tx_buf_list[i].next += (i + 1) * sizeof(SCADESC);
  2963. }
  2964. return 0;
  2965. }
  2966. /* Allocate the frame DMA buffers used by the specified buffer list.
  2967. */
  2968. int alloc_frame_bufs(SLMP_INFO *info, SCADESC *buf_list,SCADESC_EX *buf_list_ex,int count)
  2969. {
  2970. int i;
  2971. unsigned long phys_addr;
  2972. for ( i = 0; i < count; i++ ) {
  2973. buf_list_ex[i].virt_addr = info->memory_base + info->port_array[0]->last_mem_alloc;
  2974. phys_addr = info->port_array[0]->last_mem_alloc;
  2975. info->port_array[0]->last_mem_alloc += SCABUFSIZE;
  2976. buf_list[i].buf_ptr = (unsigned short)phys_addr;
  2977. buf_list[i].buf_base = (unsigned char)(phys_addr >> 16);
  2978. }
  2979. return 0;
  2980. }
  2981. void free_dma_bufs(SLMP_INFO *info)
  2982. {
  2983. info->buffer_list = NULL;
  2984. info->rx_buf_list = NULL;
  2985. info->tx_buf_list = NULL;
  2986. }
  2987. /* allocate buffer large enough to hold max_frame_size.
  2988. * This buffer is used to pass an assembled frame to the line discipline.
  2989. */
  2990. int alloc_tmp_rx_buf(SLMP_INFO *info)
  2991. {
  2992. info->tmp_rx_buf = kmalloc(info->max_frame_size, GFP_KERNEL);
  2993. if (info->tmp_rx_buf == NULL)
  2994. return -ENOMEM;
  2995. return 0;
  2996. }
  2997. void free_tmp_rx_buf(SLMP_INFO *info)
  2998. {
  2999. if (info->tmp_rx_buf)
  3000. kfree(info->tmp_rx_buf);
  3001. info->tmp_rx_buf = NULL;
  3002. }
  3003. int claim_resources(SLMP_INFO *info)
  3004. {
  3005. if (request_mem_region(info->phys_memory_base,SCA_MEM_SIZE,"synclinkmp") == NULL) {
  3006. printk( "%s(%d):%s mem addr conflict, Addr=%08X\n",
  3007. __FILE__,__LINE__,info->device_name, info->phys_memory_base);
  3008. info->init_error = DiagStatus_AddressConflict;
  3009. goto errout;
  3010. }
  3011. else
  3012. info->shared_mem_requested = 1;
  3013. if (request_mem_region(info->phys_lcr_base + info->lcr_offset,128,"synclinkmp") == NULL) {
  3014. printk( "%s(%d):%s lcr mem addr conflict, Addr=%08X\n",
  3015. __FILE__,__LINE__,info->device_name, info->phys_lcr_base);
  3016. info->init_error = DiagStatus_AddressConflict;
  3017. goto errout;
  3018. }
  3019. else
  3020. info->lcr_mem_requested = 1;
  3021. if (request_mem_region(info->phys_sca_base + info->sca_offset,SCA_BASE_SIZE,"synclinkmp") == NULL) {
  3022. printk( "%s(%d):%s sca mem addr conflict, Addr=%08X\n",
  3023. __FILE__,__LINE__,info->device_name, info->phys_sca_base);
  3024. info->init_error = DiagStatus_AddressConflict;
  3025. goto errout;
  3026. }
  3027. else
  3028. info->sca_base_requested = 1;
  3029. if (request_mem_region(info->phys_statctrl_base + info->statctrl_offset,SCA_REG_SIZE,"synclinkmp") == NULL) {
  3030. printk( "%s(%d):%s stat/ctrl mem addr conflict, Addr=%08X\n",
  3031. __FILE__,__LINE__,info->device_name, info->phys_statctrl_base);
  3032. info->init_error = DiagStatus_AddressConflict;
  3033. goto errout;
  3034. }
  3035. else
  3036. info->sca_statctrl_requested = 1;
  3037. info->memory_base = ioremap(info->phys_memory_base,SCA_MEM_SIZE);
  3038. if (!info->memory_base) {
  3039. printk( "%s(%d):%s Cant map shared memory, MemAddr=%08X\n",
  3040. __FILE__,__LINE__,info->device_name, info->phys_memory_base );
  3041. info->init_error = DiagStatus_CantAssignPciResources;
  3042. goto errout;
  3043. }
  3044. info->lcr_base = ioremap(info->phys_lcr_base,PAGE_SIZE);
  3045. if (!info->lcr_base) {
  3046. printk( "%s(%d):%s Cant map LCR memory, MemAddr=%08X\n",
  3047. __FILE__,__LINE__,info->device_name, info->phys_lcr_base );
  3048. info->init_error = DiagStatus_CantAssignPciResources;
  3049. goto errout;
  3050. }
  3051. info->lcr_base += info->lcr_offset;
  3052. info->sca_base = ioremap(info->phys_sca_base,PAGE_SIZE);
  3053. if (!info->sca_base) {
  3054. printk( "%s(%d):%s Cant map SCA memory, MemAddr=%08X\n",
  3055. __FILE__,__LINE__,info->device_name, info->phys_sca_base );
  3056. info->init_error = DiagStatus_CantAssignPciResources;
  3057. goto errout;
  3058. }
  3059. info->sca_base += info->sca_offset;
  3060. info->statctrl_base = ioremap(info->phys_statctrl_base,PAGE_SIZE);
  3061. if (!info->statctrl_base) {
  3062. printk( "%s(%d):%s Cant map SCA Status/Control memory, MemAddr=%08X\n",
  3063. __FILE__,__LINE__,info->device_name, info->phys_statctrl_base );
  3064. info->init_error = DiagStatus_CantAssignPciResources;
  3065. goto errout;
  3066. }
  3067. info->statctrl_base += info->statctrl_offset;
  3068. if ( !memory_test(info) ) {
  3069. printk( "%s(%d):Shared Memory Test failed for device %s MemAddr=%08X\n",
  3070. __FILE__,__LINE__,info->device_name, info->phys_memory_base );
  3071. info->init_error = DiagStatus_MemoryError;
  3072. goto errout;
  3073. }
  3074. return 0;
  3075. errout:
  3076. release_resources( info );
  3077. return -ENODEV;
  3078. }
  3079. void release_resources(SLMP_INFO *info)
  3080. {
  3081. if ( debug_level >= DEBUG_LEVEL_INFO )
  3082. printk( "%s(%d):%s release_resources() entry\n",
  3083. __FILE__,__LINE__,info->device_name );
  3084. if ( info->irq_requested ) {
  3085. free_irq(info->irq_level, info);
  3086. info->irq_requested = 0;
  3087. }
  3088. if ( info->shared_mem_requested ) {
  3089. release_mem_region(info->phys_memory_base,SCA_MEM_SIZE);
  3090. info->shared_mem_requested = 0;
  3091. }
  3092. if ( info->lcr_mem_requested ) {
  3093. release_mem_region(info->phys_lcr_base + info->lcr_offset,128);
  3094. info->lcr_mem_requested = 0;
  3095. }
  3096. if ( info->sca_base_requested ) {
  3097. release_mem_region(info->phys_sca_base + info->sca_offset,SCA_BASE_SIZE);
  3098. info->sca_base_requested = 0;
  3099. }
  3100. if ( info->sca_statctrl_requested ) {
  3101. release_mem_region(info->phys_statctrl_base + info->statctrl_offset,SCA_REG_SIZE);
  3102. info->sca_statctrl_requested = 0;
  3103. }
  3104. if (info->memory_base){
  3105. iounmap(info->memory_base);
  3106. info->memory_base = NULL;
  3107. }
  3108. if (info->sca_base) {
  3109. iounmap(info->sca_base - info->sca_offset);
  3110. info->sca_base=NULL;
  3111. }
  3112. if (info->statctrl_base) {
  3113. iounmap(info->statctrl_base - info->statctrl_offset);
  3114. info->statctrl_base=NULL;
  3115. }
  3116. if (info->lcr_base){
  3117. iounmap(info->lcr_base - info->lcr_offset);
  3118. info->lcr_base = NULL;
  3119. }
  3120. if ( debug_level >= DEBUG_LEVEL_INFO )
  3121. printk( "%s(%d):%s release_resources() exit\n",
  3122. __FILE__,__LINE__,info->device_name );
  3123. }
  3124. /* Add the specified device instance data structure to the
  3125. * global linked list of devices and increment the device count.
  3126. */
  3127. void add_device(SLMP_INFO *info)
  3128. {
  3129. info->next_device = NULL;
  3130. info->line = synclinkmp_device_count;
  3131. sprintf(info->device_name,"ttySLM%dp%d",info->adapter_num,info->port_num);
  3132. if (info->line < MAX_DEVICES) {
  3133. if (maxframe[info->line])
  3134. info->max_frame_size = maxframe[info->line];
  3135. info->dosyncppp = dosyncppp[info->line];
  3136. }
  3137. synclinkmp_device_count++;
  3138. if ( !synclinkmp_device_list )
  3139. synclinkmp_device_list = info;
  3140. else {
  3141. SLMP_INFO *current_dev = synclinkmp_device_list;
  3142. while( current_dev->next_device )
  3143. current_dev = current_dev->next_device;
  3144. current_dev->next_device = info;
  3145. }
  3146. if ( info->max_frame_size < 4096 )
  3147. info->max_frame_size = 4096;
  3148. else if ( info->max_frame_size > 65535 )
  3149. info->max_frame_size = 65535;
  3150. printk( "SyncLink MultiPort %s: "
  3151. "Mem=(%08x %08X %08x %08X) IRQ=%d MaxFrameSize=%u\n",
  3152. info->device_name,
  3153. info->phys_sca_base,
  3154. info->phys_memory_base,
  3155. info->phys_statctrl_base,
  3156. info->phys_lcr_base,
  3157. info->irq_level,
  3158. info->max_frame_size );
  3159. #ifdef CONFIG_HDLC
  3160. hdlcdev_init(info);
  3161. #endif
  3162. }
  3163. /* Allocate and initialize a device instance structure
  3164. *
  3165. * Return Value: pointer to SLMP_INFO if success, otherwise NULL
  3166. */
  3167. static SLMP_INFO *alloc_dev(int adapter_num, int port_num, struct pci_dev *pdev)
  3168. {
  3169. SLMP_INFO *info;
  3170. info = (SLMP_INFO *)kmalloc(sizeof(SLMP_INFO),
  3171. GFP_KERNEL);
  3172. if (!info) {
  3173. printk("%s(%d) Error can't allocate device instance data for adapter %d, port %d\n",
  3174. __FILE__,__LINE__, adapter_num, port_num);
  3175. } else {
  3176. memset(info, 0, sizeof(SLMP_INFO));
  3177. info->magic = MGSL_MAGIC;
  3178. INIT_WORK(&info->task, bh_handler, info);
  3179. info->max_frame_size = 4096;
  3180. info->close_delay = 5*HZ/10;
  3181. info->closing_wait = 30*HZ;
  3182. init_waitqueue_head(&info->open_wait);
  3183. init_waitqueue_head(&info->close_wait);
  3184. init_waitqueue_head(&info->status_event_wait_q);
  3185. init_waitqueue_head(&info->event_wait_q);
  3186. spin_lock_init(&info->netlock);
  3187. memcpy(&info->params,&default_params,sizeof(MGSL_PARAMS));
  3188. info->idle_mode = HDLC_TXIDLE_FLAGS;
  3189. info->adapter_num = adapter_num;
  3190. info->port_num = port_num;
  3191. /* Copy configuration info to device instance data */
  3192. info->irq_level = pdev->irq;
  3193. info->phys_lcr_base = pci_resource_start(pdev,0);
  3194. info->phys_sca_base = pci_resource_start(pdev,2);
  3195. info->phys_memory_base = pci_resource_start(pdev,3);
  3196. info->phys_statctrl_base = pci_resource_start(pdev,4);
  3197. /* Because veremap only works on page boundaries we must map
  3198. * a larger area than is actually implemented for the LCR
  3199. * memory range. We map a full page starting at the page boundary.
  3200. */
  3201. info->lcr_offset = info->phys_lcr_base & (PAGE_SIZE-1);
  3202. info->phys_lcr_base &= ~(PAGE_SIZE-1);
  3203. info->sca_offset = info->phys_sca_base & (PAGE_SIZE-1);
  3204. info->phys_sca_base &= ~(PAGE_SIZE-1);
  3205. info->statctrl_offset = info->phys_statctrl_base & (PAGE_SIZE-1);
  3206. info->phys_statctrl_base &= ~(PAGE_SIZE-1);
  3207. info->bus_type = MGSL_BUS_TYPE_PCI;
  3208. info->irq_flags = SA_SHIRQ;
  3209. init_timer(&info->tx_timer);
  3210. info->tx_timer.data = (unsigned long)info;
  3211. info->tx_timer.function = tx_timeout;
  3212. init_timer(&info->status_timer);
  3213. info->status_timer.data = (unsigned long)info;
  3214. info->status_timer.function = status_timeout;
  3215. /* Store the PCI9050 misc control register value because a flaw
  3216. * in the PCI9050 prevents LCR registers from being read if
  3217. * BIOS assigns an LCR base address with bit 7 set.
  3218. *
  3219. * Only the misc control register is accessed for which only
  3220. * write access is needed, so set an initial value and change
  3221. * bits to the device instance data as we write the value
  3222. * to the actual misc control register.
  3223. */
  3224. info->misc_ctrl_value = 0x087e4546;
  3225. /* initial port state is unknown - if startup errors
  3226. * occur, init_error will be set to indicate the
  3227. * problem. Once the port is fully initialized,
  3228. * this value will be set to 0 to indicate the
  3229. * port is available.
  3230. */
  3231. info->init_error = -1;
  3232. }
  3233. return info;
  3234. }
  3235. void device_init(int adapter_num, struct pci_dev *pdev)
  3236. {
  3237. SLMP_INFO *port_array[SCA_MAX_PORTS];
  3238. int port;
  3239. /* allocate device instances for up to SCA_MAX_PORTS devices */
  3240. for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
  3241. port_array[port] = alloc_dev(adapter_num,port,pdev);
  3242. if( port_array[port] == NULL ) {
  3243. for ( --port; port >= 0; --port )
  3244. kfree(port_array[port]);
  3245. return;
  3246. }
  3247. }
  3248. /* give copy of port_array to all ports and add to device list */
  3249. for ( port = 0; port < SCA_MAX_PORTS; ++port ) {
  3250. memcpy(port_array[port]->port_array,port_array,sizeof(port_array));
  3251. add_device( port_array[port] );
  3252. spin_lock_init(&port_array[port]->lock);
  3253. }
  3254. /* Allocate and claim adapter resources */
  3255. if ( !claim_resources(port_array[0]) ) {
  3256. alloc_dma_bufs(port_array[0]);
  3257. /* copy resource information from first port to others */
  3258. for ( port = 1; port < SCA_MAX_PORTS; ++port ) {
  3259. port_array[port]->lock = port_array[0]->lock;
  3260. port_array[port]->irq_level = port_array[0]->irq_level;
  3261. port_array[port]->memory_base = port_array[0]->memory_base;
  3262. port_array[port]->sca_base = port_array[0]->sca_base;
  3263. port_array[port]->statctrl_base = port_array[0]->statctrl_base;
  3264. port_array[port]->lcr_base = port_array[0]->lcr_base;
  3265. alloc_dma_bufs(port_array[port]);
  3266. }
  3267. if ( request_irq(port_array[0]->irq_level,
  3268. synclinkmp_interrupt,
  3269. port_array[0]->irq_flags,
  3270. port_array[0]->device_name,
  3271. port_array[0]) < 0 ) {
  3272. printk( "%s(%d):%s Cant request interrupt, IRQ=%d\n",
  3273. __FILE__,__LINE__,
  3274. port_array[0]->device_name,
  3275. port_array[0]->irq_level );
  3276. }
  3277. else {
  3278. port_array[0]->irq_requested = 1;
  3279. adapter_test(port_array[0]);
  3280. }
  3281. }
  3282. }
  3283. static struct tty_operations ops = {
  3284. .open = open,
  3285. .close = close,
  3286. .write = write,
  3287. .put_char = put_char,
  3288. .flush_chars = flush_chars,
  3289. .write_room = write_room,
  3290. .chars_in_buffer = chars_in_buffer,
  3291. .flush_buffer = flush_buffer,
  3292. .ioctl = ioctl,
  3293. .throttle = throttle,
  3294. .unthrottle = unthrottle,
  3295. .send_xchar = send_xchar,
  3296. .break_ctl = set_break,
  3297. .wait_until_sent = wait_until_sent,
  3298. .read_proc = read_proc,
  3299. .set_termios = set_termios,
  3300. .stop = tx_hold,
  3301. .start = tx_release,
  3302. .hangup = hangup,
  3303. .tiocmget = tiocmget,
  3304. .tiocmset = tiocmset,
  3305. };
  3306. static void synclinkmp_cleanup(void)
  3307. {
  3308. int rc;
  3309. SLMP_INFO *info;
  3310. SLMP_INFO *tmp;
  3311. printk("Unloading %s %s\n", driver_name, driver_version);
  3312. if (serial_driver) {
  3313. if ((rc = tty_unregister_driver(serial_driver)))
  3314. printk("%s(%d) failed to unregister tty driver err=%d\n",
  3315. __FILE__,__LINE__,rc);
  3316. put_tty_driver(serial_driver);
  3317. }
  3318. /* reset devices */
  3319. info = synclinkmp_device_list;
  3320. while(info) {
  3321. reset_port(info);
  3322. info = info->next_device;
  3323. }
  3324. /* release devices */
  3325. info = synclinkmp_device_list;
  3326. while(info) {
  3327. #ifdef CONFIG_HDLC
  3328. hdlcdev_exit(info);
  3329. #endif
  3330. free_dma_bufs(info);
  3331. free_tmp_rx_buf(info);
  3332. if ( info->port_num == 0 ) {
  3333. if (info->sca_base)
  3334. write_reg(info, LPR, 1); /* set low power mode */
  3335. release_resources(info);
  3336. }
  3337. tmp = info;
  3338. info = info->next_device;
  3339. kfree(tmp);
  3340. }
  3341. pci_unregister_driver(&synclinkmp_pci_driver);
  3342. }
  3343. /* Driver initialization entry point.
  3344. */
  3345. static int __init synclinkmp_init(void)
  3346. {
  3347. int rc;
  3348. if (break_on_load) {
  3349. synclinkmp_get_text_ptr();
  3350. BREAKPOINT();
  3351. }
  3352. printk("%s %s\n", driver_name, driver_version);
  3353. if ((rc = pci_register_driver(&synclinkmp_pci_driver)) < 0) {
  3354. printk("%s:failed to register PCI driver, error=%d\n",__FILE__,rc);
  3355. return rc;
  3356. }
  3357. serial_driver = alloc_tty_driver(128);
  3358. if (!serial_driver) {
  3359. rc = -ENOMEM;
  3360. goto error;
  3361. }
  3362. /* Initialize the tty_driver structure */
  3363. serial_driver->owner = THIS_MODULE;
  3364. serial_driver->driver_name = "synclinkmp";
  3365. serial_driver->name = "ttySLM";
  3366. serial_driver->major = ttymajor;
  3367. serial_driver->minor_start = 64;
  3368. serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  3369. serial_driver->subtype = SERIAL_TYPE_NORMAL;
  3370. serial_driver->init_termios = tty_std_termios;
  3371. serial_driver->init_termios.c_cflag =
  3372. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  3373. serial_driver->flags = TTY_DRIVER_REAL_RAW;
  3374. tty_set_operations(serial_driver, &ops);
  3375. if ((rc = tty_register_driver(serial_driver)) < 0) {
  3376. printk("%s(%d):Couldn't register serial driver\n",
  3377. __FILE__,__LINE__);
  3378. put_tty_driver(serial_driver);
  3379. serial_driver = NULL;
  3380. goto error;
  3381. }
  3382. printk("%s %s, tty major#%d\n",
  3383. driver_name, driver_version,
  3384. serial_driver->major);
  3385. return 0;
  3386. error:
  3387. synclinkmp_cleanup();
  3388. return rc;
  3389. }
  3390. static void __exit synclinkmp_exit(void)
  3391. {
  3392. synclinkmp_cleanup();
  3393. }
  3394. module_init(synclinkmp_init);
  3395. module_exit(synclinkmp_exit);
  3396. /* Set the port for internal loopback mode.
  3397. * The TxCLK and RxCLK signals are generated from the BRG and
  3398. * the TxD is looped back to the RxD internally.
  3399. */
  3400. void enable_loopback(SLMP_INFO *info, int enable)
  3401. {
  3402. if (enable) {
  3403. /* MD2 (Mode Register 2)
  3404. * 01..00 CNCT<1..0> Channel Connection 11=Local Loopback
  3405. */
  3406. write_reg(info, MD2, (unsigned char)(read_reg(info, MD2) | (BIT1 + BIT0)));
  3407. /* degate external TxC clock source */
  3408. info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
  3409. write_control_reg(info);
  3410. /* RXS/TXS (Rx/Tx clock source)
  3411. * 07 Reserved, must be 0
  3412. * 06..04 Clock Source, 100=BRG
  3413. * 03..00 Clock Divisor, 0000=1
  3414. */
  3415. write_reg(info, RXS, 0x40);
  3416. write_reg(info, TXS, 0x40);
  3417. } else {
  3418. /* MD2 (Mode Register 2)
  3419. * 01..00 CNCT<1..0> Channel connection, 0=normal
  3420. */
  3421. write_reg(info, MD2, (unsigned char)(read_reg(info, MD2) & ~(BIT1 + BIT0)));
  3422. /* RXS/TXS (Rx/Tx clock source)
  3423. * 07 Reserved, must be 0
  3424. * 06..04 Clock Source, 000=RxC/TxC Pin
  3425. * 03..00 Clock Divisor, 0000=1
  3426. */
  3427. write_reg(info, RXS, 0x00);
  3428. write_reg(info, TXS, 0x00);
  3429. }
  3430. /* set LinkSpeed if available, otherwise default to 2Mbps */
  3431. if (info->params.clock_speed)
  3432. set_rate(info, info->params.clock_speed);
  3433. else
  3434. set_rate(info, 3686400);
  3435. }
  3436. /* Set the baud rate register to the desired speed
  3437. *
  3438. * data_rate data rate of clock in bits per second
  3439. * A data rate of 0 disables the AUX clock.
  3440. */
  3441. void set_rate( SLMP_INFO *info, u32 data_rate )
  3442. {
  3443. u32 TMCValue;
  3444. unsigned char BRValue;
  3445. u32 Divisor=0;
  3446. /* fBRG = fCLK/(TMC * 2^BR)
  3447. */
  3448. if (data_rate != 0) {
  3449. Divisor = 14745600/data_rate;
  3450. if (!Divisor)
  3451. Divisor = 1;
  3452. TMCValue = Divisor;
  3453. BRValue = 0;
  3454. if (TMCValue != 1 && TMCValue != 2) {
  3455. /* BRValue of 0 provides 50/50 duty cycle *only* when
  3456. * TMCValue is 1 or 2. BRValue of 1 to 9 always provides
  3457. * 50/50 duty cycle.
  3458. */
  3459. BRValue = 1;
  3460. TMCValue >>= 1;
  3461. }
  3462. /* while TMCValue is too big for TMC register, divide
  3463. * by 2 and increment BR exponent.
  3464. */
  3465. for(; TMCValue > 256 && BRValue < 10; BRValue++)
  3466. TMCValue >>= 1;
  3467. write_reg(info, TXS,
  3468. (unsigned char)((read_reg(info, TXS) & 0xf0) | BRValue));
  3469. write_reg(info, RXS,
  3470. (unsigned char)((read_reg(info, RXS) & 0xf0) | BRValue));
  3471. write_reg(info, TMC, (unsigned char)TMCValue);
  3472. }
  3473. else {
  3474. write_reg(info, TXS,0);
  3475. write_reg(info, RXS,0);
  3476. write_reg(info, TMC, 0);
  3477. }
  3478. }
  3479. /* Disable receiver
  3480. */
  3481. void rx_stop(SLMP_INFO *info)
  3482. {
  3483. if (debug_level >= DEBUG_LEVEL_ISR)
  3484. printk("%s(%d):%s rx_stop()\n",
  3485. __FILE__,__LINE__, info->device_name );
  3486. write_reg(info, CMD, RXRESET);
  3487. info->ie0_value &= ~RXRDYE;
  3488. write_reg(info, IE0, info->ie0_value); /* disable Rx data interrupts */
  3489. write_reg(info, RXDMA + DSR, 0); /* disable Rx DMA */
  3490. write_reg(info, RXDMA + DCMD, SWABORT); /* reset/init Rx DMA */
  3491. write_reg(info, RXDMA + DIR, 0); /* disable Rx DMA interrupts */
  3492. info->rx_enabled = 0;
  3493. info->rx_overflow = 0;
  3494. }
  3495. /* enable the receiver
  3496. */
  3497. void rx_start(SLMP_INFO *info)
  3498. {
  3499. int i;
  3500. if (debug_level >= DEBUG_LEVEL_ISR)
  3501. printk("%s(%d):%s rx_start()\n",
  3502. __FILE__,__LINE__, info->device_name );
  3503. write_reg(info, CMD, RXRESET);
  3504. if ( info->params.mode == MGSL_MODE_HDLC ) {
  3505. /* HDLC, disabe IRQ on rxdata */
  3506. info->ie0_value &= ~RXRDYE;
  3507. write_reg(info, IE0, info->ie0_value);
  3508. /* Reset all Rx DMA buffers and program rx dma */
  3509. write_reg(info, RXDMA + DSR, 0); /* disable Rx DMA */
  3510. write_reg(info, RXDMA + DCMD, SWABORT); /* reset/init Rx DMA */
  3511. for (i = 0; i < info->rx_buf_count; i++) {
  3512. info->rx_buf_list[i].status = 0xff;
  3513. // throttle to 4 shared memory writes at a time to prevent
  3514. // hogging local bus (keep latency time for DMA requests low).
  3515. if (!(i % 4))
  3516. read_status_reg(info);
  3517. }
  3518. info->current_rx_buf = 0;
  3519. /* set current/1st descriptor address */
  3520. write_reg16(info, RXDMA + CDA,
  3521. info->rx_buf_list_ex[0].phys_entry);
  3522. /* set new last rx descriptor address */
  3523. write_reg16(info, RXDMA + EDA,
  3524. info->rx_buf_list_ex[info->rx_buf_count - 1].phys_entry);
  3525. /* set buffer length (shared by all rx dma data buffers) */
  3526. write_reg16(info, RXDMA + BFL, SCABUFSIZE);
  3527. write_reg(info, RXDMA + DIR, 0x60); /* enable Rx DMA interrupts (EOM/BOF) */
  3528. write_reg(info, RXDMA + DSR, 0xf2); /* clear Rx DMA IRQs, enable Rx DMA */
  3529. } else {
  3530. /* async, enable IRQ on rxdata */
  3531. info->ie0_value |= RXRDYE;
  3532. write_reg(info, IE0, info->ie0_value);
  3533. }
  3534. write_reg(info, CMD, RXENABLE);
  3535. info->rx_overflow = FALSE;
  3536. info->rx_enabled = 1;
  3537. }
  3538. /* Enable the transmitter and send a transmit frame if
  3539. * one is loaded in the DMA buffers.
  3540. */
  3541. void tx_start(SLMP_INFO *info)
  3542. {
  3543. if (debug_level >= DEBUG_LEVEL_ISR)
  3544. printk("%s(%d):%s tx_start() tx_count=%d\n",
  3545. __FILE__,__LINE__, info->device_name,info->tx_count );
  3546. if (!info->tx_enabled ) {
  3547. write_reg(info, CMD, TXRESET);
  3548. write_reg(info, CMD, TXENABLE);
  3549. info->tx_enabled = TRUE;
  3550. }
  3551. if ( info->tx_count ) {
  3552. /* If auto RTS enabled and RTS is inactive, then assert */
  3553. /* RTS and set a flag indicating that the driver should */
  3554. /* negate RTS when the transmission completes. */
  3555. info->drop_rts_on_tx_done = 0;
  3556. if (info->params.mode != MGSL_MODE_ASYNC) {
  3557. if ( info->params.flags & HDLC_FLAG_AUTO_RTS ) {
  3558. get_signals( info );
  3559. if ( !(info->serial_signals & SerialSignal_RTS) ) {
  3560. info->serial_signals |= SerialSignal_RTS;
  3561. set_signals( info );
  3562. info->drop_rts_on_tx_done = 1;
  3563. }
  3564. }
  3565. write_reg16(info, TRC0,
  3566. (unsigned short)(((tx_negate_fifo_level-1)<<8) + tx_active_fifo_level));
  3567. write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
  3568. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  3569. /* set TX CDA (current descriptor address) */
  3570. write_reg16(info, TXDMA + CDA,
  3571. info->tx_buf_list_ex[0].phys_entry);
  3572. /* set TX EDA (last descriptor address) */
  3573. write_reg16(info, TXDMA + EDA,
  3574. info->tx_buf_list_ex[info->last_tx_buf].phys_entry);
  3575. /* enable underrun IRQ */
  3576. info->ie1_value &= ~IDLE;
  3577. info->ie1_value |= UDRN;
  3578. write_reg(info, IE1, info->ie1_value);
  3579. write_reg(info, SR1, (unsigned char)(IDLE + UDRN));
  3580. write_reg(info, TXDMA + DIR, 0x40); /* enable Tx DMA interrupts (EOM) */
  3581. write_reg(info, TXDMA + DSR, 0xf2); /* clear Tx DMA IRQs, enable Tx DMA */
  3582. info->tx_timer.expires = jiffies + msecs_to_jiffies(5000);
  3583. add_timer(&info->tx_timer);
  3584. }
  3585. else {
  3586. tx_load_fifo(info);
  3587. /* async, enable IRQ on txdata */
  3588. info->ie0_value |= TXRDYE;
  3589. write_reg(info, IE0, info->ie0_value);
  3590. }
  3591. info->tx_active = 1;
  3592. }
  3593. }
  3594. /* stop the transmitter and DMA
  3595. */
  3596. void tx_stop( SLMP_INFO *info )
  3597. {
  3598. if (debug_level >= DEBUG_LEVEL_ISR)
  3599. printk("%s(%d):%s tx_stop()\n",
  3600. __FILE__,__LINE__, info->device_name );
  3601. del_timer(&info->tx_timer);
  3602. write_reg(info, TXDMA + DSR, 0); /* disable DMA channel */
  3603. write_reg(info, TXDMA + DCMD, SWABORT); /* reset/init DMA channel */
  3604. write_reg(info, CMD, TXRESET);
  3605. info->ie1_value &= ~(UDRN + IDLE);
  3606. write_reg(info, IE1, info->ie1_value); /* disable tx status interrupts */
  3607. write_reg(info, SR1, (unsigned char)(IDLE + UDRN)); /* clear pending */
  3608. info->ie0_value &= ~TXRDYE;
  3609. write_reg(info, IE0, info->ie0_value); /* disable tx data interrupts */
  3610. info->tx_enabled = 0;
  3611. info->tx_active = 0;
  3612. }
  3613. /* Fill the transmit FIFO until the FIFO is full or
  3614. * there is no more data to load.
  3615. */
  3616. void tx_load_fifo(SLMP_INFO *info)
  3617. {
  3618. u8 TwoBytes[2];
  3619. /* do nothing is now tx data available and no XON/XOFF pending */
  3620. if ( !info->tx_count && !info->x_char )
  3621. return;
  3622. /* load the Transmit FIFO until FIFOs full or all data sent */
  3623. while( info->tx_count && (read_reg(info,SR0) & BIT1) ) {
  3624. /* there is more space in the transmit FIFO and */
  3625. /* there is more data in transmit buffer */
  3626. if ( (info->tx_count > 1) && !info->x_char ) {
  3627. /* write 16-bits */
  3628. TwoBytes[0] = info->tx_buf[info->tx_get++];
  3629. if (info->tx_get >= info->max_frame_size)
  3630. info->tx_get -= info->max_frame_size;
  3631. TwoBytes[1] = info->tx_buf[info->tx_get++];
  3632. if (info->tx_get >= info->max_frame_size)
  3633. info->tx_get -= info->max_frame_size;
  3634. write_reg16(info, TRB, *((u16 *)TwoBytes));
  3635. info->tx_count -= 2;
  3636. info->icount.tx += 2;
  3637. } else {
  3638. /* only 1 byte left to transmit or 1 FIFO slot left */
  3639. if (info->x_char) {
  3640. /* transmit pending high priority char */
  3641. write_reg(info, TRB, info->x_char);
  3642. info->x_char = 0;
  3643. } else {
  3644. write_reg(info, TRB, info->tx_buf[info->tx_get++]);
  3645. if (info->tx_get >= info->max_frame_size)
  3646. info->tx_get -= info->max_frame_size;
  3647. info->tx_count--;
  3648. }
  3649. info->icount.tx++;
  3650. }
  3651. }
  3652. }
  3653. /* Reset a port to a known state
  3654. */
  3655. void reset_port(SLMP_INFO *info)
  3656. {
  3657. if (info->sca_base) {
  3658. tx_stop(info);
  3659. rx_stop(info);
  3660. info->serial_signals &= ~(SerialSignal_DTR + SerialSignal_RTS);
  3661. set_signals(info);
  3662. /* disable all port interrupts */
  3663. info->ie0_value = 0;
  3664. info->ie1_value = 0;
  3665. info->ie2_value = 0;
  3666. write_reg(info, IE0, info->ie0_value);
  3667. write_reg(info, IE1, info->ie1_value);
  3668. write_reg(info, IE2, info->ie2_value);
  3669. write_reg(info, CMD, CHRESET);
  3670. }
  3671. }
  3672. /* Reset all the ports to a known state.
  3673. */
  3674. void reset_adapter(SLMP_INFO *info)
  3675. {
  3676. int i;
  3677. for ( i=0; i < SCA_MAX_PORTS; ++i) {
  3678. if (info->port_array[i])
  3679. reset_port(info->port_array[i]);
  3680. }
  3681. }
  3682. /* Program port for asynchronous communications.
  3683. */
  3684. void async_mode(SLMP_INFO *info)
  3685. {
  3686. unsigned char RegValue;
  3687. tx_stop(info);
  3688. rx_stop(info);
  3689. /* MD0, Mode Register 0
  3690. *
  3691. * 07..05 PRCTL<2..0>, Protocol Mode, 000=async
  3692. * 04 AUTO, Auto-enable (RTS/CTS/DCD)
  3693. * 03 Reserved, must be 0
  3694. * 02 CRCCC, CRC Calculation, 0=disabled
  3695. * 01..00 STOP<1..0> Stop bits (00=1,10=2)
  3696. *
  3697. * 0000 0000
  3698. */
  3699. RegValue = 0x00;
  3700. if (info->params.stop_bits != 1)
  3701. RegValue |= BIT1;
  3702. write_reg(info, MD0, RegValue);
  3703. /* MD1, Mode Register 1
  3704. *
  3705. * 07..06 BRATE<1..0>, bit rate, 00=1/1 01=1/16 10=1/32 11=1/64
  3706. * 05..04 TXCHR<1..0>, tx char size, 00=8 bits,01=7,10=6,11=5
  3707. * 03..02 RXCHR<1..0>, rx char size
  3708. * 01..00 PMPM<1..0>, Parity mode, 00=none 10=even 11=odd
  3709. *
  3710. * 0100 0000
  3711. */
  3712. RegValue = 0x40;
  3713. switch (info->params.data_bits) {
  3714. case 7: RegValue |= BIT4 + BIT2; break;
  3715. case 6: RegValue |= BIT5 + BIT3; break;
  3716. case 5: RegValue |= BIT5 + BIT4 + BIT3 + BIT2; break;
  3717. }
  3718. if (info->params.parity != ASYNC_PARITY_NONE) {
  3719. RegValue |= BIT1;
  3720. if (info->params.parity == ASYNC_PARITY_ODD)
  3721. RegValue |= BIT0;
  3722. }
  3723. write_reg(info, MD1, RegValue);
  3724. /* MD2, Mode Register 2
  3725. *
  3726. * 07..02 Reserved, must be 0
  3727. * 01..00 CNCT<1..0> Channel connection, 00=normal 11=local loopback
  3728. *
  3729. * 0000 0000
  3730. */
  3731. RegValue = 0x00;
  3732. if (info->params.loopback)
  3733. RegValue |= (BIT1 + BIT0);
  3734. write_reg(info, MD2, RegValue);
  3735. /* RXS, Receive clock source
  3736. *
  3737. * 07 Reserved, must be 0
  3738. * 06..04 RXCS<2..0>, clock source, 000=RxC Pin, 100=BRG, 110=DPLL
  3739. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3740. */
  3741. RegValue=BIT6;
  3742. write_reg(info, RXS, RegValue);
  3743. /* TXS, Transmit clock source
  3744. *
  3745. * 07 Reserved, must be 0
  3746. * 06..04 RXCS<2..0>, clock source, 000=TxC Pin, 100=BRG, 110=Receive Clock
  3747. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3748. */
  3749. RegValue=BIT6;
  3750. write_reg(info, TXS, RegValue);
  3751. /* Control Register
  3752. *
  3753. * 6,4,2,0 CLKSEL<3..0>, 0 = TcCLK in, 1 = Auxclk out
  3754. */
  3755. info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
  3756. write_control_reg(info);
  3757. tx_set_idle(info);
  3758. /* RRC Receive Ready Control 0
  3759. *
  3760. * 07..05 Reserved, must be 0
  3761. * 04..00 RRC<4..0> Rx FIFO trigger active 0x00 = 1 byte
  3762. */
  3763. write_reg(info, RRC, 0x00);
  3764. /* TRC0 Transmit Ready Control 0
  3765. *
  3766. * 07..05 Reserved, must be 0
  3767. * 04..00 TRC<4..0> Tx FIFO trigger active 0x10 = 16 bytes
  3768. */
  3769. write_reg(info, TRC0, 0x10);
  3770. /* TRC1 Transmit Ready Control 1
  3771. *
  3772. * 07..05 Reserved, must be 0
  3773. * 04..00 TRC<4..0> Tx FIFO trigger inactive 0x1e = 31 bytes (full-1)
  3774. */
  3775. write_reg(info, TRC1, 0x1e);
  3776. /* CTL, MSCI control register
  3777. *
  3778. * 07..06 Reserved, set to 0
  3779. * 05 UDRNC, underrun control, 0=abort 1=CRC+flag (HDLC/BSC)
  3780. * 04 IDLC, idle control, 0=mark 1=idle register
  3781. * 03 BRK, break, 0=off 1 =on (async)
  3782. * 02 SYNCLD, sync char load enable (BSC) 1=enabled
  3783. * 01 GOP, go active on poll (LOOP mode) 1=enabled
  3784. * 00 RTS, RTS output control, 0=active 1=inactive
  3785. *
  3786. * 0001 0001
  3787. */
  3788. RegValue = 0x10;
  3789. if (!(info->serial_signals & SerialSignal_RTS))
  3790. RegValue |= 0x01;
  3791. write_reg(info, CTL, RegValue);
  3792. /* enable status interrupts */
  3793. info->ie0_value |= TXINTE + RXINTE;
  3794. write_reg(info, IE0, info->ie0_value);
  3795. /* enable break detect interrupt */
  3796. info->ie1_value = BRKD;
  3797. write_reg(info, IE1, info->ie1_value);
  3798. /* enable rx overrun interrupt */
  3799. info->ie2_value = OVRN;
  3800. write_reg(info, IE2, info->ie2_value);
  3801. set_rate( info, info->params.data_rate * 16 );
  3802. }
  3803. /* Program the SCA for HDLC communications.
  3804. */
  3805. void hdlc_mode(SLMP_INFO *info)
  3806. {
  3807. unsigned char RegValue;
  3808. u32 DpllDivisor;
  3809. // Can't use DPLL because SCA outputs recovered clock on RxC when
  3810. // DPLL mode selected. This causes output contention with RxC receiver.
  3811. // Use of DPLL would require external hardware to disable RxC receiver
  3812. // when DPLL mode selected.
  3813. info->params.flags &= ~(HDLC_FLAG_TXC_DPLL + HDLC_FLAG_RXC_DPLL);
  3814. /* disable DMA interrupts */
  3815. write_reg(info, TXDMA + DIR, 0);
  3816. write_reg(info, RXDMA + DIR, 0);
  3817. /* MD0, Mode Register 0
  3818. *
  3819. * 07..05 PRCTL<2..0>, Protocol Mode, 100=HDLC
  3820. * 04 AUTO, Auto-enable (RTS/CTS/DCD)
  3821. * 03 Reserved, must be 0
  3822. * 02 CRCCC, CRC Calculation, 1=enabled
  3823. * 01 CRC1, CRC selection, 0=CRC-16,1=CRC-CCITT-16
  3824. * 00 CRC0, CRC initial value, 1 = all 1s
  3825. *
  3826. * 1000 0001
  3827. */
  3828. RegValue = 0x81;
  3829. if (info->params.flags & HDLC_FLAG_AUTO_CTS)
  3830. RegValue |= BIT4;
  3831. if (info->params.flags & HDLC_FLAG_AUTO_DCD)
  3832. RegValue |= BIT4;
  3833. if (info->params.crc_type == HDLC_CRC_16_CCITT)
  3834. RegValue |= BIT2 + BIT1;
  3835. write_reg(info, MD0, RegValue);
  3836. /* MD1, Mode Register 1
  3837. *
  3838. * 07..06 ADDRS<1..0>, Address detect, 00=no addr check
  3839. * 05..04 TXCHR<1..0>, tx char size, 00=8 bits
  3840. * 03..02 RXCHR<1..0>, rx char size, 00=8 bits
  3841. * 01..00 PMPM<1..0>, Parity mode, 00=no parity
  3842. *
  3843. * 0000 0000
  3844. */
  3845. RegValue = 0x00;
  3846. write_reg(info, MD1, RegValue);
  3847. /* MD2, Mode Register 2
  3848. *
  3849. * 07 NRZFM, 0=NRZ, 1=FM
  3850. * 06..05 CODE<1..0> Encoding, 00=NRZ
  3851. * 04..03 DRATE<1..0> DPLL Divisor, 00=8
  3852. * 02 Reserved, must be 0
  3853. * 01..00 CNCT<1..0> Channel connection, 0=normal
  3854. *
  3855. * 0000 0000
  3856. */
  3857. RegValue = 0x00;
  3858. switch(info->params.encoding) {
  3859. case HDLC_ENCODING_NRZI: RegValue |= BIT5; break;
  3860. case HDLC_ENCODING_BIPHASE_MARK: RegValue |= BIT7 + BIT5; break; /* aka FM1 */
  3861. case HDLC_ENCODING_BIPHASE_SPACE: RegValue |= BIT7 + BIT6; break; /* aka FM0 */
  3862. case HDLC_ENCODING_BIPHASE_LEVEL: RegValue |= BIT7; break; /* aka Manchester */
  3863. #if 0
  3864. case HDLC_ENCODING_NRZB: /* not supported */
  3865. case HDLC_ENCODING_NRZI_MARK: /* not supported */
  3866. case HDLC_ENCODING_DIFF_BIPHASE_LEVEL: /* not supported */
  3867. #endif
  3868. }
  3869. if ( info->params.flags & HDLC_FLAG_DPLL_DIV16 ) {
  3870. DpllDivisor = 16;
  3871. RegValue |= BIT3;
  3872. } else if ( info->params.flags & HDLC_FLAG_DPLL_DIV8 ) {
  3873. DpllDivisor = 8;
  3874. } else {
  3875. DpllDivisor = 32;
  3876. RegValue |= BIT4;
  3877. }
  3878. write_reg(info, MD2, RegValue);
  3879. /* RXS, Receive clock source
  3880. *
  3881. * 07 Reserved, must be 0
  3882. * 06..04 RXCS<2..0>, clock source, 000=RxC Pin, 100=BRG, 110=DPLL
  3883. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3884. */
  3885. RegValue=0;
  3886. if (info->params.flags & HDLC_FLAG_RXC_BRG)
  3887. RegValue |= BIT6;
  3888. if (info->params.flags & HDLC_FLAG_RXC_DPLL)
  3889. RegValue |= BIT6 + BIT5;
  3890. write_reg(info, RXS, RegValue);
  3891. /* TXS, Transmit clock source
  3892. *
  3893. * 07 Reserved, must be 0
  3894. * 06..04 RXCS<2..0>, clock source, 000=TxC Pin, 100=BRG, 110=Receive Clock
  3895. * 03..00 RXBR<3..0>, rate divisor, 0000=1
  3896. */
  3897. RegValue=0;
  3898. if (info->params.flags & HDLC_FLAG_TXC_BRG)
  3899. RegValue |= BIT6;
  3900. if (info->params.flags & HDLC_FLAG_TXC_DPLL)
  3901. RegValue |= BIT6 + BIT5;
  3902. write_reg(info, TXS, RegValue);
  3903. if (info->params.flags & HDLC_FLAG_RXC_DPLL)
  3904. set_rate(info, info->params.clock_speed * DpllDivisor);
  3905. else
  3906. set_rate(info, info->params.clock_speed);
  3907. /* GPDATA (General Purpose I/O Data Register)
  3908. *
  3909. * 6,4,2,0 CLKSEL<3..0>, 0 = TcCLK in, 1 = Auxclk out
  3910. */
  3911. if (info->params.flags & HDLC_FLAG_TXC_BRG)
  3912. info->port_array[0]->ctrlreg_value |= (BIT0 << (info->port_num * 2));
  3913. else
  3914. info->port_array[0]->ctrlreg_value &= ~(BIT0 << (info->port_num * 2));
  3915. write_control_reg(info);
  3916. /* RRC Receive Ready Control 0
  3917. *
  3918. * 07..05 Reserved, must be 0
  3919. * 04..00 RRC<4..0> Rx FIFO trigger active
  3920. */
  3921. write_reg(info, RRC, rx_active_fifo_level);
  3922. /* TRC0 Transmit Ready Control 0
  3923. *
  3924. * 07..05 Reserved, must be 0
  3925. * 04..00 TRC<4..0> Tx FIFO trigger active
  3926. */
  3927. write_reg(info, TRC0, tx_active_fifo_level);
  3928. /* TRC1 Transmit Ready Control 1
  3929. *
  3930. * 07..05 Reserved, must be 0
  3931. * 04..00 TRC<4..0> Tx FIFO trigger inactive 0x1f = 32 bytes (full)
  3932. */
  3933. write_reg(info, TRC1, (unsigned char)(tx_negate_fifo_level - 1));
  3934. /* DMR, DMA Mode Register
  3935. *
  3936. * 07..05 Reserved, must be 0
  3937. * 04 TMOD, Transfer Mode: 1=chained-block
  3938. * 03 Reserved, must be 0
  3939. * 02 NF, Number of Frames: 1=multi-frame
  3940. * 01 CNTE, Frame End IRQ Counter enable: 0=disabled
  3941. * 00 Reserved, must be 0
  3942. *
  3943. * 0001 0100
  3944. */
  3945. write_reg(info, TXDMA + DMR, 0x14);
  3946. write_reg(info, RXDMA + DMR, 0x14);
  3947. /* Set chain pointer base (upper 8 bits of 24 bit addr) */
  3948. write_reg(info, RXDMA + CPB,
  3949. (unsigned char)(info->buffer_list_phys >> 16));
  3950. /* Set chain pointer base (upper 8 bits of 24 bit addr) */
  3951. write_reg(info, TXDMA + CPB,
  3952. (unsigned char)(info->buffer_list_phys >> 16));
  3953. /* enable status interrupts. other code enables/disables
  3954. * the individual sources for these two interrupt classes.
  3955. */
  3956. info->ie0_value |= TXINTE + RXINTE;
  3957. write_reg(info, IE0, info->ie0_value);
  3958. /* CTL, MSCI control register
  3959. *
  3960. * 07..06 Reserved, set to 0
  3961. * 05 UDRNC, underrun control, 0=abort 1=CRC+flag (HDLC/BSC)
  3962. * 04 IDLC, idle control, 0=mark 1=idle register
  3963. * 03 BRK, break, 0=off 1 =on (async)
  3964. * 02 SYNCLD, sync char load enable (BSC) 1=enabled
  3965. * 01 GOP, go active on poll (LOOP mode) 1=enabled
  3966. * 00 RTS, RTS output control, 0=active 1=inactive
  3967. *
  3968. * 0001 0001
  3969. */
  3970. RegValue = 0x10;
  3971. if (!(info->serial_signals & SerialSignal_RTS))
  3972. RegValue |= 0x01;
  3973. write_reg(info, CTL, RegValue);
  3974. /* preamble not supported ! */
  3975. tx_set_idle(info);
  3976. tx_stop(info);
  3977. rx_stop(info);
  3978. set_rate(info, info->params.clock_speed);
  3979. if (info->params.loopback)
  3980. enable_loopback(info,1);
  3981. }
  3982. /* Set the transmit HDLC idle mode
  3983. */
  3984. void tx_set_idle(SLMP_INFO *info)
  3985. {
  3986. unsigned char RegValue = 0xff;
  3987. /* Map API idle mode to SCA register bits */
  3988. switch(info->idle_mode) {
  3989. case HDLC_TXIDLE_FLAGS: RegValue = 0x7e; break;
  3990. case HDLC_TXIDLE_ALT_ZEROS_ONES: RegValue = 0xaa; break;
  3991. case HDLC_TXIDLE_ZEROS: RegValue = 0x00; break;
  3992. case HDLC_TXIDLE_ONES: RegValue = 0xff; break;
  3993. case HDLC_TXIDLE_ALT_MARK_SPACE: RegValue = 0xaa; break;
  3994. case HDLC_TXIDLE_SPACE: RegValue = 0x00; break;
  3995. case HDLC_TXIDLE_MARK: RegValue = 0xff; break;
  3996. }
  3997. write_reg(info, IDL, RegValue);
  3998. }
  3999. /* Query the adapter for the state of the V24 status (input) signals.
  4000. */
  4001. void get_signals(SLMP_INFO *info)
  4002. {
  4003. u16 status = read_reg(info, SR3);
  4004. u16 gpstatus = read_status_reg(info);
  4005. u16 testbit;
  4006. /* clear all serial signals except DTR and RTS */
  4007. info->serial_signals &= SerialSignal_DTR + SerialSignal_RTS;
  4008. /* set serial signal bits to reflect MISR */
  4009. if (!(status & BIT3))
  4010. info->serial_signals |= SerialSignal_CTS;
  4011. if ( !(status & BIT2))
  4012. info->serial_signals |= SerialSignal_DCD;
  4013. testbit = BIT1 << (info->port_num * 2); // Port 0..3 RI is GPDATA<1,3,5,7>
  4014. if (!(gpstatus & testbit))
  4015. info->serial_signals |= SerialSignal_RI;
  4016. testbit = BIT0 << (info->port_num * 2); // Port 0..3 DSR is GPDATA<0,2,4,6>
  4017. if (!(gpstatus & testbit))
  4018. info->serial_signals |= SerialSignal_DSR;
  4019. }
  4020. /* Set the state of DTR and RTS based on contents of
  4021. * serial_signals member of device context.
  4022. */
  4023. void set_signals(SLMP_INFO *info)
  4024. {
  4025. unsigned char RegValue;
  4026. u16 EnableBit;
  4027. RegValue = read_reg(info, CTL);
  4028. if (info->serial_signals & SerialSignal_RTS)
  4029. RegValue &= ~BIT0;
  4030. else
  4031. RegValue |= BIT0;
  4032. write_reg(info, CTL, RegValue);
  4033. // Port 0..3 DTR is ctrl reg <1,3,5,7>
  4034. EnableBit = BIT1 << (info->port_num*2);
  4035. if (info->serial_signals & SerialSignal_DTR)
  4036. info->port_array[0]->ctrlreg_value &= ~EnableBit;
  4037. else
  4038. info->port_array[0]->ctrlreg_value |= EnableBit;
  4039. write_control_reg(info);
  4040. }
  4041. /*******************/
  4042. /* DMA Buffer Code */
  4043. /*******************/
  4044. /* Set the count for all receive buffers to SCABUFSIZE
  4045. * and set the current buffer to the first buffer. This effectively
  4046. * makes all buffers free and discards any data in buffers.
  4047. */
  4048. void rx_reset_buffers(SLMP_INFO *info)
  4049. {
  4050. rx_free_frame_buffers(info, 0, info->rx_buf_count - 1);
  4051. }
  4052. /* Free the buffers used by a received frame
  4053. *
  4054. * info pointer to device instance data
  4055. * first index of 1st receive buffer of frame
  4056. * last index of last receive buffer of frame
  4057. */
  4058. void rx_free_frame_buffers(SLMP_INFO *info, unsigned int first, unsigned int last)
  4059. {
  4060. int done = 0;
  4061. while(!done) {
  4062. /* reset current buffer for reuse */
  4063. info->rx_buf_list[first].status = 0xff;
  4064. if (first == last) {
  4065. done = 1;
  4066. /* set new last rx descriptor address */
  4067. write_reg16(info, RXDMA + EDA, info->rx_buf_list_ex[first].phys_entry);
  4068. }
  4069. first++;
  4070. if (first == info->rx_buf_count)
  4071. first = 0;
  4072. }
  4073. /* set current buffer to next buffer after last buffer of frame */
  4074. info->current_rx_buf = first;
  4075. }
  4076. /* Return a received frame from the receive DMA buffers.
  4077. * Only frames received without errors are returned.
  4078. *
  4079. * Return Value: 1 if frame returned, otherwise 0
  4080. */
  4081. int rx_get_frame(SLMP_INFO *info)
  4082. {
  4083. unsigned int StartIndex, EndIndex; /* index of 1st and last buffers of Rx frame */
  4084. unsigned short status;
  4085. unsigned int framesize = 0;
  4086. int ReturnCode = 0;
  4087. unsigned long flags;
  4088. struct tty_struct *tty = info->tty;
  4089. unsigned char addr_field = 0xff;
  4090. SCADESC *desc;
  4091. SCADESC_EX *desc_ex;
  4092. CheckAgain:
  4093. /* assume no frame returned, set zero length */
  4094. framesize = 0;
  4095. addr_field = 0xff;
  4096. /*
  4097. * current_rx_buf points to the 1st buffer of the next available
  4098. * receive frame. To find the last buffer of the frame look for
  4099. * a non-zero status field in the buffer entries. (The status
  4100. * field is set by the 16C32 after completing a receive frame.
  4101. */
  4102. StartIndex = EndIndex = info->current_rx_buf;
  4103. for ( ;; ) {
  4104. desc = &info->rx_buf_list[EndIndex];
  4105. desc_ex = &info->rx_buf_list_ex[EndIndex];
  4106. if (desc->status == 0xff)
  4107. goto Cleanup; /* current desc still in use, no frames available */
  4108. if (framesize == 0 && info->params.addr_filter != 0xff)
  4109. addr_field = desc_ex->virt_addr[0];
  4110. framesize += desc->length;
  4111. /* Status != 0 means last buffer of frame */
  4112. if (desc->status)
  4113. break;
  4114. EndIndex++;
  4115. if (EndIndex == info->rx_buf_count)
  4116. EndIndex = 0;
  4117. if (EndIndex == info->current_rx_buf) {
  4118. /* all buffers have been 'used' but none mark */
  4119. /* the end of a frame. Reset buffers and receiver. */
  4120. if ( info->rx_enabled ){
  4121. spin_lock_irqsave(&info->lock,flags);
  4122. rx_start(info);
  4123. spin_unlock_irqrestore(&info->lock,flags);
  4124. }
  4125. goto Cleanup;
  4126. }
  4127. }
  4128. /* check status of receive frame */
  4129. /* frame status is byte stored after frame data
  4130. *
  4131. * 7 EOM (end of msg), 1 = last buffer of frame
  4132. * 6 Short Frame, 1 = short frame
  4133. * 5 Abort, 1 = frame aborted
  4134. * 4 Residue, 1 = last byte is partial
  4135. * 3 Overrun, 1 = overrun occurred during frame reception
  4136. * 2 CRC, 1 = CRC error detected
  4137. *
  4138. */
  4139. status = desc->status;
  4140. /* ignore CRC bit if not using CRC (bit is undefined) */
  4141. /* Note:CRC is not save to data buffer */
  4142. if (info->params.crc_type == HDLC_CRC_NONE)
  4143. status &= ~BIT2;
  4144. if (framesize == 0 ||
  4145. (addr_field != 0xff && addr_field != info->params.addr_filter)) {
  4146. /* discard 0 byte frames, this seems to occur sometime
  4147. * when remote is idling flags.
  4148. */
  4149. rx_free_frame_buffers(info, StartIndex, EndIndex);
  4150. goto CheckAgain;
  4151. }
  4152. if (framesize < 2)
  4153. status |= BIT6;
  4154. if (status & (BIT6+BIT5+BIT3+BIT2)) {
  4155. /* received frame has errors,
  4156. * update counts and mark frame size as 0
  4157. */
  4158. if (status & BIT6)
  4159. info->icount.rxshort++;
  4160. else if (status & BIT5)
  4161. info->icount.rxabort++;
  4162. else if (status & BIT3)
  4163. info->icount.rxover++;
  4164. else
  4165. info->icount.rxcrc++;
  4166. framesize = 0;
  4167. #ifdef CONFIG_HDLC
  4168. {
  4169. struct net_device_stats *stats = hdlc_stats(info->netdev);
  4170. stats->rx_errors++;
  4171. stats->rx_frame_errors++;
  4172. }
  4173. #endif
  4174. }
  4175. if ( debug_level >= DEBUG_LEVEL_BH )
  4176. printk("%s(%d):%s rx_get_frame() status=%04X size=%d\n",
  4177. __FILE__,__LINE__,info->device_name,status,framesize);
  4178. if ( debug_level >= DEBUG_LEVEL_DATA )
  4179. trace_block(info,info->rx_buf_list_ex[StartIndex].virt_addr,
  4180. min_t(int, framesize,SCABUFSIZE),0);
  4181. if (framesize) {
  4182. if (framesize > info->max_frame_size)
  4183. info->icount.rxlong++;
  4184. else {
  4185. /* copy dma buffer(s) to contiguous intermediate buffer */
  4186. int copy_count = framesize;
  4187. int index = StartIndex;
  4188. unsigned char *ptmp = info->tmp_rx_buf;
  4189. info->tmp_rx_buf_count = framesize;
  4190. info->icount.rxok++;
  4191. while(copy_count) {
  4192. int partial_count = min(copy_count,SCABUFSIZE);
  4193. memcpy( ptmp,
  4194. info->rx_buf_list_ex[index].virt_addr,
  4195. partial_count );
  4196. ptmp += partial_count;
  4197. copy_count -= partial_count;
  4198. if ( ++index == info->rx_buf_count )
  4199. index = 0;
  4200. }
  4201. #ifdef CONFIG_HDLC
  4202. if (info->netcount)
  4203. hdlcdev_rx(info,info->tmp_rx_buf,framesize);
  4204. else
  4205. #endif
  4206. ldisc_receive_buf(tty,info->tmp_rx_buf,
  4207. info->flag_buf, framesize);
  4208. }
  4209. }
  4210. /* Free the buffers used by this frame. */
  4211. rx_free_frame_buffers( info, StartIndex, EndIndex );
  4212. ReturnCode = 1;
  4213. Cleanup:
  4214. if ( info->rx_enabled && info->rx_overflow ) {
  4215. /* Receiver is enabled, but needs to restarted due to
  4216. * rx buffer overflow. If buffers are empty, restart receiver.
  4217. */
  4218. if (info->rx_buf_list[EndIndex].status == 0xff) {
  4219. spin_lock_irqsave(&info->lock,flags);
  4220. rx_start(info);
  4221. spin_unlock_irqrestore(&info->lock,flags);
  4222. }
  4223. }
  4224. return ReturnCode;
  4225. }
  4226. /* load the transmit DMA buffer with data
  4227. */
  4228. void tx_load_dma_buffer(SLMP_INFO *info, const char *buf, unsigned int count)
  4229. {
  4230. unsigned short copy_count;
  4231. unsigned int i = 0;
  4232. SCADESC *desc;
  4233. SCADESC_EX *desc_ex;
  4234. if ( debug_level >= DEBUG_LEVEL_DATA )
  4235. trace_block(info,buf, min_t(int, count,SCABUFSIZE), 1);
  4236. /* Copy source buffer to one or more DMA buffers, starting with
  4237. * the first transmit dma buffer.
  4238. */
  4239. for(i=0;;)
  4240. {
  4241. copy_count = min_t(unsigned short,count,SCABUFSIZE);
  4242. desc = &info->tx_buf_list[i];
  4243. desc_ex = &info->tx_buf_list_ex[i];
  4244. load_pci_memory(info, desc_ex->virt_addr,buf,copy_count);
  4245. desc->length = copy_count;
  4246. desc->status = 0;
  4247. buf += copy_count;
  4248. count -= copy_count;
  4249. if (!count)
  4250. break;
  4251. i++;
  4252. if (i >= info->tx_buf_count)
  4253. i = 0;
  4254. }
  4255. info->tx_buf_list[i].status = 0x81; /* set EOM and EOT status */
  4256. info->last_tx_buf = ++i;
  4257. }
  4258. int register_test(SLMP_INFO *info)
  4259. {
  4260. static unsigned char testval[] = {0x00, 0xff, 0xaa, 0x55, 0x69, 0x96};
  4261. static unsigned int count = sizeof(testval)/sizeof(unsigned char);
  4262. unsigned int i;
  4263. int rc = TRUE;
  4264. unsigned long flags;
  4265. spin_lock_irqsave(&info->lock,flags);
  4266. reset_port(info);
  4267. /* assume failure */
  4268. info->init_error = DiagStatus_AddressFailure;
  4269. /* Write bit patterns to various registers but do it out of */
  4270. /* sync, then read back and verify values. */
  4271. for (i = 0 ; i < count ; i++) {
  4272. write_reg(info, TMC, testval[i]);
  4273. write_reg(info, IDL, testval[(i+1)%count]);
  4274. write_reg(info, SA0, testval[(i+2)%count]);
  4275. write_reg(info, SA1, testval[(i+3)%count]);
  4276. if ( (read_reg(info, TMC) != testval[i]) ||
  4277. (read_reg(info, IDL) != testval[(i+1)%count]) ||
  4278. (read_reg(info, SA0) != testval[(i+2)%count]) ||
  4279. (read_reg(info, SA1) != testval[(i+3)%count]) )
  4280. {
  4281. rc = FALSE;
  4282. break;
  4283. }
  4284. }
  4285. reset_port(info);
  4286. spin_unlock_irqrestore(&info->lock,flags);
  4287. return rc;
  4288. }
  4289. int irq_test(SLMP_INFO *info)
  4290. {
  4291. unsigned long timeout;
  4292. unsigned long flags;
  4293. unsigned char timer = (info->port_num & 1) ? TIMER2 : TIMER0;
  4294. spin_lock_irqsave(&info->lock,flags);
  4295. reset_port(info);
  4296. /* assume failure */
  4297. info->init_error = DiagStatus_IrqFailure;
  4298. info->irq_occurred = FALSE;
  4299. /* setup timer0 on SCA0 to interrupt */
  4300. /* IER2<7..4> = timer<3..0> interrupt enables (1=enabled) */
  4301. write_reg(info, IER2, (unsigned char)((info->port_num & 1) ? BIT6 : BIT4));
  4302. write_reg(info, (unsigned char)(timer + TEPR), 0); /* timer expand prescale */
  4303. write_reg16(info, (unsigned char)(timer + TCONR), 1); /* timer constant */
  4304. /* TMCS, Timer Control/Status Register
  4305. *
  4306. * 07 CMF, Compare match flag (read only) 1=match
  4307. * 06 ECMI, CMF Interrupt Enable: 1=enabled
  4308. * 05 Reserved, must be 0
  4309. * 04 TME, Timer Enable
  4310. * 03..00 Reserved, must be 0
  4311. *
  4312. * 0101 0000
  4313. */
  4314. write_reg(info, (unsigned char)(timer + TMCS), 0x50);
  4315. spin_unlock_irqrestore(&info->lock,flags);
  4316. timeout=100;
  4317. while( timeout-- && !info->irq_occurred ) {
  4318. msleep_interruptible(10);
  4319. }
  4320. spin_lock_irqsave(&info->lock,flags);
  4321. reset_port(info);
  4322. spin_unlock_irqrestore(&info->lock,flags);
  4323. return info->irq_occurred;
  4324. }
  4325. /* initialize individual SCA device (2 ports)
  4326. */
  4327. static int sca_init(SLMP_INFO *info)
  4328. {
  4329. /* set wait controller to single mem partition (low), no wait states */
  4330. write_reg(info, PABR0, 0); /* wait controller addr boundary 0 */
  4331. write_reg(info, PABR1, 0); /* wait controller addr boundary 1 */
  4332. write_reg(info, WCRL, 0); /* wait controller low range */
  4333. write_reg(info, WCRM, 0); /* wait controller mid range */
  4334. write_reg(info, WCRH, 0); /* wait controller high range */
  4335. /* DPCR, DMA Priority Control
  4336. *
  4337. * 07..05 Not used, must be 0
  4338. * 04 BRC, bus release condition: 0=all transfers complete
  4339. * 03 CCC, channel change condition: 0=every cycle
  4340. * 02..00 PR<2..0>, priority 100=round robin
  4341. *
  4342. * 00000100 = 0x04
  4343. */
  4344. write_reg(info, DPCR, dma_priority);
  4345. /* DMA Master Enable, BIT7: 1=enable all channels */
  4346. write_reg(info, DMER, 0x80);
  4347. /* enable all interrupt classes */
  4348. write_reg(info, IER0, 0xff); /* TxRDY,RxRDY,TxINT,RxINT (ports 0-1) */
  4349. write_reg(info, IER1, 0xff); /* DMIB,DMIA (channels 0-3) */
  4350. write_reg(info, IER2, 0xf0); /* TIRQ (timers 0-3) */
  4351. /* ITCR, interrupt control register
  4352. * 07 IPC, interrupt priority, 0=MSCI->DMA
  4353. * 06..05 IAK<1..0>, Acknowledge cycle, 00=non-ack cycle
  4354. * 04 VOS, Vector Output, 0=unmodified vector
  4355. * 03..00 Reserved, must be 0
  4356. */
  4357. write_reg(info, ITCR, 0);
  4358. return TRUE;
  4359. }
  4360. /* initialize adapter hardware
  4361. */
  4362. int init_adapter(SLMP_INFO *info)
  4363. {
  4364. int i;
  4365. /* Set BIT30 of Local Control Reg 0x50 to reset SCA */
  4366. volatile u32 *MiscCtrl = (u32 *)(info->lcr_base + 0x50);
  4367. u32 readval;
  4368. info->misc_ctrl_value |= BIT30;
  4369. *MiscCtrl = info->misc_ctrl_value;
  4370. /*
  4371. * Force at least 170ns delay before clearing
  4372. * reset bit. Each read from LCR takes at least
  4373. * 30ns so 10 times for 300ns to be safe.
  4374. */
  4375. for(i=0;i<10;i++)
  4376. readval = *MiscCtrl;
  4377. info->misc_ctrl_value &= ~BIT30;
  4378. *MiscCtrl = info->misc_ctrl_value;
  4379. /* init control reg (all DTRs off, all clksel=input) */
  4380. info->ctrlreg_value = 0xaa;
  4381. write_control_reg(info);
  4382. {
  4383. volatile u32 *LCR1BRDR = (u32 *)(info->lcr_base + 0x2c);
  4384. lcr1_brdr_value &= ~(BIT5 + BIT4 + BIT3);
  4385. switch(read_ahead_count)
  4386. {
  4387. case 16:
  4388. lcr1_brdr_value |= BIT5 + BIT4 + BIT3;
  4389. break;
  4390. case 8:
  4391. lcr1_brdr_value |= BIT5 + BIT4;
  4392. break;
  4393. case 4:
  4394. lcr1_brdr_value |= BIT5 + BIT3;
  4395. break;
  4396. case 0:
  4397. lcr1_brdr_value |= BIT5;
  4398. break;
  4399. }
  4400. *LCR1BRDR = lcr1_brdr_value;
  4401. *MiscCtrl = misc_ctrl_value;
  4402. }
  4403. sca_init(info->port_array[0]);
  4404. sca_init(info->port_array[2]);
  4405. return TRUE;
  4406. }
  4407. /* Loopback an HDLC frame to test the hardware
  4408. * interrupt and DMA functions.
  4409. */
  4410. int loopback_test(SLMP_INFO *info)
  4411. {
  4412. #define TESTFRAMESIZE 20
  4413. unsigned long timeout;
  4414. u16 count = TESTFRAMESIZE;
  4415. unsigned char buf[TESTFRAMESIZE];
  4416. int rc = FALSE;
  4417. unsigned long flags;
  4418. struct tty_struct *oldtty = info->tty;
  4419. u32 speed = info->params.clock_speed;
  4420. info->params.clock_speed = 3686400;
  4421. info->tty = NULL;
  4422. /* assume failure */
  4423. info->init_error = DiagStatus_DmaFailure;
  4424. /* build and send transmit frame */
  4425. for (count = 0; count < TESTFRAMESIZE;++count)
  4426. buf[count] = (unsigned char)count;
  4427. memset(info->tmp_rx_buf,0,TESTFRAMESIZE);
  4428. /* program hardware for HDLC and enabled receiver */
  4429. spin_lock_irqsave(&info->lock,flags);
  4430. hdlc_mode(info);
  4431. enable_loopback(info,1);
  4432. rx_start(info);
  4433. info->tx_count = count;
  4434. tx_load_dma_buffer(info,buf,count);
  4435. tx_start(info);
  4436. spin_unlock_irqrestore(&info->lock,flags);
  4437. /* wait for receive complete */
  4438. /* Set a timeout for waiting for interrupt. */
  4439. for ( timeout = 100; timeout; --timeout ) {
  4440. msleep_interruptible(10);
  4441. if (rx_get_frame(info)) {
  4442. rc = TRUE;
  4443. break;
  4444. }
  4445. }
  4446. /* verify received frame length and contents */
  4447. if (rc == TRUE &&
  4448. ( info->tmp_rx_buf_count != count ||
  4449. memcmp(buf, info->tmp_rx_buf,count))) {
  4450. rc = FALSE;
  4451. }
  4452. spin_lock_irqsave(&info->lock,flags);
  4453. reset_adapter(info);
  4454. spin_unlock_irqrestore(&info->lock,flags);
  4455. info->params.clock_speed = speed;
  4456. info->tty = oldtty;
  4457. return rc;
  4458. }
  4459. /* Perform diagnostics on hardware
  4460. */
  4461. int adapter_test( SLMP_INFO *info )
  4462. {
  4463. unsigned long flags;
  4464. if ( debug_level >= DEBUG_LEVEL_INFO )
  4465. printk( "%s(%d):Testing device %s\n",
  4466. __FILE__,__LINE__,info->device_name );
  4467. spin_lock_irqsave(&info->lock,flags);
  4468. init_adapter(info);
  4469. spin_unlock_irqrestore(&info->lock,flags);
  4470. info->port_array[0]->port_count = 0;
  4471. if ( register_test(info->port_array[0]) &&
  4472. register_test(info->port_array[1])) {
  4473. info->port_array[0]->port_count = 2;
  4474. if ( register_test(info->port_array[2]) &&
  4475. register_test(info->port_array[3]) )
  4476. info->port_array[0]->port_count += 2;
  4477. }
  4478. else {
  4479. printk( "%s(%d):Register test failure for device %s Addr=%08lX\n",
  4480. __FILE__,__LINE__,info->device_name, (unsigned long)(info->phys_sca_base));
  4481. return -ENODEV;
  4482. }
  4483. if ( !irq_test(info->port_array[0]) ||
  4484. !irq_test(info->port_array[1]) ||
  4485. (info->port_count == 4 && !irq_test(info->port_array[2])) ||
  4486. (info->port_count == 4 && !irq_test(info->port_array[3]))) {
  4487. printk( "%s(%d):Interrupt test failure for device %s IRQ=%d\n",
  4488. __FILE__,__LINE__,info->device_name, (unsigned short)(info->irq_level) );
  4489. return -ENODEV;
  4490. }
  4491. if (!loopback_test(info->port_array[0]) ||
  4492. !loopback_test(info->port_array[1]) ||
  4493. (info->port_count == 4 && !loopback_test(info->port_array[2])) ||
  4494. (info->port_count == 4 && !loopback_test(info->port_array[3]))) {
  4495. printk( "%s(%d):DMA test failure for device %s\n",
  4496. __FILE__,__LINE__,info->device_name);
  4497. return -ENODEV;
  4498. }
  4499. if ( debug_level >= DEBUG_LEVEL_INFO )
  4500. printk( "%s(%d):device %s passed diagnostics\n",
  4501. __FILE__,__LINE__,info->device_name );
  4502. info->port_array[0]->init_error = 0;
  4503. info->port_array[1]->init_error = 0;
  4504. if ( info->port_count > 2 ) {
  4505. info->port_array[2]->init_error = 0;
  4506. info->port_array[3]->init_error = 0;
  4507. }
  4508. return 0;
  4509. }
  4510. /* Test the shared memory on a PCI adapter.
  4511. */
  4512. int memory_test(SLMP_INFO *info)
  4513. {
  4514. static unsigned long testval[] = { 0x0, 0x55555555, 0xaaaaaaaa,
  4515. 0x66666666, 0x99999999, 0xffffffff, 0x12345678 };
  4516. unsigned long count = sizeof(testval)/sizeof(unsigned long);
  4517. unsigned long i;
  4518. unsigned long limit = SCA_MEM_SIZE/sizeof(unsigned long);
  4519. unsigned long * addr = (unsigned long *)info->memory_base;
  4520. /* Test data lines with test pattern at one location. */
  4521. for ( i = 0 ; i < count ; i++ ) {
  4522. *addr = testval[i];
  4523. if ( *addr != testval[i] )
  4524. return FALSE;
  4525. }
  4526. /* Test address lines with incrementing pattern over */
  4527. /* entire address range. */
  4528. for ( i = 0 ; i < limit ; i++ ) {
  4529. *addr = i * 4;
  4530. addr++;
  4531. }
  4532. addr = (unsigned long *)info->memory_base;
  4533. for ( i = 0 ; i < limit ; i++ ) {
  4534. if ( *addr != i * 4 )
  4535. return FALSE;
  4536. addr++;
  4537. }
  4538. memset( info->memory_base, 0, SCA_MEM_SIZE );
  4539. return TRUE;
  4540. }
  4541. /* Load data into PCI adapter shared memory.
  4542. *
  4543. * The PCI9050 releases control of the local bus
  4544. * after completing the current read or write operation.
  4545. *
  4546. * While the PCI9050 write FIFO not empty, the
  4547. * PCI9050 treats all of the writes as a single transaction
  4548. * and does not release the bus. This causes DMA latency problems
  4549. * at high speeds when copying large data blocks to the shared memory.
  4550. *
  4551. * This function breaks a write into multiple transations by
  4552. * interleaving a read which flushes the write FIFO and 'completes'
  4553. * the write transation. This allows any pending DMA request to gain control
  4554. * of the local bus in a timely fasion.
  4555. */
  4556. void load_pci_memory(SLMP_INFO *info, char* dest, const char* src, unsigned short count)
  4557. {
  4558. /* A load interval of 16 allows for 4 32-bit writes at */
  4559. /* 136ns each for a maximum latency of 542ns on the local bus.*/
  4560. unsigned short interval = count / sca_pci_load_interval;
  4561. unsigned short i;
  4562. for ( i = 0 ; i < interval ; i++ )
  4563. {
  4564. memcpy(dest, src, sca_pci_load_interval);
  4565. read_status_reg(info);
  4566. dest += sca_pci_load_interval;
  4567. src += sca_pci_load_interval;
  4568. }
  4569. memcpy(dest, src, count % sca_pci_load_interval);
  4570. }
  4571. void trace_block(SLMP_INFO *info,const char* data, int count, int xmit)
  4572. {
  4573. int i;
  4574. int linecount;
  4575. if (xmit)
  4576. printk("%s tx data:\n",info->device_name);
  4577. else
  4578. printk("%s rx data:\n",info->device_name);
  4579. while(count) {
  4580. if (count > 16)
  4581. linecount = 16;
  4582. else
  4583. linecount = count;
  4584. for(i=0;i<linecount;i++)
  4585. printk("%02X ",(unsigned char)data[i]);
  4586. for(;i<17;i++)
  4587. printk(" ");
  4588. for(i=0;i<linecount;i++) {
  4589. if (data[i]>=040 && data[i]<=0176)
  4590. printk("%c",data[i]);
  4591. else
  4592. printk(".");
  4593. }
  4594. printk("\n");
  4595. data += linecount;
  4596. count -= linecount;
  4597. }
  4598. } /* end of trace_block() */
  4599. /* called when HDLC frame times out
  4600. * update stats and do tx completion processing
  4601. */
  4602. void tx_timeout(unsigned long context)
  4603. {
  4604. SLMP_INFO *info = (SLMP_INFO*)context;
  4605. unsigned long flags;
  4606. if ( debug_level >= DEBUG_LEVEL_INFO )
  4607. printk( "%s(%d):%s tx_timeout()\n",
  4608. __FILE__,__LINE__,info->device_name);
  4609. if(info->tx_active && info->params.mode == MGSL_MODE_HDLC) {
  4610. info->icount.txtimeout++;
  4611. }
  4612. spin_lock_irqsave(&info->lock,flags);
  4613. info->tx_active = 0;
  4614. info->tx_count = info->tx_put = info->tx_get = 0;
  4615. spin_unlock_irqrestore(&info->lock,flags);
  4616. #ifdef CONFIG_HDLC
  4617. if (info->netcount)
  4618. hdlcdev_tx_done(info);
  4619. else
  4620. #endif
  4621. bh_transmit(info);
  4622. }
  4623. /* called to periodically check the DSR/RI modem signal input status
  4624. */
  4625. void status_timeout(unsigned long context)
  4626. {
  4627. u16 status = 0;
  4628. SLMP_INFO *info = (SLMP_INFO*)context;
  4629. unsigned long flags;
  4630. unsigned char delta;
  4631. spin_lock_irqsave(&info->lock,flags);
  4632. get_signals(info);
  4633. spin_unlock_irqrestore(&info->lock,flags);
  4634. /* check for DSR/RI state change */
  4635. delta = info->old_signals ^ info->serial_signals;
  4636. info->old_signals = info->serial_signals;
  4637. if (delta & SerialSignal_DSR)
  4638. status |= MISCSTATUS_DSR_LATCHED|(info->serial_signals&SerialSignal_DSR);
  4639. if (delta & SerialSignal_RI)
  4640. status |= MISCSTATUS_RI_LATCHED|(info->serial_signals&SerialSignal_RI);
  4641. if (delta & SerialSignal_DCD)
  4642. status |= MISCSTATUS_DCD_LATCHED|(info->serial_signals&SerialSignal_DCD);
  4643. if (delta & SerialSignal_CTS)
  4644. status |= MISCSTATUS_CTS_LATCHED|(info->serial_signals&SerialSignal_CTS);
  4645. if (status)
  4646. isr_io_pin(info,status);
  4647. info->status_timer.data = (unsigned long)info;
  4648. info->status_timer.function = status_timeout;
  4649. info->status_timer.expires = jiffies + msecs_to_jiffies(10);
  4650. add_timer(&info->status_timer);
  4651. }
  4652. /* Register Access Routines -
  4653. * All registers are memory mapped
  4654. */
  4655. #define CALC_REGADDR() \
  4656. unsigned char * RegAddr = (unsigned char*)(info->sca_base + Addr); \
  4657. if (info->port_num > 1) \
  4658. RegAddr += 256; /* port 0-1 SCA0, 2-3 SCA1 */ \
  4659. if ( info->port_num & 1) { \
  4660. if (Addr > 0x7f) \
  4661. RegAddr += 0x40; /* DMA access */ \
  4662. else if (Addr > 0x1f && Addr < 0x60) \
  4663. RegAddr += 0x20; /* MSCI access */ \
  4664. }
  4665. unsigned char read_reg(SLMP_INFO * info, unsigned char Addr)
  4666. {
  4667. CALC_REGADDR();
  4668. return *RegAddr;
  4669. }
  4670. void write_reg(SLMP_INFO * info, unsigned char Addr, unsigned char Value)
  4671. {
  4672. CALC_REGADDR();
  4673. *RegAddr = Value;
  4674. }
  4675. u16 read_reg16(SLMP_INFO * info, unsigned char Addr)
  4676. {
  4677. CALC_REGADDR();
  4678. return *((u16 *)RegAddr);
  4679. }
  4680. void write_reg16(SLMP_INFO * info, unsigned char Addr, u16 Value)
  4681. {
  4682. CALC_REGADDR();
  4683. *((u16 *)RegAddr) = Value;
  4684. }
  4685. unsigned char read_status_reg(SLMP_INFO * info)
  4686. {
  4687. unsigned char *RegAddr = (unsigned char *)info->statctrl_base;
  4688. return *RegAddr;
  4689. }
  4690. void write_control_reg(SLMP_INFO * info)
  4691. {
  4692. unsigned char *RegAddr = (unsigned char *)info->statctrl_base;
  4693. *RegAddr = info->port_array[0]->ctrlreg_value;
  4694. }
  4695. static int __devinit synclinkmp_init_one (struct pci_dev *dev,
  4696. const struct pci_device_id *ent)
  4697. {
  4698. if (pci_enable_device(dev)) {
  4699. printk("error enabling pci device %p\n", dev);
  4700. return -EIO;
  4701. }
  4702. device_init( ++synclinkmp_adapter_count, dev );
  4703. return 0;
  4704. }
  4705. static void __devexit synclinkmp_remove_one (struct pci_dev *dev)
  4706. {
  4707. }