nosy.c 17.4 KB
Newer Older
1 2 3
/*
 * nosy - Snoop mode driver for TI PCILynx 1394 controllers
 * Copyright (C) 2002-2007 Kristian Høgsberg
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

20
#include <linux/device.h>
21
#include <linux/errno.h>
22
#include <linux/fs.h>
23
#include <linux/init.h>
24 25 26
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/kernel.h>
27
#include <linux/kref.h>
28 29
#include <linux/miscdevice.h>
#include <linux/module.h>
30
#include <linux/mutex.h>
31 32
#include <linux/pci.h>
#include <linux/poll.h>
33 34 35
#include <linux/sched.h> /* required for linux/wait.h */
#include <linux/slab.h>
#include <linux/spinlock.h>
36
#include <linux/time64.h>
37 38 39
#include <linux/timex.h>
#include <linux/uaccess.h>
#include <linux/wait.h>
40
#include <linux/dma-mapping.h>
Arun Sharma's avatar
Arun Sharma committed
41
#include <linux/atomic.h>
42
#include <asm/byteorder.h>
43 44 45 46 47 48 49

#include "nosy.h"
#include "nosy-user.h"

#define TCODE_PHY_PACKET		0x10
#define PCI_DEVICE_ID_TI_PCILYNX	0x8000

50
static char driver_name[] = KBUILD_MODNAME;
51 52 53

/* this is the physical layout of a PCL, its size is 128 bytes */
struct pcl {
54 55 56 57 58 59 60 61 62 63 64
	__le32 next;
	__le32 async_error_next;
	u32 user_data;
	__le32 pcl_status;
	__le32 remaining_transfer_count;
	__le32 next_data_buffer;
	struct {
		__le32 control;
		__le32 pointer;
	} buffer[13];
};
65 66

struct packet {
67
	unsigned int length;
68 69 70 71 72 73 74 75
	char data[0];
};

struct packet_buffer {
	char *data;
	size_t capacity;
	long total_packet_count, lost_packet_count;
	atomic_t size;
76 77
	struct packet *head, *tail;
	wait_queue_head_t wait;
78 79 80 81
};

struct pcilynx {
	struct pci_dev *pci_device;
82
	__iomem char *registers;
83 84

	struct pcl *rcv_start_pcl, *rcv_pcl;
85
	__le32 *rcv_buffer;
86 87 88 89 90 91 92

	dma_addr_t rcv_start_pcl_bus, rcv_pcl_bus, rcv_buffer_bus;

	spinlock_t client_list_lock;
	struct list_head client_list;

	struct miscdevice misc;
93 94
	struct list_head link;
	struct kref kref;
95 96
};

97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
static inline struct pcilynx *
lynx_get(struct pcilynx *lynx)
{
	kref_get(&lynx->kref);

	return lynx;
}

static void
lynx_release(struct kref *kref)
{
	kfree(container_of(kref, struct pcilynx, kref));
}

static inline void
lynx_put(struct pcilynx *lynx)
{
	kref_put(&lynx->kref, lynx_release);
}

117 118
struct client {
	struct pcilynx *lynx;
119
	u32 tcode_mask;
120 121 122 123
	struct packet_buffer buffer;
	struct list_head link;
};

124 125
static DEFINE_MUTEX(card_mutex);
static LIST_HEAD(card_list);
126 127 128 129 130 131 132 133 134 135 136 137

static int
packet_buffer_init(struct packet_buffer *buffer, size_t capacity)
{
	buffer->data = kmalloc(capacity, GFP_KERNEL);
	if (buffer->data == NULL)
		return -ENOMEM;
	buffer->head = (struct packet *) buffer->data;
	buffer->tail = (struct packet *) buffer->data;
	buffer->capacity = capacity;
	buffer->lost_packet_count = 0;
	atomic_set(&buffer->size, 0);
138
	init_waitqueue_head(&buffer->wait);
139 140 141 142 143 144 145 146 147 148 149

	return 0;
}

static void
packet_buffer_destroy(struct packet_buffer *buffer)
{
	kfree(buffer->data);
}

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 154 155 156
	size_t length;
	char *end;

	if (wait_event_interruptible(buffer->wait,
157 158
				     atomic_read(&buffer->size) > 0) ||
				     list_empty(&client->lynx->link))
