synclinkmp.c 149 KB

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