48 #include <linux/module.h>
49 #include <linux/pci.h>
52 #include <linux/slab.h>
56 static const char *hfcpci_revision =
"2.0";
62 static unsigned long hfc_jiffies;
120 #define HFC_CFG_MASTER 1
121 #define HFC_CFG_SLAVE 2
122 #define HFC_CFG_PCM 3
123 #define HFC_CFG_2HFC 4
124 #define HFC_CFG_SLAVEHFC 5
125 #define HFC_CFG_NEG_F0 6
126 #define HFC_CFG_SW_DD_DU 7
128 #define FLG_HFC_TIMER_T1 16
129 #define FLG_HFC_TIMER_T3 17
131 #define NT_T1_COUNT 1120
132 #define NT_T3_COUNT 31
133 #define CLKDEL_TE 0x0e
134 #define CLKDEL_NT 0x6c
153 enable_hwirq(
struct hfc_pci *hc)
160 disable_hwirq(
struct hfc_pci *hc)
170 release_io_hfcpci(
struct hfc_pci *hc)
183 hfcpci_setmode(
struct hfc_pci *hc)
206 reset_hfcpci(
struct hfc_pci *hc)
230 while (cnt < 50000) {
239 hc->
hw.fifo_en = 0x30;
304 hfcpci_Timer(
struct hfc_pci *hc)
322 (hc->
bch[0].nr & channel))
325 (hc->
bch[1].nr & channel))
348 hc->
hw.fifo_en ^= fifo_state;
350 hc->
hw.last_bfifo_cnt[fifo] = 0;
357 hc->
hw.fifo_en |= fifo_state;
364 static void hfcpci_clear_fifo_tx(
struct hfc_pci *hc,
int fifo)
377 hc->
hw.fifo_en ^= fifo_state;
381 "z1(%x) z2(%x) state(%x)\n",
382 fifo, bzt->
f1, bzt->
f2,
391 hc->
hw.fifo_en |= fifo_state;
393 if (hc->
bch[fifo].debug & DEBUG_HW_BCHANNEL)
395 "hfcpci_clear_fifo_tx%d f1(%x) f2(%x) z1(%x) z2(%x)\n",
396 fifo, bzt->
f1, bzt->
f2,
414 zp = &bz->
za[bz->
f2];
423 "invalid length %d or crc\n", count);
424 #ifdef ERROR_STATISTIC
446 memcpy(ptr, ptr1, maxlen);
464 receive_dmsg(
struct hfc_pci *hc)
483 "hfcpci recd f1(%d) f2(%d) z1(%x) z2(%x) cnt(%d)\n",
493 "empty_fifo hfcpci paket inv. len "
497 #ifdef ERROR_STATISTIC
509 "HFC-PCI: D receive out of memory\n");
524 memcpy(ptr, ptr1, maxlen);
546 hfcpci_empty_fifo_trans(
struct bchannel *bch,
struct bzfifo *rxbz,
549 __le16 *z1r, *z2r, *z1t, *z2t;
550 int new_z2, fcnt_rx, fcnt_tx, maxlen;
582 pr_warning(
"B%d: No bufferspace for %d bytes\n",
594 memcpy(ptr, ptr1, maxlen);
600 memcpy(ptr, ptr1, fcnt_rx);
611 main_rec_hfcpci(
struct bchannel *bch)
615 int receive = 0, count = 5;
616 struct bzfifo *txbz, *rxbz;
620 if ((bch->
nr & 2) && (!hc->
hw.bswapped)) {
622 txbz = &((
union fifo_area *)(hc->
hw.fifos))->b_chans.txbz_b2;
627 txbz = &((
union fifo_area *)(hc->
hw.fifos))->b_chans.txbz_b1;
633 if (rxbz->
f1 != rxbz->
f2) {
634 if (bch->
debug & DEBUG_HW_BCHANNEL)
636 bch->
nr, rxbz->
f1, rxbz->
f2);
637 zp = &rxbz->
za[rxbz->
f2];
643 if (bch->
debug & DEBUG_HW_BCHANNEL)
645 "hfcpci rec ch(%x) z1(%x) z2(%x) cnt(%d)\n",
648 hfcpci_empty_bfifo(bch, rxbz, bdata, rcnt);
649 rcnt = rxbz->
f1 - rxbz->
f2;
652 if (hc->
hw.last_bfifo_cnt[real_fifo] > rcnt + 1) {
654 hfcpci_clear_fifo_rx(hc, real_fifo);
656 hc->
hw.last_bfifo_cnt[real_fifo] = rcnt;
662 hfcpci_empty_fifo_trans(bch, rxbz, txbz, bdata);
666 if (count && receive)
675 hfcpci_fill_dfifo(
struct hfc_pci *hc)
697 fcnt = df->
f1 - df->
f2;
703 "hfcpci_fill_Dfifo more as 14 frames\n");
704 #ifdef ERROR_STATISTIC
718 if (count > maxlen) {
752 hfcpci_fill_fifo(
struct bchannel *bch)
772 if ((bch->
nr & 2) && (!hc->
hw.bswapped)) {
774 bdata = ((
union fifo_area *)(hc->
hw.fifos))->b_chans.txdat_b2;
777 bdata = ((
union fifo_area *)(hc->
hw.fifos))->b_chans.txdat_b1;
783 if (bch->
debug & DEBUG_HW_BCHANNEL)
785 "cnt(%d) z1(%x) z2(%x)\n", bch->
nr, count,
803 "fcnt(%d) maxl(%d) nz1(%x) dst(%p)\n",
804 fcnt, maxlen, new_z1, dst);
823 if (count > (
poll << 1) - fcnt)
824 count = (
poll << 1) - fcnt;
839 "maxl(%d) nz1(%x) dst(%p)\n",
840 fcnt, maxlen, new_z1, dst);
855 dev_kfree_skb(bch->
tx_skb);
860 if (bch->
debug & DEBUG_HW_BCHANNEL)
862 "%s: ch(%x) f1(%d) f2(%d) z1(f1)(%x)\n",
863 __func__, bch->
nr, bz->
f1, bz->
f2,
865 fcnt = bz->
f1 - bz->
f2;
869 if (bch->
debug & DEBUG_HW_BCHANNEL)
871 "hfcpci_fill_Bfifo more as 14 frames\n");
880 if (bch->
debug & DEBUG_HW_BCHANNEL)
882 bch->
nr, count, maxlen);
884 if (maxlen < count) {
885 if (bch->
debug & DEBUG_HW_BCHANNEL)
911 dev_kfree_skb(bch->
tx_skb);
926 __func__, dch->
state);
927 switch (dch->
state) {
952 handle_nt_timer3(
struct dchannel *dch) {
974 __func__, dch->
state);
975 switch (dch->
state) {
977 if (hc->
hw.nt_timer < 0) {
989 }
else if (hc->
hw.nt_timer == 0) {
1006 hc->
hw.nt_timer = 0;
1019 hc->
hw.nt_timer = 0;
1029 handle_nt_timer3(dch);
1052 hc->
hw.nt_timer < 0)
1053 handle_nt_timer3(dch);
1092 dev_kfree_skb(dch->
tx_skb);
1097 dev_kfree_skb(dch->
rx_skb);
1133 hfcpci_fill_fifo(bch);
1136 dev_kfree_skb(bch->
tx_skb);
1138 hfcpci_fill_fifo(bch);
1146 hfcpci_fill_dfifo(dch->
hw);
1149 dev_kfree_skb(dch->
tx_skb);
1151 hfcpci_fill_dfifo(dch->
hw);
1156 hfcpci_int(
int intno,
void *
dev_id)
1163 spin_lock(&hc->
lock);
1164 if (!(hc->
hw.int_m2 & 0x08)) {
1165 spin_unlock(&hc->
lock);
1173 "HFC-PCI: stat(%02x) s1(%02x)\n", stat, val);
1176 spin_unlock(&hc->
lock);
1183 val &= hc->
hw.int_m1;
1188 hc->
dch.state, exval);
1189 hc->
dch.state = exval;
1195 if ((--hc->
hw.nt_timer) < 0)
1202 bch = Sel_BCS(hc, hc->
hw.bswapped ? 2 : 1);
1204 main_rec_hfcpci(bch);
1205 else if (hc->
dch.debug)
1209 bch = Sel_BCS(hc, 2);
1211 main_rec_hfcpci(bch);
1212 else if (hc->
dch.debug)
1216 bch = Sel_BCS(hc, hc->
hw.bswapped ? 2 : 1);
1219 else if (hc->
dch.debug)
1223 bch = Sel_BCS(hc, 2);
1226 else if (hc->
dch.debug)
1236 spin_unlock(&hc->
lock);
1244 hfcpci_dbusy_timer(
struct hfc_pci *hc)
1256 u_char rx_slot = 0, tx_slot = 0, pcm_mode;
1258 if (bch->
debug & DEBUG_HW_BCHANNEL)
1260 "HFCPCI bchannel protocol %x-->%x ch %x-->%x\n",
1261 bch->
state, protocol, bch->
nr, bc);
1264 pcm_mode = (bc >> 24) & 0xff;
1268 "%s: pcm channel id without HFC_CFG_PCM\n",
1270 rx_slot = (bc >> 8) & 0xff;
1271 tx_slot = (bc >> 16) & 0xff;
1277 hc->
hw.bswapped = 0;
1278 hc->
hw.sctrl_e &= ~0x80;
1282 hc->
hw.bswapped = 1;
1283 hc->
hw.sctrl_e |= 0x80;
1285 hc->
hw.bswapped = 0;
1286 hc->
hw.sctrl_e &= ~0x80;
1290 hc->
hw.bswapped = 0;
1291 hc->
hw.sctrl_e &= ~0x80;
1317 #ifdef REVERSE_BITORDER
1319 hc->
hw.cirm &= 0x7f;
1321 hc->
hw.cirm &= 0xbf;
1331 hfcpci_clear_fifo_rx(hc, (fifo2 & 2) ? 1 : 0);
1332 hfcpci_clear_fifo_tx(hc, (fifo2 & 2) ? 1 : 0);
1336 #ifdef REVERSE_BITORDER
1337 hc->
hw.cirm |= 0x80;
1342 #ifdef REVERSE_BITORDER
1343 hc->
hw.cirm |= 0x40;
1352 hc->
hw.conn &= ~0x18;
1359 hc->
hw.conn &= ~0x03;
1366 hfcpci_clear_fifo_rx(hc, (fifo2 & 2) ? 1 : 0);
1367 hfcpci_clear_fifo_tx(hc, (fifo2 & 2) ? 1 : 0);
1376 hc->
hw.last_bfifo_cnt[1] = 0;
1381 hc->
hw.conn &= ~0x18;
1383 hc->
hw.last_bfifo_cnt[0] = 0;
1388 hc->
hw.conn &= ~0x03;
1411 hc->
hw.conn &= 0xc7;
1412 hc->
hw.conn |= 0x08;
1420 hc->
hw.conn &= 0xf8;
1421 hc->
hw.conn |= 0x01;
1437 #ifdef REVERSE_BITORDER
1444 set_hfcpci_rxtest(
struct bchannel *bch,
int protocol,
int chan)
1448 if (bch->
debug & DEBUG_HW_BCHANNEL)
1450 "HFCPCI bchannel test rx protocol %x-->%x ch %x-->%x\n",
1451 bch->
state, protocol, bch->
nr, chan);
1452 if (bch->
nr != chan) {
1454 "HFCPCI rxtest wrong channel parameter %x/%x\n",
1461 hfcpci_clear_fifo_rx(hc, (chan & 2) ? 1 : 0);
1468 hc->
hw.conn &= ~0x18;
1469 #ifdef REVERSE_BITORDER
1470 hc->
hw.cirm |= 0x80;
1478 hc->
hw.conn &= ~0x03;
1479 #ifdef REVERSE_BITORDER
1480 hc->
hw.cirm |= 0x40;
1486 hfcpci_clear_fifo_rx(hc, (chan & 2) ? 1 : 0);
1489 hc->
hw.last_bfifo_cnt[1] = 0;
1493 hc->
hw.conn &= ~0x18;
1496 hc->
hw.last_bfifo_cnt[0] = 0;
1500 hc->
hw.conn &= ~0x03;
1512 #ifdef REVERSE_BITORDER
1519 deactivate_bchannel(
struct bchannel *bch)
1527 spin_unlock_irqrestore(&hc->
lock, flags);
1539 hfc_bctrl(
struct mISDNchannel *ch,
u_int cmd,
void *
arg)
1551 ret = set_hfcpci_rxtest(bch,
ISDN_P_B_RAW, (
int)(
long)arg);
1552 spin_unlock_irqrestore(&hc->
lock, flags);
1556 ret = set_hfcpci_rxtest(bch,
ISDN_P_B_HDLC, (
int)(
long)arg);
1557 spin_unlock_irqrestore(&hc->
lock, flags);
1562 spin_unlock_irqrestore(&hc->
lock, flags);
1567 deactivate_bchannel(bch);
1574 ret = channel_bctrl(bch, arg);
1587 hfcpci_l2l1D(
struct mISDNchannel *ch,
struct sk_buff *
skb)
1603 hfcpci_fill_dfifo(dch->
hw);
1605 spin_unlock_irqrestore(&hc->
lock, flags);
1608 spin_unlock_irqrestore(&hc->
lock, flags);
1618 spin_unlock_irqrestore(&hc->
lock, flags);
1628 spin_unlock_irqrestore(&hc->
lock, flags);
1638 dev_kfree_skb(dch->
tx_skb);
1643 dev_kfree_skb(dch->
rx_skb);
1659 spin_unlock_irqrestore(&hc->
lock, flags);
1671 hfcpci_l2l1B(
struct mISDNchannel *ch,
struct sk_buff *skb)
1676 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1677 unsigned long flags;
1684 hfcpci_fill_fifo(bch);
1687 spin_unlock_irqrestore(&hc->
lock, flags);
1692 ret = mode_hfcpci(bch, bch->
nr, ch->protocol);
1695 spin_unlock_irqrestore(&hc->
lock, flags);
1701 deactivate_bchannel(bch);
1717 inithfcpci(
struct hfc_pci *hc)
1720 hc->
dch.timer.function = (
void *) hfcpci_dbusy_timer;
1724 mode_hfcpci(&hc->
bch[0], 1, -1);
1725 mode_hfcpci(&hc->
bch[1], 2, -1);
1740 spin_unlock_irqrestore(&hc->
lock, flags);
1743 "mISDN: couldn't get interrupt %d\n", hc->
irq);
1756 spin_unlock_irqrestore(&hc->
lock, flags);
1770 "HFC PCI: IRQ(%d) getting no interrupts "
1771 "during init %d\n", hc->
irq, 4 - cnt);
1779 spin_unlock_irqrestore(&hc->
lock, flags);
1785 spin_unlock_irqrestore(&hc->
lock, flags);
1816 hc->
hw.conn = (hc->
hw.conn & ~7) | 6;
1828 hc->
hw.conn = (hc->
hw.conn & ~0x38) | 0x30;
1834 hc->
hw.conn = (hc->
hw.conn & ~0x3f) | 0x09;
1846 cq->
p1 < 1 || cq->
p1 > 2) {
1866 hc->
hw.conn = (hc->
hw.conn & ~0x3f) | 0x36;
1872 hc->
hw.conn = (hc->
hw.conn & ~0x3f) | 0x09;
1889 open_dchannel(
struct hfc_pci *hc,
struct mISDNchannel *ch,
1890 struct channel_req *
rq)
1896 hc->
dch.dev.id, __builtin_return_address(0));
1899 if (rq->adr.channel == 1) {
1909 hc->
hw.protocol = rq->protocol;
1910 ch->protocol = rq->protocol;
1911 err = init_card(hc);
1915 if (rq->protocol != ch->protocol) {
1923 hc->
hw.protocol = rq->protocol;
1924 ch->protocol = rq->protocol;
1941 open_bchannel(
struct hfc_pci *hc,
struct channel_req *rq)
1945 if (rq->adr.channel == 0 || rq->adr.channel > 2)
1949 bch = &hc->
bch[rq->adr.channel - 1];
1952 bch->
ch.protocol = rq->protocol;
1963 hfc_dctrl(
struct mISDNchannel *ch,
u_int cmd,
void *arg)
1965 struct mISDNdevice *dev =
container_of(ch,
struct mISDNdevice,
D);
1968 struct channel_req *
rq;
1973 __func__, cmd, arg);
1979 err = open_dchannel(hc, ch, rq);
1981 err = open_bchannel(hc, rq);
1984 if (
debug & DEBUG_HW_OPEN)
1986 __func__, hc->
dch.dev.id,
1987 __builtin_return_address(0));
1991 err = channel_ctrl(hc, arg);
2016 (
char __iomem *)(
unsigned long)hc->
pdev->resource[1].start;
2018 if (!hc->
hw.pci_io) {
2024 pci_set_dma_mask(hc->
pdev, 0xFFFF8000);
2029 "HFC-PCI: Error allocating memory for FIFO!\n");
2033 pci_write_config_dword(hc->
pdev, 0x80, hc->
hw.dmahandle);
2036 "HFC-PCI: defined at mem %#lx fifo %#lx(%#lx) IRQ %d HZ %d\n",
2047 hc->
hw.timer.function = (
void *) hfcpci_Timer;
2048 hc->
hw.timer.data = (
long) hc;
2056 release_card(
struct hfc_pci *hc) {
2064 if (hc->
dch.timer.function !=
NULL) {
2066 hc->
dch.timer.function =
NULL;
2068 spin_unlock_irqrestore(&hc->
lock, flags);
2073 release_io_hfcpci(hc);
2096 card->
dch.dev.D.send = hfcpci_l2l1D;
2097 card->
dch.dev.D.ctrl = hfc_dctrl;
2098 card->
dch.dev.nrbchan = 2;
2099 for (i = 0; i < 2; i++) {
2100 card->
bch[
i].nr = i + 1;
2101 set_channelmap(i + 1, card->
dch.dev.channelmap);
2105 card->
bch[
i].ch.send = hfcpci_l2l1B;
2106 card->
bch[
i].ch.ctrl = hfc_bctrl;
2107 card->
bch[
i].ch.nr = i + 1;
2108 list_add(&card->
bch[i].ch.list, &card->
dch.dev.bchannels);
2110 err = setup_hw(card);
2135 static const struct _hfc_map hfc_map[] =
2156 "Digi International DataFire Micro V IOM2 (Europe)"},
2158 "Digi International DataFire Micro V (Europe)"},
2160 "Digi International DataFire Micro V IOM2 (North America)"},
2162 "Digi International DataFire Micro V (North America)"},
2170 (
unsigned long) &hfc_map[0] },
2172 (
unsigned long) &hfc_map[1] },
2174 (
unsigned long) &hfc_map[2] },
2176 (
unsigned long) &hfc_map[3] },
2178 (
unsigned long) &hfc_map[4] },
2180 (
unsigned long) &hfc_map[5] },
2182 (
unsigned long) &hfc_map[6] },
2184 (
unsigned long) &hfc_map[7] },
2186 (
unsigned long) &hfc_map[8] },
2188 (
unsigned long) &hfc_map[9] },
2190 (
unsigned long) &hfc_map[10] },
2192 (
unsigned long) &hfc_map[11] },
2194 (
unsigned long) &hfc_map[12] },
2196 (
unsigned long) &hfc_map[13] },
2198 (
unsigned long) &hfc_map[14] },
2200 (
unsigned long) &hfc_map[15] },
2202 (
unsigned long) &hfc_map[16] },
2204 (
unsigned long) &hfc_map[17] },
2206 (
unsigned long) &hfc_map[18] },
2208 (
unsigned long) &hfc_map[19] },
2210 (
unsigned long) &hfc_map[20] },
2212 (
unsigned long) &hfc_map[21] },
2214 (
unsigned long) &hfc_map[22] },
2239 m->
name, pci_name(pdev));
2242 pci_set_drvdata(pdev, card);
2243 err = setup_card(card);
2245 pci_set_drvdata(pdev,
NULL);
2250 hfc_remove_pci(
struct pci_dev *pdev)
2252 struct hfc_pci *card = pci_get_drvdata(pdev);
2267 .id_table = hfc_ids,
2271 _hfcpci_softirq(
struct device *dev,
void *arg)
2279 spin_lock(&hc->
lock);
2280 bch = Sel_BCS(hc, hc->
hw.bswapped ? 2 : 1);
2282 main_rec_hfcpci(bch);
2285 bch = Sel_BCS(hc, hc->
hw.bswapped ? 1 : 2);
2287 main_rec_hfcpci(bch);
2290 spin_unlock(&hc->
lock);
2296 hfcpci_softirq(
void *arg)
2302 if ((
s32)(hfc_jiffies + tics -
jiffies) <= 0)
2305 hfc_jiffies += tics;
2306 hfc_tl.expires = hfc_jiffies;
2319 tics = (
poll *
HZ) / 8000;
2322 poll = (tics * 8000) /
HZ;
2325 "of 8..256.\n", __func__,
poll);
2333 hfc_tl.function = (
void *)hfcpci_softirq;
2336 hfc_tl.expires =
jiffies + tics;
2337 hfc_jiffies = hfc_tl.expires;
2342 err = pci_register_driver(&hfc_driver);
2344 if (timer_pending(&hfc_tl))
2354 if (timer_pending(&hfc_tl))