hisax_fcpcipnp.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027
  1. /*
  2. * Driver for AVM Fritz!PCI, Fritz!PCI v2, Fritz!PnP ISDN cards
  3. *
  4. * Author Kai Germaschewski
  5. * Copyright 2001 by Kai Germaschewski <kai.germaschewski@gmx.de>
  6. * 2001 by Karsten Keil <keil@isdn4linux.de>
  7. *
  8. * based upon Karsten Keil's original avm_pci.c driver
  9. *
  10. * This software may be used and distributed according to the terms
  11. * of the GNU General Public License, incorporated herein by reference.
  12. *
  13. * Thanks to Wizard Computersysteme GmbH, Bremervoerde and
  14. * SoHaNet Technology GmbH, Berlin
  15. * for supporting the development of this driver
  16. */
  17. /* TODO:
  18. *
  19. * o POWER PC
  20. * o clean up debugging
  21. * o tx_skb at PH_DEACTIVATE time
  22. */
  23. #include <linux/module.h>
  24. #include <linux/init.h>
  25. #include <linux/pci.h>
  26. #include <linux/isapnp.h>
  27. #include <linux/kmod.h>
  28. #include <linux/slab.h>
  29. #include <linux/skbuff.h>
  30. #include <linux/netdevice.h>
  31. #include <linux/delay.h>
  32. #include <asm/io.h>
  33. #include "hisax_fcpcipnp.h"
  34. // debugging cruft
  35. #define __debug_variable debug
  36. #include "hisax_debug.h"
  37. #ifdef CONFIG_HISAX_DEBUG
  38. static int debug = 0;
  39. /* static int hdlcfifosize = 32; */
  40. module_param(debug, int, 0);
  41. /* module_param(hdlcfifosize, int, 0); */
  42. #endif
  43. MODULE_AUTHOR("Kai Germaschewski <kai.germaschewski@gmx.de>/Karsten Keil <kkeil@suse.de>");
  44. MODULE_DESCRIPTION("AVM Fritz!PCI/PnP ISDN driver");
  45. static struct pci_device_id fcpci_ids[] = {
  46. { .vendor = PCI_VENDOR_ID_AVM,
  47. .device = PCI_DEVICE_ID_AVM_A1,
  48. .subvendor = PCI_ANY_ID,
  49. .subdevice = PCI_ANY_ID,
  50. .driver_data = (unsigned long) "Fritz!Card PCI",
  51. },
  52. { .vendor = PCI_VENDOR_ID_AVM,
  53. .device = PCI_DEVICE_ID_AVM_A1_V2,
  54. .subvendor = PCI_ANY_ID,
  55. .subdevice = PCI_ANY_ID,
  56. .driver_data = (unsigned long) "Fritz!Card PCI v2" },
  57. {}
  58. };
  59. MODULE_DEVICE_TABLE(pci, fcpci_ids);
  60. #ifdef __ISAPNP__
  61. static struct pnp_device_id fcpnp_ids[] __devinitdata = {
  62. {
  63. .id = "AVM0900",
  64. .driver_data = (unsigned long) "Fritz!Card PnP",
  65. },
  66. };
  67. MODULE_DEVICE_TABLE(isapnp, fcpnp_ids);
  68. #endif
  69. static int protocol = 2; /* EURO-ISDN Default */
  70. module_param(protocol, int, 0);
  71. MODULE_LICENSE("GPL");
  72. // ----------------------------------------------------------------------
  73. #define AVM_INDEX 0x04
  74. #define AVM_DATA 0x10
  75. #define AVM_IDX_HDLC_1 0x00
  76. #define AVM_IDX_HDLC_2 0x01
  77. #define AVM_IDX_ISAC_FIFO 0x02
  78. #define AVM_IDX_ISAC_REG_LOW 0x04
  79. #define AVM_IDX_ISAC_REG_HIGH 0x06
  80. #define AVM_STATUS0 0x02
  81. #define AVM_STATUS0_IRQ_ISAC 0x01
  82. #define AVM_STATUS0_IRQ_HDLC 0x02
  83. #define AVM_STATUS0_IRQ_TIMER 0x04
  84. #define AVM_STATUS0_IRQ_MASK 0x07
  85. #define AVM_STATUS0_RESET 0x01
  86. #define AVM_STATUS0_DIS_TIMER 0x02
  87. #define AVM_STATUS0_RES_TIMER 0x04
  88. #define AVM_STATUS0_ENA_IRQ 0x08
  89. #define AVM_STATUS0_TESTBIT 0x10
  90. #define AVM_STATUS1 0x03
  91. #define AVM_STATUS1_ENA_IOM 0x80
  92. #define HDLC_FIFO 0x0
  93. #define HDLC_STATUS 0x4
  94. #define HDLC_CTRL 0x4
  95. #define HDLC_MODE_ITF_FLG 0x01
  96. #define HDLC_MODE_TRANS 0x02
  97. #define HDLC_MODE_CCR_7 0x04
  98. #define HDLC_MODE_CCR_16 0x08
  99. #define HDLC_MODE_TESTLOOP 0x80
  100. #define HDLC_INT_XPR 0x80
  101. #define HDLC_INT_XDU 0x40
  102. #define HDLC_INT_RPR 0x20
  103. #define HDLC_INT_MASK 0xE0
  104. #define HDLC_STAT_RME 0x01
  105. #define HDLC_STAT_RDO 0x10
  106. #define HDLC_STAT_CRCVFRRAB 0x0E
  107. #define HDLC_STAT_CRCVFR 0x06
  108. #define HDLC_STAT_RML_MASK 0xff00
  109. #define HDLC_CMD_XRS 0x80
  110. #define HDLC_CMD_XME 0x01
  111. #define HDLC_CMD_RRS 0x20
  112. #define HDLC_CMD_XML_MASK 0xff00
  113. #define AVM_HDLC_FIFO_1 0x10
  114. #define AVM_HDLC_FIFO_2 0x18
  115. #define AVM_HDLC_STATUS_1 0x14
  116. #define AVM_HDLC_STATUS_2 0x1c
  117. #define AVM_ISACSX_INDEX 0x04
  118. #define AVM_ISACSX_DATA 0x08
  119. // ----------------------------------------------------------------------
  120. // Fritz!PCI
  121. static unsigned char fcpci_read_isac(struct isac *isac, unsigned char offset)
  122. {
  123. struct fritz_adapter *adapter = isac->priv;
  124. unsigned char idx = (offset > 0x2f) ?
  125. AVM_IDX_ISAC_REG_HIGH : AVM_IDX_ISAC_REG_LOW;
  126. unsigned char val;
  127. unsigned long flags;
  128. spin_lock_irqsave(&adapter->hw_lock, flags);
  129. outb(idx, adapter->io + AVM_INDEX);
  130. val = inb(adapter->io + AVM_DATA + (offset & 0xf));
  131. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  132. DBG(0x1000, " port %#x, value %#x",
  133. offset, val);
  134. return val;
  135. }
  136. static void fcpci_write_isac(struct isac *isac, unsigned char offset,
  137. unsigned char value)
  138. {
  139. struct fritz_adapter *adapter = isac->priv;
  140. unsigned char idx = (offset > 0x2f) ?
  141. AVM_IDX_ISAC_REG_HIGH : AVM_IDX_ISAC_REG_LOW;
  142. unsigned long flags;
  143. DBG(0x1000, " port %#x, value %#x",
  144. offset, value);
  145. spin_lock_irqsave(&adapter->hw_lock, flags);
  146. outb(idx, adapter->io + AVM_INDEX);
  147. outb(value, adapter->io + AVM_DATA + (offset & 0xf));
  148. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  149. }
  150. static void fcpci_read_isac_fifo(struct isac *isac, unsigned char * data,
  151. int size)
  152. {
  153. struct fritz_adapter *adapter = isac->priv;
  154. unsigned long flags;
  155. spin_lock_irqsave(&adapter->hw_lock, flags);
  156. outb(AVM_IDX_ISAC_FIFO, adapter->io + AVM_INDEX);
  157. insb(adapter->io + AVM_DATA, data, size);
  158. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  159. }
  160. static void fcpci_write_isac_fifo(struct isac *isac, unsigned char * data,
  161. int size)
  162. {
  163. struct fritz_adapter *adapter = isac->priv;
  164. unsigned long flags;
  165. spin_lock_irqsave(&adapter->hw_lock, flags);
  166. outb(AVM_IDX_ISAC_FIFO, adapter->io + AVM_INDEX);
  167. outsb(adapter->io + AVM_DATA, data, size);
  168. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  169. }
  170. static u32 fcpci_read_hdlc_status(struct fritz_adapter *adapter, int nr)
  171. {
  172. u32 val;
  173. int idx = nr ? AVM_IDX_HDLC_2 : AVM_IDX_HDLC_1;
  174. unsigned long flags;
  175. spin_lock_irqsave(&adapter->hw_lock, flags);
  176. outl(idx, adapter->io + AVM_INDEX);
  177. val = inl(adapter->io + AVM_DATA + HDLC_STATUS);
  178. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  179. return val;
  180. }
  181. static void __fcpci_write_ctrl(struct fritz_bcs *bcs, int which)
  182. {
  183. struct fritz_adapter *adapter = bcs->adapter;
  184. int idx = bcs->channel ? AVM_IDX_HDLC_2 : AVM_IDX_HDLC_1;
  185. DBG(0x40, "hdlc %c wr%x ctrl %x",
  186. 'A' + bcs->channel, which, bcs->ctrl.ctrl);
  187. outl(idx, adapter->io + AVM_INDEX);
  188. outl(bcs->ctrl.ctrl, adapter->io + AVM_DATA + HDLC_CTRL);
  189. }
  190. static void fcpci_write_ctrl(struct fritz_bcs *bcs, int which)
  191. {
  192. struct fritz_adapter *adapter = bcs->adapter;
  193. unsigned long flags;
  194. spin_lock_irqsave(&adapter->hw_lock, flags);
  195. __fcpci_write_ctrl(bcs, which);
  196. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  197. }
  198. // ----------------------------------------------------------------------
  199. // Fritz!PCI v2
  200. static unsigned char fcpci2_read_isac(struct isac *isac, unsigned char offset)
  201. {
  202. struct fritz_adapter *adapter = isac->priv;
  203. unsigned char val;
  204. unsigned long flags;
  205. spin_lock_irqsave(&adapter->hw_lock, flags);
  206. outl(offset, adapter->io + AVM_ISACSX_INDEX);
  207. val = inl(adapter->io + AVM_ISACSX_DATA);
  208. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  209. DBG(0x1000, " port %#x, value %#x",
  210. offset, val);
  211. return val;
  212. }
  213. static void fcpci2_write_isac(struct isac *isac, unsigned char offset,
  214. unsigned char value)
  215. {
  216. struct fritz_adapter *adapter = isac->priv;
  217. unsigned long flags;
  218. DBG(0x1000, " port %#x, value %#x",
  219. offset, value);
  220. spin_lock_irqsave(&adapter->hw_lock, flags);
  221. outl(offset, adapter->io + AVM_ISACSX_INDEX);
  222. outl(value, adapter->io + AVM_ISACSX_DATA);
  223. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  224. }
  225. static void fcpci2_read_isac_fifo(struct isac *isac, unsigned char * data,
  226. int size)
  227. {
  228. struct fritz_adapter *adapter = isac->priv;
  229. int i;
  230. unsigned long flags;
  231. spin_lock_irqsave(&adapter->hw_lock, flags);
  232. outl(0, adapter->io + AVM_ISACSX_INDEX);
  233. for (i = 0; i < size; i++)
  234. data[i] = inl(adapter->io + AVM_ISACSX_DATA);
  235. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  236. }
  237. static void fcpci2_write_isac_fifo(struct isac *isac, unsigned char * data,
  238. int size)
  239. {
  240. struct fritz_adapter *adapter = isac->priv;
  241. int i;
  242. unsigned long flags;
  243. spin_lock_irqsave(&adapter->hw_lock, flags);
  244. outl(0, adapter->io + AVM_ISACSX_INDEX);
  245. for (i = 0; i < size; i++)
  246. outl(data[i], adapter->io + AVM_ISACSX_DATA);
  247. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  248. }
  249. static u32 fcpci2_read_hdlc_status(struct fritz_adapter *adapter, int nr)
  250. {
  251. int offset = nr ? AVM_HDLC_STATUS_2 : AVM_HDLC_STATUS_1;
  252. return inl(adapter->io + offset);
  253. }
  254. static void fcpci2_write_ctrl(struct fritz_bcs *bcs, int which)
  255. {
  256. struct fritz_adapter *adapter = bcs->adapter;
  257. int offset = bcs->channel ? AVM_HDLC_STATUS_2 : AVM_HDLC_STATUS_1;
  258. DBG(0x40, "hdlc %c wr%x ctrl %x",
  259. 'A' + bcs->channel, which, bcs->ctrl.ctrl);
  260. outl(bcs->ctrl.ctrl, adapter->io + offset);
  261. }
  262. // ----------------------------------------------------------------------
  263. // Fritz!PnP (ISAC access as for Fritz!PCI)
  264. static u32 fcpnp_read_hdlc_status(struct fritz_adapter *adapter, int nr)
  265. {
  266. unsigned char idx = nr ? AVM_IDX_HDLC_2 : AVM_IDX_HDLC_1;
  267. u32 val;
  268. unsigned long flags;
  269. spin_lock_irqsave(&adapter->hw_lock, flags);
  270. outb(idx, adapter->io + AVM_INDEX);
  271. val = inb(adapter->io + AVM_DATA + HDLC_STATUS);
  272. if (val & HDLC_INT_RPR)
  273. val |= inb(adapter->io + AVM_DATA + HDLC_STATUS + 1) << 8;
  274. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  275. return val;
  276. }
  277. static void __fcpnp_write_ctrl(struct fritz_bcs *bcs, int which)
  278. {
  279. struct fritz_adapter *adapter = bcs->adapter;
  280. unsigned char idx = bcs->channel ? AVM_IDX_HDLC_2 : AVM_IDX_HDLC_1;
  281. DBG(0x40, "hdlc %c wr%x ctrl %x",
  282. 'A' + bcs->channel, which, bcs->ctrl.ctrl);
  283. outb(idx, adapter->io + AVM_INDEX);
  284. if (which & 4)
  285. outb(bcs->ctrl.sr.mode,
  286. adapter->io + AVM_DATA + HDLC_STATUS + 2);
  287. if (which & 2)
  288. outb(bcs->ctrl.sr.xml,
  289. adapter->io + AVM_DATA + HDLC_STATUS + 1);
  290. if (which & 1)
  291. outb(bcs->ctrl.sr.cmd,
  292. adapter->io + AVM_DATA + HDLC_STATUS + 0);
  293. }
  294. static void fcpnp_write_ctrl(struct fritz_bcs *bcs, int which)
  295. {
  296. struct fritz_adapter *adapter = bcs->adapter;
  297. unsigned long flags;
  298. spin_lock_irqsave(&adapter->hw_lock, flags);
  299. __fcpnp_write_ctrl(bcs, which);
  300. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  301. }
  302. // ----------------------------------------------------------------------
  303. static inline void B_L1L2(struct fritz_bcs *bcs, int pr, void *arg)
  304. {
  305. struct hisax_if *ifc = (struct hisax_if *) &bcs->b_if;
  306. DBG(2, "pr %#x", pr);
  307. ifc->l1l2(ifc, pr, arg);
  308. }
  309. static void hdlc_fill_fifo(struct fritz_bcs *bcs)
  310. {
  311. struct fritz_adapter *adapter = bcs->adapter;
  312. struct sk_buff *skb = bcs->tx_skb;
  313. int count;
  314. unsigned long flags;
  315. unsigned char *p;
  316. DBG(0x40, "hdlc_fill_fifo");
  317. if (skb->len == 0)
  318. BUG();
  319. bcs->ctrl.sr.cmd &= ~HDLC_CMD_XME;
  320. if (bcs->tx_skb->len > bcs->fifo_size) {
  321. count = bcs->fifo_size;
  322. } else {
  323. count = bcs->tx_skb->len;
  324. if (bcs->mode != L1_MODE_TRANS)
  325. bcs->ctrl.sr.cmd |= HDLC_CMD_XME;
  326. }
  327. DBG(0x40, "hdlc_fill_fifo %d/%d", count, bcs->tx_skb->len);
  328. p = bcs->tx_skb->data;
  329. skb_pull(bcs->tx_skb, count);
  330. bcs->tx_cnt += count;
  331. bcs->ctrl.sr.xml = ((count == bcs->fifo_size) ? 0 : count);
  332. switch (adapter->type) {
  333. case AVM_FRITZ_PCI:
  334. spin_lock_irqsave(&adapter->hw_lock, flags);
  335. // sets the correct AVM_INDEX, too
  336. __fcpci_write_ctrl(bcs, 3);
  337. outsl(adapter->io + AVM_DATA + HDLC_FIFO,
  338. p, (count + 3) / 4);
  339. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  340. break;
  341. case AVM_FRITZ_PCIV2:
  342. fcpci2_write_ctrl(bcs, 3);
  343. outsl(adapter->io +
  344. (bcs->channel ? AVM_HDLC_FIFO_2 : AVM_HDLC_FIFO_1),
  345. p, (count + 3) / 4);
  346. break;
  347. case AVM_FRITZ_PNP:
  348. spin_lock_irqsave(&adapter->hw_lock, flags);
  349. // sets the correct AVM_INDEX, too
  350. __fcpnp_write_ctrl(bcs, 3);
  351. outsb(adapter->io + AVM_DATA, p, count);
  352. spin_unlock_irqrestore(&adapter->hw_lock, flags);
  353. break;
  354. }
  355. }
  356. static inline void hdlc_empty_fifo(struct fritz_bcs *bcs, int count)
  357. {
  358. struct fritz_adapter *adapter = bcs->adapter;
  359. unsigned char *p;
  360. unsigned char idx = bcs->channel ? AVM_IDX_HDLC_2 : AVM_IDX_HDLC_1;
  361. DBG(0x10, "hdlc_empty_fifo %d", count);
  362. if (bcs->rcvidx + count > HSCX_BUFMAX) {
  363. DBG(0x10, "hdlc_empty_fifo: incoming packet too large");
  364. return;
  365. }
  366. p = bcs->rcvbuf + bcs->rcvidx;
  367. bcs->rcvidx += count;
  368. switch (adapter->type) {
  369. case AVM_FRITZ_PCI:
  370. spin_lock(&adapter->hw_lock);
  371. outl(idx, adapter->io + AVM_INDEX);
  372. insl(adapter->io + AVM_DATA + HDLC_FIFO,
  373. p, (count + 3) / 4);
  374. spin_unlock(&adapter->hw_lock);
  375. break;
  376. case AVM_FRITZ_PCIV2:
  377. insl(adapter->io +
  378. (bcs->channel ? AVM_HDLC_FIFO_2 : AVM_HDLC_FIFO_1),
  379. p, (count + 3) / 4);
  380. break;
  381. case AVM_FRITZ_PNP:
  382. spin_lock(&adapter->hw_lock);
  383. outb(idx, adapter->io + AVM_INDEX);
  384. insb(adapter->io + AVM_DATA, p, count);
  385. spin_unlock(&adapter->hw_lock);
  386. break;
  387. }
  388. }
  389. static inline void hdlc_rpr_irq(struct fritz_bcs *bcs, u32 stat)
  390. {
  391. struct fritz_adapter *adapter = bcs->adapter;
  392. struct sk_buff *skb;
  393. int len;
  394. if (stat & HDLC_STAT_RDO) {
  395. DBG(0x10, "RDO");
  396. bcs->ctrl.sr.xml = 0;
  397. bcs->ctrl.sr.cmd |= HDLC_CMD_RRS;
  398. adapter->write_ctrl(bcs, 1);
  399. bcs->ctrl.sr.cmd &= ~HDLC_CMD_RRS;
  400. adapter->write_ctrl(bcs, 1);
  401. bcs->rcvidx = 0;
  402. return;
  403. }
  404. len = (stat & HDLC_STAT_RML_MASK) >> 8;
  405. if (len == 0)
  406. len = bcs->fifo_size;
  407. hdlc_empty_fifo(bcs, len);
  408. if ((stat & HDLC_STAT_RME) || (bcs->mode == L1_MODE_TRANS)) {
  409. if (((stat & HDLC_STAT_CRCVFRRAB)== HDLC_STAT_CRCVFR) ||
  410. (bcs->mode == L1_MODE_TRANS)) {
  411. skb = dev_alloc_skb(bcs->rcvidx);
  412. if (!skb) {
  413. printk(KERN_WARNING "HDLC: receive out of memory\n");
  414. } else {
  415. memcpy(skb_put(skb, bcs->rcvidx), bcs->rcvbuf,
  416. bcs->rcvidx);
  417. DBG_SKB(1, skb);
  418. B_L1L2(bcs, PH_DATA | INDICATION, skb);
  419. }
  420. bcs->rcvidx = 0;
  421. } else {
  422. DBG(0x10, "ch%d invalid frame %#x",
  423. bcs->channel, stat);
  424. bcs->rcvidx = 0;
  425. }
  426. }
  427. }
  428. static inline void hdlc_xdu_irq(struct fritz_bcs *bcs)
  429. {
  430. struct fritz_adapter *adapter = bcs->adapter;
  431. /* Here we lost an TX interrupt, so
  432. * restart transmitting the whole frame.
  433. */
  434. bcs->ctrl.sr.xml = 0;
  435. bcs->ctrl.sr.cmd |= HDLC_CMD_XRS;
  436. adapter->write_ctrl(bcs, 1);
  437. bcs->ctrl.sr.cmd &= ~HDLC_CMD_XRS;
  438. if (!bcs->tx_skb) {
  439. DBG(0x10, "XDU without skb");
  440. adapter->write_ctrl(bcs, 1);
  441. return;
  442. }
  443. /* only hdlc restarts the frame, transparent mode must continue */
  444. if (bcs->mode == L1_MODE_HDLC) {
  445. skb_push(bcs->tx_skb, bcs->tx_cnt);
  446. bcs->tx_cnt = 0;
  447. }
  448. }
  449. static inline void hdlc_xpr_irq(struct fritz_bcs *bcs)
  450. {
  451. struct sk_buff *skb;
  452. skb = bcs->tx_skb;
  453. if (!skb)
  454. return;
  455. if (skb->len) {
  456. hdlc_fill_fifo(bcs);
  457. return;
  458. }
  459. bcs->tx_cnt = 0;
  460. bcs->tx_skb = NULL;
  461. B_L1L2(bcs, PH_DATA | CONFIRM, (void *) skb->truesize);
  462. dev_kfree_skb_irq(skb);
  463. }
  464. static void hdlc_irq_one(struct fritz_bcs *bcs, u32 stat)
  465. {
  466. DBG(0x10, "ch%d stat %#x", bcs->channel, stat);
  467. if (stat & HDLC_INT_RPR) {
  468. DBG(0x10, "RPR");
  469. hdlc_rpr_irq(bcs, stat);
  470. }
  471. if (stat & HDLC_INT_XDU) {
  472. DBG(0x10, "XDU");
  473. hdlc_xdu_irq(bcs);
  474. hdlc_xpr_irq(bcs);
  475. return;
  476. }
  477. if (stat & HDLC_INT_XPR) {
  478. DBG(0x10, "XPR");
  479. hdlc_xpr_irq(bcs);
  480. }
  481. }
  482. static inline void hdlc_irq(struct fritz_adapter *adapter)
  483. {
  484. int nr;
  485. u32 stat;
  486. for (nr = 0; nr < 2; nr++) {
  487. stat = adapter->read_hdlc_status(adapter, nr);
  488. DBG(0x10, "HDLC %c stat %#x", 'A' + nr, stat);
  489. if (stat & HDLC_INT_MASK)
  490. hdlc_irq_one(&adapter->bcs[nr], stat);
  491. }
  492. }
  493. static void modehdlc(struct fritz_bcs *bcs, int mode)
  494. {
  495. struct fritz_adapter *adapter = bcs->adapter;
  496. DBG(0x40, "hdlc %c mode %d --> %d",
  497. 'A' + bcs->channel, bcs->mode, mode);
  498. if (bcs->mode == mode)
  499. return;
  500. bcs->fifo_size = 32;
  501. bcs->ctrl.ctrl = 0;
  502. bcs->ctrl.sr.cmd = HDLC_CMD_XRS | HDLC_CMD_RRS;
  503. switch (mode) {
  504. case L1_MODE_NULL:
  505. bcs->ctrl.sr.mode = HDLC_MODE_TRANS;
  506. adapter->write_ctrl(bcs, 5);
  507. break;
  508. case L1_MODE_TRANS:
  509. case L1_MODE_HDLC:
  510. bcs->rcvidx = 0;
  511. bcs->tx_cnt = 0;
  512. bcs->tx_skb = NULL;
  513. if (mode == L1_MODE_TRANS) {
  514. bcs->ctrl.sr.mode = HDLC_MODE_TRANS;
  515. } else {
  516. bcs->ctrl.sr.mode = HDLC_MODE_ITF_FLG;
  517. }
  518. adapter->write_ctrl(bcs, 5);
  519. bcs->ctrl.sr.cmd = HDLC_CMD_XRS;
  520. adapter->write_ctrl(bcs, 1);
  521. bcs->ctrl.sr.cmd = 0;
  522. break;
  523. }
  524. bcs->mode = mode;
  525. }
  526. static void fritz_b_l2l1(struct hisax_if *ifc, int pr, void *arg)
  527. {
  528. struct fritz_bcs *bcs = ifc->priv;
  529. struct sk_buff *skb = arg;
  530. int mode;
  531. DBG(0x10, "pr %#x", pr);
  532. switch (pr) {
  533. case PH_DATA | REQUEST:
  534. if (bcs->tx_skb)
  535. BUG();
  536. bcs->tx_skb = skb;
  537. DBG_SKB(1, skb);
  538. hdlc_fill_fifo(bcs);
  539. break;
  540. case PH_ACTIVATE | REQUEST:
  541. mode = (int) arg;
  542. DBG(4,"B%d,PH_ACTIVATE_REQUEST %d", bcs->channel + 1, mode);
  543. modehdlc(bcs, mode);
  544. B_L1L2(bcs, PH_ACTIVATE | INDICATION, NULL);
  545. break;
  546. case PH_DEACTIVATE | REQUEST:
  547. DBG(4,"B%d,PH_DEACTIVATE_REQUEST", bcs->channel + 1);
  548. modehdlc(bcs, L1_MODE_NULL);
  549. B_L1L2(bcs, PH_DEACTIVATE | INDICATION, NULL);
  550. break;
  551. }
  552. }
  553. // ----------------------------------------------------------------------
  554. static irqreturn_t
  555. fcpci2_irq(int intno, void *dev, struct pt_regs *regs)
  556. {
  557. struct fritz_adapter *adapter = dev;
  558. unsigned char val;
  559. val = inb(adapter->io + AVM_STATUS0);
  560. if (!(val & AVM_STATUS0_IRQ_MASK))
  561. /* hopefully a shared IRQ reqest */
  562. return IRQ_NONE;
  563. DBG(2, "STATUS0 %#x", val);
  564. if (val & AVM_STATUS0_IRQ_ISAC)
  565. isacsx_irq(&adapter->isac);
  566. if (val & AVM_STATUS0_IRQ_HDLC)
  567. hdlc_irq(adapter);
  568. if (val & AVM_STATUS0_IRQ_ISAC)
  569. isacsx_irq(&adapter->isac);
  570. return IRQ_HANDLED;
  571. }
  572. static irqreturn_t
  573. fcpci_irq(int intno, void *dev, struct pt_regs *regs)
  574. {
  575. struct fritz_adapter *adapter = dev;
  576. unsigned char sval;
  577. sval = inb(adapter->io + 2);
  578. if ((sval & AVM_STATUS0_IRQ_MASK) == AVM_STATUS0_IRQ_MASK)
  579. /* possibly a shared IRQ reqest */
  580. return IRQ_NONE;
  581. DBG(2, "sval %#x", sval);
  582. if (!(sval & AVM_STATUS0_IRQ_ISAC))
  583. isac_irq(&adapter->isac);
  584. if (!(sval & AVM_STATUS0_IRQ_HDLC))
  585. hdlc_irq(adapter);
  586. return IRQ_HANDLED;
  587. }
  588. // ----------------------------------------------------------------------
  589. static inline void fcpci2_init(struct fritz_adapter *adapter)
  590. {
  591. outb(AVM_STATUS0_RES_TIMER, adapter->io + AVM_STATUS0);
  592. outb(AVM_STATUS0_ENA_IRQ, adapter->io + AVM_STATUS0);
  593. }
  594. static inline void fcpci_init(struct fritz_adapter *adapter)
  595. {
  596. outb(AVM_STATUS0_DIS_TIMER | AVM_STATUS0_RES_TIMER |
  597. AVM_STATUS0_ENA_IRQ, adapter->io + AVM_STATUS0);
  598. outb(AVM_STATUS1_ENA_IOM | adapter->irq,
  599. adapter->io + AVM_STATUS1);
  600. mdelay(10);
  601. }
  602. // ----------------------------------------------------------------------
  603. static int __devinit fcpcipnp_setup(struct fritz_adapter *adapter)
  604. {
  605. u32 val = 0;
  606. int retval;
  607. DBG(1,"");
  608. isac_init(&adapter->isac); // FIXME is this okay now
  609. retval = -EBUSY;
  610. if (!request_region(adapter->io, 32, "fcpcipnp"))
  611. goto err;
  612. switch (adapter->type) {
  613. case AVM_FRITZ_PCIV2:
  614. retval = request_irq(adapter->irq, fcpci2_irq, SA_SHIRQ,
  615. "fcpcipnp", adapter);
  616. break;
  617. case AVM_FRITZ_PCI:
  618. retval = request_irq(adapter->irq, fcpci_irq, SA_SHIRQ,
  619. "fcpcipnp", adapter);
  620. break;
  621. case AVM_FRITZ_PNP:
  622. retval = request_irq(adapter->irq, fcpci_irq, 0,
  623. "fcpcipnp", adapter);
  624. break;
  625. }
  626. if (retval)
  627. goto err_region;
  628. switch (adapter->type) {
  629. case AVM_FRITZ_PCIV2:
  630. case AVM_FRITZ_PCI:
  631. val = inl(adapter->io);
  632. break;
  633. case AVM_FRITZ_PNP:
  634. val = inb(adapter->io);
  635. val |= inb(adapter->io + 1) << 8;
  636. break;
  637. }
  638. DBG(1, "stat %#x Class %X Rev %d",
  639. val, val & 0xff, (val>>8) & 0xff);
  640. spin_lock_init(&adapter->hw_lock);
  641. adapter->isac.priv = adapter;
  642. switch (adapter->type) {
  643. case AVM_FRITZ_PCIV2:
  644. adapter->isac.read_isac = &fcpci2_read_isac;
  645. adapter->isac.write_isac = &fcpci2_write_isac;
  646. adapter->isac.read_isac_fifo = &fcpci2_read_isac_fifo;
  647. adapter->isac.write_isac_fifo = &fcpci2_write_isac_fifo;
  648. adapter->read_hdlc_status = &fcpci2_read_hdlc_status;
  649. adapter->write_ctrl = &fcpci2_write_ctrl;
  650. break;
  651. case AVM_FRITZ_PCI:
  652. adapter->isac.read_isac = &fcpci_read_isac;
  653. adapter->isac.write_isac = &fcpci_write_isac;
  654. adapter->isac.read_isac_fifo = &fcpci_read_isac_fifo;
  655. adapter->isac.write_isac_fifo = &fcpci_write_isac_fifo;
  656. adapter->read_hdlc_status = &fcpci_read_hdlc_status;
  657. adapter->write_ctrl = &fcpci_write_ctrl;
  658. break;
  659. case AVM_FRITZ_PNP:
  660. adapter->isac.read_isac = &fcpci_read_isac;
  661. adapter->isac.write_isac = &fcpci_write_isac;
  662. adapter->isac.read_isac_fifo = &fcpci_read_isac_fifo;
  663. adapter->isac.write_isac_fifo = &fcpci_write_isac_fifo;
  664. adapter->read_hdlc_status = &fcpnp_read_hdlc_status;
  665. adapter->write_ctrl = &fcpnp_write_ctrl;
  666. break;
  667. }
  668. // Reset
  669. outb(0, adapter->io + AVM_STATUS0);
  670. mdelay(10);
  671. outb(AVM_STATUS0_RESET, adapter->io + AVM_STATUS0);
  672. mdelay(10);
  673. outb(0, adapter->io + AVM_STATUS0);
  674. mdelay(10);
  675. switch (adapter->type) {
  676. case AVM_FRITZ_PCIV2:
  677. fcpci2_init(adapter);
  678. isacsx_setup(&adapter->isac);
  679. break;
  680. case AVM_FRITZ_PCI:
  681. case AVM_FRITZ_PNP:
  682. fcpci_init(adapter);
  683. isac_setup(&adapter->isac);
  684. break;
  685. }
  686. val = adapter->read_hdlc_status(adapter, 0);
  687. DBG(0x20, "HDLC A STA %x", val);
  688. val = adapter->read_hdlc_status(adapter, 1);
  689. DBG(0x20, "HDLC B STA %x", val);
  690. adapter->bcs[0].mode = -1;
  691. adapter->bcs[1].mode = -1;
  692. modehdlc(&adapter->bcs[0], L1_MODE_NULL);
  693. modehdlc(&adapter->bcs[1], L1_MODE_NULL);
  694. return 0;
  695. err_region:
  696. release_region(adapter->io, 32);
  697. err:
  698. return retval;
  699. }
  700. static void __devexit fcpcipnp_release(struct fritz_adapter *adapter)
  701. {
  702. DBG(1,"");
  703. outb(0, adapter->io + AVM_STATUS0);
  704. free_irq(adapter->irq, adapter);
  705. release_region(adapter->io, 32);
  706. }
  707. // ----------------------------------------------------------------------
  708. static struct fritz_adapter * __devinit
  709. new_adapter(void)
  710. {
  711. struct fritz_adapter *adapter;
  712. struct hisax_b_if *b_if[2];
  713. int i;
  714. adapter = kmalloc(sizeof(struct fritz_adapter), GFP_KERNEL);
  715. if (!adapter)
  716. return NULL;
  717. memset(adapter, 0, sizeof(struct fritz_adapter));
  718. adapter->isac.hisax_d_if.owner = THIS_MODULE;
  719. adapter->isac.hisax_d_if.ifc.priv = &adapter->isac;
  720. adapter->isac.hisax_d_if.ifc.l2l1 = isac_d_l2l1;
  721. for (i = 0; i < 2; i++) {
  722. adapter->bcs[i].adapter = adapter;
  723. adapter->bcs[i].channel = i;
  724. adapter->bcs[i].b_if.ifc.priv = &adapter->bcs[i];
  725. adapter->bcs[i].b_if.ifc.l2l1 = fritz_b_l2l1;
  726. }
  727. for (i = 0; i < 2; i++)
  728. b_if[i] = &adapter->bcs[i].b_if;
  729. hisax_register(&adapter->isac.hisax_d_if, b_if, "fcpcipnp", protocol);
  730. return adapter;
  731. }
  732. static void delete_adapter(struct fritz_adapter *adapter)
  733. {
  734. hisax_unregister(&adapter->isac.hisax_d_if);
  735. kfree(adapter);
  736. }
  737. static int __devinit fcpci_probe(struct pci_dev *pdev,
  738. const struct pci_device_id *ent)
  739. {
  740. struct fritz_adapter *adapter;
  741. int retval;
  742. retval = -ENOMEM;
  743. adapter = new_adapter();
  744. if (!adapter)
  745. goto err;
  746. pci_set_drvdata(pdev, adapter);
  747. if (pdev->device == PCI_DEVICE_ID_AVM_A1_V2)
  748. adapter->type = AVM_FRITZ_PCIV2;
  749. else
  750. adapter->type = AVM_FRITZ_PCI;
  751. retval = pci_enable_device(pdev);
  752. if (retval)
  753. goto err_free;
  754. adapter->io = pci_resource_start(pdev, 1);
  755. adapter->irq = pdev->irq;
  756. printk(KERN_INFO "hisax_fcpcipnp: found adapter %s at %s\n",
  757. (char *) ent->driver_data, pci_name(pdev));
  758. retval = fcpcipnp_setup(adapter);
  759. if (retval)
  760. goto err_free;
  761. return 0;
  762. err_free:
  763. delete_adapter(adapter);
  764. err:
  765. return retval;
  766. }
  767. #ifdef __ISAPNP__
  768. static int __devinit fcpnp_probe(struct pnp_dev *pdev, const struct pnp_device_id *dev_id)
  769. {
  770. struct fritz_adapter *adapter;
  771. int retval;
  772. if (!pdev)
  773. return(-ENODEV);
  774. retval = -ENOMEM;
  775. adapter = new_adapter();
  776. if (!adapter)
  777. goto err;
  778. pnp_set_drvdata(pdev, adapter);
  779. adapter->type = AVM_FRITZ_PNP;
  780. pnp_disable_dev(pdev);
  781. retval = pnp_activate_dev(pdev);
  782. if (retval < 0) {
  783. printk(KERN_WARNING "%s: pnp_activate_dev(%s) ret(%d)\n", __FUNCTION__,
  784. (char *)dev_id->driver_data, retval);
  785. goto err_free;
  786. }
  787. adapter->io = pnp_port_start(pdev, 0);
  788. adapter->irq = pnp_irq(pdev, 0);
  789. printk(KERN_INFO "hisax_fcpcipnp: found adapter %s at IO %#x irq %d\n",
  790. (char *) dev_id->driver_data, adapter->io, adapter->irq);
  791. retval = fcpcipnp_setup(adapter);
  792. if (retval)
  793. goto err_free;
  794. return 0;
  795. err_free:
  796. delete_adapter(adapter);
  797. err:
  798. return retval;
  799. }
  800. static void __devexit fcpnp_remove(struct pnp_dev *pdev)
  801. {
  802. struct fritz_adapter *adapter = pnp_get_drvdata(pdev);
  803. if (adapter) {
  804. fcpcipnp_release(adapter);
  805. delete_adapter(adapter);
  806. }
  807. pnp_disable_dev(pdev);
  808. }
  809. static struct pnp_driver fcpnp_driver = {
  810. .name = "fcpnp",
  811. .probe = fcpnp_probe,
  812. .remove = __devexit_p(fcpnp_remove),
  813. .id_table = fcpnp_ids,
  814. };
  815. #endif
  816. static void __devexit fcpci_remove(struct pci_dev *pdev)
  817. {
  818. struct fritz_adapter *adapter = pci_get_drvdata(pdev);
  819. fcpcipnp_release(adapter);
  820. pci_disable_device(pdev);
  821. delete_adapter(adapter);
  822. }
  823. static struct pci_driver fcpci_driver = {
  824. .name = "fcpci",
  825. .probe = fcpci_probe,
  826. .remove = __devexit_p(fcpci_remove),
  827. .id_table = fcpci_ids,
  828. };
  829. static int __init hisax_fcpcipnp_init(void)
  830. {
  831. int retval;
  832. printk(KERN_INFO "hisax_fcpcipnp: Fritz!Card PCI/PCIv2/PnP ISDN driver v0.0.1\n");
  833. retval = pci_register_driver(&fcpci_driver);
  834. if (retval)
  835. goto out;
  836. #ifdef __ISAPNP__
  837. retval = pnp_register_driver(&fcpnp_driver);
  838. if (retval < 0)
  839. goto out_unregister_pci;
  840. #endif
  841. return 0;
  842. out_unregister_pci:
  843. pci_unregister_driver(&fcpci_driver);
  844. out:
  845. return retval;
  846. }
  847. static void __exit hisax_fcpcipnp_exit(void)
  848. {
  849. #ifdef __ISAPNP__
  850. pnp_unregister_driver(&fcpnp_driver);
  851. #endif
  852. pci_unregister_driver(&fcpci_driver);
  853. }
  854. module_init(hisax_fcpcipnp_init);
  855. module_exit(hisax_fcpcipnp_exit);