avmcard.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581
  1. /* $Id: avmcard.h,v 1.1.4.1.2.1 2001/12/21 15:00:17 kai Exp $
  2. *
  3. * Copyright 1999 by Carsten Paeth <calle@calle.de>
  4. *
  5. * This software may be used and distributed according to the terms
  6. * of the GNU General Public License, incorporated herein by reference.
  7. *
  8. */
  9. #ifndef _AVMCARD_H_
  10. #define _AVMCARD_H_
  11. #include <linux/spinlock.h>
  12. #include <linux/list.h>
  13. #include <linux/interrupt.h>
  14. #define AVMB1_PORTLEN 0x1f
  15. #define AVM_MAXVERSION 8
  16. #define AVM_NCCI_PER_CHANNEL 4
  17. /*
  18. * Versions
  19. */
  20. #define VER_DRIVER 0
  21. #define VER_CARDTYPE 1
  22. #define VER_HWID 2
  23. #define VER_SERIAL 3
  24. #define VER_OPTION 4
  25. #define VER_PROTO 5
  26. #define VER_PROFILE 6
  27. #define VER_CAPI 7
  28. enum avmcardtype {
  29. avm_b1isa,
  30. avm_b1pci,
  31. avm_b1pcmcia,
  32. avm_m1,
  33. avm_m2,
  34. avm_t1isa,
  35. avm_t1pci,
  36. avm_c4,
  37. avm_c2
  38. };
  39. typedef struct avmcard_dmabuf {
  40. long size;
  41. u8 *dmabuf;
  42. dma_addr_t dmaaddr;
  43. } avmcard_dmabuf;
  44. typedef struct avmcard_dmainfo {
  45. u32 recvlen;
  46. avmcard_dmabuf recvbuf;
  47. avmcard_dmabuf sendbuf;
  48. struct sk_buff_head send_queue;
  49. struct pci_dev *pcidev;
  50. } avmcard_dmainfo;
  51. typedef struct avmctrl_info {
  52. char cardname[32];
  53. int versionlen;
  54. char versionbuf[1024];
  55. char *version[AVM_MAXVERSION];
  56. char infobuf[128]; /* for function procinfo */
  57. struct avmcard *card;
  58. struct capi_ctr capi_ctrl;
  59. struct list_head ncci_head;
  60. } avmctrl_info;
  61. typedef struct avmcard {
  62. char name[32];
  63. spinlock_t lock;
  64. unsigned int port;
  65. unsigned irq;
  66. unsigned long membase;
  67. enum avmcardtype cardtype;
  68. unsigned char revision;
  69. unsigned char class;
  70. int cardnr; /* for t1isa */
  71. char msgbuf[128]; /* capimsg msg part */
  72. char databuf[2048]; /* capimsg data part */
  73. void __iomem *mbase;
  74. volatile u32 csr;
  75. avmcard_dmainfo *dma;
  76. struct avmctrl_info *ctrlinfo;
  77. u_int nr_controllers;
  78. u_int nlogcontr;
  79. struct list_head list;
  80. } avmcard;
  81. extern int b1_irq_table[16];
  82. /*
  83. * LLI Messages to the ISDN-ControllerISDN Controller
  84. */
  85. #define SEND_POLL 0x72 /*
  86. * after load <- RECEIVE_POLL
  87. */
  88. #define SEND_INIT 0x11 /*
  89. * first message <- RECEIVE_INIT
  90. * int32 NumApplications int32
  91. * NumNCCIs int32 BoardNumber
  92. */
  93. #define SEND_REGISTER 0x12 /*
  94. * register an application int32
  95. * ApplIDId int32 NumMessages
  96. * int32 NumB3Connections int32
  97. * NumB3Blocks int32 B3Size
  98. *
  99. * AnzB3Connection != 0 &&
  100. * AnzB3Blocks >= 1 && B3Size >= 1
  101. */
  102. #define SEND_RELEASE 0x14 /*
  103. * deregister an application int32
  104. * ApplID
  105. */
  106. #define SEND_MESSAGE 0x15 /*
  107. * send capi-message int32 length
  108. * capi-data ...
  109. */
  110. #define SEND_DATA_B3_REQ 0x13 /*
  111. * send capi-data-message int32
  112. * MsgLength capi-data ... int32
  113. * B3Length data ....
  114. */
  115. #define SEND_CONFIG 0x21 /*
  116. */
  117. #define SEND_POLLACK 0x73 /* T1 Watchdog */
  118. /*
  119. * LLI Messages from the ISDN-ControllerISDN Controller
  120. */
  121. #define RECEIVE_POLL 0x32 /*
  122. * <- after SEND_POLL
  123. */
  124. #define RECEIVE_INIT 0x27 /*
  125. * <- after SEND_INIT int32 length
  126. * byte total length b1struct board
  127. * driver revision b1struct card
  128. * type b1struct reserved b1struct
  129. * serial number b1struct driver
  130. * capability b1struct d-channel
  131. * protocol b1struct CAPI-2.0
  132. * profile b1struct capi version
  133. */
  134. #define RECEIVE_MESSAGE 0x21 /*
  135. * <- after SEND_MESSAGE int32
  136. * AppllID int32 Length capi-data
  137. * ....
  138. */
  139. #define RECEIVE_DATA_B3_IND 0x22 /*
  140. * received data int32 AppllID
  141. * int32 Length capi-data ...
  142. * int32 B3Length data ...
  143. */
  144. #define RECEIVE_START 0x23 /*
  145. * Handshake
  146. */
  147. #define RECEIVE_STOP 0x24 /*
  148. * Handshake
  149. */
  150. #define RECEIVE_NEW_NCCI 0x25 /*
  151. * int32 AppllID int32 NCCI int32
  152. * WindowSize
  153. */
  154. #define RECEIVE_FREE_NCCI 0x26 /*
  155. * int32 AppllID int32 NCCI
  156. */
  157. #define RECEIVE_RELEASE 0x26 /*
  158. * int32 AppllID int32 0xffffffff
  159. */
  160. #define RECEIVE_TASK_READY 0x31 /*
  161. * int32 tasknr
  162. * int32 Length Taskname ...
  163. */
  164. #define RECEIVE_DEBUGMSG 0x71 /*
  165. * int32 Length message
  166. *
  167. */
  168. #define RECEIVE_POLLDWORD 0x75 /* t1pci in dword mode */
  169. #define WRITE_REGISTER 0x00
  170. #define READ_REGISTER 0x01
  171. /*
  172. * port offsets
  173. */
  174. #define B1_READ 0x00
  175. #define B1_WRITE 0x01
  176. #define B1_INSTAT 0x02
  177. #define B1_OUTSTAT 0x03
  178. #define B1_ANALYSE 0x04
  179. #define B1_REVISION 0x05
  180. #define B1_RESET 0x10
  181. #define B1_STAT0(cardtype) ((cardtype) == avm_m1 ? 0x81200000l : 0x80A00000l)
  182. #define B1_STAT1(cardtype) (0x80E00000l)
  183. /* ---------------------------------------------------------------- */
  184. static inline unsigned char b1outp(unsigned int base,
  185. unsigned short offset,
  186. unsigned char value)
  187. {
  188. outb(value, base + offset);
  189. return inb(base + B1_ANALYSE);
  190. }
  191. static inline int b1_rx_full(unsigned int base)
  192. {
  193. return inb(base + B1_INSTAT) & 0x1;
  194. }
  195. static inline unsigned char b1_get_byte(unsigned int base)
  196. {
  197. unsigned long stop = jiffies + 1 * HZ; /* maximum wait time 1 sec */
  198. while (!b1_rx_full(base) && time_before(jiffies, stop));
  199. if (b1_rx_full(base))
  200. return inb(base + B1_READ);
  201. printk(KERN_CRIT "b1lli(0x%x): rx not full after 1 second\n", base);
  202. return 0;
  203. }
  204. static inline unsigned int b1_get_word(unsigned int base)
  205. {
  206. unsigned int val = 0;
  207. val |= b1_get_byte(base);
  208. val |= (b1_get_byte(base) << 8);
  209. val |= (b1_get_byte(base) << 16);
  210. val |= (b1_get_byte(base) << 24);
  211. return val;
  212. }
  213. static inline int b1_tx_empty(unsigned int base)
  214. {
  215. return inb(base + B1_OUTSTAT) & 0x1;
  216. }
  217. static inline void b1_put_byte(unsigned int base, unsigned char val)
  218. {
  219. while (!b1_tx_empty(base));
  220. b1outp(base, B1_WRITE, val);
  221. }
  222. static inline int b1_save_put_byte(unsigned int base, unsigned char val)
  223. {
  224. unsigned long stop = jiffies + 2 * HZ;
  225. while (!b1_tx_empty(base) && time_before(jiffies, stop));
  226. if (!b1_tx_empty(base)) return -1;
  227. b1outp(base, B1_WRITE, val);
  228. return 0;
  229. }
  230. static inline void b1_put_word(unsigned int base, unsigned int val)
  231. {
  232. b1_put_byte(base, val & 0xff);
  233. b1_put_byte(base, (val >> 8) & 0xff);
  234. b1_put_byte(base, (val >> 16) & 0xff);
  235. b1_put_byte(base, (val >> 24) & 0xff);
  236. }
  237. static inline unsigned int b1_get_slice(unsigned int base,
  238. unsigned char *dp)
  239. {
  240. unsigned int len, i;
  241. len = i = b1_get_word(base);
  242. while (i-- > 0) *dp++ = b1_get_byte(base);
  243. return len;
  244. }
  245. static inline void b1_put_slice(unsigned int base,
  246. unsigned char *dp, unsigned int len)
  247. {
  248. unsigned i = len;
  249. b1_put_word(base, i);
  250. while (i-- > 0)
  251. b1_put_byte(base, *dp++);
  252. }
  253. static void b1_wr_reg(unsigned int base,
  254. unsigned int reg,
  255. unsigned int value)
  256. {
  257. b1_put_byte(base, WRITE_REGISTER);
  258. b1_put_word(base, reg);
  259. b1_put_word(base, value);
  260. }
  261. static inline unsigned int b1_rd_reg(unsigned int base,
  262. unsigned int reg)
  263. {
  264. b1_put_byte(base, READ_REGISTER);
  265. b1_put_word(base, reg);
  266. return b1_get_word(base);
  267. }
  268. static inline void b1_reset(unsigned int base)
  269. {
  270. b1outp(base, B1_RESET, 0);
  271. mdelay(55 * 2); /* 2 TIC's */
  272. b1outp(base, B1_RESET, 1);
  273. mdelay(55 * 2); /* 2 TIC's */
  274. b1outp(base, B1_RESET, 0);
  275. mdelay(55 * 2); /* 2 TIC's */
  276. }
  277. static inline unsigned char b1_disable_irq(unsigned int base)
  278. {
  279. return b1outp(base, B1_INSTAT, 0x00);
  280. }
  281. /* ---------------------------------------------------------------- */
  282. static inline void b1_set_test_bit(unsigned int base,
  283. enum avmcardtype cardtype,
  284. int onoff)
  285. {
  286. b1_wr_reg(base, B1_STAT0(cardtype), onoff ? 0x21 : 0x20);
  287. }
  288. static inline int b1_get_test_bit(unsigned int base,
  289. enum avmcardtype cardtype)
  290. {
  291. return (b1_rd_reg(base, B1_STAT0(cardtype)) & 0x01) != 0;
  292. }
  293. /* ---------------------------------------------------------------- */
  294. #define T1_FASTLINK 0x00
  295. #define T1_SLOWLINK 0x08
  296. #define T1_READ B1_READ
  297. #define T1_WRITE B1_WRITE
  298. #define T1_INSTAT B1_INSTAT
  299. #define T1_OUTSTAT B1_OUTSTAT
  300. #define T1_IRQENABLE 0x05
  301. #define T1_FIFOSTAT 0x06
  302. #define T1_RESETLINK 0x10
  303. #define T1_ANALYSE 0x11
  304. #define T1_IRQMASTER 0x12
  305. #define T1_IDENT 0x17
  306. #define T1_RESETBOARD 0x1f
  307. #define T1F_IREADY 0x01
  308. #define T1F_IHALF 0x02
  309. #define T1F_IFULL 0x04
  310. #define T1F_IEMPTY 0x08
  311. #define T1F_IFLAGS 0xF0
  312. #define T1F_OREADY 0x10
  313. #define T1F_OHALF 0x20
  314. #define T1F_OEMPTY 0x40
  315. #define T1F_OFULL 0x80
  316. #define T1F_OFLAGS 0xF0
  317. /* there are HEMA cards with 1k and 4k FIFO out */
  318. #define FIFO_OUTBSIZE 256
  319. #define FIFO_INPBSIZE 512
  320. #define HEMA_VERSION_ID 0
  321. #define HEMA_PAL_ID 0
  322. static inline void t1outp(unsigned int base,
  323. unsigned short offset,
  324. unsigned char value)
  325. {
  326. outb(value, base + offset);
  327. }
  328. static inline unsigned char t1inp(unsigned int base,
  329. unsigned short offset)
  330. {
  331. return inb(base + offset);
  332. }
  333. static inline int t1_isfastlink(unsigned int base)
  334. {
  335. return (inb(base + T1_IDENT) & ~0x82) == 1;
  336. }
  337. static inline unsigned char t1_fifostatus(unsigned int base)
  338. {
  339. return inb(base + T1_FIFOSTAT);
  340. }
  341. static inline unsigned int t1_get_slice(unsigned int base,
  342. unsigned char *dp)
  343. {
  344. unsigned int len, i;
  345. #ifdef FASTLINK_DEBUG
  346. unsigned wcnt = 0, bcnt = 0;
  347. #endif
  348. len = i = b1_get_word(base);
  349. if (t1_isfastlink(base)) {
  350. int status;
  351. while (i > 0) {
  352. status = t1_fifostatus(base) & (T1F_IREADY | T1F_IHALF);
  353. if (i >= FIFO_INPBSIZE) status |= T1F_IFULL;
  354. switch (status) {
  355. case T1F_IREADY | T1F_IHALF | T1F_IFULL:
  356. insb(base + B1_READ, dp, FIFO_INPBSIZE);
  357. dp += FIFO_INPBSIZE;
  358. i -= FIFO_INPBSIZE;
  359. #ifdef FASTLINK_DEBUG
  360. wcnt += FIFO_INPBSIZE;
  361. #endif
  362. break;
  363. case T1F_IREADY | T1F_IHALF:
  364. insb(base + B1_READ, dp, i);
  365. #ifdef FASTLINK_DEBUG
  366. wcnt += i;
  367. #endif
  368. dp += i;
  369. i = 0;
  370. break;
  371. default:
  372. *dp++ = b1_get_byte(base);
  373. i--;
  374. #ifdef FASTLINK_DEBUG
  375. bcnt++;
  376. #endif
  377. break;
  378. }
  379. }
  380. #ifdef FASTLINK_DEBUG
  381. if (wcnt)
  382. printk(KERN_DEBUG "b1lli(0x%x): get_slice l=%d w=%d b=%d\n",
  383. base, len, wcnt, bcnt);
  384. #endif
  385. } else {
  386. while (i-- > 0)
  387. *dp++ = b1_get_byte(base);
  388. }
  389. return len;
  390. }
  391. static inline void t1_put_slice(unsigned int base,
  392. unsigned char *dp, unsigned int len)
  393. {
  394. unsigned i = len;
  395. b1_put_word(base, i);
  396. if (t1_isfastlink(base)) {
  397. int status;
  398. while (i > 0) {
  399. status = t1_fifostatus(base) & (T1F_OREADY | T1F_OHALF);
  400. if (i >= FIFO_OUTBSIZE) status |= T1F_OEMPTY;
  401. switch (status) {
  402. case T1F_OREADY | T1F_OHALF | T1F_OEMPTY:
  403. outsb(base + B1_WRITE, dp, FIFO_OUTBSIZE);
  404. dp += FIFO_OUTBSIZE;
  405. i -= FIFO_OUTBSIZE;
  406. break;
  407. case T1F_OREADY | T1F_OHALF:
  408. outsb(base + B1_WRITE, dp, i);
  409. dp += i;
  410. i = 0;
  411. break;
  412. default:
  413. b1_put_byte(base, *dp++);
  414. i--;
  415. break;
  416. }
  417. }
  418. } else {
  419. while (i-- > 0)
  420. b1_put_byte(base, *dp++);
  421. }
  422. }
  423. static inline void t1_disable_irq(unsigned int base)
  424. {
  425. t1outp(base, T1_IRQMASTER, 0x00);
  426. }
  427. static inline void t1_reset(unsigned int base)
  428. {
  429. /* reset T1 Controller */
  430. b1_reset(base);
  431. /* disable irq on HEMA */
  432. t1outp(base, B1_INSTAT, 0x00);
  433. t1outp(base, B1_OUTSTAT, 0x00);
  434. t1outp(base, T1_IRQMASTER, 0x00);
  435. /* reset HEMA board configuration */
  436. t1outp(base, T1_RESETBOARD, 0xf);
  437. }
  438. static inline void b1_setinterrupt(unsigned int base, unsigned irq,
  439. enum avmcardtype cardtype)
  440. {
  441. switch (cardtype) {
  442. case avm_t1isa:
  443. t1outp(base, B1_INSTAT, 0x00);
  444. t1outp(base, B1_INSTAT, 0x02);
  445. t1outp(base, T1_IRQMASTER, 0x08);
  446. break;
  447. case avm_b1isa:
  448. b1outp(base, B1_INSTAT, 0x00);
  449. b1outp(base, B1_RESET, b1_irq_table[irq]);
  450. b1outp(base, B1_INSTAT, 0x02);
  451. break;
  452. default:
  453. case avm_m1:
  454. case avm_m2:
  455. case avm_b1pci:
  456. b1outp(base, B1_INSTAT, 0x00);
  457. b1outp(base, B1_RESET, 0xf0);
  458. b1outp(base, B1_INSTAT, 0x02);
  459. break;
  460. case avm_c4:
  461. case avm_t1pci:
  462. b1outp(base, B1_RESET, 0xf0);
  463. break;
  464. }
  465. }
  466. /* b1.c */
  467. avmcard *b1_alloc_card(int nr_controllers);
  468. void b1_free_card(avmcard *card);
  469. int b1_detect(unsigned int base, enum avmcardtype cardtype);
  470. void b1_getrevision(avmcard *card);
  471. int b1_load_t4file(avmcard *card, capiloaddatapart *t4file);
  472. int b1_load_config(avmcard *card, capiloaddatapart *config);
  473. int b1_loaded(avmcard *card);
  474. int b1_load_firmware(struct capi_ctr *ctrl, capiloaddata *data);
  475. void b1_reset_ctr(struct capi_ctr *ctrl);
  476. void b1_register_appl(struct capi_ctr *ctrl, u16 appl,
  477. capi_register_params *rp);
  478. void b1_release_appl(struct capi_ctr *ctrl, u16 appl);
  479. u16 b1_send_message(struct capi_ctr *ctrl, struct sk_buff *skb);
  480. void b1_parse_version(avmctrl_info *card);
  481. irqreturn_t b1_interrupt(int interrupt, void *devptr);
  482. extern const struct file_operations b1ctl_proc_fops;
  483. avmcard_dmainfo *avmcard_dma_alloc(char *name, struct pci_dev *,
  484. long rsize, long ssize);
  485. void avmcard_dma_free(avmcard_dmainfo *);
  486. /* b1dma.c */
  487. int b1pciv4_detect(avmcard *card);
  488. int t1pci_detect(avmcard *card);
  489. void b1dma_reset(avmcard *card);
  490. irqreturn_t b1dma_interrupt(int interrupt, void *devptr);
  491. int b1dma_load_firmware(struct capi_ctr *ctrl, capiloaddata *data);
  492. void b1dma_reset_ctr(struct capi_ctr *ctrl);
  493. void b1dma_remove_ctr(struct capi_ctr *ctrl);
  494. void b1dma_register_appl(struct capi_ctr *ctrl,
  495. u16 appl,
  496. capi_register_params *rp);
  497. void b1dma_release_appl(struct capi_ctr *ctrl, u16 appl);
  498. u16 b1dma_send_message(struct capi_ctr *ctrl, struct sk_buff *skb);
  499. extern const struct file_operations b1dmactl_proc_fops;
  500. #endif /* _AVMCARD_H_ */