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