159 160
		return -ERESTARTSYS;

161 162 163
	if (atomic_read(&buffer->size) == 0)
		return -ENODEV;

164 165 166 167 168 169 170 171 172
	/* FIXME: Check length <= user_length. */

	end = buffer->data + buffer->capacity;
	length = buffer->head->length;

	if (&buffer->head->data[length] < end) {
		if (copy_to_user(data, buffer->head->data, length))
			return -EFAULT;
		buffer->head = (struct packet *) &buffer->head->data[length];
173
	} else {
174 175 176 177 178 179 180 181 182
		size_t split = end - buffer->head->data;

		if (copy_to_user(data, buffer->head->data, split))
			return -EFAULT;
		if (copy_to_user(data + split, buffer->data, length - split))
			return -EFAULT;
		buffer->head = (struct packet *) &buffer->data[length - split];
	}

183 184
	/*
	 * Decrease buffer->size as the last thing, since this is what
185
	 * keeps the interrupt from overwriting the packet we are
186 187 188
	 * retrieving from the buffer.
	 */
	atomic_sub(sizeof(struct packet) + length, &buffer->size);
189 190 191 192 193 194 195 196 197 198 199

	return length;
}

static void
packet_buffer_put(struct packet_buffer *buffer, void *data, size_t length)
{
	char *end;

	buffer->total_packet_count++;

200 201
	if (buffer->capacity <
	    atomic_read(&buffer->size) + sizeof(struct packet) + length) {
202 203 204 205 206 207 208 209 210 211
		buffer->lost_packet_count++;
		return;
	}

	end = buffer->data + buffer->capacity;
	buffer->tail->length = length;

	if (&buffer->tail->data[length] < end) {
		memcpy(buffer->tail->data, data, length);
		buffer->tail = (struct packet *) &buffer->tail->data[length];
212
	} else {
213 214 215 216 217 218
		size_t split = end - buffer->tail->data;

		memcpy(buffer->tail->data, data, split);
		memcpy(buffer->data, data + split, length - split);
		buffer->tail = (struct packet *) &buffer->data[length - split];
	}
219

220 221
	/* Finally, adjust buffer size and wake up userspace reader. */

222
	atomic_add(sizeof(struct packet) + length, &buffer->size);
223 224 225 226 227 228
	wake_up_interruptible(&buffer->wait);
}

static inline void
reg_write(struct pcilynx *lynx, int offset, u32 data)
{
229
	writel(data, lynx->registers + offset);
230 231 232 233 234
}

static inline u32
reg_read(struct pcilynx *lynx, int offset)
{
235
	return readl(lynx->registers + offset);
236 237 238 239 240
}

static inline void
reg_set_bits(struct pcilynx *lynx, int offset, u32 mask)
{
241
	reg_write(lynx, offset, (reg_read(lynx, offset) | mask));
242 243
}

244 245 246 247 248 249 250
/*
 * Maybe the pcl programs could be set up to just append data instead
 * of using a whole packet.
 */
static inline void
run_pcl(struct pcilynx *lynx, dma_addr_t pcl_bus,
			   int dmachan)
251
{
252 253 254
	reg_write(lynx, DMA0_CURRENT_PCL + dmachan * 0x20, pcl_bus);
	reg_write(lynx, DMA0_CHAN_CTRL + dmachan * 0x20,
		  DMA_CHAN_CTRL_ENABLE | DMA_CHAN_CTRL_LINK);
255 256 257 258 259
}

static int
set_phy_reg(struct pcilynx *lynx, int addr, int val)
{
260
	if (addr > 15) {
261 262
		dev_err(&lynx->pci_device->dev,
			"PHY register address %d out of range\n", addr);
263 264 265
		return -1;
	}
	if (val > 0xff) {
266 267
		dev_err(&lynx->pci_device->dev,
			"PHY register value %d out of range\n", val);
268 269 270
		return -1;
	}
	reg_write(lynx, LINK_PHY, LINK_PHY_WRITE |
271 272
		  LINK_PHY_ADDR(addr) | LINK_PHY_WDATA(val));

273
	return 0;
274 275
}

