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