epca.c 99 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113
  1. /*
  2. Copyright (C) 1996 Digi International.
  3. For technical support please email digiLinux@dgii.com or
  4. call Digi tech support at (612) 912-3456
  5. ** This driver is no longer supported by Digi **
  6. Much of this design and code came from epca.c which was
  7. copyright (C) 1994, 1995 Troy De Jongh, and subsquently
  8. modified by David Nugent, Christoph Lameter, Mike McLagan.
  9. This program is free software; you can redistribute it and/or modify
  10. it under the terms of the GNU General Public License as published by
  11. the Free Software Foundation; either version 2 of the License, or
  12. (at your option) any later version.
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. --------------------------------------------------------------------------- */
  21. /* See README.epca for change history --DAT*/
  22. #include <linux/config.h>
  23. #include <linux/module.h>
  24. #include <linux/kernel.h>
  25. #include <linux/types.h>
  26. #include <linux/init.h>
  27. #include <linux/serial.h>
  28. #include <linux/delay.h>
  29. #include <linux/ctype.h>
  30. #include <linux/tty.h>
  31. #include <linux/tty_flip.h>
  32. #include <linux/slab.h>
  33. #include <linux/ioport.h>
  34. #include <linux/interrupt.h>
  35. #include <asm/uaccess.h>
  36. #include <asm/io.h>
  37. #include <linux/spinlock.h>
  38. #include <linux/pci.h>
  39. #include "digiPCI.h"
  40. #include "digi1.h"
  41. #include "digiFep1.h"
  42. #include "epca.h"
  43. #include "epcaconfig.h"
  44. /* ---------------------- Begin defines ------------------------ */
  45. #define VERSION "1.3.0.1-LK2.6"
  46. /* This major needs to be submitted to Linux to join the majors list */
  47. #define DIGIINFOMAJOR 35 /* For Digi specific ioctl */
  48. #define MAXCARDS 7
  49. #define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
  50. #define PFX "epca: "
  51. /* ----------------- Begin global definitions ------------------- */
  52. static int nbdevs, num_cards, liloconfig;
  53. static int digi_poller_inhibited = 1 ;
  54. static int setup_error_code;
  55. static int invalid_lilo_config;
  56. /* The ISA boards do window flipping into the same spaces so its only sane
  57. with a single lock. It's still pretty efficient */
  58. static spinlock_t epca_lock = SPIN_LOCK_UNLOCKED;
  59. /* -----------------------------------------------------------------------
  60. MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
  61. 7 below.
  62. --------------------------------------------------------------------------*/
  63. static struct board_info boards[MAXBOARDS];
  64. /* ------------- Begin structures used for driver registeration ---------- */
  65. static struct tty_driver *pc_driver;
  66. static struct tty_driver *pc_info;
  67. /* ------------------ Begin Digi specific structures -------------------- */
  68. /* ------------------------------------------------------------------------
  69. digi_channels represents an array of structures that keep track of
  70. each channel of the Digi product. Information such as transmit and
  71. receive pointers, termio data, and signal definitions (DTR, CTS, etc ...)
  72. are stored here. This structure is NOT used to overlay the cards
  73. physical channel structure.
  74. -------------------------------------------------------------------------- */
  75. static struct channel digi_channels[MAX_ALLOC];
  76. /* ------------------------------------------------------------------------
  77. card_ptr is an array used to hold the address of the
  78. first channel structure of each card. This array will hold
  79. the addresses of various channels located in digi_channels.
  80. -------------------------------------------------------------------------- */
  81. static struct channel *card_ptr[MAXCARDS];
  82. static struct timer_list epca_timer;
  83. /* ---------------------- Begin function prototypes --------------------- */
  84. /* ----------------------------------------------------------------------
  85. Begin generic memory functions. These functions will be alias
  86. (point at) more specific functions dependent on the board being
  87. configured.
  88. ----------------------------------------------------------------------- */
  89. static void memwinon(struct board_info *b, unsigned int win);
  90. static void memwinoff(struct board_info *b, unsigned int win);
  91. static void globalwinon(struct channel *ch);
  92. static void rxwinon(struct channel *ch);
  93. static void txwinon(struct channel *ch);
  94. static void memoff(struct channel *ch);
  95. static void assertgwinon(struct channel *ch);
  96. static void assertmemoff(struct channel *ch);
  97. /* ---- Begin more 'specific' memory functions for cx_like products --- */
  98. static void pcxem_memwinon(struct board_info *b, unsigned int win);
  99. static void pcxem_memwinoff(struct board_info *b, unsigned int win);
  100. static void pcxem_globalwinon(struct channel *ch);
  101. static void pcxem_rxwinon(struct channel *ch);
  102. static void pcxem_txwinon(struct channel *ch);
  103. static void pcxem_memoff(struct channel *ch);
  104. /* ------ Begin more 'specific' memory functions for the pcxe ------- */
  105. static void pcxe_memwinon(struct board_info *b, unsigned int win);
  106. static void pcxe_memwinoff(struct board_info *b, unsigned int win);
  107. static void pcxe_globalwinon(struct channel *ch);
  108. static void pcxe_rxwinon(struct channel *ch);
  109. static void pcxe_txwinon(struct channel *ch);
  110. static void pcxe_memoff(struct channel *ch);
  111. /* ---- Begin more 'specific' memory functions for the pc64xe and pcxi ---- */
  112. /* Note : pc64xe and pcxi share the same windowing routines */
  113. static void pcxi_memwinon(struct board_info *b, unsigned int win);
  114. static void pcxi_memwinoff(struct board_info *b, unsigned int win);
  115. static void pcxi_globalwinon(struct channel *ch);
  116. static void pcxi_rxwinon(struct channel *ch);
  117. static void pcxi_txwinon(struct channel *ch);
  118. static void pcxi_memoff(struct channel *ch);
  119. /* - Begin 'specific' do nothing memory functions needed for some cards - */
  120. static void dummy_memwinon(struct board_info *b, unsigned int win);
  121. static void dummy_memwinoff(struct board_info *b, unsigned int win);
  122. static void dummy_globalwinon(struct channel *ch);
  123. static void dummy_rxwinon(struct channel *ch);
  124. static void dummy_txwinon(struct channel *ch);
  125. static void dummy_memoff(struct channel *ch);
  126. static void dummy_assertgwinon(struct channel *ch);
  127. static void dummy_assertmemoff(struct channel *ch);
  128. /* ------------------- Begin declare functions ----------------------- */
  129. static struct channel *verifyChannel(struct tty_struct *);
  130. static void pc_sched_event(struct channel *, int);
  131. static void epca_error(int, char *);
  132. static void pc_close(struct tty_struct *, struct file *);
  133. static void shutdown(struct channel *);
  134. static void pc_hangup(struct tty_struct *);
  135. static void pc_put_char(struct tty_struct *, unsigned char);
  136. static int pc_write_room(struct tty_struct *);
  137. static int pc_chars_in_buffer(struct tty_struct *);
  138. static void pc_flush_buffer(struct tty_struct *);
  139. static void pc_flush_chars(struct tty_struct *);
  140. static int block_til_ready(struct tty_struct *, struct file *,
  141. struct channel *);
  142. static int pc_open(struct tty_struct *, struct file *);
  143. static void post_fep_init(unsigned int crd);
  144. static void epcapoll(unsigned long);
  145. static void doevent(int);
  146. static void fepcmd(struct channel *, int, int, int, int, int);
  147. static unsigned termios2digi_h(struct channel *ch, unsigned);
  148. static unsigned termios2digi_i(struct channel *ch, unsigned);
  149. static unsigned termios2digi_c(struct channel *ch, unsigned);
  150. static void epcaparam(struct tty_struct *, struct channel *);
  151. static void receive_data(struct channel *);
  152. static int pc_ioctl(struct tty_struct *, struct file *,
  153. unsigned int, unsigned long);
  154. static int info_ioctl(struct tty_struct *, struct file *,
  155. unsigned int, unsigned long);
  156. static void pc_set_termios(struct tty_struct *, struct termios *);
  157. static void do_softint(void *);
  158. static void pc_stop(struct tty_struct *);
  159. static void pc_start(struct tty_struct *);
  160. static void pc_throttle(struct tty_struct * tty);
  161. static void pc_unthrottle(struct tty_struct *tty);
  162. static void digi_send_break(struct channel *ch, int msec);
  163. static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
  164. void epca_setup(char *, int *);
  165. static int get_termio(struct tty_struct *, struct termio __user *);
  166. static int pc_write(struct tty_struct *, const unsigned char *, int);
  167. static int pc_init(void);
  168. static int init_PCI(void);
  169. /* ------------------------------------------------------------------
  170. Table of functions for each board to handle memory. Mantaining
  171. parallelism is a *very* good idea here. The idea is for the
  172. runtime code to blindly call these functions, not knowing/caring
  173. about the underlying hardware. This stuff should contain no
  174. conditionals; if more functionality is needed a different entry
  175. should be established. These calls are the interface calls and
  176. are the only functions that should be accessed. Anyone caught
  177. making direct calls deserves what they get.
  178. -------------------------------------------------------------------- */
  179. static void memwinon(struct board_info *b, unsigned int win)
  180. {
  181. (b->memwinon)(b, win);
  182. }
  183. static void memwinoff(struct board_info *b, unsigned int win)
  184. {
  185. (b->memwinoff)(b, win);
  186. }
  187. static void globalwinon(struct channel *ch)
  188. {
  189. (ch->board->globalwinon)(ch);
  190. }
  191. static void rxwinon(struct channel *ch)
  192. {
  193. (ch->board->rxwinon)(ch);
  194. }
  195. static void txwinon(struct channel *ch)
  196. {
  197. (ch->board->txwinon)(ch);
  198. }
  199. static void memoff(struct channel *ch)
  200. {
  201. (ch->board->memoff)(ch);
  202. }
  203. static void assertgwinon(struct channel *ch)
  204. {
  205. (ch->board->assertgwinon)(ch);
  206. }
  207. static void assertmemoff(struct channel *ch)
  208. {
  209. (ch->board->assertmemoff)(ch);
  210. }
  211. /* ---------------------------------------------------------
  212. PCXEM windowing is the same as that used in the PCXR
  213. and CX series cards.
  214. ------------------------------------------------------------ */
  215. static void pcxem_memwinon(struct board_info *b, unsigned int win)
  216. {
  217. outb_p(FEPWIN|win, b->port + 1);
  218. }
  219. static void pcxem_memwinoff(struct board_info *b, unsigned int win)
  220. {
  221. outb_p(0, b->port + 1);
  222. }
  223. static void pcxem_globalwinon(struct channel *ch)
  224. {
  225. outb_p( FEPWIN, (int)ch->board->port + 1);
  226. }
  227. static void pcxem_rxwinon(struct channel *ch)
  228. {
  229. outb_p(ch->rxwin, (int)ch->board->port + 1);
  230. }
  231. static void pcxem_txwinon(struct channel *ch)
  232. {
  233. outb_p(ch->txwin, (int)ch->board->port + 1);
  234. }
  235. static void pcxem_memoff(struct channel *ch)
  236. {
  237. outb_p(0, (int)ch->board->port + 1);
  238. }
  239. /* ----------------- Begin pcxe memory window stuff ------------------ */
  240. static void pcxe_memwinon(struct board_info *b, unsigned int win)
  241. {
  242. outb_p(FEPWIN | win, b->port + 1);
  243. }
  244. static void pcxe_memwinoff(struct board_info *b, unsigned int win)
  245. {
  246. outb_p(inb(b->port) & ~FEPMEM,
  247. b->port + 1);
  248. outb_p(0, b->port + 1);
  249. }
  250. static void pcxe_globalwinon(struct channel *ch)
  251. {
  252. outb_p( FEPWIN, (int)ch->board->port + 1);
  253. }
  254. static void pcxe_rxwinon(struct channel *ch)
  255. {
  256. outb_p(ch->rxwin, (int)ch->board->port + 1);
  257. }
  258. static void pcxe_txwinon(struct channel *ch)
  259. {
  260. outb_p(ch->txwin, (int)ch->board->port + 1);
  261. }
  262. static void pcxe_memoff(struct channel *ch)
  263. {
  264. outb_p(0, (int)ch->board->port);
  265. outb_p(0, (int)ch->board->port + 1);
  266. }
  267. /* ------------- Begin pc64xe and pcxi memory window stuff -------------- */
  268. static void pcxi_memwinon(struct board_info *b, unsigned int win)
  269. {
  270. outb_p(inb(b->port) | FEPMEM, b->port);
  271. }
  272. static void pcxi_memwinoff(struct board_info *b, unsigned int win)
  273. {
  274. outb_p(inb(b->port) & ~FEPMEM, b->port);
  275. }
  276. static void pcxi_globalwinon(struct channel *ch)
  277. {
  278. outb_p(FEPMEM, ch->board->port);
  279. }
  280. static void pcxi_rxwinon(struct channel *ch)
  281. {
  282. outb_p(FEPMEM, ch->board->port);
  283. }
  284. static void pcxi_txwinon(struct channel *ch)
  285. {
  286. outb_p(FEPMEM, ch->board->port);
  287. }
  288. static void pcxi_memoff(struct channel *ch)
  289. {
  290. outb_p(0, ch->board->port);
  291. }
  292. static void pcxi_assertgwinon(struct channel *ch)
  293. {
  294. epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
  295. }
  296. static void pcxi_assertmemoff(struct channel *ch)
  297. {
  298. epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
  299. }
  300. /* ----------------------------------------------------------------------
  301. Not all of the cards need specific memory windowing routines. Some
  302. cards (Such as PCI) needs no windowing routines at all. We provide
  303. these do nothing routines so that the same code base can be used.
  304. The driver will ALWAYS call a windowing routine if it thinks it needs
  305. to; regardless of the card. However, dependent on the card the routine
  306. may or may not do anything.
  307. ---------------------------------------------------------------------------*/
  308. static void dummy_memwinon(struct board_info *b, unsigned int win)
  309. {
  310. }
  311. static void dummy_memwinoff(struct board_info *b, unsigned int win)
  312. {
  313. }
  314. static void dummy_globalwinon(struct channel *ch)
  315. {
  316. }
  317. static void dummy_rxwinon(struct channel *ch)
  318. {
  319. }
  320. static void dummy_txwinon(struct channel *ch)
  321. {
  322. }
  323. static void dummy_memoff(struct channel *ch)
  324. {
  325. }
  326. static void dummy_assertgwinon(struct channel *ch)
  327. {
  328. }
  329. static void dummy_assertmemoff(struct channel *ch)
  330. {
  331. }
  332. /* ----------------- Begin verifyChannel function ----------------------- */
  333. static struct channel *verifyChannel(struct tty_struct *tty)
  334. { /* Begin verifyChannel */
  335. /* --------------------------------------------------------------------
  336. This routine basically provides a sanity check. It insures that
  337. the channel returned is within the proper range of addresses as
  338. well as properly initialized. If some bogus info gets passed in
  339. through tty->driver_data this should catch it.
  340. --------------------------------------------------------------------- */
  341. if (tty) {
  342. struct channel *ch = (struct channel *)tty->driver_data;
  343. if ((ch >= &digi_channels[0]) && (ch < &digi_channels[nbdevs])) {
  344. if (ch->magic == EPCA_MAGIC)
  345. return ch;
  346. }
  347. }
  348. return NULL;
  349. } /* End verifyChannel */
  350. /* ------------------ Begin pc_sched_event ------------------------- */
  351. static void pc_sched_event(struct channel *ch, int event)
  352. {
  353. /* ----------------------------------------------------------------------
  354. We call this to schedule interrupt processing on some event. The
  355. kernel sees our request and calls the related routine in OUR driver.
  356. -------------------------------------------------------------------------*/
  357. ch->event |= 1 << event;
  358. schedule_work(&ch->tqueue);
  359. } /* End pc_sched_event */
  360. /* ------------------ Begin epca_error ------------------------- */
  361. static void epca_error(int line, char *msg)
  362. {
  363. printk(KERN_ERR "epca_error (Digi): line = %d %s\n",line,msg);
  364. }
  365. /* ------------------ Begin pc_close ------------------------- */
  366. static void pc_close(struct tty_struct * tty, struct file * filp)
  367. {
  368. struct channel *ch;
  369. unsigned long flags;
  370. /* ---------------------------------------------------------
  371. verifyChannel returns the channel from the tty struct
  372. if it is valid. This serves as a sanity check.
  373. ------------------------------------------------------------- */
  374. if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
  375. spin_lock_irqsave(&epca_lock, flags);
  376. if (tty_hung_up_p(filp)) {
  377. spin_unlock_irqrestore(&epca_lock, flags);
  378. return;
  379. }
  380. /* Check to see if the channel is open more than once */
  381. if (ch->count-- > 1) {
  382. /* Begin channel is open more than once */
  383. /* -------------------------------------------------------------
  384. Return without doing anything. Someone might still be using
  385. the channel.
  386. ---------------------------------------------------------------- */
  387. spin_unlock_irqrestore(&epca_lock, flags);
  388. return;
  389. } /* End channel is open more than once */
  390. /* Port open only once go ahead with shutdown & reset */
  391. BUG_ON(ch->count < 0);
  392. /* ---------------------------------------------------------------
  393. Let the rest of the driver know the channel is being closed.
  394. This becomes important if an open is attempted before close
  395. is finished.
  396. ------------------------------------------------------------------ */
  397. ch->asyncflags |= ASYNC_CLOSING;
  398. tty->closing = 1;
  399. spin_unlock_irqrestore(&epca_lock, flags);
  400. if (ch->asyncflags & ASYNC_INITIALIZED) {
  401. /* Setup an event to indicate when the transmit buffer empties */
  402. setup_empty_event(tty, ch);
  403. tty_wait_until_sent(tty, 3000); /* 30 seconds timeout */
  404. }
  405. if (tty->driver->flush_buffer)
  406. tty->driver->flush_buffer(tty);
  407. tty_ldisc_flush(tty);
  408. shutdown(ch);
  409. spin_lock_irqsave(&epca_lock, flags);
  410. tty->closing = 0;
  411. ch->event = 0;
  412. ch->tty = NULL;
  413. spin_unlock_irqrestore(&epca_lock, flags);
  414. if (ch->blocked_open) { /* Begin if blocked_open */
  415. if (ch->close_delay)
  416. msleep_interruptible(jiffies_to_msecs(ch->close_delay));
  417. wake_up_interruptible(&ch->open_wait);
  418. } /* End if blocked_open */
  419. ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
  420. ASYNC_CLOSING);
  421. wake_up_interruptible(&ch->close_wait);
  422. } /* End if ch != NULL */
  423. } /* End pc_close */
  424. /* ------------------ Begin shutdown ------------------------- */
  425. static void shutdown(struct channel *ch)
  426. { /* Begin shutdown */
  427. unsigned long flags;
  428. struct tty_struct *tty;
  429. struct board_chan __iomem *bc;
  430. if (!(ch->asyncflags & ASYNC_INITIALIZED))
  431. return;
  432. spin_lock_irqsave(&epca_lock, flags);
  433. globalwinon(ch);
  434. bc = ch->brdchan;
  435. /* ------------------------------------------------------------------
  436. In order for an event to be generated on the receipt of data the
  437. idata flag must be set. Since we are shutting down, this is not
  438. necessary clear this flag.
  439. --------------------------------------------------------------------- */
  440. if (bc)
  441. writeb(0, &bc->idata);
  442. tty = ch->tty;
  443. /* ----------------------------------------------------------------
  444. If we're a modem control device and HUPCL is on, drop RTS & DTR.
  445. ------------------------------------------------------------------ */
  446. if (tty->termios->c_cflag & HUPCL) {
  447. ch->omodem &= ~(ch->m_rts | ch->m_dtr);
  448. fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
  449. }
  450. memoff(ch);
  451. /* ------------------------------------------------------------------
  452. The channel has officialy been closed. The next time it is opened
  453. it will have to reinitialized. Set a flag to indicate this.
  454. ---------------------------------------------------------------------- */
  455. /* Prevent future Digi programmed interrupts from coming active */
  456. ch->asyncflags &= ~ASYNC_INITIALIZED;
  457. spin_unlock_irqrestore(&epca_lock, flags);
  458. } /* End shutdown */
  459. /* ------------------ Begin pc_hangup ------------------------- */
  460. static void pc_hangup(struct tty_struct *tty)
  461. { /* Begin pc_hangup */
  462. struct channel *ch;
  463. /* ---------------------------------------------------------
  464. verifyChannel returns the channel from the tty struct
  465. if it is valid. This serves as a sanity check.
  466. ------------------------------------------------------------- */
  467. if ((ch = verifyChannel(tty)) != NULL) { /* Begin if ch != NULL */
  468. unsigned long flags;
  469. if (tty->driver->flush_buffer)
  470. tty->driver->flush_buffer(tty);
  471. tty_ldisc_flush(tty);
  472. shutdown(ch);
  473. spin_lock_irqsave(&epca_lock, flags);
  474. ch->tty = NULL;
  475. ch->event = 0;
  476. ch->count = 0;
  477. ch->asyncflags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
  478. spin_unlock_irqrestore(&epca_lock, flags);
  479. wake_up_interruptible(&ch->open_wait);
  480. } /* End if ch != NULL */
  481. } /* End pc_hangup */
  482. /* ------------------ Begin pc_write ------------------------- */
  483. static int pc_write(struct tty_struct * tty,
  484. const unsigned char *buf, int bytesAvailable)
  485. { /* Begin pc_write */
  486. unsigned int head, tail;
  487. int dataLen;
  488. int size;
  489. int amountCopied;
  490. struct channel *ch;
  491. unsigned long flags;
  492. int remain;
  493. struct board_chan __iomem *bc;
  494. /* ----------------------------------------------------------------
  495. pc_write is primarily called directly by the kernel routine
  496. tty_write (Though it can also be called by put_char) found in
  497. tty_io.c. pc_write is passed a line discipline buffer where
  498. the data to be written out is stored. The line discipline
  499. implementation itself is done at the kernel level and is not
  500. brought into the driver.
  501. ------------------------------------------------------------------- */
  502. /* ---------------------------------------------------------
  503. verifyChannel returns the channel from the tty struct
  504. if it is valid. This serves as a sanity check.
  505. ------------------------------------------------------------- */
  506. if ((ch = verifyChannel(tty)) == NULL)
  507. return 0;
  508. /* Make a pointer to the channel data structure found on the board. */
  509. bc = ch->brdchan;
  510. size = ch->txbufsize;
  511. amountCopied = 0;
  512. spin_lock_irqsave(&epca_lock, flags);
  513. globalwinon(ch);
  514. head = readw(&bc->tin) & (size - 1);
  515. tail = readw(&bc->tout);
  516. if (tail != readw(&bc->tout))
  517. tail = readw(&bc->tout);
  518. tail &= (size - 1);
  519. /* If head >= tail, head has not wrapped around. */
  520. if (head >= tail) { /* Begin head has not wrapped */
  521. /* ---------------------------------------------------------------
  522. remain (much like dataLen above) represents the total amount of
  523. space available on the card for data. Here dataLen represents
  524. the space existing between the head pointer and the end of
  525. buffer. This is important because a memcpy cannot be told to
  526. automatically wrap around when it hits the buffer end.
  527. ------------------------------------------------------------------ */
  528. dataLen = size - head;
  529. remain = size - (head - tail) - 1;
  530. } else { /* Begin head has wrapped around */
  531. remain = tail - head - 1;
  532. dataLen = remain;
  533. } /* End head has wrapped around */
  534. /* -------------------------------------------------------------------
  535. Check the space on the card. If we have more data than
  536. space; reduce the amount of data to fit the space.
  537. ---------------------------------------------------------------------- */
  538. bytesAvailable = min(remain, bytesAvailable);
  539. txwinon(ch);
  540. while (bytesAvailable > 0)
  541. { /* Begin while there is data to copy onto card */
  542. /* -----------------------------------------------------------------
  543. If head is not wrapped, the below will make sure the first
  544. data copy fills to the end of card buffer.
  545. ------------------------------------------------------------------- */
  546. dataLen = min(bytesAvailable, dataLen);
  547. memcpy_toio(ch->txptr + head, buf, dataLen);
  548. buf += dataLen;
  549. head += dataLen;
  550. amountCopied += dataLen;
  551. bytesAvailable -= dataLen;
  552. if (head >= size) {
  553. head = 0;
  554. dataLen = tail;
  555. }
  556. } /* End while there is data to copy onto card */
  557. ch->statusflags |= TXBUSY;
  558. globalwinon(ch);
  559. writew(head, &bc->tin);
  560. if ((ch->statusflags & LOWWAIT) == 0) {
  561. ch->statusflags |= LOWWAIT;
  562. writeb(1, &bc->ilow);
  563. }
  564. memoff(ch);
  565. spin_unlock_irqrestore(&epca_lock, flags);
  566. return(amountCopied);
  567. } /* End pc_write */
  568. /* ------------------ Begin pc_put_char ------------------------- */
  569. static void pc_put_char(struct tty_struct *tty, unsigned char c)
  570. { /* Begin pc_put_char */
  571. pc_write(tty, &c, 1);
  572. } /* End pc_put_char */
  573. /* ------------------ Begin pc_write_room ------------------------- */
  574. static int pc_write_room(struct tty_struct *tty)
  575. { /* Begin pc_write_room */
  576. int remain;
  577. struct channel *ch;
  578. unsigned long flags;
  579. unsigned int head, tail;
  580. struct board_chan __iomem *bc;
  581. remain = 0;
  582. /* ---------------------------------------------------------
  583. verifyChannel returns the channel from the tty struct
  584. if it is valid. This serves as a sanity check.
  585. ------------------------------------------------------------- */
  586. if ((ch = verifyChannel(tty)) != NULL) {
  587. spin_lock_irqsave(&epca_lock, flags);
  588. globalwinon(ch);
  589. bc = ch->brdchan;
  590. head = readw(&bc->tin) & (ch->txbufsize - 1);
  591. tail = readw(&bc->tout);
  592. if (tail != readw(&bc->tout))
  593. tail = readw(&bc->tout);
  594. /* Wrap tail if necessary */
  595. tail &= (ch->txbufsize - 1);
  596. if ((remain = tail - head - 1) < 0 )
  597. remain += ch->txbufsize;
  598. if (remain && (ch->statusflags & LOWWAIT) == 0) {
  599. ch->statusflags |= LOWWAIT;
  600. writeb(1, &bc->ilow);
  601. }
  602. memoff(ch);
  603. spin_unlock_irqrestore(&epca_lock, flags);
  604. }
  605. /* Return how much room is left on card */
  606. return remain;
  607. } /* End pc_write_room */
  608. /* ------------------ Begin pc_chars_in_buffer ---------------------- */
  609. static int pc_chars_in_buffer(struct tty_struct *tty)
  610. { /* Begin pc_chars_in_buffer */
  611. int chars;
  612. unsigned int ctail, head, tail;
  613. int remain;
  614. unsigned long flags;
  615. struct channel *ch;
  616. struct board_chan __iomem *bc;
  617. /* ---------------------------------------------------------
  618. verifyChannel returns the channel from the tty struct
  619. if it is valid. This serves as a sanity check.
  620. ------------------------------------------------------------- */
  621. if ((ch = verifyChannel(tty)) == NULL)
  622. return(0);
  623. spin_lock_irqsave(&epca_lock, flags);
  624. globalwinon(ch);
  625. bc = ch->brdchan;
  626. tail = readw(&bc->tout);
  627. head = readw(&bc->tin);
  628. ctail = readw(&ch->mailbox->cout);
  629. if (tail == head && readw(&ch->mailbox->cin) == ctail && readb(&bc->tbusy) == 0)
  630. chars = 0;
  631. else { /* Begin if some space on the card has been used */
  632. head = readw(&bc->tin) & (ch->txbufsize - 1);
  633. tail &= (ch->txbufsize - 1);
  634. /* --------------------------------------------------------------
  635. The logic here is basically opposite of the above pc_write_room
  636. here we are finding the amount of bytes in the buffer filled.
  637. Not the amount of bytes empty.
  638. ------------------------------------------------------------------- */
  639. if ((remain = tail - head - 1) < 0 )
  640. remain += ch->txbufsize;
  641. chars = (int)(ch->txbufsize - remain);
  642. /* -------------------------------------------------------------
  643. Make it possible to wakeup anything waiting for output
  644. in tty_ioctl.c, etc.
  645. If not already set. Setup an event to indicate when the
  646. transmit buffer empties
  647. ----------------------------------------------------------------- */
  648. if (!(ch->statusflags & EMPTYWAIT))
  649. setup_empty_event(tty,ch);
  650. } /* End if some space on the card has been used */
  651. memoff(ch);
  652. spin_unlock_irqrestore(&epca_lock, flags);
  653. /* Return number of characters residing on card. */
  654. return(chars);
  655. } /* End pc_chars_in_buffer */
  656. /* ------------------ Begin pc_flush_buffer ---------------------- */
  657. static void pc_flush_buffer(struct tty_struct *tty)
  658. { /* Begin pc_flush_buffer */
  659. unsigned int tail;
  660. unsigned long flags;
  661. struct channel *ch;
  662. struct board_chan __iomem *bc;
  663. /* ---------------------------------------------------------
  664. verifyChannel returns the channel from the tty struct
  665. if it is valid. This serves as a sanity check.
  666. ------------------------------------------------------------- */
  667. if ((ch = verifyChannel(tty)) == NULL)
  668. return;
  669. spin_lock_irqsave(&epca_lock, flags);
  670. globalwinon(ch);
  671. bc = ch->brdchan;
  672. tail = readw(&bc->tout);
  673. /* Have FEP move tout pointer; effectively flushing transmit buffer */
  674. fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
  675. memoff(ch);
  676. spin_unlock_irqrestore(&epca_lock, flags);
  677. wake_up_interruptible(&tty->write_wait);
  678. tty_wakeup(tty);
  679. } /* End pc_flush_buffer */
  680. /* ------------------ Begin pc_flush_chars ---------------------- */
  681. static void pc_flush_chars(struct tty_struct *tty)
  682. { /* Begin pc_flush_chars */
  683. struct channel * ch;
  684. /* ---------------------------------------------------------
  685. verifyChannel returns the channel from the tty struct
  686. if it is valid. This serves as a sanity check.
  687. ------------------------------------------------------------- */
  688. if ((ch = verifyChannel(tty)) != NULL) {
  689. unsigned long flags;
  690. spin_lock_irqsave(&epca_lock, flags);
  691. /* ----------------------------------------------------------------
  692. If not already set and the transmitter is busy setup an event
  693. to indicate when the transmit empties.
  694. ------------------------------------------------------------------- */
  695. if ((ch->statusflags & TXBUSY) && !(ch->statusflags & EMPTYWAIT))
  696. setup_empty_event(tty,ch);
  697. spin_unlock_irqrestore(&epca_lock, flags);
  698. }
  699. } /* End pc_flush_chars */
  700. /* ------------------ Begin block_til_ready ---------------------- */
  701. static int block_til_ready(struct tty_struct *tty,
  702. struct file *filp, struct channel *ch)
  703. { /* Begin block_til_ready */
  704. DECLARE_WAITQUEUE(wait,current);
  705. int retval, do_clocal = 0;
  706. unsigned long flags;
  707. if (tty_hung_up_p(filp)) {
  708. if (ch->asyncflags & ASYNC_HUP_NOTIFY)
  709. retval = -EAGAIN;
  710. else
  711. retval = -ERESTARTSYS;
  712. return(retval);
  713. }
  714. /* -----------------------------------------------------------------
  715. If the device is in the middle of being closed, then block
  716. until it's done, and then try again.
  717. -------------------------------------------------------------------- */
  718. if (ch->asyncflags & ASYNC_CLOSING) {
  719. interruptible_sleep_on(&ch->close_wait);
  720. if (ch->asyncflags & ASYNC_HUP_NOTIFY)
  721. return -EAGAIN;
  722. else
  723. return -ERESTARTSYS;
  724. }
  725. if (filp->f_flags & O_NONBLOCK) {
  726. /* -----------------------------------------------------------------
  727. If non-blocking mode is set, then make the check up front
  728. and then exit.
  729. -------------------------------------------------------------------- */
  730. ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
  731. return 0;
  732. }
  733. if (tty->termios->c_cflag & CLOCAL)
  734. do_clocal = 1;
  735. /* Block waiting for the carrier detect and the line to become free */
  736. retval = 0;
  737. add_wait_queue(&ch->open_wait, &wait);
  738. spin_lock_irqsave(&epca_lock, flags);
  739. /* We dec count so that pc_close will know when to free things */
  740. if (!tty_hung_up_p(filp))
  741. ch->count--;
  742. ch->blocked_open++;
  743. while(1)
  744. { /* Begin forever while */
  745. set_current_state(TASK_INTERRUPTIBLE);
  746. if (tty_hung_up_p(filp) ||
  747. !(ch->asyncflags & ASYNC_INITIALIZED))
  748. {
  749. if (ch->asyncflags & ASYNC_HUP_NOTIFY)
  750. retval = -EAGAIN;
  751. else
  752. retval = -ERESTARTSYS;
  753. break;
  754. }
  755. if (!(ch->asyncflags & ASYNC_CLOSING) &&
  756. (do_clocal || (ch->imodem & ch->dcd)))
  757. break;
  758. if (signal_pending(current)) {
  759. retval = -ERESTARTSYS;
  760. break;
  761. }
  762. spin_unlock_irqrestore(&epca_lock, flags);
  763. /* ---------------------------------------------------------------
  764. Allow someone else to be scheduled. We will occasionally go
  765. through this loop until one of the above conditions change.
  766. The below schedule call will allow other processes to enter and
  767. prevent this loop from hogging the cpu.
  768. ------------------------------------------------------------------ */
  769. schedule();
  770. spin_lock_irqsave(&epca_lock, flags);
  771. } /* End forever while */
  772. current->state = TASK_RUNNING;
  773. remove_wait_queue(&ch->open_wait, &wait);
  774. if (!tty_hung_up_p(filp))
  775. ch->count++;
  776. ch->blocked_open--;
  777. spin_unlock_irqrestore(&epca_lock, flags);
  778. if (retval)
  779. return retval;
  780. ch->asyncflags |= ASYNC_NORMAL_ACTIVE;
  781. return 0;
  782. } /* End block_til_ready */
  783. /* ------------------ Begin pc_open ---------------------- */
  784. static int pc_open(struct tty_struct *tty, struct file * filp)
  785. { /* Begin pc_open */
  786. struct channel *ch;
  787. unsigned long flags;
  788. int line, retval, boardnum;
  789. struct board_chan __iomem *bc;
  790. unsigned int head;
  791. line = tty->index;
  792. if (line < 0 || line >= nbdevs)
  793. return -ENODEV;
  794. ch = &digi_channels[line];
  795. boardnum = ch->boardnum;
  796. /* Check status of board configured in system. */
  797. /* -----------------------------------------------------------------
  798. I check to see if the epca_setup routine detected an user error.
  799. It might be better to put this in pc_init, but for the moment it
  800. goes here.
  801. ---------------------------------------------------------------------- */
  802. if (invalid_lilo_config) {
  803. if (setup_error_code & INVALID_BOARD_TYPE)
  804. printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
  805. if (setup_error_code & INVALID_NUM_PORTS)
  806. printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
  807. if (setup_error_code & INVALID_MEM_BASE)
  808. printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
  809. if (setup_error_code & INVALID_PORT_BASE)
  810. printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
  811. if (setup_error_code & INVALID_BOARD_STATUS)
  812. printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
  813. if (setup_error_code & INVALID_ALTPIN)
  814. printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
  815. tty->driver_data = NULL; /* Mark this device as 'down' */
  816. return -ENODEV;
  817. }
  818. if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
  819. tty->driver_data = NULL; /* Mark this device as 'down' */
  820. return(-ENODEV);
  821. }
  822. if ((bc = ch->brdchan) == 0) {
  823. tty->driver_data = NULL;
  824. return -ENODEV;
  825. }
  826. spin_lock_irqsave(&epca_lock, flags);
  827. /* ------------------------------------------------------------------
  828. Every time a channel is opened, increment a counter. This is
  829. necessary because we do not wish to flush and shutdown the channel
  830. until the last app holding the channel open, closes it.
  831. --------------------------------------------------------------------- */
  832. ch->count++;
  833. /* ----------------------------------------------------------------
  834. Set a kernel structures pointer to our local channel
  835. structure. This way we can get to it when passed only
  836. a tty struct.
  837. ------------------------------------------------------------------ */
  838. tty->driver_data = ch;
  839. /* ----------------------------------------------------------------
  840. If this is the first time the channel has been opened, initialize
  841. the tty->termios struct otherwise let pc_close handle it.
  842. -------------------------------------------------------------------- */
  843. globalwinon(ch);
  844. ch->statusflags = 0;
  845. /* Save boards current modem status */
  846. ch->imodem = readb(&bc->mstat);
  847. /* ----------------------------------------------------------------
  848. Set receive head and tail ptrs to each other. This indicates
  849. no data available to read.
  850. ----------------------------------------------------------------- */
  851. head = readw(&bc->rin);
  852. writew(head, &bc->rout);
  853. /* Set the channels associated tty structure */
  854. ch->tty = tty;
  855. /* -----------------------------------------------------------------
  856. The below routine generally sets up parity, baud, flow control
  857. issues, etc.... It effect both control flags and input flags.
  858. -------------------------------------------------------------------- */
  859. epcaparam(tty,ch);
  860. ch->asyncflags |= ASYNC_INITIALIZED;
  861. memoff(ch);
  862. spin_unlock_irqrestore(&epca_lock, flags);
  863. retval = block_til_ready(tty, filp, ch);
  864. if (retval)
  865. return retval;
  866. /* -------------------------------------------------------------
  867. Set this again in case a hangup set it to zero while this
  868. open() was waiting for the line...
  869. --------------------------------------------------------------- */
  870. spin_lock_irqsave(&epca_lock, flags);
  871. ch->tty = tty;
  872. globalwinon(ch);
  873. /* Enable Digi Data events */
  874. writeb(1, &bc->idata);
  875. memoff(ch);
  876. spin_unlock_irqrestore(&epca_lock, flags);
  877. return 0;
  878. } /* End pc_open */
  879. static int __init epca_module_init(void)
  880. { /* Begin init_module */
  881. return pc_init();
  882. }
  883. module_init(epca_module_init);
  884. static struct pci_driver epca_driver;
  885. static void __exit epca_module_exit(void)
  886. {
  887. int count, crd;
  888. struct board_info *bd;
  889. struct channel *ch;
  890. del_timer_sync(&epca_timer);
  891. if ((tty_unregister_driver(pc_driver)) ||
  892. (tty_unregister_driver(pc_info)))
  893. {
  894. printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
  895. return;
  896. }
  897. put_tty_driver(pc_driver);
  898. put_tty_driver(pc_info);
  899. for (crd = 0; crd < num_cards; crd++) { /* Begin for each card */
  900. bd = &boards[crd];
  901. if (!bd)
  902. { /* Begin sanity check */
  903. printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
  904. return;
  905. } /* End sanity check */
  906. ch = card_ptr[crd];
  907. for (count = 0; count < bd->numports; count++, ch++)
  908. { /* Begin for each port */
  909. if (ch) {
  910. if (ch->tty)
  911. tty_hangup(ch->tty);
  912. kfree(ch->tmp_buf);
  913. }
  914. } /* End for each port */
  915. } /* End for each card */
  916. pci_unregister_driver (&epca_driver);
  917. }
  918. module_exit(epca_module_exit);
  919. static struct tty_operations pc_ops = {
  920. .open = pc_open,
  921. .close = pc_close,
  922. .write = pc_write,
  923. .write_room = pc_write_room,
  924. .flush_buffer = pc_flush_buffer,
  925. .chars_in_buffer = pc_chars_in_buffer,
  926. .flush_chars = pc_flush_chars,
  927. .put_char = pc_put_char,
  928. .ioctl = pc_ioctl,
  929. .set_termios = pc_set_termios,
  930. .stop = pc_stop,
  931. .start = pc_start,
  932. .throttle = pc_throttle,
  933. .unthrottle = pc_unthrottle,
  934. .hangup = pc_hangup,
  935. };
  936. static int info_open(struct tty_struct *tty, struct file * filp)
  937. {
  938. return 0;
  939. }
  940. static struct tty_operations info_ops = {
  941. .open = info_open,
  942. .ioctl = info_ioctl,
  943. };
  944. /* ------------------ Begin pc_init ---------------------- */
  945. static int __init pc_init(void)
  946. { /* Begin pc_init */
  947. int crd;
  948. struct board_info *bd;
  949. unsigned char board_id = 0;
  950. int pci_boards_found, pci_count;
  951. pci_count = 0;
  952. pc_driver = alloc_tty_driver(MAX_ALLOC);
  953. if (!pc_driver)
  954. return -ENOMEM;
  955. pc_info = alloc_tty_driver(MAX_ALLOC);
  956. if (!pc_info) {
  957. put_tty_driver(pc_driver);
  958. return -ENOMEM;
  959. }
  960. /* -----------------------------------------------------------------------
  961. If epca_setup has not been ran by LILO set num_cards to defaults; copy
  962. board structure defined by digiConfig into drivers board structure.
  963. Note : If LILO has ran epca_setup then epca_setup will handle defining
  964. num_cards as well as copying the data into the board structure.
  965. -------------------------------------------------------------------------- */
  966. if (!liloconfig) { /* Begin driver has been configured via. epcaconfig */
  967. nbdevs = NBDEVS;
  968. num_cards = NUMCARDS;
  969. memcpy((void *)&boards, (void *)&static_boards,
  970. (sizeof(struct board_info) * NUMCARDS));
  971. } /* End driver has been configured via. epcaconfig */
  972. /* -----------------------------------------------------------------
  973. Note : If lilo was used to configure the driver and the
  974. ignore epcaconfig option was choosen (digiepca=2) then
  975. nbdevs and num_cards will equal 0 at this point. This is
  976. okay; PCI cards will still be picked up if detected.
  977. --------------------------------------------------------------------- */
  978. /* -----------------------------------------------------------
  979. Set up interrupt, we will worry about memory allocation in
  980. post_fep_init.
  981. --------------------------------------------------------------- */
  982. printk(KERN_INFO "DIGI epca driver version %s loaded.\n",VERSION);
  983. /* ------------------------------------------------------------------
  984. NOTE : This code assumes that the number of ports found in
  985. the boards array is correct. This could be wrong if
  986. the card in question is PCI (And therefore has no ports
  987. entry in the boards structure.) The rest of the
  988. information will be valid for PCI because the beginning
  989. of pc_init scans for PCI and determines i/o and base
  990. memory addresses. I am not sure if it is possible to
  991. read the number of ports supported by the card prior to
  992. it being booted (Since that is the state it is in when
  993. pc_init is run). Because it is not possible to query the
  994. number of supported ports until after the card has booted;
  995. we are required to calculate the card_ptrs as the card is
  996. is initialized (Inside post_fep_init). The negative thing
  997. about this approach is that digiDload's call to GET_INFO
  998. will have a bad port value. (Since this is called prior
  999. to post_fep_init.)
  1000. --------------------------------------------------------------------- */
  1001. pci_boards_found = 0;
  1002. if(num_cards < MAXBOARDS)
  1003. pci_boards_found += init_PCI();
  1004. num_cards += pci_boards_found;
  1005. pc_driver->owner = THIS_MODULE;
  1006. pc_driver->name = "ttyD";
  1007. pc_driver->devfs_name = "tts/D";
  1008. pc_driver->major = DIGI_MAJOR;
  1009. pc_driver->minor_start = 0;
  1010. pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
  1011. pc_driver->subtype = SERIAL_TYPE_NORMAL;
  1012. pc_driver->init_termios = tty_std_termios;
  1013. pc_driver->init_termios.c_iflag = 0;
  1014. pc_driver->init_termios.c_oflag = 0;
  1015. pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
  1016. pc_driver->init_termios.c_lflag = 0;
  1017. pc_driver->flags = TTY_DRIVER_REAL_RAW;
  1018. tty_set_operations(pc_driver, &pc_ops);
  1019. pc_info->owner = THIS_MODULE;
  1020. pc_info->name = "digi_ctl";
  1021. pc_info->major = DIGIINFOMAJOR;
  1022. pc_info->minor_start = 0;
  1023. pc_info->type = TTY_DRIVER_TYPE_SERIAL;
  1024. pc_info->subtype = SERIAL_TYPE_INFO;
  1025. pc_info->init_termios = tty_std_termios;
  1026. pc_info->init_termios.c_iflag = 0;
  1027. pc_info->init_termios.c_oflag = 0;
  1028. pc_info->init_termios.c_lflag = 0;
  1029. pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
  1030. pc_info->flags = TTY_DRIVER_REAL_RAW;
  1031. tty_set_operations(pc_info, &info_ops);
  1032. for (crd = 0; crd < num_cards; crd++)
  1033. { /* Begin for each card */
  1034. /* ------------------------------------------------------------------
  1035. This is where the appropriate memory handlers for the hardware is
  1036. set. Everything at runtime blindly jumps through these vectors.
  1037. ---------------------------------------------------------------------- */
  1038. /* defined in epcaconfig.h */
  1039. bd = &boards[crd];
  1040. switch (bd->type)
  1041. { /* Begin switch on bd->type {board type} */
  1042. case PCXEM:
  1043. case EISAXEM:
  1044. bd->memwinon = pcxem_memwinon ;
  1045. bd->memwinoff = pcxem_memwinoff ;
  1046. bd->globalwinon = pcxem_globalwinon ;
  1047. bd->txwinon = pcxem_txwinon ;
  1048. bd->rxwinon = pcxem_rxwinon ;
  1049. bd->memoff = pcxem_memoff ;
  1050. bd->assertgwinon = dummy_assertgwinon;
  1051. bd->assertmemoff = dummy_assertmemoff;
  1052. break;
  1053. case PCIXEM:
  1054. case PCIXRJ:
  1055. case PCIXR:
  1056. bd->memwinon = dummy_memwinon;
  1057. bd->memwinoff = dummy_memwinoff;
  1058. bd->globalwinon = dummy_globalwinon;
  1059. bd->txwinon = dummy_txwinon;
  1060. bd->rxwinon = dummy_rxwinon;
  1061. bd->memoff = dummy_memoff;
  1062. bd->assertgwinon = dummy_assertgwinon;
  1063. bd->assertmemoff = dummy_assertmemoff;
  1064. break;
  1065. case PCXE:
  1066. case PCXEVE:
  1067. bd->memwinon = pcxe_memwinon;
  1068. bd->memwinoff = pcxe_memwinoff;
  1069. bd->globalwinon = pcxe_globalwinon;
  1070. bd->txwinon = pcxe_txwinon;
  1071. bd->rxwinon = pcxe_rxwinon;
  1072. bd->memoff = pcxe_memoff;
  1073. bd->assertgwinon = dummy_assertgwinon;
  1074. bd->assertmemoff = dummy_assertmemoff;
  1075. break;
  1076. case PCXI:
  1077. case PC64XE:
  1078. bd->memwinon = pcxi_memwinon;
  1079. bd->memwinoff = pcxi_memwinoff;
  1080. bd->globalwinon = pcxi_globalwinon;
  1081. bd->txwinon = pcxi_txwinon;
  1082. bd->rxwinon = pcxi_rxwinon;
  1083. bd->memoff = pcxi_memoff;
  1084. bd->assertgwinon = pcxi_assertgwinon;
  1085. bd->assertmemoff = pcxi_assertmemoff;
  1086. break;
  1087. default:
  1088. break;
  1089. } /* End switch on bd->type */
  1090. /* ---------------------------------------------------------------
  1091. Some cards need a memory segment to be defined for use in
  1092. transmit and receive windowing operations. These boards
  1093. are listed in the below switch. In the case of the XI the
  1094. amount of memory on the board is variable so the memory_seg
  1095. is also variable. This code determines what they segment
  1096. should be.
  1097. ----------------------------------------------------------------- */
  1098. switch (bd->type)
  1099. { /* Begin switch on bd->type {board type} */
  1100. case PCXE:
  1101. case PCXEVE:
  1102. case PC64XE:
  1103. bd->memory_seg = 0xf000;
  1104. break;
  1105. case PCXI:
  1106. board_id = inb((int)bd->port);
  1107. if ((board_id & 0x1) == 0x1)
  1108. { /* Begin it's an XI card */
  1109. /* Is it a 64K board */
  1110. if ((board_id & 0x30) == 0)
  1111. bd->memory_seg = 0xf000;
  1112. /* Is it a 128K board */
  1113. if ((board_id & 0x30) == 0x10)
  1114. bd->memory_seg = 0xe000;
  1115. /* Is is a 256K board */
  1116. if ((board_id & 0x30) == 0x20)
  1117. bd->memory_seg = 0xc000;
  1118. /* Is it a 512K board */
  1119. if ((board_id & 0x30) == 0x30)
  1120. bd->memory_seg = 0x8000;
  1121. } else printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n",(int)bd->port);
  1122. break;
  1123. } /* End switch on bd->type */
  1124. } /* End for each card */
  1125. if (tty_register_driver(pc_driver))
  1126. panic("Couldn't register Digi PC/ driver");
  1127. if (tty_register_driver(pc_info))
  1128. panic("Couldn't register Digi PC/ info ");
  1129. /* -------------------------------------------------------------------
  1130. Start up the poller to check for events on all enabled boards
  1131. ---------------------------------------------------------------------- */
  1132. init_timer(&epca_timer);
  1133. epca_timer.function = epcapoll;
  1134. mod_timer(&epca_timer, jiffies + HZ/25);
  1135. return 0;
  1136. } /* End pc_init */
  1137. /* ------------------ Begin post_fep_init ---------------------- */
  1138. static void post_fep_init(unsigned int crd)
  1139. { /* Begin post_fep_init */
  1140. int i;
  1141. void __iomem *memaddr;
  1142. struct global_data __iomem *gd;
  1143. struct board_info *bd;
  1144. struct board_chan __iomem *bc;
  1145. struct channel *ch;
  1146. int shrinkmem = 0, lowwater ;
  1147. /* -------------------------------------------------------------
  1148. This call is made by the user via. the ioctl call DIGI_INIT.
  1149. It is responsible for setting up all the card specific stuff.
  1150. ---------------------------------------------------------------- */
  1151. bd = &boards[crd];
  1152. /* -----------------------------------------------------------------
  1153. If this is a PCI board, get the port info. Remember PCI cards
  1154. do not have entries into the epcaconfig.h file, so we can't get
  1155. the number of ports from it. Unfortunetly, this means that anyone
  1156. doing a DIGI_GETINFO before the board has booted will get an invalid
  1157. number of ports returned (It should return 0). Calls to DIGI_GETINFO
  1158. after DIGI_INIT has been called will return the proper values.
  1159. ------------------------------------------------------------------- */
  1160. if (bd->type >= PCIXEM) { /* Begin get PCI number of ports */
  1161. /* --------------------------------------------------------------------
  1162. Below we use XEMPORTS as a memory offset regardless of which PCI
  1163. card it is. This is because all of the supported PCI cards have
  1164. the same memory offset for the channel data. This will have to be
  1165. changed if we ever develop a PCI/XE card. NOTE : The FEP manual
  1166. states that the port offset is 0xC22 as opposed to 0xC02. This is
  1167. only true for PC/XE, and PC/XI cards; not for the XEM, or CX series.
  1168. On the PCI cards the number of ports is determined by reading a
  1169. ID PROM located in the box attached to the card. The card can then
  1170. determine the index the id to determine the number of ports available.
  1171. (FYI - The id should be located at 0x1ac (And may use up to 4 bytes
  1172. if the box in question is a XEM or CX)).
  1173. ------------------------------------------------------------------------ */
  1174. /* PCI cards are already remapped at this point ISA are not */
  1175. bd->numports = readw(bd->re_map_membase + XEMPORTS);
  1176. epcaassert(bd->numports <= 64,"PCI returned a invalid number of ports");
  1177. nbdevs += (bd->numports);
  1178. } else {
  1179. /* Fix up the mappings for ISA/EISA etc */
  1180. /* FIXME: 64K - can we be smarter ? */
  1181. bd->re_map_membase = ioremap(bd->membase, 0x10000);
  1182. }
  1183. if (crd != 0)
  1184. card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
  1185. else
  1186. card_ptr[crd] = &digi_channels[crd]; /* <- For card 0 only */
  1187. ch = card_ptr[crd];
  1188. epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
  1189. memaddr = bd->re_map_membase;
  1190. /* -----------------------------------------------------------------
  1191. The below assignment will set bc to point at the BEGINING of
  1192. the cards channel structures. For 1 card there will be between
  1193. 8 and 64 of these structures.
  1194. -------------------------------------------------------------------- */
  1195. bc = memaddr + CHANSTRUCT;
  1196. /* -------------------------------------------------------------------
  1197. The below assignment will set gd to point at the BEGINING of
  1198. global memory address 0xc00. The first data in that global
  1199. memory actually starts at address 0xc1a. The command in
  1200. pointer begins at 0xd10.
  1201. ---------------------------------------------------------------------- */
  1202. gd = memaddr + GLOBAL;
  1203. /* --------------------------------------------------------------------
  1204. XEPORTS (address 0xc22) points at the number of channels the
  1205. card supports. (For 64XE, XI, XEM, and XR use 0xc02)
  1206. ----------------------------------------------------------------------- */
  1207. if ((bd->type == PCXEVE || bd->type == PCXE) && (readw(memaddr + XEPORTS) < 3))
  1208. shrinkmem = 1;
  1209. if (bd->type < PCIXEM)
  1210. if (!request_region((int)bd->port, 4, board_desc[bd->type]))
  1211. return;
  1212. memwinon(bd, 0);
  1213. /* --------------------------------------------------------------------
  1214. Remember ch is the main drivers channels structure, while bc is
  1215. the cards channel structure.
  1216. ------------------------------------------------------------------------ */
  1217. /* For every port on the card do ..... */
  1218. for (i = 0; i < bd->numports; i++, ch++, bc++) { /* Begin for each port */
  1219. unsigned long flags;
  1220. u16 tseg, rseg;
  1221. ch->brdchan = bc;
  1222. ch->mailbox = gd;
  1223. INIT_WORK(&ch->tqueue, do_softint, ch);
  1224. ch->board = &boards[crd];
  1225. spin_lock_irqsave(&epca_lock, flags);
  1226. switch (bd->type) {
  1227. /* ----------------------------------------------------------------
  1228. Since some of the boards use different bitmaps for their
  1229. control signals we cannot hard code these values and retain
  1230. portability. We virtualize this data here.
  1231. ------------------------------------------------------------------- */
  1232. case EISAXEM:
  1233. case PCXEM:
  1234. case PCIXEM:
  1235. case PCIXRJ:
  1236. case PCIXR:
  1237. ch->m_rts = 0x02 ;
  1238. ch->m_dcd = 0x80 ;
  1239. ch->m_dsr = 0x20 ;
  1240. ch->m_cts = 0x10 ;
  1241. ch->m_ri = 0x40 ;
  1242. ch->m_dtr = 0x01 ;
  1243. break;
  1244. case PCXE:
  1245. case PCXEVE:
  1246. case PCXI:
  1247. case PC64XE:
  1248. ch->m_rts = 0x02 ;
  1249. ch->m_dcd = 0x08 ;
  1250. ch->m_dsr = 0x10 ;
  1251. ch->m_cts = 0x20 ;
  1252. ch->m_ri = 0x40 ;
  1253. ch->m_dtr = 0x80 ;
  1254. break;
  1255. } /* End switch bd->type */
  1256. if (boards[crd].altpin) {
  1257. ch->dsr = ch->m_dcd;
  1258. ch->dcd = ch->m_dsr;
  1259. ch->digiext.digi_flags |= DIGI_ALTPIN;
  1260. }
  1261. else {
  1262. ch->dcd = ch->m_dcd;
  1263. ch->dsr = ch->m_dsr;
  1264. }
  1265. ch->boardnum = crd;
  1266. ch->channelnum = i;
  1267. ch->magic = EPCA_MAGIC;
  1268. ch->tty = NULL;
  1269. if (shrinkmem) {
  1270. fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
  1271. shrinkmem = 0;
  1272. }
  1273. tseg = readw(&bc->tseg);
  1274. rseg = readw(&bc->rseg);
  1275. switch (bd->type) {
  1276. case PCIXEM:
  1277. case PCIXRJ:
  1278. case PCIXR:
  1279. /* Cover all the 2MEG cards */
  1280. ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
  1281. ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
  1282. ch->txwin = FEPWIN | (tseg >> 11);
  1283. ch->rxwin = FEPWIN | (rseg >> 11);
  1284. break;
  1285. case PCXEM:
  1286. case EISAXEM:
  1287. /* Cover all the 32K windowed cards */
  1288. /* Mask equal to window size - 1 */
  1289. ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
  1290. ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
  1291. ch->txwin = FEPWIN | (tseg >> 11);
  1292. ch->rxwin = FEPWIN | (rseg >> 11);
  1293. break;
  1294. case PCXEVE:
  1295. case PCXE:
  1296. ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4) & 0x1fff);
  1297. ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
  1298. ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4) & 0x1fff);
  1299. ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >>9 );
  1300. break;
  1301. case PCXI:
  1302. case PC64XE:
  1303. ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
  1304. ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
  1305. ch->txwin = ch->rxwin = 0;
  1306. break;
  1307. } /* End switch bd->type */
  1308. ch->txbufhead = 0;
  1309. ch->txbufsize = readw(&bc->tmax) + 1;
  1310. ch->rxbufhead = 0;
  1311. ch->rxbufsize = readw(&bc->rmax) + 1;
  1312. lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
  1313. /* Set transmitter low water mark */
  1314. fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
  1315. /* Set receiver low water mark */
  1316. fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
  1317. /* Set receiver high water mark */
  1318. fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
  1319. writew(100, &bc->edelay);
  1320. writeb(1, &bc->idata);
  1321. ch->startc = readb(&bc->startc);
  1322. ch->stopc = readb(&bc->stopc);
  1323. ch->startca = readb(&bc->startca);
  1324. ch->stopca = readb(&bc->stopca);
  1325. ch->fepcflag = 0;
  1326. ch->fepiflag = 0;
  1327. ch->fepoflag = 0;
  1328. ch->fepstartc = 0;
  1329. ch->fepstopc = 0;
  1330. ch->fepstartca = 0;
  1331. ch->fepstopca = 0;
  1332. ch->close_delay = 50;
  1333. ch->count = 0;
  1334. ch->blocked_open = 0;
  1335. init_waitqueue_head(&ch->open_wait);
  1336. init_waitqueue_head(&ch->close_wait);
  1337. spin_unlock_irqrestore(&epca_lock, flags);
  1338. ch->tmp_buf = kmalloc(ch->txbufsize,GFP_KERNEL);
  1339. if (!ch->tmp_buf) {
  1340. printk(KERN_ERR "POST FEP INIT : kmalloc failed for port 0x%x\n",i);
  1341. release_region((int)bd->port, 4);
  1342. while(i-- > 0)
  1343. kfree((ch--)->tmp_buf);
  1344. return;
  1345. } else
  1346. memset((void *)ch->tmp_buf,0,ch->txbufsize);
  1347. } /* End for each port */
  1348. printk(KERN_INFO
  1349. "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
  1350. VERSION, board_desc[bd->type], (long)bd->port, (long)bd->membase, bd->numports);
  1351. memwinoff(bd, 0);
  1352. } /* End post_fep_init */
  1353. /* --------------------- Begin epcapoll ------------------------ */
  1354. static void epcapoll(unsigned long ignored)
  1355. { /* Begin epcapoll */
  1356. unsigned long flags;
  1357. int crd;
  1358. volatile unsigned int head, tail;
  1359. struct channel *ch;
  1360. struct board_info *bd;
  1361. /* -------------------------------------------------------------------
  1362. This routine is called upon every timer interrupt. Even though
  1363. the Digi series cards are capable of generating interrupts this
  1364. method of non-looping polling is more efficient. This routine
  1365. checks for card generated events (Such as receive data, are transmit
  1366. buffer empty) and acts on those events.
  1367. ----------------------------------------------------------------------- */
  1368. for (crd = 0; crd < num_cards; crd++)
  1369. { /* Begin for each card */
  1370. bd = &boards[crd];
  1371. ch = card_ptr[crd];
  1372. if ((bd->status == DISABLED) || digi_poller_inhibited)
  1373. continue; /* Begin loop next interation */
  1374. /* -----------------------------------------------------------
  1375. assertmemoff is not needed here; indeed it is an empty subroutine.
  1376. It is being kept because future boards may need this as well as
  1377. some legacy boards.
  1378. ---------------------------------------------------------------- */
  1379. spin_lock_irqsave(&epca_lock, flags);
  1380. assertmemoff(ch);
  1381. globalwinon(ch);
  1382. /* ---------------------------------------------------------------
  1383. In this case head and tail actually refer to the event queue not
  1384. the transmit or receive queue.
  1385. ------------------------------------------------------------------- */
  1386. head = readw(&ch->mailbox->ein);
  1387. tail = readw(&ch->mailbox->eout);
  1388. /* If head isn't equal to tail we have an event */
  1389. if (head != tail)
  1390. doevent(crd);
  1391. memoff(ch);
  1392. spin_unlock_irqrestore(&epca_lock, flags);
  1393. } /* End for each card */
  1394. mod_timer(&epca_timer, jiffies + (HZ / 25));
  1395. } /* End epcapoll */
  1396. /* --------------------- Begin doevent ------------------------ */
  1397. static void doevent(int crd)
  1398. { /* Begin doevent */
  1399. void __iomem *eventbuf;
  1400. struct channel *ch, *chan0;
  1401. static struct tty_struct *tty;
  1402. struct board_info *bd;
  1403. struct board_chan __iomem *bc;
  1404. unsigned int tail, head;
  1405. int event, channel;
  1406. int mstat, lstat;
  1407. /* -------------------------------------------------------------------
  1408. This subroutine is called by epcapoll when an event is detected
  1409. in the event queue. This routine responds to those events.
  1410. --------------------------------------------------------------------- */
  1411. bd = &boards[crd];
  1412. chan0 = card_ptr[crd];
  1413. epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
  1414. assertgwinon(chan0);
  1415. while ((tail = readw(&chan0->mailbox->eout)) != (head = readw(&chan0->mailbox->ein)))
  1416. { /* Begin while something in event queue */
  1417. assertgwinon(chan0);
  1418. eventbuf = bd->re_map_membase + tail + ISTART;
  1419. /* Get the channel the event occurred on */
  1420. channel = readb(eventbuf);
  1421. /* Get the actual event code that occurred */
  1422. event = readb(eventbuf + 1);
  1423. /* ----------------------------------------------------------------
  1424. The two assignments below get the current modem status (mstat)
  1425. and the previous modem status (lstat). These are useful becuase
  1426. an event could signal a change in modem signals itself.
  1427. ------------------------------------------------------------------- */
  1428. mstat = readb(eventbuf + 2);
  1429. lstat = readb(eventbuf + 3);
  1430. ch = chan0 + channel;
  1431. if ((unsigned)channel >= bd->numports || !ch) {
  1432. if (channel >= bd->numports)
  1433. ch = chan0;
  1434. bc = ch->brdchan;
  1435. goto next;
  1436. }
  1437. if ((bc = ch->brdchan) == NULL)
  1438. goto next;
  1439. if (event & DATA_IND) { /* Begin DATA_IND */
  1440. receive_data(ch);
  1441. assertgwinon(ch);
  1442. } /* End DATA_IND */
  1443. /* else *//* Fix for DCD transition missed bug */
  1444. if (event & MODEMCHG_IND) { /* Begin MODEMCHG_IND */
  1445. /* A modem signal change has been indicated */
  1446. ch->imodem = mstat;
  1447. if (ch->asyncflags & ASYNC_CHECK_CD) {
  1448. if (mstat & ch->dcd) /* We are now receiving dcd */
  1449. wake_up_interruptible(&ch->open_wait);
  1450. else
  1451. pc_sched_event(ch, EPCA_EVENT_HANGUP); /* No dcd; hangup */
  1452. }
  1453. } /* End MODEMCHG_IND */
  1454. tty = ch->tty;
  1455. if (tty) { /* Begin if valid tty */
  1456. if (event & BREAK_IND) { /* Begin if BREAK_IND */
  1457. /* A break has been indicated */
  1458. tty_insert_flip_char(tty, 0, TTY_BREAK);
  1459. tty_schedule_flip(tty);
  1460. } else if (event & LOWTX_IND) { /* Begin LOWTX_IND */
  1461. if (ch->statusflags & LOWWAIT)
  1462. { /* Begin if LOWWAIT */
  1463. ch->statusflags &= ~LOWWAIT;
  1464. tty_wakeup(tty);
  1465. wake_up_interruptible(&tty->write_wait);
  1466. } /* End if LOWWAIT */
  1467. } else if (event & EMPTYTX_IND) { /* Begin EMPTYTX_IND */
  1468. /* This event is generated by setup_empty_event */
  1469. ch->statusflags &= ~TXBUSY;
  1470. if (ch->statusflags & EMPTYWAIT) { /* Begin if EMPTYWAIT */
  1471. ch->statusflags &= ~EMPTYWAIT;
  1472. tty_wakeup(tty);
  1473. wake_up_interruptible(&tty->write_wait);
  1474. } /* End if EMPTYWAIT */
  1475. } /* End EMPTYTX_IND */
  1476. } /* End if valid tty */
  1477. next:
  1478. globalwinon(ch);
  1479. BUG_ON(!bc);
  1480. writew(1, &bc->idata);
  1481. writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
  1482. globalwinon(chan0);
  1483. } /* End while something in event queue */
  1484. } /* End doevent */
  1485. /* --------------------- Begin fepcmd ------------------------ */
  1486. static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
  1487. int byte2, int ncmds, int bytecmd)
  1488. { /* Begin fepcmd */
  1489. unchar __iomem *memaddr;
  1490. unsigned int head, cmdTail, cmdStart, cmdMax;
  1491. long count;
  1492. int n;
  1493. /* This is the routine in which commands may be passed to the card. */
  1494. if (ch->board->status == DISABLED)
  1495. return;
  1496. assertgwinon(ch);
  1497. /* Remember head (As well as max) is just an offset not a base addr */
  1498. head = readw(&ch->mailbox->cin);
  1499. /* cmdStart is a base address */
  1500. cmdStart = readw(&ch->mailbox->cstart);
  1501. /* ------------------------------------------------------------------
  1502. We do the addition below because we do not want a max pointer
  1503. relative to cmdStart. We want a max pointer that points at the
  1504. physical end of the command queue.
  1505. -------------------------------------------------------------------- */
  1506. cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
  1507. memaddr = ch->board->re_map_membase;
  1508. if (head >= (cmdMax - cmdStart) || (head & 03)) {
  1509. printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n", __LINE__, cmd, head);
  1510. printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n", __LINE__, cmdMax, cmdStart);
  1511. return;
  1512. }
  1513. if (bytecmd) {
  1514. writeb(cmd, memaddr + head + cmdStart + 0);
  1515. writeb(ch->channelnum, memaddr + head + cmdStart + 1);
  1516. /* Below word_or_byte is bits to set */
  1517. writeb(word_or_byte, memaddr + head + cmdStart + 2);
  1518. /* Below byte2 is bits to reset */
  1519. writeb(byte2, memaddr + head + cmdStart + 3);
  1520. } else {
  1521. writeb(cmd, memaddr + head + cmdStart + 0);
  1522. writeb(ch->channelnum, memaddr + head + cmdStart + 1);
  1523. writeb(word_or_byte, memaddr + head + cmdStart + 2);
  1524. }
  1525. head = (head + 4) & (cmdMax - cmdStart - 4);
  1526. writew(head, &ch->mailbox->cin);
  1527. count = FEPTIMEOUT;
  1528. for (;;) { /* Begin forever loop */
  1529. count--;
  1530. if (count == 0) {
  1531. printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
  1532. return;
  1533. }
  1534. head = readw(&ch->mailbox->cin);
  1535. cmdTail = readw(&ch->mailbox->cout);
  1536. n = (head - cmdTail) & (cmdMax - cmdStart - 4);
  1537. /* ----------------------------------------------------------
  1538. Basically this will break when the FEP acknowledges the
  1539. command by incrementing cmdTail (Making it equal to head).
  1540. ------------------------------------------------------------- */
  1541. if (n <= ncmds * (sizeof(short) * 4))
  1542. break; /* Well nearly forever :-) */
  1543. } /* End forever loop */
  1544. } /* End fepcmd */
  1545. /* ---------------------------------------------------------------------
  1546. Digi products use fields in their channels structures that are very
  1547. similar to the c_cflag and c_iflag fields typically found in UNIX
  1548. termios structures. The below three routines allow mappings
  1549. between these hardware "flags" and their respective Linux flags.
  1550. ------------------------------------------------------------------------- */
  1551. /* --------------------- Begin termios2digi_h -------------------- */
  1552. static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
  1553. { /* Begin termios2digi_h */
  1554. unsigned res = 0;
  1555. if (cflag & CRTSCTS) {
  1556. ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
  1557. res |= ((ch->m_cts) | (ch->m_rts));
  1558. }
  1559. if (ch->digiext.digi_flags & RTSPACE)
  1560. res |= ch->m_rts;
  1561. if (ch->digiext.digi_flags & DTRPACE)
  1562. res |= ch->m_dtr;
  1563. if (ch->digiext.digi_flags & CTSPACE)
  1564. res |= ch->m_cts;
  1565. if (ch->digiext.digi_flags & DSRPACE)
  1566. res |= ch->dsr;
  1567. if (ch->digiext.digi_flags & DCDPACE)
  1568. res |= ch->dcd;
  1569. if (res & (ch->m_rts))
  1570. ch->digiext.digi_flags |= RTSPACE;
  1571. if (res & (ch->m_cts))
  1572. ch->digiext.digi_flags |= CTSPACE;
  1573. return res;
  1574. } /* End termios2digi_h */
  1575. /* --------------------- Begin termios2digi_i -------------------- */
  1576. static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
  1577. { /* Begin termios2digi_i */
  1578. unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
  1579. INPCK | ISTRIP|IXON|IXANY|IXOFF);
  1580. if (ch->digiext.digi_flags & DIGI_AIXON)
  1581. res |= IAIXON;
  1582. return res;
  1583. } /* End termios2digi_i */
  1584. /* --------------------- Begin termios2digi_c -------------------- */
  1585. static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
  1586. { /* Begin termios2digi_c */
  1587. unsigned res = 0;
  1588. if (cflag & CBAUDEX) { /* Begin detected CBAUDEX */
  1589. ch->digiext.digi_flags |= DIGI_FAST;
  1590. /* -------------------------------------------------------------
  1591. HUPCL bit is used by FEP to indicate fast baud
  1592. table is to be used.
  1593. ----------------------------------------------------------------- */
  1594. res |= FEP_HUPCL;
  1595. } /* End detected CBAUDEX */
  1596. else ch->digiext.digi_flags &= ~DIGI_FAST;
  1597. /* -------------------------------------------------------------------
  1598. CBAUD has bit position 0x1000 set these days to indicate Linux
  1599. baud rate remap. Digi hardware can't handle the bit assignment.
  1600. (We use a different bit assignment for high speed.). Clear this
  1601. bit out.
  1602. ---------------------------------------------------------------------- */
  1603. res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
  1604. /* -------------------------------------------------------------
  1605. This gets a little confusing. The Digi cards have their own
  1606. representation of c_cflags controling baud rate. For the most
  1607. part this is identical to the Linux implementation. However;
  1608. Digi supports one rate (76800) that Linux doesn't. This means
  1609. that the c_cflag entry that would normally mean 76800 for Digi
  1610. actually means 115200 under Linux. Without the below mapping,
  1611. a stty 115200 would only drive the board at 76800. Since
  1612. the rate 230400 is also found after 76800, the same problem afflicts
  1613. us when we choose a rate of 230400. Without the below modificiation
  1614. stty 230400 would actually give us 115200.
  1615. There are two additional differences. The Linux value for CLOCAL
  1616. (0x800; 0004000) has no meaning to the Digi hardware. Also in
  1617. later releases of Linux; the CBAUD define has CBAUDEX (0x1000;
  1618. 0010000) ored into it (CBAUD = 0x100f as opposed to 0xf). CBAUDEX
  1619. should be checked for a screened out prior to termios2digi_c
  1620. returning. Since CLOCAL isn't used by the board this can be
  1621. ignored as long as the returned value is used only by Digi hardware.
  1622. ----------------------------------------------------------------- */
  1623. if (cflag & CBAUDEX) {
  1624. /* -------------------------------------------------------------
  1625. The below code is trying to guarantee that only baud rates
  1626. 115200 and 230400 are remapped. We use exclusive or because
  1627. the various baud rates share common bit positions and therefore
  1628. can't be tested for easily.
  1629. ----------------------------------------------------------------- */
  1630. if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
  1631. (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
  1632. res += 1;
  1633. }
  1634. return res;
  1635. } /* End termios2digi_c */
  1636. /* --------------------- Begin epcaparam ----------------------- */
  1637. /* Caller must hold the locks */
  1638. static void epcaparam(struct tty_struct *tty, struct channel *ch)
  1639. { /* Begin epcaparam */
  1640. unsigned int cmdHead;
  1641. struct termios *ts;
  1642. struct board_chan __iomem *bc;
  1643. unsigned mval, hflow, cflag, iflag;
  1644. bc = ch->brdchan;
  1645. epcaassert(bc !=0, "bc out of range");
  1646. assertgwinon(ch);
  1647. ts = tty->termios;
  1648. if ((ts->c_cflag & CBAUD) == 0) { /* Begin CBAUD detected */
  1649. cmdHead = readw(&bc->rin);
  1650. writew(cmdHead, &bc->rout);
  1651. cmdHead = readw(&bc->tin);
  1652. /* Changing baud in mid-stream transmission can be wonderful */
  1653. /* ---------------------------------------------------------------
  1654. Flush current transmit buffer by setting cmdTail pointer (tout)
  1655. to cmdHead pointer (tin). Hopefully the transmit buffer is empty.
  1656. ----------------------------------------------------------------- */
  1657. fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
  1658. mval = 0;
  1659. } else { /* Begin CBAUD not detected */
  1660. /* -------------------------------------------------------------------
  1661. c_cflags have changed but that change had nothing to do with BAUD.
  1662. Propagate the change to the card.
  1663. ---------------------------------------------------------------------- */
  1664. cflag = termios2digi_c(ch, ts->c_cflag);
  1665. if (cflag != ch->fepcflag) {
  1666. ch->fepcflag = cflag;
  1667. /* Set baud rate, char size, stop bits, parity */
  1668. fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
  1669. }
  1670. /* ----------------------------------------------------------------
  1671. If the user has not forced CLOCAL and if the device is not a
  1672. CALLOUT device (Which is always CLOCAL) we set flags such that
  1673. the driver will wait on carrier detect.
  1674. ------------------------------------------------------------------- */
  1675. if (ts->c_cflag & CLOCAL)
  1676. ch->asyncflags &= ~ASYNC_CHECK_CD;
  1677. else
  1678. ch->asyncflags |= ASYNC_CHECK_CD;
  1679. mval = ch->m_dtr | ch->m_rts;
  1680. } /* End CBAUD not detected */
  1681. iflag = termios2digi_i(ch, ts->c_iflag);
  1682. /* Check input mode flags */
  1683. if (iflag != ch->fepiflag) {
  1684. ch->fepiflag = iflag;
  1685. /* ---------------------------------------------------------------
  1686. Command sets channels iflag structure on the board. Such things
  1687. as input soft flow control, handling of parity errors, and
  1688. break handling are all set here.
  1689. ------------------------------------------------------------------- */
  1690. /* break handling, parity handling, input stripping, flow control chars */
  1691. fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
  1692. }
  1693. /* ---------------------------------------------------------------
  1694. Set the board mint value for this channel. This will cause hardware
  1695. events to be generated each time the DCD signal (Described in mint)
  1696. changes.
  1697. ------------------------------------------------------------------- */
  1698. writeb(ch->dcd, &bc->mint);
  1699. if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
  1700. if (ch->digiext.digi_flags & DIGI_FORCEDCD)
  1701. writeb(0, &bc->mint);
  1702. ch->imodem = readb(&bc->mstat);
  1703. hflow = termios2digi_h(ch, ts->c_cflag);
  1704. if (hflow != ch->hflow) {
  1705. ch->hflow = hflow;
  1706. /* --------------------------------------------------------------
  1707. Hard flow control has been selected but the board is not
  1708. using it. Activate hard flow control now.
  1709. ----------------------------------------------------------------- */
  1710. fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
  1711. }
  1712. mval ^= ch->modemfake & (mval ^ ch->modem);
  1713. if (ch->omodem ^ mval) {
  1714. ch->omodem = mval;
  1715. /* --------------------------------------------------------------
  1716. The below command sets the DTR and RTS mstat structure. If
  1717. hard flow control is NOT active these changes will drive the
  1718. output of the actual DTR and RTS lines. If hard flow control
  1719. is active, the changes will be saved in the mstat structure and
  1720. only asserted when hard flow control is turned off.
  1721. ----------------------------------------------------------------- */
  1722. /* First reset DTR & RTS; then set them */
  1723. fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
  1724. fepcmd(ch, SETMODEM, mval, 0, 0, 1);
  1725. }
  1726. if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
  1727. ch->fepstartc = ch->startc;
  1728. ch->fepstopc = ch->stopc;
  1729. /* ------------------------------------------------------------
  1730. The XON / XOFF characters have changed; propagate these
  1731. changes to the card.
  1732. --------------------------------------------------------------- */
  1733. fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
  1734. }
  1735. if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
  1736. ch->fepstartca = ch->startca;
  1737. ch->fepstopca = ch->stopca;
  1738. /* ---------------------------------------------------------------
  1739. Similar to the above, this time the auxilarly XON / XOFF
  1740. characters have changed; propagate these changes to the card.
  1741. ------------------------------------------------------------------ */
  1742. fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
  1743. }
  1744. } /* End epcaparam */
  1745. /* --------------------- Begin receive_data ----------------------- */
  1746. /* Caller holds lock */
  1747. static void receive_data(struct channel *ch)
  1748. { /* Begin receive_data */
  1749. unchar *rptr;
  1750. struct termios *ts = NULL;
  1751. struct tty_struct *tty;
  1752. struct board_chan __iomem *bc;
  1753. int dataToRead, wrapgap, bytesAvailable;
  1754. unsigned int tail, head;
  1755. unsigned int wrapmask;
  1756. /* ---------------------------------------------------------------
  1757. This routine is called by doint when a receive data event
  1758. has taken place.
  1759. ------------------------------------------------------------------- */
  1760. globalwinon(ch);
  1761. if (ch->statusflags & RXSTOPPED)
  1762. return;
  1763. tty = ch->tty;
  1764. if (tty)
  1765. ts = tty->termios;
  1766. bc = ch->brdchan;
  1767. BUG_ON(!bc);
  1768. wrapmask = ch->rxbufsize - 1;
  1769. /* ---------------------------------------------------------------------
  1770. Get the head and tail pointers to the receiver queue. Wrap the
  1771. head pointer if it has reached the end of the buffer.
  1772. ------------------------------------------------------------------------ */
  1773. head = readw(&bc->rin);
  1774. head &= wrapmask;
  1775. tail = readw(&bc->rout) & wrapmask;
  1776. bytesAvailable = (head - tail) & wrapmask;
  1777. if (bytesAvailable == 0)
  1778. return;
  1779. /* ------------------------------------------------------------------
  1780. If CREAD bit is off or device not open, set TX tail to head
  1781. --------------------------------------------------------------------- */
  1782. if (!tty || !ts || !(ts->c_cflag & CREAD)) {
  1783. writew(head, &bc->rout);
  1784. return;
  1785. }
  1786. if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
  1787. return;
  1788. if (readb(&bc->orun)) {
  1789. writeb(0, &bc->orun);
  1790. printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",tty->name);
  1791. tty_insert_flip_char(tty, 0, TTY_OVERRUN);
  1792. }
  1793. rxwinon(ch);
  1794. while (bytesAvailable > 0) { /* Begin while there is data on the card */
  1795. wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
  1796. /* ---------------------------------------------------------------
  1797. Even if head has wrapped around only report the amount of
  1798. data to be equal to the size - tail. Remember memcpy can't
  1799. automaticly wrap around the receive buffer.
  1800. ----------------------------------------------------------------- */
  1801. dataToRead = (wrapgap < bytesAvailable) ? wrapgap : bytesAvailable;
  1802. /* --------------------------------------------------------------
  1803. Make sure we don't overflow the buffer
  1804. ----------------------------------------------------------------- */
  1805. dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
  1806. if (dataToRead == 0)
  1807. break;
  1808. /* ---------------------------------------------------------------
  1809. Move data read from our card into the line disciplines buffer
  1810. for translation if necessary.
  1811. ------------------------------------------------------------------ */
  1812. memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
  1813. tail = (tail + dataToRead) & wrapmask;
  1814. bytesAvailable -= dataToRead;
  1815. } /* End while there is data on the card */
  1816. globalwinon(ch);
  1817. writew(tail, &bc->rout);
  1818. /* Must be called with global data */
  1819. tty_schedule_flip(ch->tty);
  1820. return;
  1821. } /* End receive_data */
  1822. static int info_ioctl(struct tty_struct *tty, struct file * file,
  1823. unsigned int cmd, unsigned long arg)
  1824. {
  1825. switch (cmd)
  1826. { /* Begin switch cmd */
  1827. case DIGI_GETINFO:
  1828. { /* Begin case DIGI_GETINFO */
  1829. struct digi_info di ;
  1830. int brd;
  1831. if(get_user(brd, (unsigned int __user *)arg))
  1832. return -EFAULT;
  1833. if (brd < 0 || brd >= num_cards || num_cards == 0)
  1834. return -ENODEV;
  1835. memset(&di, 0, sizeof(di));
  1836. di.board = brd ;
  1837. di.status = boards[brd].status;
  1838. di.type = boards[brd].type ;
  1839. di.numports = boards[brd].numports ;
  1840. /* Legacy fixups - just move along nothing to see */
  1841. di.port = (unsigned char *)boards[brd].port ;
  1842. di.membase = (unsigned char *)boards[brd].membase ;
  1843. if (copy_to_user((void __user *)arg, &di, sizeof (di)))
  1844. return -EFAULT;
  1845. break;
  1846. } /* End case DIGI_GETINFO */
  1847. case DIGI_POLLER:
  1848. { /* Begin case DIGI_POLLER */
  1849. int brd = arg & 0xff000000 >> 16 ;
  1850. unsigned char state = arg & 0xff ;
  1851. if (brd < 0 || brd >= num_cards) {
  1852. printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
  1853. return (-ENODEV);
  1854. }
  1855. digi_poller_inhibited = state ;
  1856. break ;
  1857. } /* End case DIGI_POLLER */
  1858. case DIGI_INIT:
  1859. { /* Begin case DIGI_INIT */
  1860. /* ------------------------------------------------------------
  1861. This call is made by the apps to complete the initilization
  1862. of the board(s). This routine is responsible for setting
  1863. the card to its initial state and setting the drivers control
  1864. fields to the sutianle settings for the card in question.
  1865. ---------------------------------------------------------------- */
  1866. int crd ;
  1867. for (crd = 0; crd < num_cards; crd++)
  1868. post_fep_init (crd);
  1869. break ;
  1870. } /* End case DIGI_INIT */
  1871. default:
  1872. return -ENOTTY;
  1873. } /* End switch cmd */
  1874. return (0) ;
  1875. }
  1876. /* --------------------- Begin pc_ioctl ----------------------- */
  1877. static int pc_tiocmget(struct tty_struct *tty, struct file *file)
  1878. {
  1879. struct channel *ch = (struct channel *) tty->driver_data;
  1880. struct board_chan __iomem *bc;
  1881. unsigned int mstat, mflag = 0;
  1882. unsigned long flags;
  1883. if (ch)
  1884. bc = ch->brdchan;
  1885. else
  1886. return -EINVAL;
  1887. spin_lock_irqsave(&epca_lock, flags);
  1888. globalwinon(ch);
  1889. mstat = readb(&bc->mstat);
  1890. memoff(ch);
  1891. spin_unlock_irqrestore(&epca_lock, flags);
  1892. if (mstat & ch->m_dtr)
  1893. mflag |= TIOCM_DTR;
  1894. if (mstat & ch->m_rts)
  1895. mflag |= TIOCM_RTS;
  1896. if (mstat & ch->m_cts)
  1897. mflag |= TIOCM_CTS;
  1898. if (mstat & ch->dsr)
  1899. mflag |= TIOCM_DSR;
  1900. if (mstat & ch->m_ri)
  1901. mflag |= TIOCM_RI;
  1902. if (mstat & ch->dcd)
  1903. mflag |= TIOCM_CD;
  1904. return mflag;
  1905. }
  1906. static int pc_tiocmset(struct tty_struct *tty, struct file *file,
  1907. unsigned int set, unsigned int clear)
  1908. {
  1909. struct channel *ch = (struct channel *) tty->driver_data;
  1910. unsigned long flags;
  1911. if (!ch)
  1912. return -EINVAL;
  1913. spin_lock_irqsave(&epca_lock, flags);
  1914. /*
  1915. * I think this modemfake stuff is broken. It doesn't
  1916. * correctly reflect the behaviour desired by the TIOCM*
  1917. * ioctls. Therefore this is probably broken.
  1918. */
  1919. if (set & TIOCM_RTS) {
  1920. ch->modemfake |= ch->m_rts;
  1921. ch->modem |= ch->m_rts;
  1922. }
  1923. if (set & TIOCM_DTR) {
  1924. ch->modemfake |= ch->m_dtr;
  1925. ch->modem |= ch->m_dtr;
  1926. }
  1927. if (clear & TIOCM_RTS) {
  1928. ch->modemfake |= ch->m_rts;
  1929. ch->modem &= ~ch->m_rts;
  1930. }
  1931. if (clear & TIOCM_DTR) {
  1932. ch->modemfake |= ch->m_dtr;
  1933. ch->modem &= ~ch->m_dtr;
  1934. }
  1935. globalwinon(ch);
  1936. /* --------------------------------------------------------------
  1937. The below routine generally sets up parity, baud, flow control
  1938. issues, etc.... It effect both control flags and input flags.
  1939. ------------------------------------------------------------------ */
  1940. epcaparam(tty,ch);
  1941. memoff(ch);
  1942. spin_unlock_irqrestore(&epca_lock, flags);
  1943. return 0;
  1944. }
  1945. static int pc_ioctl(struct tty_struct *tty, struct file * file,
  1946. unsigned int cmd, unsigned long arg)
  1947. { /* Begin pc_ioctl */
  1948. digiflow_t dflow;
  1949. int retval;
  1950. unsigned long flags;
  1951. unsigned int mflag, mstat;
  1952. unsigned char startc, stopc;
  1953. struct board_chan __iomem *bc;
  1954. struct channel *ch = (struct channel *) tty->driver_data;
  1955. void __user *argp = (void __user *)arg;
  1956. if (ch)
  1957. bc = ch->brdchan;
  1958. else
  1959. return -EINVAL;
  1960. /* -------------------------------------------------------------------
  1961. For POSIX compliance we need to add more ioctls. See tty_ioctl.c
  1962. in /usr/src/linux/drivers/char for a good example. In particular
  1963. think about adding TCSETAF, TCSETAW, TCSETA, TCSETSF, TCSETSW, TCSETS.
  1964. ---------------------------------------------------------------------- */
  1965. switch (cmd)
  1966. { /* Begin switch cmd */
  1967. case TCGETS:
  1968. if (copy_to_user(argp, tty->termios, sizeof(struct termios)))
  1969. return -EFAULT;
  1970. return 0;
  1971. case TCGETA:
  1972. return get_termio(tty, argp);
  1973. case TCSBRK: /* SVID version: non-zero arg --> no break */
  1974. retval = tty_check_change(tty);
  1975. if (retval)
  1976. return retval;
  1977. /* Setup an event to indicate when the transmit buffer empties */
  1978. spin_lock_irqsave(&epca_lock, flags);
  1979. setup_empty_event(tty,ch);
  1980. spin_unlock_irqrestore(&epca_lock, flags);
  1981. tty_wait_until_sent(tty, 0);
  1982. if (!arg)
  1983. digi_send_break(ch, HZ/4); /* 1/4 second */
  1984. return 0;
  1985. case TCSBRKP: /* support for POSIX tcsendbreak() */
  1986. retval = tty_check_change(tty);
  1987. if (retval)
  1988. return retval;
  1989. /* Setup an event to indicate when the transmit buffer empties */
  1990. spin_lock_irqsave(&epca_lock, flags);
  1991. setup_empty_event(tty,ch);
  1992. spin_unlock_irqrestore(&epca_lock, flags);
  1993. tty_wait_until_sent(tty, 0);
  1994. digi_send_break(ch, arg ? arg*(HZ/10) : HZ/4);
  1995. return 0;
  1996. case TIOCGSOFTCAR:
  1997. if (put_user(C_CLOCAL(tty)?1:0, (unsigned long __user *)arg))
  1998. return -EFAULT;
  1999. return 0;
  2000. case TIOCSSOFTCAR:
  2001. {
  2002. unsigned int value;
  2003. if (get_user(value, (unsigned __user *)argp))
  2004. return -EFAULT;
  2005. tty->termios->c_cflag =
  2006. ((tty->termios->c_cflag & ~CLOCAL) |
  2007. (value ? CLOCAL : 0));
  2008. return 0;
  2009. }
  2010. case TIOCMODG:
  2011. mflag = pc_tiocmget(tty, file);
  2012. if (put_user(mflag, (unsigned long __user *)argp))
  2013. return -EFAULT;
  2014. break;
  2015. case TIOCMODS:
  2016. if (get_user(mstat, (unsigned __user *)argp))
  2017. return -EFAULT;
  2018. return pc_tiocmset(tty, file, mstat, ~mstat);
  2019. case TIOCSDTR:
  2020. spin_lock_irqsave(&epca_lock, flags);
  2021. ch->omodem |= ch->m_dtr;
  2022. globalwinon(ch);
  2023. fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
  2024. memoff(ch);
  2025. spin_unlock_irqrestore(&epca_lock, flags);
  2026. break;
  2027. case TIOCCDTR:
  2028. spin_lock_irqsave(&epca_lock, flags);
  2029. ch->omodem &= ~ch->m_dtr;
  2030. globalwinon(ch);
  2031. fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
  2032. memoff(ch);
  2033. spin_unlock_irqrestore(&epca_lock, flags);
  2034. break;
  2035. case DIGI_GETA:
  2036. if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
  2037. return -EFAULT;
  2038. break;
  2039. case DIGI_SETAW:
  2040. case DIGI_SETAF:
  2041. if (cmd == DIGI_SETAW) {
  2042. /* Setup an event to indicate when the transmit buffer empties */
  2043. spin_lock_irqsave(&epca_lock, flags);
  2044. setup_empty_event(tty,ch);
  2045. spin_unlock_irqrestore(&epca_lock, flags);
  2046. tty_wait_until_sent(tty, 0);
  2047. } else {
  2048. /* ldisc lock already held in ioctl */
  2049. if (tty->ldisc.flush_buffer)
  2050. tty->ldisc.flush_buffer(tty);
  2051. }
  2052. /* Fall Thru */
  2053. case DIGI_SETA:
  2054. if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
  2055. return -EFAULT;
  2056. if (ch->digiext.digi_flags & DIGI_ALTPIN) {
  2057. ch->dcd = ch->m_dsr;
  2058. ch->dsr = ch->m_dcd;
  2059. } else {
  2060. ch->dcd = ch->m_dcd;
  2061. ch->dsr = ch->m_dsr;
  2062. }
  2063. spin_lock_irqsave(&epca_lock, flags);
  2064. globalwinon(ch);
  2065. /* -----------------------------------------------------------------
  2066. The below routine generally sets up parity, baud, flow control
  2067. issues, etc.... It effect both control flags and input flags.
  2068. ------------------------------------------------------------------- */
  2069. epcaparam(tty,ch);
  2070. memoff(ch);
  2071. spin_unlock_irqrestore(&epca_lock, flags);
  2072. break;
  2073. case DIGI_GETFLOW:
  2074. case DIGI_GETAFLOW:
  2075. spin_lock_irqsave(&epca_lock, flags);
  2076. globalwinon(ch);
  2077. if (cmd == DIGI_GETFLOW) {
  2078. dflow.startc = readb(&bc->startc);
  2079. dflow.stopc = readb(&bc->stopc);
  2080. } else {
  2081. dflow.startc = readb(&bc->startca);
  2082. dflow.stopc = readb(&bc->stopca);
  2083. }
  2084. memoff(ch);
  2085. spin_unlock_irqrestore(&epca_lock, flags);
  2086. if (copy_to_user(argp, &dflow, sizeof(dflow)))
  2087. return -EFAULT;
  2088. break;
  2089. case DIGI_SETAFLOW:
  2090. case DIGI_SETFLOW:
  2091. if (cmd == DIGI_SETFLOW) {
  2092. startc = ch->startc;
  2093. stopc = ch->stopc;
  2094. } else {
  2095. startc = ch->startca;
  2096. stopc = ch->stopca;
  2097. }
  2098. if (copy_from_user(&dflow, argp, sizeof(dflow)))
  2099. return -EFAULT;
  2100. if (dflow.startc != startc || dflow.stopc != stopc) { /* Begin if setflow toggled */
  2101. spin_lock_irqsave(&epca_lock, flags);
  2102. globalwinon(ch);
  2103. if (cmd == DIGI_SETFLOW) {
  2104. ch->fepstartc = ch->startc = dflow.startc;
  2105. ch->fepstopc = ch->stopc = dflow.stopc;
  2106. fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
  2107. } else {
  2108. ch->fepstartca = ch->startca = dflow.startc;
  2109. ch->fepstopca = ch->stopca = dflow.stopc;
  2110. fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
  2111. }
  2112. if (ch->statusflags & TXSTOPPED)
  2113. pc_start(tty);
  2114. memoff(ch);
  2115. spin_unlock_irqrestore(&epca_lock, flags);
  2116. } /* End if setflow toggled */
  2117. break;
  2118. default:
  2119. return -ENOIOCTLCMD;
  2120. } /* End switch cmd */
  2121. return 0;
  2122. } /* End pc_ioctl */
  2123. /* --------------------- Begin pc_set_termios ----------------------- */
  2124. static void pc_set_termios(struct tty_struct *tty, struct termios *old_termios)
  2125. { /* Begin pc_set_termios */
  2126. struct channel *ch;
  2127. unsigned long flags;
  2128. /* ---------------------------------------------------------
  2129. verifyChannel returns the channel from the tty struct
  2130. if it is valid. This serves as a sanity check.
  2131. ------------------------------------------------------------- */
  2132. if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
  2133. spin_lock_irqsave(&epca_lock, flags);
  2134. globalwinon(ch);
  2135. epcaparam(tty, ch);
  2136. memoff(ch);
  2137. spin_unlock_irqrestore(&epca_lock, flags);
  2138. if ((old_termios->c_cflag & CRTSCTS) &&
  2139. ((tty->termios->c_cflag & CRTSCTS) == 0))
  2140. tty->hw_stopped = 0;
  2141. if (!(old_termios->c_cflag & CLOCAL) &&
  2142. (tty->termios->c_cflag & CLOCAL))
  2143. wake_up_interruptible(&ch->open_wait);
  2144. } /* End if channel valid */
  2145. } /* End pc_set_termios */
  2146. /* --------------------- Begin do_softint ----------------------- */
  2147. static void do_softint(void *private_)
  2148. { /* Begin do_softint */
  2149. struct channel *ch = (struct channel *) private_;
  2150. /* Called in response to a modem change event */
  2151. if (ch && ch->magic == EPCA_MAGIC) { /* Begin EPCA_MAGIC */
  2152. struct tty_struct *tty = ch->tty;
  2153. if (tty && tty->driver_data) {
  2154. if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) { /* Begin if clear_bit */
  2155. tty_hangup(tty); /* FIXME: module removal race here - AKPM */
  2156. wake_up_interruptible(&ch->open_wait);
  2157. ch->asyncflags &= ~ASYNC_NORMAL_ACTIVE;
  2158. } /* End if clear_bit */
  2159. }
  2160. } /* End EPCA_MAGIC */
  2161. } /* End do_softint */
  2162. /* ------------------------------------------------------------
  2163. pc_stop and pc_start provide software flow control to the
  2164. routine and the pc_ioctl routine.
  2165. ---------------------------------------------------------------- */
  2166. /* --------------------- Begin pc_stop ----------------------- */
  2167. static void pc_stop(struct tty_struct *tty)
  2168. { /* Begin pc_stop */
  2169. struct channel *ch;
  2170. unsigned long flags;
  2171. /* ---------------------------------------------------------
  2172. verifyChannel returns the channel from the tty struct
  2173. if it is valid. This serves as a sanity check.
  2174. ------------------------------------------------------------- */
  2175. if ((ch = verifyChannel(tty)) != NULL) { /* Begin if valid channel */
  2176. spin_lock_irqsave(&epca_lock, flags);
  2177. if ((ch->statusflags & TXSTOPPED) == 0) { /* Begin if transmit stop requested */
  2178. globalwinon(ch);
  2179. /* STOP transmitting now !! */
  2180. fepcmd(ch, PAUSETX, 0, 0, 0, 0);
  2181. ch->statusflags |= TXSTOPPED;
  2182. memoff(ch);
  2183. } /* End if transmit stop requested */
  2184. spin_unlock_irqrestore(&epca_lock, flags);
  2185. } /* End if valid channel */
  2186. } /* End pc_stop */
  2187. /* --------------------- Begin pc_start ----------------------- */
  2188. static void pc_start(struct tty_struct *tty)
  2189. { /* Begin pc_start */
  2190. struct channel *ch;
  2191. /* ---------------------------------------------------------
  2192. verifyChannel returns the channel from the tty struct
  2193. if it is valid. This serves as a sanity check.
  2194. ------------------------------------------------------------- */
  2195. if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
  2196. unsigned long flags;
  2197. spin_lock_irqsave(&epca_lock, flags);
  2198. /* Just in case output was resumed because of a change in Digi-flow */
  2199. if (ch->statusflags & TXSTOPPED) { /* Begin transmit resume requested */
  2200. struct board_chan __iomem *bc;
  2201. globalwinon(ch);
  2202. bc = ch->brdchan;
  2203. if (ch->statusflags & LOWWAIT)
  2204. writeb(1, &bc->ilow);
  2205. /* Okay, you can start transmitting again... */
  2206. fepcmd(ch, RESUMETX, 0, 0, 0, 0);
  2207. ch->statusflags &= ~TXSTOPPED;
  2208. memoff(ch);
  2209. } /* End transmit resume requested */
  2210. spin_unlock_irqrestore(&epca_lock, flags);
  2211. } /* End if channel valid */
  2212. } /* End pc_start */
  2213. /* ------------------------------------------------------------------
  2214. The below routines pc_throttle and pc_unthrottle are used
  2215. to slow (And resume) the receipt of data into the kernels
  2216. receive buffers. The exact occurrence of this depends on the
  2217. size of the kernels receive buffer and what the 'watermarks'
  2218. are set to for that buffer. See the n_ttys.c file for more
  2219. details.
  2220. ______________________________________________________________________ */
  2221. /* --------------------- Begin throttle ----------------------- */
  2222. static void pc_throttle(struct tty_struct * tty)
  2223. { /* Begin pc_throttle */
  2224. struct channel *ch;
  2225. unsigned long flags;
  2226. /* ---------------------------------------------------------
  2227. verifyChannel returns the channel from the tty struct
  2228. if it is valid. This serves as a sanity check.
  2229. ------------------------------------------------------------- */
  2230. if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
  2231. spin_lock_irqsave(&epca_lock, flags);
  2232. if ((ch->statusflags & RXSTOPPED) == 0) {
  2233. globalwinon(ch);
  2234. fepcmd(ch, PAUSERX, 0, 0, 0, 0);
  2235. ch->statusflags |= RXSTOPPED;
  2236. memoff(ch);
  2237. }
  2238. spin_unlock_irqrestore(&epca_lock, flags);
  2239. } /* End if channel valid */
  2240. } /* End pc_throttle */
  2241. /* --------------------- Begin unthrottle ----------------------- */
  2242. static void pc_unthrottle(struct tty_struct *tty)
  2243. { /* Begin pc_unthrottle */
  2244. struct channel *ch;
  2245. unsigned long flags;
  2246. /* ---------------------------------------------------------
  2247. verifyChannel returns the channel from the tty struct
  2248. if it is valid. This serves as a sanity check.
  2249. ------------------------------------------------------------- */
  2250. if ((ch = verifyChannel(tty)) != NULL) { /* Begin if channel valid */
  2251. /* Just in case output was resumed because of a change in Digi-flow */
  2252. spin_lock_irqsave(&epca_lock, flags);
  2253. if (ch->statusflags & RXSTOPPED) {
  2254. globalwinon(ch);
  2255. fepcmd(ch, RESUMERX, 0, 0, 0, 0);
  2256. ch->statusflags &= ~RXSTOPPED;
  2257. memoff(ch);
  2258. }
  2259. spin_unlock_irqrestore(&epca_lock, flags);
  2260. } /* End if channel valid */
  2261. } /* End pc_unthrottle */
  2262. /* --------------------- Begin digi_send_break ----------------------- */
  2263. void digi_send_break(struct channel *ch, int msec)
  2264. { /* Begin digi_send_break */
  2265. unsigned long flags;
  2266. spin_lock_irqsave(&epca_lock, flags);
  2267. globalwinon(ch);
  2268. /* --------------------------------------------------------------------
  2269. Maybe I should send an infinite break here, schedule() for
  2270. msec amount of time, and then stop the break. This way,
  2271. the user can't screw up the FEP by causing digi_send_break()
  2272. to be called (i.e. via an ioctl()) more than once in msec amount
  2273. of time. Try this for now...
  2274. ------------------------------------------------------------------------ */
  2275. fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
  2276. memoff(ch);
  2277. spin_unlock_irqrestore(&epca_lock, flags);
  2278. } /* End digi_send_break */
  2279. /* --------------------- Begin setup_empty_event ----------------------- */
  2280. /* Caller MUST hold the lock */
  2281. static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
  2282. { /* Begin setup_empty_event */
  2283. struct board_chan __iomem *bc = ch->brdchan;
  2284. globalwinon(ch);
  2285. ch->statusflags |= EMPTYWAIT;
  2286. /* ------------------------------------------------------------------
  2287. When set the iempty flag request a event to be generated when the
  2288. transmit buffer is empty (If there is no BREAK in progress).
  2289. --------------------------------------------------------------------- */
  2290. writeb(1, &bc->iempty);
  2291. memoff(ch);
  2292. } /* End setup_empty_event */
  2293. /* --------------------- Begin get_termio ----------------------- */
  2294. static int get_termio(struct tty_struct * tty, struct termio __user * termio)
  2295. { /* Begin get_termio */
  2296. return kernel_termios_to_user_termio(termio, tty->termios);
  2297. } /* End get_termio */
  2298. /* ---------------------- Begin epca_setup -------------------------- */
  2299. void epca_setup(char *str, int *ints)
  2300. { /* Begin epca_setup */
  2301. struct board_info board;
  2302. int index, loop, last;
  2303. char *temp, *t2;
  2304. unsigned len;
  2305. /* ----------------------------------------------------------------------
  2306. If this routine looks a little strange it is because it is only called
  2307. if a LILO append command is given to boot the kernel with parameters.
  2308. In this way, we can provide the user a method of changing his board
  2309. configuration without rebuilding the kernel.
  2310. ----------------------------------------------------------------------- */
  2311. if (!liloconfig)
  2312. liloconfig = 1;
  2313. memset(&board, 0, sizeof(board));
  2314. /* Assume the data is int first, later we can change it */
  2315. /* I think that array position 0 of ints holds the number of args */
  2316. for (last = 0, index = 1; index <= ints[0]; index++)
  2317. switch(index)
  2318. { /* Begin parse switch */
  2319. case 1:
  2320. board.status = ints[index];
  2321. /* ---------------------------------------------------------
  2322. We check for 2 (As opposed to 1; because 2 is a flag
  2323. instructing the driver to ignore epcaconfig.) For this
  2324. reason we check for 2.
  2325. ------------------------------------------------------------ */
  2326. if (board.status == 2) { /* Begin ignore epcaconfig as well as lilo cmd line */
  2327. nbdevs = 0;
  2328. num_cards = 0;
  2329. return;
  2330. } /* End ignore epcaconfig as well as lilo cmd line */
  2331. if (board.status > 2) {
  2332. printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n", board.status);
  2333. invalid_lilo_config = 1;
  2334. setup_error_code |= INVALID_BOARD_STATUS;
  2335. return;
  2336. }
  2337. last = index;
  2338. break;
  2339. case 2:
  2340. board.type = ints[index];
  2341. if (board.type >= PCIXEM) {
  2342. printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
  2343. invalid_lilo_config = 1;
  2344. setup_error_code |= INVALID_BOARD_TYPE;
  2345. return;
  2346. }
  2347. last = index;
  2348. break;
  2349. case 3:
  2350. board.altpin = ints[index];
  2351. if (board.altpin > 1) {
  2352. printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
  2353. invalid_lilo_config = 1;
  2354. setup_error_code |= INVALID_ALTPIN;
  2355. return;
  2356. }
  2357. last = index;
  2358. break;
  2359. case 4:
  2360. board.numports = ints[index];
  2361. if (board.numports < 2 || board.numports > 256) {
  2362. printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
  2363. invalid_lilo_config = 1;
  2364. setup_error_code |= INVALID_NUM_PORTS;
  2365. return;
  2366. }
  2367. nbdevs += board.numports;
  2368. last = index;
  2369. break;
  2370. case 5:
  2371. board.port = ints[index];
  2372. if (ints[index] <= 0) {
  2373. printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
  2374. invalid_lilo_config = 1;
  2375. setup_error_code |= INVALID_PORT_BASE;
  2376. return;
  2377. }
  2378. last = index;
  2379. break;
  2380. case 6:
  2381. board.membase = ints[index];
  2382. if (ints[index] <= 0) {
  2383. printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",(unsigned int)board.membase);
  2384. invalid_lilo_config = 1;
  2385. setup_error_code |= INVALID_MEM_BASE;
  2386. return;
  2387. }
  2388. last = index;
  2389. break;
  2390. default:
  2391. printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
  2392. return;
  2393. } /* End parse switch */
  2394. while (str && *str) { /* Begin while there is a string arg */
  2395. /* find the next comma or terminator */
  2396. temp = str;
  2397. /* While string is not null, and a comma hasn't been found */
  2398. while (*temp && (*temp != ','))
  2399. temp++;
  2400. if (!*temp)
  2401. temp = NULL;
  2402. else
  2403. *temp++ = 0;
  2404. /* Set index to the number of args + 1 */
  2405. index = last + 1;
  2406. switch(index)
  2407. {
  2408. case 1:
  2409. len = strlen(str);
  2410. if (strncmp("Disable", str, len) == 0)
  2411. board.status = 0;
  2412. else if (strncmp("Enable", str, len) == 0)
  2413. board.status = 1;
  2414. else {
  2415. printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
  2416. invalid_lilo_config = 1;
  2417. setup_error_code |= INVALID_BOARD_STATUS;
  2418. return;
  2419. }
  2420. last = index;
  2421. break;
  2422. case 2:
  2423. for(loop = 0; loop < EPCA_NUM_TYPES; loop++)
  2424. if (strcmp(board_desc[loop], str) == 0)
  2425. break;
  2426. /* ---------------------------------------------------------------
  2427. If the index incremented above refers to a legitamate board
  2428. type set it here.
  2429. ------------------------------------------------------------------*/
  2430. if (index < EPCA_NUM_TYPES)
  2431. board.type = loop;
  2432. else {
  2433. printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
  2434. invalid_lilo_config = 1;
  2435. setup_error_code |= INVALID_BOARD_TYPE;
  2436. return;
  2437. }
  2438. last = index;
  2439. break;
  2440. case 3:
  2441. len = strlen(str);
  2442. if (strncmp("Disable", str, len) == 0)
  2443. board.altpin = 0;
  2444. else if (strncmp("Enable", str, len) == 0)
  2445. board.altpin = 1;
  2446. else {
  2447. printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
  2448. invalid_lilo_config = 1;
  2449. setup_error_code |= INVALID_ALTPIN;
  2450. return;
  2451. }
  2452. last = index;
  2453. break;
  2454. case 4:
  2455. t2 = str;
  2456. while (isdigit(*t2))
  2457. t2++;
  2458. if (*t2) {
  2459. printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
  2460. invalid_lilo_config = 1;
  2461. setup_error_code |= INVALID_NUM_PORTS;
  2462. return;
  2463. }
  2464. /* ------------------------------------------------------------
  2465. There is not a man page for simple_strtoul but the code can be
  2466. found in vsprintf.c. The first argument is the string to
  2467. translate (To an unsigned long obviously), the second argument
  2468. can be the address of any character variable or a NULL. If a
  2469. variable is given, the end pointer of the string will be stored
  2470. in that variable; if a NULL is given the end pointer will
  2471. not be returned. The last argument is the base to use. If
  2472. a 0 is indicated, the routine will attempt to determine the
  2473. proper base by looking at the values prefix (A '0' for octal,
  2474. a 'x' for hex, etc ... If a value is given it will use that
  2475. value as the base.
  2476. ---------------------------------------------------------------- */
  2477. board.numports = simple_strtoul(str, NULL, 0);
  2478. nbdevs += board.numports;
  2479. last = index;
  2480. break;
  2481. case 5:
  2482. t2 = str;
  2483. while (isxdigit(*t2))
  2484. t2++;
  2485. if (*t2) {
  2486. printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
  2487. invalid_lilo_config = 1;
  2488. setup_error_code |= INVALID_PORT_BASE;
  2489. return;
  2490. }
  2491. board.port = simple_strtoul(str, NULL, 16);
  2492. last = index;
  2493. break;
  2494. case 6:
  2495. t2 = str;
  2496. while (isxdigit(*t2))
  2497. t2++;
  2498. if (*t2) {
  2499. printk(KERN_ERR "epca_setup: Invalid memory base %s\n",str);
  2500. invalid_lilo_config = 1;
  2501. setup_error_code |= INVALID_MEM_BASE;
  2502. return;
  2503. }
  2504. board.membase = simple_strtoul(str, NULL, 16);
  2505. last = index;
  2506. break;
  2507. default:
  2508. printk(KERN_ERR "epca: Too many string parms\n");
  2509. return;
  2510. }
  2511. str = temp;
  2512. } /* End while there is a string arg */
  2513. if (last < 6) {
  2514. printk(KERN_ERR "epca: Insufficient parms specified\n");
  2515. return;
  2516. }
  2517. /* I should REALLY validate the stuff here */
  2518. /* Copies our local copy of board into boards */
  2519. memcpy((void *)&boards[num_cards],(void *)&board, sizeof(board));
  2520. /* Does this get called once per lilo arg are what ? */
  2521. printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
  2522. num_cards, board_desc[board.type],
  2523. board.numports, (int)board.port, (unsigned int) board.membase);
  2524. num_cards++;
  2525. } /* End epca_setup */
  2526. /* ------------------------ Begin init_PCI --------------------------- */
  2527. enum epic_board_types {
  2528. brd_xr = 0,
  2529. brd_xem,
  2530. brd_cx,
  2531. brd_xrj,
  2532. };
  2533. /* indexed directly by epic_board_types enum */
  2534. static struct {
  2535. unsigned char board_type;
  2536. unsigned bar_idx; /* PCI base address region */
  2537. } epca_info_tbl[] = {
  2538. { PCIXR, 0, },
  2539. { PCIXEM, 0, },
  2540. { PCICX, 0, },
  2541. { PCIXRJ, 2, },
  2542. };
  2543. static int __devinit epca_init_one (struct pci_dev *pdev,
  2544. const struct pci_device_id *ent)
  2545. {
  2546. static int board_num = -1;
  2547. int board_idx, info_idx = ent->driver_data;
  2548. unsigned long addr;
  2549. if (pci_enable_device(pdev))
  2550. return -EIO;
  2551. board_num++;
  2552. board_idx = board_num + num_cards;
  2553. if (board_idx >= MAXBOARDS)
  2554. goto err_out;
  2555. addr = pci_resource_start (pdev, epca_info_tbl[info_idx].bar_idx);
  2556. if (!addr) {
  2557. printk (KERN_ERR PFX "PCI region #%d not available (size 0)\n",
  2558. epca_info_tbl[info_idx].bar_idx);
  2559. goto err_out;
  2560. }
  2561. boards[board_idx].status = ENABLED;
  2562. boards[board_idx].type = epca_info_tbl[info_idx].board_type;
  2563. boards[board_idx].numports = 0x0;
  2564. boards[board_idx].port = addr + PCI_IO_OFFSET;
  2565. boards[board_idx].membase = addr;
  2566. if (!request_mem_region (addr + PCI_IO_OFFSET, 0x200000, "epca")) {
  2567. printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
  2568. 0x200000, addr + PCI_IO_OFFSET);
  2569. goto err_out;
  2570. }
  2571. boards[board_idx].re_map_port = ioremap(addr + PCI_IO_OFFSET, 0x200000);
  2572. if (!boards[board_idx].re_map_port) {
  2573. printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
  2574. 0x200000, addr + PCI_IO_OFFSET);
  2575. goto err_out_free_pciio;
  2576. }
  2577. if (!request_mem_region (addr, 0x200000, "epca")) {
  2578. printk (KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
  2579. 0x200000, addr);
  2580. goto err_out_free_iounmap;
  2581. }
  2582. boards[board_idx].re_map_membase = ioremap(addr, 0x200000);
  2583. if (!boards[board_idx].re_map_membase) {
  2584. printk (KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
  2585. 0x200000, addr + PCI_IO_OFFSET);
  2586. goto err_out_free_memregion;
  2587. }
  2588. /* --------------------------------------------------------------
  2589. I don't know what the below does, but the hardware guys say
  2590. its required on everything except PLX (In this case XRJ).
  2591. ---------------------------------------------------------------- */
  2592. if (info_idx != brd_xrj) {
  2593. pci_write_config_byte(pdev, 0x40, 0);
  2594. pci_write_config_byte(pdev, 0x46, 0);
  2595. }
  2596. return 0;
  2597. err_out_free_memregion:
  2598. release_mem_region (addr, 0x200000);
  2599. err_out_free_iounmap:
  2600. iounmap (boards[board_idx].re_map_port);
  2601. err_out_free_pciio:
  2602. release_mem_region (addr + PCI_IO_OFFSET, 0x200000);
  2603. err_out:
  2604. return -ENODEV;
  2605. }
  2606. static struct pci_device_id epca_pci_tbl[] = {
  2607. { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
  2608. { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
  2609. { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
  2610. { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
  2611. { 0, }
  2612. };
  2613. MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
  2614. int __init init_PCI (void)
  2615. { /* Begin init_PCI */
  2616. memset (&epca_driver, 0, sizeof (epca_driver));
  2617. epca_driver.name = "epca";
  2618. epca_driver.id_table = epca_pci_tbl;
  2619. epca_driver.probe = epca_init_one;
  2620. return pci_register_driver(&epca_driver);
  2621. }
  2622. MODULE_LICENSE("GPL");