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
,
488 unsigned char *commandbuf
;
490 DEBUG("card_send_command: enter card_send_command... size=%d\n", size
);
492 commandbuf
= (unsigned char *)kmalloc(size
+ 2, GFP_KERNEL
);
493 memcpy((void *)commandbuf
+ 2, (void *)ptempbuffer
, size
);
495 //DEBUG("card_send_command: Command Send\n");
497 ft1000_read_register(ft1000dev
, &temp
, FT1000_REG_DOORBELL
);
502 /* check for odd word */
505 /* Must force to be 32 bit aligned */
507 size
+= 4 - (size
% 4);
509 //DEBUG("card_send_command: write dpram ... size=%d\n", size);
510 ft1000_write_dpram32(ft1000dev
, 0, commandbuf
, size
);
512 //DEBUG("card_send_command: write into doorbell ...\n");
513 ft1000_write_register(ft1000dev
, FT1000_DB_DPRAM_TX
,
514 FT1000_REG_DOORBELL
);
517 ft1000_read_register(ft1000dev
, &temp
, FT1000_REG_DOORBELL
);
518 //DEBUG("card_send_command: read doorbell ...temp=%x\n", temp);
519 if ((temp
& 0x0100) == 0) {
520 //DEBUG("card_send_command: Message sent\n");
525 //--------------------------------------------------------------------------
527 // Function: dsp_reload
529 // Synopsis: This function is called to load or reload the DSP
531 // Arguments: ft1000dev - device structure
534 //-----------------------------------------------------------------------
535 int dsp_reload(struct ft1000_device
*ft1000dev
)
541 struct ft1000_info
*pft1000info
;
543 pft1000info
= netdev_priv(ft1000dev
->net
);
545 pft1000info
->CardReady
= 0;
547 /* Program Interrupt Mask register */
548 status
= ft1000_write_register(ft1000dev
, 0xffff, FT1000_REG_SUP_IMASK
);
550 status
= ft1000_read_register(ft1000dev
, &tempword
, FT1000_REG_RESET
);
551 tempword
|= ASIC_RESET_BIT
;
552 status
= ft1000_write_register(ft1000dev
, tempword
, FT1000_REG_RESET
);
554 status
= ft1000_read_register(ft1000dev
, &tempword
, FT1000_REG_RESET
);
555 DEBUG("Reset Register = 0x%x\n", tempword
);
557 /* Toggle DSP reset */
558 card_reset_dsp(ft1000dev
, 1);
560 card_reset_dsp(ft1000dev
, 0);
564 ft1000_write_register(ft1000dev
, HOST_INTF_BE
, FT1000_REG_SUP_CTRL
);
566 /* Let's check for FEFE */
568 ft1000_read_dpram32(ft1000dev
, FT1000_MAG_DPRAM_FEFE_INDX
,
569 (u8
*) &templong
, 4);
570 DEBUG("templong (fefe) = 0x%8x\n", templong
);
572 /* call codeloader */
573 status
= scram_dnldr(ft1000dev
, pFileStart
, FileLength
);
575 if (status
!= STATUS_SUCCESS
)
580 DEBUG("dsp_reload returned\n");
585 //---------------------------------------------------------------------------
587 // Function: ft1000_reset_asic
588 // Descripton: This function will call the Card Service function to reset the
591 // dev - device structure
595 //---------------------------------------------------------------------------
596 static void ft1000_reset_asic(struct net_device
*dev
)
598 struct ft1000_info
*info
= netdev_priv(dev
);
599 struct ft1000_device
*ft1000dev
= info
->pFt1000Dev
;
602 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
604 info
->ASICResetNum
++;
606 /* Let's use the register provided by the Magnemite ASIC to reset the
609 ft1000_write_register(ft1000dev
, (DSP_RESET_BIT
| ASIC_RESET_BIT
),
614 /* set watermark to -1 in order to not generate an interrrupt */
615 ft1000_write_register(ft1000dev
, 0xffff, FT1000_REG_MAG_WATERMARK
);
617 /* clear interrupts */
618 ft1000_read_register(ft1000dev
, &tempword
, FT1000_REG_SUP_ISR
);
619 DEBUG("ft1000_hw: interrupt status register = 0x%x\n", tempword
);
620 ft1000_write_register(ft1000dev
, tempword
, FT1000_REG_SUP_ISR
);
621 ft1000_read_register(ft1000dev
, &tempword
, FT1000_REG_SUP_ISR
);
622 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_reset_card:deleting provisioning record\n");
654 list_entry(info
->prov_list
.next
, struct prov_record
, list
);
655 list_del(&ptr
->list
);
656 kfree(ptr
->pprov_data
);
660 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");
672 /* Initialize DSP heartbeat area */
673 ft1000_write_dpram16(ft1000dev
, FT1000_MAG_HI_HO
, ho_mag
,
674 FT1000_MAG_HI_HO_INDX
);
675 ft1000_read_dpram16(ft1000dev
, FT1000_MAG_HI_HO
, (u8
*) &tempword
,
676 FT1000_MAG_HI_HO_INDX
);
677 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword
);
681 info
->fCondResetPend
= 0;
688 #ifdef HAVE_NET_DEVICE_OPS
689 static const struct net_device_ops ftnet_ops
=
691 .ndo_open
= &ft1000_open
,
692 .ndo_stop
= &ft1000_close
,
693 .ndo_start_xmit
= &ft1000_start_xmit
,
694 .ndo_get_stats
= &ft1000_netdev_stats
,
699 //---------------------------------------------------------------------------
700 // Function: init_ft1000_netdev
702 // Parameters: ft1000dev - device structure
705 // Returns: STATUS_SUCCESS - success
706 // STATUS_FAILURE - failure
708 // Description: This function initialize the network device
712 //---------------------------------------------------------------------------
713 int init_ft1000_netdev(struct ft1000_device
*ft1000dev
)
715 struct net_device
*netdev
;
716 struct ft1000_info
*pInfo
= NULL
;
717 struct dpram_blk
*pdpram_blk
;
719 struct list_head
*cur
, *tmp
;
721 unsigned long gCardIndex
= 0;
723 DEBUG("Enter init_ft1000_netdev...\n");
725 netdev
= alloc_etherdev(sizeof(struct ft1000_info
));
727 DEBUG("init_ft1000_netdev: can not allocate network device\n");
731 pInfo
= netdev_priv(netdev
);
733 memset(pInfo
, 0, sizeof(struct ft1000_info
));
735 dev_alloc_name(netdev
, netdev
->name
);
737 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev
->name
);
739 if (strncmp(netdev
->name
, "eth", 3) == 0) {
740 card_nr
[0] = netdev
->name
[3];
742 ret_val
= strict_strtoul(card_nr
, 10, &gCardIndex
);
744 printk(KERN_ERR
"Can't parse netdev\n");
748 pInfo
->CardNumber
= gCardIndex
;
749 DEBUG("card number = %d\n", pInfo
->CardNumber
);
751 printk(KERN_ERR
"ft1000: Invalid device name\n");
756 memset(&pInfo
->stats
, 0, sizeof(struct net_device_stats
));
758 spin_lock_init(&pInfo
->dpram_lock
);
759 pInfo
->pFt1000Dev
= ft1000dev
;
760 pInfo
->DrvErrNum
= 0;
761 pInfo
->ASICResetNum
= 0;
762 pInfo
->registered
= 1;
763 pInfo
->ft1000_reset
= ft1000_reset
;
764 pInfo
->mediastate
= 0;
766 pInfo
->DeviceCreated
= FALSE
;
767 pInfo
->CurrentInterruptEnableMask
= ISR_DEFAULT_MASK
;
768 pInfo
->InterruptsEnabled
= FALSE
;
769 pInfo
->CardReady
= 0;
770 pInfo
->DSP_TIME
[0] = 0;
771 pInfo
->DSP_TIME
[1] = 0;
772 pInfo
->DSP_TIME
[2] = 0;
773 pInfo
->DSP_TIME
[3] = 0;
774 pInfo
->fAppMsgPend
= 0;
775 pInfo
->fCondResetPend
= 0;
778 memset(&pInfo
->tempbuf
[0], 0, sizeof(pInfo
->tempbuf
));
780 INIT_LIST_HEAD(&pInfo
->prov_list
);
782 INIT_LIST_HEAD(&pInfo
->nodes
.list
);
784 #ifdef HAVE_NET_DEVICE_OPS
785 netdev
->netdev_ops
= &ftnet_ops
;
787 netdev
->hard_start_xmit
= &ft1000_start_xmit
;
788 netdev
->get_stats
= &ft1000_netdev_stats
;
789 netdev
->open
= &ft1000_open
;
790 netdev
->stop
= &ft1000_close
;
793 ft1000dev
->net
= netdev
;
795 DEBUG("Initialize free_buff_lock and freercvpool\n");
796 spin_lock_init(&free_buff_lock
);
798 /* initialize a list of buffers to be use for queuing
799 * up receive command data
801 INIT_LIST_HEAD(&freercvpool
);
803 /* create list of free buffers */
804 for (i
= 0; i
< NUM_OF_FREE_BUFFERS
; i
++) {
805 /* Get memory for DPRAM_DATA link list */
806 pdpram_blk
= kmalloc(sizeof(struct dpram_blk
), GFP_KERNEL
);
807 if (pdpram_blk
== NULL
) {
811 /* Get a block of memory to store command data */
812 pdpram_blk
->pbuffer
= kmalloc(MAX_CMD_SQSIZE
, GFP_KERNEL
);
813 if (pdpram_blk
->pbuffer
== NULL
) {
818 /* link provisioning data */
819 list_add_tail(&pdpram_blk
->list
, &freercvpool
);
821 numofmsgbuf
= NUM_OF_FREE_BUFFERS
;
826 list_for_each_safe(cur
, tmp
, &freercvpool
) {
827 pdpram_blk
= list_entry(cur
, struct dpram_blk
, list
);
828 list_del(&pdpram_blk
->list
);
829 kfree(pdpram_blk
->pbuffer
);
837 //---------------------------------------------------------------------------
838 // Function: reg_ft1000_netdev
840 // Parameters: ft1000dev - device structure
843 // Returns: STATUS_SUCCESS - success
844 // STATUS_FAILURE - failure
846 // Description: This function register the network driver
850 //---------------------------------------------------------------------------
851 int reg_ft1000_netdev(struct ft1000_device
*ft1000dev
, struct usb_interface
*intf
)
853 struct net_device
*netdev
;
854 struct ft1000_info
*pInfo
;
857 netdev
= ft1000dev
->net
;
858 pInfo
= netdev_priv(ft1000dev
->net
);
859 DEBUG("Enter reg_ft1000_netdev...\n");
862 ft1000_read_register(ft1000dev
, &pInfo
->AsicID
, FT1000_REG_ASIC_ID
);
864 usb_set_intfdata(intf
, pInfo
);
865 SET_NETDEV_DEV(netdev
, &intf
->dev
);
867 rc
= register_netdev(netdev
);
870 DEBUG("reg_ft1000_netdev: could not register network device\n");
876 //Create character device, implemented by Jim
877 ft1000_create_dev(ft1000dev
);
879 DEBUG ("reg_ft1000_netdev returned\n");
881 pInfo
->CardReady
= 1;
887 static int ft1000_reset(struct net_device
*dev
)
889 ft1000_reset_card(dev
);
893 //---------------------------------------------------------------------------
894 // Function: ft1000_usb_transmit_complete
896 // Parameters: urb - transmitted usb urb
901 // Description: This is the callback function when a urb is transmitted
905 //---------------------------------------------------------------------------
906 static void ft1000_usb_transmit_complete(struct urb
*urb
)
909 struct ft1000_device
*ft1000dev
= urb
->context
;
911 //DEBUG("ft1000_usb_transmit_complete entered\n");
914 printk("%s: TX status %d\n", ft1000dev
->net
->name
, urb
->status
);
916 netif_wake_queue(ft1000dev
->net
);
918 //DEBUG("Return from ft1000_usb_transmit_complete\n");
921 //---------------------------------------------------------------------------
923 // Function: ft1000_copy_down_pkt
924 // Descripton: This function will take an ethernet packet and convert it to
925 // a Flarion packet prior to sending it to the ASIC Downlink
928 // dev - device structure
929 // packet - address of ethernet packet
930 // len - length of IP packet
935 //---------------------------------------------------------------------------
936 static int ft1000_copy_down_pkt (struct net_device
*netdev
, u8
*packet
, u16 len
)
938 struct ft1000_info
*pInfo
= netdev_priv(netdev
);
939 struct ft1000_device
*pFt1000Dev
= pInfo
->pFt1000Dev
;
944 struct pseudo_hdr hdr
;
946 if (!pInfo
->CardReady
)
949 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
955 //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len);
957 count
= sizeof(struct pseudo_hdr
) + len
;
958 if(count
> MAX_BUF_SIZE
)
960 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n");
961 DEBUG("size = %d\n", count
);
966 count
= count
+ (4- (count
%4) );
968 memset(&hdr
, 0, sizeof(struct pseudo_hdr
));
970 hdr
.length
= ntohs(count
);
972 hdr
.destination
= 0x20;
975 hdr
.sh_str_id
= 0x91;
978 hdr
.checksum
= hdr
.length
^ hdr
.source
^ hdr
.destination
^
979 hdr
.portdest
^ hdr
.portsrc
^ hdr
.sh_str_id
^
982 memcpy(&pFt1000Dev
->tx_buf
[0], &hdr
, sizeof(hdr
));
983 memcpy(&(pFt1000Dev
->tx_buf
[sizeof(struct pseudo_hdr
)]), packet
, len
);
985 netif_stop_queue(netdev
);
987 //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count);
989 usb_fill_bulk_urb(pFt1000Dev
->tx_urb
,
991 usb_sndbulkpipe(pFt1000Dev
->dev
, pFt1000Dev
->bulk_out_endpointAddr
),
994 ft1000_usb_transmit_complete
,
997 t
= (u8
*)pFt1000Dev
->tx_urb
->transfer_buffer
;
998 //DEBUG("transfer_length=%d\n", pFt1000Dev->tx_urb->transfer_buffer_length);
999 /*for (i=0; i<count; i++ )
1001 DEBUG("%x ", *t++ );
1005 ret
= usb_submit_urb(pFt1000Dev
->tx_urb
, GFP_ATOMIC
);
1007 DEBUG("ft1000 failed tx_urb %d\n", ret
);
1010 pInfo
->stats
.tx_packets
++;
1011 pInfo
->stats
.tx_bytes
+= (len
+14);
1014 //DEBUG("ft1000_copy_down_pkt() exit\n");
1019 //---------------------------------------------------------------------------
1020 // Function: ft1000_start_xmit
1022 // Parameters: skb - socket buffer to be sent
1023 // dev - network device
1028 // Description: transmit a ethernet packet
1032 //---------------------------------------------------------------------------
1033 static int ft1000_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
1035 struct ft1000_info
*pInfo
= netdev_priv(dev
);
1036 struct ft1000_device
*pFt1000Dev
= pInfo
->pFt1000Dev
;
1041 //DEBUG(" ft1000_start_xmit() entered\n");
1045 DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" );
1046 return NETDEV_TX_OK
;
1049 if ( pFt1000Dev
->status
& FT1000_STATUS_CLOSING
)
1051 DEBUG("network driver is closed, return\n");
1055 //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len);
1056 pipe
= usb_sndbulkpipe(pFt1000Dev
->dev
, pFt1000Dev
->bulk_out_endpointAddr
);
1057 maxlen
= usb_maxpacket(pFt1000Dev
->dev
, pipe
, usb_pipeout(pipe
));
1058 //DEBUG("ft1000_start_xmit 2: pipe=%d dev->maxpacket = %d\n", pipe, maxlen);
1060 pdata
= (u8
*)skb
->data
;
1061 /*for (i=0; i<skb->len; i++)
1062 DEBUG("skb->data[%d]=%x ", i, *(skb->data+i));
1067 if (pInfo
->mediastate
== 0)
1069 /* Drop packet is mediastate is down */
1070 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n");
1074 if ( (skb
->len
< ENET_HEADER_SIZE
) || (skb
->len
> ENET_MAX_SIZE
) )
1076 /* Drop packet which has invalid size */
1077 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n");
1081 ft1000_copy_down_pkt(dev
, (pdata
+ENET_HEADER_SIZE
-2),
1082 skb
->len
- ENET_HEADER_SIZE
+ 2);
1086 //DEBUG(" ft1000_start_xmit() exit\n");
1088 return NETDEV_TX_OK
;
1091 //---------------------------------------------------------------------------
1093 // Function: ft1000_copy_up_pkt
1094 // Descripton: This function will take a packet from the FIFO up link and
1095 // convert it into an ethernet packet and deliver it to the IP stack
1097 // urb - the receving usb urb
1103 //---------------------------------------------------------------------------
1104 static int ft1000_copy_up_pkt (struct urb
*urb
)
1106 struct ft1000_info
*info
= urb
->context
;
1107 struct ft1000_device
*ft1000dev
= info
->pFt1000Dev
;
1108 struct net_device
*net
= ft1000dev
->net
;
1113 struct sk_buff
*skb
;
1120 //DEBUG("ft1000_copy_up_pkt entered\n");
1122 if ( ft1000dev
->status
& FT1000_STATUS_CLOSING
)
1124 DEBUG("network driver is closed, return\n");
1125 return STATUS_SUCCESS
;
1129 len
= urb
->transfer_buffer_length
;
1130 lena
= urb
->actual_length
; //mbelian
1131 //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n",
1132 // urb->transfer_buffer_length, urb->actual_length);
1134 chksum
= (u16
*)ft1000dev
->rx_buf
;
1136 tempword
= *chksum
++;
1139 tempword
^= *chksum
++;
1142 if (tempword
!= *chksum
)
1144 info
->stats
.rx_errors
++;
1145 ft1000_submit_rx_urb(info
);
1146 return STATUS_FAILURE
;
1150 //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum);
1152 skb
= dev_alloc_skb(len
+12+2);
1156 DEBUG("ft1000_copy_up_pkt: No Network buffers available\n");
1157 info
->stats
.rx_errors
++;
1158 ft1000_submit_rx_urb(info
);
1159 return STATUS_FAILURE
;
1162 pbuffer
= (u8
*)skb_put(skb
, len
+12);
1164 //subtract the number of bytes read already
1168 *pbuffer
++ = net
->dev_addr
[0];
1169 *pbuffer
++ = net
->dev_addr
[1];
1170 *pbuffer
++ = net
->dev_addr
[2];
1171 *pbuffer
++ = net
->dev_addr
[3];
1172 *pbuffer
++ = net
->dev_addr
[4];
1173 *pbuffer
++ = net
->dev_addr
[5];
1184 memcpy(pbuffer
, ft1000dev
->rx_buf
+sizeof(struct pseudo_hdr
), len
-sizeof(struct pseudo_hdr
));
1186 //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n");
1187 /*for (i=0; i<len+12; i++)
1189 DEBUG("ft1000_copy_up_pkt: Protocol Data: 0x%x\n ", *ptemp++);
1194 skb
->protocol
= eth_type_trans(skb
, net
);
1195 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
1198 info
->stats
.rx_packets
++;
1199 // Add on 12 bytes for MAC address which was removed
1200 info
->stats
.rx_bytes
+= (lena
+12); //mbelian
1202 ft1000_submit_rx_urb(info
);
1203 //DEBUG("ft1000_copy_up_pkt exited\n");
1207 //---------------------------------------------------------------------------
1209 // Function: ft1000_submit_rx_urb
1210 // Descripton: the receiving function of the network driver
1213 // info - a private structure contains the device information
1219 //---------------------------------------------------------------------------
1220 static int ft1000_submit_rx_urb(struct ft1000_info
*info
)
1223 struct ft1000_device
*pFt1000Dev
= info
->pFt1000Dev
;
1226 //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb));
1227 if ( pFt1000Dev
->status
& FT1000_STATUS_CLOSING
)
1229 DEBUG("network driver is closed, return\n");
1230 //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian
1234 usb_fill_bulk_urb(pFt1000Dev
->rx_urb
,
1236 usb_rcvbulkpipe(pFt1000Dev
->dev
, pFt1000Dev
->bulk_in_endpointAddr
),
1239 (usb_complete_t
)ft1000_copy_up_pkt
,
1243 if((result
= usb_submit_urb(pFt1000Dev
->rx_urb
, GFP_ATOMIC
)))
1245 printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result
);
1249 //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result);
1254 //---------------------------------------------------------------------------
1255 // Function: ft1000_open
1258 // dev - network device
1263 // Description: open the network driver
1267 //---------------------------------------------------------------------------
1268 static int ft1000_open (struct net_device
*dev
)
1270 struct ft1000_info
*pInfo
= netdev_priv(dev
);
1271 struct timeval tv
; //mbelian
1274 DEBUG("ft1000_open is called for card %d\n", pInfo
->CardNumber
);
1275 //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len);
1277 pInfo
->stats
.rx_bytes
= 0; //mbelian
1278 pInfo
->stats
.tx_bytes
= 0; //mbelian
1279 pInfo
->stats
.rx_packets
= 0; //mbelian
1280 pInfo
->stats
.tx_packets
= 0; //mbelian
1281 do_gettimeofday(&tv
);
1282 pInfo
->ConTm
= tv
.tv_sec
;
1283 pInfo
->ProgConStat
= 0; //mbelian
1286 netif_start_queue(dev
);
1288 netif_carrier_on(dev
); //mbelian
1290 ret
= ft1000_submit_rx_urb(pInfo
);
1295 //---------------------------------------------------------------------------
1296 // Function: ft1000_close
1299 // net - network device
1304 // Description: close the network driver
1308 //---------------------------------------------------------------------------
1309 int ft1000_close(struct net_device
*net
)
1311 struct ft1000_info
*pInfo
= netdev_priv(net
);
1312 struct ft1000_device
*ft1000dev
= pInfo
->pFt1000Dev
;
1314 //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt);
1316 ft1000dev
->status
|= FT1000_STATUS_CLOSING
;
1318 //DEBUG("ft1000_close: calling usb_kill_urb \n");
1320 DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo
, ft1000dev
);
1321 netif_carrier_off(net
);//mbelian
1322 netif_stop_queue(net
);
1323 //DEBUG("ft1000_close: netif_stop_queue called\n");
1324 ft1000dev
->status
&= ~FT1000_STATUS_CLOSING
;
1326 pInfo
->ProgConStat
= 0xff; //mbelian
1332 static struct net_device_stats
*ft1000_netdev_stats(struct net_device
*dev
)
1334 struct ft1000_info
*info
= netdev_priv(dev
);
1336 return &(info
->stats
); //mbelian
1340 /*********************************************************************************
1345 //---------------------------------------------------------------------------
1347 // Function: ft1000_chkcard
1348 // Descripton: This function will check if the device is presently available on
1351 // dev - device structure
1353 // status - FALSE (device is not present)
1354 // TRUE (device is present)
1356 //---------------------------------------------------------------------------
1357 static int ft1000_chkcard (struct ft1000_device
*dev
) {
1360 struct ft1000_info
*info
= netdev_priv(dev
->net
);
1362 if (info
->fCondResetPend
)
1364 DEBUG("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1368 // Mask register is used to check for device presence since it is never
1370 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_SUP_IMASK
);
1371 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword);
1372 if (tempword
== 0) {
1373 DEBUG("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
1377 // The system will return the value of 0xffff for the version register
1378 // if the device is not present.
1379 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_ASIC_ID
);
1380 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword);
1381 if (tempword
!= 0x1b01 ){
1382 dev
->status
|= FT1000_STATUS_CLOSING
; //mbelian
1383 DEBUG("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
1391 //---------------------------------------------------------------------------
1393 // Function: ft1000_receive_cmd
1394 // Descripton: This function will read a message from the dpram area.
1396 // dev - network device structure
1397 // pbuffer - caller supply address to buffer
1398 // pnxtph - pointer to next pseudo header
1400 // Status = 0 (unsuccessful)
1403 //---------------------------------------------------------------------------
1404 static bool ft1000_receive_cmd (struct ft1000_device
*dev
, u16
*pbuffer
, int maxsz
, u16
*pnxtph
) {
1410 ret
= ft1000_read_dpram16(dev
, FT1000_MAG_PH_LEN
, (u8
*)&size
, FT1000_MAG_PH_LEN_INDX
);
1411 size
= ntohs(size
) + PSEUDOSZ
;
1413 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size
);
1417 ppseudohdr
= (u16
*)pbuffer
;
1418 ft1000_write_register(dev
, FT1000_DPRAM_MAG_RX_BASE
, FT1000_REG_DPRAM_ADDR
);
1419 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAH
);
1420 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1422 ft1000_write_register(dev
, FT1000_DPRAM_MAG_RX_BASE
+1, FT1000_REG_DPRAM_ADDR
);
1423 for (i
=0; i
<=(size
>>2); i
++) {
1424 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAL
);
1426 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAH
);
1429 //copy odd aligned word
1430 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAL
);
1431 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1433 ret
= ft1000_read_register(dev
, pbuffer
, FT1000_REG_MAG_DPDATAH
);
1434 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1436 if (size
& 0x0001) {
1437 //copy odd byte from fifo
1438 ret
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DPRAM_DATA
);
1439 *pbuffer
= ntohs(tempword
);
1442 // Check if pseudo header checksum is good
1443 // Calculate pseudo header checksum
1444 tempword
= *ppseudohdr
++;
1445 for (i
=1; i
<7; i
++) {
1446 tempword
^= *ppseudohdr
++;
1448 if ( (tempword
!= *ppseudohdr
) ) {
1457 static int ft1000_dsp_prov(void *arg
)
1459 struct ft1000_device
*dev
= (struct ft1000_device
*)arg
;
1460 struct ft1000_info
*info
= netdev_priv(dev
->net
);
1464 struct prov_record
*ptr
;
1465 struct pseudo_hdr
*ppseudo_hdr
;
1468 u16 TempShortBuf
[256];
1470 DEBUG("*** DspProv Entered\n");
1472 while (list_empty(&info
->prov_list
) == 0)
1474 DEBUG("DSP Provisioning List Entry\n");
1476 // Check if doorbell is available
1477 DEBUG("check if doorbell is cleared\n");
1478 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_DOORBELL
);
1481 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n");
1485 while (tempword
& FT1000_DB_DPRAM_TX
) {
1489 DEBUG("FT1000:ft1000_dsp_prov:message drop\n");
1490 return STATUS_FAILURE
;
1492 ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1495 if ( !(tempword
& FT1000_DB_DPRAM_TX
) ) {
1496 DEBUG("*** Provision Data Sent to DSP\n");
1498 // Send provisioning data
1499 ptr
= list_entry(info
->prov_list
.next
, struct prov_record
, list
);
1500 len
= *(u16
*)ptr
->pprov_data
;
1504 pmsg
= (u16
*)ptr
->pprov_data
;
1505 ppseudo_hdr
= (struct pseudo_hdr
*)pmsg
;
1506 // Insert slow queue sequence number
1507 ppseudo_hdr
->seq_num
= info
->squeseqnum
++;
1508 ppseudo_hdr
->portsrc
= 0;
1509 // Calculate new checksum
1510 ppseudo_hdr
->checksum
= *pmsg
++;
1511 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
1512 for (i
=1; i
<7; i
++) {
1513 ppseudo_hdr
->checksum
^= *pmsg
++;
1514 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
1517 TempShortBuf
[0] = 0;
1518 TempShortBuf
[1] = htons (len
);
1519 memcpy(&TempShortBuf
[2], ppseudo_hdr
, len
);
1521 status
= ft1000_write_dpram32 (dev
, 0, (u8
*)&TempShortBuf
[0], (unsigned short)(len
+2));
1522 status
= ft1000_write_register (dev
, FT1000_DB_DPRAM_TX
, FT1000_REG_DOORBELL
);
1524 list_del(&ptr
->list
);
1525 kfree(ptr
->pprov_data
);
1531 DEBUG("DSP Provisioning List Entry finished\n");
1535 info
->fProvComplete
= 1;
1536 info
->CardReady
= 1;
1537 return STATUS_SUCCESS
;
1542 static int ft1000_proc_drvmsg (struct ft1000_device
*dev
, u16 size
) {
1543 struct ft1000_info
*info
= netdev_priv(dev
->net
);
1546 struct media_msg
*pmediamsg
;
1547 struct dsp_init_msg
*pdspinitmsg
;
1548 struct drv_msg
*pdrvmsg
;
1550 struct pseudo_hdr
*ppseudo_hdr
;
1559 char *cmdbuffer
= kmalloc(1600, GFP_KERNEL
);
1561 return STATUS_FAILURE
;
1563 status
= ft1000_read_dpram32(dev
, 0x200, cmdbuffer
, size
);
1568 DEBUG("ft1000_proc_drvmsg:cmdbuffer\n");
1569 for(i
= 0; i
< size
; i
+=5)
1571 if( (i
+ 5) < size
)
1572 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]);
1575 for (j
= i
; j
< size
; j
++)
1576 DEBUG("0x%x ", cmdbuffer
[j
]);
1582 pdrvmsg
= (struct drv_msg
*)&cmdbuffer
[2];
1583 msgtype
= ntohs(pdrvmsg
->type
);
1584 DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype
);
1587 DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE");
1589 pmediamsg
= (struct media_msg
*)&cmdbuffer
[0];
1590 if (info
->ProgConStat
!= 0xFF) {
1591 if (pmediamsg
->state
) {
1592 DEBUG("Media is up\n");
1593 if (info
->mediastate
== 0) {
1594 if ( info
->NetDevRegDone
)
1596 //netif_carrier_on(dev->net);//mbelian
1597 netif_wake_queue(dev
->net
);
1599 info
->mediastate
= 1;
1600 /*do_gettimeofday(&tv);
1601 info->ConTm = tv.tv_sec;*/ //mbelian
1605 DEBUG("Media is down\n");
1606 if (info
->mediastate
== 1) {
1607 info
->mediastate
= 0;
1608 if ( info
->NetDevRegDone
)
1610 //netif_carrier_off(dev->net); mbelian
1611 //netif_stop_queue(dev->net);
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 case DSP_INIT_MSG
: {
1632 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG");
1634 pdspinitmsg
= (struct dsp_init_msg
*)&cmdbuffer
[2];
1635 memcpy(info
->DspVer
, pdspinitmsg
->DspVer
, DSPVERSZ
);
1636 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", info
->DspVer
[0], info
->DspVer
[1], info
->DspVer
[2], info
->DspVer
[3]);
1637 memcpy(info
->HwSerNum
, pdspinitmsg
->HwSerNum
, HWSERNUMSZ
);
1638 memcpy(info
->Sku
, pdspinitmsg
->Sku
, SKUSZ
);
1639 memcpy(info
->eui64
, pdspinitmsg
->eui64
, EUISZ
);
1640 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]);
1641 dev
->net
->dev_addr
[0] = info
->eui64
[0];
1642 dev
->net
->dev_addr
[1] = info
->eui64
[1];
1643 dev
->net
->dev_addr
[2] = info
->eui64
[2];
1644 dev
->net
->dev_addr
[3] = info
->eui64
[5];
1645 dev
->net
->dev_addr
[4] = info
->eui64
[6];
1646 dev
->net
->dev_addr
[5] = info
->eui64
[7];
1648 if (ntohs(pdspinitmsg
->length
) == (sizeof(struct dsp_init_msg
) - 20)) {
1649 memcpy(info
->ProductMode
, pdspinitmsg
->ProductMode
, MODESZ
);
1650 memcpy(info
->RfCalVer
, pdspinitmsg
->RfCalVer
, CALVERSZ
);
1651 memcpy(info
->RfCalDate
, pdspinitmsg
->RfCalDate
, CALDATESZ
);
1652 DEBUG("RFCalVer = 0x%2x 0x%2x\n", info
->RfCalVer
[0], info
->RfCalVer
[1]);
1656 case DSP_PROVISION
: {
1657 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n");
1659 // kick off dspprov routine to start provisioning
1660 // Send provisioning data to DSP
1661 if (list_empty(&info
->prov_list
) == 0)
1663 info
->fProvComplete
= 0;
1664 status
= ft1000_dsp_prov(dev
);
1665 if (status
!= STATUS_SUCCESS
)
1669 info
->fProvComplete
= 1;
1670 status
= ft1000_write_register (dev
, FT1000_DB_HB
, FT1000_REG_DOORBELL
);
1671 DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n");
1673 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n");
1676 case DSP_STORE_INFO
: {
1677 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO");
1679 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
1680 tempword
= ntohs(pdrvmsg
->length
);
1681 info
->DSPInfoBlklen
= tempword
;
1682 if (tempword
< (MAX_DSP_SESS_REC
-4) ) {
1683 pmsg
= (u16
*)&pdrvmsg
->data
[0];
1684 for (i
=0; i
<((tempword
+1)/2); i
++) {
1685 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg
);
1686 info
->DSPInfoBlk
[i
+10] = *pmsg
++;
1690 info
->DSPInfoBlklen
= 0;
1694 case DSP_GET_INFO
: {
1695 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
1696 // copy dsp info block to dsp
1697 info
->DrvMsgPend
= 1;
1698 // allow any outstanding ioctl to finish
1700 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1701 if (tempword
& FT1000_DB_DPRAM_TX
) {
1703 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1704 if (tempword
& FT1000_DB_DPRAM_TX
) {
1706 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1707 if (tempword
& FT1000_DB_DPRAM_TX
) {
1713 // Put message into Slow Queue
1714 // Form Pseudo header
1715 pmsg
= (u16
*)info
->DSPInfoBlk
;
1717 *pmsg
++ = htons(info
->DSPInfoBlklen
+20+info
->DSPInfoBlklen
);
1718 ppseudo_hdr
= (struct pseudo_hdr
*)(u16
*)&info
->DSPInfoBlk
[2];
1719 ppseudo_hdr
->length
= htons(info
->DSPInfoBlklen
+4+info
->DSPInfoBlklen
);
1720 ppseudo_hdr
->source
= 0x10;
1721 ppseudo_hdr
->destination
= 0x20;
1722 ppseudo_hdr
->portdest
= 0;
1723 ppseudo_hdr
->portsrc
= 0;
1724 ppseudo_hdr
->sh_str_id
= 0;
1725 ppseudo_hdr
->control
= 0;
1726 ppseudo_hdr
->rsvd1
= 0;
1727 ppseudo_hdr
->rsvd2
= 0;
1728 ppseudo_hdr
->qos_class
= 0;
1729 // Insert slow queue sequence number
1730 ppseudo_hdr
->seq_num
= info
->squeseqnum
++;
1731 // Insert application id
1732 ppseudo_hdr
->portsrc
= 0;
1733 // Calculate new checksum
1734 ppseudo_hdr
->checksum
= *pmsg
++;
1735 for (i
=1; i
<7; i
++) {
1736 ppseudo_hdr
->checksum
^= *pmsg
++;
1738 info
->DSPInfoBlk
[10] = 0x7200;
1739 info
->DSPInfoBlk
[11] = htons(info
->DSPInfoBlklen
);
1740 status
= ft1000_write_dpram32 (dev
, 0, (u8
*)&info
->DSPInfoBlk
[0], (unsigned short)(info
->DSPInfoBlklen
+22));
1741 status
= ft1000_write_register (dev
, FT1000_DB_DPRAM_TX
, FT1000_REG_DOORBELL
);
1742 info
->DrvMsgPend
= 0;
1747 case GET_DRV_ERR_RPT_MSG
: {
1748 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
1749 // copy driver error message to dsp
1750 info
->DrvMsgPend
= 1;
1751 // allow any outstanding ioctl to finish
1753 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1754 if (tempword
& FT1000_DB_DPRAM_TX
) {
1756 status
= ft1000_read_register(dev
, &tempword
, FT1000_REG_DOORBELL
);
1757 if (tempword
& FT1000_DB_DPRAM_TX
) {
1762 if ( (tempword
& FT1000_DB_DPRAM_TX
) == 0) {
1763 // Put message into Slow Queue
1764 // Form Pseudo header
1765 pmsg
= (u16
*)&tempbuffer
[0];
1766 ppseudo_hdr
= (struct pseudo_hdr
*)pmsg
;
1767 ppseudo_hdr
->length
= htons(0x0012);
1768 ppseudo_hdr
->source
= 0x10;
1769 ppseudo_hdr
->destination
= 0x20;
1770 ppseudo_hdr
->portdest
= 0;
1771 ppseudo_hdr
->portsrc
= 0;
1772 ppseudo_hdr
->sh_str_id
= 0;
1773 ppseudo_hdr
->control
= 0;
1774 ppseudo_hdr
->rsvd1
= 0;
1775 ppseudo_hdr
->rsvd2
= 0;
1776 ppseudo_hdr
->qos_class
= 0;
1777 // Insert slow queue sequence number
1778 ppseudo_hdr
->seq_num
= info
->squeseqnum
++;
1779 // Insert application id
1780 ppseudo_hdr
->portsrc
= 0;
1781 // Calculate new checksum
1782 ppseudo_hdr
->checksum
= *pmsg
++;
1783 for (i
=1; i
<7; i
++) {
1784 ppseudo_hdr
->checksum
^= *pmsg
++;
1786 pmsg
= (u16
*)&tempbuffer
[16];
1787 *pmsg
++ = htons(RSP_DRV_ERR_RPT_MSG
);
1788 *pmsg
++ = htons(0x000e);
1789 *pmsg
++ = htons(info
->DSP_TIME
[0]);
1790 *pmsg
++ = htons(info
->DSP_TIME
[1]);
1791 *pmsg
++ = htons(info
->DSP_TIME
[2]);
1792 *pmsg
++ = htons(info
->DSP_TIME
[3]);
1793 convert
.byte
[0] = info
->DspVer
[0];
1794 convert
.byte
[1] = info
->DspVer
[1];
1795 *pmsg
++ = convert
.wrd
;
1796 convert
.byte
[0] = info
->DspVer
[2];
1797 convert
.byte
[1] = info
->DspVer
[3];
1798 *pmsg
++ = convert
.wrd
;
1799 *pmsg
++ = htons(info
->DrvErrNum
);
1801 card_send_command (dev
, (unsigned char*)&tempbuffer
[0], (u16
)(0x0012 + PSEUDOSZ
));
1802 info
->DrvErrNum
= 0;
1804 info
->DrvMsgPend
= 0;
1814 status
= STATUS_SUCCESS
;
1817 DEBUG("return from ft1000_proc_drvmsg\n");
1823 int ft1000_poll(void* dev_id
) {
1825 struct ft1000_device
*dev
= (struct ft1000_device
*)dev_id
;
1826 struct ft1000_info
*info
= netdev_priv(dev
->net
);
1836 struct dpram_blk
*pdpram_blk
;
1837 struct pseudo_hdr
*ppseudo_hdr
;
1838 unsigned long flags
;
1840 //DEBUG("Enter ft1000_poll...\n");
1841 if (ft1000_chkcard(dev
) == FALSE
) {
1842 DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
1843 return STATUS_FAILURE
;
1846 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_DOORBELL
);
1847 // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword);
1852 if (tempword
& FT1000_DB_DPRAM_RX
) {
1853 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n");
1855 status
= ft1000_read_dpram16(dev
, 0x200, (u8
*)&data
, 0);
1856 //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data);
1857 size
= ntohs(data
) + 16 + 2; //wai
1859 modulo
= 4 - (size
% 4);
1860 size
= size
+ modulo
;
1862 status
= ft1000_read_dpram16(dev
, 0x201, (u8
*)&portid
, 1);
1864 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid);
1866 if (size
< MAX_CMD_SQSIZE
) {
1870 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
1872 status
= ft1000_proc_drvmsg (dev
, size
);
1873 if (status
!= STATUS_SUCCESS
)
1877 // This is a dsp broadcast message
1878 // Check which application has registered for dsp broadcast messages
1879 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n");
1881 for (i
=0; i
<MAX_NUM_APP
; i
++) {
1882 if ( (info
->app_info
[i
].DspBCMsgFlag
) && (info
->app_info
[i
].fileobject
) &&
1883 (info
->app_info
[i
].NumOfMsg
< MAX_MSG_LIMIT
) )
1885 //DEBUG("Dsp broadcast message detected for app id %d\n", i);
1886 nxtph
= FT1000_DPRAM_RX_BASE
+ 2;
1887 pdpram_blk
= ft1000_get_buffer (&freercvpool
);
1888 if (pdpram_blk
!= NULL
) {
1889 if ( ft1000_receive_cmd(dev
, pdpram_blk
->pbuffer
, MAX_CMD_SQSIZE
, &nxtph
) ) {
1890 ppseudo_hdr
= (struct pseudo_hdr
*)pdpram_blk
->pbuffer
;
1891 // Put message into the appropriate application block
1892 info
->app_info
[i
].nRxMsg
++;
1893 spin_lock_irqsave(&free_buff_lock
, flags
);
1894 list_add_tail(&pdpram_blk
->list
, &info
->app_info
[i
].app_sqlist
);
1895 info
->app_info
[i
].NumOfMsg
++;
1896 spin_unlock_irqrestore(&free_buff_lock
, flags
);
1897 wake_up_interruptible(&info
->app_info
[i
].wait_dpram_msg
);
1900 info
->app_info
[i
].nRxMsgMiss
++;
1901 // Put memory back to free pool
1902 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
1903 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
1907 DEBUG("Out of memory in free receive command pool\n");
1908 info
->app_info
[i
].nRxMsgMiss
++;
1909 }//endof if (pdpram_blk != NULL)
1912 // DEBUG("app_info mismatch\n");
1916 pdpram_blk
= ft1000_get_buffer (&freercvpool
);
1917 //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk);
1918 if (pdpram_blk
!= NULL
) {
1919 if ( ft1000_receive_cmd(dev
, pdpram_blk
->pbuffer
, MAX_CMD_SQSIZE
, &nxtph
) ) {
1920 ppseudo_hdr
= (struct pseudo_hdr
*)pdpram_blk
->pbuffer
;
1921 // Search for correct application block
1922 for (i
=0; i
<MAX_NUM_APP
; i
++) {
1923 if (info
->app_info
[i
].app_id
== ppseudo_hdr
->portdest
) {
1928 if (i
== MAX_NUM_APP
) {
1929 DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr
->portdest
);
1930 // Put memory back to free pool
1931 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
1934 if (info
->app_info
[i
].NumOfMsg
> MAX_MSG_LIMIT
) {
1935 // Put memory back to free pool
1936 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
1939 info
->app_info
[i
].nRxMsg
++;
1940 // Put message into the appropriate application block
1941 //pxu spin_lock_irqsave(&free_buff_lock, flags);
1942 list_add_tail(&pdpram_blk
->list
, &info
->app_info
[i
].app_sqlist
);
1943 info
->app_info
[i
].NumOfMsg
++;
1944 //pxu spin_unlock_irqrestore(&free_buff_lock, flags);
1945 //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
1950 // Put memory back to free pool
1951 ft1000_free_buffer(pdpram_blk
, &freercvpool
);
1955 DEBUG("Out of memory in free receive command pool\n");
1959 } //endof if (size < MAX_CMD_SQSIZE)
1961 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size
);
1963 status
= ft1000_write_register (dev
, FT1000_DB_DPRAM_RX
, FT1000_REG_DOORBELL
);
1965 else if (tempword
& FT1000_DSP_ASIC_RESET
) {
1966 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DSP_ASIC_RESET\n");
1968 // Let's reset the ASIC from the Host side as well
1969 status
= ft1000_write_register (dev
, ASIC_RESET_BIT
, FT1000_REG_RESET
);
1970 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_RESET
);
1972 while (tempword
& ASIC_RESET_BIT
) {
1973 status
= ft1000_read_register (dev
, &tempword
, FT1000_REG_RESET
);
1980 DEBUG("Unable to reset ASIC\n");
1981 return STATUS_SUCCESS
;
1984 // Program WMARK register
1985 status
= ft1000_write_register (dev
, 0x600, FT1000_REG_MAG_WATERMARK
);
1986 // clear ASIC reset doorbell
1987 status
= ft1000_write_register (dev
, FT1000_DSP_ASIC_RESET
, FT1000_REG_DOORBELL
);
1990 else if (tempword
& FT1000_ASIC_RESET_REQ
) {
1991 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
1993 // clear ASIC reset request from DSP
1994 status
= ft1000_write_register (dev
, FT1000_ASIC_RESET_REQ
, FT1000_REG_DOORBELL
);
1995 status
= ft1000_write_register (dev
, HOST_INTF_BE
, FT1000_REG_SUP_CTRL
);
1996 // copy dsp session record from Adapter block
1997 status
= ft1000_write_dpram32 (dev
, 0, (u8
*)&info
->DSPSess
.Rec
[0], 1024);
1998 // Program WMARK register
1999 status
= ft1000_write_register (dev
, 0x600, FT1000_REG_MAG_WATERMARK
);
2000 // ring doorbell to tell DSP that ASIC is out of reset
2001 status
= ft1000_write_register (dev
, FT1000_ASIC_RESET_DSP
, FT1000_REG_DOORBELL
);
2003 else if (tempword
& FT1000_DB_COND_RESET
) {
2004 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
2006 // Reset ASIC and DSP
2008 if (info
->fAppMsgPend
== 0) {
2009 // Reset ASIC and DSP
2011 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER0
, (u8
*)&(info
->DSP_TIME
[0]), FT1000_MAG_DSP_TIMER0_INDX
);
2012 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER1
, (u8
*)&(info
->DSP_TIME
[1]), FT1000_MAG_DSP_TIMER1_INDX
);
2013 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER2
, (u8
*)&(info
->DSP_TIME
[2]), FT1000_MAG_DSP_TIMER2_INDX
);
2014 status
= ft1000_read_dpram16(dev
, FT1000_MAG_DSP_TIMER3
, (u8
*)&(info
->DSP_TIME
[3]), FT1000_MAG_DSP_TIMER3_INDX
);
2015 info
->CardReady
= 0;
2016 info
->DrvErrNum
= DSP_CONDRESET_INFO
;
2017 DEBUG("ft1000_hw:DSP conditional reset requested\n");
2018 info
->ft1000_reset(dev
->net
);
2021 info
->fProvComplete
= 0;
2022 info
->fCondResetPend
= 1;
2025 ft1000_write_register(dev
, FT1000_DB_COND_RESET
, FT1000_REG_DOORBELL
);
2028 }//endof if ( !status )
2030 //DEBUG("return from ft1000_poll.\n");
2031 return STATUS_SUCCESS
;