nosy.c 17 KB

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