1/***********************************
2*	Adapter.h
3************************************/
4#ifndef	__ADAPTER_H__
5#define	__ADAPTER_H__
6
7#define MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES 256
8#include "Debug.h"
9
10struct bcm_leader {
11	USHORT	Vcid;
12	USHORT	PLength;
13	UCHAR	Status;
14	UCHAR	Unused[3];
15} __packed;
16
17struct bcm_packettosend {
18	struct bcm_leader Leader;
19	UCHAR	ucPayload;
20} __packed;
21
22struct bcm_control_packet {
23	PVOID	ControlBuff;
24	UINT	ControlBuffLen;
25	struct bcm_control_packet *next;
26} __packed;
27
28struct bcm_link_request {
29	struct bcm_leader Leader;
30	UCHAR	szData[4];
31} __packed;
32
33#define MAX_IP_RANGE_LENGTH 4
34#define MAX_PORT_RANGE 4
35#define MAX_PROTOCOL_LENGTH   32
36#define IPV6_ADDRESS_SIZEINBYTES 0x10
37
38union u_ip_address {
39	struct {
40		/* Source Ip Address Range */
41		ULONG ulIpv4Addr[MAX_IP_RANGE_LENGTH];
42		 /* Source Ip Mask Address Range */
43		ULONG ulIpv4Mask[MAX_IP_RANGE_LENGTH];
44	};
45	struct {
46		/* Source Ip Address Range */
47		ULONG ulIpv6Addr[MAX_IP_RANGE_LENGTH * 4];
48		/* Source Ip Mask Address Range */
49		ULONG ulIpv6Mask[MAX_IP_RANGE_LENGTH * 4];
50	};
51	struct {
52		UCHAR ucIpv4Address[MAX_IP_RANGE_LENGTH * IP_LENGTH_OF_ADDRESS];
53		UCHAR ucIpv4Mask[MAX_IP_RANGE_LENGTH * IP_LENGTH_OF_ADDRESS];
54	};
55	struct {
56		UCHAR ucIpv6Address[MAX_IP_RANGE_LENGTH * IPV6_ADDRESS_SIZEINBYTES];
57		UCHAR ucIpv6Mask[MAX_IP_RANGE_LENGTH * IPV6_ADDRESS_SIZEINBYTES];
58	};
59};
60
61struct bcm_hdr_suppression_contextinfo {
62	/* Intermediate buffer to accumulate pkt Header for PHS */
63	UCHAR ucaHdrSuppressionInBuf[MAX_PHS_LENGTHS];
64	/* Intermediate buffer containing pkt Header after PHS */
65	UCHAR ucaHdrSuppressionOutBuf[MAX_PHS_LENGTHS + PHSI_LEN];
66};
67
68struct bcm_classifier_rule {
69	ULONG		ulSFID;
70	UCHAR		ucReserved[2];
71	B_UINT16	uiClassifierRuleIndex;
72	bool		bUsed;
73	USHORT		usVCID_Value;
74	/* This field detemines the Classifier Priority */
75	B_UINT8		u8ClassifierRulePriority;
76	union u_ip_address	stSrcIpAddress;
77	UCHAR		ucIPSourceAddressLength; /* Ip Source Address Length */
78
79	union u_ip_address	stDestIpAddress;
80	/* Ip Destination Address Length */
81	UCHAR		ucIPDestinationAddressLength;
82	UCHAR		ucIPTypeOfServiceLength; /* Type of service Length */
83	UCHAR		ucTosLow; /* Tos Low */
84	UCHAR		ucTosHigh; /* Tos High */
85	UCHAR		ucTosMask; /* Tos Mask */
86
87	UCHAR		ucProtocolLength; /* protocol Length */
88	UCHAR		ucProtocol[MAX_PROTOCOL_LENGTH]; /* protocol Length */
89	USHORT		usSrcPortRangeLo[MAX_PORT_RANGE];
90	USHORT		usSrcPortRangeHi[MAX_PORT_RANGE];
91	UCHAR		ucSrcPortRangeLength;
92
93	USHORT		usDestPortRangeLo[MAX_PORT_RANGE];
94	USHORT		usDestPortRangeHi[MAX_PORT_RANGE];
95	UCHAR		ucDestPortRangeLength;
96
97	bool		bProtocolValid;
98	bool		bTOSValid;
99	bool		bDestIpValid;
100	bool		bSrcIpValid;
101
102	/* For IPv6 Addressing */
103	UCHAR		ucDirection;
104	bool		bIpv6Protocol;
105	UINT32		u32PHSRuleID;
106	struct bcm_phs_rule sPhsRule;
107	UCHAR		u8AssociatedPHSI;
108
109	/* Classification fields for ETH CS */
110	UCHAR		ucEthCSSrcMACLen;
111	UCHAR		au8EThCSSrcMAC[MAC_ADDRESS_SIZE];
112	UCHAR		au8EThCSSrcMACMask[MAC_ADDRESS_SIZE];
113	UCHAR		ucEthCSDestMACLen;
114	UCHAR		au8EThCSDestMAC[MAC_ADDRESS_SIZE];
115	UCHAR		au8EThCSDestMACMask[MAC_ADDRESS_SIZE];
116	UCHAR		ucEtherTypeLen;
117	UCHAR		au8EthCSEtherType[NUM_ETHERTYPE_BYTES];
118	UCHAR		usUserPriority[2];
119	USHORT		usVLANID;
120	USHORT		usValidityBitMap;
121};
122
123struct bcm_fragmented_packet_info {
124	bool			bUsed;
125	ULONG			ulSrcIpAddress;
126	USHORT			usIpIdentification;
127	struct bcm_classifier_rule *pstMatchedClassifierEntry;
128	bool			bOutOfOrderFragment;
129};
130
131struct bcm_packet_info {
132	/* classification extension Rule */
133	ULONG		ulSFID;
134	USHORT		usVCID_Value;
135	UINT		uiThreshold;
136	/* This field determines the priority of the SF Queues */
137	B_UINT8		u8TrafficPriority;
138
139	bool		bValid;
140	bool		bActive;
141	bool		bActivateRequestSent;
142
143	B_UINT8		u8QueueType; /* BE or rtPS */
144
145	/* maximum size of the bucket for the queue */
146	UINT		uiMaxBucketSize;
147	UINT		uiCurrentQueueDepthOnTarget;
148	UINT		uiCurrentBytesOnHost;
149	UINT		uiCurrentPacketsOnHost;
150	UINT		uiDroppedCountBytes;
151	UINT		uiDroppedCountPackets;
152	UINT		uiSentBytes;
153	UINT		uiSentPackets;
154	UINT		uiCurrentDrainRate;
155	UINT		uiThisPeriodSentBytes;
156	LARGE_INTEGER	liDrainCalculated;
157	UINT		uiCurrentTokenCount;
158	LARGE_INTEGER	liLastUpdateTokenAt;
159	UINT		uiMaxAllowedRate;
160	UINT		NumOfPacketsSent;
161	UCHAR		ucDirection;
162	USHORT		usCID;
163	struct bcm_mibs_parameters stMibsExtServiceFlowTable;
164	UINT		uiCurrentRxRate;
165	UINT		uiThisPeriodRxBytes;
166	UINT		uiTotalRxBytes;
167	UINT		uiTotalTxBytes;
168	UINT		uiPendedLast;
169	UCHAR		ucIpVersion;
170
171	union {
172		struct {
173			struct sk_buff *FirstTxQueue;
174			struct sk_buff *LastTxQueue;
175		};
176		struct {
177			struct sk_buff *ControlHead;
178			struct sk_buff *ControlTail;
179		};
180	};
181
182	bool		bProtocolValid;
183	bool		bTOSValid;
184	bool		bDestIpValid;
185	bool		bSrcIpValid;
186
187	bool		bActiveSet;
188	bool		bAdmittedSet;
189	bool		bAuthorizedSet;
190	bool		bClassifierPriority;
191	UCHAR		ucServiceClassName[MAX_CLASS_NAME_LENGTH];
192	bool		bHeaderSuppressionEnabled;
193	spinlock_t	SFQueueLock;
194	void		*pstSFIndication;
195	struct timeval	stLastUpdateTokenAt;
196	atomic_t	uiPerSFTxResourceCount;
197	UINT		uiMaxLatency;
198	UCHAR		bIPCSSupport;
199	UCHAR		bEthCSSupport;
200};
201
202struct bcm_tarang_data {
203	struct bcm_tarang_data	*next;
204	struct bcm_mini_adapter	*Adapter;
205	struct sk_buff		*RxAppControlHead;
206	struct sk_buff		*RxAppControlTail;
207	int			AppCtrlQueueLen;
208	bool			MacTracingEnabled;
209	bool			bApplicationToExit;
210	struct bcm_mibs_dropped_cntrl_msg stDroppedAppCntrlMsgs;
211	ULONG			RxCntrlMsgBitMask;
212};
213
214struct bcm_targetdsx_buffer {
215	ULONG		ulTargetDsxBuffer;
216	B_UINT16	tid;
217	bool		valid;
218};
219
220typedef int (*FP_FLASH_WRITE)(struct bcm_mini_adapter *, UINT, PVOID);
221
222typedef int (*FP_FLASH_WRITE_STATUS)(struct bcm_mini_adapter *, UINT, PVOID);
223
224/*
225 * Driver adapter data structure
226 */
227struct bcm_mini_adapter {
228	struct bcm_mini_adapter	*next;
229	struct net_device	*dev;
230	u32			msg_enable;
231	CHAR			*caDsxReqResp;
232	atomic_t		ApplicationRunning;
233	bool			AppCtrlQueueOverFlow;
234	atomic_t		CurrentApplicationCount;
235	atomic_t		RegisteredApplicationCount;
236	bool			LinkUpStatus;
237	bool			TimerActive;
238	u32			StatisticsPointer;
239	struct sk_buff		*RxControlHead;
240	struct sk_buff		*RxControlTail;
241	struct semaphore	RxAppControlQueuelock;
242	struct semaphore	fw_download_sema;
243	struct bcm_tarang_data	*pTarangs;
244	spinlock_t		control_queue_lock;
245	wait_queue_head_t	process_read_wait_queue;
246
247	/* the pointer to the first packet we have queued in send
248	 * deserialized miniport support variables
249	 */
250	atomic_t		TotalPacketCount;
251	atomic_t		TxPktAvail;
252
253	/* this to keep track of the Tx and Rx MailBox Registers. */
254	atomic_t		CurrNumFreeTxDesc;
255	/* to keep track the no of byte received */
256	USHORT			PrevNumRecvDescs;
257	USHORT			CurrNumRecvDescs;
258	UINT			u32TotalDSD;
259	struct bcm_packet_info	PackInfo[NO_OF_QUEUES];
260	struct bcm_classifier_rule astClassifierTable[MAX_CLASSIFIERS];
261	bool			TransferMode;
262
263	/*************** qos ******************/
264	bool			bETHCSEnabled;
265	ULONG			BEBucketSize;
266	ULONG			rtPSBucketSize;
267	UCHAR			LinkStatus;
268	bool			AutoLinkUp;
269	bool			AutoSyncup;
270
271	int			major;
272	int			minor;
273	wait_queue_head_t	tx_packet_wait_queue;
274	wait_queue_head_t	process_rx_cntrlpkt;
275	atomic_t		process_waiting;
276	bool			fw_download_done;
277
278	char			*txctlpacket[MAX_CNTRL_PKTS];
279	atomic_t		cntrlpktCnt;
280	atomic_t		index_app_read_cntrlpkt;
281	atomic_t		index_wr_txcntrlpkt;
282	atomic_t		index_rd_txcntrlpkt;
283	UINT			index_datpkt;
284	struct semaphore	rdmwrmsync;
285
286	struct bcm_targetdsx_buffer	astTargetDsxBuffer[MAX_TARGET_DSX_BUFFERS];
287	ULONG			ulFreeTargetBufferCnt;
288	ULONG			ulCurrentTargetBuffer;
289	ULONG			ulTotalTargetBuffersAvailable;
290	unsigned long		chip_id;
291	wait_queue_head_t	lowpower_mode_wait_queue;
292	bool			bFlashBoot;
293	bool			bBinDownloaded;
294	bool			bCfgDownloaded;
295	bool			bSyncUpRequestSent;
296	USHORT			usBestEffortQueueIndex;
297	wait_queue_head_t	ioctl_fw_dnld_wait_queue;
298	bool			waiting_to_fw_download_done;
299	pid_t			fw_download_process_pid;
300	struct bcm_target_params *pstargetparams;
301	bool			device_removed;
302	bool			DeviceAccess;
303	bool			bIsAutoCorrectEnabled;
304	bool			bDDRInitDone;
305	int			DDRSetting;
306	ULONG			ulPowerSaveMode;
307	spinlock_t		txtransmitlock;
308	B_UINT8			txtransmit_running;
309	/* Thread for control packet handling */
310	struct task_struct	*control_packet_handler;
311	/* thread for transmitting packets. */
312	struct task_struct	*transmit_packet_thread;
313
314	/* LED Related Structures */
315	struct bcm_led_info	LEDInfo;
316
317	/* Driver State for LED Blinking */
318	enum bcm_led_events	DriverState;
319	/* Interface Specific */
320	PVOID			pvInterfaceAdapter;
321	int (*bcm_file_download)(PVOID,
322				struct file *,
323				unsigned int);
324	int (*bcm_file_readback_from_chip)(PVOID,
325					struct file *,
326					unsigned int);
327	int (*interface_rdm)(PVOID,
328			UINT,
329			PVOID,
330			int);
331	int (*interface_wrm)(PVOID,
332			UINT,
333			PVOID,
334			int);
335	int (*interface_transmit)(PVOID, PVOID , UINT);
336	bool			IdleMode;
337	bool			bDregRequestSentInIdleMode;
338	bool			bTriedToWakeUpFromlowPowerMode;
339	bool			bShutStatus;
340	bool			bWakeUpDevice;
341	unsigned int		usIdleModePattern;
342	/* BOOLEAN			bTriedToWakeUpFromShutdown; */
343	bool			bLinkDownRequested;
344	int			downloadDDR;
345	struct bcm_phs_extension stBCMPhsContext;
346	struct bcm_hdr_suppression_contextinfo stPhsTxContextInfo;
347	uint8_t			ucaPHSPktRestoreBuf[2048];
348	uint8_t			bPHSEnabled;
349	bool			AutoFirmDld;
350	bool			bMipsConfig;
351	bool			bDPLLConfig;
352	UINT32			aTxPktSizeHist[MIBS_MAX_HIST_ENTRIES];
353	UINT32			aRxPktSizeHist[MIBS_MAX_HIST_ENTRIES];
354	struct bcm_fragmented_packet_info
355		astFragmentedPktClassifierTable[MAX_FRAGMENTEDIP_CLASSIFICATION_ENTRIES];
356	atomic_t		uiMBupdate;
357	UINT32			PmuMode;
358	enum bcm_nvm_type	eNVMType;
359	UINT			uiSectorSize;
360	UINT			uiSectorSizeInCFG;
361	bool			bSectorSizeOverride;
362	bool			bStatusWrite;
363	UINT			uiNVMDSDSize;
364	UINT			uiVendorExtnFlag;
365	/* it will always represent chosen DSD at any point of time.
366	 * Generally it is Active DSD but in case of NVM RD/WR it
367	 * might be different.
368	 */
369	UINT			ulFlashCalStart;
370	ULONG			ulFlashControlSectionStart;
371	ULONG			ulFlashWriteSize;
372	ULONG			ulFlashID;
373	FP_FLASH_WRITE		fpFlashWrite;
374	FP_FLASH_WRITE_STATUS	fpFlashWriteWithStatusCheck;
375
376	struct semaphore	NVMRdmWrmLock;
377	struct device		*pstCreatedClassDevice;
378
379	/*	BOOLEAN				InterfaceUpStatus; */
380	struct bcm_flash2x_cs_info *psFlash2xCSInfo;
381	struct bcm_flash_cs_info *psFlashCSInfo;
382	struct bcm_flash2x_vendor_info *psFlash2xVendorInfo;
383	UINT			uiFlashBaseAdd; /* Flash start address */
384	/* Active ISO offset chosen before f/w download */
385	UINT			uiActiveISOOffset;
386	enum bcm_flash2x_section_val eActiveISO; /* Active ISO section val */
387	/* Active DSD val chosen before f/w download */
388	enum bcm_flash2x_section_val eActiveDSD;
389	/* For accessing Active DSD chosen before f/w download */
390	UINT			uiActiveDSDOffsetAtFwDld;
391	UINT			uiFlashLayoutMajorVersion;
392	UINT			uiFlashLayoutMinorVersion;
393	bool			bAllDSDWriteAllow;
394	bool			bSigCorrupted;
395	/* this should be set who so ever want to change the Headers.
396	 * after Write it should be reset immediately.
397	 */
398	bool			bHeaderChangeAllowed;
399	int			SelectedChip;
400	bool			bEndPointHalted;
401	/* while bFlashRawRead will be true, Driver
402	 * ignore map lay out and consider flash as of without any map.
403	 */
404	bool			bFlashRawRead;
405	bool			bPreparingForLowPowerMode;
406	bool			bDoSuspend;
407	UINT			syscfgBefFwDld;
408	bool			StopAllXaction;
409	/* Used to Support extended CAPI requirements from */
410	UINT32			liTimeSinceLastNetEntry;
411	struct semaphore	LowPowerModeSync;
412	ULONG			liDrainCalculated;
413	UINT			gpioBitMap;
414	struct bcm_debug_state	stDebugState;
415};
416
417#define GET_BCM_ADAPTER(net_dev) netdev_priv(net_dev)
418
419struct bcm_eth_header {
420	UCHAR	au8DestinationAddress[6];
421	UCHAR	au8SourceAddress[6];
422	USHORT	u16Etype;
423} __packed;
424
425struct bcm_firmware_info {
426	void	__user *pvMappedFirmwareAddress;
427	ULONG	u32FirmwareLength;
428	ULONG	u32StartingAddress;
429} __packed;
430
431/* holds the value of net_device structure.. */
432extern struct net_device *gblpnetdev;
433
434struct bcm_ddr_setting {
435	UINT ulRegAddress;
436	UINT ulRegValue;
437};
438int InitAdapter(struct bcm_mini_adapter *psAdapter);
439
440/* =====================================================================
441 * Beceem vendor request codes for EP0
442 * =====================================================================
443 */
444
445#define BCM_REQUEST_READ	0x2
446#define BCM_REQUEST_WRITE	0x1
447#define EP2_MPS_REG		0x0F0110A0
448#define EP2_MPS			0x40
449
450#define EP2_CFG_REG	0x0F0110A8
451#define EP2_CFG_INT	0x27
452#define EP2_CFG_BULK	0x25
453
454#define EP4_MPS_REG	0x0F0110F0
455#define EP4_MPS		0x8C
456
457#define EP4_CFG_REG	0x0F0110F8
458
459#define ISO_MPS_REG	0x0F0110C8
460#define ISO_MPS		0x00000000
461
462#define EP1 0
463#define EP2 1
464#define EP3 2
465#define EP4 3
466#define EP5 4
467#define EP6 5
468
469enum bcm_einterface_setting {
470	DEFAULT_SETTING_0  = 0,
471	ALTERNATE_SETTING_1 = 1,
472};
473
474#endif	/* __ADAPTER_H__ */
475