65 #define PROBE_VERBOSE 1
84 #define RING_SIZE (OBOE_RING_SIZE_RX8 | OBOE_RING_SIZE_TX8)
106 #define BUF_SAFETY 0x7a
107 #define RX_BUF_SZ (RX_LEN)
108 #define TX_BUF_SZ (TX_LEN+BUF_SAFETY)
145 #include <linux/module.h>
147 #include <linux/kernel.h>
148 #include <linux/types.h>
150 #include <linux/netdevice.h>
153 #include <linux/slab.h>
156 #include <linux/pci.h>
157 #include <linux/rtnetlink.h>
170 #define INB(port) inb_p(port)
171 #define OUTB(val,port) outb_p(val,port)
172 #define OUTBP(val,port) outb_p(val,port)
174 #define PROMPT OUTB(OBOE_PROMPT_BIT,OBOE_PROMPT);
177 #define PROBE_DEBUG(args...) (printk (args))
179 #define PROBE_DEBUG(args...) ;
183 #define CONFIG0H_DMA_OFF OBOE_CONFIG0H_RCVANY
184 #define CONFIG0H_DMA_ON_NORX CONFIG0H_DMA_OFF| OBOE_CONFIG0H_ENDMAC
185 #define CONFIG0H_DMA_ON CONFIG0H_DMA_ON_NORX | OBOE_CONFIG0H_ENRX
194 #define DRIVER_NAME "toshoboe"
199 static bool do_probe =
false;
205 toshoboe_checkfcs (
unsigned char *
buf,
int len)
217 for (i = 0; i < len; ++
i)
226 static unsigned char dump[50];
228 _dumpbufs (
unsigned char *
data,
int len,
char tete)
232 for (i=0;i<len;i+=16) {
233 for (j=0;j<16 && i+j<len;j++) {
sprintf(&
dump[3*j],
"%02x.",data[i+j]); }
255 printk (
KERN_ERR "Interrupts: Tx:%d Rx:%d TxUnder:%d RxOver:%d Sip:%d\n",
256 self->int_tx, self->int_rx, self->int_txunder, self->int_rxover,
281 printk (
" (%d,%02x)",self->ring->rx[i].len,self->ring->rx[i].control);
285 printk (
" (%d,%02x)",self->ring->tx[i].len,self->ring->tx[i].control);
298 pci_read_config_byte (self->pdev,
PCI_COMMAND, &command);
300 pci_write_config_byte (self->pdev,
PCI_COMMAND, command);
333 toshoboe_disablebm (
self);
353 IRDA_DEBUG (2,
"%s(%d/%d)\n", __func__, self->speed, self->io.speed);
478 self->io.speed =
self->speed;
499 self->ring->tx[
i].len = 0;
500 self->ring->tx[
i].control = 0x00;
501 self->ring->tx[
i].address =
virt_to_bus (self->tx_bufs[i]);
506 self->ring->rx[
i].len =
RX_LEN;
507 self->ring->rx[
i].len = 0;
508 self->ring->rx[
i].address =
virt_to_bus (self->rx_bufs[i]);
534 toshoboe_resetptrs (
self);
555 toshoboe_initring (
self);
556 toshoboe_enablebm (
self);
602 toshoboe_setbaud (
self);
603 toshoboe_initptrs (
self);
623 toshoboe_stopchip (
self);
624 toshoboe_startchip (
self);
625 spin_unlock_irqrestore(&self->spinlock, flags);
631 toshoboe_makemttpacket (
struct toshoboe_cb *
self,
void *
buf,
int mtt)
635 xbofs = ((
int) (mtt/100)) * (
int) (
self->speed);
640 ": generated mtt of %d bytes for %d us at %d baud\n"
641 , xbofs,mtt,self->speed);
645 printk (
KERN_ERR DRIVER_NAME
": wanted %d bytes MTT but TX_LEN is %d\n",
666 PROBE_DEBUG(
" (%d,%02x)",self->ring->tx[i].len,self->ring->tx[i].control);
676 PROBE_DEBUG(
" (%d,%02x)",self->ring->rx[i].len,self->ring->rx[i].control);
702 toshoboe_probeinterrupt (
int irq,
void *
dev_id)
748 toshoboe_maketestpacket (
unsigned char *buf,
int badcrc,
int fir)
773 len += stuff_byte (i, buf + len);
777 len += stuff_byte (
fcs.bytes[0] ^ badcrc, buf + len);
778 len += stuff_byte (
fcs.bytes[1] ^ badcrc, buf + len);
788 toshoboe_dumpregs (
self);
789 toshoboe_stopchip (
self);
790 free_irq (self->io.irq, (
void *)
self);
799 if ((self->ring->rx[i].control & 0xe0) == 0)
821 static const int bauds[] = { 9600, 115200, 4000000, 1152000 };
823 static const int bauds[] = { 9600, 115200, 4000000 };
829 if (
request_irq (self->io.irq, toshoboe_probeinterrupt,
830 self->io.irqflags,
"toshoboe", (
void *)
self))
832 printk (
KERN_ERR DRIVER_NAME
": probe failed to allocate irq %d\n",
842 toshoboe_stopchip (
self);
847 toshoboe_startchip (
self);
848 self->int_rx =
self->int_tx = 0;
849 self->speed = bauds[
j];
850 toshoboe_setbaud (
self);
851 toshoboe_initptrs (
self);
852 spin_unlock_irqrestore(&self->spinlock, flags);
854 self->ring->tx[
self->txs].control =
859 self->ring->tx[
self->txs].len =
860 toshoboe_maketestpacket (self->tx_bufs[self->txs], 0, fir);
864 self->ring->tx[
self->txs].control =
867 self->ring->tx[
self->txs].len =
868 toshoboe_maketestpacket (self->tx_bufs[self->txs], 0, fir);
872 self->ring->tx[
self->txs].control =
875 self->ring->tx[
self->txs].len =
876 toshoboe_maketestpacket (self->tx_bufs[self->txs], 0, fir);
880 self->ring->tx[
self->txs].control =
884 self->ring->tx[
self->txs].len =
885 toshoboe_maketestpacket (self->tx_bufs[self->txs], 0, fir);
889 toshoboe_dumptx (
self);
895 while (toshoboe_numvalidrcvs (
self) != n)
898 return toshoboe_probefail (
self,
"filter test");
904 while ((toshoboe_numrcvs(
self) != self->int_rx) || (self->int_tx != n))
907 return toshoboe_probefail (
self,
"interrupt test");
911 toshoboe_dumprx (
self,i);
917 toshoboe_stopchip (
self);
918 self->int_rx =
self->int_tx = 0;
921 toshoboe_startchip (
self);
922 spin_unlock_irqrestore(&self->spinlock, flags);
925 self->speed = 115200;
926 toshoboe_setbaud (
self);
927 self->ring->tx[
self->txs].control =
929 self->ring->tx[
self->txs].len = 4;
931 ((
unsigned char *) self->tx_bufs[self->txs])[0] =
'f';
932 ((
unsigned char *) self->tx_bufs[self->txs])[1] =
'i';
933 ((
unsigned char *) self->tx_bufs[self->txs])[2] =
's';
934 ((
unsigned char *) self->tx_bufs[self->txs])[3] =
'h';
935 toshoboe_dumptx (
self);
939 while (toshoboe_numvalidrcvs (
self) != 4)
942 return toshoboe_probefail (
self,
"Async test");
947 while ((toshoboe_numrcvs (
self) != self->int_rx) || (self->int_tx != 1))
950 return toshoboe_probefail (
self,
"Async interrupt test");
954 toshoboe_dumprx (
self,i);
958 toshoboe_setbaud (
self);
959 toshoboe_stopchip (
self);
961 free_irq (self->io.irq, (
void *)
self);
982 self = netdev_priv(dev);
991 _dumpbufs(skb->
data,skb->
len,
'>');
1003 toshoboe_checkstuck (
self);
1007 speed=irda_get_next_speed(skb);
1008 if ((speed != self->io.speed) && (speed != -1))
1012 if (self->txpending || skb->
len)
1014 self->new_speed = speed;
1015 IRDA_DEBUG (1,
"%s: Queued TxDone scheduled speed change %d\n" ,
1020 spin_unlock_irqrestore(&self->spinlock, flags);
1021 dev_kfree_skb (skb);
1026 netif_stop_queue(dev);
1028 spin_unlock_irqrestore(&self->spinlock, flags);
1033 self->speed = speed;
1034 toshoboe_setbaud (
self);
1035 spin_unlock_irqrestore(&self->spinlock, flags);
1036 dev_kfree_skb (skb);
1042 if ((mtt = irda_get_mtt(skb)))
1047 if (self->txpending)
1049 spin_unlock_irqrestore(&self->spinlock, flags);
1057 mtt = toshoboe_makemttpacket (
self, self->tx_bufs[self->txs], mtt);
1059 ,skb->
len,mtt,self->txpending);
1062 self->ring->tx[
self->txs].len = mtt & 0xfff;
1075 self->ring->tx[
self->txs].control =
ctl;
1089 printk(
KERN_ERR DRIVER_NAME
": problem with mtt packet - ignored\n");
1091 spin_unlock_irqrestore(&self->spinlock, flags);
1095 dumpbufs(skb->
data,skb->
len,
'>');
1103 ,skb->
len, self->ring->tx[self->txs].control, self->txpending);
1105 spin_unlock_irqrestore(&self->spinlock, flags);
1116 skb_copy_from_linear_data(skb, self->tx_bufs[self->txs], len);
1118 self->ring->tx[
self->txs].len = len & 0x0fff;
1129 self->ring->tx[
self->txs].control =
ctl;
1133 if (!self->txpending)
1141 spin_unlock_irqrestore(&self->spinlock, flags);
1142 dev_kfree_skb (skb);
1149 toshoboe_interrupt (
int irq,
void *dev_id)
1158 if (!(irqstat & OBOE_INT_MASK))
1164 toshoboe_isntstuck (
self);
1167 if (irqstat & OBOE_INT_TXDONE)
1172 txp =
self->txpending;
1173 self->txpending = 0;
1181 ,irqstat,txp,self->txpending);
1190 while (self->ring->tx[txpc].control & OBOE_CTL_TX_HW_OWNS)
1195 self->netdev->stats.tx_packets++;
1196 if (self->ring->tx[txpc].control & OBOE_CTL_TX_HW_OWNS)
1199 self->netdev->stats.tx_packets--;
1201 self->netdev->stats.tx_packets++;
1206 if ((!self->txpending) && (self->new_speed))
1208 self->speed =
self->new_speed;
1209 IRDA_DEBUG (1,
"%s: Executed TxDone scheduled speed change %d\n",
1210 __func__, self->speed);
1211 toshoboe_setbaud (
self);
1215 if (!self->new_speed)
1216 netif_wake_queue(self->netdev);
1219 if (irqstat & OBOE_INT_RXDONE)
1223 int len =
self->ring->rx[
self->rxs].len;
1226 ,len,self->ring->rx[self->rxs].control);
1229 dumpbufs(self->rx_bufs[self->rxs],len,
'<');
1232 if (self->ring->rx[self->rxs].control == 0)
1238 if (enable & OBOE_ENABLEH_SIRON)
1240 if (!toshoboe_checkfcs (self->rx_bufs[self->rxs], len))
1247 IRDA_DEBUG (1,
"%s.SIR:%x(%x)\n", __func__, len,enable);
1257 IRDA_DEBUG (2,
"%s.MIR:%x(%x)\n", __func__, len,enable);
1260 else if (enable & OBOE_ENABLEH_FIRON)
1266 IRDA_DEBUG (1,
"%s.FIR:%x(%x)\n", __func__, len,enable);
1269 IRDA_DEBUG (0,
"%s.?IR:%x(%x)\n", __func__, len,enable);
1273 skb = dev_alloc_skb (len + 1);
1276 skb_reserve (skb, 1);
1279 skb_copy_to_linear_data(skb, self->rx_bufs[self->rxs],
1281 self->netdev->stats.rx_packets++;
1282 skb->
dev =
self->netdev;
1283 skb_reset_mac_header(skb);
1289 "%s(), memory squeeze, dropping frame.\n",
1303 ,len,self->ring->rx[self->rxs].control);
1306 self->ring->rx[
self->rxs].len = 0x0;
1318 if (irqstat & OBOE_INT_TXUNDER)
1322 if (irqstat & OBOE_INT_RXOVER)
1331 ,self->int_sip,irqstat,self->txpending);
1341 unsigned long flags;
1346 self = netdev_priv(dev);
1354 rc =
request_irq (self->io.irq, toshoboe_interrupt,
1360 toshoboe_startchip (
self);
1361 spin_unlock_irqrestore(&self->spinlock, flags);
1364 netif_start_queue(dev);
1385 self = netdev_priv(dev);
1388 netif_stop_queue(dev);
1397 free_irq (self->io.irq, (
void *)
self);
1401 toshoboe_stopchip (
self);
1418 unsigned long flags;
1423 self = netdev_priv(dev);
1427 IRDA_DEBUG (5,
"%s(), %s, (cmd=0x%X)\n", __func__, dev->
name, cmd);
1439 IRDA_DEBUG (1,
"%s(BANDWIDTH), %s, (%X/%ld\n", __func__
1449 self->new_speed = irq->ifr_baudrate;
1452 IRDA_DEBUG (1,
"%s(MEDIABUSY), %s, (%X/%x)\n", __func__
1462 IRDA_DEBUG (3,
"%s(RECEIVING), %s, (%X/%x)\n", __func__
1466 IRDA_DEBUG (1,
"%s(?), %s, (cmd=0x%X)\n", __func__, dev->
name, cmd);
1470 spin_unlock_irqrestore(&self->spinlock, flags);
1499 toshoboe_stopchip (
self);
1506 kfree (self->tx_bufs[i]);
1507 self->tx_bufs[
i] =
NULL;
1512 kfree (self->rx_bufs[i]);
1513 self->rx_bufs[
i] =
NULL;
1518 kfree (self->ringbuf);
1519 self->ringbuf =
NULL;
1526 .ndo_open = toshoboe_net_open,
1527 .ndo_stop = toshoboe_net_close,
1528 .ndo_start_xmit = toshoboe_hard_xmit,
1529 .ndo_do_ioctl = toshoboe_net_ioctl,
1533 toshoboe_open (
struct pci_dev *pci_dev,
const struct pci_device_id *pdid)
1550 "IrDA control block\n");
1554 self = netdev_priv(dev);
1559 self->io.fir_base =
self->base;
1561 self->io.irq = pci_dev->
irq;
1564 self->speed =
self->io.speed = 9600;
1571 ,self->io.fir_base);
1579 self->qos.baud_rate.bits = 0;
1582 self->qos.baud_rate.bits |=
IR_2400;
1585 self->qos.baud_rate.bits |=
IR_9600;
1587 self->qos.baud_rate.bits |=
IR_19200;
1598 self->qos.baud_rate.bits |= (
IR_4000000 << 8);
1602 self->qos.min_turn_time.bits = 0xff;
1614 #if (BITS_PER_LONG == 64)
1615 #error broken on 64-bit: casts pointer to 32-bit, and then back to pointer.
1622 addr = (
__u32) self->ringbuf;
1625 self->ring = (
struct OboeRing *) addr;
1629 self->io.mem_base = (
__u32) self->ring;
1635 if (!self->tx_bufs[i])
1642 if (!self->rx_bufs[i])
1655 if (!toshoboe_probe (
self))
1674 pci_set_drvdata(pci_dev,
self);
1682 kfree (self->tx_bufs[i]);
1684 kfree (self->rx_bufs[i]);
1685 kfree(self->ringbuf);
1697 toshoboe_gotosleep (
struct pci_dev *pci_dev,
pm_message_t crap)
1700 unsigned long flags;
1705 if (!
self || self->stopped)
1708 if ((!self->irdad) && (!self->async))
1712 while ((i--) && (self->txpending))
1717 toshoboe_stopchip (
self);
1719 self->txpending = 0;
1721 spin_unlock_irqrestore(&self->spinlock, flags);
1726 toshoboe_wakeup (
struct pci_dev *pci_dev)
1729 unsigned long flags;
1733 if (!
self || !self->stopped)
1736 if ((!self->irdad) && (!self->async))
1741 toshoboe_startchip (
self);
1744 netif_wake_queue(self->netdev);
1745 spin_unlock_irqrestore(&self->spinlock, flags);
1749 static struct pci_driver donauboe_pci_driver = {
1751 .id_table = toshoboe_pci_tbl,
1752 .probe = toshoboe_open,
1753 .remove = toshoboe_close,
1754 .suspend = toshoboe_gotosleep,
1755 .resume = toshoboe_wakeup
1759 donauboe_init (
void)
1761 return pci_register_driver(&donauboe_pci_driver);
1765 donauboe_cleanup (
void)