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
74 static int atmdebug = 0;
75 static int firmware_upgrade = 0;
76 static int fpga_upgrade = 0;
91 #define SKB_CB(skb) ((struct solos_skb_cb *)skb->cb)
100 void __iomem *config_regs;
101 void __iomem *buffers;
105 struct atm_dev *atmdev[4];
106 struct tasklet_struct tlet;
108 spinlock_t tx_queue_lock;
109 spinlock_t cli_queue_lock;
110 spinlock_t param_queue_lock;
111 struct list_head param_queue;
112 struct sk_buff_head tx_queue[4];
113 struct sk_buff_head cli_queue[4];
114 struct sk_buff *tx_skb[4];
115 struct sk_buff *rx_skb[4];
116 wait_queue_head_t param_wq;
117 wait_queue_head_t fw_wq;
123 struct list_head list;
126 struct sk_buff *response;
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(reset, "Reset Solos chips on startup");
136 MODULE_PARM_DESC(atmdebug, "Print ATM data");
137 MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade");
138 MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade");
139 module_param(reset, int, 0444);
140 module_param(atmdebug, int, 0644);
141 module_param(firmware_upgrade, int, 0444);
142 module_param(fpga_upgrade, int, 0444);
144 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
145 struct atm_vcc *vcc);
146 static uint32_t fpga_tx(struct solos_card *);
147 static irqreturn_t solos_irq(int irq, void *dev_id);
148 static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
149 static int list_vccs(int vci);
150 static void release_vccs(struct atm_dev *dev);
151 static int atm_init(struct solos_card *);
152 static void atm_remove(struct solos_card *);
153 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
154 static void solos_bh(unsigned long);
155 static int print_buffer(struct sk_buff *buf);
157 static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb)
162 dev_kfree_skb_any(skb);
165 static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr,
168 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
169 struct solos_card *card = atmdev->dev_data;
170 struct solos_param prm;
172 struct pkt_hdr *header;
175 buflen = strlen(attr->attr.name) + 10;
177 skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL);
179 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n");
183 header = (void *)skb_put(skb, sizeof(*header));
185 buflen = snprintf((void *)&header[1], buflen - 1,
186 "L%05d\n%s\n", current->pid, attr->attr.name);
187 skb_put(skb, buflen);
189 header->size = cpu_to_le16(buflen);
190 header->vpi = cpu_to_le16(0);
191 header->vci = cpu_to_le16(0);
192 header->type = cpu_to_le16(PKT_COMMAND);
194 prm.pid = current->pid;
196 prm.port = SOLOS_CHAN(atmdev);
198 spin_lock_irq(&card->param_queue_lock);
199 list_add(&prm.list, &card->param_queue);
200 spin_unlock_irq(&card->param_queue_lock);
202 fpga_queue(card, prm.port, skb, NULL);
204 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
206 spin_lock_irq(&card->param_queue_lock);
208 spin_unlock_irq(&card->param_queue_lock);
213 buflen = prm.response->len;
214 memcpy(buf, prm.response->data, buflen);
215 kfree_skb(prm.response);
220 static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr,
221 const char *buf, size_t count)
223 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
224 struct solos_card *card = atmdev->dev_data;
225 struct solos_param prm;
227 struct pkt_hdr *header;
231 buflen = strlen(attr->attr.name) + 11 + count;
233 skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL);
235 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n");
239 header = (void *)skb_put(skb, sizeof(*header));
241 buflen = snprintf((void *)&header[1], buflen - 1,
242 "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf);
244 skb_put(skb, buflen);
245 header->size = cpu_to_le16(buflen);
246 header->vpi = cpu_to_le16(0);
247 header->vci = cpu_to_le16(0);
248 header->type = cpu_to_le16(PKT_COMMAND);
250 prm.pid = current->pid;
252 prm.port = SOLOS_CHAN(atmdev);
254 spin_lock_irq(&card->param_queue_lock);
255 list_add(&prm.list, &card->param_queue);
256 spin_unlock_irq(&card->param_queue_lock);
258 fpga_queue(card, prm.port, skb, NULL);
260 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
262 spin_lock_irq(&card->param_queue_lock);
264 spin_unlock_irq(&card->param_queue_lock);
273 /* Sometimes it has a newline, sometimes it doesn't. */
274 if (skb->data[buflen - 1] == '\n')
277 if (buflen == 2 && !strncmp(skb->data, "OK", 2))
279 else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5))
282 /* We know we have enough space allocated for this; we allocated
284 skb->data[buflen] = 0;
286 dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n",
295 static char *next_string(struct sk_buff *skb)
298 char *this = skb->data;
300 for (i = 0; i < skb->len; i++) {
301 if (this[i] == '\n') {
303 skb_pull(skb, i + 1);
306 if (!isprint(this[i]))
313 * Status packet has fields separated by \n, starting with a version number
314 * for the information therein. Fields are....
317 * TxBitRate (version >= 1)
318 * RxBitRate (version >= 1)
319 * State (version >= 1)
321 static int process_status(struct solos_card *card, int port, struct sk_buff *skb)
323 char *str, *end, *state_str;
324 int ver, rate_up, rate_down, state;
326 if (!card->atmdev[port])
329 str = next_string(skb);
333 ver = simple_strtol(str, NULL, 10);
335 dev_warn(&card->dev->dev, "Unexpected status interrupt version %d\n",
340 str = next_string(skb);
343 if (!strcmp(str, "ERROR")) {
344 dev_dbg(&card->dev->dev, "Status packet indicated Solos error on port %d (starting up?)\n",
349 rate_up = simple_strtol(str, &end, 10);
353 str = next_string(skb);
356 rate_down = simple_strtol(str, &end, 10);
360 state_str = next_string(skb);
363 if (!strcmp(state_str, "Showtime"))
364 state = ATM_PHY_SIG_FOUND;
366 state = ATM_PHY_SIG_LOST;
367 release_vccs(card->atmdev[port]);
370 if (state == ATM_PHY_SIG_LOST) {
371 dev_info(&card->dev->dev, "Port %d: %s\n", port, state_str);
375 snr = next_string(skb);
378 attn = next_string(skb);
382 dev_info(&card->dev->dev, "Port %d: %s @%d/%d kb/s%s%s%s%s\n",
383 port, state_str, rate_down/1000, rate_up/1000,
384 snr[0]?", SNR ":"", snr, attn[0]?", Attn ":"", attn);
386 card->atmdev[port]->link_rate = rate_down / 424;
387 card->atmdev[port]->signal = state;
392 static int process_command(struct solos_card *card, int port, struct sk_buff *skb)
394 struct solos_param *prm;
402 if (skb->data[0] != 'L' || !isdigit(skb->data[1]) ||
403 !isdigit(skb->data[2]) || !isdigit(skb->data[3]) ||
404 !isdigit(skb->data[4]) || !isdigit(skb->data[5]) ||
405 skb->data[6] != '\n')
408 cmdpid = simple_strtol(&skb->data[1], NULL, 10);
410 spin_lock_irqsave(&card->param_queue_lock, flags);
411 list_for_each_entry(prm, &card->param_queue, list) {
412 if (prm->port == port && prm->pid == cmdpid) {
415 wake_up(&card->param_wq);
420 spin_unlock_irqrestore(&card->param_queue_lock, flags);
424 static ssize_t console_show(struct device *dev, struct device_attribute *attr,
427 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
428 struct solos_card *card = atmdev->dev_data;
431 spin_lock(&card->cli_queue_lock);
432 skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
433 spin_unlock(&card->cli_queue_lock);
435 return sprintf(buf, "No data.\n");
437 memcpy(buf, skb->data, skb->len);
438 dev_dbg(&card->dev->dev, "len: %d\n", skb->len);
444 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
447 struct pkt_hdr *header;
449 if (size > (BUF_SIZE - sizeof(*header))) {
450 dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n");
453 skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC);
455 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n");
459 header = (void *)skb_put(skb, sizeof(*header));
461 header->size = cpu_to_le16(size);
462 header->vpi = cpu_to_le16(0);
463 header->vci = cpu_to_le16(0);
464 header->type = cpu_to_le16(PKT_COMMAND);
466 memcpy(skb_put(skb, size), buf, size);
468 fpga_queue(card, dev, skb, NULL);
473 static ssize_t console_store(struct device *dev, struct device_attribute *attr,
474 const char *buf, size_t count)
476 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
477 struct solos_card *card = atmdev->dev_data;
480 err = send_command(card, SOLOS_CHAN(atmdev), buf, count);
485 static DEVICE_ATTR(console, 0644, console_show, console_store);
488 #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL);
489 #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store);
491 #include "solos-attrlist.c"
496 #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr,
497 #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr,
499 static struct attribute *solos_attrs[] = {
500 #include "solos-attrlist.c"
504 static struct attribute_group solos_attr_group = {
505 .attrs = solos_attrs,
506 .name = "parameters",
509 static int flash_upgrade(struct solos_card *card, int chip)
511 const struct firmware *fw;
519 fw_name = "solos-FPGA.bin";
520 blocksize = FPGA_BLOCK;
522 fw_name = "solos-Firmware.bin";
523 blocksize = SOLOS_BLOCK;
526 if (request_firmware(&fw, fw_name, &card->dev->dev))
529 dev_info(&card->dev->dev, "Flash upgrade starting\n");
531 numblocks = fw->size / blocksize;
532 dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size);
533 dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks);
535 dev_info(&card->dev->dev, "Changing FPGA to Update mode\n");
536 iowrite32(1, card->config_regs + FPGA_MODE);
537 data32 = ioread32(card->config_regs + FPGA_MODE);
539 /* Set mode to Chip Erase */
540 dev_info(&card->dev->dev, "Set FPGA Flash mode to %s Chip Erase\n",
541 chip?"Solos":"FPGA");
542 iowrite32((chip * 2), card->config_regs + FLASH_MODE);
545 iowrite32(1, card->config_regs + WRITE_FLASH);
546 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
548 for (offset = 0; offset < fw->size; offset += blocksize) {
551 /* Clear write flag */
552 iowrite32(0, card->config_regs + WRITE_FLASH);
554 /* Set mode to Block Write */
555 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
556 iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE);
558 /* Copy block to buffer, swapping each 16 bits */
559 for(i = 0; i < blocksize; i += 4) {
560 uint32_t word = swahb32p((uint32_t *)(fw->data + offset + i));
561 iowrite32(word, RX_BUF(card, 3) + i);
564 /* Specify block number and then trigger flash write */
565 iowrite32(offset / blocksize, card->config_regs + FLASH_BLOCK);
566 iowrite32(1, card->config_regs + WRITE_FLASH);
567 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
570 release_firmware(fw);
571 iowrite32(0, card->config_regs + WRITE_FLASH);
572 iowrite32(0, card->config_regs + FPGA_MODE);
573 iowrite32(0, card->config_regs + FLASH_MODE);
574 dev_info(&card->dev->dev, "Returning FPGA to Data mode\n");
578 static irqreturn_t solos_irq(int irq, void *dev_id)
580 struct solos_card *card = dev_id;
583 iowrite32(0, card->config_regs + IRQ_CLEAR);
585 /* If we're up and running, just kick the tasklet to process TX/RX */
587 tasklet_schedule(&card->tlet);
589 wake_up(&card->fw_wq);
591 return IRQ_RETVAL(handled);
594 void solos_bh(unsigned long card_arg)
596 struct solos_card *card = (void *)card_arg;
598 uint32_t rx_done = 0;
602 * Since fpga_tx() is going to need to read the flags under its lock,
603 * it can return them to us so that we don't have to hit PCI MMIO
604 * again for the same information
606 card_flags = fpga_tx(card);
608 for (port = 0; port < card->nr_ports; port++) {
609 if (card_flags & (0x10 << port)) {
610 struct pkt_hdr _hdr, *header;
615 if (card->using_dma) {
616 skb = card->rx_skb[port];
617 card->rx_skb[port] = NULL;
619 pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr,
620 RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
622 header = (void *)skb->data;
623 size = le16_to_cpu(header->size);
624 skb_put(skb, size + sizeof(*header));
625 skb_pull(skb, sizeof(*header));
629 rx_done |= 0x10 << port;
631 memcpy_fromio(header, RX_BUF(card, port), sizeof(*header));
633 size = le16_to_cpu(header->size);
635 skb = alloc_skb(size + 1, GFP_ATOMIC);
638 dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
642 memcpy_fromio(skb_put(skb, size),
643 RX_BUF(card, port) + sizeof(*header),
647 dev_info(&card->dev->dev, "Received: device %d\n", port);
648 dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n",
649 size, le16_to_cpu(header->vpi),
650 le16_to_cpu(header->vci));
654 switch (le16_to_cpu(header->type)) {
656 vcc = find_vcc(card->atmdev[port], le16_to_cpu(header->vpi),
657 le16_to_cpu(header->vci));
660 dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
661 le16_to_cpu(header->vci), le16_to_cpu(header->vpi),
665 atm_charge(vcc, skb->truesize);
667 atomic_inc(&vcc->stats->rx);
671 if (process_status(card, port, skb) &&
673 dev_warn(&card->dev->dev, "Bad status packet of %d bytes on port %d:\n", skb->len, port);
676 dev_kfree_skb_any(skb);
680 default: /* FIXME: Not really, surely? */
681 if (process_command(card, port, skb))
683 spin_lock(&card->cli_queue_lock);
684 if (skb_queue_len(&card->cli_queue[port]) > 10) {
686 dev_warn(&card->dev->dev, "Dropping console response on port %d\n",
688 dev_kfree_skb_any(skb);
690 skb_queue_tail(&card->cli_queue[port], skb);
691 spin_unlock(&card->cli_queue_lock);
695 /* Allocate RX skbs for any ports which need them */
696 if (card->using_dma && card->atmdev[port] &&
697 !card->rx_skb[port]) {
698 struct sk_buff *skb = alloc_skb(RX_DMA_SIZE, GFP_ATOMIC);
700 SKB_CB(skb)->dma_addr =
701 pci_map_single(card->dev, skb->data,
702 RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
703 iowrite32(SKB_CB(skb)->dma_addr,
704 card->config_regs + RX_DMA_ADDR(port));
705 card->rx_skb[port] = skb;
708 dev_warn(&card->dev->dev, "Failed to allocate RX skb");
710 /* We'll have to try again later */
711 tasklet_schedule(&card->tlet);
716 iowrite32(rx_done, card->config_regs + FLAGS_ADDR);
721 static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
723 struct hlist_head *head;
724 struct atm_vcc *vcc = NULL;
725 struct hlist_node *node;
728 read_lock(&vcc_sklist_lock);
729 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
730 sk_for_each(s, node, head) {
732 if (vcc->dev == dev && vcc->vci == vci &&
733 vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE)
738 read_unlock(&vcc_sklist_lock);
742 static int list_vccs(int vci)
744 struct hlist_head *head;
746 struct hlist_node *node;
751 read_lock(&vcc_sklist_lock);
753 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
754 sk_for_each(s, node, head) {
757 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
763 for(i = 0; i < VCC_HTABLE_SIZE; i++){
765 sk_for_each(s, node, head) {
768 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
775 read_unlock(&vcc_sklist_lock);
779 static void release_vccs(struct atm_dev *dev)
783 write_lock_irq(&vcc_sklist_lock);
784 for (i = 0; i < VCC_HTABLE_SIZE; i++) {
785 struct hlist_head *head = &vcc_hash[i];
786 struct hlist_node *node, *tmp;
790 sk_for_each_safe(s, node, tmp, head) {
792 if (vcc->dev == dev) {
793 vcc_release_async(vcc, -EPIPE);
798 write_unlock_irq(&vcc_sklist_lock);
802 static int popen(struct atm_vcc *vcc)
804 struct solos_card *card = vcc->dev->dev_data;
806 struct pkt_hdr *header;
808 if (vcc->qos.aal != ATM_AAL5) {
809 dev_warn(&card->dev->dev, "Unsupported ATM type %d\n",
814 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
815 if (!skb && net_ratelimit()) {
816 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
819 header = (void *)skb_put(skb, sizeof(*header));
821 header->size = cpu_to_le16(0);
822 header->vpi = cpu_to_le16(vcc->vpi);
823 header->vci = cpu_to_le16(vcc->vci);
824 header->type = cpu_to_le16(PKT_POPEN);
826 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
828 set_bit(ATM_VF_ADDR, &vcc->flags);
829 set_bit(ATM_VF_READY, &vcc->flags);
836 static void pclose(struct atm_vcc *vcc)
838 struct solos_card *card = vcc->dev->dev_data;
840 struct pkt_hdr *header;
842 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
844 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
847 header = (void *)skb_put(skb, sizeof(*header));
849 header->size = cpu_to_le16(0);
850 header->vpi = cpu_to_le16(vcc->vpi);
851 header->vci = cpu_to_le16(vcc->vci);
852 header->type = cpu_to_le16(PKT_PCLOSE);
854 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
856 clear_bit(ATM_VF_ADDR, &vcc->flags);
857 clear_bit(ATM_VF_READY, &vcc->flags);
862 static int print_buffer(struct sk_buff *buf)
869 for (i = 0; i < len; i++){
871 sprintf(msg, "%02X: ", i);
873 sprintf(item,"%02X ",*(buf->data + i));
878 printk(KERN_DEBUG "%s", msg);
884 printk(KERN_DEBUG "%s", msg);
886 printk(KERN_DEBUG "\n");
891 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
897 SKB_CB(skb)->vcc = vcc;
899 spin_lock_irqsave(&card->tx_queue_lock, flags);
900 old_len = skb_queue_len(&card->tx_queue[port]);
901 skb_queue_tail(&card->tx_queue[port], skb);
903 card->tx_mask |= (1 << port);
904 spin_unlock_irqrestore(&card->tx_queue_lock, flags);
906 /* Theoretically we could just schedule the tasklet here, but
907 that introduces latency we don't want -- it's noticeable */
912 static uint32_t fpga_tx(struct solos_card *card)
914 uint32_t tx_pending, card_flags;
915 uint32_t tx_started = 0;
921 spin_lock_irqsave(&card->tx_lock, flags);
923 card_flags = ioread32(card->config_regs + FLAGS_ADDR);
925 * The queue lock is required for _writing_ to tx_mask, but we're
926 * OK to read it here without locking. The only potential update
927 * that we could race with is in fpga_queue() where it sets a bit
928 * for a new port... but it's going to call this function again if
929 * it's doing that, anyway.
931 tx_pending = card->tx_mask & ~card_flags;
933 for (port = 0; tx_pending; tx_pending >>= 1, port++) {
934 if (tx_pending & 1) {
935 struct sk_buff *oldskb = card->tx_skb[port];
937 pci_unmap_single(card->dev, SKB_CB(oldskb)->dma_addr,
938 oldskb->len, PCI_DMA_TODEVICE);
940 spin_lock(&card->tx_queue_lock);
941 skb = skb_dequeue(&card->tx_queue[port]);
943 card->tx_mask &= ~(1 << port);
944 spin_unlock(&card->tx_queue_lock);
946 if (skb && !card->using_dma) {
947 memcpy_toio(TX_BUF(card, port), skb->data, skb->len);
948 tx_started |= 1 << port;
949 oldskb = skb; /* We're done with this skb already */
950 } else if (skb && card->using_dma) {
951 SKB_CB(skb)->dma_addr = pci_map_single(card->dev, skb->data,
952 skb->len, PCI_DMA_TODEVICE);
953 iowrite32(SKB_CB(skb)->dma_addr,
954 card->config_regs + TX_DMA_ADDR(port));
960 /* Clean up and free oldskb now it's gone */
962 dev_info(&card->dev->dev, "Transmitted: port %d\n",
964 print_buffer(oldskb);
967 vcc = SKB_CB(oldskb)->vcc;
970 atomic_inc(&vcc->stats->tx);
971 solos_pop(vcc, oldskb);
973 dev_kfree_skb_irq(oldskb);
977 /* For non-DMA TX, write the 'TX start' bit for all four ports simultaneously */
979 iowrite32(tx_started, card->config_regs + FLAGS_ADDR);
981 spin_unlock_irqrestore(&card->tx_lock, flags);
985 static int psend(struct atm_vcc *vcc, struct sk_buff *skb)
987 struct solos_card *card = vcc->dev->dev_data;
988 struct pkt_hdr *header;
992 if (pktlen > (BUF_SIZE - sizeof(*header))) {
993 dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
998 if (!skb_clone_writable(skb, sizeof(*header))) {
1002 if (skb_headroom(skb) < sizeof(*header))
1003 expand_by = sizeof(*header) - skb_headroom(skb);
1005 ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
1007 dev_warn(&card->dev->dev, "pskb_expand_head failed.\n");
1008 solos_pop(vcc, skb);
1013 header = (void *)skb_push(skb, sizeof(*header));
1015 /* This does _not_ include the size of the header */
1016 header->size = cpu_to_le16(pktlen);
1017 header->vpi = cpu_to_le16(vcc->vpi);
1018 header->vci = cpu_to_le16(vcc->vci);
1019 header->type = cpu_to_le16(PKT_DATA);
1021 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
1026 static struct atmdev_ops fpga_ops = {
1038 .owner = THIS_MODULE
1041 static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1045 uint8_t major_ver, minor_ver;
1047 struct solos_card *card;
1049 card = kzalloc(sizeof(*card), GFP_KERNEL);
1054 init_waitqueue_head(&card->fw_wq);
1055 init_waitqueue_head(&card->param_wq);
1057 err = pci_enable_device(dev);
1059 dev_warn(&dev->dev, "Failed to enable PCI device\n");
1063 err = pci_set_dma_mask(dev, DMA_32BIT_MASK);
1065 dev_warn(&dev->dev, "Failed to set 32-bit DMA mask\n");
1069 err = pci_request_regions(dev, "solos");
1071 dev_warn(&dev->dev, "Failed to request regions\n");
1075 card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
1076 if (!card->config_regs) {
1077 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
1078 goto out_release_regions;
1080 card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
1081 if (!card->buffers) {
1082 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
1083 goto out_unmap_config;
1087 iowrite32(1, card->config_regs + FPGA_MODE);
1088 data32 = ioread32(card->config_regs + FPGA_MODE);
1090 iowrite32(0, card->config_regs + FPGA_MODE);
1091 data32 = ioread32(card->config_regs + FPGA_MODE);
1093 //Fill Config Mem with zeros
1094 for(i = 0; i < 128; i += 4)
1095 iowrite32(0, card->config_regs + i);
1097 //Set RX empty flags
1098 iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
1100 data32 = ioread32(card->config_regs + FPGA_VER);
1101 fpga_ver = (data32 & 0x0000FFFF);
1102 major_ver = ((data32 & 0xFF000000) >> 24);
1103 minor_ver = ((data32 & 0x00FF0000) >> 16);
1104 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
1105 major_ver, minor_ver, fpga_ver);
1108 card->using_dma = 1;
1110 card->nr_ports = 2; /* FIXME: Detect daughterboard */
1112 pci_set_drvdata(dev, card);
1114 tasklet_init(&card->tlet, solos_bh, (unsigned long)card);
1115 spin_lock_init(&card->tx_lock);
1116 spin_lock_init(&card->tx_queue_lock);
1117 spin_lock_init(&card->cli_queue_lock);
1118 spin_lock_init(&card->param_queue_lock);
1119 INIT_LIST_HEAD(&card->param_queue);
1121 err = request_irq(dev->irq, solos_irq, IRQF_SHARED,
1124 dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
1125 goto out_unmap_both;
1128 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
1131 flash_upgrade(card, 0);
1133 if (firmware_upgrade)
1134 flash_upgrade(card, 1);
1136 err = atm_init(card);
1143 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1144 free_irq(dev->irq, card);
1145 tasklet_kill(&card->tlet);
1148 pci_set_drvdata(dev, NULL);
1149 pci_iounmap(dev, card->config_regs);
1151 pci_iounmap(dev, card->buffers);
1152 out_release_regions:
1153 pci_release_regions(dev);
1158 static int atm_init(struct solos_card *card)
1162 for (i = 0; i < card->nr_ports; i++) {
1163 struct sk_buff *skb;
1164 struct pkt_hdr *header;
1166 skb_queue_head_init(&card->tx_queue[i]);
1167 skb_queue_head_init(&card->cli_queue[i]);
1169 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
1170 if (!card->atmdev[i]) {
1171 dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
1175 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
1176 dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
1177 if (sysfs_create_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group))
1178 dev_err(&card->dev->dev, "Could not register parameter group for ATM device %d\n", i);
1180 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
1182 card->atmdev[i]->ci_range.vpi_bits = 8;
1183 card->atmdev[i]->ci_range.vci_bits = 16;
1184 card->atmdev[i]->dev_data = card;
1185 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
1186 card->atmdev[i]->signal = ATM_PHY_SIG_UNKNOWN;
1188 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
1190 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in atm_init()\n");
1194 header = (void *)skb_put(skb, sizeof(*header));
1196 header->size = cpu_to_le16(0);
1197 header->vpi = cpu_to_le16(0);
1198 header->vci = cpu_to_le16(0);
1199 header->type = cpu_to_le16(PKT_STATUS);
1201 fpga_queue(card, i, skb, NULL);
1206 static void atm_remove(struct solos_card *card)
1210 for (i = 0; i < card->nr_ports; i++) {
1211 if (card->atmdev[i]) {
1212 dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
1214 sysfs_remove_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group);
1215 atm_dev_deregister(card->atmdev[i]);
1220 static void fpga_remove(struct pci_dev *dev)
1222 struct solos_card *card = pci_get_drvdata(dev);
1226 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1227 free_irq(dev->irq, card);
1228 tasklet_kill(&card->tlet);
1230 pci_iounmap(dev, card->buffers);
1231 pci_iounmap(dev, card->config_regs);
1233 pci_release_regions(dev);
1234 pci_disable_device(dev);
1236 pci_set_drvdata(dev, NULL);
1240 static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
1241 { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1245 MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
1247 static struct pci_driver fpga_driver = {
1249 .id_table = fpga_pci_tbl,
1250 .probe = fpga_probe,
1251 .remove = fpga_remove,
1255 static int __init solos_pci_init(void)
1257 printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
1258 return pci_register_driver(&fpga_driver);
1261 static void __exit solos_pci_exit(void)
1263 pci_unregister_driver(&fpga_driver);
1264 printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
1267 module_init(solos_pci_init);
1268 module_exit(solos_pci_exit);