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