276 277
static int
nosy_open(struct inode *inode, struct file *file)
278
{
279
	int minor = iminor(inode);
280
	struct client *client;
281 282 283 284 285 286 287 288 289 290
	struct pcilynx *tmp, *lynx = NULL;

	mutex_lock(&card_mutex);
	list_for_each_entry(tmp, &card_list, link)
		if (tmp->misc.minor == minor) {
			lynx = lynx_get(tmp);
			break;
		}
	mutex_unlock(&card_mutex);
	if (lynx == NULL)
291 292
		return -ENODEV;

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 300
	INIT_LIST_HEAD(&client->link);

301 302
	if (packet_buffer_init(&client->buffer, 128 * 1024) < 0)
		goto fail;
303

304
	file->private_data = client;
305

306
	return nonseekable_open(inode, file);
307 308 309 310 311
fail:
	kfree(client);
	lynx_put(lynx);

	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 325
	packet_buffer_destroy(&client->buffer);
	kfree(client);
326
	lynx_put(lynx);
327

328
	return 0;
329 330 331 332 333 334
}

static unsigned int
nosy_poll(struct file *file, poll_table *pt)
{
	struct client *client = file->private_data;
335
	unsigned int ret = 0;
336 337 338 339

	poll_wait(file, &client->buffer.wait, pt);

	if (atomic_read(&client->buffer.size) > 0)
340 341 342 343 344 345
		ret = POLLIN | POLLRDNORM;

	if (list_empty(&client->lynx->link))
		ret |= POLLHUP;

	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 352
{
	struct client *client = file->private_data;

353
	return packet_buffer_get(client, buffer, count);
354 355
}

356 357
static long
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 363

	switch (cmd) {
364
	case NOSY_IOC_GET_STATS:
365
		spin_lock_irq(client_list_lock);
366
		stats.total_packet_count = client->buffer.total_packet_count;
367 368 369
		stats.lost_packet_count  = client->buffer.lost_packet_count;
		spin_unlock_irq(client_list_lock);

370
		if (copy_to_user((void __user *) arg, &stats, sizeof stats))
371 372 373
			return -EFAULT;
		else
			return 0;
374

375
	case NOSY_IOC_START:
376 377 378 379
		spin_lock_irq(client_list_lock);
		list_add_tail(&client->link, &client->lynx->client_list);
		spin_unlock_irq(client_list_lock);

380 381 382
		return 0;

	case NOSY_IOC_STOP:
383 384 385 386
		spin_lock_irq(client_list_lock);
		list_del_init(&client->link);
		spin_unlock_irq(client_list_lock);

387 388 389
		return 0;

	case NOSY_IOC_FILTER:
390
		spin_lock_irq(client_list_lock);
391
		client->tcode_mask = arg;
392
		spin_unlock_irq(client_list_lock);
393

394 395 396 397 398 399 400 401
		return 0;

	default:
		return -EINVAL;
		/* Flush buffer, configure filter. */
	}
}

402
static const struct file_operations nosy_ops = {
403 404 405 406 407 408
	.owner =		THIS_MODULE,
	.read =			nosy_read,
	.unlocked_ioctl =	nosy_ioctl,
	.poll =			nosy_poll,
	.open =			nosy_open,
	.release =		nosy_release,
409 410 411 412 413
};

#define PHY_PACKET_SIZE 12 /* 1 payload, 1 inverse, 1 ack = 3 quadlets */

static void
414
packet_irq_handler(struct pcilynx *lynx)
415 416
{
	struct client *client;
417
	u32 tcode_mask, tcode, timestamp;
418
	size_t length;
419
	struct timespec64 ts64;
420 421 422

	/* FIXME: Also report rcv_speed. */

423 424
	length = __le32_to_cpu(lynx->rcv_pcl->pcl_status) & 0x00001fff;
	tcode  = __le32_to_cpu(lynx->rcv_buffer[1]) >> 4 & 0xf;
425

426 427 428
	ktime_get_real_ts64(&ts64);
	timestamp = ts64.tv_nsec / NSEC_PER_USEC;
	lynx->rcv_buffer[0] = (__force __le32)timestamp;
429 430 431 432

	if (length == PHY_PACKET_SIZE)
		tcode_mask = 1 << TCODE_PHY_PACKET;
	else
433
		tcode_mask = 1 << tcode;
434

435
	spin_lock(&lynx->client_list_lock);
436

437
	list_for_each_entry(client, &lynx->client_list, link)
438
		if (client->tcode_mask & tcode_mask)
439
			packet_buffer_put(&client->buffer,
440 441
					  lynx->rcv_buffer, length + 4);

442
	spin_unlock(&lynx->client_list_lock);
443 444 445
}

