epca.c 75 KB

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