rocket.c 97 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295
  1. /*
  2. * RocketPort device driver for Linux
  3. *
  4. * Written by Theodore Ts'o, 1995, 1996, 1997, 1998, 1999, 2000.
  5. *
  6. * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2003 by Comtrol, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. /*
  23. * Kernel Synchronization:
  24. *
  25. * This driver has 2 kernel control paths - exception handlers (calls into the driver
  26. * from user mode) and the timer bottom half (tasklet). This is a polled driver, interrupts
  27. * are not used.
  28. *
  29. * Critical data:
  30. * - rp_table[], accessed through passed "info" pointers, is a global (static) array of
  31. * serial port state information and the xmit_buf circular buffer. Protected by
  32. * a per port spinlock.
  33. * - xmit_flags[], an array of ints indexed by line (port) number, indicating that there
  34. * is data to be transmitted. Protected by atomic bit operations.
  35. * - rp_num_ports, int indicating number of open ports, protected by atomic operations.
  36. *
  37. * rp_write() and rp_write_char() functions use a per port semaphore to protect against
  38. * simultaneous access to the same port by more than one process.
  39. */
  40. /****** Defines ******/
  41. #define ROCKET_PARANOIA_CHECK
  42. #define ROCKET_DISABLE_SIMUSAGE
  43. #undef ROCKET_SOFT_FLOW
  44. #undef ROCKET_DEBUG_OPEN
  45. #undef ROCKET_DEBUG_INTR
  46. #undef ROCKET_DEBUG_WRITE
  47. #undef ROCKET_DEBUG_FLOW
  48. #undef ROCKET_DEBUG_THROTTLE
  49. #undef ROCKET_DEBUG_WAIT_UNTIL_SENT
  50. #undef ROCKET_DEBUG_RECEIVE
  51. #undef ROCKET_DEBUG_HANGUP
  52. #undef REV_PCI_ORDER
  53. #undef ROCKET_DEBUG_IO
  54. #define POLL_PERIOD HZ/100 /* Polling period .01 seconds (10ms) */
  55. /****** Kernel includes ******/
  56. #include <linux/module.h>
  57. #include <linux/errno.h>
  58. #include <linux/major.h>
  59. #include <linux/kernel.h>
  60. #include <linux/signal.h>
  61. #include <linux/slab.h>
  62. #include <linux/mm.h>
  63. #include <linux/sched.h>
  64. #include <linux/timer.h>
  65. #include <linux/interrupt.h>
  66. #include <linux/tty.h>
  67. #include <linux/tty_driver.h>
  68. #include <linux/tty_flip.h>
  69. #include <linux/string.h>
  70. #include <linux/fcntl.h>
  71. #include <linux/ptrace.h>
  72. #include <linux/mutex.h>
  73. #include <linux/ioport.h>
  74. #include <linux/delay.h>
  75. #include <linux/completion.h>
  76. #include <linux/wait.h>
  77. #include <linux/pci.h>
  78. #include <asm/uaccess.h>
  79. #include <asm/atomic.h>
  80. #include <asm/unaligned.h>
  81. #include <linux/bitops.h>
  82. #include <linux/spinlock.h>
  83. #include <linux/init.h>
  84. /****** RocketPort includes ******/
  85. #include "rocket_int.h"
  86. #include "rocket.h"
  87. #define ROCKET_VERSION "2.09"
  88. #define ROCKET_DATE "12-June-2003"
  89. /****** RocketPort Local Variables ******/
  90. static void rp_do_poll(unsigned long dummy);
  91. static struct tty_driver *rocket_driver;
  92. static struct rocket_version driver_version = {
  93. ROCKET_VERSION, ROCKET_DATE
  94. };
  95. static struct r_port *rp_table[MAX_RP_PORTS]; /* The main repository of serial port state information. */
  96. static unsigned int xmit_flags[NUM_BOARDS]; /* Bit significant, indicates port had data to transmit. */
  97. /* eg. Bit 0 indicates port 0 has xmit data, ... */
  98. static atomic_t rp_num_ports_open; /* Number of serial ports open */
  99. static DEFINE_TIMER(rocket_timer, rp_do_poll, 0, 0);
  100. static unsigned long board1; /* ISA addresses, retrieved from rocketport.conf */
  101. static unsigned long board2;
  102. static unsigned long board3;
  103. static unsigned long board4;
  104. static unsigned long controller;
  105. static int support_low_speed;
  106. static unsigned long modem1;
  107. static unsigned long modem2;
  108. static unsigned long modem3;
  109. static unsigned long modem4;
  110. static unsigned long pc104_1[8];
  111. static unsigned long pc104_2[8];
  112. static unsigned long pc104_3[8];
  113. static unsigned long pc104_4[8];
  114. static unsigned long *pc104[4] = { pc104_1, pc104_2, pc104_3, pc104_4 };
  115. static int rp_baud_base[NUM_BOARDS]; /* Board config info (Someday make a per-board structure) */
  116. static unsigned long rcktpt_io_addr[NUM_BOARDS];
  117. static int rcktpt_type[NUM_BOARDS];
  118. static int is_PCI[NUM_BOARDS];
  119. static rocketModel_t rocketModel[NUM_BOARDS];
  120. static int max_board;
  121. /*
  122. * The following arrays define the interrupt bits corresponding to each AIOP.
  123. * These bits are different between the ISA and regular PCI boards and the
  124. * Universal PCI boards.
  125. */
  126. static Word_t aiop_intr_bits[AIOP_CTL_SIZE] = {
  127. AIOP_INTR_BIT_0,
  128. AIOP_INTR_BIT_1,
  129. AIOP_INTR_BIT_2,
  130. AIOP_INTR_BIT_3
  131. };
  132. static Word_t upci_aiop_intr_bits[AIOP_CTL_SIZE] = {
  133. UPCI_AIOP_INTR_BIT_0,
  134. UPCI_AIOP_INTR_BIT_1,
  135. UPCI_AIOP_INTR_BIT_2,
  136. UPCI_AIOP_INTR_BIT_3
  137. };
  138. static Byte_t RData[RDATASIZE] = {
  139. 0x00, 0x09, 0xf6, 0x82,
  140. 0x02, 0x09, 0x86, 0xfb,
  141. 0x04, 0x09, 0x00, 0x0a,
  142. 0x06, 0x09, 0x01, 0x0a,
  143. 0x08, 0x09, 0x8a, 0x13,
  144. 0x0a, 0x09, 0xc5, 0x11,
  145. 0x0c, 0x09, 0x86, 0x85,
  146. 0x0e, 0x09, 0x20, 0x0a,
  147. 0x10, 0x09, 0x21, 0x0a,
  148. 0x12, 0x09, 0x41, 0xff,
  149. 0x14, 0x09, 0x82, 0x00,
  150. 0x16, 0x09, 0x82, 0x7b,
  151. 0x18, 0x09, 0x8a, 0x7d,
  152. 0x1a, 0x09, 0x88, 0x81,
  153. 0x1c, 0x09, 0x86, 0x7a,
  154. 0x1e, 0x09, 0x84, 0x81,
  155. 0x20, 0x09, 0x82, 0x7c,
  156. 0x22, 0x09, 0x0a, 0x0a
  157. };
  158. static Byte_t RRegData[RREGDATASIZE] = {
  159. 0x00, 0x09, 0xf6, 0x82, /* 00: Stop Rx processor */
  160. 0x08, 0x09, 0x8a, 0x13, /* 04: Tx software flow control */
  161. 0x0a, 0x09, 0xc5, 0x11, /* 08: XON char */
  162. 0x0c, 0x09, 0x86, 0x85, /* 0c: XANY */
  163. 0x12, 0x09, 0x41, 0xff, /* 10: Rx mask char */
  164. 0x14, 0x09, 0x82, 0x00, /* 14: Compare/Ignore #0 */
  165. 0x16, 0x09, 0x82, 0x7b, /* 18: Compare #1 */
  166. 0x18, 0x09, 0x8a, 0x7d, /* 1c: Compare #2 */
  167. 0x1a, 0x09, 0x88, 0x81, /* 20: Interrupt #1 */
  168. 0x1c, 0x09, 0x86, 0x7a, /* 24: Ignore/Replace #1 */
  169. 0x1e, 0x09, 0x84, 0x81, /* 28: Interrupt #2 */
  170. 0x20, 0x09, 0x82, 0x7c, /* 2c: Ignore/Replace #2 */
  171. 0x22, 0x09, 0x0a, 0x0a /* 30: Rx FIFO Enable */
  172. };
  173. static CONTROLLER_T sController[CTL_SIZE] = {
  174. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  175. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
  176. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  177. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
  178. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  179. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}},
  180. {-1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0},
  181. {0, 0, 0, 0}, {-1, -1, -1, -1}, {0, 0, 0, 0}}
  182. };
  183. static Byte_t sBitMapClrTbl[8] = {
  184. 0xfe, 0xfd, 0xfb, 0xf7, 0xef, 0xdf, 0xbf, 0x7f
  185. };
  186. static Byte_t sBitMapSetTbl[8] = {
  187. 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
  188. };
  189. static int sClockPrescale = 0x14;
  190. /*
  191. * Line number is the ttySIx number (x), the Minor number. We
  192. * assign them sequentially, starting at zero. The following
  193. * array keeps track of the line number assigned to a given board/aiop/channel.
  194. */
  195. static unsigned char lineNumbers[MAX_RP_PORTS];
  196. static unsigned long nextLineNumber;
  197. /***** RocketPort Static Prototypes *********/
  198. static int __init init_ISA(int i);
  199. static void rp_wait_until_sent(struct tty_struct *tty, int timeout);
  200. static void rp_flush_buffer(struct tty_struct *tty);
  201. static void rmSpeakerReset(CONTROLLER_T * CtlP, unsigned long model);
  202. static unsigned char GetLineNumber(int ctrl, int aiop, int ch);
  203. static unsigned char SetLineNumber(int ctrl, int aiop, int ch);
  204. static void rp_start(struct tty_struct *tty);
  205. static int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
  206. int ChanNum);
  207. static void sSetInterfaceMode(CHANNEL_T * ChP, Byte_t mode);
  208. static void sFlushRxFIFO(CHANNEL_T * ChP);
  209. static void sFlushTxFIFO(CHANNEL_T * ChP);
  210. static void sEnInterrupts(CHANNEL_T * ChP, Word_t Flags);
  211. static void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags);
  212. static void sModemReset(CONTROLLER_T * CtlP, int chan, int on);
  213. static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on);
  214. static int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data);
  215. static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
  216. ByteIO_t * AiopIOList, int AiopIOListSize,
  217. WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
  218. int PeriodicOnly, int altChanRingIndicator,
  219. int UPCIRingInd);
  220. static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
  221. ByteIO_t * AiopIOList, int AiopIOListSize,
  222. int IRQNum, Byte_t Frequency, int PeriodicOnly);
  223. static int sReadAiopID(ByteIO_t io);
  224. static int sReadAiopNumChan(WordIO_t io);
  225. MODULE_AUTHOR("Theodore Ts'o");
  226. MODULE_DESCRIPTION("Comtrol RocketPort driver");
  227. module_param(board1, ulong, 0);
  228. MODULE_PARM_DESC(board1, "I/O port for (ISA) board #1");
  229. module_param(board2, ulong, 0);
  230. MODULE_PARM_DESC(board2, "I/O port for (ISA) board #2");
  231. module_param(board3, ulong, 0);
  232. MODULE_PARM_DESC(board3, "I/O port for (ISA) board #3");
  233. module_param(board4, ulong, 0);
  234. MODULE_PARM_DESC(board4, "I/O port for (ISA) board #4");
  235. module_param(controller, ulong, 0);
  236. MODULE_PARM_DESC(controller, "I/O port for (ISA) rocketport controller");
  237. module_param(support_low_speed, bool, 0);
  238. MODULE_PARM_DESC(support_low_speed, "1 means support 50 baud, 0 means support 460400 baud");
  239. module_param(modem1, ulong, 0);
  240. MODULE_PARM_DESC(modem1, "1 means (ISA) board #1 is a RocketModem");
  241. module_param(modem2, ulong, 0);
  242. MODULE_PARM_DESC(modem2, "1 means (ISA) board #2 is a RocketModem");
  243. module_param(modem3, ulong, 0);
  244. MODULE_PARM_DESC(modem3, "1 means (ISA) board #3 is a RocketModem");
  245. module_param(modem4, ulong, 0);
  246. MODULE_PARM_DESC(modem4, "1 means (ISA) board #4 is a RocketModem");
  247. module_param_array(pc104_1, ulong, NULL, 0);
  248. MODULE_PARM_DESC(pc104_1, "set interface types for ISA(PC104) board #1 (e.g. pc104_1=232,232,485,485,...");
  249. module_param_array(pc104_2, ulong, NULL, 0);
  250. MODULE_PARM_DESC(pc104_2, "set interface types for ISA(PC104) board #2 (e.g. pc104_2=232,232,485,485,...");
  251. module_param_array(pc104_3, ulong, NULL, 0);
  252. MODULE_PARM_DESC(pc104_3, "set interface types for ISA(PC104) board #3 (e.g. pc104_3=232,232,485,485,...");
  253. module_param_array(pc104_4, ulong, NULL, 0);
  254. MODULE_PARM_DESC(pc104_4, "set interface types for ISA(PC104) board #4 (e.g. pc104_4=232,232,485,485,...");
  255. static int rp_init(void);
  256. static void rp_cleanup_module(void);
  257. module_init(rp_init);
  258. module_exit(rp_cleanup_module);
  259. MODULE_LICENSE("Dual BSD/GPL");
  260. /*************************************************************************/
  261. /* Module code starts here */
  262. static inline int rocket_paranoia_check(struct r_port *info,
  263. const char *routine)
  264. {
  265. #ifdef ROCKET_PARANOIA_CHECK
  266. if (!info)
  267. return 1;
  268. if (info->magic != RPORT_MAGIC) {
  269. printk(KERN_WARNING "Warning: bad magic number for rocketport "
  270. "struct in %s\n", routine);
  271. return 1;
  272. }
  273. #endif
  274. return 0;
  275. }
  276. /* Serial port receive data function. Called (from timer poll) when an AIOPIC signals
  277. * that receive data is present on a serial port. Pulls data from FIFO, moves it into the
  278. * tty layer.
  279. */
  280. static void rp_do_receive(struct r_port *info,
  281. struct tty_struct *tty,
  282. CHANNEL_t * cp, unsigned int ChanStatus)
  283. {
  284. unsigned int CharNStat;
  285. int ToRecv, wRecv, space;
  286. unsigned char *cbuf;
  287. ToRecv = sGetRxCnt(cp);
  288. #ifdef ROCKET_DEBUG_INTR
  289. printk(KERN_INFO "rp_do_receive(%d)...\n", ToRecv);
  290. #endif
  291. if (ToRecv == 0)
  292. return;
  293. /*
  294. * if status indicates there are errored characters in the
  295. * FIFO, then enter status mode (a word in FIFO holds
  296. * character and status).
  297. */
  298. if (ChanStatus & (RXFOVERFL | RXBREAK | RXFRAME | RXPARITY)) {
  299. if (!(ChanStatus & STATMODE)) {
  300. #ifdef ROCKET_DEBUG_RECEIVE
  301. printk(KERN_INFO "Entering STATMODE...\n");
  302. #endif
  303. ChanStatus |= STATMODE;
  304. sEnRxStatusMode(cp);
  305. }
  306. }
  307. /*
  308. * if we previously entered status mode, then read down the
  309. * FIFO one word at a time, pulling apart the character and
  310. * the status. Update error counters depending on status
  311. */
  312. if (ChanStatus & STATMODE) {
  313. #ifdef ROCKET_DEBUG_RECEIVE
  314. printk(KERN_INFO "Ignore %x, read %x...\n",
  315. info->ignore_status_mask, info->read_status_mask);
  316. #endif
  317. while (ToRecv) {
  318. char flag;
  319. CharNStat = sInW(sGetTxRxDataIO(cp));
  320. #ifdef ROCKET_DEBUG_RECEIVE
  321. printk(KERN_INFO "%x...\n", CharNStat);
  322. #endif
  323. if (CharNStat & STMBREAKH)
  324. CharNStat &= ~(STMFRAMEH | STMPARITYH);
  325. if (CharNStat & info->ignore_status_mask) {
  326. ToRecv--;
  327. continue;
  328. }
  329. CharNStat &= info->read_status_mask;
  330. if (CharNStat & STMBREAKH)
  331. flag = TTY_BREAK;
  332. else if (CharNStat & STMPARITYH)
  333. flag = TTY_PARITY;
  334. else if (CharNStat & STMFRAMEH)
  335. flag = TTY_FRAME;
  336. else if (CharNStat & STMRCVROVRH)
  337. flag = TTY_OVERRUN;
  338. else
  339. flag = TTY_NORMAL;
  340. tty_insert_flip_char(tty, CharNStat & 0xff, flag);
  341. ToRecv--;
  342. }
  343. /*
  344. * after we've emptied the FIFO in status mode, turn
  345. * status mode back off
  346. */
  347. if (sGetRxCnt(cp) == 0) {
  348. #ifdef ROCKET_DEBUG_RECEIVE
  349. printk(KERN_INFO "Status mode off.\n");
  350. #endif
  351. sDisRxStatusMode(cp);
  352. }
  353. } else {
  354. /*
  355. * we aren't in status mode, so read down the FIFO two
  356. * characters at time by doing repeated word IO
  357. * transfer.
  358. */
  359. space = tty_prepare_flip_string(tty, &cbuf, ToRecv);
  360. if (space < ToRecv) {
  361. #ifdef ROCKET_DEBUG_RECEIVE
  362. printk(KERN_INFO "rp_do_receive:insufficient space ToRecv=%d space=%d\n", ToRecv, space);
  363. #endif
  364. if (space <= 0)
  365. return;
  366. ToRecv = space;
  367. }
  368. wRecv = ToRecv >> 1;
  369. if (wRecv)
  370. sInStrW(sGetTxRxDataIO(cp), (unsigned short *) cbuf, wRecv);
  371. if (ToRecv & 1)
  372. cbuf[ToRecv - 1] = sInB(sGetTxRxDataIO(cp));
  373. }
  374. /* Push the data up to the tty layer */
  375. tty_flip_buffer_push(tty);
  376. }
  377. /*
  378. * Serial port transmit data function. Called from the timer polling loop as a
  379. * result of a bit set in xmit_flags[], indicating data (from the tty layer) is ready
  380. * to be sent out the serial port. Data is buffered in rp_table[line].xmit_buf, it is
  381. * moved to the port's xmit FIFO. *info is critical data, protected by spinlocks.
  382. */
  383. static void rp_do_transmit(struct r_port *info)
  384. {
  385. int c;
  386. CHANNEL_t *cp = &info->channel;
  387. struct tty_struct *tty;
  388. unsigned long flags;
  389. #ifdef ROCKET_DEBUG_INTR
  390. printk(KERN_DEBUG "%s\n", __func__);
  391. #endif
  392. if (!info)
  393. return;
  394. if (!info->tty) {
  395. printk(KERN_WARNING "rp: WARNING %s called with "
  396. "info->tty==NULL\n", __func__);
  397. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  398. return;
  399. }
  400. spin_lock_irqsave(&info->slock, flags);
  401. tty = info->tty;
  402. info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
  403. /* Loop sending data to FIFO until done or FIFO full */
  404. while (1) {
  405. if (tty->stopped || tty->hw_stopped)
  406. break;
  407. c = min(info->xmit_fifo_room, info->xmit_cnt);
  408. c = min(c, XMIT_BUF_SIZE - info->xmit_tail);
  409. if (c <= 0 || info->xmit_fifo_room <= 0)
  410. break;
  411. sOutStrW(sGetTxRxDataIO(cp), (unsigned short *) (info->xmit_buf + info->xmit_tail), c / 2);
  412. if (c & 1)
  413. sOutB(sGetTxRxDataIO(cp), info->xmit_buf[info->xmit_tail + c - 1]);
  414. info->xmit_tail += c;
  415. info->xmit_tail &= XMIT_BUF_SIZE - 1;
  416. info->xmit_cnt -= c;
  417. info->xmit_fifo_room -= c;
  418. #ifdef ROCKET_DEBUG_INTR
  419. printk(KERN_INFO "tx %d chars...\n", c);
  420. #endif
  421. }
  422. if (info->xmit_cnt == 0)
  423. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  424. if (info->xmit_cnt < WAKEUP_CHARS) {
  425. tty_wakeup(tty);
  426. #ifdef ROCKETPORT_HAVE_POLL_WAIT
  427. wake_up_interruptible(&tty->poll_wait);
  428. #endif
  429. }
  430. spin_unlock_irqrestore(&info->slock, flags);
  431. #ifdef ROCKET_DEBUG_INTR
  432. printk(KERN_DEBUG "(%d,%d,%d,%d)...\n", info->xmit_cnt, info->xmit_head,
  433. info->xmit_tail, info->xmit_fifo_room);
  434. #endif
  435. }
  436. /*
  437. * Called when a serial port signals it has read data in it's RX FIFO.
  438. * It checks what interrupts are pending and services them, including
  439. * receiving serial data.
  440. */
  441. static void rp_handle_port(struct r_port *info)
  442. {
  443. CHANNEL_t *cp;
  444. struct tty_struct *tty;
  445. unsigned int IntMask, ChanStatus;
  446. if (!info)
  447. return;
  448. if ((info->flags & ROCKET_INITIALIZED) == 0) {
  449. printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
  450. "info->flags & NOT_INIT\n");
  451. return;
  452. }
  453. if (!info->tty) {
  454. printk(KERN_WARNING "rp: WARNING: rp_handle_port called with "
  455. "info->tty==NULL\n");
  456. return;
  457. }
  458. cp = &info->channel;
  459. tty = info->tty;
  460. IntMask = sGetChanIntID(cp) & info->intmask;
  461. #ifdef ROCKET_DEBUG_INTR
  462. printk(KERN_INFO "rp_interrupt %02x...\n", IntMask);
  463. #endif
  464. ChanStatus = sGetChanStatus(cp);
  465. if (IntMask & RXF_TRIG) { /* Rx FIFO trigger level */
  466. rp_do_receive(info, tty, cp, ChanStatus);
  467. }
  468. if (IntMask & DELTA_CD) { /* CD change */
  469. #if (defined(ROCKET_DEBUG_OPEN) || defined(ROCKET_DEBUG_INTR) || defined(ROCKET_DEBUG_HANGUP))
  470. printk(KERN_INFO "ttyR%d CD now %s...\n", info->line,
  471. (ChanStatus & CD_ACT) ? "on" : "off");
  472. #endif
  473. if (!(ChanStatus & CD_ACT) && info->cd_status) {
  474. #ifdef ROCKET_DEBUG_HANGUP
  475. printk(KERN_INFO "CD drop, calling hangup.\n");
  476. #endif
  477. tty_hangup(tty);
  478. }
  479. info->cd_status = (ChanStatus & CD_ACT) ? 1 : 0;
  480. wake_up_interruptible(&info->open_wait);
  481. }
  482. #ifdef ROCKET_DEBUG_INTR
  483. if (IntMask & DELTA_CTS) { /* CTS change */
  484. printk(KERN_INFO "CTS change...\n");
  485. }
  486. if (IntMask & DELTA_DSR) { /* DSR change */
  487. printk(KERN_INFO "DSR change...\n");
  488. }
  489. #endif
  490. }
  491. /*
  492. * The top level polling routine. Repeats every 1/100 HZ (10ms).
  493. */
  494. static void rp_do_poll(unsigned long dummy)
  495. {
  496. CONTROLLER_t *ctlp;
  497. int ctrl, aiop, ch, line;
  498. unsigned int xmitmask, i;
  499. unsigned int CtlMask;
  500. unsigned char AiopMask;
  501. Word_t bit;
  502. /* Walk through all the boards (ctrl's) */
  503. for (ctrl = 0; ctrl < max_board; ctrl++) {
  504. if (rcktpt_io_addr[ctrl] <= 0)
  505. continue;
  506. /* Get a ptr to the board's control struct */
  507. ctlp = sCtlNumToCtlPtr(ctrl);
  508. /* Get the interrupt status from the board */
  509. #ifdef CONFIG_PCI
  510. if (ctlp->BusType == isPCI)
  511. CtlMask = sPCIGetControllerIntStatus(ctlp);
  512. else
  513. #endif
  514. CtlMask = sGetControllerIntStatus(ctlp);
  515. /* Check if any AIOP read bits are set */
  516. for (aiop = 0; CtlMask; aiop++) {
  517. bit = ctlp->AiopIntrBits[aiop];
  518. if (CtlMask & bit) {
  519. CtlMask &= ~bit;
  520. AiopMask = sGetAiopIntStatus(ctlp, aiop);
  521. /* Check if any port read bits are set */
  522. for (ch = 0; AiopMask; AiopMask >>= 1, ch++) {
  523. if (AiopMask & 1) {
  524. /* Get the line number (/dev/ttyRx number). */
  525. /* Read the data from the port. */
  526. line = GetLineNumber(ctrl, aiop, ch);
  527. rp_handle_port(rp_table[line]);
  528. }
  529. }
  530. }
  531. }
  532. xmitmask = xmit_flags[ctrl];
  533. /*
  534. * xmit_flags contains bit-significant flags, indicating there is data
  535. * to xmit on the port. Bit 0 is port 0 on this board, bit 1 is port
  536. * 1, ... (32 total possible). The variable i has the aiop and ch
  537. * numbers encoded in it (port 0-7 are aiop0, 8-15 are aiop1, etc).
  538. */
  539. if (xmitmask) {
  540. for (i = 0; i < rocketModel[ctrl].numPorts; i++) {
  541. if (xmitmask & (1 << i)) {
  542. aiop = (i & 0x18) >> 3;
  543. ch = i & 0x07;
  544. line = GetLineNumber(ctrl, aiop, ch);
  545. rp_do_transmit(rp_table[line]);
  546. }
  547. }
  548. }
  549. }
  550. /*
  551. * Reset the timer so we get called at the next clock tick (10ms).
  552. */
  553. if (atomic_read(&rp_num_ports_open))
  554. mod_timer(&rocket_timer, jiffies + POLL_PERIOD);
  555. }
  556. /*
  557. * Initializes the r_port structure for a port, as well as enabling the port on
  558. * the board.
  559. * Inputs: board, aiop, chan numbers
  560. */
  561. static void init_r_port(int board, int aiop, int chan, struct pci_dev *pci_dev)
  562. {
  563. unsigned rocketMode;
  564. struct r_port *info;
  565. int line;
  566. CONTROLLER_T *ctlp;
  567. /* Get the next available line number */
  568. line = SetLineNumber(board, aiop, chan);
  569. ctlp = sCtlNumToCtlPtr(board);
  570. /* Get a r_port struct for the port, fill it in and save it globally, indexed by line number */
  571. info = kzalloc(sizeof (struct r_port), GFP_KERNEL);
  572. if (!info) {
  573. printk(KERN_ERR "Couldn't allocate info struct for line #%d\n",
  574. line);
  575. return;
  576. }
  577. info->magic = RPORT_MAGIC;
  578. info->line = line;
  579. info->ctlp = ctlp;
  580. info->board = board;
  581. info->aiop = aiop;
  582. info->chan = chan;
  583. info->closing_wait = 3000;
  584. info->close_delay = 50;
  585. init_waitqueue_head(&info->open_wait);
  586. init_completion(&info->close_wait);
  587. info->flags &= ~ROCKET_MODE_MASK;
  588. switch (pc104[board][line]) {
  589. case 422:
  590. info->flags |= ROCKET_MODE_RS422;
  591. break;
  592. case 485:
  593. info->flags |= ROCKET_MODE_RS485;
  594. break;
  595. case 232:
  596. default:
  597. info->flags |= ROCKET_MODE_RS232;
  598. break;
  599. }
  600. info->intmask = RXF_TRIG | TXFIFO_MT | SRC_INT | DELTA_CD | DELTA_CTS | DELTA_DSR;
  601. if (sInitChan(ctlp, &info->channel, aiop, chan) == 0) {
  602. printk(KERN_ERR "RocketPort sInitChan(%d, %d, %d) failed!\n",
  603. board, aiop, chan);
  604. kfree(info);
  605. return;
  606. }
  607. rocketMode = info->flags & ROCKET_MODE_MASK;
  608. if ((info->flags & ROCKET_RTS_TOGGLE) || (rocketMode == ROCKET_MODE_RS485))
  609. sEnRTSToggle(&info->channel);
  610. else
  611. sDisRTSToggle(&info->channel);
  612. if (ctlp->boardType == ROCKET_TYPE_PC104) {
  613. switch (rocketMode) {
  614. case ROCKET_MODE_RS485:
  615. sSetInterfaceMode(&info->channel, InterfaceModeRS485);
  616. break;
  617. case ROCKET_MODE_RS422:
  618. sSetInterfaceMode(&info->channel, InterfaceModeRS422);
  619. break;
  620. case ROCKET_MODE_RS232:
  621. default:
  622. if (info->flags & ROCKET_RTS_TOGGLE)
  623. sSetInterfaceMode(&info->channel, InterfaceModeRS232T);
  624. else
  625. sSetInterfaceMode(&info->channel, InterfaceModeRS232);
  626. break;
  627. }
  628. }
  629. spin_lock_init(&info->slock);
  630. mutex_init(&info->write_mtx);
  631. rp_table[line] = info;
  632. tty_register_device(rocket_driver, line, pci_dev ? &pci_dev->dev :
  633. NULL);
  634. }
  635. /*
  636. * Configures a rocketport port according to its termio settings. Called from
  637. * user mode into the driver (exception handler). *info CD manipulation is spinlock protected.
  638. */
  639. static void configure_r_port(struct r_port *info,
  640. struct ktermios *old_termios)
  641. {
  642. unsigned cflag;
  643. unsigned long flags;
  644. unsigned rocketMode;
  645. int bits, baud, divisor;
  646. CHANNEL_t *cp;
  647. struct ktermios *t = info->tty->termios;
  648. cp = &info->channel;
  649. cflag = t->c_cflag;
  650. /* Byte size and parity */
  651. if ((cflag & CSIZE) == CS8) {
  652. sSetData8(cp);
  653. bits = 10;
  654. } else {
  655. sSetData7(cp);
  656. bits = 9;
  657. }
  658. if (cflag & CSTOPB) {
  659. sSetStop2(cp);
  660. bits++;
  661. } else {
  662. sSetStop1(cp);
  663. }
  664. if (cflag & PARENB) {
  665. sEnParity(cp);
  666. bits++;
  667. if (cflag & PARODD) {
  668. sSetOddParity(cp);
  669. } else {
  670. sSetEvenParity(cp);
  671. }
  672. } else {
  673. sDisParity(cp);
  674. }
  675. /* baud rate */
  676. baud = tty_get_baud_rate(info->tty);
  677. if (!baud)
  678. baud = 9600;
  679. divisor = ((rp_baud_base[info->board] + (baud >> 1)) / baud) - 1;
  680. if ((divisor >= 8192 || divisor < 0) && old_termios) {
  681. baud = tty_termios_baud_rate(old_termios);
  682. if (!baud)
  683. baud = 9600;
  684. divisor = (rp_baud_base[info->board] / baud) - 1;
  685. }
  686. if (divisor >= 8192 || divisor < 0) {
  687. baud = 9600;
  688. divisor = (rp_baud_base[info->board] / baud) - 1;
  689. }
  690. info->cps = baud / bits;
  691. sSetBaud(cp, divisor);
  692. /* FIXME: Should really back compute a baud rate from the divisor */
  693. tty_encode_baud_rate(info->tty, baud, baud);
  694. if (cflag & CRTSCTS) {
  695. info->intmask |= DELTA_CTS;
  696. sEnCTSFlowCtl(cp);
  697. } else {
  698. info->intmask &= ~DELTA_CTS;
  699. sDisCTSFlowCtl(cp);
  700. }
  701. if (cflag & CLOCAL) {
  702. info->intmask &= ~DELTA_CD;
  703. } else {
  704. spin_lock_irqsave(&info->slock, flags);
  705. if (sGetChanStatus(cp) & CD_ACT)
  706. info->cd_status = 1;
  707. else
  708. info->cd_status = 0;
  709. info->intmask |= DELTA_CD;
  710. spin_unlock_irqrestore(&info->slock, flags);
  711. }
  712. /*
  713. * Handle software flow control in the board
  714. */
  715. #ifdef ROCKET_SOFT_FLOW
  716. if (I_IXON(info->tty)) {
  717. sEnTxSoftFlowCtl(cp);
  718. if (I_IXANY(info->tty)) {
  719. sEnIXANY(cp);
  720. } else {
  721. sDisIXANY(cp);
  722. }
  723. sSetTxXONChar(cp, START_CHAR(info->tty));
  724. sSetTxXOFFChar(cp, STOP_CHAR(info->tty));
  725. } else {
  726. sDisTxSoftFlowCtl(cp);
  727. sDisIXANY(cp);
  728. sClrTxXOFF(cp);
  729. }
  730. #endif
  731. /*
  732. * Set up ignore/read mask words
  733. */
  734. info->read_status_mask = STMRCVROVRH | 0xFF;
  735. if (I_INPCK(info->tty))
  736. info->read_status_mask |= STMFRAMEH | STMPARITYH;
  737. if (I_BRKINT(info->tty) || I_PARMRK(info->tty))
  738. info->read_status_mask |= STMBREAKH;
  739. /*
  740. * Characters to ignore
  741. */
  742. info->ignore_status_mask = 0;
  743. if (I_IGNPAR(info->tty))
  744. info->ignore_status_mask |= STMFRAMEH | STMPARITYH;
  745. if (I_IGNBRK(info->tty)) {
  746. info->ignore_status_mask |= STMBREAKH;
  747. /*
  748. * If we're ignoring parity and break indicators,
  749. * ignore overruns too. (For real raw support).
  750. */
  751. if (I_IGNPAR(info->tty))
  752. info->ignore_status_mask |= STMRCVROVRH;
  753. }
  754. rocketMode = info->flags & ROCKET_MODE_MASK;
  755. if ((info->flags & ROCKET_RTS_TOGGLE)
  756. || (rocketMode == ROCKET_MODE_RS485))
  757. sEnRTSToggle(cp);
  758. else
  759. sDisRTSToggle(cp);
  760. sSetRTS(&info->channel);
  761. if (cp->CtlP->boardType == ROCKET_TYPE_PC104) {
  762. switch (rocketMode) {
  763. case ROCKET_MODE_RS485:
  764. sSetInterfaceMode(cp, InterfaceModeRS485);
  765. break;
  766. case ROCKET_MODE_RS422:
  767. sSetInterfaceMode(cp, InterfaceModeRS422);
  768. break;
  769. case ROCKET_MODE_RS232:
  770. default:
  771. if (info->flags & ROCKET_RTS_TOGGLE)
  772. sSetInterfaceMode(cp, InterfaceModeRS232T);
  773. else
  774. sSetInterfaceMode(cp, InterfaceModeRS232);
  775. break;
  776. }
  777. }
  778. }
  779. /* info->count is considered critical, protected by spinlocks. */
  780. static int block_til_ready(struct tty_struct *tty, struct file *filp,
  781. struct r_port *info)
  782. {
  783. DECLARE_WAITQUEUE(wait, current);
  784. int retval;
  785. int do_clocal = 0, extra_count = 0;
  786. unsigned long flags;
  787. /*
  788. * If the device is in the middle of being closed, then block
  789. * until it's done, and then try again.
  790. */
  791. if (tty_hung_up_p(filp))
  792. return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
  793. if (info->flags & ROCKET_CLOSING) {
  794. if (wait_for_completion_interruptible(&info->close_wait))
  795. return -ERESTARTSYS;
  796. return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
  797. }
  798. /*
  799. * If non-blocking mode is set, or the port is not enabled,
  800. * then make the check up front and then exit.
  801. */
  802. if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
  803. info->flags |= ROCKET_NORMAL_ACTIVE;
  804. return 0;
  805. }
  806. if (tty->termios->c_cflag & CLOCAL)
  807. do_clocal = 1;
  808. /*
  809. * Block waiting for the carrier detect and the line to become free. While we are in
  810. * this loop, info->count is dropped by one, so that rp_close() knows when to free things.
  811. * We restore it upon exit, either normal or abnormal.
  812. */
  813. retval = 0;
  814. add_wait_queue(&info->open_wait, &wait);
  815. #ifdef ROCKET_DEBUG_OPEN
  816. printk(KERN_INFO "block_til_ready before block: ttyR%d, count = %d\n", info->line, info->count);
  817. #endif
  818. spin_lock_irqsave(&info->slock, flags);
  819. #ifdef ROCKET_DISABLE_SIMUSAGE
  820. info->flags |= ROCKET_NORMAL_ACTIVE;
  821. #else
  822. if (!tty_hung_up_p(filp)) {
  823. extra_count = 1;
  824. info->count--;
  825. }
  826. #endif
  827. info->blocked_open++;
  828. spin_unlock_irqrestore(&info->slock, flags);
  829. while (1) {
  830. if (tty->termios->c_cflag & CBAUD) {
  831. sSetDTR(&info->channel);
  832. sSetRTS(&info->channel);
  833. }
  834. set_current_state(TASK_INTERRUPTIBLE);
  835. if (tty_hung_up_p(filp) || !(info->flags & ROCKET_INITIALIZED)) {
  836. if (info->flags & ROCKET_HUP_NOTIFY)
  837. retval = -EAGAIN;
  838. else
  839. retval = -ERESTARTSYS;
  840. break;
  841. }
  842. if (!(info->flags & ROCKET_CLOSING) && (do_clocal || (sGetChanStatusLo(&info->channel) & CD_ACT)))
  843. break;
  844. if (signal_pending(current)) {
  845. retval = -ERESTARTSYS;
  846. break;
  847. }
  848. #ifdef ROCKET_DEBUG_OPEN
  849. printk(KERN_INFO "block_til_ready blocking: ttyR%d, count = %d, flags=0x%0x\n",
  850. info->line, info->count, info->flags);
  851. #endif
  852. schedule(); /* Don't hold spinlock here, will hang PC */
  853. }
  854. __set_current_state(TASK_RUNNING);
  855. remove_wait_queue(&info->open_wait, &wait);
  856. spin_lock_irqsave(&info->slock, flags);
  857. if (extra_count)
  858. info->count++;
  859. info->blocked_open--;
  860. spin_unlock_irqrestore(&info->slock, flags);
  861. #ifdef ROCKET_DEBUG_OPEN
  862. printk(KERN_INFO "block_til_ready after blocking: ttyR%d, count = %d\n",
  863. info->line, info->count);
  864. #endif
  865. if (retval)
  866. return retval;
  867. info->flags |= ROCKET_NORMAL_ACTIVE;
  868. return 0;
  869. }
  870. /*
  871. * Exception handler that opens a serial port. Creates xmit_buf storage, fills in
  872. * port's r_port struct. Initializes the port hardware.
  873. */
  874. static int rp_open(struct tty_struct *tty, struct file *filp)
  875. {
  876. struct r_port *info;
  877. int line = 0, retval;
  878. CHANNEL_t *cp;
  879. unsigned long page;
  880. line = tty->index;
  881. if ((line < 0) || (line >= MAX_RP_PORTS) || ((info = rp_table[line]) == NULL))
  882. return -ENXIO;
  883. page = __get_free_page(GFP_KERNEL);
  884. if (!page)
  885. return -ENOMEM;
  886. if (info->flags & ROCKET_CLOSING) {
  887. retval = wait_for_completion_interruptible(&info->close_wait);
  888. free_page(page);
  889. if (retval)
  890. return retval;
  891. return ((info->flags & ROCKET_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
  892. }
  893. /*
  894. * We must not sleep from here until the port is marked fully in use.
  895. */
  896. if (info->xmit_buf)
  897. free_page(page);
  898. else
  899. info->xmit_buf = (unsigned char *) page;
  900. tty->driver_data = info;
  901. info->tty = tty;
  902. if (info->count++ == 0) {
  903. atomic_inc(&rp_num_ports_open);
  904. #ifdef ROCKET_DEBUG_OPEN
  905. printk(KERN_INFO "rocket mod++ = %d...\n",
  906. atomic_read(&rp_num_ports_open));
  907. #endif
  908. }
  909. #ifdef ROCKET_DEBUG_OPEN
  910. printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->count);
  911. #endif
  912. /*
  913. * Info->count is now 1; so it's safe to sleep now.
  914. */
  915. if ((info->flags & ROCKET_INITIALIZED) == 0) {
  916. cp = &info->channel;
  917. sSetRxTrigger(cp, TRIG_1);
  918. if (sGetChanStatus(cp) & CD_ACT)
  919. info->cd_status = 1;
  920. else
  921. info->cd_status = 0;
  922. sDisRxStatusMode(cp);
  923. sFlushRxFIFO(cp);
  924. sFlushTxFIFO(cp);
  925. sEnInterrupts(cp, (TXINT_EN | MCINT_EN | RXINT_EN | SRCINT_EN | CHANINT_EN));
  926. sSetRxTrigger(cp, TRIG_1);
  927. sGetChanStatus(cp);
  928. sDisRxStatusMode(cp);
  929. sClrTxXOFF(cp);
  930. sDisCTSFlowCtl(cp);
  931. sDisTxSoftFlowCtl(cp);
  932. sEnRxFIFO(cp);
  933. sEnTransmit(cp);
  934. info->flags |= ROCKET_INITIALIZED;
  935. /*
  936. * Set up the tty->alt_speed kludge
  937. */
  938. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
  939. info->tty->alt_speed = 57600;
  940. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
  941. info->tty->alt_speed = 115200;
  942. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
  943. info->tty->alt_speed = 230400;
  944. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
  945. info->tty->alt_speed = 460800;
  946. configure_r_port(info, NULL);
  947. if (tty->termios->c_cflag & CBAUD) {
  948. sSetDTR(cp);
  949. sSetRTS(cp);
  950. }
  951. }
  952. /* Starts (or resets) the maint polling loop */
  953. mod_timer(&rocket_timer, jiffies + POLL_PERIOD);
  954. retval = block_til_ready(tty, filp, info);
  955. if (retval) {
  956. #ifdef ROCKET_DEBUG_OPEN
  957. printk(KERN_INFO "rp_open returning after block_til_ready with %d\n", retval);
  958. #endif
  959. return retval;
  960. }
  961. return 0;
  962. }
  963. /*
  964. * Exception handler that closes a serial port. info->count is considered critical.
  965. */
  966. static void rp_close(struct tty_struct *tty, struct file *filp)
  967. {
  968. struct r_port *info = (struct r_port *) tty->driver_data;
  969. unsigned long flags;
  970. int timeout;
  971. CHANNEL_t *cp;
  972. if (rocket_paranoia_check(info, "rp_close"))
  973. return;
  974. #ifdef ROCKET_DEBUG_OPEN
  975. printk(KERN_INFO "rp_close ttyR%d, count = %d\n", info->line, info->count);
  976. #endif
  977. if (tty_hung_up_p(filp))
  978. return;
  979. spin_lock_irqsave(&info->slock, flags);
  980. if ((tty->count == 1) && (info->count != 1)) {
  981. /*
  982. * Uh, oh. tty->count is 1, which means that the tty
  983. * structure will be freed. Info->count should always
  984. * be one in these conditions. If it's greater than
  985. * one, we've got real problems, since it means the
  986. * serial port won't be shutdown.
  987. */
  988. printk(KERN_WARNING "rp_close: bad serial port count; "
  989. "tty->count is 1, info->count is %d\n", info->count);
  990. info->count = 1;
  991. }
  992. if (--info->count < 0) {
  993. printk(KERN_WARNING "rp_close: bad serial port count for "
  994. "ttyR%d: %d\n", info->line, info->count);
  995. info->count = 0;
  996. }
  997. if (info->count) {
  998. spin_unlock_irqrestore(&info->slock, flags);
  999. return;
  1000. }
  1001. info->flags |= ROCKET_CLOSING;
  1002. spin_unlock_irqrestore(&info->slock, flags);
  1003. cp = &info->channel;
  1004. /*
  1005. * Notify the line discpline to only process XON/XOFF characters
  1006. */
  1007. tty->closing = 1;
  1008. /*
  1009. * If transmission was throttled by the application request,
  1010. * just flush the xmit buffer.
  1011. */
  1012. if (tty->flow_stopped)
  1013. rp_flush_buffer(tty);
  1014. /*
  1015. * Wait for the transmit buffer to clear
  1016. */
  1017. if (info->closing_wait != ROCKET_CLOSING_WAIT_NONE)
  1018. tty_wait_until_sent(tty, info->closing_wait);
  1019. /*
  1020. * Before we drop DTR, make sure the UART transmitter
  1021. * has completely drained; this is especially
  1022. * important if there is a transmit FIFO!
  1023. */
  1024. timeout = (sGetTxCnt(cp) + 1) * HZ / info->cps;
  1025. if (timeout == 0)
  1026. timeout = 1;
  1027. rp_wait_until_sent(tty, timeout);
  1028. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1029. sDisTransmit(cp);
  1030. sDisInterrupts(cp, (TXINT_EN | MCINT_EN | RXINT_EN | SRCINT_EN | CHANINT_EN));
  1031. sDisCTSFlowCtl(cp);
  1032. sDisTxSoftFlowCtl(cp);
  1033. sClrTxXOFF(cp);
  1034. sFlushRxFIFO(cp);
  1035. sFlushTxFIFO(cp);
  1036. sClrRTS(cp);
  1037. if (C_HUPCL(tty))
  1038. sClrDTR(cp);
  1039. rp_flush_buffer(tty);
  1040. tty_ldisc_flush(tty);
  1041. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1042. if (info->blocked_open) {
  1043. if (info->close_delay) {
  1044. msleep_interruptible(jiffies_to_msecs(info->close_delay));
  1045. }
  1046. wake_up_interruptible(&info->open_wait);
  1047. } else {
  1048. if (info->xmit_buf) {
  1049. free_page((unsigned long) info->xmit_buf);
  1050. info->xmit_buf = NULL;
  1051. }
  1052. }
  1053. info->flags &= ~(ROCKET_INITIALIZED | ROCKET_CLOSING | ROCKET_NORMAL_ACTIVE);
  1054. tty->closing = 0;
  1055. complete_all(&info->close_wait);
  1056. atomic_dec(&rp_num_ports_open);
  1057. #ifdef ROCKET_DEBUG_OPEN
  1058. printk(KERN_INFO "rocket mod-- = %d...\n",
  1059. atomic_read(&rp_num_ports_open));
  1060. printk(KERN_INFO "rp_close ttyR%d complete shutdown\n", info->line);
  1061. #endif
  1062. }
  1063. static void rp_set_termios(struct tty_struct *tty,
  1064. struct ktermios *old_termios)
  1065. {
  1066. struct r_port *info = (struct r_port *) tty->driver_data;
  1067. CHANNEL_t *cp;
  1068. unsigned cflag;
  1069. if (rocket_paranoia_check(info, "rp_set_termios"))
  1070. return;
  1071. cflag = tty->termios->c_cflag;
  1072. /*
  1073. * This driver doesn't support CS5 or CS6
  1074. */
  1075. if (((cflag & CSIZE) == CS5) || ((cflag & CSIZE) == CS6))
  1076. tty->termios->c_cflag =
  1077. ((cflag & ~CSIZE) | (old_termios->c_cflag & CSIZE));
  1078. /* Or CMSPAR */
  1079. tty->termios->c_cflag &= ~CMSPAR;
  1080. configure_r_port(info, old_termios);
  1081. cp = &info->channel;
  1082. /* Handle transition to B0 status */
  1083. if ((old_termios->c_cflag & CBAUD) && !(tty->termios->c_cflag & CBAUD)) {
  1084. sClrDTR(cp);
  1085. sClrRTS(cp);
  1086. }
  1087. /* Handle transition away from B0 status */
  1088. if (!(old_termios->c_cflag & CBAUD) && (tty->termios->c_cflag & CBAUD)) {
  1089. if (!tty->hw_stopped || !(tty->termios->c_cflag & CRTSCTS))
  1090. sSetRTS(cp);
  1091. sSetDTR(cp);
  1092. }
  1093. if ((old_termios->c_cflag & CRTSCTS) && !(tty->termios->c_cflag & CRTSCTS)) {
  1094. tty->hw_stopped = 0;
  1095. rp_start(tty);
  1096. }
  1097. }
  1098. static void rp_break(struct tty_struct *tty, int break_state)
  1099. {
  1100. struct r_port *info = (struct r_port *) tty->driver_data;
  1101. unsigned long flags;
  1102. if (rocket_paranoia_check(info, "rp_break"))
  1103. return;
  1104. spin_lock_irqsave(&info->slock, flags);
  1105. if (break_state == -1)
  1106. sSendBreak(&info->channel);
  1107. else
  1108. sClrBreak(&info->channel);
  1109. spin_unlock_irqrestore(&info->slock, flags);
  1110. }
  1111. /*
  1112. * sGetChanRI used to be a macro in rocket_int.h. When the functionality for
  1113. * the UPCI boards was added, it was decided to make this a function because
  1114. * the macro was getting too complicated. All cases except the first one
  1115. * (UPCIRingInd) are taken directly from the original macro.
  1116. */
  1117. static int sGetChanRI(CHANNEL_T * ChP)
  1118. {
  1119. CONTROLLER_t *CtlP = ChP->CtlP;
  1120. int ChanNum = ChP->ChanNum;
  1121. int RingInd = 0;
  1122. if (CtlP->UPCIRingInd)
  1123. RingInd = !(sInB(CtlP->UPCIRingInd) & sBitMapSetTbl[ChanNum]);
  1124. else if (CtlP->AltChanRingIndicator)
  1125. RingInd = sInB((ByteIO_t) (ChP->ChanStat + 8)) & DSR_ACT;
  1126. else if (CtlP->boardType == ROCKET_TYPE_PC104)
  1127. RingInd = !(sInB(CtlP->AiopIO[3]) & sBitMapSetTbl[ChanNum]);
  1128. return RingInd;
  1129. }
  1130. /********************************************************************************************/
  1131. /* Here are the routines used by rp_ioctl. These are all called from exception handlers. */
  1132. /*
  1133. * Returns the state of the serial modem control lines. These next 2 functions
  1134. * are the way kernel versions > 2.5 handle modem control lines rather than IOCTLs.
  1135. */
  1136. static int rp_tiocmget(struct tty_struct *tty, struct file *file)
  1137. {
  1138. struct r_port *info = (struct r_port *)tty->driver_data;
  1139. unsigned int control, result, ChanStatus;
  1140. ChanStatus = sGetChanStatusLo(&info->channel);
  1141. control = info->channel.TxControl[3];
  1142. result = ((control & SET_RTS) ? TIOCM_RTS : 0) |
  1143. ((control & SET_DTR) ? TIOCM_DTR : 0) |
  1144. ((ChanStatus & CD_ACT) ? TIOCM_CAR : 0) |
  1145. (sGetChanRI(&info->channel) ? TIOCM_RNG : 0) |
  1146. ((ChanStatus & DSR_ACT) ? TIOCM_DSR : 0) |
  1147. ((ChanStatus & CTS_ACT) ? TIOCM_CTS : 0);
  1148. return result;
  1149. }
  1150. /*
  1151. * Sets the modem control lines
  1152. */
  1153. static int rp_tiocmset(struct tty_struct *tty, struct file *file,
  1154. unsigned int set, unsigned int clear)
  1155. {
  1156. struct r_port *info = (struct r_port *)tty->driver_data;
  1157. if (set & TIOCM_RTS)
  1158. info->channel.TxControl[3] |= SET_RTS;
  1159. if (set & TIOCM_DTR)
  1160. info->channel.TxControl[3] |= SET_DTR;
  1161. if (clear & TIOCM_RTS)
  1162. info->channel.TxControl[3] &= ~SET_RTS;
  1163. if (clear & TIOCM_DTR)
  1164. info->channel.TxControl[3] &= ~SET_DTR;
  1165. out32(info->channel.IndexAddr, info->channel.TxControl);
  1166. return 0;
  1167. }
  1168. static int get_config(struct r_port *info, struct rocket_config __user *retinfo)
  1169. {
  1170. struct rocket_config tmp;
  1171. if (!retinfo)
  1172. return -EFAULT;
  1173. memset(&tmp, 0, sizeof (tmp));
  1174. tmp.line = info->line;
  1175. tmp.flags = info->flags;
  1176. tmp.close_delay = info->close_delay;
  1177. tmp.closing_wait = info->closing_wait;
  1178. tmp.port = rcktpt_io_addr[(info->line >> 5) & 3];
  1179. if (copy_to_user(retinfo, &tmp, sizeof (*retinfo)))
  1180. return -EFAULT;
  1181. return 0;
  1182. }
  1183. static int set_config(struct r_port *info, struct rocket_config __user *new_info)
  1184. {
  1185. struct rocket_config new_serial;
  1186. if (copy_from_user(&new_serial, new_info, sizeof (new_serial)))
  1187. return -EFAULT;
  1188. if (!capable(CAP_SYS_ADMIN))
  1189. {
  1190. if ((new_serial.flags & ~ROCKET_USR_MASK) != (info->flags & ~ROCKET_USR_MASK))
  1191. return -EPERM;
  1192. info->flags = ((info->flags & ~ROCKET_USR_MASK) | (new_serial.flags & ROCKET_USR_MASK));
  1193. configure_r_port(info, NULL);
  1194. return 0;
  1195. }
  1196. info->flags = ((info->flags & ~ROCKET_FLAGS) | (new_serial.flags & ROCKET_FLAGS));
  1197. info->close_delay = new_serial.close_delay;
  1198. info->closing_wait = new_serial.closing_wait;
  1199. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_HI)
  1200. info->tty->alt_speed = 57600;
  1201. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_VHI)
  1202. info->tty->alt_speed = 115200;
  1203. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_SHI)
  1204. info->tty->alt_speed = 230400;
  1205. if ((info->flags & ROCKET_SPD_MASK) == ROCKET_SPD_WARP)
  1206. info->tty->alt_speed = 460800;
  1207. configure_r_port(info, NULL);
  1208. return 0;
  1209. }
  1210. /*
  1211. * This function fills in a rocket_ports struct with information
  1212. * about what boards/ports are in the system. This info is passed
  1213. * to user space. See setrocket.c where the info is used to create
  1214. * the /dev/ttyRx ports.
  1215. */
  1216. static int get_ports(struct r_port *info, struct rocket_ports __user *retports)
  1217. {
  1218. struct rocket_ports tmp;
  1219. int board;
  1220. if (!retports)
  1221. return -EFAULT;
  1222. memset(&tmp, 0, sizeof (tmp));
  1223. tmp.tty_major = rocket_driver->major;
  1224. for (board = 0; board < 4; board++) {
  1225. tmp.rocketModel[board].model = rocketModel[board].model;
  1226. strcpy(tmp.rocketModel[board].modelString, rocketModel[board].modelString);
  1227. tmp.rocketModel[board].numPorts = rocketModel[board].numPorts;
  1228. tmp.rocketModel[board].loadrm2 = rocketModel[board].loadrm2;
  1229. tmp.rocketModel[board].startingPortNumber = rocketModel[board].startingPortNumber;
  1230. }
  1231. if (copy_to_user(retports, &tmp, sizeof (*retports)))
  1232. return -EFAULT;
  1233. return 0;
  1234. }
  1235. static int reset_rm2(struct r_port *info, void __user *arg)
  1236. {
  1237. int reset;
  1238. if (!capable(CAP_SYS_ADMIN))
  1239. return -EPERM;
  1240. if (copy_from_user(&reset, arg, sizeof (int)))
  1241. return -EFAULT;
  1242. if (reset)
  1243. reset = 1;
  1244. if (rcktpt_type[info->board] != ROCKET_TYPE_MODEMII &&
  1245. rcktpt_type[info->board] != ROCKET_TYPE_MODEMIII)
  1246. return -EINVAL;
  1247. if (info->ctlp->BusType == isISA)
  1248. sModemReset(info->ctlp, info->chan, reset);
  1249. else
  1250. sPCIModemReset(info->ctlp, info->chan, reset);
  1251. return 0;
  1252. }
  1253. static int get_version(struct r_port *info, struct rocket_version __user *retvers)
  1254. {
  1255. if (copy_to_user(retvers, &driver_version, sizeof (*retvers)))
  1256. return -EFAULT;
  1257. return 0;
  1258. }
  1259. /* IOCTL call handler into the driver */
  1260. static int rp_ioctl(struct tty_struct *tty, struct file *file,
  1261. unsigned int cmd, unsigned long arg)
  1262. {
  1263. struct r_port *info = (struct r_port *) tty->driver_data;
  1264. void __user *argp = (void __user *)arg;
  1265. int ret = 0;
  1266. if (cmd != RCKP_GET_PORTS && rocket_paranoia_check(info, "rp_ioctl"))
  1267. return -ENXIO;
  1268. lock_kernel();
  1269. switch (cmd) {
  1270. case RCKP_GET_STRUCT:
  1271. if (copy_to_user(argp, info, sizeof (struct r_port)))
  1272. ret = -EFAULT;
  1273. break;
  1274. case RCKP_GET_CONFIG:
  1275. ret = get_config(info, argp);
  1276. break;
  1277. case RCKP_SET_CONFIG:
  1278. ret = set_config(info, argp);
  1279. break;
  1280. case RCKP_GET_PORTS:
  1281. ret = get_ports(info, argp);
  1282. break;
  1283. case RCKP_RESET_RM2:
  1284. ret = reset_rm2(info, argp);
  1285. break;
  1286. case RCKP_GET_VERSION:
  1287. ret = get_version(info, argp);
  1288. break;
  1289. default:
  1290. ret = -ENOIOCTLCMD;
  1291. }
  1292. unlock_kernel();
  1293. return ret;
  1294. }
  1295. static void rp_send_xchar(struct tty_struct *tty, char ch)
  1296. {
  1297. struct r_port *info = (struct r_port *) tty->driver_data;
  1298. CHANNEL_t *cp;
  1299. if (rocket_paranoia_check(info, "rp_send_xchar"))
  1300. return;
  1301. cp = &info->channel;
  1302. if (sGetTxCnt(cp))
  1303. sWriteTxPrioByte(cp, ch);
  1304. else
  1305. sWriteTxByte(sGetTxRxDataIO(cp), ch);
  1306. }
  1307. static void rp_throttle(struct tty_struct *tty)
  1308. {
  1309. struct r_port *info = (struct r_port *) tty->driver_data;
  1310. CHANNEL_t *cp;
  1311. #ifdef ROCKET_DEBUG_THROTTLE
  1312. printk(KERN_INFO "throttle %s: %d....\n", tty->name,
  1313. tty->ldisc.chars_in_buffer(tty));
  1314. #endif
  1315. if (rocket_paranoia_check(info, "rp_throttle"))
  1316. return;
  1317. cp = &info->channel;
  1318. if (I_IXOFF(tty))
  1319. rp_send_xchar(tty, STOP_CHAR(tty));
  1320. sClrRTS(&info->channel);
  1321. }
  1322. static void rp_unthrottle(struct tty_struct *tty)
  1323. {
  1324. struct r_port *info = (struct r_port *) tty->driver_data;
  1325. CHANNEL_t *cp;
  1326. #ifdef ROCKET_DEBUG_THROTTLE
  1327. printk(KERN_INFO "unthrottle %s: %d....\n", tty->name,
  1328. tty->ldisc.chars_in_buffer(tty));
  1329. #endif
  1330. if (rocket_paranoia_check(info, "rp_throttle"))
  1331. return;
  1332. cp = &info->channel;
  1333. if (I_IXOFF(tty))
  1334. rp_send_xchar(tty, START_CHAR(tty));
  1335. sSetRTS(&info->channel);
  1336. }
  1337. /*
  1338. * ------------------------------------------------------------
  1339. * rp_stop() and rp_start()
  1340. *
  1341. * This routines are called before setting or resetting tty->stopped.
  1342. * They enable or disable transmitter interrupts, as necessary.
  1343. * ------------------------------------------------------------
  1344. */
  1345. static void rp_stop(struct tty_struct *tty)
  1346. {
  1347. struct r_port *info = (struct r_port *) tty->driver_data;
  1348. #ifdef ROCKET_DEBUG_FLOW
  1349. printk(KERN_INFO "stop %s: %d %d....\n", tty->name,
  1350. info->xmit_cnt, info->xmit_fifo_room);
  1351. #endif
  1352. if (rocket_paranoia_check(info, "rp_stop"))
  1353. return;
  1354. if (sGetTxCnt(&info->channel))
  1355. sDisTransmit(&info->channel);
  1356. }
  1357. static void rp_start(struct tty_struct *tty)
  1358. {
  1359. struct r_port *info = (struct r_port *) tty->driver_data;
  1360. #ifdef ROCKET_DEBUG_FLOW
  1361. printk(KERN_INFO "start %s: %d %d....\n", tty->name,
  1362. info->xmit_cnt, info->xmit_fifo_room);
  1363. #endif
  1364. if (rocket_paranoia_check(info, "rp_stop"))
  1365. return;
  1366. sEnTransmit(&info->channel);
  1367. set_bit((info->aiop * 8) + info->chan,
  1368. (void *) &xmit_flags[info->board]);
  1369. }
  1370. /*
  1371. * rp_wait_until_sent() --- wait until the transmitter is empty
  1372. */
  1373. static void rp_wait_until_sent(struct tty_struct *tty, int timeout)
  1374. {
  1375. struct r_port *info = (struct r_port *) tty->driver_data;
  1376. CHANNEL_t *cp;
  1377. unsigned long orig_jiffies;
  1378. int check_time, exit_time;
  1379. int txcnt;
  1380. if (rocket_paranoia_check(info, "rp_wait_until_sent"))
  1381. return;
  1382. cp = &info->channel;
  1383. orig_jiffies = jiffies;
  1384. #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
  1385. printk(KERN_INFO "In RP_wait_until_sent(%d) (jiff=%lu)...\n", timeout,
  1386. jiffies);
  1387. printk(KERN_INFO "cps=%d...\n", info->cps);
  1388. #endif
  1389. lock_kernel();
  1390. while (1) {
  1391. txcnt = sGetTxCnt(cp);
  1392. if (!txcnt) {
  1393. if (sGetChanStatusLo(cp) & TXSHRMT)
  1394. break;
  1395. check_time = (HZ / info->cps) / 5;
  1396. } else {
  1397. check_time = HZ * txcnt / info->cps;
  1398. }
  1399. if (timeout) {
  1400. exit_time = orig_jiffies + timeout - jiffies;
  1401. if (exit_time <= 0)
  1402. break;
  1403. if (exit_time < check_time)
  1404. check_time = exit_time;
  1405. }
  1406. if (check_time == 0)
  1407. check_time = 1;
  1408. #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
  1409. printk(KERN_INFO "txcnt = %d (jiff=%lu,check=%d)...\n", txcnt,
  1410. jiffies, check_time);
  1411. #endif
  1412. msleep_interruptible(jiffies_to_msecs(check_time));
  1413. if (signal_pending(current))
  1414. break;
  1415. }
  1416. __set_current_state(TASK_RUNNING);
  1417. unlock_kernel();
  1418. #ifdef ROCKET_DEBUG_WAIT_UNTIL_SENT
  1419. printk(KERN_INFO "txcnt = %d (jiff=%lu)...done\n", txcnt, jiffies);
  1420. #endif
  1421. }
  1422. /*
  1423. * rp_hangup() --- called by tty_hangup() when a hangup is signaled.
  1424. */
  1425. static void rp_hangup(struct tty_struct *tty)
  1426. {
  1427. CHANNEL_t *cp;
  1428. struct r_port *info = (struct r_port *) tty->driver_data;
  1429. if (rocket_paranoia_check(info, "rp_hangup"))
  1430. return;
  1431. #if (defined(ROCKET_DEBUG_OPEN) || defined(ROCKET_DEBUG_HANGUP))
  1432. printk(KERN_INFO "rp_hangup of ttyR%d...\n", info->line);
  1433. #endif
  1434. rp_flush_buffer(tty);
  1435. if (info->flags & ROCKET_CLOSING)
  1436. return;
  1437. if (info->count)
  1438. atomic_dec(&rp_num_ports_open);
  1439. clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1440. info->count = 0;
  1441. info->flags &= ~ROCKET_NORMAL_ACTIVE;
  1442. info->tty = NULL;
  1443. cp = &info->channel;
  1444. sDisRxFIFO(cp);
  1445. sDisTransmit(cp);
  1446. sDisInterrupts(cp, (TXINT_EN | MCINT_EN | RXINT_EN | SRCINT_EN | CHANINT_EN));
  1447. sDisCTSFlowCtl(cp);
  1448. sDisTxSoftFlowCtl(cp);
  1449. sClrTxXOFF(cp);
  1450. info->flags &= ~ROCKET_INITIALIZED;
  1451. wake_up_interruptible(&info->open_wait);
  1452. }
  1453. /*
  1454. * Exception handler - write char routine. The RocketPort driver uses a
  1455. * double-buffering strategy, with the twist that if the in-memory CPU
  1456. * buffer is empty, and there's space in the transmit FIFO, the
  1457. * writing routines will write directly to transmit FIFO.
  1458. * Write buffer and counters protected by spinlocks
  1459. */
  1460. static int rp_put_char(struct tty_struct *tty, unsigned char ch)
  1461. {
  1462. struct r_port *info = (struct r_port *) tty->driver_data;
  1463. CHANNEL_t *cp;
  1464. unsigned long flags;
  1465. if (rocket_paranoia_check(info, "rp_put_char"))
  1466. return 0;
  1467. /*
  1468. * Grab the port write mutex, locking out other processes that try to
  1469. * write to this port
  1470. */
  1471. mutex_lock(&info->write_mtx);
  1472. #ifdef ROCKET_DEBUG_WRITE
  1473. printk(KERN_INFO "rp_put_char %c...\n", ch);
  1474. #endif
  1475. spin_lock_irqsave(&info->slock, flags);
  1476. cp = &info->channel;
  1477. if (!tty->stopped && !tty->hw_stopped && info->xmit_fifo_room == 0)
  1478. info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
  1479. if (tty->stopped || tty->hw_stopped || info->xmit_fifo_room == 0 || info->xmit_cnt != 0) {
  1480. info->xmit_buf[info->xmit_head++] = ch;
  1481. info->xmit_head &= XMIT_BUF_SIZE - 1;
  1482. info->xmit_cnt++;
  1483. set_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1484. } else {
  1485. sOutB(sGetTxRxDataIO(cp), ch);
  1486. info->xmit_fifo_room--;
  1487. }
  1488. spin_unlock_irqrestore(&info->slock, flags);
  1489. mutex_unlock(&info->write_mtx);
  1490. return 1;
  1491. }
  1492. /*
  1493. * Exception handler - write routine, called when user app writes to the device.
  1494. * A per port write mutex is used to protect from another process writing to
  1495. * this port at the same time. This other process could be running on the other CPU
  1496. * or get control of the CPU if the copy_from_user() blocks due to a page fault (swapped out).
  1497. * Spinlocks protect the info xmit members.
  1498. */
  1499. static int rp_write(struct tty_struct *tty,
  1500. const unsigned char *buf, int count)
  1501. {
  1502. struct r_port *info = (struct r_port *) tty->driver_data;
  1503. CHANNEL_t *cp;
  1504. const unsigned char *b;
  1505. int c, retval = 0;
  1506. unsigned long flags;
  1507. if (count <= 0 || rocket_paranoia_check(info, "rp_write"))
  1508. return 0;
  1509. if (mutex_lock_interruptible(&info->write_mtx))
  1510. return -ERESTARTSYS;
  1511. #ifdef ROCKET_DEBUG_WRITE
  1512. printk(KERN_INFO "rp_write %d chars...\n", count);
  1513. #endif
  1514. cp = &info->channel;
  1515. if (!tty->stopped && !tty->hw_stopped && info->xmit_fifo_room < count)
  1516. info->xmit_fifo_room = TXFIFO_SIZE - sGetTxCnt(cp);
  1517. /*
  1518. * If the write queue for the port is empty, and there is FIFO space, stuff bytes
  1519. * into FIFO. Use the write queue for temp storage.
  1520. */
  1521. if (!tty->stopped && !tty->hw_stopped && info->xmit_cnt == 0 && info->xmit_fifo_room > 0) {
  1522. c = min(count, info->xmit_fifo_room);
  1523. b = buf;
  1524. /* Push data into FIFO, 2 bytes at a time */
  1525. sOutStrW(sGetTxRxDataIO(cp), (unsigned short *) b, c / 2);
  1526. /* If there is a byte remaining, write it */
  1527. if (c & 1)
  1528. sOutB(sGetTxRxDataIO(cp), b[c - 1]);
  1529. retval += c;
  1530. buf += c;
  1531. count -= c;
  1532. spin_lock_irqsave(&info->slock, flags);
  1533. info->xmit_fifo_room -= c;
  1534. spin_unlock_irqrestore(&info->slock, flags);
  1535. }
  1536. /* If count is zero, we wrote it all and are done */
  1537. if (!count)
  1538. goto end;
  1539. /* Write remaining data into the port's xmit_buf */
  1540. while (1) {
  1541. if (!info->tty) /* Seemingly obligatory check... */
  1542. goto end;
  1543. c = min(count, XMIT_BUF_SIZE - info->xmit_cnt - 1);
  1544. c = min(c, XMIT_BUF_SIZE - info->xmit_head);
  1545. if (c <= 0)
  1546. break;
  1547. b = buf;
  1548. memcpy(info->xmit_buf + info->xmit_head, b, c);
  1549. spin_lock_irqsave(&info->slock, flags);
  1550. info->xmit_head =
  1551. (info->xmit_head + c) & (XMIT_BUF_SIZE - 1);
  1552. info->xmit_cnt += c;
  1553. spin_unlock_irqrestore(&info->slock, flags);
  1554. buf += c;
  1555. count -= c;
  1556. retval += c;
  1557. }
  1558. if ((retval > 0) && !tty->stopped && !tty->hw_stopped)
  1559. set_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
  1560. end:
  1561. if (info->xmit_cnt < WAKEUP_CHARS) {
  1562. tty_wakeup(tty);
  1563. #ifdef ROCKETPORT_HAVE_POLL_WAIT
  1564. wake_up_interruptible(&tty->poll_wait);
  1565. #endif
  1566. }
  1567. mutex_unlock(&info->write_mtx);
  1568. return retval;
  1569. }
  1570. /*
  1571. * Return the number of characters that can be sent. We estimate
  1572. * only using the in-memory transmit buffer only, and ignore the
  1573. * potential space in the transmit FIFO.
  1574. */
  1575. static int rp_write_room(struct tty_struct *tty)
  1576. {
  1577. struct r_port *info = (struct r_port *) tty->driver_data;
  1578. int ret;
  1579. if (rocket_paranoia_check(info, "rp_write_room"))
  1580. return 0;
  1581. ret = XMIT_BUF_SIZE - info->xmit_cnt - 1;
  1582. if (ret < 0)
  1583. ret = 0;
  1584. #ifdef ROCKET_DEBUG_WRITE
  1585. printk(KERN_INFO "rp_write_room returns %d...\n", ret);
  1586. #endif
  1587. return ret;
  1588. }
  1589. /*
  1590. * Return the number of characters in the buffer. Again, this only
  1591. * counts those characters in the in-memory transmit buffer.
  1592. */
  1593. static int rp_chars_in_buffer(struct tty_struct *tty)
  1594. {
  1595. struct r_port *info = (struct r_port *) tty->driver_data;
  1596. CHANNEL_t *cp;
  1597. if (rocket_paranoia_check(info, "rp_chars_in_buffer"))
  1598. return 0;
  1599. cp = &info->channel;
  1600. #ifdef ROCKET_DEBUG_WRITE
  1601. printk(KERN_INFO "rp_chars_in_buffer returns %d...\n", info->xmit_cnt);
  1602. #endif
  1603. return info->xmit_cnt;
  1604. }
  1605. /*
  1606. * Flushes the TX fifo for a port, deletes data in the xmit_buf stored in the
  1607. * r_port struct for the port. Note that spinlock are used to protect info members,
  1608. * do not call this function if the spinlock is already held.
  1609. */
  1610. static void rp_flush_buffer(struct tty_struct *tty)
  1611. {
  1612. struct r_port *info = (struct r_port *) tty->driver_data;
  1613. CHANNEL_t *cp;
  1614. unsigned long flags;
  1615. if (rocket_paranoia_check(info, "rp_flush_buffer"))
  1616. return;
  1617. spin_lock_irqsave(&info->slock, flags);
  1618. info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
  1619. spin_unlock_irqrestore(&info->slock, flags);
  1620. #ifdef ROCKETPORT_HAVE_POLL_WAIT
  1621. wake_up_interruptible(&tty->poll_wait);
  1622. #endif
  1623. tty_wakeup(tty);
  1624. cp = &info->channel;
  1625. sFlushTxFIFO(cp);
  1626. }
  1627. #ifdef CONFIG_PCI
  1628. static struct pci_device_id __devinitdata rocket_pci_ids[] = {
  1629. { PCI_DEVICE(PCI_VENDOR_ID_RP, PCI_ANY_ID) },
  1630. { }
  1631. };
  1632. MODULE_DEVICE_TABLE(pci, rocket_pci_ids);
  1633. /*
  1634. * Called when a PCI card is found. Retrieves and stores model information,
  1635. * init's aiopic and serial port hardware.
  1636. * Inputs: i is the board number (0-n)
  1637. */
  1638. static __init int register_PCI(int i, struct pci_dev *dev)
  1639. {
  1640. int num_aiops, aiop, max_num_aiops, num_chan, chan;
  1641. unsigned int aiopio[MAX_AIOPS_PER_BOARD];
  1642. char *str, *board_type;
  1643. CONTROLLER_t *ctlp;
  1644. int fast_clock = 0;
  1645. int altChanRingIndicator = 0;
  1646. int ports_per_aiop = 8;
  1647. WordIO_t ConfigIO = 0;
  1648. ByteIO_t UPCIRingInd = 0;
  1649. if (!dev || pci_enable_device(dev))
  1650. return 0;
  1651. rcktpt_io_addr[i] = pci_resource_start(dev, 0);
  1652. rcktpt_type[i] = ROCKET_TYPE_NORMAL;
  1653. rocketModel[i].loadrm2 = 0;
  1654. rocketModel[i].startingPortNumber = nextLineNumber;
  1655. /* Depending on the model, set up some config variables */
  1656. switch (dev->device) {
  1657. case PCI_DEVICE_ID_RP4QUAD:
  1658. str = "Quadcable";
  1659. max_num_aiops = 1;
  1660. ports_per_aiop = 4;
  1661. rocketModel[i].model = MODEL_RP4QUAD;
  1662. strcpy(rocketModel[i].modelString, "RocketPort 4 port w/quad cable");
  1663. rocketModel[i].numPorts = 4;
  1664. break;
  1665. case PCI_DEVICE_ID_RP8OCTA:
  1666. str = "Octacable";
  1667. max_num_aiops = 1;
  1668. rocketModel[i].model = MODEL_RP8OCTA;
  1669. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/octa cable");
  1670. rocketModel[i].numPorts = 8;
  1671. break;
  1672. case PCI_DEVICE_ID_URP8OCTA:
  1673. str = "Octacable";
  1674. max_num_aiops = 1;
  1675. rocketModel[i].model = MODEL_UPCI_RP8OCTA;
  1676. strcpy(rocketModel[i].modelString, "RocketPort UPCI 8 port w/octa cable");
  1677. rocketModel[i].numPorts = 8;
  1678. break;
  1679. case PCI_DEVICE_ID_RP8INTF:
  1680. str = "8";
  1681. max_num_aiops = 1;
  1682. rocketModel[i].model = MODEL_RP8INTF;
  1683. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/external I/F");
  1684. rocketModel[i].numPorts = 8;
  1685. break;
  1686. case PCI_DEVICE_ID_URP8INTF:
  1687. str = "8";
  1688. max_num_aiops = 1;
  1689. rocketModel[i].model = MODEL_UPCI_RP8INTF;
  1690. strcpy(rocketModel[i].modelString, "RocketPort UPCI 8 port w/external I/F");
  1691. rocketModel[i].numPorts = 8;
  1692. break;
  1693. case PCI_DEVICE_ID_RP8J:
  1694. str = "8J";
  1695. max_num_aiops = 1;
  1696. rocketModel[i].model = MODEL_RP8J;
  1697. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/RJ11 connectors");
  1698. rocketModel[i].numPorts = 8;
  1699. break;
  1700. case PCI_DEVICE_ID_RP4J:
  1701. str = "4J";
  1702. max_num_aiops = 1;
  1703. ports_per_aiop = 4;
  1704. rocketModel[i].model = MODEL_RP4J;
  1705. strcpy(rocketModel[i].modelString, "RocketPort 4 port w/RJ45 connectors");
  1706. rocketModel[i].numPorts = 4;
  1707. break;
  1708. case PCI_DEVICE_ID_RP8SNI:
  1709. str = "8 (DB78 Custom)";
  1710. max_num_aiops = 1;
  1711. rocketModel[i].model = MODEL_RP8SNI;
  1712. strcpy(rocketModel[i].modelString, "RocketPort 8 port w/ custom DB78");
  1713. rocketModel[i].numPorts = 8;
  1714. break;
  1715. case PCI_DEVICE_ID_RP16SNI:
  1716. str = "16 (DB78 Custom)";
  1717. max_num_aiops = 2;
  1718. rocketModel[i].model = MODEL_RP16SNI;
  1719. strcpy(rocketModel[i].modelString, "RocketPort 16 port w/ custom DB78");
  1720. rocketModel[i].numPorts = 16;
  1721. break;
  1722. case PCI_DEVICE_ID_RP16INTF:
  1723. str = "16";
  1724. max_num_aiops = 2;
  1725. rocketModel[i].model = MODEL_RP16INTF;
  1726. strcpy(rocketModel[i].modelString, "RocketPort 16 port w/external I/F");
  1727. rocketModel[i].numPorts = 16;
  1728. break;
  1729. case PCI_DEVICE_ID_URP16INTF:
  1730. str = "16";
  1731. max_num_aiops = 2;
  1732. rocketModel[i].model = MODEL_UPCI_RP16INTF;
  1733. strcpy(rocketModel[i].modelString, "RocketPort UPCI 16 port w/external I/F");
  1734. rocketModel[i].numPorts = 16;
  1735. break;
  1736. case PCI_DEVICE_ID_CRP16INTF:
  1737. str = "16";
  1738. max_num_aiops = 2;
  1739. rocketModel[i].model = MODEL_CPCI_RP16INTF;
  1740. strcpy(rocketModel[i].modelString, "RocketPort Compact PCI 16 port w/external I/F");
  1741. rocketModel[i].numPorts = 16;
  1742. break;
  1743. case PCI_DEVICE_ID_RP32INTF:
  1744. str = "32";
  1745. max_num_aiops = 4;
  1746. rocketModel[i].model = MODEL_RP32INTF;
  1747. strcpy(rocketModel[i].modelString, "RocketPort 32 port w/external I/F");
  1748. rocketModel[i].numPorts = 32;
  1749. break;
  1750. case PCI_DEVICE_ID_URP32INTF:
  1751. str = "32";
  1752. max_num_aiops = 4;
  1753. rocketModel[i].model = MODEL_UPCI_RP32INTF;
  1754. strcpy(rocketModel[i].modelString, "RocketPort UPCI 32 port w/external I/F");
  1755. rocketModel[i].numPorts = 32;
  1756. break;
  1757. case PCI_DEVICE_ID_RPP4:
  1758. str = "Plus Quadcable";
  1759. max_num_aiops = 1;
  1760. ports_per_aiop = 4;
  1761. altChanRingIndicator++;
  1762. fast_clock++;
  1763. rocketModel[i].model = MODEL_RPP4;
  1764. strcpy(rocketModel[i].modelString, "RocketPort Plus 4 port");
  1765. rocketModel[i].numPorts = 4;
  1766. break;
  1767. case PCI_DEVICE_ID_RPP8:
  1768. str = "Plus Octacable";
  1769. max_num_aiops = 2;
  1770. ports_per_aiop = 4;
  1771. altChanRingIndicator++;
  1772. fast_clock++;
  1773. rocketModel[i].model = MODEL_RPP8;
  1774. strcpy(rocketModel[i].modelString, "RocketPort Plus 8 port");
  1775. rocketModel[i].numPorts = 8;
  1776. break;
  1777. case PCI_DEVICE_ID_RP2_232:
  1778. str = "Plus 2 (RS-232)";
  1779. max_num_aiops = 1;
  1780. ports_per_aiop = 2;
  1781. altChanRingIndicator++;
  1782. fast_clock++;
  1783. rocketModel[i].model = MODEL_RP2_232;
  1784. strcpy(rocketModel[i].modelString, "RocketPort Plus 2 port RS232");
  1785. rocketModel[i].numPorts = 2;
  1786. break;
  1787. case PCI_DEVICE_ID_RP2_422:
  1788. str = "Plus 2 (RS-422)";
  1789. max_num_aiops = 1;
  1790. ports_per_aiop = 2;
  1791. altChanRingIndicator++;
  1792. fast_clock++;
  1793. rocketModel[i].model = MODEL_RP2_422;
  1794. strcpy(rocketModel[i].modelString, "RocketPort Plus 2 port RS422");
  1795. rocketModel[i].numPorts = 2;
  1796. break;
  1797. case PCI_DEVICE_ID_RP6M:
  1798. max_num_aiops = 1;
  1799. ports_per_aiop = 6;
  1800. str = "6-port";
  1801. /* If revision is 1, the rocketmodem flash must be loaded.
  1802. * If it is 2 it is a "socketed" version. */
  1803. if (dev->revision == 1) {
  1804. rcktpt_type[i] = ROCKET_TYPE_MODEMII;
  1805. rocketModel[i].loadrm2 = 1;
  1806. } else {
  1807. rcktpt_type[i] = ROCKET_TYPE_MODEM;
  1808. }
  1809. rocketModel[i].model = MODEL_RP6M;
  1810. strcpy(rocketModel[i].modelString, "RocketModem 6 port");
  1811. rocketModel[i].numPorts = 6;
  1812. break;
  1813. case PCI_DEVICE_ID_RP4M:
  1814. max_num_aiops = 1;
  1815. ports_per_aiop = 4;
  1816. str = "4-port";
  1817. if (dev->revision == 1) {
  1818. rcktpt_type[i] = ROCKET_TYPE_MODEMII;
  1819. rocketModel[i].loadrm2 = 1;
  1820. } else {
  1821. rcktpt_type[i] = ROCKET_TYPE_MODEM;
  1822. }
  1823. rocketModel[i].model = MODEL_RP4M;
  1824. strcpy(rocketModel[i].modelString, "RocketModem 4 port");
  1825. rocketModel[i].numPorts = 4;
  1826. break;
  1827. default:
  1828. str = "(unknown/unsupported)";
  1829. max_num_aiops = 0;
  1830. break;
  1831. }
  1832. /*
  1833. * Check for UPCI boards.
  1834. */
  1835. switch (dev->device) {
  1836. case PCI_DEVICE_ID_URP32INTF:
  1837. case PCI_DEVICE_ID_URP8INTF:
  1838. case PCI_DEVICE_ID_URP16INTF:
  1839. case PCI_DEVICE_ID_CRP16INTF:
  1840. case PCI_DEVICE_ID_URP8OCTA:
  1841. rcktpt_io_addr[i] = pci_resource_start(dev, 2);
  1842. ConfigIO = pci_resource_start(dev, 1);
  1843. if (dev->device == PCI_DEVICE_ID_URP8OCTA) {
  1844. UPCIRingInd = rcktpt_io_addr[i] + _PCI_9030_RING_IND;
  1845. /*
  1846. * Check for octa or quad cable.
  1847. */
  1848. if (!
  1849. (sInW(ConfigIO + _PCI_9030_GPIO_CTRL) &
  1850. PCI_GPIO_CTRL_8PORT)) {
  1851. str = "Quadcable";
  1852. ports_per_aiop = 4;
  1853. rocketModel[i].numPorts = 4;
  1854. }
  1855. }
  1856. break;
  1857. case PCI_DEVICE_ID_UPCI_RM3_8PORT:
  1858. str = "8 ports";
  1859. max_num_aiops = 1;
  1860. rocketModel[i].model = MODEL_UPCI_RM3_8PORT;
  1861. strcpy(rocketModel[i].modelString, "RocketModem III 8 port");
  1862. rocketModel[i].numPorts = 8;
  1863. rcktpt_io_addr[i] = pci_resource_start(dev, 2);
  1864. UPCIRingInd = rcktpt_io_addr[i] + _PCI_9030_RING_IND;
  1865. ConfigIO = pci_resource_start(dev, 1);
  1866. rcktpt_type[i] = ROCKET_TYPE_MODEMIII;
  1867. break;
  1868. case PCI_DEVICE_ID_UPCI_RM3_4PORT:
  1869. str = "4 ports";
  1870. max_num_aiops = 1;
  1871. rocketModel[i].model = MODEL_UPCI_RM3_4PORT;
  1872. strcpy(rocketModel[i].modelString, "RocketModem III 4 port");
  1873. rocketModel[i].numPorts = 4;
  1874. rcktpt_io_addr[i] = pci_resource_start(dev, 2);
  1875. UPCIRingInd = rcktpt_io_addr[i] + _PCI_9030_RING_IND;
  1876. ConfigIO = pci_resource_start(dev, 1);
  1877. rcktpt_type[i] = ROCKET_TYPE_MODEMIII;
  1878. break;
  1879. default:
  1880. break;
  1881. }
  1882. switch (rcktpt_type[i]) {
  1883. case ROCKET_TYPE_MODEM:
  1884. board_type = "RocketModem";
  1885. break;
  1886. case ROCKET_TYPE_MODEMII:
  1887. board_type = "RocketModem II";
  1888. break;
  1889. case ROCKET_TYPE_MODEMIII:
  1890. board_type = "RocketModem III";
  1891. break;
  1892. default:
  1893. board_type = "RocketPort";
  1894. break;
  1895. }
  1896. if (fast_clock) {
  1897. sClockPrescale = 0x12; /* mod 2 (divide by 3) */
  1898. rp_baud_base[i] = 921600;
  1899. } else {
  1900. /*
  1901. * If support_low_speed is set, use the slow clock
  1902. * prescale, which supports 50 bps
  1903. */
  1904. if (support_low_speed) {
  1905. /* mod 9 (divide by 10) prescale */
  1906. sClockPrescale = 0x19;
  1907. rp_baud_base[i] = 230400;
  1908. } else {
  1909. /* mod 4 (devide by 5) prescale */
  1910. sClockPrescale = 0x14;
  1911. rp_baud_base[i] = 460800;
  1912. }
  1913. }
  1914. for (aiop = 0; aiop < max_num_aiops; aiop++)
  1915. aiopio[aiop] = rcktpt_io_addr[i] + (aiop * 0x40);
  1916. ctlp = sCtlNumToCtlPtr(i);
  1917. num_aiops = sPCIInitController(ctlp, i, aiopio, max_num_aiops, ConfigIO, 0, FREQ_DIS, 0, altChanRingIndicator, UPCIRingInd);
  1918. for (aiop = 0; aiop < max_num_aiops; aiop++)
  1919. ctlp->AiopNumChan[aiop] = ports_per_aiop;
  1920. dev_info(&dev->dev, "comtrol PCI controller #%d found at "
  1921. "address %04lx, %d AIOP(s) (%s), creating ttyR%d - %ld\n",
  1922. i, rcktpt_io_addr[i], num_aiops, rocketModel[i].modelString,
  1923. rocketModel[i].startingPortNumber,
  1924. rocketModel[i].startingPortNumber + rocketModel[i].numPorts-1);
  1925. if (num_aiops <= 0) {
  1926. rcktpt_io_addr[i] = 0;
  1927. return (0);
  1928. }
  1929. is_PCI[i] = 1;
  1930. /* Reset the AIOPIC, init the serial ports */
  1931. for (aiop = 0; aiop < num_aiops; aiop++) {
  1932. sResetAiopByNum(ctlp, aiop);
  1933. num_chan = ports_per_aiop;
  1934. for (chan = 0; chan < num_chan; chan++)
  1935. init_r_port(i, aiop, chan, dev);
  1936. }
  1937. /* Rocket modems must be reset */
  1938. if ((rcktpt_type[i] == ROCKET_TYPE_MODEM) ||
  1939. (rcktpt_type[i] == ROCKET_TYPE_MODEMII) ||
  1940. (rcktpt_type[i] == ROCKET_TYPE_MODEMIII)) {
  1941. num_chan = ports_per_aiop;
  1942. for (chan = 0; chan < num_chan; chan++)
  1943. sPCIModemReset(ctlp, chan, 1);
  1944. msleep(500);
  1945. for (chan = 0; chan < num_chan; chan++)
  1946. sPCIModemReset(ctlp, chan, 0);
  1947. msleep(500);
  1948. rmSpeakerReset(ctlp, rocketModel[i].model);
  1949. }
  1950. return (1);
  1951. }
  1952. /*
  1953. * Probes for PCI cards, inits them if found
  1954. * Input: board_found = number of ISA boards already found, or the
  1955. * starting board number
  1956. * Returns: Number of PCI boards found
  1957. */
  1958. static int __init init_PCI(int boards_found)
  1959. {
  1960. struct pci_dev *dev = NULL;
  1961. int count = 0;
  1962. /* Work through the PCI device list, pulling out ours */
  1963. while ((dev = pci_get_device(PCI_VENDOR_ID_RP, PCI_ANY_ID, dev))) {
  1964. if (register_PCI(count + boards_found, dev))
  1965. count++;
  1966. }
  1967. return (count);
  1968. }
  1969. #endif /* CONFIG_PCI */
  1970. /*
  1971. * Probes for ISA cards
  1972. * Input: i = the board number to look for
  1973. * Returns: 1 if board found, 0 else
  1974. */
  1975. static int __init init_ISA(int i)
  1976. {
  1977. int num_aiops, num_chan = 0, total_num_chan = 0;
  1978. int aiop, chan;
  1979. unsigned int aiopio[MAX_AIOPS_PER_BOARD];
  1980. CONTROLLER_t *ctlp;
  1981. char *type_string;
  1982. /* If io_addr is zero, no board configured */
  1983. if (rcktpt_io_addr[i] == 0)
  1984. return (0);
  1985. /* Reserve the IO region */
  1986. if (!request_region(rcktpt_io_addr[i], 64, "Comtrol RocketPort")) {
  1987. printk(KERN_ERR "Unable to reserve IO region for configured "
  1988. "ISA RocketPort at address 0x%lx, board not "
  1989. "installed...\n", rcktpt_io_addr[i]);
  1990. rcktpt_io_addr[i] = 0;
  1991. return (0);
  1992. }
  1993. ctlp = sCtlNumToCtlPtr(i);
  1994. ctlp->boardType = rcktpt_type[i];
  1995. switch (rcktpt_type[i]) {
  1996. case ROCKET_TYPE_PC104:
  1997. type_string = "(PC104)";
  1998. break;
  1999. case ROCKET_TYPE_MODEM:
  2000. type_string = "(RocketModem)";
  2001. break;
  2002. case ROCKET_TYPE_MODEMII:
  2003. type_string = "(RocketModem II)";
  2004. break;
  2005. default:
  2006. type_string = "";
  2007. break;
  2008. }
  2009. /*
  2010. * If support_low_speed is set, use the slow clock prescale,
  2011. * which supports 50 bps
  2012. */
  2013. if (support_low_speed) {
  2014. sClockPrescale = 0x19; /* mod 9 (divide by 10) prescale */
  2015. rp_baud_base[i] = 230400;
  2016. } else {
  2017. sClockPrescale = 0x14; /* mod 4 (devide by 5) prescale */
  2018. rp_baud_base[i] = 460800;
  2019. }
  2020. for (aiop = 0; aiop < MAX_AIOPS_PER_BOARD; aiop++)
  2021. aiopio[aiop] = rcktpt_io_addr[i] + (aiop * 0x400);
  2022. num_aiops = sInitController(ctlp, i, controller + (i * 0x400), aiopio, MAX_AIOPS_PER_BOARD, 0, FREQ_DIS, 0);
  2023. if (ctlp->boardType == ROCKET_TYPE_PC104) {
  2024. sEnAiop(ctlp, 2); /* only one AIOPIC, but these */
  2025. sEnAiop(ctlp, 3); /* CSels used for other stuff */
  2026. }
  2027. /* If something went wrong initing the AIOP's release the ISA IO memory */
  2028. if (num_aiops <= 0) {
  2029. release_region(rcktpt_io_addr[i], 64);
  2030. rcktpt_io_addr[i] = 0;
  2031. return (0);
  2032. }
  2033. rocketModel[i].startingPortNumber = nextLineNumber;
  2034. for (aiop = 0; aiop < num_aiops; aiop++) {
  2035. sResetAiopByNum(ctlp, aiop);
  2036. sEnAiop(ctlp, aiop);
  2037. num_chan = sGetAiopNumChan(ctlp, aiop);
  2038. total_num_chan += num_chan;
  2039. for (chan = 0; chan < num_chan; chan++)
  2040. init_r_port(i, aiop, chan, NULL);
  2041. }
  2042. is_PCI[i] = 0;
  2043. if ((rcktpt_type[i] == ROCKET_TYPE_MODEM) || (rcktpt_type[i] == ROCKET_TYPE_MODEMII)) {
  2044. num_chan = sGetAiopNumChan(ctlp, 0);
  2045. total_num_chan = num_chan;
  2046. for (chan = 0; chan < num_chan; chan++)
  2047. sModemReset(ctlp, chan, 1);
  2048. msleep(500);
  2049. for (chan = 0; chan < num_chan; chan++)
  2050. sModemReset(ctlp, chan, 0);
  2051. msleep(500);
  2052. strcpy(rocketModel[i].modelString, "RocketModem ISA");
  2053. } else {
  2054. strcpy(rocketModel[i].modelString, "RocketPort ISA");
  2055. }
  2056. rocketModel[i].numPorts = total_num_chan;
  2057. rocketModel[i].model = MODEL_ISA;
  2058. printk(KERN_INFO "RocketPort ISA card #%d found at 0x%lx - %d AIOPs %s\n",
  2059. i, rcktpt_io_addr[i], num_aiops, type_string);
  2060. printk(KERN_INFO "Installing %s, creating /dev/ttyR%d - %ld\n",
  2061. rocketModel[i].modelString,
  2062. rocketModel[i].startingPortNumber,
  2063. rocketModel[i].startingPortNumber +
  2064. rocketModel[i].numPorts - 1);
  2065. return (1);
  2066. }
  2067. static const struct tty_operations rocket_ops = {
  2068. .open = rp_open,
  2069. .close = rp_close,
  2070. .write = rp_write,
  2071. .put_char = rp_put_char,
  2072. .write_room = rp_write_room,
  2073. .chars_in_buffer = rp_chars_in_buffer,
  2074. .flush_buffer = rp_flush_buffer,
  2075. .ioctl = rp_ioctl,
  2076. .throttle = rp_throttle,
  2077. .unthrottle = rp_unthrottle,
  2078. .set_termios = rp_set_termios,
  2079. .stop = rp_stop,
  2080. .start = rp_start,
  2081. .hangup = rp_hangup,
  2082. .break_ctl = rp_break,
  2083. .send_xchar = rp_send_xchar,
  2084. .wait_until_sent = rp_wait_until_sent,
  2085. .tiocmget = rp_tiocmget,
  2086. .tiocmset = rp_tiocmset,
  2087. };
  2088. /*
  2089. * The module "startup" routine; it's run when the module is loaded.
  2090. */
  2091. static int __init rp_init(void)
  2092. {
  2093. int ret = -ENOMEM, pci_boards_found, isa_boards_found, i;
  2094. printk(KERN_INFO "RocketPort device driver module, version %s, %s\n",
  2095. ROCKET_VERSION, ROCKET_DATE);
  2096. rocket_driver = alloc_tty_driver(MAX_RP_PORTS);
  2097. if (!rocket_driver)
  2098. goto err;
  2099. /*
  2100. * If board 1 is non-zero, there is at least one ISA configured. If controller is
  2101. * zero, use the default controller IO address of board1 + 0x40.
  2102. */
  2103. if (board1) {
  2104. if (controller == 0)
  2105. controller = board1 + 0x40;
  2106. } else {
  2107. controller = 0; /* Used as a flag, meaning no ISA boards */
  2108. }
  2109. /* If an ISA card is configured, reserve the 4 byte IO space for the Mudbac controller */
  2110. if (controller && (!request_region(controller, 4, "Comtrol RocketPort"))) {
  2111. printk(KERN_ERR "Unable to reserve IO region for first "
  2112. "configured ISA RocketPort controller 0x%lx. "
  2113. "Driver exiting\n", controller);
  2114. ret = -EBUSY;
  2115. goto err_tty;
  2116. }
  2117. /* Store ISA variable retrieved from command line or .conf file. */
  2118. rcktpt_io_addr[0] = board1;
  2119. rcktpt_io_addr[1] = board2;
  2120. rcktpt_io_addr[2] = board3;
  2121. rcktpt_io_addr[3] = board4;
  2122. rcktpt_type[0] = modem1 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2123. rcktpt_type[0] = pc104_1[0] ? ROCKET_TYPE_PC104 : rcktpt_type[0];
  2124. rcktpt_type[1] = modem2 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2125. rcktpt_type[1] = pc104_2[0] ? ROCKET_TYPE_PC104 : rcktpt_type[1];
  2126. rcktpt_type[2] = modem3 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2127. rcktpt_type[2] = pc104_3[0] ? ROCKET_TYPE_PC104 : rcktpt_type[2];
  2128. rcktpt_type[3] = modem4 ? ROCKET_TYPE_MODEM : ROCKET_TYPE_NORMAL;
  2129. rcktpt_type[3] = pc104_4[0] ? ROCKET_TYPE_PC104 : rcktpt_type[3];
  2130. /*
  2131. * Set up the tty driver structure and then register this
  2132. * driver with the tty layer.
  2133. */
  2134. rocket_driver->owner = THIS_MODULE;
  2135. rocket_driver->flags = TTY_DRIVER_DYNAMIC_DEV;
  2136. rocket_driver->name = "ttyR";
  2137. rocket_driver->driver_name = "Comtrol RocketPort";
  2138. rocket_driver->major = TTY_ROCKET_MAJOR;
  2139. rocket_driver->minor_start = 0;
  2140. rocket_driver->type = TTY_DRIVER_TYPE_SERIAL;
  2141. rocket_driver->subtype = SERIAL_TYPE_NORMAL;
  2142. rocket_driver->init_termios = tty_std_termios;
  2143. rocket_driver->init_termios.c_cflag =
  2144. B9600 | CS8 | CREAD | HUPCL | CLOCAL;
  2145. rocket_driver->init_termios.c_ispeed = 9600;
  2146. rocket_driver->init_termios.c_ospeed = 9600;
  2147. #ifdef ROCKET_SOFT_FLOW
  2148. rocket_driver->flags |= TTY_DRIVER_REAL_RAW;
  2149. #endif
  2150. tty_set_operations(rocket_driver, &rocket_ops);
  2151. ret = tty_register_driver(rocket_driver);
  2152. if (ret < 0) {
  2153. printk(KERN_ERR "Couldn't install tty RocketPort driver\n");
  2154. goto err_tty;
  2155. }
  2156. #ifdef ROCKET_DEBUG_OPEN
  2157. printk(KERN_INFO "RocketPort driver is major %d\n", rocket_driver.major);
  2158. #endif
  2159. /*
  2160. * OK, let's probe each of the controllers looking for boards. Any boards found
  2161. * will be initialized here.
  2162. */
  2163. isa_boards_found = 0;
  2164. pci_boards_found = 0;
  2165. for (i = 0; i < NUM_BOARDS; i++) {
  2166. if (init_ISA(i))
  2167. isa_boards_found++;
  2168. }
  2169. #ifdef CONFIG_PCI
  2170. if (isa_boards_found < NUM_BOARDS)
  2171. pci_boards_found = init_PCI(isa_boards_found);
  2172. #endif
  2173. max_board = pci_boards_found + isa_boards_found;
  2174. if (max_board == 0) {
  2175. printk(KERN_ERR "No rocketport ports found; unloading driver\n");
  2176. ret = -ENXIO;
  2177. goto err_ttyu;
  2178. }
  2179. return 0;
  2180. err_ttyu:
  2181. tty_unregister_driver(rocket_driver);
  2182. err_tty:
  2183. put_tty_driver(rocket_driver);
  2184. err:
  2185. return ret;
  2186. }
  2187. static void rp_cleanup_module(void)
  2188. {
  2189. int retval;
  2190. int i;
  2191. del_timer_sync(&rocket_timer);
  2192. retval = tty_unregister_driver(rocket_driver);
  2193. if (retval)
  2194. printk(KERN_ERR "Error %d while trying to unregister "
  2195. "rocketport driver\n", -retval);
  2196. for (i = 0; i < MAX_RP_PORTS; i++)
  2197. if (rp_table[i]) {
  2198. tty_unregister_device(rocket_driver, i);
  2199. kfree(rp_table[i]);
  2200. }
  2201. put_tty_driver(rocket_driver);
  2202. for (i = 0; i < NUM_BOARDS; i++) {
  2203. if (rcktpt_io_addr[i] <= 0 || is_PCI[i])
  2204. continue;
  2205. release_region(rcktpt_io_addr[i], 64);
  2206. }
  2207. if (controller)
  2208. release_region(controller, 4);
  2209. }
  2210. /***************************************************************************
  2211. Function: sInitController
  2212. Purpose: Initialization of controller global registers and controller
  2213. structure.
  2214. Call: sInitController(CtlP,CtlNum,MudbacIO,AiopIOList,AiopIOListSize,
  2215. IRQNum,Frequency,PeriodicOnly)
  2216. CONTROLLER_T *CtlP; Ptr to controller structure
  2217. int CtlNum; Controller number
  2218. ByteIO_t MudbacIO; Mudbac base I/O address.
  2219. ByteIO_t *AiopIOList; List of I/O addresses for each AIOP.
  2220. This list must be in the order the AIOPs will be found on the
  2221. controller. Once an AIOP in the list is not found, it is
  2222. assumed that there are no more AIOPs on the controller.
  2223. int AiopIOListSize; Number of addresses in AiopIOList
  2224. int IRQNum; Interrupt Request number. Can be any of the following:
  2225. 0: Disable global interrupts
  2226. 3: IRQ 3
  2227. 4: IRQ 4
  2228. 5: IRQ 5
  2229. 9: IRQ 9
  2230. 10: IRQ 10
  2231. 11: IRQ 11
  2232. 12: IRQ 12
  2233. 15: IRQ 15
  2234. Byte_t Frequency: A flag identifying the frequency
  2235. of the periodic interrupt, can be any one of the following:
  2236. FREQ_DIS - periodic interrupt disabled
  2237. FREQ_137HZ - 137 Hertz
  2238. FREQ_69HZ - 69 Hertz
  2239. FREQ_34HZ - 34 Hertz
  2240. FREQ_17HZ - 17 Hertz
  2241. FREQ_9HZ - 9 Hertz
  2242. FREQ_4HZ - 4 Hertz
  2243. If IRQNum is set to 0 the Frequency parameter is
  2244. overidden, it is forced to a value of FREQ_DIS.
  2245. int PeriodicOnly: 1 if all interrupts except the periodic
  2246. interrupt are to be blocked.
  2247. 0 is both the periodic interrupt and
  2248. other channel interrupts are allowed.
  2249. If IRQNum is set to 0 the PeriodicOnly parameter is
  2250. overidden, it is forced to a value of 0.
  2251. Return: int: Number of AIOPs on the controller, or CTLID_NULL if controller
  2252. initialization failed.
  2253. Comments:
  2254. If periodic interrupts are to be disabled but AIOP interrupts
  2255. are allowed, set Frequency to FREQ_DIS and PeriodicOnly to 0.
  2256. If interrupts are to be completely disabled set IRQNum to 0.
  2257. Setting Frequency to FREQ_DIS and PeriodicOnly to 1 is an
  2258. invalid combination.
  2259. This function performs initialization of global interrupt modes,
  2260. but it does not actually enable global interrupts. To enable
  2261. and disable global interrupts use functions sEnGlobalInt() and
  2262. sDisGlobalInt(). Enabling of global interrupts is normally not
  2263. done until all other initializations are complete.
  2264. Even if interrupts are globally enabled, they must also be
  2265. individually enabled for each channel that is to generate
  2266. interrupts.
  2267. Warnings: No range checking on any of the parameters is done.
  2268. No context switches are allowed while executing this function.
  2269. After this function all AIOPs on the controller are disabled,
  2270. they can be enabled with sEnAiop().
  2271. */
  2272. static int sInitController(CONTROLLER_T * CtlP, int CtlNum, ByteIO_t MudbacIO,
  2273. ByteIO_t * AiopIOList, int AiopIOListSize,
  2274. int IRQNum, Byte_t Frequency, int PeriodicOnly)
  2275. {
  2276. int i;
  2277. ByteIO_t io;
  2278. int done;
  2279. CtlP->AiopIntrBits = aiop_intr_bits;
  2280. CtlP->AltChanRingIndicator = 0;
  2281. CtlP->CtlNum = CtlNum;
  2282. CtlP->CtlID = CTLID_0001; /* controller release 1 */
  2283. CtlP->BusType = isISA;
  2284. CtlP->MBaseIO = MudbacIO;
  2285. CtlP->MReg1IO = MudbacIO + 1;
  2286. CtlP->MReg2IO = MudbacIO + 2;
  2287. CtlP->MReg3IO = MudbacIO + 3;
  2288. #if 1
  2289. CtlP->MReg2 = 0; /* interrupt disable */
  2290. CtlP->MReg3 = 0; /* no periodic interrupts */
  2291. #else
  2292. if (sIRQMap[IRQNum] == 0) { /* interrupts globally disabled */
  2293. CtlP->MReg2 = 0; /* interrupt disable */
  2294. CtlP->MReg3 = 0; /* no periodic interrupts */
  2295. } else {
  2296. CtlP->MReg2 = sIRQMap[IRQNum]; /* set IRQ number */
  2297. CtlP->MReg3 = Frequency; /* set frequency */
  2298. if (PeriodicOnly) { /* periodic interrupt only */
  2299. CtlP->MReg3 |= PERIODIC_ONLY;
  2300. }
  2301. }
  2302. #endif
  2303. sOutB(CtlP->MReg2IO, CtlP->MReg2);
  2304. sOutB(CtlP->MReg3IO, CtlP->MReg3);
  2305. sControllerEOI(CtlP); /* clear EOI if warm init */
  2306. /* Init AIOPs */
  2307. CtlP->NumAiop = 0;
  2308. for (i = done = 0; i < AiopIOListSize; i++) {
  2309. io = AiopIOList[i];
  2310. CtlP->AiopIO[i] = (WordIO_t) io;
  2311. CtlP->AiopIntChanIO[i] = io + _INT_CHAN;
  2312. sOutB(CtlP->MReg2IO, CtlP->MReg2 | (i & 0x03)); /* AIOP index */
  2313. sOutB(MudbacIO, (Byte_t) (io >> 6)); /* set up AIOP I/O in MUDBAC */
  2314. if (done)
  2315. continue;
  2316. sEnAiop(CtlP, i); /* enable the AIOP */
  2317. CtlP->AiopID[i] = sReadAiopID(io); /* read AIOP ID */
  2318. if (CtlP->AiopID[i] == AIOPID_NULL) /* if AIOP does not exist */
  2319. done = 1; /* done looking for AIOPs */
  2320. else {
  2321. CtlP->AiopNumChan[i] = sReadAiopNumChan((WordIO_t) io); /* num channels in AIOP */
  2322. sOutW((WordIO_t) io + _INDX_ADDR, _CLK_PRE); /* clock prescaler */
  2323. sOutB(io + _INDX_DATA, sClockPrescale);
  2324. CtlP->NumAiop++; /* bump count of AIOPs */
  2325. }
  2326. sDisAiop(CtlP, i); /* disable AIOP */
  2327. }
  2328. if (CtlP->NumAiop == 0)
  2329. return (-1);
  2330. else
  2331. return (CtlP->NumAiop);
  2332. }
  2333. /***************************************************************************
  2334. Function: sPCIInitController
  2335. Purpose: Initialization of controller global registers and controller
  2336. structure.
  2337. Call: sPCIInitController(CtlP,CtlNum,AiopIOList,AiopIOListSize,
  2338. IRQNum,Frequency,PeriodicOnly)
  2339. CONTROLLER_T *CtlP; Ptr to controller structure
  2340. int CtlNum; Controller number
  2341. ByteIO_t *AiopIOList; List of I/O addresses for each AIOP.
  2342. This list must be in the order the AIOPs will be found on the
  2343. controller. Once an AIOP in the list is not found, it is
  2344. assumed that there are no more AIOPs on the controller.
  2345. int AiopIOListSize; Number of addresses in AiopIOList
  2346. int IRQNum; Interrupt Request number. Can be any of the following:
  2347. 0: Disable global interrupts
  2348. 3: IRQ 3
  2349. 4: IRQ 4
  2350. 5: IRQ 5
  2351. 9: IRQ 9
  2352. 10: IRQ 10
  2353. 11: IRQ 11
  2354. 12: IRQ 12
  2355. 15: IRQ 15
  2356. Byte_t Frequency: A flag identifying the frequency
  2357. of the periodic interrupt, can be any one of the following:
  2358. FREQ_DIS - periodic interrupt disabled
  2359. FREQ_137HZ - 137 Hertz
  2360. FREQ_69HZ - 69 Hertz
  2361. FREQ_34HZ - 34 Hertz
  2362. FREQ_17HZ - 17 Hertz
  2363. FREQ_9HZ - 9 Hertz
  2364. FREQ_4HZ - 4 Hertz
  2365. If IRQNum is set to 0 the Frequency parameter is
  2366. overidden, it is forced to a value of FREQ_DIS.
  2367. int PeriodicOnly: 1 if all interrupts except the periodic
  2368. interrupt are to be blocked.
  2369. 0 is both the periodic interrupt and
  2370. other channel interrupts are allowed.
  2371. If IRQNum is set to 0 the PeriodicOnly parameter is
  2372. overidden, it is forced to a value of 0.
  2373. Return: int: Number of AIOPs on the controller, or CTLID_NULL if controller
  2374. initialization failed.
  2375. Comments:
  2376. If periodic interrupts are to be disabled but AIOP interrupts
  2377. are allowed, set Frequency to FREQ_DIS and PeriodicOnly to 0.
  2378. If interrupts are to be completely disabled set IRQNum to 0.
  2379. Setting Frequency to FREQ_DIS and PeriodicOnly to 1 is an
  2380. invalid combination.
  2381. This function performs initialization of global interrupt modes,
  2382. but it does not actually enable global interrupts. To enable
  2383. and disable global interrupts use functions sEnGlobalInt() and
  2384. sDisGlobalInt(). Enabling of global interrupts is normally not
  2385. done until all other initializations are complete.
  2386. Even if interrupts are globally enabled, they must also be
  2387. individually enabled for each channel that is to generate
  2388. interrupts.
  2389. Warnings: No range checking on any of the parameters is done.
  2390. No context switches are allowed while executing this function.
  2391. After this function all AIOPs on the controller are disabled,
  2392. they can be enabled with sEnAiop().
  2393. */
  2394. static int sPCIInitController(CONTROLLER_T * CtlP, int CtlNum,
  2395. ByteIO_t * AiopIOList, int AiopIOListSize,
  2396. WordIO_t ConfigIO, int IRQNum, Byte_t Frequency,
  2397. int PeriodicOnly, int altChanRingIndicator,
  2398. int UPCIRingInd)
  2399. {
  2400. int i;
  2401. ByteIO_t io;
  2402. CtlP->AltChanRingIndicator = altChanRingIndicator;
  2403. CtlP->UPCIRingInd = UPCIRingInd;
  2404. CtlP->CtlNum = CtlNum;
  2405. CtlP->CtlID = CTLID_0001; /* controller release 1 */
  2406. CtlP->BusType = isPCI; /* controller release 1 */
  2407. if (ConfigIO) {
  2408. CtlP->isUPCI = 1;
  2409. CtlP->PCIIO = ConfigIO + _PCI_9030_INT_CTRL;
  2410. CtlP->PCIIO2 = ConfigIO + _PCI_9030_GPIO_CTRL;
  2411. CtlP->AiopIntrBits = upci_aiop_intr_bits;
  2412. } else {
  2413. CtlP->isUPCI = 0;
  2414. CtlP->PCIIO =
  2415. (WordIO_t) ((ByteIO_t) AiopIOList[0] + _PCI_INT_FUNC);
  2416. CtlP->AiopIntrBits = aiop_intr_bits;
  2417. }
  2418. sPCIControllerEOI(CtlP); /* clear EOI if warm init */
  2419. /* Init AIOPs */
  2420. CtlP->NumAiop = 0;
  2421. for (i = 0; i < AiopIOListSize; i++) {
  2422. io = AiopIOList[i];
  2423. CtlP->AiopIO[i] = (WordIO_t) io;
  2424. CtlP->AiopIntChanIO[i] = io + _INT_CHAN;
  2425. CtlP->AiopID[i] = sReadAiopID(io); /* read AIOP ID */
  2426. if (CtlP->AiopID[i] == AIOPID_NULL) /* if AIOP does not exist */
  2427. break; /* done looking for AIOPs */
  2428. CtlP->AiopNumChan[i] = sReadAiopNumChan((WordIO_t) io); /* num channels in AIOP */
  2429. sOutW((WordIO_t) io + _INDX_ADDR, _CLK_PRE); /* clock prescaler */
  2430. sOutB(io + _INDX_DATA, sClockPrescale);
  2431. CtlP->NumAiop++; /* bump count of AIOPs */
  2432. }
  2433. if (CtlP->NumAiop == 0)
  2434. return (-1);
  2435. else
  2436. return (CtlP->NumAiop);
  2437. }
  2438. /***************************************************************************
  2439. Function: sReadAiopID
  2440. Purpose: Read the AIOP idenfication number directly from an AIOP.
  2441. Call: sReadAiopID(io)
  2442. ByteIO_t io: AIOP base I/O address
  2443. Return: int: Flag AIOPID_XXXX if a valid AIOP is found, where X
  2444. is replace by an identifying number.
  2445. Flag AIOPID_NULL if no valid AIOP is found
  2446. Warnings: No context switches are allowed while executing this function.
  2447. */
  2448. static int sReadAiopID(ByteIO_t io)
  2449. {
  2450. Byte_t AiopID; /* ID byte from AIOP */
  2451. sOutB(io + _CMD_REG, RESET_ALL); /* reset AIOP */
  2452. sOutB(io + _CMD_REG, 0x0);
  2453. AiopID = sInW(io + _CHN_STAT0) & 0x07;
  2454. if (AiopID == 0x06)
  2455. return (1);
  2456. else /* AIOP does not exist */
  2457. return (-1);
  2458. }
  2459. /***************************************************************************
  2460. Function: sReadAiopNumChan
  2461. Purpose: Read the number of channels available in an AIOP directly from
  2462. an AIOP.
  2463. Call: sReadAiopNumChan(io)
  2464. WordIO_t io: AIOP base I/O address
  2465. Return: int: The number of channels available
  2466. Comments: The number of channels is determined by write/reads from identical
  2467. offsets within the SRAM address spaces for channels 0 and 4.
  2468. If the channel 4 space is mirrored to channel 0 it is a 4 channel
  2469. AIOP, otherwise it is an 8 channel.
  2470. Warnings: No context switches are allowed while executing this function.
  2471. */
  2472. static int sReadAiopNumChan(WordIO_t io)
  2473. {
  2474. Word_t x;
  2475. static Byte_t R[4] = { 0x00, 0x00, 0x34, 0x12 };
  2476. /* write to chan 0 SRAM */
  2477. out32((DWordIO_t) io + _INDX_ADDR, R);
  2478. sOutW(io + _INDX_ADDR, 0); /* read from SRAM, chan 0 */
  2479. x = sInW(io + _INDX_DATA);
  2480. sOutW(io + _INDX_ADDR, 0x4000); /* read from SRAM, chan 4 */
  2481. if (x != sInW(io + _INDX_DATA)) /* if different must be 8 chan */
  2482. return (8);
  2483. else
  2484. return (4);
  2485. }
  2486. /***************************************************************************
  2487. Function: sInitChan
  2488. Purpose: Initialization of a channel and channel structure
  2489. Call: sInitChan(CtlP,ChP,AiopNum,ChanNum)
  2490. CONTROLLER_T *CtlP; Ptr to controller structure
  2491. CHANNEL_T *ChP; Ptr to channel structure
  2492. int AiopNum; AIOP number within controller
  2493. int ChanNum; Channel number within AIOP
  2494. Return: int: 1 if initialization succeeded, 0 if it fails because channel
  2495. number exceeds number of channels available in AIOP.
  2496. Comments: This function must be called before a channel can be used.
  2497. Warnings: No range checking on any of the parameters is done.
  2498. No context switches are allowed while executing this function.
  2499. */
  2500. static int sInitChan(CONTROLLER_T * CtlP, CHANNEL_T * ChP, int AiopNum,
  2501. int ChanNum)
  2502. {
  2503. int i;
  2504. WordIO_t AiopIO;
  2505. WordIO_t ChIOOff;
  2506. Byte_t *ChR;
  2507. Word_t ChOff;
  2508. static Byte_t R[4];
  2509. int brd9600;
  2510. if (ChanNum >= CtlP->AiopNumChan[AiopNum])
  2511. return 0; /* exceeds num chans in AIOP */
  2512. /* Channel, AIOP, and controller identifiers */
  2513. ChP->CtlP = CtlP;
  2514. ChP->ChanID = CtlP->AiopID[AiopNum];
  2515. ChP->AiopNum = AiopNum;
  2516. ChP->ChanNum = ChanNum;
  2517. /* Global direct addresses */
  2518. AiopIO = CtlP->AiopIO[AiopNum];
  2519. ChP->Cmd = (ByteIO_t) AiopIO + _CMD_REG;
  2520. ChP->IntChan = (ByteIO_t) AiopIO + _INT_CHAN;
  2521. ChP->IntMask = (ByteIO_t) AiopIO + _INT_MASK;
  2522. ChP->IndexAddr = (DWordIO_t) AiopIO + _INDX_ADDR;
  2523. ChP->IndexData = AiopIO + _INDX_DATA;
  2524. /* Channel direct addresses */
  2525. ChIOOff = AiopIO + ChP->ChanNum * 2;
  2526. ChP->TxRxData = ChIOOff + _TD0;
  2527. ChP->ChanStat = ChIOOff + _CHN_STAT0;
  2528. ChP->TxRxCount = ChIOOff + _FIFO_CNT0;
  2529. ChP->IntID = (ByteIO_t) AiopIO + ChP->ChanNum + _INT_ID0;
  2530. /* Initialize the channel from the RData array */
  2531. for (i = 0; i < RDATASIZE; i += 4) {
  2532. R[0] = RData[i];
  2533. R[1] = RData[i + 1] + 0x10 * ChanNum;
  2534. R[2] = RData[i + 2];
  2535. R[3] = RData[i + 3];
  2536. out32(ChP->IndexAddr, R);
  2537. }
  2538. ChR = ChP->R;
  2539. for (i = 0; i < RREGDATASIZE; i += 4) {
  2540. ChR[i] = RRegData[i];
  2541. ChR[i + 1] = RRegData[i + 1] + 0x10 * ChanNum;
  2542. ChR[i + 2] = RRegData[i + 2];
  2543. ChR[i + 3] = RRegData[i + 3];
  2544. }
  2545. /* Indexed registers */
  2546. ChOff = (Word_t) ChanNum *0x1000;
  2547. if (sClockPrescale == 0x14)
  2548. brd9600 = 47;
  2549. else
  2550. brd9600 = 23;
  2551. ChP->BaudDiv[0] = (Byte_t) (ChOff + _BAUD);
  2552. ChP->BaudDiv[1] = (Byte_t) ((ChOff + _BAUD) >> 8);
  2553. ChP->BaudDiv[2] = (Byte_t) brd9600;
  2554. ChP->BaudDiv[3] = (Byte_t) (brd9600 >> 8);
  2555. out32(ChP->IndexAddr, ChP->BaudDiv);
  2556. ChP->TxControl[0] = (Byte_t) (ChOff + _TX_CTRL);
  2557. ChP->TxControl[1] = (Byte_t) ((ChOff + _TX_CTRL) >> 8);
  2558. ChP->TxControl[2] = 0;
  2559. ChP->TxControl[3] = 0;
  2560. out32(ChP->IndexAddr, ChP->TxControl);
  2561. ChP->RxControl[0] = (Byte_t) (ChOff + _RX_CTRL);
  2562. ChP->RxControl[1] = (Byte_t) ((ChOff + _RX_CTRL) >> 8);
  2563. ChP->RxControl[2] = 0;
  2564. ChP->RxControl[3] = 0;
  2565. out32(ChP->IndexAddr, ChP->RxControl);
  2566. ChP->TxEnables[0] = (Byte_t) (ChOff + _TX_ENBLS);
  2567. ChP->TxEnables[1] = (Byte_t) ((ChOff + _TX_ENBLS) >> 8);
  2568. ChP->TxEnables[2] = 0;
  2569. ChP->TxEnables[3] = 0;
  2570. out32(ChP->IndexAddr, ChP->TxEnables);
  2571. ChP->TxCompare[0] = (Byte_t) (ChOff + _TXCMP1);
  2572. ChP->TxCompare[1] = (Byte_t) ((ChOff + _TXCMP1) >> 8);
  2573. ChP->TxCompare[2] = 0;
  2574. ChP->TxCompare[3] = 0;
  2575. out32(ChP->IndexAddr, ChP->TxCompare);
  2576. ChP->TxReplace1[0] = (Byte_t) (ChOff + _TXREP1B1);
  2577. ChP->TxReplace1[1] = (Byte_t) ((ChOff + _TXREP1B1) >> 8);
  2578. ChP->TxReplace1[2] = 0;
  2579. ChP->TxReplace1[3] = 0;
  2580. out32(ChP->IndexAddr, ChP->TxReplace1);
  2581. ChP->TxReplace2[0] = (Byte_t) (ChOff + _TXREP2);
  2582. ChP->TxReplace2[1] = (Byte_t) ((ChOff + _TXREP2) >> 8);
  2583. ChP->TxReplace2[2] = 0;
  2584. ChP->TxReplace2[3] = 0;
  2585. out32(ChP->IndexAddr, ChP->TxReplace2);
  2586. ChP->TxFIFOPtrs = ChOff + _TXF_OUTP;
  2587. ChP->TxFIFO = ChOff + _TX_FIFO;
  2588. sOutB(ChP->Cmd, (Byte_t) ChanNum | RESTXFCNT); /* apply reset Tx FIFO count */
  2589. sOutB(ChP->Cmd, (Byte_t) ChanNum); /* remove reset Tx FIFO count */
  2590. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxFIFOPtrs); /* clear Tx in/out ptrs */
  2591. sOutW(ChP->IndexData, 0);
  2592. ChP->RxFIFOPtrs = ChOff + _RXF_OUTP;
  2593. ChP->RxFIFO = ChOff + _RX_FIFO;
  2594. sOutB(ChP->Cmd, (Byte_t) ChanNum | RESRXFCNT); /* apply reset Rx FIFO count */
  2595. sOutB(ChP->Cmd, (Byte_t) ChanNum); /* remove reset Rx FIFO count */
  2596. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs); /* clear Rx out ptr */
  2597. sOutW(ChP->IndexData, 0);
  2598. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs + 2); /* clear Rx in ptr */
  2599. sOutW(ChP->IndexData, 0);
  2600. ChP->TxPrioCnt = ChOff + _TXP_CNT;
  2601. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxPrioCnt);
  2602. sOutB(ChP->IndexData, 0);
  2603. ChP->TxPrioPtr = ChOff + _TXP_PNTR;
  2604. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxPrioPtr);
  2605. sOutB(ChP->IndexData, 0);
  2606. ChP->TxPrioBuf = ChOff + _TXP_BUF;
  2607. sEnRxProcessor(ChP); /* start the Rx processor */
  2608. return 1;
  2609. }
  2610. /***************************************************************************
  2611. Function: sStopRxProcessor
  2612. Purpose: Stop the receive processor from processing a channel.
  2613. Call: sStopRxProcessor(ChP)
  2614. CHANNEL_T *ChP; Ptr to channel structure
  2615. Comments: The receive processor can be started again with sStartRxProcessor().
  2616. This function causes the receive processor to skip over the
  2617. stopped channel. It does not stop it from processing other channels.
  2618. Warnings: No context switches are allowed while executing this function.
  2619. Do not leave the receive processor stopped for more than one
  2620. character time.
  2621. After calling this function a delay of 4 uS is required to ensure
  2622. that the receive processor is no longer processing this channel.
  2623. */
  2624. static void sStopRxProcessor(CHANNEL_T * ChP)
  2625. {
  2626. Byte_t R[4];
  2627. R[0] = ChP->R[0];
  2628. R[1] = ChP->R[1];
  2629. R[2] = 0x0a;
  2630. R[3] = ChP->R[3];
  2631. out32(ChP->IndexAddr, R);
  2632. }
  2633. /***************************************************************************
  2634. Function: sFlushRxFIFO
  2635. Purpose: Flush the Rx FIFO
  2636. Call: sFlushRxFIFO(ChP)
  2637. CHANNEL_T *ChP; Ptr to channel structure
  2638. Return: void
  2639. Comments: To prevent data from being enqueued or dequeued in the Tx FIFO
  2640. while it is being flushed the receive processor is stopped
  2641. and the transmitter is disabled. After these operations a
  2642. 4 uS delay is done before clearing the pointers to allow
  2643. the receive processor to stop. These items are handled inside
  2644. this function.
  2645. Warnings: No context switches are allowed while executing this function.
  2646. */
  2647. static void sFlushRxFIFO(CHANNEL_T * ChP)
  2648. {
  2649. int i;
  2650. Byte_t Ch; /* channel number within AIOP */
  2651. int RxFIFOEnabled; /* 1 if Rx FIFO enabled */
  2652. if (sGetRxCnt(ChP) == 0) /* Rx FIFO empty */
  2653. return; /* don't need to flush */
  2654. RxFIFOEnabled = 0;
  2655. if (ChP->R[0x32] == 0x08) { /* Rx FIFO is enabled */
  2656. RxFIFOEnabled = 1;
  2657. sDisRxFIFO(ChP); /* disable it */
  2658. for (i = 0; i < 2000 / 200; i++) /* delay 2 uS to allow proc to disable FIFO */
  2659. sInB(ChP->IntChan); /* depends on bus i/o timing */
  2660. }
  2661. sGetChanStatus(ChP); /* clear any pending Rx errors in chan stat */
  2662. Ch = (Byte_t) sGetChanNum(ChP);
  2663. sOutB(ChP->Cmd, Ch | RESRXFCNT); /* apply reset Rx FIFO count */
  2664. sOutB(ChP->Cmd, Ch); /* remove reset Rx FIFO count */
  2665. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs); /* clear Rx out ptr */
  2666. sOutW(ChP->IndexData, 0);
  2667. sOutW((WordIO_t) ChP->IndexAddr, ChP->RxFIFOPtrs + 2); /* clear Rx in ptr */
  2668. sOutW(ChP->IndexData, 0);
  2669. if (RxFIFOEnabled)
  2670. sEnRxFIFO(ChP); /* enable Rx FIFO */
  2671. }
  2672. /***************************************************************************
  2673. Function: sFlushTxFIFO
  2674. Purpose: Flush the Tx FIFO
  2675. Call: sFlushTxFIFO(ChP)
  2676. CHANNEL_T *ChP; Ptr to channel structure
  2677. Return: void
  2678. Comments: To prevent data from being enqueued or dequeued in the Tx FIFO
  2679. while it is being flushed the receive processor is stopped
  2680. and the transmitter is disabled. After these operations a
  2681. 4 uS delay is done before clearing the pointers to allow
  2682. the receive processor to stop. These items are handled inside
  2683. this function.
  2684. Warnings: No context switches are allowed while executing this function.
  2685. */
  2686. static void sFlushTxFIFO(CHANNEL_T * ChP)
  2687. {
  2688. int i;
  2689. Byte_t Ch; /* channel number within AIOP */
  2690. int TxEnabled; /* 1 if transmitter enabled */
  2691. if (sGetTxCnt(ChP) == 0) /* Tx FIFO empty */
  2692. return; /* don't need to flush */
  2693. TxEnabled = 0;
  2694. if (ChP->TxControl[3] & TX_ENABLE) {
  2695. TxEnabled = 1;
  2696. sDisTransmit(ChP); /* disable transmitter */
  2697. }
  2698. sStopRxProcessor(ChP); /* stop Rx processor */
  2699. for (i = 0; i < 4000 / 200; i++) /* delay 4 uS to allow proc to stop */
  2700. sInB(ChP->IntChan); /* depends on bus i/o timing */
  2701. Ch = (Byte_t) sGetChanNum(ChP);
  2702. sOutB(ChP->Cmd, Ch | RESTXFCNT); /* apply reset Tx FIFO count */
  2703. sOutB(ChP->Cmd, Ch); /* remove reset Tx FIFO count */
  2704. sOutW((WordIO_t) ChP->IndexAddr, ChP->TxFIFOPtrs); /* clear Tx in/out ptrs */
  2705. sOutW(ChP->IndexData, 0);
  2706. if (TxEnabled)
  2707. sEnTransmit(ChP); /* enable transmitter */
  2708. sStartRxProcessor(ChP); /* restart Rx processor */
  2709. }
  2710. /***************************************************************************
  2711. Function: sWriteTxPrioByte
  2712. Purpose: Write a byte of priority transmit data to a channel
  2713. Call: sWriteTxPrioByte(ChP,Data)
  2714. CHANNEL_T *ChP; Ptr to channel structure
  2715. Byte_t Data; The transmit data byte
  2716. Return: int: 1 if the bytes is successfully written, otherwise 0.
  2717. Comments: The priority byte is transmitted before any data in the Tx FIFO.
  2718. Warnings: No context switches are allowed while executing this function.
  2719. */
  2720. static int sWriteTxPrioByte(CHANNEL_T * ChP, Byte_t Data)
  2721. {
  2722. Byte_t DWBuf[4]; /* buffer for double word writes */
  2723. Word_t *WordPtr; /* must be far because Win SS != DS */
  2724. register DWordIO_t IndexAddr;
  2725. if (sGetTxCnt(ChP) > 1) { /* write it to Tx priority buffer */
  2726. IndexAddr = ChP->IndexAddr;
  2727. sOutW((WordIO_t) IndexAddr, ChP->TxPrioCnt); /* get priority buffer status */
  2728. if (sInB((ByteIO_t) ChP->IndexData) & PRI_PEND) /* priority buffer busy */
  2729. return (0); /* nothing sent */
  2730. WordPtr = (Word_t *) (&DWBuf[0]);
  2731. *WordPtr = ChP->TxPrioBuf; /* data byte address */
  2732. DWBuf[2] = Data; /* data byte value */
  2733. out32(IndexAddr, DWBuf); /* write it out */
  2734. *WordPtr = ChP->TxPrioCnt; /* Tx priority count address */
  2735. DWBuf[2] = PRI_PEND + 1; /* indicate 1 byte pending */
  2736. DWBuf[3] = 0; /* priority buffer pointer */
  2737. out32(IndexAddr, DWBuf); /* write it out */
  2738. } else { /* write it to Tx FIFO */
  2739. sWriteTxByte(sGetTxRxDataIO(ChP), Data);
  2740. }
  2741. return (1); /* 1 byte sent */
  2742. }
  2743. /***************************************************************************
  2744. Function: sEnInterrupts
  2745. Purpose: Enable one or more interrupts for a channel
  2746. Call: sEnInterrupts(ChP,Flags)
  2747. CHANNEL_T *ChP; Ptr to channel structure
  2748. Word_t Flags: Interrupt enable flags, can be any combination
  2749. of the following flags:
  2750. TXINT_EN: Interrupt on Tx FIFO empty
  2751. RXINT_EN: Interrupt on Rx FIFO at trigger level (see
  2752. sSetRxTrigger())
  2753. SRCINT_EN: Interrupt on SRC (Special Rx Condition)
  2754. MCINT_EN: Interrupt on modem input change
  2755. CHANINT_EN: Allow channel interrupt signal to the AIOP's
  2756. Interrupt Channel Register.
  2757. Return: void
  2758. Comments: If an interrupt enable flag is set in Flags, that interrupt will be
  2759. enabled. If an interrupt enable flag is not set in Flags, that
  2760. interrupt will not be changed. Interrupts can be disabled with
  2761. function sDisInterrupts().
  2762. This function sets the appropriate bit for the channel in the AIOP's
  2763. Interrupt Mask Register if the CHANINT_EN flag is set. This allows
  2764. this channel's bit to be set in the AIOP's Interrupt Channel Register.
  2765. Interrupts must also be globally enabled before channel interrupts
  2766. will be passed on to the host. This is done with function
  2767. sEnGlobalInt().
  2768. In some cases it may be desirable to disable interrupts globally but
  2769. enable channel interrupts. This would allow the global interrupt
  2770. status register to be used to determine which AIOPs need service.
  2771. */
  2772. static void sEnInterrupts(CHANNEL_T * ChP, Word_t Flags)
  2773. {
  2774. Byte_t Mask; /* Interrupt Mask Register */
  2775. ChP->RxControl[2] |=
  2776. ((Byte_t) Flags & (RXINT_EN | SRCINT_EN | MCINT_EN));
  2777. out32(ChP->IndexAddr, ChP->RxControl);
  2778. ChP->TxControl[2] |= ((Byte_t) Flags & TXINT_EN);
  2779. out32(ChP->IndexAddr, ChP->TxControl);
  2780. if (Flags & CHANINT_EN) {
  2781. Mask = sInB(ChP->IntMask) | sBitMapSetTbl[ChP->ChanNum];
  2782. sOutB(ChP->IntMask, Mask);
  2783. }
  2784. }
  2785. /***************************************************************************
  2786. Function: sDisInterrupts
  2787. Purpose: Disable one or more interrupts for a channel
  2788. Call: sDisInterrupts(ChP,Flags)
  2789. CHANNEL_T *ChP; Ptr to channel structure
  2790. Word_t Flags: Interrupt flags, can be any combination
  2791. of the following flags:
  2792. TXINT_EN: Interrupt on Tx FIFO empty
  2793. RXINT_EN: Interrupt on Rx FIFO at trigger level (see
  2794. sSetRxTrigger())
  2795. SRCINT_EN: Interrupt on SRC (Special Rx Condition)
  2796. MCINT_EN: Interrupt on modem input change
  2797. CHANINT_EN: Disable channel interrupt signal to the
  2798. AIOP's Interrupt Channel Register.
  2799. Return: void
  2800. Comments: If an interrupt flag is set in Flags, that interrupt will be
  2801. disabled. If an interrupt flag is not set in Flags, that
  2802. interrupt will not be changed. Interrupts can be enabled with
  2803. function sEnInterrupts().
  2804. This function clears the appropriate bit for the channel in the AIOP's
  2805. Interrupt Mask Register if the CHANINT_EN flag is set. This blocks
  2806. this channel's bit from being set in the AIOP's Interrupt Channel
  2807. Register.
  2808. */
  2809. static void sDisInterrupts(CHANNEL_T * ChP, Word_t Flags)
  2810. {
  2811. Byte_t Mask; /* Interrupt Mask Register */
  2812. ChP->RxControl[2] &=
  2813. ~((Byte_t) Flags & (RXINT_EN | SRCINT_EN | MCINT_EN));
  2814. out32(ChP->IndexAddr, ChP->RxControl);
  2815. ChP->TxControl[2] &= ~((Byte_t) Flags & TXINT_EN);
  2816. out32(ChP->IndexAddr, ChP->TxControl);
  2817. if (Flags & CHANINT_EN) {
  2818. Mask = sInB(ChP->IntMask) & sBitMapClrTbl[ChP->ChanNum];
  2819. sOutB(ChP->IntMask, Mask);
  2820. }
  2821. }
  2822. static void sSetInterfaceMode(CHANNEL_T * ChP, Byte_t mode)
  2823. {
  2824. sOutB(ChP->CtlP->AiopIO[2], (mode & 0x18) | ChP->ChanNum);
  2825. }
  2826. /*
  2827. * Not an official SSCI function, but how to reset RocketModems.
  2828. * ISA bus version
  2829. */
  2830. static void sModemReset(CONTROLLER_T * CtlP, int chan, int on)
  2831. {
  2832. ByteIO_t addr;
  2833. Byte_t val;
  2834. addr = CtlP->AiopIO[0] + 0x400;
  2835. val = sInB(CtlP->MReg3IO);
  2836. /* if AIOP[1] is not enabled, enable it */
  2837. if ((val & 2) == 0) {
  2838. val = sInB(CtlP->MReg2IO);
  2839. sOutB(CtlP->MReg2IO, (val & 0xfc) | (1 & 0x03));
  2840. sOutB(CtlP->MBaseIO, (unsigned char) (addr >> 6));
  2841. }
  2842. sEnAiop(CtlP, 1);
  2843. if (!on)
  2844. addr += 8;
  2845. sOutB(addr + chan, 0); /* apply or remove reset */
  2846. sDisAiop(CtlP, 1);
  2847. }
  2848. /*
  2849. * Not an official SSCI function, but how to reset RocketModems.
  2850. * PCI bus version
  2851. */
  2852. static void sPCIModemReset(CONTROLLER_T * CtlP, int chan, int on)
  2853. {
  2854. ByteIO_t addr;
  2855. addr = CtlP->AiopIO[0] + 0x40; /* 2nd AIOP */
  2856. if (!on)
  2857. addr += 8;
  2858. sOutB(addr + chan, 0); /* apply or remove reset */
  2859. }
  2860. /* Resets the speaker controller on RocketModem II and III devices */
  2861. static void rmSpeakerReset(CONTROLLER_T * CtlP, unsigned long model)
  2862. {
  2863. ByteIO_t addr;
  2864. /* RocketModem II speaker control is at the 8th port location of offset 0x40 */
  2865. if ((model == MODEL_RP4M) || (model == MODEL_RP6M)) {
  2866. addr = CtlP->AiopIO[0] + 0x4F;
  2867. sOutB(addr, 0);
  2868. }
  2869. /* RocketModem III speaker control is at the 1st port location of offset 0x80 */
  2870. if ((model == MODEL_UPCI_RM3_8PORT)
  2871. || (model == MODEL_UPCI_RM3_4PORT)) {
  2872. addr = CtlP->AiopIO[0] + 0x88;
  2873. sOutB(addr, 0);
  2874. }
  2875. }
  2876. /* Returns the line number given the controller (board), aiop and channel number */
  2877. static unsigned char GetLineNumber(int ctrl, int aiop, int ch)
  2878. {
  2879. return lineNumbers[(ctrl << 5) | (aiop << 3) | ch];
  2880. }
  2881. /*
  2882. * Stores the line number associated with a given controller (board), aiop
  2883. * and channel number.
  2884. * Returns: The line number assigned
  2885. */
  2886. static unsigned char SetLineNumber(int ctrl, int aiop, int ch)
  2887. {
  2888. lineNumbers[(ctrl << 5) | (aiop << 3) | ch] = nextLineNumber++;
  2889. return (nextLineNumber - 1);
  2890. }