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>
20 #define HARLEY_READ_REGISTER 0x0
21 #define HARLEY_WRITE_REGISTER 0x01
22 #define HARLEY_READ_DPRAM_32 0x02
23 #define HARLEY_READ_DPRAM_LOW 0x03
24 #define HARLEY_READ_DPRAM_HIGH 0x04
25 #define HARLEY_WRITE_DPRAM_32 0x05
26 #define HARLEY_WRITE_DPRAM_LOW 0x06
27 #define HARLEY_WRITE_DPRAM_HIGH 0x07
29 #define HARLEY_READ_OPERATION 0xc1
30 #define HARLEY_WRITE_OPERATION 0x41
34 static int ft1000_reset(struct net_device *ft1000dev);
35 static int ft1000_submit_rx_urb(struct ft1000_info *info);
36 static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev);
37 static int ft1000_open (struct net_device *dev);
38 static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev);
39 static int ft1000_chkcard (struct ft1000_device *dev);
43 static u8 tempbuffer[1600];
44 static unsigned long gCardIndex;
46 #define MAX_RCV_LOOP 100
48 /****************************************************************
49 * ft1000_control_complete
50 ****************************************************************/
51 static void ft1000_control_complete(struct urb *urb)
53 struct ft1000_device *ft1000dev = (struct ft1000_device *)urb->context;
55 //DEBUG("FT1000_CONTROL_COMPLETE ENTERED\n");
56 if (ft1000dev == NULL )
58 DEBUG("NULL ft1000dev, failure\n");
61 else if ( ft1000dev->dev == NULL )
63 DEBUG("NULL ft1000dev->dev, failure\n");
67 if(waitqueue_active(&ft1000dev->control_wait))
69 wake_up(&ft1000dev->control_wait);
72 //DEBUG("FT1000_CONTROL_COMPLETE RETURNED\n");
75 //---------------------------------------------------------------------------
76 // Function: ft1000_control
78 // Parameters: ft1000_device - device structure
79 // pipe - usb control message pipe
80 // request - control request
81 // requesttype - control message request type
82 // value - value to be written or 0
83 // index - register index
84 // data - data buffer to hold the read/write values
86 // timeout - control message time out value
88 // Returns: STATUS_SUCCESS - success
89 // STATUS_FAILURE - failure
91 // Description: This function sends a control message via USB interface synchronously
95 //---------------------------------------------------------------------------
96 static int ft1000_control(struct ft1000_device *ft1000dev,unsigned int pipe,
107 if (ft1000dev == NULL )
109 DEBUG("NULL ft1000dev, failure\n");
112 else if ( ft1000dev->dev == NULL )
114 DEBUG("NULL ft1000dev->dev, failure\n");
118 ret = usb_control_msg(ft1000dev->dev,
135 //---------------------------------------------------------------------------
136 // Function: ft1000_read_register
138 // Parameters: ft1000_device - device structure
139 // Data - data buffer to hold the value read
140 // nRegIndex - register index
142 // Returns: STATUS_SUCCESS - success
143 // STATUS_FAILURE - failure
145 // Description: This function returns the value in a register
149 //---------------------------------------------------------------------------
151 u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx)
153 u16 ret = STATUS_SUCCESS;
155 //DEBUG("ft1000_read_register: reg index is %d\n", nRegIndx);
156 //DEBUG("ft1000_read_register: spin_lock locked\n");
157 ret = ft1000_control(ft1000dev,
158 usb_rcvctrlpipe(ft1000dev->dev,0),
159 HARLEY_READ_REGISTER, //request --READ_REGISTER
160 HARLEY_READ_OPERATION, //requestType
165 LARGE_TIMEOUT ); //timeout
167 //DEBUG("ft1000_read_register: ret is %d \n", ret);
169 //DEBUG("ft1000_read_register: data is %x \n", *Data);
175 //---------------------------------------------------------------------------
176 // Function: ft1000_write_register
178 // Parameters: ft1000_device - device structure
179 // value - value to write into a register
180 // nRegIndex - register index
182 // Returns: STATUS_SUCCESS - success
183 // STATUS_FAILURE - failure
185 // Description: This function writes the value in a register
189 //---------------------------------------------------------------------------
190 u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRegIndx)
192 u16 ret = STATUS_SUCCESS;
194 //DEBUG("ft1000_write_register: value is: %d, reg index is: %d\n", value, nRegIndx);
196 ret = ft1000_control(ft1000dev,
197 usb_sndctrlpipe(ft1000dev->dev, 0),
198 HARLEY_WRITE_REGISTER, //request -- WRITE_REGISTER
199 HARLEY_WRITE_OPERATION, //requestType
209 //---------------------------------------------------------------------------
210 // Function: ft1000_read_dpram32
212 // Parameters: ft1000_device - device structure
213 // indx - starting address to read
214 // buffer - data buffer to hold the data read
215 // cnt - number of byte read from DPRAM
217 // Returns: STATUS_SUCCESS - success
218 // STATUS_FAILURE - failure
220 // Description: This function read a number of bytes from DPRAM
224 //---------------------------------------------------------------------------
226 u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt)
228 u16 ret = STATUS_SUCCESS;
230 //DEBUG("ft1000_read_dpram32: indx: %d cnt: %d\n", indx, cnt);
231 ret =ft1000_control(ft1000dev,
232 usb_rcvctrlpipe(ft1000dev->dev,0),
233 HARLEY_READ_DPRAM_32, //request --READ_DPRAM_32
234 HARLEY_READ_OPERATION, //requestType
239 LARGE_TIMEOUT ); //timeout
241 //DEBUG("ft1000_read_dpram32: ret is %d \n", ret);
243 //DEBUG("ft1000_read_dpram32: ret=%d \n", ret);
249 //---------------------------------------------------------------------------
250 // Function: ft1000_write_dpram32
252 // Parameters: ft1000_device - device structure
253 // indx - starting address to write the data
254 // buffer - data buffer to write into DPRAM
255 // cnt - number of bytes to write
257 // Returns: STATUS_SUCCESS - success
258 // STATUS_FAILURE - failure
260 // Description: This function writes into DPRAM a number of bytes
264 //---------------------------------------------------------------------------
265 u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt)
267 u16 ret = STATUS_SUCCESS;
269 //DEBUG("ft1000_write_dpram32: indx: %d buffer: %x cnt: %d\n", indx, buffer, cnt);
271 cnt += cnt - (cnt % 4);
273 ret = ft1000_control(ft1000dev,
274 usb_sndctrlpipe(ft1000dev->dev, 0),
275 HARLEY_WRITE_DPRAM_32, //request -- WRITE_DPRAM_32
276 HARLEY_WRITE_OPERATION, //requestType
286 //---------------------------------------------------------------------------
287 // Function: ft1000_read_dpram16
289 // Parameters: ft1000_device - device structure
290 // indx - starting address to read
291 // buffer - data buffer to hold the data read
292 // hightlow - high or low 16 bit word
294 // Returns: STATUS_SUCCESS - success
295 // STATUS_FAILURE - failure
297 // Description: This function read 16 bits from DPRAM
301 //---------------------------------------------------------------------------
302 u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow)
304 u16 ret = STATUS_SUCCESS;
306 //DEBUG("ft1000_read_dpram16: indx: %d hightlow: %d\n", indx, highlow);
311 request = HARLEY_READ_DPRAM_LOW;
313 request = HARLEY_READ_DPRAM_HIGH;
315 ret = ft1000_control(ft1000dev,
316 usb_rcvctrlpipe(ft1000dev->dev,0),
317 request, //request --READ_DPRAM_H/L
318 HARLEY_READ_OPERATION, //requestType
323 LARGE_TIMEOUT ); //timeout
325 //DEBUG("ft1000_read_dpram16: ret is %d \n", ret);
328 //DEBUG("ft1000_read_dpram16: data is %x \n", *buffer);
334 //---------------------------------------------------------------------------
335 // Function: ft1000_write_dpram16
337 // Parameters: ft1000_device - device structure
338 // indx - starting address to write the data
339 // value - 16bits value to write
340 // hightlow - high or low 16 bit word
342 // Returns: STATUS_SUCCESS - success
343 // STATUS_FAILURE - failure
345 // Description: This function writes into DPRAM a number of bytes
349 //---------------------------------------------------------------------------
350 u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT value, u8 highlow)
352 u16 ret = STATUS_SUCCESS;
356 //DEBUG("ft1000_write_dpram16: indx: %d value: %d highlow: %d\n", indx, value, highlow);
362 request = HARLEY_WRITE_DPRAM_LOW;
364 request = HARLEY_WRITE_DPRAM_HIGH;
366 ret = ft1000_control(ft1000dev,
367 usb_sndctrlpipe(ft1000dev->dev, 0),
368 request, //request -- WRITE_DPRAM_H/L
369 HARLEY_WRITE_OPERATION, //requestType
379 //---------------------------------------------------------------------------
380 // Function: fix_ft1000_read_dpram32
382 // Parameters: ft1000_device - device structure
383 // indx - starting address to read
384 // buffer - data buffer to hold the data read
387 // Returns: STATUS_SUCCESS - success
388 // STATUS_FAILURE - failure
390 // Description: This function read DPRAM 4 words at a time
394 //---------------------------------------------------------------------------
395 u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer)
399 u16 ret = STATUS_SUCCESS;
401 //DEBUG("fix_ft1000_read_dpram32: indx: %d \n", indx);
403 ret = ft1000_read_dpram32(ft1000dev, pos, buf, 16);
404 if (ret == STATUS_SUCCESS)
407 *buffer++ = buf[pos++];
408 *buffer++ = buf[pos++];
409 *buffer++ = buf[pos++];
410 *buffer++ = buf[pos++];
414 DEBUG("fix_ft1000_read_dpram32: DPRAM32 Read failed\n");
422 //DEBUG("fix_ft1000_read_dpram32: data is %x \n", *buffer);
428 //---------------------------------------------------------------------------
429 // Function: fix_ft1000_write_dpram32
431 // Parameters: ft1000_device - device structure
432 // indx - starting address to write
433 // buffer - data buffer to write
436 // Returns: STATUS_SUCCESS - success
437 // STATUS_FAILURE - failure
439 // Description: This function write to DPRAM 4 words at a time
443 //---------------------------------------------------------------------------
444 u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer)
450 UCHAR resultbuffer[32];
452 u16 ret = STATUS_SUCCESS;
454 //DEBUG("fix_ft1000_write_dpram32: Entered:\n");
458 ret = ft1000_read_dpram32(ft1000dev, pos1, buf, 16);
459 if (ret == STATUS_SUCCESS)
462 buf[pos2++] = *buffer++;
463 buf[pos2++] = *buffer++;
464 buf[pos2++] = *buffer++;
465 buf[pos2++] = *buffer++;
466 ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16);
470 DEBUG("fix_ft1000_write_dpram32: DPRAM32 Read failed\n");
475 ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16);
476 if (ret == STATUS_SUCCESS)
481 if (buf[i] != resultbuffer[i]){
483 ret = STATUS_FAILURE;
488 if (ret == STATUS_FAILURE)
490 ret = ft1000_write_dpram32(ft1000dev, pos1, (PUCHAR)&tempbuffer[0], 16);
491 ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16);
492 if (ret == STATUS_SUCCESS)
497 if (tempbuffer[i] != resultbuffer[i])
499 ret = STATUS_FAILURE;
500 DEBUG("fix_ft1000_write_dpram32 Failed to write\n");
511 //------------------------------------------------------------------------
513 // Function: card_reset_dsp
515 // Synopsis: This function is called to reset or activate the DSP
517 // Arguments: value - reset or activate
520 //-----------------------------------------------------------------------
521 static void card_reset_dsp (struct ft1000_device *ft1000dev, BOOLEAN value)
523 u16 status = STATUS_SUCCESS;
526 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
527 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_CTRL);
530 DEBUG("Reset DSP\n");
531 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
532 tempword |= DSP_RESET_BIT;
533 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
537 DEBUG("Activate DSP\n");
538 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
539 tempword |= DSP_ENCRYPTED;
540 tempword &= ~DSP_UNENCRYPTED;
541 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
542 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
543 tempword &= ~EFUSE_MEM_DISABLE;
544 tempword &= ~DSP_RESET_BIT;
545 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
546 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
550 //---------------------------------------------------------------------------
551 // Function: CardSendCommand
553 // Parameters: ft1000_device - device structure
554 // ptempbuffer - command buffer
555 // size - command buffer size
557 // Returns: STATUS_SUCCESS - success
558 // STATUS_FAILURE - failure
560 // Description: This function sends a command to ASIC
564 //---------------------------------------------------------------------------
565 void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size)
568 unsigned char *commandbuf;
570 DEBUG("CardSendCommand: enter CardSendCommand... size=%d\n", size);
572 commandbuf =(unsigned char*) kmalloc(size+2, GFP_KERNEL);
573 memcpy((void*)commandbuf+2, (void*)ptempbuffer, size);
575 //DEBUG("CardSendCommand: Command Send\n");
577 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
584 // check for odd word
588 // Must force to be 32 bit aligned
589 size += 4 - (size % 4);
593 //DEBUG("CardSendCommand: write dpram ... size=%d\n", size);
594 ft1000_write_dpram32(ft1000dev, 0,commandbuf, size);
596 //DEBUG("CardSendCommand: write into doorbell ...\n");
597 ft1000_write_register(ft1000dev, FT1000_DB_DPRAM_TX ,FT1000_REG_DOORBELL) ;
600 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
601 //DEBUG("CardSendCommand: read doorbell ...temp=%x\n", temp);
602 if ( (temp & 0x0100) == 0)
604 //DEBUG("CardSendCommand: Message sent\n");
610 //--------------------------------------------------------------------------
612 // Function: dsp_reload
614 // Synopsis: This function is called to load or reload the DSP
616 // Arguments: ft1000dev - device structure
619 //-----------------------------------------------------------------------
620 int dsp_reload(struct ft1000_device *ft1000dev)
626 struct ft1000_info *pft1000info;
628 pft1000info = netdev_priv(ft1000dev->net);
630 pft1000info->CardReady = 0;
632 // Program Interrupt Mask register
633 status = ft1000_write_register (ft1000dev, 0xffff, FT1000_REG_SUP_IMASK);
635 status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET);
636 tempword |= ASIC_RESET_BIT;
637 status = ft1000_write_register (ft1000dev, tempword, FT1000_REG_RESET);
639 status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET);
640 DEBUG("Reset Register = 0x%x\n", tempword);
643 card_reset_dsp (ft1000dev, 1);
645 card_reset_dsp (ft1000dev, 0);
648 status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
650 // Let's check for FEFE
651 status = ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (PUCHAR)&templong, 4);
652 DEBUG("templong (fefe) = 0x%8x\n", templong);
655 status = scram_dnldr(ft1000dev, pFileStart, FileLength);
657 if (status != STATUS_SUCCESS)
662 DEBUG("dsp_reload returned\n");
667 //---------------------------------------------------------------------------
669 // Function: ft1000_reset_asic
670 // Descripton: This function will call the Card Service function to reset the
673 // dev - device structure
677 //---------------------------------------------------------------------------
678 static void ft1000_reset_asic (struct net_device *dev)
680 struct ft1000_info *info = netdev_priv(dev);
681 struct ft1000_device *ft1000dev = info->pFt1000Dev;
684 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
686 info->ASICResetNum++;
688 // Let's use the register provided by the Magnemite ASIC to reset the
690 ft1000_write_register(ft1000dev, (DSP_RESET_BIT | ASIC_RESET_BIT), FT1000_REG_RESET );
694 // set watermark to -1 in order to not generate an interrrupt
695 ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_MAG_WATERMARK);
698 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR);
699 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword);
700 ft1000_write_register (ft1000dev, tempword, FT1000_REG_SUP_ISR);
701 ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR);
702 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword);
707 //---------------------------------------------------------------------------
709 // Function: ft1000_reset_card
710 // Descripton: This function will reset the card
712 // dev - device structure
714 // status - FALSE (card reset fail)
715 // TRUE (card reset successful)
717 //---------------------------------------------------------------------------
718 static int ft1000_reset_card (struct net_device *dev)
720 struct ft1000_info *info = netdev_priv(dev);
721 struct ft1000_device *ft1000dev = info->pFt1000Dev;
723 struct prov_record *ptr;
725 DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
727 info->fCondResetPend = 1;
729 info->fProvComplete = 0;
731 // Make sure we free any memory reserve for provisioning
732 while (list_empty(&info->prov_list) == 0) {
733 DEBUG("ft1000_hw:ft1000_reset_card:deleting provisioning record\n");
734 ptr = list_entry(info->prov_list.next, struct prov_record, list);
735 list_del(&ptr->list);
736 kfree(ptr->pprov_data);
740 DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n");
742 ft1000_reset_asic(dev);
746 DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n");
747 dsp_reload(ft1000dev);
749 DEBUG("dsp reload successful\n");
754 // Initialize DSP heartbeat area to ho
755 ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag, FT1000_MAG_HI_HO_INDX);
756 ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (PCHAR)&tempword, FT1000_MAG_HI_HO_INDX);
757 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword);
763 info->fCondResetPend = 0;
770 #ifdef HAVE_NET_DEVICE_OPS
771 static const struct net_device_ops ftnet_ops =
773 .ndo_open = &ft1000_open,
774 .ndo_stop = &ft1000_close,
775 .ndo_start_xmit = &ft1000_start_xmit,
776 .ndo_get_stats = &ft1000_netdev_stats,
781 //---------------------------------------------------------------------------
782 // Function: init_ft1000_netdev
784 // Parameters: ft1000dev - device structure
787 // Returns: STATUS_SUCCESS - success
788 // STATUS_FAILURE - failure
790 // Description: This function initialize the network device
794 //---------------------------------------------------------------------------
795 u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
797 struct net_device *netdev;
798 struct ft1000_info *pInfo = NULL;
799 struct dpram_blk *pdpram_blk;
801 struct list_head *cur, *tmp;
804 gCardIndex=0; //mbelian
806 DEBUG("Enter init_ft1000_netdev...\n");
809 netdev = alloc_etherdev(sizeof(struct ft1000_info));
812 DEBUG("init_ft1000_netdev: can not allocate network device\n");
816 pInfo = (struct ft1000_info *) netdev_priv(netdev);
818 //DEBUG("init_ft1000_netdev: gFt1000Info=%x, netdev=%x, ft1000dev=%x\n", gFt1000Info, netdev, ft1000dev);
820 memset(pInfo, 0, sizeof(struct ft1000_info));
822 dev_alloc_name(netdev, netdev->name);
824 //for the first inserted card, decide the card index beginning number, in case there are existing network interfaces
825 if ( gCardIndex == 0 )
827 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name);
829 if ( strncmp(netdev->name,"eth", 3) == 0) {
830 card_nr[0] = netdev->name[3];
832 ret_val = strict_strtoul(card_nr, 10, &gCardIndex);
834 printk(KERN_ERR "Can't parse netdev\n");
838 pInfo->CardNumber = gCardIndex;
839 DEBUG("card number = %d\n", pInfo->CardNumber);
842 printk(KERN_ERR "ft1000: Invalid device name\n");
849 //not the first inserted card, increase card number by 1
850 pInfo->CardNumber = gCardIndex;
851 /*DEBUG("card number = %d\n", pInfo->CardNumber);*/ //mbelian
854 memset(&pInfo->stats, 0, sizeof(struct net_device_stats) );
856 spin_lock_init(&pInfo->dpram_lock);
857 pInfo->pFt1000Dev = ft1000dev;
858 pInfo->DrvErrNum = 0;
859 pInfo->ASICResetNum = 0;
860 pInfo->registered = 1;
861 pInfo->ft1000_reset = ft1000_reset;
862 pInfo->mediastate = 0;
864 pInfo->DeviceCreated = FALSE;
865 pInfo->DeviceMajor = 0;
866 pInfo->CurrentInterruptEnableMask = ISR_DEFAULT_MASK;
867 pInfo->InterruptsEnabled = FALSE;
868 pInfo->CardReady = 0;
869 pInfo->DSP_TIME[0] = 0;
870 pInfo->DSP_TIME[1] = 0;
871 pInfo->DSP_TIME[2] = 0;
872 pInfo->DSP_TIME[3] = 0;
873 pInfo->fAppMsgPend = 0;
874 pInfo->fCondResetPend = 0;
879 pInfo->tempbuf[i] = 0;
882 INIT_LIST_HEAD(&pInfo->prov_list);
885 #ifdef HAVE_NET_DEVICE_OPS
886 netdev->netdev_ops = &ftnet_ops;
888 netdev->hard_start_xmit = &ft1000_start_xmit;
889 netdev->get_stats = &ft1000_netdev_stats;
890 netdev->open = &ft1000_open;
891 netdev->stop = &ft1000_close;
894 ft1000dev->net = netdev;
898 //init free_buff_lock, freercvpool, numofmsgbuf, pdpram_blk
899 //only init once per card
901 DEBUG("Initialize free_buff_lock and freercvpool\n");
902 spin_lock_init(&free_buff_lock);
904 // initialize a list of buffers to be use for queuing up receive command data
905 INIT_LIST_HEAD (&freercvpool);
907 // create list of free buffers
908 for (i=0; i<NUM_OF_FREE_BUFFERS; i++) {
909 // Get memory for DPRAM_DATA link list
910 pdpram_blk = kmalloc(sizeof(struct dpram_blk), GFP_KERNEL);
911 if (pdpram_blk == NULL) {
915 // Get a block of memory to store command data
916 pdpram_blk->pbuffer = kmalloc ( MAX_CMD_SQSIZE, GFP_KERNEL );
917 if (pdpram_blk->pbuffer == NULL) {
922 // link provisioning data
923 list_add_tail (&pdpram_blk->list, &freercvpool);
925 numofmsgbuf = NUM_OF_FREE_BUFFERS;
932 list_for_each_safe(cur, tmp, &freercvpool) {
933 pdpram_blk = list_entry(cur, struct dpram_blk, list);
934 list_del(&pdpram_blk->list);
935 kfree(pdpram_blk->pbuffer);
945 //---------------------------------------------------------------------------
946 // Function: reg_ft1000_netdev
948 // Parameters: ft1000dev - device structure
951 // Returns: STATUS_SUCCESS - success
952 // STATUS_FAILURE - failure
954 // Description: This function register the network driver
958 //---------------------------------------------------------------------------
959 int reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf)
961 struct net_device *netdev;
962 struct ft1000_info *pInfo;
965 netdev = ft1000dev->net;
966 pInfo = netdev_priv(ft1000dev->net);
967 DEBUG("Enter reg_ft1000_netdev...\n");
970 ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID);
972 usb_set_intfdata(intf, pInfo);
973 SET_NETDEV_DEV(netdev, &intf->dev);
975 rc = register_netdev(netdev);
978 DEBUG("reg_ft1000_netdev: could not register network device\n");
984 //Create character device, implemented by Jim
985 ft1000_CreateDevice(ft1000dev);
987 DEBUG ("reg_ft1000_netdev returned\n");
989 pInfo->CardReady = 1;
995 static int ft1000_reset(struct net_device *dev)
997 ft1000_reset_card(dev);
1001 //---------------------------------------------------------------------------
1002 // Function: ft1000_usb_transmit_complete
1004 // Parameters: urb - transmitted usb urb
1009 // Description: This is the callback function when a urb is transmitted
1013 //---------------------------------------------------------------------------
1014 static void ft1000_usb_transmit_complete(struct urb *urb)
1017 struct ft1000_device *ft1000dev = urb->context;
1019 //DEBUG("ft1000_usb_transmit_complete entered\n");
1022 printk("%s: TX status %d\n", ft1000dev->net->name, urb->status);
1024 netif_wake_queue(ft1000dev->net);
1026 //DEBUG("Return from ft1000_usb_transmit_complete\n");
1030 /****************************************************************
1032 ****************************************************************/
1033 static int ft1000_read_fifo_reg(struct ft1000_device *ft1000dev,unsigned int pipe,
1044 DECLARE_WAITQUEUE(wait, current);
1046 struct usb_ctrlrequest *dr;
1049 if (ft1000dev == NULL )
1051 DEBUG("NULL ft1000dev, failure\n");
1052 return STATUS_FAILURE;
1054 else if ( ft1000dev->dev == NULL )
1056 DEBUG("NULL ft1000dev->dev, failure\n");
1057 return STATUS_FAILURE;
1060 spin_lock(&ft1000dev->device_lock);
1064 spin_unlock(&ft1000dev->device_lock);
1068 urb = usb_alloc_urb(0, GFP_KERNEL);
1069 dr = kmalloc(sizeof(struct usb_ctrlrequest), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL);
1075 spin_unlock(&ft1000dev->device_lock);
1081 dr->bRequestType = requesttype;
1082 dr->bRequest = request;
1087 usb_fill_control_urb(urb, ft1000dev->dev, pipe, (char*)dr, (void*)data, size, (void *)ft1000_control_complete, (void*)ft1000dev);
1090 init_waitqueue_head(&ft1000dev->control_wait);
1092 set_current_state(TASK_INTERRUPTIBLE);
1094 add_wait_queue(&ft1000dev->control_wait, &wait);
1099 status = usb_submit_urb(urb, GFP_KERNEL);
1105 remove_wait_queue(&ft1000dev->control_wait, &wait);
1106 spin_unlock(&ft1000dev->device_lock);
1110 if(urb->status == -EINPROGRESS)
1112 while(timeout && urb->status == -EINPROGRESS)
1114 status = timeout = schedule_timeout(timeout);
1122 remove_wait_queue(&ft1000dev->control_wait, &wait);
1126 usb_unlink_urb(urb);
1127 printk("ft1000 timeout\n");
1128 status = -ETIMEDOUT;
1132 status = urb->status;
1136 printk("ft1000 control message failed (urb addr: %p) with error number: %i\n", urb, (int)status);
1138 usb_clear_halt(ft1000dev->dev, usb_rcvctrlpipe(ft1000dev->dev, 0));
1139 usb_clear_halt(ft1000dev->dev, usb_sndctrlpipe(ft1000dev->dev, 0));
1140 usb_unlink_urb(urb);
1148 spin_unlock(&ft1000dev->device_lock);
1154 //---------------------------------------------------------------------------
1155 // Function: ft1000_read_fifo_len
1157 // Parameters: ft1000dev - device structure
1162 // Description: read the fifo length register content
1166 //---------------------------------------------------------------------------
1167 static inline u16 ft1000_read_fifo_len (struct net_device *dev)
1172 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev);
1173 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1174 // 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 *???
1175 DEBUG("ft1000_read_fifo_len: enter ft1000dev %p\n", ft1000dev); //aelias [+] reason: up
1177 ret = STATUS_SUCCESS;
1179 ret = ft1000_read_fifo_reg(ft1000dev,
1180 usb_rcvctrlpipe(ft1000dev->dev,0),
1181 HARLEY_READ_REGISTER,
1182 HARLEY_READ_OPERATION,
1184 FT1000_REG_MAG_UFSR,
1190 ret = STATUS_SUCCESS;
1192 ret = STATUS_FAILURE;
1194 DEBUG("ft1000_read_fifo_len: returned %d\n", temp);
1201 //---------------------------------------------------------------------------
1203 // Function: ft1000_copy_down_pkt
1204 // Descripton: This function will take an ethernet packet and convert it to
1205 // a Flarion packet prior to sending it to the ASIC Downlink
1208 // dev - device structure
1209 // packet - address of ethernet packet
1210 // len - length of IP packet
1215 //---------------------------------------------------------------------------
1216 static int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len)
1218 struct ft1000_info *pInfo = netdev_priv(netdev);
1219 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
1227 if (!pInfo->CardReady)
1230 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
1231 return STATUS_FAILURE;
1236 //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len);
1238 count = sizeof(struct pseudo_hdr) + len;
1239 if(count > MAX_BUF_SIZE)
1241 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n");
1242 DEBUG("size = %d\n", count);
1243 return STATUS_FAILURE;
1247 count = count + (4- (count %4) );
1249 pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]);
1250 *pTemp ++ = ntohs(count);
1257 pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]);
1258 checksum = *pTemp ++;
1261 checksum ^= *pTemp ++;
1263 *pTemp++ = checksum;
1264 memcpy(&(pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)]), packet, len);
1266 netif_stop_queue(netdev);
1268 //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count);
1270 usb_fill_bulk_urb(pFt1000Dev->tx_urb,
1272 usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr),
1275 ft1000_usb_transmit_complete,
1278 t = (u8 *)pFt1000Dev->tx_urb->transfer_buffer;
1279 //DEBUG("transfer_length=%d\n", pFt1000Dev->tx_urb->transfer_buffer_length);
1280 /*for (i=0; i<count; i++ )
1282 DEBUG("%x ", *t++ );
1286 ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC);
1289 DEBUG("ft1000 failed tx_urb %d\n", ret);
1291 return STATUS_FAILURE;
1296 //DEBUG("ft1000 sucess tx_urb %d\n", ret);
1298 pInfo->stats.tx_packets++;
1299 pInfo->stats.tx_bytes += (len+14);
1302 //DEBUG("ft1000_copy_down_pkt() exit\n");
1304 return STATUS_SUCCESS;
1307 //---------------------------------------------------------------------------
1308 // Function: ft1000_start_xmit
1310 // Parameters: skb - socket buffer to be sent
1311 // dev - network device
1316 // Description: transmit a ethernet packet
1320 //---------------------------------------------------------------------------
1321 static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1323 struct ft1000_info *pInfo = netdev_priv(dev);
1324 struct ft1000_device *pFt1000Dev= pInfo->pFt1000Dev;
1329 //DEBUG(" ft1000_start_xmit() entered\n");
1333 DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" );
1334 return STATUS_FAILURE;
1337 if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1339 DEBUG("network driver is closed, return\n");
1341 return STATUS_SUCCESS;
1344 //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len);
1345 pipe = usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr);
1346 maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe));
1347 //DEBUG("ft1000_start_xmit 2: pipe=%d dev->maxpacket = %d\n", pipe, maxlen);
1349 pdata = (u8 *)skb->data;
1350 /*for (i=0; i<skb->len; i++)
1351 DEBUG("skb->data[%d]=%x ", i, *(skb->data+i));
1356 if (pInfo->mediastate == 0)
1358 /* Drop packet is mediastate is down */
1359 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n");
1361 return STATUS_SUCCESS;
1364 if ( (skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE) )
1366 /* Drop packet which has invalid size */
1367 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n");
1369 return STATUS_SUCCESS;
1372 if(ft1000_copy_down_pkt (dev, (pdata+ENET_HEADER_SIZE-2), skb->len - ENET_HEADER_SIZE + 2) == STATUS_FAILURE)
1375 return STATUS_SUCCESS;
1379 //DEBUG(" ft1000_start_xmit() exit\n");
1384 //---------------------------------------------------------------------------
1386 // Function: ft1000_copy_up_pkt
1387 // Descripton: This function will take a packet from the FIFO up link and
1388 // convert it into an ethernet packet and deliver it to the IP stack
1390 // urb - the receving usb urb
1396 //---------------------------------------------------------------------------
1397 static int ft1000_copy_up_pkt (struct urb *urb)
1399 struct ft1000_info *info = urb->context;
1400 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1401 struct net_device *net = ft1000dev->net;
1406 struct sk_buff *skb;
1413 //DEBUG("ft1000_copy_up_pkt entered\n");
1415 if ( ft1000dev->status & FT1000_STATUS_CLOSING)
1417 DEBUG("network driver is closed, return\n");
1418 return STATUS_SUCCESS;
1422 len = urb->transfer_buffer_length;
1423 lena = urb->actual_length; //mbelian
1424 //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n",
1425 // urb->transfer_buffer_length, urb->actual_length);
1427 chksum = (PUSHORT)ft1000dev->rx_buf;
1429 tempword = *chksum++;
1432 tempword ^= *chksum++;
1435 if (tempword != *chksum)
1437 info->stats.rx_errors ++;
1438 ft1000_submit_rx_urb(info);
1439 return STATUS_FAILURE;
1443 //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum);
1445 skb = dev_alloc_skb(len+12+2);
1449 DEBUG("ft1000_copy_up_pkt: No Network buffers available\n");
1450 info->stats.rx_errors++;
1451 ft1000_submit_rx_urb(info);
1452 return STATUS_FAILURE;
1455 pbuffer = (u8 *)skb_put(skb, len+12);
1457 //subtract the number of bytes read already
1461 *pbuffer++ = net->dev_addr[0];
1462 *pbuffer++ = net->dev_addr[1];
1463 *pbuffer++ = net->dev_addr[2];
1464 *pbuffer++ = net->dev_addr[3];
1465 *pbuffer++ = net->dev_addr[4];
1466 *pbuffer++ = net->dev_addr[5];
1477 memcpy(pbuffer, ft1000dev->rx_buf+sizeof(struct pseudo_hdr), len-sizeof(struct pseudo_hdr));
1479 //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n");
1480 /*for (i=0; i<len+12; i++)
1482 DEBUG("ft1000_copy_up_pkt: Protocol Data: 0x%x\n ", *ptemp++);
1487 skb->protocol = eth_type_trans(skb, net);
1488 skb->ip_summed = CHECKSUM_UNNECESSARY;
1491 info->stats.rx_packets++;
1492 // Add on 12 bytes for MAC address which was removed
1493 info->stats.rx_bytes += (lena+12); //mbelian
1495 ft1000_submit_rx_urb(info);
1496 //DEBUG("ft1000_copy_up_pkt exited\n");
1500 //---------------------------------------------------------------------------
1502 // Function: ft1000_submit_rx_urb
1503 // Descripton: the receiving function of the network driver
1506 // info - a private structure contains the device information
1512 //---------------------------------------------------------------------------
1513 static int ft1000_submit_rx_urb(struct ft1000_info *info)
1516 struct ft1000_device *pFt1000Dev = info->pFt1000Dev;
1519 //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb));
1520 if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1522 DEBUG("network driver is closed, return\n");
1523 //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian
1524 return STATUS_SUCCESS;
1527 usb_fill_bulk_urb(pFt1000Dev->rx_urb,
1529 usb_rcvbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_in_endpointAddr),
1532 (usb_complete_t)ft1000_copy_up_pkt,
1536 if((result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC)))
1538 printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result);
1539 return STATUS_FAILURE;
1542 //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result);
1544 return STATUS_SUCCESS;
1547 //---------------------------------------------------------------------------
1548 // Function: ft1000_open
1551 // dev - network device
1556 // Description: open the network driver
1560 //---------------------------------------------------------------------------
1561 static int ft1000_open (struct net_device *dev)
1563 struct ft1000_info *pInfo = (struct ft1000_info *)netdev_priv(dev);
1564 struct timeval tv; //mbelian
1566 DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber);
1567 //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len);
1569 pInfo->stats.rx_bytes = 0; //mbelian
1570 pInfo->stats.tx_bytes = 0; //mbelian
1571 pInfo->stats.rx_packets = 0; //mbelian
1572 pInfo->stats.tx_packets = 0; //mbelian
1573 do_gettimeofday(&tv);
1574 pInfo->ConTm = tv.tv_sec;
1575 pInfo->ProgConStat = 0; //mbelian
1578 netif_start_queue(dev);
1580 netif_carrier_on(dev); //mbelian
1582 ft1000_submit_rx_urb(pInfo);
1586 //---------------------------------------------------------------------------
1587 // Function: ft1000_close
1590 // net - network device
1595 // Description: close the network driver
1599 //---------------------------------------------------------------------------
1600 int ft1000_close(struct net_device *net)
1602 struct ft1000_info *pInfo = (struct ft1000_info *) netdev_priv(net);
1603 struct ft1000_device *ft1000dev = pInfo->pFt1000Dev;
1605 //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt);
1607 ft1000dev->status |= FT1000_STATUS_CLOSING;
1609 //DEBUG("ft1000_close: calling usb_kill_urb \n");
1611 DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);
1612 netif_carrier_off(net);//mbelian
1613 netif_stop_queue(net);
1614 //DEBUG("ft1000_close: netif_stop_queue called\n");
1615 ft1000dev->status &= ~FT1000_STATUS_CLOSING;
1617 pInfo->ProgConStat = 0xff; //mbelian
1623 static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev)
1625 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev);
1627 return &(info->stats); //mbelian
1631 /*********************************************************************************
1636 //---------------------------------------------------------------------------
1638 // Function: ft1000_chkcard
1639 // Descripton: This function will check if the device is presently available on
1642 // dev - device structure
1644 // status - FALSE (device is not present)
1645 // TRUE (device is present)
1647 //---------------------------------------------------------------------------
1648 static int ft1000_chkcard (struct ft1000_device *dev) {
1651 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net);
1653 if (info->fCondResetPend)
1655 DEBUG("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1659 // Mask register is used to check for device presence since it is never
1661 status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK);
1662 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword);
1663 if (tempword == 0) {
1664 DEBUG("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
1668 // The system will return the value of 0xffff for the version register
1669 // if the device is not present.
1670 status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID);
1671 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword);
1672 if (tempword != 0x1b01 ){
1673 dev->status |= FT1000_STATUS_CLOSING; //mbelian
1674 DEBUG("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
1682 //---------------------------------------------------------------------------
1684 // Function: ft1000_receive_cmd
1685 // Descripton: This function will read a message from the dpram area.
1687 // dev - network device structure
1688 // pbuffer - caller supply address to buffer
1689 // pnxtph - pointer to next pseudo header
1691 // Status = 0 (unsuccessful)
1694 //---------------------------------------------------------------------------
1695 static BOOLEAN ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) {
1701 ret = ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (PUCHAR)&size, FT1000_MAG_PH_LEN_INDX);
1702 size = ntohs(size) + PSEUDOSZ;
1704 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size);
1708 ppseudohdr = (u16 *)pbuffer;
1709 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR);
1710 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1711 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1713 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE+1, FT1000_REG_DPRAM_ADDR);
1714 for (i=0; i<=(size>>2); i++) {
1715 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
1717 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1720 //copy odd aligned word
1721 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
1722 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1724 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1725 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1727 if (size & 0x0001) {
1728 //copy odd byte from fifo
1729 ret = ft1000_read_register(dev, &tempword, FT1000_REG_DPRAM_DATA);
1730 *pbuffer = ntohs(tempword);
1733 // Check if pseudo header checksum is good
1734 // Calculate pseudo header checksum
1735 tempword = *ppseudohdr++;
1736 for (i=1; i<7; i++) {
1737 tempword ^= *ppseudohdr++;
1739 if ( (tempword != *ppseudohdr) ) {
1748 static int ft1000_dsp_prov(void *arg)
1750 struct ft1000_device *dev = (struct ft1000_device *)arg;
1751 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net);
1755 struct prov_record *ptr;
1756 struct pseudo_hdr *ppseudo_hdr;
1759 USHORT TempShortBuf [256];
1761 DEBUG("*** DspProv Entered\n");
1763 while (list_empty(&info->prov_list) == 0)
1765 DEBUG("DSP Provisioning List Entry\n");
1767 // Check if doorbell is available
1768 DEBUG("check if doorbell is cleared\n");
1769 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
1772 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n");
1776 while (tempword & FT1000_DB_DPRAM_TX) {
1780 DEBUG("FT1000:ft1000_dsp_prov:message drop\n");
1781 return STATUS_FAILURE;
1783 ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1786 if ( !(tempword & FT1000_DB_DPRAM_TX) ) {
1787 DEBUG("*** Provision Data Sent to DSP\n");
1789 // Send provisioning data
1790 ptr = list_entry(info->prov_list.next, struct prov_record, list);
1791 len = *(u16 *)ptr->pprov_data;
1795 pmsg = (PUSHORT)ptr->pprov_data;
1796 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1797 // Insert slow queue sequence number
1798 ppseudo_hdr->seq_num = info->squeseqnum++;
1799 ppseudo_hdr->portsrc = 0;
1800 // Calculate new checksum
1801 ppseudo_hdr->checksum = *pmsg++;
1802 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
1803 for (i=1; i<7; i++) {
1804 ppseudo_hdr->checksum ^= *pmsg++;
1805 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
1808 TempShortBuf[0] = 0;
1809 TempShortBuf[1] = htons (len);
1810 memcpy(&TempShortBuf[2], ppseudo_hdr, len);
1812 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&TempShortBuf[0], (unsigned short)(len+2));
1813 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
1815 list_del(&ptr->list);
1816 kfree(ptr->pprov_data);
1822 DEBUG("DSP Provisioning List Entry finished\n");
1826 info->fProvComplete = 1;
1827 info->CardReady = 1;
1828 return STATUS_SUCCESS;
1833 static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
1834 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net);
1837 struct media_msg *pmediamsg;
1838 struct dsp_init_msg *pdspinitmsg;
1839 struct drv_msg *pdrvmsg;
1841 struct pseudo_hdr *ppseudo_hdr;
1850 char *cmdbuffer = kmalloc(1600, GFP_KERNEL);
1852 return STATUS_FAILURE;
1854 status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size);
1859 DEBUG("ft1000_proc_drvmsg:cmdbuffer\n");
1860 for(i = 0; i < size; i+=5)
1862 if( (i + 5) < size )
1863 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]);
1866 for (j = i; j < size; j++)
1867 DEBUG("0x%x ", cmdbuffer[j]);
1873 pdrvmsg = (struct drv_msg *)&cmdbuffer[2];
1874 msgtype = ntohs(pdrvmsg->type);
1875 DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype);
1878 DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE");
1880 pmediamsg = (struct media_msg *)&cmdbuffer[0];
1881 if (info->ProgConStat != 0xFF) {
1882 if (pmediamsg->state) {
1883 DEBUG("Media is up\n");
1884 if (info->mediastate == 0) {
1885 if ( info->NetDevRegDone )
1887 //netif_carrier_on(dev->net);//mbelian
1888 netif_wake_queue(dev->net);
1890 info->mediastate = 1;
1891 /*do_gettimeofday(&tv);
1892 info->ConTm = tv.tv_sec;*/ //mbelian
1896 DEBUG("Media is down\n");
1897 if (info->mediastate == 1) {
1898 info->mediastate = 0;
1899 if ( info->NetDevRegDone )
1901 //netif_carrier_off(dev->net); mbelian
1902 //netif_stop_queue(dev->net);
1909 DEBUG("Media is down\n");
1910 if (info->mediastate == 1) {
1911 info->mediastate = 0;
1912 if ( info->NetDevRegDone)
1914 //netif_carrier_off(dev->net); //mbelian
1915 //netif_stop_queue(dev->net);
1922 case DSP_INIT_MSG: {
1923 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG");
1925 pdspinitmsg = (struct dsp_init_msg *)&cmdbuffer[2];
1926 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
1927 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", info->DspVer[0], info->DspVer[1], info->DspVer[2], info->DspVer[3]);
1928 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum, HWSERNUMSZ);
1929 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
1930 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
1931 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]);
1932 dev->net->dev_addr[0] = info->eui64[0];
1933 dev->net->dev_addr[1] = info->eui64[1];
1934 dev->net->dev_addr[2] = info->eui64[2];
1935 dev->net->dev_addr[3] = info->eui64[5];
1936 dev->net->dev_addr[4] = info->eui64[6];
1937 dev->net->dev_addr[5] = info->eui64[7];
1939 if (ntohs(pdspinitmsg->length) == (sizeof(struct dsp_init_msg) - 20)) {
1940 memcpy(info->ProductMode, pdspinitmsg->ProductMode, MODESZ);
1941 memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, CALVERSZ);
1942 memcpy(info->RfCalDate, pdspinitmsg->RfCalDate, CALDATESZ);
1943 DEBUG("RFCalVer = 0x%2x 0x%2x\n", info->RfCalVer[0], info->RfCalVer[1]);
1947 case DSP_PROVISION: {
1948 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n");
1950 // kick off dspprov routine to start provisioning
1951 // Send provisioning data to DSP
1952 if (list_empty(&info->prov_list) == 0)
1954 info->fProvComplete = 0;
1955 status = ft1000_dsp_prov(dev);
1956 if (status != STATUS_SUCCESS)
1960 info->fProvComplete = 1;
1961 status = ft1000_write_register (dev, FT1000_DB_HB, FT1000_REG_DOORBELL);
1962 DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n");
1964 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n");
1967 case DSP_STORE_INFO: {
1968 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO");
1970 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
1971 tempword = ntohs(pdrvmsg->length);
1972 info->DSPInfoBlklen = tempword;
1973 if (tempword < (MAX_DSP_SESS_REC-4) ) {
1974 pmsg = (PUSHORT)&pdrvmsg->data[0];
1975 for (i=0; i<((tempword+1)/2); i++) {
1976 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg);
1977 info->DSPInfoBlk[i+10] = *pmsg++;
1981 info->DSPInfoBlklen = 0;
1985 case DSP_GET_INFO: {
1986 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
1987 // copy dsp info block to dsp
1988 info->DrvMsgPend = 1;
1989 // allow any outstanding ioctl to finish
1991 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1992 if (tempword & FT1000_DB_DPRAM_TX) {
1994 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1995 if (tempword & FT1000_DB_DPRAM_TX) {
1997 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1998 if (tempword & FT1000_DB_DPRAM_TX) {
2004 // Put message into Slow Queue
2005 // Form Pseudo header
2006 pmsg = (PUSHORT)info->DSPInfoBlk;
2008 *pmsg++ = htons(info->DSPInfoBlklen+20+info->DSPInfoBlklen);
2009 ppseudo_hdr = (struct pseudo_hdr *)(PUSHORT)&info->DSPInfoBlk[2];
2010 ppseudo_hdr->length = htons(info->DSPInfoBlklen+4+info->DSPInfoBlklen);
2011 ppseudo_hdr->source = 0x10;
2012 ppseudo_hdr->destination = 0x20;
2013 ppseudo_hdr->portdest = 0;
2014 ppseudo_hdr->portsrc = 0;
2015 ppseudo_hdr->sh_str_id = 0;
2016 ppseudo_hdr->control = 0;
2017 ppseudo_hdr->rsvd1 = 0;
2018 ppseudo_hdr->rsvd2 = 0;
2019 ppseudo_hdr->qos_class = 0;
2020 // Insert slow queue sequence number
2021 ppseudo_hdr->seq_num = info->squeseqnum++;
2022 // Insert application id
2023 ppseudo_hdr->portsrc = 0;
2024 // Calculate new checksum
2025 ppseudo_hdr->checksum = *pmsg++;
2026 for (i=1; i<7; i++) {
2027 ppseudo_hdr->checksum ^= *pmsg++;
2029 info->DSPInfoBlk[10] = 0x7200;
2030 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen);
2031 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPInfoBlk[0], (unsigned short)(info->DSPInfoBlklen+22));
2032 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
2033 info->DrvMsgPend = 0;
2038 case GET_DRV_ERR_RPT_MSG: {
2039 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
2040 // copy driver error message to dsp
2041 info->DrvMsgPend = 1;
2042 // allow any outstanding ioctl to finish
2044 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2045 if (tempword & FT1000_DB_DPRAM_TX) {
2047 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
2048 if (tempword & FT1000_DB_DPRAM_TX) {
2053 if ( (tempword & FT1000_DB_DPRAM_TX) == 0) {
2054 // Put message into Slow Queue
2055 // Form Pseudo header
2056 pmsg = (PUSHORT)&tempbuffer[0];
2057 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
2058 ppseudo_hdr->length = htons(0x0012);
2059 ppseudo_hdr->source = 0x10;
2060 ppseudo_hdr->destination = 0x20;
2061 ppseudo_hdr->portdest = 0;
2062 ppseudo_hdr->portsrc = 0;
2063 ppseudo_hdr->sh_str_id = 0;
2064 ppseudo_hdr->control = 0;
2065 ppseudo_hdr->rsvd1 = 0;
2066 ppseudo_hdr->rsvd2 = 0;
2067 ppseudo_hdr->qos_class = 0;
2068 // Insert slow queue sequence number
2069 ppseudo_hdr->seq_num = info->squeseqnum++;
2070 // Insert application id
2071 ppseudo_hdr->portsrc = 0;
2072 // Calculate new checksum
2073 ppseudo_hdr->checksum = *pmsg++;
2074 for (i=1; i<7; i++) {
2075 ppseudo_hdr->checksum ^= *pmsg++;
2077 pmsg = (PUSHORT)&tempbuffer[16];
2078 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
2079 *pmsg++ = htons(0x000e);
2080 *pmsg++ = htons(info->DSP_TIME[0]);
2081 *pmsg++ = htons(info->DSP_TIME[1]);
2082 *pmsg++ = htons(info->DSP_TIME[2]);
2083 *pmsg++ = htons(info->DSP_TIME[3]);
2084 convert.byte[0] = info->DspVer[0];
2085 convert.byte[1] = info->DspVer[1];
2086 *pmsg++ = convert.wrd;
2087 convert.byte[0] = info->DspVer[2];
2088 convert.byte[1] = info->DspVer[3];
2089 *pmsg++ = convert.wrd;
2090 *pmsg++ = htons(info->DrvErrNum);
2092 CardSendCommand (dev, (unsigned char*)&tempbuffer[0], (USHORT)(0x0012 + PSEUDOSZ));
2093 info->DrvErrNum = 0;
2095 info->DrvMsgPend = 0;
2105 status = STATUS_SUCCESS;
2108 DEBUG("return from ft1000_proc_drvmsg\n");
2114 int ft1000_poll(void* dev_id) {
2116 struct ft1000_device *dev = (struct ft1000_device *)dev_id;
2117 struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net);
2127 struct dpram_blk *pdpram_blk;
2128 struct pseudo_hdr *ppseudo_hdr;
2129 unsigned long flags;
2131 //DEBUG("Enter ft1000_poll...\n");
2132 if (ft1000_chkcard(dev) == FALSE) {
2133 DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
2134 return STATUS_FAILURE;
2137 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
2138 // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword);
2143 if (tempword & FT1000_DB_DPRAM_RX) {
2144 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n");
2146 status = ft1000_read_dpram16(dev, 0x200, (PUCHAR)&data, 0);
2147 //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data);
2148 size = ntohs(data) + 16 + 2; //wai
2150 modulo = 4 - (size % 4);
2151 size = size + modulo;
2153 status = ft1000_read_dpram16(dev, 0x201, (PUCHAR)&portid, 1);
2155 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid);
2157 if (size < MAX_CMD_SQSIZE) {
2161 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
2163 status = ft1000_proc_drvmsg (dev, size);
2164 if (status != STATUS_SUCCESS )
2168 // This is a dsp broadcast message
2169 // Check which application has registered for dsp broadcast messages
2170 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n");
2172 for (i=0; i<MAX_NUM_APP; i++) {
2173 if ( (info->app_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) &&
2174 (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT) )
2176 //DEBUG("Dsp broadcast message detected for app id %d\n", i);
2177 nxtph = FT1000_DPRAM_RX_BASE + 2;
2178 pdpram_blk = ft1000_get_buffer (&freercvpool);
2179 if (pdpram_blk != NULL) {
2180 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
2181 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
2182 // Put message into the appropriate application block
2183 info->app_info[i].nRxMsg++;
2184 spin_lock_irqsave(&free_buff_lock, flags);
2185 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
2186 info->app_info[i].NumOfMsg++;
2187 spin_unlock_irqrestore(&free_buff_lock, flags);
2188 wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
2191 info->app_info[i].nRxMsgMiss++;
2192 // Put memory back to free pool
2193 ft1000_free_buffer(pdpram_blk, &freercvpool);
2194 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
2198 DEBUG("Out of memory in free receive command pool\n");
2199 info->app_info[i].nRxMsgMiss++;
2200 }//endof if (pdpram_blk != NULL)
2203 // DEBUG("app_info mismatch\n");
2207 pdpram_blk = ft1000_get_buffer (&freercvpool);
2208 //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk);
2209 if (pdpram_blk != NULL) {
2210 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
2211 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
2212 // Search for correct application block
2213 for (i=0; i<MAX_NUM_APP; i++) {
2214 if (info->app_info[i].app_id == ppseudo_hdr->portdest) {
2219 if (i == MAX_NUM_APP) {
2220 DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr->portdest);
2221 // Put memory back to free pool
2222 ft1000_free_buffer(pdpram_blk, &freercvpool);
2225 if (info->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
2226 // Put memory back to free pool
2227 ft1000_free_buffer(pdpram_blk, &freercvpool);
2230 info->app_info[i].nRxMsg++;
2231 // Put message into the appropriate application block
2232 //pxu spin_lock_irqsave(&free_buff_lock, flags);
2233 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
2234 info->app_info[i].NumOfMsg++;
2235 //pxu spin_unlock_irqrestore(&free_buff_lock, flags);
2236 //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
2241 // Put memory back to free pool
2242 ft1000_free_buffer(pdpram_blk, &freercvpool);
2246 DEBUG("Out of memory in free receive command pool\n");
2250 } //endof if (size < MAX_CMD_SQSIZE)
2252 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size);
2254 status = ft1000_write_register (dev, FT1000_DB_DPRAM_RX, FT1000_REG_DOORBELL);
2256 else if (tempword & FT1000_DSP_ASIC_RESET) {
2257 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DSP_ASIC_RESET\n");
2259 // Let's reset the ASIC from the Host side as well
2260 status = ft1000_write_register (dev, ASIC_RESET_BIT, FT1000_REG_RESET);
2261 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
2263 while (tempword & ASIC_RESET_BIT) {
2264 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
2271 DEBUG("Unable to reset ASIC\n");
2272 return STATUS_SUCCESS;
2275 // Program WMARK register
2276 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2277 // clear ASIC reset doorbell
2278 status = ft1000_write_register (dev, FT1000_DSP_ASIC_RESET, FT1000_REG_DOORBELL);
2281 else if (tempword & FT1000_ASIC_RESET_REQ) {
2282 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
2284 // clear ASIC reset request from DSP
2285 status = ft1000_write_register (dev, FT1000_ASIC_RESET_REQ, FT1000_REG_DOORBELL);
2286 status = ft1000_write_register (dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
2287 // copy dsp session record from Adapter block
2288 status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPSess.Rec[0], 1024);
2289 // Program WMARK register
2290 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2291 // ring doorbell to tell DSP that ASIC is out of reset
2292 status = ft1000_write_register (dev, FT1000_ASIC_RESET_DSP, FT1000_REG_DOORBELL);
2294 else if (tempword & FT1000_DB_COND_RESET) {
2295 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
2297 // Reset ASIC and DSP
2299 if (info->fAppMsgPend == 0) {
2300 // Reset ASIC and DSP
2302 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2303 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2304 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2305 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2306 info->CardReady = 0;
2307 info->DrvErrNum = DSP_CONDRESET_INFO;
2308 DEBUG("ft1000_hw:DSP conditional reset requested\n");
2309 info->ft1000_reset(dev->net);
2312 info->fProvComplete = 0;
2313 info->fCondResetPend = 1;
2316 ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL);
2319 }//endof if ( !status )
2321 //DEBUG("return from ft1000_poll.\n");
2322 return STATUS_SUCCESS;