staging: ft1000: Fix coding style in ft1000_chkcard function.
[deliverable/linux.git] / drivers / staging / ft1000 / ft1000-usb / ft1000_hw.c
CommitLineData
f7c1be0c
MB
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>
f7c1be0c
MB
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
2a953cfd 34static int ft1000_reset(struct net_device *ft1000dev);
1a88a068 35static int ft1000_submit_rx_urb(struct ft1000_info *info);
f7c1be0c
MB
36static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev);
37static int ft1000_open (struct net_device *dev);
f7c1be0c 38static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev);
f7c1be0c 39static int ft1000_chkcard (struct ft1000_device *dev);
f7c1be0c
MB
40
41//Jim
42
43static u8 tempbuffer[1600];
f7c1be0c
MB
44
45#define MAX_RCV_LOOP 100
46
f7c1be0c
MB
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
bf3146c8 59//
f7c1be0c
MB
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//---------------------------------------------------------------------------
537a20ab
MB
68static 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)
f7c1be0c
MB
71{
72 u16 ret;
bf3146c8 73
537a20ab
MB
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);
bf3146c8 81
310bad04
MB
82 if (ret > 0)
83 ret = 0;
bf3146c8 84
537a20ab 85 return ret;
f7c1be0c 86}
537a20ab 87
f7c1be0c
MB
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
bf3146c8 94//
f7c1be0c
MB
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
31da7c09
MB
104int ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data,
105 u16 nRegIndx)
f7c1be0c 106{
31da7c09
MB
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);
f7c1be0c 118
31da7c09 119 return ret;
bf3146c8 120}
f7c1be0c
MB
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
bf3146c8 128//
f7c1be0c
MB
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//---------------------------------------------------------------------------
31da7c09
MB
137int ft1000_write_register(struct ft1000_device *ft1000dev, u16 value,
138 u16 nRegIndx)
f7c1be0c 139{
31da7c09
MB
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);
bf3146c8 151
31da7c09 152 return ret;
f7c1be0c
MB
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
bf3146c8 162//
f7c1be0c
MB
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
e3fc923d
MB
172int ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
173 u16 cnt)
f7c1be0c 174{
e3fc923d 175 int ret = STATUS_SUCCESS;
f7c1be0c 176
e3fc923d
MB
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);
f7c1be0c 186
e3fc923d 187 return ret;
bf3146c8 188}
f7c1be0c
MB
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
bf3146c8 197//
f7c1be0c
MB
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//---------------------------------------------------------------------------
e3fc923d
MB
206int ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
207 u16 cnt)
f7c1be0c 208{
e3fc923d
MB
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;
f7c1be0c
MB
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
bf3146c8 234//
f7c1be0c
MB
235// Returns: STATUS_SUCCESS - success
236// STATUS_FAILURE - failure
237//
238// Description: This function read 16 bits from DPRAM
239//
240// Notes:
241//
242//---------------------------------------------------------------------------
460bd5dd
MB
243int ft1000_read_dpram16(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer,
244 u8 highlow)
f7c1be0c 245{
460bd5dd
MB
246 int ret = STATUS_SUCCESS;
247 u8 request;
bf3146c8 248
460bd5dd
MB
249 if (highlow == 0)
250 request = HARLEY_READ_DPRAM_LOW;
251 else
252 request = HARLEY_READ_DPRAM_HIGH;
f7c1be0c 253
460bd5dd
MB
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);
f7c1be0c 263
460bd5dd 264 return ret;
bf3146c8 265}
f7c1be0c
MB
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
bf3146c8 274//
f7c1be0c
MB
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//---------------------------------------------------------------------------
4a526fca 283int ft1000_write_dpram16(struct ft1000_device *ft1000dev, u16 indx, u16 value, u8 highlow)
f7c1be0c 284{
460bd5dd
MB
285 int ret = STATUS_SUCCESS;
286 u8 request;
bf3146c8 287
460bd5dd
MB
288 if (highlow == 0)
289 request = HARLEY_WRITE_DPRAM_LOW;
290 else
291 request = HARLEY_WRITE_DPRAM_HIGH;
f7c1be0c 292
460bd5dd
MB
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);
bf3146c8 302
460bd5dd 303 return ret;
f7c1be0c
MB
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
bf3146c8
GKH
312//
313//
f7c1be0c
MB
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//---------------------------------------------------------------------------
71e3335d
MB
322int fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, u16 indx,
323 u8 *buffer)
f7c1be0c 324{
71e3335d
MB
325 u8 buf[16];
326 u16 pos;
327 int ret = STATUS_SUCCESS;
f7c1be0c 328
71e3335d
MB
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 }
f7c1be0c 345
71e3335d 346 return ret;
bf3146c8 347}
f7c1be0c
MB
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
bf3146c8
GKH
356//
357//
f7c1be0c
MB
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//---------------------------------------------------------------------------
4a526fca 366int fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, u16 indx, u8 *buffer)
f7c1be0c 367{
8bfef502
MB
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);
bf3146c8 379
8bfef502
MB
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 }
f7c1be0c 391
8bfef502 392 ret = ft1000_read_dpram32(ft1000dev, pos1, (u8 *)&resultbuffer[0], 16);
f7c1be0c 393
8bfef502
MB
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 }
bf3146c8 401
8bfef502
MB
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 }
f7c1be0c 418
8bfef502 419 return ret;
f7c1be0c
MB
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//-----------------------------------------------------------------------
677aaa43 433static void card_reset_dsp(struct ft1000_device *ft1000dev, bool value)
f7c1be0c 434{
677aaa43
MB
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 }
f7c1be0c
MB
467}
468
469//---------------------------------------------------------------------------
a209efad 470// Function: card_send_command
f7c1be0c
MB
471//
472// Parameters: ft1000_device - device structure
473// ptempbuffer - command buffer
474// size - command buffer size
bf3146c8 475//
f7c1be0c
MB
476// Returns: STATUS_SUCCESS - success
477// STATUS_FAILURE - failure
478//
479// Description: This function sends a command to ASIC
480//
481// Notes:
482//
483//---------------------------------------------------------------------------
68e79bcc
MB
484void card_send_command(struct ft1000_device *ft1000dev, void *ptempbuffer,
485 int size)
f7c1be0c 486{
68e79bcc
MB
487 unsigned short temp;
488 unsigned char *commandbuf;
bf3146c8 489
68e79bcc 490 DEBUG("card_send_command: enter card_send_command... size=%d\n", size);
bf3146c8 491
68e79bcc
MB
492 commandbuf = (unsigned char *)kmalloc(size + 2, GFP_KERNEL);
493 memcpy((void *)commandbuf + 2, (void *)ptempbuffer, size);
bf3146c8 494
68e79bcc 495 //DEBUG("card_send_command: Command Send\n");
bf3146c8 496
68e79bcc 497 ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL);
bf3146c8 498
68e79bcc
MB
499 if (temp & 0x0100)
500 msleep(10);
bf3146c8 501
68e79bcc
MB
502 /* check for odd word */
503 size = size + 2;
f7c1be0c 504
68e79bcc
MB
505 /* Must force to be 32 bit aligned */
506 if (size % 4)
507 size += 4 - (size % 4);
bf3146c8 508
68e79bcc
MB
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);
bf3146c8 516
68e79bcc
MB
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 }
f7c1be0c
MB
522
523}
524
f7c1be0c
MB
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//-----------------------------------------------------------------------
5cb9954a 535int dsp_reload(struct ft1000_device *ft1000dev)
f7c1be0c 536{
3529bd41
MB
537 u16 status;
538 u16 tempword;
539 u32 templong;
bf3146c8 540
1a88a068 541 struct ft1000_info *pft1000info;
bf3146c8 542
3529bd41 543 pft1000info = netdev_priv(ft1000dev->net);
f7c1be0c 544
3529bd41 545 pft1000info->CardReady = 0;
f7c1be0c 546
3529bd41
MB
547 /* Program Interrupt Mask register */
548 status = ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_SUP_IMASK);
f7c1be0c 549
3529bd41
MB
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);
f7c1be0c 556
3529bd41
MB
557 /* Toggle DSP reset */
558 card_reset_dsp(ft1000dev, 1);
559 msleep(1000);
560 card_reset_dsp(ft1000dev, 0);
561 msleep(1000);
f7c1be0c 562
3529bd41
MB
563 status =
564 ft1000_write_register(ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
f7c1be0c 565
3529bd41
MB
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);
f7c1be0c 571
3529bd41
MB
572 /* call codeloader */
573 status = scram_dnldr(ft1000dev, pFileStart, FileLength);
bf3146c8 574
5cb9954a
MB
575 if (status != STATUS_SUCCESS)
576 return -EIO;
f7c1be0c 577
3529bd41 578 msleep(1000);
f7c1be0c 579
3529bd41 580 DEBUG("dsp_reload returned\n");
f7c1be0c 581
3529bd41 582 return 0;
f7c1be0c
MB
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//---------------------------------------------------------------------------
84a60963 596static void ft1000_reset_asic(struct net_device *dev)
f7c1be0c 597{
1a88a068 598 struct ft1000_info *info = netdev_priv(dev);
84a60963
MB
599 struct ft1000_device *ft1000dev = info->pFt1000Dev;
600 u16 tempword;
bf3146c8 601
84a60963 602 DEBUG("ft1000_hw:ft1000_reset_asic called\n");
f7c1be0c 603
84a60963 604 info->ASICResetNum++;
bf3146c8 605
84a60963
MB
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);
f7c1be0c 611
84a60963 612 mdelay(1);
bf3146c8 613
84a60963
MB
614 /* set watermark to -1 in order to not generate an interrrupt */
615 ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_MAG_WATERMARK);
bf3146c8 616
84a60963
MB
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);
f7c1be0c 623}
f7c1be0c 624
f7c1be0c
MB
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)
bf3146c8 634// TRUE (card reset successful)
f7c1be0c
MB
635//
636//---------------------------------------------------------------------------
3071c12e 637static int ft1000_reset_card(struct net_device *dev)
f7c1be0c 638{
1a88a068 639 struct ft1000_info *info = netdev_priv(dev);
3071c12e
MB
640 struct ft1000_device *ft1000dev = info->pFt1000Dev;
641 u16 tempword;
e27d96dd 642 struct prov_record *ptr;
f7c1be0c 643
3071c12e 644 DEBUG("ft1000_hw:ft1000_reset_card called.....\n");
f7c1be0c 645
3071c12e
MB
646 info->fCondResetPend = 1;
647 info->CardReady = 0;
648 info->fProvComplete = 0;
bf3146c8 649
3071c12e
MB
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 }
bf3146c8 659
3071c12e
MB
660 DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n");
661 ft1000_reset_asic(dev);
bf3146c8 662
3071c12e 663 info->DSPResetNum++;
f7c1be0c 664
3071c12e
MB
665 DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n");
666 dsp_reload(ft1000dev);
bf3146c8 667
3071c12e 668 DEBUG("dsp reload successful\n");
f7c1be0c 669
3071c12e 670 mdelay(10);
bf3146c8 671
3071c12e
MB
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);
bf3146c8 678
3071c12e 679 info->CardReady = 1;
bf3146c8 680
3071c12e 681 info->fCondResetPend = 0;
f7c1be0c 682
3071c12e 683 return TRUE;
f7c1be0c
MB
684}
685
686
687//mbelian
688#ifdef HAVE_NET_DEVICE_OPS
689static const struct net_device_ops ftnet_ops =
690{
cb3aa5d5
MB
691 .ndo_open = &ft1000_open,
692 .ndo_stop = &ft1000_close,
693 .ndo_start_xmit = &ft1000_start_xmit,
694 .ndo_get_stats = &ft1000_netdev_stats,
f7c1be0c
MB
695};
696#endif
697
698
699//---------------------------------------------------------------------------
700// Function: init_ft1000_netdev
701//
702// Parameters: ft1000dev - device structure
703//
bf3146c8 704//
f7c1be0c
MB
705// Returns: STATUS_SUCCESS - success
706// STATUS_FAILURE - failure
707//
708// Description: This function initialize the network device
709//
710// Notes:
711//
712//---------------------------------------------------------------------------
f135da03 713int init_ft1000_netdev(struct ft1000_device *ft1000dev)
f7c1be0c 714{
6c284c7b 715 struct net_device *netdev;
1a88a068 716 struct ft1000_info *pInfo = NULL;
29437ab0 717 struct dpram_blk *pdpram_blk;
f9d17373 718 int i, ret_val;
b7378b9e 719 struct list_head *cur, *tmp;
f9d17373 720 char card_nr[2];
448d4014 721 unsigned long gCardIndex = 0;
f7c1be0c 722
6c284c7b 723 DEBUG("Enter init_ft1000_netdev...\n");
f7c1be0c 724
1a88a068 725 netdev = alloc_etherdev(sizeof(struct ft1000_info));
6c284c7b
MB
726 if (!netdev) {
727 DEBUG("init_ft1000_netdev: can not allocate network device\n");
728 return -ENOMEM;
729 }
f7c1be0c 730
e33196e1 731 pInfo = netdev_priv(netdev);
bf3146c8 732
1a88a068 733 memset(pInfo, 0, sizeof(struct ft1000_info));
f7c1be0c 734
6c284c7b 735 dev_alloc_name(netdev, netdev->name);
f7c1be0c 736
6c284c7b 737 DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name);
bf3146c8 738
6c284c7b 739 if (strncmp(netdev->name, "eth", 3) == 0) {
f9d17373
MB
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");
78890fdb 745 goto err_net;
f9d17373
MB
746 }
747
6c284c7b
MB
748 pInfo->CardNumber = gCardIndex;
749 DEBUG("card number = %d\n", pInfo->CardNumber);
750 } else {
751 printk(KERN_ERR "ft1000: Invalid device name\n");
78890fdb
MB
752 ret_val = -ENXIO;
753 goto err_net;
6c284c7b
MB
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;
f7c1be0c
MB
776 pInfo->usbboot = 0;
777 pInfo->dspalive = 0;
eb21c158 778 memset(&pInfo->tempbuf[0], 0, sizeof(pInfo->tempbuf));
f7c1be0c 779
6c284c7b 780 INIT_LIST_HEAD(&pInfo->prov_list);
f7c1be0c 781
9119dee1 782 INIT_LIST_HEAD(&pInfo->nodes.list);
6c284c7b 783
f7c1be0c 784#ifdef HAVE_NET_DEVICE_OPS
bf3146c8 785 netdev->netdev_ops = &ftnet_ops;
f7c1be0c 786#else
6c284c7b
MB
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;
f7c1be0c
MB
791#endif
792
6c284c7b 793 ft1000dev->net = netdev;
f7c1be0c 794
6c284c7b
MB
795 DEBUG("Initialize free_buff_lock and freercvpool\n");
796 spin_lock_init(&free_buff_lock);
f7c1be0c 797
6c284c7b
MB
798 /* initialize a list of buffers to be use for queuing
799 * up receive command data
800 */
801 INIT_LIST_HEAD(&freercvpool);
f7c1be0c 802
6c284c7b
MB
803 /* create list of free buffers */
804 for (i = 0; i < NUM_OF_FREE_BUFFERS; i++) {
805 /* Get memory for DPRAM_DATA link list */
29437ab0 806 pdpram_blk = kmalloc(sizeof(struct dpram_blk), GFP_KERNEL);
78890fdb
MB
807 if (pdpram_blk == NULL) {
808 ret_val = -ENOMEM;
809 goto err_free;
810 }
6c284c7b
MB
811 /* Get a block of memory to store command data */
812 pdpram_blk->pbuffer = kmalloc(MAX_CMD_SQSIZE, GFP_KERNEL);
78890fdb
MB
813 if (pdpram_blk->pbuffer == NULL) {
814 ret_val = -ENOMEM;
815 kfree(pdpram_blk);
816 goto err_free;
817 }
6c284c7b
MB
818 /* link provisioning data */
819 list_add_tail(&pdpram_blk->list, &freercvpool);
820 }
821 numofmsgbuf = NUM_OF_FREE_BUFFERS;
bf3146c8 822
78890fdb 823 return 0;
bf3146c8 824
b7378b9e 825err_free:
1055cc99 826 list_for_each_safe(cur, tmp, &freercvpool) {
29437ab0 827 pdpram_blk = list_entry(cur, struct dpram_blk, list);
b7378b9e
VK
828 list_del(&pdpram_blk->list);
829 kfree(pdpram_blk->pbuffer);
830 kfree(pdpram_blk);
831 }
78890fdb
MB
832err_net:
833 free_netdev(netdev);
834 return ret_val;
f7c1be0c
MB
835}
836
f7c1be0c
MB
837//---------------------------------------------------------------------------
838// Function: reg_ft1000_netdev
839//
840// Parameters: ft1000dev - device structure
841//
bf3146c8 842//
f7c1be0c
MB
843// Returns: STATUS_SUCCESS - success
844// STATUS_FAILURE - failure
845//
846// Description: This function register the network driver
847//
848// Notes:
849//
850//---------------------------------------------------------------------------
05a7c39c
MB
851int reg_ft1000_netdev(struct ft1000_device *ft1000dev,
852 struct usb_interface *intf)
f7c1be0c 853{
05a7c39c 854 struct net_device *netdev;
1a88a068 855 struct ft1000_info *pInfo;
7dc59115 856 int rc;
f7c1be0c 857
05a7c39c
MB
858 netdev = ft1000dev->net;
859 pInfo = netdev_priv(ft1000dev->net);
860 DEBUG("Enter reg_ft1000_netdev...\n");
f7c1be0c 861
05a7c39c 862 ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID);
bf3146c8 863
05a7c39c
MB
864 usb_set_intfdata(intf, pInfo);
865 SET_NETDEV_DEV(netdev, &intf->dev);
f7c1be0c 866
05a7c39c
MB
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 }
f7c1be0c 873
05a7c39c 874 ft1000_create_dev(ft1000dev);
f7c1be0c 875
05a7c39c 876 DEBUG("reg_ft1000_netdev returned\n");
f7c1be0c 877
05a7c39c 878 pInfo->CardReady = 1;
f7c1be0c 879
aaf0885c 880 return 0;
f7c1be0c
MB
881}
882
2a953cfd 883static int ft1000_reset(struct net_device *dev)
f7c1be0c 884{
2dd9017b
MB
885 ft1000_reset_card(dev);
886 return 0;
f7c1be0c
MB
887}
888
889//---------------------------------------------------------------------------
890// Function: ft1000_usb_transmit_complete
891//
892// Parameters: urb - transmitted usb urb
893//
bf3146c8 894//
f7c1be0c
MB
895// Returns: none
896//
897// Description: This is the callback function when a urb is transmitted
898//
899// Notes:
900//
901//---------------------------------------------------------------------------
902static void ft1000_usb_transmit_complete(struct urb *urb)
903{
904
251c72f8 905 struct ft1000_device *ft1000dev = urb->context;
f7c1be0c
MB
906
907 //DEBUG("ft1000_usb_transmit_complete entered\n");
f7c1be0c 908
251c72f8
MB
909 if (urb->status)
910 pr_err("%s: TX status %d\n", ft1000dev->net->name, urb->status);
f7c1be0c 911
251c72f8 912 netif_wake_queue(ft1000dev->net);
f7c1be0c 913
f7c1be0c
MB
914 //DEBUG("Return from ft1000_usb_transmit_complete\n");
915}
916
f7c1be0c
MB
917//---------------------------------------------------------------------------
918//
919// Function: ft1000_copy_down_pkt
bf3146c8
GKH
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
f7c1be0c
MB
922// FIFO.
923// Input:
924// dev - device structure
925// packet - address of ethernet packet
926// len - length of IP packet
927// Output:
bf3146c8
GKH
928// status - FAILURE
929// SUCCESS
f7c1be0c
MB
930//
931//---------------------------------------------------------------------------
d8dfaf4c 932static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len)
f7c1be0c 933{
1a88a068 934 struct ft1000_info *pInfo = netdev_priv(netdev);
d8dfaf4c 935 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
f7c1be0c 936
d2b07455 937 int count, ret;
d8dfaf4c 938 u8 *t;
d2b07455 939 struct pseudo_hdr hdr;
bf3146c8 940
d8dfaf4c
MB
941 if (!pInfo->CardReady) {
942 DEBUG("ft1000_copy_down_pkt::Card Not Ready\n");
943 return -ENODEV;
944 }
bf3146c8 945
d8dfaf4c 946 //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len);
bf3146c8 947
b13e39b2 948 count = sizeof(struct pseudo_hdr) + len;
d8dfaf4c
MB
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 }
bf3146c8 954
d8dfaf4c
MB
955 if (count % 4)
956 count = count + (4 - (count % 4));
bf3146c8 957
d2b07455
MB
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 ^
d8dfaf4c 969 hdr.portdest ^ hdr.portsrc ^ hdr.sh_str_id ^ hdr.control;
d2b07455
MB
970
971 memcpy(&pFt1000Dev->tx_buf[0], &hdr, sizeof(hdr));
b13e39b2 972 memcpy(&(pFt1000Dev->tx_buf[sizeof(struct pseudo_hdr)]), packet, len);
f7c1be0c 973
d8dfaf4c 974 netif_stop_queue(netdev);
bf3146c8 975
d8dfaf4c 976 //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count);
bf3146c8 977
d8dfaf4c
MB
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);
bf3146c8 984
d8dfaf4c
MB
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 } */
bf3146c8 991
35e9403b 992 ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC);
d8dfaf4c 993
35e9403b 994 if (ret) {
f7c1be0c 995 DEBUG("ft1000 failed tx_urb %d\n", ret);
35e9403b
MB
996 return ret;
997 } else {
998 pInfo->stats.tx_packets++;
d8dfaf4c 999 pInfo->stats.tx_bytes += (len + 14);
35e9403b 1000 }
bf3146c8 1001
d8dfaf4c 1002 //DEBUG("ft1000_copy_down_pkt() exit\n");
bf3146c8 1003
35e9403b 1004 return 0;
f7c1be0c
MB
1005}
1006
d8dfaf4c 1007
f7c1be0c
MB
1008//---------------------------------------------------------------------------
1009// Function: ft1000_start_xmit
1010//
1011// Parameters: skb - socket buffer to be sent
1012// dev - network device
1013//
bf3146c8 1014//
f7c1be0c
MB
1015// Returns: none
1016//
1017// Description: transmit a ethernet packet
1018//
1019// Notes:
1020//
1021//---------------------------------------------------------------------------
bf3146c8 1022static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev)
f7c1be0c 1023{
1a88a068 1024 struct ft1000_info *pInfo = netdev_priv(dev);
e31e3385
MB
1025 struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev;
1026 u8 *pdata;
1027 int maxlen, pipe;
bf3146c8 1028
e31e3385 1029 //DEBUG(" ft1000_start_xmit() entered\n");
bf3146c8 1030
e31e3385
MB
1031 if (skb == NULL) {
1032 DEBUG("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n");
1033 return NETDEV_TX_OK;
1034 }
bf3146c8 1035
e31e3385
MB
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 }
bf3146c8 1063//mbelian
e31e3385
MB
1064 ft1000_copy_down_pkt(dev, (pdata + ENET_HEADER_SIZE - 2),
1065 skb->len - ENET_HEADER_SIZE + 2);
bf3146c8 1066
3b3291e8
MB
1067err:
1068 dev_kfree_skb(skb);
e31e3385 1069 //DEBUG(" ft1000_start_xmit() exit\n");
bf3146c8 1070
3b3291e8 1071 return NETDEV_TX_OK;
f7c1be0c
MB
1072}
1073
e31e3385 1074
f7c1be0c
MB
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:
bf3146c8
GKH
1084// status - FAILURE
1085// SUCCESS
f7c1be0c
MB
1086//
1087//---------------------------------------------------------------------------
bee1b21c 1088static int ft1000_copy_up_pkt(struct urb *urb)
f7c1be0c 1089{
1a88a068 1090 struct ft1000_info *info = urb->context;
bee1b21c
MB
1091 struct ft1000_device *ft1000dev = info->pFt1000Dev;
1092 struct net_device *net = ft1000dev->net;
bf3146c8 1093
bee1b21c
MB
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;
f7c1be0c 1102
bee1b21c 1103 //DEBUG("ft1000_copy_up_pkt entered\n");
f7c1be0c 1104
bee1b21c
MB
1105 if (ft1000dev->status & FT1000_STATUS_CLOSING) {
1106 DEBUG("network driver is closed, return\n");
1107 return STATUS_SUCCESS;
1108 }
1109 // Read length
1110 len = urb->transfer_buffer_length;
1111 lena = urb->actual_length; //mbelian
1112 //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n",
1113 // urb->transfer_buffer_length, urb->actual_length);
1114
1115 chksum = (u16 *) ft1000dev->rx_buf;
1116
1117 tempword = *chksum++;
1118 for (i = 1; i < 7; i++)
1119 tempword ^= *chksum++;
1120
1121 if (tempword != *chksum) {
1122 info->stats.rx_errors++;
1123 ft1000_submit_rx_urb(info);
1124 return STATUS_FAILURE;
1125 }
bf3146c8 1126
bee1b21c 1127 //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum);
bf3146c8 1128
bee1b21c 1129 skb = dev_alloc_skb(len + 12 + 2);
bf3146c8 1130
bee1b21c
MB
1131 if (skb == NULL) {
1132 DEBUG("ft1000_copy_up_pkt: No Network buffers available\n");
1133 info->stats.rx_errors++;
1134 ft1000_submit_rx_urb(info);
1135 return STATUS_FAILURE;
1136 }
f7c1be0c 1137
bee1b21c
MB
1138 pbuffer = (u8 *) skb_put(skb, len + 12);
1139
1140 /* subtract the number of bytes read already */
1141 ptemp = pbuffer;
1142
1143 /* fake MAC address */
1144 *pbuffer++ = net->dev_addr[0];
1145 *pbuffer++ = net->dev_addr[1];
1146 *pbuffer++ = net->dev_addr[2];
1147 *pbuffer++ = net->dev_addr[3];
1148 *pbuffer++ = net->dev_addr[4];
1149 *pbuffer++ = net->dev_addr[5];
1150 *pbuffer++ = 0x00;
1151 *pbuffer++ = 0x07;
1152 *pbuffer++ = 0x35;
1153 *pbuffer++ = 0xff;
1154 *pbuffer++ = 0xff;
1155 *pbuffer++ = 0xfe;
1156
1157 memcpy(pbuffer, ft1000dev->rx_buf + sizeof(struct pseudo_hdr),
1158 len - sizeof(struct pseudo_hdr));
1159
1160 //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n");
1161 /*for (i=0; i<len+12; i++)
1162 {
1163 DEBUG("ft1000_copy_up_pkt: Protocol Data: 0x%x\n ", *ptemp++);
1164 } */
f7c1be0c 1165
bee1b21c 1166 skb->dev = net;
bf3146c8 1167
bee1b21c
MB
1168 skb->protocol = eth_type_trans(skb, net);
1169 skb->ip_summed = CHECKSUM_UNNECESSARY;
1170 netif_rx(skb);
f7c1be0c 1171
bee1b21c
MB
1172 info->stats.rx_packets++;
1173 /* Add on 12 bytes for MAC address which was removed */
1174 info->stats.rx_bytes += (lena + 12); //mbelian
f7c1be0c 1175
bee1b21c
MB
1176 ft1000_submit_rx_urb(info);
1177 //DEBUG("ft1000_copy_up_pkt exited\n");
1178 return SUCCESS;
f7c1be0c
MB
1179}
1180
bee1b21c 1181
f7c1be0c
MB
1182//---------------------------------------------------------------------------
1183//
1184// Function: ft1000_submit_rx_urb
1185// Descripton: the receiving function of the network driver
1186//
1187// Input:
1188// info - a private structure contains the device information
1189//
1190// Output:
bf3146c8
GKH
1191// status - FAILURE
1192// SUCCESS
f7c1be0c
MB
1193//
1194//---------------------------------------------------------------------------
1a88a068 1195static int ft1000_submit_rx_urb(struct ft1000_info *info)
f7c1be0c 1196{
6b2a66f2
MB
1197 int result;
1198 struct ft1000_device *pFt1000Dev = info->pFt1000Dev;
f7c1be0c 1199
6b2a66f2
MB
1200 //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb));
1201 if (pFt1000Dev->status & FT1000_STATUS_CLOSING) {
1202 DEBUG("network driver is closed, return\n");
1203 //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian
1204 return -ENODEV;
1205 }
bf3146c8 1206
6b2a66f2
MB
1207 usb_fill_bulk_urb(pFt1000Dev->rx_urb,
1208 pFt1000Dev->dev,
1209 usb_rcvbulkpipe(pFt1000Dev->dev,
1210 pFt1000Dev->bulk_in_endpointAddr),
1211 pFt1000Dev->rx_buf, MAX_BUF_SIZE,
1212 (usb_complete_t) ft1000_copy_up_pkt, info);
f7c1be0c 1213
6b2a66f2 1214 result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC);
bf3146c8 1215
6b2a66f2
MB
1216 if (result) {
1217 pr_err("ft1000_submit_rx_urb: submitting rx_urb %d failed\n",
1218 result);
1219 return result;
1220 }
1221 //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result);
f7c1be0c 1222
d7780865 1223 return 0;
f7c1be0c
MB
1224}
1225
6b2a66f2 1226
f7c1be0c
MB
1227//---------------------------------------------------------------------------
1228// Function: ft1000_open
1229//
bf3146c8 1230// Parameters:
f7c1be0c
MB
1231// dev - network device
1232//
bf3146c8 1233//
f7c1be0c
MB
1234// Returns: none
1235//
1236// Description: open the network driver
1237//
1238// Notes:
1239//
1240//---------------------------------------------------------------------------
a01ffcd6 1241static int ft1000_open(struct net_device *dev)
f7c1be0c 1242{
e33196e1 1243 struct ft1000_info *pInfo = netdev_priv(dev);
a01ffcd6 1244 struct timeval tv; //mbelian
95112cb4 1245 int ret;
f7c1be0c 1246
a01ffcd6
MB
1247 DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber);
1248 //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len);
f7c1be0c 1249
a01ffcd6
MB
1250 pInfo->stats.rx_bytes = 0; //mbelian
1251 pInfo->stats.tx_bytes = 0; //mbelian
1252 pInfo->stats.rx_packets = 0; //mbelian
1253 pInfo->stats.tx_packets = 0; //mbelian
f7c1be0c 1254 do_gettimeofday(&tv);
a01ffcd6
MB
1255 pInfo->ConTm = tv.tv_sec;
1256 pInfo->ProgConStat = 0; //mbelian
bf3146c8 1257
a01ffcd6 1258 netif_start_queue(dev);
bf3146c8 1259
a01ffcd6 1260 netif_carrier_on(dev); //mbelian
bf3146c8 1261
95112cb4
MB
1262 ret = ft1000_submit_rx_urb(pInfo);
1263
1264 return ret;
f7c1be0c
MB
1265}
1266
1267//---------------------------------------------------------------------------
1268// Function: ft1000_close
1269//
bf3146c8 1270// Parameters:
f7c1be0c
MB
1271// net - network device
1272//
bf3146c8 1273//
f7c1be0c
MB
1274// Returns: none
1275//
1276// Description: close the network driver
1277//
1278// Notes:
1279//
1280//---------------------------------------------------------------------------
1281int ft1000_close(struct net_device *net)
1282{
e33196e1 1283 struct ft1000_info *pInfo = netdev_priv(net);
a007e842 1284 struct ft1000_device *ft1000dev = pInfo->pFt1000Dev;
f7c1be0c 1285
a007e842 1286 //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt);
bf3146c8 1287
a007e842 1288 ft1000dev->status |= FT1000_STATUS_CLOSING;
f7c1be0c 1289
a007e842 1290 //DEBUG("ft1000_close: calling usb_kill_urb \n");
f7c1be0c 1291
a007e842
MB
1292 DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev);
1293 netif_carrier_off(net); //mbelian
1294 netif_stop_queue(net);
1295 //DEBUG("ft1000_close: netif_stop_queue called\n");
1296 ft1000dev->status &= ~FT1000_STATUS_CLOSING;
f7c1be0c 1297
a007e842 1298 pInfo->ProgConStat = 0xff; //mbelian
f7c1be0c 1299
a007e842 1300 return 0;
f7c1be0c
MB
1301}
1302
1303static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev)
1304{
e33196e1 1305 struct ft1000_info *info = netdev_priv(dev);
bf3146c8 1306
f7c1be0c
MB
1307 return &(info->stats); //mbelian
1308}
1309
1310
1311/*********************************************************************************
1312Jim
1313*/
1314
1315
1316//---------------------------------------------------------------------------
1317//
1318// Function: ft1000_chkcard
1319// Descripton: This function will check if the device is presently available on
1320// the system.
1321// Input:
1322// dev - device structure
1323// Output:
1324// status - FALSE (device is not present)
bf3146c8 1325// TRUE (device is present)
f7c1be0c
MB
1326//
1327//---------------------------------------------------------------------------
53cd3aa6
MB
1328static int ft1000_chkcard(struct ft1000_device *dev)
1329{
1330 u16 tempword;
1331 u16 status;
e33196e1 1332 struct ft1000_info *info = netdev_priv(dev->net);
bf3146c8 1333
53cd3aa6
MB
1334 if (info->fCondResetPend) {
1335 DEBUG
1336 ("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n");
1337 return TRUE;
1338 }
1339 /* Mask register is used to check for device presence since it is never
1340 * set to zero.
1341 */
1342 status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK);
1343 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword);
1344 if (tempword == 0) {
1345 DEBUG
1346 ("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n");
1347 return FALSE;
1348 }
1349 /* The system will return the value of 0xffff for the version register
1350 * if the device is not present.
1351 */
1352 status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID);
1353 //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword);
1354 if (tempword != 0x1b01) {
1355 dev->status |= FT1000_STATUS_CLOSING; //mbelian
1356 DEBUG
1357 ("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n");
1358 return FALSE;
1359 }
1360 return TRUE;
f7c1be0c
MB
1361}
1362
f7c1be0c
MB
1363//---------------------------------------------------------------------------
1364//
1365// Function: ft1000_receive_cmd
bf3146c8 1366// Descripton: This function will read a message from the dpram area.
f7c1be0c
MB
1367// Input:
1368// dev - network device structure
1369// pbuffer - caller supply address to buffer
1370// pnxtph - pointer to next pseudo header
1371// Output:
1372// Status = 0 (unsuccessful)
1373// = 1 (successful)
1374//
1375//---------------------------------------------------------------------------
81584137 1376static bool ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) {
f7c1be0c
MB
1377 u16 size, ret;
1378 u16 *ppseudohdr;
1379 int i;
1380 u16 tempword;
1381
e2cb7da1 1382 ret = ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (u8 *)&size, FT1000_MAG_PH_LEN_INDX);
f7c1be0c
MB
1383 size = ntohs(size) + PSEUDOSZ;
1384 if (size > maxsz) {
1385 DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size);
1386 return FALSE;
1387 }
1388 else {
1389 ppseudohdr = (u16 *)pbuffer;
f7c1be0c
MB
1390 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR);
1391 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1392 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
bf3146c8 1393 pbuffer++;
f7c1be0c
MB
1394 ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE+1, FT1000_REG_DPRAM_ADDR);
1395 for (i=0; i<=(size>>2); i++) {
1396 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
1397 pbuffer++;
1398 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1399 pbuffer++;
1400 }
1401 //copy odd aligned word
1402 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL);
1403 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1404 pbuffer++;
1405 ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH);
1406 //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer);
1407 pbuffer++;
1408 if (size & 0x0001) {
1409 //copy odd byte from fifo
1410 ret = ft1000_read_register(dev, &tempword, FT1000_REG_DPRAM_DATA);
1411 *pbuffer = ntohs(tempword);
1412 }
f7c1be0c
MB
1413
1414 // Check if pseudo header checksum is good
1415 // Calculate pseudo header checksum
1416 tempword = *ppseudohdr++;
1417 for (i=1; i<7; i++) {
1418 tempword ^= *ppseudohdr++;
1419 }
1420 if ( (tempword != *ppseudohdr) ) {
1421 return FALSE;
1422 }
bf3146c8 1423
f7c1be0c
MB
1424 return TRUE;
1425 }
1426}
1427
1428
2a953cfd 1429static int ft1000_dsp_prov(void *arg)
f7c1be0c
MB
1430{
1431 struct ft1000_device *dev = (struct ft1000_device *)arg;
e33196e1 1432 struct ft1000_info *info = netdev_priv(dev->net);
f7c1be0c
MB
1433 u16 tempword;
1434 u16 len;
1435 u16 i=0;
e27d96dd 1436 struct prov_record *ptr;
b13e39b2 1437 struct pseudo_hdr *ppseudo_hdr;
d1674983 1438 u16 *pmsg;
f7c1be0c 1439 u16 status;
fc549a05 1440 u16 TempShortBuf [256];
f7c1be0c
MB
1441
1442 DEBUG("*** DspProv Entered\n");
1443
8e99c33d 1444 while (list_empty(&info->prov_list) == 0)
f7c1be0c
MB
1445 {
1446 DEBUG("DSP Provisioning List Entry\n");
1447
1448 // Check if doorbell is available
1449 DEBUG("check if doorbell is cleared\n");
1450 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
1451 if (status)
1452 {
1453 DEBUG("ft1000_dsp_prov::ft1000_read_register error\n");
1454 break;
1455 }
1456
1457 while (tempword & FT1000_DB_DPRAM_TX) {
1458 mdelay(10);
1459 i++;
1460 if (i==10) {
1461 DEBUG("FT1000:ft1000_dsp_prov:message drop\n");
1462 return STATUS_FAILURE;
1463 }
1464 ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1465 }
1466
1467 if ( !(tempword & FT1000_DB_DPRAM_TX) ) {
1468 DEBUG("*** Provision Data Sent to DSP\n");
bf3146c8 1469
f7c1be0c 1470 // Send provisioning data
e27d96dd 1471 ptr = list_entry(info->prov_list.next, struct prov_record, list);
f7c1be0c
MB
1472 len = *(u16 *)ptr->pprov_data;
1473 len = htons(len);
1474 len += PSEUDOSZ;
bf3146c8 1475
d1674983 1476 pmsg = (u16 *)ptr->pprov_data;
b13e39b2 1477 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
f7c1be0c
MB
1478 // Insert slow queue sequence number
1479 ppseudo_hdr->seq_num = info->squeseqnum++;
1480 ppseudo_hdr->portsrc = 0;
1481 // Calculate new checksum
1482 ppseudo_hdr->checksum = *pmsg++;
1483 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
1484 for (i=1; i<7; i++) {
1485 ppseudo_hdr->checksum ^= *pmsg++;
1486 //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum);
1487 }
bf3146c8 1488
f7c1be0c
MB
1489 TempShortBuf[0] = 0;
1490 TempShortBuf[1] = htons (len);
1491 memcpy(&TempShortBuf[2], ppseudo_hdr, len);
bf3146c8 1492
e2cb7da1 1493 status = ft1000_write_dpram32 (dev, 0, (u8 *)&TempShortBuf[0], (unsigned short)(len+2));
bf3146c8
GKH
1494 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
1495
f7c1be0c
MB
1496 list_del(&ptr->list);
1497 kfree(ptr->pprov_data);
bf3146c8 1498 kfree(ptr);
f7c1be0c
MB
1499 }
1500 msleep(10);
1501 }
1502
1503 DEBUG("DSP Provisioning List Entry finished\n");
1504
1505 msleep(100);
bf3146c8 1506
f7c1be0c
MB
1507 info->fProvComplete = 1;
1508 info->CardReady = 1;
f7c1be0c 1509 return STATUS_SUCCESS;
bf3146c8 1510
f7c1be0c
MB
1511}
1512
bf3146c8 1513
2a953cfd 1514static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) {
e33196e1 1515 struct ft1000_info *info = netdev_priv(dev->net);
f7c1be0c
MB
1516 u16 msgtype;
1517 u16 tempword;
1b8a3012 1518 struct media_msg *pmediamsg;
369e857e 1519 struct dsp_init_msg *pdspinitmsg;
e09aee2a 1520 struct drv_msg *pdrvmsg;
f7c1be0c 1521 u16 i;
b13e39b2 1522 struct pseudo_hdr *ppseudo_hdr;
d1674983 1523 u16 *pmsg;
bf3146c8 1524 u16 status;
f7c1be0c
MB
1525 union {
1526 u8 byte[2];
1527 u16 wrd;
1528 } convert;
1529
bf3146c8 1530
2a953cfd
AB
1531 char *cmdbuffer = kmalloc(1600, GFP_KERNEL);
1532 if (!cmdbuffer)
1533 return STATUS_FAILURE;
bf3146c8 1534
2a953cfd 1535 status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size);
f7c1be0c 1536
bf3146c8 1537
bf3146c8
GKH
1538
1539#ifdef JDEBUG
f7c1be0c
MB
1540 DEBUG("ft1000_proc_drvmsg:cmdbuffer\n");
1541 for(i = 0; i < size; i+=5)
1542 {
bf3146c8
GKH
1543 if( (i + 5) < size )
1544 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]);
f7c1be0c
MB
1545 else
1546 {
1547 for (j = i; j < size; j++)
bf3146c8
GKH
1548 DEBUG("0x%x ", cmdbuffer[j]);
1549 DEBUG("\n");
f7c1be0c
MB
1550 break;
1551 }
1552 }
bf3146c8 1553#endif
e09aee2a 1554 pdrvmsg = (struct drv_msg *)&cmdbuffer[2];
f7c1be0c
MB
1555 msgtype = ntohs(pdrvmsg->type);
1556 DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype);
1557 switch (msgtype) {
1558 case MEDIA_STATE: {
1559 DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE");
bf3146c8 1560
1b8a3012 1561 pmediamsg = (struct media_msg *)&cmdbuffer[0];
f7c1be0c
MB
1562 if (info->ProgConStat != 0xFF) {
1563 if (pmediamsg->state) {
1564 DEBUG("Media is up\n");
1565 if (info->mediastate == 0) {
1566 if ( info->NetDevRegDone )
1567 {
1568 //netif_carrier_on(dev->net);//mbelian
bf3146c8 1569 netif_wake_queue(dev->net);
f7c1be0c 1570 }
bf3146c8 1571 info->mediastate = 1;
f7c1be0c
MB
1572 /*do_gettimeofday(&tv);
1573 info->ConTm = tv.tv_sec;*/ //mbelian
1574 }
1575 }
1576 else {
1577 DEBUG("Media is down\n");
1578 if (info->mediastate == 1) {
1579 info->mediastate = 0;
1580 if ( info->NetDevRegDone )
1581 {
1582 //netif_carrier_off(dev->net); mbelian
1583 //netif_stop_queue(dev->net);
1584 }
1585 info->ConTm = 0;
1586 }
1587 }
1588 }
1589 else {
1590 DEBUG("Media is down\n");
1591 if (info->mediastate == 1) {
1592 info->mediastate = 0;
bf3146c8 1593 if ( info->NetDevRegDone)
f7c1be0c
MB
1594 {
1595 //netif_carrier_off(dev->net); //mbelian
1596 //netif_stop_queue(dev->net);
1597 }
1598 info->ConTm = 0;
1599 }
1600 }
1601 break;
1602 }
1603 case DSP_INIT_MSG: {
1604 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG");
bf3146c8 1605
369e857e 1606 pdspinitmsg = (struct dsp_init_msg *)&cmdbuffer[2];
f7c1be0c
MB
1607 memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ);
1608 DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", info->DspVer[0], info->DspVer[1], info->DspVer[2], info->DspVer[3]);
1609 memcpy(info->HwSerNum, pdspinitmsg->HwSerNum, HWSERNUMSZ);
1610 memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ);
1611 memcpy(info->eui64, pdspinitmsg->eui64, EUISZ);
1612 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]);
1613 dev->net->dev_addr[0] = info->eui64[0];
1614 dev->net->dev_addr[1] = info->eui64[1];
1615 dev->net->dev_addr[2] = info->eui64[2];
1616 dev->net->dev_addr[3] = info->eui64[5];
1617 dev->net->dev_addr[4] = info->eui64[6];
1618 dev->net->dev_addr[5] = info->eui64[7];
bf3146c8 1619
369e857e 1620 if (ntohs(pdspinitmsg->length) == (sizeof(struct dsp_init_msg) - 20)) {
f7c1be0c
MB
1621 memcpy(info->ProductMode, pdspinitmsg->ProductMode, MODESZ);
1622 memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, CALVERSZ);
1623 memcpy(info->RfCalDate, pdspinitmsg->RfCalDate, CALDATESZ);
1624 DEBUG("RFCalVer = 0x%2x 0x%2x\n", info->RfCalVer[0], info->RfCalVer[1]);
1625 }
1626 break;
1627 }
1628 case DSP_PROVISION: {
1629 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n");
bf3146c8 1630
f7c1be0c
MB
1631 // kick off dspprov routine to start provisioning
1632 // Send provisioning data to DSP
bf3146c8 1633 if (list_empty(&info->prov_list) == 0)
f7c1be0c
MB
1634 {
1635 info->fProvComplete = 0;
1636 status = ft1000_dsp_prov(dev);
1637 if (status != STATUS_SUCCESS)
2a953cfd 1638 goto out;
f7c1be0c
MB
1639 }
1640 else {
1641 info->fProvComplete = 1;
1642 status = ft1000_write_register (dev, FT1000_DB_HB, FT1000_REG_DOORBELL);
1643 DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n");
1644 }
1645 DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n");
1646 break;
1647 }
1648 case DSP_STORE_INFO: {
1649 DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO");
bf3146c8 1650
f7c1be0c
MB
1651 DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n");
1652 tempword = ntohs(pdrvmsg->length);
1653 info->DSPInfoBlklen = tempword;
1654 if (tempword < (MAX_DSP_SESS_REC-4) ) {
d1674983 1655 pmsg = (u16 *)&pdrvmsg->data[0];
f7c1be0c
MB
1656 for (i=0; i<((tempword+1)/2); i++) {
1657 DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg);
1658 info->DSPInfoBlk[i+10] = *pmsg++;
1659 }
1660 }
1661 else {
1662 info->DSPInfoBlklen = 0;
1663 }
1664 break;
1665 }
1666 case DSP_GET_INFO: {
1667 DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n");
1668 // copy dsp info block to dsp
1669 info->DrvMsgPend = 1;
1670 // allow any outstanding ioctl to finish
1671 mdelay(10);
1672 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1673 if (tempword & FT1000_DB_DPRAM_TX) {
1674 mdelay(10);
1675 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1676 if (tempword & FT1000_DB_DPRAM_TX) {
1677 mdelay(10);
1678 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1679 if (tempword & FT1000_DB_DPRAM_TX) {
1680 break;
1681 }
bf3146c8 1682 }
f7c1be0c 1683 }
bf3146c8 1684
f7c1be0c
MB
1685 // Put message into Slow Queue
1686 // Form Pseudo header
d1674983 1687 pmsg = (u16 *)info->DSPInfoBlk;
f7c1be0c 1688 *pmsg++ = 0;
bf3146c8 1689 *pmsg++ = htons(info->DSPInfoBlklen+20+info->DSPInfoBlklen);
d1674983 1690 ppseudo_hdr = (struct pseudo_hdr *)(u16 *)&info->DSPInfoBlk[2];
f7c1be0c 1691 ppseudo_hdr->length = htons(info->DSPInfoBlklen+4+info->DSPInfoBlklen);
bf3146c8 1692 ppseudo_hdr->source = 0x10;
f7c1be0c
MB
1693 ppseudo_hdr->destination = 0x20;
1694 ppseudo_hdr->portdest = 0;
1695 ppseudo_hdr->portsrc = 0;
1696 ppseudo_hdr->sh_str_id = 0;
1697 ppseudo_hdr->control = 0;
1698 ppseudo_hdr->rsvd1 = 0;
1699 ppseudo_hdr->rsvd2 = 0;
1700 ppseudo_hdr->qos_class = 0;
1701 // Insert slow queue sequence number
1702 ppseudo_hdr->seq_num = info->squeseqnum++;
bf3146c8 1703 // Insert application id
f7c1be0c
MB
1704 ppseudo_hdr->portsrc = 0;
1705 // Calculate new checksum
1706 ppseudo_hdr->checksum = *pmsg++;
1707 for (i=1; i<7; i++) {
1708 ppseudo_hdr->checksum ^= *pmsg++;
1709 }
1710 info->DSPInfoBlk[10] = 0x7200;
1711 info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen);
e2cb7da1 1712 status = ft1000_write_dpram32 (dev, 0, (u8 *)&info->DSPInfoBlk[0], (unsigned short)(info->DSPInfoBlklen+22));
bf3146c8 1713 status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL);
f7c1be0c 1714 info->DrvMsgPend = 0;
bf3146c8 1715
f7c1be0c
MB
1716 break;
1717 }
bf3146c8 1718
f7c1be0c
MB
1719 case GET_DRV_ERR_RPT_MSG: {
1720 DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n");
1721 // copy driver error message to dsp
1722 info->DrvMsgPend = 1;
1723 // allow any outstanding ioctl to finish
1724 mdelay(10);
1725 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1726 if (tempword & FT1000_DB_DPRAM_TX) {
1727 mdelay(10);
1728 status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL);
1729 if (tempword & FT1000_DB_DPRAM_TX) {
1730 mdelay(10);
bf3146c8 1731 }
f7c1be0c 1732 }
bf3146c8 1733
f7c1be0c
MB
1734 if ( (tempword & FT1000_DB_DPRAM_TX) == 0) {
1735 // Put message into Slow Queue
1736 // Form Pseudo header
d1674983 1737 pmsg = (u16 *)&tempbuffer[0];
b13e39b2 1738 ppseudo_hdr = (struct pseudo_hdr *)pmsg;
f7c1be0c 1739 ppseudo_hdr->length = htons(0x0012);
bf3146c8 1740 ppseudo_hdr->source = 0x10;
f7c1be0c
MB
1741 ppseudo_hdr->destination = 0x20;
1742 ppseudo_hdr->portdest = 0;
1743 ppseudo_hdr->portsrc = 0;
1744 ppseudo_hdr->sh_str_id = 0;
1745 ppseudo_hdr->control = 0;
1746 ppseudo_hdr->rsvd1 = 0;
1747 ppseudo_hdr->rsvd2 = 0;
1748 ppseudo_hdr->qos_class = 0;
1749 // Insert slow queue sequence number
1750 ppseudo_hdr->seq_num = info->squeseqnum++;
bf3146c8 1751 // Insert application id
f7c1be0c
MB
1752 ppseudo_hdr->portsrc = 0;
1753 // Calculate new checksum
1754 ppseudo_hdr->checksum = *pmsg++;
1755 for (i=1; i<7; i++) {
1756 ppseudo_hdr->checksum ^= *pmsg++;
1757 }
d1674983 1758 pmsg = (u16 *)&tempbuffer[16];
f7c1be0c
MB
1759 *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG);
1760 *pmsg++ = htons(0x000e);
1761 *pmsg++ = htons(info->DSP_TIME[0]);
1762 *pmsg++ = htons(info->DSP_TIME[1]);
1763 *pmsg++ = htons(info->DSP_TIME[2]);
1764 *pmsg++ = htons(info->DSP_TIME[3]);
1765 convert.byte[0] = info->DspVer[0];
1766 convert.byte[1] = info->DspVer[1];
1767 *pmsg++ = convert.wrd;
1768 convert.byte[0] = info->DspVer[2];
1769 convert.byte[1] = info->DspVer[3];
1770 *pmsg++ = convert.wrd;
1771 *pmsg++ = htons(info->DrvErrNum);
1772
a209efad 1773 card_send_command (dev, (unsigned char*)&tempbuffer[0], (u16)(0x0012 + PSEUDOSZ));
f7c1be0c
MB
1774 info->DrvErrNum = 0;
1775 }
1776 info->DrvMsgPend = 0;
bf3146c8
GKH
1777
1778 break;
f7c1be0c 1779 }
bf3146c8 1780
f7c1be0c 1781 default:
bf3146c8 1782 break;
f7c1be0c
MB
1783 }
1784
f7c1be0c 1785
2a953cfd
AB
1786 status = STATUS_SUCCESS;
1787out:
1788 kfree(cmdbuffer);
f7c1be0c 1789 DEBUG("return from ft1000_proc_drvmsg\n");
2a953cfd 1790 return status;
f7c1be0c
MB
1791}
1792
1793
1794
1795int ft1000_poll(void* dev_id) {
bf3146c8 1796
f7c1be0c 1797 struct ft1000_device *dev = (struct ft1000_device *)dev_id;
e33196e1 1798 struct ft1000_info *info = netdev_priv(dev->net);
bf3146c8 1799
f7c1be0c
MB
1800 u16 tempword;
1801 u16 status;
1802 u16 size;
1803 int i;
fc549a05
MB
1804 u16 data;
1805 u16 modulo;
1806 u16 portid;
f7c1be0c 1807 u16 nxtph;
29437ab0 1808 struct dpram_blk *pdpram_blk;
b13e39b2 1809 struct pseudo_hdr *ppseudo_hdr;
f7c1be0c 1810 unsigned long flags;
bf3146c8 1811
f7c1be0c
MB
1812 //DEBUG("Enter ft1000_poll...\n");
1813 if (ft1000_chkcard(dev) == FALSE) {
1814 DEBUG("ft1000_poll::ft1000_chkcard: failed\n");
1815 return STATUS_FAILURE;
1816 }
1817
1818 status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL);
1819 // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword);
1820
bf3146c8
GKH
1821 if ( !status )
1822 {
1823
f7c1be0c
MB
1824 if (tempword & FT1000_DB_DPRAM_RX) {
1825 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n");
bf3146c8 1826
e2cb7da1 1827 status = ft1000_read_dpram16(dev, 0x200, (u8 *)&data, 0);
f7c1be0c
MB
1828 //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data);
1829 size = ntohs(data) + 16 + 2; //wai
1830 if (size % 4) {
1831 modulo = 4 - (size % 4);
1832 size = size + modulo;
bf3146c8 1833 }
e2cb7da1 1834 status = ft1000_read_dpram16(dev, 0x201, (u8 *)&portid, 1);
f7c1be0c
MB
1835 portid &= 0xff;
1836 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid);
bf3146c8 1837
f7c1be0c 1838 if (size < MAX_CMD_SQSIZE) {
bf3146c8 1839 switch (portid)
f7c1be0c
MB
1840 {
1841 case DRIVERID:
1842 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n");
bf3146c8 1843
f7c1be0c
MB
1844 status = ft1000_proc_drvmsg (dev, size);
1845 if (status != STATUS_SUCCESS )
1846 return status;
1847 break;
1848 case DSPBCMSGID:
1849 // This is a dsp broadcast message
bf3146c8 1850 // Check which application has registered for dsp broadcast messages
f7c1be0c 1851 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n");
bf3146c8 1852
f7c1be0c 1853 for (i=0; i<MAX_NUM_APP; i++) {
bf3146c8
GKH
1854 if ( (info->app_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) &&
1855 (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT) )
f7c1be0c
MB
1856 {
1857 //DEBUG("Dsp broadcast message detected for app id %d\n", i);
1858 nxtph = FT1000_DPRAM_RX_BASE + 2;
1859 pdpram_blk = ft1000_get_buffer (&freercvpool);
1860 if (pdpram_blk != NULL) {
1861 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
b13e39b2 1862 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
f7c1be0c
MB
1863 // Put message into the appropriate application block
1864 info->app_info[i].nRxMsg++;
1865 spin_lock_irqsave(&free_buff_lock, flags);
1866 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
1867 info->app_info[i].NumOfMsg++;
1868 spin_unlock_irqrestore(&free_buff_lock, flags);
1869 wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
1870 }
1871 else {
1872 info->app_info[i].nRxMsgMiss++;
1873 // Put memory back to free pool
1874 ft1000_free_buffer(pdpram_blk, &freercvpool);
1875 DEBUG("pdpram_blk::ft1000_get_buffer NULL\n");
1876 }
1877 }
1878 else {
1879 DEBUG("Out of memory in free receive command pool\n");
1880 info->app_info[i].nRxMsgMiss++;
1881 }//endof if (pdpram_blk != NULL)
bf3146c8 1882 }//endof if
f7c1be0c
MB
1883 //else
1884 // DEBUG("app_info mismatch\n");
1885 }// endof for
1886 break;
1887 default:
1888 pdpram_blk = ft1000_get_buffer (&freercvpool);
1889 //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk);
1890 if (pdpram_blk != NULL) {
1891 if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) {
b13e39b2 1892 ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer;
f7c1be0c
MB
1893 // Search for correct application block
1894 for (i=0; i<MAX_NUM_APP; i++) {
1895 if (info->app_info[i].app_id == ppseudo_hdr->portdest) {
1896 break;
1897 }
1898 }
1899
fcbf77bf 1900 if (i == MAX_NUM_APP) {
f7c1be0c
MB
1901 DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr->portdest);
1902 // Put memory back to free pool
1903 ft1000_free_buffer(pdpram_blk, &freercvpool);
1904 }
1905 else {
1906 if (info->app_info[i].NumOfMsg > MAX_MSG_LIMIT) {
1907 // Put memory back to free pool
1908 ft1000_free_buffer(pdpram_blk, &freercvpool);
1909 }
1910 else {
1911 info->app_info[i].nRxMsg++;
1912 // Put message into the appropriate application block
1913 //pxu spin_lock_irqsave(&free_buff_lock, flags);
1914 list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist);
1915 info->app_info[i].NumOfMsg++;
1916 //pxu spin_unlock_irqrestore(&free_buff_lock, flags);
1917 //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg);
1918 }
1919 }
1920 }
1921 else {
1922 // Put memory back to free pool
1923 ft1000_free_buffer(pdpram_blk, &freercvpool);
1924 }
1925 }
1926 else {
1927 DEBUG("Out of memory in free receive command pool\n");
1928 }
1929 break;
1930 } //end of switch
1931 } //endof if (size < MAX_CMD_SQSIZE)
1932 else {
1933 DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size);
1934 }
bf3146c8 1935 status = ft1000_write_register (dev, FT1000_DB_DPRAM_RX, FT1000_REG_DOORBELL);
f7c1be0c
MB
1936 }
1937 else if (tempword & FT1000_DSP_ASIC_RESET) {
1938 //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DSP_ASIC_RESET\n");
1939
1940 // Let's reset the ASIC from the Host side as well
1941 status = ft1000_write_register (dev, ASIC_RESET_BIT, FT1000_REG_RESET);
1942 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
1943 i = 0;
1944 while (tempword & ASIC_RESET_BIT) {
1945 status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET);
1946 msleep(10);
1947 i++;
1948 if (i==100)
1949 break;
1950 }
1951 if (i==100) {
1952 DEBUG("Unable to reset ASIC\n");
1953 return STATUS_SUCCESS;
1954 }
1955 msleep(10);
1956 // Program WMARK register
1957 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
1958 // clear ASIC reset doorbell
1959 status = ft1000_write_register (dev, FT1000_DSP_ASIC_RESET, FT1000_REG_DOORBELL);
1960 msleep(10);
1961 }
1962 else if (tempword & FT1000_ASIC_RESET_REQ) {
1963 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n");
bf3146c8 1964
f7c1be0c
MB
1965 // clear ASIC reset request from DSP
1966 status = ft1000_write_register (dev, FT1000_ASIC_RESET_REQ, FT1000_REG_DOORBELL);
1967 status = ft1000_write_register (dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL);
1968 // copy dsp session record from Adapter block
e2cb7da1 1969 status = ft1000_write_dpram32 (dev, 0, (u8 *)&info->DSPSess.Rec[0], 1024);
f7c1be0c
MB
1970 // Program WMARK register
1971 status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK);
bf3146c8 1972 // ring doorbell to tell DSP that ASIC is out of reset
f7c1be0c 1973 status = ft1000_write_register (dev, FT1000_ASIC_RESET_DSP, FT1000_REG_DOORBELL);
bf3146c8 1974 }
f7c1be0c 1975 else if (tempword & FT1000_DB_COND_RESET) {
bf3146c8 1976 DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n");
f7c1be0c 1977//By Jim
bf3146c8 1978// Reset ASIC and DSP
f7c1be0c
MB
1979//MAG
1980 if (info->fAppMsgPend == 0) {
bf3146c8
GKH
1981 // Reset ASIC and DSP
1982
e2cb7da1
MB
1983 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (u8 *)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX);
1984 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (u8 *)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX);
1985 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (u8 *)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX);
1986 status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (u8 *)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX);
bf3146c8 1987 info->CardReady = 0;
f7c1be0c
MB
1988 info->DrvErrNum = DSP_CONDRESET_INFO;
1989 DEBUG("ft1000_hw:DSP conditional reset requested\n");
1990 info->ft1000_reset(dev->net);
1991 }
1992 else {
1993 info->fProvComplete = 0;
1994 info->fCondResetPend = 1;
1995 }
bf3146c8
GKH
1996
1997 ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL);
f7c1be0c 1998 }
bf3146c8 1999
f7c1be0c
MB
2000 }//endof if ( !status )
2001
2002 //DEBUG("return from ft1000_poll.\n");
2003 return STATUS_SUCCESS;
2004
2005}
2006
2007/*end of Jim*/
This page took 0.199424 seconds and 5 git commands to generate.