Linux Audio

Check our new training course

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