synclinkmp.c 148 KB

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