31 #include <linux/module.h>
32 #include <linux/sched.h>
33 #include <linux/kernel.h>
35 #include <linux/pci.h>
36 #include <linux/poison.h>
37 #include <linux/errno.h>
38 #include <linux/atm.h>
39 #include <linux/atmdev.h>
40 #include <linux/sonet.h>
42 #include <linux/netdevice.h>
45 #include <linux/uio.h>
48 #include <linux/capability.h>
49 #include <linux/bitops.h>
50 #include <linux/slab.h>
51 #include <asm/byteorder.h>
52 #include <asm/string.h>
55 #include <asm/uaccess.h>
56 #include <linux/wait.h>
86 #define NP FS_NR_FREE_POOLS
87 static int rx_buf_sizes[
NP] = {128, 256, 512, 1024, 2048, 4096, 16384, 65520};
91 static int rx_pool_sizes[
NP] = {1024, 1024, 512, 256, 128, 64, 32, 32};
94 static int rx_pool_sizes[
NP] = {128, 128, 128, 64, 64, 64, 32, 32};
153 static char *res_strings[] = {
154 "RX OK: streaming not EOP",
155 "RX OK: streaming EOP",
156 "RX OK: Single buffer packet",
157 "RX OK: packet mode",
158 "RX OK: F4 OAM (end to end)",
159 "RX OK: F4 OAM (Segment)",
160 "RX OK: F5 OAM (end to end)",
161 "RX OK: F5 OAM (Segment)",
163 "RX OK: TRANSP cell",
164 "RX OK: TRANSPC cell",
171 "reassemby abort: AAL5 abort",
173 "packet ageing timeout",
174 "channel ageing timeout",
175 "calculated length error",
176 "programmed length limit error",
178 "oam transp or transpc crc10 error",
185 "reassembly abort: no buffers",
186 "receive buffer overflow",
188 "receive buffer full",
189 "low priority discard - no receive descriptor",
190 "low priority discard - missing end of packet",
216 static char *irq_bitname[] = {
248 #define PHY_CLEARALL -2
276 #undef IRQ_RATE_LIMIT // 100
280 #undef FS_POLL_FREQ // 100
293 #define fs_dprintk(f, str...) if (fs_debug & f) printk (str)
295 #define fs_dprintk(f, str...)
299 static int fs_keystream = 0;
304 static int fs_debug = 0;
320 #define FS_DEBUG_FLOW 0x00000001
321 #define FS_DEBUG_OPEN 0x00000002
322 #define FS_DEBUG_QUEUE 0x00000004
323 #define FS_DEBUG_IRQ 0x00000008
324 #define FS_DEBUG_INIT 0x00000010
325 #define FS_DEBUG_SEND 0x00000020
326 #define FS_DEBUG_PHY 0x00000040
327 #define FS_DEBUG_CLEANUP 0x00000080
328 #define FS_DEBUG_QOS 0x00000100
329 #define FS_DEBUG_TXQ 0x00000200
330 #define FS_DEBUG_ALLOC 0x00000400
331 #define FS_DEBUG_TXMEM 0x00000800
332 #define FS_DEBUG_QSIZE 0x00001000
335 #define func_enter() fs_dprintk(FS_DEBUG_FLOW, "fs: enter %s\n", __func__)
336 #define func_exit() fs_dprintk(FS_DEBUG_FLOW, "fs: exit %s\n", __func__)
343 static void my_hd (
void *
addr,
int len)
350 for (j=0;j < ((len < 16)?len:16);j++) {
351 printk (
"%02x %s", ptr[j], (j==7)?
" ":
"");
354 printk (
" %s", (j==7)?
" ":
"");
356 for (j=0;j < ((len < 16)?len:16);j++) {
358 printk (
"%c", (ch < 0x20)?
'.':((ch > 0x7f)?
'.':ch));
366 static void my_hd (
void *
addr,
int len){}
374 static inline void fs_kfree_skb (
struct sk_buff *
skb)
444 #define ROUND_NEAREST 3
447 static int make_rate(
unsigned int rate,
int r,
448 u16 *
bits,
unsigned int *actual)
450 unsigned char exp = -1;
451 unsigned int man = -1;
471 if (rate > 0xffc00000U) {
488 while (!(man & (1<<31))) {
516 if (man & (~0
U>>9)) {
517 man = (man>>(32-9)) + 1;
530 if (man & (1<<(32-9-1))) {
531 man = (man>>(32-9)) + 1;
558 *bits = (exp<<9) | man;
562 ? (1 << exp) + (man << (exp-9))
563 : (1 <<
exp) + ((man + (1<<(9-exp-1))) >> (9-
exp));
624 q->
offset, rp, wp, wp-rp);
638 static void submit_queue (
struct fs_dev *dev,
struct queue *q,
643 qe = get_qentry (dev, q);
648 submit_qentry (dev, q, qe);
656 if (qp >= 60) qp = 0;
662 #define submit_command submit_queue
668 write_fs (dev,
CMDR0, cmd);
669 write_fs (dev,
CMDR1, p1);
670 write_fs (dev,
CMDR2, p2);
671 write_fs (dev,
CMDR3, p3);
677 static void process_return_queue (
struct fs_dev *dev,
struct queue *q)
703 static void process_txdone_queue (
struct fs_dev *dev,
struct queue *q)
773 static void process_incoming (
struct fs_dev *dev,
struct queue *q)
798 channo = qe->
cmd & 0xffff;
800 if (channo < dev->nchannels)
820 __net_timestamp(skb);
822 atm_vcc->
push (atm_vcc, skb);
826 printk (
KERN_ERR "Got a receive on a non-open channel %d.\n", channo);
831 if (qe->
p1 & 0xffff) {
857 #define DO_DIRECTION(tp) ((tp)->traffic_class != ATM_NONE)
859 static int fs_open(
struct atm_vcc *atm_vcc)
872 short vpi = atm_vcc->
vpi;
873 int vci = atm_vcc->
vci;
889 atm_vcc->
dev->number, atm_vcc->
vpi, atm_vcc->
vci);
905 txtp = &atm_vcc->
qos.txtp;
906 rxtp = &atm_vcc->
qos.rxtp;
911 for (to=33;to;to--, dev->
channo++) {
925 printk (
"No more free channels for FS50..\n");
935 printk (
"Channel is in use for FS155.\n");
958 switch (atm_vcc->
qos.aal) {
976 printk (
"Unknown aal: %d\n", atm_vcc->
qos.aal);
981 tc->
atm_hdr = (vpi << 20) | (vci << 4);
991 if (pcr > 51840000/53/8) pcr = 51840000/53/8;
993 if (pcr > 155520000/53/8) pcr = 155520000/53/8;
997 tmc0 =
IS_FS50(dev)?0x61BE:0x64c9;
1006 error = make_rate (pcr, r, &tmc0,
NULL);
1015 tc->
TMC[0] = tmc0 | 0x4000;
1027 fs_dprintk (FS_DEBUG_OPEN,
"TX config record:\n");
1028 my_hd (tc,
sizeof (*tc));
1056 if (atm_vcc->
qos.rxtp.max_sdu <= dev->
rx_fp[bfp].bufsize)
break;
1057 if (bfp >= FS_NR_FREE_POOLS) {
1059 atm_vcc->
qos.rxtp.max_sdu);
1068 switch (atm_vcc->
qos.aal) {
1089 (vpi << 16) | vci, 0 );
1104 static void fs_close(
struct atm_vcc *atm_vcc)
1129 txtp = &atm_vcc->
qos.txtp;
1130 rxtp = &atm_vcc->
qos.rxtp;
1154 0x80 + vcc->
channo, -1, 0 );
1165 static int fs_send (
struct atm_vcc *atm_vcc,
struct sk_buff *skb)
1175 atm_vcc, skb, vcc, dev);
1191 *(
int *) skb->
data);
1204 dq[qd].bsa = td->
bsa;
1205 dq[qd].skb = td->
skb;
1206 dq[qd].dev = td->
dev;
1208 if (qd >= 60) qd = 0;
1211 submit_queue (dev, &dev->hp_txq,
1217 read_fs (dev,
Q_EA (dev->hp_txq.offset)) -
1218 read_fs (dev,
Q_SA (dev->hp_txq.offset)),
1219 read_fs (dev,
Q_EA (dev->tx_relq.offset)) -
1220 read_fs (dev,
Q_SA (dev->tx_relq.offset)));
1230 static int fs_ioctl(
struct atm_dev *dev,
unsigned int cmd,
void __user *
arg)
1238 static int fs_getsockopt(
struct atm_vcc *vcc,
int level,
int optname,
1239 void __user *optval,
int optlen)
1247 static int fs_setsockopt(
struct atm_vcc *vcc,
int level,
int optname,
1248 void __user *optval,
unsigned int optlen)
1256 static void fs_phy_put(
struct atm_dev *dev,
unsigned char value,
1264 static unsigned char fs_phy_get(
struct atm_dev *dev,
unsigned long addr)
1272 static int fs_change_qos(
struct atm_vcc *vcc,
struct atm_qos *qos,
int flags)
1309 pci_read_config_dword (pdev, 0x28, &tint);
1312 pci_write_config_dword (pdev, 0x28, tint);
1336 for (i=0;i<reginit->
val;i++) {
1337 write_phy (dev, i, 0);
1340 write_phy (dev, reginit->
reg, reginit->
val);
1348 static void reset_chip (
struct fs_dev *dev)
1379 write_fs (dev, 0x200 + i * 4, -1);
1388 if (alignment <= 0x10) {
1390 if ((
unsigned long)t & (alignment-1)) {
1391 printk (
"Kmalloc doesn't align things correctly! %p\n", t);
1393 return aligned_kmalloc (size, flags, alignment * 4);
1397 printk (
KERN_ERR "Request for > 0x10 alignment not yet implemented (hard!)\n");
1402 struct queue *txq,
int queue,
int nentries,
int is_rq)
1404 int sz = nentries *
sizeof (
struct FS_QENTRY);
1425 write_fs (dev,
Q_CNF(queue), 0 );
1445 write_fs (dev,
FP_SA(queue), 0);
1446 write_fs (dev,
FP_EA(queue), 0);
1447 write_fs (dev,
FP_CTU(queue), 0);
1448 write_fs (dev,
FP_CNT(queue), 0);
1459 static inline int nr_buffers_in_freepool (
struct fs_dev *dev,
struct freepool *fp)
1485 while (nr_buffers_in_freepool(dev, fp) < fp->
nr_buffers) {
1487 skb = alloc_skb (fp->
bufsize, gfp_flags);
1531 static void __devexit free_queue (
struct fs_dev *dev,
struct queue *txq)
1568 status = read_fs (dev,
ISR);
1574 #ifdef IRQ_RATE_LIMIT
1581 if (lastjif == jiffies) {
1582 if (++nintr > IRQ_RATE_LIMIT) {
1584 printk (
KERN_ERR "fs: Too many interrupts. Turning off interrupt %d.\n",
1594 read_fs (dev,
Q_EA (dev->hp_txq.offset)) -
1595 read_fs (dev,
Q_SA (dev->hp_txq.offset)),
1596 read_fs (dev,
Q_EA (dev->tx_relq.offset)) -
1597 read_fs (dev,
Q_SA (dev->tx_relq.offset)));
1605 if (status & (1 << i))
1606 fs_dprintk (FS_DEBUG_IRQ,
" %s", irq_bitname[i]);
1611 fs_dprintk (FS_DEBUG_IRQ,
"Iiiin-coming (0)!!!!\n");
1612 process_incoming (dev, &dev->
rx_rq[0]);
1619 fs_dprintk (FS_DEBUG_IRQ,
"Iiiin-coming (1)!!!!\n");
1620 process_incoming (dev, &dev->
rx_rq[1]);
1626 fs_dprintk (FS_DEBUG_IRQ,
"Iiiin-coming (2)!!!!\n");
1627 process_incoming (dev, &dev->
rx_rq[2]);
1633 fs_dprintk (FS_DEBUG_IRQ,
"Iiiin-coming (3)!!!!\n");
1634 process_incoming (dev, &dev->
rx_rq[3]);
1640 fs_dprintk (FS_DEBUG_IRQ,
"Command executed ok!\n");
1641 process_return_queue (dev, &dev->
st_q);
1645 fs_dprintk (FS_DEBUG_IRQ,
"Data tramsitted!\n");
1646 process_txdone_queue (dev, &dev->tx_relq);
1655 static void fs_poll (
unsigned long data)
1674 printk (
KERN_INFO "found a FireStream %d card, base %16llx, irq%d.\n",
1680 my_hd ((
unsigned char *) dev,
sizeof (*dev));
1682 undocumented_pci_fix (pci_dev);
1710 isr = read_fs (dev,
ISR);
1718 fs_dprintk (FS_DEBUG_INIT,
"Ha! Initialized OK!\n");
1760 write_fs (dev,
TMCONF, 0x0000000f);
1762 write_fs (dev, 0x80, 0x000F00E4);
1778 dev->
atm_dev->ci_range.vpi_bits = 12;
1779 dev->
atm_dev->ci_range.vci_bits = 16;
1791 write_fs (dev,
RAC, 0);
1833 rx_buf_sizes[i], rx_pool_sizes[i]);
1847 fs_dprintk (FS_DEBUG_INIT,
"Grabbed irq %d for dev at %p.\n", dev->
irq, dev);
1851 write_fs (dev,
IMR, 0
1865 SARMODE0_PRPWT_FS155_3)
1877 init_phy (dev, PHY_NTC_INIT);
1880 write_phy (dev, 0x39, 0x000e);
1886 dev->
timer.function = fs_poll;
1900 static int __devinit firestream_init_one (
struct pci_dev *pci_dev,
1909 fs_dev = kzalloc (
sizeof (
struct fs_dev),
GFP_KERNEL);
1911 fs_dev,
sizeof (
struct fs_dev));
1916 goto err_out_free_fs_dev;
1922 if (fs_init(fs_dev))
1923 goto err_out_free_atm_dev;
1925 fs_dev->
next = fs_boards;
1929 err_out_free_atm_dev:
1931 err_out_free_fs_dev:
1937 static void __devexit firestream_remove_one (
struct pci_dev *pdev)
1940 struct fs_dev *
dev, *nxtdev;
1948 for (i=0;i<60;i++) {
1949 printk (
"%d: %08x %08x %08x %08x \n",
1950 i, pq[qp].cmd, pq[qp].
p0, pq[qp].p1, pq[qp].p2);
1952 if (qp >= 60) qp = 0;
1955 printk (
"descriptors:\n");
1956 for (i=0;i<60;i++) {
1957 printk (
"%d: %p: %08x %08x %p %p\n",
1958 i, da[qd],
dq[qd].flags,
dq[qd].
bsa,
dq[qd].skb,
dq[qd].dev);
1960 if (qd >= 60) qd = 0;
1964 for (dev = fs_boards;dev !=
NULL;dev=nxtdev) {
2006 free_queue (dev, &dev->hp_txq);
2007 free_queue (dev, &dev->lp_txq);
2008 free_queue (dev, &dev->tx_relq);
2009 free_queue (dev, &dev->
st_q);
2015 free_freepool (dev, &dev->
rx_fp[i]);
2018 free_queue (dev, &dev->
rx_rq[i]);
2037 static struct pci_driver firestream_driver = {
2038 .name =
"firestream",
2039 .id_table = firestream_pci_tbl,
2040 .probe = firestream_init_one,
2044 static int __init firestream_init_module (
void)
2049 error = pci_register_driver(&firestream_driver);
2054 static void __exit firestream_cleanup_module(
void)