solos-pci.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. /*
  2. * Driver for the Solos PCI ADSL2+ card, designed to support Linux by
  3. * Traverse Technologies -- http://www.traverse.com.au/
  4. * Xrio Limited -- http://www.xrio.com/
  5. *
  6. *
  7. * Copyright © 2008 Traverse Technologies
  8. * Copyright © 2008 Intel Corporation
  9. *
  10. * Authors: Nathan Williams <nathan@traverse.com.au>
  11. * David Woodhouse <dwmw2@infradead.org>
  12. * Treker Chen <treker@xrio.com>
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * version 2, as published by the Free Software Foundation.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. */
  23. #define DEBUG
  24. #define VERBOSE_DEBUG
  25. #include <linux/interrupt.h>
  26. #include <linux/module.h>
  27. #include <linux/kernel.h>
  28. #include <linux/errno.h>
  29. #include <linux/ioport.h>
  30. #include <linux/types.h>
  31. #include <linux/pci.h>
  32. #include <linux/atm.h>
  33. #include <linux/atmdev.h>
  34. #include <linux/skbuff.h>
  35. #include <linux/sysfs.h>
  36. #include <linux/device.h>
  37. #include <linux/kobject.h>
  38. #include <linux/firmware.h>
  39. #define VERSION "0.07"
  40. #define PTAG "solos-pci"
  41. #define CONFIG_RAM_SIZE 128
  42. #define FLAGS_ADDR 0x7C
  43. #define IRQ_EN_ADDR 0x78
  44. #define FPGA_VER 0x74
  45. #define IRQ_CLEAR 0x70
  46. #define WRITE_FLASH 0x6C
  47. #define PORTS 0x68
  48. #define FLASH_BLOCK 0x64
  49. #define FLASH_BUSY 0x60
  50. #define FPGA_MODE 0x5C
  51. #define FLASH_MODE 0x58
  52. #define DATA_RAM_SIZE 32768
  53. #define BUF_SIZE 4096
  54. #define FPGA_PAGE 528 /* FPGA flash page size*/
  55. #define SOLOS_PAGE 512 /* Solos flash page size*/
  56. #define FPGA_BLOCK (FPGA_PAGE * 8) /* FPGA flash block size*/
  57. #define SOLOS_BLOCK (SOLOS_PAGE * 8) /* Solos flash block size*/
  58. #define RX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2)
  59. #define TX_BUF(card, nr) ((card->buffers) + (nr)*BUF_SIZE*2 + BUF_SIZE)
  60. static int debug = 0;
  61. static int atmdebug = 0;
  62. static int firmware_upgrade = 0;
  63. static int fpga_upgrade = 0;
  64. struct pkt_hdr {
  65. __le16 size;
  66. __le16 vpi;
  67. __le16 vci;
  68. __le16 type;
  69. };
  70. #define PKT_DATA 0
  71. #define PKT_COMMAND 1
  72. #define PKT_POPEN 3
  73. #define PKT_PCLOSE 4
  74. struct solos_card {
  75. void __iomem *config_regs;
  76. void __iomem *buffers;
  77. int nr_ports;
  78. struct pci_dev *dev;
  79. struct atm_dev *atmdev[4];
  80. struct tasklet_struct tlet;
  81. spinlock_t tx_lock;
  82. spinlock_t tx_queue_lock;
  83. spinlock_t cli_queue_lock;
  84. struct sk_buff_head tx_queue[4];
  85. struct sk_buff_head cli_queue[4];
  86. wait_queue_head_t fw_wq;
  87. };
  88. #define SOLOS_CHAN(atmdev) ((int)(unsigned long)(atmdev)->phy_data)
  89. MODULE_AUTHOR("Traverse Technologies <support@traverse.com.au>");
  90. MODULE_DESCRIPTION("Solos PCI driver");
  91. MODULE_VERSION(VERSION);
  92. MODULE_LICENSE("GPL");
  93. MODULE_PARM_DESC(debug, "Enable Loopback");
  94. MODULE_PARM_DESC(atmdebug, "Print ATM data");
  95. MODULE_PARM_DESC(firmware_upgrade, "Initiate Solos firmware upgrade");
  96. MODULE_PARM_DESC(fpga_upgrade, "Initiate FPGA upgrade");
  97. module_param(debug, int, 0444);
  98. module_param(atmdebug, int, 0644);
  99. module_param(firmware_upgrade, int, 0444);
  100. module_param(fpga_upgrade, int, 0444);
  101. static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
  102. struct atm_vcc *vcc);
  103. static int fpga_tx(struct solos_card *);
  104. static irqreturn_t solos_irq(int irq, void *dev_id);
  105. static struct atm_vcc* find_vcc(struct atm_dev *dev, short vpi, int vci);
  106. static int list_vccs(int vci);
  107. static int atm_init(struct solos_card *);
  108. static void atm_remove(struct solos_card *);
  109. static int send_command(struct solos_card *card, int dev, const char *buf, size_t size);
  110. static void solos_bh(unsigned long);
  111. static int print_buffer(struct sk_buff *buf);
  112. static inline void solos_pop(struct atm_vcc *vcc, struct sk_buff *skb)
  113. {
  114. if (vcc->pop)
  115. vcc->pop(vcc, skb);
  116. else
  117. dev_kfree_skb_any(skb);
  118. }
  119. static ssize_t console_show(struct device *dev, struct device_attribute *attr,
  120. char *buf)
  121. {
  122. struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
  123. struct solos_card *card = atmdev->dev_data;
  124. struct sk_buff *skb;
  125. spin_lock(&card->cli_queue_lock);
  126. skb = skb_dequeue(&card->cli_queue[SOLOS_CHAN(atmdev)]);
  127. spin_unlock(&card->cli_queue_lock);
  128. if(skb == NULL)
  129. return sprintf(buf, "No data.\n");
  130. memcpy(buf, skb->data, skb->len);
  131. dev_dbg(&card->dev->dev, "len: %d\n", skb->len);
  132. kfree_skb(skb);
  133. return skb->len;
  134. }
  135. static int send_command(struct solos_card *card, int dev, const char *buf, size_t size)
  136. {
  137. struct sk_buff *skb;
  138. struct pkt_hdr *header;
  139. // dev_dbg(&card->dev->dev, "size: %d\n", size);
  140. if (size > (BUF_SIZE - sizeof(*header))) {
  141. dev_dbg(&card->dev->dev, "Command is too big. Dropping request\n");
  142. return 0;
  143. }
  144. skb = alloc_skb(size + sizeof(*header), GFP_ATOMIC);
  145. if (!skb) {
  146. dev_warn(&card->dev->dev, "Failed to allocate sk_buff in send_command()\n");
  147. return 0;
  148. }
  149. header = (void *)skb_put(skb, sizeof(*header));
  150. header->size = cpu_to_le16(size);
  151. header->vpi = cpu_to_le16(0);
  152. header->vci = cpu_to_le16(0);
  153. header->type = cpu_to_le16(PKT_COMMAND);
  154. memcpy(skb_put(skb, size), buf, size);
  155. fpga_queue(card, dev, skb, NULL);
  156. return 0;
  157. }
  158. static ssize_t console_store(struct device *dev, struct device_attribute *attr,
  159. const char *buf, size_t count)
  160. {
  161. struct atm_dev *atmdev = container_of(dev, struct atm_dev, class_dev);
  162. struct solos_card *card = atmdev->dev_data;
  163. int err;
  164. err = send_command(card, SOLOS_CHAN(atmdev), buf, count);
  165. return err?:count;
  166. }
  167. static DEVICE_ATTR(console, 0644, console_show, console_store);
  168. static int flash_upgrade(struct solos_card *card, int chip)
  169. {
  170. const struct firmware *fw;
  171. const char *fw_name;
  172. uint32_t data32 = 0;
  173. int blocksize = 0;
  174. int numblocks = 0;
  175. int offset;
  176. if (chip == 0) {
  177. fw_name = "solos-FPGA.bin";
  178. blocksize = FPGA_BLOCK;
  179. } else {
  180. fw_name = "solos-Firmware.bin";
  181. blocksize = SOLOS_BLOCK;
  182. }
  183. if (request_firmware(&fw, fw_name, &card->dev->dev))
  184. return -ENOENT;
  185. dev_info(&card->dev->dev, "Flash upgrade starting\n");
  186. numblocks = fw->size / blocksize;
  187. dev_info(&card->dev->dev, "Firmware size: %zd\n", fw->size);
  188. dev_info(&card->dev->dev, "Number of blocks: %d\n", numblocks);
  189. dev_info(&card->dev->dev, "Changing FPGA to Update mode\n");
  190. iowrite32(1, card->config_regs + FPGA_MODE);
  191. data32 = ioread32(card->config_regs + FPGA_MODE);
  192. /* Set mode to Chip Erase */
  193. dev_info(&card->dev->dev, "Set FPGA Flash mode to %s Chip Erase\n",
  194. chip?"Solos":"FPGA");
  195. iowrite32((chip * 2), card->config_regs + FLASH_MODE);
  196. iowrite32(1, card->config_regs + WRITE_FLASH);
  197. wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
  198. for (offset = 0; offset < fw->size; offset += blocksize) {
  199. int i;
  200. /* Clear write flag */
  201. iowrite32(0, card->config_regs + WRITE_FLASH);
  202. /* Set mode to Block Write */
  203. /* dev_info(&card->dev->dev, "Set FPGA Flash mode to Block Write\n"); */
  204. iowrite32(((chip * 2) + 1), card->config_regs + FLASH_MODE);
  205. /* Copy block to buffer, swapping each 16 bits */
  206. for(i = 0; i < blocksize; i += 4) {
  207. uint32_t word = swahb32p((uint32_t *)(fw->data + offset + i));
  208. iowrite32(word, RX_BUF(card, 3) + i);
  209. }
  210. /* Specify block number and then trigger flash write */
  211. iowrite32(offset / blocksize, card->config_regs + FLASH_BLOCK);
  212. iowrite32(1, card->config_regs + WRITE_FLASH);
  213. wait_event(card->fw_wq, !ioread32(card->config_regs + FLASH_BUSY));
  214. }
  215. release_firmware(fw);
  216. iowrite32(0, card->config_regs + WRITE_FLASH);
  217. iowrite32(0, card->config_regs + FPGA_MODE);
  218. iowrite32(0, card->config_regs + FLASH_MODE);
  219. dev_info(&card->dev->dev, "Returning FPGA to Data mode\n");
  220. return 0;
  221. }
  222. static irqreturn_t solos_irq(int irq, void *dev_id)
  223. {
  224. struct solos_card *card = dev_id;
  225. int handled = 1;
  226. //ACK IRQ
  227. iowrite32(0, card->config_regs + IRQ_CLEAR);
  228. //Disable IRQs from FPGA
  229. iowrite32(0, card->config_regs + IRQ_EN_ADDR);
  230. if (card->atmdev[0])
  231. tasklet_schedule(&card->tlet);
  232. else
  233. wake_up(&card->fw_wq);
  234. //Enable IRQs from FPGA
  235. iowrite32(1, card->config_regs + IRQ_EN_ADDR);
  236. return IRQ_RETVAL(handled);
  237. }
  238. void solos_bh(unsigned long card_arg)
  239. {
  240. struct solos_card *card = (void *)card_arg;
  241. int port;
  242. uint32_t card_flags;
  243. uint32_t tx_mask;
  244. uint32_t rx_done = 0;
  245. card_flags = ioread32(card->config_regs + FLAGS_ADDR);
  246. /* The TX bits are set if the channel is busy; clear if not. We want to
  247. invoke fpga_tx() unless _all_ the bits for active channels are set */
  248. tx_mask = (1 << card->nr_ports) - 1;
  249. if ((card_flags & tx_mask) != tx_mask)
  250. fpga_tx(card);
  251. for (port = 0; port < card->nr_ports; port++) {
  252. if (card_flags & (0x10 << port)) {
  253. struct pkt_hdr header;
  254. struct sk_buff *skb;
  255. struct atm_vcc *vcc;
  256. int size;
  257. rx_done |= 0x10 << port;
  258. memcpy_fromio(&header, RX_BUF(card, port), sizeof(header));
  259. size = le16_to_cpu(header.size);
  260. skb = alloc_skb(size, GFP_ATOMIC);
  261. if (!skb) {
  262. if (net_ratelimit())
  263. dev_warn(&card->dev->dev, "Failed to allocate sk_buff for RX\n");
  264. continue;
  265. }
  266. memcpy_fromio(skb_put(skb, size),
  267. RX_BUF(card, port) + sizeof(header),
  268. size);
  269. if (atmdebug) {
  270. dev_info(&card->dev->dev, "Received: device %d\n", port);
  271. dev_info(&card->dev->dev, "size: %d VPI: %d VCI: %d\n",
  272. size, le16_to_cpu(header.vpi),
  273. le16_to_cpu(header.vci));
  274. print_buffer(skb);
  275. }
  276. switch (le16_to_cpu(header.type)) {
  277. case PKT_DATA:
  278. vcc = find_vcc(card->atmdev[port], le16_to_cpu(header.vpi),
  279. le16_to_cpu(header.vci));
  280. if (!vcc) {
  281. if (net_ratelimit())
  282. dev_warn(&card->dev->dev, "Received packet for unknown VCI.VPI %d.%d on port %d\n",
  283. le16_to_cpu(header.vci), le16_to_cpu(header.vpi),
  284. port);
  285. continue;
  286. }
  287. atm_charge(vcc, skb->truesize);
  288. vcc->push(vcc, skb);
  289. atomic_inc(&vcc->stats->rx);
  290. break;
  291. case PKT_COMMAND:
  292. default: /* FIXME: Not really, surely? */
  293. spin_lock(&card->cli_queue_lock);
  294. if (skb_queue_len(&card->cli_queue[port]) > 10) {
  295. if (net_ratelimit())
  296. dev_warn(&card->dev->dev, "Dropping console response on port %d\n",
  297. port);
  298. } else
  299. skb_queue_tail(&card->cli_queue[port], skb);
  300. spin_unlock(&card->cli_queue_lock);
  301. break;
  302. }
  303. }
  304. }
  305. if (rx_done)
  306. iowrite32(rx_done, card->config_regs + FLAGS_ADDR);
  307. return;
  308. }
  309. static struct atm_vcc *find_vcc(struct atm_dev *dev, short vpi, int vci)
  310. {
  311. struct hlist_head *head;
  312. struct atm_vcc *vcc = NULL;
  313. struct hlist_node *node;
  314. struct sock *s;
  315. read_lock(&vcc_sklist_lock);
  316. head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
  317. sk_for_each(s, node, head) {
  318. vcc = atm_sk(s);
  319. if (vcc->dev == dev && vcc->vci == vci &&
  320. vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE)
  321. goto out;
  322. }
  323. vcc = NULL;
  324. out:
  325. read_unlock(&vcc_sklist_lock);
  326. return vcc;
  327. }
  328. static int list_vccs(int vci)
  329. {
  330. struct hlist_head *head;
  331. struct atm_vcc *vcc;
  332. struct hlist_node *node;
  333. struct sock *s;
  334. int num_found = 0;
  335. int i;
  336. read_lock(&vcc_sklist_lock);
  337. if (vci != 0){
  338. head = &vcc_hash[vci & (VCC_HTABLE_SIZE -1)];
  339. sk_for_each(s, node, head) {
  340. num_found ++;
  341. vcc = atm_sk(s);
  342. printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
  343. vcc->dev->number,
  344. vcc->vpi,
  345. vcc->vci);
  346. }
  347. } else {
  348. for(i=0; i<32; i++){
  349. head = &vcc_hash[i];
  350. sk_for_each(s, node, head) {
  351. num_found ++;
  352. vcc = atm_sk(s);
  353. printk(KERN_DEBUG "Device: %d Vpi: %d Vci: %d\n",
  354. vcc->dev->number,
  355. vcc->vpi,
  356. vcc->vci);
  357. }
  358. }
  359. }
  360. read_unlock(&vcc_sklist_lock);
  361. return num_found;
  362. }
  363. static int popen(struct atm_vcc *vcc)
  364. {
  365. struct solos_card *card = vcc->dev->dev_data;
  366. struct sk_buff *skb;
  367. struct pkt_hdr *header;
  368. skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
  369. if (!skb && net_ratelimit()) {
  370. dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
  371. return -ENOMEM;
  372. }
  373. header = (void *)skb_put(skb, sizeof(*header));
  374. header->size = cpu_to_le16(0);
  375. header->vpi = cpu_to_le16(vcc->vpi);
  376. header->vci = cpu_to_le16(vcc->vci);
  377. header->type = cpu_to_le16(PKT_POPEN);
  378. fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
  379. // dev_dbg(&card->dev->dev, "Open for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
  380. set_bit(ATM_VF_ADDR, &vcc->flags); // accept the vpi / vci
  381. set_bit(ATM_VF_READY, &vcc->flags);
  382. list_vccs(0);
  383. return 0;
  384. }
  385. static void pclose(struct atm_vcc *vcc)
  386. {
  387. struct solos_card *card = vcc->dev->dev_data;
  388. struct sk_buff *skb;
  389. struct pkt_hdr *header;
  390. skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
  391. if (!skb) {
  392. dev_warn(&card->dev->dev, "Failed to allocate sk_buff in pclose()\n");
  393. return;
  394. }
  395. header = (void *)skb_put(skb, sizeof(*header));
  396. header->size = cpu_to_le16(0);
  397. header->vpi = cpu_to_le16(vcc->vpi);
  398. header->vci = cpu_to_le16(vcc->vci);
  399. header->type = cpu_to_le16(PKT_PCLOSE);
  400. fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, NULL);
  401. // dev_dbg(&card->dev->dev, "Close for vpi %d and vci %d on interface %d\n", vcc->vpi, vcc->vci, SOLOS_CHAN(vcc->dev));
  402. clear_bit(ATM_VF_ADDR, &vcc->flags);
  403. clear_bit(ATM_VF_READY, &vcc->flags);
  404. return;
  405. }
  406. static int print_buffer(struct sk_buff *buf)
  407. {
  408. int len,i;
  409. char msg[500];
  410. char item[10];
  411. len = buf->len;
  412. for (i = 0; i < len; i++){
  413. if(i % 8 == 0)
  414. sprintf(msg, "%02X: ", i);
  415. sprintf(item,"%02X ",*(buf->data + i));
  416. strcat(msg, item);
  417. if(i % 8 == 7) {
  418. sprintf(item, "\n");
  419. strcat(msg, item);
  420. printk(KERN_DEBUG "%s", msg);
  421. }
  422. }
  423. if (i % 8 != 0) {
  424. sprintf(item, "\n");
  425. strcat(msg, item);
  426. printk(KERN_DEBUG "%s", msg);
  427. }
  428. printk(KERN_DEBUG "\n");
  429. return 0;
  430. }
  431. static void fpga_queue(struct solos_card *card, int port, struct sk_buff *skb,
  432. struct atm_vcc *vcc)
  433. {
  434. int old_len;
  435. *(void **)skb->cb = vcc;
  436. spin_lock(&card->tx_queue_lock);
  437. old_len = skb_queue_len(&card->tx_queue[port]);
  438. skb_queue_tail(&card->tx_queue[port], skb);
  439. spin_unlock(&card->tx_queue_lock);
  440. /* If TX might need to be started, do so */
  441. if (!old_len)
  442. fpga_tx(card);
  443. }
  444. static int fpga_tx(struct solos_card *card)
  445. {
  446. uint32_t tx_pending;
  447. uint32_t tx_started = 0;
  448. struct sk_buff *skb;
  449. struct atm_vcc *vcc;
  450. unsigned char port;
  451. unsigned long flags;
  452. spin_lock_irqsave(&card->tx_lock, flags);
  453. tx_pending = ioread32(card->config_regs + FLAGS_ADDR);
  454. dev_vdbg(&card->dev->dev, "TX Flags are %X\n", tx_pending);
  455. for (port = 0; port < card->nr_ports; port++) {
  456. if (!(tx_pending & (1 << port))) {
  457. spin_lock(&card->tx_queue_lock);
  458. skb = skb_dequeue(&card->tx_queue[port]);
  459. spin_unlock(&card->tx_queue_lock);
  460. if (!skb)
  461. continue;
  462. if (atmdebug) {
  463. dev_info(&card->dev->dev, "Transmitted: port %d\n",
  464. port);
  465. print_buffer(skb);
  466. }
  467. memcpy_toio(TX_BUF(card, port), skb->data, skb->len);
  468. vcc = *(void **)skb->cb;
  469. if (vcc) {
  470. atomic_inc(&vcc->stats->tx);
  471. solos_pop(vcc, skb);
  472. } else
  473. dev_kfree_skb_irq(skb);
  474. tx_started |= 1 << port; //Set TX full flag
  475. }
  476. }
  477. if (tx_started)
  478. iowrite32(tx_started, card->config_regs + FLAGS_ADDR);
  479. spin_unlock_irqrestore(&card->tx_lock, flags);
  480. return 0;
  481. }
  482. static int psend(struct atm_vcc *vcc, struct sk_buff *skb)
  483. {
  484. struct solos_card *card = vcc->dev->dev_data;
  485. struct sk_buff *skb2 = NULL;
  486. struct pkt_hdr *header;
  487. int pktlen;
  488. //dev_dbg(&card->dev->dev, "psend called.\n");
  489. //dev_dbg(&card->dev->dev, "dev,vpi,vci = %d,%d,%d\n",SOLOS_CHAN(vcc->dev),vcc->vpi,vcc->vci);
  490. if (debug) {
  491. skb2 = atm_alloc_charge(vcc, skb->len, GFP_ATOMIC);
  492. if (skb2) {
  493. memcpy(skb2->data, skb->data, skb->len);
  494. skb_put(skb2, skb->len);
  495. vcc->push(vcc, skb2);
  496. atomic_inc(&vcc->stats->rx);
  497. }
  498. atomic_inc(&vcc->stats->tx);
  499. solos_pop(vcc, skb);
  500. return 0;
  501. }
  502. pktlen = skb->len;
  503. if (pktlen > (BUF_SIZE - sizeof(*header))) {
  504. dev_warn(&card->dev->dev, "Length of PDU is too large. Dropping PDU.\n");
  505. solos_pop(vcc, skb);
  506. return 0;
  507. }
  508. if (!skb_clone_writable(skb, sizeof(*header))) {
  509. int expand_by = 0;
  510. int ret;
  511. if (skb_headroom(skb) < sizeof(*header))
  512. expand_by = sizeof(*header) - skb_headroom(skb);
  513. ret = pskb_expand_head(skb, expand_by, 0, GFP_ATOMIC);
  514. if (ret) {
  515. dev_warn(&card->dev->dev, "pskb_expand_head failed.\n");
  516. solos_pop(vcc, skb);
  517. return ret;
  518. }
  519. }
  520. header = (void *)skb_push(skb, sizeof(*header));
  521. /* This does _not_ include the size of the header */
  522. header->size = cpu_to_le16(pktlen);
  523. header->vpi = cpu_to_le16(vcc->vpi);
  524. header->vci = cpu_to_le16(vcc->vci);
  525. header->type = cpu_to_le16(PKT_DATA);
  526. fpga_queue(card, SOLOS_CHAN(vcc->dev), skb, vcc);
  527. return 0;
  528. }
  529. static struct atmdev_ops fpga_ops = {
  530. .open = popen,
  531. .close = pclose,
  532. .ioctl = NULL,
  533. .getsockopt = NULL,
  534. .setsockopt = NULL,
  535. .send = psend,
  536. .send_oam = NULL,
  537. .phy_put = NULL,
  538. .phy_get = NULL,
  539. .change_qos = NULL,
  540. .proc_read = NULL,
  541. .owner = THIS_MODULE
  542. };
  543. static int fpga_probe(struct pci_dev *dev, const struct pci_device_id *id)
  544. {
  545. int err, i;
  546. uint16_t fpga_ver;
  547. uint8_t major_ver, minor_ver;
  548. uint32_t data32;
  549. struct solos_card *card;
  550. if (debug)
  551. return 0;
  552. card = kzalloc(sizeof(*card), GFP_KERNEL);
  553. if (!card)
  554. return -ENOMEM;
  555. card->dev = dev;
  556. init_waitqueue_head(&card->fw_wq);
  557. err = pci_enable_device(dev);
  558. if (err) {
  559. dev_warn(&dev->dev, "Failed to enable PCI device\n");
  560. goto out;
  561. }
  562. err = pci_request_regions(dev, "solos");
  563. if (err) {
  564. dev_warn(&dev->dev, "Failed to request regions\n");
  565. goto out;
  566. }
  567. card->config_regs = pci_iomap(dev, 0, CONFIG_RAM_SIZE);
  568. if (!card->config_regs) {
  569. dev_warn(&dev->dev, "Failed to ioremap config registers\n");
  570. goto out_release_regions;
  571. }
  572. card->buffers = pci_iomap(dev, 1, DATA_RAM_SIZE);
  573. if (!card->buffers) {
  574. dev_warn(&dev->dev, "Failed to ioremap data buffers\n");
  575. goto out_unmap_config;
  576. }
  577. // for(i=0;i<64 ;i+=4){
  578. // data32=ioread32(card->buffers + i);
  579. // dev_dbg(&card->dev->dev, "%08lX\n",(unsigned long)data32);
  580. // }
  581. //Fill Config Mem with zeros
  582. for(i = 0; i < 128; i += 4)
  583. iowrite32(0, card->config_regs + i);
  584. //Set RX empty flags
  585. iowrite32(0xF0, card->config_regs + FLAGS_ADDR);
  586. data32 = ioread32(card->config_regs + FPGA_VER);
  587. fpga_ver = (data32 & 0x0000FFFF);
  588. major_ver = ((data32 & 0xFF000000) >> 24);
  589. minor_ver = ((data32 & 0x00FF0000) >> 16);
  590. dev_info(&dev->dev, "Solos FPGA Version %d.%02d svn-%d\n",
  591. major_ver, minor_ver, fpga_ver);
  592. card->nr_ports = 2; /* FIXME: Detect daughterboard */
  593. pci_set_drvdata(dev, card);
  594. tasklet_init(&card->tlet, solos_bh, (unsigned long)card);
  595. spin_lock_init(&card->tx_lock);
  596. spin_lock_init(&card->tx_queue_lock);
  597. spin_lock_init(&card->cli_queue_lock);
  598. /*
  599. // Set Loopback mode
  600. data32 = 0x00010000;
  601. iowrite32(data32,card->config_regs + FLAGS_ADDR);
  602. */
  603. /*
  604. // Fill Buffers with zeros
  605. for (i = 0; i < BUF_SIZE * 8; i += 4)
  606. iowrite32(0, card->buffers + i);
  607. */
  608. /*
  609. for(i = 0; i < (BUF_SIZE * 1); i += 4)
  610. iowrite32(0x12345678, card->buffers + i + (0*BUF_SIZE));
  611. for(i = 0; i < (BUF_SIZE * 1); i += 4)
  612. iowrite32(0xabcdef98, card->buffers + i + (1*BUF_SIZE));
  613. // Read Config Memory
  614. printk(KERN_DEBUG "Reading Config MEM\n");
  615. i = 0;
  616. for(i = 0; i < 16; i++) {
  617. data32=ioread32(card->buffers + i*(BUF_SIZE/2));
  618. printk(KERN_ALERT "Addr: %lX Data: %08lX\n",
  619. (unsigned long)(addr_start + i*(BUF_SIZE/2)),
  620. (unsigned long)data32);
  621. }
  622. */
  623. //dev_dbg(&card->dev->dev, "Requesting IRQ: %d\n",dev->irq);
  624. err = request_irq(dev->irq, solos_irq, IRQF_DISABLED|IRQF_SHARED,
  625. "solos-pci", card);
  626. if (err) {
  627. dev_dbg(&card->dev->dev, "Failed to request interrupt IRQ: %d\n", dev->irq);
  628. goto out_unmap_both;
  629. }
  630. // Enable IRQs
  631. iowrite32(1, card->config_regs + IRQ_EN_ADDR);
  632. if (fpga_upgrade)
  633. flash_upgrade(card, 0);
  634. if (firmware_upgrade)
  635. flash_upgrade(card, 1);
  636. err = atm_init(card);
  637. if (err)
  638. goto out_free_irq;
  639. return 0;
  640. out_free_irq:
  641. iowrite32(0, card->config_regs + IRQ_EN_ADDR);
  642. free_irq(dev->irq, card);
  643. tasklet_kill(&card->tlet);
  644. out_unmap_both:
  645. pci_set_drvdata(dev, NULL);
  646. pci_iounmap(dev, card->config_regs);
  647. out_unmap_config:
  648. pci_iounmap(dev, card->buffers);
  649. out_release_regions:
  650. pci_release_regions(dev);
  651. out:
  652. return err;
  653. }
  654. static int atm_init(struct solos_card *card)
  655. {
  656. int i;
  657. for (i = 0; i < card->nr_ports; i++) {
  658. skb_queue_head_init(&card->tx_queue[i]);
  659. skb_queue_head_init(&card->cli_queue[i]);
  660. card->atmdev[i] = atm_dev_register("solos-pci", &fpga_ops, -1, NULL);
  661. if (!card->atmdev[i]) {
  662. dev_err(&card->dev->dev, "Could not register ATM device %d\n", i);
  663. atm_remove(card);
  664. return -ENODEV;
  665. }
  666. if (device_create_file(&card->atmdev[i]->class_dev, &dev_attr_console))
  667. dev_err(&card->dev->dev, "Could not register console for ATM device %d\n", i);
  668. dev_info(&card->dev->dev, "Registered ATM device %d\n", card->atmdev[i]->number);
  669. card->atmdev[i]->ci_range.vpi_bits = 8;
  670. card->atmdev[i]->ci_range.vci_bits = 16;
  671. card->atmdev[i]->dev_data = card;
  672. card->atmdev[i]->phy_data = (void *)(unsigned long)i;
  673. }
  674. return 0;
  675. }
  676. static void atm_remove(struct solos_card *card)
  677. {
  678. int i;
  679. for (i = 0; i < card->nr_ports; i++) {
  680. if (card->atmdev[i]) {
  681. dev_info(&card->dev->dev, "Unregistering ATM device %d\n", card->atmdev[i]->number);
  682. atm_dev_deregister(card->atmdev[i]);
  683. }
  684. }
  685. }
  686. static void fpga_remove(struct pci_dev *dev)
  687. {
  688. struct solos_card *card = pci_get_drvdata(dev);
  689. if (debug)
  690. return;
  691. atm_remove(card);
  692. dev_vdbg(&dev->dev, "Freeing IRQ\n");
  693. // Disable IRQs from FPGA
  694. iowrite32(0, card->config_regs + IRQ_EN_ADDR);
  695. free_irq(dev->irq, card);
  696. tasklet_kill(&card->tlet);
  697. // iowrite32(0x01,pciregs);
  698. dev_vdbg(&dev->dev, "Unmapping PCI resource\n");
  699. pci_iounmap(dev, card->buffers);
  700. pci_iounmap(dev, card->config_regs);
  701. dev_vdbg(&dev->dev, "Releasing PCI Region\n");
  702. pci_release_regions(dev);
  703. pci_disable_device(dev);
  704. pci_set_drvdata(dev, NULL);
  705. kfree(card);
  706. // dev_dbg(&card->dev->dev, "fpga_remove\n");
  707. return;
  708. }
  709. static struct pci_device_id fpga_pci_tbl[] __devinitdata = {
  710. { 0x10ee, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  711. { 0, }
  712. };
  713. MODULE_DEVICE_TABLE(pci,fpga_pci_tbl);
  714. static struct pci_driver fpga_driver = {
  715. .name = "solos",
  716. .id_table = fpga_pci_tbl,
  717. .probe = fpga_probe,
  718. .remove = fpga_remove,
  719. };
  720. static int __init solos_pci_init(void)
  721. {
  722. printk(KERN_INFO "Solos PCI Driver Version %s\n", VERSION);
  723. return pci_register_driver(&fpga_driver);
  724. }
  725. static void __exit solos_pci_exit(void)
  726. {
  727. pci_unregister_driver(&fpga_driver);
  728. printk(KERN_INFO "Solos PCI Driver %s Unloaded\n", VERSION);
  729. }
  730. module_init(solos_pci_init);
  731. module_exit(solos_pci_exit);