blob: c5f5186d62a3160404a50b5819c440239b311870 [file] [log] [blame]
David Woodhouse9c540042008-12-23 04:09:02 +00001/*
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>
Simon Farnsworth7c4015b2009-01-21 20:45:49 +000012 * Treker Chen <treker@xrio.com>
David Woodhouse9c540042008-12-23 04:09:02 +000013 *
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>
Simon Farnsworth7c4015b2009-01-21 20:45:49 +000040#include <linux/firmware.h>
David Woodhouse01e2ffa2009-01-27 16:20:04 +110041#include <linux/ctype.h>
42#include <linux/swab.h>
David Woodhouse9c540042008-12-23 04:09:02 +000043
Simon Farnsworth7c4015b2009-01-21 20:45:49 +000044#define VERSION "0.07"
David Woodhouse9c540042008-12-23 04:09:02 +000045#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
Simon Farnsworth7c4015b2009-01-21 20:45:49 +000052#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
David Woodhouse90937232009-01-28 16:46:56 +110058#define TX_DMA_ADDR(port) (0x40 + (4 * (port)))
59#define RX_DMA_ADDR(port) (0x30 + (4 * (port)))
David Woodhouse9c540042008-12-23 04:09:02 +000060
61#define DATA_RAM_SIZE 32768
Nathan Williams4dbedf42009-03-25 20:27:37 +110062#define BUF_SIZE 2048
63#define OLD_BUF_SIZE 4096 /* For FPGA versions <= 2*/
Simon Farnsworth7c4015b2009-01-21 20:45:49 +000064#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*/
David Woodhouse9c540042008-12-23 04:09:02 +000068
Nathan Williams4dbedf42009-03-25 20:27:37 +110069#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)
David Woodhouse9c540042008-12-23 04:09:02 +000072
David Woodhouseeaf83e32009-01-29 10:51:11 +110073#define RX_DMA_SIZE 2048
74
Nathan Williams4dbedf42009-03-25 20:27:37 +110075#define FPGA_VERSION(a,b) (((a) << 8) + (b))
76#define LEGACY_BUFFERS 2
77#define DMA_SUPPORTED 4
78
David Woodhousecc3657e2009-01-30 14:23:22 +110079static int reset = 0;
David Woodhouse9c540042008-12-23 04:09:02 +000080static int atmdebug = 0;
Simon Farnsworth7c4015b2009-01-21 20:45:49 +000081static int firmware_upgrade = 0;
82static int fpga_upgrade = 0;
Nathan Williams4dbedf42009-03-25 20:27:37 +110083static int db_firmware_upgrade = 0;
84static int db_fpga_upgrade = 0;
David Woodhouse9c540042008-12-23 04:09:02 +000085
86struct pkt_hdr {
87 __le16 size;
88 __le16 vpi;
89 __le16 vci;
90 __le16 type;
91};
92
David Woodhouse90937232009-01-28 16:46:56 +110093struct 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
David Woodhouse9c540042008-12-23 04:09:02 +0000101#define PKT_DATA 0
102#define PKT_COMMAND 1
103#define PKT_POPEN 3
104#define PKT_PCLOSE 4
David Woodhouse87ebb182009-01-27 20:02:30 +1100105#define PKT_STATUS 5
David Woodhouse9c540042008-12-23 04:09:02 +0000106
107struct solos_card {
108 void __iomem *config_regs;
109 void __iomem *buffers;
110 int nr_ports;
David Woodhousef69e4172009-01-29 11:10:58 +1100111 int tx_mask;
David Woodhouse9c540042008-12-23 04:09:02 +0000112 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;
David Woodhouse01e2ffa2009-01-27 16:20:04 +1100118 spinlock_t param_queue_lock;
119 struct list_head param_queue;
David Woodhouse9c540042008-12-23 04:09:02 +0000120 struct sk_buff_head tx_queue[4];
121 struct sk_buff_head cli_queue[4];
David Woodhouse90937232009-01-28 16:46:56 +1100122 struct sk_buff *tx_skb[4];
123 struct sk_buff *rx_skb[4];
David Woodhouse01e2ffa2009-01-27 16:20:04 +1100124 wait_queue_head_t param_wq;
David Woodhousefa755b92009-01-27 14:16:12 +1100125 wait_queue_head_t fw_wq;
David Woodhouse90937232009-01-28 16:46:56 +1100126 int using_dma;
Nathan Williams4dbedf42009-03-25 20:27:37 +1100127 int fpga_version;
128 int buffer_size;
David Woodhouse9c540042008-12-23 04:09:02 +0000129};
130
David Woodhouse01e2ffa2009-01-27 16:20:04 +1100131
132struct solos_param {
133 struct list_head list;
134 pid_t pid;
135 int port;
136 struct sk_buff *response;
David Woodhouse9c540042008-12-23 04:09:02 +0000137};
138
139#define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
140
141MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
142MODULE_DESCRIPTION("Solos PCI driver");
143MODULE_VERSION(VERSION);
144MODULE_LICENSE("GPL");
David Woodhousecc3657e2009-01-30 14:23:22 +1100145MODULE_PARM_DESC(reset, "Reset Solos chips on startup");
David Woodhouse9c540042008-12-23 04:09:02 +0000146MODULE_PARM_DESC(atmdebug, "Print ATM data");
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000147MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade");
148MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade");
Nathan Williams4dbedf42009-03-25 20:27:37 +1100149MODULE_PARM_DESC(db_firmware_upgrade, "Initiate daughter board Solos firmware upgrade");
150MODULE_PARM_DESC(db_fpga_upgrade, "Initiate daughter board FPGA upgrade");
David Woodhousecc3657e2009-01-30 14:23:22 +1100151module_param(reset, int, 0444);
Simon Farnsworth4306cad2009-01-19 21:19:29 +0000152module_param(atmdebug, int, 0644);
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000153module_param(firmware_upgrade, int, 0444);
154module_param(fpga_upgrade, int, 0444);
Nathan Williams4dbedf42009-03-25 20:27:37 +1100155module_param(db_firmware_upgrade, int, 0444);
156module_param(db_fpga_upgrade, int, 0444);
David Woodhouse9c540042008-12-23 04:09:02 +0000157
158static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
159 struct atm_vcc *vcc);
David Woodhouse35c22212009-01-29 14:08:27 +1100160static uint32_t fpga_tx(struct solos_card *);
David Woodhouse9c540042008-12-23 04:09:02 +0000161static irqreturn_t solos_irq(int irq, void *dev_id);
162static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
163static int list_vccs(int vci);
David Woodhouse1e615df2009-01-27 21:47:47 +1100164static void release_vccs(struct atm_dev *dev);
David Woodhouse9c540042008-12-23 04:09:02 +0000165static int atm_init(struct solos_card *);
166static void atm_remove(struct solos_card *);
167static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
168static void solos_bh(unsigned long);
169static int print_buffer(struct sk_buff *buf);
170
171static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb)
172{
173 if (vcc->pop)
174 vcc->pop(vcc, skb);
175 else
176 dev_kfree_skb_any(skb);
177}
178
David Woodhouse01e2ffa2009-01-27 16:20:04 +1100179static ssize_t solos_param_show(struct device *dev, struct device_attribute *attr,
180 char *buf)
181{
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;
185 struct sk_buff *skb;
186 struct pkt_hdr *header;
187 int buflen;
188
189 buflen = strlen(attr->attr.name) + 10;
190
David Woodhouse3456b222009-01-28 10:39:23 +1100191 skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL);
David Woodhouse01e2ffa2009-01-27 16:20:04 +1100192 if (!skb) {
193 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_show()\n");
194 return -ENOMEM;
195 }
196
197 header = (void *)skb_put(skb, sizeof(*header));
198
199 buflen = snprintf((void *)&header[1], buflen - 1,
200 "L%05d\n%s\n", current->pid, attr->attr.name);
201 skb_put(skb, buflen);
202
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);
207
208 prm.pid = current->pid;
209 prm.response = NULL;
210 prm.port = SOLOS_CHAN(atmdev);
211
212 spin_lock_irq(&card->param_queue_lock);
213 list_add(&prm.list, &card->param_queue);
214 spin_unlock_irq(&card->param_queue_lock);
215
216 fpga_queue(card, prm.port, skb, NULL);
217
218 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
219
220 spin_lock_irq(&card->param_queue_lock);
221 list_del(&prm.list);
222 spin_unlock_irq(&card->param_queue_lock);
223
224 if (!prm.response)
225 return -EIO;
226
227 buflen = prm.response->len;
228 memcpy(buf, prm.response->data, buflen);
229 kfree_skb(prm.response);
230
231 return buflen;
232}
233
234static ssize_t solos_param_store(struct device *dev, struct device_attribute *attr,
235 const char *buf, size_t count)
236{
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;
240 struct sk_buff *skb;
241 struct pkt_hdr *header;
242 int buflen;
243 ssize_t ret;
244
245 buflen = strlen(attr->attr.name) + 11 + count;
246
David Woodhouse3456b222009-01-28 10:39:23 +1100247 skb = alloc_skb(sizeof(*header) + buflen, GFP_KERNEL);
David Woodhouse01e2ffa2009-01-27 16:20:04 +1100248 if (!skb) {
249 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in solos_param_store()\n");
250 return -ENOMEM;
251 }
252
253 header = (void *)skb_put(skb, sizeof(*header));
254
255 buflen = snprintf((void *)&header[1], buflen - 1,
256 "L%05d\n%s\n%s\n", current->pid, attr->attr.name, buf);
257
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);
263
264 prm.pid = current->pid;
265 prm.response = NULL;
266 prm.port = SOLOS_CHAN(atmdev);
267
268 spin_lock_irq(&card->param_queue_lock);
269 list_add(&prm.list, &card->param_queue);
270 spin_unlock_irq(&card->param_queue_lock);
271
272 fpga_queue(card, prm.port, skb, NULL);
273
274 wait_event_timeout(card->param_wq, prm.response, 5 * HZ);
275
276 spin_lock_irq(&card->param_queue_lock);
277 list_del(&prm.list);
278 spin_unlock_irq(&card->param_queue_lock);
279
280 skb = prm.response;
281
282 if (!skb)
283 return -EIO;
284
285 buflen = skb->len;
286
287 /* Sometimes it has a newline, sometimes it doesn't. */
288 if (skb->data[buflen - 1] == '\n')
289 buflen--;
290
291 if (buflen == 2 && !strncmp(skb->data, "OK", 2))
292 ret = count;
293 else if (buflen == 5 && !strncmp(skb->data, "ERROR", 5))
294 ret = -EIO;
295 else {
296 /* We know we have enough space allocated for this; we allocated
297 it ourselves */
298 skb->data[buflen] = 0;
299
300 dev_warn(&card->dev->dev, "Unexpected parameter response: '%s'\n",
301 skb->data);
302 ret = -EIO;
303 }
304 kfree_skb(skb);
305
306 return ret;
307}
308
David Woodhouse87ebb182009-01-27 20:02:30 +1100309static char *next_string(struct sk_buff *skb)
310{
311 int i = 0;
312 char *this = skb->data;
David Woodhousec6428e52009-01-29 12:17:09 +1100313
314 for (i = 0; i < skb->len; i++) {
David Woodhouse87ebb182009-01-27 20:02:30 +1100315 if (this[i] == '\n') {
316 this[i] = 0;
David Woodhousec6428e52009-01-29 12:17:09 +1100317 skb_pull(skb, i + 1);
David Woodhouse87ebb182009-01-27 20:02:30 +1100318 return this;
319 }
David Woodhousec6428e52009-01-29 12:17:09 +1100320 if (!isprint(this[i]))
321 return NULL;
David Woodhouse87ebb182009-01-27 20:02:30 +1100322 }
323 return NULL;
324}
325
326/*
327 * Status packet has fields separated by \n, starting with a version number
328 * for the information therein. Fields are....
329 *
330 * packet version
David Woodhouse87ebb182009-01-27 20:02:30 +1100331 * RxBitRate (version >= 1)
David Woodhousef87b2ed2009-01-30 14:31:36 +1100332 * TxBitRate (version >= 1)
David Woodhouse87ebb182009-01-27 20:02:30 +1100333 * State (version >= 1)
David Woodhousef87b2ed2009-01-30 14:31:36 +1100334 * LocalSNRMargin (version >= 1)
335 * LocalLineAttn (version >= 1)
David Woodhouse87ebb182009-01-27 20:02:30 +1100336 */
337static int process_status(struct solos_card *card, int port, struct sk_buff *skb)
338{
David Woodhousef87b2ed2009-01-30 14:31:36 +1100339 char *str, *end, *state_str, *snr, *attn;
340 int ver, rate_up, rate_down;
David Woodhouse87ebb182009-01-27 20:02:30 +1100341
342 if (!card->atmdev[port])
343 return -ENODEV;
344
345 str = next_string(skb);
346 if (!str)
347 return -EIO;
348
349 ver = simple_strtol(str, NULL, 10);
350 if (ver < 1) {
351 dev_warn(&card->dev->dev, "Unexpected status interrupt version %d\n",
352 ver);
353 return -EIO;
354 }
355
356 str = next_string(skb);
David Woodhousec6428e52009-01-29 12:17:09 +1100357 if (!str)
358 return -EIO;
David Woodhouse95852f42009-01-30 14:23:52 +1100359 if (!strcmp(str, "ERROR")) {
360 dev_dbg(&card->dev->dev, "Status packet indicated Solos error on port %d (starting up?)\n",
361 port);
362 return 0;
363 }
364
David Woodhousef87b2ed2009-01-30 14:31:36 +1100365 rate_down = simple_strtol(str, &end, 10);
David Woodhouse87ebb182009-01-27 20:02:30 +1100366 if (*end)
367 return -EIO;
368
369 str = next_string(skb);
David Woodhousec6428e52009-01-29 12:17:09 +1100370 if (!str)
371 return -EIO;
David Woodhousef87b2ed2009-01-30 14:31:36 +1100372 rate_up = simple_strtol(str, &end, 10);
David Woodhouse87ebb182009-01-27 20:02:30 +1100373 if (*end)
374 return -EIO;
375
David Woodhouseaf780652009-01-28 10:22:57 +1100376 state_str = next_string(skb);
David Woodhousec6428e52009-01-29 12:17:09 +1100377 if (!state_str)
378 return -EIO;
David Woodhousef87b2ed2009-01-30 14:31:36 +1100379
380 /* Anything but 'Showtime' is down */
381 if (strcmp(state_str, "Showtime")) {
382 card->atmdev[port]->signal = ATM_PHY_SIG_LOST;
David Woodhouse1e615df2009-01-27 21:47:47 +1100383 release_vccs(card->atmdev[port]);
David Woodhousef87b2ed2009-01-30 14:31:36 +1100384 dev_info(&card->dev->dev, "Port %d: %s\n", port, state_str);
385 return 0;
David Woodhouse1e615df2009-01-27 21:47:47 +1100386 }
David Woodhouse87ebb182009-01-27 20:02:30 +1100387
David Woodhousef87b2ed2009-01-30 14:31:36 +1100388 snr = next_string(skb);
Julia Lawall6cf57672009-07-27 11:38:52 -0700389 if (!snr)
David Woodhousef87b2ed2009-01-30 14:31:36 +1100390 return -EIO;
391 attn = next_string(skb);
392 if (!attn)
393 return -EIO;
David Woodhouseaf780652009-01-28 10:22:57 +1100394
David Woodhousef87b2ed2009-01-30 14:31:36 +1100395 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);
398
David Woodhousec6428e52009-01-29 12:17:09 +1100399 card->atmdev[port]->link_rate = rate_down / 424;
David Woodhousef87b2ed2009-01-30 14:31:36 +1100400 card->atmdev[port]->signal = ATM_PHY_SIG_FOUND;
David Woodhouse87ebb182009-01-27 20:02:30 +1100401
David Woodhouse87ebb182009-01-27 20:02:30 +1100402 return 0;
403}
404
David Woodhouse01e2ffa2009-01-27 16:20:04 +1100405static int process_command(struct solos_card *card, int port, struct sk_buff *skb)
406{
407 struct solos_param *prm;
408 unsigned long flags;
409 int cmdpid;
410 int found = 0;
411
412 if (skb->len < 7)
413 return 0;
414
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')
419 return 0;
420
421 cmdpid = simple_strtol(&skb->data[1], NULL, 10);
422
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) {
426 prm->response = skb;
427 skb_pull(skb, 7);
428 wake_up(&card->param_wq);
429 found = 1;
430 break;
431 }
432 }
433 spin_unlock_irqrestore(&card->param_queue_lock, flags);
434 return found;
435}
436
David Woodhouse9c540042008-12-23 04:09:02 +0000437static ssize_t console_show(struct device *dev, struct device_attribute *attr,
438 char *buf)
439{
440 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
441 struct solos_card *card = atmdev->dev_data;
442 struct sk_buff *skb;
443
444 spin_lock(&card->cli_queue_lock);
445 skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
446 spin_unlock(&card->cli_queue_lock);
447 if(skb == NULL)
448 return sprintf(buf, "No data.\n");
449
450 memcpy(buf, skb->data, skb->len);
451 dev_dbg(&card->dev->dev, "len: %d\n", skb->len);
452
453 kfree_skb(skb);
454 return skb->len;
455}
456
457static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
458{
459 struct sk_buff *skb;
460 struct pkt_hdr *header;
461
David Woodhouse9c540042008-12-23 04:09:02 +0000462 if (size > (BUF_SIZE - sizeof(*header))) {
463 dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n");
464 return 0;
465 }
466 skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC);
467 if (!skb) {
468 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n");
469 return 0;
470 }
471
472 header = (void *)skb_put(skb, sizeof(*header));
473
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);
478
479 memcpy(skb_put(skb, size), buf, size);
480
481 fpga_queue(card, dev, skb, NULL);
482
483 return 0;
484}
485
486static ssize_t console_store(struct device *dev, struct device_attribute *attr,
487 const char *buf, size_t count)
488{
489 struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
490 struct solos_card *card = atmdev->dev_data;
491 int err;
492
493 err = send_command(card, SOLOS_CHAN(atmdev), buf, count);
494
495 return err?:count;
496}
497
498static DEVICE_ATTR(console, 0644, console_show, console_store);
499
David Woodhoused057f0a2009-01-27 16:52:07 +1100500
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);
503
504#include "solos-attrlist.c"
505
506#undef SOLOS_ATTR_RO
507#undef SOLOS_ATTR_RW
508
509#define SOLOS_ATTR_RO(x) &dev_attr_##x.attr,
510#define SOLOS_ATTR_RW(x) &dev_attr_##x.attr,
511
512static struct attribute *solos_attrs[] = {
513#include "solos-attrlist.c"
514 NULL
515};
516
517static struct attribute_group solos_attr_group = {
518 .attrs = solos_attrs,
519 .name = "parameters",
520};
David Woodhouse9c540042008-12-23 04:09:02 +0000521
David Woodhousefa755b92009-01-27 14:16:12 +1100522static int flash_upgrade(struct solos_card *card, int chip)
523{
524 const struct firmware *fw;
525 const char *fw_name;
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000526 uint32_t data32 = 0;
527 int blocksize = 0;
528 int numblocks = 0;
David Woodhousefa755b92009-01-27 14:16:12 +1100529 int offset;
530
531 if (chip == 0) {
532 fw_name = "solos-FPGA.bin";
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000533 blocksize = FPGA_BLOCK;
Nathan Williams4dbedf42009-03-25 20:27:37 +1100534 }
535
536 if (chip == 1) {
David Woodhousefa755b92009-01-27 14:16:12 +1100537 fw_name = "solos-Firmware.bin";
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000538 blocksize = SOLOS_BLOCK;
539 }
Nathan Williams4dbedf42009-03-25 20:27:37 +1100540
541 if (chip == 2){
542 if (card->fpga_version > LEGACY_BUFFERS){
543 fw_name = "solos-db-FPGA.bin";
544 blocksize = FPGA_BLOCK;
545 } else {
546 dev_info(&card->dev->dev, "FPGA version doesn't support daughter board upgrades\n");
547 return -EPERM;
548 }
549 }
550
551 if (chip == 3){
552 if (card->fpga_version > LEGACY_BUFFERS){
553 fw_name = "solos-Firmware.bin";
554 blocksize = SOLOS_BLOCK;
555 } else {
556 dev_info(&card->dev->dev, "FPGA version doesn't support daughter board upgrades\n");
557 return -EPERM;
558 }
559 }
David Woodhousefa755b92009-01-27 14:16:12 +1100560
561 if (request_firmware(&fw, fw_name, &card->dev->dev))
562 return -ENOENT;
563
564 dev_info(&card->dev->dev, "Flash upgrade starting\n");
565
566 numblocks = fw->size / blocksize;
567 dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size);
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000568 dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks);
569
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000570 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);
David Woodhousefa755b92009-01-27 14:16:12 +1100573
574 /* Set mode to Chip Erase */
Nathan Williams4dbedf42009-03-25 20:27:37 +1100575 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");
David Woodhousefa755b92009-01-27 14:16:12 +1100579 iowrite32((chip * 2), card->config_regs + FLASH_MODE);
580
581
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000582 iowrite32(1, card->config_regs + WRITE_FLASH);
David Woodhousefa755b92009-01-27 14:16:12 +1100583 wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000584
David Woodhousefa755b92009-01-27 14:16:12 +1100585 for (offset = 0; offset < fw->size; offset += blocksize) {
586 int i;
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000587
David Woodhousefa755b92009-01-27 14:16:12 +1100588 /* Clear write flag */
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000589 iowrite32(0, card->config_regs + WRITE_FLASH);
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000590
David Woodhousefa755b92009-01-27 14:16:12 +1100591 /* 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);
594
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));
Nathan Williams4dbedf42009-03-25 20:27:37 +1100598 if(card->fpga_version > LEGACY_BUFFERS)
599 iowrite32(word, FLASH_BUF + i);
600 else
601 iowrite32(word, RX_BUF(card, 3) + i);
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000602 }
603
David Woodhousefa755b92009-01-27 14:16:12 +1100604 /* 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));
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000608 }
609
David Woodhousefa755b92009-01-27 14:16:12 +1100610 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");
615 return 0;
Simon Farnsworth7c4015b2009-01-21 20:45:49 +0000616}
617
David Woodhouse9c540042008-12-23 04:09:02 +0000618static irqreturn_t solos_irq(int irq, void *dev_id)
619{
620 struct solos_card *card = dev_id;
621 int handled = 1;
622
David Woodhouse9c540042008-12-23 04:09:02 +0000623 iowrite32(0, card->config_regs + IRQ_CLEAR);
David Woodhouse9c540042008-12-23 04:09:02 +0000624
David Woodhouse35c22212009-01-29 14:08:27 +1100625 /* If we're up and running, just kick the tasklet to process TX/RX */
David Woodhousefa755b92009-01-27 14:16:12 +1100626 if (card->atmdev[0])
David Woodhouse9c540042008-12-23 04:09:02 +0000627 tasklet_schedule(&card->tlet);
David Woodhousefa755b92009-01-27 14:16:12 +1100628 else
629 wake_up(&card->fw_wq);
David Woodhouse9c540042008-12-23 04:09:02 +0000630
David Woodhouse9c540042008-12-23 04:09:02 +0000631 return IRQ_RETVAL(handled);
632}
633
634void solos_bh(unsigned long card_arg)
635{
636 struct solos_card *card = (void *)card_arg;
David Woodhouse9c540042008-12-23 04:09:02 +0000637 uint32_t card_flags;
David Woodhouse9c540042008-12-23 04:09:02 +0000638 uint32_t rx_done = 0;
David Woodhouse35c22212009-01-29 14:08:27 +1100639 int port;
David Woodhouse9c540042008-12-23 04:09:02 +0000640
David Woodhouse35c22212009-01-29 14:08:27 +1100641 /*
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
645 */
646 card_flags = fpga_tx(card);
David Woodhouse9c540042008-12-23 04:09:02 +0000647
648 for (port = 0; port < card->nr_ports; port++) {
649 if (card_flags & (0x10 << port)) {
David Woodhouse90937232009-01-28 16:46:56 +1100650 struct pkt_hdr _hdr, *header;
David Woodhouse9c540042008-12-23 04:09:02 +0000651 struct sk_buff *skb;
652 struct atm_vcc *vcc;
653 int size;
654
David Woodhouse90937232009-01-28 16:46:56 +1100655 if (card->using_dma) {
656 skb = card->rx_skb[port];
David Woodhouseeaf83e32009-01-29 10:51:11 +1100657 card->rx_skb[port] = NULL;
David Woodhouse9c540042008-12-23 04:09:02 +0000658
David Woodhouseeaf83e32009-01-29 10:51:11 +1100659 pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr,
660 RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
David Woodhouse9c540042008-12-23 04:09:02 +0000661
David Woodhouse90937232009-01-28 16:46:56 +1100662 header = (void *)skb->data;
663 size = le16_to_cpu(header->size);
664 skb_put(skb, size + sizeof(*header));
665 skb_pull(skb, sizeof(*header));
666 } else {
667 header = &_hdr;
David Woodhouse9c540042008-12-23 04:09:02 +0000668
David Woodhouse90937232009-01-28 16:46:56 +1100669 rx_done |= 0x10 << port;
David Woodhouse9c540042008-12-23 04:09:02 +0000670
David Woodhouse90937232009-01-28 16:46:56 +1100671 memcpy_fromio(header, RX_BUF(card, port), sizeof(*header));
672
673 size = le16_to_cpu(header->size);
Nathan Williams78f857f2009-03-25 20:33:42 +1100674 if (size > (card->buffer_size - sizeof(*header))){
675 dev_warn(&card->dev->dev, "Invalid buffer size\n");
676 continue;
677 }
David Woodhouse90937232009-01-28 16:46:56 +1100678
679 skb = alloc_skb(size + 1, GFP_ATOMIC);
680 if (!skb) {
681 if (net_ratelimit())
682 dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
683 continue;
684 }
685
686 memcpy_fromio(skb_put(skb, size),
687 RX_BUF(card, port) + sizeof(*header),
688 size);
David Woodhouse9c540042008-12-23 04:09:02 +0000689 }
David Woodhouse9c540042008-12-23 04:09:02 +0000690 if (atmdebug) {
691 dev_info(&card->dev->dev, "Received: device %d\n", port);
692 dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n",
David Woodhouse90937232009-01-28 16:46:56 +1100693 size, le16_to_cpu(header->vpi),
694 le16_to_cpu(header->vci));
David Woodhouse9c540042008-12-23 04:09:02 +0000695 print_buffer(skb);
696 }
697
David Woodhouse90937232009-01-28 16:46:56 +1100698 switch (le16_to_cpu(header->type)) {
David Woodhouse9c540042008-12-23 04:09:02 +0000699 case PKT_DATA:
David Woodhouse90937232009-01-28 16:46:56 +1100700 vcc = find_vcc(card->atmdev[port], le16_to_cpu(header->vpi),
701 le16_to_cpu(header->vci));
David Woodhouse9c540042008-12-23 04:09:02 +0000702 if (!vcc) {
703 if (net_ratelimit())
704 dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
David Woodhouse90937232009-01-28 16:46:56 +1100705 le16_to_cpu(header->vci), le16_to_cpu(header->vpi),
David Woodhouse9c540042008-12-23 04:09:02 +0000706 port);
707 continue;
708 }
709 atm_charge(vcc, skb->truesize);
710 vcc->push(vcc, skb);
711 atomic_inc(&vcc->stats->rx);
712 break;
713
David Woodhouse87ebb182009-01-27 20:02:30 +1100714 case PKT_STATUS:
David Woodhouse95852f42009-01-30 14:23:52 +1100715 if (process_status(card, port, skb) &&
716 net_ratelimit()) {
717 dev_warn(&card->dev->dev, "Bad status packet of %d bytes on port %d:\n", skb->len, port);
718 print_buffer(skb);
719 }
David Woodhouseeaf83e32009-01-29 10:51:11 +1100720 dev_kfree_skb_any(skb);
David Woodhouse87ebb182009-01-27 20:02:30 +1100721 break;
722
David Woodhouse9c540042008-12-23 04:09:02 +0000723 case PKT_COMMAND:
724 default: /* FIXME: Not really, surely? */
David Woodhouse01e2ffa2009-01-27 16:20:04 +1100725 if (process_command(card, port, skb))
726 break;
David Woodhouse9c540042008-12-23 04:09:02 +0000727 spin_lock(&card->cli_queue_lock);
728 if (skb_queue_len(&card->cli_queue[port]) > 10) {
729 if (net_ratelimit())
730 dev_warn(&card->dev->dev, "Dropping console response on port %d\n",
731 port);
David Woodhouseeaf83e32009-01-29 10:51:11 +1100732 dev_kfree_skb_any(skb);
David Woodhouse9c540042008-12-23 04:09:02 +0000733 } else
734 skb_queue_tail(&card->cli_queue[port], skb);
735 spin_unlock(&card->cli_queue_lock);
736 break;
737 }
738 }
David Woodhouseeaf83e32009-01-29 10:51:11 +1100739 /* 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);
743 if (skb) {
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;
750 } else {
751 if (net_ratelimit())
752 dev_warn(&card->dev->dev, "Failed to allocate RX skb");
753
754 /* We'll have to try again later */
755 tasklet_schedule(&card->tlet);
756 }
757 }
David Woodhouse9c540042008-12-23 04:09:02 +0000758 }
759 if (rx_done)
760 iowrite32(rx_done, card->config_regs + FLAGS_ADDR);
761
762 return;
763}
764
765static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
766{
767 struct hlist_head *head;
768 struct atm_vcc *vcc = NULL;
769 struct hlist_node *node;
770 struct sock *s;
771
772 read_lock(&vcc_sklist_lock);
773 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
774 sk_for_each(s, node, head) {
775 vcc = atm_sk(s);
776 if (vcc->dev == dev && vcc->vci == vci &&
777 vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE)
778 goto out;
779 }
780 vcc = NULL;
781 out:
782 read_unlock(&vcc_sklist_lock);
783 return vcc;
784}
785
786static int list_vccs(int vci)
787{
788 struct hlist_head *head;
789 struct atm_vcc *vcc;
790 struct hlist_node *node;
791 struct sock *s;
792 int num_found = 0;
793 int i;
794
795 read_lock(&vcc_sklist_lock);
796 if (vci != 0){
797 head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
798 sk_for_each(s, node, head) {
799 num_found ++;
800 vcc = atm_sk(s);
801 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
802 vcc->dev->number,
803 vcc->vpi,
804 vcc->vci);
805 }
806 } else {
David Woodhouse1e615df2009-01-27 21:47:47 +1100807 for(i = 0; i < VCC_HTABLE_SIZE; i++){
David Woodhouse9c540042008-12-23 04:09:02 +0000808 head = &vcc_hash[i];
809 sk_for_each(s, node, head) {
810 num_found ++;
811 vcc = atm_sk(s);
812 printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
813 vcc->dev->number,
814 vcc->vpi,
815 vcc->vci);
816 }
817 }
818 }
819 read_unlock(&vcc_sklist_lock);
820 return num_found;
821}
822
David Woodhouse1e615df2009-01-27 21:47:47 +1100823static void release_vccs(struct atm_dev *dev)
824{
825 int i;
826
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;
831 struct sock *s;
832 struct atm_vcc *vcc;
833
834 sk_for_each_safe(s, node, tmp, head) {
835 vcc = atm_sk(s);
836 if (vcc->dev == dev) {
837 vcc_release_async(vcc, -EPIPE);
838 sk_del_node_init(s);
839 }
840 }
841 }
842 write_unlock_irq(&vcc_sklist_lock);
843}
844
David Woodhouse9c540042008-12-23 04:09:02 +0000845
846static int popen(struct atm_vcc *vcc)
847{
848 struct solos_card *card = vcc->dev->dev_data;
849 struct sk_buff *skb;
850 struct pkt_hdr *header;
851
David Woodhouseb28a4b92009-01-27 21:50:36 +1100852 if (vcc->qos.aal != ATM_AAL5) {
853 dev_warn(&card->dev->dev, "Unsupported ATM type %d\n",
854 vcc->qos.aal);
855 return -EINVAL;
856 }
857
David Woodhouse9c540042008-12-23 04:09:02 +0000858 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");
861 return -ENOMEM;
862 }
863 header = (void *)skb_put(skb, sizeof(*header));
864
David Woodhouseb76811a2009-01-27 10:18:51 +1100865 header->size = cpu_to_le16(0);
David Woodhouse9c540042008-12-23 04:09:02 +0000866 header->vpi = cpu_to_le16(vcc->vpi);
867 header->vci = cpu_to_le16(vcc->vci);
868 header->type = cpu_to_le16(PKT_POPEN);
869
870 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
871
David Woodhousebdc54622009-01-29 14:37:20 +1100872 set_bit(ATM_VF_ADDR, &vcc->flags);
David Woodhouse9c540042008-12-23 04:09:02 +0000873 set_bit(ATM_VF_READY, &vcc->flags);
874 list_vccs(0);
875
David Woodhouse9c540042008-12-23 04:09:02 +0000876
877 return 0;
878}
879
880static void pclose(struct atm_vcc *vcc)
881{
882 struct solos_card *card = vcc->dev->dev_data;
883 struct sk_buff *skb;
884 struct pkt_hdr *header;
885
886 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
887 if (!skb) {
888 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
889 return;
890 }
891 header = (void *)skb_put(skb, sizeof(*header));
892
David Woodhouseb76811a2009-01-27 10:18:51 +1100893 header->size = cpu_to_le16(0);
David Woodhouse9c540042008-12-23 04:09:02 +0000894 header->vpi = cpu_to_le16(vcc->vpi);
895 header->vci = cpu_to_le16(vcc->vci);
896 header->type = cpu_to_le16(PKT_PCLOSE);
897
898 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
899
David Woodhouse9c540042008-12-23 04:09:02 +0000900 clear_bit(ATM_VF_ADDR, &vcc->flags);
901 clear_bit(ATM_VF_READY, &vcc->flags);
902
903 return;
904}
905
906static int print_buffer(struct sk_buff *buf)
907{
908 int len,i;
909 char msg[500];
910 char item[10];
911
912 len = buf->len;
913 for (i = 0; i < len; i++){
914 if(i % 8 == 0)
915 sprintf(msg, "%02X: ", i);
916
917 sprintf(item,"%02X ",*(buf->data + i));
918 strcat(msg, item);
919 if(i % 8 == 7) {
920 sprintf(item, "\n");
921 strcat(msg, item);
922 printk(KERN_DEBUG "%s", msg);
923 }
924 }
925 if (i % 8 != 0) {
926 sprintf(item, "\n");
927 strcat(msg, item);
928 printk(KERN_DEBUG "%s", msg);
929 }
930 printk(KERN_DEBUG "\n");
931
932 return 0;
933}
934
935static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
936 struct atm_vcc *vcc)
937{
938 int old_len;
David Woodhousef69e4172009-01-29 11:10:58 +1100939 unsigned long flags;
David Woodhouse9c540042008-12-23 04:09:02 +0000940
David Woodhouse90937232009-01-28 16:46:56 +1100941 SKB_CB(skb)->vcc = vcc;
David Woodhouse9c540042008-12-23 04:09:02 +0000942
David Woodhousef69e4172009-01-29 11:10:58 +1100943 spin_lock_irqsave(&card->tx_queue_lock, flags);
David Woodhouse9c540042008-12-23 04:09:02 +0000944 old_len = skb_queue_len(&card->tx_queue[port]);
945 skb_queue_tail(&card->tx_queue[port], skb);
David Woodhouse35c22212009-01-29 14:08:27 +1100946 if (!old_len)
David Woodhousef69e4172009-01-29 11:10:58 +1100947 card->tx_mask |= (1 << port);
David Woodhousef69e4172009-01-29 11:10:58 +1100948 spin_unlock_irqrestore(&card->tx_queue_lock, flags);
David Woodhouse9c540042008-12-23 04:09:02 +0000949
David Woodhousef69e4172009-01-29 11:10:58 +1100950 /* Theoretically we could just schedule the tasklet here, but
951 that introduces latency we don't want -- it's noticeable */
David Woodhouse9c540042008-12-23 04:09:02 +0000952 if (!old_len)
953 fpga_tx(card);
954}
955
David Woodhouse35c22212009-01-29 14:08:27 +1100956static uint32_t fpga_tx(struct solos_card *card)
David Woodhouse9c540042008-12-23 04:09:02 +0000957{
David Woodhouse35c22212009-01-29 14:08:27 +1100958 uint32_t tx_pending, card_flags;
David Woodhouse9c540042008-12-23 04:09:02 +0000959 uint32_t tx_started = 0;
960 struct sk_buff *skb;
961 struct atm_vcc *vcc;
962 unsigned char port;
963 unsigned long flags;
964
965 spin_lock_irqsave(&card->tx_lock, flags);
David Woodhouse35c22212009-01-29 14:08:27 +1100966
967 card_flags = ioread32(card->config_regs + FLAGS_ADDR);
968 /*
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.
974 */
975 tx_pending = card->tx_mask & ~card_flags;
David Woodhouse9c540042008-12-23 04:09:02 +0000976
David Woodhouse35c22212009-01-29 14:08:27 +1100977 for (port = 0; tx_pending; tx_pending >>= 1, port++) {
978 if (tx_pending & 1) {
David Woodhouseeaf83e32009-01-29 10:51:11 +1100979 struct sk_buff *oldskb = card->tx_skb[port];
David Woodhouseeaf83e32009-01-29 10:51:11 +1100980 if (oldskb)
981 pci_unmap_single(card->dev, SKB_CB(oldskb)->dma_addr,
982 oldskb->len, PCI_DMA_TODEVICE);
David Woodhouse9c540042008-12-23 04:09:02 +0000983
984 spin_lock(&card->tx_queue_lock);
985 skb = skb_dequeue(&card->tx_queue[port]);
David Woodhousef69e4172009-01-29 11:10:58 +1100986 if (!skb)
987 card->tx_mask &= ~(1 << port);
David Woodhouse9c540042008-12-23 04:09:02 +0000988 spin_unlock(&card->tx_queue_lock);
989
David Woodhouseeaf83e32009-01-29 10:51:11 +1100990 if (skb && !card->using_dma) {
991 memcpy_toio(TX_BUF(card, port), skb->data, skb->len);
David Woodhousebdc54622009-01-29 14:37:20 +1100992 tx_started |= 1 << port;
David Woodhouseeaf83e32009-01-29 10:51:11 +1100993 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));
999 }
1000
1001 if (!oldskb)
David Woodhouse9c540042008-12-23 04:09:02 +00001002 continue;
1003
David Woodhouseeaf83e32009-01-29 10:51:11 +11001004 /* Clean up and free oldskb now it's gone */
David Woodhouse9c540042008-12-23 04:09:02 +00001005 if (atmdebug) {
1006 dev_info(&card->dev->dev, "Transmitted: port %d\n",
1007 port);
David Woodhouseeaf83e32009-01-29 10:51:11 +11001008 print_buffer(oldskb);
David Woodhouse9c540042008-12-23 04:09:02 +00001009 }
David Woodhouse9c540042008-12-23 04:09:02 +00001010
David Woodhouseeaf83e32009-01-29 10:51:11 +11001011 vcc = SKB_CB(oldskb)->vcc;
David Woodhouse9c540042008-12-23 04:09:02 +00001012
1013 if (vcc) {
1014 atomic_inc(&vcc->stats->tx);
David Woodhouseeaf83e32009-01-29 10:51:11 +11001015 solos_pop(vcc, oldskb);
David Woodhouse9c540042008-12-23 04:09:02 +00001016 } else
David Woodhouseeaf83e32009-01-29 10:51:11 +11001017 dev_kfree_skb_irq(oldskb);
David Woodhouse9c540042008-12-23 04:09:02 +00001018
David Woodhouse9c540042008-12-23 04:09:02 +00001019 }
1020 }
David Woodhousebdc54622009-01-29 14:37:20 +11001021 /* For non-DMA TX, write the 'TX start' bit for all four ports simultaneously */
David Woodhouse9c540042008-12-23 04:09:02 +00001022 if (tx_started)
1023 iowrite32(tx_started, card->config_regs + FLAGS_ADDR);
1024
1025 spin_unlock_irqrestore(&card->tx_lock, flags);
David Woodhouse35c22212009-01-29 14:08:27 +11001026 return card_flags;
David Woodhouse9c540042008-12-23 04:09:02 +00001027}
1028
1029static int psend(struct atm_vcc *vcc, struct sk_buff *skb)
1030{
1031 struct solos_card *card = vcc->dev->dev_data;
David Woodhouse9c540042008-12-23 04:09:02 +00001032 struct pkt_hdr *header;
David Woodhouseb76811a2009-01-27 10:18:51 +11001033 int pktlen;
David Woodhouse9c540042008-12-23 04:09:02 +00001034
David Woodhouseb76811a2009-01-27 10:18:51 +11001035 pktlen = skb->len;
1036 if (pktlen > (BUF_SIZE - sizeof(*header))) {
David Woodhouse9c540042008-12-23 04:09:02 +00001037 dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
1038 solos_pop(vcc, skb);
1039 return 0;
1040 }
1041
1042 if (!skb_clone_writable(skb, sizeof(*header))) {
1043 int expand_by = 0;
1044 int ret;
1045
1046 if (skb_headroom(skb) < sizeof(*header))
1047 expand_by = sizeof(*header) - skb_headroom(skb);
1048
1049 ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
1050 if (ret) {
Simon Farnsworth4306cad2009-01-19 21:19:29 +00001051 dev_warn(&card->dev->dev, "pskb_expand_head failed.\n");
David Woodhouse9c540042008-12-23 04:09:02 +00001052 solos_pop(vcc, skb);
1053 return ret;
1054 }
1055 }
1056
1057 header = (void *)skb_push(skb, sizeof(*header));
1058
David Woodhouseb76811a2009-01-27 10:18:51 +11001059 /* This does _not_ include the size of the header */
1060 header->size = cpu_to_le16(pktlen);
David Woodhouse9c540042008-12-23 04:09:02 +00001061 header->vpi = cpu_to_le16(vcc->vpi);
1062 header->vci = cpu_to_le16(vcc->vci);
1063 header->type = cpu_to_le16(PKT_DATA);
1064
1065 fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
1066
1067 return 0;
1068}
1069
1070static struct atmdev_ops fpga_ops = {
1071 .open = popen,
1072 .close = pclose,
1073 .ioctl = NULL,
1074 .getsockopt = NULL,
1075 .setsockopt = NULL,
1076 .send = psend,
1077 .send_oam = NULL,
1078 .phy_put = NULL,
1079 .phy_get = NULL,
1080 .change_qos = NULL,
1081 .proc_read = NULL,
1082 .owner = THIS_MODULE
1083};
1084
1085static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
1086{
David Woodhousecd5549e2009-01-30 14:26:37 +11001087 int err;
David Woodhouse9c540042008-12-23 04:09:02 +00001088 uint16_t fpga_ver;
1089 uint8_t major_ver, minor_ver;
1090 uint32_t data32;
1091 struct solos_card *card;
1092
David Woodhouse9c540042008-12-23 04:09:02 +00001093 card = kzalloc(sizeof(*card), GFP_KERNEL);
1094 if (!card)
1095 return -ENOMEM;
1096
1097 card->dev = dev;
David Woodhousefa755b92009-01-27 14:16:12 +11001098 init_waitqueue_head(&card->fw_wq);
David Woodhouse01e2ffa2009-01-27 16:20:04 +11001099 init_waitqueue_head(&card->param_wq);
David Woodhouse9c540042008-12-23 04:09:02 +00001100
1101 err = pci_enable_device(dev);
1102 if (err) {
1103 dev_warn(&dev->dev, "Failed to enable PCI device\n");
1104 goto out;
1105 }
1106
Yang Hongyange9304382009-04-13 14:40:14 -07001107 err = pci_set_dma_mask(dev, DMA_BIT_MASK(32));
David Woodhouse90937232009-01-28 16:46:56 +11001108 if (err) {
1109 dev_warn(&dev->dev, "Failed to set 32-bit DMA mask\n");
1110 goto out;
1111 }
1112
David Woodhouse9c540042008-12-23 04:09:02 +00001113 err = pci_request_regions(dev, "solos");
1114 if (err) {
1115 dev_warn(&dev->dev, "Failed to request regions\n");
1116 goto out;
1117 }
1118
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;
1123 }
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;
1128 }
1129
David Woodhousecc3657e2009-01-30 14:23:22 +11001130 if (reset) {
1131 iowrite32(1, card->config_regs + FPGA_MODE);
1132 data32 = ioread32(card->config_regs + FPGA_MODE);
David Woodhouse9c540042008-12-23 04:09:02 +00001133
David Woodhousecc3657e2009-01-30 14:23:22 +11001134 iowrite32(0, card->config_regs + FPGA_MODE);
1135 data32 = ioread32(card->config_regs + FPGA_MODE);
1136 }
David Woodhouse9c540042008-12-23 04:09:02 +00001137
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);
Nathan Williams4dbedf42009-03-25 20:27:37 +11001142 card->fpga_version = FPGA_VERSION(major_ver,minor_ver);
1143 if (card->fpga_version > LEGACY_BUFFERS)
1144 card->buffer_size = BUF_SIZE;
1145 else
1146 card->buffer_size = OLD_BUF_SIZE;
David Woodhouse9c540042008-12-23 04:09:02 +00001147 dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
1148 major_ver, minor_ver, fpga_ver);
1149
Nathan Williams4dbedf42009-03-25 20:27:37 +11001150 if (card->fpga_version >= DMA_SUPPORTED){
David Woodhouse90937232009-01-28 16:46:56 +11001151 card->using_dma = 1;
Nathan Williams4dbedf42009-03-25 20:27:37 +11001152 } else {
1153 card->using_dma = 0;
David Woodhouseeab50f72009-01-30 14:27:26 +11001154 /* Set RX empty flag for all ports */
1155 iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
1156 }
David Woodhouse9c540042008-12-23 04:09:02 +00001157
Nathan Williams0fc36aa2009-02-07 10:19:13 +11001158 data32 = ioread32(card->config_regs + PORTS);
1159 card->nr_ports = (data32 & 0x000000FF);
David Woodhouse9c540042008-12-23 04:09:02 +00001160
1161 pci_set_drvdata(dev, card);
David Woodhousefa755b92009-01-27 14:16:12 +11001162
David Woodhouse9c540042008-12-23 04:09:02 +00001163 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);
David Woodhouse01e2ffa2009-01-27 16:20:04 +11001167 spin_lock_init(&card->param_queue_lock);
1168 INIT_LIST_HEAD(&card->param_queue);
David Woodhouse9c540042008-12-23 04:09:02 +00001169
David Woodhousefcd82662009-01-29 11:29:12 +11001170 err = request_irq(dev->irq, solos_irq, IRQF_SHARED,
David Woodhouse9c540042008-12-23 04:09:02 +00001171 "solos-pci", card);
David Woodhousefa755b92009-01-27 14:16:12 +11001172 if (err) {
David Woodhouse9c540042008-12-23 04:09:02 +00001173 dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
David Woodhousefa755b92009-01-27 14:16:12 +11001174 goto out_unmap_both;
1175 }
David Woodhouse9c540042008-12-23 04:09:02 +00001176
David Woodhouse9c540042008-12-23 04:09:02 +00001177 iowrite32(1, card->config_regs + IRQ_EN_ADDR);
1178
David Woodhousefa755b92009-01-27 14:16:12 +11001179 if (fpga_upgrade)
1180 flash_upgrade(card, 0);
1181
1182 if (firmware_upgrade)
1183 flash_upgrade(card, 1);
1184
Nathan Williams4dbedf42009-03-25 20:27:37 +11001185 if (db_fpga_upgrade)
1186 flash_upgrade(card, 2);
1187
1188 if (db_firmware_upgrade)
1189 flash_upgrade(card, 3);
1190
David Woodhousefa755b92009-01-27 14:16:12 +11001191 err = atm_init(card);
1192 if (err)
1193 goto out_free_irq;
1194
David Woodhouse9c540042008-12-23 04:09:02 +00001195 return 0;
1196
David Woodhousefa755b92009-01-27 14:16:12 +11001197 out_free_irq:
1198 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
1199 free_irq(dev->irq, card);
1200 tasklet_kill(&card->tlet);
1201
David Woodhouse9c540042008-12-23 04:09:02 +00001202 out_unmap_both:
David Woodhousefa755b92009-01-27 14:16:12 +11001203 pci_set_drvdata(dev, NULL);
David Woodhouse9c540042008-12-23 04:09:02 +00001204 pci_iounmap(dev, card->config_regs);
1205 out_unmap_config:
1206 pci_iounmap(dev, card->buffers);
1207 out_release_regions:
1208 pci_release_regions(dev);
1209 out:
Julia Lawallbc111d52009-02-08 17:00:02 -08001210 kfree(card);
David Woodhouse9c540042008-12-23 04:09:02 +00001211 return err;
1212}
1213
1214static int atm_init(struct solos_card *card)
1215{
1216 int i;
1217
David Woodhouse9c540042008-12-23 04:09:02 +00001218 for (i = 0; i < card->nr_ports; i++) {
David Woodhouse87ebb182009-01-27 20:02:30 +11001219 struct sk_buff *skb;
1220 struct pkt_hdr *header;
1221
David Woodhouse9c540042008-12-23 04:09:02 +00001222 skb_queue_head_init(&card->tx_queue[i]);
1223 skb_queue_head_init(&card->cli_queue[i]);
1224
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);
1228 atm_remove(card);
1229 return -ENODEV;
1230 }
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);
David Woodhoused057f0a2009-01-27 16:52:07 +11001233 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);
David Woodhouse9c540042008-12-23 04:09:02 +00001235
1236 dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
1237
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;
David Woodhouse87ebb182009-01-27 20:02:30 +11001242 card->atmdev[i]->signal = ATM_PHY_SIG_UNKNOWN;
1243
1244 skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
1245 if (!skb) {
1246 dev_warn(&card->dev->dev, "Failed to allocate sk_buff in atm_init()\n");
1247 continue;
1248 }
1249
1250 header = (void *)skb_put(skb, sizeof(*header));
1251
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);
1256
1257 fpga_queue(card, i, skb, NULL);
David Woodhouse9c540042008-12-23 04:09:02 +00001258 }
1259 return 0;
1260}
1261
1262static void atm_remove(struct solos_card *card)
1263{
1264 int i;
1265
1266 for (i = 0; i < card->nr_ports; i++) {
1267 if (card->atmdev[i]) {
David Woodhouse97d759d2009-03-17 14:59:34 +00001268 struct sk_buff *skb;
1269
David Woodhouse9c540042008-12-23 04:09:02 +00001270 dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
David Woodhousec0fe3022009-01-28 14:34:34 +11001271
1272 sysfs_remove_group(&card->atmdev[i]->class_dev.kobj, &solos_attr_group);
David Woodhouse9c540042008-12-23 04:09:02 +00001273 atm_dev_deregister(card->atmdev[i]);
David Woodhouse97d759d2009-03-17 14:59:34 +00001274
1275 skb = card->rx_skb[i];
1276 if (skb) {
1277 pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr,
1278 RX_DMA_SIZE, PCI_DMA_FROMDEVICE);
1279 dev_kfree_skb(skb);
1280 }
1281 skb = card->tx_skb[i];
1282 if (skb) {
1283 pci_unmap_single(card->dev, SKB_CB(skb)->dma_addr,
1284 skb->len, PCI_DMA_TODEVICE);
1285 dev_kfree_skb(skb);
1286 }
1287 while ((skb = skb_dequeue(&card->tx_queue[i])))
1288 dev_kfree_skb(skb);
1289
David Woodhouse9c540042008-12-23 04:09:02 +00001290 }
1291 }
1292}
1293
1294static void fpga_remove(struct pci_dev *dev)
1295{
1296 struct solos_card *card = pci_get_drvdata(dev);
David Woodhouse97d759d2009-03-17 14:59:34 +00001297
1298 /* Disable IRQs */
1299 iowrite32(0, card->config_regs + IRQ_EN_ADDR);
David Woodhouse9c540042008-12-23 04:09:02 +00001300
David Woodhouse97d759d2009-03-17 14:59:34 +00001301 /* Reset FPGA */
1302 iowrite32(1, card->config_regs + FPGA_MODE);
1303 (void)ioread32(card->config_regs + FPGA_MODE);
David Woodhouse9c540042008-12-23 04:09:02 +00001304
1305 atm_remove(card);
1306
David Woodhouse9c540042008-12-23 04:09:02 +00001307 free_irq(dev->irq, card);
1308 tasklet_kill(&card->tlet);
1309
David Woodhouse97d759d2009-03-17 14:59:34 +00001310 /* Release device from reset */
1311 iowrite32(0, card->config_regs + FPGA_MODE);
1312 (void)ioread32(card->config_regs + FPGA_MODE);
1313
David Woodhouse9c540042008-12-23 04:09:02 +00001314 pci_iounmap(dev, card->buffers);
1315 pci_iounmap(dev, card->config_regs);
1316
David Woodhouse9c540042008-12-23 04:09:02 +00001317 pci_release_regions(dev);
1318 pci_disable_device(dev);
1319
1320 pci_set_drvdata(dev, NULL);
1321 kfree(card);
David Woodhouse9c540042008-12-23 04:09:02 +00001322}
1323
1324static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
1325 { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
1326 { 0, }
1327};
1328
1329MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
1330
1331static struct pci_driver fpga_driver = {
1332 .name = "solos",
1333 .id_table = fpga_pci_tbl,
1334 .probe = fpga_probe,
1335 .remove = fpga_remove,
1336};
1337
1338
1339static int __init solos_pci_init(void)
1340{
1341 printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
1342 return pci_register_driver(&fpga_driver);
1343}
1344
1345static void __exit solos_pci_exit(void)
1346{
1347 pci_unregister_driver(&fpga_driver);
1348 printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
1349}
1350
1351module_init(solos_pci_init);
1352module_exit(solos_pci_exit);