nosy.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. /*
  2. * nosy - Snoop mode driver for TI PCILynx 1394 controllers
  3. * Copyright (C) 2002-2007 Kristian Høgsberg
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software Foundation,
  17. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. */
  19. #include <linux/device.h>
  20. #include <linux/errno.h>
  21. #include <linux/fs.h>
  22. #include <linux/init.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/io.h>
  25. #include <linux/kernel.h>
  26. #include <linux/kref.h>
  27. #include <linux/miscdevice.h>
  28. #include <linux/module.h>
  29. #include <linux/mutex.h>
  30. #include <linux/pci.h>
  31. #include <linux/poll.h>
  32. #include <linux/sched.h> /* required for linux/wait.h */
  33. #include <linux/slab.h>
  34. #include <linux/spinlock.h>
  35. #include <linux/timex.h>
  36. #include <linux/uaccess.h>
  37. #include <linux/wait.h>
  38. #include <linux/dma-mapping.h>
  39. #include <linux/atomic.h>
  40. #include <asm/byteorder.h>
  41. #include "nosy.h"
  42. #include "nosy-user.h"
  43. #define TCODE_PHY_PACKET 0x10
  44. #define PCI_DEVICE_ID_TI_PCILYNX 0x8000
  45. static char driver_name[] = KBUILD_MODNAME;
  46. /* this is the physical layout of a PCL, its size is 128 bytes */
  47. struct pcl {
  48. __le32 next;
  49. __le32 async_error_next;
  50. u32 user_data;
  51. __le32 pcl_status;
  52. __le32 remaining_transfer_count;
  53. __le32 next_data_buffer;
  54. struct {
  55. __le32 control;
  56. __le32 pointer;
  57. } buffer[13];
  58. };
  59. struct packet {
  60. unsigned int length;
  61. char data[0];
  62. };
  63. struct packet_buffer {
  64. char *data;
  65. size_t capacity;
  66. long total_packet_count, lost_packet_count;
  67. atomic_t size;
  68. struct packet *head, *tail;
  69. wait_queue_head_t wait;
  70. };
  71. struct pcilynx {
  72. struct pci_dev *pci_device;
  73. __iomem char *registers;
  74. struct pcl *rcv_start_pcl, *rcv_pcl;
  75. __le32 *rcv_buffer;
  76. dma_addr_t rcv_start_pcl_bus, rcv_pcl_bus, rcv_buffer_bus;
  77. spinlock_t client_list_lock;
  78. struct list_head client_list;
  79. struct miscdevice misc;
  80. struct list_head link;
  81. struct kref kref;
  82. };
  83. static inline struct pcilynx *
  84. lynx_get(struct pcilynx *lynx)
  85. {
  86. kref_get(&lynx->kref);
  87. return lynx;
  88. }
  89. static void
  90. lynx_release(struct kref *kref)
  91. {
  92. kfree(container_of(kref, struct pcilynx, kref));
  93. }
  94. static inline void
  95. lynx_put(struct pcilynx *lynx)
  96. {
  97. kref_put(&lynx->kref, lynx_release);
  98. }
  99. struct client {
  100. struct pcilynx *lynx;
  101. u32 tcode_mask;
  102. struct packet_buffer buffer;
  103. struct list_head link;
  104. };
  105. static DEFINE_MUTEX(card_mutex);
  106. static LIST_HEAD(card_list);
  107. static int
  108. packet_buffer_init(struct packet_buffer *buffer, size_t capacity)
  109. {
  110. buffer->data = kmalloc(capacity, GFP_KERNEL);
  111. if (buffer->data == NULL)
  112. return -ENOMEM;
  113. buffer->head = (struct packet *) buffer->data;
  114. buffer->tail = (struct packet *) buffer->data;
  115. buffer->capacity = capacity;
  116. buffer->lost_packet_count = 0;
  117. atomic_set(&buffer->size, 0);
  118. init_waitqueue_head(&buffer->wait);
  119. return 0;
  120. }
  121. static void
  122. packet_buffer_destroy(struct packet_buffer *buffer)
  123. {
  124. kfree(buffer->data);
  125. }
  126. static int
  127. packet_buffer_get(struct client *client, char __user *data, size_t user_length)
  128. {
  129. struct packet_buffer *buffer = &client->buffer;
  130. size_t length;
  131. char *end;
  132. if (wait_event_interruptible(buffer->wait,
  133. atomic_read(&buffer->size) > 0) ||
  134. list_empty(&client->lynx->link))
  135. return -ERESTARTSYS;
  136. if (atomic_read(&buffer->size) == 0)
  137. return -ENODEV;
  138. /* FIXME: Check length <= user_length. */
  139. end = buffer->data + buffer->capacity;
  140. length = buffer->head->length;
  141. if (&buffer->head->data[length] < end) {
  142. if (copy_to_user(data, buffer->head->data, length))
  143. return -EFAULT;
  144. buffer->head = (struct packet *) &buffer->head->data[length];
  145. } else {
  146. size_t split = end - buffer->head->data;
  147. if (copy_to_user(data, buffer->head->data, split))
  148. return -EFAULT;
  149. if (copy_to_user(data + split, buffer->data, length - split))
  150. return -EFAULT;
  151. buffer->head = (struct packet *) &buffer->data[length - split];
  152. }
  153. /*
  154. * Decrease buffer->size as the last thing, since this is what
  155. * keeps the interrupt from overwriting the packet we are
  156. * retrieving from the buffer.
  157. */
  158. atomic_sub(sizeof(struct packet) + length, &buffer->size);
  159. return length;
  160. }
  161. static void
  162. packet_buffer_put(struct packet_buffer *buffer, void *data, size_t length)
  163. {
  164. char *end;
  165. buffer->total_packet_count++;
  166. if (buffer->capacity <
  167. atomic_read(&buffer->size) + sizeof(struct packet) + length) {
  168. buffer->lost_packet_count++;
  169. return;
  170. }
  171. end = buffer->data + buffer->capacity;
  172. buffer->tail->length = length;
  173. if (&buffer->tail->data[length] < end) {
  174. memcpy(buffer->tail->data, data, length);
  175. buffer->tail = (struct packet *) &buffer->tail->data[length];
  176. } else {
  177. size_t split = end - buffer->tail->data;
  178. memcpy(buffer->tail->data, data, split);
  179. memcpy(buffer->data, data + split, length - split);
  180. buffer->tail = (struct packet *) &buffer->data[length - split];
  181. }
  182. /* Finally, adjust buffer size and wake up userspace reader. */
  183. atomic_add(sizeof(struct packet) + length, &buffer->size);
  184. wake_up_interruptible(&buffer->wait);
  185. }
  186. static inline void
  187. reg_write(struct pcilynx *lynx, int offset, u32 data)
  188. {
  189. writel(data, lynx->registers + offset);
  190. }
  191. static inline u32
  192. reg_read(struct pcilynx *lynx, int offset)
  193. {
  194. return readl(lynx->registers + offset);
  195. }
  196. static inline void
  197. reg_set_bits(struct pcilynx *lynx, int offset, u32 mask)
  198. {
  199. reg_write(lynx, offset, (reg_read(lynx, offset) | mask));
  200. }
  201. /*
  202. * Maybe the pcl programs could be set up to just append data instead
  203. * of using a whole packet.
  204. */
  205. static inline void
  206. run_pcl(struct pcilynx *lynx, dma_addr_t pcl_bus,
  207. int dmachan)
  208. {
  209. reg_write(lynx, DMA0_CURRENT_PCL + dmachan * 0x20, pcl_bus);
  210. reg_write(lynx, DMA0_CHAN_CTRL + dmachan * 0x20,
  211. DMA_CHAN_CTRL_ENABLE | DMA_CHAN_CTRL_LINK);
  212. }
  213. static int
  214. set_phy_reg(struct pcilynx *lynx, int addr, int val)
  215. {
  216. if (addr > 15) {
  217. dev_err(&lynx->pci_device->dev,
  218. "PHY register address %d out of range\n", addr);
  219. return -1;
  220. }
  221. if (val > 0xff) {
  222. dev_err(&lynx->pci_device->dev,
  223. "PHY register value %d out of range\n", val);
  224. return -1;
  225. }
  226. reg_write(lynx, LINK_PHY, LINK_PHY_WRITE |
  227. LINK_PHY_ADDR(addr) | LINK_PHY_WDATA(val));
  228. return 0;
  229. }
  230. static int
  231. nosy_open(struct inode *inode, struct file *file)
  232. {
  233. int minor = iminor(inode);
  234. struct client *client;
  235. struct pcilynx *tmp, *lynx = NULL;
  236. mutex_lock(&card_mutex);
  237. list_for_each_entry(tmp, &card_list, link)
  238. if (tmp->misc.minor == minor) {
  239. lynx = lynx_get(tmp);
  240. break;
  241. }
  242. mutex_unlock(&card_mutex);
  243. if (lynx == NULL)
  244. return -ENODEV;
  245. client = kmalloc(sizeof *client, GFP_KERNEL);
  246. if (client == NULL)
  247. goto fail;
  248. client->tcode_mask = ~0;
  249. client->lynx = lynx;
  250. INIT_LIST_HEAD(&client->link);
  251. if (packet_buffer_init(&client->buffer, 128 * 1024) < 0)
  252. goto fail;
  253. file->private_data = client;
  254. return nonseekable_open(inode, file);
  255. fail:
  256. kfree(client);
  257. lynx_put(lynx);
  258. return -ENOMEM;
  259. }
  260. static int
  261. nosy_release(struct inode *inode, struct file *file)
  262. {
  263. struct client *client = file->private_data;
  264. struct pcilynx *lynx = client->lynx;
  265. spin_lock_irq(&lynx->client_list_lock);
  266. list_del_init(&client->link);
  267. spin_unlock_irq(&lynx->client_list_lock);
  268. packet_buffer_destroy(&client->buffer);
  269. kfree(client);
  270. lynx_put(lynx);
  271. return 0;
  272. }
  273. static unsigned int
  274. nosy_poll(struct file *file, poll_table *pt)
  275. {
  276. struct client *client = file->private_data;
  277. unsigned int ret = 0;
  278. poll_wait(file, &client->buffer.wait, pt);
  279. if (atomic_read(&client->buffer.size) > 0)
  280. ret = POLLIN | POLLRDNORM;
  281. if (list_empty(&client->lynx->link))
  282. ret |= POLLHUP;
  283. return ret;
  284. }
  285. static ssize_t
  286. nosy_read(struct file *file, char __user *buffer, size_t count, loff_t *offset)
  287. {
  288. struct client *client = file->private_data;
  289. return packet_buffer_get(client, buffer, count);
  290. }
  291. static long
  292. nosy_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  293. {
  294. struct client *client = file->private_data;
  295. spinlock_t *client_list_lock = &client->lynx->client_list_lock;
  296. struct nosy_stats stats;
  297. switch (cmd) {
  298. case NOSY_IOC_GET_STATS:
  299. spin_lock_irq(client_list_lock);
  300. stats.total_packet_count = client->buffer.total_packet_count;
  301. stats.lost_packet_count = client->buffer.lost_packet_count;
  302. spin_unlock_irq(client_list_lock);
  303. if (copy_to_user((void __user *) arg, &stats, sizeof stats))
  304. return -EFAULT;
  305. else
  306. return 0;
  307. case NOSY_IOC_START:
  308. spin_lock_irq(client_list_lock);
  309. list_add_tail(&client->link, &client->lynx->client_list);
  310. spin_unlock_irq(client_list_lock);
  311. return 0;
  312. case NOSY_IOC_STOP:
  313. spin_lock_irq(client_list_lock);
  314. list_del_init(&client->link);
  315. spin_unlock_irq(client_list_lock);
  316. return 0;
  317. case NOSY_IOC_FILTER:
  318. spin_lock_irq(client_list_lock);
  319. client->tcode_mask = arg;
  320. spin_unlock_irq(client_list_lock);
  321. return 0;
  322. default:
  323. return -EINVAL;
  324. /* Flush buffer, configure filter. */
  325. }
  326. }
  327. static const struct file_operations nosy_ops = {
  328. .owner = THIS_MODULE,
  329. .read = nosy_read,
  330. .unlocked_ioctl = nosy_ioctl,
  331. .poll = nosy_poll,
  332. .open = nosy_open,
  333. .release = nosy_release,
  334. };
  335. #define PHY_PACKET_SIZE 12 /* 1 payload, 1 inverse, 1 ack = 3 quadlets */
  336. static void
  337. packet_irq_handler(struct pcilynx *lynx)
  338. {
  339. struct client *client;
  340. u32 tcode_mask, tcode;
  341. size_t length;
  342. struct timeval tv;
  343. /* FIXME: Also report rcv_speed. */
  344. length = __le32_to_cpu(lynx->rcv_pcl->pcl_status) & 0x00001fff;
  345. tcode = __le32_to_cpu(lynx->rcv_buffer[1]) >> 4 & 0xf;
  346. do_gettimeofday(&tv);
  347. lynx->rcv_buffer[0] = (__force __le32)tv.tv_usec;
  348. if (length == PHY_PACKET_SIZE)
  349. tcode_mask = 1 << TCODE_PHY_PACKET;
  350. else
  351. tcode_mask = 1 << tcode;
  352. spin_lock(&lynx->client_list_lock);
  353. list_for_each_entry(client, &lynx->client_list, link)
  354. if (client->tcode_mask & tcode_mask)
  355. packet_buffer_put(&client->buffer,
  356. lynx->rcv_buffer, length + 4);
  357. spin_unlock(&lynx->client_list_lock);
  358. }
  359. static void
  360. bus_reset_irq_handler(struct pcilynx *lynx)
  361. {
  362. struct client *client;
  363. struct timeval tv;
  364. do_gettimeofday(&tv);
  365. spin_lock(&lynx->client_list_lock);
  366. list_for_each_entry(client, &lynx->client_list, link)
  367. packet_buffer_put(&client->buffer, &tv.tv_usec, 4);
  368. spin_unlock(&lynx->client_list_lock);
  369. }
  370. static irqreturn_t
  371. irq_handler(int irq, void *device)
  372. {
  373. struct pcilynx *lynx = device;
  374. u32 pci_int_status;
  375. pci_int_status = reg_read(lynx, PCI_INT_STATUS);
  376. if (pci_int_status == ~0)
  377. /* Card was ejected. */
  378. return IRQ_NONE;
  379. if ((pci_int_status & PCI_INT_INT_PEND) == 0)
  380. /* Not our interrupt, bail out quickly. */
  381. return IRQ_NONE;
  382. if ((pci_int_status & PCI_INT_P1394_INT) != 0) {
  383. u32 link_int_status;
  384. link_int_status = reg_read(lynx, LINK_INT_STATUS);
  385. reg_write(lynx, LINK_INT_STATUS, link_int_status);
  386. if ((link_int_status & LINK_INT_PHY_BUSRESET) > 0)
  387. bus_reset_irq_handler(lynx);
  388. }
  389. /* Clear the PCI_INT_STATUS register only after clearing the
  390. * LINK_INT_STATUS register; otherwise the PCI_INT_P1394 will
  391. * be set again immediately. */
  392. reg_write(lynx, PCI_INT_STATUS, pci_int_status);
  393. if ((pci_int_status & PCI_INT_DMA0_HLT) > 0) {
  394. packet_irq_handler(lynx);
  395. run_pcl(lynx, lynx->rcv_start_pcl_bus, 0);
  396. }
  397. return IRQ_HANDLED;
  398. }
  399. static void
  400. remove_card(struct pci_dev *dev)
  401. {
  402. struct pcilynx *lynx = pci_get_drvdata(dev);
  403. struct client *client;
  404. mutex_lock(&card_mutex);
  405. list_del_init(&lynx->link);
  406. misc_deregister(&lynx->misc);
  407. mutex_unlock(&card_mutex);
  408. reg_write(lynx, PCI_INT_ENABLE, 0);
  409. free_irq(lynx->pci_device->irq, lynx);
  410. spin_lock_irq(&lynx->client_list_lock);
  411. list_for_each_entry(client, &lynx->client_list, link)
  412. wake_up_interruptible(&client->buffer.wait);
  413. spin_unlock_irq(&lynx->client_list_lock);
  414. pci_free_consistent(lynx->pci_device, sizeof(struct pcl),
  415. lynx->rcv_start_pcl, lynx->rcv_start_pcl_bus);
  416. pci_free_consistent(lynx->pci_device, sizeof(struct pcl),
  417. lynx->rcv_pcl, lynx->rcv_pcl_bus);
  418. pci_free_consistent(lynx->pci_device, PAGE_SIZE,
  419. lynx->rcv_buffer, lynx->rcv_buffer_bus);
  420. iounmap(lynx->registers);
  421. pci_disable_device(dev);
  422. lynx_put(lynx);
  423. }
  424. #define RCV_BUFFER_SIZE (16 * 1024)
  425. static int
  426. add_card(struct pci_dev *dev, const struct pci_device_id *unused)
  427. {
  428. struct pcilynx *lynx;
  429. u32 p, end;
  430. int ret, i;
  431. if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) {
  432. dev_err(&dev->dev,
  433. "DMA address limits not supported for PCILynx hardware\n");
  434. return -ENXIO;
  435. }
  436. if (pci_enable_device(dev)) {
  437. dev_err(&dev->dev, "Failed to enable PCILynx hardware\n");
  438. return -ENXIO;
  439. }
  440. pci_set_master(dev);
  441. lynx = kzalloc(sizeof *lynx, GFP_KERNEL);
  442. if (lynx == NULL) {
  443. dev_err(&dev->dev, "Failed to allocate control structure\n");
  444. ret = -ENOMEM;
  445. goto fail_disable;
  446. }
  447. lynx->pci_device = dev;
  448. pci_set_drvdata(dev, lynx);
  449. spin_lock_init(&lynx->client_list_lock);
  450. INIT_LIST_HEAD(&lynx->client_list);
  451. kref_init(&lynx->kref);
  452. lynx->registers = ioremap_nocache(pci_resource_start(dev, 0),
  453. PCILYNX_MAX_REGISTER);
  454. lynx->rcv_start_pcl = pci_alloc_consistent(lynx->pci_device,
  455. sizeof(struct pcl), &lynx->rcv_start_pcl_bus);
  456. lynx->rcv_pcl = pci_alloc_consistent(lynx->pci_device,
  457. sizeof(struct pcl), &lynx->rcv_pcl_bus);
  458. lynx->rcv_buffer = pci_alloc_consistent(lynx->pci_device,
  459. RCV_BUFFER_SIZE, &lynx->rcv_buffer_bus);
  460. if (lynx->rcv_start_pcl == NULL ||
  461. lynx->rcv_pcl == NULL ||
  462. lynx->rcv_buffer == NULL) {
  463. dev_err(&dev->dev, "Failed to allocate receive buffer\n");
  464. ret = -ENOMEM;
  465. goto fail_deallocate;
  466. }
  467. lynx->rcv_start_pcl->next = cpu_to_le32(lynx->rcv_pcl_bus);
  468. lynx->rcv_pcl->next = cpu_to_le32(PCL_NEXT_INVALID);
  469. lynx->rcv_pcl->async_error_next = cpu_to_le32(PCL_NEXT_INVALID);
  470. lynx->rcv_pcl->buffer[0].control =
  471. cpu_to_le32(PCL_CMD_RCV | PCL_BIGENDIAN | 2044);
  472. lynx->rcv_pcl->buffer[0].pointer =
  473. cpu_to_le32(lynx->rcv_buffer_bus + 4);
  474. p = lynx->rcv_buffer_bus + 2048;
  475. end = lynx->rcv_buffer_bus + RCV_BUFFER_SIZE;
  476. for (i = 1; p < end; i++, p += 2048) {
  477. lynx->rcv_pcl->buffer[i].control =
  478. cpu_to_le32(PCL_CMD_RCV | PCL_BIGENDIAN | 2048);
  479. lynx->rcv_pcl->buffer[i].pointer = cpu_to_le32(p);
  480. }
  481. lynx->rcv_pcl->buffer[i - 1].control |= cpu_to_le32(PCL_LAST_BUFF);
  482. reg_set_bits(lynx, MISC_CONTROL, MISC_CONTROL_SWRESET);
  483. /* Fix buggy cards with autoboot pin not tied low: */
  484. reg_write(lynx, DMA0_CHAN_CTRL, 0);
  485. reg_write(lynx, DMA_GLOBAL_REGISTER, 0x00 << 24);
  486. #if 0
  487. /* now, looking for PHY register set */
  488. if ((get_phy_reg(lynx, 2) & 0xe0) == 0xe0) {
  489. lynx->phyic.reg_1394a = 1;
  490. PRINT(KERN_INFO, lynx->id,
  491. "found 1394a conform PHY (using extended register set)");
  492. lynx->phyic.vendor = get_phy_vendorid(lynx);
  493. lynx->phyic.product = get_phy_productid(lynx);
  494. } else {
  495. lynx->phyic.reg_1394a = 0;
  496. PRINT(KERN_INFO, lynx->id, "found old 1394 PHY");
  497. }
  498. #endif
  499. /* Setup the general receive FIFO max size. */
  500. reg_write(lynx, FIFO_SIZES, 255);
  501. reg_set_bits(lynx, PCI_INT_ENABLE, PCI_INT_DMA_ALL);
  502. reg_write(lynx, LINK_INT_ENABLE,
  503. LINK_INT_PHY_TIME_OUT | LINK_INT_PHY_REG_RCVD |
  504. LINK_INT_PHY_BUSRESET | LINK_INT_IT_STUCK |
  505. LINK_INT_AT_STUCK | LINK_INT_SNTRJ |
  506. LINK_INT_TC_ERR | LINK_INT_GRF_OVER_FLOW |
  507. LINK_INT_ITF_UNDER_FLOW | LINK_INT_ATF_UNDER_FLOW);
  508. /* Disable the L flag in self ID packets. */
  509. set_phy_reg(lynx, 4, 0);
  510. /* Put this baby into snoop mode */
  511. reg_set_bits(lynx, LINK_CONTROL, LINK_CONTROL_SNOOP_ENABLE);
  512. run_pcl(lynx, lynx->rcv_start_pcl_bus, 0);
  513. if (request_irq(dev->irq, irq_handler, IRQF_SHARED,
  514. driver_name, lynx)) {
  515. dev_err(&dev->dev,
  516. "Failed to allocate shared interrupt %d\n", dev->irq);
  517. ret = -EIO;
  518. goto fail_deallocate;
  519. }
  520. lynx->misc.parent = &dev->dev;
  521. lynx->misc.minor = MISC_DYNAMIC_MINOR;
  522. lynx->misc.name = "nosy";
  523. lynx->misc.fops = &nosy_ops;
  524. mutex_lock(&card_mutex);
  525. ret = misc_register(&lynx->misc);
  526. if (ret) {
  527. dev_err(&dev->dev, "Failed to register misc char device\n");
  528. mutex_unlock(&card_mutex);
  529. goto fail_free_irq;
  530. }
  531. list_add_tail(&lynx->link, &card_list);
  532. mutex_unlock(&card_mutex);
  533. dev_info(&dev->dev,
  534. "Initialized PCILynx IEEE1394 card, irq=%d\n", dev->irq);
  535. return 0;
  536. fail_free_irq:
  537. reg_write(lynx, PCI_INT_ENABLE, 0);
  538. free_irq(lynx->pci_device->irq, lynx);
  539. fail_deallocate:
  540. if (lynx->rcv_start_pcl)
  541. pci_free_consistent(lynx->pci_device, sizeof(struct pcl),
  542. lynx->rcv_start_pcl, lynx->rcv_start_pcl_bus);
  543. if (lynx->rcv_pcl)
  544. pci_free_consistent(lynx->pci_device, sizeof(struct pcl),
  545. lynx->rcv_pcl, lynx->rcv_pcl_bus);
  546. if (lynx->rcv_buffer)
  547. pci_free_consistent(lynx->pci_device, PAGE_SIZE,
  548. lynx->rcv_buffer, lynx->rcv_buffer_bus);
  549. iounmap(lynx->registers);
  550. kfree(lynx);
  551. fail_disable:
  552. pci_disable_device(dev);
  553. return ret;
  554. }
  555. static struct pci_device_id pci_table[] = {
  556. {
  557. .vendor = PCI_VENDOR_ID_TI,
  558. .device = PCI_DEVICE_ID_TI_PCILYNX,
  559. .subvendor = PCI_ANY_ID,
  560. .subdevice = PCI_ANY_ID,
  561. },
  562. { } /* Terminating entry */
  563. };
  564. MODULE_DEVICE_TABLE(pci, pci_table);
  565. static struct pci_driver lynx_pci_driver = {
  566. .name = driver_name,
  567. .id_table = pci_table,
  568. .probe = add_card,
  569. .remove = remove_card,
  570. };
  571. module_pci_driver(lynx_pci_driver);
  572. MODULE_AUTHOR("Kristian Hoegsberg");
  573. MODULE_DESCRIPTION("Snoop mode driver for TI pcilynx 1394 controllers");
  574. MODULE_LICENSE("GPL");