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
58 #define TX_DMA_ADDR(port) (0x40 + (4 * (port)))
59 #define RX_DMA_ADDR(port) (0x30 + (4 * (port)))
61 #define DATA_RAM_SIZE 32768
63 #define FPGA_PAGE 528 /* FPGA flash page size*/
64 #define SOLOS_PAGE 512 /* Solos flash page size*/
65 #define FPGA_BLOCK (FPGA_PAGE * 8) /* FPGA flash block size*/
66 #define SOLOS_BLOCK (SOLOS_PAGE * 8) /* Solos flash block size*/
68 #define RX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2)
69 #define TX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2 + BUF_SIZE)
71 #define RX_DMA_SIZE 2048
73 static int atmdebug = 0;
74 static int firmware_upgrade = 0;
75 static int fpga_upgrade = 0;
90 #define SKB_CB(skb) ((struct solos_skb_cb *)skb->cb)
99 void __iomem *config_regs;
100 void __iomem *buffers;
104 struct atm_dev *atmdev[4];
105 struct tasklet_struct tlet;
107 spinlock_t tx_queue_lock;
108 spinlock_t cli_queue_lock;
109 spinlock_t param_queue_lock;
110 struct list_head param_queue;
111 struct sk_buff_head tx_queue[4];
112 struct sk_buff_head cli_queue[4];
113 struct sk_buff *tx_skb[4];
114 struct sk_buff *rx_skb[4];
115 wait_queue_head_t param_wq;
116 wait_queue_head_t fw_wq;
122 struct list_head list;
125 struct sk_buff *response;
126 wait_queue_head_t wq;
129 #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
131 MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
132 MODULE_DESCRIPTION("Solos PCI driver");
133 MODULE_VERSION(VERSION);
134 MODULE_LICENSE("GPL");
135 MODULE_PARM_DESC(atmdebug, "Print ATM data");
136 MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade");
137 MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade");
138 module_param(atmdebug, int, 0644);
139 module_param(firmware_upgrade, int, 0444);
140 module_param(fpga_upgrade, int, 0444);
142 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
143 struct atm_vcc *vcc);
144 static int fpga_tx(struct solos_card *);
145 static irqreturn_t solos_irq(int irq, void *dev_id);
146 static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
147 static int list_vccs(int vci);
148 static void release_vccs(struct atm_dev *dev);
149 static int atm_init(struct solos_card *);
150 static void atm_remove(struct solos_card *);
151 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
152 static void solos_bh(unsigned long);
153 static int print_buffer(struct sk_buff *buf);
155 static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb)
160 dev_kfree_skb_any(skb);
163 static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr,
166 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
167 struct solos_card *card = atmdev->dev_data;
168 struct solos_param prm;
170 struct pkt_hdr *header;
173 buflen = strlen(attr->attr.name) + 10;
175 skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL);
177 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n");
181 header = (void *)skb_put(skb, sizeof(*header));
183 buflen = snprintf((void *)&header[1], buflen - 1,
184 "L%05d\n%s\n", current->pid, attr->attr.name);
185 skb_put(skb, buflen);
187 header->size = cpu_to_le16(buflen);
188 header->vpi = cpu_to_le16(0);
189 header->vci = cpu_to_le16(0);
190 header->type = cpu_to_le16(PKT_COMMAND);
192 prm.pid = current->pid;
194 prm.port = SOLOS_CHAN(atmdev);
196 spin_lock_irq(&card->param_queue_lock);
197 list_add(&prm.list, &card->param_queue);
198 spin_unlock_irq(&card->param_queue_lock);
200 fpga_queue(card, prm.port, skb, NULL);
202 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
204 spin_lock_irq(&card->param_queue_lock);
206 spin_unlock_irq(&card->param_queue_lock);
211 buflen = prm.response->len;
212 memcpy(buf, prm.response->data, buflen);
213 kfree_skb(prm.response);
218 static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr,
219 const char *buf, size_t count)
221 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
222 struct solos_card *card = atmdev->dev_data;
223 struct solos_param prm;
225 struct pkt_hdr *header;
229 buflen = strlen(attr->attr.name) + 11 + count;
231 skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL);
233 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n");
237 header = (void *)skb_put(skb, sizeof(*header));
239 buflen = snprintf((void *)&header[1], buflen - 1,
240 "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf);
242 skb_put(skb, buflen);
243 header->size = cpu_to_le16(buflen);
244 header->vpi = cpu_to_le16(0);
245 header->vci = cpu_to_le16(0);
246 header->type = cpu_to_le16(PKT_COMMAND);
248 prm.pid = current->pid;
250 prm.port = SOLOS_CHAN(atmdev);
252 spin_lock_irq(&card->param_queue_lock);
253 list_add(&prm.list, &card->param_queue);
254 spin_unlock_irq(&card->param_queue_lock);
256 fpga_queue(card, prm.port, skb, NULL);
258 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
260 spin_lock_irq(&card->param_queue_lock);
262 spin_unlock_irq(&card->param_queue_lock);
271 /* Sometimes it has a newline, sometimes it doesn't. */
272 if (skb->data[buflen - 1] == '\n')
275 if (buflen == 2 && !strncmp(skb->data, "OK", 2))
277 else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5))
280 /* We know we have enough space allocated for this; we allocated
282 skb->data[buflen] = 0;
284 dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n",
293 static char *next_string(struct sk_buff *skb)
296 char *this = skb->data;
298 while (i < skb->len) {
299 if (this[i] == '\n') {
309 * Status packet has fields separated by \n, starting with a version number
310 * for the information therein. Fields are....
313 * TxBitRate (version >= 1)
314 * RxBitRate (version >= 1)
315 * State (version >= 1)
317 static int process_status(struct solos_card *card, int port, struct sk_buff *skb)
319 char *str, *end, *state_str;
320 int ver, rate_up, rate_down, state, snr, attn;
322 if (!card->atmdev[port])
325 str = next_string(skb);
329 ver = simple_strtol(str, NULL, 10);
331 dev_warn(&card->dev->dev, "Unexpected status interrupt version %d\n",
336 str = next_string(skb);
337 rate_up = simple_strtol(str, &end, 10);
341 str = next_string(skb);
342 rate_down = simple_strtol(str, &end, 10);
346 state_str = next_string(skb);
347 if (!strcmp(state_str, "Showtime"))
348 state = ATM_PHY_SIG_FOUND;
350 state = ATM_PHY_SIG_LOST;
351 release_vccs(card->atmdev[port]);
354 str = next_string(skb);
355 snr = simple_strtol(str, &end, 10);
359 str = next_string(skb);
360 attn = simple_strtol(str, &end, 10);
364 if (state == ATM_PHY_SIG_LOST && !rate_up && !rate_down)
365 dev_info(&card->dev->dev, "Port %d ATM state: %s\n",
368 dev_info(&card->dev->dev, "Port %d ATM state: %s (%d/%d kb/s, SNR %ddB, Attn %ddB)\n",
369 port, state_str, rate_up/1000, rate_down/1000,
372 card->atmdev[port]->link_rate = rate_down;
373 card->atmdev[port]->signal = state;
378 static int process_command(struct solos_card *card, int port, struct sk_buff *skb)
380 struct solos_param *prm;
388 if (skb->data[0] != 'L' || !isdigit(skb->data[1]) ||
389 !isdigit(skb->data[2]) || !isdigit(skb->data[3]) ||
390 !isdigit(skb->data[4]) || !isdigit(skb->data[5]) ||
391 skb->data[6] != '\n')
394 cmdpid = simple_strtol(&skb->data[1], NULL, 10);
396 spin_lock_irqsave(&card->param_queue_lock, flags);
397 list_for_each_entry(prm, &card->param_queue, list) {
398 if (prm->port == port && prm->pid == cmdpid) {
401 wake_up(&card->param_wq);
406 spin_unlock_irqrestore(&card->param_queue_lock, flags);
410 static ssize_t console_show(struct device *dev, struct device_attribute *attr,
413 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
414 struct solos_card *card = atmdev->dev_data;
417 spin_lock(&card->cli_queue_lock);
418 skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
419 spin_unlock(&card->cli_queue_lock);
421 return sprintf(buf, "No data.\n");
423 memcpy(buf, skb->data, skb->len);
424 dev_dbg(&card->dev->dev, "len: %d\n", skb->len);
430 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
433 struct pkt_hdr *header;
435 // dev_dbg(&card->dev->dev, "size: %d\n", size);
437 if (size > (BUF_SIZE - sizeof(*header))) {
438 dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n");
441 skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC);
443 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n");
447 header = (void *)skb_put(skb, sizeof(*header));
449 header->size = cpu_to_le16(size);
450 header->vpi = cpu_to_le16(0);
451 header->vci = cpu_to_le16(0);
452 header->type = cpu_to_le16(PKT_COMMAND);
454 memcpy(skb_put(skb, size), buf, size);
456 fpga_queue(card, dev, skb, NULL);
461 static ssize_t console_store(struct device *dev, struct device_attribute *attr,
462 const char *buf, size_t count)
464 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
465 struct solos_card *card = atmdev->dev_data;
468 err = send_command(card, SOLOS_CHAN(atmdev), buf, count);
473 static DEVICE_ATTR(console, 0644, console_show, console_store);
476 #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL);
477 #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store);
479 #include "solos-attrlist.c"
484 #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr,
485 #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr,
487 static struct attribute *solos_attrs[] = {
488 #include "solos-attrlist.c"
492 static struct attribute_group solos_attr_group = {
493 .attrs = solos_attrs,
494 .name = "parameters",
497 static int flash_upgrade(struct solos_card *card, int chip)
499 const struct firmware *fw;
507 fw_name = "solos-FPGA.bin";
508 blocksize = FPGA_BLOCK;
510 fw_name = "solos-Firmware.bin";
511 blocksize = SOLOS_BLOCK;
514 if (request_firmware(&fw, fw_name, &card->dev->dev))
517 dev_info(&card->dev->dev, "Flash upgrade starting\n");
519 numblocks = fw->size / blocksize;
520 dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size);
521 dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks);
523 dev_info(&card->dev->dev, "Changing FPGA to Update mode\n");
524 iowrite32(1, card->config_regs + FPGA_MODE);
525 data32 = ioread32(card->config_regs + FPGA_MODE);
527 /* Set mode to Chip Erase */
528 dev_info(&card->dev->dev, "Set FPGA Flash mode to %s Chip Erase\n",
529 chip?"Solos":"FPGA");
530 iowrite32((chip * 2), card->config_regs + FLASH_MODE);
533 iowrite32(1, card->config_regs + WRITE_FLASH);
534 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
536 for (offset = 0; offset < fw->size; offset += blocksize) {
539 /* Clear write flag */
540 iowrite32(0, card->config_regs + WRITE_FLASH);
542 /* Set mode to Block Write */
543 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
544 iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE);
546 /* Copy block to buffer, swapping each 16 bits */
547 for(i = 0; i < blocksize; i += 4) {
548 uint32_t word = swahb32p((uint32_t *)(fw->data + offset + i));
549 iowrite32(word, RX_BUF(card, 3) + i);
552 /* Specify block number and then trigger flash write */
553 iowrite32(offset / blocksize, card->config_regs + FLASH_BLOCK);
554 iowrite32(1, card->config_regs + WRITE_FLASH);
555 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
558 release_firmware(fw);
559 iowrite32(0, card->config_regs + WRITE_FLASH);
560 iowrite32(0, card->config_regs + FPGA_MODE);
561 iowrite32(0, card->config_regs + FLASH_MODE);
562 dev_info(&card->dev->dev, "Returning FPGA to Data mode\n");
566 static irqreturn_t solos_irq(int irq, void *dev_id)
568 struct solos_card *card = dev_id;
572 iowrite32(0, card->config_regs + IRQ_CLEAR);
575 tasklet_schedule(&card->tlet);
577 wake_up(&card->fw_wq);
579 return IRQ_RETVAL(handled);
582 void solos_bh(unsigned long card_arg)
584 struct solos_card *card = (void *)card_arg;
587 uint32_t rx_done = 0;
589 card_flags = ioread32(card->config_regs + FLAGS_ADDR);
591 /* The TX bits are set if the channel is busy; clear if not. We want to
592 invoke fpga_tx() unless _all_ the bits for active channels are set */
593 if ((card_flags & card->tx_mask) != card->tx_mask)
596 for (port = 0; port < card->nr_ports; port++) {
597 if (card_flags & (0x10 << port)) {
598 struct pkt_hdr _hdr, *header;
603 if (card->using_dma) {
604 skb = card->rx_skb[port];
605 card->rx_skb[port] = NULL;
607 pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr,
608 RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
610 header = (void *)skb->data;
611 size = le16_to_cpu(header->size);
612 skb_put(skb, size + sizeof(*header));
613 skb_pull(skb, sizeof(*header));
617 rx_done |= 0x10 << port;
619 memcpy_fromio(header, RX_BUF(card, port), sizeof(*header));
621 size = le16_to_cpu(header->size);
623 skb = alloc_skb(size + 1, GFP_ATOMIC);
626 dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
630 memcpy_fromio(skb_put(skb, size),
631 RX_BUF(card, port) + sizeof(*header),
635 dev_info(&card->dev->dev, "Received: device %d\n", port);
636 dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n",
637 size, le16_to_cpu(header->vpi),
638 le16_to_cpu(header->vci));
642 switch (le16_to_cpu(header->type)) {
644 vcc = find_vcc(card->atmdev[port], le16_to_cpu(header->vpi),
645 le16_to_cpu(header->vci));
648 dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
649 le16_to_cpu(header->vci), le16_to_cpu(header->vpi),
653 atm_charge(vcc, skb->truesize);
655 atomic_inc(&vcc->stats->rx);
659 process_status(card, port, skb);
660 dev_kfree_skb_any(skb);
664 default: /* FIXME: Not really, surely? */
665 if (process_command(card, port, skb))
667 spin_lock(&card->cli_queue_lock);
668 if (skb_queue_len(&card->cli_queue[port]) > 10) {
670 dev_warn(&card->dev->dev, "Dropping console response on port %d\n",
672 dev_kfree_skb_any(skb);
674 skb_queue_tail(&card->cli_queue[port], skb);
675 spin_unlock(&card->cli_queue_lock);
679 /* Allocate RX skbs for any ports which need them */
680 if (card->using_dma && card->atmdev[port] &&
681 !card->rx_skb[port]) {
682 struct sk_buff *skb = alloc_skb(RX_DMA_SIZE, GFP_ATOMIC);
684 SKB_CB(skb)->dma_addr =
685 pci_map_single(card->dev, skb->data,
686 RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
687 iowrite32(SKB_CB(skb)->dma_addr,
688 card->config_regs + RX_DMA_ADDR(port));
689 card->rx_skb[port] = skb;
692 dev_warn(&card->dev->dev, "Failed to allocate RX skb");
694 /* We'll have to try again later */
695 tasklet_schedule(&card->tlet);
700 iowrite32(rx_done, card->config_regs + FLAGS_ADDR);
705 static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
707 struct hlist_head *head;
708 struct atm_vcc *vcc = NULL;
709 struct hlist_node *node;
712 read_lock(&vcc_sklist_lock);
713 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
714 sk_for_each(s, node, head) {
716 if (vcc->dev == dev && vcc->vci == vci &&
717 vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE)
722 read_unlock(&vcc_sklist_lock);
726 static int list_vccs(int vci)
728 struct hlist_head *head;
730 struct hlist_node *node;
735 read_lock(&vcc_sklist_lock);
737 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
738 sk_for_each(s, node, head) {
741 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
747 for(i = 0; i < VCC_HTABLE_SIZE; i++){
749 sk_for_each(s, node, head) {
752 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
759 read_unlock(&vcc_sklist_lock);
763 static void release_vccs(struct atm_dev *dev)
767 write_lock_irq(&vcc_sklist_lock);
768 for (i = 0; i < VCC_HTABLE_SIZE; i++) {
769 struct hlist_head *head = &vcc_hash[i];
770 struct hlist_node *node, *tmp;
774 sk_for_each_safe(s, node, tmp, head) {
776 if (vcc->dev == dev) {
777 vcc_release_async(vcc, -EPIPE);
782 write_unlock_irq(&vcc_sklist_lock);
786 static int popen(struct atm_vcc *vcc)
788 struct solos_card *card = vcc->dev->dev_data;
790 struct pkt_hdr *header;
792 if (vcc->qos.aal != ATM_AAL5) {
793 dev_warn(&card->dev->dev, "Unsupported ATM type %d\n",
798 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
799 if (!skb && net_ratelimit()) {
800 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
803 header = (void *)skb_put(skb, sizeof(*header));
805 header->size = cpu_to_le16(0);
806 header->vpi = cpu_to_le16(vcc->vpi);
807 header->vci = cpu_to_le16(vcc->vci);
808 header->type = cpu_to_le16(PKT_POPEN);
810 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
812 // dev_dbg(&card->dev->dev, "Open for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
813 set_bit(ATM_VF_ADDR, &vcc->flags); // accept the vpi / vci
814 set_bit(ATM_VF_READY, &vcc->flags);
821 static void pclose(struct atm_vcc *vcc)
823 struct solos_card *card = vcc->dev->dev_data;
825 struct pkt_hdr *header;
827 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
829 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
832 header = (void *)skb_put(skb, sizeof(*header));
834 header->size = cpu_to_le16(0);
835 header->vpi = cpu_to_le16(vcc->vpi);
836 header->vci = cpu_to_le16(vcc->vci);
837 header->type = cpu_to_le16(PKT_PCLOSE);
839 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
841 // dev_dbg(&card->dev->dev, "Close for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
843 clear_bit(ATM_VF_ADDR, &vcc->flags);
844 clear_bit(ATM_VF_READY, &vcc->flags);
849 static int print_buffer(struct sk_buff *buf)
856 for (i = 0; i < len; i++){
858 sprintf(msg, "%02X: ", i);
860 sprintf(item,"%02X ",*(buf->data + i));
865 printk(KERN_DEBUG "%s", msg);
871 printk(KERN_DEBUG "%s", msg);
873 printk(KERN_DEBUG "\n");
878 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
884 SKB_CB(skb)->vcc = vcc;
886 spin_lock_irqsave(&card->tx_queue_lock, flags);
887 old_len = skb_queue_len(&card->tx_queue[port]);
888 skb_queue_tail(&card->tx_queue[port], skb);
890 card->tx_mask |= (1 << port);
892 spin_unlock_irqrestore(&card->tx_queue_lock, flags);
894 /* Theoretically we could just schedule the tasklet here, but
895 that introduces latency we don't want -- it's noticeable */
900 static int fpga_tx(struct solos_card *card)
903 uint32_t tx_started = 0;
909 spin_lock_irqsave(&card->tx_lock, flags);
911 tx_pending = ioread32(card->config_regs + FLAGS_ADDR) & card->tx_mask;
913 dev_vdbg(&card->dev->dev, "TX Flags are %X\n", tx_pending);
915 for (port = 0; port < card->nr_ports; port++) {
916 if (card->atmdev[port] && !(tx_pending & (1 << port))) {
917 struct sk_buff *oldskb = card->tx_skb[port];
920 pci_unmap_single(card->dev, SKB_CB(oldskb)->dma_addr,
921 oldskb->len, PCI_DMA_TODEVICE);
923 spin_lock(&card->tx_queue_lock);
924 skb = skb_dequeue(&card->tx_queue[port]);
926 card->tx_mask &= ~(1 << port);
927 spin_unlock(&card->tx_queue_lock);
929 if (skb && !card->using_dma) {
930 memcpy_toio(TX_BUF(card, port), skb->data, skb->len);
931 tx_started |= 1 << port; //Set TX full flag
932 oldskb = skb; /* We're done with this skb already */
933 } else if (skb && card->using_dma) {
934 SKB_CB(skb)->dma_addr = pci_map_single(card->dev, skb->data,
935 skb->len, PCI_DMA_TODEVICE);
936 iowrite32(SKB_CB(skb)->dma_addr,
937 card->config_regs + TX_DMA_ADDR(port));
943 /* Clean up and free oldskb now it's gone */
945 dev_info(&card->dev->dev, "Transmitted: port %d\n",
947 print_buffer(oldskb);
950 vcc = SKB_CB(oldskb)->vcc;
953 atomic_inc(&vcc->stats->tx);
954 solos_pop(vcc, oldskb);
956 dev_kfree_skb_irq(oldskb);
961 iowrite32(tx_started, card->config_regs + FLAGS_ADDR);
963 spin_unlock_irqrestore(&card->tx_lock, flags);
967 static int psend(struct atm_vcc *vcc, struct sk_buff *skb)
969 struct solos_card *card = vcc->dev->dev_data;
970 struct pkt_hdr *header;
973 //dev_dbg(&card->dev->dev, "psend called.\n");
974 //dev_dbg(&card->dev->dev, "dev,vpi,vci = %d,%d,%d\n",SOLOS_CHAN(vcc->dev),vcc->vpi,vcc->vci);
977 if (pktlen > (BUF_SIZE - sizeof(*header))) {
978 dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
983 if (!skb_clone_writable(skb, sizeof(*header))) {
987 if (skb_headroom(skb) < sizeof(*header))
988 expand_by = sizeof(*header) - skb_headroom(skb);
990 ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
992 dev_warn(&card->dev->dev, "pskb_expand_head failed.\n");
998 header = (void *)skb_push(skb, sizeof(*header));
1000 /* This does _not_ include the size of the header */
1001 header->size = cpu_to_le16(pktlen);
1002 header->vpi = cpu_to_le16(vcc->vpi);
1003 header->vci = cpu_to_le16(vcc->vci);
1004 header->type = cpu_to_le16(PKT_DATA);
1006 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
1011 static struct atmdev_ops fpga_ops = {
1023 .owner = THIS_MODULE
1026 static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1030 uint8_t major_ver, minor_ver;
1032 struct solos_card *card;
1034 card = kzalloc(sizeof(*card), GFP_KERNEL);
1039 init_waitqueue_head(&card->fw_wq);
1040 init_waitqueue_head(&card->param_wq);
1042 err = pci_enable_device(dev);
1044 dev_warn(&dev->dev, "Failed to enable PCI device\n");
1048 err = pci_set_dma_mask(dev, DMA_32BIT_MASK);
1050 dev_warn(&dev->dev, "Failed to set 32-bit DMA mask\n");
1054 err = pci_request_regions(dev, "solos");
1056 dev_warn(&dev->dev, "Failed to request regions\n");
1060 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
1061 if (!card->config_regs) {
1062 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
1063 goto out_release_regions;
1065 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
1066 if (!card->buffers) {
1067 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
1068 goto out_unmap_config;
1071 // for(i=0;i<64 ;i+=4){
1072 // data32=ioread32(card->buffers + i);
1073 // dev_dbg(&card->dev->dev, "%08lX\n",(unsigned long)data32);
1076 //Fill Config Mem with zeros
1077 for(i = 0; i < 128; i += 4)
1078 iowrite32(0, card->config_regs + i);
1080 //Set RX empty flags
1081 iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
1083 data32 = ioread32(card->config_regs + FPGA_VER);
1084 fpga_ver = (data32 & 0x0000FFFF);
1085 major_ver = ((data32 & 0xFF000000) >> 24);
1086 minor_ver = ((data32 & 0x00FF0000) >> 16);
1087 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
1088 major_ver, minor_ver, fpga_ver);
1091 card->using_dma = 1;
1093 card->nr_ports = 2; /* FIXME: Detect daughterboard */
1095 pci_set_drvdata(dev, card);
1097 tasklet_init(&card->tlet, solos_bh, (unsigned long)card);
1098 spin_lock_init(&card->tx_lock);
1099 spin_lock_init(&card->tx_queue_lock);
1100 spin_lock_init(&card->cli_queue_lock);
1101 spin_lock_init(&card->param_queue_lock);
1102 INIT_LIST_HEAD(&card->param_queue);
1105 // Set Loopback mode
1106 data32 = 0x00010000;
1107 iowrite32(data32,card->config_regs + FLAGS_ADDR);
1110 // Fill Buffers with zeros
1111 for (i = 0; i < BUF_SIZE * 8; i += 4)
1112 iowrite32(0, card->buffers + i);
1115 for(i = 0; i < (BUF_SIZE * 1); i += 4)
1116 iowrite32(0x12345678, card->buffers + i + (0*BUF_SIZE));
1117 for(i = 0; i < (BUF_SIZE * 1); i += 4)
1118 iowrite32(0xabcdef98, card->buffers + i + (1*BUF_SIZE));
1120 // Read Config Memory
1121 printk(KERN_DEBUG "Reading Config MEM\n");
1123 for(i = 0; i < 16; i++) {
1124 data32=ioread32(card->buffers + i*(BUF_SIZE/2));
1125 printk(KERN_ALERT "Addr: %lX Data: %08lX\n",
1126 (unsigned long)(addr_start + i*(BUF_SIZE/2)),
1127 (unsigned long)data32);
1130 //dev_dbg(&card->dev->dev, "Requesting IRQ: %d\n",dev->irq);
1131 err = request_irq(dev->irq, solos_irq, IRQF_SHARED,
1134 dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
1135 goto out_unmap_both;
1139 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
1142 flash_upgrade(card, 0);
1144 if (firmware_upgrade)
1145 flash_upgrade(card, 1);
1147 err = atm_init(card);
1154 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1155 free_irq(dev->irq, card);
1156 tasklet_kill(&card->tlet);
1159 pci_set_drvdata(dev, NULL);
1160 pci_iounmap(dev, card->config_regs);
1162 pci_iounmap(dev, card->buffers);
1163 out_release_regions:
1164 pci_release_regions(dev);
1169 static int atm_init(struct solos_card *card)
1173 for (i = 0; i < card->nr_ports; i++) {
1174 struct sk_buff *skb;
1175 struct pkt_hdr *header;
1177 skb_queue_head_init(&card->tx_queue[i]);
1178 skb_queue_head_init(&card->cli_queue[i]);
1180 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
1181 if (!card->atmdev[i]) {
1182 dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
1186 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
1187 dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
1188 if (sysfs_create_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group))
1189 dev_err(&card->dev->dev, "Could not register parameter group for ATM device %d\n", i);
1191 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
1193 card->atmdev[i]->ci_range.vpi_bits = 8;
1194 card->atmdev[i]->ci_range.vci_bits = 16;
1195 card->atmdev[i]->dev_data = card;
1196 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
1197 card->atmdev[i]->signal = ATM_PHY_SIG_UNKNOWN;
1199 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
1201 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in atm_init()\n");
1205 header = (void *)skb_put(skb, sizeof(*header));
1207 header->size = cpu_to_le16(0);
1208 header->vpi = cpu_to_le16(0);
1209 header->vci = cpu_to_le16(0);
1210 header->type = cpu_to_le16(PKT_STATUS);
1212 fpga_queue(card, i, skb, NULL);
1217 static void atm_remove(struct solos_card *card)
1221 for (i = 0; i < card->nr_ports; i++) {
1222 if (card->atmdev[i]) {
1223 dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
1225 sysfs_remove_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group);
1226 atm_dev_deregister(card->atmdev[i]);
1231 static void fpga_remove(struct pci_dev *dev)
1233 struct solos_card *card = pci_get_drvdata(dev);
1237 dev_vdbg(&dev->dev, "Freeing IRQ\n");
1238 // Disable IRQs from FPGA
1239 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1240 free_irq(dev->irq, card);
1241 tasklet_kill(&card->tlet);
1243 // iowrite32(0x01,pciregs);
1244 dev_vdbg(&dev->dev, "Unmapping PCI resource\n");
1245 pci_iounmap(dev, card->buffers);
1246 pci_iounmap(dev, card->config_regs);
1248 dev_vdbg(&dev->dev, "Releasing PCI Region\n");
1249 pci_release_regions(dev);
1250 pci_disable_device(dev);
1252 pci_set_drvdata(dev, NULL);
1254 // dev_dbg(&card->dev->dev, "fpga_remove\n");
1258 static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
1259 { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1263 MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
1265 static struct pci_driver fpga_driver = {
1267 .id_table = fpga_pci_tbl,
1268 .probe = fpga_probe,
1269 .remove = fpga_remove,
1273 static int __init solos_pci_init(void)
1275 printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
1276 return pci_register_driver(&fpga_driver);
1279 static void __exit solos_pci_exit(void)
1281 pci_unregister_driver(&fpga_driver);
1282 printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
1285 module_init(solos_pci_init);
1286 module_exit(solos_pci_exit);