istallion.c 120 KB

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