Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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