synclinkmp.c 147 KB

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