Commit 7b24d75a authored by Rafaela Meissner's avatar Rafaela Meissner
Browse files

more deleting :P

parent a18bd87a
cmd_/home/implantador1/N957Tools/Driver/Linux/V0.6/n957.ko := ld -r -m elf_i386 -T /usr/src/linux-headers-2.6.32-5-common/scripts/module-common.lds --build-id -o /home/implantador1/N957Tools/Driver/Linux/V0.6/n957.ko /home/implantador1/N957Tools/Driver/Linux/V0.6/n957.o /home/implantador1/N957Tools/Driver/Linux/V0.6/n957.mod.o
This diff is collapsed.
This diff is collapsed.
/home/implantador1/N957Tools/Driver/Linux/V0.6/n957.ko
/home/implantador1/N957Tools/Driver/Linux/V0.6/n957.o
#=============================================================================
#
# --- CAEN SpA - Computing Systems Division ---
#
# Written by Stefano Coluccini (s.coluccini@caen.it)
#
# Makefile
#
#
# January 2006 : Created.
#
#=============================================================================
###############################
# Kernel >= 2.5
###############################
# Comment/uncomment the following line to disable/enable debugging
#DEBUG = y
# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g # "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif
CFLAGS += $(DEBFLAGS) -I$(LDDINCDIR)
ifneq ($(KERNELRELEASE),)
# call from kernel build system
obj-m := n957.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINCDIR=$(PWD)/../include modules
endif
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
depend .depend dep:
$(CC) $(CFLAGS) -M *.c > .depend
ifeq (.depend,$(wildcard .depend))
include .depend
endif
#=============================================================================
#
# --- CAEN SpA - Computing Systems Division ---
#
# Written by Stefano Coluccini (s.coluccini@caen.it)
#
# Makefile
#
#
# March 2004 : Created.
#
#=============================================================================
###############################
# Kernel < 2.5
###############################
KERNELREV:=$(shell uname -r)
KERNELSRC:=/lib/modules/$(KERNELREV)/build
# The include directory is right for RedHat systems, modify the
# kernel source location as appropriate for other distributions.
INCLUDE = $(KERNELSRC)/include/
COPTS = -O2 -Wall -W -Wpointer-arith -Wcast-qual \
-Wstrict-prototypes -Wmissing-prototypes \
-Wmissing-declarations -Winline -Wcast-align
# Link-time flags to use
LDFLAGS=
# Additional link libraries
LIBS=
n957.o: n957.c Makefile
gcc -I${INCLUDE} -DMODULE -D__KERNEL__ -O -c n957.c
all: n957.o
clean:
rm -f *.o core
#=============================================================================
#
# --- CAEN SpA - Computing Systems Division ---
#
# Written by Stefano Coluccini (s.coluccini@caen.it)
#
# Makefile
#
#
# January 2006 : Created.
#
#=============================================================================
###############################
# Kernel >= 2.5
###############################
# Comment/uncomment the following line to disable/enable debugging
#DEBUG = y
# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
DEBFLAGS = -O -g # "-O" is needed to expand inlines
else
DEBFLAGS = -O2
endif
CFLAGS += $(DEBFLAGS) -I$(LDDINCDIR)
ifneq ($(KERNELRELEASE),)
# call from kernel build system
obj-m := n957.o
else
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
default:
$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINCDIR=$(PWD)/../include modules
endif
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
depend .depend dep:
$(CC) $(CFLAGS) -M *.c > .depend
ifeq (.depend,$(wildcard .depend))
include .depend
endif
kernel//home/implantador1/N957Tools/Driver/Linux/V0.6/n957.ko
/*
* CAEN n957 USB/NIM Bridge driver - 0.6
*
* Written by Stefano Coluccini (s.coluccini@caen.it) - CAEN SpA
*
* based on rio500.c by Cesar Miquel (miquel@df.uba.ar)
*
* 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.
*
*
* TODO
* - Precise identification of the device based on strings.
*
* Changelog:
*
* March 2010 rev 0.6
* - removed minor check for kernel 2.6
*
* April 2007 rev 0.5
* - Branched from v1718 CAEN USB/VME Bridge
* - !!! WARNING !!! conficts with usbtest driver. Remove it!
*/
#undef DEBUG
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/random.h>
#include <linux/poll.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/spinlock.h>
#include <linux/usb.h>
#include <linux/smp_lock.h>
#ifdef CONFIG_DEVFS_FS
#include <linux/devfs_fs_kernel.h>
#endif
/*
* Version Information
*/
#define DRIVER_VERSION "v0.6"
#define DRIVER_AUTHOR "CAEN COmputing Division <support.computing@caen.it>"
#define DRIVER_DESC "CAEN N957 USB/NIM Bridge driver"
#define N957_MINOR_BASE 210
/* stall/wait timeout for n957 */
#define NAK_TIMEOUT (HZ)
#define IBUF_SIZE 0x10000 /* 64 kbytes */
/* Size of the n957 buffer */
#define OBUF_SIZE 0x10000 /* 64 kbytes */
/* we can have up to this number of devices plugged in at once */
#define MAX_DEVICES 16
//
// Rev 0.2: added ini
#include <linux/version.h>
#ifndef VERSION
#define VERSION(ver,rel,seq) (((ver)<<16) | ((rel)<<8) | (seq))
#endif
#if LINUX_VERSION_CODE >= VERSION(2,5,0)
#define USB_ST_TIMEOUT (-ETIMEDOUT)
#define USB_ST_DATAUNDERRUN (-EREMOTEIO)
#endif
// Rev. 0.4
#if LINUX_VERSION_CODE >= VERSION(2,6,11)
#include <linux/mutex.h> // for unlocked ioctl interface
#endif
#include "n957.h"
//
// Rev 0.2: added end
struct n957_usb_data {
struct usb_device *n957_dev; /* init: probe_n957 */
#if LINUX_VERSION_CODE < VERSION(2,5,0)
devfs_handle_t devfs; /* devfs device */
#endif
unsigned int ifnum; /* Interface number of the USB device */
int open_count; /* number of users */
int present; /* Device is present on the bus */
int minor; /* minor number for the device */
char *obuf, *ibuf; /* transfer buffers */
char bulk_in_ep, bulk_out_ep; /* Endpoint assignments */
wait_queue_head_t wait_q; /* for timeouts */
struct semaphore lock; /* general race avoidance */
// Rev 0.4
#if LINUX_VERSION_CODE >= VERSION(2,6,11)
struct mutex ioctl_lock;
#endif
};
#if LINUX_VERSION_CODE < VERSION(2,5,0)
extern devfs_handle_t usb_devfs_handle; /* /dev/usb dir. */
#endif
/* array of pointers to our devices that are currently connected */
static struct n957_usb_data *minor_table[MAX_DEVICES];
/* lock to protect the minor_table structure */
static DECLARE_MUTEX (minor_table_mutex);
//
//Rev 0.2
// static n957_delete(struct n957_usb_data *n957)
static void n957_delete(struct n957_usb_data *n957)
{
minor_table[n957->minor] = NULL;
if( n957->ibuf != NULL )
kfree(n957->ibuf);
if( n957->obuf != NULL )
kfree(n957->obuf);
kfree(n957);
}
// // Rev. 0.4
#if LINUX_VERSION_CODE >= VERSION(2,6,11)
static long unlocked_ioctl_n957(struct file *, unsigned int, unsigned long);
#endif
static int open_n957(struct inode *inode, struct file *file)
{
struct n957_usb_data *n957 = NULL;
int subminor;
//Dbg
//info( "n957 opening...\n");
#if LINUX_VERSION_CODE <= VERSION(2,5,0)
subminor = MINOR(inode->i_rdev) - N957_MINOR_BASE;
if( (subminor < 0) || (subminor > MAX_DEVICES) )
return -ENODEV;
#else
subminor = MINOR(inode->i_rdev);
#endif
down(&minor_table_mutex);
n957 = minor_table[subminor];
if( n957 == NULL ) {
up(&minor_table_mutex);
return -ENODEV;
}
down(&n957->lock);
up(&minor_table_mutex);
n957->open_count++;
init_waitqueue_head(&n957->wait_q);
// Rev. 1.6
#if LINUX_VERSION_CODE >= VERSION(2,6,11)
mutex_init(&n957->ioctl_lock);
#endif
file->private_data = n957;
up(&n957->lock);
// info("n957 opened.");
//Dbg
//info( "n957 opened...\n");
return 0;
}
static int close_n957(struct inode *inode, struct file *file)
{
struct n957_usb_data *n957 = (struct n957_usb_data *)file->private_data;
int retval = 0;
if( n957 == NULL ) {
err("Close: object is null");
return -ENODEV;
}
down(&minor_table_mutex);
down(&n957->lock);
if( n957->open_count <= 0 ) {
err("Device not opened");
retval = -ENODEV;
goto exit_not_opened;
}
if( n957->n957_dev == NULL ) {
/* the device was unplugged before the file was released */
up(&n957->lock);
n957_delete(n957);
up(&minor_table_mutex);
return 0;
}
n957->open_count--;
exit_not_opened:
up(&(n957->lock));
up(&minor_table_mutex);
// info("n957 closed.");
//Dbg
//info( "n957 close...\n");
return retval;
}
static int
ioctl_n957(struct inode *inode, struct file *file, unsigned int cmd,
unsigned long arg)
{
//
// rev 0.2
int ret= 0;
struct n957_usb_data *n957;
n957 = (struct n957_usb_data *)file->private_data;
down(&(n957->lock));
/* Sanity check to make sure n957 is connected, powered, etc */
if ( n957 == NULL ||
n957->present == 0 ||
n957->n957_dev == NULL )
{
up(&(n957->lock));
return -ENOTTY;
}
switch (cmd) {
case N957_IOCTL_REV:
{
n957_rev_t rev;
if( copy_from_user(&rev, (n957_rev_t *)arg, sizeof(rev)) > 0 ) {
ret = -EFAULT;
break;
}
strcpy( rev.rev_buf, DRIVER_VERSION);
if( copy_to_user((n957_rev_t *)arg, &rev, sizeof(rev)) > 0) {
ret = -EFAULT;
break;
}
}
break;
default:
ret= -ENOTTY;
break;
}
up(&(n957->lock));
return ret;
}
// Rev 0.4
/*
----------------------------------------------------------------------
unlocked_ioctl_n957 (Called in preference to ioctl_n957 on newer kernels)
----------------------------------------------------------------------
*/
#if LINUX_VERSION_CODE >= VERSION(2,6,11)
static long unlocked_ioctl_n957(struct file *file, unsigned int cmd, unsigned long arg)
{
struct inode *inode = file->f_dentry->d_inode;
struct n957_usb_data *s = (struct n957_usb_data *)file->private_data;
long ret;
/* ioctl() calls can cause the Big Kernel Lock (BKL) to be taken, which
* can have significant performance penalties system-wide. By providing
* an unlocked ioctl() method the BKL will not be taken, but the driver
* becomes responsible for its own locking. Furthermore, the lock can be
* broken down per A2818 so that multiple threads accessing different CONET
* chains do not contend with one another during ioctl() calls.
*/
mutex_lock(&s->ioctl_lock);
ret = (long) ioctl_n957(inode, file, cmd, arg);
mutex_unlock(&s->ioctl_lock);
return ret;
}
#endif
static ssize_t
write_n957(struct file *file, const char *buffer,
size_t count, loff_t * ppos)
{
struct n957_usb_data *n957;
unsigned long copy_size;
unsigned long bytes_written = 0;
unsigned int partial;
int result = 0;
int maxretry;
int errn = 0;
n957 = (struct n957_usb_data *)file->private_data;
down(&(n957->lock));
/* Sanity check to make sure n957 is connected, powered, etc */
if ( n957 == NULL ||
n957->present == 0 ||
n957->n957_dev == NULL )
{
up(&(n957->lock));
return -ENODEV;
}
do {
unsigned long thistime;
char *obuf = n957->obuf;
thistime = copy_size =
(count >= OBUF_SIZE) ? OBUF_SIZE : count;
if (copy_from_user(n957->obuf, buffer, copy_size)) {
errn = -EFAULT;
goto error;
}
// maxretry = 5;
maxretry = 1; // TEMP - 1 volta e' sufficiente ?
while (thistime) {
if (!n957->n957_dev) {
errn = -ENODEV;
goto error;
}
if (signal_pending(current)) {
up(&(n957->lock));
return bytes_written ? bytes_written : -EINTR;
}
result = usb_bulk_msg(n957->n957_dev,
usb_sndbulkpipe(n957->n957_dev, 2),
// obuf, thistime, &partial, 5 * HZ);
obuf, thistime, &partial, 1 * HZ); // TEMP - 1 sec basta?
dbg("write stats: result:%d thistime:%lu partial:%u",
result, thistime, partial);
if (result == USB_ST_TIMEOUT) { /* NAK - so hold for a while */
if (!maxretry--) {
errn = -ETIME;
goto error;
}
interruptible_sleep_on_timeout(&n957-> wait_q, NAK_TIMEOUT);
continue;
//Rev 0.2
// } else if (!result & partial) {
} else if (!result && partial) {
obuf += partial;
thistime -= partial;
} else
break;
};
if (result) {
err("Write Whoops - %x", result);
errn = -EIO;
goto error;
}
bytes_written += copy_size;
count -= copy_size;
buffer += copy_size;
} while (count > 0);
up(&(n957->lock));
return bytes_written ? bytes_written : -EIO;
error:
up(&(n957->lock));
return errn;
}
static ssize_t
read_n957(struct file *file, char *buffer, size_t count, loff_t * ppos)
{
struct n957_usb_data *n957;
ssize_t read_count;
unsigned int partial;
int this_read;
int result;
// int maxretry = 10; // TEMP - Prova per abortire prima
int maxretry = 1;
char *ibuf;
n957 = (struct n957_usb_data *)file->private_data;
down(&(n957->lock));
/* Sanity check to make sure n957 is connected, powered, etc */
if ( n957 == NULL ||
n957->present == 0 ||
n957->n957_dev == NULL )
{
up(&(n957->lock));
return -ENODEV;
}
ibuf = n957->ibuf;
read_count = 0;
while (count > 0) {
if (signal_pending(current)) {
up(&(n957->lock));
return read_count ? read_count : -EINTR;
}
if (!n957->n957_dev) {
up(&(n957->lock));
return -ENODEV;
}
this_read = (count >= IBUF_SIZE) ? IBUF_SIZE : count;
result = usb_bulk_msg(n957->n957_dev,
usb_rcvbulkpipe(n957->n957_dev, 6),
ibuf, this_read, &partial,
// (int) (HZ * 8));
(int) (HZ * 1)); // TEMP - 1 secondo credo che basti
dbg("read stats: result:%d this_read:%u partial:%u",
result, this_read, partial);
if (partial) {
count = this_read = partial;
} else if (result == USB_ST_TIMEOUT || result == 15) { /* FIXME: 15 ??? */
if (!maxretry--) {
up(&(n957->lock));
err("read_n957: maxretry timeout");
return -ETIME;
}
interruptible_sleep_on_timeout(&n957->wait_q,
NAK_TIMEOUT);
continue;
} else if (result != USB_ST_DATAUNDERRUN) {
up(&(n957->lock));
err("Read Whoops - result:%u partial:%u this_read:%u",
result, partial, this_read);
return -EIO;
} else {
up(&(n957->lock));
return (0);
}
if (this_read) {
if (copy_to_user(buffer, ibuf, this_read)) {
up(&(n957->lock));
return -EFAULT;
}
count -= this_read;
read_count += this_read;
buffer += this_read;
}
}
up(&(n957->lock));
return read_count;
}