d7ad19d2603a626f8df75fef1d96835cd84c4bab
[linux-2.6.git] / drivers / atm / solos-pci.c
1 /*
2  * Driver for the Solos PCI ADSL2+ card, designed to support Linux by
3  *  Traverse Technologies -- http://www.traverse.com.au/
4  *  Xrio Limited          -- http://www.xrio.com/
5  *
6  *
7  * Copyright © 2008 Traverse Technologies
8  * Copyright © 2008 Intel Corporation
9  *
10  * Authors: Nathan Williams <nathan@traverse.com.au>
11  *          David Woodhouse <dwmw2@infradead.org>
12  *          Treker Chen <treker@xrio.com>
13  *
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.
17  *
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.
22  */
23
24 #define DEBUG
25 #define VERBOSE_DEBUG
26
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>
43
44 #define VERSION "0.07"
45 #define PTAG "solos-pci"
46
47 #define CONFIG_RAM_SIZE 128
48 #define FLAGS_ADDR      0x7C
49 #define IRQ_EN_ADDR     0x78
50 #define FPGA_VER        0x74
51 #define IRQ_CLEAR       0x70
52 #define WRITE_FLASH     0x6C
53 #define PORTS           0x68
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)))
60
61 #define DATA_RAM_SIZE   32768
62 #define BUF_SIZE        2048
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*/
68
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)
72
73 #define RX_DMA_SIZE     2048
74
75 #define FPGA_VERSION(a,b) (((a) << 8) + (b))
76 #define LEGACY_BUFFERS  2
77 #define DMA_SUPPORTED   4
78
79 static int reset = 0;
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;
85
86 struct pkt_hdr {
87         __le16 size;
88         __le16 vpi;
89         __le16 vci;
90         __le16 type;
91 };
92
93 struct solos_skb_cb {
94         struct atm_vcc *vcc;
95         uint32_t dma_addr;
96 };
97
98
99 #define SKB_CB(skb)             ((struct solos_skb_cb *)skb->cb)
100
101 #define PKT_DATA        0
102 #define PKT_COMMAND     1
103 #define PKT_POPEN       3
104 #define PKT_PCLOSE      4
105 #define PKT_STATUS      5
106
107 struct solos_card {
108         void __iomem *config_regs;
109         void __iomem *buffers;
110         int nr_ports;
111         int tx_mask;
112         struct pci_dev *dev;
113         struct atm_dev *atmdev[4];
114         struct tasklet_struct tlet;
115         spinlock_t tx_lock;
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;
126         int using_dma;
127         int fpga_version;
128         int buffer_size;
129 };
130
131
132 struct solos_param {
133         struct list_head list;
134         pid_t pid;
135         int port;
136         struct sk_buff *response;
137 };
138
139 #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
140
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_FIRMWARE("solos-FPGA.bin");
146 MODULE_FIRMWARE("solos-Firmware.bin");
147 MODULE_FIRMWARE("solos-db-FPGA.bin");
148 MODULE_PARM_DESC(reset, "Reset Solos chips on startup");
149 MODULE_PARM_DESC(atmdebug, "Print ATM data");
150 MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade");
151 MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade");
152 MODULE_PARM_DESC(db_firmware_upgrade, "Initiate daughter board Solos firmware upgrade");
153 MODULE_PARM_DESC(db_fpga_upgrade, "Initiate daughter board FPGA upgrade");
154 module_param(reset, int, 0444);
155 module_param(atmdebug, int, 0644);
156 module_param(firmware_upgrade, int, 0444);
157 module_param(fpga_upgrade, int, 0444);
158 module_param(db_firmware_upgrade, int, 0444);
159 module_param(db_fpga_upgrade, int, 0444);
160
161 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
162                        struct atm_vcc *vcc);
163 static uint32_t fpga_tx(struct solos_card *);
164 static irqreturn_t solos_irq(int irq, void *dev_id);
165 static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
166 static int list_vccs(int vci);
167 static void release_vccs(struct atm_dev *dev);
168 static int atm_init(struct solos_card *);
169 static void atm_remove(struct solos_card *);
170 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
171 static void solos_bh(unsigned long);
172 static int print_buffer(struct sk_buff *buf);
173
174 static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb)
175 {
176         if (vcc->pop)
177                 vcc->pop(vcc, skb);
178         else
179                 dev_kfree_skb_any(skb);
180 }
181
182 static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr,
183                                 char *buf)
184 {
185         struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
186         struct solos_card *card = atmdev->dev_data;
187         struct solos_param prm;
188         struct sk_buff *skb;
189         struct pkt_hdr *header;
190         int buflen;
191
192         buflen = strlen(attr->attr.name) + 10;
193
194         skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL);
195         if (!skb) {
196                 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n");
197                 return -ENOMEM;
198         }
199
200         header = (void *)skb_put(skb, sizeof(*header));
201
202         buflen = snprintf((void *)&header[1], buflen - 1,
203                           "L%05d\n%s\n", current->pid, attr->attr.name);
204         skb_put(skb, buflen);
205
206         header->size = cpu_to_le16(buflen);
207         header->vpi = cpu_to_le16(0);
208         header->vci = cpu_to_le16(0);
209         header->type = cpu_to_le16(PKT_COMMAND);
210
211         prm.pid = current->pid;
212         prm.response = NULL;
213         prm.port = SOLOS_CHAN(atmdev);
214
215         spin_lock_irq(&card->param_queue_lock);
216         list_add(&prm.list, &card->param_queue);
217         spin_unlock_irq(&card->param_queue_lock);
218
219         fpga_queue(card, prm.port, skb, NULL);
220
221         wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
222
223         spin_lock_irq(&card->param_queue_lock);
224         list_del(&prm.list);
225         spin_unlock_irq(&card->param_queue_lock);
226
227         if (!prm.response)
228                 return -EIO;
229
230         buflen = prm.response->len;
231         memcpy(buf, prm.response->data, buflen);
232         kfree_skb(prm.response);
233
234         return buflen;
235 }
236
237 static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr,
238                                  const char *buf, size_t count)
239 {
240         struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
241         struct solos_card *card = atmdev->dev_data;
242         struct solos_param prm;
243         struct sk_buff *skb;
244         struct pkt_hdr *header;
245         int buflen;
246         ssize_t ret;
247
248         buflen = strlen(attr->attr.name) + 11 + count;
249
250         skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL);
251         if (!skb) {
252                 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n");
253                 return -ENOMEM;
254         }
255
256         header = (void *)skb_put(skb, sizeof(*header));
257
258         buflen = snprintf((void *)&header[1], buflen - 1,
259                           "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf);
260
261         skb_put(skb, buflen);
262         header->size = cpu_to_le16(buflen);
263         header->vpi = cpu_to_le16(0);
264         header->vci = cpu_to_le16(0);
265         header->type = cpu_to_le16(PKT_COMMAND);
266
267         prm.pid = current->pid;
268         prm.response = NULL;
269         prm.port = SOLOS_CHAN(atmdev);
270
271         spin_lock_irq(&card->param_queue_lock);
272         list_add(&prm.list, &card->param_queue);
273         spin_unlock_irq(&card->param_queue_lock);
274
275         fpga_queue(card, prm.port, skb, NULL);
276
277         wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
278
279         spin_lock_irq(&card->param_queue_lock);
280         list_del(&prm.list);
281         spin_unlock_irq(&card->param_queue_lock);
282
283         skb = prm.response;
284
285         if (!skb)
286                 return -EIO;
287
288         buflen = skb->len;
289
290         /* Sometimes it has a newline, sometimes it doesn't. */
291         if (skb->data[buflen - 1] == '\n')
292                 buflen--;
293
294         if (buflen == 2 && !strncmp(skb->data, "OK", 2))
295                 ret = count;
296         else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5))
297                 ret = -EIO;
298         else {
299                 /* We know we have enough space allocated for this; we allocated 
300                    it ourselves */
301                 skb->data[buflen] = 0;
302         
303                 dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n",
304                          skb->data);
305                 ret = -EIO;
306         }
307         kfree_skb(skb);
308
309         return ret;
310 }
311
312 static char *next_string(struct sk_buff *skb)
313 {
314         int i = 0;
315         char *this = skb->data;
316         
317         for (i = 0; i < skb->len; i++) {
318                 if (this[i] == '\n') {
319                         this[i] = 0;
320                         skb_pull(skb, i + 1);
321                         return this;
322                 }
323                 if (!isprint(this[i]))
324                         return NULL;
325         }
326         return NULL;
327 }
328
329 /*
330  * Status packet has fields separated by \n, starting with a version number
331  * for the information therein. Fields are....
332  *
333  *     packet version
334  *     RxBitRate        (version >= 1)
335  *     TxBitRate        (version >= 1)
336  *     State            (version >= 1)
337  *     LocalSNRMargin   (version >= 1)
338  *     LocalLineAttn    (version >= 1)
339  */       
340 static int process_status(struct solos_card *card, int port, struct sk_buff *skb)
341 {
342         char *str, *end, *state_str, *snr, *attn;
343         int ver, rate_up, rate_down;
344
345         if (!card->atmdev[port])
346                 return -ENODEV;
347
348         str = next_string(skb);
349         if (!str)
350                 return -EIO;
351
352         ver = simple_strtol(str, NULL, 10);
353         if (ver < 1) {
354                 dev_warn(&card->dev->dev, "Unexpected status interrupt version %d\n",
355                          ver);
356                 return -EIO;
357         }
358
359         str = next_string(skb);
360         if (!str)
361                 return -EIO;
362         if (!strcmp(str, "ERROR")) {
363                 dev_dbg(&card->dev->dev, "Status packet indicated Solos error on port %d (starting up?)\n",
364                          port);
365                 return 0;
366         }
367
368         rate_down = simple_strtol(str, &end, 10);
369         if (*end)
370                 return -EIO;
371
372         str = next_string(skb);
373         if (!str)
374                 return -EIO;
375         rate_up = simple_strtol(str, &end, 10);
376         if (*end)
377                 return -EIO;
378
379         state_str = next_string(skb);
380         if (!state_str)
381                 return -EIO;
382
383         /* Anything but 'Showtime' is down */
384         if (strcmp(state_str, "Showtime")) {
385                 card->atmdev[port]->signal = ATM_PHY_SIG_LOST;
386                 release_vccs(card->atmdev[port]);
387                 dev_info(&card->dev->dev, "Port %d: %s\n", port, state_str);
388                 return 0;
389         }
390
391         snr = next_string(skb);
392         if (!snr)
393                 return -EIO;
394         attn = next_string(skb);
395         if (!attn)
396                 return -EIO;
397
398         dev_info(&card->dev->dev, "Port %d: %s @%d/%d kb/s%s%s%s%s\n",
399                  port, state_str, rate_down/1000, rate_up/1000,
400                  snr[0]?", SNR ":"", snr, attn[0]?", Attn ":"", attn);
401         
402         card->atmdev[port]->link_rate = rate_down / 424;
403         card->atmdev[port]->signal = ATM_PHY_SIG_FOUND;
404
405         return 0;
406 }
407
408 static int process_command(struct solos_card *card, int port, struct sk_buff *skb)
409 {
410         struct solos_param *prm;
411         unsigned long flags;
412         int cmdpid;
413         int found = 0;
414
415         if (skb->len < 7)
416                 return 0;
417
418         if (skb->data[0] != 'L'    || !isdigit(skb->data[1]) ||
419             !isdigit(skb->data[2]) || !isdigit(skb->data[3]) ||
420             !isdigit(skb->data[4]) || !isdigit(skb->data[5]) ||
421             skb->data[6] != '\n')
422                 return 0;
423
424         cmdpid = simple_strtol(&skb->data[1], NULL, 10);
425
426         spin_lock_irqsave(&card->param_queue_lock, flags);
427         list_for_each_entry(prm, &card->param_queue, list) {
428                 if (prm->port == port && prm->pid == cmdpid) {
429                         prm->response = skb;
430                         skb_pull(skb, 7);
431                         wake_up(&card->param_wq);
432                         found = 1;
433                         break;
434                 }
435         }
436         spin_unlock_irqrestore(&card->param_queue_lock, flags);
437         return found;
438 }
439
440 static ssize_t console_show(struct device *dev, struct device_attribute *attr,
441                             char *buf)
442 {
443         struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
444         struct solos_card *card = atmdev->dev_data;
445         struct sk_buff *skb;
446
447         spin_lock(&card->cli_queue_lock);
448         skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
449         spin_unlock(&card->cli_queue_lock);
450         if(skb == NULL)
451                 return sprintf(buf, "No data.\n");
452
453         memcpy(buf, skb->data, skb->len);
454         dev_dbg(&card->dev->dev, "len: %d\n", skb->len);
455
456         kfree_skb(skb);
457         return skb->len;
458 }
459
460 static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
461 {
462         struct sk_buff *skb;
463         struct pkt_hdr *header;
464
465         if (size > (BUF_SIZE - sizeof(*header))) {
466                 dev_dbg(&card->dev->dev, "Command is too big.  Dropping request\n");
467                 return 0;
468         }
469         skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC);
470         if (!skb) {
471                 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n");
472                 return 0;
473         }
474
475         header = (void *)skb_put(skb, sizeof(*header));
476
477         header->size = cpu_to_le16(size);
478         header->vpi = cpu_to_le16(0);
479         header->vci = cpu_to_le16(0);
480         header->type = cpu_to_le16(PKT_COMMAND);
481
482         memcpy(skb_put(skb, size), buf, size);
483
484         fpga_queue(card, dev, skb, NULL);
485
486         return 0;
487 }
488
489 static ssize_t console_store(struct device *dev, struct device_attribute *attr,
490                              const char *buf, size_t count)
491 {
492         struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
493         struct solos_card *card = atmdev->dev_data;
494         int err;
495
496         err = send_command(card, SOLOS_CHAN(atmdev), buf, count);
497
498         return err?:count;
499 }
500
501 static DEVICE_ATTR(console, 0644, console_show, console_store);
502
503
504 #define SOLOS_ATTR_RO(x) static DEVICE_ATTR(x, 0444, solos_param_show, NULL);
505 #define SOLOS_ATTR_RW(x) static DEVICE_ATTR(x, 0644, solos_param_show, solos_param_store);
506
507 #include "solos-attrlist.c"
508
509 #undef SOLOS_ATTR_RO
510 #undef SOLOS_ATTR_RW
511
512 #define SOLOS_ATTR_RO(x) &dev_attr_##x.attr,
513 #define SOLOS_ATTR_RW(x) &dev_attr_##x.attr,
514
515 static struct attribute *solos_attrs[] = {
516 #include "solos-attrlist.c"
517         NULL
518 };
519
520 static struct attribute_group solos_attr_group = {
521         .attrs = solos_attrs,
522         .name = "parameters",
523 };
524
525 static int flash_upgrade(struct solos_card *card, int chip)
526 {
527         const struct firmware *fw;
528         const char *fw_name;
529         uint32_t data32 = 0;
530         int blocksize = 0;
531         int numblocks = 0;
532         int offset;
533
534         if (chip == 0) {
535                 fw_name = "solos-FPGA.bin";
536                 blocksize = FPGA_BLOCK;
537         } 
538         
539         if (chip == 1) {
540                 fw_name = "solos-Firmware.bin";
541                 blocksize = SOLOS_BLOCK;
542         }
543         
544         if (chip == 2){
545                 if (card->fpga_version > LEGACY_BUFFERS){
546                         fw_name = "solos-db-FPGA.bin";
547                         blocksize = FPGA_BLOCK;
548                 } else {
549                         dev_info(&card->dev->dev, "FPGA version doesn't support daughter board upgrades\n");
550                         return -EPERM;
551                 }
552         }
553         
554         if (chip == 3){
555                 if (card->fpga_version > LEGACY_BUFFERS){
556                         fw_name = "solos-Firmware.bin";
557                         blocksize = SOLOS_BLOCK;
558                 } else {
559                 dev_info(&card->dev->dev, "FPGA version doesn't support daughter board upgrades\n");
560                 return -EPERM;
561                 }
562         }
563
564         if (request_firmware(&fw, fw_name, &card->dev->dev))
565                 return -ENOENT;
566
567         dev_info(&card->dev->dev, "Flash upgrade starting\n");
568
569         numblocks = fw->size / blocksize;
570         dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size);
571         dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks);
572         
573         dev_info(&card->dev->dev, "Changing FPGA to Update mode\n");
574         iowrite32(1, card->config_regs + FPGA_MODE);
575         data32 = ioread32(card->config_regs + FPGA_MODE); 
576
577         /* Set mode to Chip Erase */
578         if(chip == 0 || chip == 2)
579                 dev_info(&card->dev->dev, "Set FPGA Flash mode to FPGA Chip Erase\n");
580         if(chip == 1 || chip == 3)
581                 dev_info(&card->dev->dev, "Set FPGA Flash mode to Solos Chip Erase\n");
582         iowrite32((chip * 2), card->config_regs + FLASH_MODE);
583
584
585         iowrite32(1, card->config_regs + WRITE_FLASH);
586         wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
587
588         for (offset = 0; offset < fw->size; offset += blocksize) {
589                 int i;
590
591                 /* Clear write flag */
592                 iowrite32(0, card->config_regs + WRITE_FLASH);
593
594                 /* Set mode to Block Write */
595                 /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
596                 iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE);
597
598                 /* Copy block to buffer, swapping each 16 bits */
599                 for(i = 0; i < blocksize; i += 4) {
600                         uint32_t word = swahb32p((uint32_t *)(fw->data + offset + i));
601                         if(card->fpga_version > LEGACY_BUFFERS)
602                                 iowrite32(word, FLASH_BUF + i);
603                         else
604                                 iowrite32(word, RX_BUF(card, 3) + i);
605                 }
606
607                 /* Specify block number and then trigger flash write */
608                 iowrite32(offset / blocksize, card->config_regs + FLASH_BLOCK);
609                 iowrite32(1, card->config_regs + WRITE_FLASH);
610                 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
611         }
612
613         release_firmware(fw);
614         iowrite32(0, card->config_regs + WRITE_FLASH);
615         iowrite32(0, card->config_regs + FPGA_MODE);
616         iowrite32(0, card->config_regs + FLASH_MODE);
617         dev_info(&card->dev->dev, "Returning FPGA to Data mode\n");
618         return 0;
619 }
620
621 static irqreturn_t solos_irq(int irq, void *dev_id)
622 {
623         struct solos_card *card = dev_id;
624         int handled = 1;
625
626         iowrite32(0, card->config_regs + IRQ_CLEAR);
627
628         /* If we're up and running, just kick the tasklet to process TX/RX */
629         if (card->atmdev[0])
630                 tasklet_schedule(&card->tlet);
631         else
632                 wake_up(&card->fw_wq);
633
634         return IRQ_RETVAL(handled);
635 }
636
637 void solos_bh(unsigned long card_arg)
638 {
639         struct solos_card *card = (void *)card_arg;
640         uint32_t card_flags;
641         uint32_t rx_done = 0;
642         int port;
643
644         /*
645          * Since fpga_tx() is going to need to read the flags under its lock,
646          * it can return them to us so that we don't have to hit PCI MMIO
647          * again for the same information
648          */
649         card_flags = fpga_tx(card);
650
651         for (port = 0; port < card->nr_ports; port++) {
652                 if (card_flags & (0x10 << port)) {
653                         struct pkt_hdr _hdr, *header;
654                         struct sk_buff *skb;
655                         struct atm_vcc *vcc;
656                         int size;
657
658                         if (card->using_dma) {
659                                 skb = card->rx_skb[port];
660                                 card->rx_skb[port] = NULL;
661
662                                 pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr,
663                                                  RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
664
665                                 header = (void *)skb->data;
666                                 size = le16_to_cpu(header->size);
667                                 skb_put(skb, size + sizeof(*header));
668                                 skb_pull(skb, sizeof(*header));
669                         } else {
670                                 header = &_hdr;
671
672                                 rx_done |= 0x10 << port;
673
674                                 memcpy_fromio(header, RX_BUF(card, port), sizeof(*header));
675
676                                 size = le16_to_cpu(header->size);
677                                 if (size > (card->buffer_size - sizeof(*header))){
678                                         dev_warn(&card->dev->dev, "Invalid buffer size\n");
679                                         continue;
680                                 }
681
682                                 skb = alloc_skb(size + 1, GFP_ATOMIC);
683                                 if (!skb) {
684                                         if (net_ratelimit())
685                                                 dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
686                                         continue;
687                                 }
688
689                                 memcpy_fromio(skb_put(skb, size),
690                                               RX_BUF(card, port) + sizeof(*header),
691                                               size);
692                         }
693                         if (atmdebug) {
694                                 dev_info(&card->dev->dev, "Received: device %d\n", port);
695                                 dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n",
696                                          size, le16_to_cpu(header->vpi),
697                                          le16_to_cpu(header->vci));
698                                 print_buffer(skb);
699                         }
700
701                         switch (le16_to_cpu(header->type)) {
702                         case PKT_DATA:
703                                 vcc = find_vcc(card->atmdev[port], le16_to_cpu(header->vpi),
704                                                le16_to_cpu(header->vci));
705                                 if (!vcc) {
706                                         if (net_ratelimit())
707                                                 dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
708                                                          le16_to_cpu(header->vci), le16_to_cpu(header->vpi),
709                                                          port);
710                                         continue;
711                                 }
712                                 atm_charge(vcc, skb->truesize);
713                                 vcc->push(vcc, skb);
714                                 atomic_inc(&vcc->stats->rx);
715                                 break;
716
717                         case PKT_STATUS:
718                                 if (process_status(card, port, skb) &&
719                                     net_ratelimit()) {
720                                         dev_warn(&card->dev->dev, "Bad status packet of %d bytes on port %d:\n", skb->len, port);
721                                         print_buffer(skb);
722                                 }
723                                 dev_kfree_skb_any(skb);
724                                 break;
725
726                         case PKT_COMMAND:
727                         default: /* FIXME: Not really, surely? */
728                                 if (process_command(card, port, skb))
729                                         break;
730                                 spin_lock(&card->cli_queue_lock);
731                                 if (skb_queue_len(&card->cli_queue[port]) > 10) {
732                                         if (net_ratelimit())
733                                                 dev_warn(&card->dev->dev, "Dropping console response on port %d\n",
734                                                          port);
735                                         dev_kfree_skb_any(skb);
736                                 } else
737                                         skb_queue_tail(&card->cli_queue[port], skb);
738                                 spin_unlock(&card->cli_queue_lock);
739                                 break;
740                         }
741                 }
742                 /* Allocate RX skbs for any ports which need them */
743                 if (card->using_dma && card->atmdev[port] &&
744                     !card->rx_skb[port]) {
745                         struct sk_buff *skb = alloc_skb(RX_DMA_SIZE, GFP_ATOMIC);
746                         if (skb) {
747                                 SKB_CB(skb)->dma_addr =
748                                         pci_map_single(card->dev, skb->data,
749                                                        RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
750                                 iowrite32(SKB_CB(skb)->dma_addr,
751                                           card->config_regs + RX_DMA_ADDR(port));
752                                 card->rx_skb[port] = skb;
753                         } else {
754                                 if (net_ratelimit())
755                                         dev_warn(&card->dev->dev, "Failed to allocate RX skb");
756
757                                 /* We'll have to try again later */
758                                 tasklet_schedule(&card->tlet);
759                         }
760                 }
761         }
762         if (rx_done)
763                 iowrite32(rx_done, card->config_regs + FLAGS_ADDR);
764
765         return;
766 }
767
768 static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
769 {
770         struct hlist_head *head;
771         struct atm_vcc *vcc = NULL;
772         struct hlist_node *node;
773         struct sock *s;
774
775         read_lock(&vcc_sklist_lock);
776         head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
777         sk_for_each(s, node, head) {
778                 vcc = atm_sk(s);
779                 if (vcc->dev == dev && vcc->vci == vci &&
780                     vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE)
781                         goto out;
782         }
783         vcc = NULL;
784  out:
785         read_unlock(&vcc_sklist_lock);
786         return vcc;
787 }
788
789 static int list_vccs(int vci)
790 {
791         struct hlist_head *head;
792         struct atm_vcc *vcc;
793         struct hlist_node *node;
794         struct sock *s;
795         int num_found = 0;
796         int i;
797
798         read_lock(&vcc_sklist_lock);
799         if (vci != 0){
800                 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
801                 sk_for_each(s, node, head) {
802                         num_found ++;
803                         vcc = atm_sk(s);
804                         printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
805                                vcc->dev->number,
806                                vcc->vpi,
807                                vcc->vci);
808                 }
809         } else {
810                 for(i = 0; i < VCC_HTABLE_SIZE; i++){
811                         head = &vcc_hash[i];
812                         sk_for_each(s, node, head) {
813                                 num_found ++;
814                                 vcc = atm_sk(s);
815                                 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
816                                        vcc->dev->number,
817                                        vcc->vpi,
818                                        vcc->vci);
819                         }
820                 }
821         }
822         read_unlock(&vcc_sklist_lock);
823         return num_found;
824 }
825
826 static void release_vccs(struct atm_dev *dev)
827 {
828         int i;
829
830         write_lock_irq(&vcc_sklist_lock);
831         for (i = 0; i < VCC_HTABLE_SIZE; i++) {
832                 struct hlist_head *head = &vcc_hash[i];
833                 struct hlist_node *node, *tmp;
834                 struct sock *s;
835                 struct atm_vcc *vcc;
836
837                 sk_for_each_safe(s, node, tmp, head) {
838                         vcc = atm_sk(s);
839                         if (vcc->dev == dev) {
840                                 vcc_release_async(vcc, -EPIPE);
841                                 sk_del_node_init(s);
842                         }
843                 }
844         }
845         write_unlock_irq(&vcc_sklist_lock);
846 }
847
848
849 static int popen(struct atm_vcc *vcc)
850 {
851         struct solos_card *card = vcc->dev->dev_data;
852         struct sk_buff *skb;
853         struct pkt_hdr *header;
854
855         if (vcc->qos.aal != ATM_AAL5) {
856                 dev_warn(&card->dev->dev, "Unsupported ATM type %d\n",
857                          vcc->qos.aal);
858                 return -EINVAL;
859         }
860
861         skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
862         if (!skb && net_ratelimit()) {
863                 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
864                 return -ENOMEM;
865         }
866         header = (void *)skb_put(skb, sizeof(*header));
867
868         header->size = cpu_to_le16(0);
869         header->vpi = cpu_to_le16(vcc->vpi);
870         header->vci = cpu_to_le16(vcc->vci);
871         header->type = cpu_to_le16(PKT_POPEN);
872
873         fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
874
875         set_bit(ATM_VF_ADDR, &vcc->flags);
876         set_bit(ATM_VF_READY, &vcc->flags);
877         list_vccs(0);
878
879
880         return 0;
881 }
882
883 static void pclose(struct atm_vcc *vcc)
884 {
885         struct solos_card *card = vcc->dev->dev_data;
886         struct sk_buff *skb;
887         struct pkt_hdr *header;
888
889         skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
890         if (!skb) {
891                 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
892                 return;
893         }
894         header = (void *)skb_put(skb, sizeof(*header));
895
896         header->size = cpu_to_le16(0);
897         header->vpi = cpu_to_le16(vcc->vpi);
898         header->vci = cpu_to_le16(vcc->vci);
899         header->type = cpu_to_le16(PKT_PCLOSE);
900
901         fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
902
903         clear_bit(ATM_VF_ADDR, &vcc->flags);
904         clear_bit(ATM_VF_READY, &vcc->flags);
905
906         return;
907 }
908
909 static int print_buffer(struct sk_buff *buf)
910 {
911         int len,i;
912         char msg[500];
913         char item[10];
914
915         len = buf->len;
916         for (i = 0; i < len; i++){
917                 if(i % 8 == 0)
918                         sprintf(msg, "%02X: ", i);
919
920                 sprintf(item,"%02X ",*(buf->data + i));
921                 strcat(msg, item);
922                 if(i % 8 == 7) {
923                         sprintf(item, "\n");
924                         strcat(msg, item);
925                         printk(KERN_DEBUG "%s", msg);
926                 }
927         }
928         if (i % 8 != 0) {
929                 sprintf(item, "\n");
930                 strcat(msg, item);
931                 printk(KERN_DEBUG "%s", msg);
932         }
933         printk(KERN_DEBUG "\n");
934
935         return 0;
936 }
937
938 static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
939                        struct atm_vcc *vcc)
940 {
941         int old_len;
942         unsigned long flags;
943
944         SKB_CB(skb)->vcc = vcc;
945
946         spin_lock_irqsave(&card->tx_queue_lock, flags);
947         old_len = skb_queue_len(&card->tx_queue[port]);
948         skb_queue_tail(&card->tx_queue[port], skb);
949         if (!old_len)
950                 card->tx_mask |= (1 << port);
951         spin_unlock_irqrestore(&card->tx_queue_lock, flags);
952
953         /* Theoretically we could just schedule the tasklet here, but
954            that introduces latency we don't want -- it's noticeable */
955         if (!old_len)
956                 fpga_tx(card);
957 }
958
959 static uint32_t fpga_tx(struct solos_card *card)
960 {
961         uint32_t tx_pending, card_flags;
962         uint32_t tx_started = 0;
963         struct sk_buff *skb;
964         struct atm_vcc *vcc;
965         unsigned char port;
966         unsigned long flags;
967
968         spin_lock_irqsave(&card->tx_lock, flags);
969         
970         card_flags = ioread32(card->config_regs + FLAGS_ADDR);
971         /*
972          * The queue lock is required for _writing_ to tx_mask, but we're
973          * OK to read it here without locking. The only potential update
974          * that we could race with is in fpga_queue() where it sets a bit
975          * for a new port... but it's going to call this function again if
976          * it's doing that, anyway.
977          */
978         tx_pending = card->tx_mask & ~card_flags;
979
980         for (port = 0; tx_pending; tx_pending >>= 1, port++) {
981                 if (tx_pending & 1) {
982                         struct sk_buff *oldskb = card->tx_skb[port];
983                         if (oldskb)
984                                 pci_unmap_single(card->dev, SKB_CB(oldskb)->dma_addr,
985                                                  oldskb->len, PCI_DMA_TODEVICE);
986
987                         spin_lock(&card->tx_queue_lock);
988                         skb = skb_dequeue(&card->tx_queue[port]);
989                         if (!skb)
990                                 card->tx_mask &= ~(1 << port);
991                         spin_unlock(&card->tx_queue_lock);
992
993                         if (skb && !card->using_dma) {
994                                 memcpy_toio(TX_BUF(card, port), skb->data, skb->len);
995                                 tx_started |= 1 << port;
996                                 oldskb = skb; /* We're done with this skb already */
997                         } else if (skb && card->using_dma) {
998                                 SKB_CB(skb)->dma_addr = pci_map_single(card->dev, skb->data,
999                                                                        skb->len, PCI_DMA_TODEVICE);
1000                                 iowrite32(SKB_CB(skb)->dma_addr,
1001                                           card->config_regs + TX_DMA_ADDR(port));
1002                         }
1003
1004                         if (!oldskb)
1005                                 continue;
1006
1007                         /* Clean up and free oldskb now it's gone */
1008                         if (atmdebug) {
1009                                 dev_info(&card->dev->dev, "Transmitted: port %d\n",
1010                                          port);
1011                                 print_buffer(oldskb);
1012                         }
1013
1014                         vcc = SKB_CB(oldskb)->vcc;
1015
1016                         if (vcc) {
1017                                 atomic_inc(&vcc->stats->tx);
1018                                 solos_pop(vcc, oldskb);
1019                         } else
1020                                 dev_kfree_skb_irq(oldskb);
1021
1022                 }
1023         }
1024         /* For non-DMA TX, write the 'TX start' bit for all four ports simultaneously */
1025         if (tx_started)
1026                 iowrite32(tx_started, card->config_regs + FLAGS_ADDR);
1027
1028         spin_unlock_irqrestore(&card->tx_lock, flags);
1029         return card_flags;
1030 }
1031
1032 static int psend(struct atm_vcc *vcc, struct sk_buff *skb)
1033 {
1034         struct solos_card *card = vcc->dev->dev_data;
1035         struct pkt_hdr *header;
1036         int pktlen;
1037
1038         pktlen = skb->len;
1039         if (pktlen > (BUF_SIZE - sizeof(*header))) {
1040                 dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
1041                 solos_pop(vcc, skb);
1042                 return 0;
1043         }
1044
1045         if (!skb_clone_writable(skb, sizeof(*header))) {
1046                 int expand_by = 0;
1047                 int ret;
1048
1049                 if (skb_headroom(skb) < sizeof(*header))
1050                         expand_by = sizeof(*header) - skb_headroom(skb);
1051
1052                 ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
1053                 if (ret) {
1054                         dev_warn(&card->dev->dev, "pskb_expand_head failed.\n");
1055                         solos_pop(vcc, skb);
1056                         return ret;
1057                 }
1058         }
1059
1060         header = (void *)skb_push(skb, sizeof(*header));
1061
1062         /* This does _not_ include the size of the header */
1063         header->size = cpu_to_le16(pktlen);
1064         header->vpi = cpu_to_le16(vcc->vpi);
1065         header->vci = cpu_to_le16(vcc->vci);
1066         header->type = cpu_to_le16(PKT_DATA);
1067
1068         fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
1069
1070         return 0;
1071 }
1072
1073 static struct atmdev_ops fpga_ops = {
1074         .open =         popen,
1075         .close =        pclose,
1076         .ioctl =        NULL,
1077         .getsockopt =   NULL,
1078         .setsockopt =   NULL,
1079         .send =         psend,
1080         .send_oam =     NULL,
1081         .phy_put =      NULL,
1082         .phy_get =      NULL,
1083         .change_qos =   NULL,
1084         .proc_read =    NULL,
1085         .owner =        THIS_MODULE
1086 };
1087
1088 static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1089 {
1090         int err;
1091         uint16_t fpga_ver;
1092         uint8_t major_ver, minor_ver;
1093         uint32_t data32;
1094         struct solos_card *card;
1095
1096         card = kzalloc(sizeof(*card), GFP_KERNEL);
1097         if (!card)
1098                 return -ENOMEM;
1099
1100         card->dev = dev;
1101         init_waitqueue_head(&card->fw_wq);
1102         init_waitqueue_head(&card->param_wq);
1103
1104         err = pci_enable_device(dev);
1105         if (err) {
1106                 dev_warn(&dev->dev,  "Failed to enable PCI device\n");
1107                 goto out;
1108         }
1109
1110         err = pci_set_dma_mask(dev, DMA_BIT_MASK(32));
1111         if (err) {
1112                 dev_warn(&dev->dev, "Failed to set 32-bit DMA mask\n");
1113                 goto out;
1114         }
1115
1116         err = pci_request_regions(dev, "solos");
1117         if (err) {
1118                 dev_warn(&dev->dev, "Failed to request regions\n");
1119                 goto out;
1120         }
1121
1122         card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
1123         if (!card->config_regs) {
1124                 dev_warn(&dev->dev, "Failed to ioremap config registers\n");
1125                 goto out_release_regions;
1126         }
1127         card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
1128         if (!card->buffers) {
1129                 dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
1130                 goto out_unmap_config;
1131         }
1132
1133         if (reset) {
1134                 iowrite32(1, card->config_regs + FPGA_MODE);
1135                 data32 = ioread32(card->config_regs + FPGA_MODE); 
1136
1137                 iowrite32(0, card->config_regs + FPGA_MODE);
1138                 data32 = ioread32(card->config_regs + FPGA_MODE); 
1139         }
1140
1141         data32 = ioread32(card->config_regs + FPGA_VER);
1142         fpga_ver = (data32 & 0x0000FFFF);
1143         major_ver = ((data32 & 0xFF000000) >> 24);
1144         minor_ver = ((data32 & 0x00FF0000) >> 16);
1145         card->fpga_version = FPGA_VERSION(major_ver,minor_ver);
1146         if (card->fpga_version > LEGACY_BUFFERS)
1147                 card->buffer_size = BUF_SIZE;
1148         else
1149                 card->buffer_size = OLD_BUF_SIZE;
1150         dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
1151                  major_ver, minor_ver, fpga_ver);
1152
1153         if (card->fpga_version >= DMA_SUPPORTED){
1154                 card->using_dma = 1;
1155         } else {
1156                 card->using_dma = 0;
1157                 /* Set RX empty flag for all ports */
1158                 iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
1159         }
1160
1161         data32 = ioread32(card->config_regs + PORTS);
1162         card->nr_ports = (data32 & 0x000000FF);
1163
1164         pci_set_drvdata(dev, card);
1165
1166         tasklet_init(&card->tlet, solos_bh, (unsigned long)card);
1167         spin_lock_init(&card->tx_lock);
1168         spin_lock_init(&card->tx_queue_lock);
1169         spin_lock_init(&card->cli_queue_lock);
1170         spin_lock_init(&card->param_queue_lock);
1171         INIT_LIST_HEAD(&card->param_queue);
1172
1173         err = request_irq(dev->irq, solos_irq, IRQF_SHARED,
1174                           "solos-pci", card);
1175         if (err) {
1176                 dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
1177                 goto out_unmap_both;
1178         }
1179
1180         iowrite32(1, card->config_regs + IRQ_EN_ADDR);
1181
1182         if (fpga_upgrade)
1183                 flash_upgrade(card, 0);
1184
1185         if (firmware_upgrade)
1186                 flash_upgrade(card, 1);
1187
1188         if (db_fpga_upgrade)
1189                 flash_upgrade(card, 2);
1190
1191         if (db_firmware_upgrade)
1192                 flash_upgrade(card, 3);
1193
1194         err = atm_init(card);
1195         if (err)
1196                 goto out_free_irq;
1197
1198         return 0;
1199
1200  out_free_irq:
1201         iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1202         free_irq(dev->irq, card);
1203         tasklet_kill(&card->tlet);
1204         
1205  out_unmap_both:
1206         pci_set_drvdata(dev, NULL);
1207         pci_iounmap(dev, card->config_regs);
1208  out_unmap_config:
1209         pci_iounmap(dev, card->buffers);
1210  out_release_regions:
1211         pci_release_regions(dev);
1212  out:
1213         kfree(card);
1214         return err;
1215 }
1216
1217 static int atm_init(struct solos_card *card)
1218 {
1219         int i;
1220
1221         for (i = 0; i < card->nr_ports; i++) {
1222                 struct sk_buff *skb;
1223                 struct pkt_hdr *header;
1224
1225                 skb_queue_head_init(&card->tx_queue[i]);
1226                 skb_queue_head_init(&card->cli_queue[i]);
1227
1228                 card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
1229                 if (!card->atmdev[i]) {
1230                         dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
1231                         atm_remove(card);
1232                         return -ENODEV;
1233                 }
1234                 if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
1235                         dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
1236                 if (sysfs_create_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group))
1237                         dev_err(&card->dev->dev, "Could not register parameter group for ATM device %d\n", i);
1238
1239                 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
1240
1241                 card->atmdev[i]->ci_range.vpi_bits = 8;
1242                 card->atmdev[i]->ci_range.vci_bits = 16;
1243                 card->atmdev[i]->dev_data = card;
1244                 card->atmdev[i]->phy_data = (void *)(unsigned long)i;
1245                 card->atmdev[i]->signal = ATM_PHY_SIG_UNKNOWN;
1246
1247                 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
1248                 if (!skb) {
1249                         dev_warn(&card->dev->dev, "Failed to allocate sk_buff in atm_init()\n");
1250                         continue;
1251                 }
1252
1253                 header = (void *)skb_put(skb, sizeof(*header));
1254
1255                 header->size = cpu_to_le16(0);
1256                 header->vpi = cpu_to_le16(0);
1257                 header->vci = cpu_to_le16(0);
1258                 header->type = cpu_to_le16(PKT_STATUS);
1259
1260                 fpga_queue(card, i, skb, NULL);
1261         }
1262         return 0;
1263 }
1264
1265 static void atm_remove(struct solos_card *card)
1266 {
1267         int i;
1268
1269         for (i = 0; i < card->nr_ports; i++) {
1270                 if (card->atmdev[i]) {
1271                         struct sk_buff *skb;
1272
1273                         dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
1274
1275                         sysfs_remove_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group);
1276                         atm_dev_deregister(card->atmdev[i]);
1277
1278                         skb = card->rx_skb[i];
1279                         if (skb) {
1280                                 pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr,
1281                                                  RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
1282                                 dev_kfree_skb(skb);
1283                         }
1284                         skb = card->tx_skb[i];
1285                         if (skb) {
1286                                 pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr,
1287                                                  skb->len, PCI_DMA_TODEVICE);
1288                                 dev_kfree_skb(skb);
1289                         }
1290                         while ((skb = skb_dequeue(&card->tx_queue[i])))
1291                                 dev_kfree_skb(skb);
1292  
1293                 }
1294         }
1295 }
1296
1297 static void fpga_remove(struct pci_dev *dev)
1298 {
1299         struct solos_card *card = pci_get_drvdata(dev);
1300         
1301         /* Disable IRQs */
1302         iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1303
1304         /* Reset FPGA */
1305         iowrite32(1, card->config_regs + FPGA_MODE);
1306         (void)ioread32(card->config_regs + FPGA_MODE); 
1307
1308         atm_remove(card);
1309
1310         free_irq(dev->irq, card);
1311         tasklet_kill(&card->tlet);
1312
1313         /* Release device from reset */
1314         iowrite32(0, card->config_regs + FPGA_MODE);
1315         (void)ioread32(card->config_regs + FPGA_MODE); 
1316
1317         pci_iounmap(dev, card->buffers);
1318         pci_iounmap(dev, card->config_regs);
1319
1320         pci_release_regions(dev);
1321         pci_disable_device(dev);
1322
1323         pci_set_drvdata(dev, NULL);
1324         kfree(card);
1325 }
1326
1327 static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
1328         { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1329         { 0, }
1330 };
1331
1332 MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
1333
1334 static struct pci_driver fpga_driver = {
1335         .name =         "solos",
1336         .id_table =     fpga_pci_tbl,
1337         .probe =        fpga_probe,
1338         .remove =       fpga_remove,
1339 };
1340
1341
1342 static int __init solos_pci_init(void)
1343 {
1344         printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
1345         return pci_register_driver(&fpga_driver);
1346 }
1347
1348 static void __exit solos_pci_exit(void)
1349 {
1350         pci_unregister_driver(&fpga_driver);
1351         printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
1352 }
1353
1354 module_init(solos_pci_init);
1355 module_exit(solos_pci_exit);