static void
446
bus_reset_irq_handler(struct pcilynx *lynx)
447 448
{
	struct client *client;
449 450
	struct timespec64 ts64;
	u32    timestamp;
451

452 453
	ktime_get_real_ts64(&ts64);
	timestamp = ts64.tv_nsec / NSEC_PER_USEC;
454

455
	spin_lock(&lynx->client_list_lock);
456

457
	list_for_each_entry(client, &lynx->client_list, link)
458
		packet_buffer_put(&client->buffer, &timestamp, 4);
459

460
	spin_unlock(&lynx->client_list_lock);
461 462 463 464 465
}

static irqreturn_t
irq_handler(int irq, void *device)
{
466
	struct pcilynx *lynx = device;
467
	u32 pci_int_status;
468 469

	pci_int_status = reg_read(lynx, PCI_INT_STATUS);
470

471 472 473 474
	if (pci_int_status == ~0)
		/* Card was ejected. */
		return IRQ_NONE;

475 476 477 478 479 480 481 482 483 484 485
	if ((pci_int_status & PCI_INT_INT_PEND) == 0)
		/* Not our interrupt, bail out quickly. */
		return IRQ_NONE;

	if ((pci_int_status & PCI_INT_P1394_INT) != 0) {
		u32 link_int_status;

		link_int_status = reg_read(lynx, LINK_INT_STATUS);
		reg_write(lynx, LINK_INT_STATUS, link_int_status);

		if ((link_int_status & LINK_INT_PHY_BUSRESET) > 0)
486
			bus_reset_irq_handler(lynx);
487 488 489 490 491 492 493 494 495
	}

	/* Clear the PCI_INT_STATUS register only after clearing the
	 * LINK_INT_STATUS register; otherwise the PCI_INT_P1394 will
	 * be set again immediately. */

	reg_write(lynx, PCI_INT_STATUS, pci_int_status);

	if ((pci_int_status & PCI_INT_DMA0_HLT) > 0) {
496
		packet_irq_handler(lynx);
497 498 499 500 501 502 503 504 505
		run_pcl(lynx, lynx->rcv_start_pcl_bus, 0);
	}

	return IRQ_HANDLED;
}

static void
remove_card(struct pci_dev *dev)
{
506 507
	struct pcilynx *lynx = pci_get_drvdata(dev);
	struct client *client;
508

509 510 511 512
	mutex_lock(&card_mutex);
	list_del_init(&lynx->link);
	misc_deregister(&lynx->misc);
	mutex_unlock(&card_mutex);
513 514 515 516

	reg_write(lynx, PCI_INT_ENABLE, 0);
	free_irq(lynx->pci_device->irq, lynx);

517 518 519 520 521
	spin_lock_irq(&lynx->client_list_lock);
	list_for_each_entry(client, &lynx->client_list, link)
		wake_up_interruptible(&client->buffer.wait);
	spin_unlock_irq(&lynx->client_list_lock);

522
	pci_free_consistent(lynx->pci_device, sizeof(struct pcl),
523
			    lynx->rcv_start_pcl, lynx->rcv_start_pcl_bus);
524
	pci_free_consistent(lynx->pci_device, sizeof(struct pcl),
525 526 527 528 529
			    lynx->rcv_pcl, lynx->rcv_pcl_bus);
	pci_free_consistent(lynx->pci_device, PAGE_SIZE,
			    lynx->rcv_buffer, lynx->rcv_buffer_bus);

	iounmap(lynx->registers);
530
	pci_disable_device(dev);
531
	lynx_put(lynx);
532 533 534 535
}

#define RCV_BUFFER_SIZE (16 * 1024)

