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 unsigned long gCardIndex;
60 #define MAX_RCV_LOOP 100
62 /****************************************************************
63 * ft1000_control_complete
64 ****************************************************************/
65 static void ft1000_control_complete(struct urb *urb)
67 struct ft1000_device *ft1000dev = (struct ft1000_device *)urb->context;
69 //DEBUG("FT1000_CONTROL_COMPLETE ENTERED\n");
70 if (ft1000dev == NULL )
72 DEBUG("NULL ft1000dev, failure\n");
75 else if ( ft1000dev->dev == NULL )
77 DEBUG("NULL ft1000dev->dev, failure\n");
80 //spin_lock(&ft1000dev->device_lock);
82 if(waitqueue_active(&ft1000dev->control_wait))
84 wake_up(&ft1000dev->control_wait);
87 //DEBUG("FT1000_CONTROL_COMPLETE RETURNED\n");
88 //spin_unlock(&ft1000dev->device_lock);
91 //---------------------------------------------------------------------------
92 // Function: ft1000_control
94 // Parameters: ft1000_device - device structure
95 // pipe - usb control message pipe
96 // request - control request
97 // requesttype - control message request type
98 // value - value to be written or 0
99 // index - register index
100 // data - data buffer to hold the read/write values
102 // timeout - control message time out value
104 // Returns: STATUS_SUCCESS - success
105 // STATUS_FAILURE - failure
107 // Description: This function sends a control message via USB interface synchronously
111 //---------------------------------------------------------------------------
112 static int ft1000_control(struct ft1000_device *ft1000dev,unsigned int pipe,
123 if (ft1000dev == NULL )
125 DEBUG("NULL ft1000dev, failure\n");
126 return STATUS_FAILURE;
128 else if ( ft1000dev->dev == NULL )
130 DEBUG("NULL ft1000dev->dev, failure\n");
131 return STATUS_FAILURE;
134 ret = usb_control_msg(ft1000dev->dev,
145 ret = STATUS_SUCCESS;
147 ret = STATUS_FAILURE;
154 //---------------------------------------------------------------------------
155 // Function: ft1000_read_register
157 // Parameters: ft1000_device - device structure
158 // Data - data buffer to hold the value read
159 // nRegIndex - register index
161 // Returns: STATUS_SUCCESS - success
162 // STATUS_FAILURE - failure
164 // Description: This function returns the value in a register
168 //---------------------------------------------------------------------------
170 u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx)
172 u16 ret = STATUS_SUCCESS;
174 //DEBUG("ft1000_read_register: reg index is %d\n", nRegIndx);
175 //DEBUG("ft1000_read_register: spin_lock locked\n");
176 ret = ft1000_control(ft1000dev,
177 usb_rcvctrlpipe(ft1000dev->dev,0),
178 HARLEY_READ_REGISTER, //request --READ_REGISTER
179 HARLEY_READ_OPERATION, //requestType
184 LARGE_TIMEOUT ); //timeout
186 //DEBUG("ft1000_read_register: ret is %d \n", ret);
188 //DEBUG("ft1000_read_register: data is %x \n", *Data);
189 if ( ret != STATUS_SUCCESS )
190 return STATUS_FAILURE;
196 //---------------------------------------------------------------------------
197 // Function: ft1000_write_register
199 // Parameters: ft1000_device - device structure
200 // value - value to write into a register
201 // nRegIndex - register index
203 // Returns: STATUS_SUCCESS - success
204 // STATUS_FAILURE - failure
206 // Description: This function writes the value in a register
210 //---------------------------------------------------------------------------
211 u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRegIndx)
213 u16 ret = STATUS_SUCCESS;
215 //DEBUG("ft1000_write_register: value is: %d, reg index is: %d\n", value, nRegIndx);
217 ret = ft1000_control(ft1000dev,
218 usb_sndctrlpipe(ft1000dev->dev, 0),
219 HARLEY_WRITE_REGISTER, //request -- WRITE_REGISTER
220 HARLEY_WRITE_OPERATION, //requestType
227 if ( ret != STATUS_SUCCESS )
228 return STATUS_FAILURE;
233 //---------------------------------------------------------------------------
234 // Function: ft1000_read_dpram32
236 // Parameters: ft1000_device - device structure
237 // indx - starting address to read
238 // buffer - data buffer to hold the data read
239 // cnt - number of byte read from DPRAM
241 // Returns: STATUS_SUCCESS - success
242 // STATUS_FAILURE - failure
244 // Description: This function read a number of bytes from DPRAM
248 //---------------------------------------------------------------------------
250 u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt)
252 u16 ret = STATUS_SUCCESS;
254 //DEBUG("ft1000_read_dpram32: indx: %d cnt: %d\n", indx, cnt);
255 ret =ft1000_control(ft1000dev,
256 usb_rcvctrlpipe(ft1000dev->dev,0),
257 HARLEY_READ_DPRAM_32, //request --READ_DPRAM_32
258 HARLEY_READ_OPERATION, //requestType
263 LARGE_TIMEOUT ); //timeout
265 //DEBUG("ft1000_read_dpram32: ret is %d \n", ret);
267 //DEBUG("ft1000_read_dpram32: ret=%d \n", ret);
268 if ( ret != STATUS_SUCCESS )
269 return STATUS_FAILURE;
275 //---------------------------------------------------------------------------
276 // Function: ft1000_write_dpram32
278 // Parameters: ft1000_device - device structure
279 // indx - starting address to write the data
280 // buffer - data buffer to write into DPRAM
281 // cnt - number of bytes to write
283 // Returns: STATUS_SUCCESS - success
284 // STATUS_FAILURE - failure
286 // Description: This function writes into DPRAM a number of bytes
290 //---------------------------------------------------------------------------
291 u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt)
293 u16 ret = STATUS_SUCCESS;
295 //DEBUG("ft1000_write_dpram32: indx: %d buffer: %x cnt: %d\n", indx, buffer, cnt);
297 cnt += cnt - (cnt % 4);
299 ret = ft1000_control(ft1000dev,
300 usb_sndctrlpipe(ft1000dev->dev, 0),
301 HARLEY_WRITE_DPRAM_32, //request -- WRITE_DPRAM_32
302 HARLEY_WRITE_OPERATION, //requestType
310 if ( ret != STATUS_SUCCESS )
311 return STATUS_FAILURE;
317 //---------------------------------------------------------------------------
318 // Function: ft1000_read_dpram16
320 // Parameters: ft1000_device - device structure
321 // indx - starting address to read
322 // buffer - data buffer to hold the data read
323 // hightlow - high or low 16 bit word
325 // Returns: STATUS_SUCCESS - success
326 // STATUS_FAILURE - failure
328 // Description: This function read 16 bits from DPRAM
332 //---------------------------------------------------------------------------
333 u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow)
335 u16 ret = STATUS_SUCCESS;
337 //DEBUG("ft1000_read_dpram16: indx: %d hightlow: %d\n", indx, highlow);
342 request = HARLEY_READ_DPRAM_LOW;
344 request = HARLEY_READ_DPRAM_HIGH;
346 ret = ft1000_control(ft1000dev,
347 usb_rcvctrlpipe(ft1000dev->dev,0),
348 request, //request --READ_DPRAM_H/L
349 HARLEY_READ_OPERATION, //requestType
354 LARGE_TIMEOUT ); //timeout
356 //DEBUG("ft1000_read_dpram16: ret is %d \n", ret);
359 //DEBUG("ft1000_read_dpram16: data is %x \n", *buffer);
360 if ( ret != STATUS_SUCCESS )
361 return STATUS_FAILURE;
367 //---------------------------------------------------------------------------
368 // Function: ft1000_write_dpram16
370 // Parameters: ft1000_device - device structure
371 // indx - starting address to write the data
372 // value - 16bits value to write
373 // hightlow - high or low 16 bit word
375 // Returns: STATUS_SUCCESS - success
376 // STATUS_FAILURE - failure
378 // Description: This function writes into DPRAM a number of bytes
382 //---------------------------------------------------------------------------
383 u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT value, u8 highlow)
385 u16 ret = STATUS_SUCCESS;
389 //DEBUG("ft1000_write_dpram16: indx: %d value: %d highlow: %d\n", indx, value, highlow);
395 request = HARLEY_WRITE_DPRAM_LOW;
397 request = HARLEY_WRITE_DPRAM_HIGH;
399 ret = ft1000_control(ft1000dev,
400 usb_sndctrlpipe(ft1000dev->dev, 0),
401 request, //request -- WRITE_DPRAM_H/L
402 HARLEY_WRITE_OPERATION, //requestType
410 if ( ret != STATUS_SUCCESS )
411 return STATUS_FAILURE;
417 //---------------------------------------------------------------------------
418 // Function: fix_ft1000_read_dpram32
420 // Parameters: ft1000_device - device structure
421 // indx - starting address to read
422 // buffer - data buffer to hold the data read
425 // Returns: STATUS_SUCCESS - success
426 // STATUS_FAILURE - failure
428 // Description: This function read DPRAM 4 words at a time
432 //---------------------------------------------------------------------------
433 u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer)
437 u16 ret = STATUS_SUCCESS;
439 //DEBUG("fix_ft1000_read_dpram32: indx: %d \n", indx);
441 ret = ft1000_read_dpram32(ft1000dev, pos, buf, 16);
442 if (ret == STATUS_SUCCESS)
445 *buffer++ = buf[pos++];
446 *buffer++ = buf[pos++];
447 *buffer++ = buf[pos++];
448 *buffer++ = buf[pos++];
452 DEBUG("fix_ft1000_read_dpram32: DPRAM32 Read failed\n");
460 //DEBUG("fix_ft1000_read_dpram32: data is %x \n", *buffer);
466 //---------------------------------------------------------------------------
467 // Function: fix_ft1000_write_dpram32
469 // Parameters: ft1000_device - device structure
470 // indx - starting address to write
471 // buffer - data buffer to write
474 // Returns: STATUS_SUCCESS - success
475 // STATUS_FAILURE - failure
477 // Description: This function write to DPRAM 4 words at a time
481 //---------------------------------------------------------------------------
482 u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer)
488 UCHAR resultbuffer[32];
490 u16 ret = STATUS_SUCCESS;
492 //DEBUG("fix_ft1000_write_dpram32: Entered:\n");
496 ret = ft1000_read_dpram32(ft1000dev, pos1, buf, 16);
497 if (ret == STATUS_SUCCESS)
500 buf[pos2++] = *buffer++;
501 buf[pos2++] = *buffer++;
502 buf[pos2++] = *buffer++;
503 buf[pos2++] = *buffer++;
504 ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16);
508 DEBUG("fix_ft1000_write_dpram32: DPRAM32 Read failed\n");
513 ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16);
514 if (ret == STATUS_SUCCESS)
519 if (buf[i] != resultbuffer[i]){
521 ret = STATUS_FAILURE;
526 if (ret == STATUS_FAILURE)
528 ret = ft1000_write_dpram32(ft1000dev, pos1, (PUCHAR)&tempbuffer[0], 16);
529 ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16);
530 if (ret == STATUS_SUCCESS)
535 if (tempbuffer[i] != resultbuffer[i])
537 ret = STATUS_FAILURE;
538 DEBUG("fix_ft1000_write_dpram32 Failed to write\n");
549 //------------------------------------------------------------------------
551 // Function: card_reset_dsp
553 // Synopsis: This function is called to reset or activate the DSP
555 // Arguments: value - reset or activate
558 //-----------------------------------------------------------------------
559 static void card_reset_dsp (struct ft1000_device *ft1000dev, BOOLEAN value)
561 u16 status = STATUS_SUCCESS;
564 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
565 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_CTRL);
568 DEBUG("Reset DSP\n");
569 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
570 tempword |= DSP_RESET_BIT;
571 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
575 DEBUG("Activate DSP\n");
576 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
578 tempword |= DSP_ENCRYPTED;
579 tempword &= ~DSP_UNENCRYPTED;
581 tempword |= DSP_UNENCRYPTED;
582 tempword &= ~DSP_ENCRYPTED;
584 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
585 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
586 tempword &= ~EFUSE_MEM_DISABLE;
587 tempword &= ~DSP_RESET_BIT;
588 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
589 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
593 //---------------------------------------------------------------------------
594 // Function: CardSendCommand
596 // Parameters: ft1000_device - device structure
597 // ptempbuffer - command buffer
598 // size - command buffer size
600 // Returns: STATUS_SUCCESS - success
601 // STATUS_FAILURE - failure
603 // Description: This function sends a command to ASIC
607 //---------------------------------------------------------------------------
608 void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size)
611 unsigned char *commandbuf;
613 DEBUG("CardSendCommand: enter CardSendCommand... size=%d\n", size);
615 commandbuf =(unsigned char*) kmalloc(size+2, GFP_KERNEL);
616 //memset((void*)commandbuf, 0, size+2);
617 memcpy((void*)commandbuf+2, (void*)ptempbuffer, size);
619 //DEBUG("CardSendCommand: Command Send\n");
621 for (i=0; i<size+2; i++)
623 DEBUG("FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
627 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
634 // check for odd word
638 // Must force to be 32 bit aligned
639 size += 4 - (size % 4);
643 //DEBUG("CardSendCommand: write dpram ... size=%d\n", size);
644 ft1000_write_dpram32(ft1000dev, 0,commandbuf, size);
646 //DEBUG("CardSendCommand: write into doorbell ...\n");
647 ft1000_write_register(ft1000dev, FT1000_DB_DPRAM_TX ,FT1000_REG_DOORBELL) ;
650 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
651 //DEBUG("CardSendCommand: read doorbell ...temp=%x\n", temp);
652 if ( (temp & 0x0100) == 0)
654 //DEBUG("CardSendCommand: Message sent\n");
660 //--------------------------------------------------------------------------
662 // Function: dsp_reload
664 // Synopsis: This function is called to load or reload the DSP
666 // Arguments: ft1000dev - device structure
669 //-----------------------------------------------------------------------
670 int dsp_reload(struct ft1000_device *ft1000dev)
676 PFT1000_INFO pft1000info;
678 pft1000info = netdev_priv(ft1000dev->net);
680 pft1000info->CardReady = 0;
682 // Program Interrupt Mask register
683 status = ft1000_write_register (ft1000dev, 0xffff, FT1000_REG_SUP_IMASK);
685 status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET);
686 tempword |= ASIC_RESET_BIT;
687 status = ft1000_write_register (ft1000dev, tempword, FT1000_REG_RESET);
689 status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET);
690 DEBUG("Reset Register = 0x%x\n", tempword);
693 card_reset_dsp (ft1000dev, 1);
695 card_reset_dsp (ft1000dev, 0);
698 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
700 // Let's check for FEFE
701 status = ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (PUCHAR)&templong, 4);
702 DEBUG("templong (fefe) = 0x%8x\n", templong);
705 status = scram_dnldr(ft1000dev, pFileStart, FileLength);
707 if (status != STATUS_SUCCESS)
712 DEBUG("dsp_reload returned\n");
717 //---------------------------------------------------------------------------
719 // Function: ft1000_reset_asic
720 // Descripton: This function will call the Card Service function to reset the
723 // dev - device structure
727 //---------------------------------------------------------------------------
728 static void ft1000_reset_asic (struct net_device *dev)
730 FT1000_INFO *info = netdev_priv(dev);
731 struct ft1000_device *ft1000dev = info->pFt1000Dev;
734 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
736 info->ASICResetNum++;
738 // Let's use the register provided by the Magnemite ASIC to reset the
740 ft1000_write_register(ft1000dev, (DSP_RESET_BIT | ASIC_RESET_BIT), FT1000_REG_RESET );
744 // set watermark to -1 in order to not generate an interrrupt
745 ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_MAG_WATERMARK);
748 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR);
749 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword);
750 ft1000_write_register (ft1000dev, tempword, FT1000_REG_SUP_ISR);
751 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR);
752 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword);
756 //---------------------------------------------------------------------------
758 // Function: ft1000_disable_interrupts
759 // Descripton: This function will disable all interrupts.
761 // dev - device structure
765 //---------------------------------------------------------------------------
766 static void ft1000_disable_interrupts(struct net_device *dev) {
767 FT1000_INFO *info = netdev_priv(dev);
768 struct ft1000_device *ft1000dev = info->pFt1000Dev;
771 DEBUG("ft1000_hw: ft1000_disable_interrupts()\n");
772 ft1000_write_register (ft1000dev, ISR_MASK_ALL, FT1000_REG_SUP_IMASK);
773 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_IMASK);
774 DEBUG("ft1000_hw:ft1000_disable_interrupts:current interrupt enable mask = 0x%x\n", tempword);
775 info->InterruptsEnabled = FALSE;
778 //---------------------------------------------------------------------------
780 // Function: ft1000_enable_interrupts
781 // Descripton: This function will enable interrupts base on the current interrupt mask.
783 // dev - device structure
787 //---------------------------------------------------------------------------
788 static void ft1000_enable_interrupts(struct net_device *dev) {
789 FT1000_INFO *info = netdev_priv(dev);
790 struct ft1000_device *ft1000dev = info->pFt1000Dev;
793 DEBUG("ft1000_hw:ft1000_enable_interrupts()\n");
794 ft1000_write_register (ft1000dev, info->CurrentInterruptEnableMask, FT1000_REG_SUP_IMASK);
795 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_IMASK);
796 DEBUG("ft1000_hw:ft1000_enable_interrupts:current interrupt enable mask = 0x%x\n", tempword);
797 info->InterruptsEnabled = TRUE;
801 //---------------------------------------------------------------------------
803 // Function: ft1000_reset_card
804 // Descripton: This function will reset the card
806 // dev - device structure
808 // status - FALSE (card reset fail)
809 // TRUE (card reset successful)
811 //---------------------------------------------------------------------------
812 static int ft1000_reset_card (struct net_device *dev)
814 FT1000_INFO *info = netdev_priv(dev);
815 struct ft1000_device *ft1000dev = info->pFt1000Dev;
819 DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
821 info->fCondResetPend = 1;
823 info->fProvComplete = 0;
824 //ft1000_disable_interrupts(dev);
826 // Cancel heartbeat task since we are reloading the dsp
827 //del_timer(&poll_timer[info->CardNumber]);
829 // Make sure we free any memory reserve for provisioning
830 while (list_empty(&info->prov_list) == 0) {
831 DEBUG("ft1000_hw:ft1000_reset_card:deleting provisioning record\n");
832 ptr = list_entry(info->prov_list.next, PROV_RECORD, list);
833 list_del(&ptr->list);
834 kfree(ptr->pprov_data);
838 DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n");
840 ft1000_reset_asic(dev);
845 DEBUG("ft1000_hw:ft1000_reset_card:resetting ASIC and DSP\n");
846 ft1000_write_register (ft1000dev, (DSP_RESET_BIT | ASIC_RESET_BIT), FT1000_REG_RESET );
849 // Copy DSP session record into info block if this is not a coldstart
850 //if (ft1000_card_present == 1) {
851 spin_lock_irqsave(&info->dpram_lock, flags);
853 ft1000_write_register(ft1000dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR);
854 for (i=0;i<MAX_DSP_SESS_REC/2; i++) {
855 //info->DSPSess.MagRec[i] = inl(dev->base_addr+FT1000_REG_MAG_DPDATA);
856 ft1000_read_dpram32(ft1000dev, FT1000_REG_MAG_DPDATA, (PCHAR)&(info->DSPSess.MagRec[i]), 4);
859 spin_unlock_irqrestore(&info->dpram_lock, flags);
861 info->squeseqnum = 0;
863 DEBUG("ft1000_hw:ft1000_reset_card:resetting ASIC\n");
866 ft1000_reset_asic(dev);
870 DEBUG("ft1000_hw:ft1000_reset_card:downloading dsp image\n");
873 // Put dsp in reset and take ASIC out of reset
874 DEBUG("ft1000_hw:ft1000_reset_card:Put DSP in reset and take ASIC out of reset\n");
875 ft1000_write_register (ft1000dev, DSP_RESET_BIT, FT1000_REG_RESET);
877 // Setting MAGNEMITE ASIC to big endian mode
878 ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
880 // Take DSP out of reset
882 ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
883 tempword |= DSP_ENCRYPTED;
884 tempword &= ~DSP_UNENCRYPTED;
885 ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
886 tempword &= ~EFUSE_MEM_DISABLE;
887 ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
888 tempword &= ~DSP_RESET_BIT;
889 ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
892 // FLARION_DSP_ACTIVE;
894 DEBUG("ft1000_hw:ft1000_reset_card:Take DSP out of reset\n");
896 // Wait for 0xfefe indicating dsp ready before starting download
897 for (i=0; i<50; i++) {
898 //tempword = ft1000_read_dpram_mag_16(dev, FT1000_MAG_DPRAM_FEFE, FT1000_MAG_DPRAM_FEFE_INDX);
899 ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (PUCHAR)&templong, 4);
900 if (tempword == 0xfefe) {
907 DEBUG("ft1000_hw:ft1000_reset_card:No FEFE detected from DSP\n");
914 DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n");
915 dsp_reload(ft1000dev);
917 DEBUG("dsp reload successful\n");
922 // Initialize DSP heartbeat area to ho
923 ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag, FT1000_MAG_HI_HO_INDX);
924 ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (PCHAR)&tempword, FT1000_MAG_HI_HO_INDX);
925 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword);
930 //ft1000_enable_interrupts(dev);
931 /* Schedule heartbeat process to run every 2 seconds */
932 //poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
933 //poll_timer[info->CardNumber].data = (u_long)dev;
934 //add_timer(&poll_timer[info->CardNumber]);
936 info->fCondResetPend = 0;
943 #ifdef HAVE_NET_DEVICE_OPS
944 static const struct net_device_ops ftnet_ops =
946 .ndo_open = &ft1000_open,
947 .ndo_stop = &ft1000_close,
948 .ndo_start_xmit = &ft1000_start_xmit,
949 .ndo_get_stats = &ft1000_netdev_stats,
954 //---------------------------------------------------------------------------
955 // Function: init_ft1000_netdev
957 // Parameters: ft1000dev - device structure
960 // Returns: STATUS_SUCCESS - success
961 // STATUS_FAILURE - failure
963 // Description: This function initialize the network device
967 //---------------------------------------------------------------------------
968 u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
970 struct net_device *netdev;
971 FT1000_INFO *pInfo = NULL;
972 PDPRAM_BLK pdpram_blk;
974 struct list_head *cur, *tmp;
977 gCardIndex=0; //mbelian
979 DEBUG("Enter init_ft1000_netdev...\n");
982 netdev = alloc_etherdev( sizeof(FT1000_INFO));
985 DEBUG("init_ft1000_netdev: can not allocate network device\n");
986 return STATUS_FAILURE;
989 //pInfo = (PFT1000_INFO)netdev->priv;
990 pInfo = (FT1000_INFO *) netdev_priv (netdev);
992 //DEBUG("init_ft1000_netdev: gFt1000Info=%x, netdev=%x, ft1000dev=%x\n", gFt1000Info, netdev, ft1000dev);
994 memset (pInfo, 0, sizeof(FT1000_INFO));
996 dev_alloc_name(netdev, netdev->name);
998 //for the first inserted card, decide the card index beginning number, in case there are existing network interfaces
999 if ( gCardIndex == 0 )
1001 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name);
1003 if ( strncmp(netdev->name,"eth", 3) == 0) {
1004 card_nr[0] = netdev->name[3];
1006 ret_val = strict_strtoul(card_nr, 10, &gCardIndex);
1008 printk(KERN_ERR "Can't parse netdev\n");
1009 free_netdev(netdev);
1010 return STATUS_FAILURE;
1013 pInfo->CardNumber = gCardIndex;
1014 DEBUG("card number = %d\n", pInfo->CardNumber);
1017 printk(KERN_ERR "ft1000: Invalid device name\n");
1018 free_netdev(netdev);
1019 return STATUS_FAILURE;
1024 //not the first inserted card, increase card number by 1
1026 pInfo->CardNumber = gCardIndex;
1027 /*DEBUG("card number = %d\n", pInfo->CardNumber);*/ //mbelian
1030 memset(&pInfo->stats, 0, sizeof(struct net_device_stats) );
1032 spin_lock_init(&pInfo->dpram_lock);
1033 pInfo->pFt1000Dev = ft1000dev;
1034 pInfo->DrvErrNum = 0;
1035 pInfo->ASICResetNum = 0;
1036 pInfo->registered = 1;
1037 pInfo->ft1000_reset = ft1000_reset;
1038 pInfo->mediastate = 0;
1039 pInfo->fifo_cnt = 0;
1040 pInfo->DeviceCreated = FALSE;
1041 pInfo->DeviceMajor = 0;
1042 pInfo->CurrentInterruptEnableMask = ISR_DEFAULT_MASK;
1043 pInfo->InterruptsEnabled = FALSE;
1044 pInfo->CardReady = 0;
1045 pInfo->DSP_TIME[0] = 0;
1046 pInfo->DSP_TIME[1] = 0;
1047 pInfo->DSP_TIME[2] = 0;
1048 pInfo->DSP_TIME[3] = 0;
1049 pInfo->fAppMsgPend = 0;
1050 pInfo->fCondResetPend = 0;
1052 pInfo->dspalive = 0;
1053 for (i=0;i<32 ;i++ )
1055 pInfo->tempbuf[i] = 0;
1058 INIT_LIST_HEAD(&pInfo->prov_list);
1061 #ifdef HAVE_NET_DEVICE_OPS
1062 netdev->netdev_ops = &ftnet_ops;
1064 netdev->hard_start_xmit = &ft1000_start_xmit;
1065 netdev->get_stats = &ft1000_netdev_stats;
1066 netdev->open = &ft1000_open;
1067 netdev->stop = &ft1000_close;
1070 //netif_stop_queue(netdev); //mbelian
1073 ft1000dev->net = netdev;
1077 //init free_buff_lock, freercvpool, numofmsgbuf, pdpram_blk
1078 //only init once per card
1080 DEBUG("Initialize free_buff_lock and freercvpool\n");
1081 spin_lock_init(&free_buff_lock);
1083 // initialize a list of buffers to be use for queuing up receive command data
1084 INIT_LIST_HEAD (&freercvpool);
1086 // create list of free buffers
1087 for (i=0; i<NUM_OF_FREE_BUFFERS; i++) {
1088 // Get memory for DPRAM_DATA link list
1089 pdpram_blk = kmalloc ( sizeof(DPRAM_BLK), GFP_KERNEL );
1090 if (pdpram_blk == NULL)
1092 // Get a block of memory to store command data
1093 pdpram_blk->pbuffer = kmalloc ( MAX_CMD_SQSIZE, GFP_KERNEL );
1094 if (pdpram_blk->pbuffer == NULL) {
1098 // link provisioning data
1099 list_add_tail (&pdpram_blk->list, &freercvpool);
1101 numofmsgbuf = NUM_OF_FREE_BUFFERS;
1104 return STATUS_SUCCESS;
1108 list_for_each_safe(cur, tmp, &pdpram_blk->list) {
1109 pdpram_blk = list_entry(cur, DPRAM_BLK, list);
1110 list_del(&pdpram_blk->list);
1111 kfree(pdpram_blk->pbuffer);
1114 return STATUS_FAILURE;
1119 //---------------------------------------------------------------------------
1120 // Function: reg_ft1000_netdev
1122 // Parameters: ft1000dev - device structure
1125 // Returns: STATUS_SUCCESS - success
1126 // STATUS_FAILURE - failure
1128 // Description: This function register the network driver
1132 //---------------------------------------------------------------------------
1133 u16 reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf)
1135 struct net_device *netdev;
1139 netdev = ft1000dev->net;
1140 pInfo = netdev_priv(ft1000dev->net);
1141 DEBUG("Enter reg_ft1000_netdev...\n");
1144 ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID);
1146 usb_set_intfdata(intf, pInfo);
1147 SET_NETDEV_DEV(netdev, &intf->dev);
1149 rc = register_netdev(netdev);
1152 DEBUG("reg_ft1000_netdev: could not register network device\n");
1153 free_netdev(netdev);
1154 return STATUS_FAILURE;
1158 //Create character device, implemented by Jim
1159 ft1000_CreateDevice(ft1000dev);
1161 //INIT_LIST_HEAD(&pInfo->prov_list);
1163 for (i=0; i<MAX_NUM_CARDS; i++) {
1164 poll_timer[i].function = ft1000_hbchk;
1168 //hard code MAC address for now
1170 netdev->dev_addr[0] = 0;
1171 netdev->dev_addr[1] = 7;
1172 netdev->dev_addr[2] = 0x35;
1173 netdev->dev_addr[3] = 0x84;
1174 netdev->dev_addr[4] = 0;
1175 netdev->dev_addr[5] = 0x20 + pInfo->CardNumber;
1178 DEBUG ("reg_ft1000_netdev returned\n");
1180 pInfo->CardReady = 1;
1183 return STATUS_SUCCESS;
1186 static int ft1000_reset(struct net_device *dev)
1188 ft1000_reset_card(dev);
1192 //---------------------------------------------------------------------------
1193 // Function: ft1000_usb_transmit_complete
1195 // Parameters: urb - transmitted usb urb
1200 // Description: This is the callback function when a urb is transmitted
1204 //---------------------------------------------------------------------------
1205 static void ft1000_usb_transmit_complete(struct urb *urb)
1208 struct ft1000_device *ft1000dev = urb->context;
1210 //DEBUG("ft1000_usb_transmit_complete entered\n");
1211 // Jim spin_lock(&ft1000dev->device_lock);
1214 printk("%s: TX status %d\n", ft1000dev->net->name, urb->status);
1216 netif_wake_queue(ft1000dev->net);
1218 //Jim spin_unlock(&ft1000dev->device_lock);
1219 //DEBUG("Return from ft1000_usb_transmit_complete\n");
1223 /****************************************************************
1225 ****************************************************************/
1226 static int ft1000_read_fifo_reg(struct ft1000_device *ft1000dev,unsigned int pipe,
1237 DECLARE_WAITQUEUE(wait, current);
1239 struct usb_ctrlrequest *dr;
1242 if (ft1000dev == NULL )
1244 DEBUG("NULL ft1000dev, failure\n");
1245 return STATUS_FAILURE;
1247 else if ( ft1000dev->dev == NULL )
1249 DEBUG("NULL ft1000dev->dev, failure\n");
1250 return STATUS_FAILURE;
1253 spin_lock(&ft1000dev->device_lock);
1255 /*DECLARE_WAITQUEUE(wait, current);
1257 struct usb_ctrlrequest *dr;
1262 spin_unlock(&ft1000dev->device_lock);
1266 urb = usb_alloc_urb(0, GFP_KERNEL);
1267 dr = kmalloc(sizeof(struct usb_ctrlrequest), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
1273 spin_unlock(&ft1000dev->device_lock);
1279 dr->bRequestType = requesttype;
1280 dr->bRequest = request;
1285 usb_fill_control_urb(urb, ft1000dev->dev, pipe, (char*)dr, (void*)data, size, (void *)ft1000_control_complete, (void*)ft1000dev);
1288 init_waitqueue_head(&ft1000dev->control_wait);
1290 //current->state = TASK_INTERRUPTIBLE; //mbelian
1291 set_current_state(TASK_INTERRUPTIBLE);
1293 add_wait_queue(&ft1000dev->control_wait, &wait);
1298 status = usb_submit_urb(urb, GFP_KERNEL);
1304 remove_wait_queue(&ft1000dev->control_wait, &wait);
1305 spin_unlock(&ft1000dev->device_lock);
1309 if(urb->status == -EINPROGRESS)
1311 while(timeout && urb->status == -EINPROGRESS)
1313 status = timeout = schedule_timeout(timeout);
1321 remove_wait_queue(&ft1000dev->control_wait, &wait);
1325 usb_unlink_urb(urb);
1326 printk("ft1000 timeout\n");
1327 status = -ETIMEDOUT;
1331 status = urb->status;
1335 printk("ft1000 control message failed (urb addr: %p) with error number: %i\n", urb, (int)status);
1337 usb_clear_halt(ft1000dev->dev, usb_rcvctrlpipe(ft1000dev->dev, 0));
1338 usb_clear_halt(ft1000dev->dev, usb_sndctrlpipe(ft1000dev->dev, 0));
1339 usb_unlink_urb(urb);
1347 spin_unlock(&ft1000dev->device_lock);
1353 //---------------------------------------------------------------------------
1354 // Function: ft1000_read_fifo_len
1356 // Parameters: ft1000dev - device structure
1361 // Description: read the fifo length register content
1365 //---------------------------------------------------------------------------
1366 static inline u16 ft1000_read_fifo_len (struct net_device *dev)
1371 //FT1000_INFO *info = (PFT1000_INFO)dev->priv;
1372 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev);
1373 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1374 // 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 *???
1375 DEBUG("ft1000_read_fifo_len: enter ft1000dev %p\n", ft1000dev); //aelias [+] reason: up
1376 //ft1000_read_register(ft1000dev, &temp, FT1000_REG_MAG_UFSR);
1378 ret = STATUS_SUCCESS;
1380 ret = ft1000_read_fifo_reg(ft1000dev,
1381 usb_rcvctrlpipe(ft1000dev->dev,0),
1382 HARLEY_READ_REGISTER,
1383 HARLEY_READ_OPERATION,
1385 FT1000_REG_MAG_UFSR,
1391 ret = STATUS_SUCCESS;
1393 ret = STATUS_FAILURE;
1395 DEBUG("ft1000_read_fifo_len: returned %d\n", temp);
1402 //---------------------------------------------------------------------------
1404 // Function: ft1000_copy_down_pkt
1405 // Descripton: This function will take an ethernet packet and convert it to
1406 // a Flarion packet prior to sending it to the ASIC Downlink
1409 // dev - device structure
1410 // packet - address of ethernet packet
1411 // len - length of IP packet
1416 //---------------------------------------------------------------------------
1417 static int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len)
1419 FT1000_INFO *pInfo = netdev_priv(netdev);
1420 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
1428 if (!pInfo->CardReady)
1431 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
1432 return STATUS_FAILURE;
1437 //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len);
1440 // Check if there is room on the FIFO
1441 if ( len > ft1000_read_fifo_len (netdev) )
1444 if ( len > ft1000_read_fifo_len (netdev) )
1449 if ( len > ft1000_read_fifo_len (netdev) )
1454 if ( len > ft1000_read_fifo_len (netdev) )
1459 if ( len > ft1000_read_fifo_len (netdev) )
1464 if ( len > ft1000_read_fifo_len (netdev) )
1469 if ( len > ft1000_read_fifo_len (netdev) )
1471 DEBUG("ft1000_hw:ft1000_copy_down_pkt:Transmit FIFO is fulli - pkt drop\n");
1472 pInfo->stats.tx_errors++;
1473 return STATUS_SUCCESS;
1478 count = sizeof (PSEUDO_HDR) + len;
1479 if(count > MAX_BUF_SIZE)
1481 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n");
1482 DEBUG("size = %d\n", count);
1483 return STATUS_FAILURE;
1487 count = count + (4- (count %4) );
1489 pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]);
1490 *pTemp ++ = ntohs(count);
1497 pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]);
1498 checksum = *pTemp ++;
1501 checksum ^= *pTemp ++;
1503 *pTemp++ = checksum;
1504 memcpy (&(pFt1000Dev->tx_buf[sizeof(PSEUDO_HDR)]), packet, len);
1506 //usb_init_urb(pFt1000Dev->tx_urb); //mbelian
1508 netif_stop_queue(netdev);
1510 //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count);
1512 usb_fill_bulk_urb(pFt1000Dev->tx_urb,
1514 usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr),
1517 ft1000_usb_transmit_complete,
1520 t = (u8 *)pFt1000Dev->tx_urb->transfer_buffer;
1521 //DEBUG("transfer_length=%d\n", pFt1000Dev->tx_urb->transfer_buffer_length);
1522 /*for (i=0; i<count; i++ )
1524 DEBUG("%x ", *t++ );
1528 ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC);
1531 DEBUG("ft1000 failed tx_urb %d\n", ret);
1533 /* pInfo->stats.tx_errors++;
1535 netif_start_queue(netdev); */ //mbelian
1536 return STATUS_FAILURE;
1541 //DEBUG("ft1000 sucess tx_urb %d\n", ret);
1543 pInfo->stats.tx_packets++;
1544 pInfo->stats.tx_bytes += (len+14);
1547 //DEBUG("ft1000_copy_down_pkt() exit\n");
1549 return STATUS_SUCCESS;
1552 //---------------------------------------------------------------------------
1553 // Function: ft1000_start_xmit
1555 // Parameters: skb - socket buffer to be sent
1556 // dev - network device
1561 // Description: transmit a ethernet packet
1565 //---------------------------------------------------------------------------
1566 static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1568 FT1000_INFO *pInfo = netdev_priv(dev);
1569 struct ft1000_device *pFt1000Dev= pInfo->pFt1000Dev;
1574 //DEBUG(" ft1000_start_xmit() entered\n");
1578 DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" );
1579 return STATUS_FAILURE;
1582 if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1584 DEBUG("network driver is closed, return\n");
1586 //usb_kill_urb(pFt1000Dev->tx_urb); //mbelian
1587 return STATUS_SUCCESS;
1590 //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len);
1591 pipe = usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr);
1592 maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe));
1593 //DEBUG("ft1000_start_xmit 2: pipe=%d dev->maxpacket = %d\n", pipe, maxlen);
1595 pdata = (u8 *)skb->data;
1596 /*for (i=0; i<skb->len; i++)
1597 DEBUG("skb->data[%d]=%x ", i, *(skb->data+i));
1602 if (pInfo->mediastate == 0)
1604 /* Drop packet is mediastate is down */
1605 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n");
1607 return STATUS_SUCCESS;
1610 if ( (skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE) )
1612 /* Drop packet which has invalid size */
1613 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n");
1615 return STATUS_SUCCESS;
1618 if(ft1000_copy_down_pkt (dev, (pdata+ENET_HEADER_SIZE-2), skb->len - ENET_HEADER_SIZE + 2) == STATUS_FAILURE)
1621 return STATUS_SUCCESS;
1625 //DEBUG(" ft1000_start_xmit() exit\n");
1630 //---------------------------------------------------------------------------
1632 // Function: ft1000_copy_up_pkt
1633 // Descripton: This function will take a packet from the FIFO up link and
1634 // convert it into an ethernet packet and deliver it to the IP stack
1636 // urb - the receving usb urb
1642 //---------------------------------------------------------------------------
1643 static int ft1000_copy_up_pkt (struct urb *urb)
1645 PFT1000_INFO info = urb->context;
1646 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1647 struct net_device *net = ft1000dev->net;
1652 struct sk_buff *skb;
1659 //DEBUG("ft1000_copy_up_pkt entered\n");
1661 if ( ft1000dev->status & FT1000_STATUS_CLOSING)
1663 DEBUG("network driver is closed, return\n");
1664 return STATUS_SUCCESS;
1668 len = urb->transfer_buffer_length;
1669 lena = urb->actual_length; //mbelian
1670 //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n",
1671 // urb->transfer_buffer_length, urb->actual_length);
1673 chksum = (PUSHORT)ft1000dev->rx_buf;
1675 tempword = *chksum++;
1678 tempword ^= *chksum++;
1681 if (tempword != *chksum)
1683 info->stats.rx_errors ++;
1684 ft1000_submit_rx_urb(info);
1685 return STATUS_FAILURE;
1689 //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum);
1691 skb = dev_alloc_skb(len+12+2);
1695 DEBUG("ft1000_copy_up_pkt: No Network buffers available\n");
1696 info->stats.rx_errors++;
1697 ft1000_submit_rx_urb(info);
1698 return STATUS_FAILURE;
1701 pbuffer = (u8 *)skb_put(skb, len+12);
1703 //subtract the number of bytes read already
1707 *pbuffer++ = net->dev_addr[0];
1708 *pbuffer++ = net->dev_addr[1];
1709 *pbuffer++ = net->dev_addr[2];
1710 *pbuffer++ = net->dev_addr[3];
1711 *pbuffer++ = net->dev_addr[4];
1712 *pbuffer++ = net->dev_addr[5];
1723 memcpy(pbuffer, ft1000dev->rx_buf+sizeof(PSEUDO_HDR), len-sizeof(PSEUDO_HDR));
1725 //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n");
1726 /*for (i=0; i<len+12; i++)
1728 DEBUG("ft1000_copy_up_pkt: Protocol Data: 0x%x\n ", *ptemp++);
1733 skb->protocol = eth_type_trans(skb, net);
1734 skb->ip_summed = CHECKSUM_UNNECESSARY;
1737 info->stats.rx_packets++;
1738 // Add on 12 bytes for MAC address which was removed
1739 info->stats.rx_bytes += (lena+12); //mbelian
1741 ft1000_submit_rx_urb(info);
1742 //DEBUG("ft1000_copy_up_pkt exited\n");
1746 //---------------------------------------------------------------------------
1748 // Function: ft1000_submit_rx_urb
1749 // Descripton: the receiving function of the network driver
1752 // info - a private structure contains the device information
1758 //---------------------------------------------------------------------------
1759 static int ft1000_submit_rx_urb(PFT1000_INFO info)
1762 struct ft1000_device *pFt1000Dev = info->pFt1000Dev;
1764 //netif_carrier_on(pFt1000Dev->net);
1766 //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb));
1767 if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1769 DEBUG("network driver is closed, return\n");
1770 //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian
1771 return STATUS_SUCCESS;
1773 //memset(pFt1000Dev->rx_urb, 0, sizeof(*pFt1000Dev->rx_urb));
1774 //usb_init_urb(pFt1000Dev->rx_urb);//mbelian
1776 //spin_lock_init(&pFt1000Dev->rx_urb->lock);
1778 usb_fill_bulk_urb(pFt1000Dev->rx_urb,
1780 usb_rcvbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_in_endpointAddr),
1783 (usb_complete_t)ft1000_copy_up_pkt,
1787 if((result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC)))
1789 printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result);
1790 return STATUS_FAILURE;
1793 //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result);
1795 return STATUS_SUCCESS;
1798 //---------------------------------------------------------------------------
1799 // Function: ft1000_open
1802 // dev - network device
1807 // Description: open the network driver
1811 //---------------------------------------------------------------------------
1812 static int ft1000_open (struct net_device *dev)
1814 FT1000_INFO *pInfo = (FT1000_INFO *)netdev_priv(dev);
1815 struct timeval tv; //mbelian
1817 DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber);
1818 //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len);
1820 pInfo->stats.rx_bytes = 0; //mbelian
1821 pInfo->stats.tx_bytes = 0; //mbelian
1822 pInfo->stats.rx_packets = 0; //mbelian
1823 pInfo->stats.tx_packets = 0; //mbelian
1824 do_gettimeofday(&tv);
1825 pInfo->ConTm = tv.tv_sec;
1826 pInfo->ProgConStat = 0; //mbelian
1829 netif_start_queue(dev);
1831 //netif_device_attach(dev);
1833 netif_carrier_on(dev); //mbelian
1835 ft1000_submit_rx_urb(pInfo);
1839 //---------------------------------------------------------------------------
1840 // Function: ft1000_close
1843 // net - network device
1848 // Description: close the network driver
1852 //---------------------------------------------------------------------------
1853 int ft1000_close(struct net_device *net)
1855 FT1000_INFO *pInfo = (FT1000_INFO *) netdev_priv (net);
1856 struct ft1000_device *ft1000dev = pInfo->pFt1000Dev;
1858 //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt);
1860 ft1000dev->status |= FT1000_STATUS_CLOSING;
1862 //DEBUG("ft1000_close: calling usb_kill_urb \n");
1863 //usb_kill_urb(ft1000dev->rx_urb);
1864 //usb_kill_urb(ft1000dev->tx_urb);
1867 DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);
1868 netif_carrier_off(net);//mbelian
1869 netif_stop_queue(net);
1870 //DEBUG("ft1000_close: netif_stop_queue called\n");
1871 ft1000dev->status &= ~FT1000_STATUS_CLOSING;
1873 pInfo->ProgConStat = 0xff; //mbelian
1879 static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev)
1881 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev);
1882 //struct ft1000_device *ft1000dev = info->pFt1000Dev;
1884 //return &(ft1000dev->stats);//mbelian
1885 return &(info->stats); //mbelian
1889 /*********************************************************************************
1894 //---------------------------------------------------------------------------
1896 // Function: ft1000_chkcard
1897 // Descripton: This function will check if the device is presently available on
1900 // dev - device structure
1902 // status - FALSE (device is not present)
1903 // TRUE (device is present)
1905 //---------------------------------------------------------------------------
1906 static int ft1000_chkcard (struct ft1000_device *dev) {
1909 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
1911 if (info->fCondResetPend)
1913 DEBUG("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1917 // Mask register is used to check for device presence since it is never
1919 status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK);
1920 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword);
1921 if (tempword == 0) {
1922 DEBUG("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
1926 // The system will return the value of 0xffff for the version register
1927 // if the device is not present.
1928 status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID);
1929 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword);
1930 //pxu if (tempword == 0xffff) {
1931 if (tempword != 0x1b01 ){
1932 dev->status |= FT1000_STATUS_CLOSING; //mbelian
1933 DEBUG("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
1939 //---------------------------------------------------------------------------
1941 // Function: ft1000_hbchk
1942 // Descripton: This function will perform the heart beat check of the DSP as
1943 // well as the ASIC.
1945 // dev - device structure
1949 //---------------------------------------------------------------------------
1950 static void ft1000_hbchk(u_long data)
1952 struct ft1000_device *dev = (struct ft1000_device *)data;
1957 info = (FT1000_INFO *) netdev_priv (dev->net);
1959 DEBUG("ft1000_hbchk called for CardNumber = %d CardReady = %d\n", info->CardNumber, info->CardReady);
1961 if (info->fCondResetPend == 1) {
1962 // Reset ASIC and DSP
1963 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
1964 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
1965 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
1966 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
1968 info->DrvErrNum = DSP_CONDRESET_INFO;
1969 DEBUG("ft1000_hw:DSP conditional reset requested\n");
1970 ft1000_reset_card(dev->net);
1971 info->fCondResetPend = 0;
1972 /* Schedule this module to run every 2 seconds */
1974 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
1975 poll_timer[info->CardNumber].data = (u_long)dev;
1976 add_timer(&poll_timer[info->CardNumber]);
1983 if (info->CardReady == 1) {
1984 // Perform dsp heartbeat check
1985 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX));
1986 DEBUG("ft1000_hw:ft1000_hbchk:hi_ho value = 0x%x\n", tempword);
1987 // Let's perform another check if ho is not detected
1988 if (tempword != ho) {
1989 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword,FT1000_MAG_HI_HO_INDX));
1991 if (tempword != ho) {
1992 printk(KERN_INFO "ft1000: heartbeat failed - no ho detected\n");
1993 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
1994 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
1995 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
1996 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
1997 info->DrvErrNum = DSP_HB_INFO;
1998 if (ft1000_reset_card(dev->net) == 0) {
1999 printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n");
2000 info->ProgConStat = 0xff;
2003 /* Schedule this module to run every 2 seconds */
2004 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2005 poll_timer[info->CardNumber].data = (u_long)dev;
2006 add_timer(&poll_timer[info->CardNumber]);
2010 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2011 // Let's check doorbell again if fail
2012 if (tempword & FT1000_DB_HB) {
2013 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2015 if (tempword & FT1000_DB_HB) {
2016 printk(KERN_INFO "ft1000: heartbeat doorbell not clear by firmware\n");
2017 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2018 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2019 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2020 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2021 info->DrvErrNum = DSP_HB_INFO;
2022 if (ft1000_reset_card(dev->net) == 0) {
2023 printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n");
2024 info->ProgConStat = 0xff;
2027 /* Schedule this module to run every 2 seconds */
2028 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2029 poll_timer[info->CardNumber].data = (u_long)dev;
2030 add_timer(&poll_timer[info->CardNumber]);
2034 // Set dedicated area to hi and ring appropriate doorbell according
2035 // to hi/ho heartbeat protocol
2036 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));
2039 // Let's write hi again if fail
2040 if (tempword != hi) {
2041 ft1000_write_dpram16(dev, FT1000_MAG_HI_HO, hi_mag, FT1000_MAG_HI_HO_INDX);
2042 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX));
2045 if (tempword != hi) {
2046 printk(KERN_INFO "ft1000: heartbeat failed - cannot write hi into DPRAM\n");
2047 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2048 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2049 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2050 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2052 info->DrvErrNum = DSP_HB_INFO;
2053 if (ft1000_reset_card(dev->net) == 0) {
2054 printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n");
2055 info->ProgConStat = 0xff;
2058 /* Schedule this module to run every 2 seconds */
2059 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2060 poll_timer[info->CardNumber].data = (u_long)dev;
2061 add_timer(&poll_timer[info->CardNumber]);
2064 ft1000_write_register(dev, FT1000_DB_HB, FT1000_REG_DOORBELL);
2068 /* Schedule this module to run every 2 seconds */
2069 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2070 poll_timer[info->CardNumber].data = (u_long)dev;
2071 add_timer(&poll_timer[info->CardNumber]);
2074 //---------------------------------------------------------------------------
2076 // Function: ft1000_receive_cmd
2077 // Descripton: This function will read a message from the dpram area.
2079 // dev - network device structure
2080 // pbuffer - caller supply address to buffer
2081 // pnxtph - pointer to next pseudo header
2083 // Status = 0 (unsuccessful)
2086 //---------------------------------------------------------------------------
2087 static BOOLEAN ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) {
2093 ret = ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (PUCHAR)&size, FT1000_MAG_PH_LEN_INDX);
2094 size = ntohs(size) + PSEUDOSZ;
2096 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size);
2100 ppseudohdr = (u16 *)pbuffer;
2101 //spin_lock_irqsave (&info->dpram_lock, flags);
2102 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR);
2103 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
2104 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2106 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE+1, FT1000_REG_DPRAM_ADDR);
2107 for (i=0; i<=(size>>2); i++) {
2108 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
2110 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
2113 //copy odd aligned word
2114 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
2115 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2117 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
2118 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2120 if (size & 0x0001) {
2121 //copy odd byte from fifo
2122 ret = ft1000_read_register(dev, &tempword, FT1000_REG_DPRAM_DATA);
2123 *pbuffer = ntohs(tempword);
2125 //spin_unlock_irqrestore(&info->dpram_lock, flags);
2127 // Check if pseudo header checksum is good
2128 // Calculate pseudo header checksum
2129 tempword = *ppseudohdr++;
2130 for (i=1; i<7; i++) {
2131 tempword ^= *ppseudohdr++;
2133 if ( (tempword != *ppseudohdr) ) {
2139 DEBUG("ft1000_receive_cmd:pbuffer\n");
2140 for(i = 0; i < size; i+=5)
2142 if( (i + 5) < size )
2143 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]);
2146 for (j = i; j < size; j++)
2147 DEBUG("0x%x ", tempbuffer[j]);
2160 static int ft1000_dsp_prov(void *arg)
2162 struct ft1000_device *dev = (struct ft1000_device *)arg;
2163 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
2168 PPSEUDO_HDR ppseudo_hdr;
2171 USHORT TempShortBuf [256];
2173 DEBUG("*** DspProv Entered\n");
2175 while ( list_empty(&info->prov_list) == 0
2176 /*&& !kthread_should_stop() */)
2178 DEBUG("DSP Provisioning List Entry\n");
2180 // Check if doorbell is available
2181 DEBUG("check if doorbell is cleared\n");
2182 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
2185 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n");
2189 while (tempword & FT1000_DB_DPRAM_TX) {
2193 DEBUG("FT1000:ft1000_dsp_prov:message drop\n");
2194 return STATUS_FAILURE;
2196 ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2199 if ( !(tempword & FT1000_DB_DPRAM_TX) ) {
2200 DEBUG("*** Provision Data Sent to DSP\n");
2202 // Send provisioning data
2203 ptr = list_entry(info->prov_list.next, PROV_RECORD, list);
2204 len = *(u16 *)ptr->pprov_data;
2209 pmsg = (PUSHORT)ptr->pprov_data;
2210 ppseudo_hdr = (PPSEUDO_HDR)pmsg;
2211 // Insert slow queue sequence number
2212 ppseudo_hdr->seq_num = info->squeseqnum++;
2213 ppseudo_hdr->portsrc = 0;
2214 // Calculate new checksum
2215 ppseudo_hdr->checksum = *pmsg++;
2216 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
2217 for (i=1; i<7; i++) {
2218 ppseudo_hdr->checksum ^= *pmsg++;
2219 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
2222 TempShortBuf[0] = 0;
2223 TempShortBuf[1] = htons (len);
2224 memcpy(&TempShortBuf[2], ppseudo_hdr, len);
2226 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&TempShortBuf[0], (unsigned short)(len+2));
2227 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
2229 list_del(&ptr->list);
2230 kfree(ptr->pprov_data);
2236 DEBUG("DSP Provisioning List Entry finished\n");
2240 info->fProvComplete = 1;
2241 info->CardReady = 1;
2242 return STATUS_SUCCESS;
2247 static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
2248 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
2251 PMEDIAMSG pmediamsg;
2252 PDSPINITMSG pdspinitmsg;
2255 PPSEUDO_HDR ppseudo_hdr;
2258 //struct timeval tv; //mbelian
2265 char *cmdbuffer = kmalloc(1600, GFP_KERNEL);
2267 return STATUS_FAILURE;
2269 status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size);
2272 //if (ft1000_receive_cmd(dev, &cmdbuffer[0], MAX_CMD_SQSIZE, &tempword))
2276 DEBUG("ft1000_proc_drvmsg:cmdbuffer\n");
2277 for(i = 0; i < size; i+=5)
2279 if( (i + 5) < size )
2280 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]);
2283 for (j = i; j < size; j++)
2284 DEBUG("0x%x ", cmdbuffer[j]);
2290 pdrvmsg = (PDRVMSG)&cmdbuffer[2];
2291 msgtype = ntohs(pdrvmsg->type);
2292 DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype);
2295 DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE");
2297 pmediamsg = (PMEDIAMSG)&cmdbuffer[0];
2298 if (info->ProgConStat != 0xFF) {
2299 if (pmediamsg->state) {
2300 DEBUG("Media is up\n");
2301 if (info->mediastate == 0) {
2302 if ( info->NetDevRegDone )
2304 //netif_carrier_on(dev->net);//mbelian
2305 netif_wake_queue(dev->net);
2307 info->mediastate = 1;
2308 /*do_gettimeofday(&tv);
2309 info->ConTm = tv.tv_sec;*/ //mbelian
2313 DEBUG("Media is down\n");
2314 if (info->mediastate == 1) {
2315 info->mediastate = 0;
2316 if ( info->NetDevRegDone )
2318 //netif_carrier_off(dev->net); mbelian
2319 //netif_stop_queue(dev->net);
2326 DEBUG("Media is down\n");
2327 if (info->mediastate == 1) {
2328 info->mediastate = 0;
2329 if ( info->NetDevRegDone)
2331 //netif_carrier_off(dev->net); //mbelian
2332 //netif_stop_queue(dev->net);
2339 case DSP_INIT_MSG: {
2340 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG");
2342 pdspinitmsg = (PDSPINITMSG)&cmdbuffer[2];
2343 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
2344 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", info->DspVer[0], info->DspVer[1], info->DspVer[2], info->DspVer[3]);
2345 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum, HWSERNUMSZ);
2346 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
2347 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
2348 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]);
2349 dev->net->dev_addr[0] = info->eui64[0];
2350 dev->net->dev_addr[1] = info->eui64[1];
2351 dev->net->dev_addr[2] = info->eui64[2];
2352 dev->net->dev_addr[3] = info->eui64[5];
2353 dev->net->dev_addr[4] = info->eui64[6];
2354 dev->net->dev_addr[5] = info->eui64[7];
2356 if (ntohs(pdspinitmsg->length) == (sizeof(DSPINITMSG) - 20) ) {
2357 memcpy(info->ProductMode, pdspinitmsg->ProductMode, MODESZ);
2358 memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, CALVERSZ);
2359 memcpy(info->RfCalDate, pdspinitmsg->RfCalDate, CALDATESZ);
2360 DEBUG("RFCalVer = 0x%2x 0x%2x\n", info->RfCalVer[0], info->RfCalVer[1]);
2364 case DSP_PROVISION: {
2365 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n");
2367 // kick off dspprov routine to start provisioning
2368 // Send provisioning data to DSP
2369 if (list_empty(&info->prov_list) == 0)
2371 info->fProvComplete = 0;
2372 status = ft1000_dsp_prov(dev);
2373 if (status != STATUS_SUCCESS)
2377 info->fProvComplete = 1;
2378 status = ft1000_write_register (dev, FT1000_DB_HB, FT1000_REG_DOORBELL);
2379 DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n");
2381 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n");
2384 case DSP_STORE_INFO: {
2385 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO");
2387 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
2388 tempword = ntohs(pdrvmsg->length);
2389 info->DSPInfoBlklen = tempword;
2390 if (tempword < (MAX_DSP_SESS_REC-4) ) {
2391 pmsg = (PUSHORT)&pdrvmsg->data[0];
2392 for (i=0; i<((tempword+1)/2); i++) {
2393 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg);
2394 info->DSPInfoBlk[i+10] = *pmsg++;
2398 info->DSPInfoBlklen = 0;
2402 case DSP_GET_INFO: {
2403 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
2404 // copy dsp info block to dsp
2405 info->DrvMsgPend = 1;
2406 // allow any outstanding ioctl to finish
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) {
2414 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2415 if (tempword & FT1000_DB_DPRAM_TX) {
2421 // Put message into Slow Queue
2422 // Form Pseudo header
2423 pmsg = (PUSHORT)info->DSPInfoBlk;
2425 *pmsg++ = htons(info->DSPInfoBlklen+20+info->DSPInfoBlklen);
2426 ppseudo_hdr = (PPSEUDO_HDR)(PUSHORT)&info->DSPInfoBlk[2];
2427 ppseudo_hdr->length = htons(info->DSPInfoBlklen+4+info->DSPInfoBlklen);
2428 ppseudo_hdr->source = 0x10;
2429 ppseudo_hdr->destination = 0x20;
2430 ppseudo_hdr->portdest = 0;
2431 ppseudo_hdr->portsrc = 0;
2432 ppseudo_hdr->sh_str_id = 0;
2433 ppseudo_hdr->control = 0;
2434 ppseudo_hdr->rsvd1 = 0;
2435 ppseudo_hdr->rsvd2 = 0;
2436 ppseudo_hdr->qos_class = 0;
2437 // Insert slow queue sequence number
2438 ppseudo_hdr->seq_num = info->squeseqnum++;
2439 // Insert application id
2440 ppseudo_hdr->portsrc = 0;
2441 // Calculate new checksum
2442 ppseudo_hdr->checksum = *pmsg++;
2443 for (i=1; i<7; i++) {
2444 ppseudo_hdr->checksum ^= *pmsg++;
2446 info->DSPInfoBlk[10] = 0x7200;
2447 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen);
2448 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPInfoBlk[0], (unsigned short)(info->DSPInfoBlklen+22));
2449 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
2450 info->DrvMsgPend = 0;
2455 case GET_DRV_ERR_RPT_MSG: {
2456 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
2457 // copy driver error message to dsp
2458 info->DrvMsgPend = 1;
2459 // allow any outstanding ioctl to finish
2461 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2462 if (tempword & FT1000_DB_DPRAM_TX) {
2464 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2465 if (tempword & FT1000_DB_DPRAM_TX) {
2470 if ( (tempword & FT1000_DB_DPRAM_TX) == 0) {
2471 // Put message into Slow Queue
2472 // Form Pseudo header
2473 pmsg = (PUSHORT)&tempbuffer[0];
2474 ppseudo_hdr = (PPSEUDO_HDR)pmsg;
2475 ppseudo_hdr->length = htons(0x0012);
2476 ppseudo_hdr->source = 0x10;
2477 ppseudo_hdr->destination = 0x20;
2478 ppseudo_hdr->portdest = 0;
2479 ppseudo_hdr->portsrc = 0;
2480 ppseudo_hdr->sh_str_id = 0;
2481 ppseudo_hdr->control = 0;
2482 ppseudo_hdr->rsvd1 = 0;
2483 ppseudo_hdr->rsvd2 = 0;
2484 ppseudo_hdr->qos_class = 0;
2485 // Insert slow queue sequence number
2486 ppseudo_hdr->seq_num = info->squeseqnum++;
2487 // Insert application id
2488 ppseudo_hdr->portsrc = 0;
2489 // Calculate new checksum
2490 ppseudo_hdr->checksum = *pmsg++;
2491 for (i=1; i<7; i++) {
2492 ppseudo_hdr->checksum ^= *pmsg++;
2494 pmsg = (PUSHORT)&tempbuffer[16];
2495 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
2496 *pmsg++ = htons(0x000e);
2497 *pmsg++ = htons(info->DSP_TIME[0]);
2498 *pmsg++ = htons(info->DSP_TIME[1]);
2499 *pmsg++ = htons(info->DSP_TIME[2]);
2500 *pmsg++ = htons(info->DSP_TIME[3]);
2501 convert.byte[0] = info->DspVer[0];
2502 convert.byte[1] = info->DspVer[1];
2503 *pmsg++ = convert.wrd;
2504 convert.byte[0] = info->DspVer[2];
2505 convert.byte[1] = info->DspVer[3];
2506 *pmsg++ = convert.wrd;
2507 *pmsg++ = htons(info->DrvErrNum);
2509 CardSendCommand (dev, (unsigned char*)&tempbuffer[0], (USHORT)(0x0012 + PSEUDOSZ));
2510 info->DrvErrNum = 0;
2512 info->DrvMsgPend = 0;
2523 status = STATUS_SUCCESS;
2526 DEBUG("return from ft1000_proc_drvmsg\n");
2532 int ft1000_poll(void* dev_id) {
2534 //FT1000_INFO *info = (PFT1000_INFO)((struct net_device *)dev_id)->priv;
2535 //struct ft1000_device *dev = (struct ft1000_device *)info->pFt1000Dev;
2536 struct ft1000_device *dev = (struct ft1000_device *)dev_id;
2537 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
2547 PDPRAM_BLK pdpram_blk;
2548 PPSEUDO_HDR ppseudo_hdr;
2549 unsigned long flags;
2551 //DEBUG("Enter ft1000_poll...\n");
2552 if (ft1000_chkcard(dev) == FALSE) {
2553 DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
2554 return STATUS_FAILURE;
2557 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
2558 // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword);
2560 //while ( (tempword) && (!status) ) {
2564 if (tempword & FT1000_DB_DPRAM_RX) {
2565 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n");
2567 status = ft1000_read_dpram16(dev, 0x200, (PUCHAR)&data, 0);
2568 //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data);
2569 size = ntohs(data) + 16 + 2; //wai
2571 modulo = 4 - (size % 4);
2572 size = size + modulo;
2574 status = ft1000_read_dpram16(dev, 0x201, (PUCHAR)&portid, 1);
2576 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid);
2578 if (size < MAX_CMD_SQSIZE) {
2582 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
2584 status = ft1000_proc_drvmsg (dev, size);
2585 if (status != STATUS_SUCCESS )
2589 // This is a dsp broadcast message
2590 // Check which application has registered for dsp broadcast messages
2591 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n");
2593 for (i=0; i<MAX_NUM_APP; i++) {
2594 if ( (info->app_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) &&
2595 (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT) )
2597 //DEBUG("Dsp broadcast message detected for app id %d\n", i);
2598 nxtph = FT1000_DPRAM_RX_BASE + 2;
2599 pdpram_blk = ft1000_get_buffer (&freercvpool);
2600 if (pdpram_blk != NULL) {
2601 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
2602 ppseudo_hdr = (PPSEUDO_HDR)pdpram_blk->pbuffer;
2603 // Put message into the appropriate application block
2604 info->app_info[i].nRxMsg++;
2605 spin_lock_irqsave(&free_buff_lock, flags);
2606 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
2607 info->app_info[i].NumOfMsg++;
2608 spin_unlock_irqrestore(&free_buff_lock, flags);
2609 wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
2612 info->app_info[i].nRxMsgMiss++;
2613 // Put memory back to free pool
2614 ft1000_free_buffer(pdpram_blk, &freercvpool);
2615 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
2619 DEBUG("Out of memory in free receive command pool\n");
2620 info->app_info[i].nRxMsgMiss++;
2621 }//endof if (pdpram_blk != NULL)
2624 // DEBUG("app_info mismatch\n");
2628 pdpram_blk = ft1000_get_buffer (&freercvpool);
2629 //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk);
2630 if (pdpram_blk != NULL) {
2631 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
2632 ppseudo_hdr = (PPSEUDO_HDR)pdpram_blk->pbuffer;
2633 // Search for correct application block
2634 for (i=0; i<MAX_NUM_APP; i++) {
2635 if (info->app_info[i].app_id == ppseudo_hdr->portdest) {
2640 if (i==(MAX_NUM_APP-1)) { // aelias [+] reason: was out of array boundary
2641 info->app_info[i].nRxMsgMiss++;
2642 DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr->portdest);
2643 // Put memory back to free pool
2644 ft1000_free_buffer(pdpram_blk, &freercvpool);
2647 if (info->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
2648 // Put memory back to free pool
2649 ft1000_free_buffer(pdpram_blk, &freercvpool);
2652 info->app_info[i].nRxMsg++;
2653 // Put message into the appropriate application block
2654 //pxu spin_lock_irqsave(&free_buff_lock, flags);
2655 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
2656 info->app_info[i].NumOfMsg++;
2657 //pxu spin_unlock_irqrestore(&free_buff_lock, flags);
2658 //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
2663 // Put memory back to free pool
2664 ft1000_free_buffer(pdpram_blk, &freercvpool);
2668 DEBUG("Out of memory in free receive command pool\n");
2672 } //endof if (size < MAX_CMD_SQSIZE)
2674 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size);
2676 status = ft1000_write_register (dev, FT1000_DB_DPRAM_RX, FT1000_REG_DOORBELL);
2678 else if (tempword & FT1000_DSP_ASIC_RESET) {
2679 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DSP_ASIC_RESET\n");
2681 // Let's reset the ASIC from the Host side as well
2682 status = ft1000_write_register (dev, ASIC_RESET_BIT, FT1000_REG_RESET);
2683 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
2685 while (tempword & ASIC_RESET_BIT) {
2686 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
2693 DEBUG("Unable to reset ASIC\n");
2694 return STATUS_SUCCESS;
2697 // Program WMARK register
2698 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2699 // clear ASIC reset doorbell
2700 status = ft1000_write_register (dev, FT1000_DSP_ASIC_RESET, FT1000_REG_DOORBELL);
2703 else if (tempword & FT1000_ASIC_RESET_REQ) {
2704 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
2706 // clear ASIC reset request from DSP
2707 status = ft1000_write_register (dev, FT1000_ASIC_RESET_REQ, FT1000_REG_DOORBELL);
2708 status = ft1000_write_register (dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
2709 // copy dsp session record from Adapter block
2710 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPSess.Rec[0], 1024);
2711 // Program WMARK register
2712 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2713 // ring doorbell to tell DSP that ASIC is out of reset
2714 status = ft1000_write_register (dev, FT1000_ASIC_RESET_DSP, FT1000_REG_DOORBELL);
2716 else if (tempword & FT1000_DB_COND_RESET) {
2717 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
2719 // Reset ASIC and DSP
2721 if (info->fAppMsgPend == 0) {
2722 // Reset ASIC and DSP
2724 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2725 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2726 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2727 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2728 info->CardReady = 0;
2729 info->DrvErrNum = DSP_CONDRESET_INFO;
2730 DEBUG("ft1000_hw:DSP conditional reset requested\n");
2731 info->ft1000_reset(dev->net);
2734 info->fProvComplete = 0;
2735 info->fCondResetPend = 1;
2738 ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL);
2741 }//endof if ( !status )
2743 //DEBUG("return from ft1000_poll.\n");
2744 return STATUS_SUCCESS;