staging/ft1000-usb: fix problems found by sparse
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / ft1000 / ft1000-usb / ft1000_usb.h
blobb0ab91856d8428121b8aedbd83a0c6e507d6e163
1 #ifndef _FT1000_USB_H_
2 #define _FT1000_USB_H_
4 /*Jim*/
5 #include "ft1000_ioctl.h"
6 #define FT1000_DRV_VER 0x01010403
8 #define MODESZ 2
9 #define MAX_NUM_APP 6
10 #define MAX_MSG_LIMIT 200
11 #define NUM_OF_FREE_BUFFERS 1500
13 // Driver message types
14 #define MEDIA_STATE 0x0010
15 #define DSP_PROVISION 0x0030
16 #define DSP_INIT_MSG 0x0050
17 #define DSP_STORE_INFO 0x0070
18 #define DSP_GET_INFO 0x0071
19 #define GET_DRV_ERR_RPT_MSG 0x0073
20 #define RSP_DRV_ERR_RPT_MSG 0x0074
23 // Size of DPRAM Command
24 #define MAX_CMD_SQSIZE 1780
25 #define SLOWQ_TYPE 0
26 #define PSEUDOSZ 16
27 #define DSP_QID_OFFSET 4
30 // MEMORY MAP FOR ELECTRABUZZ ASIC
31 #define FT1000_REG_DFIFO_STAT 0x0008 // Downlink FIFO status register
32 #define FT1000_REG_DPRAM_DATA 0x000C // DPRAM VALUE in DPRAM ADDR
34 #define FT1000_DSP_LED 0xFFA // dsp led status for PAD device
36 #define FT1000_MAG_DSP_LED 0x3FE // dsp led status for PAD device
37 #define FT1000_MAG_DSP_LED_INDX 0x1 // dsp led status for PAD device
39 #define SUCCESS 0x00
42 #define DRIVERID 0x00
44 // Driver Error Messages for DSP
45 #define DSP_CONDRESET_INFO 0x7ef2
46 #define DSP_HB_INFO 0x7ef0
48 // Magnemite specific defines
49 #define hi_mag 0x6968 // Byte swap hi to avoid additional system call
50 #define ho_mag 0x6f68 // Byte swap ho to avoid additional system call
54 typedef struct _MEDIAMSG {
55 PSEUDO_HDR pseudo;
56 u16 type;
57 u16 length;
58 u16 state;
59 u32 ip_addr;
60 u32 net_mask;
61 u32 gateway;
62 u32 dns_1;
63 u32 dns_2;
64 } __attribute__ ((packed)) MEDIAMSG, *PMEDIAMSG;
66 typedef struct _DSPINITMSG {
67 PSEUDO_HDR pseudo;
68 u16 type;
69 u16 length;
70 u8 DspVer[DSPVERSZ]; // DSP version number
71 u8 HwSerNum[HWSERNUMSZ]; // Hardware Serial Number
72 u8 Sku[SKUSZ]; // SKU
73 u8 eui64[EUISZ]; // EUI64
74 u8 ProductMode[MODESZ]; // Product Mode (Market/Production)
75 u8 RfCalVer[CALVERSZ]; // Rf Calibration version
76 u8 RfCalDate[CALDATESZ]; // Rf Calibration date
77 } __attribute__ ((packed)) DSPINITMSG, *PDSPINITMSG;
80 typedef struct _APP_INFO_BLOCK
82 u32 nTxMsg; // DPRAM msg sent to DSP with app_id
83 u32 nRxMsg; // DPRAM msg rcv from dsp with app_id
84 u32 nTxMsgReject; // DPRAM msg rejected due to DSP doorbell set
85 u32 nRxMsgMiss; // DPRAM msg dropped due to overflow
86 struct fown_struct *fileobject;// Application's file object
87 u16 app_id; // Application id
88 int DspBCMsgFlag;
89 int NumOfMsg; // number of messages queued up
90 wait_queue_head_t wait_dpram_msg;
91 struct list_head app_sqlist; // link list of msgs for applicaton on slow queue
92 } APP_INFO_BLOCK, *PAPP_INFO_BLOCK;
94 typedef struct _PROV_RECORD {
95 struct list_head list;
96 u8 *pprov_data;
97 } PROV_RECORD, *PPROV_RECORD;
99 /*end of Jim*/
101 #define DEBUG(args...) printk(KERN_INFO args)
103 #define UCHAR u8
104 #define USHORT u16
105 #define ULONG u32 /* WTF ??? */
106 #define BOOLEAN u8
107 #define PULONG u32 *
108 #define PUSHORT u16 *
109 #define PUCHAR u8 *
110 #define PCHAR u8 *
111 #define UINT u32
113 #define FALSE 0
114 #define TRUE 1
116 #define STATUS_SUCCESS 0
117 #define STATUS_FAILURE 0x1001
119 #define FT1000_STATUS_CLOSING 0x01
121 #define LARGE_TIMEOUT 5000
123 #define MAX_DSP_SESS_REC 1024
125 #define MAX_NUM_CARDS 32
127 #define DSPVERSZ 4
128 #define HWSERNUMSZ 16
129 #define SKUSZ 20
130 #define EUISZ 8
131 #define CALVERSZ 2
132 #define CALDATESZ 6
133 #define MODESZ 2
135 #define DSPID 0x20
136 #define HOSTID 0x10
138 #define DSPOAM 0x80
139 #define DSPAIRID 0x90
141 #define DRIVERID 0x00
142 #define FMM 0x10
143 #define NETWORKID 0x20
144 #define AUTOLNCHID 0x30
145 #define DSPLPBKID 0x40
147 #define DSPBCMSGID 0x10
149 #define ENET_MAX_SIZE 1514
150 #define ENET_HEADER_SIZE 14
153 #define CIS_NET_ADDR_OFFSET 0xff0
155 // MAGNEMITE specific
157 #define FT1000_REG_MAG_UFDR 0x0000 // Uplink FIFO Data Register.
159 #define FT1000_REG_MAG_UFDRL 0x0000 // Uplink FIFO Data Register low-word.
161 #define FT1000_REG_MAG_UFDRH 0x0002 // Uplink FIFO Data Register high-word.
163 #define FT1000_REG_MAG_UFER 0x0004 // Uplink FIFO End Register
165 #define FT1000_REG_MAG_UFSR 0x0006 // Uplink FIFO Status Register
167 #define FT1000_REG_MAG_DFR 0x0008 // Downlink FIFO Register
169 #define FT1000_REG_MAG_DFRL 0x0008 // Downlink FIFO Register low-word
171 #define FT1000_REG_MAG_DFRH 0x000a // Downlink FIFO Register high-word
173 #define FT1000_REG_MAG_DFSR 0x000c // Downlink FIFO Status Register
175 #define FT1000_REG_MAG_DPDATA 0x0010 // Dual Port RAM Indirect Data Register
177 #define FT1000_REG_MAG_DPDATAL 0x0010 // Dual Port RAM Indirect Data Register low-word
179 #define FT1000_REG_MAG_DPDATAH 0x0012 // Dual Port RAM Indirect Data Register high-word
181 #define FT1000_REG_MAG_WATERMARK 0x002c // Supv. Control Reg. LLC register
183 #define FT1000_REG_MAG_VERSION 0x0030 // LLC Version LLC register
187 // Common
189 #define FT1000_REG_DPRAM_ADDR 0x000E // DPRAM ADDRESS when card in IO mode
191 #define FT1000_REG_SUP_CTRL 0x0020 // Supv. Control Reg. LLC register
193 #define FT1000_REG_SUP_STAT 0x0022 // Supv. Status Reg LLC register
195 #define FT1000_REG_RESET 0x0024 // Reset Reg LLC register
197 #define FT1000_REG_SUP_ISR 0x0026 // Supv ISR LLC register
199 #define FT1000_REG_SUP_IMASK 0x0028 // Supervisor Interrupt Mask LLC register
201 #define FT1000_REG_DOORBELL 0x002a // Door Bell Reg LLC register
203 #define FT1000_REG_ASIC_ID 0x002e // ASIC Identification Number
205 // (Electrabuzz=0 Magnemite=TBD)
209 // DSP doorbells
211 #define FT1000_DB_DPRAM_RX 0x0001 // this value indicates that DSP has
213 // data for host in DPRAM SlowQ
215 #define FT1000_DB_DNLD_RX 0x0002 // Downloader handshake doorbell
217 #define FT1000_ASIC_RESET_REQ 0x0004
219 #define FT1000_DSP_ASIC_RESET 0x0008
223 #define FT1000_DB_COND_RESET 0x0010
227 // Host doorbells
229 #define FT1000_DB_DPRAM_TX 0x0100 // this value indicates that host has
231 // data for DSP in DPRAM.
233 #define FT1000_DB_DNLD_TX 0x0200 // Downloader handshake doorbell
235 #define FT1000_ASIC_RESET_DSP 0x0400
237 #define FT1000_DB_HB 0x1000 // this value indicates that supervisor
241 // Electrabuzz specific DPRAM mapping // has a heartbeat message for DSP.
243 #define FT1000_DPRAM_BASE 0x1000 // 0x0000 to 0x07FF DPRAM 2Kx16 - R/W from PCMCIA or DSP
245 #define FT1000_DPRAM_TX_BASE 0x1002 // TX AREA (SlowQ)
247 #define FT1000_DPRAM_RX_BASE 0x1800 // RX AREA (SlowQ)
249 #define FT1000_DPRAM_SIZE 0x1000 // 4K bytes
253 #define FT1000_DRV_DEBUG 0x17E0 // Debug area for driver
255 #define FT1000_FIFO_LEN 0x17FC // total length for DSP FIFO tracking
257 #define FT1000_HI_HO 0x17FE // heartbeat with HI/HO
259 #define FT1000_DSP_STATUS 0x1FFE // dsp status - non-zero is a request to reset dsp
263 #define FT1000_DSP_CON_STATE 0x1FF8 // DSP Connection Status Info
265 #define FT1000_DSP_LEDS 0x1FFA // DSP LEDS for rcv pwr strength, Rx data, Tx data
267 #define DSP_TIMESTAMP 0x1FFC // dsp timestamp
269 #define DSP_TIMESTAMP_DIFF 0x1FFA // difference of dsp timestamp in DPRAM and Pseudo header.
273 #define FT1000_DPRAM_FEFE 0x1002 // Dsp Downloader handshake location
277 #define FT1000_DSP_TIMER0 0x1FF0
279 #define FT1000_DSP_TIMER1 0x1FF2
281 #define FT1000_DSP_TIMER2 0x1FF4
283 #define FT1000_DSP_TIMER3 0x1FF6
287 // MEMORY MAP FOR MAGNEMITE
289 #define FT1000_DPRAM_MAG_TX_BASE 0x0000 // TX AREA (SlowQ)
291 #define FT1000_DPRAM_MAG_RX_BASE 0x0200 // RX AREA (SlowQ)
295 #define FT1000_MAG_FIFO_LEN 0x1FF // total length for DSP FIFO tracking
297 #define FT1000_MAG_FIFO_LEN_INDX 0x1 // low-word index
299 #define FT1000_MAG_HI_HO 0x1FF // heartbeat with HI/HO
301 #define FT1000_MAG_HI_HO_INDX 0x0 // high-word index
303 #define FT1000_MAG_DSP_LEDS 0x3FE // dsp led status for PAD device
305 #define FT1000_MAG_DSP_LEDS_INDX 0x1 // dsp led status for PAD device
309 #define FT1000_MAG_DSP_CON_STATE 0x3FE // DSP Connection Status Info
311 #define FT1000_MAG_DSP_CON_STATE_INDX 0x0 // DSP Connection Status Info
315 #define FT1000_MAG_DPRAM_FEFE 0x000 // location for dsp ready indicator
317 #define FT1000_MAG_DPRAM_FEFE_INDX 0x0 // location for dsp ready indicator
321 #define FT1000_MAG_DSP_TIMER0 0x3FC
323 #define FT1000_MAG_DSP_TIMER0_INDX 0x1
327 #define FT1000_MAG_DSP_TIMER1 0x3FC
329 #define FT1000_MAG_DSP_TIMER1_INDX 0x0
333 #define FT1000_MAG_DSP_TIMER2 0x3FD
335 #define FT1000_MAG_DSP_TIMER2_INDX 0x1
339 #define FT1000_MAG_DSP_TIMER3 0x3FD
341 #define FT1000_MAG_DSP_TIMER3_INDX 0x0
345 #define FT1000_MAG_TOTAL_LEN 0x200
347 #define FT1000_MAG_TOTAL_LEN_INDX 0x1
351 #define FT1000_MAG_PH_LEN 0x200
353 #define FT1000_MAG_PH_LEN_INDX 0x0
357 #define FT1000_MAG_PORT_ID 0x201
359 #define FT1000_MAG_PORT_ID_INDX 0x0
365 // Constants for the FT1000_REG_SUP_ISR
369 // Indicate the cause of an interrupt.
373 // SUPERVISOR ISR BIT MAPS
377 #define ISR_EMPTY (UCHAR)0x00 // no bits set in ISR
379 #define ISR_DOORBELL_ACK (UCHAR)0x01 // the doorbell i sent has been recieved.
381 #define ISR_DOORBELL_PEND (UCHAR)0x02 // doorbell for me
383 #define ISR_RCV (UCHAR)0x04 // packet received with no errors
385 #define ISR_WATERMARK (UCHAR)0x08 //
389 // Interrupt mask register defines
391 // note these are different from the ISR BIT MAPS.
393 #define ISR_MASK_NONE 0x0000
395 #define ISR_MASK_DOORBELL_ACK 0x0001
397 #define ISR_MASK_DOORBELL_PEND 0x0002
399 #define ISR_MASK_RCV 0x0004
401 #define ISR_MASK_WATERMARK 0x0008 // Normally we will only mask the watermark interrupt when we want to enable interrupts.
403 #define ISR_MASK_ALL 0xffff
407 #define HOST_INTF_LE 0x0000 // Host interface little endian
409 #define HOST_INTF_BE 0x0001 // Host interface big endian
413 #define ISR_DEFAULT_MASK 0x7ff9
417 #define hi 0x6869
419 #define ho 0x686f
423 #define FT1000_ASIC_RESET 0x80 // COR value for soft reset to PCMCIA core
425 #define FT1000_ASIC_BITS 0x51 // Bits set in COR register under normal operation
427 #define FT1000_ASIC_MAG_BITS 0x55 // Bits set in COR register under normal operation
431 #define FT1000_COR_OFFSET 0x100
435 #define ELECTRABUZZ_ID 0 // ASIC ID for ELECTRABUZZ
437 #define MAGNEMITE_ID 0x1a01 // ASIC ID for MAGNEMITE
441 // Maximum times trying to get ASIC out of reset
443 #define MAX_ASIC_RESET_CNT 20
447 #define DSP_RESET_BIT 0x1
449 #define ASIC_RESET_BIT 0x2
451 #define DSP_UNENCRYPTED 0x4
453 #define DSP_ENCRYPTED 0x8
455 #define EFUSE_MEM_DISABLE 0x0040
458 #define MAX_BUF_SIZE 4096
461 #if 0 //Removed by Jim
462 typedef struct _PSEUDO_HDR
466 unsigned short length;
468 unsigned char source;
470 unsigned char destination;
472 unsigned char portdest;
474 unsigned char portsrc;
476 unsigned short sh_str_id;
478 unsigned char control;
480 unsigned char rsvd1;
482 unsigned char seq_num;
484 unsigned char rsvd2;
486 unsigned short qos_class;
488 unsigned short checksum;
492 } PSEUDO_HDR, *PPSEUDO_HDR;
493 #endif //end of Jim
495 typedef struct _DRVMSG {
496 PSEUDO_HDR pseudo;
497 u16 type;
498 u16 length;
499 u8 data[0];
500 } __attribute__ ((packed)) DRVMSG, *PDRVMSG;
502 struct ft1000_device
504 struct usb_device *dev;
505 struct net_device *net;
506 spinlock_t device_lock;
508 u32 status;
510 wait_queue_head_t control_wait;
512 struct urb *rx_urb;
513 struct urb *tx_urb;
515 u8 tx_buf[MAX_BUF_SIZE];
516 u8 rx_buf[MAX_BUF_SIZE];
518 u8 bulk_in_endpointAddr;
519 u8 bulk_out_endpointAddr;
521 //struct ft1000_ethernet_configuration configuration;
523 // struct net_device_stats stats; //mbelian
524 } __attribute__ ((packed));
526 typedef struct _FT1000_INFO {
527 struct ft1000_device *pFt1000Dev;
528 struct net_device_stats stats;
530 struct task_struct *pPollThread;
532 unsigned char fcodeldr;
533 unsigned char bootmode;
534 unsigned char usbboot;
535 unsigned short dspalive;
536 u16 ASIC_ID;
537 BOOLEAN fProvComplete;
538 BOOLEAN fCondResetPend;
539 BOOLEAN fAppMsgPend;
540 char *pfwimg;
541 int fwimgsz;
542 u16 DrvErrNum;
543 u8 *pTestImage;
544 u16 AsicID;
545 unsigned long TestImageIndx;
546 unsigned long TestImageSz;
547 u8 TestImageEnable;
548 u8 TestImageReady;
549 int ASICResetNum;
550 int DspAsicReset;
551 int PktIntfErr;
552 int DSPResetNum;
553 int NumIOCTLBufs;
554 int IOCTLBufLvl;
555 int DeviceCreated;
556 int CardReady;
557 int DSP_loading;
558 int NetDevRegDone;
559 u8 CardNumber;
560 u8 DeviceName[15];
561 int DeviceMajor;
562 int registered;
563 int mediastate;
564 int dhcpflg;
565 u16 packetseqnum;
566 u8 squeseqnum; // sequence number on slow queue
567 spinlock_t dpram_lock;
568 spinlock_t fifo_lock;
569 u16 CurrentInterruptEnableMask;
570 int InterruptsEnabled;
571 u16 fifo_cnt;
572 u8 DspVer[DSPVERSZ]; // DSP version number
573 u8 HwSerNum[HWSERNUMSZ]; // Hardware Serial Number
574 u8 Sku[SKUSZ]; // SKU
575 u8 eui64[EUISZ]; // EUI64
576 time_t ConTm; // Connection Time
577 u8 ProductMode[MODESZ];
578 u8 RfCalVer[CALVERSZ];
579 u8 RfCalDate[CALDATESZ];
580 u16 DSP_TIME[4];
581 u16 ProgSnr;
582 u16 LedStat; //mbelian
583 u16 ConStat; //mbelian
584 u16 ProgConStat;
585 struct list_head prov_list;
586 int appcnt;
587 APP_INFO_BLOCK app_info[MAX_NUM_APP]; //Added by Jim
588 u16 DSPInfoBlklen;
589 u16 DrvMsgPend;
590 int (*ft1000_reset)(struct net_device *dev);
591 u16 DSPInfoBlk[MAX_DSP_SESS_REC];
592 union {
593 u16 Rec[MAX_DSP_SESS_REC];
594 u32 MagRec[MAX_DSP_SESS_REC/2];
595 } DSPSess;
596 unsigned short tempbuf[32];
597 char netdevname[IFNAMSIZ];
598 struct proc_dir_entry *ft1000_proc_dir; //mbelian
599 } FT1000_INFO, *PFT1000_INFO;
602 typedef struct _DPRAM_BLK {
603 struct list_head list;
604 u16 *pbuffer;
605 } __attribute__ ((packed)) DPRAM_BLK, *PDPRAM_BLK;
607 u16 ft1000_read_register(struct ft1000_device *ft1000dev, u16* Data, u16 nRegIndx);
608 u16 ft1000_write_register(struct ft1000_device *ft1000dev, USHORT value, u16 nRegIndx);
609 u16 ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt);
610 u16 ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, USHORT cnt);
611 u16 ft1000_read_dpram16(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer, u8 highlow);
612 u16 ft1000_write_dpram16(struct ft1000_device *ft1000dev, USHORT indx, USHORT value, u8 highlow);
613 u16 fix_ft1000_read_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer);
614 u16 fix_ft1000_write_dpram32(struct ft1000_device *ft1000dev, USHORT indx, PUCHAR buffer);
616 extern void *pFileStart;
617 extern size_t FileLength;
618 extern int numofmsgbuf;
620 int ft1000_close (struct net_device *dev);
621 u16 scram_dnldr(struct ft1000_device *ft1000dev, void *pFileStart, ULONG FileLength);
623 extern struct list_head freercvpool;
624 extern spinlock_t free_buff_lock; // lock to arbitrate free buffer list for receive command data
626 int ft1000_CreateDevice(struct ft1000_device *dev);
627 void ft1000_DestroyDevice(struct net_device *dev);
628 extern void CardSendCommand(struct ft1000_device *ft1000dev, void *ptempbuffer, int size);
630 PDPRAM_BLK ft1000_get_buffer (struct list_head *bufflist);
631 void ft1000_free_buffer (PDPRAM_BLK pdpram_blk, struct list_head *plist);
633 char *getfw (char *fn, size_t *pimgsz);
635 void dsp_reload(struct ft1000_device *ft1000dev);
636 u16 init_ft1000_netdev(struct ft1000_device *ft1000dev);
637 struct usb_interface;
638 u16 reg_ft1000_netdev(struct ft1000_device *ft1000dev, struct usb_interface *intf);
639 int ft1000_poll(void* dev_id);
641 void ft1000InitProc(struct net_device *dev);
642 void ft1000CleanupProc(FT1000_INFO *info);
646 #endif