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