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