]> git.karo-electronics.de Git - mv-sheeva.git/blob - drivers/staging/ft1000/ft1000-usb/ft1000_hw.c
Staging: Merge Ben Collins solo6x10 tree with upstream
[mv-sheeva.git] / drivers / staging / ft1000 / ft1000-usb / ft1000_hw.c
1 //=====================================================
2 // CopyRight (C) 2007 Qualcomm Inc. All Rights Reserved.
3 //
4 //
5 // This file is part of Express Card USB Driver
6 //
7 // $Id:
8 //====================================================
9 // 20090926; aelias; removed compiler warnings & errors; ubuntu 9.04; 2.6.28-15-generic
10
11 #include <linux/init.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/netdevice.h>
15 #include <linux/etherdevice.h>
16 #include <linux/usb.h>
17 #include "ft1000_usb.h"
18 #include <linux/types.h>
19
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
28
29 #define HARLEY_READ_OPERATION    0xc1
30 #define HARLEY_WRITE_OPERATION   0x41
31
32 //#define JDEBUG
33
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);
40
41 //Jim
42
43 static u8 tempbuffer[1600];
44 static unsigned long gCardIndex;
45
46 #define MAX_RCV_LOOP   100
47
48 //---------------------------------------------------------------------------
49 // Function:    ft1000_control
50 //
51 // Parameters:  ft1000_device  - device structure
52 //              pipe - usb control message pipe
53 //              request - control request
54 //              requesttype - control message request type
55 //              value - value to be written or 0
56 //              index - register index
57 //              data - data buffer to hold the read/write values
58 //              size - data size
59 //              timeout - control message time out value
60 //
61 // Returns:     STATUS_SUCCESS - success
62 //              STATUS_FAILURE - failure
63 //
64 // Description: This function sends a control message via USB interface synchronously
65 //
66 // Notes:
67 //
68 //---------------------------------------------------------------------------
69 static int ft1000_control(struct ft1000_device *ft1000dev,unsigned int pipe,
70                           u8 request,
71                           u8 requesttype,
72                           u16 value,
73                           u16 index,
74                           void *data,
75                           u16 size,
76                           int timeout)
77 {
78         u16 ret;
79
80     if (ft1000dev == NULL )
81     {
82         DEBUG("NULL ft1000dev, failure\n");
83         return -ENODEV;
84     }
85     else if ( ft1000dev->dev == NULL )
86     {
87         DEBUG("NULL ft1000dev->dev, failure\n");
88         return -ENODEV;
89     }
90
91     ret = usb_control_msg(ft1000dev->dev,
92                           pipe,
93                           request,
94                           requesttype,
95                           value,
96                           index,
97                           data,
98                           size,
99                           LARGE_TIMEOUT);
100
101         if (ret > 0)
102                 ret = 0;
103
104     return ret;
105
106
107 }
108 //---------------------------------------------------------------------------
109 // Function:    ft1000_read_register
110 //
111 // Parameters:  ft1000_device  - device structure
112 //              Data - data buffer to hold the value read
113 //              nRegIndex - register index
114 //
115 // Returns:     STATUS_SUCCESS - success
116 //              STATUS_FAILURE - failure
117 //
118 // Description: This function returns the value in a register
119 //
120 // Notes:
121 //
122 //---------------------------------------------------------------------------
123
124 u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx)
125 {
126     u16 ret = STATUS_SUCCESS;
127
128     //DEBUG("ft1000_read_register: reg index is %d\n", nRegIndx);
129     //DEBUG("ft1000_read_register: spin_lock locked\n");
130     ret = ft1000_control(ft1000dev,
131                          usb_rcvctrlpipe(ft1000dev->dev,0),
132                          HARLEY_READ_REGISTER,   //request --READ_REGISTER
133                          HARLEY_READ_OPERATION,  //requestType
134                          0,                      //value
135                          nRegIndx,               //index
136                          Data,                   //data
137                          2,                      //data size
138                          LARGE_TIMEOUT );        //timeout
139
140    //DEBUG("ft1000_read_register: ret is  %d \n", ret);
141
142    //DEBUG("ft1000_read_register: data is  %x \n", *Data);
143
144    return ret;
145
146 }
147
148 //---------------------------------------------------------------------------
149 // Function:    ft1000_write_register
150 //
151 // Parameters:  ft1000_device  - device structure
152 //              value - value to write into a register
153 //              nRegIndex - register index
154 //
155 // Returns:     STATUS_SUCCESS - success
156 //              STATUS_FAILURE - failure
157 //
158 // Description: This function writes the value in a register
159 //
160 // Notes:
161 //
162 //---------------------------------------------------------------------------
163 u16 ft1000_write_register(struct ft1000_device *ft1000dev, u16 value, u16 nRegIndx)
164 {
165      u16 ret = STATUS_SUCCESS;
166
167      //DEBUG("ft1000_write_register: value is: %d, reg index is: %d\n", value, nRegIndx);
168
169      ret = ft1000_control(ft1000dev,
170                            usb_sndctrlpipe(ft1000dev->dev, 0),
171                            HARLEY_WRITE_REGISTER,       //request -- WRITE_REGISTER
172                            HARLEY_WRITE_OPERATION,      //requestType
173                            value,
174                            nRegIndx,
175                            NULL,
176                            0,
177                            LARGE_TIMEOUT );
178
179     return ret;
180 }
181
182 //---------------------------------------------------------------------------
183 // Function:    ft1000_read_dpram32
184 //
185 // Parameters:  ft1000_device  - device structure
186 //              indx - starting address to read
187 //              buffer - data buffer to hold the data read
188 //              cnt - number of byte read from DPRAM
189 //
190 // Returns:     STATUS_SUCCESS - success
191 //              STATUS_FAILURE - failure
192 //
193 // Description: This function read a number of bytes from DPRAM
194 //
195 // Notes:
196 //
197 //---------------------------------------------------------------------------
198
199 u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, u16 cnt)
200 {
201     u16 ret = STATUS_SUCCESS;
202
203     //DEBUG("ft1000_read_dpram32: indx: %d  cnt: %d\n", indx, cnt);
204     ret =ft1000_control(ft1000dev,
205                          usb_rcvctrlpipe(ft1000dev->dev,0),
206                          HARLEY_READ_DPRAM_32,                //request --READ_DPRAM_32
207                          HARLEY_READ_OPERATION,               //requestType
208                          0,                                   //value
209                          indx,                                //index
210                          buffer,                              //data
211                          cnt,                                 //data size
212                          LARGE_TIMEOUT );                     //timeout
213
214    //DEBUG("ft1000_read_dpram32: ret is  %d \n", ret);
215
216    //DEBUG("ft1000_read_dpram32: ret=%d \n", ret);
217
218    return ret;
219
220 }
221
222 //---------------------------------------------------------------------------
223 // Function:    ft1000_write_dpram32
224 //
225 // Parameters:  ft1000_device  - device structure
226 //              indx - starting address to write the data
227 //              buffer - data buffer to write into DPRAM
228 //              cnt - number of bytes to write
229 //
230 // Returns:     STATUS_SUCCESS - success
231 //              STATUS_FAILURE - failure
232 //
233 // Description: This function writes into DPRAM a number of bytes
234 //
235 // Notes:
236 //
237 //---------------------------------------------------------------------------
238 u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, u16 cnt)
239 {
240      u16 ret = STATUS_SUCCESS;
241
242      //DEBUG("ft1000_write_dpram32: indx: %d   buffer: %x cnt: %d\n", indx, buffer, cnt);
243      if ( cnt % 4)
244          cnt += cnt - (cnt % 4);
245
246      ret = ft1000_control(ft1000dev,
247                            usb_sndctrlpipe(ft1000dev->dev, 0),
248                            HARLEY_WRITE_DPRAM_32,              //request -- WRITE_DPRAM_32
249                            HARLEY_WRITE_OPERATION,             //requestType
250                            0,                                  //value
251                            indx,                               //index
252                            buffer,                             //buffer
253                            cnt,                                //buffer size
254                            LARGE_TIMEOUT );
255
256     return ret;
257 }
258
259 //---------------------------------------------------------------------------
260 // Function:    ft1000_read_dpram16
261 //
262 // Parameters:  ft1000_device  - device structure
263 //              indx - starting address to read
264 //              buffer - data buffer to hold the data read
265 //              hightlow - high or low 16 bit word
266 //
267 // Returns:     STATUS_SUCCESS - success
268 //              STATUS_FAILURE - failure
269 //
270 // Description: This function read 16 bits from DPRAM
271 //
272 // Notes:
273 //
274 //---------------------------------------------------------------------------
275 u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer, u8 highlow)
276 {
277     u16 ret = STATUS_SUCCESS;
278
279     //DEBUG("ft1000_read_dpram16: indx: %d  hightlow: %d\n", indx, highlow);
280
281     u8 request;
282
283     if (highlow == 0 )
284         request = HARLEY_READ_DPRAM_LOW;
285     else
286         request = HARLEY_READ_DPRAM_HIGH;
287
288     ret = ft1000_control(ft1000dev,
289                          usb_rcvctrlpipe(ft1000dev->dev,0),
290                          request,                     //request --READ_DPRAM_H/L
291                          HARLEY_READ_OPERATION,       //requestType
292                          0,                           //value
293                          indx,                        //index
294                          buffer,                      //data
295                          2,                           //data size
296                          LARGE_TIMEOUT );             //timeout
297
298    //DEBUG("ft1000_read_dpram16: ret is  %d \n", ret);
299
300
301    //DEBUG("ft1000_read_dpram16: data is  %x \n", *buffer);
302
303    return ret;
304
305 }
306
307 //---------------------------------------------------------------------------
308 // Function:    ft1000_write_dpram16
309 //
310 // Parameters:  ft1000_device  - device structure
311 //              indx - starting address to write the data
312 //              value - 16bits value to write
313 //              hightlow - high or low 16 bit word
314 //
315 // Returns:     STATUS_SUCCESS - success
316 //              STATUS_FAILURE - failure
317 //
318 // Description: This function writes into DPRAM a number of bytes
319 //
320 // Notes:
321 //
322 //---------------------------------------------------------------------------
323 u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u8 highlow)
324 {
325      u16 ret = STATUS_SUCCESS;
326
327
328
329      //DEBUG("ft1000_write_dpram16: indx: %d  value: %d  highlow: %d\n", indx, value, highlow);
330
331      u8 request;
332
333
334      if ( highlow == 0 )
335          request = HARLEY_WRITE_DPRAM_LOW;
336      else
337          request = HARLEY_WRITE_DPRAM_HIGH;
338
339      ret = ft1000_control(ft1000dev,
340                            usb_sndctrlpipe(ft1000dev->dev, 0),
341                            request,                             //request -- WRITE_DPRAM_H/L
342                            HARLEY_WRITE_OPERATION,              //requestType
343                            value,                                   //value
344                            indx,                                //index
345                            NULL,                               //buffer
346                            0,                                   //buffer size
347                            LARGE_TIMEOUT );
348
349     return ret;
350 }
351
352 //---------------------------------------------------------------------------
353 // Function:    fix_ft1000_read_dpram32
354 //
355 // Parameters:  ft1000_device  - device structure
356 //              indx - starting address to read
357 //              buffer - data buffer to hold the data read
358 //
359 //
360 // Returns:     STATUS_SUCCESS - success
361 //              STATUS_FAILURE - failure
362 //
363 // Description: This function read DPRAM 4 words at a time
364 //
365 // Notes:
366 //
367 //---------------------------------------------------------------------------
368 u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer)
369 {
370     u8 buf[16];
371     u16 pos;
372     u16 ret = STATUS_SUCCESS;
373
374     //DEBUG("fix_ft1000_read_dpram32: indx: %d  \n", indx);
375     pos = (indx / 4)*4;
376     ret = ft1000_read_dpram32(ft1000dev, pos, buf, 16);
377     if (ret == STATUS_SUCCESS)
378     {
379         pos = (indx % 4)*4;
380         *buffer++ = buf[pos++];
381         *buffer++ = buf[pos++];
382         *buffer++ = buf[pos++];
383         *buffer++ = buf[pos++];
384     }
385     else
386     {
387         DEBUG("fix_ft1000_read_dpram32: DPRAM32 Read failed\n");
388         *buffer++ = 0;
389         *buffer++ = 0;
390         *buffer++ = 0;
391         *buffer++ = 0;
392
393     }
394
395    //DEBUG("fix_ft1000_read_dpram32: data is  %x \n", *buffer);
396    return ret;
397
398 }
399
400
401 //---------------------------------------------------------------------------
402 // Function:    fix_ft1000_write_dpram32
403 //
404 // Parameters:  ft1000_device  - device structure
405 //              indx - starting address to write
406 //              buffer - data buffer to write
407 //
408 //
409 // Returns:     STATUS_SUCCESS - success
410 //              STATUS_FAILURE - failure
411 //
412 // Description: This function write to DPRAM 4 words at a time
413 //
414 // Notes:
415 //
416 //---------------------------------------------------------------------------
417 u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer)
418 {
419     u16 pos1;
420     u16 pos2;
421     u16 i;
422     u8 buf[32];
423     u8 resultbuffer[32];
424     u8 *pdata;
425     u16 ret  = STATUS_SUCCESS;
426
427     //DEBUG("fix_ft1000_write_dpram32: Entered:\n");
428
429     pos1 = (indx / 4)*4;
430     pdata = buffer;
431     ret = ft1000_read_dpram32(ft1000dev, pos1, buf, 16);
432     if (ret == STATUS_SUCCESS)
433     {
434         pos2 = (indx % 4)*4;
435         buf[pos2++] = *buffer++;
436         buf[pos2++] = *buffer++;
437         buf[pos2++] = *buffer++;
438         buf[pos2++] = *buffer++;
439         ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16);
440     }
441     else
442     {
443         DEBUG("fix_ft1000_write_dpram32: DPRAM32 Read failed\n");
444
445         return ret;
446     }
447
448     ret = ft1000_read_dpram32(ft1000dev, pos1, (u8 *)&resultbuffer[0], 16);
449     if (ret == STATUS_SUCCESS)
450     {
451         buffer = pdata;
452         for (i=0; i<16; i++)
453         {
454             if (buf[i] != resultbuffer[i]){
455
456                 ret = STATUS_FAILURE;
457             }
458         }
459     }
460
461     if (ret == STATUS_FAILURE)
462     {
463         ret = ft1000_write_dpram32(ft1000dev, pos1, (u8 *)&tempbuffer[0], 16);
464         ret = ft1000_read_dpram32(ft1000dev, pos1, (u8 *)&resultbuffer[0], 16);
465         if (ret == STATUS_SUCCESS)
466         {
467             buffer = pdata;
468             for (i=0; i<16; i++)
469             {
470                 if (tempbuffer[i] != resultbuffer[i])
471                 {
472                     ret = STATUS_FAILURE;
473                     DEBUG("fix_ft1000_write_dpram32 Failed to write\n");
474                 }
475             }
476          }
477     }
478
479     return ret;
480
481 }
482
483
484 //------------------------------------------------------------------------
485 //
486 //  Function:   card_reset_dsp
487 //
488 //  Synopsis:   This function is called to reset or activate the DSP
489 //
490 //  Arguments:  value                  - reset or activate
491 //
492 //  Returns:    None
493 //-----------------------------------------------------------------------
494 static void card_reset_dsp (struct ft1000_device *ft1000dev, bool value)
495 {
496     u16 status = STATUS_SUCCESS;
497     u16 tempword;
498
499     status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
500     status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_CTRL);
501     if (value)
502     {
503         DEBUG("Reset DSP\n");
504         status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
505         tempword |= DSP_RESET_BIT;
506         status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
507     }
508     else
509     {
510         DEBUG("Activate DSP\n");
511         status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
512         tempword |= DSP_ENCRYPTED;
513         tempword &= ~DSP_UNENCRYPTED;
514         status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
515         status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
516         tempword &= ~EFUSE_MEM_DISABLE;
517         tempword &= ~DSP_RESET_BIT;
518         status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET);
519         status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET);
520     }
521 }
522
523 //---------------------------------------------------------------------------
524 // Function:    CardSendCommand
525 //
526 // Parameters:  ft1000_device  - device structure
527 //              ptempbuffer - command buffer
528 //              size - command buffer size
529 //
530 // Returns:     STATUS_SUCCESS - success
531 //              STATUS_FAILURE - failure
532 //
533 // Description: This function sends a command to ASIC
534 //
535 // Notes:
536 //
537 //---------------------------------------------------------------------------
538 void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size)
539 {
540     unsigned short temp;
541     unsigned char *commandbuf;
542
543     DEBUG("CardSendCommand: enter CardSendCommand... size=%d\n", size);
544
545     commandbuf =(unsigned char*) kmalloc(size+2, GFP_KERNEL);
546     memcpy((void*)commandbuf+2, (void*)ptempbuffer, size);
547
548     //DEBUG("CardSendCommand: Command Send\n");
549
550     ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
551
552     if (temp & 0x0100)
553     {
554        msleep(10);
555     }
556
557     // check for odd word
558     size = size + 2;
559     if (size % 4)
560     {
561        // Must force to be 32 bit aligned
562        size += 4 - (size % 4);
563     }
564
565
566     //DEBUG("CardSendCommand: write dpram ... size=%d\n", size);
567     ft1000_write_dpram32(ft1000dev, 0,commandbuf, size);
568     msleep(1);
569     //DEBUG("CardSendCommand: write into doorbell ...\n");
570     ft1000_write_register(ft1000dev,  FT1000_DB_DPRAM_TX ,FT1000_REG_DOORBELL) ;
571     msleep(1);
572
573     ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
574     //DEBUG("CardSendCommand: read doorbell ...temp=%x\n", temp);
575     if ( (temp & 0x0100) == 0)
576     {
577        //DEBUG("CardSendCommand: Message sent\n");
578     }
579
580 }
581
582
583 //--------------------------------------------------------------------------
584 //
585 //  Function:   dsp_reload
586 //
587 //  Synopsis:   This function is called to load or reload the DSP
588 //
589 //  Arguments:  ft1000dev - device structure
590 //
591 //  Returns:    None
592 //-----------------------------------------------------------------------
593 int dsp_reload(struct ft1000_device *ft1000dev)
594 {
595     u16 status;
596     u16 tempword;
597     u32 templong;
598
599         struct ft1000_info *pft1000info;
600
601     pft1000info = netdev_priv(ft1000dev->net);
602
603     pft1000info->CardReady = 0;
604
605     // Program Interrupt Mask register
606     status = ft1000_write_register (ft1000dev, 0xffff, FT1000_REG_SUP_IMASK);
607
608     status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET);
609     tempword |= ASIC_RESET_BIT;
610     status = ft1000_write_register (ft1000dev, tempword, FT1000_REG_RESET);
611     msleep(1000);
612     status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET);
613     DEBUG("Reset Register = 0x%x\n", tempword);
614
615     // Toggle DSP reset
616     card_reset_dsp (ft1000dev, 1);
617     msleep(1000);
618     card_reset_dsp (ft1000dev, 0);
619     msleep(1000);
620
621     status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
622
623     // Let's check for FEFE
624     status = ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (u8 *)&templong, 4);
625     DEBUG("templong (fefe) = 0x%8x\n", templong);
626
627     // call codeloader
628     status = scram_dnldr(ft1000dev, pFileStart, FileLength);
629
630         if (status != STATUS_SUCCESS)
631                 return -EIO;
632
633     msleep(1000);
634
635     DEBUG("dsp_reload returned\n");
636         return 0;
637
638 }
639
640 //---------------------------------------------------------------------------
641 //
642 // Function:   ft1000_reset_asic
643 // Descripton: This function will call the Card Service function to reset the
644 //             ASIC.
645 // Input:
646 //     dev    - device structure
647 // Output:
648 //     none
649 //
650 //---------------------------------------------------------------------------
651 static void ft1000_reset_asic (struct net_device *dev)
652 {
653         struct ft1000_info *info = netdev_priv(dev);
654     struct ft1000_device *ft1000dev = info->pFt1000Dev;
655     u16 tempword;
656
657     DEBUG("ft1000_hw:ft1000_reset_asic called\n");
658
659     info->ASICResetNum++;
660
661     // Let's use the register provided by the Magnemite ASIC to reset the
662     // ASIC and DSP.
663     ft1000_write_register(ft1000dev,  (DSP_RESET_BIT | ASIC_RESET_BIT), FT1000_REG_RESET );
664
665     mdelay(1);
666
667     // set watermark to -1 in order to not generate an interrrupt
668     ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_MAG_WATERMARK);
669
670     // clear interrupts
671     ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR);
672     DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword);
673     ft1000_write_register (ft1000dev,  tempword, FT1000_REG_SUP_ISR);
674     ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR);
675     DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword);
676
677 }
678
679
680 //---------------------------------------------------------------------------
681 //
682 // Function:   ft1000_reset_card
683 // Descripton: This function will reset the card
684 // Input:
685 //     dev    - device structure
686 // Output:
687 //     status - FALSE (card reset fail)
688 //              TRUE  (card reset successful)
689 //
690 //---------------------------------------------------------------------------
691 static int ft1000_reset_card (struct net_device *dev)
692 {
693         struct ft1000_info *info = netdev_priv(dev);
694     struct ft1000_device *ft1000dev = info->pFt1000Dev;
695     u16 tempword;
696         struct prov_record *ptr;
697
698     DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
699
700     info->fCondResetPend = 1;
701     info->CardReady = 0;
702     info->fProvComplete = 0;
703
704     // Make sure we free any memory reserve for provisioning
705     while (list_empty(&info->prov_list) == 0) {
706         DEBUG("ft1000_hw:ft1000_reset_card:deleting provisioning record\n");
707         ptr = list_entry(info->prov_list.next, struct prov_record, list);
708         list_del(&ptr->list);
709         kfree(ptr->pprov_data);
710         kfree(ptr);
711     }
712
713     DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n");
714     //reset ASIC
715     ft1000_reset_asic(dev);
716
717     info->DSPResetNum++;
718
719     DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n");
720     dsp_reload(ft1000dev);
721
722     DEBUG("dsp reload successful\n");
723
724
725     mdelay(10);
726
727     // Initialize DSP heartbeat area to ho
728     ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag, FT1000_MAG_HI_HO_INDX);
729     ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (u8 *)&tempword, FT1000_MAG_HI_HO_INDX);
730     DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword);
731
732
733
734     info->CardReady = 1;
735
736     info->fCondResetPend = 0;
737     return TRUE;
738
739 }
740
741
742 //mbelian
743 #ifdef HAVE_NET_DEVICE_OPS
744 static const struct net_device_ops ftnet_ops =
745 {
746 .ndo_open = &ft1000_open,
747 .ndo_stop = &ft1000_close,
748 .ndo_start_xmit = &ft1000_start_xmit,
749 .ndo_get_stats = &ft1000_netdev_stats,
750 };
751 #endif
752
753
754 //---------------------------------------------------------------------------
755 // Function:    init_ft1000_netdev
756 //
757 // Parameters:  ft1000dev  - device structure
758 //
759 //
760 // Returns:     STATUS_SUCCESS - success
761 //              STATUS_FAILURE - failure
762 //
763 // Description: This function initialize the network device
764 //
765 // Notes:
766 //
767 //---------------------------------------------------------------------------
768 u16 init_ft1000_netdev(struct ft1000_device *ft1000dev)
769 {
770     struct net_device *netdev;
771         struct ft1000_info *pInfo = NULL;
772         struct dpram_blk *pdpram_blk;
773         int i, ret_val;
774         struct list_head *cur, *tmp;
775         char card_nr[2];
776
777         gCardIndex=0; //mbelian
778
779     DEBUG("Enter init_ft1000_netdev...\n");
780
781
782         netdev = alloc_etherdev(sizeof(struct ft1000_info));
783     if (!netdev )
784     {
785         DEBUG("init_ft1000_netdev: can not allocate network device\n");
786         return -ENOMEM;
787     }
788
789         pInfo = (struct ft1000_info *) netdev_priv(netdev);
790
791     //DEBUG("init_ft1000_netdev: gFt1000Info=%x, netdev=%x, ft1000dev=%x\n", gFt1000Info, netdev, ft1000dev);
792
793         memset(pInfo, 0, sizeof(struct ft1000_info));
794
795     dev_alloc_name(netdev, netdev->name);
796
797     //for the first inserted card, decide the card index beginning number, in case there are existing network interfaces
798     if ( gCardIndex == 0 )
799     {
800         DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name);
801
802         if ( strncmp(netdev->name,"eth", 3) == 0) {
803                 card_nr[0] = netdev->name[3];
804                 card_nr[1] = '\0';
805                 ret_val = strict_strtoul(card_nr, 10, &gCardIndex);
806                 if (ret_val) {
807                         printk(KERN_ERR "Can't parse netdev\n");
808                         goto err_net;
809                 }
810
811             pInfo->CardNumber = gCardIndex;
812             DEBUG("card number = %d\n", pInfo->CardNumber);
813         }
814         else {
815             printk(KERN_ERR "ft1000: Invalid device name\n");
816                 ret_val = -ENXIO;
817                 goto err_net;
818         }
819     }
820     else
821     {
822         //not the first inserted card, increase card number by 1
823         pInfo->CardNumber = gCardIndex;
824         /*DEBUG("card number = %d\n", pInfo->CardNumber);*/ //mbelian
825     }
826
827     memset(&pInfo->stats, 0, sizeof(struct net_device_stats) );
828
829    spin_lock_init(&pInfo->dpram_lock);
830     pInfo->pFt1000Dev = ft1000dev;
831     pInfo->DrvErrNum = 0;
832     pInfo->ASICResetNum = 0;
833     pInfo->registered = 1;
834     pInfo->ft1000_reset = ft1000_reset;
835     pInfo->mediastate = 0;
836     pInfo->fifo_cnt = 0;
837     pInfo->DeviceCreated = FALSE;
838     pInfo->DeviceMajor = 0;
839     pInfo->CurrentInterruptEnableMask = ISR_DEFAULT_MASK;
840     pInfo->InterruptsEnabled = FALSE;
841     pInfo->CardReady = 0;
842     pInfo->DSP_TIME[0] = 0;
843     pInfo->DSP_TIME[1] = 0;
844     pInfo->DSP_TIME[2] = 0;
845     pInfo->DSP_TIME[3] = 0;
846     pInfo->fAppMsgPend = 0;
847     pInfo->fCondResetPend = 0;
848         pInfo->usbboot = 0;
849         pInfo->dspalive = 0;
850         memset(&pInfo->tempbuf[0], 0, sizeof(pInfo->tempbuf));
851
852     INIT_LIST_HEAD(&pInfo->prov_list);
853
854 //mbelian
855 #ifdef HAVE_NET_DEVICE_OPS
856         netdev->netdev_ops = &ftnet_ops;
857 #else
858     netdev->hard_start_xmit = &ft1000_start_xmit;
859     netdev->get_stats = &ft1000_netdev_stats;
860     netdev->open = &ft1000_open;
861     netdev->stop = &ft1000_close;
862 #endif
863
864     ft1000dev->net = netdev;
865
866
867
868 //init free_buff_lock, freercvpool, numofmsgbuf, pdpram_blk
869 //only init once per card
870 //Jim
871           DEBUG("Initialize free_buff_lock and freercvpool\n");
872         spin_lock_init(&free_buff_lock);
873
874         // initialize a list of buffers to be use for queuing up receive command data
875         INIT_LIST_HEAD (&freercvpool);
876
877         // create list of free buffers
878         for (i=0; i<NUM_OF_FREE_BUFFERS; i++) {
879             // Get memory for DPRAM_DATA link list
880                 pdpram_blk = kmalloc(sizeof(struct dpram_blk), GFP_KERNEL);
881                 if (pdpram_blk == NULL) {
882                         ret_val = -ENOMEM;
883                         goto err_free;
884                 }
885             // Get a block of memory to store command data
886             pdpram_blk->pbuffer = kmalloc ( MAX_CMD_SQSIZE, GFP_KERNEL );
887                 if (pdpram_blk->pbuffer == NULL) {
888                         ret_val = -ENOMEM;
889                         kfree(pdpram_blk);
890                         goto err_free;
891                 }
892             // link provisioning data
893             list_add_tail (&pdpram_blk->list, &freercvpool);
894         }
895         numofmsgbuf = NUM_OF_FREE_BUFFERS;
896
897
898         return 0;
899
900
901 err_free:
902         list_for_each_safe(cur, tmp, &freercvpool) {
903                 pdpram_blk = list_entry(cur, struct dpram_blk, list);
904                 list_del(&pdpram_blk->list);
905                 kfree(pdpram_blk->pbuffer);
906                 kfree(pdpram_blk);
907         }
908 err_net:
909         free_netdev(netdev);
910         return ret_val;
911 }
912
913
914
915 //---------------------------------------------------------------------------
916 // Function:    reg_ft1000_netdev
917 //
918 // Parameters:  ft1000dev  - device structure
919 //
920 //
921 // Returns:     STATUS_SUCCESS - success
922 //              STATUS_FAILURE - failure
923 //
924 // Description: This function register the network driver
925 //
926 // Notes:
927 //
928 //---------------------------------------------------------------------------
929 int reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf)
930 {
931     struct net_device *netdev;
932         struct ft1000_info *pInfo;
933         int rc;
934
935     netdev = ft1000dev->net;
936     pInfo = netdev_priv(ft1000dev->net);
937     DEBUG("Enter reg_ft1000_netdev...\n");
938
939
940     ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID);
941
942     usb_set_intfdata(intf, pInfo);
943     SET_NETDEV_DEV(netdev, &intf->dev);
944
945     rc = register_netdev(netdev);
946     if (rc)
947     {
948         DEBUG("reg_ft1000_netdev: could not register network device\n");
949         free_netdev(netdev);
950         return rc;
951     }
952
953
954     //Create character device, implemented by Jim
955     ft1000_CreateDevice(ft1000dev);
956
957     DEBUG ("reg_ft1000_netdev returned\n");
958
959     pInfo->CardReady = 1;
960
961
962         return 0;
963 }
964
965 static int ft1000_reset(struct net_device *dev)
966 {
967     ft1000_reset_card(dev);
968     return 0;
969 }
970
971 //---------------------------------------------------------------------------
972 // Function:    ft1000_usb_transmit_complete
973 //
974 // Parameters:  urb  - transmitted usb urb
975 //
976 //
977 // Returns:     none
978 //
979 // Description: This is the callback function when a urb is transmitted
980 //
981 // Notes:
982 //
983 //---------------------------------------------------------------------------
984 static void ft1000_usb_transmit_complete(struct urb *urb)
985 {
986
987     struct ft1000_device *ft1000dev = urb->context;
988
989     //DEBUG("ft1000_usb_transmit_complete entered\n");
990
991     if (urb->status)
992         printk("%s: TX status %d\n", ft1000dev->net->name, urb->status);
993
994     netif_wake_queue(ft1000dev->net);
995
996     //DEBUG("Return from ft1000_usb_transmit_complete\n");
997 }
998
999 //---------------------------------------------------------------------------
1000 //
1001 // Function:   ft1000_copy_down_pkt
1002 // Descripton: This function will take an ethernet packet and convert it to
1003 //             a Flarion packet prior to sending it to the ASIC Downlink
1004 //             FIFO.
1005 // Input:
1006 //     dev    - device structure
1007 //     packet - address of ethernet packet
1008 //     len    - length of IP packet
1009 // Output:
1010 //     status - FAILURE
1011 //              SUCCESS
1012 //
1013 //---------------------------------------------------------------------------
1014 static int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len)
1015 {
1016         struct ft1000_info *pInfo = netdev_priv(netdev);
1017     struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
1018
1019
1020         int count, ret;
1021     u8 *t;
1022         struct pseudo_hdr hdr;
1023
1024     if (!pInfo->CardReady)
1025     {
1026
1027         DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
1028         return -ENODEV;
1029
1030     }
1031
1032
1033     //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len);
1034
1035         count = sizeof(struct pseudo_hdr) + len;
1036     if(count > MAX_BUF_SIZE)
1037     {
1038         DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n");
1039         DEBUG("size = %d\n", count);
1040         return -EINVAL;
1041     }
1042
1043     if ( count % 4)
1044         count = count + (4- (count %4) );
1045
1046         memset(&hdr, 0, sizeof(struct pseudo_hdr));
1047
1048         hdr.length = ntohs(count);
1049         hdr.source = 0x10;
1050         hdr.destination = 0x20;
1051         hdr.portdest = 0x20;
1052         hdr.portsrc = 0x10;
1053         hdr.sh_str_id = 0x91;
1054         hdr.control = 0x00;
1055
1056         hdr.checksum = hdr.length ^ hdr.source ^ hdr.destination ^
1057                         hdr.portdest ^ hdr.portsrc ^ hdr.sh_str_id ^
1058                         hdr.control;
1059
1060         memcpy(&pFt1000Dev->tx_buf[0], &hdr, sizeof(hdr));
1061         memcpy(&(pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)]), packet, len);
1062
1063     netif_stop_queue(netdev);
1064
1065     //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count);
1066
1067     usb_fill_bulk_urb(pFt1000Dev->tx_urb,
1068                       pFt1000Dev->dev,
1069                       usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr),
1070                       pFt1000Dev->tx_buf,
1071                       count,
1072                       ft1000_usb_transmit_complete,
1073                       (void*)pFt1000Dev);
1074
1075     t = (u8 *)pFt1000Dev->tx_urb->transfer_buffer;
1076     //DEBUG("transfer_length=%d\n", pFt1000Dev->tx_urb->transfer_buffer_length);
1077     /*for (i=0; i<count; i++ )
1078     {
1079        DEBUG("%x    ", *t++ );
1080     }*/
1081
1082
1083         ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC);
1084         if (ret) {
1085                 DEBUG("ft1000 failed tx_urb %d\n", ret);
1086                 return ret;
1087         } else {
1088                 pInfo->stats.tx_packets++;
1089                 pInfo->stats.tx_bytes += (len+14);
1090         }
1091
1092     //DEBUG("ft1000_copy_down_pkt() exit\n");
1093
1094         return 0;
1095 }
1096
1097 //---------------------------------------------------------------------------
1098 // Function:    ft1000_start_xmit
1099 //
1100 // Parameters:  skb - socket buffer to be sent
1101 //              dev - network device
1102 //
1103 //
1104 // Returns:     none
1105 //
1106 // Description: transmit a ethernet packet
1107 //
1108 // Notes:
1109 //
1110 //---------------------------------------------------------------------------
1111 static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
1112 {
1113         struct ft1000_info *pInfo = netdev_priv(dev);
1114     struct ft1000_device *pFt1000Dev= pInfo->pFt1000Dev;
1115     u8 *pdata;
1116     int maxlen, pipe;
1117
1118
1119     //DEBUG(" ft1000_start_xmit() entered\n");
1120
1121     if ( skb == NULL )
1122     {
1123         DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" );
1124         return NETDEV_TX_OK;
1125     }
1126
1127     if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1128     {
1129         DEBUG("network driver is closed, return\n");
1130         goto err;
1131     }
1132
1133     //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len);
1134     pipe = usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr);
1135     maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe));
1136     //DEBUG("ft1000_start_xmit 2: pipe=%d dev->maxpacket  = %d\n", pipe, maxlen);
1137
1138     pdata = (u8 *)skb->data;
1139     /*for (i=0; i<skb->len; i++)
1140         DEBUG("skb->data[%d]=%x    ", i, *(skb->data+i));
1141
1142     DEBUG("\n");*/
1143
1144
1145     if (pInfo->mediastate == 0)
1146     {
1147         /* Drop packet is mediastate is down */
1148         DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n");
1149         goto err;
1150     }
1151
1152     if ( (skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE) )
1153     {
1154         /* Drop packet which has invalid size */
1155         DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n");
1156         goto err;
1157     }
1158 //mbelian
1159         ft1000_copy_down_pkt(dev, (pdata+ENET_HEADER_SIZE-2),
1160                                 skb->len - ENET_HEADER_SIZE + 2);
1161
1162 err:
1163         dev_kfree_skb(skb);
1164     //DEBUG(" ft1000_start_xmit() exit\n");
1165
1166         return NETDEV_TX_OK;
1167 }
1168
1169 //---------------------------------------------------------------------------
1170 //
1171 // Function:   ft1000_copy_up_pkt
1172 // Descripton: This function will take a packet from the FIFO up link and
1173 //             convert it into an ethernet packet and deliver it to the IP stack
1174 // Input:
1175 //     urb - the receving usb urb
1176 //
1177 // Output:
1178 //     status - FAILURE
1179 //              SUCCESS
1180 //
1181 //---------------------------------------------------------------------------
1182 static int ft1000_copy_up_pkt (struct urb *urb)
1183 {
1184         struct ft1000_info *info = urb->context;
1185     struct ft1000_device *ft1000dev = info->pFt1000Dev;
1186     struct net_device *net = ft1000dev->net;
1187
1188     u16 tempword;
1189     u16 len;
1190     u16 lena; //mbelian
1191     struct sk_buff *skb;
1192     u16 i;
1193     u8 *pbuffer=NULL;
1194     u8 *ptemp=NULL;
1195     u16 *chksum;
1196
1197
1198     //DEBUG("ft1000_copy_up_pkt entered\n");
1199
1200     if ( ft1000dev->status & FT1000_STATUS_CLOSING)
1201     {
1202         DEBUG("network driver is closed, return\n");
1203         return STATUS_SUCCESS;
1204     }
1205
1206     // Read length
1207     len = urb->transfer_buffer_length;
1208     lena = urb->actual_length; //mbelian
1209     //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n",
1210       //       urb->transfer_buffer_length, urb->actual_length);
1211
1212     chksum = (u16 *)ft1000dev->rx_buf;
1213
1214     tempword = *chksum++;
1215     for (i=1; i<7; i++)
1216     {
1217         tempword ^= *chksum++;
1218     }
1219
1220     if  (tempword != *chksum)
1221     {
1222         info->stats.rx_errors ++;
1223         ft1000_submit_rx_urb(info);
1224         return STATUS_FAILURE;
1225     }
1226
1227
1228     //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum);
1229
1230     skb = dev_alloc_skb(len+12+2);
1231
1232     if (skb == NULL)
1233     {
1234         DEBUG("ft1000_copy_up_pkt: No Network buffers available\n");
1235         info->stats.rx_errors++;
1236         ft1000_submit_rx_urb(info);
1237         return STATUS_FAILURE;
1238     }
1239
1240     pbuffer = (u8 *)skb_put(skb, len+12);
1241
1242     //subtract the number of bytes read already
1243     ptemp = pbuffer;
1244
1245     // fake MAC address
1246     *pbuffer++ = net->dev_addr[0];
1247     *pbuffer++ = net->dev_addr[1];
1248     *pbuffer++ = net->dev_addr[2];
1249     *pbuffer++ = net->dev_addr[3];
1250     *pbuffer++ = net->dev_addr[4];
1251     *pbuffer++ = net->dev_addr[5];
1252     *pbuffer++ = 0x00;
1253     *pbuffer++ = 0x07;
1254     *pbuffer++ = 0x35;
1255     *pbuffer++ = 0xff;
1256     *pbuffer++ = 0xff;
1257     *pbuffer++ = 0xfe;
1258
1259
1260
1261
1262         memcpy(pbuffer, ft1000dev->rx_buf+sizeof(struct pseudo_hdr), len-sizeof(struct pseudo_hdr));
1263
1264     //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n");
1265     /*for (i=0; i<len+12; i++)
1266     {
1267         DEBUG("ft1000_copy_up_pkt: Protocol Data: 0x%x\n ", *ptemp++);
1268     }*/
1269
1270     skb->dev = net;
1271
1272     skb->protocol = eth_type_trans(skb, net);
1273     skb->ip_summed = CHECKSUM_UNNECESSARY;
1274     netif_rx(skb);
1275
1276     info->stats.rx_packets++;
1277     // Add on 12 bytes for MAC address which was removed
1278     info->stats.rx_bytes += (lena+12); //mbelian
1279
1280     ft1000_submit_rx_urb(info);
1281     //DEBUG("ft1000_copy_up_pkt exited\n");
1282     return SUCCESS;
1283 }
1284
1285 //---------------------------------------------------------------------------
1286 //
1287 // Function:   ft1000_submit_rx_urb
1288 // Descripton: the receiving function of the network driver
1289 //
1290 // Input:
1291 //     info - a private structure contains the device information
1292 //
1293 // Output:
1294 //     status - FAILURE
1295 //              SUCCESS
1296 //
1297 //---------------------------------------------------------------------------
1298 static int ft1000_submit_rx_urb(struct ft1000_info *info)
1299 {
1300     int result;
1301     struct ft1000_device *pFt1000Dev = info->pFt1000Dev;
1302
1303
1304     //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb));
1305     if ( pFt1000Dev->status & FT1000_STATUS_CLOSING)
1306     {
1307         DEBUG("network driver is closed, return\n");
1308         //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian
1309         return -ENODEV;
1310     }
1311
1312     usb_fill_bulk_urb(pFt1000Dev->rx_urb,
1313             pFt1000Dev->dev,
1314             usb_rcvbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_in_endpointAddr),
1315             pFt1000Dev->rx_buf,
1316             MAX_BUF_SIZE,
1317             (usb_complete_t)ft1000_copy_up_pkt,
1318             info);
1319
1320
1321     if((result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC)))
1322     {
1323         printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result);
1324         return result;
1325     }
1326
1327     //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result);
1328
1329         return 0;
1330 }
1331
1332 //---------------------------------------------------------------------------
1333 // Function:    ft1000_open
1334 //
1335 // Parameters:
1336 //              dev - network device
1337 //
1338 //
1339 // Returns:     none
1340 //
1341 // Description: open the network driver
1342 //
1343 // Notes:
1344 //
1345 //---------------------------------------------------------------------------
1346 static int ft1000_open (struct net_device *dev)
1347 {
1348         struct ft1000_info *pInfo = (struct ft1000_info *)netdev_priv(dev);
1349     struct timeval tv; //mbelian
1350         int ret;
1351
1352     DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber);
1353     //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len);
1354
1355         pInfo->stats.rx_bytes = 0; //mbelian
1356         pInfo->stats.tx_bytes = 0; //mbelian
1357         pInfo->stats.rx_packets = 0; //mbelian
1358         pInfo->stats.tx_packets = 0; //mbelian
1359         do_gettimeofday(&tv);
1360     pInfo->ConTm = tv.tv_sec;
1361         pInfo->ProgConStat = 0; //mbelian
1362
1363
1364     netif_start_queue(dev);
1365
1366     netif_carrier_on(dev); //mbelian
1367
1368         ret = ft1000_submit_rx_urb(pInfo);
1369
1370         return ret;
1371 }
1372
1373 //---------------------------------------------------------------------------
1374 // Function:    ft1000_close
1375 //
1376 // Parameters:
1377 //              net - network device
1378 //
1379 //
1380 // Returns:     none
1381 //
1382 // Description: close the network driver
1383 //
1384 // Notes:
1385 //
1386 //---------------------------------------------------------------------------
1387 int ft1000_close(struct net_device *net)
1388 {
1389         struct ft1000_info *pInfo = (struct ft1000_info *) netdev_priv(net);
1390     struct ft1000_device *ft1000dev = pInfo->pFt1000Dev;
1391
1392     //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt);
1393
1394     ft1000dev->status |= FT1000_STATUS_CLOSING;
1395     
1396     //DEBUG("ft1000_close: calling usb_kill_urb \n");
1397
1398     DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);
1399     netif_carrier_off(net);//mbelian
1400     netif_stop_queue(net);
1401     //DEBUG("ft1000_close: netif_stop_queue called\n");
1402     ft1000dev->status &= ~FT1000_STATUS_CLOSING;
1403
1404    pInfo->ProgConStat = 0xff; //mbelian
1405
1406
1407     return 0;
1408 }
1409
1410 static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev)
1411 {
1412         struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev);
1413
1414         return &(info->stats); //mbelian
1415 }
1416
1417
1418 /*********************************************************************************
1419 Jim
1420 */
1421
1422
1423 //---------------------------------------------------------------------------
1424 //
1425 // Function:   ft1000_chkcard
1426 // Descripton: This function will check if the device is presently available on
1427 //             the system.
1428 // Input:
1429 //     dev    - device structure
1430 // Output:
1431 //     status - FALSE (device is not present)
1432 //              TRUE  (device is present)
1433 //
1434 //---------------------------------------------------------------------------
1435 static int ft1000_chkcard (struct ft1000_device *dev) {
1436     u16 tempword;
1437     u16 status;
1438         struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net);
1439
1440     if (info->fCondResetPend)
1441     {
1442         DEBUG("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1443         return TRUE;
1444     }
1445
1446     // Mask register is used to check for device presence since it is never
1447     // set to zero.
1448     status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK);
1449     //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword);
1450     if (tempword == 0) {
1451         DEBUG("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
1452         return FALSE;
1453     }
1454
1455     // The system will return the value of 0xffff for the version register
1456     // if the device is not present.
1457     status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID);
1458     //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword);
1459     if (tempword != 0x1b01 ){
1460         dev->status |= FT1000_STATUS_CLOSING; //mbelian
1461         DEBUG("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
1462         return FALSE;
1463     }
1464     return TRUE;
1465 }
1466
1467
1468
1469 //---------------------------------------------------------------------------
1470 //
1471 // Function:   ft1000_receive_cmd
1472 // Descripton: This function will read a message from the dpram area.
1473 // Input:
1474 //    dev - network device structure
1475 //    pbuffer - caller supply address to buffer
1476 //    pnxtph - pointer to next pseudo header
1477 // Output:
1478 //   Status = 0 (unsuccessful)
1479 //          = 1 (successful)
1480 //
1481 //---------------------------------------------------------------------------
1482 static bool ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) {
1483     u16 size, ret;
1484     u16 *ppseudohdr;
1485     int i;
1486     u16 tempword;
1487
1488     ret = ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (u8 *)&size, FT1000_MAG_PH_LEN_INDX);
1489     size = ntohs(size) + PSEUDOSZ;
1490     if (size > maxsz) {
1491         DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size);
1492         return FALSE;
1493     }
1494     else {
1495         ppseudohdr = (u16 *)pbuffer;
1496         ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR);
1497         ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1498         //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1499         pbuffer++;
1500         ft1000_write_register(dev,  FT1000_DPRAM_MAG_RX_BASE+1, FT1000_REG_DPRAM_ADDR);
1501         for (i=0; i<=(size>>2); i++) {
1502             ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
1503             pbuffer++;
1504             ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1505             pbuffer++;
1506         }
1507         //copy odd aligned word
1508         ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
1509         //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1510         pbuffer++;
1511         ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1512         //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1513         pbuffer++;
1514         if (size & 0x0001) {
1515             //copy odd byte from fifo
1516             ret = ft1000_read_register(dev, &tempword, FT1000_REG_DPRAM_DATA);
1517             *pbuffer = ntohs(tempword);
1518         }
1519
1520         // Check if pseudo header checksum is good
1521         // Calculate pseudo header checksum
1522         tempword = *ppseudohdr++;
1523         for (i=1; i<7; i++) {
1524             tempword ^= *ppseudohdr++;
1525         }
1526         if ( (tempword != *ppseudohdr) ) {
1527             return FALSE;
1528         }
1529
1530         return TRUE;
1531     }
1532 }
1533
1534
1535 static int ft1000_dsp_prov(void *arg)
1536 {
1537     struct ft1000_device *dev = (struct ft1000_device *)arg;
1538         struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net);
1539     u16 tempword;
1540     u16 len;
1541     u16 i=0;
1542         struct prov_record *ptr;
1543         struct pseudo_hdr *ppseudo_hdr;
1544     u16 *pmsg;
1545     u16 status;
1546     u16 TempShortBuf [256];
1547
1548     DEBUG("*** DspProv Entered\n");
1549
1550     while (list_empty(&info->prov_list) == 0)
1551     {
1552         DEBUG("DSP Provisioning List Entry\n");
1553
1554         // Check if doorbell is available
1555         DEBUG("check if doorbell is cleared\n");
1556         status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
1557         if (status)
1558         {
1559                 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n");
1560             break;
1561         }
1562
1563         while (tempword & FT1000_DB_DPRAM_TX) {
1564             mdelay(10);
1565             i++;
1566             if (i==10) {
1567                DEBUG("FT1000:ft1000_dsp_prov:message drop\n");
1568                return STATUS_FAILURE;
1569             }
1570             ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1571         }
1572
1573         if ( !(tempword & FT1000_DB_DPRAM_TX) ) {
1574             DEBUG("*** Provision Data Sent to DSP\n");
1575
1576             // Send provisioning data
1577                 ptr = list_entry(info->prov_list.next, struct prov_record, list);
1578             len = *(u16 *)ptr->pprov_data;
1579             len = htons(len);
1580             len += PSEUDOSZ;
1581
1582             pmsg = (u16 *)ptr->pprov_data;
1583                 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1584             // Insert slow queue sequence number
1585             ppseudo_hdr->seq_num = info->squeseqnum++;
1586             ppseudo_hdr->portsrc = 0;
1587             // Calculate new checksum
1588             ppseudo_hdr->checksum = *pmsg++;
1589             //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
1590             for (i=1; i<7; i++) {
1591                 ppseudo_hdr->checksum ^= *pmsg++;
1592                 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
1593             }
1594
1595             TempShortBuf[0] = 0;
1596             TempShortBuf[1] = htons (len);
1597             memcpy(&TempShortBuf[2], ppseudo_hdr, len);
1598
1599             status = ft1000_write_dpram32 (dev, 0, (u8 *)&TempShortBuf[0], (unsigned short)(len+2));
1600             status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
1601
1602             list_del(&ptr->list);
1603             kfree(ptr->pprov_data);
1604             kfree(ptr);
1605         }
1606         msleep(10);
1607     }
1608
1609     DEBUG("DSP Provisioning List Entry finished\n");
1610
1611     msleep(100);
1612
1613     info->fProvComplete = 1;
1614     info->CardReady = 1;
1615     return STATUS_SUCCESS;
1616
1617 }
1618
1619
1620 static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
1621         struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net);
1622     u16 msgtype;
1623     u16 tempword;
1624         struct media_msg *pmediamsg;
1625         struct dsp_init_msg *pdspinitmsg;
1626         struct drv_msg *pdrvmsg;
1627     u16 i;
1628         struct pseudo_hdr *ppseudo_hdr;
1629     u16 *pmsg;
1630     u16 status;
1631     union {
1632         u8  byte[2];
1633         u16 wrd;
1634     } convert;
1635
1636
1637     char *cmdbuffer = kmalloc(1600, GFP_KERNEL);
1638     if (!cmdbuffer)
1639         return STATUS_FAILURE;
1640
1641     status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size);
1642
1643
1644
1645 #ifdef JDEBUG
1646         DEBUG("ft1000_proc_drvmsg:cmdbuffer\n");
1647         for(i = 0; i < size; i+=5)
1648         {
1649             if( (i + 5) < size )
1650                 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]);
1651             else
1652             {
1653                 for (j = i; j < size; j++)
1654                 DEBUG("0x%x ", cmdbuffer[j]);
1655                 DEBUG("\n");
1656                 break;
1657             }
1658         }
1659 #endif
1660         pdrvmsg = (struct drv_msg *)&cmdbuffer[2];
1661         msgtype = ntohs(pdrvmsg->type);
1662         DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype);
1663         switch (msgtype) {
1664             case MEDIA_STATE: {
1665                 DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE");
1666
1667                 pmediamsg = (struct media_msg *)&cmdbuffer[0];
1668                 if (info->ProgConStat != 0xFF) {
1669                     if (pmediamsg->state) {
1670                         DEBUG("Media is up\n");
1671                         if (info->mediastate == 0) {
1672                             if ( info->NetDevRegDone )
1673                             {
1674                                 //netif_carrier_on(dev->net);//mbelian
1675                                 netif_wake_queue(dev->net);
1676                             }
1677                             info->mediastate = 1;
1678                             /*do_gettimeofday(&tv);
1679                             info->ConTm = tv.tv_sec;*/ //mbelian
1680                         }
1681                     }
1682                     else {
1683                         DEBUG("Media is down\n");
1684                         if (info->mediastate == 1) {
1685                             info->mediastate = 0;
1686                             if ( info->NetDevRegDone )
1687                             {
1688                                 //netif_carrier_off(dev->net); mbelian
1689                                 //netif_stop_queue(dev->net);
1690                             }
1691                             info->ConTm = 0;
1692                         }
1693                     }
1694                 }
1695                 else {
1696                     DEBUG("Media is down\n");
1697                     if (info->mediastate == 1) {
1698                         info->mediastate = 0;
1699                         if ( info->NetDevRegDone)
1700                         {
1701                             //netif_carrier_off(dev->net); //mbelian
1702                             //netif_stop_queue(dev->net);
1703                         }
1704                         info->ConTm = 0;
1705                     }
1706                 }
1707                 break;
1708             }
1709             case DSP_INIT_MSG: {
1710                 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG");
1711
1712                 pdspinitmsg = (struct dsp_init_msg *)&cmdbuffer[2];
1713                 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
1714                 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", info->DspVer[0], info->DspVer[1], info->DspVer[2], info->DspVer[3]);
1715                 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum, HWSERNUMSZ);
1716                 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
1717                 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
1718                 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]);
1719                 dev->net->dev_addr[0] = info->eui64[0];
1720                 dev->net->dev_addr[1] = info->eui64[1];
1721                 dev->net->dev_addr[2] = info->eui64[2];
1722                 dev->net->dev_addr[3] = info->eui64[5];
1723                 dev->net->dev_addr[4] = info->eui64[6];
1724                 dev->net->dev_addr[5] = info->eui64[7];
1725
1726                 if (ntohs(pdspinitmsg->length) == (sizeof(struct dsp_init_msg) - 20)) {
1727                     memcpy(info->ProductMode, pdspinitmsg->ProductMode, MODESZ);
1728                     memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, CALVERSZ);
1729                     memcpy(info->RfCalDate, pdspinitmsg->RfCalDate, CALDATESZ);
1730                     DEBUG("RFCalVer = 0x%2x 0x%2x\n", info->RfCalVer[0], info->RfCalVer[1]);
1731                 }
1732                 break;
1733             }
1734             case DSP_PROVISION: {
1735                 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n");
1736
1737                 // kick off dspprov routine to start provisioning
1738                 // Send provisioning data to DSP
1739                 if (list_empty(&info->prov_list) == 0)
1740                 {
1741                     info->fProvComplete = 0;
1742                     status = ft1000_dsp_prov(dev);
1743                     if (status != STATUS_SUCCESS)
1744                         goto out;
1745                 }
1746                 else {
1747                     info->fProvComplete = 1;
1748                     status = ft1000_write_register (dev, FT1000_DB_HB, FT1000_REG_DOORBELL);
1749                     DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n");
1750                 }
1751                 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n");
1752                 break;
1753             }
1754             case DSP_STORE_INFO: {
1755                 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO");
1756
1757                 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
1758                 tempword = ntohs(pdrvmsg->length);
1759                 info->DSPInfoBlklen = tempword;
1760                 if (tempword < (MAX_DSP_SESS_REC-4) ) {
1761                     pmsg = (u16 *)&pdrvmsg->data[0];
1762                     for (i=0; i<((tempword+1)/2); i++) {
1763                         DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg);
1764                         info->DSPInfoBlk[i+10] = *pmsg++;
1765                     }
1766                 }
1767                 else {
1768                     info->DSPInfoBlklen = 0;
1769                 }
1770                 break;
1771             }
1772             case DSP_GET_INFO: {
1773                 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
1774                 // copy dsp info block to dsp
1775                 info->DrvMsgPend = 1;
1776                 // allow any outstanding ioctl to finish
1777                 mdelay(10);
1778                 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1779                 if (tempword & FT1000_DB_DPRAM_TX) {
1780                     mdelay(10);
1781                     status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1782                     if (tempword & FT1000_DB_DPRAM_TX) {
1783                         mdelay(10);
1784                             status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1785                             if (tempword & FT1000_DB_DPRAM_TX) {
1786                                 break;
1787                             }
1788                     }
1789                 }
1790
1791                 // Put message into Slow Queue
1792                 // Form Pseudo header
1793                 pmsg = (u16 *)info->DSPInfoBlk;
1794                 *pmsg++ = 0;
1795                 *pmsg++ = htons(info->DSPInfoBlklen+20+info->DSPInfoBlklen);
1796                 ppseudo_hdr = (struct pseudo_hdr *)(u16 *)&info->DSPInfoBlk[2];
1797                 ppseudo_hdr->length = htons(info->DSPInfoBlklen+4+info->DSPInfoBlklen);
1798                 ppseudo_hdr->source = 0x10;
1799                 ppseudo_hdr->destination = 0x20;
1800                 ppseudo_hdr->portdest = 0;
1801                 ppseudo_hdr->portsrc = 0;
1802                 ppseudo_hdr->sh_str_id = 0;
1803                 ppseudo_hdr->control = 0;
1804                 ppseudo_hdr->rsvd1 = 0;
1805                 ppseudo_hdr->rsvd2 = 0;
1806                 ppseudo_hdr->qos_class = 0;
1807                 // Insert slow queue sequence number
1808                 ppseudo_hdr->seq_num = info->squeseqnum++;
1809                 // Insert application id
1810                 ppseudo_hdr->portsrc = 0;
1811                 // Calculate new checksum
1812                 ppseudo_hdr->checksum = *pmsg++;
1813                 for (i=1; i<7; i++) {
1814                     ppseudo_hdr->checksum ^= *pmsg++;
1815                 }
1816                 info->DSPInfoBlk[10] = 0x7200;
1817                 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen);
1818                 status = ft1000_write_dpram32 (dev, 0, (u8 *)&info->DSPInfoBlk[0], (unsigned short)(info->DSPInfoBlklen+22));
1819                 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
1820                 info->DrvMsgPend = 0;
1821
1822                 break;
1823             }
1824
1825           case GET_DRV_ERR_RPT_MSG: {
1826               DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
1827               // copy driver error message to dsp
1828               info->DrvMsgPend = 1;
1829               // allow any outstanding ioctl to finish
1830               mdelay(10);
1831               status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1832               if (tempword & FT1000_DB_DPRAM_TX) {
1833                   mdelay(10);
1834                   status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1835                   if (tempword & FT1000_DB_DPRAM_TX) {
1836                       mdelay(10);
1837                   }
1838               }
1839
1840               if ( (tempword & FT1000_DB_DPRAM_TX) == 0) {
1841                   // Put message into Slow Queue
1842                   // Form Pseudo header
1843                   pmsg = (u16 *)&tempbuffer[0];
1844                         ppseudo_hdr = (struct pseudo_hdr *)pmsg;
1845                   ppseudo_hdr->length = htons(0x0012);
1846                   ppseudo_hdr->source = 0x10;
1847                   ppseudo_hdr->destination = 0x20;
1848                   ppseudo_hdr->portdest = 0;
1849                   ppseudo_hdr->portsrc = 0;
1850                   ppseudo_hdr->sh_str_id = 0;
1851                   ppseudo_hdr->control = 0;
1852                   ppseudo_hdr->rsvd1 = 0;
1853                   ppseudo_hdr->rsvd2 = 0;
1854                   ppseudo_hdr->qos_class = 0;
1855                   // Insert slow queue sequence number
1856                   ppseudo_hdr->seq_num = info->squeseqnum++;
1857                   // Insert application id
1858                   ppseudo_hdr->portsrc = 0;
1859                   // Calculate new checksum
1860                   ppseudo_hdr->checksum = *pmsg++;
1861                   for (i=1; i<7; i++) {
1862                       ppseudo_hdr->checksum ^= *pmsg++;
1863                   }
1864                   pmsg = (u16 *)&tempbuffer[16];
1865                   *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
1866                   *pmsg++ = htons(0x000e);
1867                   *pmsg++ = htons(info->DSP_TIME[0]);
1868                   *pmsg++ = htons(info->DSP_TIME[1]);
1869                   *pmsg++ = htons(info->DSP_TIME[2]);
1870                   *pmsg++ = htons(info->DSP_TIME[3]);
1871                   convert.byte[0] = info->DspVer[0];
1872                   convert.byte[1] = info->DspVer[1];
1873                   *pmsg++ = convert.wrd;
1874                   convert.byte[0] = info->DspVer[2];
1875                   convert.byte[1] = info->DspVer[3];
1876                   *pmsg++ = convert.wrd;
1877                   *pmsg++ = htons(info->DrvErrNum);
1878
1879                   CardSendCommand (dev, (unsigned char*)&tempbuffer[0], (u16)(0x0012 + PSEUDOSZ));
1880                   info->DrvErrNum = 0;
1881               }
1882               info->DrvMsgPend = 0;
1883
1884           break;
1885       }
1886
1887       default:
1888           break;
1889         }
1890
1891
1892     status = STATUS_SUCCESS;
1893 out:
1894     kfree(cmdbuffer);
1895     DEBUG("return from ft1000_proc_drvmsg\n");
1896     return status;
1897 }
1898
1899
1900
1901 int ft1000_poll(void* dev_id) {
1902
1903     struct ft1000_device *dev = (struct ft1000_device *)dev_id;
1904         struct ft1000_info *info = (struct ft1000_info *) netdev_priv(dev->net);
1905
1906     u16 tempword;
1907     u16 status;
1908     u16 size;
1909     int i;
1910     u16 data;
1911     u16 modulo;
1912     u16 portid;
1913     u16 nxtph;
1914         struct dpram_blk *pdpram_blk;
1915         struct pseudo_hdr *ppseudo_hdr;
1916     unsigned long flags;
1917
1918     //DEBUG("Enter ft1000_poll...\n");
1919     if (ft1000_chkcard(dev) == FALSE) {
1920         DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
1921         return STATUS_FAILURE;
1922     }
1923
1924     status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
1925    // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword);
1926
1927     if ( !status )
1928     {
1929
1930         if (tempword & FT1000_DB_DPRAM_RX) {
1931             //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type:  FT1000_DB_DPRAM_RX\n");
1932
1933             status = ft1000_read_dpram16(dev, 0x200, (u8 *)&data, 0);
1934             //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data);
1935             size = ntohs(data) + 16 + 2; //wai
1936             if (size % 4) {
1937                 modulo = 4 - (size % 4);
1938                 size = size + modulo;
1939             }
1940             status = ft1000_read_dpram16(dev, 0x201, (u8 *)&portid, 1);
1941             portid &= 0xff;
1942             //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid);
1943
1944             if (size < MAX_CMD_SQSIZE) {
1945                 switch (portid)
1946                 {
1947                     case DRIVERID:
1948                         DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
1949
1950                         status = ft1000_proc_drvmsg (dev, size);
1951                         if (status != STATUS_SUCCESS )
1952                             return status;
1953                         break;
1954                     case DSPBCMSGID:
1955                         // This is a dsp broadcast message
1956                         // Check which application has registered for dsp broadcast messages
1957                         //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n");
1958
1959                         for (i=0; i<MAX_NUM_APP; i++) {
1960                            if ( (info->app_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) &&
1961                                          (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT)  )
1962                            {
1963                                //DEBUG("Dsp broadcast message detected for app id %d\n", i);
1964                                nxtph = FT1000_DPRAM_RX_BASE + 2;
1965                                pdpram_blk = ft1000_get_buffer (&freercvpool);
1966                                if (pdpram_blk != NULL) {
1967                                    if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
1968                                         ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
1969                                        // Put message into the appropriate application block
1970                                        info->app_info[i].nRxMsg++;
1971                                        spin_lock_irqsave(&free_buff_lock, flags);
1972                                        list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
1973                                        info->app_info[i].NumOfMsg++;
1974                                        spin_unlock_irqrestore(&free_buff_lock, flags);
1975                                        wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
1976                                    }
1977                                    else {
1978                                        info->app_info[i].nRxMsgMiss++;
1979                                        // Put memory back to free pool
1980                                        ft1000_free_buffer(pdpram_blk, &freercvpool);
1981                                        DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
1982                                    }
1983                                }
1984                                else {
1985                                    DEBUG("Out of memory in free receive command pool\n");
1986                                    info->app_info[i].nRxMsgMiss++;
1987                                }//endof if (pdpram_blk != NULL)
1988                            }//endof if
1989                            //else
1990                            //    DEBUG("app_info mismatch\n");
1991                         }// endof for
1992                         break;
1993                     default:
1994                         pdpram_blk = ft1000_get_buffer (&freercvpool);
1995                         //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk);
1996                         if (pdpram_blk != NULL) {
1997                            if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
1998                                 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
1999                                // Search for correct application block
2000                                for (i=0; i<MAX_NUM_APP; i++) {
2001                                    if (info->app_info[i].app_id == ppseudo_hdr->portdest) {
2002                                        break;
2003                                    }
2004                                }
2005
2006                                if (i == MAX_NUM_APP) {
2007                                    DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr->portdest);
2008                                    // Put memory back to free pool
2009                                    ft1000_free_buffer(pdpram_blk, &freercvpool);
2010                                }
2011                                else {
2012                                    if (info->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
2013                                        // Put memory back to free pool
2014                                        ft1000_free_buffer(pdpram_blk, &freercvpool);
2015                                    }
2016                                    else {
2017                                        info->app_info[i].nRxMsg++;
2018                                        // Put message into the appropriate application block
2019                                        //pxu spin_lock_irqsave(&free_buff_lock, flags);
2020                                        list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
2021                                        info->app_info[i].NumOfMsg++;
2022                                        //pxu spin_unlock_irqrestore(&free_buff_lock, flags);
2023                                        //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
2024                                    }
2025                                }
2026                            }
2027                            else {
2028                                // Put memory back to free pool
2029                                ft1000_free_buffer(pdpram_blk, &freercvpool);
2030                            }
2031                         }
2032                         else {
2033                             DEBUG("Out of memory in free receive command pool\n");
2034                         }
2035                         break;
2036                 } //end of switch
2037             } //endof if (size < MAX_CMD_SQSIZE)
2038             else {
2039                 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size);
2040             }
2041             status = ft1000_write_register (dev, FT1000_DB_DPRAM_RX, FT1000_REG_DOORBELL);
2042         }
2043         else if (tempword & FT1000_DSP_ASIC_RESET) {
2044             //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type:  FT1000_DSP_ASIC_RESET\n");
2045
2046             // Let's reset the ASIC from the Host side as well
2047             status = ft1000_write_register (dev, ASIC_RESET_BIT, FT1000_REG_RESET);
2048             status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
2049             i = 0;
2050             while (tempword & ASIC_RESET_BIT) {
2051                 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
2052                 msleep(10);
2053                 i++;
2054                 if (i==100)
2055                     break;
2056             }
2057             if (i==100) {
2058                 DEBUG("Unable to reset ASIC\n");
2059                 return STATUS_SUCCESS;
2060             }
2061             msleep(10);
2062             // Program WMARK register
2063             status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2064             // clear ASIC reset doorbell
2065             status = ft1000_write_register (dev, FT1000_DSP_ASIC_RESET, FT1000_REG_DOORBELL);
2066             msleep(10);
2067         }
2068         else if (tempword & FT1000_ASIC_RESET_REQ) {
2069             DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type:  FT1000_ASIC_RESET_REQ\n");
2070
2071             // clear ASIC reset request from DSP
2072             status = ft1000_write_register (dev, FT1000_ASIC_RESET_REQ, FT1000_REG_DOORBELL);
2073             status = ft1000_write_register (dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
2074             // copy dsp session record from Adapter block
2075             status = ft1000_write_dpram32 (dev, 0, (u8 *)&info->DSPSess.Rec[0], 1024);
2076             // Program WMARK register
2077             status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
2078             // ring doorbell to tell DSP that ASIC is out of reset
2079             status = ft1000_write_register (dev, FT1000_ASIC_RESET_DSP, FT1000_REG_DOORBELL);
2080         }
2081         else if (tempword & FT1000_DB_COND_RESET) {
2082             DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type:  FT1000_DB_COND_RESET\n");
2083 //By Jim
2084 // Reset ASIC and DSP
2085 //MAG
2086             if (info->fAppMsgPend == 0) {
2087                // Reset ASIC and DSP
2088
2089                 status    = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (u8 *)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
2090                 status    = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (u8 *)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
2091                 status    = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (u8 *)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
2092                 status    = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (u8 *)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
2093                 info->CardReady = 0;
2094                 info->DrvErrNum = DSP_CONDRESET_INFO;
2095                 DEBUG("ft1000_hw:DSP conditional reset requested\n");
2096                 info->ft1000_reset(dev->net);
2097             }
2098             else {
2099                 info->fProvComplete = 0;
2100                 info->fCondResetPend = 1;
2101             }
2102
2103             ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL);
2104         }
2105
2106     }//endof if ( !status )
2107
2108     //DEBUG("return from ft1000_poll.\n");
2109     return STATUS_SUCCESS;
2110
2111 }
2112
2113 /*end of Jim*/