1 //---------------------------------------------------------------------------
2 // FT1000 driver for Flarion Flash OFDM NIC Device
4 // Copyright (C) 2006 Flarion Technologies, All rights reserved.
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.
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/signal.h>
31 #include <linux/errno.h>
32 #include <linux/poll.h>
33 #include <linux/netdevice.h>
34 #include <linux/delay.h>
37 #include <linux/kmod.h>
38 #include <linux/ioctl.h>
39 #include <linux/unistd.h>
41 #include "ft1000_usb.h"
42 //#include "ft1000_ioctl.h"
44 static int ft1000_flarion_cnt = 0;
46 //need to looking usage of ft1000Handle
48 static int ft1000_ChOpen (struct inode *Inode, struct file *File);
49 static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait);
50 static long ft1000_ChIoctl(struct file *File, unsigned int Command,
51 unsigned long Argument);
52 static int ft1000_ChRelease (struct inode *Inode, struct file *File);
54 // Global pointer to device object
55 static struct ft1000_device *pdevobj[MAX_NUM_CARDS + 2];
56 //static devfs_handle_t ft1000Handle[MAX_NUM_CARDS];
58 // List to free receive command buffer pool
59 struct list_head freercvpool;
61 // lock to arbitrate free buffer list for receive command data
62 spinlock_t free_buff_lock;
66 // Global variable to indicate that all provisioning data is sent to DSP
67 //BOOLEAN fProvComplete;
70 // Table of entry-point routines for char device
72 static struct file_operations ft1000fops =
74 .unlocked_ioctl = ft1000_ChIoctl,
75 .poll = ft1000_ChPoll,
76 .open = ft1000_ChOpen,
77 .release = ft1000_ChRelease,
84 //---------------------------------------------------------------------------
85 // Function: exec_mknod
95 //---------------------------------------------------------------------------
96 static int exec_mknod (void *pdata)
98 struct ft1000_info *info;
103 // int i; //aelias [-] reason : unused variable
104 char *envp[] = { "HOME=/", "PATH=/usr/bin:/bin", NULL };
105 char *argv[]={"-m 666",temp,"c",mjnum,minornum,NULL};
108 DEBUG("ft1000_chdev:exec_mknod is called with major number = %d\n", info->DeviceMajor);
109 sprintf(temp, "%s%s", "/dev/", info->DeviceName) ;
110 sprintf(mjnum, "%d", info->DeviceMajor);
111 sprintf(minornum, "%d", info->CardNumber);
113 //char *argv[]={"mknod","-m 666",temp,"c",mjnum,minornum,NULL};
114 // char *argv[]={"-m 666",temp,"c",mjnum,minornum,NULL};
117 // DEBUG("argv[%d]=%s\n", i, argv[i]);
120 retcode = call_usermodehelper ("/bin/mknod", argv, envp, 1);
122 DEBUG("ft1000_chdev:exec_mknod failed to make the node: retcode = %d\n", retcode);
131 //---------------------------------------------------------------------------
132 // Function: rm_mknod
134 // Description: This module removes the FT1000 device file
136 //---------------------------------------------------------------------------
137 static int rm_mknod (void *pdata)
140 struct ft1000_info *info;
141 //char *argv[4]={"rm", "-f", "/dev/FT1000", NULL};
144 char *argv[]={"rm", "-f", temp, NULL};
146 info = (struct ft1000_info *)pdata;
147 DEBUG("ft1000_chdev:rm_mknod is called for device %s\n", info->DeviceName);
148 sprintf(temp, "%s%s", "/dev/", info->DeviceName) ;
150 // char *argv[]={"rm", "-f", temp, NULL};
152 retcode = call_usermodehelper ("/bin/rm", argv, NULL, 1);
154 DEBUG("ft1000_chdev:rm_mknod failed to remove the node: retcode = %d\n", retcode);
157 DEBUG("ft1000_chdev:rm_mknod done!\n");
163 //---------------------------------------------------------------------------
164 // Function: ft1000_get_buffer
174 //---------------------------------------------------------------------------
175 struct dpram_blk *ft1000_get_buffer(struct list_head *bufflist)
178 struct dpram_blk *ptr;
180 spin_lock_irqsave(&free_buff_lock, flags);
181 // Check if buffer is available
182 if ( list_empty(bufflist) ) {
183 DEBUG("ft1000_get_buffer: No more buffer - %d\n", numofmsgbuf);
188 ptr = list_entry(bufflist->next, struct dpram_blk, list);
189 list_del(&ptr->list);
190 //DEBUG("ft1000_get_buffer: number of free msg buffers = %d\n", numofmsgbuf);
192 spin_unlock_irqrestore(&free_buff_lock, flags);
200 //---------------------------------------------------------------------------
201 // Function: ft1000_free_buffer
211 //---------------------------------------------------------------------------
212 void ft1000_free_buffer(struct dpram_blk *pdpram_blk, struct list_head *plist)
216 spin_lock_irqsave(&free_buff_lock, flags);
217 // Put memory back to list
218 list_add_tail(&pdpram_blk->list, plist);
220 //DEBUG("ft1000_free_buffer: number of free msg buffers = %d\n", numofmsgbuf);
221 spin_unlock_irqrestore(&free_buff_lock, flags);
224 //---------------------------------------------------------------------------
225 // Function: ft1000_CreateDevice
227 // Parameters: dev - pointer to adapter object
229 // Returns: 0 if successful
231 // Description: Creates a private char device.
233 // Notes: Only called by init_module().
235 //---------------------------------------------------------------------------
236 int ft1000_CreateDevice(struct ft1000_device *dev)
238 struct ft1000_info *info = netdev_priv(dev->net);
243 // make a new device name
244 sprintf(info->DeviceName, "%s%d", "FT100", info->CardNumber);
246 // Delete any existing FT1000 node
247 pid = kernel_thread (rm_mknod,(void *)info, 0);
250 DEBUG("ft1000_CreateDevice: number of instance = %d\n", ft1000_flarion_cnt);
251 DEBUG("DeviceCreated = %x\n", info->DeviceCreated);
253 //save the device info to global array
254 pdevobj[info->CardNumber] = dev;
256 DEBUG("ft1000_CreateDevice: ******SAVED pdevobj[%d]=%p\n", info->CardNumber, pdevobj[info->CardNumber]); //aelias [+] reason:up
258 if (info->DeviceCreated)
260 DEBUG("ft1000_CreateDevice: \"%s\" already registered\n", info->DeviceName);
265 // register the device
266 DEBUG("ft1000_CreateDevice: \"%s\" device registration\n", info->DeviceName);
267 info->DeviceMajor = 0;
269 result = register_chrdev(info->DeviceMajor, info->DeviceName, &ft1000fops);
272 DEBUG("ft1000_CreateDevice: unable to get major %d\n", info->DeviceMajor);
276 DEBUG("ft1000_CreateDevice: registered char device \"%s\"\n", info->DeviceName);
278 // save a dynamic device major number
279 if (info->DeviceMajor == 0)
281 info->DeviceMajor = result;
282 DEBUG("ft1000_PcdCreateDevice: device major = %d\n", info->DeviceMajor);
285 // Create a thread to call user mode app to mknod
286 pid = kernel_thread (exec_mknod, (void *)info, 0);
288 // initialize application information
291 // if (ft1000_flarion_cnt == 0) {
293 // DEBUG("Initialize free_buff_lock and freercvpool\n");
294 // spin_lock_init(&free_buff_lock);
296 // // initialize a list of buffers to be use for queuing up receive command data
297 // INIT_LIST_HEAD (&freercvpool);
299 // // create list of free buffers
300 // for (i=0; i<NUM_OF_FREE_BUFFERS; i++) {
301 // // Get memory for DPRAM_DATA link list
302 // pdpram_blk = kmalloc ( sizeof(struct dpram_blk), GFP_KERNEL );
303 // // Get a block of memory to store command data
304 // pdpram_blk->pbuffer = kmalloc ( MAX_CMD_SQSIZE, GFP_KERNEL );
305 // // link provisioning data
306 // list_add_tail (&pdpram_blk->list, &freercvpool);
308 // numofmsgbuf = NUM_OF_FREE_BUFFERS;
312 // initialize application information
314 for (i=0; i<MAX_NUM_APP; i++) {
315 info->app_info[i].nTxMsg = 0;
316 info->app_info[i].nRxMsg = 0;
317 info->app_info[i].nTxMsgReject = 0;
318 info->app_info[i].nRxMsgMiss = 0;
319 info->app_info[i].fileobject = NULL;
320 info->app_info[i].app_id = i+1;
321 info->app_info[i].DspBCMsgFlag = 0;
322 info->app_info[i].NumOfMsg = 0;
323 init_waitqueue_head(&info->app_info[i].wait_dpram_msg);
324 INIT_LIST_HEAD (&info->app_info[i].app_sqlist);
330 // ft1000Handle[info->CardNumber] = devfs_register(NULL, info->DeviceName, DEVFS_FL_AUTO_DEVNUM, 0, 0,
331 // S_IFCHR | S_IRUGO | S_IWUGO, &ft1000fops, NULL);
334 info->DeviceCreated = TRUE;
335 ft1000_flarion_cnt++;
340 //---------------------------------------------------------------------------
341 // Function: ft1000_DestroyDeviceDEBUG
343 // Parameters: dev - pointer to adapter object
345 // Description: Destroys a private char device.
347 // Notes: Only called by cleanup_module().
349 //---------------------------------------------------------------------------
350 void ft1000_DestroyDevice(struct net_device *dev)
352 struct ft1000_info *info = netdev_priv(dev);
356 struct dpram_blk *pdpram_blk;
357 struct dpram_blk *ptr;
359 DEBUG("ft1000_chdev:ft1000_DestroyDevice called\n");
363 if (info->DeviceCreated)
365 ft1000_flarion_cnt--;
366 unregister_chrdev(info->DeviceMajor, info->DeviceName);
367 DEBUG("ft1000_DestroyDevice: unregistered device \"%s\", result = %d\n",
368 info->DeviceName, result);
370 pid = kernel_thread (rm_mknod, (void *)info, 0);
372 // Make sure we free any memory reserve for slow Queue
373 for (i=0; i<MAX_NUM_APP; i++) {
374 while (list_empty(&info->app_info[i].app_sqlist) == 0) {
375 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list);
376 list_del(&pdpram_blk->list);
377 ft1000_free_buffer(pdpram_blk, &freercvpool);
380 wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
383 // Remove buffer allocated for receive command data
384 if (ft1000_flarion_cnt == 0) {
385 while (list_empty(&freercvpool) == 0) {
386 ptr = list_entry(freercvpool.next, struct dpram_blk, list);
387 list_del(&ptr->list);
393 // devfs_unregister(ft1000Handle[info->CardNumber]);
395 info->DeviceCreated = FALSE;
397 pdevobj[info->CardNumber] = NULL;
403 //---------------------------------------------------------------------------
404 // Function: ft1000_ChOpen
412 //---------------------------------------------------------------------------
413 static int ft1000_ChOpen (struct inode *Inode, struct file *File)
415 struct ft1000_info *info;
418 DEBUG("ft1000_ChOpen called\n");
419 num = (MINOR(Inode->i_rdev) & 0xf);
420 DEBUG("ft1000_ChOpen: minor number=%d\n", num);
423 DEBUG("pdevobj[%d]=%p\n", i, pdevobj[i]); //aelias [+] reason: down
425 if ( pdevobj[num] != NULL )
426 //info = (struct ft1000_info *)(pdevobj[num]->net->priv);
427 info = (struct ft1000_info *)netdev_priv(pdevobj[num]->net);
430 DEBUG("ft1000_ChOpen: can not find device object %d\n", num);
434 DEBUG("f_owner = %p number of application = %d\n", (&File->f_owner), info->appcnt );
436 // Check if maximum number of application exceeded
437 if (info->appcnt > MAX_NUM_APP) {
438 DEBUG("Maximum number of application exceeded\n");
442 // Search for available application info block
443 for (i=0; i<MAX_NUM_APP; i++) {
444 if ( (info->app_info[i].fileobject == NULL) ) {
449 // Fail due to lack of application info block
450 if (i == MAX_NUM_APP) {
451 DEBUG("Could not find an application info block\n");
456 info->app_info[i].fileobject = &File->f_owner;
457 info->app_info[i].nTxMsg = 0;
458 info->app_info[i].nRxMsg = 0;
459 info->app_info[i].nTxMsgReject = 0;
460 info->app_info[i].nRxMsgMiss = 0;
462 File->private_data = pdevobj[num]->net;
464 nonseekable_open(Inode, File);
469 //---------------------------------------------------------------------------
470 // Function: ft1000_ChPoll
478 //---------------------------------------------------------------------------
480 static unsigned int ft1000_ChPoll(struct file *file, poll_table *wait)
482 struct net_device *dev = file->private_data;
483 struct ft1000_info *info;
486 //DEBUG("ft1000_ChPoll called\n");
487 if (ft1000_flarion_cnt == 0) {
488 DEBUG("FT1000:ft1000_ChPoll called when ft1000_flarion_cnt is zero\n");
492 info = (struct ft1000_info *) netdev_priv(dev);
494 // Search for matching file object
495 for (i=0; i<MAX_NUM_APP; i++) {
496 if ( info->app_info[i].fileobject == &file->f_owner) {
497 //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
502 // Could not find application info block
503 if (i == MAX_NUM_APP) {
504 DEBUG("FT1000:ft1000_ChIoctl:Could not find application info block\n");
508 if (list_empty(&info->app_info[i].app_sqlist) == 0) {
509 DEBUG("FT1000:ft1000_ChPoll:Message detected in slow queue\n");
510 return(POLLIN | POLLRDNORM | POLLPRI);
513 poll_wait (file, &info->app_info[i].wait_dpram_msg, wait);
514 //DEBUG("FT1000:ft1000_ChPoll:Polling for data from DSP\n");
519 //---------------------------------------------------------------------------
520 // Function: ft1000_ChIoctl
528 //---------------------------------------------------------------------------
529 static long ft1000_ChIoctl (struct file *File, unsigned int Command,
530 unsigned long Argument)
532 void __user *argp = (void __user *)Argument;
533 struct net_device *dev;
534 struct ft1000_info *info;
535 struct ft1000_device *ft1000dev;
542 IOCTL_GET_VER get_ver_data;
543 IOCTL_GET_DSP_STAT get_stat_data;
544 u8 ConnectionMsg[] = {0x00,0x44,0x10,0x20,0x80,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x93,0x64,
545 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0a,
546 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
547 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
548 0x00,0x00,0x02,0x37,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x01,0x00,0x01,0x7f,0x00,
549 0x00,0x01,0x00,0x00};
551 unsigned short ledStat=0;
552 unsigned short conStat=0;
554 //DEBUG("ft1000_ChIoctl called\n");
556 if (ft1000_flarion_cnt == 0) {
557 DEBUG("FT1000:ft1000_ChIoctl called when ft1000_flarion_cnt is zero\n");
561 //DEBUG("FT1000:ft1000_ChIoctl:Command = 0x%x Argument = 0x%8x\n", Command, (u32)Argument);
563 dev = File->private_data;
564 info = (struct ft1000_info *) netdev_priv(dev);
565 ft1000dev = info->pFt1000Dev;
566 cmd = _IOC_NR(Command);
567 //DEBUG("FT1000:ft1000_ChIoctl:cmd = 0x%x\n", cmd);
569 // process the command
571 case IOCTL_REGISTER_CMD:
572 DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_REGISTER called\n");
573 result = get_user(tempword, (__u16 __user*)argp);
575 DEBUG("result = %d failed to get_user\n", result);
578 if (tempword == DSPBCMSGID) {
579 // Search for matching file object
580 for (i=0; i<MAX_NUM_APP; i++) {
581 if ( info->app_info[i].fileobject == &File->f_owner) {
582 info->app_info[i].DspBCMsgFlag = 1;
583 DEBUG("FT1000:ft1000_ChIoctl:Registered for broadcast messages\n");
590 case IOCTL_GET_VER_CMD:
591 DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_VER called\n");
593 get_ver_data.drv_ver = FT1000_DRV_VER;
595 if (copy_to_user(argp, &get_ver_data, sizeof(get_ver_data)) ) {
596 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
601 DEBUG("FT1000:ft1000_ChIoctl:driver version = 0x%x\n",(unsigned int)get_ver_data.drv_ver);
606 DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_CONNECT\n");
607 ConnectionMsg[79] = 0xfc;
608 CardSendCommand(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c);
611 case IOCTL_DISCONNECT:
612 // Disconnect Message
613 DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_DISCONNECT\n");
614 ConnectionMsg[79] = 0xfd;
615 CardSendCommand(ft1000dev, (unsigned short *)ConnectionMsg, 0x4c);
617 case IOCTL_GET_DSP_STAT_CMD:
618 //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_DSP_STAT called\n");
619 memset(&get_stat_data, 0, sizeof(get_stat_data));
620 memcpy(get_stat_data.DspVer, info->DspVer, DSPVERSZ);
621 memcpy(get_stat_data.HwSerNum, info->HwSerNum, HWSERNUMSZ);
622 memcpy(get_stat_data.Sku, info->Sku, SKUSZ);
623 memcpy(get_stat_data.eui64, info->eui64, EUISZ);
625 if (info->ProgConStat != 0xFF) {
626 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_LED, (PUCHAR)&ledStat, FT1000_MAG_DSP_LED_INDX);
627 get_stat_data.LedStat = ntohs(ledStat);
628 DEBUG("FT1000:ft1000_ChIoctl: LedStat = 0x%x\n", get_stat_data.LedStat);
629 ft1000_read_dpram16(ft1000dev, FT1000_MAG_DSP_CON_STATE, (PUCHAR)&conStat, FT1000_MAG_DSP_CON_STATE_INDX);
630 get_stat_data.ConStat = ntohs(conStat);
631 DEBUG("FT1000:ft1000_ChIoctl: ConStat = 0x%x\n", get_stat_data.ConStat);
634 get_stat_data.ConStat = 0x0f;
638 get_stat_data.nTxPkts = info->stats.tx_packets;
639 get_stat_data.nRxPkts = info->stats.rx_packets;
640 get_stat_data.nTxBytes = info->stats.tx_bytes;
641 get_stat_data.nRxBytes = info->stats.rx_bytes;
642 do_gettimeofday ( &tv );
643 get_stat_data.ConTm = (u32)(tv.tv_sec - info->ConTm);
644 DEBUG("Connection Time = %d\n", (int)get_stat_data.ConTm);
645 if (copy_to_user(argp, &get_stat_data, sizeof(get_stat_data)) ) {
646 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
650 DEBUG("ft1000_chioctl: GET_DSP_STAT succeed\n");
652 case IOCTL_SET_DPRAM_CMD:
654 IOCTL_DPRAM_BLK *dpram_data;
655 //IOCTL_DPRAM_COMMAND dpram_command;
658 struct pseudo_hdr *ppseudo_hdr;
664 //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_SET_DPRAM called\n");
667 if (ft1000_flarion_cnt == 0) {
671 if (info->DrvMsgPend) {
675 if ( (info->DspAsicReset) || (info->fProvComplete == 0) ) {
679 info->fAppMsgPend = 1;
681 if (info->CardReady) {
683 //DEBUG("FT1000:ft1000_ChIoctl: try to SET_DPRAM \n");
685 // Get the length field to see how many bytes to copy
686 result = get_user(msgsz, (__u16 __user *)argp);
687 msgsz = ntohs (msgsz);
688 //DEBUG("FT1000:ft1000_ChIoctl: length of message = %d\n", msgsz);
690 if (msgsz > MAX_CMD_SQSIZE) {
691 DEBUG("FT1000:ft1000_ChIoctl: bad message length = %d\n", msgsz);
697 dpram_data = kmalloc(msgsz + 2, GFP_KERNEL);
701 //if ( copy_from_user(&(dpram_command.dpram_blk), (PIOCTL_DPRAM_BLK)Argument, msgsz+2) ) {
702 if ( copy_from_user(&dpram_data, argp, msgsz+2) ) {
703 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
708 // whc - for debugging only
709 ptr = (char *)&dpram_data;
710 for (i=0; i<msgsz; i++) {
711 DEBUG(1,"FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
714 // Check if this message came from a registered application
715 for (i=0; i<MAX_NUM_APP; i++) {
716 if ( info->app_info[i].fileobject == &File->f_owner) {
720 if (i==MAX_NUM_APP) {
721 DEBUG("FT1000:No matching application fileobject\n");
728 // Check message qtype type which is the lower byte within qos_class
729 //qtype = ntohs(dpram_command.dpram_blk.pseudohdr.qos_class) & 0xff;
730 qtype = ntohs(dpram_data->pseudohdr.qos_class) & 0xff;
731 //DEBUG("FT1000_ft1000_ChIoctl: qtype = %d\n", qtype);
735 // Put message into Slow Queue
736 // Only put a message into the DPRAM if msg doorbell is available
737 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
738 //DEBUG("FT1000_ft1000_ChIoctl: READ REGISTER tempword=%x\n", tempword);
739 if (tempword & FT1000_DB_DPRAM_TX) {
740 // Suspend for 2ms and try again due to DSP doorbell busy
742 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
743 if (tempword & FT1000_DB_DPRAM_TX) {
744 // Suspend for 1ms and try again due to DSP doorbell busy
746 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
747 if (tempword & FT1000_DB_DPRAM_TX) {
748 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
749 if (tempword & FT1000_DB_DPRAM_TX) {
750 // Suspend for 3ms and try again due to DSP doorbell busy
752 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_DOORBELL);
753 if (tempword & FT1000_DB_DPRAM_TX) {
754 DEBUG("FT1000:ft1000_ChIoctl:Doorbell not available\n");
764 //DEBUG("FT1000_ft1000_ChIoctl: finished reading register\n");
766 // Make sure we are within the limits of the slow queue memory limitation
767 if ( (msgsz < MAX_CMD_SQSIZE) && (msgsz > PSEUDOSZ) ) {
768 // Need to put sequence number plus new checksum for message
769 //pmsg = (PUSHORT)&dpram_command.dpram_blk.pseudohdr;
770 pmsg = (PUSHORT)&dpram_data->pseudohdr;
771 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
773 if (total_len & 0x1) {
777 // Insert slow queue sequence number
778 ppseudo_hdr->seq_num = info->squeseqnum++;
779 ppseudo_hdr->portsrc = info->app_info[app_index].app_id;
780 // Calculate new checksum
781 ppseudo_hdr->checksum = *pmsg++;
782 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
783 for (i=1; i<7; i++) {
784 ppseudo_hdr->checksum ^= *pmsg++;
785 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
788 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
791 DEBUG("FT1000:ft1000_ChIoctl: Command Send\n");
792 for (i=0; i<total_len; i++) {
793 DEBUG("FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
796 //dpram_command.extra = 0;
798 //CardSendCommand(ft1000dev,(unsigned char*)&dpram_command,total_len+2);
799 CardSendCommand(ft1000dev,(unsigned short*)dpram_data,total_len+2);
802 info->app_info[app_index].nTxMsg++;
811 DEBUG("FT1000:ft1000_ChIoctl: Card not ready take messages\n");
818 case IOCTL_GET_DPRAM_CMD:
820 struct dpram_blk *pdpram_blk;
821 IOCTL_DPRAM_BLK __user *pioctl_dpram;
824 //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_DPRAM called\n");
826 if (ft1000_flarion_cnt == 0) {
830 // Search for matching file object
831 for (i=0; i<MAX_NUM_APP; i++) {
832 if ( info->app_info[i].fileobject == &File->f_owner) {
833 //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
838 // Could not find application info block
839 if (i == MAX_NUM_APP) {
840 DEBUG("FT1000:ft1000_ChIoctl:Could not find application info block\n");
847 if (list_empty(&info->app_info[i].app_sqlist) == 0) {
848 //DEBUG("FT1000:ft1000_ChIoctl:Message detected in slow queue\n");
849 spin_lock_irqsave(&free_buff_lock, flags);
850 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list);
851 list_del(&pdpram_blk->list);
852 info->app_info[i].NumOfMsg--;
853 //DEBUG("FT1000:ft1000_ChIoctl:NumOfMsg for app %d = %d\n", i, info->app_info[i].NumOfMsg);
854 spin_unlock_irqrestore(&free_buff_lock, flags);
855 msglen = ntohs(*(u16 *)pdpram_blk->pbuffer) + PSEUDOSZ;
856 result = get_user(msglen, &pioctl_dpram->total_len);
859 msglen = htons(msglen);
860 //DEBUG("FT1000:ft1000_ChIoctl:msg length = %x\n", msglen);
861 if(copy_to_user (&pioctl_dpram->pseudohdr, pdpram_blk->pbuffer, msglen))
863 DEBUG("FT1000:ft1000_ChIoctl: copy fault occurred\n");
868 ft1000_free_buffer(pdpram_blk, &freercvpool);
871 //DEBUG("FT1000:ft1000_ChIoctl: IOCTL_FT1000_GET_DPRAM no message\n");
876 DEBUG("FT1000:ft1000_ChIoctl:unknown command: 0x%x\n", Command);
880 info->fAppMsgPend = 0;
884 //---------------------------------------------------------------------------
885 // Function: ft1000_ChRelease
893 //---------------------------------------------------------------------------
894 static int ft1000_ChRelease (struct inode *Inode, struct file *File)
896 struct ft1000_info *info;
897 struct net_device *dev;
899 struct dpram_blk *pdpram_blk;
901 DEBUG("ft1000_ChRelease called\n");
903 dev = File->private_data;
904 info = (struct ft1000_info *) netdev_priv(dev);
906 if (ft1000_flarion_cnt == 0) {
911 // Search for matching file object
912 for (i=0; i<MAX_NUM_APP; i++) {
913 if ( info->app_info[i].fileobject == &File->f_owner) {
914 //DEBUG("FT1000:ft1000_ChIoctl: Message is for AppId = %d\n", info->app_info[i].app_id);
922 while (list_empty(&info->app_info[i].app_sqlist) == 0) {
923 DEBUG("Remove and free memory queue up on slow queue\n");
924 pdpram_blk = list_entry(info->app_info[i].app_sqlist.next, struct dpram_blk, list);
925 list_del(&pdpram_blk->list);
926 ft1000_free_buffer(pdpram_blk, &freercvpool);
929 // initialize application information
931 DEBUG("ft1000_chdev:%s:appcnt = %d\n", __FUNCTION__, info->appcnt);
932 info->app_info[i].fileobject = NULL;