istallion.c 136 KB

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