epca.c 79 KB

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