1 diff -Nur linux-mips-cvs/drivers/net/port_based_qos/Atan.c linux-broadcom/drivers/net/port_based_qos/Atan.c
2 --- linux-mips-cvs/drivers/net/port_based_qos/Atan.c 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-broadcom/drivers/net/port_based_qos/Atan.c 2005-01-31 13:13:14.000000000 +0100
8 +extern void conf_gpio(int x);
10 +/*----------------------------------------------------------------------------
11 +Write specified data to eeprom
12 +entry: *src = pointer to specified data to write
13 + len = number of short(2 bytes) to be written
15 +void write_eeprom( short RegNumber, unsigned short *data, int len )
18 + unsigned short s_addr, s_data;
19 + unsigned short *src;
22 + SetEEpromToSendState();
23 +// the write enable(WEN) instruction must be executed before any device
24 +// programming can be done
27 + SendAddrToEEprom(s_data); //00000001 0011000000B
28 + SetCSToLowForEEprom();
30 + s_addr = 0x0500 | (RegNumber & 0x0ff); //00000001 01dddddddd
33 + for (i2 = len; i2 > 0 ; i2 --)
35 + SendAddrToEEprom(s_addr); //00000001 01dddddd
36 + SendDataToEEprom(s_data); //dddddddd dddddddd
37 + SetCSToLowForEEprom();
38 + SetCSToLowForEEprom();
44 +// after all data has been written to EEprom , the write disable(WDS)
45 +// instruction must be executed
46 + SetCSToHighForEEprom();
48 + SendAddrToEEprom(s_data); //00000001 00000000B
49 + SetCSToLowForEEprom();
50 + SetCSToLowForEEprom();
53 +void SetEEpromToSendState()
67 +void ResetEEpromToSendState()
81 +void SetCSToLowForEEprom()
95 +void SetCSToHighForEEprom()
98 + conf_gpio(B_ECS|B_ECK);
99 + conf_gpio(B_ECS|B_ECK);
109 +void send_1ToEEprom()
111 + conf_gpio(B_ECS|B_EDI);
112 + conf_gpio(B_ECS|B_ECK|B_EDI);
113 + conf_gpio(B_ECS|B_ECK|B_EDI);
114 + conf_gpio(B_ECS|B_EDI);
123 +void send_0ToEEprom()
126 + conf_gpio(B_ECS|B_ECK);
127 + conf_gpio(B_ECS|B_ECK);
140 + unsigned int status;
142 + SetCSToLowForEEprom();
143 + SetCSToHighForEEprom();
145 + SetCSToHighForEEprom();
146 + //status = ReadGPIOData(EDO);
147 + status = gpio & B_EDO; // read EDO bit
149 + while (!status); // wait for write - ready
150 + SetCSToLowForEEprom();
154 +void SendDataToEEprom(short s_data)
158 + for (data_mask = 0x8000; data_mask != 0; )
160 + if (s_data & data_mask)
164 + data_mask = data_mask >> 1;
168 +void SendAddrToEEprom(short s_data)
172 + for (data_mask = 0x0400 ;data_mask != 0; )
174 + if (s_data & data_mask)
178 + data_mask = data_mask >> 1;
182 diff -Nur linux-mips-cvs/drivers/net/port_based_qos/Atan.h linux-broadcom/drivers/net/port_based_qos/Atan.h
183 --- linux-mips-cvs/drivers/net/port_based_qos/Atan.h 1970-01-01 01:00:00.000000000 +0100
184 +++ linux-broadcom/drivers/net/port_based_qos/Atan.h 2005-01-31 13:13:14.000000000 +0100
189 +#define SINGLECOLOUR 0x1
190 +#define DUALCOLOUR 0x2
192 +void write_eeprom(short,unsigned short *,int);
193 +void SetEEpromToSendState(void);
194 +void ResetEEpromToSendState(void);
195 +void SetCSToLowForEEprom(void);
196 +void SetCSToHighForEEprom(void);
197 +void send_1ToEEprom(void);
198 +void send_0ToEEprom(void);
199 +//void WriteWait(void);
200 +void SendAddrToEEprom(short);
201 +void SendDataToEEprom(short);
204 diff -Nur linux-mips-cvs/drivers/net/port_based_qos/Makefile linux-broadcom/drivers/net/port_based_qos/Makefile
205 --- linux-mips-cvs/drivers/net/port_based_qos/Makefile 1970-01-01 01:00:00.000000000 +0100
206 +++ linux-broadcom/drivers/net/port_based_qos/Makefile 2005-01-31 13:13:14.000000000 +0100
208 +# Copyright 2001, Cybertan Corporation
209 +# All Rights Reserved.
211 +# This is UNPUBLISHED PROPRIETARY SOURCE CODE of Cybertan Corporation;
212 +# the contents of this file may not be disclosed to third parties, copied or
213 +# duplicated in any form, in whole or in part, without the prior written
214 +# permission of Cybertan Corporation.
220 +O_TARGET := port_based_qos_mod.o
222 +PORT_BASED_QOS_MOD_OBJS := port_based_qos.o Atan.o c47xx.o eeprom.o
225 +obj-y := $(PORT_BASED_QOS_MOD_OBJS)
226 +obj-m := $(O_TARGET)
228 +SRCBASE := $(TOPDIR)/../..
229 +EXTRA_CFLAGS += -I$(SRCBASE)/include -Wall -I$(SRCBASE)/
231 +vpath %.c $(SRCBASE)/shared
233 +include $(TOPDIR)/Rules.make
235 diff -Nur linux-mips-cvs/drivers/net/port_based_qos/c47xx.c linux-broadcom/drivers/net/port_based_qos/c47xx.c
236 --- linux-mips-cvs/drivers/net/port_based_qos/c47xx.c 1970-01-01 01:00:00.000000000 +0100
237 +++ linux-broadcom/drivers/net/port_based_qos/c47xx.c 2005-01-31 13:13:14.000000000 +0100
239 +#include <typedefs.h>
240 +#include <sbutils.h>
241 +#include <bcmdevs.h>
243 +#include <bcmnvram.h>
244 +#include <bcmutils.h>
247 +#include <sbchipc.h>
248 +#include <sbconfig.h>
249 +#include <sbextif.h>
252 +extern uint32 sb_gpioouten(void *sbh, uint32 mask, uint32 val);
253 +extern uint32 sb_gpioout(void *sbh, uint32 mask, uint32 val);
254 +extern uint32 sb_gpioin(void *sbh);
255 +extern uint32 sb_gpiointmask(void *sbh, uint32 mask, uint32 val);
257 +#define OUTENMASK B_RESET|B_ECS|B_ECK|B_EDI
258 +#define CFGMASK B_ECS|B_ECK|B_EDI
259 +#define BIT(x) (1 << (x))
260 +#define ASSERT(exp) do {} while (0)
267 + /* Enable all of output pins */
268 + sb_gpioouten(sbh, OUTENMASK, OUTENMASK);
270 + /* We don't want the B_RESET pin changed, unless
271 + * it tries to set the B_RESET pin.
274 + sb_gpioout(sbh, OUTENMASK, x);
276 + sb_gpioout(sbh, CFGMASK, x);
281 +gpio_line_set(int x, unsigned int value)
286 + sb_gpioout(sbh, BIT(x), BIT(x));
287 + else if (value == 0)
288 + sb_gpioout(sbh, BIT(x), 0);
292 +gpio_line_get(int x, int *value)
296 + *value = (sb_gpioin(sbh) >> x) & 0x1;
300 +gpio_line_config_in(int x)
304 + sb_gpioouten(sbh, BIT(x), 0);
305 + sb_gpiointmask(sbh, BIT(x), BIT(x));
309 +gpio_line_config_out(int x)
313 + sb_gpiointmask(sbh, BIT(x), 0);
314 + sb_gpioouten(sbh, BIT(x), BIT(x));
318 +gpio_line_config_out_all(int x)
322 + sb_gpioouten(sbh, OUTENMASK, OUTENMASK);
324 diff -Nur linux-mips-cvs/drivers/net/port_based_qos/c47xx.h linux-broadcom/drivers/net/port_based_qos/c47xx.h
325 --- linux-mips-cvs/drivers/net/port_based_qos/c47xx.h 1970-01-01 01:00:00.000000000 +0100
326 +++ linux-broadcom/drivers/net/port_based_qos/c47xx.h 2005-01-31 13:13:14.000000000 +0100
331 +extern void *bcm947xx_sbh;
332 +#define sbh bcm947xx_sbh
344 +#define B_RESET 1<<GPIO0
345 +#define B_ECS 1<<GPIO2
346 +#define B_ECK 1<<GPIO3
347 +#define B_EDO 1<<GPIO4
348 +#define B_EDI 1<<GPIO5
351 diff -Nur linux-mips-cvs/drivers/net/port_based_qos/eeprom.c linux-broadcom/drivers/net/port_based_qos/eeprom.c
352 --- linux-mips-cvs/drivers/net/port_based_qos/eeprom.c 1970-01-01 01:00:00.000000000 +0100
353 +++ linux-broadcom/drivers/net/port_based_qos/eeprom.c 2005-01-31 13:13:14.000000000 +0100
355 +#include <linux/delay.h>
363 +static void SetCSToLowForEEprom(void);
364 +//static void SetCSToHighForEEprom(void);
365 +static void send1ToEEprom(void);
366 +static void send0ToEEprom(void);
367 +static void InitSerialInterface(void);
368 +static void SerialPulse(void);
369 +static void WriteDataToRegister(unsigned short RegNumber, unsigned short data);
370 +void ReadDataFromRegister(unsigned short addr, unsigned short *hidata, unsigned short *lodata,int select_count);
371 +static void WriteDataToEEprom(unsigned short addr, unsigned short data);
372 +static void WriteCmdToEEprom(unsigned short cmd);
373 +extern void gpio_line_set(int x, unsigned int value);
374 +extern void gpio_line_get(int x, int *value);
375 +extern void gpio_line_config_out(int x);
376 +extern void gpio_line_config_in(int x);
377 +extern void gpio_line_config_out_all(void);
384 +static void SetEEpromToSendState(void)
386 + gpio_line_set(EECS_PIN, 0);
387 + gpio_line_set(EECK_PIN, 0);
388 + gpio_line_set(EEDI_PIN, 1);
389 +// gpio_line_set(EEDO_PIN, 1); /* high impedance */
392 + gpio_line_set(EECS_PIN, 1);
393 +// gpio_line_set(EEDO_PIN, 1); /* high impedance */
397 +static void EEpromInit(void)
399 + gpio_line_set(EECS_PIN, 0);
400 + gpio_line_set(EECK_PIN, 0);
401 + gpio_line_set(EEDI_PIN, 1);
402 + gpio_line_set(EEDO_PIN, 1); /* high impedance */
412 +static void ResetEEpromToSendState(void)
414 + gpio_line_set(EECS_PIN, 0);
415 + gpio_line_set(EEDI_PIN, 0);
416 + //gpio_line_set(EEDO_PIN, 0);
417 + gpio_line_set(EECK_PIN, 0);
426 +static void SetCSToLowForEEprom(void)
428 + /* minimum tcs is 1us */
429 + gpio_line_set(EECS_PIN, 0);
430 + gpio_line_set(EECS_PIN, 0);
432 + gpio_line_set(EECK_PIN, 0);
433 + gpio_line_set(EECK_PIN, 1);
434 + gpio_line_set(EECK_PIN, 1);
435 + gpio_line_set(EECK_PIN, 1);
436 + gpio_line_set(EECK_PIN, 1);
437 + gpio_line_set(EECK_PIN, 0);
439 + gpio_line_set(EECS_PIN, 1);
450 +static void SetCSToHighForEEprom(void)
452 + gpio_line_set(EECS_PIN, 1);
454 + /* min tskh and tskl is 1us */
455 + gpio_line_set(EECK_PIN, 1);
457 + gpio_line_set(EECK_PIN, 0);
466 +static void send1ToEEprom(void)
468 +//printf("send1ToEEprom(1)...");
469 + gpio_line_set(EEDI_PIN, 1);
471 + gpio_line_set(EECK_PIN, 0);
473 + gpio_line_set(EECK_PIN, 1);
474 + gpio_line_set(EECK_PIN, 1);
475 + gpio_line_set(EECK_PIN, 1);
477 + gpio_line_set(EECK_PIN, 0);
485 +static void send0ToEEprom(void)
487 +//printf("send0ToEEprom(0)...");
488 + gpio_line_set(EEDI_PIN, 0);
490 + gpio_line_set(EECK_PIN, 0);
492 + gpio_line_set(EECK_PIN, 1);
493 + gpio_line_set(EECK_PIN, 1);
494 + gpio_line_set(EECK_PIN, 1);
496 + gpio_line_set(EECK_PIN, 0);
499 +static void WriteDataToEEprom(unsigned short addr, unsigned short data)
501 + unsigned short addr_mask, data_mask;
503 + SetEEpromToSendState();
504 + for (addr_mask = 0x400; addr_mask != 0; )
506 + if (addr & addr_mask)
510 + addr_mask = addr_mask >> 1;
512 + for (data_mask = 0x8000; data_mask != 0; )
514 + if (data & data_mask)
518 + data_mask = data_mask >> 1;
520 + SetCSToLowForEEprom();
523 +static void WriteCmdToEEprom(unsigned short cmd)
525 + unsigned short cmd_mask;
527 + SetEEpromToSendState();
528 + for (cmd_mask = 0x0400 ;cmd_mask != 0; )
530 + if (cmd & cmd_mask)
534 + cmd_mask = cmd_mask >> 1;
536 + SetCSToLowForEEprom();
540 + * Write data to configure registers through EEPROM interface, even we do not have
541 + * an external EEPROM connectted, ADM6996 got a virtual AT39C66 inside
543 +static void WriteDataToRegister(unsigned short RegNumber, unsigned short data)
545 + unsigned short cmd, addr;
547 + printk("WriteDataToRegister(RegNumber=0x%x, data=0x%x)\n", RegNumber, data);
549 +// the write enable(WEN) instruction must be executed before any device
550 +// programming can be done
552 + WriteCmdToEEprom(cmd); //00000001 0011000000B
554 + addr = 0x0500 | (RegNumber & 0x0ff); //00000001 01dddddddd
555 + WriteDataToEEprom(addr, data); //00000001 01dddddd
558 +// after all data has been written to EEprom , the write disable(WDS)
559 +// instruction must be executed
561 + WriteCmdToEEprom(cmd); //00000001 00000000B
564 +static void SerialDelay(int count)
569 +static void InitSerialInterface(void)
571 + gpio_line_set(EECK_PIN, 0);
572 + gpio_line_set(EEDI_PIN, 0);
575 +static void SerialPulse(void)
577 + gpio_line_set(EECK_PIN, 0);
578 + gpio_line_set(EECK_PIN, 1);
580 + gpio_line_set(EECK_PIN, 1);
581 + gpio_line_set(EECK_PIN, 0);
584 + * Since there is no EEPROM is our board, read from EEPROM need to obey the timing alike
585 + * MII interface, EECK = MDC, EEDI = MDIO, please refer to section 4.3 of ADM6996 datasheet
587 +void ReadDataFromRegister(unsigned short addr, unsigned short *hidata, unsigned short *lodata, int select_count)
589 + unsigned short addr_mask, data_mask;
591 + unsigned char StartBits, Opcode, TAbits;
593 + gpio_line_config_out_all();
595 + /* initialize serial interface */
596 + gpio_line_set(EECS_PIN, 0);
597 + InitSerialInterface();
599 + /* Preamble, 35 bits */
600 + gpio_line_set(EECK_PIN, 0);
601 + gpio_line_set(EEDI_PIN, 1);
602 + for (i = 0; i < 35; i++)
604 + gpio_line_set(EECK_PIN, 1);
606 + gpio_line_set(EECK_PIN, 0);
610 + /* Start bits, 2-bit(01b) */
611 + InitSerialInterface();
613 + for (i = 0; i < 2; i++)
615 + value = (StartBits & 2) ? 1 : 0;
616 + gpio_line_set(EEDI_PIN, value);
622 + /* Opcode, read = 10b */
623 + InitSerialInterface();
625 + for (i = 0; i < 2; i++)
627 + value = (Opcode & 0x02) ? 1 : 0;
628 + gpio_line_set(EEDI_PIN, value);
634 + /* 10 bits register address */
635 + /* 1-bit Table Select, 2-bit Device Address, 7-bit Register Address */
636 + InitSerialInterface();
638 + addr = (addr & 0x7f) | 0x200;
640 + addr = addr & 0x7f ;
641 + for (addr_mask = 0x200; addr_mask != 0; addr_mask >>= 1)
643 + value = (addr & addr_mask) ? 1 : 0;
644 + gpio_line_set(EEDI_PIN, value);
649 + /* TA, turnaround 2-bit */
650 + InitSerialInterface();
652 + gpio_line_config_in(EEDI_PIN);
653 + for (i = 0; i < 2; i++)
655 + gpio_line_set(EECK_PIN, 1);
657 + gpio_line_get(EEDI_PIN, &value);
660 + gpio_line_set(EECK_PIN, 1);
664 + /* Latch data from serial management EEDI pin */
666 + gpio_line_set(EECK_PIN, 0);
667 + for (data_mask = 0x8000; data_mask != 0; data_mask >>= 1)
670 + gpio_line_set(EECK_PIN, 1);
671 + gpio_line_get(EEDI_PIN, &value);
674 + *hidata |= data_mask;
676 + gpio_line_set(EECK_PIN, 0);
680 + gpio_line_set(EECK_PIN, 0);
681 + for (data_mask = 0x8000; data_mask != 0; data_mask >>= 1)
684 + gpio_line_set(EECK_PIN, 1);
685 + gpio_line_get(EEDI_PIN, &value);
688 + *lodata |= data_mask;
690 + gpio_line_set(EECK_PIN, 0);
696 + /* Idle, EECK must send at least one clock at idle time */
698 + gpio_line_set(EECK_PIN, 0);
700 + gpio_line_set(EECK_PIN, 1);
702 + gpio_line_set(EECK_PIN, 0);
705 + gpio_line_config_out(EEDI_PIN);
706 + gpio_line_set(EECS_PIN, 1);
708 + printk("ReadDataFromRegister(addr=0x%x, hidata=0x%x, lodata=0x%x)\n", addr, *hidata, *lodata);
710 diff -Nur linux-mips-cvs/drivers/net/port_based_qos/port_based_qos.c linux-broadcom/drivers/net/port_based_qos/port_based_qos.c
711 --- linux-mips-cvs/drivers/net/port_based_qos/port_based_qos.c 1970-01-01 01:00:00.000000000 +0100
712 +++ linux-broadcom/drivers/net/port_based_qos/port_based_qos.c 2005-01-31 13:13:14.000000000 +0100
715 + * Remaining issues:
717 + * + multicast support
719 + * + half/full duplex
720 + * - random MAC addr.
723 +#include <linux/config.h>
724 +#include <linux/module.h>
725 +#include <linux/kernel.h>
726 +#include <linux/pci.h>
727 +#include <linux/init.h>
728 +#include <linux/ioport.h>
729 +#include <linux/netdevice.h>
730 +#include <linux/etherdevice.h>
731 +#include <linux/ethtool.h>
732 +#include <linux/mii.h>
735 +#include <linux/sysctl.h>
736 +#include <cy_conf.h>
738 +#define MODULE_NAME "port_based_qos_mod"
739 +#define DEVICE_NAME "qos"
740 +#define MODULE_VERSION "0.0.1"
742 +extern void ReadDataFromRegister(unsigned short addr, unsigned short *hidata, unsigned short *lodata,int select_count);
744 +#ifdef PERFORMANCE_SUPPORT
745 +static struct ctl_table_header *qos_sysctl_header;
746 +static unsigned long qos[28];
748 +static ctl_table mytable[] = {
756 +static unsigned short statis_addr_map[7][6] ={
757 + {0x04, 0x06, 0x08, 0x0a, 0x0b, 0x0c},
758 + {0x16, 0x18, 0x1a, 0x1c, 0x1d, 0x1e},
759 + {0x0d, 0x0f, 0x11, 0x13, 0x14, 0x15},
760 + {0x1f, 0x21, 0x23, 0x25, 0x26, 0x27},
761 + {0x31, 0x33, 0x35, 0x37, 0x38, 0x39},
762 + {0x28, 0x2a, 0x2c, 0x2e, 0x2f, 0x30},
763 + {0x01, 0x01, 0x01, 0x01, 0x01, 0x01}
766 +unsigned long get_statistic_from_serial(unsigned short port, unsigned short item)
768 + unsigned short hidata, lodata;
770 + ReadDataFromRegister(statis_addr_map[item][port], &hidata, &lodata, 1);
771 + return ((hidata << 16) | lodata);
775 +#ifdef HW_QOS_SUPPORT
782 +void WriteDataToRegister_(unsigned short reg_idx, unsigned short content_idx);
783 +extern void write_eeprom(short,short *,int);
785 +#define BANDWIDTH_1_BIT 2
786 +#define BANDWIDTH_2_BIT 4
787 +#define BANDWIDTH_3_BIT 6
788 +#define BANDWIDTH_4_BIT 7
790 +#define PORT_CONFIG_1 0x3
791 +#define PORT_CONFIG_2 0x5
792 +#define PORT_CONFIG_3 0x7
793 +#define PORT_CONFIG_4 0x8
794 +#define BANDWIDTH_CTL_123 0x31
795 +#define BANDWIDTH_CTL_4 0x32
796 +#define BANDWIDTH_CTL_ENABLE 0x33
797 +#define DISCARD_MODE 0x10
798 +#define TOS_PRIO_MAP 0xf
800 +#define PRIORITY_MASK 0xfc7f
801 +#define PRIORITY_DISABLE_MASK 0xfc7e
802 +#define FLOW_CTL_MASK 0xfffe
803 +#define RATE_LIMIT_MASK_1 0xff8f
804 +#define RATE_LIMIT_MASK_2 0xf8ff
805 +#define RATE_LIMIT_MASK_3 0x8fff
806 +#define RATE_LIMIT_MASK_4 0xfff8
807 +#define BANDWIDTH_CTL_MASK 0xff2b
808 +#define DISCARD_MASK 0x0fff
810 +#define BANDWIDTH_ENABLE_1 1 << BANDWIDTH_1_BIT//04
811 +#define BANDWIDTH_ENABLE_2 1 << BANDWIDTH_2_BIT//10
812 +#define BANDWIDTH_ENABLE_3 1 << BANDWIDTH_3_BIT//40
813 +#define BANDWIDTH_ENABLE_4 1 << BANDWIDTH_4_BIT//80
814 +#define BANDWIDTH_CTL_MASK_1 0xffff^BANDWIDTH_ENABLE_1//0xfffb
815 +#define BANDWIDTH_CTL_MASK_2 0xffff^BANDWIDTH_ENABLE_2//0xffef
816 +#define BANDWIDTH_CTL_MASK_3 0xffff^BANDWIDTH_ENABLE_3//0xffbf
817 +#define BANDWIDTH_CTL_MASK_4 0xffff^BANDWIDTH_ENABLE_4//0xff7f
819 +/*static int disable_content[] = {0x0};
820 +//static int enable_content[] = {0xd4, 0x0cff};//bit 7,6,4,2; Q1=11(50%),Q0=00(0%)*/
821 +//static int sw_content[] = {0x0,0x0c00};//bit 7,6,4,2; Q1=11(50%),Q0=00(0%)
822 +static int sw_content[] = {0x0,0xc000};//bit 7,6,4,2; Q1=11(50%),Q0=00(0%)
823 +static int port_priority_content[] = {0x080,0x380};//Q0,Q3
824 +//static int port_priority_content[] = {0x300,0x0};//Q1,Q0
825 +static int port_flow_ctl_content[] = {0x0,0x1};
826 +static int port_rate_limit_content_1[] = {0x0,0x00,0x10,0x20,0x30,0x40,0x50,0x60,0x70};
827 +static int port_rate_limit_content_2[] = {0x0,0x000,0x100,0x200,0x300,0x400,0x500,0x600,0x700};
828 +static int port_rate_limit_content_3[] = {0x0,0x0000,0x1000,0x2000,0x3000,0x4000,0x5000,0x6000,0x7000};
829 +static int port_rate_limit_content_4[] = {0x0,0x0,0x1,0x2,0x3,0x4,0x5,0x6,0x7};
830 +static int port_rate_limit_enable_1[] = {0x0, BANDWIDTH_ENABLE_1};
831 +static int port_rate_limit_enable_2[] = {0x0, BANDWIDTH_ENABLE_2};
832 +static int port_rate_limit_enable_3[] = {0x0, BANDWIDTH_ENABLE_3};
833 +static int port_rate_limit_enable_4[] = {0x0, BANDWIDTH_ENABLE_4};
835 +static struct port_qos_t port_mii_disable[] = {
836 + { BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK, sw_content},
837 + //{ DISCARD_MODE, DISCARD_MASK, sw_content},
838 + { PORT_CONFIG_1, PRIORITY_MASK, sw_content},//port_priority_1
839 + { PORT_CONFIG_2, PRIORITY_MASK, sw_content},//port_priority_2
840 + { PORT_CONFIG_3, PRIORITY_MASK, sw_content},//port_priority_3
841 + { PORT_CONFIG_4, PRIORITY_MASK, sw_content},//port_priority_4
842 + { PORT_CONFIG_1, FLOW_CTL_MASK, &port_flow_ctl_content[1]},//port_flow_control_1
843 + { PORT_CONFIG_2, FLOW_CTL_MASK, &port_flow_ctl_content[1]},//port_flow_control_2
844 + { PORT_CONFIG_3, FLOW_CTL_MASK, &port_flow_ctl_content[1]},//port_flow_control_3
845 + { PORT_CONFIG_4, FLOW_CTL_MASK, &port_flow_ctl_content[1]},//port_flow_control_4
849 +static struct port_qos_t port_mii_enable[] = {
850 + //{ BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK, enable_content},
851 + //{ DISCARD_MODE, DISCARD_MASK, sw_content},
855 +struct port_qos_t *port_mii_sw_array[] = {port_mii_disable, port_mii_enable};
857 +/*static struct port_qos_t port_mii_addr[] = {
858 + { PORT_CONFIG_1, PRIORITY_MASK, port_priority_content},//port_priority_1
859 + { PORT_CONFIG_1, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_1
860 + //{ "port_frame_type_1", 0x3},
861 + { BANDWIDTH_CTL_123, RATE_LIMIT_MASK_14, port_rate_limit_content_14},//port_rate_limit_1
862 + { PORT_CONFIG_2, PRIORITY_MASK, port_priority_content},//port_priority_2
863 + { PORT_CONFIG_2, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_2
864 + //{ "port_frame_type_2", 0x5},
865 + { BANDWIDTH_CTL_123, RATE_LIMIT_MASK_2, port_rate_limit_content_2},//port_rate_limit_2
866 + { PORT_CONFIG_3, PRIORITY_MASK, port_priority_content},//port_priority_3
867 + { PORT_CONFIG_3, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_3
868 + //{ "port_frame_type_3", 0x7},
869 + { BANDWIDTH_CTL_123, RATE_LIMIT_MASK_3, port_rate_limit_content_3},//port_rate_limit_3
870 + //{ "port_priority_4", 0x8, 0x380},
871 + { PORT_CONFIG_4, PRIORITY_MASK, port_priority_content},//port_priority_4
872 + { PORT_CONFIG_4, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_4
873 + //{ "port_frame_type_4", 0x8},
874 + { BANDWIDTH_CTL_4, RATE_LIMIT_MASK_14, port_rate_limit_content_14},//port_rate_limit_4
878 +static struct port_qos_t priority_1[] = {
879 + { PORT_CONFIG_1, PRIORITY_MASK, port_priority_content},//port_priority_1
882 +static struct port_qos_t flow_control_1[] = {
883 + { PORT_CONFIG_1, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_1
886 +static struct port_qos_t rate_limit_1[] = {
887 + { BANDWIDTH_CTL_123, RATE_LIMIT_MASK_1, port_rate_limit_content_1},//port_rate_limit_1
888 + { BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK_1, port_rate_limit_enable_1},//port_rate_limit_4
891 +static struct port_qos_t priority_2[] = {
892 + { PORT_CONFIG_2, PRIORITY_MASK, port_priority_content},//port_priority_2
895 +static struct port_qos_t flow_control_2[] = {
896 + { PORT_CONFIG_2, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_2
899 +static struct port_qos_t rate_limit_2[] = {
900 + { BANDWIDTH_CTL_123, RATE_LIMIT_MASK_2, port_rate_limit_content_2},//port_rate_limit_2
901 + { BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK_2, port_rate_limit_enable_2},//port_rate_limit_4
904 +static struct port_qos_t priority_3[] = {
905 + { PORT_CONFIG_3, PRIORITY_MASK, port_priority_content},//port_priority_3
908 +static struct port_qos_t flow_control_3[] = {
909 + { PORT_CONFIG_3, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_3
912 +static struct port_qos_t rate_limit_3[] = {
913 + { BANDWIDTH_CTL_123, RATE_LIMIT_MASK_3, port_rate_limit_content_3},//port_rate_limit_3
914 + { BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK_3, port_rate_limit_enable_3},//port_rate_limit_4
917 +static struct port_qos_t priority_4[] = {
918 + { PORT_CONFIG_4, PRIORITY_MASK, port_priority_content},//port_priority_4
921 +static struct port_qos_t flow_control_4[] = {
922 + { PORT_CONFIG_4, FLOW_CTL_MASK, port_flow_ctl_content},//port_flow_control_4
925 +static struct port_qos_t rate_limit_4[] = {
926 + { BANDWIDTH_CTL_4, RATE_LIMIT_MASK_4, port_rate_limit_content_4},//port_rate_limit_4
927 + { BANDWIDTH_CTL_ENABLE, BANDWIDTH_CTL_MASK_4, port_rate_limit_enable_4},//port_rate_limit_4
931 +static struct port_qos_t *port_mii_addr[] = {
947 +void WriteDataToRegister_(unsigned short reg_idx, unsigned short content_idx)
950 + unsigned short data, hidata=0x0, lodata=0x0;
952 + struct port_qos_t *port_qos = port_mii_addr[reg_idx];
954 + //printk("\nWriteDataToRegister_:reg_idx=%d content_idx=%d\n", reg_idx, content_idx);
956 + port_qos = port_mii_sw_array[content_idx];
958 + for (i=0; port_qos[i].addr != -1; i++)
960 + RegNumber = port_qos[i].addr;
961 + ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
963 + if (!(RegNumber % 2)) /* even port number use lower word */
966 + data = (hidata & port_qos[i].content_mask) | (((i > 0) && (content_idx > 1))? port_qos[i].content_set[1] : port_qos[i].content_set[content_idx]);
968 + write_eeprom(RegNumber, &data, 1);
969 + ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
971 + ReadDataFromRegister(0xf, &hidata, &lodata, 0);
973 + /*RegNumber = port_mii_addr[reg_idx].addr;
974 + if (RegNumber == -1)//Disable or Enable
976 + struct port_qos_t *port_mii_sw = port_mii_sw_array[content_idx];
978 + printk("\nWriteDataToRegister_:reg_idx=%d content_idx=%d\n", reg_idx, content_idx);
979 + for (i=0; port_mii_sw[i].addr != -1; i++)
981 + RegNumber = port_mii_sw[i].addr;
983 + ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
985 + if (!(RegNumber % 2))
988 + data = (hidata & port_mii_sw[i].content_mask) | port_mii_sw[i].content_set[i];
990 + write_eeprom(RegNumber, &data, 1);
992 + ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
993 + printk("\n============== %s===============\n", (content_idx==0)?"disable":"enable");
998 + ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
1000 + if (!(RegNumber % 2))
1003 + data = (hidata & port_mii_addr[reg_idx].content_mask) | port_mii_addr[reg_idx].content_set[content_idx];
1005 + write_eeprom(RegNumber, &data, 1);
1006 + ReadDataFromRegister(RegNumber, &hidata, &lodata, 0);
1011 +static int dev_do_ioctl(struct net_device *dev, struct ifreq *req, int cmd)
1013 + struct mii_ioctl_data *data = (struct mii_ioctl_data *)req->ifr_data;
1014 +#ifdef PERFORMANCE_SUPPORT
1017 + unsigned long status_item;
1022 + case SIOCGMIIPHY: /* Get address of MII PHY in use. */
1023 + case SIOCDEVPRIVATE: /* for binary compat, remove in 2.5 */
1025 + /* Fall through to the SIOCGMIIREG, taken from eepro100 and rtl
1027 +#ifdef PERFORMANCE_SUPPORT
1028 + case SIOCGMIIREG: /* Read MII PHY register. */
1029 + for (item=0; item<6; item++)
1030 + for (port=1; port<5; port++){
1031 + qos[(item * 4) + (port-1)] = get_statistic_from_serial(port, item);
1034 + status_item = get_statistic_from_serial(0, 6);
1036 + qos[24] = (0x1 & (status_item >> 8));
1037 + qos[25] = (0x1 & (status_item >> 16));
1038 + qos[26] = (0x1 & (status_item >> 24));
1039 + qos[27] = (0x1 & (status_item >> 28));
1044 + case SIOCDEVPRIVATE+1: /* for binary compat, remove in 2.5 */
1045 +#ifdef HW_QOS_SUPPORT
1046 + case SIOCSMIIREG: /* Write MII PHY register. */
1048 + printk("\n x phy_id=%x\n", data->phy_id);
1049 + printk("\n x reg_num=%x\n", data->reg_num);
1050 + printk("\n x val_in=%x\n", data->val_in);
1051 + printk("\n x val_out=%x\n", data->val_out);
1053 + WriteDataToRegister_(data->phy_id, data->val_in);
1057 + case SIOCDEVPRIVATE+2: /* for binary compat, remove in 2.5 */
1059 + return -EOPNOTSUPP;
1063 +static int __devinit qos_eth_probe(struct net_device *dev)
1066 + SET_MODULE_OWNER(dev);
1070 + strcpy(dev->name, DEVICE_NAME "0");
1072 + dev->do_ioctl = dev_do_ioctl;
1077 +#ifdef HW_QOS_SUPPORT
1078 +static char *port_option_name[] = {
1079 + "port_priority_1",
1080 + "port_flow_control_1",
1081 + //{ "port_frame_type_1",
1082 + "port_rate_limit_1",
1083 + "port_priority_2",
1084 + "port_flow_control_2",
1085 + //{ "port_frame_type_2",
1086 + "port_rate_limit_2",
1087 + "port_priority_3",
1088 + "port_flow_control_3",
1089 + //{ "port_frame_type_3",
1090 + "port_rate_limit_3",
1091 + "port_priority_4",
1092 + //{ "port_priority_4", PORT_CONFIG_4, PRIORITY_MASK, port_priority_content},
1093 + "port_flow_control_4",
1094 + //{ "port_frame_type_4",
1095 + "port_rate_limit_4",
1100 +extern char *nvram_get(const char *name);
1101 +extern uint bcm_atoi(char *s);
1103 +static int set_port_option(struct net_device *dev, unsigned short port_addr, char *option_content)
1106 + struct mii_ioctl_data stats;
1108 + stats.phy_id=port_addr;
1109 + stats.val_in=bcm_atoi(option_content);
1111 + ifr.ifr_data = (void *)&stats;
1113 + return dev_do_ioctl(dev, &ifr, SIOCSMIIREG);
1118 +restore_default_from_NV(struct net_device *dev)
1121 + char *value = NULL;
1123 + for (i = 0; port_option_name[i]; i++)
1125 + if((value = nvram_get(port_option_name[i])))
1126 + set_port_option(dev, i, value);
1132 +static struct net_device qos_devices;
1134 +/* Module initialization and cleanup */
1135 +int init_module(void)
1138 + struct net_device *dev;
1140 + printk("Initializing " MODULE_NAME " driver " MODULE_VERSION "\n");
1142 + dev = &qos_devices;
1144 + dev->init = qos_eth_probe;
1146 + if ((res = register_netdev(dev)))
1147 + printk("Failed to register netdev. res = %d\n", res);
1149 +#ifdef PERFORMANCE_SUPPORT
1150 + qos_sysctl_header = register_sysctl_table(mytable, 0);
1152 +#ifdef HW_QOS_SUPPORT
1153 + restore_default_from_NV(dev);
1154 + write_eeprom(TOS_PRIO_MAP, &sw_content[0], 1);/* disable TOS priority map*/
1159 +void cleanup_module(void)
1161 + struct net_device *dev = &qos_devices;
1162 + if (dev->priv != NULL)
1164 + unregister_netdev(dev);
1169 +#ifdef PERFORMANCE_SUPPORT
1170 + unregister_sysctl_table(qos_sysctl_header);