epca.c 75 KB

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