Merge branch 'x86/core' into core/percpu
[linux-2.6] / drivers / atm / solos-pci.c
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
56 static int debug = 0;
57 static int atmdebug = 0;
58
59 struct 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
71 struct 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
87 MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
88 MODULE_DESCRIPTION("Solos PCI driver");
89 MODULE_VERSION(VERSION);
90 MODULE_LICENSE("GPL");
91 MODULE_PARM_DESC(debug, "Enable Loopback");
92 MODULE_PARM_DESC(atmdebug, "Print ATM data");
93 module_param(debug, int, 0444);
94 module_param(atmdebug, int, 0444);
95
96 static int opens;
97
98 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
99                        struct atm_vcc *vcc);
100 static int fpga_tx(struct solos_card *);
101 static irqreturn_t solos_irq(int irq, void *dev_id);
102 static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
103 static int list_vccs(int vci);
104 static int atm_init(struct solos_card *);
105 static void atm_remove(struct solos_card *);
106 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
107 static void solos_bh(unsigned long);
108 static int print_buffer(struct sk_buff *buf);
109
110 static 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
118 static 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
138 static 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
169 static 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
181 static DEVICE_ATTR(console, 0644, console_show, console_store);
182
183 static 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
203 void 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
287 static 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
308 static 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
346 static 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
379 static 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
409 static 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
438 static 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
455 static 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
505 static 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
559 static 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
574 static 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         kfree(card);
689         return err;
690 }
691
692 static int atm_init(struct solos_card *card)
693 {
694         int i;
695
696         opens = 0;
697
698         for (i = 0; i < card->nr_ports; i++) {
699                 skb_queue_head_init(&card->tx_queue[i]);
700                 skb_queue_head_init(&card->cli_queue[i]);
701
702                 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
703                 if (!card->atmdev[i]) {
704                         dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
705                         atm_remove(card);
706                         return -ENODEV;
707                 }
708                 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
709                         dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
710
711                 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
712
713                 card->atmdev[i]->ci_range.vpi_bits = 8;
714                 card->atmdev[i]->ci_range.vci_bits = 16;
715                 card->atmdev[i]->dev_data = card;
716                 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
717         }
718         return 0;
719 }
720
721 static void atm_remove(struct solos_card *card)
722 {
723         int i;
724
725         for (i = 0; i < card->nr_ports; i++) {
726                 if (card->atmdev[i]) {
727                         dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
728                         atm_dev_deregister(card->atmdev[i]);
729                 }
730         }
731 }
732
733 static void fpga_remove(struct pci_dev *dev)
734 {
735         struct solos_card *card = pci_get_drvdata(dev);
736
737         if (debug)
738                 return;
739
740         atm_remove(card);
741
742         dev_vdbg(&dev->dev, "Freeing IRQ\n");
743         // Disable IRQs from FPGA
744         iowrite32(0, card->config_regs + IRQ_EN_ADDR);
745         free_irq(dev->irq, card);
746         tasklet_kill(&card->tlet);
747
748         //      iowrite32(0x01,pciregs);
749         dev_vdbg(&dev->dev, "Unmapping PCI resource\n");
750         pci_iounmap(dev, card->buffers);
751         pci_iounmap(dev, card->config_regs);
752
753         dev_vdbg(&dev->dev, "Releasing PCI Region\n");
754         pci_release_regions(dev);
755         pci_disable_device(dev);
756
757         pci_set_drvdata(dev, NULL);
758         kfree(card);
759 //      dev_dbg(&card->dev->dev, "fpga_remove\n");
760         return;
761 }
762
763 static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
764         { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
765         { 0, }
766 };
767
768 MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
769
770 static struct pci_driver fpga_driver = {
771         .name =         "solos",
772         .id_table =     fpga_pci_tbl,
773         .probe =        fpga_probe,
774         .remove =       fpga_remove,
775 };
776
777
778 static int __init solos_pci_init(void)
779 {
780         printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
781         return pci_register_driver(&fpga_driver);
782 }
783
784 static void __exit solos_pci_exit(void)
785 {
786         pci_unregister_driver(&fpga_driver);
787         printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
788 }
789
790 module_init(solos_pci_init);
791 module_exit(solos_pci_exit);