cyclades.c 159 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542
  1. #undef BLOCKMOVE
  2. #define Z_WAKE
  3. #undef Z_EXT_CHARS_IN_BUFFER
  4. /*
  5. * linux/drivers/char/cyclades.c
  6. *
  7. * This file contains the driver for the Cyclades async multiport
  8. * serial boards.
  9. *
  10. * Initially written by Randolph Bentson <bentson@grieg.seaslug.org>.
  11. * Modified and maintained by Marcio Saito <marcio@cyclades.com>.
  12. *
  13. * Copyright (C) 2007 Jiri Slaby <jirislaby@gmail.com>
  14. *
  15. * Much of the design and some of the code came from serial.c
  16. * which was copyright (C) 1991, 1992 Linus Torvalds. It was
  17. * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
  18. * and then fixed as suggested by Michael K. Johnson 12/12/92.
  19. * Converted to pci probing and cleaned up by Jiri Slaby.
  20. *
  21. * This version supports shared IRQ's (only for PCI boards).
  22. *
  23. * $Log: cyclades.c,v $
  24. * Prevent users from opening non-existing Z ports.
  25. *
  26. * Revision 2.3.2.8 2000/07/06 18:14:16 ivan
  27. * Fixed the PCI detection function to work properly on Alpha systems.
  28. * Implemented support for TIOCSERGETLSR ioctl.
  29. * Implemented full support for non-standard baud rates.
  30. *
  31. * Revision 2.3.2.7 2000/06/01 18:26:34 ivan
  32. * Request PLX I/O region, although driver doesn't use it, to avoid
  33. * problems with other drivers accessing it.
  34. * Removed count for on-board buffer characters in cy_chars_in_buffer
  35. * (Cyclades-Z only).
  36. *
  37. * Revision 2.3.2.6 2000/05/05 13:56:05 ivan
  38. * Driver now reports physical instead of virtual memory addresses.
  39. * Masks were added to some Cyclades-Z read accesses.
  40. * Implemented workaround for PLX9050 bug that would cause a system lockup
  41. * in certain systems, depending on the MMIO addresses allocated to the
  42. * board.
  43. * Changed the Tx interrupt programming in the CD1400 chips to boost up
  44. * performance (Cyclom-Y only).
  45. * Code is now compliant with the new module interface (module_[init|exit]).
  46. * Make use of the PCI helper functions to access PCI resources.
  47. * Did some code "housekeeping".
  48. *
  49. * Revision 2.3.2.5 2000/01/19 14:35:33 ivan
  50. * Fixed bug in cy_set_termios on CRTSCTS flag turnoff.
  51. *
  52. * Revision 2.3.2.4 2000/01/17 09:19:40 ivan
  53. * Fixed SMP locking in Cyclom-Y interrupt handler.
  54. *
  55. * Revision 2.3.2.3 1999/12/28 12:11:39 ivan
  56. * Added a new cyclades_card field called nports to allow the driver to
  57. * know the exact number of ports found by the Z firmware after its load;
  58. * RX buffer contention prevention logic on interrupt op mode revisited
  59. * (Cyclades-Z only);
  60. * Revisited printk's for Z debug;
  61. * Driver now makes sure that the constant SERIAL_XMIT_SIZE is defined;
  62. *
  63. * Revision 2.3.2.2 1999/10/01 11:27:43 ivan
  64. * Fixed bug in cyz_poll that would make all ports but port 0
  65. * unable to transmit/receive data (Cyclades-Z only);
  66. * Implemented logic to prevent the RX buffer from being stuck with data
  67. * due to a driver / firmware race condition in interrupt op mode
  68. * (Cyclades-Z only);
  69. * Fixed bug in block_til_ready logic that would lead to a system crash;
  70. * Revisited cy_close spinlock usage;
  71. *
  72. * Revision 2.3.2.1 1999/09/28 11:01:22 ivan
  73. * Revisited CONFIG_PCI conditional compilation for PCI board support;
  74. * Implemented TIOCGICOUNT and TIOCMIWAIT ioctl support;
  75. * _Major_ cleanup on the Cyclades-Z interrupt support code / logic;
  76. * Removed CTS handling from the driver -- this is now completely handled
  77. * by the firmware (Cyclades-Z only);
  78. * Flush RX on-board buffers on a port open (Cyclades-Z only);
  79. * Fixed handling of ASYNC_SPD_* TTY flags;
  80. * Module unload now unmaps all memory area allocated by ioremap;
  81. *
  82. * Revision 2.3.1.1 1999/07/15 16:45:53 ivan
  83. * Removed CY_PROC conditional compilation;
  84. * Implemented SMP-awareness for the driver;
  85. * Implemented a new ISA IRQ autoprobe that uses the irq_probe_[on|off]
  86. * functions;
  87. * The driver now accepts memory addresses (maddr=0xMMMMM) and IRQs
  88. * (irq=NN) as parameters (only for ISA boards);
  89. * Fixed bug in set_line_char that would prevent the Cyclades-Z
  90. * ports from being configured at speeds above 115.2Kbps;
  91. * Fixed bug in cy_set_termios that would prevent XON/XOFF flow control
  92. * switching from working properly;
  93. * The driver now only prints IRQ info for the Cyclades-Z if it's
  94. * configured to work in interrupt mode;
  95. *
  96. * Revision 2.2.2.3 1999/06/28 11:13:29 ivan
  97. * Added support for interrupt mode operation for the Z cards;
  98. * Removed the driver inactivity control for the Z;
  99. * Added a missing MOD_DEC_USE_COUNT in the cy_open function for when
  100. * the Z firmware is not loaded yet;
  101. * Replaced the "manual" Z Tx flush buffer by a call to a FW command of
  102. * same functionality;
  103. * Implemented workaround for IRQ setting loss on the PCI configuration
  104. * registers after a PCI bridge EEPROM reload (affects PLX9060 only);
  105. *
  106. * Revision 2.2.2.2 1999/05/14 17:18:15 ivan
  107. * /proc entry location changed to /proc/tty/driver/cyclades;
  108. * Added support to shared IRQ's (only for PCI boards);
  109. * Added support for Cobalt Qube2 systems;
  110. * IRQ [de]allocation scheme revisited;
  111. * BREAK implementation changed in order to make use of the 'break_ctl'
  112. * TTY facility;
  113. * Fixed typo in TTY structure field 'driver_name';
  114. * Included a PCI bridge reset and EEPROM reload in the board
  115. * initialization code (for both Y and Z series).
  116. *
  117. * Revision 2.2.2.1 1999/04/08 16:17:43 ivan
  118. * Fixed a bug in cy_wait_until_sent that was preventing the port to be
  119. * closed properly after a SIGINT;
  120. * Module usage counter scheme revisited;
  121. * Added support to the upcoming Y PCI boards (i.e., support to additional
  122. * PCI Device ID's).
  123. *
  124. * Revision 2.2.1.10 1999/01/20 16:14:29 ivan
  125. * Removed all unnecessary page-alignement operations in ioremap calls
  126. * (ioremap is currently safe for these operations).
  127. *
  128. * Revision 2.2.1.9 1998/12/30 18:18:30 ivan
  129. * Changed access to PLX PCI bridge registers from I/O to MMIO, in
  130. * order to make PLX9050-based boards work with certain motherboards.
  131. *
  132. * Revision 2.2.1.8 1998/11/13 12:46:20 ivan
  133. * cy_close function now resets (correctly) the tty->closing flag;
  134. * JIFFIES_DIFF macro fixed.
  135. *
  136. * Revision 2.2.1.7 1998/09/03 12:07:28 ivan
  137. * Fixed bug in cy_close function, which was not informing HW of
  138. * which port should have the reception disabled before doing so;
  139. * fixed Cyclom-8YoP hardware detection bug.
  140. *
  141. * Revision 2.2.1.6 1998/08/20 17:15:39 ivan
  142. * Fixed bug in cy_close function, which causes malfunction
  143. * of one of the first 4 ports when a higher port is closed
  144. * (Cyclom-Y only).
  145. *
  146. * Revision 2.2.1.5 1998/08/10 18:10:28 ivan
  147. * Fixed Cyclom-4Yo hardware detection bug.
  148. *
  149. * Revision 2.2.1.4 1998/08/04 11:02:50 ivan
  150. * /proc/cyclades implementation with great collaboration of
  151. * Marc Lewis <marc@blarg.net>;
  152. * cyy_interrupt was changed to avoid occurrence of kernel oopses
  153. * during PPP operation.
  154. *
  155. * Revision 2.2.1.3 1998/06/01 12:09:10 ivan
  156. * General code review in order to comply with 2.1 kernel standards;
  157. * data loss prevention for slow devices revisited (cy_wait_until_sent
  158. * was created);
  159. * removed conditional compilation for new/old PCI structure support
  160. * (now the driver only supports the new PCI structure).
  161. *
  162. * Revision 2.2.1.1 1998/03/19 16:43:12 ivan
  163. * added conditional compilation for new/old PCI structure support;
  164. * removed kernel series (2.0.x / 2.1.x) conditional compilation.
  165. *
  166. * Revision 2.1.1.3 1998/03/16 18:01:12 ivan
  167. * cleaned up the data loss fix;
  168. * fixed XON/XOFF handling once more (Cyclades-Z);
  169. * general review of the driver routines;
  170. * introduction of a mechanism to prevent data loss with slow
  171. * printers, by forcing a delay before closing the port.
  172. *
  173. * Revision 2.1.1.2 1998/02/17 16:50:00 ivan
  174. * fixed detection/handling of new CD1400 in Ye boards;
  175. * fixed XON/XOFF handling (Cyclades-Z);
  176. * fixed data loss caused by a premature port close;
  177. * introduction of a flag that holds the CD1400 version ID per port
  178. * (used by the CYGETCD1400VER new ioctl).
  179. *
  180. * Revision 2.1.1.1 1997/12/03 17:31:19 ivan
  181. * Code review for the module cleanup routine;
  182. * fixed RTS and DTR status report for new CD1400's in get_modem_info;
  183. * includes anonymous changes regarding signal_pending.
  184. *
  185. * Revision 2.1 1997/11/01 17:42:41 ivan
  186. * Changes in the driver to support Alpha systems (except 8Zo V_1);
  187. * BREAK fix for the Cyclades-Z boards;
  188. * driver inactivity control by FW implemented;
  189. * introduction of flag that allows driver to take advantage of
  190. * a special CD1400 feature related to HW flow control;
  191. * added support for the CD1400 rev. J (Cyclom-Y boards);
  192. * introduction of ioctls to:
  193. * - control the rtsdtr_inv flag (Cyclom-Y);
  194. * - control the rflow flag (Cyclom-Y);
  195. * - adjust the polling interval (Cyclades-Z);
  196. *
  197. * Revision 1.36.4.33 1997/06/27 19:00:00 ivan
  198. * Fixes related to kernel version conditional
  199. * compilation.
  200. *
  201. * Revision 1.36.4.32 1997/06/14 19:30:00 ivan
  202. * Compatibility issues between kernels 2.0.x and
  203. * 2.1.x (mainly related to clear_bit function).
  204. *
  205. * Revision 1.36.4.31 1997/06/03 15:30:00 ivan
  206. * Changes to define the memory window according to the
  207. * board type.
  208. *
  209. * Revision 1.36.4.30 1997/05/16 15:30:00 daniel
  210. * Changes to support new cycladesZ boards.
  211. *
  212. * Revision 1.36.4.29 1997/05/12 11:30:00 daniel
  213. * Merge of Bentson's and Daniel's version 1.36.4.28.
  214. * Corrects bug in cy_detect_pci: check if there are more
  215. * ports than the number of static structs allocated.
  216. * Warning message during initialization if this driver is
  217. * used with the new generation of cycladesZ boards. Those
  218. * will be supported only in next release of the driver.
  219. * Corrects bug in cy_detect_pci and cy_detect_isa that
  220. * returned wrong number of VALID boards, when a cyclomY
  221. * was found with no serial modules connected.
  222. * Changes to use current (2.1.x) kernel subroutine names
  223. * and created macros for compilation with 2.0.x kernel,
  224. * instead of the other way around.
  225. *
  226. * Revision 1.36.4.28 1997/05/?? ??:00:00 bentson
  227. * Change queue_task_irq_off to queue_task_irq.
  228. * The inline function queue_task_irq_off (tqueue.h)
  229. * was removed from latest releases of 2.1.x kernel.
  230. * Use of macro __init to mark the initialization
  231. * routines, so memory can be reused.
  232. * Also incorporate implementation of critical region
  233. * in function cleanup_module() created by anonymous
  234. * linuxer.
  235. *
  236. * Revision 1.36.4.28 1997/04/25 16:00:00 daniel
  237. * Change to support new firmware that solves DCD problem:
  238. * application could fail to receive SIGHUP signal when DCD
  239. * varying too fast.
  240. *
  241. * Revision 1.36.4.27 1997/03/26 10:30:00 daniel
  242. * Changed for support linux versions 2.1.X.
  243. * Backward compatible with linux versions 2.0.X.
  244. * Corrected illegal use of filler field in
  245. * CH_CTRL struct.
  246. * Deleted some debug messages.
  247. *
  248. * Revision 1.36.4.26 1997/02/27 12:00:00 daniel
  249. * Included check for NULL tty pointer in cyz_poll.
  250. *
  251. * Revision 1.36.4.25 1997/02/26 16:28:30 bentson
  252. * Bill Foster at Blarg! Online services noticed that
  253. * some of the switch elements of -Z modem control
  254. * lacked a closing "break;"
  255. *
  256. * Revision 1.36.4.24 1997/02/24 11:00:00 daniel
  257. * Changed low water threshold for buffer xmit_buf
  258. *
  259. * Revision 1.36.4.23 1996/12/02 21:50:16 bentson
  260. * Marcio provided fix to modem status fetch for -Z
  261. *
  262. * Revision 1.36.4.22 1996/10/28 22:41:17 bentson
  263. * improve mapping of -Z control page (thanks to Steve
  264. * Price <stevep@fa.tdktca.com> for help on this)
  265. *
  266. * Revision 1.36.4.21 1996/09/10 17:00:10 bentson
  267. * shift from CPU-bound to memcopy in cyz_polling operation
  268. *
  269. * Revision 1.36.4.20 1996/09/09 18:30:32 Bentson
  270. * Added support to set and report higher speeds.
  271. *
  272. * Revision 1.36.4.19c 1996/08/09 10:00:00 Marcio Saito
  273. * Some fixes in the HW flow control for the BETA release.
  274. * Don't try to register the IRQ.
  275. *
  276. * Revision 1.36.4.19 1996/08/08 16:23:18 Bentson
  277. * make sure "cyc" appears in all kernel messages; all soft interrupts
  278. * handled by same routine; recognize out-of-band reception; comment
  279. * out some diagnostic messages; leave RTS/CTS flow control to hardware;
  280. * fix race condition in -Z buffer management; only -Y needs to explicitly
  281. * flush chars; tidy up some startup messages;
  282. *
  283. * Revision 1.36.4.18 1996/07/25 18:57:31 bentson
  284. * shift MOD_INC_USE_COUNT location to match
  285. * serial.c; purge some diagnostic messages;
  286. *
  287. * Revision 1.36.4.17 1996/07/25 18:01:08 bentson
  288. * enable modem status messages and fetch & process them; note
  289. * time of last activity type for each port; set_line_char now
  290. * supports more than line 0 and treats 0 baud correctly;
  291. * get_modem_info senses rs_status;
  292. *
  293. * Revision 1.36.4.16 1996/07/20 08:43:15 bentson
  294. * barely works--now's time to turn on
  295. * more features 'til it breaks
  296. *
  297. * Revision 1.36.4.15 1996/07/19 22:30:06 bentson
  298. * check more -Z board status; shorten boot message
  299. *
  300. * Revision 1.36.4.14 1996/07/19 22:20:37 bentson
  301. * fix reference to ch_ctrl in startup; verify return
  302. * values from cyz_issue_cmd and cyz_update_channel;
  303. * more stuff to get modem control correct;
  304. *
  305. * Revision 1.36.4.13 1996/07/11 19:53:33 bentson
  306. * more -Z stuff folded in; re-order changes to put -Z stuff
  307. * after -Y stuff (to make changes clearer)
  308. *
  309. * Revision 1.36.4.12 1996/07/11 15:40:55 bentson
  310. * Add code to poll Cyclades-Z. Add code to get & set RS-232 control.
  311. * Add code to send break. Clear firmware ID word at startup (so
  312. * that other code won't talk to inactive board).
  313. *
  314. * Revision 1.36.4.11 1996/07/09 05:28:29 bentson
  315. * add code for -Z in set_line_char
  316. *
  317. * Revision 1.36.4.10 1996/07/08 19:28:37 bentson
  318. * fold more -Z stuff (or in some cases, error messages)
  319. * into driver; add text to "don't know what to do" messages.
  320. *
  321. * Revision 1.36.4.9 1996/07/08 18:38:38 bentson
  322. * moved compile-time flags near top of file; cosmetic changes
  323. * to narrow text (to allow 2-up printing); changed many declarations
  324. * to "static" to limit external symbols; shuffled code order to
  325. * coalesce -Y and -Z specific code, also to put internal functions
  326. * in order of tty_driver structure; added code to recognize -Z
  327. * ports (and for moment, do nothing or report error); add cy_startup
  328. * to parse boot command line for extra base addresses for ISA probes;
  329. *
  330. * Revision 1.36.4.8 1996/06/25 17:40:19 bentson
  331. * reorder some code, fix types of some vars (int vs. long),
  332. * add cy_setup to support user declared ISA addresses
  333. *
  334. * Revision 1.36.4.7 1996/06/21 23:06:18 bentson
  335. * dump ioctl based firmware load (it's now a user level
  336. * program); ensure uninitialzed ports cannot be used
  337. *
  338. * Revision 1.36.4.6 1996/06/20 23:17:19 bentson
  339. * rename vars and restructure some code
  340. *
  341. * Revision 1.36.4.5 1996/06/14 15:09:44 bentson
  342. * get right status back after boot load
  343. *
  344. * Revision 1.36.4.4 1996/06/13 19:51:44 bentson
  345. * successfully loads firmware
  346. *
  347. * Revision 1.36.4.3 1996/06/13 06:08:33 bentson
  348. * add more of the code for the boot/load ioctls
  349. *
  350. * Revision 1.36.4.2 1996/06/11 21:00:51 bentson
  351. * start to add Z functionality--starting with ioctl
  352. * for loading firmware
  353. *
  354. * Revision 1.36.4.1 1996/06/10 18:03:02 bentson
  355. * added code to recognize Z/PCI card at initialization; report
  356. * presence, but card is not initialized (because firmware needs
  357. * to be loaded)
  358. *
  359. * Revision 1.36.3.8 1996/06/07 16:29:00 bentson
  360. * starting minor number at zero; added missing verify_area
  361. * as noted by Heiko Eissfeldt <heiko@colossus.escape.de>
  362. *
  363. * Revision 1.36.3.7 1996/04/19 21:06:18 bentson
  364. * remove unneeded boot message & fix CLOCAL hardware flow
  365. * control (Miquel van Smoorenburg <miquels@Q.cistron.nl>);
  366. * remove unused diagnostic statements; minor 0 is first;
  367. *
  368. * Revision 1.36.3.6 1996/03/13 13:21:17 marcio
  369. * The kernel function vremap (available only in later 1.3.xx kernels)
  370. * allows the access to memory addresses above the RAM. This revision
  371. * of the driver supports PCI boards below 1Mb (device id 0x100) and
  372. * above 1Mb (device id 0x101).
  373. *
  374. * Revision 1.36.3.5 1996/03/07 15:20:17 bentson
  375. * Some global changes to interrupt handling spilled into
  376. * this driver--mostly unused arguments in system function
  377. * calls. Also added change by Marcio Saito which should
  378. * reduce lost interrupts at startup by fast processors.
  379. *
  380. * Revision 1.36.3.4 1995/11/13 20:45:10 bentson
  381. * Changes by Corey Minyard <minyard@wf-rch.cirr.com> distributed
  382. * in 1.3.41 kernel to remove a possible race condition, extend
  383. * some error messages, and let the driver run as a loadable module
  384. * Change by Alan Wendt <alan@ez0.ezlink.com> to remove a
  385. * possible race condition.
  386. * Change by Marcio Saito <marcio@cyclades.com> to fix PCI addressing.
  387. *
  388. * Revision 1.36.3.3 1995/11/13 19:44:48 bentson
  389. * Changes by Linus Torvalds in 1.3.33 kernel distribution
  390. * required due to reordering of driver initialization.
  391. * Drivers are now initialized *after* memory management.
  392. *
  393. * Revision 1.36.3.2 1995/09/08 22:07:14 bentson
  394. * remove printk from ISR; fix typo
  395. *
  396. * Revision 1.36.3.1 1995/09/01 12:00:42 marcio
  397. * Minor fixes in the PCI board support. PCI function calls in
  398. * conditional compilation (CONFIG_PCI). Thanks to Jim Duncan
  399. * <duncan@okay.com>. "bad serial count" message removed.
  400. *
  401. * Revision 1.36.3 1995/08/22 09:19:42 marcio
  402. * Cyclom-Y/PCI support added. Changes in the cy_init routine and
  403. * board initialization. Changes in the boot messages. The driver
  404. * supports up to 4 boards and 64 ports by default.
  405. *
  406. * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
  407. * disambiguate between Cyclom-16Y and Cyclom-32Ye;
  408. *
  409. * Revision 1.36.1.3 1995/03/23 22:15:35 bentson
  410. * add missing break in modem control block in ioctl switch statement
  411. * (discovered by Michael Edward Chastain <mec@jobe.shell.portal.com>);
  412. *
  413. * Revision 1.36.1.2 1995/03/22 19:16:22 bentson
  414. * make sure CTS flow control is set as soon as possible (thanks
  415. * to note from David Lambert <lambert@chesapeake.rps.slb.com>);
  416. *
  417. * Revision 1.36.1.1 1995/03/13 15:44:43 bentson
  418. * initialize defaults for receive threshold and stale data timeout;
  419. * cosmetic changes;
  420. *
  421. * Revision 1.36 1995/03/10 23:33:53 bentson
  422. * added support of chips 4-7 in 32 port Cyclom-Ye;
  423. * fix cy_interrupt pointer dereference problem
  424. * (Joe Portman <baron@aa.net>);
  425. * give better error response if open is attempted on non-existent port
  426. * (Zachariah Vaum <jchryslr@netcom.com>);
  427. * correct command timeout (Kenneth Lerman <lerman@@seltd.newnet.com>);
  428. * conditional compilation for -16Y on systems with fast, noisy bus;
  429. * comment out diagnostic print function;
  430. * cleaned up table of base addresses;
  431. * set receiver time-out period register to correct value,
  432. * set receive threshold to better default values,
  433. * set chip timer to more accurate 200 Hz ticking,
  434. * add code to monitor and modify receive parameters
  435. * (Rik Faith <faith@cs.unc.edu> Nick Simicich
  436. * <njs@scifi.emi.net>);
  437. *
  438. * Revision 1.35 1994/12/16 13:54:18 steffen
  439. * additional patch by Marcio Saito for board detection
  440. * Accidently left out in 1.34
  441. *
  442. * Revision 1.34 1994/12/10 12:37:12 steffen
  443. * This is the corrected version as suggested by Marcio Saito
  444. *
  445. * Revision 1.33 1994/12/01 22:41:18 bentson
  446. * add hooks to support more high speeds directly; add tytso
  447. * patch regarding CLOCAL wakeups
  448. *
  449. * Revision 1.32 1994/11/23 19:50:04 bentson
  450. * allow direct kernel control of higher signalling rates;
  451. * look for cards at additional locations
  452. *
  453. * Revision 1.31 1994/11/16 04:33:28 bentson
  454. * ANOTHER fix from Corey Minyard, minyard@wf-rch.cirr.com--
  455. * a problem in chars_in_buffer has been resolved by some
  456. * small changes; this should yield smoother output
  457. *
  458. * Revision 1.30 1994/11/16 04:28:05 bentson
  459. * Fix from Corey Minyard, Internet: minyard@metronet.com,
  460. * UUCP: minyard@wf-rch.cirr.com, WORK: minyardbnr.ca, to
  461. * cy_hangup that appears to clear up much (all?) of the
  462. * DTR glitches; also he's added/cleaned-up diagnostic messages
  463. *
  464. * Revision 1.29 1994/11/16 04:16:07 bentson
  465. * add change proposed by Ralph Sims, ralphs@halcyon.com, to
  466. * operate higher speeds in same way as other serial ports;
  467. * add more serial ports (for up to two 16-port muxes).
  468. *
  469. * Revision 1.28 1994/11/04 00:13:16 root
  470. * turn off diagnostic messages
  471. *
  472. * Revision 1.27 1994/11/03 23:46:37 root
  473. * bunch of changes to bring driver into greater conformance
  474. * with the serial.c driver (looking for missed fixes)
  475. *
  476. * Revision 1.26 1994/11/03 22:40:36 root
  477. * automatic interrupt probing fixed.
  478. *
  479. * Revision 1.25 1994/11/03 20:17:02 root
  480. * start to implement auto-irq
  481. *
  482. * Revision 1.24 1994/11/03 18:01:55 root
  483. * still working on modem signals--trying not to drop DTR
  484. * during the getty/login processes
  485. *
  486. * Revision 1.23 1994/11/03 17:51:36 root
  487. * extend baud rate support; set receive threshold as function
  488. * of baud rate; fix some problems with RTS/CTS;
  489. *
  490. * Revision 1.22 1994/11/02 18:05:35 root
  491. * changed arguments to udelay to type long to get
  492. * delays to be of correct duration
  493. *
  494. * Revision 1.21 1994/11/02 17:37:30 root
  495. * employ udelay (after calibrating loops_per_second earlier
  496. * in init/main.c) instead of using home-grown delay routines
  497. *
  498. * Revision 1.20 1994/11/02 03:11:38 root
  499. * cy_chars_in_buffer forces a return value of 0 to let
  500. * login work (don't know why it does); some functions
  501. * that were returning EFAULT, now executes the code;
  502. * more work on deciding when to disable xmit interrupts;
  503. *
  504. * Revision 1.19 1994/11/01 20:10:14 root
  505. * define routine to start transmission interrupts (by enabling
  506. * transmit interrupts); directly enable/disable modem interrupts;
  507. *
  508. * Revision 1.18 1994/11/01 18:40:45 bentson
  509. * Don't always enable transmit interrupts in startup; interrupt on
  510. * TxMpty instead of TxRdy to help characters get out before shutdown;
  511. * restructure xmit interrupt to check for chars first and quit if
  512. * none are ready to go; modem status (MXVRx) is upright, _not_ inverted
  513. * (to my view);
  514. *
  515. * Revision 1.17 1994/10/30 04:39:45 bentson
  516. * rename serial_driver and callout_driver to cy_serial_driver and
  517. * cy_callout_driver to avoid linkage interference; initialize
  518. * info->type to PORT_CIRRUS; ruggedize paranoia test; elide ->port
  519. * from cyclades_port structure; add paranoia check to cy_close;
  520. *
  521. * Revision 1.16 1994/10/30 01:14:33 bentson
  522. * change major numbers; add some _early_ return statements;
  523. *
  524. * Revision 1.15 1994/10/29 06:43:15 bentson
  525. * final tidying up for clean compile; enable some error reporting
  526. *
  527. * Revision 1.14 1994/10/28 20:30:22 Bentson
  528. * lots of changes to drag the driver towards the new tty_io
  529. * structures and operation. not expected to work, but may
  530. * compile cleanly.
  531. *
  532. * Revision 1.13 1994/07/21 23:08:57 Bentson
  533. * add some diagnostic cruft; support 24 lines (for testing
  534. * both -8Y and -16Y cards; be more thorough in servicing all
  535. * chips during interrupt; add "volatile" a few places to
  536. * circumvent compiler optimizations; fix base & offset
  537. * computations in block_til_ready (was causing chip 0 to
  538. * stop operation)
  539. *
  540. * Revision 1.12 1994/07/19 16:42:11 Bentson
  541. * add some hackery for kernel version 1.1.8; expand
  542. * error messages; refine timing for delay loops and
  543. * declare loop params volatile
  544. *
  545. * Revision 1.11 1994/06/11 21:53:10 bentson
  546. * get use of save_car right in transmit interrupt service
  547. *
  548. * Revision 1.10.1.1 1994/06/11 21:31:18 bentson
  549. * add some diagnostic printing; try to fix save_car stuff
  550. *
  551. * Revision 1.10 1994/06/11 20:36:08 bentson
  552. * clean up compiler warnings
  553. *
  554. * Revision 1.9 1994/06/11 19:42:46 bentson
  555. * added a bunch of code to support modem signalling
  556. *
  557. * Revision 1.8 1994/06/11 17:57:07 bentson
  558. * recognize break & parity error
  559. *
  560. * Revision 1.7 1994/06/05 05:51:34 bentson
  561. * Reorder baud table to be monotonic; add cli to CP; discard
  562. * incoming characters and status if the line isn't open; start to
  563. * fold code into cy_throttle; start to port get_serial_info,
  564. * set_serial_info, get_modem_info, set_modem_info, and send_break
  565. * from serial.c; expand cy_ioctl; relocate and expand config_setup;
  566. * get flow control characters from tty struct; invalidate ports w/o
  567. * hardware;
  568. *
  569. * Revision 1.6 1994/05/31 18:42:21 bentson
  570. * add a loop-breaker in the interrupt service routine;
  571. * note when port is initialized so that it can be shut
  572. * down under the right conditions; receive works without
  573. * any obvious errors
  574. *
  575. * Revision 1.5 1994/05/30 00:55:02 bentson
  576. * transmit works without obvious errors
  577. *
  578. * Revision 1.4 1994/05/27 18:46:27 bentson
  579. * incorporated more code from lib_y.c; can now print short
  580. * strings under interrupt control to port zero; seems to
  581. * select ports/channels/lines correctly
  582. *
  583. * Revision 1.3 1994/05/25 22:12:44 bentson
  584. * shifting from multi-port on a card to proper multiplexor
  585. * data structures; added skeletons of most routines
  586. *
  587. * Revision 1.2 1994/05/19 13:21:43 bentson
  588. * start to crib from other sources
  589. *
  590. */
  591. #define CY_VERSION "2.5"
  592. /* If you need to install more boards than NR_CARDS, change the constant
  593. in the definition below. No other change is necessary to support up to
  594. eight boards. Beyond that you'll have to extend cy_isa_addresses. */
  595. #define NR_CARDS 4
  596. /*
  597. If the total number of ports is larger than NR_PORTS, change this
  598. constant in the definition below. No other change is necessary to
  599. support more boards/ports. */
  600. #define NR_PORTS 256
  601. #define ZE_V1_NPORTS 64
  602. #define ZO_V1 0
  603. #define ZO_V2 1
  604. #define ZE_V1 2
  605. #define SERIAL_PARANOIA_CHECK
  606. #undef CY_DEBUG_OPEN
  607. #undef CY_DEBUG_THROTTLE
  608. #undef CY_DEBUG_OTHER
  609. #undef CY_DEBUG_IO
  610. #undef CY_DEBUG_COUNT
  611. #undef CY_DEBUG_DTR
  612. #undef CY_DEBUG_WAIT_UNTIL_SENT
  613. #undef CY_DEBUG_INTERRUPTS
  614. #undef CY_16Y_HACK
  615. #undef CY_ENABLE_MONITORING
  616. #undef CY_PCI_DEBUG
  617. /*
  618. * Include section
  619. */
  620. #include <linux/module.h>
  621. #include <linux/errno.h>
  622. #include <linux/signal.h>
  623. #include <linux/sched.h>
  624. #include <linux/timer.h>
  625. #include <linux/interrupt.h>
  626. #include <linux/tty.h>
  627. #include <linux/tty_flip.h>
  628. #include <linux/serial.h>
  629. #include <linux/major.h>
  630. #include <linux/string.h>
  631. #include <linux/fcntl.h>
  632. #include <linux/ptrace.h>
  633. #include <linux/cyclades.h>
  634. #include <linux/mm.h>
  635. #include <linux/ioport.h>
  636. #include <linux/init.h>
  637. #include <linux/delay.h>
  638. #include <linux/spinlock.h>
  639. #include <linux/bitops.h>
  640. #include <linux/firmware.h>
  641. #include <asm/system.h>
  642. #include <asm/io.h>
  643. #include <asm/irq.h>
  644. #include <asm/uaccess.h>
  645. #include <linux/kernel.h>
  646. #include <linux/pci.h>
  647. #include <linux/stat.h>
  648. #include <linux/proc_fs.h>
  649. static void cy_throttle(struct tty_struct *tty);
  650. static void cy_send_xchar(struct tty_struct *tty, char ch);
  651. #define IS_CYC_Z(card) ((card).num_chips == -1)
  652. #define Z_FPGA_CHECK(card) \
  653. ((readl(&((struct RUNTIME_9060 __iomem *) \
  654. ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
  655. #define ISZLOADED(card) (((ZO_V1==readl(&((struct RUNTIME_9060 __iomem *) \
  656. ((card).ctl_addr))->mail_box_0)) || \
  657. Z_FPGA_CHECK(card)) && \
  658. (ZFIRM_ID==readl(&((struct FIRM_ID __iomem *) \
  659. ((card).base_addr+ID_ADDRESS))->signature)))
  660. #ifndef SERIAL_XMIT_SIZE
  661. #define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096))
  662. #endif
  663. #define WAKEUP_CHARS 256
  664. #define STD_COM_FLAGS (0)
  665. /* firmware stuff */
  666. #define ZL_MAX_BLOCKS 16
  667. #define DRIVER_VERSION 0x02010203
  668. #define RAM_SIZE 0x80000
  669. #define Z_FPGA_LOADED(X) ((readl(&(X)->init_ctrl) & (1<<17)) != 0)
  670. enum zblock_type {
  671. ZBLOCK_PRG = 0,
  672. ZBLOCK_FPGA = 1
  673. };
  674. struct zfile_header {
  675. char name[64];
  676. char date[32];
  677. char aux[32];
  678. u32 n_config;
  679. u32 config_offset;
  680. u32 n_blocks;
  681. u32 block_offset;
  682. u32 reserved[9];
  683. } __attribute__ ((packed));
  684. struct zfile_config {
  685. char name[64];
  686. u32 mailbox;
  687. u32 function;
  688. u32 n_blocks;
  689. u32 block_list[ZL_MAX_BLOCKS];
  690. } __attribute__ ((packed));
  691. struct zfile_block {
  692. u32 type;
  693. u32 file_offset;
  694. u32 ram_offset;
  695. u32 size;
  696. } __attribute__ ((packed));
  697. static struct tty_driver *cy_serial_driver;
  698. #ifdef CONFIG_ISA
  699. /* This is the address lookup table. The driver will probe for
  700. Cyclom-Y/ISA boards at all addresses in here. If you want the
  701. driver to probe addresses at a different address, add it to
  702. this table. If the driver is probing some other board and
  703. causing problems, remove the offending address from this table.
  704. The cy_setup function extracts additional addresses from the
  705. boot options line. The form is "cyclades=address,address..."
  706. */
  707. static unsigned int cy_isa_addresses[] = {
  708. 0xD0000,
  709. 0xD2000,
  710. 0xD4000,
  711. 0xD6000,
  712. 0xD8000,
  713. 0xDA000,
  714. 0xDC000,
  715. 0xDE000,
  716. 0, 0, 0, 0, 0, 0, 0, 0
  717. };
  718. #define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses)
  719. #ifdef MODULE
  720. static long maddr[NR_CARDS];
  721. static int irq[NR_CARDS];
  722. module_param_array(maddr, long, NULL, 0);
  723. module_param_array(irq, int, NULL, 0);
  724. #endif
  725. #endif /* CONFIG_ISA */
  726. /* This is the per-card data structure containing address, irq, number of
  727. channels, etc. This driver supports a maximum of NR_CARDS cards.
  728. */
  729. static struct cyclades_card cy_card[NR_CARDS];
  730. static int cy_next_channel; /* next minor available */
  731. /*
  732. * This is used to look up the divisor speeds and the timeouts
  733. * We're normally limited to 15 distinct baud rates. The extra
  734. * are accessed via settings in info->flags.
  735. * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  736. * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  737. * HI VHI
  738. * 20
  739. */
  740. static int baud_table[] = {
  741. 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
  742. 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
  743. 230400, 0
  744. };
  745. static char baud_co_25[] = { /* 25 MHz clock option table */
  746. /* value => 00 01 02 03 04 */
  747. /* divide by 8 32 128 512 2048 */
  748. 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
  749. 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  750. };
  751. static char baud_bpr_25[] = { /* 25 MHz baud rate period table */
  752. 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
  753. 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
  754. };
  755. static char baud_co_60[] = { /* 60 MHz clock option table (CD1400 J) */
  756. /* value => 00 01 02 03 04 */
  757. /* divide by 8 32 128 512 2048 */
  758. 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
  759. 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  760. 0x00
  761. };
  762. static char baud_bpr_60[] = { /* 60 MHz baud rate period table (CD1400 J) */
  763. 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
  764. 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
  765. 0x21
  766. };
  767. static char baud_cor3[] = { /* receive threshold */
  768. 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  769. 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
  770. 0x07
  771. };
  772. /*
  773. * The Cyclades driver implements HW flow control as any serial driver.
  774. * The cyclades_port structure member rflow and the vector rflow_thr
  775. * allows us to take advantage of a special feature in the CD1400 to avoid
  776. * data loss even when the system interrupt latency is too high. These flags
  777. * are to be used only with very special applications. Setting these flags
  778. * requires the use of a special cable (DTR and RTS reversed). In the new
  779. * CD1400-based boards (rev. 6.00 or later), there is no need for special
  780. * cables.
  781. */
  782. static char rflow_thr[] = { /* rflow threshold */
  783. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  784. 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
  785. 0x0a
  786. };
  787. /* The Cyclom-Ye has placed the sequential chips in non-sequential
  788. * address order. This look-up table overcomes that problem.
  789. */
  790. static int cy_chip_offset[] = { 0x0000,
  791. 0x0400,
  792. 0x0800,
  793. 0x0C00,
  794. 0x0200,
  795. 0x0600,
  796. 0x0A00,
  797. 0x0E00
  798. };
  799. /* PCI related definitions */
  800. #ifdef CONFIG_PCI
  801. static struct pci_device_id cy_pci_dev_id[] __devinitdata = {
  802. { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Y_Lo) }, /* PCI < 1Mb */
  803. { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Y_Hi) }, /* PCI > 1Mb */
  804. { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_4Y_Lo) }, /* 4Y PCI < 1Mb */
  805. { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_4Y_Hi) }, /* 4Y PCI > 1Mb */
  806. { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_8Y_Lo) }, /* 8Y PCI < 1Mb */
  807. { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_8Y_Hi) }, /* 8Y PCI > 1Mb */
  808. { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Z_Lo) }, /* Z PCI < 1Mb */
  809. { PCI_DEVICE(PCI_VENDOR_ID_CYCLADES, PCI_DEVICE_ID_CYCLOM_Z_Hi) }, /* Z PCI > 1Mb */
  810. { } /* end of table */
  811. };
  812. MODULE_DEVICE_TABLE(pci, cy_pci_dev_id);
  813. #endif
  814. static void cy_start(struct tty_struct *);
  815. static void set_line_char(struct cyclades_port *);
  816. static int cyz_issue_cmd(struct cyclades_card *, __u32, __u8, __u32);
  817. #ifdef CONFIG_ISA
  818. static unsigned detect_isa_irq(void __iomem *);
  819. #endif /* CONFIG_ISA */
  820. static int cyclades_get_proc_info(char *, char **, off_t, int, int *, void *);
  821. #ifndef CONFIG_CYZ_INTR
  822. static void cyz_poll(unsigned long);
  823. /* The Cyclades-Z polling cycle is defined by this variable */
  824. static long cyz_polling_cycle = CZ_DEF_POLL;
  825. static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0);
  826. #else /* CONFIG_CYZ_INTR */
  827. static void cyz_rx_restart(unsigned long);
  828. static struct timer_list cyz_rx_full_timer[NR_PORTS];
  829. #endif /* CONFIG_CYZ_INTR */
  830. static inline int serial_paranoia_check(struct cyclades_port *info,
  831. char *name, const char *routine)
  832. {
  833. #ifdef SERIAL_PARANOIA_CHECK
  834. if (!info) {
  835. printk(KERN_WARNING "cyc Warning: null cyclades_port for (%s) "
  836. "in %s\n", name, routine);
  837. return 1;
  838. }
  839. if (info->magic != CYCLADES_MAGIC) {
  840. printk(KERN_WARNING "cyc Warning: bad magic number for serial "
  841. "struct (%s) in %s\n", name, routine);
  842. return 1;
  843. }
  844. #endif
  845. return 0;
  846. } /* serial_paranoia_check */
  847. /*
  848. * This routine is used by the interrupt handler to schedule
  849. * processing in the software interrupt portion of the driver
  850. * (also known as the "bottom half"). This can be called any
  851. * number of times for any channel without harm.
  852. */
  853. static inline void cy_sched_event(struct cyclades_port *info, int event)
  854. {
  855. info->event |= 1 << event; /* remember what kind of event and who */
  856. schedule_work(&info->tqueue);
  857. } /* cy_sched_event */
  858. /*
  859. * This routine is used to handle the "bottom half" processing for the
  860. * serial driver, known also the "software interrupt" processing.
  861. * This processing is done at the kernel interrupt level, after the
  862. * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
  863. * is where time-consuming activities which can not be done in the
  864. * interrupt driver proper are done; the interrupt driver schedules
  865. * them using cy_sched_event(), and they get done here.
  866. *
  867. * This is done through one level of indirection--the task queue.
  868. * When a hardware interrupt service routine wants service by the
  869. * driver's bottom half, it enqueues the appropriate tq_struct (one
  870. * per port) to the keventd work queue and sets a request flag
  871. * that the work queue be processed.
  872. *
  873. * Although this may seem unwieldy, it gives the system a way to
  874. * pass an argument (in this case the pointer to the cyclades_port
  875. * structure) to the bottom half of the driver. Previous kernels
  876. * had to poll every port to see if that port needed servicing.
  877. */
  878. static void
  879. do_softint(struct work_struct *work)
  880. {
  881. struct cyclades_port *info =
  882. container_of(work, struct cyclades_port, tqueue);
  883. struct tty_struct *tty;
  884. tty = info->tty;
  885. if (!tty)
  886. return;
  887. if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
  888. tty_hangup(info->tty);
  889. wake_up_interruptible(&info->open_wait);
  890. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  891. }
  892. if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event))
  893. wake_up_interruptible(&info->open_wait);
  894. #ifdef CONFIG_CYZ_INTR
  895. if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event) &&
  896. !timer_pending(&cyz_rx_full_timer[info->line]))
  897. mod_timer(&cyz_rx_full_timer[info->line], jiffies + 1);
  898. #endif
  899. if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event))
  900. wake_up_interruptible(&info->delta_msr_wait);
  901. tty_wakeup(tty);
  902. #ifdef Z_WAKE
  903. if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event))
  904. complete(&info->shutdown_wait);
  905. #endif
  906. } /* do_softint */
  907. /***********************************************************/
  908. /********* Start of block of Cyclom-Y specific code ********/
  909. /* This routine waits up to 1000 micro-seconds for the previous
  910. command to the Cirrus chip to complete and then issues the
  911. new command. An error is returned if the previous command
  912. didn't finish within the time limit.
  913. This function is only called from inside spinlock-protected code.
  914. */
  915. static int cyy_issue_cmd(void __iomem * base_addr, u_char cmd, int index)
  916. {
  917. unsigned int i;
  918. /* Check to see that the previous command has completed */
  919. for (i = 0; i < 100; i++) {
  920. if (readb(base_addr + (CyCCR << index)) == 0) {
  921. break;
  922. }
  923. udelay(10L);
  924. }
  925. /* if the CCR never cleared, the previous command
  926. didn't finish within the "reasonable time" */
  927. if (i == 100)
  928. return -1;
  929. /* Issue the new command */
  930. cy_writeb(base_addr + (CyCCR << index), cmd);
  931. return 0;
  932. } /* cyy_issue_cmd */
  933. #ifdef CONFIG_ISA
  934. /* ISA interrupt detection code */
  935. static unsigned detect_isa_irq(void __iomem * address)
  936. {
  937. int irq;
  938. unsigned long irqs, flags;
  939. int save_xir, save_car;
  940. int index = 0; /* IRQ probing is only for ISA */
  941. /* forget possible initially masked and pending IRQ */
  942. irq = probe_irq_off(probe_irq_on());
  943. /* Clear interrupts on the board first */
  944. cy_writeb(address + (Cy_ClrIntr << index), 0);
  945. /* Cy_ClrIntr is 0x1800 */
  946. irqs = probe_irq_on();
  947. /* Wait ... */
  948. udelay(5000L);
  949. /* Enable the Tx interrupts on the CD1400 */
  950. local_irq_save(flags);
  951. cy_writeb(address + (CyCAR << index), 0);
  952. cyy_issue_cmd(address, CyCHAN_CTL | CyENB_XMTR, index);
  953. cy_writeb(address + (CyCAR << index), 0);
  954. cy_writeb(address + (CySRER << index),
  955. readb(address + (CySRER << index)) | CyTxRdy);
  956. local_irq_restore(flags);
  957. /* Wait ... */
  958. udelay(5000L);
  959. /* Check which interrupt is in use */
  960. irq = probe_irq_off(irqs);
  961. /* Clean up */
  962. save_xir = (u_char) readb(address + (CyTIR << index));
  963. save_car = readb(address + (CyCAR << index));
  964. cy_writeb(address + (CyCAR << index), (save_xir & 0x3));
  965. cy_writeb(address + (CySRER << index),
  966. readb(address + (CySRER << index)) & ~CyTxRdy);
  967. cy_writeb(address + (CyTIR << index), (save_xir & 0x3f));
  968. cy_writeb(address + (CyCAR << index), (save_car));
  969. cy_writeb(address + (Cy_ClrIntr << index), 0);
  970. /* Cy_ClrIntr is 0x1800 */
  971. return (irq > 0) ? irq : 0;
  972. }
  973. #endif /* CONFIG_ISA */
  974. static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
  975. void __iomem * base_addr, int status, int index)
  976. {
  977. struct cyclades_port *info;
  978. struct tty_struct *tty;
  979. int char_count;
  980. int j, len, mdm_change, mdm_status, outch;
  981. int save_xir, channel, save_car;
  982. char data;
  983. if (status & CySRReceive) { /* reception interrupt */
  984. #ifdef CY_DEBUG_INTERRUPTS
  985. printk(KERN_DEBUG "cyy_interrupt: rcvd intr, chip %d\n", chip);
  986. #endif
  987. /* determine the channel & change to that context */
  988. spin_lock(&cinfo->card_lock);
  989. save_xir = (u_char) readb(base_addr + (CyRIR << index));
  990. channel = (u_short) (save_xir & CyIRChannel);
  991. info = &cinfo->ports[channel + chip * 4];
  992. save_car = readb(base_addr + (CyCAR << index));
  993. cy_writeb(base_addr + (CyCAR << index), save_xir);
  994. /* if there is nowhere to put the data, discard it */
  995. if (info->tty == NULL) {
  996. j = (readb(base_addr + (CyRIVR << index)) &
  997. CyIVRMask);
  998. if (j == CyIVRRxEx) { /* exception */
  999. data = readb(base_addr + (CyRDSR << index));
  1000. } else { /* normal character reception */
  1001. char_count = readb(base_addr +
  1002. (CyRDCR << index));
  1003. while (char_count--) {
  1004. data = readb(base_addr +
  1005. (CyRDSR << index));
  1006. }
  1007. }
  1008. } else { /* there is an open port for this data */
  1009. tty = info->tty;
  1010. j = (readb(base_addr + (CyRIVR << index)) &
  1011. CyIVRMask);
  1012. if (j == CyIVRRxEx) { /* exception */
  1013. data = readb(base_addr + (CyRDSR << index));
  1014. /* For statistics only */
  1015. if (data & CyBREAK)
  1016. info->icount.brk++;
  1017. else if (data & CyFRAME)
  1018. info->icount.frame++;
  1019. else if (data & CyPARITY)
  1020. info->icount.parity++;
  1021. else if (data & CyOVERRUN)
  1022. info->icount.overrun++;
  1023. if (data & info->ignore_status_mask) {
  1024. info->icount.rx++;
  1025. spin_unlock(&cinfo->card_lock);
  1026. return;
  1027. }
  1028. if (tty_buffer_request_room(tty, 1)) {
  1029. if (data & info->read_status_mask) {
  1030. if (data & CyBREAK) {
  1031. tty_insert_flip_char(
  1032. tty,
  1033. readb(
  1034. base_addr +
  1035. (CyRDSR <<
  1036. index)),
  1037. TTY_BREAK);
  1038. info->icount.rx++;
  1039. if (info->flags &
  1040. ASYNC_SAK) {
  1041. do_SAK(tty);
  1042. }
  1043. } else if (data & CyFRAME) {
  1044. tty_insert_flip_char(
  1045. tty,
  1046. readb(
  1047. base_addr +
  1048. (CyRDSR <<
  1049. index)),
  1050. TTY_FRAME);
  1051. info->icount.rx++;
  1052. info->idle_stats.
  1053. frame_errs++;
  1054. } else if (data & CyPARITY) {
  1055. /* Pieces of seven... */
  1056. tty_insert_flip_char(
  1057. tty,
  1058. readb(
  1059. base_addr +
  1060. (CyRDSR <<
  1061. index)),
  1062. TTY_PARITY);
  1063. info->icount.rx++;
  1064. info->idle_stats.
  1065. parity_errs++;
  1066. } else if (data & CyOVERRUN) {
  1067. tty_insert_flip_char(
  1068. tty, 0,
  1069. TTY_OVERRUN);
  1070. info->icount.rx++;
  1071. /* If the flip buffer itself is
  1072. overflowing, we still lose
  1073. the next incoming character.
  1074. */
  1075. tty_insert_flip_char(
  1076. tty,
  1077. readb(
  1078. base_addr +
  1079. (CyRDSR <<
  1080. index)),
  1081. TTY_FRAME);
  1082. info->icount.rx++;
  1083. info->idle_stats.
  1084. overruns++;
  1085. /* These two conditions may imply */
  1086. /* a normal read should be done. */
  1087. /* }else if(data & CyTIMEOUT){ */
  1088. /* }else if(data & CySPECHAR){ */
  1089. } else {
  1090. tty_insert_flip_char(
  1091. tty, 0,
  1092. TTY_NORMAL);
  1093. info->icount.rx++;
  1094. }
  1095. } else {
  1096. tty_insert_flip_char(tty, 0,
  1097. TTY_NORMAL);
  1098. info->icount.rx++;
  1099. }
  1100. } else {
  1101. /* there was a software buffer
  1102. overrun and nothing could be
  1103. done about it!!! */
  1104. info->icount.buf_overrun++;
  1105. info->idle_stats.overruns++;
  1106. }
  1107. } else { /* normal character reception */
  1108. /* load # chars available from the chip */
  1109. char_count = readb(base_addr +
  1110. (CyRDCR << index));
  1111. #ifdef CY_ENABLE_MONITORING
  1112. ++info->mon.int_count;
  1113. info->mon.char_count += char_count;
  1114. if (char_count > info->mon.char_max)
  1115. info->mon.char_max = char_count;
  1116. info->mon.char_last = char_count;
  1117. #endif
  1118. len = tty_buffer_request_room(tty, char_count);
  1119. while (len--) {
  1120. data = readb(base_addr +
  1121. (CyRDSR << index));
  1122. tty_insert_flip_char(tty, data,
  1123. TTY_NORMAL);
  1124. info->idle_stats.recv_bytes++;
  1125. info->icount.rx++;
  1126. #ifdef CY_16Y_HACK
  1127. udelay(10L);
  1128. #endif
  1129. }
  1130. info->idle_stats.recv_idle = jiffies;
  1131. }
  1132. tty_schedule_flip(tty);
  1133. }
  1134. /* end of service */
  1135. cy_writeb(base_addr + (CyRIR << index), (save_xir & 0x3f));
  1136. cy_writeb(base_addr + (CyCAR << index), (save_car));
  1137. spin_unlock(&cinfo->card_lock);
  1138. }
  1139. if (status & CySRTransmit) { /* transmission interrupt */
  1140. /* Since we only get here when the transmit buffer
  1141. is empty, we know we can always stuff a dozen
  1142. characters. */
  1143. #ifdef CY_DEBUG_INTERRUPTS
  1144. printk(KERN_DEBUG "cyy_interrupt: xmit intr, chip %d\n", chip);
  1145. #endif
  1146. /* determine the channel & change to that context */
  1147. spin_lock(&cinfo->card_lock);
  1148. save_xir = (u_char) readb(base_addr + (CyTIR << index));
  1149. channel = (u_short) (save_xir & CyIRChannel);
  1150. save_car = readb(base_addr + (CyCAR << index));
  1151. cy_writeb(base_addr + (CyCAR << index), save_xir);
  1152. /* validate the port# (as configured and open) */
  1153. if (channel + chip * 4 >= cinfo->nports) {
  1154. cy_writeb(base_addr + (CySRER << index),
  1155. readb(base_addr + (CySRER << index)) &
  1156. ~CyTxRdy);
  1157. goto txend;
  1158. }
  1159. info = &cinfo->ports[channel + chip * 4];
  1160. if (info->tty == NULL) {
  1161. cy_writeb(base_addr + (CySRER << index),
  1162. readb(base_addr + (CySRER << index)) &
  1163. ~CyTxRdy);
  1164. goto txdone;
  1165. }
  1166. /* load the on-chip space for outbound data */
  1167. char_count = info->xmit_fifo_size;
  1168. if (info->x_char) { /* send special char */
  1169. outch = info->x_char;
  1170. cy_writeb(base_addr + (CyTDR << index), outch);
  1171. char_count--;
  1172. info->icount.tx++;
  1173. info->x_char = 0;
  1174. }
  1175. if (info->breakon || info->breakoff) {
  1176. if (info->breakon) {
  1177. cy_writeb(base_addr + (CyTDR << index), 0);
  1178. cy_writeb(base_addr + (CyTDR << index), 0x81);
  1179. info->breakon = 0;
  1180. char_count -= 2;
  1181. }
  1182. if (info->breakoff) {
  1183. cy_writeb(base_addr + (CyTDR << index), 0);
  1184. cy_writeb(base_addr + (CyTDR << index), 0x83);
  1185. info->breakoff = 0;
  1186. char_count -= 2;
  1187. }
  1188. }
  1189. while (char_count-- > 0) {
  1190. if (!info->xmit_cnt) {
  1191. if (readb(base_addr + (CySRER << index)) &
  1192. CyTxMpty) {
  1193. cy_writeb(base_addr + (CySRER << index),
  1194. readb(base_addr +
  1195. (CySRER << index)) &
  1196. ~CyTxMpty);
  1197. } else {
  1198. cy_writeb(base_addr + (CySRER << index),
  1199. (readb(base_addr +
  1200. (CySRER << index)) &
  1201. ~CyTxRdy) | CyTxMpty);
  1202. }
  1203. goto txdone;
  1204. }
  1205. if (info->xmit_buf == NULL) {
  1206. cy_writeb(base_addr + (CySRER << index),
  1207. readb(base_addr + (CySRER << index)) &
  1208. ~CyTxRdy);
  1209. goto txdone;
  1210. }
  1211. if (info->tty->stopped || info->tty->hw_stopped) {
  1212. cy_writeb(base_addr + (CySRER << index),
  1213. readb(base_addr + (CySRER << index)) &
  1214. ~CyTxRdy);
  1215. goto txdone;
  1216. }
  1217. /* Because the Embedded Transmit Commands have
  1218. been enabled, we must check to see if the
  1219. escape character, NULL, is being sent. If it
  1220. is, we must ensure that there is room for it
  1221. to be doubled in the output stream. Therefore
  1222. we no longer advance the pointer when the
  1223. character is fetched, but rather wait until
  1224. after the check for a NULL output character.
  1225. This is necessary because there may not be
  1226. room for the two chars needed to send a NULL.)
  1227. */
  1228. outch = info->xmit_buf[info->xmit_tail];
  1229. if (outch) {
  1230. info->xmit_cnt--;
  1231. info->xmit_tail = (info->xmit_tail + 1) &
  1232. (SERIAL_XMIT_SIZE - 1);
  1233. cy_writeb(base_addr + (CyTDR << index), outch);
  1234. info->icount.tx++;
  1235. } else {
  1236. if (char_count > 1) {
  1237. info->xmit_cnt--;
  1238. info->xmit_tail = (info->xmit_tail + 1)&
  1239. (SERIAL_XMIT_SIZE - 1);
  1240. cy_writeb(base_addr + (CyTDR << index),
  1241. outch);
  1242. cy_writeb(base_addr + (CyTDR << index),
  1243. 0);
  1244. info->icount.tx++;
  1245. char_count--;
  1246. }
  1247. }
  1248. }
  1249. txdone:
  1250. if (info->xmit_cnt < WAKEUP_CHARS) {
  1251. cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
  1252. }
  1253. txend:
  1254. /* end of service */
  1255. cy_writeb(base_addr + (CyTIR << index), (save_xir & 0x3f));
  1256. cy_writeb(base_addr + (CyCAR << index), (save_car));
  1257. spin_unlock(&cinfo->card_lock);
  1258. }
  1259. if (status & CySRModem) { /* modem interrupt */
  1260. /* determine the channel & change to that context */
  1261. spin_lock(&cinfo->card_lock);
  1262. save_xir = (u_char) readb(base_addr + (CyMIR << index));
  1263. channel = (u_short) (save_xir & CyIRChannel);
  1264. info = &cinfo->ports[channel + chip * 4];
  1265. save_car = readb(base_addr + (CyCAR << index));
  1266. cy_writeb(base_addr + (CyCAR << index), save_xir);
  1267. mdm_change = readb(base_addr + (CyMISR << index));
  1268. mdm_status = readb(base_addr + (CyMSVR1 << index));
  1269. if (info->tty) {
  1270. if (mdm_change & CyANY_DELTA) {
  1271. /* For statistics only */
  1272. if (mdm_change & CyDCD)
  1273. info->icount.dcd++;
  1274. if (mdm_change & CyCTS)
  1275. info->icount.cts++;
  1276. if (mdm_change & CyDSR)
  1277. info->icount.dsr++;
  1278. if (mdm_change & CyRI)
  1279. info->icount.rng++;
  1280. cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
  1281. }
  1282. if ((mdm_change & CyDCD) &&
  1283. (info->flags & ASYNC_CHECK_CD)) {
  1284. if (mdm_status & CyDCD) {
  1285. cy_sched_event(info,
  1286. Cy_EVENT_OPEN_WAKEUP);
  1287. } else {
  1288. cy_sched_event(info, Cy_EVENT_HANGUP);
  1289. }
  1290. }
  1291. if ((mdm_change & CyCTS) &&
  1292. (info->flags & ASYNC_CTS_FLOW)) {
  1293. if (info->tty->hw_stopped) {
  1294. if (mdm_status & CyCTS) {
  1295. /* cy_start isn't used
  1296. because... !!! */
  1297. info->tty->hw_stopped = 0;
  1298. cy_writeb(base_addr +
  1299. (CySRER << index),
  1300. readb(base_addr +
  1301. (CySRER <<
  1302. index))|
  1303. CyTxRdy);
  1304. cy_sched_event(info,
  1305. Cy_EVENT_WRITE_WAKEUP);
  1306. }
  1307. } else {
  1308. if (!(mdm_status & CyCTS)) {
  1309. /* cy_stop isn't used
  1310. because ... !!! */
  1311. info->tty->hw_stopped = 1;
  1312. cy_writeb(base_addr +
  1313. (CySRER << index),
  1314. readb(base_addr +
  1315. (CySRER <<
  1316. index)) &
  1317. ~CyTxRdy);
  1318. }
  1319. }
  1320. }
  1321. /* if (mdm_change & CyDSR) {
  1322. }
  1323. if (mdm_change & CyRI) {
  1324. }*/
  1325. }
  1326. /* end of service */
  1327. cy_writeb(base_addr + (CyMIR << index), (save_xir & 0x3f));
  1328. cy_writeb(base_addr + (CyCAR << index), save_car);
  1329. spin_unlock(&cinfo->card_lock);
  1330. }
  1331. }
  1332. /* The real interrupt service routine is called
  1333. whenever the card wants its hand held--chars
  1334. received, out buffer empty, modem change, etc.
  1335. */
  1336. static irqreturn_t cyy_interrupt(int irq, void *dev_id)
  1337. {
  1338. int status;
  1339. struct cyclades_card *cinfo = dev_id;
  1340. void __iomem *base_addr, *card_base_addr;
  1341. int chip;
  1342. int index;
  1343. int too_many;
  1344. int had_work;
  1345. if (unlikely(cinfo == NULL)) {
  1346. #ifdef CY_DEBUG_INTERRUPTS
  1347. printk(KERN_DEBUG "cyy_interrupt: spurious interrupt %d\n",irq);
  1348. #endif
  1349. return IRQ_NONE; /* spurious interrupt */
  1350. }
  1351. card_base_addr = cinfo->base_addr;
  1352. index = cinfo->bus_index;
  1353. /* card was not initialized yet (e.g. DEBUG_SHIRQ) */
  1354. if (unlikely(card_base_addr == NULL))
  1355. return IRQ_HANDLED;
  1356. /* This loop checks all chips in the card. Make a note whenever
  1357. _any_ chip had some work to do, as this is considered an
  1358. indication that there will be more to do. Only when no chip
  1359. has any work does this outermost loop exit.
  1360. */
  1361. do {
  1362. had_work = 0;
  1363. for (chip = 0; chip < cinfo->num_chips; chip++) {
  1364. base_addr = cinfo->base_addr +
  1365. (cy_chip_offset[chip] << index);
  1366. too_many = 0;
  1367. while ((status = readb(base_addr +
  1368. (CySVRR << index))) != 0x00) {
  1369. had_work++;
  1370. /* The purpose of the following test is to ensure that
  1371. no chip can monopolize the driver. This forces the
  1372. chips to be checked in a round-robin fashion (after
  1373. draining each of a bunch (1000) of characters).
  1374. */
  1375. if (1000 < too_many++) {
  1376. break;
  1377. }
  1378. cyy_intr_chip(cinfo, chip, base_addr, status,
  1379. index);
  1380. }
  1381. }
  1382. } while (had_work);
  1383. /* clear interrupts */
  1384. spin_lock(&cinfo->card_lock);
  1385. cy_writeb(card_base_addr + (Cy_ClrIntr << index), 0);
  1386. /* Cy_ClrIntr is 0x1800 */
  1387. spin_unlock(&cinfo->card_lock);
  1388. return IRQ_HANDLED;
  1389. } /* cyy_interrupt */
  1390. /***********************************************************/
  1391. /********* End of block of Cyclom-Y specific code **********/
  1392. /******** Start of block of Cyclades-Z specific code *********/
  1393. /***********************************************************/
  1394. static int
  1395. cyz_fetch_msg(struct cyclades_card *cinfo,
  1396. __u32 * channel, __u8 * cmd, __u32 * param)
  1397. {
  1398. struct FIRM_ID __iomem *firm_id;
  1399. struct ZFW_CTRL __iomem *zfw_ctrl;
  1400. struct BOARD_CTRL __iomem *board_ctrl;
  1401. unsigned long loc_doorbell;
  1402. firm_id = cinfo->base_addr + ID_ADDRESS;
  1403. if (!ISZLOADED(*cinfo)) {
  1404. return -1;
  1405. }
  1406. zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  1407. board_ctrl = &zfw_ctrl->board_ctrl;
  1408. loc_doorbell = readl(&((struct RUNTIME_9060 __iomem *)
  1409. (cinfo->ctl_addr))->loc_doorbell);
  1410. if (loc_doorbell) {
  1411. *cmd = (char)(0xff & loc_doorbell);
  1412. *channel = readl(&board_ctrl->fwcmd_channel);
  1413. *param = (__u32) readl(&board_ctrl->fwcmd_param);
  1414. cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
  1415. loc_doorbell, 0xffffffff);
  1416. return 1;
  1417. }
  1418. return 0;
  1419. } /* cyz_fetch_msg */
  1420. static int
  1421. cyz_issue_cmd(struct cyclades_card *cinfo,
  1422. __u32 channel, __u8 cmd, __u32 param)
  1423. {
  1424. struct FIRM_ID __iomem *firm_id;
  1425. struct ZFW_CTRL __iomem *zfw_ctrl;
  1426. struct BOARD_CTRL __iomem *board_ctrl;
  1427. __u32 __iomem *pci_doorbell;
  1428. int index;
  1429. firm_id = cinfo->base_addr + ID_ADDRESS;
  1430. if (!ISZLOADED(*cinfo)) {
  1431. return -1;
  1432. }
  1433. zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  1434. board_ctrl = &zfw_ctrl->board_ctrl;
  1435. index = 0;
  1436. pci_doorbell =
  1437. &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell;
  1438. while ((readl(pci_doorbell) & 0xff) != 0) {
  1439. if (index++ == 1000) {
  1440. return (int)(readl(pci_doorbell) & 0xff);
  1441. }
  1442. udelay(50L);
  1443. }
  1444. cy_writel(&board_ctrl->hcmd_channel, channel);
  1445. cy_writel(&board_ctrl->hcmd_param, param);
  1446. cy_writel(pci_doorbell, (long)cmd);
  1447. return 0;
  1448. } /* cyz_issue_cmd */
  1449. static void
  1450. cyz_handle_rx(struct cyclades_port *info, struct CH_CTRL __iomem *ch_ctrl,
  1451. struct BUF_CTRL __iomem *buf_ctrl)
  1452. {
  1453. struct cyclades_card *cinfo = info->card;
  1454. struct tty_struct *tty = info->tty;
  1455. int char_count;
  1456. int len;
  1457. #ifdef BLOCKMOVE
  1458. unsigned char *buf;
  1459. #else
  1460. char data;
  1461. #endif
  1462. __u32 rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr;
  1463. rx_get = new_rx_get = readl(&buf_ctrl->rx_get);
  1464. rx_put = readl(&buf_ctrl->rx_put);
  1465. rx_bufsize = readl(&buf_ctrl->rx_bufsize);
  1466. rx_bufaddr = readl(&buf_ctrl->rx_bufaddr);
  1467. if (rx_put >= rx_get)
  1468. char_count = rx_put - rx_get;
  1469. else
  1470. char_count = rx_put - rx_get + rx_bufsize;
  1471. if (char_count) {
  1472. #ifdef CY_ENABLE_MONITORING
  1473. info->mon.int_count++;
  1474. info->mon.char_count += char_count;
  1475. if (char_count > info->mon.char_max)
  1476. info->mon.char_max = char_count;
  1477. info->mon.char_last = char_count;
  1478. #endif
  1479. if (tty == NULL) {
  1480. /* flush received characters */
  1481. new_rx_get = (new_rx_get + char_count) &
  1482. (rx_bufsize - 1);
  1483. info->rflush_count++;
  1484. } else {
  1485. #ifdef BLOCKMOVE
  1486. /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
  1487. for performance, but because of buffer boundaries, there
  1488. may be several steps to the operation */
  1489. while (1) {
  1490. len = tty_prepare_flip_string(tty, &buf,
  1491. char_count);
  1492. if (!len)
  1493. break;
  1494. len = min_t(unsigned int, min(len, char_count),
  1495. rx_bufsize - new_rx_get);
  1496. memcpy_fromio(buf, cinfo->base_addr +
  1497. rx_bufaddr + new_rx_get, len);
  1498. new_rx_get = (new_rx_get + len) &
  1499. (rx_bufsize - 1);
  1500. char_count -= len;
  1501. info->icount.rx += len;
  1502. info->idle_stats.recv_bytes += len;
  1503. }
  1504. #else
  1505. len = tty_buffer_request_room(tty, char_count);
  1506. while (len--) {
  1507. data = readb(cinfo->base_addr + rx_bufaddr +
  1508. new_rx_get);
  1509. new_rx_get = (new_rx_get + 1)& (rx_bufsize - 1);
  1510. tty_insert_flip_char(tty, data, TTY_NORMAL);
  1511. info->idle_stats.recv_bytes++;
  1512. info->icount.rx++;
  1513. }
  1514. #endif
  1515. #ifdef CONFIG_CYZ_INTR
  1516. /* Recalculate the number of chars in the RX buffer and issue
  1517. a cmd in case it's higher than the RX high water mark */
  1518. rx_put = readl(&buf_ctrl->rx_put);
  1519. if (rx_put >= rx_get)
  1520. char_count = rx_put - rx_get;
  1521. else
  1522. char_count = rx_put - rx_get + rx_bufsize;
  1523. if (char_count >= (int)readl(&buf_ctrl->rx_threshold)) {
  1524. cy_sched_event(info, Cy_EVENT_Z_RX_FULL);
  1525. }
  1526. #endif
  1527. info->idle_stats.recv_idle = jiffies;
  1528. tty_schedule_flip(tty);
  1529. }
  1530. /* Update rx_get */
  1531. cy_writel(&buf_ctrl->rx_get, new_rx_get);
  1532. }
  1533. }
  1534. static void
  1535. cyz_handle_tx(struct cyclades_port *info, struct CH_CTRL __iomem *ch_ctrl,
  1536. struct BUF_CTRL __iomem *buf_ctrl)
  1537. {
  1538. struct cyclades_card *cinfo = info->card;
  1539. struct tty_struct *tty = info->tty;
  1540. char data;
  1541. int char_count;
  1542. #ifdef BLOCKMOVE
  1543. int small_count;
  1544. #endif
  1545. __u32 tx_put, tx_get, tx_bufsize, tx_bufaddr;
  1546. if (info->xmit_cnt <= 0) /* Nothing to transmit */
  1547. return;
  1548. tx_get = readl(&buf_ctrl->tx_get);
  1549. tx_put = readl(&buf_ctrl->tx_put);
  1550. tx_bufsize = readl(&buf_ctrl->tx_bufsize);
  1551. tx_bufaddr = readl(&buf_ctrl->tx_bufaddr);
  1552. if (tx_put >= tx_get)
  1553. char_count = tx_get - tx_put - 1 + tx_bufsize;
  1554. else
  1555. char_count = tx_get - tx_put - 1;
  1556. if (char_count) {
  1557. if (tty == NULL)
  1558. goto ztxdone;
  1559. if (info->x_char) { /* send special char */
  1560. data = info->x_char;
  1561. cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
  1562. tx_put = (tx_put + 1) & (tx_bufsize - 1);
  1563. info->x_char = 0;
  1564. char_count--;
  1565. info->icount.tx++;
  1566. }
  1567. #ifdef BLOCKMOVE
  1568. while (0 < (small_count = min_t(unsigned int,
  1569. tx_bufsize - tx_put, min_t(unsigned int,
  1570. (SERIAL_XMIT_SIZE - info->xmit_tail),
  1571. min_t(unsigned int, info->xmit_cnt,
  1572. char_count))))) {
  1573. memcpy_toio((char *)(cinfo->base_addr + tx_bufaddr +
  1574. tx_put),
  1575. &info->xmit_buf[info->xmit_tail],
  1576. small_count);
  1577. tx_put = (tx_put + small_count) & (tx_bufsize - 1);
  1578. char_count -= small_count;
  1579. info->icount.tx += small_count;
  1580. info->xmit_cnt -= small_count;
  1581. info->xmit_tail = (info->xmit_tail + small_count) &
  1582. (SERIAL_XMIT_SIZE - 1);
  1583. }
  1584. #else
  1585. while (info->xmit_cnt && char_count) {
  1586. data = info->xmit_buf[info->xmit_tail];
  1587. info->xmit_cnt--;
  1588. info->xmit_tail = (info->xmit_tail + 1) &
  1589. (SERIAL_XMIT_SIZE - 1);
  1590. cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
  1591. tx_put = (tx_put + 1) & (tx_bufsize - 1);
  1592. char_count--;
  1593. info->icount.tx++;
  1594. }
  1595. #endif
  1596. ztxdone:
  1597. if (info->xmit_cnt < WAKEUP_CHARS) {
  1598. cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
  1599. }
  1600. /* Update tx_put */
  1601. cy_writel(&buf_ctrl->tx_put, tx_put);
  1602. }
  1603. }
  1604. static void cyz_handle_cmd(struct cyclades_card *cinfo)
  1605. {
  1606. struct tty_struct *tty;
  1607. struct cyclades_port *info;
  1608. static struct FIRM_ID __iomem *firm_id;
  1609. static struct ZFW_CTRL __iomem *zfw_ctrl;
  1610. static struct BOARD_CTRL __iomem *board_ctrl;
  1611. static struct CH_CTRL __iomem *ch_ctrl;
  1612. static struct BUF_CTRL __iomem *buf_ctrl;
  1613. __u32 channel;
  1614. __u8 cmd;
  1615. __u32 param;
  1616. __u32 hw_ver, fw_ver;
  1617. int special_count;
  1618. int delta_count;
  1619. firm_id = cinfo->base_addr + ID_ADDRESS;
  1620. zfw_ctrl = cinfo->base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  1621. board_ctrl = &zfw_ctrl->board_ctrl;
  1622. fw_ver = readl(&board_ctrl->fw_version);
  1623. hw_ver = readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
  1624. mail_box_0);
  1625. while (cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) {
  1626. special_count = 0;
  1627. delta_count = 0;
  1628. info = &cinfo->ports[channel];
  1629. if ((tty = info->tty) == NULL)
  1630. continue;
  1631. ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
  1632. buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
  1633. switch (cmd) {
  1634. case C_CM_PR_ERROR:
  1635. tty_insert_flip_char(tty, 0, TTY_PARITY);
  1636. info->icount.rx++;
  1637. special_count++;
  1638. break;
  1639. case C_CM_FR_ERROR:
  1640. tty_insert_flip_char(tty, 0, TTY_FRAME);
  1641. info->icount.rx++;
  1642. special_count++;
  1643. break;
  1644. case C_CM_RXBRK:
  1645. tty_insert_flip_char(tty, 0, TTY_BREAK);
  1646. info->icount.rx++;
  1647. special_count++;
  1648. break;
  1649. case C_CM_MDCD:
  1650. info->icount.dcd++;
  1651. delta_count++;
  1652. if (info->flags & ASYNC_CHECK_CD) {
  1653. if ((fw_ver > 241 ? ((u_long) param) :
  1654. readl(&ch_ctrl->rs_status)) &
  1655. C_RS_DCD) {
  1656. cy_sched_event(info,
  1657. Cy_EVENT_OPEN_WAKEUP);
  1658. } else {
  1659. cy_sched_event(info, Cy_EVENT_HANGUP);
  1660. }
  1661. }
  1662. break;
  1663. case C_CM_MCTS:
  1664. info->icount.cts++;
  1665. delta_count++;
  1666. break;
  1667. case C_CM_MRI:
  1668. info->icount.rng++;
  1669. delta_count++;
  1670. break;
  1671. case C_CM_MDSR:
  1672. info->icount.dsr++;
  1673. delta_count++;
  1674. break;
  1675. #ifdef Z_WAKE
  1676. case C_CM_IOCTLW:
  1677. cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP);
  1678. break;
  1679. #endif
  1680. #ifdef CONFIG_CYZ_INTR
  1681. case C_CM_RXHIWM:
  1682. case C_CM_RXNNDT:
  1683. case C_CM_INTBACK2:
  1684. /* Reception Interrupt */
  1685. #ifdef CY_DEBUG_INTERRUPTS
  1686. printk(KERN_DEBUG "cyz_interrupt: rcvd intr, card %d, "
  1687. "port %ld\n", info->card, channel);
  1688. #endif
  1689. cyz_handle_rx(info, ch_ctrl, buf_ctrl);
  1690. break;
  1691. case C_CM_TXBEMPTY:
  1692. case C_CM_TXLOWWM:
  1693. case C_CM_INTBACK:
  1694. /* Transmission Interrupt */
  1695. #ifdef CY_DEBUG_INTERRUPTS
  1696. printk(KERN_DEBUG "cyz_interrupt: xmit intr, card %d, "
  1697. "port %ld\n", info->card, channel);
  1698. #endif
  1699. cyz_handle_tx(info, ch_ctrl, buf_ctrl);
  1700. break;
  1701. #endif /* CONFIG_CYZ_INTR */
  1702. case C_CM_FATAL:
  1703. /* should do something with this !!! */
  1704. break;
  1705. default:
  1706. break;
  1707. }
  1708. if (delta_count)
  1709. cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
  1710. if (special_count)
  1711. tty_schedule_flip(tty);
  1712. }
  1713. }
  1714. #ifdef CONFIG_CYZ_INTR
  1715. static irqreturn_t cyz_interrupt(int irq, void *dev_id)
  1716. {
  1717. struct cyclades_card *cinfo = dev_id;
  1718. if (unlikely(cinfo == NULL)) {
  1719. #ifdef CY_DEBUG_INTERRUPTS
  1720. printk(KERN_DEBUG "cyz_interrupt: spurious interrupt %d\n",irq);
  1721. #endif
  1722. return IRQ_NONE; /* spurious interrupt */
  1723. }
  1724. if (unlikely(!ISZLOADED(*cinfo))) {
  1725. #ifdef CY_DEBUG_INTERRUPTS
  1726. printk(KERN_DEBUG "cyz_interrupt: board not yet loaded "
  1727. "(IRQ%d).\n", irq);
  1728. #endif
  1729. return IRQ_NONE;
  1730. }
  1731. /* Handle the interrupts */
  1732. cyz_handle_cmd(cinfo);
  1733. return IRQ_HANDLED;
  1734. } /* cyz_interrupt */
  1735. static void cyz_rx_restart(unsigned long arg)
  1736. {
  1737. struct cyclades_port *info = (struct cyclades_port *)arg;
  1738. struct cyclades_card *card = info->card;
  1739. int retval;
  1740. __u32 channel = info->line - card->first_line;
  1741. unsigned long flags;
  1742. spin_lock_irqsave(&card->card_lock, flags);
  1743. retval = cyz_issue_cmd(card, channel, C_CM_INTBACK2, 0L);
  1744. if (retval != 0) {
  1745. printk(KERN_ERR "cyc:cyz_rx_restart retval on ttyC%d was %x\n",
  1746. info->line, retval);
  1747. }
  1748. spin_unlock_irqrestore(&card->card_lock, flags);
  1749. }
  1750. #else /* CONFIG_CYZ_INTR */
  1751. static void cyz_poll(unsigned long arg)
  1752. {
  1753. struct cyclades_card *cinfo;
  1754. struct cyclades_port *info;
  1755. struct tty_struct *tty;
  1756. struct FIRM_ID __iomem *firm_id;
  1757. struct ZFW_CTRL __iomem *zfw_ctrl;
  1758. struct BOARD_CTRL __iomem *board_ctrl;
  1759. struct CH_CTRL __iomem *ch_ctrl;
  1760. struct BUF_CTRL __iomem *buf_ctrl;
  1761. unsigned long expires = jiffies + HZ;
  1762. int card, port;
  1763. for (card = 0; card < NR_CARDS; card++) {
  1764. cinfo = &cy_card[card];
  1765. if (!IS_CYC_Z(*cinfo))
  1766. continue;
  1767. if (!ISZLOADED(*cinfo))
  1768. continue;
  1769. firm_id = cinfo->base_addr + ID_ADDRESS;
  1770. zfw_ctrl = cinfo->base_addr +
  1771. (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  1772. board_ctrl = &(zfw_ctrl->board_ctrl);
  1773. /* Skip first polling cycle to avoid racing conditions with the FW */
  1774. if (!cinfo->intr_enabled) {
  1775. cinfo->nports = (int)readl(&board_ctrl->n_channel);
  1776. cinfo->intr_enabled = 1;
  1777. continue;
  1778. }
  1779. cyz_handle_cmd(cinfo);
  1780. for (port = 0; port < cinfo->nports; port++) {
  1781. info = &cinfo->ports[port];
  1782. tty = info->tty;
  1783. ch_ctrl = &(zfw_ctrl->ch_ctrl[port]);
  1784. buf_ctrl = &(zfw_ctrl->buf_ctrl[port]);
  1785. if (!info->throttle)
  1786. cyz_handle_rx(info, ch_ctrl, buf_ctrl);
  1787. cyz_handle_tx(info, ch_ctrl, buf_ctrl);
  1788. }
  1789. /* poll every 'cyz_polling_cycle' period */
  1790. expires = jiffies + cyz_polling_cycle;
  1791. }
  1792. mod_timer(&cyz_timerlist, expires);
  1793. } /* cyz_poll */
  1794. #endif /* CONFIG_CYZ_INTR */
  1795. /********** End of block of Cyclades-Z specific code *********/
  1796. /***********************************************************/
  1797. /* This is called whenever a port becomes active;
  1798. interrupts are enabled and DTR & RTS are turned on.
  1799. */
  1800. static int startup(struct cyclades_port *info)
  1801. {
  1802. struct cyclades_card *card;
  1803. unsigned long flags;
  1804. int retval = 0;
  1805. void __iomem *base_addr;
  1806. int chip, channel, index;
  1807. unsigned long page;
  1808. card = info->card;
  1809. channel = info->line - card->first_line;
  1810. page = get_zeroed_page(GFP_KERNEL);
  1811. if (!page)
  1812. return -ENOMEM;
  1813. spin_lock_irqsave(&card->card_lock, flags);
  1814. if (info->flags & ASYNC_INITIALIZED) {
  1815. free_page(page);
  1816. goto errout;
  1817. }
  1818. if (!info->type) {
  1819. if (info->tty) {
  1820. set_bit(TTY_IO_ERROR, &info->tty->flags);
  1821. }
  1822. free_page(page);
  1823. goto errout;
  1824. }
  1825. if (info->xmit_buf)
  1826. free_page(page);
  1827. else
  1828. info->xmit_buf = (unsigned char *)page;
  1829. spin_unlock_irqrestore(&card->card_lock, flags);
  1830. set_line_char(info);
  1831. if (!IS_CYC_Z(*card)) {
  1832. chip = channel >> 2;
  1833. channel &= 0x03;
  1834. index = card->bus_index;
  1835. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  1836. #ifdef CY_DEBUG_OPEN
  1837. printk(KERN_DEBUG "cyc startup card %d, chip %d, channel %d, "
  1838. "base_addr %p\n",
  1839. card, chip, channel, base_addr);
  1840. #endif
  1841. spin_lock_irqsave(&card->card_lock, flags);
  1842. cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
  1843. cy_writeb(base_addr + (CyRTPR << index),
  1844. (info->default_timeout ? info->default_timeout : 0x02));
  1845. /* 10ms rx timeout */
  1846. cyy_issue_cmd(base_addr, CyCHAN_CTL | CyENB_RCVR | CyENB_XMTR,
  1847. index);
  1848. cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
  1849. cy_writeb(base_addr + (CyMSVR1 << index), CyRTS);
  1850. cy_writeb(base_addr + (CyMSVR2 << index), CyDTR);
  1851. #ifdef CY_DEBUG_DTR
  1852. printk(KERN_DEBUG "cyc:startup raising DTR\n");
  1853. printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
  1854. readb(base_addr + (CyMSVR1 << index)),
  1855. readb(base_addr + (CyMSVR2 << index)));
  1856. #endif
  1857. cy_writeb(base_addr + (CySRER << index),
  1858. readb(base_addr + (CySRER << index)) | CyRxData);
  1859. info->flags |= ASYNC_INITIALIZED;
  1860. if (info->tty) {
  1861. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  1862. }
  1863. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1864. info->breakon = info->breakoff = 0;
  1865. memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
  1866. info->idle_stats.in_use =
  1867. info->idle_stats.recv_idle =
  1868. info->idle_stats.xmit_idle = jiffies;
  1869. spin_unlock_irqrestore(&card->card_lock, flags);
  1870. } else {
  1871. struct FIRM_ID __iomem *firm_id;
  1872. struct ZFW_CTRL __iomem *zfw_ctrl;
  1873. struct BOARD_CTRL __iomem *board_ctrl;
  1874. struct CH_CTRL __iomem *ch_ctrl;
  1875. base_addr = card->base_addr;
  1876. firm_id = base_addr + ID_ADDRESS;
  1877. if (!ISZLOADED(*card)) {
  1878. return -ENODEV;
  1879. }
  1880. zfw_ctrl = card->base_addr +
  1881. (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  1882. board_ctrl = &zfw_ctrl->board_ctrl;
  1883. ch_ctrl = zfw_ctrl->ch_ctrl;
  1884. #ifdef CY_DEBUG_OPEN
  1885. printk(KERN_DEBUG "cyc startup Z card %d, channel %d, "
  1886. "base_addr %p\n", card, channel, base_addr);
  1887. #endif
  1888. spin_lock_irqsave(&card->card_lock, flags);
  1889. cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
  1890. #ifdef Z_WAKE
  1891. #ifdef CONFIG_CYZ_INTR
  1892. cy_writel(&ch_ctrl[channel].intr_enable,
  1893. C_IN_TXBEMPTY | C_IN_TXLOWWM | C_IN_RXHIWM |
  1894. C_IN_RXNNDT | C_IN_IOCTLW | C_IN_MDCD);
  1895. #else
  1896. cy_writel(&ch_ctrl[channel].intr_enable,
  1897. C_IN_IOCTLW | C_IN_MDCD);
  1898. #endif /* CONFIG_CYZ_INTR */
  1899. #else
  1900. #ifdef CONFIG_CYZ_INTR
  1901. cy_writel(&ch_ctrl[channel].intr_enable,
  1902. C_IN_TXBEMPTY | C_IN_TXLOWWM | C_IN_RXHIWM |
  1903. C_IN_RXNNDT | C_IN_MDCD);
  1904. #else
  1905. cy_writel(&ch_ctrl[channel].intr_enable, C_IN_MDCD);
  1906. #endif /* CONFIG_CYZ_INTR */
  1907. #endif /* Z_WAKE */
  1908. retval = cyz_issue_cmd(card, channel, C_CM_IOCTL, 0L);
  1909. if (retval != 0) {
  1910. printk(KERN_ERR "cyc:startup(1) retval on ttyC%d was "
  1911. "%x\n", info->line, retval);
  1912. }
  1913. /* Flush RX buffers before raising DTR and RTS */
  1914. retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_RX, 0L);
  1915. if (retval != 0) {
  1916. printk(KERN_ERR "cyc:startup(2) retval on ttyC%d was "
  1917. "%x\n", info->line, retval);
  1918. }
  1919. /* set timeout !!! */
  1920. /* set RTS and DTR !!! */
  1921. cy_writel(&ch_ctrl[channel].rs_control,
  1922. readl(&ch_ctrl[channel].rs_control) | C_RS_RTS |
  1923. C_RS_DTR);
  1924. retval = cyz_issue_cmd(card, channel, C_CM_IOCTLM, 0L);
  1925. if (retval != 0) {
  1926. printk(KERN_ERR "cyc:startup(3) retval on ttyC%d was "
  1927. "%x\n", info->line, retval);
  1928. }
  1929. #ifdef CY_DEBUG_DTR
  1930. printk(KERN_DEBUG "cyc:startup raising Z DTR\n");
  1931. #endif
  1932. /* enable send, recv, modem !!! */
  1933. info->flags |= ASYNC_INITIALIZED;
  1934. if (info->tty) {
  1935. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  1936. }
  1937. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1938. info->breakon = info->breakoff = 0;
  1939. memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
  1940. info->idle_stats.in_use =
  1941. info->idle_stats.recv_idle =
  1942. info->idle_stats.xmit_idle = jiffies;
  1943. spin_unlock_irqrestore(&card->card_lock, flags);
  1944. }
  1945. #ifdef CY_DEBUG_OPEN
  1946. printk(KERN_DEBUG "cyc startup done\n");
  1947. #endif
  1948. return 0;
  1949. errout:
  1950. spin_unlock_irqrestore(&card->card_lock, flags);
  1951. return retval;
  1952. } /* startup */
  1953. static void start_xmit(struct cyclades_port *info)
  1954. {
  1955. struct cyclades_card *card;
  1956. unsigned long flags;
  1957. void __iomem *base_addr;
  1958. int chip, channel, index;
  1959. card = info->card;
  1960. channel = info->line - card->first_line;
  1961. if (!IS_CYC_Z(*card)) {
  1962. chip = channel >> 2;
  1963. channel &= 0x03;
  1964. index = card->bus_index;
  1965. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  1966. spin_lock_irqsave(&card->card_lock, flags);
  1967. cy_writeb(base_addr + (CyCAR << index), channel);
  1968. cy_writeb(base_addr + (CySRER << index),
  1969. readb(base_addr + (CySRER << index)) | CyTxRdy);
  1970. spin_unlock_irqrestore(&card->card_lock, flags);
  1971. } else {
  1972. #ifdef CONFIG_CYZ_INTR
  1973. int retval;
  1974. spin_lock_irqsave(&card->card_lock, flags);
  1975. retval = cyz_issue_cmd(card, channel, C_CM_INTBACK, 0L);
  1976. if (retval != 0) {
  1977. printk(KERN_ERR "cyc:start_xmit retval on ttyC%d was "
  1978. "%x\n", info->line, retval);
  1979. }
  1980. spin_unlock_irqrestore(&card->card_lock, flags);
  1981. #else /* CONFIG_CYZ_INTR */
  1982. /* Don't have to do anything at this time */
  1983. #endif /* CONFIG_CYZ_INTR */
  1984. }
  1985. } /* start_xmit */
  1986. /*
  1987. * This routine shuts down a serial port; interrupts are disabled,
  1988. * and DTR is dropped if the hangup on close termio flag is on.
  1989. */
  1990. static void shutdown(struct cyclades_port *info)
  1991. {
  1992. struct cyclades_card *card;
  1993. unsigned long flags;
  1994. void __iomem *base_addr;
  1995. int chip, channel, index;
  1996. if (!(info->flags & ASYNC_INITIALIZED)) {
  1997. return;
  1998. }
  1999. card = info->card;
  2000. channel = info->line - card->first_line;
  2001. if (!IS_CYC_Z(*card)) {
  2002. chip = channel >> 2;
  2003. channel &= 0x03;
  2004. index = card->bus_index;
  2005. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  2006. #ifdef CY_DEBUG_OPEN
  2007. printk(KERN_DEBUG "cyc shutdown Y card %d, chip %d, "
  2008. "channel %d, base_addr %p\n",
  2009. card, chip, channel, base_addr);
  2010. #endif
  2011. spin_lock_irqsave(&card->card_lock, flags);
  2012. /* Clear delta_msr_wait queue to avoid mem leaks. */
  2013. wake_up_interruptible(&info->delta_msr_wait);
  2014. if (info->xmit_buf) {
  2015. unsigned char *temp;
  2016. temp = info->xmit_buf;
  2017. info->xmit_buf = NULL;
  2018. free_page((unsigned long)temp);
  2019. }
  2020. cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
  2021. if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
  2022. cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS);
  2023. cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR);
  2024. #ifdef CY_DEBUG_DTR
  2025. printk(KERN_DEBUG "cyc shutdown dropping DTR\n");
  2026. printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
  2027. readb(base_addr + (CyMSVR1 << index)),
  2028. readb(base_addr + (CyMSVR2 << index)));
  2029. #endif
  2030. }
  2031. cyy_issue_cmd(base_addr, CyCHAN_CTL | CyDIS_RCVR, index);
  2032. /* it may be appropriate to clear _XMIT at
  2033. some later date (after testing)!!! */
  2034. if (info->tty) {
  2035. set_bit(TTY_IO_ERROR, &info->tty->flags);
  2036. }
  2037. info->flags &= ~ASYNC_INITIALIZED;
  2038. spin_unlock_irqrestore(&card->card_lock, flags);
  2039. } else {
  2040. struct FIRM_ID __iomem *firm_id;
  2041. struct ZFW_CTRL __iomem *zfw_ctrl;
  2042. struct BOARD_CTRL __iomem *board_ctrl;
  2043. struct CH_CTRL __iomem *ch_ctrl;
  2044. int retval;
  2045. base_addr = card->base_addr;
  2046. #ifdef CY_DEBUG_OPEN
  2047. printk(KERN_DEBUG "cyc shutdown Z card %d, channel %d, "
  2048. "base_addr %p\n", card, channel, base_addr);
  2049. #endif
  2050. firm_id = base_addr + ID_ADDRESS;
  2051. if (!ISZLOADED(*card)) {
  2052. return;
  2053. }
  2054. zfw_ctrl = card->base_addr +
  2055. (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  2056. board_ctrl = &zfw_ctrl->board_ctrl;
  2057. ch_ctrl = zfw_ctrl->ch_ctrl;
  2058. spin_lock_irqsave(&card->card_lock, flags);
  2059. if (info->xmit_buf) {
  2060. unsigned char *temp;
  2061. temp = info->xmit_buf;
  2062. info->xmit_buf = NULL;
  2063. free_page((unsigned long)temp);
  2064. }
  2065. if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
  2066. cy_writel(&ch_ctrl[channel].rs_control,
  2067. (__u32)(readl(&ch_ctrl[channel].rs_control) &
  2068. ~(C_RS_RTS | C_RS_DTR)));
  2069. retval = cyz_issue_cmd(info->card, channel,
  2070. C_CM_IOCTLM, 0L);
  2071. if (retval != 0) {
  2072. printk(KERN_ERR"cyc:shutdown retval on ttyC%d "
  2073. "was %x\n", info->line, retval);
  2074. }
  2075. #ifdef CY_DEBUG_DTR
  2076. printk(KERN_DEBUG "cyc:shutdown dropping Z DTR\n");
  2077. #endif
  2078. }
  2079. if (info->tty) {
  2080. set_bit(TTY_IO_ERROR, &info->tty->flags);
  2081. }
  2082. info->flags &= ~ASYNC_INITIALIZED;
  2083. spin_unlock_irqrestore(&card->card_lock, flags);
  2084. }
  2085. #ifdef CY_DEBUG_OPEN
  2086. printk(KERN_DEBUG "cyc shutdown done\n");
  2087. #endif
  2088. } /* shutdown */
  2089. /*
  2090. * ------------------------------------------------------------
  2091. * cy_open() and friends
  2092. * ------------------------------------------------------------
  2093. */
  2094. static int
  2095. block_til_ready(struct tty_struct *tty, struct file *filp,
  2096. struct cyclades_port *info)
  2097. {
  2098. DECLARE_WAITQUEUE(wait, current);
  2099. struct cyclades_card *cinfo;
  2100. unsigned long flags;
  2101. int chip, channel, index;
  2102. int retval;
  2103. void __iomem *base_addr;
  2104. cinfo = info->card;
  2105. channel = info->line - cinfo->first_line;
  2106. /*
  2107. * If the device is in the middle of being closed, then block
  2108. * until it's done, and then try again.
  2109. */
  2110. if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
  2111. wait_event_interruptible(info->close_wait,
  2112. !(info->flags & ASYNC_CLOSING));
  2113. return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
  2114. }
  2115. /*
  2116. * If non-blocking mode is set, then make the check up front
  2117. * and then exit.
  2118. */
  2119. if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
  2120. info->flags |= ASYNC_NORMAL_ACTIVE;
  2121. return 0;
  2122. }
  2123. /*
  2124. * Block waiting for the carrier detect and the line to become
  2125. * free (i.e., not in use by the callout). While we are in
  2126. * this loop, info->count is dropped by one, so that
  2127. * cy_close() knows when to free things. We restore it upon
  2128. * exit, either normal or abnormal.
  2129. */
  2130. retval = 0;
  2131. add_wait_queue(&info->open_wait, &wait);
  2132. #ifdef CY_DEBUG_OPEN
  2133. printk(KERN_DEBUG "cyc block_til_ready before block: ttyC%d, "
  2134. "count = %d\n", info->line, info->count);
  2135. #endif
  2136. spin_lock_irqsave(&cinfo->card_lock, flags);
  2137. if (!tty_hung_up_p(filp))
  2138. info->count--;
  2139. spin_unlock_irqrestore(&cinfo->card_lock, flags);
  2140. #ifdef CY_DEBUG_COUNT
  2141. printk(KERN_DEBUG "cyc block_til_ready: (%d): decrementing count to "
  2142. "%d\n", current->pid, info->count);
  2143. #endif
  2144. info->blocked_open++;
  2145. if (!IS_CYC_Z(*cinfo)) {
  2146. chip = channel >> 2;
  2147. channel &= 0x03;
  2148. index = cinfo->bus_index;
  2149. base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
  2150. while (1) {
  2151. spin_lock_irqsave(&cinfo->card_lock, flags);
  2152. if ((tty->termios->c_cflag & CBAUD)) {
  2153. cy_writeb(base_addr + (CyCAR << index),
  2154. (u_char) channel);
  2155. cy_writeb(base_addr + (CyMSVR1 << index),
  2156. CyRTS);
  2157. cy_writeb(base_addr + (CyMSVR2 << index),
  2158. CyDTR);
  2159. #ifdef CY_DEBUG_DTR
  2160. printk(KERN_DEBUG "cyc:block_til_ready raising "
  2161. "DTR\n");
  2162. printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
  2163. readb(base_addr + (CyMSVR1 << index)),
  2164. readb(base_addr + (CyMSVR2 << index)));
  2165. #endif
  2166. }
  2167. spin_unlock_irqrestore(&cinfo->card_lock, flags);
  2168. set_current_state(TASK_INTERRUPTIBLE);
  2169. if (tty_hung_up_p(filp) ||
  2170. !(info->flags & ASYNC_INITIALIZED)) {
  2171. retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
  2172. -EAGAIN : -ERESTARTSYS);
  2173. break;
  2174. }
  2175. spin_lock_irqsave(&cinfo->card_lock, flags);
  2176. cy_writeb(base_addr + (CyCAR << index),
  2177. (u_char) channel);
  2178. if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
  2179. (readb(base_addr +
  2180. (CyMSVR1 << index)) & CyDCD))) {
  2181. spin_unlock_irqrestore(&cinfo->card_lock, flags);
  2182. break;
  2183. }
  2184. spin_unlock_irqrestore(&cinfo->card_lock, flags);
  2185. if (signal_pending(current)) {
  2186. retval = -ERESTARTSYS;
  2187. break;
  2188. }
  2189. #ifdef CY_DEBUG_OPEN
  2190. printk(KERN_DEBUG "cyc block_til_ready blocking: "
  2191. "ttyC%d, count = %d\n",
  2192. info->line, info->count);
  2193. #endif
  2194. schedule();
  2195. }
  2196. } else {
  2197. struct FIRM_ID __iomem *firm_id;
  2198. struct ZFW_CTRL __iomem *zfw_ctrl;
  2199. struct BOARD_CTRL __iomem *board_ctrl;
  2200. struct CH_CTRL __iomem *ch_ctrl;
  2201. base_addr = cinfo->base_addr;
  2202. firm_id = base_addr + ID_ADDRESS;
  2203. if (!ISZLOADED(*cinfo)) {
  2204. __set_current_state(TASK_RUNNING);
  2205. remove_wait_queue(&info->open_wait, &wait);
  2206. return -EINVAL;
  2207. }
  2208. zfw_ctrl = base_addr + (readl(&firm_id->zfwctrl_addr)& 0xfffff);
  2209. board_ctrl = &zfw_ctrl->board_ctrl;
  2210. ch_ctrl = zfw_ctrl->ch_ctrl;
  2211. while (1) {
  2212. if ((tty->termios->c_cflag & CBAUD)) {
  2213. cy_writel(&ch_ctrl[channel].rs_control,
  2214. readl(&ch_ctrl[channel].rs_control) |
  2215. C_RS_RTS | C_RS_DTR);
  2216. retval = cyz_issue_cmd(cinfo,
  2217. channel, C_CM_IOCTLM, 0L);
  2218. if (retval != 0) {
  2219. printk(KERN_ERR "cyc:block_til_ready "
  2220. "retval on ttyC%d was %x\n",
  2221. info->line, retval);
  2222. }
  2223. #ifdef CY_DEBUG_DTR
  2224. printk(KERN_DEBUG "cyc:block_til_ready raising "
  2225. "Z DTR\n");
  2226. #endif
  2227. }
  2228. set_current_state(TASK_INTERRUPTIBLE);
  2229. if (tty_hung_up_p(filp) ||
  2230. !(info->flags & ASYNC_INITIALIZED)) {
  2231. retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
  2232. -EAGAIN : -ERESTARTSYS);
  2233. break;
  2234. }
  2235. if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
  2236. (readl(&ch_ctrl[channel].rs_status) &
  2237. C_RS_DCD))) {
  2238. break;
  2239. }
  2240. if (signal_pending(current)) {
  2241. retval = -ERESTARTSYS;
  2242. break;
  2243. }
  2244. #ifdef CY_DEBUG_OPEN
  2245. printk(KERN_DEBUG "cyc block_til_ready blocking: "
  2246. "ttyC%d, count = %d\n",
  2247. info->line, info->count);
  2248. #endif
  2249. schedule();
  2250. }
  2251. }
  2252. __set_current_state(TASK_RUNNING);
  2253. remove_wait_queue(&info->open_wait, &wait);
  2254. if (!tty_hung_up_p(filp)) {
  2255. info->count++;
  2256. #ifdef CY_DEBUG_COUNT
  2257. printk(KERN_DEBUG "cyc:block_til_ready (%d): incrementing "
  2258. "count to %d\n", current->pid, info->count);
  2259. #endif
  2260. }
  2261. info->blocked_open--;
  2262. #ifdef CY_DEBUG_OPEN
  2263. printk(KERN_DEBUG "cyc:block_til_ready after blocking: ttyC%d, "
  2264. "count = %d\n", info->line, info->count);
  2265. #endif
  2266. if (retval)
  2267. return retval;
  2268. info->flags |= ASYNC_NORMAL_ACTIVE;
  2269. return 0;
  2270. } /* block_til_ready */
  2271. /*
  2272. * This routine is called whenever a serial port is opened. It
  2273. * performs the serial-specific initialization for the tty structure.
  2274. */
  2275. static int cy_open(struct tty_struct *tty, struct file *filp)
  2276. {
  2277. struct cyclades_port *info;
  2278. unsigned int i;
  2279. int retval, line;
  2280. line = tty->index;
  2281. if ((line < 0) || (NR_PORTS <= line)) {
  2282. return -ENODEV;
  2283. }
  2284. for (i = 0; i < NR_CARDS; i++)
  2285. if (line < cy_card[i].first_line + cy_card[i].nports &&
  2286. line >= cy_card[i].first_line)
  2287. break;
  2288. if (i >= NR_CARDS)
  2289. return -ENODEV;
  2290. info = &cy_card[i].ports[line - cy_card[i].first_line];
  2291. if (info->line < 0) {
  2292. return -ENODEV;
  2293. }
  2294. /* If the card's firmware hasn't been loaded,
  2295. treat it as absent from the system. This
  2296. will make the user pay attention.
  2297. */
  2298. if (IS_CYC_Z(*info->card)) {
  2299. struct cyclades_card *cinfo = info->card;
  2300. struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
  2301. if (!ISZLOADED(*cinfo)) {
  2302. if (((ZE_V1 == readl(&((struct RUNTIME_9060 __iomem *)
  2303. (cinfo->ctl_addr))->mail_box_0)) &&
  2304. Z_FPGA_CHECK(*cinfo)) &&
  2305. (ZFIRM_HLT == readl(
  2306. &firm_id->signature))) {
  2307. printk(KERN_ERR "cyc:Cyclades-Z Error: you "
  2308. "need an external power supply for "
  2309. "this number of ports.\nFirmware "
  2310. "halted.\n");
  2311. } else {
  2312. printk(KERN_ERR "cyc:Cyclades-Z firmware not "
  2313. "yet loaded\n");
  2314. }
  2315. return -ENODEV;
  2316. }
  2317. #ifdef CONFIG_CYZ_INTR
  2318. else {
  2319. /* In case this Z board is operating in interrupt mode, its
  2320. interrupts should be enabled as soon as the first open
  2321. happens to one of its ports. */
  2322. if (!cinfo->intr_enabled) {
  2323. struct ZFW_CTRL __iomem *zfw_ctrl;
  2324. struct BOARD_CTRL __iomem *board_ctrl;
  2325. zfw_ctrl = cinfo->base_addr +
  2326. (readl(&firm_id->zfwctrl_addr) &
  2327. 0xfffff);
  2328. board_ctrl = &zfw_ctrl->board_ctrl;
  2329. /* Enable interrupts on the PLX chip */
  2330. cy_writew(cinfo->ctl_addr + 0x68,
  2331. readw(cinfo->ctl_addr + 0x68) | 0x0900);
  2332. /* Enable interrupts on the FW */
  2333. retval = cyz_issue_cmd(cinfo, 0,
  2334. C_CM_IRQ_ENBL, 0L);
  2335. if (retval != 0) {
  2336. printk(KERN_ERR "cyc:IRQ enable retval "
  2337. "was %x\n", retval);
  2338. }
  2339. cinfo->nports =
  2340. (int)readl(&board_ctrl->n_channel);
  2341. cinfo->intr_enabled = 1;
  2342. }
  2343. }
  2344. #endif /* CONFIG_CYZ_INTR */
  2345. /* Make sure this Z port really exists in hardware */
  2346. if (info->line > (cinfo->first_line + cinfo->nports - 1))
  2347. return -ENODEV;
  2348. }
  2349. #ifdef CY_DEBUG_OTHER
  2350. printk(KERN_DEBUG "cyc:cy_open ttyC%d\n", info->line);
  2351. #endif
  2352. tty->driver_data = info;
  2353. info->tty = tty;
  2354. if (serial_paranoia_check(info, tty->name, "cy_open")) {
  2355. return -ENODEV;
  2356. }
  2357. #ifdef CY_DEBUG_OPEN
  2358. printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
  2359. info->count);
  2360. #endif
  2361. info->count++;
  2362. #ifdef CY_DEBUG_COUNT
  2363. printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
  2364. current->pid, info->count);
  2365. #endif
  2366. /*
  2367. * If the port is the middle of closing, bail out now
  2368. */
  2369. if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
  2370. wait_event_interruptible(info->close_wait,
  2371. !(info->flags & ASYNC_CLOSING));
  2372. return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
  2373. }
  2374. /*
  2375. * Start up serial port
  2376. */
  2377. retval = startup(info);
  2378. if (retval) {
  2379. return retval;
  2380. }
  2381. retval = block_til_ready(tty, filp, info);
  2382. if (retval) {
  2383. #ifdef CY_DEBUG_OPEN
  2384. printk(KERN_DEBUG "cyc:cy_open returning after block_til_ready "
  2385. "with %d\n", retval);
  2386. #endif
  2387. return retval;
  2388. }
  2389. info->throttle = 0;
  2390. #ifdef CY_DEBUG_OPEN
  2391. printk(KERN_DEBUG "cyc:cy_open done\n");
  2392. #endif
  2393. return 0;
  2394. } /* cy_open */
  2395. /*
  2396. * cy_wait_until_sent() --- wait until the transmitter is empty
  2397. */
  2398. static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
  2399. {
  2400. struct cyclades_card *card;
  2401. struct cyclades_port *info = tty->driver_data;
  2402. void __iomem *base_addr;
  2403. int chip, channel, index;
  2404. unsigned long orig_jiffies;
  2405. int char_time;
  2406. if (serial_paranoia_check(info, tty->name, "cy_wait_until_sent"))
  2407. return;
  2408. if (info->xmit_fifo_size == 0)
  2409. return; /* Just in case.... */
  2410. orig_jiffies = jiffies;
  2411. /*
  2412. * Set the check interval to be 1/5 of the estimated time to
  2413. * send a single character, and make it at least 1. The check
  2414. * interval should also be less than the timeout.
  2415. *
  2416. * Note: we have to use pretty tight timings here to satisfy
  2417. * the NIST-PCTS.
  2418. */
  2419. char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
  2420. char_time = char_time / 5;
  2421. if (char_time <= 0)
  2422. char_time = 1;
  2423. if (timeout < 0)
  2424. timeout = 0;
  2425. if (timeout)
  2426. char_time = min(char_time, timeout);
  2427. /*
  2428. * If the transmitter hasn't cleared in twice the approximate
  2429. * amount of time to send the entire FIFO, it probably won't
  2430. * ever clear. This assumes the UART isn't doing flow
  2431. * control, which is currently the case. Hence, if it ever
  2432. * takes longer than info->timeout, this is probably due to a
  2433. * UART bug of some kind. So, we clamp the timeout parameter at
  2434. * 2*info->timeout.
  2435. */
  2436. if (!timeout || timeout > 2 * info->timeout)
  2437. timeout = 2 * info->timeout;
  2438. #ifdef CY_DEBUG_WAIT_UNTIL_SENT
  2439. printk(KERN_DEBUG "In cy_wait_until_sent(%d) check=%d, jiff=%lu...",
  2440. timeout, char_time, jiffies);
  2441. #endif
  2442. card = info->card;
  2443. channel = (info->line) - (card->first_line);
  2444. if (!IS_CYC_Z(*card)) {
  2445. chip = channel >> 2;
  2446. channel &= 0x03;
  2447. index = card->bus_index;
  2448. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  2449. while (readb(base_addr + (CySRER << index)) & CyTxRdy) {
  2450. #ifdef CY_DEBUG_WAIT_UNTIL_SENT
  2451. printk(KERN_DEBUG "Not clean (jiff=%lu)...", jiffies);
  2452. #endif
  2453. if (msleep_interruptible(jiffies_to_msecs(char_time)))
  2454. break;
  2455. if (timeout && time_after(jiffies, orig_jiffies +
  2456. timeout))
  2457. break;
  2458. }
  2459. }
  2460. /* Run one more char cycle */
  2461. msleep_interruptible(jiffies_to_msecs(char_time * 5));
  2462. #ifdef CY_DEBUG_WAIT_UNTIL_SENT
  2463. printk(KERN_DEBUG "Clean (jiff=%lu)...done\n", jiffies);
  2464. #endif
  2465. }
  2466. /*
  2467. * This routine is called when a particular tty device is closed.
  2468. */
  2469. static void cy_close(struct tty_struct *tty, struct file *filp)
  2470. {
  2471. struct cyclades_port *info = tty->driver_data;
  2472. struct cyclades_card *card;
  2473. unsigned long flags;
  2474. #ifdef CY_DEBUG_OTHER
  2475. printk(KERN_DEBUG "cyc:cy_close ttyC%d\n", info->line);
  2476. #endif
  2477. if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
  2478. return;
  2479. }
  2480. card = info->card;
  2481. spin_lock_irqsave(&card->card_lock, flags);
  2482. /* If the TTY is being hung up, nothing to do */
  2483. if (tty_hung_up_p(filp)) {
  2484. spin_unlock_irqrestore(&card->card_lock, flags);
  2485. return;
  2486. }
  2487. #ifdef CY_DEBUG_OPEN
  2488. printk(KERN_DEBUG "cyc:cy_close ttyC%d, count = %d\n", info->line,
  2489. info->count);
  2490. #endif
  2491. if ((tty->count == 1) && (info->count != 1)) {
  2492. /*
  2493. * Uh, oh. tty->count is 1, which means that the tty
  2494. * structure will be freed. Info->count should always
  2495. * be one in these conditions. If it's greater than
  2496. * one, we've got real problems, since it means the
  2497. * serial port won't be shutdown.
  2498. */
  2499. printk(KERN_ERR "cyc:cy_close: bad serial port count; "
  2500. "tty->count is 1, info->count is %d\n", info->count);
  2501. info->count = 1;
  2502. }
  2503. #ifdef CY_DEBUG_COUNT
  2504. printk(KERN_DEBUG "cyc:cy_close at (%d): decrementing count to %d\n",
  2505. current->pid, info->count - 1);
  2506. #endif
  2507. if (--info->count < 0) {
  2508. #ifdef CY_DEBUG_COUNT
  2509. printk(KERN_DEBUG "cyc:cyc_close setting count to 0\n");
  2510. #endif
  2511. info->count = 0;
  2512. }
  2513. if (info->count) {
  2514. spin_unlock_irqrestore(&card->card_lock, flags);
  2515. return;
  2516. }
  2517. info->flags |= ASYNC_CLOSING;
  2518. /*
  2519. * Now we wait for the transmit buffer to clear; and we notify
  2520. * the line discipline to only process XON/XOFF characters.
  2521. */
  2522. tty->closing = 1;
  2523. spin_unlock_irqrestore(&card->card_lock, flags);
  2524. if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
  2525. tty_wait_until_sent(tty, info->closing_wait);
  2526. }
  2527. spin_lock_irqsave(&card->card_lock, flags);
  2528. if (!IS_CYC_Z(*card)) {
  2529. int channel = info->line - card->first_line;
  2530. int index = card->bus_index;
  2531. void __iomem *base_addr = card->base_addr +
  2532. (cy_chip_offset[channel >> 2] << index);
  2533. /* Stop accepting input */
  2534. channel &= 0x03;
  2535. cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
  2536. cy_writeb(base_addr + (CySRER << index),
  2537. readb(base_addr + (CySRER << index)) & ~CyRxData);
  2538. if (info->flags & ASYNC_INITIALIZED) {
  2539. /* Waiting for on-board buffers to be empty before closing
  2540. the port */
  2541. spin_unlock_irqrestore(&card->card_lock, flags);
  2542. cy_wait_until_sent(tty, info->timeout);
  2543. spin_lock_irqsave(&card->card_lock, flags);
  2544. }
  2545. } else {
  2546. #ifdef Z_WAKE
  2547. /* Waiting for on-board buffers to be empty before closing the port */
  2548. void __iomem *base_addr = card->base_addr;
  2549. struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS;
  2550. struct ZFW_CTRL __iomem *zfw_ctrl =
  2551. base_addr + (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  2552. struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl;
  2553. int channel = info->line - card->first_line;
  2554. int retval;
  2555. if (readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) {
  2556. retval = cyz_issue_cmd(card, channel, C_CM_IOCTLW, 0L);
  2557. if (retval != 0) {
  2558. printk(KERN_DEBUG "cyc:cy_close retval on "
  2559. "ttyC%d was %x\n", info->line, retval);
  2560. }
  2561. spin_unlock_irqrestore(&card->card_lock, flags);
  2562. wait_for_completion_interruptible(&info->shutdown_wait);
  2563. spin_lock_irqsave(&card->card_lock, flags);
  2564. }
  2565. #endif
  2566. }
  2567. spin_unlock_irqrestore(&card->card_lock, flags);
  2568. shutdown(info);
  2569. if (tty->driver->flush_buffer)
  2570. tty->driver->flush_buffer(tty);
  2571. tty_ldisc_flush(tty);
  2572. spin_lock_irqsave(&card->card_lock, flags);
  2573. tty->closing = 0;
  2574. info->event = 0;
  2575. info->tty = NULL;
  2576. if (info->blocked_open) {
  2577. spin_unlock_irqrestore(&card->card_lock, flags);
  2578. if (info->close_delay) {
  2579. msleep_interruptible(jiffies_to_msecs
  2580. (info->close_delay));
  2581. }
  2582. wake_up_interruptible(&info->open_wait);
  2583. spin_lock_irqsave(&card->card_lock, flags);
  2584. }
  2585. info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
  2586. wake_up_interruptible(&info->close_wait);
  2587. #ifdef CY_DEBUG_OTHER
  2588. printk(KERN_DEBUG "cyc:cy_close done\n");
  2589. #endif
  2590. spin_unlock_irqrestore(&card->card_lock, flags);
  2591. } /* cy_close */
  2592. /* This routine gets called when tty_write has put something into
  2593. * the write_queue. The characters may come from user space or
  2594. * kernel space.
  2595. *
  2596. * This routine will return the number of characters actually
  2597. * accepted for writing.
  2598. *
  2599. * If the port is not already transmitting stuff, start it off by
  2600. * enabling interrupts. The interrupt service routine will then
  2601. * ensure that the characters are sent.
  2602. * If the port is already active, there is no need to kick it.
  2603. *
  2604. */
  2605. static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
  2606. {
  2607. struct cyclades_port *info = tty->driver_data;
  2608. unsigned long flags;
  2609. int c, ret = 0;
  2610. #ifdef CY_DEBUG_IO
  2611. printk(KERN_DEBUG "cyc:cy_write ttyC%d\n", info->line);
  2612. #endif
  2613. if (serial_paranoia_check(info, tty->name, "cy_write")) {
  2614. return 0;
  2615. }
  2616. if (!info->xmit_buf)
  2617. return 0;
  2618. spin_lock_irqsave(&info->card->card_lock, flags);
  2619. while (1) {
  2620. c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
  2621. (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
  2622. if (c <= 0)
  2623. break;
  2624. memcpy(info->xmit_buf + info->xmit_head, buf, c);
  2625. info->xmit_head = (info->xmit_head + c) &
  2626. (SERIAL_XMIT_SIZE - 1);
  2627. info->xmit_cnt += c;
  2628. buf += c;
  2629. count -= c;
  2630. ret += c;
  2631. }
  2632. spin_unlock_irqrestore(&info->card->card_lock, flags);
  2633. info->idle_stats.xmit_bytes += ret;
  2634. info->idle_stats.xmit_idle = jiffies;
  2635. if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
  2636. start_xmit(info);
  2637. }
  2638. return ret;
  2639. } /* cy_write */
  2640. /*
  2641. * This routine is called by the kernel to write a single
  2642. * character to the tty device. If the kernel uses this routine,
  2643. * it must call the flush_chars() routine (if defined) when it is
  2644. * done stuffing characters into the driver. If there is no room
  2645. * in the queue, the character is ignored.
  2646. */
  2647. static void cy_put_char(struct tty_struct *tty, unsigned char ch)
  2648. {
  2649. struct cyclades_port *info = tty->driver_data;
  2650. unsigned long flags;
  2651. #ifdef CY_DEBUG_IO
  2652. printk(KERN_DEBUG "cyc:cy_put_char ttyC%d\n", info->line);
  2653. #endif
  2654. if (serial_paranoia_check(info, tty->name, "cy_put_char"))
  2655. return;
  2656. if (!info->xmit_buf)
  2657. return;
  2658. spin_lock_irqsave(&info->card->card_lock, flags);
  2659. if (info->xmit_cnt >= (int)(SERIAL_XMIT_SIZE - 1)) {
  2660. spin_unlock_irqrestore(&info->card->card_lock, flags);
  2661. return;
  2662. }
  2663. info->xmit_buf[info->xmit_head++] = ch;
  2664. info->xmit_head &= SERIAL_XMIT_SIZE - 1;
  2665. info->xmit_cnt++;
  2666. info->idle_stats.xmit_bytes++;
  2667. info->idle_stats.xmit_idle = jiffies;
  2668. spin_unlock_irqrestore(&info->card->card_lock, flags);
  2669. } /* cy_put_char */
  2670. /*
  2671. * This routine is called by the kernel after it has written a
  2672. * series of characters to the tty device using put_char().
  2673. */
  2674. static void cy_flush_chars(struct tty_struct *tty)
  2675. {
  2676. struct cyclades_port *info = tty->driver_data;
  2677. #ifdef CY_DEBUG_IO
  2678. printk(KERN_DEBUG "cyc:cy_flush_chars ttyC%d\n", info->line);
  2679. #endif
  2680. if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
  2681. return;
  2682. if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
  2683. !info->xmit_buf)
  2684. return;
  2685. start_xmit(info);
  2686. } /* cy_flush_chars */
  2687. /*
  2688. * This routine returns the numbers of characters the tty driver
  2689. * will accept for queuing to be written. This number is subject
  2690. * to change as output buffers get emptied, or if the output flow
  2691. * control is activated.
  2692. */
  2693. static int cy_write_room(struct tty_struct *tty)
  2694. {
  2695. struct cyclades_port *info = tty->driver_data;
  2696. int ret;
  2697. #ifdef CY_DEBUG_IO
  2698. printk(KERN_DEBUG "cyc:cy_write_room ttyC%d\n", info->line);
  2699. #endif
  2700. if (serial_paranoia_check(info, tty->name, "cy_write_room"))
  2701. return 0;
  2702. ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
  2703. if (ret < 0)
  2704. ret = 0;
  2705. return ret;
  2706. } /* cy_write_room */
  2707. static int cy_chars_in_buffer(struct tty_struct *tty)
  2708. {
  2709. struct cyclades_card *card;
  2710. struct cyclades_port *info = tty->driver_data;
  2711. int channel;
  2712. if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
  2713. return 0;
  2714. card = info->card;
  2715. channel = (info->line) - (card->first_line);
  2716. #ifdef Z_EXT_CHARS_IN_BUFFER
  2717. if (!IS_CYC_Z(cy_card[card])) {
  2718. #endif /* Z_EXT_CHARS_IN_BUFFER */
  2719. #ifdef CY_DEBUG_IO
  2720. printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n",
  2721. info->line, info->xmit_cnt);
  2722. #endif
  2723. return info->xmit_cnt;
  2724. #ifdef Z_EXT_CHARS_IN_BUFFER
  2725. } else {
  2726. static struct FIRM_ID *firm_id;
  2727. static struct ZFW_CTRL *zfw_ctrl;
  2728. static struct CH_CTRL *ch_ctrl;
  2729. static struct BUF_CTRL *buf_ctrl;
  2730. int char_count;
  2731. __u32 tx_put, tx_get, tx_bufsize;
  2732. firm_id = card->base_addr + ID_ADDRESS;
  2733. zfw_ctrl = card->base_addr +
  2734. (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  2735. ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
  2736. buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
  2737. tx_get = readl(&buf_ctrl->tx_get);
  2738. tx_put = readl(&buf_ctrl->tx_put);
  2739. tx_bufsize = readl(&buf_ctrl->tx_bufsize);
  2740. if (tx_put >= tx_get)
  2741. char_count = tx_put - tx_get;
  2742. else
  2743. char_count = tx_put - tx_get + tx_bufsize;
  2744. #ifdef CY_DEBUG_IO
  2745. printk(KERN_DEBUG "cyc:cy_chars_in_buffer ttyC%d %d\n",
  2746. info->line, info->xmit_cnt + char_count);
  2747. #endif
  2748. return info->xmit_cnt + char_count;
  2749. }
  2750. #endif /* Z_EXT_CHARS_IN_BUFFER */
  2751. } /* cy_chars_in_buffer */
  2752. /*
  2753. * ------------------------------------------------------------
  2754. * cy_ioctl() and friends
  2755. * ------------------------------------------------------------
  2756. */
  2757. static void cyy_baud_calc(struct cyclades_port *info, __u32 baud)
  2758. {
  2759. int co, co_val, bpr;
  2760. __u32 cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 :
  2761. 25000000);
  2762. if (baud == 0) {
  2763. info->tbpr = info->tco = info->rbpr = info->rco = 0;
  2764. return;
  2765. }
  2766. /* determine which prescaler to use */
  2767. for (co = 4, co_val = 2048; co; co--, co_val >>= 2) {
  2768. if (cy_clock / co_val / baud > 63)
  2769. break;
  2770. }
  2771. bpr = (cy_clock / co_val * 2 / baud + 1) / 2;
  2772. if (bpr > 255)
  2773. bpr = 255;
  2774. info->tbpr = info->rbpr = bpr;
  2775. info->tco = info->rco = co;
  2776. }
  2777. /*
  2778. * This routine finds or computes the various line characteristics.
  2779. * It used to be called config_setup
  2780. */
  2781. static void set_line_char(struct cyclades_port *info)
  2782. {
  2783. struct cyclades_card *card;
  2784. unsigned long flags;
  2785. void __iomem *base_addr;
  2786. int chip, channel, index;
  2787. unsigned cflag, iflag;
  2788. unsigned short chip_number;
  2789. int baud, baud_rate = 0;
  2790. int i;
  2791. if (!info->tty || !info->tty->termios) {
  2792. return;
  2793. }
  2794. if (info->line == -1) {
  2795. return;
  2796. }
  2797. cflag = info->tty->termios->c_cflag;
  2798. iflag = info->tty->termios->c_iflag;
  2799. /*
  2800. * Set up the tty->alt_speed kludge
  2801. */
  2802. if (info->tty) {
  2803. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  2804. info->tty->alt_speed = 57600;
  2805. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  2806. info->tty->alt_speed = 115200;
  2807. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
  2808. info->tty->alt_speed = 230400;
  2809. if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
  2810. info->tty->alt_speed = 460800;
  2811. }
  2812. card = info->card;
  2813. channel = info->line - card->first_line;
  2814. chip_number = channel / 4;
  2815. if (!IS_CYC_Z(*card)) {
  2816. index = card->bus_index;
  2817. /* baud rate */
  2818. baud = tty_get_baud_rate(info->tty);
  2819. if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
  2820. ASYNC_SPD_CUST) {
  2821. if (info->custom_divisor)
  2822. baud_rate = info->baud / info->custom_divisor;
  2823. else
  2824. baud_rate = info->baud;
  2825. } else if (baud > CD1400_MAX_SPEED) {
  2826. baud = CD1400_MAX_SPEED;
  2827. }
  2828. /* find the baud index */
  2829. for (i = 0; i < 20; i++) {
  2830. if (baud == baud_table[i]) {
  2831. break;
  2832. }
  2833. }
  2834. if (i == 20) {
  2835. i = 19; /* CD1400_MAX_SPEED */
  2836. }
  2837. if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
  2838. ASYNC_SPD_CUST) {
  2839. cyy_baud_calc(info, baud_rate);
  2840. } else {
  2841. if (info->chip_rev >= CD1400_REV_J) {
  2842. /* It is a CD1400 rev. J or later */
  2843. info->tbpr = baud_bpr_60[i]; /* Tx BPR */
  2844. info->tco = baud_co_60[i]; /* Tx CO */
  2845. info->rbpr = baud_bpr_60[i]; /* Rx BPR */
  2846. info->rco = baud_co_60[i]; /* Rx CO */
  2847. } else {
  2848. info->tbpr = baud_bpr_25[i]; /* Tx BPR */
  2849. info->tco = baud_co_25[i]; /* Tx CO */
  2850. info->rbpr = baud_bpr_25[i]; /* Rx BPR */
  2851. info->rco = baud_co_25[i]; /* Rx CO */
  2852. }
  2853. }
  2854. if (baud_table[i] == 134) {
  2855. /* get it right for 134.5 baud */
  2856. info->timeout = (info->xmit_fifo_size * HZ * 30 / 269) +
  2857. 2;
  2858. } else if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
  2859. ASYNC_SPD_CUST) {
  2860. info->timeout = (info->xmit_fifo_size * HZ * 15 /
  2861. baud_rate) + 2;
  2862. } else if (baud_table[i]) {
  2863. info->timeout = (info->xmit_fifo_size * HZ * 15 /
  2864. baud_table[i]) + 2;
  2865. /* this needs to be propagated into the card info */
  2866. } else {
  2867. info->timeout = 0;
  2868. }
  2869. /* By tradition (is it a standard?) a baud rate of zero
  2870. implies the line should be/has been closed. A bit
  2871. later in this routine such a test is performed. */
  2872. /* byte size and parity */
  2873. info->cor5 = 0;
  2874. info->cor4 = 0;
  2875. /* receive threshold */
  2876. info->cor3 = (info->default_threshold ?
  2877. info->default_threshold : baud_cor3[i]);
  2878. info->cor2 = CyETC;
  2879. switch (cflag & CSIZE) {
  2880. case CS5:
  2881. info->cor1 = Cy_5_BITS;
  2882. break;
  2883. case CS6:
  2884. info->cor1 = Cy_6_BITS;
  2885. break;
  2886. case CS7:
  2887. info->cor1 = Cy_7_BITS;
  2888. break;
  2889. case CS8:
  2890. info->cor1 = Cy_8_BITS;
  2891. break;
  2892. }
  2893. if (cflag & CSTOPB) {
  2894. info->cor1 |= Cy_2_STOP;
  2895. }
  2896. if (cflag & PARENB) {
  2897. if (cflag & PARODD) {
  2898. info->cor1 |= CyPARITY_O;
  2899. } else {
  2900. info->cor1 |= CyPARITY_E;
  2901. }
  2902. } else {
  2903. info->cor1 |= CyPARITY_NONE;
  2904. }
  2905. /* CTS flow control flag */
  2906. if (cflag & CRTSCTS) {
  2907. info->flags |= ASYNC_CTS_FLOW;
  2908. info->cor2 |= CyCtsAE;
  2909. } else {
  2910. info->flags &= ~ASYNC_CTS_FLOW;
  2911. info->cor2 &= ~CyCtsAE;
  2912. }
  2913. if (cflag & CLOCAL)
  2914. info->flags &= ~ASYNC_CHECK_CD;
  2915. else
  2916. info->flags |= ASYNC_CHECK_CD;
  2917. /***********************************************
  2918. The hardware option, CyRtsAO, presents RTS when
  2919. the chip has characters to send. Since most modems
  2920. use RTS as reverse (inbound) flow control, this
  2921. option is not used. If inbound flow control is
  2922. necessary, DTR can be programmed to provide the
  2923. appropriate signals for use with a non-standard
  2924. cable. Contact Marcio Saito for details.
  2925. ***********************************************/
  2926. chip = channel >> 2;
  2927. channel &= 0x03;
  2928. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  2929. spin_lock_irqsave(&card->card_lock, flags);
  2930. cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
  2931. /* tx and rx baud rate */
  2932. cy_writeb(base_addr + (CyTCOR << index), info->tco);
  2933. cy_writeb(base_addr + (CyTBPR << index), info->tbpr);
  2934. cy_writeb(base_addr + (CyRCOR << index), info->rco);
  2935. cy_writeb(base_addr + (CyRBPR << index), info->rbpr);
  2936. /* set line characteristics according configuration */
  2937. cy_writeb(base_addr + (CySCHR1 << index),
  2938. START_CHAR(info->tty));
  2939. cy_writeb(base_addr + (CySCHR2 << index), STOP_CHAR(info->tty));
  2940. cy_writeb(base_addr + (CyCOR1 << index), info->cor1);
  2941. cy_writeb(base_addr + (CyCOR2 << index), info->cor2);
  2942. cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
  2943. cy_writeb(base_addr + (CyCOR4 << index), info->cor4);
  2944. cy_writeb(base_addr + (CyCOR5 << index), info->cor5);
  2945. cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR1ch | CyCOR2ch |
  2946. CyCOR3ch, index);
  2947. cy_writeb(base_addr + (CyCAR << index), (u_char) channel); /* !!! Is this needed? */
  2948. cy_writeb(base_addr + (CyRTPR << index),
  2949. (info->default_timeout ? info->default_timeout : 0x02));
  2950. /* 10ms rx timeout */
  2951. if (C_CLOCAL(info->tty)) {
  2952. /* without modem intr */
  2953. cy_writeb(base_addr + (CySRER << index),
  2954. readb(base_addr + (CySRER << index)) | CyMdmCh);
  2955. /* act on 1->0 modem transitions */
  2956. if ((cflag & CRTSCTS) && info->rflow) {
  2957. cy_writeb(base_addr + (CyMCOR1 << index),
  2958. (CyCTS | rflow_thr[i]));
  2959. } else {
  2960. cy_writeb(base_addr + (CyMCOR1 << index),
  2961. CyCTS);
  2962. }
  2963. /* act on 0->1 modem transitions */
  2964. cy_writeb(base_addr + (CyMCOR2 << index), CyCTS);
  2965. } else {
  2966. /* without modem intr */
  2967. cy_writeb(base_addr + (CySRER << index),
  2968. readb(base_addr +
  2969. (CySRER << index)) | CyMdmCh);
  2970. /* act on 1->0 modem transitions */
  2971. if ((cflag & CRTSCTS) && info->rflow) {
  2972. cy_writeb(base_addr + (CyMCOR1 << index),
  2973. (CyDSR | CyCTS | CyRI | CyDCD |
  2974. rflow_thr[i]));
  2975. } else {
  2976. cy_writeb(base_addr + (CyMCOR1 << index),
  2977. CyDSR | CyCTS | CyRI | CyDCD);
  2978. }
  2979. /* act on 0->1 modem transitions */
  2980. cy_writeb(base_addr + (CyMCOR2 << index),
  2981. CyDSR | CyCTS | CyRI | CyDCD);
  2982. }
  2983. if (i == 0) { /* baud rate is zero, turn off line */
  2984. if (info->rtsdtr_inv) {
  2985. cy_writeb(base_addr + (CyMSVR1 << index),
  2986. ~CyRTS);
  2987. } else {
  2988. cy_writeb(base_addr + (CyMSVR2 << index),
  2989. ~CyDTR);
  2990. }
  2991. #ifdef CY_DEBUG_DTR
  2992. printk(KERN_DEBUG "cyc:set_line_char dropping DTR\n");
  2993. printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
  2994. readb(base_addr + (CyMSVR1 << index)),
  2995. readb(base_addr + (CyMSVR2 << index)));
  2996. #endif
  2997. } else {
  2998. if (info->rtsdtr_inv) {
  2999. cy_writeb(base_addr + (CyMSVR1 << index),
  3000. CyRTS);
  3001. } else {
  3002. cy_writeb(base_addr + (CyMSVR2 << index),
  3003. CyDTR);
  3004. }
  3005. #ifdef CY_DEBUG_DTR
  3006. printk(KERN_DEBUG "cyc:set_line_char raising DTR\n");
  3007. printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
  3008. readb(base_addr + (CyMSVR1 << index)),
  3009. readb(base_addr + (CyMSVR2 << index)));
  3010. #endif
  3011. }
  3012. if (info->tty) {
  3013. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  3014. }
  3015. spin_unlock_irqrestore(&card->card_lock, flags);
  3016. } else {
  3017. struct FIRM_ID __iomem *firm_id;
  3018. struct ZFW_CTRL __iomem *zfw_ctrl;
  3019. struct BOARD_CTRL __iomem *board_ctrl;
  3020. struct CH_CTRL __iomem *ch_ctrl;
  3021. struct BUF_CTRL __iomem *buf_ctrl;
  3022. __u32 sw_flow;
  3023. int retval;
  3024. firm_id = card->base_addr + ID_ADDRESS;
  3025. if (!ISZLOADED(*card)) {
  3026. return;
  3027. }
  3028. zfw_ctrl = card->base_addr +
  3029. (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  3030. board_ctrl = &zfw_ctrl->board_ctrl;
  3031. ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
  3032. buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
  3033. /* baud rate */
  3034. baud = tty_get_baud_rate(info->tty);
  3035. if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
  3036. ASYNC_SPD_CUST) {
  3037. if (info->custom_divisor)
  3038. baud_rate = info->baud / info->custom_divisor;
  3039. else
  3040. baud_rate = info->baud;
  3041. } else if (baud > CYZ_MAX_SPEED) {
  3042. baud = CYZ_MAX_SPEED;
  3043. }
  3044. cy_writel(&ch_ctrl->comm_baud, baud);
  3045. if (baud == 134) {
  3046. /* get it right for 134.5 baud */
  3047. info->timeout = (info->xmit_fifo_size * HZ * 30 / 269) +
  3048. 2;
  3049. } else if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
  3050. ASYNC_SPD_CUST) {
  3051. info->timeout = (info->xmit_fifo_size * HZ * 15 /
  3052. baud_rate) + 2;
  3053. } else if (baud) {
  3054. info->timeout = (info->xmit_fifo_size * HZ * 15 /
  3055. baud) + 2;
  3056. /* this needs to be propagated into the card info */
  3057. } else {
  3058. info->timeout = 0;
  3059. }
  3060. /* byte size and parity */
  3061. switch (cflag & CSIZE) {
  3062. case CS5:
  3063. cy_writel(&ch_ctrl->comm_data_l, C_DL_CS5);
  3064. break;
  3065. case CS6:
  3066. cy_writel(&ch_ctrl->comm_data_l, C_DL_CS6);
  3067. break;
  3068. case CS7:
  3069. cy_writel(&ch_ctrl->comm_data_l, C_DL_CS7);
  3070. break;
  3071. case CS8:
  3072. cy_writel(&ch_ctrl->comm_data_l, C_DL_CS8);
  3073. break;
  3074. }
  3075. if (cflag & CSTOPB) {
  3076. cy_writel(&ch_ctrl->comm_data_l,
  3077. readl(&ch_ctrl->comm_data_l) | C_DL_2STOP);
  3078. } else {
  3079. cy_writel(&ch_ctrl->comm_data_l,
  3080. readl(&ch_ctrl->comm_data_l) | C_DL_1STOP);
  3081. }
  3082. if (cflag & PARENB) {
  3083. if (cflag & PARODD) {
  3084. cy_writel(&ch_ctrl->comm_parity, C_PR_ODD);
  3085. } else {
  3086. cy_writel(&ch_ctrl->comm_parity, C_PR_EVEN);
  3087. }
  3088. } else {
  3089. cy_writel(&ch_ctrl->comm_parity, C_PR_NONE);
  3090. }
  3091. /* CTS flow control flag */
  3092. if (cflag & CRTSCTS) {
  3093. cy_writel(&ch_ctrl->hw_flow,
  3094. readl(&ch_ctrl->hw_flow) | C_RS_CTS | C_RS_RTS);
  3095. } else {
  3096. cy_writel(&ch_ctrl->hw_flow, readl(&ch_ctrl->hw_flow) &
  3097. ~(C_RS_CTS | C_RS_RTS));
  3098. }
  3099. /* As the HW flow control is done in firmware, the driver
  3100. doesn't need to care about it */
  3101. info->flags &= ~ASYNC_CTS_FLOW;
  3102. /* XON/XOFF/XANY flow control flags */
  3103. sw_flow = 0;
  3104. if (iflag & IXON) {
  3105. sw_flow |= C_FL_OXX;
  3106. if (iflag & IXANY)
  3107. sw_flow |= C_FL_OIXANY;
  3108. }
  3109. cy_writel(&ch_ctrl->sw_flow, sw_flow);
  3110. retval = cyz_issue_cmd(card, channel, C_CM_IOCTL, 0L);
  3111. if (retval != 0) {
  3112. printk(KERN_ERR "cyc:set_line_char retval on ttyC%d "
  3113. "was %x\n", info->line, retval);
  3114. }
  3115. /* CD sensitivity */
  3116. if (cflag & CLOCAL) {
  3117. info->flags &= ~ASYNC_CHECK_CD;
  3118. } else {
  3119. info->flags |= ASYNC_CHECK_CD;
  3120. }
  3121. if (baud == 0) { /* baud rate is zero, turn off line */
  3122. cy_writel(&ch_ctrl->rs_control,
  3123. readl(&ch_ctrl->rs_control) & ~C_RS_DTR);
  3124. #ifdef CY_DEBUG_DTR
  3125. printk(KERN_DEBUG "cyc:set_line_char dropping Z DTR\n");
  3126. #endif
  3127. } else {
  3128. cy_writel(&ch_ctrl->rs_control,
  3129. readl(&ch_ctrl->rs_control) | C_RS_DTR);
  3130. #ifdef CY_DEBUG_DTR
  3131. printk(KERN_DEBUG "cyc:set_line_char raising Z DTR\n");
  3132. #endif
  3133. }
  3134. retval = cyz_issue_cmd(card, channel, C_CM_IOCTLM,0L);
  3135. if (retval != 0) {
  3136. printk(KERN_ERR "cyc:set_line_char(2) retval on ttyC%d "
  3137. "was %x\n", info->line, retval);
  3138. }
  3139. if (info->tty) {
  3140. clear_bit(TTY_IO_ERROR, &info->tty->flags);
  3141. }
  3142. }
  3143. } /* set_line_char */
  3144. static int
  3145. get_serial_info(struct cyclades_port *info,
  3146. struct serial_struct __user * retinfo)
  3147. {
  3148. struct serial_struct tmp;
  3149. struct cyclades_card *cinfo = info->card;
  3150. if (!retinfo)
  3151. return -EFAULT;
  3152. memset(&tmp, 0, sizeof(tmp));
  3153. tmp.type = info->type;
  3154. tmp.line = info->line;
  3155. tmp.port = (info->card - cy_card) * 0x100 + info->line -
  3156. cinfo->first_line;
  3157. tmp.irq = cinfo->irq;
  3158. tmp.flags = info->flags;
  3159. tmp.close_delay = info->close_delay;
  3160. tmp.closing_wait = info->closing_wait;
  3161. tmp.baud_base = info->baud;
  3162. tmp.custom_divisor = info->custom_divisor;
  3163. tmp.hub6 = 0; /*!!! */
  3164. return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
  3165. } /* get_serial_info */
  3166. static int
  3167. set_serial_info(struct cyclades_port *info,
  3168. struct serial_struct __user * new_info)
  3169. {
  3170. struct serial_struct new_serial;
  3171. struct cyclades_port old_info;
  3172. if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
  3173. return -EFAULT;
  3174. old_info = *info;
  3175. if (!capable(CAP_SYS_ADMIN)) {
  3176. if (new_serial.close_delay != info->close_delay ||
  3177. new_serial.baud_base != info->baud ||
  3178. (new_serial.flags & ASYNC_FLAGS &
  3179. ~ASYNC_USR_MASK) !=
  3180. (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))
  3181. return -EPERM;
  3182. info->flags = (info->flags & ~ASYNC_USR_MASK) |
  3183. (new_serial.flags & ASYNC_USR_MASK);
  3184. info->baud = new_serial.baud_base;
  3185. info->custom_divisor = new_serial.custom_divisor;
  3186. goto check_and_exit;
  3187. }
  3188. /*
  3189. * OK, past this point, all the error checking has been done.
  3190. * At this point, we start making changes.....
  3191. */
  3192. info->baud = new_serial.baud_base;
  3193. info->custom_divisor = new_serial.custom_divisor;
  3194. info->flags = (info->flags & ~ASYNC_FLAGS) |
  3195. (new_serial.flags & ASYNC_FLAGS);
  3196. info->close_delay = new_serial.close_delay * HZ / 100;
  3197. info->closing_wait = new_serial.closing_wait * HZ / 100;
  3198. check_and_exit:
  3199. if (info->flags & ASYNC_INITIALIZED) {
  3200. set_line_char(info);
  3201. return 0;
  3202. } else {
  3203. return startup(info);
  3204. }
  3205. } /* set_serial_info */
  3206. /*
  3207. * get_lsr_info - get line status register info
  3208. *
  3209. * Purpose: Let user call ioctl() to get info when the UART physically
  3210. * is emptied. On bus types like RS485, the transmitter must
  3211. * release the bus after transmitting. This must be done when
  3212. * the transmit shift register is empty, not be done when the
  3213. * transmit holding register is empty. This functionality
  3214. * allows an RS485 driver to be written in user space.
  3215. */
  3216. static int get_lsr_info(struct cyclades_port *info, unsigned int __user * value)
  3217. {
  3218. struct cyclades_card *card;
  3219. int chip, channel, index;
  3220. unsigned char status;
  3221. unsigned int result;
  3222. unsigned long flags;
  3223. void __iomem *base_addr;
  3224. card = info->card;
  3225. channel = (info->line) - (card->first_line);
  3226. if (!IS_CYC_Z(*card)) {
  3227. chip = channel >> 2;
  3228. channel &= 0x03;
  3229. index = card->bus_index;
  3230. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  3231. spin_lock_irqsave(&card->card_lock, flags);
  3232. status = readb(base_addr + (CySRER << index)) &
  3233. (CyTxRdy | CyTxMpty);
  3234. spin_unlock_irqrestore(&card->card_lock, flags);
  3235. result = (status ? 0 : TIOCSER_TEMT);
  3236. } else {
  3237. /* Not supported yet */
  3238. return -EINVAL;
  3239. }
  3240. return put_user(result, (unsigned long __user *)value);
  3241. }
  3242. static int cy_tiocmget(struct tty_struct *tty, struct file *file)
  3243. {
  3244. struct cyclades_port *info = tty->driver_data;
  3245. struct cyclades_card *card;
  3246. int chip, channel, index;
  3247. void __iomem *base_addr;
  3248. unsigned long flags;
  3249. unsigned char status;
  3250. unsigned long lstatus;
  3251. unsigned int result;
  3252. struct FIRM_ID __iomem *firm_id;
  3253. struct ZFW_CTRL __iomem *zfw_ctrl;
  3254. struct BOARD_CTRL __iomem *board_ctrl;
  3255. struct CH_CTRL __iomem *ch_ctrl;
  3256. if (serial_paranoia_check(info, tty->name, __FUNCTION__))
  3257. return -ENODEV;
  3258. card = info->card;
  3259. channel = info->line - card->first_line;
  3260. if (!IS_CYC_Z(*card)) {
  3261. chip = channel >> 2;
  3262. channel &= 0x03;
  3263. index = card->bus_index;
  3264. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  3265. spin_lock_irqsave(&card->card_lock, flags);
  3266. cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
  3267. status = readb(base_addr + (CyMSVR1 << index));
  3268. status |= readb(base_addr + (CyMSVR2 << index));
  3269. spin_unlock_irqrestore(&card->card_lock, flags);
  3270. if (info->rtsdtr_inv) {
  3271. result = ((status & CyRTS) ? TIOCM_DTR : 0) |
  3272. ((status & CyDTR) ? TIOCM_RTS : 0);
  3273. } else {
  3274. result = ((status & CyRTS) ? TIOCM_RTS : 0) |
  3275. ((status & CyDTR) ? TIOCM_DTR : 0);
  3276. }
  3277. result |= ((status & CyDCD) ? TIOCM_CAR : 0) |
  3278. ((status & CyRI) ? TIOCM_RNG : 0) |
  3279. ((status & CyDSR) ? TIOCM_DSR : 0) |
  3280. ((status & CyCTS) ? TIOCM_CTS : 0);
  3281. } else {
  3282. base_addr = card->base_addr;
  3283. firm_id = card->base_addr + ID_ADDRESS;
  3284. if (ISZLOADED(*card)) {
  3285. zfw_ctrl = card->base_addr +
  3286. (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  3287. board_ctrl = &zfw_ctrl->board_ctrl;
  3288. ch_ctrl = zfw_ctrl->ch_ctrl;
  3289. lstatus = readl(&ch_ctrl[channel].rs_status);
  3290. result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0) |
  3291. ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0) |
  3292. ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0) |
  3293. ((lstatus & C_RS_RI) ? TIOCM_RNG : 0) |
  3294. ((lstatus & C_RS_DSR) ? TIOCM_DSR : 0) |
  3295. ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
  3296. } else {
  3297. result = 0;
  3298. return -ENODEV;
  3299. }
  3300. }
  3301. return result;
  3302. } /* cy_tiomget */
  3303. static int
  3304. cy_tiocmset(struct tty_struct *tty, struct file *file,
  3305. unsigned int set, unsigned int clear)
  3306. {
  3307. struct cyclades_port *info = tty->driver_data;
  3308. struct cyclades_card *card;
  3309. int chip, channel, index;
  3310. void __iomem *base_addr;
  3311. unsigned long flags;
  3312. struct FIRM_ID __iomem *firm_id;
  3313. struct ZFW_CTRL __iomem *zfw_ctrl;
  3314. struct BOARD_CTRL __iomem *board_ctrl;
  3315. struct CH_CTRL __iomem *ch_ctrl;
  3316. int retval;
  3317. if (serial_paranoia_check(info, tty->name, __FUNCTION__))
  3318. return -ENODEV;
  3319. card = info->card;
  3320. channel = (info->line) - (card->first_line);
  3321. if (!IS_CYC_Z(*card)) {
  3322. chip = channel >> 2;
  3323. channel &= 0x03;
  3324. index = card->bus_index;
  3325. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  3326. if (set & TIOCM_RTS) {
  3327. spin_lock_irqsave(&card->card_lock, flags);
  3328. cy_writeb(base_addr + (CyCAR << index),
  3329. (u_char) channel);
  3330. if (info->rtsdtr_inv) {
  3331. cy_writeb(base_addr + (CyMSVR2 << index),
  3332. CyDTR);
  3333. } else {
  3334. cy_writeb(base_addr + (CyMSVR1 << index),
  3335. CyRTS);
  3336. }
  3337. spin_unlock_irqrestore(&card->card_lock, flags);
  3338. }
  3339. if (clear & TIOCM_RTS) {
  3340. spin_lock_irqsave(&card->card_lock, flags);
  3341. cy_writeb(base_addr + (CyCAR << index),
  3342. (u_char) channel);
  3343. if (info->rtsdtr_inv) {
  3344. cy_writeb(base_addr + (CyMSVR2 << index),
  3345. ~CyDTR);
  3346. } else {
  3347. cy_writeb(base_addr + (CyMSVR1 << index),
  3348. ~CyRTS);
  3349. }
  3350. spin_unlock_irqrestore(&card->card_lock, flags);
  3351. }
  3352. if (set & TIOCM_DTR) {
  3353. spin_lock_irqsave(&card->card_lock, flags);
  3354. cy_writeb(base_addr + (CyCAR << index),
  3355. (u_char) channel);
  3356. if (info->rtsdtr_inv) {
  3357. cy_writeb(base_addr + (CyMSVR1 << index),
  3358. CyRTS);
  3359. } else {
  3360. cy_writeb(base_addr + (CyMSVR2 << index),
  3361. CyDTR);
  3362. }
  3363. #ifdef CY_DEBUG_DTR
  3364. printk(KERN_DEBUG "cyc:set_modem_info raising DTR\n");
  3365. printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
  3366. readb(base_addr + (CyMSVR1 << index)),
  3367. readb(base_addr + (CyMSVR2 << index)));
  3368. #endif
  3369. spin_unlock_irqrestore(&card->card_lock, flags);
  3370. }
  3371. if (clear & TIOCM_DTR) {
  3372. spin_lock_irqsave(&card->card_lock, flags);
  3373. cy_writeb(base_addr + (CyCAR << index),
  3374. (u_char) channel);
  3375. if (info->rtsdtr_inv) {
  3376. cy_writeb(base_addr + (CyMSVR1 << index),
  3377. ~CyRTS);
  3378. } else {
  3379. cy_writeb(base_addr + (CyMSVR2 << index),
  3380. ~CyDTR);
  3381. }
  3382. #ifdef CY_DEBUG_DTR
  3383. printk(KERN_DEBUG "cyc:set_modem_info dropping DTR\n");
  3384. printk(KERN_DEBUG " status: 0x%x, 0x%x\n",
  3385. readb(base_addr + (CyMSVR1 << index)),
  3386. readb(base_addr + (CyMSVR2 << index)));
  3387. #endif
  3388. spin_unlock_irqrestore(&card->card_lock, flags);
  3389. }
  3390. } else {
  3391. base_addr = card->base_addr;
  3392. firm_id = card->base_addr + ID_ADDRESS;
  3393. if (ISZLOADED(*card)) {
  3394. zfw_ctrl = card->base_addr +
  3395. (readl(&firm_id->zfwctrl_addr) & 0xfffff);
  3396. board_ctrl = &zfw_ctrl->board_ctrl;
  3397. ch_ctrl = zfw_ctrl->ch_ctrl;
  3398. if (set & TIOCM_RTS) {
  3399. spin_lock_irqsave(&card->card_lock, flags);
  3400. cy_writel(&ch_ctrl[channel].rs_control,
  3401. readl(&ch_ctrl[channel].rs_control) |
  3402. C_RS_RTS);
  3403. spin_unlock_irqrestore(&card->card_lock, flags);
  3404. }
  3405. if (clear & TIOCM_RTS) {
  3406. spin_lock_irqsave(&card->card_lock, flags);
  3407. cy_writel(&ch_ctrl[channel].rs_control,
  3408. readl(&ch_ctrl[channel].rs_control) &
  3409. ~C_RS_RTS);
  3410. spin_unlock_irqrestore(&card->card_lock, flags);
  3411. }
  3412. if (set & TIOCM_DTR) {
  3413. spin_lock_irqsave(&card->card_lock, flags);
  3414. cy_writel(&ch_ctrl[channel].rs_control,
  3415. readl(&ch_ctrl[channel].rs_control) |
  3416. C_RS_DTR);
  3417. #ifdef CY_DEBUG_DTR
  3418. printk(KERN_DEBUG "cyc:set_modem_info raising "
  3419. "Z DTR\n");
  3420. #endif
  3421. spin_unlock_irqrestore(&card->card_lock, flags);
  3422. }
  3423. if (clear & TIOCM_DTR) {
  3424. spin_lock_irqsave(&card->card_lock, flags);
  3425. cy_writel(&ch_ctrl[channel].rs_control,
  3426. readl(&ch_ctrl[channel].rs_control) &
  3427. ~C_RS_DTR);
  3428. #ifdef CY_DEBUG_DTR
  3429. printk(KERN_DEBUG "cyc:set_modem_info clearing "
  3430. "Z DTR\n");
  3431. #endif
  3432. spin_unlock_irqrestore(&card->card_lock, flags);
  3433. }
  3434. } else {
  3435. return -ENODEV;
  3436. }
  3437. spin_lock_irqsave(&card->card_lock, flags);
  3438. retval = cyz_issue_cmd(card, channel, C_CM_IOCTLM, 0L);
  3439. if (retval != 0) {
  3440. printk(KERN_ERR "cyc:set_modem_info retval on ttyC%d "
  3441. "was %x\n", info->line, retval);
  3442. }
  3443. spin_unlock_irqrestore(&card->card_lock, flags);
  3444. }
  3445. return 0;
  3446. } /* cy_tiocmset */
  3447. /*
  3448. * cy_break() --- routine which turns the break handling on or off
  3449. */
  3450. static void cy_break(struct tty_struct *tty, int break_state)
  3451. {
  3452. struct cyclades_port *info = tty->driver_data;
  3453. struct cyclades_card *card;
  3454. unsigned long flags;
  3455. if (serial_paranoia_check(info, tty->name, "cy_break"))
  3456. return;
  3457. card = info->card;
  3458. spin_lock_irqsave(&card->card_lock, flags);
  3459. if (!IS_CYC_Z(*card)) {
  3460. /* Let the transmit ISR take care of this (since it
  3461. requires stuffing characters into the output stream).
  3462. */
  3463. if (break_state == -1) {
  3464. if (!info->breakon) {
  3465. info->breakon = 1;
  3466. if (!info->xmit_cnt) {
  3467. spin_unlock_irqrestore(&card->card_lock, flags);
  3468. start_xmit(info);
  3469. spin_lock_irqsave(&card->card_lock, flags);
  3470. }
  3471. }
  3472. } else {
  3473. if (!info->breakoff) {
  3474. info->breakoff = 1;
  3475. if (!info->xmit_cnt) {
  3476. spin_unlock_irqrestore(&card->card_lock, flags);
  3477. start_xmit(info);
  3478. spin_lock_irqsave(&card->card_lock, flags);
  3479. }
  3480. }
  3481. }
  3482. } else {
  3483. int retval;
  3484. if (break_state == -1) {
  3485. retval = cyz_issue_cmd(card,
  3486. info->line - card->first_line,
  3487. C_CM_SET_BREAK, 0L);
  3488. if (retval != 0) {
  3489. printk(KERN_ERR "cyc:cy_break (set) retval on "
  3490. "ttyC%d was %x\n", info->line, retval);
  3491. }
  3492. } else {
  3493. retval = cyz_issue_cmd(card,
  3494. info->line - card->first_line,
  3495. C_CM_CLR_BREAK, 0L);
  3496. if (retval != 0) {
  3497. printk(KERN_DEBUG "cyc:cy_break (clr) retval "
  3498. "on ttyC%d was %x\n", info->line,
  3499. retval);
  3500. }
  3501. }
  3502. }
  3503. spin_unlock_irqrestore(&card->card_lock, flags);
  3504. } /* cy_break */
  3505. static int
  3506. get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
  3507. {
  3508. if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
  3509. return -EFAULT;
  3510. info->mon.int_count = 0;
  3511. info->mon.char_count = 0;
  3512. info->mon.char_max = 0;
  3513. info->mon.char_last = 0;
  3514. return 0;
  3515. } /* get_mon_info */
  3516. static int set_threshold(struct cyclades_port *info, unsigned long value)
  3517. {
  3518. struct cyclades_card *card;
  3519. void __iomem *base_addr;
  3520. int channel, chip, index;
  3521. unsigned long flags;
  3522. card = info->card;
  3523. channel = info->line - card->first_line;
  3524. if (!IS_CYC_Z(*card)) {
  3525. chip = channel >> 2;
  3526. channel &= 0x03;
  3527. index = card->bus_index;
  3528. base_addr =
  3529. card->base_addr + (cy_chip_offset[chip] << index);
  3530. info->cor3 &= ~CyREC_FIFO;
  3531. info->cor3 |= value & CyREC_FIFO;
  3532. spin_lock_irqsave(&card->card_lock, flags);
  3533. cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
  3534. cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR3ch, index);
  3535. spin_unlock_irqrestore(&card->card_lock, flags);
  3536. }
  3537. return 0;
  3538. } /* set_threshold */
  3539. static int
  3540. get_threshold(struct cyclades_port *info, unsigned long __user * value)
  3541. {
  3542. struct cyclades_card *card;
  3543. void __iomem *base_addr;
  3544. int channel, chip, index;
  3545. unsigned long tmp;
  3546. card = info->card;
  3547. channel = info->line - card->first_line;
  3548. if (!IS_CYC_Z(*card)) {
  3549. chip = channel >> 2;
  3550. channel &= 0x03;
  3551. index = card->bus_index;
  3552. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  3553. tmp = readb(base_addr + (CyCOR3 << index)) & CyREC_FIFO;
  3554. return put_user(tmp, value);
  3555. }
  3556. return 0;
  3557. } /* get_threshold */
  3558. static int
  3559. set_default_threshold(struct cyclades_port *info, unsigned long value)
  3560. {
  3561. info->default_threshold = value & 0x0f;
  3562. return 0;
  3563. } /* set_default_threshold */
  3564. static int
  3565. get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
  3566. {
  3567. return put_user(info->default_threshold, value);
  3568. } /* get_default_threshold */
  3569. static int set_timeout(struct cyclades_port *info, unsigned long value)
  3570. {
  3571. struct cyclades_card *card;
  3572. void __iomem *base_addr;
  3573. int channel, chip, index;
  3574. unsigned long flags;
  3575. card = info->card;
  3576. channel = info->line - card->first_line;
  3577. if (!IS_CYC_Z(*card)) {
  3578. chip = channel >> 2;
  3579. channel &= 0x03;
  3580. index = card->bus_index;
  3581. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  3582. spin_lock_irqsave(&card->card_lock, flags);
  3583. cy_writeb(base_addr + (CyRTPR << index), value & 0xff);
  3584. spin_unlock_irqrestore(&card->card_lock, flags);
  3585. }
  3586. return 0;
  3587. } /* set_timeout */
  3588. static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
  3589. {
  3590. struct cyclades_card *card;
  3591. void __iomem *base_addr;
  3592. int channel, chip, index;
  3593. unsigned long tmp;
  3594. card = info->card;
  3595. channel = info->line - card->first_line;
  3596. if (!IS_CYC_Z(*card)) {
  3597. chip = channel >> 2;
  3598. channel &= 0x03;
  3599. index = card->bus_index;
  3600. base_addr = card->base_addr + (cy_chip_offset[chip] << index);
  3601. tmp = readb(base_addr + (CyRTPR << index));
  3602. return put_user(tmp, value);
  3603. }
  3604. return 0;
  3605. } /* get_timeout */
  3606. static int set_default_timeout(struct cyclades_port *info, unsigned long value)
  3607. {
  3608. info->default_timeout = value & 0xff;
  3609. return 0;
  3610. } /* set_default_timeout */
  3611. static int
  3612. get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
  3613. {
  3614. return put_user(info->default_timeout, value);
  3615. } /* get_default_timeout */
  3616. /*
  3617. * This routine allows the tty driver to implement device-
  3618. * specific ioctl's. If the ioctl number passed in cmd is
  3619. * not recognized by the driver, it should return ENOIOCTLCMD.
  3620. */
  3621. static int
  3622. cy_ioctl(struct tty_struct *tty, struct file *file,
  3623. unsigned int cmd, unsigned long arg)
  3624. {
  3625. struct cyclades_port *info = tty->driver_data;
  3626. struct cyclades_icount cprev, cnow; /* kernel counter temps */
  3627. struct serial_icounter_struct __user *p_cuser; /* user space */
  3628. int ret_val = 0;
  3629. unsigned long flags;
  3630. void __user *argp = (void __user *)arg;
  3631. if (serial_paranoia_check(info, tty->name, "cy_ioctl"))
  3632. return -ENODEV;
  3633. #ifdef CY_DEBUG_OTHER
  3634. printk(KERN_DEBUG "cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
  3635. info->line, cmd, arg);
  3636. #endif
  3637. switch (cmd) {
  3638. case CYGETMON:
  3639. ret_val = get_mon_info(info, argp);
  3640. break;
  3641. case CYGETTHRESH:
  3642. ret_val = get_threshold(info, argp);
  3643. break;
  3644. case CYSETTHRESH:
  3645. ret_val = set_threshold(info, arg);
  3646. break;
  3647. case CYGETDEFTHRESH:
  3648. ret_val = get_default_threshold(info, argp);
  3649. break;
  3650. case CYSETDEFTHRESH:
  3651. ret_val = set_default_threshold(info, arg);
  3652. break;
  3653. case CYGETTIMEOUT:
  3654. ret_val = get_timeout(info, argp);
  3655. break;
  3656. case CYSETTIMEOUT:
  3657. ret_val = set_timeout(info, arg);
  3658. break;
  3659. case CYGETDEFTIMEOUT:
  3660. ret_val = get_default_timeout(info, argp);
  3661. break;
  3662. case CYSETDEFTIMEOUT:
  3663. ret_val = set_default_timeout(info, arg);
  3664. break;
  3665. case CYSETRFLOW:
  3666. info->rflow = (int)arg;
  3667. ret_val = 0;
  3668. break;
  3669. case CYGETRFLOW:
  3670. ret_val = info->rflow;
  3671. break;
  3672. case CYSETRTSDTR_INV:
  3673. info->rtsdtr_inv = (int)arg;
  3674. ret_val = 0;
  3675. break;
  3676. case CYGETRTSDTR_INV:
  3677. ret_val = info->rtsdtr_inv;
  3678. break;
  3679. case CYGETCD1400VER:
  3680. ret_val = info->chip_rev;
  3681. break;
  3682. #ifndef CONFIG_CYZ_INTR
  3683. case CYZSETPOLLCYCLE:
  3684. cyz_polling_cycle = (arg * HZ) / 1000;
  3685. ret_val = 0;
  3686. break;
  3687. case CYZGETPOLLCYCLE:
  3688. ret_val = (cyz_polling_cycle * 1000) / HZ;
  3689. break;
  3690. #endif /* CONFIG_CYZ_INTR */
  3691. case CYSETWAIT:
  3692. info->closing_wait = (unsigned short)arg *HZ / 100;
  3693. ret_val = 0;
  3694. break;
  3695. case CYGETWAIT:
  3696. ret_val = info->closing_wait / (HZ / 100);
  3697. break;
  3698. case TIOCGSERIAL:
  3699. ret_val = get_serial_info(info, argp);
  3700. break;
  3701. case TIOCSSERIAL:
  3702. ret_val = set_serial_info(info, argp);
  3703. break;
  3704. case TIOCSERGETLSR: /* Get line status register */
  3705. ret_val = get_lsr_info(info, argp);
  3706. break;
  3707. /*
  3708. * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
  3709. * - mask passed in arg for lines of interest
  3710. * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
  3711. * Caller should use TIOCGICOUNT to see which one it was
  3712. */
  3713. case TIOCMIWAIT:
  3714. spin_lock_irqsave(&info->card->card_lock, flags);
  3715. /* note the counters on entry */
  3716. cnow = info->icount;
  3717. spin_unlock_irqrestore(&info->card->card_lock, flags);
  3718. ret_val = wait_event_interruptible(info->delta_msr_wait, ({
  3719. cprev = cnow;
  3720. spin_lock_irqsave(&info->card->card_lock, flags);
  3721. cnow = info->icount; /* atomic copy */
  3722. spin_unlock_irqrestore(&info->card->card_lock, flags);
  3723. ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
  3724. ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
  3725. ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
  3726. ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts));
  3727. }));
  3728. break;
  3729. /*
  3730. * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
  3731. * Return: write counters to the user passed counter struct
  3732. * NB: both 1->0 and 0->1 transitions are counted except for
  3733. * RI where only 0->1 is counted.
  3734. */
  3735. case TIOCGICOUNT:
  3736. spin_lock_irqsave(&info->card->card_lock, flags);
  3737. cnow = info->icount;
  3738. spin_unlock_irqrestore(&info->card->card_lock, flags);
  3739. p_cuser = argp;
  3740. ret_val = put_user(cnow.cts, &p_cuser->cts);
  3741. if (ret_val)
  3742. return ret_val;
  3743. ret_val = put_user(cnow.dsr, &p_cuser->dsr);
  3744. if (ret_val)
  3745. return ret_val;
  3746. ret_val = put_user(cnow.rng, &p_cuser->rng);
  3747. if (ret_val)
  3748. return ret_val;
  3749. ret_val = put_user(cnow.dcd, &p_cuser->dcd);
  3750. if (ret_val)
  3751. return ret_val;
  3752. ret_val = put_user(cnow.rx, &p_cuser->rx);
  3753. if (ret_val)
  3754. return ret_val;
  3755. ret_val = put_user(cnow.tx, &p_cuser->tx);
  3756. if (ret_val)
  3757. return ret_val;
  3758. ret_val = put_user(cnow.frame, &p_cuser->frame);
  3759. if (ret_val)
  3760. return ret_val;
  3761. ret_val = put_user(cnow.overrun, &p_cuser->overrun);
  3762. if (ret_val)
  3763. return ret_val;
  3764. ret_val = put_user(cnow.parity, &p_cuser->parity);
  3765. if (ret_val)
  3766. return ret_val;
  3767. ret_val = put_user(cnow.brk, &p_cuser->brk);
  3768. if (ret_val)
  3769. return ret_val;
  3770. ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
  3771. if (ret_val)
  3772. return ret_val;
  3773. ret_val = 0;
  3774. break;
  3775. default:
  3776. ret_val = -ENOIOCTLCMD;
  3777. }
  3778. #ifdef CY_DEBUG_OTHER
  3779. printk(KERN_DEBUG "cyc:cy_ioctl done\n");
  3780. #endif
  3781. return ret_val;
  3782. } /* cy_ioctl */
  3783. /*
  3784. * This routine allows the tty driver to be notified when
  3785. * device's termios settings have changed. Note that a
  3786. * well-designed tty driver should be prepared to accept the case
  3787. * where old == NULL, and try to do something rational.
  3788. */
  3789. static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
  3790. {
  3791. struct cyclades_port *info = tty->driver_data;
  3792. #ifdef CY_DEBUG_OTHER
  3793. printk(KERN_DEBUG "cyc:cy_set_termios ttyC%d\n", info->line);
  3794. #endif
  3795. set_line_char(info);
  3796. if ((old_termios->c_cflag & CRTSCTS) &&
  3797. !(tty->termios->c_cflag & CRTSCTS)) {
  3798. tty->hw_stopped = 0;
  3799. cy_start(tty);
  3800. }
  3801. #if 0
  3802. /*
  3803. * No need to wake up processes in open wait, since they
  3804. * sample the CLOCAL flag once, and don't recheck it.
  3805. * XXX It's not clear whether the current behavior is correct
  3806. * or not. Hence, this may change.....
  3807. */
  3808. if (!(old_termios->c_cflag & CLOCAL) &&
  3809. (tty->termios->c_cflag & CLOCAL))
  3810. wake_up_interruptible(&info->open_wait);
  3811. #endif
  3812. } /* cy_set_termios */
  3813. /* This function is used to send a high-priority XON/XOFF character to
  3814. the device.
  3815. */
  3816. static void cy_send_xchar(struct tty_struct *tty, char ch)
  3817. {
  3818. struct cyclades_port *info = tty->driver_data;
  3819. struct cyclades_card *card;
  3820. int channel;
  3821. if (serial_paranoia_check(info, tty->name, "cy_send_xchar"))
  3822. return;
  3823. info->x_char = ch;
  3824. if (ch)
  3825. cy_start(tty);
  3826. card = info->card;
  3827. channel = info->line - card->first_line;
  3828. if (IS_CYC_Z(*card)) {
  3829. if (ch == STOP_CHAR(tty))
  3830. cyz_issue_cmd(card, channel, C_CM_SENDXOFF, 0L);
  3831. else if (ch == START_CHAR(tty))
  3832. cyz_issue_cmd(card, channel, C_CM_SENDXON, 0L);
  3833. }
  3834. }
  3835. /* This routine is called by the upper-layer tty layer to signal
  3836. that incoming characters should be throttled because the input
  3837. buffers are close to full.
  3838. */
  3839. static void cy_throttle(struct tty_struct *tty)
  3840. {
  3841. struct cyclades_port *info = tty->driver_data;
  3842. struct cyclades_card *card;
  3843. unsigned long flags;
  3844. void __iomem *base_addr;
  3845. int chip, channel, index;
  3846. #ifdef CY_DEBUG_THROTTLE
  3847. char buf[64];
  3848. printk(KERN_DEBUG "cyc:throttle %s: %ld...ttyC%d\n", tty_name(tty, buf),
  3849. tty->ldisc.chars_in_buffer(tty), info->line);
  3850. #endif
  3851. if (serial_paranoia_check(info, tty->name, "cy_throttle")) {
  3852. return;
  3853. }
  3854. card = info->card;
  3855. if (I_IXOFF(tty)) {
  3856. if (!IS_CYC_Z(*card))
  3857. cy_send_xchar(tty, STOP_CHAR(tty));
  3858. else
  3859. info->throttle = 1;
  3860. }
  3861. if (tty->termios->c_cflag & CRTSCTS) {
  3862. channel = info->line - card->first_line;
  3863. if (!IS_CYC_Z(*card)) {
  3864. chip = channel >> 2;
  3865. channel &= 0x03;
  3866. index = card->bus_index;
  3867. base_addr = card->base_addr +
  3868. (cy_chip_offset[chip] << index);
  3869. spin_lock_irqsave(&card->card_lock, flags);
  3870. cy_writeb(base_addr + (CyCAR << index),
  3871. (u_char) channel);
  3872. if (info->rtsdtr_inv) {
  3873. cy_writeb(base_addr + (CyMSVR2 << index),
  3874. ~CyDTR);
  3875. } else {
  3876. cy_writeb(base_addr + (CyMSVR1 << index),
  3877. ~CyRTS);
  3878. }
  3879. spin_unlock_irqrestore(&card->card_lock, flags);
  3880. } else {
  3881. info->throttle = 1;
  3882. }
  3883. }
  3884. } /* cy_throttle */
  3885. /*
  3886. * This routine notifies the tty driver that it should signal
  3887. * that characters can now be sent to the tty without fear of
  3888. * overrunning the input buffers of the line disciplines.
  3889. */
  3890. static void cy_unthrottle(struct tty_struct *tty)
  3891. {
  3892. struct cyclades_port *info = tty->driver_data;
  3893. struct cyclades_card *card;
  3894. unsigned long flags;
  3895. void __iomem *base_addr;
  3896. int chip, channel, index;
  3897. #ifdef CY_DEBUG_THROTTLE
  3898. char buf[64];
  3899. printk(KERN_DEBUG "cyc:unthrottle %s: %ld...ttyC%d\n",
  3900. tty_name(tty, buf), tty->ldisc.chars_in_buffer(tty),info->line);
  3901. #endif
  3902. if (serial_paranoia_check(info, tty->name, "cy_unthrottle")) {
  3903. return;
  3904. }
  3905. if (I_IXOFF(tty)) {
  3906. if (info->x_char)
  3907. info->x_char = 0;
  3908. else
  3909. cy_send_xchar(tty, START_CHAR(tty));
  3910. }
  3911. if (tty->termios->c_cflag & CRTSCTS) {
  3912. card = info->card;
  3913. channel = info->line - card->first_line;
  3914. if (!IS_CYC_Z(*card)) {
  3915. chip = channel >> 2;
  3916. channel &= 0x03;
  3917. index = card->bus_index;
  3918. base_addr = card->base_addr +
  3919. (cy_chip_offset[chip] << index);
  3920. spin_lock_irqsave(&card->card_lock, flags);
  3921. cy_writeb(base_addr + (CyCAR << index),
  3922. (u_char) channel);
  3923. if (info->rtsdtr_inv) {
  3924. cy_writeb(base_addr + (CyMSVR2 << index),
  3925. CyDTR);
  3926. } else {
  3927. cy_writeb(base_addr + (CyMSVR1 << index),
  3928. CyRTS);
  3929. }
  3930. spin_unlock_irqrestore(&card->card_lock, flags);
  3931. } else {
  3932. info->throttle = 0;
  3933. }
  3934. }
  3935. } /* cy_unthrottle */
  3936. /* cy_start and cy_stop provide software output flow control as a
  3937. function of XON/XOFF, software CTS, and other such stuff.
  3938. */
  3939. static void cy_stop(struct tty_struct *tty)
  3940. {
  3941. struct cyclades_card *cinfo;
  3942. struct cyclades_port *info = tty->driver_data;
  3943. void __iomem *base_addr;
  3944. int chip, channel, index;
  3945. unsigned long flags;
  3946. #ifdef CY_DEBUG_OTHER
  3947. printk(KERN_DEBUG "cyc:cy_stop ttyC%d\n", info->line);
  3948. #endif
  3949. if (serial_paranoia_check(info, tty->name, "cy_stop"))
  3950. return;
  3951. cinfo = info->card;
  3952. channel = info->line - cinfo->first_line;
  3953. if (!IS_CYC_Z(*cinfo)) {
  3954. index = cinfo->bus_index;
  3955. chip = channel >> 2;
  3956. channel &= 0x03;
  3957. base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
  3958. spin_lock_irqsave(&cinfo->card_lock, flags);
  3959. cy_writeb(base_addr + (CyCAR << index),
  3960. (u_char)(channel & 0x0003)); /* index channel */
  3961. cy_writeb(base_addr + (CySRER << index),
  3962. readb(base_addr + (CySRER << index)) & ~CyTxRdy);
  3963. spin_unlock_irqrestore(&cinfo->card_lock, flags);
  3964. }
  3965. } /* cy_stop */
  3966. static void cy_start(struct tty_struct *tty)
  3967. {
  3968. struct cyclades_card *cinfo;
  3969. struct cyclades_port *info = tty->driver_data;
  3970. void __iomem *base_addr;
  3971. int chip, channel, index;
  3972. unsigned long flags;
  3973. #ifdef CY_DEBUG_OTHER
  3974. printk(KERN_DEBUG "cyc:cy_start ttyC%d\n", info->line);
  3975. #endif
  3976. if (serial_paranoia_check(info, tty->name, "cy_start"))
  3977. return;
  3978. cinfo = info->card;
  3979. channel = info->line - cinfo->first_line;
  3980. index = cinfo->bus_index;
  3981. if (!IS_CYC_Z(*cinfo)) {
  3982. chip = channel >> 2;
  3983. channel &= 0x03;
  3984. base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
  3985. spin_lock_irqsave(&cinfo->card_lock, flags);
  3986. cy_writeb(base_addr + (CyCAR << index), (u_char) (channel & 0x0003)); /* index channel */
  3987. cy_writeb(base_addr + (CySRER << index),
  3988. readb(base_addr + (CySRER << index)) | CyTxRdy);
  3989. spin_unlock_irqrestore(&cinfo->card_lock, flags);
  3990. }
  3991. } /* cy_start */
  3992. static void cy_flush_buffer(struct tty_struct *tty)
  3993. {
  3994. struct cyclades_port *info = tty->driver_data;
  3995. struct cyclades_card *card;
  3996. int channel, retval;
  3997. unsigned long flags;
  3998. #ifdef CY_DEBUG_IO
  3999. printk(KERN_DEBUG "cyc:cy_flush_buffer ttyC%d\n", info->line);
  4000. #endif
  4001. if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
  4002. return;
  4003. card = info->card;
  4004. channel = info->line - card->first_line;
  4005. spin_lock_irqsave(&card->card_lock, flags);
  4006. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  4007. spin_unlock_irqrestore(&card->card_lock, flags);
  4008. if (IS_CYC_Z(*card)) { /* If it is a Z card, flush the on-board
  4009. buffers as well */
  4010. spin_lock_irqsave(&card->card_lock, flags);
  4011. retval = cyz_issue_cmd(card, channel, C_CM_FLUSH_TX, 0L);
  4012. if (retval != 0) {
  4013. printk(KERN_ERR "cyc: flush_buffer retval on ttyC%d "
  4014. "was %x\n", info->line, retval);
  4015. }
  4016. spin_unlock_irqrestore(&card->card_lock, flags);
  4017. }
  4018. tty_wakeup(tty);
  4019. } /* cy_flush_buffer */
  4020. /*
  4021. * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
  4022. */
  4023. static void cy_hangup(struct tty_struct *tty)
  4024. {
  4025. struct cyclades_port *info = tty->driver_data;
  4026. #ifdef CY_DEBUG_OTHER
  4027. printk(KERN_DEBUG "cyc:cy_hangup ttyC%d\n", info->line);
  4028. #endif
  4029. if (serial_paranoia_check(info, tty->name, "cy_hangup"))
  4030. return;
  4031. cy_flush_buffer(tty);
  4032. shutdown(info);
  4033. info->event = 0;
  4034. info->count = 0;
  4035. #ifdef CY_DEBUG_COUNT
  4036. printk(KERN_DEBUG "cyc:cy_hangup (%d): setting count to 0\n",
  4037. current->pid);
  4038. #endif
  4039. info->tty = NULL;
  4040. info->flags &= ~ASYNC_NORMAL_ACTIVE;
  4041. wake_up_interruptible(&info->open_wait);
  4042. } /* cy_hangup */
  4043. /*
  4044. * ---------------------------------------------------------------------
  4045. * cy_init() and friends
  4046. *
  4047. * cy_init() is called at boot-time to initialize the serial driver.
  4048. * ---------------------------------------------------------------------
  4049. */
  4050. static int __devinit cy_init_card(struct cyclades_card *cinfo)
  4051. {
  4052. struct cyclades_port *info;
  4053. u32 uninitialized_var(mailbox);
  4054. unsigned int nports;
  4055. unsigned short chip_number;
  4056. int uninitialized_var(index), port;
  4057. spin_lock_init(&cinfo->card_lock);
  4058. if (IS_CYC_Z(*cinfo)) { /* Cyclades-Z */
  4059. mailbox = readl(&((struct RUNTIME_9060 __iomem *)
  4060. cinfo->ctl_addr)->mail_box_0);
  4061. nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
  4062. cinfo->intr_enabled = 0;
  4063. cinfo->nports = 0; /* Will be correctly set later, after
  4064. Z FW is loaded */
  4065. } else {
  4066. index = cinfo->bus_index;
  4067. nports = cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips;
  4068. }
  4069. cinfo->ports = kzalloc(sizeof(*cinfo->ports) * nports, GFP_KERNEL);
  4070. if (cinfo->ports == NULL) {
  4071. printk(KERN_ERR "Cyclades: cannot allocate ports\n");
  4072. cinfo->nports = 0;
  4073. return -ENOMEM;
  4074. }
  4075. for (port = cinfo->first_line; port < cinfo->first_line + nports;
  4076. port++) {
  4077. info = &cinfo->ports[port - cinfo->first_line];
  4078. info->magic = CYCLADES_MAGIC;
  4079. info->card = cinfo;
  4080. info->line = port;
  4081. info->flags = STD_COM_FLAGS;
  4082. info->closing_wait = CLOSING_WAIT_DELAY;
  4083. info->close_delay = 5 * HZ / 10;
  4084. INIT_WORK(&info->tqueue, do_softint);
  4085. init_waitqueue_head(&info->open_wait);
  4086. init_waitqueue_head(&info->close_wait);
  4087. init_completion(&info->shutdown_wait);
  4088. init_waitqueue_head(&info->delta_msr_wait);
  4089. if (IS_CYC_Z(*cinfo)) {
  4090. info->type = PORT_STARTECH;
  4091. if (mailbox == ZO_V1)
  4092. info->xmit_fifo_size = CYZ_FIFO_SIZE;
  4093. else
  4094. info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE;
  4095. #ifdef CONFIG_CYZ_INTR
  4096. setup_timer(&cyz_rx_full_timer[port],
  4097. cyz_rx_restart, (unsigned long)info);
  4098. #endif
  4099. } else {
  4100. info->type = PORT_CIRRUS;
  4101. info->xmit_fifo_size = CyMAX_CHAR_FIFO;
  4102. info->cor1 = CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS;
  4103. info->cor2 = CyETC;
  4104. info->cor3 = 0x08; /* _very_ small rcv threshold */
  4105. chip_number = (port - cinfo->first_line) / 4;
  4106. if ((info->chip_rev = readb(cinfo->base_addr +
  4107. (cy_chip_offset[chip_number] <<
  4108. index) + (CyGFRCR << index))) >=
  4109. CD1400_REV_J) {
  4110. /* It is a CD1400 rev. J or later */
  4111. info->tbpr = baud_bpr_60[13]; /* Tx BPR */
  4112. info->tco = baud_co_60[13]; /* Tx CO */
  4113. info->rbpr = baud_bpr_60[13]; /* Rx BPR */
  4114. info->rco = baud_co_60[13]; /* Rx CO */
  4115. info->rtsdtr_inv = 1;
  4116. } else {
  4117. info->tbpr = baud_bpr_25[13]; /* Tx BPR */
  4118. info->tco = baud_co_25[13]; /* Tx CO */
  4119. info->rbpr = baud_bpr_25[13]; /* Rx BPR */
  4120. info->rco = baud_co_25[13]; /* Rx CO */
  4121. info->rtsdtr_inv = 0;
  4122. }
  4123. info->read_status_mask = CyTIMEOUT | CySPECHAR |
  4124. CyBREAK | CyPARITY | CyFRAME | CyOVERRUN;
  4125. }
  4126. }
  4127. #ifndef CONFIG_CYZ_INTR
  4128. if (IS_CYC_Z(*cinfo) && !timer_pending(&cyz_timerlist)) {
  4129. mod_timer(&cyz_timerlist, jiffies + 1);
  4130. #ifdef CY_PCI_DEBUG
  4131. printk(KERN_DEBUG "Cyclades-Z polling initialized\n");
  4132. #endif
  4133. }
  4134. #endif
  4135. return 0;
  4136. }
  4137. /* initialize chips on Cyclom-Y card -- return number of valid
  4138. chips (which is number of ports/4) */
  4139. static unsigned short __devinit cyy_init_card(void __iomem *true_base_addr,
  4140. int index)
  4141. {
  4142. unsigned int chip_number;
  4143. void __iomem *base_addr;
  4144. cy_writeb(true_base_addr + (Cy_HwReset << index), 0);
  4145. /* Cy_HwReset is 0x1400 */
  4146. cy_writeb(true_base_addr + (Cy_ClrIntr << index), 0);
  4147. /* Cy_ClrIntr is 0x1800 */
  4148. udelay(500L);
  4149. for (chip_number = 0; chip_number < CyMAX_CHIPS_PER_CARD; chip_number++) {
  4150. base_addr =
  4151. true_base_addr + (cy_chip_offset[chip_number] << index);
  4152. mdelay(1);
  4153. if (readb(base_addr + (CyCCR << index)) != 0x00) {
  4154. /*************
  4155. printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
  4156. chip_number, (unsigned long)base_addr);
  4157. *************/
  4158. return chip_number;
  4159. }
  4160. cy_writeb(base_addr + (CyGFRCR << index), 0);
  4161. udelay(10L);
  4162. /* The Cyclom-16Y does not decode address bit 9 and therefore
  4163. cannot distinguish between references to chip 0 and a non-
  4164. existent chip 4. If the preceding clearing of the supposed
  4165. chip 4 GFRCR register appears at chip 0, there is no chip 4
  4166. and this must be a Cyclom-16Y, not a Cyclom-32Ye.
  4167. */
  4168. if (chip_number == 4 && readb(true_base_addr +
  4169. (cy_chip_offset[0] << index) +
  4170. (CyGFRCR << index)) == 0) {
  4171. return chip_number;
  4172. }
  4173. cy_writeb(base_addr + (CyCCR << index), CyCHIP_RESET);
  4174. mdelay(1);
  4175. if (readb(base_addr + (CyGFRCR << index)) == 0x00) {
  4176. /*
  4177. printk(" chip #%d at %#6lx is not responding ",
  4178. chip_number, (unsigned long)base_addr);
  4179. printk("(GFRCR stayed 0)\n",
  4180. */
  4181. return chip_number;
  4182. }
  4183. if ((0xf0 & (readb(base_addr + (CyGFRCR << index)))) !=
  4184. 0x40) {
  4185. /*
  4186. printk(" chip #%d at %#6lx is not valid (GFRCR == "
  4187. "%#2x)\n",
  4188. chip_number, (unsigned long)base_addr,
  4189. base_addr[CyGFRCR<<index]);
  4190. */
  4191. return chip_number;
  4192. }
  4193. cy_writeb(base_addr + (CyGCR << index), CyCH0_SERIAL);
  4194. if (readb(base_addr + (CyGFRCR << index)) >= CD1400_REV_J) {
  4195. /* It is a CD1400 rev. J or later */
  4196. /* Impossible to reach 5ms with this chip.
  4197. Changed to 2ms instead (f = 500 Hz). */
  4198. cy_writeb(base_addr + (CyPPR << index), CyCLOCK_60_2MS);
  4199. } else {
  4200. /* f = 200 Hz */
  4201. cy_writeb(base_addr + (CyPPR << index), CyCLOCK_25_5MS);
  4202. }
  4203. /*
  4204. printk(" chip #%d at %#6lx is rev 0x%2x\n",
  4205. chip_number, (unsigned long)base_addr,
  4206. readb(base_addr+(CyGFRCR<<index)));
  4207. */
  4208. }
  4209. return chip_number;
  4210. } /* cyy_init_card */
  4211. /*
  4212. * ---------------------------------------------------------------------
  4213. * cy_detect_isa() - Probe for Cyclom-Y/ISA boards.
  4214. * sets global variables and return the number of ISA boards found.
  4215. * ---------------------------------------------------------------------
  4216. */
  4217. static int __init cy_detect_isa(void)
  4218. {
  4219. #ifdef CONFIG_ISA
  4220. unsigned short cy_isa_irq, nboard;
  4221. void __iomem *cy_isa_address;
  4222. unsigned short i, j, cy_isa_nchan;
  4223. #ifdef MODULE
  4224. int isparam = 0;
  4225. #endif
  4226. nboard = 0;
  4227. #ifdef MODULE
  4228. /* Check for module parameters */
  4229. for (i = 0; i < NR_CARDS; i++) {
  4230. if (maddr[i] || i) {
  4231. isparam = 1;
  4232. cy_isa_addresses[i] = maddr[i];
  4233. }
  4234. if (!maddr[i])
  4235. break;
  4236. }
  4237. #endif
  4238. /* scan the address table probing for Cyclom-Y/ISA boards */
  4239. for (i = 0; i < NR_ISA_ADDRS; i++) {
  4240. unsigned int isa_address = cy_isa_addresses[i];
  4241. if (isa_address == 0x0000) {
  4242. return nboard;
  4243. }
  4244. /* probe for CD1400... */
  4245. cy_isa_address = ioremap(isa_address, CyISA_Ywin);
  4246. if (cy_isa_address == NULL) {
  4247. printk(KERN_ERR "Cyclom-Y/ISA: can't remap base "
  4248. "address\n");
  4249. continue;
  4250. }
  4251. cy_isa_nchan = CyPORTS_PER_CHIP *
  4252. cyy_init_card(cy_isa_address, 0);
  4253. if (cy_isa_nchan == 0) {
  4254. iounmap(cy_isa_address);
  4255. continue;
  4256. }
  4257. #ifdef MODULE
  4258. if (isparam && irq[i])
  4259. cy_isa_irq = irq[i];
  4260. else
  4261. #endif
  4262. /* find out the board's irq by probing */
  4263. cy_isa_irq = detect_isa_irq(cy_isa_address);
  4264. if (cy_isa_irq == 0) {
  4265. printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but the "
  4266. "IRQ could not be detected.\n",
  4267. (unsigned long)cy_isa_address);
  4268. iounmap(cy_isa_address);
  4269. continue;
  4270. }
  4271. if ((cy_next_channel + cy_isa_nchan) > NR_PORTS) {
  4272. printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but no "
  4273. "more channels are available. Change NR_PORTS "
  4274. "in cyclades.c and recompile kernel.\n",
  4275. (unsigned long)cy_isa_address);
  4276. iounmap(cy_isa_address);
  4277. return nboard;
  4278. }
  4279. /* fill the next cy_card structure available */
  4280. for (j = 0; j < NR_CARDS; j++) {
  4281. if (cy_card[j].base_addr == NULL)
  4282. break;
  4283. }
  4284. if (j == NR_CARDS) { /* no more cy_cards available */
  4285. printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but no "
  4286. "more cards can be used. Change NR_CARDS in "
  4287. "cyclades.c and recompile kernel.\n",
  4288. (unsigned long)cy_isa_address);
  4289. iounmap(cy_isa_address);
  4290. return nboard;
  4291. }
  4292. /* allocate IRQ */
  4293. if (request_irq(cy_isa_irq, cyy_interrupt,
  4294. IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) {
  4295. printk(KERN_ERR "Cyclom-Y/ISA found at 0x%lx, but "
  4296. "could not allocate IRQ#%d.\n",
  4297. (unsigned long)cy_isa_address, cy_isa_irq);
  4298. iounmap(cy_isa_address);
  4299. return nboard;
  4300. }
  4301. /* set cy_card */
  4302. cy_card[j].base_addr = cy_isa_address;
  4303. cy_card[j].ctl_addr = NULL;
  4304. cy_card[j].irq = (int)cy_isa_irq;
  4305. cy_card[j].bus_index = 0;
  4306. cy_card[j].first_line = cy_next_channel;
  4307. cy_card[j].num_chips = cy_isa_nchan / 4;
  4308. if (cy_init_card(&cy_card[j])) {
  4309. cy_card[j].base_addr = NULL;
  4310. free_irq(cy_isa_irq, &cy_card[j]);
  4311. iounmap(cy_isa_address);
  4312. continue;
  4313. }
  4314. nboard++;
  4315. printk(KERN_INFO "Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d found: "
  4316. "%d channels starting from port %d\n",
  4317. j + 1, (unsigned long)cy_isa_address,
  4318. (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)),
  4319. cy_isa_irq, cy_isa_nchan, cy_next_channel);
  4320. for (j = cy_next_channel;
  4321. j < cy_next_channel + cy_isa_nchan; j++)
  4322. tty_register_device(cy_serial_driver, j, NULL);
  4323. cy_next_channel += cy_isa_nchan;
  4324. }
  4325. return nboard;
  4326. #else
  4327. return 0;
  4328. #endif /* CONFIG_ISA */
  4329. } /* cy_detect_isa */
  4330. #ifdef CONFIG_PCI
  4331. static inline int __devinit cyc_isfwstr(const char *str, unsigned int size)
  4332. {
  4333. unsigned int a;
  4334. for (a = 0; a < size && *str; a++, str++)
  4335. if (*str & 0x80)
  4336. return -EINVAL;
  4337. for (; a < size; a++, str++)
  4338. if (*str)
  4339. return -EINVAL;
  4340. return 0;
  4341. }
  4342. static inline void __devinit cyz_fpga_copy(void __iomem *fpga, u8 *data,
  4343. unsigned int size)
  4344. {
  4345. for (; size > 0; size--) {
  4346. cy_writel(fpga, *data++);
  4347. udelay(10);
  4348. }
  4349. }
  4350. static void __devinit plx_init(struct pci_dev *pdev, int irq,
  4351. struct RUNTIME_9060 __iomem *addr)
  4352. {
  4353. /* Reset PLX */
  4354. cy_writel(&addr->init_ctrl, readl(&addr->init_ctrl) | 0x40000000);
  4355. udelay(100L);
  4356. cy_writel(&addr->init_ctrl, readl(&addr->init_ctrl) & ~0x40000000);
  4357. /* Reload Config. Registers from EEPROM */
  4358. cy_writel(&addr->init_ctrl, readl(&addr->init_ctrl) | 0x20000000);
  4359. udelay(100L);
  4360. cy_writel(&addr->init_ctrl, readl(&addr->init_ctrl) & ~0x20000000);
  4361. /* For some yet unknown reason, once the PLX9060 reloads the EEPROM,
  4362. * the IRQ is lost and, thus, we have to re-write it to the PCI config.
  4363. * registers. This will remain here until we find a permanent fix.
  4364. */
  4365. pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, irq);
  4366. }
  4367. static int __devinit __cyz_load_fw(const struct firmware *fw,
  4368. const char *name, const u32 mailbox, void __iomem *base,
  4369. void __iomem *fpga)
  4370. {
  4371. void *ptr = fw->data;
  4372. struct zfile_header *h = ptr;
  4373. struct zfile_config *c, *cs;
  4374. struct zfile_block *b, *bs;
  4375. unsigned int a, tmp, len = fw->size;
  4376. #define BAD_FW KERN_ERR "Bad firmware: "
  4377. if (len < sizeof(*h)) {
  4378. printk(BAD_FW "too short: %u<%zu\n", len, sizeof(*h));
  4379. return -EINVAL;
  4380. }
  4381. cs = ptr + h->config_offset;
  4382. bs = ptr + h->block_offset;
  4383. if ((void *)(cs + h->n_config) > ptr + len ||
  4384. (void *)(bs + h->n_blocks) > ptr + len) {
  4385. printk(BAD_FW "too short");
  4386. return -EINVAL;
  4387. }
  4388. if (cyc_isfwstr(h->name, sizeof(h->name)) ||
  4389. cyc_isfwstr(h->date, sizeof(h->date))) {
  4390. printk(BAD_FW "bad formatted header string\n");
  4391. return -EINVAL;
  4392. }
  4393. if (strncmp(name, h->name, sizeof(h->name))) {
  4394. printk(BAD_FW "bad name '%s' (expected '%s')\n", h->name, name);
  4395. return -EINVAL;
  4396. }
  4397. tmp = 0;
  4398. for (c = cs; c < cs + h->n_config; c++) {
  4399. for (a = 0; a < c->n_blocks; a++)
  4400. if (c->block_list[a] > h->n_blocks) {
  4401. printk(BAD_FW "bad block ref number in cfgs\n");
  4402. return -EINVAL;
  4403. }
  4404. if (c->mailbox == mailbox && c->function == 0) /* 0 is normal */
  4405. tmp++;
  4406. }
  4407. if (!tmp) {
  4408. printk(BAD_FW "nothing appropriate\n");
  4409. return -EINVAL;
  4410. }
  4411. for (b = bs; b < bs + h->n_blocks; b++)
  4412. if (b->file_offset + b->size > len) {
  4413. printk(BAD_FW "bad block data offset\n");
  4414. return -EINVAL;
  4415. }
  4416. /* everything is OK, let's seek'n'load it */
  4417. for (c = cs; c < cs + h->n_config; c++)
  4418. if (c->mailbox == mailbox && c->function == 0)
  4419. break;
  4420. for (a = 0; a < c->n_blocks; a++) {
  4421. b = &bs[c->block_list[a]];
  4422. if (b->type == ZBLOCK_FPGA) {
  4423. if (fpga != NULL)
  4424. cyz_fpga_copy(fpga, ptr + b->file_offset,
  4425. b->size);
  4426. } else {
  4427. if (base != NULL)
  4428. memcpy_toio(base + b->ram_offset,
  4429. ptr + b->file_offset, b->size);
  4430. }
  4431. }
  4432. #undef BAD_FW
  4433. return 0;
  4434. }
  4435. static int __devinit cyz_load_fw(struct pci_dev *pdev, void __iomem *base_addr,
  4436. struct RUNTIME_9060 __iomem *ctl_addr, int irq)
  4437. {
  4438. const struct firmware *fw;
  4439. struct FIRM_ID __iomem *fid = base_addr + ID_ADDRESS;
  4440. struct CUSTOM_REG __iomem *cust = base_addr;
  4441. struct ZFW_CTRL __iomem *pt_zfwctrl;
  4442. void __iomem *tmp;
  4443. u32 mailbox, status;
  4444. unsigned int i;
  4445. int retval;
  4446. retval = request_firmware(&fw, "cyzfirm.bin", &pdev->dev);
  4447. if (retval) {
  4448. dev_err(&pdev->dev, "can't get firmware\n");
  4449. goto err;
  4450. }
  4451. /* Check whether the firmware is already loaded and running. If
  4452. positive, skip this board */
  4453. if (Z_FPGA_LOADED(ctl_addr) && readl(&fid->signature) == ZFIRM_ID) {
  4454. u32 cntval = readl(base_addr + 0x190);
  4455. udelay(100);
  4456. if (cntval != readl(base_addr + 0x190)) {
  4457. /* FW counter is working, FW is running */
  4458. dev_dbg(&pdev->dev, "Cyclades-Z FW already loaded. "
  4459. "Skipping board.\n");
  4460. retval = 0;
  4461. goto err_rel;
  4462. }
  4463. }
  4464. /* start boot */
  4465. cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) &
  4466. ~0x00030800UL);
  4467. mailbox = readl(&ctl_addr->mail_box_0);
  4468. if (mailbox == 0 || Z_FPGA_LOADED(ctl_addr)) {
  4469. /* stops CPU and set window to beginning of RAM */
  4470. cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
  4471. cy_writel(&cust->cpu_stop, 0);
  4472. cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
  4473. udelay(100);
  4474. }
  4475. plx_init(pdev, irq, ctl_addr);
  4476. if (mailbox != 0) {
  4477. /* load FPGA */
  4478. retval = __cyz_load_fw(fw, "Cyclom-Z", mailbox, NULL,
  4479. base_addr);
  4480. if (retval)
  4481. goto err_rel;
  4482. if (!Z_FPGA_LOADED(ctl_addr)) {
  4483. dev_err(&pdev->dev, "fw upload successful, but fw is "
  4484. "not loaded\n");
  4485. goto err_rel;
  4486. }
  4487. }
  4488. /* stops CPU and set window to beginning of RAM */
  4489. cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
  4490. cy_writel(&cust->cpu_stop, 0);
  4491. cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
  4492. udelay(100);
  4493. /* clear memory */
  4494. for (tmp = base_addr; tmp < base_addr + RAM_SIZE; tmp++)
  4495. cy_writeb(tmp, 255);
  4496. if (mailbox != 0) {
  4497. /* set window to last 512K of RAM */
  4498. cy_writel(&ctl_addr->loc_addr_base, WIN_RAM + RAM_SIZE);
  4499. //sleep(1);
  4500. for (tmp = base_addr; tmp < base_addr + RAM_SIZE; tmp++)
  4501. cy_writeb(tmp, 255);
  4502. /* set window to beginning of RAM */
  4503. cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
  4504. //sleep(1);
  4505. }
  4506. retval = __cyz_load_fw(fw, "Cyclom-Z", mailbox, base_addr, NULL);
  4507. release_firmware(fw);
  4508. if (retval)
  4509. goto err;
  4510. /* finish boot and start boards */
  4511. cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
  4512. cy_writel(&cust->cpu_start, 0);
  4513. cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
  4514. i = 0;
  4515. while ((status = readl(&fid->signature)) != ZFIRM_ID && i++ < 40)
  4516. msleep(100);
  4517. if (status != ZFIRM_ID) {
  4518. if (status == ZFIRM_HLT) {
  4519. dev_err(&pdev->dev, "you need an external power supply "
  4520. "for this number of ports. Firmware halted and "
  4521. "board reset.\n");
  4522. retval = -EIO;
  4523. goto err;
  4524. }
  4525. dev_warn(&pdev->dev, "fid->signature = 0x%x... Waiting "
  4526. "some more time\n", status);
  4527. while ((status = readl(&fid->signature)) != ZFIRM_ID &&
  4528. i++ < 200)
  4529. msleep(100);
  4530. if (status != ZFIRM_ID) {
  4531. dev_err(&pdev->dev, "Board not started in 20 seconds! "
  4532. "Giving up. (fid->signature = 0x%x)\n",
  4533. status);
  4534. dev_info(&pdev->dev, "*** Warning ***: if you are "
  4535. "upgrading the FW, please power cycle the "
  4536. "system before loading the new FW to the "
  4537. "Cyclades-Z.\n");
  4538. if (Z_FPGA_LOADED(ctl_addr))
  4539. plx_init(pdev, irq, ctl_addr);
  4540. retval = -EIO;
  4541. goto err;
  4542. }
  4543. dev_dbg(&pdev->dev, "Firmware started after %d seconds.\n",
  4544. i / 10);
  4545. }
  4546. pt_zfwctrl = base_addr + readl(&fid->zfwctrl_addr);
  4547. dev_dbg(&pdev->dev, "fid=> %p, zfwctrl_addr=> %x, npt_zfwctrl=> %p\n",
  4548. base_addr + ID_ADDRESS, readl(&fid->zfwctrl_addr),
  4549. base_addr + readl(&fid->zfwctrl_addr));
  4550. dev_info(&pdev->dev, "Cyclades-Z FW loaded: version = %x, ports = %u\n",
  4551. readl(&pt_zfwctrl->board_ctrl.fw_version),
  4552. readl(&pt_zfwctrl->board_ctrl.n_channel));
  4553. if (readl(&pt_zfwctrl->board_ctrl.n_channel) == 0) {
  4554. dev_warn(&pdev->dev, "no Cyclades-Z ports were found. Please "
  4555. "check the connection between the Z host card and the "
  4556. "serial expanders.\n");
  4557. if (Z_FPGA_LOADED(ctl_addr))
  4558. plx_init(pdev, irq, ctl_addr);
  4559. dev_info(&pdev->dev, "Null number of ports detected. Board "
  4560. "reset.\n");
  4561. retval = 0;
  4562. goto err;
  4563. }
  4564. cy_writel(&pt_zfwctrl->board_ctrl.op_system, C_OS_LINUX);
  4565. cy_writel(&pt_zfwctrl->board_ctrl.dr_version, DRIVER_VERSION);
  4566. /*
  4567. Early firmware failed to start looking for commands.
  4568. This enables firmware interrupts for those commands.
  4569. */
  4570. cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) |
  4571. (1 << 17));
  4572. cy_writel(&ctl_addr->intr_ctrl_stat, readl(&ctl_addr->intr_ctrl_stat) |
  4573. 0x00030800UL);
  4574. plx_init(pdev, irq, ctl_addr);
  4575. return 0;
  4576. err_rel:
  4577. release_firmware(fw);
  4578. err:
  4579. return retval;
  4580. }
  4581. static int __devinit cy_pci_probe(struct pci_dev *pdev,
  4582. const struct pci_device_id *ent)
  4583. {
  4584. void __iomem *addr0 = NULL, *addr2 = NULL;
  4585. char *card_name = NULL;
  4586. u32 mailbox;
  4587. unsigned int device_id, nchan = 0, card_no, i;
  4588. unsigned char plx_ver;
  4589. int retval, irq;
  4590. retval = pci_enable_device(pdev);
  4591. if (retval) {
  4592. dev_err(&pdev->dev, "cannot enable device\n");
  4593. goto err;
  4594. }
  4595. /* read PCI configuration area */
  4596. irq = pdev->irq;
  4597. device_id = pdev->device & ~PCI_DEVICE_ID_MASK;
  4598. #if defined(__alpha__)
  4599. if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */
  4600. dev_err(&pdev->dev, "Cyclom-Y/PCI not supported for low "
  4601. "addresses on Alpha systems.\n");
  4602. retval = -EIO;
  4603. goto err_dis;
  4604. }
  4605. #endif
  4606. if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo) {
  4607. dev_err(&pdev->dev, "Cyclades-Z/PCI not supported for low "
  4608. "addresses\n");
  4609. retval = -EIO;
  4610. goto err_dis;
  4611. }
  4612. if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
  4613. dev_warn(&pdev->dev, "PCI I/O bit incorrectly set. Ignoring "
  4614. "it...\n");
  4615. pdev->resource[2].flags &= ~IORESOURCE_IO;
  4616. }
  4617. retval = pci_request_regions(pdev, "cyclades");
  4618. if (retval) {
  4619. dev_err(&pdev->dev, "failed to reserve resources\n");
  4620. goto err_dis;
  4621. }
  4622. retval = -EIO;
  4623. if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
  4624. device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
  4625. card_name = "Cyclom-Y";
  4626. addr0 = pci_iomap(pdev, 0, CyPCI_Yctl);
  4627. if (addr0 == NULL) {
  4628. dev_err(&pdev->dev, "can't remap ctl region\n");
  4629. goto err_reg;
  4630. }
  4631. addr2 = pci_iomap(pdev, 2, CyPCI_Ywin);
  4632. if (addr2 == NULL) {
  4633. dev_err(&pdev->dev, "can't remap base region\n");
  4634. goto err_unmap;
  4635. }
  4636. nchan = CyPORTS_PER_CHIP * cyy_init_card(addr2, 1);
  4637. if (nchan == 0) {
  4638. dev_err(&pdev->dev, "Cyclom-Y PCI host card with no "
  4639. "Serial-Modules\n");
  4640. return -EIO;
  4641. }
  4642. } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) {
  4643. struct RUNTIME_9060 __iomem *ctl_addr;
  4644. ctl_addr = addr0 = pci_iomap(pdev, 0, CyPCI_Zctl);
  4645. if (addr0 == NULL) {
  4646. dev_err(&pdev->dev, "can't remap ctl region\n");
  4647. goto err_reg;
  4648. }
  4649. /* Disable interrupts on the PLX before resetting it */
  4650. cy_writew(addr0 + 0x68, readw(addr0 + 0x68) & ~0x0900);
  4651. plx_init(pdev, irq, addr0);
  4652. mailbox = (u32)readl(&ctl_addr->mail_box_0);
  4653. addr2 = pci_iomap(pdev, 2, mailbox == ZE_V1 ?
  4654. CyPCI_Ze_win : CyPCI_Zwin);
  4655. if (addr2 == NULL) {
  4656. dev_err(&pdev->dev, "can't remap base region\n");
  4657. goto err_unmap;
  4658. }
  4659. if (mailbox == ZE_V1) {
  4660. card_name = "Cyclades-Ze";
  4661. readl(&ctl_addr->mail_box_0);
  4662. nchan = ZE_V1_NPORTS;
  4663. } else {
  4664. card_name = "Cyclades-8Zo";
  4665. #ifdef CY_PCI_DEBUG
  4666. if (mailbox == ZO_V1) {
  4667. cy_writel(&ctl_addr->loc_addr_base, WIN_CREG);
  4668. dev_info(&pdev->dev, "Cyclades-8Zo/PCI: FPGA "
  4669. "id %lx, ver %lx\n", (ulong)(0xff &
  4670. readl(&((struct CUSTOM_REG *)addr2)->
  4671. fpga_id)), (ulong)(0xff &
  4672. readl(&((struct CUSTOM_REG *)addr2)->
  4673. fpga_version)));
  4674. cy_writel(&ctl_addr->loc_addr_base, WIN_RAM);
  4675. } else {
  4676. dev_info(&pdev->dev, "Cyclades-Z/PCI: New "
  4677. "Cyclades-Z board. FPGA not loaded\n");
  4678. }
  4679. #endif
  4680. /* The following clears the firmware id word. This
  4681. ensures that the driver will not attempt to talk to
  4682. the board until it has been properly initialized.
  4683. */
  4684. if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
  4685. cy_writel(addr2 + ID_ADDRESS, 0L);
  4686. retval = cyz_load_fw(pdev, addr2, addr0, irq);
  4687. if (retval)
  4688. goto err_unmap;
  4689. /* This must be a Cyclades-8Zo/PCI. The extendable
  4690. version will have a different device_id and will
  4691. be allocated its maximum number of ports. */
  4692. nchan = 8;
  4693. }
  4694. }
  4695. if ((cy_next_channel + nchan) > NR_PORTS) {
  4696. dev_err(&pdev->dev, "Cyclades-8Zo/PCI found, but no "
  4697. "channels are available. Change NR_PORTS in "
  4698. "cyclades.c and recompile kernel.\n");
  4699. goto err_unmap;
  4700. }
  4701. /* fill the next cy_card structure available */
  4702. for (card_no = 0; card_no < NR_CARDS; card_no++) {
  4703. if (cy_card[card_no].base_addr == NULL)
  4704. break;
  4705. }
  4706. if (card_no == NR_CARDS) { /* no more cy_cards available */
  4707. dev_err(&pdev->dev, "Cyclades-8Zo/PCI found, but no "
  4708. "more cards can be used. Change NR_CARDS in "
  4709. "cyclades.c and recompile kernel.\n");
  4710. goto err_unmap;
  4711. }
  4712. if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
  4713. device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
  4714. /* allocate IRQ */
  4715. retval = request_irq(irq, cyy_interrupt,
  4716. IRQF_SHARED, "Cyclom-Y", &cy_card[card_no]);
  4717. if (retval) {
  4718. dev_err(&pdev->dev, "could not allocate IRQ\n");
  4719. goto err_unmap;
  4720. }
  4721. cy_card[card_no].num_chips = nchan / 4;
  4722. } else {
  4723. #ifdef CONFIG_CYZ_INTR
  4724. /* allocate IRQ only if board has an IRQ */
  4725. if (irq != 0 && irq != 255) {
  4726. retval = request_irq(irq, cyz_interrupt,
  4727. IRQF_SHARED, "Cyclades-Z",
  4728. &cy_card[card_no]);
  4729. if (retval) {
  4730. dev_err(&pdev->dev, "could not allocate IRQ\n");
  4731. goto err_unmap;
  4732. }
  4733. }
  4734. #endif /* CONFIG_CYZ_INTR */
  4735. cy_card[card_no].num_chips = -1;
  4736. }
  4737. /* set cy_card */
  4738. cy_card[card_no].base_addr = addr2;
  4739. cy_card[card_no].ctl_addr = addr0;
  4740. cy_card[card_no].irq = irq;
  4741. cy_card[card_no].bus_index = 1;
  4742. cy_card[card_no].first_line = cy_next_channel;
  4743. retval = cy_init_card(&cy_card[card_no]);
  4744. if (retval)
  4745. goto err_null;
  4746. pci_set_drvdata(pdev, &cy_card[card_no]);
  4747. if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
  4748. device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
  4749. /* enable interrupts in the PCI interface */
  4750. plx_ver = readb(addr2 + CyPLX_VER) & 0x0f;
  4751. switch (plx_ver) {
  4752. case PLX_9050:
  4753. cy_writeb(addr0 + 0x4c, 0x43);
  4754. break;
  4755. case PLX_9060:
  4756. case PLX_9080:
  4757. default: /* Old boards, use PLX_9060 */
  4758. plx_init(pdev, irq, addr0);
  4759. cy_writew(addr0 + 0x68, readw(addr0 + 0x68) | 0x0900);
  4760. break;
  4761. }
  4762. }
  4763. dev_info(&pdev->dev, "%s/PCI #%d found: %d channels starting from "
  4764. "port %d.\n", card_name, card_no + 1, nchan, cy_next_channel);
  4765. for (i = cy_next_channel; i < cy_next_channel + nchan; i++)
  4766. tty_register_device(cy_serial_driver, i, &pdev->dev);
  4767. cy_next_channel += nchan;
  4768. return 0;
  4769. err_null:
  4770. cy_card[card_no].base_addr = NULL;
  4771. free_irq(irq, &cy_card[card_no]);
  4772. err_unmap:
  4773. pci_iounmap(pdev, addr0);
  4774. if (addr2)
  4775. pci_iounmap(pdev, addr2);
  4776. err_reg:
  4777. pci_release_regions(pdev);
  4778. err_dis:
  4779. pci_disable_device(pdev);
  4780. err:
  4781. return retval;
  4782. }
  4783. static void __devexit cy_pci_remove(struct pci_dev *pdev)
  4784. {
  4785. struct cyclades_card *cinfo = pci_get_drvdata(pdev);
  4786. unsigned int i;
  4787. /* non-Z with old PLX */
  4788. if (!IS_CYC_Z(*cinfo) && (readb(cinfo->base_addr + CyPLX_VER) & 0x0f) ==
  4789. PLX_9050)
  4790. cy_writeb(cinfo->ctl_addr + 0x4c, 0);
  4791. else
  4792. #ifndef CONFIG_CYZ_INTR
  4793. if (!IS_CYC_Z(*cinfo))
  4794. #endif
  4795. cy_writew(cinfo->ctl_addr + 0x68,
  4796. readw(cinfo->ctl_addr + 0x68) & ~0x0900);
  4797. pci_iounmap(pdev, cinfo->base_addr);
  4798. if (cinfo->ctl_addr)
  4799. pci_iounmap(pdev, cinfo->ctl_addr);
  4800. if (cinfo->irq
  4801. #ifndef CONFIG_CYZ_INTR
  4802. && !IS_CYC_Z(*cinfo)
  4803. #endif /* CONFIG_CYZ_INTR */
  4804. )
  4805. free_irq(cinfo->irq, cinfo);
  4806. pci_release_regions(pdev);
  4807. cinfo->base_addr = NULL;
  4808. for (i = cinfo->first_line; i < cinfo->first_line +
  4809. cinfo->nports; i++)
  4810. tty_unregister_device(cy_serial_driver, i);
  4811. cinfo->nports = 0;
  4812. kfree(cinfo->ports);
  4813. }
  4814. static struct pci_driver cy_pci_driver = {
  4815. .name = "cyclades",
  4816. .id_table = cy_pci_dev_id,
  4817. .probe = cy_pci_probe,
  4818. .remove = __devexit_p(cy_pci_remove)
  4819. };
  4820. #endif
  4821. static int
  4822. cyclades_get_proc_info(char *buf, char **start, off_t offset, int length,
  4823. int *eof, void *data)
  4824. {
  4825. struct cyclades_port *info;
  4826. unsigned int i, j;
  4827. int len = 0;
  4828. off_t begin = 0;
  4829. off_t pos = 0;
  4830. int size;
  4831. __u32 cur_jifs = jiffies;
  4832. size = sprintf(buf, "Dev TimeOpen BytesOut IdleOut BytesIn "
  4833. "IdleIn Overruns Ldisc\n");
  4834. pos += size;
  4835. len += size;
  4836. /* Output one line for each known port */
  4837. for (i = 0; i < NR_CARDS; i++)
  4838. for (j = 0; j < cy_card[i].nports; j++) {
  4839. info = &cy_card[i].ports[j];
  4840. if (info->count)
  4841. size = sprintf(buf + len, "%3d %8lu %10lu %8lu "
  4842. "%10lu %8lu %9lu %6ld\n", info->line,
  4843. (cur_jifs - info->idle_stats.in_use) /
  4844. HZ, info->idle_stats.xmit_bytes,
  4845. (cur_jifs - info->idle_stats.xmit_idle)/
  4846. HZ, info->idle_stats.recv_bytes,
  4847. (cur_jifs - info->idle_stats.recv_idle)/
  4848. HZ, info->idle_stats.overruns,
  4849. (long)info->tty->ldisc.num);
  4850. else
  4851. size = sprintf(buf + len, "%3d %8lu %10lu %8lu "
  4852. "%10lu %8lu %9lu %6ld\n",
  4853. info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
  4854. len += size;
  4855. pos = begin + len;
  4856. if (pos < offset) {
  4857. len = 0;
  4858. begin = pos;
  4859. }
  4860. if (pos > offset + length)
  4861. goto done;
  4862. }
  4863. *eof = 1;
  4864. done:
  4865. *start = buf + (offset - begin); /* Start of wanted data */
  4866. len -= (offset - begin); /* Start slop */
  4867. if (len > length)
  4868. len = length; /* Ending slop */
  4869. if (len < 0)
  4870. len = 0;
  4871. return len;
  4872. }
  4873. /* The serial driver boot-time initialization code!
  4874. Hardware I/O ports are mapped to character special devices on a
  4875. first found, first allocated manner. That is, this code searches
  4876. for Cyclom cards in the system. As each is found, it is probed
  4877. to discover how many chips (and thus how many ports) are present.
  4878. These ports are mapped to the tty ports 32 and upward in monotonic
  4879. fashion. If an 8-port card is replaced with a 16-port card, the
  4880. port mapping on a following card will shift.
  4881. This approach is different from what is used in the other serial
  4882. device driver because the Cyclom is more properly a multiplexer,
  4883. not just an aggregation of serial ports on one card.
  4884. If there are more cards with more ports than have been
  4885. statically allocated above, a warning is printed and the
  4886. extra ports are ignored.
  4887. */
  4888. static const struct tty_operations cy_ops = {
  4889. .open = cy_open,
  4890. .close = cy_close,
  4891. .write = cy_write,
  4892. .put_char = cy_put_char,
  4893. .flush_chars = cy_flush_chars,
  4894. .write_room = cy_write_room,
  4895. .chars_in_buffer = cy_chars_in_buffer,
  4896. .flush_buffer = cy_flush_buffer,
  4897. .ioctl = cy_ioctl,
  4898. .throttle = cy_throttle,
  4899. .unthrottle = cy_unthrottle,
  4900. .set_termios = cy_set_termios,
  4901. .stop = cy_stop,
  4902. .start = cy_start,
  4903. .hangup = cy_hangup,
  4904. .break_ctl = cy_break,
  4905. .wait_until_sent = cy_wait_until_sent,
  4906. .read_proc = cyclades_get_proc_info,
  4907. .tiocmget = cy_tiocmget,
  4908. .tiocmset = cy_tiocmset,
  4909. };
  4910. static int __init cy_init(void)
  4911. {
  4912. unsigned int nboards;
  4913. int retval = -ENOMEM;
  4914. cy_serial_driver = alloc_tty_driver(NR_PORTS);
  4915. if (!cy_serial_driver)
  4916. goto err;
  4917. printk(KERN_INFO "Cyclades driver " CY_VERSION " (built %s %s)\n",
  4918. __DATE__, __TIME__);
  4919. /* Initialize the tty_driver structure */
  4920. cy_serial_driver->owner = THIS_MODULE;
  4921. cy_serial_driver->driver_name = "cyclades";
  4922. cy_serial_driver->name = "ttyC";
  4923. cy_serial_driver->major = CYCLADES_MAJOR;
  4924. cy_serial_driver->minor_start = 0;
  4925. cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
  4926. cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
  4927. cy_serial_driver->init_termios = tty_std_termios;
  4928. cy_serial_driver->init_termios.c_cflag =
  4929. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  4930. cy_serial_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
  4931. tty_set_operations(cy_serial_driver, &cy_ops);
  4932. retval = tty_register_driver(cy_serial_driver);
  4933. if (retval) {
  4934. printk(KERN_ERR "Couldn't register Cyclades serial driver\n");
  4935. goto err_frtty;
  4936. }
  4937. /* the code below is responsible to find the boards. Each different
  4938. type of board has its own detection routine. If a board is found,
  4939. the next cy_card structure available is set by the detection
  4940. routine. These functions are responsible for checking the
  4941. availability of cy_card and cy_port data structures and updating
  4942. the cy_next_channel. */
  4943. /* look for isa boards */
  4944. nboards = cy_detect_isa();
  4945. #ifdef CONFIG_PCI
  4946. /* look for pci boards */
  4947. retval = pci_register_driver(&cy_pci_driver);
  4948. if (retval && !nboards)
  4949. goto err_unr;
  4950. #endif
  4951. return 0;
  4952. err_unr:
  4953. tty_unregister_driver(cy_serial_driver);
  4954. err_frtty:
  4955. put_tty_driver(cy_serial_driver);
  4956. err:
  4957. return retval;
  4958. } /* cy_init */
  4959. static void __exit cy_cleanup_module(void)
  4960. {
  4961. struct cyclades_card *card;
  4962. int i, e1;
  4963. #ifndef CONFIG_CYZ_INTR
  4964. del_timer_sync(&cyz_timerlist);
  4965. #endif /* CONFIG_CYZ_INTR */
  4966. if ((e1 = tty_unregister_driver(cy_serial_driver)))
  4967. printk(KERN_ERR "failed to unregister Cyclades serial "
  4968. "driver(%d)\n", e1);
  4969. #ifdef CONFIG_PCI
  4970. pci_unregister_driver(&cy_pci_driver);
  4971. #endif
  4972. for (i = 0; i < NR_CARDS; i++) {
  4973. card = &cy_card[i];
  4974. if (card->base_addr) {
  4975. /* clear interrupt */
  4976. cy_writeb(card->base_addr + Cy_ClrIntr, 0);
  4977. iounmap(card->base_addr);
  4978. if (card->ctl_addr)
  4979. iounmap(card->ctl_addr);
  4980. if (card->irq
  4981. #ifndef CONFIG_CYZ_INTR
  4982. && !IS_CYC_Z(*card)
  4983. #endif /* CONFIG_CYZ_INTR */
  4984. )
  4985. free_irq(card->irq, card);
  4986. for (e1 = card->first_line;
  4987. e1 < card->first_line +
  4988. card->nports; e1++)
  4989. tty_unregister_device(cy_serial_driver, e1);
  4990. kfree(card->ports);
  4991. }
  4992. }
  4993. put_tty_driver(cy_serial_driver);
  4994. } /* cy_cleanup_module */
  4995. module_init(cy_init);
  4996. module_exit(cy_cleanup_module);
  4997. MODULE_LICENSE("GPL");
  4998. MODULE_VERSION(CY_VERSION);