rocket.c 92 KB

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