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 OLD_BUF_SIZE 4096 /* For FPGA versions <= 2*/
64 #define FPGA_PAGE 528 /* FPGA flash page size*/
65 #define SOLOS_PAGE 512 /* Solos flash page size*/
66 #define FPGA_BLOCK (FPGA_PAGE * 8) /* FPGA flash block size*/
67 #define SOLOS_BLOCK (SOLOS_PAGE * 8) /* Solos flash block size*/
69 #define RX_BUF(card, nr) ((card->buffers) + (nr)*(card->buffer_size)*2)
70 #define TX_BUF(card, nr) ((card->buffers) + (nr)*(card->buffer_size)*2 + (card->buffer_size))
71 #define FLASH_BUF ((card->buffers) + 4*(card->buffer_size)*2)
73 #define RX_DMA_SIZE 2048
75 #define FPGA_VERSION(a,b) (((a) << 8) + (b))
76 #define LEGACY_BUFFERS 2
77 #define DMA_SUPPORTED 4
80 static int atmdebug
= 0;
81 static int firmware_upgrade
= 0;
82 static int fpga_upgrade
= 0;
83 static int db_firmware_upgrade
= 0;
84 static int db_fpga_upgrade
= 0;
99 #define SKB_CB(skb) ((struct solos_skb_cb *)skb->cb)
102 #define PKT_COMMAND 1
108 void __iomem
*config_regs
;
109 void __iomem
*buffers
;
113 struct atm_dev
*atmdev
[4];
114 struct tasklet_struct tlet
;
116 spinlock_t tx_queue_lock
;
117 spinlock_t cli_queue_lock
;
118 spinlock_t param_queue_lock
;
119 struct list_head param_queue
;
120 struct sk_buff_head tx_queue
[4];
121 struct sk_buff_head cli_queue
[4];
122 struct sk_buff
*tx_skb
[4];
123 struct sk_buff
*rx_skb
[4];
124 wait_queue_head_t param_wq
;
125 wait_queue_head_t fw_wq
;
133 struct list_head list
;
136 struct sk_buff
*response
;
139 #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
141 MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
142 MODULE_DESCRIPTION("Solos PCI driver");
143 MODULE_VERSION(VERSION
);
144 MODULE_LICENSE("GPL");
145 MODULE_PARM_DESC(reset
, "Reset Solos chips on startup");
146 MODULE_PARM_DESC(atmdebug
, "Print ATM data");
147 MODULE_PARM_DESC(firmware_upgrade
, "Initiate Solos firmware upgrade");
148 MODULE_PARM_DESC(fpga_upgrade
, "Initiate FPGA upgrade");
149 MODULE_PARM_DESC(db_firmware_upgrade
, "Initiate daughter board Solos firmware upgrade");
150 MODULE_PARM_DESC(db_fpga_upgrade
, "Initiate daughter board FPGA upgrade");
151 module_param(reset
, int, 0444);
152 module_param(atmdebug
, int, 0644);
153 module_param(firmware_upgrade
, int, 0444);
154 module_param(fpga_upgrade
, int, 0444);
155 module_param(db_firmware_upgrade
, int, 0444);
156 module_param(db_fpga_upgrade
, int, 0444);
158 static void fpga_queue(struct solos_card
*card
, int port
, struct sk_buff
*skb
,
159 struct atm_vcc
*vcc
);
160 static uint32_t fpga_tx(struct solos_card
*);
161 static irqreturn_t
solos_irq(int irq
, void *dev_id
);
162 static struct atm_vcc
* find_vcc(struct atm_dev
*dev
, short vpi
, int vci
);
163 static int list_vccs(int vci
);
164 static void release_vccs(struct atm_dev
*dev
);
165 static int atm_init(struct solos_card
*);
166 static void atm_remove(struct solos_card
*);
167 static int send_command(struct solos_card
*card
, int dev
, const char *buf
, size_t size
);
168 static void solos_bh(unsigned long);
169 static int print_buffer(struct sk_buff
*buf
);
171 static inline void solos_pop(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
176 dev_kfree_skb_any(skb
);
179 static ssize_t
solos_param_show(struct device
*dev
, struct device_attribute
*attr
,
182 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
183 struct solos_card
*card
= atmdev
->dev_data
;
184 struct solos_param prm
;
186 struct pkt_hdr
*header
;
189 buflen
= strlen(attr
->attr
.name
) + 10;
191 skb
= alloc_skb(sizeof(*header
) + buflen
, GFP_KERNEL
);
193 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in solos_param_show()\n");
197 header
= (void *)skb_put(skb
, sizeof(*header
));
199 buflen
= snprintf((void *)&header
[1], buflen
- 1,
200 "L%05d\n%s\n", current
->pid
, attr
->attr
.name
);
201 skb_put(skb
, buflen
);
203 header
->size
= cpu_to_le16(buflen
);
204 header
->vpi
= cpu_to_le16(0);
205 header
->vci
= cpu_to_le16(0);
206 header
->type
= cpu_to_le16(PKT_COMMAND
);
208 prm
.pid
= current
->pid
;
210 prm
.port
= SOLOS_CHAN(atmdev
);
212 spin_lock_irq(&card
->param_queue_lock
);
213 list_add(&prm
.list
, &card
->param_queue
);
214 spin_unlock_irq(&card
->param_queue_lock
);
216 fpga_queue(card
, prm
.port
, skb
, NULL
);
218 wait_event_timeout(card
->param_wq
, prm
.response
, 5 * HZ
);
220 spin_lock_irq(&card
->param_queue_lock
);
222 spin_unlock_irq(&card
->param_queue_lock
);
227 buflen
= prm
.response
->len
;
228 memcpy(buf
, prm
.response
->data
, buflen
);
229 kfree_skb(prm
.response
);
234 static ssize_t
solos_param_store(struct device
*dev
, struct device_attribute
*attr
,
235 const char *buf
, size_t count
)
237 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
238 struct solos_card
*card
= atmdev
->dev_data
;
239 struct solos_param prm
;
241 struct pkt_hdr
*header
;
245 buflen
= strlen(attr
->attr
.name
) + 11 + count
;
247 skb
= alloc_skb(sizeof(*header
) + buflen
, GFP_KERNEL
);
249 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in solos_param_store()\n");
253 header
= (void *)skb_put(skb
, sizeof(*header
));
255 buflen
= snprintf((void *)&header
[1], buflen
- 1,
256 "L%05d\n%s\n%s\n", current
->pid
, attr
->attr
.name
, buf
);
258 skb_put(skb
, buflen
);
259 header
->size
= cpu_to_le16(buflen
);
260 header
->vpi
= cpu_to_le16(0);
261 header
->vci
= cpu_to_le16(0);
262 header
->type
= cpu_to_le16(PKT_COMMAND
);
264 prm
.pid
= current
->pid
;
266 prm
.port
= SOLOS_CHAN(atmdev
);
268 spin_lock_irq(&card
->param_queue_lock
);
269 list_add(&prm
.list
, &card
->param_queue
);
270 spin_unlock_irq(&card
->param_queue_lock
);
272 fpga_queue(card
, prm
.port
, skb
, NULL
);
274 wait_event_timeout(card
->param_wq
, prm
.response
, 5 * HZ
);
276 spin_lock_irq(&card
->param_queue_lock
);
278 spin_unlock_irq(&card
->param_queue_lock
);
287 /* Sometimes it has a newline, sometimes it doesn't. */
288 if (skb
->data
[buflen
- 1] == '\n')
291 if (buflen
== 2 && !strncmp(skb
->data
, "OK", 2))
293 else if (buflen
== 5 && !strncmp(skb
->data
, "ERROR", 5))
296 /* We know we have enough space allocated for this; we allocated
298 skb
->data
[buflen
] = 0;
300 dev_warn(&card
->dev
->dev
, "Unexpected parameter response: '%s'\n",
309 static char *next_string(struct sk_buff
*skb
)
312 char *this = skb
->data
;
314 for (i
= 0; i
< skb
->len
; i
++) {
315 if (this[i
] == '\n') {
317 skb_pull(skb
, i
+ 1);
320 if (!isprint(this[i
]))
327 * Status packet has fields separated by \n, starting with a version number
328 * for the information therein. Fields are....
331 * RxBitRate (version >= 1)
332 * TxBitRate (version >= 1)
333 * State (version >= 1)
334 * LocalSNRMargin (version >= 1)
335 * LocalLineAttn (version >= 1)
337 static int process_status(struct solos_card
*card
, int port
, struct sk_buff
*skb
)
339 char *str
, *end
, *state_str
, *snr
, *attn
;
340 int ver
, rate_up
, rate_down
;
342 if (!card
->atmdev
[port
])
345 str
= next_string(skb
);
349 ver
= simple_strtol(str
, NULL
, 10);
351 dev_warn(&card
->dev
->dev
, "Unexpected status interrupt version %d\n",
356 str
= next_string(skb
);
359 if (!strcmp(str
, "ERROR")) {
360 dev_dbg(&card
->dev
->dev
, "Status packet indicated Solos error on port %d (starting up?)\n",
365 rate_down
= simple_strtol(str
, &end
, 10);
369 str
= next_string(skb
);
372 rate_up
= simple_strtol(str
, &end
, 10);
376 state_str
= next_string(skb
);
380 /* Anything but 'Showtime' is down */
381 if (strcmp(state_str
, "Showtime")) {
382 card
->atmdev
[port
]->signal
= ATM_PHY_SIG_LOST
;
383 release_vccs(card
->atmdev
[port
]);
384 dev_info(&card
->dev
->dev
, "Port %d: %s\n", port
, state_str
);
388 snr
= next_string(skb
);
391 attn
= next_string(skb
);
395 dev_info(&card
->dev
->dev
, "Port %d: %s @%d/%d kb/s%s%s%s%s\n",
396 port
, state_str
, rate_down
/1000, rate_up
/1000,
397 snr
[0]?", SNR ":"", snr
, attn
[0]?", Attn ":"", attn
);
399 card
->atmdev
[port
]->link_rate
= rate_down
/ 424;
400 card
->atmdev
[port
]->signal
= ATM_PHY_SIG_FOUND
;
405 static int process_command(struct solos_card
*card
, int port
, struct sk_buff
*skb
)
407 struct solos_param
*prm
;
415 if (skb
->data
[0] != 'L' || !isdigit(skb
->data
[1]) ||
416 !isdigit(skb
->data
[2]) || !isdigit(skb
->data
[3]) ||
417 !isdigit(skb
->data
[4]) || !isdigit(skb
->data
[5]) ||
418 skb
->data
[6] != '\n')
421 cmdpid
= simple_strtol(&skb
->data
[1], NULL
, 10);
423 spin_lock_irqsave(&card
->param_queue_lock
, flags
);
424 list_for_each_entry(prm
, &card
->param_queue
, list
) {
425 if (prm
->port
== port
&& prm
->pid
== cmdpid
) {
428 wake_up(&card
->param_wq
);
433 spin_unlock_irqrestore(&card
->param_queue_lock
, flags
);
437 static ssize_t
console_show(struct device
*dev
, struct device_attribute
*attr
,
440 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
441 struct solos_card
*card
= atmdev
->dev_data
;
444 spin_lock(&card
->cli_queue_lock
);
445 skb
= skb_dequeue(&card
->cli_queue
[SOLOS_CHAN(atmdev
)]);
446 spin_unlock(&card
->cli_queue_lock
);
448 return sprintf(buf
, "No data.\n");
450 memcpy(buf
, skb
->data
, skb
->len
);
451 dev_dbg(&card
->dev
->dev
, "len: %d\n", skb
->len
);
457 static int send_command(struct solos_card
*card
, int dev
, const char *buf
, size_t size
)
460 struct pkt_hdr
*header
;
462 if (size
> (BUF_SIZE
- sizeof(*header
))) {
463 dev_dbg(&card
->dev
->dev
, "Command is too big. Dropping request\n");
466 skb
= alloc_skb(size
+ sizeof(*header
), GFP_ATOMIC
);
468 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in send_command()\n");
472 header
= (void *)skb_put(skb
, sizeof(*header
));
474 header
->size
= cpu_to_le16(size
);
475 header
->vpi
= cpu_to_le16(0);
476 header
->vci
= cpu_to_le16(0);
477 header
->type
= cpu_to_le16(PKT_COMMAND
);
479 memcpy(skb_put(skb
, size
), buf
, size
);
481 fpga_queue(card
, dev
, skb
, NULL
);
486 static ssize_t
console_store(struct device
*dev
, struct device_attribute
*attr
,
487 const char *buf
, size_t count
)
489 struct atm_dev
*atmdev
= container_of(dev
, struct atm_dev
, class_dev
);
490 struct solos_card
*card
= atmdev
->dev_data
;
493 err
= send_command(card
, SOLOS_CHAN(atmdev
), buf
, count
);
498 static DEVICE_ATTR(console
, 0644, console_show
, console_store
);
501 #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL);
502 #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store);
504 #include "solos-attrlist.c"
509 #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr,
510 #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr,
512 static struct attribute
*solos_attrs
[] = {
513 #include "solos-attrlist.c"
517 static struct attribute_group solos_attr_group
= {
518 .attrs
= solos_attrs
,
519 .name
= "parameters",
522 static int flash_upgrade(struct solos_card
*card
, int chip
)
524 const struct firmware
*fw
;
532 fw_name
= "solos-FPGA.bin";
533 blocksize
= FPGA_BLOCK
;
537 fw_name
= "solos-Firmware.bin";
538 blocksize
= SOLOS_BLOCK
;
542 if (card
->fpga_version
> LEGACY_BUFFERS
){
543 fw_name
= "solos-db-FPGA.bin";
544 blocksize
= FPGA_BLOCK
;
546 dev_info(&card
->dev
->dev
, "FPGA version doesn't support daughter board upgrades\n");
552 if (card
->fpga_version
> LEGACY_BUFFERS
){
553 fw_name
= "solos-Firmware.bin";
554 blocksize
= SOLOS_BLOCK
;
556 dev_info(&card
->dev
->dev
, "FPGA version doesn't support daughter board upgrades\n");
561 if (request_firmware(&fw
, fw_name
, &card
->dev
->dev
))
564 dev_info(&card
->dev
->dev
, "Flash upgrade starting\n");
566 numblocks
= fw
->size
/ blocksize
;
567 dev_info(&card
->dev
->dev
, "Firmware size: %zd\n", fw
->size
);
568 dev_info(&card
->dev
->dev
, "Number of blocks: %d\n", numblocks
);
570 dev_info(&card
->dev
->dev
, "Changing FPGA to Update mode\n");
571 iowrite32(1, card
->config_regs
+ FPGA_MODE
);
572 data32
= ioread32(card
->config_regs
+ FPGA_MODE
);
574 /* Set mode to Chip Erase */
575 if(chip
== 0 || chip
== 2)
576 dev_info(&card
->dev
->dev
, "Set FPGA Flash mode to FPGA Chip Erase\n");
577 if(chip
== 1 || chip
== 3)
578 dev_info(&card
->dev
->dev
, "Set FPGA Flash mode to Solos Chip Erase\n");
579 iowrite32((chip
* 2), card
->config_regs
+ FLASH_MODE
);
582 iowrite32(1, card
->config_regs
+ WRITE_FLASH
);
583 wait_event(card
->fw_wq
, !ioread32(card
->config_regs
+ FLASH_BUSY
));
585 for (offset
= 0; offset
< fw
->size
; offset
+= blocksize
) {
588 /* Clear write flag */
589 iowrite32(0, card
->config_regs
+ WRITE_FLASH
);
591 /* Set mode to Block Write */
592 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
593 iowrite32(((chip
* 2) + 1), card
->config_regs
+ FLASH_MODE
);
595 /* Copy block to buffer, swapping each 16 bits */
596 for(i
= 0; i
< blocksize
; i
+= 4) {
597 uint32_t word
= swahb32p((uint32_t *)(fw
->data
+ offset
+ i
));
598 if(card
->fpga_version
> LEGACY_BUFFERS
)
599 iowrite32(word
, FLASH_BUF
+ i
);
601 iowrite32(word
, RX_BUF(card
, 3) + i
);
604 /* Specify block number and then trigger flash write */
605 iowrite32(offset
/ blocksize
, card
->config_regs
+ FLASH_BLOCK
);
606 iowrite32(1, card
->config_regs
+ WRITE_FLASH
);
607 wait_event(card
->fw_wq
, !ioread32(card
->config_regs
+ FLASH_BUSY
));
610 release_firmware(fw
);
611 iowrite32(0, card
->config_regs
+ WRITE_FLASH
);
612 iowrite32(0, card
->config_regs
+ FPGA_MODE
);
613 iowrite32(0, card
->config_regs
+ FLASH_MODE
);
614 dev_info(&card
->dev
->dev
, "Returning FPGA to Data mode\n");
618 static irqreturn_t
solos_irq(int irq
, void *dev_id
)
620 struct solos_card
*card
= dev_id
;
623 iowrite32(0, card
->config_regs
+ IRQ_CLEAR
);
625 /* If we're up and running, just kick the tasklet to process TX/RX */
627 tasklet_schedule(&card
->tlet
);
629 wake_up(&card
->fw_wq
);
631 return IRQ_RETVAL(handled
);
634 void solos_bh(unsigned long card_arg
)
636 struct solos_card
*card
= (void *)card_arg
;
638 uint32_t rx_done
= 0;
642 * Since fpga_tx() is going to need to read the flags under its lock,
643 * it can return them to us so that we don't have to hit PCI MMIO
644 * again for the same information
646 card_flags
= fpga_tx(card
);
648 for (port
= 0; port
< card
->nr_ports
; port
++) {
649 if (card_flags
& (0x10 << port
)) {
650 struct pkt_hdr _hdr
, *header
;
655 if (card
->using_dma
) {
656 skb
= card
->rx_skb
[port
];
657 card
->rx_skb
[port
] = NULL
;
659 pci_unmap_single(card
->dev
, SKB_CB(skb
)->dma_addr
,
660 RX_DMA_SIZE
, PCI_DMA_FROMDEVICE
);
662 header
= (void *)skb
->data
;
663 size
= le16_to_cpu(header
->size
);
664 skb_put(skb
, size
+ sizeof(*header
));
665 skb_pull(skb
, sizeof(*header
));
669 rx_done
|= 0x10 << port
;
671 memcpy_fromio(header
, RX_BUF(card
, port
), sizeof(*header
));
673 size
= le16_to_cpu(header
->size
);
674 if (size
> (card
->buffer_size
- sizeof(*header
))){
675 dev_warn(&card
->dev
->dev
, "Invalid buffer size\n");
679 skb
= alloc_skb(size
+ 1, GFP_ATOMIC
);
682 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff for RX\n");
686 memcpy_fromio(skb_put(skb
, size
),
687 RX_BUF(card
, port
) + sizeof(*header
),
691 dev_info(&card
->dev
->dev
, "Received: device %d\n", port
);
692 dev_info(&card
->dev
->dev
, "size: %d VPI: %d VCI: %d\n",
693 size
, le16_to_cpu(header
->vpi
),
694 le16_to_cpu(header
->vci
));
698 switch (le16_to_cpu(header
->type
)) {
700 vcc
= find_vcc(card
->atmdev
[port
], le16_to_cpu(header
->vpi
),
701 le16_to_cpu(header
->vci
));
704 dev_warn(&card
->dev
->dev
, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
705 le16_to_cpu(header
->vci
), le16_to_cpu(header
->vpi
),
709 atm_charge(vcc
, skb
->truesize
);
711 atomic_inc(&vcc
->stats
->rx
);
715 if (process_status(card
, port
, skb
) &&
717 dev_warn(&card
->dev
->dev
, "Bad status packet of %d bytes on port %d:\n", skb
->len
, port
);
720 dev_kfree_skb_any(skb
);
724 default: /* FIXME: Not really, surely? */
725 if (process_command(card
, port
, skb
))
727 spin_lock(&card
->cli_queue_lock
);
728 if (skb_queue_len(&card
->cli_queue
[port
]) > 10) {
730 dev_warn(&card
->dev
->dev
, "Dropping console response on port %d\n",
732 dev_kfree_skb_any(skb
);
734 skb_queue_tail(&card
->cli_queue
[port
], skb
);
735 spin_unlock(&card
->cli_queue_lock
);
739 /* Allocate RX skbs for any ports which need them */
740 if (card
->using_dma
&& card
->atmdev
[port
] &&
741 !card
->rx_skb
[port
]) {
742 struct sk_buff
*skb
= alloc_skb(RX_DMA_SIZE
, GFP_ATOMIC
);
744 SKB_CB(skb
)->dma_addr
=
745 pci_map_single(card
->dev
, skb
->data
,
746 RX_DMA_SIZE
, PCI_DMA_FROMDEVICE
);
747 iowrite32(SKB_CB(skb
)->dma_addr
,
748 card
->config_regs
+ RX_DMA_ADDR(port
));
749 card
->rx_skb
[port
] = skb
;
752 dev_warn(&card
->dev
->dev
, "Failed to allocate RX skb");
754 /* We'll have to try again later */
755 tasklet_schedule(&card
->tlet
);
760 iowrite32(rx_done
, card
->config_regs
+ FLAGS_ADDR
);
765 static struct atm_vcc
*find_vcc(struct atm_dev
*dev
, short vpi
, int vci
)
767 struct hlist_head
*head
;
768 struct atm_vcc
*vcc
= NULL
;
769 struct hlist_node
*node
;
772 read_lock(&vcc_sklist_lock
);
773 head
= &vcc_hash
[vci
& (VCC_HTABLE_SIZE
-1)];
774 sk_for_each(s
, node
, head
) {
776 if (vcc
->dev
== dev
&& vcc
->vci
== vci
&&
777 vcc
->vpi
== vpi
&& vcc
->qos
.rxtp
.traffic_class
!= ATM_NONE
)
782 read_unlock(&vcc_sklist_lock
);
786 static int list_vccs(int vci
)
788 struct hlist_head
*head
;
790 struct hlist_node
*node
;
795 read_lock(&vcc_sklist_lock
);
797 head
= &vcc_hash
[vci
& (VCC_HTABLE_SIZE
-1)];
798 sk_for_each(s
, node
, head
) {
801 printk(KERN_DEBUG
"Device: %d Vpi: %d Vci: %d\n",
807 for(i
= 0; i
< VCC_HTABLE_SIZE
; i
++){
809 sk_for_each(s
, node
, head
) {
812 printk(KERN_DEBUG
"Device: %d Vpi: %d Vci: %d\n",
819 read_unlock(&vcc_sklist_lock
);
823 static void release_vccs(struct atm_dev
*dev
)
827 write_lock_irq(&vcc_sklist_lock
);
828 for (i
= 0; i
< VCC_HTABLE_SIZE
; i
++) {
829 struct hlist_head
*head
= &vcc_hash
[i
];
830 struct hlist_node
*node
, *tmp
;
834 sk_for_each_safe(s
, node
, tmp
, head
) {
836 if (vcc
->dev
== dev
) {
837 vcc_release_async(vcc
, -EPIPE
);
842 write_unlock_irq(&vcc_sklist_lock
);
846 static int popen(struct atm_vcc
*vcc
)
848 struct solos_card
*card
= vcc
->dev
->dev_data
;
850 struct pkt_hdr
*header
;
852 if (vcc
->qos
.aal
!= ATM_AAL5
) {
853 dev_warn(&card
->dev
->dev
, "Unsupported ATM type %d\n",
858 skb
= alloc_skb(sizeof(*header
), GFP_ATOMIC
);
859 if (!skb
&& net_ratelimit()) {
860 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in popen()\n");
863 header
= (void *)skb_put(skb
, sizeof(*header
));
865 header
->size
= cpu_to_le16(0);
866 header
->vpi
= cpu_to_le16(vcc
->vpi
);
867 header
->vci
= cpu_to_le16(vcc
->vci
);
868 header
->type
= cpu_to_le16(PKT_POPEN
);
870 fpga_queue(card
, SOLOS_CHAN(vcc
->dev
), skb
, NULL
);
872 set_bit(ATM_VF_ADDR
, &vcc
->flags
);
873 set_bit(ATM_VF_READY
, &vcc
->flags
);
880 static void pclose(struct atm_vcc
*vcc
)
882 struct solos_card
*card
= vcc
->dev
->dev_data
;
884 struct pkt_hdr
*header
;
886 skb
= alloc_skb(sizeof(*header
), GFP_ATOMIC
);
888 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in pclose()\n");
891 header
= (void *)skb_put(skb
, sizeof(*header
));
893 header
->size
= cpu_to_le16(0);
894 header
->vpi
= cpu_to_le16(vcc
->vpi
);
895 header
->vci
= cpu_to_le16(vcc
->vci
);
896 header
->type
= cpu_to_le16(PKT_PCLOSE
);
898 fpga_queue(card
, SOLOS_CHAN(vcc
->dev
), skb
, NULL
);
900 clear_bit(ATM_VF_ADDR
, &vcc
->flags
);
901 clear_bit(ATM_VF_READY
, &vcc
->flags
);
906 static int print_buffer(struct sk_buff
*buf
)
913 for (i
= 0; i
< len
; i
++){
915 sprintf(msg
, "%02X: ", i
);
917 sprintf(item
,"%02X ",*(buf
->data
+ i
));
922 printk(KERN_DEBUG
"%s", msg
);
928 printk(KERN_DEBUG
"%s", msg
);
930 printk(KERN_DEBUG
"\n");
935 static void fpga_queue(struct solos_card
*card
, int port
, struct sk_buff
*skb
,
941 SKB_CB(skb
)->vcc
= vcc
;
943 spin_lock_irqsave(&card
->tx_queue_lock
, flags
);
944 old_len
= skb_queue_len(&card
->tx_queue
[port
]);
945 skb_queue_tail(&card
->tx_queue
[port
], skb
);
947 card
->tx_mask
|= (1 << port
);
948 spin_unlock_irqrestore(&card
->tx_queue_lock
, flags
);
950 /* Theoretically we could just schedule the tasklet here, but
951 that introduces latency we don't want -- it's noticeable */
956 static uint32_t fpga_tx(struct solos_card
*card
)
958 uint32_t tx_pending
, card_flags
;
959 uint32_t tx_started
= 0;
965 spin_lock_irqsave(&card
->tx_lock
, flags
);
967 card_flags
= ioread32(card
->config_regs
+ FLAGS_ADDR
);
969 * The queue lock is required for _writing_ to tx_mask, but we're
970 * OK to read it here without locking. The only potential update
971 * that we could race with is in fpga_queue() where it sets a bit
972 * for a new port... but it's going to call this function again if
973 * it's doing that, anyway.
975 tx_pending
= card
->tx_mask
& ~card_flags
;
977 for (port
= 0; tx_pending
; tx_pending
>>= 1, port
++) {
978 if (tx_pending
& 1) {
979 struct sk_buff
*oldskb
= card
->tx_skb
[port
];
981 pci_unmap_single(card
->dev
, SKB_CB(oldskb
)->dma_addr
,
982 oldskb
->len
, PCI_DMA_TODEVICE
);
984 spin_lock(&card
->tx_queue_lock
);
985 skb
= skb_dequeue(&card
->tx_queue
[port
]);
987 card
->tx_mask
&= ~(1 << port
);
988 spin_unlock(&card
->tx_queue_lock
);
990 if (skb
&& !card
->using_dma
) {
991 memcpy_toio(TX_BUF(card
, port
), skb
->data
, skb
->len
);
992 tx_started
|= 1 << port
;
993 oldskb
= skb
; /* We're done with this skb already */
994 } else if (skb
&& card
->using_dma
) {
995 SKB_CB(skb
)->dma_addr
= pci_map_single(card
->dev
, skb
->data
,
996 skb
->len
, PCI_DMA_TODEVICE
);
997 iowrite32(SKB_CB(skb
)->dma_addr
,
998 card
->config_regs
+ TX_DMA_ADDR(port
));
1004 /* Clean up and free oldskb now it's gone */
1006 dev_info(&card
->dev
->dev
, "Transmitted: port %d\n",
1008 print_buffer(oldskb
);
1011 vcc
= SKB_CB(oldskb
)->vcc
;
1014 atomic_inc(&vcc
->stats
->tx
);
1015 solos_pop(vcc
, oldskb
);
1017 dev_kfree_skb_irq(oldskb
);
1021 /* For non-DMA TX, write the 'TX start' bit for all four ports simultaneously */
1023 iowrite32(tx_started
, card
->config_regs
+ FLAGS_ADDR
);
1025 spin_unlock_irqrestore(&card
->tx_lock
, flags
);
1029 static int psend(struct atm_vcc
*vcc
, struct sk_buff
*skb
)
1031 struct solos_card
*card
= vcc
->dev
->dev_data
;
1032 struct pkt_hdr
*header
;
1036 if (pktlen
> (BUF_SIZE
- sizeof(*header
))) {
1037 dev_warn(&card
->dev
->dev
, "Length of PDU is too large. Dropping PDU.\n");
1038 solos_pop(vcc
, skb
);
1042 if (!skb_clone_writable(skb
, sizeof(*header
))) {
1046 if (skb_headroom(skb
) < sizeof(*header
))
1047 expand_by
= sizeof(*header
) - skb_headroom(skb
);
1049 ret
= pskb_expand_head(skb
, expand_by
, 0, GFP_ATOMIC
);
1051 dev_warn(&card
->dev
->dev
, "pskb_expand_head failed.\n");
1052 solos_pop(vcc
, skb
);
1057 header
= (void *)skb_push(skb
, sizeof(*header
));
1059 /* This does _not_ include the size of the header */
1060 header
->size
= cpu_to_le16(pktlen
);
1061 header
->vpi
= cpu_to_le16(vcc
->vpi
);
1062 header
->vci
= cpu_to_le16(vcc
->vci
);
1063 header
->type
= cpu_to_le16(PKT_DATA
);
1065 fpga_queue(card
, SOLOS_CHAN(vcc
->dev
), skb
, vcc
);
1070 static struct atmdev_ops fpga_ops
= {
1082 .owner
= THIS_MODULE
1085 static int fpga_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
1089 uint8_t major_ver
, minor_ver
;
1091 struct solos_card
*card
;
1093 card
= kzalloc(sizeof(*card
), GFP_KERNEL
);
1098 init_waitqueue_head(&card
->fw_wq
);
1099 init_waitqueue_head(&card
->param_wq
);
1101 err
= pci_enable_device(dev
);
1103 dev_warn(&dev
->dev
, "Failed to enable PCI device\n");
1107 err
= pci_set_dma_mask(dev
, DMA_BIT_MASK(32));
1109 dev_warn(&dev
->dev
, "Failed to set 32-bit DMA mask\n");
1113 err
= pci_request_regions(dev
, "solos");
1115 dev_warn(&dev
->dev
, "Failed to request regions\n");
1119 card
->config_regs
= pci_iomap(dev
, 0, CONFIG_RAM_SIZE
);
1120 if (!card
->config_regs
) {
1121 dev_warn(&dev
->dev
, "Failed to ioremap config registers\n");
1122 goto out_release_regions
;
1124 card
->buffers
= pci_iomap(dev
, 1, DATA_RAM_SIZE
);
1125 if (!card
->buffers
) {
1126 dev_warn(&dev
->dev
, "Failed to ioremap data buffers\n");
1127 goto out_unmap_config
;
1131 iowrite32(1, card
->config_regs
+ FPGA_MODE
);
1132 data32
= ioread32(card
->config_regs
+ FPGA_MODE
);
1134 iowrite32(0, card
->config_regs
+ FPGA_MODE
);
1135 data32
= ioread32(card
->config_regs
+ FPGA_MODE
);
1138 data32
= ioread32(card
->config_regs
+ FPGA_VER
);
1139 fpga_ver
= (data32
& 0x0000FFFF);
1140 major_ver
= ((data32
& 0xFF000000) >> 24);
1141 minor_ver
= ((data32
& 0x00FF0000) >> 16);
1142 card
->fpga_version
= FPGA_VERSION(major_ver
,minor_ver
);
1143 if (card
->fpga_version
> LEGACY_BUFFERS
)
1144 card
->buffer_size
= BUF_SIZE
;
1146 card
->buffer_size
= OLD_BUF_SIZE
;
1147 dev_info(&dev
->dev
, "Solos FPGA Version %d.%02d svn-%d\n",
1148 major_ver
, minor_ver
, fpga_ver
);
1150 if (card
->fpga_version
>= DMA_SUPPORTED
){
1151 card
->using_dma
= 1;
1153 card
->using_dma
= 0;
1154 /* Set RX empty flag for all ports */
1155 iowrite32(0xF0, card
->config_regs
+ FLAGS_ADDR
);
1158 data32
= ioread32(card
->config_regs
+ PORTS
);
1159 card
->nr_ports
= (data32
& 0x000000FF);
1161 pci_set_drvdata(dev
, card
);
1163 tasklet_init(&card
->tlet
, solos_bh
, (unsigned long)card
);
1164 spin_lock_init(&card
->tx_lock
);
1165 spin_lock_init(&card
->tx_queue_lock
);
1166 spin_lock_init(&card
->cli_queue_lock
);
1167 spin_lock_init(&card
->param_queue_lock
);
1168 INIT_LIST_HEAD(&card
->param_queue
);
1170 err
= request_irq(dev
->irq
, solos_irq
, IRQF_SHARED
,
1173 dev_dbg(&card
->dev
->dev
, "Failed to request interrupt IRQ: %d\n", dev
->irq
);
1174 goto out_unmap_both
;
1177 iowrite32(1, card
->config_regs
+ IRQ_EN_ADDR
);
1180 flash_upgrade(card
, 0);
1182 if (firmware_upgrade
)
1183 flash_upgrade(card
, 1);
1185 if (db_fpga_upgrade
)
1186 flash_upgrade(card
, 2);
1188 if (db_firmware_upgrade
)
1189 flash_upgrade(card
, 3);
1191 err
= atm_init(card
);
1198 iowrite32(0, card
->config_regs
+ IRQ_EN_ADDR
);
1199 free_irq(dev
->irq
, card
);
1200 tasklet_kill(&card
->tlet
);
1203 pci_set_drvdata(dev
, NULL
);
1204 pci_iounmap(dev
, card
->config_regs
);
1206 pci_iounmap(dev
, card
->buffers
);
1207 out_release_regions
:
1208 pci_release_regions(dev
);
1214 static int atm_init(struct solos_card
*card
)
1218 for (i
= 0; i
< card
->nr_ports
; i
++) {
1219 struct sk_buff
*skb
;
1220 struct pkt_hdr
*header
;
1222 skb_queue_head_init(&card
->tx_queue
[i
]);
1223 skb_queue_head_init(&card
->cli_queue
[i
]);
1225 card
->atmdev
[i
] = atm_dev_register("solos-pci", &fpga_ops
, -1, NULL
);
1226 if (!card
->atmdev
[i
]) {
1227 dev_err(&card
->dev
->dev
, "Could not register ATM device %d\n", i
);
1231 if (device_create_file(&card
->atmdev
[i
]->class_dev
, &dev_attr_console
))
1232 dev_err(&card
->dev
->dev
, "Could not register console for ATM device %d\n", i
);
1233 if (sysfs_create_group(&card
->atmdev
[i
]->class_dev
.kobj
, &solos_attr_group
))
1234 dev_err(&card
->dev
->dev
, "Could not register parameter group for ATM device %d\n", i
);
1236 dev_info(&card
->dev
->dev
, "Registered ATM device %d\n", card
->atmdev
[i
]->number
);
1238 card
->atmdev
[i
]->ci_range
.vpi_bits
= 8;
1239 card
->atmdev
[i
]->ci_range
.vci_bits
= 16;
1240 card
->atmdev
[i
]->dev_data
= card
;
1241 card
->atmdev
[i
]->phy_data
= (void *)(unsigned long)i
;
1242 card
->atmdev
[i
]->signal
= ATM_PHY_SIG_UNKNOWN
;
1244 skb
= alloc_skb(sizeof(*header
), GFP_ATOMIC
);
1246 dev_warn(&card
->dev
->dev
, "Failed to allocate sk_buff in atm_init()\n");
1250 header
= (void *)skb_put(skb
, sizeof(*header
));
1252 header
->size
= cpu_to_le16(0);
1253 header
->vpi
= cpu_to_le16(0);
1254 header
->vci
= cpu_to_le16(0);
1255 header
->type
= cpu_to_le16(PKT_STATUS
);
1257 fpga_queue(card
, i
, skb
, NULL
);
1262 static void atm_remove(struct solos_card
*card
)
1266 for (i
= 0; i
< card
->nr_ports
; i
++) {
1267 if (card
->atmdev
[i
]) {
1268 struct sk_buff
*skb
;
1270 dev_info(&card
->dev
->dev
, "Unregistering ATM device %d\n", card
->atmdev
[i
]->number
);
1272 sysfs_remove_group(&card
->atmdev
[i
]->class_dev
.kobj
, &solos_attr_group
);
1273 atm_dev_deregister(card
->atmdev
[i
]);
1275 skb
= card
->rx_skb
[i
];
1277 pci_unmap_single(card
->dev
, SKB_CB(skb
)->dma_addr
,
1278 RX_DMA_SIZE
, PCI_DMA_FROMDEVICE
);
1281 skb
= card
->tx_skb
[i
];
1283 pci_unmap_single(card
->dev
, SKB_CB(skb
)->dma_addr
,
1284 skb
->len
, PCI_DMA_TODEVICE
);
1287 while ((skb
= skb_dequeue(&card
->tx_queue
[i
])))
1294 static void fpga_remove(struct pci_dev
*dev
)
1296 struct solos_card
*card
= pci_get_drvdata(dev
);
1299 iowrite32(0, card
->config_regs
+ IRQ_EN_ADDR
);
1302 iowrite32(1, card
->config_regs
+ FPGA_MODE
);
1303 (void)ioread32(card
->config_regs
+ FPGA_MODE
);
1307 free_irq(dev
->irq
, card
);
1308 tasklet_kill(&card
->tlet
);
1310 /* Release device from reset */
1311 iowrite32(0, card
->config_regs
+ FPGA_MODE
);
1312 (void)ioread32(card
->config_regs
+ FPGA_MODE
);
1314 pci_iounmap(dev
, card
->buffers
);
1315 pci_iounmap(dev
, card
->config_regs
);
1317 pci_release_regions(dev
);
1318 pci_disable_device(dev
);
1320 pci_set_drvdata(dev
, NULL
);
1324 static struct pci_device_id fpga_pci_tbl
[] __devinitdata
= {
1325 { 0x10ee, 0x0300, PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, 0 },
1329 MODULE_DEVICE_TABLE(pci
,fpga_pci_tbl
);
1331 static struct pci_driver fpga_driver
= {
1333 .id_table
= fpga_pci_tbl
,
1334 .probe
= fpga_probe
,
1335 .remove
= fpga_remove
,
1339 static int __init
solos_pci_init(void)
1341 printk(KERN_INFO
"Solos PCI Driver Version %s\n", VERSION
);
1342 return pci_register_driver(&fpga_driver
);
1345 static void __exit
solos_pci_exit(void)
1347 pci_unregister_driver(&fpga_driver
);
1348 printk(KERN_INFO
"Solos PCI Driver %s Unloaded\n", VERSION
);
1351 module_init(solos_pci_init
);
1352 module_exit(solos_pci_exit
);