aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/atm/Kconfig6
-rw-r--r--drivers/atm/Makefile1
-rw-r--r--drivers/atm/solos-pci.c790
3 files changed, 797 insertions, 0 deletions
diff --git a/drivers/atm/Kconfig b/drivers/atm/Kconfig
index f197a193633a..191b85e857e0 100644
--- a/drivers/atm/Kconfig
+++ b/drivers/atm/Kconfig
@@ -391,4 +391,10 @@ config ATM_HE_USE_SUNI
391 Support for the S/UNI-Ultra and S/UNI-622 found in the ForeRunner 391 Support for the S/UNI-Ultra and S/UNI-622 found in the ForeRunner
392 HE cards. This driver provides carrier detection some statistics. 392 HE cards. This driver provides carrier detection some statistics.
393 393
394config ATM_SOLOS
395 tristate "Solos ADSL2+ PCI Multiport card driver"
396 depends on PCI
397 help
398 Support for the Solos multiport ADSL2+ card.
399
394endif # ATM 400endif # ATM
diff --git a/drivers/atm/Makefile b/drivers/atm/Makefile
index 0bfb31748ecf..62c3cc1075ae 100644
--- a/drivers/atm/Makefile
+++ b/drivers/atm/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_ATM_IA) += iphase.o suni.o
12obj-$(CONFIG_ATM_FORE200E) += fore_200e.o 12obj-$(CONFIG_ATM_FORE200E) += fore_200e.o
13obj-$(CONFIG_ATM_ENI) += eni.o suni.o 13obj-$(CONFIG_ATM_ENI) += eni.o suni.o
14obj-$(CONFIG_ATM_IDT77252) += idt77252.o 14obj-$(CONFIG_ATM_IDT77252) += idt77252.o
15obj-$(CONFIG_ATM_SOLOS) += solos-pci.o
15 16
16ifeq ($(CONFIG_ATM_NICSTAR_USE_SUNI),y) 17ifeq ($(CONFIG_ATM_NICSTAR_USE_SUNI),y)
17 obj-$(CONFIG_ATM_NICSTAR) += suni.o 18 obj-$(CONFIG_ATM_NICSTAR) += suni.o
diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
new file mode 100644
index 000000000000..72fc0f799a64
--- /dev/null
+++ b/drivers/atm/solos-pci.c
@@ -0,0 +1,790 @@
1/*
2 * Driver for the Solos PCI ADSL2+ card, designed to support Linux by
3 * Traverse Technologies -- http://www.traverse.com.au/
4 * Xrio Limited -- http://www.xrio.com/
5 *
6 *
7 * Copyright © 2008 Traverse Technologies
8 * Copyright © 2008 Intel Corporation
9 *
10 * Authors: Nathan Williams <nathan@traverse.com.au>
11 * David Woodhouse <dwmw2@infradead.org>
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * version 2, as published by the Free Software Foundation.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 */
22
23#define DEBUG
24#define VERBOSE_DEBUG
25
26#include <linux/interrupt.h>
27#include <linux/module.h>
28#include <linux/kernel.h>
29#include <linux/errno.h>
30#include <linux/ioport.h>
31#include <linux/types.h>
32#include <linux/pci.h>
33#include <linux/atm.h>
34#include <linux/atmdev.h>
35#include <linux/skbuff.h>
36#include <linux/sysfs.h>
37#include <linux/device.h>
38#include <linux/kobject.h>
39
40#define VERSION "0.04"
41#define PTAG "solos-pci"
42
43#define CONFIG_RAM_SIZE 128
44#define FLAGS_ADDR 0x7C
45#define IRQ_EN_ADDR 0x78
46#define FPGA_VER 0x74
47#define IRQ_CLEAR 0x70
48#define BUG_FLAG 0x6C
49
50#define DATA_RAM_SIZE 32768
51#define BUF_SIZE 4096
52
53#define RX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2)
54#define TX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2 + BUF_SIZE)
55
56static int debug = 0;
57static int atmdebug = 0;
58
59struct pkt_hdr {
60 __le16 size;
61 __le16 vpi;
62 __le16 vci;
63 __le16 type;
64};
65
66#define PKT_DATA 0
67#define PKT_COMMAND 1
68#define PKT_POPEN 3
69#define PKT_PCLOSE 4
70
71struct solos_card {
72 void __iomem *config_regs;
73 void __iomem *buffers;
74 int nr_ports;
75 struct pci_dev *dev;
76 struct atm_dev *atmdev[4];
77 struct tasklet_struct tlet;
78 spinlock_t tx_lock;
79 spinlock_t tx_queue_lock;
80 spinlock_t cli_queue_lock;
81 struct sk_buff_head tx_queue[4];
82 struct sk_buff_head cli_queue[4];
83};
84
85#define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
86
87MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
88MODULE_DESCRIPTION("Solos PCI driver");
89MODULE_VERSION(VERSION);
90MODULE_LICENSE("GPL");
91MODULE_PARM_DESC(debug, "Enable Loopback");
92MODULE_PARM_DESC(atmdebug, "Print ATM data");
93module_param(debug, int, 0444);
94module_param(atmdebug, int, 0444);
95
96static int opens;
97
98static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
99 struct atm_vcc *vcc);
100static int fpga_tx(struct solos_card *);
101static irqreturn_t solos_irq(int irq, void *dev_id);
102static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
103static int list_vccs(int vci);
104static int atm_init(struct solos_card *);
105static void atm_remove(struct solos_card *);
106static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
107static void solos_bh(unsigned long);
108static int print_buffer(struct sk_buff *buf);
109
110static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb)
111{
112 if (vcc->pop)
113 vcc->pop(vcc, skb);
114 else
115 dev_kfree_skb_any(skb);
116}
117
118static ssize_t console_show(struct device *dev, struct device_attribute *attr,
119 char *buf)
120{
121 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
122 struct solos_card *card = atmdev->dev_data;
123 struct sk_buff *skb;
124
125 spin_lock(&card->cli_queue_lock);
126 skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
127 spin_unlock(&card->cli_queue_lock);
128 if(skb == NULL)
129 return sprintf(buf, "No data.\n");
130
131 memcpy(buf, skb->data, skb->len);
132 dev_dbg(&card->dev->dev, "len: %d\n", skb->len);
133
134 kfree_skb(skb);
135 return skb->len;
136}
137
138static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
139{
140 struct sk_buff *skb;
141 struct pkt_hdr *header;
142
143// dev_dbg(&card->dev->dev, "size: %d\n", size);
144
145 if (size > (BUF_SIZE - sizeof(*header))) {
146 dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n");
147 return 0;
148 }
149 skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC);
150 if (!skb) {
151 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n");
152 return 0;
153 }
154
155 header = (void *)skb_put(skb, sizeof(*header));
156
157 header->size = cpu_to_le16(size);
158 header->vpi = cpu_to_le16(0);
159 header->vci = cpu_to_le16(0);
160 header->type = cpu_to_le16(PKT_COMMAND);
161
162 memcpy(skb_put(skb, size), buf, size);
163
164 fpga_queue(card, dev, skb, NULL);
165
166 return 0;
167}
168
169static ssize_t console_store(struct device *dev, struct device_attribute *attr,
170 const char *buf, size_t count)
171{
172 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
173 struct solos_card *card = atmdev->dev_data;
174 int err;
175
176 err = send_command(card, SOLOS_CHAN(atmdev), buf, count);
177
178 return err?:count;
179}
180
181static DEVICE_ATTR(console, 0644, console_show, console_store);
182
183static irqreturn_t solos_irq(int irq, void *dev_id)
184{
185 struct solos_card *card = dev_id;
186 int handled = 1;
187
188 //ACK IRQ
189 iowrite32(0, card->config_regs + IRQ_CLEAR);
190 //Disable IRQs from FPGA
191 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
192
193 /* If we only do it when the device is open, we lose console
194 messages */
195 if (1 || opens)
196 tasklet_schedule(&card->tlet);
197
198 //Enable IRQs from FPGA
199 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
200 return IRQ_RETVAL(handled);
201}
202
203void solos_bh(unsigned long card_arg)
204{
205 struct solos_card *card = (void *)card_arg;
206 int port;
207 uint32_t card_flags;
208 uint32_t tx_mask;
209 uint32_t rx_done = 0;
210
211 card_flags = ioread32(card->config_regs + FLAGS_ADDR);
212
213 /* The TX bits are set if the channel is busy; clear if not. We want to
214 invoke fpga_tx() unless _all_ the bits for active channels are set */
215 tx_mask = (1 << card->nr_ports) - 1;
216 if ((card_flags & tx_mask) != tx_mask)
217 fpga_tx(card);
218
219 for (port = 0; port < card->nr_ports; port++) {
220 if (card_flags & (0x10 << port)) {
221 struct pkt_hdr header;
222 struct sk_buff *skb;
223 struct atm_vcc *vcc;
224 int size;
225
226 rx_done |= 0x10 << port;
227
228 memcpy_fromio(&header, RX_BUF(card, port), sizeof(header));
229
230 size = le16_to_cpu(header.size);
231
232 skb = alloc_skb(size, GFP_ATOMIC);
233 if (!skb) {
234 if (net_ratelimit())
235 dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
236 continue;
237 }
238
239 memcpy_fromio(skb_put(skb, size),
240 RX_BUF(card, port) + sizeof(header),
241 size);
242
243 if (atmdebug) {
244 dev_info(&card->dev->dev, "Received: device %d\n", port);
245 dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n",
246 size, le16_to_cpu(header.vpi),
247 le16_to_cpu(header.vci));
248 print_buffer(skb);
249 }
250
251 switch (le16_to_cpu(header.type)) {
252 case PKT_DATA:
253 vcc = find_vcc(card->atmdev[port], le16_to_cpu(header.vpi),
254 le16_to_cpu(header.vci));
255 if (!vcc) {
256 if (net_ratelimit())
257 dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
258 le16_to_cpu(header.vci), le16_to_cpu(header.vpi),
259 port);
260 continue;
261 }
262 atm_charge(vcc, skb->truesize);
263 vcc->push(vcc, skb);
264 atomic_inc(&vcc->stats->rx);
265 break;
266
267 case PKT_COMMAND:
268 default: /* FIXME: Not really, surely? */
269 spin_lock(&card->cli_queue_lock);
270 if (skb_queue_len(&card->cli_queue[port]) > 10) {
271 if (net_ratelimit())
272 dev_warn(&card->dev->dev, "Dropping console response on port %d\n",
273 port);
274 } else
275 skb_queue_tail(&card->cli_queue[port], skb);
276 spin_unlock(&card->cli_queue_lock);
277 break;
278 }
279 }
280 }
281 if (rx_done)
282 iowrite32(rx_done, card->config_regs + FLAGS_ADDR);
283
284 return;
285}
286
287static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
288{
289 struct hlist_head *head;
290 struct atm_vcc *vcc = NULL;
291 struct hlist_node *node;
292 struct sock *s;
293
294 read_lock(&vcc_sklist_lock);
295 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
296 sk_for_each(s, node, head) {
297 vcc = atm_sk(s);
298 if (vcc->dev == dev && vcc->vci == vci &&
299 vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE)
300 goto out;
301 }
302 vcc = NULL;
303 out:
304 read_unlock(&vcc_sklist_lock);
305 return vcc;
306}
307
308static int list_vccs(int vci)
309{
310 struct hlist_head *head;
311 struct atm_vcc *vcc;
312 struct hlist_node *node;
313 struct sock *s;
314 int num_found = 0;
315 int i;
316
317 read_lock(&vcc_sklist_lock);
318 if (vci != 0){
319 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
320 sk_for_each(s, node, head) {
321 num_found ++;
322 vcc = atm_sk(s);
323 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
324 vcc->dev->number,
325 vcc->vpi,
326 vcc->vci);
327 }
328 } else {
329 for(i=0; i<32; i++){
330 head = &vcc_hash[i];
331 sk_for_each(s, node, head) {
332 num_found ++;
333 vcc = atm_sk(s);
334 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
335 vcc->dev->number,
336 vcc->vpi,
337 vcc->vci);
338 }
339 }
340 }
341 read_unlock(&vcc_sklist_lock);
342 return num_found;
343}
344
345
346static int popen(struct atm_vcc *vcc)
347{
348 struct solos_card *card = vcc->dev->dev_data;
349 struct sk_buff *skb;
350 struct pkt_hdr *header;
351
352 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
353 if (!skb && net_ratelimit()) {
354 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
355 return -ENOMEM;
356 }
357 header = (void *)skb_put(skb, sizeof(*header));
358
359 header->size = cpu_to_le16(sizeof(*header));
360 header->vpi = cpu_to_le16(vcc->vpi);
361 header->vci = cpu_to_le16(vcc->vci);
362 header->type = cpu_to_le16(PKT_POPEN);
363
364 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
365
366// dev_dbg(&card->dev->dev, "Open for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
367 set_bit(ATM_VF_ADDR, &vcc->flags); // accept the vpi / vci
368 set_bit(ATM_VF_READY, &vcc->flags);
369 list_vccs(0);
370
371 if (!opens)
372 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
373
374 opens++; //count open PVCs
375
376 return 0;
377}
378
379static void pclose(struct atm_vcc *vcc)
380{
381 struct solos_card *card = vcc->dev->dev_data;
382 struct sk_buff *skb;
383 struct pkt_hdr *header;
384
385 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
386 if (!skb) {
387 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
388 return;
389 }
390 header = (void *)skb_put(skb, sizeof(*header));
391
392 header->size = cpu_to_le16(sizeof(*header));
393 header->vpi = cpu_to_le16(vcc->vpi);
394 header->vci = cpu_to_le16(vcc->vci);
395 header->type = cpu_to_le16(PKT_PCLOSE);
396
397 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
398
399// dev_dbg(&card->dev->dev, "Close for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
400 if (!--opens)
401 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
402
403 clear_bit(ATM_VF_ADDR, &vcc->flags);
404 clear_bit(ATM_VF_READY, &vcc->flags);
405
406 return;
407}
408
409static int print_buffer(struct sk_buff *buf)
410{
411 int len,i;
412 char msg[500];
413 char item[10];
414
415 len = buf->len;
416 for (i = 0; i < len; i++){
417 if(i % 8 == 0)
418 sprintf(msg, "%02X: ", i);
419
420 sprintf(item,"%02X ",*(buf->data + i));
421 strcat(msg, item);
422 if(i % 8 == 7) {
423 sprintf(item, "\n");
424 strcat(msg, item);
425 printk(KERN_DEBUG "%s", msg);
426 }
427 }
428 if (i % 8 != 0) {
429 sprintf(item, "\n");
430 strcat(msg, item);
431 printk(KERN_DEBUG "%s", msg);
432 }
433 printk(KERN_DEBUG "\n");
434
435 return 0;
436}
437
438static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
439 struct atm_vcc *vcc)
440{
441 int old_len;
442
443 *(void **)skb->cb = vcc;
444
445 spin_lock(&card->tx_queue_lock);
446 old_len = skb_queue_len(&card->tx_queue[port]);
447 skb_queue_tail(&card->tx_queue[port], skb);
448 spin_unlock(&card->tx_queue_lock);
449
450 /* If TX might need to be started, do so */
451 if (!old_len)
452 fpga_tx(card);
453}
454
455static int fpga_tx(struct solos_card *card)
456{
457 uint32_t tx_pending;
458 uint32_t tx_started = 0;
459 struct sk_buff *skb;
460 struct atm_vcc *vcc;
461 unsigned char port;
462 unsigned long flags;
463
464 spin_lock_irqsave(&card->tx_lock, flags);
465
466 tx_pending = ioread32(card->config_regs + FLAGS_ADDR);
467
468 dev_vdbg(&card->dev->dev, "TX Flags are %X\n", tx_pending);
469
470 for (port = 0; port < card->nr_ports; port++) {
471 if (!(tx_pending & (1 << port))) {
472
473 spin_lock(&card->tx_queue_lock);
474 skb = skb_dequeue(&card->tx_queue[port]);
475 spin_unlock(&card->tx_queue_lock);
476
477 if (!skb)
478 continue;
479
480 if (atmdebug) {
481 dev_info(&card->dev->dev, "Transmitted: port %d\n",
482 port);
483 print_buffer(skb);
484 }
485 memcpy_toio(TX_BUF(card, port), skb->data, skb->len);
486
487 vcc = *(void **)skb->cb;
488
489 if (vcc) {
490 atomic_inc(&vcc->stats->tx);
491 solos_pop(vcc, skb);
492 } else
493 dev_kfree_skb_irq(skb);
494
495 tx_started |= 1 << port; //Set TX full flag
496 }
497 }
498 if (tx_started)
499 iowrite32(tx_started, card->config_regs + FLAGS_ADDR);
500
501 spin_unlock_irqrestore(&card->tx_lock, flags);
502 return 0;
503}
504
505static int psend(struct atm_vcc *vcc, struct sk_buff *skb)
506{
507 struct solos_card *card = vcc->dev->dev_data;
508 struct sk_buff *skb2 = NULL;
509 struct pkt_hdr *header;
510
511 //dev_dbg(&card->dev->dev, "psend called.\n");
512 //dev_dbg(&card->dev->dev, "dev,vpi,vci = %d,%d,%d\n",SOLOS_CHAN(vcc->dev),vcc->vpi,vcc->vci);
513
514 if (debug) {
515 skb2 = atm_alloc_charge(vcc, skb->len, GFP_ATOMIC);
516 if (skb2) {
517 memcpy(skb2->data, skb->data, skb->len);
518 skb_put(skb2, skb->len);
519 vcc->push(vcc, skb2);
520 atomic_inc(&vcc->stats->rx);
521 }
522 atomic_inc(&vcc->stats->tx);
523 solos_pop(vcc, skb);
524 return 0;
525 }
526
527 if (skb->len > (BUF_SIZE - sizeof(*header))) {
528 dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
529 solos_pop(vcc, skb);
530 return 0;
531 }
532
533 if (!skb_clone_writable(skb, sizeof(*header))) {
534 int expand_by = 0;
535 int ret;
536
537 if (skb_headroom(skb) < sizeof(*header))
538 expand_by = sizeof(*header) - skb_headroom(skb);
539
540 ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
541 if (ret) {
542 solos_pop(vcc, skb);
543 return ret;
544 }
545 }
546
547 header = (void *)skb_push(skb, sizeof(*header));
548
549 header->size = cpu_to_le16(skb->len);
550 header->vpi = cpu_to_le16(vcc->vpi);
551 header->vci = cpu_to_le16(vcc->vci);
552 header->type = cpu_to_le16(PKT_DATA);
553
554 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
555
556 return 0;
557}
558
559static struct atmdev_ops fpga_ops = {
560 .open = popen,
561 .close = pclose,
562 .ioctl = NULL,
563 .getsockopt = NULL,
564 .setsockopt = NULL,
565 .send = psend,
566 .send_oam = NULL,
567 .phy_put = NULL,
568 .phy_get = NULL,
569 .change_qos = NULL,
570 .proc_read = NULL,
571 .owner = THIS_MODULE
572};
573
574static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
575{
576 int err, i;
577 uint16_t fpga_ver;
578 uint8_t major_ver, minor_ver;
579 uint32_t data32;
580 struct solos_card *card;
581
582 if (debug)
583 return 0;
584
585 card = kzalloc(sizeof(*card), GFP_KERNEL);
586 if (!card)
587 return -ENOMEM;
588
589 card->dev = dev;
590
591 err = pci_enable_device(dev);
592 if (err) {
593 dev_warn(&dev->dev, "Failed to enable PCI device\n");
594 goto out;
595 }
596
597 err = pci_request_regions(dev, "solos");
598 if (err) {
599 dev_warn(&dev->dev, "Failed to request regions\n");
600 goto out;
601 }
602
603 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
604 if (!card->config_regs) {
605 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
606 goto out_release_regions;
607 }
608 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
609 if (!card->buffers) {
610 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
611 goto out_unmap_config;
612 }
613
614// for(i=0;i<64 ;i+=4){
615// data32=ioread32(card->buffers + i);
616// dev_dbg(&card->dev->dev, "%08lX\n",(unsigned long)data32);
617// }
618
619 //Fill Config Mem with zeros
620 for(i = 0; i < 128; i += 4)
621 iowrite32(0, card->config_regs + i);
622
623 //Set RX empty flags
624 iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
625
626 data32 = ioread32(card->config_regs + FPGA_VER);
627 fpga_ver = (data32 & 0x0000FFFF);
628 major_ver = ((data32 & 0xFF000000) >> 24);
629 minor_ver = ((data32 & 0x00FF0000) >> 16);
630 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
631 major_ver, minor_ver, fpga_ver);
632
633 card->nr_ports = 2; /* FIXME: Detect daughterboard */
634
635 err = atm_init(card);
636 if (err)
637 goto out_unmap_both;
638
639 pci_set_drvdata(dev, card);
640 tasklet_init(&card->tlet, solos_bh, (unsigned long)card);
641 spin_lock_init(&card->tx_lock);
642 spin_lock_init(&card->tx_queue_lock);
643 spin_lock_init(&card->cli_queue_lock);
644/*
645 // Set Loopback mode
646 data32 = 0x00010000;
647 iowrite32(data32,card->config_regs + FLAGS_ADDR);
648*/
649/*
650 // Fill Buffers with zeros
651 for (i = 0; i < BUF_SIZE * 8; i += 4)
652 iowrite32(0, card->buffers + i);
653*/
654/*
655 for(i = 0; i < (BUF_SIZE * 1); i += 4)
656 iowrite32(0x12345678, card->buffers + i + (0*BUF_SIZE));
657 for(i = 0; i < (BUF_SIZE * 1); i += 4)
658 iowrite32(0xabcdef98, card->buffers + i + (1*BUF_SIZE));
659
660 // Read Config Memory
661 printk(KERN_DEBUG "Reading Config MEM\n");
662 i = 0;
663 for(i = 0; i < 16; i++) {
664 data32=ioread32(card->buffers + i*(BUF_SIZE/2));
665 printk(KERN_ALERT "Addr: %lX Data: %08lX\n",
666 (unsigned long)(addr_start + i*(BUF_SIZE/2)),
667 (unsigned long)data32);
668 }
669*/
670 //dev_dbg(&card->dev->dev, "Requesting IRQ: %d\n",dev->irq);
671 err = request_irq(dev->irq, solos_irq, IRQF_DISABLED|IRQF_SHARED,
672 "solos-pci", card);
673 if (err)
674 dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
675
676 // Enable IRQs
677 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
678
679 return 0;
680
681 out_unmap_both:
682 pci_iounmap(dev, card->config_regs);
683 out_unmap_config:
684 pci_iounmap(dev, card->buffers);
685 out_release_regions:
686 pci_release_regions(dev);
687 out:
688 return err;
689}
690
691static int atm_init(struct solos_card *card)
692{
693 int i;
694
695 opens = 0;
696
697 for (i = 0; i < card->nr_ports; i++) {
698 skb_queue_head_init(&card->tx_queue[i]);
699 skb_queue_head_init(&card->cli_queue[i]);
700
701 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
702 if (!card->atmdev[i]) {
703 dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
704 atm_remove(card);
705 return -ENODEV;
706 }
707 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
708 dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
709
710 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
711
712 card->atmdev[i]->ci_range.vpi_bits = 8;
713 card->atmdev[i]->ci_range.vci_bits = 16;
714 card->atmdev[i]->dev_data = card;
715 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
716 }
717 return 0;
718}
719
720static void atm_remove(struct solos_card *card)
721{
722 int i;
723
724 for (i = 0; i < card->nr_ports; i++) {
725 if (card->atmdev[i]) {
726 dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
727 atm_dev_deregister(card->atmdev[i]);
728 }
729 }
730}
731
732static void fpga_remove(struct pci_dev *dev)
733{
734 struct solos_card *card = pci_get_drvdata(dev);
735
736 if (debug)
737 return;
738
739 atm_remove(card);
740
741 dev_vdbg(&dev->dev, "Freeing IRQ\n");
742 // Disable IRQs from FPGA
743 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
744 free_irq(dev->irq, card);
745 tasklet_kill(&card->tlet);
746
747 // iowrite32(0x01,pciregs);
748 dev_vdbg(&dev->dev, "Unmapping PCI resource\n");
749 pci_iounmap(dev, card->buffers);
750 pci_iounmap(dev, card->config_regs);
751
752 dev_vdbg(&dev->dev, "Releasing PCI Region\n");
753 pci_release_regions(dev);
754 pci_disable_device(dev);
755
756 pci_set_drvdata(dev, NULL);
757 kfree(card);
758// dev_dbg(&card->dev->dev, "fpga_remove\n");
759 return;
760}
761
762static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
763 { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
764 { 0, }
765};
766
767MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
768
769static struct pci_driver fpga_driver = {
770 .name = "solos",
771 .id_table = fpga_pci_tbl,
772 .probe = fpga_probe,
773 .remove = fpga_remove,
774};
775
776
777static int __init solos_pci_init(void)
778{
779 printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
780 return pci_register_driver(&fpga_driver);
781}
782
783static void __exit solos_pci_exit(void)
784{
785 pci_unregister_driver(&fpga_driver);
786 printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
787}
788
789module_init(solos_pci_init);
790module_exit(solos_pci_exit);