stallion.c 131 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116
  1. /*****************************************************************************/
  2. /*
  3. * stallion.c -- stallion multiport serial driver.
  4. *
  5. * Copyright (C) 1996-1999 Stallion Technologies
  6. * Copyright (C) 1994-1996 Greg Ungerer.
  7. *
  8. * This code is loosely based on the Linux serial driver, written by
  9. * Linus Torvalds, Theodore T'so and others.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  24. */
  25. /*****************************************************************************/
  26. #include <linux/config.h>
  27. #include <linux/module.h>
  28. #include <linux/slab.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/tty.h>
  31. #include <linux/tty_flip.h>
  32. #include <linux/serial.h>
  33. #include <linux/cd1400.h>
  34. #include <linux/sc26198.h>
  35. #include <linux/comstats.h>
  36. #include <linux/stallion.h>
  37. #include <linux/ioport.h>
  38. #include <linux/init.h>
  39. #include <linux/smp_lock.h>
  40. #include <linux/device.h>
  41. #include <linux/delay.h>
  42. #include <asm/io.h>
  43. #include <asm/uaccess.h>
  44. #ifdef CONFIG_PCI
  45. #include <linux/pci.h>
  46. #endif
  47. /*****************************************************************************/
  48. /*
  49. * Define different board types. Use the standard Stallion "assigned"
  50. * board numbers. Boards supported in this driver are abbreviated as
  51. * EIO = EasyIO and ECH = EasyConnection 8/32.
  52. */
  53. #define BRD_EASYIO 20
  54. #define BRD_ECH 21
  55. #define BRD_ECHMC 22
  56. #define BRD_ECHPCI 26
  57. #define BRD_ECH64PCI 27
  58. #define BRD_EASYIOPCI 28
  59. /*
  60. * Define a configuration structure to hold the board configuration.
  61. * Need to set this up in the code (for now) with the boards that are
  62. * to be configured into the system. This is what needs to be modified
  63. * when adding/removing/modifying boards. Each line entry in the
  64. * stl_brdconf[] array is a board. Each line contains io/irq/memory
  65. * ranges for that board (as well as what type of board it is).
  66. * Some examples:
  67. * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
  68. * This line would configure an EasyIO board (4 or 8, no difference),
  69. * at io address 2a0 and irq 10.
  70. * Another example:
  71. * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
  72. * This line will configure an EasyConnection 8/32 board at primary io
  73. * address 2a8, secondary io address 280 and irq 12.
  74. * Enter as many lines into this array as you want (only the first 4
  75. * will actually be used!). Any combination of EasyIO and EasyConnection
  76. * boards can be specified. EasyConnection 8/32 boards can share their
  77. * secondary io addresses between each other.
  78. *
  79. * NOTE: there is no need to put any entries in this table for PCI
  80. * boards. They will be found automatically by the driver - provided
  81. * PCI BIOS32 support is compiled into the kernel.
  82. */
  83. typedef struct {
  84. int brdtype;
  85. int ioaddr1;
  86. int ioaddr2;
  87. unsigned long memaddr;
  88. int irq;
  89. int irqtype;
  90. } stlconf_t;
  91. static stlconf_t stl_brdconf[] = {
  92. /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
  93. };
  94. static int stl_nrbrds = ARRAY_SIZE(stl_brdconf);
  95. /*****************************************************************************/
  96. /*
  97. * Define some important driver characteristics. Device major numbers
  98. * allocated as per Linux Device Registry.
  99. */
  100. #ifndef STL_SIOMEMMAJOR
  101. #define STL_SIOMEMMAJOR 28
  102. #endif
  103. #ifndef STL_SERIALMAJOR
  104. #define STL_SERIALMAJOR 24
  105. #endif
  106. #ifndef STL_CALLOUTMAJOR
  107. #define STL_CALLOUTMAJOR 25
  108. #endif
  109. /*
  110. * Set the TX buffer size. Bigger is better, but we don't want
  111. * to chew too much memory with buffers!
  112. */
  113. #define STL_TXBUFLOW 512
  114. #define STL_TXBUFSIZE 4096
  115. /*****************************************************************************/
  116. /*
  117. * Define our local driver identity first. Set up stuff to deal with
  118. * all the local structures required by a serial tty driver.
  119. */
  120. static char *stl_drvtitle = "Stallion Multiport Serial Driver";
  121. static char *stl_drvname = "stallion";
  122. static char *stl_drvversion = "5.6.0";
  123. static struct tty_driver *stl_serial;
  124. /*
  125. * Define a local default termios struct. All ports will be created
  126. * with this termios initially. Basically all it defines is a raw port
  127. * at 9600, 8 data bits, 1 stop bit.
  128. */
  129. static struct termios stl_deftermios = {
  130. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  131. .c_cc = INIT_C_CC,
  132. };
  133. /*
  134. * Define global stats structures. Not used often, and can be
  135. * re-used for each stats call.
  136. */
  137. static comstats_t stl_comstats;
  138. static combrd_t stl_brdstats;
  139. static stlbrd_t stl_dummybrd;
  140. static stlport_t stl_dummyport;
  141. /*
  142. * Define global place to put buffer overflow characters.
  143. */
  144. static char stl_unwanted[SC26198_RXFIFOSIZE];
  145. /*****************************************************************************/
  146. static stlbrd_t *stl_brds[STL_MAXBRDS];
  147. /*
  148. * Per board state flags. Used with the state field of the board struct.
  149. * Not really much here!
  150. */
  151. #define BRD_FOUND 0x1
  152. /*
  153. * Define the port structure istate flags. These set of flags are
  154. * modified at interrupt time - so setting and reseting them needs
  155. * to be atomic. Use the bit clear/setting routines for this.
  156. */
  157. #define ASYI_TXBUSY 1
  158. #define ASYI_TXLOW 2
  159. #define ASYI_DCDCHANGE 3
  160. #define ASYI_TXFLOWED 4
  161. /*
  162. * Define an array of board names as printable strings. Handy for
  163. * referencing boards when printing trace and stuff.
  164. */
  165. static char *stl_brdnames[] = {
  166. (char *) NULL,
  167. (char *) NULL,
  168. (char *) NULL,
  169. (char *) NULL,
  170. (char *) NULL,
  171. (char *) NULL,
  172. (char *) NULL,
  173. (char *) NULL,
  174. (char *) NULL,
  175. (char *) NULL,
  176. (char *) NULL,
  177. (char *) NULL,
  178. (char *) NULL,
  179. (char *) NULL,
  180. (char *) NULL,
  181. (char *) NULL,
  182. (char *) NULL,
  183. (char *) NULL,
  184. (char *) NULL,
  185. (char *) NULL,
  186. "EasyIO",
  187. "EC8/32-AT",
  188. "EC8/32-MC",
  189. (char *) NULL,
  190. (char *) NULL,
  191. (char *) NULL,
  192. "EC8/32-PCI",
  193. "EC8/64-PCI",
  194. "EasyIO-PCI",
  195. };
  196. /*****************************************************************************/
  197. /*
  198. * Define some string labels for arguments passed from the module
  199. * load line. These allow for easy board definitions, and easy
  200. * modification of the io, memory and irq resoucres.
  201. */
  202. static int stl_nargs = 0;
  203. static char *board0[4];
  204. static char *board1[4];
  205. static char *board2[4];
  206. static char *board3[4];
  207. static char **stl_brdsp[] = {
  208. (char **) &board0,
  209. (char **) &board1,
  210. (char **) &board2,
  211. (char **) &board3
  212. };
  213. /*
  214. * Define a set of common board names, and types. This is used to
  215. * parse any module arguments.
  216. */
  217. typedef struct stlbrdtype {
  218. char *name;
  219. int type;
  220. } stlbrdtype_t;
  221. static stlbrdtype_t stl_brdstr[] = {
  222. { "easyio", BRD_EASYIO },
  223. { "eio", BRD_EASYIO },
  224. { "20", BRD_EASYIO },
  225. { "ec8/32", BRD_ECH },
  226. { "ec8/32-at", BRD_ECH },
  227. { "ec8/32-isa", BRD_ECH },
  228. { "ech", BRD_ECH },
  229. { "echat", BRD_ECH },
  230. { "21", BRD_ECH },
  231. { "ec8/32-mc", BRD_ECHMC },
  232. { "ec8/32-mca", BRD_ECHMC },
  233. { "echmc", BRD_ECHMC },
  234. { "echmca", BRD_ECHMC },
  235. { "22", BRD_ECHMC },
  236. { "ec8/32-pc", BRD_ECHPCI },
  237. { "ec8/32-pci", BRD_ECHPCI },
  238. { "26", BRD_ECHPCI },
  239. { "ec8/64-pc", BRD_ECH64PCI },
  240. { "ec8/64-pci", BRD_ECH64PCI },
  241. { "ech-pci", BRD_ECH64PCI },
  242. { "echpci", BRD_ECH64PCI },
  243. { "echpc", BRD_ECH64PCI },
  244. { "27", BRD_ECH64PCI },
  245. { "easyio-pc", BRD_EASYIOPCI },
  246. { "easyio-pci", BRD_EASYIOPCI },
  247. { "eio-pci", BRD_EASYIOPCI },
  248. { "eiopci", BRD_EASYIOPCI },
  249. { "28", BRD_EASYIOPCI },
  250. };
  251. /*
  252. * Define the module agruments.
  253. */
  254. MODULE_AUTHOR("Greg Ungerer");
  255. MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
  256. MODULE_LICENSE("GPL");
  257. module_param_array(board0, charp, &stl_nargs, 0);
  258. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
  259. module_param_array(board1, charp, &stl_nargs, 0);
  260. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
  261. module_param_array(board2, charp, &stl_nargs, 0);
  262. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
  263. module_param_array(board3, charp, &stl_nargs, 0);
  264. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
  265. /*****************************************************************************/
  266. /*
  267. * Hardware ID bits for the EasyIO and ECH boards. These defines apply
  268. * to the directly accessible io ports of these boards (not the uarts -
  269. * they are in cd1400.h and sc26198.h).
  270. */
  271. #define EIO_8PORTRS 0x04
  272. #define EIO_4PORTRS 0x05
  273. #define EIO_8PORTDI 0x00
  274. #define EIO_8PORTM 0x06
  275. #define EIO_MK3 0x03
  276. #define EIO_IDBITMASK 0x07
  277. #define EIO_BRDMASK 0xf0
  278. #define ID_BRD4 0x10
  279. #define ID_BRD8 0x20
  280. #define ID_BRD16 0x30
  281. #define EIO_INTRPEND 0x08
  282. #define EIO_INTEDGE 0x00
  283. #define EIO_INTLEVEL 0x08
  284. #define EIO_0WS 0x10
  285. #define ECH_ID 0xa0
  286. #define ECH_IDBITMASK 0xe0
  287. #define ECH_BRDENABLE 0x08
  288. #define ECH_BRDDISABLE 0x00
  289. #define ECH_INTENABLE 0x01
  290. #define ECH_INTDISABLE 0x00
  291. #define ECH_INTLEVEL 0x02
  292. #define ECH_INTEDGE 0x00
  293. #define ECH_INTRPEND 0x01
  294. #define ECH_BRDRESET 0x01
  295. #define ECHMC_INTENABLE 0x01
  296. #define ECHMC_BRDRESET 0x02
  297. #define ECH_PNLSTATUS 2
  298. #define ECH_PNL16PORT 0x20
  299. #define ECH_PNLIDMASK 0x07
  300. #define ECH_PNLXPID 0x40
  301. #define ECH_PNLINTRPEND 0x80
  302. #define ECH_ADDR2MASK 0x1e0
  303. /*
  304. * Define the vector mapping bits for the programmable interrupt board
  305. * hardware. These bits encode the interrupt for the board to use - it
  306. * is software selectable (except the EIO-8M).
  307. */
  308. static unsigned char stl_vecmap[] = {
  309. 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
  310. 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
  311. };
  312. /*
  313. * Lock ordering is that you may not take stallion_lock holding
  314. * brd_lock.
  315. */
  316. static spinlock_t brd_lock; /* Guard the board mapping */
  317. static spinlock_t stallion_lock; /* Guard the tty driver */
  318. /*
  319. * Set up enable and disable macros for the ECH boards. They require
  320. * the secondary io address space to be activated and deactivated.
  321. * This way all ECH boards can share their secondary io region.
  322. * If this is an ECH-PCI board then also need to set the page pointer
  323. * to point to the correct page.
  324. */
  325. #define BRDENABLE(brdnr,pagenr) \
  326. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  327. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
  328. stl_brds[(brdnr)]->ioctrl); \
  329. else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
  330. outb((pagenr), stl_brds[(brdnr)]->ioctrl);
  331. #define BRDDISABLE(brdnr) \
  332. if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
  333. outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
  334. stl_brds[(brdnr)]->ioctrl);
  335. #define STL_CD1400MAXBAUD 230400
  336. #define STL_SC26198MAXBAUD 460800
  337. #define STL_BAUDBASE 115200
  338. #define STL_CLOSEDELAY (5 * HZ / 10)
  339. /*****************************************************************************/
  340. #ifdef CONFIG_PCI
  341. /*
  342. * Define the Stallion PCI vendor and device IDs.
  343. */
  344. #ifndef PCI_VENDOR_ID_STALLION
  345. #define PCI_VENDOR_ID_STALLION 0x124d
  346. #endif
  347. #ifndef PCI_DEVICE_ID_ECHPCI832
  348. #define PCI_DEVICE_ID_ECHPCI832 0x0000
  349. #endif
  350. #ifndef PCI_DEVICE_ID_ECHPCI864
  351. #define PCI_DEVICE_ID_ECHPCI864 0x0002
  352. #endif
  353. #ifndef PCI_DEVICE_ID_EIOPCI
  354. #define PCI_DEVICE_ID_EIOPCI 0x0003
  355. #endif
  356. /*
  357. * Define structure to hold all Stallion PCI boards.
  358. */
  359. typedef struct stlpcibrd {
  360. unsigned short vendid;
  361. unsigned short devid;
  362. int brdtype;
  363. } stlpcibrd_t;
  364. static stlpcibrd_t stl_pcibrds[] = {
  365. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
  366. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
  367. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
  368. { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
  369. };
  370. static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
  371. #endif
  372. /*****************************************************************************/
  373. /*
  374. * Define macros to extract a brd/port number from a minor number.
  375. */
  376. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  377. #define MINOR2PORT(min) ((min) & 0x3f)
  378. /*
  379. * Define a baud rate table that converts termios baud rate selector
  380. * into the actual baud rate value. All baud rate calculations are
  381. * based on the actual baud rate required.
  382. */
  383. static unsigned int stl_baudrates[] = {
  384. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  385. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
  386. };
  387. /*
  388. * Define some handy local macros...
  389. */
  390. #undef MIN
  391. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  392. #undef TOLOWER
  393. #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
  394. /*****************************************************************************/
  395. /*
  396. * Declare all those functions in this driver!
  397. */
  398. static void stl_argbrds(void);
  399. static int stl_parsebrd(stlconf_t *confp, char **argp);
  400. static unsigned long stl_atol(char *str);
  401. static int stl_init(void);
  402. static int stl_open(struct tty_struct *tty, struct file *filp);
  403. static void stl_close(struct tty_struct *tty, struct file *filp);
  404. static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
  405. static void stl_putchar(struct tty_struct *tty, unsigned char ch);
  406. static void stl_flushchars(struct tty_struct *tty);
  407. static int stl_writeroom(struct tty_struct *tty);
  408. static int stl_charsinbuffer(struct tty_struct *tty);
  409. static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  410. static void stl_settermios(struct tty_struct *tty, struct termios *old);
  411. static void stl_throttle(struct tty_struct *tty);
  412. static void stl_unthrottle(struct tty_struct *tty);
  413. static void stl_stop(struct tty_struct *tty);
  414. static void stl_start(struct tty_struct *tty);
  415. static void stl_flushbuffer(struct tty_struct *tty);
  416. static void stl_breakctl(struct tty_struct *tty, int state);
  417. static void stl_waituntilsent(struct tty_struct *tty, int timeout);
  418. static void stl_sendxchar(struct tty_struct *tty, char ch);
  419. static void stl_hangup(struct tty_struct *tty);
  420. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
  421. static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
  422. static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
  423. static int stl_brdinit(stlbrd_t *brdp);
  424. static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
  425. static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
  426. static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
  427. static int stl_getbrdstats(combrd_t __user *bp);
  428. static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
  429. static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
  430. static int stl_getportstruct(stlport_t __user *arg);
  431. static int stl_getbrdstruct(stlbrd_t __user *arg);
  432. static int stl_waitcarrier(stlport_t *portp, struct file *filp);
  433. static int stl_eiointr(stlbrd_t *brdp);
  434. static int stl_echatintr(stlbrd_t *brdp);
  435. static int stl_echmcaintr(stlbrd_t *brdp);
  436. static int stl_echpciintr(stlbrd_t *brdp);
  437. static int stl_echpci64intr(stlbrd_t *brdp);
  438. static void stl_offintr(void *private);
  439. static stlbrd_t *stl_allocbrd(void);
  440. static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
  441. static inline int stl_initbrds(void);
  442. static inline int stl_initeio(stlbrd_t *brdp);
  443. static inline int stl_initech(stlbrd_t *brdp);
  444. static inline int stl_getbrdnr(void);
  445. #ifdef CONFIG_PCI
  446. static inline int stl_findpcibrds(void);
  447. static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
  448. #endif
  449. /*
  450. * CD1400 uart specific handling functions.
  451. */
  452. static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
  453. static int stl_cd1400getreg(stlport_t *portp, int regnr);
  454. static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
  455. static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
  456. static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  457. static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
  458. static int stl_cd1400getsignals(stlport_t *portp);
  459. static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
  460. static void stl_cd1400ccrwait(stlport_t *portp);
  461. static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
  462. static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
  463. static void stl_cd1400disableintrs(stlport_t *portp);
  464. static void stl_cd1400sendbreak(stlport_t *portp, int len);
  465. static void stl_cd1400flowctrl(stlport_t *portp, int state);
  466. static void stl_cd1400sendflow(stlport_t *portp, int state);
  467. static void stl_cd1400flush(stlport_t *portp);
  468. static int stl_cd1400datastate(stlport_t *portp);
  469. static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
  470. static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
  471. static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
  472. static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
  473. static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
  474. static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
  475. /*
  476. * SC26198 uart specific handling functions.
  477. */
  478. static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
  479. static int stl_sc26198getreg(stlport_t *portp, int regnr);
  480. static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
  481. static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
  482. static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
  483. static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  484. static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
  485. static int stl_sc26198getsignals(stlport_t *portp);
  486. static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
  487. static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
  488. static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
  489. static void stl_sc26198disableintrs(stlport_t *portp);
  490. static void stl_sc26198sendbreak(stlport_t *portp, int len);
  491. static void stl_sc26198flowctrl(stlport_t *portp, int state);
  492. static void stl_sc26198sendflow(stlport_t *portp, int state);
  493. static void stl_sc26198flush(stlport_t *portp);
  494. static int stl_sc26198datastate(stlport_t *portp);
  495. static void stl_sc26198wait(stlport_t *portp);
  496. static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
  497. static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
  498. static void stl_sc26198txisr(stlport_t *port);
  499. static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
  500. static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
  501. static void stl_sc26198rxbadchars(stlport_t *portp);
  502. static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
  503. /*****************************************************************************/
  504. /*
  505. * Generic UART support structure.
  506. */
  507. typedef struct uart {
  508. int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
  509. void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
  510. void (*setport)(stlport_t *portp, struct termios *tiosp);
  511. int (*getsignals)(stlport_t *portp);
  512. void (*setsignals)(stlport_t *portp, int dtr, int rts);
  513. void (*enablerxtx)(stlport_t *portp, int rx, int tx);
  514. void (*startrxtx)(stlport_t *portp, int rx, int tx);
  515. void (*disableintrs)(stlport_t *portp);
  516. void (*sendbreak)(stlport_t *portp, int len);
  517. void (*flowctrl)(stlport_t *portp, int state);
  518. void (*sendflow)(stlport_t *portp, int state);
  519. void (*flush)(stlport_t *portp);
  520. int (*datastate)(stlport_t *portp);
  521. void (*intr)(stlpanel_t *panelp, unsigned int iobase);
  522. } uart_t;
  523. /*
  524. * Define some macros to make calling these functions nice and clean.
  525. */
  526. #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
  527. #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
  528. #define stl_setport (* ((uart_t *) portp->uartp)->setport)
  529. #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
  530. #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
  531. #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
  532. #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
  533. #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
  534. #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
  535. #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
  536. #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
  537. #define stl_flush (* ((uart_t *) portp->uartp)->flush)
  538. #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
  539. /*****************************************************************************/
  540. /*
  541. * CD1400 UART specific data initialization.
  542. */
  543. static uart_t stl_cd1400uart = {
  544. stl_cd1400panelinit,
  545. stl_cd1400portinit,
  546. stl_cd1400setport,
  547. stl_cd1400getsignals,
  548. stl_cd1400setsignals,
  549. stl_cd1400enablerxtx,
  550. stl_cd1400startrxtx,
  551. stl_cd1400disableintrs,
  552. stl_cd1400sendbreak,
  553. stl_cd1400flowctrl,
  554. stl_cd1400sendflow,
  555. stl_cd1400flush,
  556. stl_cd1400datastate,
  557. stl_cd1400eiointr
  558. };
  559. /*
  560. * Define the offsets within the register bank of a cd1400 based panel.
  561. * These io address offsets are common to the EasyIO board as well.
  562. */
  563. #define EREG_ADDR 0
  564. #define EREG_DATA 4
  565. #define EREG_RXACK 5
  566. #define EREG_TXACK 6
  567. #define EREG_MDACK 7
  568. #define EREG_BANKSIZE 8
  569. #define CD1400_CLK 25000000
  570. #define CD1400_CLK8M 20000000
  571. /*
  572. * Define the cd1400 baud rate clocks. These are used when calculating
  573. * what clock and divisor to use for the required baud rate. Also
  574. * define the maximum baud rate allowed, and the default base baud.
  575. */
  576. static int stl_cd1400clkdivs[] = {
  577. CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
  578. };
  579. /*****************************************************************************/
  580. /*
  581. * SC26198 UART specific data initization.
  582. */
  583. static uart_t stl_sc26198uart = {
  584. stl_sc26198panelinit,
  585. stl_sc26198portinit,
  586. stl_sc26198setport,
  587. stl_sc26198getsignals,
  588. stl_sc26198setsignals,
  589. stl_sc26198enablerxtx,
  590. stl_sc26198startrxtx,
  591. stl_sc26198disableintrs,
  592. stl_sc26198sendbreak,
  593. stl_sc26198flowctrl,
  594. stl_sc26198sendflow,
  595. stl_sc26198flush,
  596. stl_sc26198datastate,
  597. stl_sc26198intr
  598. };
  599. /*
  600. * Define the offsets within the register bank of a sc26198 based panel.
  601. */
  602. #define XP_DATA 0
  603. #define XP_ADDR 1
  604. #define XP_MODID 2
  605. #define XP_STATUS 2
  606. #define XP_IACK 3
  607. #define XP_BANKSIZE 4
  608. /*
  609. * Define the sc26198 baud rate table. Offsets within the table
  610. * represent the actual baud rate selector of sc26198 registers.
  611. */
  612. static unsigned int sc26198_baudtable[] = {
  613. 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
  614. 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
  615. 230400, 460800, 921600
  616. };
  617. #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
  618. /*****************************************************************************/
  619. /*
  620. * Define the driver info for a user level control device. Used mainly
  621. * to get at port stats - only not using the port device itself.
  622. */
  623. static struct file_operations stl_fsiomem = {
  624. .owner = THIS_MODULE,
  625. .ioctl = stl_memioctl,
  626. };
  627. /*****************************************************************************/
  628. static struct class *stallion_class;
  629. /*
  630. * Loadable module initialization stuff.
  631. */
  632. static int __init stallion_module_init(void)
  633. {
  634. stl_init();
  635. return 0;
  636. }
  637. /*****************************************************************************/
  638. static void __exit stallion_module_exit(void)
  639. {
  640. stlbrd_t *brdp;
  641. stlpanel_t *panelp;
  642. stlport_t *portp;
  643. int i, j, k;
  644. #ifdef DEBUG
  645. printk("cleanup_module()\n");
  646. #endif
  647. printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
  648. stl_drvversion);
  649. /*
  650. * Free up all allocated resources used by the ports. This includes
  651. * memory and interrupts. As part of this process we will also do
  652. * a hangup on every open port - to try to flush out any processes
  653. * hanging onto ports.
  654. */
  655. i = tty_unregister_driver(stl_serial);
  656. put_tty_driver(stl_serial);
  657. if (i) {
  658. printk("STALLION: failed to un-register tty driver, "
  659. "errno=%d\n", -i);
  660. return;
  661. }
  662. for (i = 0; i < 4; i++)
  663. class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
  664. if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
  665. printk("STALLION: failed to un-register serial memory device, "
  666. "errno=%d\n", -i);
  667. class_destroy(stallion_class);
  668. for (i = 0; (i < stl_nrbrds); i++) {
  669. if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
  670. continue;
  671. free_irq(brdp->irq, brdp);
  672. for (j = 0; (j < STL_MAXPANELS); j++) {
  673. panelp = brdp->panels[j];
  674. if (panelp == (stlpanel_t *) NULL)
  675. continue;
  676. for (k = 0; (k < STL_PORTSPERPANEL); k++) {
  677. portp = panelp->ports[k];
  678. if (portp == (stlport_t *) NULL)
  679. continue;
  680. if (portp->tty != (struct tty_struct *) NULL)
  681. stl_hangup(portp->tty);
  682. kfree(portp->tx.buf);
  683. kfree(portp);
  684. }
  685. kfree(panelp);
  686. }
  687. release_region(brdp->ioaddr1, brdp->iosize1);
  688. if (brdp->iosize2 > 0)
  689. release_region(brdp->ioaddr2, brdp->iosize2);
  690. kfree(brdp);
  691. stl_brds[i] = (stlbrd_t *) NULL;
  692. }
  693. }
  694. module_init(stallion_module_init);
  695. module_exit(stallion_module_exit);
  696. /*****************************************************************************/
  697. /*
  698. * Check for any arguments passed in on the module load command line.
  699. */
  700. static void stl_argbrds(void)
  701. {
  702. stlconf_t conf;
  703. stlbrd_t *brdp;
  704. int i;
  705. #ifdef DEBUG
  706. printk("stl_argbrds()\n");
  707. #endif
  708. for (i = stl_nrbrds; (i < stl_nargs); i++) {
  709. memset(&conf, 0, sizeof(conf));
  710. if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
  711. continue;
  712. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  713. continue;
  714. stl_nrbrds = i + 1;
  715. brdp->brdnr = i;
  716. brdp->brdtype = conf.brdtype;
  717. brdp->ioaddr1 = conf.ioaddr1;
  718. brdp->ioaddr2 = conf.ioaddr2;
  719. brdp->irq = conf.irq;
  720. brdp->irqtype = conf.irqtype;
  721. stl_brdinit(brdp);
  722. }
  723. }
  724. /*****************************************************************************/
  725. /*
  726. * Convert an ascii string number into an unsigned long.
  727. */
  728. static unsigned long stl_atol(char *str)
  729. {
  730. unsigned long val;
  731. int base, c;
  732. char *sp;
  733. val = 0;
  734. sp = str;
  735. if ((*sp == '0') && (*(sp+1) == 'x')) {
  736. base = 16;
  737. sp += 2;
  738. } else if (*sp == '0') {
  739. base = 8;
  740. sp++;
  741. } else {
  742. base = 10;
  743. }
  744. for (; (*sp != 0); sp++) {
  745. c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
  746. if ((c < 0) || (c >= base)) {
  747. printk("STALLION: invalid argument %s\n", str);
  748. val = 0;
  749. break;
  750. }
  751. val = (val * base) + c;
  752. }
  753. return val;
  754. }
  755. /*****************************************************************************/
  756. /*
  757. * Parse the supplied argument string, into the board conf struct.
  758. */
  759. static int stl_parsebrd(stlconf_t *confp, char **argp)
  760. {
  761. char *sp;
  762. int i;
  763. #ifdef DEBUG
  764. printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
  765. #endif
  766. if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
  767. return 0;
  768. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  769. *sp = TOLOWER(*sp);
  770. for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
  771. if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
  772. break;
  773. }
  774. if (i == ARRAY_SIZE(stl_brdstr)) {
  775. printk("STALLION: unknown board name, %s?\n", argp[0]);
  776. return 0;
  777. }
  778. confp->brdtype = stl_brdstr[i].type;
  779. i = 1;
  780. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  781. confp->ioaddr1 = stl_atol(argp[i]);
  782. i++;
  783. if (confp->brdtype == BRD_ECH) {
  784. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  785. confp->ioaddr2 = stl_atol(argp[i]);
  786. i++;
  787. }
  788. if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
  789. confp->irq = stl_atol(argp[i]);
  790. return 1;
  791. }
  792. /*****************************************************************************/
  793. /*
  794. * Allocate a new board structure. Fill out the basic info in it.
  795. */
  796. static stlbrd_t *stl_allocbrd(void)
  797. {
  798. stlbrd_t *brdp;
  799. brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
  800. if (!brdp) {
  801. printk("STALLION: failed to allocate memory (size=%Zd)\n",
  802. sizeof(stlbrd_t));
  803. return NULL;
  804. }
  805. brdp->magic = STL_BOARDMAGIC;
  806. return brdp;
  807. }
  808. /*****************************************************************************/
  809. static int stl_open(struct tty_struct *tty, struct file *filp)
  810. {
  811. stlport_t *portp;
  812. stlbrd_t *brdp;
  813. unsigned int minordev;
  814. int brdnr, panelnr, portnr, rc;
  815. #ifdef DEBUG
  816. printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
  817. (int) filp, tty->name);
  818. #endif
  819. minordev = tty->index;
  820. brdnr = MINOR2BRD(minordev);
  821. if (brdnr >= stl_nrbrds)
  822. return -ENODEV;
  823. brdp = stl_brds[brdnr];
  824. if (brdp == (stlbrd_t *) NULL)
  825. return -ENODEV;
  826. minordev = MINOR2PORT(minordev);
  827. for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  828. if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
  829. break;
  830. if (minordev < brdp->panels[panelnr]->nrports) {
  831. portnr = minordev;
  832. break;
  833. }
  834. minordev -= brdp->panels[panelnr]->nrports;
  835. }
  836. if (portnr < 0)
  837. return -ENODEV;
  838. portp = brdp->panels[panelnr]->ports[portnr];
  839. if (portp == (stlport_t *) NULL)
  840. return -ENODEV;
  841. /*
  842. * On the first open of the device setup the port hardware, and
  843. * initialize the per port data structure.
  844. */
  845. portp->tty = tty;
  846. tty->driver_data = portp;
  847. portp->refcount++;
  848. if ((portp->flags & ASYNC_INITIALIZED) == 0) {
  849. if (!portp->tx.buf) {
  850. portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
  851. if (!portp->tx.buf)
  852. return -ENOMEM;
  853. portp->tx.head = portp->tx.buf;
  854. portp->tx.tail = portp->tx.buf;
  855. }
  856. stl_setport(portp, tty->termios);
  857. portp->sigs = stl_getsignals(portp);
  858. stl_setsignals(portp, 1, 1);
  859. stl_enablerxtx(portp, 1, 1);
  860. stl_startrxtx(portp, 1, 0);
  861. clear_bit(TTY_IO_ERROR, &tty->flags);
  862. portp->flags |= ASYNC_INITIALIZED;
  863. }
  864. /*
  865. * Check if this port is in the middle of closing. If so then wait
  866. * until it is closed then return error status, based on flag settings.
  867. * The sleep here does not need interrupt protection since the wakeup
  868. * for it is done with the same context.
  869. */
  870. if (portp->flags & ASYNC_CLOSING) {
  871. interruptible_sleep_on(&portp->close_wait);
  872. if (portp->flags & ASYNC_HUP_NOTIFY)
  873. return -EAGAIN;
  874. return -ERESTARTSYS;
  875. }
  876. /*
  877. * Based on type of open being done check if it can overlap with any
  878. * previous opens still in effect. If we are a normal serial device
  879. * then also we might have to wait for carrier.
  880. */
  881. if (!(filp->f_flags & O_NONBLOCK)) {
  882. if ((rc = stl_waitcarrier(portp, filp)) != 0)
  883. return rc;
  884. }
  885. portp->flags |= ASYNC_NORMAL_ACTIVE;
  886. return 0;
  887. }
  888. /*****************************************************************************/
  889. /*
  890. * Possibly need to wait for carrier (DCD signal) to come high. Say
  891. * maybe because if we are clocal then we don't need to wait...
  892. */
  893. static int stl_waitcarrier(stlport_t *portp, struct file *filp)
  894. {
  895. unsigned long flags;
  896. int rc, doclocal;
  897. #ifdef DEBUG
  898. printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
  899. #endif
  900. rc = 0;
  901. doclocal = 0;
  902. spin_lock_irqsave(&stallion_lock, flags);
  903. if (portp->tty->termios->c_cflag & CLOCAL)
  904. doclocal++;
  905. portp->openwaitcnt++;
  906. if (! tty_hung_up_p(filp))
  907. portp->refcount--;
  908. for (;;) {
  909. /* Takes brd_lock internally */
  910. stl_setsignals(portp, 1, 1);
  911. if (tty_hung_up_p(filp) ||
  912. ((portp->flags & ASYNC_INITIALIZED) == 0)) {
  913. if (portp->flags & ASYNC_HUP_NOTIFY)
  914. rc = -EBUSY;
  915. else
  916. rc = -ERESTARTSYS;
  917. break;
  918. }
  919. if (((portp->flags & ASYNC_CLOSING) == 0) &&
  920. (doclocal || (portp->sigs & TIOCM_CD))) {
  921. break;
  922. }
  923. if (signal_pending(current)) {
  924. rc = -ERESTARTSYS;
  925. break;
  926. }
  927. /* FIXME */
  928. interruptible_sleep_on(&portp->open_wait);
  929. }
  930. if (! tty_hung_up_p(filp))
  931. portp->refcount++;
  932. portp->openwaitcnt--;
  933. spin_unlock_irqrestore(&stallion_lock, flags);
  934. return rc;
  935. }
  936. /*****************************************************************************/
  937. static void stl_close(struct tty_struct *tty, struct file *filp)
  938. {
  939. stlport_t *portp;
  940. unsigned long flags;
  941. #ifdef DEBUG
  942. printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
  943. #endif
  944. portp = tty->driver_data;
  945. if (portp == (stlport_t *) NULL)
  946. return;
  947. spin_lock_irqsave(&stallion_lock, flags);
  948. if (tty_hung_up_p(filp)) {
  949. spin_unlock_irqrestore(&stallion_lock, flags);
  950. return;
  951. }
  952. if ((tty->count == 1) && (portp->refcount != 1))
  953. portp->refcount = 1;
  954. if (portp->refcount-- > 1) {
  955. spin_unlock_irqrestore(&stallion_lock, flags);
  956. return;
  957. }
  958. portp->refcount = 0;
  959. portp->flags |= ASYNC_CLOSING;
  960. /*
  961. * May want to wait for any data to drain before closing. The BUSY
  962. * flag keeps track of whether we are still sending or not - it is
  963. * very accurate for the cd1400, not quite so for the sc26198.
  964. * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
  965. */
  966. tty->closing = 1;
  967. spin_unlock_irqrestore(&stallion_lock, flags);
  968. if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  969. tty_wait_until_sent(tty, portp->closing_wait);
  970. stl_waituntilsent(tty, (HZ / 2));
  971. spin_lock_irqsave(&stallion_lock, flags);
  972. portp->flags &= ~ASYNC_INITIALIZED;
  973. spin_unlock_irqrestore(&stallion_lock, flags);
  974. stl_disableintrs(portp);
  975. if (tty->termios->c_cflag & HUPCL)
  976. stl_setsignals(portp, 0, 0);
  977. stl_enablerxtx(portp, 0, 0);
  978. stl_flushbuffer(tty);
  979. portp->istate = 0;
  980. if (portp->tx.buf != (char *) NULL) {
  981. kfree(portp->tx.buf);
  982. portp->tx.buf = (char *) NULL;
  983. portp->tx.head = (char *) NULL;
  984. portp->tx.tail = (char *) NULL;
  985. }
  986. set_bit(TTY_IO_ERROR, &tty->flags);
  987. tty_ldisc_flush(tty);
  988. tty->closing = 0;
  989. portp->tty = (struct tty_struct *) NULL;
  990. if (portp->openwaitcnt) {
  991. if (portp->close_delay)
  992. msleep_interruptible(jiffies_to_msecs(portp->close_delay));
  993. wake_up_interruptible(&portp->open_wait);
  994. }
  995. portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  996. wake_up_interruptible(&portp->close_wait);
  997. }
  998. /*****************************************************************************/
  999. /*
  1000. * Write routine. Take data and stuff it in to the TX ring queue.
  1001. * If transmit interrupts are not running then start them.
  1002. */
  1003. static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
  1004. {
  1005. stlport_t *portp;
  1006. unsigned int len, stlen;
  1007. unsigned char *chbuf;
  1008. char *head, *tail;
  1009. #ifdef DEBUG
  1010. printk("stl_write(tty=%x,buf=%x,count=%d)\n",
  1011. (int) tty, (int) buf, count);
  1012. #endif
  1013. portp = tty->driver_data;
  1014. if (portp == (stlport_t *) NULL)
  1015. return 0;
  1016. if (portp->tx.buf == (char *) NULL)
  1017. return 0;
  1018. /*
  1019. * If copying direct from user space we must cater for page faults,
  1020. * causing us to "sleep" here for a while. To handle this copy in all
  1021. * the data we need now, into a local buffer. Then when we got it all
  1022. * copy it into the TX buffer.
  1023. */
  1024. chbuf = (unsigned char *) buf;
  1025. head = portp->tx.head;
  1026. tail = portp->tx.tail;
  1027. if (head >= tail) {
  1028. len = STL_TXBUFSIZE - (head - tail) - 1;
  1029. stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
  1030. } else {
  1031. len = tail - head - 1;
  1032. stlen = len;
  1033. }
  1034. len = MIN(len, count);
  1035. count = 0;
  1036. while (len > 0) {
  1037. stlen = MIN(len, stlen);
  1038. memcpy(head, chbuf, stlen);
  1039. len -= stlen;
  1040. chbuf += stlen;
  1041. count += stlen;
  1042. head += stlen;
  1043. if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
  1044. head = portp->tx.buf;
  1045. stlen = tail - head;
  1046. }
  1047. }
  1048. portp->tx.head = head;
  1049. clear_bit(ASYI_TXLOW, &portp->istate);
  1050. stl_startrxtx(portp, -1, 1);
  1051. return count;
  1052. }
  1053. /*****************************************************************************/
  1054. static void stl_putchar(struct tty_struct *tty, unsigned char ch)
  1055. {
  1056. stlport_t *portp;
  1057. unsigned int len;
  1058. char *head, *tail;
  1059. #ifdef DEBUG
  1060. printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
  1061. #endif
  1062. if (tty == (struct tty_struct *) NULL)
  1063. return;
  1064. portp = tty->driver_data;
  1065. if (portp == (stlport_t *) NULL)
  1066. return;
  1067. if (portp->tx.buf == (char *) NULL)
  1068. return;
  1069. head = portp->tx.head;
  1070. tail = portp->tx.tail;
  1071. len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
  1072. len--;
  1073. if (len > 0) {
  1074. *head++ = ch;
  1075. if (head >= (portp->tx.buf + STL_TXBUFSIZE))
  1076. head = portp->tx.buf;
  1077. }
  1078. portp->tx.head = head;
  1079. }
  1080. /*****************************************************************************/
  1081. /*
  1082. * If there are any characters in the buffer then make sure that TX
  1083. * interrupts are on and get'em out. Normally used after the putchar
  1084. * routine has been called.
  1085. */
  1086. static void stl_flushchars(struct tty_struct *tty)
  1087. {
  1088. stlport_t *portp;
  1089. #ifdef DEBUG
  1090. printk("stl_flushchars(tty=%x)\n", (int) tty);
  1091. #endif
  1092. if (tty == (struct tty_struct *) NULL)
  1093. return;
  1094. portp = tty->driver_data;
  1095. if (portp == (stlport_t *) NULL)
  1096. return;
  1097. if (portp->tx.buf == (char *) NULL)
  1098. return;
  1099. stl_startrxtx(portp, -1, 1);
  1100. }
  1101. /*****************************************************************************/
  1102. static int stl_writeroom(struct tty_struct *tty)
  1103. {
  1104. stlport_t *portp;
  1105. char *head, *tail;
  1106. #ifdef DEBUG
  1107. printk("stl_writeroom(tty=%x)\n", (int) tty);
  1108. #endif
  1109. if (tty == (struct tty_struct *) NULL)
  1110. return 0;
  1111. portp = tty->driver_data;
  1112. if (portp == (stlport_t *) NULL)
  1113. return 0;
  1114. if (portp->tx.buf == (char *) NULL)
  1115. return 0;
  1116. head = portp->tx.head;
  1117. tail = portp->tx.tail;
  1118. return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
  1119. }
  1120. /*****************************************************************************/
  1121. /*
  1122. * Return number of chars in the TX buffer. Normally we would just
  1123. * calculate the number of chars in the buffer and return that, but if
  1124. * the buffer is empty and TX interrupts are still on then we return
  1125. * that the buffer still has 1 char in it. This way whoever called us
  1126. * will not think that ALL chars have drained - since the UART still
  1127. * must have some chars in it (we are busy after all).
  1128. */
  1129. static int stl_charsinbuffer(struct tty_struct *tty)
  1130. {
  1131. stlport_t *portp;
  1132. unsigned int size;
  1133. char *head, *tail;
  1134. #ifdef DEBUG
  1135. printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
  1136. #endif
  1137. if (tty == (struct tty_struct *) NULL)
  1138. return 0;
  1139. portp = tty->driver_data;
  1140. if (portp == (stlport_t *) NULL)
  1141. return 0;
  1142. if (portp->tx.buf == (char *) NULL)
  1143. return 0;
  1144. head = portp->tx.head;
  1145. tail = portp->tx.tail;
  1146. size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  1147. if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
  1148. size = 1;
  1149. return size;
  1150. }
  1151. /*****************************************************************************/
  1152. /*
  1153. * Generate the serial struct info.
  1154. */
  1155. static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
  1156. {
  1157. struct serial_struct sio;
  1158. stlbrd_t *brdp;
  1159. #ifdef DEBUG
  1160. printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
  1161. #endif
  1162. memset(&sio, 0, sizeof(struct serial_struct));
  1163. sio.line = portp->portnr;
  1164. sio.port = portp->ioaddr;
  1165. sio.flags = portp->flags;
  1166. sio.baud_base = portp->baud_base;
  1167. sio.close_delay = portp->close_delay;
  1168. sio.closing_wait = portp->closing_wait;
  1169. sio.custom_divisor = portp->custom_divisor;
  1170. sio.hub6 = 0;
  1171. if (portp->uartp == &stl_cd1400uart) {
  1172. sio.type = PORT_CIRRUS;
  1173. sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
  1174. } else {
  1175. sio.type = PORT_UNKNOWN;
  1176. sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
  1177. }
  1178. brdp = stl_brds[portp->brdnr];
  1179. if (brdp != (stlbrd_t *) NULL)
  1180. sio.irq = brdp->irq;
  1181. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
  1182. }
  1183. /*****************************************************************************/
  1184. /*
  1185. * Set port according to the serial struct info.
  1186. * At this point we do not do any auto-configure stuff, so we will
  1187. * just quietly ignore any requests to change irq, etc.
  1188. */
  1189. static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
  1190. {
  1191. struct serial_struct sio;
  1192. #ifdef DEBUG
  1193. printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
  1194. #endif
  1195. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1196. return -EFAULT;
  1197. if (!capable(CAP_SYS_ADMIN)) {
  1198. if ((sio.baud_base != portp->baud_base) ||
  1199. (sio.close_delay != portp->close_delay) ||
  1200. ((sio.flags & ~ASYNC_USR_MASK) !=
  1201. (portp->flags & ~ASYNC_USR_MASK)))
  1202. return -EPERM;
  1203. }
  1204. portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
  1205. (sio.flags & ASYNC_USR_MASK);
  1206. portp->baud_base = sio.baud_base;
  1207. portp->close_delay = sio.close_delay;
  1208. portp->closing_wait = sio.closing_wait;
  1209. portp->custom_divisor = sio.custom_divisor;
  1210. stl_setport(portp, portp->tty->termios);
  1211. return 0;
  1212. }
  1213. /*****************************************************************************/
  1214. static int stl_tiocmget(struct tty_struct *tty, struct file *file)
  1215. {
  1216. stlport_t *portp;
  1217. if (tty == (struct tty_struct *) NULL)
  1218. return -ENODEV;
  1219. portp = tty->driver_data;
  1220. if (portp == (stlport_t *) NULL)
  1221. return -ENODEV;
  1222. if (tty->flags & (1 << TTY_IO_ERROR))
  1223. return -EIO;
  1224. return stl_getsignals(portp);
  1225. }
  1226. static int stl_tiocmset(struct tty_struct *tty, struct file *file,
  1227. unsigned int set, unsigned int clear)
  1228. {
  1229. stlport_t *portp;
  1230. int rts = -1, dtr = -1;
  1231. if (tty == (struct tty_struct *) NULL)
  1232. return -ENODEV;
  1233. portp = tty->driver_data;
  1234. if (portp == (stlport_t *) NULL)
  1235. return -ENODEV;
  1236. if (tty->flags & (1 << TTY_IO_ERROR))
  1237. return -EIO;
  1238. if (set & TIOCM_RTS)
  1239. rts = 1;
  1240. if (set & TIOCM_DTR)
  1241. dtr = 1;
  1242. if (clear & TIOCM_RTS)
  1243. rts = 0;
  1244. if (clear & TIOCM_DTR)
  1245. dtr = 0;
  1246. stl_setsignals(portp, dtr, rts);
  1247. return 0;
  1248. }
  1249. static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1250. {
  1251. stlport_t *portp;
  1252. unsigned int ival;
  1253. int rc;
  1254. void __user *argp = (void __user *)arg;
  1255. #ifdef DEBUG
  1256. printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
  1257. (int) tty, (int) file, cmd, (int) arg);
  1258. #endif
  1259. if (tty == (struct tty_struct *) NULL)
  1260. return -ENODEV;
  1261. portp = tty->driver_data;
  1262. if (portp == (stlport_t *) NULL)
  1263. return -ENODEV;
  1264. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1265. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1266. if (tty->flags & (1 << TTY_IO_ERROR))
  1267. return -EIO;
  1268. }
  1269. rc = 0;
  1270. switch (cmd) {
  1271. case TIOCGSOFTCAR:
  1272. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  1273. (unsigned __user *) argp);
  1274. break;
  1275. case TIOCSSOFTCAR:
  1276. if (get_user(ival, (unsigned int __user *) arg))
  1277. return -EFAULT;
  1278. tty->termios->c_cflag =
  1279. (tty->termios->c_cflag & ~CLOCAL) |
  1280. (ival ? CLOCAL : 0);
  1281. break;
  1282. case TIOCGSERIAL:
  1283. rc = stl_getserial(portp, argp);
  1284. break;
  1285. case TIOCSSERIAL:
  1286. rc = stl_setserial(portp, argp);
  1287. break;
  1288. case COM_GETPORTSTATS:
  1289. rc = stl_getportstats(portp, argp);
  1290. break;
  1291. case COM_CLRPORTSTATS:
  1292. rc = stl_clrportstats(portp, argp);
  1293. break;
  1294. case TIOCSERCONFIG:
  1295. case TIOCSERGWILD:
  1296. case TIOCSERSWILD:
  1297. case TIOCSERGETLSR:
  1298. case TIOCSERGSTRUCT:
  1299. case TIOCSERGETMULTI:
  1300. case TIOCSERSETMULTI:
  1301. default:
  1302. rc = -ENOIOCTLCMD;
  1303. break;
  1304. }
  1305. return rc;
  1306. }
  1307. /*****************************************************************************/
  1308. static void stl_settermios(struct tty_struct *tty, struct termios *old)
  1309. {
  1310. stlport_t *portp;
  1311. struct termios *tiosp;
  1312. #ifdef DEBUG
  1313. printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
  1314. #endif
  1315. if (tty == (struct tty_struct *) NULL)
  1316. return;
  1317. portp = tty->driver_data;
  1318. if (portp == (stlport_t *) NULL)
  1319. return;
  1320. tiosp = tty->termios;
  1321. if ((tiosp->c_cflag == old->c_cflag) &&
  1322. (tiosp->c_iflag == old->c_iflag))
  1323. return;
  1324. stl_setport(portp, tiosp);
  1325. stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
  1326. -1);
  1327. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
  1328. tty->hw_stopped = 0;
  1329. stl_start(tty);
  1330. }
  1331. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1332. wake_up_interruptible(&portp->open_wait);
  1333. }
  1334. /*****************************************************************************/
  1335. /*
  1336. * Attempt to flow control who ever is sending us data. Based on termios
  1337. * settings use software or/and hardware flow control.
  1338. */
  1339. static void stl_throttle(struct tty_struct *tty)
  1340. {
  1341. stlport_t *portp;
  1342. #ifdef DEBUG
  1343. printk("stl_throttle(tty=%x)\n", (int) tty);
  1344. #endif
  1345. if (tty == (struct tty_struct *) NULL)
  1346. return;
  1347. portp = tty->driver_data;
  1348. if (portp == (stlport_t *) NULL)
  1349. return;
  1350. stl_flowctrl(portp, 0);
  1351. }
  1352. /*****************************************************************************/
  1353. /*
  1354. * Unflow control the device sending us data...
  1355. */
  1356. static void stl_unthrottle(struct tty_struct *tty)
  1357. {
  1358. stlport_t *portp;
  1359. #ifdef DEBUG
  1360. printk("stl_unthrottle(tty=%x)\n", (int) tty);
  1361. #endif
  1362. if (tty == (struct tty_struct *) NULL)
  1363. return;
  1364. portp = tty->driver_data;
  1365. if (portp == (stlport_t *) NULL)
  1366. return;
  1367. stl_flowctrl(portp, 1);
  1368. }
  1369. /*****************************************************************************/
  1370. /*
  1371. * Stop the transmitter. Basically to do this we will just turn TX
  1372. * interrupts off.
  1373. */
  1374. static void stl_stop(struct tty_struct *tty)
  1375. {
  1376. stlport_t *portp;
  1377. #ifdef DEBUG
  1378. printk("stl_stop(tty=%x)\n", (int) tty);
  1379. #endif
  1380. if (tty == (struct tty_struct *) NULL)
  1381. return;
  1382. portp = tty->driver_data;
  1383. if (portp == (stlport_t *) NULL)
  1384. return;
  1385. stl_startrxtx(portp, -1, 0);
  1386. }
  1387. /*****************************************************************************/
  1388. /*
  1389. * Start the transmitter again. Just turn TX interrupts back on.
  1390. */
  1391. static void stl_start(struct tty_struct *tty)
  1392. {
  1393. stlport_t *portp;
  1394. #ifdef DEBUG
  1395. printk("stl_start(tty=%x)\n", (int) tty);
  1396. #endif
  1397. if (tty == (struct tty_struct *) NULL)
  1398. return;
  1399. portp = tty->driver_data;
  1400. if (portp == (stlport_t *) NULL)
  1401. return;
  1402. stl_startrxtx(portp, -1, 1);
  1403. }
  1404. /*****************************************************************************/
  1405. /*
  1406. * Hangup this port. This is pretty much like closing the port, only
  1407. * a little more brutal. No waiting for data to drain. Shutdown the
  1408. * port and maybe drop signals.
  1409. */
  1410. static void stl_hangup(struct tty_struct *tty)
  1411. {
  1412. stlport_t *portp;
  1413. #ifdef DEBUG
  1414. printk("stl_hangup(tty=%x)\n", (int) tty);
  1415. #endif
  1416. if (tty == (struct tty_struct *) NULL)
  1417. return;
  1418. portp = tty->driver_data;
  1419. if (portp == (stlport_t *) NULL)
  1420. return;
  1421. portp->flags &= ~ASYNC_INITIALIZED;
  1422. stl_disableintrs(portp);
  1423. if (tty->termios->c_cflag & HUPCL)
  1424. stl_setsignals(portp, 0, 0);
  1425. stl_enablerxtx(portp, 0, 0);
  1426. stl_flushbuffer(tty);
  1427. portp->istate = 0;
  1428. set_bit(TTY_IO_ERROR, &tty->flags);
  1429. if (portp->tx.buf != (char *) NULL) {
  1430. kfree(portp->tx.buf);
  1431. portp->tx.buf = (char *) NULL;
  1432. portp->tx.head = (char *) NULL;
  1433. portp->tx.tail = (char *) NULL;
  1434. }
  1435. portp->tty = (struct tty_struct *) NULL;
  1436. portp->flags &= ~ASYNC_NORMAL_ACTIVE;
  1437. portp->refcount = 0;
  1438. wake_up_interruptible(&portp->open_wait);
  1439. }
  1440. /*****************************************************************************/
  1441. static void stl_flushbuffer(struct tty_struct *tty)
  1442. {
  1443. stlport_t *portp;
  1444. #ifdef DEBUG
  1445. printk("stl_flushbuffer(tty=%x)\n", (int) tty);
  1446. #endif
  1447. if (tty == (struct tty_struct *) NULL)
  1448. return;
  1449. portp = tty->driver_data;
  1450. if (portp == (stlport_t *) NULL)
  1451. return;
  1452. stl_flush(portp);
  1453. tty_wakeup(tty);
  1454. }
  1455. /*****************************************************************************/
  1456. static void stl_breakctl(struct tty_struct *tty, int state)
  1457. {
  1458. stlport_t *portp;
  1459. #ifdef DEBUG
  1460. printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
  1461. #endif
  1462. if (tty == (struct tty_struct *) NULL)
  1463. return;
  1464. portp = tty->driver_data;
  1465. if (portp == (stlport_t *) NULL)
  1466. return;
  1467. stl_sendbreak(portp, ((state == -1) ? 1 : 2));
  1468. }
  1469. /*****************************************************************************/
  1470. static void stl_waituntilsent(struct tty_struct *tty, int timeout)
  1471. {
  1472. stlport_t *portp;
  1473. unsigned long tend;
  1474. #ifdef DEBUG
  1475. printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
  1476. #endif
  1477. if (tty == (struct tty_struct *) NULL)
  1478. return;
  1479. portp = tty->driver_data;
  1480. if (portp == (stlport_t *) NULL)
  1481. return;
  1482. if (timeout == 0)
  1483. timeout = HZ;
  1484. tend = jiffies + timeout;
  1485. while (stl_datastate(portp)) {
  1486. if (signal_pending(current))
  1487. break;
  1488. msleep_interruptible(20);
  1489. if (time_after_eq(jiffies, tend))
  1490. break;
  1491. }
  1492. }
  1493. /*****************************************************************************/
  1494. static void stl_sendxchar(struct tty_struct *tty, char ch)
  1495. {
  1496. stlport_t *portp;
  1497. #ifdef DEBUG
  1498. printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
  1499. #endif
  1500. if (tty == (struct tty_struct *) NULL)
  1501. return;
  1502. portp = tty->driver_data;
  1503. if (portp == (stlport_t *) NULL)
  1504. return;
  1505. if (ch == STOP_CHAR(tty))
  1506. stl_sendflow(portp, 0);
  1507. else if (ch == START_CHAR(tty))
  1508. stl_sendflow(portp, 1);
  1509. else
  1510. stl_putchar(tty, ch);
  1511. }
  1512. /*****************************************************************************/
  1513. #define MAXLINE 80
  1514. /*
  1515. * Format info for a specified port. The line is deliberately limited
  1516. * to 80 characters. (If it is too long it will be truncated, if too
  1517. * short then padded with spaces).
  1518. */
  1519. static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
  1520. {
  1521. char *sp;
  1522. int sigs, cnt;
  1523. sp = pos;
  1524. sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
  1525. portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
  1526. (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
  1527. if (portp->stats.rxframing)
  1528. sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
  1529. if (portp->stats.rxparity)
  1530. sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
  1531. if (portp->stats.rxbreaks)
  1532. sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
  1533. if (portp->stats.rxoverrun)
  1534. sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
  1535. sigs = stl_getsignals(portp);
  1536. cnt = sprintf(sp, "%s%s%s%s%s ",
  1537. (sigs & TIOCM_RTS) ? "|RTS" : "",
  1538. (sigs & TIOCM_CTS) ? "|CTS" : "",
  1539. (sigs & TIOCM_DTR) ? "|DTR" : "",
  1540. (sigs & TIOCM_CD) ? "|DCD" : "",
  1541. (sigs & TIOCM_DSR) ? "|DSR" : "");
  1542. *sp = ' ';
  1543. sp += cnt;
  1544. for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
  1545. *sp++ = ' ';
  1546. if (cnt >= MAXLINE)
  1547. pos[(MAXLINE - 2)] = '+';
  1548. pos[(MAXLINE - 1)] = '\n';
  1549. return MAXLINE;
  1550. }
  1551. /*****************************************************************************/
  1552. /*
  1553. * Port info, read from the /proc file system.
  1554. */
  1555. static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
  1556. {
  1557. stlbrd_t *brdp;
  1558. stlpanel_t *panelp;
  1559. stlport_t *portp;
  1560. int brdnr, panelnr, portnr, totalport;
  1561. int curoff, maxoff;
  1562. char *pos;
  1563. #ifdef DEBUG
  1564. printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
  1565. "data=%x\n", (int) page, (int) start, (int) off, count,
  1566. (int) eof, (int) data);
  1567. #endif
  1568. pos = page;
  1569. totalport = 0;
  1570. curoff = 0;
  1571. if (off == 0) {
  1572. pos += sprintf(pos, "%s: version %s", stl_drvtitle,
  1573. stl_drvversion);
  1574. while (pos < (page + MAXLINE - 1))
  1575. *pos++ = ' ';
  1576. *pos++ = '\n';
  1577. }
  1578. curoff = MAXLINE;
  1579. /*
  1580. * We scan through for each board, panel and port. The offset is
  1581. * calculated on the fly, and irrelevant ports are skipped.
  1582. */
  1583. for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
  1584. brdp = stl_brds[brdnr];
  1585. if (brdp == (stlbrd_t *) NULL)
  1586. continue;
  1587. if (brdp->state == 0)
  1588. continue;
  1589. maxoff = curoff + (brdp->nrports * MAXLINE);
  1590. if (off >= maxoff) {
  1591. curoff = maxoff;
  1592. continue;
  1593. }
  1594. totalport = brdnr * STL_MAXPORTS;
  1595. for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
  1596. panelp = brdp->panels[panelnr];
  1597. if (panelp == (stlpanel_t *) NULL)
  1598. continue;
  1599. maxoff = curoff + (panelp->nrports * MAXLINE);
  1600. if (off >= maxoff) {
  1601. curoff = maxoff;
  1602. totalport += panelp->nrports;
  1603. continue;
  1604. }
  1605. for (portnr = 0; (portnr < panelp->nrports); portnr++,
  1606. totalport++) {
  1607. portp = panelp->ports[portnr];
  1608. if (portp == (stlport_t *) NULL)
  1609. continue;
  1610. if (off >= (curoff += MAXLINE))
  1611. continue;
  1612. if ((pos - page + MAXLINE) > count)
  1613. goto stl_readdone;
  1614. pos += stl_portinfo(portp, totalport, pos);
  1615. }
  1616. }
  1617. }
  1618. *eof = 1;
  1619. stl_readdone:
  1620. *start = page;
  1621. return (pos - page);
  1622. }
  1623. /*****************************************************************************/
  1624. /*
  1625. * All board interrupts are vectored through here first. This code then
  1626. * calls off to the approrpriate board interrupt handlers.
  1627. */
  1628. static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
  1629. {
  1630. stlbrd_t *brdp = (stlbrd_t *) dev_id;
  1631. #ifdef DEBUG
  1632. printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
  1633. (int) regs);
  1634. #endif
  1635. return IRQ_RETVAL((* brdp->isr)(brdp));
  1636. }
  1637. /*****************************************************************************/
  1638. /*
  1639. * Interrupt service routine for EasyIO board types.
  1640. */
  1641. static int stl_eiointr(stlbrd_t *brdp)
  1642. {
  1643. stlpanel_t *panelp;
  1644. unsigned int iobase;
  1645. int handled = 0;
  1646. spin_lock(&brd_lock);
  1647. panelp = brdp->panels[0];
  1648. iobase = panelp->iobase;
  1649. while (inb(brdp->iostatus) & EIO_INTRPEND) {
  1650. handled = 1;
  1651. (* panelp->isr)(panelp, iobase);
  1652. }
  1653. spin_unlock(&brd_lock);
  1654. return handled;
  1655. }
  1656. /*****************************************************************************/
  1657. /*
  1658. * Interrupt service routine for ECH-AT board types.
  1659. */
  1660. static int stl_echatintr(stlbrd_t *brdp)
  1661. {
  1662. stlpanel_t *panelp;
  1663. unsigned int ioaddr;
  1664. int bnknr;
  1665. int handled = 0;
  1666. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  1667. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1668. handled = 1;
  1669. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1670. ioaddr = brdp->bnkstataddr[bnknr];
  1671. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1672. panelp = brdp->bnk2panel[bnknr];
  1673. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1674. }
  1675. }
  1676. }
  1677. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  1678. return handled;
  1679. }
  1680. /*****************************************************************************/
  1681. /*
  1682. * Interrupt service routine for ECH-MCA board types.
  1683. */
  1684. static int stl_echmcaintr(stlbrd_t *brdp)
  1685. {
  1686. stlpanel_t *panelp;
  1687. unsigned int ioaddr;
  1688. int bnknr;
  1689. int handled = 0;
  1690. while (inb(brdp->iostatus) & ECH_INTRPEND) {
  1691. handled = 1;
  1692. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1693. ioaddr = brdp->bnkstataddr[bnknr];
  1694. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1695. panelp = brdp->bnk2panel[bnknr];
  1696. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1697. }
  1698. }
  1699. }
  1700. return handled;
  1701. }
  1702. /*****************************************************************************/
  1703. /*
  1704. * Interrupt service routine for ECH-PCI board types.
  1705. */
  1706. static int stl_echpciintr(stlbrd_t *brdp)
  1707. {
  1708. stlpanel_t *panelp;
  1709. unsigned int ioaddr;
  1710. int bnknr, recheck;
  1711. int handled = 0;
  1712. while (1) {
  1713. recheck = 0;
  1714. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1715. outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
  1716. ioaddr = brdp->bnkstataddr[bnknr];
  1717. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1718. panelp = brdp->bnk2panel[bnknr];
  1719. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1720. recheck++;
  1721. handled = 1;
  1722. }
  1723. }
  1724. if (! recheck)
  1725. break;
  1726. }
  1727. return handled;
  1728. }
  1729. /*****************************************************************************/
  1730. /*
  1731. * Interrupt service routine for ECH-8/64-PCI board types.
  1732. */
  1733. static int stl_echpci64intr(stlbrd_t *brdp)
  1734. {
  1735. stlpanel_t *panelp;
  1736. unsigned int ioaddr;
  1737. int bnknr;
  1738. int handled = 0;
  1739. while (inb(brdp->ioctrl) & 0x1) {
  1740. handled = 1;
  1741. for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
  1742. ioaddr = brdp->bnkstataddr[bnknr];
  1743. if (inb(ioaddr) & ECH_PNLINTRPEND) {
  1744. panelp = brdp->bnk2panel[bnknr];
  1745. (* panelp->isr)(panelp, (ioaddr & 0xfffc));
  1746. }
  1747. }
  1748. }
  1749. return handled;
  1750. }
  1751. /*****************************************************************************/
  1752. /*
  1753. * Service an off-level request for some channel.
  1754. */
  1755. static void stl_offintr(void *private)
  1756. {
  1757. stlport_t *portp;
  1758. struct tty_struct *tty;
  1759. unsigned int oldsigs;
  1760. portp = private;
  1761. #ifdef DEBUG
  1762. printk("stl_offintr(portp=%x)\n", (int) portp);
  1763. #endif
  1764. if (portp == (stlport_t *) NULL)
  1765. return;
  1766. tty = portp->tty;
  1767. if (tty == (struct tty_struct *) NULL)
  1768. return;
  1769. lock_kernel();
  1770. if (test_bit(ASYI_TXLOW, &portp->istate)) {
  1771. tty_wakeup(tty);
  1772. }
  1773. if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
  1774. clear_bit(ASYI_DCDCHANGE, &portp->istate);
  1775. oldsigs = portp->sigs;
  1776. portp->sigs = stl_getsignals(portp);
  1777. if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
  1778. wake_up_interruptible(&portp->open_wait);
  1779. if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
  1780. if (portp->flags & ASYNC_CHECK_CD)
  1781. tty_hangup(tty); /* FIXME: module removal race here - AKPM */
  1782. }
  1783. }
  1784. unlock_kernel();
  1785. }
  1786. /*****************************************************************************/
  1787. /*
  1788. * Initialize all the ports on a panel.
  1789. */
  1790. static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
  1791. {
  1792. stlport_t *portp;
  1793. int chipmask, i;
  1794. #ifdef DEBUG
  1795. printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
  1796. #endif
  1797. chipmask = stl_panelinit(brdp, panelp);
  1798. /*
  1799. * All UART's are initialized (if found!). Now go through and setup
  1800. * each ports data structures.
  1801. */
  1802. for (i = 0; (i < panelp->nrports); i++) {
  1803. portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
  1804. if (!portp) {
  1805. printk("STALLION: failed to allocate memory "
  1806. "(size=%Zd)\n", sizeof(stlport_t));
  1807. break;
  1808. }
  1809. portp->magic = STL_PORTMAGIC;
  1810. portp->portnr = i;
  1811. portp->brdnr = panelp->brdnr;
  1812. portp->panelnr = panelp->panelnr;
  1813. portp->uartp = panelp->uartp;
  1814. portp->clk = brdp->clk;
  1815. portp->baud_base = STL_BAUDBASE;
  1816. portp->close_delay = STL_CLOSEDELAY;
  1817. portp->closing_wait = 30 * HZ;
  1818. INIT_WORK(&portp->tqueue, stl_offintr, portp);
  1819. init_waitqueue_head(&portp->open_wait);
  1820. init_waitqueue_head(&portp->close_wait);
  1821. portp->stats.brd = portp->brdnr;
  1822. portp->stats.panel = portp->panelnr;
  1823. portp->stats.port = portp->portnr;
  1824. panelp->ports[i] = portp;
  1825. stl_portinit(brdp, panelp, portp);
  1826. }
  1827. return(0);
  1828. }
  1829. /*****************************************************************************/
  1830. /*
  1831. * Try to find and initialize an EasyIO board.
  1832. */
  1833. static inline int stl_initeio(stlbrd_t *brdp)
  1834. {
  1835. stlpanel_t *panelp;
  1836. unsigned int status;
  1837. char *name;
  1838. int rc;
  1839. #ifdef DEBUG
  1840. printk("stl_initeio(brdp=%x)\n", (int) brdp);
  1841. #endif
  1842. brdp->ioctrl = brdp->ioaddr1 + 1;
  1843. brdp->iostatus = brdp->ioaddr1 + 2;
  1844. status = inb(brdp->iostatus);
  1845. if ((status & EIO_IDBITMASK) == EIO_MK3)
  1846. brdp->ioctrl++;
  1847. /*
  1848. * Handle board specific stuff now. The real difference is PCI
  1849. * or not PCI.
  1850. */
  1851. if (brdp->brdtype == BRD_EASYIOPCI) {
  1852. brdp->iosize1 = 0x80;
  1853. brdp->iosize2 = 0x80;
  1854. name = "serial(EIO-PCI)";
  1855. outb(0x41, (brdp->ioaddr2 + 0x4c));
  1856. } else {
  1857. brdp->iosize1 = 8;
  1858. name = "serial(EIO)";
  1859. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1860. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1861. printk("STALLION: invalid irq=%d for brd=%d\n",
  1862. brdp->irq, brdp->brdnr);
  1863. return(-EINVAL);
  1864. }
  1865. outb((stl_vecmap[brdp->irq] | EIO_0WS |
  1866. ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
  1867. brdp->ioctrl);
  1868. }
  1869. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  1870. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  1871. "%x conflicts with another device\n", brdp->brdnr,
  1872. brdp->ioaddr1);
  1873. return(-EBUSY);
  1874. }
  1875. if (brdp->iosize2 > 0)
  1876. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  1877. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  1878. "address %x conflicts with another device\n",
  1879. brdp->brdnr, brdp->ioaddr2);
  1880. printk(KERN_WARNING "STALLION: Warning, also "
  1881. "releasing board %d I/O address %x \n",
  1882. brdp->brdnr, brdp->ioaddr1);
  1883. release_region(brdp->ioaddr1, brdp->iosize1);
  1884. return(-EBUSY);
  1885. }
  1886. /*
  1887. * Everything looks OK, so let's go ahead and probe for the hardware.
  1888. */
  1889. brdp->clk = CD1400_CLK;
  1890. brdp->isr = stl_eiointr;
  1891. switch (status & EIO_IDBITMASK) {
  1892. case EIO_8PORTM:
  1893. brdp->clk = CD1400_CLK8M;
  1894. /* fall thru */
  1895. case EIO_8PORTRS:
  1896. case EIO_8PORTDI:
  1897. brdp->nrports = 8;
  1898. break;
  1899. case EIO_4PORTRS:
  1900. brdp->nrports = 4;
  1901. break;
  1902. case EIO_MK3:
  1903. switch (status & EIO_BRDMASK) {
  1904. case ID_BRD4:
  1905. brdp->nrports = 4;
  1906. break;
  1907. case ID_BRD8:
  1908. brdp->nrports = 8;
  1909. break;
  1910. case ID_BRD16:
  1911. brdp->nrports = 16;
  1912. break;
  1913. default:
  1914. return(-ENODEV);
  1915. }
  1916. break;
  1917. default:
  1918. return(-ENODEV);
  1919. }
  1920. /*
  1921. * We have verified that the board is actually present, so now we
  1922. * can complete the setup.
  1923. */
  1924. panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
  1925. if (!panelp) {
  1926. printk(KERN_WARNING "STALLION: failed to allocate memory "
  1927. "(size=%Zd)\n", sizeof(stlpanel_t));
  1928. return -ENOMEM;
  1929. }
  1930. panelp->magic = STL_PANELMAGIC;
  1931. panelp->brdnr = brdp->brdnr;
  1932. panelp->panelnr = 0;
  1933. panelp->nrports = brdp->nrports;
  1934. panelp->iobase = brdp->ioaddr1;
  1935. panelp->hwid = status;
  1936. if ((status & EIO_IDBITMASK) == EIO_MK3) {
  1937. panelp->uartp = (void *) &stl_sc26198uart;
  1938. panelp->isr = stl_sc26198intr;
  1939. } else {
  1940. panelp->uartp = (void *) &stl_cd1400uart;
  1941. panelp->isr = stl_cd1400eiointr;
  1942. }
  1943. brdp->panels[0] = panelp;
  1944. brdp->nrpanels = 1;
  1945. brdp->state |= BRD_FOUND;
  1946. brdp->hwid = status;
  1947. if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
  1948. printk("STALLION: failed to register interrupt "
  1949. "routine for %s irq=%d\n", name, brdp->irq);
  1950. rc = -ENODEV;
  1951. } else {
  1952. rc = 0;
  1953. }
  1954. return rc;
  1955. }
  1956. /*****************************************************************************/
  1957. /*
  1958. * Try to find an ECH board and initialize it. This code is capable of
  1959. * dealing with all types of ECH board.
  1960. */
  1961. static inline int stl_initech(stlbrd_t *brdp)
  1962. {
  1963. stlpanel_t *panelp;
  1964. unsigned int status, nxtid, ioaddr, conflict;
  1965. int panelnr, banknr, i;
  1966. char *name;
  1967. #ifdef DEBUG
  1968. printk("stl_initech(brdp=%x)\n", (int) brdp);
  1969. #endif
  1970. status = 0;
  1971. conflict = 0;
  1972. /*
  1973. * Set up the initial board register contents for boards. This varies a
  1974. * bit between the different board types. So we need to handle each
  1975. * separately. Also do a check that the supplied IRQ is good.
  1976. */
  1977. switch (brdp->brdtype) {
  1978. case BRD_ECH:
  1979. brdp->isr = stl_echatintr;
  1980. brdp->ioctrl = brdp->ioaddr1 + 1;
  1981. brdp->iostatus = brdp->ioaddr1 + 1;
  1982. status = inb(brdp->iostatus);
  1983. if ((status & ECH_IDBITMASK) != ECH_ID)
  1984. return(-ENODEV);
  1985. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  1986. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  1987. printk("STALLION: invalid irq=%d for brd=%d\n",
  1988. brdp->irq, brdp->brdnr);
  1989. return(-EINVAL);
  1990. }
  1991. status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
  1992. status |= (stl_vecmap[brdp->irq] << 1);
  1993. outb((status | ECH_BRDRESET), brdp->ioaddr1);
  1994. brdp->ioctrlval = ECH_INTENABLE |
  1995. ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
  1996. for (i = 0; (i < 10); i++)
  1997. outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
  1998. brdp->iosize1 = 2;
  1999. brdp->iosize2 = 32;
  2000. name = "serial(EC8/32)";
  2001. outb(status, brdp->ioaddr1);
  2002. break;
  2003. case BRD_ECHMC:
  2004. brdp->isr = stl_echmcaintr;
  2005. brdp->ioctrl = brdp->ioaddr1 + 0x20;
  2006. brdp->iostatus = brdp->ioctrl;
  2007. status = inb(brdp->iostatus);
  2008. if ((status & ECH_IDBITMASK) != ECH_ID)
  2009. return(-ENODEV);
  2010. if ((brdp->irq < 0) || (brdp->irq > 15) ||
  2011. (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
  2012. printk("STALLION: invalid irq=%d for brd=%d\n",
  2013. brdp->irq, brdp->brdnr);
  2014. return(-EINVAL);
  2015. }
  2016. outb(ECHMC_BRDRESET, brdp->ioctrl);
  2017. outb(ECHMC_INTENABLE, brdp->ioctrl);
  2018. brdp->iosize1 = 64;
  2019. name = "serial(EC8/32-MC)";
  2020. break;
  2021. case BRD_ECHPCI:
  2022. brdp->isr = stl_echpciintr;
  2023. brdp->ioctrl = brdp->ioaddr1 + 2;
  2024. brdp->iosize1 = 4;
  2025. brdp->iosize2 = 8;
  2026. name = "serial(EC8/32-PCI)";
  2027. break;
  2028. case BRD_ECH64PCI:
  2029. brdp->isr = stl_echpci64intr;
  2030. brdp->ioctrl = brdp->ioaddr2 + 0x40;
  2031. outb(0x43, (brdp->ioaddr1 + 0x4c));
  2032. brdp->iosize1 = 0x80;
  2033. brdp->iosize2 = 0x80;
  2034. name = "serial(EC8/64-PCI)";
  2035. break;
  2036. default:
  2037. printk("STALLION: unknown board type=%d\n", brdp->brdtype);
  2038. return(-EINVAL);
  2039. break;
  2040. }
  2041. /*
  2042. * Check boards for possible IO address conflicts and return fail status
  2043. * if an IO conflict found.
  2044. */
  2045. if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
  2046. printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
  2047. "%x conflicts with another device\n", brdp->brdnr,
  2048. brdp->ioaddr1);
  2049. return(-EBUSY);
  2050. }
  2051. if (brdp->iosize2 > 0)
  2052. if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
  2053. printk(KERN_WARNING "STALLION: Warning, board %d I/O "
  2054. "address %x conflicts with another device\n",
  2055. brdp->brdnr, brdp->ioaddr2);
  2056. printk(KERN_WARNING "STALLION: Warning, also "
  2057. "releasing board %d I/O address %x \n",
  2058. brdp->brdnr, brdp->ioaddr1);
  2059. release_region(brdp->ioaddr1, brdp->iosize1);
  2060. return(-EBUSY);
  2061. }
  2062. /*
  2063. * Scan through the secondary io address space looking for panels.
  2064. * As we find'em allocate and initialize panel structures for each.
  2065. */
  2066. brdp->clk = CD1400_CLK;
  2067. brdp->hwid = status;
  2068. ioaddr = brdp->ioaddr2;
  2069. banknr = 0;
  2070. panelnr = 0;
  2071. nxtid = 0;
  2072. for (i = 0; (i < STL_MAXPANELS); i++) {
  2073. if (brdp->brdtype == BRD_ECHPCI) {
  2074. outb(nxtid, brdp->ioctrl);
  2075. ioaddr = brdp->ioaddr2;
  2076. }
  2077. status = inb(ioaddr + ECH_PNLSTATUS);
  2078. if ((status & ECH_PNLIDMASK) != nxtid)
  2079. break;
  2080. panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
  2081. if (!panelp) {
  2082. printk("STALLION: failed to allocate memory "
  2083. "(size=%Zd)\n", sizeof(stlpanel_t));
  2084. break;
  2085. }
  2086. panelp->magic = STL_PANELMAGIC;
  2087. panelp->brdnr = brdp->brdnr;
  2088. panelp->panelnr = panelnr;
  2089. panelp->iobase = ioaddr;
  2090. panelp->pagenr = nxtid;
  2091. panelp->hwid = status;
  2092. brdp->bnk2panel[banknr] = panelp;
  2093. brdp->bnkpageaddr[banknr] = nxtid;
  2094. brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
  2095. if (status & ECH_PNLXPID) {
  2096. panelp->uartp = (void *) &stl_sc26198uart;
  2097. panelp->isr = stl_sc26198intr;
  2098. if (status & ECH_PNL16PORT) {
  2099. panelp->nrports = 16;
  2100. brdp->bnk2panel[banknr] = panelp;
  2101. brdp->bnkpageaddr[banknr] = nxtid;
  2102. brdp->bnkstataddr[banknr++] = ioaddr + 4 +
  2103. ECH_PNLSTATUS;
  2104. } else {
  2105. panelp->nrports = 8;
  2106. }
  2107. } else {
  2108. panelp->uartp = (void *) &stl_cd1400uart;
  2109. panelp->isr = stl_cd1400echintr;
  2110. if (status & ECH_PNL16PORT) {
  2111. panelp->nrports = 16;
  2112. panelp->ackmask = 0x80;
  2113. if (brdp->brdtype != BRD_ECHPCI)
  2114. ioaddr += EREG_BANKSIZE;
  2115. brdp->bnk2panel[banknr] = panelp;
  2116. brdp->bnkpageaddr[banknr] = ++nxtid;
  2117. brdp->bnkstataddr[banknr++] = ioaddr +
  2118. ECH_PNLSTATUS;
  2119. } else {
  2120. panelp->nrports = 8;
  2121. panelp->ackmask = 0xc0;
  2122. }
  2123. }
  2124. nxtid++;
  2125. ioaddr += EREG_BANKSIZE;
  2126. brdp->nrports += panelp->nrports;
  2127. brdp->panels[panelnr++] = panelp;
  2128. if ((brdp->brdtype != BRD_ECHPCI) &&
  2129. (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
  2130. break;
  2131. }
  2132. brdp->nrpanels = panelnr;
  2133. brdp->nrbnks = banknr;
  2134. if (brdp->brdtype == BRD_ECH)
  2135. outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
  2136. brdp->state |= BRD_FOUND;
  2137. if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
  2138. printk("STALLION: failed to register interrupt "
  2139. "routine for %s irq=%d\n", name, brdp->irq);
  2140. i = -ENODEV;
  2141. } else {
  2142. i = 0;
  2143. }
  2144. return(i);
  2145. }
  2146. /*****************************************************************************/
  2147. /*
  2148. * Initialize and configure the specified board.
  2149. * Scan through all the boards in the configuration and see what we
  2150. * can find. Handle EIO and the ECH boards a little differently here
  2151. * since the initial search and setup is very different.
  2152. */
  2153. static int __init stl_brdinit(stlbrd_t *brdp)
  2154. {
  2155. int i;
  2156. #ifdef DEBUG
  2157. printk("stl_brdinit(brdp=%x)\n", (int) brdp);
  2158. #endif
  2159. switch (brdp->brdtype) {
  2160. case BRD_EASYIO:
  2161. case BRD_EASYIOPCI:
  2162. stl_initeio(brdp);
  2163. break;
  2164. case BRD_ECH:
  2165. case BRD_ECHMC:
  2166. case BRD_ECHPCI:
  2167. case BRD_ECH64PCI:
  2168. stl_initech(brdp);
  2169. break;
  2170. default:
  2171. printk("STALLION: board=%d is unknown board type=%d\n",
  2172. brdp->brdnr, brdp->brdtype);
  2173. return(ENODEV);
  2174. }
  2175. stl_brds[brdp->brdnr] = brdp;
  2176. if ((brdp->state & BRD_FOUND) == 0) {
  2177. printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
  2178. stl_brdnames[brdp->brdtype], brdp->brdnr,
  2179. brdp->ioaddr1, brdp->irq);
  2180. return(ENODEV);
  2181. }
  2182. for (i = 0; (i < STL_MAXPANELS); i++)
  2183. if (brdp->panels[i] != (stlpanel_t *) NULL)
  2184. stl_initports(brdp, brdp->panels[i]);
  2185. printk("STALLION: %s found, board=%d io=%x irq=%d "
  2186. "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
  2187. brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
  2188. brdp->nrports);
  2189. return(0);
  2190. }
  2191. /*****************************************************************************/
  2192. /*
  2193. * Find the next available board number that is free.
  2194. */
  2195. static inline int stl_getbrdnr(void)
  2196. {
  2197. int i;
  2198. for (i = 0; (i < STL_MAXBRDS); i++) {
  2199. if (stl_brds[i] == (stlbrd_t *) NULL) {
  2200. if (i >= stl_nrbrds)
  2201. stl_nrbrds = i + 1;
  2202. return(i);
  2203. }
  2204. }
  2205. return(-1);
  2206. }
  2207. /*****************************************************************************/
  2208. #ifdef CONFIG_PCI
  2209. /*
  2210. * We have a Stallion board. Allocate a board structure and
  2211. * initialize it. Read its IO and IRQ resources from PCI
  2212. * configuration space.
  2213. */
  2214. static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
  2215. {
  2216. stlbrd_t *brdp;
  2217. #ifdef DEBUG
  2218. printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
  2219. devp->bus->number, devp->devfn);
  2220. #endif
  2221. if (pci_enable_device(devp))
  2222. return(-EIO);
  2223. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  2224. return(-ENOMEM);
  2225. if ((brdp->brdnr = stl_getbrdnr()) < 0) {
  2226. printk("STALLION: too many boards found, "
  2227. "maximum supported %d\n", STL_MAXBRDS);
  2228. return(0);
  2229. }
  2230. brdp->brdtype = brdtype;
  2231. /*
  2232. * Different Stallion boards use the BAR registers in different ways,
  2233. * so set up io addresses based on board type.
  2234. */
  2235. #ifdef DEBUG
  2236. printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
  2237. pci_resource_start(devp, 0), pci_resource_start(devp, 1),
  2238. pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
  2239. #endif
  2240. /*
  2241. * We have all resources from the board, so let's setup the actual
  2242. * board structure now.
  2243. */
  2244. switch (brdtype) {
  2245. case BRD_ECHPCI:
  2246. brdp->ioaddr2 = pci_resource_start(devp, 0);
  2247. brdp->ioaddr1 = pci_resource_start(devp, 1);
  2248. break;
  2249. case BRD_ECH64PCI:
  2250. brdp->ioaddr2 = pci_resource_start(devp, 2);
  2251. brdp->ioaddr1 = pci_resource_start(devp, 1);
  2252. break;
  2253. case BRD_EASYIOPCI:
  2254. brdp->ioaddr1 = pci_resource_start(devp, 2);
  2255. brdp->ioaddr2 = pci_resource_start(devp, 1);
  2256. break;
  2257. default:
  2258. printk("STALLION: unknown PCI board type=%d\n", brdtype);
  2259. break;
  2260. }
  2261. brdp->irq = devp->irq;
  2262. stl_brdinit(brdp);
  2263. return(0);
  2264. }
  2265. /*****************************************************************************/
  2266. /*
  2267. * Find all Stallion PCI boards that might be installed. Initialize each
  2268. * one as it is found.
  2269. */
  2270. static inline int stl_findpcibrds(void)
  2271. {
  2272. struct pci_dev *dev = NULL;
  2273. int i, rc;
  2274. #ifdef DEBUG
  2275. printk("stl_findpcibrds()\n");
  2276. #endif
  2277. for (i = 0; (i < stl_nrpcibrds); i++)
  2278. while ((dev = pci_find_device(stl_pcibrds[i].vendid,
  2279. stl_pcibrds[i].devid, dev))) {
  2280. /*
  2281. * Found a device on the PCI bus that has our vendor and
  2282. * device ID. Need to check now that it is really us.
  2283. */
  2284. if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
  2285. continue;
  2286. rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
  2287. if (rc)
  2288. return(rc);
  2289. }
  2290. return(0);
  2291. }
  2292. #endif
  2293. /*****************************************************************************/
  2294. /*
  2295. * Scan through all the boards in the configuration and see what we
  2296. * can find. Handle EIO and the ECH boards a little differently here
  2297. * since the initial search and setup is too different.
  2298. */
  2299. static inline int stl_initbrds(void)
  2300. {
  2301. stlbrd_t *brdp;
  2302. stlconf_t *confp;
  2303. int i;
  2304. #ifdef DEBUG
  2305. printk("stl_initbrds()\n");
  2306. #endif
  2307. if (stl_nrbrds > STL_MAXBRDS) {
  2308. printk("STALLION: too many boards in configuration table, "
  2309. "truncating to %d\n", STL_MAXBRDS);
  2310. stl_nrbrds = STL_MAXBRDS;
  2311. }
  2312. /*
  2313. * Firstly scan the list of static boards configured. Allocate
  2314. * resources and initialize the boards as found.
  2315. */
  2316. for (i = 0; (i < stl_nrbrds); i++) {
  2317. confp = &stl_brdconf[i];
  2318. stl_parsebrd(confp, stl_brdsp[i]);
  2319. if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
  2320. return(-ENOMEM);
  2321. brdp->brdnr = i;
  2322. brdp->brdtype = confp->brdtype;
  2323. brdp->ioaddr1 = confp->ioaddr1;
  2324. brdp->ioaddr2 = confp->ioaddr2;
  2325. brdp->irq = confp->irq;
  2326. brdp->irqtype = confp->irqtype;
  2327. stl_brdinit(brdp);
  2328. }
  2329. /*
  2330. * Find any dynamically supported boards. That is via module load
  2331. * line options or auto-detected on the PCI bus.
  2332. */
  2333. stl_argbrds();
  2334. #ifdef CONFIG_PCI
  2335. stl_findpcibrds();
  2336. #endif
  2337. return(0);
  2338. }
  2339. /*****************************************************************************/
  2340. /*
  2341. * Return the board stats structure to user app.
  2342. */
  2343. static int stl_getbrdstats(combrd_t __user *bp)
  2344. {
  2345. stlbrd_t *brdp;
  2346. stlpanel_t *panelp;
  2347. int i;
  2348. if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
  2349. return -EFAULT;
  2350. if (stl_brdstats.brd >= STL_MAXBRDS)
  2351. return(-ENODEV);
  2352. brdp = stl_brds[stl_brdstats.brd];
  2353. if (brdp == (stlbrd_t *) NULL)
  2354. return(-ENODEV);
  2355. memset(&stl_brdstats, 0, sizeof(combrd_t));
  2356. stl_brdstats.brd = brdp->brdnr;
  2357. stl_brdstats.type = brdp->brdtype;
  2358. stl_brdstats.hwid = brdp->hwid;
  2359. stl_brdstats.state = brdp->state;
  2360. stl_brdstats.ioaddr = brdp->ioaddr1;
  2361. stl_brdstats.ioaddr2 = brdp->ioaddr2;
  2362. stl_brdstats.irq = brdp->irq;
  2363. stl_brdstats.nrpanels = brdp->nrpanels;
  2364. stl_brdstats.nrports = brdp->nrports;
  2365. for (i = 0; (i < brdp->nrpanels); i++) {
  2366. panelp = brdp->panels[i];
  2367. stl_brdstats.panels[i].panel = i;
  2368. stl_brdstats.panels[i].hwid = panelp->hwid;
  2369. stl_brdstats.panels[i].nrports = panelp->nrports;
  2370. }
  2371. return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
  2372. }
  2373. /*****************************************************************************/
  2374. /*
  2375. * Resolve the referenced port number into a port struct pointer.
  2376. */
  2377. static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
  2378. {
  2379. stlbrd_t *brdp;
  2380. stlpanel_t *panelp;
  2381. if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
  2382. return((stlport_t *) NULL);
  2383. brdp = stl_brds[brdnr];
  2384. if (brdp == (stlbrd_t *) NULL)
  2385. return((stlport_t *) NULL);
  2386. if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
  2387. return((stlport_t *) NULL);
  2388. panelp = brdp->panels[panelnr];
  2389. if (panelp == (stlpanel_t *) NULL)
  2390. return((stlport_t *) NULL);
  2391. if ((portnr < 0) || (portnr >= panelp->nrports))
  2392. return((stlport_t *) NULL);
  2393. return(panelp->ports[portnr]);
  2394. }
  2395. /*****************************************************************************/
  2396. /*
  2397. * Return the port stats structure to user app. A NULL port struct
  2398. * pointer passed in means that we need to find out from the app
  2399. * what port to get stats for (used through board control device).
  2400. */
  2401. static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
  2402. {
  2403. unsigned char *head, *tail;
  2404. unsigned long flags;
  2405. if (!portp) {
  2406. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2407. return -EFAULT;
  2408. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2409. stl_comstats.port);
  2410. if (portp == (stlport_t *) NULL)
  2411. return(-ENODEV);
  2412. }
  2413. portp->stats.state = portp->istate;
  2414. portp->stats.flags = portp->flags;
  2415. portp->stats.hwid = portp->hwid;
  2416. portp->stats.ttystate = 0;
  2417. portp->stats.cflags = 0;
  2418. portp->stats.iflags = 0;
  2419. portp->stats.oflags = 0;
  2420. portp->stats.lflags = 0;
  2421. portp->stats.rxbuffered = 0;
  2422. spin_lock_irqsave(&stallion_lock, flags);
  2423. if (portp->tty != (struct tty_struct *) NULL) {
  2424. if (portp->tty->driver_data == portp) {
  2425. portp->stats.ttystate = portp->tty->flags;
  2426. /* No longer available as a statistic */
  2427. portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
  2428. if (portp->tty->termios != (struct termios *) NULL) {
  2429. portp->stats.cflags = portp->tty->termios->c_cflag;
  2430. portp->stats.iflags = portp->tty->termios->c_iflag;
  2431. portp->stats.oflags = portp->tty->termios->c_oflag;
  2432. portp->stats.lflags = portp->tty->termios->c_lflag;
  2433. }
  2434. }
  2435. }
  2436. spin_unlock_irqrestore(&stallion_lock, flags);
  2437. head = portp->tx.head;
  2438. tail = portp->tx.tail;
  2439. portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
  2440. (STL_TXBUFSIZE - (tail - head)));
  2441. portp->stats.signals = (unsigned long) stl_getsignals(portp);
  2442. return copy_to_user(cp, &portp->stats,
  2443. sizeof(comstats_t)) ? -EFAULT : 0;
  2444. }
  2445. /*****************************************************************************/
  2446. /*
  2447. * Clear the port stats structure. We also return it zeroed out...
  2448. */
  2449. static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
  2450. {
  2451. if (!portp) {
  2452. if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
  2453. return -EFAULT;
  2454. portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
  2455. stl_comstats.port);
  2456. if (portp == (stlport_t *) NULL)
  2457. return(-ENODEV);
  2458. }
  2459. memset(&portp->stats, 0, sizeof(comstats_t));
  2460. portp->stats.brd = portp->brdnr;
  2461. portp->stats.panel = portp->panelnr;
  2462. portp->stats.port = portp->portnr;
  2463. return copy_to_user(cp, &portp->stats,
  2464. sizeof(comstats_t)) ? -EFAULT : 0;
  2465. }
  2466. /*****************************************************************************/
  2467. /*
  2468. * Return the entire driver ports structure to a user app.
  2469. */
  2470. static int stl_getportstruct(stlport_t __user *arg)
  2471. {
  2472. stlport_t *portp;
  2473. if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
  2474. return -EFAULT;
  2475. portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
  2476. stl_dummyport.portnr);
  2477. if (!portp)
  2478. return -ENODEV;
  2479. return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
  2480. }
  2481. /*****************************************************************************/
  2482. /*
  2483. * Return the entire driver board structure to a user app.
  2484. */
  2485. static int stl_getbrdstruct(stlbrd_t __user *arg)
  2486. {
  2487. stlbrd_t *brdp;
  2488. if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
  2489. return -EFAULT;
  2490. if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
  2491. return -ENODEV;
  2492. brdp = stl_brds[stl_dummybrd.brdnr];
  2493. if (!brdp)
  2494. return(-ENODEV);
  2495. return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
  2496. }
  2497. /*****************************************************************************/
  2498. /*
  2499. * The "staliomem" device is also required to do some special operations
  2500. * on the board and/or ports. In this driver it is mostly used for stats
  2501. * collection.
  2502. */
  2503. static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  2504. {
  2505. int brdnr, rc;
  2506. void __user *argp = (void __user *)arg;
  2507. #ifdef DEBUG
  2508. printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
  2509. (int) fp, cmd, (int) arg);
  2510. #endif
  2511. brdnr = iminor(ip);
  2512. if (brdnr >= STL_MAXBRDS)
  2513. return(-ENODEV);
  2514. rc = 0;
  2515. switch (cmd) {
  2516. case COM_GETPORTSTATS:
  2517. rc = stl_getportstats(NULL, argp);
  2518. break;
  2519. case COM_CLRPORTSTATS:
  2520. rc = stl_clrportstats(NULL, argp);
  2521. break;
  2522. case COM_GETBRDSTATS:
  2523. rc = stl_getbrdstats(argp);
  2524. break;
  2525. case COM_READPORT:
  2526. rc = stl_getportstruct(argp);
  2527. break;
  2528. case COM_READBOARD:
  2529. rc = stl_getbrdstruct(argp);
  2530. break;
  2531. default:
  2532. rc = -ENOIOCTLCMD;
  2533. break;
  2534. }
  2535. return(rc);
  2536. }
  2537. static struct tty_operations stl_ops = {
  2538. .open = stl_open,
  2539. .close = stl_close,
  2540. .write = stl_write,
  2541. .put_char = stl_putchar,
  2542. .flush_chars = stl_flushchars,
  2543. .write_room = stl_writeroom,
  2544. .chars_in_buffer = stl_charsinbuffer,
  2545. .ioctl = stl_ioctl,
  2546. .set_termios = stl_settermios,
  2547. .throttle = stl_throttle,
  2548. .unthrottle = stl_unthrottle,
  2549. .stop = stl_stop,
  2550. .start = stl_start,
  2551. .hangup = stl_hangup,
  2552. .flush_buffer = stl_flushbuffer,
  2553. .break_ctl = stl_breakctl,
  2554. .wait_until_sent = stl_waituntilsent,
  2555. .send_xchar = stl_sendxchar,
  2556. .read_proc = stl_readproc,
  2557. .tiocmget = stl_tiocmget,
  2558. .tiocmset = stl_tiocmset,
  2559. };
  2560. /*****************************************************************************/
  2561. static int __init stl_init(void)
  2562. {
  2563. int i;
  2564. printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
  2565. spin_lock_init(&stallion_lock);
  2566. spin_lock_init(&brd_lock);
  2567. stl_initbrds();
  2568. stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  2569. if (!stl_serial)
  2570. return -1;
  2571. /*
  2572. * Set up a character driver for per board stuff. This is mainly used
  2573. * to do stats ioctls on the ports.
  2574. */
  2575. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
  2576. printk("STALLION: failed to register serial board device\n");
  2577. stallion_class = class_create(THIS_MODULE, "staliomem");
  2578. for (i = 0; i < 4; i++)
  2579. class_device_create(stallion_class, NULL,
  2580. MKDEV(STL_SIOMEMMAJOR, i), NULL,
  2581. "staliomem%d", i);
  2582. stl_serial->owner = THIS_MODULE;
  2583. stl_serial->driver_name = stl_drvname;
  2584. stl_serial->name = "ttyE";
  2585. stl_serial->major = STL_SERIALMAJOR;
  2586. stl_serial->minor_start = 0;
  2587. stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
  2588. stl_serial->subtype = SERIAL_TYPE_NORMAL;
  2589. stl_serial->init_termios = stl_deftermios;
  2590. stl_serial->flags = TTY_DRIVER_REAL_RAW;
  2591. tty_set_operations(stl_serial, &stl_ops);
  2592. if (tty_register_driver(stl_serial)) {
  2593. put_tty_driver(stl_serial);
  2594. printk("STALLION: failed to register serial driver\n");
  2595. return -1;
  2596. }
  2597. return 0;
  2598. }
  2599. /*****************************************************************************/
  2600. /* CD1400 HARDWARE FUNCTIONS */
  2601. /*****************************************************************************/
  2602. /*
  2603. * These functions get/set/update the registers of the cd1400 UARTs.
  2604. * Access to the cd1400 registers is via an address/data io port pair.
  2605. * (Maybe should make this inline...)
  2606. */
  2607. static int stl_cd1400getreg(stlport_t *portp, int regnr)
  2608. {
  2609. outb((regnr + portp->uartaddr), portp->ioaddr);
  2610. return inb(portp->ioaddr + EREG_DATA);
  2611. }
  2612. static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
  2613. {
  2614. outb((regnr + portp->uartaddr), portp->ioaddr);
  2615. outb(value, portp->ioaddr + EREG_DATA);
  2616. }
  2617. static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
  2618. {
  2619. outb((regnr + portp->uartaddr), portp->ioaddr);
  2620. if (inb(portp->ioaddr + EREG_DATA) != value) {
  2621. outb(value, portp->ioaddr + EREG_DATA);
  2622. return 1;
  2623. }
  2624. return 0;
  2625. }
  2626. /*****************************************************************************/
  2627. /*
  2628. * Inbitialize the UARTs in a panel. We don't care what sort of board
  2629. * these ports are on - since the port io registers are almost
  2630. * identical when dealing with ports.
  2631. */
  2632. static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
  2633. {
  2634. unsigned int gfrcr;
  2635. int chipmask, i, j;
  2636. int nrchips, uartaddr, ioaddr;
  2637. unsigned long flags;
  2638. #ifdef DEBUG
  2639. printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
  2640. #endif
  2641. spin_lock_irqsave(&brd_lock, flags);
  2642. BRDENABLE(panelp->brdnr, panelp->pagenr);
  2643. /*
  2644. * Check that each chip is present and started up OK.
  2645. */
  2646. chipmask = 0;
  2647. nrchips = panelp->nrports / CD1400_PORTS;
  2648. for (i = 0; (i < nrchips); i++) {
  2649. if (brdp->brdtype == BRD_ECHPCI) {
  2650. outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
  2651. ioaddr = panelp->iobase;
  2652. } else {
  2653. ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
  2654. }
  2655. uartaddr = (i & 0x01) ? 0x080 : 0;
  2656. outb((GFRCR + uartaddr), ioaddr);
  2657. outb(0, (ioaddr + EREG_DATA));
  2658. outb((CCR + uartaddr), ioaddr);
  2659. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2660. outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
  2661. outb((GFRCR + uartaddr), ioaddr);
  2662. for (j = 0; (j < CCR_MAXWAIT); j++) {
  2663. if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
  2664. break;
  2665. }
  2666. if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
  2667. printk("STALLION: cd1400 not responding, "
  2668. "brd=%d panel=%d chip=%d\n",
  2669. panelp->brdnr, panelp->panelnr, i);
  2670. continue;
  2671. }
  2672. chipmask |= (0x1 << i);
  2673. outb((PPR + uartaddr), ioaddr);
  2674. outb(PPR_SCALAR, (ioaddr + EREG_DATA));
  2675. }
  2676. BRDDISABLE(panelp->brdnr);
  2677. spin_unlock_irqrestore(&brd_lock, flags);
  2678. return chipmask;
  2679. }
  2680. /*****************************************************************************/
  2681. /*
  2682. * Initialize hardware specific port registers.
  2683. */
  2684. static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
  2685. {
  2686. unsigned long flags;
  2687. #ifdef DEBUG
  2688. printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
  2689. (int) brdp, (int) panelp, (int) portp);
  2690. #endif
  2691. if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
  2692. (portp == (stlport_t *) NULL))
  2693. return;
  2694. spin_lock_irqsave(&brd_lock, flags);
  2695. portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
  2696. (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
  2697. portp->uartaddr = (portp->portnr & 0x04) << 5;
  2698. portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
  2699. BRDENABLE(portp->brdnr, portp->pagenr);
  2700. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2701. stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
  2702. portp->hwid = stl_cd1400getreg(portp, GFRCR);
  2703. BRDDISABLE(portp->brdnr);
  2704. spin_unlock_irqrestore(&brd_lock, flags);
  2705. }
  2706. /*****************************************************************************/
  2707. /*
  2708. * Wait for the command register to be ready. We will poll this,
  2709. * since it won't usually take too long to be ready.
  2710. */
  2711. static void stl_cd1400ccrwait(stlport_t *portp)
  2712. {
  2713. int i;
  2714. for (i = 0; (i < CCR_MAXWAIT); i++) {
  2715. if (stl_cd1400getreg(portp, CCR) == 0) {
  2716. return;
  2717. }
  2718. }
  2719. printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
  2720. portp->portnr, portp->panelnr, portp->brdnr);
  2721. }
  2722. /*****************************************************************************/
  2723. /*
  2724. * Set up the cd1400 registers for a port based on the termios port
  2725. * settings.
  2726. */
  2727. static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
  2728. {
  2729. stlbrd_t *brdp;
  2730. unsigned long flags;
  2731. unsigned int clkdiv, baudrate;
  2732. unsigned char cor1, cor2, cor3;
  2733. unsigned char cor4, cor5, ccr;
  2734. unsigned char srer, sreron, sreroff;
  2735. unsigned char mcor1, mcor2, rtpr;
  2736. unsigned char clk, div;
  2737. cor1 = 0;
  2738. cor2 = 0;
  2739. cor3 = 0;
  2740. cor4 = 0;
  2741. cor5 = 0;
  2742. ccr = 0;
  2743. rtpr = 0;
  2744. clk = 0;
  2745. div = 0;
  2746. mcor1 = 0;
  2747. mcor2 = 0;
  2748. sreron = 0;
  2749. sreroff = 0;
  2750. brdp = stl_brds[portp->brdnr];
  2751. if (brdp == (stlbrd_t *) NULL)
  2752. return;
  2753. /*
  2754. * Set up the RX char ignore mask with those RX error types we
  2755. * can ignore. We can get the cd1400 to help us out a little here,
  2756. * it will ignore parity errors and breaks for us.
  2757. */
  2758. portp->rxignoremsk = 0;
  2759. if (tiosp->c_iflag & IGNPAR) {
  2760. portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
  2761. cor1 |= COR1_PARIGNORE;
  2762. }
  2763. if (tiosp->c_iflag & IGNBRK) {
  2764. portp->rxignoremsk |= ST_BREAK;
  2765. cor4 |= COR4_IGNBRK;
  2766. }
  2767. portp->rxmarkmsk = ST_OVERRUN;
  2768. if (tiosp->c_iflag & (INPCK | PARMRK))
  2769. portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
  2770. if (tiosp->c_iflag & BRKINT)
  2771. portp->rxmarkmsk |= ST_BREAK;
  2772. /*
  2773. * Go through the char size, parity and stop bits and set all the
  2774. * option register appropriately.
  2775. */
  2776. switch (tiosp->c_cflag & CSIZE) {
  2777. case CS5:
  2778. cor1 |= COR1_CHL5;
  2779. break;
  2780. case CS6:
  2781. cor1 |= COR1_CHL6;
  2782. break;
  2783. case CS7:
  2784. cor1 |= COR1_CHL7;
  2785. break;
  2786. default:
  2787. cor1 |= COR1_CHL8;
  2788. break;
  2789. }
  2790. if (tiosp->c_cflag & CSTOPB)
  2791. cor1 |= COR1_STOP2;
  2792. else
  2793. cor1 |= COR1_STOP1;
  2794. if (tiosp->c_cflag & PARENB) {
  2795. if (tiosp->c_cflag & PARODD)
  2796. cor1 |= (COR1_PARENB | COR1_PARODD);
  2797. else
  2798. cor1 |= (COR1_PARENB | COR1_PAREVEN);
  2799. } else {
  2800. cor1 |= COR1_PARNONE;
  2801. }
  2802. /*
  2803. * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
  2804. * space for hardware flow control and the like. This should be set to
  2805. * VMIN. Also here we will set the RX data timeout to 10ms - this should
  2806. * really be based on VTIME.
  2807. */
  2808. cor3 |= FIFO_RXTHRESHOLD;
  2809. rtpr = 2;
  2810. /*
  2811. * Calculate the baud rate timers. For now we will just assume that
  2812. * the input and output baud are the same. Could have used a baud
  2813. * table here, but this way we can generate virtually any baud rate
  2814. * we like!
  2815. */
  2816. baudrate = tiosp->c_cflag & CBAUD;
  2817. if (baudrate & CBAUDEX) {
  2818. baudrate &= ~CBAUDEX;
  2819. if ((baudrate < 1) || (baudrate > 4))
  2820. tiosp->c_cflag &= ~CBAUDEX;
  2821. else
  2822. baudrate += 15;
  2823. }
  2824. baudrate = stl_baudrates[baudrate];
  2825. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2826. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2827. baudrate = 57600;
  2828. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2829. baudrate = 115200;
  2830. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2831. baudrate = 230400;
  2832. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2833. baudrate = 460800;
  2834. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2835. baudrate = (portp->baud_base / portp->custom_divisor);
  2836. }
  2837. if (baudrate > STL_CD1400MAXBAUD)
  2838. baudrate = STL_CD1400MAXBAUD;
  2839. if (baudrate > 0) {
  2840. for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
  2841. clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
  2842. if (clkdiv < 0x100)
  2843. break;
  2844. }
  2845. div = (unsigned char) clkdiv;
  2846. }
  2847. /*
  2848. * Check what form of modem signaling is required and set it up.
  2849. */
  2850. if ((tiosp->c_cflag & CLOCAL) == 0) {
  2851. mcor1 |= MCOR1_DCD;
  2852. mcor2 |= MCOR2_DCD;
  2853. sreron |= SRER_MODEM;
  2854. portp->flags |= ASYNC_CHECK_CD;
  2855. } else {
  2856. portp->flags &= ~ASYNC_CHECK_CD;
  2857. }
  2858. /*
  2859. * Setup cd1400 enhanced modes if we can. In particular we want to
  2860. * handle as much of the flow control as possible automatically. As
  2861. * well as saving a few CPU cycles it will also greatly improve flow
  2862. * control reliability.
  2863. */
  2864. if (tiosp->c_iflag & IXON) {
  2865. cor2 |= COR2_TXIBE;
  2866. cor3 |= COR3_SCD12;
  2867. if (tiosp->c_iflag & IXANY)
  2868. cor2 |= COR2_IXM;
  2869. }
  2870. if (tiosp->c_cflag & CRTSCTS) {
  2871. cor2 |= COR2_CTSAE;
  2872. mcor1 |= FIFO_RTSTHRESHOLD;
  2873. }
  2874. /*
  2875. * All cd1400 register values calculated so go through and set
  2876. * them all up.
  2877. */
  2878. #ifdef DEBUG
  2879. printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  2880. portp->portnr, portp->panelnr, portp->brdnr);
  2881. printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
  2882. cor1, cor2, cor3, cor4, cor5);
  2883. printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
  2884. mcor1, mcor2, rtpr, sreron, sreroff);
  2885. printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
  2886. printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  2887. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  2888. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  2889. #endif
  2890. spin_lock_irqsave(&brd_lock, flags);
  2891. BRDENABLE(portp->brdnr, portp->pagenr);
  2892. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
  2893. srer = stl_cd1400getreg(portp, SRER);
  2894. stl_cd1400setreg(portp, SRER, 0);
  2895. if (stl_cd1400updatereg(portp, COR1, cor1))
  2896. ccr = 1;
  2897. if (stl_cd1400updatereg(portp, COR2, cor2))
  2898. ccr = 1;
  2899. if (stl_cd1400updatereg(portp, COR3, cor3))
  2900. ccr = 1;
  2901. if (ccr) {
  2902. stl_cd1400ccrwait(portp);
  2903. stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
  2904. }
  2905. stl_cd1400setreg(portp, COR4, cor4);
  2906. stl_cd1400setreg(portp, COR5, cor5);
  2907. stl_cd1400setreg(portp, MCOR1, mcor1);
  2908. stl_cd1400setreg(portp, MCOR2, mcor2);
  2909. if (baudrate > 0) {
  2910. stl_cd1400setreg(portp, TCOR, clk);
  2911. stl_cd1400setreg(portp, TBPR, div);
  2912. stl_cd1400setreg(portp, RCOR, clk);
  2913. stl_cd1400setreg(portp, RBPR, div);
  2914. }
  2915. stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
  2916. stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
  2917. stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
  2918. stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
  2919. stl_cd1400setreg(portp, RTPR, rtpr);
  2920. mcor1 = stl_cd1400getreg(portp, MSVR1);
  2921. if (mcor1 & MSVR1_DCD)
  2922. portp->sigs |= TIOCM_CD;
  2923. else
  2924. portp->sigs &= ~TIOCM_CD;
  2925. stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
  2926. BRDDISABLE(portp->brdnr);
  2927. spin_unlock_irqrestore(&brd_lock, flags);
  2928. }
  2929. /*****************************************************************************/
  2930. /*
  2931. * Set the state of the DTR and RTS signals.
  2932. */
  2933. static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
  2934. {
  2935. unsigned char msvr1, msvr2;
  2936. unsigned long flags;
  2937. #ifdef DEBUG
  2938. printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
  2939. (int) portp, dtr, rts);
  2940. #endif
  2941. msvr1 = 0;
  2942. msvr2 = 0;
  2943. if (dtr > 0)
  2944. msvr1 = MSVR1_DTR;
  2945. if (rts > 0)
  2946. msvr2 = MSVR2_RTS;
  2947. spin_lock_irqsave(&brd_lock, flags);
  2948. BRDENABLE(portp->brdnr, portp->pagenr);
  2949. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2950. if (rts >= 0)
  2951. stl_cd1400setreg(portp, MSVR2, msvr2);
  2952. if (dtr >= 0)
  2953. stl_cd1400setreg(portp, MSVR1, msvr1);
  2954. BRDDISABLE(portp->brdnr);
  2955. spin_unlock_irqrestore(&brd_lock, flags);
  2956. }
  2957. /*****************************************************************************/
  2958. /*
  2959. * Return the state of the signals.
  2960. */
  2961. static int stl_cd1400getsignals(stlport_t *portp)
  2962. {
  2963. unsigned char msvr1, msvr2;
  2964. unsigned long flags;
  2965. int sigs;
  2966. #ifdef DEBUG
  2967. printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
  2968. #endif
  2969. spin_lock_irqsave(&brd_lock, flags);
  2970. BRDENABLE(portp->brdnr, portp->pagenr);
  2971. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  2972. msvr1 = stl_cd1400getreg(portp, MSVR1);
  2973. msvr2 = stl_cd1400getreg(portp, MSVR2);
  2974. BRDDISABLE(portp->brdnr);
  2975. spin_unlock_irqrestore(&brd_lock, flags);
  2976. sigs = 0;
  2977. sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
  2978. sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
  2979. sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
  2980. sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
  2981. #if 0
  2982. sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
  2983. sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
  2984. #else
  2985. sigs |= TIOCM_DSR;
  2986. #endif
  2987. return sigs;
  2988. }
  2989. /*****************************************************************************/
  2990. /*
  2991. * Enable/Disable the Transmitter and/or Receiver.
  2992. */
  2993. static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
  2994. {
  2995. unsigned char ccr;
  2996. unsigned long flags;
  2997. #ifdef DEBUG
  2998. printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
  2999. (int) portp, rx, tx);
  3000. #endif
  3001. ccr = 0;
  3002. if (tx == 0)
  3003. ccr |= CCR_TXDISABLE;
  3004. else if (tx > 0)
  3005. ccr |= CCR_TXENABLE;
  3006. if (rx == 0)
  3007. ccr |= CCR_RXDISABLE;
  3008. else if (rx > 0)
  3009. ccr |= CCR_RXENABLE;
  3010. spin_lock_irqsave(&brd_lock, flags);
  3011. BRDENABLE(portp->brdnr, portp->pagenr);
  3012. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3013. stl_cd1400ccrwait(portp);
  3014. stl_cd1400setreg(portp, CCR, ccr);
  3015. stl_cd1400ccrwait(portp);
  3016. BRDDISABLE(portp->brdnr);
  3017. spin_unlock_irqrestore(&brd_lock, flags);
  3018. }
  3019. /*****************************************************************************/
  3020. /*
  3021. * Start/stop the Transmitter and/or Receiver.
  3022. */
  3023. static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
  3024. {
  3025. unsigned char sreron, sreroff;
  3026. unsigned long flags;
  3027. #ifdef DEBUG
  3028. printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
  3029. (int) portp, rx, tx);
  3030. #endif
  3031. sreron = 0;
  3032. sreroff = 0;
  3033. if (tx == 0)
  3034. sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
  3035. else if (tx == 1)
  3036. sreron |= SRER_TXDATA;
  3037. else if (tx >= 2)
  3038. sreron |= SRER_TXEMPTY;
  3039. if (rx == 0)
  3040. sreroff |= SRER_RXDATA;
  3041. else if (rx > 0)
  3042. sreron |= SRER_RXDATA;
  3043. spin_lock_irqsave(&brd_lock, flags);
  3044. BRDENABLE(portp->brdnr, portp->pagenr);
  3045. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3046. stl_cd1400setreg(portp, SRER,
  3047. ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
  3048. BRDDISABLE(portp->brdnr);
  3049. if (tx > 0)
  3050. set_bit(ASYI_TXBUSY, &portp->istate);
  3051. spin_unlock_irqrestore(&brd_lock, flags);
  3052. }
  3053. /*****************************************************************************/
  3054. /*
  3055. * Disable all interrupts from this port.
  3056. */
  3057. static void stl_cd1400disableintrs(stlport_t *portp)
  3058. {
  3059. unsigned long flags;
  3060. #ifdef DEBUG
  3061. printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
  3062. #endif
  3063. spin_lock_irqsave(&brd_lock, flags);
  3064. BRDENABLE(portp->brdnr, portp->pagenr);
  3065. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3066. stl_cd1400setreg(portp, SRER, 0);
  3067. BRDDISABLE(portp->brdnr);
  3068. spin_unlock_irqrestore(&brd_lock, flags);
  3069. }
  3070. /*****************************************************************************/
  3071. static void stl_cd1400sendbreak(stlport_t *portp, int len)
  3072. {
  3073. unsigned long flags;
  3074. #ifdef DEBUG
  3075. printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
  3076. #endif
  3077. spin_lock_irqsave(&brd_lock, flags);
  3078. BRDENABLE(portp->brdnr, portp->pagenr);
  3079. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3080. stl_cd1400setreg(portp, SRER,
  3081. ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
  3082. SRER_TXEMPTY));
  3083. BRDDISABLE(portp->brdnr);
  3084. portp->brklen = len;
  3085. if (len == 1)
  3086. portp->stats.txbreaks++;
  3087. spin_unlock_irqrestore(&brd_lock, flags);
  3088. }
  3089. /*****************************************************************************/
  3090. /*
  3091. * Take flow control actions...
  3092. */
  3093. static void stl_cd1400flowctrl(stlport_t *portp, int state)
  3094. {
  3095. struct tty_struct *tty;
  3096. unsigned long flags;
  3097. #ifdef DEBUG
  3098. printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
  3099. #endif
  3100. if (portp == (stlport_t *) NULL)
  3101. return;
  3102. tty = portp->tty;
  3103. if (tty == (struct tty_struct *) NULL)
  3104. return;
  3105. spin_lock_irqsave(&brd_lock, flags);
  3106. BRDENABLE(portp->brdnr, portp->pagenr);
  3107. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3108. if (state) {
  3109. if (tty->termios->c_iflag & IXOFF) {
  3110. stl_cd1400ccrwait(portp);
  3111. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  3112. portp->stats.rxxon++;
  3113. stl_cd1400ccrwait(portp);
  3114. }
  3115. /*
  3116. * Question: should we return RTS to what it was before? It may
  3117. * have been set by an ioctl... Suppose not, since if you have
  3118. * hardware flow control set then it is pretty silly to go and
  3119. * set the RTS line by hand.
  3120. */
  3121. if (tty->termios->c_cflag & CRTSCTS) {
  3122. stl_cd1400setreg(portp, MCOR1,
  3123. (stl_cd1400getreg(portp, MCOR1) |
  3124. FIFO_RTSTHRESHOLD));
  3125. stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
  3126. portp->stats.rxrtson++;
  3127. }
  3128. } else {
  3129. if (tty->termios->c_iflag & IXOFF) {
  3130. stl_cd1400ccrwait(portp);
  3131. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  3132. portp->stats.rxxoff++;
  3133. stl_cd1400ccrwait(portp);
  3134. }
  3135. if (tty->termios->c_cflag & CRTSCTS) {
  3136. stl_cd1400setreg(portp, MCOR1,
  3137. (stl_cd1400getreg(portp, MCOR1) & 0xf0));
  3138. stl_cd1400setreg(portp, MSVR2, 0);
  3139. portp->stats.rxrtsoff++;
  3140. }
  3141. }
  3142. BRDDISABLE(portp->brdnr);
  3143. spin_unlock_irqrestore(&brd_lock, flags);
  3144. }
  3145. /*****************************************************************************/
  3146. /*
  3147. * Send a flow control character...
  3148. */
  3149. static void stl_cd1400sendflow(stlport_t *portp, int state)
  3150. {
  3151. struct tty_struct *tty;
  3152. unsigned long flags;
  3153. #ifdef DEBUG
  3154. printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
  3155. #endif
  3156. if (portp == (stlport_t *) NULL)
  3157. return;
  3158. tty = portp->tty;
  3159. if (tty == (struct tty_struct *) NULL)
  3160. return;
  3161. spin_lock_irqsave(&brd_lock, flags);
  3162. BRDENABLE(portp->brdnr, portp->pagenr);
  3163. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3164. if (state) {
  3165. stl_cd1400ccrwait(portp);
  3166. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
  3167. portp->stats.rxxon++;
  3168. stl_cd1400ccrwait(portp);
  3169. } else {
  3170. stl_cd1400ccrwait(portp);
  3171. stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
  3172. portp->stats.rxxoff++;
  3173. stl_cd1400ccrwait(portp);
  3174. }
  3175. BRDDISABLE(portp->brdnr);
  3176. spin_unlock_irqrestore(&brd_lock, flags);
  3177. }
  3178. /*****************************************************************************/
  3179. static void stl_cd1400flush(stlport_t *portp)
  3180. {
  3181. unsigned long flags;
  3182. #ifdef DEBUG
  3183. printk("stl_cd1400flush(portp=%x)\n", (int) portp);
  3184. #endif
  3185. if (portp == (stlport_t *) NULL)
  3186. return;
  3187. spin_lock_irqsave(&brd_lock, flags);
  3188. BRDENABLE(portp->brdnr, portp->pagenr);
  3189. stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
  3190. stl_cd1400ccrwait(portp);
  3191. stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
  3192. stl_cd1400ccrwait(portp);
  3193. portp->tx.tail = portp->tx.head;
  3194. BRDDISABLE(portp->brdnr);
  3195. spin_unlock_irqrestore(&brd_lock, flags);
  3196. }
  3197. /*****************************************************************************/
  3198. /*
  3199. * Return the current state of data flow on this port. This is only
  3200. * really interresting when determining if data has fully completed
  3201. * transmission or not... This is easy for the cd1400, it accurately
  3202. * maintains the busy port flag.
  3203. */
  3204. static int stl_cd1400datastate(stlport_t *portp)
  3205. {
  3206. #ifdef DEBUG
  3207. printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
  3208. #endif
  3209. if (portp == (stlport_t *) NULL)
  3210. return 0;
  3211. return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
  3212. }
  3213. /*****************************************************************************/
  3214. /*
  3215. * Interrupt service routine for cd1400 EasyIO boards.
  3216. */
  3217. static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
  3218. {
  3219. unsigned char svrtype;
  3220. #ifdef DEBUG
  3221. printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
  3222. (int) panelp, iobase);
  3223. #endif
  3224. spin_lock(&brd_lock);
  3225. outb(SVRR, iobase);
  3226. svrtype = inb(iobase + EREG_DATA);
  3227. if (panelp->nrports > 4) {
  3228. outb((SVRR + 0x80), iobase);
  3229. svrtype |= inb(iobase + EREG_DATA);
  3230. }
  3231. if (svrtype & SVRR_RX)
  3232. stl_cd1400rxisr(panelp, iobase);
  3233. else if (svrtype & SVRR_TX)
  3234. stl_cd1400txisr(panelp, iobase);
  3235. else if (svrtype & SVRR_MDM)
  3236. stl_cd1400mdmisr(panelp, iobase);
  3237. spin_unlock(&brd_lock);
  3238. }
  3239. /*****************************************************************************/
  3240. /*
  3241. * Interrupt service routine for cd1400 panels.
  3242. */
  3243. static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
  3244. {
  3245. unsigned char svrtype;
  3246. #ifdef DEBUG
  3247. printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
  3248. iobase);
  3249. #endif
  3250. outb(SVRR, iobase);
  3251. svrtype = inb(iobase + EREG_DATA);
  3252. outb((SVRR + 0x80), iobase);
  3253. svrtype |= inb(iobase + EREG_DATA);
  3254. if (svrtype & SVRR_RX)
  3255. stl_cd1400rxisr(panelp, iobase);
  3256. else if (svrtype & SVRR_TX)
  3257. stl_cd1400txisr(panelp, iobase);
  3258. else if (svrtype & SVRR_MDM)
  3259. stl_cd1400mdmisr(panelp, iobase);
  3260. }
  3261. /*****************************************************************************/
  3262. /*
  3263. * Unfortunately we need to handle breaks in the TX data stream, since
  3264. * this is the only way to generate them on the cd1400.
  3265. */
  3266. static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
  3267. {
  3268. if (portp->brklen == 1) {
  3269. outb((COR2 + portp->uartaddr), ioaddr);
  3270. outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
  3271. (ioaddr + EREG_DATA));
  3272. outb((TDR + portp->uartaddr), ioaddr);
  3273. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3274. outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
  3275. outb((SRER + portp->uartaddr), ioaddr);
  3276. outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
  3277. (ioaddr + EREG_DATA));
  3278. return 1;
  3279. } else if (portp->brklen > 1) {
  3280. outb((TDR + portp->uartaddr), ioaddr);
  3281. outb(ETC_CMD, (ioaddr + EREG_DATA));
  3282. outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
  3283. portp->brklen = -1;
  3284. return 1;
  3285. } else {
  3286. outb((COR2 + portp->uartaddr), ioaddr);
  3287. outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
  3288. (ioaddr + EREG_DATA));
  3289. portp->brklen = 0;
  3290. }
  3291. return 0;
  3292. }
  3293. /*****************************************************************************/
  3294. /*
  3295. * Transmit interrupt handler. This has gotta be fast! Handling TX
  3296. * chars is pretty simple, stuff as many as possible from the TX buffer
  3297. * into the cd1400 FIFO. Must also handle TX breaks here, since they
  3298. * are embedded as commands in the data stream. Oh no, had to use a goto!
  3299. * This could be optimized more, will do when I get time...
  3300. * In practice it is possible that interrupts are enabled but that the
  3301. * port has been hung up. Need to handle not having any TX buffer here,
  3302. * this is done by using the side effect that head and tail will also
  3303. * be NULL if the buffer has been freed.
  3304. */
  3305. static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
  3306. {
  3307. stlport_t *portp;
  3308. int len, stlen;
  3309. char *head, *tail;
  3310. unsigned char ioack, srer;
  3311. #ifdef DEBUG
  3312. printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
  3313. #endif
  3314. ioack = inb(ioaddr + EREG_TXACK);
  3315. if (((ioack & panelp->ackmask) != 0) ||
  3316. ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
  3317. printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
  3318. return;
  3319. }
  3320. portp = panelp->ports[(ioack >> 3)];
  3321. /*
  3322. * Unfortunately we need to handle breaks in the data stream, since
  3323. * this is the only way to generate them on the cd1400. Do it now if
  3324. * a break is to be sent.
  3325. */
  3326. if (portp->brklen != 0)
  3327. if (stl_cd1400breakisr(portp, ioaddr))
  3328. goto stl_txalldone;
  3329. head = portp->tx.head;
  3330. tail = portp->tx.tail;
  3331. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  3332. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  3333. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  3334. set_bit(ASYI_TXLOW, &portp->istate);
  3335. schedule_work(&portp->tqueue);
  3336. }
  3337. if (len == 0) {
  3338. outb((SRER + portp->uartaddr), ioaddr);
  3339. srer = inb(ioaddr + EREG_DATA);
  3340. if (srer & SRER_TXDATA) {
  3341. srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
  3342. } else {
  3343. srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
  3344. clear_bit(ASYI_TXBUSY, &portp->istate);
  3345. }
  3346. outb(srer, (ioaddr + EREG_DATA));
  3347. } else {
  3348. len = MIN(len, CD1400_TXFIFOSIZE);
  3349. portp->stats.txtotal += len;
  3350. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  3351. outb((TDR + portp->uartaddr), ioaddr);
  3352. outsb((ioaddr + EREG_DATA), tail, stlen);
  3353. len -= stlen;
  3354. tail += stlen;
  3355. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  3356. tail = portp->tx.buf;
  3357. if (len > 0) {
  3358. outsb((ioaddr + EREG_DATA), tail, len);
  3359. tail += len;
  3360. }
  3361. portp->tx.tail = tail;
  3362. }
  3363. stl_txalldone:
  3364. outb((EOSRR + portp->uartaddr), ioaddr);
  3365. outb(0, (ioaddr + EREG_DATA));
  3366. }
  3367. /*****************************************************************************/
  3368. /*
  3369. * Receive character interrupt handler. Determine if we have good chars
  3370. * or bad chars and then process appropriately. Good chars are easy
  3371. * just shove the lot into the RX buffer and set all status byte to 0.
  3372. * If a bad RX char then process as required. This routine needs to be
  3373. * fast! In practice it is possible that we get an interrupt on a port
  3374. * that is closed. This can happen on hangups - since they completely
  3375. * shutdown a port not in user context. Need to handle this case.
  3376. */
  3377. static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
  3378. {
  3379. stlport_t *portp;
  3380. struct tty_struct *tty;
  3381. unsigned int ioack, len, buflen;
  3382. unsigned char status;
  3383. char ch;
  3384. #ifdef DEBUG
  3385. printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
  3386. #endif
  3387. ioack = inb(ioaddr + EREG_RXACK);
  3388. if ((ioack & panelp->ackmask) != 0) {
  3389. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3390. return;
  3391. }
  3392. portp = panelp->ports[(ioack >> 3)];
  3393. tty = portp->tty;
  3394. if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
  3395. outb((RDCR + portp->uartaddr), ioaddr);
  3396. len = inb(ioaddr + EREG_DATA);
  3397. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  3398. len = MIN(len, sizeof(stl_unwanted));
  3399. outb((RDSR + portp->uartaddr), ioaddr);
  3400. insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
  3401. portp->stats.rxlost += len;
  3402. portp->stats.rxtotal += len;
  3403. } else {
  3404. len = MIN(len, buflen);
  3405. if (len > 0) {
  3406. unsigned char *ptr;
  3407. outb((RDSR + portp->uartaddr), ioaddr);
  3408. tty_prepare_flip_string(tty, &ptr, len);
  3409. insb((ioaddr + EREG_DATA), ptr, len);
  3410. tty_schedule_flip(tty);
  3411. portp->stats.rxtotal += len;
  3412. }
  3413. }
  3414. } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
  3415. outb((RDSR + portp->uartaddr), ioaddr);
  3416. status = inb(ioaddr + EREG_DATA);
  3417. ch = inb(ioaddr + EREG_DATA);
  3418. if (status & ST_PARITY)
  3419. portp->stats.rxparity++;
  3420. if (status & ST_FRAMING)
  3421. portp->stats.rxframing++;
  3422. if (status & ST_OVERRUN)
  3423. portp->stats.rxoverrun++;
  3424. if (status & ST_BREAK)
  3425. portp->stats.rxbreaks++;
  3426. if (status & ST_SCHARMASK) {
  3427. if ((status & ST_SCHARMASK) == ST_SCHAR1)
  3428. portp->stats.txxon++;
  3429. if ((status & ST_SCHARMASK) == ST_SCHAR2)
  3430. portp->stats.txxoff++;
  3431. goto stl_rxalldone;
  3432. }
  3433. if (tty != NULL && (portp->rxignoremsk & status) == 0) {
  3434. if (portp->rxmarkmsk & status) {
  3435. if (status & ST_BREAK) {
  3436. status = TTY_BREAK;
  3437. if (portp->flags & ASYNC_SAK) {
  3438. do_SAK(tty);
  3439. BRDENABLE(portp->brdnr, portp->pagenr);
  3440. }
  3441. } else if (status & ST_PARITY) {
  3442. status = TTY_PARITY;
  3443. } else if (status & ST_FRAMING) {
  3444. status = TTY_FRAME;
  3445. } else if(status & ST_OVERRUN) {
  3446. status = TTY_OVERRUN;
  3447. } else {
  3448. status = 0;
  3449. }
  3450. } else {
  3451. status = 0;
  3452. }
  3453. tty_insert_flip_char(tty, ch, status);
  3454. tty_schedule_flip(tty);
  3455. }
  3456. } else {
  3457. printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
  3458. return;
  3459. }
  3460. stl_rxalldone:
  3461. outb((EOSRR + portp->uartaddr), ioaddr);
  3462. outb(0, (ioaddr + EREG_DATA));
  3463. }
  3464. /*****************************************************************************/
  3465. /*
  3466. * Modem interrupt handler. The is called when the modem signal line
  3467. * (DCD) has changed state. Leave most of the work to the off-level
  3468. * processing routine.
  3469. */
  3470. static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
  3471. {
  3472. stlport_t *portp;
  3473. unsigned int ioack;
  3474. unsigned char misr;
  3475. #ifdef DEBUG
  3476. printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
  3477. #endif
  3478. ioack = inb(ioaddr + EREG_MDACK);
  3479. if (((ioack & panelp->ackmask) != 0) ||
  3480. ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
  3481. printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
  3482. return;
  3483. }
  3484. portp = panelp->ports[(ioack >> 3)];
  3485. outb((MISR + portp->uartaddr), ioaddr);
  3486. misr = inb(ioaddr + EREG_DATA);
  3487. if (misr & MISR_DCD) {
  3488. set_bit(ASYI_DCDCHANGE, &portp->istate);
  3489. schedule_work(&portp->tqueue);
  3490. portp->stats.modem++;
  3491. }
  3492. outb((EOSRR + portp->uartaddr), ioaddr);
  3493. outb(0, (ioaddr + EREG_DATA));
  3494. }
  3495. /*****************************************************************************/
  3496. /* SC26198 HARDWARE FUNCTIONS */
  3497. /*****************************************************************************/
  3498. /*
  3499. * These functions get/set/update the registers of the sc26198 UARTs.
  3500. * Access to the sc26198 registers is via an address/data io port pair.
  3501. * (Maybe should make this inline...)
  3502. */
  3503. static int stl_sc26198getreg(stlport_t *portp, int regnr)
  3504. {
  3505. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3506. return inb(portp->ioaddr + XP_DATA);
  3507. }
  3508. static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
  3509. {
  3510. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3511. outb(value, (portp->ioaddr + XP_DATA));
  3512. }
  3513. static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
  3514. {
  3515. outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
  3516. if (inb(portp->ioaddr + XP_DATA) != value) {
  3517. outb(value, (portp->ioaddr + XP_DATA));
  3518. return 1;
  3519. }
  3520. return 0;
  3521. }
  3522. /*****************************************************************************/
  3523. /*
  3524. * Functions to get and set the sc26198 global registers.
  3525. */
  3526. static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
  3527. {
  3528. outb(regnr, (portp->ioaddr + XP_ADDR));
  3529. return inb(portp->ioaddr + XP_DATA);
  3530. }
  3531. #if 0
  3532. static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
  3533. {
  3534. outb(regnr, (portp->ioaddr + XP_ADDR));
  3535. outb(value, (portp->ioaddr + XP_DATA));
  3536. }
  3537. #endif
  3538. /*****************************************************************************/
  3539. /*
  3540. * Inbitialize the UARTs in a panel. We don't care what sort of board
  3541. * these ports are on - since the port io registers are almost
  3542. * identical when dealing with ports.
  3543. */
  3544. static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
  3545. {
  3546. int chipmask, i;
  3547. int nrchips, ioaddr;
  3548. #ifdef DEBUG
  3549. printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
  3550. (int) brdp, (int) panelp);
  3551. #endif
  3552. BRDENABLE(panelp->brdnr, panelp->pagenr);
  3553. /*
  3554. * Check that each chip is present and started up OK.
  3555. */
  3556. chipmask = 0;
  3557. nrchips = (panelp->nrports + 4) / SC26198_PORTS;
  3558. if (brdp->brdtype == BRD_ECHPCI)
  3559. outb(panelp->pagenr, brdp->ioctrl);
  3560. for (i = 0; (i < nrchips); i++) {
  3561. ioaddr = panelp->iobase + (i * 4);
  3562. outb(SCCR, (ioaddr + XP_ADDR));
  3563. outb(CR_RESETALL, (ioaddr + XP_DATA));
  3564. outb(TSTR, (ioaddr + XP_ADDR));
  3565. if (inb(ioaddr + XP_DATA) != 0) {
  3566. printk("STALLION: sc26198 not responding, "
  3567. "brd=%d panel=%d chip=%d\n",
  3568. panelp->brdnr, panelp->panelnr, i);
  3569. continue;
  3570. }
  3571. chipmask |= (0x1 << i);
  3572. outb(GCCR, (ioaddr + XP_ADDR));
  3573. outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
  3574. outb(WDTRCR, (ioaddr + XP_ADDR));
  3575. outb(0xff, (ioaddr + XP_DATA));
  3576. }
  3577. BRDDISABLE(panelp->brdnr);
  3578. return chipmask;
  3579. }
  3580. /*****************************************************************************/
  3581. /*
  3582. * Initialize hardware specific port registers.
  3583. */
  3584. static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
  3585. {
  3586. #ifdef DEBUG
  3587. printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
  3588. (int) brdp, (int) panelp, (int) portp);
  3589. #endif
  3590. if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
  3591. (portp == (stlport_t *) NULL))
  3592. return;
  3593. portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
  3594. portp->uartaddr = (portp->portnr & 0x07) << 4;
  3595. portp->pagenr = panelp->pagenr;
  3596. portp->hwid = 0x1;
  3597. BRDENABLE(portp->brdnr, portp->pagenr);
  3598. stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
  3599. BRDDISABLE(portp->brdnr);
  3600. }
  3601. /*****************************************************************************/
  3602. /*
  3603. * Set up the sc26198 registers for a port based on the termios port
  3604. * settings.
  3605. */
  3606. static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
  3607. {
  3608. stlbrd_t *brdp;
  3609. unsigned long flags;
  3610. unsigned int baudrate;
  3611. unsigned char mr0, mr1, mr2, clk;
  3612. unsigned char imron, imroff, iopr, ipr;
  3613. mr0 = 0;
  3614. mr1 = 0;
  3615. mr2 = 0;
  3616. clk = 0;
  3617. iopr = 0;
  3618. imron = 0;
  3619. imroff = 0;
  3620. brdp = stl_brds[portp->brdnr];
  3621. if (brdp == (stlbrd_t *) NULL)
  3622. return;
  3623. /*
  3624. * Set up the RX char ignore mask with those RX error types we
  3625. * can ignore.
  3626. */
  3627. portp->rxignoremsk = 0;
  3628. if (tiosp->c_iflag & IGNPAR)
  3629. portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
  3630. SR_RXOVERRUN);
  3631. if (tiosp->c_iflag & IGNBRK)
  3632. portp->rxignoremsk |= SR_RXBREAK;
  3633. portp->rxmarkmsk = SR_RXOVERRUN;
  3634. if (tiosp->c_iflag & (INPCK | PARMRK))
  3635. portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
  3636. if (tiosp->c_iflag & BRKINT)
  3637. portp->rxmarkmsk |= SR_RXBREAK;
  3638. /*
  3639. * Go through the char size, parity and stop bits and set all the
  3640. * option register appropriately.
  3641. */
  3642. switch (tiosp->c_cflag & CSIZE) {
  3643. case CS5:
  3644. mr1 |= MR1_CS5;
  3645. break;
  3646. case CS6:
  3647. mr1 |= MR1_CS6;
  3648. break;
  3649. case CS7:
  3650. mr1 |= MR1_CS7;
  3651. break;
  3652. default:
  3653. mr1 |= MR1_CS8;
  3654. break;
  3655. }
  3656. if (tiosp->c_cflag & CSTOPB)
  3657. mr2 |= MR2_STOP2;
  3658. else
  3659. mr2 |= MR2_STOP1;
  3660. if (tiosp->c_cflag & PARENB) {
  3661. if (tiosp->c_cflag & PARODD)
  3662. mr1 |= (MR1_PARENB | MR1_PARODD);
  3663. else
  3664. mr1 |= (MR1_PARENB | MR1_PAREVEN);
  3665. } else {
  3666. mr1 |= MR1_PARNONE;
  3667. }
  3668. mr1 |= MR1_ERRBLOCK;
  3669. /*
  3670. * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
  3671. * space for hardware flow control and the like. This should be set to
  3672. * VMIN.
  3673. */
  3674. mr2 |= MR2_RXFIFOHALF;
  3675. /*
  3676. * Calculate the baud rate timers. For now we will just assume that
  3677. * the input and output baud are the same. The sc26198 has a fixed
  3678. * baud rate table, so only discrete baud rates possible.
  3679. */
  3680. baudrate = tiosp->c_cflag & CBAUD;
  3681. if (baudrate & CBAUDEX) {
  3682. baudrate &= ~CBAUDEX;
  3683. if ((baudrate < 1) || (baudrate > 4))
  3684. tiosp->c_cflag &= ~CBAUDEX;
  3685. else
  3686. baudrate += 15;
  3687. }
  3688. baudrate = stl_baudrates[baudrate];
  3689. if ((tiosp->c_cflag & CBAUD) == B38400) {
  3690. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  3691. baudrate = 57600;
  3692. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  3693. baudrate = 115200;
  3694. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  3695. baudrate = 230400;
  3696. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  3697. baudrate = 460800;
  3698. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  3699. baudrate = (portp->baud_base / portp->custom_divisor);
  3700. }
  3701. if (baudrate > STL_SC26198MAXBAUD)
  3702. baudrate = STL_SC26198MAXBAUD;
  3703. if (baudrate > 0) {
  3704. for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
  3705. if (baudrate <= sc26198_baudtable[clk])
  3706. break;
  3707. }
  3708. }
  3709. /*
  3710. * Check what form of modem signaling is required and set it up.
  3711. */
  3712. if (tiosp->c_cflag & CLOCAL) {
  3713. portp->flags &= ~ASYNC_CHECK_CD;
  3714. } else {
  3715. iopr |= IOPR_DCDCOS;
  3716. imron |= IR_IOPORT;
  3717. portp->flags |= ASYNC_CHECK_CD;
  3718. }
  3719. /*
  3720. * Setup sc26198 enhanced modes if we can. In particular we want to
  3721. * handle as much of the flow control as possible automatically. As
  3722. * well as saving a few CPU cycles it will also greatly improve flow
  3723. * control reliability.
  3724. */
  3725. if (tiosp->c_iflag & IXON) {
  3726. mr0 |= MR0_SWFTX | MR0_SWFT;
  3727. imron |= IR_XONXOFF;
  3728. } else {
  3729. imroff |= IR_XONXOFF;
  3730. }
  3731. if (tiosp->c_iflag & IXOFF)
  3732. mr0 |= MR0_SWFRX;
  3733. if (tiosp->c_cflag & CRTSCTS) {
  3734. mr2 |= MR2_AUTOCTS;
  3735. mr1 |= MR1_AUTORTS;
  3736. }
  3737. /*
  3738. * All sc26198 register values calculated so go through and set
  3739. * them all up.
  3740. */
  3741. #ifdef DEBUG
  3742. printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
  3743. portp->portnr, portp->panelnr, portp->brdnr);
  3744. printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
  3745. printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
  3746. printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
  3747. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
  3748. tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
  3749. #endif
  3750. spin_lock_irqsave(&brd_lock, flags);
  3751. BRDENABLE(portp->brdnr, portp->pagenr);
  3752. stl_sc26198setreg(portp, IMR, 0);
  3753. stl_sc26198updatereg(portp, MR0, mr0);
  3754. stl_sc26198updatereg(portp, MR1, mr1);
  3755. stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
  3756. stl_sc26198updatereg(portp, MR2, mr2);
  3757. stl_sc26198updatereg(portp, IOPIOR,
  3758. ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
  3759. if (baudrate > 0) {
  3760. stl_sc26198setreg(portp, TXCSR, clk);
  3761. stl_sc26198setreg(portp, RXCSR, clk);
  3762. }
  3763. stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
  3764. stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
  3765. ipr = stl_sc26198getreg(portp, IPR);
  3766. if (ipr & IPR_DCD)
  3767. portp->sigs &= ~TIOCM_CD;
  3768. else
  3769. portp->sigs |= TIOCM_CD;
  3770. portp->imr = (portp->imr & ~imroff) | imron;
  3771. stl_sc26198setreg(portp, IMR, portp->imr);
  3772. BRDDISABLE(portp->brdnr);
  3773. spin_unlock_irqrestore(&brd_lock, flags);
  3774. }
  3775. /*****************************************************************************/
  3776. /*
  3777. * Set the state of the DTR and RTS signals.
  3778. */
  3779. static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
  3780. {
  3781. unsigned char iopioron, iopioroff;
  3782. unsigned long flags;
  3783. #ifdef DEBUG
  3784. printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
  3785. (int) portp, dtr, rts);
  3786. #endif
  3787. iopioron = 0;
  3788. iopioroff = 0;
  3789. if (dtr == 0)
  3790. iopioroff |= IPR_DTR;
  3791. else if (dtr > 0)
  3792. iopioron |= IPR_DTR;
  3793. if (rts == 0)
  3794. iopioroff |= IPR_RTS;
  3795. else if (rts > 0)
  3796. iopioron |= IPR_RTS;
  3797. spin_lock_irqsave(&brd_lock, flags);
  3798. BRDENABLE(portp->brdnr, portp->pagenr);
  3799. stl_sc26198setreg(portp, IOPIOR,
  3800. ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
  3801. BRDDISABLE(portp->brdnr);
  3802. spin_unlock_irqrestore(&brd_lock, flags);
  3803. }
  3804. /*****************************************************************************/
  3805. /*
  3806. * Return the state of the signals.
  3807. */
  3808. static int stl_sc26198getsignals(stlport_t *portp)
  3809. {
  3810. unsigned char ipr;
  3811. unsigned long flags;
  3812. int sigs;
  3813. #ifdef DEBUG
  3814. printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
  3815. #endif
  3816. spin_lock_irqsave(&brd_lock, flags);
  3817. BRDENABLE(portp->brdnr, portp->pagenr);
  3818. ipr = stl_sc26198getreg(portp, IPR);
  3819. BRDDISABLE(portp->brdnr);
  3820. spin_unlock_irqrestore(&brd_lock, flags);
  3821. sigs = 0;
  3822. sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
  3823. sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
  3824. sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
  3825. sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
  3826. sigs |= TIOCM_DSR;
  3827. return sigs;
  3828. }
  3829. /*****************************************************************************/
  3830. /*
  3831. * Enable/Disable the Transmitter and/or Receiver.
  3832. */
  3833. static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
  3834. {
  3835. unsigned char ccr;
  3836. unsigned long flags;
  3837. #ifdef DEBUG
  3838. printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
  3839. (int) portp, rx, tx);
  3840. #endif
  3841. ccr = portp->crenable;
  3842. if (tx == 0)
  3843. ccr &= ~CR_TXENABLE;
  3844. else if (tx > 0)
  3845. ccr |= CR_TXENABLE;
  3846. if (rx == 0)
  3847. ccr &= ~CR_RXENABLE;
  3848. else if (rx > 0)
  3849. ccr |= CR_RXENABLE;
  3850. spin_lock_irqsave(&brd_lock, flags);
  3851. BRDENABLE(portp->brdnr, portp->pagenr);
  3852. stl_sc26198setreg(portp, SCCR, ccr);
  3853. BRDDISABLE(portp->brdnr);
  3854. portp->crenable = ccr;
  3855. spin_unlock_irqrestore(&brd_lock, flags);
  3856. }
  3857. /*****************************************************************************/
  3858. /*
  3859. * Start/stop the Transmitter and/or Receiver.
  3860. */
  3861. static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
  3862. {
  3863. unsigned char imr;
  3864. unsigned long flags;
  3865. #ifdef DEBUG
  3866. printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
  3867. (int) portp, rx, tx);
  3868. #endif
  3869. imr = portp->imr;
  3870. if (tx == 0)
  3871. imr &= ~IR_TXRDY;
  3872. else if (tx == 1)
  3873. imr |= IR_TXRDY;
  3874. if (rx == 0)
  3875. imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
  3876. else if (rx > 0)
  3877. imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
  3878. spin_lock_irqsave(&brd_lock, flags);
  3879. BRDENABLE(portp->brdnr, portp->pagenr);
  3880. stl_sc26198setreg(portp, IMR, imr);
  3881. BRDDISABLE(portp->brdnr);
  3882. portp->imr = imr;
  3883. if (tx > 0)
  3884. set_bit(ASYI_TXBUSY, &portp->istate);
  3885. spin_unlock_irqrestore(&brd_lock, flags);
  3886. }
  3887. /*****************************************************************************/
  3888. /*
  3889. * Disable all interrupts from this port.
  3890. */
  3891. static void stl_sc26198disableintrs(stlport_t *portp)
  3892. {
  3893. unsigned long flags;
  3894. #ifdef DEBUG
  3895. printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
  3896. #endif
  3897. spin_lock_irqsave(&brd_lock, flags);
  3898. BRDENABLE(portp->brdnr, portp->pagenr);
  3899. portp->imr = 0;
  3900. stl_sc26198setreg(portp, IMR, 0);
  3901. BRDDISABLE(portp->brdnr);
  3902. spin_unlock_irqrestore(&brd_lock, flags);
  3903. }
  3904. /*****************************************************************************/
  3905. static void stl_sc26198sendbreak(stlport_t *portp, int len)
  3906. {
  3907. unsigned long flags;
  3908. #ifdef DEBUG
  3909. printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
  3910. #endif
  3911. spin_lock_irqsave(&brd_lock, flags);
  3912. BRDENABLE(portp->brdnr, portp->pagenr);
  3913. if (len == 1) {
  3914. stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
  3915. portp->stats.txbreaks++;
  3916. } else {
  3917. stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
  3918. }
  3919. BRDDISABLE(portp->brdnr);
  3920. spin_unlock_irqrestore(&brd_lock, flags);
  3921. }
  3922. /*****************************************************************************/
  3923. /*
  3924. * Take flow control actions...
  3925. */
  3926. static void stl_sc26198flowctrl(stlport_t *portp, int state)
  3927. {
  3928. struct tty_struct *tty;
  3929. unsigned long flags;
  3930. unsigned char mr0;
  3931. #ifdef DEBUG
  3932. printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
  3933. #endif
  3934. if (portp == (stlport_t *) NULL)
  3935. return;
  3936. tty = portp->tty;
  3937. if (tty == (struct tty_struct *) NULL)
  3938. return;
  3939. spin_lock_irqsave(&brd_lock, flags);
  3940. BRDENABLE(portp->brdnr, portp->pagenr);
  3941. if (state) {
  3942. if (tty->termios->c_iflag & IXOFF) {
  3943. mr0 = stl_sc26198getreg(portp, MR0);
  3944. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3945. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  3946. mr0 |= MR0_SWFRX;
  3947. portp->stats.rxxon++;
  3948. stl_sc26198wait(portp);
  3949. stl_sc26198setreg(portp, MR0, mr0);
  3950. }
  3951. /*
  3952. * Question: should we return RTS to what it was before? It may
  3953. * have been set by an ioctl... Suppose not, since if you have
  3954. * hardware flow control set then it is pretty silly to go and
  3955. * set the RTS line by hand.
  3956. */
  3957. if (tty->termios->c_cflag & CRTSCTS) {
  3958. stl_sc26198setreg(portp, MR1,
  3959. (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
  3960. stl_sc26198setreg(portp, IOPIOR,
  3961. (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
  3962. portp->stats.rxrtson++;
  3963. }
  3964. } else {
  3965. if (tty->termios->c_iflag & IXOFF) {
  3966. mr0 = stl_sc26198getreg(portp, MR0);
  3967. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  3968. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  3969. mr0 &= ~MR0_SWFRX;
  3970. portp->stats.rxxoff++;
  3971. stl_sc26198wait(portp);
  3972. stl_sc26198setreg(portp, MR0, mr0);
  3973. }
  3974. if (tty->termios->c_cflag & CRTSCTS) {
  3975. stl_sc26198setreg(portp, MR1,
  3976. (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
  3977. stl_sc26198setreg(portp, IOPIOR,
  3978. (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
  3979. portp->stats.rxrtsoff++;
  3980. }
  3981. }
  3982. BRDDISABLE(portp->brdnr);
  3983. spin_unlock_irqrestore(&brd_lock, flags);
  3984. }
  3985. /*****************************************************************************/
  3986. /*
  3987. * Send a flow control character.
  3988. */
  3989. static void stl_sc26198sendflow(stlport_t *portp, int state)
  3990. {
  3991. struct tty_struct *tty;
  3992. unsigned long flags;
  3993. unsigned char mr0;
  3994. #ifdef DEBUG
  3995. printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
  3996. #endif
  3997. if (portp == (stlport_t *) NULL)
  3998. return;
  3999. tty = portp->tty;
  4000. if (tty == (struct tty_struct *) NULL)
  4001. return;
  4002. spin_lock_irqsave(&brd_lock, flags);
  4003. BRDENABLE(portp->brdnr, portp->pagenr);
  4004. if (state) {
  4005. mr0 = stl_sc26198getreg(portp, MR0);
  4006. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4007. stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
  4008. mr0 |= MR0_SWFRX;
  4009. portp->stats.rxxon++;
  4010. stl_sc26198wait(portp);
  4011. stl_sc26198setreg(portp, MR0, mr0);
  4012. } else {
  4013. mr0 = stl_sc26198getreg(portp, MR0);
  4014. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4015. stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
  4016. mr0 &= ~MR0_SWFRX;
  4017. portp->stats.rxxoff++;
  4018. stl_sc26198wait(portp);
  4019. stl_sc26198setreg(portp, MR0, mr0);
  4020. }
  4021. BRDDISABLE(portp->brdnr);
  4022. spin_unlock_irqrestore(&brd_lock, flags);
  4023. }
  4024. /*****************************************************************************/
  4025. static void stl_sc26198flush(stlport_t *portp)
  4026. {
  4027. unsigned long flags;
  4028. #ifdef DEBUG
  4029. printk("stl_sc26198flush(portp=%x)\n", (int) portp);
  4030. #endif
  4031. if (portp == (stlport_t *) NULL)
  4032. return;
  4033. spin_lock_irqsave(&brd_lock, flags);
  4034. BRDENABLE(portp->brdnr, portp->pagenr);
  4035. stl_sc26198setreg(portp, SCCR, CR_TXRESET);
  4036. stl_sc26198setreg(portp, SCCR, portp->crenable);
  4037. BRDDISABLE(portp->brdnr);
  4038. portp->tx.tail = portp->tx.head;
  4039. spin_unlock_irqrestore(&brd_lock, flags);
  4040. }
  4041. /*****************************************************************************/
  4042. /*
  4043. * Return the current state of data flow on this port. This is only
  4044. * really interresting when determining if data has fully completed
  4045. * transmission or not... The sc26198 interrupt scheme cannot
  4046. * determine when all data has actually drained, so we need to
  4047. * check the port statusy register to be sure.
  4048. */
  4049. static int stl_sc26198datastate(stlport_t *portp)
  4050. {
  4051. unsigned long flags;
  4052. unsigned char sr;
  4053. #ifdef DEBUG
  4054. printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
  4055. #endif
  4056. if (portp == (stlport_t *) NULL)
  4057. return 0;
  4058. if (test_bit(ASYI_TXBUSY, &portp->istate))
  4059. return 1;
  4060. spin_lock_irqsave(&brd_lock, flags);
  4061. BRDENABLE(portp->brdnr, portp->pagenr);
  4062. sr = stl_sc26198getreg(portp, SR);
  4063. BRDDISABLE(portp->brdnr);
  4064. spin_unlock_irqrestore(&brd_lock, flags);
  4065. return (sr & SR_TXEMPTY) ? 0 : 1;
  4066. }
  4067. /*****************************************************************************/
  4068. /*
  4069. * Delay for a small amount of time, to give the sc26198 a chance
  4070. * to process a command...
  4071. */
  4072. static void stl_sc26198wait(stlport_t *portp)
  4073. {
  4074. int i;
  4075. #ifdef DEBUG
  4076. printk("stl_sc26198wait(portp=%x)\n", (int) portp);
  4077. #endif
  4078. if (portp == (stlport_t *) NULL)
  4079. return;
  4080. for (i = 0; (i < 20); i++)
  4081. stl_sc26198getglobreg(portp, TSTR);
  4082. }
  4083. /*****************************************************************************/
  4084. /*
  4085. * If we are TX flow controlled and in IXANY mode then we may
  4086. * need to unflow control here. We gotta do this because of the
  4087. * automatic flow control modes of the sc26198.
  4088. */
  4089. static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
  4090. {
  4091. unsigned char mr0;
  4092. mr0 = stl_sc26198getreg(portp, MR0);
  4093. stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
  4094. stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
  4095. stl_sc26198wait(portp);
  4096. stl_sc26198setreg(portp, MR0, mr0);
  4097. clear_bit(ASYI_TXFLOWED, &portp->istate);
  4098. }
  4099. /*****************************************************************************/
  4100. /*
  4101. * Interrupt service routine for sc26198 panels.
  4102. */
  4103. static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
  4104. {
  4105. stlport_t *portp;
  4106. unsigned int iack;
  4107. spin_lock(&brd_lock);
  4108. /*
  4109. * Work around bug in sc26198 chip... Cannot have A6 address
  4110. * line of UART high, else iack will be returned as 0.
  4111. */
  4112. outb(0, (iobase + 1));
  4113. iack = inb(iobase + XP_IACK);
  4114. portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
  4115. if (iack & IVR_RXDATA)
  4116. stl_sc26198rxisr(portp, iack);
  4117. else if (iack & IVR_TXDATA)
  4118. stl_sc26198txisr(portp);
  4119. else
  4120. stl_sc26198otherisr(portp, iack);
  4121. spin_unlock(&brd_lock);
  4122. }
  4123. /*****************************************************************************/
  4124. /*
  4125. * Transmit interrupt handler. This has gotta be fast! Handling TX
  4126. * chars is pretty simple, stuff as many as possible from the TX buffer
  4127. * into the sc26198 FIFO.
  4128. * In practice it is possible that interrupts are enabled but that the
  4129. * port has been hung up. Need to handle not having any TX buffer here,
  4130. * this is done by using the side effect that head and tail will also
  4131. * be NULL if the buffer has been freed.
  4132. */
  4133. static void stl_sc26198txisr(stlport_t *portp)
  4134. {
  4135. unsigned int ioaddr;
  4136. unsigned char mr0;
  4137. int len, stlen;
  4138. char *head, *tail;
  4139. #ifdef DEBUG
  4140. printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
  4141. #endif
  4142. ioaddr = portp->ioaddr;
  4143. head = portp->tx.head;
  4144. tail = portp->tx.tail;
  4145. len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
  4146. if ((len == 0) || ((len < STL_TXBUFLOW) &&
  4147. (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
  4148. set_bit(ASYI_TXLOW, &portp->istate);
  4149. schedule_work(&portp->tqueue);
  4150. }
  4151. if (len == 0) {
  4152. outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
  4153. mr0 = inb(ioaddr + XP_DATA);
  4154. if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
  4155. portp->imr &= ~IR_TXRDY;
  4156. outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
  4157. outb(portp->imr, (ioaddr + XP_DATA));
  4158. clear_bit(ASYI_TXBUSY, &portp->istate);
  4159. } else {
  4160. mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
  4161. outb(mr0, (ioaddr + XP_DATA));
  4162. }
  4163. } else {
  4164. len = MIN(len, SC26198_TXFIFOSIZE);
  4165. portp->stats.txtotal += len;
  4166. stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
  4167. outb(GTXFIFO, (ioaddr + XP_ADDR));
  4168. outsb((ioaddr + XP_DATA), tail, stlen);
  4169. len -= stlen;
  4170. tail += stlen;
  4171. if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
  4172. tail = portp->tx.buf;
  4173. if (len > 0) {
  4174. outsb((ioaddr + XP_DATA), tail, len);
  4175. tail += len;
  4176. }
  4177. portp->tx.tail = tail;
  4178. }
  4179. }
  4180. /*****************************************************************************/
  4181. /*
  4182. * Receive character interrupt handler. Determine if we have good chars
  4183. * or bad chars and then process appropriately. Good chars are easy
  4184. * just shove the lot into the RX buffer and set all status byte to 0.
  4185. * If a bad RX char then process as required. This routine needs to be
  4186. * fast! In practice it is possible that we get an interrupt on a port
  4187. * that is closed. This can happen on hangups - since they completely
  4188. * shutdown a port not in user context. Need to handle this case.
  4189. */
  4190. static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
  4191. {
  4192. struct tty_struct *tty;
  4193. unsigned int len, buflen, ioaddr;
  4194. #ifdef DEBUG
  4195. printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
  4196. #endif
  4197. tty = portp->tty;
  4198. ioaddr = portp->ioaddr;
  4199. outb(GIBCR, (ioaddr + XP_ADDR));
  4200. len = inb(ioaddr + XP_DATA) + 1;
  4201. if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
  4202. if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
  4203. len = MIN(len, sizeof(stl_unwanted));
  4204. outb(GRXFIFO, (ioaddr + XP_ADDR));
  4205. insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
  4206. portp->stats.rxlost += len;
  4207. portp->stats.rxtotal += len;
  4208. } else {
  4209. len = MIN(len, buflen);
  4210. if (len > 0) {
  4211. unsigned char *ptr;
  4212. outb(GRXFIFO, (ioaddr + XP_ADDR));
  4213. tty_prepare_flip_string(tty, &ptr, len);
  4214. insb((ioaddr + XP_DATA), ptr, len);
  4215. tty_schedule_flip(tty);
  4216. portp->stats.rxtotal += len;
  4217. }
  4218. }
  4219. } else {
  4220. stl_sc26198rxbadchars(portp);
  4221. }
  4222. /*
  4223. * If we are TX flow controlled and in IXANY mode then we may need
  4224. * to unflow control here. We gotta do this because of the automatic
  4225. * flow control modes of the sc26198.
  4226. */
  4227. if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
  4228. if ((tty != (struct tty_struct *) NULL) &&
  4229. (tty->termios != (struct termios *) NULL) &&
  4230. (tty->termios->c_iflag & IXANY)) {
  4231. stl_sc26198txunflow(portp, tty);
  4232. }
  4233. }
  4234. }
  4235. /*****************************************************************************/
  4236. /*
  4237. * Process an RX bad character.
  4238. */
  4239. static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
  4240. {
  4241. struct tty_struct *tty;
  4242. unsigned int ioaddr;
  4243. tty = portp->tty;
  4244. ioaddr = portp->ioaddr;
  4245. if (status & SR_RXPARITY)
  4246. portp->stats.rxparity++;
  4247. if (status & SR_RXFRAMING)
  4248. portp->stats.rxframing++;
  4249. if (status & SR_RXOVERRUN)
  4250. portp->stats.rxoverrun++;
  4251. if (status & SR_RXBREAK)
  4252. portp->stats.rxbreaks++;
  4253. if ((tty != (struct tty_struct *) NULL) &&
  4254. ((portp->rxignoremsk & status) == 0)) {
  4255. if (portp->rxmarkmsk & status) {
  4256. if (status & SR_RXBREAK) {
  4257. status = TTY_BREAK;
  4258. if (portp->flags & ASYNC_SAK) {
  4259. do_SAK(tty);
  4260. BRDENABLE(portp->brdnr, portp->pagenr);
  4261. }
  4262. } else if (status & SR_RXPARITY) {
  4263. status = TTY_PARITY;
  4264. } else if (status & SR_RXFRAMING) {
  4265. status = TTY_FRAME;
  4266. } else if(status & SR_RXOVERRUN) {
  4267. status = TTY_OVERRUN;
  4268. } else {
  4269. status = 0;
  4270. }
  4271. } else {
  4272. status = 0;
  4273. }
  4274. tty_insert_flip_char(tty, ch, status);
  4275. tty_schedule_flip(tty);
  4276. if (status == 0)
  4277. portp->stats.rxtotal++;
  4278. }
  4279. }
  4280. /*****************************************************************************/
  4281. /*
  4282. * Process all characters in the RX FIFO of the UART. Check all char
  4283. * status bytes as well, and process as required. We need to check
  4284. * all bytes in the FIFO, in case some more enter the FIFO while we
  4285. * are here. To get the exact character error type we need to switch
  4286. * into CHAR error mode (that is why we need to make sure we empty
  4287. * the FIFO).
  4288. */
  4289. static void stl_sc26198rxbadchars(stlport_t *portp)
  4290. {
  4291. unsigned char status, mr1;
  4292. char ch;
  4293. /*
  4294. * To get the precise error type for each character we must switch
  4295. * back into CHAR error mode.
  4296. */
  4297. mr1 = stl_sc26198getreg(portp, MR1);
  4298. stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
  4299. while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
  4300. stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
  4301. ch = stl_sc26198getreg(portp, RXFIFO);
  4302. stl_sc26198rxbadch(portp, status, ch);
  4303. }
  4304. /*
  4305. * To get correct interrupt class we must switch back into BLOCK
  4306. * error mode.
  4307. */
  4308. stl_sc26198setreg(portp, MR1, mr1);
  4309. }
  4310. /*****************************************************************************/
  4311. /*
  4312. * Other interrupt handler. This includes modem signals, flow
  4313. * control actions, etc. Most stuff is left to off-level interrupt
  4314. * processing time.
  4315. */
  4316. static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
  4317. {
  4318. unsigned char cir, ipr, xisr;
  4319. #ifdef DEBUG
  4320. printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
  4321. #endif
  4322. cir = stl_sc26198getglobreg(portp, CIR);
  4323. switch (cir & CIR_SUBTYPEMASK) {
  4324. case CIR_SUBCOS:
  4325. ipr = stl_sc26198getreg(portp, IPR);
  4326. if (ipr & IPR_DCDCHANGE) {
  4327. set_bit(ASYI_DCDCHANGE, &portp->istate);
  4328. schedule_work(&portp->tqueue);
  4329. portp->stats.modem++;
  4330. }
  4331. break;
  4332. case CIR_SUBXONXOFF:
  4333. xisr = stl_sc26198getreg(portp, XISR);
  4334. if (xisr & XISR_RXXONGOT) {
  4335. set_bit(ASYI_TXFLOWED, &portp->istate);
  4336. portp->stats.txxoff++;
  4337. }
  4338. if (xisr & XISR_RXXOFFGOT) {
  4339. clear_bit(ASYI_TXFLOWED, &portp->istate);
  4340. portp->stats.txxon++;
  4341. }
  4342. break;
  4343. case CIR_SUBBREAK:
  4344. stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
  4345. stl_sc26198rxbadchars(portp);
  4346. break;
  4347. default:
  4348. break;
  4349. }
  4350. }
  4351. /*****************************************************************************/