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