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");
128 else if ( ft1000dev->dev == NULL )
130 DEBUG("NULL ft1000dev->dev, failure\n");
134 ret = usb_control_msg(ft1000dev->dev,
151 //---------------------------------------------------------------------------
152 // Function: ft1000_read_register
154 // Parameters: ft1000_device - device structure
155 // Data - data buffer to hold the value read
156 // nRegIndex - register index
158 // Returns: STATUS_SUCCESS - success
159 // STATUS_FAILURE - failure
161 // Description: This function returns the value in a register
165 //---------------------------------------------------------------------------
167 u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx)
169 u16 ret = STATUS_SUCCESS;
171 //DEBUG("ft1000_read_register: reg index is %d\n", nRegIndx);
172 //DEBUG("ft1000_read_register: spin_lock locked\n");
173 ret = ft1000_control(ft1000dev,
174 usb_rcvctrlpipe(ft1000dev->dev,0),
175 HARLEY_READ_REGISTER, //request --READ_REGISTER
176 HARLEY_READ_OPERATION, //requestType
181 LARGE_TIMEOUT ); //timeout
183 //DEBUG("ft1000_read_register: ret is %d \n", ret);
185 //DEBUG("ft1000_read_register: data is %x \n", *Data);
191 //---------------------------------------------------------------------------
192 // Function: ft1000_write_register
194 // Parameters: ft1000_device - device structure
195 // value - value to write into a register
196 // nRegIndex - register index
198 // Returns: STATUS_SUCCESS - success
199 // STATUS_FAILURE - failure
201 // Description: This function writes the value in a register
205 //---------------------------------------------------------------------------
206 u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRegIndx)
208 u16 ret = STATUS_SUCCESS;
210 //DEBUG("ft1000_write_register: value is: %d, reg index is: %d\n", value, nRegIndx);
212 ret = ft1000_control(ft1000dev,
213 usb_sndctrlpipe(ft1000dev->dev, 0),
214 HARLEY_WRITE_REGISTER, //request -- WRITE_REGISTER
215 HARLEY_WRITE_OPERATION, //requestType
225 //---------------------------------------------------------------------------
226 // Function: ft1000_read_dpram32
228 // Parameters: ft1000_device - device structure
229 // indx - starting address to read
230 // buffer - data buffer to hold the data read
231 // cnt - number of byte read from DPRAM
233 // Returns: STATUS_SUCCESS - success
234 // STATUS_FAILURE - failure
236 // Description: This function read a number of bytes from DPRAM
240 //---------------------------------------------------------------------------
242 u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt)
244 u16 ret = STATUS_SUCCESS;
246 //DEBUG("ft1000_read_dpram32: indx: %d cnt: %d\n", indx, cnt);
247 ret =ft1000_control(ft1000dev,
248 usb_rcvctrlpipe(ft1000dev->dev,0),
249 HARLEY_READ_DPRAM_32, //request --READ_DPRAM_32
250 HARLEY_READ_OPERATION, //requestType
255 LARGE_TIMEOUT ); //timeout
257 //DEBUG("ft1000_read_dpram32: ret is %d \n", ret);
259 //DEBUG("ft1000_read_dpram32: ret=%d \n", ret);
265 //---------------------------------------------------------------------------
266 // Function: ft1000_write_dpram32
268 // Parameters: ft1000_device - device structure
269 // indx - starting address to write the data
270 // buffer - data buffer to write into DPRAM
271 // cnt - number of bytes to write
273 // Returns: STATUS_SUCCESS - success
274 // STATUS_FAILURE - failure
276 // Description: This function writes into DPRAM a number of bytes
280 //---------------------------------------------------------------------------
281 u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt)
283 u16 ret = STATUS_SUCCESS;
285 //DEBUG("ft1000_write_dpram32: indx: %d buffer: %x cnt: %d\n", indx, buffer, cnt);
287 cnt += cnt - (cnt % 4);
289 ret = ft1000_control(ft1000dev,
290 usb_sndctrlpipe(ft1000dev->dev, 0),
291 HARLEY_WRITE_DPRAM_32, //request -- WRITE_DPRAM_32
292 HARLEY_WRITE_OPERATION, //requestType
302 //---------------------------------------------------------------------------
303 // Function: ft1000_read_dpram16
305 // Parameters: ft1000_device - device structure
306 // indx - starting address to read
307 // buffer - data buffer to hold the data read
308 // hightlow - high or low 16 bit word
310 // Returns: STATUS_SUCCESS - success
311 // STATUS_FAILURE - failure
313 // Description: This function read 16 bits from DPRAM
317 //---------------------------------------------------------------------------
318 u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow)
320 u16 ret = STATUS_SUCCESS;
322 //DEBUG("ft1000_read_dpram16: indx: %d hightlow: %d\n", indx, highlow);
327 request = HARLEY_READ_DPRAM_LOW;
329 request = HARLEY_READ_DPRAM_HIGH;
331 ret = ft1000_control(ft1000dev,
332 usb_rcvctrlpipe(ft1000dev->dev,0),
333 request, //request --READ_DPRAM_H/L
334 HARLEY_READ_OPERATION, //requestType
339 LARGE_TIMEOUT ); //timeout
341 //DEBUG("ft1000_read_dpram16: ret is %d \n", ret);
344 //DEBUG("ft1000_read_dpram16: data is %x \n", *buffer);
350 //---------------------------------------------------------------------------
351 // Function: ft1000_write_dpram16
353 // Parameters: ft1000_device - device structure
354 // indx - starting address to write the data
355 // value - 16bits value to write
356 // hightlow - high or low 16 bit word
358 // Returns: STATUS_SUCCESS - success
359 // STATUS_FAILURE - failure
361 // Description: This function writes into DPRAM a number of bytes
365 //---------------------------------------------------------------------------
366 u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT value, u8 highlow)
368 u16 ret = STATUS_SUCCESS;
372 //DEBUG("ft1000_write_dpram16: indx: %d value: %d highlow: %d\n", indx, value, highlow);
378 request = HARLEY_WRITE_DPRAM_LOW;
380 request = HARLEY_WRITE_DPRAM_HIGH;
382 ret = ft1000_control(ft1000dev,
383 usb_sndctrlpipe(ft1000dev->dev, 0),
384 request, //request -- WRITE_DPRAM_H/L
385 HARLEY_WRITE_OPERATION, //requestType
395 //---------------------------------------------------------------------------
396 // Function: fix_ft1000_read_dpram32
398 // Parameters: ft1000_device - device structure
399 // indx - starting address to read
400 // buffer - data buffer to hold the data read
403 // Returns: STATUS_SUCCESS - success
404 // STATUS_FAILURE - failure
406 // Description: This function read DPRAM 4 words at a time
410 //---------------------------------------------------------------------------
411 u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer)
415 u16 ret = STATUS_SUCCESS;
417 //DEBUG("fix_ft1000_read_dpram32: indx: %d \n", indx);
419 ret = ft1000_read_dpram32(ft1000dev, pos, buf, 16);
420 if (ret == STATUS_SUCCESS)
423 *buffer++ = buf[pos++];
424 *buffer++ = buf[pos++];
425 *buffer++ = buf[pos++];
426 *buffer++ = buf[pos++];
430 DEBUG("fix_ft1000_read_dpram32: DPRAM32 Read failed\n");
438 //DEBUG("fix_ft1000_read_dpram32: data is %x \n", *buffer);
444 //---------------------------------------------------------------------------
445 // Function: fix_ft1000_write_dpram32
447 // Parameters: ft1000_device - device structure
448 // indx - starting address to write
449 // buffer - data buffer to write
452 // Returns: STATUS_SUCCESS - success
453 // STATUS_FAILURE - failure
455 // Description: This function write to DPRAM 4 words at a time
459 //---------------------------------------------------------------------------
460 u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer)
466 UCHAR resultbuffer[32];
468 u16 ret = STATUS_SUCCESS;
470 //DEBUG("fix_ft1000_write_dpram32: Entered:\n");
474 ret = ft1000_read_dpram32(ft1000dev, pos1, buf, 16);
475 if (ret == STATUS_SUCCESS)
478 buf[pos2++] = *buffer++;
479 buf[pos2++] = *buffer++;
480 buf[pos2++] = *buffer++;
481 buf[pos2++] = *buffer++;
482 ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16);
486 DEBUG("fix_ft1000_write_dpram32: DPRAM32 Read failed\n");
491 ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16);
492 if (ret == STATUS_SUCCESS)
497 if (buf[i] != resultbuffer[i]){
499 ret = STATUS_FAILURE;
504 if (ret == STATUS_FAILURE)
506 ret = ft1000_write_dpram32(ft1000dev, pos1, (PUCHAR)&tempbuffer[0], 16);
507 ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16);
508 if (ret == STATUS_SUCCESS)
513 if (tempbuffer[i] != resultbuffer[i])
515 ret = STATUS_FAILURE;
516 DEBUG("fix_ft1000_write_dpram32 Failed to write\n");
527 //------------------------------------------------------------------------
529 // Function: card_reset_dsp
531 // Synopsis: This function is called to reset or activate the DSP
533 // Arguments: value - reset or activate
536 //-----------------------------------------------------------------------
537 static void card_reset_dsp (struct ft1000_device *ft1000dev, BOOLEAN value)
539 u16 status = STATUS_SUCCESS;
542 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
543 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_CTRL);
546 DEBUG("Reset DSP\n");
547 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
548 tempword |= DSP_RESET_BIT;
549 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
553 DEBUG("Activate DSP\n");
554 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
556 tempword |= DSP_ENCRYPTED;
557 tempword &= ~DSP_UNENCRYPTED;
559 tempword |= DSP_UNENCRYPTED;
560 tempword &= ~DSP_ENCRYPTED;
562 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
563 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
564 tempword &= ~EFUSE_MEM_DISABLE;
565 tempword &= ~DSP_RESET_BIT;
566 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
567 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
571 //---------------------------------------------------------------------------
572 // Function: CardSendCommand
574 // Parameters: ft1000_device - device structure
575 // ptempbuffer - command buffer
576 // size - command buffer size
578 // Returns: STATUS_SUCCESS - success
579 // STATUS_FAILURE - failure
581 // Description: This function sends a command to ASIC
585 //---------------------------------------------------------------------------
586 void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size)
589 unsigned char *commandbuf;
591 DEBUG("CardSendCommand: enter CardSendCommand... size=%d\n", size);
593 commandbuf =(unsigned char*) kmalloc(size+2, GFP_KERNEL);
594 //memset((void*)commandbuf, 0, size+2);
595 memcpy((void*)commandbuf+2, (void*)ptempbuffer, size);
597 //DEBUG("CardSendCommand: Command Send\n");
599 for (i=0; i<size+2; i++)
601 DEBUG("FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++);
605 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
612 // check for odd word
616 // Must force to be 32 bit aligned
617 size += 4 - (size % 4);
621 //DEBUG("CardSendCommand: write dpram ... size=%d\n", size);
622 ft1000_write_dpram32(ft1000dev, 0,commandbuf, size);
624 //DEBUG("CardSendCommand: write into doorbell ...\n");
625 ft1000_write_register(ft1000dev, FT1000_DB_DPRAM_TX ,FT1000_REG_DOORBELL) ;
628 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
629 //DEBUG("CardSendCommand: read doorbell ...temp=%x\n", temp);
630 if ( (temp & 0x0100) == 0)
632 //DEBUG("CardSendCommand: Message sent\n");
638 //--------------------------------------------------------------------------
640 // Function: dsp_reload
642 // Synopsis: This function is called to load or reload the DSP
644 // Arguments: ft1000dev - device structure
647 //-----------------------------------------------------------------------
648 int dsp_reload(struct ft1000_device *ft1000dev)
654 PFT1000_INFO pft1000info;
656 pft1000info = netdev_priv(ft1000dev->net);
658 pft1000info->CardReady = 0;
660 // Program Interrupt Mask register
661 status = ft1000_write_register (ft1000dev, 0xffff, FT1000_REG_SUP_IMASK);
663 status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET);
664 tempword |= ASIC_RESET_BIT;
665 status = ft1000_write_register (ft1000dev, tempword, FT1000_REG_RESET);
667 status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET);
668 DEBUG("Reset Register = 0x%x\n", tempword);
671 card_reset_dsp (ft1000dev, 1);
673 card_reset_dsp (ft1000dev, 0);
676 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
678 // Let's check for FEFE
679 status = ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (PUCHAR)&templong, 4);
680 DEBUG("templong (fefe) = 0x%8x\n", templong);
683 status = scram_dnldr(ft1000dev, pFileStart, FileLength);
685 if (status != STATUS_SUCCESS)
690 DEBUG("dsp_reload returned\n");
695 //---------------------------------------------------------------------------
697 // Function: ft1000_reset_asic
698 // Descripton: This function will call the Card Service function to reset the
701 // dev - device structure
705 //---------------------------------------------------------------------------
706 static void ft1000_reset_asic (struct net_device *dev)
708 FT1000_INFO *info = netdev_priv(dev);
709 struct ft1000_device *ft1000dev = info->pFt1000Dev;
712 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
714 info->ASICResetNum++;
716 // Let's use the register provided by the Magnemite ASIC to reset the
718 ft1000_write_register(ft1000dev, (DSP_RESET_BIT | ASIC_RESET_BIT), FT1000_REG_RESET );
722 // set watermark to -1 in order to not generate an interrrupt
723 ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_MAG_WATERMARK);
726 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR);
727 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword);
728 ft1000_write_register (ft1000dev, tempword, FT1000_REG_SUP_ISR);
729 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR);
730 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword);
734 //---------------------------------------------------------------------------
736 // Function: ft1000_disable_interrupts
737 // Descripton: This function will disable all interrupts.
739 // dev - device structure
743 //---------------------------------------------------------------------------
744 static void ft1000_disable_interrupts(struct net_device *dev) {
745 FT1000_INFO *info = netdev_priv(dev);
746 struct ft1000_device *ft1000dev = info->pFt1000Dev;
749 DEBUG("ft1000_hw: ft1000_disable_interrupts()\n");
750 ft1000_write_register (ft1000dev, ISR_MASK_ALL, FT1000_REG_SUP_IMASK);
751 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_IMASK);
752 DEBUG("ft1000_hw:ft1000_disable_interrupts:current interrupt enable mask = 0x%x\n", tempword);
753 info->InterruptsEnabled = FALSE;
756 //---------------------------------------------------------------------------
758 // Function: ft1000_enable_interrupts
759 // Descripton: This function will enable interrupts base on the current interrupt mask.
761 // dev - device structure
765 //---------------------------------------------------------------------------
766 static void ft1000_enable_interrupts(struct net_device *dev) {
767 FT1000_INFO *info = netdev_priv(dev);
768 struct ft1000_device *ft1000dev = info->pFt1000Dev;
771 DEBUG("ft1000_hw:ft1000_enable_interrupts()\n");
772 ft1000_write_register (ft1000dev, info->CurrentInterruptEnableMask, FT1000_REG_SUP_IMASK);
773 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_IMASK);
774 DEBUG("ft1000_hw:ft1000_enable_interrupts:current interrupt enable mask = 0x%x\n", tempword);
775 info->InterruptsEnabled = TRUE;
779 //---------------------------------------------------------------------------
781 // Function: ft1000_reset_card
782 // Descripton: This function will reset the card
784 // dev - device structure
786 // status - FALSE (card reset fail)
787 // TRUE (card reset successful)
789 //---------------------------------------------------------------------------
790 static int ft1000_reset_card (struct net_device *dev)
792 FT1000_INFO *info = netdev_priv(dev);
793 struct ft1000_device *ft1000dev = info->pFt1000Dev;
797 DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
799 info->fCondResetPend = 1;
801 info->fProvComplete = 0;
802 //ft1000_disable_interrupts(dev);
804 // Cancel heartbeat task since we are reloading the dsp
805 //del_timer(&poll_timer[info->CardNumber]);
807 // Make sure we free any memory reserve for provisioning
808 while (list_empty(&info->prov_list) == 0) {
809 DEBUG("ft1000_hw:ft1000_reset_card:deleting provisioning record\n");
810 ptr = list_entry(info->prov_list.next, PROV_RECORD, list);
811 list_del(&ptr->list);
812 kfree(ptr->pprov_data);
816 DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n");
818 ft1000_reset_asic(dev);
823 DEBUG("ft1000_hw:ft1000_reset_card:resetting ASIC and DSP\n");
824 ft1000_write_register (ft1000dev, (DSP_RESET_BIT | ASIC_RESET_BIT), FT1000_REG_RESET );
827 // Copy DSP session record into info block if this is not a coldstart
828 //if (ft1000_card_present == 1) {
829 spin_lock_irqsave(&info->dpram_lock, flags);
831 ft1000_write_register(ft1000dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR);
832 for (i=0;i<MAX_DSP_SESS_REC/2; i++) {
833 //info->DSPSess.MagRec[i] = inl(dev->base_addr+FT1000_REG_MAG_DPDATA);
834 ft1000_read_dpram32(ft1000dev, FT1000_REG_MAG_DPDATA, (PCHAR)&(info->DSPSess.MagRec[i]), 4);
837 spin_unlock_irqrestore(&info->dpram_lock, flags);
839 info->squeseqnum = 0;
841 DEBUG("ft1000_hw:ft1000_reset_card:resetting ASIC\n");
844 ft1000_reset_asic(dev);
848 DEBUG("ft1000_hw:ft1000_reset_card:downloading dsp image\n");
851 // Put dsp in reset and take ASIC out of reset
852 DEBUG("ft1000_hw:ft1000_reset_card:Put DSP in reset and take ASIC out of reset\n");
853 ft1000_write_register (ft1000dev, DSP_RESET_BIT, FT1000_REG_RESET);
855 // Setting MAGNEMITE ASIC to big endian mode
856 ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
858 // Take DSP out of reset
860 ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
861 tempword |= DSP_ENCRYPTED;
862 tempword &= ~DSP_UNENCRYPTED;
863 ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
864 tempword &= ~EFUSE_MEM_DISABLE;
865 ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
866 tempword &= ~DSP_RESET_BIT;
867 ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
870 // FLARION_DSP_ACTIVE;
872 DEBUG("ft1000_hw:ft1000_reset_card:Take DSP out of reset\n");
874 // Wait for 0xfefe indicating dsp ready before starting download
875 for (i=0; i<50; i++) {
876 //tempword = ft1000_read_dpram_mag_16(dev, FT1000_MAG_DPRAM_FEFE, FT1000_MAG_DPRAM_FEFE_INDX);
877 ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (PUCHAR)&templong, 4);
878 if (tempword == 0xfefe) {
885 DEBUG("ft1000_hw:ft1000_reset_card:No FEFE detected from DSP\n");
892 DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n");
893 dsp_reload(ft1000dev);
895 DEBUG("dsp reload successful\n");
900 // Initialize DSP heartbeat area to ho
901 ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag, FT1000_MAG_HI_HO_INDX);
902 ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (PCHAR)&tempword, FT1000_MAG_HI_HO_INDX);
903 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword);
908 //ft1000_enable_interrupts(dev);
909 /* Schedule heartbeat process to run every 2 seconds */
910 //poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
911 //poll_timer[info->CardNumber].data = (u_long)dev;
912 //add_timer(&poll_timer[info->CardNumber]);
914 info->fCondResetPend = 0;
921 #ifdef HAVE_NET_DEVICE_OPS
922 static const struct net_device_ops ftnet_ops =
924 .ndo_open = &ft1000_open,
925 .ndo_stop = &ft1000_close,
926 .ndo_start_xmit = &ft1000_start_xmit,
927 .ndo_get_stats = &ft1000_netdev_stats,
932 //---------------------------------------------------------------------------
933 // Function: init_ft1000_netdev
935 // Parameters: ft1000dev - device structure
938 // Returns: STATUS_SUCCESS - success
939 // STATUS_FAILURE - failure
941 // Description: This function initialize the network device
945 //---------------------------------------------------------------------------
946 u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
948 struct net_device *netdev;
949 FT1000_INFO *pInfo = NULL;
950 PDPRAM_BLK pdpram_blk;
952 struct list_head *cur, *tmp;
955 gCardIndex=0; //mbelian
957 DEBUG("Enter init_ft1000_netdev...\n");
960 netdev = alloc_etherdev( sizeof(FT1000_INFO));
963 DEBUG("init_ft1000_netdev: can not allocate network device\n");
964 return STATUS_FAILURE;
967 //pInfo = (PFT1000_INFO)netdev->priv;
968 pInfo = (FT1000_INFO *) netdev_priv (netdev);
970 //DEBUG("init_ft1000_netdev: gFt1000Info=%x, netdev=%x, ft1000dev=%x\n", gFt1000Info, netdev, ft1000dev);
972 memset (pInfo, 0, sizeof(FT1000_INFO));
974 dev_alloc_name(netdev, netdev->name);
976 //for the first inserted card, decide the card index beginning number, in case there are existing network interfaces
977 if ( gCardIndex == 0 )
979 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name);
981 if ( strncmp(netdev->name,"eth", 3) == 0) {
982 card_nr[0] = netdev->name[3];
984 ret_val = strict_strtoul(card_nr, 10, &gCardIndex);
986 printk(KERN_ERR "Can't parse netdev\n");
988 return STATUS_FAILURE;
991 pInfo->CardNumber = gCardIndex;
992 DEBUG("card number = %d\n", pInfo->CardNumber);
995 printk(KERN_ERR "ft1000: Invalid device name\n");
997 return STATUS_FAILURE;
1002 //not the first inserted card, increase card number by 1
1004 pInfo->CardNumber = gCardIndex;
1005 /*DEBUG("card number = %d\n", pInfo->CardNumber);*/ //mbelian
1008 memset(&pInfo->stats, 0, sizeof(struct net_device_stats) );
1010 spin_lock_init(&pInfo->dpram_lock);
1011 pInfo->pFt1000Dev = ft1000dev;
1012 pInfo->DrvErrNum = 0;
1013 pInfo->ASICResetNum = 0;
1014 pInfo->registered = 1;
1015 pInfo->ft1000_reset = ft1000_reset;
1016 pInfo->mediastate = 0;
1017 pInfo->fifo_cnt = 0;
1018 pInfo->DeviceCreated = FALSE;
1019 pInfo->DeviceMajor = 0;
1020 pInfo->CurrentInterruptEnableMask = ISR_DEFAULT_MASK;
1021 pInfo->InterruptsEnabled = FALSE;
1022 pInfo->CardReady = 0;
1023 pInfo->DSP_TIME[0] = 0;
1024 pInfo->DSP_TIME[1] = 0;
1025 pInfo->DSP_TIME[2] = 0;
1026 pInfo->DSP_TIME[3] = 0;
1027 pInfo->fAppMsgPend = 0;
1028 pInfo->fCondResetPend = 0;
1030 pInfo->dspalive = 0;
1031 for (i=0;i<32 ;i++ )
1033 pInfo->tempbuf[i] = 0;
1036 INIT_LIST_HEAD(&pInfo->prov_list);
1039 #ifdef HAVE_NET_DEVICE_OPS
1040 netdev->netdev_ops = &ftnet_ops;
1042 netdev->hard_start_xmit = &ft1000_start_xmit;
1043 netdev->get_stats = &ft1000_netdev_stats;
1044 netdev->open = &ft1000_open;
1045 netdev->stop = &ft1000_close;
1048 //netif_stop_queue(netdev); //mbelian
1051 ft1000dev->net = netdev;
1055 //init free_buff_lock, freercvpool, numofmsgbuf, pdpram_blk
1056 //only init once per card
1058 DEBUG("Initialize free_buff_lock and freercvpool\n");
1059 spin_lock_init(&free_buff_lock);
1061 // initialize a list of buffers to be use for queuing up receive command data
1062 INIT_LIST_HEAD (&freercvpool);
1064 // create list of free buffers
1065 for (i=0; i<NUM_OF_FREE_BUFFERS; i++) {
1066 // Get memory for DPRAM_DATA link list
1067 pdpram_blk = kmalloc ( sizeof(DPRAM_BLK), GFP_KERNEL );
1068 if (pdpram_blk == NULL)
1070 // Get a block of memory to store command data
1071 pdpram_blk->pbuffer = kmalloc ( MAX_CMD_SQSIZE, GFP_KERNEL );
1072 if (pdpram_blk->pbuffer == NULL) {
1076 // link provisioning data
1077 list_add_tail (&pdpram_blk->list, &freercvpool);
1079 numofmsgbuf = NUM_OF_FREE_BUFFERS;
1082 return STATUS_SUCCESS;
1086 list_for_each_safe(cur, tmp, &freercvpool) {
1087 pdpram_blk = list_entry(cur, DPRAM_BLK, list);
1088 list_del(&pdpram_blk->list);
1089 kfree(pdpram_blk->pbuffer);
1092 return STATUS_FAILURE;
1097 //---------------------------------------------------------------------------
1098 // Function: reg_ft1000_netdev
1100 // Parameters: ft1000dev - device structure
1103 // Returns: STATUS_SUCCESS - success
1104 // STATUS_FAILURE - failure
1106 // Description: This function register the network driver
1110 //---------------------------------------------------------------------------
1111 u16 reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf)
1113 struct net_device *netdev;
1117 netdev = ft1000dev->net;
1118 pInfo = netdev_priv(ft1000dev->net);
1119 DEBUG("Enter reg_ft1000_netdev...\n");
1122 ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID);
1124 usb_set_intfdata(intf, pInfo);
1125 SET_NETDEV_DEV(netdev, &intf->dev);
1127 rc = register_netdev(netdev);
1130 DEBUG("reg_ft1000_netdev: could not register network device\n");
1131 free_netdev(netdev);
1132 return STATUS_FAILURE;
1136 //Create character device, implemented by Jim
1137 ft1000_CreateDevice(ft1000dev);
1139 //INIT_LIST_HEAD(&pInfo->prov_list);
1141 for (i=0; i<MAX_NUM_CARDS; i++) {
1142 poll_timer[i].function = ft1000_hbchk;
1146 //hard code MAC address for now
1148 netdev->dev_addr[0] = 0;
1149 netdev->dev_addr[1] = 7;
1150 netdev->dev_addr[2] = 0x35;
1151 netdev->dev_addr[3] = 0x84;
1152 netdev->dev_addr[4] = 0;
1153 netdev->dev_addr[5] = 0x20 + pInfo->CardNumber;
1156 DEBUG ("reg_ft1000_netdev returned\n");
1158 pInfo->CardReady = 1;
1161 return STATUS_SUCCESS;
1164 static int ft1000_reset(struct net_device *dev)
1166 ft1000_reset_card(dev);
1170 //---------------------------------------------------------------------------
1171 // Function: ft1000_usb_transmit_complete
1173 // Parameters: urb - transmitted usb urb
1178 // Description: This is the callback function when a urb is transmitted
1182 //---------------------------------------------------------------------------
1183 static void ft1000_usb_transmit_complete(struct urb *urb)
1186 struct ft1000_device *ft1000dev = urb->context;
1188 //DEBUG("ft1000_usb_transmit_complete entered\n");
1189 // Jim spin_lock(&ft1000dev->device_lock);
1192 printk("%s: TX status %d\n", ft1000dev->net->name, urb->status);
1194 netif_wake_queue(ft1000dev->net);
1196 //Jim spin_unlock(&ft1000dev->device_lock);
1197 //DEBUG("Return from ft1000_usb_transmit_complete\n");
1201 /****************************************************************
1203 ****************************************************************/
1204 static int ft1000_read_fifo_reg(struct ft1000_device *ft1000dev,unsigned int pipe,
1215 DECLARE_WAITQUEUE(wait, current);
1217 struct usb_ctrlrequest *dr;
1220 if (ft1000dev == NULL )
1222 DEBUG("NULL ft1000dev, failure\n");
1223 return STATUS_FAILURE;
1225 else if ( ft1000dev->dev == NULL )
1227 DEBUG("NULL ft1000dev->dev, failure\n");
1228 return STATUS_FAILURE;
1231 spin_lock(&ft1000dev->device_lock);
1233 /*DECLARE_WAITQUEUE(wait, current);
1235 struct usb_ctrlrequest *dr;
1240 spin_unlock(&ft1000dev->device_lock);
1244 urb = usb_alloc_urb(0, GFP_KERNEL);
1245 dr = kmalloc(sizeof(struct usb_ctrlrequest), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
1251 spin_unlock(&ft1000dev->device_lock);
1257 dr->bRequestType = requesttype;
1258 dr->bRequest = request;
1263 usb_fill_control_urb(urb, ft1000dev->dev, pipe, (char*)dr, (void*)data, size, (void *)ft1000_control_complete, (void*)ft1000dev);
1266 init_waitqueue_head(&ft1000dev->control_wait);
1268 //current->state = TASK_INTERRUPTIBLE; //mbelian
1269 set_current_state(TASK_INTERRUPTIBLE);
1271 add_wait_queue(&ft1000dev->control_wait, &wait);
1276 status = usb_submit_urb(urb, GFP_KERNEL);
1282 remove_wait_queue(&ft1000dev->control_wait, &wait);
1283 spin_unlock(&ft1000dev->device_lock);
1287 if(urb->status == -EINPROGRESS)
1289 while(timeout && urb->status == -EINPROGRESS)
1291 status = timeout = schedule_timeout(timeout);
1299 remove_wait_queue(&ft1000dev->control_wait, &wait);
1303 usb_unlink_urb(urb);
1304 printk("ft1000 timeout\n");
1305 status = -ETIMEDOUT;
1309 status = urb->status;
1313 printk("ft1000 control message failed (urb addr: %p) with error number: %i\n", urb, (int)status);
1315 usb_clear_halt(ft1000dev->dev, usb_rcvctrlpipe(ft1000dev->dev, 0));
1316 usb_clear_halt(ft1000dev->dev, usb_sndctrlpipe(ft1000dev->dev, 0));
1317 usb_unlink_urb(urb);
1325 spin_unlock(&ft1000dev->device_lock);
1331 //---------------------------------------------------------------------------
1332 // Function: ft1000_read_fifo_len
1334 // Parameters: ft1000dev - device structure
1339 // Description: read the fifo length register content
1343 //---------------------------------------------------------------------------
1344 static inline u16 ft1000_read_fifo_len (struct net_device *dev)
1349 //FT1000_INFO *info = (PFT1000_INFO)dev->priv;
1350 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev);
1351 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1352 // 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 *???
1353 DEBUG("ft1000_read_fifo_len: enter ft1000dev %p\n", ft1000dev); //aelias [+] reason: up
1354 //ft1000_read_register(ft1000dev, &temp, FT1000_REG_MAG_UFSR);
1356 ret = STATUS_SUCCESS;
1358 ret = ft1000_read_fifo_reg(ft1000dev,
1359 usb_rcvctrlpipe(ft1000dev->dev,0),
1360 HARLEY_READ_REGISTER,
1361 HARLEY_READ_OPERATION,
1363 FT1000_REG_MAG_UFSR,
1369 ret = STATUS_SUCCESS;
1371 ret = STATUS_FAILURE;
1373 DEBUG("ft1000_read_fifo_len: returned %d\n", temp);
1380 //---------------------------------------------------------------------------
1382 // Function: ft1000_copy_down_pkt
1383 // Descripton: This function will take an ethernet packet and convert it to
1384 // a Flarion packet prior to sending it to the ASIC Downlink
1387 // dev - device structure
1388 // packet - address of ethernet packet
1389 // len - length of IP packet
1394 //---------------------------------------------------------------------------
1395 static int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len)
1397 FT1000_INFO *pInfo = netdev_priv(netdev);
1398 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
1406 if (!pInfo->CardReady)
1409 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
1410 return STATUS_FAILURE;
1415 //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len);
1418 // Check if there is room on the FIFO
1419 if ( len > ft1000_read_fifo_len (netdev) )
1422 if ( len > ft1000_read_fifo_len (netdev) )
1427 if ( len > ft1000_read_fifo_len (netdev) )
1432 if ( len > ft1000_read_fifo_len (netdev) )
1437 if ( len > ft1000_read_fifo_len (netdev) )
1442 if ( len > ft1000_read_fifo_len (netdev) )
1447 if ( len > ft1000_read_fifo_len (netdev) )
1449 DEBUG("ft1000_hw:ft1000_copy_down_pkt:Transmit FIFO is fulli - pkt drop\n");
1450 pInfo->stats.tx_errors++;
1451 return STATUS_SUCCESS;
1456 count = sizeof (PSEUDO_HDR) + len;
1457 if(count > MAX_BUF_SIZE)
1459 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n");
1460 DEBUG("size = %d\n", count);
1461 return STATUS_FAILURE;
1465 count = count + (4- (count %4) );
1467 pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]);
1468 *pTemp ++ = ntohs(count);
1475 pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]);
1476 checksum = *pTemp ++;
1479 checksum ^= *pTemp ++;
1481 *pTemp++ = checksum;
1482 memcpy (&(pFt1000Dev->tx_buf[sizeof(PSEUDO_HDR)]), packet, len);
1484 //usb_init_urb(pFt1000Dev->tx_urb); //mbelian
1486 netif_stop_queue(netdev);
1488 //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count);
1490 usb_fill_bulk_urb(pFt1000Dev->tx_urb,
1492 usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr),
1495 ft1000_usb_transmit_complete,
1498 t = (u8 *)pFt1000Dev->tx_urb->transfer_buffer;
1499 //DEBUG("transfer_length=%d\n", pFt1000Dev->tx_urb->transfer_buffer_length);
1500 /*for (i=0; i<count; i++ )
1502 DEBUG("%x ", *t++ );
1506 ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC);
1509 DEBUG("ft1000 failed tx_urb %d\n", ret);
1511 /* pInfo->stats.tx_errors++;
1513 netif_start_queue(netdev); */ //mbelian
1514 return STATUS_FAILURE;
1519 //DEBUG("ft1000 sucess tx_urb %d\n", ret);
1521 pInfo->stats.tx_packets++;
1522 pInfo->stats.tx_bytes += (len+14);
1525 //DEBUG("ft1000_copy_down_pkt() exit\n");
1527 return STATUS_SUCCESS;
1530 //---------------------------------------------------------------------------
1531 // Function: ft1000_start_xmit
1533 // Parameters: skb - socket buffer to be sent
1534 // dev - network device
1539 // Description: transmit a ethernet packet
1543 //---------------------------------------------------------------------------
1544 static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1546 FT1000_INFO *pInfo = netdev_priv(dev);
1547 struct ft1000_device *pFt1000Dev= pInfo->pFt1000Dev;
1552 //DEBUG(" ft1000_start_xmit() entered\n");
1556 DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" );
1557 return STATUS_FAILURE;
1560 if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1562 DEBUG("network driver is closed, return\n");
1564 //usb_kill_urb(pFt1000Dev->tx_urb); //mbelian
1565 return STATUS_SUCCESS;
1568 //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len);
1569 pipe = usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr);
1570 maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe));
1571 //DEBUG("ft1000_start_xmit 2: pipe=%d dev->maxpacket = %d\n", pipe, maxlen);
1573 pdata = (u8 *)skb->data;
1574 /*for (i=0; i<skb->len; i++)
1575 DEBUG("skb->data[%d]=%x ", i, *(skb->data+i));
1580 if (pInfo->mediastate == 0)
1582 /* Drop packet is mediastate is down */
1583 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n");
1585 return STATUS_SUCCESS;
1588 if ( (skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE) )
1590 /* Drop packet which has invalid size */
1591 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n");
1593 return STATUS_SUCCESS;
1596 if(ft1000_copy_down_pkt (dev, (pdata+ENET_HEADER_SIZE-2), skb->len - ENET_HEADER_SIZE + 2) == STATUS_FAILURE)
1599 return STATUS_SUCCESS;
1603 //DEBUG(" ft1000_start_xmit() exit\n");
1608 //---------------------------------------------------------------------------
1610 // Function: ft1000_copy_up_pkt
1611 // Descripton: This function will take a packet from the FIFO up link and
1612 // convert it into an ethernet packet and deliver it to the IP stack
1614 // urb - the receving usb urb
1620 //---------------------------------------------------------------------------
1621 static int ft1000_copy_up_pkt (struct urb *urb)
1623 PFT1000_INFO info = urb->context;
1624 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1625 struct net_device *net = ft1000dev->net;
1630 struct sk_buff *skb;
1637 //DEBUG("ft1000_copy_up_pkt entered\n");
1639 if ( ft1000dev->status & FT1000_STATUS_CLOSING)
1641 DEBUG("network driver is closed, return\n");
1642 return STATUS_SUCCESS;
1646 len = urb->transfer_buffer_length;
1647 lena = urb->actual_length; //mbelian
1648 //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n",
1649 // urb->transfer_buffer_length, urb->actual_length);
1651 chksum = (PUSHORT)ft1000dev->rx_buf;
1653 tempword = *chksum++;
1656 tempword ^= *chksum++;
1659 if (tempword != *chksum)
1661 info->stats.rx_errors ++;
1662 ft1000_submit_rx_urb(info);
1663 return STATUS_FAILURE;
1667 //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum);
1669 skb = dev_alloc_skb(len+12+2);
1673 DEBUG("ft1000_copy_up_pkt: No Network buffers available\n");
1674 info->stats.rx_errors++;
1675 ft1000_submit_rx_urb(info);
1676 return STATUS_FAILURE;
1679 pbuffer = (u8 *)skb_put(skb, len+12);
1681 //subtract the number of bytes read already
1685 *pbuffer++ = net->dev_addr[0];
1686 *pbuffer++ = net->dev_addr[1];
1687 *pbuffer++ = net->dev_addr[2];
1688 *pbuffer++ = net->dev_addr[3];
1689 *pbuffer++ = net->dev_addr[4];
1690 *pbuffer++ = net->dev_addr[5];
1701 memcpy(pbuffer, ft1000dev->rx_buf+sizeof(PSEUDO_HDR), len-sizeof(PSEUDO_HDR));
1703 //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n");
1704 /*for (i=0; i<len+12; i++)
1706 DEBUG("ft1000_copy_up_pkt: Protocol Data: 0x%x\n ", *ptemp++);
1711 skb->protocol = eth_type_trans(skb, net);
1712 skb->ip_summed = CHECKSUM_UNNECESSARY;
1715 info->stats.rx_packets++;
1716 // Add on 12 bytes for MAC address which was removed
1717 info->stats.rx_bytes += (lena+12); //mbelian
1719 ft1000_submit_rx_urb(info);
1720 //DEBUG("ft1000_copy_up_pkt exited\n");
1724 //---------------------------------------------------------------------------
1726 // Function: ft1000_submit_rx_urb
1727 // Descripton: the receiving function of the network driver
1730 // info - a private structure contains the device information
1736 //---------------------------------------------------------------------------
1737 static int ft1000_submit_rx_urb(PFT1000_INFO info)
1740 struct ft1000_device *pFt1000Dev = info->pFt1000Dev;
1742 //netif_carrier_on(pFt1000Dev->net);
1744 //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb));
1745 if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1747 DEBUG("network driver is closed, return\n");
1748 //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian
1749 return STATUS_SUCCESS;
1751 //memset(pFt1000Dev->rx_urb, 0, sizeof(*pFt1000Dev->rx_urb));
1752 //usb_init_urb(pFt1000Dev->rx_urb);//mbelian
1754 //spin_lock_init(&pFt1000Dev->rx_urb->lock);
1756 usb_fill_bulk_urb(pFt1000Dev->rx_urb,
1758 usb_rcvbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_in_endpointAddr),
1761 (usb_complete_t)ft1000_copy_up_pkt,
1765 if((result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC)))
1767 printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result);
1768 return STATUS_FAILURE;
1771 //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result);
1773 return STATUS_SUCCESS;
1776 //---------------------------------------------------------------------------
1777 // Function: ft1000_open
1780 // dev - network device
1785 // Description: open the network driver
1789 //---------------------------------------------------------------------------
1790 static int ft1000_open (struct net_device *dev)
1792 FT1000_INFO *pInfo = (FT1000_INFO *)netdev_priv(dev);
1793 struct timeval tv; //mbelian
1795 DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber);
1796 //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len);
1798 pInfo->stats.rx_bytes = 0; //mbelian
1799 pInfo->stats.tx_bytes = 0; //mbelian
1800 pInfo->stats.rx_packets = 0; //mbelian
1801 pInfo->stats.tx_packets = 0; //mbelian
1802 do_gettimeofday(&tv);
1803 pInfo->ConTm = tv.tv_sec;
1804 pInfo->ProgConStat = 0; //mbelian
1807 netif_start_queue(dev);
1809 //netif_device_attach(dev);
1811 netif_carrier_on(dev); //mbelian
1813 ft1000_submit_rx_urb(pInfo);
1817 //---------------------------------------------------------------------------
1818 // Function: ft1000_close
1821 // net - network device
1826 // Description: close the network driver
1830 //---------------------------------------------------------------------------
1831 int ft1000_close(struct net_device *net)
1833 FT1000_INFO *pInfo = (FT1000_INFO *) netdev_priv (net);
1834 struct ft1000_device *ft1000dev = pInfo->pFt1000Dev;
1836 //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt);
1838 ft1000dev->status |= FT1000_STATUS_CLOSING;
1840 //DEBUG("ft1000_close: calling usb_kill_urb \n");
1841 //usb_kill_urb(ft1000dev->rx_urb);
1842 //usb_kill_urb(ft1000dev->tx_urb);
1845 DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);
1846 netif_carrier_off(net);//mbelian
1847 netif_stop_queue(net);
1848 //DEBUG("ft1000_close: netif_stop_queue called\n");
1849 ft1000dev->status &= ~FT1000_STATUS_CLOSING;
1851 pInfo->ProgConStat = 0xff; //mbelian
1857 static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev)
1859 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev);
1860 //struct ft1000_device *ft1000dev = info->pFt1000Dev;
1862 //return &(ft1000dev->stats);//mbelian
1863 return &(info->stats); //mbelian
1867 /*********************************************************************************
1872 //---------------------------------------------------------------------------
1874 // Function: ft1000_chkcard
1875 // Descripton: This function will check if the device is presently available on
1878 // dev - device structure
1880 // status - FALSE (device is not present)
1881 // TRUE (device is present)
1883 //---------------------------------------------------------------------------
1884 static int ft1000_chkcard (struct ft1000_device *dev) {
1887 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
1889 if (info->fCondResetPend)
1891 DEBUG("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1895 // Mask register is used to check for device presence since it is never
1897 status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK);
1898 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword);
1899 if (tempword == 0) {
1900 DEBUG("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
1904 // The system will return the value of 0xffff for the version register
1905 // if the device is not present.
1906 status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID);
1907 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword);
1908 //pxu if (tempword == 0xffff) {
1909 if (tempword != 0x1b01 ){
1910 dev->status |= FT1000_STATUS_CLOSING; //mbelian
1911 DEBUG("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
1917 //---------------------------------------------------------------------------
1919 // Function: ft1000_hbchk
1920 // Descripton: This function will perform the heart beat check of the DSP as
1921 // well as the ASIC.
1923 // dev - device structure
1927 //---------------------------------------------------------------------------
1928 static void ft1000_hbchk(u_long data)
1930 struct ft1000_device *dev = (struct ft1000_device *)data;
1935 info = (FT1000_INFO *) netdev_priv (dev->net);
1937 DEBUG("ft1000_hbchk called for CardNumber = %d CardReady = %d\n", info->CardNumber, info->CardReady);
1939 if (info->fCondResetPend == 1) {
1940 // Reset ASIC and DSP
1941 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
1942 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
1943 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
1944 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
1946 info->DrvErrNum = DSP_CONDRESET_INFO;
1947 DEBUG("ft1000_hw:DSP conditional reset requested\n");
1948 ft1000_reset_card(dev->net);
1949 info->fCondResetPend = 0;
1950 /* Schedule this module to run every 2 seconds */
1952 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
1953 poll_timer[info->CardNumber].data = (u_long)dev;
1954 add_timer(&poll_timer[info->CardNumber]);
1961 if (info->CardReady == 1) {
1962 // Perform dsp heartbeat check
1963 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX));
1964 DEBUG("ft1000_hw:ft1000_hbchk:hi_ho value = 0x%x\n", tempword);
1965 // Let's perform another check if ho is not detected
1966 if (tempword != ho) {
1967 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword,FT1000_MAG_HI_HO_INDX));
1969 if (tempword != ho) {
1970 printk(KERN_INFO "ft1000: heartbeat failed - no ho detected\n");
1971 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
1972 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
1973 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
1974 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
1975 info->DrvErrNum = DSP_HB_INFO;
1976 if (ft1000_reset_card(dev->net) == 0) {
1977 printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n");
1978 info->ProgConStat = 0xff;
1981 /* Schedule this module to run every 2 seconds */
1982 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
1983 poll_timer[info->CardNumber].data = (u_long)dev;
1984 add_timer(&poll_timer[info->CardNumber]);
1988 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1989 // Let's check doorbell again if fail
1990 if (tempword & FT1000_DB_HB) {
1991 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1993 if (tempword & FT1000_DB_HB) {
1994 printk(KERN_INFO "ft1000: heartbeat doorbell not clear by firmware\n");
1995 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
1996 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
1997 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
1998 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
1999 info->DrvErrNum = DSP_HB_INFO;
2000 if (ft1000_reset_card(dev->net) == 0) {
2001 printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n");
2002 info->ProgConStat = 0xff;
2005 /* Schedule this module to run every 2 seconds */
2006 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2007 poll_timer[info->CardNumber].data = (u_long)dev;
2008 add_timer(&poll_timer[info->CardNumber]);
2012 // Set dedicated area to hi and ring appropriate doorbell according
2013 // to hi/ho heartbeat protocol
2014 ft1000_write_dpram16(dev, FT1000_MAG_HI_HO, hi_mag, FT1000_MAG_HI_HO_INDX);
2016 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX));
2017 // Let's write hi again if fail
2018 if (tempword != hi) {
2019 ft1000_write_dpram16(dev, FT1000_MAG_HI_HO, hi_mag, FT1000_MAG_HI_HO_INDX);
2020 status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX));
2023 if (tempword != hi) {
2024 printk(KERN_INFO "ft1000: heartbeat failed - cannot write hi into DPRAM\n");
2025 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2026 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2027 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2028 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2030 info->DrvErrNum = DSP_HB_INFO;
2031 if (ft1000_reset_card(dev->net) == 0) {
2032 printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n");
2033 info->ProgConStat = 0xff;
2036 /* Schedule this module to run every 2 seconds */
2037 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2038 poll_timer[info->CardNumber].data = (u_long)dev;
2039 add_timer(&poll_timer[info->CardNumber]);
2042 ft1000_write_register(dev, FT1000_DB_HB, FT1000_REG_DOORBELL);
2046 /* Schedule this module to run every 2 seconds */
2047 poll_timer[info->CardNumber].expires = jiffies + (2*HZ);
2048 poll_timer[info->CardNumber].data = (u_long)dev;
2049 add_timer(&poll_timer[info->CardNumber]);
2052 //---------------------------------------------------------------------------
2054 // Function: ft1000_receive_cmd
2055 // Descripton: This function will read a message from the dpram area.
2057 // dev - network device structure
2058 // pbuffer - caller supply address to buffer
2059 // pnxtph - pointer to next pseudo header
2061 // Status = 0 (unsuccessful)
2064 //---------------------------------------------------------------------------
2065 static BOOLEAN ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) {
2071 ret = ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (PUCHAR)&size, FT1000_MAG_PH_LEN_INDX);
2072 size = ntohs(size) + PSEUDOSZ;
2074 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size);
2078 ppseudohdr = (u16 *)pbuffer;
2079 //spin_lock_irqsave (&info->dpram_lock, flags);
2080 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR);
2081 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
2082 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2084 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE+1, FT1000_REG_DPRAM_ADDR);
2085 for (i=0; i<=(size>>2); i++) {
2086 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
2088 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
2091 //copy odd aligned word
2092 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
2093 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2095 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
2096 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
2098 if (size & 0x0001) {
2099 //copy odd byte from fifo
2100 ret = ft1000_read_register(dev, &tempword, FT1000_REG_DPRAM_DATA);
2101 *pbuffer = ntohs(tempword);
2103 //spin_unlock_irqrestore(&info->dpram_lock, flags);
2105 // Check if pseudo header checksum is good
2106 // Calculate pseudo header checksum
2107 tempword = *ppseudohdr++;
2108 for (i=1; i<7; i++) {
2109 tempword ^= *ppseudohdr++;
2111 if ( (tempword != *ppseudohdr) ) {
2117 DEBUG("ft1000_receive_cmd:pbuffer\n");
2118 for(i = 0; i < size; i+=5)
2120 if( (i + 5) < size )
2121 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]);
2124 for (j = i; j < size; j++)
2125 DEBUG("0x%x ", tempbuffer[j]);
2138 static int ft1000_dsp_prov(void *arg)
2140 struct ft1000_device *dev = (struct ft1000_device *)arg;
2141 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
2146 PPSEUDO_HDR ppseudo_hdr;
2149 USHORT TempShortBuf [256];
2151 DEBUG("*** DspProv Entered\n");
2153 while ( list_empty(&info->prov_list) == 0
2154 /*&& !kthread_should_stop() */)
2156 DEBUG("DSP Provisioning List Entry\n");
2158 // Check if doorbell is available
2159 DEBUG("check if doorbell is cleared\n");
2160 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
2163 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n");
2167 while (tempword & FT1000_DB_DPRAM_TX) {
2171 DEBUG("FT1000:ft1000_dsp_prov:message drop\n");
2172 return STATUS_FAILURE;
2174 ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2177 if ( !(tempword & FT1000_DB_DPRAM_TX) ) {
2178 DEBUG("*** Provision Data Sent to DSP\n");
2180 // Send provisioning data
2181 ptr = list_entry(info->prov_list.next, PROV_RECORD, list);
2182 len = *(u16 *)ptr->pprov_data;
2187 pmsg = (PUSHORT)ptr->pprov_data;
2188 ppseudo_hdr = (PPSEUDO_HDR)pmsg;
2189 // Insert slow queue sequence number
2190 ppseudo_hdr->seq_num = info->squeseqnum++;
2191 ppseudo_hdr->portsrc = 0;
2192 // Calculate new checksum
2193 ppseudo_hdr->checksum = *pmsg++;
2194 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
2195 for (i=1; i<7; i++) {
2196 ppseudo_hdr->checksum ^= *pmsg++;
2197 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
2200 TempShortBuf[0] = 0;
2201 TempShortBuf[1] = htons (len);
2202 memcpy(&TempShortBuf[2], ppseudo_hdr, len);
2204 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&TempShortBuf[0], (unsigned short)(len+2));
2205 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
2207 list_del(&ptr->list);
2208 kfree(ptr->pprov_data);
2214 DEBUG("DSP Provisioning List Entry finished\n");
2218 info->fProvComplete = 1;
2219 info->CardReady = 1;
2220 return STATUS_SUCCESS;
2225 static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
2226 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
2229 PMEDIAMSG pmediamsg;
2230 PDSPINITMSG pdspinitmsg;
2233 PPSEUDO_HDR ppseudo_hdr;
2236 //struct timeval tv; //mbelian
2243 char *cmdbuffer = kmalloc(1600, GFP_KERNEL);
2245 return STATUS_FAILURE;
2247 status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size);
2250 //if (ft1000_receive_cmd(dev, &cmdbuffer[0], MAX_CMD_SQSIZE, &tempword))
2254 DEBUG("ft1000_proc_drvmsg:cmdbuffer\n");
2255 for(i = 0; i < size; i+=5)
2257 if( (i + 5) < size )
2258 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]);
2261 for (j = i; j < size; j++)
2262 DEBUG("0x%x ", cmdbuffer[j]);
2268 pdrvmsg = (PDRVMSG)&cmdbuffer[2];
2269 msgtype = ntohs(pdrvmsg->type);
2270 DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype);
2273 DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE");
2275 pmediamsg = (PMEDIAMSG)&cmdbuffer[0];
2276 if (info->ProgConStat != 0xFF) {
2277 if (pmediamsg->state) {
2278 DEBUG("Media is up\n");
2279 if (info->mediastate == 0) {
2280 if ( info->NetDevRegDone )
2282 //netif_carrier_on(dev->net);//mbelian
2283 netif_wake_queue(dev->net);
2285 info->mediastate = 1;
2286 /*do_gettimeofday(&tv);
2287 info->ConTm = tv.tv_sec;*/ //mbelian
2291 DEBUG("Media is down\n");
2292 if (info->mediastate == 1) {
2293 info->mediastate = 0;
2294 if ( info->NetDevRegDone )
2296 //netif_carrier_off(dev->net); mbelian
2297 //netif_stop_queue(dev->net);
2304 DEBUG("Media is down\n");
2305 if (info->mediastate == 1) {
2306 info->mediastate = 0;
2307 if ( info->NetDevRegDone)
2309 //netif_carrier_off(dev->net); //mbelian
2310 //netif_stop_queue(dev->net);
2317 case DSP_INIT_MSG: {
2318 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG");
2320 pdspinitmsg = (PDSPINITMSG)&cmdbuffer[2];
2321 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
2322 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", info->DspVer[0], info->DspVer[1], info->DspVer[2], info->DspVer[3]);
2323 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum, HWSERNUMSZ);
2324 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
2325 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
2326 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]);
2327 dev->net->dev_addr[0] = info->eui64[0];
2328 dev->net->dev_addr[1] = info->eui64[1];
2329 dev->net->dev_addr[2] = info->eui64[2];
2330 dev->net->dev_addr[3] = info->eui64[5];
2331 dev->net->dev_addr[4] = info->eui64[6];
2332 dev->net->dev_addr[5] = info->eui64[7];
2334 if (ntohs(pdspinitmsg->length) == (sizeof(DSPINITMSG) - 20) ) {
2335 memcpy(info->ProductMode, pdspinitmsg->ProductMode, MODESZ);
2336 memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, CALVERSZ);
2337 memcpy(info->RfCalDate, pdspinitmsg->RfCalDate, CALDATESZ);
2338 DEBUG("RFCalVer = 0x%2x 0x%2x\n", info->RfCalVer[0], info->RfCalVer[1]);
2342 case DSP_PROVISION: {
2343 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n");
2345 // kick off dspprov routine to start provisioning
2346 // Send provisioning data to DSP
2347 if (list_empty(&info->prov_list) == 0)
2349 info->fProvComplete = 0;
2350 status = ft1000_dsp_prov(dev);
2351 if (status != STATUS_SUCCESS)
2355 info->fProvComplete = 1;
2356 status = ft1000_write_register (dev, FT1000_DB_HB, FT1000_REG_DOORBELL);
2357 DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n");
2359 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n");
2362 case DSP_STORE_INFO: {
2363 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO");
2365 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
2366 tempword = ntohs(pdrvmsg->length);
2367 info->DSPInfoBlklen = tempword;
2368 if (tempword < (MAX_DSP_SESS_REC-4) ) {
2369 pmsg = (PUSHORT)&pdrvmsg->data[0];
2370 for (i=0; i<((tempword+1)/2); i++) {
2371 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg);
2372 info->DSPInfoBlk[i+10] = *pmsg++;
2376 info->DSPInfoBlklen = 0;
2380 case DSP_GET_INFO: {
2381 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
2382 // copy dsp info block to dsp
2383 info->DrvMsgPend = 1;
2384 // allow any outstanding ioctl to finish
2386 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2387 if (tempword & FT1000_DB_DPRAM_TX) {
2389 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2390 if (tempword & FT1000_DB_DPRAM_TX) {
2392 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2393 if (tempword & FT1000_DB_DPRAM_TX) {
2399 // Put message into Slow Queue
2400 // Form Pseudo header
2401 pmsg = (PUSHORT)info->DSPInfoBlk;
2403 *pmsg++ = htons(info->DSPInfoBlklen+20+info->DSPInfoBlklen);
2404 ppseudo_hdr = (PPSEUDO_HDR)(PUSHORT)&info->DSPInfoBlk[2];
2405 ppseudo_hdr->length = htons(info->DSPInfoBlklen+4+info->DSPInfoBlklen);
2406 ppseudo_hdr->source = 0x10;
2407 ppseudo_hdr->destination = 0x20;
2408 ppseudo_hdr->portdest = 0;
2409 ppseudo_hdr->portsrc = 0;
2410 ppseudo_hdr->sh_str_id = 0;
2411 ppseudo_hdr->control = 0;
2412 ppseudo_hdr->rsvd1 = 0;
2413 ppseudo_hdr->rsvd2 = 0;
2414 ppseudo_hdr->qos_class = 0;
2415 // Insert slow queue sequence number
2416 ppseudo_hdr->seq_num = info->squeseqnum++;
2417 // Insert application id
2418 ppseudo_hdr->portsrc = 0;
2419 // Calculate new checksum
2420 ppseudo_hdr->checksum = *pmsg++;
2421 for (i=1; i<7; i++) {
2422 ppseudo_hdr->checksum ^= *pmsg++;
2424 info->DSPInfoBlk[10] = 0x7200;
2425 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen);
2426 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPInfoBlk[0], (unsigned short)(info->DSPInfoBlklen+22));
2427 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
2428 info->DrvMsgPend = 0;
2433 case GET_DRV_ERR_RPT_MSG: {
2434 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
2435 // copy driver error message to dsp
2436 info->DrvMsgPend = 1;
2437 // allow any outstanding ioctl to finish
2439 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2440 if (tempword & FT1000_DB_DPRAM_TX) {
2442 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2443 if (tempword & FT1000_DB_DPRAM_TX) {
2448 if ( (tempword & FT1000_DB_DPRAM_TX) == 0) {
2449 // Put message into Slow Queue
2450 // Form Pseudo header
2451 pmsg = (PUSHORT)&tempbuffer[0];
2452 ppseudo_hdr = (PPSEUDO_HDR)pmsg;
2453 ppseudo_hdr->length = htons(0x0012);
2454 ppseudo_hdr->source = 0x10;
2455 ppseudo_hdr->destination = 0x20;
2456 ppseudo_hdr->portdest = 0;
2457 ppseudo_hdr->portsrc = 0;
2458 ppseudo_hdr->sh_str_id = 0;
2459 ppseudo_hdr->control = 0;
2460 ppseudo_hdr->rsvd1 = 0;
2461 ppseudo_hdr->rsvd2 = 0;
2462 ppseudo_hdr->qos_class = 0;
2463 // Insert slow queue sequence number
2464 ppseudo_hdr->seq_num = info->squeseqnum++;
2465 // Insert application id
2466 ppseudo_hdr->portsrc = 0;
2467 // Calculate new checksum
2468 ppseudo_hdr->checksum = *pmsg++;
2469 for (i=1; i<7; i++) {
2470 ppseudo_hdr->checksum ^= *pmsg++;
2472 pmsg = (PUSHORT)&tempbuffer[16];
2473 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
2474 *pmsg++ = htons(0x000e);
2475 *pmsg++ = htons(info->DSP_TIME[0]);
2476 *pmsg++ = htons(info->DSP_TIME[1]);
2477 *pmsg++ = htons(info->DSP_TIME[2]);
2478 *pmsg++ = htons(info->DSP_TIME[3]);
2479 convert.byte[0] = info->DspVer[0];
2480 convert.byte[1] = info->DspVer[1];
2481 *pmsg++ = convert.wrd;
2482 convert.byte[0] = info->DspVer[2];
2483 convert.byte[1] = info->DspVer[3];
2484 *pmsg++ = convert.wrd;
2485 *pmsg++ = htons(info->DrvErrNum);
2487 CardSendCommand (dev, (unsigned char*)&tempbuffer[0], (USHORT)(0x0012 + PSEUDOSZ));
2488 info->DrvErrNum = 0;
2490 info->DrvMsgPend = 0;
2501 status = STATUS_SUCCESS;
2504 DEBUG("return from ft1000_proc_drvmsg\n");
2510 int ft1000_poll(void* dev_id) {
2512 //FT1000_INFO *info = (PFT1000_INFO)((struct net_device *)dev_id)->priv;
2513 //struct ft1000_device *dev = (struct ft1000_device *)info->pFt1000Dev;
2514 struct ft1000_device *dev = (struct ft1000_device *)dev_id;
2515 FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net);
2525 PDPRAM_BLK pdpram_blk;
2526 PPSEUDO_HDR ppseudo_hdr;
2527 unsigned long flags;
2529 //DEBUG("Enter ft1000_poll...\n");
2530 if (ft1000_chkcard(dev) == FALSE) {
2531 DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
2532 return STATUS_FAILURE;
2535 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
2536 // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword);
2538 //while ( (tempword) && (!status) ) {
2542 if (tempword & FT1000_DB_DPRAM_RX) {
2543 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n");
2545 status = ft1000_read_dpram16(dev, 0x200, (PUCHAR)&data, 0);
2546 //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data);
2547 size = ntohs(data) + 16 + 2; //wai
2549 modulo = 4 - (size % 4);
2550 size = size + modulo;
2552 status = ft1000_read_dpram16(dev, 0x201, (PUCHAR)&portid, 1);
2554 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid);
2556 if (size < MAX_CMD_SQSIZE) {
2560 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
2562 status = ft1000_proc_drvmsg (dev, size);
2563 if (status != STATUS_SUCCESS )
2567 // This is a dsp broadcast message
2568 // Check which application has registered for dsp broadcast messages
2569 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n");
2571 for (i=0; i<MAX_NUM_APP; i++) {
2572 if ( (info->app_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) &&
2573 (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT) )
2575 //DEBUG("Dsp broadcast message detected for app id %d\n", i);
2576 nxtph = FT1000_DPRAM_RX_BASE + 2;
2577 pdpram_blk = ft1000_get_buffer (&freercvpool);
2578 if (pdpram_blk != NULL) {
2579 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
2580 ppseudo_hdr = (PPSEUDO_HDR)pdpram_blk->pbuffer;
2581 // Put message into the appropriate application block
2582 info->app_info[i].nRxMsg++;
2583 spin_lock_irqsave(&free_buff_lock, flags);
2584 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
2585 info->app_info[i].NumOfMsg++;
2586 spin_unlock_irqrestore(&free_buff_lock, flags);
2587 wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
2590 info->app_info[i].nRxMsgMiss++;
2591 // Put memory back to free pool
2592 ft1000_free_buffer(pdpram_blk, &freercvpool);
2593 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
2597 DEBUG("Out of memory in free receive command pool\n");
2598 info->app_info[i].nRxMsgMiss++;
2599 }//endof if (pdpram_blk != NULL)
2602 // DEBUG("app_info mismatch\n");
2606 pdpram_blk = ft1000_get_buffer (&freercvpool);
2607 //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk);
2608 if (pdpram_blk != NULL) {
2609 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
2610 ppseudo_hdr = (PPSEUDO_HDR)pdpram_blk->pbuffer;
2611 // Search for correct application block
2612 for (i=0; i<MAX_NUM_APP; i++) {
2613 if (info->app_info[i].app_id == ppseudo_hdr->portdest) {
2618 if (i == MAX_NUM_APP) {
2619 DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr->portdest);
2620 // Put memory back to free pool
2621 ft1000_free_buffer(pdpram_blk, &freercvpool);
2624 if (info->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
2625 // Put memory back to free pool
2626 ft1000_free_buffer(pdpram_blk, &freercvpool);
2629 info->app_info[i].nRxMsg++;
2630 // Put message into the appropriate application block
2631 //pxu spin_lock_irqsave(&free_buff_lock, flags);
2632 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
2633 info->app_info[i].NumOfMsg++;
2634 //pxu spin_unlock_irqrestore(&free_buff_lock, flags);
2635 //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
2640 // Put memory back to free pool
2641 ft1000_free_buffer(pdpram_blk, &freercvpool);
2645 DEBUG("Out of memory in free receive command pool\n");
2649 } //endof if (size < MAX_CMD_SQSIZE)
2651 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size);
2653 status = ft1000_write_register (dev, FT1000_DB_DPRAM_RX, FT1000_REG_DOORBELL);
2655 else if (tempword & FT1000_DSP_ASIC_RESET) {
2656 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DSP_ASIC_RESET\n");
2658 // Let's reset the ASIC from the Host side as well
2659 status = ft1000_write_register (dev, ASIC_RESET_BIT, FT1000_REG_RESET);
2660 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
2662 while (tempword & ASIC_RESET_BIT) {
2663 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
2670 DEBUG("Unable to reset ASIC\n");
2671 return STATUS_SUCCESS;
2674 // Program WMARK register
2675 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2676 // clear ASIC reset doorbell
2677 status = ft1000_write_register (dev, FT1000_DSP_ASIC_RESET, FT1000_REG_DOORBELL);
2680 else if (tempword & FT1000_ASIC_RESET_REQ) {
2681 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
2683 // clear ASIC reset request from DSP
2684 status = ft1000_write_register (dev, FT1000_ASIC_RESET_REQ, FT1000_REG_DOORBELL);
2685 status = ft1000_write_register (dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
2686 // copy dsp session record from Adapter block
2687 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPSess.Rec[0], 1024);
2688 // Program WMARK register
2689 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2690 // ring doorbell to tell DSP that ASIC is out of reset
2691 status = ft1000_write_register (dev, FT1000_ASIC_RESET_DSP, FT1000_REG_DOORBELL);
2693 else if (tempword & FT1000_DB_COND_RESET) {
2694 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
2696 // Reset ASIC and DSP
2698 if (info->fAppMsgPend == 0) {
2699 // Reset ASIC and DSP
2701 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2702 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2703 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2704 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2705 info->CardReady = 0;
2706 info->DrvErrNum = DSP_CONDRESET_INFO;
2707 DEBUG("ft1000_hw:DSP conditional reset requested\n");
2708 info->ft1000_reset(dev->net);
2711 info->fProvComplete = 0;
2712 info->fCondResetPend = 1;
2715 ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL);
2718 }//endof if ( !status )
2720 //DEBUG("return from ft1000_poll.\n");
2721 return STATUS_SUCCESS;