#include "ft1000_usb.h"
//#include "ft1000_ioctl.h"
-void ft1000_DestroyDevice(struct net_device *dev);
-u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow);
-u16 ft1000_read_register(struct ft1000_device *ft1000dev, short* Data, u16 nRegIndx);
+static int ft1000_flarion_cnt = 0;
-extern inline u16 ft1000_asic_read (struct net_device *dev, u16 offset);
-extern inline void ft1000_asic_write (struct net_device *dev, u16 offset, u16 value);
-extern void CardSendCommand(struct ft1000_device *ft1000dev, unsigned short *ptempbuffer, int size);
+//need to looking usage of ft1000Handle
static int ft1000_ChOpen (struct inode *Inode, struct file *File);
static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait);
unsigned long Argument);
static int ft1000_ChRelease (struct inode *Inode, struct file *File);
-static int ft1000_flarion_cnt = 0;
-
-//need to looking usage of ft1000Handle
-
-
-
// Global pointer to device object
static struct ft1000_device *pdevobj[MAX_NUM_CARDS + 2];
//static devfs_handle_t ft1000Handle[MAX_NUM_CARDS];
//---------------------------------------------------------------------------
static int exec_mknod (void *pdata)
{
- PFT1000_INFO info;
+ struct ft1000_info *info;
char mjnum[4];
char minornum[4];
char temp[32];
static int rm_mknod (void *pdata)
{
- PFT1000_INFO info;
+ struct ft1000_info *info;
//char *argv[4]={"rm", "-f", "/dev/FT1000", NULL};
int retcode;
char temp[32];
char *argv[]={"rm", "-f", temp, NULL};
- info = (PFT1000_INFO)pdata;
+ info = (struct ft1000_info *)pdata;
DEBUG("ft1000_chdev:rm_mknod is called for device %s\n", info->DeviceName);
sprintf(temp, "%s%s", "/dev/", info->DeviceName) ;
// Notes:
//
//---------------------------------------------------------------------------
-PDPRAM_BLK ft1000_get_buffer (struct list_head *bufflist)
+struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist)
{
unsigned long flags;
- PDPRAM_BLK ptr;
+ struct dpram_blk *ptr;
spin_lock_irqsave(&free_buff_lock, flags);
// Check if buffer is available
}
else {
numofmsgbuf--;
- ptr = list_entry(bufflist->next, DPRAM_BLK, list);
+ ptr = list_entry(bufflist->next, struct dpram_blk, list);
list_del(&ptr->list);
//DEBUG("ft1000_get_buffer: number of free msg buffers = %d\n", numofmsgbuf);
}
// Notes:
//
//---------------------------------------------------------------------------
-void ft1000_free_buffer (PDPRAM_BLK pdpram_blk, struct list_head *plist)
+void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist)
{
unsigned long flags;
//---------------------------------------------------------------------------
int ft1000_CreateDevice(struct ft1000_device *dev)
{
- PFT1000_INFO info = netdev_priv(dev->net);
+ struct ft1000_info *info = netdev_priv(dev->net);
int result;
int i;
pid_t pid;
//save the device info to global array
pdevobj[info->CardNumber] = dev;
- DEBUG("ft1000_CreateDevice: ******SAVED pdevobj[%d]=%x\n", info->CardNumber, (unsigned int)pdevobj[info->CardNumber]); //aelias [+] reason:up
+ DEBUG("ft1000_CreateDevice: ******SAVED pdevobj[%d]=%p\n", info->CardNumber, pdevobj[info->CardNumber]); //aelias [+] reason:up
if (info->DeviceCreated)
{
pid = kernel_thread (exec_mknod, (void *)info, 0);
// initialize application information
- info->appcnt = 0;
// if (ft1000_flarion_cnt == 0) {
//
// // create list of free buffers
// for (i=0; i<NUM_OF_FREE_BUFFERS; i++) {
// // Get memory for DPRAM_DATA link list
-// pdpram_blk = kmalloc ( sizeof(DPRAM_BLK), GFP_KERNEL );
+// pdpram_blk = kmalloc ( sizeof(struct dpram_blk), GFP_KERNEL );
// // Get a block of memory to store command data
// pdpram_blk->pbuffer = kmalloc ( MAX_CMD_SQSIZE, GFP_KERNEL );
// // link provisioning data
info->app_info[i].nRxMsg = 0;
info->app_info[i].nTxMsgReject = 0;
info->app_info[i].nRxMsgMiss = 0;
- info->app_info[i].fileobject = 0;
+ info->app_info[i].fileobject = NULL;
info->app_info[i].app_id = i+1;
info->app_info[i].DspBCMsgFlag = 0;
info->app_info[i].NumOfMsg = 0;
//---------------------------------------------------------------------------
void ft1000_DestroyDevice(struct net_device *dev)
{
- PFT1000_INFO info = netdev_priv(dev);
+ struct ft1000_info *info = netdev_priv(dev);
int result = 0;
pid_t pid;
int i;
- PDPRAM_BLK pdpram_blk;
- DPRAM_BLK *ptr;
+ struct dpram_blk *pdpram_blk;
+ struct dpram_blk *ptr;
DEBUG("ft1000_chdev:ft1000_DestroyDevice called\n");
// Make sure we free any memory reserve for slow Queue
for (i=0; i<MAX_NUM_APP; i++) {
while (list_empty(&info->app_info[i].app_sqlist) == 0) {
- pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, DPRAM_BLK, list);
+ pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list);
list_del(&pdpram_blk->list);
ft1000_free_buffer(pdpram_blk, &freercvpool);
// Remove buffer allocated for receive command data
if (ft1000_flarion_cnt == 0) {
while (list_empty(&freercvpool) == 0) {
- ptr = list_entry(freercvpool.next, DPRAM_BLK, list);
+ ptr = list_entry(freercvpool.next, struct dpram_blk, list);
list_del(&ptr->list);
kfree(ptr->pbuffer);
kfree(ptr);
//---------------------------------------------------------------------------
static int ft1000_ChOpen (struct inode *Inode, struct file *File)
{
- PFT1000_INFO info;
+ struct ft1000_info *info;
int i,num;
DEBUG("ft1000_ChOpen called\n");
DEBUG("ft1000_ChOpen: minor number=%d\n", num);
for (i=0; i<5; i++)
- DEBUG("pdevobj[%d]=%x\n", i, (unsigned int)pdevobj[i]); //aelias [+] reason: down
+ DEBUG("pdevobj[%d]=%p\n", i, pdevobj[i]); //aelias [+] reason: down
if ( pdevobj[num] != NULL )
- //info = (PFT1000_INFO)(pdevobj[num]->net->priv);
- info = (FT1000_INFO *) netdev_priv (pdevobj[num]->net);
+ //info = (struct ft1000_info *)(pdevobj[num]->net->priv);
+ info = (struct ft1000_info *)netdev_priv(pdevobj[num]->net);
else
{
DEBUG("ft1000_ChOpen: can not find device object %d\n", num);
return -1;
}
- DEBUG("f_owner = 0x%8x number of application = %d\n", (u32)(&File->f_owner), info->appcnt );
+ DEBUG("f_owner = %p number of application = %d\n", (&File->f_owner), info->appcnt );
// Check if maximum number of application exceeded
if (info->appcnt > MAX_NUM_APP) {
// Search for available application info block
for (i=0; i<MAX_NUM_APP; i++) {
- if ( (info->app_info[i].fileobject == 0) ) {
+ if ( (info->app_info[i].fileobject == NULL) ) {
break;
}
}
}
info->appcnt++;
- info->app_info[i].fileobject = (u32)(&File->f_owner);
+ info->app_info[i].fileobject = &File->f_owner;
info->app_info[i].nTxMsg = 0;
info->app_info[i].nRxMsg = 0;
info->app_info[i].nTxMsgReject = 0;
static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait)
{
struct net_device *dev = file->private_data;
- PFT1000_INFO info;
+ struct ft1000_info *info;
int i;
//DEBUG("ft1000_ChPoll called\n");
return (-EBADF);
}
- info = (FT1000_INFO *) netdev_priv (dev);
+ info = (struct ft1000_info *) netdev_priv(dev);
// Search for matching file object
for (i=0; i<MAX_NUM_APP; i++) {
- if ( info->app_info[i].fileobject == (u32)(&file->f_owner) ) {
+ if ( info->app_info[i].fileobject == &file->f_owner) {
//DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
break;
}
static long ft1000_ChIoctl (struct file *File, unsigned int Command,
unsigned long Argument)
{
+ void __user *argp = (void __user *)Argument;
struct net_device *dev;
- PFT1000_INFO info;
+ struct ft1000_info *info;
struct ft1000_device *ft1000dev;
int result=0;
int cmd;
//DEBUG("FT1000:ft1000_ChIoctl:Command = 0x%x Argument = 0x%8x\n", Command, (u32)Argument);
dev = File->private_data;
- info = (FT1000_INFO *) netdev_priv (dev);
+ info = (struct ft1000_info *) netdev_priv(dev);
ft1000dev = info->pFt1000Dev;
cmd = _IOC_NR(Command);
//DEBUG("FT1000:ft1000_ChIoctl:cmd = 0x%x\n", cmd);
switch (cmd) {
case IOCTL_REGISTER_CMD:
DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_REGISTER called\n");
- result = get_user(tempword, (unsigned short *)Argument);
+ result = get_user(tempword, (__u16 __user*)argp);
if (result) {
DEBUG("result = %d failed to get_user\n", result);
break;
if (tempword == DSPBCMSGID) {
// Search for matching file object
for (i=0; i<MAX_NUM_APP; i++) {
- if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+ if ( info->app_info[i].fileobject == &File->f_owner) {
info->app_info[i].DspBCMsgFlag = 1;
DEBUG("FT1000:ft1000_ChIoctl:Registered for broadcast messages\n");
break;
get_ver_data.drv_ver = FT1000_DRV_VER;
- if (copy_to_user((PIOCTL_GET_VER)Argument, &get_ver_data, sizeof(get_ver_data)) ) {
+ if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data)) ) {
DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
result = -EFAULT;
break;
break;
case IOCTL_GET_DSP_STAT_CMD:
//DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_DSP_STAT called\n");
-
+ memset(&get_stat_data, 0, sizeof(get_stat_data));
memcpy(get_stat_data.DspVer, info->DspVer, DSPVERSZ);
memcpy(get_stat_data.HwSerNum, info->HwSerNum, HWSERNUMSZ);
memcpy(get_stat_data.Sku, info->Sku, SKUSZ);
do_gettimeofday ( &tv );
get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm);
DEBUG("Connection Time = %d\n", (int)get_stat_data.ConTm);
- if (copy_to_user((PIOCTL_GET_DSP_STAT)Argument, &get_stat_data, sizeof(get_stat_data)) ) {
+ if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data)) ) {
DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
result = -EFAULT;
break;
break;
case IOCTL_SET_DPRAM_CMD:
{
- IOCTL_DPRAM_BLK dpram_data;
+ IOCTL_DPRAM_BLK *dpram_data;
//IOCTL_DPRAM_COMMAND dpram_command;
USHORT qtype;
USHORT msgsz;
- PPSEUDO_HDR ppseudo_hdr;
+ struct pseudo_hdr *ppseudo_hdr;
PUSHORT pmsg;
USHORT total_len;
USHORT app_index;
//DEBUG("FT1000:ft1000_ChIoctl: try to SET_DPRAM \n");
// Get the length field to see how many bytes to copy
- result = get_user(msgsz, (unsigned short *)Argument);
+ result = get_user(msgsz, (__u16 __user *)argp);
msgsz = ntohs (msgsz);
//DEBUG("FT1000:ft1000_ChIoctl: length of message = %d\n", msgsz);
break;
}
+ result = -ENOMEM;
+ dpram_data = kmalloc(msgsz + 2, GFP_KERNEL);
+ if (!dpram_data)
+ break;
+
//if ( copy_from_user(&(dpram_command.dpram_blk), (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
- if ( copy_from_user(&dpram_data, (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
+ if ( copy_from_user(&dpram_data, argp, msgsz+2) ) {
DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
result = -EFAULT;
}
#endif
// Check if this message came from a registered application
for (i=0; i<MAX_NUM_APP; i++) {
- if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+ if ( info->app_info[i].fileobject == &File->f_owner) {
break;
}
}
if (i==MAX_NUM_APP) {
DEBUG("FT1000:No matching application fileobject\n");
result = -EINVAL;
+ kfree(dpram_data);
break;
}
app_index = i;
// Check message qtype type which is the lower byte within qos_class
//qtype = ntohs(dpram_command.dpram_blk.pseudohdr.qos_class) & 0xff;
- qtype = ntohs(dpram_data.pseudohdr.qos_class) & 0xff;
+ qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff;
//DEBUG("FT1000_ft1000_ChIoctl: qtype = %d\n", qtype);
if (qtype) {
}
if (tempword & FT1000_DB_DPRAM_TX) {
DEBUG("FT1000:ft1000_ChIoctl:Doorbell not available\n");
result = -ENOTTY;
+ kfree(dpram_data);
break;
}
}
if ( (msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ) ) {
// Need to put sequence number plus new checksum for message
//pmsg = (PUSHORT)&dpram_command.dpram_blk.pseudohdr;
- pmsg = (PUSHORT)&dpram_data.pseudohdr;
- ppseudo_hdr = (PPSEUDO_HDR)pmsg;
+ pmsg = (PUSHORT)&dpram_data->pseudohdr;
+ ppseudo_hdr = (struct pseudo_hdr *)pmsg;
total_len = msgsz+2;
if (total_len & 0x1) {
total_len++;
//DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
}
pmsg++;
- ppseudo_hdr = (PPSEUDO_HDR)pmsg;
+ ppseudo_hdr = (struct pseudo_hdr *)pmsg;
#if 0
- ptr = (char *)&dpram_data;
+ ptr = dpram_data;
DEBUG("FT1000:ft1000_ChIoctl: Command Send\n");
for (i=0; i<total_len; i++) {
DEBUG("FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
//dpram_command.extra = 0;
//CardSendCommand(ft1000dev,(unsigned char*)&dpram_command,total_len+2);
- CardSendCommand(ft1000dev,(unsigned short*)&dpram_data,total_len+2);
+ CardSendCommand(ft1000dev,(unsigned short*)dpram_data,total_len+2);
info->app_info[app_index].nTxMsg++;
- break;
}
else {
result = -EINVAL;
- break;
}
}
}
DEBUG("FT1000:ft1000_ChIoctl: Card not ready take messages\n");
result = -EACCES;
}
+ kfree(dpram_data);
}
break;
case IOCTL_GET_DPRAM_CMD:
{
- PDPRAM_BLK pdpram_blk;
- PIOCTL_DPRAM_BLK pioctl_dpram;
+ struct dpram_blk *pdpram_blk;
+ IOCTL_DPRAM_BLK __user *pioctl_dpram;
int msglen;
//DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_DPRAM called\n");
// Search for matching file object
for (i=0; i<MAX_NUM_APP; i++) {
- if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+ if ( info->app_info[i].fileobject == &File->f_owner) {
//DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
break;
}
}
result = 0;
- pioctl_dpram = (PIOCTL_DPRAM_BLK)Argument;
+ pioctl_dpram = argp;
if (list_empty(&info->app_info[i].app_sqlist) == 0) {
//DEBUG("FT1000:ft1000_ChIoctl:Message detected in slow queue\n");
spin_lock_irqsave(&free_buff_lock, flags);
- pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, DPRAM_BLK, list);
+ pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list);
list_del(&pdpram_blk->list);
info->app_info[i].NumOfMsg--;
//DEBUG("FT1000:ft1000_ChIoctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg);
spin_unlock_irqrestore(&free_buff_lock, flags);
msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
- pioctl_dpram->total_len = htons(msglen);
+ result = get_user(msglen, &pioctl_dpram->total_len);
+ if (result)
+ break;
+ msglen = htons(msglen);
//DEBUG("FT1000:ft1000_ChIoctl:msg length = %x\n", msglen);
if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen))
{
//---------------------------------------------------------------------------
static int ft1000_ChRelease (struct inode *Inode, struct file *File)
{
- PFT1000_INFO info;
+ struct ft1000_info *info;
struct net_device *dev;
int i;
- PDPRAM_BLK pdpram_blk;
+ struct dpram_blk *pdpram_blk;
DEBUG("ft1000_ChRelease called\n");
dev = File->private_data;
- info = (FT1000_INFO *) netdev_priv (dev);
+ info = (struct ft1000_info *) netdev_priv(dev);
if (ft1000_flarion_cnt == 0) {
info->appcnt--;
// Search for matching file object
for (i=0; i<MAX_NUM_APP; i++) {
- if ( info->app_info[i].fileobject == (u32)(&File->f_owner) ) {
+ if ( info->app_info[i].fileobject == &File->f_owner) {
//DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
break;
}
while (list_empty(&info->app_info[i].app_sqlist) == 0) {
DEBUG("Remove and free memory queue up on slow queue\n");
- pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, DPRAM_BLK, list);
+ pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list);
list_del(&pdpram_blk->list);
ft1000_free_buffer(pdpram_blk, &freercvpool);
}
// initialize application information
info->appcnt--;
DEBUG("ft1000_chdev:%s:appcnt = %d\n", __FUNCTION__, info->appcnt);
- info->app_info[i].fileobject = 0;
+ info->app_info[i].fileobject = NULL;
return 0;
}