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>
39 static int ft1000_flarion_cnt = 0;
44 unsigned long argument);
60 .unlocked_ioctl = ft1000_ioctl,
61 .poll = ft1000_poll_dev,
63 .release = ft1000_release,
86 if ( list_empty(bufflist) ) {
96 spin_unlock_irqrestore(&free_buff_lock, flags);
125 spin_unlock_irqrestore(&free_buff_lock, flags);
151 DEBUG(
"%s: number of instance = %d\n", __func__, ft1000_flarion_cnt);
162 DEBUG(
"%s: \"%s\" debugfs device registration\n", __func__, info->
DeviceName);
172 result = PTR_ERR(dir);
179 result = PTR_ERR(file);
180 goto debug_file_fail;
186 list_add(&(tmp->
list), &(info->
nodes.list));
188 DEBUG(
"%s: registered debugfs directory \"%s\"\n", __func__, info->
DeviceName);
202 INIT_LIST_HEAD (&info->
app_info[i].app_sqlist);
206 ft1000_flarion_cnt++;
237 DEBUG(
"%s called\n", __func__);
243 ft1000_flarion_cnt--;
253 DEBUG(
"%s: unregistered device \"%s\"\n", __func__,
258 while (list_empty(&info->
app_info[i].app_sqlist) == 0) {
268 if (ft1000_flarion_cnt == 0) {
298 DEBUG(
"%s called\n", __func__);
300 DEBUG(
"ft1000_open: minor number=%d\n", num);
308 DEBUG(
"Maximum number of application exceeded\n");
320 if (i == MAX_NUM_APP) {
321 DEBUG(
"Could not find an application info block\n");
348 static unsigned int ft1000_poll_dev(
struct file *file,
poll_table *
wait)
355 if (ft1000_flarion_cnt == 0) {
356 DEBUG(
"FT1000:ft1000_poll_dev called when ft1000_flarion_cnt is zero\n");
360 info = netdev_priv(dev);
371 if (i == MAX_NUM_APP) {
372 DEBUG(
"FT1000:ft1000_ioctl:Could not find application info block\n");
376 if (list_empty(&info->
app_info[i].app_sqlist) == 0) {
377 DEBUG(
"FT1000:ft1000_poll_dev:Message detected in slow queue\n");
381 poll_wait (file, &info->
app_info[i].wait_dpram_msg, wait);
397 static long ft1000_ioctl (
struct file *file,
unsigned int command,
398 unsigned long argument)
409 IOCTL_GET_VER get_ver_data;
410 IOCTL_GET_DSP_STAT get_stat_data;
411 u8 ConnectionMsg[] = {0x00,0x44,0x10,0x20,0x80,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x93,0x64,
412 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x0a,
413 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
414 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
415 0x00,0x00,0x02,0x37,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x01,0x00,0x01,0x7f,0x00,
416 0x00,0x01,0x00,0x00};
418 unsigned short ledStat=0;
419 unsigned short conStat=0;
423 if (ft1000_flarion_cnt == 0) {
424 DEBUG(
"FT1000:ft1000_ioctl called when ft1000_flarion_cnt is zero\n");
438 DEBUG(
"FT1000:ft1000_ioctl: IOCTL_FT1000_REGISTER called\n");
441 DEBUG(
"result = %d failed to get_user\n", result);
449 DEBUG(
"FT1000:ft1000_ioctl:Registered for broadcast messages\n");
457 DEBUG(
"FT1000:ft1000_ioctl: IOCTL_FT1000_GET_VER called\n");
461 if (
copy_to_user(argp, &get_ver_data,
sizeof(get_ver_data)) ) {
462 DEBUG(
"FT1000:ft1000_ioctl: copy fault occurred\n");
467 DEBUG(
"FT1000:ft1000_ioctl:driver version = 0x%x\n",(
unsigned int)get_ver_data.drv_ver);
472 DEBUG(
"FT1000:ft1000_ioctl: IOCTL_FT1000_CONNECT\n");
473 ConnectionMsg[79] = 0xfc;
479 DEBUG(
"FT1000:ft1000_ioctl: IOCTL_FT1000_DISCONNECT\n");
480 ConnectionMsg[79] = 0xfd;
485 memset(&get_stat_data, 0,
sizeof(get_stat_data));
493 get_stat_data.LedStat =
ntohs(ledStat);
494 DEBUG(
"FT1000:ft1000_ioctl: LedStat = 0x%x\n", get_stat_data.LedStat);
496 get_stat_data.ConStat =
ntohs(conStat);
497 DEBUG(
"FT1000:ft1000_ioctl: ConStat = 0x%x\n", get_stat_data.ConStat);
500 get_stat_data.ConStat = 0x0f;
504 get_stat_data.nTxPkts = info->
stats.tx_packets;
505 get_stat_data.nRxPkts = info->
stats.rx_packets;
506 get_stat_data.nTxBytes = info->
stats.tx_bytes;
507 get_stat_data.nRxBytes = info->
stats.rx_bytes;
509 get_stat_data.ConTm = (
u32)(tv.tv_sec - info->
ConTm);
510 DEBUG(
"Connection Time = %d\n", (
int)get_stat_data.ConTm);
511 if (
copy_to_user(argp, &get_stat_data,
sizeof(get_stat_data)) ) {
512 DEBUG(
"FT1000:ft1000_ioctl: copy fault occurred\n");
516 DEBUG(
"ft1000_chioctl: GET_DSP_STAT succeed\n");
520 IOCTL_DPRAM_BLK *dpram_data =
NULL;
533 if (ft1000_flarion_cnt == 0) {
553 msgsz =
ntohs (msgsz);
557 DEBUG(
"FT1000:ft1000_ioctl: bad message length = %d\n", msgsz);
568 DEBUG(
"FT1000:ft1000_ChIoctl: copy fault occurred\n");
578 if (i==MAX_NUM_APP) {
579 DEBUG(
"FT1000:No matching application fileobject\n");
587 qtype =
ntohs(dpram_data->pseudohdr.qos_class) & 0xff;
600 if (tempword & FT1000_DB_DPRAM_TX) {
604 if (tempword & FT1000_DB_DPRAM_TX) {
606 if (tempword & FT1000_DB_DPRAM_TX) {
610 if (tempword & FT1000_DB_DPRAM_TX) {
611 DEBUG(
"FT1000:ft1000_ioctl:Doorbell not available\n");
626 pmsg = (
u16 *)&dpram_data->pseudohdr;
629 if (total_len & 0x1) {
639 for (i=1; i<7; i++) {
657 DEBUG(
"FT1000:ft1000_ioctl: Card not ready take messages\n");
667 IOCTL_DPRAM_BLK
__user *pioctl_dpram;
672 if (ft1000_flarion_cnt == 0) {
685 if (i == MAX_NUM_APP) {
686 DEBUG(
"FT1000:ft1000_ioctl:Could not find application info block\n");
693 if (list_empty(&info->
app_info[i].app_sqlist) == 0) {
700 spin_unlock_irqrestore(&free_buff_lock, flags);
702 result =
get_user(msglen, &pioctl_dpram->total_len);
705 msglen =
htons(msglen);
709 DEBUG(
"FT1000:ft1000_ioctl: copy fault occurred\n");
722 DEBUG(
"FT1000:ft1000_ioctl:unknown command: 0x%x\n", command);
740 static int ft1000_release (
struct inode *inode,
struct file *file)
747 DEBUG(
"ft1000_release called\n");
750 info = netdev_priv(dev);
752 if (ft1000_flarion_cnt == 0) {
768 while (list_empty(&info->
app_info[i].app_sqlist) == 0) {
769 DEBUG(
"Remove and free memory queue up on slow queue\n");