istallion.c 123 KB

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