20 #include <linux/device.h>
21 #include <linux/errno.h>
26 #include <linux/kernel.h>
29 #include <linux/module.h>
31 #include <linux/pci.h>
32 #include <linux/poll.h>
33 #include <linux/sched.h>
34 #include <linux/slab.h>
36 #include <linux/timex.h>
38 #include <linux/wait.h>
41 #include <asm/byteorder.h>
46 #define TCODE_PHY_PACKET 0x10
47 #define PCI_DEVICE_ID_TI_PCILYNX 0x8000
99 kref_get(&lynx->
kref);
113 kref_put(&lynx->
kref, lynx_release);
149 packet_buffer_get(
struct client *
client,
char __user *
data,
size_t user_length)
157 list_empty(&client->
lynx->link))
166 length = buffer->
head->length;
168 if (&buffer->
head->data[length] < end) {
193 packet_buffer_put(
struct packet_buffer *buffer,
void *data,
size_t length)
208 if (&buffer->
tail->data[length] < end) {
212 size_t split = end - buffer->
tail->data;
215 memcpy(buffer->
data, data + split, length - split);
261 "PHY register address %d out of range\n", addr);
266 "PHY register value %d out of range\n", val);
278 int minor = iminor(inode);
284 if (tmp->
misc.minor == minor) {
285 lynx = lynx_get(tmp);
298 INIT_LIST_HEAD(&client->
link);
300 if (packet_buffer_init(&client->
buffer, 128 * 1024) < 0)
314 nosy_release(
struct inode *inode,
struct file *file)
320 list_del_init(&client->
link);
323 packet_buffer_destroy(&client->
buffer);
334 unsigned int ret = 0;
336 poll_wait(file, &client->
buffer.wait, pt);
341 if (list_empty(&client->
lynx->link))
348 nosy_read(
struct file *file,
char __user *buffer,
size_t count, loff_t *offset)
352 return packet_buffer_get(client, buffer, count);
356 nosy_ioctl(
struct file *file,
unsigned int cmd,
unsigned long arg)
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);
375 spin_lock_irq(client_list_lock);
377 spin_unlock_irq(client_list_lock);
382 spin_lock_irq(client_list_lock);
383 list_del_init(&client->
link);
384 spin_unlock_irq(client_list_lock);
389 spin_lock_irq(client_list_lock);
391 spin_unlock_irq(client_list_lock);
404 .unlocked_ioctl = nosy_ioctl,
407 .release = nosy_release,
410 #define PHY_PACKET_SIZE 12
413 packet_irq_handler(
struct pcilynx *lynx)
431 tcode_mask = 1 << tcode;
437 packet_buffer_put(&client->
buffer,
444 bus_reset_irq_handler(
struct pcilynx *lynx)
454 packet_buffer_put(&client->buffer, &tv.
tv_usec, 4);
456 spin_unlock(&lynx->client_list_lock);
467 if (pci_int_status == ~0)
482 bus_reset_irq_handler(lynx);
492 packet_irq_handler(lynx);
502 struct pcilynx *lynx = pci_get_drvdata(dev);
506 list_del_init(&lynx->
link);
516 spin_unlock_irq(&lynx->client_list_lock);
519 lynx->rcv_start_pcl, lynx->rcv_start_pcl_bus);
521 lynx->rcv_pcl, lynx->rcv_pcl_bus);
523 lynx->rcv_buffer, lynx->rcv_buffer_bus);
530 #define RCV_BUFFER_SIZE (16 * 1024)
541 "DMA address limits not supported for PCILynx hardware\n");
545 dev_err(&dev->
dev,
"Failed to enable PCILynx hardware\n");
552 dev_err(&dev->
dev,
"Failed to allocate control structure\n");
557 pci_set_drvdata(dev, lynx);
561 kref_init(&lynx->
kref);
575 dev_err(&dev->
dev,
"Failed to allocate receive buffer\n");
577 goto fail_deallocate;
583 lynx->
rcv_pcl->buffer[0].control =
585 lynx->
rcv_pcl->buffer[0].pointer =
589 for (i = 1; p <
end; i++, p += 2048) {
603 if ((get_phy_reg(lynx, 2) & 0xe0) == 0xe0) {
604 lynx->phyic.reg_1394a = 1;
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);
610 lynx->phyic.reg_1394a = 0;
628 set_phy_reg(lynx, 4, 0);
638 "Failed to allocate shared interrupt %d\n", dev->
irq);
640 goto fail_deallocate;
645 lynx->
misc.name =
"nosy";
646 lynx->
misc.fops = &nosy_ops;
651 dev_err(&dev->
dev,
"Failed to register misc char device\n");
659 "Initialized PCILynx IEEE1394 card, irq=%d\n", dev->
irq);
700 .id_table = pci_table,
702 .remove = remove_card,