synclinkmp.c 148 KB

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