epca.c 75 KB

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