Commit | Line | Data |
---|---|---|
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> | |
19 | //#include <asm/semaphore.h> //aelias [-] reason : file moved | |
20 | //#include <linux/semaphore.h> //aelias [+] reason : file moved | |
21 | //#include <asm/io.h> | |
22 | //#include <linux/kthread.h> | |
23 | ||
24 | #define HARLEY_READ_REGISTER 0x0 | |
25 | #define HARLEY_WRITE_REGISTER 0x01 | |
26 | #define HARLEY_READ_DPRAM_32 0x02 | |
27 | #define HARLEY_READ_DPRAM_LOW 0x03 | |
28 | #define HARLEY_READ_DPRAM_HIGH 0x04 | |
29 | #define HARLEY_WRITE_DPRAM_32 0x05 | |
30 | #define HARLEY_WRITE_DPRAM_LOW 0x06 | |
31 | #define HARLEY_WRITE_DPRAM_HIGH 0x07 | |
32 | ||
33 | #define HARLEY_READ_OPERATION 0xc1 | |
34 | #define HARLEY_WRITE_OPERATION 0x41 | |
35 | ||
36 | //#define JDEBUG | |
37 | ||
2a953cfd AB |
38 | static int ft1000_reset(struct net_device *ft1000dev); |
39 | static int ft1000_submit_rx_urb(PFT1000_INFO info); | |
f7c1be0c | 40 | static void ft1000_hbchk(u_long data); |
f7c1be0c MB |
41 | static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev); |
42 | static int ft1000_open (struct net_device *dev); | |
f7c1be0c | 43 | static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev); |
f7c1be0c MB |
44 | static struct timer_list poll_timer[MAX_NUM_CARDS]; |
45 | static int ft1000_chkcard (struct ft1000_device *dev); | |
46 | /* | |
47 | static const struct net_device_ops ft1000net_ops = { | |
48 | .ndo_start_xmit = ft1000_start_xmit, | |
49 | .ndo_get_stats = ft1000_netdev_stats, | |
50 | .ndo_open = ft1000_open, | |
51 | .ndo_stop = ft1000_close, | |
52 | }; | |
53 | */ | |
54 | ||
55 | //Jim | |
56 | ||
57 | static u8 tempbuffer[1600]; | |
2a953cfd | 58 | static int gCardIndex; |
f7c1be0c MB |
59 | |
60 | #define MAX_RCV_LOOP 100 | |
61 | ||
62 | ||
f7c1be0c MB |
63 | static int atoi(const char *s) |
64 | { | |
65 | int k = 0; | |
66 | int cnt; | |
67 | ||
68 | k = 0; | |
69 | cnt = 0; | |
70 | while (*s != '\0' && *s >= '0' && *s <= '9') { | |
71 | k = 10 * k + (*s - '0'); | |
72 | s++; | |
73 | // Let's put a limit on this while loop to avoid deadlock scenario | |
74 | if (cnt > 100) | |
75 | break; | |
76 | cnt++; | |
77 | } | |
78 | return k; | |
79 | } | |
80 | /**************************************************************** | |
81 | * ft1000_control_complete | |
82 | ****************************************************************/ | |
83 | static void ft1000_control_complete(struct urb *urb) | |
84 | { | |
85 | struct ft1000_device *ft1000dev = (struct ft1000_device *)urb->context; | |
86 | ||
87 | //DEBUG("FT1000_CONTROL_COMPLETE ENTERED\n"); | |
88 | if (ft1000dev == NULL ) | |
89 | { | |
90 | DEBUG("NULL ft1000dev, failure\n"); | |
91 | return ; | |
92 | } | |
93 | else if ( ft1000dev->dev == NULL ) | |
94 | { | |
95 | DEBUG("NULL ft1000dev->dev, failure\n"); | |
96 | return ; | |
97 | } | |
98 | //spin_lock(&ft1000dev->device_lock); | |
bf3146c8 | 99 | |
f7c1be0c MB |
100 | if(waitqueue_active(&ft1000dev->control_wait)) |
101 | { | |
102 | wake_up(&ft1000dev->control_wait); | |
103 | } | |
bf3146c8 | 104 | |
f7c1be0c MB |
105 | //DEBUG("FT1000_CONTROL_COMPLETE RETURNED\n"); |
106 | //spin_unlock(&ft1000dev->device_lock); | |
107 | } | |
108 | ||
109 | //--------------------------------------------------------------------------- | |
110 | // Function: ft1000_control | |
111 | // | |
112 | // Parameters: ft1000_device - device structure | |
113 | // pipe - usb control message pipe | |
114 | // request - control request | |
115 | // requesttype - control message request type | |
116 | // value - value to be written or 0 | |
117 | // index - register index | |
118 | // data - data buffer to hold the read/write values | |
119 | // size - data size | |
120 | // timeout - control message time out value | |
bf3146c8 | 121 | // |
f7c1be0c MB |
122 | // Returns: STATUS_SUCCESS - success |
123 | // STATUS_FAILURE - failure | |
124 | // | |
125 | // Description: This function sends a control message via USB interface synchronously | |
126 | // | |
127 | // Notes: | |
128 | // | |
129 | //--------------------------------------------------------------------------- | |
bf3146c8 GKH |
130 | static int ft1000_control(struct ft1000_device *ft1000dev,unsigned int pipe, |
131 | u8 request, | |
f7c1be0c MB |
132 | u8 requesttype, |
133 | u16 value, | |
134 | u16 index, | |
135 | void *data, | |
136 | u16 size, | |
137 | int timeout) | |
138 | { | |
139 | u16 ret; | |
bf3146c8 | 140 | |
f7c1be0c MB |
141 | if (ft1000dev == NULL ) |
142 | { | |
143 | DEBUG("NULL ft1000dev, failure\n"); | |
144 | return STATUS_FAILURE; | |
145 | } | |
146 | else if ( ft1000dev->dev == NULL ) | |
147 | { | |
148 | DEBUG("NULL ft1000dev->dev, failure\n"); | |
149 | return STATUS_FAILURE; | |
150 | } | |
bf3146c8 | 151 | |
f7c1be0c MB |
152 | ret = usb_control_msg(ft1000dev->dev, |
153 | pipe, | |
154 | request, | |
155 | requesttype, | |
156 | value, | |
157 | index, | |
158 | data, | |
159 | size, | |
160 | LARGE_TIMEOUT); | |
bf3146c8 | 161 | |
f7c1be0c MB |
162 | if (ret>0) |
163 | ret = STATUS_SUCCESS; | |
164 | else | |
165 | ret = STATUS_FAILURE; | |
f7c1be0c | 166 | |
bf3146c8 GKH |
167 | |
168 | return ret; | |
169 | ||
170 | ||
f7c1be0c MB |
171 | } |
172 | //--------------------------------------------------------------------------- | |
173 | // Function: ft1000_read_register | |
174 | // | |
175 | // Parameters: ft1000_device - device structure | |
176 | // Data - data buffer to hold the value read | |
177 | // nRegIndex - register index | |
bf3146c8 | 178 | // |
f7c1be0c MB |
179 | // Returns: STATUS_SUCCESS - success |
180 | // STATUS_FAILURE - failure | |
181 | // | |
182 | // Description: This function returns the value in a register | |
183 | // | |
184 | // Notes: | |
185 | // | |
186 | //--------------------------------------------------------------------------- | |
187 | ||
2a953cfd | 188 | u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx) |
f7c1be0c MB |
189 | { |
190 | u16 ret = STATUS_SUCCESS; | |
bf3146c8 | 191 | |
f7c1be0c MB |
192 | //DEBUG("ft1000_read_register: reg index is %d\n", nRegIndx); |
193 | //DEBUG("ft1000_read_register: spin_lock locked\n"); | |
bf3146c8 | 194 | ret = ft1000_control(ft1000dev, |
f7c1be0c MB |
195 | usb_rcvctrlpipe(ft1000dev->dev,0), |
196 | HARLEY_READ_REGISTER, //request --READ_REGISTER | |
197 | HARLEY_READ_OPERATION, //requestType | |
198 | 0, //value | |
199 | nRegIndx, //index | |
200 | Data, //data | |
201 | 2, //data size | |
202 | LARGE_TIMEOUT ); //timeout | |
f7c1be0c | 203 | |
bf3146c8 GKH |
204 | //DEBUG("ft1000_read_register: ret is %d \n", ret); |
205 | ||
206 | //DEBUG("ft1000_read_register: data is %x \n", *Data); | |
f7c1be0c MB |
207 | if ( ret != STATUS_SUCCESS ) |
208 | return STATUS_FAILURE; | |
bf3146c8 | 209 | |
f7c1be0c MB |
210 | return ret; |
211 | ||
bf3146c8 | 212 | } |
f7c1be0c MB |
213 | |
214 | //--------------------------------------------------------------------------- | |
215 | // Function: ft1000_write_register | |
216 | // | |
217 | // Parameters: ft1000_device - device structure | |
218 | // value - value to write into a register | |
219 | // nRegIndex - register index | |
bf3146c8 | 220 | // |
f7c1be0c MB |
221 | // Returns: STATUS_SUCCESS - success |
222 | // STATUS_FAILURE - failure | |
223 | // | |
224 | // Description: This function writes the value in a register | |
225 | // | |
226 | // Notes: | |
227 | // | |
228 | //--------------------------------------------------------------------------- | |
229 | u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRegIndx) | |
230 | { | |
231 | u16 ret = STATUS_SUCCESS; | |
232 | ||
233 | //DEBUG("ft1000_write_register: value is: %d, reg index is: %d\n", value, nRegIndx); | |
bf3146c8 | 234 | |
f7c1be0c MB |
235 | ret = ft1000_control(ft1000dev, |
236 | usb_sndctrlpipe(ft1000dev->dev, 0), | |
237 | HARLEY_WRITE_REGISTER, //request -- WRITE_REGISTER | |
238 | HARLEY_WRITE_OPERATION, //requestType | |
239 | value, | |
240 | nRegIndx, | |
241 | NULL, | |
242 | 0, | |
243 | LARGE_TIMEOUT ); | |
bf3146c8 | 244 | |
f7c1be0c MB |
245 | if ( ret != STATUS_SUCCESS ) |
246 | return STATUS_FAILURE; | |
bf3146c8 | 247 | |
f7c1be0c MB |
248 | return ret; |
249 | } | |
250 | ||
251 | //--------------------------------------------------------------------------- | |
252 | // Function: ft1000_read_dpram32 | |
253 | // | |
254 | // Parameters: ft1000_device - device structure | |
255 | // indx - starting address to read | |
256 | // buffer - data buffer to hold the data read | |
257 | // cnt - number of byte read from DPRAM | |
bf3146c8 | 258 | // |
f7c1be0c MB |
259 | // Returns: STATUS_SUCCESS - success |
260 | // STATUS_FAILURE - failure | |
261 | // | |
262 | // Description: This function read a number of bytes from DPRAM | |
263 | // | |
264 | // Notes: | |
265 | // | |
266 | //--------------------------------------------------------------------------- | |
267 | ||
268 | u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt) | |
269 | { | |
270 | u16 ret = STATUS_SUCCESS; | |
bf3146c8 | 271 | |
f7c1be0c | 272 | //DEBUG("ft1000_read_dpram32: indx: %d cnt: %d\n", indx, cnt); |
bf3146c8 | 273 | ret =ft1000_control(ft1000dev, |
f7c1be0c MB |
274 | usb_rcvctrlpipe(ft1000dev->dev,0), |
275 | HARLEY_READ_DPRAM_32, //request --READ_DPRAM_32 | |
276 | HARLEY_READ_OPERATION, //requestType | |
277 | 0, //value | |
278 | indx, //index | |
279 | buffer, //data | |
280 | cnt, //data size | |
281 | LARGE_TIMEOUT ); //timeout | |
bf3146c8 GKH |
282 | |
283 | //DEBUG("ft1000_read_dpram32: ret is %d \n", ret); | |
284 | ||
285 | //DEBUG("ft1000_read_dpram32: ret=%d \n", ret); | |
f7c1be0c MB |
286 | if ( ret != STATUS_SUCCESS ) |
287 | return STATUS_FAILURE; | |
288 | ||
289 | return ret; | |
290 | ||
bf3146c8 | 291 | } |
f7c1be0c MB |
292 | |
293 | //--------------------------------------------------------------------------- | |
294 | // Function: ft1000_write_dpram32 | |
295 | // | |
296 | // Parameters: ft1000_device - device structure | |
297 | // indx - starting address to write the data | |
298 | // buffer - data buffer to write into DPRAM | |
299 | // cnt - number of bytes to write | |
bf3146c8 | 300 | // |
f7c1be0c MB |
301 | // Returns: STATUS_SUCCESS - success |
302 | // STATUS_FAILURE - failure | |
303 | // | |
304 | // Description: This function writes into DPRAM a number of bytes | |
305 | // | |
306 | // Notes: | |
307 | // | |
308 | //--------------------------------------------------------------------------- | |
309 | u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt) | |
310 | { | |
311 | u16 ret = STATUS_SUCCESS; | |
bf3146c8 | 312 | |
f7c1be0c MB |
313 | //DEBUG("ft1000_write_dpram32: indx: %d buffer: %x cnt: %d\n", indx, buffer, cnt); |
314 | if ( cnt % 4) | |
315 | cnt += cnt - (cnt % 4); | |
bf3146c8 | 316 | |
f7c1be0c MB |
317 | ret = ft1000_control(ft1000dev, |
318 | usb_sndctrlpipe(ft1000dev->dev, 0), | |
319 | HARLEY_WRITE_DPRAM_32, //request -- WRITE_DPRAM_32 | |
320 | HARLEY_WRITE_OPERATION, //requestType | |
321 | 0, //value | |
322 | indx, //index | |
323 | buffer, //buffer | |
324 | cnt, //buffer size | |
325 | LARGE_TIMEOUT ); | |
326 | ||
bf3146c8 | 327 | |
f7c1be0c MB |
328 | if ( ret != STATUS_SUCCESS ) |
329 | return STATUS_FAILURE; | |
bf3146c8 | 330 | |
f7c1be0c MB |
331 | |
332 | return ret; | |
333 | } | |
334 | ||
335 | //--------------------------------------------------------------------------- | |
336 | // Function: ft1000_read_dpram16 | |
337 | // | |
338 | // Parameters: ft1000_device - device structure | |
339 | // indx - starting address to read | |
340 | // buffer - data buffer to hold the data read | |
341 | // hightlow - high or low 16 bit word | |
bf3146c8 | 342 | // |
f7c1be0c MB |
343 | // Returns: STATUS_SUCCESS - success |
344 | // STATUS_FAILURE - failure | |
345 | // | |
346 | // Description: This function read 16 bits from DPRAM | |
347 | // | |
348 | // Notes: | |
349 | // | |
350 | //--------------------------------------------------------------------------- | |
351 | u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow) | |
352 | { | |
353 | u16 ret = STATUS_SUCCESS; | |
bf3146c8 | 354 | |
f7c1be0c MB |
355 | //DEBUG("ft1000_read_dpram16: indx: %d hightlow: %d\n", indx, highlow); |
356 | ||
357 | u8 request; | |
358 | ||
359 | if (highlow == 0 ) | |
360 | request = HARLEY_READ_DPRAM_LOW; | |
361 | else | |
362 | request = HARLEY_READ_DPRAM_HIGH; | |
bf3146c8 GKH |
363 | |
364 | ret = ft1000_control(ft1000dev, | |
f7c1be0c MB |
365 | usb_rcvctrlpipe(ft1000dev->dev,0), |
366 | request, //request --READ_DPRAM_H/L | |
367 | HARLEY_READ_OPERATION, //requestType | |
368 | 0, //value | |
369 | indx, //index | |
370 | buffer, //data | |
371 | 2, //data size | |
372 | LARGE_TIMEOUT ); //timeout | |
bf3146c8 GKH |
373 | |
374 | //DEBUG("ft1000_read_dpram16: ret is %d \n", ret); | |
375 | ||
376 | ||
377 | //DEBUG("ft1000_read_dpram16: data is %x \n", *buffer); | |
f7c1be0c MB |
378 | if ( ret != STATUS_SUCCESS ) |
379 | return STATUS_FAILURE; | |
380 | ||
381 | return ret; | |
382 | ||
bf3146c8 | 383 | } |
f7c1be0c MB |
384 | |
385 | //--------------------------------------------------------------------------- | |
386 | // Function: ft1000_write_dpram16 | |
387 | // | |
388 | // Parameters: ft1000_device - device structure | |
389 | // indx - starting address to write the data | |
390 | // value - 16bits value to write | |
391 | // hightlow - high or low 16 bit word | |
bf3146c8 | 392 | // |
f7c1be0c MB |
393 | // Returns: STATUS_SUCCESS - success |
394 | // STATUS_FAILURE - failure | |
395 | // | |
396 | // Description: This function writes into DPRAM a number of bytes | |
397 | // | |
398 | // Notes: | |
399 | // | |
400 | //--------------------------------------------------------------------------- | |
401 | u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT value, u8 highlow) | |
402 | { | |
403 | u16 ret = STATUS_SUCCESS; | |
bf3146c8 GKH |
404 | |
405 | ||
f7c1be0c MB |
406 | |
407 | //DEBUG("ft1000_write_dpram16: indx: %d value: %d highlow: %d\n", indx, value, highlow); | |
bf3146c8 | 408 | |
f7c1be0c MB |
409 | u8 request; |
410 | ||
bf3146c8 | 411 | |
f7c1be0c MB |
412 | if ( highlow == 0 ) |
413 | request = HARLEY_WRITE_DPRAM_LOW; | |
414 | else | |
415 | request = HARLEY_WRITE_DPRAM_HIGH; | |
416 | ||
417 | ret = ft1000_control(ft1000dev, | |
418 | usb_sndctrlpipe(ft1000dev->dev, 0), | |
419 | request, //request -- WRITE_DPRAM_H/L | |
420 | HARLEY_WRITE_OPERATION, //requestType | |
421 | value, //value | |
422 | indx, //index | |
423 | NULL, //buffer | |
424 | 0, //buffer size | |
425 | LARGE_TIMEOUT ); | |
bf3146c8 GKH |
426 | |
427 | ||
f7c1be0c MB |
428 | if ( ret != STATUS_SUCCESS ) |
429 | return STATUS_FAILURE; | |
430 | ||
bf3146c8 | 431 | |
f7c1be0c MB |
432 | return ret; |
433 | } | |
434 | ||
435 | //--------------------------------------------------------------------------- | |
436 | // Function: fix_ft1000_read_dpram32 | |
437 | // | |
438 | // Parameters: ft1000_device - device structure | |
439 | // indx - starting address to read | |
440 | // buffer - data buffer to hold the data read | |
bf3146c8 GKH |
441 | // |
442 | // | |
f7c1be0c MB |
443 | // Returns: STATUS_SUCCESS - success |
444 | // STATUS_FAILURE - failure | |
445 | // | |
446 | // Description: This function read DPRAM 4 words at a time | |
447 | // | |
448 | // Notes: | |
449 | // | |
450 | //--------------------------------------------------------------------------- | |
451 | u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer) | |
452 | { | |
2a953cfd | 453 | UCHAR buf[16]; |
f7c1be0c MB |
454 | USHORT pos; |
455 | u16 ret = STATUS_SUCCESS; | |
456 | ||
457 | //DEBUG("fix_ft1000_read_dpram32: indx: %d \n", indx); | |
458 | pos = (indx / 4)*4; | |
2a953cfd | 459 | ret = ft1000_read_dpram32(ft1000dev, pos, buf, 16); |
bf3146c8 | 460 | if (ret == STATUS_SUCCESS) |
f7c1be0c MB |
461 | { |
462 | pos = (indx % 4)*4; | |
2a953cfd AB |
463 | *buffer++ = buf[pos++]; |
464 | *buffer++ = buf[pos++]; | |
465 | *buffer++ = buf[pos++]; | |
466 | *buffer++ = buf[pos++]; | |
f7c1be0c | 467 | } |
bf3146c8 | 468 | else |
f7c1be0c MB |
469 | { |
470 | DEBUG("fix_ft1000_read_dpram32: DPRAM32 Read failed\n"); | |
471 | *buffer++ = 0; | |
472 | *buffer++ = 0; | |
473 | *buffer++ = 0; | |
474 | *buffer++ = 0; | |
bf3146c8 | 475 | |
f7c1be0c MB |
476 | } |
477 | ||
bf3146c8 | 478 | //DEBUG("fix_ft1000_read_dpram32: data is %x \n", *buffer); |
f7c1be0c MB |
479 | return ret; |
480 | ||
bf3146c8 | 481 | } |
f7c1be0c MB |
482 | |
483 | ||
484 | //--------------------------------------------------------------------------- | |
485 | // Function: fix_ft1000_write_dpram32 | |
486 | // | |
487 | // Parameters: ft1000_device - device structure | |
488 | // indx - starting address to write | |
489 | // buffer - data buffer to write | |
bf3146c8 GKH |
490 | // |
491 | // | |
f7c1be0c MB |
492 | // Returns: STATUS_SUCCESS - success |
493 | // STATUS_FAILURE - failure | |
494 | // | |
495 | // Description: This function write to DPRAM 4 words at a time | |
496 | // | |
497 | // Notes: | |
498 | // | |
499 | //--------------------------------------------------------------------------- | |
500 | u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer) | |
501 | { | |
502 | USHORT pos1; | |
503 | USHORT pos2; | |
504 | USHORT i; | |
2a953cfd | 505 | UCHAR buf[32]; |
f7c1be0c MB |
506 | UCHAR resultbuffer[32]; |
507 | PUCHAR pdata; | |
508 | u16 ret = STATUS_SUCCESS; | |
509 | ||
510 | //DEBUG("fix_ft1000_write_dpram32: Entered:\n"); | |
bf3146c8 | 511 | |
f7c1be0c MB |
512 | pos1 = (indx / 4)*4; |
513 | pdata = buffer; | |
2a953cfd | 514 | ret = ft1000_read_dpram32(ft1000dev, pos1, buf, 16); |
bf3146c8 | 515 | if (ret == STATUS_SUCCESS) |
f7c1be0c MB |
516 | { |
517 | pos2 = (indx % 4)*4; | |
2a953cfd AB |
518 | buf[pos2++] = *buffer++; |
519 | buf[pos2++] = *buffer++; | |
520 | buf[pos2++] = *buffer++; | |
521 | buf[pos2++] = *buffer++; | |
522 | ret = ft1000_write_dpram32(ft1000dev, pos1, buf, 16); | |
f7c1be0c | 523 | } |
bf3146c8 | 524 | else |
f7c1be0c MB |
525 | { |
526 | DEBUG("fix_ft1000_write_dpram32: DPRAM32 Read failed\n"); | |
bf3146c8 | 527 | |
f7c1be0c MB |
528 | return ret; |
529 | } | |
530 | ||
531 | ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16); | |
bf3146c8 | 532 | if (ret == STATUS_SUCCESS) |
f7c1be0c MB |
533 | { |
534 | buffer = pdata; | |
bf3146c8 | 535 | for (i=0; i<16; i++) |
f7c1be0c | 536 | { |
2a953cfd | 537 | if (buf[i] != resultbuffer[i]){ |
bf3146c8 | 538 | |
f7c1be0c MB |
539 | ret = STATUS_FAILURE; |
540 | } | |
541 | } | |
542 | } | |
543 | ||
bf3146c8 | 544 | if (ret == STATUS_FAILURE) |
f7c1be0c MB |
545 | { |
546 | ret = ft1000_write_dpram32(ft1000dev, pos1, (PUCHAR)&tempbuffer[0], 16); | |
547 | ret = ft1000_read_dpram32(ft1000dev, pos1, (PUCHAR)&resultbuffer[0], 16); | |
bf3146c8 | 548 | if (ret == STATUS_SUCCESS) |
f7c1be0c MB |
549 | { |
550 | buffer = pdata; | |
bf3146c8 | 551 | for (i=0; i<16; i++) |
f7c1be0c | 552 | { |
bf3146c8 | 553 | if (tempbuffer[i] != resultbuffer[i]) |
f7c1be0c MB |
554 | { |
555 | ret = STATUS_FAILURE; | |
556 | DEBUG("fix_ft1000_write_dpram32 Failed to write\n"); | |
557 | } | |
558 | } | |
559 | } | |
560 | } | |
bf3146c8 | 561 | |
f7c1be0c MB |
562 | return ret; |
563 | ||
564 | } | |
565 | ||
566 | ||
567 | //------------------------------------------------------------------------ | |
568 | // | |
569 | // Function: card_reset_dsp | |
570 | // | |
571 | // Synopsis: This function is called to reset or activate the DSP | |
572 | // | |
573 | // Arguments: value - reset or activate | |
574 | // | |
575 | // Returns: None | |
576 | //----------------------------------------------------------------------- | |
2a953cfd | 577 | static void card_reset_dsp (struct ft1000_device *ft1000dev, BOOLEAN value) |
f7c1be0c MB |
578 | { |
579 | u16 status = STATUS_SUCCESS; | |
580 | USHORT tempword; | |
581 | ||
582 | status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL); | |
583 | status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_SUP_CTRL); | |
bf3146c8 | 584 | if (value) |
f7c1be0c MB |
585 | { |
586 | DEBUG("Reset DSP\n"); | |
587 | status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET); | |
588 | tempword |= DSP_RESET_BIT; | |
589 | status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET); | |
590 | } | |
bf3146c8 | 591 | else |
f7c1be0c MB |
592 | { |
593 | DEBUG("Activate DSP\n"); | |
594 | status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET); | |
595 | #if 1 | |
596 | tempword |= DSP_ENCRYPTED; | |
597 | tempword &= ~DSP_UNENCRYPTED; | |
598 | #else | |
599 | tempword |= DSP_UNENCRYPTED; | |
600 | tempword &= ~DSP_ENCRYPTED; | |
601 | #endif | |
602 | status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET); | |
603 | status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET); | |
604 | tempword &= ~EFUSE_MEM_DISABLE; | |
605 | tempword &= ~DSP_RESET_BIT; | |
606 | status = ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET); | |
607 | status = ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET); | |
608 | } | |
609 | } | |
610 | ||
611 | //--------------------------------------------------------------------------- | |
612 | // Function: CardSendCommand | |
613 | // | |
614 | // Parameters: ft1000_device - device structure | |
615 | // ptempbuffer - command buffer | |
616 | // size - command buffer size | |
bf3146c8 | 617 | // |
f7c1be0c MB |
618 | // Returns: STATUS_SUCCESS - success |
619 | // STATUS_FAILURE - failure | |
620 | // | |
621 | // Description: This function sends a command to ASIC | |
622 | // | |
623 | // Notes: | |
624 | // | |
625 | //--------------------------------------------------------------------------- | |
2a953cfd | 626 | void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size) |
f7c1be0c | 627 | { |
bf3146c8 | 628 | unsigned short temp; |
f7c1be0c | 629 | unsigned char *commandbuf; |
bf3146c8 | 630 | |
f7c1be0c | 631 | DEBUG("CardSendCommand: enter CardSendCommand... size=%d\n", size); |
bf3146c8 | 632 | |
f7c1be0c MB |
633 | commandbuf =(unsigned char*) kmalloc(size+2, GFP_KERNEL); |
634 | //memset((void*)commandbuf, 0, size+2); | |
635 | memcpy((void*)commandbuf+2, (void*)ptempbuffer, size); | |
bf3146c8 | 636 | |
f7c1be0c MB |
637 | //DEBUG("CardSendCommand: Command Send\n"); |
638 | /*** | |
bf3146c8 | 639 | for (i=0; i<size+2; i++) |
f7c1be0c MB |
640 | { |
641 | DEBUG("FT1000:ft1000_ChIoctl: data %d = 0x%x\n", i, *ptr++); | |
bf3146c8 GKH |
642 | } |
643 | ***/ | |
644 | ||
f7c1be0c | 645 | ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL); |
bf3146c8 GKH |
646 | |
647 | if (temp & 0x0100) | |
f7c1be0c MB |
648 | { |
649 | msleep(10); | |
650 | } | |
bf3146c8 | 651 | |
f7c1be0c MB |
652 | // check for odd word |
653 | size = size + 2; | |
bf3146c8 | 654 | if (size % 4) |
f7c1be0c MB |
655 | { |
656 | // Must force to be 32 bit aligned | |
657 | size += 4 - (size % 4); | |
658 | } | |
659 | ||
bf3146c8 | 660 | |
f7c1be0c MB |
661 | //DEBUG("CardSendCommand: write dpram ... size=%d\n", size); |
662 | ft1000_write_dpram32(ft1000dev, 0,commandbuf, size); | |
663 | msleep(1); | |
664 | //DEBUG("CardSendCommand: write into doorbell ...\n"); | |
665 | ft1000_write_register(ft1000dev, FT1000_DB_DPRAM_TX ,FT1000_REG_DOORBELL) ; | |
666 | msleep(1); | |
bf3146c8 | 667 | |
f7c1be0c MB |
668 | ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL); |
669 | //DEBUG("CardSendCommand: read doorbell ...temp=%x\n", temp); | |
bf3146c8 | 670 | if ( (temp & 0x0100) == 0) |
f7c1be0c MB |
671 | { |
672 | //DEBUG("CardSendCommand: Message sent\n"); | |
673 | } | |
674 | ||
675 | } | |
676 | ||
677 | ||
678 | //-------------------------------------------------------------------------- | |
679 | // | |
680 | // Function: dsp_reload | |
681 | // | |
682 | // Synopsis: This function is called to load or reload the DSP | |
683 | // | |
684 | // Arguments: ft1000dev - device structure | |
685 | // | |
686 | // Returns: None | |
687 | //----------------------------------------------------------------------- | |
688 | void dsp_reload (struct ft1000_device *ft1000dev) | |
689 | { | |
690 | u16 status; | |
691 | USHORT tempword; | |
692 | ULONG templong; | |
bf3146c8 | 693 | |
f7c1be0c | 694 | PFT1000_INFO pft1000info; |
bf3146c8 | 695 | |
f7c1be0c MB |
696 | pft1000info = netdev_priv(ft1000dev->net); |
697 | ||
698 | pft1000info->CardReady = 0; | |
bf3146c8 | 699 | pft1000info->DSP_loading= 1; |
f7c1be0c MB |
700 | |
701 | // Program Interrupt Mask register | |
702 | status = ft1000_write_register (ft1000dev, 0xffff, FT1000_REG_SUP_IMASK); | |
703 | ||
704 | status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET); | |
705 | tempword |= ASIC_RESET_BIT; | |
706 | status = ft1000_write_register (ft1000dev, tempword, FT1000_REG_RESET); | |
707 | msleep(1000); | |
708 | status = ft1000_read_register (ft1000dev, &tempword, FT1000_REG_RESET); | |
709 | DEBUG("Reset Register = 0x%x\n", tempword); | |
710 | ||
711 | // Toggle DSP reset | |
712 | card_reset_dsp (ft1000dev, 1); | |
713 | msleep(1000); | |
714 | card_reset_dsp (ft1000dev, 0); | |
715 | msleep(1000); | |
716 | ||
717 | status = ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL); | |
718 | ||
719 | // Let's check for FEFE | |
720 | status = ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (PUCHAR)&templong, 4); | |
721 | DEBUG("templong (fefe) = 0x%8x\n", templong); | |
722 | ||
723 | // call codeloader | |
724 | status = scram_dnldr(ft1000dev, pFileStart, FileLength); | |
bf3146c8 | 725 | |
f7c1be0c MB |
726 | if ( status != STATUS_SUCCESS) |
727 | return; | |
728 | ||
729 | msleep(1000); | |
730 | pft1000info->DSP_loading= 0; | |
731 | ||
732 | DEBUG("dsp_reload returned\n"); | |
bf3146c8 | 733 | |
f7c1be0c MB |
734 | |
735 | } | |
736 | ||
737 | //--------------------------------------------------------------------------- | |
738 | // | |
739 | // Function: ft1000_reset_asic | |
740 | // Descripton: This function will call the Card Service function to reset the | |
741 | // ASIC. | |
742 | // Input: | |
743 | // dev - device structure | |
744 | // Output: | |
745 | // none | |
746 | // | |
747 | //--------------------------------------------------------------------------- | |
bf3146c8 | 748 | static void ft1000_reset_asic (struct net_device *dev) |
f7c1be0c MB |
749 | { |
750 | FT1000_INFO *info = netdev_priv(dev); | |
751 | struct ft1000_device *ft1000dev = info->pFt1000Dev; | |
752 | u16 tempword; | |
bf3146c8 | 753 | |
f7c1be0c | 754 | DEBUG("ft1000_hw:ft1000_reset_asic called\n"); |
bf3146c8 | 755 | |
f7c1be0c MB |
756 | info->ASICResetNum++; |
757 | ||
758 | // Let's use the register provided by the Magnemite ASIC to reset the | |
759 | // ASIC and DSP. | |
760 | ft1000_write_register(ft1000dev, (DSP_RESET_BIT | ASIC_RESET_BIT), FT1000_REG_RESET ); | |
bf3146c8 | 761 | |
f7c1be0c MB |
762 | mdelay(1); |
763 | ||
764 | // set watermark to -1 in order to not generate an interrrupt | |
765 | ft1000_write_register(ft1000dev, 0xffff, FT1000_REG_MAG_WATERMARK); | |
bf3146c8 | 766 | |
f7c1be0c MB |
767 | // clear interrupts |
768 | ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR); | |
769 | DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword); | |
770 | ft1000_write_register (ft1000dev, tempword, FT1000_REG_SUP_ISR); | |
771 | ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_ISR); | |
772 | DEBUG("ft1000_hw: interrupt status register = 0x%x\n",tempword); | |
bf3146c8 | 773 | |
f7c1be0c MB |
774 | } |
775 | /* | |
776 | //--------------------------------------------------------------------------- | |
777 | // | |
778 | // Function: ft1000_disable_interrupts | |
779 | // Descripton: This function will disable all interrupts. | |
780 | // Input: | |
781 | // dev - device structure | |
782 | // Output: | |
783 | // None. | |
784 | // | |
785 | //--------------------------------------------------------------------------- | |
786 | static void ft1000_disable_interrupts(struct net_device *dev) { | |
787 | FT1000_INFO *info = netdev_priv(dev); | |
788 | struct ft1000_device *ft1000dev = info->pFt1000Dev; | |
789 | u16 tempword; | |
790 | ||
791 | DEBUG("ft1000_hw: ft1000_disable_interrupts()\n"); | |
792 | ft1000_write_register (ft1000dev, ISR_MASK_ALL, FT1000_REG_SUP_IMASK); | |
793 | ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_IMASK); | |
794 | DEBUG("ft1000_hw:ft1000_disable_interrupts:current interrupt enable mask = 0x%x\n", tempword); | |
795 | info->InterruptsEnabled = FALSE; | |
796 | } | |
797 | ||
798 | //--------------------------------------------------------------------------- | |
799 | // | |
800 | // Function: ft1000_enable_interrupts | |
801 | // Descripton: This function will enable interrupts base on the current interrupt mask. | |
802 | // Input: | |
803 | // dev - device structure | |
804 | // Output: | |
805 | // None. | |
806 | // | |
807 | //--------------------------------------------------------------------------- | |
808 | static void ft1000_enable_interrupts(struct net_device *dev) { | |
809 | FT1000_INFO *info = netdev_priv(dev); | |
810 | struct ft1000_device *ft1000dev = info->pFt1000Dev; | |
811 | u16 tempword; | |
812 | ||
813 | DEBUG("ft1000_hw:ft1000_enable_interrupts()\n"); | |
814 | ft1000_write_register (ft1000dev, info->CurrentInterruptEnableMask, FT1000_REG_SUP_IMASK); | |
815 | ft1000_read_register (ft1000dev, &tempword, FT1000_REG_SUP_IMASK); | |
816 | DEBUG("ft1000_hw:ft1000_enable_interrupts:current interrupt enable mask = 0x%x\n", tempword); | |
817 | info->InterruptsEnabled = TRUE; | |
818 | } | |
819 | */ | |
820 | ||
821 | //--------------------------------------------------------------------------- | |
822 | // | |
823 | // Function: ft1000_reset_card | |
824 | // Descripton: This function will reset the card | |
825 | // Input: | |
826 | // dev - device structure | |
827 | // Output: | |
828 | // status - FALSE (card reset fail) | |
bf3146c8 | 829 | // TRUE (card reset successful) |
f7c1be0c MB |
830 | // |
831 | //--------------------------------------------------------------------------- | |
bf3146c8 | 832 | static int ft1000_reset_card (struct net_device *dev) |
f7c1be0c MB |
833 | { |
834 | FT1000_INFO *info = netdev_priv(dev); | |
835 | struct ft1000_device *ft1000dev = info->pFt1000Dev; | |
836 | u16 tempword; | |
837 | PPROV_RECORD ptr; | |
838 | ||
839 | DEBUG("ft1000_hw:ft1000_reset_card called.....\n"); | |
bf3146c8 | 840 | |
f7c1be0c MB |
841 | info->fCondResetPend = 1; |
842 | info->CardReady = 0; | |
843 | info->fProvComplete = 0; | |
844 | //ft1000_disable_interrupts(dev); | |
845 | ||
846 | // Cancel heartbeat task since we are reloading the dsp | |
847 | //del_timer(&poll_timer[info->CardNumber]); | |
848 | ||
849 | // Make sure we free any memory reserve for provisioning | |
850 | while (list_empty(&info->prov_list) == 0) { | |
851 | DEBUG("ft1000_hw:ft1000_reset_card:deleting provisioning record\n"); | |
852 | ptr = list_entry(info->prov_list.next, PROV_RECORD, list); | |
853 | list_del(&ptr->list); | |
854 | kfree(ptr->pprov_data); | |
855 | kfree(ptr); | |
856 | } | |
bf3146c8 | 857 | |
f7c1be0c MB |
858 | DEBUG("ft1000_hw:ft1000_reset_card: reset asic\n"); |
859 | //reset ASIC | |
860 | ft1000_reset_asic(dev); | |
861 | ||
862 | info->DSPResetNum++; | |
bf3146c8 | 863 | |
f7c1be0c MB |
864 | #if 0 |
865 | DEBUG("ft1000_hw:ft1000_reset_card:resetting ASIC and DSP\n"); | |
866 | ft1000_write_register (ft1000dev, (DSP_RESET_BIT | ASIC_RESET_BIT), FT1000_REG_RESET ); | |
867 | ||
868 | ||
bf3146c8 | 869 | // Copy DSP session record into info block if this is not a coldstart |
f7c1be0c MB |
870 | //if (ft1000_card_present == 1) { |
871 | spin_lock_irqsave(&info->dpram_lock, flags); | |
bf3146c8 | 872 | |
f7c1be0c MB |
873 | ft1000_write_register(ft1000dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR); |
874 | for (i=0;i<MAX_DSP_SESS_REC/2; i++) { | |
875 | //info->DSPSess.MagRec[i] = inl(dev->base_addr+FT1000_REG_MAG_DPDATA); | |
876 | ft1000_read_dpram32(ft1000dev, FT1000_REG_MAG_DPDATA, (PCHAR)&(info->DSPSess.MagRec[i]), 4); | |
877 | } | |
bf3146c8 | 878 | |
f7c1be0c MB |
879 | spin_unlock_irqrestore(&info->dpram_lock, flags); |
880 | //} | |
881 | info->squeseqnum = 0; | |
bf3146c8 | 882 | |
f7c1be0c MB |
883 | DEBUG("ft1000_hw:ft1000_reset_card:resetting ASIC\n"); |
884 | mdelay(10); | |
885 | //reset ASIC | |
886 | ft1000_reset_asic(dev); | |
887 | ||
888 | info->DSPResetNum++; | |
889 | ||
890 | DEBUG("ft1000_hw:ft1000_reset_card:downloading dsp image\n"); | |
bf3146c8 GKH |
891 | |
892 | ||
f7c1be0c MB |
893 | // Put dsp in reset and take ASIC out of reset |
894 | DEBUG("ft1000_hw:ft1000_reset_card:Put DSP in reset and take ASIC out of reset\n"); | |
895 | ft1000_write_register (ft1000dev, DSP_RESET_BIT, FT1000_REG_RESET); | |
bf3146c8 | 896 | |
f7c1be0c | 897 | // Setting MAGNEMITE ASIC to big endian mode |
bf3146c8 | 898 | ft1000_write_register (ft1000dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL); |
f7c1be0c MB |
899 | |
900 | // Take DSP out of reset | |
bf3146c8 | 901 | |
f7c1be0c MB |
902 | ft1000_read_register(ft1000dev, &tempword, FT1000_REG_RESET); |
903 | tempword |= DSP_ENCRYPTED; | |
904 | tempword &= ~DSP_UNENCRYPTED; | |
905 | ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET); | |
906 | tempword &= ~EFUSE_MEM_DISABLE; | |
907 | ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET); | |
908 | tempword &= ~DSP_RESET_BIT; | |
909 | ft1000_write_register(ft1000dev, tempword, FT1000_REG_RESET); | |
bf3146c8 GKH |
910 | |
911 | ||
f7c1be0c MB |
912 | // FLARION_DSP_ACTIVE; |
913 | mdelay(10); | |
bf3146c8 | 914 | DEBUG("ft1000_hw:ft1000_reset_card:Take DSP out of reset\n"); |
f7c1be0c MB |
915 | |
916 | // Wait for 0xfefe indicating dsp ready before starting download | |
917 | for (i=0; i<50; i++) { | |
918 | //tempword = ft1000_read_dpram_mag_16(dev, FT1000_MAG_DPRAM_FEFE, FT1000_MAG_DPRAM_FEFE_INDX); | |
919 | ft1000_read_dpram32 (ft1000dev, FT1000_MAG_DPRAM_FEFE_INDX, (PUCHAR)&templong, 4); | |
920 | if (tempword == 0xfefe) { | |
921 | break; | |
922 | } | |
923 | mdelay(20); | |
924 | } | |
925 | ||
926 | if (i==50) { | |
bf3146c8 | 927 | DEBUG("ft1000_hw:ft1000_reset_card:No FEFE detected from DSP\n"); |
f7c1be0c MB |
928 | return FALSE; |
929 | } | |
930 | ||
bf3146c8 | 931 | |
f7c1be0c MB |
932 | #endif |
933 | ||
934 | DEBUG("ft1000_hw:ft1000_reset_card: call dsp_reload\n"); | |
935 | dsp_reload(ft1000dev); | |
bf3146c8 | 936 | |
f7c1be0c | 937 | DEBUG("dsp reload successful\n"); |
bf3146c8 | 938 | |
f7c1be0c MB |
939 | |
940 | mdelay(10); | |
bf3146c8 | 941 | |
f7c1be0c MB |
942 | // Initialize DSP heartbeat area to ho |
943 | ft1000_write_dpram16(ft1000dev, FT1000_MAG_HI_HO, ho_mag, FT1000_MAG_HI_HO_INDX); | |
944 | ft1000_read_dpram16(ft1000dev, FT1000_MAG_HI_HO, (PCHAR)&tempword, FT1000_MAG_HI_HO_INDX); | |
945 | DEBUG("ft1000_hw:ft1000_reset_card:hi_ho value = 0x%x\n", tempword); | |
f7c1be0c | 946 | |
bf3146c8 GKH |
947 | |
948 | ||
f7c1be0c MB |
949 | info->CardReady = 1; |
950 | //ft1000_enable_interrupts(dev); | |
951 | /* Schedule heartbeat process to run every 2 seconds */ | |
952 | //poll_timer[info->CardNumber].expires = jiffies + (2*HZ); | |
953 | //poll_timer[info->CardNumber].data = (u_long)dev; | |
954 | //add_timer(&poll_timer[info->CardNumber]); | |
bf3146c8 | 955 | |
f7c1be0c MB |
956 | info->fCondResetPend = 0; |
957 | return TRUE; | |
958 | ||
959 | } | |
960 | ||
961 | ||
962 | //mbelian | |
963 | #ifdef HAVE_NET_DEVICE_OPS | |
964 | static const struct net_device_ops ftnet_ops = | |
965 | { | |
966 | .ndo_open = &ft1000_open, | |
967 | .ndo_stop = &ft1000_close, | |
968 | .ndo_start_xmit = &ft1000_start_xmit, | |
969 | .ndo_get_stats = &ft1000_netdev_stats, | |
970 | }; | |
971 | #endif | |
972 | ||
973 | ||
974 | //--------------------------------------------------------------------------- | |
975 | // Function: init_ft1000_netdev | |
976 | // | |
977 | // Parameters: ft1000dev - device structure | |
978 | // | |
bf3146c8 | 979 | // |
f7c1be0c MB |
980 | // Returns: STATUS_SUCCESS - success |
981 | // STATUS_FAILURE - failure | |
982 | // | |
983 | // Description: This function initialize the network device | |
984 | // | |
985 | // Notes: | |
986 | // | |
987 | //--------------------------------------------------------------------------- | |
988 | u16 init_ft1000_netdev(struct ft1000_device *ft1000dev) | |
989 | { | |
990 | struct net_device *netdev; | |
991 | FT1000_INFO *pInfo = NULL; | |
992 | PDPRAM_BLK pdpram_blk; | |
993 | int i; | |
b7378b9e | 994 | struct list_head *cur, *tmp; |
f7c1be0c MB |
995 | |
996 | gCardIndex=0; //mbelian | |
997 | ||
998 | DEBUG("Enter init_ft1000_netdev...\n"); | |
bf3146c8 | 999 | |
f7c1be0c MB |
1000 | |
1001 | netdev = alloc_etherdev( sizeof(FT1000_INFO)); | |
1002 | if (!netdev ) | |
1003 | { | |
1004 | DEBUG("init_ft1000_netdev: can not allocate network device\n"); | |
1005 | return STATUS_FAILURE; | |
1006 | } | |
1007 | ||
1008 | //pInfo = (PFT1000_INFO)netdev->priv; | |
1009 | pInfo = (FT1000_INFO *) netdev_priv (netdev); | |
bf3146c8 | 1010 | |
f7c1be0c MB |
1011 | //DEBUG("init_ft1000_netdev: gFt1000Info=%x, netdev=%x, ft1000dev=%x\n", gFt1000Info, netdev, ft1000dev); |
1012 | ||
1013 | memset (pInfo, 0, sizeof(FT1000_INFO)); | |
1014 | ||
1015 | dev_alloc_name(netdev, netdev->name); | |
1016 | ||
bf3146c8 | 1017 | //for the first inserted card, decide the card index beginning number, in case there are existing network interfaces |
f7c1be0c MB |
1018 | if ( gCardIndex == 0 ) |
1019 | { | |
1020 | DEBUG("init_ft1000_netdev: network device name is %s\n", netdev->name); | |
bf3146c8 | 1021 | |
f7c1be0c MB |
1022 | if ( strncmp(netdev->name,"eth", 3) == 0) { |
1023 | //pInfo->CardNumber = atoi(&netdev->name[3]); | |
1024 | gCardIndex = atoi(&netdev->name[3]); | |
1025 | pInfo->CardNumber = gCardIndex; | |
1026 | DEBUG("card number = %d\n", pInfo->CardNumber); | |
1027 | } | |
1028 | else { | |
bf3146c8 | 1029 | printk(KERN_ERR "ft1000: Invalid device name\n"); |
b7378b9e | 1030 | free_netdev(netdev); |
f7c1be0c MB |
1031 | return STATUS_FAILURE; |
1032 | } | |
1033 | } | |
1034 | else | |
1035 | { | |
1036 | //not the first inserted card, increase card number by 1 | |
1037 | /*gCardIndex ++;*/ | |
1038 | pInfo->CardNumber = gCardIndex; | |
1039 | /*DEBUG("card number = %d\n", pInfo->CardNumber);*/ //mbelian | |
1040 | } | |
1041 | ||
1042 | memset(&pInfo->stats, 0, sizeof(struct net_device_stats) ); | |
1043 | ||
1044 | spin_lock_init(&pInfo->dpram_lock); | |
1045 | pInfo->pFt1000Dev = ft1000dev; | |
1046 | pInfo->DrvErrNum = 0; | |
1047 | pInfo->ASICResetNum = 0; | |
1048 | pInfo->registered = 1; | |
1049 | pInfo->ft1000_reset = ft1000_reset; | |
1050 | pInfo->mediastate = 0; | |
1051 | pInfo->fifo_cnt = 0; | |
1052 | pInfo->DeviceCreated = FALSE; | |
1053 | pInfo->DeviceMajor = 0; | |
1054 | pInfo->CurrentInterruptEnableMask = ISR_DEFAULT_MASK; | |
1055 | pInfo->InterruptsEnabled = FALSE; | |
1056 | pInfo->CardReady = 0; | |
1057 | pInfo->DSP_loading = 0; | |
1058 | pInfo->DSP_TIME[0] = 0; | |
1059 | pInfo->DSP_TIME[1] = 0; | |
1060 | pInfo->DSP_TIME[2] = 0; | |
1061 | pInfo->DSP_TIME[3] = 0; | |
1062 | pInfo->fAppMsgPend = 0; | |
1063 | pInfo->fCondResetPend = 0; | |
1064 | pInfo->usbboot = 0; | |
1065 | pInfo->dspalive = 0; | |
1066 | for (i=0;i<32 ;i++ ) | |
1067 | { | |
1068 | pInfo->tempbuf[i] = 0; | |
1069 | } | |
1070 | ||
1071 | INIT_LIST_HEAD(&pInfo->prov_list); | |
1072 | ||
1073 | //mbelian | |
1074 | #ifdef HAVE_NET_DEVICE_OPS | |
bf3146c8 | 1075 | netdev->netdev_ops = &ftnet_ops; |
f7c1be0c | 1076 | #else |
bf3146c8 | 1077 | netdev->hard_start_xmit = &ft1000_start_xmit; |
f7c1be0c MB |
1078 | netdev->get_stats = &ft1000_netdev_stats; |
1079 | netdev->open = &ft1000_open; | |
1080 | netdev->stop = &ft1000_close; | |
1081 | #endif | |
1082 | ||
1083 | //netif_stop_queue(netdev); //mbelian | |
1084 | ||
bf3146c8 | 1085 | |
f7c1be0c MB |
1086 | ft1000dev->net = netdev; |
1087 | ||
1088 | ||
1089 | ||
bf3146c8 | 1090 | //init free_buff_lock, freercvpool, numofmsgbuf, pdpram_blk |
f7c1be0c MB |
1091 | //only init once per card |
1092 | //Jim | |
1093 | DEBUG("Initialize free_buff_lock and freercvpool\n"); | |
1094 | spin_lock_init(&free_buff_lock); | |
1095 | ||
1096 | // initialize a list of buffers to be use for queuing up receive command data | |
1097 | INIT_LIST_HEAD (&freercvpool); | |
1098 | ||
1099 | // create list of free buffers | |
1100 | for (i=0; i<NUM_OF_FREE_BUFFERS; i++) { | |
1101 | // Get memory for DPRAM_DATA link list | |
1102 | pdpram_blk = kmalloc ( sizeof(DPRAM_BLK), GFP_KERNEL ); | |
b7378b9e VK |
1103 | if (pdpram_blk == NULL) |
1104 | goto err_free; | |
f7c1be0c | 1105 | // Get a block of memory to store command data |
bf3146c8 | 1106 | pdpram_blk->pbuffer = kmalloc ( MAX_CMD_SQSIZE, GFP_KERNEL ); |
b7378b9e VK |
1107 | if (pdpram_blk->pbuffer == NULL) { |
1108 | kfree(pdpram_blk); | |
1109 | goto err_free; | |
1110 | } | |
bf3146c8 | 1111 | // link provisioning data |
f7c1be0c MB |
1112 | list_add_tail (&pdpram_blk->list, &freercvpool); |
1113 | } | |
1114 | numofmsgbuf = NUM_OF_FREE_BUFFERS; | |
1115 | ||
bf3146c8 | 1116 | |
f7c1be0c | 1117 | return STATUS_SUCCESS; |
bf3146c8 | 1118 | |
b7378b9e VK |
1119 | |
1120 | err_free: | |
1121 | list_for_each_safe(cur, tmp, &pdpram_blk->list) { | |
1122 | pdpram_blk = list_entry(cur, DPRAM_BLK, list); | |
1123 | list_del(&pdpram_blk->list); | |
1124 | kfree(pdpram_blk->pbuffer); | |
1125 | kfree(pdpram_blk); | |
1126 | } | |
1127 | return STATUS_FAILURE; | |
f7c1be0c MB |
1128 | } |
1129 | ||
1130 | ||
1131 | ||
1132 | //--------------------------------------------------------------------------- | |
1133 | // Function: reg_ft1000_netdev | |
1134 | // | |
1135 | // Parameters: ft1000dev - device structure | |
1136 | // | |
bf3146c8 | 1137 | // |
f7c1be0c MB |
1138 | // Returns: STATUS_SUCCESS - success |
1139 | // STATUS_FAILURE - failure | |
1140 | // | |
1141 | // Description: This function register the network driver | |
1142 | // | |
1143 | // Notes: | |
1144 | // | |
1145 | //--------------------------------------------------------------------------- | |
1146 | u16 reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf) | |
1147 | { | |
1148 | struct net_device *netdev; | |
1149 | FT1000_INFO *pInfo; | |
1150 | int i, rc; | |
1151 | ||
1152 | netdev = ft1000dev->net; | |
1153 | pInfo = netdev_priv(ft1000dev->net); | |
1154 | DEBUG("Enter reg_ft1000_netdev...\n"); | |
1155 | ||
1156 | ||
1157 | ft1000_read_register(ft1000dev, &pInfo->AsicID, FT1000_REG_ASIC_ID); | |
1158 | ||
1159 | usb_set_intfdata(intf, pInfo); | |
1160 | SET_NETDEV_DEV(netdev, &intf->dev); | |
bf3146c8 | 1161 | |
f7c1be0c MB |
1162 | rc = register_netdev(netdev); |
1163 | if (rc) | |
1164 | { | |
1165 | DEBUG("reg_ft1000_netdev: could not register network device\n"); | |
1166 | free_netdev(netdev); | |
1167 | return STATUS_FAILURE; | |
1168 | } | |
1169 | ||
1170 | ||
1171 | //Create character device, implemented by Jim | |
1172 | ft1000_CreateDevice(ft1000dev); | |
1173 | ||
1174 | //INIT_LIST_HEAD(&pInfo->prov_list); | |
1175 | ||
1176 | for (i=0; i<MAX_NUM_CARDS; i++) { | |
1177 | poll_timer[i].function = ft1000_hbchk; | |
1178 | } | |
1179 | ||
1180 | ||
1181 | //hard code MAC address for now | |
1182 | /** | |
1183 | netdev->dev_addr[0] = 0; | |
1184 | netdev->dev_addr[1] = 7; | |
1185 | netdev->dev_addr[2] = 0x35; | |
1186 | netdev->dev_addr[3] = 0x84; | |
1187 | netdev->dev_addr[4] = 0; | |
1188 | netdev->dev_addr[5] = 0x20 + pInfo->CardNumber; | |
1189 | **/ | |
bf3146c8 | 1190 | |
f7c1be0c MB |
1191 | DEBUG ("reg_ft1000_netdev returned\n"); |
1192 | ||
1193 | pInfo->CardReady = 1; | |
1194 | ||
1195 | ||
bf3146c8 | 1196 | return STATUS_SUCCESS; |
f7c1be0c MB |
1197 | } |
1198 | ||
2a953cfd | 1199 | static int ft1000_reset(struct net_device *dev) |
f7c1be0c MB |
1200 | { |
1201 | ft1000_reset_card(dev); | |
1202 | return 0; | |
1203 | } | |
1204 | ||
1205 | //--------------------------------------------------------------------------- | |
1206 | // Function: ft1000_usb_transmit_complete | |
1207 | // | |
1208 | // Parameters: urb - transmitted usb urb | |
1209 | // | |
bf3146c8 | 1210 | // |
f7c1be0c MB |
1211 | // Returns: none |
1212 | // | |
1213 | // Description: This is the callback function when a urb is transmitted | |
1214 | // | |
1215 | // Notes: | |
1216 | // | |
1217 | //--------------------------------------------------------------------------- | |
1218 | static void ft1000_usb_transmit_complete(struct urb *urb) | |
1219 | { | |
1220 | ||
1221 | struct ft1000_device *ft1000dev = urb->context; | |
1222 | ||
1223 | //DEBUG("ft1000_usb_transmit_complete entered\n"); | |
1224 | // Jim spin_lock(&ft1000dev->device_lock); | |
1225 | ||
1226 | if (urb->status) | |
1227 | printk("%s: TX status %d\n", ft1000dev->net->name, urb->status); | |
1228 | ||
1229 | netif_wake_queue(ft1000dev->net); | |
1230 | ||
1231 | //Jim spin_unlock(&ft1000dev->device_lock); | |
1232 | //DEBUG("Return from ft1000_usb_transmit_complete\n"); | |
1233 | } | |
1234 | ||
1235 | ||
1236 | /**************************************************************** | |
1237 | * ft1000_control | |
1238 | ****************************************************************/ | |
bf3146c8 GKH |
1239 | static int ft1000_read_fifo_reg(struct ft1000_device *ft1000dev,unsigned int pipe, |
1240 | u8 request, | |
f7c1be0c MB |
1241 | u8 requesttype, |
1242 | u16 value, | |
1243 | u16 index, | |
1244 | void *data, | |
1245 | u16 size, | |
1246 | int timeout) | |
1247 | { | |
1248 | u16 ret; | |
bf3146c8 | 1249 | |
f7c1be0c MB |
1250 | DECLARE_WAITQUEUE(wait, current); |
1251 | struct urb *urb; | |
1252 | struct usb_ctrlrequest *dr; | |
1253 | int status; | |
1254 | ||
1255 | if (ft1000dev == NULL ) | |
1256 | { | |
1257 | DEBUG("NULL ft1000dev, failure\n"); | |
1258 | return STATUS_FAILURE; | |
1259 | } | |
1260 | else if ( ft1000dev->dev == NULL ) | |
1261 | { | |
1262 | DEBUG("NULL ft1000dev->dev, failure\n"); | |
1263 | return STATUS_FAILURE; | |
1264 | } | |
bf3146c8 | 1265 | |
f7c1be0c MB |
1266 | spin_lock(&ft1000dev->device_lock); |
1267 | ||
1268 | /*DECLARE_WAITQUEUE(wait, current); | |
1269 | struct urb *urb; | |
1270 | struct usb_ctrlrequest *dr; | |
1271 | int status;*/ | |
1272 | ||
1273 | if(in_interrupt()) | |
1274 | { | |
1275 | spin_unlock(&ft1000dev->device_lock); | |
1276 | return -EBUSY; | |
1277 | } | |
1278 | ||
1279 | urb = usb_alloc_urb(0, GFP_KERNEL); | |
1280 | dr = kmalloc(sizeof(struct usb_ctrlrequest), in_interrupt() ? GFP_ATOMIC : GFP_KERNEL); | |
1281 | ||
1282 | if(!urb || !dr) | |
1283 | { | |
b7378b9e VK |
1284 | kfree(dr); |
1285 | usb_free_urb(urb); | |
bf3146c8 | 1286 | spin_unlock(&ft1000dev->device_lock); |
f7c1be0c MB |
1287 | return -ENOMEM; |
1288 | } | |
1289 | ||
bf3146c8 GKH |
1290 | |
1291 | ||
f7c1be0c MB |
1292 | dr->bRequestType = requesttype; |
1293 | dr->bRequest = request; | |
1294 | dr->wValue = value; | |
1295 | dr->wIndex = index; | |
1296 | dr->wLength = size; | |
1297 | ||
1298 | usb_fill_control_urb(urb, ft1000dev->dev, pipe, (char*)dr, (void*)data, size, (void *)ft1000_control_complete, (void*)ft1000dev); | |
bf3146c8 | 1299 | |
f7c1be0c MB |
1300 | |
1301 | init_waitqueue_head(&ft1000dev->control_wait); | |
1302 | ||
1303 | //current->state = TASK_INTERRUPTIBLE; //mbelian | |
1304 | set_current_state(TASK_INTERRUPTIBLE); | |
bf3146c8 | 1305 | |
f7c1be0c | 1306 | add_wait_queue(&ft1000dev->control_wait, &wait); |
bf3146c8 GKH |
1307 | |
1308 | ||
1309 | ||
f7c1be0c MB |
1310 | |
1311 | status = usb_submit_urb(urb, GFP_KERNEL); | |
bf3146c8 | 1312 | |
f7c1be0c | 1313 | if(status) |
bf3146c8 | 1314 | { |
f7c1be0c MB |
1315 | usb_free_urb(urb); |
1316 | kfree(dr); | |
1317 | remove_wait_queue(&ft1000dev->control_wait, &wait); | |
1318 | spin_unlock(&ft1000dev->device_lock); | |
1319 | return status; | |
1320 | } | |
1321 | ||
1322 | if(urb->status == -EINPROGRESS) | |
1323 | { | |
1324 | while(timeout && urb->status == -EINPROGRESS) | |
1325 | { | |
1326 | status = timeout = schedule_timeout(timeout); | |
1327 | } | |
1328 | } | |
1329 | else | |
1330 | { | |
1331 | status = 1; | |
1332 | } | |
1333 | ||
1334 | remove_wait_queue(&ft1000dev->control_wait, &wait); | |
1335 | ||
1336 | if(!status) | |
1337 | { | |
1338 | usb_unlink_urb(urb); | |
1339 | printk("ft1000 timeout\n"); | |
1340 | status = -ETIMEDOUT; | |
1341 | } | |
1342 | else | |
1343 | { | |
1344 | status = urb->status; | |
1345 | ||
1346 | if(urb->status) | |
1347 | { | |
7cfd8a37 | 1348 | printk("ft1000 control message failed (urb addr: %p) with error number: %i\n", urb, (int)status); |
bf3146c8 | 1349 | |
f7c1be0c MB |
1350 | usb_clear_halt(ft1000dev->dev, usb_rcvctrlpipe(ft1000dev->dev, 0)); |
1351 | usb_clear_halt(ft1000dev->dev, usb_sndctrlpipe(ft1000dev->dev, 0)); | |
1352 | usb_unlink_urb(urb); | |
1353 | } | |
1354 | } | |
1355 | ||
bf3146c8 | 1356 | |
f7c1be0c MB |
1357 | |
1358 | usb_free_urb(urb); | |
1359 | kfree(dr); | |
1360 | spin_unlock(&ft1000dev->device_lock); | |
bf3146c8 GKH |
1361 | return ret; |
1362 | ||
f7c1be0c | 1363 | |
f7c1be0c MB |
1364 | } |
1365 | ||
1366 | //--------------------------------------------------------------------------- | |
1367 | // Function: ft1000_read_fifo_len | |
1368 | // | |
1369 | // Parameters: ft1000dev - device structure | |
1370 | // | |
bf3146c8 | 1371 | // |
f7c1be0c MB |
1372 | // Returns: none |
1373 | // | |
1374 | // Description: read the fifo length register content | |
1375 | // | |
1376 | // Notes: | |
1377 | // | |
1378 | //--------------------------------------------------------------------------- | |
bf3146c8 | 1379 | static inline u16 ft1000_read_fifo_len (struct net_device *dev) |
f7c1be0c MB |
1380 | { |
1381 | u16 temp; | |
1382 | u16 ret; | |
bf3146c8 | 1383 | |
f7c1be0c MB |
1384 | //FT1000_INFO *info = (PFT1000_INFO)dev->priv; |
1385 | FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev); | |
1386 | struct ft1000_device *ft1000dev = info->pFt1000Dev; | |
1387 | // DEBUG("ft1000_read_fifo_len: enter ft1000dev %x\n", ft1000dev); //aelias [-] reason: warning: format ???%x??? expects type ???unsigned int???, but argument 2 has type ???struct ft1000_device *??? | |
7cfd8a37 | 1388 | DEBUG("ft1000_read_fifo_len: enter ft1000dev %p\n", ft1000dev); //aelias [+] reason: up |
f7c1be0c | 1389 | //ft1000_read_register(ft1000dev, &temp, FT1000_REG_MAG_UFSR); |
bf3146c8 GKH |
1390 | |
1391 | ret = STATUS_SUCCESS; | |
1392 | ||
f7c1be0c MB |
1393 | ret = ft1000_read_fifo_reg(ft1000dev, |
1394 | usb_rcvctrlpipe(ft1000dev->dev,0), | |
1395 | HARLEY_READ_REGISTER, | |
1396 | HARLEY_READ_OPERATION, | |
1397 | 0, | |
1398 | FT1000_REG_MAG_UFSR, | |
1399 | &temp, | |
1400 | 2, | |
1401 | LARGE_TIMEOUT); | |
bf3146c8 | 1402 | |
f7c1be0c MB |
1403 | if (ret>0) |
1404 | ret = STATUS_SUCCESS; | |
1405 | else | |
1406 | ret = STATUS_FAILURE; | |
1407 | ||
1408 | DEBUG("ft1000_read_fifo_len: returned %d\n", temp); | |
bf3146c8 | 1409 | |
f7c1be0c | 1410 | return (temp- 16); |
bf3146c8 | 1411 | |
f7c1be0c MB |
1412 | } |
1413 | ||
1414 | ||
1415 | //--------------------------------------------------------------------------- | |
1416 | // | |
1417 | // Function: ft1000_copy_down_pkt | |
bf3146c8 GKH |
1418 | // Descripton: This function will take an ethernet packet and convert it to |
1419 | // a Flarion packet prior to sending it to the ASIC Downlink | |
f7c1be0c MB |
1420 | // FIFO. |
1421 | // Input: | |
1422 | // dev - device structure | |
1423 | // packet - address of ethernet packet | |
1424 | // len - length of IP packet | |
1425 | // Output: | |
bf3146c8 GKH |
1426 | // status - FAILURE |
1427 | // SUCCESS | |
f7c1be0c MB |
1428 | // |
1429 | //--------------------------------------------------------------------------- | |
2a953cfd | 1430 | static int ft1000_copy_down_pkt (struct net_device *netdev, u8 *packet, u16 len) |
f7c1be0c MB |
1431 | { |
1432 | FT1000_INFO *pInfo = netdev_priv(netdev); | |
1433 | struct ft1000_device *pFt1000Dev = pInfo->pFt1000Dev; | |
1434 | ||
1435 | ||
1436 | int i, count, ret; | |
1437 | USHORT *pTemp; | |
1438 | USHORT checksum; | |
1439 | u8 *t; | |
bf3146c8 | 1440 | |
f7c1be0c MB |
1441 | if (!pInfo->CardReady) |
1442 | { | |
bf3146c8 | 1443 | |
f7c1be0c MB |
1444 | DEBUG("ft1000_copy_down_pkt::Card Not Ready\n"); |
1445 | return STATUS_FAILURE; | |
bf3146c8 | 1446 | |
f7c1be0c | 1447 | } |
f7c1be0c | 1448 | |
bf3146c8 GKH |
1449 | |
1450 | //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len); | |
1451 | ||
1452 | #if 0 | |
1453 | // Check if there is room on the FIFO | |
1454 | if ( len > ft1000_read_fifo_len (netdev) ) | |
f7c1be0c MB |
1455 | { |
1456 | udelay(10); | |
bf3146c8 | 1457 | if ( len > ft1000_read_fifo_len (netdev) ) |
f7c1be0c MB |
1458 | { |
1459 | udelay(20); | |
1460 | } | |
bf3146c8 GKH |
1461 | |
1462 | if ( len > ft1000_read_fifo_len (netdev) ) | |
f7c1be0c MB |
1463 | { |
1464 | udelay(20); | |
1465 | } | |
bf3146c8 GKH |
1466 | |
1467 | if ( len > ft1000_read_fifo_len (netdev) ) | |
f7c1be0c MB |
1468 | { |
1469 | udelay(20); | |
1470 | } | |
bf3146c8 GKH |
1471 | |
1472 | if ( len > ft1000_read_fifo_len (netdev) ) | |
f7c1be0c MB |
1473 | { |
1474 | udelay(20); | |
1475 | } | |
bf3146c8 GKH |
1476 | |
1477 | if ( len > ft1000_read_fifo_len (netdev) ) | |
f7c1be0c MB |
1478 | { |
1479 | udelay(20); | |
1480 | } | |
bf3146c8 GKH |
1481 | |
1482 | if ( len > ft1000_read_fifo_len (netdev) ) | |
f7c1be0c MB |
1483 | { |
1484 | DEBUG("ft1000_hw:ft1000_copy_down_pkt:Transmit FIFO is fulli - pkt drop\n"); | |
1485 | pInfo->stats.tx_errors++; | |
1486 | return STATUS_SUCCESS; | |
1487 | } | |
1488 | } | |
1489 | #endif | |
bf3146c8 | 1490 | |
f7c1be0c MB |
1491 | count = sizeof (PSEUDO_HDR) + len; |
1492 | if(count > MAX_BUF_SIZE) | |
1493 | { | |
1494 | DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n"); | |
1495 | DEBUG("size = %d\n", count); | |
1496 | return STATUS_FAILURE; | |
1497 | } | |
bf3146c8 | 1498 | |
f7c1be0c MB |
1499 | if ( count % 4) |
1500 | count = count + (4- (count %4) ); | |
bf3146c8 | 1501 | |
f7c1be0c MB |
1502 | pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]); |
1503 | *pTemp ++ = ntohs(count); | |
1504 | *pTemp ++ = 0x1020; | |
1505 | *pTemp ++ = 0x2010; | |
1506 | *pTemp ++ = 0x9100; | |
1507 | *pTemp ++ = 0; | |
1508 | *pTemp ++ = 0; | |
1509 | *pTemp ++ = 0; | |
1510 | pTemp = (PUSHORT)&(pFt1000Dev->tx_buf[0]); | |
1511 | checksum = *pTemp ++; | |
1512 | for (i=1; i<7; i++) | |
1513 | { | |
1514 | checksum ^= *pTemp ++; | |
1515 | } | |
1516 | *pTemp++ = checksum; | |
1517 | memcpy (&(pFt1000Dev->tx_buf[sizeof(PSEUDO_HDR)]), packet, len); | |
1518 | ||
1519 | //usb_init_urb(pFt1000Dev->tx_urb); //mbelian | |
1520 | ||
1521 | netif_stop_queue(netdev); | |
1522 | ||
1523 | //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count); | |
bf3146c8 | 1524 | |
f7c1be0c MB |
1525 | usb_fill_bulk_urb(pFt1000Dev->tx_urb, |
1526 | pFt1000Dev->dev, | |
1527 | usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr), | |
1528 | pFt1000Dev->tx_buf, | |
1529 | count, | |
1530 | ft1000_usb_transmit_complete, | |
bf3146c8 GKH |
1531 | (void*)pFt1000Dev); |
1532 | ||
f7c1be0c MB |
1533 | t = (u8 *)pFt1000Dev->tx_urb->transfer_buffer; |
1534 | //DEBUG("transfer_length=%d\n", pFt1000Dev->tx_urb->transfer_buffer_length); | |
1535 | /*for (i=0; i<count; i++ ) | |
bf3146c8 | 1536 | { |
f7c1be0c | 1537 | DEBUG("%x ", *t++ ); |
bf3146c8 GKH |
1538 | }*/ |
1539 | ||
1540 | ||
f7c1be0c MB |
1541 | ret = usb_submit_urb(pFt1000Dev->tx_urb, GFP_ATOMIC); |
1542 | if(ret) | |
1543 | { | |
1544 | DEBUG("ft1000 failed tx_urb %d\n", ret); | |
1545 | ||
1546 | /* pInfo->stats.tx_errors++; | |
bf3146c8 | 1547 | |
f7c1be0c MB |
1548 | netif_start_queue(netdev); */ //mbelian |
1549 | return STATUS_FAILURE; | |
1550 | ||
bf3146c8 GKH |
1551 | } |
1552 | else | |
f7c1be0c MB |
1553 | { |
1554 | //DEBUG("ft1000 sucess tx_urb %d\n", ret); | |
1555 | ||
1556 | pInfo->stats.tx_packets++; | |
1557 | pInfo->stats.tx_bytes += (len+14); | |
1558 | } | |
bf3146c8 GKH |
1559 | |
1560 | //DEBUG("ft1000_copy_down_pkt() exit\n"); | |
1561 | ||
f7c1be0c MB |
1562 | return STATUS_SUCCESS; |
1563 | } | |
1564 | ||
1565 | //--------------------------------------------------------------------------- | |
1566 | // Function: ft1000_start_xmit | |
1567 | // | |
1568 | // Parameters: skb - socket buffer to be sent | |
1569 | // dev - network device | |
1570 | // | |
bf3146c8 | 1571 | // |
f7c1be0c MB |
1572 | // Returns: none |
1573 | // | |
1574 | // Description: transmit a ethernet packet | |
1575 | // | |
1576 | // Notes: | |
1577 | // | |
1578 | //--------------------------------------------------------------------------- | |
bf3146c8 | 1579 | static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) |
f7c1be0c MB |
1580 | { |
1581 | FT1000_INFO *pInfo = netdev_priv(dev); | |
1582 | struct ft1000_device *pFt1000Dev= pInfo->pFt1000Dev; | |
1583 | u8 *pdata; | |
1584 | int maxlen, pipe; | |
bf3146c8 GKH |
1585 | |
1586 | ||
1587 | //DEBUG(" ft1000_start_xmit() entered\n"); | |
1588 | ||
1589 | if ( skb == NULL ) | |
f7c1be0c | 1590 | { |
bf3146c8 | 1591 | DEBUG ("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n" ); |
f7c1be0c MB |
1592 | return STATUS_FAILURE; |
1593 | } | |
bf3146c8 | 1594 | |
f7c1be0c MB |
1595 | if ( pFt1000Dev->status & FT1000_STATUS_CLOSING) |
1596 | { | |
1597 | DEBUG("network driver is closed, return\n"); | |
1598 | dev_kfree_skb(skb); | |
1599 | //usb_kill_urb(pFt1000Dev->tx_urb); //mbelian | |
1600 | return STATUS_SUCCESS; | |
1601 | } | |
1602 | ||
1603 | //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len); | |
1604 | pipe = usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr); | |
1605 | maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe)); | |
1606 | //DEBUG("ft1000_start_xmit 2: pipe=%d dev->maxpacket = %d\n", pipe, maxlen); | |
1607 | ||
1608 | pdata = (u8 *)skb->data; | |
1609 | /*for (i=0; i<skb->len; i++) | |
1610 | DEBUG("skb->data[%d]=%x ", i, *(skb->data+i)); | |
bf3146c8 | 1611 | |
f7c1be0c | 1612 | DEBUG("\n");*/ |
bf3146c8 GKH |
1613 | |
1614 | ||
1615 | if (pInfo->mediastate == 0) | |
f7c1be0c MB |
1616 | { |
1617 | /* Drop packet is mediastate is down */ | |
1618 | DEBUG("ft1000_hw:ft1000_start_xmit:mediastate is down\n"); | |
1619 | dev_kfree_skb(skb); | |
1620 | return STATUS_SUCCESS; | |
1621 | } | |
1622 | ||
bf3146c8 | 1623 | if ( (skb->len < ENET_HEADER_SIZE) || (skb->len > ENET_MAX_SIZE) ) |
f7c1be0c MB |
1624 | { |
1625 | /* Drop packet which has invalid size */ | |
1626 | DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n"); | |
1627 | dev_kfree_skb(skb); | |
1628 | return STATUS_SUCCESS; | |
1629 | } | |
bf3146c8 | 1630 | //mbelian |
f7c1be0c MB |
1631 | if(ft1000_copy_down_pkt (dev, (pdata+ENET_HEADER_SIZE-2), skb->len - ENET_HEADER_SIZE + 2) == STATUS_FAILURE) |
1632 | { | |
1633 | dev_kfree_skb(skb); | |
1634 | return STATUS_SUCCESS; | |
1635 | } | |
bf3146c8 | 1636 | |
f7c1be0c MB |
1637 | dev_kfree_skb(skb); |
1638 | //DEBUG(" ft1000_start_xmit() exit\n"); | |
bf3146c8 | 1639 | |
f7c1be0c MB |
1640 | return 0; |
1641 | } | |
1642 | ||
1643 | //--------------------------------------------------------------------------- | |
1644 | // | |
1645 | // Function: ft1000_copy_up_pkt | |
1646 | // Descripton: This function will take a packet from the FIFO up link and | |
1647 | // convert it into an ethernet packet and deliver it to the IP stack | |
1648 | // Input: | |
1649 | // urb - the receving usb urb | |
1650 | // | |
1651 | // Output: | |
bf3146c8 GKH |
1652 | // status - FAILURE |
1653 | // SUCCESS | |
f7c1be0c MB |
1654 | // |
1655 | //--------------------------------------------------------------------------- | |
2a953cfd | 1656 | static int ft1000_copy_up_pkt (struct urb *urb) |
f7c1be0c MB |
1657 | { |
1658 | PFT1000_INFO info = urb->context; | |
1659 | struct ft1000_device *ft1000dev = info->pFt1000Dev; | |
1660 | struct net_device *net = ft1000dev->net; | |
bf3146c8 | 1661 | |
f7c1be0c MB |
1662 | u16 tempword; |
1663 | u16 len; | |
1664 | u16 lena; //mbelian | |
1665 | struct sk_buff *skb; | |
1666 | u16 i; | |
1667 | u8 *pbuffer=NULL; | |
1668 | u8 *ptemp=NULL; | |
1669 | u16 *chksum; | |
1670 | ||
1671 | ||
1672 | //DEBUG("ft1000_copy_up_pkt entered\n"); | |
bf3146c8 | 1673 | |
f7c1be0c MB |
1674 | if ( ft1000dev->status & FT1000_STATUS_CLOSING) |
1675 | { | |
1676 | DEBUG("network driver is closed, return\n"); | |
1677 | return STATUS_SUCCESS; | |
1678 | } | |
bf3146c8 | 1679 | |
f7c1be0c MB |
1680 | // Read length |
1681 | len = urb->transfer_buffer_length; | |
1682 | lena = urb->actual_length; //mbelian | |
1683 | //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n", | |
1684 | // urb->transfer_buffer_length, urb->actual_length); | |
1685 | ||
1686 | chksum = (PUSHORT)ft1000dev->rx_buf; | |
bf3146c8 | 1687 | |
f7c1be0c MB |
1688 | tempword = *chksum++; |
1689 | for (i=1; i<7; i++) | |
1690 | { | |
1691 | tempword ^= *chksum++; | |
1692 | } | |
bf3146c8 | 1693 | |
f7c1be0c | 1694 | if (tempword != *chksum) |
bf3146c8 | 1695 | { |
f7c1be0c MB |
1696 | info->stats.rx_errors ++; |
1697 | ft1000_submit_rx_urb(info); | |
1698 | return STATUS_FAILURE; | |
1699 | } | |
1700 | ||
1701 | ||
1702 | //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum); | |
bf3146c8 | 1703 | |
f7c1be0c MB |
1704 | skb = dev_alloc_skb(len+12+2); |
1705 | ||
bf3146c8 | 1706 | if (skb == NULL) |
f7c1be0c MB |
1707 | { |
1708 | DEBUG("ft1000_copy_up_pkt: No Network buffers available\n"); | |
1709 | info->stats.rx_errors++; | |
1710 | ft1000_submit_rx_urb(info); | |
1711 | return STATUS_FAILURE; | |
1712 | } | |
bf3146c8 | 1713 | |
f7c1be0c | 1714 | pbuffer = (u8 *)skb_put(skb, len+12); |
bf3146c8 | 1715 | |
f7c1be0c MB |
1716 | //subtract the number of bytes read already |
1717 | ptemp = pbuffer; | |
1718 | ||
1719 | // fake MAC address | |
1720 | *pbuffer++ = net->dev_addr[0]; | |
1721 | *pbuffer++ = net->dev_addr[1]; | |
1722 | *pbuffer++ = net->dev_addr[2]; | |
1723 | *pbuffer++ = net->dev_addr[3]; | |
1724 | *pbuffer++ = net->dev_addr[4]; | |
1725 | *pbuffer++ = net->dev_addr[5]; | |
1726 | *pbuffer++ = 0x00; | |
1727 | *pbuffer++ = 0x07; | |
1728 | *pbuffer++ = 0x35; | |
1729 | *pbuffer++ = 0xff; | |
1730 | *pbuffer++ = 0xff; | |
1731 | *pbuffer++ = 0xfe; | |
f7c1be0c | 1732 | |
bf3146c8 GKH |
1733 | |
1734 | ||
1735 | ||
f7c1be0c MB |
1736 | memcpy(pbuffer, ft1000dev->rx_buf+sizeof(PSEUDO_HDR), len-sizeof(PSEUDO_HDR)); |
1737 | ||
1738 | //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n"); | |
bf3146c8 | 1739 | /*for (i=0; i<len+12; i++) |
f7c1be0c MB |
1740 | { |
1741 | DEBUG("ft1000_copy_up_pkt: Protocol Data: 0x%x\n ", *ptemp++); | |
1742 | }*/ | |
1743 | ||
1744 | skb->dev = net; | |
bf3146c8 | 1745 | |
f7c1be0c MB |
1746 | skb->protocol = eth_type_trans(skb, net); |
1747 | skb->ip_summed = CHECKSUM_UNNECESSARY; | |
1748 | netif_rx(skb); | |
1749 | ||
1750 | info->stats.rx_packets++; | |
1751 | // Add on 12 bytes for MAC address which was removed | |
1752 | info->stats.rx_bytes += (lena+12); //mbelian | |
1753 | ||
bf3146c8 | 1754 | ft1000_submit_rx_urb(info); |
f7c1be0c MB |
1755 | //DEBUG("ft1000_copy_up_pkt exited\n"); |
1756 | return SUCCESS; | |
1757 | } | |
1758 | ||
1759 | //--------------------------------------------------------------------------- | |
1760 | // | |
1761 | // Function: ft1000_submit_rx_urb | |
1762 | // Descripton: the receiving function of the network driver | |
1763 | // | |
1764 | // Input: | |
1765 | // info - a private structure contains the device information | |
1766 | // | |
1767 | // Output: | |
bf3146c8 GKH |
1768 | // status - FAILURE |
1769 | // SUCCESS | |
f7c1be0c MB |
1770 | // |
1771 | //--------------------------------------------------------------------------- | |
2a953cfd | 1772 | static int ft1000_submit_rx_urb(PFT1000_INFO info) |
f7c1be0c MB |
1773 | { |
1774 | int result; | |
1775 | struct ft1000_device *pFt1000Dev = info->pFt1000Dev; | |
1776 | ||
1777 | //netif_carrier_on(pFt1000Dev->net); | |
bf3146c8 | 1778 | |
f7c1be0c MB |
1779 | //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb)); |
1780 | if ( pFt1000Dev->status & FT1000_STATUS_CLOSING) | |
1781 | { | |
1782 | DEBUG("network driver is closed, return\n"); | |
1783 | //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian | |
1784 | return STATUS_SUCCESS; | |
1785 | } | |
1786 | //memset(pFt1000Dev->rx_urb, 0, sizeof(*pFt1000Dev->rx_urb)); | |
1787 | //usb_init_urb(pFt1000Dev->rx_urb);//mbelian | |
1788 | ||
1789 | //spin_lock_init(&pFt1000Dev->rx_urb->lock); | |
1790 | ||
1791 | usb_fill_bulk_urb(pFt1000Dev->rx_urb, | |
1792 | pFt1000Dev->dev, | |
1793 | usb_rcvbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_in_endpointAddr), | |
1794 | pFt1000Dev->rx_buf, | |
1795 | MAX_BUF_SIZE, | |
1796 | (usb_complete_t)ft1000_copy_up_pkt, | |
1797 | info); | |
1798 | ||
1799 | ||
1800 | if((result = usb_submit_urb(pFt1000Dev->rx_urb, GFP_ATOMIC))) | |
1801 | { | |
1802 | printk("ft1000_submit_rx_urb: submitting rx_urb %d failed\n", result); | |
1803 | return STATUS_FAILURE; | |
1804 | } | |
bf3146c8 | 1805 | |
f7c1be0c MB |
1806 | //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result); |
1807 | ||
1808 | return STATUS_SUCCESS; | |
1809 | } | |
1810 | ||
1811 | //--------------------------------------------------------------------------- | |
1812 | // Function: ft1000_open | |
1813 | // | |
bf3146c8 | 1814 | // Parameters: |
f7c1be0c MB |
1815 | // dev - network device |
1816 | // | |
bf3146c8 | 1817 | // |
f7c1be0c MB |
1818 | // Returns: none |
1819 | // | |
1820 | // Description: open the network driver | |
1821 | // | |
1822 | // Notes: | |
1823 | // | |
1824 | //--------------------------------------------------------------------------- | |
bf3146c8 | 1825 | static int ft1000_open (struct net_device *dev) |
f7c1be0c MB |
1826 | { |
1827 | FT1000_INFO *pInfo = (FT1000_INFO *)netdev_priv(dev); | |
1828 | struct timeval tv; //mbelian | |
1829 | ||
1830 | DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber); | |
1831 | //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len); | |
1832 | ||
1833 | pInfo->stats.rx_bytes = 0; //mbelian | |
1834 | pInfo->stats.tx_bytes = 0; //mbelian | |
1835 | pInfo->stats.rx_packets = 0; //mbelian | |
1836 | pInfo->stats.tx_packets = 0; //mbelian | |
1837 | do_gettimeofday(&tv); | |
1838 | pInfo->ConTm = tv.tv_sec; | |
1839 | pInfo->ProgConStat = 0; //mbelian | |
bf3146c8 GKH |
1840 | |
1841 | ||
f7c1be0c | 1842 | netif_start_queue(dev); |
bf3146c8 | 1843 | |
f7c1be0c | 1844 | //netif_device_attach(dev); |
bf3146c8 | 1845 | |
f7c1be0c | 1846 | netif_carrier_on(dev); //mbelian |
bf3146c8 GKH |
1847 | |
1848 | ft1000_submit_rx_urb(pInfo); | |
f7c1be0c MB |
1849 | return 0; |
1850 | } | |
1851 | ||
1852 | //--------------------------------------------------------------------------- | |
1853 | // Function: ft1000_close | |
1854 | // | |
bf3146c8 | 1855 | // Parameters: |
f7c1be0c MB |
1856 | // net - network device |
1857 | // | |
bf3146c8 | 1858 | // |
f7c1be0c MB |
1859 | // Returns: none |
1860 | // | |
1861 | // Description: close the network driver | |
1862 | // | |
1863 | // Notes: | |
1864 | // | |
1865 | //--------------------------------------------------------------------------- | |
1866 | int ft1000_close(struct net_device *net) | |
1867 | { | |
1868 | FT1000_INFO *pInfo = (FT1000_INFO *) netdev_priv (net); | |
1869 | struct ft1000_device *ft1000dev = pInfo->pFt1000Dev; | |
1870 | ||
1871 | //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt); | |
bf3146c8 | 1872 | |
f7c1be0c MB |
1873 | ft1000dev->status |= FT1000_STATUS_CLOSING; |
1874 | ||
1875 | //DEBUG("ft1000_close: calling usb_kill_urb \n"); | |
1876 | //usb_kill_urb(ft1000dev->rx_urb); | |
1877 | //usb_kill_urb(ft1000dev->tx_urb); | |
bf3146c8 | 1878 | |
f7c1be0c | 1879 | |
7cfd8a37 | 1880 | DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev); |
f7c1be0c MB |
1881 | netif_carrier_off(net);//mbelian |
1882 | netif_stop_queue(net); | |
1883 | //DEBUG("ft1000_close: netif_stop_queue called\n"); | |
1884 | ft1000dev->status &= ~FT1000_STATUS_CLOSING; | |
1885 | ||
1886 | pInfo->ProgConStat = 0xff; //mbelian | |
1887 | ||
1888 | ||
1889 | return 0; | |
1890 | } | |
1891 | ||
1892 | static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev) | |
1893 | { | |
1894 | FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev); | |
1895 | //struct ft1000_device *ft1000dev = info->pFt1000Dev; | |
bf3146c8 | 1896 | |
f7c1be0c MB |
1897 | //return &(ft1000dev->stats);//mbelian |
1898 | return &(info->stats); //mbelian | |
1899 | } | |
1900 | ||
1901 | ||
1902 | /********************************************************************************* | |
1903 | Jim | |
1904 | */ | |
1905 | ||
1906 | ||
1907 | //--------------------------------------------------------------------------- | |
1908 | // | |
1909 | // Function: ft1000_chkcard | |
1910 | // Descripton: This function will check if the device is presently available on | |
1911 | // the system. | |
1912 | // Input: | |
1913 | // dev - device structure | |
1914 | // Output: | |
1915 | // status - FALSE (device is not present) | |
bf3146c8 | 1916 | // TRUE (device is present) |
f7c1be0c MB |
1917 | // |
1918 | //--------------------------------------------------------------------------- | |
1919 | static int ft1000_chkcard (struct ft1000_device *dev) { | |
1920 | u16 tempword; | |
1921 | u16 status; | |
1922 | FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net); | |
bf3146c8 | 1923 | |
f7c1be0c MB |
1924 | if (info->fCondResetPend) |
1925 | { | |
1926 | DEBUG("ft1000_hw:ft1000_chkcard:Card is being reset, return FALSE\n"); | |
1927 | return TRUE; | |
1928 | } | |
bf3146c8 | 1929 | |
f7c1be0c MB |
1930 | // Mask register is used to check for device presence since it is never |
1931 | // set to zero. | |
1932 | status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK); | |
1933 | //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword); | |
1934 | if (tempword == 0) { | |
1935 | DEBUG("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n"); | |
1936 | return FALSE; | |
1937 | } | |
1938 | ||
1939 | // The system will return the value of 0xffff for the version register | |
1940 | // if the device is not present. | |
1941 | status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID); | |
1942 | //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword); | |
1943 | //pxu if (tempword == 0xffff) { | |
1944 | if (tempword != 0x1b01 ){ | |
1945 | dev->status |= FT1000_STATUS_CLOSING; //mbelian | |
1946 | DEBUG("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n"); | |
1947 | return FALSE; | |
1948 | } | |
1949 | return TRUE; | |
1950 | } | |
1951 | ||
1952 | //--------------------------------------------------------------------------- | |
1953 | // | |
1954 | // Function: ft1000_hbchk | |
1955 | // Descripton: This function will perform the heart beat check of the DSP as | |
1956 | // well as the ASIC. | |
1957 | // Input: | |
1958 | // dev - device structure | |
1959 | // Output: | |
1960 | // none | |
1961 | // | |
1962 | //--------------------------------------------------------------------------- | |
1963 | static void ft1000_hbchk(u_long data) | |
1964 | { | |
bf3146c8 | 1965 | struct ft1000_device *dev = (struct ft1000_device *)data; |
f7c1be0c MB |
1966 | |
1967 | FT1000_INFO *info; | |
1968 | USHORT tempword; | |
1969 | u16 status; | |
1970 | info = (FT1000_INFO *) netdev_priv (dev->net); | |
1971 | ||
1972 | DEBUG("ft1000_hbchk called for CardNumber = %d CardReady = %d\n", info->CardNumber, info->CardReady); | |
bf3146c8 | 1973 | |
f7c1be0c | 1974 | if (info->fCondResetPend == 1) { |
bf3146c8 | 1975 | // Reset ASIC and DSP |
f7c1be0c MB |
1976 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX); |
1977 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX); | |
1978 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX); | |
bf3146c8 | 1979 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX); |
f7c1be0c MB |
1980 | |
1981 | info->DrvErrNum = DSP_CONDRESET_INFO; | |
1982 | DEBUG("ft1000_hw:DSP conditional reset requested\n"); | |
1983 | ft1000_reset_card(dev->net); | |
1984 | info->fCondResetPend = 0; | |
1985 | /* Schedule this module to run every 2 seconds */ | |
1986 | ||
1987 | poll_timer[info->CardNumber].expires = jiffies + (2*HZ); | |
1988 | poll_timer[info->CardNumber].data = (u_long)dev; | |
1989 | add_timer(&poll_timer[info->CardNumber]); | |
1990 | ||
1991 | ||
1992 | ||
1993 | return; | |
1994 | } | |
bf3146c8 | 1995 | |
f7c1be0c MB |
1996 | if (info->CardReady == 1) { |
1997 | // Perform dsp heartbeat check | |
1998 | status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX)); | |
1999 | DEBUG("ft1000_hw:ft1000_hbchk:hi_ho value = 0x%x\n", tempword); | |
2000 | // Let's perform another check if ho is not detected | |
2001 | if (tempword != ho) { | |
2002 | status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword,FT1000_MAG_HI_HO_INDX)); | |
2003 | } | |
2004 | if (tempword != ho) { | |
2005 | printk(KERN_INFO "ft1000: heartbeat failed - no ho detected\n"); | |
2006 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX); | |
2007 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX); | |
2008 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX); | |
bf3146c8 | 2009 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX); |
f7c1be0c MB |
2010 | info->DrvErrNum = DSP_HB_INFO; |
2011 | if (ft1000_reset_card(dev->net) == 0) { | |
2012 | printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n"); | |
2013 | info->ProgConStat = 0xff; | |
2014 | return; | |
2015 | } | |
2016 | /* Schedule this module to run every 2 seconds */ | |
2017 | poll_timer[info->CardNumber].expires = jiffies + (2*HZ); | |
2018 | poll_timer[info->CardNumber].data = (u_long)dev; | |
2019 | add_timer(&poll_timer[info->CardNumber]); | |
2020 | return; | |
2021 | } | |
2022 | ||
2023 | status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL); | |
2024 | // Let's check doorbell again if fail | |
2025 | if (tempword & FT1000_DB_HB) { | |
2026 | status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL); | |
2027 | } | |
2028 | if (tempword & FT1000_DB_HB) { | |
2029 | printk(KERN_INFO "ft1000: heartbeat doorbell not clear by firmware\n"); | |
2030 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX); | |
2031 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX); | |
2032 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX); | |
2033 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX); | |
2034 | info->DrvErrNum = DSP_HB_INFO; | |
2035 | if (ft1000_reset_card(dev->net) == 0) { | |
2036 | printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n"); | |
2037 | info->ProgConStat = 0xff; | |
2038 | return; | |
2039 | } | |
2040 | /* Schedule this module to run every 2 seconds */ | |
2041 | poll_timer[info->CardNumber].expires = jiffies + (2*HZ); | |
2042 | poll_timer[info->CardNumber].data = (u_long)dev; | |
2043 | add_timer(&poll_timer[info->CardNumber]); | |
2044 | return; | |
2045 | } | |
2046 | ||
bf3146c8 | 2047 | // Set dedicated area to hi and ring appropriate doorbell according |
f7c1be0c MB |
2048 | // to hi/ho heartbeat protocol |
2049 | ft1000_write_dpram16(dev, FT1000_MAG_HI_HO, hi_mag, FT1000_MAG_HI_HO_INDX); | |
2050 | ||
2051 | status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX)); | |
2052 | // Let's write hi again if fail | |
2053 | if (tempword != hi) { | |
2054 | ft1000_write_dpram16(dev, FT1000_MAG_HI_HO, hi_mag, FT1000_MAG_HI_HO_INDX); | |
2055 | status = ntohs(ft1000_read_dpram16(dev, FT1000_MAG_HI_HO, (PUCHAR)&tempword, FT1000_MAG_HI_HO_INDX)); | |
2056 | ||
2057 | } | |
2058 | if (tempword != hi) { | |
2059 | printk(KERN_INFO "ft1000: heartbeat failed - cannot write hi into DPRAM\n"); | |
2060 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX); | |
2061 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX); | |
2062 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX); | |
bf3146c8 | 2063 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX); |
f7c1be0c MB |
2064 | |
2065 | info->DrvErrNum = DSP_HB_INFO; | |
2066 | if (ft1000_reset_card(dev->net) == 0) { | |
2067 | printk(KERN_INFO "ft1000: Hardware Failure Detected - PC Card disabled\n"); | |
2068 | info->ProgConStat = 0xff; | |
2069 | return; | |
2070 | } | |
2071 | /* Schedule this module to run every 2 seconds */ | |
2072 | poll_timer[info->CardNumber].expires = jiffies + (2*HZ); | |
2073 | poll_timer[info->CardNumber].data = (u_long)dev; | |
2074 | add_timer(&poll_timer[info->CardNumber]); | |
2075 | return; | |
2076 | } | |
2077 | ft1000_write_register(dev, FT1000_DB_HB, FT1000_REG_DOORBELL); | |
2078 | ||
2079 | } | |
bf3146c8 | 2080 | |
f7c1be0c MB |
2081 | /* Schedule this module to run every 2 seconds */ |
2082 | poll_timer[info->CardNumber].expires = jiffies + (2*HZ); | |
2083 | poll_timer[info->CardNumber].data = (u_long)dev; | |
2084 | add_timer(&poll_timer[info->CardNumber]); | |
2085 | } | |
2086 | ||
2087 | //--------------------------------------------------------------------------- | |
2088 | // | |
2089 | // Function: ft1000_receive_cmd | |
bf3146c8 | 2090 | // Descripton: This function will read a message from the dpram area. |
f7c1be0c MB |
2091 | // Input: |
2092 | // dev - network device structure | |
2093 | // pbuffer - caller supply address to buffer | |
2094 | // pnxtph - pointer to next pseudo header | |
2095 | // Output: | |
2096 | // Status = 0 (unsuccessful) | |
2097 | // = 1 (successful) | |
2098 | // | |
2099 | //--------------------------------------------------------------------------- | |
2a953cfd | 2100 | static BOOLEAN ft1000_receive_cmd (struct ft1000_device *dev, u16 *pbuffer, int maxsz, u16 *pnxtph) { |
f7c1be0c MB |
2101 | u16 size, ret; |
2102 | u16 *ppseudohdr; | |
2103 | int i; | |
2104 | u16 tempword; | |
2105 | ||
2106 | ret = ft1000_read_dpram16(dev, FT1000_MAG_PH_LEN, (PUCHAR)&size, FT1000_MAG_PH_LEN_INDX); | |
2107 | size = ntohs(size) + PSEUDOSZ; | |
2108 | if (size > maxsz) { | |
2109 | DEBUG("FT1000:ft1000_receive_cmd:Invalid command length = %d\n", size); | |
2110 | return FALSE; | |
2111 | } | |
2112 | else { | |
2113 | ppseudohdr = (u16 *)pbuffer; | |
2114 | //spin_lock_irqsave (&info->dpram_lock, flags); | |
2115 | ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE, FT1000_REG_DPRAM_ADDR); | |
2116 | ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH); | |
2117 | //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer); | |
bf3146c8 | 2118 | pbuffer++; |
f7c1be0c MB |
2119 | ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE+1, FT1000_REG_DPRAM_ADDR); |
2120 | for (i=0; i<=(size>>2); i++) { | |
2121 | ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL); | |
2122 | pbuffer++; | |
2123 | ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH); | |
2124 | pbuffer++; | |
2125 | } | |
2126 | //copy odd aligned word | |
2127 | ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL); | |
2128 | //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer); | |
2129 | pbuffer++; | |
2130 | ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH); | |
2131 | //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer); | |
2132 | pbuffer++; | |
2133 | if (size & 0x0001) { | |
2134 | //copy odd byte from fifo | |
2135 | ret = ft1000_read_register(dev, &tempword, FT1000_REG_DPRAM_DATA); | |
2136 | *pbuffer = ntohs(tempword); | |
2137 | } | |
2138 | //spin_unlock_irqrestore(&info->dpram_lock, flags); | |
2139 | ||
2140 | // Check if pseudo header checksum is good | |
2141 | // Calculate pseudo header checksum | |
2142 | tempword = *ppseudohdr++; | |
2143 | for (i=1; i<7; i++) { | |
2144 | tempword ^= *ppseudohdr++; | |
2145 | } | |
2146 | if ( (tempword != *ppseudohdr) ) { | |
2147 | return FALSE; | |
2148 | } | |
bf3146c8 GKH |
2149 | |
2150 | ||
2151 | #if 0 | |
f7c1be0c MB |
2152 | DEBUG("ft1000_receive_cmd:pbuffer\n"); |
2153 | for(i = 0; i < size; i+=5) | |
2154 | { | |
bf3146c8 GKH |
2155 | if( (i + 5) < size ) |
2156 | DEBUG("0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", tempbuffer[i], tempbuffer[i+1], tempbuffer[i+2], tempbuffer[i+3], tempbuffer[i+4]); | |
f7c1be0c MB |
2157 | else |
2158 | { | |
2159 | for (j = i; j < size; j++) | |
bf3146c8 GKH |
2160 | DEBUG("0x%x ", tempbuffer[j]); |
2161 | DEBUG("\n"); | |
f7c1be0c MB |
2162 | break; |
2163 | } | |
2164 | } | |
bf3146c8 GKH |
2165 | |
2166 | #endif | |
2167 | ||
f7c1be0c MB |
2168 | return TRUE; |
2169 | } | |
2170 | } | |
2171 | ||
2172 | ||
2a953cfd | 2173 | static int ft1000_dsp_prov(void *arg) |
f7c1be0c MB |
2174 | { |
2175 | struct ft1000_device *dev = (struct ft1000_device *)arg; | |
2176 | FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net); | |
2177 | u16 tempword; | |
2178 | u16 len; | |
2179 | u16 i=0; | |
2180 | PPROV_RECORD ptr; | |
2181 | PPSEUDO_HDR ppseudo_hdr; | |
2182 | PUSHORT pmsg; | |
2183 | u16 status; | |
2184 | USHORT TempShortBuf [256]; | |
2185 | ||
2186 | DEBUG("*** DspProv Entered\n"); | |
2187 | ||
bf3146c8 GKH |
2188 | while ( list_empty(&info->prov_list) == 0 |
2189 | /*&& !kthread_should_stop() */) | |
f7c1be0c MB |
2190 | { |
2191 | DEBUG("DSP Provisioning List Entry\n"); | |
2192 | ||
2193 | // Check if doorbell is available | |
2194 | DEBUG("check if doorbell is cleared\n"); | |
2195 | status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL); | |
2196 | if (status) | |
2197 | { | |
2198 | DEBUG("ft1000_dsp_prov::ft1000_read_register error\n"); | |
2199 | break; | |
2200 | } | |
2201 | ||
2202 | while (tempword & FT1000_DB_DPRAM_TX) { | |
2203 | mdelay(10); | |
2204 | i++; | |
2205 | if (i==10) { | |
2206 | DEBUG("FT1000:ft1000_dsp_prov:message drop\n"); | |
2207 | return STATUS_FAILURE; | |
2208 | } | |
2209 | ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL); | |
2210 | } | |
2211 | ||
2212 | if ( !(tempword & FT1000_DB_DPRAM_TX) ) { | |
2213 | DEBUG("*** Provision Data Sent to DSP\n"); | |
bf3146c8 | 2214 | |
f7c1be0c MB |
2215 | // Send provisioning data |
2216 | ptr = list_entry(info->prov_list.next, PROV_RECORD, list); | |
2217 | len = *(u16 *)ptr->pprov_data; | |
2218 | len = htons(len); | |
2219 | len += PSEUDOSZ; | |
2220 | //len = htons(len); | |
bf3146c8 | 2221 | |
f7c1be0c MB |
2222 | pmsg = (PUSHORT)ptr->pprov_data; |
2223 | ppseudo_hdr = (PPSEUDO_HDR)pmsg; | |
2224 | // Insert slow queue sequence number | |
2225 | ppseudo_hdr->seq_num = info->squeseqnum++; | |
2226 | ppseudo_hdr->portsrc = 0; | |
2227 | // Calculate new checksum | |
2228 | ppseudo_hdr->checksum = *pmsg++; | |
2229 | //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); | |
2230 | for (i=1; i<7; i++) { | |
2231 | ppseudo_hdr->checksum ^= *pmsg++; | |
2232 | //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); | |
2233 | } | |
bf3146c8 | 2234 | |
f7c1be0c MB |
2235 | TempShortBuf[0] = 0; |
2236 | TempShortBuf[1] = htons (len); | |
2237 | memcpy(&TempShortBuf[2], ppseudo_hdr, len); | |
bf3146c8 | 2238 | |
f7c1be0c | 2239 | status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&TempShortBuf[0], (unsigned short)(len+2)); |
bf3146c8 GKH |
2240 | status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL); |
2241 | ||
f7c1be0c MB |
2242 | list_del(&ptr->list); |
2243 | kfree(ptr->pprov_data); | |
bf3146c8 | 2244 | kfree(ptr); |
f7c1be0c MB |
2245 | } |
2246 | msleep(10); | |
2247 | } | |
2248 | ||
2249 | DEBUG("DSP Provisioning List Entry finished\n"); | |
2250 | ||
2251 | msleep(100); | |
bf3146c8 | 2252 | |
f7c1be0c MB |
2253 | info->fProvComplete = 1; |
2254 | info->CardReady = 1; | |
2255 | info->DSP_loading= 0; | |
2256 | return STATUS_SUCCESS; | |
bf3146c8 | 2257 | |
f7c1be0c MB |
2258 | } |
2259 | ||
bf3146c8 | 2260 | |
2a953cfd | 2261 | static int ft1000_proc_drvmsg (struct ft1000_device *dev, u16 size) { |
f7c1be0c MB |
2262 | FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net); |
2263 | u16 msgtype; | |
2264 | u16 tempword; | |
2265 | PMEDIAMSG pmediamsg; | |
2266 | PDSPINITMSG pdspinitmsg; | |
2267 | PDRVMSG pdrvmsg; | |
2268 | u16 i; | |
2269 | PPSEUDO_HDR ppseudo_hdr; | |
2270 | PUSHORT pmsg; | |
bf3146c8 | 2271 | u16 status; |
f7c1be0c MB |
2272 | //struct timeval tv; //mbelian |
2273 | union { | |
2274 | u8 byte[2]; | |
2275 | u16 wrd; | |
2276 | } convert; | |
2277 | ||
bf3146c8 | 2278 | |
2a953cfd AB |
2279 | char *cmdbuffer = kmalloc(1600, GFP_KERNEL); |
2280 | if (!cmdbuffer) | |
2281 | return STATUS_FAILURE; | |
bf3146c8 | 2282 | |
2a953cfd | 2283 | status = ft1000_read_dpram32(dev, 0x200, cmdbuffer, size); |
f7c1be0c | 2284 | |
bf3146c8 GKH |
2285 | |
2286 | //if (ft1000_receive_cmd(dev, &cmdbuffer[0], MAX_CMD_SQSIZE, &tempword)) | |
f7c1be0c | 2287 | { |
bf3146c8 GKH |
2288 | |
2289 | #ifdef JDEBUG | |
f7c1be0c MB |
2290 | DEBUG("ft1000_proc_drvmsg:cmdbuffer\n"); |
2291 | for(i = 0; i < size; i+=5) | |
2292 | { | |
bf3146c8 GKH |
2293 | if( (i + 5) < size ) |
2294 | 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 |
2295 | else |
2296 | { | |
2297 | for (j = i; j < size; j++) | |
bf3146c8 GKH |
2298 | DEBUG("0x%x ", cmdbuffer[j]); |
2299 | DEBUG("\n"); | |
f7c1be0c MB |
2300 | break; |
2301 | } | |
2302 | } | |
bf3146c8 | 2303 | #endif |
f7c1be0c MB |
2304 | pdrvmsg = (PDRVMSG)&cmdbuffer[2]; |
2305 | msgtype = ntohs(pdrvmsg->type); | |
2306 | DEBUG("ft1000_proc_drvmsg:Command message type = 0x%x\n", msgtype); | |
2307 | switch (msgtype) { | |
2308 | case MEDIA_STATE: { | |
2309 | DEBUG("ft1000_proc_drvmsg:Command message type = MEDIA_STATE"); | |
bf3146c8 | 2310 | |
f7c1be0c MB |
2311 | pmediamsg = (PMEDIAMSG)&cmdbuffer[0]; |
2312 | if (info->ProgConStat != 0xFF) { | |
2313 | if (pmediamsg->state) { | |
2314 | DEBUG("Media is up\n"); | |
2315 | if (info->mediastate == 0) { | |
2316 | if ( info->NetDevRegDone ) | |
2317 | { | |
2318 | //netif_carrier_on(dev->net);//mbelian | |
bf3146c8 | 2319 | netif_wake_queue(dev->net); |
f7c1be0c | 2320 | } |
bf3146c8 | 2321 | info->mediastate = 1; |
f7c1be0c MB |
2322 | /*do_gettimeofday(&tv); |
2323 | info->ConTm = tv.tv_sec;*/ //mbelian | |
2324 | } | |
2325 | } | |
2326 | else { | |
2327 | DEBUG("Media is down\n"); | |
2328 | if (info->mediastate == 1) { | |
2329 | info->mediastate = 0; | |
2330 | if ( info->NetDevRegDone ) | |
2331 | { | |
2332 | //netif_carrier_off(dev->net); mbelian | |
2333 | //netif_stop_queue(dev->net); | |
2334 | } | |
2335 | info->ConTm = 0; | |
2336 | } | |
2337 | } | |
2338 | } | |
2339 | else { | |
2340 | DEBUG("Media is down\n"); | |
2341 | if (info->mediastate == 1) { | |
2342 | info->mediastate = 0; | |
bf3146c8 | 2343 | if ( info->NetDevRegDone) |
f7c1be0c MB |
2344 | { |
2345 | //netif_carrier_off(dev->net); //mbelian | |
2346 | //netif_stop_queue(dev->net); | |
2347 | } | |
2348 | info->ConTm = 0; | |
2349 | } | |
2350 | } | |
2351 | break; | |
2352 | } | |
2353 | case DSP_INIT_MSG: { | |
2354 | DEBUG("ft1000_proc_drvmsg:Command message type = DSP_INIT_MSG"); | |
bf3146c8 | 2355 | |
f7c1be0c MB |
2356 | pdspinitmsg = (PDSPINITMSG)&cmdbuffer[2]; |
2357 | memcpy(info->DspVer, pdspinitmsg->DspVer, DSPVERSZ); | |
2358 | DEBUG("DSPVER = 0x%2x 0x%2x 0x%2x 0x%2x\n", info->DspVer[0], info->DspVer[1], info->DspVer[2], info->DspVer[3]); | |
2359 | memcpy(info->HwSerNum, pdspinitmsg->HwSerNum, HWSERNUMSZ); | |
2360 | memcpy(info->Sku, pdspinitmsg->Sku, SKUSZ); | |
2361 | memcpy(info->eui64, pdspinitmsg->eui64, EUISZ); | |
2362 | 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]); | |
2363 | dev->net->dev_addr[0] = info->eui64[0]; | |
2364 | dev->net->dev_addr[1] = info->eui64[1]; | |
2365 | dev->net->dev_addr[2] = info->eui64[2]; | |
2366 | dev->net->dev_addr[3] = info->eui64[5]; | |
2367 | dev->net->dev_addr[4] = info->eui64[6]; | |
2368 | dev->net->dev_addr[5] = info->eui64[7]; | |
bf3146c8 | 2369 | |
f7c1be0c MB |
2370 | if (ntohs(pdspinitmsg->length) == (sizeof(DSPINITMSG) - 20) ) { |
2371 | memcpy(info->ProductMode, pdspinitmsg->ProductMode, MODESZ); | |
2372 | memcpy(info->RfCalVer, pdspinitmsg->RfCalVer, CALVERSZ); | |
2373 | memcpy(info->RfCalDate, pdspinitmsg->RfCalDate, CALDATESZ); | |
2374 | DEBUG("RFCalVer = 0x%2x 0x%2x\n", info->RfCalVer[0], info->RfCalVer[1]); | |
2375 | } | |
2376 | break; | |
2377 | } | |
2378 | case DSP_PROVISION: { | |
2379 | DEBUG("ft1000_proc_drvmsg:Command message type = DSP_PROVISION\n"); | |
bf3146c8 | 2380 | |
f7c1be0c MB |
2381 | // kick off dspprov routine to start provisioning |
2382 | // Send provisioning data to DSP | |
bf3146c8 | 2383 | if (list_empty(&info->prov_list) == 0) |
f7c1be0c MB |
2384 | { |
2385 | info->fProvComplete = 0; | |
2386 | status = ft1000_dsp_prov(dev); | |
2387 | if (status != STATUS_SUCCESS) | |
2a953cfd | 2388 | goto out; |
f7c1be0c MB |
2389 | } |
2390 | else { | |
2391 | info->fProvComplete = 1; | |
2392 | status = ft1000_write_register (dev, FT1000_DB_HB, FT1000_REG_DOORBELL); | |
2393 | DEBUG("FT1000:drivermsg:No more DSP provisioning data in dsp image\n"); | |
2394 | } | |
2395 | DEBUG("ft1000_proc_drvmsg:DSP PROVISION is done\n"); | |
2396 | break; | |
2397 | } | |
2398 | case DSP_STORE_INFO: { | |
2399 | DEBUG("ft1000_proc_drvmsg:Command message type = DSP_STORE_INFO"); | |
bf3146c8 | 2400 | |
f7c1be0c MB |
2401 | DEBUG("FT1000:drivermsg:Got DSP_STORE_INFO\n"); |
2402 | tempword = ntohs(pdrvmsg->length); | |
2403 | info->DSPInfoBlklen = tempword; | |
2404 | if (tempword < (MAX_DSP_SESS_REC-4) ) { | |
2405 | pmsg = (PUSHORT)&pdrvmsg->data[0]; | |
2406 | for (i=0; i<((tempword+1)/2); i++) { | |
2407 | DEBUG("FT1000:drivermsg:dsp info data = 0x%x\n", *pmsg); | |
2408 | info->DSPInfoBlk[i+10] = *pmsg++; | |
2409 | } | |
2410 | } | |
2411 | else { | |
2412 | info->DSPInfoBlklen = 0; | |
2413 | } | |
2414 | break; | |
2415 | } | |
2416 | case DSP_GET_INFO: { | |
2417 | DEBUG("FT1000:drivermsg:Got DSP_GET_INFO\n"); | |
2418 | // copy dsp info block to dsp | |
2419 | info->DrvMsgPend = 1; | |
2420 | // allow any outstanding ioctl to finish | |
2421 | mdelay(10); | |
2422 | status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL); | |
2423 | if (tempword & FT1000_DB_DPRAM_TX) { | |
2424 | mdelay(10); | |
2425 | status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL); | |
2426 | if (tempword & FT1000_DB_DPRAM_TX) { | |
2427 | mdelay(10); | |
2428 | status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL); | |
2429 | if (tempword & FT1000_DB_DPRAM_TX) { | |
2430 | break; | |
2431 | } | |
bf3146c8 | 2432 | } |
f7c1be0c | 2433 | } |
bf3146c8 | 2434 | |
f7c1be0c MB |
2435 | // Put message into Slow Queue |
2436 | // Form Pseudo header | |
2437 | pmsg = (PUSHORT)info->DSPInfoBlk; | |
2438 | *pmsg++ = 0; | |
bf3146c8 | 2439 | *pmsg++ = htons(info->DSPInfoBlklen+20+info->DSPInfoBlklen); |
f7c1be0c MB |
2440 | ppseudo_hdr = (PPSEUDO_HDR)(PUSHORT)&info->DSPInfoBlk[2]; |
2441 | ppseudo_hdr->length = htons(info->DSPInfoBlklen+4+info->DSPInfoBlklen); | |
bf3146c8 | 2442 | ppseudo_hdr->source = 0x10; |
f7c1be0c MB |
2443 | ppseudo_hdr->destination = 0x20; |
2444 | ppseudo_hdr->portdest = 0; | |
2445 | ppseudo_hdr->portsrc = 0; | |
2446 | ppseudo_hdr->sh_str_id = 0; | |
2447 | ppseudo_hdr->control = 0; | |
2448 | ppseudo_hdr->rsvd1 = 0; | |
2449 | ppseudo_hdr->rsvd2 = 0; | |
2450 | ppseudo_hdr->qos_class = 0; | |
2451 | // Insert slow queue sequence number | |
2452 | ppseudo_hdr->seq_num = info->squeseqnum++; | |
bf3146c8 | 2453 | // Insert application id |
f7c1be0c MB |
2454 | ppseudo_hdr->portsrc = 0; |
2455 | // Calculate new checksum | |
2456 | ppseudo_hdr->checksum = *pmsg++; | |
2457 | for (i=1; i<7; i++) { | |
2458 | ppseudo_hdr->checksum ^= *pmsg++; | |
2459 | } | |
2460 | info->DSPInfoBlk[10] = 0x7200; | |
2461 | info->DSPInfoBlk[11] = htons(info->DSPInfoBlklen); | |
2462 | status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPInfoBlk[0], (unsigned short)(info->DSPInfoBlklen+22)); | |
bf3146c8 | 2463 | status = ft1000_write_register (dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL); |
f7c1be0c | 2464 | info->DrvMsgPend = 0; |
bf3146c8 | 2465 | |
f7c1be0c MB |
2466 | break; |
2467 | } | |
bf3146c8 | 2468 | |
f7c1be0c MB |
2469 | case GET_DRV_ERR_RPT_MSG: { |
2470 | DEBUG("FT1000:drivermsg:Got GET_DRV_ERR_RPT_MSG\n"); | |
2471 | // copy driver error message to dsp | |
2472 | info->DrvMsgPend = 1; | |
2473 | // allow any outstanding ioctl to finish | |
2474 | mdelay(10); | |
2475 | status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL); | |
2476 | if (tempword & FT1000_DB_DPRAM_TX) { | |
2477 | mdelay(10); | |
2478 | status = ft1000_read_register(dev, &tempword, FT1000_REG_DOORBELL); | |
2479 | if (tempword & FT1000_DB_DPRAM_TX) { | |
2480 | mdelay(10); | |
bf3146c8 | 2481 | } |
f7c1be0c | 2482 | } |
bf3146c8 | 2483 | |
f7c1be0c MB |
2484 | if ( (tempword & FT1000_DB_DPRAM_TX) == 0) { |
2485 | // Put message into Slow Queue | |
2486 | // Form Pseudo header | |
2487 | pmsg = (PUSHORT)&tempbuffer[0]; | |
2488 | ppseudo_hdr = (PPSEUDO_HDR)pmsg; | |
2489 | ppseudo_hdr->length = htons(0x0012); | |
bf3146c8 | 2490 | ppseudo_hdr->source = 0x10; |
f7c1be0c MB |
2491 | ppseudo_hdr->destination = 0x20; |
2492 | ppseudo_hdr->portdest = 0; | |
2493 | ppseudo_hdr->portsrc = 0; | |
2494 | ppseudo_hdr->sh_str_id = 0; | |
2495 | ppseudo_hdr->control = 0; | |
2496 | ppseudo_hdr->rsvd1 = 0; | |
2497 | ppseudo_hdr->rsvd2 = 0; | |
2498 | ppseudo_hdr->qos_class = 0; | |
2499 | // Insert slow queue sequence number | |
2500 | ppseudo_hdr->seq_num = info->squeseqnum++; | |
bf3146c8 | 2501 | // Insert application id |
f7c1be0c MB |
2502 | ppseudo_hdr->portsrc = 0; |
2503 | // Calculate new checksum | |
2504 | ppseudo_hdr->checksum = *pmsg++; | |
2505 | for (i=1; i<7; i++) { | |
2506 | ppseudo_hdr->checksum ^= *pmsg++; | |
2507 | } | |
2508 | pmsg = (PUSHORT)&tempbuffer[16]; | |
2509 | *pmsg++ = htons(RSP_DRV_ERR_RPT_MSG); | |
2510 | *pmsg++ = htons(0x000e); | |
2511 | *pmsg++ = htons(info->DSP_TIME[0]); | |
2512 | *pmsg++ = htons(info->DSP_TIME[1]); | |
2513 | *pmsg++ = htons(info->DSP_TIME[2]); | |
2514 | *pmsg++ = htons(info->DSP_TIME[3]); | |
2515 | convert.byte[0] = info->DspVer[0]; | |
2516 | convert.byte[1] = info->DspVer[1]; | |
2517 | *pmsg++ = convert.wrd; | |
2518 | convert.byte[0] = info->DspVer[2]; | |
2519 | convert.byte[1] = info->DspVer[3]; | |
2520 | *pmsg++ = convert.wrd; | |
2521 | *pmsg++ = htons(info->DrvErrNum); | |
2522 | ||
2523 | CardSendCommand (dev, (unsigned char*)&tempbuffer[0], (USHORT)(0x0012 + PSEUDOSZ)); | |
2524 | info->DrvErrNum = 0; | |
2525 | } | |
2526 | info->DrvMsgPend = 0; | |
bf3146c8 GKH |
2527 | |
2528 | break; | |
f7c1be0c | 2529 | } |
bf3146c8 | 2530 | |
f7c1be0c | 2531 | default: |
bf3146c8 | 2532 | break; |
f7c1be0c MB |
2533 | } |
2534 | ||
2535 | } | |
2536 | ||
2a953cfd AB |
2537 | status = STATUS_SUCCESS; |
2538 | out: | |
2539 | kfree(cmdbuffer); | |
f7c1be0c | 2540 | DEBUG("return from ft1000_proc_drvmsg\n"); |
2a953cfd | 2541 | return status; |
f7c1be0c MB |
2542 | } |
2543 | ||
2544 | ||
2545 | ||
2546 | int ft1000_poll(void* dev_id) { | |
bf3146c8 | 2547 | |
f7c1be0c | 2548 | //FT1000_INFO *info = (PFT1000_INFO)((struct net_device *)dev_id)->priv; |
bf3146c8 | 2549 | //struct ft1000_device *dev = (struct ft1000_device *)info->pFt1000Dev; |
f7c1be0c MB |
2550 | struct ft1000_device *dev = (struct ft1000_device *)dev_id; |
2551 | FT1000_INFO *info = (FT1000_INFO *) netdev_priv (dev->net); | |
bf3146c8 | 2552 | |
f7c1be0c MB |
2553 | u16 tempword; |
2554 | u16 status; | |
2555 | u16 size; | |
2556 | int i; | |
bf3146c8 | 2557 | USHORT data; |
f7c1be0c MB |
2558 | USHORT modulo; |
2559 | USHORT portid; | |
2560 | u16 nxtph; | |
2561 | PDPRAM_BLK pdpram_blk; | |
2562 | PPSEUDO_HDR ppseudo_hdr; | |
2563 | unsigned long flags; | |
bf3146c8 | 2564 | |
f7c1be0c MB |
2565 | //DEBUG("Enter ft1000_poll...\n"); |
2566 | if (ft1000_chkcard(dev) == FALSE) { | |
2567 | DEBUG("ft1000_poll::ft1000_chkcard: failed\n"); | |
2568 | return STATUS_FAILURE; | |
2569 | } | |
2570 | ||
2571 | status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL); | |
2572 | // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword); | |
2573 | ||
bf3146c8 GKH |
2574 | //while ( (tempword) && (!status) ) { |
2575 | if ( !status ) | |
2576 | { | |
2577 | ||
f7c1be0c MB |
2578 | if (tempword & FT1000_DB_DPRAM_RX) { |
2579 | //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n"); | |
bf3146c8 | 2580 | |
f7c1be0c MB |
2581 | status = ft1000_read_dpram16(dev, 0x200, (PUCHAR)&data, 0); |
2582 | //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data); | |
2583 | size = ntohs(data) + 16 + 2; //wai | |
2584 | if (size % 4) { | |
2585 | modulo = 4 - (size % 4); | |
2586 | size = size + modulo; | |
bf3146c8 | 2587 | } |
f7c1be0c MB |
2588 | status = ft1000_read_dpram16(dev, 0x201, (PUCHAR)&portid, 1); |
2589 | portid &= 0xff; | |
2590 | //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid); | |
bf3146c8 | 2591 | |
f7c1be0c | 2592 | if (size < MAX_CMD_SQSIZE) { |
bf3146c8 | 2593 | switch (portid) |
f7c1be0c MB |
2594 | { |
2595 | case DRIVERID: | |
2596 | DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DRIVERID\n"); | |
bf3146c8 | 2597 | |
f7c1be0c MB |
2598 | status = ft1000_proc_drvmsg (dev, size); |
2599 | if (status != STATUS_SUCCESS ) | |
2600 | return status; | |
2601 | break; | |
2602 | case DSPBCMSGID: | |
2603 | // This is a dsp broadcast message | |
bf3146c8 | 2604 | // Check which application has registered for dsp broadcast messages |
f7c1be0c | 2605 | //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n"); |
bf3146c8 | 2606 | |
f7c1be0c | 2607 | for (i=0; i<MAX_NUM_APP; i++) { |
bf3146c8 GKH |
2608 | if ( (info->app_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) && |
2609 | (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT) ) | |
f7c1be0c MB |
2610 | { |
2611 | //DEBUG("Dsp broadcast message detected for app id %d\n", i); | |
2612 | nxtph = FT1000_DPRAM_RX_BASE + 2; | |
2613 | pdpram_blk = ft1000_get_buffer (&freercvpool); | |
2614 | if (pdpram_blk != NULL) { | |
2615 | if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) { | |
2616 | ppseudo_hdr = (PPSEUDO_HDR)pdpram_blk->pbuffer; | |
2617 | // Put message into the appropriate application block | |
2618 | info->app_info[i].nRxMsg++; | |
2619 | spin_lock_irqsave(&free_buff_lock, flags); | |
2620 | list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist); | |
2621 | info->app_info[i].NumOfMsg++; | |
2622 | spin_unlock_irqrestore(&free_buff_lock, flags); | |
2623 | wake_up_interruptible(&info->app_info[i].wait_dpram_msg); | |
2624 | } | |
2625 | else { | |
2626 | info->app_info[i].nRxMsgMiss++; | |
2627 | // Put memory back to free pool | |
2628 | ft1000_free_buffer(pdpram_blk, &freercvpool); | |
2629 | DEBUG("pdpram_blk::ft1000_get_buffer NULL\n"); | |
2630 | } | |
2631 | } | |
2632 | else { | |
2633 | DEBUG("Out of memory in free receive command pool\n"); | |
2634 | info->app_info[i].nRxMsgMiss++; | |
2635 | }//endof if (pdpram_blk != NULL) | |
bf3146c8 | 2636 | }//endof if |
f7c1be0c MB |
2637 | //else |
2638 | // DEBUG("app_info mismatch\n"); | |
2639 | }// endof for | |
2640 | break; | |
2641 | default: | |
2642 | pdpram_blk = ft1000_get_buffer (&freercvpool); | |
2643 | //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk); | |
2644 | if (pdpram_blk != NULL) { | |
2645 | if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) { | |
2646 | ppseudo_hdr = (PPSEUDO_HDR)pdpram_blk->pbuffer; | |
2647 | // Search for correct application block | |
2648 | for (i=0; i<MAX_NUM_APP; i++) { | |
2649 | if (info->app_info[i].app_id == ppseudo_hdr->portdest) { | |
2650 | break; | |
2651 | } | |
2652 | } | |
2653 | ||
2654 | if (i==(MAX_NUM_APP-1)) { // aelias [+] reason: was out of array boundary | |
2655 | info->app_info[i].nRxMsgMiss++; | |
2656 | DEBUG("FT1000:ft1000_parse_dpram_msg: No application matching id = %d\n", ppseudo_hdr->portdest); | |
2657 | // Put memory back to free pool | |
2658 | ft1000_free_buffer(pdpram_blk, &freercvpool); | |
2659 | } | |
2660 | else { | |
2661 | if (info->app_info[i].NumOfMsg > MAX_MSG_LIMIT) { | |
2662 | // Put memory back to free pool | |
2663 | ft1000_free_buffer(pdpram_blk, &freercvpool); | |
2664 | } | |
2665 | else { | |
2666 | info->app_info[i].nRxMsg++; | |
2667 | // Put message into the appropriate application block | |
2668 | //pxu spin_lock_irqsave(&free_buff_lock, flags); | |
2669 | list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist); | |
2670 | info->app_info[i].NumOfMsg++; | |
2671 | //pxu spin_unlock_irqrestore(&free_buff_lock, flags); | |
2672 | //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg); | |
2673 | } | |
2674 | } | |
2675 | } | |
2676 | else { | |
2677 | // Put memory back to free pool | |
2678 | ft1000_free_buffer(pdpram_blk, &freercvpool); | |
2679 | } | |
2680 | } | |
2681 | else { | |
2682 | DEBUG("Out of memory in free receive command pool\n"); | |
2683 | } | |
2684 | break; | |
2685 | } //end of switch | |
2686 | } //endof if (size < MAX_CMD_SQSIZE) | |
2687 | else { | |
2688 | DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size); | |
2689 | } | |
bf3146c8 | 2690 | status = ft1000_write_register (dev, FT1000_DB_DPRAM_RX, FT1000_REG_DOORBELL); |
f7c1be0c MB |
2691 | } |
2692 | else if (tempword & FT1000_DSP_ASIC_RESET) { | |
2693 | //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DSP_ASIC_RESET\n"); | |
2694 | ||
2695 | // Let's reset the ASIC from the Host side as well | |
2696 | status = ft1000_write_register (dev, ASIC_RESET_BIT, FT1000_REG_RESET); | |
2697 | status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET); | |
2698 | i = 0; | |
2699 | while (tempword & ASIC_RESET_BIT) { | |
2700 | status = ft1000_read_register (dev, &tempword, FT1000_REG_RESET); | |
2701 | msleep(10); | |
2702 | i++; | |
2703 | if (i==100) | |
2704 | break; | |
2705 | } | |
2706 | if (i==100) { | |
2707 | DEBUG("Unable to reset ASIC\n"); | |
2708 | return STATUS_SUCCESS; | |
2709 | } | |
2710 | msleep(10); | |
2711 | // Program WMARK register | |
2712 | status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK); | |
2713 | // clear ASIC reset doorbell | |
2714 | status = ft1000_write_register (dev, FT1000_DSP_ASIC_RESET, FT1000_REG_DOORBELL); | |
2715 | msleep(10); | |
2716 | } | |
2717 | else if (tempword & FT1000_ASIC_RESET_REQ) { | |
2718 | DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_ASIC_RESET_REQ\n"); | |
bf3146c8 | 2719 | |
f7c1be0c MB |
2720 | // clear ASIC reset request from DSP |
2721 | status = ft1000_write_register (dev, FT1000_ASIC_RESET_REQ, FT1000_REG_DOORBELL); | |
2722 | status = ft1000_write_register (dev, HOST_INTF_BE, FT1000_REG_SUP_CTRL); | |
2723 | // copy dsp session record from Adapter block | |
2724 | status = ft1000_write_dpram32 (dev, 0, (PUCHAR)&info->DSPSess.Rec[0], 1024); | |
2725 | // Program WMARK register | |
2726 | status = ft1000_write_register (dev, 0x600, FT1000_REG_MAG_WATERMARK); | |
bf3146c8 | 2727 | // ring doorbell to tell DSP that ASIC is out of reset |
f7c1be0c | 2728 | status = ft1000_write_register (dev, FT1000_ASIC_RESET_DSP, FT1000_REG_DOORBELL); |
bf3146c8 | 2729 | } |
f7c1be0c | 2730 | else if (tempword & FT1000_DB_COND_RESET) { |
bf3146c8 | 2731 | DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n"); |
f7c1be0c | 2732 | //By Jim |
bf3146c8 | 2733 | // Reset ASIC and DSP |
f7c1be0c MB |
2734 | //MAG |
2735 | if (info->fAppMsgPend == 0) { | |
bf3146c8 GKH |
2736 | // Reset ASIC and DSP |
2737 | ||
f7c1be0c MB |
2738 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (PUCHAR)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX); |
2739 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER1, (PUCHAR)&(info->DSP_TIME[1]), FT1000_MAG_DSP_TIMER1_INDX); | |
2740 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER2, (PUCHAR)&(info->DSP_TIME[2]), FT1000_MAG_DSP_TIMER2_INDX); | |
bf3146c8 GKH |
2741 | status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER3, (PUCHAR)&(info->DSP_TIME[3]), FT1000_MAG_DSP_TIMER3_INDX); |
2742 | info->CardReady = 0; | |
f7c1be0c MB |
2743 | info->DrvErrNum = DSP_CONDRESET_INFO; |
2744 | DEBUG("ft1000_hw:DSP conditional reset requested\n"); | |
2745 | info->ft1000_reset(dev->net); | |
2746 | } | |
2747 | else { | |
2748 | info->fProvComplete = 0; | |
2749 | info->fCondResetPend = 1; | |
2750 | } | |
bf3146c8 GKH |
2751 | |
2752 | ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL); | |
f7c1be0c | 2753 | } |
bf3146c8 | 2754 | |
f7c1be0c MB |
2755 | }//endof if ( !status ) |
2756 | ||
2757 | //DEBUG("return from ft1000_poll.\n"); | |
2758 | return STATUS_SUCCESS; | |
2759 | ||
2760 | } | |
2761 | ||
2762 | /*end of Jim*/ |