25 #include <linux/module.h>
26 #include <linux/pci.h>
29 #include <linux/slab.h>
32 #define W6692_REV "2.0"
34 #define DBUSY_TIMER_VALUE 80
48 static const struct w6692map w6692_map[] =
55 #ifndef PCI_VENDOR_ID_USR
56 #define PCI_VENDOR_ID_USR 0x16ec
57 #define PCI_DEVICE_ID_USR_6692 0x3409
132 return inb(card->addr + offset);
160 disable_hwirq(
struct w6692_hw *card)
162 WriteW6692(card,
W_IMASK, 0xff);
165 static const char *W6692Ver[] = {
"V00",
"V01",
"V10",
"V11"};
174 W6692Ver[(val >> 6) & 3]);
178 w6692_led_handler(
struct w6692_hw *card,
int on)
195 WriteW6692(card,
W_CIX, cmd);
211 switch (card->
state) {
229 if (dch->
state <= 5) {
250 pr_debug(
"%s: TE unknown state %02x dch state %02x\n",
267 pr_info(
"%s: D receive out of memory\n", card->
name);
274 dch->
rx_skb->len + count);
289 W6692_fill_Dfifo(
struct w6692_hw *card)
311 pr_debug(
"%s: fill_Dfifo dbusytimer running\n", card->
name);
338 W6692_fill_Dfifo(card);
340 pr_info(
"%s: %s without TX_BUSY\n", card->
name, __func__);
343 W6692_fill_Dfifo(card);
347 W6692_fill_Dfifo(card);
360 #ifdef ERROR_STATISTIC
366 #ifdef ERROR_STATISTIC
372 #ifdef ERROR_STATISTIC
376 if (card->
dch.rx_skb)
377 dev_kfree_skb(card->
dch.rx_skb);
384 W6692_empty_Dfifo(card, count);
393 if (card->
dch.tx_skb && card->
dch.tx_idx < card->
dch.tx_skb->len) {
394 W6692_fill_Dfifo(card);
396 if (card->
dch.tx_skb)
397 dev_kfree_skb(card->
dch.tx_skb);
399 W6692_fill_Dfifo(card);
404 handle_statusD(
struct w6692_hw *card)
414 pr_debug(
"%s: D-channel underrun/collision\n", card->
name);
415 #ifdef ERROR_STATISTIC
427 v1 = ReadW6692(card,
W_MOSR);
428 pr_debug(
"%s: spurious MOC interrupt MOSR %02x\n",
432 cir = ReadW6692(card,
W_CIR);
443 w6692_led_handler(card, 1);
446 w6692_led_handler(card, 0);
453 v1 = ReadW6692(card,
W_SQR);
464 W6692_empty_Bfifo(
struct w6692_ch *wch,
int count)
488 pr_warning(
"%s.B%d: No bufferspace for %d bytes\n",
489 card->
name, wch->
bch.nr, count);
497 wch->
bch.nr, card->
name, count);
503 W6692_fill_Bfifo(
struct w6692_ch *wch)
506 int count, fillempty = 0;
510 if (!wch->
bch.tx_skb) {
517 count = wch->
bch.tx_skb->len - wch->
bch.tx_idx;
520 ptr = wch->
bch.tx_skb->data + wch->
bch.tx_idx;
528 count, wch->
bch.tx_idx);
541 wch->
bch.nr, card->
name, count);
612 wch->
bch.nr, wch->
bch.state, pr);
643 pr_info(
"%s: protocol %x not known\n", card->
name, pr);
653 if (wch->
bch.tx_skb && wch->
bch.tx_idx < wch->
bch.tx_skb->len) {
654 W6692_fill_Bfifo(wch);
657 dev_kfree_skb(wch->
bch.tx_skb);
659 W6692_fill_Bfifo(wch);
662 W6692_fill_Bfifo(wch);
668 W6692B_interrupt(
struct w6692_hw *card,
int ch)
682 wch->
bch.nr, wch->
bch.state);
683 #ifdef ERROR_STATISTIC
691 #ifdef ERROR_STATISTIC
698 #ifdef ERROR_STATISTIC
712 W6692_empty_Bfifo(wch, count);
717 if (!(stat & W_B_EXI_RME))
719 if (star & W_B_STAR_RDOV) {
721 wch->
bch.nr, wch->
bch.state);
722 #ifdef ERROR_STATISTIC
735 if (!(star & W_B_STAR_RDOV)) {
737 wch->
bch.nr, wch->
bch.state);
738 #ifdef ERROR_STATISTIC
746 if (!(stat & (W_B_EXI_RME | W_B_EXI_RMR))) {
753 wch->
bch.nr, wch->
bch.state);
754 #ifdef ERROR_STATISTIC
760 if (wch->
bch.tx_skb) {
766 if (star & W_B_STAR_XDOW)
771 wch->
bch.nr, wch->
bch.state);
772 #ifdef ERROR_STATISTIC
776 if (wch->
bch.tx_skb) {
787 w6692_irq(
int intno,
void *
dev_id)
792 spin_lock(&card->
lock);
793 ista = ReadW6692(card,
W_ISTA);
796 spin_unlock(&card->
lock);
801 ista &= ~card->
imask;
803 W6692B_interrupt(card, 0);
805 W6692B_interrupt(card, 1);
813 handle_statusD(card);
817 spin_unlock(&card->
lock);
822 dbusy_timer_handler(
struct dchannel *dch)
832 pr_debug(
"%s: D-Channel Busy RBCH %02x STAR %02x\n",
833 card->
name, rbch, star);
842 pr_info(
"%s: W6692 D-Channel Busy no tx_idx\n",
847 spin_unlock_irqrestore(&card->
lock, flags);
855 card->
dch.timer.function = (
void *)dbusy_timer_handler;
860 WriteW6692(card,
W_D_CTL, 0x00);
862 WriteW6692(card,
W_D_SAM, 0xff);
863 WriteW6692(card,
W_D_TAM, 0xff);
900 val = ReadW6692(card,
W_XADDR);
924 spin_unlock_irqrestore(&card->
lock, flags);
926 pr_info(
"%s: couldn't get interrupt %d\n", card->
name,
934 spin_unlock_irqrestore(&card->
lock, flags);
941 pr_info(
"%s: IRQ(%d) getting no IRQs during init %d\n",
942 card->
name, card->
irq, 3 - cnt);
952 w6692_l2l1B(
struct mISDNchannel *ch,
struct sk_buff *skb)
967 W6692_fill_Bfifo(bc);
969 spin_unlock_irqrestore(&card->
lock, flags);
974 ret = w6692_mode(bc, ch->protocol);
977 spin_unlock_irqrestore(&card->
lock, flags);
986 spin_unlock_irqrestore(&card->
lock, flags);
992 pr_info(
"%s: %s unknown prim(%x,%x)\n",
1008 open_bchannel(
struct w6692_hw *card,
struct channel_req *
rq)
1012 if (rq->adr.channel == 0 || rq->adr.channel > 2)
1016 bch = &card->
bc[rq->adr.channel - 1].bch;
1019 bch->
ch.protocol = rq->protocol;
1045 w6692_bctrl(
struct mISDNchannel *ch,
u32 cmd,
void *
arg)
1053 pr_debug(
"%s: %s cmd:%x %p\n", card->
name, __func__, cmd, arg);
1061 spin_unlock_irqrestore(&card->
lock, flags);
1068 ret = channel_bctrl(bch, arg);
1071 pr_info(
"%s: %s unknown prim(%x)\n",
1072 card->
name, __func__, cmd);
1078 w6692_l2l1D(
struct mISDNchannel *ch,
struct sk_buff *skb)
1084 struct mISDNhead *hh = mISDN_HEAD_P(skb);
1094 W6692_fill_Dfifo(card);
1096 spin_unlock_irqrestore(&card->
lock, flags);
1099 spin_unlock_irqrestore(&card->
lock, flags);
1126 spin_unlock_irqrestore(&card->
lock, flags);
1131 spin_unlock_irqrestore(&card->
lock, flags);
1138 spin_unlock_irqrestore(&card->
lock, flags);
1143 dev_kfree_skb(dch->
tx_skb);
1148 dev_kfree_skb(dch->
rx_skb);
1158 spin_unlock_irqrestore(&card->
lock, flags);
1179 open_dchannel(
struct w6692_hw *card,
struct channel_req *rq)
1181 pr_debug(
"%s: %s dev(%d) open from %p\n", card->
name, __func__,
1182 card->
dch.dev.id, __builtin_return_address(1));
1185 if (rq->adr.channel == 1)
1188 rq->ch = &card->
dch.dev.D;
1189 rq->ch->protocol = rq->protocol;
1190 if (card->
dch.state == 7)
1197 w6692_dctrl(
struct mISDNchannel *ch,
u32 cmd,
void *arg)
1199 struct mISDNdevice *dev =
container_of(ch,
struct mISDNdevice,
D);
1202 struct channel_req *
rq;
1210 err = open_dchannel(card, rq);
1212 err = open_bchannel(card, rq);
1220 dch->
dev.id, __builtin_return_address(0));
1224 err = channel_ctrl(card, arg);
1227 pr_debug(
"%s: unknown DCTRL command %x\n", card->
name, cmd);
1239 pr_info(
"%s: config port %x-%x already in use\n", card->
name,
1244 card->
bc[0].addr = card->
addr;
1245 card->
bc[1].addr = card->
addr + 0x40;
1246 val = ReadW6692(card,
W_ISTA);
1249 val = ReadW6692(card,
W_IMASK);
1250 if (
debug & DEBUG_HW)
1253 if (
debug & DEBUG_HW)
1256 if (
debug & DEBUG_HW)
1259 if (
debug & DEBUG_HW)
1265 release_card(
struct w6692_hw *card)
1270 disable_hwirq(card);
1274 card->
xdata |= 0x04;
1277 spin_unlock_irqrestore(&card->
lock, flags);
1294 setup_instance(
struct w6692_hw *card)
1303 card->
fmask = (1 << w6692_cnt);
1308 card->
dch.dev.D.send = w6692_l2l1D;
1309 card->
dch.dev.D.ctrl = w6692_dctrl;
1313 card->
dch.dev.nrbchan = 2;
1314 for (i = 0; i < 2; i++) {
1318 card->
bc[
i].bch.nr = i + 1;
1319 card->
bc[
i].bch.ch.nr = i + 1;
1320 card->
bc[
i].bch.ch.send = w6692_l2l1B;
1321 card->
bc[
i].bch.ch.ctrl = w6692_bctrl;
1322 set_channelmap(i + 1, card->
dch.dev.channelmap);
1323 list_add(&card->
bc[i].bch.ch.list, &card->
dch.dev.bchannels);
1332 err = init_card(card);
1338 pr_notice(
"W6692 %d cards installed\n", w6692_cnt);
1367 pr_info(
"No kmem for w6692 card\n");
1379 m->
name, pci_name(pdev));
1383 pci_set_drvdata(pdev, card);
1384 err = setup_instance(card);
1386 pci_set_drvdata(pdev,
NULL);
1391 w6692_remove_pci(
struct pci_dev *pdev)
1393 struct w6692_hw *card = pci_get_drvdata(pdev);
1399 pr_notice(
"%s: drvdata already removed\n", __func__);
1407 (
ulong)&w6692_map[2]},
1416 .probe = w6692_probe,
1418 .id_table = w6692_ids,
1421 static int __init w6692_init(
void)
1427 err = pci_register_driver(&w6692_driver);
1431 static void __exit w6692_cleanup(
void)