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];
45 #define MAX_RCV_LOOP 100
47 //---------------------------------------------------------------------------
48 // Function: ft1000_control
50 // Parameters: ft1000_device - device structure
51 // pipe - usb control message pipe
52 // request - control request
53 // requesttype - control message request type
54 // value - value to be written or 0
55 // index - register index
56 // data - data buffer to hold the read/write values
58 // timeout - control message time out value
60 // Returns: STATUS_SUCCESS - success
61 // STATUS_FAILURE - failure
63 // Description: This function sends a control message via USB interface synchronously
67 //---------------------------------------------------------------------------
68 static int ft1000_control(struct ft1000_device
*ft1000dev
, unsigned int pipe
,
69 u8 request
, u8 requesttype
, u16 value
, u16 index
,
70 void *data
, u16 size
, int timeout
)
74 if ((ft1000dev
== NULL
) || (ft1000dev
->dev
== NULL
)) {
75 DEBUG("ft1000dev or ft1000dev->dev == NULL, failure\n");
79 ret
= usb_control_msg(ft1000dev
->dev
, pipe
, request
, requesttype
,
80 value
, index
, data
, size
, LARGE_TIMEOUT
);
88 //---------------------------------------------------------------------------
89 // Function: ft1000_read_register
91 // Parameters: ft1000_device - device structure
92 // Data - data buffer to hold the value read
93 // nRegIndex - register index
95 // Returns: STATUS_SUCCESS - success
96 // STATUS_FAILURE - failure
98 // Description: This function returns the value in a register
102 //---------------------------------------------------------------------------
104 int ft1000_read_register(struct ft1000_device
*ft1000dev
, u16
* Data
,
107 int ret
= STATUS_SUCCESS
;
109 ret
= ft1000_control(ft1000dev
,
110 usb_rcvctrlpipe(ft1000dev
->dev
, 0),
111 HARLEY_READ_REGISTER
,
112 HARLEY_READ_OPERATION
,
122 //---------------------------------------------------------------------------
123 // Function: ft1000_write_register
125 // Parameters: ft1000_device - device structure
126 // value - value to write into a register
127 // nRegIndex - register index
129 // Returns: STATUS_SUCCESS - success
130 // STATUS_FAILURE - failure
132 // Description: This function writes the value in a register
136 //---------------------------------------------------------------------------
137 int ft1000_write_register(struct ft1000_device
*ft1000dev
, u16 value
,
140 int ret
= STATUS_SUCCESS
;
142 ret
= ft1000_control(ft1000dev
,
143 usb_sndctrlpipe(ft1000dev
->dev
, 0),
144 HARLEY_WRITE_REGISTER
,
145 HARLEY_WRITE_OPERATION
,
155 //---------------------------------------------------------------------------
156 // Function: ft1000_read_dpram32
158 // Parameters: ft1000_device - device structure
159 // indx - starting address to read
160 // buffer - data buffer to hold the data read
161 // cnt - number of byte read from DPRAM
163 // Returns: STATUS_SUCCESS - success
164 // STATUS_FAILURE - failure
166 // Description: This function read a number of bytes from DPRAM
170 //---------------------------------------------------------------------------
172 int ft1000_read_dpram32(struct ft1000_device
*ft1000dev
, u16 indx
, u8
*buffer
,
175 int ret
= STATUS_SUCCESS
;
177 ret
= ft1000_control(ft1000dev
,
178 usb_rcvctrlpipe(ft1000dev
->dev
, 0),
179 HARLEY_READ_DPRAM_32
,
180 HARLEY_READ_OPERATION
,
190 //---------------------------------------------------------------------------
191 // Function: ft1000_write_dpram32
193 // Parameters: ft1000_device - device structure
194 // indx - starting address to write the data
195 // buffer - data buffer to write into DPRAM
196 // cnt - number of bytes to write
198 // Returns: STATUS_SUCCESS - success
199 // STATUS_FAILURE - failure
201 // Description: This function writes into DPRAM a number of bytes
205 //---------------------------------------------------------------------------
206 int ft1000_write_dpram32(struct ft1000_device
*ft1000dev
, u16 indx
, u8
*buffer
,
209 int ret
= STATUS_SUCCESS
;
212 cnt
+= cnt
- (cnt
% 4);
214 ret
= ft1000_control(ft1000dev
,
215 usb_sndctrlpipe(ft1000dev
->dev
, 0),
216 HARLEY_WRITE_DPRAM_32
,
217 HARLEY_WRITE_OPERATION
,
227 //---------------------------------------------------------------------------
228 // Function: ft1000_read_dpram16
230 // Parameters: ft1000_device - device structure
231 // indx - starting address to read
232 // buffer - data buffer to hold the data read
233 // hightlow - high or low 16 bit word
235 // Returns: STATUS_SUCCESS - success
236 // STATUS_FAILURE - failure
238 // Description: This function read 16 bits from DPRAM
242 //---------------------------------------------------------------------------
243 int ft1000_read_dpram16(struct ft1000_device
*ft1000dev
, u16 indx
, u8
*buffer
,
246 int ret
= STATUS_SUCCESS
;
250 request
= HARLEY_READ_DPRAM_LOW
;
252 request
= HARLEY_READ_DPRAM_HIGH
;
254 ret
= ft1000_control(ft1000dev
,
255 usb_rcvctrlpipe(ft1000dev
->dev
, 0),
257 HARLEY_READ_OPERATION
,
267 //---------------------------------------------------------------------------
268 // Function: ft1000_write_dpram16
270 // Parameters: ft1000_device - device structure
271 // indx - starting address to write the data
272 // value - 16bits value to write
273 // hightlow - high or low 16 bit word
275 // Returns: STATUS_SUCCESS - success
276 // STATUS_FAILURE - failure
278 // Description: This function writes into DPRAM a number of bytes
282 //---------------------------------------------------------------------------
283 int ft1000_write_dpram16(struct ft1000_device
*ft1000dev
, u16 indx
, u16 value
, u8 highlow
)
285 int ret
= STATUS_SUCCESS
;
289 request
= HARLEY_WRITE_DPRAM_LOW
;
291 request
= HARLEY_WRITE_DPRAM_HIGH
;
293 ret
= ft1000_control(ft1000dev
,
294 usb_sndctrlpipe(ft1000dev
->dev
, 0),
296 HARLEY_WRITE_OPERATION
,
306 //---------------------------------------------------------------------------
307 // Function: fix_ft1000_read_dpram32
309 // Parameters: ft1000_device - device structure
310 // indx - starting address to read
311 // buffer - data buffer to hold the data read
314 // Returns: STATUS_SUCCESS - success
315 // STATUS_FAILURE - failure
317 // Description: This function read DPRAM 4 words at a time
321 //---------------------------------------------------------------------------
322 int fix_ft1000_read_dpram32(struct ft1000_device
*ft1000dev
, u16 indx
,
327 int ret
= STATUS_SUCCESS
;
329 pos
= (indx
/ 4) * 4;
330 ret
= ft1000_read_dpram32(ft1000dev
, pos
, buf
, 16);
332 if (ret
== STATUS_SUCCESS
) {
333 pos
= (indx
% 4) * 4;
334 *buffer
++ = buf
[pos
++];
335 *buffer
++ = buf
[pos
++];
336 *buffer
++ = buf
[pos
++];
337 *buffer
++ = buf
[pos
++];
339 DEBUG("fix_ft1000_read_dpram32: DPRAM32 Read failed\n");
350 //---------------------------------------------------------------------------
351 // Function: fix_ft1000_write_dpram32
353 // Parameters: ft1000_device - device structure
354 // indx - starting address to write
355 // buffer - data buffer to write
358 // Returns: STATUS_SUCCESS - success
359 // STATUS_FAILURE - failure
361 // Description: This function write to DPRAM 4 words at a time
365 //---------------------------------------------------------------------------
366 int fix_ft1000_write_dpram32(struct ft1000_device
*ft1000dev
, u16 indx
, u8
*buffer
)
374 int ret
= STATUS_SUCCESS
;
376 pos1
= (indx
/ 4) * 4;
378 ret
= ft1000_read_dpram32(ft1000dev
, pos1
, buf
, 16);
380 if (ret
== STATUS_SUCCESS
) {
382 buf
[pos2
++] = *buffer
++;
383 buf
[pos2
++] = *buffer
++;
384 buf
[pos2
++] = *buffer
++;
385 buf
[pos2
++] = *buffer
++;
386 ret
= ft1000_write_dpram32(ft1000dev
, pos1
, buf
, 16);
388 DEBUG("fix_ft1000_write_dpram32: DPRAM32 Read failed\n");
392 ret
= ft1000_read_dpram32(ft1000dev
, pos1
, (u8
*)&resultbuffer
[0], 16);
394 if (ret
== STATUS_SUCCESS
) {
396 for (i
= 0; i
< 16; i
++) {
397 if (buf
[i
] != resultbuffer
[i
])
398 ret
= STATUS_FAILURE
;
402 if (ret
== STATUS_FAILURE
) {
403 ret
= ft1000_write_dpram32(ft1000dev
, pos1
,
404 (u8
*)&tempbuffer
[0], 16);
405 ret
= ft1000_read_dpram32(ft1000dev
, pos1
,
406 (u8
*)&resultbuffer
[0], 16);
407 if (ret
== STATUS_SUCCESS
) {
409 for (i
= 0; i
< 16; i
++) {
410 if (tempbuffer
[i
] != resultbuffer
[i
]) {
411 ret
= STATUS_FAILURE
;
412 DEBUG("%s Failed to write\n",
423 //------------------------------------------------------------------------
425 // Function: card_reset_dsp
427 // Synopsis: This function is called to reset or activate the DSP
429 // Arguments: value - reset or activate
432 //-----------------------------------------------------------------------
433 static void card_reset_dsp(struct ft1000_device
*ft1000dev
, bool value
)
435 u16 status
= STATUS_SUCCESS
;
438 status
= ft1000_write_register(ft1000dev
, HOST_INTF_BE
,
439 FT1000_REG_SUP_CTRL
);
440 status
= ft1000_read_register(ft1000dev
, &tempword
,
441 FT1000_REG_SUP_CTRL
);
444 DEBUG("Reset DSP\n");
445 status
= ft1000_read_register(ft1000dev
, &tempword
,
447 tempword
|= DSP_RESET_BIT
;
448 status
= ft1000_write_register(ft1000dev
, tempword
,
451 DEBUG("Activate DSP\n");
452 status
= ft1000_read_register(ft1000dev
, &tempword
,
454 tempword
|= DSP_ENCRYPTED
;
455 tempword
&= ~DSP_UNENCRYPTED
;
456 status
= ft1000_write_register(ft1000dev
, tempword
,
458 status
= ft1000_read_register(ft1000dev
, &tempword
,
460 tempword
&= ~EFUSE_MEM_DISABLE
;
461 tempword
&= ~DSP_RESET_BIT
;
462 status
= ft1000_write_register(ft1000dev
, tempword
,
464 status
= ft1000_read_register(ft1000dev
, &tempword
,
469 //---------------------------------------------------------------------------
470 // Function: card_send_command
472 // Parameters: ft1000_device - device structure
473 // ptempbuffer - command buffer
474 // size - command buffer size
476 // Returns: STATUS_SUCCESS - success
477 // STATUS_FAILURE - failure
479 // Description: This function sends a command to ASIC
483 //---------------------------------------------------------------------------
484 void card_send_command(struct ft1000_device
*ft1000dev
, void *ptempbuffer
, int size
)
487 unsigned char *commandbuf
;
489 DEBUG("card_send_command: enter card_send_command... size=%d\n", size
);
491 commandbuf
=(unsigned char*) kmalloc(size
+2, GFP_KERNEL
);
492 memcpy((void*)commandbuf
+2, (void*)ptempbuffer
, size
);
494 //DEBUG("card_send_command: Command Send\n");
496 ft1000_read_register(ft1000dev
, &temp
, FT1000_REG_DOORBELL
);
503 // check for odd word
507 // Must force to be 32 bit aligned
508 size
+= 4 - (size
% 4);
512 //DEBUG("card_send_command: write dpram ... size=%d\n", size);
513 ft1000_write_dpram32(ft1000dev
, 0,commandbuf
, size
);
515 //DEBUG("card_send_command: write into doorbell ...\n");
516 ft1000_write_register(ft1000dev
, FT1000_DB_DPRAM_TX
,FT1000_REG_DOORBELL
) ;
519 ft1000_read_register(ft1000dev
, &temp
, FT1000_REG_DOORBELL
);
520 //DEBUG("card_send_command: read doorbell ...temp=%x\n", temp);
521 if ( (temp
& 0x0100) == 0)
523 //DEBUG("card_send_command: Message sent\n");
529 //--------------------------------------------------------------------------
531 // Function: dsp_reload
533 // Synopsis: This function is called to load or reload the DSP
535 // Arguments: ft1000dev - device structure
538 //-----------------------------------------------------------------------
539 int dsp_reload(struct ft1000_device
*ft1000dev
)
545 struct ft1000_info
*pft1000info
;
547 pft1000info
= netdev_priv(ft1000dev
->net
);
549 pft1000info
->CardReady
= 0;
551 // Program Interrupt Mask register
552 status
= ft1000_write_register (ft1000dev
, 0xffff, FT1000_REG_SUP_IMASK
);
554 status
= ft1000_read_register (ft1000dev
, &tempword
, FT1000_REG_RESET
);
555 tempword
|= ASIC_RESET_BIT
;
556 status
= ft1000_write_register (ft1000dev
, tempword
, FT1000_REG_RESET
);
558 status
= ft1000_read_register (ft1000dev
, &tempword
, FT1000_REG_RESET
);
559 DEBUG("Reset Register = 0x%x\n", tempword
);
562 card_reset_dsp (ft1000dev
, 1);
564 card_reset_dsp (ft1000dev
, 0);
567 status
= ft1000_write_register (ft1000dev
, HOST_INTF_BE
, FT1000_REG_SUP_CTRL
);
569 // Let's check for FEFE
570 status
= ft1000_read_dpram32 (ft1000dev
, FT1000_MAG_DPRAM_FEFE_INDX
, (u8
*)&templong
, 4);
571 DEBUG("templong (fefe) = 0x%8x\n", templong
);
574 status
= scram_dnldr(ft1000dev
, pFileStart
, FileLength
);
576 if (status
!= STATUS_SUCCESS
)
581 DEBUG("dsp_reload returned\n");
586 //---------------------------------------------------------------------------
588 // Function: ft1000_reset_asic
589 // Descripton: This function will call the Card Service function to reset the
592 // dev - device structure
596 //---------------------------------------------------------------------------
597 static void ft1000_reset_asic (struct net_device
*dev
)
599 struct ft1000_info
*info
= netdev_priv(dev
);
600 struct ft1000_device
*ft1000dev
= info
->pFt1000Dev
;
603 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
605 info
->ASICResetNum
++;
607 // Let's use the register provided by the Magnemite ASIC to reset the
609 ft1000_write_register(ft1000dev
, (DSP_RESET_BIT
| ASIC_RESET_BIT
), FT1000_REG_RESET
);
613 // set watermark to -1 in order to not generate an interrrupt
614 ft1000_write_register(ft1000dev
, 0xffff, FT1000_REG_MAG_WATERMARK
);
617 ft1000_read_register (ft1000dev
, &tempword
, FT1000_REG_SUP_ISR
);
618 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword
);
619 ft1000_write_register (ft1000dev
, tempword
, FT1000_REG_SUP_ISR
);
620 ft1000_read_register (ft1000dev
, &tempword
, FT1000_REG_SUP_ISR
);
621 DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword
);
626 //---------------------------------------------------------------------------
628 // Function: ft1000_reset_card
629 // Descripton: This function will reset the card
631 // dev - device structure
633 // status - FALSE (card reset fail)
634 // TRUE (card reset successful)
636 //---------------------------------------------------------------------------
637 static int ft1000_reset_card (struct net_device
*dev
)
639 struct ft1000_info
*info
= netdev_priv(dev
);
640 struct ft1000_device
*ft1000dev
= info
->pFt1000Dev
;
642 struct prov_record
*ptr
;
644 DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
646 info
->fCondResetPend
= 1;
648 info
->fProvComplete
= 0;
650 // Make sure we free any memory reserve for provisioning
651 while (list_empty(&info
->prov_list
) == 0) {
652 DEBUG("ft1000_hw:ft1000_reset_card:deleting provisioning record\n");
653 ptr
= list_entry(info
->prov_list
.next
, struct prov_record
, list
);
654 list_del(&ptr
->list
);
655 kfree(ptr
->pprov_data
);
659 DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n");
661 ft1000_reset_asic(dev
);
665 DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n");
666 dsp_reload(ft1000dev
);
668 DEBUG("dsp reload successful\n");
673 // Initialize DSP heartbeat area to ho
674 ft1000_write_dpram16(ft1000dev
, FT1000_MAG_HI_HO
, ho_mag
, FT1000_MAG_HI_HO_INDX
);
675 ft1000_read_dpram16(ft1000dev
, FT1000_MAG_HI_HO
, (u8
*)&tempword
, FT1000_MAG_HI_HO_INDX
);
676 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword
);
682 info
->fCondResetPend
= 0;
689 #ifdef HAVE_NET_DEVICE_OPS
690 static const struct net_device_ops ftnet_ops
=
692 .ndo_open
= &ft1000_open
,
693 .ndo_stop
= &ft1000_close
,
694 .ndo_start_xmit
= &ft1000_start_xmit
,
695 .ndo_get_stats
= &ft1000_netdev_stats
,
700 //---------------------------------------------------------------------------
701 // Function: init_ft1000_netdev
703 // Parameters: ft1000dev - device structure
706 // Returns: STATUS_SUCCESS - success
707 // STATUS_FAILURE - failure
709 // Description: This function initialize the network device
713 //---------------------------------------------------------------------------
714 u16
init_ft1000_netdev(struct ft1000_device
*ft1000dev
)
716 struct net_device
*netdev
;
717 struct ft1000_info
*pInfo
= NULL
;
718 struct dpram_blk
*pdpram_blk
;
720 struct list_head
*cur
, *tmp
;
722 unsigned long gCardIndex
= 0;
724 DEBUG("Enter init_ft1000_netdev...\n");
727 netdev
= alloc_etherdev(sizeof(struct ft1000_info
));
730 DEBUG("init_ft1000_netdev: can not allocate network device\n");
734 pInfo
= netdev_priv(netdev
);
736 //DEBUG("init_ft1000_netdev: gFt1000Info=%x, netdev=%x, ft1000dev=%x\n", gFt1000Info, netdev, ft1000dev);
738 memset(pInfo
, 0, sizeof(struct ft1000_info
));
740 dev_alloc_name(netdev
, netdev
->name
);
742 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev
->name
);
744 if ( strncmp(netdev
->name
,"eth", 3) == 0) {
745 card_nr
[0] = netdev
->name
[3];
747 ret_val
= strict_strtoul(card_nr
, 10, &gCardIndex
);
749 printk(KERN_ERR
"Can't parse netdev\n");
753 pInfo
->CardNumber
= gCardIndex
;
754 DEBUG("card number = %d\n", pInfo
->CardNumber
);
757 printk(KERN_ERR
"ft1000: Invalid device name\n");
762 memset(&pInfo
->stats
, 0, sizeof(struct net_device_stats
) );
764 spin_lock_init(&pInfo
->dpram_lock
);
765 pInfo
->pFt1000Dev
= ft1000dev
;
766 pInfo
->DrvErrNum
= 0;
767 pInfo
->ASICResetNum
= 0;
768 pInfo
->registered
= 1;
769 pInfo
->ft1000_reset
= ft1000_reset
;
770 pInfo
->mediastate
= 0;
772 pInfo
->DeviceCreated
= FALSE
;
773 pInfo
->CurrentInterruptEnableMask
= ISR_DEFAULT_MASK
;
774 pInfo
->InterruptsEnabled
= FALSE
;
775 pInfo
->CardReady
= 0;
776 pInfo
->DSP_TIME
[0] = 0;
777 pInfo
->DSP_TIME
[1] = 0;
778 pInfo
->DSP_TIME
[2] = 0;
779 pInfo
->DSP_TIME
[3] = 0;
780 pInfo
->fAppMsgPend
= 0;
781 pInfo
->fCondResetPend
= 0;
784 memset(&pInfo
->tempbuf
[0], 0, sizeof(pInfo
->tempbuf
));
786 INIT_LIST_HEAD(&pInfo
->prov_list
);
788 INIT_LIST_HEAD(&pInfo
->nodes
.list
);
790 #ifdef HAVE_NET_DEVICE_OPS
791 netdev
->netdev_ops
= &ftnet_ops
;
793 netdev
->hard_start_xmit
= &ft1000_start_xmit
;
794 netdev
->get_stats
= &ft1000_netdev_stats
;
795 netdev
->open
= &ft1000_open
;
796 netdev
->stop
= &ft1000_close
;
799 ft1000dev
->net
= netdev
;
803 //init free_buff_lock, freercvpool, numofmsgbuf, pdpram_blk
804 //only init once per card
806 DEBUG("Initialize free_buff_lock and freercvpool\n");
807 spin_lock_init(&free_buff_lock
);
809 // initialize a list of buffers to be use for queuing up receive command data
810 INIT_LIST_HEAD (&freercvpool
);
812 // create list of free buffers
813 for (i
=0; i
<NUM_OF_FREE_BUFFERS
; i
++) {
814 // Get memory for DPRAM_DATA link list
815 pdpram_blk
= kmalloc(sizeof(struct dpram_blk
), GFP_KERNEL
);
816 if (pdpram_blk
== NULL
) {
820 // Get a block of memory to store command data
821 pdpram_blk
->pbuffer
= kmalloc ( MAX_CMD_SQSIZE
, GFP_KERNEL
);
822 if (pdpram_blk
->pbuffer
== NULL
) {
827 // link provisioning data
828 list_add_tail (&pdpram_blk
->list
, &freercvpool
);
830 numofmsgbuf
= NUM_OF_FREE_BUFFERS
;
837 list_for_each_safe(cur
, tmp
, &freercvpool
) {
838 pdpram_blk
= list_entry(cur
, struct dpram_blk
, list
);
839 list_del(&pdpram_blk
->list
);
840 kfree(pdpram_blk
->pbuffer
);
850 //---------------------------------------------------------------------------
851 // Function: reg_ft1000_netdev
853 // Parameters: ft1000dev - device structure
856 // Returns: STATUS_SUCCESS - success
857 // STATUS_FAILURE - failure
859 // Description: This function register the network driver
863 //---------------------------------------------------------------------------
864 int reg_ft1000_netdev(struct ft1000_device
*ft1000dev
, struct usb_interface
*intf
)
866 struct net_device
*netdev
;
867 struct ft1000_info
*pInfo
;
870 netdev
= ft1000dev
->net
;
871 pInfo
= netdev_priv(ft1000dev
->net
);
872 DEBUG("Enter reg_ft1000_netdev...\n");
875 ft1000_read_register(ft1000dev
, &pInfo
->AsicID
, FT1000_REG_ASIC_ID
);
877 usb_set_intfdata(intf
, pInfo
);
878 SET_NETDEV_DEV(netdev
, &intf
->dev
);
880 rc
= register_netdev(netdev
);
883 DEBUG("reg_ft1000_netdev: could not register network device\n");
889 //Create character device, implemented by Jim
890 ft1000_create_dev(ft1000dev
);
892 DEBUG ("reg_ft1000_netdev returned\n");
894 pInfo
->CardReady
= 1;
900 static int ft1000_reset(struct net_device
*dev
)
902 ft1000_reset_card(dev
);
906 //---------------------------------------------------------------------------
907 // Function: ft1000_usb_transmit_complete
909 // Parameters: urb - transmitted usb urb
914 // Description: This is the callback function when a urb is transmitted
918 //---------------------------------------------------------------------------
919 static void ft1000_usb_transmit_complete(struct urb
*urb
)
922 struct ft1000_device
*ft1000dev
= urb
->context
;
924 //DEBUG("ft1000_usb_transmit_complete entered\n");
927 printk("%s: TX status %d\n", ft1000dev
->net
->name
, urb
->status
);
929 netif_wake_queue(ft1000dev
->net
);
931 //DEBUG("Return from ft1000_usb_transmit_complete\n");
934 //---------------------------------------------------------------------------
936 // Function: ft1000_copy_down_pkt
937 // Descripton: This function will take an ethernet packet and convert it to
938 // a Flarion packet prior to sending it to the ASIC Downlink
941 // dev - device structure
942 // packet - address of ethernet packet
943 // len - length of IP packet
948 //---------------------------------------------------------------------------
949 static int ft1000_copy_down_pkt (struct net_device
*netdev
, u8
*packet
, u16 len
)
951 struct ft1000_info
*pInfo
= netdev_priv(netdev
);
952 struct ft1000_device
*pFt1000Dev
= pInfo
->pFt1000Dev
;
957 struct pseudo_hdr hdr
;
959 if (!pInfo
->CardReady
)
962 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
968 //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len);
970 count
= sizeof(struct pseudo_hdr
) + len
;
971 if(count
> MAX_BUF_SIZE
)
973 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n");
974 DEBUG("size = %d\n", count
);
979 count
= count
+ (4- (count
%4) );
981 memset(&hdr
, 0, sizeof(struct pseudo_hdr
));
983 hdr
.length
= ntohs(count
);
985 hdr
.destination
= 0x20;
988 hdr
.sh_str_id
= 0x91;
991 hdr
.checksum
= hdr
.length
^ hdr
.source
^ hdr
.destination
^
992 hdr
.portdest
^ hdr
.portsrc
^ hdr
.sh_str_id
^
995 memcpy(&pFt1000Dev
->tx_buf
[0], &hdr
, sizeof(hdr
));
996 memcpy(&(pFt1000Dev
->tx_buf
[sizeof(struct pseudo_hdr
)]), packet
, len
);
998 netif_stop_queue(netdev
);
1000 //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count);
1002 usb_fill_bulk_urb(pFt1000Dev
->tx_urb
,
1004 usb_sndbulkpipe(pFt1000Dev
->dev
, pFt1000Dev
->bulk_out_endpointAddr
),
1007 ft1000_usb_transmit_complete
,
1010 t
= (u8
*)pFt1000Dev
->tx_urb
->transfer_buffer
;
1011 //DEBUG("transfer_length=%d\n", pFt1000Dev->tx_urb->transfer_buffer_length);
1012 /*for (i=0; i<count; i++ )
1014 DEBUG("%x ", *t++ );
1018 ret
= usb_submit_urb(pFt1000Dev
->tx_urb
, GFP_ATOMIC
);
1020 DEBUG("ft1000 failed tx_urb %d\n", ret
);
1023 pInfo
->stats
.tx_packets
++;
1024 pInfo
->stats
.tx_bytes
+= (len
+14);
1027 //DEBUG("ft1000_copy_down_pkt() exit\n");
1032 //---------------------------------------------------------------------------
1033 // Function: ft1000_start_xmit
1035 // Parameters: skb - socket buffer to be sent
1036 // dev - network device
1041 // Description: transmit a ethernet packet
1045 //---------------------------------------------------------------------------
1046 static int ft1000_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1048 struct ft1000_info
*pInfo
= netdev_priv(dev
);
1049 struct ft1000_device
*pFt1000Dev
= pInfo
->pFt1000Dev
;
1054 //DEBUG(" ft1000_start_xmit() entered\n");
1058 DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" );
1059 return NETDEV_TX_OK
;
1062 if ( pFt1000Dev
->status
& FT1000_STATUS_CLOSING
)
1064 DEBUG("network driver is closed, return\n");
1068 //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len);
1069 pipe
= usb_sndbulkpipe(pFt1000Dev
->dev
, pFt1000Dev
->bulk_out_endpointAddr
);
1070 maxlen
= usb_maxpacket(pFt1000Dev
->dev
, pipe
, usb_pipeout(pipe
));
1071 //DEBUG("ft1000_start_xmit 2: pipe=%d dev->maxpacket = %d\n", pipe, maxlen);
1073 pdata
= (u8
*)skb
->data
;
1074 /*for (i=0; i<skb->len; i++)
1075 DEBUG("skb->data[%d]=%x ", i, *(skb->data+i));
1080 if (pInfo
->mediastate
== 0)
1082 /* Drop packet is mediastate is down */
1083 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n");
1087 if ( (skb
->len
< ENET_HEADER_SIZE
) || (skb
->len
> ENET_MAX_SIZE
) )
1089 /* Drop packet which has invalid size */
1090 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n");
1094 ft1000_copy_down_pkt(dev
, (pdata
+ENET_HEADER_SIZE
-2),
1095 skb
->len
- ENET_HEADER_SIZE
+ 2);
1099 //DEBUG(" ft1000_start_xmit() exit\n");
1101 return NETDEV_TX_OK
;
1104 //---------------------------------------------------------------------------
1106 // Function: ft1000_copy_up_pkt
1107 // Descripton: This function will take a packet from the FIFO up link and
1108 // convert it into an ethernet packet and deliver it to the IP stack
1110 // urb - the receving usb urb
1116 //---------------------------------------------------------------------------
1117 static int ft1000_copy_up_pkt (struct urb
*urb
)
1119 struct ft1000_info
*info
= urb
->context
;
1120 struct ft1000_device
*ft1000dev
= info
->pFt1000Dev
;
1121 struct net_device
*net
= ft1000dev
->net
;
1126 struct sk_buff
*skb
;
1133 //DEBUG("ft1000_copy_up_pkt entered\n");
1135 if ( ft1000dev
->status
& FT1000_STATUS_CLOSING
)
1137 DEBUG("network driver is closed, return\n");
1138 return STATUS_SUCCESS
;
1142 len
= urb
->transfer_buffer_length
;
1143 lena
= urb
->actual_length
; //mbelian
1144 //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n",
1145 // urb->transfer_buffer_length, urb->actual_length);
1147 chksum
= (u16
*)ft1000dev
->rx_buf
;
1149 tempword
= *chksum
++;
1152 tempword
^= *chksum
++;
1155 if (tempword
!= *chksum
)
1157 info
->stats
.rx_errors
++;
1158 ft1000_submit_rx_urb(info
);
1159 return STATUS_FAILURE
;
1163 //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum);
1165 skb
= dev_alloc_skb(len
+12+2);
1169 DEBUG("ft1000_copy_up_pkt: No Network buffers available\n");
1170 info
->stats
.rx_errors
++;
1171 ft1000_submit_rx_urb(info
);
1172 return STATUS_FAILURE
;
1175 pbuffer
= (u8
*)skb_put(skb
, len
+12);
1177 //subtract the number of bytes read already
1181 *pbuffer
++ = net
->dev_addr
[0];
1182 *pbuffer
++ = net
->dev_addr
[1];
1183 *pbuffer
++ = net
->dev_addr
[2];
1184 *pbuffer
++ = net
->dev_addr
[3];
1185 *pbuffer
++ = net
->dev_addr
[4];
1186 *pbuffer
++ = net
->dev_addr
[5];
1197 memcpy(pbuffer
, ft1000dev
->rx_buf
+sizeof(struct pseudo_hdr
), len
-sizeof(struct pseudo_hdr
));
1199 //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n");
1200 /*for (i=0; i<len+12; i++)
1202 DEBUG("ft1000_copy_up_pkt: Protocol Data: 0x%x\n ", *ptemp++);
1207 skb
->protocol
= eth_type_trans(skb
, net
);
1208 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1211 info
->stats
.rx_packets
++;
1212 // Add on 12 bytes for MAC address which was removed
1213 info
->stats
.rx_bytes
+= (lena
+12); //mbelian
1215 ft1000_submit_rx_urb(info
);
1216 //DEBUG("ft1000_copy_up_pkt exited\n");
1220 //---------------------------------------------------------------------------
1222 // Function: ft1000_submit_rx_urb
1223 // Descripton: the receiving function of the network driver
1226 // info - a private structure contains the device information
1232 //---------------------------------------------------------------------------
1233 static int ft1000_submit_rx_urb(struct ft1000_info
*info
)
1236 struct ft1000_device
*pFt1000Dev
= info
->pFt1000Dev
;
1239 //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb));
1240 if ( pFt1000Dev
->status
& FT1000_STATUS_CLOSING
)
1242 DEBUG("network driver is closed, return\n");
1243 //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian
1247 usb_fill_bulk_urb(pFt1000Dev
->rx_urb
,
1249 usb_rcvbulkpipe(pFt1000Dev
->dev
, pFt1000Dev
->bulk_in_endpointAddr
),
1252 (usb_complete_t
)ft1000_copy_up_pkt
,
1256 if((result
= usb_submit_urb(pFt1000Dev
->rx_urb
, GFP_ATOMIC
)))
1258 printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result
);
1262 //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result);
1267 //---------------------------------------------------------------------------
1268 // Function: ft1000_open
1271 // dev - network device
1276 // Description: open the network driver
1280 //---------------------------------------------------------------------------
1281 static int ft1000_open (struct net_device
*dev
)
1283 struct ft1000_info
*pInfo
= netdev_priv(dev
);
1284 struct timeval tv
; //mbelian
1287 DEBUG("ft1000_open is called for card %d\n", pInfo
->CardNumber
);
1288 //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len);
1290 pInfo
->stats
.rx_bytes
= 0; //mbelian
1291 pInfo
->stats
.tx_bytes
= 0; //mbelian
1292 pInfo
->stats
.rx_packets
= 0; //mbelian
1293 pInfo
->stats
.tx_packets
= 0; //mbelian
1294 do_gettimeofday(&tv
);
1295 pInfo
->ConTm
= tv
.tv_sec
;
1296 pInfo
->ProgConStat
= 0; //mbelian
1299 netif_start_queue(dev
);
1301 netif_carrier_on(dev
); //mbelian
1303 ret
= ft1000_submit_rx_urb(pInfo
);
1308 //---------------------------------------------------------------------------
1309 // Function: ft1000_close
1312 // net - network device
1317 // Description: close the network driver
1321 //---------------------------------------------------------------------------
1322 int ft1000_close(struct net_device
*net
)
1324 struct ft1000_info
*pInfo
= netdev_priv(net
);
1325 struct ft1000_device
*ft1000dev
= pInfo
->pFt1000Dev
;
1327 //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt);
1329 ft1000dev
->status
|= FT1000_STATUS_CLOSING
;
1331 //DEBUG("ft1000_close: calling usb_kill_urb \n");
1333 DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo
, ft1000dev
);
1334 netif_carrier_off(net
);//mbelian
1335 netif_stop_queue(net
);
1336 //DEBUG("ft1000_close: netif_stop_queue called\n");
1337 ft1000dev
->status
&= ~FT1000_STATUS_CLOSING
;
1339 pInfo
->ProgConStat
= 0xff; //mbelian
1345 static struct net_device_stats
*ft1000_netdev_stats(struct net_device
*dev
)
1347 struct ft1000_info
*info
= netdev_priv(dev
);
1349 return &(info
->stats
); //mbelian
1353 /*********************************************************************************
1358 //---------------------------------------------------------------------------
1360 // Function: ft1000_chkcard
1361 // Descripton: This function will check if the device is presently available on
1364 // dev - device structure
1366 // status - FALSE (device is not present)
1367 // TRUE (device is present)
1369 //---------------------------------------------------------------------------
1370 static int ft1000_chkcard (struct ft1000_device
*dev
) {
1373 struct ft1000_info
*info
= netdev_priv(dev
->net
);
1375 if (info
->fCondResetPend
)
1377 DEBUG("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1381 // Mask register is used to check for device presence since it is never
1383 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_SUP_IMASK
);
1384 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword);
1385 if (tempword
== 0) {
1386 DEBUG("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
1390 // The system will return the value of 0xffff for the version register
1391 // if the device is not present.
1392 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_ASIC_ID
);
1393 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword);
1394 if (tempword
!= 0x1b01 ){
1395 dev
->status
|= FT1000_STATUS_CLOSING
; //mbelian
1396 DEBUG("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
1404 //---------------------------------------------------------------------------
1406 // Function: ft1000_receive_cmd
1407 // Descripton: This function will read a message from the dpram area.
1409 // dev - network device structure
1410 // pbuffer - caller supply address to buffer
1411 // pnxtph - pointer to next pseudo header
1413 // Status = 0 (unsuccessful)
1416 //---------------------------------------------------------------------------
1417 static bool ft1000_receive_cmd (struct ft1000_device
*dev
, u16
*pbuffer
, int maxsz
, u16
*pnxtph
) {
1423 ret
= ft1000_read_dpram16(dev
, FT1000_MAG_PH_LEN
, (u8
*)&size
, FT1000_MAG_PH_LEN_INDX
);
1424 size
= ntohs(size
) + PSEUDOSZ
;
1426 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size
);
1430 ppseudohdr
= (u16
*)pbuffer
;
1431 ft1000_write_register(dev
, FT1000_DPRAM_MAG_RX_BASE
, FT1000_REG_DPRAM_ADDR
);
1432 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAH
);
1433 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1435 ft1000_write_register(dev
, FT1000_DPRAM_MAG_RX_BASE
+1, FT1000_REG_DPRAM_ADDR
);
1436 for (i
=0; i
<=(size
>>2); i
++) {
1437 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAL
);
1439 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAH
);
1442 //copy odd aligned word
1443 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAL
);
1444 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1446 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAH
);
1447 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1449 if (size
& 0x0001) {
1450 //copy odd byte from fifo
1451 ret
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DPRAM_DATA
);
1452 *pbuffer
= ntohs(tempword
);
1455 // Check if pseudo header checksum is good
1456 // Calculate pseudo header checksum
1457 tempword
= *ppseudohdr
++;
1458 for (i
=1; i
<7; i
++) {
1459 tempword
^= *ppseudohdr
++;
1461 if ( (tempword
!= *ppseudohdr
) ) {
1470 static int ft1000_dsp_prov(void *arg
)
1472 struct ft1000_device
*dev
= (struct ft1000_device
*)arg
;
1473 struct ft1000_info
*info
= netdev_priv(dev
->net
);
1477 struct prov_record
*ptr
;
1478 struct pseudo_hdr
*ppseudo_hdr
;
1481 u16 TempShortBuf
[256];
1483 DEBUG("*** DspProv Entered\n");
1485 while (list_empty(&info
->prov_list
) == 0)
1487 DEBUG("DSP Provisioning List Entry\n");
1489 // Check if doorbell is available
1490 DEBUG("check if doorbell is cleared\n");
1491 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_DOORBELL
);
1494 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n");
1498 while (tempword
& FT1000_DB_DPRAM_TX
) {
1502 DEBUG("FT1000:ft1000_dsp_prov:message drop\n");
1503 return STATUS_FAILURE
;
1505 ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1508 if ( !(tempword
& FT1000_DB_DPRAM_TX
) ) {
1509 DEBUG("*** Provision Data Sent to DSP\n");
1511 // Send provisioning data
1512 ptr
= list_entry(info
->prov_list
.next
, struct prov_record
, list
);
1513 len
= *(u16
*)ptr
->pprov_data
;
1517 pmsg
= (u16
*)ptr
->pprov_data
;
1518 ppseudo_hdr
= (struct pseudo_hdr
*)pmsg
;
1519 // Insert slow queue sequence number
1520 ppseudo_hdr
->seq_num
= info
->squeseqnum
++;
1521 ppseudo_hdr
->portsrc
= 0;
1522 // Calculate new checksum
1523 ppseudo_hdr
->checksum
= *pmsg
++;
1524 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
1525 for (i
=1; i
<7; i
++) {
1526 ppseudo_hdr
->checksum
^= *pmsg
++;
1527 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
1530 TempShortBuf
[0] = 0;
1531 TempShortBuf
[1] = htons (len
);
1532 memcpy(&TempShortBuf
[2], ppseudo_hdr
, len
);
1534 status
= ft1000_write_dpram32 (dev
, 0, (u8
*)&TempShortBuf
[0], (unsigned short)(len
+2));
1535 status
= ft1000_write_register (dev
, FT1000_DB_DPRAM_TX
, FT1000_REG_DOORBELL
);
1537 list_del(&ptr
->list
);
1538 kfree(ptr
->pprov_data
);
1544 DEBUG("DSP Provisioning List Entry finished\n");
1548 info
->fProvComplete
= 1;
1549 info
->CardReady
= 1;
1550 return STATUS_SUCCESS
;
1555 static int ft1000_proc_drvmsg (struct ft1000_device
*dev
, u16 size
) {
1556 struct ft1000_info
*info
= netdev_priv(dev
->net
);
1559 struct media_msg
*pmediamsg
;
1560 struct dsp_init_msg
*pdspinitmsg
;
1561 struct drv_msg
*pdrvmsg
;
1563 struct pseudo_hdr
*ppseudo_hdr
;
1572 char *cmdbuffer
= kmalloc(1600, GFP_KERNEL
);
1574 return STATUS_FAILURE
;
1576 status
= ft1000_read_dpram32(dev
, 0x200, cmdbuffer
, size
);
1581 DEBUG("ft1000_proc_drvmsg:cmdbuffer\n");
1582 for(i
= 0; i
< size
; i
+=5)
1584 if( (i
+ 5) < size
)
1585 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]);
1588 for (j
= i
; j
< size
; j
++)
1589 DEBUG("0x%x ", cmdbuffer
[j
]);
1595 pdrvmsg
= (struct drv_msg
*)&cmdbuffer
[2];
1596 msgtype
= ntohs(pdrvmsg
->type
);
1597 DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype
);
1600 DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE");
1602 pmediamsg
= (struct media_msg
*)&cmdbuffer
[0];
1603 if (info
->ProgConStat
!= 0xFF) {
1604 if (pmediamsg
->state
) {
1605 DEBUG("Media is up\n");
1606 if (info
->mediastate
== 0) {
1607 if ( info
->NetDevRegDone
)
1609 //netif_carrier_on(dev->net);//mbelian
1610 netif_wake_queue(dev
->net
);
1612 info
->mediastate
= 1;
1613 /*do_gettimeofday(&tv);
1614 info->ConTm = tv.tv_sec;*/ //mbelian
1618 DEBUG("Media is down\n");
1619 if (info
->mediastate
== 1) {
1620 info
->mediastate
= 0;
1621 if ( info
->NetDevRegDone
)
1623 //netif_carrier_off(dev->net); mbelian
1624 //netif_stop_queue(dev->net);
1631 DEBUG("Media is down\n");
1632 if (info
->mediastate
== 1) {
1633 info
->mediastate
= 0;
1634 if ( info
->NetDevRegDone
)
1636 //netif_carrier_off(dev->net); //mbelian
1637 //netif_stop_queue(dev->net);
1644 case DSP_INIT_MSG
: {
1645 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG");
1647 pdspinitmsg
= (struct dsp_init_msg
*)&cmdbuffer
[2];
1648 memcpy(info
->DspVer
, pdspinitmsg
->DspVer
, DSPVERSZ
);
1649 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", info
->DspVer
[0], info
->DspVer
[1], info
->DspVer
[2], info
->DspVer
[3]);
1650 memcpy(info
->HwSerNum
, pdspinitmsg
->HwSerNum
, HWSERNUMSZ
);
1651 memcpy(info
->Sku
, pdspinitmsg
->Sku
, SKUSZ
);
1652 memcpy(info
->eui64
, pdspinitmsg
->eui64
, EUISZ
);
1653 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]);
1654 dev
->net
->dev_addr
[0] = info
->eui64
[0];
1655 dev
->net
->dev_addr
[1] = info
->eui64
[1];
1656 dev
->net
->dev_addr
[2] = info
->eui64
[2];
1657 dev
->net
->dev_addr
[3] = info
->eui64
[5];
1658 dev
->net
->dev_addr
[4] = info
->eui64
[6];
1659 dev
->net
->dev_addr
[5] = info
->eui64
[7];
1661 if (ntohs(pdspinitmsg
->length
) == (sizeof(struct dsp_init_msg
) - 20)) {
1662 memcpy(info
->ProductMode
, pdspinitmsg
->ProductMode
, MODESZ
);
1663 memcpy(info
->RfCalVer
, pdspinitmsg
->RfCalVer
, CALVERSZ
);
1664 memcpy(info
->RfCalDate
, pdspinitmsg
->RfCalDate
, CALDATESZ
);
1665 DEBUG("RFCalVer = 0x%2x 0x%2x\n", info
->RfCalVer
[0], info
->RfCalVer
[1]);
1669 case DSP_PROVISION
: {
1670 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n");
1672 // kick off dspprov routine to start provisioning
1673 // Send provisioning data to DSP
1674 if (list_empty(&info
->prov_list
) == 0)
1676 info
->fProvComplete
= 0;
1677 status
= ft1000_dsp_prov(dev
);
1678 if (status
!= STATUS_SUCCESS
)
1682 info
->fProvComplete
= 1;
1683 status
= ft1000_write_register (dev
, FT1000_DB_HB
, FT1000_REG_DOORBELL
);
1684 DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n");
1686 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n");
1689 case DSP_STORE_INFO
: {
1690 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO");
1692 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
1693 tempword
= ntohs(pdrvmsg
->length
);
1694 info
->DSPInfoBlklen
= tempword
;
1695 if (tempword
< (MAX_DSP_SESS_REC
-4) ) {
1696 pmsg
= (u16
*)&pdrvmsg
->data
[0];
1697 for (i
=0; i
<((tempword
+1)/2); i
++) {
1698 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg
);
1699 info
->DSPInfoBlk
[i
+10] = *pmsg
++;
1703 info
->DSPInfoBlklen
= 0;
1707 case DSP_GET_INFO
: {
1708 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
1709 // copy dsp info block to dsp
1710 info
->DrvMsgPend
= 1;
1711 // allow any outstanding ioctl to finish
1713 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1714 if (tempword
& FT1000_DB_DPRAM_TX
) {
1716 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1717 if (tempword
& FT1000_DB_DPRAM_TX
) {
1719 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1720 if (tempword
& FT1000_DB_DPRAM_TX
) {
1726 // Put message into Slow Queue
1727 // Form Pseudo header
1728 pmsg
= (u16
*)info
->DSPInfoBlk
;
1730 *pmsg
++ = htons(info
->DSPInfoBlklen
+20+info
->DSPInfoBlklen
);
1731 ppseudo_hdr
= (struct pseudo_hdr
*)(u16
*)&info
->DSPInfoBlk
[2];
1732 ppseudo_hdr
->length
= htons(info
->DSPInfoBlklen
+4+info
->DSPInfoBlklen
);
1733 ppseudo_hdr
->source
= 0x10;
1734 ppseudo_hdr
->destination
= 0x20;
1735 ppseudo_hdr
->portdest
= 0;
1736 ppseudo_hdr
->portsrc
= 0;
1737 ppseudo_hdr
->sh_str_id
= 0;
1738 ppseudo_hdr
->control
= 0;
1739 ppseudo_hdr
->rsvd1
= 0;
1740 ppseudo_hdr
->rsvd2
= 0;
1741 ppseudo_hdr
->qos_class
= 0;
1742 // Insert slow queue sequence number
1743 ppseudo_hdr
->seq_num
= info
->squeseqnum
++;
1744 // Insert application id
1745 ppseudo_hdr
->portsrc
= 0;
1746 // Calculate new checksum
1747 ppseudo_hdr
->checksum
= *pmsg
++;
1748 for (i
=1; i
<7; i
++) {
1749 ppseudo_hdr
->checksum
^= *pmsg
++;
1751 info
->DSPInfoBlk
[10] = 0x7200;
1752 info
->DSPInfoBlk
[11] = htons(info
->DSPInfoBlklen
);
1753 status
= ft1000_write_dpram32 (dev
, 0, (u8
*)&info
->DSPInfoBlk
[0], (unsigned short)(info
->DSPInfoBlklen
+22));
1754 status
= ft1000_write_register (dev
, FT1000_DB_DPRAM_TX
, FT1000_REG_DOORBELL
);
1755 info
->DrvMsgPend
= 0;
1760 case GET_DRV_ERR_RPT_MSG
: {
1761 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
1762 // copy driver error message to dsp
1763 info
->DrvMsgPend
= 1;
1764 // allow any outstanding ioctl to finish
1766 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1767 if (tempword
& FT1000_DB_DPRAM_TX
) {
1769 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1770 if (tempword
& FT1000_DB_DPRAM_TX
) {
1775 if ( (tempword
& FT1000_DB_DPRAM_TX
) == 0) {
1776 // Put message into Slow Queue
1777 // Form Pseudo header
1778 pmsg
= (u16
*)&tempbuffer
[0];
1779 ppseudo_hdr
= (struct pseudo_hdr
*)pmsg
;
1780 ppseudo_hdr
->length
= htons(0x0012);
1781 ppseudo_hdr
->source
= 0x10;
1782 ppseudo_hdr
->destination
= 0x20;
1783 ppseudo_hdr
->portdest
= 0;
1784 ppseudo_hdr
->portsrc
= 0;
1785 ppseudo_hdr
->sh_str_id
= 0;
1786 ppseudo_hdr
->control
= 0;
1787 ppseudo_hdr
->rsvd1
= 0;
1788 ppseudo_hdr
->rsvd2
= 0;
1789 ppseudo_hdr
->qos_class
= 0;
1790 // Insert slow queue sequence number
1791 ppseudo_hdr
->seq_num
= info
->squeseqnum
++;
1792 // Insert application id
1793 ppseudo_hdr
->portsrc
= 0;
1794 // Calculate new checksum
1795 ppseudo_hdr
->checksum
= *pmsg
++;
1796 for (i
=1; i
<7; i
++) {
1797 ppseudo_hdr
->checksum
^= *pmsg
++;
1799 pmsg
= (u16
*)&tempbuffer
[16];
1800 *pmsg
++ = htons(RSP_DRV_ERR_RPT_MSG
);
1801 *pmsg
++ = htons(0x000e);
1802 *pmsg
++ = htons(info
->DSP_TIME
[0]);
1803 *pmsg
++ = htons(info
->DSP_TIME
[1]);
1804 *pmsg
++ = htons(info
->DSP_TIME
[2]);
1805 *pmsg
++ = htons(info
->DSP_TIME
[3]);
1806 convert
.byte
[0] = info
->DspVer
[0];
1807 convert
.byte
[1] = info
->DspVer
[1];
1808 *pmsg
++ = convert
.wrd
;
1809 convert
.byte
[0] = info
->DspVer
[2];
1810 convert
.byte
[1] = info
->DspVer
[3];
1811 *pmsg
++ = convert
.wrd
;
1812 *pmsg
++ = htons(info
->DrvErrNum
);
1814 card_send_command (dev
, (unsigned char*)&tempbuffer
[0], (u16
)(0x0012 + PSEUDOSZ
));
1815 info
->DrvErrNum
= 0;
1817 info
->DrvMsgPend
= 0;
1827 status
= STATUS_SUCCESS
;
1830 DEBUG("return from ft1000_proc_drvmsg\n");
1836 int ft1000_poll(void* dev_id
) {
1838 struct ft1000_device
*dev
= (struct ft1000_device
*)dev_id
;
1839 struct ft1000_info
*info
= netdev_priv(dev
->net
);
1849 struct dpram_blk
*pdpram_blk
;
1850 struct pseudo_hdr
*ppseudo_hdr
;
1851 unsigned long flags
;
1853 //DEBUG("Enter ft1000_poll...\n");
1854 if (ft1000_chkcard(dev
) == FALSE
) {
1855 DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
1856 return STATUS_FAILURE
;
1859 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_DOORBELL
);
1860 // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword);
1865 if (tempword
& FT1000_DB_DPRAM_RX
) {
1866 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n");
1868 status
= ft1000_read_dpram16(dev
, 0x200, (u8
*)&data
, 0);
1869 //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data);
1870 size
= ntohs(data
) + 16 + 2; //wai
1872 modulo
= 4 - (size
% 4);
1873 size
= size
+ modulo
;
1875 status
= ft1000_read_dpram16(dev
, 0x201, (u8
*)&portid
, 1);
1877 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid);
1879 if (size
< MAX_CMD_SQSIZE
) {
1883 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
1885 status
= ft1000_proc_drvmsg (dev
, size
);
1886 if (status
!= STATUS_SUCCESS
)
1890 // This is a dsp broadcast message
1891 // Check which application has registered for dsp broadcast messages
1892 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n");
1894 for (i
=0; i
<MAX_NUM_APP
; i
++) {
1895 if ( (info
->app_info
[i
].DspBCMsgFlag
) && (info
->app_info
[i
].fileobject
) &&
1896 (info
->app_info
[i
].NumOfMsg
< MAX_MSG_LIMIT
) )
1898 //DEBUG("Dsp broadcast message detected for app id %d\n", i);
1899 nxtph
= FT1000_DPRAM_RX_BASE
+ 2;
1900 pdpram_blk
= ft1000_get_buffer (&freercvpool
);
1901 if (pdpram_blk
!= NULL
) {
1902 if ( ft1000_receive_cmd(dev
, pdpram_blk
->pbuffer
, MAX_CMD_SQSIZE
, &nxtph
) ) {
1903 ppseudo_hdr
= (struct pseudo_hdr
*)pdpram_blk
->pbuffer
;
1904 // Put message into the appropriate application block
1905 info
->app_info
[i
].nRxMsg
++;
1906 spin_lock_irqsave(&free_buff_lock
, flags
);
1907 list_add_tail(&pdpram_blk
->list
, &info
->app_info
[i
].app_sqlist
);
1908 info
->app_info
[i
].NumOfMsg
++;
1909 spin_unlock_irqrestore(&free_buff_lock
, flags
);
1910 wake_up_interruptible(&info
->app_info
[i
].wait_dpram_msg
);
1913 info
->app_info
[i
].nRxMsgMiss
++;
1914 // Put memory back to free pool
1915 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
1916 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
1920 DEBUG("Out of memory in free receive command pool\n");
1921 info
->app_info
[i
].nRxMsgMiss
++;
1922 }//endof if (pdpram_blk != NULL)
1925 // DEBUG("app_info mismatch\n");
1929 pdpram_blk
= ft1000_get_buffer (&freercvpool
);
1930 //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk);
1931 if (pdpram_blk
!= NULL
) {
1932 if ( ft1000_receive_cmd(dev
, pdpram_blk
->pbuffer
, MAX_CMD_SQSIZE
, &nxtph
) ) {
1933 ppseudo_hdr
= (struct pseudo_hdr
*)pdpram_blk
->pbuffer
;
1934 // Search for correct application block
1935 for (i
=0; i
<MAX_NUM_APP
; i
++) {
1936 if (info
->app_info
[i
].app_id
== ppseudo_hdr
->portdest
) {
1941 if (i
== MAX_NUM_APP
) {
1942 DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr
->portdest
);
1943 // Put memory back to free pool
1944 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
1947 if (info
->app_info
[i
].NumOfMsg
> MAX_MSG_LIMIT
) {
1948 // Put memory back to free pool
1949 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
1952 info
->app_info
[i
].nRxMsg
++;
1953 // Put message into the appropriate application block
1954 //pxu spin_lock_irqsave(&free_buff_lock, flags);
1955 list_add_tail(&pdpram_blk
->list
, &info
->app_info
[i
].app_sqlist
);
1956 info
->app_info
[i
].NumOfMsg
++;
1957 //pxu spin_unlock_irqrestore(&free_buff_lock, flags);
1958 //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
1963 // Put memory back to free pool
1964 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
1968 DEBUG("Out of memory in free receive command pool\n");
1972 } //endof if (size < MAX_CMD_SQSIZE)
1974 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size
);
1976 status
= ft1000_write_register (dev
, FT1000_DB_DPRAM_RX
, FT1000_REG_DOORBELL
);
1978 else if (tempword
& FT1000_DSP_ASIC_RESET
) {
1979 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DSP_ASIC_RESET\n");
1981 // Let's reset the ASIC from the Host side as well
1982 status
= ft1000_write_register (dev
, ASIC_RESET_BIT
, FT1000_REG_RESET
);
1983 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_RESET
);
1985 while (tempword
& ASIC_RESET_BIT
) {
1986 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_RESET
);
1993 DEBUG("Unable to reset ASIC\n");
1994 return STATUS_SUCCESS
;
1997 // Program WMARK register
1998 status
= ft1000_write_register (dev
, 0x600, FT1000_REG_MAG_WATERMARK
);
1999 // clear ASIC reset doorbell
2000 status
= ft1000_write_register (dev
, FT1000_DSP_ASIC_RESET
, FT1000_REG_DOORBELL
);
2003 else if (tempword
& FT1000_ASIC_RESET_REQ
) {
2004 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
2006 // clear ASIC reset request from DSP
2007 status
= ft1000_write_register (dev
, FT1000_ASIC_RESET_REQ
, FT1000_REG_DOORBELL
);
2008 status
= ft1000_write_register (dev
, HOST_INTF_BE
, FT1000_REG_SUP_CTRL
);
2009 // copy dsp session record from Adapter block
2010 status
= ft1000_write_dpram32 (dev
, 0, (u8
*)&info
->DSPSess
.Rec
[0], 1024);
2011 // Program WMARK register
2012 status
= ft1000_write_register (dev
, 0x600, FT1000_REG_MAG_WATERMARK
);
2013 // ring doorbell to tell DSP that ASIC is out of reset
2014 status
= ft1000_write_register (dev
, FT1000_ASIC_RESET_DSP
, FT1000_REG_DOORBELL
);
2016 else if (tempword
& FT1000_DB_COND_RESET
) {
2017 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
2019 // Reset ASIC and DSP
2021 if (info
->fAppMsgPend
== 0) {
2022 // Reset ASIC and DSP
2024 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER0
, (u8
*)&(info
->DSP_TIME
[0]), FT1000_MAG_DSP_TIMER0_INDX
);
2025 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER1
, (u8
*)&(info
->DSP_TIME
[1]), FT1000_MAG_DSP_TIMER1_INDX
);
2026 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER2
, (u8
*)&(info
->DSP_TIME
[2]), FT1000_MAG_DSP_TIMER2_INDX
);
2027 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER3
, (u8
*)&(info
->DSP_TIME
[3]), FT1000_MAG_DSP_TIMER3_INDX
);
2028 info
->CardReady
= 0;
2029 info
->DrvErrNum
= DSP_CONDRESET_INFO
;
2030 DEBUG("ft1000_hw:DSP conditional reset requested\n");
2031 info
->ft1000_reset(dev
->net
);
2034 info
->fProvComplete
= 0;
2035 info
->fCondResetPend
= 1;
2038 ft1000_write_register(dev
, FT1000_DB_COND_RESET
, FT1000_REG_DOORBELL
);
2041 }//endof if ( !status )
2043 //DEBUG("return from ft1000_poll.\n");
2044 return STATUS_SUCCESS
;