hisax_fcpcipnp.c 25 KB

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