istallion.c 136 KB

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