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. #define RCV_BUFFER_SIZE (16 * 1024)
  35. /* this is the physical layout of a PCL, its size is 128 bytes */
  36. struct pcl {
  37. __le32 next;
  38. __le32 async_error_next;
  39. u32 user_data;
  40. __le32 pcl_status;
  41. __le32 remaining_transfer_count;
  42. __le32 next_data_buffer;
  43. struct {
  44. __le32 control;
  45. __le32 pointer;
  46. } buffer[13];
  47. };
  48. struct packet {
  49. unsigned int length;
  50. char data[];
  51. };
  52. struct packet_buffer {
  53. char *data;
  54. size_t capacity;
  55. long total_packet_count, lost_packet_count;
  56. atomic_t size;
  57. struct packet *head, *tail;
  58. wait_queue_head_t wait;
  59. };
  60. struct pcilynx {
  61. struct pci_dev *pci_device;
  62. __iomem char *registers;
  63. struct pcl *rcv_start_pcl, *rcv_pcl;
  64. __le32 *rcv_buffer;
  65. dma_addr_t rcv_start_pcl_bus, rcv_pcl_bus, rcv_buffer_bus;
  66. spinlock_t client_list_lock;
  67. struct list_head client_list;
  68. struct miscdevice misc;
  69. struct list_head link;
  70. struct kref kref;
  71. };
  72. static inline struct pcilynx *
  73. lynx_get(struct pcilynx *lynx)
  74. {
  75. kref_get(&lynx->kref);
  76. return lynx;
  77. }
  78. static void
  79. lynx_release(struct kref *kref)
  80. {
  81. kfree(container_of(kref, struct pcilynx, kref));
  82. }
  83. static inline void
  84. lynx_put(struct pcilynx *lynx)
  85. {
  86. kref_put(&lynx->kref, lynx_release);
  87. }
  88. struct client {
  89. struct pcilynx *lynx;
  90. u32 tcode_mask;
  91. struct packet_buffer buffer;
  92. struct list_head link;
  93. };
  94. static DEFINE_MUTEX(card_mutex);
  95. static LIST_HEAD(card_list);
  96. static int
  97. packet_buffer_init(struct packet_buffer *buffer, size_t capacity)
  98. {
  99. buffer->data = kmalloc(capacity, GFP_KERNEL);
  100. if (buffer->data == NULL)
  101. return -ENOMEM;
  102. buffer->head = (struct packet *) buffer->data;
  103. buffer->tail = (struct packet *) buffer->data;
  104. buffer->capacity = capacity;
  105. buffer->lost_packet_count = 0;
  106. atomic_set(&buffer->size, 0);
  107. init_waitqueue_head(&buffer->wait);
  108. return 0;
  109. }
  110. static void
  111. packet_buffer_destroy(struct packet_buffer *buffer)
  112. {
  113. kfree(buffer->data);
  114. }
  115. static int
  116. packet_buffer_get(struct client *client, char __user *data, size_t user_length)
  117. {
  118. struct packet_buffer *buffer = &client->buffer;
  119. size_t length;
  120. char *end;
  121. if (wait_event_interruptible(buffer->wait,
  122. atomic_read(&buffer->size) > 0) ||
  123. list_empty(&client->lynx->link))
  124. return -ERESTARTSYS;
  125. if (atomic_read(&buffer->size) == 0)
  126. return -ENODEV;
  127. length = buffer->head->length;
  128. if (length > user_length)
  129. return 0;
  130. end = buffer->data + buffer->capacity;
  131. if (&buffer->head->data[length] < end) {
  132. if (copy_to_user(data, buffer->head->data, length))
  133. return -EFAULT;
  134. buffer->head = (struct packet *) &buffer->head->data[length];
  135. } else {
  136. size_t split = end - buffer->head->data;
  137. if (copy_to_user(data, buffer->head->data, split))
  138. return -EFAULT;
  139. if (copy_to_user(data + split, buffer->data, length - split))
  140. return -EFAULT;
  141. buffer->head = (struct packet *) &buffer->data[length - split];
  142. }
  143. /*
  144. * Decrease buffer->size as the last thing, since this is what
  145. * keeps the interrupt from overwriting the packet we are
  146. * retrieving from the buffer.
  147. */
  148. atomic_sub(sizeof(struct packet) + length, &buffer->size);
  149. return length;
  150. }
  151. static void
  152. packet_buffer_put(struct packet_buffer *buffer, void *data, size_t length)
  153. {
  154. char *end;
  155. buffer->total_packet_count++;
  156. if (buffer->capacity <
  157. atomic_read(&buffer->size) + sizeof(struct packet) + length) {
  158. buffer->lost_packet_count++;
  159. return;
  160. }
  161. end = buffer->data + buffer->capacity;
  162. buffer->tail->length = length;
  163. if (&buffer->tail->data[length] < end) {
  164. memcpy(buffer->tail->data, data, length);
  165. buffer->tail = (struct packet *) &buffer->tail->data[length];
  166. } else {
  167. size_t split = end - buffer->tail->data;
  168. memcpy(buffer->tail->data, data, split);
  169. memcpy(buffer->data, data + split, length - split);
  170. buffer->tail = (struct packet *) &buffer->data[length - split];
  171. }
  172. /* Finally, adjust buffer size and wake up userspace reader. */
  173. atomic_add(sizeof(struct packet) + length, &buffer->size);
  174. wake_up_interruptible(&buffer->wait);
  175. }
  176. static inline void
  177. reg_write(struct pcilynx *lynx, int offset, u32 data)
  178. {
  179. writel(data, lynx->registers + offset);
  180. }
  181. static inline u32
  182. reg_read(struct pcilynx *lynx, int offset)
  183. {
  184. return readl(lynx->registers + offset);
  185. }
  186. static inline void
  187. reg_set_bits(struct pcilynx *lynx, int offset, u32 mask)
  188. {
  189. reg_write(lynx, offset, (reg_read(lynx, offset) | mask));
  190. }
  191. /*
  192. * Maybe the pcl programs could be set up to just append data instead
  193. * of using a whole packet.
  194. */
  195. static inline void
  196. run_pcl(struct pcilynx *lynx, dma_addr_t pcl_bus,
  197. int dmachan)
  198. {
  199. reg_write(lynx, DMA0_CURRENT_PCL + dmachan * 0x20, pcl_bus);
  200. reg_write(lynx, DMA0_CHAN_CTRL + dmachan * 0x20,
  201. DMA_CHAN_CTRL_ENABLE | DMA_CHAN_CTRL_LINK);
  202. }
  203. static int
  204. set_phy_reg(struct pcilynx *lynx, int addr, int val)
  205. {
  206. if (addr > 15) {
  207. dev_err(&lynx->pci_device->dev,
  208. "PHY register address %d out of range\n", addr);
  209. return -1;
  210. }
  211. if (val > 0xff) {
  212. dev_err(&lynx->pci_device->dev,
  213. "PHY register value %d out of range\n", val);
  214. return -1;
  215. }
  216. reg_write(lynx, LINK_PHY, LINK_PHY_WRITE |
  217. LINK_PHY_ADDR(addr) | LINK_PHY_WDATA(val));
  218. return 0;
  219. }
  220. static int
  221. nosy_open(struct inode *inode, struct file *file)
  222. {
  223. int minor = iminor(inode);
  224. struct client *client;
  225. struct pcilynx *tmp, *lynx = NULL;
  226. mutex_lock(&card_mutex);
  227. list_for_each_entry(tmp, &card_list, link)
  228. if (tmp->misc.minor == minor) {
  229. lynx = lynx_get(tmp);
  230. break;
  231. }
  232. mutex_unlock(&card_mutex);
  233. if (lynx == NULL)
  234. return -ENODEV;
  235. client = kmalloc_obj(*client);
  236. if (client == NULL)
  237. goto fail;
  238. client->tcode_mask = ~0;
  239. client->lynx = lynx;
  240. INIT_LIST_HEAD(&client->link);
  241. if (packet_buffer_init(&client->buffer, 128 * 1024) < 0)
  242. goto fail;
  243. file->private_data = client;
  244. return stream_open(inode, file);
  245. fail:
  246. kfree(client);
  247. lynx_put(lynx);
  248. return -ENOMEM;
  249. }
  250. static int
  251. nosy_release(struct inode *inode, struct file *file)
  252. {
  253. struct client *client = file->private_data;
  254. struct pcilynx *lynx = client->lynx;
  255. spin_lock_irq(&lynx->client_list_lock);
  256. list_del_init(&client->link);
  257. spin_unlock_irq(&lynx->client_list_lock);
  258. packet_buffer_destroy(&client->buffer);
  259. kfree(client);
  260. lynx_put(lynx);
  261. return 0;
  262. }
  263. static __poll_t
  264. nosy_poll(struct file *file, poll_table *pt)
  265. {
  266. struct client *client = file->private_data;
  267. __poll_t ret = 0;
  268. poll_wait(file, &client->buffer.wait, pt);
  269. if (atomic_read(&client->buffer.size) > 0)
  270. ret = EPOLLIN | EPOLLRDNORM;
  271. if (list_empty(&client->lynx->link))
  272. ret |= EPOLLHUP;
  273. return ret;
  274. }
  275. static ssize_t
  276. nosy_read(struct file *file, char __user *buffer, size_t count, loff_t *offset)
  277. {
  278. struct client *client = file->private_data;
  279. return packet_buffer_get(client, buffer, count);
  280. }
  281. static long
  282. nosy_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  283. {
  284. struct client *client = file->private_data;
  285. spinlock_t *client_list_lock = &client->lynx->client_list_lock;
  286. struct nosy_stats stats;
  287. int ret;
  288. switch (cmd) {
  289. case NOSY_IOC_GET_STATS:
  290. spin_lock_irq(client_list_lock);
  291. stats.total_packet_count = client->buffer.total_packet_count;
  292. stats.lost_packet_count = client->buffer.lost_packet_count;
  293. spin_unlock_irq(client_list_lock);
  294. if (copy_to_user((void __user *) arg, &stats, sizeof stats))
  295. return -EFAULT;
  296. else
  297. return 0;
  298. case NOSY_IOC_START:
  299. ret = -EBUSY;
  300. spin_lock_irq(client_list_lock);
  301. if (list_empty(&client->link)) {
  302. list_add_tail(&client->link, &client->lynx->client_list);
  303. ret = 0;
  304. }
  305. spin_unlock_irq(client_list_lock);
  306. return ret;
  307. case NOSY_IOC_STOP:
  308. spin_lock_irq(client_list_lock);
  309. list_del_init(&client->link);
  310. spin_unlock_irq(client_list_lock);
  311. return 0;
  312. case NOSY_IOC_FILTER:
  313. spin_lock_irq(client_list_lock);
  314. client->tcode_mask = arg;
  315. spin_unlock_irq(client_list_lock);
  316. return 0;
  317. default:
  318. return -EINVAL;
  319. /* Flush buffer, configure filter. */
  320. }
  321. }
  322. static const struct file_operations nosy_ops = {
  323. .owner = THIS_MODULE,
  324. .read = nosy_read,
  325. .unlocked_ioctl = nosy_ioctl,
  326. .poll = nosy_poll,
  327. .open = nosy_open,
  328. .release = nosy_release,
  329. };
  330. #define PHY_PACKET_SIZE 12 /* 1 payload, 1 inverse, 1 ack = 3 quadlets */
  331. static void
  332. packet_irq_handler(struct pcilynx *lynx)
  333. {
  334. struct client *client;
  335. u32 tcode_mask, tcode, timestamp;
  336. size_t length;
  337. struct timespec64 ts64;
  338. /* FIXME: Also report rcv_speed. */
  339. length = __le32_to_cpu(lynx->rcv_pcl->pcl_status) & 0x00001fff;
  340. tcode = __le32_to_cpu(lynx->rcv_buffer[1]) >> 4 & 0xf;
  341. ktime_get_real_ts64(&ts64);
  342. timestamp = ts64.tv_nsec / NSEC_PER_USEC;
  343. lynx->rcv_buffer[0] = (__force __le32)timestamp;
  344. if (length == PHY_PACKET_SIZE)
  345. tcode_mask = 1 << TCODE_PHY_PACKET;
  346. else
  347. tcode_mask = 1 << tcode;
  348. spin_lock(&lynx->client_list_lock);
  349. list_for_each_entry(client, &lynx->client_list, link)
  350. if (client->tcode_mask & tcode_mask)
  351. packet_buffer_put(&client->buffer,
  352. lynx->rcv_buffer, length + 4);
  353. spin_unlock(&lynx->client_list_lock);
  354. }
  355. static void
  356. bus_reset_irq_handler(struct pcilynx *lynx)
  357. {
  358. struct client *client;
  359. struct timespec64 ts64;
  360. u32 timestamp;
  361. ktime_get_real_ts64(&ts64);
  362. timestamp = ts64.tv_nsec / NSEC_PER_USEC;
  363. spin_lock(&lynx->client_list_lock);
  364. list_for_each_entry(client, &lynx->client_list, link)
  365. packet_buffer_put(&client->buffer, &timestamp, 4);
  366. spin_unlock(&lynx->client_list_lock);
  367. }
  368. static irqreturn_t
  369. irq_handler(int irq, void *device)
  370. {
  371. struct pcilynx *lynx = device;
  372. u32 pci_int_status;
  373. pci_int_status = reg_read(lynx, PCI_INT_STATUS);
  374. if (pci_int_status == ~0)
  375. /* Card was ejected. */
  376. return IRQ_NONE;
  377. if ((pci_int_status & PCI_INT_INT_PEND) == 0)
  378. /* Not our interrupt, bail out quickly. */
  379. return IRQ_NONE;
  380. if ((pci_int_status & PCI_INT_P1394_INT) != 0) {
  381. u32 link_int_status;
  382. link_int_status = reg_read(lynx, LINK_INT_STATUS);
  383. reg_write(lynx, LINK_INT_STATUS, link_int_status);
  384. if ((link_int_status & LINK_INT_PHY_BUSRESET) > 0)
  385. bus_reset_irq_handler(lynx);
  386. }
  387. /* Clear the PCI_INT_STATUS register only after clearing the
  388. * LINK_INT_STATUS register; otherwise the PCI_INT_P1394 will
  389. * be set again immediately. */
  390. reg_write(lynx, PCI_INT_STATUS, pci_int_status);
  391. if ((pci_int_status & PCI_INT_DMA0_HLT) > 0) {
  392. packet_irq_handler(lynx);
  393. run_pcl(lynx, lynx->rcv_start_pcl_bus, 0);
  394. }
  395. return IRQ_HANDLED;
  396. }
  397. static void
  398. remove_card(struct pci_dev *dev)
  399. {
  400. struct pcilynx *lynx = pci_get_drvdata(dev);
  401. struct client *client;
  402. mutex_lock(&card_mutex);
  403. list_del_init(&lynx->link);
  404. misc_deregister(&lynx->misc);
  405. mutex_unlock(&card_mutex);
  406. reg_write(lynx, PCI_INT_ENABLE, 0);
  407. free_irq(lynx->pci_device->irq, lynx);
  408. spin_lock_irq(&lynx->client_list_lock);
  409. list_for_each_entry(client, &lynx->client_list, link)
  410. wake_up_interruptible(&client->buffer.wait);
  411. spin_unlock_irq(&lynx->client_list_lock);
  412. dma_free_coherent(&lynx->pci_device->dev, sizeof(struct pcl),
  413. lynx->rcv_start_pcl, lynx->rcv_start_pcl_bus);
  414. dma_free_coherent(&lynx->pci_device->dev, sizeof(struct pcl),
  415. lynx->rcv_pcl, lynx->rcv_pcl_bus);
  416. dma_free_coherent(&lynx->pci_device->dev, RCV_BUFFER_SIZE,
  417. lynx->rcv_buffer, lynx->rcv_buffer_bus);
  418. iounmap(lynx->registers);
  419. pci_disable_device(dev);
  420. lynx_put(lynx);
  421. }
  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_obj(*lynx);
  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, RCV_BUFFER_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");