staging: ft1000: Remove unused headers.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / ft1000 / ft1000-usb / ft1000_chdev.c
blobd249c8ae4f46b3cbc91a06ed82db3832fa390658
1 //---------------------------------------------------------------------------
2 // FT1000 driver for Flarion Flash OFDM NIC Device
3 //
4 // Copyright (C) 2006 Flarion Technologies, All rights reserved.
5 //
6 // This program is free software; you can redistribute it and/or modify it
7 // under the terms of the GNU General Public License as published by the Free
8 // Software Foundation; either version 2 of the License, or (at your option) any
9 // later version. This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 // more details. You should have received a copy of the GNU General Public
13 // License along with this program; if not, write to the
14 // Free Software Foundation, Inc., 59 Temple Place -
15 // Suite 330, Boston, MA 02111-1307, USA.
16 //---------------------------------------------------------------------------
18 // File: ft1000_chdev.c
20 // Description: Custom character device dispatch routines.
22 // History:
23 // 8/29/02 Whc Ported to Linux.
24 // 6/05/06 Whc Porting to Linux 2.6.9
26 //---------------------------------------------------------------------------
27 #include <linux/module.h>
28 #include <linux/kernel.h>
29 #include <linux/sched.h>
30 #include <linux/errno.h>
31 #include <linux/poll.h>
32 #include <linux/netdevice.h>
33 #include <linux/delay.h>
35 #include <linux/ioctl.h>
36 #include <linux/debugfs.h>
37 #include "ft1000_usb.h"
39 static int ft1000_flarion_cnt = 0;
41 static int ft1000_open (struct inode *inode, struct file *file);
42 static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait);
43 static long ft1000_ioctl(struct file *file, unsigned int command,
44 unsigned long argument);
45 static int ft1000_release (struct inode *inode, struct file *file);
47 // List to free receive command buffer pool
48 struct list_head freercvpool;
50 // lock to arbitrate free buffer list for receive command data
51 spinlock_t free_buff_lock;
53 int numofmsgbuf = 0;
56 // Table of entry-point routines for char device
58 static struct file_operations ft1000fops =
60 .unlocked_ioctl = ft1000_ioctl,
61 .poll = ft1000_poll_dev,
62 .open = ft1000_open,
63 .release = ft1000_release,
64 .llseek = no_llseek,
67 //---------------------------------------------------------------------------
68 // Function: ft1000_get_buffer
70 // Parameters:
72 // Returns:
74 // Description:
76 // Notes:
78 //---------------------------------------------------------------------------
79 struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist)
81 unsigned long flags;
82 struct dpram_blk *ptr;
84 spin_lock_irqsave(&free_buff_lock, flags);
85 // Check if buffer is available
86 if ( list_empty(bufflist) ) {
87 DEBUG("ft1000_get_buffer: No more buffer - %d\n", numofmsgbuf);
88 ptr = NULL;
90 else {
91 numofmsgbuf--;
92 ptr = list_entry(bufflist->next, struct dpram_blk, list);
93 list_del(&ptr->list);
94 //DEBUG("ft1000_get_buffer: number of free msg buffers = %d\n", numofmsgbuf);
96 spin_unlock_irqrestore(&free_buff_lock, flags);
98 return ptr;
104 //---------------------------------------------------------------------------
105 // Function: ft1000_free_buffer
107 // Parameters:
109 // Returns:
111 // Description:
113 // Notes:
115 //---------------------------------------------------------------------------
116 void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist)
118 unsigned long flags;
120 spin_lock_irqsave(&free_buff_lock, flags);
121 // Put memory back to list
122 list_add_tail(&pdpram_blk->list, plist);
123 numofmsgbuf++;
124 //DEBUG("ft1000_free_buffer: number of free msg buffers = %d\n", numofmsgbuf);
125 spin_unlock_irqrestore(&free_buff_lock, flags);
128 //---------------------------------------------------------------------------
129 // Function: ft1000_CreateDevice
131 // Parameters: dev - pointer to adapter object
133 // Returns: 0 if successful
135 // Description: Creates a private char device.
137 // Notes: Only called by init_module().
139 //---------------------------------------------------------------------------
140 int ft1000_create_dev(struct ft1000_device *dev)
142 struct ft1000_info *info = netdev_priv(dev->net);
143 int result;
144 int i;
145 struct dentry *dir, *file;
146 struct ft1000_debug_dirs *tmp;
148 // make a new device name
149 sprintf(info->DeviceName, "%s%d", "FT1000_", info->CardNumber);
151 DEBUG("ft1000_CreateDevice: number of instance = %d\n", ft1000_flarion_cnt);
152 DEBUG("DeviceCreated = %x\n", info->DeviceCreated);
154 if (info->DeviceCreated)
156 DEBUG("ft1000_CreateDevice: \"%s\" already registered\n", info->DeviceName);
157 return -EIO;
161 // register the device
162 DEBUG("ft1000_CreateDevice: \"%s\" device registration\n", info->DeviceName);
164 tmp = kmalloc(sizeof(struct ft1000_debug_dirs), GFP_KERNEL);
165 if (tmp == NULL) {
166 result = -1;
167 goto fail;
170 dir = debugfs_create_dir(info->DeviceName, 0);
171 if (IS_ERR(dir)) {
172 result = PTR_ERR(dir);
173 goto debug_dir_fail;
176 file = debugfs_create_file("device", S_IRUGO | S_IWUGO, dir,
177 NULL, &ft1000fops);
178 if (IS_ERR(file)) {
179 result = PTR_ERR(file);
180 goto debug_file_fail;
183 tmp->dent = dir;
184 tmp->file = file;
185 tmp->int_number = info->CardNumber;
186 list_add(&(tmp->list), &(info->nodes.list));
188 DEBUG("ft1000_CreateDevice: registered char device \"%s\"\n", info->DeviceName);
190 // initialize application information
191 info->appcnt = 0;
192 for (i=0; i<MAX_NUM_APP; i++) {
193 info->app_info[i].nTxMsg = 0;
194 info->app_info[i].nRxMsg = 0;
195 info->app_info[i].nTxMsgReject = 0;
196 info->app_info[i].nRxMsgMiss = 0;
197 info->app_info[i].fileobject = NULL;
198 info->app_info[i].app_id = i+1;
199 info->app_info[i].DspBCMsgFlag = 0;
200 info->app_info[i].NumOfMsg = 0;
201 init_waitqueue_head(&info->app_info[i].wait_dpram_msg);
202 INIT_LIST_HEAD (&info->app_info[i].app_sqlist);
205 info->DeviceCreated = TRUE;
206 ft1000_flarion_cnt++;
208 return 0;
210 debug_file_fail:
211 debugfs_remove(dir);
212 debug_dir_fail:
213 kfree(tmp);
214 fail:
215 return result;
218 //---------------------------------------------------------------------------
219 // Function: ft1000_DestroyDeviceDEBUG
221 // Parameters: dev - pointer to adapter object
223 // Description: Destroys a private char device.
225 // Notes: Only called by cleanup_module().
227 //---------------------------------------------------------------------------
228 void ft1000_destroy_dev(struct net_device *dev)
230 struct ft1000_info *info = netdev_priv(dev);
231 int i;
232 struct dpram_blk *pdpram_blk;
233 struct dpram_blk *ptr;
234 struct list_head *pos, *q;
235 struct ft1000_debug_dirs *dir;
237 DEBUG("ft1000_chdev:ft1000_DestroyDevice called\n");
241 if (info->DeviceCreated)
243 ft1000_flarion_cnt--;
244 list_for_each_safe(pos, q, &info->nodes.list) {
245 dir = list_entry(pos, struct ft1000_debug_dirs, list);
246 if (dir->int_number == info->CardNumber) {
247 debugfs_remove(dir->file);
248 debugfs_remove(dir->dent);
249 list_del(pos);
250 kfree(dir);
253 DEBUG("ft1000_DestroyDevice: unregistered device \"%s\"\n",
254 info->DeviceName);
256 // Make sure we free any memory reserve for slow Queue
257 for (i=0; i<MAX_NUM_APP; i++) {
258 while (list_empty(&info->app_info[i].app_sqlist) == 0) {
259 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list);
260 list_del(&pdpram_blk->list);
261 ft1000_free_buffer(pdpram_blk, &freercvpool);
264 wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
267 // Remove buffer allocated for receive command data
268 if (ft1000_flarion_cnt == 0) {
269 while (list_empty(&freercvpool) == 0) {
270 ptr = list_entry(freercvpool.next, struct dpram_blk, list);
271 list_del(&ptr->list);
272 kfree(ptr->pbuffer);
273 kfree(ptr);
276 info->DeviceCreated = FALSE;
282 //---------------------------------------------------------------------------
283 // Function: ft1000_open
285 // Parameters:
287 // Description:
289 // Notes:
291 //---------------------------------------------------------------------------
292 static int ft1000_open (struct inode *inode, struct file *file)
294 struct ft1000_info *info;
295 struct ft1000_device *dev = (struct ft1000_device *)inode->i_private;
296 int i,num;
298 DEBUG("ft1000_open called\n");
299 num = (MINOR(inode->i_rdev) & 0xf);
300 DEBUG("ft1000_open: minor number=%d\n", num);
302 info = file->private_data = netdev_priv(dev->net);
304 DEBUG("f_owner = %p number of application = %d\n", (&file->f_owner), info->appcnt );
306 // Check if maximum number of application exceeded
307 if (info->appcnt > MAX_NUM_APP) {
308 DEBUG("Maximum number of application exceeded\n");
309 return -EACCES;
312 // Search for available application info block
313 for (i=0; i<MAX_NUM_APP; i++) {
314 if ( (info->app_info[i].fileobject == NULL) ) {
315 break;
319 // Fail due to lack of application info block
320 if (i == MAX_NUM_APP) {
321 DEBUG("Could not find an application info block\n");
322 return -EACCES;
325 info->appcnt++;
326 info->app_info[i].fileobject = &file->f_owner;
327 info->app_info[i].nTxMsg = 0;
328 info->app_info[i].nRxMsg = 0;
329 info->app_info[i].nTxMsgReject = 0;
330 info->app_info[i].nRxMsgMiss = 0;
332 nonseekable_open(inode, file);
333 return 0;
337 //---------------------------------------------------------------------------
338 // Function: ft1000_poll_dev
340 // Parameters:
342 // Description:
344 // Notes:
346 //---------------------------------------------------------------------------
348 static unsigned int ft1000_poll_dev(struct file *file, poll_table *wait)
350 struct net_device *dev = file->private_data;
351 struct ft1000_info *info;
352 int i;
354 //DEBUG("ft1000_poll_dev called\n");
355 if (ft1000_flarion_cnt == 0) {
356 DEBUG("FT1000:ft1000_poll_dev called when ft1000_flarion_cnt is zero\n");
357 return (-EBADF);
360 info = netdev_priv(dev);
362 // Search for matching file object
363 for (i=0; i<MAX_NUM_APP; i++) {
364 if ( info->app_info[i].fileobject == &file->f_owner) {
365 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id);
366 break;
370 // Could not find application info block
371 if (i == MAX_NUM_APP) {
372 DEBUG("FT1000:ft1000_ioctl:Could not find application info block\n");
373 return ( -EACCES );
376 if (list_empty(&info->app_info[i].app_sqlist) == 0) {
377 DEBUG("FT1000:ft1000_poll_dev:Message detected in slow queue\n");
378 return(POLLIN | POLLRDNORM | POLLPRI);
381 poll_wait (file, &info->app_info[i].wait_dpram_msg, wait);
382 //DEBUG("FT1000:ft1000_poll_dev:Polling for data from DSP\n");
384 return (0);
387 //---------------------------------------------------------------------------
388 // Function: ft1000_ioctl
390 // Parameters:
392 // Description:
394 // Notes:
396 //---------------------------------------------------------------------------
397 static long ft1000_ioctl (struct file *file, unsigned int command,
398 unsigned long argument)
400 void __user *argp = (void __user *)argument;
401 struct net_device *dev;
402 struct ft1000_info *info;
403 struct ft1000_device *ft1000dev;
404 int result=0;
405 int cmd;
406 int i;
407 u16 tempword;
408 unsigned long flags;
409 struct timeval tv;
410 IOCTL_GET_VER get_ver_data;
411 IOCTL_GET_DSP_STAT get_stat_data;
412 u8 ConnectionMsg[] = {0x00,0x44,0x10,0x20,0x80,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x93,0x64,
413 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0a,
414 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
415 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
416 0x00,0x00,0x02,0x37,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x01,0x00,0x01,0x7f,0x00,
417 0x00,0x01,0x00,0x00};
419 unsigned short ledStat=0;
420 unsigned short conStat=0;
422 //DEBUG("ft1000_ioctl called\n");
424 if (ft1000_flarion_cnt == 0) {
425 DEBUG("FT1000:ft1000_ioctl called when ft1000_flarion_cnt is zero\n");
426 return (-EBADF);
429 //DEBUG("FT1000:ft1000_ioctl:command = 0x%x argument = 0x%8x\n", command, (u32)argument);
431 dev = file->private_data;
432 info = netdev_priv(dev);
433 ft1000dev = info->pFt1000Dev;
434 cmd = _IOC_NR(command);
435 //DEBUG("FT1000:ft1000_ioctl:cmd = 0x%x\n", cmd);
437 // process the command
438 switch (cmd) {
439 case IOCTL_REGISTER_CMD:
440 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_REGISTER called\n");
441 result = get_user(tempword, (__u16 __user*)argp);
442 if (result) {
443 DEBUG("result = %d failed to get_user\n", result);
444 break;
446 if (tempword == DSPBCMSGID) {
447 // Search for matching file object
448 for (i=0; i<MAX_NUM_APP; i++) {
449 if ( info->app_info[i].fileobject == &file->f_owner) {
450 info->app_info[i].DspBCMsgFlag = 1;
451 DEBUG("FT1000:ft1000_ioctl:Registered for broadcast messages\n");
452 break;
456 break;
458 case IOCTL_GET_VER_CMD:
459 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_VER called\n");
461 get_ver_data.drv_ver = FT1000_DRV_VER;
463 if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data)) ) {
464 DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n");
465 result = -EFAULT;
466 break;
469 DEBUG("FT1000:ft1000_ioctl:driver version = 0x%x\n",(unsigned int)get_ver_data.drv_ver);
471 break;
472 case IOCTL_CONNECT:
473 // Connect Message
474 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_CONNECT\n");
475 ConnectionMsg[79] = 0xfc;
476 CardSendCommand(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c);
478 break;
479 case IOCTL_DISCONNECT:
480 // Disconnect Message
481 DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_DISCONNECT\n");
482 ConnectionMsg[79] = 0xfd;
483 CardSendCommand(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c);
484 break;
485 case IOCTL_GET_DSP_STAT_CMD:
486 //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DSP_STAT called\n");
487 memset(&get_stat_data, 0, sizeof(get_stat_data));
488 memcpy(get_stat_data.DspVer, info->DspVer, DSPVERSZ);
489 memcpy(get_stat_data.HwSerNum, info->HwSerNum, HWSERNUMSZ);
490 memcpy(get_stat_data.Sku, info->Sku, SKUSZ);
491 memcpy(get_stat_data.eui64, info->eui64, EUISZ);
493 if (info->ProgConStat != 0xFF) {
494 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED, (u8 *)&ledStat, FT1000_MAG_DSP_LED_INDX);
495 get_stat_data.LedStat = ntohs(ledStat);
496 DEBUG("FT1000:ft1000_ioctl: LedStat = 0x%x\n", get_stat_data.LedStat);
497 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE, (u8 *)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
498 get_stat_data.ConStat = ntohs(conStat);
499 DEBUG("FT1000:ft1000_ioctl: ConStat = 0x%x\n", get_stat_data.ConStat);
501 else {
502 get_stat_data.ConStat = 0x0f;
506 get_stat_data.nTxPkts = info->stats.tx_packets;
507 get_stat_data.nRxPkts = info->stats.rx_packets;
508 get_stat_data.nTxBytes = info->stats.tx_bytes;
509 get_stat_data.nRxBytes = info->stats.rx_bytes;
510 do_gettimeofday ( &tv );
511 get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm);
512 DEBUG("Connection Time = %d\n", (int)get_stat_data.ConTm);
513 if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data)) ) {
514 DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n");
515 result = -EFAULT;
516 break;
518 DEBUG("ft1000_chioctl: GET_DSP_STAT succeed\n");
519 break;
520 case IOCTL_SET_DPRAM_CMD:
522 IOCTL_DPRAM_BLK *dpram_data = NULL;
523 //IOCTL_DPRAM_COMMAND dpram_command;
524 u16 qtype;
525 u16 msgsz;
526 struct pseudo_hdr *ppseudo_hdr;
527 u16 *pmsg;
528 u16 total_len;
529 u16 app_index;
530 u16 status;
532 //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_SET_DPRAM called\n");
535 if (ft1000_flarion_cnt == 0) {
536 return (-EBADF);
539 if (info->DrvMsgPend) {
540 return (-ENOTTY);
543 if ( (info->DspAsicReset) || (info->fProvComplete == 0) ) {
544 return (-EACCES);
547 info->fAppMsgPend = 1;
549 if (info->CardReady) {
551 //DEBUG("FT1000:ft1000_ioctl: try to SET_DPRAM \n");
553 // Get the length field to see how many bytes to copy
554 result = get_user(msgsz, (__u16 __user *)argp);
555 msgsz = ntohs (msgsz);
556 //DEBUG("FT1000:ft1000_ioctl: length of message = %d\n", msgsz);
558 if (msgsz > MAX_CMD_SQSIZE) {
559 DEBUG("FT1000:ft1000_ioctl: bad message length = %d\n", msgsz);
560 result = -EINVAL;
561 break;
564 result = -ENOMEM;
565 dpram_data = kmalloc(msgsz + 2, GFP_KERNEL);
566 if (!dpram_data)
567 break;
569 if ( copy_from_user(dpram_data, argp, msgsz+2) ) {
570 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
571 result = -EFAULT;
573 else {
574 // Check if this message came from a registered application
575 for (i=0; i<MAX_NUM_APP; i++) {
576 if ( info->app_info[i].fileobject == &file->f_owner) {
577 break;
580 if (i==MAX_NUM_APP) {
581 DEBUG("FT1000:No matching application fileobject\n");
582 result = -EINVAL;
583 kfree(dpram_data);
584 break;
586 app_index = i;
588 // Check message qtype type which is the lower byte within qos_class
589 qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff;
590 //DEBUG("FT1000_ft1000_ioctl: qtype = %d\n", qtype);
591 if (qtype) {
593 else {
594 // Put message into Slow Queue
595 // Only put a message into the DPRAM if msg doorbell is available
596 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
597 //DEBUG("FT1000_ft1000_ioctl: READ REGISTER tempword=%x\n", tempword);
598 if (tempword & FT1000_DB_DPRAM_TX) {
599 // Suspend for 2ms and try again due to DSP doorbell busy
600 mdelay(2);
601 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
602 if (tempword & FT1000_DB_DPRAM_TX) {
603 // Suspend for 1ms and try again due to DSP doorbell busy
604 mdelay(1);
605 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
606 if (tempword & FT1000_DB_DPRAM_TX) {
607 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
608 if (tempword & FT1000_DB_DPRAM_TX) {
609 // Suspend for 3ms and try again due to DSP doorbell busy
610 mdelay(3);
611 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
612 if (tempword & FT1000_DB_DPRAM_TX) {
613 DEBUG("FT1000:ft1000_ioctl:Doorbell not available\n");
614 result = -ENOTTY;
615 kfree(dpram_data);
616 break;
623 //DEBUG("FT1000_ft1000_ioctl: finished reading register\n");
625 // Make sure we are within the limits of the slow queue memory limitation
626 if ( (msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ) ) {
627 // Need to put sequence number plus new checksum for message
628 pmsg = (u16 *)&dpram_data->pseudohdr;
629 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
630 total_len = msgsz+2;
631 if (total_len & 0x1) {
632 total_len++;
635 // Insert slow queue sequence number
636 ppseudo_hdr->seq_num = info->squeseqnum++;
637 ppseudo_hdr->portsrc = info->app_info[app_index].app_id;
638 // Calculate new checksum
639 ppseudo_hdr->checksum = *pmsg++;
640 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
641 for (i=1; i<7; i++) {
642 ppseudo_hdr->checksum ^= *pmsg++;
643 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
645 pmsg++;
646 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
647 CardSendCommand(ft1000dev,(unsigned short*)dpram_data,total_len+2);
650 info->app_info[app_index].nTxMsg++;
652 else {
653 result = -EINVAL;
658 else {
659 DEBUG("FT1000:ft1000_ioctl: Card not ready take messages\n");
660 result = -EACCES;
662 kfree(dpram_data);
665 break;
666 case IOCTL_GET_DPRAM_CMD:
668 struct dpram_blk *pdpram_blk;
669 IOCTL_DPRAM_BLK __user *pioctl_dpram;
670 int msglen;
672 //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DPRAM called\n");
674 if (ft1000_flarion_cnt == 0) {
675 return (-EBADF);
678 // Search for matching file object
679 for (i=0; i<MAX_NUM_APP; i++) {
680 if ( info->app_info[i].fileobject == &file->f_owner) {
681 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id);
682 break;
686 // Could not find application info block
687 if (i == MAX_NUM_APP) {
688 DEBUG("FT1000:ft1000_ioctl:Could not find application info block\n");
689 result = -EBADF;
690 break;
693 result = 0;
694 pioctl_dpram = argp;
695 if (list_empty(&info->app_info[i].app_sqlist) == 0) {
696 //DEBUG("FT1000:ft1000_ioctl:Message detected in slow queue\n");
697 spin_lock_irqsave(&free_buff_lock, flags);
698 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list);
699 list_del(&pdpram_blk->list);
700 info->app_info[i].NumOfMsg--;
701 //DEBUG("FT1000:ft1000_ioctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg);
702 spin_unlock_irqrestore(&free_buff_lock, flags);
703 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
704 result = get_user(msglen, &pioctl_dpram->total_len);
705 if (result)
706 break;
707 msglen = htons(msglen);
708 //DEBUG("FT1000:ft1000_ioctl:msg length = %x\n", msglen);
709 if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen))
711 DEBUG("FT1000:ft1000_ioctl: copy fault occurred\n");
712 result = -EFAULT;
713 break;
716 ft1000_free_buffer(pdpram_blk, &freercvpool);
717 result = msglen;
719 //DEBUG("FT1000:ft1000_ioctl: IOCTL_FT1000_GET_DPRAM no message\n");
721 break;
723 default:
724 DEBUG("FT1000:ft1000_ioctl:unknown command: 0x%x\n", command);
725 result = -ENOTTY;
726 break;
728 info->fAppMsgPend = 0;
729 return result;
732 //---------------------------------------------------------------------------
733 // Function: ft1000_release
735 // Parameters:
737 // Description:
739 // Notes:
741 //---------------------------------------------------------------------------
742 static int ft1000_release (struct inode *inode, struct file *file)
744 struct ft1000_info *info;
745 struct net_device *dev;
746 int i;
747 struct dpram_blk *pdpram_blk;
749 DEBUG("ft1000_release called\n");
751 dev = file->private_data;
752 info = netdev_priv(dev);
754 if (ft1000_flarion_cnt == 0) {
755 info->appcnt--;
756 return (-EBADF);
759 // Search for matching file object
760 for (i=0; i<MAX_NUM_APP; i++) {
761 if ( info->app_info[i].fileobject == &file->f_owner) {
762 //DEBUG("FT1000:ft1000_ioctl: Message is for AppId = %d\n", info->app_info[i].app_id);
763 break;
767 if (i==MAX_NUM_APP)
768 return 0;
770 while (list_empty(&info->app_info[i].app_sqlist) == 0) {
771 DEBUG("Remove and free memory queue up on slow queue\n");
772 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list);
773 list_del(&pdpram_blk->list);
774 ft1000_free_buffer(pdpram_blk, &freercvpool);
777 // initialize application information
778 info->appcnt--;
779 DEBUG("ft1000_chdev:%s:appcnt = %d\n", __FUNCTION__, info->appcnt);
780 info->app_info[i].fileobject = NULL;
782 return 0;