1 //=====================================================
2 // CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
5 // This file is part of Express Card USB Driver
8 //====================================================
9 #include <linux/init.h>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/netdevice.h>
13 #include <linux/etherdevice.h>
14 #include <linux/usb.h>
15 #include "ft1000_usb.h"
16 #include <linux/types.h>
18 #define HARLEY_READ_REGISTER 0x0
19 #define HARLEY_WRITE_REGISTER 0x01
20 #define HARLEY_READ_DPRAM_32 0x02
21 #define HARLEY_READ_DPRAM_LOW 0x03
22 #define HARLEY_READ_DPRAM_HIGH 0x04
23 #define HARLEY_WRITE_DPRAM_32 0x05
24 #define HARLEY_WRITE_DPRAM_LOW 0x06
25 #define HARLEY_WRITE_DPRAM_HIGH 0x07
27 #define HARLEY_READ_OPERATION 0xc1
28 #define HARLEY_WRITE_OPERATION 0x41
32 static int ft1000_reset(struct net_device *ft1000dev);
33 static int ft1000_submit_rx_urb(struct ft1000_info *info);
34 static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev);
35 static int ft1000_open (struct net_device *dev);
36 static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev);
37 static int ft1000_chkcard (struct ft1000_device *dev);
39 static u8 tempbuffer[1600];
41 #define MAX_RCV_LOOP 100
43 //---------------------------------------------------------------------------
44 // Function: ft1000_control
46 // Parameters: ft1000_device - device structure
47 // pipe - usb control message pipe
48 // request - control request
49 // requesttype - control message request type
50 // value - value to be written or 0
51 // index - register index
52 // data - data buffer to hold the read/write values
54 // timeout - control message time out value
56 // Returns: STATUS_SUCCESS - success
57 // STATUS_FAILURE - failure
59 // Description: This function sends a control message via USB interface synchronously
63 //---------------------------------------------------------------------------
64 static int ft1000_control(struct ft1000_device *ft1000dev, unsigned int pipe,
65 u8 request, u8 requesttype, u16 value, u16 index,
66 void *data, u16 size, int timeout)
70 if ((ft1000dev == NULL) || (ft1000dev->dev == NULL)) {
71 DEBUG("ft1000dev or ft1000dev->dev == NULL, failure\n");
75 ret = usb_control_msg(ft1000dev->dev, pipe, request, requesttype,
76 value, index, data, size, LARGE_TIMEOUT);
84 //---------------------------------------------------------------------------
85 // Function: ft1000_read_register
87 // Parameters: ft1000_device - device structure
88 // Data - data buffer to hold the value read
89 // nRegIndex - register index
91 // Returns: STATUS_SUCCESS - success
92 // STATUS_FAILURE - failure
94 // Description: This function returns the value in a register
98 //---------------------------------------------------------------------------
100 int ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data,
103 int ret = STATUS_SUCCESS;
105 ret = ft1000_control(ft1000dev,
106 usb_rcvctrlpipe(ft1000dev->dev, 0),
107 HARLEY_READ_REGISTER,
108 HARLEY_READ_OPERATION,
118 //---------------------------------------------------------------------------
119 // Function: ft1000_write_register
121 // Parameters: ft1000_device - device structure
122 // value - value to write into a register
123 // nRegIndex - register index
125 // Returns: STATUS_SUCCESS - success
126 // STATUS_FAILURE - failure
128 // Description: This function writes the value in a register
132 //---------------------------------------------------------------------------
133 int ft1000_write_register(struct ft1000_device *ft1000dev, u16 value,
136 int ret = STATUS_SUCCESS;
138 ret = ft1000_control(ft1000dev,
139 usb_sndctrlpipe(ft1000dev->dev, 0),
140 HARLEY_WRITE_REGISTER,
141 HARLEY_WRITE_OPERATION,
151 //---------------------------------------------------------------------------
152 // Function: ft1000_read_dpram32
154 // Parameters: ft1000_device - device structure
155 // indx - starting address to read
156 // buffer - data buffer to hold the data read
157 // cnt - number of byte read from DPRAM
159 // Returns: STATUS_SUCCESS - success
160 // STATUS_FAILURE - failure
162 // Description: This function read a number of bytes from DPRAM
166 //---------------------------------------------------------------------------
168 int ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
171 int ret = STATUS_SUCCESS;
173 ret = ft1000_control(ft1000dev,
174 usb_rcvctrlpipe(ft1000dev->dev, 0),
175 HARLEY_READ_DPRAM_32,
176 HARLEY_READ_OPERATION,
186 //---------------------------------------------------------------------------
187 // Function: ft1000_write_dpram32
189 // Parameters: ft1000_device - device structure
190 // indx - starting address to write the data
191 // buffer - data buffer to write into DPRAM
192 // cnt - number of bytes to write
194 // Returns: STATUS_SUCCESS - success
195 // STATUS_FAILURE - failure
197 // Description: This function writes into DPRAM a number of bytes
201 //---------------------------------------------------------------------------
202 int ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
205 int ret = STATUS_SUCCESS;
208 cnt += cnt - (cnt % 4);
210 ret = ft1000_control(ft1000dev,
211 usb_sndctrlpipe(ft1000dev->dev, 0),
212 HARLEY_WRITE_DPRAM_32,
213 HARLEY_WRITE_OPERATION,
223 //---------------------------------------------------------------------------
224 // Function: ft1000_read_dpram16
226 // Parameters: ft1000_device - device structure
227 // indx - starting address to read
228 // buffer - data buffer to hold the data read
229 // hightlow - high or low 16 bit word
231 // Returns: STATUS_SUCCESS - success
232 // STATUS_FAILURE - failure
234 // Description: This function read 16 bits from DPRAM
238 //---------------------------------------------------------------------------
239 int ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
242 int ret = STATUS_SUCCESS;
246 request = HARLEY_READ_DPRAM_LOW;
248 request = HARLEY_READ_DPRAM_HIGH;
250 ret = ft1000_control(ft1000dev,
251 usb_rcvctrlpipe(ft1000dev->dev, 0),
253 HARLEY_READ_OPERATION,
263 //---------------------------------------------------------------------------
264 // Function: ft1000_write_dpram16
266 // Parameters: ft1000_device - device structure
267 // indx - starting address to write the data
268 // value - 16bits value to write
269 // hightlow - high or low 16 bit word
271 // Returns: STATUS_SUCCESS - success
272 // STATUS_FAILURE - failure
274 // Description: This function writes into DPRAM a number of bytes
278 //---------------------------------------------------------------------------
279 int ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u8 highlow)
281 int ret = STATUS_SUCCESS;
285 request = HARLEY_WRITE_DPRAM_LOW;
287 request = HARLEY_WRITE_DPRAM_HIGH;
289 ret = ft1000_control(ft1000dev,
290 usb_sndctrlpipe(ft1000dev->dev, 0),
292 HARLEY_WRITE_OPERATION,
302 //---------------------------------------------------------------------------
303 // Function: fix_ft1000_read_dpram32
305 // Parameters: ft1000_device - device structure
306 // indx - starting address to read
307 // buffer - data buffer to hold the data read
310 // Returns: STATUS_SUCCESS - success
311 // STATUS_FAILURE - failure
313 // Description: This function read DPRAM 4 words at a time
317 //---------------------------------------------------------------------------
318 int fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx,
323 int ret = STATUS_SUCCESS;
325 pos = (indx / 4) * 4;
326 ret = ft1000_read_dpram32(ft1000dev, pos, buf, 16);
328 if (ret == STATUS_SUCCESS) {
329 pos = (indx % 4) * 4;
330 *buffer++ = buf[pos++];
331 *buffer++ = buf[pos++];
332 *buffer++ = buf[pos++];
333 *buffer++ = buf[pos++];
335 DEBUG("fix_ft1000_read_dpram32: DPRAM32 Read failed\n");
346 //---------------------------------------------------------------------------
347 // Function: fix_ft1000_write_dpram32
349 // Parameters: ft1000_device - device structure
350 // indx - starting address to write
351 // buffer - data buffer to write
354 // Returns: STATUS_SUCCESS - success
355 // STATUS_FAILURE - failure
357 // Description: This function write to DPRAM 4 words at a time
361 //---------------------------------------------------------------------------
362 int fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer)
370 int ret = STATUS_SUCCESS;
372 pos1 = (indx / 4) * 4;
374 ret = ft1000_read_dpram32(ft1000dev, pos1, buf, 16);
376 if (ret == STATUS_SUCCESS) {
378 buf[pos2++] = *buffer++;
379 buf[pos2++] = *buffer++;
380 buf[pos2++] = *buffer++;
381 buf[pos2++] = *buffer++;
382 ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16);
384 DEBUG("fix_ft1000_write_dpram32: DPRAM32 Read failed\n");
388 ret = ft1000_read_dpram32(ft1000dev, pos1, (u8 *)&resultbuffer[0], 16);
390 if (ret == STATUS_SUCCESS) {
392 for (i = 0; i < 16; i++) {
393 if (buf[i] != resultbuffer[i])
394 ret = STATUS_FAILURE;
398 if (ret == STATUS_FAILURE) {
399 ret = ft1000_write_dpram32(ft1000dev, pos1,
400 (u8 *)&tempbuffer[0], 16);
401 ret = ft1000_read_dpram32(ft1000dev, pos1,
402 (u8 *)&resultbuffer[0], 16);
403 if (ret == STATUS_SUCCESS) {
405 for (i = 0; i < 16; i++) {
406 if (tempbuffer[i] != resultbuffer[i]) {
407 ret = STATUS_FAILURE;
408 DEBUG("%s Failed to write\n",
419 //------------------------------------------------------------------------
421 // Function: card_reset_dsp
423 // Synopsis: This function is called to reset or activate the DSP
425 // Arguments: value - reset or activate
428 //-----------------------------------------------------------------------
429 static void card_reset_dsp(struct ft1000_device *ft1000dev, bool value)
431 u16 status = STATUS_SUCCESS;
434 status = ft1000_write_register(ft1000dev, HOST_INTF_BE,
435 FT1000_REG_SUP_CTRL);
436 status = ft1000_read_register(ft1000dev, &tempword,
437 FT1000_REG_SUP_CTRL);
440 DEBUG("Reset DSP\n");
441 status = ft1000_read_register(ft1000dev, &tempword,
443 tempword |= DSP_RESET_BIT;
444 status = ft1000_write_register(ft1000dev, tempword,
447 DEBUG("Activate DSP\n");
448 status = ft1000_read_register(ft1000dev, &tempword,
450 tempword |= DSP_ENCRYPTED;
451 tempword &= ~DSP_UNENCRYPTED;
452 status = ft1000_write_register(ft1000dev, tempword,
454 status = ft1000_read_register(ft1000dev, &tempword,
456 tempword &= ~EFUSE_MEM_DISABLE;
457 tempword &= ~DSP_RESET_BIT;
458 status = ft1000_write_register(ft1000dev, tempword,
460 status = ft1000_read_register(ft1000dev, &tempword,
465 //---------------------------------------------------------------------------
466 // Function: card_send_command
468 // Parameters: ft1000_device - device structure
469 // ptempbuffer - command buffer
470 // size - command buffer size
472 // Returns: STATUS_SUCCESS - success
473 // STATUS_FAILURE - failure
475 // Description: This function sends a command to ASIC
479 //---------------------------------------------------------------------------
480 void card_send_command(struct ft1000_device *ft1000dev, void *ptempbuffer,
484 unsigned char *commandbuf;
486 DEBUG("card_send_command: enter card_send_command... size=%d\n", size);
488 commandbuf = kmalloc(size + 2, GFP_KERNEL);
489 memcpy((void *)commandbuf + 2, (void *)ptempbuffer, size);
491 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
496 /* check for odd word */
499 /* Must force to be 32 bit aligned */
501 size += 4 - (size % 4);
503 ft1000_write_dpram32(ft1000dev, 0, commandbuf, size);
505 ft1000_write_register(ft1000dev, FT1000_DB_DPRAM_TX,
506 FT1000_REG_DOORBELL);
509 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
511 if ((temp & 0x0100) == 0) {
512 //DEBUG("card_send_command: Message sent\n");
517 //--------------------------------------------------------------------------
519 // Function: dsp_reload
521 // Synopsis: This function is called to load or reload the DSP
523 // Arguments: ft1000dev - device structure
526 //-----------------------------------------------------------------------
527 int dsp_reload(struct ft1000_device *ft1000dev)
533 struct ft1000_info *pft1000info;
535 pft1000info = netdev_priv(ft1000dev->net);
537 pft1000info->CardReady = 0;
539 /* Program Interrupt Mask register */
540 status = ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_SUP_IMASK);
542 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
543 tempword |= ASIC_RESET_BIT;
544 status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
546 status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
547 DEBUG("Reset Register = 0x%x\n", tempword);
549 /* Toggle DSP reset */
550 card_reset_dsp(ft1000dev, 1);
552 card_reset_dsp(ft1000dev, 0);
556 ft1000_write_register(ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
558 /* Let's check for FEFE */
560 ft1000_read_dpram32(ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX,
561 (u8 *) &templong, 4);
562 DEBUG("templong (fefe) = 0x%8x\n", templong);
564 /* call codeloader */
565 status = scram_dnldr(ft1000dev, pFileStart, FileLength);
567 if (status != STATUS_SUCCESS)
572 DEBUG("dsp_reload returned\n");
577 //---------------------------------------------------------------------------
579 // Function: ft1000_reset_asic
580 // Description: This function will call the Card Service function to reset the
583 // dev - device structure
587 //---------------------------------------------------------------------------
588 static void ft1000_reset_asic(struct net_device *dev)
590 struct ft1000_info *info = netdev_priv(dev);
591 struct ft1000_device *ft1000dev = info->pFt1000Dev;
594 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
596 /* Let's use the register provided by the Magnemite ASIC to reset the
599 ft1000_write_register(ft1000dev, (DSP_RESET_BIT | ASIC_RESET_BIT),
604 /* set watermark to -1 in order to not generate an interrupt */
605 ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_MAG_WATERMARK);
607 /* clear interrupts */
608 ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_ISR);
609 DEBUG("ft1000_hw: interrupt status register = 0x%x\n", tempword);
610 ft1000_write_register(ft1000dev, tempword, FT1000_REG_SUP_ISR);
611 ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_ISR);
612 DEBUG("ft1000_hw: interrupt status register = 0x%x\n", tempword);
616 //---------------------------------------------------------------------------
618 // Function: ft1000_reset_card
619 // Description: This function will reset the card
621 // dev - device structure
623 // status - FALSE (card reset fail)
624 // TRUE (card reset successful)
626 //---------------------------------------------------------------------------
627 static int ft1000_reset_card(struct net_device *dev)
629 struct ft1000_info *info = netdev_priv(dev);
630 struct ft1000_device *ft1000dev = info->pFt1000Dev;
632 struct prov_record *ptr;
634 DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
636 info->fCondResetPend = 1;
638 info->fProvComplete = 0;
640 /* Make sure we free any memory reserve for provisioning */
641 while (list_empty(&info->prov_list) == 0) {
642 DEBUG("ft1000_reset_card:deleting provisioning record\n");
644 list_entry(info->prov_list.next, struct prov_record, list);
645 list_del(&ptr->list);
646 kfree(ptr->pprov_data);
650 DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n");
651 ft1000_reset_asic(dev);
653 DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n");
654 dsp_reload(ft1000dev);
656 DEBUG("dsp reload successful\n");
660 /* Initialize DSP heartbeat area */
661 ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag,
662 FT1000_MAG_HI_HO_INDX);
663 ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (u8 *) &tempword,
664 FT1000_MAG_HI_HO_INDX);
665 DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword);
669 info->fCondResetPend = 0;
674 static const struct net_device_ops ftnet_ops =
676 .ndo_open = &ft1000_open,
677 .ndo_stop = &ft1000_close,
678 .ndo_start_xmit = &ft1000_start_xmit,
679 .ndo_get_stats = &ft1000_netdev_stats,
683 //---------------------------------------------------------------------------
684 // Function: init_ft1000_netdev
686 // Parameters: ft1000dev - device structure
689 // Returns: STATUS_SUCCESS - success
690 // STATUS_FAILURE - failure
692 // Description: This function initialize the network device
696 //---------------------------------------------------------------------------
697 int init_ft1000_netdev(struct ft1000_device *ft1000dev)
699 struct net_device *netdev;
700 struct ft1000_info *pInfo = NULL;
701 struct dpram_blk *pdpram_blk;
703 struct list_head *cur, *tmp;
705 unsigned long gCardIndex = 0;
707 DEBUG("Enter init_ft1000_netdev...\n");
709 netdev = alloc_etherdev(sizeof(struct ft1000_info));
711 DEBUG("init_ft1000_netdev: can not allocate network device\n");
715 pInfo = netdev_priv(netdev);
717 memset(pInfo, 0, sizeof(struct ft1000_info));
719 dev_alloc_name(netdev, netdev->name);
721 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name);
723 if (strncmp(netdev->name, "eth", 3) == 0) {
724 card_nr[0] = netdev->name[3];
726 ret_val = strict_strtoul(card_nr, 10, &gCardIndex);
728 printk(KERN_ERR "Can't parse netdev\n");
732 pInfo->CardNumber = gCardIndex;
733 DEBUG("card number = %d\n", pInfo->CardNumber);
735 printk(KERN_ERR "ft1000: Invalid device name\n");
740 memset(&pInfo->stats, 0, sizeof(struct net_device_stats));
742 spin_lock_init(&pInfo->dpram_lock);
743 pInfo->pFt1000Dev = ft1000dev;
744 pInfo->DrvErrNum = 0;
745 pInfo->registered = 1;
746 pInfo->ft1000_reset = ft1000_reset;
747 pInfo->mediastate = 0;
749 pInfo->DeviceCreated = FALSE;
750 pInfo->CardReady = 0;
751 pInfo->DSP_TIME[0] = 0;
752 pInfo->DSP_TIME[1] = 0;
753 pInfo->DSP_TIME[2] = 0;
754 pInfo->DSP_TIME[3] = 0;
755 pInfo->fAppMsgPend = 0;
756 pInfo->fCondResetPend = 0;
759 memset(&pInfo->tempbuf[0], 0, sizeof(pInfo->tempbuf));
761 INIT_LIST_HEAD(&pInfo->prov_list);
763 INIT_LIST_HEAD(&pInfo->nodes.list);
765 netdev->netdev_ops = &ftnet_ops;
767 ft1000dev->net = netdev;
769 DEBUG("Initialize free_buff_lock and freercvpool\n");
770 spin_lock_init(&free_buff_lock);
772 /* initialize a list of buffers to be use for queuing
773 * up receive command data
775 INIT_LIST_HEAD(&freercvpool);
777 /* create list of free buffers */
778 for (i = 0; i < NUM_OF_FREE_BUFFERS; i++) {
779 /* Get memory for DPRAM_DATA link list */
780 pdpram_blk = kmalloc(sizeof(struct dpram_blk), GFP_KERNEL);
781 if (pdpram_blk == NULL) {
785 /* Get a block of memory to store command data */
786 pdpram_blk->pbuffer = kmalloc(MAX_CMD_SQSIZE, GFP_KERNEL);
787 if (pdpram_blk->pbuffer == NULL) {
792 /* link provisioning data */
793 list_add_tail(&pdpram_blk->list, &freercvpool);
795 numofmsgbuf = NUM_OF_FREE_BUFFERS;
800 list_for_each_safe(cur, tmp, &freercvpool) {
801 pdpram_blk = list_entry(cur, struct dpram_blk, list);
802 list_del(&pdpram_blk->list);
803 kfree(pdpram_blk->pbuffer);
811 //---------------------------------------------------------------------------
812 // Function: reg_ft1000_netdev
814 // Parameters: ft1000dev - device structure
817 // Returns: STATUS_SUCCESS - success
818 // STATUS_FAILURE - failure
820 // Description: This function register the network driver
824 //---------------------------------------------------------------------------
825 int reg_ft1000_netdev(struct ft1000_device *ft1000dev,
826 struct usb_interface *intf)
828 struct net_device *netdev;
829 struct ft1000_info *pInfo;
832 netdev = ft1000dev->net;
833 pInfo = netdev_priv(ft1000dev->net);
834 DEBUG("Enter reg_ft1000_netdev...\n");
836 ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID);
838 usb_set_intfdata(intf, pInfo);
839 SET_NETDEV_DEV(netdev, &intf->dev);
841 rc = register_netdev(netdev);
843 DEBUG("reg_ft1000_netdev: could not register network device\n");
848 ft1000_create_dev(ft1000dev);
850 DEBUG("reg_ft1000_netdev returned\n");
852 pInfo->CardReady = 1;
857 static int ft1000_reset(struct net_device *dev)
859 ft1000_reset_card(dev);
863 //---------------------------------------------------------------------------
864 // Function: ft1000_usb_transmit_complete
866 // Parameters: urb - transmitted usb urb
871 // Description: This is the callback function when a urb is transmitted
875 //---------------------------------------------------------------------------
876 static void ft1000_usb_transmit_complete(struct urb *urb)
879 struct ft1000_device *ft1000dev = urb->context;
882 pr_err("%s: TX status %d\n", ft1000dev->net->name, urb->status);
884 netif_wake_queue(ft1000dev->net);
887 //---------------------------------------------------------------------------
889 // Function: ft1000_copy_down_pkt
890 // Description: This function will take an ethernet packet and convert it to
891 // a Flarion packet prior to sending it to the ASIC Downlink
894 // dev - device structure
895 // packet - address of ethernet packet
896 // len - length of IP packet
901 //---------------------------------------------------------------------------
902 static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len)
904 struct ft1000_info *pInfo = netdev_priv(netdev);
905 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
909 struct pseudo_hdr hdr;
911 if (!pInfo->CardReady) {
912 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
916 count = sizeof(struct pseudo_hdr) + len;
917 if (count > MAX_BUF_SIZE) {
918 DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n");
919 DEBUG("size = %d\n", count);
924 count = count + (4 - (count % 4));
926 memset(&hdr, 0, sizeof(struct pseudo_hdr));
928 hdr.length = ntohs(count);
930 hdr.destination = 0x20;
933 hdr.sh_str_id = 0x91;
936 hdr.checksum = hdr.length ^ hdr.source ^ hdr.destination ^
937 hdr.portdest ^ hdr.portsrc ^ hdr.sh_str_id ^ hdr.control;
939 memcpy(&pFt1000Dev->tx_buf[0], &hdr, sizeof(hdr));
940 memcpy(&(pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)]), packet, len);
942 netif_stop_queue(netdev);
944 usb_fill_bulk_urb(pFt1000Dev->tx_urb,
946 usb_sndbulkpipe(pFt1000Dev->dev,
947 pFt1000Dev->bulk_out_endpointAddr),
948 pFt1000Dev->tx_buf, count,
949 ft1000_usb_transmit_complete, (void *)pFt1000Dev);
951 t = (u8 *) pFt1000Dev->tx_urb->transfer_buffer;
953 ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC);
956 DEBUG("ft1000 failed tx_urb %d\n", ret);
959 pInfo->stats.tx_packets++;
960 pInfo->stats.tx_bytes += (len + 14);
967 //---------------------------------------------------------------------------
968 // Function: ft1000_start_xmit
970 // Parameters: skb - socket buffer to be sent
971 // dev - network device
976 // Description: transmit a ethernet packet
980 //---------------------------------------------------------------------------
981 static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
983 struct ft1000_info *pInfo = netdev_priv(dev);
984 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
989 DEBUG("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n");
993 if (pFt1000Dev->status & FT1000_STATUS_CLOSING) {
994 DEBUG("network driver is closed, return\n");
999 usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr);
1000 maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe));
1002 pdata = (u8 *) skb->data;
1004 if (pInfo->mediastate == 0) {
1005 /* Drop packet is mediastate is down */
1006 DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n");
1010 if ((skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE)) {
1011 /* Drop packet which has invalid size */
1012 DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n");
1016 ft1000_copy_down_pkt(dev, (pdata + ENET_HEADER_SIZE - 2),
1017 skb->len - ENET_HEADER_SIZE + 2);
1022 return NETDEV_TX_OK;
1026 //---------------------------------------------------------------------------
1028 // Function: ft1000_copy_up_pkt
1029 // Description: This function will take a packet from the FIFO up link and
1030 // convert it into an ethernet packet and deliver it to the IP stack
1032 // urb - the receiving usb urb
1038 //---------------------------------------------------------------------------
1039 static int ft1000_copy_up_pkt(struct urb *urb)
1041 struct ft1000_info *info = urb->context;
1042 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1043 struct net_device *net = ft1000dev->net;
1048 struct sk_buff *skb;
1054 if (ft1000dev->status & FT1000_STATUS_CLOSING) {
1055 DEBUG("network driver is closed, return\n");
1056 return STATUS_SUCCESS;
1059 len = urb->transfer_buffer_length;
1060 lena = urb->actual_length;
1062 chksum = (u16 *) ft1000dev->rx_buf;
1064 tempword = *chksum++;
1065 for (i = 1; i < 7; i++)
1066 tempword ^= *chksum++;
1068 if (tempword != *chksum) {
1069 info->stats.rx_errors++;
1070 ft1000_submit_rx_urb(info);
1071 return STATUS_FAILURE;
1074 skb = dev_alloc_skb(len + 12 + 2);
1077 DEBUG("ft1000_copy_up_pkt: No Network buffers available\n");
1078 info->stats.rx_errors++;
1079 ft1000_submit_rx_urb(info);
1080 return STATUS_FAILURE;
1083 pbuffer = (u8 *) skb_put(skb, len + 12);
1085 /* subtract the number of bytes read already */
1088 /* fake MAC address */
1089 *pbuffer++ = net->dev_addr[0];
1090 *pbuffer++ = net->dev_addr[1];
1091 *pbuffer++ = net->dev_addr[2];
1092 *pbuffer++ = net->dev_addr[3];
1093 *pbuffer++ = net->dev_addr[4];
1094 *pbuffer++ = net->dev_addr[5];
1102 memcpy(pbuffer, ft1000dev->rx_buf + sizeof(struct pseudo_hdr),
1103 len - sizeof(struct pseudo_hdr));
1107 skb->protocol = eth_type_trans(skb, net);
1108 skb->ip_summed = CHECKSUM_UNNECESSARY;
1111 info->stats.rx_packets++;
1112 /* Add on 12 bytes for MAC address which was removed */
1113 info->stats.rx_bytes += (lena + 12);
1115 ft1000_submit_rx_urb(info);
1121 //---------------------------------------------------------------------------
1123 // Function: ft1000_submit_rx_urb
1124 // Description: the receiving function of the network driver
1127 // info - a private structure contains the device information
1133 //---------------------------------------------------------------------------
1134 static int ft1000_submit_rx_urb(struct ft1000_info *info)
1137 struct ft1000_device *pFt1000Dev = info->pFt1000Dev;
1139 if (pFt1000Dev->status & FT1000_STATUS_CLOSING) {
1140 DEBUG("network driver is closed, return\n");
1144 usb_fill_bulk_urb(pFt1000Dev->rx_urb,
1146 usb_rcvbulkpipe(pFt1000Dev->dev,
1147 pFt1000Dev->bulk_in_endpointAddr),
1148 pFt1000Dev->rx_buf, MAX_BUF_SIZE,
1149 (usb_complete_t) ft1000_copy_up_pkt, info);
1151 result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC);
1154 pr_err("ft1000_submit_rx_urb: submitting rx_urb %d failed\n",
1163 //---------------------------------------------------------------------------
1164 // Function: ft1000_open
1167 // dev - network device
1172 // Description: open the network driver
1176 //---------------------------------------------------------------------------
1177 static int ft1000_open(struct net_device *dev)
1179 struct ft1000_info *pInfo = netdev_priv(dev);
1182 DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber);
1184 pInfo->stats.rx_bytes = 0;
1185 pInfo->stats.tx_bytes = 0;
1186 pInfo->stats.rx_packets = 0;
1187 pInfo->stats.tx_packets = 0;
1188 do_gettimeofday(&tv);
1189 pInfo->ConTm = tv.tv_sec;
1190 pInfo->ProgConStat = 0;
1192 netif_start_queue(dev);
1194 netif_carrier_on(dev);
1196 return ft1000_submit_rx_urb(pInfo);
1199 //---------------------------------------------------------------------------
1200 // Function: ft1000_close
1203 // net - network device
1208 // Description: close the network driver
1212 //---------------------------------------------------------------------------
1213 int ft1000_close(struct net_device *net)
1215 struct ft1000_info *pInfo = netdev_priv(net);
1216 struct ft1000_device *ft1000dev = pInfo->pFt1000Dev;
1218 ft1000dev->status |= FT1000_STATUS_CLOSING;
1220 DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);
1221 netif_carrier_off(net);
1222 netif_stop_queue(net);
1223 ft1000dev->status &= ~FT1000_STATUS_CLOSING;
1225 pInfo->ProgConStat = 0xff;
1230 static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev)
1232 struct ft1000_info *info = netdev_priv(dev);
1234 return &(info->stats);
1238 //---------------------------------------------------------------------------
1240 // Function: ft1000_chkcard
1241 // Description: This function will check if the device is presently available on
1244 // dev - device structure
1246 // status - FALSE (device is not present)
1247 // TRUE (device is present)
1249 //---------------------------------------------------------------------------
1250 static int ft1000_chkcard(struct ft1000_device *dev)
1254 struct ft1000_info *info = netdev_priv(dev->net);
1256 if (info->fCondResetPend) {
1258 ("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1261 /* Mask register is used to check for device presence since it is never
1264 status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK);
1265 if (tempword == 0) {
1267 ("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
1270 /* The system will return the value of 0xffff for the version register
1271 * if the device is not present.
1273 status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID);
1274 if (tempword != 0x1b01) {
1275 dev->status |= FT1000_STATUS_CLOSING;
1277 ("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
1283 //---------------------------------------------------------------------------
1285 // Function: ft1000_receive_cmd
1286 // Description: This function will read a message from the dpram area.
1288 // dev - network device structure
1289 // pbuffer - caller supply address to buffer
1290 // pnxtph - pointer to next pseudo header
1292 // Status = 0 (unsuccessful)
1295 //---------------------------------------------------------------------------
1296 static bool ft1000_receive_cmd(struct ft1000_device *dev, u16 *pbuffer,
1297 int maxsz, u16 *pnxtph)
1305 ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (u8 *) &size,
1306 FT1000_MAG_PH_LEN_INDX);
1307 size = ntohs(size) + PSEUDOSZ;
1309 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n",
1313 ppseudohdr = (u16 *) pbuffer;
1314 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE,
1315 FT1000_REG_DPRAM_ADDR);
1317 ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1319 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE + 1,
1320 FT1000_REG_DPRAM_ADDR);
1321 for (i = 0; i <= (size >> 2); i++) {
1323 ft1000_read_register(dev, pbuffer,
1324 FT1000_REG_MAG_DPDATAL);
1327 ft1000_read_register(dev, pbuffer,
1328 FT1000_REG_MAG_DPDATAH);
1331 /* copy odd aligned word */
1333 ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
1337 ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1340 if (size & 0x0001) {
1341 /* copy odd byte from fifo */
1343 ft1000_read_register(dev, &tempword,
1344 FT1000_REG_DPRAM_DATA);
1345 *pbuffer = ntohs(tempword);
1347 /* Check if pseudo header checksum is good
1348 * Calculate pseudo header checksum
1350 tempword = *ppseudohdr++;
1351 for (i = 1; i < 7; i++)
1352 tempword ^= *ppseudohdr++;
1354 if ((tempword != *ppseudohdr))
1361 static int ft1000_dsp_prov(void *arg)
1363 struct ft1000_device *dev = (struct ft1000_device *)arg;
1364 struct ft1000_info *info = netdev_priv(dev->net);
1368 struct prov_record *ptr;
1369 struct pseudo_hdr *ppseudo_hdr;
1372 u16 TempShortBuf[256];
1374 DEBUG("*** DspProv Entered\n");
1376 while (list_empty(&info->prov_list) == 0) {
1377 DEBUG("DSP Provisioning List Entry\n");
1379 /* Check if doorbell is available */
1380 DEBUG("check if doorbell is cleared\n");
1382 ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1384 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n");
1388 while (tempword & FT1000_DB_DPRAM_TX) {
1392 DEBUG("FT1000:ft1000_dsp_prov:message drop\n");
1393 return STATUS_FAILURE;
1395 ft1000_read_register(dev, &tempword,
1396 FT1000_REG_DOORBELL);
1399 if (!(tempword & FT1000_DB_DPRAM_TX)) {
1400 DEBUG("*** Provision Data Sent to DSP\n");
1402 /* Send provisioning data */
1404 list_entry(info->prov_list.next, struct prov_record,
1406 len = *(u16 *) ptr->pprov_data;
1410 pmsg = (u16 *) ptr->pprov_data;
1411 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1412 /* Insert slow queue sequence number */
1413 ppseudo_hdr->seq_num = info->squeseqnum++;
1414 ppseudo_hdr->portsrc = 0;
1415 /* Calculate new checksum */
1416 ppseudo_hdr->checksum = *pmsg++;
1417 for (i = 1; i < 7; i++) {
1418 ppseudo_hdr->checksum ^= *pmsg++;
1421 TempShortBuf[0] = 0;
1422 TempShortBuf[1] = htons(len);
1423 memcpy(&TempShortBuf[2], ppseudo_hdr, len);
1426 ft1000_write_dpram32(dev, 0,
1427 (u8 *) &TempShortBuf[0],
1428 (unsigned short)(len + 2));
1430 ft1000_write_register(dev, FT1000_DB_DPRAM_TX,
1431 FT1000_REG_DOORBELL);
1433 list_del(&ptr->list);
1434 kfree(ptr->pprov_data);
1440 DEBUG("DSP Provisioning List Entry finished\n");
1444 info->fProvComplete = 1;
1445 info->CardReady = 1;
1447 return STATUS_SUCCESS;
1450 static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size)
1452 struct ft1000_info *info = netdev_priv(dev->net);
1455 struct media_msg *pmediamsg;
1456 struct dsp_init_msg *pdspinitmsg;
1457 struct drv_msg *pdrvmsg;
1459 struct pseudo_hdr *ppseudo_hdr;
1467 char *cmdbuffer = kmalloc(1600, GFP_KERNEL);
1469 return STATUS_FAILURE;
1471 status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size);
1474 DEBUG("ft1000_proc_drvmsg:cmdbuffer\n");
1475 for (i = 0; i < size; i += 5) {
1477 DEBUG("0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", cmdbuffer[i],
1478 cmdbuffer[i + 1], cmdbuffer[i + 2],
1479 cmdbuffer[i + 3], cmdbuffer[i + 4]);
1481 for (j = i; j < size; j++)
1482 DEBUG("0x%x ", cmdbuffer[j]);
1488 pdrvmsg = (struct drv_msg *)&cmdbuffer[2];
1489 msgtype = ntohs(pdrvmsg->type);
1490 DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype);
1494 ("ft1000_proc_drvmsg:Command message type = MEDIA_STATE");
1496 pmediamsg = (struct media_msg *)&cmdbuffer[0];
1497 if (info->ProgConStat != 0xFF) {
1498 if (pmediamsg->state) {
1499 DEBUG("Media is up\n");
1500 if (info->mediastate == 0) {
1501 if (info->NetDevRegDone) {
1502 netif_wake_queue(dev->
1505 info->mediastate = 1;
1508 DEBUG("Media is down\n");
1509 if (info->mediastate == 1) {
1510 info->mediastate = 0;
1511 if (info->NetDevRegDone) {
1517 DEBUG("Media is down\n");
1518 if (info->mediastate == 1) {
1519 info->mediastate = 0;
1527 ("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG");
1529 pdspinitmsg = (struct dsp_init_msg *)&cmdbuffer[2];
1530 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
1531 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n",
1532 info->DspVer[0], info->DspVer[1], info->DspVer[2],
1534 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum,
1536 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
1537 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
1538 DEBUG("EUI64=%2x.%2x.%2x.%2x.%2x.%2x.%2x.%2x\n",
1539 info->eui64[0], info->eui64[1], info->eui64[2],
1540 info->eui64[3], info->eui64[4], info->eui64[5],
1541 info->eui64[6], info->eui64[7]);
1542 dev->net->dev_addr[0] = info->eui64[0];
1543 dev->net->dev_addr[1] = info->eui64[1];
1544 dev->net->dev_addr[2] = info->eui64[2];
1545 dev->net->dev_addr[3] = info->eui64[5];
1546 dev->net->dev_addr[4] = info->eui64[6];
1547 dev->net->dev_addr[5] = info->eui64[7];
1549 if (ntohs(pdspinitmsg->length) ==
1550 (sizeof(struct dsp_init_msg) - 20)) {
1551 memcpy(info->ProductMode,
1552 pdspinitmsg->ProductMode, MODESZ);
1553 memcpy(info->RfCalVer, pdspinitmsg->RfCalVer,
1555 memcpy(info->RfCalDate, pdspinitmsg->RfCalDate,
1557 DEBUG("RFCalVer = 0x%2x 0x%2x\n",
1558 info->RfCalVer[0], info->RfCalVer[1]);
1562 case DSP_PROVISION:{
1564 ("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n");
1566 /* kick off dspprov routine to start provisioning
1567 * Send provisioning data to DSP
1569 if (list_empty(&info->prov_list) == 0) {
1570 info->fProvComplete = 0;
1571 status = ft1000_dsp_prov(dev);
1572 if (status != STATUS_SUCCESS)
1575 info->fProvComplete = 1;
1577 ft1000_write_register(dev, FT1000_DB_HB,
1578 FT1000_REG_DOORBELL);
1580 ("FT1000:drivermsg:No more DSP provisioning data in dsp image\n");
1582 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n");
1585 case DSP_STORE_INFO:{
1587 ("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO");
1589 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
1590 tempword = ntohs(pdrvmsg->length);
1591 info->DSPInfoBlklen = tempword;
1592 if (tempword < (MAX_DSP_SESS_REC - 4)) {
1593 pmsg = (u16 *) &pdrvmsg->data[0];
1594 for (i = 0; i < ((tempword + 1) / 2); i++) {
1596 ("FT1000:drivermsg:dsp info data = 0x%x\n",
1598 info->DSPInfoBlk[i + 10] = *pmsg++;
1601 info->DSPInfoBlklen = 0;
1606 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
1607 /* copy dsp info block to dsp */
1608 info->DrvMsgPend = 1;
1609 /* allow any outstanding ioctl to finish */
1612 ft1000_read_register(dev, &tempword,
1613 FT1000_REG_DOORBELL);
1614 if (tempword & FT1000_DB_DPRAM_TX) {
1617 ft1000_read_register(dev, &tempword,
1618 FT1000_REG_DOORBELL);
1619 if (tempword & FT1000_DB_DPRAM_TX) {
1622 ft1000_read_register(dev, &tempword,
1623 FT1000_REG_DOORBELL);
1624 if (tempword & FT1000_DB_DPRAM_TX)
1628 /* Put message into Slow Queue
1629 * Form Pseudo header
1631 pmsg = (u16 *) info->DSPInfoBlk;
1634 htons(info->DSPInfoBlklen + 20 +
1635 info->DSPInfoBlklen);
1637 (struct pseudo_hdr *)(u16 *) &info->DSPInfoBlk[2];
1638 ppseudo_hdr->length =
1639 htons(info->DSPInfoBlklen + 4 +
1640 info->DSPInfoBlklen);
1641 ppseudo_hdr->source = 0x10;
1642 ppseudo_hdr->destination = 0x20;
1643 ppseudo_hdr->portdest = 0;
1644 ppseudo_hdr->portsrc = 0;
1645 ppseudo_hdr->sh_str_id = 0;
1646 ppseudo_hdr->control = 0;
1647 ppseudo_hdr->rsvd1 = 0;
1648 ppseudo_hdr->rsvd2 = 0;
1649 ppseudo_hdr->qos_class = 0;
1650 /* Insert slow queue sequence number */
1651 ppseudo_hdr->seq_num = info->squeseqnum++;
1652 /* Insert application id */
1653 ppseudo_hdr->portsrc = 0;
1654 /* Calculate new checksum */
1655 ppseudo_hdr->checksum = *pmsg++;
1656 for (i = 1; i < 7; i++)
1657 ppseudo_hdr->checksum ^= *pmsg++;
1659 info->DSPInfoBlk[10] = 0x7200;
1660 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen);
1662 ft1000_write_dpram32(dev, 0,
1663 (u8 *) &info->DSPInfoBlk[0],
1664 (unsigned short)(info->
1668 ft1000_write_register(dev, FT1000_DB_DPRAM_TX,
1669 FT1000_REG_DOORBELL);
1670 info->DrvMsgPend = 0;
1675 case GET_DRV_ERR_RPT_MSG:{
1676 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
1677 /* copy driver error message to dsp */
1678 info->DrvMsgPend = 1;
1679 /* allow any outstanding ioctl to finish */
1682 ft1000_read_register(dev, &tempword,
1683 FT1000_REG_DOORBELL);
1684 if (tempword & FT1000_DB_DPRAM_TX) {
1687 ft1000_read_register(dev, &tempword,
1688 FT1000_REG_DOORBELL);
1689 if (tempword & FT1000_DB_DPRAM_TX)
1693 if ((tempword & FT1000_DB_DPRAM_TX) == 0) {
1694 /* Put message into Slow Queue
1695 * Form Pseudo header
1697 pmsg = (u16 *) &tempbuffer[0];
1698 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1699 ppseudo_hdr->length = htons(0x0012);
1700 ppseudo_hdr->source = 0x10;
1701 ppseudo_hdr->destination = 0x20;
1702 ppseudo_hdr->portdest = 0;
1703 ppseudo_hdr->portsrc = 0;
1704 ppseudo_hdr->sh_str_id = 0;
1705 ppseudo_hdr->control = 0;
1706 ppseudo_hdr->rsvd1 = 0;
1707 ppseudo_hdr->rsvd2 = 0;
1708 ppseudo_hdr->qos_class = 0;
1709 /* Insert slow queue sequence number */
1710 ppseudo_hdr->seq_num = info->squeseqnum++;
1711 /* Insert application id */
1712 ppseudo_hdr->portsrc = 0;
1713 /* Calculate new checksum */
1714 ppseudo_hdr->checksum = *pmsg++;
1715 for (i = 1; i < 7; i++)
1716 ppseudo_hdr->checksum ^= *pmsg++;
1718 pmsg = (u16 *) &tempbuffer[16];
1719 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
1720 *pmsg++ = htons(0x000e);
1721 *pmsg++ = htons(info->DSP_TIME[0]);
1722 *pmsg++ = htons(info->DSP_TIME[1]);
1723 *pmsg++ = htons(info->DSP_TIME[2]);
1724 *pmsg++ = htons(info->DSP_TIME[3]);
1725 convert.byte[0] = info->DspVer[0];
1726 convert.byte[1] = info->DspVer[1];
1727 *pmsg++ = convert.wrd;
1728 convert.byte[0] = info->DspVer[2];
1729 convert.byte[1] = info->DspVer[3];
1730 *pmsg++ = convert.wrd;
1731 *pmsg++ = htons(info->DrvErrNum);
1733 card_send_command(dev,
1734 (unsigned char *)&tempbuffer[0],
1735 (u16) (0x0012 + PSEUDOSZ));
1736 info->DrvErrNum = 0;
1738 info->DrvMsgPend = 0;
1747 status = STATUS_SUCCESS;
1750 DEBUG("return from ft1000_proc_drvmsg\n");
1754 int ft1000_poll(void* dev_id) {
1756 struct ft1000_device *dev = (struct ft1000_device *)dev_id;
1757 struct ft1000_info *info = netdev_priv(dev->net);
1767 struct dpram_blk *pdpram_blk;
1768 struct pseudo_hdr *ppseudo_hdr;
1769 unsigned long flags;
1771 if (ft1000_chkcard(dev) == FALSE) {
1772 DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
1773 return STATUS_FAILURE;
1776 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
1781 if (tempword & FT1000_DB_DPRAM_RX) {
1783 status = ft1000_read_dpram16(dev, 0x200, (u8 *)&data, 0);
1784 size = ntohs(data) + 16 + 2;
1786 modulo = 4 - (size % 4);
1787 size = size + modulo;
1789 status = ft1000_read_dpram16(dev, 0x201, (u8 *)&portid, 1);
1792 if (size < MAX_CMD_SQSIZE) {
1796 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
1798 status = ft1000_proc_drvmsg (dev, size);
1799 if (status != STATUS_SUCCESS )
1803 // This is a dsp broadcast message
1804 // Check which application has registered for dsp broadcast messages
1806 for (i=0; i<MAX_NUM_APP; i++) {
1807 if ( (info->app_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) &&
1808 (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT) )
1810 nxtph = FT1000_DPRAM_RX_BASE + 2;
1811 pdpram_blk = ft1000_get_buffer (&freercvpool);
1812 if (pdpram_blk != NULL) {
1813 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
1814 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
1815 // Put message into the appropriate application block
1816 info->app_info[i].nRxMsg++;
1817 spin_lock_irqsave(&free_buff_lock, flags);
1818 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
1819 info->app_info[i].NumOfMsg++;
1820 spin_unlock_irqrestore(&free_buff_lock, flags);
1821 wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
1824 info->app_info[i].nRxMsgMiss++;
1825 // Put memory back to free pool
1826 ft1000_free_buffer(pdpram_blk, &freercvpool);
1827 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
1831 DEBUG("Out of memory in free receive command pool\n");
1832 info->app_info[i].nRxMsgMiss++;
1838 pdpram_blk = ft1000_get_buffer (&freercvpool);
1840 if (pdpram_blk != NULL) {
1841 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
1842 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
1843 // Search for correct application block
1844 for (i=0; i<MAX_NUM_APP; i++) {
1845 if (info->app_info[i].app_id == ppseudo_hdr->portdest) {
1850 if (i == MAX_NUM_APP) {
1851 DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr->portdest);
1852 // Put memory back to free pool
1853 ft1000_free_buffer(pdpram_blk, &freercvpool);
1856 if (info->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
1857 // Put memory back to free pool
1858 ft1000_free_buffer(pdpram_blk, &freercvpool);
1861 info->app_info[i].nRxMsg++;
1862 // Put message into the appropriate application block
1863 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
1864 info->app_info[i].NumOfMsg++;
1869 // Put memory back to free pool
1870 ft1000_free_buffer(pdpram_blk, &freercvpool);
1874 DEBUG("Out of memory in free receive command pool\n");
1880 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size);
1882 status = ft1000_write_register (dev, FT1000_DB_DPRAM_RX, FT1000_REG_DOORBELL);
1884 else if (tempword & FT1000_DSP_ASIC_RESET) {
1886 // Let's reset the ASIC from the Host side as well
1887 status = ft1000_write_register (dev, ASIC_RESET_BIT, FT1000_REG_RESET);
1888 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
1890 while (tempword & ASIC_RESET_BIT) {
1891 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
1898 DEBUG("Unable to reset ASIC\n");
1899 return STATUS_SUCCESS;
1902 // Program WMARK register
1903 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
1904 // clear ASIC reset doorbell
1905 status = ft1000_write_register (dev, FT1000_DSP_ASIC_RESET, FT1000_REG_DOORBELL);
1908 else if (tempword & FT1000_ASIC_RESET_REQ) {
1909 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
1911 // clear ASIC reset request from DSP
1912 status = ft1000_write_register (dev, FT1000_ASIC_RESET_REQ, FT1000_REG_DOORBELL);
1913 status = ft1000_write_register (dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
1914 // copy dsp session record from Adapter block
1915 status = ft1000_write_dpram32 (dev, 0, (u8 *)&info->DSPSess.Rec[0], 1024);
1916 // Program WMARK register
1917 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
1918 // ring doorbell to tell DSP that ASIC is out of reset
1919 status = ft1000_write_register (dev, FT1000_ASIC_RESET_DSP, FT1000_REG_DOORBELL);
1921 else if (tempword & FT1000_DB_COND_RESET) {
1922 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
1924 if (info->fAppMsgPend == 0) {
1925 // Reset ASIC and DSP
1927 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (u8 *)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
1928 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (u8 *)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
1929 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (u8 *)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
1930 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (u8 *)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
1931 info->CardReady = 0;
1932 info->DrvErrNum = DSP_CONDRESET_INFO;
1933 DEBUG("ft1000_hw:DSP conditional reset requested\n");
1934 info->ft1000_reset(dev->net);
1937 info->fProvComplete = 0;
1938 info->fCondResetPend = 1;
1941 ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL);
1946 return STATUS_SUCCESS;