istallion.c 137 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275
  1. /*****************************************************************************/
  2. /*
  3. * istallion.c -- stallion intelligent 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/cdk.h>
  34. #include <linux/comstats.h>
  35. #include <linux/istallion.h>
  36. #include <linux/ioport.h>
  37. #include <linux/delay.h>
  38. #include <linux/init.h>
  39. #include <linux/devfs_fs_kernel.h>
  40. #include <linux/device.h>
  41. #include <linux/wait.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. Not all of the following board types
  50. * are supported by this driver. But I will use the standard "assigned"
  51. * board numbers. Currently supported boards are abbreviated as:
  52. * ECP = EasyConnection 8/64, ONB = ONboard, BBY = Brumby and
  53. * STAL = Stallion.
  54. */
  55. #define BRD_UNKNOWN 0
  56. #define BRD_STALLION 1
  57. #define BRD_BRUMBY4 2
  58. #define BRD_ONBOARD2 3
  59. #define BRD_ONBOARD 4
  60. #define BRD_BRUMBY8 5
  61. #define BRD_BRUMBY16 6
  62. #define BRD_ONBOARDE 7
  63. #define BRD_ONBOARD32 9
  64. #define BRD_ONBOARD2_32 10
  65. #define BRD_ONBOARDRS 11
  66. #define BRD_EASYIO 20
  67. #define BRD_ECH 21
  68. #define BRD_ECHMC 22
  69. #define BRD_ECP 23
  70. #define BRD_ECPE 24
  71. #define BRD_ECPMC 25
  72. #define BRD_ECHPCI 26
  73. #define BRD_ECH64PCI 27
  74. #define BRD_EASYIOPCI 28
  75. #define BRD_ECPPCI 29
  76. #define BRD_BRUMBY BRD_BRUMBY4
  77. /*
  78. * Define a configuration structure to hold the board configuration.
  79. * Need to set this up in the code (for now) with the boards that are
  80. * to be configured into the system. This is what needs to be modified
  81. * when adding/removing/modifying boards. Each line entry in the
  82. * stli_brdconf[] array is a board. Each line contains io/irq/memory
  83. * ranges for that board (as well as what type of board it is).
  84. * Some examples:
  85. * { BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },
  86. * This line will configure an EasyConnection 8/64 at io address 2a0,
  87. * and shared memory address of cc000. Multiple EasyConnection 8/64
  88. * boards can share the same shared memory address space. No interrupt
  89. * is required for this board type.
  90. * Another example:
  91. * { BRD_ECPE, 0x5000, 0, 0x80000000, 0, 0 },
  92. * This line will configure an EasyConnection 8/64 EISA in slot 5 and
  93. * shared memory address of 0x80000000 (2 GByte). Multiple
  94. * EasyConnection 8/64 EISA boards can share the same shared memory
  95. * address space. No interrupt is required for this board type.
  96. * Another example:
  97. * { BRD_ONBOARD, 0x240, 0, 0xd0000, 0, 0 },
  98. * This line will configure an ONboard (ISA type) at io address 240,
  99. * and shared memory address of d0000. Multiple ONboards can share
  100. * the same shared memory address space. No interrupt required.
  101. * Another example:
  102. * { BRD_BRUMBY4, 0x360, 0, 0xc8000, 0, 0 },
  103. * This line will configure a Brumby board (any number of ports!) at
  104. * io address 360 and shared memory address of c8000. All Brumby boards
  105. * configured into a system must have their own separate io and memory
  106. * addresses. No interrupt is required.
  107. * Another example:
  108. * { BRD_STALLION, 0x330, 0, 0xd0000, 0, 0 },
  109. * This line will configure an original Stallion board at io address 330
  110. * and shared memory address d0000 (this would only be valid for a "V4.0"
  111. * or Rev.O Stallion board). All Stallion boards configured into the
  112. * system must have their own separate io and memory addresses. No
  113. * interrupt is required.
  114. */
  115. typedef struct {
  116. int brdtype;
  117. int ioaddr1;
  118. int ioaddr2;
  119. unsigned long memaddr;
  120. int irq;
  121. int irqtype;
  122. } stlconf_t;
  123. static stlconf_t stli_brdconf[] = {
  124. /*{ BRD_ECP, 0x2a0, 0, 0xcc000, 0, 0 },*/
  125. };
  126. static int stli_nrbrds = sizeof(stli_brdconf) / sizeof(stlconf_t);
  127. /*
  128. * There is some experimental EISA board detection code in this driver.
  129. * By default it is disabled, but for those that want to try it out,
  130. * then set the define below to be 1.
  131. */
  132. #define STLI_EISAPROBE 0
  133. /*****************************************************************************/
  134. /*
  135. * Define some important driver characteristics. Device major numbers
  136. * allocated as per Linux Device Registry.
  137. */
  138. #ifndef STL_SIOMEMMAJOR
  139. #define STL_SIOMEMMAJOR 28
  140. #endif
  141. #ifndef STL_SERIALMAJOR
  142. #define STL_SERIALMAJOR 24
  143. #endif
  144. #ifndef STL_CALLOUTMAJOR
  145. #define STL_CALLOUTMAJOR 25
  146. #endif
  147. /*****************************************************************************/
  148. /*
  149. * Define our local driver identity first. Set up stuff to deal with
  150. * all the local structures required by a serial tty driver.
  151. */
  152. static char *stli_drvtitle = "Stallion Intelligent Multiport Serial Driver";
  153. static char *stli_drvname = "istallion";
  154. static char *stli_drvversion = "5.6.0";
  155. static char *stli_serialname = "ttyE";
  156. static struct tty_driver *stli_serial;
  157. /*
  158. * We will need to allocate a temporary write buffer for chars that
  159. * come direct from user space. The problem is that a copy from user
  160. * space might cause a page fault (typically on a system that is
  161. * swapping!). All ports will share one buffer - since if the system
  162. * is already swapping a shared buffer won't make things any worse.
  163. */
  164. static char *stli_tmpwritebuf;
  165. static DECLARE_MUTEX(stli_tmpwritesem);
  166. #define STLI_TXBUFSIZE 4096
  167. /*
  168. * Use a fast local buffer for cooked characters. Typically a whole
  169. * bunch of cooked characters come in for a port, 1 at a time. So we
  170. * save those up into a local buffer, then write out the whole lot
  171. * with a large memcpy. Just use 1 buffer for all ports, since its
  172. * use it is only need for short periods of time by each port.
  173. */
  174. static char *stli_txcookbuf;
  175. static int stli_txcooksize;
  176. static int stli_txcookrealsize;
  177. static struct tty_struct *stli_txcooktty;
  178. /*
  179. * Define a local default termios struct. All ports will be created
  180. * with this termios initially. Basically all it defines is a raw port
  181. * at 9600 baud, 8 data bits, no parity, 1 stop bit.
  182. */
  183. static struct termios stli_deftermios = {
  184. .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
  185. .c_cc = INIT_C_CC,
  186. };
  187. /*
  188. * Define global stats structures. Not used often, and can be
  189. * re-used for each stats call.
  190. */
  191. static comstats_t stli_comstats;
  192. static combrd_t stli_brdstats;
  193. static asystats_t stli_cdkstats;
  194. static stlibrd_t stli_dummybrd;
  195. static stliport_t stli_dummyport;
  196. /*****************************************************************************/
  197. static stlibrd_t *stli_brds[STL_MAXBRDS];
  198. static int stli_shared;
  199. /*
  200. * Per board state flags. Used with the state field of the board struct.
  201. * Not really much here... All we need to do is keep track of whether
  202. * the board has been detected, and whether it is actually running a slave
  203. * or not.
  204. */
  205. #define BST_FOUND 0x1
  206. #define BST_STARTED 0x2
  207. /*
  208. * Define the set of port state flags. These are marked for internal
  209. * state purposes only, usually to do with the state of communications
  210. * with the slave. Most of them need to be updated atomically, so always
  211. * use the bit setting operations (unless protected by cli/sti).
  212. */
  213. #define ST_INITIALIZING 1
  214. #define ST_OPENING 2
  215. #define ST_CLOSING 3
  216. #define ST_CMDING 4
  217. #define ST_TXBUSY 5
  218. #define ST_RXING 6
  219. #define ST_DOFLUSHRX 7
  220. #define ST_DOFLUSHTX 8
  221. #define ST_DOSIGS 9
  222. #define ST_RXSTOP 10
  223. #define ST_GETSIGS 11
  224. /*
  225. * Define an array of board names as printable strings. Handy for
  226. * referencing boards when printing trace and stuff.
  227. */
  228. static char *stli_brdnames[] = {
  229. "Unknown",
  230. "Stallion",
  231. "Brumby",
  232. "ONboard-MC",
  233. "ONboard",
  234. "Brumby",
  235. "Brumby",
  236. "ONboard-EI",
  237. (char *) NULL,
  238. "ONboard",
  239. "ONboard-MC",
  240. "ONboard-MC",
  241. (char *) NULL,
  242. (char *) NULL,
  243. (char *) NULL,
  244. (char *) NULL,
  245. (char *) NULL,
  246. (char *) NULL,
  247. (char *) NULL,
  248. (char *) NULL,
  249. "EasyIO",
  250. "EC8/32-AT",
  251. "EC8/32-MC",
  252. "EC8/64-AT",
  253. "EC8/64-EI",
  254. "EC8/64-MC",
  255. "EC8/32-PCI",
  256. "EC8/64-PCI",
  257. "EasyIO-PCI",
  258. "EC/RA-PCI",
  259. };
  260. /*****************************************************************************/
  261. #ifdef MODULE
  262. /*
  263. * Define some string labels for arguments passed from the module
  264. * load line. These allow for easy board definitions, and easy
  265. * modification of the io, memory and irq resoucres.
  266. */
  267. static char *board0[8];
  268. static char *board1[8];
  269. static char *board2[8];
  270. static char *board3[8];
  271. static char **stli_brdsp[] = {
  272. (char **) &board0,
  273. (char **) &board1,
  274. (char **) &board2,
  275. (char **) &board3
  276. };
  277. /*
  278. * Define a set of common board names, and types. This is used to
  279. * parse any module arguments.
  280. */
  281. typedef struct stlibrdtype {
  282. char *name;
  283. int type;
  284. } stlibrdtype_t;
  285. static stlibrdtype_t stli_brdstr[] = {
  286. { "stallion", BRD_STALLION },
  287. { "1", BRD_STALLION },
  288. { "brumby", BRD_BRUMBY },
  289. { "brumby4", BRD_BRUMBY },
  290. { "brumby/4", BRD_BRUMBY },
  291. { "brumby-4", BRD_BRUMBY },
  292. { "brumby8", BRD_BRUMBY },
  293. { "brumby/8", BRD_BRUMBY },
  294. { "brumby-8", BRD_BRUMBY },
  295. { "brumby16", BRD_BRUMBY },
  296. { "brumby/16", BRD_BRUMBY },
  297. { "brumby-16", BRD_BRUMBY },
  298. { "2", BRD_BRUMBY },
  299. { "onboard2", BRD_ONBOARD2 },
  300. { "onboard-2", BRD_ONBOARD2 },
  301. { "onboard/2", BRD_ONBOARD2 },
  302. { "onboard-mc", BRD_ONBOARD2 },
  303. { "onboard/mc", BRD_ONBOARD2 },
  304. { "onboard-mca", BRD_ONBOARD2 },
  305. { "onboard/mca", BRD_ONBOARD2 },
  306. { "3", BRD_ONBOARD2 },
  307. { "onboard", BRD_ONBOARD },
  308. { "onboardat", BRD_ONBOARD },
  309. { "4", BRD_ONBOARD },
  310. { "onboarde", BRD_ONBOARDE },
  311. { "onboard-e", BRD_ONBOARDE },
  312. { "onboard/e", BRD_ONBOARDE },
  313. { "onboard-ei", BRD_ONBOARDE },
  314. { "onboard/ei", BRD_ONBOARDE },
  315. { "7", BRD_ONBOARDE },
  316. { "ecp", BRD_ECP },
  317. { "ecpat", BRD_ECP },
  318. { "ec8/64", BRD_ECP },
  319. { "ec8/64-at", BRD_ECP },
  320. { "ec8/64-isa", BRD_ECP },
  321. { "23", BRD_ECP },
  322. { "ecpe", BRD_ECPE },
  323. { "ecpei", BRD_ECPE },
  324. { "ec8/64-e", BRD_ECPE },
  325. { "ec8/64-ei", BRD_ECPE },
  326. { "24", BRD_ECPE },
  327. { "ecpmc", BRD_ECPMC },
  328. { "ec8/64-mc", BRD_ECPMC },
  329. { "ec8/64-mca", BRD_ECPMC },
  330. { "25", BRD_ECPMC },
  331. { "ecppci", BRD_ECPPCI },
  332. { "ec/ra", BRD_ECPPCI },
  333. { "ec/ra-pc", BRD_ECPPCI },
  334. { "ec/ra-pci", BRD_ECPPCI },
  335. { "29", BRD_ECPPCI },
  336. };
  337. /*
  338. * Define the module agruments.
  339. */
  340. MODULE_AUTHOR("Greg Ungerer");
  341. MODULE_DESCRIPTION("Stallion Intelligent Multiport Serial Driver");
  342. MODULE_LICENSE("GPL");
  343. MODULE_PARM(board0, "1-3s");
  344. MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,memaddr]");
  345. MODULE_PARM(board1, "1-3s");
  346. MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,memaddr]");
  347. MODULE_PARM(board2, "1-3s");
  348. MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,memaddr]");
  349. MODULE_PARM(board3, "1-3s");
  350. MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,memaddr]");
  351. #endif
  352. /*
  353. * Set up a default memory address table for EISA board probing.
  354. * The default addresses are all bellow 1Mbyte, which has to be the
  355. * case anyway. They should be safe, since we only read values from
  356. * them, and interrupts are disabled while we do it. If the higher
  357. * memory support is compiled in then we also try probing around
  358. * the 1Gb, 2Gb and 3Gb areas as well...
  359. */
  360. static unsigned long stli_eisamemprobeaddrs[] = {
  361. 0xc0000, 0xd0000, 0xe0000, 0xf0000,
  362. 0x80000000, 0x80010000, 0x80020000, 0x80030000,
  363. 0x40000000, 0x40010000, 0x40020000, 0x40030000,
  364. 0xc0000000, 0xc0010000, 0xc0020000, 0xc0030000,
  365. 0xff000000, 0xff010000, 0xff020000, 0xff030000,
  366. };
  367. static int stli_eisamempsize = sizeof(stli_eisamemprobeaddrs) / sizeof(unsigned long);
  368. /*
  369. * Define the Stallion PCI vendor and device IDs.
  370. */
  371. #ifdef CONFIG_PCI
  372. #ifndef PCI_VENDOR_ID_STALLION
  373. #define PCI_VENDOR_ID_STALLION 0x124d
  374. #endif
  375. #ifndef PCI_DEVICE_ID_ECRA
  376. #define PCI_DEVICE_ID_ECRA 0x0004
  377. #endif
  378. static struct pci_device_id istallion_pci_tbl[] = {
  379. { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  380. { 0 }
  381. };
  382. MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
  383. #endif /* CONFIG_PCI */
  384. /*****************************************************************************/
  385. /*
  386. * Hardware configuration info for ECP boards. These defines apply
  387. * to the directly accessible io ports of the ECP. There is a set of
  388. * defines for each ECP board type, ISA, EISA, MCA and PCI.
  389. */
  390. #define ECP_IOSIZE 4
  391. #define ECP_MEMSIZE (128 * 1024)
  392. #define ECP_PCIMEMSIZE (256 * 1024)
  393. #define ECP_ATPAGESIZE (4 * 1024)
  394. #define ECP_MCPAGESIZE (4 * 1024)
  395. #define ECP_EIPAGESIZE (64 * 1024)
  396. #define ECP_PCIPAGESIZE (64 * 1024)
  397. #define STL_EISAID 0x8c4e
  398. /*
  399. * Important defines for the ISA class of ECP board.
  400. */
  401. #define ECP_ATIREG 0
  402. #define ECP_ATCONFR 1
  403. #define ECP_ATMEMAR 2
  404. #define ECP_ATMEMPR 3
  405. #define ECP_ATSTOP 0x1
  406. #define ECP_ATINTENAB 0x10
  407. #define ECP_ATENABLE 0x20
  408. #define ECP_ATDISABLE 0x00
  409. #define ECP_ATADDRMASK 0x3f000
  410. #define ECP_ATADDRSHFT 12
  411. /*
  412. * Important defines for the EISA class of ECP board.
  413. */
  414. #define ECP_EIIREG 0
  415. #define ECP_EIMEMARL 1
  416. #define ECP_EICONFR 2
  417. #define ECP_EIMEMARH 3
  418. #define ECP_EIENABLE 0x1
  419. #define ECP_EIDISABLE 0x0
  420. #define ECP_EISTOP 0x4
  421. #define ECP_EIEDGE 0x00
  422. #define ECP_EILEVEL 0x80
  423. #define ECP_EIADDRMASKL 0x00ff0000
  424. #define ECP_EIADDRSHFTL 16
  425. #define ECP_EIADDRMASKH 0xff000000
  426. #define ECP_EIADDRSHFTH 24
  427. #define ECP_EIBRDENAB 0xc84
  428. #define ECP_EISAID 0x4
  429. /*
  430. * Important defines for the Micro-channel class of ECP board.
  431. * (It has a lot in common with the ISA boards.)
  432. */
  433. #define ECP_MCIREG 0
  434. #define ECP_MCCONFR 1
  435. #define ECP_MCSTOP 0x20
  436. #define ECP_MCENABLE 0x80
  437. #define ECP_MCDISABLE 0x00
  438. /*
  439. * Important defines for the PCI class of ECP board.
  440. * (It has a lot in common with the other ECP boards.)
  441. */
  442. #define ECP_PCIIREG 0
  443. #define ECP_PCICONFR 1
  444. #define ECP_PCISTOP 0x01
  445. /*
  446. * Hardware configuration info for ONboard and Brumby boards. These
  447. * defines apply to the directly accessible io ports of these boards.
  448. */
  449. #define ONB_IOSIZE 16
  450. #define ONB_MEMSIZE (64 * 1024)
  451. #define ONB_ATPAGESIZE (64 * 1024)
  452. #define ONB_MCPAGESIZE (64 * 1024)
  453. #define ONB_EIMEMSIZE (128 * 1024)
  454. #define ONB_EIPAGESIZE (64 * 1024)
  455. /*
  456. * Important defines for the ISA class of ONboard board.
  457. */
  458. #define ONB_ATIREG 0
  459. #define ONB_ATMEMAR 1
  460. #define ONB_ATCONFR 2
  461. #define ONB_ATSTOP 0x4
  462. #define ONB_ATENABLE 0x01
  463. #define ONB_ATDISABLE 0x00
  464. #define ONB_ATADDRMASK 0xff0000
  465. #define ONB_ATADDRSHFT 16
  466. #define ONB_MEMENABLO 0
  467. #define ONB_MEMENABHI 0x02
  468. /*
  469. * Important defines for the EISA class of ONboard board.
  470. */
  471. #define ONB_EIIREG 0
  472. #define ONB_EIMEMARL 1
  473. #define ONB_EICONFR 2
  474. #define ONB_EIMEMARH 3
  475. #define ONB_EIENABLE 0x1
  476. #define ONB_EIDISABLE 0x0
  477. #define ONB_EISTOP 0x4
  478. #define ONB_EIEDGE 0x00
  479. #define ONB_EILEVEL 0x80
  480. #define ONB_EIADDRMASKL 0x00ff0000
  481. #define ONB_EIADDRSHFTL 16
  482. #define ONB_EIADDRMASKH 0xff000000
  483. #define ONB_EIADDRSHFTH 24
  484. #define ONB_EIBRDENAB 0xc84
  485. #define ONB_EISAID 0x1
  486. /*
  487. * Important defines for the Brumby boards. They are pretty simple,
  488. * there is not much that is programmably configurable.
  489. */
  490. #define BBY_IOSIZE 16
  491. #define BBY_MEMSIZE (64 * 1024)
  492. #define BBY_PAGESIZE (16 * 1024)
  493. #define BBY_ATIREG 0
  494. #define BBY_ATCONFR 1
  495. #define BBY_ATSTOP 0x4
  496. /*
  497. * Important defines for the Stallion boards. They are pretty simple,
  498. * there is not much that is programmably configurable.
  499. */
  500. #define STAL_IOSIZE 16
  501. #define STAL_MEMSIZE (64 * 1024)
  502. #define STAL_PAGESIZE (64 * 1024)
  503. /*
  504. * Define the set of status register values for EasyConnection panels.
  505. * The signature will return with the status value for each panel. From
  506. * this we can determine what is attached to the board - before we have
  507. * actually down loaded any code to it.
  508. */
  509. #define ECH_PNLSTATUS 2
  510. #define ECH_PNL16PORT 0x20
  511. #define ECH_PNLIDMASK 0x07
  512. #define ECH_PNLXPID 0x40
  513. #define ECH_PNLINTRPEND 0x80
  514. /*
  515. * Define some macros to do things to the board. Even those these boards
  516. * are somewhat related there is often significantly different ways of
  517. * doing some operation on it (like enable, paging, reset, etc). So each
  518. * board class has a set of functions which do the commonly required
  519. * operations. The macros below basically just call these functions,
  520. * generally checking for a NULL function - which means that the board
  521. * needs nothing done to it to achieve this operation!
  522. */
  523. #define EBRDINIT(brdp) \
  524. if (brdp->init != NULL) \
  525. (* brdp->init)(brdp)
  526. #define EBRDENABLE(brdp) \
  527. if (brdp->enable != NULL) \
  528. (* brdp->enable)(brdp);
  529. #define EBRDDISABLE(brdp) \
  530. if (brdp->disable != NULL) \
  531. (* brdp->disable)(brdp);
  532. #define EBRDINTR(brdp) \
  533. if (brdp->intr != NULL) \
  534. (* brdp->intr)(brdp);
  535. #define EBRDRESET(brdp) \
  536. if (brdp->reset != NULL) \
  537. (* brdp->reset)(brdp);
  538. #define EBRDGETMEMPTR(brdp,offset) \
  539. (* brdp->getmemptr)(brdp, offset, __LINE__)
  540. /*
  541. * Define the maximal baud rate, and the default baud base for ports.
  542. */
  543. #define STL_MAXBAUD 460800
  544. #define STL_BAUDBASE 115200
  545. #define STL_CLOSEDELAY (5 * HZ / 10)
  546. /*****************************************************************************/
  547. /*
  548. * Define macros to extract a brd or port number from a minor number.
  549. */
  550. #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
  551. #define MINOR2PORT(min) ((min) & 0x3f)
  552. /*
  553. * Define a baud rate table that converts termios baud rate selector
  554. * into the actual baud rate value. All baud rate calculations are based
  555. * on the actual baud rate required.
  556. */
  557. static unsigned int stli_baudrates[] = {
  558. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
  559. 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
  560. };
  561. /*****************************************************************************/
  562. /*
  563. * Define some handy local macros...
  564. */
  565. #undef MIN
  566. #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
  567. #undef TOLOWER
  568. #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
  569. /*****************************************************************************/
  570. /*
  571. * Prototype all functions in this driver!
  572. */
  573. #ifdef MODULE
  574. static void stli_argbrds(void);
  575. static int stli_parsebrd(stlconf_t *confp, char **argp);
  576. static unsigned long stli_atol(char *str);
  577. #endif
  578. int stli_init(void);
  579. static int stli_open(struct tty_struct *tty, struct file *filp);
  580. static void stli_close(struct tty_struct *tty, struct file *filp);
  581. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count);
  582. static void stli_putchar(struct tty_struct *tty, unsigned char ch);
  583. static void stli_flushchars(struct tty_struct *tty);
  584. static int stli_writeroom(struct tty_struct *tty);
  585. static int stli_charsinbuffer(struct tty_struct *tty);
  586. static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
  587. static void stli_settermios(struct tty_struct *tty, struct termios *old);
  588. static void stli_throttle(struct tty_struct *tty);
  589. static void stli_unthrottle(struct tty_struct *tty);
  590. static void stli_stop(struct tty_struct *tty);
  591. static void stli_start(struct tty_struct *tty);
  592. static void stli_flushbuffer(struct tty_struct *tty);
  593. static void stli_breakctl(struct tty_struct *tty, int state);
  594. static void stli_waituntilsent(struct tty_struct *tty, int timeout);
  595. static void stli_sendxchar(struct tty_struct *tty, char ch);
  596. static void stli_hangup(struct tty_struct *tty);
  597. static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos);
  598. static int stli_brdinit(stlibrd_t *brdp);
  599. static int stli_startbrd(stlibrd_t *brdp);
  600. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
  601. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
  602. static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
  603. static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp);
  604. static void stli_poll(unsigned long arg);
  605. static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
  606. static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
  607. static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
  608. static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait);
  609. static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp);
  610. static void stli_dohangup(void *arg);
  611. static int stli_setport(stliport_t *portp);
  612. static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
  613. static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
  614. static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp);
  615. static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
  616. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
  617. static long stli_mktiocm(unsigned long sigvalue);
  618. static void stli_read(stlibrd_t *brdp, stliport_t *portp);
  619. static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp);
  620. static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp);
  621. static int stli_getbrdstats(combrd_t __user *bp);
  622. static int stli_getportstats(stliport_t *portp, comstats_t __user *cp);
  623. static int stli_portcmdstats(stliport_t *portp);
  624. static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp);
  625. static int stli_getportstruct(stliport_t __user *arg);
  626. static int stli_getbrdstruct(stlibrd_t __user *arg);
  627. static void *stli_memalloc(int len);
  628. static stlibrd_t *stli_allocbrd(void);
  629. static void stli_ecpinit(stlibrd_t *brdp);
  630. static void stli_ecpenable(stlibrd_t *brdp);
  631. static void stli_ecpdisable(stlibrd_t *brdp);
  632. static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  633. static void stli_ecpreset(stlibrd_t *brdp);
  634. static void stli_ecpintr(stlibrd_t *brdp);
  635. static void stli_ecpeiinit(stlibrd_t *brdp);
  636. static void stli_ecpeienable(stlibrd_t *brdp);
  637. static void stli_ecpeidisable(stlibrd_t *brdp);
  638. static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  639. static void stli_ecpeireset(stlibrd_t *brdp);
  640. static void stli_ecpmcenable(stlibrd_t *brdp);
  641. static void stli_ecpmcdisable(stlibrd_t *brdp);
  642. static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  643. static void stli_ecpmcreset(stlibrd_t *brdp);
  644. static void stli_ecppciinit(stlibrd_t *brdp);
  645. static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  646. static void stli_ecppcireset(stlibrd_t *brdp);
  647. static void stli_onbinit(stlibrd_t *brdp);
  648. static void stli_onbenable(stlibrd_t *brdp);
  649. static void stli_onbdisable(stlibrd_t *brdp);
  650. static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  651. static void stli_onbreset(stlibrd_t *brdp);
  652. static void stli_onbeinit(stlibrd_t *brdp);
  653. static void stli_onbeenable(stlibrd_t *brdp);
  654. static void stli_onbedisable(stlibrd_t *brdp);
  655. static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  656. static void stli_onbereset(stlibrd_t *brdp);
  657. static void stli_bbyinit(stlibrd_t *brdp);
  658. static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  659. static void stli_bbyreset(stlibrd_t *brdp);
  660. static void stli_stalinit(stlibrd_t *brdp);
  661. static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line);
  662. static void stli_stalreset(stlibrd_t *brdp);
  663. static stliport_t *stli_getport(int brdnr, int panelnr, int portnr);
  664. static int stli_initecp(stlibrd_t *brdp);
  665. static int stli_initonb(stlibrd_t *brdp);
  666. static int stli_eisamemprobe(stlibrd_t *brdp);
  667. static int stli_initports(stlibrd_t *brdp);
  668. #ifdef CONFIG_PCI
  669. static int stli_initpcibrd(int brdtype, struct pci_dev *devp);
  670. #endif
  671. /*****************************************************************************/
  672. /*
  673. * Define the driver info for a user level shared memory device. This
  674. * device will work sort of like the /dev/kmem device - except that it
  675. * will give access to the shared memory on the Stallion intelligent
  676. * board. This is also a very useful debugging tool.
  677. */
  678. static struct file_operations stli_fsiomem = {
  679. .owner = THIS_MODULE,
  680. .read = stli_memread,
  681. .write = stli_memwrite,
  682. .ioctl = stli_memioctl,
  683. };
  684. /*****************************************************************************/
  685. /*
  686. * Define a timer_list entry for our poll routine. The slave board
  687. * is polled every so often to see if anything needs doing. This is
  688. * much cheaper on host cpu than using interrupts. It turns out to
  689. * not increase character latency by much either...
  690. */
  691. static DEFINE_TIMER(stli_timerlist, stli_poll, 0, 0);
  692. static int stli_timeron;
  693. /*
  694. * Define the calculation for the timeout routine.
  695. */
  696. #define STLI_TIMEOUT (jiffies + 1)
  697. /*****************************************************************************/
  698. static struct class *istallion_class;
  699. #ifdef MODULE
  700. /*
  701. * Loadable module initialization stuff.
  702. */
  703. static int __init istallion_module_init(void)
  704. {
  705. unsigned long flags;
  706. #ifdef DEBUG
  707. printk("init_module()\n");
  708. #endif
  709. save_flags(flags);
  710. cli();
  711. stli_init();
  712. restore_flags(flags);
  713. return(0);
  714. }
  715. /*****************************************************************************/
  716. static void __exit istallion_module_exit(void)
  717. {
  718. stlibrd_t *brdp;
  719. stliport_t *portp;
  720. unsigned long flags;
  721. int i, j;
  722. #ifdef DEBUG
  723. printk("cleanup_module()\n");
  724. #endif
  725. printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
  726. stli_drvversion);
  727. save_flags(flags);
  728. cli();
  729. /*
  730. * Free up all allocated resources used by the ports. This includes
  731. * memory and interrupts.
  732. */
  733. if (stli_timeron) {
  734. stli_timeron = 0;
  735. del_timer(&stli_timerlist);
  736. }
  737. i = tty_unregister_driver(stli_serial);
  738. if (i) {
  739. printk("STALLION: failed to un-register tty driver, "
  740. "errno=%d\n", -i);
  741. restore_flags(flags);
  742. return;
  743. }
  744. put_tty_driver(stli_serial);
  745. for (i = 0; i < 4; i++) {
  746. devfs_remove("staliomem/%d", i);
  747. class_device_destroy(istallion_class, MKDEV(STL_SIOMEMMAJOR, i));
  748. }
  749. devfs_remove("staliomem");
  750. class_destroy(istallion_class);
  751. if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
  752. printk("STALLION: failed to un-register serial memory device, "
  753. "errno=%d\n", -i);
  754. if (stli_tmpwritebuf != (char *) NULL)
  755. kfree(stli_tmpwritebuf);
  756. if (stli_txcookbuf != (char *) NULL)
  757. kfree(stli_txcookbuf);
  758. for (i = 0; (i < stli_nrbrds); i++) {
  759. if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL)
  760. continue;
  761. for (j = 0; (j < STL_MAXPORTS); j++) {
  762. portp = brdp->ports[j];
  763. if (portp != (stliport_t *) NULL) {
  764. if (portp->tty != (struct tty_struct *) NULL)
  765. tty_hangup(portp->tty);
  766. kfree(portp);
  767. }
  768. }
  769. iounmap(brdp->membase);
  770. if (brdp->iosize > 0)
  771. release_region(brdp->iobase, brdp->iosize);
  772. kfree(brdp);
  773. stli_brds[i] = (stlibrd_t *) NULL;
  774. }
  775. restore_flags(flags);
  776. }
  777. module_init(istallion_module_init);
  778. module_exit(istallion_module_exit);
  779. /*****************************************************************************/
  780. /*
  781. * Check for any arguments passed in on the module load command line.
  782. */
  783. static void stli_argbrds(void)
  784. {
  785. stlconf_t conf;
  786. stlibrd_t *brdp;
  787. int nrargs, i;
  788. #ifdef DEBUG
  789. printk("stli_argbrds()\n");
  790. #endif
  791. nrargs = sizeof(stli_brdsp) / sizeof(char **);
  792. for (i = stli_nrbrds; (i < nrargs); i++) {
  793. memset(&conf, 0, sizeof(conf));
  794. if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
  795. continue;
  796. if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
  797. continue;
  798. stli_nrbrds = i + 1;
  799. brdp->brdnr = i;
  800. brdp->brdtype = conf.brdtype;
  801. brdp->iobase = conf.ioaddr1;
  802. brdp->memaddr = conf.memaddr;
  803. stli_brdinit(brdp);
  804. }
  805. }
  806. /*****************************************************************************/
  807. /*
  808. * Convert an ascii string number into an unsigned long.
  809. */
  810. static unsigned long stli_atol(char *str)
  811. {
  812. unsigned long val;
  813. int base, c;
  814. char *sp;
  815. val = 0;
  816. sp = str;
  817. if ((*sp == '0') && (*(sp+1) == 'x')) {
  818. base = 16;
  819. sp += 2;
  820. } else if (*sp == '0') {
  821. base = 8;
  822. sp++;
  823. } else {
  824. base = 10;
  825. }
  826. for (; (*sp != 0); sp++) {
  827. c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
  828. if ((c < 0) || (c >= base)) {
  829. printk("STALLION: invalid argument %s\n", str);
  830. val = 0;
  831. break;
  832. }
  833. val = (val * base) + c;
  834. }
  835. return(val);
  836. }
  837. /*****************************************************************************/
  838. /*
  839. * Parse the supplied argument string, into the board conf struct.
  840. */
  841. static int stli_parsebrd(stlconf_t *confp, char **argp)
  842. {
  843. char *sp;
  844. int nrbrdnames, i;
  845. #ifdef DEBUG
  846. printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
  847. #endif
  848. if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
  849. return(0);
  850. for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
  851. *sp = TOLOWER(*sp);
  852. nrbrdnames = sizeof(stli_brdstr) / sizeof(stlibrdtype_t);
  853. for (i = 0; (i < nrbrdnames); i++) {
  854. if (strcmp(stli_brdstr[i].name, argp[0]) == 0)
  855. break;
  856. }
  857. if (i >= nrbrdnames) {
  858. printk("STALLION: unknown board name, %s?\n", argp[0]);
  859. return(0);
  860. }
  861. confp->brdtype = stli_brdstr[i].type;
  862. if ((argp[1] != (char *) NULL) && (*argp[1] != 0))
  863. confp->ioaddr1 = stli_atol(argp[1]);
  864. if ((argp[2] != (char *) NULL) && (*argp[2] != 0))
  865. confp->memaddr = stli_atol(argp[2]);
  866. return(1);
  867. }
  868. #endif
  869. /*****************************************************************************/
  870. /*
  871. * Local driver kernel malloc routine.
  872. */
  873. static void *stli_memalloc(int len)
  874. {
  875. return((void *) kmalloc(len, GFP_KERNEL));
  876. }
  877. /*****************************************************************************/
  878. static int stli_open(struct tty_struct *tty, struct file *filp)
  879. {
  880. stlibrd_t *brdp;
  881. stliport_t *portp;
  882. unsigned int minordev;
  883. int brdnr, portnr, rc;
  884. #ifdef DEBUG
  885. printk("stli_open(tty=%x,filp=%x): device=%s\n", (int) tty,
  886. (int) filp, tty->name);
  887. #endif
  888. minordev = tty->index;
  889. brdnr = MINOR2BRD(minordev);
  890. if (brdnr >= stli_nrbrds)
  891. return(-ENODEV);
  892. brdp = stli_brds[brdnr];
  893. if (brdp == (stlibrd_t *) NULL)
  894. return(-ENODEV);
  895. if ((brdp->state & BST_STARTED) == 0)
  896. return(-ENODEV);
  897. portnr = MINOR2PORT(minordev);
  898. if ((portnr < 0) || (portnr > brdp->nrports))
  899. return(-ENODEV);
  900. portp = brdp->ports[portnr];
  901. if (portp == (stliport_t *) NULL)
  902. return(-ENODEV);
  903. if (portp->devnr < 1)
  904. return(-ENODEV);
  905. /*
  906. * Check if this port is in the middle of closing. If so then wait
  907. * until it is closed then return error status based on flag settings.
  908. * The sleep here does not need interrupt protection since the wakeup
  909. * for it is done with the same context.
  910. */
  911. if (portp->flags & ASYNC_CLOSING) {
  912. interruptible_sleep_on(&portp->close_wait);
  913. if (portp->flags & ASYNC_HUP_NOTIFY)
  914. return(-EAGAIN);
  915. return(-ERESTARTSYS);
  916. }
  917. /*
  918. * On the first open of the device setup the port hardware, and
  919. * initialize the per port data structure. Since initializing the port
  920. * requires several commands to the board we will need to wait for any
  921. * other open that is already initializing the port.
  922. */
  923. portp->tty = tty;
  924. tty->driver_data = portp;
  925. portp->refcount++;
  926. wait_event_interruptible(portp->raw_wait,
  927. !test_bit(ST_INITIALIZING, &portp->state));
  928. if (signal_pending(current))
  929. return(-ERESTARTSYS);
  930. if ((portp->flags & ASYNC_INITIALIZED) == 0) {
  931. set_bit(ST_INITIALIZING, &portp->state);
  932. if ((rc = stli_initopen(brdp, portp)) >= 0) {
  933. portp->flags |= ASYNC_INITIALIZED;
  934. clear_bit(TTY_IO_ERROR, &tty->flags);
  935. }
  936. clear_bit(ST_INITIALIZING, &portp->state);
  937. wake_up_interruptible(&portp->raw_wait);
  938. if (rc < 0)
  939. return(rc);
  940. }
  941. /*
  942. * Check if this port is in the middle of closing. If so then wait
  943. * until it is closed then return error status, based on flag settings.
  944. * The sleep here does not need interrupt protection since the wakeup
  945. * for it is done with the same context.
  946. */
  947. if (portp->flags & ASYNC_CLOSING) {
  948. interruptible_sleep_on(&portp->close_wait);
  949. if (portp->flags & ASYNC_HUP_NOTIFY)
  950. return(-EAGAIN);
  951. return(-ERESTARTSYS);
  952. }
  953. /*
  954. * Based on type of open being done check if it can overlap with any
  955. * previous opens still in effect. If we are a normal serial device
  956. * then also we might have to wait for carrier.
  957. */
  958. if (!(filp->f_flags & O_NONBLOCK)) {
  959. if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
  960. return(rc);
  961. }
  962. portp->flags |= ASYNC_NORMAL_ACTIVE;
  963. return(0);
  964. }
  965. /*****************************************************************************/
  966. static void stli_close(struct tty_struct *tty, struct file *filp)
  967. {
  968. stlibrd_t *brdp;
  969. stliport_t *portp;
  970. unsigned long flags;
  971. #ifdef DEBUG
  972. printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
  973. #endif
  974. portp = tty->driver_data;
  975. if (portp == (stliport_t *) NULL)
  976. return;
  977. save_flags(flags);
  978. cli();
  979. if (tty_hung_up_p(filp)) {
  980. restore_flags(flags);
  981. return;
  982. }
  983. if ((tty->count == 1) && (portp->refcount != 1))
  984. portp->refcount = 1;
  985. if (portp->refcount-- > 1) {
  986. restore_flags(flags);
  987. return;
  988. }
  989. portp->flags |= ASYNC_CLOSING;
  990. /*
  991. * May want to wait for data to drain before closing. The BUSY flag
  992. * keeps track of whether we are still transmitting or not. It is
  993. * updated by messages from the slave - indicating when all chars
  994. * really have drained.
  995. */
  996. if (tty == stli_txcooktty)
  997. stli_flushchars(tty);
  998. tty->closing = 1;
  999. if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  1000. tty_wait_until_sent(tty, portp->closing_wait);
  1001. portp->flags &= ~ASYNC_INITIALIZED;
  1002. brdp = stli_brds[portp->brdnr];
  1003. stli_rawclose(brdp, portp, 0, 0);
  1004. if (tty->termios->c_cflag & HUPCL) {
  1005. stli_mkasysigs(&portp->asig, 0, 0);
  1006. if (test_bit(ST_CMDING, &portp->state))
  1007. set_bit(ST_DOSIGS, &portp->state);
  1008. else
  1009. stli_sendcmd(brdp, portp, A_SETSIGNALS, &portp->asig,
  1010. sizeof(asysigs_t), 0);
  1011. }
  1012. clear_bit(ST_TXBUSY, &portp->state);
  1013. clear_bit(ST_RXSTOP, &portp->state);
  1014. set_bit(TTY_IO_ERROR, &tty->flags);
  1015. if (tty->ldisc.flush_buffer)
  1016. (tty->ldisc.flush_buffer)(tty);
  1017. set_bit(ST_DOFLUSHRX, &portp->state);
  1018. stli_flushbuffer(tty);
  1019. tty->closing = 0;
  1020. portp->tty = (struct tty_struct *) NULL;
  1021. if (portp->openwaitcnt) {
  1022. if (portp->close_delay)
  1023. msleep_interruptible(jiffies_to_msecs(portp->close_delay));
  1024. wake_up_interruptible(&portp->open_wait);
  1025. }
  1026. portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
  1027. wake_up_interruptible(&portp->close_wait);
  1028. restore_flags(flags);
  1029. }
  1030. /*****************************************************************************/
  1031. /*
  1032. * Carry out first open operations on a port. This involves a number of
  1033. * commands to be sent to the slave. We need to open the port, set the
  1034. * notification events, set the initial port settings, get and set the
  1035. * initial signal values. We sleep and wait in between each one. But
  1036. * this still all happens pretty quickly.
  1037. */
  1038. static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
  1039. {
  1040. struct tty_struct *tty;
  1041. asynotify_t nt;
  1042. asyport_t aport;
  1043. int rc;
  1044. #ifdef DEBUG
  1045. printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
  1046. #endif
  1047. if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
  1048. return(rc);
  1049. memset(&nt, 0, sizeof(asynotify_t));
  1050. nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
  1051. nt.signal = SG_DCD;
  1052. if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
  1053. sizeof(asynotify_t), 0)) < 0)
  1054. return(rc);
  1055. tty = portp->tty;
  1056. if (tty == (struct tty_struct *) NULL)
  1057. return(-ENODEV);
  1058. stli_mkasyport(portp, &aport, tty->termios);
  1059. if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
  1060. sizeof(asyport_t), 0)) < 0)
  1061. return(rc);
  1062. set_bit(ST_GETSIGS, &portp->state);
  1063. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
  1064. sizeof(asysigs_t), 1)) < 0)
  1065. return(rc);
  1066. if (test_and_clear_bit(ST_GETSIGS, &portp->state))
  1067. portp->sigs = stli_mktiocm(portp->asig.sigvalue);
  1068. stli_mkasysigs(&portp->asig, 1, 1);
  1069. if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1070. sizeof(asysigs_t), 0)) < 0)
  1071. return(rc);
  1072. return(0);
  1073. }
  1074. /*****************************************************************************/
  1075. /*
  1076. * Send an open message to the slave. This will sleep waiting for the
  1077. * acknowledgement, so must have user context. We need to co-ordinate
  1078. * with close events here, since we don't want open and close events
  1079. * to overlap.
  1080. */
  1081. static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
  1082. {
  1083. volatile cdkhdr_t *hdrp;
  1084. volatile cdkctrl_t *cp;
  1085. volatile unsigned char *bits;
  1086. unsigned long flags;
  1087. int rc;
  1088. #ifdef DEBUG
  1089. printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
  1090. (int) brdp, (int) portp, (int) arg, wait);
  1091. #endif
  1092. /*
  1093. * Send a message to the slave to open this port.
  1094. */
  1095. save_flags(flags);
  1096. cli();
  1097. /*
  1098. * Slave is already closing this port. This can happen if a hangup
  1099. * occurs on this port. So we must wait until it is complete. The
  1100. * order of opens and closes may not be preserved across shared
  1101. * memory, so we must wait until it is complete.
  1102. */
  1103. wait_event_interruptible(portp->raw_wait,
  1104. !test_bit(ST_CLOSING, &portp->state));
  1105. if (signal_pending(current)) {
  1106. restore_flags(flags);
  1107. return -ERESTARTSYS;
  1108. }
  1109. /*
  1110. * Everything is ready now, so write the open message into shared
  1111. * memory. Once the message is in set the service bits to say that
  1112. * this port wants service.
  1113. */
  1114. EBRDENABLE(brdp);
  1115. cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  1116. cp->openarg = arg;
  1117. cp->open = 1;
  1118. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1119. bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
  1120. portp->portidx;
  1121. *bits |= portp->portbit;
  1122. EBRDDISABLE(brdp);
  1123. if (wait == 0) {
  1124. restore_flags(flags);
  1125. return(0);
  1126. }
  1127. /*
  1128. * Slave is in action, so now we must wait for the open acknowledgment
  1129. * to come back.
  1130. */
  1131. rc = 0;
  1132. set_bit(ST_OPENING, &portp->state);
  1133. wait_event_interruptible(portp->raw_wait,
  1134. !test_bit(ST_OPENING, &portp->state));
  1135. if (signal_pending(current))
  1136. rc = -ERESTARTSYS;
  1137. restore_flags(flags);
  1138. if ((rc == 0) && (portp->rc != 0))
  1139. rc = -EIO;
  1140. return(rc);
  1141. }
  1142. /*****************************************************************************/
  1143. /*
  1144. * Send a close message to the slave. Normally this will sleep waiting
  1145. * for the acknowledgement, but if wait parameter is 0 it will not. If
  1146. * wait is true then must have user context (to sleep).
  1147. */
  1148. static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
  1149. {
  1150. volatile cdkhdr_t *hdrp;
  1151. volatile cdkctrl_t *cp;
  1152. volatile unsigned char *bits;
  1153. unsigned long flags;
  1154. int rc;
  1155. #ifdef DEBUG
  1156. printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
  1157. (int) brdp, (int) portp, (int) arg, wait);
  1158. #endif
  1159. save_flags(flags);
  1160. cli();
  1161. /*
  1162. * Slave is already closing this port. This can happen if a hangup
  1163. * occurs on this port.
  1164. */
  1165. if (wait) {
  1166. wait_event_interruptible(portp->raw_wait,
  1167. !test_bit(ST_CLOSING, &portp->state));
  1168. if (signal_pending(current)) {
  1169. restore_flags(flags);
  1170. return -ERESTARTSYS;
  1171. }
  1172. }
  1173. /*
  1174. * Write the close command into shared memory.
  1175. */
  1176. EBRDENABLE(brdp);
  1177. cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  1178. cp->closearg = arg;
  1179. cp->close = 1;
  1180. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1181. bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
  1182. portp->portidx;
  1183. *bits |= portp->portbit;
  1184. EBRDDISABLE(brdp);
  1185. set_bit(ST_CLOSING, &portp->state);
  1186. if (wait == 0) {
  1187. restore_flags(flags);
  1188. return(0);
  1189. }
  1190. /*
  1191. * Slave is in action, so now we must wait for the open acknowledgment
  1192. * to come back.
  1193. */
  1194. rc = 0;
  1195. wait_event_interruptible(portp->raw_wait,
  1196. !test_bit(ST_CLOSING, &portp->state));
  1197. if (signal_pending(current))
  1198. rc = -ERESTARTSYS;
  1199. restore_flags(flags);
  1200. if ((rc == 0) && (portp->rc != 0))
  1201. rc = -EIO;
  1202. return(rc);
  1203. }
  1204. /*****************************************************************************/
  1205. /*
  1206. * Send a command to the slave and wait for the response. This must
  1207. * have user context (it sleeps). This routine is generic in that it
  1208. * can send any type of command. Its purpose is to wait for that command
  1209. * to complete (as opposed to initiating the command then returning).
  1210. */
  1211. static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
  1212. {
  1213. unsigned long flags;
  1214. #ifdef DEBUG
  1215. printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
  1216. "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
  1217. (int) arg, size, copyback);
  1218. #endif
  1219. save_flags(flags);
  1220. cli();
  1221. wait_event_interruptible(portp->raw_wait,
  1222. !test_bit(ST_CMDING, &portp->state));
  1223. if (signal_pending(current)) {
  1224. restore_flags(flags);
  1225. return -ERESTARTSYS;
  1226. }
  1227. stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
  1228. wait_event_interruptible(portp->raw_wait,
  1229. !test_bit(ST_CMDING, &portp->state));
  1230. if (signal_pending(current)) {
  1231. restore_flags(flags);
  1232. return -ERESTARTSYS;
  1233. }
  1234. restore_flags(flags);
  1235. if (portp->rc != 0)
  1236. return(-EIO);
  1237. return(0);
  1238. }
  1239. /*****************************************************************************/
  1240. /*
  1241. * Send the termios settings for this port to the slave. This sleeps
  1242. * waiting for the command to complete - so must have user context.
  1243. */
  1244. static int stli_setport(stliport_t *portp)
  1245. {
  1246. stlibrd_t *brdp;
  1247. asyport_t aport;
  1248. #ifdef DEBUG
  1249. printk("stli_setport(portp=%x)\n", (int) portp);
  1250. #endif
  1251. if (portp == (stliport_t *) NULL)
  1252. return(-ENODEV);
  1253. if (portp->tty == (struct tty_struct *) NULL)
  1254. return(-ENODEV);
  1255. if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds))
  1256. return(-ENODEV);
  1257. brdp = stli_brds[portp->brdnr];
  1258. if (brdp == (stlibrd_t *) NULL)
  1259. return(-ENODEV);
  1260. stli_mkasyport(portp, &aport, portp->tty->termios);
  1261. return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
  1262. }
  1263. /*****************************************************************************/
  1264. /*
  1265. * Possibly need to wait for carrier (DCD signal) to come high. Say
  1266. * maybe because if we are clocal then we don't need to wait...
  1267. */
  1268. static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
  1269. {
  1270. unsigned long flags;
  1271. int rc, doclocal;
  1272. #ifdef DEBUG
  1273. printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
  1274. (int) brdp, (int) portp, (int) filp);
  1275. #endif
  1276. rc = 0;
  1277. doclocal = 0;
  1278. if (portp->tty->termios->c_cflag & CLOCAL)
  1279. doclocal++;
  1280. save_flags(flags);
  1281. cli();
  1282. portp->openwaitcnt++;
  1283. if (! tty_hung_up_p(filp))
  1284. portp->refcount--;
  1285. for (;;) {
  1286. stli_mkasysigs(&portp->asig, 1, 1);
  1287. if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS,
  1288. &portp->asig, sizeof(asysigs_t), 0)) < 0)
  1289. break;
  1290. if (tty_hung_up_p(filp) ||
  1291. ((portp->flags & ASYNC_INITIALIZED) == 0)) {
  1292. if (portp->flags & ASYNC_HUP_NOTIFY)
  1293. rc = -EBUSY;
  1294. else
  1295. rc = -ERESTARTSYS;
  1296. break;
  1297. }
  1298. if (((portp->flags & ASYNC_CLOSING) == 0) &&
  1299. (doclocal || (portp->sigs & TIOCM_CD))) {
  1300. break;
  1301. }
  1302. if (signal_pending(current)) {
  1303. rc = -ERESTARTSYS;
  1304. break;
  1305. }
  1306. interruptible_sleep_on(&portp->open_wait);
  1307. }
  1308. if (! tty_hung_up_p(filp))
  1309. portp->refcount++;
  1310. portp->openwaitcnt--;
  1311. restore_flags(flags);
  1312. return(rc);
  1313. }
  1314. /*****************************************************************************/
  1315. /*
  1316. * Write routine. Take the data and put it in the shared memory ring
  1317. * queue. If port is not already sending chars then need to mark the
  1318. * service bits for this port.
  1319. */
  1320. static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
  1321. {
  1322. volatile cdkasy_t *ap;
  1323. volatile cdkhdr_t *hdrp;
  1324. volatile unsigned char *bits;
  1325. unsigned char *shbuf, *chbuf;
  1326. stliport_t *portp;
  1327. stlibrd_t *brdp;
  1328. unsigned int len, stlen, head, tail, size;
  1329. unsigned long flags;
  1330. #ifdef DEBUG
  1331. printk("stli_write(tty=%x,buf=%x,count=%d)\n",
  1332. (int) tty, (int) buf, count);
  1333. #endif
  1334. if ((tty == (struct tty_struct *) NULL) ||
  1335. (stli_tmpwritebuf == (char *) NULL))
  1336. return(0);
  1337. if (tty == stli_txcooktty)
  1338. stli_flushchars(tty);
  1339. portp = tty->driver_data;
  1340. if (portp == (stliport_t *) NULL)
  1341. return(0);
  1342. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1343. return(0);
  1344. brdp = stli_brds[portp->brdnr];
  1345. if (brdp == (stlibrd_t *) NULL)
  1346. return(0);
  1347. chbuf = (unsigned char *) buf;
  1348. /*
  1349. * All data is now local, shove as much as possible into shared memory.
  1350. */
  1351. save_flags(flags);
  1352. cli();
  1353. EBRDENABLE(brdp);
  1354. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  1355. head = (unsigned int) ap->txq.head;
  1356. tail = (unsigned int) ap->txq.tail;
  1357. if (tail != ((unsigned int) ap->txq.tail))
  1358. tail = (unsigned int) ap->txq.tail;
  1359. size = portp->txsize;
  1360. if (head >= tail) {
  1361. len = size - (head - tail) - 1;
  1362. stlen = size - head;
  1363. } else {
  1364. len = tail - head - 1;
  1365. stlen = len;
  1366. }
  1367. len = MIN(len, count);
  1368. count = 0;
  1369. shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
  1370. while (len > 0) {
  1371. stlen = MIN(len, stlen);
  1372. memcpy((shbuf + head), chbuf, stlen);
  1373. chbuf += stlen;
  1374. len -= stlen;
  1375. count += stlen;
  1376. head += stlen;
  1377. if (head >= size) {
  1378. head = 0;
  1379. stlen = tail;
  1380. }
  1381. }
  1382. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  1383. ap->txq.head = head;
  1384. if (test_bit(ST_TXBUSY, &portp->state)) {
  1385. if (ap->changed.data & DT_TXEMPTY)
  1386. ap->changed.data &= ~DT_TXEMPTY;
  1387. }
  1388. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1389. bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
  1390. portp->portidx;
  1391. *bits |= portp->portbit;
  1392. set_bit(ST_TXBUSY, &portp->state);
  1393. EBRDDISABLE(brdp);
  1394. restore_flags(flags);
  1395. return(count);
  1396. }
  1397. /*****************************************************************************/
  1398. /*
  1399. * Output a single character. We put it into a temporary local buffer
  1400. * (for speed) then write out that buffer when the flushchars routine
  1401. * is called. There is a safety catch here so that if some other port
  1402. * writes chars before the current buffer has been, then we write them
  1403. * first them do the new ports.
  1404. */
  1405. static void stli_putchar(struct tty_struct *tty, unsigned char ch)
  1406. {
  1407. #ifdef DEBUG
  1408. printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
  1409. #endif
  1410. if (tty == (struct tty_struct *) NULL)
  1411. return;
  1412. if (tty != stli_txcooktty) {
  1413. if (stli_txcooktty != (struct tty_struct *) NULL)
  1414. stli_flushchars(stli_txcooktty);
  1415. stli_txcooktty = tty;
  1416. }
  1417. stli_txcookbuf[stli_txcooksize++] = ch;
  1418. }
  1419. /*****************************************************************************/
  1420. /*
  1421. * Transfer characters from the local TX cooking buffer to the board.
  1422. * We sort of ignore the tty that gets passed in here. We rely on the
  1423. * info stored with the TX cook buffer to tell us which port to flush
  1424. * the data on. In any case we clean out the TX cook buffer, for re-use
  1425. * by someone else.
  1426. */
  1427. static void stli_flushchars(struct tty_struct *tty)
  1428. {
  1429. volatile cdkhdr_t *hdrp;
  1430. volatile unsigned char *bits;
  1431. volatile cdkasy_t *ap;
  1432. struct tty_struct *cooktty;
  1433. stliport_t *portp;
  1434. stlibrd_t *brdp;
  1435. unsigned int len, stlen, head, tail, size, count, cooksize;
  1436. unsigned char *buf, *shbuf;
  1437. unsigned long flags;
  1438. #ifdef DEBUG
  1439. printk("stli_flushchars(tty=%x)\n", (int) tty);
  1440. #endif
  1441. cooksize = stli_txcooksize;
  1442. cooktty = stli_txcooktty;
  1443. stli_txcooksize = 0;
  1444. stli_txcookrealsize = 0;
  1445. stli_txcooktty = (struct tty_struct *) NULL;
  1446. if (tty == (struct tty_struct *) NULL)
  1447. return;
  1448. if (cooktty == (struct tty_struct *) NULL)
  1449. return;
  1450. if (tty != cooktty)
  1451. tty = cooktty;
  1452. if (cooksize == 0)
  1453. return;
  1454. portp = tty->driver_data;
  1455. if (portp == (stliport_t *) NULL)
  1456. return;
  1457. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1458. return;
  1459. brdp = stli_brds[portp->brdnr];
  1460. if (brdp == (stlibrd_t *) NULL)
  1461. return;
  1462. save_flags(flags);
  1463. cli();
  1464. EBRDENABLE(brdp);
  1465. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  1466. head = (unsigned int) ap->txq.head;
  1467. tail = (unsigned int) ap->txq.tail;
  1468. if (tail != ((unsigned int) ap->txq.tail))
  1469. tail = (unsigned int) ap->txq.tail;
  1470. size = portp->txsize;
  1471. if (head >= tail) {
  1472. len = size - (head - tail) - 1;
  1473. stlen = size - head;
  1474. } else {
  1475. len = tail - head - 1;
  1476. stlen = len;
  1477. }
  1478. len = MIN(len, cooksize);
  1479. count = 0;
  1480. shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset);
  1481. buf = stli_txcookbuf;
  1482. while (len > 0) {
  1483. stlen = MIN(len, stlen);
  1484. memcpy((shbuf + head), buf, stlen);
  1485. buf += stlen;
  1486. len -= stlen;
  1487. count += stlen;
  1488. head += stlen;
  1489. if (head >= size) {
  1490. head = 0;
  1491. stlen = tail;
  1492. }
  1493. }
  1494. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  1495. ap->txq.head = head;
  1496. if (test_bit(ST_TXBUSY, &portp->state)) {
  1497. if (ap->changed.data & DT_TXEMPTY)
  1498. ap->changed.data &= ~DT_TXEMPTY;
  1499. }
  1500. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  1501. bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
  1502. portp->portidx;
  1503. *bits |= portp->portbit;
  1504. set_bit(ST_TXBUSY, &portp->state);
  1505. EBRDDISABLE(brdp);
  1506. restore_flags(flags);
  1507. }
  1508. /*****************************************************************************/
  1509. static int stli_writeroom(struct tty_struct *tty)
  1510. {
  1511. volatile cdkasyrq_t *rp;
  1512. stliport_t *portp;
  1513. stlibrd_t *brdp;
  1514. unsigned int head, tail, len;
  1515. unsigned long flags;
  1516. #ifdef DEBUG
  1517. printk("stli_writeroom(tty=%x)\n", (int) tty);
  1518. #endif
  1519. if (tty == (struct tty_struct *) NULL)
  1520. return(0);
  1521. if (tty == stli_txcooktty) {
  1522. if (stli_txcookrealsize != 0) {
  1523. len = stli_txcookrealsize - stli_txcooksize;
  1524. return(len);
  1525. }
  1526. }
  1527. portp = tty->driver_data;
  1528. if (portp == (stliport_t *) NULL)
  1529. return(0);
  1530. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1531. return(0);
  1532. brdp = stli_brds[portp->brdnr];
  1533. if (brdp == (stlibrd_t *) NULL)
  1534. return(0);
  1535. save_flags(flags);
  1536. cli();
  1537. EBRDENABLE(brdp);
  1538. rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1539. head = (unsigned int) rp->head;
  1540. tail = (unsigned int) rp->tail;
  1541. if (tail != ((unsigned int) rp->tail))
  1542. tail = (unsigned int) rp->tail;
  1543. len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
  1544. len--;
  1545. EBRDDISABLE(brdp);
  1546. restore_flags(flags);
  1547. if (tty == stli_txcooktty) {
  1548. stli_txcookrealsize = len;
  1549. len -= stli_txcooksize;
  1550. }
  1551. return(len);
  1552. }
  1553. /*****************************************************************************/
  1554. /*
  1555. * Return the number of characters in the transmit buffer. Normally we
  1556. * will return the number of chars in the shared memory ring queue.
  1557. * We need to kludge around the case where the shared memory buffer is
  1558. * empty but not all characters have drained yet, for this case just
  1559. * return that there is 1 character in the buffer!
  1560. */
  1561. static int stli_charsinbuffer(struct tty_struct *tty)
  1562. {
  1563. volatile cdkasyrq_t *rp;
  1564. stliport_t *portp;
  1565. stlibrd_t *brdp;
  1566. unsigned int head, tail, len;
  1567. unsigned long flags;
  1568. #ifdef DEBUG
  1569. printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
  1570. #endif
  1571. if (tty == (struct tty_struct *) NULL)
  1572. return(0);
  1573. if (tty == stli_txcooktty)
  1574. stli_flushchars(tty);
  1575. portp = tty->driver_data;
  1576. if (portp == (stliport_t *) NULL)
  1577. return(0);
  1578. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1579. return(0);
  1580. brdp = stli_brds[portp->brdnr];
  1581. if (brdp == (stlibrd_t *) NULL)
  1582. return(0);
  1583. save_flags(flags);
  1584. cli();
  1585. EBRDENABLE(brdp);
  1586. rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
  1587. head = (unsigned int) rp->head;
  1588. tail = (unsigned int) rp->tail;
  1589. if (tail != ((unsigned int) rp->tail))
  1590. tail = (unsigned int) rp->tail;
  1591. len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
  1592. if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
  1593. len = 1;
  1594. EBRDDISABLE(brdp);
  1595. restore_flags(flags);
  1596. return(len);
  1597. }
  1598. /*****************************************************************************/
  1599. /*
  1600. * Generate the serial struct info.
  1601. */
  1602. static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
  1603. {
  1604. struct serial_struct sio;
  1605. stlibrd_t *brdp;
  1606. #ifdef DEBUG
  1607. printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
  1608. #endif
  1609. memset(&sio, 0, sizeof(struct serial_struct));
  1610. sio.type = PORT_UNKNOWN;
  1611. sio.line = portp->portnr;
  1612. sio.irq = 0;
  1613. sio.flags = portp->flags;
  1614. sio.baud_base = portp->baud_base;
  1615. sio.close_delay = portp->close_delay;
  1616. sio.closing_wait = portp->closing_wait;
  1617. sio.custom_divisor = portp->custom_divisor;
  1618. sio.xmit_fifo_size = 0;
  1619. sio.hub6 = 0;
  1620. brdp = stli_brds[portp->brdnr];
  1621. if (brdp != (stlibrd_t *) NULL)
  1622. sio.port = brdp->iobase;
  1623. return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
  1624. -EFAULT : 0;
  1625. }
  1626. /*****************************************************************************/
  1627. /*
  1628. * Set port according to the serial struct info.
  1629. * At this point we do not do any auto-configure stuff, so we will
  1630. * just quietly ignore any requests to change irq, etc.
  1631. */
  1632. static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
  1633. {
  1634. struct serial_struct sio;
  1635. int rc;
  1636. #ifdef DEBUG
  1637. printk("stli_setserial(portp=%p,sp=%p)\n", portp, sp);
  1638. #endif
  1639. if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
  1640. return -EFAULT;
  1641. if (!capable(CAP_SYS_ADMIN)) {
  1642. if ((sio.baud_base != portp->baud_base) ||
  1643. (sio.close_delay != portp->close_delay) ||
  1644. ((sio.flags & ~ASYNC_USR_MASK) !=
  1645. (portp->flags & ~ASYNC_USR_MASK)))
  1646. return(-EPERM);
  1647. }
  1648. portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
  1649. (sio.flags & ASYNC_USR_MASK);
  1650. portp->baud_base = sio.baud_base;
  1651. portp->close_delay = sio.close_delay;
  1652. portp->closing_wait = sio.closing_wait;
  1653. portp->custom_divisor = sio.custom_divisor;
  1654. if ((rc = stli_setport(portp)) < 0)
  1655. return(rc);
  1656. return(0);
  1657. }
  1658. /*****************************************************************************/
  1659. static int stli_tiocmget(struct tty_struct *tty, struct file *file)
  1660. {
  1661. stliport_t *portp = tty->driver_data;
  1662. stlibrd_t *brdp;
  1663. int rc;
  1664. if (portp == (stliport_t *) NULL)
  1665. return(-ENODEV);
  1666. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1667. return(0);
  1668. brdp = stli_brds[portp->brdnr];
  1669. if (brdp == (stlibrd_t *) NULL)
  1670. return(0);
  1671. if (tty->flags & (1 << TTY_IO_ERROR))
  1672. return(-EIO);
  1673. if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
  1674. &portp->asig, sizeof(asysigs_t), 1)) < 0)
  1675. return(rc);
  1676. return stli_mktiocm(portp->asig.sigvalue);
  1677. }
  1678. static int stli_tiocmset(struct tty_struct *tty, struct file *file,
  1679. unsigned int set, unsigned int clear)
  1680. {
  1681. stliport_t *portp = tty->driver_data;
  1682. stlibrd_t *brdp;
  1683. int rts = -1, dtr = -1;
  1684. if (portp == (stliport_t *) NULL)
  1685. return(-ENODEV);
  1686. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1687. return(0);
  1688. brdp = stli_brds[portp->brdnr];
  1689. if (brdp == (stlibrd_t *) NULL)
  1690. return(0);
  1691. if (tty->flags & (1 << TTY_IO_ERROR))
  1692. return(-EIO);
  1693. if (set & TIOCM_RTS)
  1694. rts = 1;
  1695. if (set & TIOCM_DTR)
  1696. dtr = 1;
  1697. if (clear & TIOCM_RTS)
  1698. rts = 0;
  1699. if (clear & TIOCM_DTR)
  1700. dtr = 0;
  1701. stli_mkasysigs(&portp->asig, dtr, rts);
  1702. return stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1703. sizeof(asysigs_t), 0);
  1704. }
  1705. static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
  1706. {
  1707. stliport_t *portp;
  1708. stlibrd_t *brdp;
  1709. unsigned int ival;
  1710. int rc;
  1711. void __user *argp = (void __user *)arg;
  1712. #ifdef DEBUG
  1713. printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
  1714. (int) tty, (int) file, cmd, (int) arg);
  1715. #endif
  1716. if (tty == (struct tty_struct *) NULL)
  1717. return(-ENODEV);
  1718. portp = tty->driver_data;
  1719. if (portp == (stliport_t *) NULL)
  1720. return(-ENODEV);
  1721. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1722. return(0);
  1723. brdp = stli_brds[portp->brdnr];
  1724. if (brdp == (stlibrd_t *) NULL)
  1725. return(0);
  1726. if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
  1727. (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
  1728. if (tty->flags & (1 << TTY_IO_ERROR))
  1729. return(-EIO);
  1730. }
  1731. rc = 0;
  1732. switch (cmd) {
  1733. case TIOCGSOFTCAR:
  1734. rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
  1735. (unsigned __user *) arg);
  1736. break;
  1737. case TIOCSSOFTCAR:
  1738. if ((rc = get_user(ival, (unsigned __user *) arg)) == 0)
  1739. tty->termios->c_cflag =
  1740. (tty->termios->c_cflag & ~CLOCAL) |
  1741. (ival ? CLOCAL : 0);
  1742. break;
  1743. case TIOCGSERIAL:
  1744. rc = stli_getserial(portp, argp);
  1745. break;
  1746. case TIOCSSERIAL:
  1747. rc = stli_setserial(portp, argp);
  1748. break;
  1749. case STL_GETPFLAG:
  1750. rc = put_user(portp->pflag, (unsigned __user *)argp);
  1751. break;
  1752. case STL_SETPFLAG:
  1753. if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
  1754. stli_setport(portp);
  1755. break;
  1756. case COM_GETPORTSTATS:
  1757. rc = stli_getportstats(portp, argp);
  1758. break;
  1759. case COM_CLRPORTSTATS:
  1760. rc = stli_clrportstats(portp, argp);
  1761. break;
  1762. case TIOCSERCONFIG:
  1763. case TIOCSERGWILD:
  1764. case TIOCSERSWILD:
  1765. case TIOCSERGETLSR:
  1766. case TIOCSERGSTRUCT:
  1767. case TIOCSERGETMULTI:
  1768. case TIOCSERSETMULTI:
  1769. default:
  1770. rc = -ENOIOCTLCMD;
  1771. break;
  1772. }
  1773. return(rc);
  1774. }
  1775. /*****************************************************************************/
  1776. /*
  1777. * This routine assumes that we have user context and can sleep.
  1778. * Looks like it is true for the current ttys implementation..!!
  1779. */
  1780. static void stli_settermios(struct tty_struct *tty, struct termios *old)
  1781. {
  1782. stliport_t *portp;
  1783. stlibrd_t *brdp;
  1784. struct termios *tiosp;
  1785. asyport_t aport;
  1786. #ifdef DEBUG
  1787. printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
  1788. #endif
  1789. if (tty == (struct tty_struct *) NULL)
  1790. return;
  1791. portp = tty->driver_data;
  1792. if (portp == (stliport_t *) NULL)
  1793. return;
  1794. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1795. return;
  1796. brdp = stli_brds[portp->brdnr];
  1797. if (brdp == (stlibrd_t *) NULL)
  1798. return;
  1799. tiosp = tty->termios;
  1800. if ((tiosp->c_cflag == old->c_cflag) &&
  1801. (tiosp->c_iflag == old->c_iflag))
  1802. return;
  1803. stli_mkasyport(portp, &aport, tiosp);
  1804. stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
  1805. stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
  1806. stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
  1807. sizeof(asysigs_t), 0);
  1808. if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0))
  1809. tty->hw_stopped = 0;
  1810. if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
  1811. wake_up_interruptible(&portp->open_wait);
  1812. }
  1813. /*****************************************************************************/
  1814. /*
  1815. * Attempt to flow control who ever is sending us data. We won't really
  1816. * do any flow control action here. We can't directly, and even if we
  1817. * wanted to we would have to send a command to the slave. The slave
  1818. * knows how to flow control, and will do so when its buffers reach its
  1819. * internal high water marks. So what we will do is set a local state
  1820. * bit that will stop us sending any RX data up from the poll routine
  1821. * (which is the place where RX data from the slave is handled).
  1822. */
  1823. static void stli_throttle(struct tty_struct *tty)
  1824. {
  1825. stliport_t *portp;
  1826. #ifdef DEBUG
  1827. printk("stli_throttle(tty=%x)\n", (int) tty);
  1828. #endif
  1829. if (tty == (struct tty_struct *) NULL)
  1830. return;
  1831. portp = tty->driver_data;
  1832. if (portp == (stliport_t *) NULL)
  1833. return;
  1834. set_bit(ST_RXSTOP, &portp->state);
  1835. }
  1836. /*****************************************************************************/
  1837. /*
  1838. * Unflow control the device sending us data... That means that all
  1839. * we have to do is clear the RXSTOP state bit. The next poll call
  1840. * will then be able to pass the RX data back up.
  1841. */
  1842. static void stli_unthrottle(struct tty_struct *tty)
  1843. {
  1844. stliport_t *portp;
  1845. #ifdef DEBUG
  1846. printk("stli_unthrottle(tty=%x)\n", (int) tty);
  1847. #endif
  1848. if (tty == (struct tty_struct *) NULL)
  1849. return;
  1850. portp = tty->driver_data;
  1851. if (portp == (stliport_t *) NULL)
  1852. return;
  1853. clear_bit(ST_RXSTOP, &portp->state);
  1854. }
  1855. /*****************************************************************************/
  1856. /*
  1857. * Stop the transmitter. Basically to do this we will just turn TX
  1858. * interrupts off.
  1859. */
  1860. static void stli_stop(struct tty_struct *tty)
  1861. {
  1862. stlibrd_t *brdp;
  1863. stliport_t *portp;
  1864. asyctrl_t actrl;
  1865. #ifdef DEBUG
  1866. printk("stli_stop(tty=%x)\n", (int) tty);
  1867. #endif
  1868. if (tty == (struct tty_struct *) NULL)
  1869. return;
  1870. portp = tty->driver_data;
  1871. if (portp == (stliport_t *) NULL)
  1872. return;
  1873. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1874. return;
  1875. brdp = stli_brds[portp->brdnr];
  1876. if (brdp == (stlibrd_t *) NULL)
  1877. return;
  1878. memset(&actrl, 0, sizeof(asyctrl_t));
  1879. actrl.txctrl = CT_STOPFLOW;
  1880. #if 0
  1881. stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
  1882. #endif
  1883. }
  1884. /*****************************************************************************/
  1885. /*
  1886. * Start the transmitter again. Just turn TX interrupts back on.
  1887. */
  1888. static void stli_start(struct tty_struct *tty)
  1889. {
  1890. stliport_t *portp;
  1891. stlibrd_t *brdp;
  1892. asyctrl_t actrl;
  1893. #ifdef DEBUG
  1894. printk("stli_start(tty=%x)\n", (int) tty);
  1895. #endif
  1896. if (tty == (struct tty_struct *) NULL)
  1897. return;
  1898. portp = tty->driver_data;
  1899. if (portp == (stliport_t *) NULL)
  1900. return;
  1901. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1902. return;
  1903. brdp = stli_brds[portp->brdnr];
  1904. if (brdp == (stlibrd_t *) NULL)
  1905. return;
  1906. memset(&actrl, 0, sizeof(asyctrl_t));
  1907. actrl.txctrl = CT_STARTFLOW;
  1908. #if 0
  1909. stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
  1910. #endif
  1911. }
  1912. /*****************************************************************************/
  1913. /*
  1914. * Scheduler called hang up routine. This is called from the scheduler,
  1915. * not direct from the driver "poll" routine. We can't call it there
  1916. * since the real local hangup code will enable/disable the board and
  1917. * other things that we can't do while handling the poll. Much easier
  1918. * to deal with it some time later (don't really care when, hangups
  1919. * aren't that time critical).
  1920. */
  1921. static void stli_dohangup(void *arg)
  1922. {
  1923. stliport_t *portp;
  1924. #ifdef DEBUG
  1925. printk(KERN_DEBUG "stli_dohangup(portp=%x)\n", (int) arg);
  1926. #endif
  1927. /*
  1928. * FIXME: There's a module removal race here: tty_hangup
  1929. * calls schedule_work which will call into this
  1930. * driver later.
  1931. */
  1932. portp = (stliport_t *) arg;
  1933. if (portp != (stliport_t *) NULL) {
  1934. if (portp->tty != (struct tty_struct *) NULL) {
  1935. tty_hangup(portp->tty);
  1936. }
  1937. }
  1938. }
  1939. /*****************************************************************************/
  1940. /*
  1941. * Hangup this port. This is pretty much like closing the port, only
  1942. * a little more brutal. No waiting for data to drain. Shutdown the
  1943. * port and maybe drop signals. This is rather tricky really. We want
  1944. * to close the port as well.
  1945. */
  1946. static void stli_hangup(struct tty_struct *tty)
  1947. {
  1948. stliport_t *portp;
  1949. stlibrd_t *brdp;
  1950. unsigned long flags;
  1951. #ifdef DEBUG
  1952. printk(KERN_DEBUG "stli_hangup(tty=%x)\n", (int) tty);
  1953. #endif
  1954. if (tty == (struct tty_struct *) NULL)
  1955. return;
  1956. portp = tty->driver_data;
  1957. if (portp == (stliport_t *) NULL)
  1958. return;
  1959. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  1960. return;
  1961. brdp = stli_brds[portp->brdnr];
  1962. if (brdp == (stlibrd_t *) NULL)
  1963. return;
  1964. portp->flags &= ~ASYNC_INITIALIZED;
  1965. save_flags(flags);
  1966. cli();
  1967. if (! test_bit(ST_CLOSING, &portp->state))
  1968. stli_rawclose(brdp, portp, 0, 0);
  1969. if (tty->termios->c_cflag & HUPCL) {
  1970. stli_mkasysigs(&portp->asig, 0, 0);
  1971. if (test_bit(ST_CMDING, &portp->state)) {
  1972. set_bit(ST_DOSIGS, &portp->state);
  1973. set_bit(ST_DOFLUSHTX, &portp->state);
  1974. set_bit(ST_DOFLUSHRX, &portp->state);
  1975. } else {
  1976. stli_sendcmd(brdp, portp, A_SETSIGNALSF,
  1977. &portp->asig, sizeof(asysigs_t), 0);
  1978. }
  1979. }
  1980. restore_flags(flags);
  1981. clear_bit(ST_TXBUSY, &portp->state);
  1982. clear_bit(ST_RXSTOP, &portp->state);
  1983. set_bit(TTY_IO_ERROR, &tty->flags);
  1984. portp->tty = (struct tty_struct *) NULL;
  1985. portp->flags &= ~ASYNC_NORMAL_ACTIVE;
  1986. portp->refcount = 0;
  1987. wake_up_interruptible(&portp->open_wait);
  1988. }
  1989. /*****************************************************************************/
  1990. /*
  1991. * Flush characters from the lower buffer. We may not have user context
  1992. * so we cannot sleep waiting for it to complete. Also we need to check
  1993. * if there is chars for this port in the TX cook buffer, and flush them
  1994. * as well.
  1995. */
  1996. static void stli_flushbuffer(struct tty_struct *tty)
  1997. {
  1998. stliport_t *portp;
  1999. stlibrd_t *brdp;
  2000. unsigned long ftype, flags;
  2001. #ifdef DEBUG
  2002. printk(KERN_DEBUG "stli_flushbuffer(tty=%x)\n", (int) tty);
  2003. #endif
  2004. if (tty == (struct tty_struct *) NULL)
  2005. return;
  2006. portp = tty->driver_data;
  2007. if (portp == (stliport_t *) NULL)
  2008. return;
  2009. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  2010. return;
  2011. brdp = stli_brds[portp->brdnr];
  2012. if (brdp == (stlibrd_t *) NULL)
  2013. return;
  2014. save_flags(flags);
  2015. cli();
  2016. if (tty == stli_txcooktty) {
  2017. stli_txcooktty = (struct tty_struct *) NULL;
  2018. stli_txcooksize = 0;
  2019. stli_txcookrealsize = 0;
  2020. }
  2021. if (test_bit(ST_CMDING, &portp->state)) {
  2022. set_bit(ST_DOFLUSHTX, &portp->state);
  2023. } else {
  2024. ftype = FLUSHTX;
  2025. if (test_bit(ST_DOFLUSHRX, &portp->state)) {
  2026. ftype |= FLUSHRX;
  2027. clear_bit(ST_DOFLUSHRX, &portp->state);
  2028. }
  2029. stli_sendcmd(brdp, portp, A_FLUSH, &ftype,
  2030. sizeof(unsigned long), 0);
  2031. }
  2032. restore_flags(flags);
  2033. wake_up_interruptible(&tty->write_wait);
  2034. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  2035. tty->ldisc.write_wakeup)
  2036. (tty->ldisc.write_wakeup)(tty);
  2037. }
  2038. /*****************************************************************************/
  2039. static void stli_breakctl(struct tty_struct *tty, int state)
  2040. {
  2041. stlibrd_t *brdp;
  2042. stliport_t *portp;
  2043. long arg;
  2044. /* long savestate, savetime; */
  2045. #ifdef DEBUG
  2046. printk(KERN_DEBUG "stli_breakctl(tty=%x,state=%d)\n", (int) tty, state);
  2047. #endif
  2048. if (tty == (struct tty_struct *) NULL)
  2049. return;
  2050. portp = tty->driver_data;
  2051. if (portp == (stliport_t *) NULL)
  2052. return;
  2053. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  2054. return;
  2055. brdp = stli_brds[portp->brdnr];
  2056. if (brdp == (stlibrd_t *) NULL)
  2057. return;
  2058. /*
  2059. * Due to a bug in the tty send_break() code we need to preserve
  2060. * the current process state and timeout...
  2061. savetime = current->timeout;
  2062. savestate = current->state;
  2063. */
  2064. arg = (state == -1) ? BREAKON : BREAKOFF;
  2065. stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
  2066. /*
  2067. *
  2068. current->timeout = savetime;
  2069. current->state = savestate;
  2070. */
  2071. }
  2072. /*****************************************************************************/
  2073. static void stli_waituntilsent(struct tty_struct *tty, int timeout)
  2074. {
  2075. stliport_t *portp;
  2076. unsigned long tend;
  2077. #ifdef DEBUG
  2078. printk(KERN_DEBUG "stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty, timeout);
  2079. #endif
  2080. if (tty == (struct tty_struct *) NULL)
  2081. return;
  2082. portp = tty->driver_data;
  2083. if (portp == (stliport_t *) NULL)
  2084. return;
  2085. if (timeout == 0)
  2086. timeout = HZ;
  2087. tend = jiffies + timeout;
  2088. while (test_bit(ST_TXBUSY, &portp->state)) {
  2089. if (signal_pending(current))
  2090. break;
  2091. msleep_interruptible(20);
  2092. if (time_after_eq(jiffies, tend))
  2093. break;
  2094. }
  2095. }
  2096. /*****************************************************************************/
  2097. static void stli_sendxchar(struct tty_struct *tty, char ch)
  2098. {
  2099. stlibrd_t *brdp;
  2100. stliport_t *portp;
  2101. asyctrl_t actrl;
  2102. #ifdef DEBUG
  2103. printk(KERN_DEBUG "stli_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
  2104. #endif
  2105. if (tty == (struct tty_struct *) NULL)
  2106. return;
  2107. portp = tty->driver_data;
  2108. if (portp == (stliport_t *) NULL)
  2109. return;
  2110. if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
  2111. return;
  2112. brdp = stli_brds[portp->brdnr];
  2113. if (brdp == (stlibrd_t *) NULL)
  2114. return;
  2115. memset(&actrl, 0, sizeof(asyctrl_t));
  2116. if (ch == STOP_CHAR(tty)) {
  2117. actrl.rxctrl = CT_STOPFLOW;
  2118. } else if (ch == START_CHAR(tty)) {
  2119. actrl.rxctrl = CT_STARTFLOW;
  2120. } else {
  2121. actrl.txctrl = CT_SENDCHR;
  2122. actrl.tximdch = ch;
  2123. }
  2124. stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
  2125. }
  2126. /*****************************************************************************/
  2127. #define MAXLINE 80
  2128. /*
  2129. * Format info for a specified port. The line is deliberately limited
  2130. * to 80 characters. (If it is too long it will be truncated, if too
  2131. * short then padded with spaces).
  2132. */
  2133. static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
  2134. {
  2135. char *sp, *uart;
  2136. int rc, cnt;
  2137. rc = stli_portcmdstats(portp);
  2138. uart = "UNKNOWN";
  2139. if (brdp->state & BST_STARTED) {
  2140. switch (stli_comstats.hwid) {
  2141. case 0: uart = "2681"; break;
  2142. case 1: uart = "SC26198"; break;
  2143. default: uart = "CD1400"; break;
  2144. }
  2145. }
  2146. sp = pos;
  2147. sp += sprintf(sp, "%d: uart:%s ", portnr, uart);
  2148. if ((brdp->state & BST_STARTED) && (rc >= 0)) {
  2149. sp += sprintf(sp, "tx:%d rx:%d", (int) stli_comstats.txtotal,
  2150. (int) stli_comstats.rxtotal);
  2151. if (stli_comstats.rxframing)
  2152. sp += sprintf(sp, " fe:%d",
  2153. (int) stli_comstats.rxframing);
  2154. if (stli_comstats.rxparity)
  2155. sp += sprintf(sp, " pe:%d",
  2156. (int) stli_comstats.rxparity);
  2157. if (stli_comstats.rxbreaks)
  2158. sp += sprintf(sp, " brk:%d",
  2159. (int) stli_comstats.rxbreaks);
  2160. if (stli_comstats.rxoverrun)
  2161. sp += sprintf(sp, " oe:%d",
  2162. (int) stli_comstats.rxoverrun);
  2163. cnt = sprintf(sp, "%s%s%s%s%s ",
  2164. (stli_comstats.signals & TIOCM_RTS) ? "|RTS" : "",
  2165. (stli_comstats.signals & TIOCM_CTS) ? "|CTS" : "",
  2166. (stli_comstats.signals & TIOCM_DTR) ? "|DTR" : "",
  2167. (stli_comstats.signals & TIOCM_CD) ? "|DCD" : "",
  2168. (stli_comstats.signals & TIOCM_DSR) ? "|DSR" : "");
  2169. *sp = ' ';
  2170. sp += cnt;
  2171. }
  2172. for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
  2173. *sp++ = ' ';
  2174. if (cnt >= MAXLINE)
  2175. pos[(MAXLINE - 2)] = '+';
  2176. pos[(MAXLINE - 1)] = '\n';
  2177. return(MAXLINE);
  2178. }
  2179. /*****************************************************************************/
  2180. /*
  2181. * Port info, read from the /proc file system.
  2182. */
  2183. static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
  2184. {
  2185. stlibrd_t *brdp;
  2186. stliport_t *portp;
  2187. int brdnr, portnr, totalport;
  2188. int curoff, maxoff;
  2189. char *pos;
  2190. #ifdef DEBUG
  2191. printk(KERN_DEBUG "stli_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
  2192. "data=%x\n", (int) page, (int) start, (int) off, count,
  2193. (int) eof, (int) data);
  2194. #endif
  2195. pos = page;
  2196. totalport = 0;
  2197. curoff = 0;
  2198. if (off == 0) {
  2199. pos += sprintf(pos, "%s: version %s", stli_drvtitle,
  2200. stli_drvversion);
  2201. while (pos < (page + MAXLINE - 1))
  2202. *pos++ = ' ';
  2203. *pos++ = '\n';
  2204. }
  2205. curoff = MAXLINE;
  2206. /*
  2207. * We scan through for each board, panel and port. The offset is
  2208. * calculated on the fly, and irrelevant ports are skipped.
  2209. */
  2210. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  2211. brdp = stli_brds[brdnr];
  2212. if (brdp == (stlibrd_t *) NULL)
  2213. continue;
  2214. if (brdp->state == 0)
  2215. continue;
  2216. maxoff = curoff + (brdp->nrports * MAXLINE);
  2217. if (off >= maxoff) {
  2218. curoff = maxoff;
  2219. continue;
  2220. }
  2221. totalport = brdnr * STL_MAXPORTS;
  2222. for (portnr = 0; (portnr < brdp->nrports); portnr++,
  2223. totalport++) {
  2224. portp = brdp->ports[portnr];
  2225. if (portp == (stliport_t *) NULL)
  2226. continue;
  2227. if (off >= (curoff += MAXLINE))
  2228. continue;
  2229. if ((pos - page + MAXLINE) > count)
  2230. goto stli_readdone;
  2231. pos += stli_portinfo(brdp, portp, totalport, pos);
  2232. }
  2233. }
  2234. *eof = 1;
  2235. stli_readdone:
  2236. *start = page;
  2237. return(pos - page);
  2238. }
  2239. /*****************************************************************************/
  2240. /*
  2241. * Generic send command routine. This will send a message to the slave,
  2242. * of the specified type with the specified argument. Must be very
  2243. * careful of data that will be copied out from shared memory -
  2244. * containing command results. The command completion is all done from
  2245. * a poll routine that does not have user context. Therefore you cannot
  2246. * copy back directly into user space, or to the kernel stack of a
  2247. * process. This routine does not sleep, so can be called from anywhere.
  2248. */
  2249. static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
  2250. {
  2251. volatile cdkhdr_t *hdrp;
  2252. volatile cdkctrl_t *cp;
  2253. volatile unsigned char *bits;
  2254. unsigned long flags;
  2255. #ifdef DEBUG
  2256. printk(KERN_DEBUG "stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
  2257. "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
  2258. (int) arg, size, copyback);
  2259. #endif
  2260. save_flags(flags);
  2261. cli();
  2262. if (test_bit(ST_CMDING, &portp->state)) {
  2263. printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
  2264. (int) cmd);
  2265. restore_flags(flags);
  2266. return;
  2267. }
  2268. EBRDENABLE(brdp);
  2269. cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
  2270. if (size > 0) {
  2271. memcpy((void *) &(cp->args[0]), arg, size);
  2272. if (copyback) {
  2273. portp->argp = arg;
  2274. portp->argsize = size;
  2275. }
  2276. }
  2277. cp->status = 0;
  2278. cp->cmd = cmd;
  2279. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2280. bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset +
  2281. portp->portidx;
  2282. *bits |= portp->portbit;
  2283. set_bit(ST_CMDING, &portp->state);
  2284. EBRDDISABLE(brdp);
  2285. restore_flags(flags);
  2286. }
  2287. /*****************************************************************************/
  2288. /*
  2289. * Read data from shared memory. This assumes that the shared memory
  2290. * is enabled and that interrupts are off. Basically we just empty out
  2291. * the shared memory buffer into the tty buffer. Must be careful to
  2292. * handle the case where we fill up the tty buffer, but still have
  2293. * more chars to unload.
  2294. */
  2295. static void stli_read(stlibrd_t *brdp, stliport_t *portp)
  2296. {
  2297. volatile cdkasyrq_t *rp;
  2298. volatile char *shbuf;
  2299. struct tty_struct *tty;
  2300. unsigned int head, tail, size;
  2301. unsigned int len, stlen;
  2302. #ifdef DEBUG
  2303. printk(KERN_DEBUG "stli_read(brdp=%x,portp=%d)\n",
  2304. (int) brdp, (int) portp);
  2305. #endif
  2306. if (test_bit(ST_RXSTOP, &portp->state))
  2307. return;
  2308. tty = portp->tty;
  2309. if (tty == (struct tty_struct *) NULL)
  2310. return;
  2311. rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  2312. head = (unsigned int) rp->head;
  2313. if (head != ((unsigned int) rp->head))
  2314. head = (unsigned int) rp->head;
  2315. tail = (unsigned int) rp->tail;
  2316. size = portp->rxsize;
  2317. if (head >= tail) {
  2318. len = head - tail;
  2319. stlen = len;
  2320. } else {
  2321. len = size - (tail - head);
  2322. stlen = size - tail;
  2323. }
  2324. len = MIN(len, (TTY_FLIPBUF_SIZE - tty->flip.count));
  2325. shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset);
  2326. while (len > 0) {
  2327. stlen = MIN(len, stlen);
  2328. memcpy(tty->flip.char_buf_ptr, (char *) (shbuf + tail), stlen);
  2329. memset(tty->flip.flag_buf_ptr, 0, stlen);
  2330. tty->flip.char_buf_ptr += stlen;
  2331. tty->flip.flag_buf_ptr += stlen;
  2332. tty->flip.count += stlen;
  2333. len -= stlen;
  2334. tail += stlen;
  2335. if (tail >= size) {
  2336. tail = 0;
  2337. stlen = head;
  2338. }
  2339. }
  2340. rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
  2341. rp->tail = tail;
  2342. if (head != tail)
  2343. set_bit(ST_RXING, &portp->state);
  2344. tty_schedule_flip(tty);
  2345. }
  2346. /*****************************************************************************/
  2347. /*
  2348. * Set up and carry out any delayed commands. There is only a small set
  2349. * of slave commands that can be done "off-level". So it is not too
  2350. * difficult to deal with them here.
  2351. */
  2352. static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
  2353. {
  2354. int cmd;
  2355. if (test_bit(ST_DOSIGS, &portp->state)) {
  2356. if (test_bit(ST_DOFLUSHTX, &portp->state) &&
  2357. test_bit(ST_DOFLUSHRX, &portp->state))
  2358. cmd = A_SETSIGNALSF;
  2359. else if (test_bit(ST_DOFLUSHTX, &portp->state))
  2360. cmd = A_SETSIGNALSFTX;
  2361. else if (test_bit(ST_DOFLUSHRX, &portp->state))
  2362. cmd = A_SETSIGNALSFRX;
  2363. else
  2364. cmd = A_SETSIGNALS;
  2365. clear_bit(ST_DOFLUSHTX, &portp->state);
  2366. clear_bit(ST_DOFLUSHRX, &portp->state);
  2367. clear_bit(ST_DOSIGS, &portp->state);
  2368. memcpy((void *) &(cp->args[0]), (void *) &portp->asig,
  2369. sizeof(asysigs_t));
  2370. cp->status = 0;
  2371. cp->cmd = cmd;
  2372. set_bit(ST_CMDING, &portp->state);
  2373. } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
  2374. test_bit(ST_DOFLUSHRX, &portp->state)) {
  2375. cmd = ((test_bit(ST_DOFLUSHTX, &portp->state)) ? FLUSHTX : 0);
  2376. cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
  2377. clear_bit(ST_DOFLUSHTX, &portp->state);
  2378. clear_bit(ST_DOFLUSHRX, &portp->state);
  2379. memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int));
  2380. cp->status = 0;
  2381. cp->cmd = A_FLUSH;
  2382. set_bit(ST_CMDING, &portp->state);
  2383. }
  2384. }
  2385. /*****************************************************************************/
  2386. /*
  2387. * Host command service checking. This handles commands or messages
  2388. * coming from the slave to the host. Must have board shared memory
  2389. * enabled and interrupts off when called. Notice that by servicing the
  2390. * read data last we don't need to change the shared memory pointer
  2391. * during processing (which is a slow IO operation).
  2392. * Return value indicates if this port is still awaiting actions from
  2393. * the slave (like open, command, or even TX data being sent). If 0
  2394. * then port is still busy, otherwise no longer busy.
  2395. */
  2396. static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
  2397. {
  2398. volatile cdkasy_t *ap;
  2399. volatile cdkctrl_t *cp;
  2400. struct tty_struct *tty;
  2401. asynotify_t nt;
  2402. unsigned long oldsigs;
  2403. int rc, donerx;
  2404. #ifdef DEBUG
  2405. printk(KERN_DEBUG "stli_hostcmd(brdp=%x,channr=%d)\n",
  2406. (int) brdp, channr);
  2407. #endif
  2408. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  2409. cp = &ap->ctrl;
  2410. /*
  2411. * Check if we are waiting for an open completion message.
  2412. */
  2413. if (test_bit(ST_OPENING, &portp->state)) {
  2414. rc = (int) cp->openarg;
  2415. if ((cp->open == 0) && (rc != 0)) {
  2416. if (rc > 0)
  2417. rc--;
  2418. cp->openarg = 0;
  2419. portp->rc = rc;
  2420. clear_bit(ST_OPENING, &portp->state);
  2421. wake_up_interruptible(&portp->raw_wait);
  2422. }
  2423. }
  2424. /*
  2425. * Check if we are waiting for a close completion message.
  2426. */
  2427. if (test_bit(ST_CLOSING, &portp->state)) {
  2428. rc = (int) cp->closearg;
  2429. if ((cp->close == 0) && (rc != 0)) {
  2430. if (rc > 0)
  2431. rc--;
  2432. cp->closearg = 0;
  2433. portp->rc = rc;
  2434. clear_bit(ST_CLOSING, &portp->state);
  2435. wake_up_interruptible(&portp->raw_wait);
  2436. }
  2437. }
  2438. /*
  2439. * Check if we are waiting for a command completion message. We may
  2440. * need to copy out the command results associated with this command.
  2441. */
  2442. if (test_bit(ST_CMDING, &portp->state)) {
  2443. rc = cp->status;
  2444. if ((cp->cmd == 0) && (rc != 0)) {
  2445. if (rc > 0)
  2446. rc--;
  2447. if (portp->argp != (void *) NULL) {
  2448. memcpy(portp->argp, (void *) &(cp->args[0]),
  2449. portp->argsize);
  2450. portp->argp = (void *) NULL;
  2451. }
  2452. cp->status = 0;
  2453. portp->rc = rc;
  2454. clear_bit(ST_CMDING, &portp->state);
  2455. stli_dodelaycmd(portp, cp);
  2456. wake_up_interruptible(&portp->raw_wait);
  2457. }
  2458. }
  2459. /*
  2460. * Check for any notification messages ready. This includes lots of
  2461. * different types of events - RX chars ready, RX break received,
  2462. * TX data low or empty in the slave, modem signals changed state.
  2463. */
  2464. donerx = 0;
  2465. if (ap->notify) {
  2466. nt = ap->changed;
  2467. ap->notify = 0;
  2468. tty = portp->tty;
  2469. if (nt.signal & SG_DCD) {
  2470. oldsigs = portp->sigs;
  2471. portp->sigs = stli_mktiocm(nt.sigvalue);
  2472. clear_bit(ST_GETSIGS, &portp->state);
  2473. if ((portp->sigs & TIOCM_CD) &&
  2474. ((oldsigs & TIOCM_CD) == 0))
  2475. wake_up_interruptible(&portp->open_wait);
  2476. if ((oldsigs & TIOCM_CD) &&
  2477. ((portp->sigs & TIOCM_CD) == 0)) {
  2478. if (portp->flags & ASYNC_CHECK_CD) {
  2479. if (tty)
  2480. schedule_work(&portp->tqhangup);
  2481. }
  2482. }
  2483. }
  2484. if (nt.data & DT_TXEMPTY)
  2485. clear_bit(ST_TXBUSY, &portp->state);
  2486. if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
  2487. if (tty != (struct tty_struct *) NULL) {
  2488. if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
  2489. tty->ldisc.write_wakeup) {
  2490. (tty->ldisc.write_wakeup)(tty);
  2491. EBRDENABLE(brdp);
  2492. }
  2493. wake_up_interruptible(&tty->write_wait);
  2494. }
  2495. }
  2496. if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
  2497. if (tty != (struct tty_struct *) NULL) {
  2498. if (tty->flip.count < TTY_FLIPBUF_SIZE) {
  2499. tty->flip.count++;
  2500. *tty->flip.flag_buf_ptr++ = TTY_BREAK;
  2501. *tty->flip.char_buf_ptr++ = 0;
  2502. if (portp->flags & ASYNC_SAK) {
  2503. do_SAK(tty);
  2504. EBRDENABLE(brdp);
  2505. }
  2506. tty_schedule_flip(tty);
  2507. }
  2508. }
  2509. }
  2510. if (nt.data & DT_RXBUSY) {
  2511. donerx++;
  2512. stli_read(brdp, portp);
  2513. }
  2514. }
  2515. /*
  2516. * It might seem odd that we are checking for more RX chars here.
  2517. * But, we need to handle the case where the tty buffer was previously
  2518. * filled, but we had more characters to pass up. The slave will not
  2519. * send any more RX notify messages until the RX buffer has been emptied.
  2520. * But it will leave the service bits on (since the buffer is not empty).
  2521. * So from here we can try to process more RX chars.
  2522. */
  2523. if ((!donerx) && test_bit(ST_RXING, &portp->state)) {
  2524. clear_bit(ST_RXING, &portp->state);
  2525. stli_read(brdp, portp);
  2526. }
  2527. return((test_bit(ST_OPENING, &portp->state) ||
  2528. test_bit(ST_CLOSING, &portp->state) ||
  2529. test_bit(ST_CMDING, &portp->state) ||
  2530. test_bit(ST_TXBUSY, &portp->state) ||
  2531. test_bit(ST_RXING, &portp->state)) ? 0 : 1);
  2532. }
  2533. /*****************************************************************************/
  2534. /*
  2535. * Service all ports on a particular board. Assumes that the boards
  2536. * shared memory is enabled, and that the page pointer is pointed
  2537. * at the cdk header structure.
  2538. */
  2539. static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
  2540. {
  2541. stliport_t *portp;
  2542. unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
  2543. unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
  2544. unsigned char *slavep;
  2545. int bitpos, bitat, bitsize;
  2546. int channr, nrdevs, slavebitchange;
  2547. bitsize = brdp->bitsize;
  2548. nrdevs = brdp->nrdevs;
  2549. /*
  2550. * Check if slave wants any service. Basically we try to do as
  2551. * little work as possible here. There are 2 levels of service
  2552. * bits. So if there is nothing to do we bail early. We check
  2553. * 8 service bits at a time in the inner loop, so we can bypass
  2554. * the lot if none of them want service.
  2555. */
  2556. memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset),
  2557. bitsize);
  2558. memset(&slavebits[0], 0, bitsize);
  2559. slavebitchange = 0;
  2560. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  2561. if (hostbits[bitpos] == 0)
  2562. continue;
  2563. channr = bitpos * 8;
  2564. for (bitat = 0x1; (channr < nrdevs); channr++, bitat <<= 1) {
  2565. if (hostbits[bitpos] & bitat) {
  2566. portp = brdp->ports[(channr - 1)];
  2567. if (stli_hostcmd(brdp, portp)) {
  2568. slavebitchange++;
  2569. slavebits[bitpos] |= bitat;
  2570. }
  2571. }
  2572. }
  2573. }
  2574. /*
  2575. * If any of the ports are no longer busy then update them in the
  2576. * slave request bits. We need to do this after, since a host port
  2577. * service may initiate more slave requests.
  2578. */
  2579. if (slavebitchange) {
  2580. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2581. slavep = ((unsigned char *) hdrp) + brdp->slaveoffset;
  2582. for (bitpos = 0; (bitpos < bitsize); bitpos++) {
  2583. if (slavebits[bitpos])
  2584. slavep[bitpos] &= ~slavebits[bitpos];
  2585. }
  2586. }
  2587. }
  2588. /*****************************************************************************/
  2589. /*
  2590. * Driver poll routine. This routine polls the boards in use and passes
  2591. * messages back up to host when necessary. This is actually very
  2592. * CPU efficient, since we will always have the kernel poll clock, it
  2593. * adds only a few cycles when idle (since board service can be
  2594. * determined very easily), but when loaded generates no interrupts
  2595. * (with their expensive associated context change).
  2596. */
  2597. static void stli_poll(unsigned long arg)
  2598. {
  2599. volatile cdkhdr_t *hdrp;
  2600. stlibrd_t *brdp;
  2601. int brdnr;
  2602. stli_timerlist.expires = STLI_TIMEOUT;
  2603. add_timer(&stli_timerlist);
  2604. /*
  2605. * Check each board and do any servicing required.
  2606. */
  2607. for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
  2608. brdp = stli_brds[brdnr];
  2609. if (brdp == (stlibrd_t *) NULL)
  2610. continue;
  2611. if ((brdp->state & BST_STARTED) == 0)
  2612. continue;
  2613. EBRDENABLE(brdp);
  2614. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  2615. if (hdrp->hostreq)
  2616. stli_brdpoll(brdp, hdrp);
  2617. EBRDDISABLE(brdp);
  2618. }
  2619. }
  2620. /*****************************************************************************/
  2621. /*
  2622. * Translate the termios settings into the port setting structure of
  2623. * the slave.
  2624. */
  2625. static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
  2626. {
  2627. #ifdef DEBUG
  2628. printk(KERN_DEBUG "stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
  2629. (int) portp, (int) pp, (int) tiosp);
  2630. #endif
  2631. memset(pp, 0, sizeof(asyport_t));
  2632. /*
  2633. * Start of by setting the baud, char size, parity and stop bit info.
  2634. */
  2635. pp->baudout = tiosp->c_cflag & CBAUD;
  2636. if (pp->baudout & CBAUDEX) {
  2637. pp->baudout &= ~CBAUDEX;
  2638. if ((pp->baudout < 1) || (pp->baudout > 4))
  2639. tiosp->c_cflag &= ~CBAUDEX;
  2640. else
  2641. pp->baudout += 15;
  2642. }
  2643. pp->baudout = stli_baudrates[pp->baudout];
  2644. if ((tiosp->c_cflag & CBAUD) == B38400) {
  2645. if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2646. pp->baudout = 57600;
  2647. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2648. pp->baudout = 115200;
  2649. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2650. pp->baudout = 230400;
  2651. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2652. pp->baudout = 460800;
  2653. else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
  2654. pp->baudout = (portp->baud_base / portp->custom_divisor);
  2655. }
  2656. if (pp->baudout > STL_MAXBAUD)
  2657. pp->baudout = STL_MAXBAUD;
  2658. pp->baudin = pp->baudout;
  2659. switch (tiosp->c_cflag & CSIZE) {
  2660. case CS5:
  2661. pp->csize = 5;
  2662. break;
  2663. case CS6:
  2664. pp->csize = 6;
  2665. break;
  2666. case CS7:
  2667. pp->csize = 7;
  2668. break;
  2669. default:
  2670. pp->csize = 8;
  2671. break;
  2672. }
  2673. if (tiosp->c_cflag & CSTOPB)
  2674. pp->stopbs = PT_STOP2;
  2675. else
  2676. pp->stopbs = PT_STOP1;
  2677. if (tiosp->c_cflag & PARENB) {
  2678. if (tiosp->c_cflag & PARODD)
  2679. pp->parity = PT_ODDPARITY;
  2680. else
  2681. pp->parity = PT_EVENPARITY;
  2682. } else {
  2683. pp->parity = PT_NOPARITY;
  2684. }
  2685. /*
  2686. * Set up any flow control options enabled.
  2687. */
  2688. if (tiosp->c_iflag & IXON) {
  2689. pp->flow |= F_IXON;
  2690. if (tiosp->c_iflag & IXANY)
  2691. pp->flow |= F_IXANY;
  2692. }
  2693. if (tiosp->c_cflag & CRTSCTS)
  2694. pp->flow |= (F_RTSFLOW | F_CTSFLOW);
  2695. pp->startin = tiosp->c_cc[VSTART];
  2696. pp->stopin = tiosp->c_cc[VSTOP];
  2697. pp->startout = tiosp->c_cc[VSTART];
  2698. pp->stopout = tiosp->c_cc[VSTOP];
  2699. /*
  2700. * Set up the RX char marking mask with those RX error types we must
  2701. * catch. We can get the slave to help us out a little here, it will
  2702. * ignore parity errors and breaks for us, and mark parity errors in
  2703. * the data stream.
  2704. */
  2705. if (tiosp->c_iflag & IGNPAR)
  2706. pp->iflag |= FI_IGNRXERRS;
  2707. if (tiosp->c_iflag & IGNBRK)
  2708. pp->iflag |= FI_IGNBREAK;
  2709. portp->rxmarkmsk = 0;
  2710. if (tiosp->c_iflag & (INPCK | PARMRK))
  2711. pp->iflag |= FI_1MARKRXERRS;
  2712. if (tiosp->c_iflag & BRKINT)
  2713. portp->rxmarkmsk |= BRKINT;
  2714. /*
  2715. * Set up clocal processing as required.
  2716. */
  2717. if (tiosp->c_cflag & CLOCAL)
  2718. portp->flags &= ~ASYNC_CHECK_CD;
  2719. else
  2720. portp->flags |= ASYNC_CHECK_CD;
  2721. /*
  2722. * Transfer any persistent flags into the asyport structure.
  2723. */
  2724. pp->pflag = (portp->pflag & 0xffff);
  2725. pp->vmin = (portp->pflag & P_RXIMIN) ? 1 : 0;
  2726. pp->vtime = (portp->pflag & P_RXITIME) ? 1 : 0;
  2727. pp->cc[1] = (portp->pflag & P_RXTHOLD) ? 1 : 0;
  2728. }
  2729. /*****************************************************************************/
  2730. /*
  2731. * Construct a slave signals structure for setting the DTR and RTS
  2732. * signals as specified.
  2733. */
  2734. static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
  2735. {
  2736. #ifdef DEBUG
  2737. printk(KERN_DEBUG "stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n",
  2738. (int) sp, dtr, rts);
  2739. #endif
  2740. memset(sp, 0, sizeof(asysigs_t));
  2741. if (dtr >= 0) {
  2742. sp->signal |= SG_DTR;
  2743. sp->sigvalue |= ((dtr > 0) ? SG_DTR : 0);
  2744. }
  2745. if (rts >= 0) {
  2746. sp->signal |= SG_RTS;
  2747. sp->sigvalue |= ((rts > 0) ? SG_RTS : 0);
  2748. }
  2749. }
  2750. /*****************************************************************************/
  2751. /*
  2752. * Convert the signals returned from the slave into a local TIOCM type
  2753. * signals value. We keep them locally in TIOCM format.
  2754. */
  2755. static long stli_mktiocm(unsigned long sigvalue)
  2756. {
  2757. long tiocm;
  2758. #ifdef DEBUG
  2759. printk(KERN_DEBUG "stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
  2760. #endif
  2761. tiocm = 0;
  2762. tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
  2763. tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
  2764. tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
  2765. tiocm |= ((sigvalue & SG_DSR) ? TIOCM_DSR : 0);
  2766. tiocm |= ((sigvalue & SG_DTR) ? TIOCM_DTR : 0);
  2767. tiocm |= ((sigvalue & SG_RTS) ? TIOCM_RTS : 0);
  2768. return(tiocm);
  2769. }
  2770. /*****************************************************************************/
  2771. /*
  2772. * All panels and ports actually attached have been worked out. All
  2773. * we need to do here is set up the appropriate per port data structures.
  2774. */
  2775. static int stli_initports(stlibrd_t *brdp)
  2776. {
  2777. stliport_t *portp;
  2778. int i, panelnr, panelport;
  2779. #ifdef DEBUG
  2780. printk(KERN_DEBUG "stli_initports(brdp=%x)\n", (int) brdp);
  2781. #endif
  2782. for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
  2783. portp = (stliport_t *) stli_memalloc(sizeof(stliport_t));
  2784. if (portp == (stliport_t *) NULL) {
  2785. printk("STALLION: failed to allocate port structure\n");
  2786. continue;
  2787. }
  2788. memset(portp, 0, sizeof(stliport_t));
  2789. portp->magic = STLI_PORTMAGIC;
  2790. portp->portnr = i;
  2791. portp->brdnr = brdp->brdnr;
  2792. portp->panelnr = panelnr;
  2793. portp->baud_base = STL_BAUDBASE;
  2794. portp->close_delay = STL_CLOSEDELAY;
  2795. portp->closing_wait = 30 * HZ;
  2796. INIT_WORK(&portp->tqhangup, stli_dohangup, portp);
  2797. init_waitqueue_head(&portp->open_wait);
  2798. init_waitqueue_head(&portp->close_wait);
  2799. init_waitqueue_head(&portp->raw_wait);
  2800. panelport++;
  2801. if (panelport >= brdp->panels[panelnr]) {
  2802. panelport = 0;
  2803. panelnr++;
  2804. }
  2805. brdp->ports[i] = portp;
  2806. }
  2807. return(0);
  2808. }
  2809. /*****************************************************************************/
  2810. /*
  2811. * All the following routines are board specific hardware operations.
  2812. */
  2813. static void stli_ecpinit(stlibrd_t *brdp)
  2814. {
  2815. unsigned long memconf;
  2816. #ifdef DEBUG
  2817. printk(KERN_DEBUG "stli_ecpinit(brdp=%d)\n", (int) brdp);
  2818. #endif
  2819. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2820. udelay(10);
  2821. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2822. udelay(100);
  2823. memconf = (brdp->memaddr & ECP_ATADDRMASK) >> ECP_ATADDRSHFT;
  2824. outb(memconf, (brdp->iobase + ECP_ATMEMAR));
  2825. }
  2826. /*****************************************************************************/
  2827. static void stli_ecpenable(stlibrd_t *brdp)
  2828. {
  2829. #ifdef DEBUG
  2830. printk(KERN_DEBUG "stli_ecpenable(brdp=%x)\n", (int) brdp);
  2831. #endif
  2832. outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
  2833. }
  2834. /*****************************************************************************/
  2835. static void stli_ecpdisable(stlibrd_t *brdp)
  2836. {
  2837. #ifdef DEBUG
  2838. printk(KERN_DEBUG "stli_ecpdisable(brdp=%x)\n", (int) brdp);
  2839. #endif
  2840. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2841. }
  2842. /*****************************************************************************/
  2843. static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2844. {
  2845. void *ptr;
  2846. unsigned char val;
  2847. #ifdef DEBUG
  2848. printk(KERN_DEBUG "stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
  2849. (int) offset);
  2850. #endif
  2851. if (offset > brdp->memsize) {
  2852. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2853. "range at line=%d(%d), brd=%d\n",
  2854. (int) offset, line, __LINE__, brdp->brdnr);
  2855. ptr = NULL;
  2856. val = 0;
  2857. } else {
  2858. ptr = brdp->membase + (offset % ECP_ATPAGESIZE);
  2859. val = (unsigned char) (offset / ECP_ATPAGESIZE);
  2860. }
  2861. outb(val, (brdp->iobase + ECP_ATMEMPR));
  2862. return(ptr);
  2863. }
  2864. /*****************************************************************************/
  2865. static void stli_ecpreset(stlibrd_t *brdp)
  2866. {
  2867. #ifdef DEBUG
  2868. printk(KERN_DEBUG "stli_ecpreset(brdp=%x)\n", (int) brdp);
  2869. #endif
  2870. outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
  2871. udelay(10);
  2872. outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
  2873. udelay(500);
  2874. }
  2875. /*****************************************************************************/
  2876. static void stli_ecpintr(stlibrd_t *brdp)
  2877. {
  2878. #ifdef DEBUG
  2879. printk(KERN_DEBUG "stli_ecpintr(brdp=%x)\n", (int) brdp);
  2880. #endif
  2881. outb(0x1, brdp->iobase);
  2882. }
  2883. /*****************************************************************************/
  2884. /*
  2885. * The following set of functions act on ECP EISA boards.
  2886. */
  2887. static void stli_ecpeiinit(stlibrd_t *brdp)
  2888. {
  2889. unsigned long memconf;
  2890. #ifdef DEBUG
  2891. printk(KERN_DEBUG "stli_ecpeiinit(brdp=%x)\n", (int) brdp);
  2892. #endif
  2893. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  2894. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2895. udelay(10);
  2896. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2897. udelay(500);
  2898. memconf = (brdp->memaddr & ECP_EIADDRMASKL) >> ECP_EIADDRSHFTL;
  2899. outb(memconf, (brdp->iobase + ECP_EIMEMARL));
  2900. memconf = (brdp->memaddr & ECP_EIADDRMASKH) >> ECP_EIADDRSHFTH;
  2901. outb(memconf, (brdp->iobase + ECP_EIMEMARH));
  2902. }
  2903. /*****************************************************************************/
  2904. static void stli_ecpeienable(stlibrd_t *brdp)
  2905. {
  2906. outb(ECP_EIENABLE, (brdp->iobase + ECP_EICONFR));
  2907. }
  2908. /*****************************************************************************/
  2909. static void stli_ecpeidisable(stlibrd_t *brdp)
  2910. {
  2911. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2912. }
  2913. /*****************************************************************************/
  2914. static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2915. {
  2916. void *ptr;
  2917. unsigned char val;
  2918. #ifdef DEBUG
  2919. printk(KERN_DEBUG "stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
  2920. (int) brdp, (int) offset, line);
  2921. #endif
  2922. if (offset > brdp->memsize) {
  2923. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2924. "range at line=%d(%d), brd=%d\n",
  2925. (int) offset, line, __LINE__, brdp->brdnr);
  2926. ptr = NULL;
  2927. val = 0;
  2928. } else {
  2929. ptr = brdp->membase + (offset % ECP_EIPAGESIZE);
  2930. if (offset < ECP_EIPAGESIZE)
  2931. val = ECP_EIENABLE;
  2932. else
  2933. val = ECP_EIENABLE | 0x40;
  2934. }
  2935. outb(val, (brdp->iobase + ECP_EICONFR));
  2936. return(ptr);
  2937. }
  2938. /*****************************************************************************/
  2939. static void stli_ecpeireset(stlibrd_t *brdp)
  2940. {
  2941. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  2942. udelay(10);
  2943. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  2944. udelay(500);
  2945. }
  2946. /*****************************************************************************/
  2947. /*
  2948. * The following set of functions act on ECP MCA boards.
  2949. */
  2950. static void stli_ecpmcenable(stlibrd_t *brdp)
  2951. {
  2952. outb(ECP_MCENABLE, (brdp->iobase + ECP_MCCONFR));
  2953. }
  2954. /*****************************************************************************/
  2955. static void stli_ecpmcdisable(stlibrd_t *brdp)
  2956. {
  2957. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2958. }
  2959. /*****************************************************************************/
  2960. static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  2961. {
  2962. void *ptr;
  2963. unsigned char val;
  2964. if (offset > brdp->memsize) {
  2965. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  2966. "range at line=%d(%d), brd=%d\n",
  2967. (int) offset, line, __LINE__, brdp->brdnr);
  2968. ptr = NULL;
  2969. val = 0;
  2970. } else {
  2971. ptr = brdp->membase + (offset % ECP_MCPAGESIZE);
  2972. val = ((unsigned char) (offset / ECP_MCPAGESIZE)) | ECP_MCENABLE;
  2973. }
  2974. outb(val, (brdp->iobase + ECP_MCCONFR));
  2975. return(ptr);
  2976. }
  2977. /*****************************************************************************/
  2978. static void stli_ecpmcreset(stlibrd_t *brdp)
  2979. {
  2980. outb(ECP_MCSTOP, (brdp->iobase + ECP_MCCONFR));
  2981. udelay(10);
  2982. outb(ECP_MCDISABLE, (brdp->iobase + ECP_MCCONFR));
  2983. udelay(500);
  2984. }
  2985. /*****************************************************************************/
  2986. /*
  2987. * The following set of functions act on ECP PCI boards.
  2988. */
  2989. static void stli_ecppciinit(stlibrd_t *brdp)
  2990. {
  2991. #ifdef DEBUG
  2992. printk(KERN_DEBUG "stli_ecppciinit(brdp=%x)\n", (int) brdp);
  2993. #endif
  2994. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  2995. udelay(10);
  2996. outb(0, (brdp->iobase + ECP_PCICONFR));
  2997. udelay(500);
  2998. }
  2999. /*****************************************************************************/
  3000. static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  3001. {
  3002. void *ptr;
  3003. unsigned char val;
  3004. #ifdef DEBUG
  3005. printk(KERN_DEBUG "stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
  3006. (int) brdp, (int) offset, line);
  3007. #endif
  3008. if (offset > brdp->memsize) {
  3009. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  3010. "range at line=%d(%d), board=%d\n",
  3011. (int) offset, line, __LINE__, brdp->brdnr);
  3012. ptr = NULL;
  3013. val = 0;
  3014. } else {
  3015. ptr = brdp->membase + (offset % ECP_PCIPAGESIZE);
  3016. val = (offset / ECP_PCIPAGESIZE) << 1;
  3017. }
  3018. outb(val, (brdp->iobase + ECP_PCICONFR));
  3019. return(ptr);
  3020. }
  3021. /*****************************************************************************/
  3022. static void stli_ecppcireset(stlibrd_t *brdp)
  3023. {
  3024. outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
  3025. udelay(10);
  3026. outb(0, (brdp->iobase + ECP_PCICONFR));
  3027. udelay(500);
  3028. }
  3029. /*****************************************************************************/
  3030. /*
  3031. * The following routines act on ONboards.
  3032. */
  3033. static void stli_onbinit(stlibrd_t *brdp)
  3034. {
  3035. unsigned long memconf;
  3036. #ifdef DEBUG
  3037. printk(KERN_DEBUG "stli_onbinit(brdp=%d)\n", (int) brdp);
  3038. #endif
  3039. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  3040. udelay(10);
  3041. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  3042. mdelay(1000);
  3043. memconf = (brdp->memaddr & ONB_ATADDRMASK) >> ONB_ATADDRSHFT;
  3044. outb(memconf, (brdp->iobase + ONB_ATMEMAR));
  3045. outb(0x1, brdp->iobase);
  3046. mdelay(1);
  3047. }
  3048. /*****************************************************************************/
  3049. static void stli_onbenable(stlibrd_t *brdp)
  3050. {
  3051. #ifdef DEBUG
  3052. printk(KERN_DEBUG "stli_onbenable(brdp=%x)\n", (int) brdp);
  3053. #endif
  3054. outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
  3055. }
  3056. /*****************************************************************************/
  3057. static void stli_onbdisable(stlibrd_t *brdp)
  3058. {
  3059. #ifdef DEBUG
  3060. printk(KERN_DEBUG "stli_onbdisable(brdp=%x)\n", (int) brdp);
  3061. #endif
  3062. outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
  3063. }
  3064. /*****************************************************************************/
  3065. static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  3066. {
  3067. void *ptr;
  3068. #ifdef DEBUG
  3069. printk(KERN_DEBUG "stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
  3070. (int) offset);
  3071. #endif
  3072. if (offset > brdp->memsize) {
  3073. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  3074. "range at line=%d(%d), brd=%d\n",
  3075. (int) offset, line, __LINE__, brdp->brdnr);
  3076. ptr = NULL;
  3077. } else {
  3078. ptr = brdp->membase + (offset % ONB_ATPAGESIZE);
  3079. }
  3080. return(ptr);
  3081. }
  3082. /*****************************************************************************/
  3083. static void stli_onbreset(stlibrd_t *brdp)
  3084. {
  3085. #ifdef DEBUG
  3086. printk(KERN_DEBUG "stli_onbreset(brdp=%x)\n", (int) brdp);
  3087. #endif
  3088. outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
  3089. udelay(10);
  3090. outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
  3091. mdelay(1000);
  3092. }
  3093. /*****************************************************************************/
  3094. /*
  3095. * The following routines act on ONboard EISA.
  3096. */
  3097. static void stli_onbeinit(stlibrd_t *brdp)
  3098. {
  3099. unsigned long memconf;
  3100. #ifdef DEBUG
  3101. printk(KERN_DEBUG "stli_onbeinit(brdp=%d)\n", (int) brdp);
  3102. #endif
  3103. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  3104. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  3105. udelay(10);
  3106. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  3107. mdelay(1000);
  3108. memconf = (brdp->memaddr & ONB_EIADDRMASKL) >> ONB_EIADDRSHFTL;
  3109. outb(memconf, (brdp->iobase + ONB_EIMEMARL));
  3110. memconf = (brdp->memaddr & ONB_EIADDRMASKH) >> ONB_EIADDRSHFTH;
  3111. outb(memconf, (brdp->iobase + ONB_EIMEMARH));
  3112. outb(0x1, brdp->iobase);
  3113. mdelay(1);
  3114. }
  3115. /*****************************************************************************/
  3116. static void stli_onbeenable(stlibrd_t *brdp)
  3117. {
  3118. #ifdef DEBUG
  3119. printk(KERN_DEBUG "stli_onbeenable(brdp=%x)\n", (int) brdp);
  3120. #endif
  3121. outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
  3122. }
  3123. /*****************************************************************************/
  3124. static void stli_onbedisable(stlibrd_t *brdp)
  3125. {
  3126. #ifdef DEBUG
  3127. printk(KERN_DEBUG "stli_onbedisable(brdp=%x)\n", (int) brdp);
  3128. #endif
  3129. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  3130. }
  3131. /*****************************************************************************/
  3132. static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  3133. {
  3134. void *ptr;
  3135. unsigned char val;
  3136. #ifdef DEBUG
  3137. printk(KERN_DEBUG "stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
  3138. (int) brdp, (int) offset, line);
  3139. #endif
  3140. if (offset > brdp->memsize) {
  3141. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  3142. "range at line=%d(%d), brd=%d\n",
  3143. (int) offset, line, __LINE__, brdp->brdnr);
  3144. ptr = NULL;
  3145. val = 0;
  3146. } else {
  3147. ptr = brdp->membase + (offset % ONB_EIPAGESIZE);
  3148. if (offset < ONB_EIPAGESIZE)
  3149. val = ONB_EIENABLE;
  3150. else
  3151. val = ONB_EIENABLE | 0x40;
  3152. }
  3153. outb(val, (brdp->iobase + ONB_EICONFR));
  3154. return(ptr);
  3155. }
  3156. /*****************************************************************************/
  3157. static void stli_onbereset(stlibrd_t *brdp)
  3158. {
  3159. #ifdef DEBUG
  3160. printk(KERN_ERR "stli_onbereset(brdp=%x)\n", (int) brdp);
  3161. #endif
  3162. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  3163. udelay(10);
  3164. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  3165. mdelay(1000);
  3166. }
  3167. /*****************************************************************************/
  3168. /*
  3169. * The following routines act on Brumby boards.
  3170. */
  3171. static void stli_bbyinit(stlibrd_t *brdp)
  3172. {
  3173. #ifdef DEBUG
  3174. printk(KERN_ERR "stli_bbyinit(brdp=%d)\n", (int) brdp);
  3175. #endif
  3176. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  3177. udelay(10);
  3178. outb(0, (brdp->iobase + BBY_ATCONFR));
  3179. mdelay(1000);
  3180. outb(0x1, brdp->iobase);
  3181. mdelay(1);
  3182. }
  3183. /*****************************************************************************/
  3184. static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  3185. {
  3186. void *ptr;
  3187. unsigned char val;
  3188. #ifdef DEBUG
  3189. printk(KERN_ERR "stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
  3190. (int) offset);
  3191. #endif
  3192. if (offset > brdp->memsize) {
  3193. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  3194. "range at line=%d(%d), brd=%d\n",
  3195. (int) offset, line, __LINE__, brdp->brdnr);
  3196. ptr = NULL;
  3197. val = 0;
  3198. } else {
  3199. ptr = brdp->membase + (offset % BBY_PAGESIZE);
  3200. val = (unsigned char) (offset / BBY_PAGESIZE);
  3201. }
  3202. outb(val, (brdp->iobase + BBY_ATCONFR));
  3203. return(ptr);
  3204. }
  3205. /*****************************************************************************/
  3206. static void stli_bbyreset(stlibrd_t *brdp)
  3207. {
  3208. #ifdef DEBUG
  3209. printk(KERN_DEBUG "stli_bbyreset(brdp=%x)\n", (int) brdp);
  3210. #endif
  3211. outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
  3212. udelay(10);
  3213. outb(0, (brdp->iobase + BBY_ATCONFR));
  3214. mdelay(1000);
  3215. }
  3216. /*****************************************************************************/
  3217. /*
  3218. * The following routines act on original old Stallion boards.
  3219. */
  3220. static void stli_stalinit(stlibrd_t *brdp)
  3221. {
  3222. #ifdef DEBUG
  3223. printk(KERN_DEBUG "stli_stalinit(brdp=%d)\n", (int) brdp);
  3224. #endif
  3225. outb(0x1, brdp->iobase);
  3226. mdelay(1000);
  3227. }
  3228. /*****************************************************************************/
  3229. static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
  3230. {
  3231. void *ptr;
  3232. #ifdef DEBUG
  3233. printk(KERN_DEBUG "stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
  3234. (int) offset);
  3235. #endif
  3236. if (offset > brdp->memsize) {
  3237. printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
  3238. "range at line=%d(%d), brd=%d\n",
  3239. (int) offset, line, __LINE__, brdp->brdnr);
  3240. ptr = NULL;
  3241. } else {
  3242. ptr = brdp->membase + (offset % STAL_PAGESIZE);
  3243. }
  3244. return(ptr);
  3245. }
  3246. /*****************************************************************************/
  3247. static void stli_stalreset(stlibrd_t *brdp)
  3248. {
  3249. volatile unsigned long *vecp;
  3250. #ifdef DEBUG
  3251. printk(KERN_DEBUG "stli_stalreset(brdp=%x)\n", (int) brdp);
  3252. #endif
  3253. vecp = (volatile unsigned long *) (brdp->membase + 0x30);
  3254. *vecp = 0xffff0000;
  3255. outb(0, brdp->iobase);
  3256. mdelay(1000);
  3257. }
  3258. /*****************************************************************************/
  3259. /*
  3260. * Try to find an ECP board and initialize it. This handles only ECP
  3261. * board types.
  3262. */
  3263. static int stli_initecp(stlibrd_t *brdp)
  3264. {
  3265. cdkecpsig_t sig;
  3266. cdkecpsig_t *sigsp;
  3267. unsigned int status, nxtid;
  3268. char *name;
  3269. int panelnr, nrports;
  3270. #ifdef DEBUG
  3271. printk(KERN_DEBUG "stli_initecp(brdp=%x)\n", (int) brdp);
  3272. #endif
  3273. if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
  3274. return -EIO;
  3275. if ((brdp->iobase == 0) || (brdp->memaddr == 0))
  3276. {
  3277. release_region(brdp->iobase, brdp->iosize);
  3278. return(-ENODEV);
  3279. }
  3280. brdp->iosize = ECP_IOSIZE;
  3281. /*
  3282. * Based on the specific board type setup the common vars to access
  3283. * and enable shared memory. Set all board specific information now
  3284. * as well.
  3285. */
  3286. switch (brdp->brdtype) {
  3287. case BRD_ECP:
  3288. brdp->membase = (void *) brdp->memaddr;
  3289. brdp->memsize = ECP_MEMSIZE;
  3290. brdp->pagesize = ECP_ATPAGESIZE;
  3291. brdp->init = stli_ecpinit;
  3292. brdp->enable = stli_ecpenable;
  3293. brdp->reenable = stli_ecpenable;
  3294. brdp->disable = stli_ecpdisable;
  3295. brdp->getmemptr = stli_ecpgetmemptr;
  3296. brdp->intr = stli_ecpintr;
  3297. brdp->reset = stli_ecpreset;
  3298. name = "serial(EC8/64)";
  3299. break;
  3300. case BRD_ECPE:
  3301. brdp->membase = (void *) brdp->memaddr;
  3302. brdp->memsize = ECP_MEMSIZE;
  3303. brdp->pagesize = ECP_EIPAGESIZE;
  3304. brdp->init = stli_ecpeiinit;
  3305. brdp->enable = stli_ecpeienable;
  3306. brdp->reenable = stli_ecpeienable;
  3307. brdp->disable = stli_ecpeidisable;
  3308. brdp->getmemptr = stli_ecpeigetmemptr;
  3309. brdp->intr = stli_ecpintr;
  3310. brdp->reset = stli_ecpeireset;
  3311. name = "serial(EC8/64-EI)";
  3312. break;
  3313. case BRD_ECPMC:
  3314. brdp->membase = (void *) brdp->memaddr;
  3315. brdp->memsize = ECP_MEMSIZE;
  3316. brdp->pagesize = ECP_MCPAGESIZE;
  3317. brdp->init = NULL;
  3318. brdp->enable = stli_ecpmcenable;
  3319. brdp->reenable = stli_ecpmcenable;
  3320. brdp->disable = stli_ecpmcdisable;
  3321. brdp->getmemptr = stli_ecpmcgetmemptr;
  3322. brdp->intr = stli_ecpintr;
  3323. brdp->reset = stli_ecpmcreset;
  3324. name = "serial(EC8/64-MCA)";
  3325. break;
  3326. case BRD_ECPPCI:
  3327. brdp->membase = (void *) brdp->memaddr;
  3328. brdp->memsize = ECP_PCIMEMSIZE;
  3329. brdp->pagesize = ECP_PCIPAGESIZE;
  3330. brdp->init = stli_ecppciinit;
  3331. brdp->enable = NULL;
  3332. brdp->reenable = NULL;
  3333. brdp->disable = NULL;
  3334. brdp->getmemptr = stli_ecppcigetmemptr;
  3335. brdp->intr = stli_ecpintr;
  3336. brdp->reset = stli_ecppcireset;
  3337. name = "serial(EC/RA-PCI)";
  3338. break;
  3339. default:
  3340. release_region(brdp->iobase, brdp->iosize);
  3341. return(-EINVAL);
  3342. }
  3343. /*
  3344. * The per-board operations structure is all set up, so now let's go
  3345. * and get the board operational. Firstly initialize board configuration
  3346. * registers. Set the memory mapping info so we can get at the boards
  3347. * shared memory.
  3348. */
  3349. EBRDINIT(brdp);
  3350. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  3351. if (brdp->membase == (void *) NULL)
  3352. {
  3353. release_region(brdp->iobase, brdp->iosize);
  3354. return(-ENOMEM);
  3355. }
  3356. /*
  3357. * Now that all specific code is set up, enable the shared memory and
  3358. * look for the a signature area that will tell us exactly what board
  3359. * this is, and what it is connected to it.
  3360. */
  3361. EBRDENABLE(brdp);
  3362. sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  3363. memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
  3364. EBRDDISABLE(brdp);
  3365. #if 0
  3366. printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
  3367. __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
  3368. (int) sig.panelid[1], (int) sig.panelid[2],
  3369. (int) sig.panelid[3], (int) sig.panelid[4],
  3370. (int) sig.panelid[5], (int) sig.panelid[6],
  3371. (int) sig.panelid[7]);
  3372. #endif
  3373. if (sig.magic != ECP_MAGIC)
  3374. {
  3375. release_region(brdp->iobase, brdp->iosize);
  3376. return(-ENODEV);
  3377. }
  3378. /*
  3379. * Scan through the signature looking at the panels connected to the
  3380. * board. Calculate the total number of ports as we go.
  3381. */
  3382. for (panelnr = 0, nxtid = 0; (panelnr < STL_MAXPANELS); panelnr++) {
  3383. status = sig.panelid[nxtid];
  3384. if ((status & ECH_PNLIDMASK) != nxtid)
  3385. break;
  3386. brdp->panelids[panelnr] = status;
  3387. nrports = (status & ECH_PNL16PORT) ? 16 : 8;
  3388. if ((nrports == 16) && ((status & ECH_PNLXPID) == 0))
  3389. nxtid++;
  3390. brdp->panels[panelnr] = nrports;
  3391. brdp->nrports += nrports;
  3392. nxtid++;
  3393. brdp->nrpanels++;
  3394. }
  3395. brdp->state |= BST_FOUND;
  3396. return(0);
  3397. }
  3398. /*****************************************************************************/
  3399. /*
  3400. * Try to find an ONboard, Brumby or Stallion board and initialize it.
  3401. * This handles only these board types.
  3402. */
  3403. static int stli_initonb(stlibrd_t *brdp)
  3404. {
  3405. cdkonbsig_t sig;
  3406. cdkonbsig_t *sigsp;
  3407. char *name;
  3408. int i;
  3409. #ifdef DEBUG
  3410. printk(KERN_DEBUG "stli_initonb(brdp=%x)\n", (int) brdp);
  3411. #endif
  3412. /*
  3413. * Do a basic sanity check on the IO and memory addresses.
  3414. */
  3415. if ((brdp->iobase == 0) || (brdp->memaddr == 0))
  3416. return(-ENODEV);
  3417. brdp->iosize = ONB_IOSIZE;
  3418. if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
  3419. return -EIO;
  3420. /*
  3421. * Based on the specific board type setup the common vars to access
  3422. * and enable shared memory. Set all board specific information now
  3423. * as well.
  3424. */
  3425. switch (brdp->brdtype) {
  3426. case BRD_ONBOARD:
  3427. case BRD_ONBOARD32:
  3428. case BRD_ONBOARD2:
  3429. case BRD_ONBOARD2_32:
  3430. case BRD_ONBOARDRS:
  3431. brdp->membase = (void *) brdp->memaddr;
  3432. brdp->memsize = ONB_MEMSIZE;
  3433. brdp->pagesize = ONB_ATPAGESIZE;
  3434. brdp->init = stli_onbinit;
  3435. brdp->enable = stli_onbenable;
  3436. brdp->reenable = stli_onbenable;
  3437. brdp->disable = stli_onbdisable;
  3438. brdp->getmemptr = stli_onbgetmemptr;
  3439. brdp->intr = stli_ecpintr;
  3440. brdp->reset = stli_onbreset;
  3441. if (brdp->memaddr > 0x100000)
  3442. brdp->enabval = ONB_MEMENABHI;
  3443. else
  3444. brdp->enabval = ONB_MEMENABLO;
  3445. name = "serial(ONBoard)";
  3446. break;
  3447. case BRD_ONBOARDE:
  3448. brdp->membase = (void *) brdp->memaddr;
  3449. brdp->memsize = ONB_EIMEMSIZE;
  3450. brdp->pagesize = ONB_EIPAGESIZE;
  3451. brdp->init = stli_onbeinit;
  3452. brdp->enable = stli_onbeenable;
  3453. brdp->reenable = stli_onbeenable;
  3454. brdp->disable = stli_onbedisable;
  3455. brdp->getmemptr = stli_onbegetmemptr;
  3456. brdp->intr = stli_ecpintr;
  3457. brdp->reset = stli_onbereset;
  3458. name = "serial(ONBoard/E)";
  3459. break;
  3460. case BRD_BRUMBY4:
  3461. case BRD_BRUMBY8:
  3462. case BRD_BRUMBY16:
  3463. brdp->membase = (void *) brdp->memaddr;
  3464. brdp->memsize = BBY_MEMSIZE;
  3465. brdp->pagesize = BBY_PAGESIZE;
  3466. brdp->init = stli_bbyinit;
  3467. brdp->enable = NULL;
  3468. brdp->reenable = NULL;
  3469. brdp->disable = NULL;
  3470. brdp->getmemptr = stli_bbygetmemptr;
  3471. brdp->intr = stli_ecpintr;
  3472. brdp->reset = stli_bbyreset;
  3473. name = "serial(Brumby)";
  3474. break;
  3475. case BRD_STALLION:
  3476. brdp->membase = (void *) brdp->memaddr;
  3477. brdp->memsize = STAL_MEMSIZE;
  3478. brdp->pagesize = STAL_PAGESIZE;
  3479. brdp->init = stli_stalinit;
  3480. brdp->enable = NULL;
  3481. brdp->reenable = NULL;
  3482. brdp->disable = NULL;
  3483. brdp->getmemptr = stli_stalgetmemptr;
  3484. brdp->intr = stli_ecpintr;
  3485. brdp->reset = stli_stalreset;
  3486. name = "serial(Stallion)";
  3487. break;
  3488. default:
  3489. release_region(brdp->iobase, brdp->iosize);
  3490. return(-EINVAL);
  3491. }
  3492. /*
  3493. * The per-board operations structure is all set up, so now let's go
  3494. * and get the board operational. Firstly initialize board configuration
  3495. * registers. Set the memory mapping info so we can get at the boards
  3496. * shared memory.
  3497. */
  3498. EBRDINIT(brdp);
  3499. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  3500. if (brdp->membase == (void *) NULL)
  3501. {
  3502. release_region(brdp->iobase, brdp->iosize);
  3503. return(-ENOMEM);
  3504. }
  3505. /*
  3506. * Now that all specific code is set up, enable the shared memory and
  3507. * look for the a signature area that will tell us exactly what board
  3508. * this is, and how many ports.
  3509. */
  3510. EBRDENABLE(brdp);
  3511. sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
  3512. memcpy(&sig, sigsp, sizeof(cdkonbsig_t));
  3513. EBRDDISABLE(brdp);
  3514. #if 0
  3515. printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n",
  3516. __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2,
  3517. sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2);
  3518. #endif
  3519. if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
  3520. (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
  3521. {
  3522. release_region(brdp->iobase, brdp->iosize);
  3523. return(-ENODEV);
  3524. }
  3525. /*
  3526. * Scan through the signature alive mask and calculate how many ports
  3527. * there are on this board.
  3528. */
  3529. brdp->nrpanels = 1;
  3530. if (sig.amask1) {
  3531. brdp->nrports = 32;
  3532. } else {
  3533. for (i = 0; (i < 16); i++) {
  3534. if (((sig.amask0 << i) & 0x8000) == 0)
  3535. break;
  3536. }
  3537. brdp->nrports = i;
  3538. }
  3539. brdp->panels[0] = brdp->nrports;
  3540. brdp->state |= BST_FOUND;
  3541. return(0);
  3542. }
  3543. /*****************************************************************************/
  3544. /*
  3545. * Start up a running board. This routine is only called after the
  3546. * code has been down loaded to the board and is operational. It will
  3547. * read in the memory map, and get the show on the road...
  3548. */
  3549. static int stli_startbrd(stlibrd_t *brdp)
  3550. {
  3551. volatile cdkhdr_t *hdrp;
  3552. volatile cdkmem_t *memp;
  3553. volatile cdkasy_t *ap;
  3554. unsigned long flags;
  3555. stliport_t *portp;
  3556. int portnr, nrdevs, i, rc;
  3557. #ifdef DEBUG
  3558. printk(KERN_DEBUG "stli_startbrd(brdp=%x)\n", (int) brdp);
  3559. #endif
  3560. rc = 0;
  3561. save_flags(flags);
  3562. cli();
  3563. EBRDENABLE(brdp);
  3564. hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
  3565. nrdevs = hdrp->nrdevs;
  3566. #if 0
  3567. printk("%s(%d): CDK version %d.%d.%d --> "
  3568. "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
  3569. __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification,
  3570. hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp,
  3571. (int) hdrp->slavep);
  3572. #endif
  3573. if (nrdevs < (brdp->nrports + 1)) {
  3574. printk(KERN_ERR "STALLION: slave failed to allocate memory for "
  3575. "all devices, devices=%d\n", nrdevs);
  3576. brdp->nrports = nrdevs - 1;
  3577. }
  3578. brdp->nrdevs = nrdevs;
  3579. brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
  3580. brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
  3581. brdp->bitsize = (nrdevs + 7) / 8;
  3582. memp = (volatile cdkmem_t *) hdrp->memp;
  3583. if (((unsigned long) memp) > brdp->memsize) {
  3584. printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
  3585. rc = -EIO;
  3586. goto stli_donestartup;
  3587. }
  3588. memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp);
  3589. if (memp->dtype != TYP_ASYNCTRL) {
  3590. printk(KERN_ERR "STALLION: no slave control device found\n");
  3591. goto stli_donestartup;
  3592. }
  3593. memp++;
  3594. /*
  3595. * Cycle through memory allocation of each port. We are guaranteed to
  3596. * have all ports inside the first page of slave window, so no need to
  3597. * change pages while reading memory map.
  3598. */
  3599. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
  3600. if (memp->dtype != TYP_ASYNC)
  3601. break;
  3602. portp = brdp->ports[portnr];
  3603. if (portp == (stliport_t *) NULL)
  3604. break;
  3605. portp->devnr = i;
  3606. portp->addr = memp->offset;
  3607. portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
  3608. portp->portidx = (unsigned char) (i / 8);
  3609. portp->portbit = (unsigned char) (0x1 << (i % 8));
  3610. }
  3611. hdrp->slavereq = 0xff;
  3612. /*
  3613. * For each port setup a local copy of the RX and TX buffer offsets
  3614. * and sizes. We do this separate from the above, because we need to
  3615. * move the shared memory page...
  3616. */
  3617. for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
  3618. portp = brdp->ports[portnr];
  3619. if (portp == (stliport_t *) NULL)
  3620. break;
  3621. if (portp->addr == 0)
  3622. break;
  3623. ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
  3624. if (ap != (volatile cdkasy_t *) NULL) {
  3625. portp->rxsize = ap->rxq.size;
  3626. portp->txsize = ap->txq.size;
  3627. portp->rxoffset = ap->rxq.offset;
  3628. portp->txoffset = ap->txq.offset;
  3629. }
  3630. }
  3631. stli_donestartup:
  3632. EBRDDISABLE(brdp);
  3633. restore_flags(flags);
  3634. if (rc == 0)
  3635. brdp->state |= BST_STARTED;
  3636. if (! stli_timeron) {
  3637. stli_timeron++;
  3638. stli_timerlist.expires = STLI_TIMEOUT;
  3639. add_timer(&stli_timerlist);
  3640. }
  3641. return(rc);
  3642. }
  3643. /*****************************************************************************/
  3644. /*
  3645. * Probe and initialize the specified board.
  3646. */
  3647. static int __init stli_brdinit(stlibrd_t *brdp)
  3648. {
  3649. #ifdef DEBUG
  3650. printk(KERN_DEBUG "stli_brdinit(brdp=%x)\n", (int) brdp);
  3651. #endif
  3652. stli_brds[brdp->brdnr] = brdp;
  3653. switch (brdp->brdtype) {
  3654. case BRD_ECP:
  3655. case BRD_ECPE:
  3656. case BRD_ECPMC:
  3657. case BRD_ECPPCI:
  3658. stli_initecp(brdp);
  3659. break;
  3660. case BRD_ONBOARD:
  3661. case BRD_ONBOARDE:
  3662. case BRD_ONBOARD2:
  3663. case BRD_ONBOARD32:
  3664. case BRD_ONBOARD2_32:
  3665. case BRD_ONBOARDRS:
  3666. case BRD_BRUMBY4:
  3667. case BRD_BRUMBY8:
  3668. case BRD_BRUMBY16:
  3669. case BRD_STALLION:
  3670. stli_initonb(brdp);
  3671. break;
  3672. case BRD_EASYIO:
  3673. case BRD_ECH:
  3674. case BRD_ECHMC:
  3675. case BRD_ECHPCI:
  3676. printk(KERN_ERR "STALLION: %s board type not supported in "
  3677. "this driver\n", stli_brdnames[brdp->brdtype]);
  3678. return(ENODEV);
  3679. default:
  3680. printk(KERN_ERR "STALLION: board=%d is unknown board "
  3681. "type=%d\n", brdp->brdnr, brdp->brdtype);
  3682. return(ENODEV);
  3683. }
  3684. if ((brdp->state & BST_FOUND) == 0) {
  3685. printk(KERN_ERR "STALLION: %s board not found, board=%d "
  3686. "io=%x mem=%x\n",
  3687. stli_brdnames[brdp->brdtype], brdp->brdnr,
  3688. brdp->iobase, (int) brdp->memaddr);
  3689. return(ENODEV);
  3690. }
  3691. stli_initports(brdp);
  3692. printk(KERN_INFO "STALLION: %s found, board=%d io=%x mem=%x "
  3693. "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
  3694. brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
  3695. brdp->nrpanels, brdp->nrports);
  3696. return(0);
  3697. }
  3698. /*****************************************************************************/
  3699. /*
  3700. * Probe around trying to find where the EISA boards shared memory
  3701. * might be. This is a bit if hack, but it is the best we can do.
  3702. */
  3703. static int stli_eisamemprobe(stlibrd_t *brdp)
  3704. {
  3705. cdkecpsig_t ecpsig, *ecpsigp;
  3706. cdkonbsig_t onbsig, *onbsigp;
  3707. int i, foundit;
  3708. #ifdef DEBUG
  3709. printk(KERN_DEBUG "stli_eisamemprobe(brdp=%x)\n", (int) brdp);
  3710. #endif
  3711. /*
  3712. * First up we reset the board, to get it into a known state. There
  3713. * is only 2 board types here we need to worry about. Don;t use the
  3714. * standard board init routine here, it programs up the shared
  3715. * memory address, and we don't know it yet...
  3716. */
  3717. if (brdp->brdtype == BRD_ECPE) {
  3718. outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
  3719. outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
  3720. udelay(10);
  3721. outb(ECP_EIDISABLE, (brdp->iobase + ECP_EICONFR));
  3722. udelay(500);
  3723. stli_ecpeienable(brdp);
  3724. } else if (brdp->brdtype == BRD_ONBOARDE) {
  3725. outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
  3726. outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
  3727. udelay(10);
  3728. outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
  3729. mdelay(100);
  3730. outb(0x1, brdp->iobase);
  3731. mdelay(1);
  3732. stli_onbeenable(brdp);
  3733. } else {
  3734. return(-ENODEV);
  3735. }
  3736. foundit = 0;
  3737. brdp->memsize = ECP_MEMSIZE;
  3738. /*
  3739. * Board shared memory is enabled, so now we have a poke around and
  3740. * see if we can find it.
  3741. */
  3742. for (i = 0; (i < stli_eisamempsize); i++) {
  3743. brdp->memaddr = stli_eisamemprobeaddrs[i];
  3744. brdp->membase = (void *) brdp->memaddr;
  3745. brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
  3746. if (brdp->membase == (void *) NULL)
  3747. continue;
  3748. if (brdp->brdtype == BRD_ECPE) {
  3749. ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp,
  3750. CDK_SIGADDR, __LINE__);
  3751. memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
  3752. if (ecpsig.magic == ECP_MAGIC)
  3753. foundit = 1;
  3754. } else {
  3755. onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp,
  3756. CDK_SIGADDR, __LINE__);
  3757. memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t));
  3758. if ((onbsig.magic0 == ONB_MAGIC0) &&
  3759. (onbsig.magic1 == ONB_MAGIC1) &&
  3760. (onbsig.magic2 == ONB_MAGIC2) &&
  3761. (onbsig.magic3 == ONB_MAGIC3))
  3762. foundit = 1;
  3763. }
  3764. iounmap(brdp->membase);
  3765. if (foundit)
  3766. break;
  3767. }
  3768. /*
  3769. * Regardless of whether we found the shared memory or not we must
  3770. * disable the region. After that return success or failure.
  3771. */
  3772. if (brdp->brdtype == BRD_ECPE)
  3773. stli_ecpeidisable(brdp);
  3774. else
  3775. stli_onbedisable(brdp);
  3776. if (! foundit) {
  3777. brdp->memaddr = 0;
  3778. brdp->membase = NULL;
  3779. printk(KERN_ERR "STALLION: failed to probe shared memory "
  3780. "region for %s in EISA slot=%d\n",
  3781. stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
  3782. return(-ENODEV);
  3783. }
  3784. return(0);
  3785. }
  3786. static int stli_getbrdnr(void)
  3787. {
  3788. int i;
  3789. for (i = 0; i < STL_MAXBRDS; i++) {
  3790. if (!stli_brds[i]) {
  3791. if (i >= stli_nrbrds)
  3792. stli_nrbrds = i + 1;
  3793. return i;
  3794. }
  3795. }
  3796. return -1;
  3797. }
  3798. /*****************************************************************************/
  3799. /*
  3800. * Probe around and try to find any EISA boards in system. The biggest
  3801. * problem here is finding out what memory address is associated with
  3802. * an EISA board after it is found. The registers of the ECPE and
  3803. * ONboardE are not readable - so we can't read them from there. We
  3804. * don't have access to the EISA CMOS (or EISA BIOS) so we don't
  3805. * actually have any way to find out the real value. The best we can
  3806. * do is go probing around in the usual places hoping we can find it.
  3807. */
  3808. static int stli_findeisabrds(void)
  3809. {
  3810. stlibrd_t *brdp;
  3811. unsigned int iobase, eid;
  3812. int i;
  3813. #ifdef DEBUG
  3814. printk(KERN_DEBUG "stli_findeisabrds()\n");
  3815. #endif
  3816. /*
  3817. * Firstly check if this is an EISA system. Do this by probing for
  3818. * the system board EISA ID. If this is not an EISA system then
  3819. * don't bother going any further!
  3820. */
  3821. outb(0xff, 0xc80);
  3822. if (inb(0xc80) == 0xff)
  3823. return(0);
  3824. /*
  3825. * Looks like an EISA system, so go searching for EISA boards.
  3826. */
  3827. for (iobase = 0x1000; (iobase <= 0xc000); iobase += 0x1000) {
  3828. outb(0xff, (iobase + 0xc80));
  3829. eid = inb(iobase + 0xc80);
  3830. eid |= inb(iobase + 0xc81) << 8;
  3831. if (eid != STL_EISAID)
  3832. continue;
  3833. /*
  3834. * We have found a board. Need to check if this board was
  3835. * statically configured already (just in case!).
  3836. */
  3837. for (i = 0; (i < STL_MAXBRDS); i++) {
  3838. brdp = stli_brds[i];
  3839. if (brdp == (stlibrd_t *) NULL)
  3840. continue;
  3841. if (brdp->iobase == iobase)
  3842. break;
  3843. }
  3844. if (i < STL_MAXBRDS)
  3845. continue;
  3846. /*
  3847. * We have found a Stallion board and it is not configured already.
  3848. * Allocate a board structure and initialize it.
  3849. */
  3850. if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
  3851. return(-ENOMEM);
  3852. if ((brdp->brdnr = stli_getbrdnr()) < 0)
  3853. return(-ENOMEM);
  3854. eid = inb(iobase + 0xc82);
  3855. if (eid == ECP_EISAID)
  3856. brdp->brdtype = BRD_ECPE;
  3857. else if (eid == ONB_EISAID)
  3858. brdp->brdtype = BRD_ONBOARDE;
  3859. else
  3860. brdp->brdtype = BRD_UNKNOWN;
  3861. brdp->iobase = iobase;
  3862. outb(0x1, (iobase + 0xc84));
  3863. if (stli_eisamemprobe(brdp))
  3864. outb(0, (iobase + 0xc84));
  3865. stli_brdinit(brdp);
  3866. }
  3867. return(0);
  3868. }
  3869. /*****************************************************************************/
  3870. /*
  3871. * Find the next available board number that is free.
  3872. */
  3873. /*****************************************************************************/
  3874. #ifdef CONFIG_PCI
  3875. /*
  3876. * We have a Stallion board. Allocate a board structure and
  3877. * initialize it. Read its IO and MEMORY resources from PCI
  3878. * configuration space.
  3879. */
  3880. static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
  3881. {
  3882. stlibrd_t *brdp;
  3883. #ifdef DEBUG
  3884. printk(KERN_DEBUG "stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
  3885. brdtype, dev->bus->number, dev->devfn);
  3886. #endif
  3887. if (pci_enable_device(devp))
  3888. return(-EIO);
  3889. if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
  3890. return(-ENOMEM);
  3891. if ((brdp->brdnr = stli_getbrdnr()) < 0) {
  3892. printk(KERN_INFO "STALLION: too many boards found, "
  3893. "maximum supported %d\n", STL_MAXBRDS);
  3894. return(0);
  3895. }
  3896. brdp->brdtype = brdtype;
  3897. #ifdef DEBUG
  3898. printk(KERN_DEBUG "%s(%d): BAR[]=%lx,%lx,%lx,%lx\n", __FILE__, __LINE__,
  3899. pci_resource_start(devp, 0),
  3900. pci_resource_start(devp, 1),
  3901. pci_resource_start(devp, 2),
  3902. pci_resource_start(devp, 3));
  3903. #endif
  3904. /*
  3905. * We have all resources from the board, so lets setup the actual
  3906. * board structure now.
  3907. */
  3908. brdp->iobase = pci_resource_start(devp, 3);
  3909. brdp->memaddr = pci_resource_start(devp, 2);
  3910. stli_brdinit(brdp);
  3911. return(0);
  3912. }
  3913. /*****************************************************************************/
  3914. /*
  3915. * Find all Stallion PCI boards that might be installed. Initialize each
  3916. * one as it is found.
  3917. */
  3918. static int stli_findpcibrds(void)
  3919. {
  3920. struct pci_dev *dev = NULL;
  3921. int rc;
  3922. #ifdef DEBUG
  3923. printk("stli_findpcibrds()\n");
  3924. #endif
  3925. while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION,
  3926. PCI_DEVICE_ID_ECRA, dev))) {
  3927. if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
  3928. return(rc);
  3929. }
  3930. return(0);
  3931. }
  3932. #endif
  3933. /*****************************************************************************/
  3934. /*
  3935. * Allocate a new board structure. Fill out the basic info in it.
  3936. */
  3937. static stlibrd_t *stli_allocbrd(void)
  3938. {
  3939. stlibrd_t *brdp;
  3940. brdp = (stlibrd_t *) stli_memalloc(sizeof(stlibrd_t));
  3941. if (brdp == (stlibrd_t *) NULL) {
  3942. printk(KERN_ERR "STALLION: failed to allocate memory "
  3943. "(size=%d)\n", sizeof(stlibrd_t));
  3944. return((stlibrd_t *) NULL);
  3945. }
  3946. memset(brdp, 0, sizeof(stlibrd_t));
  3947. brdp->magic = STLI_BOARDMAGIC;
  3948. return(brdp);
  3949. }
  3950. /*****************************************************************************/
  3951. /*
  3952. * Scan through all the boards in the configuration and see what we
  3953. * can find.
  3954. */
  3955. static int stli_initbrds(void)
  3956. {
  3957. stlibrd_t *brdp, *nxtbrdp;
  3958. stlconf_t *confp;
  3959. int i, j;
  3960. #ifdef DEBUG
  3961. printk(KERN_DEBUG "stli_initbrds()\n");
  3962. #endif
  3963. if (stli_nrbrds > STL_MAXBRDS) {
  3964. printk(KERN_INFO "STALLION: too many boards in configuration "
  3965. "table, truncating to %d\n", STL_MAXBRDS);
  3966. stli_nrbrds = STL_MAXBRDS;
  3967. }
  3968. /*
  3969. * Firstly scan the list of static boards configured. Allocate
  3970. * resources and initialize the boards as found. If this is a
  3971. * module then let the module args override static configuration.
  3972. */
  3973. for (i = 0; (i < stli_nrbrds); i++) {
  3974. confp = &stli_brdconf[i];
  3975. #ifdef MODULE
  3976. stli_parsebrd(confp, stli_brdsp[i]);
  3977. #endif
  3978. if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL)
  3979. return(-ENOMEM);
  3980. brdp->brdnr = i;
  3981. brdp->brdtype = confp->brdtype;
  3982. brdp->iobase = confp->ioaddr1;
  3983. brdp->memaddr = confp->memaddr;
  3984. stli_brdinit(brdp);
  3985. }
  3986. /*
  3987. * Static configuration table done, so now use dynamic methods to
  3988. * see if any more boards should be configured.
  3989. */
  3990. #ifdef MODULE
  3991. stli_argbrds();
  3992. #endif
  3993. if (STLI_EISAPROBE)
  3994. stli_findeisabrds();
  3995. #ifdef CONFIG_PCI
  3996. stli_findpcibrds();
  3997. #endif
  3998. /*
  3999. * All found boards are initialized. Now for a little optimization, if
  4000. * no boards are sharing the "shared memory" regions then we can just
  4001. * leave them all enabled. This is in fact the usual case.
  4002. */
  4003. stli_shared = 0;
  4004. if (stli_nrbrds > 1) {
  4005. for (i = 0; (i < stli_nrbrds); i++) {
  4006. brdp = stli_brds[i];
  4007. if (brdp == (stlibrd_t *) NULL)
  4008. continue;
  4009. for (j = i + 1; (j < stli_nrbrds); j++) {
  4010. nxtbrdp = stli_brds[j];
  4011. if (nxtbrdp == (stlibrd_t *) NULL)
  4012. continue;
  4013. if ((brdp->membase >= nxtbrdp->membase) &&
  4014. (brdp->membase <= (nxtbrdp->membase +
  4015. nxtbrdp->memsize - 1))) {
  4016. stli_shared++;
  4017. break;
  4018. }
  4019. }
  4020. }
  4021. }
  4022. if (stli_shared == 0) {
  4023. for (i = 0; (i < stli_nrbrds); i++) {
  4024. brdp = stli_brds[i];
  4025. if (brdp == (stlibrd_t *) NULL)
  4026. continue;
  4027. if (brdp->state & BST_FOUND) {
  4028. EBRDENABLE(brdp);
  4029. brdp->enable = NULL;
  4030. brdp->disable = NULL;
  4031. }
  4032. }
  4033. }
  4034. return(0);
  4035. }
  4036. /*****************************************************************************/
  4037. /*
  4038. * Code to handle an "staliomem" read operation. This device is the
  4039. * contents of the board shared memory. It is used for down loading
  4040. * the slave image (and debugging :-)
  4041. */
  4042. static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
  4043. {
  4044. unsigned long flags;
  4045. void *memptr;
  4046. stlibrd_t *brdp;
  4047. int brdnr, size, n;
  4048. #ifdef DEBUG
  4049. printk(KERN_DEBUG "stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n",
  4050. (int) fp, (int) buf, count, (int) offp);
  4051. #endif
  4052. brdnr = iminor(fp->f_dentry->d_inode);
  4053. if (brdnr >= stli_nrbrds)
  4054. return(-ENODEV);
  4055. brdp = stli_brds[brdnr];
  4056. if (brdp == (stlibrd_t *) NULL)
  4057. return(-ENODEV);
  4058. if (brdp->state == 0)
  4059. return(-ENODEV);
  4060. if (fp->f_pos >= brdp->memsize)
  4061. return(0);
  4062. size = MIN(count, (brdp->memsize - fp->f_pos));
  4063. save_flags(flags);
  4064. cli();
  4065. EBRDENABLE(brdp);
  4066. while (size > 0) {
  4067. memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
  4068. n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
  4069. if (copy_to_user(buf, memptr, n)) {
  4070. count = -EFAULT;
  4071. goto out;
  4072. }
  4073. fp->f_pos += n;
  4074. buf += n;
  4075. size -= n;
  4076. }
  4077. out:
  4078. EBRDDISABLE(brdp);
  4079. restore_flags(flags);
  4080. return(count);
  4081. }
  4082. /*****************************************************************************/
  4083. /*
  4084. * Code to handle an "staliomem" write operation. This device is the
  4085. * contents of the board shared memory. It is used for down loading
  4086. * the slave image (and debugging :-)
  4087. */
  4088. static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
  4089. {
  4090. unsigned long flags;
  4091. void *memptr;
  4092. stlibrd_t *brdp;
  4093. char __user *chbuf;
  4094. int brdnr, size, n;
  4095. #ifdef DEBUG
  4096. printk(KERN_DEBUG "stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n",
  4097. (int) fp, (int) buf, count, (int) offp);
  4098. #endif
  4099. brdnr = iminor(fp->f_dentry->d_inode);
  4100. if (brdnr >= stli_nrbrds)
  4101. return(-ENODEV);
  4102. brdp = stli_brds[brdnr];
  4103. if (brdp == (stlibrd_t *) NULL)
  4104. return(-ENODEV);
  4105. if (brdp->state == 0)
  4106. return(-ENODEV);
  4107. if (fp->f_pos >= brdp->memsize)
  4108. return(0);
  4109. chbuf = (char __user *) buf;
  4110. size = MIN(count, (brdp->memsize - fp->f_pos));
  4111. save_flags(flags);
  4112. cli();
  4113. EBRDENABLE(brdp);
  4114. while (size > 0) {
  4115. memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos);
  4116. n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize)));
  4117. if (copy_from_user(memptr, chbuf, n)) {
  4118. count = -EFAULT;
  4119. goto out;
  4120. }
  4121. fp->f_pos += n;
  4122. chbuf += n;
  4123. size -= n;
  4124. }
  4125. out:
  4126. EBRDDISABLE(brdp);
  4127. restore_flags(flags);
  4128. return(count);
  4129. }
  4130. /*****************************************************************************/
  4131. /*
  4132. * Return the board stats structure to user app.
  4133. */
  4134. static int stli_getbrdstats(combrd_t __user *bp)
  4135. {
  4136. stlibrd_t *brdp;
  4137. int i;
  4138. if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
  4139. return -EFAULT;
  4140. if (stli_brdstats.brd >= STL_MAXBRDS)
  4141. return(-ENODEV);
  4142. brdp = stli_brds[stli_brdstats.brd];
  4143. if (brdp == (stlibrd_t *) NULL)
  4144. return(-ENODEV);
  4145. memset(&stli_brdstats, 0, sizeof(combrd_t));
  4146. stli_brdstats.brd = brdp->brdnr;
  4147. stli_brdstats.type = brdp->brdtype;
  4148. stli_brdstats.hwid = 0;
  4149. stli_brdstats.state = brdp->state;
  4150. stli_brdstats.ioaddr = brdp->iobase;
  4151. stli_brdstats.memaddr = brdp->memaddr;
  4152. stli_brdstats.nrpanels = brdp->nrpanels;
  4153. stli_brdstats.nrports = brdp->nrports;
  4154. for (i = 0; (i < brdp->nrpanels); i++) {
  4155. stli_brdstats.panels[i].panel = i;
  4156. stli_brdstats.panels[i].hwid = brdp->panelids[i];
  4157. stli_brdstats.panels[i].nrports = brdp->panels[i];
  4158. }
  4159. if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
  4160. return -EFAULT;
  4161. return(0);
  4162. }
  4163. /*****************************************************************************/
  4164. /*
  4165. * Resolve the referenced port number into a port struct pointer.
  4166. */
  4167. static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
  4168. {
  4169. stlibrd_t *brdp;
  4170. int i;
  4171. if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
  4172. return((stliport_t *) NULL);
  4173. brdp = stli_brds[brdnr];
  4174. if (brdp == (stlibrd_t *) NULL)
  4175. return((stliport_t *) NULL);
  4176. for (i = 0; (i < panelnr); i++)
  4177. portnr += brdp->panels[i];
  4178. if ((portnr < 0) || (portnr >= brdp->nrports))
  4179. return((stliport_t *) NULL);
  4180. return(brdp->ports[portnr]);
  4181. }
  4182. /*****************************************************************************/
  4183. /*
  4184. * Return the port stats structure to user app. A NULL port struct
  4185. * pointer passed in means that we need to find out from the app
  4186. * what port to get stats for (used through board control device).
  4187. */
  4188. static int stli_portcmdstats(stliport_t *portp)
  4189. {
  4190. unsigned long flags;
  4191. stlibrd_t *brdp;
  4192. int rc;
  4193. memset(&stli_comstats, 0, sizeof(comstats_t));
  4194. if (portp == (stliport_t *) NULL)
  4195. return(-ENODEV);
  4196. brdp = stli_brds[portp->brdnr];
  4197. if (brdp == (stlibrd_t *) NULL)
  4198. return(-ENODEV);
  4199. if (brdp->state & BST_STARTED) {
  4200. if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
  4201. &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
  4202. return(rc);
  4203. } else {
  4204. memset(&stli_cdkstats, 0, sizeof(asystats_t));
  4205. }
  4206. stli_comstats.brd = portp->brdnr;
  4207. stli_comstats.panel = portp->panelnr;
  4208. stli_comstats.port = portp->portnr;
  4209. stli_comstats.state = portp->state;
  4210. stli_comstats.flags = portp->flags;
  4211. save_flags(flags);
  4212. cli();
  4213. if (portp->tty != (struct tty_struct *) NULL) {
  4214. if (portp->tty->driver_data == portp) {
  4215. stli_comstats.ttystate = portp->tty->flags;
  4216. stli_comstats.rxbuffered = portp->tty->flip.count;
  4217. if (portp->tty->termios != (struct termios *) NULL) {
  4218. stli_comstats.cflags = portp->tty->termios->c_cflag;
  4219. stli_comstats.iflags = portp->tty->termios->c_iflag;
  4220. stli_comstats.oflags = portp->tty->termios->c_oflag;
  4221. stli_comstats.lflags = portp->tty->termios->c_lflag;
  4222. }
  4223. }
  4224. }
  4225. restore_flags(flags);
  4226. stli_comstats.txtotal = stli_cdkstats.txchars;
  4227. stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
  4228. stli_comstats.txbuffered = stli_cdkstats.txringq;
  4229. stli_comstats.rxbuffered += stli_cdkstats.rxringq;
  4230. stli_comstats.rxoverrun = stli_cdkstats.overruns;
  4231. stli_comstats.rxparity = stli_cdkstats.parity;
  4232. stli_comstats.rxframing = stli_cdkstats.framing;
  4233. stli_comstats.rxlost = stli_cdkstats.ringover;
  4234. stli_comstats.rxbreaks = stli_cdkstats.rxbreaks;
  4235. stli_comstats.txbreaks = stli_cdkstats.txbreaks;
  4236. stli_comstats.txxon = stli_cdkstats.txstart;
  4237. stli_comstats.txxoff = stli_cdkstats.txstop;
  4238. stli_comstats.rxxon = stli_cdkstats.rxstart;
  4239. stli_comstats.rxxoff = stli_cdkstats.rxstop;
  4240. stli_comstats.rxrtsoff = stli_cdkstats.rtscnt / 2;
  4241. stli_comstats.rxrtson = stli_cdkstats.rtscnt - stli_comstats.rxrtsoff;
  4242. stli_comstats.modem = stli_cdkstats.dcdcnt;
  4243. stli_comstats.hwid = stli_cdkstats.hwid;
  4244. stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
  4245. return(0);
  4246. }
  4247. /*****************************************************************************/
  4248. /*
  4249. * Return the port stats structure to user app. A NULL port struct
  4250. * pointer passed in means that we need to find out from the app
  4251. * what port to get stats for (used through board control device).
  4252. */
  4253. static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
  4254. {
  4255. stlibrd_t *brdp;
  4256. int rc;
  4257. if (!portp) {
  4258. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  4259. return -EFAULT;
  4260. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  4261. stli_comstats.port);
  4262. if (!portp)
  4263. return -ENODEV;
  4264. }
  4265. brdp = stli_brds[portp->brdnr];
  4266. if (!brdp)
  4267. return -ENODEV;
  4268. if ((rc = stli_portcmdstats(portp)) < 0)
  4269. return rc;
  4270. return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
  4271. -EFAULT : 0;
  4272. }
  4273. /*****************************************************************************/
  4274. /*
  4275. * Clear the port stats structure. We also return it zeroed out...
  4276. */
  4277. static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
  4278. {
  4279. stlibrd_t *brdp;
  4280. int rc;
  4281. if (!portp) {
  4282. if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
  4283. return -EFAULT;
  4284. portp = stli_getport(stli_comstats.brd, stli_comstats.panel,
  4285. stli_comstats.port);
  4286. if (!portp)
  4287. return -ENODEV;
  4288. }
  4289. brdp = stli_brds[portp->brdnr];
  4290. if (!brdp)
  4291. return -ENODEV;
  4292. if (brdp->state & BST_STARTED) {
  4293. if ((rc = stli_cmdwait(brdp, portp, A_CLEARSTATS, NULL, 0, 0)) < 0)
  4294. return rc;
  4295. }
  4296. memset(&stli_comstats, 0, sizeof(comstats_t));
  4297. stli_comstats.brd = portp->brdnr;
  4298. stli_comstats.panel = portp->panelnr;
  4299. stli_comstats.port = portp->portnr;
  4300. if (copy_to_user(cp, &stli_comstats, sizeof(comstats_t)))
  4301. return -EFAULT;
  4302. return 0;
  4303. }
  4304. /*****************************************************************************/
  4305. /*
  4306. * Return the entire driver ports structure to a user app.
  4307. */
  4308. static int stli_getportstruct(stliport_t __user *arg)
  4309. {
  4310. stliport_t *portp;
  4311. if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
  4312. return -EFAULT;
  4313. portp = stli_getport(stli_dummyport.brdnr, stli_dummyport.panelnr,
  4314. stli_dummyport.portnr);
  4315. if (!portp)
  4316. return -ENODEV;
  4317. if (copy_to_user(arg, portp, sizeof(stliport_t)))
  4318. return -EFAULT;
  4319. return 0;
  4320. }
  4321. /*****************************************************************************/
  4322. /*
  4323. * Return the entire driver board structure to a user app.
  4324. */
  4325. static int stli_getbrdstruct(stlibrd_t __user *arg)
  4326. {
  4327. stlibrd_t *brdp;
  4328. if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
  4329. return -EFAULT;
  4330. if ((stli_dummybrd.brdnr < 0) || (stli_dummybrd.brdnr >= STL_MAXBRDS))
  4331. return -ENODEV;
  4332. brdp = stli_brds[stli_dummybrd.brdnr];
  4333. if (!brdp)
  4334. return -ENODEV;
  4335. if (copy_to_user(arg, brdp, sizeof(stlibrd_t)))
  4336. return -EFAULT;
  4337. return 0;
  4338. }
  4339. /*****************************************************************************/
  4340. /*
  4341. * The "staliomem" device is also required to do some special operations on
  4342. * the board. We need to be able to send an interrupt to the board,
  4343. * reset it, and start/stop it.
  4344. */
  4345. static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
  4346. {
  4347. stlibrd_t *brdp;
  4348. int brdnr, rc, done;
  4349. void __user *argp = (void __user *)arg;
  4350. #ifdef DEBUG
  4351. printk(KERN_DEBUG "stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n",
  4352. (int) ip, (int) fp, cmd, (int) arg);
  4353. #endif
  4354. /*
  4355. * First up handle the board independent ioctls.
  4356. */
  4357. done = 0;
  4358. rc = 0;
  4359. switch (cmd) {
  4360. case COM_GETPORTSTATS:
  4361. rc = stli_getportstats(NULL, argp);
  4362. done++;
  4363. break;
  4364. case COM_CLRPORTSTATS:
  4365. rc = stli_clrportstats(NULL, argp);
  4366. done++;
  4367. break;
  4368. case COM_GETBRDSTATS:
  4369. rc = stli_getbrdstats(argp);
  4370. done++;
  4371. break;
  4372. case COM_READPORT:
  4373. rc = stli_getportstruct(argp);
  4374. done++;
  4375. break;
  4376. case COM_READBOARD:
  4377. rc = stli_getbrdstruct(argp);
  4378. done++;
  4379. break;
  4380. }
  4381. if (done)
  4382. return(rc);
  4383. /*
  4384. * Now handle the board specific ioctls. These all depend on the
  4385. * minor number of the device they were called from.
  4386. */
  4387. brdnr = iminor(ip);
  4388. if (brdnr >= STL_MAXBRDS)
  4389. return(-ENODEV);
  4390. brdp = stli_brds[brdnr];
  4391. if (!brdp)
  4392. return(-ENODEV);
  4393. if (brdp->state == 0)
  4394. return(-ENODEV);
  4395. switch (cmd) {
  4396. case STL_BINTR:
  4397. EBRDINTR(brdp);
  4398. break;
  4399. case STL_BSTART:
  4400. rc = stli_startbrd(brdp);
  4401. break;
  4402. case STL_BSTOP:
  4403. brdp->state &= ~BST_STARTED;
  4404. break;
  4405. case STL_BRESET:
  4406. brdp->state &= ~BST_STARTED;
  4407. EBRDRESET(brdp);
  4408. if (stli_shared == 0) {
  4409. if (brdp->reenable != NULL)
  4410. (* brdp->reenable)(brdp);
  4411. }
  4412. break;
  4413. default:
  4414. rc = -ENOIOCTLCMD;
  4415. break;
  4416. }
  4417. return(rc);
  4418. }
  4419. static struct tty_operations stli_ops = {
  4420. .open = stli_open,
  4421. .close = stli_close,
  4422. .write = stli_write,
  4423. .put_char = stli_putchar,
  4424. .flush_chars = stli_flushchars,
  4425. .write_room = stli_writeroom,
  4426. .chars_in_buffer = stli_charsinbuffer,
  4427. .ioctl = stli_ioctl,
  4428. .set_termios = stli_settermios,
  4429. .throttle = stli_throttle,
  4430. .unthrottle = stli_unthrottle,
  4431. .stop = stli_stop,
  4432. .start = stli_start,
  4433. .hangup = stli_hangup,
  4434. .flush_buffer = stli_flushbuffer,
  4435. .break_ctl = stli_breakctl,
  4436. .wait_until_sent = stli_waituntilsent,
  4437. .send_xchar = stli_sendxchar,
  4438. .read_proc = stli_readproc,
  4439. .tiocmget = stli_tiocmget,
  4440. .tiocmset = stli_tiocmset,
  4441. };
  4442. /*****************************************************************************/
  4443. int __init stli_init(void)
  4444. {
  4445. int i;
  4446. printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
  4447. stli_initbrds();
  4448. stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
  4449. if (!stli_serial)
  4450. return -ENOMEM;
  4451. /*
  4452. * Allocate a temporary write buffer.
  4453. */
  4454. stli_tmpwritebuf = (char *) stli_memalloc(STLI_TXBUFSIZE);
  4455. if (stli_tmpwritebuf == (char *) NULL)
  4456. printk(KERN_ERR "STALLION: failed to allocate memory "
  4457. "(size=%d)\n", STLI_TXBUFSIZE);
  4458. stli_txcookbuf = stli_memalloc(STLI_TXBUFSIZE);
  4459. if (stli_txcookbuf == (char *) NULL)
  4460. printk(KERN_ERR "STALLION: failed to allocate memory "
  4461. "(size=%d)\n", STLI_TXBUFSIZE);
  4462. /*
  4463. * Set up a character driver for the shared memory region. We need this
  4464. * to down load the slave code image. Also it is a useful debugging tool.
  4465. */
  4466. if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stli_fsiomem))
  4467. printk(KERN_ERR "STALLION: failed to register serial memory "
  4468. "device\n");
  4469. devfs_mk_dir("staliomem");
  4470. istallion_class = class_create(THIS_MODULE, "staliomem");
  4471. for (i = 0; i < 4; i++) {
  4472. devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
  4473. S_IFCHR | S_IRUSR | S_IWUSR,
  4474. "staliomem/%d", i);
  4475. class_device_create(istallion_class, MKDEV(STL_SIOMEMMAJOR, i),
  4476. NULL, "staliomem%d", i);
  4477. }
  4478. /*
  4479. * Set up the tty driver structure and register us as a driver.
  4480. */
  4481. stli_serial->owner = THIS_MODULE;
  4482. stli_serial->driver_name = stli_drvname;
  4483. stli_serial->name = stli_serialname;
  4484. stli_serial->major = STL_SERIALMAJOR;
  4485. stli_serial->minor_start = 0;
  4486. stli_serial->type = TTY_DRIVER_TYPE_SERIAL;
  4487. stli_serial->subtype = SERIAL_TYPE_NORMAL;
  4488. stli_serial->init_termios = stli_deftermios;
  4489. stli_serial->flags = TTY_DRIVER_REAL_RAW;
  4490. tty_set_operations(stli_serial, &stli_ops);
  4491. if (tty_register_driver(stli_serial)) {
  4492. put_tty_driver(stli_serial);
  4493. printk(KERN_ERR "STALLION: failed to register serial driver\n");
  4494. return -EBUSY;
  4495. }
  4496. return(0);
  4497. }
  4498. /*****************************************************************************/