blob: 3daa3a3743131dab6957c4d79c24a75f99006bae [file] [log] [blame]
David Woodhouse9c540042008-12-23 04:09:02 +00001/*
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);
Simon Farnsworth4306cad2009-01-19 21:19:29 +000094module_param(atmdebug, int, 0644);
David Woodhouse9c540042008-12-23 04:09:02 +000095
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
David Woodhouseb76811a2009-01-27 10:18:51 +1100359 header->size = cpu_to_le16(0);
David Woodhouse9c540042008-12-23 04:09:02 +0000360 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
David Woodhouseb76811a2009-01-27 10:18:51 +1100392 header->size = cpu_to_le16(0);
David Woodhouse9c540042008-12-23 04:09:02 +0000393 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;
David Woodhouseb76811a2009-01-27 10:18:51 +1100510 int pktlen;
David Woodhouse9c540042008-12-23 04:09:02 +0000511
512 //dev_dbg(&card->dev->dev, "psend called.\n");
513 //dev_dbg(&card->dev->dev, "dev,vpi,vci = %d,%d,%d\n",SOLOS_CHAN(vcc->dev),vcc->vpi,vcc->vci);
514
515 if (debug) {
516 skb2 = atm_alloc_charge(vcc, skb->len, GFP_ATOMIC);
517 if (skb2) {
518 memcpy(skb2->data, skb->data, skb->len);
519 skb_put(skb2, skb->len);
520 vcc->push(vcc, skb2);
521 atomic_inc(&vcc->stats->rx);
522 }
523 atomic_inc(&vcc->stats->tx);
524 solos_pop(vcc, skb);
525 return 0;
526 }
527
David Woodhouseb76811a2009-01-27 10:18:51 +1100528 pktlen = skb->len;
529 if (pktlen > (BUF_SIZE - sizeof(*header))) {
David Woodhouse9c540042008-12-23 04:09:02 +0000530 dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
531 solos_pop(vcc, skb);
532 return 0;
533 }
534
535 if (!skb_clone_writable(skb, sizeof(*header))) {
536 int expand_by = 0;
537 int ret;
538
539 if (skb_headroom(skb) < sizeof(*header))
540 expand_by = sizeof(*header) - skb_headroom(skb);
541
542 ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
543 if (ret) {
Simon Farnsworth4306cad2009-01-19 21:19:29 +0000544 dev_warn(&card->dev->dev, "pskb_expand_head failed.\n");
David Woodhouse9c540042008-12-23 04:09:02 +0000545 solos_pop(vcc, skb);
546 return ret;
547 }
548 }
549
550 header = (void *)skb_push(skb, sizeof(*header));
551
David Woodhouseb76811a2009-01-27 10:18:51 +1100552 /* This does _not_ include the size of the header */
553 header->size = cpu_to_le16(pktlen);
David Woodhouse9c540042008-12-23 04:09:02 +0000554 header->vpi = cpu_to_le16(vcc->vpi);
555 header->vci = cpu_to_le16(vcc->vci);
556 header->type = cpu_to_le16(PKT_DATA);
557
558 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
559
560 return 0;
561}
562
563static struct atmdev_ops fpga_ops = {
564 .open = popen,
565 .close = pclose,
566 .ioctl = NULL,
567 .getsockopt = NULL,
568 .setsockopt = NULL,
569 .send = psend,
570 .send_oam = NULL,
571 .phy_put = NULL,
572 .phy_get = NULL,
573 .change_qos = NULL,
574 .proc_read = NULL,
575 .owner = THIS_MODULE
576};
577
578static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
579{
580 int err, i;
581 uint16_t fpga_ver;
582 uint8_t major_ver, minor_ver;
583 uint32_t data32;
584 struct solos_card *card;
585
586 if (debug)
587 return 0;
588
589 card = kzalloc(sizeof(*card), GFP_KERNEL);
590 if (!card)
591 return -ENOMEM;
592
593 card->dev = dev;
594
595 err = pci_enable_device(dev);
596 if (err) {
597 dev_warn(&dev->dev, "Failed to enable PCI device\n");
598 goto out;
599 }
600
601 err = pci_request_regions(dev, "solos");
602 if (err) {
603 dev_warn(&dev->dev, "Failed to request regions\n");
604 goto out;
605 }
606
607 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
608 if (!card->config_regs) {
609 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
610 goto out_release_regions;
611 }
612 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
613 if (!card->buffers) {
614 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
615 goto out_unmap_config;
616 }
617
618// for(i=0;i<64 ;i+=4){
619// data32=ioread32(card->buffers + i);
620// dev_dbg(&card->dev->dev, "%08lX\n",(unsigned long)data32);
621// }
622
623 //Fill Config Mem with zeros
624 for(i = 0; i < 128; i += 4)
625 iowrite32(0, card->config_regs + i);
626
627 //Set RX empty flags
628 iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
629
630 data32 = ioread32(card->config_regs + FPGA_VER);
631 fpga_ver = (data32 & 0x0000FFFF);
632 major_ver = ((data32 & 0xFF000000) >> 24);
633 minor_ver = ((data32 & 0x00FF0000) >> 16);
634 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
635 major_ver, minor_ver, fpga_ver);
636
637 card->nr_ports = 2; /* FIXME: Detect daughterboard */
638
639 err = atm_init(card);
640 if (err)
641 goto out_unmap_both;
642
643 pci_set_drvdata(dev, card);
644 tasklet_init(&card->tlet, solos_bh, (unsigned long)card);
645 spin_lock_init(&card->tx_lock);
646 spin_lock_init(&card->tx_queue_lock);
647 spin_lock_init(&card->cli_queue_lock);
648/*
649 // Set Loopback mode
650 data32 = 0x00010000;
651 iowrite32(data32,card->config_regs + FLAGS_ADDR);
652*/
653/*
654 // Fill Buffers with zeros
655 for (i = 0; i < BUF_SIZE * 8; i += 4)
656 iowrite32(0, card->buffers + i);
657*/
658/*
659 for(i = 0; i < (BUF_SIZE * 1); i += 4)
660 iowrite32(0x12345678, card->buffers + i + (0*BUF_SIZE));
661 for(i = 0; i < (BUF_SIZE * 1); i += 4)
662 iowrite32(0xabcdef98, card->buffers + i + (1*BUF_SIZE));
663
664 // Read Config Memory
665 printk(KERN_DEBUG "Reading Config MEM\n");
666 i = 0;
667 for(i = 0; i < 16; i++) {
668 data32=ioread32(card->buffers + i*(BUF_SIZE/2));
669 printk(KERN_ALERT "Addr: %lX Data: %08lX\n",
670 (unsigned long)(addr_start + i*(BUF_SIZE/2)),
671 (unsigned long)data32);
672 }
673*/
674 //dev_dbg(&card->dev->dev, "Requesting IRQ: %d\n",dev->irq);
675 err = request_irq(dev->irq, solos_irq, IRQF_DISABLED|IRQF_SHARED,
676 "solos-pci", card);
677 if (err)
678 dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
679
680 // Enable IRQs
681 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
682
683 return 0;
684
685 out_unmap_both:
686 pci_iounmap(dev, card->config_regs);
687 out_unmap_config:
688 pci_iounmap(dev, card->buffers);
689 out_release_regions:
690 pci_release_regions(dev);
691 out:
692 return err;
693}
694
695static int atm_init(struct solos_card *card)
696{
697 int i;
698
699 opens = 0;
700
701 for (i = 0; i < card->nr_ports; i++) {
702 skb_queue_head_init(&card->tx_queue[i]);
703 skb_queue_head_init(&card->cli_queue[i]);
704
705 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
706 if (!card->atmdev[i]) {
707 dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
708 atm_remove(card);
709 return -ENODEV;
710 }
711 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
712 dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
713
714 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
715
716 card->atmdev[i]->ci_range.vpi_bits = 8;
717 card->atmdev[i]->ci_range.vci_bits = 16;
718 card->atmdev[i]->dev_data = card;
719 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
720 }
721 return 0;
722}
723
724static void atm_remove(struct solos_card *card)
725{
726 int i;
727
728 for (i = 0; i < card->nr_ports; i++) {
729 if (card->atmdev[i]) {
730 dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
731 atm_dev_deregister(card->atmdev[i]);
732 }
733 }
734}
735
736static void fpga_remove(struct pci_dev *dev)
737{
738 struct solos_card *card = pci_get_drvdata(dev);
739
740 if (debug)
741 return;
742
743 atm_remove(card);
744
745 dev_vdbg(&dev->dev, "Freeing IRQ\n");
746 // Disable IRQs from FPGA
747 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
748 free_irq(dev->irq, card);
749 tasklet_kill(&card->tlet);
750
751 // iowrite32(0x01,pciregs);
752 dev_vdbg(&dev->dev, "Unmapping PCI resource\n");
753 pci_iounmap(dev, card->buffers);
754 pci_iounmap(dev, card->config_regs);
755
756 dev_vdbg(&dev->dev, "Releasing PCI Region\n");
757 pci_release_regions(dev);
758 pci_disable_device(dev);
759
760 pci_set_drvdata(dev, NULL);
761 kfree(card);
762// dev_dbg(&card->dev->dev, "fpga_remove\n");
763 return;
764}
765
766static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
767 { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
768 { 0, }
769};
770
771MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
772
773static struct pci_driver fpga_driver = {
774 .name = "solos",
775 .id_table = fpga_pci_tbl,
776 .probe = fpga_probe,
777 .remove = fpga_remove,
778};
779
780
781static int __init solos_pci_init(void)
782{
783 printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
784 return pci_register_driver(&fpga_driver);
785}
786
787static void __exit solos_pci_exit(void)
788{
789 pci_unregister_driver(&fpga_driver);
790 printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
791}
792
793module_init(solos_pci_init);
794module_exit(solos_pci_exit);