isicom.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * as published by the Free Software Foundation; either version
  5. * 2 of the License, or (at your option) any later version.
  6. *
  7. * Original driver code supplied by Multi-Tech
  8. *
  9. * Changes
  10. * 1/9/98 alan@redhat.com Merge to 2.0.x kernel tree
  11. * Obtain and use official major/minors
  12. * Loader switched to a misc device
  13. * (fixed range check bug as a side effect)
  14. * Printk clean up
  15. * 9/12/98 alan@redhat.com Rough port to 2.1.x
  16. *
  17. * 10/6/99 sameer Merged the ISA and PCI drivers to
  18. * a new unified driver.
  19. *
  20. * 3/9/99 sameer Added support for ISI4616 cards.
  21. *
  22. * 16/9/99 sameer We do not force RTS low anymore.
  23. * This is to prevent the firmware
  24. * from getting confused.
  25. *
  26. * 26/10/99 sameer Cosmetic changes:The driver now
  27. * dumps the Port Count information
  28. * along with I/O address and IRQ.
  29. *
  30. * 13/12/99 sameer Fixed the problem with IRQ sharing.
  31. *
  32. * 10/5/00 sameer Fixed isicom_shutdown_board()
  33. * to not lower DTR on all the ports
  34. * when the last port on the card is
  35. * closed.
  36. *
  37. * 10/5/00 sameer Signal mask setup command added
  38. * to isicom_setup_port and
  39. * isicom_shutdown_port.
  40. *
  41. * 24/5/00 sameer The driver is now SMP aware.
  42. *
  43. *
  44. * 27/11/00 Vinayak P Risbud Fixed the Driver Crash Problem
  45. *
  46. *
  47. * 03/01/01 anil .s Added support for resetting the
  48. * internal modems on ISI cards.
  49. *
  50. * 08/02/01 anil .s Upgraded the driver for kernel
  51. * 2.4.x
  52. *
  53. * 11/04/01 Kevin Fixed firmware load problem with
  54. * ISIHP-4X card
  55. *
  56. * 30/04/01 anil .s Fixed the remote login through
  57. * ISI port problem. Now the link
  58. * does not go down before password
  59. * prompt.
  60. *
  61. * 03/05/01 anil .s Fixed the problem with IRQ sharing
  62. * among ISI-PCI cards.
  63. *
  64. * 03/05/01 anil .s Added support to display the version
  65. * info during insmod as well as module
  66. * listing by lsmod.
  67. *
  68. * 10/05/01 anil .s Done the modifications to the source
  69. * file and Install script so that the
  70. * same installation can be used for
  71. * 2.2.x and 2.4.x kernel.
  72. *
  73. * 06/06/01 anil .s Now we drop both dtr and rts during
  74. * shutdown_port as well as raise them
  75. * during isicom_config_port.
  76. *
  77. * 09/06/01 acme@conectiva.com.br use capable, not suser, do
  78. * restore_flags on failure in
  79. * isicom_send_break, verify put_user
  80. * result
  81. *
  82. * 11/02/03 ranjeeth Added support for 230 Kbps and 460 Kbps
  83. * Baud index extended to 21
  84. *
  85. * 20/03/03 ranjeeth Made to work for Linux Advanced server.
  86. * Taken care of license warning.
  87. *
  88. * 10/12/03 Ravindra Made to work for Fedora Core 1 of
  89. * Red Hat Distribution
  90. *
  91. * 06/01/05 Alan Cox Merged the ISI and base kernel strands
  92. * into a single 2.6 driver
  93. *
  94. * ***********************************************************
  95. *
  96. * To use this driver you also need the support package. You
  97. * can find this in RPM format on
  98. * ftp://ftp.linux.org.uk/pub/linux/alan
  99. *
  100. * You can find the original tools for this direct from Multitech
  101. * ftp://ftp.multitech.com/ISI-Cards/
  102. *
  103. * Having installed the cards the module options (/etc/modprobe.conf)
  104. *
  105. * options isicom io=card1,card2,card3,card4 irq=card1,card2,card3,card4
  106. *
  107. * Omit those entries for boards you don't have installed.
  108. *
  109. * TODO
  110. * Hotplug
  111. * Merge testing
  112. * 64-bit verification
  113. */
  114. #include <linux/module.h>
  115. #include <linux/kernel.h>
  116. #include <linux/tty.h>
  117. #include <linux/termios.h>
  118. #include <linux/fs.h>
  119. #include <linux/sched.h>
  120. #include <linux/serial.h>
  121. #include <linux/mm.h>
  122. #include <linux/miscdevice.h>
  123. #include <linux/interrupt.h>
  124. #include <linux/timer.h>
  125. #include <linux/delay.h>
  126. #include <linux/ioport.h>
  127. #include <asm/uaccess.h>
  128. #include <asm/io.h>
  129. #include <asm/system.h>
  130. #include <linux/pci.h>
  131. #include <linux/isicom.h>
  132. static struct pci_device_id isicom_pci_tbl[] = {
  133. { VENDOR_ID, 0x2028, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  134. { VENDOR_ID, 0x2051, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  135. { VENDOR_ID, 0x2052, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  136. { VENDOR_ID, 0x2053, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  137. { VENDOR_ID, 0x2054, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  138. { VENDOR_ID, 0x2055, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  139. { VENDOR_ID, 0x2056, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  140. { VENDOR_ID, 0x2057, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  141. { VENDOR_ID, 0x2058, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  142. { 0 }
  143. };
  144. MODULE_DEVICE_TABLE(pci, isicom_pci_tbl);
  145. static int prev_card = 3; /* start servicing isi_card[0] */
  146. static struct tty_driver *isicom_normal;
  147. static struct timer_list tx;
  148. static char re_schedule = 1;
  149. #ifdef ISICOM_DEBUG
  150. static unsigned long tx_count = 0;
  151. #endif
  152. static int ISILoad_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg);
  153. static void isicom_tx(unsigned long _data);
  154. static void isicom_start(struct tty_struct * tty);
  155. static unsigned char * tmp_buf;
  156. static DECLARE_MUTEX(tmp_buf_sem);
  157. /* baud index mappings from linux defns to isi */
  158. static signed char linuxb_to_isib[] = {
  159. -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 15, 16, 17,
  160. 18, 19
  161. };
  162. struct isi_board {
  163. unsigned short base;
  164. unsigned char irq;
  165. unsigned char port_count;
  166. unsigned short status;
  167. unsigned short port_status; /* each bit represents a single port */
  168. unsigned short shift_count;
  169. struct isi_port * ports;
  170. signed char count;
  171. unsigned char isa;
  172. spinlock_t card_lock; /* Card wide lock 11/5/00 -sameer */
  173. unsigned long flags;
  174. };
  175. struct isi_port {
  176. unsigned short magic;
  177. unsigned int flags;
  178. int count;
  179. int blocked_open;
  180. int close_delay;
  181. unsigned short channel;
  182. unsigned short status;
  183. unsigned short closing_wait;
  184. struct isi_board * card;
  185. struct tty_struct * tty;
  186. wait_queue_head_t close_wait;
  187. wait_queue_head_t open_wait;
  188. struct work_struct hangup_tq;
  189. struct work_struct bh_tqueue;
  190. unsigned char * xmit_buf;
  191. int xmit_head;
  192. int xmit_tail;
  193. int xmit_cnt;
  194. };
  195. static struct isi_board isi_card[BOARD_COUNT];
  196. static struct isi_port isi_ports[PORT_COUNT];
  197. /*
  198. * Locking functions for card level locking. We need to own both
  199. * the kernel lock for the card and have the card in a position that
  200. * it wants to talk.
  201. */
  202. static int lock_card(struct isi_board *card)
  203. {
  204. char retries;
  205. unsigned short base = card->base;
  206. for (retries = 0; retries < 100; retries++) {
  207. spin_lock_irqsave(&card->card_lock, card->flags);
  208. if (inw(base + 0xe) & 0x1) {
  209. return 1;
  210. } else {
  211. spin_unlock_irqrestore(&card->card_lock, card->flags);
  212. udelay(1000); /* 1ms */
  213. }
  214. }
  215. printk(KERN_WARNING "ISICOM: Failed to lock Card (0x%x)\n", card->base);
  216. return 0; /* Failed to aquire the card! */
  217. }
  218. static int lock_card_at_interrupt(struct isi_board *card)
  219. {
  220. unsigned char retries;
  221. unsigned short base = card->base;
  222. for (retries = 0; retries < 200; retries++) {
  223. spin_lock_irqsave(&card->card_lock, card->flags);
  224. if (inw(base + 0xe) & 0x1)
  225. return 1;
  226. else
  227. spin_unlock_irqrestore(&card->card_lock, card->flags);
  228. }
  229. /* Failing in interrupt is an acceptable event */
  230. return 0; /* Failed to aquire the card! */
  231. }
  232. static void unlock_card(struct isi_board *card)
  233. {
  234. spin_unlock_irqrestore(&card->card_lock, card->flags);
  235. }
  236. /*
  237. * ISI Card specific ops ...
  238. */
  239. static void raise_dtr(struct isi_port * port)
  240. {
  241. struct isi_board * card = port->card;
  242. unsigned short base = card->base;
  243. unsigned char channel = port->channel;
  244. if (!lock_card(card))
  245. return;
  246. outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
  247. outw(0x0504, base);
  248. InterruptTheCard(base);
  249. port->status |= ISI_DTR;
  250. unlock_card(card);
  251. }
  252. static inline void drop_dtr(struct isi_port * port)
  253. {
  254. struct isi_board * card = port->card;
  255. unsigned short base = card->base;
  256. unsigned char channel = port->channel;
  257. if (!lock_card(card))
  258. return;
  259. outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
  260. outw(0x0404, base);
  261. InterruptTheCard(base);
  262. port->status &= ~ISI_DTR;
  263. unlock_card(card);
  264. }
  265. static inline void raise_rts(struct isi_port * port)
  266. {
  267. struct isi_board * card = port->card;
  268. unsigned short base = card->base;
  269. unsigned char channel = port->channel;
  270. if (!lock_card(card))
  271. return;
  272. outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
  273. outw(0x0a04, base);
  274. InterruptTheCard(base);
  275. port->status |= ISI_RTS;
  276. unlock_card(card);
  277. }
  278. static inline void drop_rts(struct isi_port * port)
  279. {
  280. struct isi_board * card = port->card;
  281. unsigned short base = card->base;
  282. unsigned char channel = port->channel;
  283. if (!lock_card(card))
  284. return;
  285. outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
  286. outw(0x0804, base);
  287. InterruptTheCard(base);
  288. port->status &= ~ISI_RTS;
  289. unlock_card(card);
  290. }
  291. static inline void raise_dtr_rts(struct isi_port * port)
  292. {
  293. struct isi_board * card = port->card;
  294. unsigned short base = card->base;
  295. unsigned char channel = port->channel;
  296. if (!lock_card(card))
  297. return;
  298. outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
  299. outw(0x0f04, base);
  300. InterruptTheCard(base);
  301. port->status |= (ISI_DTR | ISI_RTS);
  302. unlock_card(card);
  303. }
  304. static void drop_dtr_rts(struct isi_port * port)
  305. {
  306. struct isi_board * card = port->card;
  307. unsigned short base = card->base;
  308. unsigned char channel = port->channel;
  309. if (!lock_card(card))
  310. return;
  311. outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
  312. outw(0x0c04, base);
  313. InterruptTheCard(base);
  314. port->status &= ~(ISI_RTS | ISI_DTR);
  315. unlock_card(card);
  316. }
  317. static inline void kill_queue(struct isi_port * port, short queue)
  318. {
  319. struct isi_board * card = port->card;
  320. unsigned short base = card->base;
  321. unsigned char channel = port->channel;
  322. if (!lock_card(card))
  323. return;
  324. outw(0x8000 | (channel << card->shift_count) | 0x02 , base);
  325. outw((queue << 8) | 0x06, base);
  326. InterruptTheCard(base);
  327. unlock_card(card);
  328. }
  329. /*
  330. * Firmware loader driver specific routines. This needs to mostly die
  331. * and be replaced with request_firmware.
  332. */
  333. static struct file_operations ISILoad_fops = {
  334. .owner = THIS_MODULE,
  335. .ioctl = ISILoad_ioctl,
  336. };
  337. static struct miscdevice isiloader_device = {
  338. ISILOAD_MISC_MINOR, "isictl", &ISILoad_fops
  339. };
  340. static inline int WaitTillCardIsFree(unsigned short base)
  341. {
  342. unsigned long count=0;
  343. while( (!(inw(base+0xe) & 0x1)) && (count++ < 6000000));
  344. if (inw(base+0xe)&0x1)
  345. return 0;
  346. else
  347. return 1;
  348. }
  349. static int ISILoad_ioctl(struct inode *inode, struct file *filp,
  350. unsigned int cmd, unsigned long arg)
  351. {
  352. unsigned int card, i, j, signature, status, portcount = 0;
  353. unsigned long t;
  354. unsigned short word_count, base;
  355. bin_frame frame;
  356. void __user *argp = (void __user *)arg;
  357. /* exec_record exec_rec; */
  358. if(get_user(card, (int __user *)argp))
  359. return -EFAULT;
  360. if(card < 0 || card >= BOARD_COUNT)
  361. return -ENXIO;
  362. base=isi_card[card].base;
  363. if(base==0)
  364. return -ENXIO; /* disabled or not used */
  365. switch(cmd) {
  366. case MIOCTL_RESET_CARD:
  367. if (!capable(CAP_SYS_ADMIN))
  368. return -EPERM;
  369. printk(KERN_DEBUG "ISILoad:Resetting Card%d at 0x%x ",card+1,base);
  370. inw(base+0x8);
  371. for(t=jiffies+HZ/100;time_before(jiffies, t););
  372. outw(0,base+0x8); /* Reset */
  373. for(j=1;j<=3;j++) {
  374. for(t=jiffies+HZ;time_before(jiffies, t););
  375. printk(".");
  376. }
  377. signature=(inw(base+0x4)) & 0xff;
  378. if (isi_card[card].isa) {
  379. if (!(inw(base+0xe) & 0x1) || (inw(base+0x2))) {
  380. #ifdef ISICOM_DEBUG
  381. printk("\nbase+0x2=0x%x , base+0xe=0x%x",inw(base+0x2),inw(base+0xe));
  382. #endif
  383. printk("\nISILoad:ISA Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card+1,base);
  384. return -EIO;
  385. }
  386. }
  387. else {
  388. portcount = inw(base+0x2);
  389. if (!(inw(base+0xe) & 0x1) || ((portcount!=0) && (portcount!=4) && (portcount!=8))) {
  390. #ifdef ISICOM_DEBUG
  391. printk("\nbase+0x2=0x%x , base+0xe=0x%x",inw(base+0x2),inw(base+0xe));
  392. #endif
  393. printk("\nISILoad:PCI Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card+1,base);
  394. return -EIO;
  395. }
  396. }
  397. switch(signature) {
  398. case 0xa5:
  399. case 0xbb:
  400. case 0xdd:
  401. if (isi_card[card].isa)
  402. isi_card[card].port_count = 8;
  403. else {
  404. if (portcount == 4)
  405. isi_card[card].port_count = 4;
  406. else
  407. isi_card[card].port_count = 8;
  408. }
  409. isi_card[card].shift_count = 12;
  410. break;
  411. case 0xcc: isi_card[card].port_count = 16;
  412. isi_card[card].shift_count = 11;
  413. break;
  414. default: printk("ISILoad:Card%d reset failure (Possible bad I/O Port Address 0x%x).\n",card+1,base);
  415. #ifdef ISICOM_DEBUG
  416. printk("Sig=0x%x\n",signature);
  417. #endif
  418. return -EIO;
  419. }
  420. printk("-Done\n");
  421. return put_user(signature,(unsigned __user *)argp);
  422. case MIOCTL_LOAD_FIRMWARE:
  423. if (!capable(CAP_SYS_ADMIN))
  424. return -EPERM;
  425. if(copy_from_user(&frame, argp, sizeof(bin_frame)))
  426. return -EFAULT;
  427. if (WaitTillCardIsFree(base))
  428. return -EIO;
  429. outw(0xf0,base); /* start upload sequence */
  430. outw(0x00,base);
  431. outw((frame.addr), base);/* lsb of adderess */
  432. word_count=(frame.count >> 1) + frame.count % 2;
  433. outw(word_count, base);
  434. InterruptTheCard(base);
  435. for(i=0;i<=0x2f;i++); /* a wee bit of delay */
  436. if (WaitTillCardIsFree(base))
  437. return -EIO;
  438. if ((status=inw(base+0x4))!=0) {
  439. printk(KERN_WARNING "ISILoad:Card%d rejected load header:\nAddress:0x%x \nCount:0x%x \nStatus:0x%x \n",
  440. card+1, frame.addr, frame.count, status);
  441. return -EIO;
  442. }
  443. outsw(base, (void *) frame.bin_data, word_count);
  444. InterruptTheCard(base);
  445. for(i=0;i<=0x0f;i++); /* another wee bit of delay */
  446. if (WaitTillCardIsFree(base))
  447. return -EIO;
  448. if ((status=inw(base+0x4))!=0) {
  449. printk(KERN_ERR "ISILoad:Card%d got out of sync.Card Status:0x%x\n",card+1, status);
  450. return -EIO;
  451. }
  452. return 0;
  453. case MIOCTL_READ_FIRMWARE:
  454. if (!capable(CAP_SYS_ADMIN))
  455. return -EPERM;
  456. if(copy_from_user(&frame, argp, sizeof(bin_header)))
  457. return -EFAULT;
  458. if (WaitTillCardIsFree(base))
  459. return -EIO;
  460. outw(0xf1,base); /* start download sequence */
  461. outw(0x00,base);
  462. outw((frame.addr), base);/* lsb of adderess */
  463. word_count=(frame.count >> 1) + frame.count % 2;
  464. outw(word_count+1, base);
  465. InterruptTheCard(base);
  466. for(i=0;i<=0xf;i++); /* a wee bit of delay */
  467. if (WaitTillCardIsFree(base))
  468. return -EIO;
  469. if ((status=inw(base+0x4))!=0) {
  470. printk(KERN_WARNING "ISILoad:Card%d rejected verify header:\nAddress:0x%x \nCount:0x%x \nStatus:0x%x \n",
  471. card+1, frame.addr, frame.count, status);
  472. return -EIO;
  473. }
  474. inw(base);
  475. insw(base, frame.bin_data, word_count);
  476. InterruptTheCard(base);
  477. for(i=0;i<=0x0f;i++); /* another wee bit of delay */
  478. if (WaitTillCardIsFree(base))
  479. return -EIO;
  480. if ((status=inw(base+0x4))!=0) {
  481. printk(KERN_ERR "ISILoad:Card%d verify got out of sync.Card Status:0x%x\n",card+1, status);
  482. return -EIO;
  483. }
  484. if(copy_to_user(argp, &frame, sizeof(bin_frame)))
  485. return -EFAULT;
  486. return 0;
  487. case MIOCTL_XFER_CTRL:
  488. if (!capable(CAP_SYS_ADMIN))
  489. return -EPERM;
  490. if (WaitTillCardIsFree(base))
  491. return -EIO;
  492. outw(0xf2, base);
  493. outw(0x800, base);
  494. outw(0x0, base);
  495. outw(0x0, base);
  496. InterruptTheCard(base);
  497. outw(0x0, base+0x4); /* for ISI4608 cards */
  498. isi_card[card].status |= FIRMWARE_LOADED;
  499. return 0;
  500. default:
  501. #ifdef ISICOM_DEBUG
  502. printk(KERN_DEBUG "ISILoad: Received Ioctl cmd 0x%x.\n", cmd);
  503. #endif
  504. return -ENOIOCTLCMD;
  505. }
  506. }
  507. /*
  508. * ISICOM Driver specific routines ...
  509. *
  510. */
  511. static inline int isicom_paranoia_check(struct isi_port const * port, char *name,
  512. const char * routine)
  513. {
  514. #ifdef ISICOM_DEBUG
  515. static const char * badmagic =
  516. KERN_WARNING "ISICOM: Warning: bad isicom magic for dev %s in %s.\n";
  517. static const char * badport =
  518. KERN_WARNING "ISICOM: Warning: NULL isicom port for dev %s in %s.\n";
  519. if (!port) {
  520. printk(badport, name, routine);
  521. return 1;
  522. }
  523. if (port->magic != ISICOM_MAGIC) {
  524. printk(badmagic, name, routine);
  525. return 1;
  526. }
  527. #endif
  528. return 0;
  529. }
  530. /*
  531. * Transmitter.
  532. *
  533. * We shovel data into the card buffers on a regular basis. The card
  534. * will do the rest of the work for us.
  535. */
  536. static void isicom_tx(unsigned long _data)
  537. {
  538. short count = (BOARD_COUNT-1), card, base;
  539. short txcount, wrd, residue, word_count, cnt;
  540. struct isi_port * port;
  541. struct tty_struct * tty;
  542. #ifdef ISICOM_DEBUG
  543. ++tx_count;
  544. #endif
  545. /* find next active board */
  546. card = (prev_card + 1) & 0x0003;
  547. while(count-- > 0) {
  548. if (isi_card[card].status & BOARD_ACTIVE)
  549. break;
  550. card = (card + 1) & 0x0003;
  551. }
  552. if (!(isi_card[card].status & BOARD_ACTIVE))
  553. goto sched_again;
  554. prev_card = card;
  555. count = isi_card[card].port_count;
  556. port = isi_card[card].ports;
  557. base = isi_card[card].base;
  558. for (;count > 0;count--, port++) {
  559. if (!lock_card_at_interrupt(&isi_card[card]))
  560. continue;
  561. /* port not active or tx disabled to force flow control */
  562. if (!(port->flags & ASYNC_INITIALIZED) ||
  563. !(port->status & ISI_TXOK))
  564. unlock_card(&isi_card[card]);
  565. continue;
  566. tty = port->tty;
  567. if(tty == NULL) {
  568. unlock_card(&isi_card[card]);
  569. continue;
  570. }
  571. txcount = min_t(short, TX_SIZE, port->xmit_cnt);
  572. if (txcount <= 0 || tty->stopped || tty->hw_stopped) {
  573. unlock_card(&isi_card[card]);
  574. continue;
  575. }
  576. if (!(inw(base + 0x02) & (1 << port->channel))) {
  577. unlock_card(&isi_card[card]);
  578. continue;
  579. }
  580. #ifdef ISICOM_DEBUG
  581. printk(KERN_DEBUG "ISICOM: txing %d bytes, port%d.\n",
  582. txcount, port->channel+1);
  583. #endif
  584. outw((port->channel << isi_card[card].shift_count) | txcount
  585. , base);
  586. residue = NO;
  587. wrd = 0;
  588. while (1) {
  589. cnt = min_t(int, txcount, (SERIAL_XMIT_SIZE - port->xmit_tail));
  590. if (residue == YES) {
  591. residue = NO;
  592. if (cnt > 0) {
  593. wrd |= (port->xmit_buf[port->xmit_tail] << 8);
  594. port->xmit_tail = (port->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1);
  595. port->xmit_cnt--;
  596. txcount--;
  597. cnt--;
  598. outw(wrd, base);
  599. }
  600. else {
  601. outw(wrd, base);
  602. break;
  603. }
  604. }
  605. if (cnt <= 0) break;
  606. word_count = cnt >> 1;
  607. outsw(base, port->xmit_buf+port->xmit_tail, word_count);
  608. port->xmit_tail = (port->xmit_tail + (word_count << 1)) &
  609. (SERIAL_XMIT_SIZE - 1);
  610. txcount -= (word_count << 1);
  611. port->xmit_cnt -= (word_count << 1);
  612. if (cnt & 0x0001) {
  613. residue = YES;
  614. wrd = port->xmit_buf[port->xmit_tail];
  615. port->xmit_tail = (port->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1);
  616. port->xmit_cnt--;
  617. txcount--;
  618. }
  619. }
  620. InterruptTheCard(base);
  621. if (port->xmit_cnt <= 0)
  622. port->status &= ~ISI_TXOK;
  623. if (port->xmit_cnt <= WAKEUP_CHARS)
  624. schedule_work(&port->bh_tqueue);
  625. unlock_card(&isi_card[card]);
  626. }
  627. /* schedule another tx for hopefully in about 10ms */
  628. sched_again:
  629. if (!re_schedule)
  630. return;
  631. init_timer(&tx);
  632. tx.expires = jiffies + HZ/100;
  633. tx.data = 0;
  634. tx.function = isicom_tx;
  635. add_timer(&tx);
  636. return;
  637. }
  638. /* Interrupt handlers */
  639. static void isicom_bottomhalf(void * data)
  640. {
  641. struct isi_port * port = (struct isi_port *) data;
  642. struct tty_struct * tty = port->tty;
  643. if (!tty)
  644. return;
  645. tty_wakeup(tty);
  646. wake_up_interruptible(&tty->write_wait);
  647. }
  648. /*
  649. * Main interrupt handler routine
  650. */
  651. static irqreturn_t isicom_interrupt(int irq, void *dev_id,
  652. struct pt_regs *regs)
  653. {
  654. struct isi_board * card;
  655. struct isi_port * port;
  656. struct tty_struct * tty;
  657. unsigned short base, header, word_count, count;
  658. unsigned char channel;
  659. short byte_count;
  660. card = (struct isi_board *) dev_id;
  661. if (!card || !(card->status & FIRMWARE_LOADED))
  662. return IRQ_NONE;
  663. base = card->base;
  664. spin_lock(&card->card_lock);
  665. if (card->isa == NO) {
  666. /*
  667. * disable any interrupts from the PCI card and lower the
  668. * interrupt line
  669. */
  670. outw(0x8000, base+0x04);
  671. ClearInterrupt(base);
  672. }
  673. inw(base); /* get the dummy word out */
  674. header = inw(base);
  675. channel = (header & 0x7800) >> card->shift_count;
  676. byte_count = header & 0xff;
  677. if (channel + 1 > card->port_count) {
  678. printk(KERN_WARNING "ISICOM: isicom_interrupt(0x%x): %d(channel) > port_count.\n",
  679. base, channel+1);
  680. if (card->isa)
  681. ClearInterrupt(base);
  682. else
  683. outw(0x0000, base+0x04); /* enable interrupts */
  684. spin_unlock(&card->card_lock);
  685. return IRQ_HANDLED;
  686. }
  687. port = card->ports + channel;
  688. if (!(port->flags & ASYNC_INITIALIZED)) {
  689. if (card->isa)
  690. ClearInterrupt(base);
  691. else
  692. outw(0x0000, base+0x04); /* enable interrupts */
  693. return IRQ_HANDLED;
  694. }
  695. tty = port->tty;
  696. if (tty == NULL) {
  697. word_count = byte_count >> 1;
  698. while(byte_count > 1) {
  699. inw(base);
  700. byte_count -= 2;
  701. }
  702. if (byte_count & 0x01)
  703. inw(base);
  704. if (card->isa == YES)
  705. ClearInterrupt(base);
  706. else
  707. outw(0x0000, base+0x04); /* enable interrupts */
  708. spin_unlock(&card->card_lock);
  709. return IRQ_HANDLED;
  710. }
  711. if (header & 0x8000) { /* Status Packet */
  712. header = inw(base);
  713. switch(header & 0xff) {
  714. case 0: /* Change in EIA signals */
  715. if (port->flags & ASYNC_CHECK_CD) {
  716. if (port->status & ISI_DCD) {
  717. if (!(header & ISI_DCD)) {
  718. /* Carrier has been lost */
  719. #ifdef ISICOM_DEBUG
  720. printk(KERN_DEBUG "ISICOM: interrupt: DCD->low.\n");
  721. #endif
  722. port->status &= ~ISI_DCD;
  723. schedule_work(&port->hangup_tq);
  724. }
  725. }
  726. else {
  727. if (header & ISI_DCD) {
  728. /* Carrier has been detected */
  729. #ifdef ISICOM_DEBUG
  730. printk(KERN_DEBUG "ISICOM: interrupt: DCD->high.\n");
  731. #endif
  732. port->status |= ISI_DCD;
  733. wake_up_interruptible(&port->open_wait);
  734. }
  735. }
  736. }
  737. else {
  738. if (header & ISI_DCD)
  739. port->status |= ISI_DCD;
  740. else
  741. port->status &= ~ISI_DCD;
  742. }
  743. if (port->flags & ASYNC_CTS_FLOW) {
  744. if (port->tty->hw_stopped) {
  745. if (header & ISI_CTS) {
  746. port->tty->hw_stopped = 0;
  747. /* start tx ing */
  748. port->status |= (ISI_TXOK | ISI_CTS);
  749. schedule_work(&port->bh_tqueue);
  750. }
  751. }
  752. else {
  753. if (!(header & ISI_CTS)) {
  754. port->tty->hw_stopped = 1;
  755. /* stop tx ing */
  756. port->status &= ~(ISI_TXOK | ISI_CTS);
  757. }
  758. }
  759. }
  760. else {
  761. if (header & ISI_CTS)
  762. port->status |= ISI_CTS;
  763. else
  764. port->status &= ~ISI_CTS;
  765. }
  766. if (header & ISI_DSR)
  767. port->status |= ISI_DSR;
  768. else
  769. port->status &= ~ISI_DSR;
  770. if (header & ISI_RI)
  771. port->status |= ISI_RI;
  772. else
  773. port->status &= ~ISI_RI;
  774. break;
  775. case 1: /* Received Break !!! */
  776. if (tty->flip.count >= TTY_FLIPBUF_SIZE)
  777. break;
  778. *tty->flip.flag_buf_ptr++ = TTY_BREAK;
  779. *tty->flip.char_buf_ptr++ = 0;
  780. tty->flip.count++;
  781. if (port->flags & ASYNC_SAK)
  782. do_SAK(tty);
  783. schedule_delayed_work(&tty->flip.work, 1);
  784. break;
  785. case 2: /* Statistics */
  786. printk(KERN_DEBUG "ISICOM: isicom_interrupt: stats!!!.\n");
  787. break;
  788. default:
  789. printk(KERN_WARNING "ISICOM: Intr: Unknown code in status packet.\n");
  790. break;
  791. }
  792. }
  793. else { /* Data Packet */
  794. count = min_t(unsigned short, byte_count, (TTY_FLIPBUF_SIZE - tty->flip.count));
  795. #ifdef ISICOM_DEBUG
  796. printk(KERN_DEBUG "ISICOM: Intr: Can rx %d of %d bytes.\n",
  797. count, byte_count);
  798. #endif
  799. word_count = count >> 1;
  800. insw(base, tty->flip.char_buf_ptr, word_count);
  801. tty->flip.char_buf_ptr += (word_count << 1);
  802. byte_count -= (word_count << 1);
  803. if (count & 0x0001) {
  804. *tty->flip.char_buf_ptr++ = (char)(inw(base) & 0xff);
  805. byte_count -= 2;
  806. }
  807. memset(tty->flip.flag_buf_ptr, 0, count);
  808. tty->flip.flag_buf_ptr += count;
  809. tty->flip.count += count;
  810. if (byte_count > 0) {
  811. printk(KERN_DEBUG "ISICOM: Intr(0x%x:%d): Flip buffer overflow! dropping bytes...\n",
  812. base, channel+1);
  813. while(byte_count > 0) { /* drain out unread xtra data */
  814. inw(base);
  815. byte_count -= 2;
  816. }
  817. }
  818. schedule_delayed_work(&tty->flip.work, 1);
  819. }
  820. if (card->isa == YES)
  821. ClearInterrupt(base);
  822. else
  823. outw(0x0000, base+0x04); /* enable interrupts */
  824. return IRQ_HANDLED;
  825. }
  826. static void isicom_config_port(struct isi_port * port)
  827. {
  828. struct isi_board * card = port->card;
  829. struct tty_struct * tty;
  830. unsigned long baud;
  831. unsigned short channel_setup, base = card->base;
  832. unsigned short channel = port->channel, shift_count = card->shift_count;
  833. unsigned char flow_ctrl;
  834. if (!(tty = port->tty) || !tty->termios)
  835. return;
  836. baud = C_BAUD(tty);
  837. if (baud & CBAUDEX) {
  838. baud &= ~CBAUDEX;
  839. /* if CBAUDEX bit is on and the baud is set to either 50 or 75
  840. * then the card is programmed for 57.6Kbps or 115Kbps
  841. * respectively.
  842. */
  843. if (baud < 1 || baud > 2)
  844. port->tty->termios->c_cflag &= ~CBAUDEX;
  845. else
  846. baud += 15;
  847. }
  848. if (baud == 15) {
  849. /* the ASYNC_SPD_HI and ASYNC_SPD_VHI options are set
  850. * by the set_serial_info ioctl ... this is done by
  851. * the 'setserial' utility.
  852. */
  853. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
  854. baud++; /* 57.6 Kbps */
  855. if ((port->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
  856. baud +=2; /* 115 Kbps */
  857. }
  858. if (linuxb_to_isib[baud] == -1) {
  859. /* hang up */
  860. drop_dtr(port);
  861. return;
  862. }
  863. else
  864. raise_dtr(port);
  865. if (lock_card(card)) {
  866. outw(0x8000 | (channel << shift_count) |0x03, base);
  867. outw(linuxb_to_isib[baud] << 8 | 0x03, base);
  868. channel_setup = 0;
  869. switch(C_CSIZE(tty)) {
  870. case CS5:
  871. channel_setup |= ISICOM_CS5;
  872. break;
  873. case CS6:
  874. channel_setup |= ISICOM_CS6;
  875. break;
  876. case CS7:
  877. channel_setup |= ISICOM_CS7;
  878. break;
  879. case CS8:
  880. channel_setup |= ISICOM_CS8;
  881. break;
  882. }
  883. if (C_CSTOPB(tty))
  884. channel_setup |= ISICOM_2SB;
  885. if (C_PARENB(tty)) {
  886. channel_setup |= ISICOM_EVPAR;
  887. if (C_PARODD(tty))
  888. channel_setup |= ISICOM_ODPAR;
  889. }
  890. outw(channel_setup, base);
  891. InterruptTheCard(base);
  892. unlock_card(card);
  893. }
  894. if (C_CLOCAL(tty))
  895. port->flags &= ~ASYNC_CHECK_CD;
  896. else
  897. port->flags |= ASYNC_CHECK_CD;
  898. /* flow control settings ...*/
  899. flow_ctrl = 0;
  900. port->flags &= ~ASYNC_CTS_FLOW;
  901. if (C_CRTSCTS(tty)) {
  902. port->flags |= ASYNC_CTS_FLOW;
  903. flow_ctrl |= ISICOM_CTSRTS;
  904. }
  905. if (I_IXON(tty))
  906. flow_ctrl |= ISICOM_RESPOND_XONXOFF;
  907. if (I_IXOFF(tty))
  908. flow_ctrl |= ISICOM_INITIATE_XONXOFF;
  909. if (lock_card(card)) {
  910. outw(0x8000 | (channel << shift_count) |0x04, base);
  911. outw(flow_ctrl << 8 | 0x05, base);
  912. outw((STOP_CHAR(tty)) << 8 | (START_CHAR(tty)), base);
  913. InterruptTheCard(base);
  914. unlock_card(card);
  915. }
  916. /* rx enabled -> enable port for rx on the card */
  917. if (C_CREAD(tty)) {
  918. card->port_status |= (1 << channel);
  919. outw(card->port_status, base + 0x02);
  920. }
  921. }
  922. /* open et all */
  923. static inline void isicom_setup_board(struct isi_board * bp)
  924. {
  925. int channel;
  926. struct isi_port * port;
  927. unsigned long flags;
  928. spin_lock_irqsave(&bp->card_lock, flags);
  929. if (bp->status & BOARD_ACTIVE) {
  930. spin_unlock_irqrestore(&bp->card_lock, flags);
  931. return;
  932. }
  933. port = bp->ports;
  934. bp->status |= BOARD_ACTIVE;
  935. spin_unlock_irqrestore(&bp->card_lock, flags);
  936. for(channel = 0; channel < bp->port_count; channel++, port++)
  937. drop_dtr_rts(port);
  938. return;
  939. }
  940. static int isicom_setup_port(struct isi_port * port)
  941. {
  942. struct isi_board * card = port->card;
  943. unsigned long flags;
  944. if (port->flags & ASYNC_INITIALIZED) {
  945. return 0;
  946. }
  947. if (!port->xmit_buf) {
  948. unsigned long page;
  949. if (!(page = get_zeroed_page(GFP_KERNEL)))
  950. return -ENOMEM;
  951. if (port->xmit_buf) {
  952. free_page(page);
  953. return -ERESTARTSYS;
  954. }
  955. port->xmit_buf = (unsigned char *) page;
  956. }
  957. spin_lock_irqsave(&card->card_lock, flags);
  958. if (port->tty)
  959. clear_bit(TTY_IO_ERROR, &port->tty->flags);
  960. if (port->count == 1)
  961. card->count++;
  962. port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
  963. /* discard any residual data */
  964. kill_queue(port, ISICOM_KILLTX | ISICOM_KILLRX);
  965. isicom_config_port(port);
  966. port->flags |= ASYNC_INITIALIZED;
  967. spin_unlock_irqrestore(&card->card_lock, flags);
  968. return 0;
  969. }
  970. static int block_til_ready(struct tty_struct * tty, struct file * filp, struct isi_port * port)
  971. {
  972. struct isi_board * card = port->card;
  973. int do_clocal = 0, retval;
  974. unsigned long flags;
  975. DECLARE_WAITQUEUE(wait, current);
  976. /* block if port is in the process of being closed */
  977. if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING) {
  978. #ifdef ISICOM_DEBUG
  979. printk(KERN_DEBUG "ISICOM: block_til_ready: close in progress.\n");
  980. #endif
  981. interruptible_sleep_on(&port->close_wait);
  982. if (port->flags & ASYNC_HUP_NOTIFY)
  983. return -EAGAIN;
  984. else
  985. return -ERESTARTSYS;
  986. }
  987. /* if non-blocking mode is set ... */
  988. if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
  989. #ifdef ISICOM_DEBUG
  990. printk(KERN_DEBUG "ISICOM: block_til_ready: non-block mode.\n");
  991. #endif
  992. port->flags |= ASYNC_NORMAL_ACTIVE;
  993. return 0;
  994. }
  995. if (C_CLOCAL(tty))
  996. do_clocal = 1;
  997. /* block waiting for DCD to be asserted, and while
  998. callout dev is busy */
  999. retval = 0;
  1000. add_wait_queue(&port->open_wait, &wait);
  1001. spin_lock_irqsave(&card->card_lock, flags);
  1002. if (!tty_hung_up_p(filp))
  1003. port->count--;
  1004. port->blocked_open++;
  1005. spin_unlock_irqrestore(&card->card_lock, flags);
  1006. while (1) {
  1007. raise_dtr_rts(port);
  1008. set_current_state(TASK_INTERRUPTIBLE);
  1009. if (tty_hung_up_p(filp) || !(port->flags & ASYNC_INITIALIZED)) {
  1010. if (port->flags & ASYNC_HUP_NOTIFY)
  1011. retval = -EAGAIN;
  1012. else
  1013. retval = -ERESTARTSYS;
  1014. break;
  1015. }
  1016. if (!(port->flags & ASYNC_CLOSING) &&
  1017. (do_clocal || (port->status & ISI_DCD))) {
  1018. break;
  1019. }
  1020. if (signal_pending(current)) {
  1021. retval = -ERESTARTSYS;
  1022. break;
  1023. }
  1024. schedule();
  1025. }
  1026. set_current_state(TASK_RUNNING);
  1027. remove_wait_queue(&port->open_wait, &wait);
  1028. spin_lock_irqsave(&card->card_lock, flags);
  1029. if (!tty_hung_up_p(filp))
  1030. port->count++;
  1031. port->blocked_open--;
  1032. spin_unlock_irqrestore(&card->card_lock, flags);
  1033. if (retval)
  1034. return retval;
  1035. port->flags |= ASYNC_NORMAL_ACTIVE;
  1036. return 0;
  1037. }
  1038. static int isicom_open(struct tty_struct * tty, struct file * filp)
  1039. {
  1040. struct isi_port * port;
  1041. struct isi_board * card;
  1042. unsigned int line, board;
  1043. int error;
  1044. line = tty->index;
  1045. if (line < 0 || line > PORT_COUNT-1)
  1046. return -ENODEV;
  1047. board = BOARD(line);
  1048. card = &isi_card[board];
  1049. if (!(card->status & FIRMWARE_LOADED))
  1050. return -ENODEV;
  1051. /* open on a port greater than the port count for the card !!! */
  1052. if (line > ((board * 16) + card->port_count - 1))
  1053. return -ENODEV;
  1054. port = &isi_ports[line];
  1055. if (isicom_paranoia_check(port, tty->name, "isicom_open"))
  1056. return -ENODEV;
  1057. isicom_setup_board(card);
  1058. port->count++;
  1059. tty->driver_data = port;
  1060. port->tty = tty;
  1061. if ((error = isicom_setup_port(port))!=0)
  1062. return error;
  1063. if ((error = block_til_ready(tty, filp, port))!=0)
  1064. return error;
  1065. return 0;
  1066. }
  1067. /* close et all */
  1068. static inline void isicom_shutdown_board(struct isi_board * bp)
  1069. {
  1070. unsigned long flags;
  1071. spin_lock_irqsave(&bp->card_lock, flags);
  1072. if (bp->status & BOARD_ACTIVE) {
  1073. bp->status &= ~BOARD_ACTIVE;
  1074. }
  1075. spin_unlock_irqrestore(&bp->card_lock, flags);
  1076. }
  1077. static void isicom_shutdown_port(struct isi_port * port)
  1078. {
  1079. struct isi_board * card = port->card;
  1080. struct tty_struct * tty;
  1081. unsigned long flags;
  1082. tty = port->tty;
  1083. spin_lock_irqsave(&card->card_lock, flags);
  1084. if (!(port->flags & ASYNC_INITIALIZED)) {
  1085. spin_unlock_irqrestore(&card->card_lock, flags);
  1086. return;
  1087. }
  1088. if (port->xmit_buf) {
  1089. free_page((unsigned long) port->xmit_buf);
  1090. port->xmit_buf = NULL;
  1091. }
  1092. port->flags &= ~ASYNC_INITIALIZED;
  1093. /* 3rd October 2000 : Vinayak P Risbud */
  1094. port->tty = NULL;
  1095. spin_unlock_irqrestore(&card->card_lock, flags);
  1096. /*Fix done by Anil .S on 30-04-2001
  1097. remote login through isi port has dtr toggle problem
  1098. due to which the carrier drops before the password prompt
  1099. appears on the remote end. Now we drop the dtr only if the
  1100. HUPCL(Hangup on close) flag is set for the tty*/
  1101. if (C_HUPCL(tty))
  1102. /* drop dtr on this port */
  1103. drop_dtr(port);
  1104. /* any other port uninits */
  1105. if (tty)
  1106. set_bit(TTY_IO_ERROR, &tty->flags);
  1107. if (--card->count < 0) {
  1108. printk(KERN_DEBUG "ISICOM: isicom_shutdown_port: bad board(0x%x) count %d.\n",
  1109. card->base, card->count);
  1110. card->count = 0;
  1111. }
  1112. /* last port was closed , shutdown that boad too */
  1113. if(C_HUPCL(tty)) {
  1114. if (!card->count)
  1115. isicom_shutdown_board(card);
  1116. }
  1117. }
  1118. static void isicom_close(struct tty_struct * tty, struct file * filp)
  1119. {
  1120. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1121. struct isi_board * card = port->card;
  1122. unsigned long flags;
  1123. if (!port)
  1124. return;
  1125. if (isicom_paranoia_check(port, tty->name, "isicom_close"))
  1126. return;
  1127. #ifdef ISICOM_DEBUG
  1128. printk(KERN_DEBUG "ISICOM: Close start!!!.\n");
  1129. #endif
  1130. spin_lock_irqsave(&card->card_lock, flags);
  1131. if (tty_hung_up_p(filp)) {
  1132. spin_unlock_irqrestore(&card->card_lock, flags);
  1133. return;
  1134. }
  1135. if (tty->count == 1 && port->count != 1) {
  1136. printk(KERN_WARNING "ISICOM:(0x%x) isicom_close: bad port count"
  1137. "tty->count = 1 port count = %d.\n",
  1138. card->base, port->count);
  1139. port->count = 1;
  1140. }
  1141. if (--port->count < 0) {
  1142. printk(KERN_WARNING "ISICOM:(0x%x) isicom_close: bad port count for"
  1143. "channel%d = %d", card->base, port->channel,
  1144. port->count);
  1145. port->count = 0;
  1146. }
  1147. if (port->count) {
  1148. spin_unlock_irqrestore(&card->card_lock, flags);
  1149. return;
  1150. }
  1151. port->flags |= ASYNC_CLOSING;
  1152. tty->closing = 1;
  1153. spin_unlock_irqrestore(&card->card_lock, flags);
  1154. if (port->closing_wait != ASYNC_CLOSING_WAIT_NONE)
  1155. tty_wait_until_sent(tty, port->closing_wait);
  1156. /* indicate to the card that no more data can be received
  1157. on this port */
  1158. spin_lock_irqsave(&card->card_lock, flags);
  1159. if (port->flags & ASYNC_INITIALIZED) {
  1160. card->port_status &= ~(1 << port->channel);
  1161. outw(card->port_status, card->base + 0x02);
  1162. }
  1163. isicom_shutdown_port(port);
  1164. spin_unlock_irqrestore(&card->card_lock, flags);
  1165. if (tty->driver->flush_buffer)
  1166. tty->driver->flush_buffer(tty);
  1167. tty_ldisc_flush(tty);
  1168. spin_lock_irqsave(&card->card_lock, flags);
  1169. tty->closing = 0;
  1170. if (port->blocked_open) {
  1171. spin_unlock_irqrestore(&card->card_lock, flags);
  1172. if (port->close_delay) {
  1173. #ifdef ISICOM_DEBUG
  1174. printk(KERN_DEBUG "ISICOM: scheduling until time out.\n");
  1175. #endif
  1176. msleep_interruptible(jiffies_to_msecs(port->close_delay));
  1177. }
  1178. spin_lock_irqsave(&card->card_lock, flags);
  1179. wake_up_interruptible(&port->open_wait);
  1180. }
  1181. port->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
  1182. wake_up_interruptible(&port->close_wait);
  1183. spin_unlock_irqrestore(&card->card_lock, flags);
  1184. }
  1185. /* write et all */
  1186. static int isicom_write(struct tty_struct * tty,
  1187. const unsigned char * buf, int count)
  1188. {
  1189. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1190. struct isi_board * card = port->card;
  1191. unsigned long flags;
  1192. int cnt, total = 0;
  1193. if (isicom_paranoia_check(port, tty->name, "isicom_write"))
  1194. return 0;
  1195. if (!tty || !port->xmit_buf || !tmp_buf)
  1196. return 0;
  1197. spin_lock_irqsave(&card->card_lock, flags);
  1198. while(1) {
  1199. cnt = min_t(int, count, min(SERIAL_XMIT_SIZE - port->xmit_cnt - 1,
  1200. SERIAL_XMIT_SIZE - port->xmit_head));
  1201. if (cnt <= 0)
  1202. break;
  1203. memcpy(port->xmit_buf + port->xmit_head, buf, cnt);
  1204. port->xmit_head = (port->xmit_head + cnt) & (SERIAL_XMIT_SIZE - 1);
  1205. port->xmit_cnt += cnt;
  1206. buf += cnt;
  1207. count -= cnt;
  1208. total += cnt;
  1209. }
  1210. if (port->xmit_cnt && !tty->stopped && !tty->hw_stopped)
  1211. port->status |= ISI_TXOK;
  1212. spin_unlock_irqrestore(&card->card_lock, flags);
  1213. return total;
  1214. }
  1215. /* put_char et all */
  1216. static void isicom_put_char(struct tty_struct * tty, unsigned char ch)
  1217. {
  1218. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1219. struct isi_board * card = port->card;
  1220. unsigned long flags;
  1221. if (isicom_paranoia_check(port, tty->name, "isicom_put_char"))
  1222. return;
  1223. if (!tty || !port->xmit_buf)
  1224. return;
  1225. spin_lock_irqsave(&card->card_lock, flags);
  1226. if (port->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
  1227. spin_unlock_irqrestore(&card->card_lock, flags);
  1228. return;
  1229. }
  1230. port->xmit_buf[port->xmit_head++] = ch;
  1231. port->xmit_head &= (SERIAL_XMIT_SIZE - 1);
  1232. port->xmit_cnt++;
  1233. spin_unlock_irqrestore(&card->card_lock, flags);
  1234. }
  1235. /* flush_chars et all */
  1236. static void isicom_flush_chars(struct tty_struct * tty)
  1237. {
  1238. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1239. if (isicom_paranoia_check(port, tty->name, "isicom_flush_chars"))
  1240. return;
  1241. if (port->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped || !port->xmit_buf)
  1242. return;
  1243. /* this tells the transmitter to consider this port for
  1244. data output to the card ... that's the best we can do. */
  1245. port->status |= ISI_TXOK;
  1246. }
  1247. /* write_room et all */
  1248. static int isicom_write_room(struct tty_struct * tty)
  1249. {
  1250. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1251. int free;
  1252. if (isicom_paranoia_check(port, tty->name, "isicom_write_room"))
  1253. return 0;
  1254. free = SERIAL_XMIT_SIZE - port->xmit_cnt - 1;
  1255. if (free < 0)
  1256. free = 0;
  1257. return free;
  1258. }
  1259. /* chars_in_buffer et all */
  1260. static int isicom_chars_in_buffer(struct tty_struct * tty)
  1261. {
  1262. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1263. if (isicom_paranoia_check(port, tty->name, "isicom_chars_in_buffer"))
  1264. return 0;
  1265. return port->xmit_cnt;
  1266. }
  1267. /* ioctl et all */
  1268. static inline void isicom_send_break(struct isi_port * port, unsigned long length)
  1269. {
  1270. struct isi_board * card = port->card;
  1271. unsigned short base = card->base;
  1272. if(!lock_card(card))
  1273. return;
  1274. outw(0x8000 | ((port->channel) << (card->shift_count)) | 0x3, base);
  1275. outw((length & 0xff) << 8 | 0x00, base);
  1276. outw((length & 0xff00), base);
  1277. InterruptTheCard(base);
  1278. unlock_card(card);
  1279. }
  1280. static int isicom_tiocmget(struct tty_struct *tty, struct file *file)
  1281. {
  1282. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1283. /* just send the port status */
  1284. unsigned short status = port->status;
  1285. if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
  1286. return -ENODEV;
  1287. return ((status & ISI_RTS) ? TIOCM_RTS : 0) |
  1288. ((status & ISI_DTR) ? TIOCM_DTR : 0) |
  1289. ((status & ISI_DCD) ? TIOCM_CAR : 0) |
  1290. ((status & ISI_DSR) ? TIOCM_DSR : 0) |
  1291. ((status & ISI_CTS) ? TIOCM_CTS : 0) |
  1292. ((status & ISI_RI ) ? TIOCM_RI : 0);
  1293. }
  1294. static int isicom_tiocmset(struct tty_struct *tty, struct file *file,
  1295. unsigned int set, unsigned int clear)
  1296. {
  1297. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1298. if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
  1299. return -ENODEV;
  1300. if (set & TIOCM_RTS)
  1301. raise_rts(port);
  1302. if (set & TIOCM_DTR)
  1303. raise_dtr(port);
  1304. if (clear & TIOCM_RTS)
  1305. drop_rts(port);
  1306. if (clear & TIOCM_DTR)
  1307. drop_dtr(port);
  1308. return 0;
  1309. }
  1310. static int isicom_set_serial_info(struct isi_port * port,
  1311. struct serial_struct __user *info)
  1312. {
  1313. struct serial_struct newinfo;
  1314. int reconfig_port;
  1315. if(copy_from_user(&newinfo, info, sizeof(newinfo)))
  1316. return -EFAULT;
  1317. reconfig_port = ((port->flags & ASYNC_SPD_MASK) !=
  1318. (newinfo.flags & ASYNC_SPD_MASK));
  1319. if (!capable(CAP_SYS_ADMIN)) {
  1320. if ((newinfo.close_delay != port->close_delay) ||
  1321. (newinfo.closing_wait != port->closing_wait) ||
  1322. ((newinfo.flags & ~ASYNC_USR_MASK) !=
  1323. (port->flags & ~ASYNC_USR_MASK)))
  1324. return -EPERM;
  1325. port->flags = ((port->flags & ~ ASYNC_USR_MASK) |
  1326. (newinfo.flags & ASYNC_USR_MASK));
  1327. }
  1328. else {
  1329. port->close_delay = newinfo.close_delay;
  1330. port->closing_wait = newinfo.closing_wait;
  1331. port->flags = ((port->flags & ~ASYNC_FLAGS) |
  1332. (newinfo.flags & ASYNC_FLAGS));
  1333. }
  1334. if (reconfig_port) {
  1335. isicom_config_port(port);
  1336. }
  1337. return 0;
  1338. }
  1339. static int isicom_get_serial_info(struct isi_port * port,
  1340. struct serial_struct __user *info)
  1341. {
  1342. struct serial_struct out_info;
  1343. memset(&out_info, 0, sizeof(out_info));
  1344. /* out_info.type = ? */
  1345. out_info.line = port - isi_ports;
  1346. out_info.port = port->card->base;
  1347. out_info.irq = port->card->irq;
  1348. out_info.flags = port->flags;
  1349. /* out_info.baud_base = ? */
  1350. out_info.close_delay = port->close_delay;
  1351. out_info.closing_wait = port->closing_wait;
  1352. if(copy_to_user(info, &out_info, sizeof(out_info)))
  1353. return -EFAULT;
  1354. return 0;
  1355. }
  1356. static int isicom_ioctl(struct tty_struct * tty, struct file * filp,
  1357. unsigned int cmd, unsigned long arg)
  1358. {
  1359. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1360. void __user *argp = (void __user *)arg;
  1361. int retval;
  1362. if (isicom_paranoia_check(port, tty->name, "isicom_ioctl"))
  1363. return -ENODEV;
  1364. switch(cmd) {
  1365. case TCSBRK:
  1366. retval = tty_check_change(tty);
  1367. if (retval)
  1368. return retval;
  1369. tty_wait_until_sent(tty, 0);
  1370. if (!arg)
  1371. isicom_send_break(port, HZ/4);
  1372. return 0;
  1373. case TCSBRKP:
  1374. retval = tty_check_change(tty);
  1375. if (retval)
  1376. return retval;
  1377. tty_wait_until_sent(tty, 0);
  1378. isicom_send_break(port, arg ? arg * (HZ/10) : HZ/4);
  1379. return 0;
  1380. case TIOCGSOFTCAR:
  1381. return put_user(C_CLOCAL(tty) ? 1 : 0, (unsigned long __user *)argp);
  1382. case TIOCSSOFTCAR:
  1383. if(get_user(arg, (unsigned long __user *) argp))
  1384. return -EFAULT;
  1385. tty->termios->c_cflag =
  1386. ((tty->termios->c_cflag & ~CLOCAL) |
  1387. (arg ? CLOCAL : 0));
  1388. return 0;
  1389. case TIOCGSERIAL:
  1390. return isicom_get_serial_info(port, argp);
  1391. case TIOCSSERIAL:
  1392. return isicom_set_serial_info(port, argp);
  1393. default:
  1394. return -ENOIOCTLCMD;
  1395. }
  1396. return 0;
  1397. }
  1398. /* set_termios et all */
  1399. static void isicom_set_termios(struct tty_struct * tty, struct termios * old_termios)
  1400. {
  1401. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1402. if (isicom_paranoia_check(port, tty->name, "isicom_set_termios"))
  1403. return;
  1404. if (tty->termios->c_cflag == old_termios->c_cflag &&
  1405. tty->termios->c_iflag == old_termios->c_iflag)
  1406. return;
  1407. isicom_config_port(port);
  1408. if ((old_termios->c_cflag & CRTSCTS) &&
  1409. !(tty->termios->c_cflag & CRTSCTS)) {
  1410. tty->hw_stopped = 0;
  1411. isicom_start(tty);
  1412. }
  1413. }
  1414. /* throttle et all */
  1415. static void isicom_throttle(struct tty_struct * tty)
  1416. {
  1417. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1418. struct isi_board * card = port->card;
  1419. if (isicom_paranoia_check(port, tty->name, "isicom_throttle"))
  1420. return;
  1421. /* tell the card that this port cannot handle any more data for now */
  1422. card->port_status &= ~(1 << port->channel);
  1423. outw(card->port_status, card->base + 0x02);
  1424. }
  1425. /* unthrottle et all */
  1426. static void isicom_unthrottle(struct tty_struct * tty)
  1427. {
  1428. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1429. struct isi_board * card = port->card;
  1430. if (isicom_paranoia_check(port, tty->name, "isicom_unthrottle"))
  1431. return;
  1432. /* tell the card that this port is ready to accept more data */
  1433. card->port_status |= (1 << port->channel);
  1434. outw(card->port_status, card->base + 0x02);
  1435. }
  1436. /* stop et all */
  1437. static void isicom_stop(struct tty_struct * tty)
  1438. {
  1439. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1440. if (isicom_paranoia_check(port, tty->name, "isicom_stop"))
  1441. return;
  1442. /* this tells the transmitter not to consider this port for
  1443. data output to the card. */
  1444. port->status &= ~ISI_TXOK;
  1445. }
  1446. /* start et all */
  1447. static void isicom_start(struct tty_struct * tty)
  1448. {
  1449. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1450. if (isicom_paranoia_check(port, tty->name, "isicom_start"))
  1451. return;
  1452. /* this tells the transmitter to consider this port for
  1453. data output to the card. */
  1454. port->status |= ISI_TXOK;
  1455. }
  1456. /* hangup et all */
  1457. static void do_isicom_hangup(void * data)
  1458. {
  1459. struct isi_port * port = (struct isi_port *) data;
  1460. struct tty_struct * tty;
  1461. tty = port->tty;
  1462. if (tty)
  1463. tty_hangup(tty);
  1464. }
  1465. static void isicom_hangup(struct tty_struct * tty)
  1466. {
  1467. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1468. if (isicom_paranoia_check(port, tty->name, "isicom_hangup"))
  1469. return;
  1470. isicom_shutdown_port(port);
  1471. port->count = 0;
  1472. port->flags &= ~ASYNC_NORMAL_ACTIVE;
  1473. port->tty = NULL;
  1474. wake_up_interruptible(&port->open_wait);
  1475. }
  1476. /* flush_buffer et all */
  1477. static void isicom_flush_buffer(struct tty_struct * tty)
  1478. {
  1479. struct isi_port * port = (struct isi_port *) tty->driver_data;
  1480. struct isi_board * card = port->card;
  1481. unsigned long flags;
  1482. if (isicom_paranoia_check(port, tty->name, "isicom_flush_buffer"))
  1483. return;
  1484. spin_lock_irqsave(&card->card_lock, flags);
  1485. port->xmit_cnt = port->xmit_head = port->xmit_tail = 0;
  1486. spin_unlock_irqrestore(&card->card_lock, flags);
  1487. wake_up_interruptible(&tty->write_wait);
  1488. tty_wakeup(tty);
  1489. }
  1490. static int __devinit register_ioregion(void)
  1491. {
  1492. int count, done=0;
  1493. for (count=0; count < BOARD_COUNT; count++ ) {
  1494. if (isi_card[count].base)
  1495. if (!request_region(isi_card[count].base,16,ISICOM_NAME)) {
  1496. printk(KERN_DEBUG "ISICOM: I/O Region 0x%x-0x%x is busy. Card%d will be disabled.\n",
  1497. isi_card[count].base,isi_card[count].base+15,count+1);
  1498. isi_card[count].base=0;
  1499. done++;
  1500. }
  1501. }
  1502. return done;
  1503. }
  1504. static void unregister_ioregion(void)
  1505. {
  1506. int count;
  1507. for (count=0; count < BOARD_COUNT; count++ )
  1508. if (isi_card[count].base) {
  1509. release_region(isi_card[count].base,16);
  1510. #ifdef ISICOM_DEBUG
  1511. printk(KERN_DEBUG "ISICOM: I/O Region 0x%x-0x%x released for Card%d.\n",isi_card[count].base,isi_card[count].base+15,count+1);
  1512. #endif
  1513. }
  1514. }
  1515. static struct tty_operations isicom_ops = {
  1516. .open = isicom_open,
  1517. .close = isicom_close,
  1518. .write = isicom_write,
  1519. .put_char = isicom_put_char,
  1520. .flush_chars = isicom_flush_chars,
  1521. .write_room = isicom_write_room,
  1522. .chars_in_buffer = isicom_chars_in_buffer,
  1523. .ioctl = isicom_ioctl,
  1524. .set_termios = isicom_set_termios,
  1525. .throttle = isicom_throttle,
  1526. .unthrottle = isicom_unthrottle,
  1527. .stop = isicom_stop,
  1528. .start = isicom_start,
  1529. .hangup = isicom_hangup,
  1530. .flush_buffer = isicom_flush_buffer,
  1531. .tiocmget = isicom_tiocmget,
  1532. .tiocmset = isicom_tiocmset,
  1533. };
  1534. static int __devinit register_drivers(void)
  1535. {
  1536. int error;
  1537. /* tty driver structure initialization */
  1538. isicom_normal = alloc_tty_driver(PORT_COUNT);
  1539. if (!isicom_normal)
  1540. return -ENOMEM;
  1541. isicom_normal->owner = THIS_MODULE;
  1542. isicom_normal->name = "ttyM";
  1543. isicom_normal->devfs_name = "isicom/";
  1544. isicom_normal->major = ISICOM_NMAJOR;
  1545. isicom_normal->minor_start = 0;
  1546. isicom_normal->type = TTY_DRIVER_TYPE_SERIAL;
  1547. isicom_normal->subtype = SERIAL_TYPE_NORMAL;
  1548. isicom_normal->init_termios = tty_std_termios;
  1549. isicom_normal->init_termios.c_cflag =
  1550. B9600 | CS8 | CREAD | HUPCL |CLOCAL;
  1551. isicom_normal->flags = TTY_DRIVER_REAL_RAW;
  1552. tty_set_operations(isicom_normal, &isicom_ops);
  1553. if ((error=tty_register_driver(isicom_normal))!=0) {
  1554. printk(KERN_DEBUG "ISICOM: Couldn't register the dialin driver, error=%d\n",
  1555. error);
  1556. put_tty_driver(isicom_normal);
  1557. return error;
  1558. }
  1559. return 0;
  1560. }
  1561. static void unregister_drivers(void)
  1562. {
  1563. int error = tty_unregister_driver(isicom_normal);
  1564. if (error)
  1565. printk(KERN_DEBUG "ISICOM: couldn't unregister normal driver error=%d.\n",error);
  1566. put_tty_driver(isicom_normal);
  1567. }
  1568. static int __devinit register_isr(void)
  1569. {
  1570. int count, done=0;
  1571. unsigned long irqflags;
  1572. for (count=0; count < BOARD_COUNT; count++ ) {
  1573. if (isi_card[count].base) {
  1574. irqflags = (isi_card[count].isa == YES) ?
  1575. SA_INTERRUPT :
  1576. (SA_INTERRUPT | SA_SHIRQ);
  1577. if (request_irq(isi_card[count].irq,
  1578. isicom_interrupt,
  1579. irqflags,
  1580. ISICOM_NAME, &isi_card[count])) {
  1581. printk(KERN_WARNING "ISICOM: Could not"
  1582. " install handler at Irq %d."
  1583. " Card%d will be disabled.\n",
  1584. isi_card[count].irq, count+1);
  1585. release_region(isi_card[count].base,16);
  1586. isi_card[count].base=0;
  1587. }
  1588. else
  1589. done++;
  1590. }
  1591. }
  1592. return done;
  1593. }
  1594. static void __exit unregister_isr(void)
  1595. {
  1596. int count;
  1597. for (count=0; count < BOARD_COUNT; count++ ) {
  1598. if (isi_card[count].base)
  1599. free_irq(isi_card[count].irq, &isi_card[count]);
  1600. }
  1601. }
  1602. static int __devinit isicom_init(void)
  1603. {
  1604. int card, channel, base;
  1605. struct isi_port * port;
  1606. unsigned long page;
  1607. if (!tmp_buf) {
  1608. page = get_zeroed_page(GFP_KERNEL);
  1609. if (!page) {
  1610. #ifdef ISICOM_DEBUG
  1611. printk(KERN_DEBUG "ISICOM: Couldn't allocate page for tmp_buf.\n");
  1612. #else
  1613. printk(KERN_ERR "ISICOM: Not enough memory...\n");
  1614. #endif
  1615. return 0;
  1616. }
  1617. tmp_buf = (unsigned char *) page;
  1618. }
  1619. if (!register_ioregion())
  1620. {
  1621. printk(KERN_ERR "ISICOM: All required I/O space found busy.\n");
  1622. free_page((unsigned long)tmp_buf);
  1623. return 0;
  1624. }
  1625. if (register_drivers())
  1626. {
  1627. unregister_ioregion();
  1628. free_page((unsigned long)tmp_buf);
  1629. return 0;
  1630. }
  1631. if (!register_isr())
  1632. {
  1633. unregister_drivers();
  1634. /* ioports already uregistered in register_isr */
  1635. free_page((unsigned long)tmp_buf);
  1636. return 0;
  1637. }
  1638. memset(isi_ports, 0, sizeof(isi_ports));
  1639. for (card = 0; card < BOARD_COUNT; card++) {
  1640. port = &isi_ports[card * 16];
  1641. isi_card[card].ports = port;
  1642. spin_lock_init(&isi_card[card].card_lock);
  1643. base = isi_card[card].base;
  1644. for (channel = 0; channel < 16; channel++, port++) {
  1645. port->magic = ISICOM_MAGIC;
  1646. port->card = &isi_card[card];
  1647. port->channel = channel;
  1648. port->close_delay = 50 * HZ/100;
  1649. port->closing_wait = 3000 * HZ/100;
  1650. INIT_WORK(&port->hangup_tq, do_isicom_hangup, port);
  1651. INIT_WORK(&port->bh_tqueue, isicom_bottomhalf, port);
  1652. port->status = 0;
  1653. init_waitqueue_head(&port->open_wait);
  1654. init_waitqueue_head(&port->close_wait);
  1655. /* . . . */
  1656. }
  1657. }
  1658. return 1;
  1659. }
  1660. /*
  1661. * Insmod can set static symbols so keep these static
  1662. */
  1663. static int io[4];
  1664. static int irq[4];
  1665. MODULE_AUTHOR("MultiTech");
  1666. MODULE_DESCRIPTION("Driver for the ISI series of cards by MultiTech");
  1667. MODULE_LICENSE("GPL");
  1668. module_param_array(io, int, NULL, 0);
  1669. MODULE_PARM_DESC(io, "I/O ports for the cards");
  1670. module_param_array(irq, int, NULL, 0);
  1671. MODULE_PARM_DESC(irq, "Interrupts for the cards");
  1672. static int __devinit isicom_setup(void)
  1673. {
  1674. struct pci_dev *dev = NULL;
  1675. int retval, card, idx, count;
  1676. unsigned char pciirq;
  1677. unsigned int ioaddr;
  1678. card = 0;
  1679. for(idx=0; idx < BOARD_COUNT; idx++) {
  1680. if (io[idx]) {
  1681. isi_card[idx].base=io[idx];
  1682. isi_card[idx].irq=irq[idx];
  1683. isi_card[idx].isa=YES;
  1684. card++;
  1685. }
  1686. else {
  1687. isi_card[idx].base = 0;
  1688. isi_card[idx].irq = 0;
  1689. }
  1690. }
  1691. for (idx=0 ;idx < card; idx++) {
  1692. if (!((isi_card[idx].irq==2)||(isi_card[idx].irq==3)||
  1693. (isi_card[idx].irq==4)||(isi_card[idx].irq==5)||
  1694. (isi_card[idx].irq==7)||(isi_card[idx].irq==10)||
  1695. (isi_card[idx].irq==11)||(isi_card[idx].irq==12)||
  1696. (isi_card[idx].irq==15))) {
  1697. if (isi_card[idx].base) {
  1698. printk(KERN_ERR "ISICOM: Irq %d unsupported. Disabling Card%d...\n",
  1699. isi_card[idx].irq, idx+1);
  1700. isi_card[idx].base=0;
  1701. card--;
  1702. }
  1703. }
  1704. }
  1705. if (card < BOARD_COUNT) {
  1706. for (idx=0; idx < DEVID_COUNT; idx++) {
  1707. dev = NULL;
  1708. for (;;){
  1709. if (!(dev = pci_find_device(VENDOR_ID, isicom_pci_tbl[idx].device, dev)))
  1710. break;
  1711. if (card >= BOARD_COUNT)
  1712. break;
  1713. if (pci_enable_device(dev))
  1714. break;
  1715. /* found a PCI ISI card! */
  1716. ioaddr = pci_resource_start (dev, 3); /* i.e at offset 0x1c in the
  1717. * PCI configuration register
  1718. * space.
  1719. */
  1720. pciirq = dev->irq;
  1721. printk(KERN_INFO "ISI PCI Card(Device ID 0x%x)\n", isicom_pci_tbl[idx].device);
  1722. /*
  1723. * allot the first empty slot in the array
  1724. */
  1725. for (count=0; count < BOARD_COUNT; count++) {
  1726. if (isi_card[count].base == 0) {
  1727. isi_card[count].base = ioaddr;
  1728. isi_card[count].irq = pciirq;
  1729. isi_card[count].isa = NO;
  1730. card++;
  1731. break;
  1732. }
  1733. }
  1734. }
  1735. if (card >= BOARD_COUNT) break;
  1736. }
  1737. }
  1738. if (!(isi_card[0].base || isi_card[1].base || isi_card[2].base || isi_card[3].base)) {
  1739. printk(KERN_ERR "ISICOM: No valid card configuration. Driver cannot be initialized...\n");
  1740. return -EIO;
  1741. }
  1742. retval = misc_register(&isiloader_device);
  1743. if (retval < 0) {
  1744. printk(KERN_ERR "ISICOM: Unable to register firmware loader driver.\n");
  1745. return retval;
  1746. }
  1747. if (!isicom_init()) {
  1748. if (misc_deregister(&isiloader_device))
  1749. printk(KERN_ERR "ISICOM: Unable to unregister Firmware Loader driver\n");
  1750. return -EIO;
  1751. }
  1752. init_timer(&tx);
  1753. tx.expires = jiffies + 1;
  1754. tx.data = 0;
  1755. tx.function = isicom_tx;
  1756. re_schedule = 1;
  1757. add_timer(&tx);
  1758. return 0;
  1759. }
  1760. static void __exit isicom_exit(void)
  1761. {
  1762. re_schedule = 0;
  1763. /* FIXME */
  1764. msleep(1000);
  1765. unregister_isr();
  1766. unregister_drivers();
  1767. unregister_ioregion();
  1768. if(tmp_buf)
  1769. free_page((unsigned long)tmp_buf);
  1770. if (misc_deregister(&isiloader_device))
  1771. printk(KERN_ERR "ISICOM: Unable to unregister Firmware Loader driver\n");
  1772. }
  1773. module_init(isicom_setup);
  1774. module_exit(isicom_exit);