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/
7 * Copyright © 2008 Traverse Technologies
8 * Copyright © 2008 Intel Corporation
10 * Authors: Nathan Williams <nathan@traverse.com.au>
11 * David Woodhouse <dwmw2@infradead.org>
12 * Treker Chen <treker@xrio.com>
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * version 2, as published by the Free Software Foundation.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
27 #include <linux/interrupt.h>
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/errno.h>
31 #include <linux/ioport.h>
32 #include <linux/types.h>
33 #include <linux/pci.h>
34 #include <linux/atm.h>
35 #include <linux/atmdev.h>
36 #include <linux/skbuff.h>
37 #include <linux/sysfs.h>
38 #include <linux/device.h>
39 #include <linux/kobject.h>
40 #include <linux/firmware.h>
41 #include <linux/ctype.h>
42 #include <linux/swab.h>
44 #define VERSION "0.07"
45 #define PTAG "solos-pci"
47 #define CONFIG_RAM_SIZE 128
48 #define FLAGS_ADDR 0x7C
49 #define IRQ_EN_ADDR 0x78
51 #define IRQ_CLEAR 0x70
52 #define WRITE_FLASH 0x6C
54 #define FLASH_BLOCK 0x64
55 #define FLASH_BUSY 0x60
56 #define FPGA_MODE 0x5C
57 #define FLASH_MODE 0x58
59 #define DATA_RAM_SIZE 32768
61 #define FPGA_PAGE 528 /* FPGA flash page size*/
62 #define SOLOS_PAGE 512 /* Solos flash page size*/
63 #define FPGA_BLOCK (FPGA_PAGE * 8) /* FPGA flash block size*/
64 #define SOLOS_BLOCK (SOLOS_PAGE * 8) /* Solos flash block size*/
66 #define RX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2)
67 #define TX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2 + BUF_SIZE)
70 static int atmdebug = 0;
71 static int firmware_upgrade = 0;
72 static int fpga_upgrade = 0;
87 void __iomem *config_regs;
88 void __iomem *buffers;
91 struct atm_dev *atmdev[4];
92 struct tasklet_struct tlet;
94 spinlock_t tx_queue_lock;
95 spinlock_t cli_queue_lock;
96 spinlock_t param_queue_lock;
97 struct list_head param_queue;
98 struct sk_buff_head tx_queue[4];
99 struct sk_buff_head cli_queue[4];
100 wait_queue_head_t param_wq;
101 wait_queue_head_t fw_wq;
106 struct list_head list;
109 struct sk_buff *response;
110 wait_queue_head_t wq;
113 #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
115 MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
116 MODULE_DESCRIPTION("Solos PCI driver");
117 MODULE_VERSION(VERSION);
118 MODULE_LICENSE("GPL");
119 MODULE_PARM_DESC(debug, "Enable Loopback");
120 MODULE_PARM_DESC(atmdebug, "Print ATM data");
121 MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade");
122 MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade");
123 module_param(debug, int, 0444);
124 module_param(atmdebug, int, 0644);
125 module_param(firmware_upgrade, int, 0444);
126 module_param(fpga_upgrade, int, 0444);
128 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
129 struct atm_vcc *vcc);
130 static int fpga_tx(struct solos_card *);
131 static irqreturn_t solos_irq(int irq, void *dev_id);
132 static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
133 static int list_vccs(int vci);
134 static int atm_init(struct solos_card *);
135 static void atm_remove(struct solos_card *);
136 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
137 static void solos_bh(unsigned long);
138 static int print_buffer(struct sk_buff *buf);
140 static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb)
145 dev_kfree_skb_any(skb);
148 static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr,
151 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
152 struct solos_card *card = atmdev->dev_data;
153 struct solos_param prm;
155 struct pkt_hdr *header;
158 buflen = strlen(attr->attr.name) + 10;
160 skb = alloc_skb(buflen, GFP_KERNEL);
162 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n");
166 header = (void *)skb_put(skb, sizeof(*header));
168 buflen = snprintf((void *)&header[1], buflen - 1,
169 "L%05d\n%s\n", current->pid, attr->attr.name);
170 skb_put(skb, buflen);
172 header->size = cpu_to_le16(buflen);
173 header->vpi = cpu_to_le16(0);
174 header->vci = cpu_to_le16(0);
175 header->type = cpu_to_le16(PKT_COMMAND);
177 prm.pid = current->pid;
179 prm.port = SOLOS_CHAN(atmdev);
181 spin_lock_irq(&card->param_queue_lock);
182 list_add(&prm.list, &card->param_queue);
183 spin_unlock_irq(&card->param_queue_lock);
185 fpga_queue(card, prm.port, skb, NULL);
187 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
189 spin_lock_irq(&card->param_queue_lock);
191 spin_unlock_irq(&card->param_queue_lock);
196 buflen = prm.response->len;
197 memcpy(buf, prm.response->data, buflen);
198 kfree_skb(prm.response);
203 static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr,
204 const char *buf, size_t count)
206 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
207 struct solos_card *card = atmdev->dev_data;
208 struct solos_param prm;
210 struct pkt_hdr *header;
214 buflen = strlen(attr->attr.name) + 11 + count;
216 skb = alloc_skb(buflen, GFP_KERNEL);
218 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n");
222 header = (void *)skb_put(skb, sizeof(*header));
224 buflen = snprintf((void *)&header[1], buflen - 1,
225 "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf);
227 skb_put(skb, buflen);
228 header->size = cpu_to_le16(buflen);
229 header->vpi = cpu_to_le16(0);
230 header->vci = cpu_to_le16(0);
231 header->type = cpu_to_le16(PKT_COMMAND);
233 prm.pid = current->pid;
235 prm.port = SOLOS_CHAN(atmdev);
237 spin_lock_irq(&card->param_queue_lock);
238 list_add(&prm.list, &card->param_queue);
239 spin_unlock_irq(&card->param_queue_lock);
241 fpga_queue(card, prm.port, skb, NULL);
243 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
245 spin_lock_irq(&card->param_queue_lock);
247 spin_unlock_irq(&card->param_queue_lock);
256 /* Sometimes it has a newline, sometimes it doesn't. */
257 if (skb->data[buflen - 1] == '\n')
260 if (buflen == 2 && !strncmp(skb->data, "OK", 2))
262 else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5))
265 /* We know we have enough space allocated for this; we allocated
267 skb->data[buflen] = 0;
269 dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n",
278 static int process_command(struct solos_card *card, int port, struct sk_buff *skb)
280 struct solos_param *prm;
288 if (skb->data[0] != 'L' || !isdigit(skb->data[1]) ||
289 !isdigit(skb->data[2]) || !isdigit(skb->data[3]) ||
290 !isdigit(skb->data[4]) || !isdigit(skb->data[5]) ||
291 skb->data[6] != '\n')
294 cmdpid = simple_strtol(&skb->data[1], NULL, 10);
296 spin_lock_irqsave(&card->param_queue_lock, flags);
297 list_for_each_entry(prm, &card->param_queue, list) {
298 if (prm->port == port && prm->pid == cmdpid) {
301 wake_up(&card->param_wq);
306 spin_unlock_irqrestore(&card->param_queue_lock, flags);
310 static ssize_t console_show(struct device *dev, struct device_attribute *attr,
313 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
314 struct solos_card *card = atmdev->dev_data;
317 spin_lock(&card->cli_queue_lock);
318 skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
319 spin_unlock(&card->cli_queue_lock);
321 return sprintf(buf, "No data.\n");
323 memcpy(buf, skb->data, skb->len);
324 dev_dbg(&card->dev->dev, "len: %d\n", skb->len);
330 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
333 struct pkt_hdr *header;
335 // dev_dbg(&card->dev->dev, "size: %d\n", size);
337 if (size > (BUF_SIZE - sizeof(*header))) {
338 dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n");
341 skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC);
343 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n");
347 header = (void *)skb_put(skb, sizeof(*header));
349 header->size = cpu_to_le16(size);
350 header->vpi = cpu_to_le16(0);
351 header->vci = cpu_to_le16(0);
352 header->type = cpu_to_le16(PKT_COMMAND);
354 memcpy(skb_put(skb, size), buf, size);
356 fpga_queue(card, dev, skb, NULL);
361 static ssize_t console_store(struct device *dev, struct device_attribute *attr,
362 const char *buf, size_t count)
364 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
365 struct solos_card *card = atmdev->dev_data;
368 err = send_command(card, SOLOS_CHAN(atmdev), buf, count);
373 static DEVICE_ATTR(console, 0644, console_show, console_store);
376 #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL);
377 #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store);
379 #include "solos-attrlist.c"
384 #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr,
385 #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr,
387 static struct attribute *solos_attrs[] = {
388 #include "solos-attrlist.c"
392 static struct attribute_group solos_attr_group = {
393 .attrs = solos_attrs,
394 .name = "parameters",
397 static int flash_upgrade(struct solos_card *card, int chip)
399 const struct firmware *fw;
407 fw_name = "solos-FPGA.bin";
408 blocksize = FPGA_BLOCK;
410 fw_name = "solos-Firmware.bin";
411 blocksize = SOLOS_BLOCK;
414 if (request_firmware(&fw, fw_name, &card->dev->dev))
417 dev_info(&card->dev->dev, "Flash upgrade starting\n");
419 numblocks = fw->size / blocksize;
420 dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size);
421 dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks);
423 dev_info(&card->dev->dev, "Changing FPGA to Update mode\n");
424 iowrite32(1, card->config_regs + FPGA_MODE);
425 data32 = ioread32(card->config_regs + FPGA_MODE);
427 /* Set mode to Chip Erase */
428 dev_info(&card->dev->dev, "Set FPGA Flash mode to %s Chip Erase\n",
429 chip?"Solos":"FPGA");
430 iowrite32((chip * 2), card->config_regs + FLASH_MODE);
433 iowrite32(1, card->config_regs + WRITE_FLASH);
434 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
436 for (offset = 0; offset < fw->size; offset += blocksize) {
439 /* Clear write flag */
440 iowrite32(0, card->config_regs + WRITE_FLASH);
442 /* Set mode to Block Write */
443 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
444 iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE);
446 /* Copy block to buffer, swapping each 16 bits */
447 for(i = 0; i < blocksize; i += 4) {
448 uint32_t word = swahb32p((uint32_t *)(fw->data + offset + i));
449 iowrite32(word, RX_BUF(card, 3) + i);
452 /* Specify block number and then trigger flash write */
453 iowrite32(offset / blocksize, card->config_regs + FLASH_BLOCK);
454 iowrite32(1, card->config_regs + WRITE_FLASH);
455 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
458 release_firmware(fw);
459 iowrite32(0, card->config_regs + WRITE_FLASH);
460 iowrite32(0, card->config_regs + FPGA_MODE);
461 iowrite32(0, card->config_regs + FLASH_MODE);
462 dev_info(&card->dev->dev, "Returning FPGA to Data mode\n");
466 static irqreturn_t solos_irq(int irq, void *dev_id)
468 struct solos_card *card = dev_id;
472 iowrite32(0, card->config_regs + IRQ_CLEAR);
473 //Disable IRQs from FPGA
474 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
477 tasklet_schedule(&card->tlet);
479 wake_up(&card->fw_wq);
481 //Enable IRQs from FPGA
482 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
483 return IRQ_RETVAL(handled);
486 void solos_bh(unsigned long card_arg)
488 struct solos_card *card = (void *)card_arg;
492 uint32_t rx_done = 0;
494 card_flags = ioread32(card->config_regs + FLAGS_ADDR);
496 /* The TX bits are set if the channel is busy; clear if not. We want to
497 invoke fpga_tx() unless _all_ the bits for active channels are set */
498 tx_mask = (1 << card->nr_ports) - 1;
499 if ((card_flags & tx_mask) != tx_mask)
502 for (port = 0; port < card->nr_ports; port++) {
503 if (card_flags & (0x10 << port)) {
504 struct pkt_hdr header;
509 rx_done |= 0x10 << port;
511 memcpy_fromio(&header, RX_BUF(card, port), sizeof(header));
513 size = le16_to_cpu(header.size);
515 skb = alloc_skb(size, GFP_ATOMIC);
518 dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
522 memcpy_fromio(skb_put(skb, size),
523 RX_BUF(card, port) + sizeof(header),
527 dev_info(&card->dev->dev, "Received: device %d\n", port);
528 dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n",
529 size, le16_to_cpu(header.vpi),
530 le16_to_cpu(header.vci));
534 switch (le16_to_cpu(header.type)) {
536 vcc = find_vcc(card->atmdev[port], le16_to_cpu(header.vpi),
537 le16_to_cpu(header.vci));
540 dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
541 le16_to_cpu(header.vci), le16_to_cpu(header.vpi),
545 atm_charge(vcc, skb->truesize);
547 atomic_inc(&vcc->stats->rx);
551 default: /* FIXME: Not really, surely? */
552 if (process_command(card, port, skb))
554 spin_lock(&card->cli_queue_lock);
555 if (skb_queue_len(&card->cli_queue[port]) > 10) {
557 dev_warn(&card->dev->dev, "Dropping console response on port %d\n",
560 skb_queue_tail(&card->cli_queue[port], skb);
561 spin_unlock(&card->cli_queue_lock);
567 iowrite32(rx_done, card->config_regs + FLAGS_ADDR);
572 static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
574 struct hlist_head *head;
575 struct atm_vcc *vcc = NULL;
576 struct hlist_node *node;
579 read_lock(&vcc_sklist_lock);
580 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
581 sk_for_each(s, node, head) {
583 if (vcc->dev == dev && vcc->vci == vci &&
584 vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE)
589 read_unlock(&vcc_sklist_lock);
593 static int list_vccs(int vci)
595 struct hlist_head *head;
597 struct hlist_node *node;
602 read_lock(&vcc_sklist_lock);
604 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
605 sk_for_each(s, node, head) {
608 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
616 sk_for_each(s, node, head) {
619 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
626 read_unlock(&vcc_sklist_lock);
631 static int popen(struct atm_vcc *vcc)
633 struct solos_card *card = vcc->dev->dev_data;
635 struct pkt_hdr *header;
637 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
638 if (!skb && net_ratelimit()) {
639 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
642 header = (void *)skb_put(skb, sizeof(*header));
644 header->size = cpu_to_le16(0);
645 header->vpi = cpu_to_le16(vcc->vpi);
646 header->vci = cpu_to_le16(vcc->vci);
647 header->type = cpu_to_le16(PKT_POPEN);
649 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
651 // dev_dbg(&card->dev->dev, "Open for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
652 set_bit(ATM_VF_ADDR, &vcc->flags); // accept the vpi / vci
653 set_bit(ATM_VF_READY, &vcc->flags);
660 static void pclose(struct atm_vcc *vcc)
662 struct solos_card *card = vcc->dev->dev_data;
664 struct pkt_hdr *header;
666 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
668 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
671 header = (void *)skb_put(skb, sizeof(*header));
673 header->size = cpu_to_le16(0);
674 header->vpi = cpu_to_le16(vcc->vpi);
675 header->vci = cpu_to_le16(vcc->vci);
676 header->type = cpu_to_le16(PKT_PCLOSE);
678 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
680 // dev_dbg(&card->dev->dev, "Close for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
682 clear_bit(ATM_VF_ADDR, &vcc->flags);
683 clear_bit(ATM_VF_READY, &vcc->flags);
688 static int print_buffer(struct sk_buff *buf)
695 for (i = 0; i < len; i++){
697 sprintf(msg, "%02X: ", i);
699 sprintf(item,"%02X ",*(buf->data + i));
704 printk(KERN_DEBUG "%s", msg);
710 printk(KERN_DEBUG "%s", msg);
712 printk(KERN_DEBUG "\n");
717 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
722 *(void **)skb->cb = vcc;
724 spin_lock(&card->tx_queue_lock);
725 old_len = skb_queue_len(&card->tx_queue[port]);
726 skb_queue_tail(&card->tx_queue[port], skb);
727 spin_unlock(&card->tx_queue_lock);
729 /* If TX might need to be started, do so */
734 static int fpga_tx(struct solos_card *card)
737 uint32_t tx_started = 0;
743 spin_lock_irqsave(&card->tx_lock, flags);
745 tx_pending = ioread32(card->config_regs + FLAGS_ADDR);
747 dev_vdbg(&card->dev->dev, "TX Flags are %X\n", tx_pending);
749 for (port = 0; port < card->nr_ports; port++) {
750 if (!(tx_pending & (1 << port))) {
752 spin_lock(&card->tx_queue_lock);
753 skb = skb_dequeue(&card->tx_queue[port]);
754 spin_unlock(&card->tx_queue_lock);
760 dev_info(&card->dev->dev, "Transmitted: port %d\n",
764 memcpy_toio(TX_BUF(card, port), skb->data, skb->len);
766 vcc = *(void **)skb->cb;
769 atomic_inc(&vcc->stats->tx);
772 dev_kfree_skb_irq(skb);
774 tx_started |= 1 << port; //Set TX full flag
778 iowrite32(tx_started, card->config_regs + FLAGS_ADDR);
780 spin_unlock_irqrestore(&card->tx_lock, flags);
784 static int psend(struct atm_vcc *vcc, struct sk_buff *skb)
786 struct solos_card *card = vcc->dev->dev_data;
787 struct sk_buff *skb2 = NULL;
788 struct pkt_hdr *header;
791 //dev_dbg(&card->dev->dev, "psend called.\n");
792 //dev_dbg(&card->dev->dev, "dev,vpi,vci = %d,%d,%d\n",SOLOS_CHAN(vcc->dev),vcc->vpi,vcc->vci);
795 skb2 = atm_alloc_charge(vcc, skb->len, GFP_ATOMIC);
797 memcpy(skb2->data, skb->data, skb->len);
798 skb_put(skb2, skb->len);
799 vcc->push(vcc, skb2);
800 atomic_inc(&vcc->stats->rx);
802 atomic_inc(&vcc->stats->tx);
808 if (pktlen > (BUF_SIZE - sizeof(*header))) {
809 dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
814 if (!skb_clone_writable(skb, sizeof(*header))) {
818 if (skb_headroom(skb) < sizeof(*header))
819 expand_by = sizeof(*header) - skb_headroom(skb);
821 ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
823 dev_warn(&card->dev->dev, "pskb_expand_head failed.\n");
829 header = (void *)skb_push(skb, sizeof(*header));
831 /* This does _not_ include the size of the header */
832 header->size = cpu_to_le16(pktlen);
833 header->vpi = cpu_to_le16(vcc->vpi);
834 header->vci = cpu_to_le16(vcc->vci);
835 header->type = cpu_to_le16(PKT_DATA);
837 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
842 static struct atmdev_ops fpga_ops = {
857 static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
861 uint8_t major_ver, minor_ver;
863 struct solos_card *card;
868 card = kzalloc(sizeof(*card), GFP_KERNEL);
873 init_waitqueue_head(&card->fw_wq);
874 init_waitqueue_head(&card->param_wq);
876 err = pci_enable_device(dev);
878 dev_warn(&dev->dev, "Failed to enable PCI device\n");
882 err = pci_request_regions(dev, "solos");
884 dev_warn(&dev->dev, "Failed to request regions\n");
888 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
889 if (!card->config_regs) {
890 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
891 goto out_release_regions;
893 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
894 if (!card->buffers) {
895 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
896 goto out_unmap_config;
899 // for(i=0;i<64 ;i+=4){
900 // data32=ioread32(card->buffers + i);
901 // dev_dbg(&card->dev->dev, "%08lX\n",(unsigned long)data32);
904 //Fill Config Mem with zeros
905 for(i = 0; i < 128; i += 4)
906 iowrite32(0, card->config_regs + i);
909 iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
911 data32 = ioread32(card->config_regs + FPGA_VER);
912 fpga_ver = (data32 & 0x0000FFFF);
913 major_ver = ((data32 & 0xFF000000) >> 24);
914 minor_ver = ((data32 & 0x00FF0000) >> 16);
915 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
916 major_ver, minor_ver, fpga_ver);
918 card->nr_ports = 2; /* FIXME: Detect daughterboard */
920 pci_set_drvdata(dev, card);
922 tasklet_init(&card->tlet, solos_bh, (unsigned long)card);
923 spin_lock_init(&card->tx_lock);
924 spin_lock_init(&card->tx_queue_lock);
925 spin_lock_init(&card->cli_queue_lock);
926 spin_lock_init(&card->param_queue_lock);
927 INIT_LIST_HEAD(&card->param_queue);
932 iowrite32(data32,card->config_regs + FLAGS_ADDR);
935 // Fill Buffers with zeros
936 for (i = 0; i < BUF_SIZE * 8; i += 4)
937 iowrite32(0, card->buffers + i);
940 for(i = 0; i < (BUF_SIZE * 1); i += 4)
941 iowrite32(0x12345678, card->buffers + i + (0*BUF_SIZE));
942 for(i = 0; i < (BUF_SIZE * 1); i += 4)
943 iowrite32(0xabcdef98, card->buffers + i + (1*BUF_SIZE));
945 // Read Config Memory
946 printk(KERN_DEBUG "Reading Config MEM\n");
948 for(i = 0; i < 16; i++) {
949 data32=ioread32(card->buffers + i*(BUF_SIZE/2));
950 printk(KERN_ALERT "Addr: %lX Data: %08lX\n",
951 (unsigned long)(addr_start + i*(BUF_SIZE/2)),
952 (unsigned long)data32);
955 //dev_dbg(&card->dev->dev, "Requesting IRQ: %d\n",dev->irq);
956 err = request_irq(dev->irq, solos_irq, IRQF_DISABLED|IRQF_SHARED,
959 dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
964 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
967 flash_upgrade(card, 0);
969 if (firmware_upgrade)
970 flash_upgrade(card, 1);
972 err = atm_init(card);
979 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
980 free_irq(dev->irq, card);
981 tasklet_kill(&card->tlet);
984 pci_set_drvdata(dev, NULL);
985 pci_iounmap(dev, card->config_regs);
987 pci_iounmap(dev, card->buffers);
989 pci_release_regions(dev);
994 static int atm_init(struct solos_card *card)
998 for (i = 0; i < card->nr_ports; i++) {
999 skb_queue_head_init(&card->tx_queue[i]);
1000 skb_queue_head_init(&card->cli_queue[i]);
1002 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
1003 if (!card->atmdev[i]) {
1004 dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
1008 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
1009 dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
1010 if (sysfs_create_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group))
1011 dev_err(&card->dev->dev, "Could not register parameter group for ATM device %d\n", i);
1013 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
1015 card->atmdev[i]->ci_range.vpi_bits = 8;
1016 card->atmdev[i]->ci_range.vci_bits = 16;
1017 card->atmdev[i]->dev_data = card;
1018 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
1023 static void atm_remove(struct solos_card *card)
1027 for (i = 0; i < card->nr_ports; i++) {
1028 if (card->atmdev[i]) {
1029 dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
1030 atm_dev_deregister(card->atmdev[i]);
1035 static void fpga_remove(struct pci_dev *dev)
1037 struct solos_card *card = pci_get_drvdata(dev);
1044 dev_vdbg(&dev->dev, "Freeing IRQ\n");
1045 // Disable IRQs from FPGA
1046 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1047 free_irq(dev->irq, card);
1048 tasklet_kill(&card->tlet);
1050 // iowrite32(0x01,pciregs);
1051 dev_vdbg(&dev->dev, "Unmapping PCI resource\n");
1052 pci_iounmap(dev, card->buffers);
1053 pci_iounmap(dev, card->config_regs);
1055 dev_vdbg(&dev->dev, "Releasing PCI Region\n");
1056 pci_release_regions(dev);
1057 pci_disable_device(dev);
1059 pci_set_drvdata(dev, NULL);
1061 // dev_dbg(&card->dev->dev, "fpga_remove\n");
1065 static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
1066 { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1070 MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
1072 static struct pci_driver fpga_driver = {
1074 .id_table = fpga_pci_tbl,
1075 .probe = fpga_probe,
1076 .remove = fpga_remove,
1080 static int __init solos_pci_init(void)
1082 printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
1083 return pci_register_driver(&fpga_driver);
1086 static void __exit solos_pci_exit(void)
1088 pci_unregister_driver(&fpga_driver);
1089 printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
1092 module_init(solos_pci_init);
1093 module_exit(solos_pci_exit);