hc
2023-11-22 9ca5fbcb63a8dcaee0527f96afb91dc4b4bd8fa9
add ip1811 driver
27 files added
1 files modified
23432 ■■■■■ changed files
kernel/drivers/net/ethernet/Makefile 1 ●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/Makefile 4 ●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/Makefile_ 50 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/driver_load 29 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/include/Makefile 7 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/include/libcommon.h 53 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/include/list.h 517 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/include/port_config.h 16 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/include/system_config.h 36 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/include/types.h 17 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/include/zconf.h 506 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/include/zlib.h 1744 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/ip1811.c 482 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/ip1811.h 1323 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/ip1811ds.h 746 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/ip1811fdat.c 466 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/ip1811fdat.h 550 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/ip1811func.c 13309 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/ip1811op.h 427 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/ip1811reg.h 231 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/ip218.h 29 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/libcommon.h 53 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/list.h 517 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/port_config.h 16 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/system_config.h 36 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/types.h 17 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/zconf.h 506 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/ip1811/zlib.h 1744 ●●●●● patch | view | raw | blame | history
kernel/drivers/net/ethernet/Makefile
....@@ -95,3 +95,4 @@
9595 obj-$(CONFIG_NET_VENDOR_XILINX) += xilinx/
9696 obj-$(CONFIG_NET_VENDOR_XIRCOM) += xircom/
9797 obj-$(CONFIG_NET_VENDOR_SYNOPSYS) += synopsys/
98
+obj-y += ip1811/
kernel/drivers/net/ethernet/ip1811/Makefile
....@@ -0,0 +1,4 @@
1
+DRIVER_NAME = ip1811drv
2
+obj-m := $(DRIVER_NAME).o
3
+$(DRIVER_NAME)-objs := ip1811.o ip1811fdat.o ip1811func.o
4
+
kernel/drivers/net/ethernet/ip1811/Makefile_
....@@ -0,0 +1,50 @@
1
+# Comment/uncomment the following line to disable/enable debugging
2
+#DEBFLAGS = -g # "-O" is needed to expand inlines
3
+EXTRA_CFLAGS += $(DEBFLAGS)
4
+
5
+# assign extra include path
6
+INCLUDEPATH ?= -I$(PWD)/../include
7
+EXTRA_CFLAGS += $(INCLUDEPATH)
8
+
9
+# Use MDC/MDIO to access external switch register.
10
+EXTRA_CFLAGS += -DACCESS_REG_BY_MDIO
11
+
12
+DRIVER_NAME = ip1811drv
13
+
14
+WORK_FN_FILE_SIZE =$(shell (ls -l $(1) | awk '{print $$5}'))
15
+PWD := $(shell pwd)
16
+EXE = $(DRIVER_NAME).ko
17
+
18
+KERNELDIR ?= /home/zdb/rk3568/rk356_linux4.19/kernel
19
+#KERNELDIR ?= ../../build/linux
20
+
21
+#CROSS_COMPILE :=mips-linux-
22
+CROSS_COMPILE := aarch64-linux-gnu-
23
+
24
+
25
+obj-m := $(DRIVER_NAME).o
26
+$(DRIVER_NAME)-objs := ip1811.o ip1811fdat.o ip1811func.o
27
+
28
+.PHONY: all
29
+all:
30
+ @echo "EXTRA_CFLGAS=[$(EXTRA_CFLAGS)]"
31
+ @echo " Making $@ ..."
32
+ $(MAKE) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNELDIR) M=$(PWD) modules
33
+ @make show_size
34
+ cp *.h $(INC)
35
+
36
+
37
+.PHONY: show_size
38
+show_size:
39
+ @echo "Info: generate AP $@ with size = $(call WORK_FN_FILE_SIZE,$(EXE))"
40
+
41
+.PHONY: clean
42
+clean:
43
+ rm -rf *.o .*.d *~ core .depend .*.cmd *.ko* *.mod.c .tmp_versions modules.order Module.symvers
44
+
45
+depend .depend dep:
46
+ $(CC) $(CFLAGS) -M *.c > .depend
47
+
48
+ifeq (.depend,$(wildcard .depend))
49
+ include .depend
50
+endif
kernel/drivers/net/ethernet/ip1811/driver_load
....@@ -0,0 +1,29 @@
1
+#!/bin/sh
2
+module="ip1811"
3
+mname="ip1811drv"
4
+device="ip1811_cdev"
5
+mode="664"
6
+
7
+# Group: since distributions do it differently, look for wheel or use staff
8
+if grep '^staff:' /etc/group > /dev/null; then
9
+ group="staff"
10
+else
11
+ group="wheel"
12
+fi
13
+
14
+# invoke insmod with all arguments we got
15
+# and use a pathname, as newer modutils don't look in . by default
16
+#/sbin/insmod -f ./$module.ko $* || exit 1
17
+insmod $mname.ko
18
+
19
+major=`cat /proc/devices | awk "\\$2==\"$device\" {print \\$1}"`
20
+
21
+# Remove stale nodes and replace them, then give gid and perms
22
+# Usually the script is shorter, it's simple that has several devices in it.
23
+
24
+#rm -f /dev/${device}[rn]
25
+mknod /dev/${module} c $major 0
26
+#mknod /dev/${device}r c $major 0
27
+#mknod /dev/${device}n c $major 1
28
+#chgrp $group /dev/${device}[rn]
29
+#chmod $mode /dev/${device}[rn]
kernel/drivers/net/ethernet/ip1811/include/Makefile
....@@ -0,0 +1,7 @@
1
+
2
+INCLUDEPATH = $(shell cd ../../linux/include; pwd)
3
+
4
+.PHONY: all
5
+all:
6
+ @echo "Copying include/*.h ..."
7
+ cp *.h $(INCLUDEPATH)
kernel/drivers/net/ethernet/ip1811/include/libcommon.h
....@@ -0,0 +1,53 @@
1
+#ifndef __LIB_COMMON_H__
2
+#define __LIB_COMMON_H__
3
+#include <sys/types.h>//for u_int8_t
4
+
5
+#undef OK
6
+#define OK 0
7
+
8
+#undef ERROR
9
+#define ERROR -1
10
+
11
+#undef FALSE
12
+#define FALSE 0
13
+
14
+#undef TRUE
15
+#define TRUE 1
16
+
17
+#undef DISABLE
18
+#define DISABLE 0
19
+
20
+#undef ENABLE
21
+#define ENABLE 1
22
+
23
+#define FREE_SAFE(a) if(a!=NULL){free(a);a=NULL;}
24
+
25
+#define SV_WDT_WDT_TIME (100)//Unit depends on WORKQUEUE_DELAY_TIME defined in supervisor.c
26
+
27
+/************************************************************
28
+ * Name: getSysUptime
29
+ * Description: get system uptime from proc file
30
+ * Parameters: None
31
+ * Return value:failed: -1
32
+ * success: float type uptime
33
+ * **********************************************************/
34
+float getSysUptime(void);
35
+long getSysUptime_10ms(void);
36
+void daemonize(void);
37
+int lock_file(char *filename);
38
+int unlock_file(int fd, char *filename);
39
+
40
+void get_switch_mac(u_int8_t* macaddr);
41
+void get_switch_ip(u_int8_t *ip);
42
+void get_switch_netmask(u_int8_t *mask);
43
+void get_gateway_ip(u_int8_t *ip);
44
+void get_gateway_ipv6(u_int8_t *ipv6);
45
+void DER_OID_decoder(unsigned char *input_OID, unsigned int OIDLen, char *outputString);
46
+char popen_d(char *cmd, char *ret, unsigned int ret_len);
47
+void printfd(char *file, char *buf);
48
+char ipStr2Array(char *ip, char *buf);
49
+int do_fork_execvp(char *argv[]);
50
+int supervisor_wdt_add(char *command, const char *func_name, int wdt_life_time);
51
+int supervisor_wdt_del(char *command);
52
+int supervisor_wdt_reset(char *command);
53
+#endif//__LIB_COMMON_H__
kernel/drivers/net/ethernet/ip1811/include/list.h
....@@ -0,0 +1,517 @@
1
+/**
2
+ *
3
+ * I grub it from linux kernel source code and fix it for user space
4
+ * program. Of course, this is a GPL licensed header file.
5
+ *
6
+ * Here is a recipe to cook list.h for user space program
7
+ *
8
+ * 1. copy list.h from linux/include/list.h
9
+ * 2. remove
10
+ * - #ifdef __KERNE__ and its #endif
11
+ * - all #include line
12
+ * - prefetch() and rcu related functions
13
+ * 3. add macro offsetof() and container_of
14
+ *
15
+ * - kazutomo@mcs.anl.gov
16
+ */
17
+#ifndef _LINUX_LIST_H
18
+#define _LINUX_LIST_H
19
+#include <stddef.h>
20
+/**
21
+ * @name from other kernel headers
22
+ */
23
+/*@{*/
24
+
25
+/**
26
+ * Get offset of a member
27
+ */
28
+//#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
29
+
30
+/**
31
+ * Casts a member of a structure out to the containing structure
32
+ * @param ptr the pointer to the member.
33
+ * @param type the type of the container struct this is embedded in.
34
+ * @param member the name of the member within the struct.
35
+ *
36
+ */
37
+#define container_of(ptr, type, member) ({ \
38
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
39
+ (type *)( (char *)__mptr - offsetof(type,member) );})
40
+/*@}*/
41
+
42
+
43
+/*
44
+ * These are non-NULL pointers that will result in page faults
45
+ * under normal circumstances, used to verify that nobody uses
46
+ * non-initialized list entries.
47
+ */
48
+#define LIST_POISON1 ((void *) 0x00100100)
49
+#define LIST_POISON2 ((void *) 0x00200200)
50
+
51
+/**
52
+ * Simple doubly linked list implementation.
53
+ *
54
+ * Some of the internal functions ("__xxx") are useful when
55
+ * manipulating whole lists rather than single entries, as
56
+ * sometimes we already know the next/prev entries and we can
57
+ * generate better code by using them directly rather than
58
+ * using the generic single-entry routines.
59
+ */
60
+struct list_head {
61
+ struct list_head *next, *prev;
62
+};
63
+
64
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
65
+
66
+#define LIST_HEAD(name) \
67
+ struct list_head name = LIST_HEAD_INIT(name)
68
+
69
+#define INIT_LIST_HEAD(ptr) do { \
70
+ (ptr)->next = (ptr); (ptr)->prev = (ptr); \
71
+} while (0)
72
+
73
+/*
74
+ * Insert a new entry between two known consecutive entries.
75
+ *
76
+ * This is only for internal list manipulation where we know
77
+ * the prev/next entries already!
78
+ */
79
+static inline void __list_add(struct list_head *new,
80
+ struct list_head *prev,
81
+ struct list_head *next)
82
+{
83
+ next->prev = new;
84
+ new->next = next;
85
+ new->prev = prev;
86
+ prev->next = new;
87
+}
88
+
89
+/**
90
+ * list_add - add a new entry
91
+ * @new: new entry to be added
92
+ * @head: list head to add it after
93
+ *
94
+ * Insert a new entry after the specified head.
95
+ * This is good for implementing stacks.
96
+ */
97
+static inline void list_add(struct list_head *new, struct list_head *head)
98
+{
99
+ __list_add(new, head, head->next);
100
+}
101
+
102
+/**
103
+ * list_add_tail - add a new entry
104
+ * @new: new entry to be added
105
+ * @head: list head to add it before
106
+ *
107
+ * Insert a new entry before the specified head.
108
+ * This is useful for implementing queues.
109
+ */
110
+static inline void list_add_tail(struct list_head *new, struct list_head *head)
111
+{
112
+ __list_add(new, head->prev, head);
113
+}
114
+
115
+
116
+/*
117
+ * Delete a list entry by making the prev/next entries
118
+ * point to each other.
119
+ *
120
+ * This is only for internal list manipulation where we know
121
+ * the prev/next entries already!
122
+ */
123
+static inline void __list_del(struct list_head * prev, struct list_head * next)
124
+{
125
+ next->prev = prev;
126
+ prev->next = next;
127
+}
128
+
129
+/**
130
+ * list_del - deletes entry from list.
131
+ * @entry: the element to delete from the list.
132
+ * Note: list_empty on entry does not return true after this, the entry is
133
+ * in an undefined state.
134
+ */
135
+static inline void list_del(struct list_head *entry)
136
+{
137
+ __list_del(entry->prev, entry->next);
138
+ entry->next = LIST_POISON1;
139
+ entry->prev = LIST_POISON2;
140
+}
141
+
142
+
143
+
144
+/**
145
+ * list_del_init - deletes entry from list and reinitialize it.
146
+ * @entry: the element to delete from the list.
147
+ */
148
+static inline void list_del_init(struct list_head *entry)
149
+{
150
+ __list_del(entry->prev, entry->next);
151
+ INIT_LIST_HEAD(entry);
152
+}
153
+
154
+/**
155
+ * list_move - delete from one list and add as another's head
156
+ * @list: the entry to move
157
+ * @head: the head that will precede our entry
158
+ */
159
+static inline void list_move(struct list_head *list, struct list_head *head)
160
+{
161
+ __list_del(list->prev, list->next);
162
+ list_add(list, head);
163
+}
164
+
165
+/**
166
+ * list_move_tail - delete from one list and add as another's tail
167
+ * @list: the entry to move
168
+ * @head: the head that will follow our entry
169
+ */
170
+static inline void list_move_tail(struct list_head *list,
171
+ struct list_head *head)
172
+{
173
+ __list_del(list->prev, list->next);
174
+ list_add_tail(list, head);
175
+}
176
+
177
+/**
178
+ * list_empty - tests whether a list is empty
179
+ * @head: the list to test.
180
+ */
181
+static inline int list_empty(const struct list_head *head)
182
+{
183
+ return head->next == head;
184
+}
185
+
186
+static inline void __list_splice(struct list_head *list,
187
+ struct list_head *head)
188
+{
189
+ struct list_head *first = list->next;
190
+ struct list_head *last = list->prev;
191
+ struct list_head *at = head->next;
192
+
193
+ first->prev = head;
194
+ head->next = first;
195
+
196
+ last->next = at;
197
+ at->prev = last;
198
+}
199
+
200
+/**
201
+ * list_splice - join two lists
202
+ * @list: the new list to add.
203
+ * @head: the place to add it in the first list.
204
+ */
205
+static inline void list_splice(struct list_head *list, struct list_head *head)
206
+{
207
+ if (!list_empty(list))
208
+ __list_splice(list, head);
209
+}
210
+
211
+/**
212
+ * list_splice_init - join two lists and reinitialise the emptied list.
213
+ * @list: the new list to add.
214
+ * @head: the place to add it in the first list.
215
+ *
216
+ * The list at @list is reinitialised
217
+ */
218
+static inline void list_splice_init(struct list_head *list,
219
+ struct list_head *head)
220
+{
221
+ if (!list_empty(list)) {
222
+ __list_splice(list, head);
223
+ INIT_LIST_HEAD(list);
224
+ }
225
+}
226
+
227
+/**
228
+ * list_entry - get the struct for this entry
229
+ * @ptr: the &struct list_head pointer.
230
+ * @type: the type of the struct this is embedded in.
231
+ * @member: the name of the list_struct within the struct.
232
+ */
233
+#define list_entry(ptr, type, member) \
234
+ container_of(ptr, type, member)
235
+
236
+/**
237
+ * list_for_each - iterate over a list
238
+ * @pos: the &struct list_head to use as a loop counter.
239
+ * @head: the head for your list.
240
+ */
241
+
242
+#define list_for_each(pos, head) \
243
+ for (pos = (head)->next; pos != (head); \
244
+ pos = pos->next)
245
+
246
+/**
247
+ * __list_for_each - iterate over a list
248
+ * @pos: the &struct list_head to use as a loop counter.
249
+ * @head: the head for your list.
250
+ *
251
+ * This variant differs from list_for_each() in that it's the
252
+ * simplest possible list iteration code, no prefetching is done.
253
+ * Use this for code that knows the list to be very short (empty
254
+ * or 1 entry) most of the time.
255
+ */
256
+#define __list_for_each(pos, head) \
257
+ for (pos = (head)->next; pos != (head); pos = pos->next)
258
+
259
+/**
260
+ * list_for_each_prev - iterate over a list backwards
261
+ * @pos: the &struct list_head to use as a loop counter.
262
+ * @head: the head for your list.
263
+ */
264
+#define list_for_each_prev(pos, head) \
265
+ for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
266
+ pos = pos->prev)
267
+
268
+/**
269
+ * list_for_each_safe - iterate over a list safe against removal of list entry
270
+ * @pos: the &struct list_head to use as a loop counter.
271
+ * @n: another &struct list_head to use as temporary storage
272
+ * @head: the head for your list.
273
+ */
274
+#define list_for_each_safe(pos, n, head) \
275
+ for (pos = (head)->next, n = pos->next; pos != (head); \
276
+ pos = n, n = pos->next)
277
+
278
+/**
279
+ * list_for_each_entry - iterate over list of given type
280
+ * @pos: the type * to use as a loop counter.
281
+ * @head: the head for your list.
282
+ * @member: the name of the list_struct within the struct.
283
+ */
284
+#define list_for_each_entry(pos, head, member) \
285
+ for (pos = list_entry((head)->next, typeof(*pos), member); \
286
+ &pos->member != (head); \
287
+ pos = list_entry(pos->member.next, typeof(*pos), member))
288
+
289
+/**
290
+ * list_for_each_entry_reverse - iterate backwards over list of given type.
291
+ * @pos: the type * to use as a loop counter.
292
+ * @head: the head for your list.
293
+ * @member: the name of the list_struct within the struct.
294
+ */
295
+#define list_for_each_entry_reverse(pos, head, member) \
296
+ for (pos = list_entry((head)->prev, typeof(*pos), member); \
297
+ &pos->member != (head); \
298
+ pos = list_entry(pos->member.prev, typeof(*pos), member))
299
+
300
+/**
301
+ * list_prepare_entry - prepare a pos entry for use as a start point in
302
+ * list_for_each_entry_continue
303
+ * @pos: the type * to use as a start point
304
+ * @head: the head of the list
305
+ * @member: the name of the list_struct within the struct.
306
+ */
307
+#define list_prepare_entry(pos, head, member) \
308
+ ((pos) ? : list_entry(head, typeof(*pos), member))
309
+
310
+/**
311
+ * list_for_each_entry_continue - iterate over list of given type
312
+ * continuing after existing point
313
+ * @pos: the type * to use as a loop counter.
314
+ * @head: the head for your list.
315
+ * @member: the name of the list_struct within the struct.
316
+ */
317
+#define list_for_each_entry_continue(pos, head, member) \
318
+ for (pos = list_entry(pos->member.next, typeof(*pos), member); \
319
+ &pos->member != (head); \
320
+ pos = list_entry(pos->member.next, typeof(*pos), member))
321
+
322
+/**
323
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
324
+ * @pos: the type * to use as a loop counter.
325
+ * @n: another type * to use as temporary storage
326
+ * @head: the head for your list.
327
+ * @member: the name of the list_struct within the struct.
328
+ */
329
+#define list_for_each_entry_safe(pos, n, head, member) \
330
+ for (pos = list_entry((head)->next, typeof(*pos), member), \
331
+ n = list_entry(pos->member.next, typeof(*pos), member); \
332
+ &pos->member != (head); \
333
+ pos = n, n = list_entry(n->member.next, typeof(*n), member))
334
+
335
+/**
336
+ * list_for_each_entry_safe_continue - iterate over list of given type
337
+ * continuing after existing point safe against removal of list entry
338
+ * @pos: the type * to use as a loop counter.
339
+ * @n: another type * to use as temporary storage
340
+ * @head: the head for your list.
341
+ * @member: the name of the list_struct within the struct.
342
+ */
343
+#define list_for_each_entry_safe_continue(pos, n, head, member) \
344
+ for (pos = list_entry(pos->member.next, typeof(*pos), member), \
345
+ n = list_entry(pos->member.next, typeof(*pos), member); \
346
+ &pos->member != (head); \
347
+ pos = n, n = list_entry(n->member.next, typeof(*n), member))
348
+
349
+/**
350
+ * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against
351
+ * removal of list entry
352
+ * @pos: the type * to use as a loop counter.
353
+ * @n: another type * to use as temporary storage
354
+ * @head: the head for your list.
355
+ * @member: the name of the list_struct within the struct.
356
+ */
357
+#define list_for_each_entry_safe_reverse(pos, n, head, member) \
358
+ for (pos = list_entry((head)->prev, typeof(*pos), member), \
359
+ n = list_entry(pos->member.prev, typeof(*pos), member); \
360
+ &pos->member != (head); \
361
+ pos = n, n = list_entry(n->member.prev, typeof(*n), member))
362
+
363
+
364
+
365
+
366
+/*
367
+ * Double linked lists with a single pointer list head.
368
+ * Mostly useful for hash tables where the two pointer list head is
369
+ * too wasteful.
370
+ * You lose the ability to access the tail in O(1).
371
+ */
372
+
373
+struct hlist_head {
374
+ struct hlist_node *first;
375
+};
376
+
377
+struct hlist_node {
378
+ struct hlist_node *next, **pprev;
379
+};
380
+
381
+#define HLIST_HEAD_INIT { .first = NULL }
382
+#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
383
+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
384
+#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
385
+
386
+static inline int hlist_unhashed(const struct hlist_node *h)
387
+{
388
+ return !h->pprev;
389
+}
390
+
391
+static inline int hlist_empty(const struct hlist_head *h)
392
+{
393
+ return !h->first;
394
+}
395
+
396
+static inline void __hlist_del(struct hlist_node *n)
397
+{
398
+ struct hlist_node *next = n->next;
399
+ struct hlist_node **pprev = n->pprev;
400
+ *pprev = next;
401
+ if (next)
402
+ next->pprev = pprev;
403
+}
404
+
405
+static inline void hlist_del(struct hlist_node *n)
406
+{
407
+ __hlist_del(n);
408
+ n->next = LIST_POISON1;
409
+ n->pprev = LIST_POISON2;
410
+}
411
+
412
+
413
+static inline void hlist_del_init(struct hlist_node *n)
414
+{
415
+ if (n->pprev) {
416
+ __hlist_del(n);
417
+ INIT_HLIST_NODE(n);
418
+ }
419
+}
420
+
421
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
422
+{
423
+ struct hlist_node *first = h->first;
424
+ n->next = first;
425
+ if (first)
426
+ first->pprev = &n->next;
427
+ h->first = n;
428
+ n->pprev = &h->first;
429
+}
430
+
431
+
432
+
433
+/* next must be != NULL */
434
+static inline void hlist_add_before(struct hlist_node *n,
435
+ struct hlist_node *next)
436
+{
437
+ n->pprev = next->pprev;
438
+ n->next = next;
439
+ next->pprev = &n->next;
440
+ *(n->pprev) = n;
441
+}
442
+
443
+static inline void hlist_add_after(struct hlist_node *n,
444
+ struct hlist_node *next)
445
+{
446
+ next->next = n->next;
447
+ n->next = next;
448
+ next->pprev = &n->next;
449
+
450
+ if(next->next)
451
+ next->next->pprev = &next->next;
452
+}
453
+
454
+
455
+
456
+#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
457
+
458
+#define hlist_for_each(pos, head) \
459
+ for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
460
+ pos = pos->next)
461
+
462
+#define hlist_for_each_safe(pos, n, head) \
463
+ for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
464
+ pos = n)
465
+
466
+/**
467
+ * hlist_for_each_entry - iterate over list of given type
468
+ * @tpos: the type * to use as a loop counter.
469
+ * @pos: the &struct hlist_node to use as a loop counter.
470
+ * @head: the head for your list.
471
+ * @member: the name of the hlist_node within the struct.
472
+ */
473
+#define hlist_for_each_entry(tpos, pos, head, member) \
474
+ for (pos = (head)->first; \
475
+ pos && ({ prefetch(pos->next); 1;}) && \
476
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
477
+ pos = pos->next)
478
+
479
+/**
480
+ * hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
481
+ * @tpos: the type * to use as a loop counter.
482
+ * @pos: the &struct hlist_node to use as a loop counter.
483
+ * @member: the name of the hlist_node within the struct.
484
+ */
485
+#define hlist_for_each_entry_continue(tpos, pos, member) \
486
+ for (pos = (pos)->next; \
487
+ pos && ({ prefetch(pos->next); 1;}) && \
488
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
489
+ pos = pos->next)
490
+
491
+/**
492
+ * hlist_for_each_entry_from - iterate over a hlist continuing from existing point
493
+ * @tpos: the type * to use as a loop counter.
494
+ * @pos: the &struct hlist_node to use as a loop counter.
495
+ * @member: the name of the hlist_node within the struct.
496
+ */
497
+#define hlist_for_each_entry_from(tpos, pos, member) \
498
+ for (; pos && ({ prefetch(pos->next); 1;}) && \
499
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
500
+ pos = pos->next)
501
+
502
+/**
503
+ * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
504
+ * @tpos: the type * to use as a loop counter.
505
+ * @pos: the &struct hlist_node to use as a loop counter.
506
+ * @n: another &struct hlist_node to use as temporary storage
507
+ * @head: the head for your list.
508
+ * @member: the name of the hlist_node within the struct.
509
+ */
510
+#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
511
+ for (pos = (head)->first; \
512
+ pos && ({ n = pos->next; 1; }) && \
513
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
514
+ pos = n)
515
+
516
+
517
+#endif
kernel/drivers/net/ethernet/ip1811/include/port_config.h
....@@ -0,0 +1,16 @@
1
+#ifndef __PORT_CONFIG_H__
2
+#define __PORT_CONFIG_H__
3
+#include "portnumber.h"
4
+
5
+#define MAX_PORT_NUM get_MaxPort()
6
+#define GIGA_PORT_START get_GPStart()
7
+#define GIGA_PORT_END get_GPEnd()
8
+
9
+#define MAX_IPORT_CNT SWITCH_MAX_IPORT_CNT
10
+#define ALL_PORTS_LIST (~(-1 << MAX_PORT_NUM))
11
+#define GIGA_PORT_NUM (GIGA_PORT_END - GIGA_PORT_START)
12
+#define CPU_PORT_NUM MAX_IPORT_CNT
13
+#define MAX_TP_PORT_NUM (GIGA_PORT_START -1)
14
+
15
+#endif
16
+
kernel/drivers/net/ethernet/ip1811/include/system_config.h
....@@ -0,0 +1,36 @@
1
+
2
+#ifndef __SYSTEM_CONFIG_H__
3
+#define __SYSTEM_CONFIG_H__
4
+///////////////////////////////////////////////
5
+//// board config
6
+///////////////////////////////////////////////
7
+
8
+//#define SYSTEM_CONFIG__FPGA
9
+//#define SYSTEM_CONFIG__ASIC//this is ASIC_135
10
+//#define SYSTEM_CONFIG__ASIC125
11
+//#define SYSTEM_CONFIG__ASIC_135
12
+#define SYSTEM_CONFIG__ASIC_150
13
+
14
+
15
+#define SYSTEM_CONFIG__SERVER_MODE
16
+//#define SYSTEM_CONFIG__PCI_MODE
17
+
18
+
19
+///////////////////////////////////////////////
20
+//// DRAM parameter - ref: sdram_support_list
21
+///////////////////////////////////////////////
22
+
23
+#define SYSTEM_CONFIG_DRAM__ARCH_4CH
24
+//#define SYSTEM_CONFIG_DRAM__USED_2CHIPS
25
+//#define SYSTEM_CONFIG_FLASH__USED_2CHIPS
26
+
27
+//#define SYSTEM_CONFIG_DRAM__NT5SV16M16CS_6K
28
+//#define SYSTEM_CONFIG_DRAM__PMS308416BTR_6
29
+//#define SYSTEM_CONFIG_DRAM__IS42S16320D
30
+#define SYSTEM_CONFIG_DRAM__W9825G6KH_6I
31
+//#define SYSTEM_CONFIG_DRAM__A3V56S30
32
+
33
+//#define SYS_CONFIG_WITH_IP102_PHY
34
+
35
+#endif
36
+
kernel/drivers/net/ethernet/ip1811/include/types.h
....@@ -0,0 +1,17 @@
1
+#ifndef _TYPES_H_
2
+#define _TYPES_H_
3
+
4
+typedef unsigned char u8;
5
+typedef unsigned short u16;
6
+typedef unsigned int u32;
7
+typedef unsigned long long u64;
8
+typedef char s8;
9
+typedef short s16;
10
+typedef int s32;
11
+typedef long long s64;
12
+
13
+#define BIT(x) (1UL<<(x))
14
+
15
+#define err (-1)
16
+
17
+#endif
kernel/drivers/net/ethernet/ip1811/include/zconf.h
....@@ -0,0 +1,506 @@
1
+/* zconf.h -- configuration of the zlib compression library
2
+ * Copyright (C) 1995-2012 Jean-loup Gailly.
3
+ * For conditions of distribution and use, see copyright notice in zlib.h
4
+ */
5
+
6
+/* @(#) $Id$ */
7
+
8
+#ifndef ZCONF_H
9
+#define ZCONF_H
10
+
11
+/*
12
+ * If you *really* need a unique prefix for all types and library functions,
13
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
14
+ * Even better than compiling with -DZ_PREFIX would be to use configure to set
15
+ * this permanently in zconf.h using "./configure --zprefix".
16
+ */
17
+#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
18
+# define Z_PREFIX_SET
19
+
20
+/* all linked symbols */
21
+# define _dist_code z__dist_code
22
+# define _length_code z__length_code
23
+# define _tr_align z__tr_align
24
+# define _tr_flush_block z__tr_flush_block
25
+# define _tr_init z__tr_init
26
+# define _tr_stored_block z__tr_stored_block
27
+# define _tr_tally z__tr_tally
28
+# define adler32 z_adler32
29
+# define adler32_combine z_adler32_combine
30
+# define adler32_combine64 z_adler32_combine64
31
+# ifndef Z_SOLO
32
+# define compress z_compress
33
+# define compress2 z_compress2
34
+# define compressBound z_compressBound
35
+# endif
36
+# define crc32 z_crc32
37
+# define crc32_combine z_crc32_combine
38
+# define crc32_combine64 z_crc32_combine64
39
+# define deflate z_deflate
40
+# define deflateBound z_deflateBound
41
+# define deflateCopy z_deflateCopy
42
+# define deflateEnd z_deflateEnd
43
+# define deflateInit2_ z_deflateInit2_
44
+# define deflateInit_ z_deflateInit_
45
+# define deflateParams z_deflateParams
46
+# define deflatePending z_deflatePending
47
+# define deflatePrime z_deflatePrime
48
+# define deflateReset z_deflateReset
49
+# define deflateResetKeep z_deflateResetKeep
50
+# define deflateSetDictionary z_deflateSetDictionary
51
+# define deflateSetHeader z_deflateSetHeader
52
+# define deflateTune z_deflateTune
53
+# define deflate_copyright z_deflate_copyright
54
+# define get_crc_table z_get_crc_table
55
+# ifndef Z_SOLO
56
+# define gz_error z_gz_error
57
+# define gz_intmax z_gz_intmax
58
+# define gz_strwinerror z_gz_strwinerror
59
+# define gzbuffer z_gzbuffer
60
+# define gzclearerr z_gzclearerr
61
+# define gzclose z_gzclose
62
+# define gzclose_r z_gzclose_r
63
+# define gzclose_w z_gzclose_w
64
+# define gzdirect z_gzdirect
65
+# define gzdopen z_gzdopen
66
+# define gzeof z_gzeof
67
+# define gzerror z_gzerror
68
+# define gzflush z_gzflush
69
+# define gzgetc z_gzgetc
70
+# define gzgetc_ z_gzgetc_
71
+# define gzgets z_gzgets
72
+# define gzoffset z_gzoffset
73
+# define gzoffset64 z_gzoffset64
74
+# define gzopen z_gzopen
75
+# define gzopen64 z_gzopen64
76
+# ifdef _WIN32
77
+# define gzopen_w z_gzopen_w
78
+# endif
79
+# define gzprintf z_gzprintf
80
+# define gzputc z_gzputc
81
+# define gzputs z_gzputs
82
+# define gzread z_gzread
83
+# define gzrewind z_gzrewind
84
+# define gzseek z_gzseek
85
+# define gzseek64 z_gzseek64
86
+# define gzsetparams z_gzsetparams
87
+# define gztell z_gztell
88
+# define gztell64 z_gztell64
89
+# define gzungetc z_gzungetc
90
+# define gzwrite z_gzwrite
91
+# endif
92
+# define inflate z_inflate
93
+# define inflateBack z_inflateBack
94
+# define inflateBackEnd z_inflateBackEnd
95
+# define inflateBackInit_ z_inflateBackInit_
96
+# define inflateCopy z_inflateCopy
97
+# define inflateEnd z_inflateEnd
98
+# define inflateGetHeader z_inflateGetHeader
99
+# define inflateInit2_ z_inflateInit2_
100
+# define inflateInit_ z_inflateInit_
101
+# define inflateMark z_inflateMark
102
+# define inflatePrime z_inflatePrime
103
+# define inflateReset z_inflateReset
104
+# define inflateReset2 z_inflateReset2
105
+# define inflateSetDictionary z_inflateSetDictionary
106
+# define inflateSync z_inflateSync
107
+# define inflateSyncPoint z_inflateSyncPoint
108
+# define inflateUndermine z_inflateUndermine
109
+# define inflateResetKeep z_inflateResetKeep
110
+# define inflate_copyright z_inflate_copyright
111
+# define inflate_fast z_inflate_fast
112
+# define inflate_table z_inflate_table
113
+# ifndef Z_SOLO
114
+# define uncompress z_uncompress
115
+# endif
116
+# define zError z_zError
117
+# ifndef Z_SOLO
118
+# define zcalloc z_zcalloc
119
+# define zcfree z_zcfree
120
+# endif
121
+# define zlibCompileFlags z_zlibCompileFlags
122
+# define zlibVersion z_zlibVersion
123
+
124
+/* all zlib typedefs in zlib.h and zconf.h */
125
+# define Byte z_Byte
126
+# define Bytef z_Bytef
127
+# define alloc_func z_alloc_func
128
+# define charf z_charf
129
+# define free_func z_free_func
130
+# ifndef Z_SOLO
131
+# define gzFile z_gzFile
132
+# endif
133
+# define gz_header z_gz_header
134
+# define gz_headerp z_gz_headerp
135
+# define in_func z_in_func
136
+# define intf z_intf
137
+# define out_func z_out_func
138
+# define uInt z_uInt
139
+# define uIntf z_uIntf
140
+# define uLong z_uLong
141
+# define uLongf z_uLongf
142
+# define voidp z_voidp
143
+# define voidpc z_voidpc
144
+# define voidpf z_voidpf
145
+
146
+/* all zlib structs in zlib.h and zconf.h */
147
+# define gz_header_s z_gz_header_s
148
+# define internal_state z_internal_state
149
+
150
+#endif
151
+
152
+#if defined(__MSDOS__) && !defined(MSDOS)
153
+# define MSDOS
154
+#endif
155
+#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
156
+# define OS2
157
+#endif
158
+#if defined(_WINDOWS) && !defined(WINDOWS)
159
+# define WINDOWS
160
+#endif
161
+#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
162
+# ifndef WIN32
163
+# define WIN32
164
+# endif
165
+#endif
166
+#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
167
+# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
168
+# ifndef SYS16BIT
169
+# define SYS16BIT
170
+# endif
171
+# endif
172
+#endif
173
+
174
+/*
175
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
176
+ * than 64k bytes at a time (needed on systems with 16-bit int).
177
+ */
178
+#ifdef SYS16BIT
179
+# define MAXSEG_64K
180
+#endif
181
+#ifdef MSDOS
182
+# define UNALIGNED_OK
183
+#endif
184
+
185
+#ifdef __STDC_VERSION__
186
+# ifndef STDC
187
+# define STDC
188
+# endif
189
+# if __STDC_VERSION__ >= 199901L
190
+# ifndef STDC99
191
+# define STDC99
192
+# endif
193
+# endif
194
+#endif
195
+#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
196
+# define STDC
197
+#endif
198
+#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
199
+# define STDC
200
+#endif
201
+#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
202
+# define STDC
203
+#endif
204
+#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
205
+# define STDC
206
+#endif
207
+
208
+#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
209
+# define STDC
210
+#endif
211
+
212
+#ifndef STDC
213
+# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
214
+# define const /* note: need a more gentle solution here */
215
+# endif
216
+#endif
217
+
218
+#if defined(ZLIB_CONST) && !defined(z_const)
219
+# define z_const const
220
+#else
221
+# define z_const
222
+#endif
223
+
224
+/* Some Mac compilers merge all .h files incorrectly: */
225
+#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
226
+# define NO_DUMMY_DECL
227
+#endif
228
+
229
+/* Maximum value for memLevel in deflateInit2 */
230
+#ifndef MAX_MEM_LEVEL
231
+# ifdef MAXSEG_64K
232
+# define MAX_MEM_LEVEL 8
233
+# else
234
+# define MAX_MEM_LEVEL 9
235
+# endif
236
+#endif
237
+
238
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.
239
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
240
+ * created by gzip. (Files created by minigzip can still be extracted by
241
+ * gzip.)
242
+ */
243
+#ifndef MAX_WBITS
244
+# define MAX_WBITS 15 /* 32K LZ77 window */
245
+#endif
246
+
247
+/* The memory requirements for deflate are (in bytes):
248
+ (1 << (windowBits+2)) + (1 << (memLevel+9))
249
+ that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
250
+ plus a few kilobytes for small objects. For example, if you want to reduce
251
+ the default memory requirements from 256K to 128K, compile with
252
+ make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
253
+ Of course this will generally degrade compression (there's no free lunch).
254
+
255
+ The memory requirements for inflate are (in bytes) 1 << windowBits
256
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes
257
+ for small objects.
258
+*/
259
+
260
+ /* Type declarations */
261
+
262
+#ifndef OF /* function prototypes */
263
+# ifdef STDC
264
+# define OF(args) args
265
+# else
266
+# define OF(args) ()
267
+# endif
268
+#endif
269
+
270
+#ifndef Z_ARG /* function prototypes for stdarg */
271
+# if defined(STDC) || defined(Z_HAVE_STDARG_H)
272
+# define Z_ARG(args) args
273
+# else
274
+# define Z_ARG(args) ()
275
+# endif
276
+#endif
277
+
278
+/* The following definitions for FAR are needed only for MSDOS mixed
279
+ * model programming (small or medium model with some far allocations).
280
+ * This was tested only with MSC; for other MSDOS compilers you may have
281
+ * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
282
+ * just define FAR to be empty.
283
+ */
284
+#ifdef SYS16BIT
285
+# if defined(M_I86SM) || defined(M_I86MM)
286
+ /* MSC small or medium model */
287
+# define SMALL_MEDIUM
288
+# ifdef _MSC_VER
289
+# define FAR _far
290
+# else
291
+# define FAR far
292
+# endif
293
+# endif
294
+# if (defined(__SMALL__) || defined(__MEDIUM__))
295
+ /* Turbo C small or medium model */
296
+# define SMALL_MEDIUM
297
+# ifdef __BORLANDC__
298
+# define FAR _far
299
+# else
300
+# define FAR far
301
+# endif
302
+# endif
303
+#endif
304
+
305
+#if defined(WINDOWS) || defined(WIN32)
306
+ /* If building or using zlib as a DLL, define ZLIB_DLL.
307
+ * This is not mandatory, but it offers a little performance increase.
308
+ */
309
+# ifdef ZLIB_DLL
310
+# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
311
+# ifdef ZLIB_INTERNAL
312
+# define ZEXTERN extern __declspec(dllexport)
313
+# else
314
+# define ZEXTERN extern __declspec(dllimport)
315
+# endif
316
+# endif
317
+# endif /* ZLIB_DLL */
318
+ /* If building or using zlib with the WINAPI/WINAPIV calling convention,
319
+ * define ZLIB_WINAPI.
320
+ * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
321
+ */
322
+# ifdef ZLIB_WINAPI
323
+# ifdef FAR
324
+# undef FAR
325
+# endif
326
+# include <windows.h>
327
+ /* No need for _export, use ZLIB.DEF instead. */
328
+ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
329
+# define ZEXPORT WINAPI
330
+# ifdef WIN32
331
+# define ZEXPORTVA WINAPIV
332
+# else
333
+# define ZEXPORTVA FAR CDECL
334
+# endif
335
+# endif
336
+#endif
337
+
338
+#if defined (__BEOS__)
339
+# ifdef ZLIB_DLL
340
+# ifdef ZLIB_INTERNAL
341
+# define ZEXPORT __declspec(dllexport)
342
+# define ZEXPORTVA __declspec(dllexport)
343
+# else
344
+# define ZEXPORT __declspec(dllimport)
345
+# define ZEXPORTVA __declspec(dllimport)
346
+# endif
347
+# endif
348
+#endif
349
+
350
+#ifndef ZEXTERN
351
+# define ZEXTERN extern
352
+#endif
353
+#ifndef ZEXPORT
354
+# define ZEXPORT
355
+#endif
356
+#ifndef ZEXPORTVA
357
+# define ZEXPORTVA
358
+#endif
359
+
360
+#ifndef FAR
361
+# define FAR
362
+#endif
363
+
364
+#if !defined(__MACTYPES__)
365
+typedef unsigned char Byte; /* 8 bits */
366
+#endif
367
+typedef unsigned int uInt; /* 16 bits or more */
368
+typedef unsigned long uLong; /* 32 bits or more */
369
+
370
+#ifdef SMALL_MEDIUM
371
+ /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
372
+# define Bytef Byte FAR
373
+#else
374
+ typedef Byte FAR Bytef;
375
+#endif
376
+typedef char FAR charf;
377
+typedef int FAR intf;
378
+typedef uInt FAR uIntf;
379
+typedef uLong FAR uLongf;
380
+
381
+#ifdef STDC
382
+ typedef void const *voidpc;
383
+ typedef void FAR *voidpf;
384
+ typedef void *voidp;
385
+#else
386
+ typedef Byte const *voidpc;
387
+ typedef Byte FAR *voidpf;
388
+ typedef Byte *voidp;
389
+#endif
390
+
391
+/* ./configure may #define Z_U4 here */
392
+
393
+#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
394
+# include <limits.h>
395
+# if (UINT_MAX == 0xffffffffUL)
396
+# define Z_U4 unsigned
397
+# else
398
+# if (ULONG_MAX == 0xffffffffUL)
399
+# define Z_U4 unsigned long
400
+# else
401
+# if (USHRT_MAX == 0xffffffffUL)
402
+# define Z_U4 unsigned short
403
+# endif
404
+# endif
405
+# endif
406
+#endif
407
+
408
+#ifdef Z_U4
409
+ typedef Z_U4 z_crc_t;
410
+#else
411
+ typedef unsigned long z_crc_t;
412
+#endif
413
+
414
+#if 1 /* was set to #if 1 by ./configure */
415
+# define Z_HAVE_UNISTD_H
416
+#endif
417
+
418
+#if 1 /* was set to #if 1 by ./configure */
419
+# define Z_HAVE_STDARG_H
420
+#endif
421
+
422
+#ifdef STDC
423
+# ifndef Z_SOLO
424
+# include <sys/types.h> /* for off_t */
425
+# endif
426
+#endif
427
+
428
+#ifdef _WIN32
429
+# include <stddef.h> /* for wchar_t */
430
+#endif
431
+
432
+/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
433
+ * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
434
+ * though the former does not conform to the LFS document), but considering
435
+ * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
436
+ * equivalently requesting no 64-bit operations
437
+ */
438
+#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
439
+# undef _LARGEFILE64_SOURCE
440
+#endif
441
+
442
+#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
443
+# define Z_HAVE_UNISTD_H
444
+#endif
445
+#ifndef Z_SOLO
446
+# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE)
447
+# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
448
+# ifdef VMS
449
+# include <unixio.h> /* for off_t */
450
+# endif
451
+# ifndef z_off_t
452
+# define z_off_t off_t
453
+# endif
454
+# endif
455
+#endif
456
+
457
+#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
458
+# define Z_LFS64
459
+#endif
460
+
461
+#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
462
+# define Z_LARGE64
463
+#endif
464
+
465
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
466
+# define Z_WANT64
467
+#endif
468
+
469
+#if !defined(SEEK_SET) && !defined(Z_SOLO)
470
+# define SEEK_SET 0 /* Seek from beginning of file. */
471
+# define SEEK_CUR 1 /* Seek from current position. */
472
+# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
473
+#endif
474
+
475
+#ifndef z_off_t
476
+# define z_off_t long
477
+#endif
478
+
479
+#if !defined(_WIN32) && defined(Z_LARGE64)
480
+# define z_off64_t off64_t
481
+#else
482
+# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
483
+# define z_off64_t __int64
484
+# else
485
+# define z_off64_t z_off_t
486
+# endif
487
+#endif
488
+
489
+/* MVS linker does not support external names larger than 8 bytes */
490
+#if defined(__MVS__)
491
+ #pragma map(deflateInit_,"DEIN")
492
+ #pragma map(deflateInit2_,"DEIN2")
493
+ #pragma map(deflateEnd,"DEEND")
494
+ #pragma map(deflateBound,"DEBND")
495
+ #pragma map(inflateInit_,"ININ")
496
+ #pragma map(inflateInit2_,"ININ2")
497
+ #pragma map(inflateEnd,"INEND")
498
+ #pragma map(inflateSync,"INSY")
499
+ #pragma map(inflateSetDictionary,"INSEDI")
500
+ #pragma map(compressBound,"CMBND")
501
+ #pragma map(inflate_table,"INTABL")
502
+ #pragma map(inflate_fast,"INFA")
503
+ #pragma map(inflate_copyright,"INCOPY")
504
+#endif
505
+
506
+#endif /* ZCONF_H */
kernel/drivers/net/ethernet/ip1811/include/zlib.h
....@@ -0,0 +1,1744 @@
1
+/* zlib.h -- interface of the 'zlib' general purpose compression library
2
+ version 1.2.7, May 2nd, 2012
3
+
4
+ Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
5
+
6
+ This software is provided 'as-is', without any express or implied
7
+ warranty. In no event will the authors be held liable for any damages
8
+ arising from the use of this software.
9
+
10
+ Permission is granted to anyone to use this software for any purpose,
11
+ including commercial applications, and to alter it and redistribute it
12
+ freely, subject to the following restrictions:
13
+
14
+ 1. The origin of this software must not be misrepresented; you must not
15
+ claim that you wrote the original software. If you use this software
16
+ in a product, an acknowledgment in the product documentation would be
17
+ appreciated but is not required.
18
+ 2. Altered source versions must be plainly marked as such, and must not be
19
+ misrepresented as being the original software.
20
+ 3. This notice may not be removed or altered from any source distribution.
21
+
22
+ Jean-loup Gailly Mark Adler
23
+ jloup@gzip.org madler@alumni.caltech.edu
24
+
25
+
26
+ The data format used by the zlib library is described by RFCs (Request for
27
+ Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
28
+ (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
29
+*/
30
+
31
+#ifndef ZLIB_H
32
+#define ZLIB_H
33
+
34
+#include "zconf.h"
35
+
36
+#ifdef __cplusplus
37
+extern "C" {
38
+#endif
39
+
40
+#define ZLIB_VERSION "1.2.7"
41
+#define ZLIB_VERNUM 0x1270
42
+#define ZLIB_VER_MAJOR 1
43
+#define ZLIB_VER_MINOR 2
44
+#define ZLIB_VER_REVISION 7
45
+#define ZLIB_VER_SUBREVISION 0
46
+
47
+/*
48
+ The 'zlib' compression library provides in-memory compression and
49
+ decompression functions, including integrity checks of the uncompressed data.
50
+ This version of the library supports only one compression method (deflation)
51
+ but other algorithms will be added later and will have the same stream
52
+ interface.
53
+
54
+ Compression can be done in a single step if the buffers are large enough,
55
+ or can be done by repeated calls of the compression function. In the latter
56
+ case, the application must provide more input and/or consume the output
57
+ (providing more output space) before each call.
58
+
59
+ The compressed data format used by default by the in-memory functions is
60
+ the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
61
+ around a deflate stream, which is itself documented in RFC 1951.
62
+
63
+ The library also supports reading and writing files in gzip (.gz) format
64
+ with an interface similar to that of stdio using the functions that start
65
+ with "gz". The gzip format is different from the zlib format. gzip is a
66
+ gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
67
+
68
+ This library can optionally read and write gzip streams in memory as well.
69
+
70
+ The zlib format was designed to be compact and fast for use in memory
71
+ and on communications channels. The gzip format was designed for single-
72
+ file compression on file systems, has a larger header than zlib to maintain
73
+ directory information, and uses a different, slower check method than zlib.
74
+
75
+ The library does not install any signal handler. The decoder checks
76
+ the consistency of the compressed data, so the library should never crash
77
+ even in case of corrupted input.
78
+*/
79
+
80
+typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
81
+typedef void (*free_func) OF((voidpf opaque, voidpf address));
82
+
83
+struct internal_state;
84
+
85
+typedef struct z_stream_s {
86
+ z_const Bytef *next_in; /* next input byte */
87
+ uInt avail_in; /* number of bytes available at next_in */
88
+ uLong total_in; /* total number of input bytes read so far */
89
+
90
+ Bytef *next_out; /* next output byte should be put there */
91
+ uInt avail_out; /* remaining free space at next_out */
92
+ uLong total_out; /* total number of bytes output so far */
93
+
94
+ z_const char *msg; /* last error message, NULL if no error */
95
+ struct internal_state FAR *state; /* not visible by applications */
96
+
97
+ alloc_func zalloc; /* used to allocate the internal state */
98
+ free_func zfree; /* used to free the internal state */
99
+ voidpf opaque; /* private data object passed to zalloc and zfree */
100
+
101
+ int data_type; /* best guess about the data type: binary or text */
102
+ uLong adler; /* adler32 value of the uncompressed data */
103
+ uLong reserved; /* reserved for future use */
104
+} z_stream;
105
+
106
+typedef z_stream FAR *z_streamp;
107
+
108
+/*
109
+ gzip header information passed to and from zlib routines. See RFC 1952
110
+ for more details on the meanings of these fields.
111
+*/
112
+typedef struct gz_header_s {
113
+ int text; /* true if compressed data believed to be text */
114
+ uLong time; /* modification time */
115
+ int xflags; /* extra flags (not used when writing a gzip file) */
116
+ int os; /* operating system */
117
+ Bytef *extra; /* pointer to extra field or Z_NULL if none */
118
+ uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
119
+ uInt extra_max; /* space at extra (only when reading header) */
120
+ Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
121
+ uInt name_max; /* space at name (only when reading header) */
122
+ Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
123
+ uInt comm_max; /* space at comment (only when reading header) */
124
+ int hcrc; /* true if there was or will be a header crc */
125
+ int done; /* true when done reading gzip header (not used
126
+ when writing a gzip file) */
127
+} gz_header;
128
+
129
+typedef gz_header FAR *gz_headerp;
130
+
131
+/*
132
+ The application must update next_in and avail_in when avail_in has dropped
133
+ to zero. It must update next_out and avail_out when avail_out has dropped
134
+ to zero. The application must initialize zalloc, zfree and opaque before
135
+ calling the init function. All other fields are set by the compression
136
+ library and must not be updated by the application.
137
+
138
+ The opaque value provided by the application will be passed as the first
139
+ parameter for calls of zalloc and zfree. This can be useful for custom
140
+ memory management. The compression library attaches no meaning to the
141
+ opaque value.
142
+
143
+ zalloc must return Z_NULL if there is not enough memory for the object.
144
+ If zlib is used in a multi-threaded application, zalloc and zfree must be
145
+ thread safe.
146
+
147
+ On 16-bit systems, the functions zalloc and zfree must be able to allocate
148
+ exactly 65536 bytes, but will not be required to allocate more than this if
149
+ the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers
150
+ returned by zalloc for objects of exactly 65536 bytes *must* have their
151
+ offset normalized to zero. The default allocation function provided by this
152
+ library ensures this (see zutil.c). To reduce memory requirements and avoid
153
+ any allocation of 64K objects, at the expense of compression ratio, compile
154
+ the library with -DMAX_WBITS=14 (see zconf.h).
155
+
156
+ The fields total_in and total_out can be used for statistics or progress
157
+ reports. After compression, total_in holds the total size of the
158
+ uncompressed data and may be saved for use in the decompressor (particularly
159
+ if the decompressor wants to decompress everything in a single step).
160
+*/
161
+
162
+ /* constants */
163
+
164
+#define Z_NO_FLUSH 0
165
+#define Z_PARTIAL_FLUSH 1
166
+#define Z_SYNC_FLUSH 2
167
+#define Z_FULL_FLUSH 3
168
+#define Z_FINISH 4
169
+#define Z_BLOCK 5
170
+#define Z_TREES 6
171
+/* Allowed flush values; see deflate() and inflate() below for details */
172
+
173
+#define Z_OK 0
174
+#define Z_STREAM_END 1
175
+#define Z_NEED_DICT 2
176
+#define Z_ERRNO (-1)
177
+#define Z_STREAM_ERROR (-2)
178
+#define Z_DATA_ERROR (-3)
179
+#define Z_MEM_ERROR (-4)
180
+#define Z_BUF_ERROR (-5)
181
+#define Z_VERSION_ERROR (-6)
182
+/* Return codes for the compression/decompression functions. Negative values
183
+ * are errors, positive values are used for special but normal events.
184
+ */
185
+
186
+#define Z_NO_COMPRESSION 0
187
+#define Z_BEST_SPEED 1
188
+#define Z_BEST_COMPRESSION 9
189
+#define Z_DEFAULT_COMPRESSION (-1)
190
+/* compression levels */
191
+
192
+#define Z_FILTERED 1
193
+#define Z_HUFFMAN_ONLY 2
194
+#define Z_RLE 3
195
+#define Z_FIXED 4
196
+#define Z_DEFAULT_STRATEGY 0
197
+/* compression strategy; see deflateInit2() below for details */
198
+
199
+#define Z_BINARY 0
200
+#define Z_TEXT 1
201
+#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
202
+#define Z_UNKNOWN 2
203
+/* Possible values of the data_type field (though see inflate()) */
204
+
205
+#define Z_DEFLATED 8
206
+/* The deflate compression method (the only one supported in this version) */
207
+
208
+#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
209
+
210
+#define zlib_version zlibVersion()
211
+/* for compatibility with versions < 1.0.2 */
212
+
213
+
214
+ /* basic functions */
215
+
216
+ZEXTERN const char * ZEXPORT zlibVersion OF((void));
217
+/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
218
+ If the first character differs, the library code actually used is not
219
+ compatible with the zlib.h header file used by the application. This check
220
+ is automatically made by deflateInit and inflateInit.
221
+ */
222
+
223
+/*
224
+ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
225
+
226
+ Initializes the internal stream state for compression. The fields
227
+ zalloc, zfree and opaque must be initialized before by the caller. If
228
+ zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
229
+ allocation functions.
230
+
231
+ The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
232
+ 1 gives best speed, 9 gives best compression, 0 gives no compression at all
233
+ (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
234
+ requests a default compromise between speed and compression (currently
235
+ equivalent to level 6).
236
+
237
+ deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
238
+ memory, Z_STREAM_ERROR if level is not a valid compression level, or
239
+ Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
240
+ with the version assumed by the caller (ZLIB_VERSION). msg is set to null
241
+ if there is no error message. deflateInit does not perform any compression:
242
+ this will be done by deflate().
243
+*/
244
+
245
+
246
+ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
247
+/*
248
+ deflate compresses as much data as possible, and stops when the input
249
+ buffer becomes empty or the output buffer becomes full. It may introduce
250
+ some output latency (reading input without producing any output) except when
251
+ forced to flush.
252
+
253
+ The detailed semantics are as follows. deflate performs one or both of the
254
+ following actions:
255
+
256
+ - Compress more input starting at next_in and update next_in and avail_in
257
+ accordingly. If not all input can be processed (because there is not
258
+ enough room in the output buffer), next_in and avail_in are updated and
259
+ processing will resume at this point for the next call of deflate().
260
+
261
+ - Provide more output starting at next_out and update next_out and avail_out
262
+ accordingly. This action is forced if the parameter flush is non zero.
263
+ Forcing flush frequently degrades the compression ratio, so this parameter
264
+ should be set only when necessary (in interactive applications). Some
265
+ output may be provided even if flush is not set.
266
+
267
+ Before the call of deflate(), the application should ensure that at least
268
+ one of the actions is possible, by providing more input and/or consuming more
269
+ output, and updating avail_in or avail_out accordingly; avail_out should
270
+ never be zero before the call. The application can consume the compressed
271
+ output when it wants, for example when the output buffer is full (avail_out
272
+ == 0), or after each call of deflate(). If deflate returns Z_OK and with
273
+ zero avail_out, it must be called again after making room in the output
274
+ buffer because there might be more output pending.
275
+
276
+ Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
277
+ decide how much data to accumulate before producing output, in order to
278
+ maximize compression.
279
+
280
+ If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
281
+ flushed to the output buffer and the output is aligned on a byte boundary, so
282
+ that the decompressor can get all input data available so far. (In
283
+ particular avail_in is zero after the call if enough output space has been
284
+ provided before the call.) Flushing may degrade compression for some
285
+ compression algorithms and so it should be used only when necessary. This
286
+ completes the current deflate block and follows it with an empty stored block
287
+ that is three bits plus filler bits to the next byte, followed by four bytes
288
+ (00 00 ff ff).
289
+
290
+ If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
291
+ output buffer, but the output is not aligned to a byte boundary. All of the
292
+ input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
293
+ This completes the current deflate block and follows it with an empty fixed
294
+ codes block that is 10 bits long. This assures that enough bytes are output
295
+ in order for the decompressor to finish the block before the empty fixed code
296
+ block.
297
+
298
+ If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
299
+ for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
300
+ seven bits of the current block are held to be written as the next byte after
301
+ the next deflate block is completed. In this case, the decompressor may not
302
+ be provided enough bits at this point in order to complete decompression of
303
+ the data provided so far to the compressor. It may need to wait for the next
304
+ block to be emitted. This is for advanced applications that need to control
305
+ the emission of deflate blocks.
306
+
307
+ If flush is set to Z_FULL_FLUSH, all output is flushed as with
308
+ Z_SYNC_FLUSH, and the compression state is reset so that decompression can
309
+ restart from this point if previous compressed data has been damaged or if
310
+ random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
311
+ compression.
312
+
313
+ If deflate returns with avail_out == 0, this function must be called again
314
+ with the same value of the flush parameter and more output space (updated
315
+ avail_out), until the flush is complete (deflate returns with non-zero
316
+ avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
317
+ avail_out is greater than six to avoid repeated flush markers due to
318
+ avail_out == 0 on return.
319
+
320
+ If the parameter flush is set to Z_FINISH, pending input is processed,
321
+ pending output is flushed and deflate returns with Z_STREAM_END if there was
322
+ enough output space; if deflate returns with Z_OK, this function must be
323
+ called again with Z_FINISH and more output space (updated avail_out) but no
324
+ more input data, until it returns with Z_STREAM_END or an error. After
325
+ deflate has returned Z_STREAM_END, the only possible operations on the stream
326
+ are deflateReset or deflateEnd.
327
+
328
+ Z_FINISH can be used immediately after deflateInit if all the compression
329
+ is to be done in a single step. In this case, avail_out must be at least the
330
+ value returned by deflateBound (see below). Then deflate is guaranteed to
331
+ return Z_STREAM_END. If not enough output space is provided, deflate will
332
+ not return Z_STREAM_END, and it must be called again as described above.
333
+
334
+ deflate() sets strm->adler to the adler32 checksum of all input read
335
+ so far (that is, total_in bytes).
336
+
337
+ deflate() may update strm->data_type if it can make a good guess about
338
+ the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
339
+ binary. This field is only for information purposes and does not affect the
340
+ compression algorithm in any manner.
341
+
342
+ deflate() returns Z_OK if some progress has been made (more input
343
+ processed or more output produced), Z_STREAM_END if all input has been
344
+ consumed and all output has been produced (only when flush is set to
345
+ Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
346
+ if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
347
+ (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
348
+ fatal, and deflate() can be called again with more input and more output
349
+ space to continue compressing.
350
+*/
351
+
352
+
353
+ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
354
+/*
355
+ All dynamically allocated data structures for this stream are freed.
356
+ This function discards any unprocessed input and does not flush any pending
357
+ output.
358
+
359
+ deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
360
+ stream state was inconsistent, Z_DATA_ERROR if the stream was freed
361
+ prematurely (some input or output was discarded). In the error case, msg
362
+ may be set but then points to a static string (which must not be
363
+ deallocated).
364
+*/
365
+
366
+
367
+/*
368
+ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
369
+
370
+ Initializes the internal stream state for decompression. The fields
371
+ next_in, avail_in, zalloc, zfree and opaque must be initialized before by
372
+ the caller. If next_in is not Z_NULL and avail_in is large enough (the
373
+ exact value depends on the compression method), inflateInit determines the
374
+ compression method from the zlib header and allocates all data structures
375
+ accordingly; otherwise the allocation will be deferred to the first call of
376
+ inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
377
+ use default allocation functions.
378
+
379
+ inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
380
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
381
+ version assumed by the caller, or Z_STREAM_ERROR if the parameters are
382
+ invalid, such as a null pointer to the structure. msg is set to null if
383
+ there is no error message. inflateInit does not perform any decompression
384
+ apart from possibly reading the zlib header if present: actual decompression
385
+ will be done by inflate(). (So next_in and avail_in may be modified, but
386
+ next_out and avail_out are unused and unchanged.) The current implementation
387
+ of inflateInit() does not process any header information -- that is deferred
388
+ until inflate() is called.
389
+*/
390
+
391
+
392
+ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
393
+/*
394
+ inflate decompresses as much data as possible, and stops when the input
395
+ buffer becomes empty or the output buffer becomes full. It may introduce
396
+ some output latency (reading input without producing any output) except when
397
+ forced to flush.
398
+
399
+ The detailed semantics are as follows. inflate performs one or both of the
400
+ following actions:
401
+
402
+ - Decompress more input starting at next_in and update next_in and avail_in
403
+ accordingly. If not all input can be processed (because there is not
404
+ enough room in the output buffer), next_in is updated and processing will
405
+ resume at this point for the next call of inflate().
406
+
407
+ - Provide more output starting at next_out and update next_out and avail_out
408
+ accordingly. inflate() provides as much output as possible, until there is
409
+ no more input data or no more space in the output buffer (see below about
410
+ the flush parameter).
411
+
412
+ Before the call of inflate(), the application should ensure that at least
413
+ one of the actions is possible, by providing more input and/or consuming more
414
+ output, and updating the next_* and avail_* values accordingly. The
415
+ application can consume the uncompressed output when it wants, for example
416
+ when the output buffer is full (avail_out == 0), or after each call of
417
+ inflate(). If inflate returns Z_OK and with zero avail_out, it must be
418
+ called again after making room in the output buffer because there might be
419
+ more output pending.
420
+
421
+ The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
422
+ Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much
423
+ output as possible to the output buffer. Z_BLOCK requests that inflate()
424
+ stop if and when it gets to the next deflate block boundary. When decoding
425
+ the zlib or gzip format, this will cause inflate() to return immediately
426
+ after the header and before the first block. When doing a raw inflate,
427
+ inflate() will go ahead and process the first block, and will return when it
428
+ gets to the end of that block, or when it runs out of data.
429
+
430
+ The Z_BLOCK option assists in appending to or combining deflate streams.
431
+ Also to assist in this, on return inflate() will set strm->data_type to the
432
+ number of unused bits in the last byte taken from strm->next_in, plus 64 if
433
+ inflate() is currently decoding the last block in the deflate stream, plus
434
+ 128 if inflate() returned immediately after decoding an end-of-block code or
435
+ decoding the complete header up to just before the first byte of the deflate
436
+ stream. The end-of-block will not be indicated until all of the uncompressed
437
+ data from that block has been written to strm->next_out. The number of
438
+ unused bits may in general be greater than seven, except when bit 7 of
439
+ data_type is set, in which case the number of unused bits will be less than
440
+ eight. data_type is set as noted here every time inflate() returns for all
441
+ flush options, and so can be used to determine the amount of currently
442
+ consumed input in bits.
443
+
444
+ The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
445
+ end of each deflate block header is reached, before any actual data in that
446
+ block is decoded. This allows the caller to determine the length of the
447
+ deflate block header for later use in random access within a deflate block.
448
+ 256 is added to the value of strm->data_type when inflate() returns
449
+ immediately after reaching the end of the deflate block header.
450
+
451
+ inflate() should normally be called until it returns Z_STREAM_END or an
452
+ error. However if all decompression is to be performed in a single step (a
453
+ single call of inflate), the parameter flush should be set to Z_FINISH. In
454
+ this case all pending input is processed and all pending output is flushed;
455
+ avail_out must be large enough to hold all of the uncompressed data for the
456
+ operation to complete. (The size of the uncompressed data may have been
457
+ saved by the compressor for this purpose.) The use of Z_FINISH is not
458
+ required to perform an inflation in one step. However it may be used to
459
+ inform inflate that a faster approach can be used for the single inflate()
460
+ call. Z_FINISH also informs inflate to not maintain a sliding window if the
461
+ stream completes, which reduces inflate's memory footprint. If the stream
462
+ does not complete, either because not all of the stream is provided or not
463
+ enough output space is provided, then a sliding window will be allocated and
464
+ inflate() can be called again to continue the operation as if Z_NO_FLUSH had
465
+ been used.
466
+
467
+ In this implementation, inflate() always flushes as much output as
468
+ possible to the output buffer, and always uses the faster approach on the
469
+ first call. So the effects of the flush parameter in this implementation are
470
+ on the return value of inflate() as noted below, when inflate() returns early
471
+ when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
472
+ memory for a sliding window when Z_FINISH is used.
473
+
474
+ If a preset dictionary is needed after this call (see inflateSetDictionary
475
+ below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
476
+ chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
477
+ strm->adler to the Adler-32 checksum of all output produced so far (that is,
478
+ total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
479
+ below. At the end of the stream, inflate() checks that its computed adler32
480
+ checksum is equal to that saved by the compressor and returns Z_STREAM_END
481
+ only if the checksum is correct.
482
+
483
+ inflate() can decompress and check either zlib-wrapped or gzip-wrapped
484
+ deflate data. The header type is detected automatically, if requested when
485
+ initializing with inflateInit2(). Any information contained in the gzip
486
+ header is not retained, so applications that need that information should
487
+ instead use raw inflate, see inflateInit2() below, or inflateBack() and
488
+ perform their own processing of the gzip header and trailer. When processing
489
+ gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
490
+ producted so far. The CRC-32 is checked against the gzip trailer.
491
+
492
+ inflate() returns Z_OK if some progress has been made (more input processed
493
+ or more output produced), Z_STREAM_END if the end of the compressed data has
494
+ been reached and all uncompressed output has been produced, Z_NEED_DICT if a
495
+ preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
496
+ corrupted (input stream not conforming to the zlib format or incorrect check
497
+ value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
498
+ next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
499
+ Z_BUF_ERROR if no progress is possible or if there was not enough room in the
500
+ output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
501
+ inflate() can be called again with more input and more output space to
502
+ continue decompressing. If Z_DATA_ERROR is returned, the application may
503
+ then call inflateSync() to look for a good compression block if a partial
504
+ recovery of the data is desired.
505
+*/
506
+
507
+
508
+ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
509
+/*
510
+ All dynamically allocated data structures for this stream are freed.
511
+ This function discards any unprocessed input and does not flush any pending
512
+ output.
513
+
514
+ inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
515
+ was inconsistent. In the error case, msg may be set but then points to a
516
+ static string (which must not be deallocated).
517
+*/
518
+
519
+
520
+ /* Advanced functions */
521
+
522
+/*
523
+ The following functions are needed only in some special applications.
524
+*/
525
+
526
+/*
527
+ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
528
+ int level,
529
+ int method,
530
+ int windowBits,
531
+ int memLevel,
532
+ int strategy));
533
+
534
+ This is another version of deflateInit with more compression options. The
535
+ fields next_in, zalloc, zfree and opaque must be initialized before by the
536
+ caller.
537
+
538
+ The method parameter is the compression method. It must be Z_DEFLATED in
539
+ this version of the library.
540
+
541
+ The windowBits parameter is the base two logarithm of the window size
542
+ (the size of the history buffer). It should be in the range 8..15 for this
543
+ version of the library. Larger values of this parameter result in better
544
+ compression at the expense of memory usage. The default value is 15 if
545
+ deflateInit is used instead.
546
+
547
+ windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
548
+ determines the window size. deflate() will then generate raw deflate data
549
+ with no zlib header or trailer, and will not compute an adler32 check value.
550
+
551
+ windowBits can also be greater than 15 for optional gzip encoding. Add
552
+ 16 to windowBits to write a simple gzip header and trailer around the
553
+ compressed data instead of a zlib wrapper. The gzip header will have no
554
+ file name, no extra data, no comment, no modification time (set to zero), no
555
+ header crc, and the operating system will be set to 255 (unknown). If a
556
+ gzip stream is being written, strm->adler is a crc32 instead of an adler32.
557
+
558
+ The memLevel parameter specifies how much memory should be allocated
559
+ for the internal compression state. memLevel=1 uses minimum memory but is
560
+ slow and reduces compression ratio; memLevel=9 uses maximum memory for
561
+ optimal speed. The default value is 8. See zconf.h for total memory usage
562
+ as a function of windowBits and memLevel.
563
+
564
+ The strategy parameter is used to tune the compression algorithm. Use the
565
+ value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
566
+ filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
567
+ string match), or Z_RLE to limit match distances to one (run-length
568
+ encoding). Filtered data consists mostly of small values with a somewhat
569
+ random distribution. In this case, the compression algorithm is tuned to
570
+ compress them better. The effect of Z_FILTERED is to force more Huffman
571
+ coding and less string matching; it is somewhat intermediate between
572
+ Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as
573
+ fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
574
+ strategy parameter only affects the compression ratio but not the
575
+ correctness of the compressed output even if it is not set appropriately.
576
+ Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler
577
+ decoder for special applications.
578
+
579
+ deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
580
+ memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid
581
+ method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is
582
+ incompatible with the version assumed by the caller (ZLIB_VERSION). msg is
583
+ set to null if there is no error message. deflateInit2 does not perform any
584
+ compression: this will be done by deflate().
585
+*/
586
+
587
+ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
588
+ const Bytef *dictionary,
589
+ uInt dictLength));
590
+/*
591
+ Initializes the compression dictionary from the given byte sequence
592
+ without producing any compressed output. When using the zlib format, this
593
+ function must be called immediately after deflateInit, deflateInit2 or
594
+ deflateReset, and before any call of deflate. When doing raw deflate, this
595
+ function must be called either before any call of deflate, or immediately
596
+ after the completion of a deflate block, i.e. after all input has been
597
+ consumed and all output has been delivered when using any of the flush
598
+ options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The
599
+ compressor and decompressor must use exactly the same dictionary (see
600
+ inflateSetDictionary).
601
+
602
+ The dictionary should consist of strings (byte sequences) that are likely
603
+ to be encountered later in the data to be compressed, with the most commonly
604
+ used strings preferably put towards the end of the dictionary. Using a
605
+ dictionary is most useful when the data to be compressed is short and can be
606
+ predicted with good accuracy; the data can then be compressed better than
607
+ with the default empty dictionary.
608
+
609
+ Depending on the size of the compression data structures selected by
610
+ deflateInit or deflateInit2, a part of the dictionary may in effect be
611
+ discarded, for example if the dictionary is larger than the window size
612
+ provided in deflateInit or deflateInit2. Thus the strings most likely to be
613
+ useful should be put at the end of the dictionary, not at the front. In
614
+ addition, the current implementation of deflate will use at most the window
615
+ size minus 262 bytes of the provided dictionary.
616
+
617
+ Upon return of this function, strm->adler is set to the adler32 value
618
+ of the dictionary; the decompressor may later use this value to determine
619
+ which dictionary has been used by the compressor. (The adler32 value
620
+ applies to the whole dictionary even if only a subset of the dictionary is
621
+ actually used by the compressor.) If a raw deflate was requested, then the
622
+ adler32 value is not computed and strm->adler is not set.
623
+
624
+ deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
625
+ parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
626
+ inconsistent (for example if deflate has already been called for this stream
627
+ or if not at a block boundary for raw deflate). deflateSetDictionary does
628
+ not perform any compression: this will be done by deflate().
629
+*/
630
+
631
+ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
632
+ z_streamp source));
633
+/*
634
+ Sets the destination stream as a complete copy of the source stream.
635
+
636
+ This function can be useful when several compression strategies will be
637
+ tried, for example when there are several ways of pre-processing the input
638
+ data with a filter. The streams that will be discarded should then be freed
639
+ by calling deflateEnd. Note that deflateCopy duplicates the internal
640
+ compression state which can be quite large, so this strategy is slow and can
641
+ consume lots of memory.
642
+
643
+ deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
644
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
645
+ (such as zalloc being Z_NULL). msg is left unchanged in both source and
646
+ destination.
647
+*/
648
+
649
+ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
650
+/*
651
+ This function is equivalent to deflateEnd followed by deflateInit,
652
+ but does not free and reallocate all the internal compression state. The
653
+ stream will keep the same compression level and any other attributes that
654
+ may have been set by deflateInit2.
655
+
656
+ deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
657
+ stream state was inconsistent (such as zalloc or state being Z_NULL).
658
+*/
659
+
660
+ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
661
+ int level,
662
+ int strategy));
663
+/*
664
+ Dynamically update the compression level and compression strategy. The
665
+ interpretation of level and strategy is as in deflateInit2. This can be
666
+ used to switch between compression and straight copy of the input data, or
667
+ to switch to a different kind of input data requiring a different strategy.
668
+ If the compression level is changed, the input available so far is
669
+ compressed with the old level (and may be flushed); the new level will take
670
+ effect only at the next call of deflate().
671
+
672
+ Before the call of deflateParams, the stream state must be set as for
673
+ a call of deflate(), since the currently available input may have to be
674
+ compressed and flushed. In particular, strm->avail_out must be non-zero.
675
+
676
+ deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
677
+ stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
678
+ strm->avail_out was zero.
679
+*/
680
+
681
+ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
682
+ int good_length,
683
+ int max_lazy,
684
+ int nice_length,
685
+ int max_chain));
686
+/*
687
+ Fine tune deflate's internal compression parameters. This should only be
688
+ used by someone who understands the algorithm used by zlib's deflate for
689
+ searching for the best matching string, and even then only by the most
690
+ fanatic optimizer trying to squeeze out the last compressed bit for their
691
+ specific input data. Read the deflate.c source code for the meaning of the
692
+ max_lazy, good_length, nice_length, and max_chain parameters.
693
+
694
+ deflateTune() can be called after deflateInit() or deflateInit2(), and
695
+ returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
696
+ */
697
+
698
+ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
699
+ uLong sourceLen));
700
+/*
701
+ deflateBound() returns an upper bound on the compressed size after
702
+ deflation of sourceLen bytes. It must be called after deflateInit() or
703
+ deflateInit2(), and after deflateSetHeader(), if used. This would be used
704
+ to allocate an output buffer for deflation in a single pass, and so would be
705
+ called before deflate(). If that first deflate() call is provided the
706
+ sourceLen input bytes, an output buffer allocated to the size returned by
707
+ deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
708
+ to return Z_STREAM_END. Note that it is possible for the compressed size to
709
+ be larger than the value returned by deflateBound() if flush options other
710
+ than Z_FINISH or Z_NO_FLUSH are used.
711
+*/
712
+
713
+ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
714
+ unsigned *pending,
715
+ int *bits));
716
+/*
717
+ deflatePending() returns the number of bytes and bits of output that have
718
+ been generated, but not yet provided in the available output. The bytes not
719
+ provided would be due to the available output space having being consumed.
720
+ The number of bits of output not provided are between 0 and 7, where they
721
+ await more bits to join them in order to fill out a full byte. If pending
722
+ or bits are Z_NULL, then those values are not set.
723
+
724
+ deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
725
+ stream state was inconsistent.
726
+ */
727
+
728
+ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
729
+ int bits,
730
+ int value));
731
+/*
732
+ deflatePrime() inserts bits in the deflate output stream. The intent
733
+ is that this function is used to start off the deflate output with the bits
734
+ leftover from a previous deflate stream when appending to it. As such, this
735
+ function can only be used for raw deflate, and must be used before the first
736
+ deflate() call after a deflateInit2() or deflateReset(). bits must be less
737
+ than or equal to 16, and that many of the least significant bits of value
738
+ will be inserted in the output.
739
+
740
+ deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
741
+ room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
742
+ source stream state was inconsistent.
743
+*/
744
+
745
+ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
746
+ gz_headerp head));
747
+/*
748
+ deflateSetHeader() provides gzip header information for when a gzip
749
+ stream is requested by deflateInit2(). deflateSetHeader() may be called
750
+ after deflateInit2() or deflateReset() and before the first call of
751
+ deflate(). The text, time, os, extra field, name, and comment information
752
+ in the provided gz_header structure are written to the gzip header (xflag is
753
+ ignored -- the extra flags are set according to the compression level). The
754
+ caller must assure that, if not Z_NULL, name and comment are terminated with
755
+ a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
756
+ available there. If hcrc is true, a gzip header crc is included. Note that
757
+ the current versions of the command-line version of gzip (up through version
758
+ 1.3.x) do not support header crc's, and will report that it is a "multi-part
759
+ gzip file" and give up.
760
+
761
+ If deflateSetHeader is not used, the default gzip header has text false,
762
+ the time set to zero, and os set to 255, with no extra, name, or comment
763
+ fields. The gzip header is returned to the default state by deflateReset().
764
+
765
+ deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
766
+ stream state was inconsistent.
767
+*/
768
+
769
+/*
770
+ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
771
+ int windowBits));
772
+
773
+ This is another version of inflateInit with an extra parameter. The
774
+ fields next_in, avail_in, zalloc, zfree and opaque must be initialized
775
+ before by the caller.
776
+
777
+ The windowBits parameter is the base two logarithm of the maximum window
778
+ size (the size of the history buffer). It should be in the range 8..15 for
779
+ this version of the library. The default value is 15 if inflateInit is used
780
+ instead. windowBits must be greater than or equal to the windowBits value
781
+ provided to deflateInit2() while compressing, or it must be equal to 15 if
782
+ deflateInit2() was not used. If a compressed stream with a larger window
783
+ size is given as input, inflate() will return with the error code
784
+ Z_DATA_ERROR instead of trying to allocate a larger window.
785
+
786
+ windowBits can also be zero to request that inflate use the window size in
787
+ the zlib header of the compressed stream.
788
+
789
+ windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
790
+ determines the window size. inflate() will then process raw deflate data,
791
+ not looking for a zlib or gzip header, not generating a check value, and not
792
+ looking for any check values for comparison at the end of the stream. This
793
+ is for use with other formats that use the deflate compressed data format
794
+ such as zip. Those formats provide their own check values. If a custom
795
+ format is developed using the raw deflate format for compressed data, it is
796
+ recommended that a check value such as an adler32 or a crc32 be applied to
797
+ the uncompressed data as is done in the zlib, gzip, and zip formats. For
798
+ most applications, the zlib format should be used as is. Note that comments
799
+ above on the use in deflateInit2() applies to the magnitude of windowBits.
800
+
801
+ windowBits can also be greater than 15 for optional gzip decoding. Add
802
+ 32 to windowBits to enable zlib and gzip decoding with automatic header
803
+ detection, or add 16 to decode only the gzip format (the zlib format will
804
+ return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
805
+ crc32 instead of an adler32.
806
+
807
+ inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
808
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
809
+ version assumed by the caller, or Z_STREAM_ERROR if the parameters are
810
+ invalid, such as a null pointer to the structure. msg is set to null if
811
+ there is no error message. inflateInit2 does not perform any decompression
812
+ apart from possibly reading the zlib header if present: actual decompression
813
+ will be done by inflate(). (So next_in and avail_in may be modified, but
814
+ next_out and avail_out are unused and unchanged.) The current implementation
815
+ of inflateInit2() does not process any header information -- that is
816
+ deferred until inflate() is called.
817
+*/
818
+
819
+ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
820
+ const Bytef *dictionary,
821
+ uInt dictLength));
822
+/*
823
+ Initializes the decompression dictionary from the given uncompressed byte
824
+ sequence. This function must be called immediately after a call of inflate,
825
+ if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
826
+ can be determined from the adler32 value returned by that call of inflate.
827
+ The compressor and decompressor must use exactly the same dictionary (see
828
+ deflateSetDictionary). For raw inflate, this function can be called at any
829
+ time to set the dictionary. If the provided dictionary is smaller than the
830
+ window and there is already data in the window, then the provided dictionary
831
+ will amend what's there. The application must insure that the dictionary
832
+ that was used for compression is provided.
833
+
834
+ inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
835
+ parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
836
+ inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
837
+ expected one (incorrect adler32 value). inflateSetDictionary does not
838
+ perform any decompression: this will be done by subsequent calls of
839
+ inflate().
840
+*/
841
+
842
+ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
843
+/*
844
+ Skips invalid compressed data until a possible full flush point (see above
845
+ for the description of deflate with Z_FULL_FLUSH) can be found, or until all
846
+ available input is skipped. No output is provided.
847
+
848
+ inflateSync searches for a 00 00 FF FF pattern in the compressed data.
849
+ All full flush points have this pattern, but not all occurences of this
850
+ pattern are full flush points.
851
+
852
+ inflateSync returns Z_OK if a possible full flush point has been found,
853
+ Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
854
+ has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
855
+ In the success case, the application may save the current current value of
856
+ total_in which indicates where valid compressed data was found. In the
857
+ error case, the application may repeatedly call inflateSync, providing more
858
+ input each time, until success or end of the input data.
859
+*/
860
+
861
+ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
862
+ z_streamp source));
863
+/*
864
+ Sets the destination stream as a complete copy of the source stream.
865
+
866
+ This function can be useful when randomly accessing a large stream. The
867
+ first pass through the stream can periodically record the inflate state,
868
+ allowing restarting inflate at those points when randomly accessing the
869
+ stream.
870
+
871
+ inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
872
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
873
+ (such as zalloc being Z_NULL). msg is left unchanged in both source and
874
+ destination.
875
+*/
876
+
877
+ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
878
+/*
879
+ This function is equivalent to inflateEnd followed by inflateInit,
880
+ but does not free and reallocate all the internal decompression state. The
881
+ stream will keep attributes that may have been set by inflateInit2.
882
+
883
+ inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
884
+ stream state was inconsistent (such as zalloc or state being Z_NULL).
885
+*/
886
+
887
+ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
888
+ int windowBits));
889
+/*
890
+ This function is the same as inflateReset, but it also permits changing
891
+ the wrap and window size requests. The windowBits parameter is interpreted
892
+ the same as it is for inflateInit2.
893
+
894
+ inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
895
+ stream state was inconsistent (such as zalloc or state being Z_NULL), or if
896
+ the windowBits parameter is invalid.
897
+*/
898
+
899
+ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
900
+ int bits,
901
+ int value));
902
+/*
903
+ This function inserts bits in the inflate input stream. The intent is
904
+ that this function is used to start inflating at a bit position in the
905
+ middle of a byte. The provided bits will be used before any bytes are used
906
+ from next_in. This function should only be used with raw inflate, and
907
+ should be used before the first inflate() call after inflateInit2() or
908
+ inflateReset(). bits must be less than or equal to 16, and that many of the
909
+ least significant bits of value will be inserted in the input.
910
+
911
+ If bits is negative, then the input stream bit buffer is emptied. Then
912
+ inflatePrime() can be called again to put bits in the buffer. This is used
913
+ to clear out bits leftover after feeding inflate a block description prior
914
+ to feeding inflate codes.
915
+
916
+ inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
917
+ stream state was inconsistent.
918
+*/
919
+
920
+ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
921
+/*
922
+ This function returns two values, one in the lower 16 bits of the return
923
+ value, and the other in the remaining upper bits, obtained by shifting the
924
+ return value down 16 bits. If the upper value is -1 and the lower value is
925
+ zero, then inflate() is currently decoding information outside of a block.
926
+ If the upper value is -1 and the lower value is non-zero, then inflate is in
927
+ the middle of a stored block, with the lower value equaling the number of
928
+ bytes from the input remaining to copy. If the upper value is not -1, then
929
+ it is the number of bits back from the current bit position in the input of
930
+ the code (literal or length/distance pair) currently being processed. In
931
+ that case the lower value is the number of bytes already emitted for that
932
+ code.
933
+
934
+ A code is being processed if inflate is waiting for more input to complete
935
+ decoding of the code, or if it has completed decoding but is waiting for
936
+ more output space to write the literal or match data.
937
+
938
+ inflateMark() is used to mark locations in the input data for random
939
+ access, which may be at bit positions, and to note those cases where the
940
+ output of a code may span boundaries of random access blocks. The current
941
+ location in the input stream can be determined from avail_in and data_type
942
+ as noted in the description for the Z_BLOCK flush parameter for inflate.
943
+
944
+ inflateMark returns the value noted above or -1 << 16 if the provided
945
+ source stream state was inconsistent.
946
+*/
947
+
948
+ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
949
+ gz_headerp head));
950
+/*
951
+ inflateGetHeader() requests that gzip header information be stored in the
952
+ provided gz_header structure. inflateGetHeader() may be called after
953
+ inflateInit2() or inflateReset(), and before the first call of inflate().
954
+ As inflate() processes the gzip stream, head->done is zero until the header
955
+ is completed, at which time head->done is set to one. If a zlib stream is
956
+ being decoded, then head->done is set to -1 to indicate that there will be
957
+ no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be
958
+ used to force inflate() to return immediately after header processing is
959
+ complete and before any actual data is decompressed.
960
+
961
+ The text, time, xflags, and os fields are filled in with the gzip header
962
+ contents. hcrc is set to true if there is a header CRC. (The header CRC
963
+ was valid if done is set to one.) If extra is not Z_NULL, then extra_max
964
+ contains the maximum number of bytes to write to extra. Once done is true,
965
+ extra_len contains the actual extra field length, and extra contains the
966
+ extra field, or that field truncated if extra_max is less than extra_len.
967
+ If name is not Z_NULL, then up to name_max characters are written there,
968
+ terminated with a zero unless the length is greater than name_max. If
969
+ comment is not Z_NULL, then up to comm_max characters are written there,
970
+ terminated with a zero unless the length is greater than comm_max. When any
971
+ of extra, name, or comment are not Z_NULL and the respective field is not
972
+ present in the header, then that field is set to Z_NULL to signal its
973
+ absence. This allows the use of deflateSetHeader() with the returned
974
+ structure to duplicate the header. However if those fields are set to
975
+ allocated memory, then the application will need to save those pointers
976
+ elsewhere so that they can be eventually freed.
977
+
978
+ If inflateGetHeader is not used, then the header information is simply
979
+ discarded. The header is always checked for validity, including the header
980
+ CRC if present. inflateReset() will reset the process to discard the header
981
+ information. The application would need to call inflateGetHeader() again to
982
+ retrieve the header from the next gzip stream.
983
+
984
+ inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
985
+ stream state was inconsistent.
986
+*/
987
+
988
+/*
989
+ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
990
+ unsigned char FAR *window));
991
+
992
+ Initialize the internal stream state for decompression using inflateBack()
993
+ calls. The fields zalloc, zfree and opaque in strm must be initialized
994
+ before the call. If zalloc and zfree are Z_NULL, then the default library-
995
+ derived memory allocation routines are used. windowBits is the base two
996
+ logarithm of the window size, in the range 8..15. window is a caller
997
+ supplied buffer of that size. Except for special applications where it is
998
+ assured that deflate was used with small window sizes, windowBits must be 15
999
+ and a 32K byte window must be supplied to be able to decompress general
1000
+ deflate streams.
1001
+
1002
+ See inflateBack() for the usage of these routines.
1003
+
1004
+ inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
1005
+ the parameters are invalid, Z_MEM_ERROR if the internal state could not be
1006
+ allocated, or Z_VERSION_ERROR if the version of the library does not match
1007
+ the version of the header file.
1008
+*/
1009
+
1010
+typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
1011
+typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
1012
+
1013
+ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1014
+ in_func in, void FAR *in_desc,
1015
+ out_func out, void FAR *out_desc));
1016
+/*
1017
+ inflateBack() does a raw inflate with a single call using a call-back
1018
+ interface for input and output. This is more efficient than inflate() for
1019
+ file i/o applications in that it avoids copying between the output and the
1020
+ sliding window by simply making the window itself the output buffer. This
1021
+ function trusts the application to not change the output buffer passed by
1022
+ the output function, at least until inflateBack() returns.
1023
+
1024
+ inflateBackInit() must be called first to allocate the internal state
1025
+ and to initialize the state with the user-provided window buffer.
1026
+ inflateBack() may then be used multiple times to inflate a complete, raw
1027
+ deflate stream with each call. inflateBackEnd() is then called to free the
1028
+ allocated state.
1029
+
1030
+ A raw deflate stream is one with no zlib or gzip header or trailer.
1031
+ This routine would normally be used in a utility that reads zip or gzip
1032
+ files and writes out uncompressed files. The utility would decode the
1033
+ header and process the trailer on its own, hence this routine expects only
1034
+ the raw deflate stream to decompress. This is different from the normal
1035
+ behavior of inflate(), which expects either a zlib or gzip header and
1036
+ trailer around the deflate stream.
1037
+
1038
+ inflateBack() uses two subroutines supplied by the caller that are then
1039
+ called by inflateBack() for input and output. inflateBack() calls those
1040
+ routines until it reads a complete deflate stream and writes out all of the
1041
+ uncompressed data, or until it encounters an error. The function's
1042
+ parameters and return types are defined above in the in_func and out_func
1043
+ typedefs. inflateBack() will call in(in_desc, &buf) which should return the
1044
+ number of bytes of provided input, and a pointer to that input in buf. If
1045
+ there is no input available, in() must return zero--buf is ignored in that
1046
+ case--and inflateBack() will return a buffer error. inflateBack() will call
1047
+ out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out()
1048
+ should return zero on success, or non-zero on failure. If out() returns
1049
+ non-zero, inflateBack() will return with an error. Neither in() nor out()
1050
+ are permitted to change the contents of the window provided to
1051
+ inflateBackInit(), which is also the buffer that out() uses to write from.
1052
+ The length written by out() will be at most the window size. Any non-zero
1053
+ amount of input may be provided by in().
1054
+
1055
+ For convenience, inflateBack() can be provided input on the first call by
1056
+ setting strm->next_in and strm->avail_in. If that input is exhausted, then
1057
+ in() will be called. Therefore strm->next_in must be initialized before
1058
+ calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
1059
+ immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
1060
+ must also be initialized, and then if strm->avail_in is not zero, input will
1061
+ initially be taken from strm->next_in[0 .. strm->avail_in - 1].
1062
+
1063
+ The in_desc and out_desc parameters of inflateBack() is passed as the
1064
+ first parameter of in() and out() respectively when they are called. These
1065
+ descriptors can be optionally used to pass any information that the caller-
1066
+ supplied in() and out() functions need to do their job.
1067
+
1068
+ On return, inflateBack() will set strm->next_in and strm->avail_in to
1069
+ pass back any unused input that was provided by the last in() call. The
1070
+ return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
1071
+ if in() or out() returned an error, Z_DATA_ERROR if there was a format error
1072
+ in the deflate stream (in which case strm->msg is set to indicate the nature
1073
+ of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
1074
+ In the case of Z_BUF_ERROR, an input or output error can be distinguished
1075
+ using strm->next_in which will be Z_NULL only if in() returned an error. If
1076
+ strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
1077
+ non-zero. (in() will always be called before out(), so strm->next_in is
1078
+ assured to be defined if out() returns non-zero.) Note that inflateBack()
1079
+ cannot return Z_OK.
1080
+*/
1081
+
1082
+ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
1083
+/*
1084
+ All memory allocated by inflateBackInit() is freed.
1085
+
1086
+ inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
1087
+ state was inconsistent.
1088
+*/
1089
+
1090
+ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
1091
+/* Return flags indicating compile-time options.
1092
+
1093
+ Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
1094
+ 1.0: size of uInt
1095
+ 3.2: size of uLong
1096
+ 5.4: size of voidpf (pointer)
1097
+ 7.6: size of z_off_t
1098
+
1099
+ Compiler, assembler, and debug options:
1100
+ 8: DEBUG
1101
+ 9: ASMV or ASMINF -- use ASM code
1102
+ 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
1103
+ 11: 0 (reserved)
1104
+
1105
+ One-time table building (smaller code, but not thread-safe if true):
1106
+ 12: BUILDFIXED -- build static block decoding tables when needed
1107
+ 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
1108
+ 14,15: 0 (reserved)
1109
+
1110
+ Library content (indicates missing functionality):
1111
+ 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
1112
+ deflate code when not needed)
1113
+ 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
1114
+ and decode gzip streams (to avoid linking crc code)
1115
+ 18-19: 0 (reserved)
1116
+
1117
+ Operation variations (changes in library functionality):
1118
+ 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
1119
+ 21: FASTEST -- deflate algorithm with only one, lowest compression level
1120
+ 22,23: 0 (reserved)
1121
+
1122
+ The sprintf variant used by gzprintf (zero is best):
1123
+ 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
1124
+ 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
1125
+ 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
1126
+
1127
+ Remainder:
1128
+ 27-31: 0 (reserved)
1129
+ */
1130
+
1131
+#ifndef Z_SOLO
1132
+
1133
+ /* utility functions */
1134
+
1135
+/*
1136
+ The following utility functions are implemented on top of the basic
1137
+ stream-oriented functions. To simplify the interface, some default options
1138
+ are assumed (compression level and memory usage, standard memory allocation
1139
+ functions). The source code of these utility functions can be modified if
1140
+ you need special options.
1141
+*/
1142
+
1143
+ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
1144
+ const Bytef *source, uLong sourceLen));
1145
+/*
1146
+ Compresses the source buffer into the destination buffer. sourceLen is
1147
+ the byte length of the source buffer. Upon entry, destLen is the total size
1148
+ of the destination buffer, which must be at least the value returned by
1149
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
1150
+ compressed buffer.
1151
+
1152
+ compress returns Z_OK if success, Z_MEM_ERROR if there was not
1153
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
1154
+ buffer.
1155
+*/
1156
+
1157
+ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1158
+ const Bytef *source, uLong sourceLen,
1159
+ int level));
1160
+/*
1161
+ Compresses the source buffer into the destination buffer. The level
1162
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
1163
+ length of the source buffer. Upon entry, destLen is the total size of the
1164
+ destination buffer, which must be at least the value returned by
1165
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
1166
+ compressed buffer.
1167
+
1168
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1169
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1170
+ Z_STREAM_ERROR if the level parameter is invalid.
1171
+*/
1172
+
1173
+ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
1174
+/*
1175
+ compressBound() returns an upper bound on the compressed size after
1176
+ compress() or compress2() on sourceLen bytes. It would be used before a
1177
+ compress() or compress2() call to allocate the destination buffer.
1178
+*/
1179
+
1180
+ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1181
+ const Bytef *source, uLong sourceLen));
1182
+/*
1183
+ Decompresses the source buffer into the destination buffer. sourceLen is
1184
+ the byte length of the source buffer. Upon entry, destLen is the total size
1185
+ of the destination buffer, which must be large enough to hold the entire
1186
+ uncompressed data. (The size of the uncompressed data must have been saved
1187
+ previously by the compressor and transmitted to the decompressor by some
1188
+ mechanism outside the scope of this compression library.) Upon exit, destLen
1189
+ is the actual size of the uncompressed buffer.
1190
+
1191
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
1192
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
1193
+ buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
1194
+ the case where there is not enough room, uncompress() will fill the output
1195
+ buffer with the uncompressed data up to that point.
1196
+*/
1197
+
1198
+ /* gzip file access functions */
1199
+
1200
+/*
1201
+ This library supports reading and writing files in gzip (.gz) format with
1202
+ an interface similar to that of stdio, using the functions that start with
1203
+ "gz". The gzip format is different from the zlib format. gzip is a gzip
1204
+ wrapper, documented in RFC 1952, wrapped around a deflate stream.
1205
+*/
1206
+
1207
+typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
1208
+
1209
+/*
1210
+ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
1211
+
1212
+ Opens a gzip (.gz) file for reading or writing. The mode parameter is as
1213
+ in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
1214
+ a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
1215
+ compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
1216
+ for fixed code compression as in "wb9F". (See the description of
1217
+ deflateInit2 for more information about the strategy parameter.) 'T' will
1218
+ request transparent writing or appending with no compression and not using
1219
+ the gzip format.
1220
+
1221
+ "a" can be used instead of "w" to request that the gzip stream that will
1222
+ be written be appended to the file. "+" will result in an error, since
1223
+ reading and writing to the same gzip file is not supported. The addition of
1224
+ "x" when writing will create the file exclusively, which fails if the file
1225
+ already exists. On systems that support it, the addition of "e" when
1226
+ reading or writing will set the flag to close the file on an execve() call.
1227
+
1228
+ These functions, as well as gzip, will read and decode a sequence of gzip
1229
+ streams in a file. The append function of gzopen() can be used to create
1230
+ such a file. (Also see gzflush() for another way to do this.) When
1231
+ appending, gzopen does not test whether the file begins with a gzip stream,
1232
+ nor does it look for the end of the gzip streams to begin appending. gzopen
1233
+ will simply append a gzip stream to the existing file.
1234
+
1235
+ gzopen can be used to read a file which is not in gzip format; in this
1236
+ case gzread will directly read from the file without decompression. When
1237
+ reading, this will be detected automatically by looking for the magic two-
1238
+ byte gzip header.
1239
+
1240
+ gzopen returns NULL if the file could not be opened, if there was
1241
+ insufficient memory to allocate the gzFile state, or if an invalid mode was
1242
+ specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
1243
+ errno can be checked to determine if the reason gzopen failed was that the
1244
+ file could not be opened.
1245
+*/
1246
+
1247
+ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
1248
+/*
1249
+ gzdopen associates a gzFile with the file descriptor fd. File descriptors
1250
+ are obtained from calls like open, dup, creat, pipe or fileno (if the file
1251
+ has been previously opened with fopen). The mode parameter is as in gzopen.
1252
+
1253
+ The next call of gzclose on the returned gzFile will also close the file
1254
+ descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
1255
+ fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
1256
+ mode);. The duplicated descriptor should be saved to avoid a leak, since
1257
+ gzdopen does not close fd if it fails. If you are using fileno() to get the
1258
+ file descriptor from a FILE *, then you will have to use dup() to avoid
1259
+ double-close()ing the file descriptor. Both gzclose() and fclose() will
1260
+ close the associated file descriptor, so they need to have different file
1261
+ descriptors.
1262
+
1263
+ gzdopen returns NULL if there was insufficient memory to allocate the
1264
+ gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
1265
+ provided, or '+' was provided), or if fd is -1. The file descriptor is not
1266
+ used until the next gz* read, write, seek, or close operation, so gzdopen
1267
+ will not detect if fd is invalid (unless fd is -1).
1268
+*/
1269
+
1270
+ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
1271
+/*
1272
+ Set the internal buffer size used by this library's functions. The
1273
+ default buffer size is 8192 bytes. This function must be called after
1274
+ gzopen() or gzdopen(), and before any other calls that read or write the
1275
+ file. The buffer memory allocation is always deferred to the first read or
1276
+ write. Two buffers are allocated, either both of the specified size when
1277
+ writing, or one of the specified size and the other twice that size when
1278
+ reading. A larger buffer size of, for example, 64K or 128K bytes will
1279
+ noticeably increase the speed of decompression (reading).
1280
+
1281
+ The new buffer size also affects the maximum length for gzprintf().
1282
+
1283
+ gzbuffer() returns 0 on success, or -1 on failure, such as being called
1284
+ too late.
1285
+*/
1286
+
1287
+ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1288
+/*
1289
+ Dynamically update the compression level or strategy. See the description
1290
+ of deflateInit2 for the meaning of these parameters.
1291
+
1292
+ gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
1293
+ opened for writing.
1294
+*/
1295
+
1296
+ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
1297
+/*
1298
+ Reads the given number of uncompressed bytes from the compressed file. If
1299
+ the input file is not in gzip format, gzread copies the given number of
1300
+ bytes into the buffer directly from the file.
1301
+
1302
+ After reaching the end of a gzip stream in the input, gzread will continue
1303
+ to read, looking for another gzip stream. Any number of gzip streams may be
1304
+ concatenated in the input file, and will all be decompressed by gzread().
1305
+ If something other than a gzip stream is encountered after a gzip stream,
1306
+ that remaining trailing garbage is ignored (and no error is returned).
1307
+
1308
+ gzread can be used to read a gzip file that is being concurrently written.
1309
+ Upon reaching the end of the input, gzread will return with the available
1310
+ data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
1311
+ gzclearerr can be used to clear the end of file indicator in order to permit
1312
+ gzread to be tried again. Z_OK indicates that a gzip stream was completed
1313
+ on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
1314
+ middle of a gzip stream. Note that gzread does not return -1 in the event
1315
+ of an incomplete gzip stream. This error is deferred until gzclose(), which
1316
+ will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
1317
+ stream. Alternatively, gzerror can be used before gzclose to detect this
1318
+ case.
1319
+
1320
+ gzread returns the number of uncompressed bytes actually read, less than
1321
+ len for end of file, or -1 for error.
1322
+*/
1323
+
1324
+ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
1325
+ voidpc buf, unsigned len));
1326
+/*
1327
+ Writes the given number of uncompressed bytes into the compressed file.
1328
+ gzwrite returns the number of uncompressed bytes written or 0 in case of
1329
+ error.
1330
+*/
1331
+
1332
+ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
1333
+/*
1334
+ Converts, formats, and writes the arguments to the compressed file under
1335
+ control of the format string, as in fprintf. gzprintf returns the number of
1336
+ uncompressed bytes actually written, or 0 in case of error. The number of
1337
+ uncompressed bytes written is limited to 8191, or one less than the buffer
1338
+ size given to gzbuffer(). The caller should assure that this limit is not
1339
+ exceeded. If it is exceeded, then gzprintf() will return an error (0) with
1340
+ nothing written. In this case, there may also be a buffer overflow with
1341
+ unpredictable consequences, which is possible only if zlib was compiled with
1342
+ the insecure functions sprintf() or vsprintf() because the secure snprintf()
1343
+ or vsnprintf() functions were not available. This can be determined using
1344
+ zlibCompileFlags().
1345
+*/
1346
+
1347
+ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1348
+/*
1349
+ Writes the given null-terminated string to the compressed file, excluding
1350
+ the terminating null character.
1351
+
1352
+ gzputs returns the number of characters written, or -1 in case of error.
1353
+*/
1354
+
1355
+ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1356
+/*
1357
+ Reads bytes from the compressed file until len-1 characters are read, or a
1358
+ newline character is read and transferred to buf, or an end-of-file
1359
+ condition is encountered. If any characters are read or if len == 1, the
1360
+ string is terminated with a null character. If no characters are read due
1361
+ to an end-of-file or len < 1, then the buffer is left untouched.
1362
+
1363
+ gzgets returns buf which is a null-terminated string, or it returns NULL
1364
+ for end-of-file or in case of error. If there was an error, the contents at
1365
+ buf are indeterminate.
1366
+*/
1367
+
1368
+ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
1369
+/*
1370
+ Writes c, converted to an unsigned char, into the compressed file. gzputc
1371
+ returns the value that was written, or -1 in case of error.
1372
+*/
1373
+
1374
+ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
1375
+/*
1376
+ Reads one byte from the compressed file. gzgetc returns this byte or -1
1377
+ in case of end of file or error. This is implemented as a macro for speed.
1378
+ As such, it does not do all of the checking the other functions do. I.e.
1379
+ it does not check to see if file is NULL, nor whether the structure file
1380
+ points to has been clobbered or not.
1381
+*/
1382
+
1383
+ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
1384
+/*
1385
+ Push one character back onto the stream to be read as the first character
1386
+ on the next read. At least one character of push-back is allowed.
1387
+ gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
1388
+ fail if c is -1, and may fail if a character has been pushed but not read
1389
+ yet. If gzungetc is used immediately after gzopen or gzdopen, at least the
1390
+ output buffer size of pushed characters is allowed. (See gzbuffer above.)
1391
+ The pushed character will be discarded if the stream is repositioned with
1392
+ gzseek() or gzrewind().
1393
+*/
1394
+
1395
+ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
1396
+/*
1397
+ Flushes all pending output into the compressed file. The parameter flush
1398
+ is as in the deflate() function. The return value is the zlib error number
1399
+ (see function gzerror below). gzflush is only permitted when writing.
1400
+
1401
+ If the flush parameter is Z_FINISH, the remaining data is written and the
1402
+ gzip stream is completed in the output. If gzwrite() is called again, a new
1403
+ gzip stream will be started in the output. gzread() is able to read such
1404
+ concatented gzip streams.
1405
+
1406
+ gzflush should be called only when strictly necessary because it will
1407
+ degrade compression if called too often.
1408
+*/
1409
+
1410
+/*
1411
+ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
1412
+ z_off_t offset, int whence));
1413
+
1414
+ Sets the starting position for the next gzread or gzwrite on the given
1415
+ compressed file. The offset represents a number of bytes in the
1416
+ uncompressed data stream. The whence parameter is defined as in lseek(2);
1417
+ the value SEEK_END is not supported.
1418
+
1419
+ If the file is opened for reading, this function is emulated but can be
1420
+ extremely slow. If the file is opened for writing, only forward seeks are
1421
+ supported; gzseek then compresses a sequence of zeroes up to the new
1422
+ starting position.
1423
+
1424
+ gzseek returns the resulting offset location as measured in bytes from
1425
+ the beginning of the uncompressed stream, or -1 in case of error, in
1426
+ particular if the file is opened for writing and the new starting position
1427
+ would be before the current position.
1428
+*/
1429
+
1430
+ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
1431
+/*
1432
+ Rewinds the given file. This function is supported only for reading.
1433
+
1434
+ gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
1435
+*/
1436
+
1437
+/*
1438
+ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
1439
+
1440
+ Returns the starting position for the next gzread or gzwrite on the given
1441
+ compressed file. This position represents a number of bytes in the
1442
+ uncompressed data stream, and is zero when starting, even if appending or
1443
+ reading a gzip stream from the middle of a file using gzdopen().
1444
+
1445
+ gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1446
+*/
1447
+
1448
+/*
1449
+ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
1450
+
1451
+ Returns the current offset in the file being read or written. This offset
1452
+ includes the count of bytes that precede the gzip stream, for example when
1453
+ appending or when using gzdopen() for reading. When reading, the offset
1454
+ does not include as yet unused buffered input. This information can be used
1455
+ for a progress indicator. On error, gzoffset() returns -1.
1456
+*/
1457
+
1458
+ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1459
+/*
1460
+ Returns true (1) if the end-of-file indicator has been set while reading,
1461
+ false (0) otherwise. Note that the end-of-file indicator is set only if the
1462
+ read tried to go past the end of the input, but came up short. Therefore,
1463
+ just like feof(), gzeof() may return false even if there is no more data to
1464
+ read, in the event that the last read request was for the exact number of
1465
+ bytes remaining in the input file. This will happen if the input file size
1466
+ is an exact multiple of the buffer size.
1467
+
1468
+ If gzeof() returns true, then the read functions will return no more data,
1469
+ unless the end-of-file indicator is reset by gzclearerr() and the input file
1470
+ has grown since the previous end of file was detected.
1471
+*/
1472
+
1473
+ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
1474
+/*
1475
+ Returns true (1) if file is being copied directly while reading, or false
1476
+ (0) if file is a gzip stream being decompressed.
1477
+
1478
+ If the input file is empty, gzdirect() will return true, since the input
1479
+ does not contain a gzip stream.
1480
+
1481
+ If gzdirect() is used immediately after gzopen() or gzdopen() it will
1482
+ cause buffers to be allocated to allow reading the file to determine if it
1483
+ is a gzip file. Therefore if gzbuffer() is used, it should be called before
1484
+ gzdirect().
1485
+
1486
+ When writing, gzdirect() returns true (1) if transparent writing was
1487
+ requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
1488
+ gzdirect() is not needed when writing. Transparent writing must be
1489
+ explicitly requested, so the application already knows the answer. When
1490
+ linking statically, using gzdirect() will include all of the zlib code for
1491
+ gzip file reading and decompression, which may not be desired.)
1492
+*/
1493
+
1494
+ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1495
+/*
1496
+ Flushes all pending output if necessary, closes the compressed file and
1497
+ deallocates the (de)compression state. Note that once file is closed, you
1498
+ cannot call gzerror with file, since its structures have been deallocated.
1499
+ gzclose must not be called more than once on the same file, just as free
1500
+ must not be called more than once on the same allocation.
1501
+
1502
+ gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
1503
+ file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
1504
+ last read ended in the middle of a gzip stream, or Z_OK on success.
1505
+*/
1506
+
1507
+ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
1508
+ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
1509
+/*
1510
+ Same as gzclose(), but gzclose_r() is only for use when reading, and
1511
+ gzclose_w() is only for use when writing or appending. The advantage to
1512
+ using these instead of gzclose() is that they avoid linking in zlib
1513
+ compression or decompression code that is not used when only reading or only
1514
+ writing respectively. If gzclose() is used, then both compression and
1515
+ decompression code will be included the application when linking to a static
1516
+ zlib library.
1517
+*/
1518
+
1519
+ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1520
+/*
1521
+ Returns the error message for the last error which occurred on the given
1522
+ compressed file. errnum is set to zlib error number. If an error occurred
1523
+ in the file system and not in the compression library, errnum is set to
1524
+ Z_ERRNO and the application may consult errno to get the exact error code.
1525
+
1526
+ The application must not modify the returned string. Future calls to
1527
+ this function may invalidate the previously returned string. If file is
1528
+ closed, then the string previously returned by gzerror will no longer be
1529
+ available.
1530
+
1531
+ gzerror() should be used to distinguish errors from end-of-file for those
1532
+ functions above that do not distinguish those cases in their return values.
1533
+*/
1534
+
1535
+ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1536
+/*
1537
+ Clears the error and end-of-file flags for file. This is analogous to the
1538
+ clearerr() function in stdio. This is useful for continuing to read a gzip
1539
+ file that is being written concurrently.
1540
+*/
1541
+
1542
+#endif /* !Z_SOLO */
1543
+
1544
+ /* checksum functions */
1545
+
1546
+/*
1547
+ These functions are not related to compression but are exported
1548
+ anyway because they might be useful in applications using the compression
1549
+ library.
1550
+*/
1551
+
1552
+ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1553
+/*
1554
+ Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1555
+ return the updated checksum. If buf is Z_NULL, this function returns the
1556
+ required initial value for the checksum.
1557
+
1558
+ An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
1559
+ much faster.
1560
+
1561
+ Usage example:
1562
+
1563
+ uLong adler = adler32(0L, Z_NULL, 0);
1564
+
1565
+ while (read_buffer(buffer, length) != EOF) {
1566
+ adler = adler32(adler, buffer, length);
1567
+ }
1568
+ if (adler != original_adler) error();
1569
+*/
1570
+
1571
+/*
1572
+ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
1573
+ z_off_t len2));
1574
+
1575
+ Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
1576
+ and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1577
+ each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
1578
+ seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
1579
+ that the z_off_t type (like off_t) is a signed integer. If len2 is
1580
+ negative, the result has no meaning or utility.
1581
+*/
1582
+
1583
+ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
1584
+/*
1585
+ Update a running CRC-32 with the bytes buf[0..len-1] and return the
1586
+ updated CRC-32. If buf is Z_NULL, this function returns the required
1587
+ initial value for the crc. Pre- and post-conditioning (one's complement) is
1588
+ performed within this function so it shouldn't be done by the application.
1589
+
1590
+ Usage example:
1591
+
1592
+ uLong crc = crc32(0L, Z_NULL, 0);
1593
+
1594
+ while (read_buffer(buffer, length) != EOF) {
1595
+ crc = crc32(crc, buffer, length);
1596
+ }
1597
+ if (crc != original_crc) error();
1598
+*/
1599
+
1600
+/*
1601
+ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
1602
+
1603
+ Combine two CRC-32 check values into one. For two sequences of bytes,
1604
+ seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1605
+ calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
1606
+ check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1607
+ len2.
1608
+*/
1609
+
1610
+
1611
+ /* various hacks, don't look :) */
1612
+
1613
+/* deflateInit and inflateInit are macros to allow checking the zlib version
1614
+ * and the compiler's view of z_stream:
1615
+ */
1616
+ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
1617
+ const char *version, int stream_size));
1618
+ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
1619
+ const char *version, int stream_size));
1620
+ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
1621
+ int windowBits, int memLevel,
1622
+ int strategy, const char *version,
1623
+ int stream_size));
1624
+ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
1625
+ const char *version, int stream_size));
1626
+ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
1627
+ unsigned char FAR *window,
1628
+ const char *version,
1629
+ int stream_size));
1630
+#define deflateInit(strm, level) \
1631
+ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
1632
+#define inflateInit(strm) \
1633
+ inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
1634
+#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
1635
+ deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
1636
+ (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
1637
+#define inflateInit2(strm, windowBits) \
1638
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
1639
+ (int)sizeof(z_stream))
1640
+#define inflateBackInit(strm, windowBits, window) \
1641
+ inflateBackInit_((strm), (windowBits), (window), \
1642
+ ZLIB_VERSION, (int)sizeof(z_stream))
1643
+
1644
+#ifndef Z_SOLO
1645
+
1646
+/* gzgetc() macro and its supporting function and exposed data structure. Note
1647
+ * that the real internal state is much larger than the exposed structure.
1648
+ * This abbreviated structure exposes just enough for the gzgetc() macro. The
1649
+ * user should not mess with these exposed elements, since their names or
1650
+ * behavior could change in the future, perhaps even capriciously. They can
1651
+ * only be used by the gzgetc() macro. You have been warned.
1652
+ */
1653
+struct gzFile_s {
1654
+ unsigned have;
1655
+ unsigned char *next;
1656
+ z_off64_t pos;
1657
+};
1658
+ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
1659
+#ifdef Z_PREFIX_SET
1660
+# undef z_gzgetc
1661
+# define z_gzgetc(g) \
1662
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
1663
+#else
1664
+# define gzgetc(g) \
1665
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
1666
+#endif
1667
+
1668
+/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
1669
+ * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
1670
+ * both are true, the application gets the *64 functions, and the regular
1671
+ * functions are changed to 64 bits) -- in case these are set on systems
1672
+ * without large file support, _LFS64_LARGEFILE must also be true
1673
+ */
1674
+#ifdef Z_LARGE64
1675
+ ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
1676
+ ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
1677
+ ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
1678
+ ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
1679
+ ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
1680
+ ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
1681
+#endif
1682
+
1683
+#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
1684
+# ifdef Z_PREFIX_SET
1685
+# define z_gzopen z_gzopen64
1686
+# define z_gzseek z_gzseek64
1687
+# define z_gztell z_gztell64
1688
+# define z_gzoffset z_gzoffset64
1689
+# define z_adler32_combine z_adler32_combine64
1690
+# define z_crc32_combine z_crc32_combine64
1691
+# else
1692
+# define gzopen gzopen64
1693
+# define gzseek gzseek64
1694
+# define gztell gztell64
1695
+# define gzoffset gzoffset64
1696
+# define adler32_combine adler32_combine64
1697
+# define crc32_combine crc32_combine64
1698
+# endif
1699
+# ifndef Z_LARGE64
1700
+ ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
1701
+ ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
1702
+ ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
1703
+ ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
1704
+ ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
1705
+ ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
1706
+# endif
1707
+#else
1708
+ ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
1709
+ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
1710
+ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
1711
+ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
1712
+ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1713
+ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1714
+#endif
1715
+
1716
+#else /* Z_SOLO */
1717
+
1718
+ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1719
+ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1720
+
1721
+#endif /* !Z_SOLO */
1722
+
1723
+/* hack for buggy compilers */
1724
+#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
1725
+ struct internal_state {int dummy;};
1726
+#endif
1727
+
1728
+/* undocumented functions */
1729
+ZEXTERN const char * ZEXPORT zError OF((int));
1730
+ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
1731
+ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
1732
+ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
1733
+ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
1734
+ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
1735
+#if defined(_WIN32) && !defined(Z_SOLO)
1736
+ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
1737
+ const char *mode));
1738
+#endif
1739
+
1740
+#ifdef __cplusplus
1741
+}
1742
+#endif
1743
+
1744
+#endif /* ZLIB_H */
kernel/drivers/net/ethernet/ip1811/ip1811.c
....@@ -0,0 +1,482 @@
1
+#include <linux/kernel.h>
2
+#include <linux/version.h>
3
+#include <linux/module.h>
4
+#include <linux/init.h>
5
+#include <linux/fs.h>
6
+#include <linux/cdev.h>
7
+#include <linux/slab.h>
8
+#include <linux/mutex.h>
9
+#include <asm/uaccess.h>
10
+#include <linux/uaccess.h>
11
+
12
+#include "ip1811.h"
13
+#include "ip1811fdat.h"
14
+
15
+static struct cdev ip1811_cdev;
16
+struct class *ip1811_class;
17
+static DEFINE_MUTEX(ip1811_mutex);
18
+u8 CPU_IF_SPEED_NORMAL;
19
+
20
+#define IP1811_MAJOR 248
21
+#define IP1811_NAME "ip1811_cdev"
22
+
23
+//#define IP1811DEBUG
24
+
25
+MODULE_LICENSE ("GPL");
26
+
27
+static int ip1811_open(struct inode *inode, struct file *fs)
28
+{
29
+#ifdef IP1811DEBUG
30
+ printk("ip1811: open...\n");
31
+#endif
32
+ try_module_get(THIS_MODULE);
33
+
34
+ return 0;
35
+}
36
+
37
+static int ip1811_release(struct inode *inode, struct file *file)
38
+{
39
+ module_put(THIS_MODULE);
40
+#ifdef IP1811DEBUG
41
+ printk("ip1811: release!\n");
42
+#endif
43
+ return 0;
44
+}
45
+
46
+static ssize_t ip1811_read(struct file *filp, char __user *buffer, size_t length, loff_t *offset)
47
+{
48
+ // return simple_read_from_buffer(buffer, length, offset, msg, 200);
49
+ return 0;
50
+}
51
+
52
+static ssize_t ip1811_write(struct file *filp, const char __user *buff, size_t len, loff_t *off)
53
+{
54
+ /* if (len > 199)
55
+ return -EINVAL;
56
+ copy_from_user(msg, buff, len);
57
+ msg[len] = '\0';
58
+ return len;*/
59
+ return 0;
60
+}
61
+
62
+static int ip1811_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
63
+{
64
+ int ret;
65
+ unsigned long len, cmdid, fno, fsubg, fgrp, fusg;
66
+ void *cptr;
67
+ char *cdata, *cmptr;
68
+ int offset_t;
69
+
70
+#ifdef IP1811DEBUG
71
+ printk(KERN_ALERT "ip1811: +ioctl...\n");
72
+#endif
73
+ len = (int)(_IOC_SIZE(cmd));
74
+ cptr = (void *)arg;
75
+ offset_t = sizeof(void*) + sizeof(unsigned long);
76
+
77
+ do {
78
+ cdata = kmalloc(len, GFP_KERNEL);
79
+ cmptr=cdata;
80
+
81
+ if (!cdata)
82
+ {
83
+ printk(KERN_ERR "cdata==NULL");
84
+ ret = -ENOMEM;
85
+ goto out_ip1811_ioctl;
86
+ }
87
+
88
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5,0,0)
89
+ if(access_ok(VERIFY_READ, cptr, len)){
90
+#else
91
+ if(access_ok(cptr, len)){
92
+#endif
93
+ if(copy_from_user(cdata, cptr, len)){
94
+ printk(KERN_ERR "copy_from_user fail. len:%ld",(unsigned long)len);
95
+ ret=-EFAULT;
96
+ goto out_ip1811_ioctl;
97
+ }
98
+ }
99
+ else{
100
+ printk(KERN_ERR "[switchDriver] copy_from_user access fail by %s:%d CMD:%x\n",__FUNCTION__,__LINE__,cmd);
101
+ ret = -EFAULT;
102
+ goto out_ip1811_ioctl;
103
+ }
104
+ if(cmptr!=cdata){
105
+ printk(KERN_ERR "cdata error org: %p, after: %p", cmptr, cdata);
106
+ }
107
+ cmdid = *((unsigned long *)(cdata+offset_t));
108
+ fno = (cmdid >> _CMDID_NRSHIFT) & _CMDID_NRMASK;
109
+ fsubg=(cmdid >> _CMDID_SUBGSHIFT) & _CMDID_SUBGMASK;
110
+ fgrp= (cmdid >> _CMDID_GRPSHIFT) & _CMDID_GRPMASK;
111
+ fusg= (cmdid >> _CMDID_USGSHIFT) & _CMDID_USGMASK;
112
+#ifdef IP1811DEBUG
113
+ printk(KERN_ALERT "cmdid=0x%08x\n", (unsigned int)cmdid);
114
+#endif
115
+
116
+ if (fusg == _CMDID_USG_COMMON)
117
+ {
118
+ switch (fgrp)
119
+ {
120
+ case _CMDID_GRP_BASIC:
121
+ switch (fsubg)
122
+ {
123
+ case _CMDID_SUBG_SMI:
124
+ ret = func_of_common_smi[fno](cdata, len); break;
125
+
126
+ case _CMDID_SUBG_CAP:
127
+ ret = func_of_common_cap[fno](cdata, len); break;
128
+
129
+ case _CMDID_SUBG_LUT:
130
+ ret = func_of_common_lut[fno](cdata, len); break;
131
+
132
+ case _CMDID_SUBG_SNIFFER:
133
+ ret = func_of_common_sniffer[fno](cdata, len); break;
134
+
135
+ case _CMDID_SUBG_STORM:
136
+ ret = func_of_common_storm[fno](cdata, len); break;
137
+
138
+ case _CMDID_SUBG_EOC:
139
+ ret = func_of_common_eoc[fno](cdata, len); break;
140
+
141
+ case _CMDID_SUBG_LD:
142
+ ret = func_of_common_ld[fno](cdata, len); break;
143
+
144
+ case _CMDID_SUBG_WOL:
145
+ ret = func_of_common_wol[fno](cdata, len); break;
146
+
147
+ case _CMDID_SUBG_STAG:
148
+ ret = func_of_common_stag[fno](cdata, len); break;
149
+
150
+ case _CMDID_SUB_BANDWIDTH:
151
+ ret = func_of_common_bandwidth[fno](cdata, len); break;
152
+
153
+ case _CMDID_SUBG_MISC:
154
+ ret = func_of_common_misc[fno](cdata, len); break;
155
+
156
+ default:
157
+ ret = -EINVAL;
158
+ }
159
+ break;
160
+
161
+ case _CMDID_GRP_VLAN:
162
+ switch (fsubg)
163
+ {
164
+ case _CMDID_SUBG_VLAN:
165
+ ret = func_of_common_vlan[fno](cdata, len); break;
166
+
167
+ default:
168
+ ret = -EINVAL;
169
+ }
170
+ break;
171
+
172
+ case _CMDID_GRP_QOS:
173
+ switch (fsubg)
174
+ {
175
+ case _CMDID_SUB_BANDWIDTH:
176
+ ret = func_of_common_bandwidth[fno](cdata, len); break;
177
+
178
+ default:
179
+ ret = -EINVAL;
180
+ }
181
+ break;
182
+
183
+ case _CMDID_GRP_SEC:
184
+ switch (fsubg)
185
+ {
186
+ case _CMDID_SUBG_IMP:
187
+ ret = func_of_common_imp[fno](cdata, len); break;
188
+
189
+ case _CMDID_SUBG_COS:
190
+ ret = func_of_common_cos[fno](cdata, len); break;
191
+
192
+ default:
193
+ ret = -EINVAL;
194
+ }
195
+ break;
196
+
197
+ case _CMDID_GRP_ADV:
198
+ switch (fsubg)
199
+ {
200
+ case _CMDID_SUBG_STP:
201
+ ret = func_of_common_stp[fno](cdata, len); break;
202
+
203
+ case _CMDID_SUBG_LACP:
204
+ ret = func_of_common_lacp[fno](cdata, len); break;
205
+
206
+ default:
207
+ ret = -EINVAL;
208
+ }
209
+ break;
210
+
211
+ default:
212
+ ret = -EINVAL;
213
+ }
214
+ }
215
+ else if (fusg == _CMDID_USG_IP1811)
216
+ {
217
+ switch (fgrp)
218
+ {
219
+ case _CMDID_GRP_BASIC:
220
+ switch (fsubg)
221
+ {
222
+ case _CMDID_SUBG_CAP:
223
+ ret = func_of_common_cap[fno](cdata, len); break;
224
+
225
+ case _CMDID_SUBG_LUT:
226
+ ret = func_of_ip1811_lut[fno](cdata, len); break;
227
+
228
+ case _CMDID_SUBG_SNIFFER:
229
+ ret = func_of_ip1811_sniffer[fno](cdata, len); break;
230
+
231
+ case _CMDID_SUBG_STORM:
232
+ ret = func_of_ip1811_storm[fno](cdata, len); break;
233
+
234
+ case _CMDID_SUBG_EOC:
235
+ ret = func_of_ip1811_eoc[fno](cdata, len); break;
236
+
237
+ case _CMDID_SUBG_LD:
238
+ ret = func_of_ip1811_ld[fno](cdata, len); break;
239
+
240
+ case _CMDID_SUBG_WOL:
241
+ ret = func_of_ip1811_wol[fno](cdata, len); break;
242
+
243
+ case _CMDID_SUBG_IGMP:
244
+ ret = func_of_ip1811_igmp[fno](cdata, len); break;
245
+
246
+ case _CMDID_SUBG_PTP:
247
+ ret = func_of_ip1811_ptp[fno](cdata, len); break;
248
+
249
+ default:
250
+ ret = -EINVAL;
251
+ }
252
+ break;
253
+
254
+ case _CMDID_GRP_VLAN:
255
+ switch (fsubg)
256
+ {
257
+ case _CMDID_SUBG_VLAN:
258
+ ret = func_of_ip1811_vlan[fno](cdata, len); break;
259
+
260
+ default:
261
+ ret = -EINVAL;
262
+ }
263
+ break;
264
+ case _CMDID_GRP_QOS:
265
+ switch (fsubg)
266
+ {
267
+ case _CMDID_SUB_QOS:
268
+ ret = func_of_ip1811_qos[fno](cdata, len); break;
269
+
270
+ default:
271
+ ret = -EINVAL;
272
+ }
273
+ break;
274
+ case _CMDID_GRP_ACL:
275
+ switch (fsubg)
276
+ {
277
+ case _CMDID_SUBG_ACL:
278
+ ret = func_of_ip1811_acl[fno](cdata, len); break;
279
+
280
+ default:
281
+ ret = -EINVAL;
282
+ }
283
+ break;
284
+
285
+ case _CMDID_GRP_SEC:
286
+ switch (fsubg)
287
+ {
288
+ case _CMDID_SUBG_IMP:
289
+ ret = func_of_ip1811_imp[fno](cdata, len); break;
290
+
291
+ default:
292
+ ret = -EINVAL;
293
+ }
294
+ break;
295
+
296
+ case _CMDID_GRP_ADV:
297
+ switch (fsubg)
298
+ {
299
+ case _CMDID_SUBG_STP:
300
+ ret = func_of_ip1811_stp[fno](cdata, len); break;
301
+
302
+ case _CMDID_SUBG_LACP:
303
+ ret = func_of_ip1811_lacp[fno](cdata, len); break;
304
+
305
+ default:
306
+ ret = -EINVAL;
307
+ }
308
+ break;
309
+ case _CMDID_GRP_MON:
310
+ switch (fsubg)
311
+ {
312
+ case _CMDID_SUBG_MIB_COUNTER:
313
+ ret = func_of_ip1811_mib_counter[fno](cdata, len); break;
314
+
315
+ default:
316
+ ret = -EINVAL;
317
+ }
318
+ break;
319
+
320
+ case _CMDID_GRP_HSR:
321
+ switch (fsubg)
322
+ {
323
+ case _CMDID_SUBG_HSR:
324
+ ret = func_of_ip1811_hsr[fno](cdata, len); break;
325
+
326
+ default:
327
+ ret = -EINVAL;
328
+ }
329
+ break;
330
+
331
+ default:
332
+ ret = -EINVAL;
333
+ }
334
+ }
335
+ else
336
+ ret = -EINVAL;
337
+
338
+ if (ret < 0) goto out_ip1811_ioctl;
339
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5,0,0)
340
+ if(access_ok(WERIFY_WRITE, cptr, len)){
341
+#else
342
+ if(access_ok(cptr, len)){
343
+#endif
344
+ if (copy_to_user(cptr, cdata, len)) {
345
+ printk(KERN_ERR "copy_touser fail.");
346
+ ret = -EFAULT;
347
+ goto out_ip1811_ioctl;
348
+ }
349
+ }
350
+ else{
351
+ printk(KERN_ERR "[switchDriver] copy_from_user access fail by %s:%d CMD:%x\n",__FUNCTION__,__LINE__,cmd);
352
+ ret=-EFAULT;
353
+ goto out_ip1811_ioctl;
354
+ }
355
+ cptr= (void *)*((unsigned long *)cdata);
356
+ len = *((unsigned long *)(cdata+4));
357
+
358
+ kfree(cdata);
359
+ cdata = NULL;
360
+ } while (cptr);
361
+out_ip1811_ioctl:
362
+ if(cdata)
363
+ {
364
+ //memset(cdata, 0x0, len);
365
+ kfree(cdata);
366
+ }
367
+#ifdef IP1811DEBUG
368
+ printk(KERN_ALERT "ip1811: -ioctl...\n");
369
+#endif
370
+ return (ret < 0) ? ret : 0;
371
+}
372
+
373
+static void lock_key_ioctl(void)
374
+{
375
+ mutex_lock(&ip1811_mutex);
376
+}
377
+
378
+static void unlock_key_ioctl(void)
379
+{
380
+ mutex_unlock(&ip1811_mutex);
381
+}
382
+
383
+static long ip1811_unlocked_ioctl(struct file *filep, unsigned int cmd, unsigned long arg)
384
+{
385
+ int ret;
386
+
387
+ lock_key_ioctl();
388
+ ret = ip1811_ioctl(filep, cmd, arg);
389
+ unlock_key_ioctl();
390
+
391
+ return ret;
392
+}
393
+
394
+static struct file_operations ip1811_fops = {
395
+ .owner = THIS_MODULE,
396
+ .read = ip1811_read,
397
+ .write = ip1811_write,
398
+ .unlocked_ioctl = ip1811_unlocked_ioctl,
399
+ .open = ip1811_open,
400
+ .release = ip1811_release
401
+};
402
+
403
+extern u16 Read_Reg(u8 regaddr);
404
+extern void Write_Reg(u8 regaddr, u16 value);
405
+extern void IP2Page(u8 page);
406
+extern u16 Read_Reg_0_With_1s(void);
407
+
408
+/* ==================================================================================== */
409
+
410
+static int __init ip1811_init(void)
411
+{
412
+ int result;
413
+
414
+ result = register_chrdev_region(MKDEV(IP1811_MAJOR, 0), 1, IP1811_NAME);
415
+ if (result < 0)
416
+ {
417
+ printk(KERN_WARNING "ip1811: can't get major %d\n", IP1811_MAJOR);
418
+ return result;
419
+ }
420
+
421
+ cdev_init(&ip1811_cdev, &ip1811_fops);
422
+ ip1811_cdev.owner = THIS_MODULE;
423
+ result = cdev_add(&ip1811_cdev, MKDEV(IP1811_MAJOR, 0), 1);
424
+ if (result)
425
+ {
426
+ printk(KERN_WARNING "ip1811: error %d adding driver\n", result);
427
+ return result;
428
+ }
429
+
430
+ CPU_IF_SPEED_NORMAL = 0; //set to normal speed initially
431
+
432
+ IP2Page(0);
433
+ if( (Read_Reg_0_With_1s() & 0xFFF0) == 0x8120 )
434
+ {
435
+ printk("ip1811: CPU I/F High speed.");
436
+ }
437
+ else
438
+ {
439
+ CPU_IF_SPEED_NORMAL = 1;
440
+ printk("ip1811: CPU I/F Normal speed.");
441
+ }
442
+
443
+ // for acl_man init.
444
+ acl_init();
445
+
446
+ printk(" Driver loaded!\n");
447
+ return 0;
448
+ /*
449
+fail_return:
450
+ if(ip1811_cdev){
451
+ cdev_del(ip1811_cdev);
452
+ kfree(ip1811_cdev);
453
+ ip1811_cdev=NULL;
454
+ }
455
+ if(devno)
456
+ unregister_chrdev_region(devno, 1);
457
+ if(ip1811_class)
458
+ class_destroy(ip1811_class);
459
+ return -1;
460
+ */
461
+}
462
+
463
+static void __exit ip1811_exit(void)
464
+{
465
+ /*
466
+ if(ip1811_cdev){
467
+ cdev_del(ip1811_cdev);
468
+ kfree(ip1811_cdev);
469
+ ip1811_cdev=NULL;
470
+ }
471
+ if(devno)
472
+ unregister_chrdev_region(devno, 1);
473
+ if(ip1811_class)
474
+ class_destroy(ip1811_class);
475
+ */
476
+ cdev_del(&ip1811_cdev);
477
+ unregister_chrdev_region(MKDEV(IP1811_MAJOR, 0), 1);
478
+ printk("ip1811: Driver unloaded!\n");
479
+}
480
+
481
+module_init(ip1811_init);
482
+module_exit(ip1811_exit);
kernel/drivers/net/ethernet/ip1811/ip1811.h
....@@ -0,0 +1,1323 @@
1
+#ifndef IP1811_H
2
+#define IP1811_H
3
+
4
+/*===================================================================*/
5
+/* max port number of this switch */
6
+#define MAX_PHY_NUM (12)
7
+/* port-list mask */
8
+#define ALL_PHY_PORTS_LIST (~(-1 << (MAX_PHY_NUM - 1)))
9
+/* max port number of TP port */
10
+#define MAX_PHY_TP_NUM (8)
11
+
12
+/* max number of fid */
13
+#define MAX_FID_NUM (16)
14
+/* max LUT table block number */
15
+#define MAX_BLOCK_NUM (1)
16
+/* max LUT table entry number */
17
+#define MAX_LUT_ENTRY_NUM (4096)
18
+/* LUT table aging time unit(millisecond) */
19
+#define AGING_TIME_UNIT (550)
20
+
21
+/* max IP-Mac-Port table entry number */
22
+#define MAX_IMP_ENTRY_NUM (128)
23
+
24
+/* max PVID number */
25
+#define MAX_PVID_NUM (4096)
26
+/* mac Protocol Based VLAN entry number */
27
+#define MAX_PRO_VLAN_ENTRY_NUM (4)
28
+
29
+/* max link speed of TP port */
30
+#define MAX_TP_SPEED (100000000)
31
+/* max link speed of Giga port */
32
+#define MAX_GIGA_SPEED (1000000000)
33
+
34
+/*===================================================================*/
35
+#define TYPECHECK(t) (sizeof(t))
36
+
37
+#define _CMDID_NRBITS 8
38
+#define _CMDID_SUBGBITS 4
39
+#define _CMDID_RSVD1BITS 4
40
+#define _CMDID_GRPBITS 8
41
+#define _CMDID_USGBITS 4
42
+
43
+#define _CMDID_NRMASK ((1 << _CMDID_NRBITS)-1)
44
+#define _CMDID_SUBGMASK ((1 << _CMDID_SUBGBITS)-1)
45
+#define _CMDID_GRPMASK ((1 << _CMDID_GRPBITS)-1)
46
+#define _CMDID_USGMASK ((1 << _CMDID_USGBITS)-1)
47
+
48
+#define _CMDID_NRSHIFT 0
49
+#define _CMDID_SUBGSHIFT (_CMDID_NRSHIFT+_CMDID_NRBITS)
50
+#define _CMDID_GRPSHIFT (_CMDID_SUBGSHIFT+_CMDID_SUBGBITS+_CMDID_RSVD1BITS)
51
+#define _CMDID_USGSHIFT (_CMDID_GRPSHIFT+_CMDID_GRPBITS)
52
+
53
+#define MAKECMDID(usg, grp, subg, nr) ( (usg << _CMDID_USGSHIFT) | (grp << _CMDID_GRPSHIFT) | \
54
+ (subg << _CMDID_SUBGSHIFT) | (nr << _CMDID_NRSHIFT) )
55
+
56
+#define _CMDID_USG_COMMON 0x0
57
+#define _CMDID_USG_IP1811 0x1
58
+#define _CMDID_USG_DBS 0x2
59
+#define NUM_CMDID_USG 0x3
60
+
61
+/*===================================================================*/
62
+#define _CMDID_GRP_BASIC 0x01
63
+
64
+/*-------------------------------------------------------------------*/
65
+#define _CMDID_SUBG_SMI 0x1
66
+enum{
67
+ IDX_COMMON_SET_PORT_AN, //0
68
+ IDX_COMMON_GET_PORT_AN,
69
+ IDX_COMMON_SET_PORT_SPEED,
70
+ IDX_COMMON_GET_PORT_SPEED,
71
+ IDX_COMMON_SET_PORT_DUPLEX,
72
+ IDX_COMMON_GET_PORT_DUPLEX,
73
+ IDX_COMMON_SET_PORT_PAUSE,
74
+ IDX_COMMON_GET_PORT_PAUSE,
75
+ IDX_COMMON_SET_PORT_ASYM_PAUSE,
76
+ IDX_COMMON_GET_PORT_ASYM_PAUSE,
77
+ IDX_COMMON_SET_PORT_LINK_STATUS, //10
78
+ IDX_COMMON_GET_PORT_LINK_STATUS,
79
+ IDX_COMMON_SET_PORT_BACKPRESSURE,
80
+ IDX_COMMON_GET_PORT_BACKPRESSURE,
81
+ IDX_COMMON_SET_PORT_POWER_DOWN,
82
+ IDX_COMMON_GET_PORT_POWER_DOWN,
83
+ IDX_COMMON_SET_PORT_FORCE_LINK,
84
+ IDX_COMMON_GET_PORT_FORCE_LINK,
85
+ IDX_COMMON_SET_PORT_UNI_DIRECTION,
86
+ IDX_COMMON_GET_PORT_UNI_DIRECTION,
87
+ IDX_COMMON_SET_MDIO_DIV, //20
88
+ IDX_COMMON_SET_FALSE_LINK_SOLUTION,
89
+ NUM_COMMON_SMI //22
90
+};
91
+
92
+#define ID_COMMON_SMI(idx) \
93
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUBG_SMI, idx)
94
+
95
+#define ID_COMMON_SET_PORT_AN \
96
+ ID_COMMON_SMI(IDX_COMMON_SET_PORT_AN)
97
+#define ID_COMMON_GET_PORT_AN \
98
+ ID_COMMON_SMI(IDX_COMMON_GET_PORT_AN)
99
+#define ID_COMMON_SET_PORT_SPEED \
100
+ ID_COMMON_SMI(IDX_COMMON_SET_PORT_SPEED)
101
+#define ID_COMMON_GET_PORT_SPEED \
102
+ ID_COMMON_SMI(IDX_COMMON_GET_PORT_SPEED)
103
+#define ID_COMMON_SET_PORT_DUPLEX \
104
+ ID_COMMON_SMI(IDX_COMMON_SET_PORT_DUPLEX)
105
+#define ID_COMMON_GET_PORT_DUPLEX \
106
+ ID_COMMON_SMI(IDX_COMMON_GET_PORT_DUPLEX)
107
+#define ID_COMMON_SET_PORT_PAUSE \
108
+ ID_COMMON_SMI(IDX_COMMON_SET_PORT_PAUSE)
109
+#define ID_COMMON_GET_PORT_PAUSE \
110
+ ID_COMMON_SMI(IDX_COMMON_GET_PORT_PAUSE)
111
+#define ID_COMMON_SET_PORT_ASYM_PAUSE \
112
+ ID_COMMON_SMI(IDX_COMMON_SET_PORT_ASYM_PAUSE)
113
+#define ID_COMMON_GET_PORT_ASYM_PAUSE \
114
+ ID_COMMON_SMI(IDX_COMMON_GET_PORT_ASYM_PAUSE)
115
+#define ID_COMMON_SET_PORT_LINK_STATUS \
116
+ ID_COMMON_SMI(IDX_COMMON_SET_PORT_LINK_STATUS)
117
+#define ID_COMMON_GET_PORT_LINK_STATUS \
118
+ ID_COMMON_SMI(IDX_COMMON_GET_PORT_LINK_STATUS)
119
+#define ID_COMMON_SET_PORT_BACKPRESSURE \
120
+ ID_COMMON_SMI(IDX_COMMON_SET_PORT_BACKPRESSURE)
121
+#define ID_COMMON_GET_PORT_BACKPRESSURE \
122
+ ID_COMMON_SMI(IDX_COMMON_GET_PORT_BACKPRESSURE)
123
+#define ID_COMMON_SET_PORT_POWER_DOWN \
124
+ ID_COMMON_SMI(IDX_COMMON_SET_PORT_POWER_DOWN)
125
+#define ID_COMMON_GET_PORT_POWER_DOWN \
126
+ ID_COMMON_SMI(IDX_COMMON_GET_PORT_POWER_DOWN)
127
+#define ID_COMMON_SET_PORT_FORCE_LINK \
128
+ ID_COMMON_SMI(IDX_COMMON_SET_PORT_FORCE_LINK)
129
+#define ID_COMMON_GET_PORT_FORCE_LINK \
130
+ ID_COMMON_SMI(IDX_COMMON_GET_PORT_FORCE_LINK)
131
+#define ID_COMMON_SET_PORT_UNI_DIRECTION \
132
+ ID_COMMON_SMI(IDX_COMMON_SET_PORT_UNI_DIRECTION)
133
+#define ID_COMMON_GET_PORT_UNI_DIRECTION \
134
+ ID_COMMON_SMI(IDX_COMMON_GET_PORT_UNI_DIRECTION)
135
+#define ID_COMMON_SET_MDIO_DIV \
136
+ ID_COMMON_SMI(IDX_COMMON_SET_MDIO_DIV)
137
+#define ID_COMMON_SET_FALSE_LINK_SOLUTION\
138
+ ID_COMMON_SMI(IDX_COMMON_SET_FALSE_LINK_SOLUTION)
139
+
140
+/*-------------------------------------------------------------------*/
141
+#define _CMDID_SUBG_CAP 0x2
142
+enum{
143
+ IDX_COMMON_L2_SET_CAP_ACT,
144
+ IDX_COMMON_CAP_SET_IN_BAND,
145
+ IDX_COMMON_CAP_SET_SWITCH_MAC,
146
+ IDX_COMMON_CAP_SET_IPV6_TCPUDP_ENABLE,
147
+ NUM_COMMON_CAP
148
+};
149
+
150
+#define ID_COMMON_CAP(idx) \
151
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUBG_CAP, idx)
152
+
153
+#define ID_COMMON_L2_SET_CAP_ACT \
154
+ ID_COMMON_CAP(IDX_COMMON_L2_SET_CAP_ACT)
155
+
156
+#define ID_COMMON_CAP_SET_IN_BAND \
157
+ ID_COMMON_CAP(IDX_COMMON_CAP_SET_IN_BAND)
158
+
159
+#define ID_COMMON_CAP_SET_SWITCH_MAC \
160
+ ID_COMMON_CAP(IDX_COMMON_CAP_SET_SWITCH_MAC)
161
+
162
+#define ID_COMMON_CAP_SET_IPV6_TCPUDP_ENABLE \
163
+ ID_COMMON_CAP(IDX_COMMON_CAP_SET_IPV6_TCPUDP_ENABLE)
164
+
165
+/*-------------------------------------------------------------------*/
166
+#define _CMDID_SUBG_LUT 0x3
167
+
168
+enum{
169
+ IDX_COMMON_SET_SMAC_LEARNING, //0
170
+ IDX_COMMON_GET_SMAC_LEARNING,
171
+ IDX_COMMON_LUT_SET_PORT_FLUSH,
172
+ IDX_COMMON_SET_LUT_AGING_TIME,
173
+ IDX_COMMON_GET_LUT_AGING_TIME,
174
+ IDX_COMMON_SET_LUT_AGING_TIME_ENABLE,
175
+ IDX_COMMON_SET_LUT_LEARN_NSA,
176
+ IDX_COMMON_SET_LUT_HASHING_ALGORITHM,
177
+ IDX_COMMON_SET_LUT_BINDING_ENABLE,
178
+ IDX_COMMON_GET_LUT_BINDING_ENABLE,
179
+ NUM_COMMON_LUT
180
+};
181
+
182
+#define ID_COMMON_LUT(idx) \
183
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUBG_LUT, idx)
184
+
185
+#define ID_COMMON_SET_SMAC_LEARNING \
186
+ ID_COMMON_LUT(IDX_COMMON_SET_SMAC_LEARNING)
187
+#define ID_COMMON_GET_SMAC_LEARNING\
188
+ ID_COMMON_LUT(IDX_COMMON_GET_SMAC_LEARNING)
189
+#define ID_COMMON_LUT_SET_PORT_FLUSH\
190
+ ID_COMMON_LUT(IDX_COMMON_LUT_SET_PORT_FLUSH)
191
+#define ID_COMMON_SET_LUT_AGING_TIME\
192
+ ID_COMMON_LUT(IDX_COMMON_SET_LUT_AGING_TIME)
193
+#define ID_COMMON_GET_LUT_AGING_TIME\
194
+ ID_COMMON_LUT(IDX_COMMON_GET_LUT_AGING_TIME)
195
+#define ID_COMMON_SET_LUT_AGING_TIME_ENABLE\
196
+ ID_COMMON_LUT(IDX_COMMON_SET_LUT_AGING_TIME_ENABLE)
197
+#define ID_COMMON_SET_LUT_LEARN_NSA \
198
+ ID_COMMON_LUT(IDX_COMMON_SET_LUT_LEARN_NSA)
199
+#define ID_COMMON_SET_LUT_HASHING_ALGORITHM \
200
+ ID_COMMON_LUT(IDX_COMMON_SET_LUT_HASHING_ALGORITHM)
201
+#define ID_COMMON_SET_LUT_BINDING_ENABLE \
202
+ ID_COMMON_LUT(IDX_COMMON_SET_LUT_BINDING_ENABLE)
203
+#define ID_COMMON_GET_LUT_BINDING_ENABLE\
204
+ ID_COMMON_LUT(IDX_COMMON_GET_LUT_BINDING_ENABLE)
205
+
206
+enum{
207
+ IDX_1811_LUT_SET_UNKNOWN_SA_RULE,
208
+ IDX_1811_LUT_SET_ENTRY,
209
+ IDX_1811_LUT_GET_ENTRY,
210
+ IDX_1811_LUT_GET_VALID_ENTRY,
211
+ NUM_1811_LUT
212
+};
213
+
214
+#define ID_1811_LUT(idx) \
215
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_BASIC, _CMDID_SUBG_LUT, idx)
216
+
217
+#define ID_1811_LUT_SET_UNKNOWN_SA_RULE \
218
+ ID_1811_LUT(IDX_1811_LUT_SET_UNKNOWN_SA_RULE)
219
+#define ID_1811_LUT_SET_ENTRY\
220
+ ID_1811_LUT(IDX_1811_LUT_SET_ENTRY)
221
+#define ID_1811_LUT_GET_ENTRY\
222
+ ID_1811_LUT(IDX_1811_LUT_GET_ENTRY)
223
+#define ID_1811_LUT_GET_VALID_ENTRY\
224
+ ID_1811_LUT(IDX_1811_LUT_GET_VALID_ENTRY)
225
+
226
+/*-------------------------------------------------------------------*/
227
+#define _CMDID_SUBG_SNIFFER 0x4
228
+
229
+enum{
230
+ IDX_COMMON_SET_SNIFFER_SOURCE,
231
+ IDX_COMMON_GET_SNIFFER_SOURCE,
232
+ IDX_COMMON_SET_SNIFFER_DEST_GRP1,
233
+ IDX_COMMON_GET_SNIFFER_DEST_GRP1,
234
+ IDX_COMMON_SNIFFER1_SET_METHOD,
235
+ IDX_COMMON_SNIFFER1_GET_METHOD,
236
+ NUM_COMMON_SNIFFER
237
+};
238
+#define ID_COMMON_SNIFFER(idx) \
239
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUBG_SNIFFER, idx)
240
+
241
+#define ID_COMMON_SET_SNIFFER_SOURCE \
242
+ ID_COMMON_SNIFFER(IDX_COMMON_SET_SNIFFER_SOURCE)
243
+#define ID_COMMON_GET_SNIFFER_SOURCE \
244
+ ID_COMMON_SNIFFER(IDX_COMMON_GET_SNIFFER_SOURCE)
245
+#define ID_COMMON_SET_SNIFFER_DEST_GRP1 \
246
+ ID_COMMON_SNIFFER(IDX_COMMON_SET_SNIFFER_DEST_GRP1)
247
+#define ID_COMMON_GET_SNIFFER_DEST_GRP1 \
248
+ ID_COMMON_SNIFFER(IDX_COMMON_GET_SNIFFER_DEST_GRP1)
249
+#define ID_COMMON_SNIFFER1_SET_METHOD \
250
+ ID_COMMON_SNIFFER(IDX_COMMON_SNIFFER1_SET_METHOD)
251
+#define ID_COMMON_SNIFFER1_GET_METHOD \
252
+ ID_COMMON_SNIFFER(IDX_COMMON_SNIFFER1_GET_METHOD)
253
+
254
+enum{
255
+ IDX_1811_SNIFFER1_SET_PKT_MODIFY,
256
+ IDX_1811_SNIFFER1_GET_PKT_MODIFY,
257
+ IDX_1811_SNIFFER1_SET_TAG_MODIFY_FOR_CPU_STAG,
258
+ IDX_1811_SNIFFER1_GET_TAG_MODIFY_FOR_CPU_STAG,
259
+ IDX_1811_SNIFFER1_SET_TAG_MODIFY_FOR_ACL_REDIR_2CPU,
260
+ IDX_1811_SNIFFER1_GET_TAG_MODIFY_FOR_ACL_REDIR_2CPU,
261
+ IDX_1811_SNIFFER1_SET_TAG_MODIFY_FOR_PKT_2MIRROR_PORT,
262
+ IDX_1811_SNIFFER1_GET_TAG_MODIFY_FOR_PKT_2MIRROR_PORT,
263
+ IDX_1811_SNIFFER2_SET_LUT_TRIGGER_TARGET_FOR_GRP1,
264
+ IDX_1811_SNIFFER2_GET_LUT_TRIGGER_TARGET_FOR_GRP1,
265
+ NUM_1811_SNIFFER
266
+};
267
+#define ID_1811_SNIFFER(idx) \
268
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_BASIC, _CMDID_SUBG_SNIFFER, idx)
269
+
270
+#define ID_1811_SNIFFER1_SET_PKT_MODIFY \
271
+ ID_1811_SNIFFER(IDX_1811_SNIFFER1_SET_PKT_MODIFY)
272
+#define ID_1811_SNIFFER1_GET_PKT_MODIFY \
273
+ ID_1811_SNIFFER(IDX_1811_SNIFFER1_GET_PKT_MODIFY)
274
+#define ID_1811_SNIFFER1_SET_TAG_MODIFY_FOR_CPU_STAG \
275
+ ID_1811_SNIFFER(IDX_1811_SNIFFER1_SET_TAG_MODIFY_FOR_CPU_STAG)
276
+#define ID_1811_SNIFFER1_GET_TAG_MODIFY_FOR_CPU_STAG \
277
+ ID_1811_SNIFFER(IDX_1811_SNIFFER1_GET_TAG_MODIFY_FOR_CPU_STAG)
278
+#define ID_1811_SNIFFER1_SET_TAG_MODIFY_FOR_ACL_REDIR_2CPU \
279
+ ID_1811_SNIFFER(IDX_1811_SNIFFER1_SET_TAG_MODIFY_FOR_ACL_REDIR_2CPU)
280
+#define ID_1811_SNIFFER1_GET_TAG_MODIFY_FOR_ACL_REDIR_2CPU \
281
+ ID_1811_SNIFFER(IDX_1811_SNIFFER1_GET_TAG_MODIFY_FOR_ACL_REDIR_2CPU)
282
+#define ID_1811_SNIFFER1_SET_TAG_MODIFY_FOR_PKT_2MIRROR_PORT \
283
+ ID_1811_SNIFFER(IDX_1811_SNIFFER1_SET_TAG_MODIFY_FOR_PKT_2MIRROR_PORT)
284
+#define ID_1811_SNIFFER1_GET_TAG_MODIFY_FOR_PKT_2MIRROR_PORT \
285
+ ID_1811_SNIFFER(IDX_1811_SNIFFER1_GET_TAG_MODIFY_FOR_PKT_2MIRROR_PORT)
286
+#define ID_1811_SNIFFER2_SET_LUT_TRIGGER_TARGET_FOR_GRP1 \
287
+ ID_1811_SNIFFER(IDX_1811_SNIFFER2_SET_LUT_TRIGGER_TARGET_FOR_GRP1)
288
+#define ID_1811_SNIFFER2_GET_LUT_TRIGGER_TARGET_FOR_GRP1 \
289
+ ID_1811_SNIFFER(IDX_1811_SNIFFER2_GET_LUT_TRIGGER_TARGET_FOR_GRP1)
290
+/*-------------------------------------------------------------------*/
291
+#define _CMDID_SUBG_STORM 0x5
292
+
293
+enum{
294
+ IDX_COMMON_STORM_CTRL_SET_FUNC,
295
+ IDX_COMMON_STORM_CTRL_GET_FUNC,
296
+ IDX_COMMON_STORM_CTRL_SET_THRESHOLD,
297
+ IDX_COMMON_STORM_CTRL_GET_THRESHOLD,
298
+ IDX_COMMON_STORM_SET_COUNTER_CLR_PERIOD,
299
+ IDX_COMMON_STORM_GET_COUNTER_CLR_PERIOD,
300
+ IDX_COMMON_STORM_SET_BLOCK_FRAME_2CPU,
301
+ IDX_COMMON_STORM_GET_BLOCK_FRAME_2CPU,
302
+ IDX_COMMON_STORM_SET_DROP_INTERRUPT,
303
+ IDX_COMMON_STORM_GET_DROP_INTERRUPT,
304
+ NUM_COMMON_STORM
305
+};
306
+#define ID_COMMON_STORM(idx) \
307
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUBG_STORM, idx)
308
+
309
+#define ID_COMMON_STORM_CTRL_SET_FUNC \
310
+ ID_COMMON_STORM(IDX_COMMON_STORM_CTRL_SET_FUNC)
311
+#define ID_COMMON_STORM_CTRL_GET_FUNC \
312
+ ID_COMMON_STORM(IDX_COMMON_STORM_CTRL_GET_FUNC)
313
+#define ID_COMMON_STORM_CTRL_SET_THRESHOLD \
314
+ ID_COMMON_STORM(IDX_COMMON_STORM_CTRL_SET_THRESHOLD)
315
+#define ID_COMMON_STORM_CTRL_GET_THRESHOLD \
316
+ ID_COMMON_STORM(IDX_COMMON_STORM_CTRL_GET_THRESHOLD)
317
+#define ID_COMMON_STORM_SET_COUNTER_CLR_PERIOD \
318
+ ID_COMMON_STORM(IDX_COMMON_STORM_SET_COUNTER_CLR_PERIOD)
319
+#define ID_COMMON_STORM_GET_COUNTER_CLR_PERIOD \
320
+ ID_COMMON_STORM(IDX_COMMON_STORM_GET_COUNTER_CLR_PERIOD)
321
+#define ID_COMMON_STORM_SET_BLOCK_FRAME_2CPU \
322
+ ID_COMMON_STORM(IDX_COMMON_STORM_SET_BLOCK_FRAME_2CPU)
323
+#define ID_COMMON_STORM_GET_BLOCK_FRAME_2CPU \
324
+ ID_COMMON_STORM(IDX_COMMON_STORM_GET_BLOCK_FRAME_2CPU)
325
+#define ID_COMMON_STORM_SET_DROP_INTERRUPT \
326
+ ID_COMMON_STORM(IDX_COMMON_STORM_SET_DROP_INTERRUPT)
327
+#define ID_COMMON_STORM_GET_DROP_INTERRUPT \
328
+ ID_COMMON_STORM(IDX_COMMON_STORM_GET_DROP_INTERRUPT)
329
+
330
+enum{
331
+ IDX_1811_MCST_STORM_SET_NBLOCK_IP_PKT,
332
+ IDX_1811_MCST_STORM_GET_NBLOCK_IP_PKT,
333
+ IDX_1811_MCST_STORM_SET_IGNORE_01005EXXXXXX,
334
+ IDX_1811_MCST_STORM_GET_IGNORE_01005EXXXXXX,
335
+ NUM_1811_STORM
336
+};
337
+#define ID_1811_STORM(idx) \
338
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_BASIC, _CMDID_SUBG_STORM, idx)
339
+#define ID_1811_MCST_STORM_SET_NBLOCK_IP_PKT \
340
+ ID_1811_STORM(IDX_1811_MCST_STORM_SET_NBLOCK_IP_PKT)
341
+#define ID_1811_MCST_STORM_GET_NBLOCK_IP_PKT \
342
+ ID_1811_STORM(IDX_1811_MCST_STORM_GET_NBLOCK_IP_PKT)
343
+#define ID_1811_MCST_STORM_SET_IGNORE_01005EXXXXXX \
344
+ ID_1811_STORM(IDX_1811_MCST_STORM_SET_IGNORE_01005EXXXXXX)
345
+#define ID_1811_MCST_STORM_GET_IGNORE_01005EXXXXXX \
346
+ ID_1811_STORM(IDX_1811_MCST_STORM_GET_IGNORE_01005EXXXXXX)
347
+
348
+/*-------------------------------------------------------------------*/
349
+#define _CMDID_SUBG_EOC 0x6
350
+#define ID_COMMON_EOC_SET_FUNC \
351
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUBG_EOC, 0)
352
+/*-------------------------------------------------------------------*/
353
+#define _CMDID_SUBG_LD 0x7
354
+enum{
355
+ IDX_COMMON_LOOP_DETECT_SET_FUNC,
356
+ IDX_COMMON_LOOP_DETECT_GET_FUNC,
357
+ IDX_COMMON_LOOP_DETECT_SET_TIME_UNIT,
358
+ IDX_COMMON_LOOP_DETECT_GET_TIME_UNIT,
359
+ IDX_COMMON_LOOP_DETECT_SET_PKT_SEND_TIMER,
360
+ IDX_COMMON_LOOP_DETECT_GET_PKT_SEND_TIMER,
361
+ IDX_COMMON_LOOP_DETECT_SET_BLOCK_RELEASE_TIMER,
362
+ IDX_COMMON_LOOP_DETECT_GET_BLOCK_RELEASE_TIMER,
363
+ IDX_COMMON_LOOP_DETECT_GET_STATUS,
364
+ NUM_COMMON_LOOP_DETECT
365
+};
366
+#define ID_COMMON_LOOP_DETECT(idx) \
367
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUBG_LD, idx)
368
+#define ID_COMMON_LOOP_DETECT_SET_FUNC \
369
+ ID_COMMON_LOOP_DETECT(IDX_COMMON_LOOP_DETECT_SET_FUNC)
370
+#define ID_COMMON_LOOP_DETECT_GET_FUNC \
371
+ ID_COMMON_LOOP_DETECT(IDX_COMMON_LOOP_DETECT_GET_FUNC)
372
+#define ID_COMMON_LOOP_DETECT_SET_TIME_UNIT \
373
+ ID_COMMON_LOOP_DETECT(IDX_COMMON_LOOP_DETECT_SET_TIME_UNIT)
374
+#define ID_COMMON_LOOP_DETECT_GET_TIME_UNIT \
375
+ ID_COMMON_LOOP_DETECT(IDX_COMMON_LOOP_DETECT_GET_TIME_UNIT)
376
+#define ID_COMMON_LOOP_DETECT_SET_PKT_SEND_TIMER \
377
+ ID_COMMON_LOOP_DETECT(IDX_COMMON_LOOP_DETECT_SET_PKT_SEND_TIMER)
378
+#define ID_COMMON_LOOP_DETECT_GET_PKT_SEND_TIMER \
379
+ ID_COMMON_LOOP_DETECT(IDX_COMMON_LOOP_DETECT_GET_PKT_SEND_TIMER)
380
+#define ID_COMMON_LOOP_DETECT_SET_BLOCK_RELEASE_TIMER \
381
+ ID_COMMON_LOOP_DETECT(IDX_COMMON_LOOP_DETECT_SET_BLOCK_RELEASE_TIMER)
382
+#define ID_COMMON_LOOP_DETECT_GET_BLOCK_RELEASE_TIMER \
383
+ ID_COMMON_LOOP_DETECT(IDX_COMMON_LOOP_DETECT_GET_BLOCK_RELEASE_TIMER)
384
+#define ID_COMMON_LOOP_DETECT_GET_STATUS \
385
+ ID_COMMON_LOOP_DETECT(IDX_COMMON_LOOP_DETECT_GET_STATUS)
386
+
387
+enum{
388
+ IDX_1811_LOOP_DETECT_SET_DMAC,
389
+ IDX_1811_LOOP_DETECT_SET_SUB_TYPE,
390
+ NUM_1811_LOOP_DETECT
391
+};
392
+#define ID_1811_LOOP_DETECT(idx) \
393
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_BASIC, _CMDID_SUBG_LD, idx)
394
+#define ID_1811_LOOP_DETECT_SET_DMAC \
395
+ ID_1811_LOOP_DETECT(IDX_1811_LOOP_DETECT_SET_DMAC)
396
+#define ID_1811_LOOP_DETECT_SET_SUB_TYPE \
397
+ ID_1811_LOOP_DETECT(IDX_1811_LOOP_DETECT_SET_SUB_TYPE)
398
+/*-------------------------------------------------------------------*/
399
+#define _CMDID_SUBG_WOL 0x8
400
+#define ID_COMMON_WOL_SET_FUNC \
401
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUBG_WOL, 0)
402
+#define ID_COMMON_WOL_GET_FUNC \
403
+#define ID_1811_WOL_SET_WAKE_IF_TX_GET_ANY_PKT \
404
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_BASIC, _CMDID_SUBG_WOL, 0)
405
+/*-------------------------------------------------------------------*/
406
+#define _CMDID_SUBG_STAG 0x9
407
+enum{
408
+ IDX_COMMON_SET_CPU_PORT_LINK,
409
+ IDX_COMMON_STAG_SET_FUNC,
410
+ IDX_COMMON_STAG_GET_TYPE_LENGTH,
411
+ IDX_COMMON_CONFIG_CPU_PORT,
412
+ NUM_COMMON_STAG
413
+};
414
+#define ID_COMMON_STAG(idx) \
415
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUBG_STAG, idx)
416
+#define ID_COMMON_SET_CPU_PORT_LINK \
417
+ ID_COMMON_STAG(IDX_COMMON_SET_CPU_PORT_LINK)
418
+#define ID_COMMON_STAG_SET_FUNC \
419
+ ID_COMMON_STAG(IDX_COMMON_STAG_SET_FUNC)
420
+#define ID_COMMON_STAG_GET_TYPE_LENGTH \
421
+ ID_COMMON_STAG(IDX_COMMON_STAG_GET_TYPE_LENGTH )
422
+#define ID_COMMON_CONFIG_CPU_PORT\
423
+ ID_COMMON_STAG(IDX_COMMON_CONFIG_CPU_PORT)
424
+
425
+/*-------------------------------------------------------------------*/
426
+#define _CMDID_SUBG_IGMP 0xA
427
+enum{
428
+ IDX_1811_IGMP_SET_SNOOPING_FUNCTION,
429
+ IDX_1811_IGMP_GET_SNOOPING_FUNCTION,
430
+ IDX_1811_IGMP_SET_MCT_BY_CPU,
431
+ IDX_1811_IGMP_GET_MCT_BY_CPU,
432
+ IDX_1811_IGMP_SET_ROUTER_LIST_MAKE_BY_CPU,
433
+ IDX_1811_IGMP_GET_ROUTER_LIST_MAKE_BY_CPU,
434
+ IDX_1811_IGMP_SET_PACKET_FORWARD_RULE,
435
+ IDX_1811_IGMP_GET_PACKET_FORWARD_RULE,
436
+ IDX_1811_IGMP_SET_ROUTER_LIST,
437
+ IDX_1811_IGMP_GET_ROUTER_LIST,
438
+ IDX_1811_IGMP_SET_HASHING_METHOD,
439
+ IDX_1811_IGMP_GET_HASHING_METHOD,
440
+ IDX_1811_MLD_SET_FORWARD_RULE,
441
+ IDX_1811_MLD_GET_FORWARD_RULE,
442
+ IDX_1811_MT_SET_RULE,
443
+ IDX_1811_MT_GET_RULE,
444
+ IDX_1811_SLT_SET_RULE,
445
+ IDX_1811_SLT_GET_RULE,
446
+ NUM_1811_IGMP
447
+};
448
+
449
+#define ID_1811_IGMP(idx) \
450
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_BASIC, _CMDID_SUBG_IGMP, idx)
451
+
452
+#define ID_1811_IGMP_SET_SNOOPING_FUNCTION \
453
+ ID_1811_IGMP(IDX_1811_IGMP_SET_SNOOPING_FUNCTION)
454
+#define ID_1811_IGMP_GET_SNOOPING_FUNCTION \
455
+ ID_1811_IGMP(IDX_1811_IGMP_GET_SNOOPING_FUNCTION)
456
+#define ID_1811_IGMP_SET_MCT_BY_CPU \
457
+ ID_1811_IGMP(IDX_1811_IGMP_SET_MCT_BY_CPU)
458
+#define ID_1811_IGMP_GET_MCT_BY_CPU \
459
+ ID_1811_IGMP(IDX_1811_IGMP_GET_MCT_BY_CPU)
460
+#define ID_1811_IGMP_SET_ROUTER_LIST_MAKE_BY_CPU \
461
+ ID_1811_IGMP(IDX_1811_IGMP_SET_ROUTER_LIST_MAKE_BY_CPU)
462
+#define ID_1811_IGMP_GET_ROUTER_LIST_MAKE_BY_CPU \
463
+ ID_1811_IGMP(IDX_1811_IGMP_GET_ROUTER_LIST_MAKE_BY_CPU)
464
+#define ID_1811_IGMP_SET_PACKET_FORWARD_RULE \
465
+ ID_1811_IGMP(IDX_1811_IGMP_SET_PACKET_FORWARD_RULE)
466
+#define ID_1811_IGMP_GET_PACKET_FORWARD_RULE \
467
+ ID_1811_IGMP(IDX_1811_IGMP_GET_PACKET_FORWARD_RULE)
468
+#define ID_1811_IGMP_SET_ROUTER_LIST \
469
+ ID_1811_IGMP(IDX_1811_IGMP_SET_ROUTER_LIST)
470
+#define ID_1811_IGMP_GET_ROUTER_LIST \
471
+ ID_1811_IGMP(IDX_1811_IGMP_GET_ROUTER_LIST)
472
+#define ID_1811_IGMP_SET_HASHING_METHOD \
473
+ ID_1811_IGMP(IDX_1811_IGMP_SET_HASHING_METHOD)
474
+#define ID_1811_IGMP_GET_HASHING_METHOD \
475
+ ID_1811_IGMP(IDX_1811_IGMP_GET_HASHING_METHOD)
476
+#define ID_1811_MLD_SET_FORWARD_RULE \
477
+ ID_1811_IGMP(IDX_1811_MLD_SET_FORWARD_RULE)
478
+#define ID_1811_MLD_GET_FORWARD_RULE \
479
+ ID_1811_IGMP(IDX_1811_MLD_GET_FORWARD_RULE)
480
+#define ID_1811_MT_SET_RULE \
481
+ ID_1811_IGMP(IDX_1811_MT_SET_RULE)
482
+#define ID_1811_MT_GET_RULE \
483
+ ID_1811_IGMP(IDX_1811_MT_GET_RULE)
484
+#define ID_1811_SLT_SET_RULE \
485
+ ID_1811_IGMP(IDX_1811_SLT_SET_RULE)
486
+#define ID_1811_SLT_GET_RULE \
487
+ ID_1811_IGMP(IDX_1811_SLT_GET_RULE)
488
+/*-------------------------------------------------------------------*/
489
+#define _CMDID_SUBG_PTP 0xB
490
+
491
+enum{
492
+ IDX_1811_PTP_SET_ENABLE,
493
+ IDX_1811_PTP_GET_ENABLE,
494
+ IDX_1811_PTP_SET_DA_011B19000000,
495
+ IDX_1811_PTP_GET_DA_011B19000000,
496
+ IDX_1811_PTP_SET_DA_0180C200000E,
497
+ IDX_1811_PTP_GET_DA_0180C200000E,
498
+ IDX_1811_PTP_SET_UDP_DP,
499
+ IDX_1811_PTP_GET_UDP_DP,
500
+ IDX_1811_PTP_SET_UDP_SP,
501
+ IDX_1811_PTP_GET_UDP_SP,
502
+ IDX_1811_PTP_SET_TO_CPU,
503
+ IDX_1811_PTP_GET_TO_CPU,
504
+ IDX_1811_PTP_SET_SPECIAL_TAG,
505
+ IDX_1811_PTP_GET_SPECIAL_TAG,
506
+ IDX_1811_PTP_SET_CLOCK_RESET,
507
+ IDX_1811_PTP_GET_TIMESTAMP,
508
+ IDX_1811_PTP_SET_CLOCK_ENABLE,
509
+ IDX_1811_PTP_GET_CLOCK_ENABLE,
510
+ IDX_1811_PTP_SET_OVERWRITE_ENABLE,
511
+ IDX_1811_PTP_GET_OVERWRITE_ENABLE,
512
+ IDX_1811_PTP_SET_PROGRAMMABLE,
513
+ IDX_1811_PTP_GET_PROGRAMMABLE,
514
+ IDX_1811_PTP_SET_PROGRAMMABLE_OUTPUT,
515
+ IDX_1811_PTP_SET_TIMESTAMP_ENABLE,
516
+ IDX_1811_PTP_GET_TIMESTAMP_ENABLE,
517
+ IDX_1811_PTP_SET_TIMESTAMP_CLEAR,
518
+ IDX_1811_PTP_SET_TIMEDATA,
519
+ IDX_1811_PTP_GET_TIMEDATA,
520
+ IDX_1811_PTP_ADD_TIMEDATA,
521
+ IDX_1811_PTP_SUB_TIMEDATA,
522
+ IDX_1811_PTP_SET_FREQUENCY_ADD,
523
+ IDX_1811_PTP_GET_FREQUENCY_ADD,
524
+ IDX_1811_PTP_SET_CLOCK_PERIOD,
525
+ IDX_1811_PTP_GET_CLOCK_PERIOD,
526
+ IDX_1811_PTP_SET_PROGRAMMABLE_CONFIG,
527
+ IDX_1811_PTP_SET_DURATION_FREQUENCY_COMPENSATION,
528
+ IDX_1811_PTP_SET_ALWAYS_FREQUENCY_COMPENSATION,
529
+ IDX_1811_PTP_GET_INGRESS_LATENCY_10,
530
+ IDX_1811_PTP_GET_INGRESS_LATENCY_100,
531
+ IDX_1811_PTP_GET_INGRESS_LATENCY_FIBER,
532
+ IDX_1811_PTP_GET_EGRESS_LATENCY_10,
533
+ IDX_1811_PTP_GET_EGRESS_LATENCY_100,
534
+ IDX_1811_PTP_GET_EGRESS_LATENCY_FIBER,
535
+ NUM_1811_PTP
536
+};
537
+
538
+#define ID_1811_PTP(idx) \
539
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_BASIC, _CMDID_SUBG_PTP, idx)
540
+
541
+#define ID_1811_PTP_SET_ENABLE \
542
+ ID_1811_PTP(IDX_1811_PTP_SET_ENABLE)
543
+#define ID_1811_PTP_GET_ENABLE \
544
+ ID_1811_PTP(IDX_1811_PTP_GET_ENABLE)
545
+#define ID_1811_PTP_SET_DA_011B19000000 \
546
+ ID_1811_PTP(IDX_1811_PTP_SET_DA_011B19000000)
547
+#define ID_1811_PTP_GET_DA_011B19000000 \
548
+ ID_1811_PTP(IDX_1811_PTP_GET_DA_011B19000000)
549
+#define ID_1811_PTP_SET_DA_0180C200000E \
550
+ ID_1811_PTP(IDX_1811_PTP_SET_DA_0180C200000E)
551
+#define ID_1811_PTP_GET_DA_0180C200000E \
552
+ ID_1811_PTP(IDX_1811_PTP_GET_DA_0180C200000E)
553
+#define ID_1811_PTP_SET_UDP_DP \
554
+ ID_1811_PTP(IDX_1811_PTP_SET_UDP_DP)
555
+#define ID_1811_PTP_GET_UDP_DP \
556
+ ID_1811_PTP(IDX_1811_PTP_GET_UDP_DP)
557
+#define ID_1811_PTP_SET_UDP_SP \
558
+ ID_1811_PTP(IDX_1811_PTP_SET_UDP_SP)
559
+#define ID_1811_PTP_GET_UDP_SP \
560
+ ID_1811_PTP(IDX_1811_PTP_GET_UDP_SP)
561
+#define ID_1811_PTP_SET_TO_CPU \
562
+ ID_1811_PTP(IDX_1811_PTP_SET_TO_CPU)
563
+#define ID_1811_PTP_GET_TO_CPU \
564
+ ID_1811_PTP(IDX_1811_PTP_GET_TO_CPU)
565
+#define ID_1811_PTP_SET_SPECIAL_TAG \
566
+ ID_1811_PTP(IDX_1811_PTP_SET_SPECIAL_TAG)
567
+#define ID_1811_PTP_GET_SPECIAL_TAG \
568
+ ID_1811_PTP(IDX_1811_PTP_GET_SPECIAL_TAG)
569
+#define ID_1811_PTP_SET_CLOCK_RESET \
570
+ ID_1811_PTP(IDX_1811_PTP_SET_CLOCK_RESET)
571
+#define ID_1811_PTP_GET_TIMESTAMP \
572
+ ID_1811_PTP(IDX_1811_PTP_GET_TIMESTAMP)
573
+#define ID_1811_PTP_SET_CLOCK_ENABLE \
574
+ ID_1811_PTP(IDX_1811_PTP_SET_CLOCK_ENABLE)
575
+#define ID_1811_PTP_GET_CLOCK_ENABLE \
576
+ ID_1811_PTP(IDX_1811_PTP_GET_CLOCK_ENABLE)
577
+#define ID_1811_PTP_SET_OVERWRITE_ENABLE \
578
+ ID_1811_PTP(IDX_1811_PTP_SET_OVERWRITE_ENABLE)
579
+#define ID_1811_PTP_GET_OVERWRITE_ENABLE \
580
+ ID_1811_PTP(IDX_1811_PTP_GET_OVERWRITE_ENABLE)
581
+#define ID_1811_PTP_SET_PROGRAMMABLE \
582
+ ID_1811_PTP(IDX_1811_PTP_SET_PROGRAMMABLE)
583
+#define ID_1811_PTP_GET_PROGRAMMABLE \
584
+ ID_1811_PTP(IDX_1811_PTP_GET_PROGRAMMABLE)
585
+#define ID_1811_PTP_SET_PROGRAMMABLE_OUTPUT \
586
+ ID_1811_PTP(IDX_1811_PTP_SET_PROGRAMMABLE_OUTPUT)
587
+#define ID_1811_PTP_SET_TIMESTAMP_ENABLE \
588
+ ID_1811_PTP(IDX_1811_PTP_SET_TIMESTAMP_ENABLE)
589
+#define ID_1811_PTP_GET_TIMESTAMP_ENABLE \
590
+ ID_1811_PTP(IDX_1811_PTP_GET_TIMESTAMP_ENABLE)
591
+#define ID_1811_PTP_SET_TIMESTAMP_CLEAR \
592
+ ID_1811_PTP(IDX_1811_PTP_SET_TIMESTAMP_CLEAR)
593
+#define ID_1811_PTP_SET_TIMEDATA \
594
+ ID_1811_PTP(IDX_1811_PTP_SET_TIMEDATA)
595
+#define ID_1811_PTP_GET_TIMEDATA \
596
+ ID_1811_PTP(IDX_1811_PTP_GET_TIMEDATA)
597
+#define ID_1811_PTP_ADD_TIMEDATA \
598
+ ID_1811_PTP(IDX_1811_PTP_ADD_TIMEDATA)
599
+#define ID_1811_PTP_SUB_TIMEDATA \
600
+ ID_1811_PTP(IDX_1811_PTP_SUB_TIMEDATA)
601
+#define ID_1811_PTP_SET_FREQUENCY_ADD \
602
+ ID_1811_PTP(IDX_1811_PTP_SET_FREQUENCY_ADD)
603
+#define ID_1811_PTP_GET_FREQUENCY_ADD \
604
+ ID_1811_PTP(IDX_1811_PTP_GET_FREQUENCY_ADD)
605
+#define ID_1811_PTP_SET_CLOCK_PERIOD \
606
+ ID_1811_PTP(IDX_1811_PTP_SET_CLOCK_PERIOD)
607
+#define ID_1811_PTP_GET_CLOCK_PERIOD \
608
+ ID_1811_PTP(IDX_1811_PTP_GET_CLOCK_PERIOD)
609
+#define ID_1811_PTP_SET_PROGRAMMABLE_CONFIG \
610
+ ID_1811_PTP(IDX_1811_PTP_SET_PROGRAMMABLE_CONFIG)
611
+#define ID_1811_PTP_SET_DURATION_FREQUENCY_COMPENSATION \
612
+ ID_1811_PTP(IDX_1811_PTP_SET_DURATION_FREQUENCY_COMPENSATION)
613
+#define ID_1811_PTP_SET_ALWAYS_FREQUENCY_COMPENSATION \
614
+ ID_1811_PTP(IDX_1811_PTP_SET_ALWAYS_FREQUENCY_COMPENSATION)
615
+#define ID_1811_PTP_GET_INGRESS_LATENCY_10 \
616
+ ID_1811_PTP(IDX_1811_PTP_GET_INGRESS_LATENCY_10)
617
+#define ID_1811_PTP_GET_INGRESS_LATENCY_100 \
618
+ ID_1811_PTP(IDX_1811_PTP_GET_INGRESS_LATENCY_100)
619
+#define ID_1811_PTP_GET_INGRESS_LATENCY_FIBER \
620
+ ID_1811_PTP(IDX_1811_PTP_GET_INGRESS_LATENCY_FIBER)
621
+#define ID_1811_PTP_GET_EGRESS_LATENCY_10 \
622
+ ID_1811_PTP(IDX_1811_PTP_GET_EGRESS_LATENCY_10)
623
+#define ID_1811_PTP_GET_EGRESS_LATENCY_100 \
624
+ ID_1811_PTP(IDX_1811_PTP_GET_EGRESS_LATENCY_100)
625
+#define ID_1811_PTP_GET_EGRESS_LATENCY_FIBER \
626
+ ID_1811_PTP(IDX_1811_PTP_GET_EGRESS_LATENCY_FIBER)
627
+
628
+/*-------------------------------------------------------------------*/
629
+#define _CMDID_SUB_BANDWIDTH 0xC
630
+#define RATE_SCALE_UNIT 64000
631
+enum{
632
+ IDX_COMMON_BANDWIDTH_SET_INGRESS_RATE,
633
+ IDX_COMMON_BANDWIDTH_GET_INGRESS_RATE,
634
+ IDX_COMMON_BANDWIDTH_SET_EGRESS_RATE,
635
+ IDX_COMMON_BANDWIDTH_GET_EGRESS_RATE,
636
+ IDX_COMMON_BANDWIDTH_SET_EGRESS_PERIOD,
637
+ IDX_COMMON_BANDWIDTH_GET_EGRESS_PERIOD,
638
+ NUM_COMMON_BANDWIDTH
639
+};
640
+#define ID_COMMON_BANDWIDTH(idx) \
641
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUB_BANDWIDTH, idx)
642
+
643
+#define ID_COMMON_BANDWIDTH_SET_INGRESS_RATE \
644
+ ID_COMMON_BANDWIDTH(IDX_COMMON_BANDWIDTH_SET_INGRESS_RATE)
645
+#define ID_COMMON_BANDWIDTH_GET_INGRESS_RATE \
646
+ ID_COMMON_BANDWIDTH(IDX_COMMON_BANDWIDTH_GET_INGRESS_RATE)
647
+#define ID_COMMON_BANDWIDTH_SET_EGRESS_RATE \
648
+ ID_COMMON_BANDWIDTH(IDX_COMMON_BANDWIDTH_SET_EGRESS_RATE)
649
+#define ID_COMMON_BANDWIDTH_GET_EGRESS_RATE \
650
+ ID_COMMON_BANDWIDTH(IDX_COMMON_BANDWIDTH_GET_EGRESS_RATE)
651
+#define ID_COMMON_BANDWIDTH_SET_EGRESS_PERIOD \
652
+ ID_COMMON_BANDWIDTH(IDX_COMMON_BANDWIDTH_SET_EGRESS_PERIOD)
653
+#define ID_COMMON_BANDWIDTH_GET_EGRESS_PERIOD \
654
+ ID_COMMON_BANDWIDTH(IDX_COMMON_BANDWIDTH_GET_EGRESS_PERIOD)
655
+
656
+/*-------------------------------------------------------------------*/
657
+#define _CMDID_SUBG_MISC 0xF
658
+enum{
659
+ IDX_COMMON_8021X_PORT_LOCK_SET_FUNC,
660
+ IDX_COMMON_8021X_PORT_LOCK_GET_FUNC,
661
+ IDX_COMMON_MISC_SET_REG,
662
+ IDX_COMMON_MISC_GET_REG,
663
+ IDX_COMMON_MISC_SET_CPU_REG,
664
+ IDX_COMMON_MISC_GET_CPU_REG,
665
+ IDX_COMMON_MISC_SET_SWITCH_RESTART,
666
+ IDX_COMMON_MISC_SET_SWITCH_RESET,
667
+ IDX_COMMON_MISC_SET_CPU_IF_SPEED,
668
+ IDX_COMMON_MISC_SET_EEPROM_BYTE,
669
+ IDX_COMMON_MISC_GET_EEPROM_BYTE,
670
+ NUM_COMMON_MISC
671
+};
672
+#define ID_COMMON_MISC(idx) \
673
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_BASIC, _CMDID_SUBG_MISC, idx)
674
+
675
+#define ID_COMMON_8021X_PORT_LOCK_SET_FUNC \
676
+ ID_COMMON_MISC(IDX_COMMON_8021X_PORT_LOCK_SET_FUNC)
677
+#define ID_COMMON_8021X_PORT_LOCK_GET_FUNC \
678
+ ID_COMMON_MISC(IDX_COMMON_8021X_PORT_LOCK_GET_FUNC)
679
+#define ID_COMMON_MISC_SET_REG \
680
+ ID_COMMON_MISC(IDX_COMMON_MISC_SET_REG)
681
+#define ID_COMMON_MISC_GET_REG \
682
+ ID_COMMON_MISC(IDX_COMMON_MISC_GET_REG)
683
+#define ID_COMMON_MISC_SET_CPU_REG \
684
+ ID_COMMON_MISC(IDX_COMMON_MISC_SET_CPU_REG)
685
+#define ID_COMMON_MISC_GET_CPU_REG \
686
+ ID_COMMON_MISC(IDX_COMMON_MISC_GET_CPU_REG)
687
+#define ID_COMMON_MISC_SET_SWITCH_RESTART \
688
+ ID_COMMON_MISC(IDX_COMMON_MISC_SET_SWITCH_RESTART)
689
+#define ID_COMMON_MISC_SET_SWITCH_RESET\
690
+ ID_COMMON_MISC(IDX_COMMON_MISC_SET_SWITCH_RESET)
691
+#define ID_COMMON_MISC_SET_CPU_IF_SPEED\
692
+ ID_COMMON_MISC(IDX_COMMON_MISC_SET_CPU_IF_SPEED)
693
+#define ID_COMMON_MISC_SET_EEPROM_BYTE\
694
+ ID_COMMON_MISC(IDX_COMMON_MISC_SET_EEPROM_BYTE)
695
+#define ID_COMMON_MISC_GET_EEPROM_BYTE\
696
+ ID_COMMON_MISC(IDX_COMMON_MISC_GET_EEPROM_BYTE)
697
+
698
+#if 0
699
+#define ID_1811_MAC_LOOP_BACK_SET_FUNC \
700
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_BASIC, _CMDID_SUBG_MISC, 0)
701
+#endif
702
+/*===================================================================*/
703
+#define _CMDID_GRP_VLAN 0x02
704
+/*-------------------------------------------------------------------*/
705
+#define _CMDID_SUBG_VLAN 0x1
706
+
707
+enum{
708
+ IDX_COMMON_VLAN_SET_EGRESS_FRAME, //0
709
+ IDX_COMMON_VLAN_GET_EGRESS_FRAME,
710
+ IDX_COMMON_VLAN_SET_TAGGING,
711
+ IDX_COMMON_VLAN_SET_TYPE,
712
+ IDX_COMMON_VLAN_SET_GROUP,
713
+ IDX_COMMON_VLAN_SET_QINQ_TYPE, //5
714
+ IDX_COMMON_VLAN_SET_QINQ_P_ADDTAG,
715
+ IDX_COMMON_VLAN_GET_QINQ_P_ADDTAG,
716
+ IDX_COMMON_VLAN_SET_QINQ_P_RMVTAG,
717
+ IDX_COMMON_VLAN_GET_QINQ_P_RMVTAG,
718
+ IDX_COMMON_VLAN_SET_QINQ_P_RXDET, //10
719
+ IDX_COMMON_VLAN_GET_QINQ_P_RXDET,
720
+ IDX_COMMON_VLAN_SET_QINQ_P_KEEP,
721
+ IDX_COMMON_VLAN_GET_QINQ_P_KEEP,
722
+ IDX_COMMON_VLAN_SET_QINQ_P_INDEX,
723
+ IDX_COMMON_VLAN_GET_QINQ_P_INDEX, //15
724
+ IDX_COMMON_VLAN_SET_QINQ_INDEX,
725
+ IDX_COMMON_VLAN_SET_QINQ_STAG_SELECT_METHOD,
726
+ IDX_COMMON_VLAN_SET_PORT_ADDTAG,
727
+ IDX_COMMON_VLAN_GET_PORT_ADDTAG,
728
+ IDX_COMMON_VLAN_SET_PORT_RMVTAG, //20
729
+ IDX_COMMON_VLAN_GET_PORT_RMVTAG,
730
+ IDX_COMMON_VLAN_SET_PORT_FORCE,
731
+ IDX_COMMON_VLAN_GET_PORT_FORCE,
732
+ IDX_COMMON_VLAN_SET_PORT_UPLINK,
733
+ IDX_COMMON_VLAN_GET_PORT_UPLINK, //25
734
+ IDX_COMMON_VLAN_SET_PORT_EXCLUSIVE,
735
+ IDX_COMMON_VLAN_GET_PORT_EXCLUSIVE,
736
+ IDX_COMMON_VLAN_SET_PORT_EGRESS,
737
+ IDX_COMMON_VLAN_GET_PORT_EGRESS,
738
+ IDX_COMMON_VLAN_SET_PORT_INGRESS_FRAME, //30
739
+ IDX_COMMON_VLAN_SET_PORT_INGRESS_CHECK,
740
+ IDX_COMMON_VLAN_GET_PORT_INGRESS_CHECK,
741
+ IDX_COMMON_VLAN_SET_PORT_VID,
742
+ IDX_COMMON_VLAN_SET_PROTOCOL_MODE,
743
+ IDX_COMMON_VLAN_SET_PROTOCOL_VID, //35
744
+ IDX_COMMON_VLAN_SET_PROTOCOL_TYPE,
745
+ IDX_COMMON_VLAN_CLEAR_PROTOCOL,
746
+ IDX_COMMON_VLAN_SET_MAC_VLAN,
747
+ IDX_COMMON_VLAN_SET_MAC_VLAN_VLANTABLE_CONFIG,
748
+ IDX_COMMON_VLAN_GET_MAC_VLAN_VLANTABLE_CONFIG, //40
749
+ IDX_COMMON_VLAN_SET_MAC_VLAN_UNKNOWN,
750
+ NUM_COMMON_VLAN
751
+};
752
+
753
+#define ID_COMMON_VLAN(idx) \
754
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_VLAN, _CMDID_SUBG_VLAN, idx)
755
+
756
+#define ID_COMMON_VLAN_SET_EGRESS_FRAME \
757
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_EGRESS_FRAME)
758
+#define ID_COMMON_VLAN_GET_EGRESS_FRAME \
759
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_EGRESS_FRAME)
760
+#define ID_COMMON_VLAN_SET_TAGGING \
761
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_TAGGING)
762
+#define ID_COMMON_VLAN_SET_TYPE \
763
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_TYPE)
764
+#define ID_COMMON_VLAN_SET_GROUP \
765
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_GROUP)
766
+
767
+#define ID_COMMON_VLAN_SET_QINQ_TYPE \
768
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_QINQ_TYPE)
769
+#define ID_COMMON_VLAN_SET_QINQ_P_ADDTAG \
770
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_QINQ_P_ADDTAG)
771
+#define ID_COMMON_VLAN_GET_QINQ_P_ADDTAG \
772
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_QINQ_P_ADDTAG)
773
+#define ID_COMMON_VLAN_SET_QINQ_P_RMVTAG \
774
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_QINQ_P_RMVTAG)
775
+#define ID_COMMON_VLAN_GET_QINQ_P_RMVTAG \
776
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_QINQ_P_RMVTAG)
777
+#define ID_COMMON_VLAN_SET_QINQ_P_RXDET \
778
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_QINQ_P_RXDET)
779
+#define ID_COMMON_VLAN_GET_QINQ_P_RXDET \
780
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_QINQ_P_RXDET)
781
+#define ID_COMMON_VLAN_SET_QINQ_P_KEEP \
782
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_QINQ_P_KEEP)
783
+#define ID_COMMON_VLAN_GET_QINQ_P_KEEP \
784
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_QINQ_P_KEEP)
785
+#define ID_COMMON_VLAN_SET_QINQ_P_INDEX \
786
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_QINQ_P_INDEX)
787
+#define ID_COMMON_VLAN_GET_QINQ_P_INDEX \
788
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_QINQ_P_INDEX)
789
+#define ID_COMMON_VLAN_SET_QINQ_INDEX \
790
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_QINQ_INDEX)
791
+#define ID_COMMON_VLAN_SET_QINQ_STAG_SELECT_METHOD \
792
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_QINQ_STAG_SELECT_METHOD)
793
+
794
+#define ID_COMMON_VLAN_SET_PORT_ADDTAG \
795
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PORT_ADDTAG)
796
+#define ID_COMMON_VLAN_GET_PORT_ADDTAG \
797
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_PORT_ADDTAG)
798
+#define ID_COMMON_VLAN_SET_PORT_RMVTAG \
799
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PORT_RMVTAG)
800
+#define ID_COMMON_VLAN_GET_PORT_RMVTAG \
801
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_PORT_RMVTAG)
802
+#define ID_COMMON_VLAN_SET_PORT_FORCE \
803
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PORT_FORCE)
804
+#define ID_COMMON_VLAN_GET_PORT_FORCE \
805
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_PORT_FORCE)
806
+#define ID_COMMON_VLAN_SET_PORT_UPLINK \
807
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PORT_UPLINK)
808
+#define ID_COMMON_VLAN_GET_PORT_UPLINK \
809
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_PORT_UPLINK)
810
+#define ID_COMMON_VLAN_SET_PORT_EXCLUSIVE \
811
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PORT_EXCLUSIVE)
812
+#define ID_COMMON_VLAN_GET_PORT_EXCLUSIVE \
813
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_PORT_EXCLUSIVE)
814
+#define ID_COMMON_VLAN_SET_PORT_EGRESS \
815
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PORT_EGRESS)
816
+#define ID_COMMON_VLAN_GET_PORT_EGRESS \
817
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_PORT_EGRESS)
818
+#define ID_COMMON_VLAN_SET_PORT_INGRESS_FRAME \
819
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PORT_INGRESS_FRAME)
820
+#define ID_COMMON_VLAN_SET_PORT_INGRESS_CHECK \
821
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PORT_INGRESS_CHECK)
822
+#define ID_COMMON_VLAN_GET_PORT_INGRESS_CHECK \
823
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_PORT_INGRESS_CHECK)
824
+#define ID_COMMON_VLAN_SET_PORT_VID \
825
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PORT_VID)
826
+
827
+#define ID_COMMON_VLAN_SET_PROTOCOL_MODE \
828
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PROTOCOL_MODE)
829
+#define ID_COMMON_VLAN_SET_PROTOCOL_VID \
830
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PROTOCOL_VID)
831
+#define ID_COMMON_VLAN_SET_PROTOCOL_TYPE \
832
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_PROTOCOL_TYPE)
833
+#define ID_COMMON_VLAN_CLEAR_PROTOCOL \
834
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_CLEAR_PROTOCOL)
835
+#define ID_COMMON_VLAN_SET_MAC_VLAN \
836
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_MAC_VLAN)
837
+#define ID_COMMON_VLAN_SET_MAC_VLAN_VLANTABLE_CONFIG \
838
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_MAC_VLAN_VLANTABLE_CONFIG)
839
+#define ID_COMMON_VLAN_GET_MAC_VLAN_VLANTABLE_CONFIG \
840
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_GET_MAC_VLAN_VLANTABLE_CONFIG)
841
+#define ID_COMMON_VLAN_SET_MAC_VLAN_UNKNOWN \
842
+ ID_COMMON_VLAN(IDX_COMMON_VLAN_SET_MAC_VLAN_UNKNOWN)
843
+
844
+enum{
845
+ IDX_IP1811_VLAN_SET_ENTRY_MEMBER, //0
846
+ IDX_IP1811_VLAN_SET_ENTRY_ADDTAG,
847
+ IDX_IP1811_VLAN_SET_ENTRY_RMVTAG,
848
+ IDX_IP1811_VLAN_SET_ENTRY_PRIORITY,
849
+ IDX_IP1811_VLAN_SET_ENTRY_FID,
850
+ IDX_IP1811_VLAN_GET_ENTRY_FID, //5
851
+ IDX_IP1811_VLAN_DELETE_ENTRY,
852
+ NUM_IP1811_VLAN
853
+};
854
+
855
+#define ID_IP1811_VLAN(idx) \
856
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_VLAN, _CMDID_SUBG_VLAN, idx)
857
+
858
+#define ID_IP1811_VLAN_SET_ENTRY_MEMBER \
859
+ ID_IP1811_VLAN(IDX_IP1811_VLAN_SET_ENTRY_MEMBER)
860
+#define ID_IP1811_VLAN_SET_ENTRY_ADDTAG \
861
+ ID_IP1811_VLAN(IDX_IP1811_VLAN_SET_ENTRY_ADDTAG)
862
+#define ID_IP1811_VLAN_SET_ENTRY_RMVTAG \
863
+ ID_IP1811_VLAN(IDX_IP1811_VLAN_SET_ENTRY_RMVTAG)
864
+#define ID_IP1811_VLAN_SET_ENTRY_PRIORITY \
865
+ ID_IP1811_VLAN(IDX_IP1811_VLAN_SET_ENTRY_PRIORITY)
866
+#define ID_IP1811_VLAN_SET_ENTRY_FID \
867
+ ID_IP1811_VLAN(IDX_IP1811_VLAN_SET_ENTRY_FID)
868
+#define ID_IP1811_VLAN_GET_ENTRY_FID \
869
+ ID_IP1811_VLAN(IDX_IP1811_VLAN_GET_ENTRY_FID)
870
+#define ID_IP1811_VLAN_DELETE_ENTRY \
871
+ ID_IP1811_VLAN(IDX_IP1811_VLAN_DELETE_ENTRY)
872
+
873
+/*===================================================================*/
874
+#define _CMDID_GRP_QOS 0x03
875
+/*-------------------------------------------------------------------*/
876
+#define _CMDID_SUB_QOS 0x1
877
+enum{
878
+ IDX_IP1811_SET_QOS_AGING_FUNCTION,
879
+ IDX_IP1811_GET_QOS_AGING_FUNCTION,
880
+ IDX_IP1811_SET_QOS_AGING_TIME,
881
+ IDX_IP1811_GET_QOS_AGING_TIME,
882
+ IDX_IP1811_SET_QOS_FASTAGING,
883
+ IDX_IP1811_GET_QOS_FASTAGING,
884
+
885
+ IDX_IP1811_SET_COS_IGMP,
886
+ IDX_IP1811_GET_COS_IGMP,
887
+ IDX_IP1811_SET_COS_MACADDRESS,
888
+ IDX_IP1811_GET_COS_MACADDRESS,
889
+ IDX_IP1811_SET_COS_VID,
890
+ IDX_IP1811_GET_COS_VID,
891
+ IDX_IP1811_SET_COS_TCPUDPPORT,
892
+ IDX_IP1811_GET_COS_TCPUDPPORT,
893
+ IDX_IP1811_SET_COS_DSCP,
894
+ IDX_IP1811_GET_COS_DSCP,
895
+ IDX_IP1811_SET_COS_8021P,
896
+ IDX_IP1811_GET_COS_8021P,
897
+ IDX_IP1811_SET_COS_PHYSICALPORT,
898
+ IDX_IP1811_GET_COS_PHYSICALPORT,
899
+ IDX_IP1811_SET_COS_PORT_QUEUE,
900
+ IDX_IP1811_GET_COS_PORT_QUEUE,
901
+ IDX_IP1811_SET_COS_8021PEDTION,
902
+ IDX_IP1811_GET_COS_8021PEDTION,
903
+ IDX_IP1811_SET_COS_DSCPBASE_DSCP,
904
+ IDX_IP1811_GET_COS_DSCPBASE_DSCP,
905
+ IDX_IP1811_SET_COS_DSCPBASE_NOMATCHACTION,
906
+ IDX_IP1811_GET_COS_DSCPBASE_NOMATCHACTION,
907
+
908
+ IDX_IP1811_SET_QOSMODE_GROUP_MEMEBER,
909
+ IDX_IP1811_GET_QOSMODE_GROUP_MEMEBER,
910
+ IDX_IP1811_SET_QOSGROUPB_EN,
911
+ IDX_IP1811_GET_QOSGROUPB_EN,
912
+ IDX_IP1811_SET_QOS_MODE,
913
+ IDX_IP1811_GET_QOS_MODE,
914
+ IDX_IP1811_SET_QOS_METHOD,
915
+ IDX_IP1811_GET_QOS_METHOD,
916
+ IDX_IP1811_SET_QOS_WEIGHT,
917
+ IDX_IP1811_GET_QOS_WEIGHT,
918
+ IDX_IP1811_SET_QOS_MAXBANDWIDTH,
919
+ IDX_IP1811_GET_QOS_MAXBANDWIDTH,
920
+ IDX_IP1811_SET_QOS_UNIT,
921
+ IDX_IP1811_GET_QOS_UNIT,
922
+ IDX_IP1811_SET_QOS_RATIOVALUE0_DEF,
923
+ IDX_IP1811_GET_QOS_RATIOVALUE0_DEF,
924
+ IDX_IP1811_SET_QOS_SBM_DBM,
925
+ IDX_IP1811_GET_QOS_SBM_DBM,
926
+ IDX_IP1811_SET_QOS_DBM_EN,
927
+ IDX_IP1811_GET_QOS_DBM_EN,
928
+
929
+ IDX_IP1811_SET_QOS_REMAP,
930
+ IDX_IP1811_GET_QOS_REMAP,
931
+ NUM_IP1811_QOS
932
+};
933
+#define ID_IP1811_QOS(idx) \
934
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_QOS, _CMDID_SUB_QOS, idx)
935
+
936
+#define ID_IP1811_SET_QOS_AGING_FUNCTION \
937
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_AGING_FUNCTION)
938
+#define ID_IP1811_GET_QOS_AGING_FUNCTION \
939
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_AGING_FUNCTION)
940
+#define ID_IP1811_SET_QOS_AGING_TIME \
941
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_AGING_TIME)
942
+#define ID_IP1811_GET_QOS_AGING_TIME \
943
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_AGING_TIME)
944
+#define ID_IP1811_SET_QOS_FASTAGING \
945
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_FASTAGING)
946
+#define ID_IP1811_GET_QOS_FASTAGING \
947
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_FASTAGING)
948
+
949
+#define ID_IP1811_SET_COS_IGMP \
950
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_IGMP)
951
+#define ID_IP1811_GET_COS_IGMP \
952
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_IGMP)
953
+#define ID_IP1811_SET_COS_MACADDRESS \
954
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_MACADDRESS)
955
+#define ID_IP1811_GET_COS_MACADDRESS \
956
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_MACADDRESS)
957
+#define ID_IP1811_SET_COS_VID \
958
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_VID)
959
+#define ID_IP1811_GET_COS_VID \
960
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_VID)
961
+#define ID_IP1811_SET_COS_TCPUDPPORT \
962
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_TCPUDPPORT)
963
+#define ID_IP1811_GET_COS_TCPUDPPORT \
964
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_TCPUDPPORT)
965
+#define ID_IP1811_SET_COS_DSCP \
966
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_DSCP)
967
+#define ID_IP1811_GET_COS_DSCP \
968
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_DSCP)
969
+#define ID_IP1811_SET_COS_8021P \
970
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_8021P)
971
+#define ID_IP1811_GET_COS_8021P \
972
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_8021P)
973
+#define ID_IP1811_SET_COS_PHYSICALPORT \
974
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_PHYSICALPORT)
975
+#define ID_IP1811_GET_COS_PHYSICALPORT \
976
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_PHYSICALPORT)
977
+#define ID_IP1811_SET_COS_PORT_QUEUE \
978
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_PORT_QUEUE)
979
+#define ID_IP1811_GET_COS_PORT_QUEUE \
980
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_PORT_QUEUE)
981
+#define ID_IP1811_SET_COS_8021PEDTION \
982
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_8021PEDTION)
983
+#define ID_IP1811_GET_COS_8021PEDTION \
984
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_8021PEDTION)
985
+#define ID_IP1811_SET_COS_DSCPBASE_DSCP \
986
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_DSCPBASE_DSCP)
987
+#define ID_IP1811_GET_COS_DSCPBASE_DSCP \
988
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_DSCPBASE_DSCP)
989
+#define ID_IP1811_SET_COS_DSCPBASE_NOMATCHACTION \
990
+ ID_IP1811_QOS(IDX_IP1811_SET_COS_DSCPBASE_NOMATCHACTION)
991
+#define ID_IP1811_GET_COS_DSCPBASE_NOMATCHACTION \
992
+ ID_IP1811_QOS(IDX_IP1811_GET_COS_DSCPBASE_NOMATCHACTION)
993
+
994
+#define ID_IP1811_SET_QOSMODE_GROUP_MEMEBER \
995
+ ID_IP1811_QOS(IDX_IP1811_SET_QOSMODE_GROUP_MEMEBER)
996
+#define ID_IP1811_GET_QOSMODE_GROUP_MEMEBER \
997
+ ID_IP1811_QOS(IDX_IP1811_GET_QOSMODE_GROUP_MEMEBER)
998
+#define ID_IP1811_SET_QOSGROUPB_EN \
999
+ ID_IP1811_QOS(IDX_IP1811_SET_QOSGROUPB_EN)
1000
+#define ID_IP1811_GET_QOSGROUPB_EN \
1001
+ ID_IP1811_QOS(IDX_IP1811_GET_QOSGROUPB_EN)
1002
+#define ID_IP1811_SET_QOS_MODE \
1003
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_MODE)
1004
+#define ID_IP1811_GET_QOS_MODE \
1005
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_MODE)
1006
+#define ID_IP1811_SET_QOS_METHOD \
1007
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_METHOD)
1008
+#define ID_IP1811_GET_QOS_METHOD \
1009
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_METHOD)
1010
+#define ID_IP1811_SET_QOS_WEIGHT \
1011
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_WEIGHT)
1012
+#define ID_IP1811_GET_QOS_WEIGHT \
1013
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_WEIGHT)
1014
+#define ID_IP1811_SET_QOS_MAXBANDWIDTH \
1015
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_MAXBANDWIDTH)
1016
+#define ID_IP1811_GET_QOS_MAXBANDWIDTH \
1017
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_MAXBANDWIDTH)
1018
+#define ID_IP1811_SET_QOS_UNIT \
1019
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_UNIT)
1020
+#define ID_IP1811_GET_QOS_UNIT \
1021
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_UNIT)
1022
+#define ID_IP1811_SET_QOS_RATIOVALUE0_DEF \
1023
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_RATIOVALUE0_DEF)
1024
+#define ID_IP1811_GET_QOS_RATIOVALUE0_DEF \
1025
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_RATIOVALUE0_DEF)
1026
+#define ID_IP1811_SET_QOS_SBM_DBM \
1027
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_SBM_DBM)
1028
+#define ID_IP1811_GET_QOS_SBM_DBM \
1029
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_SBM_DBM)
1030
+#define ID_IP1811_SET_QOS_DBM_EN \
1031
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_DBM_EN)
1032
+#define ID_IP1811_GET_QOS_DBM_EN \
1033
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_DBM_EN)
1034
+
1035
+#define ID_IP1811_SET_QOS_REMAP \
1036
+ ID_IP1811_QOS(IDX_IP1811_SET_QOS_REMAP)
1037
+#define ID_IP1811_GET_QOS_REMAP \
1038
+ ID_IP1811_QOS(IDX_IP1811_GET_QOS_REMAP)
1039
+/*===================================================================*/
1040
+#define _CMDID_GRP_ACL 0x04
1041
+/*-------------------------------------------------------------------*/
1042
+#define _CMDID_SUBG_ACL 0x01
1043
+enum{
1044
+ IDX_IP1811_ACL_SET_RULE,
1045
+ IDX_IP1811_ACL_GET_RULE,
1046
+ IDX_IP1811_ACL_CLEAN_TABLE,
1047
+ IDX_IP1811_ACL_SET_FUNCTION_EN,
1048
+ IDX_IP1811_ACL_GET_FUNCTION_EN,
1049
+ IDX_IP1811_ACL_SET_ETHER_AFTER_TAG,
1050
+ IDX_IP1811_ACL_GET_ETHER_AFTER_TAG,
1051
+ IDX_IP1811_ACL_GET_USED_RULES,
1052
+ IDX_IP1811_ACL_GET_USED_ENTRIES,
1053
+ IDX_IP1811_ACL_GET_USED_ENTRY_MASK,
1054
+ IDX_IP1811_ACL_SET_BW,
1055
+ IDX_IP1811_ACL_GET_BW,
1056
+ IDX_IP1811_ACL_SET_DSCP,
1057
+ IDX_IP1811_ACL_GET_DSCP,
1058
+ IDX_IP1811_ACL_SET_VID_REMARK,
1059
+ IDX_IP1811_ACL_GET_VID_REMARK,
1060
+ IDX_IP1811_ACL_SET_STORM_PERIOD,
1061
+ IDX_IP1811_ACL_GET_STORM_PERIOD,
1062
+ IDX_IP1811_ACL_SET_STORM,
1063
+ IDX_IP1811_ACL_GET_STORM,
1064
+ NUM_IP1811_ACL
1065
+};
1066
+#define ID_IP1811_ACL(idx) \
1067
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_ACL, _CMDID_SUBG_ACL, idx)
1068
+#define ID_1811_ACL_SET_RULE \
1069
+ ID_IP1811_ACL(IDX_IP1811_ACL_SET_RULE)
1070
+#define ID_1811_ACL_GET_RULE \
1071
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_RULE)
1072
+#define ID_1811_ACL_CLEAN_TABLE \
1073
+ ID_IP1811_ACL(IDX_IP1811_ACL_CLEAN_TABLE)
1074
+#define ID_1811_ACL_SET_FUNCTION_EN \
1075
+ ID_IP1811_ACL(IDX_IP1811_ACL_SET_FUNCTION_EN)
1076
+#define ID_1811_ACL_GET_FUNCTION_EN \
1077
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_FUNCTION_EN)
1078
+#define ID_1811_ACL_SET_ETHER_AFTER_TAG \
1079
+ ID_IP1811_ACL(IDX_IP1811_ACL_SET_ETHER_AFTER_TAG)
1080
+#define ID_1811_ACL_GET_ETHER_AFTER_TAG \
1081
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_ETHER_AFTER_TAG)
1082
+#define ID_1811_ACL_GET_USED_RULES \
1083
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_USED_RULES)
1084
+#define ID_1811_ACL_GET_USED_ENTRIES \
1085
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_USED_ENTRIES)
1086
+#define ID_1811_ACL_GET_USED_ENTRY_MASK \
1087
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_USED_ENTRY_MASK)
1088
+#define ID_1811_ACL_SET_BW \
1089
+ ID_IP1811_ACL(IDX_IP1811_ACL_SET_BW)
1090
+#define ID_1811_ACL_GET_BW \
1091
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_BW)
1092
+#define ID_1811_ACL_SET_DSCP \
1093
+ ID_IP1811_ACL(IDX_IP1811_ACL_SET_DSCP)
1094
+#define ID_1811_ACL_GET_DSCP \
1095
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_DSCP)
1096
+#define ID_1811_ACL_SET_VID_REMARK \
1097
+ ID_IP1811_ACL(IDX_IP1811_ACL_SET_VID_REMARK)
1098
+#define ID_1811_ACL_GET_VID_REMARK \
1099
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_VID_REMARK)
1100
+#define ID_1811_ACL_SET_STORM_PERIOD \
1101
+ ID_IP1811_ACL(IDX_IP1811_ACL_SET_STORM_PERIOD)
1102
+#define ID_1811_ACL_GET_STORM_PERIOD \
1103
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_STORM_PERIOD)
1104
+#define ID_1811_ACL_SET_STORM \
1105
+ ID_IP1811_ACL(IDX_IP1811_ACL_SET_STORM)
1106
+#define ID_1811_ACL_GET_STORM \
1107
+ ID_IP1811_ACL(IDX_IP1811_ACL_GET_STORM)
1108
+
1109
+/*===================================================================*/
1110
+#define _CMDID_GRP_SEC 0x05
1111
+/*-------------------------------------------------------------------*/
1112
+#define _CMDID_SUBG_IMP 0x01
1113
+#define ID_COMMON_SET_IMP_MODE \
1114
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_SEC, _CMDID_SUBG_IMP, 0)
1115
+
1116
+/*-------------------------------------------------------------------*/
1117
+#define _CMDID_SUBG_COS 0x2
1118
+enum{
1119
+ IDX_COMMON_TCPUDP_SET_USER_DEFINE,
1120
+ IDX_COMMON_TCPUDP_GET_USER_DEFINE,
1121
+ IDX_COMMON_TCPUDP_SET_QUEUE,
1122
+ IDX_COMMON_TCPUDP_GET_QUEUE,
1123
+ IDX_COMMON_TCPUDP_SET_ENABLE,
1124
+ IDX_COMMON_TCPUDP_GET_ENABLE,
1125
+ IDX_COMMON_TCPUDP_SET_TCP_ENABLE,
1126
+ IDX_COMMON_TCPUDP_GET_TCP_ENABLE,
1127
+ IDX_COMMON_TCPUDP_SET_UDP_ENABLE,
1128
+ IDX_COMMON_TCPUDP_GET_UDP_ENABLE,
1129
+ IDX_COMMON_TCPFLAG_SET_DROP_NULL,
1130
+ IDX_COMMON_TCPFLAG_GET_DROP_NULL,
1131
+ IDX_COMMON_TCPFLAG_SET_DROP_ALLSET,
1132
+ IDX_COMMON_TCPFLAG_GET_DROP_ALLSET,
1133
+ IDX_COMMON_TCPFLAG_SET_FLAG,
1134
+ IDX_COMMON_TCPFLAG_GET_FLAG,
1135
+ IDX_COMMON_TCPFLAG_SET_ACTION,
1136
+ IDX_COMMON_TCPFLAG_GET_ACTION,
1137
+ IDX_COMMON_TCPFLAG_SET_PORT,
1138
+ IDX_COMMON_TCPFLAG_GET_PORT,
1139
+ NUM_COMMON_TCPUDP
1140
+};
1141
+#define ID_COMMON_COS(idx) \
1142
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_SEC, _CMDID_SUBG_COS, idx)
1143
+
1144
+#define ID_COMMON_TCPUDP_SET_USER_DEFINE \
1145
+ ID_COMMON_COS(IDX_COMMON_TCPUDP_SET_USER_DEFINE)
1146
+#define ID_COMMON_TCPUDP_GET_USER_DEFINE \
1147
+ ID_COMMON_COS(IDX_COMMON_TCPUDP_GET_USER_DEFINE)
1148
+#define ID_COMMON_TCPUDP_SET_QUEUE \
1149
+ ID_COMMON_COS(IDX_COMMON_TCPUDP_SET_QUEUE)
1150
+#define ID_COMMON_TCPUDP_GET_QUEUE \
1151
+ ID_COMMON_COS(IDX_COMMON_TCPUDP_GET_QUEUE)
1152
+#define ID_COMMON_TCPUDP_SET_ENABLE \
1153
+ ID_COMMON_COS(IDX_COMMON_TCPUDP_SET_ENABLE)
1154
+#define ID_COMMON_TCPUDP_GET_ENABLE \
1155
+ ID_COMMON_COS(IDX_COMMON_TCPUDP_GET_ENABLE)
1156
+#define ID_COMMON_TCPUDP_SET_TCP_ENABLE \
1157
+ ID_COMMON_COS(IDX_COMMON_TCPUDP_SET_TCP_ENABLE)
1158
+#define ID_COMMON_TCPUDP_GET_TCP_ENABLE \
1159
+ ID_COMMON_COS(IDX_COMMON_TCPUDP_GET_TCP_ENABLE)
1160
+#define ID_COMMON_TCPUDP_SET_UDP_ENABLE \
1161
+ ID_COMMON_COS(IDX_COMMON_TCPUDP_SET_UDP_ENABLE)
1162
+#define ID_COMMON_TCPUDP_GET_UDP_ENABLE \
1163
+ ID_COMMON_COS(IDX_COMMON_TCPUDP_GET_UDP_ENABLE)
1164
+#define ID_COMMON_TCPFLAG_SET_DROP_NULL \
1165
+ ID_COMMON_COS(IDX_COMMON_TCPFLAG_SET_DROP_NULL)
1166
+#define ID_COMMON_TCPFLAG_GET_DROP_NULL \
1167
+ ID_COMMON_COS(IDX_COMMON_TCPFLAG_GET_DROP_NULL)
1168
+#define ID_COMMON_TCPFLAG_SET_DROP_ALLSET \
1169
+ ID_COMMON_COS(IDX_COMMON_TCPFLAG_SET_DROP_ALLSET)
1170
+#define ID_COMMON_TCPFLAG_GET_DROP_ALLSET \
1171
+ ID_COMMON_COS(IDX_COMMON_TCPFLAG_GET_DROP_ALLSET)
1172
+#define ID_COMMON_TCPFLAG_SET_FLAG \
1173
+ ID_COMMON_COS(IDX_COMMON_TCPFLAG_SET_FLAG)
1174
+#define ID_COMMON_TCPFLAG_GET_FLAG \
1175
+ ID_COMMON_COS(IDX_COMMON_TCPFLAG_GET_FLAG)
1176
+#define ID_COMMON_TCPFLAG_SET_ACTION \
1177
+ ID_COMMON_COS(IDX_COMMON_TCPFLAG_SET_ACTION)
1178
+#define ID_COMMON_TCPFLAG_GET_ACTION \
1179
+ ID_COMMON_COS(IDX_COMMON_TCPFLAG_GET_ACTION)
1180
+#define ID_COMMON_TCPFLAG_SET_PORT \
1181
+ ID_COMMON_COS(IDX_COMMON_TCPFLAG_SET_PORT)
1182
+#define ID_COMMON_TCPFLAG_GET_PORT \
1183
+ ID_COMMON_COS(IDX_COMMON_TCPFLAG_GET_PORT)
1184
+
1185
+/*===================================================================*/
1186
+#define _CMDID_GRP_ADV 0x06
1187
+/*-------------------------------------------------------------------*/
1188
+#define _CMDID_SUBG_STP 0x1
1189
+enum{
1190
+ IDX_COMMON_MSTP_SET_FUNC,
1191
+ IDX_COMMON_MSTP_GET_FUNC,
1192
+ NUM_COMMON_STP
1193
+};
1194
+#define ID_COMMON_STP(idx) \
1195
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_ADV, _CMDID_SUBG_STP, idx)
1196
+
1197
+#define ID_COMMON_MSTP_SET_FUNC \
1198
+ ID_COMMON_STP(IDX_COMMON_MSTP_SET_FUNC)
1199
+#define ID_COMMON_MSTP_GET_FUNC \
1200
+ ID_COMMON_STP(IDX_COMMON_MSTP_GET_FUNC)
1201
+
1202
+enum{
1203
+ IDX_1811_BPDU_SET_CAP_MODE,
1204
+ IDX_1811_BPDU_GET_CAP_MODE,
1205
+ IDX_1811_BPDU_SET_PORT_ACT,
1206
+ IDX_1811_BPDU_GET_PORT_ACT,
1207
+ IDX_1811_STP_SET_PORT_STATE,
1208
+ IDX_1811_STP_GET_PORT_STATE,
1209
+ NUM_1811_STP
1210
+};
1211
+#define ID_1811_STP(idx) \
1212
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_ADV, _CMDID_SUBG_STP, idx)
1213
+
1214
+#define ID_1811_BPDU_SET_CAP_MODE \
1215
+ ID_1811_STP(IDX_1811_BPDU_SET_CAP_MODE)
1216
+#define ID_1811_BPDU_GET_CAP_MODE \
1217
+ ID_1811_STP(IDX_1811_BPDU_GET_CAP_MODE)
1218
+#define ID_1811_BPDU_SET_PORT_ACT \
1219
+ ID_1811_STP(IDX_1811_BPDU_SET_PORT_ACT)
1220
+#define ID_1811_BPDU_GET_PORT_ACT \
1221
+ ID_1811_STP(IDX_1811_BPDU_GET_PORT_ACT)
1222
+#define ID_1811_STP_SET_PORT_STATE \
1223
+ ID_1811_STP(IDX_1811_STP_SET_PORT_STATE)
1224
+#define ID_1811_STP_GET_PORT_STATE \
1225
+ ID_1811_STP(IDX_1811_STP_GET_PORT_STATE)
1226
+
1227
+
1228
+/*-------------------------------------------------------------------*/
1229
+#define _CMDID_SUBG_LACP 0x2
1230
+enum{
1231
+ IDX_COMMON_TRUNK_SET_HASH_METHOD,
1232
+ IDX_COMMON_TRUNK_GET_HASH_METHOD,
1233
+ IDX_COMMON_TRUNK_SET_MEMBER,
1234
+ IDX_COMMON_TRUNK_GET_MEMBER,
1235
+ IDX_COMMON_CPU_SET_NOT_CARE_TRUNK_AND_VLAN,
1236
+ IDX_COMMON_CPU_GET_NOT_CARE_TRUNK_AND_VLAN,
1237
+ NUM_COMMON_LACP
1238
+};
1239
+#define ID_COMMON_LACP(idx) \
1240
+ MAKECMDID(_CMDID_USG_COMMON, _CMDID_GRP_ADV, _CMDID_SUBG_LACP, idx)
1241
+
1242
+#define ID_COMMON_TRUNK_SET_HASH_METHOD \
1243
+ ID_COMMON_LACP(IDX_COMMON_TRUNK_SET_HASH_METHOD)
1244
+#define ID_COMMON_TRUNK_GET_HASH_METHOD \
1245
+ ID_COMMON_LACP(IDX_COMMON_TRUNK_GET_HASH_METHOD)
1246
+#define ID_COMMON_TRUNK_SET_MEMBER \
1247
+ ID_COMMON_LACP(IDX_COMMON_TRUNK_SET_MEMBER)
1248
+#define ID_COMMON_TRUNK_GET_MEMBER \
1249
+ ID_COMMON_LACP(IDX_COMMON_TRUNK_GET_MEMBER)
1250
+#define ID_COMMON_CPU_SET_NOT_CARE_TRUNK_AND_VLAN \
1251
+ ID_COMMON_LACP(IDX_COMMON_CPU_SET_NOT_CARE_TRUNK_AND_VLAN)
1252
+#define ID_COMMON_CPU_GET_NOT_CARE_TRUNK_AND_VLAN \
1253
+ ID_COMMON_LACP(IDX_COMMON_CPU_GET_NOT_CARE_TRUNK_AND_VLAN)
1254
+
1255
+enum{
1256
+ IPX_1811_TRUNK_SET_HASH_METHOD_SEQ,
1257
+ IPX_1811_TRUNK_GET_HASH_METHOD_SEQ,
1258
+ IPX_1811_TRUNK_SET_GROUP_COMBINE,
1259
+ IPX_1811_TRUNK_GET_GROUP_COMBINE,
1260
+ NUM_1811_LACP
1261
+};
1262
+#define ID_1811_LACP(idx) \
1263
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_ADV, _CMDID_SUBG_LACP, idx)
1264
+
1265
+#define IP_1811_TRUNK_SET_HASH_METHOD_SEQ \
1266
+ ID_1811_LACP(IPX_1811_TRUNK_SET_HASH_METHOD_SEQ)
1267
+#define IP_1811_TRUNK_GET_HASH_METHOD_SEQ \
1268
+ ID_1811_LACP(IPX_1811_TRUNK_GET_HASH_METHOD_SEQ)
1269
+#define IP_1811_TRUNK_SET_GROUP_COMBINE \
1270
+ ID_1811_LACP(IPX_1811_TRUNK_SET_GROUP_COMBINE)
1271
+#define IP_1811_TRUNK_GET_GROUP_COMBINE \
1272
+ ID_1811_LACP(IPX_1811_TRUNK_GET_GROUP_COMBINE)
1273
+
1274
+/*===================================================================*/
1275
+#define _CMDID_GRP_MON 0x07
1276
+/*-------------------------------------------------------------------*/
1277
+#define _CMDID_SUBG_MIB_COUNTER 0x1
1278
+enum{
1279
+ IDX_1811_SET_MIB_COUNTER_ENABLE,
1280
+ IDX_1811_GET_MIB_COUNTER_ENABLE,
1281
+ IDX_1811_GET_MIB_COUNTER_ALL,
1282
+ IDX_1811_GET_MIB_COUNTER_BY_PORT,
1283
+ IDX_1811_GET_MIB_COUNTER_BY_ITEM,
1284
+ NUM_1811_MIB_COUNTER
1285
+};
1286
+#define ID_COMMON_MIB_COUNTER(idx) \
1287
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_MON, _CMDID_SUBG_MIB_COUNTER, idx)
1288
+
1289
+#define ID_1811_SET_MIB_COUNTER_ENABLE \
1290
+ ID_COMMON_MIB_COUNTER(IDX_1811_SET_MIB_COUNTER_ENABLE)
1291
+#define ID_1811_GET_MIB_COUNTER_ENABLE \
1292
+ ID_COMMON_MIB_COUNTER(IDX_1811_GET_MIB_COUNTER_ENABLE)
1293
+#define ID_1811_GET_MIB_COUNTER_ALL \
1294
+ ID_COMMON_MIB_COUNTER(IDX_1811_GET_MIB_COUNTER_ALL)
1295
+#define ID_1811_GET_MIB_COUNTER_BY_PORT \
1296
+ ID_COMMON_MIB_COUNTER(IDX_1811_GET_MIB_COUNTER_BY_PORT)
1297
+#define ID_1811_GET_MIB_COUNTER_BY_ITEM \
1298
+ ID_COMMON_MIB_COUNTER(IDX_1811_GET_MIB_COUNTER_BY_ITEM)
1299
+
1300
+/*===================================================================*/
1301
+#define _CMDID_GRP_HSR 0x08
1302
+/*-------------------------------------------------------------------*/
1303
+#define _CMDID_SUBG_HSR 0x1
1304
+enum{
1305
+ IDX_1811_SET_HSR_ENABLE,
1306
+ IDX_1811_GET_HSR_ENABLE,
1307
+ IDX_1811_SET_HSR_MODE,
1308
+ IDX_1811_GET_HSR_MODE,
1309
+ NUM_IP1811_HSR
1310
+};
1311
+#define ID_COMMON_HSR(idx) \
1312
+ MAKECMDID(_CMDID_USG_IP1811, _CMDID_GRP_HSR, _CMDID_SUBG_HSR, idx)
1313
+
1314
+#define ID_1811_SET_HSR_ENABLE \
1315
+ ID_COMMON_HSR(IDX_1811_SET_HSR_ENABLE)
1316
+#define ID_1811_GET_HSR_ENABLE \
1317
+ ID_COMMON_HSR(IDX_1811_GET_HSR_ENABLE)
1318
+#define ID_1811_SET_HSR_MODE \
1319
+ ID_COMMON_HSR(IDX_1811_SET_HSR_MODE)
1320
+#define ID_1811_GET_HSR_MODE \
1321
+ ID_COMMON_HSR(IDX_1811_GET_HSR_MODE)
1322
+
1323
+#endif /* IP1811_H */
kernel/drivers/net/ethernet/ip1811/ip1811ds.h
....@@ -0,0 +1,746 @@
1
+#ifndef IP1811DS_H
2
+#define IP1811DS_H
3
+
4
+#include "ip1811.h"
5
+#include "include/list.h"
6
+
7
+/*typedef unsigned char u8;
8
+typedef unsigned short u16;
9
+typedef unsigned long u32;*/
10
+
11
+struct GeneralSetting
12
+{
13
+ void *nextcmd;
14
+ unsigned long size_nextcmd;
15
+ unsigned long cmdid;
16
+ int gdata;
17
+};
18
+
19
+struct PortMemberSetting
20
+{
21
+ void *nextcmd;
22
+ unsigned long size_nextcmd;
23
+ unsigned long cmdid;
24
+ unsigned long member;
25
+};
26
+
27
+struct ByPortSetting
28
+{
29
+ void *nextcmd;
30
+ unsigned long size_nextcmd;
31
+ unsigned long cmdid;
32
+ int port;
33
+ int pdata;
34
+};
35
+
36
+struct ByPortSetting32
37
+{
38
+ void *nextcmd;
39
+ unsigned long size_nextcmd;
40
+ unsigned long cmdid;
41
+ int port;
42
+ unsigned long pdata;
43
+};
44
+
45
+struct AllPortsSetting
46
+{
47
+ void *nextcmd;
48
+ unsigned long size_nextcmd;
49
+ unsigned long cmdid;
50
+ int apdata[MAX_PHY_NUM];
51
+};
52
+
53
+struct PortmapSetting
54
+{
55
+ void *nextcmd;
56
+ unsigned long size_nextcmd;
57
+ unsigned long cmdid;
58
+ unsigned long portmap;
59
+ int pmdata;
60
+};
61
+
62
+struct PortMaskSetting
63
+{
64
+ void *nextcmd;
65
+ unsigned long size_nextcmd;
66
+ unsigned long cmdid;
67
+ unsigned long portmap;
68
+ int mask;
69
+};
70
+
71
+/*--------------- Special Data Structures for PTP ---------------*/
72
+struct PTPReadSetting{
73
+ void *nextcmd;
74
+ unsigned long size_nextcmd;
75
+ unsigned long cmdid;
76
+ unsigned char addr; //0-15
77
+ char in_out; //1:egress, 0:ingress
78
+ int port; //1-12
79
+ unsigned long long second;
80
+ unsigned long nanosecond;
81
+};
82
+
83
+struct PTPPortTSSetting{
84
+ void *nextcmd;
85
+ unsigned long size_nextcmd;
86
+ unsigned long cmdid;
87
+ unsigned long portmap;
88
+ char in_out; //1:egress, 0:ingress
89
+ char pmdata; //set:OP_FUNC_ENABLE/DISABLE
90
+ //get:always enable
91
+};
92
+
93
+struct PTPTimeSetting{
94
+ void *nextcmd;
95
+ unsigned long size_nextcmd;
96
+ unsigned long cmdid;
97
+ unsigned long long second;
98
+ unsigned long nanosecond;
99
+};
100
+
101
+struct PTPFrequencySetting{
102
+ void *nextcmd;
103
+ unsigned long size_nextcmd;
104
+ unsigned long cmdid;
105
+ char type; //1:add 0:sub
106
+ unsigned long frequency;
107
+ unsigned long clockcycle;
108
+ unsigned long period_time; //nanosecond
109
+};
110
+
111
+struct PTPFrequencyPPMSetting{
112
+ void *nextcmd;
113
+ unsigned long size_nextcmd;
114
+ unsigned long cmdid;
115
+ char type; //1:add 0:sub
116
+ unsigned long ppm_h;
117
+ unsigned long ppm_l;
118
+};
119
+/*--------------- Special Data Structures for SMI ---------------*/
120
+struct LinkStatusSetting
121
+{
122
+ void *nextcmd;
123
+ unsigned long size_nextcmd;
124
+ unsigned long cmdid;
125
+ int port;
126
+ unsigned int link;
127
+ unsigned int speed;
128
+ unsigned int duplex;
129
+ unsigned int pause;
130
+ unsigned int asym;
131
+ unsigned int an;
132
+ unsigned int fiber;
133
+};
134
+
135
+/*--------------- Special Data Structures for L2 Protocol ---------------*/
136
+struct CapActSetting
137
+{
138
+ void *nextcmd;
139
+ unsigned long size_nextcmd;
140
+ unsigned long cmdid;
141
+ unsigned int protocol;
142
+ int act;
143
+};
144
+
145
+/*--------------- Special Data Structures for Storm ---------------*/
146
+struct StormGeneralSetting
147
+{
148
+ void *nextcmd;
149
+ unsigned long size_nextcmd;
150
+ unsigned long cmdid;
151
+ unsigned char storm;
152
+ long sdata;
153
+};
154
+
155
+/*--------------- Special Data Structures for Loop Detect ---------------*/
156
+struct LDDASetting
157
+{
158
+ void *nextcmd;
159
+ unsigned long size_nextcmd;
160
+ unsigned long cmdid;
161
+ unsigned char da[6];
162
+};
163
+
164
+/*--------------- Special Data Structures for Special Tag ---------------*/
165
+struct STagTypeLenSetting
166
+{
167
+ void *nextcmd;
168
+ unsigned long size_nextcmd;
169
+ unsigned long cmdid;
170
+ unsigned int length;
171
+ unsigned int type;
172
+};
173
+
174
+/*--------------- Special Data Structures for MISC ---------------*/
175
+struct RegSetting
176
+{
177
+ void *nextcmd;
178
+ unsigned long size_nextcmd;
179
+ unsigned long cmdid;
180
+ unsigned char page;
181
+ unsigned char reg;
182
+ unsigned short val;
183
+};
184
+/*--------------- Special Data Structures for MISC PHY ---------------*/
185
+struct PhySetting
186
+{
187
+ void *nextcmd;
188
+ unsigned long size_nextcmd;
189
+ unsigned long cmdid;
190
+ unsigned char phy;
191
+ unsigned char page;
192
+ unsigned char reg;
193
+ unsigned short val;
194
+ unsigned char all;
195
+};
196
+
197
+/*--------------- Special Data Structures for STP ---------------*/
198
+struct StpByFPSetting
199
+{
200
+ void *nextcmd;
201
+ unsigned long size_nextcmd;
202
+ unsigned long cmdid;
203
+ int fid;
204
+ int port;
205
+ int pstate;
206
+};
207
+
208
+struct StpAllPortsSetting
209
+{
210
+ void *nextcmd;
211
+ unsigned long size_nextcmd;
212
+ unsigned long cmdid;
213
+ int fid;
214
+ int pstate[MAX_PHY_NUM-1];
215
+};
216
+
217
+/*--------------- Special Data Structures for LACP ---------------*/
218
+struct TrunkMemberSetting
219
+{
220
+ void *nextcmd;
221
+ unsigned long size_nextcmd;
222
+ unsigned long cmdid;
223
+ unsigned long portmask;
224
+ unsigned long tstate;
225
+};
226
+
227
+struct TrunkCombineSetting
228
+{
229
+ void *nextcmd;
230
+ unsigned long size_nextcmd;
231
+ unsigned long cmdid;
232
+ unsigned long tgrps;
233
+ int cen;
234
+};
235
+
236
+/*--------------- Special Data Structures for LUT ---------------*/
237
+struct IP1811LUTEntry
238
+{
239
+ unsigned char cfg;
240
+ unsigned char mac[6];
241
+ unsigned char fid;
242
+ unsigned char srcport;
243
+ unsigned char aging;
244
+ unsigned char priority;
245
+ struct{
246
+ unsigned short drop: 1;
247
+ unsigned short snif: 1;
248
+ unsigned short sflow: 1;
249
+ unsigned short reserve: 13;
250
+ }flag;
251
+};
252
+
253
+struct IP1811LUTSetting
254
+{
255
+ void *nextcmd;
256
+ unsigned long size_nextcmd;
257
+ unsigned long cmdid;
258
+ unsigned long retval;
259
+ unsigned char action;
260
+ unsigned long tarports;
261
+ unsigned short index;
262
+ unsigned char block;
263
+ struct IP1811LUTEntry entry;
264
+ unsigned short data[6];
265
+};
266
+
267
+struct IP1811LUTReg
268
+{
269
+ unsigned short data[6];
270
+ unsigned char block;
271
+ struct list_head list;
272
+};
273
+
274
+/*--------------- Special Data Structures for IGMP ---------------*/
275
+
276
+struct mt_rule{
277
+ unsigned char group[4];
278
+ unsigned char fid;
279
+ unsigned long port_mem;
280
+ unsigned char pri;
281
+ unsigned char slt_index;
282
+ unsigned char flag;
283
+};
284
+
285
+struct MtRuleSetting{
286
+ void *nextcmd;
287
+ unsigned long size_nextcmd;
288
+ unsigned long cmdid;
289
+ int index;
290
+ struct mt_rule mt_data;
291
+};
292
+
293
+struct slt_rule{
294
+ unsigned char type; //4:ipv4, 6:ipv6, define in ip1811op.h
295
+ union slt_para{
296
+ struct slt_ipv4{
297
+ unsigned char ip[6][4];
298
+ unsigned int used_port[6];
299
+ }ipv4;
300
+
301
+ struct slt_ipv6{
302
+ unsigned short ip[2][8];
303
+ unsigned int used_port[2];
304
+ }ipv6;
305
+ }data;
306
+ unsigned int port_filter_mode;
307
+};
308
+
309
+struct SltRuleSetting{
310
+ void *nextcmd;
311
+ unsigned long size_nextcmd;
312
+ unsigned long cmdid;
313
+ int index;
314
+ struct slt_rule slt_data;
315
+};
316
+
317
+struct IgmpPacketRule{
318
+ void *nextcmd;
319
+ unsigned long size_nextcmd;
320
+ unsigned long cmdid;
321
+ unsigned int packet_type;
322
+ unsigned int rule;
323
+};
324
+
325
+struct IgmpRouterListSetting{
326
+ void *nextcmd;
327
+ unsigned long size_nextcmd;
328
+ unsigned long cmdid;
329
+ unsigned int portmask;
330
+ unsigned int tstate;
331
+};
332
+
333
+/*--------------- Special Data Structures for IMP ---------------*/
334
+struct IP1811IMPEntry
335
+{
336
+ unsigned char ip[16];
337
+ unsigned char mac[6];
338
+ unsigned char srcport;
339
+ unsigned char priority;
340
+ struct{
341
+ unsigned int valid: 1;
342
+ unsigned int ip_type: 1;
343
+ unsigned int check_ip: 1;
344
+ unsigned int check_mac: 1;
345
+ unsigned int check_port: 1;
346
+ unsigned int filter: 1;
347
+ unsigned int sniff2: 1;
348
+ unsigned int reserved: 9;
349
+ }flag;
350
+};
351
+
352
+struct IP1811IMPSetting
353
+{
354
+ void *nextcmd;
355
+ unsigned long size_nextcmd;
356
+ unsigned long cmdid;
357
+ unsigned long retval;
358
+ unsigned char action;
359
+ unsigned char index;
360
+ struct IP1811IMPEntry entry;
361
+};
362
+
363
+/*--------------- Special Data Structures for VLAN ---------------*/
364
+struct VlanSetting{
365
+ void *nextcmd;
366
+ unsigned long size_nextcmd;
367
+ unsigned long cmdid;
368
+ unsigned int vtype;
369
+ unsigned int vdata;
370
+};
371
+
372
+struct MACVlanSetting{
373
+ void *nextcmd;
374
+ unsigned long size_nextcmd;
375
+ unsigned long cmdid;
376
+ unsigned int index;
377
+ unsigned int mvdata;
378
+};
379
+
380
+/*--------------- Special Data Structures for MAC ---------------*/
381
+struct MACSetting{
382
+ void *nextcmd;
383
+ unsigned long size_nextcmd;
384
+ unsigned long cmdid;
385
+ char mac[6];
386
+};
387
+
388
+/*--------------- Special Data Structures for TCP Flag ---------------*/
389
+struct TcpFlagSetting{
390
+ void *nextcmd;
391
+ unsigned long size_nextcmd;
392
+ unsigned long cmdid;
393
+ unsigned int index;
394
+ int fdata;
395
+};
396
+
397
+/*--------------- Special Data Structures for IPv6 ---------------*/
398
+struct IPv6Setting{
399
+ void *nextcmd;
400
+ unsigned long size_nextcmd;
401
+ unsigned long cmdid;
402
+ unsigned int header;
403
+ int act;
404
+};
405
+
406
+/*--------------- Special Data Structures for MIB Counter ---------------*/
407
+#define NUM_MIB_COUNTER_RX 24
408
+#define NUM_MIB_COUNTER_TX 20
409
+
410
+struct MIBCounterData{
411
+ void *nextcmd;
412
+ unsigned long size_nextcmd;
413
+ unsigned long cmdid;
414
+ int port;
415
+ int dir;
416
+ int idx;
417
+ unsigned long counter;
418
+};
419
+
420
+struct MIBCounterEntry{
421
+ unsigned long RX_counter[NUM_MIB_COUNTER_RX];
422
+ unsigned long TX_counter[NUM_MIB_COUNTER_TX];
423
+};
424
+
425
+struct MIBCounterEntry_all{
426
+ struct MIBCounterEntry entry[MAX_PHY_NUM];
427
+};
428
+
429
+/*--------------- Special Data Structures for QOS ---------------*/
430
+struct qos_dscp_setting
431
+{
432
+ void *nextcmd;
433
+ unsigned long size_nextcmd;
434
+ unsigned long cmdid;
435
+ unsigned char dscpentry;
436
+ unsigned char dscpvalue;
437
+ unsigned char dscpqueue;
438
+};
439
+
440
+struct qos_modesettings
441
+{
442
+ void *nextcmd;
443
+ unsigned long size_nextcmd;
444
+ unsigned long cmdid;
445
+ int groupnum;
446
+ int queuenum;
447
+ int modesettings;
448
+};
449
+
450
+struct qos_remap
451
+{
452
+ void *nextcmd;
453
+ unsigned long size_nextcmd;
454
+ unsigned long cmdid;
455
+ int port;
456
+ unsigned char queue;
457
+ unsigned char remap;
458
+};
459
+/*--------------- Special Data Structures for ACL ---------------*/
460
+struct acl_man {
461
+ struct list_head rule_list;
462
+
463
+ int num_used_rules;
464
+ int num_used_entries;
465
+
466
+ // IP1811 has 64 entries
467
+ unsigned short used_entry_mask[4];
468
+};
469
+
470
+#define ACL_RULE_FUNC_USED_ACL BIT(0)
471
+#define ACL_RULE_FUNC_USED_MCP BIT(1)
472
+#define ACL_RULE_FUNC_USED_SNOOP BIT(2)
473
+#define ACL_RULE_FUNC_USED_DOS BIT(3)
474
+
475
+struct acl_man_rule {
476
+ struct list_head rule_entry;
477
+ int start_block;
478
+ int start_index;
479
+ int num_entries;
480
+ int rule_index;
481
+ unsigned int func_used; // bit 0 : acl
482
+ // bit 1 : mcp
483
+ // bit 2 : dhcp snooping
484
+};
485
+
486
+enum {
487
+ ACL_SELECT_MODE_0001 = 1,
488
+ ACL_SELECT_MODE_0010,
489
+ ACL_SELECT_MODE_0100 = 4,
490
+ ACL_SELECT_MODE_0101,
491
+ ACL_SELECT_MODE_0110,
492
+ ACL_SELECT_MODE_0111,
493
+ ACL_SELECT_MODE_1x00,
494
+ ACL_SELECT_MODE_1x01,
495
+ ACL_SELECT_MODE_1x10,
496
+ ACL_SELECT_MODE_1x11,
497
+};
498
+#define ACL_SELECT_MODE_BIT_0010 BIT(ACL_SELECT_MODE_0010)
499
+#define ACL_SELECT_MODE_BIT_0100 BIT(ACL_SELECT_MODE_0100)
500
+#define ACL_SELECT_MODE_BIT_0101 BIT(ACL_SELECT_MODE_0101)
501
+#define ACL_SELECT_MODE_BIT_0110 BIT(ACL_SELECT_MODE_0110)
502
+#define ACL_SELECT_MODE_BIT_0111 BIT(ACL_SELECT_MODE_0111)
503
+#define ACL_SELECT_MODE_BIT_1x00 BIT(ACL_SELECT_MODE_1x00)
504
+#define ACL_SELECT_MODE_BIT_1x01 BIT(ACL_SELECT_MODE_1x01)
505
+#define ACL_SELECT_MODE_BIT_1x10 BIT(ACL_SELECT_MODE_1x10)
506
+#define ACL_SELECT_MODE_BIT_1x11 BIT(ACL_SELECT_MODE_1x11)
507
+enum {
508
+ ACL_LINK_TYPE_00 = 0,
509
+ ACL_LINK_TYPE_01,
510
+ ACL_LINK_TYPE_10,
511
+ ACL_LINK_TYPE_11,
512
+};
513
+
514
+#define ACL_RULE_VALID_SMAC BIT(0)
515
+#define ACL_RULE_VALID_DMAC BIT(1)
516
+#define ACL_RULE_VALID_SIP BIT(2)
517
+#define ACL_RULE_VALID_SIP_MASK BIT(3)
518
+#define ACL_RULE_VALID_DIP BIT(4)
519
+#define ACL_RULE_VALID_DIP_MASK BIT(5)
520
+#define ACL_RULE_VALID_SIP6 BIT(6)
521
+#define ACL_RULE_VALID_SIP6_MASK BIT(7)
522
+#define ACL_RULE_VALID_DIP6 BIT(8)
523
+#define ACL_RULE_VALID_DIP6_MASK BIT(9)
524
+#define ACL_RULE_VALID_ETH_TYPE BIT(10)
525
+#define ACL_RULE_VALID_VLAN BIT(11)
526
+#define ACL_RULE_VALID_COS BIT(12)
527
+#define ACL_RULE_VALID_SP_R BIT(13)
528
+#define ACL_RULE_VALID_DP_R BIT(14)
529
+#define ACL_RULE_VALID_DSCP BIT(15)
530
+#define ACL_RULE_VALID_IP_PROT BIT(16)
531
+#define ACL_RULE_VALID_INGRESS_PORT BIT(17)
532
+#define ACL_RULE_VALID_USERDEF_OFFSET BIT(18)
533
+
534
+#define ACL_RULE_RVS_SMAC BIT(0)
535
+#define ACL_RULE_RVS_DMAC BIT(1)
536
+#define ACL_RULE_RVS_SIP BIT(2)
537
+#define ACL_RULE_RVS_SIP_MASK BIT(3)
538
+#define ACL_RULE_RVS_DIP BIT(4)
539
+#define ACL_RULE_RVS_DIP_MASK BIT(5)
540
+#define ACL_RULE_RVS_SIP6 BIT(6)
541
+#define ACL_RULE_RVS_SIP6_MASK BIT(7)
542
+#define ACL_RULE_RVS_DIP6 BIT(8)
543
+#define ACL_RULE_RVS_DIP6_MASK BIT(9)
544
+#define ACL_RULE_RVS_ETH_TYPE BIT(10)
545
+#define ACL_RULE_RVS_VLAN BIT(11)
546
+#define ACL_RULE_RVS_COS BIT(12)
547
+#define ACL_RULE_RVS_SP_R BIT(13)
548
+#define ACL_RULE_RVS_DP_R BIT(14)
549
+#define ACL_RULE_RVS_DSCP BIT(15)
550
+#define ACL_RULE_RVS_IP_PROT BIT(16)
551
+#define ACL_RULE_RVS_INGRESS_PORT BIT(17)
552
+#define ACL_RULE_RVS_USERDEF_OFFSET BIT(18)
553
+
554
+#define ACL_ACT_VALID_REDIR BIT(0)
555
+#define ACL_ACT_VALID_PRI BIT(1)
556
+#define ACL_ACT_VALID_DSCP BIT(2)
557
+#define ACL_ACT_VALID_CPU BIT(3)
558
+#define ACL_ACT_VALID_SNIFFER BIT(4)
559
+#define ACL_ACT_VALID_PTP BIT(5)
560
+#define ACL_ACT_VALID_SFLOW BIT(6)
561
+#define ACL_ACT_VALID_CTAG BIT(7)
562
+#define ACL_ACT_VALID_STAG BIT(8)
563
+#define ACL_ACT_VALID_BW BIT(9)
564
+#define ACL_ACT_VALID_STORM BIT(10)
565
+#define ACL_ACT_VALID_MIB_COUNTER BIT(11)
566
+
567
+#define ACL_ACT_TYPE_3 3
568
+
569
+struct acl_rule
570
+{
571
+ // rule
572
+ unsigned long rule_valid; // bit 0 : smac
573
+ // bit 1 : dmac
574
+ // bit 2 : sip
575
+ // bit 3 : sip_mask
576
+ // bit 4 : dip
577
+ // bit 5 : dip_mask
578
+ // bit 6 : sip6
579
+ // bit 7 : sip6_mask
580
+ // bit 8 : dip6
581
+ // bit 9 : dip6_mask
582
+ // bit 10: eth_type
583
+ // bit 11: vlan
584
+ // bit 12: cos
585
+ // bit 13: sp_range
586
+ // bit 14: dp_range
587
+ // bit 15: dscp
588
+ // bit 16: ip_prot
589
+ // bit 17: ingress_port
590
+ // reverse
591
+ unsigned long rule_rvs; // bit 0 : smac
592
+ // bit 1 : dmac
593
+ // bit 2 : sip
594
+ // bit 3 : sip_mask
595
+ // bit 4 : dip
596
+ // bit 5 : dip_mask
597
+ // bit 6 : sip6
598
+ // bit 7 : sip6_mask
599
+ // bit 8 : dip6
600
+ // bit 9 : dip6_mask
601
+ // bit 10: eth_type
602
+ // bit 11: vlan
603
+ // bit 12: cos
604
+ // bit 13: sp_range
605
+ // bit 14: dp_range
606
+ // bit 15: dscp
607
+ // bit 16: ip_prot
608
+ // bit 17: ingress_port
609
+
610
+ unsigned char smac[6];
611
+ unsigned char dmac[6];
612
+
613
+ union{
614
+ unsigned long sip4;
615
+ unsigned short sip6[8];
616
+ }sip;
617
+#define sip4_addr sip.sip4
618
+#define sip6_addr16 sip.sip6
619
+ unsigned char sip_mask;
620
+ // IPv4 0 - FF:FF:FF:FF IPv6 0 - FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF(0x00)
621
+ // 1 - FF:FF:FF:00 1 - FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:0000:0000(0x3C)
622
+ // 2 - FF:FF:00:00 2 - FFFF:FFFF:FFFF:FFFF:0000:0000:0000:0000(0x3D)
623
+ // 4 - FF:00:00:00 3 - FFFF:FFFF:0000:0000:0000:0000:0000:0000(0x3F)
624
+ // 8 - F0:00:00:00 4 - FFFF:0000:0000:0000:0000:0000:0000:0000(0xFF)
625
+ union{
626
+ unsigned long dip4;
627
+ unsigned short dip6[8];
628
+ }dip;
629
+#define dip4_addr dip.dip4
630
+#define dip6_addr16 dip.dip6
631
+ unsigned char dip_mask;
632
+
633
+ unsigned short eth_type;
634
+ unsigned short vlan;
635
+ unsigned short cos;
636
+ unsigned short sp_hi;
637
+ unsigned short sp_lo;
638
+ unsigned short dp_hi;
639
+ unsigned short dp_lo;
640
+ unsigned char r_dscp;
641
+ unsigned char ip_prot;
642
+ unsigned char ingress_port;
643
+
644
+ // action
645
+ int act_type; // value = 0 ~ 2, type 3 need a acl entry
646
+ // 0 for drop
647
+ // 1 for Act_0 = b'0
648
+ // 2 for Act_1 = b'1
649
+ // 3 for Act_0001
650
+
651
+ unsigned long act_valid; // bit 0 : redir
652
+ // bit 1 : pri
653
+ // bit 2 : dscp
654
+ // bit 3 : cpu
655
+ // bit 4 : mirror
656
+ // bit 5 : ptp
657
+ // bit 6 : sflow
658
+ // bit 7 : ctag
659
+ // bit 8 : stag
660
+ // bit 9 : bw
661
+ // bit 10: storm
662
+ // bit 11: mib_counter
663
+ unsigned int redir:5;
664
+ unsigned int pri:3;
665
+ unsigned int a_dscp:3;
666
+ unsigned int cpu:1;
667
+ unsigned int mirror:1;
668
+ unsigned int ptp:1;
669
+ unsigned int sflow:1;
670
+ unsigned short ctag;
671
+ unsigned short stag;
672
+ unsigned short bw;
673
+ unsigned short storm;
674
+ unsigned short mib_counter;
675
+
676
+ /* User define 64 bytes offset */
677
+ //one bit for 2 bytes offset
678
+ unsigned short location1; //[4:0] user0
679
+ //[9:5] user1
680
+ unsigned short location2; //[4:0] user2
681
+ //[9:5] user3
682
+
683
+ unsigned short usr0;
684
+ unsigned short usr0_start;
685
+ unsigned short usr1;
686
+ unsigned short usr1_start;
687
+ unsigned short usr2;
688
+ unsigned short usr3;
689
+
690
+ unsigned short mask0;
691
+ unsigned short mask1;
692
+ unsigned short mask2;
693
+ unsigned short mask3;
694
+};
695
+
696
+struct AclRuleSetting
697
+{
698
+ void *nextcmd;
699
+ unsigned long size_nextcmd;
700
+ unsigned long cmdid;
701
+ unsigned int find_index_blockn; // find index start from block n and return used block actually.
702
+ unsigned int find_index_rvs; // in block, find index in reverse or not
703
+ unsigned int rule_index;
704
+ unsigned int func_used;
705
+ int rule_index_res;
706
+ struct acl_rule rule;
707
+ unsigned long reserved; // show the used entry numbers for ip1811
708
+};
709
+
710
+struct AclGeneralSetting
711
+{
712
+ void *nextcmd;
713
+ unsigned long size_nextcmd;
714
+ unsigned long cmdid;
715
+ int index;
716
+ int data;
717
+};
718
+
719
+struct AclEntryMaskGetting
720
+{
721
+ void *nextcmd;
722
+ unsigned long size_nextcmd;
723
+ unsigned long cmdid;
724
+ unsigned short mask[4];
725
+};
726
+
727
+struct AclTableCleanSetting
728
+{
729
+ void *nextcmd;
730
+ unsigned long size_nextcmd;
731
+ unsigned long cmdid;
732
+ int rule_idx;
733
+ int func_used;
734
+};
735
+
736
+/*--------------- Special Data Structures for EEPROM ---------------*/
737
+struct EepromSetting
738
+{
739
+ void *nextcmd;
740
+ unsigned long size_nextcmd;
741
+ unsigned long cmdid;
742
+ unsigned short addr;
743
+ unsigned char value;
744
+};
745
+
746
+#endif /* IP1811DS_H */
kernel/drivers/net/ethernet/ip1811/ip1811fdat.c
....@@ -0,0 +1,466 @@
1
+#include "ip1811fdat.h"
2
+
3
+int (*func_of_common_smi[NUM_COMMON_SMI])(void *cdata, int len) =
4
+{
5
+ &setPortAN,
6
+ &getPortAN,
7
+ &setPortSpeed,
8
+ &getPortSpeed,
9
+ &setPortDuplex,
10
+ &getPortDuplex,
11
+ &setPortPause,
12
+ &getPortPause,
13
+ &setPortAsymPause,
14
+ &getPortAsymPause,
15
+ &setPortLinkStatus,
16
+ &getPortLinkStatus,
17
+ &setPortBackpressure,
18
+ &getPortBackpressure,
19
+ &setPortPowerDown,
20
+ &getPortPowerDown,
21
+ &setPortForceLink,
22
+ &getPortForceLink,
23
+ &setPortUniDirection,
24
+ &getPortUniDirection,
25
+};
26
+
27
+int (*func_of_common_cap[NUM_COMMON_CAP])(void *cdata, int len) =
28
+{
29
+ &setL2CapAct,
30
+ &setCapInBand,
31
+ &setCapSwitchMac,
32
+ &setCapIpv6TcpUdpEnable,
33
+};
34
+
35
+int (*func_of_common_lut[NUM_COMMON_LUT])(void *cdata, int len) =
36
+{
37
+ &setSMACLearning,
38
+ &getSMACLearning,
39
+ &setLutPortFlush,
40
+ &setLutAgingTime,
41
+ &getLutAgingTime,
42
+ &setLutAgingTimeEnable,
43
+ &setLutLearningNullSA,
44
+ &setLutHashingAlgorithm,
45
+ &setLutBindingEnable,
46
+ &getLutBindingEnable,
47
+};
48
+
49
+int (*func_of_common_sniffer[NUM_COMMON_SNIFFER])(void *cdata, int len) =
50
+{
51
+ &setSnifferSrc,
52
+ &getSnifferSrc,
53
+ &setSnifferDestGrp1,
54
+ &getSnifferDestGrp1,
55
+ &setS1Method,
56
+ &getS1Method,
57
+};
58
+
59
+int (*func_of_common_storm[NUM_COMMON_STORM])(void *cdata, int len) =
60
+{
61
+ &setStormFunc,
62
+ &getStormFunc,
63
+ &setStormThreshold,
64
+ &getStormThreshold,
65
+ &setStormCntrClrPeriod,
66
+ &getStormCntrClrPeriod,
67
+ &setStormBlockFrm2Cpu,
68
+ &getStormBlockFrm2Cpu,
69
+ &setStormDropInterrupt,
70
+ &getStormDropInterrupt,
71
+};
72
+
73
+int (*func_of_common_eoc[5])(void *cdata, int len) =
74
+{
75
+};
76
+
77
+int (*func_of_common_ld[NUM_COMMON_LOOP_DETECT])(void *cdata, int len) =
78
+{
79
+ &setLdFunc,
80
+ &getLdFunc,
81
+ &setLdTimeUnit,
82
+ &getLdTimeUnit,
83
+ &setLdPktSendTimer,
84
+ &getLdPktSendTimer,
85
+ &setLdBlockReleaseTimer,
86
+ &getLdBlockReleaseTimer,
87
+ &getLdStatus,
88
+};
89
+
90
+int (*func_of_common_wol[12])(void *cdata, int len) =
91
+{
92
+};
93
+
94
+int (*func_of_common_stag[NUM_COMMON_STAG])(void *cdata, int len) =
95
+{
96
+ &setCpuPortLink,
97
+ &setSTagFunc,
98
+ &getSTagTypeLen,
99
+ &configCpuPort,
100
+ &getCpuPort,
101
+};
102
+
103
+int (*func_of_common_misc[NUM_COMMON_MISC])(void *cdata, int len) =
104
+{
105
+ &set8021xFunc,
106
+ &get8021xFunc,
107
+ &setReg,
108
+ &getReg,
109
+ &setCPUReg,
110
+ &getCPUReg,
111
+ &setSwitchRestart,
112
+ &setSwitchReset,
113
+ &setCpuIfSpeed,
114
+ &setEepromByte,
115
+ &getEepromByte,
116
+};
117
+
118
+int (*func_of_common_vlan[NUM_COMMON_VLAN])(void *cdata, int len) =
119
+{
120
+ &setVlanEgressFrame, //0
121
+ &getVlanEgressFrame,
122
+ &setVlanTagging,
123
+ &setVlanType,
124
+
125
+ &setVlanGroup,
126
+
127
+ &setVlanQinQPType, //5
128
+ &setVlanQinQPAddtag,
129
+ &getVlanQinQPAddtag,
130
+ &setVlanQinQPRmvtag,
131
+ &getVlanQinQPRmvtag,
132
+ &setVlanQinQPRxdet, //10
133
+ &getVlanQinQPRxdet,
134
+ &setVlanQinQPKeep,
135
+ &getVlanQinQPKeep,
136
+ &setVlanQinQPIndex,
137
+ &getVlanQinQPIndex, //15
138
+ &setVlanQinQIndex,
139
+ &setVlanQinQStagSelectMethod,
140
+
141
+ &setVlanPortAddtag,
142
+ &getVlanPortAddtag,
143
+ &setVlanPortRmvtag, //20
144
+ &getVlanPortRmvtag,
145
+ &setVlanPortForce,
146
+ &getVlanPortForce,
147
+ &setVlanPortUplink,
148
+ &getVlanPortUplink, //25
149
+ &setVlanPortExclusive,
150
+ &getVlanPortExclusive,
151
+ &setVlanPortEgress,
152
+ &getVlanPortEgress,
153
+ &setVlanPortIngressFrame, //30
154
+ &setVlanPortIngressCheck,
155
+ &getVlanPortIngressCheck,
156
+ &setVlanPortVid,
157
+
158
+ &setVlanProtocolMode,
159
+ &setVlanProtocolVid, //35
160
+ &setVlanProtocolType,
161
+
162
+ &setVlanProtocolClear,
163
+ &setVlanMACBased,
164
+ &setVlanMACBasedtableconfig,
165
+ &getVlanMACBasedtableconfig, //40
166
+ &setVlanMACBasedunknown,
167
+};
168
+
169
+int (*func_of_common_stp[NUM_COMMON_STP])(void *cdata, int len) =
170
+{
171
+ &setMstpFunc,
172
+ &getMstpFunc,
173
+};
174
+
175
+int (*func_of_common_lacp[NUM_COMMON_LACP])(void *cdata, int len) =
176
+{
177
+ &setTrunkHashMthd,
178
+ &getTrunkHashMthd,
179
+ &setTrunkMbr,
180
+ &getTrunkMbr,
181
+ &setCpuNCareTrunkAndVlan,
182
+ &getCpuNCareTrunkAndVlan,
183
+};
184
+
185
+int (*func_of_common_imp[8])(void *cdata, int len) =
186
+{
187
+};
188
+
189
+int (*func_of_common_cos[NUM_COMMON_TCPUDP])(void *cdata, int len) =
190
+{
191
+ &setCosTcpUdpUserDefine,
192
+ &getCosTcpUdpUserDefine,
193
+ &setCosTcpUdpQueue,
194
+ &getCosTcpUdpQueue,
195
+ &setCosTcpUdpEnable,
196
+ &getCosTcpUdpEnable,
197
+ &setCosTcpEnable,
198
+ &getCosTcpEnable,
199
+ &setCosUdpEnable,
200
+ &getCosUdpEnable,
201
+ &setCosTcpFlagDropNull,
202
+ &getCosTcpFlagDropNull,
203
+ &setCosTcpFlagDropAllset,
204
+ &getCosTcpFlagDropAllset,
205
+ &setCosTcpFlag,
206
+ &getCosTcpFlag,
207
+ &setCosTcpFlagAct,
208
+ &getCosTcpFlagAct,
209
+ &setCosTcpFlagPort,
210
+ &getCosTcpFlagPort,
211
+};
212
+
213
+int (*func_of_common_bandwidth[NUM_COMMON_BANDWIDTH])(void *cdata, int len) =
214
+{
215
+ &setBandwidthIngressRate,
216
+ &getBandwidthIngressRate,
217
+ &setBandwidthEgressRate,
218
+ &getBandwidthEgressRate,
219
+ &setBandwidthEgressPeriod,
220
+ &getBandwidthEgressPeriod,
221
+};
222
+/* ---------------- functions of ip1811 ---------------------------*/
223
+int (*func_of_ip1811_lut[NUM_1811_LUT])(void *cdata, int len) =
224
+{
225
+ &setLutUnknownSARule,
226
+ &setLutEntry,
227
+ &getLutEntry,
228
+ &getLutValidEntry,
229
+};
230
+
231
+int (*func_of_ip1811_sniffer[NUM_1811_SNIFFER])(void *cdata, int len) =
232
+{
233
+ &setS1PktModify,
234
+ &getS1PktModify,
235
+ &setS1TM4CpuSTag,
236
+ &getS1TM4CpuSTag,
237
+ &setS1TM4Acl2Cpu,
238
+ &getS1TM4Acl2Cpu,
239
+ &setS1TM4Pkt2MPort,
240
+ &getS1TM4Pkt2MPort,
241
+ &setS2LTT4Grp1,
242
+ &getS2LTT4Grp1,
243
+};
244
+
245
+int (*func_of_ip1811_storm[NUM_1811_STORM])(void *cdata, int len) =
246
+{
247
+ &setMStormNBlockIpPkt,
248
+ &getMStormNBlockIpPkt,
249
+ &setMStormIgnr01005EXXXXXX,
250
+ &getMStormIgnr01005EXXXXXX,
251
+};
252
+
253
+int (*func_of_ip1811_eoc[3])(void *cdata, int len) =
254
+{
255
+};
256
+
257
+int (*func_of_ip1811_ld[NUM_1811_LOOP_DETECT])(void *cdata, int len) =
258
+{
259
+ &setLdDMAC,
260
+ &setLdSubType,
261
+};
262
+
263
+int (*func_of_ip1811_wol[6])(void *cdata, int len) =
264
+{
265
+};
266
+
267
+int (*func_of_ip1811_misc[15])(void *cdata, int len) =
268
+{
269
+};
270
+
271
+int (*func_of_ip1811_stp[NUM_1811_STP])(void *cdata, int len) =
272
+{
273
+ &setBpduCapMode,
274
+ &getBpduCapMode,
275
+ &setBpduPortAct,
276
+ &getBpduPortAct,
277
+ &setStpPortState,
278
+ &getStpPortState,
279
+};
280
+
281
+int (*func_of_ip1811_lacp[NUM_1811_LACP])(void *cdata, int len) =
282
+{
283
+ &setTrunkHashMthdSeq,
284
+ &getTrunkHashMthdSeq,
285
+ &setTrunkGrpCombine,
286
+ &getTrunkGrpCombine,
287
+};
288
+
289
+int (*func_of_ip1811_igmp[NUM_1811_IGMP])(void *cdata, int len) =
290
+{
291
+ &setIGMPSnooping,
292
+ &getIGMPSnooping,
293
+ &setIGMPMctByCPU,
294
+ &getIGMPMctByCPU,
295
+ &setIGMPRltByCPU,
296
+ &getIGMPRltByCPU,
297
+ &setIGMPPktForward,
298
+ &getIGMPPktForward,
299
+ &setIGMPRlt,
300
+ &getIGMPRlt,
301
+ &setIGMPHashMethod,
302
+ &getIGMPHashMethod,
303
+ &setIGMPMldRule,
304
+ &getIGMPMldRule,
305
+ &setIGMPMctTable,
306
+ &getIGMPMctTable,
307
+ &setIGMPSltTable,
308
+ &getIGMPSltTable,
309
+};
310
+
311
+int (*func_of_ip1811_ptp[NUM_1811_PTP])(void *cdata, int len)=
312
+{
313
+ &setPTPEnable,
314
+ &getPTPEnable,
315
+ &setPTPDA011B19000000,
316
+ &getPTPDA011B19000000,
317
+ &setPTPDA0180C200000E,
318
+ &getPTPDA0180C200000E,
319
+ &setPTPUdpDP,
320
+ &getPTPUdpDP,
321
+ &setPTPUdpSP,
322
+ &getPTPUdpSP,
323
+ &setPTPToCPU,
324
+ &getPTPToCPU,
325
+ &setPTPSpecialTag,
326
+ &getPTPSpecialTag,
327
+ &setPTPClockReset,
328
+ &getPTPTimeStamp,
329
+ &setPTPClockEnable,
330
+ &getPTPClockEnable,
331
+ &setPTPOverwriteEnable,
332
+ &getPTPOverwriteEnable,
333
+ &setPTPProgrammable,
334
+ &getPTPProgrammable,
335
+ &setPTPProgrammableOut,
336
+ &setPTPTimestampEnable,
337
+ &getPTPTimestampEnable,
338
+ &setPTPTimestampClear,
339
+ &setPTPTimeData,
340
+ &getPTPTimeData,
341
+ &addPTPTimeData,
342
+ &subPTPTimeData,
343
+ &setPTPFrequencyAdd,
344
+ &getPTPFrequencyAdd,
345
+ &setPTPClockPeriod,
346
+ &getPTPClockPeriod,
347
+ &setPTPProgrammableConfig,
348
+ &setPTPDurationFrequencyCompensation,
349
+ &setPTPAlwaysFrequencyCompensation,
350
+ &getPTPIngressLatency10,
351
+ &getPTPIngressLatency100,
352
+ &getPTPIngressLatencyFiber,
353
+ &getPTPEgressLatency10,
354
+ &getPTPEgressLatency100,
355
+ &getPTPEgressLatencyFiber,
356
+};
357
+
358
+int (*func_of_ip1811_imp[2])(void *cdata, int len) =
359
+{
360
+};
361
+
362
+int (*func_of_ip1811_vlan[NUM_IP1811_VLAN])(void *cdata, int len) =
363
+{
364
+ &setVlanEntryMember,
365
+ &setVlanEntryAddtag,
366
+ &setVlanEntryRmvtag,
367
+ &setVlanEntryPriority,
368
+ &setVlanEntryFid,
369
+ &getVlanEntryFid,
370
+ &setVlanEntryClear,
371
+};
372
+
373
+int (*func_of_ip1811_mib_counter[NUM_1811_MIB_COUNTER])(void *cdata, int len) =
374
+{
375
+ &setMibCounterEnable,
376
+ &getMibCounterEnable,
377
+ &getMibCounterAll,
378
+ &getMibCounterByPort,
379
+ &getMibCounterByItem,
380
+};
381
+
382
+int (*func_of_ip1811_qos[NUM_IP1811_QOS])(void *cdata, int len) =
383
+{
384
+ &setQOSAgingFunction,
385
+ &getQOSAgingFunction,
386
+ &setQOSAgingTime,
387
+ &getQOSAgingTime,
388
+ &setQOSFastAging,
389
+ &getQOSFastAging,
390
+ &setCOSIGMP,
391
+ &getCOSIGMP,
392
+ &setCOSMACAddress,
393
+ &getCOSMACAddress,
394
+ &setCOSVID,
395
+ &getCOSVID,
396
+ &setCOSTCPUDPPort,
397
+ &getCOSTCPUDPPort,
398
+ &setCOSDSCP,
399
+ &getCOSDSCP,
400
+ &setCOS8021P,
401
+ &getCOS8021P,
402
+ &setCOSPhsicalPort,
403
+ &getCOSPhsicalPort,
404
+ &setCOSPortQueue,
405
+ &getCOSPortQueue,
406
+ &setCOS8021PEdtion,
407
+ &getCOS8021PEdtion,
408
+ &setCOSDSCPBaseDSCP,
409
+ &getCOSDSCPBaseDSCP,
410
+ &setCOSDSCPBaseNoMatchAction,
411
+ &getCOSDSCPBaseNoMatchAction,
412
+ &setQOSmodeGroupMember,
413
+ &getQOSmodeGroupMember,
414
+ &setQOSGroupBEn,
415
+ &getQOSGroupBEn,
416
+ &setQOSMode,
417
+ &getQOSMode,
418
+ &setQOSMethod,
419
+ &getQOSMethod,
420
+ &setQOSWeight,
421
+ &getQOSWeight,
422
+ &setQOSMaxBandwidth,
423
+ &getQOSMaxBandwidth,
424
+ &setQOSUnit,
425
+ &getQOSUnit,
426
+ &setQOSRatioValue0Def,
427
+ &getQOSRatioValue0Def,
428
+ &setQOSSBMDBM,
429
+ &getQOSSBMDBM,
430
+ &setQOSDBMEn,
431
+ &getQOSDBMEn,
432
+ &setQOSRemap,
433
+ &getQOSRemap,
434
+};
435
+
436
+int (*func_of_ip1811_acl[NUM_IP1811_ACL])(void *cdata, int len) =
437
+{
438
+ &setAclRule,
439
+ &getAclRule,
440
+ &aclCleanTable,
441
+ &setAclFunctionEn,
442
+ &getAclFunctionEn,
443
+ &setAclEtherAfterTag,
444
+ &getAclEtherAfterTag,
445
+ &getAclUsedRules,
446
+ &getAclUsedEntries,
447
+ &getAclUsedEntryMask,
448
+ &setAclBW,
449
+ &getAclBW,
450
+ &setAclDscp,
451
+ &getAclDscp,
452
+ &setAclVidRemark,
453
+ &getAclVidRemark,
454
+ &setAclStormPeriod,
455
+ &getAclStormPeriod,
456
+ &setAclStorm,
457
+ &getAclStorm,
458
+};
459
+
460
+int (*func_of_ip1811_hsr[NUM_IP1811_HSR])(void *cdata, int len) =
461
+{
462
+ &setHSREnable,
463
+ &getHSREnable,
464
+ &setHSRMode,
465
+ &getHSRMode,
466
+};
kernel/drivers/net/ethernet/ip1811/ip1811fdat.h
....@@ -0,0 +1,550 @@
1
+#ifndef IP1811FDAT_H
2
+#define IP1811FDAT_H
3
+#include "ip1811.h"
4
+
5
+extern int (*func_of_common_smi[NUM_COMMON_SMI])(void *cdata, int len);
6
+extern int (*func_of_common_cap[NUM_COMMON_CAP])(void *cdata, int len);
7
+extern int (*func_of_common_lut[NUM_COMMON_LUT])(void *cdata, int len);
8
+extern int (*func_of_common_sniffer[NUM_COMMON_SNIFFER])(void *cdata, int len);
9
+extern int (*func_of_common_storm[NUM_COMMON_STORM])(void *cdata, int len);
10
+extern int (*func_of_common_eoc[5])(void *cdata, int len);
11
+extern int (*func_of_common_ld[NUM_COMMON_LOOP_DETECT])(void *cdata, int len);
12
+extern int (*func_of_common_wol[12])(void *cdata, int len);
13
+extern int (*func_of_common_stag[NUM_COMMON_STAG])(void *cdata, int len);
14
+extern int (*func_of_common_misc[NUM_COMMON_MISC])(void *cdata, int len);
15
+extern int (*func_of_common_vlan[NUM_COMMON_VLAN])(void *cdata, int len);
16
+extern int (*func_of_common_stp[NUM_COMMON_STP])(void *cdata, int len);
17
+extern int (*func_of_common_lacp[NUM_COMMON_LACP])(void *cdata, int len);
18
+extern int (*func_of_common_imp[8])(void *cdata, int len);
19
+extern int (*func_of_common_cos[NUM_COMMON_TCPUDP])(void *cdata, int len);
20
+extern int (*func_of_common_bandwidth[NUM_COMMON_BANDWIDTH])(void *cdata, int len);
21
+extern int (*func_of_ip1811_sniffer[NUM_1811_SNIFFER])(void *cdata, int len);
22
+extern int (*func_of_ip1811_storm[NUM_1811_STORM])(void *cdata, int len);
23
+extern int (*func_of_ip1811_eoc[3])(void *cdata, int len);
24
+extern int (*func_of_ip1811_ld[NUM_1811_LOOP_DETECT])(void *cdata, int len);
25
+extern int (*func_of_ip1811_wol[6])(void *cdata, int len);
26
+extern int (*func_of_ip1811_misc[15])(void *cdata, int len);
27
+extern int (*func_of_ip1811_stp[NUM_1811_STP])(void *cdata, int len);
28
+extern int (*func_of_ip1811_lacp[NUM_1811_LACP])(void *cdata, int len);
29
+extern int (*func_of_ip1811_lut[NUM_1811_LUT])(void *cdata, int len);
30
+extern int (*func_of_ip1811_igmp[NUM_1811_IGMP])(void *cdata, int len);
31
+extern int (*func_of_ip1811_ptp[NUM_1811_PTP])(void *cdata, int len);
32
+extern int (*func_of_ip1811_imp[2])(void *cdata, int len);
33
+extern int (*func_of_ip1811_vlan[NUM_IP1811_VLAN])(void *cdata, int len);
34
+extern int (*func_of_ip1811_mib_counter[NUM_1811_MIB_COUNTER])(void *cdata, int len);
35
+extern int (*func_of_ip1811_qos[NUM_IP1811_QOS])(void *cdata, int len);
36
+extern int (*func_of_ip1811_acl[NUM_IP1811_ACL])(void *cdata, int len);
37
+extern int (*func_of_ip1811_hsr[NUM_IP1811_HSR])(void *cdata, int len);
38
+
39
+int setPortAN(void *cdata, int len);
40
+int getPortAN(void *cdata, int len);
41
+int setPortSpeed(void *cdata, int len);
42
+int getPortSpeed(void *cdata, int len);
43
+int setPortDuplex(void *cdata, int len);
44
+int getPortDuplex(void *cdata, int len);
45
+int setPortPause(void *cdata, int len);
46
+int getPortPause(void *cdata, int len);
47
+int setPortAsymPause(void *cdata, int len);
48
+int getPortAsymPause(void *cdata, int len);
49
+int setPortLinkStatus(void *cdata, int len);
50
+int getPortLinkStatus(void *cdata, int len);
51
+int setPortBackpressure(void *cdata, int len);
52
+int getPortBackpressure(void *cdata, int len);
53
+int setPortPowerDown(void *cdata, int len);
54
+int getPortPowerDown(void *cdata, int len);
55
+int setPortForceLink(void *cdata, int len);
56
+int getPortForceLink(void *cdata, int len);
57
+int setPortUniDirection(void *cdata, int len);
58
+int getPortUniDirection(void *cdata, int len);
59
+int setMdioDivisor(void *cdata, int len);
60
+int setFalseLinkSolution(void *cdata, int len);
61
+
62
+int setL2CapAct(void *cdata, int len);
63
+int getL2CapAct(void *cdata, int len);
64
+int setCapInBand(void *cdata, int len);
65
+int getCapInBand(void *cdata, int len);
66
+int setCapInBandRestrict(void *cdata, int len);
67
+int getCapInBandRestrict(void *cdata, int len);
68
+int setCapInBandRestrictCfg(void *cdata, int len);
69
+int getCapInBandRestrictCfg(void *cdata, int len);
70
+int setCapSwitchMac(void *cdata, int len);
71
+int getCapSwitchMac(void *cdata, int len);
72
+int setCapL3Act(void *cdata, int len);
73
+int getCapL3Act(void *cdata, int len);
74
+int setCapL3User(void *cdata, int len);
75
+int getCapL3User(void *cdata, int len);
76
+int setCapEtherUser(void *cdata, int len);
77
+int getCapEtherUser(void *cdata, int len);
78
+int setCapIpv6TcpUdpEnable(void *cdata, int len);
79
+int getCapIpv6TcpUdpEnable(void *cdata, int len);
80
+int setCapIpv6TcpUdpFlagEnable(void *cdata, int len);
81
+int getCapIpv6TcpUdpFlagEnable(void *cdata, int len);
82
+int setCapIpv6StopFinding(void *cdata, int len);
83
+int getCapIpv6StopFinding(void *cdata, int len);
84
+int setCapIpv6ToAllPortsHigh(void *cdata, int len);
85
+int getCapIpv6ToAllPortsHigh(void *cdata, int len);
86
+int setCapIpv6ToCpuHigh(void *cdata, int len);
87
+int getCapIpv6ToCpuHigh(void *cdata, int len);
88
+int setCapIpv6Act(void *cdata, int len);
89
+int getCapIpv6Act(void *cdata, int len);
90
+int setCapIpv6User(void *cdata, int len);
91
+int getCapIpv6User(void *cdata, int len);
92
+int setCapIcmpv6User(void *cdata, int len);
93
+int getCapIcmpv6User(void *cdata, int len);
94
+
95
+int setSMACLearning(void *cdata, int len);
96
+int getSMACLearning(void *cdata, int len);
97
+int setSMACLrnCntCtrl(void *cdata, int len);
98
+int getSMACLrnCntCtrl(void *cdata, int len);
99
+int setSMACLrnThreshold(void *cdata, int len);
100
+int getSMACLrnThreshold(void *cdata, int len);
101
+int setLutPortFlush(void *cdata, int len);
102
+int setLutAgingTime(void *cdata, int len);
103
+int getLutAgingTime(void *cdata, int len);
104
+int setLutAgingTimeEnable(void *cdata, int len);
105
+int getLutAgingTimeEnable(void *cdata, int len);
106
+int setLutLearningNullSA(void *cdata, int len);
107
+int getLutLearningNullSA(void *cdata, int len);
108
+int setLutHashingAlgorithm(void *cdata, int len);
109
+int getLutHashingAlgorithm(void *cdata, int len);
110
+int setLutBindingEnable(void *cdata, int len);
111
+int getLutBindingEnable(void *cdata, int len);
112
+int setLutLearnPktDropByVlanIgsChk(void *cdata, int len);
113
+int getLutLearnPktDropByVlanIgsChk(void *cdata, int len);
114
+
115
+int setLutLearningMode(void *cdata, int len);
116
+int getLutLearningMode(void *cdata, int len);
117
+int setLutUnknownSARule(void *cdata, int len);
118
+int getLutUnknownSARule(void *cdata, int len);
119
+int setLutEntry(void *cdata, int len);
120
+int getLutEntry(void *cdata, int len);
121
+int getLutValidEntry(void *cdata, int len);
122
+
123
+int setSnifferSrc(void *cdata, int len);
124
+int getSnifferSrc(void *cdata, int len);
125
+int setSnifferDestGrp1(void *cdata, int len);
126
+int getSnifferDestGrp1(void *cdata, int len);
127
+int setSnifferDestGrp2(void *cdata, int len);
128
+int getSnifferDestGrp2(void *cdata, int len);
129
+int setS1Method(void *cdata, int len);
130
+int getS1Method(void *cdata, int len);
131
+
132
+int setStormFunc(void *cdata, int len);
133
+int getStormFunc(void *cdata, int len);
134
+int setStormThreshold(void *cdata, int len);
135
+int getStormThreshold(void *cdata, int len);
136
+int setStormCntrClrPeriod(void *cdata, int len);
137
+int getStormCntrClrPeriod(void *cdata, int len);
138
+int setStormBlockFrm2Cpu(void *cdata, int len);
139
+int getStormBlockFrm2Cpu(void *cdata, int len);
140
+int setStormDropInterrupt(void *cdata, int len);
141
+int getStormDropInterrupt(void *cdata, int len);
142
+
143
+int setEocFunc(void *cdata, int len);
144
+int getEocFunc(void *cdata, int len);
145
+int getEocStatus(void *cdata, int len);
146
+int setEocReleaseTime(void *cdata, int len);
147
+int getEocReleaseTime(void *cdata, int len);
148
+
149
+int setLdFunc(void *cdata, int len);
150
+int getLdFunc(void *cdata, int len);
151
+int setLdTimeUnit(void *cdata, int len);
152
+int getLdTimeUnit(void *cdata, int len);
153
+int setLdPktSendTimer(void *cdata, int len);
154
+int getLdPktSendTimer(void *cdata, int len);
155
+int setLdBlockReleaseTimer(void *cdata, int len);
156
+int getLdBlockReleaseTimer(void *cdata, int len);
157
+int getLdStatus(void *cdata, int len);
158
+
159
+int setWolFunc(void *cdata, int len);
160
+int getWolFunc(void *cdata, int len);
161
+int setWolMode(void *cdata, int len);
162
+int getWolMode(void *cdata, int len);
163
+int setWolInterrupt(void *cdata, int len);
164
+int getWolInterrupt(void *cdata, int len);
165
+int setWolIPUnit(void *cdata, int len);
166
+int getWolIPUnit(void *cdata, int len);
167
+int setWolIPThreshold(void *cdata, int len);
168
+int getWolIPThreshold(void *cdata, int len);
169
+int setWolStatusInSlaveMode(void *cdata, int len);
170
+int getWolStatus(void *cdata, int len);
171
+
172
+int setCpuPortLink(void *cdata, int len);
173
+int getCpuPortLink(void *cdata, int len);
174
+int setSTagFunc(void *cdata, int len);
175
+int getSTagFunc(void *cdata, int len);
176
+int setSTagTypeLen(void *cdata, int len);
177
+int getSTagTypeLen(void *cdata, int len);
178
+int configCpuPort(void *cdata, int len);
179
+int getCpuPort(void *cdata, int len);
180
+
181
+int setCosTcpUdpUserDefine(void *cdata, int len);
182
+int getCosTcpUdpUserDefine(void *cdata, int len);
183
+int setCosTcpUdpQueue(void *cdata, int len);
184
+int getCosTcpUdpQueue(void *cdata, int len);
185
+int setCosTcpUdpEnable(void *cdata, int len);
186
+int getCosTcpUdpEnable(void *cdata, int len);
187
+int setCosTcpEnable(void *cdata, int len);
188
+int getCosTcpEnable(void *cdata, int len);
189
+int setCosUdpEnable(void *cdata, int len);
190
+int getCosUdpEnable(void *cdata, int len);
191
+int setCosTcpFlagDropNull(void *cdata, int len);
192
+int getCosTcpFlagDropNull(void *cdata, int len);
193
+int setCosTcpFlagDropAllset(void *cdata, int len);
194
+int getCosTcpFlagDropAllset(void *cdata, int len);
195
+int setCosTcpFlag(void *cdata, int len);
196
+int getCosTcpFlag(void *cdata, int len);
197
+int setCosTcpFlagAct(void *cdata, int len);
198
+int getCosTcpFlagAct(void *cdata, int len);
199
+int setCosTcpFlagPort(void *cdata, int len);
200
+int getCosTcpFlagPort(void *cdata, int len);
201
+
202
+int setBandwidthIngressRate(void *cdata, int len);
203
+int getBandwidthIngressRate(void *cdata, int len);
204
+int setBandwidthEgressRate(void *cdata, int len);
205
+int getBandwidthEgressRate(void *cdata, int len);
206
+int setBandwidthEgressPeriod(void *cdata, int len);
207
+int getBandwidthEgressPeriod(void *cdata, int len);
208
+
209
+int setPTPEnable(void *cdata, int len);
210
+int getPTPEnable(void *cdata, int len);
211
+int setPTPDA011B19000000(void *cdata, int len);
212
+int getPTPDA011B19000000(void *cdata, int len);
213
+int setPTPDA0180C200000E(void *cdata, int len);
214
+int getPTPDA0180C200000E(void *cdata, int len);
215
+int setPTPUdpDP(void *cdata, int len);
216
+int getPTPUdpDP(void *cdata, int len);
217
+int setPTPUdpSP(void *cdata, int len);
218
+int getPTPUdpSP(void *cdata, int len);
219
+int setPTPToCPU(void *cdata, int len);
220
+int getPTPToCPU(void *cdata, int len);
221
+int setPTPSpecialTag(void *cdata, int len);
222
+int getPTPSpecialTag(void *cdata, int len);
223
+int setPTPClockReset(void *cdata, int len);
224
+int getPTPTimeStamp(void *cdata, int len);
225
+int setPTPClockEnable(void *cdata, int len);
226
+int getPTPClockEnable(void *cdata, int len);
227
+int setPTPOverwriteEnable(void *cdata, int len);
228
+int getPTPOverwriteEnable(void *cdata, int len);
229
+int setPTPProgrammable(void *cdata, int len);
230
+int getPTPProgrammable(void *cdata, int len);
231
+int setPTPProgrammableOut(void *cdata, int len);
232
+int setPTPTimestampEnable(void *cdata, int len);
233
+int getPTPTimestampEnable(void *cdata, int len);
234
+int setPTPTimestampClear(void *cdata, int len);
235
+int setPTPTimeData(void *cdata, int len);
236
+int getPTPTimeData(void *cdata, int len);
237
+int addPTPTimeData(void *cdata, int len);
238
+int subPTPTimeData(void *cdata, int len);
239
+int setPTPFrequencyAdd(void *cdata, int len);
240
+int getPTPFrequencyAdd(void *cdata, int len);
241
+int setPTPClockPeriod(void *cdata, int len);
242
+int getPTPClockPeriod(void *cdata, int len);
243
+int setPTPProgrammableConfig(void *cdata, int len);
244
+int setPTPDurationFrequencyCompensation(void *cdata, int len);
245
+int setPTPAlwaysFrequencyCompensation(void *cdata, int len);
246
+int getPTPIngressLatency10(void *cdata, int len);
247
+int getPTPIngressLatency100(void *cdata, int len);
248
+int getPTPIngressLatencyFiber(void *cdata, int len);
249
+int getPTPEgressLatency10(void *cdata, int len);
250
+int getPTPEgressLatency100(void *cdata, int len);
251
+int getPTPEgressLatencyFiber(void *cdata, int len);
252
+
253
+int setJumboPktFunc(void *cdata, int len);
254
+int getJumboPktFunc(void *cdata, int len);
255
+int set8021xFunc(void *cdata, int len);
256
+int get8021xFunc(void *cdata, int len);
257
+int setReg(void *cdata, int len);
258
+int getReg(void *cdata, int len);
259
+int setCPUReg(void *cdata, int len);
260
+int getCPUReg(void *cdata, int len);
261
+int setSwitchRestart(void *cdata, int len);
262
+int setSwitchReset(void *cdata, int len);
263
+int setCpuIfSpeed(void *cdata, int len);
264
+int setEepromByte(void *cdata, int len);
265
+int getEepromByte(void *cdata, int len);
266
+int get_mii_reg(void *cdata, int len);
267
+int set_mii_reg(void *cdata, int len);
268
+
269
+int setVlanEgressFrame(void *cdata, int len);
270
+int getVlanEgressFrame(void *cdata, int len);
271
+int setVlanTagging(void *cdata, int len);
272
+int getVlanTagging(void *cdata, int len);
273
+int setVlanType(void *cdata, int len);
274
+int getVlanType(void *cdata, int len);
275
+int setVlanGroup(void *cdata, int len);
276
+
277
+int setVlanQinQPType(void *cdata, int len);
278
+int getVlanQinQPType(void *cdata, int len);
279
+int setVlanQinQPAddtag(void *cdata, int len);
280
+int getVlanQinQPAddtag(void *cdata, int len);
281
+int setVlanQinQPRmvtag(void *cdata, int len);
282
+int getVlanQinQPRmvtag(void *cdata, int len);
283
+int setVlanQinQPRxdet(void *cdata, int len);
284
+int getVlanQinQPRxdet(void *cdata, int len);
285
+int setVlanQinQPKeep(void *cdata, int len);
286
+int getVlanQinQPKeep(void *cdata, int len);
287
+int setVlanQinQPIndex(void *cdata, int len);
288
+int getVlanQinQPIndex(void *cdata, int len);
289
+int setVlanQinQIndex(void *cdata, int len);
290
+int getVlanQinQIndex(void *cdata, int len);
291
+int setVlanQinQStagSelectMethod(void *cdata, int len);
292
+int getVlanQinQStagSelectMethod(void *cdata, int len);
293
+
294
+int setVlanPortAddtag(void *cdata, int len);
295
+int getVlanPortAddtag(void *cdata, int len);
296
+int setVlanPortRmvtag(void *cdata, int len);
297
+int getVlanPortRmvtag(void *cdata, int len);
298
+int setVlanPortForce(void *cdata, int len);
299
+int getVlanPortForce(void *cdata, int len);
300
+int setVlanPortUplink(void *cdata, int len);
301
+int getVlanPortUplink(void *cdata, int len);
302
+int setVlanPortExclusive(void *cdata, int len);
303
+int getVlanPortExclusive(void *cdata, int len);
304
+int setVlanPortEgress(void *cdata, int len);
305
+int getVlanPortEgress(void *cdata, int len);
306
+int setVlanPortIngressFrame(void *cdata, int len);
307
+int getVlanPortIngressFrame(void *cdata, int len);
308
+int setVlanPortIngressCheck(void *cdata, int len);
309
+int getVlanPortIngressCheck(void *cdata, int len);
310
+int setVlanPortMember(void *cdata, int len);
311
+int getVlanPortMember(void *cdata, int len);
312
+int setVlanPortVid(void *cdata, int len);
313
+int getVlanPortVid(void *cdata, int len);
314
+
315
+int setVlanProtocolMode(void *cdata, int len);
316
+int getVlanProtocolMode(void *cdata, int len);
317
+int setVlanProtocolVid(void *cdata, int len);
318
+int getVlanProtocolVid(void *cdata, int len);
319
+int setVlanProtocolType(void *cdata, int len);
320
+int getVlanProtocolType(void *cdata, int len);
321
+int setVlanProtocolClear(void *cdata, int len);
322
+int setVlanMACBased(void *cdata, int len);
323
+int setVlanMACBasedtableconfig(void *cdata, int len);
324
+int getVlanMACBasedtableconfig(void *cdata, int len);
325
+int setVlanMACBasedunknown(void *cdata, int len);
326
+
327
+int setVlanEntryMember(void *cdata, int len);
328
+int getVlanEntryMember(void *cdata, int len);
329
+int setVlanEntryAddtag(void *cdata, int len);
330
+int getVlanEntryAddtag(void *cdata, int len);
331
+int setVlanEntryRmvtag(void *cdata, int len);
332
+int getVlanEntryRmvtag(void *cdata, int len);
333
+int setVlanEntryPriority(void *cdata, int len);
334
+int getVlanEntryPriority(void *cdata, int len);
335
+int setVlanEntryFid(void *cdata, int len);
336
+int getVlanEntryFid(void *cdata, int len);
337
+int setVlanEntryClear(void *cdata, int len);
338
+
339
+int setMstpFunc(void *cdata, int len);
340
+int getMstpFunc(void *cdata, int len);
341
+
342
+int setTrunkHashMthd(void *cdata, int len);
343
+int getTrunkHashMthd(void *cdata, int len);
344
+int setTrunkMbr(void *cdata, int len);
345
+int getTrunkMbr(void *cdata, int len);
346
+int setCpuNCareTrunkAndVlan(void *cdata, int len);
347
+int getCpuNCareTrunkAndVlan(void *cdata, int len);
348
+
349
+int setImpMode(void *cdata, int len);
350
+int getImpMode(void *cdata, int len);
351
+int setImpPassNullIP(void *cdata, int len);
352
+int getImpPassNullIP(void *cdata, int len);
353
+int setImpHash(void *cdata, int len);
354
+int getImpHash(void *cdata, int len);
355
+int setImpPort(void *cdata, int len);
356
+int getImpPort(void *cdata, int len);
357
+
358
+int setImpEntry(void *cdata, int len);
359
+int getImpEntry(void *cdata, int len);
360
+
361
+int setIGMPSnooping(void *cdata, int len);
362
+int getIGMPSnooping(void *cdata, int len);
363
+int setIGMPMctByCPU(void *cdata, int len);
364
+int getIGMPMctByCPU(void *cdata, int len);
365
+int setIGMPRltByCPU(void *cdata, int len);
366
+int getIGMPRltByCPU(void *cdata, int len);
367
+int setIGMPPktForward(void *cdata, int len);
368
+int getIGMPPktForward(void *cdata, int len);
369
+int setIGMPRlt(void *cdata, int len);
370
+int getIGMPRlt(void *cdata, int len);
371
+int setIGMPHashMethod(void *cdata, int len);
372
+int getIGMPHashMethod(void *cdata, int len);
373
+int setIGMPMldRule(void *cdata, int len);
374
+int getIGMPMldRule(void *cdata, int len);
375
+int setIGMPMctTable(void *cdata, int len);
376
+int getIGMPMctTable(void *cdata, int len);
377
+int setIGMPSltTable(void *cdata, int len);
378
+int getIGMPSltTable(void *cdata, int len);
379
+
380
+
381
+int setS1PktModify(void *cdata, int len);
382
+int getS1PktModify(void *cdata, int len);
383
+int setS1TM4CpuSTag(void *cdata, int len);
384
+int getS1TM4CpuSTag(void *cdata, int len);
385
+int setS1TM4Acl2Cpu(void *cdata, int len);
386
+int getS1TM4Acl2Cpu(void *cdata, int len);
387
+int setS1TM4Pkt2MPort(void *cdata, int len);
388
+int getS1TM4Pkt2MPort(void *cdata, int len);
389
+int setS2LTT4Grp1(void *cdata, int len);
390
+int getS2LTT4Grp1(void *cdata, int len);
391
+int setS2LTT4Grp2(void *cdata, int len);
392
+int getS2LTT4Grp2(void *cdata, int len);
393
+
394
+int setMStormNBlockIpPkt(void *cdata, int len);
395
+int getMStormNBlockIpPkt(void *cdata, int len);
396
+int setMStormIgnr01005EXXXXXX(void *cdata, int len);
397
+int getMStormIgnr01005EXXXXXX(void *cdata, int len);
398
+
399
+int setEocBlockClr(void *cdata, int len);
400
+int setEocClrBlockWhenRcvGood(void *cdata, int len);
401
+int getEocClrBlockWhenRcvGood(void *cdata, int len);
402
+
403
+int setLdSMACB40(void *cdata, int len);
404
+int getLdSMACB40(void *cdata, int len);
405
+int setLdRerandom(void *cdata, int len);
406
+int getLdRerandom(void *cdata, int len);
407
+int setLdDMAC(void *cdata, int len);
408
+int getLdDMAC(void *cdata, int len);
409
+int setLdEtherType(void *cdata, int len);
410
+int getLdEtherType(void *cdata, int len);
411
+int setLdSubType(void *cdata, int len);
412
+int getLdSubType(void *cdata, int len);
413
+int setLdDeviceID(void *cdata, int len);
414
+int getLdDeviceID(void *cdata, int len);
415
+
416
+int setWolWakeIfTxGetAnyPkt(void *cdata, int len);
417
+int getWolWakeIfTxGetAnyPkt(void *cdata, int len);
418
+int setWolWakeIfRxGetAnyPkt(void *cdata, int len);
419
+int getWolWakeIfRxGetAnyPkt(void *cdata, int len);
420
+int setWolWakeIfMatchAcl2Cpu(void *cdata, int len);
421
+int getWolWakeIfMatchAcl2Cpu(void *cdata, int len);
422
+
423
+int setMACLoopBackFunc(void *cdata, int len);
424
+int getMACLoopBackFunc(void *cdata, int len);
425
+int setPausePktFunc(void *cdata, int len);
426
+int getPausePktFunc(void *cdata, int len);
427
+int setPausePktDest(void *cdata, int len);
428
+int getPausePktDest(void *cdata, int len);
429
+int setLocalTrafficFunc(void *cdata, int len);
430
+int getLocalTrafficFunc(void *cdata, int len);
431
+int setMACReset(void *cdata, int len);
432
+int getMACReset(void *cdata, int len);
433
+int setMACSelfTestFunc(void *cdata, int len);
434
+int getMACSelfTestFunc(void *cdata, int len);
435
+int setMACSelfTestPktNum(void *cdata, int len);
436
+int getMACSelfTestPktNum(void *cdata, int len);
437
+int getMACSelfTestResult(void *cdata, int len);
438
+
439
+int setBpduCapMode(void *cdata, int len);
440
+int getBpduCapMode(void *cdata, int len);
441
+int setBpduPortAct(void *cdata, int len);
442
+int getBpduPortAct(void *cdata, int len);
443
+int setStpPortState(void *cdata, int len);
444
+int getStpPortState(void *cdata, int len);
445
+int setStpAllPortsState(void *cdata, int len);
446
+int getStpAllPortsState(void *cdata, int len);
447
+
448
+int setTrunkHashMthdSeq(void *cdata, int len);
449
+int getTrunkHashMthdSeq(void *cdata, int len);
450
+int setTrunkGrpCombine(void *cdata, int len);
451
+int getTrunkGrpCombine(void *cdata, int len);
452
+
453
+int setMibCounterEnable(void *cdata, int len);
454
+int getMibCounterEnable(void *cdata, int len);
455
+int getMibCounterAll(void *cdata, int len);
456
+int getMibCounterByPort(void *cdata, int len);
457
+int getMibCounterByItem(void *cdata, int len);
458
+
459
+int setQOSAgingFunction(void *cdata, int len);
460
+int getQOSAgingFunction(void *cdata, int len);
461
+int setQOSAgingTime(void *cdata, int len);
462
+int getQOSAgingTime(void *cdata, int len);
463
+int setQOSFastAging(void *cdata, int len);
464
+int getQOSFastAging(void *cdata, int len);
465
+
466
+int setCOSIGMP(void *cdata, int len);
467
+int getCOSIGMP(void *cdata, int len);
468
+int setCOSMACAddress(void *cdata, int len);
469
+int getCOSMACAddress(void *cdata, int len);
470
+int setCOSVID(void *cdata, int len);
471
+int getCOSVID(void *cdata, int len);
472
+int setCOSTCPUDPPort(void *cdata, int len);
473
+int getCOSTCPUDPPort(void *cdata, int len);
474
+int setCOSDSCP(void *cdata, int len);
475
+int getCOSDSCP(void *cdata, int len);
476
+int setCOS8021P(void *cdata, int len);
477
+int getCOS8021P(void *cdata, int len);
478
+int setCOSPhsicalPort(void *cdata, int len);
479
+int getCOSPhsicalPort(void *cdata, int len);
480
+int setCOSPortQueue(void *cdata, int len);
481
+int getCOSPortQueue(void *cdata, int len);
482
+int setCOS8021PEdtion(void *cdata, int len);
483
+int getCOS8021PEdtion(void *cdata, int len);
484
+int setCOSDSCPBaseDSCP(void *cdata, int len);
485
+int getCOSDSCPBaseDSCP(void *cdata, int len);
486
+int setCOSDSCPBaseNoMatchAction(void *cdata, int len);
487
+int getCOSDSCPBaseNoMatchAction(void *cdata, int len);
488
+int setQOSmodeGroupMember(void *cdata, int len);
489
+int getQOSmodeGroupMember(void *cdata, int len);
490
+int setQOSGroupBEn(void *cdata, int len);
491
+int getQOSGroupBEn(void *cdata, int len);
492
+int setQOSMode(void *cdata, int len);
493
+int getQOSMode(void *cdata, int len);
494
+int setQOSMethod(void *cdata, int len);
495
+int getQOSMethod(void *cdata, int len);
496
+int setQOSWeight(void *cdata, int len);
497
+int getQOSWeight(void *cdata, int len);
498
+int setQOSMaxBandwidth(void *cdata, int len);
499
+int getQOSMaxBandwidth(void *cdata, int len);
500
+int setQOSUnit(void *cdata, int len);
501
+int getQOSUnit(void *cdata, int len);
502
+int setQOSRatioValue0Def(void *cdata, int len);
503
+int getQOSRatioValue0Def(void *cdata, int len);
504
+int setQOSSBMDBM(void *cdata, int len);
505
+int getQOSSBMDBM(void *cdata, int len);
506
+int setQOSDBMEn(void *cdata, int len);
507
+int getQOSDBMEn(void *cdata, int len);
508
+int setQOSEgressControl(void *cdata, int len);
509
+int getQOSEgressControl(void *cdata, int len);
510
+
511
+int setQOSRemap(void *cdata, int len);
512
+int getQOSRemap(void *cdata, int len);
513
+
514
+void acl_init(void);
515
+int setAclRule(void *cdata, int len);
516
+int getAclRule(void *cdata, int len);
517
+int aclCleanTable(void *cdata, int len);
518
+int setAclFunctionEn(void *cdata, int len);
519
+int getAclFunctionEn(void *cdata, int len);
520
+int setAclEtherAfterTag(void *cdata, int len);
521
+int getAclEtherAfterTag(void *cdata, int len);
522
+int getAclUsedRules(void *cdata, int len);
523
+int getAclUsedEntries(void *cdata, int len);
524
+int getAclUsedEntryMask(void *cdata, int len);
525
+int setAclBW(void *cdata, int len);
526
+int getAclBW(void *cdata, int len);
527
+int setAclDscp(void *cdata, int len);
528
+int getAclDscp(void *cdata, int len);
529
+int setAclVidRemark(void *cdata, int len);
530
+int getAclVidRemark(void *cdata, int len);
531
+int setAclStormPeriod(void *cdata, int len);
532
+int getAclStormPeriod(void *cdata, int len);
533
+int setAclStorm(void *cdata, int len);
534
+int getAclStorm(void *cdata, int len);
535
+
536
+/* ipv: 4: IPv4
537
+ * 6: IPv6
538
+ * addr: IP address
539
+ * method: 1: Direct
540
+ * 0: CRC
541
+ * */
542
+unsigned char tb_calc_index(unsigned char ipv, void *addr, unsigned char method);
543
+
544
+int setHSREnable(void *cdata, int len);
545
+int getHSREnable(void *cdata, int len);
546
+int setHSRMode(void *cdata, int len);
547
+int getHSRMode(void *cdata, int len);
548
+
549
+void noFunc(void);
550
+#endif /* IP1811FDAT_H */
kernel/drivers/net/ethernet/ip1811/ip1811func.c
....@@ -0,0 +1,13309 @@
1
+#include <linux/kernel.h>
2
+#include <linux/module.h>
3
+#include <linux/errno.h>
4
+#include <linux/delay.h>
5
+#include <linux/string.h>
6
+#include <linux/slab.h>
7
+#include <asm/uaccess.h>
8
+#include <linux/uaccess.h>
9
+#include <linux/fs.h>
10
+#include <linux/file.h>
11
+#include <asm/io.h>
12
+
13
+#include "ip1811.h"
14
+#include "ip1811reg.h"
15
+#include "ip1811ds.h"
16
+#include "ip1811op.h"
17
+#include "ip1811fdat.h"
18
+#include "ip218.h"
19
+
20
+#define MII_OP_READ 0
21
+#define MII_OP_WRITE 1
22
+
23
+//#define TEST_REG
24
+//#define IP1811DEBUG
25
+//#define IP1811DRV_REG_DEBUG
26
+#ifdef IP1811DRV_REG_DEBUG
27
+#define ip1811drv_dbg(fmt, ...) printk(KERN_DEBUG "<%s:%d>" fmt, __func__, __LINE__, ##__VA_ARGS__)
28
+#else
29
+#define ip1811drv_dbg(...)
30
+#endif//IP1811DRV_REG_DEBUG
31
+
32
+#define IP1811DRV_REG_ERROR
33
+#ifdef IP1811DRV_REG_ERROR
34
+#define ip1811drv_err(fmt, ...) printk(KERN_ERR "<%s:%d>" fmt, __func__, __LINE__, ##__VA_ARGS__)
35
+#else
36
+#define ip1811drv_err(...)
37
+#endif//IP1811DRV_REG_ERROR
38
+
39
+#define FUNC_MSG_IN ip1811drv_dbg("IN \n")
40
+#define FUNC_MSG_OUT ip1811drv_dbg("OUT\n")
41
+
42
+extern u8 CPU_IF_SPEED_NORMAL;
43
+
44
+#ifdef TEST_REG
45
+u16 RegList[16][256];
46
+u8 pg;
47
+#endif//TEST_REG
48
+
49
+#define ip1811delay() (udelay(100))
50
+
51
+/*============= misc. driver functions ===================*/
52
+
53
+//#define ACCESS_REG_BY_MDIO
54
+#ifdef ACCESS_REG_BY_MDIO
55
+//-------------- p1811 project GPIO MDIO Function ---------------------
56
+#define MDIO_DELAY 0
57
+#define MDIO_RD 0
58
+#define MDIO_WR 1
59
+#define GPIO_MDIO_OFFSET 10
60
+#define GPIO_MDC_OFFSET 11
61
+#include <asm/io.h>
62
+static DEFINE_MUTEX(ip1811_gpio_lock);
63
+#define IP1811_GPIO_BASE 0xBD700000
64
+#define IP1811_GPIO_OUTPUT_VALUE_2_OFFSET 0x003C
65
+#define IP1811_GPIO_OUTPUT_ENABLE_2_OFFSET 0x0040
66
+#define IP1811_GPIO_INPUT_VALUE_2_OFFSET 0x0038
67
+#define IP1811_GPIO_SET_VALUE_1 0x1
68
+#define IP1811_GPIO_SET_VALUE_0 0x0
69
+static int ip1811_gpio_get(unsigned offset)
70
+{
71
+ void __iomem *base;
72
+ u32 val;
73
+
74
+ mutex_lock(&ip1811_gpio_lock);
75
+
76
+
77
+ base = IP1811_GPIO_BASE + IP1811_GPIO_INPUT_VALUE_2_OFFSET;
78
+ val = readl(base);
79
+ val = ((val & BIT(offset))>>offset);
80
+
81
+ mutex_unlock(&ip1811_gpio_lock);
82
+
83
+ return val;
84
+}
85
+static void ip1811_gpio_set(unsigned offset,int value)
86
+{
87
+ void __iomem *base;
88
+ u32 val;
89
+
90
+ mutex_lock(&ip1811_gpio_lock);
91
+
92
+ base = IP1811_GPIO_BASE + IP1811_GPIO_OUTPUT_VALUE_2_OFFSET;
93
+ val = readl(base);
94
+ val = (value == IP1811_GPIO_SET_VALUE_1) ? (val | BIT(offset)) : (val & ~((BIT(offset))));
95
+ writel(val, base);
96
+
97
+ mutex_unlock(&ip1811_gpio_lock);
98
+
99
+ return;
100
+}
101
+static int ip1811_gpio_direction_out(unsigned offset,int value)
102
+{
103
+ void __iomem *base;
104
+ u32 val;
105
+
106
+ mutex_lock(&ip1811_gpio_lock);
107
+
108
+ base = IP1811_GPIO_BASE + IP1811_GPIO_OUTPUT_ENABLE_2_OFFSET;
109
+ val = readl(base);
110
+ val |= BIT(offset);
111
+ writel(val, base);
112
+
113
+ mutex_unlock(&ip1811_gpio_lock);
114
+
115
+ return 0;
116
+}
117
+static int ip1811_gpio_direction_in( unsigned offset)
118
+{
119
+ void __iomem *base;
120
+ u32 val;
121
+
122
+ mutex_lock(&ip1811_gpio_lock);
123
+
124
+ base = IP1811_GPIO_BASE + IP1811_GPIO_OUTPUT_ENABLE_2_OFFSET;
125
+ val = readl(base);
126
+ val &= ~(BIT(offset));
127
+ writel(val, base);
128
+
129
+ mutex_unlock(&ip1811_gpio_lock);
130
+
131
+ return val;
132
+}
133
+void mdio_1(void){
134
+
135
+ int i;
136
+ //set MDIO to 1
137
+ //set MDC to 0
138
+ ip1811_gpio_set(GPIO_MDIO_OFFSET,1);
139
+ ip1811_gpio_set(GPIO_MDC_OFFSET,0);
140
+
141
+ for(i=0;i<MDIO_DELAY;i++);
142
+
143
+ //set MDIO to 1
144
+ //set MDC to 1
145
+ ip1811_gpio_set(GPIO_MDIO_OFFSET,1);
146
+ ip1811_gpio_set(GPIO_MDC_OFFSET,1);
147
+
148
+ for(i=0;i<MDIO_DELAY;i++);
149
+}
150
+
151
+void mdio_0(void){
152
+
153
+ int i;
154
+ //set MDIO to 0
155
+ //set MDC to 0
156
+ ip1811_gpio_set(GPIO_MDIO_OFFSET,0);
157
+ ip1811_gpio_set(GPIO_MDC_OFFSET,0);
158
+
159
+ for(i=0;i<MDIO_DELAY;i++);
160
+
161
+ //set MDIO to 0
162
+ //set MDC to 1
163
+ ip1811_gpio_set(GPIO_MDIO_OFFSET,0);
164
+ ip1811_gpio_set(GPIO_MDC_OFFSET,1);
165
+
166
+ for(i=0;i<MDIO_DELAY;i++);
167
+}
168
+
169
+void mdio_z(void){
170
+
171
+ int i;
172
+ //set MDC to 0
173
+ ip1811_gpio_set(GPIO_MDC_OFFSET,0);
174
+
175
+ for(i=0;i<MDIO_DELAY;i++);
176
+ //set MDC to 1
177
+ ip1811_gpio_set(GPIO_MDC_OFFSET,1);
178
+
179
+ for(i=0;i<MDIO_DELAY;i++);
180
+}
181
+
182
+void mdio_start(void){
183
+ mdio_0();
184
+ mdio_1();
185
+}
186
+
187
+void mdio_rw(int rw){
188
+ if(rw==MDIO_RD){
189
+ mdio_1();
190
+ mdio_0();
191
+ }else{
192
+ mdio_0();
193
+ mdio_1();
194
+ }
195
+}
196
+void mdio_set_MDC_MDIO_direction(unsigned char mdc, unsigned char mdio)//0:input, 1:output for mdc/mdio values
197
+{
198
+ if(mdc) ;
199
+ if(mdio)
200
+ ip1811_gpio_direction_out(GPIO_MDIO_OFFSET,0);
201
+ else
202
+ ip1811_gpio_direction_in(GPIO_MDIO_OFFSET);
203
+}
204
+void ic_mdio_wr(unsigned short pa, unsigned short ra, unsigned short va){
205
+ int i=0;
206
+ unsigned short data=0;
207
+
208
+ //set MDC/MDIO pins to GPIO mode
209
+ ip1811_gpio_direction_out(GPIO_MDC_OFFSET,0);
210
+ ip1811_gpio_direction_out(GPIO_MDIO_OFFSET,0);
211
+
212
+ //set MDC direction to output
213
+ //set MDIO direction to output
214
+ mdio_set_MDC_MDIO_direction(1,1);
215
+
216
+ for(i=0;i<32;i++)
217
+ mdio_1();
218
+ mdio_start();
219
+ mdio_rw(MDIO_WR);
220
+ for(i=0;i<5;i++){
221
+ if((pa>>(5-1-i))%2)
222
+ mdio_1();
223
+ else
224
+ mdio_0();
225
+ }
226
+ for(i=0;i<5;i++){
227
+ if((ra>>(5-1-i))%2)
228
+ mdio_1();
229
+ else
230
+ mdio_0();
231
+ }
232
+ mdio_1();
233
+ mdio_0();
234
+ for(i=0;i<16;i++){
235
+ data=va<<i;
236
+ data=data>>15;
237
+ if(data==1)
238
+ mdio_1();
239
+ else
240
+ mdio_0();
241
+ }
242
+}
243
+unsigned short ic_mdio_rd(unsigned short pa, unsigned short ra){
244
+ int i=0,j=0;
245
+ unsigned short data=0;
246
+ int regBit;
247
+ unsigned char debug[16];
248
+
249
+ //set MDC/MDIO pins to GPIO mode
250
+ ip1811_gpio_direction_out(GPIO_MDC_OFFSET,0);
251
+ ip1811_gpio_direction_out(GPIO_MDIO_OFFSET,0);
252
+
253
+ //set MDC/MDIO PIN direction
254
+ //mdio_set_MDC_MDIO_dir();
255
+ //MDC direction set to output
256
+ //MDIO direction set to output
257
+ mdio_set_MDC_MDIO_direction(1,1);
258
+
259
+ for(i=0;i<32;i++)
260
+ mdio_1();
261
+ mdio_start();
262
+ mdio_rw(MDIO_RD);
263
+ for(i=0;i<5;i++){
264
+ if((pa>>(5-1-i))%2)
265
+ mdio_1();
266
+ else
267
+ mdio_0();
268
+ }
269
+ for(i=0;i<5;i++){
270
+ if((ra>>(5-1-i))%2)
271
+ mdio_1();
272
+ else
273
+ mdio_0();
274
+ }
275
+ mdio_z();
276
+ //MDIO DIR set to input
277
+ mdio_set_MDC_MDIO_direction(1,0);
278
+ mdio_0();
279
+
280
+
281
+ for(j=0;j<16;j++){
282
+ //MDC set to 0
283
+ ip1811_gpio_set(GPIO_MDC_OFFSET,0);
284
+
285
+ for(i=0;i<MDIO_DELAY;i++);
286
+ //get MDIO value
287
+ regBit=ip1811_gpio_get(GPIO_MDIO_OFFSET);
288
+ if(regBit==0)
289
+ {
290
+ data|=0;
291
+ debug[15-j]=0;
292
+ }
293
+ else
294
+ {
295
+ data|=1;
296
+ debug[15-j]=1;
297
+ }
298
+ if(j<15)
299
+ data=data<<1;
300
+ //MDC set to 1
301
+ ip1811_gpio_set(GPIO_MDC_OFFSET,1);
302
+
303
+ for(i=0;i<MDIO_DELAY;i++);
304
+ }
305
+ //MDC set to 0
306
+ ip1811_gpio_set(GPIO_MDC_OFFSET,0);
307
+
308
+ for(i=0;i<MDIO_DELAY;i++);
309
+ //MDC set to 1
310
+ ip1811_gpio_set(GPIO_MDC_OFFSET,1);
311
+
312
+ for(i=0;i<MDIO_DELAY;i++);
313
+
314
+ return data;
315
+}
316
+#else//#ifndef ACCESS_REG_BY_MDIO
317
+void ic_mdio_wr(unsigned short pa, unsigned short ra, unsigned short va){
318
+ void __iomem *base;
319
+ unsigned long val;
320
+ struct ip218_smictrl0 *smic0;
321
+
322
+ FUNC_MSG_IN;
323
+
324
+ val = 0;
325
+ smic0 = (struct ip218_smictrl0 *)&val;
326
+ smic0 -> phy = pa;
327
+ smic0 -> reg = ra;
328
+ smic0 -> wr_data = va;
329
+ smic0 -> rdwr = 1;//1: write cycle
330
+ smic0 -> en = 1;
331
+
332
+ base = (void __iomem *)(IP218_MAC_BASE + IP218_MAC_SMICTRL0);
333
+ ip1811drv_dbg("write [%p]=%08lX\n", base, val);
334
+ writel(val, base);
335
+
336
+ // wait for writing process done
337
+ do{
338
+ val = readl(base);
339
+ }while(smic0 -> en);
340
+
341
+ FUNC_MSG_OUT;
342
+}
343
+unsigned short ic_mdio_rd(unsigned short pa, unsigned short ra){
344
+ void __iomem *base;
345
+ unsigned long val;
346
+ unsigned short ret;
347
+ struct ip218_smictrl0 *smic0;
348
+ struct ip218_smictrl1 *smic1;
349
+
350
+ FUNC_MSG_IN;
351
+
352
+ val = 0;
353
+ smic0 = (struct ip218_smictrl0 *)&val;
354
+ smic0 -> phy = pa;
355
+ smic0 -> reg = ra;
356
+ smic0 -> rdwr = 0;//0: read cycle
357
+ smic0 -> en = 1;
358
+
359
+ base = (void __iomem *)(IP218_MAC_BASE + IP218_MAC_SMICTRL0);
360
+ ip1811drv_dbg("write [%p]=%08lX\n", base, val);
361
+ writel(val, base);
362
+
363
+ // wait for writing process done
364
+ do{
365
+ val = readl(base);
366
+ }while(smic0 -> en);
367
+
368
+ // read data from register
369
+ base = (void __iomem *)(IP218_MAC_BASE + IP218_MAC_SMICTRL1);
370
+ val = readl(base);
371
+ smic1 = (struct ip218_smictrl1 *)&val;
372
+ ret = smic1 -> rd_data;
373
+ ip1811drv_dbg("read [%p]=%08lX\n", base, val);
374
+
375
+ FUNC_MSG_OUT;
376
+
377
+ return ret;
378
+}
379
+#endif//ACCESS_REG_BY_MDIO
380
+
381
+void Write_Reg(u8 regaddr, u16 value)
382
+{
383
+ u16 tmp = CPU_IF_SPEED_NORMAL ? regaddr : (u16)regaddr << 2;
384
+#ifdef TEST_REG
385
+ ip1811drv_dbg("RegList[%x][0x%02X]=0x%04x\n", pg, regaddr, RegList[pg][regaddr]);
386
+ RegList[pg][regaddr]=value;
387
+#else
388
+ ic_mdio_wr(((tmp)>>5)&0x1f,(tmp)&0x1f,value);
389
+#endif//TEST_REG
390
+
391
+#ifdef TEST_REG
392
+ ip1811drv_dbg("RegList[%x][0x%02X]=0x%04x\n", pg, regaddr, RegList[pg][regaddr]);
393
+#endif//TEST_REG
394
+
395
+ ip1811drv_dbg("write [%02X]=%04x\n", regaddr, value);
396
+}
397
+u16 Read_Reg(u8 regaddr)
398
+{
399
+ u16 u16d;
400
+ u16 tmp = CPU_IF_SPEED_NORMAL ? regaddr : (u16)regaddr << 2;
401
+#ifdef TEST_REG
402
+ u16d = RegList[pg][regaddr];
403
+#else
404
+ u16d=ic_mdio_rd(((tmp)>>5)&0x1f,(tmp)&0x1f);
405
+#endif//TEST_REG
406
+#ifdef TEST_REG
407
+ ip1811drv_dbg("RegList[%x][0x%02X]=0x%04x\n", pg, regaddr, RegList[pg][regaddr]);
408
+#endif//TEST_REG
409
+ ip1811drv_dbg("read [%02X]=%04x\n", regaddr, u16d);
410
+ return u16d;
411
+}
412
+
413
+void _Write_Reg(u8 regaddr, u16 value)
414
+{
415
+ u16 tmp = CPU_IF_SPEED_NORMAL ? regaddr : (u16)regaddr << 2;
416
+ ic_mdio_wr(((tmp)>>5)&0x1f,(tmp)&0x1f,value);
417
+
418
+ ip1811drv_dbg("write [%02X]=%04x\n", regaddr, value);
419
+}
420
+u16 _Read_Reg(u8 regaddr)
421
+{
422
+ u16 u16d;
423
+ u16 tmp = CPU_IF_SPEED_NORMAL ? regaddr : (u16)regaddr << 2;
424
+ u16d=ic_mdio_rd(((tmp)>>5)&0x1f,(tmp)&0x1f);
425
+ ip1811drv_dbg("read [%02X]=%04x\n", regaddr, u16d);
426
+ return u16d;
427
+}
428
+u16 Read_Reg_0_With_1s(void)
429
+{
430
+ u16 u16d;
431
+ u16 tmp = CPU_IF_SPEED_NORMAL ? 0x300 : 0x3;
432
+ u16d = ic_mdio_rd(((tmp)>>5)&0x1f,(tmp)&0x1f);
433
+ ip1811drv_dbg("read [%04X]=%04x\n", tmp, u16d);
434
+ return u16d;
435
+}
436
+void IP2Page(u8 page) // Change page to pagenum
437
+{
438
+ u16 tmp = CPU_IF_SPEED_NORMAL ? REG_Page : (u16)REG_Page << 2;
439
+#ifdef TEST_REG
440
+ pg = page;
441
+#else
442
+ ic_mdio_wr(((tmp)>>5)&0x1f,(tmp)&0x1f,page);
443
+#endif//TEST_REG
444
+ ip1811drv_dbg("set to page[%02u]\n", page);
445
+}
446
+void _IP2Page(u8 page) // Change page to pagenum
447
+{
448
+ u16 tmp = CPU_IF_SPEED_NORMAL ? REG_Page : (u16)REG_Page << 2;
449
+ ic_mdio_wr(((tmp)>>5)&0x1f,(tmp)&0x1f,page);
450
+ ip1811drv_dbg("set to page[%02u]\n", page);
451
+}
452
+/*============= sub. driver functions ==================*/
453
+static void _WriteRegBits(u8 page, u16 reg, u8 offset, u8 len, u16 val)
454
+{
455
+ u16 mask = 0;
456
+ u16 u16dat;
457
+
458
+ FUNC_MSG_IN;
459
+
460
+ IP2Page(page);
461
+ mask = (0x1 << len) - 1;
462
+ u16dat = Read_Reg(reg);
463
+ u16dat &= ~(mask<<offset);
464
+ u16dat |= (val&mask)<<offset;
465
+ Write_Reg(reg, u16dat);
466
+
467
+ FUNC_MSG_OUT;
468
+}
469
+
470
+static u16 _ReadRegBits(u8 page, u16 reg, u8 offset, u8 len)
471
+{
472
+ u16 mask = 0;
473
+ u16 u16dat;
474
+ u16 val;
475
+
476
+ FUNC_MSG_IN;
477
+
478
+ IP2Page(page);
479
+ mask = (0x1 << len) - 1;
480
+ u16dat = Read_Reg(reg);
481
+ val = (u16dat>>offset)&mask;
482
+
483
+ FUNC_MSG_OUT;
484
+ return val;
485
+}
486
+#if 0
487
+u16 _read_mii_register(u8 phy, u8 page, u8 reg)
488
+{
489
+ u8 option = MII_OP_READ;
490
+ u16 u16dat = 0;
491
+ IP2Page(3);
492
+
493
+ // change phy page
494
+ Write_Reg(P3REG_PHYACCESS_DATA, page);
495
+
496
+ u16dat = (phy & 0x1f); //PHY
497
+ u16dat |= (0x14 & 0x1f ) << 5; //MII Reg
498
+ u16dat |= (MII_OP_WRITE & 0x1 )<< 14;//Read or Write
499
+ u16dat |= 0x1 << 15;//Trigger & Write
500
+
501
+ Write_Reg(P3REG_PHYACCESS_CMD, u16dat);
502
+ while(_ReadRegBits(3, P3REG_PHYACCESS_CMD, 15, 1));
503
+ udelay(5000);
504
+
505
+ // phy read command
506
+ u16dat = 0;
507
+
508
+ u16dat = (phy & 0x1f); //PHY
509
+ u16dat |= (reg & 0x1f ) << 5;//MII Reg
510
+ u16dat |= (option & 0x1 )<< 14;//Read or Write
511
+ u16dat |= 0x1 << 15;//Trigger & Write
512
+
513
+ Write_Reg(P3REG_PHYACCESS_CMD, u16dat);
514
+ while(_ReadRegBits(3, P3REG_PHYACCESS_CMD, 15, 1));
515
+ udelay(5000);
516
+
517
+ return Read_Reg(P3REG_PHYACCESS_DATA);
518
+
519
+}
520
+
521
+u16 _write_mii_register(u8 phy, u8 page, u8 reg, u16 val, u8 all)
522
+{
523
+ u8 option = MII_OP_WRITE;
524
+ u16 u16dat = 0;
525
+ u8 count = 0;
526
+ IP2Page(3);
527
+
528
+ // change phy page
529
+ do
530
+ {
531
+ Write_Reg(P3REG_PHYACCESS_DATA, page);
532
+
533
+ u16dat = ((phy+(count*8)) & 0x1f); //PHY
534
+ u16dat |= (0x14 & 0x1f ) << 5; //MII Reg
535
+ u16dat |= (MII_OP_WRITE & 0x1 )<< 14;//Read or Write
536
+ u16dat |= 0x1 << 15;//Trigger & Write
537
+
538
+ Write_Reg(P3REG_PHYACCESS_CMD, u16dat);
539
+ while(_ReadRegBits(3, P3REG_PHYACCESS_CMD, 15, 1));
540
+ udelay(5000);
541
+ count = count + 1;
542
+ }while(all&&(count<3));
543
+
544
+ // phy write command
545
+ Write_Reg(P3REG_PHYACCESS_DATA, val);
546
+ u16dat = 0;
547
+
548
+ u16dat = (phy & 0x1f); //PHY
549
+ u16dat |= (reg & 0x1f ) << 5; //MII Reg
550
+ u16dat |= (all & 0x1) << 10; // write to all 24 phy
551
+ u16dat |= (option & 0x1 )<< 14;//Read or Write
552
+ u16dat |= 0x1 << 15;//Trigger & Write
553
+
554
+ Write_Reg(P3REG_PHYACCESS_CMD, u16dat);
555
+ while(_ReadRegBits(3, P3REG_PHYACCESS_CMD, 15, 1));
556
+ if(all)
557
+ udelay(30000);
558
+ else
559
+ udelay(5000);
560
+
561
+ return 0;
562
+}
563
+
564
+int get_mii_reg(void *cdata, int len)
565
+{
566
+ u8 phy, page, reg;
567
+ u16 u16dat;
568
+
569
+ if (sizeof(struct PhySetting) != len)
570
+ return -EINVAL;
571
+
572
+ phy = ((struct PhySetting *)cdata) ->phy;
573
+ page = ((struct PhySetting *)cdata) ->page;
574
+ reg = ((struct PhySetting *)cdata) ->reg;
575
+
576
+ if (phy >= 0x20)
577
+ return -EINVAL;
578
+
579
+ if (page >= 0x20)
580
+ return -EINVAL;
581
+
582
+ if (reg >= 0x20)
583
+ return -EINVAL;
584
+
585
+ u16dat = _read_mii_register(phy, page, reg);
586
+ ((struct PhySetting *)cdata) ->val = (unsigned short)u16dat;
587
+
588
+ return 0;
589
+}
590
+
591
+int set_mii_reg(void *cdata, int len)
592
+{
593
+ u8 phy, page, reg, all;
594
+ u16 val;
595
+ u16 u16dat;
596
+
597
+ if (sizeof(struct PhySetting) != len)
598
+ return -EINVAL;
599
+
600
+ phy = ((struct PhySetting *)cdata) ->phy;
601
+ page = ((struct PhySetting *)cdata) ->page;
602
+ reg = ((struct PhySetting *)cdata) ->reg;
603
+ val = ((struct PhySetting *)cdata) ->val;
604
+ all = ((struct PhySetting *)cdata) ->all; // if the command is set 24 phy,bit=1
605
+
606
+ if (phy >= 0x20)
607
+ return -EINVAL;
608
+
609
+ if (page >= 0x20)
610
+ return -EINVAL;
611
+
612
+ if (reg >= 0x20)
613
+ return -EINVAL;
614
+
615
+ if (all >= 2)
616
+ return -EINVAL;
617
+
618
+ u16dat = _write_mii_register(phy, page, reg, val, all);
619
+
620
+ return 0;
621
+}
622
+
623
+#endif
624
+static int _setGeneralEnable(void *cdata, int len, u8 page, u16 reg, u8 offset)
625
+{
626
+ int gdata;
627
+
628
+ FUNC_MSG_IN;
629
+ if (sizeof(struct GeneralSetting) != len){
630
+ ip1811drv_err("Error: lengtn=%d\n", len);
631
+ return -EINVAL;
632
+ }
633
+
634
+ gdata = ((struct GeneralSetting *)cdata) ->gdata;
635
+ if( gdata != OP_FUNC_ENABLE && gdata != OP_FUNC_DISABLE ){
636
+ ip1811drv_err("Error: gdata=%X\n", gdata);
637
+ return -EINVAL;
638
+ }
639
+
640
+ ip1811drv_dbg("cdata ->gdata=%d\n", gdata);
641
+
642
+ _WriteRegBits(page, reg, offset, 1, gdata);
643
+
644
+ FUNC_MSG_OUT;
645
+ return 0;
646
+}
647
+
648
+static int _getGeneralEnable(void *cdata, int len, u8 page, u16 reg, u8 offset)
649
+{
650
+ FUNC_MSG_IN;
651
+ if (sizeof(struct GeneralSetting) != len){
652
+ ip1811drv_err("Error: lengtn=%d\n", len);
653
+ return -EINVAL;
654
+ }
655
+
656
+ ((struct GeneralSetting *)cdata) ->gdata = _ReadRegBits(page, reg, offset, 1);
657
+
658
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
659
+ FUNC_MSG_OUT;
660
+ return 0;
661
+}
662
+
663
+static int _setPortmapMask(void *cdata, int len, u8 page, u8 reg)
664
+{
665
+ unsigned long pm;
666
+ int pd;
667
+ u32 u32dat;
668
+
669
+ FUNC_MSG_IN;
670
+ if (sizeof(struct PortmapSetting) != len){
671
+ ip1811drv_err("Error: lengtn=%d\n", len);
672
+ return -EINVAL;
673
+ }
674
+
675
+ pm = ((struct PortmapSetting *)cdata) ->portmap;
676
+ pd = ((struct PortmapSetting *)cdata) ->pmdata;
677
+ if (pm & ~0x1FFFFFFF){
678
+ ip1811drv_err("Error: portmap=%08lX\n", pm);
679
+ return -EINVAL;
680
+ }
681
+ if (pd & ~0x1FFFFFFF){
682
+ ip1811drv_err("Error: pmdata=%X\n", pd);
683
+ return -EINVAL;
684
+ }
685
+
686
+ ip1811drv_dbg("portmap=0x%08lX\n", pm);
687
+ ip1811drv_dbg("portdata=0x%08X\n", pd);
688
+
689
+ IP2Page(page);
690
+ u32dat = (u32)Read_Reg(reg+1)<<16 | (u32)Read_Reg(reg);
691
+
692
+ u32dat &= ~pm;
693
+ u32dat |= pm & pd;
694
+
695
+ Write_Reg(reg, (u16)(u32dat & 0xFFFF));
696
+ Write_Reg(reg+1, (u16)(u32dat >> 16));
697
+
698
+ FUNC_MSG_OUT;
699
+ return 0;
700
+}
701
+
702
+static int _getPortmapMask(void *cdata, int len, u8 page, u8 reg)
703
+{
704
+ unsigned long pm;
705
+ u32 u32dat;
706
+
707
+ FUNC_MSG_IN;
708
+ if (sizeof(struct PortmapSetting) != len){
709
+ ip1811drv_err("Error: lengtn=%d\n", len);
710
+ return -EINVAL;
711
+ }
712
+
713
+ pm = ((struct PortmapSetting *)cdata) ->portmap;
714
+ if (pm & ~0x1FFFFFFF){
715
+ ip1811drv_err("Error: portmap=%08lX\n", pm);
716
+ return -EINVAL;
717
+ }
718
+
719
+ IP2Page(page);
720
+ u32dat = (u32)Read_Reg(reg+1)<<16 | (u32)Read_Reg(reg);
721
+ ((struct PortmapSetting *)cdata) ->pmdata = u32dat & pm;
722
+
723
+ ip1811drv_dbg("cdata ->portmap=0x%08lX\n", ((struct PortmapSetting *)cdata) ->portmap);
724
+ ip1811drv_dbg("cdata ->pmdata=0x%08X\n", ((struct PortmapSetting *)cdata) ->pmdata);
725
+ FUNC_MSG_OUT;
726
+ return 0;
727
+}
728
+
729
+
730
+static int _setPortmap(void *cdata, int len, u8 page, u8 reg)
731
+{
732
+ unsigned long pm;
733
+ int pd;
734
+ u16 u16dat;
735
+
736
+ FUNC_MSG_IN;
737
+ if (sizeof(struct PortmapSetting) != len) {
738
+ ip1811drv_err("Error: lengtn=%d\n", len);
739
+ return -EINVAL;
740
+ }
741
+
742
+ pm = ((struct PortmapSetting *)cdata) ->portmap;
743
+ pd = ((struct PortmapSetting *)cdata) ->pmdata;
744
+
745
+ if (pm & ~0xFFF) {
746
+ ip1811drv_err("Error: portmap=%08lX\n", pm);
747
+ return -EINVAL;
748
+ }
749
+ if ((pd != OP_FUNC_ENABLE) && (pd != OP_FUNC_DISABLE)) {
750
+ ip1811drv_err("Error: pd=%X\n", pd);
751
+ return -EINVAL;
752
+ }
753
+
754
+ ip1811drv_dbg("portmap=0x%08lX\n", pm);
755
+ ip1811drv_dbg("portdata=0x%X\n", pd);
756
+
757
+ IP2Page(page);
758
+ u16dat = Read_Reg(reg);
759
+
760
+#ifdef COMBINED_PORT
761
+ if ((pm >> 9) & 0x1)
762
+ pm |= (u16)(1 << 10);
763
+#endif
764
+
765
+ if (pd == OP_FUNC_ENABLE)
766
+ u16dat |= (u16)pm;
767
+ else//OP_FUNC_DISABLE
768
+ u16dat &= ~(u16)pm;
769
+
770
+ Write_Reg(reg, (u16dat & 0xFFF));
771
+
772
+ FUNC_MSG_OUT;
773
+ return 0;
774
+}
775
+
776
+static int _getPortmap(void *cdata, int len, u8 page, u8 reg)
777
+{
778
+ unsigned long pm;
779
+ u16 u16dat;
780
+
781
+ FUNC_MSG_IN;
782
+ if (sizeof(struct PortmapSetting) != len){
783
+ ip1811drv_err("Error: lengtn=%d\n", len);
784
+ return -EINVAL;
785
+ }
786
+ pm = ((struct PortmapSetting *)cdata) ->portmap;
787
+
788
+ if (pm & ~0xFFF){
789
+ ip1811drv_err("Error: portmap=%08lX\n", pm);
790
+ return -EINVAL;
791
+ }
792
+ IP2Page(page);
793
+ u16dat = Read_Reg(reg);
794
+ u16dat &= (u16)pm;
795
+ ((struct PortmapSetting *)cdata) ->pmdata = u16dat;
796
+
797
+ ip1811drv_dbg("cdata ->pmdata=0x%08X\n", ((struct PortmapSetting *)cdata) ->pmdata);
798
+ FUNC_MSG_OUT;
799
+ return 0;
800
+}
801
+
802
+
803
+//------------------------------------------------
804
+//common_smi
805
+int switchdSetPortAN(int port, int an)
806
+{
807
+ u16 u16dat;
808
+
809
+ if (port < 0 || port >= MAX_PHY_NUM)
810
+ return -EINVAL;
811
+ if ( !(an==OP_FUNC_DISABLE || an==OP_FUNC_ENABLE) )
812
+ return -EINVAL;
813
+ ip1811drv_dbg("port=%d\n", port);
814
+ ip1811drv_dbg("an=%d\n", an);
815
+
816
+ IP2Page(3);
817
+ u16dat = Read_Reg(P3REG_AN);
818
+ if (an == OP_FUNC_ENABLE)
819
+ u16dat |= (u16)(1 << port);
820
+ else
821
+ u16dat &= (u16)~(1 << port);
822
+#ifdef COMBINED_PORT
823
+ if (port==9){
824
+ if (an == OP_FUNC_ENABLE)
825
+ u16dat |= (u16)(1 << port+1);
826
+ else
827
+ u16dat &= (u16)~(1 << port+1);
828
+ }
829
+#endif
830
+ Write_Reg(P3REG_AN, u16dat & 0xFFFF);
831
+
832
+ return 0;
833
+}
834
+EXPORT_SYMBOL(switchdSetPortAN);
835
+int setPortAN(void *cdata, int len)
836
+{
837
+ int port, an;
838
+
839
+ ip1811drv_dbg("ip1811: +setPortAN...\n");
840
+ if (sizeof(struct ByPortSetting) != len)
841
+ return -EINVAL;
842
+
843
+ port=((struct ByPortSetting *)cdata) ->port;
844
+ an = ((struct ByPortSetting *)cdata) ->pdata;
845
+
846
+ if(switchdSetPortAN(port, an) != 0)
847
+ return -EINVAL;
848
+
849
+ ip1811drv_dbg("ip1811: -setPortAN...\n");
850
+ return 0;
851
+}
852
+
853
+int switchdGetPortAN(int port, int *ptrInt)
854
+{
855
+
856
+ if (port < 0 || port >= MAX_PHY_NUM)
857
+ return -EINVAL;
858
+ ip1811drv_dbg("port=%d\n", port);
859
+
860
+#ifdef COMBINED_PORT
861
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
862
+ port++;
863
+#endif
864
+ *ptrInt = _ReadRegBits(3, P3REG_PORTSTS0 + port/2,6+(port&0x1)*8 , 1);
865
+ ip1811drv_dbg("an=0x%x\n", *ptrInt);
866
+
867
+ return 0;
868
+}
869
+EXPORT_SYMBOL(switchdGetPortAN);
870
+int getPortAN(void *cdata, int len)
871
+{
872
+ int port, an;
873
+
874
+ ip1811drv_dbg("ip1811: +getPortAN...\n");
875
+ if (sizeof(struct ByPortSetting) != len)
876
+ return -EINVAL;
877
+
878
+ port = ((struct ByPortSetting *)cdata) ->port;
879
+
880
+ if(switchdGetPortAN(port, &an) != 0)
881
+ return -EINVAL;
882
+
883
+ ((struct ByPortSetting *)cdata) ->pdata = an;
884
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
885
+ ip1811drv_dbg("ip1811: -getPortAN...\n");
886
+ return 0;
887
+}
888
+
889
+int switchdSetPortSpeed(int port, int speed)
890
+{
891
+ u16 u16dat;
892
+
893
+ if (port < 0 || port >= MAX_PHY_NUM)
894
+ return -EINVAL;
895
+ if ( !(speed==OP_SMI_SPEED_10 || speed==OP_SMI_SPEED_100 ||
896
+ (speed==OP_SMI_SPEED_1000 && port>=8)) )
897
+ return -EINVAL;
898
+ ip1811drv_dbg("port=%d\n", port);
899
+ ip1811drv_dbg("speed=%d\n", speed);
900
+
901
+ IP2Page(3);
902
+ if (speed == OP_SMI_SPEED_1000)
903
+ {
904
+ u16dat = Read_Reg(P3REG_SPG);
905
+ u16dat |= (u16)(1 << (port-8));
906
+#ifdef COMBINED_PORT
907
+ if (port==9)
908
+ u16dat |= (u16)(1 << (port+1-8));
909
+#endif
910
+ Write_Reg(P3REG_SPG, u16dat);
911
+ }
912
+ else
913
+ {
914
+ if (port >= 8)
915
+ {
916
+ u16dat = Read_Reg(P3REG_SPG);
917
+ u16dat &= (u16)~(1 << (port-8));
918
+#ifdef COMBINED_PORT
919
+ if (port==9)
920
+ u16dat &= (u16)~(1 << (port+1-8));
921
+#endif
922
+ Write_Reg(P3REG_SPG, u16dat);
923
+ }
924
+
925
+ u16dat = (u16)( Read_Reg(P3REG_SP) );
926
+ if (speed == OP_SMI_SPEED_100)
927
+ u16dat |= (u16)(1 << port);
928
+ else
929
+ u16dat &= (u16)~(1 << port);
930
+#ifdef COMBINED_PORT
931
+ if (port==9){
932
+ if (speed == OP_SMI_SPEED_100)
933
+ u16dat |= (u16)(1 << port+1);
934
+ else
935
+ u16dat &= (u16)~(1 << port+1);
936
+ }
937
+#endif
938
+ Write_Reg(P3REG_SP, u16dat & 0xFFFF);
939
+ }
940
+
941
+ return 0;
942
+}
943
+EXPORT_SYMBOL(switchdSetPortSpeed);
944
+int setPortSpeed(void *cdata, int len)
945
+{
946
+ int port, speed;
947
+
948
+ ip1811drv_dbg("ip1811: +setPortSpeed...\n");
949
+ if (sizeof(struct ByPortSetting) != len)
950
+ return -EINVAL;
951
+
952
+ port = ((struct ByPortSetting *)cdata) ->port;
953
+ speed= ((struct ByPortSetting *)cdata) ->pdata;
954
+
955
+ if(switchdSetPortSpeed(port, speed) != 0)
956
+ return -EINVAL;
957
+ ip1811drv_dbg("ip1811: -setPortSpeed...\n");
958
+ return 0;
959
+}
960
+
961
+int switchdGetPortSpeed(int port, int *ptrInt)
962
+{
963
+ int speed;
964
+
965
+ if (port < 0 || port >= MAX_PHY_NUM)
966
+ return -EINVAL;
967
+ ip1811drv_dbg("port=%d\n", port);
968
+
969
+#ifdef COMBINED_PORT
970
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
971
+ port++;
972
+#endif
973
+ speed = (int) _ReadRegBits(3, P3REG_PORTSTS0 + port/2,1+(port&0x1)*8 , 2);
974
+ ip1811drv_dbg("speed=0x%x\n", speed);
975
+ if (speed & 0x2)
976
+ *ptrInt = OP_SMI_SPEED_1000;
977
+ else{
978
+ if (speed & 0x1)
979
+ *ptrInt = OP_SMI_SPEED_100;
980
+ else
981
+ *ptrInt = OP_SMI_SPEED_10;
982
+ }
983
+
984
+ return 0;
985
+}
986
+EXPORT_SYMBOL(switchdGetPortSpeed);
987
+int getPortSpeed(void *cdata, int len)
988
+{
989
+ int port, speed;
990
+
991
+ ip1811drv_dbg("ip1811: +getPortSpeed...\n");
992
+ if (sizeof(struct ByPortSetting) != len)
993
+ return -EINVAL;
994
+
995
+ port = ((struct ByPortSetting *)cdata) ->port;
996
+
997
+ if(switchdGetPortSpeed(port, &speed) != 0)
998
+ return -EINVAL;
999
+ ((struct ByPortSetting *)cdata) ->pdata = speed;
1000
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
1001
+ ip1811drv_dbg("ip1811: -getPortSpeed...\n");
1002
+ return 0;
1003
+}
1004
+
1005
+int switchdSetPortDuplex(int port, int dup)
1006
+{
1007
+ u16 u16dat;
1008
+
1009
+ if (port < 0 || port >= MAX_PHY_NUM)
1010
+ return -EINVAL;
1011
+ if ( !(dup==OP_SMI_DUPLEX_HALF || dup==OP_SMI_DUPLEX_FULL) )
1012
+ return -EINVAL;
1013
+ ip1811drv_dbg("port=%d\n", port);
1014
+ ip1811drv_dbg("dup=%d\n", dup);
1015
+
1016
+ IP2Page(3);
1017
+ u16dat = Read_Reg(P3REG_DUPLEX);
1018
+ if (dup == OP_SMI_DUPLEX_FULL)
1019
+ u16dat |= (u16)(1 << port);
1020
+ else
1021
+ u16dat &= (u16)~(1 << port);
1022
+#ifdef COMBINED_PORT
1023
+ if (port==9){
1024
+ if (dup == OP_SMI_DUPLEX_FULL)
1025
+ u16dat |= (u16)(1 << port+1);
1026
+ else
1027
+ u16dat &= (u16)~(1 << port+1);
1028
+ }
1029
+#endif
1030
+ Write_Reg(P3REG_DUPLEX, u16dat & 0xFFFF);
1031
+
1032
+ return 0;
1033
+}
1034
+EXPORT_SYMBOL(switchdSetPortDuplex);
1035
+int setPortDuplex(void *cdata, int len)
1036
+{
1037
+ int port, dup;
1038
+
1039
+ ip1811drv_dbg("ip1811: +setPortDuplex...\n");
1040
+ if (sizeof(struct ByPortSetting) != len)
1041
+ return -EINVAL;
1042
+
1043
+ port=((struct ByPortSetting *)cdata) ->port;
1044
+ dup =((struct ByPortSetting *)cdata) ->pdata;
1045
+
1046
+ if(switchdSetPortDuplex(port, dup) != 0)
1047
+ return -EINVAL;
1048
+
1049
+ ip1811drv_dbg("ip1811: -setPortDuplex...\n");
1050
+ return 0;
1051
+}
1052
+
1053
+int switchdGetPortDuplex(int port, int *ptrInt)
1054
+{
1055
+ if (port < 0 || port >= MAX_PHY_NUM)
1056
+ return -EINVAL;
1057
+ ip1811drv_dbg("port=%d\n", port);
1058
+
1059
+#ifdef COMBINED_PORT
1060
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
1061
+ port++;
1062
+#endif
1063
+ *ptrInt = (int) _ReadRegBits(3, P3REG_PORTSTS0 + port/2,(3+(port&0x1)*8), 1);
1064
+ ip1811drv_dbg("dup=0x%x\n", *ptrInt);
1065
+
1066
+ return 0;
1067
+}
1068
+EXPORT_SYMBOL(switchdGetPortDuplex);
1069
+int getPortDuplex(void *cdata, int len)
1070
+{
1071
+ int port, dup;
1072
+
1073
+ ip1811drv_dbg("ip1811: +getPortDuplex...\n");
1074
+ if (sizeof(struct ByPortSetting) != len)
1075
+ return -EINVAL;
1076
+
1077
+ port = ((struct ByPortSetting *)cdata) ->port;
1078
+
1079
+ if(switchdGetPortDuplex(port, &dup) != 0)
1080
+ return -EINVAL;
1081
+ ((struct ByPortSetting *)cdata) ->pdata = dup;
1082
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
1083
+ ip1811drv_dbg("ip1811: -getPortDuplex...\n");
1084
+ return 0;
1085
+}
1086
+
1087
+int switchdSetPortPause(int port, int ps)
1088
+{
1089
+ u16 u16dat;
1090
+
1091
+ if (port < 0 || port >= MAX_PHY_NUM)
1092
+ return -EINVAL;
1093
+ if ( !(ps==OP_FUNC_ENABLE || ps==OP_FUNC_DISABLE) )
1094
+ return -EINVAL;
1095
+ ip1811drv_dbg("port=%d\n", port);
1096
+ ip1811drv_dbg("ps=%d\n", ps);
1097
+
1098
+ IP2Page(3);
1099
+ u16dat = Read_Reg(P3REG_PAUSE);
1100
+ if (ps == OP_FUNC_ENABLE)
1101
+ u16dat |= (u16)(1 << port);
1102
+ else
1103
+ u16dat &= (u16)~(1 << port);
1104
+#ifdef COMBINED_PORT
1105
+ if (port==9){
1106
+ if (ps == OP_FUNC_ENABLE)
1107
+ u16dat |= (u16)(1 << port+1);
1108
+ else
1109
+ u16dat &= (u16)~(1 << port+1);
1110
+ }
1111
+#endif
1112
+ Write_Reg(P3REG_PAUSE, u16dat & 0xFFFF);
1113
+
1114
+ return 0;
1115
+}
1116
+EXPORT_SYMBOL(switchdSetPortPause);
1117
+int setPortPause(void *cdata, int len)
1118
+{
1119
+ int port, ps;
1120
+
1121
+ ip1811drv_dbg("ip1811: +setPortPause...\n");
1122
+ if (sizeof(struct ByPortSetting) != len)
1123
+ return -EINVAL;
1124
+
1125
+ port=((struct ByPortSetting *)cdata) ->port;
1126
+ ps = ((struct ByPortSetting *)cdata) ->pdata;
1127
+
1128
+ if(switchdSetPortPause(port, ps) != 0)
1129
+ return -EINVAL;
1130
+
1131
+ ip1811drv_dbg("ip1811: -setPortPause...\n");
1132
+ return 0;
1133
+}
1134
+
1135
+int switchdGetPortPause(int port, int *ptrInt)
1136
+{
1137
+ if (port < 0 || port >= MAX_PHY_NUM)
1138
+ return -EINVAL;
1139
+ ip1811drv_dbg("port=%d\n", port);
1140
+
1141
+#ifdef COMBINED_PORT
1142
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
1143
+ port++;
1144
+#endif
1145
+ *ptrInt = (int) _ReadRegBits(3, P3REG_PORTSTS0 + port/2,4+(port&0x1)*8 , 1);
1146
+ ip1811drv_dbg("ps=0x%x\n", *ptrInt);
1147
+
1148
+ return 0;
1149
+}
1150
+EXPORT_SYMBOL(switchdGetPortPause);
1151
+int getPortPause(void *cdata, int len)
1152
+{
1153
+ int port, ps;
1154
+
1155
+ ip1811drv_dbg("ip1811: +getPortPause...\n");
1156
+ if (sizeof(struct ByPortSetting) != len)
1157
+ return -EINVAL;
1158
+
1159
+ port = ((struct ByPortSetting *)cdata) ->port;
1160
+
1161
+ if(switchdGetPortPause(port, &ps) != 0)
1162
+ return -EINVAL;
1163
+ ((struct ByPortSetting *)cdata) ->pdata = ps;
1164
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
1165
+ ip1811drv_dbg("ip1811: -getPortPause...\n");
1166
+ return 0;
1167
+}
1168
+
1169
+int switchdSetPortAsymPause(int port, int aps)
1170
+{
1171
+ u16 u16dat;
1172
+
1173
+ if (port < 0 || port >= MAX_PHY_NUM)
1174
+ return -EINVAL;
1175
+ if ( !(aps==OP_FUNC_ENABLE || aps==OP_FUNC_DISABLE) )
1176
+ return -EINVAL;
1177
+ ip1811drv_dbg("port=%d\n", port);
1178
+ ip1811drv_dbg("aps=%d\n", aps);
1179
+
1180
+ IP2Page(3);
1181
+ u16dat = Read_Reg(P3REG_ASPAUSE);
1182
+ if (aps == OP_FUNC_ENABLE)
1183
+ u16dat |= (u16)(1 << port);
1184
+ else
1185
+ u16dat &= (u16)~(1 << port);
1186
+#ifdef COMBINED_PORT
1187
+ if (port==9){
1188
+ if (aps == OP_FUNC_ENABLE)
1189
+ u16dat |= (u16)(1 << port+1);
1190
+ else
1191
+ u16dat &= (u16)~(1 << port+1);
1192
+ }
1193
+#endif
1194
+ Write_Reg(P3REG_ASPAUSE, u16dat & 0xFFFF);
1195
+
1196
+ return 0;
1197
+}
1198
+EXPORT_SYMBOL(switchdSetPortAsymPause);
1199
+int setPortAsymPause(void *cdata, int len)
1200
+{
1201
+ int port, aps;
1202
+
1203
+ ip1811drv_dbg("ip1811: +setPortAsymPause...\n");
1204
+ if (sizeof(struct ByPortSetting) != len)
1205
+ return -EINVAL;
1206
+
1207
+ port=((struct ByPortSetting *)cdata) ->port;
1208
+ aps =((struct ByPortSetting *)cdata) ->pdata;
1209
+
1210
+ if(switchdSetPortAsymPause(port, aps) != 0)
1211
+ return -EINVAL;
1212
+
1213
+ ip1811drv_dbg("ip1811: -setPortAsymPause...\n");
1214
+ return 0;
1215
+}
1216
+
1217
+int switchdGetPortAsymPause(int port, int *ptrInt)
1218
+{
1219
+ if (port < 0 || port >= MAX_PHY_NUM)
1220
+ return -EINVAL;
1221
+ ip1811drv_dbg("port=%d\n", port);
1222
+
1223
+#ifdef COMBINED_PORT
1224
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
1225
+ port++;
1226
+#endif
1227
+ *ptrInt = (int) _ReadRegBits(3, P3REG_PORTSTS0 + port/2,5+(port&0x1)*8 , 1);
1228
+ ip1811drv_dbg("aps=0x%x\n", *ptrInt);
1229
+
1230
+ return 0;
1231
+}
1232
+EXPORT_SYMBOL(switchdGetPortAsymPause);
1233
+int getPortAsymPause(void *cdata, int len)
1234
+{
1235
+ int port, aps;
1236
+
1237
+ ip1811drv_dbg("ip1811: +getPortAsymPause...\n");
1238
+ if (sizeof(struct ByPortSetting) != len)
1239
+ return -EINVAL;
1240
+
1241
+ port = ((struct ByPortSetting *)cdata) ->port;
1242
+
1243
+ if(switchdGetPortAsymPause(port, &aps) != 0)
1244
+ return -EINVAL;
1245
+ ((struct ByPortSetting *)cdata) ->pdata = aps;
1246
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
1247
+ ip1811drv_dbg("ip1811: -getPortAsymPause...\n");
1248
+ return 0;
1249
+}
1250
+
1251
+int switchdSetPortLinkStatus(struct LinkStatusSetting *avg)
1252
+{
1253
+ int port, sp, dup, ps, asym, an;
1254
+ u16 u16dat;
1255
+
1256
+ port= avg->port;
1257
+ sp = avg->speed;
1258
+ dup = avg->duplex;
1259
+ ps = avg->pause;
1260
+ asym= avg->asym;
1261
+ an = avg->an;
1262
+ if (port < 0 || port >= MAX_PHY_NUM)
1263
+ return -EINVAL;
1264
+ if ( !(sp==OP_SMI_SPEED_10 || sp==OP_SMI_SPEED_100 || (sp==OP_SMI_SPEED_1000 && port>8)) )
1265
+ return -EINVAL;
1266
+ if ( !(dup==OP_SMI_DUPLEX_HALF || dup==OP_SMI_DUPLEX_FULL) )
1267
+ return -EINVAL;
1268
+ if ( !(ps==OP_FUNC_DISABLE || ps==OP_FUNC_ENABLE) )
1269
+ return -EINVAL;
1270
+ if ( !(asym==OP_FUNC_DISABLE || asym==OP_FUNC_ENABLE) )
1271
+ return -EINVAL;
1272
+ if ( !(an==OP_FUNC_DISABLE || an==OP_FUNC_ENABLE) )
1273
+ return -EINVAL;
1274
+ ip1811drv_dbg("port=%d\n", port);
1275
+ ip1811drv_dbg("sp=%d dup=%d ps=%d asym=%d an=%d\n",
1276
+ sp, dup, ps, asym, an);
1277
+
1278
+ IP2Page(3);
1279
+ if (sp == OP_SMI_SPEED_1000)
1280
+ {
1281
+ u16dat = Read_Reg(P3REG_SPG);
1282
+ u16dat |= (u16)(1 << (port-8));
1283
+#ifdef COMBINED_PORT
1284
+ if (port==9){
1285
+ u16dat |= (u16)(1 << (port+1-8));
1286
+ }
1287
+#endif
1288
+ Write_Reg(P3REG_SPG, u16dat);
1289
+ }
1290
+ else
1291
+ {
1292
+ if (port >= 8)
1293
+ {
1294
+ u16dat = Read_Reg(P3REG_SPG);
1295
+ u16dat &= (u16)~(1 << (port-8));
1296
+#ifdef COMBINED_PORT
1297
+ if (port==9){
1298
+ u16dat &= (u16)~(1 << (port+1-8));
1299
+ }
1300
+#endif
1301
+ Write_Reg(P3REG_SPG, u16dat);
1302
+ }
1303
+
1304
+ u16dat = Read_Reg(P3REG_SP);
1305
+ if (sp == OP_SMI_SPEED_100)
1306
+ u16dat |= (u16)(1 << port);
1307
+ else
1308
+ u16dat &= (u16)~(1 << port);
1309
+#ifdef COMBINED_PORT
1310
+ if (port==9){
1311
+ if (sp == OP_SMI_SPEED_100)
1312
+ u16dat |= (u16)(1 << port+1);
1313
+ else
1314
+ u16dat &= (u16)~(1 << port+1);
1315
+ }
1316
+#endif
1317
+ Write_Reg(P3REG_SP, u16dat & 0xFFFF);
1318
+ }
1319
+
1320
+ u16dat = Read_Reg(P3REG_DUPLEX);
1321
+ if (dup == OP_SMI_DUPLEX_FULL)
1322
+ u16dat |= (u16)(1 << port);
1323
+ else
1324
+ u16dat &= (u16)~(1 << port);
1325
+#ifdef COMBINED_PORT
1326
+ if (port==9){
1327
+ if (dup == OP_SMI_DUPLEX_FULL)
1328
+ u16dat |= (u16)(1 << port+1);
1329
+ else
1330
+ u16dat &= (u16)~(1 << port+1);
1331
+ }
1332
+#endif
1333
+ Write_Reg(P3REG_DUPLEX, u16dat & 0xFFFF);
1334
+
1335
+ u16dat = Read_Reg(P3REG_PAUSE);
1336
+ if (ps == OP_FUNC_ENABLE)
1337
+ u16dat |= (u16)(1 << port);
1338
+ else
1339
+ u16dat &= (u16)~(1 << port);
1340
+#ifdef COMBINED_PORT
1341
+ if (port==9){
1342
+ if (ps == OP_FUNC_ENABLE)
1343
+ u16dat |= (u16)(1 << port+1);
1344
+ else
1345
+ u16dat &= (u16)~(1 << port+1);
1346
+ }
1347
+#endif
1348
+ Write_Reg(P3REG_PAUSE, u16dat & 0xFFFF);
1349
+
1350
+ u16dat = Read_Reg(P3REG_ASPAUSE);
1351
+ if (asym == OP_FUNC_ENABLE)
1352
+ u16dat |= (u16)(1 << port);
1353
+ else
1354
+ u16dat &= (u16)~(1 << port);
1355
+#ifdef COMBINED_PORT
1356
+ if (port==9){
1357
+ if (asym == OP_FUNC_ENABLE)
1358
+ u16dat |= (u16)(1 << port+1);
1359
+ else
1360
+ u16dat &= (u16)~(1 << port+1);
1361
+ }
1362
+#endif
1363
+ Write_Reg(P3REG_ASPAUSE, u16dat & 0xFFFF);
1364
+
1365
+ u16dat = Read_Reg(P3REG_AN);
1366
+ if (an == OP_FUNC_ENABLE)
1367
+ u16dat |= (u16)(1 << port);
1368
+ else
1369
+ u16dat &= (u16)~(1 << port);
1370
+#ifdef COMBINED_PORT
1371
+ if (port==9){
1372
+ if (an == OP_FUNC_ENABLE)
1373
+ u16dat |= (u16)(1 << port+1);
1374
+ else
1375
+ u16dat &= (u16)~(1 << port+1);
1376
+ }
1377
+#endif
1378
+ Write_Reg(P3REG_AN, u16dat & 0xFFFF);
1379
+
1380
+ return 0;
1381
+}
1382
+EXPORT_SYMBOL(switchdSetPortLinkStatus);
1383
+int setPortLinkStatus(void *cdata, int len)
1384
+{
1385
+ int port, sp, dup, ps, asym, an;
1386
+ u16 u16dat;
1387
+ struct LinkStatusSetting *avg = (struct LinkStatusSetting *)cdata;
1388
+
1389
+ ip1811drv_dbg("ip1811: +setPortLinkStatus...\n");
1390
+ if (sizeof(struct LinkStatusSetting) != len)
1391
+ return -EINVAL;
1392
+
1393
+ if(switchdSetPortLinkStatus(avg) != 0)
1394
+ return -EINVAL;
1395
+
1396
+ ip1811drv_dbg("ip1811: -setPortLinkStatus...\n");
1397
+ return 0;
1398
+}
1399
+
1400
+int switchdGetPortLinkStatus(struct LinkStatusSetting *cdata)
1401
+{
1402
+ int port, link, sp, dup, ps, asym, an, fiber;
1403
+ u8 u8dat;
1404
+ u16 u16dat;
1405
+
1406
+ port = ((struct LinkStatusSetting *)cdata) ->port;
1407
+ if (port < 0 || port >= MAX_PHY_NUM)
1408
+ return -EINVAL;
1409
+ ip1811drv_dbg("port=%d\n", port);
1410
+
1411
+#ifdef COMBINED_PORT
1412
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
1413
+ port++;
1414
+#endif
1415
+ IP2Page(3);
1416
+ u8dat = P3REG_PORTSTS0 + port/2;
1417
+ u16dat = Read_Reg(u8dat);
1418
+ ip1811drv_dbg("u16dat=0x%04x\n", u16dat);
1419
+ link=(int)( ( u16dat >> (0+(port&0x1)*8) ) & 0x1 );
1420
+ sp = (int)( ( u16dat >> (1+(port&0x1)*8) ) & 0x3 );
1421
+ if (sp & 0x2) sp = OP_SMI_SPEED_1000;
1422
+ else
1423
+ {
1424
+ if (sp & 0x1) sp = OP_SMI_SPEED_100;
1425
+ else sp = OP_SMI_SPEED_10;
1426
+ }
1427
+ dup =(int)( ( u16dat >> (3+(port&0x1)*8) ) & 0x1 );
1428
+ ps = (int)( ( u16dat >> (4+(port&0x1)*8) ) & 0x1 );
1429
+ asym=(int)( ( u16dat >> (5+(port&0x1)*8) ) & 0x1 );
1430
+ an = (int)( ( u16dat >> (6+(port&0x1)*8) ) & 0x1 );
1431
+ fiber = (int)( ( u16dat >> (7+(port&0x1)*8) ) & 0x1 );
1432
+ ip1811drv_dbg("link=0x%x sp=%d dup=0x%x ps=0x%x asym=0x%x an=0x%x fiber=0x%x\n",
1433
+ link, sp, dup, ps, asym, an, fiber);
1434
+ ((struct LinkStatusSetting *)cdata) ->link = link;
1435
+ ((struct LinkStatusSetting *)cdata) ->speed = sp;
1436
+ ((struct LinkStatusSetting *)cdata) ->duplex = dup;
1437
+ ((struct LinkStatusSetting *)cdata) ->pause = ps;
1438
+ ((struct LinkStatusSetting *)cdata) ->asym = asym;
1439
+ ((struct LinkStatusSetting *)cdata) ->an = an;
1440
+ ((struct LinkStatusSetting *)cdata) ->fiber = fiber;
1441
+ ip1811drv_dbg("cdata ->link=%d\n", ((struct LinkStatusSetting *)cdata) ->link);
1442
+ ip1811drv_dbg("cdata ->speed=%d\n", ((struct LinkStatusSetting *)cdata) ->speed);
1443
+ ip1811drv_dbg("cdata ->duplex=%d\n", ((struct LinkStatusSetting *)cdata) ->duplex);
1444
+ ip1811drv_dbg("cdata ->pause=%d\n", ((struct LinkStatusSetting *)cdata) ->pause);
1445
+ ip1811drv_dbg("cdata ->asym=%d\n", ((struct LinkStatusSetting *)cdata) ->asym);
1446
+ ip1811drv_dbg("cdata ->an=%d\n", ((struct LinkStatusSetting *)cdata) ->an);
1447
+ ip1811drv_dbg("cdata ->fiber=%d\n", ((struct LinkStatusSetting *)cdata) ->fiber);
1448
+
1449
+ return 0;
1450
+}
1451
+EXPORT_SYMBOL(switchdGetPortLinkStatus);
1452
+int getPortLinkStatus(void *cdata, int len)
1453
+{
1454
+ struct LinkStatusSetting *avg = (struct LinkStatusSetting *)cdata;
1455
+
1456
+ ip1811drv_dbg("ip1811: +getPortLinkStatus...\n");
1457
+ if (sizeof(struct LinkStatusSetting) != len)
1458
+ return -EINVAL;
1459
+
1460
+ if(switchdGetPortLinkStatus(avg) != 0)
1461
+ return -EINVAL;
1462
+
1463
+ ip1811drv_dbg("ip1811: -getPortLinkStatus...\n");
1464
+ return 0;
1465
+}
1466
+
1467
+int switchdSetPortBackpressure(int port, int bp)
1468
+{
1469
+ u16 u16dat;
1470
+
1471
+ if (port < 0 || port >= MAX_PHY_NUM)
1472
+ return -EINVAL;
1473
+ if ( !(bp==OP_FUNC_ENABLE || bp==OP_FUNC_DISABLE) )
1474
+ return -EINVAL;
1475
+ ip1811drv_dbg("port=%d\n", port);
1476
+ ip1811drv_dbg("bp=%d\n", bp);
1477
+
1478
+ IP2Page(3);
1479
+ u16dat = Read_Reg(P3REG_BPRESS);
1480
+ if (bp == OP_FUNC_ENABLE)
1481
+ u16dat |= (u16)(1 << port);
1482
+ else
1483
+ u16dat &= (u16)~(1 << port);
1484
+#ifdef COMBINED_PORT
1485
+ if (port==9){
1486
+ if (bp == OP_FUNC_ENABLE)
1487
+ u16dat |= (u16)(1 << port+1);
1488
+ else
1489
+ u16dat &= (u16)~(1 << port+1);
1490
+ }
1491
+#endif
1492
+ Write_Reg(P3REG_BPRESS, u16dat & 0xFFFF);
1493
+
1494
+ return 0;
1495
+}
1496
+EXPORT_SYMBOL(switchdSetPortBackpressure);
1497
+int setPortBackpressure(void *cdata, int len)
1498
+{
1499
+ int port, bp;
1500
+
1501
+ ip1811drv_dbg("ip1811: +setPortBackpressure...\n");
1502
+ if (sizeof(struct ByPortSetting) != len)
1503
+ return -EINVAL;
1504
+
1505
+ port=((struct ByPortSetting *)cdata) ->port;
1506
+ bp = ((struct ByPortSetting *)cdata) ->pdata;
1507
+
1508
+ if(switchdSetPortBackpressure(port, bp) != 0)
1509
+ return -EINVAL;
1510
+
1511
+ ip1811drv_dbg("ip1811: -setPortBackpressure...\n");
1512
+ return 0;
1513
+}
1514
+
1515
+int switchdGetPortBackpressure(int port, int *ptrInt)
1516
+{
1517
+ if (port < 0 || port >= MAX_PHY_NUM)
1518
+ return -EINVAL;
1519
+ ip1811drv_dbg("port=%d\n", port);
1520
+
1521
+#ifdef COMBINED_PORT
1522
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
1523
+ port++;
1524
+#endif
1525
+ *ptrInt = (int)_ReadRegBits(3, P3REG_BPRESS + port/16, port%16, 1);
1526
+ ip1811drv_dbg("bp=0x%x\n", *ptrInt);
1527
+
1528
+ return 0;
1529
+}
1530
+EXPORT_SYMBOL(switchdGetPortBackpressure);
1531
+int getPortBackpressure(void *cdata, int len)
1532
+{
1533
+ int port, bp;
1534
+
1535
+ ip1811drv_dbg("ip1811: +getPortBackpressure...\n");
1536
+ if (sizeof(struct ByPortSetting) != len)
1537
+ return -EINVAL;
1538
+
1539
+ port = ((struct ByPortSetting *)cdata) ->port;
1540
+
1541
+ if(switchdGetPortBackpressure(port, &bp) != 0)
1542
+ return -EINVAL;
1543
+ ((struct ByPortSetting *)cdata) ->pdata = bp;
1544
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
1545
+ ip1811drv_dbg("ip1811: -getPortBackpressure...\n");
1546
+ return 0;
1547
+}
1548
+
1549
+int switchdSetPortPowerDown(int port, int pd)
1550
+{
1551
+ u16 u16dat;
1552
+
1553
+ if (port < 0 || port >= MAX_PHY_NUM)
1554
+ return -EINVAL;
1555
+ if ( !(pd==OP_FUNC_ENABLE || pd==OP_FUNC_DISABLE) )
1556
+ return -EINVAL;
1557
+ ip1811drv_dbg("port=%d\n", port);
1558
+ ip1811drv_dbg("pd=%d\n", pd);
1559
+
1560
+ IP2Page(3);
1561
+ u16dat = Read_Reg(P3REG_POWERDOWN);
1562
+ if (pd == OP_FUNC_ENABLE)
1563
+ u16dat |= (u16)(1 << port);
1564
+ else
1565
+ u16dat &= (u16)~(1 << port);
1566
+ Write_Reg(P3REG_POWERDOWN, u16dat & 0xFFFF);
1567
+
1568
+ return 0;
1569
+}
1570
+EXPORT_SYMBOL(switchdSetPortPowerDown);
1571
+int setPortPowerDown(void *cdata, int len)
1572
+{
1573
+ int port, pd;
1574
+
1575
+ ip1811drv_dbg("ip1811: +setPortPowerDown...\n");
1576
+ if (sizeof(struct ByPortSetting) != len)
1577
+ return -EINVAL;
1578
+
1579
+ port=((struct ByPortSetting *)cdata) ->port;
1580
+ pd = ((struct ByPortSetting *)cdata) ->pdata;
1581
+
1582
+ if(switchdSetPortPowerDown(port, pd) != 0)
1583
+ return -EINVAL;
1584
+
1585
+ ip1811drv_dbg("ip1811: -setPortPowerDown...\n");
1586
+ return 0;
1587
+}
1588
+
1589
+int switchdGetPortPowerDown(int port, int *ptrInt)
1590
+{
1591
+ if (port < 0 || port >= MAX_PHY_NUM)
1592
+ return -EINVAL;
1593
+ ip1811drv_dbg("port=%d\n", port);
1594
+
1595
+ *ptrInt = (int)_ReadRegBits(3, P3REG_POWERDOWN + port/16, port%16, 1);
1596
+ ip1811drv_dbg("pd=0x%x\n", *ptrInt);
1597
+
1598
+ return 0;
1599
+}
1600
+EXPORT_SYMBOL(switchdGetPortPowerDown);
1601
+int getPortPowerDown(void *cdata, int len)
1602
+{
1603
+ int port, pd;
1604
+
1605
+ ip1811drv_dbg("ip1811: +getPortPowerDown...\n");
1606
+ if (sizeof(struct ByPortSetting) != len)
1607
+ return -EINVAL;
1608
+
1609
+ port = ((struct ByPortSetting *)cdata) ->port;
1610
+
1611
+ if(switchdGetPortPowerDown(port, &pd) != 0)
1612
+ return -EINVAL;
1613
+ ((struct ByPortSetting *)cdata) ->pdata = pd;
1614
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
1615
+ ip1811drv_dbg("ip1811: -getPortPowerDown...\n");
1616
+ return 0;
1617
+}
1618
+
1619
+int switchdSetPortForceLink(int port, int fl)
1620
+{
1621
+ u16 u16dat;
1622
+
1623
+ if (port < 0 || port >= MAX_PHY_NUM)
1624
+ return -EINVAL;
1625
+ if ( !(fl==OP_FUNC_ENABLE || fl==OP_FUNC_DISABLE) )
1626
+ return -EINVAL;
1627
+ ip1811drv_dbg("port=%d\n", port);
1628
+ ip1811drv_dbg("fl=%d\n", fl);
1629
+
1630
+ IP2Page(3);
1631
+ u16dat = Read_Reg(P3REG_FORCELINK);
1632
+ if (fl == OP_FUNC_ENABLE)
1633
+ u16dat |= (u16)(1 << port);
1634
+ else
1635
+ u16dat &= (u16)~(1 << port);
1636
+#ifdef COMBINED_PORT
1637
+ if (port==9){
1638
+ if (fl == OP_FUNC_ENABLE)
1639
+ u16dat |= (u16)(1 << port+1);
1640
+ else
1641
+ u16dat &= (u16)~(1 << port+1);
1642
+ }
1643
+#endif
1644
+ Write_Reg(P3REG_FORCELINK, u16dat & 0xFFFF);
1645
+
1646
+ return 0;
1647
+}
1648
+EXPORT_SYMBOL(switchdSetPortForceLink);
1649
+int setPortForceLink(void *cdata, int len)
1650
+{
1651
+ int port, fl;
1652
+
1653
+ ip1811drv_dbg("ip1811: +setPortForceLink...\n");
1654
+ if (sizeof(struct ByPortSetting) != len)
1655
+ return -EINVAL;
1656
+
1657
+ port=((struct ByPortSetting *)cdata) ->port;
1658
+ fl = ((struct ByPortSetting *)cdata) ->pdata;
1659
+
1660
+ if(switchdSetPortForceLink(port, fl) != 0)
1661
+ return -EINVAL;
1662
+
1663
+ ip1811drv_dbg("ip1811: -setPortForceLink...\n");
1664
+ return 0;
1665
+}
1666
+
1667
+int switchdGetPortForceLink(int port, int *ptrInt)
1668
+{
1669
+ if (port < 0 || port >= MAX_PHY_NUM)
1670
+ return -EINVAL;
1671
+ ip1811drv_dbg("port=%d\n", port);
1672
+
1673
+#ifdef COMBINED_PORT
1674
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
1675
+ port++;
1676
+#endif
1677
+ *ptrInt = (int)_ReadRegBits(3, P3REG_FORCELINK + port/16, port%16, 1);
1678
+ ip1811drv_dbg("fl=0x%x\n", *ptrInt);
1679
+
1680
+ return 0;
1681
+}
1682
+EXPORT_SYMBOL(switchdGetPortForceLink);
1683
+int getPortForceLink(void *cdata, int len)
1684
+{
1685
+ int port, fl;
1686
+
1687
+ ip1811drv_dbg("ip1811: +getPortForceLink...\n");
1688
+ if (sizeof(struct ByPortSetting) != len)
1689
+ return -EINVAL;
1690
+
1691
+ port = ((struct ByPortSetting *)cdata) ->port;
1692
+
1693
+ if(switchdGetPortForceLink(port, &fl) != 0)
1694
+ return -EINVAL;
1695
+ ((struct ByPortSetting *)cdata) ->pdata = fl;
1696
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
1697
+ ip1811drv_dbg("ip1811: -getPortForceLink...\n");
1698
+ return 0;
1699
+}
1700
+
1701
+int switchdSetPortUniDirection(int port, int uni)
1702
+{
1703
+ u16 u16dat;
1704
+
1705
+ if (port < 0 || port >= MAX_PHY_NUM)
1706
+ return -EINVAL;
1707
+ if ( !(uni==OP_FUNC_ENABLE || uni==OP_FUNC_DISABLE) )
1708
+ return -EINVAL;
1709
+ ip1811drv_dbg("port=%d\n", port);
1710
+ ip1811drv_dbg("uni=%d\n", uni);
1711
+
1712
+ IP2Page(3);
1713
+ u16dat = Read_Reg(P3REG_UNIDIRECT);
1714
+ if (uni == OP_FUNC_ENABLE)
1715
+ u16dat |= (u16)(1 << port);
1716
+ else
1717
+ u16dat &= (u16)~(1 << port);
1718
+#ifdef COMBINED_PORT
1719
+ if (port==9){
1720
+ if (uni == OP_FUNC_ENABLE)
1721
+ u16dat |= (u16)(1 << port+1);
1722
+ else
1723
+ u16dat &= (u16)~(1 << port+1);
1724
+ }
1725
+#endif
1726
+ Write_Reg(P3REG_UNIDIRECT, u16dat & 0xFFFF);
1727
+
1728
+ return 0;
1729
+}
1730
+EXPORT_SYMBOL(switchdSetPortUniDirection);
1731
+int setPortUniDirection(void *cdata, int len)
1732
+{
1733
+ int port, uni;
1734
+
1735
+ ip1811drv_dbg("ip1811: +setPortUniDirection...\n");
1736
+ if (sizeof(struct ByPortSetting) != len)
1737
+ return -EINVAL;
1738
+
1739
+ port=((struct ByPortSetting *)cdata) ->port;
1740
+ uni =((struct ByPortSetting *)cdata) ->pdata;
1741
+
1742
+ if(switchdSetPortUniDirection(port, uni) != 0)
1743
+ return -EINVAL;
1744
+
1745
+ ip1811drv_dbg("ip1811: -setPortUniDirection...\n");
1746
+ return 0;
1747
+}
1748
+
1749
+int switchdGetPortUniDirection(int port, int *ptrInt)
1750
+{
1751
+ if (port < 0 || port >= MAX_PHY_NUM)
1752
+ return -EINVAL;
1753
+ ip1811drv_dbg("port=%d\n", port);
1754
+
1755
+#ifdef COMBINED_PORT
1756
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
1757
+ port++;
1758
+#endif
1759
+ *ptrInt = (int)_ReadRegBits(3, P3REG_UNIDIRECT + port/16, (port-1)%16, 1);
1760
+ ip1811drv_dbg("uni=0x%x\n", *ptrInt);
1761
+
1762
+ return 0;
1763
+}
1764
+EXPORT_SYMBOL(switchdGetPortUniDirection);
1765
+int getPortUniDirection(void *cdata, int len)
1766
+{
1767
+ int port, uni;
1768
+
1769
+ ip1811drv_dbg("ip1811: +getPortUniDirection...\n");
1770
+ if (sizeof(struct ByPortSetting) != len)
1771
+ return -EINVAL;
1772
+
1773
+ port = ((struct ByPortSetting *)cdata) ->port;
1774
+
1775
+ if(switchdGetPortUniDirection(port, &uni) != 0)
1776
+ return -EINVAL;
1777
+ ((struct ByPortSetting *)cdata) ->pdata = uni;
1778
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
1779
+ ip1811drv_dbg("ip1811: -getPortUniDirection...\n");
1780
+ return 0;
1781
+}
1782
+
1783
+//------------------------------------------------
1784
+//common_cap
1785
+int switchdSetL2CapAct(int ptcl, int act)
1786
+{
1787
+ u32 u32dat, mask;
1788
+
1789
+ if (ptcl < OP_CAP_PTCL_BPDU || ptcl > OP_CAP_PTCL_GRP3)
1790
+ return -EINVAL;
1791
+ if (act!=OP_CAP_ACT_FORWARD && act!=OP_CAP_ACT_TO_CPU && act!=OP_CAP_ACT_DROP)
1792
+ return -EINVAL;
1793
+ ip1811drv_dbg("ptcl=%d\n", ptcl);
1794
+ ip1811drv_dbg("act=%d\n", act);
1795
+
1796
+ IP2Page(0);
1797
+ u32dat = ( Read_Reg(P0REG_L2FRAMEGETCTRL1) << 16 | Read_Reg(P0REG_L2FRAMEGETCTRL) );
1798
+ mask = (u32)~(0x3 << (ptcl*2));
1799
+ u32dat &= mask;
1800
+ u32dat |= (u32)(act << (ptcl*2));
1801
+ Write_Reg(P0REG_L2FRAMEGETCTRL, (u16)(u32dat & 0xFFFF));
1802
+ Write_Reg(P0REG_L2FRAMEGETCTRL1, (u16)(u32dat >> 16));
1803
+
1804
+ return 0;
1805
+}
1806
+EXPORT_SYMBOL(switchdSetL2CapAct);
1807
+int setL2CapAct(void *cdata, int len)
1808
+{
1809
+ int ptcl, act;
1810
+
1811
+ ip1811drv_dbg("ip1811: +setL2CapAct...\n");
1812
+ if (sizeof(struct CapActSetting) != len)
1813
+ return -EINVAL;
1814
+
1815
+ ptcl= ((struct CapActSetting *)cdata) ->protocol;
1816
+ act = ((struct CapActSetting *)cdata) ->act;
1817
+
1818
+ if(switchdSetL2CapAct(ptcl, act) != 0)
1819
+ return -EINVAL;
1820
+
1821
+ ip1811drv_dbg("ip1811: -setL2CapAct...\n");
1822
+ return 0;
1823
+}
1824
+
1825
+int switchdSetCapInBand(int gdata)
1826
+{
1827
+ if( gdata != OP_CAP_ACT_TO_CPU && gdata != OP_CAP_ACT_DROP ){
1828
+ ip1811drv_err("Error: gdata=%X\n", gdata);
1829
+ return -EINVAL;
1830
+ }
1831
+
1832
+ ip1811drv_dbg("cdata ->gdata=%d\n", gdata);
1833
+
1834
+ _WriteRegBits(0, P0REG_MACBEHAVIOR, 6, 1, (gdata==OP_CAP_ACT_TO_CPU?0x1:0x0));
1835
+
1836
+ return 0;
1837
+}
1838
+EXPORT_SYMBOL(switchdSetCapInBand);
1839
+int setCapInBand(void *cdata, int len)
1840
+{
1841
+ int gdata;
1842
+
1843
+ FUNC_MSG_IN;
1844
+ if (sizeof(struct GeneralSetting) != len){
1845
+ ip1811drv_err("Error: lengtn=%d\n", len);
1846
+ return -EINVAL;
1847
+ }
1848
+ gdata = ((struct GeneralSetting *)cdata) ->gdata;
1849
+
1850
+ if(switchdSetCapInBand(gdata) != 0)
1851
+ return -EINVAL;
1852
+
1853
+ FUNC_MSG_OUT;
1854
+ return 0;
1855
+}
1856
+
1857
+void switchdSetCapSwitchMac(unsigned char * mac)
1858
+{
1859
+ int i;
1860
+ u16 u16dat;
1861
+
1862
+ for(i=0; i<6; i++)
1863
+ ip1811drv_dbg("cdata ->mac[%d]=%X\n", i, mac[i]);
1864
+ IP2Page(0);
1865
+ for(i=0; i<3; i++){
1866
+ u16dat = ((((u16)mac[i*2])&0xFF)<<8) | (((u16)mac[i*2+1])&0xFF);
1867
+ Write_Reg(P0REG_MACADDRESS+(2-i), u16dat);
1868
+ }
1869
+}
1870
+EXPORT_SYMBOL(switchdSetCapSwitchMac);
1871
+int setCapSwitchMac(void *cdata, int len)
1872
+{
1873
+ char mac[6];
1874
+
1875
+ FUNC_MSG_IN;
1876
+ if (sizeof(struct MACSetting) != len){
1877
+ ip1811drv_err("Error: lengtn=%d\n", len);
1878
+ return -EINVAL;
1879
+ }
1880
+ memcpy(mac, ((struct MACSetting *)cdata) ->mac, 6);
1881
+
1882
+ switchdSetCapSwitchMac(mac);
1883
+
1884
+ FUNC_MSG_OUT;
1885
+ return 0;
1886
+}
1887
+
1888
+int switchdSetCapIpv6TcpUdpEnable(int enable)
1889
+{
1890
+ if(enable!=OP_FUNC_ENABLE && enable!=OP_FUNC_DISABLE) {
1891
+ ip1811drv_err("Error: enable=%X\n", enable);
1892
+ return -EINVAL;
1893
+ }
1894
+
1895
+ ip1811drv_dbg("enable=%d\n", enable);
1896
+
1897
+ _WriteRegBits(0, P0REG_IPV6RLTCFG, 0, 1, enable);
1898
+ return 0;
1899
+}
1900
+EXPORT_SYMBOL(switchdSetCapIpv6TcpUdpEnable);
1901
+int setCapIpv6TcpUdpEnable(void *cdata, int len)
1902
+{
1903
+ int ret, en;
1904
+ FUNC_MSG_IN;
1905
+ if (sizeof(struct GeneralSetting) != len){
1906
+ ip1811drv_err("Error: lengtn=%d\n", len);
1907
+ return -EINVAL;
1908
+ }
1909
+ en = ((struct GeneralSetting *)cdata) ->gdata;
1910
+
1911
+ ret = switchdSetCapIpv6TcpUdpEnable(en);
1912
+ FUNC_MSG_OUT;
1913
+ return ret;
1914
+}
1915
+
1916
+//------------------------------------------------
1917
+//common_lut
1918
+int switchdSetSMACLearning(int port, int en)
1919
+{
1920
+ u32 u32dat;
1921
+
1922
+ if (port < 0 || port >= MAX_PHY_NUM)
1923
+ return -EINVAL;
1924
+ if ( !(en==OP_FUNC_DISABLE || en==OP_FUNC_ENABLE) )
1925
+ return -EINVAL;
1926
+ ip1811drv_dbg("port=%d\n", port);
1927
+ ip1811drv_dbg("en=%d\n", en);
1928
+
1929
+ IP2Page(1);
1930
+ u32dat = (u32)Read_Reg(P1REG_SRCLEARN_ENABLE);
1931
+ if (en == OP_FUNC_ENABLE)
1932
+ u32dat |= (u32)(1 << port);
1933
+ else
1934
+ u32dat &= (u32)~(1 << port);
1935
+#ifdef COMBINED_PORT
1936
+ if (port==9){
1937
+ if (en == OP_FUNC_ENABLE)
1938
+ u32dat |= (u32)(1 << port+1);
1939
+ else
1940
+ u32dat &= (u32)~(1 << port+1);
1941
+ }
1942
+#endif
1943
+ Write_Reg(P1REG_SRCLEARN_ENABLE, (u32dat & 0xFFF));
1944
+
1945
+ return 0;
1946
+}
1947
+EXPORT_SYMBOL(switchdSetSMACLearning);
1948
+int setSMACLearning(void *cdata, int len)
1949
+{
1950
+ int port, en;
1951
+
1952
+ ip1811drv_dbg("ip1811: +setSMACLearning...\n");
1953
+ if (sizeof(struct ByPortSetting) != len)
1954
+ return -EINVAL;
1955
+
1956
+ port=((struct ByPortSetting *)cdata) ->port;
1957
+ en = ((struct ByPortSetting *)cdata) ->pdata;
1958
+
1959
+ if(switchdSetSMACLearning(port, en) != 0)
1960
+ return -EINVAL;
1961
+
1962
+ ip1811drv_dbg("ip1811: -setSMACLearning...\n");
1963
+ return 0;
1964
+}
1965
+
1966
+int switchdGetSMACLearning(int port, int *ptrInt)
1967
+{
1968
+ if (port < 0 || port >= MAX_PHY_NUM)
1969
+ return -EINVAL;
1970
+ ip1811drv_dbg("port=%d\n", port);
1971
+
1972
+#ifdef COMBINED_PORT
1973
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
1974
+ port++;
1975
+#endif
1976
+ *ptrInt = (int)_ReadRegBits(1, P1REG_SRCLEARN_ENABLE, port, 1);
1977
+
1978
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
1979
+
1980
+ return 0;
1981
+}
1982
+EXPORT_SYMBOL(switchdGetSMACLearning);
1983
+int getSMACLearning(void *cdata, int len)
1984
+{
1985
+ int port, en;
1986
+
1987
+ ip1811drv_dbg("ip1811: +getSMACLearning...\n");
1988
+ if (sizeof(struct ByPortSetting) != len)
1989
+ return -EINVAL;
1990
+
1991
+ port = ((struct ByPortSetting *)cdata) ->port;
1992
+
1993
+ if(switchdGetSMACLearning(port, &en) != 0)
1994
+ return -EINVAL;
1995
+
1996
+ ((struct ByPortSetting *)cdata) ->pdata = en;
1997
+
1998
+ ip1811drv_dbg("ip1811: -getSMACLearning...\n");
1999
+ return 0;
2000
+}
2001
+
2002
+int switchdSetLutPortFlush(unsigned long pm, int en)
2003
+{
2004
+ u16 u16dat;
2005
+
2006
+ if (pm & 0xF000)
2007
+ return -EINVAL;
2008
+ if ( en != OP_LUT_FLUSH_DYNAMIC_ONLY &&
2009
+ en != OP_LUT_FLUSH_STATIC_ONLY &&
2010
+ en != OP_LUT_FLUSH_ALL )
2011
+ return -EINVAL;
2012
+ ip1811drv_dbg("pm=0x%04x\n", (u16)pm);
2013
+ ip1811drv_dbg("en=%d\n", en);
2014
+
2015
+ /* start to flush LUT */
2016
+ IP2Page(1);
2017
+ u16dat = 0x80;
2018
+ if (en == OP_LUT_FLUSH_ALL)
2019
+ u16dat |= (u16)0x40; // flush static entries
2020
+ Write_Reg(P1REG_PORTFLUSH, (u16)(pm & 0x0FFF));
2021
+ Write_Reg(P1REG_LUTFLUSH_CFG, u16dat);
2022
+ udelay(10000);//flush LUT needs waiting at least 4 ms
2023
+
2024
+ return 0;
2025
+}
2026
+EXPORT_SYMBOL(switchdSetLutPortFlush);
2027
+int setLutPortFlush(void *cdata, int len)
2028
+{
2029
+ unsigned long pm;
2030
+ int en;
2031
+
2032
+ ip1811drv_dbg("ip1811: +setLutPortFlush...\n");
2033
+ if (sizeof(struct PortmapSetting) != len)
2034
+ return -EINVAL;
2035
+
2036
+ pm = ((struct PortmapSetting *)cdata) ->portmap;
2037
+ en = ((struct PortmapSetting *)cdata) ->pmdata;
2038
+
2039
+ if(switchdSetLutPortFlush(pm, en) != 0)
2040
+ return -EINVAL;
2041
+
2042
+ ip1811drv_dbg("ip1811: -setLutPortFlush...\n");
2043
+ return 0;
2044
+}
2045
+
2046
+int switchdSetLutAgingTime(int time)
2047
+{
2048
+ if (time > 18000)
2049
+ return -EINVAL;
2050
+ ip1811drv_dbg("time=%d\n", time);
2051
+
2052
+ _WriteRegBits(1, P1REG_LUTAGINGTIME, 0, 15, (u16)(time*1000/AGING_TIME_UNIT));
2053
+
2054
+ return 0;
2055
+}
2056
+EXPORT_SYMBOL(switchdSetLutAgingTime);
2057
+int setLutAgingTime(void *cdata, int len)
2058
+{
2059
+ int time;
2060
+
2061
+ ip1811drv_dbg("ip1811: +setLutAgingTime...\n");
2062
+ if (sizeof(struct GeneralSetting) != len)
2063
+ return -EINVAL;
2064
+
2065
+ time = ((struct GeneralSetting *)cdata) ->gdata;
2066
+
2067
+ if(switchdSetLutAgingTime(time) != 0)
2068
+ return -EINVAL;
2069
+
2070
+ ip1811drv_dbg("ip1811: -setLutAgingTime...\n");
2071
+ return 0;
2072
+}
2073
+
2074
+void switchdGetLutAgingTime(int *ptrInt)
2075
+{
2076
+ *ptrInt = ((int)_ReadRegBits(1, P1REG_LUTAGINGTIME, 0, 15))*AGING_TIME_UNIT/1000;
2077
+}
2078
+EXPORT_SYMBOL(switchdGetLutAgingTime);
2079
+int getLutAgingTime(void *cdata, int len)
2080
+{
2081
+ int time;
2082
+
2083
+ ip1811drv_dbg("ip1811: +getLutAgingTime...\n");
2084
+ if (sizeof(struct GeneralSetting) != len)
2085
+ return -EINVAL;
2086
+
2087
+ switchdGetLutAgingTime(&time);
2088
+
2089
+ ((struct GeneralSetting *)cdata) ->gdata = time;
2090
+
2091
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
2092
+ ip1811drv_dbg("ip1811: -getLutAgingTime...\n");
2093
+ return 0;
2094
+}
2095
+
2096
+int switchdSetLutAgingTimeEnable(int en)
2097
+{
2098
+ if ( !(en==OP_FUNC_DISABLE || en==OP_FUNC_ENABLE) )
2099
+ return -EINVAL;
2100
+
2101
+ ip1811drv_dbg("en=%d\n", en);
2102
+
2103
+ _WriteRegBits(1, P1REG_LUTAGINGTIME, 15, 1, (en==OP_FUNC_ENABLE)?0:1);
2104
+
2105
+ return 0;
2106
+}
2107
+EXPORT_SYMBOL(switchdSetLutAgingTimeEnable);
2108
+int setLutAgingTimeEnable(void *cdata, int len)
2109
+{
2110
+ int en;
2111
+
2112
+ FUNC_MSG_IN;
2113
+ if (sizeof(struct GeneralSetting) != len)
2114
+ return -EINVAL;
2115
+
2116
+ en = ((struct GeneralSetting *)cdata) ->gdata;
2117
+
2118
+ if(switchdSetLutAgingTimeEnable(en) != 0)
2119
+ return -EINVAL;
2120
+
2121
+ FUNC_MSG_OUT;
2122
+ return 0;
2123
+}
2124
+
2125
+int switchdSetLutLearningNullSA(int en)
2126
+{
2127
+ if ( !(en==OP_FUNC_DISABLE || en==OP_FUNC_ENABLE) )
2128
+ return -EINVAL;
2129
+
2130
+ ip1811drv_dbg("en=%d\n", en);
2131
+
2132
+ _WriteRegBits(1, P1REG_SRCLEARNCFG, 1, 1, en);
2133
+
2134
+ return 0;
2135
+}
2136
+EXPORT_SYMBOL(switchdSetLutLearningNullSA);
2137
+int setLutLearningNullSA(void *cdata, int len)
2138
+{
2139
+ int en;
2140
+
2141
+ FUNC_MSG_IN;
2142
+ if (sizeof(struct GeneralSetting) != len)
2143
+ return -EINVAL;
2144
+
2145
+ en = ((struct GeneralSetting *)cdata) ->gdata;
2146
+
2147
+ if(switchdSetLutLearningNullSA(en) != 0)
2148
+ return -EINVAL;
2149
+
2150
+ FUNC_MSG_OUT;
2151
+ return 0;
2152
+}
2153
+
2154
+int switchdSetLutHashingAlgorithm(int hash)
2155
+{
2156
+ if ( !(hash==OP_HASH_DIRECT || hash==OP_HASH_CRC) )
2157
+ return -EINVAL;
2158
+
2159
+ ip1811drv_dbg("hash=%d\n", hash);
2160
+
2161
+ _WriteRegBits(1, P1REG_SRCLEARNCFG, 2, 1, (hash==OP_HASH_CRC)?0:1);
2162
+
2163
+ return 0;
2164
+}
2165
+EXPORT_SYMBOL(switchdSetLutHashingAlgorithm);
2166
+int setLutHashingAlgorithm(void *cdata, int len)
2167
+{
2168
+ int hash;
2169
+
2170
+ ip1811drv_dbg("ip1811: +setLutHashingAlgorithm...\n");
2171
+ if (sizeof(struct GeneralSetting) != len)
2172
+ return -EINVAL;
2173
+
2174
+ hash = ((struct GeneralSetting *)cdata) ->gdata;
2175
+
2176
+ if(switchdSetLutHashingAlgorithm(hash) != 0)
2177
+ return -EINVAL;
2178
+
2179
+ ip1811drv_dbg("ip1811: -setLutHashingAlgorithm...\n");
2180
+ return 0;
2181
+}
2182
+
2183
+int switchdSetLutBindingEnable(int en)
2184
+{
2185
+ if ( !(en==OP_FUNC_DISABLE || en==OP_FUNC_ENABLE) )
2186
+ return -EINVAL;
2187
+
2188
+ ip1811drv_dbg("en=%d\n", en);
2189
+
2190
+ _WriteRegBits(1, P1REG_SRCLEARNCFG, 5, 1, (en==OP_FUNC_ENABLE)?1:0);
2191
+
2192
+ return 0;
2193
+}
2194
+EXPORT_SYMBOL(switchdSetLutBindingEnable);
2195
+int setLutBindingEnable(void *cdata, int len)
2196
+{
2197
+ int en;
2198
+
2199
+ FUNC_MSG_IN;
2200
+ if (sizeof(struct GeneralSetting) != len)
2201
+ return -EINVAL;
2202
+
2203
+ en = ((struct GeneralSetting *)cdata) ->gdata;
2204
+
2205
+ if(switchdSetLutBindingEnable(en) != 0)
2206
+ return -EINVAL;
2207
+
2208
+ FUNC_MSG_OUT;
2209
+ return 0;
2210
+}
2211
+
2212
+void switchdGetLutBindingEnable(int *ptrInt)
2213
+{
2214
+ *ptrInt = (int)(_ReadRegBits(1, P1REG_SRCLEARNCFG, 5, 1)?OP_FUNC_ENABLE:OP_FUNC_DISABLE);
2215
+}
2216
+EXPORT_SYMBOL(switchdGetLutBindingEnable);
2217
+int getLutBindingEnable(void *cdata, int len)
2218
+{
2219
+ int en;
2220
+
2221
+ FUNC_MSG_IN;
2222
+ if (sizeof(struct GeneralSetting) != len)
2223
+ return -EINVAL;
2224
+
2225
+ switchdGetLutBindingEnable(&en);
2226
+
2227
+ ((struct GeneralSetting *)cdata) ->gdata = en;
2228
+
2229
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
2230
+ FUNC_MSG_OUT;
2231
+ return 0;
2232
+}
2233
+
2234
+//------------------------------------------------
2235
+//common_sniffer
2236
+int switchdSetSnifferSrc(unsigned long pm)
2237
+{
2238
+ if (pm & 0xFFFFF000)
2239
+ return -EINVAL;
2240
+ ip1811drv_dbg("pm=0x%08x\n",(unsigned long)pm);
2241
+
2242
+ IP2Page(1);
2243
+ Write_Reg(P1REG_SNIFSRC, (u16)(pm & 0xFFF));
2244
+
2245
+ return 0;
2246
+}
2247
+EXPORT_SYMBOL(switchdSetSnifferSrc);
2248
+int setSnifferSrc(void *cdata, int len)
2249
+{
2250
+ unsigned long pm;
2251
+
2252
+ ip1811drv_dbg("ip1811: +setSnifferSrc...\n");
2253
+ if (sizeof(struct PortMemberSetting) != len)
2254
+ return -EINVAL;
2255
+
2256
+ pm = ((struct PortMemberSetting *)cdata) ->member;
2257
+
2258
+ if(switchdSetSnifferSrc(pm) != 0)
2259
+ return -EINVAL;
2260
+ ip1811drv_dbg("ip1811: -setSnifferSrc...\n");
2261
+ return 0;
2262
+}
2263
+
2264
+int switchdGetSnifferSrc(u16 *u16dat)
2265
+{
2266
+ IP2Page(1);
2267
+ *u16dat = (u16)Read_Reg(P1REG_SNIFSRC);
2268
+
2269
+ ip1811drv_dbg("cdata ->pdata=%d\n", *u16dat);
2270
+
2271
+ return 0;
2272
+}
2273
+EXPORT_SYMBOL(switchdGetSnifferSrc);
2274
+int getSnifferSrc(void *cdata, int len)
2275
+{
2276
+ u16 u16dat;
2277
+
2278
+ ip1811drv_dbg("ip1811: +getSnifferSrc...\n");
2279
+ if (sizeof(struct PortMemberSetting) != len)
2280
+ return -EINVAL;
2281
+
2282
+ if(switchdGetSnifferSrc(&u16dat) != 0)
2283
+ return -EINVAL;
2284
+
2285
+ ((struct PortMemberSetting *)cdata) ->member = (u16dat & 0xFFF);
2286
+ ip1811drv_dbg("cdata ->gdata=0x%08x\n",(unsigned int)((struct PortMemberSetting *)cdata) ->member);
2287
+ ip1811drv_dbg("ip1811: -getSnifferSrc...\n");
2288
+ return 0;
2289
+}
2290
+
2291
+int switchdSetSnifferDestGrp1(unsigned long pm)
2292
+{
2293
+ u32 u32dat;
2294
+
2295
+ if (pm & 0xFFFFF000)
2296
+ return -EINVAL;
2297
+ ip1811drv_dbg("pm=0x%08x\n", (unsigned int)pm);
2298
+
2299
+ IP2Page(1);
2300
+ u32dat = (u32)Read_Reg(P1REG_SNIFDEST);
2301
+ u32dat = ((u32dat & 0xFFFFF000) | pm);
2302
+ Write_Reg(P1REG_SNIFDEST, (u16)(u32dat & 0xFFF));
2303
+
2304
+ return 0;
2305
+}
2306
+EXPORT_SYMBOL(switchdSetSnifferDestGrp1);
2307
+int setSnifferDestGrp1(void *cdata, int len)
2308
+{
2309
+ unsigned long pm;
2310
+
2311
+ ip1811drv_dbg("ip1811: +setSnifferDestGrp1...\n");
2312
+ if (sizeof(struct PortMemberSetting) != len)
2313
+ return -EINVAL;
2314
+
2315
+ pm = ((struct PortMemberSetting *)cdata) ->member;
2316
+
2317
+ if(switchdSetSnifferDestGrp1(pm) != 0)
2318
+ return -EINVAL;
2319
+ ip1811drv_dbg("ip1811: -setSnifferDestGrp1...\n");
2320
+ return 0;
2321
+}
2322
+
2323
+int switchdGetSnifferDestGrp1(u16 *u16dat)
2324
+{
2325
+ IP2Page(1);
2326
+ *u16dat = (u16)Read_Reg(P1REG_SNIFDEST);
2327
+ ip1811drv_dbg("cdata ->pdata=%d\n", *u16dat);
2328
+
2329
+ return 0;
2330
+}
2331
+EXPORT_SYMBOL(switchdGetSnifferDestGrp1);
2332
+int getSnifferDestGrp1(void *cdata, int len)
2333
+{
2334
+ u16 u16dat;
2335
+
2336
+ ip1811drv_dbg("ip1811: +getSnifferDestGrp1...\n");
2337
+ if (sizeof(struct PortMemberSetting) != len)
2338
+ return -EINVAL;
2339
+
2340
+ if(switchdGetSnifferDestGrp1(&u16dat) != 0)
2341
+ return -EINVAL;
2342
+
2343
+ ((struct PortMemberSetting *)cdata) ->member = (u16dat & 0xFFF);
2344
+ ip1811drv_dbg("cdata ->gdata=0x%08x\n", (unsigned int)((struct PortMemberSetting *)cdata) ->member);
2345
+ ip1811drv_dbg("ip1811: -getSnifferDestGrp1...\n");
2346
+ return 0;
2347
+}
2348
+
2349
+int switchdSetS1Method(int method)
2350
+{
2351
+ if (method<OP_SNIFFER1_METHOD_DISABLE || method>OP_SNIFFER1_METHOD_BOTHDIR)
2352
+ return -EINVAL;
2353
+ ip1811drv_dbg("method=%d\n", method);
2354
+
2355
+ _WriteRegBits(1, P1REG_SNIFCFG, 0, 2, method);
2356
+
2357
+ return 0;
2358
+}
2359
+EXPORT_SYMBOL(switchdSetS1Method);
2360
+int setS1Method(void *cdata, int len)
2361
+{
2362
+ int method;
2363
+
2364
+ ip1811drv_dbg("ip1811: +setS1Method...\n");
2365
+ if (sizeof(struct GeneralSetting) != len)
2366
+ return -EINVAL;
2367
+
2368
+ method = ((struct GeneralSetting *)cdata) ->gdata;
2369
+
2370
+ if(switchdSetS1Method(method) != 0)
2371
+ return -EINVAL;
2372
+ ip1811drv_dbg("ip1811: -setS1Method...\n");
2373
+ return 0;
2374
+}
2375
+
2376
+int switchdGetS1Method(int *ptrInt)
2377
+{
2378
+ *ptrInt = (int)_ReadRegBits(1, P1REG_SNIFCFG, 0, 2);
2379
+
2380
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
2381
+
2382
+ return 0;
2383
+}
2384
+EXPORT_SYMBOL(switchdGetS1Method);
2385
+int getS1Method(void *cdata, int len)
2386
+{
2387
+ int method;
2388
+
2389
+ ip1811drv_dbg("ip1811: +getS1Method...\n");
2390
+ if (sizeof(struct GeneralSetting) != len)
2391
+ return -EINVAL;
2392
+
2393
+ if(switchdGetS1Method(&method) != 0)
2394
+ return -EINVAL;
2395
+
2396
+ ((struct GeneralSetting *)cdata) ->gdata = method;
2397
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
2398
+ ip1811drv_dbg("ip1811: -getS1Method...\n");
2399
+ return 0;
2400
+}
2401
+//------------------------------------------------
2402
+//common_storm
2403
+int switchdSetStormFunc(int storm, int porten)
2404
+{
2405
+ u8 u8dat=0;
2406
+
2407
+ if (storm!=OP_STORM_BCST && storm!=OP_STORM_MCST && storm!=OP_STORM_DLF &&
2408
+ storm!=OP_STORM_ARP && storm!=OP_STORM_ICMP)
2409
+ return -EINVAL;
2410
+ if (porten<0 || (porten&0xFFFFF000))
2411
+ return -EINVAL;
2412
+ ip1811drv_dbg("storm=0x%02X\n", storm);
2413
+ ip1811drv_dbg("porten=0x%08x\n", (unsigned int)porten);
2414
+
2415
+ IP2Page(1);
2416
+ switch (storm){
2417
+ case OP_STORM_BCST:
2418
+ u8dat = P1REG_BSTORMEN;
2419
+ break;
2420
+ case OP_STORM_MCST:
2421
+ u8dat = P1REG_MSTORMEN;
2422
+ break;
2423
+
2424
+ case OP_STORM_DLF:
2425
+ u8dat = P1REG_DLFSTORMEN;
2426
+ break;
2427
+
2428
+ case OP_STORM_ARP:
2429
+ u8dat = P1REG_ARPSTORMEN;
2430
+ break;
2431
+
2432
+ case OP_STORM_ICMP:
2433
+ u8dat = P1REG_ICMPSTORMEN;
2434
+ break;
2435
+ }
2436
+ Write_Reg(u8dat, (u16)(porten & 0xFFFF));
2437
+
2438
+ return 0;
2439
+}
2440
+EXPORT_SYMBOL(switchdSetStormFunc);
2441
+int setStormFunc(void *cdata, int len)
2442
+{
2443
+ u8 storm;
2444
+ long porten;
2445
+
2446
+ ip1811drv_dbg("ip1811: +setStormFunc...\n");
2447
+ if (sizeof(struct StormGeneralSetting) != len)
2448
+ return -EINVAL;
2449
+
2450
+ storm = ((struct StormGeneralSetting *)cdata) ->storm;
2451
+ porten= ((struct StormGeneralSetting *)cdata) ->sdata;
2452
+
2453
+ if(switchdSetStormFunc(storm, porten) != 0)
2454
+ return -EINVAL;
2455
+
2456
+ ip1811drv_dbg("ip1811: -setStormFunc...\n");
2457
+ return 0;
2458
+}
2459
+
2460
+int switchdGetStormFunc(int storm, u32 *u32dat)
2461
+{
2462
+ u8 u8dat=0;
2463
+
2464
+ if (storm!=OP_STORM_BCST && storm!=OP_STORM_MCST && storm!=OP_STORM_DLF &&
2465
+ storm!=OP_STORM_ARP && storm!=OP_STORM_ICMP)
2466
+ return -EINVAL;
2467
+ ip1811drv_dbg("storm=0x%02X\n", storm);
2468
+
2469
+ IP2Page(1);
2470
+ switch (storm){
2471
+ case OP_STORM_BCST:
2472
+ u8dat = P1REG_BSTORMEN;
2473
+ break;
2474
+ case OP_STORM_MCST:
2475
+ u8dat = P1REG_MSTORMEN;
2476
+ break;
2477
+ case OP_STORM_DLF:
2478
+ u8dat = P1REG_DLFSTORMEN;
2479
+ break;
2480
+ case OP_STORM_ARP:
2481
+ u8dat = P1REG_ARPSTORMEN;
2482
+ break;
2483
+ case OP_STORM_ICMP:
2484
+ u8dat = P1REG_ICMPSTORMEN;
2485
+ break;
2486
+ }
2487
+ *u32dat = (u32)Read_Reg(u8dat);
2488
+
2489
+ ip1811drv_dbg("cdata ->sdata=0x%08x\n", *u32dat);
2490
+ return 0;
2491
+}
2492
+EXPORT_SYMBOL(switchdGetStormFunc);
2493
+int getStormFunc(void *cdata, int len)
2494
+{
2495
+ u8 storm;
2496
+ u32 u32dat;
2497
+
2498
+ ip1811drv_dbg("ip1811: +getStormFunc...\n");
2499
+ if (sizeof(struct StormGeneralSetting) != len)
2500
+ return -EINVAL;
2501
+
2502
+ storm = ((struct StormGeneralSetting *)cdata) ->storm;
2503
+
2504
+ if(switchdGetStormFunc(storm, &u32dat) != 0)
2505
+ return -EINVAL;
2506
+ ((struct StormGeneralSetting *)cdata) ->sdata = (long)u32dat;
2507
+
2508
+ ip1811drv_dbg("ip1811: -getStormFunc...\n");
2509
+ return 0;
2510
+}
2511
+
2512
+int switchdSetStormThreshold(u8 storm, long threshold)
2513
+{
2514
+ u8 u8dat=0;
2515
+
2516
+ if (storm!=OP_STORM_BCST && storm!=OP_STORM_MCST && storm!=OP_STORM_DLF &&
2517
+ storm!=OP_STORM_ARP && storm!=OP_STORM_ICMP)
2518
+ return -EINVAL;
2519
+ if (threshold<0 || threshold>0xFF)
2520
+ return -EINVAL;
2521
+ ip1811drv_dbg("storm=0x%02X\n", storm);
2522
+ ip1811drv_dbg("threshold=0x%08x\n", (unsigned int)threshold);
2523
+
2524
+ switch (storm)
2525
+ {
2526
+ case OP_STORM_BCST:
2527
+ case OP_STORM_MCST:
2528
+ case OP_STORM_DLF:
2529
+ u8dat = P1REG_BSTORMTHRESH; break;
2530
+
2531
+ case OP_STORM_ARP:
2532
+ u8dat = P1REG_ARPSTORMCFG; break;
2533
+
2534
+ case OP_STORM_ICMP:
2535
+ u8dat = P1REG_ICMPSTORMCFG; break;
2536
+ }
2537
+ _WriteRegBits(1, u8dat, 0, 8, (u16)threshold);
2538
+
2539
+ return 0;
2540
+}
2541
+EXPORT_SYMBOL(switchdSetStormThreshold);
2542
+int setStormThreshold(void *cdata, int len)
2543
+{
2544
+ u8 storm;
2545
+ long threshold;
2546
+
2547
+ ip1811drv_dbg("ip1811: +setStormThreshold...\n");
2548
+ if (sizeof(struct StormGeneralSetting) != len)
2549
+ return -EINVAL;
2550
+
2551
+ storm = ((struct StormGeneralSetting *)cdata) ->storm;
2552
+ threshold = ((struct StormGeneralSetting *)cdata) ->sdata;
2553
+
2554
+ if(switchdSetStormThreshold(storm, threshold) != 0)
2555
+ return -EINVAL;
2556
+
2557
+ ip1811drv_dbg("ip1811: -setStormThreshold...\n");
2558
+ return 0;
2559
+}
2560
+
2561
+int switchdGetStormThreshold(u8 storm, long *ptrLong)
2562
+{
2563
+ u8 u8dat=0;
2564
+ if (storm!=OP_STORM_BCST && storm!=OP_STORM_MCST && storm!=OP_STORM_DLF &&
2565
+ storm!=OP_STORM_ARP && storm!=OP_STORM_ICMP)
2566
+ return -EINVAL;
2567
+ ip1811drv_dbg("storm=0x%02X\n", storm);
2568
+
2569
+ switch (storm)
2570
+ {
2571
+ case OP_STORM_BCST:
2572
+ case OP_STORM_MCST:
2573
+ case OP_STORM_DLF:
2574
+ u8dat = P1REG_BSTORMTHRESH; break;
2575
+
2576
+ case OP_STORM_ARP:
2577
+ u8dat = P1REG_ARPSTORMCFG; break;
2578
+
2579
+ case OP_STORM_ICMP:
2580
+ u8dat = P1REG_ICMPSTORMCFG; break;
2581
+ }
2582
+ *ptrLong = (long)_ReadRegBits(1, u8dat, 0, 8);
2583
+
2584
+ return 0;
2585
+}
2586
+EXPORT_SYMBOL(switchdGetStormThreshold);
2587
+int getStormThreshold(void *cdata, int len)
2588
+{
2589
+ u8 storm;
2590
+ long threshold;
2591
+
2592
+ ip1811drv_dbg("ip1811: +getStormThreshold...\n");
2593
+ if (sizeof(struct StormGeneralSetting) != len)
2594
+ return -EINVAL;
2595
+
2596
+ storm = ((struct StormGeneralSetting *)cdata) ->storm;
2597
+
2598
+ if(switchdGetStormThreshold(storm, &threshold) != 0)
2599
+ return -EINVAL;
2600
+
2601
+ ((struct StormGeneralSetting *)cdata) ->sdata = threshold;
2602
+ ip1811drv_dbg("cdata ->sdata=0x%08x\n", (unsigned int)((struct StormGeneralSetting *)cdata) ->sdata);
2603
+ ip1811drv_dbg("ip1811: -getStormThreshold...\n");
2604
+ return 0;
2605
+}
2606
+
2607
+int switchdSetStormCntrClrPeriod(u8 storm, long period)
2608
+{
2609
+ u8 reg=0;
2610
+
2611
+ if ( storm!=OP_STORM_BCST
2612
+ && storm!=OP_STORM_MCST
2613
+ && storm!=OP_STORM_DLF
2614
+ && storm!=OP_STORM_ARP
2615
+ && storm!=OP_STORM_ICMP)
2616
+ return -EINVAL;
2617
+ if (period<0 || period>3)
2618
+ return -EINVAL;
2619
+ ip1811drv_dbg("storm=0x%02X\n", storm);
2620
+ ip1811drv_dbg("period=0x%X\n", (unsigned int)period);
2621
+
2622
+ switch (storm)
2623
+ {
2624
+ case OP_STORM_BCST:
2625
+ case OP_STORM_MCST:
2626
+ case OP_STORM_DLF:
2627
+ reg = P1REG_BSTORMTHRESH;
2628
+ break;
2629
+ case OP_STORM_ARP:
2630
+ reg = P1REG_ARPSTORMCFG;
2631
+ break;
2632
+ case OP_STORM_ICMP:
2633
+ reg = P1REG_ICMPSTORMCFG;
2634
+ break;
2635
+ }
2636
+ ip1811drv_dbg("cdata ->sdata=0x%X\n", (s16)period);
2637
+
2638
+ _WriteRegBits(1, reg, 8, 2, period);
2639
+
2640
+ return 0;
2641
+}
2642
+EXPORT_SYMBOL(switchdSetStormCntrClrPeriod);
2643
+int setStormCntrClrPeriod(void *cdata, int len)
2644
+{
2645
+ u8 storm;
2646
+ long period;
2647
+
2648
+ FUNC_MSG_IN;
2649
+ if (sizeof(struct StormGeneralSetting) != len)
2650
+ return -EINVAL;
2651
+
2652
+ storm = ((struct StormGeneralSetting *)cdata) ->storm;
2653
+ period = ((struct StormGeneralSetting *)cdata) ->sdata;
2654
+
2655
+ if(switchdSetStormCntrClrPeriod(storm, period) != 0)
2656
+ return -EINVAL;
2657
+
2658
+ FUNC_MSG_OUT;
2659
+ return 0;
2660
+}
2661
+
2662
+int switchdGetStormCntrClrPeriod(u8 storm, long *ptrInt)
2663
+{
2664
+ u8 reg =0;
2665
+
2666
+ if ( storm!=OP_STORM_BCST
2667
+ && storm!=OP_STORM_MCST
2668
+ && storm!=OP_STORM_DLF
2669
+ && storm!=OP_STORM_ARP
2670
+ && storm!=OP_STORM_ICMP)
2671
+ return -EINVAL;
2672
+ ip1811drv_dbg("storm=0x%02X\n", storm);
2673
+
2674
+ switch (storm)
2675
+ {
2676
+ case OP_STORM_BCST:
2677
+ case OP_STORM_MCST:
2678
+ case OP_STORM_DLF:
2679
+ reg = P1REG_BSTORMTHRESH;
2680
+ break;
2681
+ case OP_STORM_ARP:
2682
+ reg = P1REG_ARPSTORMCFG;
2683
+ break;
2684
+ case OP_STORM_ICMP:
2685
+ reg = P1REG_ICMPSTORMCFG;
2686
+ break;
2687
+ }
2688
+
2689
+ *ptrInt = _ReadRegBits(1, reg, 8, 2);
2690
+
2691
+ ip1811drv_dbg("cdata ->sdata=0x%X\n", *ptrInt);
2692
+
2693
+ return 0;
2694
+}
2695
+EXPORT_SYMBOL(switchdGetStormCntrClrPeriod);
2696
+int getStormCntrClrPeriod(void *cdata, int len)
2697
+{
2698
+ u8 storm;
2699
+ long period=0;
2700
+
2701
+ FUNC_MSG_IN;
2702
+ ip1811drv_dbg("ip1811: +getStormCntrClrPeriod...\n");
2703
+ if (sizeof(struct StormGeneralSetting) != len)
2704
+ {
2705
+ ip1811drv_err("Error: lengtn=%d\n", len);
2706
+ return -EINVAL;
2707
+ }
2708
+
2709
+ storm = ((struct StormGeneralSetting *)cdata) ->storm;
2710
+
2711
+ if(switchdGetStormCntrClrPeriod(storm, &period) != 0)
2712
+ return -EINVAL;
2713
+
2714
+ ((struct StormGeneralSetting *)cdata) ->sdata = period;
2715
+
2716
+ ip1811drv_dbg("ip1811: -getStormCntrClrPeriod...\n");
2717
+ FUNC_MSG_OUT;
2718
+ return 0;
2719
+}
2720
+
2721
+int switchdSetStormBlockFrm2Cpu(int storm, int en)
2722
+{
2723
+ u8 u8dat=0;
2724
+
2725
+ if (storm!=OP_STORM_BCST && storm!=OP_STORM_MCST && storm!=OP_STORM_ARP)
2726
+ return -EINVAL;
2727
+ if (en!=OP_FUNC_DISABLE && en!=OP_FUNC_ENABLE)
2728
+ return -EINVAL;
2729
+ ip1811drv_dbg("storm=0x%02X\n", storm);
2730
+ ip1811drv_dbg("en=0x%08x\n", (unsigned int)en);
2731
+
2732
+ switch (storm)
2733
+ {
2734
+ case OP_STORM_BCST:
2735
+ case OP_STORM_MCST:
2736
+ u8dat = P1REG_BSTORMTHRESH; break;
2737
+
2738
+ case OP_STORM_ARP:
2739
+ u8dat = P1REG_ARPSTORMCFG; break;
2740
+ }
2741
+ _WriteRegBits(1, u8dat, 10, 1, en);
2742
+
2743
+ return 0;
2744
+}
2745
+EXPORT_SYMBOL(switchdSetStormBlockFrm2Cpu);
2746
+int setStormBlockFrm2Cpu(void *cdata, int len)
2747
+{
2748
+ u8 storm = 0;
2749
+ long en;
2750
+
2751
+ ip1811drv_dbg("ip1811: +setStormBlockFrm2Cpu...\n");
2752
+ if (sizeof(struct StormGeneralSetting) != len)
2753
+ return -EINVAL;
2754
+
2755
+ storm = ((struct StormGeneralSetting *)cdata) ->storm;
2756
+ en = ((struct StormGeneralSetting *)cdata) ->sdata;
2757
+
2758
+ if(switchdSetStormBlockFrm2Cpu(storm, en) != 0)
2759
+ return -EINVAL;
2760
+
2761
+ ip1811drv_dbg("ip1811: -setStormBlockFrm2Cpu...\n");
2762
+ return 0;
2763
+}
2764
+
2765
+int switchdGetStormBlockFrm2Cpu(u8 storm, int *ptrInt)
2766
+{
2767
+ u8 u8dat=0;
2768
+
2769
+ if (storm!=OP_STORM_BCST && storm!=OP_STORM_MCST && storm!=OP_STORM_ARP)
2770
+ return -EINVAL;
2771
+ ip1811drv_dbg("storm=0x%02X\n", storm);
2772
+
2773
+ switch (storm)
2774
+ {
2775
+ case OP_STORM_BCST:
2776
+ case OP_STORM_MCST:
2777
+ u8dat = P1REG_BSTORMTHRESH; break;
2778
+
2779
+ case OP_STORM_ARP:
2780
+ u8dat = P1REG_ARPSTORMCFG; break;
2781
+ }
2782
+
2783
+ *ptrInt = (int)_ReadRegBits(1, u8dat, 10, 1);
2784
+
2785
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
2786
+
2787
+ return 0;
2788
+}
2789
+EXPORT_SYMBOL(switchdGetStormBlockFrm2Cpu);
2790
+int getStormBlockFrm2Cpu(void *cdata, int len)
2791
+{
2792
+ u8 storm;
2793
+ int en;
2794
+
2795
+ ip1811drv_dbg("ip1811: +getStormBlockFrm2Cpu...\n");
2796
+ if (sizeof(struct StormGeneralSetting) != len)
2797
+ return -EINVAL;
2798
+
2799
+ storm = ((struct StormGeneralSetting *)cdata) ->storm;
2800
+
2801
+ if(switchdGetStormBlockFrm2Cpu(storm, &en) != 0)
2802
+ return -EINVAL;
2803
+
2804
+ ((struct StormGeneralSetting *)cdata) ->sdata = en;
2805
+ ip1811drv_dbg("cdata ->sdata=0x%08x\n", (unsigned int)((struct StormGeneralSetting *)cdata) ->sdata);
2806
+ ip1811drv_dbg("ip1811: -getStormBlockFrm2Cpu...\n");
2807
+ return 0;
2808
+}
2809
+
2810
+int switchdSetStormDropInterrupt(u8 storm, int en)
2811
+{
2812
+ if (storm!=OP_STORM_ARP && storm!=OP_STORM_ICMP)
2813
+ return -EINVAL;
2814
+ if (en!=OP_FUNC_DISABLE && en!=OP_FUNC_ENABLE)
2815
+ return -EINVAL;
2816
+ ip1811drv_dbg("storm=0x%02X\n", storm);
2817
+ ip1811drv_dbg("en=0x%08x\n", en);
2818
+
2819
+ switch (storm)
2820
+ {
2821
+ case OP_STORM_ARP:
2822
+ _WriteRegBits(1, P1REG_ARPSTORMCFG, 11, 1, (en == OP_FUNC_DISABLE)?0:1);
2823
+ break;
2824
+
2825
+ case OP_STORM_ICMP:
2826
+ _WriteRegBits(1, P1REG_ICMPSTORMCFG, 10, 1, (en == OP_FUNC_DISABLE)?0:1);
2827
+ break;
2828
+ }
2829
+
2830
+ return 0;
2831
+}
2832
+EXPORT_SYMBOL(switchdSetStormDropInterrupt);
2833
+int setStormDropInterrupt(void *cdata, int len)
2834
+{
2835
+ u8 storm;
2836
+ int en;
2837
+
2838
+ ip1811drv_dbg("ip1811: +setStormDropInterrupt...\n");
2839
+ if (sizeof(struct StormGeneralSetting) != len)
2840
+ return -EINVAL;
2841
+
2842
+ storm = ((struct StormGeneralSetting *)cdata) ->storm;
2843
+ en = ((struct StormGeneralSetting *)cdata) ->sdata;
2844
+
2845
+ if(switchdSetStormDropInterrupt(storm, en) != 0)
2846
+ return -EINVAL;
2847
+
2848
+ ip1811drv_dbg("ip1811: -setStormDropInterrupt...\n");
2849
+ return 0;
2850
+}
2851
+
2852
+int switchdGetStormDropInterrupt(u8 storm, int *ptrInt)
2853
+{
2854
+ if (storm!=OP_STORM_ARP && storm!=OP_STORM_ICMP)
2855
+ return -EINVAL;
2856
+ ip1811drv_dbg("storm=0x%02X\n", storm);
2857
+
2858
+ switch (storm)
2859
+ {
2860
+ case OP_STORM_ARP:
2861
+ *ptrInt = (int)_ReadRegBits(1, P1REG_ARPSTORMCFG, 11, 1);
2862
+ break;
2863
+
2864
+ case OP_STORM_ICMP:
2865
+ *ptrInt = (int)_ReadRegBits(1, P1REG_ICMPSTORMCFG, 10, 1);
2866
+ break;
2867
+ }
2868
+
2869
+ ip1811drv_dbg("cdata ->sdata=0x%08x\n", *ptrInt);
2870
+
2871
+ return 0;
2872
+}
2873
+EXPORT_SYMBOL(switchdGetStormDropInterrupt);
2874
+int getStormDropInterrupt(void *cdata, int len)
2875
+{
2876
+ u8 storm;
2877
+ int en;
2878
+
2879
+ ip1811drv_dbg("ip1811: +getStormDropInterrupt...\n");
2880
+ if (sizeof(struct StormGeneralSetting) != len)
2881
+ return -EINVAL;
2882
+
2883
+ storm = ((struct StormGeneralSetting *)cdata) ->storm;
2884
+
2885
+ if(switchdGetStormDropInterrupt(storm, &en) != 0)
2886
+ return -EINVAL;
2887
+
2888
+ ((struct StormGeneralSetting *)cdata) ->sdata = en;
2889
+
2890
+ ip1811drv_dbg("ip1811: -getStormDropInterrupt...\n");
2891
+ return 0;
2892
+}
2893
+
2894
+//------------------------------------------------
2895
+//common_loop_detect
2896
+int switchdSetLdFunc(unsigned int pm, int en)
2897
+{
2898
+ u16 u16dat;
2899
+ if (pm & 0xF000)
2900
+ return -EINVAL;
2901
+
2902
+ ip1811drv_dbg("pm=0x%08x\n", pm);
2903
+ ip1811drv_dbg("en=%d\n", en);
2904
+ _WriteRegBits(1, P1REG_MISCCFG, 11, 1, en);
2905
+
2906
+ IP2Page(0);
2907
+ u16dat = Read_Reg(P0REG_LDEN);
2908
+ u16dat = ((u16dat & 0xF000) | pm);
2909
+ Write_Reg(P0REG_LDEN, u16dat);
2910
+
2911
+ return 0;
2912
+}
2913
+EXPORT_SYMBOL(switchdSetLdFunc);
2914
+
2915
+int setLdFunc(void *cdata, int len)
2916
+{
2917
+ unsigned long pm;
2918
+ int en, ret;
2919
+ u32 u32dat;
2920
+
2921
+ ip1811drv_dbg("ip1811: +setLdFunc...\n");
2922
+ if (sizeof(struct PortmapSetting) != len) {
2923
+ ret = -EINVAL;
2924
+ goto out_setLdFunc;
2925
+ }
2926
+
2927
+ pm = ((struct PortmapSetting *)cdata) ->portmap;
2928
+ en = ((struct PortmapSetting *)cdata) ->pmdata;
2929
+ ret = switchdSetLdFunc(pm, en);
2930
+
2931
+out_setLdFunc:
2932
+ ip1811drv_dbg("ip1811: -setLdFunc...\n");
2933
+ return ret;
2934
+}
2935
+
2936
+int switchdGetLdFunc(unsigned long *portmap, int *pmdata)
2937
+{
2938
+ u16 u16dat;
2939
+
2940
+ IP2Page(1);
2941
+ u16dat = Read_Reg(P1REG_MISCCFG);
2942
+ if(u16dat & 0x0800)
2943
+ *pmdata = OP_FUNC_ENABLE;
2944
+ else
2945
+ *pmdata = OP_FUNC_DISABLE;
2946
+
2947
+ IP2Page(0);
2948
+ u16dat = Read_Reg(P0REG_LDEN);
2949
+ *portmap = (u16dat & 0xFFF);
2950
+
2951
+ return 0;
2952
+}
2953
+EXPORT_SYMBOL(switchdGetLdFunc);
2954
+
2955
+int getLdFunc(void *cdata, int len)
2956
+{
2957
+ int ret;
2958
+ int pmdata;
2959
+ unsigned long portmap;
2960
+
2961
+ ip1811drv_dbg("ip1811: +getLdFunc...\n");
2962
+ if (sizeof(struct PortmapSetting) != len) {
2963
+ ret = -EINVAL;
2964
+ goto out_getLdFunc;
2965
+ }
2966
+
2967
+ ret = switchdGetLdFunc(&portmap, &pmdata);
2968
+
2969
+ ((struct PortmapSetting *)cdata) ->portmap = portmap;
2970
+ ((struct PortmapSetting *)cdata) ->pmdata = pmdata;
2971
+
2972
+ ip1811drv_dbg("cdata ->portmap=0x%08x\n", ((struct PortmapSetting *)cdata) ->portmap);
2973
+ ip1811drv_dbg("cdata ->pmdata=%d\n", ((struct PortmapSetting *)cdata) ->pmdata);
2974
+
2975
+out_getLdFunc:
2976
+ ip1811drv_dbg("ip1811: -getLdFunc...\n");
2977
+ return ret;
2978
+}
2979
+
2980
+int switchdSetLdTimeUnit(int time_unit)
2981
+{
2982
+ if (time_unit!=OP_LD_TIME_UNIT_500MS && time_unit!=OP_LD_TIME_UNIT_10S)
2983
+ return -EINVAL;
2984
+ ip1811drv_dbg("tunit=%d\n", time_unit);
2985
+
2986
+ _WriteRegBits(0, P0REG_LDCONFIG, 0, 1, time_unit);
2987
+
2988
+ return 0;
2989
+}
2990
+EXPORT_SYMBOL(switchdSetLdTimeUnit);
2991
+
2992
+int setLdTimeUnit(void *cdata, int len)
2993
+{
2994
+ int tunit, ret;
2995
+
2996
+ ip1811drv_dbg("ip1811: +setLdTimeUnit...\n");
2997
+ if (sizeof(struct GeneralSetting) != len) {
2998
+ ret = -EINVAL;
2999
+ goto out_setLdTimeUnit;
3000
+ }
3001
+
3002
+ tunit = ((struct GeneralSetting *)cdata) ->gdata;
3003
+ ret = switchdSetLdTimeUnit(tunit);
3004
+
3005
+out_setLdTimeUnit:
3006
+ ip1811drv_dbg("ip1811: -setLdTimeUnit...\n");
3007
+ return ret;
3008
+}
3009
+
3010
+int switchdGetLdTimeUnit(int *time_unit_get)
3011
+{
3012
+ *time_unit_get = (int)_ReadRegBits(0, P0REG_LDCONFIG, 0, 1);
3013
+ return 0;
3014
+}
3015
+EXPORT_SYMBOL(switchdGetLdTimeUnit);
3016
+
3017
+int getLdTimeUnit(void *cdata, int len)
3018
+{
3019
+ int val, ret;
3020
+ ip1811drv_dbg("ip1811: +getLdTimeUnit...\n");
3021
+ if (sizeof(struct GeneralSetting) != len) {
3022
+ ret = -EINVAL;
3023
+ }
3024
+
3025
+ ret = switchdGetLdTimeUnit(&val);
3026
+ ((struct GeneralSetting *)cdata) ->gdata = val;
3027
+
3028
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
3029
+
3030
+out_getLdTimeUnit:
3031
+ ip1811drv_dbg("ip1811: -getLdTimeUnit...\n");
3032
+ return ret;
3033
+}
3034
+
3035
+int switchdSetLdPktSendTimer(int timer)
3036
+{
3037
+ if (timer < 0 || timer > 0xFF)
3038
+ return -EINVAL;
3039
+ ip1811drv_dbg("timer=%d\n", timer);
3040
+
3041
+ _WriteRegBits(0, P0REG_LDTIMER, 0, 8, timer);
3042
+
3043
+ return 0;
3044
+}
3045
+EXPORT_SYMBOL(switchdSetLdPktSendTimer);
3046
+
3047
+int setLdPktSendTimer(void *cdata, int len)
3048
+{
3049
+ int timer, ret;
3050
+
3051
+ ip1811drv_dbg("ip1811: +setLdPktSendTimer...\n");
3052
+ if (sizeof(struct GeneralSetting) != len) {
3053
+ ret = -EINVAL;
3054
+ goto out_setLdPktSendTimer;
3055
+ }
3056
+
3057
+ timer = ((struct GeneralSetting *)cdata) ->gdata;
3058
+ ret = switchdSetLdPktSendTimer(timer);
3059
+
3060
+out_setLdPktSendTimer:
3061
+ ip1811drv_dbg("ip1811: -setLdPktSendTimer...\n");
3062
+ return ret;
3063
+}
3064
+
3065
+int switchdGetLdPktSendTimer(int *send_timer_get)
3066
+{
3067
+ *send_timer_get = (int)_ReadRegBits(0, P0REG_LDTIMER, 0, 8);
3068
+ return 0;
3069
+}
3070
+EXPORT_SYMBOL(switchdGetLdPktSendTimer);
3071
+
3072
+int getLdPktSendTimer(void *cdata, int len)
3073
+{
3074
+ int val, ret;
3075
+ ip1811drv_dbg("ip1811: +getLdPktSendTimer...\n");
3076
+ if (sizeof(struct GeneralSetting) != len) {
3077
+ ret = -EINVAL;
3078
+ goto out_getLdPktSendTimer;
3079
+ }
3080
+
3081
+ ret = switchdGetLdPktSendTimer(&val);
3082
+ ((struct GeneralSetting *)cdata) ->gdata = val;
3083
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
3084
+
3085
+out_getLdPktSendTimer:
3086
+ ip1811drv_dbg("ip1811: -getLdPktSendTimer...\n");
3087
+ return ret;
3088
+}
3089
+
3090
+int switchdSetLdBlockReleaseTimer(int timer)
3091
+{
3092
+ if (timer < 0 || timer > 0xFF)
3093
+ return -EINVAL;
3094
+ ip1811drv_dbg("timer=%d\n", timer);
3095
+
3096
+ _WriteRegBits(0, P0REG_LDTIMER, 8, 8, timer);
3097
+
3098
+ return 0;
3099
+}
3100
+EXPORT_SYMBOL(switchdSetLdBlockReleaseTimer);
3101
+
3102
+int setLdBlockReleaseTimer(void *cdata, int len)
3103
+{
3104
+ int timer, ret;
3105
+
3106
+ ip1811drv_dbg("ip1811: +setLdBlockReleaseTimer...\n");
3107
+ if (sizeof(struct GeneralSetting) != len) {
3108
+ ret = -EINVAL;
3109
+ goto out_setLdBlockReleaseTimer;
3110
+ }
3111
+
3112
+ timer = ((struct GeneralSetting *)cdata) ->gdata;
3113
+ ret = switchdSetLdBlockReleaseTimer(timer);
3114
+
3115
+out_setLdBlockReleaseTimer:
3116
+ ip1811drv_dbg("ip1811: -setLdBlockReleaseTimer...\n");
3117
+ return ret;
3118
+}
3119
+
3120
+int switchdGetLdBlockReleaseTimer(int *release_timer_get)
3121
+{
3122
+ *release_timer_get = (int)_ReadRegBits(0, P0REG_LDTIMER, 8, 8);
3123
+ return 0;
3124
+}
3125
+EXPORT_SYMBOL(switchdGetLdBlockReleaseTimer);
3126
+
3127
+int getLdBlockReleaseTimer(void *cdata, int len)
3128
+{
3129
+ int val, ret;
3130
+ ip1811drv_dbg("ip1811: +getLdBlockReleaseTimer...\n");
3131
+ if (sizeof(struct GeneralSetting) != len) {
3132
+ ret = -EINVAL;
3133
+ goto out_getLdBlockReleaseTimer;
3134
+ }
3135
+
3136
+ ret = switchdGetLdBlockReleaseTimer(&val);
3137
+ ((struct GeneralSetting *)cdata) ->gdata = val;
3138
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
3139
+
3140
+out_getLdBlockReleaseTimer:
3141
+ ip1811drv_dbg("ip1811: -getLdBlockReleaseTimer...\n");
3142
+ return ret;
3143
+}
3144
+
3145
+int switchdGetLdStatus(unsigned long *status)
3146
+{
3147
+ IP2Page(0);
3148
+ *status = Read_Reg(P0REG_LDSTATUS);
3149
+ return 0;
3150
+}
3151
+EXPORT_SYMBOL(switchdGetLdStatus);
3152
+
3153
+int getLdStatus(void *cdata, int len)
3154
+{
3155
+ unsigned long val;
3156
+ int ret;
3157
+
3158
+ ip1811drv_dbg("ip1811: +getLdStatus...\n");
3159
+ if (sizeof(struct PortMemberSetting) != len) {
3160
+ ret = -EINVAL;
3161
+ goto out_getLdStatus;
3162
+ }
3163
+
3164
+ ret = switchdGetLdStatus(&val);
3165
+ ((struct PortMemberSetting *)cdata) ->member = val;
3166
+ ip1811drv_dbg("cdata ->member=%08lX\n", ((struct PortMemberSetting *)cdata) ->member);
3167
+
3168
+out_getLdStatus:
3169
+ ip1811drv_dbg("ip1811: -getLdStatus...\n");
3170
+ return ret;
3171
+}
3172
+
3173
+//ip1811_loop_detect
3174
+int switchdSetLdDMAC(unsigned char *mac)
3175
+{
3176
+ int i;
3177
+ u16 u16dat;
3178
+
3179
+ IP2Page(0);
3180
+ for (i=0; i<3; i++) {
3181
+ u16dat = (u16)( (mac[i*2] << 8) | mac[i*2+1] );
3182
+ Write_Reg(P0REG_LDDA0+2-i, u16dat);
3183
+ }
3184
+ return 0;
3185
+}
3186
+EXPORT_SYMBOL(switchdSetLdDMAC);
3187
+
3188
+int setLdDMAC(void *cdata, int len)
3189
+{
3190
+ int i, ret;
3191
+ u8 da[6];
3192
+
3193
+ ip1811drv_dbg("ip1811: +setLdDMAC...\n");
3194
+ if (sizeof(struct LDDASetting) != len) {
3195
+ ret = -EINVAL;
3196
+ goto out_setLdDMAC;
3197
+ }
3198
+
3199
+ ip1811drv_dbg("da=[");
3200
+ for (i=0; i<6; i++) {
3201
+ da[i] = ((struct LDDASetting *)cdata) ->da[i];
3202
+ ip1811drv_dbg("0x%02X, ", da[i]);
3203
+ }
3204
+ ip1811drv_dbg("]\n");
3205
+ ret = switchdSetLdDMAC(da);
3206
+
3207
+out_setLdDMAC:
3208
+ ip1811drv_dbg("ip1811: -setLdDMAC...\n");
3209
+ return 0;
3210
+}
3211
+
3212
+int switchdSetLdSubType(int stype)
3213
+{
3214
+ IP2Page(0);
3215
+ Write_Reg(P0REG_LDSUBTYPE, (u16)stype);
3216
+ return 0;
3217
+}
3218
+EXPORT_SYMBOL(switchdSetLdSubType);
3219
+
3220
+int setLdSubType(void *cdata, int len)
3221
+{
3222
+ int stype, ret;
3223
+
3224
+ ip1811drv_dbg("ip1811: +setLdSubType...\n");
3225
+ if (sizeof(struct GeneralSetting) != len) {
3226
+ ret = -EINVAL;
3227
+ goto out_setLdSubType;
3228
+ }
3229
+
3230
+ stype = ((struct GeneralSetting *)cdata) ->gdata;
3231
+ if (stype<0 && stype>0xFFFF) {
3232
+ ret = -EINVAL;
3233
+ goto out_setLdSubType;
3234
+ }
3235
+ ip1811drv_dbg("stype=%d\n", stype);
3236
+
3237
+ ret = switchdSetLdSubType(stype);
3238
+
3239
+out_setLdSubType:
3240
+ ip1811drv_dbg("ip1811: -setLdSubType...\n");
3241
+ return 0;
3242
+}
3243
+//------------------------------------------------
3244
+//common_stag
3245
+int switchdSetCpuPortLink(int clink)
3246
+{
3247
+ if (clink!=OP_CPU_PORT_NORMAL && clink!=OP_CPU_PORT_CPU)
3248
+ return -EINVAL;
3249
+ ip1811drv_dbg("clink=%d\n", clink);
3250
+
3251
+ return 0;
3252
+}
3253
+EXPORT_SYMBOL(switchdSetCpuPortLink);
3254
+int setCpuPortLink(void *cdata, int len)
3255
+{
3256
+ int clink;
3257
+
3258
+ ip1811drv_dbg("ip1811: +setCpuPortLink...\n");
3259
+ if (sizeof(struct GeneralSetting) != len)
3260
+ return -EINVAL;
3261
+
3262
+ clink = ((struct GeneralSetting *)cdata) ->gdata;
3263
+
3264
+ if(switchdSetCpuPortLink(clink) != 0)
3265
+ return -EINVAL;
3266
+
3267
+ ip1811drv_dbg("ip1811: -setCpuPortLink...\n");
3268
+ return 0;
3269
+}
3270
+
3271
+int switchdSetSTagFunc(int en)
3272
+{
3273
+ if (en!=OP_FUNC_DISABLE && en!=OP_FUNC_ENABLE)
3274
+ return -EINVAL;
3275
+ ip1811drv_dbg("en=%d\n", en);
3276
+
3277
+ if(en == OP_FUNC_ENABLE){
3278
+ _WriteRegBits(0xE, PEREG_CPUMODE, 0, 2 , 0x3);
3279
+ }else{
3280
+ _WriteRegBits(0xE, PEREG_CPUMODE, 0, 2 , 0x0);
3281
+ }
3282
+
3283
+ return 0;
3284
+}
3285
+EXPORT_SYMBOL(switchdSetSTagFunc);
3286
+int setSTagFunc(void *cdata, int len)
3287
+{
3288
+ int en;
3289
+
3290
+ ip1811drv_dbg("ip1811: +setSTagFunc...\n");
3291
+ if (sizeof(struct GeneralSetting) != len)
3292
+ return -EINVAL;
3293
+
3294
+ en = ((struct GeneralSetting *)cdata) ->gdata;
3295
+
3296
+ if(switchdSetSTagFunc(en) != 0)
3297
+ return -EINVAL;
3298
+
3299
+ ip1811drv_dbg("ip1811: -setSTagFunc...\n");
3300
+ return 0;
3301
+}
3302
+
3303
+void switchdGetSTagTypeLen(unsigned short *ptrLength, unsigned short *ptrType)
3304
+{
3305
+ IP2Page(0xE);
3306
+ *ptrType= Read_Reg(PEREG_SPTAG);
3307
+ *ptrLength = 0;
3308
+ ip1811drv_dbg("cdata ->length=%d\n", *ptrLength);
3309
+ ip1811drv_dbg("cdata ->type=0x%08x\n", *ptrType);
3310
+}
3311
+EXPORT_SYMBOL(switchdGetSTagTypeLen);
3312
+int getSTagTypeLen(void *cdata, int len)
3313
+{
3314
+ unsigned short type, length;
3315
+
3316
+ ip1811drv_dbg("ip1811: +getSTagTypeLen...\n");
3317
+ if (sizeof(struct STagTypeLenSetting) != len)
3318
+ return -EINVAL;
3319
+
3320
+ switchdGetSTagTypeLen(&length, &type);
3321
+
3322
+ ((struct STagTypeLenSetting *)cdata) ->length = (unsigned int)length;
3323
+ ((struct STagTypeLenSetting *)cdata) ->type = (unsigned int)type;
3324
+ ip1811drv_dbg("ip1811: -getSTagTypeLen...\n");
3325
+ return 0;
3326
+}
3327
+
3328
+//------------ PTP functions:common Start -----------------------
3329
+int setPTPEnable(void *cdata, int len)
3330
+{
3331
+ int ret;
3332
+
3333
+ FUNC_MSG_IN;
3334
+ ret = _setGeneralEnable(cdata, len, 0, P0REG_PTPCFG, 0);
3335
+ FUNC_MSG_OUT;
3336
+
3337
+ return ret;
3338
+}
3339
+
3340
+int getPTPEnable(void *cdata, int len)
3341
+{
3342
+ int ret;
3343
+
3344
+ FUNC_MSG_IN;
3345
+ ret = _getGeneralEnable(cdata, len, 0, P0REG_PTPCFG, 0);
3346
+ FUNC_MSG_OUT;
3347
+
3348
+ return ret;
3349
+}
3350
+
3351
+int setPTPDA011B19000000(void *cdata, int len){
3352
+ int ret;
3353
+
3354
+ FUNC_MSG_IN;
3355
+ ret = _setGeneralEnable(cdata, len, 0, P0REG_PTPCFG, 1);
3356
+ FUNC_MSG_OUT;
3357
+
3358
+ return ret;
3359
+}
3360
+
3361
+int getPTPDA011B19000000(void *cdata, int len){
3362
+ int ret;
3363
+
3364
+ FUNC_MSG_IN;
3365
+ ret = _getGeneralEnable(cdata, len, 0, P0REG_PTPCFG, 1);
3366
+ FUNC_MSG_OUT;
3367
+
3368
+ return ret;
3369
+}
3370
+
3371
+int setPTPDA0180C200000E(void *cdata, int len){
3372
+ int ret;
3373
+
3374
+ FUNC_MSG_IN;
3375
+ ret = _setGeneralEnable(cdata, len, 0, P0REG_PTPCFG, 2);
3376
+ FUNC_MSG_OUT;
3377
+
3378
+ return ret;
3379
+}
3380
+
3381
+int getPTPDA0180C200000E(void *cdata, int len){
3382
+ int ret;
3383
+
3384
+ FUNC_MSG_IN;
3385
+ ret = _getGeneralEnable(cdata, len, 0, P0REG_PTPCFG, 2);
3386
+ FUNC_MSG_OUT;
3387
+
3388
+ return ret;
3389
+}
3390
+
3391
+int setPTPUdpDP(void *cdata, int len){
3392
+ int ret;
3393
+
3394
+ FUNC_MSG_IN;
3395
+ ret = _setGeneralEnable(cdata, len, 0, P0REG_PTPCFG, 3);
3396
+ FUNC_MSG_OUT;
3397
+
3398
+ return ret;
3399
+}
3400
+
3401
+int getPTPUdpDP(void *cdata, int len){
3402
+ int ret;
3403
+
3404
+ FUNC_MSG_IN;
3405
+ ret = _getGeneralEnable(cdata, len, 0, P0REG_PTPCFG, 3);
3406
+ FUNC_MSG_OUT;
3407
+
3408
+ return ret;
3409
+}
3410
+
3411
+int setPTPUdpSP(void *cdata, int len){
3412
+ int ret;
3413
+
3414
+ FUNC_MSG_IN;
3415
+ ret = _setGeneralEnable(cdata, len, 0, P0REG_PTPCFG, 4);
3416
+ FUNC_MSG_OUT;
3417
+
3418
+ return ret;
3419
+}
3420
+
3421
+int getPTPUdpSP(void *cdata, int len){
3422
+ int ret;
3423
+
3424
+ FUNC_MSG_IN;
3425
+ ret = _getGeneralEnable(cdata, len, 0, P0REG_PTPCFG, 4);
3426
+ FUNC_MSG_OUT;
3427
+
3428
+ return ret;
3429
+}
3430
+
3431
+int setPTPToCPU(void *cdata, int len)
3432
+{
3433
+ int gdata;
3434
+
3435
+ FUNC_MSG_IN;
3436
+ if (sizeof(struct GeneralSetting) != len)
3437
+ {
3438
+ ip1811drv_err("Error: length=%d\n", len);
3439
+ return -EINVAL;
3440
+ }
3441
+
3442
+ gdata = ((struct GeneralSetting *)cdata) ->gdata;
3443
+ if( gdata != OP_CAP_ACT_TO_CPU && gdata != OP_CAP_ACT_FORWARD )
3444
+ {
3445
+ ip1811drv_err("Error: gdata=%X\n", gdata);
3446
+ return -EINVAL;
3447
+ }
3448
+
3449
+ ip1811drv_dbg("cdata ->gdata=%d\n", gdata);
3450
+
3451
+ _WriteRegBits(0, P0REG_PTPCFG, 5, 1, gdata==OP_CAP_ACT_TO_CPU?0x0:0x1);
3452
+
3453
+ FUNC_MSG_OUT;
3454
+ return 0;
3455
+}
3456
+
3457
+int getPTPToCPU(void *cdata, int len)
3458
+{
3459
+ int gdata;
3460
+
3461
+ FUNC_MSG_IN;
3462
+ if (sizeof(struct GeneralSetting) != len)
3463
+ {
3464
+ ip1811drv_err("Error: length=%d\n", len);
3465
+ return -EINVAL;
3466
+ }
3467
+
3468
+ gdata = (_ReadRegBits(0, P0REG_PTPCFG, 5, 1)==0x0?OP_CAP_ACT_TO_CPU:OP_CAP_ACT_FORWARD);
3469
+ ((struct GeneralSetting *)cdata) ->gdata = gdata;
3470
+
3471
+ ip1811drv_dbg("cdata ->gdata=%d\n", gdata);
3472
+ FUNC_MSG_OUT;
3473
+ return 0;
3474
+}
3475
+
3476
+int setPTPSpecialTag(void *cdata, int len){
3477
+ int ret;
3478
+
3479
+ FUNC_MSG_IN;
3480
+ ret = _setGeneralEnable(cdata, len, 0x07, P7REG_TXDMA, 5);
3481
+ FUNC_MSG_OUT;
3482
+
3483
+ return ret;
3484
+}
3485
+
3486
+int getPTPSpecialTag(void *cdata, int len){
3487
+ int ret;
3488
+
3489
+ FUNC_MSG_IN;
3490
+ ret = _getGeneralEnable(cdata, len, 0x07, P7REG_TXDMA, 5);
3491
+ FUNC_MSG_OUT;
3492
+
3493
+ return ret;
3494
+}
3495
+
3496
+int setPTPClockReset(void *cdata, int len){
3497
+ int ret;
3498
+
3499
+ FUNC_MSG_IN;
3500
+ ret = _setGeneralEnable(cdata, len, 0x09, P9REG_PTP_CLOCK_RESET, 0);
3501
+ FUNC_MSG_OUT;
3502
+
3503
+ return ret;
3504
+}
3505
+
3506
+int getPTPTimeStamp(void *cdata, int len){
3507
+ unsigned int cmd=0, port=0;
3508
+ struct PTPReadSetting* ps=(struct PTPReadSetting*)cdata;
3509
+
3510
+ if(sizeof(struct PTPReadSetting) != len)
3511
+ return -EINVAL;
3512
+
3513
+ cmd=ps->addr;
3514
+ cmd|=(ps->in_out)<<4;
3515
+ port = ps->port;
3516
+#ifdef COMBINED_PORT
3517
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
3518
+ port++;
3519
+#endif
3520
+ cmd|=(port)<<5;
3521
+ cmd|=0x8000;
3522
+
3523
+ IP2Page(0x09);
3524
+ Write_Reg(P9REG_PTP_TIMESTAMP_READ, (u16)cmd);
3525
+
3526
+ while((Read_Reg(P9REG_PTP_TIMESTAMP_READ) >> 15)&0x1);
3527
+
3528
+ ps->second=Read_Reg(P9REG_PTP_TIMEDATA_SEC2);
3529
+ ps->second<<=16;
3530
+ ps->second=Read_Reg(P9REG_PTP_TIMEDATA_SEC1);
3531
+ ps->second<<=16;
3532
+ ps->second|=Read_Reg(P9REG_PTP_TIMEDATA_SEC0);
3533
+ ps->nanosecond=Read_Reg(P9REG_PTP_TIMEDATA_NANOSEC1);
3534
+ ps->nanosecond<<=16;
3535
+ ps->nanosecond|=Read_Reg(P9REG_PTP_TIMEDATA_NANOSEC0);
3536
+
3537
+ return 0;
3538
+}
3539
+
3540
+int setPTPClockEnable(void *cdata, int len){
3541
+ int ret;
3542
+
3543
+ FUNC_MSG_IN;
3544
+ ret = _setGeneralEnable(cdata, len, 0x09, P9REG_PTP_CONFIGURATION, 0);
3545
+ FUNC_MSG_OUT;
3546
+
3547
+ return ret;
3548
+}
3549
+
3550
+int getPTPClockEnable(void *cdata, int len){
3551
+ int ret;
3552
+
3553
+ FUNC_MSG_IN;
3554
+ ret = _getGeneralEnable(cdata, len, 0x09, P9REG_PTP_CONFIGURATION, 0);
3555
+ FUNC_MSG_OUT;
3556
+
3557
+ return ret;
3558
+}
3559
+
3560
+int setPTPOverwriteEnable(void *cdata, int len){
3561
+ int ret;
3562
+
3563
+ FUNC_MSG_IN;
3564
+ ret = _setGeneralEnable(cdata, len, 0x09, P9REG_PTP_CONFIGURATION, 1);
3565
+ FUNC_MSG_OUT;
3566
+
3567
+ return ret;
3568
+}
3569
+
3570
+int getPTPOverwriteEnable(void *cdata, int len){
3571
+ int ret;
3572
+
3573
+ FUNC_MSG_IN;
3574
+ ret = _getGeneralEnable(cdata, len, 0x09, P9REG_PTP_CONFIGURATION, 1);
3575
+ FUNC_MSG_OUT;
3576
+
3577
+ return ret;
3578
+}
3579
+
3580
+int setPTPProgrammable(void *cdata, int len){
3581
+ int ret;
3582
+
3583
+ FUNC_MSG_IN;
3584
+ ret = _setGeneralEnable(cdata, len, 0x09, P9REG_PTP_CONFIGURATION, 2);
3585
+ FUNC_MSG_OUT;
3586
+
3587
+ return ret;
3588
+}
3589
+
3590
+int getPTPProgrammable(void *cdata, int len){
3591
+ int ret;
3592
+
3593
+ FUNC_MSG_IN;
3594
+ ret = _getGeneralEnable(cdata, len, 0x09, P9REG_PTP_CONFIGURATION, 2);
3595
+ FUNC_MSG_OUT;
3596
+
3597
+ return ret;
3598
+}
3599
+
3600
+int setPTPProgrammableOut(void *cdata, int len){
3601
+ int ret;
3602
+
3603
+ FUNC_MSG_IN;
3604
+ ret = _setGeneralEnable(cdata, len, 0x09, P9REG_PTP_CONFIGURATION, 9);
3605
+ FUNC_MSG_OUT;
3606
+
3607
+ return ret;
3608
+}
3609
+
3610
+int setPTPTimestampEnable(void *cdata, int len){
3611
+ unsigned int cmd=0, i=0;
3612
+ struct PTPPortTSSetting* pts=(struct PTPPortTSSetting*)cdata;
3613
+
3614
+ if(sizeof(struct PTPPortTSSetting)!=len)
3615
+ return -EINVAL;
3616
+ IP2Page(0x09);
3617
+ for(i=0;i<MAX_PHY_NUM;i++){
3618
+ if((i%8)==0){
3619
+ cmd=Read_Reg(P9REG_PTP_PORT_TIMESTAMP0+(i/8));
3620
+ }
3621
+
3622
+ if((pts->portmap&(0x01<<i))!=0){
3623
+ if(pts->pmdata==OP_FUNC_ENABLE){
3624
+ if(pts->in_out){
3625
+ //egress
3626
+ cmd|=0x01<<(1+(2*(i%8)));
3627
+ }
3628
+ else{
3629
+ //ingress
3630
+ cmd|=0x01<<(2*(i%8));
3631
+ }
3632
+ }
3633
+ else{
3634
+ if(pts->in_out){
3635
+ //egress
3636
+ cmd&=~(0x01<<(1+(2*(i%8))));
3637
+ }
3638
+ else{
3639
+ //ingress
3640
+ cmd&=~(0x01<<(2*(i%8)));
3641
+ }
3642
+ }
3643
+ }
3644
+ if((i%8)==7){
3645
+ Write_Reg(P9REG_PTP_PORT_TIMESTAMP0+(i/8), (u16)cmd);
3646
+ }
3647
+ }
3648
+ Write_Reg(P9REG_PTP_PORT_TIMESTAMP0+(i/8), (u16)cmd);
3649
+
3650
+ return 0;
3651
+}
3652
+
3653
+int getPTPTimestampEnable(void *cdata, int len){
3654
+ unsigned int cmd=0, i=0;
3655
+ struct PTPPortTSSetting* pts=(struct PTPPortTSSetting*)cdata;
3656
+
3657
+ if(sizeof(struct PTPPortTSSetting)!=len)
3658
+ return -EINVAL;
3659
+
3660
+ pts->pmdata=OP_FUNC_ENABLE;
3661
+ pts->portmap=0;
3662
+ IP2Page(0x09);
3663
+ for(i=0;i<MAX_PHY_NUM;i++){
3664
+ if((i%8)==0)
3665
+ cmd=Read_Reg(P9REG_PTP_PORT_TIMESTAMP0+(i/8));
3666
+
3667
+ if(pts->in_out){
3668
+ //egress
3669
+ if((cmd&(0x01<<(1+(2*(i%8)))))!=0)
3670
+ pts->portmap|=(0x01<<i);
3671
+ }
3672
+ else{
3673
+ //ingress
3674
+ if((cmd&(0x01<<(2*(i%8))))!=0)
3675
+ pts->portmap|=(0x01<<i);
3676
+ }
3677
+ }
3678
+
3679
+ return 0;
3680
+}
3681
+
3682
+int setPTPTimestampClear(void *cdata, int len){
3683
+ unsigned int cmd=0, i=0;
3684
+ struct PTPPortTSSetting* pts=(struct PTPPortTSSetting*)cdata;
3685
+
3686
+ if(sizeof(struct PTPPortTSSetting)!=len)
3687
+ return -EINVAL;
3688
+
3689
+ IP2Page(0x09);
3690
+ for(i=0;i<MAX_PHY_NUM;i++){
3691
+ if((pts->portmap&(0x01<<i))!=0){
3692
+ if(pts->in_out){
3693
+ //egress
3694
+ cmd|=0x01<<(1+(2*(i%8)));
3695
+ }
3696
+ else{
3697
+ //ingress
3698
+ cmd|=0x01<<(2*(i%8));
3699
+ }
3700
+ }
3701
+ if((i%8)==7 && cmd!=0){
3702
+ Write_Reg(P9REG_PTP_TIMESTAMP_CLEAR0+(i/8), (u16)cmd);
3703
+ cmd=0;
3704
+ }
3705
+ }
3706
+ if(cmd){
3707
+ Write_Reg(P9REG_PTP_TIMESTAMP_CLEAR0+(i/8), (u16)cmd);
3708
+ }
3709
+
3710
+ return 0;
3711
+}
3712
+
3713
+int setPTPTimeData(void *cdata, int len){
3714
+ struct PTPTimeSetting* ts=(struct PTPTimeSetting*)cdata;
3715
+
3716
+ if(sizeof(struct PTPTimeSetting)!=len)
3717
+ return -EINVAL;
3718
+
3719
+ IP2Page(0x09);
3720
+ Write_Reg(P9REG_PTP_TIMEDATA_SEC0, (u16)(ts->second&0xFFFF));
3721
+ Write_Reg(P9REG_PTP_TIMEDATA_SEC1, (u16)((ts->second>>16)&0xFFFF));
3722
+ Write_Reg(P9REG_PTP_TIMEDATA_SEC2, (u16)((ts->second>>32)&0xFFFF));
3723
+ Write_Reg(P9REG_PTP_TIMEDATA_NANOSEC0, (u16)(ts->nanosecond&0xFFFF));
3724
+ Write_Reg(P9REG_PTP_TIMEDATA_NANOSEC1, (u16)((ts->nanosecond>>16)&0x3FFF));
3725
+ Write_Reg(P9REG_PTP_CLOCK_CONTROL, 0x03);
3726
+
3727
+ return 0;
3728
+}
3729
+
3730
+int getPTPTimeData(void *cdata, int len){
3731
+ struct PTPTimeSetting* ts=(struct PTPTimeSetting*)cdata;
3732
+
3733
+ if(sizeof(struct PTPTimeSetting)!=len)
3734
+ return -EINVAL;
3735
+
3736
+ IP2Page(0x09);
3737
+ Write_Reg(P9REG_PTP_TIMESTAMP_READ, 0);
3738
+ Write_Reg(P9REG_PTP_CLOCK_CONTROL, 0x01);
3739
+
3740
+ ts->second=Read_Reg(P9REG_PTP_TIMEDATA_SEC2);
3741
+ ts->second<<=16;
3742
+ ts->second=Read_Reg(P9REG_PTP_TIMEDATA_SEC1);
3743
+ ts->second<<=16;
3744
+ ts->second|=Read_Reg(P9REG_PTP_TIMEDATA_SEC0);
3745
+
3746
+ ts->nanosecond=Read_Reg(P9REG_PTP_TIMEDATA_NANOSEC1);
3747
+ ts->nanosecond<<=16;
3748
+ ts->nanosecond|=Read_Reg(P9REG_PTP_TIMEDATA_NANOSEC0);
3749
+
3750
+ return 0;
3751
+}
3752
+
3753
+int addPTPTimeData(void *cdata, int len){
3754
+ struct PTPTimeSetting* ts=(struct PTPTimeSetting*)cdata;
3755
+
3756
+ if(sizeof(struct PTPTimeSetting)!=len)
3757
+ return -EINVAL;
3758
+
3759
+ IP2Page(0x09);
3760
+ Write_Reg(P9REG_PTP_TIMEDATA_SEC0, (u16)(ts->second&0xFFFF));
3761
+ Write_Reg(P9REG_PTP_TIMEDATA_SEC1, (u16)((ts->second>>16)&0xFFFF));
3762
+// Write_Reg(P9REG_PTP_TIMEDATA_SEC2, (u16)((ts->second>>32)&0xFFFF));
3763
+ Write_Reg(P9REG_PTP_TIMEDATA_NANOSEC0, (u16)(ts->nanosecond&0xFFFF));
3764
+ Write_Reg(P9REG_PTP_TIMEDATA_NANOSEC1, (u16)((ts->nanosecond>>16)&0x3FFF));
3765
+ Write_Reg(P9REG_PTP_CLOCK_CONTROL, 0x05);
3766
+
3767
+ return 0;
3768
+}
3769
+
3770
+int subPTPTimeData(void *cdata, int len){
3771
+ struct PTPTimeSetting* ts=(struct PTPTimeSetting*)cdata;
3772
+
3773
+ if(sizeof(struct PTPTimeSetting)!=len)
3774
+ return -EINVAL;
3775
+
3776
+ IP2Page(0x09);
3777
+ Write_Reg(P9REG_PTP_TIMEDATA_SEC0, (u16)(ts->second&0xFFFF));
3778
+ Write_Reg(P9REG_PTP_TIMEDATA_SEC1, (u16)((ts->second>>16)&0xFFFF));
3779
+// Write_Reg(P9REG_PTP_TIMEDATA_SEC2, (u16)((ts->second>>32)&0xFFFF));
3780
+ Write_Reg(P9REG_PTP_TIMEDATA_NANOSEC0, (u16)(ts->nanosecond&0xFFFF));
3781
+ Write_Reg(P9REG_PTP_TIMEDATA_NANOSEC1, (u16)((ts->nanosecond>>16)&0x3FFF));
3782
+ Write_Reg(P9REG_PTP_CLOCK_CONTROL, 0x07);
3783
+
3784
+ return 0;
3785
+}
3786
+
3787
+int setPTPFrequencyAdd(void *cdata, int len){
3788
+ struct PTPFrequencySetting* fs=(struct PTPFrequencySetting*)cdata;
3789
+
3790
+ if(sizeof(struct PTPFrequencySetting)!=len)
3791
+ return -EINVAL;
3792
+
3793
+ IP2Page(0x09);
3794
+ Write_Reg(P9REG_PTP_FREQUENCY_ADD0, (u16)(fs->frequency&0xFFFF));
3795
+ Write_Reg(P9REG_PTP_FREQUENCY_ADD1, (u16)((fs->frequency>>16)&0xFFFF));
3796
+
3797
+ return 0;
3798
+}
3799
+
3800
+int getPTPFrequencyAdd(void *cdata, int len){
3801
+ struct PTPFrequencySetting* fs=(struct PTPFrequencySetting*)cdata;
3802
+
3803
+ if(sizeof(struct PTPFrequencySetting)!=len)
3804
+ return -EINVAL;
3805
+
3806
+ IP2Page(0x09);
3807
+ fs->frequency=Read_Reg(P9REG_PTP_FREQUENCY_ADD1);
3808
+ fs->frequency<<=16;
3809
+ fs->frequency|=Read_Reg(P9REG_PTP_FREQUENCY_ADD0);
3810
+
3811
+ return 0;
3812
+}
3813
+
3814
+int setPTPClockPeriod(void *cdata, int len){
3815
+ if(sizeof(struct GeneralSetting)!=len)
3816
+ return -EINVAL;
3817
+
3818
+ IP2Page(0x09);
3819
+ Write_Reg(P9REG_PTP_CLOCK_PERIOD, (u16)(((struct GeneralSetting*)cdata)->gdata)&0xFFFF);
3820
+
3821
+ return 0;
3822
+}
3823
+
3824
+int getPTPClockPeriod(void *cdata, int len){
3825
+ if(sizeof(struct GeneralSetting)!=len)
3826
+ return -EINVAL;
3827
+
3828
+ IP2Page(0x09);
3829
+ ((struct GeneralSetting*)cdata)->gdata=Read_Reg(P9REG_PTP_CLOCK_PERIOD);
3830
+
3831
+ return 0;
3832
+}
3833
+
3834
+int setPTPProgrammableConfig(void *cdata, int len){
3835
+ if(sizeof(struct GeneralSetting)!=len)
3836
+ return -EINVAL;
3837
+
3838
+ IP2Page(0x09);
3839
+ Write_Reg(P9REG_PTP_PROGRAMMABLE_OUTPUT, (u16)(((struct GeneralSetting*)cdata)->gdata)&0xFFFF);
3840
+
3841
+ return 0;
3842
+}
3843
+
3844
+int setPTPDurationFrequencyCompensation(void *cdata, int len){
3845
+ struct PTPFrequencySetting* fs=(struct PTPFrequencySetting*)cdata;
3846
+
3847
+ if(sizeof(struct PTPFrequencySetting)!=len)
3848
+ return -EINVAL;
3849
+
3850
+ IP2Page(0x09);
3851
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION0, (u16)(fs->frequency&0xFFFF));
3852
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION1, (u16)((fs->frequency>>16)&0x3FF));
3853
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION2, (u16)(fs->clockcycle&0xFFFF));
3854
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION3, (u16)((fs->clockcycle>>16)&0x3FF));
3855
+ if(fs->type==1){
3856
+ //add
3857
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION_CONTROL, 0x03);
3858
+ }
3859
+ else{
3860
+ //sub
3861
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION_CONTROL, 0x07);
3862
+ }
3863
+ //Wait a period of time
3864
+ ndelay(fs->period_time);
3865
+
3866
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION_CONTROL, 0x0);
3867
+
3868
+ return 0;
3869
+}
3870
+
3871
+int setPTPAlwaysFrequencyCompensation(void *cdata, int len){
3872
+ struct PTPFrequencyPPMSetting* fps=(struct PTPFrequencyPPMSetting*)cdata;
3873
+
3874
+ if(sizeof(struct PTPFrequencyPPMSetting)!=len)
3875
+ return -EINVAL;
3876
+
3877
+ IP2Page(0x09);
3878
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION0, (u16)(fps->ppm_l));
3879
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION1, (u16)(fps->ppm_h));
3880
+ if(fps->type==1){
3881
+ //add
3882
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION_CONTROL, 0x01);
3883
+ }
3884
+ else{
3885
+ //Sub
3886
+ Write_Reg(P9REG_PTP_FREQUENCY_COMPENSATION_CONTROL, 0x05);
3887
+ }
3888
+
3889
+ return 0;
3890
+}
3891
+
3892
+int getPTPIngressLatency10(void *cdata, int len){
3893
+ if(sizeof(struct GeneralSetting)!=len)
3894
+ return -EINVAL;
3895
+
3896
+ IP2Page(0x09);
3897
+ ((struct GeneralSetting*)cdata)->gdata=Read_Reg(P9REG_PTP_INGRESS_LATENCY_10TP);
3898
+
3899
+ return 0;
3900
+}
3901
+
3902
+int getPTPIngressLatency100(void *cdata, int len){
3903
+ if(sizeof(struct GeneralSetting)!=len)
3904
+ return -EINVAL;
3905
+
3906
+ IP2Page(0x09);
3907
+ ((struct GeneralSetting*)cdata)->gdata=Read_Reg(P9REG_PTP_INGRESS_LATENCY_100TP);
3908
+
3909
+ return 0;
3910
+}
3911
+
3912
+int getPTPIngressLatencyFiber(void *cdata, int len){
3913
+ if(sizeof(struct GeneralSetting)!=len)
3914
+ return -EINVAL;
3915
+
3916
+ IP2Page(0x09);
3917
+ ((struct GeneralSetting*)cdata)->gdata=Read_Reg(P9REG_PTP_INGRESS_LATENCY_FIBER);
3918
+
3919
+ return 0;
3920
+}
3921
+
3922
+int getPTPEgressLatency10(void *cdata, int len){
3923
+ if(sizeof(struct GeneralSetting)!=len)
3924
+ return -EINVAL;
3925
+
3926
+ IP2Page(0x09);
3927
+ ((struct GeneralSetting*)cdata)->gdata=Read_Reg(P9REG_PTP_EGRESS_LATENCY_10TP);
3928
+
3929
+ return 0;
3930
+}
3931
+
3932
+int getPTPEgressLatency100(void *cdata, int len){
3933
+ if(sizeof(struct GeneralSetting)!=len)
3934
+ return -EINVAL;
3935
+
3936
+ IP2Page(0x09);
3937
+ ((struct GeneralSetting*)cdata)->gdata=Read_Reg(P9REG_PTP_EGRESS_LATENCY_100TP);
3938
+
3939
+ return 0;
3940
+}
3941
+
3942
+int getPTPEgressLatencyFiber(void *cdata, int len){
3943
+ if(sizeof(struct GeneralSetting)!=len)
3944
+ return -EINVAL;
3945
+
3946
+ IP2Page(0x09);
3947
+ ((struct GeneralSetting*)cdata)->gdata=Read_Reg(P9REG_PTP_EGRESS_LATENCY_FIBER);
3948
+
3949
+ return 0;
3950
+}
3951
+//------------ PTP functions:common end -----------------------
3952
+
3953
+int switchdConfigCpuPort(int portid)
3954
+{
3955
+ ip1811drv_dbg("portid=%d\n", portid);
3956
+ if (portid < 0 || portid >= 12)
3957
+ return -EINVAL;
3958
+
3959
+ IP2Page(1);
3960
+ Write_Reg(P1REG_CONFIG_CPUPORT, (portid + 1) | 0x20);
3961
+
3962
+ return 0;
3963
+}
3964
+EXPORT_SYMBOL(switchdConfigCpuPort);
3965
+int configCpuPort(void *cdata, int len)
3966
+{
3967
+ int portid;
3968
+
3969
+ ip1811drv_dbg("ip1811: +configCpuPort...\n");
3970
+ if (sizeof(struct GeneralSetting) != len)
3971
+ return -EINVAL;
3972
+
3973
+ portid = ((struct GeneralSetting *)cdata) ->gdata;
3974
+
3975
+ if(switchdConfigCpuPort(portid) != 0)
3976
+ return -EINVAL;
3977
+
3978
+ ip1811drv_dbg("ip1811: -configCpuPort...\n");
3979
+ return 0;
3980
+}
3981
+
3982
+int switchdGetCpuPort(int *ptrVal)
3983
+{
3984
+ *ptrVal = Read_Reg(P1REG_CONFIG_CPUPORT);
3985
+ ip1811drv_dbg("portid=%d\n", *ptrVal);
3986
+
3987
+ return 0;
3988
+}
3989
+EXPORT_SYMBOL(switchdGetCpuPort);
3990
+int getCpuPort(void *cdata, int len)
3991
+{
3992
+ int portid;
3993
+
3994
+ ip1811drv_dbg("ip1811: +getCpuPort...\n");
3995
+ if (sizeof(struct GeneralSetting) != len)
3996
+ return -EINVAL;
3997
+
3998
+
3999
+ if(switchdGetCpuPort(&portid) != 0)
4000
+ return -EINVAL;
4001
+
4002
+ ((struct GeneralSetting *)cdata) ->gdata = portid;
4003
+ ip1811drv_dbg("ip1811: -getCpuPort...\n");
4004
+ return 0;
4005
+}
4006
+//------------------------------------------------
4007
+//common_misc
4008
+
4009
+int switchdSet8021xFunc(int en, unsigned long pm)
4010
+{
4011
+ unsigned long reg16;
4012
+
4013
+ if (pm & 0xF0000000)
4014
+ return -EINVAL;
4015
+ if (en != OP_FUNC_ENABLE && en != OP_FUNC_DISABLE)
4016
+ return -EINVAL;
4017
+
4018
+ IP2Page(0);
4019
+ if(en == OP_FUNC_ENABLE) {
4020
+ reg16 = Read_Reg(P0REG_PORTLOCKEN);
4021
+ Write_Reg(P0REG_PORTLOCKEN, (u16)(reg16 | pm));
4022
+ } else {//OP_FUNC_DISABLE
4023
+ reg16 = Read_Reg(P0REG_PORTLOCKEN);
4024
+ Write_Reg(P0REG_PORTLOCKEN, (u16)(reg16 & ~pm));
4025
+ }
4026
+ return 0;
4027
+}
4028
+EXPORT_SYMBOL(switchdSet8021xFunc);
4029
+
4030
+int set8021xFunc(void *cdata, int len)
4031
+{
4032
+ unsigned long pm;
4033
+ int en, ret;
4034
+
4035
+ ip1811drv_dbg("ip1811: +set8021xFunc...\n");
4036
+ if (sizeof(struct PortmapSetting) != len)
4037
+ return -EINVAL;
4038
+
4039
+ pm = ((struct PortmapSetting *)cdata) ->portmap;
4040
+ en = ((struct PortmapSetting *)cdata) ->pmdata;
4041
+
4042
+ ip1811drv_dbg("pm=0x%08x\n", (unsigned int)pm);
4043
+ ip1811drv_dbg("en=%d\n", en);
4044
+ ret = switchdSet8021xFunc(en, pm);
4045
+
4046
+ ip1811drv_dbg("ip1811: -set8021xFunc...\n");
4047
+ return ret;
4048
+}
4049
+
4050
+int switchdGet8021xFunc(int *gdata_p)
4051
+{
4052
+ IP2Page(0);
4053
+ *gdata_p = (int)Read_Reg(P0REG_PORTLOCKEN);
4054
+ return 0;
4055
+}
4056
+EXPORT_SYMBOL(switchdGet8021xFunc);
4057
+
4058
+int get8021xFunc(void *cdata, int len)
4059
+{
4060
+ int val, ret;
4061
+
4062
+ ip1811drv_dbg("ip1811: +get8021xFunc...\n");
4063
+ if (sizeof(struct PortmapSetting) != len)
4064
+ return -EINVAL;
4065
+
4066
+ ret = switchdGet8021xFunc(&val);
4067
+ ((struct PortmapSetting *)cdata) ->portmap = (val & ALL_PHY_PORTS_LIST);
4068
+ ((struct PortmapSetting *)cdata) ->pmdata = val?OP_FUNC_ENABLE:OP_FUNC_DISABLE;
4069
+ ip1811drv_dbg("cdata ->portmap=0x%08x\n", (unsigned int)((struct PortmapSetting *)cdata) ->portmap);
4070
+ ip1811drv_dbg("cdata ->pmdata=%d\n", ((struct PortmapSetting *)cdata) ->pmdata);
4071
+ ip1811drv_dbg("ip1811: -get8021xFunc...\n");
4072
+ return ret;
4073
+}
4074
+
4075
+int switchdSetReg(u8 page, u8 reg, u16 val)
4076
+{
4077
+ if (page > 0xE)
4078
+ return -EINVAL;
4079
+ ip1811drv_dbg("page=0x%x\n", page);
4080
+ ip1811drv_dbg("reg=0x%02X\n", reg);
4081
+ ip1811drv_dbg("val=0x%04x\n", val);
4082
+
4083
+ _IP2Page(page);
4084
+ // ip1811drv_dbg("RegList[%x][0x%02X]=0x%04x\n", pg, P2REG_VLANCFG,
4085
+ // RegList[pg][P2REG_VLANCFG]);
4086
+ _Write_Reg(reg, val);
4087
+
4088
+ // ip1811drv_dbg("RegList[%x][0x%02X]=0x%04x\n", pg, P2REG_VLANCFG,
4089
+ // RegList[pg][P2REG_VLANCFG]);
4090
+ ip1811drv_dbg("ip1811: -setReg...\n");
4091
+
4092
+ return 0;
4093
+}
4094
+EXPORT_SYMBOL(switchdSetReg);
4095
+int setReg(void *cdata, int len)
4096
+{
4097
+ u8 page, reg;
4098
+ u16 val;
4099
+
4100
+ ip1811drv_dbg("ip1811: +setReg...\n");
4101
+ if (sizeof(struct RegSetting) != len)
4102
+ return -EINVAL;
4103
+
4104
+ page= ((struct RegSetting *)cdata) ->page;
4105
+ reg = ((struct RegSetting *)cdata) ->reg;
4106
+ val = ((struct RegSetting *)cdata) ->val;
4107
+
4108
+ if(switchdSetReg(page, reg, val) != 0)
4109
+ return -EINVAL;
4110
+
4111
+ return 0;
4112
+}
4113
+
4114
+
4115
+int switchdGetReg(u8 page, u8 reg, u16 *ptrVal)
4116
+{
4117
+
4118
+ if (page > 0xE)
4119
+ return -EINVAL;
4120
+ ip1811drv_dbg("page=0x%x\n", page);
4121
+ printk("page=0x%x\n", page);
4122
+ ip1811drv_dbg("reg=0x%02X\n", reg);
4123
+ printk("reg=0x%02X\n", reg);
4124
+
4125
+ _IP2Page(page);
4126
+ // ip1811drv_dbg("RegList[%x][0x%02X]=0x%04x\n", pg, P2REG_VLANCFG,
4127
+ // RegList[pg][P2REG_VLANCFG]);
4128
+ *ptrVal= _Read_Reg(reg);
4129
+ ip1811drv_dbg("u16dat=0x%04x\n", *ptrVal);
4130
+ printk("u16dat=0x%04x\n", *ptrVal);
4131
+
4132
+ // ip1811drv_dbg("RegList[%x][0x%02X]=0x%04x\n", pg, P2REG_VLANCFG,
4133
+ // RegList[pg][P2REG_VLANCFG]);
4134
+ ip1811drv_dbg("cdata ->val=0x%04x\n", *ptrVal);
4135
+ ip1811drv_dbg("ip1811: -getReg...\n");
4136
+
4137
+ return 0;
4138
+}
4139
+EXPORT_SYMBOL(switchdGetReg);
4140
+int getReg(void *cdata, int len)
4141
+{
4142
+ u8 page, reg;
4143
+ u16 u16dat;
4144
+
4145
+ printk("ip1811: +getReg...\n");
4146
+ ip1811drv_dbg("ip1811: +getReg...\n");
4147
+ if (sizeof(struct RegSetting) != len)
4148
+ return -EINVAL;
4149
+
4150
+ page= ((struct RegSetting *)cdata) ->page;
4151
+ reg = ((struct RegSetting *)cdata) ->reg;
4152
+
4153
+ if(switchdGetReg(page, reg, &u16dat) != 0)
4154
+ return -EINVAL;
4155
+
4156
+ ((struct RegSetting *)cdata) ->val = (unsigned short)u16dat;
4157
+ return 0;
4158
+}
4159
+
4160
+void switchdGetCPUReg(unsigned long reg, int * ptrVal)
4161
+{
4162
+ volatile unsigned int *p;
4163
+
4164
+ p = (unsigned int *)(reg);
4165
+ *ptrVal = *p;
4166
+
4167
+ ip1811drv_dbg("reg=%lX\n", reg);
4168
+ ip1811drv_dbg("get val=%X\n", *ptrVal);
4169
+}
4170
+EXPORT_SYMBOL(switchdGetCPUReg);
4171
+int getCPUReg(void *cdata, int len)
4172
+{
4173
+ unsigned long reg;
4174
+ int val;
4175
+
4176
+ FUNC_MSG_IN;
4177
+
4178
+ if (sizeof(struct PortmapSetting) != len){
4179
+ ip1811drv_err("Error: lengtn=%d\n", len);
4180
+ return -EINVAL;
4181
+ }
4182
+ reg = ((struct PortmapSetting *)cdata) ->portmap;
4183
+
4184
+ switchdGetCPUReg(reg, &val);
4185
+
4186
+ ((struct PortmapSetting *)cdata) ->pmdata = val;
4187
+ ip1811delay();
4188
+ FUNC_MSG_OUT;
4189
+ return 0;
4190
+}
4191
+
4192
+void switchdSetCPUReg(unsigned long reg, int val)
4193
+{
4194
+ volatile unsigned int *p;
4195
+
4196
+ p = (unsigned int *)(reg);
4197
+ *p = val;
4198
+
4199
+ ip1811drv_dbg("reg=%lX\n", reg);
4200
+ ip1811drv_dbg("set val=%X\n", val);
4201
+}
4202
+EXPORT_SYMBOL(switchdSetCPUReg);
4203
+int setCPUReg(void *cdata, int len)
4204
+{
4205
+ unsigned long reg;
4206
+ int val;
4207
+
4208
+ FUNC_MSG_IN;
4209
+
4210
+ if (sizeof(struct PortmapSetting) != len){
4211
+ ip1811drv_err("Error: lengtn=%d\n", len);
4212
+ return -EINVAL;
4213
+ }
4214
+
4215
+ reg = ((struct PortmapSetting *)cdata) ->portmap;
4216
+ val = ((struct PortmapSetting *)cdata) ->pmdata;
4217
+
4218
+ switchdSetCPUReg(reg, val);
4219
+
4220
+ ip1811delay();
4221
+
4222
+
4223
+ FUNC_MSG_OUT;
4224
+ return 0;
4225
+}
4226
+
4227
+int switchdSetSwitchRestart(int en)
4228
+{
4229
+ if(en!=OP_FUNC_ENABLE){
4230
+ ip1811drv_err("Error: en=%d\n", en);
4231
+ return -EINVAL;
4232
+ }
4233
+ ip1811drv_dbg("reset the switch of IP1811, all parameters are maintained\n");
4234
+ _WriteRegBits(0xE, PEREG_SW_RESET, 0, 1, en);
4235
+
4236
+ return 0;
4237
+}
4238
+EXPORT_SYMBOL(switchdSetSwitchRestart);
4239
+int setSwitchRestart(void *cdata, int len)
4240
+{
4241
+ int en;
4242
+ FUNC_MSG_IN;
4243
+
4244
+ if (sizeof(struct GeneralSetting) != len){
4245
+ ip1811drv_err("Error: lengtn=%d\n", len);
4246
+ return -EINVAL;
4247
+ }
4248
+
4249
+ en = ((struct GeneralSetting *)cdata) ->gdata;
4250
+
4251
+ if(switchdSetSwitchRestart(en) != 0)
4252
+ return -EINVAL;
4253
+
4254
+ FUNC_MSG_OUT;
4255
+ return 0;
4256
+}
4257
+
4258
+int switchdSetSwitchReset(int en)
4259
+{
4260
+
4261
+ if(en!=OP_FUNC_ENABLE){
4262
+ ip1811drv_err("Error: en=%d\n", en);
4263
+ return -EINVAL;
4264
+ }
4265
+ ip1811drv_dbg("reset the switch of IP1811, all parameters are reset to default\n");
4266
+ _WriteRegBits(0xE, PEREG_SW_RESET, 4, 1, en);
4267
+
4268
+ return 0;
4269
+}
4270
+EXPORT_SYMBOL(switchdSetSwitchReset);
4271
+int setSwitchReset(void *cdata, int len)
4272
+{
4273
+ int en;
4274
+
4275
+ FUNC_MSG_IN;
4276
+
4277
+ if (sizeof(struct GeneralSetting) != len){
4278
+ ip1811drv_err("Error: lengtn=%d\n", len);
4279
+ return -EINVAL;
4280
+ }
4281
+ en = ((struct GeneralSetting *)cdata) ->gdata;
4282
+
4283
+ if(switchdSetSwitchReset(en) != 0)
4284
+ return -EINVAL;
4285
+
4286
+ FUNC_MSG_OUT;
4287
+ return 0;
4288
+}
4289
+
4290
+void switchdSetCpuIfSpeed(int type)
4291
+{
4292
+ CPU_IF_SPEED_NORMAL = type;
4293
+ printk("\nip1811: set CPU I/F speed to %s\n",CPU_IF_SPEED_NORMAL?"Normal":"High");
4294
+}
4295
+EXPORT_SYMBOL(switchdSetCpuIfSpeed);
4296
+int setCpuIfSpeed(void *cdata, int len)
4297
+{
4298
+ int type;
4299
+ FUNC_MSG_IN;
4300
+
4301
+ if (sizeof(struct GeneralSetting) != len){
4302
+ ip1811drv_err("Error: lengtn=%d\n", len);
4303
+ return -EINVAL;
4304
+ }
4305
+
4306
+ switchdSetCpuIfSpeed(type);
4307
+
4308
+ FUNC_MSG_OUT;
4309
+ return 0;
4310
+}
4311
+//------------ CoS functions:common -----------------------------
4312
+int setCosTcpUdpUserDefine(void *cdata, int len)
4313
+{
4314
+ unsigned int ptcl;
4315
+ int act;
4316
+
4317
+ FUNC_MSG_IN;
4318
+ if (sizeof(struct CapActSetting) != len)
4319
+ {
4320
+ ip1811drv_err("Error: length=%d\n", len);
4321
+ return -EINVAL;
4322
+ }
4323
+
4324
+ ptcl = ((struct CapActSetting *)cdata) ->protocol;
4325
+ act = ((struct CapActSetting *)cdata) ->act;
4326
+
4327
+ if( ptcl >= OP_TCPUDP_USER_TOTALNUM)
4328
+ {
4329
+ ip1811drv_err("Error: protocol=%X\n", ptcl);
4330
+ return -EINVAL;
4331
+ }
4332
+
4333
+ if( act < 0x0 || act > 0xFFFF )
4334
+ {
4335
+ ip1811drv_err("Error: act=%X\n", act);
4336
+ return -EINVAL;
4337
+ }
4338
+
4339
+ ip1811drv_dbg("cdata ->ptcl=%X\n", ptcl);
4340
+ ip1811drv_dbg("cdata ->act=%X\n", act);
4341
+
4342
+ IP2Page(0);
4343
+ Write_Reg(P0REG_TCPUDPUSERDEF + ptcl, (u16)act);
4344
+
4345
+ FUNC_MSG_OUT;
4346
+ return 0;
4347
+}
4348
+
4349
+int getCosTcpUdpUserDefine(void *cdata, int len)
4350
+{
4351
+ unsigned int ptcl;
4352
+ int act;
4353
+
4354
+ FUNC_MSG_IN;
4355
+ if (sizeof(struct CapActSetting) != len)
4356
+ {
4357
+ ip1811drv_err("Error: length=%d\n", len);
4358
+ return -EINVAL;
4359
+ }
4360
+
4361
+ ptcl = ((struct CapActSetting *)cdata) ->protocol;
4362
+
4363
+ if( ptcl >= OP_TCPUDP_USER_TOTALNUM)
4364
+ {
4365
+ ip1811drv_err("Error: protocol=%X\n", ptcl);
4366
+ return -EINVAL;
4367
+ }
4368
+
4369
+ IP2Page(0);
4370
+ act = Read_Reg(P0REG_TCPUDPUSERDEF + ptcl);
4371
+ ((struct CapActSetting *)cdata) ->act = act;
4372
+
4373
+ ip1811drv_dbg("cdata ->protocol=%X\n", ((struct CapActSetting *)cdata) ->protocol);
4374
+ ip1811drv_dbg("cdata ->act=%X\n", ((struct CapActSetting *)cdata) ->act);
4375
+ FUNC_MSG_OUT;
4376
+ return 0;
4377
+}
4378
+
4379
+int setCosTcpUdpQueue(void *cdata, int len)
4380
+{
4381
+ unsigned int ptcl;
4382
+ int act;
4383
+
4384
+ FUNC_MSG_IN;
4385
+ if (sizeof(struct CapActSetting) != len)
4386
+ {
4387
+ ip1811drv_err("Error: length=%d\n", len);
4388
+ return -EINVAL;
4389
+ }
4390
+
4391
+ ptcl = ((struct CapActSetting *)cdata) ->protocol;
4392
+ act = ((struct CapActSetting *)cdata) ->act;
4393
+
4394
+ if( ptcl >= OP_TCPUDP_PTCL_TOTALNUM)
4395
+ {
4396
+ ip1811drv_err("Error: protocol=%X\n", ptcl);
4397
+ return -EINVAL;
4398
+ }
4399
+
4400
+ if( act < OP_TCPUDP_ACT_Q0 || act > OP_TCPUDP_ACT_ALL_PORT || act == 0x8)
4401
+ {
4402
+ ip1811drv_err("Error: act=%X\n", act);
4403
+ return -EINVAL;
4404
+ }
4405
+
4406
+ ip1811drv_dbg("cdata ->ptcl=%X\n", ptcl);
4407
+ ip1811drv_dbg("cdata ->act=%X\n", act);
4408
+
4409
+ _WriteRegBits(0, P0REG_TCPUDPPRICFG + ptcl/4, (ptcl%4)*4, 4, act);
4410
+
4411
+ FUNC_MSG_OUT;
4412
+ return 0;
4413
+}
4414
+
4415
+int getCosTcpUdpQueue(void *cdata, int len)
4416
+{
4417
+ unsigned int ptcl;
4418
+ int act;
4419
+
4420
+ FUNC_MSG_IN;
4421
+ if (sizeof(struct CapActSetting) != len)
4422
+ {
4423
+ ip1811drv_err("Error: length=%d\n", len);
4424
+ return -EINVAL;
4425
+ }
4426
+
4427
+ ptcl = ((struct CapActSetting *)cdata) ->protocol;
4428
+
4429
+ if( ptcl >= OP_TCPUDP_PTCL_TOTALNUM)
4430
+ {
4431
+ ip1811drv_err("Error: protocol=%X\n", ptcl);
4432
+ return -EINVAL;
4433
+ }
4434
+
4435
+ act = _ReadRegBits(0, P0REG_TCPUDPPRICFG + (ptcl/4), (ptcl%4)*4, 4);
4436
+ ((struct CapActSetting *)cdata) ->act = act;
4437
+
4438
+ ip1811drv_dbg("cdata ->protocol=%X\n", ((struct CapActSetting *)cdata) ->protocol);
4439
+ ip1811drv_dbg("cdata ->act=%X\n", ((struct CapActSetting *)cdata) ->act);
4440
+ FUNC_MSG_OUT;
4441
+ return 0;
4442
+}
4443
+
4444
+int setCosTcpUdpEnable(void *cdata, int len)
4445
+{
4446
+ int ret;
4447
+ FUNC_MSG_IN;
4448
+ ret = _setPortmap(cdata, len, 0, P0REG_TCPUDFUNCEN);
4449
+ FUNC_MSG_OUT;
4450
+ return ret;
4451
+}
4452
+
4453
+int getCosTcpUdpEnable(void *cdata, int len)
4454
+{
4455
+ int ret;
4456
+ FUNC_MSG_IN;
4457
+ ret = _getPortmapMask(cdata, len, 0, P0REG_TCPUDFUNCEN);
4458
+ FUNC_MSG_OUT;
4459
+ return ret;
4460
+}
4461
+
4462
+int setCosTcpEnable(void *cdata, int len)
4463
+{
4464
+ unsigned int ptcl;
4465
+ int act;
4466
+
4467
+ FUNC_MSG_IN;
4468
+ if (sizeof(struct CapActSetting) != len)
4469
+ {
4470
+ ip1811drv_err("Error: length=%d\n", len);
4471
+ return -EINVAL;
4472
+ }
4473
+
4474
+ ptcl = ((struct CapActSetting *)cdata) ->protocol;
4475
+ act = ((struct CapActSetting *)cdata) ->act;
4476
+
4477
+ if( ptcl >= OP_TCPUDP_PTCL_TOTALNUM)
4478
+ {
4479
+ ip1811drv_err("Error: protocol=%X\n", ptcl);
4480
+ return -EINVAL;
4481
+ }
4482
+
4483
+ if( act != OP_FUNC_ENABLE && act != OP_FUNC_DISABLE)
4484
+ {
4485
+ ip1811drv_err("Error: act=%X\n", act);
4486
+ return -EINVAL;
4487
+ }
4488
+
4489
+ ip1811drv_dbg("cdata ->ptcl=%X\n", ptcl);
4490
+ ip1811drv_dbg("cdata ->act=%X\n", act);
4491
+
4492
+ /* check L3 TCP action */
4493
+ if(_ReadRegBits(0, P0REG_L3FRAMEGETCTRL, 2, 2) == OP_CAP_ACT_DROP)
4494
+ {
4495
+ ip1811drv_err("Error: L3 TCP action is drop\n");
4496
+ return -EINVAL;
4497
+ }
4498
+
4499
+ /* set register */
4500
+ _WriteRegBits(0, P0REG_TCPCHECKEN + (ptcl/16), (ptcl%16), 1, act);
4501
+
4502
+ FUNC_MSG_OUT;
4503
+ return 0;
4504
+}
4505
+
4506
+int getCosTcpEnable(void *cdata, int len)
4507
+{
4508
+ unsigned int ptcl;
4509
+ int act;
4510
+
4511
+ FUNC_MSG_IN;
4512
+ if (sizeof(struct CapActSetting) != len)
4513
+ {
4514
+ ip1811drv_err("Error: length=%d\n", len);
4515
+ return -EINVAL;
4516
+ }
4517
+
4518
+ ptcl = ((struct CapActSetting *)cdata) ->protocol;
4519
+
4520
+ if( ptcl >= OP_TCPUDP_PTCL_TOTALNUM)
4521
+ {
4522
+ ip1811drv_err("Error: protocol=%X\n", ptcl);
4523
+ return -EINVAL;
4524
+ }
4525
+
4526
+ act = _ReadRegBits(0, P0REG_TCPCHECKEN + (ptcl/16), (ptcl%16), 1);
4527
+ ((struct CapActSetting *)cdata) ->act = act;
4528
+
4529
+ ip1811drv_dbg("cdata ->protocol=%X\n", ((struct CapActSetting *)cdata) ->protocol);
4530
+ ip1811drv_dbg("cdata ->act=%X\n", ((struct CapActSetting *)cdata) ->act);
4531
+ FUNC_MSG_OUT;
4532
+ return 0;
4533
+}
4534
+
4535
+int setCosUdpEnable(void *cdata, int len)
4536
+{
4537
+ unsigned int ptcl;
4538
+ int act;
4539
+
4540
+ FUNC_MSG_IN;
4541
+ if (sizeof(struct CapActSetting) != len)
4542
+ {
4543
+ ip1811drv_err("Error: length=%d\n", len);
4544
+ return -EINVAL;
4545
+ }
4546
+
4547
+ ptcl = ((struct CapActSetting *)cdata) ->protocol;
4548
+ act = ((struct CapActSetting *)cdata) ->act;
4549
+
4550
+ if( ptcl >= OP_TCPUDP_PTCL_TOTALNUM)
4551
+ {
4552
+ ip1811drv_err("Error: protocol=%X\n", ptcl);
4553
+ return -EINVAL;
4554
+ }
4555
+
4556
+ if( act != OP_FUNC_ENABLE && act != OP_FUNC_DISABLE)
4557
+ {
4558
+ ip1811drv_err("Error: act=%X\n", act);
4559
+ return -EINVAL;
4560
+ }
4561
+
4562
+ ip1811drv_dbg("cdata ->ptcl=%X\n", ptcl);
4563
+ ip1811drv_dbg("cdata ->act=%X\n", act);
4564
+
4565
+ /* check L3 UDP action */
4566
+ if(_ReadRegBits(0, P0REG_L3FRAMEGETCTRL, 4, 2) == OP_CAP_ACT_DROP)
4567
+ {
4568
+ ip1811drv_err("Error: L3 UDP action is drop\n");
4569
+ return -EINVAL;
4570
+ }
4571
+
4572
+ /* set register */
4573
+ _WriteRegBits(0, (P0REG_UDPCHECKEN + ptcl/16), (ptcl%16), 1, act);
4574
+
4575
+ FUNC_MSG_OUT;
4576
+ return 0;
4577
+}
4578
+
4579
+int getCosUdpEnable(void *cdata, int len)
4580
+{
4581
+ unsigned int ptcl;
4582
+ int act;
4583
+
4584
+ FUNC_MSG_IN;
4585
+ if (sizeof(struct CapActSetting) != len)
4586
+ {
4587
+ ip1811drv_err("Error: length=%d\n", len);
4588
+ return -EINVAL;
4589
+ }
4590
+
4591
+ ptcl = ((struct CapActSetting *)cdata) ->protocol;
4592
+
4593
+ if( ptcl >= OP_TCPUDP_PTCL_TOTALNUM)
4594
+ {
4595
+ ip1811drv_err("Error: protocol=%X\n", ptcl);
4596
+ return -EINVAL;
4597
+ }
4598
+
4599
+ act = _ReadRegBits(0, (P0REG_UDPCHECKEN + ptcl/16), (ptcl%16), 1);
4600
+ ((struct CapActSetting *)cdata) ->act = act;
4601
+
4602
+ ip1811drv_dbg("cdata ->protocol=%X\n", ((struct CapActSetting *)cdata) ->protocol);
4603
+ ip1811drv_dbg("cdata ->act=%X\n", ((struct CapActSetting *)cdata) ->act);
4604
+ FUNC_MSG_OUT;
4605
+ return 0;
4606
+}
4607
+
4608
+int setCosTcpFlagDropNull(void *cdata, int len)
4609
+{
4610
+ int ret;
4611
+ FUNC_MSG_IN;
4612
+ ret = _setGeneralEnable(cdata, len, 0, P0REG_TCPFLGCFGGLB, 0);
4613
+ FUNC_MSG_OUT;
4614
+ return ret;
4615
+}
4616
+
4617
+int getCosTcpFlagDropNull(void *cdata, int len)
4618
+{
4619
+ int ret;
4620
+ FUNC_MSG_IN;
4621
+ ret = _getGeneralEnable(cdata, len, 0, P0REG_TCPFLGCFGGLB, 0);
4622
+ FUNC_MSG_OUT;
4623
+ return ret;
4624
+}
4625
+
4626
+int setCosTcpFlagDropAllset(void *cdata, int len)
4627
+{
4628
+ int ret;
4629
+ FUNC_MSG_IN;
4630
+ ret = _setGeneralEnable(cdata, len, 0, P0REG_TCPFLGCFGGLB, 1);
4631
+ FUNC_MSG_OUT;
4632
+ return ret;
4633
+}
4634
+
4635
+int getCosTcpFlagDropAllset(void *cdata, int len)
4636
+{
4637
+ int ret;
4638
+ FUNC_MSG_IN;
4639
+ ret = _getGeneralEnable(cdata, len, 0, P0REG_TCPFLGCFGGLB, 1);
4640
+ FUNC_MSG_OUT;
4641
+ return ret;
4642
+}
4643
+
4644
+int setCosTcpFlag(void *cdata, int len)
4645
+{
4646
+ unsigned int index;
4647
+ int fdata;
4648
+
4649
+ FUNC_MSG_IN;
4650
+ if (sizeof(struct TcpFlagSetting) != len)
4651
+ {
4652
+ ip1811drv_err("Error: length=%d\n", len);
4653
+ return -EINVAL;
4654
+ }
4655
+
4656
+ index = ((struct TcpFlagSetting *)cdata) ->index;
4657
+ if( index > OP_TCPFLAG_FLAG3 )
4658
+ {
4659
+ ip1811drv_err("Error: index=%X\n", index);
4660
+ return -EINVAL;
4661
+ }
4662
+
4663
+ fdata = ((struct TcpFlagSetting *)cdata) ->fdata;
4664
+ if( fdata < 0x0 || fdata > 0xFF )
4665
+ {
4666
+ ip1811drv_err("Error: flag=%X\n", fdata);
4667
+ return -EINVAL;
4668
+ }
4669
+
4670
+ ip1811drv_dbg("cdata ->index=%X\n", index);
4671
+ ip1811drv_dbg("cdata ->fdata=%X\n", fdata);
4672
+
4673
+ _WriteRegBits(0, P0REG_TCPFLGCFG0 + index, 0, 8, fdata);
4674
+
4675
+ FUNC_MSG_OUT;
4676
+ return 0;
4677
+}
4678
+
4679
+int getCosTcpFlag(void *cdata, int len)
4680
+{
4681
+ unsigned int index;
4682
+ int fdata;
4683
+
4684
+ FUNC_MSG_IN;
4685
+ if (sizeof(struct TcpFlagSetting) != len)
4686
+ {
4687
+ ip1811drv_err("Error: length=%d\n", len);
4688
+ return -EINVAL;
4689
+ }
4690
+
4691
+ index = ((struct TcpFlagSetting *)cdata) ->index;
4692
+ if( index > OP_TCPFLAG_FLAG3 )
4693
+ {
4694
+ ip1811drv_err("Error: index=%X\n", index);
4695
+ return -EINVAL;
4696
+ }
4697
+
4698
+ fdata = _ReadRegBits(0, P0REG_TCPFLGCFG0 + index, 0, 8);
4699
+ ((struct TcpFlagSetting *)cdata) ->index = fdata;
4700
+ ip1811drv_dbg("cdata ->index=%X\n", index);
4701
+ ip1811drv_dbg("cdata ->fdata=%X\n", fdata);
4702
+ FUNC_MSG_OUT;
4703
+ return 0;
4704
+}
4705
+
4706
+int setCosTcpFlagAct(void *cdata, int len)
4707
+{
4708
+ unsigned int index;
4709
+ int fdata;
4710
+
4711
+ FUNC_MSG_IN;
4712
+ if (sizeof(struct TcpFlagSetting) != len)
4713
+ {
4714
+ ip1811drv_err("Error: length=%d\n", len);
4715
+ return -EINVAL;
4716
+ }
4717
+
4718
+ index = ((struct TcpFlagSetting *)cdata) ->index;
4719
+ if( index > OP_TCPFLAG_FLAG3 )
4720
+ {
4721
+ ip1811drv_err("Error: index=%X\n", index);
4722
+ return -EINVAL;
4723
+ }
4724
+
4725
+ fdata = ((struct TcpFlagSetting *)cdata) ->fdata;
4726
+ if( fdata < OP_TCPFLAG_ACT_NONE || fdata > OP_TCPFLAG_ACT_DROP )
4727
+ {
4728
+ ip1811drv_err("Error: act=%X\n", fdata);
4729
+ return -EINVAL;
4730
+ }
4731
+
4732
+ ip1811drv_dbg("cdata ->index=%X\n", index);
4733
+ ip1811drv_dbg("cdata ->fdata=%X\n", fdata);
4734
+
4735
+ IP2Page(0);
4736
+
4737
+ /* check L3 TCP action */
4738
+ if(_ReadRegBits(0, P0REG_L3FRAMEGETCTRL, 2, 2) == OP_CAP_ACT_DROP)
4739
+ {
4740
+ ip1811drv_err("Error: L3 TCP action is drop\n");
4741
+ return -EINVAL;
4742
+ }
4743
+
4744
+ /* set register */
4745
+ _WriteRegBits(0, P0REG_TCPFLGCFG0 + index, 12, 2, fdata);
4746
+
4747
+ FUNC_MSG_OUT;
4748
+ return 0;
4749
+}
4750
+
4751
+int getCosTcpFlagAct(void *cdata, int len)
4752
+{
4753
+ unsigned int index;
4754
+ int fdata;
4755
+
4756
+ FUNC_MSG_IN;
4757
+ if (sizeof(struct TcpFlagSetting) != len)
4758
+ {
4759
+ ip1811drv_err("Error: length=%d\n", len);
4760
+ return -EINVAL;
4761
+ }
4762
+
4763
+ index = ((struct TcpFlagSetting *)cdata) ->index;
4764
+ if( index > OP_TCPFLAG_FLAG3 )
4765
+ {
4766
+ ip1811drv_err("Error: index=%X\n", index);
4767
+ return -EINVAL;
4768
+ }
4769
+
4770
+ fdata = _ReadRegBits(0, P0REG_TCPFLGCFG0 + index, 12, 2);
4771
+ ((struct TcpFlagSetting *)cdata) ->fdata = fdata;
4772
+ ip1811drv_dbg("cdata ->index=%X\n", index);
4773
+ ip1811drv_dbg("cdata ->fdata=%X\n", fdata);
4774
+ FUNC_MSG_OUT;
4775
+ return 0;
4776
+}
4777
+
4778
+int setCosTcpFlagPort(void *cdata, int len)
4779
+{
4780
+ unsigned int index;
4781
+ int fdata;
4782
+
4783
+ FUNC_MSG_IN;
4784
+ if (sizeof(struct TcpFlagSetting) != len)
4785
+ {
4786
+ ip1811drv_err("Error: length=%d\n", len);
4787
+ return -EINVAL;
4788
+ }
4789
+
4790
+ index = ((struct TcpFlagSetting *)cdata) ->index;
4791
+ if( index > OP_TCPFLAG_FLAG3 )
4792
+ {
4793
+ ip1811drv_err("Error: index=%X\n", index);
4794
+ return -EINVAL;
4795
+ }
4796
+
4797
+ fdata = ((struct TcpFlagSetting *)cdata) ->fdata;
4798
+ if( fdata & ~0xFFF )
4799
+ {
4800
+ ip1811drv_err("Error: portmap=%X\n", fdata);
4801
+ return -EINVAL;
4802
+ }
4803
+
4804
+ ip1811drv_dbg("cdata ->index=%X\n", index);
4805
+ ip1811drv_dbg("cdata ->fdata=%X\n", fdata);
4806
+
4807
+ IP2Page(0);
4808
+
4809
+ Write_Reg(P0REG_TCPFLGPORTEN+index*2, fdata&0xFFF);
4810
+
4811
+ FUNC_MSG_OUT;
4812
+ return 0;
4813
+}
4814
+
4815
+int getCosTcpFlagPort(void *cdata, int len)
4816
+{
4817
+ unsigned int index;
4818
+ int fdata;
4819
+
4820
+ FUNC_MSG_IN;
4821
+ if (sizeof(struct TcpFlagSetting) != len)
4822
+ {
4823
+ ip1811drv_err("Error: length=%d\n", len);
4824
+ return -EINVAL;
4825
+ }
4826
+
4827
+ index = ((struct TcpFlagSetting *)cdata) ->index;
4828
+ if( index > OP_TCPFLAG_FLAG3 )
4829
+ {
4830
+ ip1811drv_err("Error: index=%X\n", index);
4831
+ return -EINVAL;
4832
+ }
4833
+
4834
+ IP2Page(0);
4835
+ fdata = Read_Reg(P0REG_TCPFLGPORTEN+index*2);
4836
+ ((struct TcpFlagSetting *)cdata) ->fdata = fdata;
4837
+ ip1811drv_dbg("cdata ->index=%X\n", index);
4838
+ ip1811drv_dbg("cdata ->fdata=%X\n", fdata);
4839
+ FUNC_MSG_OUT;
4840
+ return 0;
4841
+}
4842
+//------------ CoS functions:common end ------------------------
4843
+
4844
+//------------------------------------------------
4845
+//common_stp
4846
+int switchdSetMstpFunc(int en)
4847
+{
4848
+ if (en!=OP_FUNC_DISABLE && en!=OP_FUNC_ENABLE)
4849
+ return -EINVAL;
4850
+ ip1811drv_dbg("en=%d\n", en);
4851
+
4852
+ _WriteRegBits(2, P2REG_VLANCFG, 6, 1, en); //MSTP enable
4853
+ _WriteRegBits(2, P2REG_VLANCFG, 2, 1, en); //IVL
4854
+
4855
+ return 0;
4856
+}
4857
+EXPORT_SYMBOL(switchdSetMstpFunc);
4858
+int setMstpFunc(void *cdata, int len)
4859
+{
4860
+ int en;
4861
+
4862
+ ip1811drv_dbg("ip1811: +setMstpFunc...\n");
4863
+ if (sizeof(struct GeneralSetting) != len)
4864
+ return -EINVAL;
4865
+
4866
+ en = ((struct GeneralSetting *)cdata) ->gdata;
4867
+
4868
+ if(switchdSetMstpFunc(en) != 0)
4869
+ return -EINVAL;
4870
+
4871
+ ip1811drv_dbg("ip1811: -setMstpFunc...\n");
4872
+ return 0;
4873
+}
4874
+
4875
+int switchdGetMstpFunc(int *ptrInt)
4876
+{
4877
+ *ptrInt = (int)_ReadRegBits(2, P2REG_VLANCFG, 6, 1);
4878
+
4879
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
4880
+
4881
+ return 0;
4882
+}
4883
+EXPORT_SYMBOL(switchdGetMstpFunc);
4884
+int getMstpFunc(void *cdata, int len)
4885
+{
4886
+ int en;
4887
+
4888
+ ip1811drv_dbg("ip1811: +getMstpFunc...\n");
4889
+ if (sizeof(struct GeneralSetting) != len)
4890
+ return -EINVAL;
4891
+
4892
+ if(switchdGetMstpFunc(&en) != 0)
4893
+ return -EINVAL;
4894
+
4895
+ ((struct GeneralSetting *)cdata) ->gdata = en;
4896
+
4897
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
4898
+ ip1811drv_dbg("ip1811: -getMstpFunc...\n");
4899
+ return 0;
4900
+}
4901
+
4902
+//common_lacp
4903
+int switchdSetTrunkHashMthd(int mthd)
4904
+{
4905
+ if (mthd < OP_TRUNK_HASH_METHOD_PORT_ID || mthd > OP_TRUNK_HASH_METHOD_SP)
4906
+ return -EINVAL;
4907
+ ip1811drv_dbg("mthd=%d\n", mthd);
4908
+
4909
+ _WriteRegBits(1, P1REG_TRUNKCFG, 0, 3, mthd);
4910
+
4911
+ return 0;
4912
+}
4913
+EXPORT_SYMBOL(switchdSetTrunkHashMthd);
4914
+int setTrunkHashMthd(void *cdata, int len)
4915
+{
4916
+ int mthd;
4917
+
4918
+ ip1811drv_dbg("ip1811: +setTrunkHashMthd...\n");
4919
+ if (sizeof(struct GeneralSetting) != len)
4920
+ return -EINVAL;
4921
+
4922
+ mthd = ((struct GeneralSetting *)cdata) ->gdata;
4923
+
4924
+ if(switchdSetTrunkHashMthd(mthd) != 0)
4925
+ return -EINVAL;
4926
+
4927
+ ip1811drv_dbg("ip1811: -setTrunkHashMthd...\n");
4928
+ return 0;
4929
+}
4930
+
4931
+int switchdGetTrunkHashMthd(int *ptrInt)
4932
+{
4933
+ *ptrInt = (int)_ReadRegBits(1, P1REG_TRUNKCFG, 0, 3);
4934
+
4935
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
4936
+
4937
+ return 0;
4938
+}
4939
+EXPORT_SYMBOL(switchdGetTrunkHashMthd);
4940
+int getTrunkHashMthd(void *cdata, int len)
4941
+{
4942
+ int mthd;
4943
+
4944
+ ip1811drv_dbg("ip1811: +getTrunkHashMthd...\n");
4945
+ if (sizeof(struct GeneralSetting) != len)
4946
+ return -EINVAL;
4947
+
4948
+ if(switchdGetTrunkHashMthd(&mthd) != 0)
4949
+ return -EINVAL;
4950
+
4951
+ ((struct GeneralSetting *)cdata) ->gdata = mthd;
4952
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
4953
+ ip1811drv_dbg("ip1811: -getTrunkHashMthd...\n");
4954
+ return 0;
4955
+}
4956
+
4957
+int switchdSetTrunkMbr(unsigned long pmask, unsigned long state)
4958
+{
4959
+ unsigned long u32dat;
4960
+
4961
+ if ((pmask & 0xFFFFF000) || !pmask)
4962
+ return -EINVAL;
4963
+ if ((state & 0xFFFFF000) || (state & ~pmask))
4964
+ return -EINVAL;
4965
+ ip1811drv_dbg("pmask=0x%08X\n", pmask);
4966
+ ip1811drv_dbg("state=0x%08X\n", state);
4967
+
4968
+ IP2Page(1);
4969
+ u32dat= (unsigned long)( Read_Reg(P1REG_TRUNKGRP) );
4970
+ pmask = (unsigned long)( pmask&0xFFF );
4971
+ state = (unsigned long)( state&0xFFF );
4972
+ u32dat &= (~pmask);
4973
+ u32dat |= state;
4974
+#ifdef COMBINED_PORT
4975
+ u32dat |= 0x600;
4976
+#endif
4977
+
4978
+ Write_Reg(P1REG_TRUNKGRP, (u32dat & 0xFFF));
4979
+
4980
+ return 0;
4981
+}
4982
+EXPORT_SYMBOL(switchdSetTrunkMbr);
4983
+int setTrunkMbr(void *cdata, int len)
4984
+{
4985
+ unsigned long pmask, state, u32dat;
4986
+
4987
+ ip1811drv_dbg("ip1811: +setTrunkMbr...\n");
4988
+ if (sizeof(struct TrunkMemberSetting) != len)
4989
+ return -EINVAL;
4990
+
4991
+ pmask = ((struct TrunkMemberSetting *)cdata) ->portmask;
4992
+ state = ((struct TrunkMemberSetting *)cdata) ->tstate;
4993
+
4994
+ if(switchdSetTrunkMbr(pmask, state) != 0)
4995
+ return -EINVAL;
4996
+
4997
+ ip1811drv_dbg("ip1811: -setTrunkMbr...\n");
4998
+ return 0;
4999
+}
5000
+
5001
+int switchdGetTrunkMbr(unsigned long pmask, unsigned long *ptrInt)
5002
+{
5003
+ if ((pmask & 0xFFFFF000) || !pmask)
5004
+ return -EINVAL;
5005
+ ip1811drv_dbg("pmask=0x%08X\n", pmask);
5006
+
5007
+ IP2Page(1);
5008
+ *ptrInt = (unsigned long)( (Read_Reg(P1REG_TRUNKGRP) & 0xFFF) & pmask );
5009
+
5010
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
5011
+
5012
+ return 0;
5013
+}
5014
+EXPORT_SYMBOL(switchdGetTrunkMbr);
5015
+int getTrunkMbr(void *cdata, int len)
5016
+{
5017
+ unsigned long pmask, u32dat;
5018
+
5019
+ ip1811drv_dbg("ip1811: +getTrunkMbr...\n");
5020
+ if (sizeof(struct TrunkMemberSetting) != len)
5021
+ return -EINVAL;
5022
+
5023
+ pmask = ((struct TrunkMemberSetting *)cdata) ->portmask;
5024
+
5025
+ if(switchdGetTrunkMbr(pmask, &u32dat) != 0)
5026
+ return -EINVAL;
5027
+
5028
+ ((struct TrunkMemberSetting *)cdata) ->tstate = u32dat;
5029
+ ip1811drv_dbg("cdata ->tstate=0x%08x\n", (unsigned int)((struct TrunkMemberSetting *)cdata) ->tstate);
5030
+ ip1811drv_dbg("ip1811: -getTrunkMbr...\n");
5031
+ return 0;
5032
+}
5033
+
5034
+int switchdSetCpuNCareTrunkAndVlan(int en)
5035
+{
5036
+ if (en!=OP_FUNC_DISABLE && en!=OP_FUNC_ENABLE)
5037
+ return -EINVAL;
5038
+ ip1811drv_dbg("en=%d\n", en);
5039
+
5040
+ _WriteRegBits(1, P1REG_TRUNKCFG, 4, 1, en);
5041
+
5042
+ return 0;
5043
+}
5044
+EXPORT_SYMBOL(switchdSetCpuNCareTrunkAndVlan);
5045
+int setCpuNCareTrunkAndVlan(void *cdata, int len)
5046
+{
5047
+ int en;
5048
+
5049
+ ip1811drv_dbg("ip1811: +setCpuNCareTrunkAndVlan...\n");
5050
+ if (sizeof(struct GeneralSetting) != len)
5051
+ return -EINVAL;
5052
+ en = ((struct GeneralSetting *)cdata) ->gdata;
5053
+
5054
+ switchdSetCpuNCareTrunkAndVlan(en);
5055
+
5056
+ ip1811drv_dbg("ip1811: -setCpuNCareTrunkAndVlan...\n");
5057
+ return 0;
5058
+}
5059
+
5060
+int switchdGetCpuNCareTrunkAndVlan(int *ptrInt)
5061
+{
5062
+ *ptrInt = (int)_ReadRegBits(1, P1REG_TRUNKCFG, 4, 1);
5063
+
5064
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
5065
+
5066
+ return 0;
5067
+}
5068
+EXPORT_SYMBOL(switchdGetCpuNCareTrunkAndVlan);
5069
+int getCpuNCareTrunkAndVlan(void *cdata, int len)
5070
+{
5071
+ int en;
5072
+
5073
+ ip1811drv_dbg("ip1811: +getCpuNCareTrunkAndVlan...\n");
5074
+ if (sizeof(struct GeneralSetting) != len)
5075
+ return -EINVAL;
5076
+
5077
+ if(switchdGetCpuNCareTrunkAndVlan(&en) != 0)
5078
+ return -EINVAL;
5079
+
5080
+ ((struct GeneralSetting *)cdata) ->gdata = en;
5081
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
5082
+ ip1811drv_dbg("ip1811: -getCpuNCareTrunkAndVlan...\n");
5083
+ return 0;
5084
+}
5085
+
5086
+//------------------------------------------------
5087
+//common_vlan
5088
+int switchdSetVlanEgressFrame(int mode)
5089
+{
5090
+ if (mode > 0x7 )
5091
+ {
5092
+ ip1811drv_err("Error: mode=%X\n", mode);
5093
+ return -EINVAL;
5094
+ }
5095
+ ip1811drv_dbg("mode=0x%08x\n", mode);
5096
+
5097
+ _WriteRegBits(2, P2REG_VLAN_EGRESS_CFG1, 0, 3, mode);
5098
+
5099
+ return 0;
5100
+}
5101
+EXPORT_SYMBOL(switchdSetVlanEgressFrame);
5102
+int setVlanEgressFrame(void *cdata, int len)
5103
+{
5104
+ u16 mode;
5105
+
5106
+ FUNC_MSG_IN;
5107
+ if (sizeof(struct GeneralSetting) != len)
5108
+ return -EINVAL;
5109
+
5110
+ mode = ((struct GeneralSetting *)cdata) ->gdata;
5111
+
5112
+ if(switchdSetVlanEgressFrame(mode) != 0)
5113
+ return -EINVAL;
5114
+
5115
+ FUNC_MSG_OUT;
5116
+ return 0;
5117
+}
5118
+
5119
+void switchdGetVlanEgressFrame(int *ptrInt)
5120
+{
5121
+ *ptrInt = (int)_ReadRegBits(2,P2REG_VLAN_EGRESS_CFG1, 0, 3);
5122
+}
5123
+EXPORT_SYMBOL(switchdGetVlanEgressFrame);
5124
+int getVlanEgressFrame(void *cdata, int len)
5125
+{
5126
+ int ftype;
5127
+
5128
+ FUNC_MSG_IN;
5129
+ if (sizeof(struct GeneralSetting) != len)
5130
+ return -EINVAL;
5131
+
5132
+ switchdGetVlanEgressFrame(&ftype);
5133
+
5134
+ ((struct GeneralSetting *)cdata) ->gdata = ftype;
5135
+
5136
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
5137
+ FUNC_MSG_OUT;
5138
+ return 0;
5139
+}
5140
+
5141
+int switchdSetVlanTagging(int mode)
5142
+{
5143
+ if ((mode != OP_VLAN_TAGGING_BY_PORT) && (mode != OP_VLAN_TAGGING_BY_VID))
5144
+ {
5145
+ ip1811drv_err("Error: mode=%X\n", mode);
5146
+ return -EINVAL;
5147
+ }
5148
+
5149
+ ip1811drv_dbg("mode=0x%08x\n", mode);
5150
+
5151
+ _WriteRegBits(2, P2REG_VLANCFG, 3, 1, mode);
5152
+
5153
+ return 0;
5154
+}
5155
+EXPORT_SYMBOL(switchdSetVlanTagging);
5156
+int setVlanTagging(void *cdata, int len)
5157
+{
5158
+ u16 mode;
5159
+
5160
+ FUNC_MSG_IN;
5161
+ if (sizeof(struct GeneralSetting) != len)
5162
+ return -EINVAL;
5163
+
5164
+ mode = ((struct GeneralSetting *)cdata) ->gdata;
5165
+
5166
+ if(switchdSetVlanTagging(mode) != 0)
5167
+ return -EINVAL;
5168
+
5169
+ FUNC_MSG_OUT;
5170
+ return 0;
5171
+}
5172
+
5173
+int switchdSetVlanType(int mode)
5174
+{
5175
+ if ((mode != OP_VLAN_TYPE_TAG) && (mode != OP_VLAN_TYPE_GROUP))
5176
+ {
5177
+ ip1811drv_err("Error: mode=%X\n", mode);
5178
+ return -EINVAL;
5179
+ }
5180
+
5181
+ ip1811drv_dbg("mode=0x%08x\n", mode);
5182
+
5183
+ /* set vlan type: port/tag base */
5184
+ _WriteRegBits(2, P2REG_VLANCFG, 1, 1, mode);
5185
+ /* set vlan protocol base */
5186
+ _WriteRegBits(2, P2REG_VLANCFG, 0, 1, mode);
5187
+
5188
+ return 0;
5189
+}
5190
+EXPORT_SYMBOL(switchdSetVlanType);
5191
+int setVlanType(void *cdata, int len)
5192
+{
5193
+ u16 mode;
5194
+
5195
+ FUNC_MSG_IN;
5196
+ if (sizeof(struct GeneralSetting) != len)
5197
+ return -EINVAL;
5198
+
5199
+ mode = ((struct GeneralSetting *)cdata) ->gdata;
5200
+
5201
+ if(switchdSetVlanType(mode) != 0)
5202
+ return -EINVAL;
5203
+
5204
+ FUNC_MSG_OUT;
5205
+ return 0;
5206
+}
5207
+
5208
+int switchdSetVlanGroup(unsigned long pm, int option)
5209
+{
5210
+ u32 u32dat;
5211
+ int i;
5212
+
5213
+ if (pm & ~(0x0FFF))
5214
+ {
5215
+ ip1811drv_err("Error: portmap=%08lX\n", pm);
5216
+ return -EINVAL;
5217
+ }
5218
+ if (option & ~0x1)
5219
+ {
5220
+ ip1811drv_err("Error: option=%X\n", option);
5221
+ return -EINVAL;
5222
+ }
5223
+
5224
+ ip1811drv_dbg("pm=0x%08lx\n", pm);
5225
+ ip1811drv_dbg("option=%x\n", option);
5226
+
5227
+ IP2Page(2);
5228
+ for(i=0;i<MAX_PHY_NUM; i++)
5229
+ {
5230
+ if(!((pm>>i)&0x1))
5231
+ continue;
5232
+
5233
+ u32dat = (u32)Read_Reg(P2REG_VLANGROUP+2*i);
5234
+ if(option)
5235
+ u32dat |= pm;
5236
+ else
5237
+ u32dat &= ~pm;
5238
+
5239
+ Write_Reg(P2REG_VLANGROUP+2*i, (u16)(u32dat & 0xFFFF));
5240
+ //Write_Reg(P2REG_VLANGROUP+1+2*i, (u16)(u32dat >> 16));
5241
+ }
5242
+
5243
+ return 0;
5244
+}
5245
+EXPORT_SYMBOL(switchdSetVlanGroup);
5246
+int setVlanGroup(void *cdata, int len)
5247
+{
5248
+ unsigned long pm;
5249
+ int option;
5250
+
5251
+ FUNC_MSG_IN;
5252
+ if (sizeof(struct PortmapSetting) != len)
5253
+ return -EINVAL;
5254
+
5255
+ pm = ((struct PortmapSetting *)cdata) ->portmap;
5256
+ option = ((struct PortmapSetting *)cdata) ->pmdata;
5257
+
5258
+ if(switchdSetVlanGroup(pm, option) != 0)
5259
+ return -EINVAL;
5260
+
5261
+ FUNC_MSG_OUT;
5262
+ return 0;
5263
+}
5264
+
5265
+int switchdSetVlanQinQPType(int type)
5266
+{
5267
+ if (type&(~0xFFFF))
5268
+ {
5269
+ ip1811drv_err("Error: type=%d\n", type);
5270
+ return -EINVAL;
5271
+ }
5272
+
5273
+ ip1811drv_dbg("type=0x%08x\n", type);
5274
+
5275
+ IP2Page(7);
5276
+ Write_Reg(P7REG_QINQEGTYPELEN, type);
5277
+
5278
+ return 0;
5279
+}
5280
+EXPORT_SYMBOL(switchdSetVlanQinQPType);
5281
+int setVlanQinQPType(void *cdata, int len)
5282
+{
5283
+ int type;
5284
+
5285
+ FUNC_MSG_IN;
5286
+ if (sizeof(struct GeneralSetting) != len)
5287
+ return -EINVAL;
5288
+
5289
+ type = ((struct GeneralSetting *)cdata) ->gdata;
5290
+
5291
+ if(switchdSetVlanQinQPType(type) != 0)
5292
+ return -EINVAL;
5293
+
5294
+ FUNC_MSG_OUT;
5295
+ return 0;
5296
+}
5297
+
5298
+int switchdSetVlanQinQPAddtag(int member)
5299
+{
5300
+ if (member & ~(0x0FFF))
5301
+ {
5302
+ ip1811drv_err("Error: member=%08X\n", member);
5303
+ return -EINVAL;
5304
+ }
5305
+
5306
+ ip1811drv_dbg("member=0x%08x\n", member);
5307
+
5308
+ IP2Page(7);
5309
+ Write_Reg(P7REG_QINQ_ADDTAG, (u16)(member & 0xFFFF));
5310
+ //Write_Reg(P7REG_QINQ_ADDTAG+1, (u16)(member >> 16));
5311
+
5312
+ return 0;
5313
+}
5314
+EXPORT_SYMBOL(switchdSetVlanQinQPAddtag);
5315
+int setVlanQinQPAddtag(void *cdata, int len)
5316
+{
5317
+ int member;
5318
+
5319
+ FUNC_MSG_IN;
5320
+ if (sizeof(struct PortMemberSetting) != len)
5321
+ return -EINVAL;
5322
+
5323
+ member = ((struct PortMemberSetting *)cdata) ->member;
5324
+
5325
+ if(switchdSetVlanQinQPAddtag(member) != 0)
5326
+ return -EINVAL;
5327
+
5328
+ FUNC_MSG_OUT;
5329
+ return 0;
5330
+}
5331
+
5332
+void switchdGetVlanQinQPAddtag(u32 *u32dat)
5333
+{
5334
+ IP2Page(7);
5335
+ *u32dat = (u32)Read_Reg(P7REG_QINQ_ADDTAG);
5336
+}
5337
+EXPORT_SYMBOL(switchdGetVlanQinQPAddtag);
5338
+int getVlanQinQPAddtag(void *cdata, int len)
5339
+{
5340
+ u32 u32dat;
5341
+
5342
+ FUNC_MSG_IN;
5343
+ if (sizeof(struct PortMemberSetting) != len)
5344
+ return -EINVAL;
5345
+
5346
+ switchdGetVlanQinQPAddtag(&u32dat);
5347
+
5348
+ ((struct PortMemberSetting *)cdata) ->member = (int)u32dat;
5349
+
5350
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
5351
+ FUNC_MSG_OUT;
5352
+ return 0;
5353
+}
5354
+
5355
+int switchdSetVlanQinQPRmvtag(int member)
5356
+{
5357
+ if (member & ~(0x0FFF))
5358
+ {
5359
+ ip1811drv_err("Error: member=%08X\n", member);
5360
+ return -EINVAL;
5361
+ }
5362
+
5363
+ ip1811drv_dbg("member=0x%08x\n", member);
5364
+
5365
+ IP2Page(7);
5366
+ Write_Reg(P7REG_QINQ_RMVTAG, (u16)(member & 0xFFFF));
5367
+ //Write_Reg(P7REG_QINQ_RMVTAG+1, (u16)(member >> 16));
5368
+
5369
+ return 0;
5370
+}
5371
+EXPORT_SYMBOL(switchdSetVlanQinQPRmvtag);
5372
+int setVlanQinQPRmvtag(void *cdata, int len)
5373
+{
5374
+ int member;
5375
+
5376
+ FUNC_MSG_IN;
5377
+ if (sizeof(struct PortMemberSetting) != len)
5378
+ return -EINVAL;
5379
+
5380
+ member = ((struct PortMemberSetting *)cdata) ->member;
5381
+
5382
+ if(switchdSetVlanQinQPRmvtag(member) != 0)
5383
+ return -EINVAL;
5384
+
5385
+ FUNC_MSG_OUT;
5386
+ return 0;
5387
+}
5388
+
5389
+void switchdGetVlanQinQPRmvtag(u32 *u32dat)
5390
+{
5391
+ IP2Page(7);
5392
+ *u32dat = (u32)Read_Reg(P7REG_QINQ_RMVTAG);
5393
+}
5394
+EXPORT_SYMBOL(switchdGetVlanQinQPRmvtag);
5395
+int getVlanQinQPRmvtag(void *cdata, int len)
5396
+{
5397
+ u32 u32dat;
5398
+
5399
+ FUNC_MSG_IN;
5400
+ if (sizeof(struct PortMemberSetting) != len)
5401
+ return -EINVAL;
5402
+
5403
+ switchdGetVlanQinQPRmvtag(&u32dat);
5404
+
5405
+ ((struct PortMemberSetting *)cdata) ->member = (int)u32dat;
5406
+
5407
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
5408
+ FUNC_MSG_OUT;
5409
+ return 0;
5410
+}
5411
+
5412
+int switchdSetVlanQinQPRxdet(int member)
5413
+{
5414
+ if (member & ~(0x0FFF))
5415
+ {
5416
+ ip1811drv_err("Error: member=%08X\n", member);
5417
+ return -EINVAL;
5418
+ }
5419
+
5420
+ ip1811drv_dbg("member=0x%08x\n", member);
5421
+
5422
+ IP2Page(7);
5423
+ Write_Reg(P7REG_QINQ_DET_RX, (u16)(member & 0xFFFF));
5424
+ //Write_Reg(P7REG_QINQ_DET_RX+1, (u16)(member >> 16));
5425
+
5426
+ return 0;
5427
+}
5428
+EXPORT_SYMBOL(switchdSetVlanQinQPRxdet);
5429
+int setVlanQinQPRxdet(void *cdata, int len)
5430
+{
5431
+ int member;
5432
+
5433
+ FUNC_MSG_IN;
5434
+ if (sizeof(struct PortMemberSetting) != len)
5435
+ return -EINVAL;
5436
+
5437
+ member = ((struct PortMemberSetting *)cdata) ->member;
5438
+
5439
+ if(switchdSetVlanQinQPRxdet(member) != 0)
5440
+ return -EINVAL;
5441
+
5442
+ FUNC_MSG_OUT;
5443
+ return 0;
5444
+}
5445
+
5446
+void switchdGetVlanQinQPRxdet(u32 *u32dat)
5447
+{
5448
+ IP2Page(7);
5449
+ *u32dat = (u32)Read_Reg(P7REG_QINQ_DET_RX);
5450
+}
5451
+EXPORT_SYMBOL(switchdGetVlanQinQPRxdet);
5452
+int getVlanQinQPRxdet(void *cdata, int len)
5453
+{
5454
+ u32 u32dat;
5455
+
5456
+ FUNC_MSG_IN;
5457
+ if (sizeof(struct PortMemberSetting) != len)
5458
+ return -EINVAL;
5459
+
5460
+ switchdGetVlanQinQPRxdet(&u32dat);
5461
+
5462
+ ((struct PortMemberSetting *)cdata) ->member = (int)u32dat;
5463
+
5464
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
5465
+ FUNC_MSG_OUT;
5466
+ return 0;
5467
+}
5468
+
5469
+int switchdSetVlanQinQPKeep(int member)
5470
+{
5471
+ int i;
5472
+
5473
+ if (member & ~(0x0FFF))
5474
+ {
5475
+ ip1811drv_err("Error: member=%08X\n", member);
5476
+ return -EINVAL;
5477
+ }
5478
+
5479
+ ip1811drv_dbg("member=0x%08x\n", member);
5480
+
5481
+ for(i=0; i<MAX_PHY_NUM; i++)
5482
+ {
5483
+ _WriteRegBits(7, P7REG_QINQ_P_DATA+i, 12, 1, ((member>>i)&0x1));
5484
+ }
5485
+
5486
+ return 0;
5487
+}
5488
+EXPORT_SYMBOL(switchdSetVlanQinQPKeep);
5489
+int setVlanQinQPKeep(void *cdata, int len)
5490
+{
5491
+ int member;
5492
+
5493
+ FUNC_MSG_IN;
5494
+ if (sizeof(struct PortMemberSetting) != len)
5495
+ return -EINVAL;
5496
+
5497
+ member = ((struct PortMemberSetting *)cdata) ->member;
5498
+
5499
+ if(switchdSetVlanQinQPKeep(member) != 0)
5500
+ return -EINVAL;
5501
+
5502
+ FUNC_MSG_OUT;
5503
+ return 0;
5504
+}
5505
+
5506
+void switchdGetVlanQinQPKeep(u32 *u32dat)
5507
+{
5508
+ int i;
5509
+ u16 u16dat;
5510
+
5511
+ IP2Page(7);
5512
+ for(i=0; i<MAX_PHY_NUM; i++)
5513
+ {
5514
+ u16dat = Read_Reg(P7REG_QINQ_P_DATA+i);
5515
+ *u32dat |= ((u16dat>>12)&0x1)<<i;
5516
+ }
5517
+}
5518
+EXPORT_SYMBOL(switchdGetVlanQinQPKeep);
5519
+int getVlanQinQPKeep(void *cdata, int len)
5520
+{
5521
+ u32 member=0;
5522
+
5523
+ FUNC_MSG_IN;
5524
+ if (sizeof(struct PortMemberSetting) != len)
5525
+ return -EINVAL;
5526
+
5527
+ switchdGetVlanQinQPKeep(&member);
5528
+
5529
+ ((struct PortMemberSetting *)cdata) ->member = member;
5530
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
5531
+ FUNC_MSG_OUT;
5532
+ return 0;
5533
+}
5534
+
5535
+int switchdSetVlanQinQPIndex(int port, int index)
5536
+{
5537
+ if (port < 0 || port >= MAX_PHY_NUM)
5538
+ {
5539
+ ip1811drv_err("Error: port=%X\n", port);
5540
+ return -EINVAL;
5541
+ }
5542
+
5543
+ if (index < 0 || index > 15)
5544
+ {
5545
+ ip1811drv_err("Error: pmdata=%X\n", index);
5546
+ return -EINVAL;
5547
+ }
5548
+
5549
+ ip1811drv_dbg("port=%d\n", port);
5550
+ ip1811drv_dbg("index=%d\n", index);
5551
+
5552
+ //index |= (0x0001 << 8);
5553
+ _WriteRegBits(7, P7REG_QINQ_P_DATA+port, 0, 4, index);
5554
+#ifdef COMBINED_PORT
5555
+ if (port==9)
5556
+ _WriteRegBits(7, P7REG_QINQ_P_DATA+port+1, 0, 4, index);
5557
+#endif
5558
+
5559
+ return 0;
5560
+}
5561
+EXPORT_SYMBOL(switchdSetVlanQinQPIndex);
5562
+int setVlanQinQPIndex(void *cdata, int len)
5563
+{
5564
+ int port, index;
5565
+
5566
+ FUNC_MSG_IN;
5567
+ if (sizeof(struct ByPortSetting) != len)
5568
+ return -EINVAL;
5569
+
5570
+ port = ((struct ByPortSetting *)cdata) ->port;
5571
+ index= ((struct ByPortSetting *)cdata) ->pdata;
5572
+
5573
+ if(switchdSetVlanQinQPIndex(port, index) != 0)
5574
+ return -EINVAL;
5575
+
5576
+ FUNC_MSG_OUT;
5577
+ return 0;
5578
+}
5579
+
5580
+int switchdGetVlanQinQPIndex(int port, int *index)
5581
+{
5582
+ if (port < 0 || port >= MAX_PHY_NUM)
5583
+ {
5584
+ ip1811drv_err("Error: port=%X\n", port);
5585
+ return -EINVAL;
5586
+ }
5587
+
5588
+#ifdef COMBINED_PORT
5589
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
5590
+ port++;
5591
+#endif
5592
+ *index= _ReadRegBits(7,P7REG_QINQ_P_DATA+port, 0, 4);
5593
+ return 0;
5594
+}
5595
+EXPORT_SYMBOL(switchdGetVlanQinQPIndex);
5596
+int getVlanQinQPIndex(void *cdata, int len)
5597
+{
5598
+ int port;
5599
+ int index;
5600
+
5601
+ FUNC_MSG_IN;
5602
+ if (sizeof(struct ByPortSetting) != len)
5603
+ return -EINVAL;
5604
+
5605
+ port = ((struct ByPortSetting *)cdata) ->port;
5606
+
5607
+ if(switchdGetVlanQinQPIndex(port, &index) != 0)
5608
+ return -EINVAL;
5609
+
5610
+ ((struct ByPortSetting *)cdata) ->pdata = index;
5611
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
5612
+ FUNC_MSG_OUT;
5613
+ return 0;
5614
+}
5615
+
5616
+int switchdSetVlanQinQIndex(int index, int value)
5617
+{
5618
+ if (index<0 || index>15) {
5619
+ ip1811drv_err("Error: index=%d\n", index);
5620
+ return -EINVAL;
5621
+ }
5622
+
5623
+ if (value & (~0xFFFF)) {
5624
+ ip1811drv_err("Error: data=%x\n", value);
5625
+ return -EINVAL;
5626
+ }
5627
+
5628
+ ip1811drv_dbg("index=%d\n", index);
5629
+ ip1811drv_dbg("value=0x%x\n", value);
5630
+
5631
+ IP2Page(7);
5632
+
5633
+ Write_Reg(P7REG_QINQ_DATA+index, (u16)value);
5634
+
5635
+ return 0;
5636
+}
5637
+EXPORT_SYMBOL(switchdSetVlanQinQIndex);
5638
+int setVlanQinQIndex(void *cdata, int len)
5639
+{
5640
+ int type, data, ret;
5641
+ struct VlanSetting *vs = (struct VlanSetting *)cdata;
5642
+
5643
+ FUNC_MSG_IN;
5644
+ if (sizeof(struct VlanSetting) != len) {
5645
+ ip1811drv_err("Error: lengtn=%d\n", len);
5646
+ return -EINVAL;
5647
+ }
5648
+
5649
+ type = vs ->vtype;
5650
+ data = vs ->vdata;
5651
+ ret = switchdSetVlanQinQIndex(type, data);
5652
+
5653
+ FUNC_MSG_OUT;
5654
+ return ret;
5655
+}
5656
+
5657
+int switchdSetVlanQinQStagSelectMethod(int port, int method)
5658
+{
5659
+ if (port<0 || port>=MAX_PHY_NUM) {
5660
+ ip1811drv_err("Error: port=%X\n", port);
5661
+ return -EINVAL;
5662
+ }
5663
+
5664
+ ip1811drv_dbg("port=%d\n", port);
5665
+ ip1811drv_dbg("method=%d\n", method);
5666
+
5667
+ _WriteRegBits(7, P7REG_QINQ_P_DATA+port, 8, 4, method);
5668
+#ifdef COMBINED_PORT
5669
+ if (port==9)
5670
+ _WriteRegBits(7, P7REG_QINQ_P_DATA+port+1, 8, 4, method);
5671
+#endif
5672
+
5673
+ return 0;
5674
+}
5675
+EXPORT_SYMBOL(switchdSetVlanQinQStagSelectMethod);
5676
+int setVlanQinQStagSelectMethod(void *cdata, int len)
5677
+{
5678
+ int port, method, ret;
5679
+ struct ByPortSetting *bps = (struct ByPortSetting *)cdata;
5680
+
5681
+ FUNC_MSG_IN;
5682
+ if (sizeof(struct ByPortSetting) != len) {
5683
+ ip1811drv_err("Error: lengtn=%d\n", len);
5684
+ return -EINVAL;
5685
+ }
5686
+
5687
+ port = bps ->port;
5688
+ method = bps ->pdata;
5689
+ ret = switchdSetVlanQinQStagSelectMethod(port, method) ;
5690
+
5691
+ FUNC_MSG_OUT;
5692
+ return ret;
5693
+}
5694
+
5695
+int switchdSetVlanPortAddtag(int member)
5696
+{
5697
+ if (member & ~(0x0FFF))
5698
+ {
5699
+ ip1811drv_err("Error: member=%08X\n", member);
5700
+ return -EINVAL;
5701
+ }
5702
+
5703
+ ip1811drv_dbg("member=0x%08x\n", member);
5704
+
5705
+ IP2Page(2);
5706
+ Write_Reg(P2REG_VLAN_ADDTAG, (u16)(member & 0xFFFF));
5707
+ //Write_Reg(P2REG_VLAN_ADDTAG+1, (u16)(member >> 16));
5708
+
5709
+ return 0;
5710
+}
5711
+EXPORT_SYMBOL(switchdSetVlanPortAddtag);
5712
+int setVlanPortAddtag(void *cdata, int len)
5713
+{
5714
+ int member;
5715
+
5716
+ FUNC_MSG_IN;
5717
+ if (sizeof(struct PortMemberSetting) != len)
5718
+ return -EINVAL;
5719
+
5720
+ member = ((struct PortMemberSetting *)cdata) ->member;
5721
+
5722
+ if(switchdSetVlanPortAddtag(member) != 0)
5723
+ return -EINVAL;
5724
+
5725
+ FUNC_MSG_OUT;
5726
+ return 0;
5727
+}
5728
+
5729
+void switchdGetVlanPortAddtag(u32 *u32dat)
5730
+{
5731
+ IP2Page(2);
5732
+ *u32dat = (u32)Read_Reg(P2REG_VLAN_ADDTAG);
5733
+}
5734
+EXPORT_SYMBOL(switchdGetVlanPortAddtag);
5735
+int getVlanPortAddtag(void *cdata, int len)
5736
+{
5737
+ u32 u32dat;
5738
+
5739
+ FUNC_MSG_IN;
5740
+ if (sizeof(struct PortMemberSetting) != len)
5741
+ return -EINVAL;
5742
+
5743
+ switchdGetVlanPortAddtag(&u32dat);
5744
+
5745
+ ((struct PortMemberSetting *)cdata) ->member = (int)u32dat;
5746
+
5747
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
5748
+ FUNC_MSG_OUT;
5749
+ return 0;
5750
+}
5751
+
5752
+int switchdSetVlanPortRmvtag(int member)
5753
+{
5754
+ if (member & ~(0x0FFF))
5755
+ {
5756
+ ip1811drv_err("Error: member=%08X\n", member);
5757
+ return -EINVAL;
5758
+ }
5759
+
5760
+ ip1811drv_dbg("member=0x%08x\n", member);
5761
+
5762
+ IP2Page(2);
5763
+ Write_Reg(P2REG_VLAN_RMVTAG, (u16)(member & 0xFFFF));
5764
+ //Write_Reg(P2REG_VLAN_RMVTAG+1, (u16)(member >> 16));
5765
+
5766
+ return 0;
5767
+}
5768
+EXPORT_SYMBOL(switchdSetVlanPortRmvtag);
5769
+int setVlanPortRmvtag(void *cdata, int len)
5770
+{
5771
+ int member;
5772
+
5773
+ FUNC_MSG_IN;
5774
+ if (sizeof(struct PortMemberSetting) != len)
5775
+ return -EINVAL;
5776
+
5777
+ member = ((struct PortMemberSetting *)cdata) ->member;
5778
+
5779
+ if(switchdSetVlanPortRmvtag(member) != 0)
5780
+ return -EINVAL;
5781
+
5782
+ FUNC_MSG_OUT;
5783
+ return 0;
5784
+}
5785
+
5786
+void switchdGetVlanPortRmvtag(u32 *u32dat)
5787
+{
5788
+ IP2Page(2);
5789
+ *u32dat = (u32)Read_Reg(P2REG_VLAN_RMVTAG);
5790
+}
5791
+EXPORT_SYMBOL(switchdGetVlanPortRmvtag);
5792
+int getVlanPortRmvtag(void *cdata, int len)
5793
+{
5794
+ u32 u32dat;
5795
+
5796
+ FUNC_MSG_IN;
5797
+ if (sizeof(struct PortMemberSetting) != len)
5798
+ return -EINVAL;
5799
+
5800
+ switchdGetVlanPortRmvtag(&u32dat);
5801
+
5802
+ ((struct PortMemberSetting *)cdata) ->member = (int)u32dat;
5803
+
5804
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
5805
+ FUNC_MSG_OUT;
5806
+ return 0;
5807
+}
5808
+
5809
+int switchdSetVlanPortForce(int member)
5810
+{
5811
+ int i;
5812
+
5813
+ if (member & ~(0x0FFF))
5814
+ {
5815
+ ip1811drv_err("Error: member=%08X\n", member);
5816
+ return -EINVAL;
5817
+ }
5818
+
5819
+ ip1811drv_dbg("member=0x%08x\n", member);
5820
+
5821
+ for(i=0; i<MAX_PHY_NUM; i++)
5822
+ {
5823
+ _WriteRegBits(2, P2REG_VLANGROUP+2*i, 12, 1, (member>>i)&0x1);
5824
+ }
5825
+
5826
+ return 0;
5827
+}
5828
+EXPORT_SYMBOL(switchdSetVlanPortForce);
5829
+int setVlanPortForce(void *cdata, int len)
5830
+{
5831
+ int member;
5832
+
5833
+ FUNC_MSG_IN;
5834
+ if (sizeof(struct PortMemberSetting) != len)
5835
+ return -EINVAL;
5836
+
5837
+ member = ((struct PortMemberSetting *)cdata) ->member;
5838
+
5839
+ if(switchdSetVlanPortForce(member) != 0)
5840
+ return -EINVAL;
5841
+
5842
+ FUNC_MSG_OUT;
5843
+ return 0;
5844
+}
5845
+
5846
+void switchdGetVlanPortForce(u32 *u32dat)
5847
+{
5848
+ u16 u16dat;
5849
+ int i;
5850
+
5851
+ IP2Page(2);
5852
+ for(i=0; i<MAX_PHY_NUM; i++)
5853
+ {
5854
+ u16dat = Read_Reg(P2REG_VLANGROUP+2*i);
5855
+ *u32dat |= ((u16dat>>12)&0x1)<<i;
5856
+ }
5857
+}
5858
+EXPORT_SYMBOL(switchdGetVlanPortForce);
5859
+int getVlanPortForce(void *cdata, int len)
5860
+{
5861
+ u32 member=0;
5862
+
5863
+ FUNC_MSG_IN;
5864
+ if (sizeof(struct PortMemberSetting) != len)
5865
+ return -EINVAL;
5866
+
5867
+ switchdGetVlanPortForce(&member);
5868
+
5869
+ ((struct PortMemberSetting *)cdata) ->member = member;
5870
+
5871
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
5872
+ FUNC_MSG_OUT;
5873
+ return 0;
5874
+}
5875
+
5876
+int switchdSetVlanPortUplink(int member)
5877
+{
5878
+ //u16 u16dat;
5879
+
5880
+ if (member & ~(0x0FFF))
5881
+ {
5882
+ ip1811drv_err("Error: member=%08X\n", member);
5883
+ return -EINVAL;
5884
+ }
5885
+
5886
+ ip1811drv_dbg("member=0x%08x\n", member);
5887
+
5888
+ IP2Page(2);
5889
+ Write_Reg(P2REG_VLAN_UPLINK, (u16)((member & 0xFFFF) | 0x1000));
5890
+ //u16dat = (u16)(member >> 16);
5891
+ //u16dat |= (u16)0x1<<13; //enable uplink
5892
+ //_WriteRegBits(2, P2REG_VLAN_UPLINK+1, 0, 14, u16dat);
5893
+
5894
+ return 0;
5895
+}
5896
+EXPORT_SYMBOL(switchdSetVlanPortUplink);
5897
+int setVlanPortUplink(void *cdata, int len)
5898
+{
5899
+ int member;
5900
+
5901
+ FUNC_MSG_IN;
5902
+ if (sizeof(struct PortMemberSetting) != len)
5903
+ return -EINVAL;
5904
+
5905
+ member = ((struct PortMemberSetting *)cdata) ->member;
5906
+
5907
+ if(switchdSetVlanPortUplink(member) != 0)
5908
+ return -EINVAL;
5909
+
5910
+ FUNC_MSG_OUT;
5911
+ return 0;
5912
+}
5913
+
5914
+void switchdGetVlanPortUplink(u32 *u32dat)
5915
+{
5916
+ IP2Page(2);
5917
+ *u32dat = (u32)Read_Reg(P2REG_VLAN_UPLINK);
5918
+ *u32dat &= 0x0FFF;
5919
+}
5920
+EXPORT_SYMBOL(switchdGetVlanPortUplink);
5921
+int getVlanPortUplink(void *cdata, int len)
5922
+{
5923
+ u32 u32dat;
5924
+
5925
+ FUNC_MSG_IN;
5926
+ if (sizeof(struct PortMemberSetting) != len)
5927
+ return -EINVAL;
5928
+
5929
+ switchdGetVlanPortUplink(&u32dat);
5930
+ ((struct PortMemberSetting *)cdata) ->member = (int)u32dat;
5931
+
5932
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
5933
+ FUNC_MSG_OUT;
5934
+ return 0;
5935
+}
5936
+
5937
+int switchdSetVlanPortExclusive(int member)
5938
+{
5939
+ if (member & ~(0x0FFF))
5940
+ {
5941
+ ip1811drv_err("Error: member=%08X\n", member);
5942
+ return -EINVAL;
5943
+ }
5944
+
5945
+ ip1811drv_dbg("member=0x%08x\n", member);
5946
+
5947
+ IP2Page(2);
5948
+ Write_Reg(P2REG_VLAN_EXCLUSIVE, (u16)(member & 0xFFFF));
5949
+ //Write_Reg(P2REG_VLAN_EXCLUSIVE+1, (u16)(member >> 16));
5950
+
5951
+ return 0;
5952
+}
5953
+EXPORT_SYMBOL(switchdSetVlanPortExclusive);
5954
+int setVlanPortExclusive(void *cdata, int len)
5955
+{
5956
+ int member;
5957
+
5958
+ FUNC_MSG_IN;
5959
+ if (sizeof(struct PortMemberSetting) != len)
5960
+ return -EINVAL;
5961
+
5962
+ member = ((struct PortMemberSetting *)cdata) ->member;
5963
+
5964
+ if(switchdSetVlanPortExclusive(member) != 0)
5965
+ return -EINVAL;
5966
+
5967
+ FUNC_MSG_OUT;
5968
+ return 0;
5969
+}
5970
+
5971
+void switchdGetVlanPortExclusive(u32 *u32dat)
5972
+{
5973
+ IP2Page(2);
5974
+ *u32dat = (u32)Read_Reg(P2REG_VLAN_EXCLUSIVE);
5975
+}
5976
+EXPORT_SYMBOL(switchdGetVlanPortExclusive);
5977
+int getVlanPortExclusive(void *cdata, int len)
5978
+{
5979
+ u32 u32dat;
5980
+
5981
+ FUNC_MSG_IN;
5982
+ if (sizeof(struct PortMemberSetting) != len)
5983
+ return -EINVAL;
5984
+
5985
+ switchdGetVlanPortExclusive(&u32dat);
5986
+ ((struct PortMemberSetting *)cdata) ->member = (int)u32dat;
5987
+
5988
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
5989
+ FUNC_MSG_OUT;
5990
+ return 0;
5991
+}
5992
+
5993
+int switchdSetVlanPortEgress(int member)
5994
+{
5995
+ if (member & ~(0x0FFF))
5996
+ {
5997
+ ip1811drv_err("Error: member=%08X\n", member);
5998
+ return -EINVAL;
5999
+ }
6000
+
6001
+ ip1811drv_dbg("member=0x%08x\n", member);
6002
+
6003
+ IP2Page(2);
6004
+ Write_Reg(P2REG_VLAN_EGRESS_CFG, (u16)(member & 0xFFFF));
6005
+ //_WriteRegBits(2, P2REG_VLAN_EGRESS_CFG+1, 0, 13, (u16)(member >> 16));
6006
+
6007
+ return 0;
6008
+}
6009
+EXPORT_SYMBOL(switchdSetVlanPortEgress);
6010
+int setVlanPortEgress(void *cdata, int len)
6011
+{
6012
+ int member;
6013
+
6014
+ FUNC_MSG_IN;
6015
+ if (sizeof(struct PortMemberSetting) != len)
6016
+ return -EINVAL;
6017
+
6018
+ member = ((struct PortMemberSetting *)cdata) ->member;
6019
+
6020
+ if(switchdSetVlanPortEgress(member) != 0)
6021
+ return -EINVAL;
6022
+
6023
+ FUNC_MSG_OUT;
6024
+ return 0;
6025
+}
6026
+
6027
+void switchdGetVlanPortEgress(u32 *u32dat)
6028
+{
6029
+ IP2Page(2);
6030
+ *u32dat = (u32)Read_Reg(P2REG_VLAN_EGRESS_CFG);
6031
+ //u32dat &= 0x1FFFFFFF;
6032
+}
6033
+EXPORT_SYMBOL(switchdGetVlanPortEgress);
6034
+int getVlanPortEgress(void *cdata, int len)
6035
+{
6036
+ u32 u32dat;
6037
+
6038
+ FUNC_MSG_IN;
6039
+ if (sizeof(struct PortMemberSetting) != len)
6040
+ return -EINVAL;
6041
+
6042
+ switchdGetVlanPortEgress(&u32dat);
6043
+ ((struct PortMemberSetting *)cdata) ->member = (int)u32dat;
6044
+
6045
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
6046
+ FUNC_MSG_OUT;
6047
+ return 0;
6048
+}
6049
+
6050
+int switchdSetVlanPortIngressFrame(int port, int pdata)
6051
+{
6052
+ if (port < 0 || port >= MAX_PHY_NUM)
6053
+ {
6054
+ ip1811drv_err("Error: port=%d\n", port);
6055
+ return -EINVAL;
6056
+ }
6057
+
6058
+ if (pdata < 0 || pdata > 0x3)
6059
+ {
6060
+ ip1811drv_err("Error: pdata=0x%X\n", pdata);
6061
+ return -EINVAL;
6062
+ }
6063
+
6064
+ ip1811drv_dbg("port=%d\n", port);
6065
+ ip1811drv_dbg("pdata=0x%X\n", pdata);
6066
+
6067
+ _WriteRegBits(2, P2REG_VLAN_INGRESS_FRAME_0, port, 1, (pdata&0x1));
6068
+ _WriteRegBits(2, P2REG_VLAN_INGRESS_FRAME_1, port, 1, ((pdata>>1)&0x1));
6069
+#ifdef COMBINED_PORT
6070
+ if (port==9){
6071
+ _WriteRegBits(2, P2REG_VLAN_INGRESS_FRAME_0, port+1, 1, (pdata&0x1));
6072
+ _WriteRegBits(2, P2REG_VLAN_INGRESS_FRAME_1, port+1, 1, ((pdata>>1)&0x1));
6073
+ }
6074
+#endif
6075
+
6076
+ return 0;
6077
+}
6078
+EXPORT_SYMBOL(switchdSetVlanPortIngressFrame);
6079
+int setVlanPortIngressFrame(void *cdata, int len)
6080
+{
6081
+ int port, pdata;
6082
+
6083
+ FUNC_MSG_IN;
6084
+ if (sizeof(struct ByPortSetting) != len)
6085
+ return -EINVAL;
6086
+
6087
+ port = ((struct ByPortSetting *)cdata) ->port;
6088
+ pdata = ((struct ByPortSetting *)cdata) ->pdata;
6089
+
6090
+ if(switchdSetVlanPortIngressFrame(port, pdata) != 0)
6091
+ return -EINVAL;
6092
+
6093
+ FUNC_MSG_OUT;
6094
+ return 0;
6095
+}
6096
+
6097
+int switchdSetVlanPortIngressCheck(int member)
6098
+{
6099
+ if (member & ~(0x0FFF))
6100
+ {
6101
+ ip1811drv_err("Error: member=%08X\n", member);
6102
+ return -EINVAL;
6103
+ }
6104
+
6105
+ ip1811drv_dbg("member=0x%08x\n", member);
6106
+
6107
+ IP2Page(2);
6108
+ Write_Reg(P2REG_VLAN_INGRESS_CHK, (u16)(member & 0xFFFF));
6109
+ //Write_Reg(P2REG_VLAN_INGRESS_CHK+1, (u16)(member >> 16));
6110
+
6111
+ return 0;
6112
+}
6113
+EXPORT_SYMBOL(switchdSetVlanPortIngressCheck);
6114
+int setVlanPortIngressCheck(void *cdata, int len)
6115
+{
6116
+ int member;
6117
+
6118
+ FUNC_MSG_IN;
6119
+ if (sizeof(struct PortMemberSetting) != len)
6120
+ return -EINVAL;
6121
+
6122
+ member = ((struct PortMemberSetting *)cdata) ->member;
6123
+
6124
+ if(switchdSetVlanPortIngressCheck(member) != 0)
6125
+ return -EINVAL;
6126
+
6127
+ FUNC_MSG_OUT;
6128
+ return 0;
6129
+}
6130
+
6131
+void switchdGetVlanPortIngressCheck(u32 *u32dat)
6132
+{
6133
+ IP2Page(2);
6134
+ *u32dat = (u32)Read_Reg(P2REG_VLAN_INGRESS_CHK);
6135
+}
6136
+EXPORT_SYMBOL(switchdGetVlanPortIngressCheck);
6137
+int getVlanPortIngressCheck(void *cdata, int len)
6138
+{
6139
+ u32 u32dat;
6140
+
6141
+ FUNC_MSG_IN;
6142
+ if (sizeof(struct PortMemberSetting) != len)
6143
+ return -EINVAL;
6144
+
6145
+ switchdGetVlanPortIngressCheck(&u32dat);
6146
+
6147
+ ((struct PortMemberSetting *)cdata) ->member = (int)u32dat;
6148
+
6149
+ ip1811drv_dbg("cdata ->gdata=%d\n", (u16)((struct PortMemberSetting *)cdata) ->member);
6150
+ FUNC_MSG_OUT;
6151
+ return 0;
6152
+}
6153
+
6154
+int switchdSetVlanPortVid(int port, int pvid)
6155
+{
6156
+ if (port < 0 || port >= MAX_PHY_NUM)
6157
+ {
6158
+ ip1811drv_err("Error: port=%X\n", port);
6159
+ return -EINVAL;
6160
+ }
6161
+
6162
+ if (pvid < 0 || pvid >= MAX_PVID_NUM)
6163
+ {
6164
+ ip1811drv_err("Error: pmdata=%X\n", pvid);
6165
+ return -EINVAL;
6166
+ }
6167
+
6168
+ ip1811drv_dbg("port=%d\n", port);
6169
+ ip1811drv_dbg("pvid=%d\n", pvid);
6170
+
6171
+ _WriteRegBits(2, P2REG_VLAN_PVIDCFG+port, 0, 12, pvid);
6172
+#ifdef COMBINED_PORT
6173
+ if (port==9)
6174
+ _WriteRegBits(2, P2REG_VLAN_PVIDCFG+port+1, 0, 12, pvid);
6175
+#endif
6176
+
6177
+ return 0;
6178
+}
6179
+EXPORT_SYMBOL(switchdSetVlanPortVid);
6180
+int setVlanPortVid(void *cdata, int len)
6181
+{
6182
+ int port, pvid;
6183
+
6184
+ FUNC_MSG_IN;
6185
+ if (sizeof(struct ByPortSetting) != len)
6186
+ return -EINVAL;
6187
+
6188
+ port = ((struct ByPortSetting *)cdata) ->port;
6189
+ pvid= ((struct ByPortSetting *)cdata) ->pdata;
6190
+
6191
+ if(switchdSetVlanPortVid(port, pvid) != 0)
6192
+ return -EINVAL;
6193
+
6194
+ FUNC_MSG_OUT;
6195
+ return 0;
6196
+}
6197
+
6198
+int switchdSetVlanProtocolMode(int index, int mode)
6199
+{
6200
+ if (index < 0 || index >= MAX_PRO_VLAN_ENTRY_NUM)
6201
+ {
6202
+ ip1811drv_err("Error: index=%X\n", index);
6203
+ return -EINVAL;
6204
+ }
6205
+
6206
+ if( (mode!=OP_VLAN_PROTOCOL_INVALID)
6207
+ && (mode!=OP_VLAN_PROTOCOL_ETHER)
6208
+ && (mode!=OP_VLAN_PROTOCOL_LLC)
6209
+ && (mode!=OP_VLAN_PROTOCOL_1042) )
6210
+ {
6211
+ ip1811drv_err("Error: mode=%X\n", mode);
6212
+ return -EINVAL;
6213
+ }
6214
+
6215
+ ip1811drv_dbg("index=%d\n", index);
6216
+ ip1811drv_dbg("mode=%d\n", mode);
6217
+
6218
+ _WriteRegBits(2, P2REG_VLAN_PROCOTOL_CFG+1+index*2, 12, 2, mode);
6219
+
6220
+ return 0;
6221
+}
6222
+EXPORT_SYMBOL(switchdSetVlanProtocolMode);
6223
+int setVlanProtocolMode(void *cdata, int len)
6224
+{
6225
+ int index, mode;
6226
+
6227
+ FUNC_MSG_IN;
6228
+ if (sizeof(struct VlanSetting) != len)
6229
+ return -EINVAL;
6230
+
6231
+ index = (((struct VlanSetting *)cdata) ->vtype) - 1;
6232
+ mode= ((struct VlanSetting *)cdata) ->vdata;
6233
+
6234
+ if(switchdSetVlanProtocolMode(index, mode) != 0)
6235
+ return -EINVAL;
6236
+
6237
+ FUNC_MSG_OUT;
6238
+ return 0;
6239
+}
6240
+
6241
+int switchdSetVlanProtocolVid(int index, int vid)
6242
+{
6243
+ if (index < 0 || index >= MAX_PRO_VLAN_ENTRY_NUM)
6244
+ {
6245
+ ip1811drv_err("Error: index=%X\n", index);
6246
+ return -EINVAL;
6247
+ }
6248
+
6249
+ if( (vid < 0) || (vid>=MAX_PVID_NUM) )
6250
+ {
6251
+ ip1811drv_err("Error: vid=%X\n", vid);
6252
+ return -EINVAL;
6253
+ }
6254
+
6255
+ ip1811drv_dbg("index=%d\n", index);
6256
+ ip1811drv_dbg("vid=%d\n", vid);
6257
+
6258
+ _WriteRegBits(2, P2REG_VLAN_PROCOTOL_CFG+1+index*2, 0, 12, vid);
6259
+
6260
+ return 0;
6261
+}
6262
+EXPORT_SYMBOL(switchdSetVlanProtocolVid);
6263
+int setVlanProtocolVid(void *cdata, int len)
6264
+{
6265
+ int index, vid;
6266
+
6267
+ FUNC_MSG_IN;
6268
+ if (sizeof(struct VlanSetting) != len)
6269
+ return -EINVAL;
6270
+
6271
+ index = (((struct VlanSetting *)cdata) ->vtype) - 1;
6272
+ vid= ((struct VlanSetting *)cdata) ->vdata;
6273
+
6274
+ if(switchdSetVlanProtocolVid(index, vid) != 0)
6275
+ return -EINVAL;
6276
+
6277
+ FUNC_MSG_OUT;
6278
+ return 0;
6279
+}
6280
+
6281
+int switchdSetVlanProtocolType(int index, int type)
6282
+{
6283
+ if (index < 0 || index >= MAX_PRO_VLAN_ENTRY_NUM)
6284
+ {
6285
+ ip1811drv_err("Error: index=%X\n", index);
6286
+ return -EINVAL;
6287
+ }
6288
+
6289
+ if (type & (~0xFFFF))
6290
+ {
6291
+ ip1811drv_err("Error: type=%X\n", type);
6292
+ return -EINVAL;
6293
+ }
6294
+
6295
+ ip1811drv_dbg("index=%d\n", index);
6296
+ ip1811drv_dbg("type=%d\n", type);
6297
+
6298
+ IP2Page(2);
6299
+
6300
+ Write_Reg(P2REG_VLAN_PROCOTOL_CFG+index*2, (u16)type);
6301
+
6302
+ return 0;
6303
+}
6304
+EXPORT_SYMBOL(switchdSetVlanProtocolType);
6305
+int setVlanProtocolType(void *cdata, int len)
6306
+{
6307
+ int index, type;
6308
+
6309
+ FUNC_MSG_IN;
6310
+ if (sizeof(struct VlanSetting) != len)
6311
+ return -EINVAL;
6312
+
6313
+ index = (((struct VlanSetting *)cdata) ->vtype) - 1;
6314
+ type= ((struct VlanSetting *)cdata) ->vdata;
6315
+
6316
+ if(switchdSetVlanProtocolType(index, type) != 0)
6317
+ return -EINVAL;
6318
+
6319
+ FUNC_MSG_OUT;
6320
+ return 0;
6321
+}
6322
+
6323
+int switchdSetVlanProtocolClear(int index)
6324
+{
6325
+ if (index < 0 || index >= MAX_PRO_VLAN_ENTRY_NUM)
6326
+ {
6327
+ ip1811drv_err("Error: index=%X\n", index);
6328
+ return -EINVAL;
6329
+ }
6330
+
6331
+ ip1811drv_dbg("index=0x%08x\n", index);
6332
+
6333
+ IP2Page(2);
6334
+ Write_Reg(P2REG_VLAN_PROCOTOL_CFG+index*2, 0 );
6335
+ Write_Reg(P2REG_VLAN_PROCOTOL_CFG+index*2+1, 0 );
6336
+
6337
+ return 0;
6338
+}
6339
+EXPORT_SYMBOL(switchdSetVlanProtocolClear);
6340
+int setVlanProtocolClear(void *cdata, int len)
6341
+{
6342
+ int index;
6343
+
6344
+ FUNC_MSG_IN;
6345
+ if (sizeof(struct GeneralSetting) != len)
6346
+ return -EINVAL;
6347
+
6348
+ index = (((struct GeneralSetting *)cdata) ->gdata) - 1;
6349
+
6350
+ if(switchdSetVlanProtocolClear(index) != 0)
6351
+ return -EINVAL;
6352
+
6353
+ FUNC_MSG_OUT;
6354
+ return 0;
6355
+}
6356
+
6357
+int switchdSetVlanMACBased(int mode)
6358
+{
6359
+ if (mode!=OP_FUNC_DISABLE && mode!=OP_FUNC_ENABLE){
6360
+ ip1811drv_err("Error: mode=%X\n", mode);
6361
+ return -EINVAL;
6362
+ }
6363
+
6364
+ ip1811drv_dbg("mode=0x%08x\n", mode);
6365
+
6366
+ _WriteRegBits(2, P2REG_VLANCFG, 11, 1, mode);
6367
+
6368
+ return 0;
6369
+}
6370
+EXPORT_SYMBOL(switchdSetVlanMACBased);
6371
+int setVlanMACBased(void *cdata, int len)
6372
+{
6373
+ int mode;
6374
+
6375
+ FUNC_MSG_IN;
6376
+ if (sizeof(struct GeneralSetting) != len)
6377
+ return -EINVAL;
6378
+
6379
+ mode = ((struct GeneralSetting *)cdata) ->gdata;
6380
+
6381
+ if(switchdSetVlanMACBased(mode) != 0)
6382
+ return -EINVAL;
6383
+
6384
+ FUNC_MSG_OUT;
6385
+ return 0;
6386
+}
6387
+
6388
+int switchdSetVlanMACBasedtableconfig(unsigned int index, unsigned int data)
6389
+{
6390
+ if (index < 0 || index >= MAX_FID_NUM)
6391
+ {
6392
+ ip1811drv_err("Error: index=%X\n", index);
6393
+ return -EINVAL;
6394
+ }
6395
+
6396
+ if (data & (~0x1FFF))
6397
+ {
6398
+ ip1811drv_err("Error: data=%X\n", data);
6399
+ return -EINVAL;
6400
+ }
6401
+
6402
+ ip1811drv_dbg("index=%d data=0x%08x\n", index, data);
6403
+
6404
+ IP2Page(2);
6405
+ Write_Reg(P2REG_VLAN_MACBASED_ENTRY_0+index, (u16)data);
6406
+
6407
+ return 0;
6408
+}
6409
+EXPORT_SYMBOL(switchdSetVlanMACBasedtableconfig);
6410
+int setVlanMACBasedtableconfig(void *cdata, int len)
6411
+{
6412
+ unsigned int index, data;
6413
+
6414
+ FUNC_MSG_IN;
6415
+ if (sizeof(struct MACVlanSetting) != len)
6416
+ return -EINVAL;
6417
+
6418
+ index = ((struct MACVlanSetting *)cdata) ->index;
6419
+ data = ((struct MACVlanSetting *)cdata) ->mvdata;
6420
+
6421
+ if(switchdSetVlanMACBasedtableconfig(index, data) != 0)
6422
+ return -EINVAL;
6423
+
6424
+ FUNC_MSG_OUT;
6425
+ return 0;
6426
+}
6427
+
6428
+int switchdGetVlanMACBasedtableconfig(unsigned int index, unsigned int *data)
6429
+{
6430
+ if (index < 0 || index >= MAX_FID_NUM)
6431
+ {
6432
+ ip1811drv_err("Error: index=%X\n", index);
6433
+ return -EINVAL;
6434
+ }
6435
+
6436
+ ip1811drv_dbg("index=%d\n", index);
6437
+
6438
+ IP2Page(2);
6439
+ *data = (unsigned int)Read_Reg(P2REG_VLAN_MACBASED_ENTRY_0+index);
6440
+
6441
+ return 0;
6442
+}
6443
+EXPORT_SYMBOL(switchdGetVlanMACBasedtableconfig);
6444
+int getVlanMACBasedtableconfig(void *cdata, int len)
6445
+{
6446
+ unsigned int index, data;
6447
+
6448
+ FUNC_MSG_IN;
6449
+ if (sizeof(struct MACVlanSetting) != len)
6450
+ return -EINVAL;
6451
+
6452
+ index = ((struct MACVlanSetting *)cdata) ->index;
6453
+
6454
+ if(switchdGetVlanMACBasedtableconfig(index, &data) != 0)
6455
+ return -EINVAL;
6456
+
6457
+ ((struct MACVlanSetting *)cdata) ->mvdata = data;
6458
+
6459
+ ip1811drv_dbg("cdata ->mvdata=%d\n", ((struct MACVlanSetting *)cdata) ->mvdata);
6460
+ FUNC_MSG_OUT;
6461
+ return 0;
6462
+}
6463
+
6464
+int switchdSetVlanMACBasedunknown(unsigned int data)
6465
+{
6466
+ if (data & (~0x1FFF))
6467
+ {
6468
+ ip1811drv_err("Error: data=%X\n", data);
6469
+ return -EINVAL;
6470
+ }
6471
+
6472
+ ip1811drv_dbg("data=0x%08x\n", data);
6473
+
6474
+ IP2Page(2);
6475
+ Write_Reg(P2REG_VLAN_MACBASED_UNKNOWN, (u16)data);
6476
+
6477
+ return 0;
6478
+}
6479
+EXPORT_SYMBOL(switchdSetVlanMACBasedunknown);
6480
+int setVlanMACBasedunknown(void *cdata, int len)
6481
+{
6482
+ unsigned int data;
6483
+
6484
+ FUNC_MSG_IN;
6485
+ if (sizeof(struct GeneralSetting) != len)
6486
+ return -EINVAL;
6487
+
6488
+ data = ((struct GeneralSetting *)cdata) ->gdata;
6489
+
6490
+ if(switchdSetVlanMACBasedunknown(data) != 0)
6491
+ return -EINVAL;
6492
+
6493
+ FUNC_MSG_OUT;
6494
+ return 0;
6495
+}
6496
+
6497
+//ip1811_vlan
6498
+int switchdSetVlanEntryMember(int vid, int member)
6499
+{
6500
+ u16 u16dat;
6501
+
6502
+ if (vid < 0 || vid >= MAX_PVID_NUM)
6503
+ {
6504
+ ip1811drv_err("Error: vid=%X\n", vid);
6505
+ return -EINVAL;
6506
+ }
6507
+
6508
+ if (member & ~(0x0FFF))
6509
+ {
6510
+ ip1811drv_err("Error: member=%X\n", member);
6511
+ return -EINVAL;
6512
+ }
6513
+
6514
+ ip1811drv_dbg("vid=%d\n", vid);
6515
+ ip1811drv_dbg("member=%d\n", member);
6516
+
6517
+ IP2Page(2);
6518
+ /* read data from VLAN table */
6519
+ u16dat = 0x8000 | vid;
6520
+ Write_Reg(P2REG_VLANCMD, u16dat);
6521
+ /* wait for command ack */
6522
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6523
+
6524
+
6525
+ /* set entry memeber */
6526
+ u16dat = Read_Reg(P2REG_VLANDAT0);
6527
+ u16dat &= ~0xFFF;
6528
+ u16dat |= (u16)member&0x0FFF;
6529
+ Write_Reg(P2REG_VLANDAT0, u16dat);
6530
+
6531
+ u16dat = Read_Reg(P2REG_VLANDAT0+1);
6532
+ Write_Reg(P2REG_VLANDAT0+1, u16dat);
6533
+ u16dat = Read_Reg(P2REG_VLANDAT0+2);
6534
+ Write_Reg(P2REG_VLANDAT0+2, u16dat);
6535
+
6536
+ /* set valid bit to 1 */
6537
+ u16dat = (u16)0x1;
6538
+ Write_Reg(P2REG_VLANDAT0+3, u16dat);
6539
+
6540
+ /* Write data to VLAN table */
6541
+ u16dat = 0xC000 | vid;
6542
+ Write_Reg(P2REG_VLANCMD, u16dat);
6543
+ /* wait for command ack */
6544
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6545
+
6546
+ return 0;
6547
+}
6548
+EXPORT_SYMBOL(switchdSetVlanEntryMember);
6549
+int setVlanEntryMember(void *cdata, int len)
6550
+{
6551
+ int vid, member;
6552
+
6553
+ FUNC_MSG_IN;
6554
+ if (sizeof(struct PortmapSetting) != len)
6555
+ return -EINVAL;
6556
+
6557
+ vid = ((struct PortmapSetting *)cdata) ->pmdata;
6558
+ member= ((struct PortmapSetting *)cdata) ->portmap;
6559
+
6560
+ if(switchdSetVlanEntryMember(vid, member) != 0)
6561
+ return -EINVAL;
6562
+
6563
+ FUNC_MSG_OUT;
6564
+ return 0;
6565
+}
6566
+
6567
+int switchdSetVlanEntryAddtag(int vid, int addtag)
6568
+{
6569
+ u16 u16dat;
6570
+
6571
+ if (vid < 0 || vid >= MAX_PVID_NUM)
6572
+ {
6573
+ ip1811drv_err("Error: vid=%X\n", vid);
6574
+ return -EINVAL;
6575
+ }
6576
+
6577
+ if (addtag & ~(0x0FFF))
6578
+ {
6579
+ ip1811drv_err("Error: addtag=%X\n", addtag);
6580
+ return -EINVAL;
6581
+ }
6582
+
6583
+ ip1811drv_dbg("vid=%d\n", vid);
6584
+ ip1811drv_dbg("addtag=%d\n", addtag);
6585
+
6586
+ IP2Page(2);
6587
+ /* read data from VLAN table */
6588
+ u16dat = 0x8000 | vid;
6589
+ Write_Reg(P2REG_VLANCMD, u16dat);
6590
+ /* wait for command ack */
6591
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6592
+
6593
+
6594
+ /* set entry addtag */
6595
+ u16dat = Read_Reg(P2REG_VLANDAT0);
6596
+ u16dat &= ~0xF000;
6597
+ u16dat |= (u16)(addtag&0xF)<<12;
6598
+ Write_Reg(P2REG_VLANDAT0, u16dat);
6599
+
6600
+ u16dat = Read_Reg(P2REG_VLANDAT0+1);
6601
+ u16dat &= ~0x00FF;
6602
+ u16dat |= (u16)(addtag>>4)&0x00FF;
6603
+ Write_Reg(P2REG_VLANDAT0+1, u16dat);
6604
+
6605
+ u16dat = Read_Reg(P2REG_VLANDAT0+2);
6606
+ Write_Reg(P2REG_VLANDAT0+2, u16dat);
6607
+
6608
+ /* set valid bit to 1 */
6609
+ u16dat = (u16)0x1;
6610
+ Write_Reg(P2REG_VLANDAT0+3, u16dat);
6611
+
6612
+ /* Write data to VLAN table */
6613
+ u16dat = 0xC000 | vid;
6614
+ Write_Reg(P2REG_VLANCMD, u16dat);
6615
+ /* wait for command ack */
6616
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6617
+
6618
+ return 0;
6619
+}
6620
+EXPORT_SYMBOL(switchdSetVlanEntryAddtag);
6621
+int setVlanEntryAddtag(void *cdata, int len)
6622
+{
6623
+ int vid, addtag;
6624
+
6625
+ FUNC_MSG_IN;
6626
+ if (sizeof(struct PortmapSetting) != len)
6627
+ return -EINVAL;
6628
+
6629
+ vid = ((struct PortmapSetting *)cdata) ->pmdata;
6630
+ addtag= ((struct PortmapSetting *)cdata) ->portmap;
6631
+
6632
+ if(switchdSetVlanEntryAddtag(vid, addtag) != 0)
6633
+ return -EINVAL;
6634
+
6635
+ FUNC_MSG_OUT;
6636
+ return 0;
6637
+}
6638
+
6639
+int switchdSetVlanEntryRmvtag(int vid, int rmvtag)
6640
+{
6641
+ u16 u16dat;
6642
+
6643
+ if (vid < 0 || vid >= MAX_PVID_NUM)
6644
+ {
6645
+ ip1811drv_err("Error: vid=%X\n", vid);
6646
+ return -EINVAL;
6647
+ }
6648
+
6649
+ if (rmvtag & ~(0x0FFF))
6650
+ {
6651
+ ip1811drv_err("Error: rmvtag=%X\n", rmvtag);
6652
+ return -EINVAL;
6653
+ }
6654
+
6655
+ ip1811drv_dbg("vid=%d\n", vid);
6656
+ ip1811drv_dbg("rmvtag=%d\n", rmvtag);
6657
+
6658
+ IP2Page(2);
6659
+ /* read data from VLAN table */
6660
+ u16dat = 0x8000 | vid;
6661
+ Write_Reg(P2REG_VLANCMD, u16dat);
6662
+ /* wait for command ack */
6663
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6664
+
6665
+ u16dat = Read_Reg(P2REG_VLANDAT0);
6666
+ Write_Reg(P2REG_VLANDAT0, u16dat);
6667
+
6668
+ /* set entry rmvtag */
6669
+ u16dat = Read_Reg(P2REG_VLANDAT0+1);
6670
+ u16dat &= ~0xFF00;
6671
+ u16dat |= (u16)(rmvtag&0xFF)<<8;
6672
+ Write_Reg(P2REG_VLANDAT0+1, u16dat);
6673
+
6674
+ u16dat = Read_Reg(P2REG_VLANDAT0+2);
6675
+ u16dat &= ~0xF;
6676
+ u16dat |= (u16)(rmvtag>>8)&0xF;
6677
+ Write_Reg(P2REG_VLANDAT0+2, u16dat);
6678
+
6679
+ /* set valid bit to 1 */
6680
+ u16dat = (u16)0x1;
6681
+ Write_Reg(P2REG_VLANDAT0+3, u16dat);
6682
+
6683
+ /* Write data to VLAN table */
6684
+ u16dat = 0xC000 | vid;
6685
+ Write_Reg(P2REG_VLANCMD, u16dat);
6686
+ /* wait for command ack */
6687
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6688
+
6689
+ return 0;
6690
+}
6691
+EXPORT_SYMBOL(switchdSetVlanEntryRmvtag);
6692
+int setVlanEntryRmvtag(void *cdata, int len)
6693
+{
6694
+ int vid, rmvtag;
6695
+
6696
+ FUNC_MSG_IN;
6697
+ if (sizeof(struct PortmapSetting) != len)
6698
+ return -EINVAL;
6699
+
6700
+ vid = ((struct PortmapSetting *)cdata) ->pmdata;
6701
+ rmvtag= ((struct PortmapSetting *)cdata) ->portmap;
6702
+
6703
+ if(switchdSetVlanEntryRmvtag(vid, rmvtag) != 0)
6704
+ return -EINVAL;
6705
+
6706
+ FUNC_MSG_OUT;
6707
+ return 0;
6708
+}
6709
+
6710
+int switchdSetVlanEntryPriority(int vid, int priority)
6711
+{
6712
+ u16 u16dat;
6713
+
6714
+ if (vid < 0 || vid >= MAX_PVID_NUM)
6715
+ {
6716
+ ip1811drv_err("Error: vid=%X\n", vid);
6717
+ return -EINVAL;
6718
+ }
6719
+
6720
+ if (priority & ~(0xF))
6721
+ {
6722
+ ip1811drv_err("Error: priority=%X\n", priority);
6723
+ return -EINVAL;
6724
+ }
6725
+
6726
+ ip1811drv_dbg("vid=%d\n", vid);
6727
+ ip1811drv_dbg("priority=%d\n", priority);
6728
+
6729
+ IP2Page(2);
6730
+ /* read data from VLAN table */
6731
+ u16dat = 0x8000 | vid;
6732
+ Write_Reg(P2REG_VLANCMD, u16dat);
6733
+ /* wait for command ack */
6734
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6735
+
6736
+ u16dat = Read_Reg(P2REG_VLANDAT0);
6737
+ Write_Reg(P2REG_VLANDAT0, u16dat);
6738
+ u16dat = Read_Reg(P2REG_VLANDAT0+1);
6739
+ Write_Reg(P2REG_VLANDAT0+1, u16dat);
6740
+
6741
+ /* set entry priority */
6742
+ u16dat = Read_Reg(P2REG_VLANDAT0+2);
6743
+ u16dat &= ~0x00F0;
6744
+ u16dat |= (u16)(priority&0xF)<<4;
6745
+ Write_Reg(P2REG_VLANDAT0+2, u16dat);
6746
+
6747
+ /* set valid bit to 1 */
6748
+ u16dat = (u16)0x1;
6749
+ Write_Reg(P2REG_VLANDAT0+3, u16dat);
6750
+
6751
+ /* Write data to VLAN table */
6752
+ u16dat = 0xC000 | vid;
6753
+ Write_Reg(P2REG_VLANCMD, u16dat);
6754
+ /* wait for command ack */
6755
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6756
+
6757
+ return 0;
6758
+}
6759
+EXPORT_SYMBOL(switchdSetVlanEntryPriority);
6760
+int setVlanEntryPriority(void *cdata, int len)
6761
+{
6762
+ int vid, priority;
6763
+
6764
+ FUNC_MSG_IN;
6765
+ if (sizeof(struct VlanSetting) != len)
6766
+ return -EINVAL;
6767
+
6768
+ vid = ((struct VlanSetting *)cdata) ->vtype;
6769
+ priority= ((struct VlanSetting *)cdata) ->vdata;
6770
+
6771
+ if(switchdSetVlanEntryPriority(vid, priority) != 0)
6772
+ return -EINVAL;
6773
+
6774
+ FUNC_MSG_OUT;
6775
+ return 0;
6776
+}
6777
+
6778
+int switchdSetVlanEntryFid(int vid, int fid)
6779
+{
6780
+ u16 u16dat;
6781
+
6782
+ if (vid < 0 || vid >= MAX_PVID_NUM)
6783
+ {
6784
+ ip1811drv_err("Error: vid=%X\n", vid);
6785
+ return -EINVAL;
6786
+ }
6787
+
6788
+ if (fid & ~(0xF))
6789
+ {
6790
+ ip1811drv_err("Error: fid=%X\n", fid);
6791
+ return -EINVAL;
6792
+ }
6793
+
6794
+ ip1811drv_dbg("vid=%d\n", vid);
6795
+ ip1811drv_dbg("fid=%d\n", fid);
6796
+
6797
+ IP2Page(2);
6798
+ /* read data from VLAN table */
6799
+ u16dat = 0x8000 | vid;
6800
+ Write_Reg(P2REG_VLANCMD, u16dat);
6801
+ /* wait for command ack */
6802
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6803
+
6804
+ u16dat = Read_Reg(P2REG_VLANDAT0);
6805
+ Write_Reg(P2REG_VLANDAT0, u16dat);
6806
+ u16dat = Read_Reg(P2REG_VLANDAT0+1);
6807
+ Write_Reg(P2REG_VLANDAT0+1, u16dat);
6808
+
6809
+ /* set entry fid */
6810
+ u16dat = Read_Reg(P2REG_VLANDAT0+2);
6811
+ u16dat &= ~0xFF00;
6812
+ u16dat |= (u16)(fid&0xF)<<8;
6813
+ u16dat |= (u16)(fid&0xF)<<12;
6814
+ Write_Reg(P2REG_VLANDAT0+2, u16dat);
6815
+
6816
+ /* set valid bit to 1 */
6817
+ u16dat = (u16)0x1;
6818
+ Write_Reg(P2REG_VLANDAT0+3, u16dat);
6819
+
6820
+ /* Write data to VLAN table */
6821
+ u16dat = 0xC000 | vid;
6822
+ Write_Reg(P2REG_VLANCMD, u16dat);
6823
+ /* wait for command ack */
6824
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6825
+
6826
+ return 0;
6827
+}
6828
+EXPORT_SYMBOL(switchdSetVlanEntryFid);
6829
+int setVlanEntryFid(void *cdata, int len)
6830
+{
6831
+ int vid, fid;
6832
+
6833
+ FUNC_MSG_IN;
6834
+ if (sizeof(struct VlanSetting) != len)
6835
+ return -EINVAL;
6836
+
6837
+ vid = ((struct VlanSetting *)cdata) ->vtype;
6838
+ fid= ((struct VlanSetting *)cdata) ->vdata;
6839
+
6840
+ if(switchdSetVlanEntryFid(vid, fid) != 0)
6841
+ return -EINVAL;
6842
+
6843
+ FUNC_MSG_OUT;
6844
+ return 0;
6845
+}
6846
+
6847
+int switchdGetVlanEntryFid(int vid, int *ptrFid)
6848
+{
6849
+ u16 u16dat;
6850
+
6851
+ if (vid < 0 || vid >= MAX_PVID_NUM){
6852
+ ip1811drv_err("Error: vtype=%X\n", vid);
6853
+ return -EINVAL;
6854
+ }
6855
+
6856
+ ip1811drv_dbg("vid=%d\n", vid);
6857
+
6858
+ IP2Page(2);
6859
+ /* read data from VLAN table */
6860
+ u16dat = 0x8000 | vid;
6861
+ Write_Reg(P2REG_VLANCMD, u16dat);
6862
+ /* wait for command ack */
6863
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6864
+
6865
+ /* get entry fid */
6866
+ u16dat = Read_Reg(P2REG_VLANDAT0+2);
6867
+ *ptrFid = (int)(u16dat>>8)&0xF;
6868
+
6869
+ return 0;
6870
+}
6871
+EXPORT_SYMBOL(switchdGetVlanEntryFid);
6872
+int getVlanEntryFid(void *cdata, int len)
6873
+{
6874
+ int vid, fid=0;
6875
+
6876
+ FUNC_MSG_IN;
6877
+ if (sizeof(struct VlanSetting) != len)
6878
+ return -EINVAL;
6879
+
6880
+ vid = ((struct VlanSetting *)cdata) ->vtype;
6881
+
6882
+ if(switchdGetVlanEntryFid(vid, &fid) != 0)
6883
+ return -EINVAL;
6884
+
6885
+ ((struct VlanSetting *)cdata) ->vdata = fid;
6886
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct VlanSetting *)cdata) ->vdata);
6887
+ FUNC_MSG_OUT;
6888
+ return 0;
6889
+}
6890
+
6891
+int switchdSetVlanEntryClear(int vid)
6892
+{
6893
+ u16 u16dat;
6894
+ int i;
6895
+
6896
+ if (vid < 0 || vid >= MAX_PVID_NUM)
6897
+ {
6898
+ ip1811drv_err("Error: vid=%X\n", vid);
6899
+ return -EINVAL;
6900
+ }
6901
+
6902
+ ip1811drv_dbg("vid=%d\n", vid);
6903
+
6904
+ IP2Page(2);
6905
+
6906
+ /* clear entry data */
6907
+ for(i=0; i<4; i++)
6908
+ Write_Reg(P2REG_VLANDAT0+i, 0 );
6909
+
6910
+ /* Write data from VLAN table */
6911
+ u16dat = 0xC000 | vid;
6912
+ Write_Reg(P2REG_VLANCMD, u16dat);
6913
+ /* wait for command ack */
6914
+ while(Read_Reg(P2REG_VLANCMD)&0x8000);
6915
+
6916
+ return 0;
6917
+}
6918
+EXPORT_SYMBOL(switchdSetVlanEntryClear);
6919
+int setVlanEntryClear(void *cdata, int len)
6920
+{
6921
+ int vid;
6922
+
6923
+ FUNC_MSG_IN;
6924
+ if (sizeof(struct GeneralSetting) != len)
6925
+ return -EINVAL;
6926
+
6927
+ vid = ((struct GeneralSetting *)cdata) ->gdata;
6928
+
6929
+ if(switchdSetVlanEntryClear(vid) != 0)
6930
+ return -EINVAL;
6931
+
6932
+ FUNC_MSG_OUT;
6933
+ return 0;
6934
+}
6935
+
6936
+//------------------------------------------------
6937
+//ip1811_lut
6938
+int switchdSetLutUnknownSARule(int rule)
6939
+{
6940
+ if ( !( rule==OP_LUT_UNKNOWN_SA_DROP ||
6941
+ rule==OP_LUT_UNKNOWN_SA_FWD_2_CPU ||
6942
+ rule==OP_LUT_UNKNOWN_SA_FWD) )
6943
+ return -EINVAL;
6944
+
6945
+ ip1811drv_dbg("rule=%d\n", rule);
6946
+
6947
+ _WriteRegBits(1, P1REG_SRCLEARNCFG, 3, 2, rule);
6948
+
6949
+ return 0;
6950
+}
6951
+EXPORT_SYMBOL(switchdSetLutUnknownSARule);
6952
+int setLutUnknownSARule(void *cdata, int len)
6953
+{
6954
+ int rule;
6955
+
6956
+ FUNC_MSG_IN;
6957
+ if (sizeof(struct GeneralSetting) != len)
6958
+ return -EINVAL;
6959
+
6960
+ rule = ((struct GeneralSetting *)cdata) ->gdata;
6961
+
6962
+ if(switchdSetLutUnknownSARule(rule) != 0)
6963
+ return -EINVAL;
6964
+
6965
+ FUNC_MSG_OUT;
6966
+ return 0;
6967
+}
6968
+
6969
+int switchdSetLutEntry(struct IP1811LUTSetting *luts)
6970
+{
6971
+ int i;
6972
+ unsigned char f_notMatch = 0;
6973
+ u16 u16dat, index;
6974
+ u8 block;
6975
+ int temp_offset = -1;
6976
+ struct IP1811LUTSetting tmp_luts;
6977
+
6978
+ if( luts ->action!=OP_ENTRY_CREATE &&
6979
+ luts ->action!=OP_ENTRY_CONFIG &&
6980
+ luts ->action!=OP_ENTRY_DELETE &&
6981
+ luts ->action!=OP_ENTRY_CREATE_REG)
6982
+ {
6983
+ ip1811drv_err("action error:%d\n", luts ->action);
6984
+ return -EINVAL;
6985
+ }
6986
+ if( luts ->action == OP_ENTRY_CREATE ||
6987
+ luts ->action == OP_ENTRY_CONFIG)
6988
+ {
6989
+ if(luts ->entry.fid > 15)
6990
+ {
6991
+ ip1811drv_err("fid error:%d\n", luts ->entry.fid);
6992
+ return -EINVAL;
6993
+ }
6994
+ if(luts ->entry.srcport > 31)
6995
+ {
6996
+ ip1811drv_err("srcport error:%d\n", luts ->entry.srcport);
6997
+ return -EINVAL;
6998
+ }
6999
+ if(luts ->entry.aging > 15)
7000
+ {
7001
+ ip1811drv_err("aging error:%d\n", luts ->entry.aging);
7002
+ return -EINVAL;
7003
+ }
7004
+ if(luts ->entry.priority > 15)
7005
+ {
7006
+ ip1811drv_err("priority error:%d\n", luts ->entry.priority);
7007
+ return -EINVAL;
7008
+ }
7009
+ if(luts ->entry.cfg > OP_LUT_CFG_MVT)
7010
+ {
7011
+ ip1811drv_err("cfg error:%d\n", luts ->entry.cfg);
7012
+ return -EINVAL;
7013
+ }
7014
+ }
7015
+
7016
+ /* initialize retval value */
7017
+ luts ->retval = 0;
7018
+ /* calculate hash value */
7019
+ index = 0;//LUT_hash(luts ->entry.mac, luts ->entry.fid);
7020
+
7021
+ ip1811drv_dbg("index=%d\n", index);
7022
+ ip1811drv_dbg("MAC=\n");
7023
+ for(i=0; i<6; i++)
7024
+ ip1811drv_dbg("[%02X]\n", luts ->entry.mac[i]);
7025
+ ip1811drv_dbg("fid=%d\n", luts ->entry.fid);
7026
+ ip1811drv_dbg("srcport=%d\n", luts ->entry.srcport);
7027
+ ip1811drv_dbg("aging=%d\n", luts ->entry.aging);
7028
+ ip1811drv_dbg("priority=%d\n", luts ->entry.priority);
7029
+ ip1811drv_dbg("drop=%d\n", luts ->entry.flag.drop);
7030
+ ip1811drv_dbg("snif=%d\n", luts ->entry.flag.snif);
7031
+ ip1811drv_dbg("sflow=%d\n", luts ->entry.flag.sflow);
7032
+ ip1811drv_dbg("cfg=%d\n", luts ->entry.cfg);
7033
+
7034
+ IP2Page(1);
7035
+ if(luts ->action==OP_ENTRY_CREATE_REG)
7036
+ {
7037
+ ip1811drv_dbg("OP_ENTRY_CREATE_REG\n");
7038
+ for(i=0; i<5; i++)
7039
+ Write_Reg(P1REG_LUTDATA_0+i, luts ->data[i] );
7040
+ Write_Reg(P1REG_LUTDATA_0+5, luts ->data[5]|0x0800 ); //hw_calc
7041
+
7042
+ u16dat = 0;
7043
+ u16dat |= (u16)0x3<<14; //set write command & command trigger
7044
+ Write_Reg(P1REG_LUTCFG, u16dat );
7045
+ /* need to check does trigger bit has been pull up */
7046
+ while(!(Read_Reg(P1REG_LUTCFG)&0x8000));
7047
+ return 0;
7048
+ }
7049
+
7050
+ /* search the index of target entry */
7051
+ /* cause use hw_calc bit can't get entry index */
7052
+// if((luts ->action==OP_ENTRY_CONFIG) || (luts ->action==OP_ENTRY_DELETE))
7053
+ {
7054
+ memset(&tmp_luts, 0, sizeof(struct IP1811LUTSetting));
7055
+ /* search all entries */
7056
+ tmp_luts.action = OP_LUT_STATE_ALL;
7057
+ tmp_luts.tarports = ALL_PHY_PORTS_LIST;
7058
+ while(1)
7059
+ {
7060
+ /* try to get a valid MAC entry */
7061
+ tmp_luts.retval = 0;
7062
+ getLutValidEntry(&tmp_luts, sizeof(struct IP1811LUTSetting));
7063
+ if(tmp_luts.retval != OP_ENTRY_EXISTS)
7064
+ break;
7065
+
7066
+ /* get a valid static entry */
7067
+
7068
+ /* check MAC address & FID */
7069
+ f_notMatch = 0;
7070
+ for(i=0; i<6; i++)
7071
+ {
7072
+ if(luts ->entry.mac[i] != tmp_luts.entry.mac[i])
7073
+ {
7074
+ f_notMatch = 1;
7075
+ break;
7076
+ }
7077
+ }
7078
+ if(luts ->entry.fid != tmp_luts.entry.fid)
7079
+ f_notMatch = 1;
7080
+
7081
+ if(!f_notMatch){
7082
+ /* if match, record the index */
7083
+ temp_offset = tmp_luts.index;
7084
+ break;
7085
+ }
7086
+
7087
+ /* search next valid entry */
7088
+ tmp_luts.index++;
7089
+ }
7090
+ }
7091
+
7092
+ if(luts ->action==OP_ENTRY_CREATE)
7093
+ {
7094
+ ip1811drv_dbg("OP_ENTRY_CREATE\n");
7095
+ if(tmp_luts.entry.aging == 0xf)
7096
+ {
7097
+ ip1811drv_dbg("target entry has existed!!\n");
7098
+ luts ->retval = OP_ENTRY_EXISTS;
7099
+ return 0;
7100
+ }
7101
+ for(i=0; i<3; i++)
7102
+ {
7103
+ u16dat = (u16)(luts ->entry.mac[4 - i*2])<<8 | (u16)(luts ->entry.mac[5 - i*2]);
7104
+ Write_Reg(P1REG_LUTDATA_0+i, u16dat );
7105
+ }
7106
+ u16dat = 0;
7107
+ u16dat = luts ->entry.fid;
7108
+ u16dat |= (u16)luts ->entry.srcport<<4;
7109
+ u16dat |= (u16)0x0f<<9; //set aging to static
7110
+ u16dat |= (u16)((luts ->entry.priority & 0x7)<<13);
7111
+ Write_Reg(P1REG_LUTDATA_3, u16dat );
7112
+
7113
+ u16dat = (u16)((luts ->entry.priority >> 3)&0x1);
7114
+ u16dat |= (u16)luts ->entry.flag.sflow<<1;
7115
+ u16dat |= (u16)luts ->entry.flag.snif<<2;
7116
+ u16dat |= (u16)luts ->entry.flag.drop<<3;
7117
+ if (luts ->entry.cfg < OP_LUT_CFG_TRAN)
7118
+ u16dat |= (u16)((luts ->entry.cfg & 0x3)<<4);
7119
+ else
7120
+ {
7121
+ u16dat |= (u16)0x0020; // cfg[1] = 1
7122
+ if (luts ->entry.cfg == OP_LUT_CFG_MVT)
7123
+ u16dat |= (u16)0x0008; // drop = 1
7124
+ }
7125
+ Write_Reg(P1REG_LUTDATA_4, u16dat );
7126
+
7127
+ u16dat = 0x01<<11;//hw_calc
7128
+ Write_Reg(P1REG_LUTDATA_5, u16dat );
7129
+
7130
+ u16dat = 0; //set index
7131
+ u16dat |= (u16)0x3<<14; //set write command & command trigger
7132
+ Write_Reg(P1REG_LUTCFG, u16dat );
7133
+
7134
+ /* need to check does trigger bit has been pull up */
7135
+ while(!(Read_Reg(P1REG_LUTCFG)&0x8000));
7136
+ }
7137
+ else if(luts ->action==OP_ENTRY_CONFIG)
7138
+ {
7139
+ ip1811drv_dbg("OP_ENTRY_CONFIG\n");
7140
+ /* if MAC or FID isn't match, we should abort this configuration */
7141
+ if(f_notMatch)
7142
+ {
7143
+ ip1811drv_dbg("MAC or FID not match!!\n");
7144
+ luts ->retval = OP_ENTRY_NOT_MATCH;
7145
+ return 0;
7146
+ }
7147
+
7148
+ for (i=0; i < 3; i++)
7149
+ Write_Reg(P1REG_LUTDATA_0+i, tmp_luts.data[i]);
7150
+
7151
+ u16dat = luts ->entry.fid;
7152
+ u16dat |= (u16)luts ->entry.srcport<<4;
7153
+ u16dat |= (u16)0x0f<<9; //set aging to static
7154
+ u16dat |= (u16)((luts ->entry.priority & 0x7)<<13);
7155
+ Write_Reg(P1REG_LUTDATA_3, u16dat );
7156
+
7157
+ u16dat = (u16)((luts ->entry.priority >> 3)&0x1);
7158
+ u16dat |= (u16)luts ->entry.flag.sflow<<1;
7159
+ u16dat |= (u16)luts ->entry.flag.snif<<2;
7160
+ if (luts ->entry.cfg < OP_LUT_CFG_TRAN)
7161
+ {
7162
+ u16dat |= (u16)luts ->entry.flag.drop<<3;
7163
+ u16dat |= (u16)((luts ->entry.cfg & 0x3)<<4);
7164
+ }
7165
+ else
7166
+ {
7167
+ u16dat |= (u16)0x0020; // cfg[1] = 1
7168
+ if (luts ->entry.cfg == OP_LUT_CFG_MVT)
7169
+ u16dat |= (u16)0x0008; // drop = 1
7170
+ }
7171
+ Write_Reg(P1REG_LUTDATA_4, u16dat );
7172
+
7173
+ u16dat = 0x01<<11;//hw_calc
7174
+ Write_Reg(P1REG_LUTDATA_5, u16dat );
7175
+
7176
+ u16dat = 0; //set index
7177
+ u16dat |= (u16)0x3<<14; //set write command & command trigger
7178
+ Write_Reg(P1REG_LUTCFG, u16dat );
7179
+
7180
+ /* need to check does trigger bit has been pull up */
7181
+ while(!(Read_Reg(P1REG_LUTCFG)&0x8000));
7182
+ }
7183
+ else if(luts ->action==OP_ENTRY_DELETE)
7184
+ {
7185
+ ip1811drv_dbg("OP_ENTRY_DELETE\n");
7186
+ if(f_notMatch)
7187
+ {
7188
+ ip1811drv_dbg("MAC or FID not match!!\n");
7189
+ luts ->retval = OP_ENTRY_NOT_MATCH;
7190
+ return 0;
7191
+ }
7192
+ if(tmp_luts.entry.aging != 0xf)
7193
+ {
7194
+ /* only static entry can be deleted */
7195
+ ip1811drv_dbg("not static entry!!\n");
7196
+ luts ->retval = OP_ENTRY_NOT_FOUND;
7197
+ return 0;
7198
+ }
7199
+
7200
+ for (i=0; i < 3; i++)
7201
+ Write_Reg(P1REG_LUTDATA_0+i, tmp_luts.data[i]);
7202
+
7203
+ u16dat = 0x0; //set aging to invalid
7204
+ Write_Reg(P1REG_LUTDATA_3, u16dat );
7205
+
7206
+ u16dat = 0x01<<11;//hw_calc
7207
+ Write_Reg(P1REG_LUTDATA_5, u16dat );
7208
+
7209
+ u16dat = 0; //set index
7210
+ u16dat |= (u16)0x3<<14; //set write command & command trigger
7211
+ Write_Reg(P1REG_LUTCFG, u16dat );
7212
+
7213
+ /* need to check does trigger bit has been pull up */
7214
+ while(!(Read_Reg(P1REG_LUTCFG)&0x8000));
7215
+ }
7216
+
7217
+ return 0;
7218
+}
7219
+EXPORT_SYMBOL(switchdSetLutEntry);
7220
+int setLutEntry(void *cdata, const int len)
7221
+{
7222
+ struct IP1811LUTSetting *luts;
7223
+
7224
+ FUNC_MSG_IN;
7225
+ /* check cdata length */
7226
+ if (sizeof(struct IP1811LUTSetting) != len){
7227
+ ip1811drv_err("Error: lengtn=%d\n", len);
7228
+ return -EINVAL;
7229
+ }
7230
+
7231
+ luts = (struct IP1811LUTSetting *)cdata;
7232
+
7233
+ if(switchdSetLutEntry(luts) != 0)
7234
+ return -EINVAL;
7235
+
7236
+ FUNC_MSG_OUT;
7237
+ return 0;
7238
+}
7239
+
7240
+u8 getLutCfgFromReg(u16 reg)
7241
+{
7242
+ if (reg & 0x0020) // cfg[1] = 1
7243
+ {
7244
+ if (reg & 0x8) // drop = 1
7245
+ return (u8)OP_LUT_CFG_MVT;
7246
+ else
7247
+ return (u8)OP_LUT_CFG_TRAN;
7248
+ }
7249
+ else // cfg[1] = 0
7250
+ return (u8)((reg >> 4) & 0x1);
7251
+}
7252
+
7253
+int switchdGetLutEntry(struct IP1811LUTSetting *luts)
7254
+{
7255
+ int i;
7256
+ bool f_notMatch = 0;
7257
+ u16 u16dat, lutdat_3, lutdat_4;
7258
+ int val_aging;
7259
+ u8 op_cfg;
7260
+
7261
+ /* check index range */
7262
+ if(luts ->index >= MAX_LUT_ENTRY_NUM){
7263
+ ip1811drv_err("Error: index=%d\n", luts ->index);
7264
+ return -EINVAL;
7265
+ }
7266
+
7267
+ /* set to register page 1 */
7268
+ IP2Page(1);
7269
+
7270
+ /* check command action */
7271
+ if(luts ->action == OP_ENTRY_GET_BY_INFO){
7272
+ if(luts ->entry.fid >= MAX_FID_NUM){
7273
+ ip1811drv_err("Error: fid=%d\n", luts ->entry.fid);
7274
+ return -EINVAL;
7275
+ }
7276
+
7277
+ /* copy mac to register from cdata */
7278
+ for(i=0; i<3; i++){
7279
+ u16dat = (u16)(luts ->entry.mac[4 - i*2])<<8 | (u16)(luts ->entry.mac[5 - i*2]);
7280
+ Write_Reg(P1REG_LUTDATA_0 + i, u16dat );
7281
+ }
7282
+
7283
+ /* set fid to register from cdata */
7284
+ Write_Reg(P1REG_LUTDATA_3, luts ->entry.fid );
7285
+
7286
+ /* setup table address access method by HW */
7287
+ Write_Reg(P1REG_LUTDATA_5, 0x0800 );
7288
+ }
7289
+ else if(luts ->action == OP_ENTRY_GET_BY_INDEX){
7290
+ /* setup table address access method by CPU */
7291
+ Write_Reg(P1REG_LUTDATA_5, 0 );
7292
+ }
7293
+ else{
7294
+ ip1811drv_err("Error: action=%d\n", luts ->action);
7295
+ return -EINVAL;
7296
+ }
7297
+
7298
+ /* initialize return value */
7299
+ luts ->retval = 0;
7300
+
7301
+ u16dat = luts ->index; //set index
7302
+ u16dat |= (u16)0x2<<14; //set read command & command trigger
7303
+ Write_Reg(P1REG_LUTCFG, u16dat );
7304
+
7305
+ /* check does trigger bit has been pull up */
7306
+ while(!(Read_Reg(P1REG_LUTCFG)&0x8000));
7307
+
7308
+ /* catch aging time to check entry state */
7309
+ lutdat_3 = Read_Reg(P1REG_LUTDATA_3);
7310
+ lutdat_4 = Read_Reg(P1REG_LUTDATA_4);
7311
+ val_aging = (lutdat_3 >> 9) & 0x0F;
7312
+ if(val_aging == 0x0){
7313
+ luts ->retval = OP_ENTRY_NOT_FOUND;
7314
+ return 0;
7315
+ }
7316
+
7317
+ /* get lut cfg */
7318
+ op_cfg = getLutCfgFromReg(lutdat_4);
7319
+
7320
+ if(luts ->action == OP_ENTRY_GET_BY_INFO){
7321
+ /* if action is get by entry info, check if register value is same with input data */
7322
+ /* catch MAC address */
7323
+ for(i=0; i<3; i++){
7324
+ u16dat = Read_Reg(P1REG_LUTDATA_0 + i);
7325
+ if( luts ->entry.mac[5 - i*2] != (u8)(u16dat&0xFF) )
7326
+ f_notMatch = 1;
7327
+ if( luts ->entry.mac[4 - i*2] != (u8)((u16dat>>8)&0xFF) )
7328
+ f_notMatch = 1;
7329
+ }
7330
+
7331
+ /* check whether fid is matched to input cdata */
7332
+ if( luts ->entry.fid != (lutdat_3 & 0x000f))
7333
+ f_notMatch = 1;
7334
+
7335
+ /* check whether cfg is matched to input cdata */
7336
+ if( luts ->entry.cfg != op_cfg)
7337
+ f_notMatch = 1;
7338
+
7339
+ if(val_aging == 0xf){//static entry
7340
+ if(f_notMatch){
7341
+ ip1811drv_err("Error: MAC or FID is not match\n");
7342
+ luts ->retval = OP_ENTRY_NOT_MATCH;
7343
+ return 0;
7344
+ }
7345
+ else
7346
+ luts ->retval = OP_ENTRY_EXISTS;
7347
+ }
7348
+ else{//dynamic entry
7349
+ if(f_notMatch){
7350
+ ip1811drv_err("Error: MAC or FID is not match\n");
7351
+ luts ->retval = OP_ENTRY_NOT_MATCH;
7352
+ return 0;
7353
+ }
7354
+ else
7355
+ luts ->retval = OP_ENTRY_EXISTS_DYNAMIC;
7356
+ }
7357
+ }
7358
+ else{//if(luts ->action == OP_ENTRY_GET_BY_INDEX)
7359
+ if( ((lutdat_3 >> 9) & 0x000F ) == 0x000F )
7360
+ luts ->retval = OP_ENTRY_EXISTS;
7361
+ else
7362
+ luts ->retval = OP_ENTRY_EXISTS_DYNAMIC;
7363
+
7364
+ /* if action is get by entry index, copy the register value into output data */
7365
+ /* catch MAC address */
7366
+ for(i=0; i<3; i++){
7367
+ u16dat = Read_Reg(P1REG_LUTDATA_0 + i);
7368
+ luts ->entry.mac[5 - i*2] = (u8)(u16dat&0xFF);
7369
+ luts ->entry.mac[4 - i*2] = (u8)((u16dat>>8)&0xFF);
7370
+ }
7371
+
7372
+ lutdat_3 = Read_Reg(P1REG_LUTDATA_3);
7373
+ luts ->entry.fid = lutdat_3 & 0x000F;
7374
+ }
7375
+
7376
+ luts ->entry.priority = ((lutdat_4 & 0x0001) << 3) | ((lutdat_3>>13) & 0x0007);
7377
+ if (op_cfg < OP_LUT_CFG_TRAN)
7378
+ luts ->entry.flag.drop = (lutdat_4>>3) & 0x0001;
7379
+ else
7380
+ luts ->entry.flag.drop = 0;
7381
+ luts ->entry.flag.sflow = (lutdat_4>>1) & 0x0001;
7382
+ luts ->entry.flag.snif = (lutdat_4>>2) & 0x0001;
7383
+ luts ->entry.srcport = (lutdat_3>>4) & 0x001F;
7384
+
7385
+ luts ->entry.aging = val_aging;
7386
+ luts ->entry.cfg = op_cfg;
7387
+
7388
+ ip1811drv_dbg("cdata ->MAC=");
7389
+ for(i=0; i<6; i++)
7390
+ ip1811drv_dbg("[%02X]", luts ->entry.mac[i]);
7391
+ ip1811drv_dbg("\ncdata ->fid=%d\n", luts ->entry.fid);
7392
+ ip1811drv_dbg("cdata ->srcport=%d\n", luts ->entry.srcport);
7393
+ ip1811drv_dbg("cdata ->aging=%d\n", luts ->entry.aging);
7394
+ ip1811drv_dbg("cdata ->priority=%d\n", luts ->entry.priority);
7395
+ ip1811drv_dbg("cdata ->drop=%d\n", luts ->entry.flag.drop);
7396
+ ip1811drv_dbg("cdata ->snif=%d\n", luts ->entry.flag.snif);
7397
+ ip1811drv_dbg("cdata ->sflow=%d\n", luts ->entry.flag.sflow);
7398
+ ip1811drv_dbg("cdata ->cfg=%d\n", luts ->entry.cfg);
7399
+
7400
+ return 0;
7401
+}
7402
+EXPORT_SYMBOL(switchdGetLutEntry);
7403
+int getLutEntry(void *cdata, const int len)
7404
+{
7405
+ struct IP1811LUTSetting *luts;
7406
+
7407
+ FUNC_MSG_IN;
7408
+ /* check cdata length */
7409
+ if (sizeof(struct IP1811LUTSetting) != len){
7410
+ ip1811drv_err("Error: lengtn=%d\n", len);
7411
+ return -EINVAL;
7412
+ }
7413
+
7414
+ luts = (struct IP1811LUTSetting *)cdata;
7415
+
7416
+ if(switchdGetLutEntry(luts) != 0)
7417
+ return -EINVAL;
7418
+
7419
+ FUNC_MSG_OUT;
7420
+ return 0;
7421
+}
7422
+
7423
+int switchdGetLutValidEntry(struct IP1811LUTSetting *luts)
7424
+{
7425
+ int i, retrytimes=25;
7426
+ u16 u16dat, lutdat[6];
7427
+ unsigned short index;
7428
+ unsigned char block;
7429
+ int temp_offset;
7430
+
7431
+ u16 hashvid;
7432
+
7433
+ /* check index range */
7434
+ if(luts ->index >= MAX_LUT_ENTRY_NUM)
7435
+ {
7436
+ ip1811drv_err("Error: index=%d\n", luts ->index);
7437
+ return -EINVAL;
7438
+ }
7439
+ index = luts ->index;
7440
+
7441
+ ip1811drv_dbg("action=%d\n", luts ->action);
7442
+ /* set to register page 1 */
7443
+ IP2Page(1);
7444
+
7445
+ /* setup table address access method by CPU */
7446
+ Write_Reg(P1REG_LUTDATA_5, 0 );
7447
+
7448
+ /* initialize return value */
7449
+ luts ->retval = 0;
7450
+
7451
+ u16dat = index; //set index
7452
+ u16dat |= (u16)0x2000; //sequential search for valid entry
7453
+ u16dat |= (u16)0x2<<14; //set read command & command trigger
7454
+ Write_Reg(P1REG_LUTCFG, u16dat );
7455
+
7456
+ while (1)
7457
+ {
7458
+ memset(lutdat, 0, sizeof(lutdat));
7459
+
7460
+ /* check does trigger bit has been pull up */
7461
+ for (i=0; i < retrytimes; i++)
7462
+ {
7463
+ udelay(100);
7464
+ u16dat = Read_Reg(P1REG_LUTCFG);
7465
+ if (u16dat & 0x8000)
7466
+ break;
7467
+ }
7468
+ if (i == retrytimes)
7469
+ goto out_switchdGetLutValidEntry;
7470
+
7471
+ /* read out all registers of lut data */
7472
+ for (i=0; i < 6; i++)
7473
+ lutdat[i] = Read_Reg(P1REG_LUTDATA_0+i);
7474
+
7475
+ /* check if there is any entry data */
7476
+ if (lutdat[0]==0 && lutdat[1]==0 && lutdat[2]==0){
7477
+ /* no data in lut table */
7478
+ goto out_switchdGetLutValidEntry;
7479
+ }
7480
+
7481
+ /* check if there is no more new data */
7482
+ if (!(u16dat & 0x2000)){
7483
+ /* lut table has been scanned to the end */
7484
+ goto out_switchdGetLutValidEntry;
7485
+ }
7486
+
7487
+ /* catch aging time to check entry state */
7488
+ if((lutdat[3] &0x1e00) == 0x0){
7489
+ /* invalid entry */
7490
+ continue;
7491
+ }
7492
+ if( ((lutdat[3] >> 9) & 0xf) == 0xf &&
7493
+ !(luts ->action & OP_LUT_STATE_STATIC)
7494
+ )
7495
+ {
7496
+ /* action don't need static entry */
7497
+ continue;
7498
+ }
7499
+ if( ((lutdat[3] >> 9) & 0xf) != 0xf &&
7500
+ !(luts ->action & OP_LUT_STATE_DYNAMIC) )
7501
+ {
7502
+ /* action don't need dynamic entry */
7503
+ continue;
7504
+ }
7505
+
7506
+ /* check whether source port bigger than CPU port num */
7507
+ if((((lutdat[3]>>4) & 0x001f) + 1) > MAX_PHY_NUM)
7508
+ continue;
7509
+
7510
+ /* check whether this entry is in target portlist */
7511
+ if(!((1UL << ((lutdat[3]>>4) & 0x001f))&luts ->tarports))
7512
+ continue;
7513
+
7514
+ break;
7515
+ }
7516
+
7517
+ /* if find a valid entry, copy the register value into output data */
7518
+ /* catch MAC address */
7519
+ for(i=0; i<6; i++)
7520
+ {
7521
+ luts ->data[i] = lutdat[i];
7522
+ if (i < 3)
7523
+ {
7524
+ luts ->entry.mac[5 - i*2] = (u8)(lutdat[i]&0xFF);
7525
+ luts ->entry.mac[4 - i*2] = (u8)((lutdat[i]>>8)&0xFF);
7526
+ }
7527
+ }
7528
+
7529
+ luts ->entry.fid = lutdat[3] & 0x000f;
7530
+ luts ->entry.srcport = (lutdat[3]>>4) & 0x001f;
7531
+ luts ->entry.aging = (lutdat[3]>>9) & 0x000f;
7532
+ luts ->entry.priority = (lutdat[3]>>13) & 0x0007;
7533
+ luts ->entry.priority |= ((lutdat[4] & 0x0001) << 3);
7534
+
7535
+ luts ->entry.flag.sflow = (lutdat[4]>>1) & 0x0001;
7536
+ luts ->entry.flag.snif = (lutdat[4]>>2) & 0x0001;
7537
+ luts -> entry.cfg = getLutCfgFromReg(lutdat[4]);
7538
+ if (luts -> entry.cfg < OP_LUT_CFG_TRAN)
7539
+ luts ->entry.flag.drop = (lutdat[4]>>3) & 0x0001;
7540
+ else
7541
+ luts ->entry.flag.drop = 0;
7542
+
7543
+ luts ->retval = OP_ENTRY_EXISTS;
7544
+
7545
+ ip1811drv_dbg("=====================================\n");
7546
+ ip1811drv_dbg("index=%d\n", luts ->index);
7547
+ ip1811drv_dbg("retval=%lX\n", luts ->retval);
7548
+ ip1811drv_dbg("MAC=");
7549
+ for(i=0; i<6; i++)
7550
+ ip1811drv_dbg("[%02X]", luts ->entry.mac[i]);
7551
+ ip1811drv_dbg("\nfid=%d\n", luts ->entry.fid);
7552
+ ip1811drv_dbg("srcport=%d\n", luts ->entry.srcport);
7553
+ ip1811drv_dbg("aging=%d\n", luts ->entry.aging);
7554
+ ip1811drv_dbg("priority=%d\n", luts ->entry.priority);
7555
+ ip1811drv_dbg("drop=%d\n", luts ->entry.flag.drop);
7556
+ ip1811drv_dbg("snif=%d\n", luts ->entry.flag.snif);
7557
+ ip1811drv_dbg("sflow=%d\n", luts ->entry.flag.sflow);
7558
+ ip1811drv_dbg("cfg=%d\n", luts ->entry.cfg);
7559
+
7560
+out_switchdGetLutValidEntry:
7561
+ return 0;
7562
+}
7563
+EXPORT_SYMBOL(switchdGetLutValidEntry);
7564
+int getLutValidEntry(void *cdata, const int len)
7565
+{
7566
+ struct IP1811LUTSetting *luts;
7567
+
7568
+ FUNC_MSG_IN;
7569
+ /* check cdata length */
7570
+ if (sizeof(struct IP1811LUTSetting) != len){
7571
+ ip1811drv_err("Error: lengtn=%d\n", len);
7572
+ return -EINVAL;
7573
+ }
7574
+
7575
+ luts = (struct IP1811LUTSetting *)cdata;
7576
+
7577
+ if(switchdGetLutValidEntry(luts) != 0)
7578
+ return -EINVAL;
7579
+
7580
+ FUNC_MSG_OUT;
7581
+ return 0;
7582
+}
7583
+
7584
+//------------------------------------------------
7585
+//ip1811_igmp
7586
+int switchdSetIGMPSnooping(int enable)
7587
+{
7588
+ switch(enable) {
7589
+ case OP_FUNC_ENABLE:
7590
+ ip1811drv_dbg("Enable IGMP\n");
7591
+ break;
7592
+ case OP_FUNC_DISABLE:
7593
+ ip1811drv_dbg("Disable IGMP\n");
7594
+ break;
7595
+ default:
7596
+ ip1811drv_dbg("Option can't find\n");
7597
+ return -EINVAL;
7598
+ }
7599
+
7600
+ ip1811drv_dbg("Set IGMPSNOP: %x\n", enable);
7601
+ _WriteRegBits(1, P1REG_IGMPSNOP, 0, 1, enable);
7602
+ return 0;
7603
+}
7604
+EXPORT_SYMBOL(switchdSetIGMPSnooping);
7605
+
7606
+int setIGMPSnooping(void *cdata, int len)
7607
+{
7608
+ int ret, func_en;
7609
+ struct GeneralSetting *igmp;
7610
+
7611
+ FUNC_MSG_IN;
7612
+ ip1811drv_dbg("In setIGMPSnoopin.\n");
7613
+ if (sizeof(struct GeneralSetting) != len) {
7614
+ ip1811drv_err("length error!\n");
7615
+ return -EINVAL;
7616
+ }
7617
+
7618
+ igmp = (struct GeneralSetting *)cdata;
7619
+ func_en = igmp ->gdata;
7620
+ ret = switchdSetIGMPSnooping(func_en);
7621
+ FUNC_MSG_OUT;
7622
+
7623
+ return ret;
7624
+}
7625
+
7626
+int switchdGetIGMPSnooping(int *gdata_p)
7627
+{
7628
+ *gdata_p = (int)_ReadRegBits(1, P1REG_IGMPSNOP, 0, 1)?OP_FUNC_ENABLE:OP_FUNC_DISABLE;
7629
+ ip1811drv_dbg("IGMP %s",(*gdata_p==OP_FUNC_ENABLE)?"ENABLE":"DISABLE");
7630
+ return 0;
7631
+}
7632
+EXPORT_SYMBOL(switchdGetIGMPSnooping);
7633
+
7634
+int getIGMPSnooping(void *cdata, int len)
7635
+{
7636
+ int ret;
7637
+ struct GeneralSetting *igmp;
7638
+
7639
+ FUNC_MSG_IN;
7640
+ ip1811drv_dbg("In getIGMPSnoopin.\n");
7641
+ if (sizeof(struct GeneralSetting) != len) {
7642
+ ip1811drv_err("length error!\n");
7643
+ return -EINVAL;
7644
+ }
7645
+
7646
+ igmp = (struct GeneralSetting *)cdata;
7647
+ ret = switchdGetIGMPSnooping(&(igmp ->gdata))
7648
+ FUNC_MSG_OUT;
7649
+ return ret;
7650
+}
7651
+
7652
+int switchdSetIGMPMctByCPU(int enable)
7653
+{
7654
+ switch(enable) {
7655
+ case OP_FUNC_ENABLE:
7656
+ ip1811drv_dbg("Enable MCT By CPU\n");
7657
+ break;
7658
+ case OP_FUNC_DISABLE:
7659
+ ip1811drv_dbg("Disable MCT By CPU\n");
7660
+ break;
7661
+ default:
7662
+ ip1811drv_dbg("Option can't find\n");
7663
+ return -EINVAL;
7664
+ }
7665
+
7666
+ ip1811drv_dbg("Set MCT By CPU: %x\n", enable);
7667
+ _WriteRegBits(1, P1REG_IGMPSNOP, 1, 1, enable);
7668
+ return 0;
7669
+}
7670
+EXPORT_SYMBOL(switchdSetIGMPMctByCPU);
7671
+
7672
+int setIGMPMctByCPU(void *cdata, int len)
7673
+{
7674
+ int ret, func_en;
7675
+ struct GeneralSetting *igmp;
7676
+
7677
+ FUNC_MSG_IN;
7678
+ ip1811drv_dbg("In setIGMPMctByCPU.\n");
7679
+ if (sizeof(struct GeneralSetting) != len) {
7680
+ ip1811drv_err("length error!\n");
7681
+ return -EINVAL;
7682
+ }
7683
+
7684
+ igmp = (struct GeneralSetting *)cdata;
7685
+ func_en = igmp ->gdata;
7686
+ ret = switchdSetIGMPMctByCPU(func_en);
7687
+ FUNC_MSG_OUT;
7688
+
7689
+ return ret;
7690
+}
7691
+
7692
+int switchdGetIGMPMctByCPU(int *gdata_p)
7693
+{
7694
+ *gdata_p = (int)_ReadRegBits(1, P1REG_IGMPSNOP, 1, 1)?OP_FUNC_ENABLE:OP_FUNC_DISABLE;
7695
+ ip1811drv_dbg("IGMPMctByCPU %s",(*gdata_p==OP_FUNC_ENABLE)?"ENABLE":"DISABLE");
7696
+ return 0;
7697
+}
7698
+EXPORT_SYMBOL(switchdGetIGMPMctByCPU);
7699
+
7700
+int getIGMPMctByCPU(void *cdata, int len)
7701
+{
7702
+ int ret;
7703
+ struct GeneralSetting *igmp;
7704
+
7705
+ FUNC_MSG_IN;
7706
+ ip1811drv_dbg("In getIGMPMctByCPU.\n");
7707
+ if (sizeof(struct GeneralSetting) != len) {
7708
+ ip1811drv_err("length error!\n");
7709
+ return -EINVAL;
7710
+ }
7711
+
7712
+ igmp = (struct GeneralSetting *)cdata;
7713
+ ret = switchdGetIGMPMctByCPU(&(igmp ->gdata));
7714
+ FUNC_MSG_OUT;
7715
+
7716
+ return ret;
7717
+}
7718
+
7719
+int switchdSetIGMPRltByCPU(int enable)
7720
+{
7721
+ switch(enable) {
7722
+ case OP_FUNC_ENABLE:
7723
+ ip1811drv_dbg("Enable router list by CPU\n");
7724
+ break;
7725
+ case OP_FUNC_DISABLE:
7726
+ ip1811drv_dbg("Disable router list by CPU\n");
7727
+ break;
7728
+ default:
7729
+ ip1811drv_dbg("Option can't find\n");
7730
+ return -EINVAL;
7731
+ }
7732
+
7733
+ ip1811drv_dbg("Set router list by CPU: %x\n", enable);
7734
+ _WriteRegBits(1, P1REG_IGMPSNOP, 5, 1, enable);
7735
+ return 0;
7736
+}
7737
+EXPORT_SYMBOL(switchdSetIGMPRltByCPU);
7738
+
7739
+int setIGMPRltByCPU(void *cdata, int len)
7740
+{
7741
+ int ret, func_en;
7742
+ struct GeneralSetting *igmp;
7743
+
7744
+ FUNC_MSG_IN;
7745
+ ip1811drv_dbg("In setIGMPRltByCPU.\n");
7746
+ if (sizeof(struct GeneralSetting) != len) {
7747
+ ip1811drv_err("length error!\n");
7748
+ return -EINVAL;
7749
+ }
7750
+
7751
+ igmp = (struct GeneralSetting *)cdata;
7752
+ func_en = igmp ->gdata;
7753
+ ret = switchdSetIGMPRltByCPU(func_en);
7754
+ FUNC_MSG_OUT;
7755
+
7756
+ return 0;
7757
+}
7758
+
7759
+int switchdGetIGMPRltByCPU(int *gdata_p)
7760
+{
7761
+ *gdata_p = (int)_ReadRegBits(1, P1REG_IGMPSNOP, 5, 1)?OP_FUNC_ENABLE:OP_FUNC_DISABLE;
7762
+ ip1811drv_dbg("IGMPRltByCPU %s",(*gdata_p==OP_FUNC_ENABLE)?"ENABLE":"DISABLE");
7763
+ return 0;
7764
+}
7765
+EXPORT_SYMBOL(switchdGetIGMPRltByCPU);
7766
+
7767
+int getIGMPRltByCPU(void *cdata, int len)
7768
+{
7769
+ int ret;
7770
+ struct GeneralSetting *igmp;
7771
+
7772
+ FUNC_MSG_IN;
7773
+ ip1811drv_dbg("In getIGMPRltByCPU.\n");
7774
+ if (sizeof(struct GeneralSetting) != len) {
7775
+ ip1811drv_err("length error!\n");
7776
+ return -EINVAL;
7777
+ }
7778
+
7779
+ igmp = (struct GeneralSetting *)cdata;
7780
+ ret = switchdGetIGMPRltByCPU(&(igmp ->gdata));
7781
+ FUNC_MSG_OUT;
7782
+
7783
+ return 0;
7784
+}
7785
+
7786
+int switchdSetIGMPPktForward(unsigned int type, unsigned int rule)
7787
+{
7788
+ u16 regdata;
7789
+ u16 rule_t;
7790
+
7791
+ IP2Page(1);
7792
+ switch(type){
7793
+ case OP_IGMP_PACKET_QUERY:
7794
+ case OP_IGMP_PACKET_LEAVE:
7795
+ case OP_IGMP_PACKET_UN_REG_DATA:
7796
+ case OP_IGMP_PACKET_UN_DEFINED:
7797
+ if(rule >= OP_IGMP_RULE_GROUP_MEM){
7798
+ ip1811drv_dbg("Select Type can't support Rule 'OP_IGMP_RULE_GROUP_MEM'.\n");
7799
+ return -EINVAL;
7800
+ }
7801
+ regdata = Read_Reg(P1REG_IGMPPKTFWD_0);
7802
+ ip1811drv_dbg("Read IGMPPktForward_0 : %x\n", regdata);
7803
+ rule_t = 0x000F<<type;
7804
+ regdata &= ~rule_t;
7805
+ regdata |= rule<<type;
7806
+ ip1811drv_dbg("type : %d\n", type);
7807
+ ip1811drv_dbg("rule : %x\n", rule);
7808
+ ip1811drv_dbg("Write IGMPPktForward_0 : %x\n",regdata);
7809
+ Write_Reg(P1REG_IGMPPKTFWD_0, regdata);
7810
+ break;
7811
+ case OP_IGMP_PACKET_REPORT:
7812
+ case OP_IGMP_PACKET_GROUP_SPECIFIC_QUERY:
7813
+ case OP_IGMP_PACKET_REG_DATA:
7814
+ regdata = Read_Reg(P1REG_IGMPPKTFWD_1);
7815
+ ip1811drv_dbg("Read IGMPPktForward_1 : %x\n", regdata);
7816
+ rule_t = 0x001F<<(type-1);
7817
+ regdata &= ~rule_t;
7818
+ regdata |=rule<<(type-1);
7819
+ ip1811drv_dbg("type : %d\n", type);
7820
+ ip1811drv_dbg("rule : %x\n", rule);
7821
+ ip1811drv_dbg("Write IGMPPktForward_1 : %x\n", regdata);
7822
+ Write_Reg(P1REG_IGMPPKTFWD_1, regdata);
7823
+ break;
7824
+ default:
7825
+ ip1811drv_dbg("Option can't find.\n");
7826
+ return -EINVAL;
7827
+ break;
7828
+ }
7829
+ return 0;
7830
+}
7831
+EXPORT_SYMBOL(switchdSetIGMPPktForward);
7832
+
7833
+int setIGMPPktForward(void *cdata, int len)
7834
+{
7835
+ int ret;
7836
+ struct IgmpPacketRule *igmp;
7837
+ unsigned int pkt_type;
7838
+ unsigned int pkt_rule;
7839
+
7840
+ FUNC_MSG_IN;
7841
+ ip1811drv_dbg("In setIGMPPktForward.\n");
7842
+ if (sizeof(struct IgmpPacketRule) != len) {
7843
+ ip1811drv_err("length error!\n");
7844
+ return -EINVAL;
7845
+ }
7846
+ igmp = (struct IgmpPacketRule *)cdata;
7847
+ pkt_type = igmp ->packet_type;
7848
+ pkt_rule = igmp ->rule;
7849
+ ret = switchdSetIGMPPktForward(pkt_type, pkt_rule);
7850
+ FUNC_MSG_OUT;
7851
+
7852
+ return ret;
7853
+}
7854
+
7855
+int switchdGetIGMPPktForward(unsigned int type, int *rule_p)
7856
+{
7857
+ u16 regdata;
7858
+ u16 rule_t;
7859
+
7860
+ IP2Page(1);
7861
+ switch(type){
7862
+ case OP_IGMP_PACKET_QUERY:
7863
+ case OP_IGMP_PACKET_LEAVE:
7864
+ case OP_IGMP_PACKET_UN_REG_DATA:
7865
+ case OP_IGMP_PACKET_UN_DEFINED:
7866
+ regdata = Read_Reg(P1REG_IGMPPKTFWD_0);
7867
+ ip1811drv_dbg("Read IGMPPktForward_0 : %x\n", regdata);
7868
+ rule_t = 0x000F<<type;
7869
+ regdata &= rule_t;
7870
+ *rule_p = regdata>>(type);
7871
+ ip1811drv_dbg("type : %d\n", type);
7872
+ ip1811drv_dbg("Get rule : %x\n", *rule_p);
7873
+ break;
7874
+ case OP_IGMP_PACKET_REPORT:
7875
+ case OP_IGMP_PACKET_GROUP_SPECIFIC_QUERY:
7876
+ case OP_IGMP_PACKET_REG_DATA:
7877
+ regdata = Read_Reg(P1REG_IGMPPKTFWD_1);
7878
+ ip1811drv_dbg("Read IGMPPktForward_1 : %x\n", regdata);
7879
+ rule_t = 0x001F<<(type-1);
7880
+ regdata &= rule_t;
7881
+ *rule_p = regdata>>(type-1);
7882
+ ip1811drv_dbg("type : %d\n", type);
7883
+ ip1811drv_dbg("Get rule : %x\n", *rule_p);
7884
+ break;
7885
+ default:
7886
+ ip1811drv_dbg("Option can't find.\n");
7887
+ return -EINVAL;
7888
+ break;
7889
+ }
7890
+ return 0;
7891
+}
7892
+EXPORT_SYMBOL(switchdGetIGMPPktForward);
7893
+
7894
+int getIGMPPktForward(void *cdata, int len)
7895
+{
7896
+ unsigned int pkt_type;
7897
+ struct IgmpPacketRule *igmp;
7898
+ int ret;
7899
+
7900
+ FUNC_MSG_IN;
7901
+ ip1811drv_dbg("In getIGMPPktForward.\n");
7902
+ if (sizeof(struct IgmpPacketRule) != len) {
7903
+ ip1811drv_err("length error!\n");
7904
+ return -EINVAL;
7905
+ }
7906
+ igmp = (struct IgmpPacketRule *)cdata;
7907
+ pkt_type = igmp ->packet_type;
7908
+ ret = switchdGetIGMPPktForward(pkt_type, &(igmp ->rule));
7909
+ FUNC_MSG_OUT;
7910
+
7911
+ return ret;
7912
+}
7913
+
7914
+int switchdSetIGMPRlt(unsigned int map, unsigned int tstate)
7915
+{
7916
+ u16 regdata;
7917
+ u16 i, mask;
7918
+
7919
+ IP2Page(1);
7920
+ regdata = Read_Reg(P1REG_ROUTLIST);
7921
+ ip1811drv_dbg("Read [12-01] : %x\n", regdata);
7922
+ mask = 0x01;
7923
+ for(i=0; i<12;i++){
7924
+ if((map&mask)!=0) {
7925
+ if((tstate&mask)!=0)
7926
+ regdata |= mask;
7927
+ else
7928
+ regdata &= ~mask;
7929
+ }
7930
+ mask <<= 1;
7931
+ }
7932
+ ip1811drv_dbg("Write new [12-01] : %x\n", regdata);
7933
+ Write_Reg(P1REG_ROUTLIST, regdata);
7934
+ return 0;
7935
+}
7936
+EXPORT_SYMBOL(switchdSetIGMPRlt);
7937
+
7938
+int setIGMPRlt(void *cdata, int len)
7939
+{
7940
+ u16 map, value;
7941
+ struct IgmpRouterListSetting *igmp;
7942
+ int ret;
7943
+
7944
+ FUNC_MSG_IN;
7945
+ ip1811drv_dbg("In setIGMPRlt.\n");
7946
+ if (sizeof(struct IgmpRouterListSetting) != len) {
7947
+ ip1811drv_err("length error!\n");
7948
+ return -EINVAL;
7949
+ }
7950
+
7951
+ igmp = (struct IgmpRouterListSetting *)cdata;
7952
+ map = 0xFFF&(igmp ->portmask);
7953
+ value = 0xFFF&(igmp ->tstate);
7954
+
7955
+ ip1811drv_dbg("map [12-01] : %x\n", map);
7956
+ ip1811drv_dbg("val [12-01] : %x\n", value);
7957
+
7958
+ ret = switchdSetIGMPRlt(map, value);
7959
+ FUNC_MSG_OUT;
7960
+
7961
+ return ret;
7962
+}
7963
+
7964
+int switchdGetIGMPRlt(unsigned int map, int *value_p)
7965
+{
7966
+ u16 regdata, value, i, mask;
7967
+
7968
+ IP2Page(1);
7969
+ regdata = Read_Reg(P1REG_ROUTLIST);
7970
+ ip1811drv_dbg("Read [12-01] : %x\n", regdata&0xFFF);
7971
+ mask = 0x01;
7972
+ for(i=0; i<12; i++) {
7973
+ if((map&mask)!=0){
7974
+ if((regdata&mask)!=0)
7975
+ value |= mask;
7976
+ else
7977
+ value &= ~mask;
7978
+ }
7979
+ mask <<= 1;
7980
+ }
7981
+
7982
+ *value_p = value;
7983
+ ip1811drv_dbg("Return value : %lx\n", *value_p);
7984
+
7985
+ return 0;
7986
+}
7987
+EXPORT_SYMBOL(switchdGetIGMPRlt);
7988
+
7989
+int getIGMPRlt(void *cdata, int len)
7990
+{
7991
+ u16 map, value, i, mask;
7992
+ struct IgmpRouterListSetting *igmp;
7993
+ int ret;
7994
+
7995
+ FUNC_MSG_IN;
7996
+ ip1811drv_dbg("In getIGMPRlt.\n");
7997
+ if (sizeof(struct IgmpRouterListSetting) != len) {
7998
+ ip1811drv_err("length error!\n");
7999
+ return -EINVAL;
8000
+ }
8001
+ igmp = (struct IgmpRouterListSetting *)cdata;
8002
+
8003
+ map = 0xFFF&(igmp ->portmask);
8004
+ ip1811drv_dbg("map [12-01] : %x\n", map);
8005
+
8006
+ ret = switchdGetIGMPRlt(map, &(igmp ->tstate));
8007
+ FUNC_MSG_OUT;
8008
+
8009
+ return ret;
8010
+}
8011
+
8012
+int switchdSetIGMPHashMethod(int hash_method)
8013
+{
8014
+ if (!(hash_method==OP_HASH_DIRECT || hash_method==OP_HASH_CRC))
8015
+ return -EINVAL;
8016
+
8017
+ ip1811drv_dbg("Set Hash Method: %s\n", (hash_method==OP_HASH_DIRECT)?"DIRECT":"CRC");
8018
+ _WriteRegBits(1, P1REG_IGMPSNOP, 6, 1,(hash_method==OP_HASH_DIRECT)?1:0);
8019
+
8020
+ return 0;
8021
+}
8022
+EXPORT_SYMBOL(switchdSetIGMPHashMethod);
8023
+
8024
+int setIGMPHashMethod(void *cdata, int len)
8025
+{
8026
+ int hash, ret;
8027
+
8028
+ FUNC_MSG_IN;
8029
+ if (sizeof(struct GeneralSetting) != len)
8030
+ return -EINVAL;
8031
+
8032
+ hash = ((struct GeneralSetting *)cdata) ->gdata;
8033
+ ret = switchdSetIGMPHashMethod(hash);
8034
+ FUNC_MSG_OUT;
8035
+
8036
+ return ret;
8037
+}
8038
+
8039
+int switchdGetIGMPHashMethod(int *gdata_p)
8040
+{
8041
+ *gdata_p = (int)_ReadRegBits(1, P1REG_IGMPSNOP, 6, 1)?OP_HASH_DIRECT:OP_HASH_CRC;
8042
+ ip1811drv_dbg("HASH METHOD %s",(*gdata_p==OP_HASH_DIRECT)?"DIRECT":"CRC");
8043
+ return 0;
8044
+}
8045
+EXPORT_SYMBOL(switchdGetIGMPHashMethod);
8046
+
8047
+int getIGMPHashMethod(void *cdata, int len)
8048
+{
8049
+ int ret;
8050
+ struct GeneralSetting *igmp;
8051
+
8052
+ FUNC_MSG_IN;
8053
+ ip1811drv_dbg("In getIGMPHashMethod.\n");
8054
+ if (sizeof(struct GeneralSetting) != len)
8055
+ return -EINVAL;
8056
+
8057
+ igmp = (struct GeneralSetting *)cdata;
8058
+ ret = switchdGetIGMPHashMethod(&(igmp ->gdata));
8059
+ FUNC_MSG_OUT;
8060
+
8061
+ return ret;
8062
+}
8063
+
8064
+int switchdSetIGMPMldRule(int forwarding)
8065
+{
8066
+
8067
+ ip1811drv_dbg("set ICMPv6 MLD forwarding: %x\n", forwarding);
8068
+ _WriteRegBits(0, P0REG_IPV6RLTFWD, 8, 2, forwarding);
8069
+
8070
+ return 0;
8071
+}
8072
+EXPORT_SYMBOL(switchdSetIGMPMldRule);
8073
+
8074
+int setIGMPMldRule(void *cdata, int len)
8075
+{
8076
+ struct GeneralSetting *igmp;
8077
+ int ret, forward;
8078
+
8079
+ FUNC_MSG_IN;
8080
+ ip1811drv_dbg("In setIGMPMldRule.\n");
8081
+ if (sizeof(struct GeneralSetting) != len) {
8082
+ ip1811drv_err("length error!\n");
8083
+ return -EINVAL;
8084
+ }
8085
+
8086
+ igmp = (struct GeneralSetting *)cdata;
8087
+ forward = igmp ->gdata;
8088
+ ret = switchdSetIGMPMldRule(forward);
8089
+ FUNC_MSG_OUT;
8090
+
8091
+ return ret;
8092
+}
8093
+
8094
+int switchdGetIGMPMldRule(int *gdata_p)
8095
+{
8096
+ *gdata_p = (int)_ReadRegBits(0, P0REG_IPV6RLTFWD, 8, 2);
8097
+ ip1811drv_dbg("get ICMPv6 MLD forwarding: %x\n", *gdata_p);
8098
+ return 0;
8099
+}
8100
+EXPORT_SYMBOL(switchdGetIGMPMldRule);
8101
+
8102
+int getIGMPMldRule(void *cdata, int len)
8103
+{
8104
+ struct GeneralSetting *igmp;
8105
+ int ret;
8106
+
8107
+ FUNC_MSG_IN;
8108
+ ip1811drv_dbg("In getIGMPMldRule.\n");
8109
+ if (sizeof(struct GeneralSetting) != len) {
8110
+ ip1811drv_err("length error!\n");
8111
+ return -EINVAL;
8112
+ }
8113
+
8114
+ igmp = (struct GeneralSetting *)cdata;
8115
+ ret = switchdGetIGMPMldRule(&(igmp ->gdata));
8116
+ FUNC_MSG_OUT;
8117
+
8118
+ return ret;
8119
+}
8120
+
8121
+void makeTable(u16 *tmpbuf, u16 offset, u32 value, u8 len)
8122
+{
8123
+ u16 ptr, set, tmpvalue;
8124
+
8125
+ ptr = offset/16;
8126
+ set = offset%16;
8127
+ ip1811drv_dbg("\n\nMakeTable:\noffset : %d\nvalue : %x\nlen : %d\n", offset, value, len);
8128
+ ip1811drv_dbg("\nbuf[%d]=%x buf[%d]=%x\n", ptr, tmpbuf[ptr], ptr+1, tmpbuf[ptr+1]);
8129
+ tmpvalue = (0xFFFF&value)<<set;
8130
+ tmpbuf[ptr] |= tmpvalue;
8131
+ ip1811drv_dbg("Result:\nbuf[%d] | %x = %x\n", ptr, tmpvalue, tmpbuf[ptr]);
8132
+ if(len>(16-set)) {
8133
+ len -= (16-set);
8134
+ tmpvalue = 0xFFFF&(value>>(16-set));
8135
+ tmpbuf[ptr+1] |= tmpvalue;
8136
+ ip1811drv_dbg("buf[%d] | %x = %x\n", ptr+1, tmpvalue, tmpbuf[ptr+1]);
8137
+ if(len>16){
8138
+ tmpvalue = 0xFFFF&(value>>(32-set));
8139
+ tmpbuf[ptr+2] |= tmpvalue;
8140
+ ip1811drv_dbg("buf[%d] | %x = %x\n", ptr+2, tmpvalue, tmpbuf[ptr+2]);
8141
+ }
8142
+ }
8143
+}
8144
+
8145
+u32 getTable(u16 *tmpbuf, u16 offset, u8 len)
8146
+{
8147
+ u32 value;
8148
+ u16 ptr, set, tmpvalue, i, mask;
8149
+ u16 debug;
8150
+ ip1811drv_dbg("getTable:\n");
8151
+ ip1811drv_dbg("offset = %d, len = %d", offset, len);
8152
+ debug = offset/16;
8153
+ ip1811drv_dbg("tmpbuf[%d] offset value:\n", debug);
8154
+ for(i=0; i<3; i++)
8155
+ ip1811drv_dbg("%04x ", tmpbuf[debug+i]);
8156
+ ptr = (offset+len)/16;
8157
+ set = (offset+len)%16;
8158
+
8159
+ if(len>=set){
8160
+ mask = 0;
8161
+ for(i=0; i<set; i++){
8162
+ mask <<= 1;
8163
+ mask |= 0x01;
8164
+ }
8165
+ tmpvalue = tmpbuf[ptr]&mask;
8166
+ value = tmpvalue;
8167
+ if((len-set)>=16) {
8168
+ value <<= 16;
8169
+ value |= tmpbuf[ptr-1];
8170
+ if((len-set-16)>0){
8171
+ value <<= (len-set-16);
8172
+ value |= tmpbuf[ptr-2]>>(16-(len-set-16));
8173
+ }
8174
+ } else {
8175
+ if(len!=set) {
8176
+ value <<= (len-set);
8177
+ value |= tmpbuf[ptr-1]>>(16-(len-set));
8178
+ }
8179
+ }
8180
+ } else {
8181
+ mask = 0;
8182
+ for(i=0; i<set; i++){
8183
+ mask <<= 1;
8184
+ mask |= 0x01;
8185
+ }
8186
+ tmpvalue = tmpbuf[ptr]&mask;
8187
+ value = tmpvalue>>(set-len);
8188
+ }
8189
+ ip1811drv_dbg("return %x\n",value);
8190
+ return value;
8191
+}
8192
+
8193
+/* ipv: 4: IPv4
8194
+ * 6: IPv6
8195
+ * addr: IP address
8196
+ * method: 1: Direct
8197
+ * 0: CRC
8198
+ * */
8199
+u8 tb_calc_index(u8 ipv, void *addr, u8 method)
8200
+{
8201
+ u8 index = 0;
8202
+ u8 *u8_addr = (u8*)addr;
8203
+
8204
+ // Direct
8205
+ if(method) {
8206
+ if(ipv == 4) {
8207
+ index = u8_addr[3];
8208
+ } else if(ipv == 6) {
8209
+ index = u8_addr[15];
8210
+ }
8211
+ } else { // CRC
8212
+ int i;
8213
+ bool crc[8], d[32];
8214
+ bool c[8] = {1,1,1,1,1,1,1,1};
8215
+
8216
+ // init data
8217
+ if(ipv == 4) {
8218
+ for(i=0; i<32; i++)
8219
+ d[i] = (bool)((u8_addr[i/8] >> (7-(i%8))) & 0x1);
8220
+ } else if(ipv == 6) {
8221
+ for(i=0; i<32; i++)
8222
+ d[i] = (bool)((u8_addr[12+(i/8)] >> (7-(i%8))) & 0x1);
8223
+ }
8224
+
8225
+ // calculate crc
8226
+ crc[0] = d[31] ^ d[30] ^ d[28] ^ d[23] ^ d[21] ^ d[19] ^ d[18] ^ d[16] ^ d[14] ^ d[12] ^ d[8] ^ d[7] ^ d[6] ^ d[0] ^ c[4] ^ c[6] ^ c[7];
8227
+
8228
+ crc[1] = d[30] ^ d[29] ^ d[28] ^ d[24] ^ d[23] ^ d[22] ^ d[21] ^ d[20] ^ d[18] ^ d[17] ^ d[16] ^ d[15] ^ d[14] ^ d[13] ^ d[12] ^ d[9] ^ d[6] ^ d[1] ^ d[0] ^ c[0] ^ c[4] ^ c[5] ^ c[6];
8229
+
8230
+ crc[2] = d[29] ^ d[28] ^ d[25] ^ d[24] ^ d[22] ^ d[17] ^ d[15] ^ d[13] ^ d[12] ^ d[10] ^ d[8] ^ d[6]^ d[2] ^ d[1] ^ d[0] ^ c[0] ^ c[1] ^ c[4] ^ c[5];
8231
+
8232
+ crc[3] = d[30] ^ d[29] ^ d[26] ^ d[25] ^ d[23] ^ d[18] ^ d[16] ^ d[14] ^ d[13] ^ d[11] ^ d[9] ^ d[7] ^ d[3] ^ d[2] ^ d[1] ^ c[1] ^ c[2] ^ c[5] ^ c[6];
8233
+
8234
+ crc[4] = d[31] ^ d[30] ^ d[27] ^ d[26] ^ d[24] ^ d[19] ^ d[17] ^ d[15] ^ d[14] ^ d[12] ^ d[10] ^ d[8] ^ d[4] ^ d[3] ^ d[2] ^ c[0] ^ c[2] ^ c[3] ^ c[6] ^ c[7];
8235
+
8236
+ crc[5] = d[31] ^ d[28] ^ d[27] ^ d[25] ^ d[20] ^ d[18] ^ d[16] ^ d[15] ^ d[13] ^ d[11] ^ d[9] ^ d[5] ^ d[4] ^ d[3] ^ c[1] ^ c[3] ^ c[4] ^ c[7];
8237
+
8238
+ crc[6] = d[29] ^ d[28] ^ d[26] ^ d[21] ^ d[19] ^ d[17] ^ d[16] ^ d[14] ^ d[12] ^ d[10] ^ d[6] ^ d[5] ^ d[4] ^ c[2] ^ c[4] ^ c[5];
8239
+
8240
+ crc[7] = d[30] ^ d[29] ^ d[27] ^ d[22] ^ d[20] ^ d[18] ^ d[17] ^ d[15] ^ d[13] ^ d[11] ^ d[7] ^ d[6] ^ d[5] ^ c[3] ^ c[5] ^ c[6];
8241
+
8242
+ // get index
8243
+ for(i=0; i<8; i++)
8244
+ index |= ((u8)crc[i])<<i;
8245
+ }
8246
+
8247
+ ip1811drv_dbg("tb_calc_index() index = %02u\n", index);
8248
+ return index;
8249
+}
8250
+
8251
+int switchdSetIGMPMctTable(int index, struct mt_rule *mt_data)
8252
+{
8253
+ u16 regdata[6] = {0};
8254
+ u16 i, tmpvalue;
8255
+
8256
+ memset(regdata, 0, 11);
8257
+ ip1811drv_dbg("driver:index: %x\n", index);
8258
+ ip1811drv_dbg("driver:group: %x : %x : %x : %x\n", mt_data->group[0], mt_data->group[1], mt_data->group[2], mt_data->group[3]);
8259
+ ip1811drv_dbg("driver:Set FID: %x\n", mt_data->fid);
8260
+ ip1811drv_dbg("driver:Set age port:: %lx\n", mt_data->port_mem);
8261
+ ip1811drv_dbg("driver:Set SIP: %x\n", mt_data->slt_index);
8262
+ ip1811drv_dbg("driver:Set flag: %x\n", mt_data->flag);
8263
+
8264
+ //set Group
8265
+ regdata[0] = (mt_data->group[2] << 8) | mt_data->group[3];
8266
+ regdata[1] = (mt_data->group[0] << 8) | mt_data->group[1];
8267
+ //set FID
8268
+ makeTable(regdata, 32, mt_data->fid, 4);
8269
+ //set Aging Member
8270
+ for(i=0; i<12; i++) {
8271
+ if(mt_data->port_mem & BIT(i)) {
8272
+ makeTable(regdata, 36+i, 0x1, 1);
8273
+ makeTable(regdata, 36+i+12, 0x1, 1);
8274
+ makeTable(regdata, 36+i+24, 0x1, 1);
8275
+ }
8276
+ }
8277
+ //set Pri
8278
+ makeTable(regdata, 72, mt_data->pri, 4);
8279
+ //set SIP
8280
+ makeTable(regdata, 76, mt_data->slt_index, 5);
8281
+ //set ver and CPU
8282
+ makeTable(regdata, 81, mt_data->flag, 2);
8283
+
8284
+ IP2Page(1);
8285
+ ip1811drv_dbg("driver:Write Mct Table Data:\n");
8286
+ for(i=0; i<6; i++) {
8287
+ ip1811drv_dbg("%04x ", regdata[i]);
8288
+ Write_Reg(P1REG_MEM_MCT_TABLE_0+i, regdata[i]);
8289
+ }
8290
+ ip1811drv_dbg("\n");
8291
+
8292
+ tmpvalue = index;
8293
+ tmpvalue |= 0xC000;
8294
+ ip1811drv_dbg("\ndirver:Start Write [%04x]", tmpvalue);
8295
+ Write_Reg(P1REG_MEM_MCT_COMMAND, tmpvalue);
8296
+
8297
+ tmpvalue = Read_Reg(P1REG_MEM_MCT_COMMAND);
8298
+ while((tmpvalue&0x8000)!=0)
8299
+ tmpvalue = Read_Reg(P1REG_MEM_MCT_COMMAND);
8300
+
8301
+ return 0;
8302
+}
8303
+EXPORT_SYMBOL(switchdSetIGMPMctTable);
8304
+
8305
+int setIGMPMctTable(void *cdata, int len){
8306
+
8307
+ int ret, index;
8308
+ struct MtRuleSetting *igmp;
8309
+ struct mt_rule *mt;
8310
+
8311
+ FUNC_MSG_IN;
8312
+ ip1811drv_dbg("In setIGMPMctTable.\n");
8313
+ if (sizeof(struct MtRuleSetting) != len) {
8314
+ ip1811drv_err("length error!\n");
8315
+ return -EINVAL;
8316
+ }
8317
+
8318
+ igmp = (struct MtRuleSetting *)cdata;
8319
+ index = igmp ->index;
8320
+ mt = &(igmp ->mt_data);
8321
+ ret = switchdSetIGMPMctTable(index, mt);
8322
+ FUNC_MSG_OUT;
8323
+
8324
+ return 0;
8325
+}
8326
+
8327
+int switchdGetIGMPMctTable(int index, struct mt_rule *mt_data)
8328
+{
8329
+ u16 regdata[6] = {0};
8330
+ u16 i, j, tmpvalue;
8331
+ u32 mask;
8332
+
8333
+ tmpvalue = index;
8334
+ tmpvalue |= 0x8000;
8335
+ IP2Page(1);
8336
+ Write_Reg(P1REG_MEM_MCT_COMMAND, tmpvalue);
8337
+ ip1811drv_dbg("driver:start read: %x\n", tmpvalue);
8338
+
8339
+ tmpvalue = Read_Reg(P1REG_MEM_MCT_COMMAND);
8340
+ while((tmpvalue&0x8000)!=0)
8341
+ tmpvalue = Read_Reg(P1REG_MEM_MCT_COMMAND);
8342
+
8343
+ ip1811drv_dbg("driver:index: %x\n", index);
8344
+ ip1811drv_dbg("driver:Read Table Data:\n");
8345
+ for(i=0; i<6; i++) {
8346
+ regdata[i] = Read_Reg(P1REG_MEM_MCT_TABLE_0+i);
8347
+ ip1811drv_dbg("%04x ", regdata[i]);
8348
+ }
8349
+ ip1811drv_dbg("\nRead Group:\n");
8350
+ for(i=0; i<4; i++) {
8351
+ mt_data->group[i] = getTable(regdata, (0+(8*i)), 8);
8352
+ ip1811drv_dbg("%x ", mt_data->group[i]);
8353
+ }
8354
+
8355
+ ip1811drv_dbg("\nRead FID:\n");
8356
+ mt_data->fid = getTable(regdata, 32, 4);
8357
+ ip1811drv_dbg("%x\n",mt_data->fid);
8358
+
8359
+ ip1811drv_dbg("Read Aging:\n");
8360
+ mask = 0;
8361
+ for(i=0; i<12; i++){
8362
+ int val = 0;
8363
+ for(j=0; j<3; j++) {
8364
+ if(getTable(regdata, (36+i+(12*j)), 1)!=0 )
8365
+ val++;
8366
+ }
8367
+ if(val)
8368
+ mask |= 0x01<<i;
8369
+ }
8370
+ ip1811drv_dbg("%x\n", mask);
8371
+ mt_data->port_mem = mask;
8372
+
8373
+ ip1811drv_dbg("Read Priority:\n");
8374
+ mt_data->pri = getTable(regdata, 72, 4);
8375
+ ip1811drv_dbg("%x\n",mt_data->pri);
8376
+
8377
+ ip1811drv_dbg("Read SLT index:\n");
8378
+ mt_data->slt_index = getTable(regdata, 76, 5);
8379
+ ip1811drv_dbg("%x\n",mt_data->slt_index);
8380
+
8381
+ ip1811drv_dbg("Read flag:\n");
8382
+ mt_data->flag = getTable(regdata, 81, 2);
8383
+ ip1811drv_dbg("%x\n",mt_data->flag);
8384
+
8385
+ printk(KERN_ERR "\nGroup:");
8386
+ for(i=0;i<4;i++)
8387
+ printk(KERN_ERR " %d", mt_data->group[i]);
8388
+ printk(KERN_ERR "\nFID: %x", mt_data->fid);
8389
+ printk(KERN_ERR "\nPort member: %lx", (unsigned long)mt_data->port_mem);
8390
+ printk(KERN_ERR "\nPriority: %d", (mt_data->pri&0x07));
8391
+ printk(KERN_ERR "\nSLT index: %x", mt_data->slt_index);
8392
+ printk(KERN_ERR "\nFlag: %x\n", mt_data->flag);
8393
+ return 0;
8394
+}
8395
+EXPORT_SYMBOL(switchdGetIGMPMctTable);
8396
+
8397
+int getIGMPMctTable(void *cdata, int len){
8398
+ int ret, index;
8399
+ struct MtRuleSetting *igmp;
8400
+ struct mt_rule *mt;
8401
+
8402
+ FUNC_MSG_IN;
8403
+ ip1811drv_dbg("In getIGMPMctTable.\n");
8404
+ if (sizeof(struct MtRuleSetting) != len) {
8405
+ ip1811drv_err("length error!\n");
8406
+ return -EINVAL;
8407
+ }
8408
+
8409
+ igmp = (struct MtRuleSetting *)cdata;
8410
+ index = igmp ->index;
8411
+ mt = &(igmp ->mt_data);
8412
+ ret = switchdGetIGMPMctTable(index, mt);
8413
+ FUNC_MSG_OUT;
8414
+
8415
+ return ret;
8416
+}
8417
+
8418
+int switchdSetIGMPSltTable(int index, struct slt_rule *slt_data)
8419
+{
8420
+ u16 regdata[19] = {0};
8421
+ u16 i, j, tmpvalue;
8422
+
8423
+ if(slt_data->type == OP_IGMP_SLT_IPV4) {
8424
+ //set IP
8425
+ for(i=0; i<6; i++){
8426
+ regdata[i*2] = (slt_data->data.ipv4.ip[i][2] << 8) | slt_data->data.ipv4.ip[i][3];
8427
+ regdata[i*2+1] = (slt_data->data.ipv4.ip[i][0] << 8) | slt_data->data.ipv4.ip[i][1];
8428
+ }
8429
+ //set User Define
8430
+ for(i=0; i<6; i++)
8431
+ makeTable(regdata, (192+(12*i)), slt_data->data.ipv4.used_port[i], 12);
8432
+ }else{
8433
+ //set IP
8434
+ for(i=0; i<2; i++){
8435
+ for(j=0; j<8; j++)
8436
+ makeTable(regdata, ((128*i)+(16*j)), slt_data->data.ipv6.ip[i][7-j], 16);
8437
+ }
8438
+ //set User Define
8439
+ for(i=0; i<2 ;i++)
8440
+ makeTable(regdata, (256+(12*i)), slt_data->data.ipv6.used_port[i], 12);
8441
+ }
8442
+
8443
+ ip1811drv_dbg("SLT Table Data:");
8444
+ IP2Page(1);
8445
+ for(i=0; i<19; i++) {
8446
+ if((i%16)==0)
8447
+ ip1811drv_dbg("\n");
8448
+ ip1811drv_dbg("%04x ", regdata[i]);
8449
+ Write_Reg(P1REG_MEM_SLT_TABLE_0+i, regdata[i]);
8450
+ }
8451
+ tmpvalue = index;
8452
+ tmpvalue |= 0xC000;
8453
+ ip1811drv_dbg("\ndirver:Start Write [%04x]", tmpvalue);
8454
+ Write_Reg(P1REG_MEM_SLT_COMMAND, tmpvalue);
8455
+
8456
+ return 0;
8457
+}
8458
+EXPORT_SYMBOL(switchdSetIGMPSltTable);
8459
+
8460
+int setIGMPSltTable(void *cdata, int len){
8461
+ int ret, index;
8462
+ struct SltRuleSetting *igmp;
8463
+ struct slt_rule *slt;
8464
+
8465
+ FUNC_MSG_IN;
8466
+ ip1811drv_dbg("In setIGMPSltTable.\n");
8467
+ if (sizeof(struct SltRuleSetting) != len) {
8468
+ ip1811drv_err("length error!\n");
8469
+ return -EINVAL;
8470
+ }
8471
+
8472
+ igmp = (struct SltRuleSetting *)cdata;
8473
+ index = igmp ->index;
8474
+ slt = &(igmp ->slt_data);
8475
+ ret = switchdSetIGMPSltTable(index, slt);
8476
+ FUNC_MSG_OUT;
8477
+
8478
+ return ret;
8479
+}
8480
+
8481
+int switchdGetIGMPSltTable(int index, struct slt_rule *slt_data)
8482
+{
8483
+ u16 regdata[19] = {0};
8484
+ u16 i, j, tmpvalue;
8485
+
8486
+ tmpvalue = index;
8487
+ tmpvalue |= 0x8000;
8488
+ IP2Page(1);
8489
+ Write_Reg(P1REG_MEM_SLT_COMMAND, tmpvalue);
8490
+
8491
+ tmpvalue = Read_Reg(P1REG_MEM_SLT_COMMAND);
8492
+ while( (tmpvalue&0x8000)!=0 )
8493
+ tmpvalue = Read_Reg(P1REG_MEM_SLT_COMMAND);
8494
+
8495
+ ip1811drv_dbg("Read SLT Table:");
8496
+ for(i=0; i<19; i++) {
8497
+ regdata[i] = Read_Reg(P1REG_MEM_SLT_TABLE_0+i);
8498
+ if(i%16==0)
8499
+ ip1811drv_dbg("\n");
8500
+ ip1811drv_dbg("%04x ", regdata[i]);
8501
+ }
8502
+
8503
+ if(slt_data->type == OP_IGMP_SLT_IPV4){
8504
+ ip1811drv_dbg("Read IPv4:\n");
8505
+ printk(KERN_ERR "\nRead IPv4:");
8506
+ for(i=0; i<6; i++) {
8507
+ printk(KERN_ERR "\n");
8508
+ for(j=0; j<4; j++) {
8509
+ slt_data->data.ipv4.ip[i][j] = getTable(regdata, ((32*i)+(8*j)), 8 );
8510
+ printk(KERN_ERR " %d", slt_data->data.ipv4.ip[i][j]);
8511
+ }
8512
+ }
8513
+ ip1811drv_dbg("Read Used Define:\n");
8514
+ printk(KERN_ERR "\nUsed Define:\n");
8515
+ for(i=0; i<6; i++) {
8516
+ slt_data->data.ipv4.used_port[i] = getTable(regdata, (192+(12*i)), 12);
8517
+ printk(KERN_ERR " %04lx", (unsigned long)slt_data->data.ipv4.used_port[i]);
8518
+ }
8519
+ }else{
8520
+ ip1811drv_dbg("Read IPv6:\n");
8521
+ printk(KERN_ERR "\nRead IPv6:");
8522
+ for(i=0; i<2; i++) {
8523
+ printk(KERN_ERR "\n");
8524
+ for(j=0; j<8; j++) {
8525
+ slt_data->data.ipv6.ip[i][j] = getTable(regdata, ((128*i)+(16*j)), 16);
8526
+ printk(KERN_ERR " %04x", slt_data->data.ipv6.ip[i][j]);
8527
+ }
8528
+ }
8529
+ ip1811drv_dbg("Read Used Define:\n");
8530
+ printk(KERN_ERR "\nUsed Define:\n");
8531
+ for(i=0; i<2;i++) {
8532
+ slt_data->data.ipv6.used_port[i] = getTable(regdata, (256+(12*i)), 12);
8533
+ printk(KERN_ERR " %04lx", (unsigned long)slt_data->data.ipv6.used_port[i]);
8534
+ }
8535
+ }
8536
+ printk(KERN_ERR "\n");
8537
+ return 0;
8538
+}
8539
+EXPORT_SYMBOL(switchdGetIGMPSltTable);
8540
+
8541
+int getIGMPSltTable(void *cdata, int len){
8542
+ int ret, index;
8543
+ struct SltRuleSetting *igmp;
8544
+ struct slt_rule *slt;
8545
+
8546
+ FUNC_MSG_IN;
8547
+ ip1811drv_dbg("In getIGMPSltTable.\n");
8548
+ if (sizeof(struct SltRuleSetting) != len) {
8549
+ ip1811drv_err("length error!\n");
8550
+ return -EINVAL;
8551
+ }
8552
+
8553
+ igmp = (struct SltRuleSetting *)cdata;
8554
+ index = igmp ->index;
8555
+ slt = &(igmp ->slt_data);
8556
+ ret = switchdGetIGMPSltTable(index, slt);
8557
+ FUNC_MSG_OUT;
8558
+
8559
+ return 0;
8560
+}
8561
+
8562
+//------------------------------------------------
8563
+//ip1811_sniffer
8564
+int switchdSetS1PktModify(int modify)
8565
+{
8566
+ if (modify!=OP_SNIFFER1_PKT_MODIFY && modify!=OP_SNIFFER1_PKT_KEEP)
8567
+ return -EINVAL;
8568
+ ip1811drv_dbg("modify=%d\n", modify);
8569
+
8570
+ _WriteRegBits(1, P1REG_SNIFCFG, 2, 1, modify);
8571
+
8572
+ return 0;
8573
+}
8574
+EXPORT_SYMBOL(switchdSetS1PktModify);
8575
+int setS1PktModify(void *cdata, int len)
8576
+{
8577
+ int modify;
8578
+
8579
+ ip1811drv_dbg("ip1811: +setS1PktModify...\n");
8580
+ if (sizeof(struct GeneralSetting) != len)
8581
+ return -EINVAL;
8582
+
8583
+ modify = ((struct GeneralSetting *)cdata) ->gdata;
8584
+
8585
+ if(switchdSetS1PktModify(modify) != 0)
8586
+ return -EINVAL;
8587
+
8588
+ ip1811drv_dbg("ip1811: -setS1PktModify...\n");
8589
+ return 0;
8590
+}
8591
+
8592
+int switchdGetS1PktModify(int *ptrInt)
8593
+{
8594
+ *ptrInt = (int)_ReadRegBits(1, P1REG_SNIFCFG, 2, 1);
8595
+
8596
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
8597
+
8598
+ return 0;
8599
+}
8600
+EXPORT_SYMBOL(switchdGetS1PktModify);
8601
+int getS1PktModify(void *cdata, int len)
8602
+{
8603
+ int modify;
8604
+
8605
+ ip1811drv_dbg("ip1811: +getS1PktModify...\n");
8606
+ if (sizeof(struct GeneralSetting) != len)
8607
+ return -EINVAL;
8608
+
8609
+ if(switchdGetS1PktModify(&modify) != 0)
8610
+ return -EINVAL;
8611
+
8612
+ ((struct GeneralSetting *)cdata) ->gdata = modify;
8613
+
8614
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
8615
+ ip1811drv_dbg("ip1811: -getS1PktModify...\n");
8616
+ return 0;
8617
+}
8618
+
8619
+int switchdSetS1TM4CpuSTag(int modify)
8620
+{
8621
+ if (modify!=OP_SNIFFER1_TAG_KEEP && modify!=OP_SNIFFER1_TAG_MODIFY)
8622
+ return -EINVAL;
8623
+ ip1811drv_dbg("modify=%d\n", modify);
8624
+
8625
+ _WriteRegBits(1, P1REG_SNIFCFG, 5, 1, modify);
8626
+
8627
+ return 0;
8628
+}
8629
+EXPORT_SYMBOL(switchdSetS1TM4CpuSTag);
8630
+int setS1TM4CpuSTag(void *cdata, int len)
8631
+{
8632
+ int modify;
8633
+
8634
+ ip1811drv_dbg("ip1811: +setS1TM4CpuSTag...\n");
8635
+ if (sizeof(struct GeneralSetting) != len)
8636
+ return -EINVAL;
8637
+
8638
+ modify = ((struct GeneralSetting *)cdata) ->gdata;
8639
+
8640
+ if(switchdSetS1TM4CpuSTag(modify) != 0)
8641
+ return -EINVAL;
8642
+
8643
+ ip1811drv_dbg("ip1811: -setS1TM4CpuSTag...\n");
8644
+ return 0;
8645
+}
8646
+
8647
+int switchdGetS1TM4CpuSTag(int *ptrInt)
8648
+{
8649
+ *ptrInt = (int)_ReadRegBits(1, P1REG_SNIFCFG, 5, 1);
8650
+
8651
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
8652
+
8653
+ return 0;
8654
+}
8655
+EXPORT_SYMBOL(switchdGetS1TM4CpuSTag);
8656
+int getS1TM4CpuSTag(void *cdata, int len)
8657
+{
8658
+ int modify;
8659
+
8660
+ ip1811drv_dbg("ip1811: +getS1TM4CpuSTag...\n");
8661
+ if (sizeof(struct GeneralSetting) != len)
8662
+ return -EINVAL;
8663
+
8664
+ if(switchdGetS1TM4CpuSTag(&modify) != 0)
8665
+ return -EINVAL;
8666
+
8667
+ ((struct GeneralSetting *)cdata) ->gdata = modify;
8668
+
8669
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
8670
+ ip1811drv_dbg("ip1811: -getS1TM4CpuSTag...\n");
8671
+ return 0;
8672
+}
8673
+
8674
+int switchdSetS1TM4Acl2Cpu(int modify)
8675
+{
8676
+ if (modify!=OP_SNIFFER1_TAG_KEEP && modify!=OP_SNIFFER1_TAG_MODIFY)
8677
+ return -EINVAL;
8678
+ ip1811drv_dbg("modify=%d\n", modify);
8679
+
8680
+ _WriteRegBits(1, P1REG_SNIFCFG, 6, 1, modify);
8681
+
8682
+ return 0;
8683
+}
8684
+EXPORT_SYMBOL(switchdSetS1TM4Acl2Cpu);
8685
+int setS1TM4Acl2Cpu(void *cdata, int len)
8686
+{
8687
+ int modify;
8688
+
8689
+ ip1811drv_dbg("ip1811: +setS1TM4Acl2Cpu...\n");
8690
+ if (sizeof(struct GeneralSetting) != len)
8691
+ return -EINVAL;
8692
+
8693
+ modify = ((struct GeneralSetting *)cdata) ->gdata;
8694
+
8695
+ if(switchdSetS1TM4Acl2Cpu(modify) != 0)
8696
+ return -EINVAL;
8697
+
8698
+ ip1811drv_dbg("ip1811: -setS1TM4Acl2Cpu...\n");
8699
+ return 0;
8700
+}
8701
+
8702
+int switchdGetS1TM4Acl2Cpu(int *ptrInt)
8703
+{
8704
+ *ptrInt = (int)_ReadRegBits(1, P1REG_SNIFCFG, 6, 1);
8705
+
8706
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
8707
+
8708
+ return 0;
8709
+}
8710
+EXPORT_SYMBOL(switchdGetS1TM4Acl2Cpu);
8711
+int getS1TM4Acl2Cpu(void *cdata, int len)
8712
+{
8713
+ int modify;
8714
+
8715
+ ip1811drv_dbg("ip1811: +getS1TM4Acl2Cpu...\n");
8716
+ if (sizeof(struct GeneralSetting) != len)
8717
+ return -EINVAL;
8718
+
8719
+ if(switchdGetS1TM4Acl2Cpu(&modify) != 0)
8720
+ return -EINVAL;
8721
+
8722
+ ((struct GeneralSetting *)cdata) ->gdata = modify;
8723
+
8724
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
8725
+ ip1811drv_dbg("ip1811: -getS1TM4Acl2Cpu...\n");
8726
+ return 0;
8727
+}
8728
+
8729
+int switchdSetS1TM4Pkt2MPort(int modify)
8730
+{
8731
+ if (modify!=OP_SNIFFER1_TAG_KEEP && modify!=OP_SNIFFER1_TAG_MODIFY)
8732
+ return -EINVAL;
8733
+ ip1811drv_dbg("modify=%d\n", modify);
8734
+
8735
+ _WriteRegBits(1, P1REG_SNIFCFG, 7, 1, modify);
8736
+
8737
+ return 0;
8738
+}
8739
+EXPORT_SYMBOL(switchdSetS1TM4Pkt2MPort);
8740
+int setS1TM4Pkt2MPort(void *cdata, int len)
8741
+{
8742
+ int modify;
8743
+
8744
+ ip1811drv_dbg("ip1811: +setS1TM4Pkt2MPort...\n");
8745
+ if (sizeof(struct GeneralSetting) != len)
8746
+ return -EINVAL;
8747
+
8748
+ modify = ((struct GeneralSetting *)cdata) ->gdata;
8749
+
8750
+ if(switchdSetS1TM4Pkt2MPort(modify) != 0)
8751
+ return -EINVAL;
8752
+
8753
+ ip1811drv_dbg("ip1811: -setS1TM4Pkt2MPort...\n");
8754
+ return 0;
8755
+}
8756
+
8757
+int switchdGetS1TM4Pkt2MPort(int *ptrInt)
8758
+{
8759
+ *ptrInt = (int)_ReadRegBits(1, P1REG_SNIFCFG, 7, 1);
8760
+
8761
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
8762
+
8763
+ return 0;
8764
+}
8765
+EXPORT_SYMBOL(switchdGetS1TM4Pkt2MPort);
8766
+int getS1TM4Pkt2MPort(void *cdata, int len)
8767
+{
8768
+ int modify;
8769
+
8770
+ ip1811drv_dbg("ip1811: +getS1TM4Pkt2MPort...\n");
8771
+ if (sizeof(struct GeneralSetting) != len)
8772
+ return -EINVAL;
8773
+
8774
+ if(switchdGetS1TM4Pkt2MPort(&modify) != 0)
8775
+ return -EINVAL;
8776
+
8777
+ ((struct GeneralSetting *)cdata) ->gdata = modify;
8778
+
8779
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
8780
+ ip1811drv_dbg("ip1811: -getS1TM4Pkt2MPort...\n");
8781
+ return 0;
8782
+}
8783
+
8784
+int switchdSetS2LTT4Grp1(int ltt)
8785
+{
8786
+ if (ltt!=OP_SNIFFER2_LUT_TRIGGER_TARGET_DA && ltt!=OP_SNIFFER2_LUT_TRIGGER_TARGET_SA)
8787
+ return -EINVAL;
8788
+ ip1811drv_dbg("ltt=%d\n", ltt);
8789
+
8790
+ _WriteRegBits(1, P1REG_SNIFCFG, 3, 1, ltt);
8791
+
8792
+ return 0;
8793
+}
8794
+EXPORT_SYMBOL(switchdSetS2LTT4Grp1);
8795
+int setS2LTT4Grp1(void *cdata, int len)
8796
+{
8797
+ int ltt;
8798
+
8799
+ ip1811drv_dbg("ip1811: +setS2LTT4Grp1...\n");
8800
+ if (sizeof(struct GeneralSetting) != len)
8801
+ return -EINVAL;
8802
+
8803
+ ltt = ((struct GeneralSetting *)cdata) ->gdata;
8804
+
8805
+ if(switchdSetS2LTT4Grp1(ltt) != 0)
8806
+ return -EINVAL;
8807
+
8808
+ ip1811drv_dbg("ip1811: -setS2LTT4Grp1...\n");
8809
+ return 0;
8810
+}
8811
+
8812
+int switchdGetS2LTT4Grp1(int *ptrInt)
8813
+{
8814
+ *ptrInt = (int)_ReadRegBits(1, P1REG_SNIFCFG, 3, 1);
8815
+
8816
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
8817
+
8818
+ return 0;
8819
+}
8820
+EXPORT_SYMBOL(switchdGetS2LTT4Grp1);
8821
+int getS2LTT4Grp1(void *cdata, int len)
8822
+{
8823
+ int ltt;
8824
+
8825
+ ip1811drv_dbg("ip1811: +getS2LTT4Grp1...\n");
8826
+ if (sizeof(struct GeneralSetting) != len)
8827
+ return -EINVAL;
8828
+
8829
+ if(switchdGetS2LTT4Grp1(&ltt) != 0)
8830
+ return -EINVAL;
8831
+
8832
+ ((struct GeneralSetting *)cdata) ->gdata = ltt;
8833
+
8834
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
8835
+ ip1811drv_dbg("ip1811: -getS2LTT4Grp1...\n");
8836
+ return 0;
8837
+}
8838
+
8839
+//------------------------------------------------
8840
+//ip1811_storm
8841
+int switchdSetMStormNBlockIpPkt(int nb)
8842
+{
8843
+ if (nb!=OP_FUNC_DISABLE && nb!=OP_FUNC_ENABLE)
8844
+ return -EINVAL;
8845
+ ip1811drv_dbg("nb=%d\n", nb);
8846
+
8847
+ _WriteRegBits(1, P1REG_BSTORMTHRESH, 11, 1, nb);
8848
+
8849
+ return 0;
8850
+}
8851
+EXPORT_SYMBOL(switchdSetMStormNBlockIpPkt);
8852
+int setMStormNBlockIpPkt(void *cdata, int len)
8853
+{
8854
+ int nb;
8855
+
8856
+ ip1811drv_dbg("ip1811: +setMStormNBlockIpPkt...\n");
8857
+ if (sizeof(struct GeneralSetting) != len)
8858
+ return -EINVAL;
8859
+
8860
+ nb = ((struct GeneralSetting *)cdata) ->gdata;
8861
+
8862
+ if(switchdSetMStormNBlockIpPkt(nb) != 0)
8863
+ return -EINVAL;
8864
+
8865
+ ip1811drv_dbg("ip1811: -setMStormNBlockIpPkt...\n");
8866
+ return 0;
8867
+}
8868
+
8869
+int switchdGetMStormNBlockIpPkt(int *ptrInt)
8870
+{
8871
+ *ptrInt = (int)_ReadRegBits(1, P1REG_BSTORMTHRESH, 11, 1);
8872
+
8873
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
8874
+
8875
+ return 0;
8876
+}
8877
+EXPORT_SYMBOL(switchdGetMStormNBlockIpPkt);
8878
+int getMStormNBlockIpPkt(void *cdata, int len)
8879
+{
8880
+ int nb;
8881
+
8882
+ ip1811drv_dbg("ip1811: +getMStormNBlockIpPkt...\n");
8883
+ if (sizeof(struct GeneralSetting) != len)
8884
+ return -EINVAL;
8885
+
8886
+ if(switchdGetMStormNBlockIpPkt(&nb) != 0)
8887
+ return -EINVAL;
8888
+
8889
+ ((struct GeneralSetting *)cdata) ->gdata = nb;
8890
+
8891
+ ip1811drv_dbg("ip1811: -getMStormNBlockIpPkt...\n");
8892
+ return 0;
8893
+}
8894
+
8895
+int switchdSetMStormIgnr01005EXXXXXX(int ignr)
8896
+{
8897
+ if (ignr!=OP_FUNC_DISABLE && ignr!=OP_FUNC_ENABLE)
8898
+ return -EINVAL;
8899
+ ip1811drv_dbg("ignr=%d\n", ignr);
8900
+
8901
+ _WriteRegBits(1, P1REG_BSTORMTHRESH, 12, 1, ignr);
8902
+
8903
+ return 0;
8904
+}
8905
+EXPORT_SYMBOL(switchdSetMStormIgnr01005EXXXXXX);
8906
+int setMStormIgnr01005EXXXXXX(void *cdata, int len)
8907
+{
8908
+ int ignr;
8909
+
8910
+ ip1811drv_dbg("ip1811: +setMStormIgnr01005EXXXXXX...\n");
8911
+ if (sizeof(struct GeneralSetting) != len)
8912
+ return -EINVAL;
8913
+
8914
+ ignr = ((struct GeneralSetting *)cdata) ->gdata;
8915
+
8916
+ if(switchdSetMStormIgnr01005EXXXXXX(ignr) != 0)
8917
+ return -EINVAL;
8918
+
8919
+ ip1811drv_dbg("ip1811: -setMStormIgnr01005EXXXXXX...\n");
8920
+ return 0;
8921
+}
8922
+
8923
+int switchdGetMStormIgnr01005EXXXXXX(int *ptrInt)
8924
+{
8925
+ *ptrInt = (int)_ReadRegBits(1, P1REG_BSTORMTHRESH, 12, 1);
8926
+
8927
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
8928
+
8929
+ return 0;
8930
+}
8931
+EXPORT_SYMBOL(switchdGetMStormIgnr01005EXXXXXX);
8932
+int getMStormIgnr01005EXXXXXX(void *cdata, int len)
8933
+{
8934
+ int en=0;
8935
+
8936
+ ip1811drv_dbg("ip1811: +getMStormIgnr01005EXXXXXX...\n");
8937
+ if (sizeof(struct GeneralSetting) != len)
8938
+ return -EINVAL;
8939
+
8940
+ if(switchdGetMStormIgnr01005EXXXXXX(&en) != 0)
8941
+ return -EINVAL;
8942
+
8943
+ ((struct GeneralSetting *)cdata) ->gdata = en;
8944
+
8945
+ ip1811drv_dbg("ip1811: -getMStormIgnr01005EXXXXXX...\n");
8946
+ return 0;
8947
+}
8948
+
8949
+//ip1811_stp
8950
+int switchdSetBpduCapMode(int bcmode)
8951
+{
8952
+ if (bcmode!=OP_BPDU_CMODE_GLOBAL && bcmode!=OP_BPDU_CMODE_BY_PORT)
8953
+ return -EINVAL;
8954
+ ip1811drv_dbg("bcmode=%d\n", bcmode);
8955
+
8956
+ _WriteRegBits(0, P0REG_MACBEHAVIOR, 10, 1, bcmode);
8957
+
8958
+ return 0;
8959
+}
8960
+EXPORT_SYMBOL(switchdSetBpduCapMode);
8961
+int setBpduCapMode(void *cdata, int len)
8962
+{
8963
+ int bcmode;
8964
+
8965
+ ip1811drv_dbg("ip1811: +setBpduCapMode...\n");
8966
+ if (sizeof(struct GeneralSetting) != len)
8967
+ return -EINVAL;
8968
+
8969
+ bcmode = ((struct GeneralSetting *)cdata) ->gdata;
8970
+
8971
+ if(switchdSetBpduCapMode(bcmode) != 0)
8972
+ return -EINVAL;
8973
+
8974
+ ip1811drv_dbg("ip1811: -setBpduCapMode...\n");
8975
+ return 0;
8976
+}
8977
+
8978
+int switchdGetBpduCapMode(int *ptrInt)
8979
+{
8980
+ *ptrInt = (int)_ReadRegBits(0, P0REG_MACBEHAVIOR, 10, 1);
8981
+
8982
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
8983
+
8984
+ return 0;
8985
+}
8986
+EXPORT_SYMBOL(switchdGetBpduCapMode);
8987
+int getBpduCapMode(void *cdata, int len)
8988
+{
8989
+ int bcmode;
8990
+
8991
+ ip1811drv_dbg("ip1811: +getBpduCapMode...\n");
8992
+ if (sizeof(struct GeneralSetting) != len)
8993
+ return -EINVAL;
8994
+
8995
+ if(switchdGetBpduCapMode(&bcmode) != 0)
8996
+ return -EINVAL;
8997
+
8998
+ ((struct GeneralSetting *)cdata) ->gdata = bcmode;
8999
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
9000
+ ip1811drv_dbg("ip1811: -getBpduCapMode...\n");
9001
+ return 0;
9002
+}
9003
+
9004
+int switchdSetBpduPortAct(int port, int state)
9005
+{
9006
+ u16 u16dat;
9007
+
9008
+ if (port < 0 || port >= MAX_PHY_NUM)
9009
+ return -EINVAL;
9010
+ if (state!=OP_CAP_ACT_FORWARD && state!=OP_CAP_ACT_TO_CPU && state!=OP_CAP_ACT_DROP)
9011
+ return -EINVAL;
9012
+ ip1811drv_dbg("port=%d\n", port);
9013
+ ip1811drv_dbg("state=%d\n", state);
9014
+
9015
+ IP2Page(0);
9016
+ u16dat = Read_Reg(P0REG_BPDUPORTCAPCFG);
9017
+ u16dat |= (u16)((state&0x1) << (port));
9018
+#ifdef COMBINED_PORT
9019
+ if (port==9)
9020
+ u16dat |= (u16)((state&0x1) << (port+1));
9021
+#endif
9022
+ Write_Reg(P0REG_BPDUPORTCAPCFG, u16dat);
9023
+
9024
+ u16dat = Read_Reg(P0REG_BPDUPORTCAPCFG+2);
9025
+ u16dat |= (u16)(((state>>1)&0x1) << (port));
9026
+#ifdef COMBINED_PORT
9027
+ if (port==9)
9028
+ u16dat |= (u16)(((state>>1)&0x1) << (port+1));
9029
+#endif
9030
+ Write_Reg(P0REG_BPDUPORTCAPCFG+2, u16dat);
9031
+
9032
+ return 0;
9033
+}
9034
+EXPORT_SYMBOL(switchdSetBpduPortAct);
9035
+int setBpduPortAct(void *cdata, int len)
9036
+{
9037
+ int port, state;
9038
+
9039
+ ip1811drv_dbg("ip1811: +setBpduPortAct...\n");
9040
+ if (sizeof(struct ByPortSetting) != len)
9041
+ return -EINVAL;
9042
+
9043
+ port = ((struct ByPortSetting *)cdata) ->port;
9044
+ state= ((struct ByPortSetting *)cdata) ->pdata;
9045
+
9046
+ if(switchdSetBpduPortAct(port, state) != 0)
9047
+ return -EINVAL;
9048
+
9049
+ ip1811drv_dbg("ip1811: -setBpduPortAct...\n");
9050
+ return 0;
9051
+}
9052
+
9053
+int switchdGetBpduPortAct(int port, int *ptrInt)
9054
+{
9055
+ if (port < 0 || port >= MAX_PHY_NUM)
9056
+ return -EINVAL;
9057
+ ip1811drv_dbg("port=%d\n", port);
9058
+
9059
+#ifdef COMBINED_PORT
9060
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
9061
+ port++;
9062
+#endif
9063
+ *ptrInt = (int)(_ReadRegBits(0, P0REG_BPDUPORTCAPCFG+2, port, 1) | _ReadRegBits(0, P0REG_BPDUPORTCAPCFG, port, 1));
9064
+
9065
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
9066
+
9067
+ return 0;
9068
+}
9069
+EXPORT_SYMBOL(switchdGetBpduPortAct);
9070
+int getBpduPortAct(void *cdata, int len)
9071
+{
9072
+ int port, state;
9073
+
9074
+ ip1811drv_dbg("ip1811: +getBpduPortAct...\n");
9075
+ if (sizeof(struct ByPortSetting) != len)
9076
+ return -EINVAL;
9077
+
9078
+ port = ((struct ByPortSetting *)cdata) ->port;
9079
+
9080
+ if(switchdGetBpduPortAct(port, &state) != 0)
9081
+ return -EINVAL;
9082
+
9083
+ ((struct GeneralSetting *)cdata) ->gdata = state;
9084
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
9085
+ ip1811drv_dbg("ip1811: -getBpduPortAct...\n");
9086
+ return 0;
9087
+}
9088
+
9089
+int switchdSetStpPortState(int fid, int port, int state)
9090
+{
9091
+ u16 u16dat=0;
9092
+
9093
+ if (fid < 1 || fid > 16)
9094
+ return -EINVAL;
9095
+ if (port < 0 || port >= MAX_PHY_NUM)
9096
+ return -EINVAL;
9097
+ if (state < OP_STP_STATE_DISCARD || state > OP_STP_STATE_FORWARD)
9098
+ return -EINVAL;
9099
+ ip1811drv_dbg("fid=%d\n", fid);
9100
+ ip1811drv_dbg("port=%d\n", port);
9101
+ ip1811drv_dbg("state=%d\n", state);
9102
+
9103
+ fid--;
9104
+ IP2Page(2);
9105
+ Write_Reg(P2REG_SPANTREE_PORTCMD, (u16)(0x8010 | fid));
9106
+ u16dat = Read_Reg(P2REG_SPANTREE_PORTDTA);
9107
+ switch(state){
9108
+ case OP_STP_STATE_DISCARD:
9109
+ case OP_STP_STATE_BLOCK:
9110
+ u16dat &= (u16)~(1 << port);
9111
+#ifdef COMBINED_PORT
9112
+ if (port==9)
9113
+ u16dat &= (u16)~(1 << port+1);
9114
+#endif
9115
+ break;
9116
+ case OP_STP_STATE_LEARN:
9117
+ case OP_STP_STATE_FORWARD:
9118
+ u16dat |= (u16)(1 << port);
9119
+#ifdef COMBINED_PORT
9120
+ if (port==9)
9121
+ u16dat |= (u16)(1 << port+1);
9122
+#endif
9123
+ break;
9124
+ }
9125
+ Write_Reg(P2REG_SPANTREE_PORTDTA, u16dat & 0xFFFF);
9126
+ Write_Reg(P2REG_SPANTREE_PORTCMD, (u16)(0xC010 | fid));
9127
+
9128
+ Write_Reg(P2REG_SPANTREE_PORTCMD, (u16)(0x8000 | fid));
9129
+ u16dat = Read_Reg(P2REG_SPANTREE_PORTDTA);
9130
+ switch(state){
9131
+ case OP_STP_STATE_DISCARD:
9132
+ case OP_STP_STATE_LEARN:
9133
+ u16dat &= (u16)~(1 << port);
9134
+#ifdef COMBINED_PORT
9135
+ if (port==9)
9136
+ u16dat &= (u16)~(1 << port+1);
9137
+#endif
9138
+ break;
9139
+ case OP_STP_STATE_BLOCK:
9140
+ case OP_STP_STATE_FORWARD:
9141
+ u16dat |= (u16)(1 << port);
9142
+#ifdef COMBINED_PORT
9143
+ if (port==9)
9144
+ u16dat |= (u16)(1 << port+1);
9145
+#endif
9146
+ break;
9147
+ }
9148
+ Write_Reg(P2REG_SPANTREE_PORTDTA, u16dat & 0xFFFF);
9149
+ Write_Reg(P2REG_SPANTREE_PORTCMD, (u16)(0xC000 | fid));
9150
+
9151
+ return 0;
9152
+}
9153
+EXPORT_SYMBOL(switchdSetStpPortState);
9154
+int setStpPortState(void *cdata, int len)
9155
+{
9156
+ int fid, port, state;
9157
+
9158
+ ip1811drv_dbg("ip1811: +setStpPortState...\n");
9159
+ if (sizeof(struct StpByFPSetting) != len)
9160
+ return -EINVAL;
9161
+
9162
+ fid = ((struct StpByFPSetting *)cdata) ->fid;
9163
+ port= ((struct StpByFPSetting *)cdata) ->port;
9164
+ state=((struct StpByFPSetting *)cdata) ->pstate;
9165
+
9166
+ if(switchdSetStpPortState(fid, port, state) != 0)
9167
+ return -EINVAL;
9168
+
9169
+ ip1811drv_dbg("ip1811: -setStpPortState...\n");
9170
+ return 0;
9171
+}
9172
+
9173
+int switchdGetStpPortState(int fid, int port, int *ptrInt)
9174
+{
9175
+ int state;
9176
+ u16 u16dat=0;
9177
+
9178
+ if (fid < 1 || fid > 16)
9179
+ return -EINVAL;
9180
+ if (port < 0 || port >= MAX_PHY_NUM)
9181
+ return -EINVAL;
9182
+ ip1811drv_dbg("fid=%d\n", fid);
9183
+ ip1811drv_dbg("port=%d\n", port);
9184
+
9185
+#ifdef COMBINED_PORT
9186
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
9187
+ port++;
9188
+#endif
9189
+ fid--;
9190
+ IP2Page(2);
9191
+ Write_Reg(P2REG_SPANTREE_PORTCMD, (u16)(0x8010 | fid));
9192
+ u16dat = Read_Reg(P2REG_SPANTREE_PORTDTA);
9193
+ state = ((u16dat>>port)&0x1)<<1;
9194
+ Write_Reg(P2REG_SPANTREE_PORTCMD, (u16)(0x8000 | fid));
9195
+ u16dat = Read_Reg(P2REG_SPANTREE_PORTDTA);
9196
+ state |= ((u16dat>>port)&0x1);
9197
+
9198
+ *ptrInt = state;
9199
+
9200
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
9201
+
9202
+ return 0;
9203
+}
9204
+EXPORT_SYMBOL(switchdGetStpPortState);
9205
+int getStpPortState(void *cdata, int len)
9206
+{
9207
+ int fid, port, state;
9208
+
9209
+ ip1811drv_dbg("ip1811: +getStpPortState...\n");
9210
+ if (sizeof(struct StpByFPSetting) != len)
9211
+ return -EINVAL;
9212
+
9213
+ fid = ((struct StpByFPSetting *)cdata) ->fid;
9214
+ port= ((struct StpByFPSetting *)cdata) ->port;
9215
+
9216
+ if(switchdGetStpPortState(fid, port, &state) != 0)
9217
+ return -EINVAL;
9218
+
9219
+ ((struct StpByFPSetting *)cdata) ->pstate = state;
9220
+ ip1811drv_dbg("cdata ->pstate=%d\n", ((struct StpByFPSetting *)cdata) ->pstate);
9221
+ ip1811drv_dbg("ip1811: -getStpPortState...\n");
9222
+ return 0;
9223
+}
9224
+
9225
+//ip1811_lacp
9226
+int switchdSetTrunkHashMthdSeq(int en)
9227
+{
9228
+ if (en!=OP_FUNC_DISABLE && en!=OP_FUNC_ENABLE)
9229
+ return -EINVAL;
9230
+ ip1811drv_dbg("en=%d\n", en);
9231
+
9232
+ _WriteRegBits(1, P1REG_TRUNKCFG, 3, 1, en);
9233
+
9234
+ return 0;
9235
+}
9236
+EXPORT_SYMBOL(switchdSetTrunkHashMthdSeq);
9237
+int setTrunkHashMthdSeq(void *cdata, int len)
9238
+{
9239
+ int en;
9240
+
9241
+ ip1811drv_dbg("ip1811: +setTrunkHashMthdSeq...\n");
9242
+ if (sizeof(struct GeneralSetting) != len)
9243
+ return -EINVAL;
9244
+
9245
+ en = ((struct GeneralSetting *)cdata) ->gdata;
9246
+
9247
+ if(switchdSetTrunkHashMthdSeq(en) != 0)
9248
+ return -EINVAL;
9249
+
9250
+ ip1811drv_dbg("ip1811: -setTrunkHashMthdSeq...\n");
9251
+ return 0;
9252
+}
9253
+
9254
+int switchdGetTrunkHashMthdSeq(int *ptrInt)
9255
+{
9256
+ *ptrInt = (int)_ReadRegBits(1, P1REG_TRUNKCFG, 3, 1);
9257
+
9258
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
9259
+
9260
+ return 0;
9261
+}
9262
+EXPORT_SYMBOL(switchdGetTrunkHashMthdSeq);
9263
+int getTrunkHashMthdSeq(void *cdata, int len)
9264
+{
9265
+ int en;
9266
+
9267
+ ip1811drv_dbg("ip1811: +getTrunkHashMthdSeq...\n");
9268
+ if (sizeof(struct GeneralSetting) != len)
9269
+ return -EINVAL;
9270
+
9271
+ if(switchdGetTrunkHashMthdSeq(&en) != 0)
9272
+ return -EINVAL;
9273
+
9274
+ ((struct GeneralSetting *)cdata) ->gdata = en;
9275
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
9276
+ ip1811drv_dbg("ip1811: -getTrunkHashMthdSeq...\n");
9277
+ return 0;
9278
+}
9279
+
9280
+int switchdSetTrunkGrpCombine(int grps, int en)
9281
+{
9282
+ if (grps < OP_TRUNK_COMBINE_G1_G2 || grps > OP_TRUNK_COMBINE_G3_G4)
9283
+ return -EINVAL;
9284
+ if (en!=OP_FUNC_DISABLE && en!=OP_FUNC_ENABLE)
9285
+ return -EINVAL;
9286
+ ip1811drv_dbg("grps=%d\n", grps);
9287
+ ip1811drv_dbg("en=%d\n", en);
9288
+
9289
+ _WriteRegBits(1, P1REG_TRUNKCFG, grps, 1, en);
9290
+
9291
+ return 0;
9292
+}
9293
+EXPORT_SYMBOL(switchdSetTrunkGrpCombine);
9294
+int setTrunkGrpCombine(void *cdata, int len)
9295
+{
9296
+ int grps, en;
9297
+
9298
+ ip1811drv_dbg("ip1811: +setTrunkGrpCombine...\n");
9299
+ if (sizeof(struct TrunkCombineSetting) != len)
9300
+ return -EINVAL;
9301
+
9302
+ grps=((struct TrunkCombineSetting *)cdata) ->tgrps;
9303
+ en = ((struct TrunkCombineSetting *)cdata) ->cen;
9304
+
9305
+ if(switchdSetTrunkGrpCombine(grps, en) != 0)
9306
+ return -EINVAL;
9307
+
9308
+ ip1811drv_dbg("ip1811: -setTrunkGrpCombine...\n");
9309
+ return 0;
9310
+}
9311
+
9312
+int switchdGetTrunkGrpCombine(int grps, int *ptrInt)
9313
+{
9314
+ if (grps < OP_TRUNK_COMBINE_G1_G2 || grps > OP_TRUNK_COMBINE_G3_G4)
9315
+ return -EINVAL;
9316
+ ip1811drv_dbg("grps=%d\n", grps);
9317
+
9318
+ *ptrInt = (int)_ReadRegBits(1, P1REG_TRUNKCFG, grps, 1);
9319
+
9320
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
9321
+
9322
+ return 0;
9323
+}
9324
+EXPORT_SYMBOL(switchdGetTrunkGrpCombine);
9325
+int getTrunkGrpCombine(void *cdata, int len)
9326
+{
9327
+ int grps, en;
9328
+
9329
+ ip1811drv_dbg("ip1811: +getTrunkGrpCombine...\n");
9330
+ if (sizeof(struct TrunkCombineSetting) != len)
9331
+ return -EINVAL;
9332
+
9333
+ grps=((struct TrunkCombineSetting *)cdata) ->tgrps;
9334
+
9335
+ if(switchdGetTrunkGrpCombine(grps, &en) != 0)
9336
+ return -EINVAL;
9337
+
9338
+ ((struct TrunkCombineSetting *)cdata) ->cen = en;
9339
+ ip1811drv_dbg("cdata ->cen=%d\n", ((struct TrunkCombineSetting *)cdata) ->cen);
9340
+ ip1811drv_dbg("ip1811: -getTrunkGrpCombine...\n");
9341
+ return 0;
9342
+}
9343
+
9344
+//------------ MIB Counter functions:ip1811 ---------------------
9345
+int switchdSetMibCounterEnable(int en)
9346
+{
9347
+ if( en!=OP_FUNC_ENABLE && en!=OP_FUNC_DISABLE ){
9348
+ ip1811drv_err("Error: en=%X\n", en);
9349
+ return -EINVAL;
9350
+ }
9351
+ _WriteRegBits(0, P0REG_MACBEHAVIOR, 9, 1, en);
9352
+ return 0;
9353
+}
9354
+EXPORT_SYMBOL(switchdSetMibCounterEnable);
9355
+
9356
+int setMibCounterEnable(void *cdata, int len)
9357
+{
9358
+ int ret, en;
9359
+ FUNC_MSG_IN;
9360
+
9361
+ if (sizeof(struct GeneralSetting) != len){
9362
+ ip1811drv_err("Error: lengtn=%d\n", len);
9363
+ return -EINVAL;
9364
+ }
9365
+
9366
+ en = ((struct GeneralSetting *)cdata) ->gdata;
9367
+
9368
+ ip1811drv_dbg("cdata ->gdata=%d\n", en);
9369
+ ret = switchdSetMibCounterEnable(en);
9370
+
9371
+ FUNC_MSG_OUT;
9372
+ return ret;
9373
+}
9374
+
9375
+int switchdGetMibCounterEnable(int *gdata_p)
9376
+{
9377
+ *gdata_p = _ReadRegBits(0, P0REG_MACBEHAVIOR, 9, 1);
9378
+ return 0;
9379
+}
9380
+EXPORT_SYMBOL(switchdGetMibCounterEnable);
9381
+
9382
+int getMibCounterEnable(void *cdata, int len)
9383
+{
9384
+ int ret;
9385
+ struct GeneralSetting *gs = (struct GeneralSetting *)cdata;
9386
+
9387
+ FUNC_MSG_IN;
9388
+ if (sizeof(struct GeneralSetting) != len) {
9389
+ ip1811drv_err("Error: lengtn=%d\n", len);
9390
+ return -EINVAL;
9391
+ }
9392
+ ret = switchdGetMibCounterEnable(&(gs ->gdata));
9393
+ FUNC_MSG_OUT;
9394
+ return ret;
9395
+}
9396
+
9397
+int switchdGetMibCounterAll(void *uptr)
9398
+{
9399
+ int i, j, ret=0;
9400
+ struct MIBCounterEntry_all *dptr;
9401
+
9402
+ dptr = kmalloc(sizeof(struct MIBCounterEntry_all), GFP_KERNEL);
9403
+ if (!dptr) {
9404
+ ret = -ENOMEM;
9405
+ goto out_mib_counter_all;
9406
+ }
9407
+
9408
+ IP2Page(0);
9409
+ for(j=0; j<MAX_PHY_NUM; j++) {
9410
+ for(i=0; i<NUM_MIB_COUNTER_RX; i++) {
9411
+ //statistic counter read , read clear rx counter
9412
+ Write_Reg(POREG_MIBCOUN_CMD, 0xC000|(u16)i|((u16)j<<5));
9413
+ /* need to check does trigger bit has been put down */
9414
+ while((Read_Reg(POREG_MIBCOUN_CMD) >> 15)&0x1);
9415
+
9416
+ dptr ->entry[j].RX_counter[i] = (u32)Read_Reg(POREG_MIBCOUN_DATA_L);
9417
+ dptr ->entry[j].RX_counter[i] |= ((u32)Read_Reg(POREG_MIBCOUN_DATA_H)<<16);
9418
+ }
9419
+ for(i=0; i<NUM_MIB_COUNTER_TX; i++) {
9420
+ //statistic counter read , read clear tx counter
9421
+ Write_Reg(POREG_MIBCOUN_CMD,0xC400|(u16)i|((u16)j<<5));
9422
+ /* need to check does trigger bit has been put down */
9423
+ while((Read_Reg(POREG_MIBCOUN_CMD) >> 15)&0x1);
9424
+
9425
+ dptr ->entry[j].TX_counter[i] = (u32)Read_Reg(POREG_MIBCOUN_DATA_L);
9426
+ dptr ->entry[j].TX_counter[i] |= ((u32)Read_Reg(POREG_MIBCOUN_DATA_H)<<16);
9427
+ }
9428
+ }
9429
+ if (copy_to_user(uptr, dptr, sizeof(struct MIBCounterEntry_all))) {
9430
+ ret = -EFAULT;
9431
+ goto out_mib_counter_all;
9432
+ }
9433
+out_mib_counter_all:
9434
+ if(dptr){
9435
+ kfree(dptr);
9436
+ }
9437
+ return (ret < 0) ? ret : 0;
9438
+}
9439
+EXPORT_SYMBOL(switchdGetMibCounterAll);
9440
+
9441
+int getMibCounterAll(void *cdata, int len)
9442
+{
9443
+ int ret;
9444
+ void *uptr;
9445
+
9446
+ FUNC_MSG_IN;
9447
+ if (sizeof(struct GeneralSetting) != len) {
9448
+ ip1811drv_err("Error: lengtn=%d\n", len);
9449
+ return -EINVAL;
9450
+ }
9451
+
9452
+ uptr = (void *)(((struct GeneralSetting *)cdata) ->gdata);
9453
+ ret = switchdGetMibCounterAll(uptr);
9454
+
9455
+ FUNC_MSG_OUT;
9456
+ return ret;
9457
+}
9458
+
9459
+int switchdGetMibCounterByPort(void *uptr, int port)
9460
+{
9461
+ int i, ret;
9462
+ struct MIBCounterEntry *dptr;
9463
+
9464
+ dptr = kmalloc(sizeof(struct MIBCounterEntry), GFP_KERNEL);
9465
+ if (!dptr) {
9466
+ ret = -ENOMEM;
9467
+ goto out_mib_counter;
9468
+ }
9469
+ IP2Page(0);
9470
+
9471
+#ifdef COMBINED_PORT
9472
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
9473
+ port++;
9474
+#endif
9475
+ for(i=0; i<NUM_MIB_COUNTER_RX; i++) {
9476
+ //statistic counter read , read clear rx counter
9477
+ Write_Reg(POREG_MIBCOUN_CMD, 0xC000|(u16)i|((u16)port<<5));
9478
+ /* need to check does trigger bit has been put down */
9479
+ while((Read_Reg(POREG_MIBCOUN_CMD) >> 15)&0x1);
9480
+ dptr ->RX_counter[i] = (u32)(((u32)Read_Reg(POREG_MIBCOUN_DATA_H)<<16)|Read_Reg(POREG_MIBCOUN_DATA_L));
9481
+ }
9482
+ for(i=0; i<NUM_MIB_COUNTER_TX; i++) {
9483
+ //statistic counter read , read clear tx counter
9484
+ Write_Reg(POREG_MIBCOUN_CMD, 0xC400|(u16)i|((u16)port<<5));
9485
+ /* need to check does trigger bit has been put down */
9486
+ while((Read_Reg(POREG_MIBCOUN_CMD) >> 15)&0x1);
9487
+ dptr ->TX_counter[i] = (u32)(((u32)Read_Reg(POREG_MIBCOUN_DATA_H)<<16)|Read_Reg(POREG_MIBCOUN_DATA_L));
9488
+ }
9489
+ if (copy_to_user(uptr, dptr, sizeof(struct MIBCounterEntry))) {
9490
+ ret = -EFAULT;
9491
+ goto out_mib_counter;
9492
+ }
9493
+out_mib_counter:
9494
+ if(dptr) {
9495
+ kfree(dptr);
9496
+ }
9497
+
9498
+ return (ret < 0) ? ret : 0;
9499
+}
9500
+EXPORT_SYMBOL(switchdGetMibCounterByPort);
9501
+
9502
+int getMibCounterByPort(void *cdata, int len)
9503
+{
9504
+ int port, ret;
9505
+ void *uptr;
9506
+ FUNC_MSG_IN;
9507
+ if (sizeof(struct ByPortSetting) != len) {
9508
+ ip1811drv_err("Error: lengtn=%d\n", len);
9509
+ return -EINVAL;
9510
+ }
9511
+
9512
+ uptr = (void *)(((struct ByPortSetting *)cdata) ->pdata);
9513
+ port = ((struct ByPortSetting *)cdata) ->port;
9514
+
9515
+ ret = switchdGetMibCounterByPort(uptr, port);
9516
+
9517
+ FUNC_MSG_OUT;
9518
+ return ret;
9519
+}
9520
+
9521
+int switchdGetMibCounterByItem(int port, int is_tx, int idx, unsigned long *cnt)
9522
+{
9523
+ IP2Page(0);
9524
+
9525
+#ifdef COMBINED_PORT
9526
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
9527
+ port++;
9528
+#endif
9529
+ //statistic counter read , read clear rx counter
9530
+ Write_Reg(POREG_MIBCOUN_CMD, (is_tx?0xC400:0xC000)|(u16)idx|((u16)port<<5));
9531
+ /* need to check does trigger bit has been put down */
9532
+ while((Read_Reg(POREG_MIBCOUN_CMD) >> 15)&0x1);
9533
+
9534
+ *cnt = (u32)(((u32)Read_Reg(POREG_MIBCOUN_DATA_H)<<16)|Read_Reg(POREG_MIBCOUN_DATA_L));
9535
+
9536
+ return 0;
9537
+}
9538
+EXPORT_SYMBOL(switchdGetMibCounterByItem);
9539
+
9540
+int getMibCounterByItem(void *cdata, int len)
9541
+{
9542
+ int port, dir, idx, ret;
9543
+ unsigned long mibcnt;
9544
+ struct MIBCounterData *mcd = (struct MIBCounterData *)cdata;
9545
+
9546
+ FUNC_MSG_IN;
9547
+
9548
+ if (sizeof(struct MIBCounterData) != len) {
9549
+ ip1811drv_err("Error: lengtn=%d\n", len);
9550
+ return -EINVAL;
9551
+ }
9552
+
9553
+ port = mcd ->port;
9554
+ dir = mcd ->dir;
9555
+ idx = mcd ->idx;
9556
+
9557
+ ret = switchdGetMibCounterByItem(port, dir, idx, &mibcnt);
9558
+ mcd ->counter = mibcnt;
9559
+
9560
+ FUNC_MSG_OUT;
9561
+ return ret;
9562
+
9563
+}
9564
+
9565
+//------------ MIB Counter functions:ip1811 end------------------
9566
+//------------ QOS functions:ip1811 -----------------------------
9567
+int setQOSAgingFunction(void *cdata, int len)
9568
+{
9569
+ int port,aging;
9570
+ FUNC_MSG_IN;
9571
+ if (sizeof(struct ByPortSetting) != len)
9572
+ {
9573
+ ip1811drv_err("Error: length=%d\n", len);
9574
+ return -EINVAL;
9575
+ }
9576
+
9577
+ port=((struct ByPortSetting *)cdata) ->port;
9578
+ aging =((struct ByPortSetting *)cdata) ->pdata;
9579
+ if (port < 0 || port >= MAX_PHY_NUM)
9580
+ return -EINVAL;
9581
+
9582
+ if (aging < 0 || aging > 0xff)
9583
+ return -EINVAL;
9584
+
9585
+ _WriteRegBits(8, P8REG_QOSPORTAGINGEN0+(port/2), (port%2)*8, 8, aging);
9586
+#ifdef COMBINED_PORT
9587
+ if (port==9){
9588
+ _WriteRegBits(8, P8REG_QOSPORTAGINGEN0+((port+1)/2), ((port+1)%2)*8, 8, aging);
9589
+ }
9590
+#endif
9591
+
9592
+ FUNC_MSG_OUT;
9593
+ return 0;
9594
+}
9595
+int getQOSAgingFunction(void *cdata, int len)
9596
+{
9597
+ int port;
9598
+ FUNC_MSG_IN;
9599
+ if (sizeof(struct ByPortSetting) != len)
9600
+ {
9601
+ ip1811drv_err("Error: length=%d\n", len);
9602
+ return -EINVAL;
9603
+ }
9604
+ port=((struct ByPortSetting *)cdata) ->port;
9605
+ if (port < 0 || port >= MAX_PHY_NUM)
9606
+ return -EINVAL;
9607
+
9608
+#ifdef COMBINED_PORT
9609
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
9610
+ port++;
9611
+#endif
9612
+ ((struct ByPortSetting *)cdata) ->pdata=(u32)_ReadRegBits(8,P8REG_QOSPORTAGINGEN0+(port/2),(port%2)*8,8);
9613
+
9614
+ FUNC_MSG_OUT;
9615
+ ip1811drv_dbg("cdata ->pdata=%d\n", ((struct ByPortSetting *)cdata) ->pdata);
9616
+ return 0;
9617
+}
9618
+int setQOSAgingTime(void *cdata, int len)
9619
+{
9620
+ int aging;
9621
+ FUNC_MSG_IN;
9622
+ if (sizeof(struct GeneralSetting) != len)
9623
+ {
9624
+ ip1811drv_err("Error: length=%d\n", len);
9625
+ return -EINVAL;
9626
+ }
9627
+ aging = ((struct GeneralSetting *)cdata) ->gdata;
9628
+ if (aging < 0 || aging > 0xff)
9629
+ return -EINVAL;
9630
+
9631
+ _WriteRegBits(8, P8REG_QOSAGINGTIME, 0, 8, aging);
9632
+ FUNC_MSG_OUT;
9633
+ return 0;
9634
+}
9635
+int getQOSAgingTime(void *cdata, int len)
9636
+{
9637
+ FUNC_MSG_IN;
9638
+ if (sizeof(struct GeneralSetting) != len)
9639
+ {
9640
+ ip1811drv_err("Error: length=%d\n", len);
9641
+ return -EINVAL;
9642
+ }
9643
+
9644
+ ((struct GeneralSetting *)cdata) ->gdata = (u16)_ReadRegBits(8, P8REG_QOSAGINGTIME, 0, 8);
9645
+
9646
+ FUNC_MSG_OUT;
9647
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
9648
+ return 0;
9649
+}
9650
+int setQOSFastAging(void *cdata, int len)
9651
+{
9652
+ int ret;
9653
+ FUNC_MSG_IN;
9654
+ ret = _setGeneralEnable(cdata, len, 8, P8REG_QOSAGINGTIME, 8);
9655
+ FUNC_MSG_OUT;
9656
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
9657
+ return ret;
9658
+}
9659
+int getQOSFastAging(void *cdata, int len)
9660
+{
9661
+ int ret;
9662
+ FUNC_MSG_IN;
9663
+ ret = _getGeneralEnable(cdata, len, 8, P8REG_QOSAGINGTIME, 8);
9664
+ FUNC_MSG_OUT;
9665
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
9666
+ return ret;
9667
+}
9668
+int setCOSIGMP(void *cdata, int len)
9669
+{
9670
+ int ret;
9671
+ FUNC_MSG_IN;
9672
+ ret = _setPortmap(cdata, len, 0, P0REG_COSIGMPBASEPRIEN);
9673
+ FUNC_MSG_OUT;
9674
+ return ret;
9675
+}
9676
+int getCOSIGMP(void *cdata, int len)
9677
+{
9678
+ int ret;
9679
+ FUNC_MSG_IN;
9680
+ ret = _getPortmap(cdata, len, 0, P0REG_COSIGMPBASEPRIEN);
9681
+ FUNC_MSG_OUT;
9682
+ return ret;
9683
+}
9684
+int setCOSMACAddress(void *cdata, int len)
9685
+{
9686
+ int ret;
9687
+ FUNC_MSG_IN;
9688
+ ret = _setPortmap(cdata, len, 0, P0REG_COSMACBASEPRIEN);
9689
+ FUNC_MSG_OUT;
9690
+ return ret;
9691
+}
9692
+int getCOSMACAddress(void *cdata, int len)
9693
+{
9694
+ int ret;
9695
+ FUNC_MSG_IN;
9696
+ ret = _getPortmap(cdata, len, 0, P0REG_COSMACBASEPRIEN);
9697
+ FUNC_MSG_OUT;
9698
+ return ret;
9699
+}
9700
+int setCOSVID(void *cdata, int len)
9701
+{
9702
+ int ret;
9703
+ FUNC_MSG_IN;
9704
+ ret = _setPortmap(cdata, len, 0, P0REG_COSVIDBASEPRIEN);
9705
+ FUNC_MSG_OUT;
9706
+ return ret;
9707
+}
9708
+int getCOSVID(void *cdata, int len)
9709
+{
9710
+ int ret;
9711
+ FUNC_MSG_IN;
9712
+ ret = _getPortmap(cdata, len, 0, P0REG_COSVIDBASEPRIEN);
9713
+ FUNC_MSG_OUT;
9714
+ return ret;
9715
+}
9716
+int setCOSTCPUDPPort(void *cdata, int len)
9717
+{
9718
+ int ret;
9719
+ FUNC_MSG_IN;
9720
+ ret = _setPortmap(cdata, len, 0, P0REG_COSTCPUDPBASEPRIEN);
9721
+ FUNC_MSG_OUT;
9722
+ return ret;
9723
+}
9724
+int getCOSTCPUDPPort(void *cdata, int len)
9725
+{
9726
+ int ret;
9727
+ FUNC_MSG_IN;
9728
+ ret = _getPortmap(cdata, len, 0, P0REG_COSTCPUDPBASEPRIEN);
9729
+ FUNC_MSG_OUT;
9730
+ return ret;
9731
+}
9732
+int setCOSDSCP(void *cdata, int len)
9733
+{
9734
+ int ret;
9735
+ FUNC_MSG_IN;
9736
+ ret = _setPortmap(cdata, len, 0, P0REG_COSDSCPBASEPRIEN);
9737
+ FUNC_MSG_OUT;
9738
+ return ret;
9739
+}
9740
+int getCOSDSCP(void *cdata, int len)
9741
+{
9742
+ int ret;
9743
+ FUNC_MSG_IN;
9744
+ ret = _getPortmap(cdata, len, 0, P0REG_COSDSCPBASEPRIEN);
9745
+ FUNC_MSG_OUT;
9746
+ return ret;
9747
+}
9748
+int setCOS8021P(void *cdata, int len)
9749
+{
9750
+ int ret;
9751
+ FUNC_MSG_IN;
9752
+ ret = _setPortmap(cdata, len, 0, P0REG_COS8021PBASEPRIEN);
9753
+ FUNC_MSG_OUT;
9754
+ return ret;
9755
+}
9756
+int getCOS8021P(void *cdata, int len)
9757
+{
9758
+ int ret;
9759
+ FUNC_MSG_IN;
9760
+ ret = _getPortmap(cdata, len, 0, P0REG_COS8021PBASEPRIEN);
9761
+ FUNC_MSG_OUT;
9762
+ return ret;
9763
+}
9764
+int setCOSPhsicalPort(void *cdata, int len)
9765
+{
9766
+ int ret;
9767
+ FUNC_MSG_IN;
9768
+ ret = _setPortmap(cdata, len, 0, P0REG_COSPORTBASEPRIEN);
9769
+ FUNC_MSG_OUT;
9770
+ return ret;
9771
+}
9772
+int getCOSPhsicalPort(void *cdata, int len)
9773
+{
9774
+ int ret;
9775
+ FUNC_MSG_IN;
9776
+ ret = _getPortmap(cdata, len, 0, P0REG_COSPORTBASEPRIEN);
9777
+ FUNC_MSG_OUT;
9778
+ return ret;
9779
+}
9780
+int setCOSPortQueue(void *cdata, int len)
9781
+{
9782
+ int port;
9783
+ u8 queue;
9784
+
9785
+ FUNC_MSG_IN;
9786
+ if (sizeof(struct ByPortSetting) != len)
9787
+ {
9788
+ ip1811drv_err("Error: length=%d\n", len);
9789
+ return -EINVAL;
9790
+ }
9791
+
9792
+ port = ((struct ByPortSetting *)cdata) ->port;
9793
+ queue = ((struct ByPortSetting *)cdata) ->pdata;
9794
+
9795
+ if ((port < 0) || (port >= MAX_PHY_NUM))
9796
+ {
9797
+ ip1811drv_err("Error: port=%d\n", port);
9798
+ return -EINVAL;
9799
+ }
9800
+ if(queue>7)
9801
+ {
9802
+ ip1811drv_err("Error: queue=%d\n", queue);
9803
+ return -EINVAL;
9804
+ }
9805
+
9806
+ _WriteRegBits(0, P0REG_COSPORTBASEQUEUE0+(port/5), (port%5)*3, 3, queue);
9807
+#ifdef COMBINED_PORT
9808
+ if (port==9)
9809
+ _WriteRegBits(0, P0REG_COSPORTBASEQUEUE0+((port+1)/5), ((port+1)%5)*3, 3, queue);
9810
+#endif
9811
+ FUNC_MSG_OUT;
9812
+ return 0;
9813
+}
9814
+int getCOSPortQueue(void *cdata, int len)
9815
+{
9816
+ int port;
9817
+
9818
+ FUNC_MSG_IN;
9819
+ if (sizeof(struct ByPortSetting) != len)
9820
+ {
9821
+ ip1811drv_err("Error: length=%d\n", len);
9822
+ return -EINVAL;
9823
+ }
9824
+ port = ((struct ByPortSetting *)cdata) ->port;
9825
+ if ((port < 0) || (port >= MAX_PHY_NUM))
9826
+ {
9827
+ ip1811drv_err("Error: port=%d\n", port);
9828
+ return -EINVAL;
9829
+ }
9830
+
9831
+#ifdef COMBINED_PORT
9832
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
9833
+ port++;
9834
+#endif
9835
+ ((struct ByPortSetting *)cdata) ->pdata = (u16)_ReadRegBits(0, P0REG_COSPORTBASEQUEUE0+(port/5), (port%5)*3, 3);
9836
+ ip1811drv_dbg("cdata ->pdata=0x%04X\n", ((struct ByPortSetting *)cdata) ->pdata);
9837
+
9838
+ FUNC_MSG_OUT;
9839
+ return 0;
9840
+}
9841
+int setCOS8021PEdtion(void *cdata, int len)
9842
+{
9843
+ int gdata;
9844
+ u16 regdata;
9845
+
9846
+ FUNC_MSG_IN;
9847
+ if (sizeof(struct GeneralSetting) != len)
9848
+ {
9849
+ ip1811drv_err("Error: length=%d\n", len);
9850
+ return -EINVAL;
9851
+ }
9852
+
9853
+ gdata = ((struct GeneralSetting *)cdata) ->gdata;
9854
+ if( gdata != OP_QOS_8021PEDTION_2005 && gdata != OP_QOS_8021PEDTION_2005_EX && gdata != OP_QOS_8021PEDTION_EARLY )
9855
+ {
9856
+ ip1811drv_err("Error: gdata=%X\n", gdata);
9857
+ return -EINVAL;
9858
+ }
9859
+
9860
+ ip1811drv_dbg("cdata ->gdata=%d\n", gdata);
9861
+ IP2Page(0);
9862
+ regdata = Read_Reg(P0REG_COS8021PBASEPRIEN);
9863
+ regdata &= (u16)~0x6000;
9864
+ switch(gdata)
9865
+ {
9866
+ case OP_QOS_8021PEDTION_2005:
9867
+ break;
9868
+ case OP_QOS_8021PEDTION_2005_EX:
9869
+ regdata |= 0x4000; break;
9870
+ case OP_QOS_8021PEDTION_EARLY:
9871
+ regdata |= 0x2000; break;
9872
+ }
9873
+ Write_Reg(P0REG_COS8021PBASEPRIEN,regdata);
9874
+
9875
+ FUNC_MSG_OUT;
9876
+ return 0;
9877
+}
9878
+int getCOS8021PEdtion(void *cdata, int len)
9879
+{
9880
+ u16 u16dat;
9881
+ FUNC_MSG_IN;
9882
+ if (sizeof(struct GeneralSetting) != len)
9883
+ {
9884
+ ip1811drv_err("Error: length=%d\n", len);
9885
+ return -EINVAL;
9886
+ }
9887
+ u16dat =_ReadRegBits(0, P0REG_COS8021PBASEPRIEN, 13, 2);
9888
+
9889
+ if(u16dat&0x1)
9890
+ { ((struct GeneralSetting *)cdata) ->gdata = OP_QOS_8021PEDTION_EARLY; }
9891
+ else
9892
+ {
9893
+ if(u16dat&0x2)
9894
+ { ((struct GeneralSetting *)cdata) ->gdata = OP_QOS_8021PEDTION_2005_EX; }
9895
+ else
9896
+ { ((struct GeneralSetting *)cdata) ->gdata = OP_QOS_8021PEDTION_2005; }
9897
+ }
9898
+ ip1811drv_dbg("cdata ->gdata=0x%08x\n", ((struct GeneralSetting *)cdata) ->gdata);
9899
+
9900
+ FUNC_MSG_OUT;
9901
+ return 0;
9902
+}
9903
+int setCOSDSCPBaseDSCP(void *cdata, int len)
9904
+{
9905
+ u8 entryno,value,queue;
9906
+ FUNC_MSG_IN;
9907
+ if (sizeof(struct qos_dscp_setting) != len)
9908
+ {
9909
+ ip1811drv_err("Error: length=%d\n", len);
9910
+ return -EINVAL;
9911
+ }
9912
+
9913
+ entryno = ((struct qos_dscp_setting *)cdata) ->dscpentry;
9914
+ value = ((struct qos_dscp_setting *)cdata) ->dscpvalue;
9915
+ queue = ((struct qos_dscp_setting *)cdata) ->dscpqueue;
9916
+
9917
+ if(entryno<1 || entryno>8)
9918
+ {
9919
+ ip1811drv_err("Error: entryno=%d\n", entryno);
9920
+ return -EINVAL;
9921
+ }
9922
+ if(value & ~0x3f)
9923
+ {
9924
+ ip1811drv_err("Error: value=%X\n", value);
9925
+ return -EINVAL;
9926
+ }
9927
+ if(queue>7)
9928
+ {
9929
+ ip1811drv_err("Error: queue=%d\n", queue);
9930
+ return -EINVAL;
9931
+ }
9932
+
9933
+ entryno-=1;
9934
+
9935
+ _WriteRegBits(0, P0REG_COSDSCPVALUE0+(entryno/2), (entryno%2)*6, 6, value);
9936
+ _WriteRegBits(0, P0REG_COSDSCPPRISETTING0+(entryno/5), (entryno%5)*3, 3, queue);
9937
+ FUNC_MSG_OUT;
9938
+ return 0;
9939
+}
9940
+int getCOSDSCPBaseDSCP(void *cdata, int len)
9941
+{
9942
+ u8 entryno;
9943
+ FUNC_MSG_IN;
9944
+ if (sizeof(struct qos_dscp_setting) != len)
9945
+ {
9946
+ ip1811drv_err("Error: length=%d\n", len);
9947
+ return -EINVAL;
9948
+ }
9949
+ entryno = ((struct qos_dscp_setting *)cdata) ->dscpentry;
9950
+ if(entryno>7)
9951
+ {
9952
+ ip1811drv_err("Error: entryno=%d\n", entryno);
9953
+ return -EINVAL;
9954
+ }
9955
+ ((struct qos_dscp_setting *)cdata) ->dscpvalue = (u16)_ReadRegBits(0, P0REG_COSDSCPVALUE0+(entryno/2), (entryno%2)*5, 6);
9956
+ ((struct qos_dscp_setting *)cdata) ->dscpqueue = (u16)_ReadRegBits(0, P0REG_COSDSCPPRISETTING0+(entryno/5), (entryno%5)*3, 3);
9957
+ ip1811drv_dbg("cdata ->dscpvalue=0x%04X\n", ((struct qos_dscp_setting *)cdata) ->dscpvalue);
9958
+ ip1811drv_dbg("cdata ->dscpqueue=0x%04X\n", ((struct qos_dscp_setting *)cdata) ->dscpqueue);
9959
+ FUNC_MSG_OUT;
9960
+
9961
+ return 0;
9962
+}
9963
+int setCOSDSCPBaseNoMatchAction(void *cdata, int len)
9964
+{
9965
+ int ret;
9966
+ FUNC_MSG_IN;
9967
+ ret = _setGeneralEnable(cdata, len, 0, P0REG_COSDSCPPRISETTING1, 9);
9968
+ FUNC_MSG_OUT;
9969
+ return ret;
9970
+}
9971
+int getCOSDSCPBaseNoMatchAction(void *cdata, int len)
9972
+{
9973
+ int ret;
9974
+ FUNC_MSG_IN;
9975
+ ret = _getGeneralEnable(cdata, len, 0, P0REG_COSDSCPPRISETTING1, 9);
9976
+ FUNC_MSG_OUT;
9977
+ return ret;
9978
+}
9979
+int setQOSmodeGroupMember(void *cdata, int len)
9980
+{
9981
+ int ret;
9982
+ FUNC_MSG_IN;
9983
+ ret = _setPortmap(cdata, len, 8, P8REG_QOSGROUPSEL);
9984
+ FUNC_MSG_OUT;
9985
+ return ret;
9986
+}
9987
+int getQOSmodeGroupMember(void *cdata, int len)
9988
+{
9989
+ int ret;
9990
+ FUNC_MSG_IN;
9991
+ ret = _getPortmap(cdata, len, 8, P8REG_QOSGROUPSEL);
9992
+ FUNC_MSG_OUT;
9993
+ return ret;
9994
+}
9995
+int setQOSGroupBEn(void *cdata, int len)
9996
+{
9997
+ int ret;
9998
+ FUNC_MSG_IN;
9999
+ ret = _setGeneralEnable(cdata, len, 8, P8REG_QOSMODESELGROUP2, 9);
10000
+ FUNC_MSG_OUT;
10001
+ return ret;
10002
+}
10003
+int getQOSGroupBEn(void *cdata, int len)
10004
+{
10005
+ int ret;
10006
+ FUNC_MSG_IN;
10007
+ ret = _getGeneralEnable(cdata, len, 8, P8REG_QOSMODESELGROUP2, 9);
10008
+ FUNC_MSG_OUT;
10009
+ return ret;
10010
+}
10011
+int setQOSMode(void *cdata, int len)
10012
+{
10013
+ int gpnum,mode;
10014
+ FUNC_MSG_IN;
10015
+ if (sizeof(struct qos_modesettings) != len)
10016
+ {
10017
+ ip1811drv_err("Error: length=%d\n", len);
10018
+ return -EINVAL;
10019
+ }
10020
+ gpnum = ((struct qos_modesettings *)cdata) ->groupnum;
10021
+ mode = ((struct qos_modesettings *)cdata) ->modesettings;
10022
+ if(gpnum!=OP_QOS_GROUP1 && gpnum!=OP_QOS_GROUP2)
10023
+ {
10024
+ ip1811drv_err("Error: gpnum=%d\n", gpnum);
10025
+ return -EINVAL;
10026
+ }
10027
+ if(mode<OP_QOS_MODE_FIFO || mode>OP_QOS_MODE_SP8)
10028
+ {
10029
+ ip1811drv_err("Error: mode=%d\n", mode);
10030
+ return -EINVAL;
10031
+ }
10032
+ _WriteRegBits(8, (gpnum==OP_QOS_GROUP1)?P8REG_QOSMODESELGROUP1:P8REG_QOSMODESELGROUP2, 0, 3, mode);
10033
+
10034
+ FUNC_MSG_OUT;
10035
+ return 0;
10036
+}
10037
+int getQOSMode(void *cdata, int len)
10038
+{
10039
+ int gpnum;
10040
+ FUNC_MSG_IN;
10041
+ if (sizeof(struct qos_modesettings) != len)
10042
+ {
10043
+ ip1811drv_err("Error: length=%d\n", len);
10044
+ return -EINVAL;
10045
+ }
10046
+ gpnum = ((struct qos_modesettings *)cdata) ->groupnum;
10047
+ if(gpnum!=OP_QOS_GROUP1 && gpnum!=OP_QOS_GROUP2)
10048
+ {
10049
+ ip1811drv_err("Error: gpnum=%d\n", gpnum);
10050
+ return -EINVAL;
10051
+ }
10052
+
10053
+ ((struct qos_modesettings *)cdata) ->modesettings= (int)_ReadRegBits(8,(gpnum==OP_QOS_GROUP1)?P8REG_QOSMODESELGROUP1:P8REG_QOSMODESELGROUP2, 0, 3);
10054
+
10055
+ ip1811drv_dbg("cdata ->groupnum=0x%04X\n", ((struct qos_modesettings *)cdata) ->groupnum);
10056
+ ip1811drv_dbg("cdata ->modesettings=0x%04X\n", ((struct qos_modesettings *)cdata) ->modesettings);
10057
+ FUNC_MSG_OUT;
10058
+
10059
+ return 0;
10060
+}
10061
+int setQOSMethod(void *cdata, int len)
10062
+{
10063
+ int gpnum,mode;
10064
+ u16 u16dat;
10065
+ FUNC_MSG_IN;
10066
+ if (sizeof(struct qos_modesettings) != len)
10067
+ {
10068
+ ip1811drv_err("Error: length=%d\n", len);
10069
+ return -EINVAL;
10070
+ }
10071
+ gpnum = ((struct qos_modesettings *)cdata) ->groupnum;
10072
+ mode = ((struct qos_modesettings *)cdata) ->modesettings;
10073
+ if(gpnum!=OP_QOS_GROUP1 && gpnum!=OP_QOS_GROUP2)
10074
+ {
10075
+ ip1811drv_err("Error: gpnum=%d\n", gpnum);
10076
+ return -EINVAL;
10077
+ }
10078
+ if(mode<OP_QOS_METHOD_WRR || mode>OP_QOS_METHOD_TWRR)
10079
+ {
10080
+ ip1811drv_err("Error: mode=%d\n", mode);
10081
+ return -EINVAL;
10082
+ }
10083
+ IP2Page(8);
10084
+
10085
+ u16dat = Read_Reg((gpnum==OP_QOS_GROUP1)?P8REG_QOSMODESELGROUP1:P8REG_QOSMODESELGROUP2);
10086
+ u16dat &= 0xFF9F;
10087
+ switch(mode)
10088
+ {
10089
+ case OP_QOS_METHOD_WRR:
10090
+ break;
10091
+ case OP_QOS_METHOD_BW:
10092
+ u16dat |= ((u16)0x1<<5);
10093
+ break;
10094
+ case OP_QOS_METHOD_WFQ:
10095
+ u16dat |= ((u16)0x2<<5);
10096
+ break;
10097
+ case OP_QOS_METHOD_TWRR:
10098
+ u16dat |= ((u16)0x3<<5);
10099
+ break;
10100
+ }
10101
+ Write_Reg((gpnum==OP_QOS_GROUP1)?P8REG_QOSMODESELGROUP1:P8REG_QOSMODESELGROUP2,u16dat);
10102
+
10103
+
10104
+ if(mode==OP_QOS_METHOD_BW)
10105
+ Write_Reg(P8REG_QOSMODESELGROUP1,Read_Reg(P8REG_QOSMODESELGROUP1)|0x8000);//stop & hold pkt
10106
+ else
10107
+ Write_Reg(P8REG_QOSMODESELGROUP1,Read_Reg(P8REG_QOSMODESELGROUP1)&0x7FFF);
10108
+
10109
+ ip1811drv_dbg("cdata ->groupnum=0x%04X\n", ((struct qos_modesettings *)cdata) ->groupnum);
10110
+ ip1811drv_dbg("cdata ->modesettings=0x%04X\n", ((struct qos_modesettings *)cdata) ->modesettings);
10111
+ FUNC_MSG_OUT;
10112
+ return 0;
10113
+}
10114
+int getQOSMethod(void *cdata, int len)
10115
+{
10116
+ int gpnum;
10117
+ u16 u16dat;
10118
+ FUNC_MSG_IN;
10119
+ if (sizeof(struct qos_modesettings) != len)
10120
+ {
10121
+ ip1811drv_err("Error: length=%d\n", len);
10122
+ return -EINVAL;
10123
+ }
10124
+ gpnum = ((struct qos_modesettings *)cdata) ->groupnum;
10125
+ if(gpnum!=OP_QOS_GROUP1 && gpnum!=OP_QOS_GROUP2)
10126
+ {
10127
+ ip1811drv_err("Error: gpnum=%d\n", gpnum);
10128
+ return -EINVAL;
10129
+ }
10130
+
10131
+ u16dat = _ReadRegBits(8, (gpnum==OP_QOS_GROUP1)?P8REG_QOSMODESELGROUP1:P8REG_QOSMODESELGROUP2, 5, 3);
10132
+
10133
+ ((struct qos_modesettings *)cdata) ->modesettings = u16dat;
10134
+
10135
+ ip1811drv_dbg("cdata ->groupnum=0x%04X\n", ((struct qos_modesettings *)cdata) ->groupnum);
10136
+ ip1811drv_dbg("cdata ->modesettings=0x%04X\n", ((struct qos_modesettings *)cdata) ->modesettings);
10137
+ FUNC_MSG_OUT;
10138
+ return 0;
10139
+}
10140
+int setQOSWeight(void *cdata, int len)
10141
+{
10142
+ int gpnum,mode,queue;
10143
+ FUNC_MSG_IN;
10144
+ if (sizeof(struct qos_modesettings) != len)
10145
+ {
10146
+ ip1811drv_err("Error: length=%d\n", len);
10147
+ return -EINVAL;
10148
+ }
10149
+ gpnum = ((struct qos_modesettings *)cdata) ->groupnum;
10150
+ queue = ((struct qos_modesettings *)cdata) ->queuenum;
10151
+ mode = ((struct qos_modesettings *)cdata) ->modesettings;
10152
+ if(gpnum!=OP_QOS_GROUP1 && gpnum!=OP_QOS_GROUP2)
10153
+ {
10154
+ ip1811drv_err("Error: gpnum=%d\n", gpnum);
10155
+ return -EINVAL;
10156
+ }
10157
+ if(queue<OP_QOS_NUM_Q0 || queue>OP_QOS_NUM_Q7)
10158
+ {
10159
+ ip1811drv_err("Error: queue=%d\n", queue);
10160
+ return -EINVAL;
10161
+ }
10162
+ if(mode & ~(int)0xff)
10163
+ {
10164
+ ip1811drv_err("Error: mode=%d\n", mode);
10165
+ return -EINVAL;
10166
+ }
10167
+
10168
+ _WriteRegBits(8, (gpnum==OP_QOS_GROUP1)?(P8REG_QOSGP1_WEIGHT0+(queue/2)):(P8REG_QOSGP2_WEIGHT0+(queue/2)), (queue%2)*8, 8, mode);
10169
+
10170
+ FUNC_MSG_OUT;
10171
+ return 0;
10172
+}
10173
+int getQOSWeight(void *cdata, int len)
10174
+{
10175
+ int gpnum,queue;
10176
+ u16 u16dat;
10177
+ FUNC_MSG_IN;
10178
+ if (sizeof(struct qos_modesettings) != len)
10179
+ {
10180
+ ip1811drv_err("Error: length=%d\n", len);
10181
+ return -EINVAL;
10182
+ }
10183
+ gpnum = ((struct qos_modesettings *)cdata) ->groupnum;
10184
+ queue = ((struct qos_modesettings *)cdata) ->queuenum;
10185
+ if(gpnum!=OP_QOS_GROUP1 && gpnum!=OP_QOS_GROUP2)
10186
+ {
10187
+ ip1811drv_err("Error: gpnum=%d\n", gpnum);
10188
+ return -EINVAL;
10189
+ }
10190
+ u16dat = _ReadRegBits(8,(gpnum==OP_QOS_GROUP1)?(P8REG_QOSGP1_WEIGHT0+(queue/2)):(P8REG_QOSGP2_WEIGHT0+(queue/2)), ((queue%2)*8), 8);
10191
+
10192
+ ((struct qos_modesettings *)cdata) ->modesettings=(int)u16dat;
10193
+
10194
+ ip1811drv_dbg("cdata ->groupnum=0x%04X\n", ((struct qos_modesettings *)cdata) ->groupnum);
10195
+ ip1811drv_dbg("cdata ->queuenum=0x%04X\n", ((struct qos_modesettings *)cdata) ->queuenum);
10196
+ ip1811drv_dbg("cdata ->modesettings=0x%04X\n", ((struct qos_modesettings *)cdata) ->modesettings);
10197
+ FUNC_MSG_OUT;
10198
+
10199
+ return 0;
10200
+}
10201
+int setQOSMaxBandwidth(void *cdata, int len)
10202
+{
10203
+ int gpnum,mode,queue;
10204
+ FUNC_MSG_IN;
10205
+ if (sizeof(struct qos_modesettings) != len)
10206
+ {
10207
+ ip1811drv_err("Error: length=%d\n", len);
10208
+ return -EINVAL;
10209
+ }
10210
+ gpnum = ((struct qos_modesettings *)cdata) ->groupnum;
10211
+ queue = ((struct qos_modesettings *)cdata) ->queuenum;
10212
+ mode = ((struct qos_modesettings *)cdata) ->modesettings;
10213
+ if(gpnum!=OP_QOS_GROUP1 && gpnum!=OP_QOS_GROUP2)
10214
+ {
10215
+ ip1811drv_err("Error: gpnum=%d\n", gpnum);
10216
+ return -EINVAL;
10217
+ }
10218
+ if(queue<OP_QOS_NUM_Q0 || queue>OP_QOS_NUM_Q7)
10219
+ {
10220
+ ip1811drv_err("Error: queue=%d\n", queue);
10221
+ return -EINVAL;
10222
+ }
10223
+ if(mode & ~(int)0xff)
10224
+ {
10225
+ ip1811drv_err("Error: mode=%d\n", mode);
10226
+ return -EINVAL;
10227
+ }
10228
+
10229
+ _WriteRegBits(8, (gpnum==OP_QOS_GROUP1)?(P8REG_QOSGP1_MAXBDWT0+(queue/2)):(P8REG_QOSGP2_MAXBDWT0+(queue/2)), (queue%2)*8, 8, mode);
10230
+
10231
+ FUNC_MSG_OUT;
10232
+ return 0;
10233
+}
10234
+
10235
+int getQOSMaxBandwidth(void *cdata, int len)
10236
+{
10237
+ int gpnum,queue;
10238
+ u16 u16dat;
10239
+ FUNC_MSG_IN;
10240
+ if (sizeof(struct qos_modesettings) != len)
10241
+ {
10242
+ ip1811drv_err("Error: length=%d\n", len);
10243
+ return -EINVAL;
10244
+ }
10245
+ gpnum = ((struct qos_modesettings *)cdata) ->groupnum;
10246
+ queue = ((struct qos_modesettings *)cdata) ->queuenum;
10247
+ if(gpnum!=OP_QOS_GROUP1 && gpnum!=OP_QOS_GROUP2)
10248
+ {
10249
+ ip1811drv_err("Error: gpnum=%d\n", gpnum);
10250
+ return -EINVAL;
10251
+ }
10252
+ if(queue<OP_QOS_NUM_Q0 || queue>OP_QOS_NUM_Q7)
10253
+ {
10254
+ ip1811drv_err("Error: queue=%d\n", queue);
10255
+ return -EINVAL;
10256
+ }
10257
+
10258
+ u16dat = _ReadRegBits(8, (gpnum==OP_QOS_GROUP1)?(P8REG_QOSGP1_MAXBDWT0+(queue/2)):(P8REG_QOSGP2_MAXBDWT0+(queue/2)), ((queue%2)*8), 8);
10259
+
10260
+ ((struct qos_modesettings *)cdata) ->modesettings=(int)u16dat;
10261
+
10262
+ ip1811drv_dbg("cdata ->groupnum=0x%04X\n", ((struct qos_modesettings *)cdata) ->groupnum);
10263
+ ip1811drv_dbg("cdata ->queuenum=0x%04X\n", ((struct qos_modesettings *)cdata) ->queuenum);
10264
+ ip1811drv_dbg("cdata ->modesettings=0x%04X\n", ((struct qos_modesettings *)cdata) ->modesettings);
10265
+ FUNC_MSG_OUT;
10266
+
10267
+ return 0;
10268
+}
10269
+int setQOSUnit(void *cdata, int len)
10270
+{
10271
+ int gpnum,mode;
10272
+ FUNC_MSG_IN;
10273
+ if (sizeof(struct qos_modesettings) != len)
10274
+ {
10275
+ ip1811drv_err("Error: length=%d\n", len);
10276
+ return -EINVAL;
10277
+ }
10278
+ gpnum = ((struct qos_modesettings *)cdata) ->groupnum;
10279
+ mode = ((struct qos_modesettings *)cdata) ->modesettings;
10280
+ if(gpnum!=OP_QOS_GROUP1 && gpnum!=OP_QOS_GROUP2)
10281
+ {
10282
+ ip1811drv_err("Error: gpnum=%d\n", gpnum);
10283
+ return -EINVAL;
10284
+ }
10285
+ if(mode<OP_QOS_UNIT_64KBS || mode>OP_QOS_UNIT_4MBS)
10286
+ {
10287
+ ip1811drv_err("Error: mode=%d\n", mode);
10288
+ return -EINVAL;
10289
+ }
10290
+ _WriteRegBits(8, (gpnum==OP_QOS_GROUP1)?(P8REG_QOSMODESELGROUP1):(P8REG_QOSMODESELGROUP2), 3, 2, mode);
10291
+
10292
+ FUNC_MSG_OUT;
10293
+ return 0;
10294
+}
10295
+int getQOSUnit(void *cdata, int len)
10296
+{
10297
+ int gpnum;
10298
+ FUNC_MSG_IN;
10299
+ if (sizeof(struct qos_modesettings) != len)
10300
+ {
10301
+ ip1811drv_err("Error: lengtn=%d\n", len);
10302
+ return -EINVAL;
10303
+ }
10304
+ gpnum = ((struct qos_modesettings *)cdata) ->groupnum;
10305
+ if(gpnum!=OP_QOS_GROUP1 && gpnum!=OP_QOS_GROUP2)
10306
+ {
10307
+ ip1811drv_err("Error: gpnum=%d\n", gpnum);
10308
+ return -EINVAL;
10309
+ }
10310
+
10311
+ ((struct qos_modesettings *)cdata) ->modesettings= (int)_ReadRegBits(8,(gpnum==OP_QOS_GROUP1)?P8REG_QOSMODESELGROUP1:P8REG_QOSMODESELGROUP2, 3, 2);
10312
+
10313
+ ip1811drv_dbg("cdata ->groupnum=0x%04X\n", ((struct qos_modesettings *)cdata) ->groupnum);
10314
+ ip1811drv_dbg("cdata ->modesettings=0x%04X\n", ((struct qos_modesettings *)cdata) ->modesettings);
10315
+ FUNC_MSG_OUT;
10316
+ return 0;
10317
+}
10318
+int setQOSRatioValue0Def(void *cdata, int len)
10319
+{
10320
+ int ret;
10321
+ FUNC_MSG_IN;
10322
+ ret = _setGeneralEnable(cdata, len, 8, P8REG_QOSMODESELGROUP1, 15);
10323
+ FUNC_MSG_OUT;
10324
+ return ret;
10325
+}
10326
+int getQOSRatioValue0Def(void *cdata, int len)
10327
+{
10328
+ int ret;
10329
+ FUNC_MSG_IN;
10330
+ ret = _getGeneralEnable(cdata, len, 8, P8REG_QOSMODESELGROUP1, 15);
10331
+ FUNC_MSG_OUT;
10332
+ return ret;
10333
+}
10334
+int setQOSSBMDBM(void *cdata, int len)
10335
+{
10336
+ int port,mode;
10337
+ u16 u16dat;
10338
+ FUNC_MSG_IN;
10339
+ if (sizeof(struct ByPortSetting) != len)
10340
+ {
10341
+ ip1811drv_err("Error: length=%d\n", len);
10342
+ return -EINVAL;
10343
+ }
10344
+ port = ((struct ByPortSetting *)cdata) ->port;
10345
+ mode = ((struct ByPortSetting *)cdata) ->pdata;
10346
+ if(port < 0 || port >= MAX_PHY_NUM)
10347
+ return -EINVAL;
10348
+ if(mode!=OP_QOS_QBASE_DBM && mode!=OP_QOS_QBASE_SBM)
10349
+ {
10350
+ ip1811drv_err("Error: mode=%d\n", mode);
10351
+ return -EINVAL;
10352
+ }
10353
+ ip1811drv_dbg(" port=%d\n", port);
10354
+ ip1811drv_dbg(" mode=%d\n", mode);
10355
+
10356
+ IP2Page(8);
10357
+
10358
+ // set all queue(per port) to same mode
10359
+ u16dat=Read_Reg(P8REG_QOS_SBMDBMSEL0+(port/2));
10360
+ u16dat&=((port%2)?0x00FF:0xFF00);
10361
+ if(mode==OP_QOS_QBASE_SBM)
10362
+ { u16dat|=((port%2)?0xFF00:0x00FF); }
10363
+ Write_Reg(P8REG_QOS_SBMDBMSEL0+(port/2),u16dat);
10364
+#ifdef COMBINED_PORT
10365
+ if (port==9){
10366
+ u16dat=Read_Reg(P8REG_QOS_SBMDBMSEL0+((port+1)/2));
10367
+ u16dat&=(((port+1)%2)?0x00FF:0xFF00);
10368
+ if(mode==OP_QOS_QBASE_SBM)
10369
+ { u16dat|=(((port+1)%2)?0xFF00:0x00FF); }
10370
+ Write_Reg(P8REG_QOS_SBMDBMSEL0+((port+1)/2),u16dat);
10371
+ }
10372
+#endif
10373
+
10374
+ FUNC_MSG_OUT;
10375
+ return 0;
10376
+}
10377
+int getQOSSBMDBM(void *cdata, int len)
10378
+{
10379
+ int port;
10380
+ u16 u16dat;
10381
+ FUNC_MSG_IN;
10382
+ if (sizeof(struct ByPortSetting) != len)
10383
+ {
10384
+ ip1811drv_err("Error: length=%d\n", len);
10385
+ return -EINVAL;
10386
+ }
10387
+ port = ((struct ByPortSetting *)cdata) ->port;
10388
+ if(port<0 || port>=MAX_PHY_NUM)
10389
+ return -EINVAL;
10390
+
10391
+ IP2Page(8);
10392
+#ifdef COMBINED_PORT
10393
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
10394
+ port++;
10395
+#endif
10396
+ u16dat=Read_Reg(P8REG_QOS_SBMDBMSEL0+(port/2));
10397
+ u16dat>>=((port%2)*8);
10398
+ if(u16dat&0xff)
10399
+ { ((struct ByPortSetting *)cdata) ->pdata=OP_QOS_QBASE_SBM; }
10400
+ else
10401
+ { ((struct ByPortSetting *)cdata) ->pdata=OP_QOS_QBASE_DBM; }
10402
+
10403
+ ip1811drv_dbg("cdata ->port=0x%d\n", ((struct ByPortSetting *)cdata) ->port);
10404
+ ip1811drv_dbg("cdata ->pdata=0x%d\n", ((struct ByPortSetting *)cdata) ->pdata);
10405
+ FUNC_MSG_OUT;
10406
+
10407
+ return 0;
10408
+}
10409
+int setQOSDBMEn(void *cdata, int len)
10410
+{
10411
+ int ret;
10412
+ FUNC_MSG_IN;
10413
+ ret = _setPortmap(cdata, len, 8, P8REG_QOSQUEUEDBMEN);
10414
+ FUNC_MSG_IN;
10415
+ return ret;
10416
+}
10417
+int getQOSDBMEn(void *cdata, int len)
10418
+{
10419
+ int ret;
10420
+ FUNC_MSG_IN;
10421
+ ret = _getPortmap(cdata, len, 8, P8REG_QOSQUEUEDBMEN);
10422
+ FUNC_MSG_IN;
10423
+ return ret;
10424
+}
10425
+int setQOSRemap(void *cdata, int len)
10426
+{
10427
+ int port;
10428
+ u8 queue,remap;
10429
+ u16 u16dat;
10430
+ FUNC_MSG_IN;
10431
+ if (sizeof(struct qos_remap) != len)
10432
+ {
10433
+ ip1811drv_err("Error: length=%d\n", len);
10434
+ return -EINVAL;
10435
+ }
10436
+ port = ((struct qos_remap *)cdata) ->port;
10437
+ queue = ((struct qos_remap *)cdata) ->queue;
10438
+ remap = ((struct qos_remap *)cdata) ->remap;
10439
+
10440
+ if(port<0 || port>=MAX_PHY_NUM)
10441
+ return -EINVAL;
10442
+ if(queue>OP_QOS_REMAP_TX_Q7)
10443
+ {
10444
+ ip1811drv_err("Error: queue=%d\n", queue);
10445
+ return -EINVAL;
10446
+ }
10447
+ if(remap>7)
10448
+ {
10449
+ ip1811drv_err("Error: remap=%d\n", remap);
10450
+ return -EINVAL;
10451
+ }
10452
+ ip1811drv_dbg("cdata ->port=0x%d\n", ((struct qos_remap *)cdata) ->port);
10453
+ ip1811drv_dbg("cdata ->queue=0x%d\n", ((struct qos_remap *)cdata) ->queue);
10454
+ ip1811drv_dbg("cdata ->remap=0x%d\n", ((struct qos_remap *)cdata) ->remap);
10455
+
10456
+ if(queue<=OP_QOS_REMAP_RX_Q7)//RX
10457
+ {
10458
+ if ((queue/5) == 0)
10459
+ {
10460
+ IP2Page(6);
10461
+ u16dat = Read_Reg(P6REG_QOS_REMAP_RX0+(port*2)+1);
10462
+ }
10463
+ _WriteRegBits(6, P6REG_QOS_REMAP_RX0+(port*2)+(queue/5), (queue%5)*3, 3, remap);
10464
+ if ((queue/5) == 0)
10465
+ {
10466
+ IP2Page(6);
10467
+ Write_Reg(P6REG_QOS_REMAP_RX0+(port*2)+1, u16dat);
10468
+ }
10469
+#ifdef COMBINED_PORT
10470
+ if (port==9)
10471
+ {
10472
+ if ((queue/5) == 0)
10473
+ {
10474
+ IP2Page(6);
10475
+ u16dat = Read_Reg(P6REG_QOS_REMAP_RX0+((port+1)*2)+1);
10476
+ }
10477
+ _WriteRegBits(6, P6REG_QOS_REMAP_RX0+((port+1)*2)+(queue/5), (queue%5)*3, 3, remap);
10478
+ if ((queue/5) == 0)
10479
+ {
10480
+ IP2Page(6);
10481
+ Write_Reg(P6REG_QOS_REMAP_RX0+((port+1)*2)+1, u16dat);
10482
+ }
10483
+ }
10484
+#endif
10485
+ }
10486
+ else//TX
10487
+ {
10488
+ queue-=8;
10489
+ if (port == 0)
10490
+ {
10491
+ _WriteRegBits(8, P8REG_QOS_REMAP_TX0+(port*2)+(queue/5), (queue%5)*3, 3, remap);
10492
+ }
10493
+ else if (port == 1)
10494
+ {
10495
+ if (queue / 5)
10496
+ _WriteRegBits(8, P8REG_QOS_REMAP_TX0+(port*2)+(queue/5)+1, (queue%5)*3, 3, remap);
10497
+ else
10498
+ _WriteRegBits(8, P8REG_QOS_REMAP_TX0+(port*2)+(queue/5), (queue%5)*3, 3, remap);
10499
+ }
10500
+ else
10501
+ {
10502
+ _WriteRegBits(8, P8REG_QOS_REMAP_TX0+(port*2)+(queue/5)+1, (queue%5)*3, 3, remap);
10503
+#ifdef COMBINED_PORT
10504
+ if (port==9)
10505
+ _WriteRegBits(8, P8REG_QOS_REMAP_TX0+((port+1)*2)+(queue/5)+1, (queue%5)*3, 3, remap);
10506
+#endif
10507
+ }
10508
+ }
10509
+ FUNC_MSG_OUT;
10510
+ return 0;
10511
+}
10512
+int getQOSRemap(void *cdata, int len)
10513
+{
10514
+ int port;
10515
+ u8 queue;
10516
+ u16 u16dat;
10517
+ FUNC_MSG_IN;
10518
+ if (sizeof(struct qos_remap) != len)
10519
+ {
10520
+ ip1811drv_err("Error: length=%d\n", len);
10521
+ return -EINVAL;
10522
+ }
10523
+ port = ((struct qos_remap *)cdata) ->port;
10524
+ queue = ((struct qos_remap *)cdata) ->queue;
10525
+ if(port<0 || port>=MAX_PHY_NUM)
10526
+ return -EINVAL;
10527
+ if(queue>OP_QOS_REMAP_TX_Q7)
10528
+ {
10529
+ ip1811drv_err("Error: queue=%d\n", queue);
10530
+ return -EINVAL;
10531
+ }
10532
+ ip1811drv_dbg("cdata ->port=0x%d\n", ((struct qos_remap *)cdata) ->port);
10533
+ ip1811drv_dbg("cdata ->queue=0x%d\n", ((struct qos_remap *)cdata) ->queue);
10534
+
10535
+#ifdef COMBINED_PORT
10536
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
10537
+ port++;
10538
+#endif
10539
+ if(queue<=OP_QOS_REMAP_RX_Q7)//RX
10540
+ {
10541
+ IP2Page(6);
10542
+ u16dat = Read_Reg(P6REG_QOS_REMAP_RX0+(port*2)+(queue/5));
10543
+ }
10544
+ else//TX
10545
+ {
10546
+ queue-=8;
10547
+ IP2Page(8);
10548
+ if (port == 0)
10549
+ {
10550
+ u16dat = Read_Reg(P8REG_QOS_REMAP_TX0+(port*2)+(queue/5));
10551
+ }
10552
+ else if (port == 1)
10553
+ {
10554
+ if (queue / 5)
10555
+ u16dat = Read_Reg(P8REG_QOS_REMAP_TX0+(port*2)+(queue/5)+1);
10556
+ else
10557
+ u16dat = Read_Reg(P8REG_QOS_REMAP_TX0+(port*2)+(queue/5));
10558
+ }
10559
+ else
10560
+ {
10561
+ u16dat = Read_Reg(P8REG_QOS_REMAP_TX0+(port*2)+(queue/5)+1);
10562
+ }
10563
+ }
10564
+ ((struct qos_remap *)cdata) ->remap = (u8)((u16dat>>((queue%5)*3))&0x7);
10565
+
10566
+ ip1811drv_dbg("cdata ->remap=0x%d\n", ((struct qos_remap *)cdata) ->remap);
10567
+ FUNC_MSG_OUT;
10568
+ return 0;
10569
+}
10570
+//------------ QOS functions:ip1811 end--------------------------
10571
+
10572
+//------------ ACL functions:common ----------------------------
10573
+struct acl_man *m_acl; // acl golbal manage variable
10574
+int acl_write_table_0010(int block, int index, int link, struct acl_rule *r);
10575
+int acl_write_table_0100(int block, int index, int link, struct acl_rule *r);
10576
+int acl_write_table_0101(int block, int index, int link, struct acl_rule *r);
10577
+int acl_write_table_0110(int block, int index, int link, struct acl_rule *r);
10578
+int acl_write_table_0111(int block, int index, int link, struct acl_rule *r);
10579
+int acl_write_table_1x00(int block, int index, int link, struct acl_rule *r);
10580
+int acl_write_table_1x01(int block, int index, int link, struct acl_rule *r);
10581
+int acl_write_table_1x10(int block, int index, int link, struct acl_rule *r);
10582
+int acl_write_table_1x11(int block, int index, int link, struct acl_rule *r);
10583
+int (*acl_write_table_rule[])(int block, int index, int link, struct acl_rule *r) = {
10584
+ NULL,
10585
+ acl_write_table_0010,
10586
+ NULL,
10587
+ acl_write_table_0100,
10588
+ acl_write_table_0101,
10589
+ acl_write_table_0110,
10590
+ acl_write_table_0111,
10591
+ acl_write_table_1x00,
10592
+ acl_write_table_1x01,
10593
+ acl_write_table_1x10,
10594
+ acl_write_table_1x11
10595
+};
10596
+int acl_write_table_drop(int block, int index, int is_link, struct acl_rule *r);
10597
+int acl_write_table_a1(int block, int index, int is_link, struct acl_rule *r);
10598
+int acl_write_table_a2(int block, int index, int is_link, struct acl_rule *r);
10599
+int acl_write_table_a3(int block, int index, int is_link, struct acl_rule *r);
10600
+int (*acl_write_table_act[])(int block, int index, int is_link, struct acl_rule *r) = {
10601
+ acl_write_table_drop,
10602
+ acl_write_table_a1,
10603
+ acl_write_table_a2,
10604
+ acl_write_table_a3
10605
+};
10606
+
10607
+int set_rule_index_remap(void);
10608
+
10609
+void acl_init(void)
10610
+{
10611
+ int i;
10612
+ ip1811drv_dbg("<DBG_DR_ACL> acl_init()\n");
10613
+
10614
+ m_acl = kmalloc(sizeof(struct acl_man), GFP_KERNEL);
10615
+ if(m_acl == NULL)
10616
+ {
10617
+ ip1811drv_err("Error: acl_init() acl_man malloc failed.\n");
10618
+ return;
10619
+ }
10620
+
10621
+ INIT_LIST_HEAD(&m_acl ->rule_list);
10622
+ m_acl ->num_used_rules = 0;
10623
+ m_acl ->num_used_entries = 0;
10624
+ for(i=0; i<4; i++)
10625
+ {
10626
+ m_acl ->used_entry_mask[i] = 0;
10627
+ }
10628
+}
10629
+
10630
+int acl_find_index(int num, int *block, int *index, int find_idx_blockn, int find_idx_rvs)
10631
+{
10632
+ int i=0, j=0;
10633
+ unsigned char m = 0;
10634
+ unsigned long t = 0;
10635
+
10636
+ for(i=0; i<num; i++) {
10637
+ m |= BIT(i);
10638
+ }
10639
+
10640
+ for(i=0; i<4; i++) {
10641
+ t = (unsigned long)m_acl ->used_entry_mask[(find_idx_blockn+i)%4];
10642
+ if(find_idx_rvs) { // find index in reverse
10643
+ for(j=15; j>=0; j--) {
10644
+ if((16-j) < num) // empty entry is not enough, find next block
10645
+ break;
10646
+ if(!((t>>j) & m)) {
10647
+ *block = (i+find_idx_blockn)%4;
10648
+ *index = j;
10649
+ return 0;
10650
+ }
10651
+ }
10652
+ } else {
10653
+ for(j=0; j<16; j++) {
10654
+ if((16-j) < num) // empty entry is not enough, find next block
10655
+ break;
10656
+ if(!((t>>j) & m)) {
10657
+ *block = (i+find_idx_blockn)%4;
10658
+ *index = j;
10659
+ return 0;
10660
+ }
10661
+ }
10662
+ }
10663
+ }
10664
+
10665
+ return -ENOMEM;
10666
+}
10667
+
10668
+int acl_clean_table_rule(int block, int index)
10669
+{
10670
+ IP2Page(1);
10671
+
10672
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, 0);
10673
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, 0);
10674
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, 0);
10675
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
10676
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
10677
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
10678
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0);
10679
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, 0);
10680
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, 0);
10681
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, 0);
10682
+
10683
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
10684
+ return 0;
10685
+}
10686
+
10687
+int acl_clean_table_act(int block, int index)
10688
+{
10689
+ IP2Page(1);
10690
+
10691
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, 0);
10692
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, 0);
10693
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, 0);
10694
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
10695
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
10696
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
10697
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0);
10698
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, 0);
10699
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, 0);
10700
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, 0);
10701
+
10702
+ // act
10703
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC100|index|(block<<5));
10704
+ return 0;
10705
+}
10706
+
10707
+int acl_clean_table(int block, int index)
10708
+{
10709
+ acl_clean_table_rule(block, index);
10710
+ acl_clean_table_act(block, index);
10711
+ return 0;
10712
+}
10713
+
10714
+int acl_write_table_0010(int block, int index, int link, struct acl_rule *r)
10715
+{
10716
+ u16 tmp=0;
10717
+
10718
+ IP2Page(1);
10719
+
10720
+ /* Set user define location D3 and D4 */
10721
+ if(r->location1)
10722
+ Write_Reg(P1REG_ACL_PATTEM_LOCATION_D3, r->location1);
10723
+ if(r->location2)
10724
+ Write_Reg(P1REG_ACL_PATTEM_LOCATION_D4, r->location2);
10725
+
10726
+ /* E1 ~ E8 */
10727
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, r->usr0);
10728
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, r->mask0);
10729
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, r->usr1);
10730
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, r->mask1);
10731
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, r->usr2);
10732
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, r->mask2);
10733
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, r->usr3);
10734
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, r->mask3);
10735
+
10736
+ //E9
10737
+ if(r->rule_valid & ACL_RULE_VALID_INGRESS_PORT) {
10738
+ tmp |= r->ingress_port+1;
10739
+ }
10740
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, tmp);
10741
+
10742
+ //EA
10743
+ tmp=ACL_SELECT_MODE_0010<<6;
10744
+ if(r->rule_rvs & ACL_RULE_RVS_INGRESS_PORT) {
10745
+ tmp |= 0x8;
10746
+ }
10747
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
10748
+
10749
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
10750
+ return 0;
10751
+}
10752
+
10753
+
10754
+int acl_write_table_0100(int block, int index, int link, struct acl_rule *r)
10755
+{
10756
+ u16 tmp = 0;
10757
+
10758
+ IP2Page(1);
10759
+ //E1 & E2
10760
+ if(r->rule_valid & ACL_RULE_VALID_SIP)
10761
+ {
10762
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, r->sip4_addr&0xFFFF);
10763
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, (r->sip4_addr>>16)&0xFFFF);
10764
+ tmp |= ((u16)(r->sip_mask&0xF)<<7);
10765
+ }
10766
+ else
10767
+ {
10768
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, 0);
10769
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, 0);
10770
+ tmp |= (0xF<<7); // any sip
10771
+ }
10772
+ //E3 & E4
10773
+ if(r->rule_valid & ACL_RULE_VALID_DP_R)
10774
+ {
10775
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, r->dp_lo);
10776
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, r->dp_hi);
10777
+ }
10778
+ else
10779
+ {
10780
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, 0);
10781
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
10782
+ tmp |= BIT(5);
10783
+ }
10784
+ //E5 & E6
10785
+ if(r->rule_valid & ACL_RULE_VALID_SP_R)
10786
+ {
10787
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, r->sp_lo);
10788
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, r->sp_hi);
10789
+ }
10790
+ else
10791
+ {
10792
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
10793
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
10794
+ tmp |= BIT(6);
10795
+ }
10796
+ //E7
10797
+ if(r->rule_valid & ACL_RULE_VALID_VLAN)
10798
+ {
10799
+ if(r->rule_valid & ACL_RULE_VALID_COS)
10800
+ {
10801
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan | (r->cos<<12)));
10802
+ }
10803
+ else
10804
+ {
10805
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan|0x8000));
10806
+ }
10807
+ }
10808
+ else
10809
+ {
10810
+ tmp |= (0x3<<11);
10811
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0x8000);
10812
+ }
10813
+ //E8
10814
+ tmp |= (0x3<<13);
10815
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, 0x8000);
10816
+ //E9
10817
+ if(r->rule_valid & ACL_RULE_VALID_INGRESS_PORT)
10818
+ {
10819
+ tmp |= r->ingress_port+1;
10820
+ }
10821
+ if(r->rule_rvs & ACL_RULE_RVS_SIP) {
10822
+ tmp |= 0x8000;
10823
+ }
10824
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, tmp);
10825
+ //EA
10826
+ tmp = ((ACL_SELECT_MODE_0100<<6) | (link<<4));
10827
+ if(r->rule_rvs & ACL_RULE_RVS_DP_R) {
10828
+ tmp |= 0x1;
10829
+ }
10830
+ if(r->rule_rvs & ACL_RULE_RVS_SP_R) {
10831
+ tmp |= 0x2;
10832
+ }
10833
+ if((r->rule_rvs&ACL_RULE_RVS_VLAN) && (r->rule_rvs&ACL_RULE_RVS_COS)) {
10834
+ tmp |= 0x4;
10835
+ }
10836
+ if(r->rule_rvs & ACL_RULE_RVS_INGRESS_PORT) {
10837
+ tmp |= 0x8;
10838
+ }
10839
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
10840
+
10841
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
10842
+ return 0;
10843
+}
10844
+
10845
+int acl_write_table_0101(int block, int index, int link, struct acl_rule *r)
10846
+{
10847
+ u16 tmp = 0;
10848
+
10849
+ IP2Page(1);
10850
+ //E1 & E2
10851
+ if(r->rule_valid & ACL_RULE_VALID_DIP)
10852
+ {
10853
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, r->dip4_addr&0xFFFF);
10854
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, (r->dip4_addr>>16)&0xFFFF);
10855
+ tmp |= ((u16)(r->dip_mask&0xF)<<7);
10856
+ }
10857
+ else
10858
+ {
10859
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, 0);
10860
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, 0);
10861
+ tmp |= (0xF<<7); // any dip
10862
+ }
10863
+ //E3 & E4
10864
+ if(r->rule_valid & ACL_RULE_VALID_DP_R)
10865
+ {
10866
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, r->dp_lo);
10867
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, r->dp_hi);
10868
+ }
10869
+ else
10870
+ {
10871
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, 0);
10872
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
10873
+ tmp |= BIT(5);
10874
+ }
10875
+ //E5 & E6
10876
+ if(r->rule_valid & ACL_RULE_VALID_SP_R)
10877
+ {
10878
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, r->sp_lo);
10879
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, r->sp_hi);
10880
+ }
10881
+ else
10882
+ {
10883
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
10884
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
10885
+ tmp |= BIT(6);
10886
+ }
10887
+ //E7
10888
+ if(r->rule_valid & ACL_RULE_VALID_VLAN)
10889
+ {
10890
+ if(r->rule_valid & ACL_RULE_VALID_COS)
10891
+ {
10892
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan | (r->cos<<12)));
10893
+ }
10894
+ else
10895
+ {
10896
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan|0x8000));
10897
+ }
10898
+ }
10899
+ else
10900
+ {
10901
+ tmp |= (0x3<<11);
10902
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0x8000);
10903
+ }
10904
+ //E8
10905
+ tmp |= (0x3<<13);
10906
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, 0x8000);
10907
+ //E9
10908
+ if(r->rule_valid & ACL_RULE_VALID_INGRESS_PORT)
10909
+ {
10910
+ tmp |= r->ingress_port+1;
10911
+ }
10912
+ if(r->rule_rvs & ACL_RULE_RVS_DIP) {
10913
+ tmp |= 0x8000;
10914
+ }
10915
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, tmp);
10916
+ //EA
10917
+ tmp = ((ACL_SELECT_MODE_0101<<6) | (link<<4));
10918
+ if(r->rule_rvs & ACL_RULE_RVS_DP_R) {
10919
+ tmp |= 0x1;
10920
+ }
10921
+ if(r->rule_rvs & ACL_RULE_RVS_SP_R) {
10922
+ tmp |= 0x2;
10923
+ }
10924
+ if((r->rule_rvs&ACL_RULE_RVS_VLAN) && (r->rule_rvs&ACL_RULE_RVS_COS)) {
10925
+ tmp |= 0x4;
10926
+ }
10927
+ if(r->rule_rvs & ACL_RULE_RVS_INGRESS_PORT) {
10928
+ tmp |= 0x8;
10929
+ }
10930
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
10931
+
10932
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
10933
+ return 0;
10934
+}
10935
+
10936
+int acl_write_table_0110(int block, int index, int link, struct acl_rule *r)
10937
+{
10938
+ u16 tmp = 0;
10939
+
10940
+ IP2Page(1);
10941
+ //E1 ~ E8
10942
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, r->sip6_addr16[7]);
10943
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, r->sip6_addr16[6]);
10944
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, r->sip6_addr16[5]);
10945
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, r->sip6_addr16[4]);
10946
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, r->sip6_addr16[3]);
10947
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, r->sip6_addr16[2]);
10948
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, r->sip6_addr16[1]);
10949
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, r->sip6_addr16[0]);
10950
+ //E9
10951
+ tmp |= ((u16)(r->sip_mask&0x3FF)<<5);
10952
+ if(r->rule_valid & ACL_RULE_VALID_INGRESS_PORT)
10953
+ {
10954
+ tmp |= r->ingress_port+1;
10955
+ }
10956
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, tmp);
10957
+ //EA
10958
+ tmp = ((ACL_SELECT_MODE_0110<<6) | (link<<4));
10959
+ if(r->rule_rvs & ACL_RULE_RVS_INGRESS_PORT) {
10960
+ tmp |= 0x8;
10961
+ }
10962
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
10963
+
10964
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
10965
+ return 0;
10966
+}
10967
+
10968
+int acl_write_table_0111(int block, int index, int link, struct acl_rule *r)
10969
+{
10970
+ u16 tmp = 0;
10971
+
10972
+ IP2Page(1);
10973
+ //E1 ~ E8
10974
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, r->dip6_addr16[7]);
10975
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, r->dip6_addr16[6]);
10976
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, r->dip6_addr16[5]);
10977
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, r->dip6_addr16[4]);
10978
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, r->dip6_addr16[3]);
10979
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, r->dip6_addr16[2]);
10980
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, r->dip6_addr16[1]);
10981
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, r->dip6_addr16[0]);
10982
+ //E9
10983
+ tmp |= ((u16)(r->dip_mask&0x3FF)<<5);
10984
+ if(r->rule_valid & ACL_RULE_VALID_INGRESS_PORT)
10985
+ {
10986
+ tmp |= r->ingress_port+1;
10987
+ }
10988
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, tmp);
10989
+ //EA
10990
+ tmp = ((ACL_SELECT_MODE_0111<<6) | (link<<4));
10991
+ if(r->rule_rvs & ACL_RULE_RVS_INGRESS_PORT) {
10992
+ tmp |= 0x8;
10993
+ }
10994
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
10995
+
10996
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
10997
+ return 0;
10998
+}
10999
+
11000
+int acl_write_table_1x00(int block, int index, int link, struct acl_rule *r)
11001
+{
11002
+ u16 tmp=0, tmp2=0;
11003
+
11004
+ IP2Page(1);
11005
+ //E1 & E2
11006
+ if(r->rule_valid & ACL_RULE_VALID_SIP)
11007
+ {
11008
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, r->sip4_addr&0xFFFF);
11009
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, (r->sip4_addr>>16)&0xFFFF);
11010
+ tmp |= ((u16)(r->sip_mask&0xF)<<7);
11011
+ }
11012
+ else
11013
+ {
11014
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, 0);
11015
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, 0);
11016
+ tmp |= (0xF<<7); // any sip
11017
+ }
11018
+ //E3
11019
+ if(r->rule_valid & ACL_RULE_VALID_ETH_TYPE)
11020
+ {
11021
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, r->eth_type);
11022
+ }
11023
+ else
11024
+ {
11025
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, 0);
11026
+ tmp |= BIT(5);
11027
+ }
11028
+ //E4 ~ E6
11029
+ if(r->rule_valid & ACL_RULE_VALID_SMAC)
11030
+ {
11031
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, ((u16)(r->smac[4]&0xFF)<<8) | ((u16)(r->smac[5]&0xFF)));
11032
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, ((u16)(r->smac[2]&0xFF)<<8) | ((u16)(r->smac[3]&0xFF)));
11033
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, ((u16)(r->smac[0]&0xFF)<<8) | ((u16)(r->smac[1]&0xFF)));
11034
+ }
11035
+ else
11036
+ {
11037
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
11038
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
11039
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
11040
+ tmp |= (0x1<<6); // any smac
11041
+ }
11042
+ //E7
11043
+ if(r->rule_valid & ACL_RULE_VALID_VLAN)
11044
+ {
11045
+ if(r->rule_valid & ACL_RULE_VALID_COS)
11046
+ {
11047
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan | (r->cos<<12)));
11048
+ }
11049
+ else
11050
+ {
11051
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan|0x8000));
11052
+ }
11053
+ }
11054
+ else
11055
+ {
11056
+ tmp |= (0x3<<11);
11057
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0x8000);
11058
+ }
11059
+ //E8
11060
+ // ip_proto
11061
+ if(r->rule_valid & ACL_RULE_VALID_IP_PROT)
11062
+ {
11063
+ tmp2 |= ((u16)r->ip_prot&0xFF);
11064
+ }
11065
+ else
11066
+ {
11067
+ tmp |= BIT(13); // any ip_prot
11068
+ }
11069
+ // dscp
11070
+ if(r->rule_valid & ACL_RULE_VALID_DSCP)
11071
+ {
11072
+ tmp2 |= ((u16)(r->r_dscp&0x3F)<<10);
11073
+ }
11074
+ else
11075
+ {
11076
+ tmp |= BIT(14);
11077
+ }
11078
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, tmp2);
11079
+ //E9
11080
+ if(r->rule_valid & ACL_RULE_VALID_INGRESS_PORT)
11081
+ {
11082
+ tmp |= r->ingress_port+1;
11083
+ }
11084
+ if(r->rule_rvs & ACL_RULE_RVS_SIP) {
11085
+ tmp |= 0x8000;
11086
+ }
11087
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, tmp);
11088
+ //EA
11089
+ tmp = ((ACL_SELECT_MODE_1x00<<6) | (link<<4));
11090
+ if(r->rule_rvs & ACL_RULE_RVS_ETH_TYPE) {
11091
+ tmp |= 0x1;
11092
+ }
11093
+ if(r->rule_rvs & ACL_RULE_RVS_SMAC) {
11094
+ tmp |= 0x2;
11095
+ }
11096
+ if((r->rule_rvs&ACL_RULE_RVS_VLAN) && (r->rule_rvs&ACL_RULE_RVS_COS)) {
11097
+ tmp |= 0x4;
11098
+ }
11099
+ if(r->rule_rvs & ACL_RULE_RVS_INGRESS_PORT) {
11100
+ tmp |= 0x8;
11101
+ }
11102
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
11103
+
11104
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
11105
+ return 0;
11106
+}
11107
+
11108
+int acl_write_table_1x01(int block, int index, int link, struct acl_rule *r)
11109
+{
11110
+ u16 tmp=0, tmp2=0;
11111
+
11112
+ IP2Page(1);
11113
+ //E1 & E2
11114
+ if(r->rule_valid & ACL_RULE_VALID_DIP)
11115
+ {
11116
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, r->dip4_addr&0xFFFF);
11117
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, (r->dip4_addr>>16)&0xFFFF);
11118
+ tmp |= ((u16)(r->dip_mask&0xF)<<7);
11119
+ }
11120
+ else
11121
+ {
11122
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, 0);
11123
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, 0);
11124
+ tmp |= (0xF<<7); // any dip
11125
+ }
11126
+ //E3
11127
+ if(r->rule_valid & ACL_RULE_VALID_ETH_TYPE)
11128
+ {
11129
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, r->eth_type);
11130
+ }
11131
+ else
11132
+ {
11133
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, 0);
11134
+ tmp |= BIT(5);
11135
+ }
11136
+ //E4 ~ E6
11137
+ if(r->rule_valid & ACL_RULE_VALID_SMAC)
11138
+ {
11139
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, ((u16)(r->smac[4]&0xFF)<<8) | ((u16)(r->smac[5]&0xFF)));
11140
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, ((u16)(r->smac[2]&0xFF)<<8) | ((u16)(r->smac[3]&0xFF)));
11141
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, ((u16)(r->smac[0]&0xFF)<<8) | ((u16)(r->smac[1]&0xFF)));
11142
+ }
11143
+ else
11144
+ {
11145
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
11146
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
11147
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
11148
+ tmp |= (0x1<<6); // any smac
11149
+ }
11150
+ //E7
11151
+ if(r->rule_valid & ACL_RULE_VALID_VLAN)
11152
+ {
11153
+ if(r->rule_valid & ACL_RULE_VALID_COS)
11154
+ {
11155
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan | (r->cos<<12)));
11156
+ }
11157
+ else
11158
+ {
11159
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan|0x8000));
11160
+ }
11161
+ }
11162
+ else
11163
+ {
11164
+ tmp |= (0x3<<11);
11165
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0x8000);
11166
+ }
11167
+ //E8
11168
+ // ip_proto
11169
+ if(r->rule_valid & ACL_RULE_VALID_IP_PROT)
11170
+ {
11171
+ tmp2 |= ((u16)r->ip_prot&0xFF);
11172
+ }
11173
+ else
11174
+ {
11175
+ tmp |= BIT(13); // any ip_prot
11176
+ }
11177
+ // dscp
11178
+ if(r->rule_valid & ACL_RULE_VALID_DSCP)
11179
+ {
11180
+ tmp2 |= ((u16)(r->r_dscp&0x3F)<<10);
11181
+ }
11182
+ else
11183
+ {
11184
+ tmp |= BIT(14);
11185
+ }
11186
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, tmp2);
11187
+ //E9
11188
+ if(r->rule_valid & ACL_RULE_VALID_INGRESS_PORT)
11189
+ {
11190
+ tmp |= r->ingress_port+1;
11191
+ }
11192
+ if(r->rule_rvs & ACL_RULE_RVS_DIP) {
11193
+ tmp |= 0x8000;
11194
+ }
11195
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, tmp);
11196
+ //EA
11197
+ tmp = ((ACL_SELECT_MODE_1x01<<6) | (link<<4));
11198
+ if(r->rule_rvs & ACL_RULE_RVS_ETH_TYPE) {
11199
+ tmp |= 0x1;
11200
+ }
11201
+ if(r->rule_rvs & ACL_RULE_RVS_SMAC) {
11202
+ tmp |= 0x2;
11203
+ }
11204
+ if((r->rule_rvs&ACL_RULE_RVS_VLAN) && (r->rule_rvs&ACL_RULE_RVS_COS)) {
11205
+ tmp |= 0x4;
11206
+ }
11207
+ if(r->rule_rvs & ACL_RULE_RVS_INGRESS_PORT) {
11208
+ tmp |= 0x8;
11209
+ }
11210
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
11211
+
11212
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
11213
+ return 0;
11214
+}
11215
+
11216
+int acl_write_table_1x10(int block, int index, int link, struct acl_rule *r)
11217
+{
11218
+ u16 tmp=0, tmp2=0;
11219
+
11220
+ IP2Page(1);
11221
+ //E1 & E2
11222
+ if(r->rule_valid & ACL_RULE_VALID_SIP)
11223
+ {
11224
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, r->sip4_addr&0xFFFF);
11225
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, (r->sip4_addr>>16)&0xFFFF);
11226
+ tmp |= ((u16)(r->sip_mask&0xF)<<7);
11227
+ }
11228
+ else
11229
+ {
11230
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, 0);
11231
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, 0);
11232
+ tmp |= (0xF<<7); // any sip
11233
+ }
11234
+ //E3
11235
+ if(r->rule_valid & ACL_RULE_VALID_ETH_TYPE)
11236
+ {
11237
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, r->eth_type);
11238
+ }
11239
+ else
11240
+ {
11241
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, 0);
11242
+ tmp |= BIT(5);
11243
+ }
11244
+ //E4 ~ E6
11245
+ if(r->rule_valid & ACL_RULE_VALID_DMAC)
11246
+ {
11247
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, ((u16)(r->dmac[4]&0xFF)<<8) | ((u16)(r->dmac[5]&0xFF)));
11248
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, ((u16)(r->dmac[2]&0xFF)<<8) | ((u16)(r->dmac[3]&0xFF)));
11249
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, ((u16)(r->dmac[0]&0xFF)<<8) | ((u16)(r->dmac[1]&0xFF)));
11250
+ }
11251
+ else
11252
+ {
11253
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
11254
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
11255
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
11256
+ tmp |= (0x1<<6); // any dmac
11257
+ }
11258
+ //E7
11259
+ if(r->rule_valid & ACL_RULE_VALID_VLAN)
11260
+ {
11261
+ if(r->rule_valid & ACL_RULE_VALID_COS)
11262
+ {
11263
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan | (r->cos<<12)));
11264
+ }
11265
+ else
11266
+ {
11267
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan|0x8000));
11268
+ }
11269
+ }
11270
+ else
11271
+ {
11272
+ tmp |= (0x3<<11);
11273
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0x8000);
11274
+ }
11275
+ //E8
11276
+ // ip_proto
11277
+ if(r->rule_valid & ACL_RULE_VALID_IP_PROT)
11278
+ {
11279
+ tmp2 |= ((u16)r->ip_prot&0xFF);
11280
+ }
11281
+ else
11282
+ {
11283
+ tmp |= BIT(13); // any ip_prot
11284
+ }
11285
+ // dscp
11286
+ if(r->rule_valid & ACL_RULE_VALID_DSCP)
11287
+ {
11288
+ tmp2 |= ((u16)(r->r_dscp&0x3F)<<10);
11289
+ }
11290
+ else
11291
+ {
11292
+ tmp |= BIT(14);
11293
+ }
11294
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, tmp2);
11295
+ //E9
11296
+ if(r->rule_valid & ACL_RULE_VALID_INGRESS_PORT)
11297
+ {
11298
+ tmp |= r->ingress_port+1;
11299
+ }
11300
+ if(r->rule_rvs & ACL_RULE_RVS_SIP) {
11301
+ tmp |= 0x8000;
11302
+ }
11303
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, tmp);
11304
+ //EA
11305
+ tmp = ((ACL_SELECT_MODE_1x10<<6) | (link<<4));
11306
+ if(r->rule_rvs & ACL_RULE_RVS_ETH_TYPE) {
11307
+ tmp |= 0x1;
11308
+ }
11309
+ if(r->rule_rvs & ACL_RULE_RVS_DMAC) {
11310
+ tmp |= 0x2;
11311
+ }
11312
+ if((r->rule_rvs&ACL_RULE_RVS_VLAN) && (r->rule_rvs&ACL_RULE_RVS_COS)) {
11313
+ tmp |= 0x4;
11314
+ }
11315
+ if(r->rule_rvs & ACL_RULE_RVS_INGRESS_PORT) {
11316
+ tmp |= 0x8;
11317
+ }
11318
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
11319
+
11320
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
11321
+ return 0;
11322
+}
11323
+
11324
+int acl_write_table_1x11(int block, int index, int link, struct acl_rule *r)
11325
+{
11326
+ u16 tmp=0, tmp2=0;
11327
+
11328
+ IP2Page(1);
11329
+ //E1 & E2
11330
+ if(r->rule_valid & ACL_RULE_VALID_DIP)
11331
+ {
11332
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, r->dip4_addr&0xFFFF);
11333
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, (r->dip4_addr>>16)&0xFFFF);
11334
+ tmp |= ((u16)(r->dip_mask&0xF)<<7);
11335
+ }
11336
+ else
11337
+ {
11338
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, 0);
11339
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, 0);
11340
+ tmp |= (0xF<<7); // any dip
11341
+ }
11342
+ //E3
11343
+ if(r->rule_valid & ACL_RULE_VALID_ETH_TYPE)
11344
+ {
11345
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, r->eth_type);
11346
+ }
11347
+ else
11348
+ {
11349
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, 0);
11350
+ tmp |= BIT(5);
11351
+ }
11352
+ //E4 ~ E6
11353
+ if(r->rule_valid & ACL_RULE_VALID_DMAC)
11354
+ {
11355
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, ((u16)(r->dmac[4]&0xFF)<<8) | ((u16)(r->dmac[5]&0xFF)));
11356
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, ((u16)(r->dmac[2]&0xFF)<<8) | ((u16)(r->dmac[3]&0xFF)));
11357
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, ((u16)(r->dmac[0]&0xFF)<<8) | ((u16)(r->dmac[1]&0xFF)));
11358
+ }
11359
+ else
11360
+ {
11361
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
11362
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
11363
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
11364
+ tmp |= (0x1<<6); // any dmac
11365
+ }
11366
+ //E7
11367
+ if(r->rule_valid & ACL_RULE_VALID_VLAN)
11368
+ {
11369
+ if(r->rule_valid & ACL_RULE_VALID_COS)
11370
+ {
11371
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan | (r->cos<<12)));
11372
+ }
11373
+ else
11374
+ {
11375
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, (r->vlan|0x8000));
11376
+ }
11377
+ }
11378
+ else
11379
+ {
11380
+ tmp |= (0x3<<11);
11381
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0x8000);
11382
+ }
11383
+ //E8
11384
+ // ip_proto
11385
+ if(r->rule_valid & ACL_RULE_VALID_IP_PROT)
11386
+ {
11387
+ tmp2 |= ((u16)r->ip_prot&0xFF);
11388
+ }
11389
+ else
11390
+ {
11391
+ tmp |= BIT(13); // any ip_prot
11392
+ }
11393
+ // dscp
11394
+ if(r->rule_valid & ACL_RULE_VALID_DSCP)
11395
+ {
11396
+ tmp2 |= ((u16)(r->r_dscp&0x3F)<<10);
11397
+ }
11398
+ else
11399
+ {
11400
+ tmp |= BIT(14);
11401
+ }
11402
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, tmp2);
11403
+ //E9
11404
+ if(r->rule_valid & ACL_RULE_VALID_INGRESS_PORT)
11405
+ {
11406
+ tmp |= r->ingress_port+1;
11407
+ }
11408
+ if(r->rule_rvs & ACL_RULE_RVS_DIP) {
11409
+ tmp |= 0x8000;
11410
+ }
11411
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, tmp);
11412
+ //EA
11413
+ tmp = ((ACL_SELECT_MODE_1x11<<6) | (link<<4));
11414
+ if(r->rule_rvs & ACL_RULE_RVS_ETH_TYPE) {
11415
+ tmp |= 0x1;
11416
+ }
11417
+ if(r->rule_rvs & ACL_RULE_RVS_DMAC) {
11418
+ tmp |= 0x2;
11419
+ }
11420
+ if((r->rule_rvs&ACL_RULE_RVS_VLAN) && (r->rule_rvs&ACL_RULE_RVS_COS)) {
11421
+ tmp |= 0x4;
11422
+ }
11423
+ if(r->rule_rvs & ACL_RULE_RVS_INGRESS_PORT) {
11424
+ tmp |= 0x8;
11425
+ }
11426
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
11427
+
11428
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
11429
+ return 0;
11430
+}
11431
+
11432
+int acl_write_table_drop(int block, int index, int is_link, struct acl_rule *r)
11433
+{
11434
+ u16 tmp = 0;
11435
+
11436
+ IP2Page(1);
11437
+ //E1
11438
+ tmp = 0x1F;
11439
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, tmp);
11440
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, 0);
11441
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, 0);
11442
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
11443
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
11444
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
11445
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0);
11446
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, 0);
11447
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, 0);
11448
+ if(is_link) {
11449
+ tmp = ((ACL_SELECT_MODE_0001<<6) | (ACL_LINK_TYPE_11<<4));
11450
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
11451
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
11452
+ } else {
11453
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, 0);
11454
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC100|index|(block<<5));
11455
+ }
11456
+
11457
+ return 0;
11458
+}
11459
+
11460
+int acl_write_table_a1(int block, int index, int is_link, struct acl_rule *r)
11461
+{
11462
+ u16 tmp = 0;
11463
+ u16 tmp2 = 0;
11464
+
11465
+ IP2Page(1);
11466
+ //E1
11467
+ if(r->act_valid & ACL_ACT_VALID_REDIR)
11468
+ {
11469
+ tmp |= ((r->redir)&0x1F);
11470
+ }
11471
+ if(r->act_valid & ACL_ACT_VALID_CTAG)
11472
+ {
11473
+ tmp |= ((r->ctag&0x7F)<<5);
11474
+ }
11475
+ if(r->act_valid & ACL_ACT_VALID_STAG)
11476
+ {
11477
+ tmp |= ((r->stag&0xF)<<12);
11478
+ }
11479
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, tmp);
11480
+
11481
+ //E2
11482
+ tmp = 0;
11483
+ if(r->act_valid & ACL_ACT_VALID_STAG)
11484
+ {
11485
+ tmp |= ((r->stag&0x70)>>4);
11486
+ }
11487
+ if(r->act_valid & ACL_ACT_VALID_PRI)
11488
+ {
11489
+ tmp |= ((BIT(3)|(r->pri&0x7))<<3);
11490
+ }
11491
+ if(r->act_valid & ACL_ACT_VALID_DSCP)
11492
+ {
11493
+ tmp |= ((BIT(3)|(r->a_dscp&0x7))<<7);
11494
+ }
11495
+ if(r->act_valid & ACL_ACT_VALID_BW)
11496
+ {
11497
+ if(is_link)
11498
+ tmp2 |= ((BIT(2)|(r->bw&0x3))<<4);
11499
+ else
11500
+ tmp |= ((BIT(2)|(r->bw&0x3))<<11);
11501
+ }
11502
+ if(r->act_valid & ACL_ACT_VALID_SNIFFER)
11503
+ {
11504
+ if(is_link)
11505
+ tmp |= BIT(15);
11506
+ else
11507
+ tmp |= BIT(14);
11508
+ }
11509
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, tmp);
11510
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, tmp2);
11511
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
11512
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
11513
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
11514
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0);
11515
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, 0);
11516
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, 0);
11517
+ if(is_link) {
11518
+ tmp = ((ACL_SELECT_MODE_0001<<6) | (ACL_LINK_TYPE_11<<4));
11519
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
11520
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
11521
+ } else {
11522
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, 0);
11523
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC100|index|(block<<5));
11524
+ }
11525
+
11526
+ return 0;
11527
+}
11528
+
11529
+int acl_write_table_a2(int block, int index, int is_link, struct acl_rule *r)
11530
+{
11531
+ u16 tmp = 0;
11532
+ u16 tmp2 = 0;
11533
+
11534
+ IP2Page(1);
11535
+ //E1
11536
+ if(r->act_valid & ACL_ACT_VALID_REDIR)
11537
+ {
11538
+ tmp |= ((r->redir)&0x1F);
11539
+ }
11540
+ if(r->act_valid & ACL_ACT_VALID_CTAG)
11541
+ {
11542
+ tmp |= ((r->ctag&0x7F)<<5);
11543
+ }
11544
+ if(r->act_valid & ACL_ACT_VALID_STAG)
11545
+ {
11546
+ tmp |= ((r->stag&0xF)<<12);
11547
+ }
11548
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, tmp);
11549
+
11550
+ //E2
11551
+ tmp = 0;
11552
+ if(r->act_valid & ACL_ACT_VALID_STAG)
11553
+ {
11554
+ tmp |= ((r->stag&0x70)>>4);
11555
+ }
11556
+ if(r->act_valid & ACL_ACT_VALID_PRI)
11557
+ {
11558
+ tmp |= ((BIT(3)|(r->pri&0x7))<<3);
11559
+ }
11560
+ if(r->act_valid & ACL_ACT_VALID_STORM)
11561
+ {
11562
+ if(is_link)
11563
+ tmp2 |= (BIT(r->storm-1)<<1);
11564
+ else
11565
+ tmp |= (BIT(r->storm-1)<<7);
11566
+ }
11567
+ if(r->act_valid & ACL_ACT_VALID_CPU)
11568
+ {
11569
+ if(is_link)
11570
+ tmp2 |= BIT(0);
11571
+ else
11572
+ tmp |= BIT(10);
11573
+ }
11574
+ if(r->act_valid & ACL_ACT_VALID_MIB_COUNTER)
11575
+ {
11576
+ tmp |= ((BIT(1)|((r->mib_counter-1)&0x1))<<11);
11577
+ }
11578
+ if(r->act_valid & ACL_ACT_VALID_PTP)
11579
+ {
11580
+ tmp |= BIT(13);
11581
+ }
11582
+ if(r->act_valid & ACL_ACT_VALID_SFLOW)
11583
+ {
11584
+ tmp |= BIT(14);
11585
+ }
11586
+ tmp |= BIT(15);
11587
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, tmp);
11588
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, tmp2);
11589
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
11590
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
11591
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
11592
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0);
11593
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, 0);
11594
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, 0);
11595
+ if(is_link) {
11596
+ tmp = ((ACL_SELECT_MODE_0001<<6) | (ACL_LINK_TYPE_11<<4));
11597
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
11598
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
11599
+ } else {
11600
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, 0);
11601
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC100|index|(block<<5));
11602
+ }
11603
+
11604
+ return 0;
11605
+}
11606
+
11607
+int acl_write_table_a3(int block, int index, int is_link, struct acl_rule *r)
11608
+{
11609
+ u16 tmp = 0;
11610
+
11611
+ IP2Page(1);
11612
+ //E1
11613
+ if(r->act_valid & ACL_ACT_VALID_REDIR)
11614
+ {
11615
+ tmp |= ((r->redir)&0x1F);
11616
+ }
11617
+ if(r->act_valid & ACL_ACT_VALID_CTAG)
11618
+ {
11619
+ tmp |= ((r->ctag&0x7F)<<5);
11620
+ }
11621
+ if(r->act_valid & ACL_ACT_VALID_STAG)
11622
+ {
11623
+ tmp |= ((r->stag&0xF)<<12);
11624
+ }
11625
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1, tmp);
11626
+
11627
+ //E2
11628
+ tmp = 0;
11629
+ if(r->act_valid & ACL_ACT_VALID_STAG)
11630
+ {
11631
+ tmp |= ((r->stag&0x70)>>4);
11632
+ }
11633
+ if(r->act_valid & ACL_ACT_VALID_PRI)
11634
+ {
11635
+ tmp |= ((BIT(3)|(r->pri&0x7))<<3);
11636
+ }
11637
+ if(r->act_valid & ACL_ACT_VALID_DSCP)
11638
+ {
11639
+ tmp |= ((BIT(3)|(r->a_dscp&0x7))<<7);
11640
+ }
11641
+ if(r->act_valid & ACL_ACT_VALID_MIB_COUNTER)
11642
+ {
11643
+ tmp |= ((BIT(1)|(r->mib_counter&0x1))<<11);
11644
+ }
11645
+ if(r->act_valid & ACL_ACT_VALID_PTP)
11646
+ {
11647
+ tmp |= BIT(13);
11648
+ }
11649
+ if(r->act_valid & ACL_ACT_VALID_SFLOW)
11650
+ {
11651
+ tmp |= BIT(14);
11652
+ }
11653
+ if(r->act_valid & ACL_ACT_VALID_SNIFFER)
11654
+ {
11655
+ tmp |= BIT(15);
11656
+ }
11657
+ Write_Reg(P1REG_ACL_TABLE_DATA_E2, tmp);
11658
+
11659
+ //E3
11660
+ tmp = 0;
11661
+ if(r->act_valid & ACL_ACT_VALID_CPU)
11662
+ {
11663
+ tmp |= BIT(0);
11664
+ }
11665
+ if(r->act_valid & ACL_ACT_VALID_STORM)
11666
+ {
11667
+ tmp |= (BIT(r->storm-1)<<1);
11668
+ }
11669
+ if(r->act_valid & ACL_ACT_VALID_BW)
11670
+ {
11671
+ tmp |= ((BIT(2)|(r->bw&0x3))<<4);
11672
+ }
11673
+ Write_Reg(P1REG_ACL_TABLE_DATA_E3, tmp);
11674
+
11675
+ //E4
11676
+ Write_Reg(P1REG_ACL_TABLE_DATA_E4, 0);
11677
+ //E5
11678
+ Write_Reg(P1REG_ACL_TABLE_DATA_E5, 0);
11679
+ //E6
11680
+ Write_Reg(P1REG_ACL_TABLE_DATA_E6, 0);
11681
+ //E7
11682
+ Write_Reg(P1REG_ACL_TABLE_DATA_E7, 0);
11683
+ //E8
11684
+ Write_Reg(P1REG_ACL_TABLE_DATA_E8, 0);
11685
+ //E9
11686
+ Write_Reg(P1REG_ACL_TABLE_DATA_E9, 0);
11687
+ //EA
11688
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, 0);
11689
+
11690
+ tmp = ((ACL_SELECT_MODE_0001<<6) | (ACL_LINK_TYPE_11<<4));
11691
+ Write_Reg(P1REG_ACL_TABLE_DATA_EA, tmp);
11692
+
11693
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|index|(block<<5));
11694
+ return 0;
11695
+}
11696
+
11697
+int switchdSetAclRule(struct AclRuleSetting *ars)
11698
+{
11699
+ struct acl_rule *r = &ars ->rule;
11700
+ unsigned long rule_v = r->rule_valid;
11701
+ int s_mode = 0, s_num = 0, flag = 0, i = 0, block = 0, index = 0, link = 0;
11702
+ struct acl_man_rule *mr;
11703
+ int ret = 0;
11704
+ int find_idx_blockn;
11705
+ int find_idx_rvs;
11706
+
11707
+ ip1811drv_dbg("<DBG_DR_ACL> switchdSetAclRule(): ars ->rule_index = %i\n", ars ->rule_index);
11708
+ // check index
11709
+ list_for_each_entry(mr, &m_acl ->rule_list, rule_entry) {
11710
+ if(mr->rule_index == ars ->rule_index) {
11711
+ if((mr->func_used) & (ars->func_used)) {
11712
+ for(i = mr->start_index; i<(mr->start_index+mr->num_entries); i++) {
11713
+ block = mr->start_block;
11714
+ index = i&0xF;
11715
+ acl_clean_table(block, index);
11716
+ m_acl ->used_entry_mask[block] &= ~BIT(i&0xF);
11717
+ m_acl ->num_used_entries--;
11718
+ }
11719
+ m_acl ->num_used_rules--;
11720
+ flag = 1;
11721
+ break;
11722
+ }
11723
+ }
11724
+ }
11725
+
11726
+ if(!flag) {
11727
+ mr = NULL;
11728
+ }
11729
+
11730
+ if(rule_v==0) {
11731
+ ars->rule_index_res=0;
11732
+ ars->reserved=0;
11733
+ m_acl->num_used_rules++;
11734
+ if(mr!=NULL) {
11735
+ list_del(&mr->rule_entry);
11736
+ kfree(mr);
11737
+ }
11738
+ return 0;
11739
+ }
11740
+
11741
+ // selection logic
11742
+ if((rule_v & ACL_RULE_VALID_SIP6) || (rule_v & ACL_RULE_VALID_DIP6)) {
11743
+ if(rule_v & ACL_RULE_VALID_SIP6) {
11744
+ // 0110
11745
+ s_mode |= ACL_SELECT_MODE_BIT_0110;
11746
+ s_num += 1;
11747
+ }
11748
+
11749
+ if(rule_v & ACL_RULE_VALID_DIP6) {
11750
+ // 0111
11751
+ s_mode |= ACL_SELECT_MODE_BIT_0111;
11752
+ s_num += 1;
11753
+ }
11754
+
11755
+ if((rule_v & ACL_RULE_VALID_SP_R) || (rule_v & ACL_RULE_VALID_DP_R)) {
11756
+ // 0101
11757
+ s_mode |= ACL_SELECT_MODE_BIT_0101;
11758
+ s_num += 1;
11759
+ }
11760
+ goto out_select_logic;
11761
+ } else if(rule_v & ACL_RULE_VALID_USERDEF_OFFSET) {
11762
+ //0010
11763
+ s_mode=ACL_SELECT_MODE_BIT_0010;
11764
+ s_num=1;
11765
+ goto out_select_logic;
11766
+ }
11767
+
11768
+ if((rule_v & ACL_RULE_VALID_SP_R) || (rule_v & ACL_RULE_VALID_DP_R)) {
11769
+ if(rule_v & ACL_RULE_VALID_DIP) {
11770
+ // 0101
11771
+ s_mode |= ACL_SELECT_MODE_BIT_0101;
11772
+ s_num += 1;
11773
+
11774
+ if( (rule_v & ACL_RULE_VALID_SIP)
11775
+ || (rule_v & ACL_RULE_VALID_DMAC)
11776
+ || (rule_v & ACL_RULE_VALID_SMAC)
11777
+ || (rule_v & ACL_RULE_VALID_ETH_TYPE)
11778
+ || (rule_v & ACL_RULE_VALID_DSCP)
11779
+ || (rule_v & ACL_RULE_VALID_IP_PROT)
11780
+ ) {
11781
+ if(rule_v & ACL_RULE_VALID_DMAC) {
11782
+ // 1x10
11783
+ s_mode |= ACL_SELECT_MODE_BIT_1x10;
11784
+ s_num += 1;
11785
+
11786
+ if(rule_v & ACL_RULE_VALID_SMAC) {
11787
+ // 1x00
11788
+ s_mode |= ACL_SELECT_MODE_BIT_1x00;
11789
+ s_num += 1;
11790
+ }
11791
+ } else {
11792
+ // 1x00
11793
+ s_mode |= ACL_SELECT_MODE_BIT_1x00;
11794
+ s_num += 1;
11795
+ }
11796
+ }
11797
+ } else {
11798
+ // 0100
11799
+ s_mode |= ACL_SELECT_MODE_BIT_0100;
11800
+ s_num += 1;
11801
+ if( (rule_v & ACL_RULE_VALID_DMAC)
11802
+ || (rule_v & ACL_RULE_VALID_SMAC)
11803
+ || (rule_v & ACL_RULE_VALID_ETH_TYPE)
11804
+ || (rule_v & ACL_RULE_VALID_DSCP)
11805
+ || (rule_v & ACL_RULE_VALID_IP_PROT)
11806
+ ) {
11807
+ if(rule_v & ACL_RULE_VALID_DMAC) {
11808
+ // 1x10
11809
+ s_mode |= ACL_SELECT_MODE_BIT_1x10;
11810
+ s_num += 1;
11811
+
11812
+ if(rule_v & ACL_RULE_VALID_SMAC) {
11813
+ // 1x00
11814
+ s_mode |= ACL_SELECT_MODE_BIT_1x00;
11815
+ s_num += 1;
11816
+ }
11817
+ } else {
11818
+ // 1x00
11819
+ s_mode |= ACL_SELECT_MODE_BIT_1x00;
11820
+ s_num += 1;
11821
+ }
11822
+ }
11823
+ }
11824
+ } else {
11825
+ if(rule_v & ACL_RULE_VALID_DIP) {
11826
+ if(rule_v & ACL_RULE_VALID_DMAC) {
11827
+ // 1x11
11828
+ s_mode |= ACL_SELECT_MODE_BIT_1x11;
11829
+ s_num += 1;
11830
+
11831
+ if((rule_v & ACL_RULE_VALID_SMAC) || (rule_v & ACL_RULE_VALID_SIP)) {
11832
+ // 1x00
11833
+ s_mode |= ACL_SELECT_MODE_BIT_1x00;
11834
+ s_num += 1;
11835
+ }
11836
+ } else {
11837
+ // 1x01
11838
+ s_mode |= ACL_SELECT_MODE_BIT_1x01;
11839
+ s_num += 1;
11840
+ if(rule_v & ACL_RULE_VALID_SIP) {
11841
+ // 1x00
11842
+ s_mode |= ACL_SELECT_MODE_BIT_1x00;
11843
+ s_num += 1;
11844
+ }
11845
+ }
11846
+ } else {
11847
+ if(rule_v & ACL_RULE_VALID_DMAC) {
11848
+ // 1x10
11849
+ s_mode |= ACL_SELECT_MODE_BIT_1x10;
11850
+ s_num += 1;
11851
+ if(rule_v & ACL_RULE_VALID_SMAC) {
11852
+ // 1x00
11853
+ s_mode |= ACL_SELECT_MODE_BIT_1x00;
11854
+ s_num += 1;
11855
+ }
11856
+ } else {
11857
+ // 1x00
11858
+ s_mode |= ACL_SELECT_MODE_BIT_1x00;
11859
+ s_num += 1;
11860
+ }
11861
+ }
11862
+ }
11863
+
11864
+out_select_logic:
11865
+ ip1811drv_dbg("<DBG_SWD_ACL> s_mode = %02x, s_num = %i\n", s_mode, s_num);
11866
+
11867
+ if((r->act_type==ACL_ACT_TYPE_3) || (s_num>=2)) {
11868
+ s_num++;
11869
+ }
11870
+
11871
+ find_idx_blockn = ars->find_index_blockn;
11872
+ find_idx_rvs = ars->find_index_rvs;
11873
+
11874
+ ret = acl_find_index(s_num, &block, &index, find_idx_blockn, find_idx_rvs);
11875
+
11876
+ if(ret < 0) { // if acl_find_index return <0, remap acl rule index and find index again
11877
+ set_rule_index_remap();
11878
+ ret = acl_find_index(s_num, &block, &index, find_idx_blockn, find_idx_rvs);
11879
+ }
11880
+
11881
+ if(ret < 0) {
11882
+ if(mr != NULL) {
11883
+ list_del(&mr->rule_entry);
11884
+ kfree(mr);
11885
+ }
11886
+ ars ->rule_index_res = -2;
11887
+ ars ->reserved = s_num;
11888
+ return 0;
11889
+ //return -ENOMEM;
11890
+ }
11891
+ ip1811drv_dbg("<DBG_SWD_ACL> block, index = %i, %i\n", block, index);
11892
+
11893
+ ars->find_index_blockn = block;
11894
+ if(mr == NULL) {
11895
+ mr = kmalloc(sizeof(struct acl_man_rule), GFP_KERNEL);
11896
+ if(mr == NULL) {
11897
+ ip1811drv_err("Error: switchdSetAclRule() acl_man_rule malloc failed.\n");
11898
+ return -ENOMEM;
11899
+ }
11900
+ list_add_tail(&mr->rule_entry, &m_acl ->rule_list);
11901
+ }
11902
+
11903
+ mr->start_block = block;
11904
+ mr->start_index = index;
11905
+ mr->num_entries = s_num;
11906
+ mr->rule_index = ars ->rule_index;
11907
+ mr->func_used = ars ->func_used;
11908
+ if(s_num == 1) {
11909
+ link = ACL_LINK_TYPE_00;
11910
+ // write rule table
11911
+ for(i=2; i<12; i++) {
11912
+ if(s_mode & BIT(i)) {
11913
+ acl_write_table_rule[i-1](block, index, link, r);
11914
+ s_num--;
11915
+ break;
11916
+ }
11917
+ }
11918
+ // write action table
11919
+ acl_write_table_act[r->act_type](block, index, s_num, r);
11920
+ } else {
11921
+ link = ACL_LINK_TYPE_01;
11922
+ // write rule table
11923
+ for(i=2; i<12; i++) {
11924
+ if(s_mode & BIT(i)) {
11925
+ acl_write_table_rule[i-1](block, index, link, r);
11926
+ index++;
11927
+ s_num--;
11928
+ if(s_num == 1) {
11929
+ break;
11930
+ } else {
11931
+ link = ACL_LINK_TYPE_10;
11932
+ }
11933
+ }
11934
+ }
11935
+ // write action table
11936
+ //acl_write_table_act[r->act_type](block, index, s_num, r);
11937
+ acl_write_table_act[3](block, index, s_num, r);
11938
+ }
11939
+
11940
+ for(i=0; i<mr->num_entries; i++) {
11941
+ m_acl ->used_entry_mask[mr->start_block] |= BIT((i+mr->start_index)&0xF);
11942
+ m_acl ->num_used_entries++;
11943
+ }
11944
+ m_acl ->num_used_rules++;
11945
+ ars ->rule_index_res = 0;
11946
+ ars ->reserved = mr->num_entries;
11947
+
11948
+ return 0;
11949
+}
11950
+EXPORT_SYMBOL(switchdSetAclRule);
11951
+
11952
+int setAclRule(void *cdata, int len)
11953
+{
11954
+ int ret;
11955
+ struct AclRuleSetting *ars = (struct AclRuleSetting *)cdata;
11956
+
11957
+ FUNC_MSG_IN;
11958
+ if (sizeof(struct AclRuleSetting) != len) {
11959
+ ip1811drv_err("Error: lengtn=%d\n", len);
11960
+ return -EINVAL;
11961
+ }
11962
+
11963
+ ret = switchdSetAclRule(ars);
11964
+ FUNC_MSG_OUT;
11965
+
11966
+ return ret;
11967
+}
11968
+
11969
+int getAclRule(void *cdata, int len)
11970
+{
11971
+ return 0;
11972
+}
11973
+
11974
+int switchdAclCleanTable(int rule_index, int func_used)
11975
+{
11976
+ int i = 0;
11977
+ struct acl_man_rule *mr, *nmr;
11978
+ int block, index;
11979
+
11980
+ if ((rule_index<1 || rule_index>64) && (rule_index!=128)) {
11981
+ ip1811drv_err("Error: rule index=%d\n", rule_index);
11982
+ return -EINVAL;
11983
+ }
11984
+
11985
+ ip1811drv_dbg("<DBG_DR_ACL> aclCleanTable()\n");
11986
+
11987
+ if(rule_index == 128) {
11988
+ ip1811drv_dbg("<DBG_DR_ACL> aclCleanTable() 111111\n");
11989
+ if(list_empty(&m_acl ->rule_list)) {
11990
+ ip1811drv_dbg("<DBG_DR_ACL> aclCleanTable() 222222\n");
11991
+ return 0;
11992
+ }
11993
+
11994
+ list_for_each_entry_safe(mr, nmr, &m_acl ->rule_list, rule_entry)
11995
+ {
11996
+ for(i=0; i<mr->num_entries; i++) {
11997
+ block = mr->start_block;
11998
+ index = mr->start_index;
11999
+ acl_clean_table(block, index+i);
12000
+ m_acl ->used_entry_mask[block] &= ~BIT((index+i)&0xF);
12001
+ m_acl ->num_used_entries--;
12002
+ }
12003
+ m_acl ->num_used_rules--;
12004
+ list_del(&mr->rule_entry);
12005
+ kfree(mr);
12006
+ }
12007
+
12008
+ INIT_LIST_HEAD(&m_acl ->rule_list);
12009
+
12010
+ if((m_acl ->num_used_rules!=0) || (m_acl ->num_used_entries!=0))
12011
+ ip1811drv_err("<DBG_SWD_ACL> aclCleanTable something error!\n");
12012
+ } else {
12013
+ list_for_each_entry(mr, &m_acl ->rule_list, rule_entry)
12014
+ {
12015
+ if(mr->rule_index == rule_index) {
12016
+ if((mr->func_used) & func_used) {
12017
+ for(i=0; i<mr->num_entries; i++) {
12018
+ block = mr->start_block;
12019
+ index = mr->start_index;
12020
+ acl_clean_table(block, index+i);
12021
+ m_acl ->used_entry_mask[block] &= ~BIT((index+i)&0xF);
12022
+ m_acl ->num_used_entries--;
12023
+ }
12024
+ m_acl ->num_used_rules--;
12025
+ list_del(&mr->rule_entry);
12026
+ kfree(mr);
12027
+ break;
12028
+ }
12029
+ }
12030
+ }
12031
+ }
12032
+
12033
+ return 0;
12034
+}
12035
+EXPORT_SYMBOL(switchdAclCleanTable);
12036
+
12037
+int aclCleanTable(void *cdata, int len)
12038
+{
12039
+ int ret, rule_index, func_used;
12040
+ struct AclTableCleanSetting *atcs = (struct AclTableCleanSetting *)cdata;
12041
+
12042
+ FUNC_MSG_IN;
12043
+ if (sizeof(struct AclTableCleanSetting) != len) {
12044
+ ip1811drv_err("Error: lengtn=%d\n", len);
12045
+ return -EINVAL;
12046
+ }
12047
+
12048
+ rule_index = atcs ->rule_idx;
12049
+ func_used = atcs ->func_used;
12050
+ ret = switchdAclCleanTable(rule_index, func_used);
12051
+ FUNC_MSG_OUT;
12052
+
12053
+ return ret;
12054
+}
12055
+
12056
+int switchdSetAclFunctionEn(int enable)
12057
+{
12058
+ if ((enable!=OP_FUNC_ENABLE) && (enable!=OP_FUNC_DISABLE)) {
12059
+ ip1811drv_err("Error: value=%d\n", enable);
12060
+ return -EINVAL;
12061
+ }
12062
+ _WriteRegBits(1, P1REG_MISCCFG, 0, 1, enable);
12063
+ return 0;
12064
+}
12065
+EXPORT_SYMBOL(switchdSetAclFunctionEn);
12066
+
12067
+int setAclFunctionEn(void *cdata, int len)
12068
+{
12069
+ int ret;
12070
+ struct GeneralSetting *gs = (struct GeneralSetting *)cdata;
12071
+ int func_en;
12072
+
12073
+ FUNC_MSG_IN;
12074
+ if (sizeof(struct GeneralSetting) != len) {
12075
+ ip1811drv_err("Error: lengtn=%d\n", len);
12076
+ return -EINVAL;
12077
+ }
12078
+
12079
+ func_en = gs ->gdata;
12080
+ ret = switchdSetAclFunctionEn(func_en);
12081
+ FUNC_MSG_OUT;
12082
+
12083
+ return ret;
12084
+}
12085
+
12086
+int switchdGetAclFunctionEn(int *gdata_p)
12087
+{
12088
+ *gdata_p = _ReadRegBits(1, P1REG_MISCCFG, 0, 1);
12089
+ return 0;
12090
+}
12091
+EXPORT_SYMBOL(switchdGetAclFunctionEn);
12092
+
12093
+int getAclFunctionEn(void *cdata, int len)
12094
+{
12095
+ int ret;
12096
+ struct GeneralSetting *gs = (struct GeneralSetting *)cdata;
12097
+
12098
+ FUNC_MSG_IN;
12099
+ if (sizeof(struct GeneralSetting) != len) {
12100
+ ip1811drv_err("Error: lengtn=%d\n", len);
12101
+ return -EINVAL;
12102
+ }
12103
+
12104
+ ret = switchdGetAclFunctionEn(&(gs ->gdata));
12105
+ FUNC_MSG_OUT;
12106
+
12107
+ return ret;
12108
+}
12109
+
12110
+int switchdSetAclEtherAfterTag(int is_after_tag)
12111
+{
12112
+ if ((is_after_tag!=OP_FUNC_ENABLE) && (is_after_tag!=OP_FUNC_DISABLE)) {
12113
+ ip1811drv_err("Error: value=%d\n", is_after_tag);
12114
+ return -EINVAL;
12115
+ }
12116
+ _WriteRegBits(1, P1REG_MISCCFG, 1, 1, is_after_tag);
12117
+ return 0;
12118
+}
12119
+EXPORT_SYMBOL(switchdSetAclEtherAfterTag);
12120
+
12121
+int setAclEtherAfterTag(void *cdata, int len)
12122
+{
12123
+ int ret;
12124
+ struct GeneralSetting *gs = (struct GeneralSetting *)cdata;
12125
+ int loca_v;
12126
+
12127
+ FUNC_MSG_IN;
12128
+ if (sizeof(struct GeneralSetting) != len) {
12129
+ ip1811drv_err("Error: lengtn=%d\n", len);
12130
+ return -EINVAL;
12131
+ }
12132
+
12133
+ loca_v = gs ->gdata;
12134
+ ret = switchdSetAclEtherAfterTag(loca_v);
12135
+ FUNC_MSG_OUT;
12136
+
12137
+ return ret;
12138
+}
12139
+
12140
+int switchdGetAclEtherAfterTag(int *gdata_p)
12141
+{
12142
+ *gdata_p = _ReadRegBits(1, P1REG_MISCCFG, 1, 1);
12143
+ return 0;
12144
+}
12145
+EXPORT_SYMBOL(switchdGetAclEtherAfterTag);
12146
+
12147
+int getAclEtherAfterTag(void *cdata, int len)
12148
+{
12149
+ int ret;
12150
+ struct GeneralSetting *gs = (struct GeneralSetting *)cdata;
12151
+
12152
+ FUNC_MSG_IN;
12153
+ if (sizeof(struct GeneralSetting) != len) {
12154
+ ip1811drv_err("Error: lengtn=%d\n", len);
12155
+ return -EINVAL;
12156
+ }
12157
+
12158
+ ret = switchdGetAclEtherAfterTag(&(gs ->gdata));
12159
+ FUNC_MSG_OUT;
12160
+
12161
+ return ret;
12162
+}
12163
+
12164
+int switchdGetAclUsedRules(int *gdata_p)
12165
+{
12166
+ *gdata_p = m_acl ->num_used_rules;
12167
+ return 0;
12168
+}
12169
+EXPORT_SYMBOL(switchdGetAclUsedRules);
12170
+
12171
+int getAclUsedRules(void *cdata, int len)
12172
+{
12173
+ int ret;
12174
+ struct GeneralSetting *gs = (struct GeneralSetting *)cdata;
12175
+
12176
+ FUNC_MSG_IN;
12177
+ if (sizeof(struct GeneralSetting) != len) {
12178
+ ip1811drv_err("Error: lengtn=%d\n", len);
12179
+ return -EINVAL;
12180
+ }
12181
+
12182
+ ret = switchdGetAclUsedRules(&(gs ->gdata));
12183
+ FUNC_MSG_OUT;
12184
+
12185
+ return ret;
12186
+}
12187
+
12188
+int switchdGetAclUsedEntries(int *gdata_p)
12189
+{
12190
+ *gdata_p = m_acl ->num_used_entries;
12191
+ return 0;
12192
+}
12193
+EXPORT_SYMBOL(switchdGetAclUsedEntries);
12194
+
12195
+int getAclUsedEntries(void *cdata, int len)
12196
+{
12197
+ int ret;
12198
+ struct GeneralSetting *gs = (struct GeneralSetting *)cdata;
12199
+
12200
+ FUNC_MSG_IN;
12201
+ if (sizeof(struct GeneralSetting) != len) {
12202
+ ip1811drv_err("Error: lengtn=%d\n", len);
12203
+ return -EINVAL;
12204
+ }
12205
+
12206
+ ret = switchdGetAclUsedEntries(&(gs ->gdata));
12207
+ FUNC_MSG_OUT;
12208
+
12209
+ return ret;
12210
+}
12211
+
12212
+int switchdGetAclUsedEntryMask(unsigned short *gmask_p)
12213
+{
12214
+ memcpy(gmask_p, m_acl->used_entry_mask, 4*sizeof(unsigned short));
12215
+ return 0;
12216
+}
12217
+EXPORT_SYMBOL(switchdGetAclUsedEntryMask);
12218
+
12219
+int getAclUsedEntryMask(void *cdata, int len)
12220
+{
12221
+ int ret;
12222
+ struct AclEntryMaskGetting *aemg = (struct AclEntryMaskGetting *)cdata;
12223
+
12224
+ FUNC_MSG_IN;
12225
+ if (sizeof(struct AclEntryMaskGetting) != len) {
12226
+ ip1811drv_err("Error: lengtn=%d\n", len);
12227
+ return -EINVAL;
12228
+ }
12229
+
12230
+ ret = switchdGetAclUsedEntryMask(aemg ->mask);
12231
+ FUNC_MSG_OUT;
12232
+
12233
+ return ret;
12234
+}
12235
+
12236
+int switchdSetAclBW(int index, int in_rate)
12237
+{
12238
+ u16 rate = 0;
12239
+
12240
+ if (index<0 || index>3) {
12241
+ ip1811drv_err("Error: index=%d\n", index);
12242
+ return -EINVAL;
12243
+ }
12244
+
12245
+ if (in_rate<0 || in_rate>2540) {
12246
+ ip1811drv_err("Error: rate=%d\n", in_rate);
12247
+ return -EINVAL;
12248
+ }
12249
+
12250
+ if(in_rate > 163) {
12251
+ rate |= BIT(7);
12252
+ rate |= (in_rate*100/2000);
12253
+ if(in_rate*100%2000)
12254
+ rate++;
12255
+ } else {
12256
+ rate = (in_rate*100/128);
12257
+ if(in_rate*100%128)
12258
+ rate++;
12259
+ }
12260
+
12261
+ ip1811drv_dbg("index=%d\n", index);
12262
+ ip1811drv_dbg("value=0x%x\n", rate);
12263
+ // set 4 block
12264
+ _WriteRegBits(1, P1REG_ACL_BW_01+(index/2)+0, 8*(index%2), 8, rate);
12265
+ _WriteRegBits(1, P1REG_ACL_BW_01+(index/2)+2, 8*(index%2), 8, rate);
12266
+ _WriteRegBits(1, P1REG_ACL_BW_01+(index/2)+4, 8*(index%2), 8, rate);
12267
+ _WriteRegBits(1, P1REG_ACL_BW_01+(index/2)+6, 8*(index%2), 8, rate);
12268
+
12269
+ return 0;
12270
+}
12271
+EXPORT_SYMBOL(switchdSetAclBW);
12272
+
12273
+int setAclBW(void *cdata, int len)
12274
+{
12275
+ int ret;
12276
+ struct AclGeneralSetting *ags = (struct AclGeneralSetting *)cdata;
12277
+ int bw_index;
12278
+ int bw_v;
12279
+
12280
+ FUNC_MSG_IN;
12281
+ if (sizeof(struct AclGeneralSetting) != len) {
12282
+ ip1811drv_err("Error: lengtn=%d\n", len);
12283
+ return -EINVAL;
12284
+ }
12285
+
12286
+ bw_index = ags ->index;
12287
+ bw_v = ags ->data;
12288
+ ret = switchdSetAclBW(bw_index, bw_v);
12289
+ FUNC_MSG_OUT;
12290
+
12291
+ return ret;
12292
+}
12293
+
12294
+int switchdGetAclBW(int index, int *gdata_p)
12295
+{
12296
+ u16 tmp = 0;
12297
+ u32 c_rate;
12298
+
12299
+ if (index<0 || index>3) {
12300
+ ip1811drv_err("Error: index=%d\n", index);
12301
+ return -EINVAL;
12302
+ }
12303
+
12304
+ tmp = _ReadRegBits(1, P1REG_ACL_BW_01+(index/2), (8*(index%2)), 8);
12305
+
12306
+ if(tmp&BIT(7)) {
12307
+ c_rate = (tmp&(0x7F))*2000;
12308
+ } else {
12309
+ c_rate = (tmp&(0x7F))*128;
12310
+ }
12311
+
12312
+ *gdata_p = c_rate/100;
12313
+
12314
+ return 0;
12315
+}
12316
+EXPORT_SYMBOL(switchdGetAclBW);
12317
+
12318
+int getAclBW(void *cdata, int len)
12319
+{
12320
+ int ret;
12321
+ struct AclGeneralSetting *ags = (struct AclGeneralSetting *)cdata;
12322
+ int bw_index;
12323
+
12324
+ FUNC_MSG_IN;
12325
+ if (sizeof(struct AclGeneralSetting) != len) {
12326
+ ip1811drv_err("Error: lengtn=%d\n", len);
12327
+ return -EINVAL;
12328
+ }
12329
+
12330
+ bw_index = ags ->index;
12331
+ ret = switchdGetAclBW(bw_index, &(ags ->data));
12332
+ ip1811drv_dbg("cdata ->data=%d\n", ags ->data);
12333
+ FUNC_MSG_OUT;
12334
+
12335
+ return ret;
12336
+}
12337
+
12338
+int switchdSetAclDscp(int index, int value)
12339
+{
12340
+ if (index<0 || index>7) {
12341
+ ip1811drv_err("Error: index=%d\n", index);
12342
+ return -EINVAL;
12343
+ }
12344
+
12345
+ if (value & (~0x3F)) {
12346
+ ip1811drv_err("Error: value=%x\n", value);
12347
+ return -EINVAL;
12348
+ }
12349
+
12350
+ ip1811drv_dbg("index=%d\n", index);
12351
+ ip1811drv_dbg("value=0x%x\n", value);
12352
+
12353
+ _WriteRegBits(7, P7REG_DSCP_REMARKING_01+(index/2), 8*(index%2), 8, value);
12354
+
12355
+ return 0;
12356
+}
12357
+EXPORT_SYMBOL(switchdSetAclDscp);
12358
+
12359
+int setAclDscp(void *cdata, int len)
12360
+{
12361
+ int ret;
12362
+ struct AclGeneralSetting *ags = (struct AclGeneralSetting *)cdata;
12363
+ int dscp_index;
12364
+ int dscp_v;
12365
+
12366
+ FUNC_MSG_IN;
12367
+ if (sizeof(struct AclGeneralSetting) != len) {
12368
+ ip1811drv_err("Error: lengtn=%d\n", len);
12369
+ return -EINVAL;
12370
+ }
12371
+
12372
+ dscp_index = ags ->index;
12373
+ dscp_v = ags ->data;
12374
+ ret = switchdSetAclDscp(dscp_index, dscp_v);
12375
+ FUNC_MSG_OUT;
12376
+
12377
+ return ret;
12378
+}
12379
+
12380
+int switchdGetAclDscp(int index, int *gdata_p)
12381
+{
12382
+ if (index<0 || index>7) {
12383
+ ip1811drv_err("Error: index=%d\n", index);
12384
+ return -EINVAL;
12385
+ }
12386
+ *gdata_p = _ReadRegBits(7, P7REG_DSCP_REMARKING_01+(index/2), (8*(index%2)), 8);
12387
+ return 0;
12388
+}
12389
+EXPORT_SYMBOL(switchdGetAclDscp);
12390
+
12391
+int getAclDscp(void *cdata, int len)
12392
+{
12393
+ int ret;
12394
+ struct AclGeneralSetting *ags = (struct AclGeneralSetting *)cdata;
12395
+ int dscp_index;
12396
+
12397
+ FUNC_MSG_IN;
12398
+ if (sizeof(struct AclGeneralSetting) != len) {
12399
+ ip1811drv_err("Error: lengtn=%d\n", len);
12400
+ return -EINVAL;
12401
+ }
12402
+
12403
+ dscp_index = ags ->index;
12404
+ ret = switchdGetAclDscp(dscp_index, &(ags ->data));
12405
+ ip1811drv_dbg("cdata ->data=%d\n", ags ->data);
12406
+ FUNC_MSG_OUT;
12407
+
12408
+ return ret;
12409
+}
12410
+
12411
+int switchdSetAclVidRemark(int index, int value)
12412
+{
12413
+
12414
+ if (index<0 || index>15) {
12415
+ ip1811drv_err("Error: index=%d\n", index);
12416
+ return -EINVAL;
12417
+ }
12418
+
12419
+ if (value & (~0x7FFF)) {
12420
+ ip1811drv_err("Error: value=%x\n", value);
12421
+ return -EINVAL;
12422
+ }
12423
+
12424
+ ip1811drv_dbg("index=%d\n", index);
12425
+ ip1811drv_dbg("value=0x%x\n", value);
12426
+
12427
+ _WriteRegBits(2, P2REG_ACL_VID_REMARK_00+index, 0, 15, value);
12428
+
12429
+ return 0;
12430
+}
12431
+EXPORT_SYMBOL(switchdSetAclVidRemark);
12432
+
12433
+int setAclVidRemark(void *cdata, int len)
12434
+{
12435
+ int ret;
12436
+ struct AclGeneralSetting *ags = (struct AclGeneralSetting *)cdata;
12437
+ int vid_index;
12438
+ int vid_v;
12439
+
12440
+ FUNC_MSG_IN;
12441
+ if (sizeof(struct AclGeneralSetting) != len) {
12442
+ ip1811drv_err("Error: lengtn=%d\n", len);
12443
+ return -EINVAL;
12444
+ }
12445
+
12446
+ vid_index = ags ->index;
12447
+ vid_v = ags ->data;
12448
+ ret = switchdSetAclVidRemark(vid_index, vid_v);
12449
+ FUNC_MSG_OUT;
12450
+
12451
+ return ret;
12452
+}
12453
+
12454
+int switchdGetAclVidRemark(int index, int *gdata_p)
12455
+{
12456
+
12457
+ if (index<0 || index>15) {
12458
+ ip1811drv_err("Error: index=%d\n", index);
12459
+ return -EINVAL;
12460
+ }
12461
+
12462
+ *gdata_p = _ReadRegBits(2, P2REG_ACL_VID_REMARK_00+index, 0, 15);
12463
+
12464
+ return 0;
12465
+}
12466
+EXPORT_SYMBOL(switchdGetAclVidRemark);
12467
+
12468
+int getAclVidRemark(void *cdata, int len)
12469
+{
12470
+ int ret;
12471
+ struct AclGeneralSetting *ags = (struct AclGeneralSetting *)cdata;
12472
+ int vid_index;
12473
+
12474
+ FUNC_MSG_IN;
12475
+ if (sizeof(struct AclGeneralSetting) != len) {
12476
+ ip1811drv_err("Error: lengtn=%d\n", len);
12477
+ return -EINVAL;
12478
+ }
12479
+
12480
+ vid_index = ags ->index;
12481
+ ret = switchdGetAclVidRemark(vid_index, &(ags ->data));
12482
+ ip1811drv_dbg("cdata ->data=%d\n", ags ->data);
12483
+ FUNC_MSG_OUT;
12484
+
12485
+ return ret;
12486
+}
12487
+
12488
+int acl_write_table_move(int from_block, int from_index, int to_block, int to_index)
12489
+{
12490
+ int i;
12491
+ u16 u16array[10];
12492
+ u16 u16dat;
12493
+
12494
+ IP2Page(1);
12495
+
12496
+ // rule
12497
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0x8000|from_index|((from_block&0x3)<<5));
12498
+ for(i=0; i<10; i++) {
12499
+ u16dat = Read_Reg(P1REG_ACL_TABLE_DATA_E1+i);
12500
+ u16array[i] = u16dat;
12501
+ }
12502
+ acl_clean_table_rule(from_block, from_index);
12503
+ for(i=0; i<10; i++) {
12504
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1+i, u16array[i]);
12505
+ }
12506
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC000|to_index|((to_block&0x3)<<5));
12507
+
12508
+ // act
12509
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0x8100|from_index|((from_block&0x3)<<5));
12510
+ for(i=0; i<10; i++) {
12511
+ u16dat = Read_Reg(P1REG_ACL_TABLE_DATA_E1+i);
12512
+ u16array[i] = u16dat;
12513
+ }
12514
+ acl_clean_table_act(from_block, from_index);
12515
+ for(i=0; i<10; i++) {
12516
+ Write_Reg(P1REG_ACL_TABLE_DATA_E1+i, u16array[i]);
12517
+ }
12518
+ Write_Reg(P1REG_ACL_TABLE_ACCESS, 0xC100|to_index|((to_block&0x3)<<5));
12519
+
12520
+ m_acl ->used_entry_mask[to_block] |= BIT(to_index);
12521
+ m_acl ->used_entry_mask[from_block] &= ~BIT(from_index);
12522
+
12523
+ return 0;
12524
+}
12525
+
12526
+int set_rule_index_remap(void)
12527
+{
12528
+ int i, j;
12529
+ int index_move_to;
12530
+ int block_move_to;
12531
+ int index_move_from;
12532
+ int block_move_from;
12533
+ int index_move_range;
12534
+ struct acl_man_rule *mr;
12535
+
12536
+ ip1811drv_dbg("<DBG_DR_ACL> set_rule_index_remap()\n");
12537
+
12538
+ for(i=0; i<64; i++) {
12539
+ if(m_acl ->used_entry_mask[i>>4] & BIT(i%16)) { // entry i rule exist
12540
+ } else { // entry i rule not exist
12541
+ int no_entry = 1;
12542
+ block_move_to = (i>>4)&0x3;
12543
+ index_move_to = i&0xF;
12544
+ block_move_from = 3;
12545
+ index_move_from = 16;
12546
+ index_move_range= 0;
12547
+ // scan closest entry
12548
+ list_for_each_entry(mr, &m_acl ->rule_list, rule_entry) {
12549
+ if(mr->func_used != ACL_RULE_FUNC_USED_SNOOP) {
12550
+ if((16*mr->start_block+mr->start_index)>i) {
12551
+ if(((16*mr->start_block+mr->start_index)<(block_move_from*16+index_move_from)) && (mr->num_entries<=(16-index_move_to))) {
12552
+ block_move_from = mr->start_block;
12553
+ index_move_from = mr->start_index;
12554
+ index_move_range = mr->num_entries;
12555
+ no_entry = 0;
12556
+ }
12557
+ }
12558
+ }
12559
+ }
12560
+
12561
+ if(no_entry)
12562
+ continue;
12563
+
12564
+ // move exist entry to empty rule index
12565
+ for(j=0; j<index_move_range; j++) {
12566
+ acl_write_table_move(block_move_from, index_move_from+j, block_move_to, index_move_to+j);
12567
+ }
12568
+
12569
+ // modify entry info
12570
+ list_for_each_entry(mr, &m_acl ->rule_list, rule_entry) {
12571
+ if((mr->start_block==block_move_from) && (mr->start_index==index_move_from)) {
12572
+ mr->start_block = block_move_to;
12573
+ mr->start_index = index_move_to;
12574
+ }
12575
+ }
12576
+ // assign i to be link entry end
12577
+ i += (index_move_range-1);
12578
+ }
12579
+ ip1811drv_dbg("<DBG_DR_ACL> set_rule_index_remap(): entry from block(%d)/index(%d) to block(%d)/index(%d)\n", block_move_from, index_move_from, block_move_to, index_move_to);
12580
+
12581
+ }
12582
+
12583
+ return 0;
12584
+}
12585
+
12586
+int switchdSetAclStormPeriod(int period)
12587
+{
12588
+ if (period& (~0x3)) {
12589
+ ip1811drv_err("Error: period=0x%x\n", period);
12590
+ return -EINVAL;
12591
+ }
12592
+ ip1811drv_dbg("clear period=0x%x\n", period);
12593
+ _WriteRegBits(1, P1REG_MISCCFG, 4, 2, period);
12594
+ return 0;
12595
+}
12596
+EXPORT_SYMBOL(switchdSetAclStormPeriod);
12597
+
12598
+int setAclStormPeriod(void *cdata, int len)
12599
+{
12600
+ int ret;
12601
+ struct GeneralSetting *gs = (struct GeneralSetting *)cdata;
12602
+ int period;
12603
+
12604
+ FUNC_MSG_IN;
12605
+ if (sizeof(struct GeneralSetting) != len) {
12606
+ ip1811drv_err("Error: lengtn=%d\n", len);
12607
+ return -EINVAL;
12608
+ }
12609
+
12610
+ period = gs ->gdata;
12611
+ ret = switchdSetAclStormPeriod(period);
12612
+ FUNC_MSG_OUT;
12613
+
12614
+ return ret;
12615
+}
12616
+
12617
+int switchdGetAclStormPeriod(int *gdata_p)
12618
+{
12619
+ *gdata_p = _ReadRegBits(1, P1REG_MISCCFG, 4, 2);
12620
+ return 0;
12621
+}
12622
+EXPORT_SYMBOL(switchdGetAclStormPeriod);
12623
+
12624
+int getAclStormPeriod(void *cdata, int len)
12625
+{
12626
+ int ret;
12627
+ struct GeneralSetting *gs = (struct GeneralSetting *)cdata;
12628
+
12629
+ FUNC_MSG_IN;
12630
+ if (sizeof(struct GeneralSetting) != len) {
12631
+ ip1811drv_err("Error: lengtn=%d\n", len);
12632
+ return -EINVAL;
12633
+ }
12634
+
12635
+ ret = switchdGetAclStormPeriod(&(gs ->gdata));
12636
+ ip1811drv_dbg("cdata ->gdata=%d\n", gs ->gdata);
12637
+ FUNC_MSG_OUT;
12638
+
12639
+ return ret;
12640
+}
12641
+
12642
+int switchdSetAclStorm(int index, int value)
12643
+{
12644
+ if (index<0 || index>2) {
12645
+ ip1811drv_err("Error: index=%d\n", index);
12646
+ return -EINVAL;
12647
+ }
12648
+
12649
+ if (value & (~0xFFFF)) {
12650
+ ip1811drv_err("Error: value=%x\n", value);
12651
+ return -EINVAL;
12652
+ }
12653
+ _WriteRegBits(1, P1REG_MISCCFG, 13, 1, 1);
12654
+ ip1811drv_dbg("index=%d\n", index);
12655
+ ip1811drv_dbg("value=0x%x\n", value);
12656
+ _WriteRegBits(1, P1REG_ACL_STORM_0+index, 0, 16, value);
12657
+ _WriteRegBits(1, P1REG_MISCCFG, 13, 1, 0);
12658
+ return 0;
12659
+}
12660
+EXPORT_SYMBOL(switchdSetAclStorm);
12661
+
12662
+int setAclStorm(void *cdata, int len)
12663
+{
12664
+ int ret;
12665
+ struct AclGeneralSetting *ags = (struct AclGeneralSetting *)cdata;
12666
+ int storm_index;
12667
+ int storm_v;
12668
+
12669
+ FUNC_MSG_IN;
12670
+ if (sizeof(struct AclGeneralSetting) != len) {
12671
+ ip1811drv_err("Error: lengtn=%d\n", len);
12672
+ return -EINVAL;
12673
+ }
12674
+
12675
+ storm_index = ags ->index;
12676
+ storm_v = ags ->data;
12677
+ ret = switchdSetAclStorm(storm_index, storm_v);
12678
+ FUNC_MSG_OUT;
12679
+
12680
+ return ret;
12681
+}
12682
+
12683
+int switchdGetAclStorm(int index, int *gdata_p)
12684
+{
12685
+ if (index<0 || index>2) {
12686
+ ip1811drv_err("Error: index=%d\n", index);
12687
+ return -EINVAL;
12688
+ }
12689
+ _WriteRegBits(1, P1REG_MISCCFG, 13, 1, 1);
12690
+ *gdata_p = _ReadRegBits(1, P1REG_ACL_STORM_0+index, 0, 16);
12691
+ _WriteRegBits(1, P1REG_MISCCFG, 13, 1, 0);
12692
+ return 0;
12693
+}
12694
+EXPORT_SYMBOL(switchdGetAclStorm);
12695
+
12696
+int getAclStorm(void *cdata, int len)
12697
+{
12698
+ int ret;
12699
+ struct AclGeneralSetting *ags = (struct AclGeneralSetting *)cdata;
12700
+ int storm_index;
12701
+
12702
+ FUNC_MSG_IN;
12703
+ if (sizeof(struct AclGeneralSetting) != len) {
12704
+ ip1811drv_err("Error: lengtn=%d\n", len);
12705
+ return -EINVAL;
12706
+ }
12707
+
12708
+ storm_index = ags ->index;
12709
+ ret = switchdGetAclStorm(storm_index, &(ags ->data));
12710
+ ip1811drv_dbg("cdata ->data=%d\n", ags ->data);
12711
+ FUNC_MSG_OUT;
12712
+
12713
+ return ret;
12714
+}
12715
+//------------ ACL functions:common end -----------------------
12716
+
12717
+//------------------------------------------------
12718
+//common_bandwidth
12719
+int switchdSetBandwidthIngressRate(int port, unsigned long rate)
12720
+{
12721
+ if (port < 0 || port >= MAX_PHY_NUM)
12722
+ {
12723
+ ip1811drv_err("Error: port=%d\n", port);
12724
+ return -EINVAL;
12725
+ }
12726
+ if (rate > MAX_GIGA_SPEED)
12727
+ {
12728
+ ip1811drv_err("Error: pdata=0x%08X\n", (u16)rate);
12729
+ return -EINVAL;
12730
+ }
12731
+
12732
+ IP2Page(0);
12733
+ if (rate == 0 || rate == MAX_GIGA_SPEED || (port < MAX_PHY_TP_NUM && rate >= MAX_TP_SPEED))
12734
+ { Write_Reg(P0REG_INGRESS_RATE_CTRL0+port,0); }
12735
+ else if(rate > 0 && rate < MAX_GIGA_SPEED)
12736
+ {
12737
+ if(port < MAX_PHY_TP_NUM && rate >= (MAX_TP_SPEED/RATE_SCALE_UNIT)*RATE_SCALE_UNIT)
12738
+ { Write_Reg(P0REG_INGRESS_RATE_CTRL0+port,0); }
12739
+ else if(rate >= (MAX_GIGA_SPEED/RATE_SCALE_UNIT)*RATE_SCALE_UNIT)
12740
+ {
12741
+ Write_Reg(P0REG_INGRESS_RATE_CTRL0+port,0);
12742
+#ifdef COMBINED_PORT
12743
+ if (port==9)
12744
+ Write_Reg(P0REG_INGRESS_RATE_CTRL0+port+1,0);
12745
+#endif
12746
+ }
12747
+ else
12748
+ {
12749
+ if(rate%RATE_SCALE_UNIT)
12750
+ {
12751
+ Write_Reg(P0REG_INGRESS_RATE_CTRL0+port,rate/RATE_SCALE_UNIT+1);
12752
+#ifdef COMBINED_PORT
12753
+ if (port==9)
12754
+ Write_Reg(P0REG_INGRESS_RATE_CTRL0+port+1,rate/RATE_SCALE_UNIT+1);
12755
+#endif
12756
+ }
12757
+ else
12758
+ {
12759
+ Write_Reg(P0REG_INGRESS_RATE_CTRL0+port,rate/RATE_SCALE_UNIT);
12760
+#ifdef COMBINED_PORT
12761
+ if (port==9)
12762
+ Write_Reg(P0REG_INGRESS_RATE_CTRL0+port+1,rate/RATE_SCALE_UNIT);
12763
+#endif
12764
+ }
12765
+ }
12766
+ }
12767
+
12768
+ return 0;
12769
+}
12770
+EXPORT_SYMBOL(switchdSetBandwidthIngressRate);
12771
+int setBandwidthIngressRate(void *cdata, int len)
12772
+{
12773
+ int port; //1-28
12774
+ unsigned long rate;
12775
+ FUNC_MSG_IN;
12776
+ if (sizeof(struct ByPortSetting32) != len)
12777
+ {
12778
+ ip1811drv_err("Error: lengtn=%d\n", len);
12779
+ return -EINVAL;
12780
+ }
12781
+ port = ((struct ByPortSetting32 *)cdata)->port;
12782
+ rate = ((struct ByPortSetting32 *)cdata)->pdata;
12783
+
12784
+ if(switchdSetBandwidthIngressRate(port, rate) != 0)
12785
+ return -EINVAL;
12786
+
12787
+ FUNC_MSG_OUT;
12788
+ return 0;
12789
+}
12790
+
12791
+int switchdGetBandwidthIngressRate(int port, unsigned long *ptrInt)
12792
+{
12793
+ if (port < 0 || port >= MAX_PHY_NUM){
12794
+ ip1811drv_err("Error: port=%d\n", port);
12795
+ return -EINVAL;
12796
+ }
12797
+ ip1811drv_dbg("port=%d\n", port);
12798
+
12799
+#ifdef COMBINED_PORT
12800
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
12801
+ port++;
12802
+#endif
12803
+ *ptrInt = (unsigned long)(_ReadRegBits(0, P0REG_INGRESS_RATE_CTRL0+port, 0, 14)*64000);
12804
+
12805
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
12806
+
12807
+ return 0;
12808
+}
12809
+EXPORT_SYMBOL(switchdGetBandwidthIngressRate);
12810
+int getBandwidthIngressRate(void *cdata, int len)
12811
+{
12812
+ int port;
12813
+ unsigned long rate;
12814
+
12815
+ FUNC_MSG_IN;
12816
+ if (sizeof(struct ByPortSetting32) != len)
12817
+ {
12818
+ ip1811drv_err("Error: lengtn=%d\n", len);
12819
+ return -EINVAL;
12820
+ }
12821
+ port = ((struct ByPortSetting32 *)cdata)->port;
12822
+
12823
+ if(switchdGetBandwidthIngressRate(port, &rate) != 0)
12824
+ return -EINVAL;
12825
+
12826
+ ((struct ByPortSetting32 *)cdata)->pdata = rate;
12827
+ ip1811drv_dbg("cdata->port=%d\n", ((struct ByPortSetting32 *)cdata)->port);
12828
+ ip1811drv_dbg("cdata->pdata=0x%08X\n", (u16)((struct ByPortSetting32 *)cdata)->pdata);
12829
+ FUNC_MSG_OUT;
12830
+ return 0;
12831
+}
12832
+
12833
+int switchdSetBandwidthEgressRate(int port, unsigned long rate)
12834
+{
12835
+ if (port < 0 || port >= MAX_PHY_NUM)
12836
+ {
12837
+ ip1811drv_err("Error: port=%d\n", port);
12838
+ return -EINVAL;
12839
+ }
12840
+ if (rate > MAX_GIGA_SPEED)
12841
+ {
12842
+ ip1811drv_err("Error: pdata=0x%08X\n", (u16)rate);
12843
+ return -EINVAL;
12844
+ }
12845
+ IP2Page(8);
12846
+ if (rate == 0 || rate == MAX_GIGA_SPEED || (port < MAX_PHY_TP_NUM && rate >= MAX_TP_SPEED))
12847
+ { Write_Reg(P8REG_EGRESS_RATE_CTRL0+port,0); }
12848
+ else if(rate > 0 && rate < MAX_GIGA_SPEED)
12849
+ {
12850
+ if(port < MAX_PHY_TP_NUM && rate >= (MAX_TP_SPEED/RATE_SCALE_UNIT)*RATE_SCALE_UNIT)
12851
+ { Write_Reg(P8REG_EGRESS_RATE_CTRL0+port,0); }
12852
+ else if(rate >= (MAX_GIGA_SPEED/RATE_SCALE_UNIT)*RATE_SCALE_UNIT)
12853
+ {
12854
+ Write_Reg(P8REG_EGRESS_RATE_CTRL0+port,0);
12855
+#ifdef COMBINED_PORT
12856
+ if (port==9)
12857
+ Write_Reg(P8REG_EGRESS_RATE_CTRL0+port+1,0);
12858
+#endif
12859
+ }
12860
+ else
12861
+ {
12862
+ if(rate%RATE_SCALE_UNIT)
12863
+ {
12864
+ Write_Reg(P8REG_EGRESS_RATE_CTRL0+port,rate/RATE_SCALE_UNIT+1);
12865
+#ifdef COMBINED_PORT
12866
+ if (port==9)
12867
+ Write_Reg(P8REG_EGRESS_RATE_CTRL0+port+1,rate/RATE_SCALE_UNIT+1);
12868
+#endif
12869
+ }
12870
+ else
12871
+ {
12872
+ Write_Reg(P8REG_EGRESS_RATE_CTRL0+port,rate/RATE_SCALE_UNIT);
12873
+#ifdef COMBINED_PORT
12874
+ if (port==9)
12875
+ Write_Reg(P8REG_EGRESS_RATE_CTRL0+port+1,rate/RATE_SCALE_UNIT+1);
12876
+#endif
12877
+ }
12878
+ }
12879
+ }
12880
+
12881
+ return 0;
12882
+}
12883
+EXPORT_SYMBOL(switchdSetBandwidthEgressRate);
12884
+int setBandwidthEgressRate(void *cdata, int len)
12885
+{
12886
+ int port;
12887
+ unsigned long rate;
12888
+ FUNC_MSG_IN;
12889
+ if (sizeof(struct ByPortSetting32) != len)
12890
+ {
12891
+ ip1811drv_err("Error: lengtn=%d\n", len);
12892
+ return -EINVAL;
12893
+ }
12894
+ port = ((struct ByPortSetting32 *)cdata)->port;
12895
+ rate = ((struct ByPortSetting32 *)cdata)->pdata;
12896
+
12897
+ if(switchdSetBandwidthEgressRate(port, rate) != 0)
12898
+ return -EINVAL;
12899
+
12900
+ FUNC_MSG_OUT;
12901
+ return 0;
12902
+}
12903
+
12904
+int switchdGetBandwidthEgressRate(int port, unsigned long *ptrInt)
12905
+{
12906
+ if (port < 0 || port >= MAX_PHY_NUM){
12907
+ ip1811drv_err("Error: port=%d\n", port);
12908
+ return -EINVAL;
12909
+ }
12910
+ ip1811drv_dbg("port=%d\n", port);
12911
+
12912
+#ifdef COMBINED_PORT
12913
+ if (port==9 && _ReadRegBits(3, 0x15, 0, 1)) //port==9 && port10 link
12914
+ port++;
12915
+#endif
12916
+ *ptrInt = (unsigned long)(_ReadRegBits(8, P8REG_EGRESS_RATE_CTRL0+port, 0, 14)*64000);
12917
+
12918
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
12919
+
12920
+ return 0;
12921
+}
12922
+EXPORT_SYMBOL(switchdGetBandwidthEgressRate);
12923
+int getBandwidthEgressRate(void *cdata, int len)
12924
+{
12925
+ int port;
12926
+ unsigned long rate;
12927
+
12928
+ FUNC_MSG_IN;
12929
+ if (sizeof(struct ByPortSetting32) != len)
12930
+ {
12931
+ ip1811drv_err("Error: lengtn=%d\n", len);
12932
+ return -EINVAL;
12933
+ }
12934
+ port = ((struct ByPortSetting32 *)cdata)->port;
12935
+
12936
+ if(switchdGetBandwidthEgressRate(port, &rate) != 0)
12937
+ return -EINVAL;
12938
+
12939
+ ((struct ByPortSetting32 *)cdata)->pdata = rate;
12940
+ ip1811drv_dbg("cdata->port=%d\n", ((struct ByPortSetting32 *)cdata)->port);
12941
+ ip1811drv_dbg("cdata->pdata=0x%08X\n", (u16)((struct ByPortSetting32 *)cdata)->pdata);
12942
+ FUNC_MSG_OUT;
12943
+ return 0;
12944
+}
12945
+
12946
+int switchdSetBandwidthEgressPeriod(int period)
12947
+{
12948
+ if (period < 0 || period > 7){
12949
+ ip1811drv_err("Error: gdata=%d\n", period);
12950
+ return -EINVAL;
12951
+ }
12952
+ _WriteRegBits(8, P8REG_OUT_QUEUE_PARAM, 4, 3, period);
12953
+
12954
+ return 0;
12955
+}
12956
+EXPORT_SYMBOL(switchdSetBandwidthEgressPeriod);
12957
+int setBandwidthEgressPeriod(void *cdata, int len)
12958
+{
12959
+ int period;
12960
+ FUNC_MSG_IN;
12961
+ if (sizeof(struct GeneralSetting) != len)
12962
+ {
12963
+ ip1811drv_err("Error: lengtn=%d\n", len);
12964
+ return -EINVAL;
12965
+ }
12966
+
12967
+ period = ((struct GeneralSetting *)cdata)->gdata;
12968
+
12969
+ if(switchdSetBandwidthEgressPeriod(period) != 0)
12970
+ return -EINVAL;
12971
+
12972
+ FUNC_MSG_OUT;
12973
+ return 0;
12974
+}
12975
+
12976
+int switchdGetBandwidthEgressPeriod(int *ptrInt)
12977
+{
12978
+ *ptrInt = (int)_ReadRegBits(8,P8REG_OUT_QUEUE_PARAM,4,3);
12979
+
12980
+ ip1811drv_dbg("cdata ->pdata=%d\n", *ptrInt);
12981
+
12982
+ return 0;
12983
+}
12984
+EXPORT_SYMBOL(switchdGetBandwidthEgressPeriod);
12985
+int getBandwidthEgressPeriod(void *cdata, int len)
12986
+{
12987
+ int period=0;
12988
+
12989
+ FUNC_MSG_IN;
12990
+ if (sizeof(struct GeneralSetting) != len){
12991
+ ip1811drv_err("Error: lengtn=%d\n", len);
12992
+ return -EINVAL;
12993
+ }
12994
+
12995
+ if(switchdGetBandwidthEgressPeriod(&period) != 0)
12996
+ return -EINVAL;
12997
+
12998
+ ((struct GeneralSetting *)cdata)->gdata = period;
12999
+
13000
+ ip1811drv_dbg("cdata->gdata=0x%08X\n", ((struct GeneralSetting *)cdata)->gdata);
13001
+ FUNC_MSG_OUT;
13002
+ return 0;
13003
+}
13004
+
13005
+//------------ EEPROM functions:common start -----------------
13006
+#define CMD_EEPROM_READ 0x8000
13007
+#define CMD_EEPROM_WRITE 0xC000
13008
+#define EEPROM_BIT_COMPLETE 0x8000
13009
+#define REG_RETRY_COUNT 200
13010
+
13011
+u8 EE_Type = OP_EE_TYPE_Unknow;
13012
+u8 EE_Data [OP_EEPROM_LEN_24C32] = {0x0};
13013
+u8 EE_Flag [OP_EEPROM_LEN_24C32] = {0x0};
13014
+
13015
+u8 getEepromType(void)
13016
+{
13017
+ unsigned short val, i;
13018
+
13019
+ IP2Page(0xE);
13020
+ Write_Reg(PEREG_EEPROM_CMD+1, (unsigned short)(Read_Reg(PEREG_EEPROM_CMD+1)&0xFF00));
13021
+ IP2Page(0xE);
13022
+ Write_Reg(PEREG_EEPROM_CMD, (CMD_EEPROM_READ + 0x1));
13023
+
13024
+ IP2Page(0xE);
13025
+ val = Read_Reg(PEREG_EEPROM_CMD);
13026
+ for(i = 0 ; 0 == (val&EEPROM_BIT_COMPLETE) && i < REG_RETRY_COUNT ; i++)
13027
+ {
13028
+ IP2Page(0xE);
13029
+ val = Read_Reg(PEREG_EEPROM_CMD);
13030
+ }
13031
+
13032
+ if(i == REG_RETRY_COUNT)
13033
+ {
13034
+ ip1811drv_err("Error: get EEPROM type REG_RETRY_COUNT reached\n");
13035
+ return -EINVAL;
13036
+ }
13037
+
13038
+ IP2Page(0xE);
13039
+ val = Read_Reg(PEREG_EEPROM_DATA) & 0xFF;
13040
+
13041
+ udelay(5000);
13042
+
13043
+ if(val == 0x0B)
13044
+ return OP_EE_TYPE_C16;
13045
+ else if(val == 0x0D)
13046
+ return OP_EE_TYPE_C32;
13047
+ else
13048
+ return OP_EE_TYPE_Unknow;
13049
+}
13050
+
13051
+// EEPROM READ/WRITE
13052
+int setEepromByte(void *cdata, int len)
13053
+{
13054
+ unsigned short addr2write, i, val;
13055
+ unsigned char val2write;
13056
+
13057
+ FUNC_MSG_IN;
13058
+ if (sizeof(struct EepromSetting) != len)
13059
+ {
13060
+ ip1811drv_err("Error: length=%d\n", len);
13061
+ return -EINVAL;
13062
+ }
13063
+
13064
+ if(EE_Type==OP_EE_TYPE_Unknow)
13065
+ {
13066
+ EE_Type = getEepromType();
13067
+ if(EE_Type==OP_EE_TYPE_Unknow)
13068
+ {
13069
+ ip1811drv_err("Error: setEEPROM get type failed\n");
13070
+ return -EINVAL;
13071
+ }
13072
+ ip1811drv_dbg("set EEPROM type->%X\n", EE_Type);
13073
+ }
13074
+
13075
+ addr2write = ((struct EepromSetting *)cdata)->addr;
13076
+ val2write = ((struct EepromSetting *)cdata)->value;
13077
+ if (addr2write > (EE_Type?OP_EEPROM_LEN_24C32:OP_EEPROM_LEN_24C16))
13078
+ {
13079
+ ip1811drv_err("Error: addr=0x%04X\n", addr2write);
13080
+ return -EINVAL;
13081
+ }
13082
+ ip1811drv_dbg("type %X set addr:%04X , value:%02X\n", EE_Type, addr2write, val2write);
13083
+
13084
+ // update eeprom hardware
13085
+ IP2Page(0xE);
13086
+ Write_Reg(PEREG_EEPROM_DATA, val2write);
13087
+ IP2Page(0xE);
13088
+ if(EE_Type==OP_EE_TYPE_C16)
13089
+ {
13090
+ Write_Reg(PEREG_EEPROM_CMD, (CMD_EEPROM_WRITE + addr2write));
13091
+ }
13092
+ else
13093
+ {
13094
+ Write_Reg(PEREG_EEPROM_CMD+1, (unsigned short)((Read_Reg(PEREG_EEPROM_CMD+1)&0xFF00)|((addr2write>>8)&0xFF)));
13095
+ IP2Page(0xE);
13096
+ Write_Reg(PEREG_EEPROM_CMD, (CMD_EEPROM_WRITE + (addr2write&0xFF)));
13097
+ }
13098
+
13099
+ IP2Page(0xE);
13100
+ val = Read_Reg(PEREG_EEPROM_CMD);
13101
+ for(i = 0 ; 0 == (val&EEPROM_BIT_COMPLETE) && i < REG_RETRY_COUNT ; i++)
13102
+ {
13103
+ IP2Page(0xE);
13104
+ val = Read_Reg(PEREG_EEPROM_CMD);
13105
+ }
13106
+
13107
+ if(i == REG_RETRY_COUNT)
13108
+ {
13109
+ ip1811drv_err("Error: set EEPROM REG_RETRY_COUNT reached %04X\n", addr2write);
13110
+ return -EINVAL;
13111
+ }
13112
+
13113
+// udelay(5000);
13114
+
13115
+ // update eeprom driver mem
13116
+ EE_Flag[addr2write] = 0x1;
13117
+ EE_Data[addr2write] = val2write;
13118
+
13119
+ ip1811drv_dbg("EE set done\n");
13120
+ FUNC_MSG_OUT;
13121
+ return 0;
13122
+}
13123
+
13124
+int getEepromByte(void *cdata, int len)
13125
+{
13126
+ unsigned short addr2read, i, val;
13127
+ unsigned char val2return;
13128
+
13129
+ FUNC_MSG_IN;
13130
+ if (sizeof(struct EepromSetting) != len)
13131
+ {
13132
+ ip1811drv_err("Error: length=%d\n", len);
13133
+ return -EINVAL;
13134
+ }
13135
+
13136
+ if(EE_Type==OP_EE_TYPE_Unknow)
13137
+ {
13138
+ EE_Type = getEepromType();
13139
+ if(EE_Type==OP_EE_TYPE_Unknow)
13140
+ {
13141
+ ip1811drv_err("Error: getEEPROM get type failed\n");
13142
+ return -EINVAL;
13143
+ }
13144
+ ip1811drv_dbg("set EEPROM type->%X\n", EE_Type);
13145
+ }
13146
+
13147
+ addr2read = ((struct EepromSetting *)cdata)->addr;
13148
+ if (addr2read > (EE_Type?OP_EEPROM_LEN_24C32:OP_EEPROM_LEN_24C16))
13149
+ {
13150
+ ip1811drv_err("Error: addr=0x%04X\n", addr2read);
13151
+ return -EINVAL;
13152
+ }
13153
+ ip1811drv_dbg("type %X get addr:%04X\n", EE_Type, addr2read);
13154
+
13155
+ if(EE_Flag[addr2read]==0x1) // return driver value
13156
+ {
13157
+ val2return = EE_Data[addr2read];
13158
+ }
13159
+ else // update driver memory
13160
+ {
13161
+ IP2Page(0xE);
13162
+ if(EE_Type==OP_EE_TYPE_C16)
13163
+ {
13164
+ Write_Reg(PEREG_EEPROM_CMD, (CMD_EEPROM_READ + addr2read));
13165
+ }
13166
+ else
13167
+ {
13168
+ Write_Reg(PEREG_EEPROM_CMD+1, (unsigned short)((Read_Reg(PEREG_EEPROM_CMD+1)&0xFF00)|((addr2read>>8)&0xFF)));
13169
+ IP2Page(0xE);
13170
+ Write_Reg(PEREG_EEPROM_CMD, (CMD_EEPROM_READ + (addr2read & 0xFF)));
13171
+ }
13172
+
13173
+ IP2Page(0xE);
13174
+ val = Read_Reg(PEREG_EEPROM_CMD);
13175
+ for(i = 0 ; 0 == (val&EEPROM_BIT_COMPLETE) && i < REG_RETRY_COUNT ; i++)
13176
+ {
13177
+ IP2Page(0xE);
13178
+ val = Read_Reg(PEREG_EEPROM_CMD);
13179
+ }
13180
+
13181
+ if(i == REG_RETRY_COUNT)
13182
+ {
13183
+ ip1811drv_err("Error: get EEPROM REG_RETRY_COUNT reached %04X\n", addr2read);
13184
+ return -EINVAL;
13185
+ }
13186
+
13187
+ IP2Page(0xE);
13188
+ val2return = Read_Reg(PEREG_EEPROM_DATA) & 0xFF;
13189
+
13190
+ EE_Flag[addr2read] = 0x1;
13191
+ EE_Data[addr2read] = val2return;
13192
+
13193
+// udelay(5000);
13194
+ }
13195
+
13196
+ ((struct EepromSetting *)cdata)->value = val2return;
13197
+ ip1811drv_dbg("EE get done and value:%04X\n", val2return);
13198
+ FUNC_MSG_OUT;
13199
+ return 0;
13200
+}
13201
+//------------ EEPROM functions:common end -----------------
13202
+
13203
+//------------ HSR functions:common Start -----------------------
13204
+int setHSREnable(void *cdata, int len)
13205
+{
13206
+ int ret;
13207
+
13208
+ FUNC_MSG_IN;
13209
+ ret = _setGeneralEnable(cdata, len, 0x02, P2REG_HSR_REG_SETTING_1, 0);
13210
+ FUNC_MSG_OUT;
13211
+
13212
+ return ret;
13213
+}
13214
+
13215
+int getHSREnable(void *cdata, int len)
13216
+{
13217
+ int ret;
13218
+
13219
+ FUNC_MSG_IN;
13220
+ ret = _getGeneralEnable(cdata, len, 0x02, P2REG_HSR_REG_SETTING_1, 0);
13221
+ FUNC_MSG_OUT;
13222
+
13223
+ return ret;
13224
+}
13225
+
13226
+int switchdSetHSRMode(int mode)
13227
+{
13228
+ if( mode != OP_HSR_MANDATORY && mode != OP_HSR_UNICAST ){
13229
+ ip1811drv_err("Error: mode=%X\n", mode);
13230
+ return -EINVAL;
13231
+ }
13232
+
13233
+ ip1811drv_dbg("cdata ->mode=%d\n", mode);
13234
+
13235
+ if(mode==OP_HSR_MANDATORY){
13236
+ _WriteRegBits(2, P2REG_HSR_REG_SETTING_1, 10, 2, 0x3);
13237
+ _WriteRegBits(2, P2REG_HSR_REG_SETTING_2, 8, 1, 0x1);
13238
+ _WriteRegBits(2, P2REG_HSR_REG_SETTING_2, 11, 1, 0x1);
13239
+ _WriteRegBits(2, P2REG_HSR_REG_SETTING_2, 0, 2, 0x0);
13240
+ _WriteRegBits(1, P1REG_MISCCFG, 13, 1, 0x1);
13241
+ IP2Page(0x1);
13242
+ Write_Reg(P1REG_LUTAGINGTIME, 0x0003);
13243
+ _WriteRegBits(1, P1REG_MISCCFG, 13, 1, 0x0);
13244
+ }
13245
+ else if(mode==OP_HSR_UNICAST){
13246
+ _WriteRegBits(2, P2REG_HSR_REG_SETTING_1, 10, 2, 0x3);
13247
+ _WriteRegBits(2, P2REG_HSR_REG_SETTING_2, 8, 1, 0x1);
13248
+ _WriteRegBits(2, P2REG_HSR_REG_SETTING_2, 11, 1, 0x1);
13249
+ _WriteRegBits(2, P2REG_HSR_REG_SETTING_2, 0, 2, 0x3);
13250
+ _WriteRegBits(1, P1REG_MISCCFG, 13, 1, 0x1);
13251
+ IP2Page(0x1);
13252
+ Write_Reg(P1REG_LUTAGINGTIME, 0x00A3);
13253
+ _WriteRegBits(1, P1REG_MISCCFG, 13, 1, 0x0);
13254
+ }
13255
+
13256
+ return 0;
13257
+}
13258
+EXPORT_SYMBOL(switchdSetHSRMode);
13259
+int setHSRMode(void *cdata, int len)
13260
+{
13261
+ int gdata;
13262
+
13263
+ if (sizeof(struct GeneralSetting) != len){
13264
+ ip1811drv_err("Error: lengtn=%d\n", len);
13265
+ return -EINVAL;
13266
+ }
13267
+ gdata = ((struct GeneralSetting *)cdata) ->gdata;
13268
+
13269
+ FUNC_MSG_IN;
13270
+ if(switchdSetHSRMode(gdata) != 0)
13271
+ return -EINVAL;
13272
+ FUNC_MSG_OUT;
13273
+
13274
+ return 0;
13275
+}
13276
+
13277
+void switchdGetHSRMode(int *ptrInt)
13278
+{
13279
+ int val;
13280
+
13281
+ val=(int)_ReadRegBits(2, P2REG_HSR_REG_SETTING_2, 0, 2);
13282
+ if(val==0x3)
13283
+ *ptrInt = OP_HSR_MANDATORY;
13284
+ else if(val==0x0)
13285
+ *ptrInt = OP_HSR_UNICAST;
13286
+}
13287
+EXPORT_SYMBOL(switchdGetHSRMode);
13288
+int getHSRMode(void *cdata, int len)
13289
+{
13290
+ int ret;
13291
+
13292
+ ip1811drv_dbg("ip1811: +getHSRMode...\n");
13293
+ if (sizeof(struct GeneralSetting) != len)
13294
+ return -EINVAL;
13295
+
13296
+ FUNC_MSG_IN;
13297
+ switchdGetHSRMode(&ret);
13298
+ FUNC_MSG_OUT;
13299
+
13300
+ ((struct GeneralSetting *)cdata) ->gdata = ret;
13301
+
13302
+ ip1811drv_dbg("cdata ->gdata=%d\n", ((struct GeneralSetting *)cdata) ->gdata);
13303
+ ip1811drv_dbg("ip1811: -getHSRMode...\n");
13304
+ return 0;
13305
+}
13306
+//------------ HSR functions:common end -----------------------
13307
+
13308
+void noFunc(void)
13309
+{}
kernel/drivers/net/ethernet/ip1811/ip1811op.h
....@@ -0,0 +1,427 @@
1
+#ifndef IP1811OP_H
2
+#define IP1811OP_H
3
+
4
+#define OP_FUNC_DISABLE 0
5
+#define OP_FUNC_ENABLE 1
6
+
7
+#define OP_SMI_DUPLEX_HALF 0
8
+#define OP_SMI_DUPLEX_FULL 1
9
+
10
+#define OP_SMI_SPEED_1000 1000
11
+#define OP_SMI_SPEED_100 100
12
+#define OP_SMI_SPEED_10 10
13
+
14
+#define OP_CAP_PTCL_BPDU 0
15
+#define OP_CAP_PTCL_SLOW 1
16
+#define OP_CAP_PTCL_802_1X 2
17
+#define OP_CAP_PTCL_LLDP 3
18
+#define OP_CAP_PTCL_GRP0 4
19
+#define OP_CAP_PTCL_BRIDGE 5
20
+#define OP_CAP_PTCL_GRP1 6
21
+#define OP_CAP_PTCL_GARP 7
22
+#define OP_CAP_PTCL_GRP2 8
23
+#define OP_CAP_PTCL_GRP3 9
24
+
25
+#define OP_CAP_ACT_FORWARD 0
26
+#define OP_CAP_ACT_ALL_PORT 1
27
+#define OP_CAP_ACT_TO_CPU 2
28
+#define OP_CAP_ACT_DROP 3
29
+
30
+enum{
31
+ OP_CAT_INBAND_ARP, //0
32
+ OP_CAT_INBAND_IPV4,
33
+ OP_CAT_INBAND_IPV6,
34
+ OP_CAT_INBAND_PPPOE,
35
+ OP_CAT_INBAND_ICMP,
36
+ OP_CAT_INBAND_TCP,
37
+ OP_CAT_INBAND_UDP,
38
+ OP_CAT_INBAND_USER_ETH,
39
+ OP_CAT_INBAND_USER_IP1, //8
40
+ OP_CAT_INBAND_USER_IP2,
41
+ OP_CAT_INBAND_ICMPV6,
42
+ OP_CAT_INBAND_FTP,
43
+ OP_CAT_INBAND_SSH,
44
+ OP_CAT_INBAND_TELNET,
45
+ OP_CAT_INBAND_SMTP,
46
+ OP_CAT_INBAND_DNS,
47
+ OP_CAT_INBAND_BOOTP, //16
48
+ OP_CAT_INBAND_TFTP,
49
+ OP_CAT_INBAND_HTTP,
50
+ OP_CAT_INBAND_POP3,
51
+ OP_CAT_INBAND_NEWS,
52
+ OP_CAT_INBAND_SNTP,
53
+ OP_CAT_INBAND_NETBIOS,
54
+ OP_CAT_INBAND_IMAP,
55
+ OP_CAT_INBAND_SNMP, //24
56
+ OP_CAT_INBAND_HTTPS,
57
+ OP_CAT_INBAND_USER_TCPUDP_A,
58
+ OP_CAT_INBAND_USER_TCPUDP_B,
59
+ OP_CAT_INBAND_USER_TCPUDP_C,
60
+ OP_CAT_INBAND_USER_TCPUDP_D,
61
+ OP_CAT_INBAND_USER_TCPUDP_E,
62
+ OP_CAT_INBAND_TOTALNUM //31
63
+};
64
+
65
+enum{
66
+ OP_CAT_L3_ICMP, //0
67
+ OP_CAT_L3_TCP,
68
+ OP_CAT_L3_UDP,
69
+ OP_CAT_L3_OSPF,
70
+ OP_CAT_L3_USR1,
71
+ OP_CAT_L3_USR2,
72
+ OP_CAT_L3_IPV4_OTHER,
73
+ OP_CAT_L3_TOTALNUM //7
74
+};
75
+
76
+enum{
77
+ OP_TCPUDP_PTCL_FTP, //0
78
+ OP_TCPUDP_PTCL_SSH,
79
+ OP_TCPUDP_PTCL_TELNET,
80
+ OP_TCPUDP_PTCL_SMTP,
81
+ OP_TCPUDP_PTCL_DNS,
82
+ OP_TCPUDP_PTCL_DHCP,
83
+ OP_TCPUDP_PTCL_TFTP,
84
+ OP_TCPUDP_PTCL_HTTP,
85
+ OP_TCPUDP_PTCL_POP3,
86
+ OP_TCPUDP_PTCL_NEWS,
87
+ OP_TCPUDP_PTCL_SNTP, //10
88
+ OP_TCPUDP_PTCL_NETBIOS,
89
+ OP_TCPUDP_PTCL_IMAP,
90
+ OP_TCPUDP_PTCL_SNMP,
91
+ OP_TCPUDP_PTCL_HTTPS,
92
+ OP_TCPUDP_PTCL_USR_A,
93
+ OP_TCPUDP_PTCL_USR_B,
94
+ OP_TCPUDP_PTCL_USR_C,
95
+ OP_TCPUDP_PTCL_USR_D,
96
+ OP_TCPUDP_PTCL_USR_E,
97
+ OP_TCPUDP_PTCL_TOTALNUM //10
98
+};
99
+
100
+enum{
101
+ OP_TCPUDP_USER_A,
102
+ OP_TCPUDP_USER_B,
103
+ OP_TCPUDP_USER_C_LOWER,
104
+ OP_TCPUDP_USER_C_UPPER,
105
+ OP_TCPUDP_USER_D_LOWER,
106
+ OP_TCPUDP_USER_D_UPPER,
107
+ OP_TCPUDP_USER_E_LOWER,
108
+ OP_TCPUDP_USER_E_UPPER,
109
+ OP_TCPUDP_USER_TOTALNUM
110
+};
111
+
112
+enum{
113
+ OP_TCPUDP_ACT_Q0, //0
114
+ OP_TCPUDP_ACT_Q1,
115
+ OP_TCPUDP_ACT_Q2,
116
+ OP_TCPUDP_ACT_Q3,
117
+ OP_TCPUDP_ACT_Q4,
118
+ OP_TCPUDP_ACT_Q5,
119
+ OP_TCPUDP_ACT_Q6,
120
+ OP_TCPUDP_ACT_Q7,
121
+
122
+ OP_TCPUDP_ACT_TO_CPU = 9, //9
123
+ OP_TCPUDP_ACT_DROP,
124
+ OP_TCPUDP_ACT_ALL_PORT
125
+};
126
+
127
+enum{
128
+ OP_TCPFLAG_FLAG0,
129
+ OP_TCPFLAG_FLAG1,
130
+ OP_TCPFLAG_FLAG2,
131
+ OP_TCPFLAG_FLAG3
132
+};
133
+
134
+enum{
135
+ OP_TCPFLAG_ACT_NONE,
136
+ OP_TCPFLAG_ACT_STORMCTRL,
137
+ OP_TCPFLAG_ACT_TO_CPU,
138
+ OP_TCPFLAG_ACT_DROP
139
+};
140
+
141
+enum{
142
+ OP_IPV6_HEADER_FRAG,
143
+ OP_IPV6_HEADER_ENACP,
144
+ OP_IPV6_HEADER_AUTH,
145
+ OP_IPV6_HEADER_ICMPV6,
146
+ OP_IPV6_HEADER_ICMPV6_MLD,
147
+ OP_IPV6_HEADER_ICMPV6_NDP,
148
+ OP_IPV6_HEADER_USER1,
149
+ OP_IPV6_HEADER_USER2,
150
+ OP_IPV6_HEADER_ICMPV6_USER1,
151
+ OP_IPV6_HEADER_ICMPV6_USER2,
152
+ OP_IPV6_HEADER_TOTALNUM
153
+};
154
+
155
+enum{
156
+ OP_IPV6_HEADER_ICMPV6_USER1_HIGH,
157
+ OP_IPV6_HEADER_ICMPV6_USER1_LOW,
158
+ OP_IPV6_HEADER_ICMPV6_USER2_HIGH,
159
+ OP_IPV6_HEADER_ICMPV6_USER2_LOW
160
+};
161
+
162
+#define OP_SNIFFER1_METHOD_DISABLE 0
163
+#define OP_SNIFFER1_METHOD_EGRESS 1
164
+#define OP_SNIFFER1_METHOD_INGRESS 2
165
+#define OP_SNIFFER1_METHOD_BOTHDIR 3
166
+
167
+#define OP_SNIFFER1_PKT_MODIFY 0
168
+#define OP_SNIFFER1_PKT_KEEP 1
169
+
170
+#define OP_SNIFFER1_TAG_KEEP 0
171
+#define OP_SNIFFER1_TAG_MODIFY 1
172
+
173
+#define OP_SNIFFER2_LUT_TRIGGER_TARGET_DA 0
174
+#define OP_SNIFFER2_LUT_TRIGGER_TARGET_SA 1
175
+
176
+#define OP_STORM_BCST 0x01
177
+#define OP_STORM_MCST 0x02
178
+#define OP_STORM_DLF 0x04
179
+#define OP_STORM_ARP 0x08
180
+#define OP_STORM_ICMP 0x10
181
+
182
+#define OP_EOC_STATUS_NORMAL 0
183
+#define OP_EOC_STATUS_LOOP_DETECTED 1
184
+
185
+#define OP_EOC_RELEASE_TIME_1MIN 1
186
+#define OP_EOC_RELEASE_TIME_10MIN 10
187
+
188
+#define OP_LD_TIME_UNIT_500MS 0
189
+#define OP_LD_TIME_UNIT_10S 1
190
+
191
+#define OP_LD_STATUS_NORMAL 0
192
+#define OP_LD_STATUS_LOOP_DETECTED 1
193
+
194
+#define OP_WOL_MODE_SLAVE 0
195
+#define OP_WOL_MODE_MASTER 1
196
+
197
+#define OP_WOL_IDLE_UNIT_DISABLE 0
198
+#define OP_WOL_IDLE_UNIT_10s 1
199
+#define OP_WOL_IDLE_UNIT_1min 2
200
+#define OP_WOL_IDLE_UNIT_10min 3
201
+
202
+#define OP_WOL_STATUS_NORMAL 0
203
+#define OP_WOL_STATUS_SLEEPING 1
204
+#define OP_WOL_STATUS_RDY4SLEEP 2
205
+#define OP_WOL_STATUS_SLEEP 3
206
+
207
+#define OP_CPU_PORT_NORMAL 0
208
+#define OP_CPU_PORT_CPU 1
209
+
210
+#define OP_MAC_SELF_TEST_PKT_NO_32768 32768
211
+#define OP_MAC_SELF_TEST_PKT_NO_4096 4096
212
+#define OP_MAC_SELF_TEST_PKT_NO_256 256
213
+#define OP_MAC_SELF_TEST_PKT_NO_16 16
214
+
215
+#define OP_MAC_SELF_TEST_RESULT_FAIL 0
216
+#define OP_MAC_SELF_TEST_RESULT_PASS 1
217
+
218
+#define OP_BPDU_CMODE_GLOBAL 0
219
+#define OP_BPDU_CMODE_BY_PORT 1
220
+
221
+#define OP_STP_STATE_DISCARD 0
222
+#define OP_STP_STATE_BLOCK 1
223
+#define OP_STP_STATE_LEARN 2
224
+#define OP_STP_STATE_FORWARD 3
225
+
226
+#define OP_TRUNK_HASH_METHOD_PORT_ID 0
227
+#define OP_TRUNK_HASH_METHOD_SA 1
228
+#define OP_TRUNK_HASH_METHOD_DA 2
229
+#define OP_TRUNK_HASH_METHOD_DA_SA 3
230
+#define OP_TRUNK_HASH_METHOD_DIP 4
231
+#define OP_TRUNK_HASH_METHOD_SIP 5
232
+#define OP_TRUNK_HASH_METHOD_DP 6
233
+#define OP_TRUNK_HASH_METHOD_SP 7
234
+
235
+#define OP_TRUNK_COMBINE_G1_G2 5
236
+#define OP_TRUNK_COMBINE_G3_G4 6
237
+#define OP_TRUNK_COMBINE_G5_G6 7
238
+
239
+#define OP_LUT_LEARN_MODE_ALL_BY_AGING_TIME 0x0
240
+#define OP_LUT_LEARN_MODE_NEVER_OVERWRITE 0x1
241
+#define OP_LUT_LEARN_MODE_L2_BY_AGING_TIME 0x3
242
+
243
+#define OP_HASH_DIRECT 0
244
+#define OP_HASH_CRC 1
245
+
246
+#define OP_LUT_UNKNOWN_SA_FWD_2_CPU 0x0
247
+#define OP_LUT_UNKNOWN_SA_DROP 0x1
248
+#define OP_LUT_UNKNOWN_SA_FWD 0x2
249
+
250
+/* LUT flushing */
251
+#define OP_LUT_FLUSH_DYNAMIC_ONLY 0x0
252
+#define OP_LUT_FLUSH_STATIC_ONLY 0x1//not implemented
253
+#define OP_LUT_FLUSH_ALL 0x2
254
+
255
+/* LUT cfg */
256
+#define OP_LUT_CFG_FID 0
257
+#define OP_LUT_CFG_MD 1 //multi-destination, not implemented
258
+#define OP_LUT_CFG_TRAN 2 //vlan translation
259
+#define OP_LUT_CFG_MVT 3 //mac-based vlan
260
+
261
+/* LUT action */
262
+#define OP_ENTRY_CREATE 0
263
+#define OP_ENTRY_CONFIG 1
264
+#define OP_ENTRY_DELETE 2
265
+#define OP_ENTRY_CREATE_REG 3
266
+
267
+#define OP_ENTRY_GET_BY_INDEX 4
268
+#define OP_ENTRY_GET_BY_INFO 5
269
+
270
+/* the state for getLutValidEntry */
271
+#ifndef BIT
272
+#define BIT(x) (1UL << (x))
273
+#endif
274
+#define OP_LUT_STATE_DYNAMIC BIT(0)
275
+#define OP_LUT_STATE_STATIC BIT(1)
276
+#define OP_LUT_STATE_ALL (OP_LUT_STATE_DYNAMIC|OP_LUT_STATE_STATIC)
277
+//#define OP_LUT_STATE_ALL (OP_LUT_STATE_DYNAMIC|OP_LUT_STATE_ALL_STATIC)
278
+
279
+
280
+enum{
281
+ /* target entry is valid and index values are matched */
282
+ OP_ENTRY_EXISTS=0xE0,
283
+ /* target entry is valid but index values are not matched */
284
+ OP_ENTRY_NOT_MATCH,
285
+ /* target entry is invalid */
286
+ OP_ENTRY_NOT_FOUND,
287
+ /* target dynamice entry is valid and index values are matched */
288
+ OP_ENTRY_EXISTS_DYNAMIC,
289
+};
290
+
291
+#define OP_IGMP_PACKET_QUERY 0
292
+#define OP_IGMP_PACKET_LEAVE 4
293
+#define OP_IGMP_PACKET_UN_REG_DATA 8
294
+#define OP_IGMP_PACKET_UN_DEFINED 12
295
+#define OP_IGMP_PACKET_REPORT 1
296
+#define OP_IGMP_PACKET_GROUP_SPECIFIC_QUERY 6
297
+#define OP_IGMP_PACKET_REG_DATA 11
298
+
299
+#define OP_IGMP_RULE_BCST 0x01
300
+#define OP_IGMP_RULE_CPU 0x02
301
+#define OP_IGMP_RULE_ROUTER 0x04
302
+#define OP_IGMP_RULE_DROP 0x08
303
+#define OP_IGMP_RULE_GROUP_MEM 0x10
304
+
305
+#define OP_IGMP_SLT_IPV4 4
306
+#define OP_IGMP_SLT_IPV6 6
307
+
308
+#define OP_MLD_SEND_TO_PORTS 0
309
+#define OP_MLD_SEND_TO_PORTS_AND_CPU 1
310
+#define OP_MLD_SEND_TO_CPU 2
311
+#define OP_MLD_DROP 3
312
+
313
+#define OP_IMP_DROP_IP_MISMATCH 0
314
+#define OP_IMP_DROP_IP_MATCH 1
315
+
316
+#define OP_IMP_IPTYPE_4 0
317
+#define OP_IMP_IPTYPE_6 1
318
+
319
+#define OP_VLAN_EGRESS_UNI_FRAME 0x1
320
+#define OP_VLAN_EGRESS_ARP_FRAME 0x2
321
+#define OP_VLAN_EGRESS_MULTI_FRAME 0x4
322
+
323
+#define OP_VLAN_TAGGING_BY_PORT 0x0
324
+#define OP_VLAN_TAGGING_BY_VID 0x1
325
+
326
+#define OP_VLAN_TYPE_GROUP 0x0
327
+#define OP_VLAN_TYPE_TAG 0x1
328
+
329
+#define OP_VLAN_PROTOCOL_INVALID 0x0
330
+#define OP_VLAN_PROTOCOL_ETHER 0x1
331
+#define OP_VLAN_PROTOCOL_LLC 0x2
332
+#define OP_VLAN_PROTOCOL_1042 0x3
333
+
334
+enum{
335
+ OP_VLAN_QINQ_STAG_METHOD_ADDR,
336
+ OP_VLAN_QINQ_STAG_METHOD_ACL
337
+};
338
+
339
+#define OP_QOS_8021PEDTION_2005 0 //2005 edition
340
+#define OP_QOS_8021PEDTION_2005_EX 1 //2005 + exchange
341
+#define OP_QOS_8021PEDTION_EARLY 2 //early
342
+
343
+#define OP_QOS_GROUP1 0
344
+#define OP_QOS_GROUP2 1
345
+
346
+#define OP_CPU_IF_SPEED_HIGH 0
347
+#define OP_CPU_IF_SPEED_NORMAL 1
348
+
349
+enum{
350
+ OP_QOS_MODE_FIFO,
351
+ OP_QOS_MODE_WWBBT,
352
+ OP_QOS_MODE_SP1_WWBBT7,
353
+ OP_QOS_MODE_SP2_WWBBT6,
354
+ OP_QOS_MODE_SP4_WWBBT4,
355
+ OP_QOS_MODE_SP8
356
+};
357
+
358
+enum{
359
+ OP_QOS_NUM_Q0,
360
+ OP_QOS_NUM_Q1,
361
+ OP_QOS_NUM_Q2,
362
+ OP_QOS_NUM_Q3,
363
+ OP_QOS_NUM_Q4,
364
+ OP_QOS_NUM_Q5,
365
+ OP_QOS_NUM_Q6,
366
+ OP_QOS_NUM_Q7
367
+};
368
+enum{
369
+ OP_QOS_UNIT_64KBS,
370
+ OP_QOS_UNIT_1MBS,
371
+ OP_QOS_UNIT_2MBS,
372
+ OP_QOS_UNIT_4MBS
373
+};
374
+enum{
375
+ OP_QOS_REMAP_RX_Q0,
376
+ OP_QOS_REMAP_RX_Q1,
377
+ OP_QOS_REMAP_RX_Q2,
378
+ OP_QOS_REMAP_RX_Q3,
379
+ OP_QOS_REMAP_RX_Q4,
380
+ OP_QOS_REMAP_RX_Q5,
381
+ OP_QOS_REMAP_RX_Q6,
382
+ OP_QOS_REMAP_RX_Q7,
383
+ OP_QOS_REMAP_TX_Q0,
384
+ OP_QOS_REMAP_TX_Q1,
385
+ OP_QOS_REMAP_TX_Q2,
386
+ OP_QOS_REMAP_TX_Q3,
387
+ OP_QOS_REMAP_TX_Q4,
388
+ OP_QOS_REMAP_TX_Q5,
389
+ OP_QOS_REMAP_TX_Q6,
390
+ OP_QOS_REMAP_TX_Q7
391
+};
392
+#define OP_QOS_REMPA_RX 0
393
+#define OP_QOS_REMPA_TX 1
394
+enum{
395
+ OP_QOS_METHOD_WRR,
396
+ OP_QOS_METHOD_BW,
397
+ OP_QOS_METHOD_WFQ,
398
+ OP_QOS_METHOD_TWRR
399
+};
400
+
401
+#define OP_QOS_QBASE_DBM 0
402
+#define OP_QOS_QBASE_SBM 1
403
+
404
+enum{
405
+ OP_BW_PERIOD_4KB_500MS,
406
+ OP_BW_PERIOD_2KB_250MS,
407
+ OP_BW_PERIOD_1KB_125MS,
408
+ OP_BW_PERIOD_512B_63MS,
409
+ OP_BW_PERIOD_256B_31MS,
410
+ OP_BW_PERIOD_128B_16MS,
411
+ OP_BW_PERIOD_64B_8MS,
412
+ OP_BW_PERIOD_32B_4MS
413
+};
414
+
415
+#define OP_EEPROM_LEN_24C16 2048
416
+#define OP_EEPROM_LEN_24C32 4096
417
+
418
+enum Eeprom_Type {
419
+ OP_EE_TYPE_C16,
420
+ OP_EE_TYPE_C32,
421
+ OP_EE_TYPE_Unknow
422
+};
423
+
424
+#define OP_HSR_MANDATORY 0
425
+#define OP_HSR_UNICAST 1
426
+
427
+#endif /* IP1811OP_H */
kernel/drivers/net/ethernet/ip1811/ip1811reg.h
....@@ -0,0 +1,231 @@
1
+
2
+#define REG_Page 0xFF
3
+
4
+// Page0
5
+#define P0REG_MACBEHAVIOR 0x01
6
+#define P0REG_L2FRAMEGETCTRL 0x04
7
+#define P0REG_L2FRAMEGETCTRL1 0x05
8
+#define P0REG_BPDUPORTCAPCFG 0x0A
9
+#define P0REG_QOS8021PBASEPRIEN 0x26
10
+#define P0REG_QOSDSCPBASEPRIEN 0x27
11
+#define P0REG_QOSDSCPPRISETTING0 0x28
12
+#define P0REG_QOSDSCPPRISETTING1 0x29
13
+#define P0REG_QOSDSCPVALUE0 0x2A
14
+#define P0REG_QOSIPBASEPRIEN 0x31
15
+#define P0REG_INGRESS_RATE_CTRL0 0x40
16
+#define P0REG_TEST_PACKET_CTRL 0x4D
17
+#define P0REG_TEST_RESULT 0x4E
18
+#define P0REG_MACADDRESS 0x84
19
+#define P0REG_COSPORTBASEPRIEN 0x60
20
+#define P0REG_COS8021PBASEPRIEN 0x62
21
+#define P0REG_COSDSCPBASEPRIEN 0x64
22
+#define P0REG_COSTCPUDPBASEPRIEN 0x21
23
+#define P0REG_COSMACBASEPRIEN 0x66
24
+#define P0REG_COSVIDBASEPRIEN 0x68
25
+#define P0REG_COSIGMPBASEPRIEN 0x6A
26
+#define P0REG_COSPORTBASEQUEUE0 0x70
27
+#define P0REG_COSPORTBASEQUEUE1 0x71
28
+#define P0REG_COSPORTBASEQUEUE2 0x72
29
+#define P0REG_COSDSCPPRISETTING0 0x76
30
+#define P0REG_COSDSCPPRISETTING1 0x77
31
+#define P0REG_COSDSCPVALUE0 0x78
32
+#define P0REG_COSDSCPVALUE1 0x79
33
+#define P0REG_COSDSCPVALUE2 0x7A
34
+#define P0REG_COSDSCPVALUE3 0x7B
35
+#define P0REG_TCPUDPUSERDEF 0x10
36
+#define P0REG_TCPUDPPRICFG 0x18
37
+#define P0REG_TCPUDFUNCEN 0x1F
38
+#define P0REG_L3FRAMEGETCTRL 0x07
39
+#define P0REG_TCPCHECKEN 0x23
40
+#define P0REG_UDPCHECKEN 0x25
41
+#define P0REG_TCPFLGCFGGLB 0x30
42
+#define P0REG_TCPFLGCFG0 0x32
43
+#define P0REG_TCPFLGPORTEN 0x38
44
+#define P0REG_PORTLOCKEN 0x91
45
+#define P0REG_IPV6RLTCFG 0xA1
46
+#define P0REG_IPV6RLTFWD 0xA2
47
+#define POREG_MIBCOUN_CMD 0xA7
48
+#define POREG_MIBCOUN_DATA_L 0xA8
49
+#define POREG_MIBCOUN_DATA_H 0xA9
50
+#define P0REG_LDCONFIG 0xC0
51
+#define P0REG_LDEN 0xC1
52
+#define P0REG_LDTIMER 0xC3
53
+#define P0REG_LDSTATUS 0xCB
54
+#define P0REG_LDDA0 0xC4
55
+#define P0REG_LDSUBTYPE 0xC8
56
+#define P0REG_PTPCFG 0xA0
57
+
58
+// Page 1
59
+#define P1REG_CONFIG_CPUPORT 0x01
60
+#define P1REG_LUTAGINGTIME 0x02
61
+#define P1REG_SRCLEARNCFG 0x03
62
+#define P1REG_SRCLEARN_ENABLE 0x04
63
+#define P1REG_BSTORMTHRESH 0x09
64
+#define P1REG_ARPSTORMCFG 0x0A
65
+#define P1REG_ICMPSTORMCFG 0x0B
66
+#define P1REG_BSTORMEN 0x0C
67
+#define P1REG_MSTORMEN 0x0E
68
+#define P1REG_DLFSTORMEN 0x10
69
+#define P1REG_ARPSTORMEN 0x12
70
+#define P1REG_ICMPSTORMEN 0x14
71
+#define P1REG_OAM_8023_LB_CFG 0x14
72
+#define P1REG_TRUNKCFG 0x16
73
+#define P1REG_TRUNKGRP 0x17
74
+#define P1REG_SNIFCFG 0x1A
75
+#define P1REG_SNIFDEST 0x1B
76
+#define P1REG_SNIFSRC 0x1D
77
+#define P1REG_MEM_COMMAND 0x1D
78
+#define P1REG_MEM_TABLE_0 0x1E
79
+#define P1REG_PORTFLUSH 0x25
80
+#define P1REG_LUTFLUSH_CFG 0x27
81
+#define P1REG_LUTCFG 0x28
82
+#define P1REG_LUTDATA_0 0x29
83
+#define P1REG_LUTDATA_1 0x2A
84
+#define P1REG_LUTDATA_2 0x2B
85
+#define P1REG_LUTDATA_3 0x2C
86
+#define P1REG_LUTDATA_4 0x2D
87
+#define P1REG_LUTDATA_5 0x2E
88
+#define P1REG_MISCCFG 0x2F
89
+#define P1REG_MEM_MCT_COMMAND 0xA0
90
+#define P1REG_MEM_MCT_TABLE_0 0xA1
91
+#define P1REG_IGMPSNOP 0xA8
92
+#define P1REG_IGMPPKTFWD_0 0xA9
93
+#define P1REG_IGMPPKTFWD_1 0xAA
94
+#define P1REG_ROUTLIST 0xAE
95
+#define P1REG_MEM_SLT_COMMAND 0xB0
96
+#define P1REG_MEM_SLT_TABLE_0 0xB1
97
+#define P1REG_ACL_PATTEM_LOCATION_D3 0xD3
98
+#define P1REG_ACL_PATTEM_LOCATION_D4 0xD4
99
+#define P1REG_ACL_STORM_0 0xD7
100
+#define P1REG_ACL_BW_01 0xD7
101
+#define P1REG_ACL_TABLE_ACCESS 0xE0
102
+#define P1REG_ACL_TABLE_DATA_E1 0xE1
103
+#define P1REG_ACL_TABLE_DATA_E2 0xE2
104
+#define P1REG_ACL_TABLE_DATA_E3 0xE3
105
+#define P1REG_ACL_TABLE_DATA_E4 0xE4
106
+#define P1REG_ACL_TABLE_DATA_E5 0xE5
107
+#define P1REG_ACL_TABLE_DATA_E6 0xE6
108
+#define P1REG_ACL_TABLE_DATA_E7 0xE7
109
+#define P1REG_ACL_TABLE_DATA_E8 0xE8
110
+#define P1REG_ACL_TABLE_DATA_E9 0xE9
111
+#define P1REG_ACL_TABLE_DATA_EA 0xEA
112
+
113
+// Page2
114
+#define P2REG_VLANCFG 0x01
115
+#define P2REG_VLAN_INACTIVE_VID 0x02
116
+#define P2REG_VLAN_INGRESS_FRAME_0 0x04 //bit 0 for per port
117
+#define P2REG_VLAN_INGRESS_FRAME_1 0x06 //bit 1 for per port
118
+#define P2REG_VLAN_INGRESS_CHK 0x0A
119
+#define P2REG_VLANLOCAL 0x0C
120
+#define P2REG_VLAN_EGRESS_CFG 0x0E
121
+#define P2REG_VLAN_EGRESS_CFG1 0x10
122
+#define P2REG_VLAN_EXCLUSIVE 0x11
123
+#define P2REG_VLAN_ADDTAG 0x13
124
+#define P2REG_VLAN_RMVTAG 0x15
125
+#define P2REG_VLAN_UPLINK 0x17
126
+#define P2REG_VLAN_PVIDCFG 0x20
127
+#define P2REG_VLANGROUP 0x40
128
+#define P2REG_VLAN_MACBASED_ENTRY_0 0x80
129
+#define P2REG_VLAN_MACBASED_UNKNOWN 0x9B
130
+#define P2REG_VLAN_PROCOTOL_CFG 0xA0
131
+#define P2REG_SPANTREE_PORTCMD 0xB2
132
+#define P2REG_SPANTREE_PORTDTA 0xB3
133
+#define P2REG_VLANCMD 0xB5
134
+#define P2REG_VLANDAT0 0xB6
135
+#define P2REG_ACL_VID_REMARK_00 0xD0
136
+#define P2REG_HSR_REG_SETTING_1 0xFC
137
+#define P2REG_HSR_REG_SETTING_2 0xFD
138
+
139
+// Page 3
140
+#define P3REG_AN 0x01
141
+#define P3REG_SPG 0x02
142
+#define P3REG_SP 0x03
143
+#define P3REG_DUPLEX 0x04
144
+#define P3REG_PAUSE 0x05
145
+#define P3REG_ASPAUSE 0x06
146
+#define P3REG_BPRESS 0x07
147
+#define P3REG_POWERDOWN 0x08
148
+#define P3REG_UNIDIRECT 0x09
149
+#define P3REG_PORTSTS0 0x10
150
+#define P3REG_FORCELINK 0x24
151
+
152
+// Page4
153
+#define P4REG_OAM_8023AH_DYING_GASP 0x01
154
+#define P4REG_OAM_8023AH_CFG0 0x02
155
+#define P4REG_OAM_8023AH_REMOTE_CMD0 0x08
156
+#define P4REG_OAM_8023AH_REMOTE_DAT0 0x09
157
+#define P4REG_OAM_8023AH_STAT0 0x10
158
+#define P4REG_OAM_8023AH_REMOTE_INFO_OUI 0x1B
159
+#define P4REG_OAM_8023AH_RECV_DAT0 0x1D
160
+#define P4REG_OAM_8023AH_RECV_CMD0 0x1E
161
+#define P4REG_OAM_8023AH_FAULT_RECORD 0x1F
162
+
163
+// Page 6
164
+#define P6REG_QOS_REMAP_RX0 0x19
165
+
166
+// Page 7
167
+#define P7REG_QINQ_RMVTAG 0x01
168
+#define P7REG_QINQ_ADDTAG 0x02
169
+#define P7REG_QINQEGTYPELEN 0x03
170
+#define P7REG_QINQ_DET_RX 0x05
171
+#define P7REG_QINQ_DATA 0x06
172
+#define P7REG_QINQ_P_DATA 0x16
173
+#define P7REG_DSCP_REMARKING_01 0x22
174
+#define P7REG_TXDMA 0x33
175
+
176
+// Page8
177
+#define P8REG_QOSMODESELGROUP1 0x01
178
+#define P8REG_QOSGP1_WEIGHT0 0x02
179
+#define P8REG_QOSGP1_MAXBDWT0 0x0A
180
+#define P8REG_EGRESS_RATE_CTRL0 0x4C
181
+#define P8REG_OUT_QUEUE_PARAM 0x5E
182
+#define P8REG_QOSAGINGTIME 0x37
183
+#define P8REG_QOSPORTAGINGEN0 0x38
184
+#define P8REG_QOS_REMAP_TX0 0x11
185
+#define P8REG_QOSGROUPSEL 0x3F
186
+#define P8REG_QOSMODESELGROUP2 0x3E
187
+#define P8REG_QOSGP2_WEIGHT0 0x40
188
+#define P8REG_QOSGP2_MAXBDWT0 0x48
189
+#define P8REG_QOSQUEUEDBMEN 0x36
190
+#define P8REG_QOS_SBMDBMSEL0 0x30
191
+
192
+// Page9
193
+#define P9REG_PTP_CLOCK_RESET 0x00
194
+#define P9REG_PTP_TIMESTAMP_READ 0x01
195
+#define P9REG_PTP_CONFIGURATION 0x02
196
+#define P9REG_PTP_PORT_TIMESTAMP0 0x03
197
+#define P9REG_PTP_PORT_TIMESTAMP1 0x04
198
+#define P9REG_PTP_TIMESTAMP_CLEAR0 0x05
199
+#define P9REG_PTP_TIMESTAMP_CLEAR1 0x06
200
+#define P9REG_PTP_TIMEDATA_NANOSEC0 0x07
201
+#define P9REG_PTP_TIMEDATA_NANOSEC1 0x08
202
+#define P9REG_PTP_TIMEDATA_SEC0 0x09
203
+#define P9REG_PTP_TIMEDATA_SEC1 0x0A
204
+#define P9REG_PTP_TIMEDATA_SEC2 0x0B
205
+#define P9REG_PTP_CLOCK_CONTROL 0x0C
206
+#define P9REG_PTP_FREQUENCY_ADD0 0x0D
207
+#define P9REG_PTP_FREQUENCY_ADD1 0x0E
208
+#define P9REG_PTP_CLOCK_PERIOD 0x0F
209
+#define P9REG_PTP_FREQUENCY_COMPENSATION0 0x10
210
+#define P9REG_PTP_FREQUENCY_COMPENSATION1 0x11
211
+#define P9REG_PTP_FREQUENCY_COMPENSATION2 0x12
212
+#define P9REG_PTP_FREQUENCY_COMPENSATION3 0x13
213
+#define P9REG_PTP_FREQUENCY_COMPENSATION_CONTROL 0x14
214
+#define P9REG_PTP_PROGRAMMABLE_OUTPUT 0x15
215
+#define P9REG_PTP_INGRESS_LATENCY_10TP 0x1A
216
+#define P9REG_PTP_EGRESS_LATENCY_10TP 0x1B
217
+#define P9REG_PTP_INGRESS_LATENCY_100TP 0x1C
218
+#define P9REG_PTP_EGRESS_LATENCY_100TP 0x1D
219
+#define P9REG_PTP_INGRESS_LATENCY_FIBER 0x20
220
+#define P9REG_PTP_EGRESS_LATENCY_FIBER 0x21
221
+
222
+// PageD
223
+
224
+// PageE
225
+#define PEREG_SW_RESET 0x00
226
+#define PEREG_CPUMODE 0x03
227
+#define PEREG_SPTAG 0x05
228
+#define PEREG_INT_STATUS 0x07
229
+#define PEREG_LAST_GASP_CONFIG 0x08
230
+#define PEREG_EEPROM_CMD 0x0A
231
+#define PEREG_EEPROM_DATA 0x0C
kernel/drivers/net/ethernet/ip1811/ip218.h
....@@ -0,0 +1,29 @@
1
+#ifndef IP218_H
2
+#define IP218_H
3
+
4
+#if 1
5
+#define IP218_MAC_BASE 0xBC400000 //Virtual Address
6
+#else
7
+#define IP218_MAC_BASE 0x1C400000 //Physical Address
8
+#endif
9
+
10
+#define IP218_MAC_SMICTRL0 0x0004
11
+#define IP218_MAC_SMICTRL1 0x0008
12
+
13
+struct ip218_smictrl0{
14
+ unsigned long wr_data:16;
15
+ unsigned long en:1;
16
+ unsigned long rdwr:1;
17
+ unsigned long rev2:1;
18
+ unsigned long phy:5;
19
+ unsigned long rev1:3;
20
+ unsigned long reg:5;
21
+};
22
+
23
+struct ip218_smictrl1{
24
+ unsigned long mdc_clk_divisor:3;
25
+ unsigned long rev:13;
26
+ unsigned long rd_data:16;
27
+};
28
+
29
+#endif
kernel/drivers/net/ethernet/ip1811/libcommon.h
....@@ -0,0 +1,53 @@
1
+#ifndef __LIB_COMMON_H__
2
+#define __LIB_COMMON_H__
3
+#include <sys/types.h>//for u_int8_t
4
+
5
+#undef OK
6
+#define OK 0
7
+
8
+#undef ERROR
9
+#define ERROR -1
10
+
11
+#undef FALSE
12
+#define FALSE 0
13
+
14
+#undef TRUE
15
+#define TRUE 1
16
+
17
+#undef DISABLE
18
+#define DISABLE 0
19
+
20
+#undef ENABLE
21
+#define ENABLE 1
22
+
23
+#define FREE_SAFE(a) if(a!=NULL){free(a);a=NULL;}
24
+
25
+#define SV_WDT_WDT_TIME (100)//Unit depends on WORKQUEUE_DELAY_TIME defined in supervisor.c
26
+
27
+/************************************************************
28
+ * Name: getSysUptime
29
+ * Description: get system uptime from proc file
30
+ * Parameters: None
31
+ * Return value:failed: -1
32
+ * success: float type uptime
33
+ * **********************************************************/
34
+float getSysUptime(void);
35
+long getSysUptime_10ms(void);
36
+void daemonize(void);
37
+int lock_file(char *filename);
38
+int unlock_file(int fd, char *filename);
39
+
40
+void get_switch_mac(u_int8_t* macaddr);
41
+void get_switch_ip(u_int8_t *ip);
42
+void get_switch_netmask(u_int8_t *mask);
43
+void get_gateway_ip(u_int8_t *ip);
44
+void get_gateway_ipv6(u_int8_t *ipv6);
45
+void DER_OID_decoder(unsigned char *input_OID, unsigned int OIDLen, char *outputString);
46
+char popen_d(char *cmd, char *ret, unsigned int ret_len);
47
+void printfd(char *file, char *buf);
48
+char ipStr2Array(char *ip, char *buf);
49
+int do_fork_execvp(char *argv[]);
50
+int supervisor_wdt_add(char *command, const char *func_name, int wdt_life_time);
51
+int supervisor_wdt_del(char *command);
52
+int supervisor_wdt_reset(char *command);
53
+#endif//__LIB_COMMON_H__
kernel/drivers/net/ethernet/ip1811/list.h
....@@ -0,0 +1,517 @@
1
+/**
2
+ *
3
+ * I grub it from linux kernel source code and fix it for user space
4
+ * program. Of course, this is a GPL licensed header file.
5
+ *
6
+ * Here is a recipe to cook list.h for user space program
7
+ *
8
+ * 1. copy list.h from linux/include/list.h
9
+ * 2. remove
10
+ * - #ifdef __KERNE__ and its #endif
11
+ * - all #include line
12
+ * - prefetch() and rcu related functions
13
+ * 3. add macro offsetof() and container_of
14
+ *
15
+ * - kazutomo@mcs.anl.gov
16
+ */
17
+#ifndef _LINUX_LIST_H
18
+#define _LINUX_LIST_H
19
+#include <stddef.h>
20
+/**
21
+ * @name from other kernel headers
22
+ */
23
+/*@{*/
24
+
25
+/**
26
+ * Get offset of a member
27
+ */
28
+//#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
29
+
30
+/**
31
+ * Casts a member of a structure out to the containing structure
32
+ * @param ptr the pointer to the member.
33
+ * @param type the type of the container struct this is embedded in.
34
+ * @param member the name of the member within the struct.
35
+ *
36
+ */
37
+#define container_of(ptr, type, member) ({ \
38
+ const typeof( ((type *)0)->member ) *__mptr = (ptr); \
39
+ (type *)( (char *)__mptr - offsetof(type,member) );})
40
+/*@}*/
41
+
42
+
43
+/*
44
+ * These are non-NULL pointers that will result in page faults
45
+ * under normal circumstances, used to verify that nobody uses
46
+ * non-initialized list entries.
47
+ */
48
+#define LIST_POISON1 ((void *) 0x00100100)
49
+#define LIST_POISON2 ((void *) 0x00200200)
50
+
51
+/**
52
+ * Simple doubly linked list implementation.
53
+ *
54
+ * Some of the internal functions ("__xxx") are useful when
55
+ * manipulating whole lists rather than single entries, as
56
+ * sometimes we already know the next/prev entries and we can
57
+ * generate better code by using them directly rather than
58
+ * using the generic single-entry routines.
59
+ */
60
+struct list_head {
61
+ struct list_head *next, *prev;
62
+};
63
+
64
+#define LIST_HEAD_INIT(name) { &(name), &(name) }
65
+
66
+#define LIST_HEAD(name) \
67
+ struct list_head name = LIST_HEAD_INIT(name)
68
+
69
+#define INIT_LIST_HEAD(ptr) do { \
70
+ (ptr)->next = (ptr); (ptr)->prev = (ptr); \
71
+} while (0)
72
+
73
+/*
74
+ * Insert a new entry between two known consecutive entries.
75
+ *
76
+ * This is only for internal list manipulation where we know
77
+ * the prev/next entries already!
78
+ */
79
+static inline void __list_add(struct list_head *new,
80
+ struct list_head *prev,
81
+ struct list_head *next)
82
+{
83
+ next->prev = new;
84
+ new->next = next;
85
+ new->prev = prev;
86
+ prev->next = new;
87
+}
88
+
89
+/**
90
+ * list_add - add a new entry
91
+ * @new: new entry to be added
92
+ * @head: list head to add it after
93
+ *
94
+ * Insert a new entry after the specified head.
95
+ * This is good for implementing stacks.
96
+ */
97
+static inline void list_add(struct list_head *new, struct list_head *head)
98
+{
99
+ __list_add(new, head, head->next);
100
+}
101
+
102
+/**
103
+ * list_add_tail - add a new entry
104
+ * @new: new entry to be added
105
+ * @head: list head to add it before
106
+ *
107
+ * Insert a new entry before the specified head.
108
+ * This is useful for implementing queues.
109
+ */
110
+static inline void list_add_tail(struct list_head *new, struct list_head *head)
111
+{
112
+ __list_add(new, head->prev, head);
113
+}
114
+
115
+
116
+/*
117
+ * Delete a list entry by making the prev/next entries
118
+ * point to each other.
119
+ *
120
+ * This is only for internal list manipulation where we know
121
+ * the prev/next entries already!
122
+ */
123
+static inline void __list_del(struct list_head * prev, struct list_head * next)
124
+{
125
+ next->prev = prev;
126
+ prev->next = next;
127
+}
128
+
129
+/**
130
+ * list_del - deletes entry from list.
131
+ * @entry: the element to delete from the list.
132
+ * Note: list_empty on entry does not return true after this, the entry is
133
+ * in an undefined state.
134
+ */
135
+static inline void list_del(struct list_head *entry)
136
+{
137
+ __list_del(entry->prev, entry->next);
138
+ entry->next = LIST_POISON1;
139
+ entry->prev = LIST_POISON2;
140
+}
141
+
142
+
143
+
144
+/**
145
+ * list_del_init - deletes entry from list and reinitialize it.
146
+ * @entry: the element to delete from the list.
147
+ */
148
+static inline void list_del_init(struct list_head *entry)
149
+{
150
+ __list_del(entry->prev, entry->next);
151
+ INIT_LIST_HEAD(entry);
152
+}
153
+
154
+/**
155
+ * list_move - delete from one list and add as another's head
156
+ * @list: the entry to move
157
+ * @head: the head that will precede our entry
158
+ */
159
+static inline void list_move(struct list_head *list, struct list_head *head)
160
+{
161
+ __list_del(list->prev, list->next);
162
+ list_add(list, head);
163
+}
164
+
165
+/**
166
+ * list_move_tail - delete from one list and add as another's tail
167
+ * @list: the entry to move
168
+ * @head: the head that will follow our entry
169
+ */
170
+static inline void list_move_tail(struct list_head *list,
171
+ struct list_head *head)
172
+{
173
+ __list_del(list->prev, list->next);
174
+ list_add_tail(list, head);
175
+}
176
+
177
+/**
178
+ * list_empty - tests whether a list is empty
179
+ * @head: the list to test.
180
+ */
181
+static inline int list_empty(const struct list_head *head)
182
+{
183
+ return head->next == head;
184
+}
185
+
186
+static inline void __list_splice(struct list_head *list,
187
+ struct list_head *head)
188
+{
189
+ struct list_head *first = list->next;
190
+ struct list_head *last = list->prev;
191
+ struct list_head *at = head->next;
192
+
193
+ first->prev = head;
194
+ head->next = first;
195
+
196
+ last->next = at;
197
+ at->prev = last;
198
+}
199
+
200
+/**
201
+ * list_splice - join two lists
202
+ * @list: the new list to add.
203
+ * @head: the place to add it in the first list.
204
+ */
205
+static inline void list_splice(struct list_head *list, struct list_head *head)
206
+{
207
+ if (!list_empty(list))
208
+ __list_splice(list, head);
209
+}
210
+
211
+/**
212
+ * list_splice_init - join two lists and reinitialise the emptied list.
213
+ * @list: the new list to add.
214
+ * @head: the place to add it in the first list.
215
+ *
216
+ * The list at @list is reinitialised
217
+ */
218
+static inline void list_splice_init(struct list_head *list,
219
+ struct list_head *head)
220
+{
221
+ if (!list_empty(list)) {
222
+ __list_splice(list, head);
223
+ INIT_LIST_HEAD(list);
224
+ }
225
+}
226
+
227
+/**
228
+ * list_entry - get the struct for this entry
229
+ * @ptr: the &struct list_head pointer.
230
+ * @type: the type of the struct this is embedded in.
231
+ * @member: the name of the list_struct within the struct.
232
+ */
233
+#define list_entry(ptr, type, member) \
234
+ container_of(ptr, type, member)
235
+
236
+/**
237
+ * list_for_each - iterate over a list
238
+ * @pos: the &struct list_head to use as a loop counter.
239
+ * @head: the head for your list.
240
+ */
241
+
242
+#define list_for_each(pos, head) \
243
+ for (pos = (head)->next; pos != (head); \
244
+ pos = pos->next)
245
+
246
+/**
247
+ * __list_for_each - iterate over a list
248
+ * @pos: the &struct list_head to use as a loop counter.
249
+ * @head: the head for your list.
250
+ *
251
+ * This variant differs from list_for_each() in that it's the
252
+ * simplest possible list iteration code, no prefetching is done.
253
+ * Use this for code that knows the list to be very short (empty
254
+ * or 1 entry) most of the time.
255
+ */
256
+#define __list_for_each(pos, head) \
257
+ for (pos = (head)->next; pos != (head); pos = pos->next)
258
+
259
+/**
260
+ * list_for_each_prev - iterate over a list backwards
261
+ * @pos: the &struct list_head to use as a loop counter.
262
+ * @head: the head for your list.
263
+ */
264
+#define list_for_each_prev(pos, head) \
265
+ for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
266
+ pos = pos->prev)
267
+
268
+/**
269
+ * list_for_each_safe - iterate over a list safe against removal of list entry
270
+ * @pos: the &struct list_head to use as a loop counter.
271
+ * @n: another &struct list_head to use as temporary storage
272
+ * @head: the head for your list.
273
+ */
274
+#define list_for_each_safe(pos, n, head) \
275
+ for (pos = (head)->next, n = pos->next; pos != (head); \
276
+ pos = n, n = pos->next)
277
+
278
+/**
279
+ * list_for_each_entry - iterate over list of given type
280
+ * @pos: the type * to use as a loop counter.
281
+ * @head: the head for your list.
282
+ * @member: the name of the list_struct within the struct.
283
+ */
284
+#define list_for_each_entry(pos, head, member) \
285
+ for (pos = list_entry((head)->next, typeof(*pos), member); \
286
+ &pos->member != (head); \
287
+ pos = list_entry(pos->member.next, typeof(*pos), member))
288
+
289
+/**
290
+ * list_for_each_entry_reverse - iterate backwards over list of given type.
291
+ * @pos: the type * to use as a loop counter.
292
+ * @head: the head for your list.
293
+ * @member: the name of the list_struct within the struct.
294
+ */
295
+#define list_for_each_entry_reverse(pos, head, member) \
296
+ for (pos = list_entry((head)->prev, typeof(*pos), member); \
297
+ &pos->member != (head); \
298
+ pos = list_entry(pos->member.prev, typeof(*pos), member))
299
+
300
+/**
301
+ * list_prepare_entry - prepare a pos entry for use as a start point in
302
+ * list_for_each_entry_continue
303
+ * @pos: the type * to use as a start point
304
+ * @head: the head of the list
305
+ * @member: the name of the list_struct within the struct.
306
+ */
307
+#define list_prepare_entry(pos, head, member) \
308
+ ((pos) ? : list_entry(head, typeof(*pos), member))
309
+
310
+/**
311
+ * list_for_each_entry_continue - iterate over list of given type
312
+ * continuing after existing point
313
+ * @pos: the type * to use as a loop counter.
314
+ * @head: the head for your list.
315
+ * @member: the name of the list_struct within the struct.
316
+ */
317
+#define list_for_each_entry_continue(pos, head, member) \
318
+ for (pos = list_entry(pos->member.next, typeof(*pos), member); \
319
+ &pos->member != (head); \
320
+ pos = list_entry(pos->member.next, typeof(*pos), member))
321
+
322
+/**
323
+ * list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
324
+ * @pos: the type * to use as a loop counter.
325
+ * @n: another type * to use as temporary storage
326
+ * @head: the head for your list.
327
+ * @member: the name of the list_struct within the struct.
328
+ */
329
+#define list_for_each_entry_safe(pos, n, head, member) \
330
+ for (pos = list_entry((head)->next, typeof(*pos), member), \
331
+ n = list_entry(pos->member.next, typeof(*pos), member); \
332
+ &pos->member != (head); \
333
+ pos = n, n = list_entry(n->member.next, typeof(*n), member))
334
+
335
+/**
336
+ * list_for_each_entry_safe_continue - iterate over list of given type
337
+ * continuing after existing point safe against removal of list entry
338
+ * @pos: the type * to use as a loop counter.
339
+ * @n: another type * to use as temporary storage
340
+ * @head: the head for your list.
341
+ * @member: the name of the list_struct within the struct.
342
+ */
343
+#define list_for_each_entry_safe_continue(pos, n, head, member) \
344
+ for (pos = list_entry(pos->member.next, typeof(*pos), member), \
345
+ n = list_entry(pos->member.next, typeof(*pos), member); \
346
+ &pos->member != (head); \
347
+ pos = n, n = list_entry(n->member.next, typeof(*n), member))
348
+
349
+/**
350
+ * list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against
351
+ * removal of list entry
352
+ * @pos: the type * to use as a loop counter.
353
+ * @n: another type * to use as temporary storage
354
+ * @head: the head for your list.
355
+ * @member: the name of the list_struct within the struct.
356
+ */
357
+#define list_for_each_entry_safe_reverse(pos, n, head, member) \
358
+ for (pos = list_entry((head)->prev, typeof(*pos), member), \
359
+ n = list_entry(pos->member.prev, typeof(*pos), member); \
360
+ &pos->member != (head); \
361
+ pos = n, n = list_entry(n->member.prev, typeof(*n), member))
362
+
363
+
364
+
365
+
366
+/*
367
+ * Double linked lists with a single pointer list head.
368
+ * Mostly useful for hash tables where the two pointer list head is
369
+ * too wasteful.
370
+ * You lose the ability to access the tail in O(1).
371
+ */
372
+
373
+struct hlist_head {
374
+ struct hlist_node *first;
375
+};
376
+
377
+struct hlist_node {
378
+ struct hlist_node *next, **pprev;
379
+};
380
+
381
+#define HLIST_HEAD_INIT { .first = NULL }
382
+#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
383
+#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
384
+#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
385
+
386
+static inline int hlist_unhashed(const struct hlist_node *h)
387
+{
388
+ return !h->pprev;
389
+}
390
+
391
+static inline int hlist_empty(const struct hlist_head *h)
392
+{
393
+ return !h->first;
394
+}
395
+
396
+static inline void __hlist_del(struct hlist_node *n)
397
+{
398
+ struct hlist_node *next = n->next;
399
+ struct hlist_node **pprev = n->pprev;
400
+ *pprev = next;
401
+ if (next)
402
+ next->pprev = pprev;
403
+}
404
+
405
+static inline void hlist_del(struct hlist_node *n)
406
+{
407
+ __hlist_del(n);
408
+ n->next = LIST_POISON1;
409
+ n->pprev = LIST_POISON2;
410
+}
411
+
412
+
413
+static inline void hlist_del_init(struct hlist_node *n)
414
+{
415
+ if (n->pprev) {
416
+ __hlist_del(n);
417
+ INIT_HLIST_NODE(n);
418
+ }
419
+}
420
+
421
+static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
422
+{
423
+ struct hlist_node *first = h->first;
424
+ n->next = first;
425
+ if (first)
426
+ first->pprev = &n->next;
427
+ h->first = n;
428
+ n->pprev = &h->first;
429
+}
430
+
431
+
432
+
433
+/* next must be != NULL */
434
+static inline void hlist_add_before(struct hlist_node *n,
435
+ struct hlist_node *next)
436
+{
437
+ n->pprev = next->pprev;
438
+ n->next = next;
439
+ next->pprev = &n->next;
440
+ *(n->pprev) = n;
441
+}
442
+
443
+static inline void hlist_add_after(struct hlist_node *n,
444
+ struct hlist_node *next)
445
+{
446
+ next->next = n->next;
447
+ n->next = next;
448
+ next->pprev = &n->next;
449
+
450
+ if(next->next)
451
+ next->next->pprev = &next->next;
452
+}
453
+
454
+
455
+
456
+#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
457
+
458
+#define hlist_for_each(pos, head) \
459
+ for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
460
+ pos = pos->next)
461
+
462
+#define hlist_for_each_safe(pos, n, head) \
463
+ for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
464
+ pos = n)
465
+
466
+/**
467
+ * hlist_for_each_entry - iterate over list of given type
468
+ * @tpos: the type * to use as a loop counter.
469
+ * @pos: the &struct hlist_node to use as a loop counter.
470
+ * @head: the head for your list.
471
+ * @member: the name of the hlist_node within the struct.
472
+ */
473
+#define hlist_for_each_entry(tpos, pos, head, member) \
474
+ for (pos = (head)->first; \
475
+ pos && ({ prefetch(pos->next); 1;}) && \
476
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
477
+ pos = pos->next)
478
+
479
+/**
480
+ * hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
481
+ * @tpos: the type * to use as a loop counter.
482
+ * @pos: the &struct hlist_node to use as a loop counter.
483
+ * @member: the name of the hlist_node within the struct.
484
+ */
485
+#define hlist_for_each_entry_continue(tpos, pos, member) \
486
+ for (pos = (pos)->next; \
487
+ pos && ({ prefetch(pos->next); 1;}) && \
488
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
489
+ pos = pos->next)
490
+
491
+/**
492
+ * hlist_for_each_entry_from - iterate over a hlist continuing from existing point
493
+ * @tpos: the type * to use as a loop counter.
494
+ * @pos: the &struct hlist_node to use as a loop counter.
495
+ * @member: the name of the hlist_node within the struct.
496
+ */
497
+#define hlist_for_each_entry_from(tpos, pos, member) \
498
+ for (; pos && ({ prefetch(pos->next); 1;}) && \
499
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
500
+ pos = pos->next)
501
+
502
+/**
503
+ * hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
504
+ * @tpos: the type * to use as a loop counter.
505
+ * @pos: the &struct hlist_node to use as a loop counter.
506
+ * @n: another &struct hlist_node to use as temporary storage
507
+ * @head: the head for your list.
508
+ * @member: the name of the hlist_node within the struct.
509
+ */
510
+#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
511
+ for (pos = (head)->first; \
512
+ pos && ({ n = pos->next; 1; }) && \
513
+ ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
514
+ pos = n)
515
+
516
+
517
+#endif
kernel/drivers/net/ethernet/ip1811/port_config.h
....@@ -0,0 +1,16 @@
1
+#ifndef __PORT_CONFIG_H__
2
+#define __PORT_CONFIG_H__
3
+#include "portnumber.h"
4
+
5
+#define MAX_PORT_NUM get_MaxPort()
6
+#define GIGA_PORT_START get_GPStart()
7
+#define GIGA_PORT_END get_GPEnd()
8
+
9
+#define MAX_IPORT_CNT SWITCH_MAX_IPORT_CNT
10
+#define ALL_PORTS_LIST (~(-1 << MAX_PORT_NUM))
11
+#define GIGA_PORT_NUM (GIGA_PORT_END - GIGA_PORT_START)
12
+#define CPU_PORT_NUM MAX_IPORT_CNT
13
+#define MAX_TP_PORT_NUM (GIGA_PORT_START -1)
14
+
15
+#endif
16
+
kernel/drivers/net/ethernet/ip1811/system_config.h
....@@ -0,0 +1,36 @@
1
+
2
+#ifndef __SYSTEM_CONFIG_H__
3
+#define __SYSTEM_CONFIG_H__
4
+///////////////////////////////////////////////
5
+//// board config
6
+///////////////////////////////////////////////
7
+
8
+//#define SYSTEM_CONFIG__FPGA
9
+//#define SYSTEM_CONFIG__ASIC//this is ASIC_135
10
+//#define SYSTEM_CONFIG__ASIC125
11
+//#define SYSTEM_CONFIG__ASIC_135
12
+#define SYSTEM_CONFIG__ASIC_150
13
+
14
+
15
+#define SYSTEM_CONFIG__SERVER_MODE
16
+//#define SYSTEM_CONFIG__PCI_MODE
17
+
18
+
19
+///////////////////////////////////////////////
20
+//// DRAM parameter - ref: sdram_support_list
21
+///////////////////////////////////////////////
22
+
23
+#define SYSTEM_CONFIG_DRAM__ARCH_4CH
24
+//#define SYSTEM_CONFIG_DRAM__USED_2CHIPS
25
+//#define SYSTEM_CONFIG_FLASH__USED_2CHIPS
26
+
27
+//#define SYSTEM_CONFIG_DRAM__NT5SV16M16CS_6K
28
+//#define SYSTEM_CONFIG_DRAM__PMS308416BTR_6
29
+//#define SYSTEM_CONFIG_DRAM__IS42S16320D
30
+#define SYSTEM_CONFIG_DRAM__W9825G6KH_6I
31
+//#define SYSTEM_CONFIG_DRAM__A3V56S30
32
+
33
+//#define SYS_CONFIG_WITH_IP102_PHY
34
+
35
+#endif
36
+
kernel/drivers/net/ethernet/ip1811/types.h
....@@ -0,0 +1,17 @@
1
+#ifndef _TYPES_H_
2
+#define _TYPES_H_
3
+
4
+typedef unsigned char u8;
5
+typedef unsigned short u16;
6
+typedef unsigned int u32;
7
+typedef unsigned long long u64;
8
+typedef char s8;
9
+typedef short s16;
10
+typedef int s32;
11
+typedef long long s64;
12
+
13
+#define BIT(x) (1UL<<(x))
14
+
15
+#define err (-1)
16
+
17
+#endif
kernel/drivers/net/ethernet/ip1811/zconf.h
....@@ -0,0 +1,506 @@
1
+/* zconf.h -- configuration of the zlib compression library
2
+ * Copyright (C) 1995-2012 Jean-loup Gailly.
3
+ * For conditions of distribution and use, see copyright notice in zlib.h
4
+ */
5
+
6
+/* @(#) $Id$ */
7
+
8
+#ifndef ZCONF_H
9
+#define ZCONF_H
10
+
11
+/*
12
+ * If you *really* need a unique prefix for all types and library functions,
13
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
14
+ * Even better than compiling with -DZ_PREFIX would be to use configure to set
15
+ * this permanently in zconf.h using "./configure --zprefix".
16
+ */
17
+#ifdef Z_PREFIX /* may be set to #if 1 by ./configure */
18
+# define Z_PREFIX_SET
19
+
20
+/* all linked symbols */
21
+# define _dist_code z__dist_code
22
+# define _length_code z__length_code
23
+# define _tr_align z__tr_align
24
+# define _tr_flush_block z__tr_flush_block
25
+# define _tr_init z__tr_init
26
+# define _tr_stored_block z__tr_stored_block
27
+# define _tr_tally z__tr_tally
28
+# define adler32 z_adler32
29
+# define adler32_combine z_adler32_combine
30
+# define adler32_combine64 z_adler32_combine64
31
+# ifndef Z_SOLO
32
+# define compress z_compress
33
+# define compress2 z_compress2
34
+# define compressBound z_compressBound
35
+# endif
36
+# define crc32 z_crc32
37
+# define crc32_combine z_crc32_combine
38
+# define crc32_combine64 z_crc32_combine64
39
+# define deflate z_deflate
40
+# define deflateBound z_deflateBound
41
+# define deflateCopy z_deflateCopy
42
+# define deflateEnd z_deflateEnd
43
+# define deflateInit2_ z_deflateInit2_
44
+# define deflateInit_ z_deflateInit_
45
+# define deflateParams z_deflateParams
46
+# define deflatePending z_deflatePending
47
+# define deflatePrime z_deflatePrime
48
+# define deflateReset z_deflateReset
49
+# define deflateResetKeep z_deflateResetKeep
50
+# define deflateSetDictionary z_deflateSetDictionary
51
+# define deflateSetHeader z_deflateSetHeader
52
+# define deflateTune z_deflateTune
53
+# define deflate_copyright z_deflate_copyright
54
+# define get_crc_table z_get_crc_table
55
+# ifndef Z_SOLO
56
+# define gz_error z_gz_error
57
+# define gz_intmax z_gz_intmax
58
+# define gz_strwinerror z_gz_strwinerror
59
+# define gzbuffer z_gzbuffer
60
+# define gzclearerr z_gzclearerr
61
+# define gzclose z_gzclose
62
+# define gzclose_r z_gzclose_r
63
+# define gzclose_w z_gzclose_w
64
+# define gzdirect z_gzdirect
65
+# define gzdopen z_gzdopen
66
+# define gzeof z_gzeof
67
+# define gzerror z_gzerror
68
+# define gzflush z_gzflush
69
+# define gzgetc z_gzgetc
70
+# define gzgetc_ z_gzgetc_
71
+# define gzgets z_gzgets
72
+# define gzoffset z_gzoffset
73
+# define gzoffset64 z_gzoffset64
74
+# define gzopen z_gzopen
75
+# define gzopen64 z_gzopen64
76
+# ifdef _WIN32
77
+# define gzopen_w z_gzopen_w
78
+# endif
79
+# define gzprintf z_gzprintf
80
+# define gzputc z_gzputc
81
+# define gzputs z_gzputs
82
+# define gzread z_gzread
83
+# define gzrewind z_gzrewind
84
+# define gzseek z_gzseek
85
+# define gzseek64 z_gzseek64
86
+# define gzsetparams z_gzsetparams
87
+# define gztell z_gztell
88
+# define gztell64 z_gztell64
89
+# define gzungetc z_gzungetc
90
+# define gzwrite z_gzwrite
91
+# endif
92
+# define inflate z_inflate
93
+# define inflateBack z_inflateBack
94
+# define inflateBackEnd z_inflateBackEnd
95
+# define inflateBackInit_ z_inflateBackInit_
96
+# define inflateCopy z_inflateCopy
97
+# define inflateEnd z_inflateEnd
98
+# define inflateGetHeader z_inflateGetHeader
99
+# define inflateInit2_ z_inflateInit2_
100
+# define inflateInit_ z_inflateInit_
101
+# define inflateMark z_inflateMark
102
+# define inflatePrime z_inflatePrime
103
+# define inflateReset z_inflateReset
104
+# define inflateReset2 z_inflateReset2
105
+# define inflateSetDictionary z_inflateSetDictionary
106
+# define inflateSync z_inflateSync
107
+# define inflateSyncPoint z_inflateSyncPoint
108
+# define inflateUndermine z_inflateUndermine
109
+# define inflateResetKeep z_inflateResetKeep
110
+# define inflate_copyright z_inflate_copyright
111
+# define inflate_fast z_inflate_fast
112
+# define inflate_table z_inflate_table
113
+# ifndef Z_SOLO
114
+# define uncompress z_uncompress
115
+# endif
116
+# define zError z_zError
117
+# ifndef Z_SOLO
118
+# define zcalloc z_zcalloc
119
+# define zcfree z_zcfree
120
+# endif
121
+# define zlibCompileFlags z_zlibCompileFlags
122
+# define zlibVersion z_zlibVersion
123
+
124
+/* all zlib typedefs in zlib.h and zconf.h */
125
+# define Byte z_Byte
126
+# define Bytef z_Bytef
127
+# define alloc_func z_alloc_func
128
+# define charf z_charf
129
+# define free_func z_free_func
130
+# ifndef Z_SOLO
131
+# define gzFile z_gzFile
132
+# endif
133
+# define gz_header z_gz_header
134
+# define gz_headerp z_gz_headerp
135
+# define in_func z_in_func
136
+# define intf z_intf
137
+# define out_func z_out_func
138
+# define uInt z_uInt
139
+# define uIntf z_uIntf
140
+# define uLong z_uLong
141
+# define uLongf z_uLongf
142
+# define voidp z_voidp
143
+# define voidpc z_voidpc
144
+# define voidpf z_voidpf
145
+
146
+/* all zlib structs in zlib.h and zconf.h */
147
+# define gz_header_s z_gz_header_s
148
+# define internal_state z_internal_state
149
+
150
+#endif
151
+
152
+#if defined(__MSDOS__) && !defined(MSDOS)
153
+# define MSDOS
154
+#endif
155
+#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
156
+# define OS2
157
+#endif
158
+#if defined(_WINDOWS) && !defined(WINDOWS)
159
+# define WINDOWS
160
+#endif
161
+#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
162
+# ifndef WIN32
163
+# define WIN32
164
+# endif
165
+#endif
166
+#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
167
+# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
168
+# ifndef SYS16BIT
169
+# define SYS16BIT
170
+# endif
171
+# endif
172
+#endif
173
+
174
+/*
175
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
176
+ * than 64k bytes at a time (needed on systems with 16-bit int).
177
+ */
178
+#ifdef SYS16BIT
179
+# define MAXSEG_64K
180
+#endif
181
+#ifdef MSDOS
182
+# define UNALIGNED_OK
183
+#endif
184
+
185
+#ifdef __STDC_VERSION__
186
+# ifndef STDC
187
+# define STDC
188
+# endif
189
+# if __STDC_VERSION__ >= 199901L
190
+# ifndef STDC99
191
+# define STDC99
192
+# endif
193
+# endif
194
+#endif
195
+#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
196
+# define STDC
197
+#endif
198
+#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
199
+# define STDC
200
+#endif
201
+#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
202
+# define STDC
203
+#endif
204
+#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
205
+# define STDC
206
+#endif
207
+
208
+#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
209
+# define STDC
210
+#endif
211
+
212
+#ifndef STDC
213
+# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
214
+# define const /* note: need a more gentle solution here */
215
+# endif
216
+#endif
217
+
218
+#if defined(ZLIB_CONST) && !defined(z_const)
219
+# define z_const const
220
+#else
221
+# define z_const
222
+#endif
223
+
224
+/* Some Mac compilers merge all .h files incorrectly: */
225
+#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
226
+# define NO_DUMMY_DECL
227
+#endif
228
+
229
+/* Maximum value for memLevel in deflateInit2 */
230
+#ifndef MAX_MEM_LEVEL
231
+# ifdef MAXSEG_64K
232
+# define MAX_MEM_LEVEL 8
233
+# else
234
+# define MAX_MEM_LEVEL 9
235
+# endif
236
+#endif
237
+
238
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.
239
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
240
+ * created by gzip. (Files created by minigzip can still be extracted by
241
+ * gzip.)
242
+ */
243
+#ifndef MAX_WBITS
244
+# define MAX_WBITS 15 /* 32K LZ77 window */
245
+#endif
246
+
247
+/* The memory requirements for deflate are (in bytes):
248
+ (1 << (windowBits+2)) + (1 << (memLevel+9))
249
+ that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
250
+ plus a few kilobytes for small objects. For example, if you want to reduce
251
+ the default memory requirements from 256K to 128K, compile with
252
+ make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
253
+ Of course this will generally degrade compression (there's no free lunch).
254
+
255
+ The memory requirements for inflate are (in bytes) 1 << windowBits
256
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes
257
+ for small objects.
258
+*/
259
+
260
+ /* Type declarations */
261
+
262
+#ifndef OF /* function prototypes */
263
+# ifdef STDC
264
+# define OF(args) args
265
+# else
266
+# define OF(args) ()
267
+# endif
268
+#endif
269
+
270
+#ifndef Z_ARG /* function prototypes for stdarg */
271
+# if defined(STDC) || defined(Z_HAVE_STDARG_H)
272
+# define Z_ARG(args) args
273
+# else
274
+# define Z_ARG(args) ()
275
+# endif
276
+#endif
277
+
278
+/* The following definitions for FAR are needed only for MSDOS mixed
279
+ * model programming (small or medium model with some far allocations).
280
+ * This was tested only with MSC; for other MSDOS compilers you may have
281
+ * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
282
+ * just define FAR to be empty.
283
+ */
284
+#ifdef SYS16BIT
285
+# if defined(M_I86SM) || defined(M_I86MM)
286
+ /* MSC small or medium model */
287
+# define SMALL_MEDIUM
288
+# ifdef _MSC_VER
289
+# define FAR _far
290
+# else
291
+# define FAR far
292
+# endif
293
+# endif
294
+# if (defined(__SMALL__) || defined(__MEDIUM__))
295
+ /* Turbo C small or medium model */
296
+# define SMALL_MEDIUM
297
+# ifdef __BORLANDC__
298
+# define FAR _far
299
+# else
300
+# define FAR far
301
+# endif
302
+# endif
303
+#endif
304
+
305
+#if defined(WINDOWS) || defined(WIN32)
306
+ /* If building or using zlib as a DLL, define ZLIB_DLL.
307
+ * This is not mandatory, but it offers a little performance increase.
308
+ */
309
+# ifdef ZLIB_DLL
310
+# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
311
+# ifdef ZLIB_INTERNAL
312
+# define ZEXTERN extern __declspec(dllexport)
313
+# else
314
+# define ZEXTERN extern __declspec(dllimport)
315
+# endif
316
+# endif
317
+# endif /* ZLIB_DLL */
318
+ /* If building or using zlib with the WINAPI/WINAPIV calling convention,
319
+ * define ZLIB_WINAPI.
320
+ * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
321
+ */
322
+# ifdef ZLIB_WINAPI
323
+# ifdef FAR
324
+# undef FAR
325
+# endif
326
+# include <windows.h>
327
+ /* No need for _export, use ZLIB.DEF instead. */
328
+ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
329
+# define ZEXPORT WINAPI
330
+# ifdef WIN32
331
+# define ZEXPORTVA WINAPIV
332
+# else
333
+# define ZEXPORTVA FAR CDECL
334
+# endif
335
+# endif
336
+#endif
337
+
338
+#if defined (__BEOS__)
339
+# ifdef ZLIB_DLL
340
+# ifdef ZLIB_INTERNAL
341
+# define ZEXPORT __declspec(dllexport)
342
+# define ZEXPORTVA __declspec(dllexport)
343
+# else
344
+# define ZEXPORT __declspec(dllimport)
345
+# define ZEXPORTVA __declspec(dllimport)
346
+# endif
347
+# endif
348
+#endif
349
+
350
+#ifndef ZEXTERN
351
+# define ZEXTERN extern
352
+#endif
353
+#ifndef ZEXPORT
354
+# define ZEXPORT
355
+#endif
356
+#ifndef ZEXPORTVA
357
+# define ZEXPORTVA
358
+#endif
359
+
360
+#ifndef FAR
361
+# define FAR
362
+#endif
363
+
364
+#if !defined(__MACTYPES__)
365
+typedef unsigned char Byte; /* 8 bits */
366
+#endif
367
+typedef unsigned int uInt; /* 16 bits or more */
368
+typedef unsigned long uLong; /* 32 bits or more */
369
+
370
+#ifdef SMALL_MEDIUM
371
+ /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
372
+# define Bytef Byte FAR
373
+#else
374
+ typedef Byte FAR Bytef;
375
+#endif
376
+typedef char FAR charf;
377
+typedef int FAR intf;
378
+typedef uInt FAR uIntf;
379
+typedef uLong FAR uLongf;
380
+
381
+#ifdef STDC
382
+ typedef void const *voidpc;
383
+ typedef void FAR *voidpf;
384
+ typedef void *voidp;
385
+#else
386
+ typedef Byte const *voidpc;
387
+ typedef Byte FAR *voidpf;
388
+ typedef Byte *voidp;
389
+#endif
390
+
391
+/* ./configure may #define Z_U4 here */
392
+
393
+#if !defined(Z_U4) && !defined(Z_SOLO) && defined(STDC)
394
+# include <limits.h>
395
+# if (UINT_MAX == 0xffffffffUL)
396
+# define Z_U4 unsigned
397
+# else
398
+# if (ULONG_MAX == 0xffffffffUL)
399
+# define Z_U4 unsigned long
400
+# else
401
+# if (USHRT_MAX == 0xffffffffUL)
402
+# define Z_U4 unsigned short
403
+# endif
404
+# endif
405
+# endif
406
+#endif
407
+
408
+#ifdef Z_U4
409
+ typedef Z_U4 z_crc_t;
410
+#else
411
+ typedef unsigned long z_crc_t;
412
+#endif
413
+
414
+#if 1 /* was set to #if 1 by ./configure */
415
+# define Z_HAVE_UNISTD_H
416
+#endif
417
+
418
+#if 1 /* was set to #if 1 by ./configure */
419
+# define Z_HAVE_STDARG_H
420
+#endif
421
+
422
+#ifdef STDC
423
+# ifndef Z_SOLO
424
+# include <sys/types.h> /* for off_t */
425
+# endif
426
+#endif
427
+
428
+#ifdef _WIN32
429
+# include <stddef.h> /* for wchar_t */
430
+#endif
431
+
432
+/* a little trick to accommodate both "#define _LARGEFILE64_SOURCE" and
433
+ * "#define _LARGEFILE64_SOURCE 1" as requesting 64-bit operations, (even
434
+ * though the former does not conform to the LFS document), but considering
435
+ * both "#undef _LARGEFILE64_SOURCE" and "#define _LARGEFILE64_SOURCE 0" as
436
+ * equivalently requesting no 64-bit operations
437
+ */
438
+#if defined(LARGEFILE64_SOURCE) && -_LARGEFILE64_SOURCE - -1 == 1
439
+# undef _LARGEFILE64_SOURCE
440
+#endif
441
+
442
+#if defined(__WATCOMC__) && !defined(Z_HAVE_UNISTD_H)
443
+# define Z_HAVE_UNISTD_H
444
+#endif
445
+#ifndef Z_SOLO
446
+# if defined(Z_HAVE_UNISTD_H) || defined(LARGEFILE64_SOURCE)
447
+# include <unistd.h> /* for SEEK_*, off_t, and _LFS64_LARGEFILE */
448
+# ifdef VMS
449
+# include <unixio.h> /* for off_t */
450
+# endif
451
+# ifndef z_off_t
452
+# define z_off_t off_t
453
+# endif
454
+# endif
455
+#endif
456
+
457
+#if defined(_LFS64_LARGEFILE) && _LFS64_LARGEFILE-0
458
+# define Z_LFS64
459
+#endif
460
+
461
+#if defined(_LARGEFILE64_SOURCE) && defined(Z_LFS64)
462
+# define Z_LARGE64
463
+#endif
464
+
465
+#if defined(_FILE_OFFSET_BITS) && _FILE_OFFSET_BITS-0 == 64 && defined(Z_LFS64)
466
+# define Z_WANT64
467
+#endif
468
+
469
+#if !defined(SEEK_SET) && !defined(Z_SOLO)
470
+# define SEEK_SET 0 /* Seek from beginning of file. */
471
+# define SEEK_CUR 1 /* Seek from current position. */
472
+# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
473
+#endif
474
+
475
+#ifndef z_off_t
476
+# define z_off_t long
477
+#endif
478
+
479
+#if !defined(_WIN32) && defined(Z_LARGE64)
480
+# define z_off64_t off64_t
481
+#else
482
+# if defined(_WIN32) && !defined(__GNUC__) && !defined(Z_SOLO)
483
+# define z_off64_t __int64
484
+# else
485
+# define z_off64_t z_off_t
486
+# endif
487
+#endif
488
+
489
+/* MVS linker does not support external names larger than 8 bytes */
490
+#if defined(__MVS__)
491
+ #pragma map(deflateInit_,"DEIN")
492
+ #pragma map(deflateInit2_,"DEIN2")
493
+ #pragma map(deflateEnd,"DEEND")
494
+ #pragma map(deflateBound,"DEBND")
495
+ #pragma map(inflateInit_,"ININ")
496
+ #pragma map(inflateInit2_,"ININ2")
497
+ #pragma map(inflateEnd,"INEND")
498
+ #pragma map(inflateSync,"INSY")
499
+ #pragma map(inflateSetDictionary,"INSEDI")
500
+ #pragma map(compressBound,"CMBND")
501
+ #pragma map(inflate_table,"INTABL")
502
+ #pragma map(inflate_fast,"INFA")
503
+ #pragma map(inflate_copyright,"INCOPY")
504
+#endif
505
+
506
+#endif /* ZCONF_H */
kernel/drivers/net/ethernet/ip1811/zlib.h
....@@ -0,0 +1,1744 @@
1
+/* zlib.h -- interface of the 'zlib' general purpose compression library
2
+ version 1.2.7, May 2nd, 2012
3
+
4
+ Copyright (C) 1995-2012 Jean-loup Gailly and Mark Adler
5
+
6
+ This software is provided 'as-is', without any express or implied
7
+ warranty. In no event will the authors be held liable for any damages
8
+ arising from the use of this software.
9
+
10
+ Permission is granted to anyone to use this software for any purpose,
11
+ including commercial applications, and to alter it and redistribute it
12
+ freely, subject to the following restrictions:
13
+
14
+ 1. The origin of this software must not be misrepresented; you must not
15
+ claim that you wrote the original software. If you use this software
16
+ in a product, an acknowledgment in the product documentation would be
17
+ appreciated but is not required.
18
+ 2. Altered source versions must be plainly marked as such, and must not be
19
+ misrepresented as being the original software.
20
+ 3. This notice may not be removed or altered from any source distribution.
21
+
22
+ Jean-loup Gailly Mark Adler
23
+ jloup@gzip.org madler@alumni.caltech.edu
24
+
25
+
26
+ The data format used by the zlib library is described by RFCs (Request for
27
+ Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950
28
+ (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format).
29
+*/
30
+
31
+#ifndef ZLIB_H
32
+#define ZLIB_H
33
+
34
+#include "zconf.h"
35
+
36
+#ifdef __cplusplus
37
+extern "C" {
38
+#endif
39
+
40
+#define ZLIB_VERSION "1.2.7"
41
+#define ZLIB_VERNUM 0x1270
42
+#define ZLIB_VER_MAJOR 1
43
+#define ZLIB_VER_MINOR 2
44
+#define ZLIB_VER_REVISION 7
45
+#define ZLIB_VER_SUBREVISION 0
46
+
47
+/*
48
+ The 'zlib' compression library provides in-memory compression and
49
+ decompression functions, including integrity checks of the uncompressed data.
50
+ This version of the library supports only one compression method (deflation)
51
+ but other algorithms will be added later and will have the same stream
52
+ interface.
53
+
54
+ Compression can be done in a single step if the buffers are large enough,
55
+ or can be done by repeated calls of the compression function. In the latter
56
+ case, the application must provide more input and/or consume the output
57
+ (providing more output space) before each call.
58
+
59
+ The compressed data format used by default by the in-memory functions is
60
+ the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
61
+ around a deflate stream, which is itself documented in RFC 1951.
62
+
63
+ The library also supports reading and writing files in gzip (.gz) format
64
+ with an interface similar to that of stdio using the functions that start
65
+ with "gz". The gzip format is different from the zlib format. gzip is a
66
+ gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
67
+
68
+ This library can optionally read and write gzip streams in memory as well.
69
+
70
+ The zlib format was designed to be compact and fast for use in memory
71
+ and on communications channels. The gzip format was designed for single-
72
+ file compression on file systems, has a larger header than zlib to maintain
73
+ directory information, and uses a different, slower check method than zlib.
74
+
75
+ The library does not install any signal handler. The decoder checks
76
+ the consistency of the compressed data, so the library should never crash
77
+ even in case of corrupted input.
78
+*/
79
+
80
+typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
81
+typedef void (*free_func) OF((voidpf opaque, voidpf address));
82
+
83
+struct internal_state;
84
+
85
+typedef struct z_stream_s {
86
+ z_const Bytef *next_in; /* next input byte */
87
+ uInt avail_in; /* number of bytes available at next_in */
88
+ uLong total_in; /* total number of input bytes read so far */
89
+
90
+ Bytef *next_out; /* next output byte should be put there */
91
+ uInt avail_out; /* remaining free space at next_out */
92
+ uLong total_out; /* total number of bytes output so far */
93
+
94
+ z_const char *msg; /* last error message, NULL if no error */
95
+ struct internal_state FAR *state; /* not visible by applications */
96
+
97
+ alloc_func zalloc; /* used to allocate the internal state */
98
+ free_func zfree; /* used to free the internal state */
99
+ voidpf opaque; /* private data object passed to zalloc and zfree */
100
+
101
+ int data_type; /* best guess about the data type: binary or text */
102
+ uLong adler; /* adler32 value of the uncompressed data */
103
+ uLong reserved; /* reserved for future use */
104
+} z_stream;
105
+
106
+typedef z_stream FAR *z_streamp;
107
+
108
+/*
109
+ gzip header information passed to and from zlib routines. See RFC 1952
110
+ for more details on the meanings of these fields.
111
+*/
112
+typedef struct gz_header_s {
113
+ int text; /* true if compressed data believed to be text */
114
+ uLong time; /* modification time */
115
+ int xflags; /* extra flags (not used when writing a gzip file) */
116
+ int os; /* operating system */
117
+ Bytef *extra; /* pointer to extra field or Z_NULL if none */
118
+ uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
119
+ uInt extra_max; /* space at extra (only when reading header) */
120
+ Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
121
+ uInt name_max; /* space at name (only when reading header) */
122
+ Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
123
+ uInt comm_max; /* space at comment (only when reading header) */
124
+ int hcrc; /* true if there was or will be a header crc */
125
+ int done; /* true when done reading gzip header (not used
126
+ when writing a gzip file) */
127
+} gz_header;
128
+
129
+typedef gz_header FAR *gz_headerp;
130
+
131
+/*
132
+ The application must update next_in and avail_in when avail_in has dropped
133
+ to zero. It must update next_out and avail_out when avail_out has dropped
134
+ to zero. The application must initialize zalloc, zfree and opaque before
135
+ calling the init function. All other fields are set by the compression
136
+ library and must not be updated by the application.
137
+
138
+ The opaque value provided by the application will be passed as the first
139
+ parameter for calls of zalloc and zfree. This can be useful for custom
140
+ memory management. The compression library attaches no meaning to the
141
+ opaque value.
142
+
143
+ zalloc must return Z_NULL if there is not enough memory for the object.
144
+ If zlib is used in a multi-threaded application, zalloc and zfree must be
145
+ thread safe.
146
+
147
+ On 16-bit systems, the functions zalloc and zfree must be able to allocate
148
+ exactly 65536 bytes, but will not be required to allocate more than this if
149
+ the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers
150
+ returned by zalloc for objects of exactly 65536 bytes *must* have their
151
+ offset normalized to zero. The default allocation function provided by this
152
+ library ensures this (see zutil.c). To reduce memory requirements and avoid
153
+ any allocation of 64K objects, at the expense of compression ratio, compile
154
+ the library with -DMAX_WBITS=14 (see zconf.h).
155
+
156
+ The fields total_in and total_out can be used for statistics or progress
157
+ reports. After compression, total_in holds the total size of the
158
+ uncompressed data and may be saved for use in the decompressor (particularly
159
+ if the decompressor wants to decompress everything in a single step).
160
+*/
161
+
162
+ /* constants */
163
+
164
+#define Z_NO_FLUSH 0
165
+#define Z_PARTIAL_FLUSH 1
166
+#define Z_SYNC_FLUSH 2
167
+#define Z_FULL_FLUSH 3
168
+#define Z_FINISH 4
169
+#define Z_BLOCK 5
170
+#define Z_TREES 6
171
+/* Allowed flush values; see deflate() and inflate() below for details */
172
+
173
+#define Z_OK 0
174
+#define Z_STREAM_END 1
175
+#define Z_NEED_DICT 2
176
+#define Z_ERRNO (-1)
177
+#define Z_STREAM_ERROR (-2)
178
+#define Z_DATA_ERROR (-3)
179
+#define Z_MEM_ERROR (-4)
180
+#define Z_BUF_ERROR (-5)
181
+#define Z_VERSION_ERROR (-6)
182
+/* Return codes for the compression/decompression functions. Negative values
183
+ * are errors, positive values are used for special but normal events.
184
+ */
185
+
186
+#define Z_NO_COMPRESSION 0
187
+#define Z_BEST_SPEED 1
188
+#define Z_BEST_COMPRESSION 9
189
+#define Z_DEFAULT_COMPRESSION (-1)
190
+/* compression levels */
191
+
192
+#define Z_FILTERED 1
193
+#define Z_HUFFMAN_ONLY 2
194
+#define Z_RLE 3
195
+#define Z_FIXED 4
196
+#define Z_DEFAULT_STRATEGY 0
197
+/* compression strategy; see deflateInit2() below for details */
198
+
199
+#define Z_BINARY 0
200
+#define Z_TEXT 1
201
+#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
202
+#define Z_UNKNOWN 2
203
+/* Possible values of the data_type field (though see inflate()) */
204
+
205
+#define Z_DEFLATED 8
206
+/* The deflate compression method (the only one supported in this version) */
207
+
208
+#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
209
+
210
+#define zlib_version zlibVersion()
211
+/* for compatibility with versions < 1.0.2 */
212
+
213
+
214
+ /* basic functions */
215
+
216
+ZEXTERN const char * ZEXPORT zlibVersion OF((void));
217
+/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
218
+ If the first character differs, the library code actually used is not
219
+ compatible with the zlib.h header file used by the application. This check
220
+ is automatically made by deflateInit and inflateInit.
221
+ */
222
+
223
+/*
224
+ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
225
+
226
+ Initializes the internal stream state for compression. The fields
227
+ zalloc, zfree and opaque must be initialized before by the caller. If
228
+ zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
229
+ allocation functions.
230
+
231
+ The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
232
+ 1 gives best speed, 9 gives best compression, 0 gives no compression at all
233
+ (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION
234
+ requests a default compromise between speed and compression (currently
235
+ equivalent to level 6).
236
+
237
+ deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
238
+ memory, Z_STREAM_ERROR if level is not a valid compression level, or
239
+ Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
240
+ with the version assumed by the caller (ZLIB_VERSION). msg is set to null
241
+ if there is no error message. deflateInit does not perform any compression:
242
+ this will be done by deflate().
243
+*/
244
+
245
+
246
+ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
247
+/*
248
+ deflate compresses as much data as possible, and stops when the input
249
+ buffer becomes empty or the output buffer becomes full. It may introduce
250
+ some output latency (reading input without producing any output) except when
251
+ forced to flush.
252
+
253
+ The detailed semantics are as follows. deflate performs one or both of the
254
+ following actions:
255
+
256
+ - Compress more input starting at next_in and update next_in and avail_in
257
+ accordingly. If not all input can be processed (because there is not
258
+ enough room in the output buffer), next_in and avail_in are updated and
259
+ processing will resume at this point for the next call of deflate().
260
+
261
+ - Provide more output starting at next_out and update next_out and avail_out
262
+ accordingly. This action is forced if the parameter flush is non zero.
263
+ Forcing flush frequently degrades the compression ratio, so this parameter
264
+ should be set only when necessary (in interactive applications). Some
265
+ output may be provided even if flush is not set.
266
+
267
+ Before the call of deflate(), the application should ensure that at least
268
+ one of the actions is possible, by providing more input and/or consuming more
269
+ output, and updating avail_in or avail_out accordingly; avail_out should
270
+ never be zero before the call. The application can consume the compressed
271
+ output when it wants, for example when the output buffer is full (avail_out
272
+ == 0), or after each call of deflate(). If deflate returns Z_OK and with
273
+ zero avail_out, it must be called again after making room in the output
274
+ buffer because there might be more output pending.
275
+
276
+ Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
277
+ decide how much data to accumulate before producing output, in order to
278
+ maximize compression.
279
+
280
+ If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
281
+ flushed to the output buffer and the output is aligned on a byte boundary, so
282
+ that the decompressor can get all input data available so far. (In
283
+ particular avail_in is zero after the call if enough output space has been
284
+ provided before the call.) Flushing may degrade compression for some
285
+ compression algorithms and so it should be used only when necessary. This
286
+ completes the current deflate block and follows it with an empty stored block
287
+ that is three bits plus filler bits to the next byte, followed by four bytes
288
+ (00 00 ff ff).
289
+
290
+ If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the
291
+ output buffer, but the output is not aligned to a byte boundary. All of the
292
+ input data so far will be available to the decompressor, as for Z_SYNC_FLUSH.
293
+ This completes the current deflate block and follows it with an empty fixed
294
+ codes block that is 10 bits long. This assures that enough bytes are output
295
+ in order for the decompressor to finish the block before the empty fixed code
296
+ block.
297
+
298
+ If flush is set to Z_BLOCK, a deflate block is completed and emitted, as
299
+ for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to
300
+ seven bits of the current block are held to be written as the next byte after
301
+ the next deflate block is completed. In this case, the decompressor may not
302
+ be provided enough bits at this point in order to complete decompression of
303
+ the data provided so far to the compressor. It may need to wait for the next
304
+ block to be emitted. This is for advanced applications that need to control
305
+ the emission of deflate blocks.
306
+
307
+ If flush is set to Z_FULL_FLUSH, all output is flushed as with
308
+ Z_SYNC_FLUSH, and the compression state is reset so that decompression can
309
+ restart from this point if previous compressed data has been damaged or if
310
+ random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
311
+ compression.
312
+
313
+ If deflate returns with avail_out == 0, this function must be called again
314
+ with the same value of the flush parameter and more output space (updated
315
+ avail_out), until the flush is complete (deflate returns with non-zero
316
+ avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
317
+ avail_out is greater than six to avoid repeated flush markers due to
318
+ avail_out == 0 on return.
319
+
320
+ If the parameter flush is set to Z_FINISH, pending input is processed,
321
+ pending output is flushed and deflate returns with Z_STREAM_END if there was
322
+ enough output space; if deflate returns with Z_OK, this function must be
323
+ called again with Z_FINISH and more output space (updated avail_out) but no
324
+ more input data, until it returns with Z_STREAM_END or an error. After
325
+ deflate has returned Z_STREAM_END, the only possible operations on the stream
326
+ are deflateReset or deflateEnd.
327
+
328
+ Z_FINISH can be used immediately after deflateInit if all the compression
329
+ is to be done in a single step. In this case, avail_out must be at least the
330
+ value returned by deflateBound (see below). Then deflate is guaranteed to
331
+ return Z_STREAM_END. If not enough output space is provided, deflate will
332
+ not return Z_STREAM_END, and it must be called again as described above.
333
+
334
+ deflate() sets strm->adler to the adler32 checksum of all input read
335
+ so far (that is, total_in bytes).
336
+
337
+ deflate() may update strm->data_type if it can make a good guess about
338
+ the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
339
+ binary. This field is only for information purposes and does not affect the
340
+ compression algorithm in any manner.
341
+
342
+ deflate() returns Z_OK if some progress has been made (more input
343
+ processed or more output produced), Z_STREAM_END if all input has been
344
+ consumed and all output has been produced (only when flush is set to
345
+ Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
346
+ if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible
347
+ (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
348
+ fatal, and deflate() can be called again with more input and more output
349
+ space to continue compressing.
350
+*/
351
+
352
+
353
+ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
354
+/*
355
+ All dynamically allocated data structures for this stream are freed.
356
+ This function discards any unprocessed input and does not flush any pending
357
+ output.
358
+
359
+ deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
360
+ stream state was inconsistent, Z_DATA_ERROR if the stream was freed
361
+ prematurely (some input or output was discarded). In the error case, msg
362
+ may be set but then points to a static string (which must not be
363
+ deallocated).
364
+*/
365
+
366
+
367
+/*
368
+ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
369
+
370
+ Initializes the internal stream state for decompression. The fields
371
+ next_in, avail_in, zalloc, zfree and opaque must be initialized before by
372
+ the caller. If next_in is not Z_NULL and avail_in is large enough (the
373
+ exact value depends on the compression method), inflateInit determines the
374
+ compression method from the zlib header and allocates all data structures
375
+ accordingly; otherwise the allocation will be deferred to the first call of
376
+ inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
377
+ use default allocation functions.
378
+
379
+ inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
380
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
381
+ version assumed by the caller, or Z_STREAM_ERROR if the parameters are
382
+ invalid, such as a null pointer to the structure. msg is set to null if
383
+ there is no error message. inflateInit does not perform any decompression
384
+ apart from possibly reading the zlib header if present: actual decompression
385
+ will be done by inflate(). (So next_in and avail_in may be modified, but
386
+ next_out and avail_out are unused and unchanged.) The current implementation
387
+ of inflateInit() does not process any header information -- that is deferred
388
+ until inflate() is called.
389
+*/
390
+
391
+
392
+ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
393
+/*
394
+ inflate decompresses as much data as possible, and stops when the input
395
+ buffer becomes empty or the output buffer becomes full. It may introduce
396
+ some output latency (reading input without producing any output) except when
397
+ forced to flush.
398
+
399
+ The detailed semantics are as follows. inflate performs one or both of the
400
+ following actions:
401
+
402
+ - Decompress more input starting at next_in and update next_in and avail_in
403
+ accordingly. If not all input can be processed (because there is not
404
+ enough room in the output buffer), next_in is updated and processing will
405
+ resume at this point for the next call of inflate().
406
+
407
+ - Provide more output starting at next_out and update next_out and avail_out
408
+ accordingly. inflate() provides as much output as possible, until there is
409
+ no more input data or no more space in the output buffer (see below about
410
+ the flush parameter).
411
+
412
+ Before the call of inflate(), the application should ensure that at least
413
+ one of the actions is possible, by providing more input and/or consuming more
414
+ output, and updating the next_* and avail_* values accordingly. The
415
+ application can consume the uncompressed output when it wants, for example
416
+ when the output buffer is full (avail_out == 0), or after each call of
417
+ inflate(). If inflate returns Z_OK and with zero avail_out, it must be
418
+ called again after making room in the output buffer because there might be
419
+ more output pending.
420
+
421
+ The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH,
422
+ Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much
423
+ output as possible to the output buffer. Z_BLOCK requests that inflate()
424
+ stop if and when it gets to the next deflate block boundary. When decoding
425
+ the zlib or gzip format, this will cause inflate() to return immediately
426
+ after the header and before the first block. When doing a raw inflate,
427
+ inflate() will go ahead and process the first block, and will return when it
428
+ gets to the end of that block, or when it runs out of data.
429
+
430
+ The Z_BLOCK option assists in appending to or combining deflate streams.
431
+ Also to assist in this, on return inflate() will set strm->data_type to the
432
+ number of unused bits in the last byte taken from strm->next_in, plus 64 if
433
+ inflate() is currently decoding the last block in the deflate stream, plus
434
+ 128 if inflate() returned immediately after decoding an end-of-block code or
435
+ decoding the complete header up to just before the first byte of the deflate
436
+ stream. The end-of-block will not be indicated until all of the uncompressed
437
+ data from that block has been written to strm->next_out. The number of
438
+ unused bits may in general be greater than seven, except when bit 7 of
439
+ data_type is set, in which case the number of unused bits will be less than
440
+ eight. data_type is set as noted here every time inflate() returns for all
441
+ flush options, and so can be used to determine the amount of currently
442
+ consumed input in bits.
443
+
444
+ The Z_TREES option behaves as Z_BLOCK does, but it also returns when the
445
+ end of each deflate block header is reached, before any actual data in that
446
+ block is decoded. This allows the caller to determine the length of the
447
+ deflate block header for later use in random access within a deflate block.
448
+ 256 is added to the value of strm->data_type when inflate() returns
449
+ immediately after reaching the end of the deflate block header.
450
+
451
+ inflate() should normally be called until it returns Z_STREAM_END or an
452
+ error. However if all decompression is to be performed in a single step (a
453
+ single call of inflate), the parameter flush should be set to Z_FINISH. In
454
+ this case all pending input is processed and all pending output is flushed;
455
+ avail_out must be large enough to hold all of the uncompressed data for the
456
+ operation to complete. (The size of the uncompressed data may have been
457
+ saved by the compressor for this purpose.) The use of Z_FINISH is not
458
+ required to perform an inflation in one step. However it may be used to
459
+ inform inflate that a faster approach can be used for the single inflate()
460
+ call. Z_FINISH also informs inflate to not maintain a sliding window if the
461
+ stream completes, which reduces inflate's memory footprint. If the stream
462
+ does not complete, either because not all of the stream is provided or not
463
+ enough output space is provided, then a sliding window will be allocated and
464
+ inflate() can be called again to continue the operation as if Z_NO_FLUSH had
465
+ been used.
466
+
467
+ In this implementation, inflate() always flushes as much output as
468
+ possible to the output buffer, and always uses the faster approach on the
469
+ first call. So the effects of the flush parameter in this implementation are
470
+ on the return value of inflate() as noted below, when inflate() returns early
471
+ when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of
472
+ memory for a sliding window when Z_FINISH is used.
473
+
474
+ If a preset dictionary is needed after this call (see inflateSetDictionary
475
+ below), inflate sets strm->adler to the Adler-32 checksum of the dictionary
476
+ chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
477
+ strm->adler to the Adler-32 checksum of all output produced so far (that is,
478
+ total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
479
+ below. At the end of the stream, inflate() checks that its computed adler32
480
+ checksum is equal to that saved by the compressor and returns Z_STREAM_END
481
+ only if the checksum is correct.
482
+
483
+ inflate() can decompress and check either zlib-wrapped or gzip-wrapped
484
+ deflate data. The header type is detected automatically, if requested when
485
+ initializing with inflateInit2(). Any information contained in the gzip
486
+ header is not retained, so applications that need that information should
487
+ instead use raw inflate, see inflateInit2() below, or inflateBack() and
488
+ perform their own processing of the gzip header and trailer. When processing
489
+ gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output
490
+ producted so far. The CRC-32 is checked against the gzip trailer.
491
+
492
+ inflate() returns Z_OK if some progress has been made (more input processed
493
+ or more output produced), Z_STREAM_END if the end of the compressed data has
494
+ been reached and all uncompressed output has been produced, Z_NEED_DICT if a
495
+ preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
496
+ corrupted (input stream not conforming to the zlib format or incorrect check
497
+ value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
498
+ next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory,
499
+ Z_BUF_ERROR if no progress is possible or if there was not enough room in the
500
+ output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
501
+ inflate() can be called again with more input and more output space to
502
+ continue decompressing. If Z_DATA_ERROR is returned, the application may
503
+ then call inflateSync() to look for a good compression block if a partial
504
+ recovery of the data is desired.
505
+*/
506
+
507
+
508
+ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
509
+/*
510
+ All dynamically allocated data structures for this stream are freed.
511
+ This function discards any unprocessed input and does not flush any pending
512
+ output.
513
+
514
+ inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
515
+ was inconsistent. In the error case, msg may be set but then points to a
516
+ static string (which must not be deallocated).
517
+*/
518
+
519
+
520
+ /* Advanced functions */
521
+
522
+/*
523
+ The following functions are needed only in some special applications.
524
+*/
525
+
526
+/*
527
+ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
528
+ int level,
529
+ int method,
530
+ int windowBits,
531
+ int memLevel,
532
+ int strategy));
533
+
534
+ This is another version of deflateInit with more compression options. The
535
+ fields next_in, zalloc, zfree and opaque must be initialized before by the
536
+ caller.
537
+
538
+ The method parameter is the compression method. It must be Z_DEFLATED in
539
+ this version of the library.
540
+
541
+ The windowBits parameter is the base two logarithm of the window size
542
+ (the size of the history buffer). It should be in the range 8..15 for this
543
+ version of the library. Larger values of this parameter result in better
544
+ compression at the expense of memory usage. The default value is 15 if
545
+ deflateInit is used instead.
546
+
547
+ windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
548
+ determines the window size. deflate() will then generate raw deflate data
549
+ with no zlib header or trailer, and will not compute an adler32 check value.
550
+
551
+ windowBits can also be greater than 15 for optional gzip encoding. Add
552
+ 16 to windowBits to write a simple gzip header and trailer around the
553
+ compressed data instead of a zlib wrapper. The gzip header will have no
554
+ file name, no extra data, no comment, no modification time (set to zero), no
555
+ header crc, and the operating system will be set to 255 (unknown). If a
556
+ gzip stream is being written, strm->adler is a crc32 instead of an adler32.
557
+
558
+ The memLevel parameter specifies how much memory should be allocated
559
+ for the internal compression state. memLevel=1 uses minimum memory but is
560
+ slow and reduces compression ratio; memLevel=9 uses maximum memory for
561
+ optimal speed. The default value is 8. See zconf.h for total memory usage
562
+ as a function of windowBits and memLevel.
563
+
564
+ The strategy parameter is used to tune the compression algorithm. Use the
565
+ value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
566
+ filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
567
+ string match), or Z_RLE to limit match distances to one (run-length
568
+ encoding). Filtered data consists mostly of small values with a somewhat
569
+ random distribution. In this case, the compression algorithm is tuned to
570
+ compress them better. The effect of Z_FILTERED is to force more Huffman
571
+ coding and less string matching; it is somewhat intermediate between
572
+ Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as
573
+ fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
574
+ strategy parameter only affects the compression ratio but not the
575
+ correctness of the compressed output even if it is not set appropriately.
576
+ Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler
577
+ decoder for special applications.
578
+
579
+ deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
580
+ memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid
581
+ method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is
582
+ incompatible with the version assumed by the caller (ZLIB_VERSION). msg is
583
+ set to null if there is no error message. deflateInit2 does not perform any
584
+ compression: this will be done by deflate().
585
+*/
586
+
587
+ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
588
+ const Bytef *dictionary,
589
+ uInt dictLength));
590
+/*
591
+ Initializes the compression dictionary from the given byte sequence
592
+ without producing any compressed output. When using the zlib format, this
593
+ function must be called immediately after deflateInit, deflateInit2 or
594
+ deflateReset, and before any call of deflate. When doing raw deflate, this
595
+ function must be called either before any call of deflate, or immediately
596
+ after the completion of a deflate block, i.e. after all input has been
597
+ consumed and all output has been delivered when using any of the flush
598
+ options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The
599
+ compressor and decompressor must use exactly the same dictionary (see
600
+ inflateSetDictionary).
601
+
602
+ The dictionary should consist of strings (byte sequences) that are likely
603
+ to be encountered later in the data to be compressed, with the most commonly
604
+ used strings preferably put towards the end of the dictionary. Using a
605
+ dictionary is most useful when the data to be compressed is short and can be
606
+ predicted with good accuracy; the data can then be compressed better than
607
+ with the default empty dictionary.
608
+
609
+ Depending on the size of the compression data structures selected by
610
+ deflateInit or deflateInit2, a part of the dictionary may in effect be
611
+ discarded, for example if the dictionary is larger than the window size
612
+ provided in deflateInit or deflateInit2. Thus the strings most likely to be
613
+ useful should be put at the end of the dictionary, not at the front. In
614
+ addition, the current implementation of deflate will use at most the window
615
+ size minus 262 bytes of the provided dictionary.
616
+
617
+ Upon return of this function, strm->adler is set to the adler32 value
618
+ of the dictionary; the decompressor may later use this value to determine
619
+ which dictionary has been used by the compressor. (The adler32 value
620
+ applies to the whole dictionary even if only a subset of the dictionary is
621
+ actually used by the compressor.) If a raw deflate was requested, then the
622
+ adler32 value is not computed and strm->adler is not set.
623
+
624
+ deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
625
+ parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
626
+ inconsistent (for example if deflate has already been called for this stream
627
+ or if not at a block boundary for raw deflate). deflateSetDictionary does
628
+ not perform any compression: this will be done by deflate().
629
+*/
630
+
631
+ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
632
+ z_streamp source));
633
+/*
634
+ Sets the destination stream as a complete copy of the source stream.
635
+
636
+ This function can be useful when several compression strategies will be
637
+ tried, for example when there are several ways of pre-processing the input
638
+ data with a filter. The streams that will be discarded should then be freed
639
+ by calling deflateEnd. Note that deflateCopy duplicates the internal
640
+ compression state which can be quite large, so this strategy is slow and can
641
+ consume lots of memory.
642
+
643
+ deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
644
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
645
+ (such as zalloc being Z_NULL). msg is left unchanged in both source and
646
+ destination.
647
+*/
648
+
649
+ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
650
+/*
651
+ This function is equivalent to deflateEnd followed by deflateInit,
652
+ but does not free and reallocate all the internal compression state. The
653
+ stream will keep the same compression level and any other attributes that
654
+ may have been set by deflateInit2.
655
+
656
+ deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
657
+ stream state was inconsistent (such as zalloc or state being Z_NULL).
658
+*/
659
+
660
+ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
661
+ int level,
662
+ int strategy));
663
+/*
664
+ Dynamically update the compression level and compression strategy. The
665
+ interpretation of level and strategy is as in deflateInit2. This can be
666
+ used to switch between compression and straight copy of the input data, or
667
+ to switch to a different kind of input data requiring a different strategy.
668
+ If the compression level is changed, the input available so far is
669
+ compressed with the old level (and may be flushed); the new level will take
670
+ effect only at the next call of deflate().
671
+
672
+ Before the call of deflateParams, the stream state must be set as for
673
+ a call of deflate(), since the currently available input may have to be
674
+ compressed and flushed. In particular, strm->avail_out must be non-zero.
675
+
676
+ deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
677
+ stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if
678
+ strm->avail_out was zero.
679
+*/
680
+
681
+ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
682
+ int good_length,
683
+ int max_lazy,
684
+ int nice_length,
685
+ int max_chain));
686
+/*
687
+ Fine tune deflate's internal compression parameters. This should only be
688
+ used by someone who understands the algorithm used by zlib's deflate for
689
+ searching for the best matching string, and even then only by the most
690
+ fanatic optimizer trying to squeeze out the last compressed bit for their
691
+ specific input data. Read the deflate.c source code for the meaning of the
692
+ max_lazy, good_length, nice_length, and max_chain parameters.
693
+
694
+ deflateTune() can be called after deflateInit() or deflateInit2(), and
695
+ returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
696
+ */
697
+
698
+ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
699
+ uLong sourceLen));
700
+/*
701
+ deflateBound() returns an upper bound on the compressed size after
702
+ deflation of sourceLen bytes. It must be called after deflateInit() or
703
+ deflateInit2(), and after deflateSetHeader(), if used. This would be used
704
+ to allocate an output buffer for deflation in a single pass, and so would be
705
+ called before deflate(). If that first deflate() call is provided the
706
+ sourceLen input bytes, an output buffer allocated to the size returned by
707
+ deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed
708
+ to return Z_STREAM_END. Note that it is possible for the compressed size to
709
+ be larger than the value returned by deflateBound() if flush options other
710
+ than Z_FINISH or Z_NO_FLUSH are used.
711
+*/
712
+
713
+ZEXTERN int ZEXPORT deflatePending OF((z_streamp strm,
714
+ unsigned *pending,
715
+ int *bits));
716
+/*
717
+ deflatePending() returns the number of bytes and bits of output that have
718
+ been generated, but not yet provided in the available output. The bytes not
719
+ provided would be due to the available output space having being consumed.
720
+ The number of bits of output not provided are between 0 and 7, where they
721
+ await more bits to join them in order to fill out a full byte. If pending
722
+ or bits are Z_NULL, then those values are not set.
723
+
724
+ deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source
725
+ stream state was inconsistent.
726
+ */
727
+
728
+ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
729
+ int bits,
730
+ int value));
731
+/*
732
+ deflatePrime() inserts bits in the deflate output stream. The intent
733
+ is that this function is used to start off the deflate output with the bits
734
+ leftover from a previous deflate stream when appending to it. As such, this
735
+ function can only be used for raw deflate, and must be used before the first
736
+ deflate() call after a deflateInit2() or deflateReset(). bits must be less
737
+ than or equal to 16, and that many of the least significant bits of value
738
+ will be inserted in the output.
739
+
740
+ deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough
741
+ room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the
742
+ source stream state was inconsistent.
743
+*/
744
+
745
+ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
746
+ gz_headerp head));
747
+/*
748
+ deflateSetHeader() provides gzip header information for when a gzip
749
+ stream is requested by deflateInit2(). deflateSetHeader() may be called
750
+ after deflateInit2() or deflateReset() and before the first call of
751
+ deflate(). The text, time, os, extra field, name, and comment information
752
+ in the provided gz_header structure are written to the gzip header (xflag is
753
+ ignored -- the extra flags are set according to the compression level). The
754
+ caller must assure that, if not Z_NULL, name and comment are terminated with
755
+ a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
756
+ available there. If hcrc is true, a gzip header crc is included. Note that
757
+ the current versions of the command-line version of gzip (up through version
758
+ 1.3.x) do not support header crc's, and will report that it is a "multi-part
759
+ gzip file" and give up.
760
+
761
+ If deflateSetHeader is not used, the default gzip header has text false,
762
+ the time set to zero, and os set to 255, with no extra, name, or comment
763
+ fields. The gzip header is returned to the default state by deflateReset().
764
+
765
+ deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
766
+ stream state was inconsistent.
767
+*/
768
+
769
+/*
770
+ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
771
+ int windowBits));
772
+
773
+ This is another version of inflateInit with an extra parameter. The
774
+ fields next_in, avail_in, zalloc, zfree and opaque must be initialized
775
+ before by the caller.
776
+
777
+ The windowBits parameter is the base two logarithm of the maximum window
778
+ size (the size of the history buffer). It should be in the range 8..15 for
779
+ this version of the library. The default value is 15 if inflateInit is used
780
+ instead. windowBits must be greater than or equal to the windowBits value
781
+ provided to deflateInit2() while compressing, or it must be equal to 15 if
782
+ deflateInit2() was not used. If a compressed stream with a larger window
783
+ size is given as input, inflate() will return with the error code
784
+ Z_DATA_ERROR instead of trying to allocate a larger window.
785
+
786
+ windowBits can also be zero to request that inflate use the window size in
787
+ the zlib header of the compressed stream.
788
+
789
+ windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
790
+ determines the window size. inflate() will then process raw deflate data,
791
+ not looking for a zlib or gzip header, not generating a check value, and not
792
+ looking for any check values for comparison at the end of the stream. This
793
+ is for use with other formats that use the deflate compressed data format
794
+ such as zip. Those formats provide their own check values. If a custom
795
+ format is developed using the raw deflate format for compressed data, it is
796
+ recommended that a check value such as an adler32 or a crc32 be applied to
797
+ the uncompressed data as is done in the zlib, gzip, and zip formats. For
798
+ most applications, the zlib format should be used as is. Note that comments
799
+ above on the use in deflateInit2() applies to the magnitude of windowBits.
800
+
801
+ windowBits can also be greater than 15 for optional gzip decoding. Add
802
+ 32 to windowBits to enable zlib and gzip decoding with automatic header
803
+ detection, or add 16 to decode only the gzip format (the zlib format will
804
+ return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a
805
+ crc32 instead of an adler32.
806
+
807
+ inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
808
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
809
+ version assumed by the caller, or Z_STREAM_ERROR if the parameters are
810
+ invalid, such as a null pointer to the structure. msg is set to null if
811
+ there is no error message. inflateInit2 does not perform any decompression
812
+ apart from possibly reading the zlib header if present: actual decompression
813
+ will be done by inflate(). (So next_in and avail_in may be modified, but
814
+ next_out and avail_out are unused and unchanged.) The current implementation
815
+ of inflateInit2() does not process any header information -- that is
816
+ deferred until inflate() is called.
817
+*/
818
+
819
+ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
820
+ const Bytef *dictionary,
821
+ uInt dictLength));
822
+/*
823
+ Initializes the decompression dictionary from the given uncompressed byte
824
+ sequence. This function must be called immediately after a call of inflate,
825
+ if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
826
+ can be determined from the adler32 value returned by that call of inflate.
827
+ The compressor and decompressor must use exactly the same dictionary (see
828
+ deflateSetDictionary). For raw inflate, this function can be called at any
829
+ time to set the dictionary. If the provided dictionary is smaller than the
830
+ window and there is already data in the window, then the provided dictionary
831
+ will amend what's there. The application must insure that the dictionary
832
+ that was used for compression is provided.
833
+
834
+ inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
835
+ parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is
836
+ inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
837
+ expected one (incorrect adler32 value). inflateSetDictionary does not
838
+ perform any decompression: this will be done by subsequent calls of
839
+ inflate().
840
+*/
841
+
842
+ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
843
+/*
844
+ Skips invalid compressed data until a possible full flush point (see above
845
+ for the description of deflate with Z_FULL_FLUSH) can be found, or until all
846
+ available input is skipped. No output is provided.
847
+
848
+ inflateSync searches for a 00 00 FF FF pattern in the compressed data.
849
+ All full flush points have this pattern, but not all occurences of this
850
+ pattern are full flush points.
851
+
852
+ inflateSync returns Z_OK if a possible full flush point has been found,
853
+ Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point
854
+ has been found, or Z_STREAM_ERROR if the stream structure was inconsistent.
855
+ In the success case, the application may save the current current value of
856
+ total_in which indicates where valid compressed data was found. In the
857
+ error case, the application may repeatedly call inflateSync, providing more
858
+ input each time, until success or end of the input data.
859
+*/
860
+
861
+ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
862
+ z_streamp source));
863
+/*
864
+ Sets the destination stream as a complete copy of the source stream.
865
+
866
+ This function can be useful when randomly accessing a large stream. The
867
+ first pass through the stream can periodically record the inflate state,
868
+ allowing restarting inflate at those points when randomly accessing the
869
+ stream.
870
+
871
+ inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
872
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
873
+ (such as zalloc being Z_NULL). msg is left unchanged in both source and
874
+ destination.
875
+*/
876
+
877
+ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
878
+/*
879
+ This function is equivalent to inflateEnd followed by inflateInit,
880
+ but does not free and reallocate all the internal decompression state. The
881
+ stream will keep attributes that may have been set by inflateInit2.
882
+
883
+ inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
884
+ stream state was inconsistent (such as zalloc or state being Z_NULL).
885
+*/
886
+
887
+ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
888
+ int windowBits));
889
+/*
890
+ This function is the same as inflateReset, but it also permits changing
891
+ the wrap and window size requests. The windowBits parameter is interpreted
892
+ the same as it is for inflateInit2.
893
+
894
+ inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source
895
+ stream state was inconsistent (such as zalloc or state being Z_NULL), or if
896
+ the windowBits parameter is invalid.
897
+*/
898
+
899
+ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
900
+ int bits,
901
+ int value));
902
+/*
903
+ This function inserts bits in the inflate input stream. The intent is
904
+ that this function is used to start inflating at a bit position in the
905
+ middle of a byte. The provided bits will be used before any bytes are used
906
+ from next_in. This function should only be used with raw inflate, and
907
+ should be used before the first inflate() call after inflateInit2() or
908
+ inflateReset(). bits must be less than or equal to 16, and that many of the
909
+ least significant bits of value will be inserted in the input.
910
+
911
+ If bits is negative, then the input stream bit buffer is emptied. Then
912
+ inflatePrime() can be called again to put bits in the buffer. This is used
913
+ to clear out bits leftover after feeding inflate a block description prior
914
+ to feeding inflate codes.
915
+
916
+ inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
917
+ stream state was inconsistent.
918
+*/
919
+
920
+ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
921
+/*
922
+ This function returns two values, one in the lower 16 bits of the return
923
+ value, and the other in the remaining upper bits, obtained by shifting the
924
+ return value down 16 bits. If the upper value is -1 and the lower value is
925
+ zero, then inflate() is currently decoding information outside of a block.
926
+ If the upper value is -1 and the lower value is non-zero, then inflate is in
927
+ the middle of a stored block, with the lower value equaling the number of
928
+ bytes from the input remaining to copy. If the upper value is not -1, then
929
+ it is the number of bits back from the current bit position in the input of
930
+ the code (literal or length/distance pair) currently being processed. In
931
+ that case the lower value is the number of bytes already emitted for that
932
+ code.
933
+
934
+ A code is being processed if inflate is waiting for more input to complete
935
+ decoding of the code, or if it has completed decoding but is waiting for
936
+ more output space to write the literal or match data.
937
+
938
+ inflateMark() is used to mark locations in the input data for random
939
+ access, which may be at bit positions, and to note those cases where the
940
+ output of a code may span boundaries of random access blocks. The current
941
+ location in the input stream can be determined from avail_in and data_type
942
+ as noted in the description for the Z_BLOCK flush parameter for inflate.
943
+
944
+ inflateMark returns the value noted above or -1 << 16 if the provided
945
+ source stream state was inconsistent.
946
+*/
947
+
948
+ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
949
+ gz_headerp head));
950
+/*
951
+ inflateGetHeader() requests that gzip header information be stored in the
952
+ provided gz_header structure. inflateGetHeader() may be called after
953
+ inflateInit2() or inflateReset(), and before the first call of inflate().
954
+ As inflate() processes the gzip stream, head->done is zero until the header
955
+ is completed, at which time head->done is set to one. If a zlib stream is
956
+ being decoded, then head->done is set to -1 to indicate that there will be
957
+ no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be
958
+ used to force inflate() to return immediately after header processing is
959
+ complete and before any actual data is decompressed.
960
+
961
+ The text, time, xflags, and os fields are filled in with the gzip header
962
+ contents. hcrc is set to true if there is a header CRC. (The header CRC
963
+ was valid if done is set to one.) If extra is not Z_NULL, then extra_max
964
+ contains the maximum number of bytes to write to extra. Once done is true,
965
+ extra_len contains the actual extra field length, and extra contains the
966
+ extra field, or that field truncated if extra_max is less than extra_len.
967
+ If name is not Z_NULL, then up to name_max characters are written there,
968
+ terminated with a zero unless the length is greater than name_max. If
969
+ comment is not Z_NULL, then up to comm_max characters are written there,
970
+ terminated with a zero unless the length is greater than comm_max. When any
971
+ of extra, name, or comment are not Z_NULL and the respective field is not
972
+ present in the header, then that field is set to Z_NULL to signal its
973
+ absence. This allows the use of deflateSetHeader() with the returned
974
+ structure to duplicate the header. However if those fields are set to
975
+ allocated memory, then the application will need to save those pointers
976
+ elsewhere so that they can be eventually freed.
977
+
978
+ If inflateGetHeader is not used, then the header information is simply
979
+ discarded. The header is always checked for validity, including the header
980
+ CRC if present. inflateReset() will reset the process to discard the header
981
+ information. The application would need to call inflateGetHeader() again to
982
+ retrieve the header from the next gzip stream.
983
+
984
+ inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
985
+ stream state was inconsistent.
986
+*/
987
+
988
+/*
989
+ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
990
+ unsigned char FAR *window));
991
+
992
+ Initialize the internal stream state for decompression using inflateBack()
993
+ calls. The fields zalloc, zfree and opaque in strm must be initialized
994
+ before the call. If zalloc and zfree are Z_NULL, then the default library-
995
+ derived memory allocation routines are used. windowBits is the base two
996
+ logarithm of the window size, in the range 8..15. window is a caller
997
+ supplied buffer of that size. Except for special applications where it is
998
+ assured that deflate was used with small window sizes, windowBits must be 15
999
+ and a 32K byte window must be supplied to be able to decompress general
1000
+ deflate streams.
1001
+
1002
+ See inflateBack() for the usage of these routines.
1003
+
1004
+ inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
1005
+ the parameters are invalid, Z_MEM_ERROR if the internal state could not be
1006
+ allocated, or Z_VERSION_ERROR if the version of the library does not match
1007
+ the version of the header file.
1008
+*/
1009
+
1010
+typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
1011
+typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
1012
+
1013
+ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
1014
+ in_func in, void FAR *in_desc,
1015
+ out_func out, void FAR *out_desc));
1016
+/*
1017
+ inflateBack() does a raw inflate with a single call using a call-back
1018
+ interface for input and output. This is more efficient than inflate() for
1019
+ file i/o applications in that it avoids copying between the output and the
1020
+ sliding window by simply making the window itself the output buffer. This
1021
+ function trusts the application to not change the output buffer passed by
1022
+ the output function, at least until inflateBack() returns.
1023
+
1024
+ inflateBackInit() must be called first to allocate the internal state
1025
+ and to initialize the state with the user-provided window buffer.
1026
+ inflateBack() may then be used multiple times to inflate a complete, raw
1027
+ deflate stream with each call. inflateBackEnd() is then called to free the
1028
+ allocated state.
1029
+
1030
+ A raw deflate stream is one with no zlib or gzip header or trailer.
1031
+ This routine would normally be used in a utility that reads zip or gzip
1032
+ files and writes out uncompressed files. The utility would decode the
1033
+ header and process the trailer on its own, hence this routine expects only
1034
+ the raw deflate stream to decompress. This is different from the normal
1035
+ behavior of inflate(), which expects either a zlib or gzip header and
1036
+ trailer around the deflate stream.
1037
+
1038
+ inflateBack() uses two subroutines supplied by the caller that are then
1039
+ called by inflateBack() for input and output. inflateBack() calls those
1040
+ routines until it reads a complete deflate stream and writes out all of the
1041
+ uncompressed data, or until it encounters an error. The function's
1042
+ parameters and return types are defined above in the in_func and out_func
1043
+ typedefs. inflateBack() will call in(in_desc, &buf) which should return the
1044
+ number of bytes of provided input, and a pointer to that input in buf. If
1045
+ there is no input available, in() must return zero--buf is ignored in that
1046
+ case--and inflateBack() will return a buffer error. inflateBack() will call
1047
+ out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out()
1048
+ should return zero on success, or non-zero on failure. If out() returns
1049
+ non-zero, inflateBack() will return with an error. Neither in() nor out()
1050
+ are permitted to change the contents of the window provided to
1051
+ inflateBackInit(), which is also the buffer that out() uses to write from.
1052
+ The length written by out() will be at most the window size. Any non-zero
1053
+ amount of input may be provided by in().
1054
+
1055
+ For convenience, inflateBack() can be provided input on the first call by
1056
+ setting strm->next_in and strm->avail_in. If that input is exhausted, then
1057
+ in() will be called. Therefore strm->next_in must be initialized before
1058
+ calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
1059
+ immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
1060
+ must also be initialized, and then if strm->avail_in is not zero, input will
1061
+ initially be taken from strm->next_in[0 .. strm->avail_in - 1].
1062
+
1063
+ The in_desc and out_desc parameters of inflateBack() is passed as the
1064
+ first parameter of in() and out() respectively when they are called. These
1065
+ descriptors can be optionally used to pass any information that the caller-
1066
+ supplied in() and out() functions need to do their job.
1067
+
1068
+ On return, inflateBack() will set strm->next_in and strm->avail_in to
1069
+ pass back any unused input that was provided by the last in() call. The
1070
+ return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
1071
+ if in() or out() returned an error, Z_DATA_ERROR if there was a format error
1072
+ in the deflate stream (in which case strm->msg is set to indicate the nature
1073
+ of the error), or Z_STREAM_ERROR if the stream was not properly initialized.
1074
+ In the case of Z_BUF_ERROR, an input or output error can be distinguished
1075
+ using strm->next_in which will be Z_NULL only if in() returned an error. If
1076
+ strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning
1077
+ non-zero. (in() will always be called before out(), so strm->next_in is
1078
+ assured to be defined if out() returns non-zero.) Note that inflateBack()
1079
+ cannot return Z_OK.
1080
+*/
1081
+
1082
+ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
1083
+/*
1084
+ All memory allocated by inflateBackInit() is freed.
1085
+
1086
+ inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
1087
+ state was inconsistent.
1088
+*/
1089
+
1090
+ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
1091
+/* Return flags indicating compile-time options.
1092
+
1093
+ Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
1094
+ 1.0: size of uInt
1095
+ 3.2: size of uLong
1096
+ 5.4: size of voidpf (pointer)
1097
+ 7.6: size of z_off_t
1098
+
1099
+ Compiler, assembler, and debug options:
1100
+ 8: DEBUG
1101
+ 9: ASMV or ASMINF -- use ASM code
1102
+ 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
1103
+ 11: 0 (reserved)
1104
+
1105
+ One-time table building (smaller code, but not thread-safe if true):
1106
+ 12: BUILDFIXED -- build static block decoding tables when needed
1107
+ 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
1108
+ 14,15: 0 (reserved)
1109
+
1110
+ Library content (indicates missing functionality):
1111
+ 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
1112
+ deflate code when not needed)
1113
+ 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
1114
+ and decode gzip streams (to avoid linking crc code)
1115
+ 18-19: 0 (reserved)
1116
+
1117
+ Operation variations (changes in library functionality):
1118
+ 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
1119
+ 21: FASTEST -- deflate algorithm with only one, lowest compression level
1120
+ 22,23: 0 (reserved)
1121
+
1122
+ The sprintf variant used by gzprintf (zero is best):
1123
+ 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
1124
+ 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
1125
+ 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
1126
+
1127
+ Remainder:
1128
+ 27-31: 0 (reserved)
1129
+ */
1130
+
1131
+#ifndef Z_SOLO
1132
+
1133
+ /* utility functions */
1134
+
1135
+/*
1136
+ The following utility functions are implemented on top of the basic
1137
+ stream-oriented functions. To simplify the interface, some default options
1138
+ are assumed (compression level and memory usage, standard memory allocation
1139
+ functions). The source code of these utility functions can be modified if
1140
+ you need special options.
1141
+*/
1142
+
1143
+ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
1144
+ const Bytef *source, uLong sourceLen));
1145
+/*
1146
+ Compresses the source buffer into the destination buffer. sourceLen is
1147
+ the byte length of the source buffer. Upon entry, destLen is the total size
1148
+ of the destination buffer, which must be at least the value returned by
1149
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
1150
+ compressed buffer.
1151
+
1152
+ compress returns Z_OK if success, Z_MEM_ERROR if there was not
1153
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
1154
+ buffer.
1155
+*/
1156
+
1157
+ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
1158
+ const Bytef *source, uLong sourceLen,
1159
+ int level));
1160
+/*
1161
+ Compresses the source buffer into the destination buffer. The level
1162
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
1163
+ length of the source buffer. Upon entry, destLen is the total size of the
1164
+ destination buffer, which must be at least the value returned by
1165
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
1166
+ compressed buffer.
1167
+
1168
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1169
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
1170
+ Z_STREAM_ERROR if the level parameter is invalid.
1171
+*/
1172
+
1173
+ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
1174
+/*
1175
+ compressBound() returns an upper bound on the compressed size after
1176
+ compress() or compress2() on sourceLen bytes. It would be used before a
1177
+ compress() or compress2() call to allocate the destination buffer.
1178
+*/
1179
+
1180
+ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
1181
+ const Bytef *source, uLong sourceLen));
1182
+/*
1183
+ Decompresses the source buffer into the destination buffer. sourceLen is
1184
+ the byte length of the source buffer. Upon entry, destLen is the total size
1185
+ of the destination buffer, which must be large enough to hold the entire
1186
+ uncompressed data. (The size of the uncompressed data must have been saved
1187
+ previously by the compressor and transmitted to the decompressor by some
1188
+ mechanism outside the scope of this compression library.) Upon exit, destLen
1189
+ is the actual size of the uncompressed buffer.
1190
+
1191
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
1192
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
1193
+ buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In
1194
+ the case where there is not enough room, uncompress() will fill the output
1195
+ buffer with the uncompressed data up to that point.
1196
+*/
1197
+
1198
+ /* gzip file access functions */
1199
+
1200
+/*
1201
+ This library supports reading and writing files in gzip (.gz) format with
1202
+ an interface similar to that of stdio, using the functions that start with
1203
+ "gz". The gzip format is different from the zlib format. gzip is a gzip
1204
+ wrapper, documented in RFC 1952, wrapped around a deflate stream.
1205
+*/
1206
+
1207
+typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */
1208
+
1209
+/*
1210
+ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
1211
+
1212
+ Opens a gzip (.gz) file for reading or writing. The mode parameter is as
1213
+ in fopen ("rb" or "wb") but can also include a compression level ("wb9") or
1214
+ a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only
1215
+ compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F'
1216
+ for fixed code compression as in "wb9F". (See the description of
1217
+ deflateInit2 for more information about the strategy parameter.) 'T' will
1218
+ request transparent writing or appending with no compression and not using
1219
+ the gzip format.
1220
+
1221
+ "a" can be used instead of "w" to request that the gzip stream that will
1222
+ be written be appended to the file. "+" will result in an error, since
1223
+ reading and writing to the same gzip file is not supported. The addition of
1224
+ "x" when writing will create the file exclusively, which fails if the file
1225
+ already exists. On systems that support it, the addition of "e" when
1226
+ reading or writing will set the flag to close the file on an execve() call.
1227
+
1228
+ These functions, as well as gzip, will read and decode a sequence of gzip
1229
+ streams in a file. The append function of gzopen() can be used to create
1230
+ such a file. (Also see gzflush() for another way to do this.) When
1231
+ appending, gzopen does not test whether the file begins with a gzip stream,
1232
+ nor does it look for the end of the gzip streams to begin appending. gzopen
1233
+ will simply append a gzip stream to the existing file.
1234
+
1235
+ gzopen can be used to read a file which is not in gzip format; in this
1236
+ case gzread will directly read from the file without decompression. When
1237
+ reading, this will be detected automatically by looking for the magic two-
1238
+ byte gzip header.
1239
+
1240
+ gzopen returns NULL if the file could not be opened, if there was
1241
+ insufficient memory to allocate the gzFile state, or if an invalid mode was
1242
+ specified (an 'r', 'w', or 'a' was not provided, or '+' was provided).
1243
+ errno can be checked to determine if the reason gzopen failed was that the
1244
+ file could not be opened.
1245
+*/
1246
+
1247
+ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
1248
+/*
1249
+ gzdopen associates a gzFile with the file descriptor fd. File descriptors
1250
+ are obtained from calls like open, dup, creat, pipe or fileno (if the file
1251
+ has been previously opened with fopen). The mode parameter is as in gzopen.
1252
+
1253
+ The next call of gzclose on the returned gzFile will also close the file
1254
+ descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
1255
+ fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
1256
+ mode);. The duplicated descriptor should be saved to avoid a leak, since
1257
+ gzdopen does not close fd if it fails. If you are using fileno() to get the
1258
+ file descriptor from a FILE *, then you will have to use dup() to avoid
1259
+ double-close()ing the file descriptor. Both gzclose() and fclose() will
1260
+ close the associated file descriptor, so they need to have different file
1261
+ descriptors.
1262
+
1263
+ gzdopen returns NULL if there was insufficient memory to allocate the
1264
+ gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not
1265
+ provided, or '+' was provided), or if fd is -1. The file descriptor is not
1266
+ used until the next gz* read, write, seek, or close operation, so gzdopen
1267
+ will not detect if fd is invalid (unless fd is -1).
1268
+*/
1269
+
1270
+ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
1271
+/*
1272
+ Set the internal buffer size used by this library's functions. The
1273
+ default buffer size is 8192 bytes. This function must be called after
1274
+ gzopen() or gzdopen(), and before any other calls that read or write the
1275
+ file. The buffer memory allocation is always deferred to the first read or
1276
+ write. Two buffers are allocated, either both of the specified size when
1277
+ writing, or one of the specified size and the other twice that size when
1278
+ reading. A larger buffer size of, for example, 64K or 128K bytes will
1279
+ noticeably increase the speed of decompression (reading).
1280
+
1281
+ The new buffer size also affects the maximum length for gzprintf().
1282
+
1283
+ gzbuffer() returns 0 on success, or -1 on failure, such as being called
1284
+ too late.
1285
+*/
1286
+
1287
+ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
1288
+/*
1289
+ Dynamically update the compression level or strategy. See the description
1290
+ of deflateInit2 for the meaning of these parameters.
1291
+
1292
+ gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
1293
+ opened for writing.
1294
+*/
1295
+
1296
+ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
1297
+/*
1298
+ Reads the given number of uncompressed bytes from the compressed file. If
1299
+ the input file is not in gzip format, gzread copies the given number of
1300
+ bytes into the buffer directly from the file.
1301
+
1302
+ After reaching the end of a gzip stream in the input, gzread will continue
1303
+ to read, looking for another gzip stream. Any number of gzip streams may be
1304
+ concatenated in the input file, and will all be decompressed by gzread().
1305
+ If something other than a gzip stream is encountered after a gzip stream,
1306
+ that remaining trailing garbage is ignored (and no error is returned).
1307
+
1308
+ gzread can be used to read a gzip file that is being concurrently written.
1309
+ Upon reaching the end of the input, gzread will return with the available
1310
+ data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
1311
+ gzclearerr can be used to clear the end of file indicator in order to permit
1312
+ gzread to be tried again. Z_OK indicates that a gzip stream was completed
1313
+ on the last gzread. Z_BUF_ERROR indicates that the input file ended in the
1314
+ middle of a gzip stream. Note that gzread does not return -1 in the event
1315
+ of an incomplete gzip stream. This error is deferred until gzclose(), which
1316
+ will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
1317
+ stream. Alternatively, gzerror can be used before gzclose to detect this
1318
+ case.
1319
+
1320
+ gzread returns the number of uncompressed bytes actually read, less than
1321
+ len for end of file, or -1 for error.
1322
+*/
1323
+
1324
+ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
1325
+ voidpc buf, unsigned len));
1326
+/*
1327
+ Writes the given number of uncompressed bytes into the compressed file.
1328
+ gzwrite returns the number of uncompressed bytes written or 0 in case of
1329
+ error.
1330
+*/
1331
+
1332
+ZEXTERN int ZEXPORTVA gzprintf Z_ARG((gzFile file, const char *format, ...));
1333
+/*
1334
+ Converts, formats, and writes the arguments to the compressed file under
1335
+ control of the format string, as in fprintf. gzprintf returns the number of
1336
+ uncompressed bytes actually written, or 0 in case of error. The number of
1337
+ uncompressed bytes written is limited to 8191, or one less than the buffer
1338
+ size given to gzbuffer(). The caller should assure that this limit is not
1339
+ exceeded. If it is exceeded, then gzprintf() will return an error (0) with
1340
+ nothing written. In this case, there may also be a buffer overflow with
1341
+ unpredictable consequences, which is possible only if zlib was compiled with
1342
+ the insecure functions sprintf() or vsprintf() because the secure snprintf()
1343
+ or vsnprintf() functions were not available. This can be determined using
1344
+ zlibCompileFlags().
1345
+*/
1346
+
1347
+ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
1348
+/*
1349
+ Writes the given null-terminated string to the compressed file, excluding
1350
+ the terminating null character.
1351
+
1352
+ gzputs returns the number of characters written, or -1 in case of error.
1353
+*/
1354
+
1355
+ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
1356
+/*
1357
+ Reads bytes from the compressed file until len-1 characters are read, or a
1358
+ newline character is read and transferred to buf, or an end-of-file
1359
+ condition is encountered. If any characters are read or if len == 1, the
1360
+ string is terminated with a null character. If no characters are read due
1361
+ to an end-of-file or len < 1, then the buffer is left untouched.
1362
+
1363
+ gzgets returns buf which is a null-terminated string, or it returns NULL
1364
+ for end-of-file or in case of error. If there was an error, the contents at
1365
+ buf are indeterminate.
1366
+*/
1367
+
1368
+ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
1369
+/*
1370
+ Writes c, converted to an unsigned char, into the compressed file. gzputc
1371
+ returns the value that was written, or -1 in case of error.
1372
+*/
1373
+
1374
+ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
1375
+/*
1376
+ Reads one byte from the compressed file. gzgetc returns this byte or -1
1377
+ in case of end of file or error. This is implemented as a macro for speed.
1378
+ As such, it does not do all of the checking the other functions do. I.e.
1379
+ it does not check to see if file is NULL, nor whether the structure file
1380
+ points to has been clobbered or not.
1381
+*/
1382
+
1383
+ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
1384
+/*
1385
+ Push one character back onto the stream to be read as the first character
1386
+ on the next read. At least one character of push-back is allowed.
1387
+ gzungetc() returns the character pushed, or -1 on failure. gzungetc() will
1388
+ fail if c is -1, and may fail if a character has been pushed but not read
1389
+ yet. If gzungetc is used immediately after gzopen or gzdopen, at least the
1390
+ output buffer size of pushed characters is allowed. (See gzbuffer above.)
1391
+ The pushed character will be discarded if the stream is repositioned with
1392
+ gzseek() or gzrewind().
1393
+*/
1394
+
1395
+ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
1396
+/*
1397
+ Flushes all pending output into the compressed file. The parameter flush
1398
+ is as in the deflate() function. The return value is the zlib error number
1399
+ (see function gzerror below). gzflush is only permitted when writing.
1400
+
1401
+ If the flush parameter is Z_FINISH, the remaining data is written and the
1402
+ gzip stream is completed in the output. If gzwrite() is called again, a new
1403
+ gzip stream will be started in the output. gzread() is able to read such
1404
+ concatented gzip streams.
1405
+
1406
+ gzflush should be called only when strictly necessary because it will
1407
+ degrade compression if called too often.
1408
+*/
1409
+
1410
+/*
1411
+ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
1412
+ z_off_t offset, int whence));
1413
+
1414
+ Sets the starting position for the next gzread or gzwrite on the given
1415
+ compressed file. The offset represents a number of bytes in the
1416
+ uncompressed data stream. The whence parameter is defined as in lseek(2);
1417
+ the value SEEK_END is not supported.
1418
+
1419
+ If the file is opened for reading, this function is emulated but can be
1420
+ extremely slow. If the file is opened for writing, only forward seeks are
1421
+ supported; gzseek then compresses a sequence of zeroes up to the new
1422
+ starting position.
1423
+
1424
+ gzseek returns the resulting offset location as measured in bytes from
1425
+ the beginning of the uncompressed stream, or -1 in case of error, in
1426
+ particular if the file is opened for writing and the new starting position
1427
+ would be before the current position.
1428
+*/
1429
+
1430
+ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
1431
+/*
1432
+ Rewinds the given file. This function is supported only for reading.
1433
+
1434
+ gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
1435
+*/
1436
+
1437
+/*
1438
+ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
1439
+
1440
+ Returns the starting position for the next gzread or gzwrite on the given
1441
+ compressed file. This position represents a number of bytes in the
1442
+ uncompressed data stream, and is zero when starting, even if appending or
1443
+ reading a gzip stream from the middle of a file using gzdopen().
1444
+
1445
+ gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
1446
+*/
1447
+
1448
+/*
1449
+ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
1450
+
1451
+ Returns the current offset in the file being read or written. This offset
1452
+ includes the count of bytes that precede the gzip stream, for example when
1453
+ appending or when using gzdopen() for reading. When reading, the offset
1454
+ does not include as yet unused buffered input. This information can be used
1455
+ for a progress indicator. On error, gzoffset() returns -1.
1456
+*/
1457
+
1458
+ZEXTERN int ZEXPORT gzeof OF((gzFile file));
1459
+/*
1460
+ Returns true (1) if the end-of-file indicator has been set while reading,
1461
+ false (0) otherwise. Note that the end-of-file indicator is set only if the
1462
+ read tried to go past the end of the input, but came up short. Therefore,
1463
+ just like feof(), gzeof() may return false even if there is no more data to
1464
+ read, in the event that the last read request was for the exact number of
1465
+ bytes remaining in the input file. This will happen if the input file size
1466
+ is an exact multiple of the buffer size.
1467
+
1468
+ If gzeof() returns true, then the read functions will return no more data,
1469
+ unless the end-of-file indicator is reset by gzclearerr() and the input file
1470
+ has grown since the previous end of file was detected.
1471
+*/
1472
+
1473
+ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
1474
+/*
1475
+ Returns true (1) if file is being copied directly while reading, or false
1476
+ (0) if file is a gzip stream being decompressed.
1477
+
1478
+ If the input file is empty, gzdirect() will return true, since the input
1479
+ does not contain a gzip stream.
1480
+
1481
+ If gzdirect() is used immediately after gzopen() or gzdopen() it will
1482
+ cause buffers to be allocated to allow reading the file to determine if it
1483
+ is a gzip file. Therefore if gzbuffer() is used, it should be called before
1484
+ gzdirect().
1485
+
1486
+ When writing, gzdirect() returns true (1) if transparent writing was
1487
+ requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note:
1488
+ gzdirect() is not needed when writing. Transparent writing must be
1489
+ explicitly requested, so the application already knows the answer. When
1490
+ linking statically, using gzdirect() will include all of the zlib code for
1491
+ gzip file reading and decompression, which may not be desired.)
1492
+*/
1493
+
1494
+ZEXTERN int ZEXPORT gzclose OF((gzFile file));
1495
+/*
1496
+ Flushes all pending output if necessary, closes the compressed file and
1497
+ deallocates the (de)compression state. Note that once file is closed, you
1498
+ cannot call gzerror with file, since its structures have been deallocated.
1499
+ gzclose must not be called more than once on the same file, just as free
1500
+ must not be called more than once on the same allocation.
1501
+
1502
+ gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a
1503
+ file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
1504
+ last read ended in the middle of a gzip stream, or Z_OK on success.
1505
+*/
1506
+
1507
+ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
1508
+ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
1509
+/*
1510
+ Same as gzclose(), but gzclose_r() is only for use when reading, and
1511
+ gzclose_w() is only for use when writing or appending. The advantage to
1512
+ using these instead of gzclose() is that they avoid linking in zlib
1513
+ compression or decompression code that is not used when only reading or only
1514
+ writing respectively. If gzclose() is used, then both compression and
1515
+ decompression code will be included the application when linking to a static
1516
+ zlib library.
1517
+*/
1518
+
1519
+ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
1520
+/*
1521
+ Returns the error message for the last error which occurred on the given
1522
+ compressed file. errnum is set to zlib error number. If an error occurred
1523
+ in the file system and not in the compression library, errnum is set to
1524
+ Z_ERRNO and the application may consult errno to get the exact error code.
1525
+
1526
+ The application must not modify the returned string. Future calls to
1527
+ this function may invalidate the previously returned string. If file is
1528
+ closed, then the string previously returned by gzerror will no longer be
1529
+ available.
1530
+
1531
+ gzerror() should be used to distinguish errors from end-of-file for those
1532
+ functions above that do not distinguish those cases in their return values.
1533
+*/
1534
+
1535
+ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
1536
+/*
1537
+ Clears the error and end-of-file flags for file. This is analogous to the
1538
+ clearerr() function in stdio. This is useful for continuing to read a gzip
1539
+ file that is being written concurrently.
1540
+*/
1541
+
1542
+#endif /* !Z_SOLO */
1543
+
1544
+ /* checksum functions */
1545
+
1546
+/*
1547
+ These functions are not related to compression but are exported
1548
+ anyway because they might be useful in applications using the compression
1549
+ library.
1550
+*/
1551
+
1552
+ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
1553
+/*
1554
+ Update a running Adler-32 checksum with the bytes buf[0..len-1] and
1555
+ return the updated checksum. If buf is Z_NULL, this function returns the
1556
+ required initial value for the checksum.
1557
+
1558
+ An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
1559
+ much faster.
1560
+
1561
+ Usage example:
1562
+
1563
+ uLong adler = adler32(0L, Z_NULL, 0);
1564
+
1565
+ while (read_buffer(buffer, length) != EOF) {
1566
+ adler = adler32(adler, buffer, length);
1567
+ }
1568
+ if (adler != original_adler) error();
1569
+*/
1570
+
1571
+/*
1572
+ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
1573
+ z_off_t len2));
1574
+
1575
+ Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
1576
+ and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
1577
+ each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
1578
+ seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note
1579
+ that the z_off_t type (like off_t) is a signed integer. If len2 is
1580
+ negative, the result has no meaning or utility.
1581
+*/
1582
+
1583
+ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
1584
+/*
1585
+ Update a running CRC-32 with the bytes buf[0..len-1] and return the
1586
+ updated CRC-32. If buf is Z_NULL, this function returns the required
1587
+ initial value for the crc. Pre- and post-conditioning (one's complement) is
1588
+ performed within this function so it shouldn't be done by the application.
1589
+
1590
+ Usage example:
1591
+
1592
+ uLong crc = crc32(0L, Z_NULL, 0);
1593
+
1594
+ while (read_buffer(buffer, length) != EOF) {
1595
+ crc = crc32(crc, buffer, length);
1596
+ }
1597
+ if (crc != original_crc) error();
1598
+*/
1599
+
1600
+/*
1601
+ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
1602
+
1603
+ Combine two CRC-32 check values into one. For two sequences of bytes,
1604
+ seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
1605
+ calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
1606
+ check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
1607
+ len2.
1608
+*/
1609
+
1610
+
1611
+ /* various hacks, don't look :) */
1612
+
1613
+/* deflateInit and inflateInit are macros to allow checking the zlib version
1614
+ * and the compiler's view of z_stream:
1615
+ */
1616
+ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
1617
+ const char *version, int stream_size));
1618
+ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
1619
+ const char *version, int stream_size));
1620
+ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
1621
+ int windowBits, int memLevel,
1622
+ int strategy, const char *version,
1623
+ int stream_size));
1624
+ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
1625
+ const char *version, int stream_size));
1626
+ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
1627
+ unsigned char FAR *window,
1628
+ const char *version,
1629
+ int stream_size));
1630
+#define deflateInit(strm, level) \
1631
+ deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
1632
+#define inflateInit(strm) \
1633
+ inflateInit_((strm), ZLIB_VERSION, (int)sizeof(z_stream))
1634
+#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
1635
+ deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
1636
+ (strategy), ZLIB_VERSION, (int)sizeof(z_stream))
1637
+#define inflateInit2(strm, windowBits) \
1638
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, \
1639
+ (int)sizeof(z_stream))
1640
+#define inflateBackInit(strm, windowBits, window) \
1641
+ inflateBackInit_((strm), (windowBits), (window), \
1642
+ ZLIB_VERSION, (int)sizeof(z_stream))
1643
+
1644
+#ifndef Z_SOLO
1645
+
1646
+/* gzgetc() macro and its supporting function and exposed data structure. Note
1647
+ * that the real internal state is much larger than the exposed structure.
1648
+ * This abbreviated structure exposes just enough for the gzgetc() macro. The
1649
+ * user should not mess with these exposed elements, since their names or
1650
+ * behavior could change in the future, perhaps even capriciously. They can
1651
+ * only be used by the gzgetc() macro. You have been warned.
1652
+ */
1653
+struct gzFile_s {
1654
+ unsigned have;
1655
+ unsigned char *next;
1656
+ z_off64_t pos;
1657
+};
1658
+ZEXTERN int ZEXPORT gzgetc_ OF((gzFile file)); /* backward compatibility */
1659
+#ifdef Z_PREFIX_SET
1660
+# undef z_gzgetc
1661
+# define z_gzgetc(g) \
1662
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
1663
+#else
1664
+# define gzgetc(g) \
1665
+ ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : gzgetc(g))
1666
+#endif
1667
+
1668
+/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or
1669
+ * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if
1670
+ * both are true, the application gets the *64 functions, and the regular
1671
+ * functions are changed to 64 bits) -- in case these are set on systems
1672
+ * without large file support, _LFS64_LARGEFILE must also be true
1673
+ */
1674
+#ifdef Z_LARGE64
1675
+ ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
1676
+ ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
1677
+ ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
1678
+ ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
1679
+ ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t));
1680
+ ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t));
1681
+#endif
1682
+
1683
+#if !defined(ZLIB_INTERNAL) && defined(Z_WANT64)
1684
+# ifdef Z_PREFIX_SET
1685
+# define z_gzopen z_gzopen64
1686
+# define z_gzseek z_gzseek64
1687
+# define z_gztell z_gztell64
1688
+# define z_gzoffset z_gzoffset64
1689
+# define z_adler32_combine z_adler32_combine64
1690
+# define z_crc32_combine z_crc32_combine64
1691
+# else
1692
+# define gzopen gzopen64
1693
+# define gzseek gzseek64
1694
+# define gztell gztell64
1695
+# define gzoffset gzoffset64
1696
+# define adler32_combine adler32_combine64
1697
+# define crc32_combine crc32_combine64
1698
+# endif
1699
+# ifndef Z_LARGE64
1700
+ ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
1701
+ ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int));
1702
+ ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile));
1703
+ ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile));
1704
+ ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
1705
+ ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
1706
+# endif
1707
+#else
1708
+ ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *));
1709
+ ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int));
1710
+ ZEXTERN z_off_t ZEXPORT gztell OF((gzFile));
1711
+ ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile));
1712
+ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1713
+ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1714
+#endif
1715
+
1716
+#else /* Z_SOLO */
1717
+
1718
+ ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t));
1719
+ ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t));
1720
+
1721
+#endif /* !Z_SOLO */
1722
+
1723
+/* hack for buggy compilers */
1724
+#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
1725
+ struct internal_state {int dummy;};
1726
+#endif
1727
+
1728
+/* undocumented functions */
1729
+ZEXTERN const char * ZEXPORT zError OF((int));
1730
+ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp));
1731
+ZEXTERN const z_crc_t FAR * ZEXPORT get_crc_table OF((void));
1732
+ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int));
1733
+ZEXTERN int ZEXPORT inflateResetKeep OF((z_streamp));
1734
+ZEXTERN int ZEXPORT deflateResetKeep OF((z_streamp));
1735
+#if defined(_WIN32) && !defined(Z_SOLO)
1736
+ZEXTERN gzFile ZEXPORT gzopen_w OF((const wchar_t *path,
1737
+ const char *mode));
1738
+#endif
1739
+
1740
+#ifdef __cplusplus
1741
+}
1742
+#endif
1743
+
1744
+#endif /* ZLIB_H */