nosy.c 17 KB

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