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
38 static int ft1000_reset(struct net_device *ft1000dev);
39 static int ft1000_submit_rx_urb(PFT1000_INFO info);
40 static void ft1000_hbchk(u_long data);
41 static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev);
42 static int ft1000_open (struct net_device *dev);
43 static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev);
44 static struct timer_list poll_timer[MAX_NUM_CARDS];
45 static int ft1000_chkcard (struct ft1000_device *dev);
47 static const struct net_device_ops ft1000net_ops = {
48 .ndo_start_xmit = ft1000_start_xmit,
49 .ndo_get_stats = ft1000_netdev_stats,
50 .ndo_open = ft1000_open,
51 .ndo_stop = ft1000_close,
57 static u8 tempbuffer[1600];
58 static int gCardIndex;
60 #define MAX_RCV_LOOP 100
63 static int atoi(const char *s)
70 while (*s != '\0' && *s >= '0' && *s <= '9') {
71 k = 10 * k + (*s - '0');
73 // Let's put a limit on this while loop to avoid deadlock scenario
80 /****************************************************************
81 * ft1000_control_complete
82 ****************************************************************/
83 static void ft1000_control_complete(struct urb *urb)
85 struct ft1000_device *ft1000dev = (struct ft1000_device *)urb->context;
87 //DEBUG("FT1000_CONTROL_COMPLETE ENTERED\n");
88 if (ft1000dev == NULL )
90 DEBUG("NULL ft1000dev, failure\n");
93 else if ( ft1000dev->dev == NULL )
95 DEBUG("NULL ft1000dev->dev, failure\n");
98 //spin_lock(&ft1000dev->device_lock);
100 if(waitqueue_active(&ft1000dev->control_wait))
102 wake_up(&ft1000dev->control_wait);
105 //DEBUG("FT1000_CONTROL_COMPLETE RETURNED\n");
106 //spin_unlock(&ft1000dev->device_lock);
109 //---------------------------------------------------------------------------
110 // Function: ft1000_control
112 // Parameters: ft1000_device - device structure
113 // pipe - usb control message pipe
114 // request - control request
115 // requesttype - control message request type
116 // value - value to be written or 0
117 // index - register index
118 // data - data buffer to hold the read/write values
120 // timeout - control message time out value
122 // Returns: STATUS_SUCCESS - success
123 // STATUS_FAILURE - failure
125 // Description: This function sends a control message via USB interface synchronously
129 //---------------------------------------------------------------------------
130 static int ft1000_control(struct ft1000_device *ft1000dev,unsigned int pipe,
141 if (ft1000dev == NULL )
143 DEBUG("NULL ft1000dev, failure\n");
144 return STATUS_FAILURE;
146 else if ( ft1000dev->dev == NULL )
148 DEBUG("NULL ft1000dev->dev, failure\n");
149 return STATUS_FAILURE;
152 ret = usb_control_msg(ft1000dev->dev,
163 ret = STATUS_SUCCESS;
165 ret = STATUS_FAILURE;
172 //---------------------------------------------------------------------------
173 // Function: ft1000_read_register
175 // Parameters: ft1000_device - device structure
176 // Data - data buffer to hold the value read
177 // nRegIndex - register index
179 // Returns: STATUS_SUCCESS - success
180 // STATUS_FAILURE - failure
182 // Description: This function returns the value in a register
186 //---------------------------------------------------------------------------
188 u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx)
190 u16 ret = STATUS_SUCCESS;
192 //DEBUG("ft1000_read_register: reg index is %d\n", nRegIndx);
193 //DEBUG("ft1000_read_register: spin_lock locked\n");
194 ret = ft1000_control(ft1000dev,
195 usb_rcvctrlpipe(ft1000dev->dev,0),
196 HARLEY_READ_REGISTER, //request --READ_REGISTER
197 HARLEY_READ_OPERATION, //requestType
202 LARGE_TIMEOUT ); //timeout
204 //DEBUG("ft1000_read_register: ret is %d \n", ret);
206 //DEBUG("ft1000_read_register: data is %x \n", *Data);
207 if ( ret != STATUS_SUCCESS )
208 return STATUS_FAILURE;
214 //---------------------------------------------------------------------------
215 // Function: ft1000_write_register
217 // Parameters: ft1000_device - device structure
218 // value - value to write into a register
219 // nRegIndex - register index
221 // Returns: STATUS_SUCCESS - success
222 // STATUS_FAILURE - failure
224 // Description: This function writes the value in a register
228 //---------------------------------------------------------------------------
229 u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRegIndx)
231 u16 ret = STATUS_SUCCESS;
233 //DEBUG("ft1000_write_register: value is: %d, reg index is: %d\n", value, nRegIndx);
235 ret = ft1000_control(ft1000dev,
236 usb_sndctrlpipe(ft1000dev->dev, 0),
237 HARLEY_WRITE_REGISTER, //request -- WRITE_REGISTER
238 HARLEY_WRITE_OPERATION, //requestType
245 if ( ret != STATUS_SUCCESS )
246 return STATUS_FAILURE;
251 //---------------------------------------------------------------------------
252 // Function: ft1000_read_dpram32
254 // Parameters: ft1000_device - device structure
255 // indx - starting address to read
256 // buffer - data buffer to hold the data read
257 // cnt - number of byte read from DPRAM
259 // Returns: STATUS_SUCCESS - success
260 // STATUS_FAILURE - failure
262 // Description: This function read a number of bytes from DPRAM
266 //---------------------------------------------------------------------------
268 u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt)
270 u16 ret = STATUS_SUCCESS;
272 //DEBUG("ft1000_read_dpram32: indx: %d cnt: %d\n", indx, cnt);
273 ret =ft1000_control(ft1000dev,
274 usb_rcvctrlpipe(ft1000dev->dev,0),
275 HARLEY_READ_DPRAM_32, //request --READ_DPRAM_32
276 HARLEY_READ_OPERATION, //requestType
281 LARGE_TIMEOUT ); //timeout
283 //DEBUG("ft1000_read_dpram32: ret is %d \n", ret);
285 //DEBUG("ft1000_read_dpram32: ret=%d \n", ret);
286 if ( ret != STATUS_SUCCESS )
287 return STATUS_FAILURE;
293 //---------------------------------------------------------------------------
294 // Function: ft1000_write_dpram32
296 // Parameters: ft1000_device - device structure
297 // indx - starting address to write the data
298 // buffer - data buffer to write into DPRAM
299 // cnt - number of bytes to write
301 // Returns: STATUS_SUCCESS - success
302 // STATUS_FAILURE - failure
304 // Description: This function writes into DPRAM a number of bytes
308 //---------------------------------------------------------------------------
309 u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt)
311 u16 ret = STATUS_SUCCESS;
313 //DEBUG("ft1000_write_dpram32: indx: %d buffer: %x cnt: %d\n", indx, buffer, cnt);
315 cnt += cnt - (cnt % 4);
317 ret = ft1000_control(ft1000dev,
318 usb_sndctrlpipe(ft1000dev->dev, 0),
319 HARLEY_WRITE_DPRAM_32, //request -- WRITE_DPRAM_32
320 HARLEY_WRITE_OPERATION, //requestType
328 if ( ret != STATUS_SUCCESS )
329 return STATUS_FAILURE;
335 //---------------------------------------------------------------------------
336 // Function: ft1000_read_dpram16
338 // Parameters: ft1000_device - device structure
339 // indx - starting address to read
340 // buffer - data buffer to hold the data read
341 // hightlow - high or low 16 bit word
343 // Returns: STATUS_SUCCESS - success
344 // STATUS_FAILURE - failure
346 // Description: This function read 16 bits from DPRAM
350 //---------------------------------------------------------------------------
351 u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow)
353 u16 ret = STATUS_SUCCESS;
355 //DEBUG("ft1000_read_dpram16: indx: %d hightlow: %d\n", indx, highlow);
360 request = HARLEY_READ_DPRAM_LOW;
362 request = HARLEY_READ_DPRAM_HIGH;
364 ret = ft1000_control(ft1000dev,
365 usb_rcvctrlpipe(ft1000dev->dev,0),
366 request, //request --READ_DPRAM_H/L
367 HARLEY_READ_OPERATION, //requestType
372 LARGE_TIMEOUT ); //timeout
374 //DEBUG("ft1000_read_dpram16: ret is %d \n", ret);
377 //DEBUG("ft1000_read_dpram16: data is %x \n", *buffer);
378 if ( ret != STATUS_SUCCESS )
379 return STATUS_FAILURE;
385 //---------------------------------------------------------------------------
386 // Function: ft1000_write_dpram16
388 // Parameters: ft1000_device - device structure
389 // indx - starting address to write the data
390 // value - 16bits value to write
391 // hightlow - high or low 16 bit word
393 // Returns: STATUS_SUCCESS - success
394 // STATUS_FAILURE - failure
396 // Description: This function writes into DPRAM a number of bytes
400 //---------------------------------------------------------------------------
401 u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT value, u8 highlow)
403 u16 ret = STATUS_SUCCESS;
407 //DEBUG("ft1000_write_dpram16: indx: %d value: %d highlow: %d\n", indx, value, highlow);
413 request = HARLEY_WRITE_DPRAM_LOW;
415 request = HARLEY_WRITE_DPRAM_HIGH;
417 ret = ft1000_control(ft1000dev,
418 usb_sndctrlpipe(ft1000dev->dev, 0),
419 request, //request -- WRITE_DPRAM_H/L
420 HARLEY_WRITE_OPERATION, //requestType
428 if ( ret != STATUS_SUCCESS )
429 return STATUS_FAILURE;
435 //---------------------------------------------------------------------------
436 // Function: fix_ft1000_read_dpram32
438 // Parameters: ft1000_device - device structure
439 // indx - starting address to read
440 // buffer - data buffer to hold the data read
443 // Returns: STATUS_SUCCESS - success
444 // STATUS_FAILURE - failure
446 // Description: This function read DPRAM 4 words at a time
450 //---------------------------------------------------------------------------
451 u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer)
455 u16 ret = STATUS_SUCCESS;
457 //DEBUG("fix_ft1000_read_dpram32: indx: %d \n", indx);
459 ret = ft1000_read_dpram32(ft1000dev, pos, buf, 16);
460 if (ret == STATUS_SUCCESS)
463 *buffer++ = buf[pos++];
464 *buffer++ = buf[pos++];
465 *buffer++ = buf[pos++];
466 *buffer++ = buf[pos++];
470 DEBUG("fix_ft1000_read_dpram32: DPRAM32 Read failed\n");
478 //DEBUG("fix_ft1000_read_dpram32: data is %x \n", *buffer);
484 //---------------------------------------------------------------------------
485 // Function: fix_ft1000_write_dpram32
487 // Parameters: ft1000_device - device structure
488 // indx - starting address to write
489 // buffer - data buffer to write
492 // Returns: STATUS_SUCCESS - success
493 // STATUS_FAILURE - failure
495 // Description: This function write to DPRAM 4 words at a time
499 //---------------------------------------------------------------------------
500 u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer)
506 UCHAR resultbuffer[32];
508 u16 ret = STATUS_SUCCESS;
510 //DEBUG("fix_ft1000_write_dpram32: Entered:\n");
514 ret = ft1000_read_dpram32(ft1000dev, pos1, buf, 16);
515 if (ret == STATUS_SUCCESS)
518 buf[pos2++] = *buffer++;
519 buf[pos2++] = *buffer++;
520 buf[pos2++] = *buffer++;
521 buf[pos2++] = *buffer++;
522 ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16);
526 DEBUG("fix_ft1000_write_dpram32: DPRAM32 Read failed\n");
531 ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16);
532 if (ret == STATUS_SUCCESS)
537 if (buf[i] != resultbuffer[i]){
539 ret = STATUS_FAILURE;
544 if (ret == STATUS_FAILURE)
546 ret = ft1000_write_dpram32(ft1000dev, pos1, (PUCHAR)&tempbuffer[0], 16);
547 ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16);
548 if (ret == STATUS_SUCCESS)
553 if (tempbuffer[i] != resultbuffer[i])
555 ret = STATUS_FAILURE;
556 DEBUG("fix_ft1000_write_dpram32 Failed to write\n");
567 //------------------------------------------------------------------------
569 // Function: card_reset_dsp
571 // Synopsis: This function is called to reset or activate the DSP
573 // Arguments: value - reset or activate
576 //-----------------------------------------------------------------------
577 static void card_reset_dsp (struct ft1000_device *ft1000dev, BOOLEAN value)
579 u16 status = STATUS_SUCCESS;
582 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
583 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_CTRL);
586 DEBUG("Reset DSP\n");
587 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
588 tempword |= DSP_RESET_BIT;
589 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
593 DEBUG("Activate DSP\n");
594 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
596 tempword |= DSP_ENCRYPTED;
597 tempword &= ~DSP_UNENCRYPTED;
599 tempword |= DSP_UNENCRYPTED;
600 tempword &= ~DSP_ENCRYPTED;
602 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
603 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
604 tempword &= ~EFUSE_MEM_DISABLE;
605 tempword &= ~DSP_RESET_BIT;
606 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
607 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
611 //---------------------------------------------------------------------------
612 // Function: CardSendCommand
614 // Parameters: ft1000_device - device structure
615 // ptempbuffer - command buffer
616 // size - command buffer size
618 // Returns: STATUS_SUCCESS - success
619 // STATUS_FAILURE - failure
621 // Description: This function sends a command to ASIC
625 //---------------------------------------------------------------------------
626 void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size)
629 unsigned char *commandbuf;
631 DEBUG("CardSendCommand: enter CardSendCommand... size=%d\n", size);
633 commandbuf =(unsigned char*) kmalloc(size+2, GFP_KERNEL);
634 //memset((void*)commandbuf, 0, size+2);
635 memcpy((void*)commandbuf+2, (void*)ptempbuffer, size);
637 //DEBUG("CardSendCommand: Command Send\n");
639 for (i=0; i<size+2; i++)
641 DEBUG("FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
645 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
652 // check for odd word
656 // Must force to be 32 bit aligned
657 size += 4 - (size % 4);
661 //DEBUG("CardSendCommand: write dpram ... size=%d\n", size);
662 ft1000_write_dpram32(ft1000dev, 0,commandbuf, size);
664 //DEBUG("CardSendCommand: write into doorbell ...\n");
665 ft1000_write_register(ft1000dev, FT1000_DB_DPRAM_TX ,FT1000_REG_DOORBELL) ;
668 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
669 //DEBUG("CardSendCommand: read doorbell ...temp=%x\n", temp);
670 if ( (temp & 0x0100) == 0)
672 //DEBUG("CardSendCommand: Message sent\n");
678 //--------------------------------------------------------------------------
680 // Function: dsp_reload
682 // Synopsis: This function is called to load or reload the DSP
684 // Arguments: ft1000dev - device structure
687 //-----------------------------------------------------------------------
688 void dsp_reload (struct ft1000_device *ft1000dev)
694 PFT1000_INFO pft1000info;
696 pft1000info = netdev_priv(ft1000dev->net);
698 pft1000info->CardReady = 0;
699 pft1000info->DSP_loading= 1;
701 // Program Interrupt Mask register
702 status = ft1000_write_register (ft1000dev, 0xffff, FT1000_REG_SUP_IMASK);
704 status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET);
705 tempword |= ASIC_RESET_BIT;
706 status = ft1000_write_register (ft1000dev, tempword, FT1000_REG_RESET);
708 status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET);
709 DEBUG("Reset Register = 0x%x\n", tempword);
712 card_reset_dsp (ft1000dev, 1);
714 card_reset_dsp (ft1000dev, 0);
717 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
719 // Let's check for FEFE
720 status = ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (PUCHAR)&templong, 4);
721 DEBUG("templong (fefe) = 0x%8x\n", templong);
724 status = scram_dnldr(ft1000dev, pFileStart, FileLength);
726 if ( status != STATUS_SUCCESS)
730 pft1000info->DSP_loading= 0;
732 DEBUG("dsp_reload returned\n");
737 //---------------------------------------------------------------------------
739 // Function: ft1000_reset_asic
740 // Descripton: This function will call the Card Service function to reset the
743 // dev - device structure
747 //---------------------------------------------------------------------------
748 static void ft1000_reset_asic (struct net_device *dev)
750 FT1000_INFO *info = netdev_priv(dev);
751 struct ft1000_device *ft1000dev = info->pFt1000Dev;
754 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
756 info->ASICResetNum++;
758 // Let's use the register provided by the Magnemite ASIC to reset the
760 ft1000_write_register(ft1000dev, (DSP_RESET_BIT | ASIC_RESET_BIT), FT1000_REG_RESET );
764 // set watermark to -1 in order to not generate an interrrupt
765 ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_MAG_WATERMARK);
768 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR);
769 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword);
770 ft1000_write_register (ft1000dev, tempword, FT1000_REG_SUP_ISR);
771 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR);
772 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword);
776 //---------------------------------------------------------------------------
778 // Function: ft1000_disable_interrupts
779 // Descripton: This function will disable all interrupts.
781 // dev - device structure
785 //---------------------------------------------------------------------------
786 static void ft1000_disable_interrupts(struct net_device *dev) {
787 FT1000_INFO *info = netdev_priv(dev);
788 struct ft1000_device *ft1000dev = info->pFt1000Dev;
791 DEBUG("ft1000_hw: ft1000_disable_interrupts()\n");
792 ft1000_write_register (ft1000dev, ISR_MASK_ALL, FT1000_REG_SUP_IMASK);
793 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_IMASK);
794 DEBUG("ft1000_hw:ft1000_disable_interrupts:current interrupt enable mask = 0x%x\n", tempword);
795 info->InterruptsEnabled = FALSE;
798 //---------------------------------------------------------------------------
800 // Function: ft1000_enable_interrupts
801 // Descripton: This function will enable interrupts base on the current interrupt mask.
803 // dev - device structure
807 //---------------------------------------------------------------------------
808 static void ft1000_enable_interrupts(struct net_device *dev) {
809 FT1000_INFO *info = netdev_priv(dev);
810 struct ft1000_device *ft1000dev = info->pFt1000Dev;
813 DEBUG("ft1000_hw:ft1000_enable_interrupts()\n");
814 ft1000_write_register (ft1000dev, info->CurrentInterruptEnableMask, FT1000_REG_SUP_IMASK);
815 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_IMASK);
816 DEBUG("ft1000_hw:ft1000_enable_interrupts:current interrupt enable mask = 0x%x\n", tempword);
817 info->InterruptsEnabled = TRUE;
821 //---------------------------------------------------------------------------
823 // Function: ft1000_reset_card
824 // Descripton: This function will reset the card
826 // dev - device structure
828 // status - FALSE (card reset fail)
829 // TRUE (card reset successful)
831 //---------------------------------------------------------------------------
832 static int ft1000_reset_card (struct net_device *dev)
834 FT1000_INFO *info = netdev_priv(dev);
835 struct ft1000_device *ft1000dev = info->pFt1000Dev;
839 DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
841 info->fCondResetPend = 1;
843 info->fProvComplete = 0;
844 //ft1000_disable_interrupts(dev);
846 // Cancel heartbeat task since we are reloading the dsp
847 //del_timer(&poll_timer[info->CardNumber]);
849 // Make sure we free any memory reserve for provisioning
850 while (list_empty(&info->prov_list) == 0) {
851 DEBUG("ft1000_hw:ft1000_reset_card:deleting provisioning record\n");
852 ptr = list_entry(info->prov_list.next, PROV_RECORD, list);
853 list_del(&ptr->list);
854 kfree(ptr->pprov_data);
858 DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n");
860 ft1000_reset_asic(dev);
865 DEBUG("ft1000_hw:ft1000_reset_card:resetting ASIC and DSP\n");
866 ft1000_write_register (ft1000dev, (DSP_RESET_BIT | ASIC_RESET_BIT), FT1000_REG_RESET );
869 // Copy DSP session record into info block if this is not a coldstart
870 //if (ft1000_card_present == 1) {
871 spin_lock_irqsave(&info->dpram_lock, flags);
873 ft1000_write_register(ft1000dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR);
874 for (i=0;i<MAX_DSP_SESS_REC/2; i++) {
875 //info->DSPSess.MagRec[i] = inl(dev->base_addr+FT1000_REG_MAG_DPDATA);
876 ft1000_read_dpram32(ft1000dev, FT1000_REG_MAG_DPDATA, (PCHAR)&(info->DSPSess.MagRec[i]), 4);
879 spin_unlock_irqrestore(&info->dpram_lock, flags);
881 info->squeseqnum = 0;
883 DEBUG("ft1000_hw:ft1000_reset_card:resetting ASIC\n");
886 ft1000_reset_asic(dev);
890 DEBUG("ft1000_hw:ft1000_reset_card:downloading dsp image\n");
893 // Put dsp in reset and take ASIC out of reset
894 DEBUG("ft1000_hw:ft1000_reset_card:Put DSP in reset and take ASIC out of reset\n");
895 ft1000_write_register (ft1000dev, DSP_RESET_BIT, FT1000_REG_RESET);
897 // Setting MAGNEMITE ASIC to big endian mode
898 ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
900 // Take DSP out of reset
902 ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
903 tempword |= DSP_ENCRYPTED;
904 tempword &= ~DSP_UNENCRYPTED;
905 ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
906 tempword &= ~EFUSE_MEM_DISABLE;
907 ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
908 tempword &= ~DSP_RESET_BIT;
909 ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
912 // FLARION_DSP_ACTIVE;
914 DEBUG("ft1000_hw:ft1000_reset_card:Take DSP out of reset\n");
916 // Wait for 0xfefe indicating dsp ready before starting download
917 for (i=0; i<50; i++) {
918 //tempword = ft1000_read_dpram_mag_16(dev, FT1000_MAG_DPRAM_FEFE, FT1000_MAG_DPRAM_FEFE_INDX);
919 ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (PUCHAR)&templong, 4);
920 if (tempword == 0xfefe) {
927 DEBUG("ft1000_hw:ft1000_reset_card:No FEFE detected from DSP\n");
934 DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n");
935 dsp_reload(ft1000dev);
937 DEBUG("dsp reload successful\n");
942 // Initialize DSP heartbeat area to ho
943 ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag, FT1000_MAG_HI_HO_INDX);
944 ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (PCHAR)&tempword, FT1000_MAG_HI_HO_INDX);
945 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword);
950 //ft1000_enable_interrupts(dev);
951 /* Schedule heartbeat process to run every 2 seconds */
952 //poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
953 //poll_timer[info->CardNumber].data = (u_long)dev;
954 //add_timer(&poll_timer[info->CardNumber]);
956 info->fCondResetPend = 0;
963 #ifdef HAVE_NET_DEVICE_OPS
964 static const struct net_device_ops ftnet_ops =
966 .ndo_open = &ft1000_open,
967 .ndo_stop = &ft1000_close,
968 .ndo_start_xmit = &ft1000_start_xmit,
969 .ndo_get_stats = &ft1000_netdev_stats,
974 //---------------------------------------------------------------------------
975 // Function: init_ft1000_netdev
977 // Parameters: ft1000dev - device structure
980 // Returns: STATUS_SUCCESS - success
981 // STATUS_FAILURE - failure
983 // Description: This function initialize the network device
987 //---------------------------------------------------------------------------
988 u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
990 struct net_device *netdev;
991 FT1000_INFO *pInfo = NULL;
992 PDPRAM_BLK pdpram_blk;
995 gCardIndex=0; //mbelian
997 DEBUG("Enter init_ft1000_netdev...\n");
1000 netdev = alloc_etherdev( sizeof(FT1000_INFO));
1003 DEBUG("init_ft1000_netdev: can not allocate network device\n");
1004 return STATUS_FAILURE;
1007 //pInfo = (PFT1000_INFO)netdev->priv;
1008 pInfo = (FT1000_INFO *) netdev_priv (netdev);
1010 //DEBUG("init_ft1000_netdev: gFt1000Info=%x, netdev=%x, ft1000dev=%x\n", gFt1000Info, netdev, ft1000dev);
1012 memset (pInfo, 0, sizeof(FT1000_INFO));
1014 dev_alloc_name(netdev, netdev->name);
1016 //for the first inserted card, decide the card index beginning number, in case there are existing network interfaces
1017 if ( gCardIndex == 0 )
1019 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name);
1021 if ( strncmp(netdev->name,"eth", 3) == 0) {
1022 //pInfo->CardNumber = atoi(&netdev->name[3]);
1023 gCardIndex = atoi(&netdev->name[3]);
1024 pInfo->CardNumber = gCardIndex;
1025 DEBUG("card number = %d\n", pInfo->CardNumber);
1028 printk(KERN_ERR "ft1000: Invalid device name\n");
1030 return STATUS_FAILURE;
1035 //not the first inserted card, increase card number by 1
1037 pInfo->CardNumber = gCardIndex;
1038 /*DEBUG("card number = %d\n", pInfo->CardNumber);*/ //mbelian
1041 memset(&pInfo->stats, 0, sizeof(struct net_device_stats) );
1043 spin_lock_init(&pInfo->dpram_lock);
1044 pInfo->pFt1000Dev = ft1000dev;
1045 pInfo->DrvErrNum = 0;
1046 pInfo->ASICResetNum = 0;
1047 pInfo->registered = 1;
1048 pInfo->ft1000_reset = ft1000_reset;
1049 pInfo->mediastate = 0;
1050 pInfo->fifo_cnt = 0;
1051 pInfo->DeviceCreated = FALSE;
1052 pInfo->DeviceMajor = 0;
1053 pInfo->CurrentInterruptEnableMask = ISR_DEFAULT_MASK;
1054 pInfo->InterruptsEnabled = FALSE;
1055 pInfo->CardReady = 0;
1056 pInfo->DSP_loading = 0;
1057 pInfo->DSP_TIME[0] = 0;
1058 pInfo->DSP_TIME[1] = 0;
1059 pInfo->DSP_TIME[2] = 0;
1060 pInfo->DSP_TIME[3] = 0;
1061 pInfo->fAppMsgPend = 0;
1062 pInfo->fCondResetPend = 0;
1064 pInfo->dspalive = 0;
1065 for (i=0;i<32 ;i++ )
1067 pInfo->tempbuf[i] = 0;
1070 INIT_LIST_HEAD(&pInfo->prov_list);
1073 #ifdef HAVE_NET_DEVICE_OPS
1074 netdev->netdev_ops = &ftnet_ops;
1076 netdev->hard_start_xmit = &ft1000_start_xmit;
1077 netdev->get_stats = &ft1000_netdev_stats;
1078 netdev->open = &ft1000_open;
1079 netdev->stop = &ft1000_close;
1082 //netif_stop_queue(netdev); //mbelian
1085 ft1000dev->net = netdev;
1089 //init free_buff_lock, freercvpool, numofmsgbuf, pdpram_blk
1090 //only init once per card
1092 DEBUG("Initialize free_buff_lock and freercvpool\n");
1093 spin_lock_init(&free_buff_lock);
1095 // initialize a list of buffers to be use for queuing up receive command data
1096 INIT_LIST_HEAD (&freercvpool);
1098 // create list of free buffers
1099 for (i=0; i<NUM_OF_FREE_BUFFERS; i++) {
1100 // Get memory for DPRAM_DATA link list
1101 pdpram_blk = kmalloc ( sizeof(DPRAM_BLK), GFP_KERNEL );
1102 // Get a block of memory to store command data
1103 pdpram_blk->pbuffer = kmalloc ( MAX_CMD_SQSIZE, GFP_KERNEL );
1104 // link provisioning data
1105 list_add_tail (&pdpram_blk->list, &freercvpool);
1107 numofmsgbuf = NUM_OF_FREE_BUFFERS;
1110 return STATUS_SUCCESS;
1116 //---------------------------------------------------------------------------
1117 // Function: reg_ft1000_netdev
1119 // Parameters: ft1000dev - device structure
1122 // Returns: STATUS_SUCCESS - success
1123 // STATUS_FAILURE - failure
1125 // Description: This function register the network driver
1129 //---------------------------------------------------------------------------
1130 u16 reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf)
1132 struct net_device *netdev;
1136 netdev = ft1000dev->net;
1137 pInfo = netdev_priv(ft1000dev->net);
1138 DEBUG("Enter reg_ft1000_netdev...\n");
1141 ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID);
1143 usb_set_intfdata(intf, pInfo);
1144 SET_NETDEV_DEV(netdev, &intf->dev);
1146 rc = register_netdev(netdev);
1149 DEBUG("reg_ft1000_netdev: could not register network device\n");
1150 free_netdev(netdev);
1151 return STATUS_FAILURE;
1155 //Create character device, implemented by Jim
1156 ft1000_CreateDevice(ft1000dev);
1158 //INIT_LIST_HEAD(&pInfo->prov_list);
1160 for (i=0; i<MAX_NUM_CARDS; i++) {
1161 poll_timer[i].function = ft1000_hbchk;
1165 //hard code MAC address for now
1167 netdev->dev_addr[0] = 0;
1168 netdev->dev_addr[1] = 7;
1169 netdev->dev_addr[2] = 0x35;
1170 netdev->dev_addr[3] = 0x84;
1171 netdev->dev_addr[4] = 0;
1172 netdev->dev_addr[5] = 0x20 + pInfo->CardNumber;
1175 DEBUG ("reg_ft1000_netdev returned\n");
1177 pInfo->CardReady = 1;
1180 return STATUS_SUCCESS;
1183 static int ft1000_reset(struct net_device *dev)
1185 ft1000_reset_card(dev);
1189 //---------------------------------------------------------------------------
1190 // Function: ft1000_usb_transmit_complete
1192 // Parameters: urb - transmitted usb urb
1197 // Description: This is the callback function when a urb is transmitted
1201 //---------------------------------------------------------------------------
1202 static void ft1000_usb_transmit_complete(struct urb *urb)
1205 struct ft1000_device *ft1000dev = urb->context;
1207 //DEBUG("ft1000_usb_transmit_complete entered\n");
1208 // Jim spin_lock(&ft1000dev->device_lock);
1211 printk("%s: TX status %d\n", ft1000dev->net->name, urb->status);
1213 netif_wake_queue(ft1000dev->net);
1215 //Jim spin_unlock(&ft1000dev->device_lock);
1216 //DEBUG("Return from ft1000_usb_transmit_complete\n");
1220 /****************************************************************
1222 ****************************************************************/
1223 static int ft1000_read_fifo_reg(struct ft1000_device *ft1000dev,unsigned int pipe,
1234 DECLARE_WAITQUEUE(wait, current);
1236 struct usb_ctrlrequest *dr;
1239 if (ft1000dev == NULL )
1241 DEBUG("NULL ft1000dev, failure\n");
1242 return STATUS_FAILURE;
1244 else if ( ft1000dev->dev == NULL )
1246 DEBUG("NULL ft1000dev->dev, failure\n");
1247 return STATUS_FAILURE;
1250 spin_lock(&ft1000dev->device_lock);
1252 /*DECLARE_WAITQUEUE(wait, current);
1254 struct usb_ctrlrequest *dr;
1259 spin_unlock(&ft1000dev->device_lock);
1263 urb = usb_alloc_urb(0, GFP_KERNEL);
1264 dr = kmalloc(sizeof(struct usb_ctrlrequest), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
1269 spin_unlock(&ft1000dev->device_lock);
1275 dr->bRequestType = requesttype;
1276 dr->bRequest = request;
1281 usb_fill_control_urb(urb, ft1000dev->dev, pipe, (char*)dr, (void*)data, size, (void *)ft1000_control_complete, (void*)ft1000dev);
1284 init_waitqueue_head(&ft1000dev->control_wait);
1286 //current->state = TASK_INTERRUPTIBLE; //mbelian
1287 set_current_state(TASK_INTERRUPTIBLE);
1289 add_wait_queue(&ft1000dev->control_wait, &wait);
1294 status = usb_submit_urb(urb, GFP_KERNEL);
1300 remove_wait_queue(&ft1000dev->control_wait, &wait);
1301 spin_unlock(&ft1000dev->device_lock);
1305 if(urb->status == -EINPROGRESS)
1307 while(timeout && urb->status == -EINPROGRESS)
1309 status = timeout = schedule_timeout(timeout);
1317 remove_wait_queue(&ft1000dev->control_wait, &wait);
1321 usb_unlink_urb(urb);
1322 printk("ft1000 timeout\n");
1323 status = -ETIMEDOUT;
1327 status = urb->status;
1331 printk("ft1000 control message failed (urb addr: %p) with error number: %i\n", urb, (int)status);
1333 usb_clear_halt(ft1000dev->dev, usb_rcvctrlpipe(ft1000dev->dev, 0));
1334 usb_clear_halt(ft1000dev->dev, usb_sndctrlpipe(ft1000dev->dev, 0));
1335 usb_unlink_urb(urb);
1343 spin_unlock(&ft1000dev->device_lock);
1349 //---------------------------------------------------------------------------
1350 // Function: ft1000_read_fifo_len
1352 // Parameters: ft1000dev - device structure
1357 // Description: read the fifo length register content
1361 //---------------------------------------------------------------------------
1362 static inline u16 ft1000_read_fifo_len (struct net_device *dev)
1367 //FT1000_INFO *info = (PFT1000_INFO)dev->priv;
1368 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev);
1369 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1370 // 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 *???
1371 DEBUG("ft1000_read_fifo_len: enter ft1000dev %p\n", ft1000dev); //aelias [+] reason: up
1372 //ft1000_read_register(ft1000dev, &temp, FT1000_REG_MAG_UFSR);
1374 ret = STATUS_SUCCESS;
1376 ret = ft1000_read_fifo_reg(ft1000dev,
1377 usb_rcvctrlpipe(ft1000dev->dev,0),
1378 HARLEY_READ_REGISTER,
1379 HARLEY_READ_OPERATION,
1381 FT1000_REG_MAG_UFSR,
1387 ret = STATUS_SUCCESS;
1389 ret = STATUS_FAILURE;
1391 DEBUG("ft1000_read_fifo_len: returned %d\n", temp);
1398 //---------------------------------------------------------------------------
1400 // Function: ft1000_copy_down_pkt
1401 // Descripton: This function will take an ethernet packet and convert it to
1402 // a Flarion packet prior to sending it to the ASIC Downlink
1405 // dev - device structure
1406 // packet - address of ethernet packet
1407 // len - length of IP packet
1412 //---------------------------------------------------------------------------
1413 static int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len)
1415 FT1000_INFO *pInfo = netdev_priv(netdev);
1416 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
1424 if (!pInfo->CardReady)
1427 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
1428 return STATUS_FAILURE;
1433 //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len);
1436 // Check if there is room on the FIFO
1437 if ( len > ft1000_read_fifo_len (netdev) )
1440 if ( len > ft1000_read_fifo_len (netdev) )
1445 if ( len > ft1000_read_fifo_len (netdev) )
1450 if ( len > ft1000_read_fifo_len (netdev) )
1455 if ( len > ft1000_read_fifo_len (netdev) )
1460 if ( len > ft1000_read_fifo_len (netdev) )
1465 if ( len > ft1000_read_fifo_len (netdev) )
1467 DEBUG("ft1000_hw:ft1000_copy_down_pkt:Transmit FIFO is fulli - pkt drop\n");
1468 pInfo->stats.tx_errors++;
1469 return STATUS_SUCCESS;
1474 count = sizeof (PSEUDO_HDR) + len;
1475 if(count > MAX_BUF_SIZE)
1477 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n");
1478 DEBUG("size = %d\n", count);
1479 return STATUS_FAILURE;
1483 count = count + (4- (count %4) );
1485 pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]);
1486 *pTemp ++ = ntohs(count);
1493 pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]);
1494 checksum = *pTemp ++;
1497 checksum ^= *pTemp ++;
1499 *pTemp++ = checksum;
1500 memcpy (&(pFt1000Dev->tx_buf[sizeof(PSEUDO_HDR)]), packet, len);
1502 //usb_init_urb(pFt1000Dev->tx_urb); //mbelian
1504 netif_stop_queue(netdev);
1506 //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count);
1508 usb_fill_bulk_urb(pFt1000Dev->tx_urb,
1510 usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr),
1513 ft1000_usb_transmit_complete,
1516 t = (u8 *)pFt1000Dev->tx_urb->transfer_buffer;
1517 //DEBUG("transfer_length=%d\n", pFt1000Dev->tx_urb->transfer_buffer_length);
1518 /*for (i=0; i<count; i++ )
1520 DEBUG("%x ", *t++ );
1524 ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC);
1527 DEBUG("ft1000 failed tx_urb %d\n", ret);
1529 /* pInfo->stats.tx_errors++;
1531 netif_start_queue(netdev); */ //mbelian
1532 return STATUS_FAILURE;
1537 //DEBUG("ft1000 sucess tx_urb %d\n", ret);
1539 pInfo->stats.tx_packets++;
1540 pInfo->stats.tx_bytes += (len+14);
1543 //DEBUG("ft1000_copy_down_pkt() exit\n");
1545 return STATUS_SUCCESS;
1548 //---------------------------------------------------------------------------
1549 // Function: ft1000_start_xmit
1551 // Parameters: skb - socket buffer to be sent
1552 // dev - network device
1557 // Description: transmit a ethernet packet
1561 //---------------------------------------------------------------------------
1562 static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1564 FT1000_INFO *pInfo = netdev_priv(dev);
1565 struct ft1000_device *pFt1000Dev= pInfo->pFt1000Dev;
1570 //DEBUG(" ft1000_start_xmit() entered\n");
1574 DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" );
1575 return STATUS_FAILURE;
1578 if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1580 DEBUG("network driver is closed, return\n");
1582 //usb_kill_urb(pFt1000Dev->tx_urb); //mbelian
1583 return STATUS_SUCCESS;
1586 //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len);
1587 pipe = usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr);
1588 maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe));
1589 //DEBUG("ft1000_start_xmit 2: pipe=%d dev->maxpacket = %d\n", pipe, maxlen);
1591 pdata = (u8 *)skb->data;
1592 /*for (i=0; i<skb->len; i++)
1593 DEBUG("skb->data[%d]=%x ", i, *(skb->data+i));
1598 if (pInfo->mediastate == 0)
1600 /* Drop packet is mediastate is down */
1601 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n");
1603 return STATUS_SUCCESS;
1606 if ( (skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE) )
1608 /* Drop packet which has invalid size */
1609 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n");
1611 return STATUS_SUCCESS;
1614 if(ft1000_copy_down_pkt (dev, (pdata+ENET_HEADER_SIZE-2), skb->len - ENET_HEADER_SIZE + 2) == STATUS_FAILURE)
1617 return STATUS_SUCCESS;
1621 //DEBUG(" ft1000_start_xmit() exit\n");
1626 //---------------------------------------------------------------------------
1628 // Function: ft1000_copy_up_pkt
1629 // Descripton: This function will take a packet from the FIFO up link and
1630 // convert it into an ethernet packet and deliver it to the IP stack
1632 // urb - the receving usb urb
1638 //---------------------------------------------------------------------------
1639 static int ft1000_copy_up_pkt (struct urb *urb)
1641 PFT1000_INFO info = urb->context;
1642 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1643 struct net_device *net = ft1000dev->net;
1648 struct sk_buff *skb;
1655 //DEBUG("ft1000_copy_up_pkt entered\n");
1657 if ( ft1000dev->status & FT1000_STATUS_CLOSING)
1659 DEBUG("network driver is closed, return\n");
1660 return STATUS_SUCCESS;
1664 len = urb->transfer_buffer_length;
1665 lena = urb->actual_length; //mbelian
1666 //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n",
1667 // urb->transfer_buffer_length, urb->actual_length);
1669 chksum = (PUSHORT)ft1000dev->rx_buf;
1671 tempword = *chksum++;
1674 tempword ^= *chksum++;
1677 if (tempword != *chksum)
1679 info->stats.rx_errors ++;
1680 ft1000_submit_rx_urb(info);
1681 return STATUS_FAILURE;
1685 //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum);
1687 skb = dev_alloc_skb(len+12+2);
1691 DEBUG("ft1000_copy_up_pkt: No Network buffers available\n");
1692 info->stats.rx_errors++;
1693 ft1000_submit_rx_urb(info);
1694 return STATUS_FAILURE;
1697 pbuffer = (u8 *)skb_put(skb, len+12);
1699 //subtract the number of bytes read already
1703 *pbuffer++ = net->dev_addr[0];
1704 *pbuffer++ = net->dev_addr[1];
1705 *pbuffer++ = net->dev_addr[2];
1706 *pbuffer++ = net->dev_addr[3];
1707 *pbuffer++ = net->dev_addr[4];
1708 *pbuffer++ = net->dev_addr[5];
1719 memcpy(pbuffer, ft1000dev->rx_buf+sizeof(PSEUDO_HDR), len-sizeof(PSEUDO_HDR));
1721 //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n");
1722 /*for (i=0; i<len+12; i++)
1724 DEBUG("ft1000_copy_up_pkt: Protocol Data: 0x%x\n ", *ptemp++);
1729 skb->protocol = eth_type_trans(skb, net);
1730 skb->ip_summed = CHECKSUM_UNNECESSARY;
1733 info->stats.rx_packets++;
1734 // Add on 12 bytes for MAC address which was removed
1735 info->stats.rx_bytes += (lena+12); //mbelian
1737 ft1000_submit_rx_urb(info);
1738 //DEBUG("ft1000_copy_up_pkt exited\n");
1742 //---------------------------------------------------------------------------
1744 // Function: ft1000_submit_rx_urb
1745 // Descripton: the receiving function of the network driver
1748 // info - a private structure contains the device information
1754 //---------------------------------------------------------------------------
1755 static int ft1000_submit_rx_urb(PFT1000_INFO info)
1758 struct ft1000_device *pFt1000Dev = info->pFt1000Dev;
1760 //netif_carrier_on(pFt1000Dev->net);
1762 //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb));
1763 if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1765 DEBUG("network driver is closed, return\n");
1766 //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian
1767 return STATUS_SUCCESS;
1769 //memset(pFt1000Dev->rx_urb, 0, sizeof(*pFt1000Dev->rx_urb));
1770 //usb_init_urb(pFt1000Dev->rx_urb);//mbelian
1772 //spin_lock_init(&pFt1000Dev->rx_urb->lock);
1774 usb_fill_bulk_urb(pFt1000Dev->rx_urb,
1776 usb_rcvbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_in_endpointAddr),
1779 (usb_complete_t)ft1000_copy_up_pkt,
1783 if((result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC)))
1785 printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result);
1786 return STATUS_FAILURE;
1789 //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result);
1791 return STATUS_SUCCESS;
1794 //---------------------------------------------------------------------------
1795 // Function: ft1000_open
1798 // dev - network device
1803 // Description: open the network driver
1807 //---------------------------------------------------------------------------
1808 static int ft1000_open (struct net_device *dev)
1810 FT1000_INFO *pInfo = (FT1000_INFO *)netdev_priv(dev);
1811 struct timeval tv; //mbelian
1813 DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber);
1814 //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len);
1816 pInfo->stats.rx_bytes = 0; //mbelian
1817 pInfo->stats.tx_bytes = 0; //mbelian
1818 pInfo->stats.rx_packets = 0; //mbelian
1819 pInfo->stats.tx_packets = 0; //mbelian
1820 do_gettimeofday(&tv);
1821 pInfo->ConTm = tv.tv_sec;
1822 pInfo->ProgConStat = 0; //mbelian
1825 netif_start_queue(dev);
1827 //netif_device_attach(dev);
1829 netif_carrier_on(dev); //mbelian
1831 ft1000_submit_rx_urb(pInfo);
1835 //---------------------------------------------------------------------------
1836 // Function: ft1000_close
1839 // net - network device
1844 // Description: close the network driver
1848 //---------------------------------------------------------------------------
1849 int ft1000_close(struct net_device *net)
1851 FT1000_INFO *pInfo = (FT1000_INFO *) netdev_priv (net);
1852 struct ft1000_device *ft1000dev = pInfo->pFt1000Dev;
1854 //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt);
1856 ft1000dev->status |= FT1000_STATUS_CLOSING;
1858 //DEBUG("ft1000_close: calling usb_kill_urb \n");
1859 //usb_kill_urb(ft1000dev->rx_urb);
1860 //usb_kill_urb(ft1000dev->tx_urb);
1863 DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);
1864 netif_carrier_off(net);//mbelian
1865 netif_stop_queue(net);
1866 //DEBUG("ft1000_close: netif_stop_queue called\n");
1867 ft1000dev->status &= ~FT1000_STATUS_CLOSING;
1869 pInfo->ProgConStat = 0xff; //mbelian
1875 static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev)
1877 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev);
1878 //struct ft1000_device *ft1000dev = info->pFt1000Dev;
1880 //return &(ft1000dev->stats);//mbelian
1881 return &(info->stats); //mbelian
1885 /*********************************************************************************
1890 //---------------------------------------------------------------------------
1892 // Function: ft1000_chkcard
1893 // Descripton: This function will check if the device is presently available on
1896 // dev - device structure
1898 // status - FALSE (device is not present)
1899 // TRUE (device is present)
1901 //---------------------------------------------------------------------------
1902 static int ft1000_chkcard (struct ft1000_device *dev) {
1905 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
1907 if (info->fCondResetPend)
1909 DEBUG("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1913 // Mask register is used to check for device presence since it is never
1915 status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK);
1916 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword);
1917 if (tempword == 0) {
1918 DEBUG("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
1922 // The system will return the value of 0xffff for the version register
1923 // if the device is not present.
1924 status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID);
1925 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword);
1926 //pxu if (tempword == 0xffff) {
1927 if (tempword != 0x1b01 ){
1928 dev->status |= FT1000_STATUS_CLOSING; //mbelian
1929 DEBUG("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
1935 //---------------------------------------------------------------------------
1937 // Function: ft1000_hbchk
1938 // Descripton: This function will perform the heart beat check of the DSP as
1939 // well as the ASIC.
1941 // dev - device structure
1945 //---------------------------------------------------------------------------
1946 static void ft1000_hbchk(u_long data)
1948 struct ft1000_device *dev = (struct ft1000_device *)data;
1953 info = (FT1000_INFO *) netdev_priv (dev->net);
1955 DEBUG("ft1000_hbchk called for CardNumber = %d CardReady = %d\n", info->CardNumber, info->CardReady);
1957 if (info->fCondResetPend == 1) {
1958 // Reset ASIC and DSP
1959 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
1960 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
1961 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
1962 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
1964 info->DrvErrNum = DSP_CONDRESET_INFO;
1965 DEBUG("ft1000_hw:DSP conditional reset requested\n");
1966 ft1000_reset_card(dev->net);
1967 info->fCondResetPend = 0;
1968 /* Schedule this module to run every 2 seconds */
1970 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
1971 poll_timer[info->CardNumber].data = (u_long)dev;
1972 add_timer(&poll_timer[info->CardNumber]);
1979 if (info->CardReady == 1) {
1980 // Perform dsp heartbeat check
1981 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX));
1982 DEBUG("ft1000_hw:ft1000_hbchk:hi_ho value = 0x%x\n", tempword);
1983 // Let's perform another check if ho is not detected
1984 if (tempword != ho) {
1985 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword,FT1000_MAG_HI_HO_INDX));
1987 if (tempword != ho) {
1988 printk(KERN_INFO "ft1000: heartbeat failed - no ho detected\n");
1989 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
1990 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
1991 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
1992 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
1993 info->DrvErrNum = DSP_HB_INFO;
1994 if (ft1000_reset_card(dev->net) == 0) {
1995 printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n");
1996 info->ProgConStat = 0xff;
1999 /* Schedule this module to run every 2 seconds */
2000 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2001 poll_timer[info->CardNumber].data = (u_long)dev;
2002 add_timer(&poll_timer[info->CardNumber]);
2006 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2007 // Let's check doorbell again if fail
2008 if (tempword & FT1000_DB_HB) {
2009 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2011 if (tempword & FT1000_DB_HB) {
2012 printk(KERN_INFO "ft1000: heartbeat doorbell not clear by firmware\n");
2013 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2014 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2015 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2016 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2017 info->DrvErrNum = DSP_HB_INFO;
2018 if (ft1000_reset_card(dev->net) == 0) {
2019 printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n");
2020 info->ProgConStat = 0xff;
2023 /* Schedule this module to run every 2 seconds */
2024 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2025 poll_timer[info->CardNumber].data = (u_long)dev;
2026 add_timer(&poll_timer[info->CardNumber]);
2030 // Set dedicated area to hi and ring appropriate doorbell according
2031 // to hi/ho heartbeat protocol
2032 ft1000_write_dpram16(dev, FT1000_MAG_HI_HO, hi_mag, FT1000_MAG_HI_HO_INDX);
2034 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX));
2035 // Let's write hi again if fail
2036 if (tempword != hi) {
2037 ft1000_write_dpram16(dev, FT1000_MAG_HI_HO, hi_mag, FT1000_MAG_HI_HO_INDX);
2038 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX));
2041 if (tempword != hi) {
2042 printk(KERN_INFO "ft1000: heartbeat failed - cannot write hi into DPRAM\n");
2043 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2044 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2045 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2046 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2048 info->DrvErrNum = DSP_HB_INFO;
2049 if (ft1000_reset_card(dev->net) == 0) {
2050 printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n");
2051 info->ProgConStat = 0xff;
2054 /* Schedule this module to run every 2 seconds */
2055 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2056 poll_timer[info->CardNumber].data = (u_long)dev;
2057 add_timer(&poll_timer[info->CardNumber]);
2060 ft1000_write_register(dev, FT1000_DB_HB, FT1000_REG_DOORBELL);
2064 /* Schedule this module to run every 2 seconds */
2065 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2066 poll_timer[info->CardNumber].data = (u_long)dev;
2067 add_timer(&poll_timer[info->CardNumber]);
2070 //---------------------------------------------------------------------------
2072 // Function: ft1000_receive_cmd
2073 // Descripton: This function will read a message from the dpram area.
2075 // dev - network device structure
2076 // pbuffer - caller supply address to buffer
2077 // pnxtph - pointer to next pseudo header
2079 // Status = 0 (unsuccessful)
2082 //---------------------------------------------------------------------------
2083 static BOOLEAN ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) {
2089 ret = ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (PUCHAR)&size, FT1000_MAG_PH_LEN_INDX);
2090 size = ntohs(size) + PSEUDOSZ;
2092 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size);
2096 ppseudohdr = (u16 *)pbuffer;
2097 //spin_lock_irqsave (&info->dpram_lock, flags);
2098 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR);
2099 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
2100 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2102 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE+1, FT1000_REG_DPRAM_ADDR);
2103 for (i=0; i<=(size>>2); i++) {
2104 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
2106 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
2109 //copy odd aligned word
2110 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
2111 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2113 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
2114 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2116 if (size & 0x0001) {
2117 //copy odd byte from fifo
2118 ret = ft1000_read_register(dev, &tempword, FT1000_REG_DPRAM_DATA);
2119 *pbuffer = ntohs(tempword);
2121 //spin_unlock_irqrestore(&info->dpram_lock, flags);
2123 // Check if pseudo header checksum is good
2124 // Calculate pseudo header checksum
2125 tempword = *ppseudohdr++;
2126 for (i=1; i<7; i++) {
2127 tempword ^= *ppseudohdr++;
2129 if ( (tempword != *ppseudohdr) ) {
2135 DEBUG("ft1000_receive_cmd:pbuffer\n");
2136 for(i = 0; i < size; i+=5)
2138 if( (i + 5) < size )
2139 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]);
2142 for (j = i; j < size; j++)
2143 DEBUG("0x%x ", tempbuffer[j]);
2156 static int ft1000_dsp_prov(void *arg)
2158 struct ft1000_device *dev = (struct ft1000_device *)arg;
2159 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
2164 PPSEUDO_HDR ppseudo_hdr;
2167 USHORT TempShortBuf [256];
2169 DEBUG("*** DspProv Entered\n");
2171 while ( list_empty(&info->prov_list) == 0
2172 /*&& !kthread_should_stop() */)
2174 DEBUG("DSP Provisioning List Entry\n");
2176 // Check if doorbell is available
2177 DEBUG("check if doorbell is cleared\n");
2178 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
2181 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n");
2185 while (tempword & FT1000_DB_DPRAM_TX) {
2189 DEBUG("FT1000:ft1000_dsp_prov:message drop\n");
2190 return STATUS_FAILURE;
2192 ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2195 if ( !(tempword & FT1000_DB_DPRAM_TX) ) {
2196 DEBUG("*** Provision Data Sent to DSP\n");
2198 // Send provisioning data
2199 ptr = list_entry(info->prov_list.next, PROV_RECORD, list);
2200 len = *(u16 *)ptr->pprov_data;
2205 pmsg = (PUSHORT)ptr->pprov_data;
2206 ppseudo_hdr = (PPSEUDO_HDR)pmsg;
2207 // Insert slow queue sequence number
2208 ppseudo_hdr->seq_num = info->squeseqnum++;
2209 ppseudo_hdr->portsrc = 0;
2210 // Calculate new checksum
2211 ppseudo_hdr->checksum = *pmsg++;
2212 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
2213 for (i=1; i<7; i++) {
2214 ppseudo_hdr->checksum ^= *pmsg++;
2215 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
2218 TempShortBuf[0] = 0;
2219 TempShortBuf[1] = htons (len);
2220 memcpy(&TempShortBuf[2], ppseudo_hdr, len);
2222 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&TempShortBuf[0], (unsigned short)(len+2));
2223 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
2225 list_del(&ptr->list);
2226 kfree(ptr->pprov_data);
2232 DEBUG("DSP Provisioning List Entry finished\n");
2236 info->fProvComplete = 1;
2237 info->CardReady = 1;
2238 info->DSP_loading= 0;
2239 return STATUS_SUCCESS;
2244 static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
2245 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
2248 PMEDIAMSG pmediamsg;
2249 PDSPINITMSG pdspinitmsg;
2252 PPSEUDO_HDR ppseudo_hdr;
2255 //struct timeval tv; //mbelian
2262 char *cmdbuffer = kmalloc(1600, GFP_KERNEL);
2264 return STATUS_FAILURE;
2266 status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size);
2269 //if (ft1000_receive_cmd(dev, &cmdbuffer[0], MAX_CMD_SQSIZE, &tempword))
2273 DEBUG("ft1000_proc_drvmsg:cmdbuffer\n");
2274 for(i = 0; i < size; i+=5)
2276 if( (i + 5) < size )
2277 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]);
2280 for (j = i; j < size; j++)
2281 DEBUG("0x%x ", cmdbuffer[j]);
2287 pdrvmsg = (PDRVMSG)&cmdbuffer[2];
2288 msgtype = ntohs(pdrvmsg->type);
2289 DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype);
2292 DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE");
2294 pmediamsg = (PMEDIAMSG)&cmdbuffer[0];
2295 if (info->ProgConStat != 0xFF) {
2296 if (pmediamsg->state) {
2297 DEBUG("Media is up\n");
2298 if (info->mediastate == 0) {
2299 if ( info->NetDevRegDone )
2301 //netif_carrier_on(dev->net);//mbelian
2302 netif_wake_queue(dev->net);
2304 info->mediastate = 1;
2305 /*do_gettimeofday(&tv);
2306 info->ConTm = tv.tv_sec;*/ //mbelian
2310 DEBUG("Media is down\n");
2311 if (info->mediastate == 1) {
2312 info->mediastate = 0;
2313 if ( info->NetDevRegDone )
2315 //netif_carrier_off(dev->net); mbelian
2316 //netif_stop_queue(dev->net);
2323 DEBUG("Media is down\n");
2324 if (info->mediastate == 1) {
2325 info->mediastate = 0;
2326 if ( info->NetDevRegDone)
2328 //netif_carrier_off(dev->net); //mbelian
2329 //netif_stop_queue(dev->net);
2336 case DSP_INIT_MSG: {
2337 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG");
2339 pdspinitmsg = (PDSPINITMSG)&cmdbuffer[2];
2340 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
2341 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", info->DspVer[0], info->DspVer[1], info->DspVer[2], info->DspVer[3]);
2342 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum, HWSERNUMSZ);
2343 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
2344 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
2345 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]);
2346 dev->net->dev_addr[0] = info->eui64[0];
2347 dev->net->dev_addr[1] = info->eui64[1];
2348 dev->net->dev_addr[2] = info->eui64[2];
2349 dev->net->dev_addr[3] = info->eui64[5];
2350 dev->net->dev_addr[4] = info->eui64[6];
2351 dev->net->dev_addr[5] = info->eui64[7];
2353 if (ntohs(pdspinitmsg->length) == (sizeof(DSPINITMSG) - 20) ) {
2354 memcpy(info->ProductMode, pdspinitmsg->ProductMode, MODESZ);
2355 memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, CALVERSZ);
2356 memcpy(info->RfCalDate, pdspinitmsg->RfCalDate, CALDATESZ);
2357 DEBUG("RFCalVer = 0x%2x 0x%2x\n", info->RfCalVer[0], info->RfCalVer[1]);
2361 case DSP_PROVISION: {
2362 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n");
2364 // kick off dspprov routine to start provisioning
2365 // Send provisioning data to DSP
2366 if (list_empty(&info->prov_list) == 0)
2368 info->fProvComplete = 0;
2369 status = ft1000_dsp_prov(dev);
2370 if (status != STATUS_SUCCESS)
2374 info->fProvComplete = 1;
2375 status = ft1000_write_register (dev, FT1000_DB_HB, FT1000_REG_DOORBELL);
2376 DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n");
2378 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n");
2381 case DSP_STORE_INFO: {
2382 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO");
2384 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
2385 tempword = ntohs(pdrvmsg->length);
2386 info->DSPInfoBlklen = tempword;
2387 if (tempword < (MAX_DSP_SESS_REC-4) ) {
2388 pmsg = (PUSHORT)&pdrvmsg->data[0];
2389 for (i=0; i<((tempword+1)/2); i++) {
2390 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg);
2391 info->DSPInfoBlk[i+10] = *pmsg++;
2395 info->DSPInfoBlklen = 0;
2399 case DSP_GET_INFO: {
2400 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
2401 // copy dsp info block to dsp
2402 info->DrvMsgPend = 1;
2403 // allow any outstanding ioctl to finish
2405 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2406 if (tempword & FT1000_DB_DPRAM_TX) {
2408 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2409 if (tempword & FT1000_DB_DPRAM_TX) {
2411 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2412 if (tempword & FT1000_DB_DPRAM_TX) {
2418 // Put message into Slow Queue
2419 // Form Pseudo header
2420 pmsg = (PUSHORT)info->DSPInfoBlk;
2422 *pmsg++ = htons(info->DSPInfoBlklen+20+info->DSPInfoBlklen);
2423 ppseudo_hdr = (PPSEUDO_HDR)(PUSHORT)&info->DSPInfoBlk[2];
2424 ppseudo_hdr->length = htons(info->DSPInfoBlklen+4+info->DSPInfoBlklen);
2425 ppseudo_hdr->source = 0x10;
2426 ppseudo_hdr->destination = 0x20;
2427 ppseudo_hdr->portdest = 0;
2428 ppseudo_hdr->portsrc = 0;
2429 ppseudo_hdr->sh_str_id = 0;
2430 ppseudo_hdr->control = 0;
2431 ppseudo_hdr->rsvd1 = 0;
2432 ppseudo_hdr->rsvd2 = 0;
2433 ppseudo_hdr->qos_class = 0;
2434 // Insert slow queue sequence number
2435 ppseudo_hdr->seq_num = info->squeseqnum++;
2436 // Insert application id
2437 ppseudo_hdr->portsrc = 0;
2438 // Calculate new checksum
2439 ppseudo_hdr->checksum = *pmsg++;
2440 for (i=1; i<7; i++) {
2441 ppseudo_hdr->checksum ^= *pmsg++;
2443 info->DSPInfoBlk[10] = 0x7200;
2444 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen);
2445 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPInfoBlk[0], (unsigned short)(info->DSPInfoBlklen+22));
2446 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
2447 info->DrvMsgPend = 0;
2452 case GET_DRV_ERR_RPT_MSG: {
2453 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
2454 // copy driver error message to dsp
2455 info->DrvMsgPend = 1;
2456 // allow any outstanding ioctl to finish
2458 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2459 if (tempword & FT1000_DB_DPRAM_TX) {
2461 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2462 if (tempword & FT1000_DB_DPRAM_TX) {
2467 if ( (tempword & FT1000_DB_DPRAM_TX) == 0) {
2468 // Put message into Slow Queue
2469 // Form Pseudo header
2470 pmsg = (PUSHORT)&tempbuffer[0];
2471 ppseudo_hdr = (PPSEUDO_HDR)pmsg;
2472 ppseudo_hdr->length = htons(0x0012);
2473 ppseudo_hdr->source = 0x10;
2474 ppseudo_hdr->destination = 0x20;
2475 ppseudo_hdr->portdest = 0;
2476 ppseudo_hdr->portsrc = 0;
2477 ppseudo_hdr->sh_str_id = 0;
2478 ppseudo_hdr->control = 0;
2479 ppseudo_hdr->rsvd1 = 0;
2480 ppseudo_hdr->rsvd2 = 0;
2481 ppseudo_hdr->qos_class = 0;
2482 // Insert slow queue sequence number
2483 ppseudo_hdr->seq_num = info->squeseqnum++;
2484 // Insert application id
2485 ppseudo_hdr->portsrc = 0;
2486 // Calculate new checksum
2487 ppseudo_hdr->checksum = *pmsg++;
2488 for (i=1; i<7; i++) {
2489 ppseudo_hdr->checksum ^= *pmsg++;
2491 pmsg = (PUSHORT)&tempbuffer[16];
2492 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
2493 *pmsg++ = htons(0x000e);
2494 *pmsg++ = htons(info->DSP_TIME[0]);
2495 *pmsg++ = htons(info->DSP_TIME[1]);
2496 *pmsg++ = htons(info->DSP_TIME[2]);
2497 *pmsg++ = htons(info->DSP_TIME[3]);
2498 convert.byte[0] = info->DspVer[0];
2499 convert.byte[1] = info->DspVer[1];
2500 *pmsg++ = convert.wrd;
2501 convert.byte[0] = info->DspVer[2];
2502 convert.byte[1] = info->DspVer[3];
2503 *pmsg++ = convert.wrd;
2504 *pmsg++ = htons(info->DrvErrNum);
2506 CardSendCommand (dev, (unsigned char*)&tempbuffer[0], (USHORT)(0x0012 + PSEUDOSZ));
2507 info->DrvErrNum = 0;
2509 info->DrvMsgPend = 0;
2520 status = STATUS_SUCCESS;
2523 DEBUG("return from ft1000_proc_drvmsg\n");
2529 int ft1000_poll(void* dev_id) {
2531 //FT1000_INFO *info = (PFT1000_INFO)((struct net_device *)dev_id)->priv;
2532 //struct ft1000_device *dev = (struct ft1000_device *)info->pFt1000Dev;
2533 struct ft1000_device *dev = (struct ft1000_device *)dev_id;
2534 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
2544 PDPRAM_BLK pdpram_blk;
2545 PPSEUDO_HDR ppseudo_hdr;
2546 unsigned long flags;
2548 //DEBUG("Enter ft1000_poll...\n");
2549 if (ft1000_chkcard(dev) == FALSE) {
2550 DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
2551 return STATUS_FAILURE;
2554 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
2555 // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword);
2557 //while ( (tempword) && (!status) ) {
2561 if (tempword & FT1000_DB_DPRAM_RX) {
2562 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n");
2564 status = ft1000_read_dpram16(dev, 0x200, (PUCHAR)&data, 0);
2565 //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data);
2566 size = ntohs(data) + 16 + 2; //wai
2568 modulo = 4 - (size % 4);
2569 size = size + modulo;
2571 status = ft1000_read_dpram16(dev, 0x201, (PUCHAR)&portid, 1);
2573 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid);
2575 if (size < MAX_CMD_SQSIZE) {
2579 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
2581 status = ft1000_proc_drvmsg (dev, size);
2582 if (status != STATUS_SUCCESS )
2586 // This is a dsp broadcast message
2587 // Check which application has registered for dsp broadcast messages
2588 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n");
2590 for (i=0; i<MAX_NUM_APP; i++) {
2591 if ( (info->app_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) &&
2592 (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT) )
2594 //DEBUG("Dsp broadcast message detected for app id %d\n", i);
2595 nxtph = FT1000_DPRAM_RX_BASE + 2;
2596 pdpram_blk = ft1000_get_buffer (&freercvpool);
2597 if (pdpram_blk != NULL) {
2598 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
2599 ppseudo_hdr = (PPSEUDO_HDR)pdpram_blk->pbuffer;
2600 // Put message into the appropriate application block
2601 info->app_info[i].nRxMsg++;
2602 spin_lock_irqsave(&free_buff_lock, flags);
2603 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
2604 info->app_info[i].NumOfMsg++;
2605 spin_unlock_irqrestore(&free_buff_lock, flags);
2606 wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
2609 info->app_info[i].nRxMsgMiss++;
2610 // Put memory back to free pool
2611 ft1000_free_buffer(pdpram_blk, &freercvpool);
2612 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
2616 DEBUG("Out of memory in free receive command pool\n");
2617 info->app_info[i].nRxMsgMiss++;
2618 }//endof if (pdpram_blk != NULL)
2621 // DEBUG("app_info mismatch\n");
2625 pdpram_blk = ft1000_get_buffer (&freercvpool);
2626 //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk);
2627 if (pdpram_blk != NULL) {
2628 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
2629 ppseudo_hdr = (PPSEUDO_HDR)pdpram_blk->pbuffer;
2630 // Search for correct application block
2631 for (i=0; i<MAX_NUM_APP; i++) {
2632 if (info->app_info[i].app_id == ppseudo_hdr->portdest) {
2637 if (i==(MAX_NUM_APP-1)) { // aelias [+] reason: was out of array boundary
2638 info->app_info[i].nRxMsgMiss++;
2639 DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr->portdest);
2640 // Put memory back to free pool
2641 ft1000_free_buffer(pdpram_blk, &freercvpool);
2644 if (info->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
2645 // Put memory back to free pool
2646 ft1000_free_buffer(pdpram_blk, &freercvpool);
2649 info->app_info[i].nRxMsg++;
2650 // Put message into the appropriate application block
2651 //pxu spin_lock_irqsave(&free_buff_lock, flags);
2652 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
2653 info->app_info[i].NumOfMsg++;
2654 //pxu spin_unlock_irqrestore(&free_buff_lock, flags);
2655 //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
2660 // Put memory back to free pool
2661 ft1000_free_buffer(pdpram_blk, &freercvpool);
2665 DEBUG("Out of memory in free receive command pool\n");
2669 } //endof if (size < MAX_CMD_SQSIZE)
2671 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size);
2673 status = ft1000_write_register (dev, FT1000_DB_DPRAM_RX, FT1000_REG_DOORBELL);
2675 else if (tempword & FT1000_DSP_ASIC_RESET) {
2676 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DSP_ASIC_RESET\n");
2678 // Let's reset the ASIC from the Host side as well
2679 status = ft1000_write_register (dev, ASIC_RESET_BIT, FT1000_REG_RESET);
2680 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
2682 while (tempword & ASIC_RESET_BIT) {
2683 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
2690 DEBUG("Unable to reset ASIC\n");
2691 return STATUS_SUCCESS;
2694 // Program WMARK register
2695 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2696 // clear ASIC reset doorbell
2697 status = ft1000_write_register (dev, FT1000_DSP_ASIC_RESET, FT1000_REG_DOORBELL);
2700 else if (tempword & FT1000_ASIC_RESET_REQ) {
2701 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
2703 // clear ASIC reset request from DSP
2704 status = ft1000_write_register (dev, FT1000_ASIC_RESET_REQ, FT1000_REG_DOORBELL);
2705 status = ft1000_write_register (dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
2706 // copy dsp session record from Adapter block
2707 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPSess.Rec[0], 1024);
2708 // Program WMARK register
2709 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2710 // ring doorbell to tell DSP that ASIC is out of reset
2711 status = ft1000_write_register (dev, FT1000_ASIC_RESET_DSP, FT1000_REG_DOORBELL);
2713 else if (tempword & FT1000_DB_COND_RESET) {
2714 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
2716 // Reset ASIC and DSP
2718 if (info->fAppMsgPend == 0) {
2719 // Reset ASIC and DSP
2721 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2722 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2723 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2724 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2725 info->CardReady = 0;
2726 info->DrvErrNum = DSP_CONDRESET_INFO;
2727 DEBUG("ft1000_hw:DSP conditional reset requested\n");
2728 info->ft1000_reset(dev->net);
2731 info->fProvComplete = 0;
2732 info->fCondResetPend = 1;
2735 ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL);
2738 }//endof if ( !status )
2740 //DEBUG("return from ft1000_poll.\n");
2741 return STATUS_SUCCESS;