epca.c 78 KB

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