536
static int
537 538
add_card(struct pci_dev *dev, const struct pci_device_id *unused)
{
539
	struct pcilynx *lynx;
540
	u32 p, end;
541
	int ret, i;
542

543
	if (pci_set_dma_mask(dev, DMA_BIT_MASK(32))) {
544 545
		dev_err(&dev->dev,
		    "DMA address limits not supported for PCILynx hardware\n");
546 547 548
		return -ENXIO;
	}
	if (pci_enable_device(dev)) {
549
		dev_err(&dev->dev, "Failed to enable PCILynx hardware\n");
550 551 552
		return -ENXIO;
	}
	pci_set_master(dev);
553 554

	lynx = kzalloc(sizeof *lynx, GFP_KERNEL);
555
	if (lynx == NULL) {
556
		dev_err(&dev->dev, "Failed to allocate control structure\n");
557 558
		ret = -ENOMEM;
		goto fail_disable;
559 560 561
	}
	lynx->pci_device = dev;
	pci_set_drvdata(dev, lynx);
562 563 564

	spin_lock_init(&lynx->client_list_lock);
	INIT_LIST_HEAD(&lynx->client_list);
565
	kref_init(&lynx->kref);
566

567 568 569 570 571 572 573 574 575 576
	lynx->registers = ioremap_nocache(pci_resource_start(dev, 0),
					  PCILYNX_MAX_REGISTER);

	lynx->rcv_start_pcl = pci_alloc_consistent(lynx->pci_device,
				sizeof(struct pcl), &lynx->rcv_start_pcl_bus);
	lynx->rcv_pcl = pci_alloc_consistent(lynx->pci_device,
				sizeof(struct pcl), &lynx->rcv_pcl_bus);
	lynx->rcv_buffer = pci_alloc_consistent(lynx->pci_device,
				RCV_BUFFER_SIZE, &lynx->rcv_buffer_bus);
	if (lynx->rcv_start_pcl == NULL ||
577
	    lynx->rcv_pcl == NULL ||
578
	    lynx->rcv_buffer == NULL) {
579
		dev_err(&dev->dev, "Failed to allocate receive buffer\n");
580 581
		ret = -ENOMEM;
		goto fail_deallocate;
582
	}
583 584 585
	lynx->rcv_start_pcl->next	= cpu_to_le32(lynx->rcv_pcl_bus);
	lynx->rcv_pcl->next		= cpu_to_le32(PCL_NEXT_INVALID);
	lynx->rcv_pcl->async_error_next	= cpu_to_le32(PCL_NEXT_INVALID);
586

587
	lynx->rcv_pcl->buffer[0].control =
588 589 590
			cpu_to_le32(PCL_CMD_RCV | PCL_BIGENDIAN | 2044);
	lynx->rcv_pcl->buffer[0].pointer =
			cpu_to_le32(lynx->rcv_buffer_bus + 4);
591 592 593 594
	p = lynx->rcv_buffer_bus + 2048;
	end = lynx->rcv_buffer_bus + RCV_BUFFER_SIZE;
	for (i = 1; p < end; i++, p += 2048) {
		lynx->rcv_pcl->buffer[i].control =
595 596
			cpu_to_le32(PCL_CMD_RCV | PCL_BIGENDIAN | 2048);
		lynx->rcv_pcl->buffer[i].pointer = cpu_to_le32(p);
597
	}
598
	lynx->rcv_pcl->buffer[i - 1].control |= cpu_to_le32(PCL_LAST_BUFF);
599

600 601 602 603
	reg_set_bits(lynx, MISC_CONTROL, MISC_CONTROL_SWRESET);
	/* Fix buggy cards with autoboot pin not tied low: */
	reg_write(lynx, DMA0_CHAN_CTRL, 0);
	reg_write(lynx, DMA_GLOBAL_REGISTER, 0x00 << 24);
604 605

#if 0
606 607 608 609 610 611 612 613 614 615 616
	/* now, looking for PHY register set */
	if ((get_phy_reg(lynx, 2) & 0xe0) == 0xe0) {
		lynx->phyic.reg_1394a = 1;
		PRINT(KERN_INFO, lynx->id,
		      "found 1394a conform PHY (using extended register set)");
		lynx->phyic.vendor = get_phy_vendorid(lynx);
		lynx->phyic.product = get_phy_productid(lynx);
	} else {
		lynx->phyic.reg_1394a = 0;
		PRINT(KERN_INFO, lynx->id, "found old 1394 PHY");
	}
617 618 619 620 621
#endif

	/* Setup the general receive FIFO max size. */
	reg_write(lynx, FIFO_SIZES, 255);

622
	reg_set_bits(lynx, PCI_INT_ENABLE, PCI_INT_DMA_ALL);
623

624
	reg_write(lynx, LINK_INT_ENABLE,
625 626 627 628 629 630 631 632 633 634 635 636 637 638
		  LINK_INT_PHY_TIME_OUT | LINK_INT_PHY_REG_RCVD |
		  LINK_INT_PHY_BUSRESET | LINK_INT_IT_STUCK |
		  LINK_INT_AT_STUCK | LINK_INT_SNTRJ |
		  LINK_INT_TC_ERR | LINK_INT_GRF_OVER_FLOW |
		  LINK_INT_ITF_UNDER_FLOW | LINK_INT_ATF_UNDER_FLOW);

	/* Disable the L flag in self ID packets. */
	set_phy_reg(lynx, 4, 0);

	/* Put this baby into snoop mode */
	reg_set_bits(lynx, LINK_CONTROL, LINK_CONTROL_SNOOP_ENABLE);

	run_pcl(lynx, lynx->rcv_start_pcl_bus, 0);

639 640
	if (request_irq(dev->irq, irq_handler, IRQF_SHARED,
			driver_name, lynx)) {
641 642
		dev_err(&dev->dev,
			"Failed to allocate shared interrupt %d\n", dev->irq);
643 644
		ret = -EIO;
		goto fail_deallocate;
645
	}
646 647 648 649 650

	lynx->misc.parent = &dev->dev;
	lynx->misc.minor = MISC_DYNAMIC_MINOR;
	lynx->misc.name = "nosy";
	lynx->misc.fops = &nosy_ops;
651 652

	mutex_lock(&card_mutex);
653 654
	ret = misc_register(&lynx->misc);
	if (ret) {
655
		dev_err(&dev->dev, "Failed to register misc char device\n");
656
		mutex_unlock(&card_mutex);
657
		goto fail_free_irq;
658
	}
659 660
	list_add_tail(&lynx->link, &card_list);
	mutex_unlock(&card_mutex);
661

662 663
	dev_info(&dev->dev,
		 "Initialized PCILynx IEEE1394 card, irq=%d\n", dev->irq);
664

665
	return 0;
666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687

fail_free_irq:
	reg_write(lynx, PCI_INT_ENABLE, 0);
	free_irq(lynx->pci_device->irq, lynx);

fail_deallocate:
	if (lynx->rcv_start_pcl)
		pci_free_consistent(lynx->pci_device, sizeof(struct pcl),
				lynx->rcv_start_pcl, lynx->rcv_start_pcl_bus);
	if (lynx->rcv_pcl)
		pci_free_consistent(lynx->pci_device, sizeof(struct pcl),
				lynx->rcv_pcl, lynx->rcv_pcl_bus);
	if (lynx->rcv_buffer)
		pci_free_consistent(lynx->pci_device, PAGE_SIZE,
				lynx->rcv_buffer, lynx->rcv_buffer_bus);
	iounmap(lynx->registers);
	kfree(lynx);

fail_disable:
	pci_disable_device(dev);

	return ret;
688 689
}

690
static struct pci_device_id pci_table[] = {
691
	{
692 693 694 695
		.vendor =    PCI_VENDOR_ID_TI,
		.device =    PCI_DEVICE_ID_TI_PCILYNX,
		.subvendor = PCI_ANY_ID,
		.subdevice = PCI_ANY_ID,
696 697 698 699
	},
	{ }	/* Terminating entry */
};

Axel Lin's avatar
Axel Lin committed
700 701
MODULE_DEVICE_TABLE(pci, pci_table);

702
static struct pci_driver lynx_pci_driver = {
703
	.name =		driver_name,
704 705
	.id_table =	pci_table,
	.probe =	add_card,
706
	.remove =	remove_card,
707 708
};

Axel Lin's avatar
Axel Lin committed
709 710
module_pci_driver(lynx_pci_driver);

711
MODULE_AUTHOR("Kristian Hoegsberg");
712 713
MODULE_DESCRIPTION("Snoop mode driver for TI pcilynx 1394 controllers");
MODULE_LICENSE("GPL");