1 //=====================================================
2 // CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
5 // This file is part of Express Card USB Driver
8 //====================================================
9 // 20090926; aelias; removed compiler warnings & errors; ubuntu 9.04; 2.6.28-15-generic
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/netdevice.h>
15 #include <linux/etherdevice.h>
16 #include <linux/usb.h>
17 #include "ft1000_usb.h"
18 #include <linux/types.h>
19 //#include <asm/semaphore.h> //aelias [-] reason : file moved
20 //#include <linux/semaphore.h> //aelias [+] reason : file moved
22 //#include <linux/kthread.h>
24 #define HARLEY_READ_REGISTER 0x0
25 #define HARLEY_WRITE_REGISTER 0x01
26 #define HARLEY_READ_DPRAM_32 0x02
27 #define HARLEY_READ_DPRAM_LOW 0x03
28 #define HARLEY_READ_DPRAM_HIGH 0x04
29 #define HARLEY_WRITE_DPRAM_32 0x05
30 #define HARLEY_WRITE_DPRAM_LOW 0x06
31 #define HARLEY_WRITE_DPRAM_HIGH 0x07
33 #define HARLEY_READ_OPERATION 0xc1
34 #define HARLEY_WRITE_OPERATION 0x41
39 extern void *pFileStart
;
40 extern ULONG FileLength
;
43 extern int numofmsgbuf
;
46 int ft1000_poll_thread(void *arg
);
48 static void ft1000_hbchk(u_long data
);
49 int ft1000_reset(struct net_device
*ft1000dev
);
50 static int ft1000_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
51 static int ft1000_open (struct net_device
*dev
);
52 int ft1000_close (struct net_device
*dev
);
53 static struct net_device_stats
*ft1000_netdev_stats(struct net_device
*dev
);
54 u16
scram_dnldr(struct ft1000_device
*ft1000dev
, void *pFileStart
, ULONG FileLength
);
55 int ft1000_submit_rx_urb(PFT1000_INFO info
);
56 static struct timer_list poll_timer
[MAX_NUM_CARDS
];
57 static int ft1000_chkcard (struct ft1000_device
*dev
);
59 static const struct net_device_ops ft1000net_ops = {
60 .ndo_start_xmit = ft1000_start_xmit,
61 .ndo_get_stats = ft1000_netdev_stats,
62 .ndo_open = ft1000_open,
63 .ndo_stop = ft1000_close,
69 static u8 tempbuffer
[1600];
72 #define MAX_RCV_LOOP 100
75 extern struct list_head freercvpool
;
76 extern spinlock_t free_buff_lock
; // lock to arbitrate free buffer list for receive command data
80 extern int ft1000_CreateDevice(struct ft1000_device
*dev
);
81 extern PDPRAM_BLK
ft1000_get_buffer (struct list_head
*bufflist
);
82 extern void ft1000_free_buffer (PDPRAM_BLK pdpram_blk
, struct list_head
*plist
);
85 static int atoi(const char *s
)
92 while (*s
!= '\0' && *s
>= '0' && *s
<= '9') {
93 k
= 10 * k
+ (*s
- '0');
95 // Let's put a limit on this while loop to avoid deadlock scenario
102 /****************************************************************
103 * ft1000_control_complete
104 ****************************************************************/
105 static void ft1000_control_complete(struct urb
*urb
)
107 struct ft1000_device
*ft1000dev
= (struct ft1000_device
*)urb
->context
;
109 //DEBUG("FT1000_CONTROL_COMPLETE ENTERED\n");
110 if (ft1000dev
== NULL
)
112 DEBUG("NULL ft1000dev, failure\n");
115 else if ( ft1000dev
->dev
== NULL
)
117 DEBUG("NULL ft1000dev->dev, failure\n");
120 //spin_lock(&ft1000dev->device_lock);
122 if(waitqueue_active(&ft1000dev
->control_wait
))
124 wake_up(&ft1000dev
->control_wait
);
127 //DEBUG("FT1000_CONTROL_COMPLETE RETURNED\n");
128 //spin_unlock(&ft1000dev->device_lock);
131 //---------------------------------------------------------------------------
132 // Function: ft1000_control
134 // Parameters: ft1000_device - device structure
135 // pipe - usb control message pipe
136 // request - control request
137 // requesttype - control message request type
138 // value - value to be written or 0
139 // index - register index
140 // data - data buffer to hold the read/write values
142 // timeout - control message time out value
144 // Returns: STATUS_SUCCESS - success
145 // STATUS_FAILURE - failure
147 // Description: This function sends a control message via USB interface synchronously
151 //---------------------------------------------------------------------------
152 static int ft1000_control(struct ft1000_device
*ft1000dev
,unsigned int pipe
,
163 if (ft1000dev
== NULL
)
165 DEBUG("NULL ft1000dev, failure\n");
166 return STATUS_FAILURE
;
168 else if ( ft1000dev
->dev
== NULL
)
170 DEBUG("NULL ft1000dev->dev, failure\n");
171 return STATUS_FAILURE
;
174 ret
= usb_control_msg(ft1000dev
->dev
,
185 ret
= STATUS_SUCCESS
;
187 ret
= STATUS_FAILURE
;
194 //---------------------------------------------------------------------------
195 // Function: ft1000_read_register
197 // Parameters: ft1000_device - device structure
198 // Data - data buffer to hold the value read
199 // nRegIndex - register index
201 // Returns: STATUS_SUCCESS - success
202 // STATUS_FAILURE - failure
204 // Description: This function returns the value in a register
208 //---------------------------------------------------------------------------
210 u16
ft1000_read_register(struct ft1000_device
*ft1000dev
, short* Data
, u16 nRegIndx
)
212 u16 ret
= STATUS_SUCCESS
;
214 //DEBUG("ft1000_read_register: reg index is %d\n", nRegIndx);
215 //DEBUG("ft1000_read_register: spin_lock locked\n");
216 ret
= ft1000_control(ft1000dev
,
217 usb_rcvctrlpipe(ft1000dev
->dev
,0),
218 HARLEY_READ_REGISTER
, //request --READ_REGISTER
219 HARLEY_READ_OPERATION
, //requestType
224 LARGE_TIMEOUT
); //timeout
226 //DEBUG("ft1000_read_register: ret is %d \n", ret);
228 //DEBUG("ft1000_read_register: data is %x \n", *Data);
229 if ( ret
!= STATUS_SUCCESS
)
230 return STATUS_FAILURE
;
236 //---------------------------------------------------------------------------
237 // Function: ft1000_write_register
239 // Parameters: ft1000_device - device structure
240 // value - value to write into a register
241 // nRegIndex - register index
243 // Returns: STATUS_SUCCESS - success
244 // STATUS_FAILURE - failure
246 // Description: This function writes the value in a register
250 //---------------------------------------------------------------------------
251 u16
ft1000_write_register(struct ft1000_device
*ft1000dev
, USHORT value
, u16 nRegIndx
)
253 u16 ret
= STATUS_SUCCESS
;
255 //DEBUG("ft1000_write_register: value is: %d, reg index is: %d\n", value, nRegIndx);
257 ret
= ft1000_control(ft1000dev
,
258 usb_sndctrlpipe(ft1000dev
->dev
, 0),
259 HARLEY_WRITE_REGISTER
, //request -- WRITE_REGISTER
260 HARLEY_WRITE_OPERATION
, //requestType
267 if ( ret
!= STATUS_SUCCESS
)
268 return STATUS_FAILURE
;
273 //---------------------------------------------------------------------------
274 // Function: ft1000_read_dpram32
276 // Parameters: ft1000_device - device structure
277 // indx - starting address to read
278 // buffer - data buffer to hold the data read
279 // cnt - number of byte read from DPRAM
281 // Returns: STATUS_SUCCESS - success
282 // STATUS_FAILURE - failure
284 // Description: This function read a number of bytes from DPRAM
288 //---------------------------------------------------------------------------
290 u16
ft1000_read_dpram32(struct ft1000_device
*ft1000dev
, USHORT indx
, PUCHAR buffer
, USHORT cnt
)
292 u16 ret
= STATUS_SUCCESS
;
294 //DEBUG("ft1000_read_dpram32: indx: %d cnt: %d\n", indx, cnt);
295 ret
=ft1000_control(ft1000dev
,
296 usb_rcvctrlpipe(ft1000dev
->dev
,0),
297 HARLEY_READ_DPRAM_32
, //request --READ_DPRAM_32
298 HARLEY_READ_OPERATION
, //requestType
303 LARGE_TIMEOUT
); //timeout
305 //DEBUG("ft1000_read_dpram32: ret is %d \n", ret);
307 //DEBUG("ft1000_read_dpram32: ret=%d \n", ret);
308 if ( ret
!= STATUS_SUCCESS
)
309 return STATUS_FAILURE
;
315 //---------------------------------------------------------------------------
316 // Function: ft1000_write_dpram32
318 // Parameters: ft1000_device - device structure
319 // indx - starting address to write the data
320 // buffer - data buffer to write into DPRAM
321 // cnt - number of bytes to write
323 // Returns: STATUS_SUCCESS - success
324 // STATUS_FAILURE - failure
326 // Description: This function writes into DPRAM a number of bytes
330 //---------------------------------------------------------------------------
331 u16
ft1000_write_dpram32(struct ft1000_device
*ft1000dev
, USHORT indx
, PUCHAR buffer
, USHORT cnt
)
333 u16 ret
= STATUS_SUCCESS
;
335 //DEBUG("ft1000_write_dpram32: indx: %d buffer: %x cnt: %d\n", indx, buffer, cnt);
337 cnt
+= cnt
- (cnt
% 4);
339 ret
= ft1000_control(ft1000dev
,
340 usb_sndctrlpipe(ft1000dev
->dev
, 0),
341 HARLEY_WRITE_DPRAM_32
, //request -- WRITE_DPRAM_32
342 HARLEY_WRITE_OPERATION
, //requestType
350 if ( ret
!= STATUS_SUCCESS
)
351 return STATUS_FAILURE
;
357 //---------------------------------------------------------------------------
358 // Function: ft1000_read_dpram16
360 // Parameters: ft1000_device - device structure
361 // indx - starting address to read
362 // buffer - data buffer to hold the data read
363 // hightlow - high or low 16 bit word
365 // Returns: STATUS_SUCCESS - success
366 // STATUS_FAILURE - failure
368 // Description: This function read 16 bits from DPRAM
372 //---------------------------------------------------------------------------
373 u16
ft1000_read_dpram16(struct ft1000_device
*ft1000dev
, USHORT indx
, PUCHAR buffer
, u8 highlow
)
375 u16 ret
= STATUS_SUCCESS
;
377 //DEBUG("ft1000_read_dpram16: indx: %d hightlow: %d\n", indx, highlow);
382 request
= HARLEY_READ_DPRAM_LOW
;
384 request
= HARLEY_READ_DPRAM_HIGH
;
386 ret
= ft1000_control(ft1000dev
,
387 usb_rcvctrlpipe(ft1000dev
->dev
,0),
388 request
, //request --READ_DPRAM_H/L
389 HARLEY_READ_OPERATION
, //requestType
394 LARGE_TIMEOUT
); //timeout
396 //DEBUG("ft1000_read_dpram16: ret is %d \n", ret);
399 //DEBUG("ft1000_read_dpram16: data is %x \n", *buffer);
400 if ( ret
!= STATUS_SUCCESS
)
401 return STATUS_FAILURE
;
407 //---------------------------------------------------------------------------
408 // Function: ft1000_write_dpram16
410 // Parameters: ft1000_device - device structure
411 // indx - starting address to write the data
412 // value - 16bits value to write
413 // hightlow - high or low 16 bit word
415 // Returns: STATUS_SUCCESS - success
416 // STATUS_FAILURE - failure
418 // Description: This function writes into DPRAM a number of bytes
422 //---------------------------------------------------------------------------
423 u16
ft1000_write_dpram16(struct ft1000_device
*ft1000dev
, USHORT indx
, USHORT value
, u8 highlow
)
425 u16 ret
= STATUS_SUCCESS
;
429 //DEBUG("ft1000_write_dpram16: indx: %d value: %d highlow: %d\n", indx, value, highlow);
435 request
= HARLEY_WRITE_DPRAM_LOW
;
437 request
= HARLEY_WRITE_DPRAM_HIGH
;
439 ret
= ft1000_control(ft1000dev
,
440 usb_sndctrlpipe(ft1000dev
->dev
, 0),
441 request
, //request -- WRITE_DPRAM_H/L
442 HARLEY_WRITE_OPERATION
, //requestType
450 if ( ret
!= STATUS_SUCCESS
)
451 return STATUS_FAILURE
;
457 //---------------------------------------------------------------------------
458 // Function: fix_ft1000_read_dpram32
460 // Parameters: ft1000_device - device structure
461 // indx - starting address to read
462 // buffer - data buffer to hold the data read
465 // Returns: STATUS_SUCCESS - success
466 // STATUS_FAILURE - failure
468 // Description: This function read DPRAM 4 words at a time
472 //---------------------------------------------------------------------------
473 u16
fix_ft1000_read_dpram32(struct ft1000_device
*ft1000dev
, USHORT indx
, PUCHAR buffer
)
475 UCHAR tempbuffer
[16];
477 u16 ret
= STATUS_SUCCESS
;
479 //DEBUG("fix_ft1000_read_dpram32: indx: %d \n", indx);
481 ret
= ft1000_read_dpram32(ft1000dev
, pos
, (PUCHAR
)&tempbuffer
[0], 16);
482 if (ret
== STATUS_SUCCESS
)
485 *buffer
++ = tempbuffer
[pos
++];
486 *buffer
++ = tempbuffer
[pos
++];
487 *buffer
++ = tempbuffer
[pos
++];
488 *buffer
++ = tempbuffer
[pos
++];
492 DEBUG("fix_ft1000_read_dpram32: DPRAM32 Read failed\n");
500 //DEBUG("fix_ft1000_read_dpram32: data is %x \n", *buffer);
506 //---------------------------------------------------------------------------
507 // Function: fix_ft1000_write_dpram32
509 // Parameters: ft1000_device - device structure
510 // indx - starting address to write
511 // buffer - data buffer to write
514 // Returns: STATUS_SUCCESS - success
515 // STATUS_FAILURE - failure
517 // Description: This function write to DPRAM 4 words at a time
521 //---------------------------------------------------------------------------
522 u16
fix_ft1000_write_dpram32(struct ft1000_device
*ft1000dev
, USHORT indx
, PUCHAR buffer
)
527 UCHAR tempbuffer
[32];
528 UCHAR resultbuffer
[32];
530 u16 ret
= STATUS_SUCCESS
;
532 //DEBUG("fix_ft1000_write_dpram32: Entered:\n");
536 ret
= ft1000_read_dpram32(ft1000dev
, pos1
, (PUCHAR
)&tempbuffer
[0], 16);
537 if (ret
== STATUS_SUCCESS
)
540 tempbuffer
[pos2
++] = *buffer
++;
541 tempbuffer
[pos2
++] = *buffer
++;
542 tempbuffer
[pos2
++] = *buffer
++;
543 tempbuffer
[pos2
++] = *buffer
++;
544 ret
= ft1000_write_dpram32(ft1000dev
, pos1
, (PUCHAR
)&tempbuffer
[0], 16);
548 DEBUG("fix_ft1000_write_dpram32: DPRAM32 Read failed\n");
553 ret
= ft1000_read_dpram32(ft1000dev
, pos1
, (PUCHAR
)&resultbuffer
[0], 16);
554 if (ret
== STATUS_SUCCESS
)
559 if (tempbuffer
[i
] != resultbuffer
[i
]){
561 ret
= STATUS_FAILURE
;
566 if (ret
== STATUS_FAILURE
)
568 ret
= ft1000_write_dpram32(ft1000dev
, pos1
, (PUCHAR
)&tempbuffer
[0], 16);
569 ret
= ft1000_read_dpram32(ft1000dev
, pos1
, (PUCHAR
)&resultbuffer
[0], 16);
570 if (ret
== STATUS_SUCCESS
)
575 if (tempbuffer
[i
] != resultbuffer
[i
])
577 ret
= STATUS_FAILURE
;
578 DEBUG("fix_ft1000_write_dpram32 Failed to write\n");
589 //------------------------------------------------------------------------
591 // Function: card_reset_dsp
593 // Synopsis: This function is called to reset or activate the DSP
595 // Arguments: value - reset or activate
598 //-----------------------------------------------------------------------
599 void card_reset_dsp (struct ft1000_device
*ft1000dev
, BOOLEAN value
)
601 u16 status
= STATUS_SUCCESS
;
604 status
= ft1000_write_register (ft1000dev
, HOST_INTF_BE
, FT1000_REG_SUP_CTRL
);
605 status
= ft1000_read_register(ft1000dev
, &tempword
, FT1000_REG_SUP_CTRL
);
608 DEBUG("Reset DSP\n");
609 status
= ft1000_read_register(ft1000dev
, &tempword
, FT1000_REG_RESET
);
610 tempword
|= DSP_RESET_BIT
;
611 status
= ft1000_write_register(ft1000dev
, tempword
, FT1000_REG_RESET
);
615 DEBUG("Activate DSP\n");
616 status
= ft1000_read_register(ft1000dev
, &tempword
, FT1000_REG_RESET
);
618 tempword
|= DSP_ENCRYPTED
;
619 tempword
&= ~DSP_UNENCRYPTED
;
621 tempword
|= DSP_UNENCRYPTED
;
622 tempword
&= ~DSP_ENCRYPTED
;
624 status
= ft1000_write_register(ft1000dev
, tempword
, FT1000_REG_RESET
);
625 status
= ft1000_read_register(ft1000dev
, &tempword
, FT1000_REG_RESET
);
626 tempword
&= ~EFUSE_MEM_DISABLE
;
627 tempword
&= ~DSP_RESET_BIT
;
628 status
= ft1000_write_register(ft1000dev
, tempword
, FT1000_REG_RESET
);
629 status
= ft1000_read_register(ft1000dev
, &tempword
, FT1000_REG_RESET
);
633 //---------------------------------------------------------------------------
634 // Function: CardSendCommand
636 // Parameters: ft1000_device - device structure
637 // ptempbuffer - command buffer
638 // size - command buffer size
640 // Returns: STATUS_SUCCESS - success
641 // STATUS_FAILURE - failure
643 // Description: This function sends a command to ASIC
647 //---------------------------------------------------------------------------
648 void CardSendCommand(struct ft1000_device
*ft1000dev
, unsigned char *ptempbuffer
, int size
)
651 unsigned char *commandbuf
;
653 DEBUG("CardSendCommand: enter CardSendCommand... size=%d\n", size
);
655 commandbuf
=(unsigned char*) kmalloc(size
+2, GFP_KERNEL
);
656 //memset((void*)commandbuf, 0, size+2);
657 memcpy((void*)commandbuf
+2, (void*)ptempbuffer
, size
);
659 //DEBUG("CardSendCommand: Command Send\n");
661 for (i=0; i<size+2; i++)
663 DEBUG("FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
667 ft1000_read_register(ft1000dev
, &temp
, FT1000_REG_DOORBELL
);
674 // check for odd word
678 // Must force to be 32 bit aligned
679 size
+= 4 - (size
% 4);
683 //DEBUG("CardSendCommand: write dpram ... size=%d\n", size);
684 ft1000_write_dpram32(ft1000dev
, 0,commandbuf
, size
);
686 //DEBUG("CardSendCommand: write into doorbell ...\n");
687 ft1000_write_register(ft1000dev
, FT1000_DB_DPRAM_TX
,FT1000_REG_DOORBELL
) ;
690 ft1000_read_register(ft1000dev
, &temp
, FT1000_REG_DOORBELL
);
691 //DEBUG("CardSendCommand: read doorbell ...temp=%x\n", temp);
692 if ( (temp
& 0x0100) == 0)
694 //DEBUG("CardSendCommand: Message sent\n");
700 //--------------------------------------------------------------------------
702 // Function: dsp_reload
704 // Synopsis: This function is called to load or reload the DSP
706 // Arguments: ft1000dev - device structure
709 //-----------------------------------------------------------------------
710 void dsp_reload (struct ft1000_device
*ft1000dev
)
716 PFT1000_INFO pft1000info
;
718 pft1000info
= netdev_priv(ft1000dev
->net
);
720 pft1000info
->CardReady
= 0;
721 pft1000info
->DSP_loading
= 1;
723 // Program Interrupt Mask register
724 status
= ft1000_write_register (ft1000dev
, 0xffff, FT1000_REG_SUP_IMASK
);
726 status
= ft1000_read_register (ft1000dev
, &tempword
, FT1000_REG_RESET
);
727 tempword
|= ASIC_RESET_BIT
;
728 status
= ft1000_write_register (ft1000dev
, tempword
, FT1000_REG_RESET
);
730 status
= ft1000_read_register (ft1000dev
, &tempword
, FT1000_REG_RESET
);
731 DEBUG("Reset Register = 0x%x\n", tempword
);
734 card_reset_dsp (ft1000dev
, 1);
736 card_reset_dsp (ft1000dev
, 0);
739 status
= ft1000_write_register (ft1000dev
, HOST_INTF_BE
, FT1000_REG_SUP_CTRL
);
741 // Let's check for FEFE
742 status
= ft1000_read_dpram32 (ft1000dev
, FT1000_MAG_DPRAM_FEFE_INDX
, (PUCHAR
)&templong
, 4);
743 DEBUG("templong (fefe) = 0x%8x\n", templong
);
746 status
= scram_dnldr(ft1000dev
, pFileStart
, FileLength
);
748 if ( status
!= STATUS_SUCCESS
)
752 pft1000info
->DSP_loading
= 0;
754 DEBUG("dsp_reload returned\n");
759 //---------------------------------------------------------------------------
761 // Function: ft1000_reset_asic
762 // Descripton: This function will call the Card Service function to reset the
765 // dev - device structure
769 //---------------------------------------------------------------------------
770 static void ft1000_reset_asic (struct net_device
*dev
)
772 FT1000_INFO
*info
= netdev_priv(dev
);
773 struct ft1000_device
*ft1000dev
= info
->pFt1000Dev
;
776 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
778 info
->ASICResetNum
++;
780 // Let's use the register provided by the Magnemite ASIC to reset the
782 ft1000_write_register(ft1000dev
, (DSP_RESET_BIT
| ASIC_RESET_BIT
), FT1000_REG_RESET
);
786 // set watermark to -1 in order to not generate an interrrupt
787 ft1000_write_register(ft1000dev
, 0xffff, FT1000_REG_MAG_WATERMARK
);
790 ft1000_read_register (ft1000dev
, &tempword
, FT1000_REG_SUP_ISR
);
791 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword
);
792 ft1000_write_register (ft1000dev
, tempword
, FT1000_REG_SUP_ISR
);
793 ft1000_read_register (ft1000dev
, &tempword
, FT1000_REG_SUP_ISR
);
794 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword
);
798 //---------------------------------------------------------------------------
800 // Function: ft1000_disable_interrupts
801 // Descripton: This function will disable all interrupts.
803 // dev - device structure
807 //---------------------------------------------------------------------------
808 static void ft1000_disable_interrupts(struct net_device *dev) {
809 FT1000_INFO *info = netdev_priv(dev);
810 struct ft1000_device *ft1000dev = info->pFt1000Dev;
813 DEBUG("ft1000_hw: ft1000_disable_interrupts()\n");
814 ft1000_write_register (ft1000dev, ISR_MASK_ALL, FT1000_REG_SUP_IMASK);
815 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_IMASK);
816 DEBUG("ft1000_hw:ft1000_disable_interrupts:current interrupt enable mask = 0x%x\n", tempword);
817 info->InterruptsEnabled = FALSE;
820 //---------------------------------------------------------------------------
822 // Function: ft1000_enable_interrupts
823 // Descripton: This function will enable interrupts base on the current interrupt mask.
825 // dev - device structure
829 //---------------------------------------------------------------------------
830 static void ft1000_enable_interrupts(struct net_device *dev) {
831 FT1000_INFO *info = netdev_priv(dev);
832 struct ft1000_device *ft1000dev = info->pFt1000Dev;
835 DEBUG("ft1000_hw:ft1000_enable_interrupts()\n");
836 ft1000_write_register (ft1000dev, info->CurrentInterruptEnableMask, FT1000_REG_SUP_IMASK);
837 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_IMASK);
838 DEBUG("ft1000_hw:ft1000_enable_interrupts:current interrupt enable mask = 0x%x\n", tempword);
839 info->InterruptsEnabled = TRUE;
843 //---------------------------------------------------------------------------
845 // Function: ft1000_reset_card
846 // Descripton: This function will reset the card
848 // dev - device structure
850 // status - FALSE (card reset fail)
851 // TRUE (card reset successful)
853 //---------------------------------------------------------------------------
854 static int ft1000_reset_card (struct net_device
*dev
)
856 FT1000_INFO
*info
= netdev_priv(dev
);
857 struct ft1000_device
*ft1000dev
= info
->pFt1000Dev
;
861 DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
863 info
->fCondResetPend
= 1;
865 info
->fProvComplete
= 0;
866 //ft1000_disable_interrupts(dev);
868 // Cancel heartbeat task since we are reloading the dsp
869 //del_timer(&poll_timer[info->CardNumber]);
871 // Make sure we free any memory reserve for provisioning
872 while (list_empty(&info
->prov_list
) == 0) {
873 DEBUG("ft1000_hw:ft1000_reset_card:deleting provisioning record\n");
874 ptr
= list_entry(info
->prov_list
.next
, PROV_RECORD
, list
);
875 list_del(&ptr
->list
);
876 kfree(ptr
->pprov_data
);
880 DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n");
882 ft1000_reset_asic(dev
);
887 DEBUG("ft1000_hw:ft1000_reset_card:resetting ASIC and DSP\n");
888 ft1000_write_register (ft1000dev
, (DSP_RESET_BIT
| ASIC_RESET_BIT
), FT1000_REG_RESET
);
891 // Copy DSP session record into info block if this is not a coldstart
892 //if (ft1000_card_present == 1) {
893 spin_lock_irqsave(&info
->dpram_lock
, flags
);
895 ft1000_write_register(ft1000dev
, FT1000_DPRAM_MAG_RX_BASE
, FT1000_REG_DPRAM_ADDR
);
896 for (i
=0;i
<MAX_DSP_SESS_REC
/2; i
++) {
897 //info->DSPSess.MagRec[i] = inl(dev->base_addr+FT1000_REG_MAG_DPDATA);
898 ft1000_read_dpram32(ft1000dev
, FT1000_REG_MAG_DPDATA
, (PCHAR
)&(info
->DSPSess
.MagRec
[i
]), 4);
901 spin_unlock_irqrestore(&info
->dpram_lock
, flags
);
903 info
->squeseqnum
= 0;
905 DEBUG("ft1000_hw:ft1000_reset_card:resetting ASIC\n");
908 ft1000_reset_asic(dev
);
912 DEBUG("ft1000_hw:ft1000_reset_card:downloading dsp image\n");
915 // Put dsp in reset and take ASIC out of reset
916 DEBUG("ft1000_hw:ft1000_reset_card:Put DSP in reset and take ASIC out of reset\n");
917 ft1000_write_register (ft1000dev
, DSP_RESET_BIT
, FT1000_REG_RESET
);
919 // Setting MAGNEMITE ASIC to big endian mode
920 ft1000_write_register (ft1000dev
, HOST_INTF_BE
, FT1000_REG_SUP_CTRL
);
922 // Take DSP out of reset
924 ft1000_read_register(ft1000dev
, &tempword
, FT1000_REG_RESET
);
925 tempword
|= DSP_ENCRYPTED
;
926 tempword
&= ~DSP_UNENCRYPTED
;
927 ft1000_write_register(ft1000dev
, tempword
, FT1000_REG_RESET
);
928 tempword
&= ~EFUSE_MEM_DISABLE
;
929 ft1000_write_register(ft1000dev
, tempword
, FT1000_REG_RESET
);
930 tempword
&= ~DSP_RESET_BIT
;
931 ft1000_write_register(ft1000dev
, tempword
, FT1000_REG_RESET
);
934 // FLARION_DSP_ACTIVE;
936 DEBUG("ft1000_hw:ft1000_reset_card:Take DSP out of reset\n");
938 // Wait for 0xfefe indicating dsp ready before starting download
939 for (i
=0; i
<50; i
++) {
940 //tempword = ft1000_read_dpram_mag_16(dev, FT1000_MAG_DPRAM_FEFE, FT1000_MAG_DPRAM_FEFE_INDX);
941 ft1000_read_dpram32 (ft1000dev
, FT1000_MAG_DPRAM_FEFE_INDX
, (PUCHAR
)&templong
, 4);
942 if (tempword
== 0xfefe) {
949 DEBUG("ft1000_hw:ft1000_reset_card:No FEFE detected from DSP\n");
956 DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n");
957 dsp_reload(ft1000dev
);
959 DEBUG("dsp reload successful\n");
964 // Initialize DSP heartbeat area to ho
965 ft1000_write_dpram16(ft1000dev
, FT1000_MAG_HI_HO
, ho_mag
, FT1000_MAG_HI_HO_INDX
);
966 ft1000_read_dpram16(ft1000dev
, FT1000_MAG_HI_HO
, (PCHAR
)&tempword
, FT1000_MAG_HI_HO_INDX
);
967 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword
);
972 //ft1000_enable_interrupts(dev);
973 /* Schedule heartbeat process to run every 2 seconds */
974 //poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
975 //poll_timer[info->CardNumber].data = (u_long)dev;
976 //add_timer(&poll_timer[info->CardNumber]);
978 info
->fCondResetPend
= 0;
985 #ifdef HAVE_NET_DEVICE_OPS
986 static const struct net_device_ops ftnet_ops
=
988 .ndo_open
= &ft1000_open
,
989 .ndo_stop
= &ft1000_close
,
990 .ndo_start_xmit
= &ft1000_start_xmit
,
991 .ndo_get_stats
= &ft1000_netdev_stats
,
996 //---------------------------------------------------------------------------
997 // Function: init_ft1000_netdev
999 // Parameters: ft1000dev - device structure
1002 // Returns: STATUS_SUCCESS - success
1003 // STATUS_FAILURE - failure
1005 // Description: This function initialize the network device
1009 //---------------------------------------------------------------------------
1010 u16
init_ft1000_netdev(struct ft1000_device
*ft1000dev
)
1012 struct net_device
*netdev
;
1013 FT1000_INFO
*pInfo
= NULL
;
1014 PDPRAM_BLK pdpram_blk
;
1017 gCardIndex
=0; //mbelian
1019 DEBUG("Enter init_ft1000_netdev...\n");
1022 netdev
= alloc_etherdev( sizeof(FT1000_INFO
));
1025 DEBUG("init_ft1000_netdev: can not allocate network device\n");
1026 return STATUS_FAILURE
;
1029 //pInfo = (PFT1000_INFO)netdev->priv;
1030 pInfo
= (FT1000_INFO
*) netdev_priv (netdev
);
1032 //DEBUG("init_ft1000_netdev: gFt1000Info=%x, netdev=%x, ft1000dev=%x\n", gFt1000Info, netdev, ft1000dev);
1034 memset (pInfo
, 0, sizeof(FT1000_INFO
));
1036 dev_alloc_name(netdev
, netdev
->name
);
1038 //for the first inserted card, decide the card index beginning number, in case there are existing network interfaces
1039 if ( gCardIndex
== 0 )
1041 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev
->name
);
1043 if ( strncmp(netdev
->name
,"eth", 3) == 0) {
1044 //pInfo->CardNumber = atoi(&netdev->name[3]);
1045 gCardIndex
= atoi(&netdev
->name
[3]);
1046 pInfo
->CardNumber
= gCardIndex
;
1047 DEBUG("card number = %d\n", pInfo
->CardNumber
);
1050 printk(KERN_ERR
"ft1000: Invalid device name\n");
1052 return STATUS_FAILURE
;
1057 //not the first inserted card, increase card number by 1
1059 pInfo
->CardNumber
= gCardIndex
;
1060 /*DEBUG("card number = %d\n", pInfo->CardNumber);*/ //mbelian
1063 memset(&pInfo
->stats
, 0, sizeof(struct net_device_stats
) );
1065 spin_lock_init(&pInfo
->dpram_lock
);
1066 pInfo
->pFt1000Dev
= ft1000dev
;
1067 pInfo
->DrvErrNum
= 0;
1068 pInfo
->ASICResetNum
= 0;
1069 pInfo
->registered
= 1;
1070 pInfo
->ft1000_reset
= ft1000_reset
;
1071 pInfo
->mediastate
= 0;
1072 pInfo
->fifo_cnt
= 0;
1073 pInfo
->DeviceCreated
= FALSE
;
1074 pInfo
->DeviceMajor
= 0;
1075 pInfo
->CurrentInterruptEnableMask
= ISR_DEFAULT_MASK
;
1076 pInfo
->InterruptsEnabled
= FALSE
;
1077 pInfo
->CardReady
= 0;
1078 pInfo
->DSP_loading
= 0;
1079 pInfo
->DSP_TIME
[0] = 0;
1080 pInfo
->DSP_TIME
[1] = 0;
1081 pInfo
->DSP_TIME
[2] = 0;
1082 pInfo
->DSP_TIME
[3] = 0;
1083 pInfo
->fAppMsgPend
= 0;
1084 pInfo
->fCondResetPend
= 0;
1086 pInfo
->dspalive
= 0;
1087 for (i
=0;i
<32 ;i
++ )
1089 pInfo
->tempbuf
[i
] = 0;
1092 INIT_LIST_HEAD(&pInfo
->prov_list
);
1095 #ifdef HAVE_NET_DEVICE_OPS
1096 netdev
->netdev_ops
= &ftnet_ops
;
1098 netdev
->hard_start_xmit
= &ft1000_start_xmit
;
1099 netdev
->get_stats
= &ft1000_netdev_stats
;
1100 netdev
->open
= &ft1000_open
;
1101 netdev
->stop
= &ft1000_close
;
1104 //netif_stop_queue(netdev); //mbelian
1107 ft1000dev
->net
= netdev
;
1111 //init free_buff_lock, freercvpool, numofmsgbuf, pdpram_blk
1112 //only init once per card
1114 DEBUG("Initialize free_buff_lock and freercvpool\n");
1115 spin_lock_init(&free_buff_lock
);
1117 // initialize a list of buffers to be use for queuing up receive command data
1118 INIT_LIST_HEAD (&freercvpool
);
1120 // create list of free buffers
1121 for (i
=0; i
<NUM_OF_FREE_BUFFERS
; i
++) {
1122 // Get memory for DPRAM_DATA link list
1123 pdpram_blk
= kmalloc ( sizeof(DPRAM_BLK
), GFP_KERNEL
);
1124 // Get a block of memory to store command data
1125 pdpram_blk
->pbuffer
= kmalloc ( MAX_CMD_SQSIZE
, GFP_KERNEL
);
1126 // link provisioning data
1127 list_add_tail (&pdpram_blk
->list
, &freercvpool
);
1129 numofmsgbuf
= NUM_OF_FREE_BUFFERS
;
1132 return STATUS_SUCCESS
;
1138 //---------------------------------------------------------------------------
1139 // Function: reg_ft1000_netdev
1141 // Parameters: ft1000dev - device structure
1144 // Returns: STATUS_SUCCESS - success
1145 // STATUS_FAILURE - failure
1147 // Description: This function register the network driver
1151 //---------------------------------------------------------------------------
1152 u16
reg_ft1000_netdev(struct ft1000_device
*ft1000dev
, struct usb_interface
*intf
)
1154 struct net_device
*netdev
;
1158 netdev
= ft1000dev
->net
;
1159 pInfo
= netdev_priv(ft1000dev
->net
);
1160 DEBUG("Enter reg_ft1000_netdev...\n");
1163 ft1000_read_register(ft1000dev
, &pInfo
->AsicID
, FT1000_REG_ASIC_ID
);
1165 usb_set_intfdata(intf
, pInfo
);
1166 SET_NETDEV_DEV(netdev
, &intf
->dev
);
1168 rc
= register_netdev(netdev
);
1171 DEBUG("reg_ft1000_netdev: could not register network device\n");
1172 free_netdev(netdev
);
1173 return STATUS_FAILURE
;
1177 //Create character device, implemented by Jim
1178 ft1000_CreateDevice(ft1000dev
);
1180 //INIT_LIST_HEAD(&pInfo->prov_list);
1182 for (i
=0; i
<MAX_NUM_CARDS
; i
++) {
1183 poll_timer
[i
].function
= ft1000_hbchk
;
1187 //hard code MAC address for now
1189 netdev->dev_addr[0] = 0;
1190 netdev->dev_addr[1] = 7;
1191 netdev->dev_addr[2] = 0x35;
1192 netdev->dev_addr[3] = 0x84;
1193 netdev->dev_addr[4] = 0;
1194 netdev->dev_addr[5] = 0x20 + pInfo->CardNumber;
1197 DEBUG ("reg_ft1000_netdev returned\n");
1199 pInfo
->CardReady
= 1;
1202 return STATUS_SUCCESS
;
1205 int ft1000_reset(struct net_device
*dev
)
1207 ft1000_reset_card(dev
);
1211 //---------------------------------------------------------------------------
1212 // Function: ft1000_usb_transmit_complete
1214 // Parameters: urb - transmitted usb urb
1219 // Description: This is the callback function when a urb is transmitted
1223 //---------------------------------------------------------------------------
1224 static void ft1000_usb_transmit_complete(struct urb
*urb
)
1227 struct ft1000_device
*ft1000dev
= urb
->context
;
1229 //DEBUG("ft1000_usb_transmit_complete entered\n");
1230 // Jim spin_lock(&ft1000dev->device_lock);
1233 printk("%s: TX status %d\n", ft1000dev
->net
->name
, urb
->status
);
1235 netif_wake_queue(ft1000dev
->net
);
1237 //Jim spin_unlock(&ft1000dev->device_lock);
1238 //DEBUG("Return from ft1000_usb_transmit_complete\n");
1242 /****************************************************************
1244 ****************************************************************/
1245 static int ft1000_read_fifo_reg(struct ft1000_device
*ft1000dev
,unsigned int pipe
,
1256 DECLARE_WAITQUEUE(wait
, current
);
1258 struct usb_ctrlrequest
*dr
;
1261 if (ft1000dev
== NULL
)
1263 DEBUG("NULL ft1000dev, failure\n");
1264 return STATUS_FAILURE
;
1266 else if ( ft1000dev
->dev
== NULL
)
1268 DEBUG("NULL ft1000dev->dev, failure\n");
1269 return STATUS_FAILURE
;
1272 spin_lock(&ft1000dev
->device_lock
);
1274 /*DECLARE_WAITQUEUE(wait, current);
1276 struct usb_ctrlrequest *dr;
1281 spin_unlock(&ft1000dev
->device_lock
);
1285 urb
= usb_alloc_urb(0, GFP_KERNEL
);
1286 dr
= kmalloc(sizeof(struct usb_ctrlrequest
), in_interrupt() ? GFP_ATOMIC
: GFP_KERNEL
);
1291 spin_unlock(&ft1000dev
->device_lock
);
1297 dr
->bRequestType
= requesttype
;
1298 dr
->bRequest
= request
;
1303 usb_fill_control_urb(urb
, ft1000dev
->dev
, pipe
, (char*)dr
, (void*)data
, size
, (void *)ft1000_control_complete
, (void*)ft1000dev
);
1306 init_waitqueue_head(&ft1000dev
->control_wait
);
1308 //current->state = TASK_INTERRUPTIBLE; //mbelian
1309 set_current_state(TASK_INTERRUPTIBLE
);
1311 add_wait_queue(&ft1000dev
->control_wait
, &wait
);
1316 status
= usb_submit_urb(urb
, GFP_KERNEL
);
1322 remove_wait_queue(&ft1000dev
->control_wait
, &wait
);
1323 spin_unlock(&ft1000dev
->device_lock
);
1327 if(urb
->status
== -EINPROGRESS
)
1329 while(timeout
&& urb
->status
== -EINPROGRESS
)
1331 status
= timeout
= schedule_timeout(timeout
);
1339 remove_wait_queue(&ft1000dev
->control_wait
, &wait
);
1343 usb_unlink_urb(urb
);
1344 printk("ft1000 timeout\n");
1345 status
= -ETIMEDOUT
;
1349 status
= urb
->status
;
1353 printk("ft1000 control message failed (urb addr: %x) with error number: %i\n", (int)urb
, (int)status
);
1355 usb_clear_halt(ft1000dev
->dev
, usb_rcvctrlpipe(ft1000dev
->dev
, 0));
1356 usb_clear_halt(ft1000dev
->dev
, usb_sndctrlpipe(ft1000dev
->dev
, 0));
1357 usb_unlink_urb(urb
);
1365 spin_unlock(&ft1000dev
->device_lock
);
1371 //---------------------------------------------------------------------------
1372 // Function: ft1000_read_fifo_len
1374 // Parameters: ft1000dev - device structure
1379 // Description: read the fifo length register content
1383 //---------------------------------------------------------------------------
1384 static inline u16
ft1000_read_fifo_len (struct net_device
*dev
)
1389 //FT1000_INFO *info = (PFT1000_INFO)dev->priv;
1390 FT1000_INFO
*info
= (FT1000_INFO
*) netdev_priv (dev
);
1391 struct ft1000_device
*ft1000dev
= info
->pFt1000Dev
;
1392 // DEBUG("ft1000_read_fifo_len: enter ft1000dev %x\n", ft1000dev); //aelias [-] reason: warning: format ???%x??? expects type ???unsigned int???, but argument 2 has type ???struct ft1000_device *???
1393 DEBUG("ft1000_read_fifo_len: enter ft1000dev %x\n", (unsigned int)ft1000dev
); //aelias [+] reason: up
1394 //ft1000_read_register(ft1000dev, &temp, FT1000_REG_MAG_UFSR);
1396 ret
= STATUS_SUCCESS
;
1398 ret
= ft1000_read_fifo_reg(ft1000dev
,
1399 usb_rcvctrlpipe(ft1000dev
->dev
,0),
1400 HARLEY_READ_REGISTER
,
1401 HARLEY_READ_OPERATION
,
1403 FT1000_REG_MAG_UFSR
,
1409 ret
= STATUS_SUCCESS
;
1411 ret
= STATUS_FAILURE
;
1413 DEBUG("ft1000_read_fifo_len: returned %d\n", temp
);
1420 //---------------------------------------------------------------------------
1422 // Function: ft1000_copy_down_pkt
1423 // Descripton: This function will take an ethernet packet and convert it to
1424 // a Flarion packet prior to sending it to the ASIC Downlink
1427 // dev - device structure
1428 // packet - address of ethernet packet
1429 // len - length of IP packet
1434 //---------------------------------------------------------------------------
1435 int ft1000_copy_down_pkt (struct net_device
*netdev
, u8
*packet
, u16 len
)
1437 FT1000_INFO
*pInfo
= netdev_priv(netdev
);
1438 struct ft1000_device
*pFt1000Dev
= pInfo
->pFt1000Dev
;
1446 if (!pInfo
->CardReady
)
1449 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
1450 return STATUS_FAILURE
;
1455 //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len);
1458 // Check if there is room on the FIFO
1459 if ( len
> ft1000_read_fifo_len (netdev
) )
1462 if ( len
> ft1000_read_fifo_len (netdev
) )
1467 if ( len
> ft1000_read_fifo_len (netdev
) )
1472 if ( len
> ft1000_read_fifo_len (netdev
) )
1477 if ( len
> ft1000_read_fifo_len (netdev
) )
1482 if ( len
> ft1000_read_fifo_len (netdev
) )
1487 if ( len
> ft1000_read_fifo_len (netdev
) )
1489 DEBUG("ft1000_hw:ft1000_copy_down_pkt:Transmit FIFO is fulli - pkt drop\n");
1490 pInfo
->stats
.tx_errors
++;
1491 return STATUS_SUCCESS
;
1496 count
= sizeof (PSEUDO_HDR
) + len
;
1497 if(count
> MAX_BUF_SIZE
)
1499 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n");
1500 DEBUG("size = %d\n", count
);
1501 return STATUS_FAILURE
;
1505 count
= count
+ (4- (count
%4) );
1507 pTemp
= (PUSHORT
)&(pFt1000Dev
->tx_buf
[0]);
1508 *pTemp
++ = ntohs(count
);
1515 pTemp
= (PUSHORT
)&(pFt1000Dev
->tx_buf
[0]);
1516 checksum
= *pTemp
++;
1519 checksum
^= *pTemp
++;
1521 *pTemp
++ = checksum
;
1522 memcpy (&(pFt1000Dev
->tx_buf
[sizeof(PSEUDO_HDR
)]), packet
, len
);
1524 //usb_init_urb(pFt1000Dev->tx_urb); //mbelian
1526 netif_stop_queue(netdev
);
1528 //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count);
1530 usb_fill_bulk_urb(pFt1000Dev
->tx_urb
,
1532 usb_sndbulkpipe(pFt1000Dev
->dev
, pFt1000Dev
->bulk_out_endpointAddr
),
1535 ft1000_usb_transmit_complete
,
1538 t
= (u8
*)pFt1000Dev
->tx_urb
->transfer_buffer
;
1539 //DEBUG("transfer_length=%d\n", pFt1000Dev->tx_urb->transfer_buffer_length);
1540 /*for (i=0; i<count; i++ )
1542 DEBUG("%x ", *t++ );
1546 ret
= usb_submit_urb(pFt1000Dev
->tx_urb
, GFP_ATOMIC
);
1549 DEBUG("ft1000 failed tx_urb %d\n", ret
);
1551 /* pInfo->stats.tx_errors++;
1553 netif_start_queue(netdev); */ //mbelian
1554 return STATUS_FAILURE
;
1559 //DEBUG("ft1000 sucess tx_urb %d\n", ret);
1561 pInfo
->stats
.tx_packets
++;
1562 pInfo
->stats
.tx_bytes
+= (len
+14);
1565 //DEBUG("ft1000_copy_down_pkt() exit\n");
1567 return STATUS_SUCCESS
;
1570 //---------------------------------------------------------------------------
1571 // Function: ft1000_start_xmit
1573 // Parameters: skb - socket buffer to be sent
1574 // dev - network device
1579 // Description: transmit a ethernet packet
1583 //---------------------------------------------------------------------------
1584 static int ft1000_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1586 FT1000_INFO
*pInfo
= netdev_priv(dev
);
1587 struct ft1000_device
*pFt1000Dev
= pInfo
->pFt1000Dev
;
1592 //DEBUG(" ft1000_start_xmit() entered\n");
1596 DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" );
1597 return STATUS_FAILURE
;
1600 if ( pFt1000Dev
->status
& FT1000_STATUS_CLOSING
)
1602 DEBUG("network driver is closed, return\n");
1604 //usb_kill_urb(pFt1000Dev->tx_urb); //mbelian
1605 return STATUS_SUCCESS
;
1608 //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len);
1609 pipe
= usb_sndbulkpipe(pFt1000Dev
->dev
, pFt1000Dev
->bulk_out_endpointAddr
);
1610 maxlen
= usb_maxpacket(pFt1000Dev
->dev
, pipe
, usb_pipeout(pipe
));
1611 //DEBUG("ft1000_start_xmit 2: pipe=%d dev->maxpacket = %d\n", pipe, maxlen);
1613 pdata
= (u8
*)skb
->data
;
1614 /*for (i=0; i<skb->len; i++)
1615 DEBUG("skb->data[%d]=%x ", i, *(skb->data+i));
1620 if (pInfo
->mediastate
== 0)
1622 /* Drop packet is mediastate is down */
1623 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n");
1625 return STATUS_SUCCESS
;
1628 if ( (skb
->len
< ENET_HEADER_SIZE
) || (skb
->len
> ENET_MAX_SIZE
) )
1630 /* Drop packet which has invalid size */
1631 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n");
1633 return STATUS_SUCCESS
;
1636 if(ft1000_copy_down_pkt (dev
, (pdata
+ENET_HEADER_SIZE
-2), skb
->len
- ENET_HEADER_SIZE
+ 2) == STATUS_FAILURE
)
1639 return STATUS_SUCCESS
;
1643 //DEBUG(" ft1000_start_xmit() exit\n");
1648 //---------------------------------------------------------------------------
1650 // Function: ft1000_copy_up_pkt
1651 // Descripton: This function will take a packet from the FIFO up link and
1652 // convert it into an ethernet packet and deliver it to the IP stack
1654 // urb - the receving usb urb
1660 //---------------------------------------------------------------------------
1661 int ft1000_copy_up_pkt (struct urb
*urb
)
1663 PFT1000_INFO info
= urb
->context
;
1664 struct ft1000_device
*ft1000dev
= info
->pFt1000Dev
;
1665 struct net_device
*net
= ft1000dev
->net
;
1670 struct sk_buff
*skb
;
1677 //DEBUG("ft1000_copy_up_pkt entered\n");
1679 if ( ft1000dev
->status
& FT1000_STATUS_CLOSING
)
1681 DEBUG("network driver is closed, return\n");
1682 return STATUS_SUCCESS
;
1686 len
= urb
->transfer_buffer_length
;
1687 lena
= urb
->actual_length
; //mbelian
1688 //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n",
1689 // urb->transfer_buffer_length, urb->actual_length);
1691 chksum
= (PUSHORT
)ft1000dev
->rx_buf
;
1693 tempword
= *chksum
++;
1696 tempword
^= *chksum
++;
1699 if (tempword
!= *chksum
)
1701 info
->stats
.rx_errors
++;
1702 ft1000_submit_rx_urb(info
);
1703 return STATUS_FAILURE
;
1707 //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum);
1709 skb
= dev_alloc_skb(len
+12+2);
1713 DEBUG("ft1000_copy_up_pkt: No Network buffers available\n");
1714 info
->stats
.rx_errors
++;
1715 ft1000_submit_rx_urb(info
);
1716 return STATUS_FAILURE
;
1719 pbuffer
= (u8
*)skb_put(skb
, len
+12);
1721 //subtract the number of bytes read already
1725 *pbuffer
++ = net
->dev_addr
[0];
1726 *pbuffer
++ = net
->dev_addr
[1];
1727 *pbuffer
++ = net
->dev_addr
[2];
1728 *pbuffer
++ = net
->dev_addr
[3];
1729 *pbuffer
++ = net
->dev_addr
[4];
1730 *pbuffer
++ = net
->dev_addr
[5];
1741 memcpy(pbuffer
, ft1000dev
->rx_buf
+sizeof(PSEUDO_HDR
), len
-sizeof(PSEUDO_HDR
));
1743 //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n");
1744 /*for (i=0; i<len+12; i++)
1746 DEBUG("ft1000_copy_up_pkt: Protocol Data: 0x%x\n ", *ptemp++);
1751 skb
->protocol
= eth_type_trans(skb
, net
);
1752 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1755 info
->stats
.rx_packets
++;
1756 // Add on 12 bytes for MAC address which was removed
1757 info
->stats
.rx_bytes
+= (lena
+12); //mbelian
1759 ft1000_submit_rx_urb(info
);
1760 //DEBUG("ft1000_copy_up_pkt exited\n");
1764 //---------------------------------------------------------------------------
1766 // Function: ft1000_submit_rx_urb
1767 // Descripton: the receiving function of the network driver
1770 // info - a private structure contains the device information
1776 //---------------------------------------------------------------------------
1777 int ft1000_submit_rx_urb(PFT1000_INFO info
)
1780 struct ft1000_device
*pFt1000Dev
= info
->pFt1000Dev
;
1782 //netif_carrier_on(pFt1000Dev->net);
1784 //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb));
1785 if ( pFt1000Dev
->status
& FT1000_STATUS_CLOSING
)
1787 DEBUG("network driver is closed, return\n");
1788 //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian
1789 return STATUS_SUCCESS
;
1791 //memset(pFt1000Dev->rx_urb, 0, sizeof(*pFt1000Dev->rx_urb));
1792 //usb_init_urb(pFt1000Dev->rx_urb);//mbelian
1794 //spin_lock_init(&pFt1000Dev->rx_urb->lock);
1796 usb_fill_bulk_urb(pFt1000Dev
->rx_urb
,
1798 usb_rcvbulkpipe(pFt1000Dev
->dev
, pFt1000Dev
->bulk_in_endpointAddr
),
1801 (usb_complete_t
)ft1000_copy_up_pkt
,
1805 if((result
= usb_submit_urb(pFt1000Dev
->rx_urb
, GFP_ATOMIC
)))
1807 printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result
);
1808 return STATUS_FAILURE
;
1811 //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result);
1813 return STATUS_SUCCESS
;
1816 //---------------------------------------------------------------------------
1817 // Function: ft1000_open
1820 // dev - network device
1825 // Description: open the network driver
1829 //---------------------------------------------------------------------------
1830 static int ft1000_open (struct net_device
*dev
)
1832 FT1000_INFO
*pInfo
= (FT1000_INFO
*)netdev_priv(dev
);
1833 struct timeval tv
; //mbelian
1835 DEBUG("ft1000_open is called for card %d\n", pInfo
->CardNumber
);
1836 //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len);
1838 pInfo
->stats
.rx_bytes
= 0; //mbelian
1839 pInfo
->stats
.tx_bytes
= 0; //mbelian
1840 pInfo
->stats
.rx_packets
= 0; //mbelian
1841 pInfo
->stats
.tx_packets
= 0; //mbelian
1842 do_gettimeofday(&tv
);
1843 pInfo
->ConTm
= tv
.tv_sec
;
1844 pInfo
->ProgConStat
= 0; //mbelian
1847 netif_start_queue(dev
);
1849 //netif_device_attach(dev);
1851 netif_carrier_on(dev
); //mbelian
1853 ft1000_submit_rx_urb(pInfo
);
1857 //---------------------------------------------------------------------------
1858 // Function: ft1000_close
1861 // net - network device
1866 // Description: close the network driver
1870 //---------------------------------------------------------------------------
1871 int ft1000_close(struct net_device
*net
)
1873 FT1000_INFO
*pInfo
= (FT1000_INFO
*) netdev_priv (net
);
1874 struct ft1000_device
*ft1000dev
= pInfo
->pFt1000Dev
;
1876 //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt);
1878 ft1000dev
->status
|= FT1000_STATUS_CLOSING
;
1880 //DEBUG("ft1000_close: calling usb_kill_urb \n");
1881 //usb_kill_urb(ft1000dev->rx_urb);
1882 //usb_kill_urb(ft1000dev->tx_urb);
1885 DEBUG("ft1000_close: pInfo=%x, ft1000dev=%x\n", (int)pInfo
, (int)ft1000dev
);
1886 netif_carrier_off(net
);//mbelian
1887 netif_stop_queue(net
);
1888 //DEBUG("ft1000_close: netif_stop_queue called\n");
1889 ft1000dev
->status
&= ~FT1000_STATUS_CLOSING
;
1891 pInfo
->ProgConStat
= 0xff; //mbelian
1897 static struct net_device_stats
*ft1000_netdev_stats(struct net_device
*dev
)
1899 FT1000_INFO
*info
= (FT1000_INFO
*) netdev_priv (dev
);
1900 //struct ft1000_device *ft1000dev = info->pFt1000Dev;
1902 //return &(ft1000dev->stats);//mbelian
1903 return &(info
->stats
); //mbelian
1907 /*********************************************************************************
1912 //---------------------------------------------------------------------------
1914 // Function: ft1000_chkcard
1915 // Descripton: This function will check if the device is presently available on
1918 // dev - device structure
1920 // status - FALSE (device is not present)
1921 // TRUE (device is present)
1923 //---------------------------------------------------------------------------
1924 static int ft1000_chkcard (struct ft1000_device
*dev
) {
1927 FT1000_INFO
*info
= (FT1000_INFO
*) netdev_priv (dev
->net
);
1929 if (info
->fCondResetPend
)
1931 DEBUG("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1935 // Mask register is used to check for device presence since it is never
1937 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_SUP_IMASK
);
1938 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword);
1939 if (tempword
== 0) {
1940 DEBUG("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
1944 // The system will return the value of 0xffff for the version register
1945 // if the device is not present.
1946 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_ASIC_ID
);
1947 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword);
1948 //pxu if (tempword == 0xffff) {
1949 if (tempword
!= 0x1b01 ){
1950 dev
->status
|= FT1000_STATUS_CLOSING
; //mbelian
1951 DEBUG("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
1957 //---------------------------------------------------------------------------
1959 // Function: ft1000_hbchk
1960 // Descripton: This function will perform the heart beat check of the DSP as
1961 // well as the ASIC.
1963 // dev - device structure
1967 //---------------------------------------------------------------------------
1968 static void ft1000_hbchk(u_long data
)
1970 struct ft1000_device
*dev
= (struct ft1000_device
*)data
;
1975 info
= (FT1000_INFO
*) netdev_priv (dev
->net
);
1977 DEBUG("ft1000_hbchk called for CardNumber = %d CardReady = %d\n", info
->CardNumber
, info
->CardReady
);
1979 if (info
->fCondResetPend
== 1) {
1980 // Reset ASIC and DSP
1981 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER0
, (PUCHAR
)&(info
->DSP_TIME
[0]), FT1000_MAG_DSP_TIMER0_INDX
);
1982 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER1
, (PUCHAR
)&(info
->DSP_TIME
[1]), FT1000_MAG_DSP_TIMER1_INDX
);
1983 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER2
, (PUCHAR
)&(info
->DSP_TIME
[2]), FT1000_MAG_DSP_TIMER2_INDX
);
1984 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER3
, (PUCHAR
)&(info
->DSP_TIME
[3]), FT1000_MAG_DSP_TIMER3_INDX
);
1986 info
->DrvErrNum
= DSP_CONDRESET_INFO
;
1987 DEBUG("ft1000_hw:DSP conditional reset requested\n");
1988 ft1000_reset_card(dev
->net
);
1989 info
->fCondResetPend
= 0;
1990 /* Schedule this module to run every 2 seconds */
1992 poll_timer
[info
->CardNumber
].expires
= jiffies
+ (2*HZ
);
1993 poll_timer
[info
->CardNumber
].data
= (u_long
)dev
;
1994 add_timer(&poll_timer
[info
->CardNumber
]);
2001 if (info
->CardReady
== 1) {
2002 // Perform dsp heartbeat check
2003 status
= ntohs(ft1000_read_dpram16(dev
, FT1000_MAG_HI_HO
, (PUCHAR
)&tempword
, FT1000_MAG_HI_HO_INDX
));
2004 DEBUG("ft1000_hw:ft1000_hbchk:hi_ho value = 0x%x\n", tempword
);
2005 // Let's perform another check if ho is not detected
2006 if (tempword
!= ho
) {
2007 status
= ntohs(ft1000_read_dpram16(dev
, FT1000_MAG_HI_HO
, (PUCHAR
)&tempword
,FT1000_MAG_HI_HO_INDX
));
2009 if (tempword
!= ho
) {
2010 printk(KERN_INFO
"ft1000: heartbeat failed - no ho detected\n");
2011 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER0
, (PUCHAR
)&(info
->DSP_TIME
[0]), FT1000_MAG_DSP_TIMER0_INDX
);
2012 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER1
, (PUCHAR
)&(info
->DSP_TIME
[1]), FT1000_MAG_DSP_TIMER1_INDX
);
2013 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER2
, (PUCHAR
)&(info
->DSP_TIME
[2]), FT1000_MAG_DSP_TIMER2_INDX
);
2014 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER3
, (PUCHAR
)&(info
->DSP_TIME
[3]), FT1000_MAG_DSP_TIMER3_INDX
);
2015 info
->DrvErrNum
= DSP_HB_INFO
;
2016 if (ft1000_reset_card(dev
->net
) == 0) {
2017 printk(KERN_INFO
"ft1000: Hardware Failure Detected - PC Card disabled\n");
2018 info
->ProgConStat
= 0xff;
2021 /* Schedule this module to run every 2 seconds */
2022 poll_timer
[info
->CardNumber
].expires
= jiffies
+ (2*HZ
);
2023 poll_timer
[info
->CardNumber
].data
= (u_long
)dev
;
2024 add_timer(&poll_timer
[info
->CardNumber
]);
2028 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
2029 // Let's check doorbell again if fail
2030 if (tempword
& FT1000_DB_HB
) {
2031 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
2033 if (tempword
& FT1000_DB_HB
) {
2034 printk(KERN_INFO
"ft1000: heartbeat doorbell not clear by firmware\n");
2035 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER0
, (PUCHAR
)&(info
->DSP_TIME
[0]), FT1000_MAG_DSP_TIMER0_INDX
);
2036 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER1
, (PUCHAR
)&(info
->DSP_TIME
[1]), FT1000_MAG_DSP_TIMER1_INDX
);
2037 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER2
, (PUCHAR
)&(info
->DSP_TIME
[2]), FT1000_MAG_DSP_TIMER2_INDX
);
2038 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER3
, (PUCHAR
)&(info
->DSP_TIME
[3]), FT1000_MAG_DSP_TIMER3_INDX
);
2039 info
->DrvErrNum
= DSP_HB_INFO
;
2040 if (ft1000_reset_card(dev
->net
) == 0) {
2041 printk(KERN_INFO
"ft1000: Hardware Failure Detected - PC Card disabled\n");
2042 info
->ProgConStat
= 0xff;
2045 /* Schedule this module to run every 2 seconds */
2046 poll_timer
[info
->CardNumber
].expires
= jiffies
+ (2*HZ
);
2047 poll_timer
[info
->CardNumber
].data
= (u_long
)dev
;
2048 add_timer(&poll_timer
[info
->CardNumber
]);
2052 // Set dedicated area to hi and ring appropriate doorbell according
2053 // to hi/ho heartbeat protocol
2054 ft1000_write_dpram16(dev
, FT1000_MAG_HI_HO
, hi_mag
, FT1000_MAG_HI_HO_INDX
);
2056 status
= ntohs(ft1000_read_dpram16(dev
, FT1000_MAG_HI_HO
, (PUCHAR
)&tempword
, FT1000_MAG_HI_HO_INDX
));
2057 // Let's write hi again if fail
2058 if (tempword
!= hi
) {
2059 ft1000_write_dpram16(dev
, FT1000_MAG_HI_HO
, hi_mag
, FT1000_MAG_HI_HO_INDX
);
2060 status
= ntohs(ft1000_read_dpram16(dev
, FT1000_MAG_HI_HO
, (PUCHAR
)&tempword
, FT1000_MAG_HI_HO_INDX
));
2063 if (tempword
!= hi
) {
2064 printk(KERN_INFO
"ft1000: heartbeat failed - cannot write hi into DPRAM\n");
2065 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER0
, (PUCHAR
)&(info
->DSP_TIME
[0]), FT1000_MAG_DSP_TIMER0_INDX
);
2066 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER1
, (PUCHAR
)&(info
->DSP_TIME
[1]), FT1000_MAG_DSP_TIMER1_INDX
);
2067 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER2
, (PUCHAR
)&(info
->DSP_TIME
[2]), FT1000_MAG_DSP_TIMER2_INDX
);
2068 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER3
, (PUCHAR
)&(info
->DSP_TIME
[3]), FT1000_MAG_DSP_TIMER3_INDX
);
2070 info
->DrvErrNum
= DSP_HB_INFO
;
2071 if (ft1000_reset_card(dev
->net
) == 0) {
2072 printk(KERN_INFO
"ft1000: Hardware Failure Detected - PC Card disabled\n");
2073 info
->ProgConStat
= 0xff;
2076 /* Schedule this module to run every 2 seconds */
2077 poll_timer
[info
->CardNumber
].expires
= jiffies
+ (2*HZ
);
2078 poll_timer
[info
->CardNumber
].data
= (u_long
)dev
;
2079 add_timer(&poll_timer
[info
->CardNumber
]);
2082 ft1000_write_register(dev
, FT1000_DB_HB
, FT1000_REG_DOORBELL
);
2086 /* Schedule this module to run every 2 seconds */
2087 poll_timer
[info
->CardNumber
].expires
= jiffies
+ (2*HZ
);
2088 poll_timer
[info
->CardNumber
].data
= (u_long
)dev
;
2089 add_timer(&poll_timer
[info
->CardNumber
]);
2092 //---------------------------------------------------------------------------
2094 // Function: ft1000_receive_cmd
2095 // Descripton: This function will read a message from the dpram area.
2097 // dev - network device structure
2098 // pbuffer - caller supply address to buffer
2099 // pnxtph - pointer to next pseudo header
2101 // Status = 0 (unsuccessful)
2104 //---------------------------------------------------------------------------
2105 BOOLEAN
ft1000_receive_cmd (struct ft1000_device
*dev
, u16
*pbuffer
, int maxsz
, u16
*pnxtph
) {
2111 ret
= ft1000_read_dpram16(dev
, FT1000_MAG_PH_LEN
, (PUCHAR
)&size
, FT1000_MAG_PH_LEN_INDX
);
2112 size
= ntohs(size
) + PSEUDOSZ
;
2114 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size
);
2118 ppseudohdr
= (u16
*)pbuffer
;
2119 //spin_lock_irqsave (&info->dpram_lock, flags);
2120 ft1000_write_register(dev
, FT1000_DPRAM_MAG_RX_BASE
, FT1000_REG_DPRAM_ADDR
);
2121 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAH
);
2122 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2124 ft1000_write_register(dev
, FT1000_DPRAM_MAG_RX_BASE
+1, FT1000_REG_DPRAM_ADDR
);
2125 for (i
=0; i
<=(size
>>2); i
++) {
2126 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAL
);
2128 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAH
);
2131 //copy odd aligned word
2132 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAL
);
2133 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2135 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAH
);
2136 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2138 if (size
& 0x0001) {
2139 //copy odd byte from fifo
2140 ret
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DPRAM_DATA
);
2141 *pbuffer
= ntohs(tempword
);
2143 //spin_unlock_irqrestore(&info->dpram_lock, flags);
2145 // Check if pseudo header checksum is good
2146 // Calculate pseudo header checksum
2147 tempword
= *ppseudohdr
++;
2148 for (i
=1; i
<7; i
++) {
2149 tempword
^= *ppseudohdr
++;
2151 if ( (tempword
!= *ppseudohdr
) ) {
2157 DEBUG("ft1000_receive_cmd:pbuffer\n");
2158 for(i
= 0; i
< size
; i
+=5)
2160 if( (i
+ 5) < size
)
2161 DEBUG("0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", tempbuffer
[i
], tempbuffer
[i
+1], tempbuffer
[i
+2], tempbuffer
[i
+3], tempbuffer
[i
+4]);
2164 for (j
= i
; j
< size
; j
++)
2165 DEBUG("0x%x ", tempbuffer
[j
]);
2178 int ft1000_dsp_prov(void *arg
)
2180 struct ft1000_device
*dev
= (struct ft1000_device
*)arg
;
2181 FT1000_INFO
*info
= (FT1000_INFO
*) netdev_priv (dev
->net
);
2186 PPSEUDO_HDR ppseudo_hdr
;
2189 USHORT TempShortBuf
[256];
2191 DEBUG("*** DspProv Entered\n");
2193 while ( list_empty(&info
->prov_list
) == 0
2194 /*&& !kthread_should_stop() */)
2196 DEBUG("DSP Provisioning List Entry\n");
2198 // Check if doorbell is available
2199 DEBUG("check if doorbell is cleared\n");
2200 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_DOORBELL
);
2203 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n");
2207 while (tempword
& FT1000_DB_DPRAM_TX
) {
2211 DEBUG("FT1000:ft1000_dsp_prov:message drop\n");
2212 return STATUS_FAILURE
;
2214 ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
2217 if ( !(tempword
& FT1000_DB_DPRAM_TX
) ) {
2218 DEBUG("*** Provision Data Sent to DSP\n");
2220 // Send provisioning data
2221 ptr
= list_entry(info
->prov_list
.next
, PROV_RECORD
, list
);
2222 len
= *(u16
*)ptr
->pprov_data
;
2227 pmsg
= (PUSHORT
)ptr
->pprov_data
;
2228 ppseudo_hdr
= (PPSEUDO_HDR
)pmsg
;
2229 // Insert slow queue sequence number
2230 ppseudo_hdr
->seq_num
= info
->squeseqnum
++;
2231 ppseudo_hdr
->portsrc
= 0;
2232 // Calculate new checksum
2233 ppseudo_hdr
->checksum
= *pmsg
++;
2234 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
2235 for (i
=1; i
<7; i
++) {
2236 ppseudo_hdr
->checksum
^= *pmsg
++;
2237 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
2240 TempShortBuf
[0] = 0;
2241 TempShortBuf
[1] = htons (len
);
2242 memcpy(&TempShortBuf
[2], ppseudo_hdr
, len
);
2244 status
= ft1000_write_dpram32 (dev
, 0, (PUCHAR
)&TempShortBuf
[0], (unsigned short)(len
+2));
2245 status
= ft1000_write_register (dev
, FT1000_DB_DPRAM_TX
, FT1000_REG_DOORBELL
);
2247 list_del(&ptr
->list
);
2248 kfree(ptr
->pprov_data
);
2254 DEBUG("DSP Provisioning List Entry finished\n");
2258 info
->fProvComplete
= 1;
2259 info
->CardReady
= 1;
2260 info
->DSP_loading
= 0;
2261 return STATUS_SUCCESS
;
2266 int ft1000_proc_drvmsg (struct ft1000_device
*dev
, u16 size
) {
2267 FT1000_INFO
*info
= (FT1000_INFO
*) netdev_priv (dev
->net
);
2270 PMEDIAMSG pmediamsg
;
2271 PDSPINITMSG pdspinitmsg
;
2274 PPSEUDO_HDR ppseudo_hdr
;
2277 //struct timeval tv; //mbelian
2284 char cmdbuffer
[1600];
2286 status
= ft1000_read_dpram32(dev
, 0x200, (PUCHAR
)&cmdbuffer
[0], size
);
2289 //if (ft1000_receive_cmd(dev, &cmdbuffer[0], MAX_CMD_SQSIZE, &tempword))
2293 DEBUG("ft1000_proc_drvmsg:cmdbuffer\n");
2294 for(i
= 0; i
< size
; i
+=5)
2296 if( (i
+ 5) < size
)
2297 DEBUG("0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", cmdbuffer
[i
], cmdbuffer
[i
+1], cmdbuffer
[i
+2], cmdbuffer
[i
+3], cmdbuffer
[i
+4]);
2300 for (j
= i
; j
< size
; j
++)
2301 DEBUG("0x%x ", cmdbuffer
[j
]);
2307 pdrvmsg
= (PDRVMSG
)&cmdbuffer
[2];
2308 msgtype
= ntohs(pdrvmsg
->type
);
2309 DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype
);
2312 DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE");
2314 pmediamsg
= (PMEDIAMSG
)&cmdbuffer
[0];
2315 if (info
->ProgConStat
!= 0xFF) {
2316 if (pmediamsg
->state
) {
2317 DEBUG("Media is up\n");
2318 if (info
->mediastate
== 0) {
2319 if ( info
->NetDevRegDone
)
2321 //netif_carrier_on(dev->net);//mbelian
2322 netif_wake_queue(dev
->net
);
2324 info
->mediastate
= 1;
2325 /*do_gettimeofday(&tv);
2326 info->ConTm = tv.tv_sec;*/ //mbelian
2330 DEBUG("Media is down\n");
2331 if (info
->mediastate
== 1) {
2332 info
->mediastate
= 0;
2333 if ( info
->NetDevRegDone
)
2335 //netif_carrier_off(dev->net); mbelian
2336 //netif_stop_queue(dev->net);
2343 DEBUG("Media is down\n");
2344 if (info
->mediastate
== 1) {
2345 info
->mediastate
= 0;
2346 if ( info
->NetDevRegDone
)
2348 //netif_carrier_off(dev->net); //mbelian
2349 //netif_stop_queue(dev->net);
2356 case DSP_INIT_MSG
: {
2357 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG");
2359 pdspinitmsg
= (PDSPINITMSG
)&cmdbuffer
[2];
2360 memcpy(info
->DspVer
, pdspinitmsg
->DspVer
, DSPVERSZ
);
2361 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", info
->DspVer
[0], info
->DspVer
[1], info
->DspVer
[2], info
->DspVer
[3]);
2362 memcpy(info
->HwSerNum
, pdspinitmsg
->HwSerNum
, HWSERNUMSZ
);
2363 memcpy(info
->Sku
, pdspinitmsg
->Sku
, SKUSZ
);
2364 memcpy(info
->eui64
, pdspinitmsg
->eui64
, EUISZ
);
2365 DEBUG("EUI64=%2x.%2x.%2x.%2x.%2x.%2x.%2x.%2x\n", info
->eui64
[0],info
->eui64
[1], info
->eui64
[2], info
->eui64
[3], info
->eui64
[4], info
->eui64
[5],info
->eui64
[6], info
->eui64
[7]);
2366 dev
->net
->dev_addr
[0] = info
->eui64
[0];
2367 dev
->net
->dev_addr
[1] = info
->eui64
[1];
2368 dev
->net
->dev_addr
[2] = info
->eui64
[2];
2369 dev
->net
->dev_addr
[3] = info
->eui64
[5];
2370 dev
->net
->dev_addr
[4] = info
->eui64
[6];
2371 dev
->net
->dev_addr
[5] = info
->eui64
[7];
2373 if (ntohs(pdspinitmsg
->length
) == (sizeof(DSPINITMSG
) - 20) ) {
2374 memcpy(info
->ProductMode
, pdspinitmsg
->ProductMode
, MODESZ
);
2375 memcpy(info
->RfCalVer
, pdspinitmsg
->RfCalVer
, CALVERSZ
);
2376 memcpy(info
->RfCalDate
, pdspinitmsg
->RfCalDate
, CALDATESZ
);
2377 DEBUG("RFCalVer = 0x%2x 0x%2x\n", info
->RfCalVer
[0], info
->RfCalVer
[1]);
2381 case DSP_PROVISION
: {
2382 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n");
2384 // kick off dspprov routine to start provisioning
2385 // Send provisioning data to DSP
2386 if (list_empty(&info
->prov_list
) == 0)
2388 info
->fProvComplete
= 0;
2389 status
= ft1000_dsp_prov(dev
);
2390 if (status
!= STATUS_SUCCESS
)
2394 info
->fProvComplete
= 1;
2395 status
= ft1000_write_register (dev
, FT1000_DB_HB
, FT1000_REG_DOORBELL
);
2396 DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n");
2398 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n");
2401 case DSP_STORE_INFO
: {
2402 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO");
2404 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
2405 tempword
= ntohs(pdrvmsg
->length
);
2406 info
->DSPInfoBlklen
= tempword
;
2407 if (tempword
< (MAX_DSP_SESS_REC
-4) ) {
2408 pmsg
= (PUSHORT
)&pdrvmsg
->data
[0];
2409 for (i
=0; i
<((tempword
+1)/2); i
++) {
2410 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg
);
2411 info
->DSPInfoBlk
[i
+10] = *pmsg
++;
2415 info
->DSPInfoBlklen
= 0;
2419 case DSP_GET_INFO
: {
2420 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
2421 // copy dsp info block to dsp
2422 info
->DrvMsgPend
= 1;
2423 // allow any outstanding ioctl to finish
2425 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
2426 if (tempword
& FT1000_DB_DPRAM_TX
) {
2428 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
2429 if (tempword
& FT1000_DB_DPRAM_TX
) {
2431 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
2432 if (tempword
& FT1000_DB_DPRAM_TX
) {
2438 // Put message into Slow Queue
2439 // Form Pseudo header
2440 pmsg
= (PUSHORT
)info
->DSPInfoBlk
;
2442 *pmsg
++ = htons(info
->DSPInfoBlklen
+20+info
->DSPInfoBlklen
);
2443 ppseudo_hdr
= (PPSEUDO_HDR
)(PUSHORT
)&info
->DSPInfoBlk
[2];
2444 ppseudo_hdr
->length
= htons(info
->DSPInfoBlklen
+4+info
->DSPInfoBlklen
);
2445 ppseudo_hdr
->source
= 0x10;
2446 ppseudo_hdr
->destination
= 0x20;
2447 ppseudo_hdr
->portdest
= 0;
2448 ppseudo_hdr
->portsrc
= 0;
2449 ppseudo_hdr
->sh_str_id
= 0;
2450 ppseudo_hdr
->control
= 0;
2451 ppseudo_hdr
->rsvd1
= 0;
2452 ppseudo_hdr
->rsvd2
= 0;
2453 ppseudo_hdr
->qos_class
= 0;
2454 // Insert slow queue sequence number
2455 ppseudo_hdr
->seq_num
= info
->squeseqnum
++;
2456 // Insert application id
2457 ppseudo_hdr
->portsrc
= 0;
2458 // Calculate new checksum
2459 ppseudo_hdr
->checksum
= *pmsg
++;
2460 for (i
=1; i
<7; i
++) {
2461 ppseudo_hdr
->checksum
^= *pmsg
++;
2463 info
->DSPInfoBlk
[10] = 0x7200;
2464 info
->DSPInfoBlk
[11] = htons(info
->DSPInfoBlklen
);
2465 status
= ft1000_write_dpram32 (dev
, 0, (PUCHAR
)&info
->DSPInfoBlk
[0], (unsigned short)(info
->DSPInfoBlklen
+22));
2466 status
= ft1000_write_register (dev
, FT1000_DB_DPRAM_TX
, FT1000_REG_DOORBELL
);
2467 info
->DrvMsgPend
= 0;
2472 case GET_DRV_ERR_RPT_MSG
: {
2473 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
2474 // copy driver error message to dsp
2475 info
->DrvMsgPend
= 1;
2476 // allow any outstanding ioctl to finish
2478 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
2479 if (tempword
& FT1000_DB_DPRAM_TX
) {
2481 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
2482 if (tempword
& FT1000_DB_DPRAM_TX
) {
2487 if ( (tempword
& FT1000_DB_DPRAM_TX
) == 0) {
2488 // Put message into Slow Queue
2489 // Form Pseudo header
2490 pmsg
= (PUSHORT
)&tempbuffer
[0];
2491 ppseudo_hdr
= (PPSEUDO_HDR
)pmsg
;
2492 ppseudo_hdr
->length
= htons(0x0012);
2493 ppseudo_hdr
->source
= 0x10;
2494 ppseudo_hdr
->destination
= 0x20;
2495 ppseudo_hdr
->portdest
= 0;
2496 ppseudo_hdr
->portsrc
= 0;
2497 ppseudo_hdr
->sh_str_id
= 0;
2498 ppseudo_hdr
->control
= 0;
2499 ppseudo_hdr
->rsvd1
= 0;
2500 ppseudo_hdr
->rsvd2
= 0;
2501 ppseudo_hdr
->qos_class
= 0;
2502 // Insert slow queue sequence number
2503 ppseudo_hdr
->seq_num
= info
->squeseqnum
++;
2504 // Insert application id
2505 ppseudo_hdr
->portsrc
= 0;
2506 // Calculate new checksum
2507 ppseudo_hdr
->checksum
= *pmsg
++;
2508 for (i
=1; i
<7; i
++) {
2509 ppseudo_hdr
->checksum
^= *pmsg
++;
2511 pmsg
= (PUSHORT
)&tempbuffer
[16];
2512 *pmsg
++ = htons(RSP_DRV_ERR_RPT_MSG
);
2513 *pmsg
++ = htons(0x000e);
2514 *pmsg
++ = htons(info
->DSP_TIME
[0]);
2515 *pmsg
++ = htons(info
->DSP_TIME
[1]);
2516 *pmsg
++ = htons(info
->DSP_TIME
[2]);
2517 *pmsg
++ = htons(info
->DSP_TIME
[3]);
2518 convert
.byte
[0] = info
->DspVer
[0];
2519 convert
.byte
[1] = info
->DspVer
[1];
2520 *pmsg
++ = convert
.wrd
;
2521 convert
.byte
[0] = info
->DspVer
[2];
2522 convert
.byte
[1] = info
->DspVer
[3];
2523 *pmsg
++ = convert
.wrd
;
2524 *pmsg
++ = htons(info
->DrvErrNum
);
2526 CardSendCommand (dev
, (unsigned char*)&tempbuffer
[0], (USHORT
)(0x0012 + PSEUDOSZ
));
2527 info
->DrvErrNum
= 0;
2529 info
->DrvMsgPend
= 0;
2540 DEBUG("return from ft1000_proc_drvmsg\n");
2541 return STATUS_SUCCESS
;
2546 int ft1000_poll(void* dev_id
) {
2548 //FT1000_INFO *info = (PFT1000_INFO)((struct net_device *)dev_id)->priv;
2549 //struct ft1000_device *dev = (struct ft1000_device *)info->pFt1000Dev;
2550 struct ft1000_device
*dev
= (struct ft1000_device
*)dev_id
;
2551 FT1000_INFO
*info
= (FT1000_INFO
*) netdev_priv (dev
->net
);
2561 PDPRAM_BLK pdpram_blk
;
2562 PPSEUDO_HDR ppseudo_hdr
;
2563 unsigned long flags
;
2565 //DEBUG("Enter ft1000_poll...\n");
2566 if (ft1000_chkcard(dev
) == FALSE
) {
2567 DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
2568 return STATUS_FAILURE
;
2571 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_DOORBELL
);
2572 // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword);
2574 //while ( (tempword) && (!status) ) {
2578 if (tempword
& FT1000_DB_DPRAM_RX
) {
2579 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n");
2581 status
= ft1000_read_dpram16(dev
, 0x200, (PUCHAR
)&data
, 0);
2582 //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data);
2583 size
= ntohs(data
) + 16 + 2; //wai
2585 modulo
= 4 - (size
% 4);
2586 size
= size
+ modulo
;
2588 status
= ft1000_read_dpram16(dev
, 0x201, (PUCHAR
)&portid
, 1);
2590 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid);
2592 if (size
< MAX_CMD_SQSIZE
) {
2596 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
2598 status
= ft1000_proc_drvmsg (dev
, size
);
2599 if (status
!= STATUS_SUCCESS
)
2603 // This is a dsp broadcast message
2604 // Check which application has registered for dsp broadcast messages
2605 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n");
2607 for (i
=0; i
<MAX_NUM_APP
; i
++) {
2608 if ( (info
->app_info
[i
].DspBCMsgFlag
) && (info
->app_info
[i
].fileobject
) &&
2609 (info
->app_info
[i
].NumOfMsg
< MAX_MSG_LIMIT
) )
2611 //DEBUG("Dsp broadcast message detected for app id %d\n", i);
2612 nxtph
= FT1000_DPRAM_RX_BASE
+ 2;
2613 pdpram_blk
= ft1000_get_buffer (&freercvpool
);
2614 if (pdpram_blk
!= NULL
) {
2615 if ( ft1000_receive_cmd(dev
, pdpram_blk
->pbuffer
, MAX_CMD_SQSIZE
, &nxtph
) ) {
2616 ppseudo_hdr
= (PPSEUDO_HDR
)pdpram_blk
->pbuffer
;
2617 // Put message into the appropriate application block
2618 info
->app_info
[i
].nRxMsg
++;
2619 spin_lock_irqsave(&free_buff_lock
, flags
);
2620 list_add_tail(&pdpram_blk
->list
, &info
->app_info
[i
].app_sqlist
);
2621 info
->app_info
[i
].NumOfMsg
++;
2622 spin_unlock_irqrestore(&free_buff_lock
, flags
);
2623 wake_up_interruptible(&info
->app_info
[i
].wait_dpram_msg
);
2626 info
->app_info
[i
].nRxMsgMiss
++;
2627 // Put memory back to free pool
2628 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
2629 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
2633 DEBUG("Out of memory in free receive command pool\n");
2634 info
->app_info
[i
].nRxMsgMiss
++;
2635 }//endof if (pdpram_blk != NULL)
2638 // DEBUG("app_info mismatch\n");
2642 pdpram_blk
= ft1000_get_buffer (&freercvpool
);
2643 //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk);
2644 if (pdpram_blk
!= NULL
) {
2645 if ( ft1000_receive_cmd(dev
, pdpram_blk
->pbuffer
, MAX_CMD_SQSIZE
, &nxtph
) ) {
2646 ppseudo_hdr
= (PPSEUDO_HDR
)pdpram_blk
->pbuffer
;
2647 // Search for correct application block
2648 for (i
=0; i
<MAX_NUM_APP
; i
++) {
2649 if (info
->app_info
[i
].app_id
== ppseudo_hdr
->portdest
) {
2654 if (i
==(MAX_NUM_APP
-1)) { // aelias [+] reason: was out of array boundary
2655 info
->app_info
[i
].nRxMsgMiss
++;
2656 DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr
->portdest
);
2657 // Put memory back to free pool
2658 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
2661 if (info
->app_info
[i
].NumOfMsg
> MAX_MSG_LIMIT
) {
2662 // Put memory back to free pool
2663 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
2666 info
->app_info
[i
].nRxMsg
++;
2667 // Put message into the appropriate application block
2668 //pxu spin_lock_irqsave(&free_buff_lock, flags);
2669 list_add_tail(&pdpram_blk
->list
, &info
->app_info
[i
].app_sqlist
);
2670 info
->app_info
[i
].NumOfMsg
++;
2671 //pxu spin_unlock_irqrestore(&free_buff_lock, flags);
2672 //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
2677 // Put memory back to free pool
2678 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
2682 DEBUG("Out of memory in free receive command pool\n");
2686 } //endof if (size < MAX_CMD_SQSIZE)
2688 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size
);
2690 status
= ft1000_write_register (dev
, FT1000_DB_DPRAM_RX
, FT1000_REG_DOORBELL
);
2692 else if (tempword
& FT1000_DSP_ASIC_RESET
) {
2693 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DSP_ASIC_RESET\n");
2695 // Let's reset the ASIC from the Host side as well
2696 status
= ft1000_write_register (dev
, ASIC_RESET_BIT
, FT1000_REG_RESET
);
2697 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_RESET
);
2699 while (tempword
& ASIC_RESET_BIT
) {
2700 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_RESET
);
2707 DEBUG("Unable to reset ASIC\n");
2708 return STATUS_SUCCESS
;
2711 // Program WMARK register
2712 status
= ft1000_write_register (dev
, 0x600, FT1000_REG_MAG_WATERMARK
);
2713 // clear ASIC reset doorbell
2714 status
= ft1000_write_register (dev
, FT1000_DSP_ASIC_RESET
, FT1000_REG_DOORBELL
);
2717 else if (tempword
& FT1000_ASIC_RESET_REQ
) {
2718 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
2720 // clear ASIC reset request from DSP
2721 status
= ft1000_write_register (dev
, FT1000_ASIC_RESET_REQ
, FT1000_REG_DOORBELL
);
2722 status
= ft1000_write_register (dev
, HOST_INTF_BE
, FT1000_REG_SUP_CTRL
);
2723 // copy dsp session record from Adapter block
2724 status
= ft1000_write_dpram32 (dev
, 0, (PUCHAR
)&info
->DSPSess
.Rec
[0], 1024);
2725 // Program WMARK register
2726 status
= ft1000_write_register (dev
, 0x600, FT1000_REG_MAG_WATERMARK
);
2727 // ring doorbell to tell DSP that ASIC is out of reset
2728 status
= ft1000_write_register (dev
, FT1000_ASIC_RESET_DSP
, FT1000_REG_DOORBELL
);
2730 else if (tempword
& FT1000_DB_COND_RESET
) {
2731 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
2733 // Reset ASIC and DSP
2735 if (info
->fAppMsgPend
== 0) {
2736 // Reset ASIC and DSP
2738 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER0
, (PUCHAR
)&(info
->DSP_TIME
[0]), FT1000_MAG_DSP_TIMER0_INDX
);
2739 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER1
, (PUCHAR
)&(info
->DSP_TIME
[1]), FT1000_MAG_DSP_TIMER1_INDX
);
2740 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER2
, (PUCHAR
)&(info
->DSP_TIME
[2]), FT1000_MAG_DSP_TIMER2_INDX
);
2741 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER3
, (PUCHAR
)&(info
->DSP_TIME
[3]), FT1000_MAG_DSP_TIMER3_INDX
);
2742 info
->CardReady
= 0;
2743 info
->DrvErrNum
= DSP_CONDRESET_INFO
;
2744 DEBUG("ft1000_hw:DSP conditional reset requested\n");
2745 info
->ft1000_reset(dev
->net
);
2748 info
->fProvComplete
= 0;
2749 info
->fCondResetPend
= 1;
2752 ft1000_write_register(dev
, FT1000_DB_COND_RESET
, FT1000_REG_DOORBELL
);
2755 }//endof if ( !status )
2757 //DEBUG("return from ft1000_poll.\n");
2758 return STATUS_SUCCESS
;