diff --git a/[refs] b/[refs] index a7419f0d62fd..b509d11914a0 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 5d46f3266728913d05106ee82fb5f043be06eb21 +refs/heads/master: fefecc6989b4b24276797270c0e229c07be02ad3 diff --git a/trunk/Documentation/feature-removal-schedule.txt b/trunk/Documentation/feature-removal-schedule.txt index 492e81df2968..274b32d12532 100644 --- a/trunk/Documentation/feature-removal-schedule.txt +++ b/trunk/Documentation/feature-removal-schedule.txt @@ -387,6 +387,26 @@ Who: Tejun Heo ---------------------------- +What: Support for lcd_switch and display_get in asus-laptop driver +When: March 2010 +Why: These two features use non-standard interfaces. There are the + only features that really need multiple path to guess what's + the right method name on a specific laptop. + + Removing them will allow to remove a lot of code an significantly + clean the drivers. + + This will affect the backlight code which won't be able to know + if the backlight is on or off. The platform display file will also be + write only (like the one in eeepc-laptop). + + This should'nt affect a lot of user because they usually know + when their display is on or off. + +Who: Corentin Chary + +---------------------------- + What: sysfs-class-rfkill state file When: Feb 2014 Files: net/rfkill/core.c diff --git a/trunk/Documentation/input/event-codes.txt b/trunk/Documentation/input/event-codes.txt deleted file mode 100644 index 23fcb05175be..000000000000 --- a/trunk/Documentation/input/event-codes.txt +++ /dev/null @@ -1,262 +0,0 @@ -The input protocol uses a map of types and codes to express input device values -to userspace. This document describes the types and codes and how and when they -may be used. - -A single hardware event generates multiple input events. Each input event -contains the new value of a single data item. A special event type, EV_SYN, is -used to separate input events into packets of input data changes occurring at -the same moment in time. In the following, the term "event" refers to a single -input event encompassing a type, code, and value. - -The input protocol is a stateful protocol. Events are emitted only when values -of event codes have changed. However, the state is maintained within the Linux -input subsystem; drivers do not need to maintain the state and may attempt to -emit unchanged values without harm. Userspace may obtain the current state of -event code values using the EVIOCG* ioctls defined in linux/input.h. The event -reports supported by a device are also provided by sysfs in -class/input/event*/device/capabilities/, and the properties of a device are -provided in class/input/event*/device/properties. - -Types: -========== -Types are groupings of codes under a logical input construct. Each type has a -set of applicable codes to be used in generating events. See the Codes section -for details on valid codes for each type. - -* EV_SYN: - - Used as markers to separate events. Events may be separated in time or in - space, such as with the multitouch protocol. - -* EV_KEY: - - Used to describe state changes of keyboards, buttons, or other key-like - devices. - -* EV_REL: - - Used to describe relative axis value changes, e.g. moving the mouse 5 units - to the left. - -* EV_ABS: - - Used to describe absolute axis value changes, e.g. describing the - coordinates of a touch on a touchscreen. - -* EV_MSC: - - Used to describe miscellaneous input data that do not fit into other types. - -* EV_SW: - - Used to describe binary state input switches. - -* EV_LED: - - Used to turn LEDs on devices on and off. - -* EV_SND: - - Used to output sound to devices. - -* EV_REP: - - Used for autorepeating devices. - -* EV_FF: - - Used to send force feedback commands to an input device. - -* EV_PWR: - - A special type for power button and switch input. - -* EV_FF_STATUS: - - Used to receive force feedback device status. - -Codes: -========== -Codes define the precise type of event. - -EV_SYN: ----------- -EV_SYN event values are undefined. Their usage is defined only by when they are -sent in the evdev event stream. - -* SYN_REPORT: - - Used to synchronize and separate events into packets of input data changes - occurring at the same moment in time. For example, motion of a mouse may set - the REL_X and REL_Y values for one motion, then emit a SYN_REPORT. The next - motion will emit more REL_X and REL_Y values and send another SYN_REPORT. - -* SYN_CONFIG: - - TBD - -* SYN_MT_REPORT: - - Used to synchronize and separate touch events. See the - multi-touch-protocol.txt document for more information. - -* SYN_DROPPED: - - Used to indicate buffer overrun in the evdev client's event queue. - Client should ignore all events up to and including next SYN_REPORT - event and query the device (using EVIOCG* ioctls) to obtain its - current state. - -EV_KEY: ----------- -EV_KEY events take the form KEY_ or BTN_. For example, KEY_A is used -to represent the 'A' key on a keyboard. When a key is depressed, an event with -the key's code is emitted with value 1. When the key is released, an event is -emitted with value 0. Some hardware send events when a key is repeated. These -events have a value of 2. In general, KEY_ is used for keyboard keys, and -BTN_ is used for other types of momentary switch events. - -A few EV_KEY codes have special meanings: - -* BTN_TOOL_: - - These codes are used in conjunction with input trackpads, tablets, and - touchscreens. These devices may be used with fingers, pens, or other tools. - When an event occurs and a tool is used, the corresponding BTN_TOOL_ - code should be set to a value of 1. When the tool is no longer interacting - with the input device, the BTN_TOOL_ code should be reset to 0. All - trackpads, tablets, and touchscreens should use at least one BTN_TOOL_ - code when events are generated. - -* BTN_TOUCH: - BTN_TOUCH is used for touch contact. While an input tool is determined to be - within meaningful physical contact, the value of this property must be set - to 1. Meaningful physical contact may mean any contact, or it may mean - contact conditioned by an implementation defined property. For example, a - touchpad may set the value to 1 only when the touch pressure rises above a - certain value. BTN_TOUCH may be combined with BTN_TOOL_ codes. For - example, a pen tablet may set BTN_TOOL_PEN to 1 and BTN_TOUCH to 0 while the - pen is hovering over but not touching the tablet surface. - -Note: For appropriate function of the legacy mousedev emulation driver, -BTN_TOUCH must be the first evdev code emitted in a synchronization frame. - -Note: Historically a touch device with BTN_TOOL_FINGER and BTN_TOUCH was -interpreted as a touchpad by userspace, while a similar device without -BTN_TOOL_FINGER was interpreted as a touchscreen. For backwards compatibility -with current userspace it is recommended to follow this distinction. In the -future, this distinction will be deprecated and the device properties ioctl -EVIOCGPROP, defined in linux/input.h, will be used to convey the device type. - -* BTN_TOOL_FINGER, BTN_TOOL_DOUBLETAP, BTN_TOOL_TRIPLETAP, BTN_TOOL_QUADTAP: - - These codes denote one, two, three, and four finger interaction on a - trackpad or touchscreen. For example, if the user uses two fingers and moves - them on the touchpad in an effort to scroll content on screen, - BTN_TOOL_DOUBLETAP should be set to value 1 for the duration of the motion. - Note that all BTN_TOOL_ codes and the BTN_TOUCH code are orthogonal in - purpose. A trackpad event generated by finger touches should generate events - for one code from each group. At most only one of these BTN_TOOL_ - codes should have a value of 1 during any synchronization frame. - -Note: Historically some drivers emitted multiple of the finger count codes with -a value of 1 in the same synchronization frame. This usage is deprecated. - -Note: In multitouch drivers, the input_mt_report_finger_count() function should -be used to emit these codes. Please see multi-touch-protocol.txt for details. - -EV_REL: ----------- -EV_REL events describe relative changes in a property. For example, a mouse may -move to the left by a certain number of units, but its absolute position in -space is unknown. If the absolute position is known, EV_ABS codes should be used -instead of EV_REL codes. - -A few EV_REL codes have special meanings: - -* REL_WHEEL, REL_HWHEEL: - - These codes are used for vertical and horizontal scroll wheels, - respectively. - -EV_ABS: ----------- -EV_ABS events describe absolute changes in a property. For example, a touchpad -may emit coordinates for a touch location. - -A few EV_ABS codes have special meanings: - -* ABS_DISTANCE: - - Used to describe the distance of a tool from an interaction surface. This - event should only be emitted while the tool is hovering, meaning in close - proximity of the device and while the value of the BTN_TOUCH code is 0. If - the input device may be used freely in three dimensions, consider ABS_Z - instead. - -* ABS_MT_: - - Used to describe multitouch input events. Please see - multi-touch-protocol.txt for details. - -EV_SW: ----------- -EV_SW events describe stateful binary switches. For example, the SW_LID code is -used to denote when a laptop lid is closed. - -Upon binding to a device or resuming from suspend, a driver must report -the current switch state. This ensures that the device, kernel, and userspace -state is in sync. - -Upon resume, if the switch state is the same as before suspend, then the input -subsystem will filter out the duplicate switch state reports. The driver does -not need to keep the state of the switch at any time. - -EV_MSC: ----------- -EV_MSC events are used for input and output events that do not fall under other -categories. - -EV_LED: ----------- -EV_LED events are used for input and output to set and query the state of -various LEDs on devices. - -EV_REP: ----------- -EV_REP events are used for specifying autorepeating events. - -EV_SND: ----------- -EV_SND events are used for sending sound commands to simple sound output -devices. - -EV_FF: ----------- -EV_FF events are used to initialize a force feedback capable device and to cause -such device to feedback. - -EV_PWR: ----------- -EV_PWR events are a special type of event used specifically for power -mangement. Its usage is not well defined. To be addressed later. - -Guidelines: -========== -The guidelines below ensure proper single-touch and multi-finger functionality. -For multi-touch functionality, see the multi-touch-protocol.txt document for -more information. - -Mice: ----------- -REL_{X,Y} must be reported when the mouse moves. BTN_LEFT must be used to report -the primary button press. BTN_{MIDDLE,RIGHT,4,5,etc.} should be used to report -further buttons of the device. REL_WHEEL and REL_HWHEEL should be used to report -scroll wheel events where available. - -Touchscreens: ----------- -ABS_{X,Y} must be reported with the location of the touch. BTN_TOUCH must be -used to report when a touch is active on the screen. -BTN_{MOUSE,LEFT,MIDDLE,RIGHT} must not be reported as the result of touch -contact. BTN_TOOL_ events should be reported where possible. - -Trackpads: ----------- -Legacy trackpads that only provide relative position information must report -events like mice described above. - -Trackpads that provide absolute touch position must report ABS_{X,Y} for the -location of the touch. BTN_TOUCH should be used to report when a touch is active -on the trackpad. Where multi-finger support is available, BTN_TOOL_ should -be used to report the number of touches active on the trackpad. - -Tablets: ----------- -BTN_TOOL_ events must be reported when a stylus or other tool is active on -the tablet. ABS_{X,Y} must be reported with the location of the tool. BTN_TOUCH -should be used to report when the tool is in contact with the tablet. -BTN_{STYLUS,STYLUS2} should be used to report buttons on the tool itself. Any -button may be used for buttons on the tablet except BTN_{MOUSE,LEFT}. -BTN_{0,1,2,etc} are good generic codes for unlabeled buttons. Do not use -meaningful buttons, like BTN_FORWARD, unless the button is labeled for that -purpose on the device. diff --git a/trunk/MAINTAINERS b/trunk/MAINTAINERS index ec3600306289..6b4b9cdec370 100644 --- a/trunk/MAINTAINERS +++ b/trunk/MAINTAINERS @@ -184,9 +184,10 @@ F: Documentation/filesystems/9p.txt F: fs/9p/ A2232 SERIAL BOARD DRIVER +M: Enver Haase L: linux-m68k@lists.linux-m68k.org -S: Orphan -F: drivers/staging/generic_serial/ser_a2232* +S: Maintained +F: drivers/char/ser_a2232* AACRAID SCSI RAID DRIVER M: Adaptec OEM Raid Solutions @@ -876,13 +877,6 @@ F: arch/arm/mach-mv78xx0/ F: arch/arm/mach-orion5x/ F: arch/arm/plat-orion/ -ARM/Orion SoC/Technologic Systems TS-78xx platform support -M: Alexander Clouter -L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) -W: http://www.digriz.org.uk/ts78xx/kernel -S: Maintained -F: arch/arm/mach-orion5x/ts78xx-* - ARM/MIOA701 MACHINE SUPPORT M: Robert Jarzmik L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) @@ -1069,7 +1063,7 @@ F: arch/arm/mach-shmobile/ F: drivers/sh/ ARM/TELECHIPS ARM ARCHITECTURE -M: "Hans J. Koch" +M: "Hans J. Koch" L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) S: Maintained F: arch/arm/plat-tcc/ @@ -1829,10 +1823,11 @@ S: Maintained F: drivers/platform/x86/compal-laptop.c COMPUTONE INTELLIPORT MULTIPORT CARD +M: "Michael H. Warfield" W: http://www.wittsend.com/computone.html -S: Orphan +S: Maintained F: Documentation/serial/computone.txt -F: drivers/staging/tty/ip2/ +F: drivers/char/ip2/ CONEXANT ACCESSRUNNER USB DRIVER M: Simon Arlott @@ -2015,7 +2010,7 @@ F: drivers/net/wan/cycx* CYCLADES ASYNC MUX DRIVER W: http://www.cyclades.com/ S: Orphan -F: drivers/tty/cyclades.c +F: drivers/char/cyclades.c F: include/linux/cyclades.h CYCLADES PC300 DRIVER @@ -2129,8 +2124,8 @@ L: Eng.Linux@digi.com W: http://www.digi.com S: Orphan F: Documentation/serial/digiepca.txt -F: drivers/staging/tty/epca* -F: drivers/staging/tty/digi* +F: drivers/char/epca* +F: drivers/char/digi* DIOLAN U2C-12 I2C DRIVER M: Guenter Roeck @@ -4082,7 +4077,7 @@ F: drivers/video/matrox/matroxfb_* F: include/linux/matroxfb.h MAX6650 HARDWARE MONITOR AND FAN CONTROLLER DRIVER -M: "Hans J. Koch" +M: "Hans J. Koch" L: lm-sensors@lm-sensors.org S: Maintained F: Documentation/hwmon/max6650 @@ -4197,7 +4192,7 @@ MOXA SMARTIO/INDUSTIO/INTELLIO SERIAL CARD M: Jiri Slaby S: Maintained F: Documentation/serial/moxa-smartio -F: drivers/tty/mxser.* +F: drivers/char/mxser.* MSI LAPTOP SUPPORT M: "Lee, Chun-Yi" @@ -4239,7 +4234,7 @@ F: sound/oss/msnd* MULTITECH MULTIPORT CARD (ISICOM) S: Orphan -F: drivers/tty/isicom.c +F: drivers/char/isicom.c F: include/linux/isicom.h MUSB MULTIPOINT HIGH SPEED DUAL-ROLE CONTROLLER @@ -5278,14 +5273,14 @@ F: drivers/memstick/host/r592.* RISCOM8 DRIVER S: Orphan F: Documentation/serial/riscom8.txt -F: drivers/staging/tty/riscom8* +F: drivers/char/riscom8* ROCKETPORT DRIVER P: Comtrol Corp. W: http://www.comtrol.com S: Maintained F: Documentation/serial/rocket.txt -F: drivers/tty/rocket* +F: drivers/char/rocket* ROSE NETWORK LAYER M: Ralf Baechle @@ -5921,9 +5916,10 @@ F: arch/arm/mach-spear6xx/spear600.c F: arch/arm/mach-spear6xx/spear600_evb.c SPECIALIX IO8+ MULTIPORT SERIAL CARD DRIVER -S: Orphan +M: Roger Wolff +S: Supported F: Documentation/serial/specialix.txt -F: drivers/staging/tty/specialix* +F: drivers/char/specialix* SPI SUBSYSTEM M: David Brownell @@ -5968,6 +5964,7 @@ F: arch/alpha/kernel/srm_env.c STABLE BRANCH M: Greg Kroah-Hartman +M: Chris Wright L: stable@kernel.org S: Maintained @@ -6251,8 +6248,7 @@ M: Greg Ungerer W: http://www.uclinux.org/ L: uclinux-dev@uclinux.org (subscribers-only) S: Maintained -F: arch/m68k/*/*_no.* -F: arch/m68k/include/asm/*_no.* +F: arch/m68knommu/ UCLINUX FOR RENESAS H8/300 (H8300) M: Yoshinori Sato @@ -6622,7 +6618,7 @@ F: fs/hostfs/ F: fs/hppfs/ USERSPACE I/O (UIO) -M: "Hans J. Koch" +M: "Hans J. Koch" M: Greg Kroah-Hartman S: Maintained F: Documentation/DocBook/uio-howto.tmpl @@ -6920,13 +6916,6 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/mjg59/platform-drivers-x86. S: Maintained F: drivers/platform/x86 -XEN NETWORK BACKEND DRIVER -M: Ian Campbell -L: xen-devel@lists.xensource.com (moderated for non-subscribers) -L: netdev@vger.kernel.org -S: Supported -F: drivers/net/xen-netback/* - XEN PCI SUBSYSTEM M: Konrad Rzeszutek Wilk L: xen-devel@lists.xensource.com (moderated for non-subscribers) diff --git a/trunk/Makefile b/trunk/Makefile index b967b967572b..8392b64079df 100644 --- a/trunk/Makefile +++ b/trunk/Makefile @@ -1,7 +1,7 @@ VERSION = 2 PATCHLEVEL = 6 SUBLEVEL = 39 -EXTRAVERSION = -rc4 +EXTRAVERSION = -rc2 NAME = Flesh-Eating Bats with Fangs # *DOCUMENTATION* diff --git a/trunk/arch/alpha/kernel/Makefile b/trunk/arch/alpha/kernel/Makefile index 7a6d908bb865..9bb7b858ed23 100644 --- a/trunk/arch/alpha/kernel/Makefile +++ b/trunk/arch/alpha/kernel/Makefile @@ -4,7 +4,7 @@ extra-y := head.o vmlinux.lds asflags-y := $(KBUILD_CFLAGS) -ccflags-y := -Wno-sign-compare +ccflags-y := -Werror -Wno-sign-compare obj-y := entry.o traps.o process.o init_task.o osf_sys.o irq.o \ irq_alpha.o signal.o setup.o ptrace.o time.o \ diff --git a/trunk/arch/alpha/kernel/core_mcpcia.c b/trunk/arch/alpha/kernel/core_mcpcia.c index da7bcc372f16..381fec0af52e 100644 --- a/trunk/arch/alpha/kernel/core_mcpcia.c +++ b/trunk/arch/alpha/kernel/core_mcpcia.c @@ -88,7 +88,7 @@ conf_read(unsigned long addr, unsigned char type1, { unsigned long flags; unsigned long mid = MCPCIA_HOSE2MID(hose->index); - unsigned int stat0, value, cpu; + unsigned int stat0, value, temp, cpu; cpu = smp_processor_id(); @@ -101,7 +101,7 @@ conf_read(unsigned long addr, unsigned char type1, stat0 = *(vuip)MCPCIA_CAP_ERR(mid); *(vuip)MCPCIA_CAP_ERR(mid) = stat0; mb(); - *(vuip)MCPCIA_CAP_ERR(mid); + temp = *(vuip)MCPCIA_CAP_ERR(mid); DBG_CFG(("conf_read: MCPCIA_CAP_ERR(%d) was 0x%x\n", mid, stat0)); mb(); @@ -136,7 +136,7 @@ conf_write(unsigned long addr, unsigned int value, unsigned char type1, { unsigned long flags; unsigned long mid = MCPCIA_HOSE2MID(hose->index); - unsigned int stat0, cpu; + unsigned int stat0, temp, cpu; cpu = smp_processor_id(); @@ -145,7 +145,7 @@ conf_write(unsigned long addr, unsigned int value, unsigned char type1, /* Reset status register to avoid losing errors. */ stat0 = *(vuip)MCPCIA_CAP_ERR(mid); *(vuip)MCPCIA_CAP_ERR(mid) = stat0; mb(); - *(vuip)MCPCIA_CAP_ERR(mid); + temp = *(vuip)MCPCIA_CAP_ERR(mid); DBG_CFG(("conf_write: MCPCIA CAP_ERR(%d) was 0x%x\n", mid, stat0)); draina(); @@ -157,7 +157,7 @@ conf_write(unsigned long addr, unsigned int value, unsigned char type1, *((vuip)addr) = value; mb(); mb(); /* magic */ - *(vuip)MCPCIA_CAP_ERR(mid); /* read to force the write */ + temp = *(vuip)MCPCIA_CAP_ERR(mid); /* read to force the write */ mcheck_expected(cpu) = 0; mb(); @@ -572,10 +572,12 @@ mcpcia_print_system_area(unsigned long la_ptr) void mcpcia_machine_check(unsigned long vector, unsigned long la_ptr) { + struct el_common *mchk_header; struct el_MCPCIA_uncorrected_frame_mcheck *mchk_logout; unsigned int cpu = smp_processor_id(); int expected; + mchk_header = (struct el_common *)la_ptr; mchk_logout = (struct el_MCPCIA_uncorrected_frame_mcheck *)la_ptr; expected = mcheck_expected(cpu); diff --git a/trunk/arch/alpha/kernel/err_titan.c b/trunk/arch/alpha/kernel/err_titan.c index 14b26c466c89..c3b3781a03de 100644 --- a/trunk/arch/alpha/kernel/err_titan.c +++ b/trunk/arch/alpha/kernel/err_titan.c @@ -533,6 +533,8 @@ static struct el_subpacket_annotation el_titan_annotations[] = { static struct el_subpacket * el_process_regatta_subpacket(struct el_subpacket *header) { + int status; + if (header->class != EL_CLASS__REGATTA_FAMILY) { printk("%s ** Unexpected header CLASS %d TYPE %d, aborting\n", err_print_prefix, @@ -549,7 +551,7 @@ el_process_regatta_subpacket(struct el_subpacket *header) printk("%s ** Occurred on CPU %d:\n", err_print_prefix, (int)header->by_type.regatta_frame.cpuid); - privateer_process_logout_frame((struct el_common *) + status = privateer_process_logout_frame((struct el_common *) header->by_type.regatta_frame.data_start, 1); break; default: diff --git a/trunk/arch/alpha/kernel/irq_alpha.c b/trunk/arch/alpha/kernel/irq_alpha.c index 51b7fbd9e4c1..1479dc6ebd97 100644 --- a/trunk/arch/alpha/kernel/irq_alpha.c +++ b/trunk/arch/alpha/kernel/irq_alpha.c @@ -228,7 +228,7 @@ struct irqaction timer_irqaction = { void __init init_rtc_irq(void) { - irq_set_chip_and_handler_name(RTC_IRQ, &dummy_irq_chip, + irq_set_chip_and_handler_name(RTC_IRQ, &no_irq_chip, handle_simple_irq, "RTC"); setup_irq(RTC_IRQ, &timer_irqaction); } diff --git a/trunk/arch/alpha/kernel/setup.c b/trunk/arch/alpha/kernel/setup.c index edbddcbd5bc6..d2634e4476b4 100644 --- a/trunk/arch/alpha/kernel/setup.c +++ b/trunk/arch/alpha/kernel/setup.c @@ -1404,6 +1404,8 @@ determine_cpu_caches (unsigned int cpu_type) case PCA56_CPU: case PCA57_CPU: { + unsigned long cbox_config, size; + if (cpu_type == PCA56_CPU) { L1I = CSHAPE(16*1024, 6, 1); L1D = CSHAPE(8*1024, 5, 1); @@ -1413,12 +1415,10 @@ determine_cpu_caches (unsigned int cpu_type) } L3 = -1; -#if 0 - unsigned long cbox_config, size; - cbox_config = *(vulp) phys_to_virt (0xfffff00008UL); size = 512*1024 * (1 << ((cbox_config >> 12) & 3)); +#if 0 L2 = ((cbox_config >> 31) & 1 ? CSHAPE (size, 6, 1) : -1); #else L2 = external_cache_probe(512*1024, 6); diff --git a/trunk/arch/alpha/kernel/smc37c93x.c b/trunk/arch/alpha/kernel/smc37c93x.c index 6886b834f487..3e6a2893af9f 100644 --- a/trunk/arch/alpha/kernel/smc37c93x.c +++ b/trunk/arch/alpha/kernel/smc37c93x.c @@ -79,6 +79,7 @@ static unsigned long __init SMCConfigState(unsigned long baseAddr) { unsigned char devId; + unsigned char devRev; unsigned long configPort; unsigned long indexPort; @@ -99,7 +100,7 @@ static unsigned long __init SMCConfigState(unsigned long baseAddr) devId = inb(dataPort); if (devId == VALID_DEVICE_ID) { outb(DEVICE_REV, indexPort); - /* unsigned char devRev = */ inb(dataPort); + devRev = inb(dataPort); break; } else diff --git a/trunk/arch/alpha/kernel/sys_wildfire.c b/trunk/arch/alpha/kernel/sys_wildfire.c index d92cdc715c65..d3cb28bb8eb0 100644 --- a/trunk/arch/alpha/kernel/sys_wildfire.c +++ b/trunk/arch/alpha/kernel/sys_wildfire.c @@ -156,6 +156,7 @@ static void __init wildfire_init_irq_per_pca(int qbbno, int pcano) { int i, irq_bias; + unsigned long io_bias; static struct irqaction isa_enable = { .handler = no_action, .name = "isa_enable", @@ -164,12 +165,10 @@ wildfire_init_irq_per_pca(int qbbno, int pcano) irq_bias = qbbno * (WILDFIRE_PCA_PER_QBB * WILDFIRE_IRQ_PER_PCA) + pcano * WILDFIRE_IRQ_PER_PCA; -#if 0 - unsigned long io_bias; - /* Only need the following for first PCI bus per PCA. */ io_bias = WILDFIRE_IO(qbbno, pcano<<1) - WILDFIRE_IO_BIAS; +#if 0 outb(0, DMA1_RESET_REG + io_bias); outb(0, DMA2_RESET_REG + io_bias); outb(DMA_MODE_CASCADE, DMA2_MODE_REG + io_bias); diff --git a/trunk/arch/alpha/kernel/time.c b/trunk/arch/alpha/kernel/time.c index 918e8e0b72ff..a58e84f1a63b 100644 --- a/trunk/arch/alpha/kernel/time.c +++ b/trunk/arch/alpha/kernel/time.c @@ -153,7 +153,6 @@ void read_persistent_clock(struct timespec *ts) year += 100; ts->tv_sec = mktime(year, mon, day, hour, min, sec); - ts->tv_nsec = 0; } diff --git a/trunk/arch/arm/Kconfig b/trunk/arch/arm/Kconfig index 377a7a595b08..fdc9d4dbf85b 100644 --- a/trunk/arch/arm/Kconfig +++ b/trunk/arch/arm/Kconfig @@ -1540,6 +1540,7 @@ config HIGHMEM config HIGHPTE bool "Allocate 2nd-level pagetables from highmem" depends on HIGHMEM + depends on !OUTER_CACHE config HW_PERF_EVENTS bool "Enable hardware performance counter support for perf events" @@ -2011,8 +2012,6 @@ source "kernel/power/Kconfig" config ARCH_SUSPEND_POSSIBLE depends on !ARCH_S5P64X0 && !ARCH_S5P6442 - depends on CPU_ARM920T || CPU_ARM926T || CPU_SA1100 || \ - CPU_V6 || CPU_V6K || CPU_V7 || CPU_XSC3 || CPU_XSCALE def_bool y endmenu diff --git a/trunk/arch/arm/Kconfig.debug b/trunk/arch/arm/Kconfig.debug index 03d01d783e3b..494224a9b459 100644 --- a/trunk/arch/arm/Kconfig.debug +++ b/trunk/arch/arm/Kconfig.debug @@ -63,6 +63,17 @@ config DEBUG_USER 8 - SIGSEGV faults 16 - SIGBUS faults +config DEBUG_ERRORS + bool "Verbose kernel error messages" + depends on DEBUG_KERNEL + help + This option controls verbose debugging information which can be + printed when the kernel detects an internal error. This debugging + information is useful to kernel hackers when tracking down problems, + but mostly meaningless to other people. It's safe to say Y unless + you are concerned with the code size or don't want to see these + messages. + config DEBUG_STACK_USAGE bool "Enable stack utilization instrumentation" depends on DEBUG_KERNEL diff --git a/trunk/arch/arm/common/Makefile b/trunk/arch/arm/common/Makefile index 6ea9b6f3607a..e7521bca2c35 100644 --- a/trunk/arch/arm/common/Makefile +++ b/trunk/arch/arm/common/Makefile @@ -16,4 +16,5 @@ obj-$(CONFIG_SHARP_SCOOP) += scoop.o obj-$(CONFIG_ARCH_IXP2000) += uengine.o obj-$(CONFIG_ARCH_IXP23XX) += uengine.o obj-$(CONFIG_PCI_HOST_ITE8152) += it8152.o +obj-$(CONFIG_COMMON_CLKDEV) += clkdev.o obj-$(CONFIG_ARM_TIMER_SP804) += timer-sp.o diff --git a/trunk/arch/arm/include/asm/thread_notify.h b/trunk/arch/arm/include/asm/thread_notify.h index 1dc980675894..c4391ba20350 100644 --- a/trunk/arch/arm/include/asm/thread_notify.h +++ b/trunk/arch/arm/include/asm/thread_notify.h @@ -43,7 +43,6 @@ static inline void thread_notify(unsigned long rc, struct thread_info *thread) #define THREAD_NOTIFY_FLUSH 0 #define THREAD_NOTIFY_EXIT 1 #define THREAD_NOTIFY_SWITCH 2 -#define THREAD_NOTIFY_COPY 3 #endif #endif diff --git a/trunk/arch/arm/kernel/Makefile b/trunk/arch/arm/kernel/Makefile index 8d95446150a3..74554f1742d7 100644 --- a/trunk/arch/arm/kernel/Makefile +++ b/trunk/arch/arm/kernel/Makefile @@ -29,7 +29,7 @@ obj-$(CONFIG_MODULES) += armksyms.o module.o obj-$(CONFIG_ARTHUR) += arthur.o obj-$(CONFIG_ISA_DMA) += dma-isa.o obj-$(CONFIG_PCI) += bios32.o isa.o -obj-$(CONFIG_PM_SLEEP) += sleep.o +obj-$(CONFIG_PM) += sleep.o obj-$(CONFIG_HAVE_SCHED_CLOCK) += sched_clock.o obj-$(CONFIG_SMP) += smp.o smp_tlb.o obj-$(CONFIG_HAVE_ARM_SCU) += smp_scu.o diff --git a/trunk/arch/arm/kernel/elf.c b/trunk/arch/arm/kernel/elf.c index 9b05c6a0dcea..d4a0da1e48f4 100644 --- a/trunk/arch/arm/kernel/elf.c +++ b/trunk/arch/arm/kernel/elf.c @@ -40,22 +40,15 @@ EXPORT_SYMBOL(elf_check_arch); void elf_set_personality(const struct elf32_hdr *x) { unsigned int eflags = x->e_flags; - unsigned int personality = current->personality & ~PER_MASK; - - /* - * We only support Linux ELF executables, so always set the - * personality to LINUX. - */ - personality |= PER_LINUX; + unsigned int personality = PER_LINUX_32BIT; /* * APCS-26 is only valid for OABI executables */ - if ((eflags & EF_ARM_EABI_MASK) == EF_ARM_EABI_UNKNOWN && - (eflags & EF_ARM_APCS_26)) - personality &= ~ADDR_LIMIT_32BIT; - else - personality |= ADDR_LIMIT_32BIT; + if ((eflags & EF_ARM_EABI_MASK) == EF_ARM_EABI_UNKNOWN) { + if (eflags & EF_ARM_APCS_26) + personality = PER_LINUX; + } set_personality(personality); diff --git a/trunk/arch/arm/kernel/hw_breakpoint.c b/trunk/arch/arm/kernel/hw_breakpoint.c index 87acc25d7a3e..8dbc126f7152 100644 --- a/trunk/arch/arm/kernel/hw_breakpoint.c +++ b/trunk/arch/arm/kernel/hw_breakpoint.c @@ -868,13 +868,6 @@ static void reset_ctrl_regs(void *info) */ asm volatile("mcr p14, 0, %0, c1, c0, 4" : : "r" (0)); isb(); - - /* - * Clear any configured vector-catch events before - * enabling monitor mode. - */ - asm volatile("mcr p14, 0, %0, c0, c7, 0" : : "r" (0)); - isb(); } if (enable_monitor_mode()) diff --git a/trunk/arch/arm/kernel/perf_event.c b/trunk/arch/arm/kernel/perf_event.c index 979da3947f42..69cfee0fe00f 100644 --- a/trunk/arch/arm/kernel/perf_event.c +++ b/trunk/arch/arm/kernel/perf_event.c @@ -221,7 +221,7 @@ armpmu_event_update(struct perf_event *event, prev_raw_count &= armpmu->max_period; if (overflow) - delta = armpmu->max_period - prev_raw_count + new_raw_count + 1; + delta = armpmu->max_period - prev_raw_count + new_raw_count; else delta = new_raw_count - prev_raw_count; diff --git a/trunk/arch/arm/kernel/process.c b/trunk/arch/arm/kernel/process.c index 5e1e54197227..94bbedbed639 100644 --- a/trunk/arch/arm/kernel/process.c +++ b/trunk/arch/arm/kernel/process.c @@ -372,8 +372,6 @@ copy_thread(unsigned long clone_flags, unsigned long stack_start, if (clone_flags & CLONE_SETTLS) thread->tp_value = regs->ARM_r3; - thread_notify(THREAD_NOTIFY_COPY, thread); - return 0; } diff --git a/trunk/arch/arm/kernel/traps.c b/trunk/arch/arm/kernel/traps.c index 3b54ad19d489..f0000e188c8c 100644 --- a/trunk/arch/arm/kernel/traps.c +++ b/trunk/arch/arm/kernel/traps.c @@ -410,7 +410,8 @@ static int bad_syscall(int n, struct pt_regs *regs) struct thread_info *thread = current_thread_info(); siginfo_t info; - if ((current->personality & PER_MASK) != PER_LINUX && + if (current->personality != PER_LINUX && + current->personality != PER_LINUX_32BIT && thread->exec_domain->handler) { thread->exec_domain->handler(n, regs); return regs->ARM_r0; diff --git a/trunk/arch/arm/mach-mmp/include/mach/gpio.h b/trunk/arch/arm/mach-mmp/include/mach/gpio.h index 7bfb827f3fe3..ee8b02ed8011 100644 --- a/trunk/arch/arm/mach-mmp/include/mach/gpio.h +++ b/trunk/arch/arm/mach-mmp/include/mach/gpio.h @@ -10,7 +10,7 @@ #define BANK_OFF(n) (((n) < 3) ? (n) << 2 : 0x100 + (((n) - 3) << 2)) #define GPIO_REG(x) (*((volatile u32 *)(GPIO_REGS_VIRT + (x)))) -#define NR_BUILTIN_GPIO IRQ_GPIO_NUM +#define NR_BUILTIN_GPIO (192) #define gpio_to_bank(gpio) ((gpio) >> 5) #define gpio_to_irq(gpio) (IRQ_GPIO_START + (gpio)) diff --git a/trunk/arch/arm/mach-mmp/include/mach/mfp-pxa168.h b/trunk/arch/arm/mach-mmp/include/mach/mfp-pxa168.h index 713be155a44d..4621067c7720 100644 --- a/trunk/arch/arm/mach-mmp/include/mach/mfp-pxa168.h +++ b/trunk/arch/arm/mach-mmp/include/mach/mfp-pxa168.h @@ -8,15 +8,6 @@ #define MFP_DRIVE_MEDIUM (0x2 << 13) #define MFP_DRIVE_FAST (0x3 << 13) -#undef MFP_CFG -#undef MFP_CFG_DRV - -#define MFP_CFG(pin, af) \ - (MFP_LPM_INPUT | MFP_PIN(MFP_PIN_##pin) | MFP_##af | MFP_DRIVE_MEDIUM) - -#define MFP_CFG_DRV(pin, af, drv) \ - (MFP_LPM_INPUT | MFP_PIN(MFP_PIN_##pin) | MFP_##af | MFP_DRIVE_##drv) - /* GPIO */ #define GPIO0_GPIO MFP_CFG(GPIO0, AF5) #define GPIO1_GPIO MFP_CFG(GPIO1, AF5) diff --git a/trunk/arch/arm/mach-msm/board-qsd8x50.c b/trunk/arch/arm/mach-msm/board-qsd8x50.c index 6a96911b0ad5..7f568611547e 100644 --- a/trunk/arch/arm/mach-msm/board-qsd8x50.c +++ b/trunk/arch/arm/mach-msm/board-qsd8x50.c @@ -160,7 +160,10 @@ static struct msm_mmc_platform_data qsd8x50_sdc1_data = { static void __init qsd8x50_init_mmc(void) { - vreg_mmc = vreg_get(NULL, "gp5"); + if (machine_is_qsd8x50_ffa() || machine_is_qsd8x50a_ffa()) + vreg_mmc = vreg_get(NULL, "gp6"); + else + vreg_mmc = vreg_get(NULL, "gp5"); if (IS_ERR(vreg_mmc)) { pr_err("vreg get for vreg_mmc failed (%ld)\n", diff --git a/trunk/arch/arm/mach-msm/timer.c b/trunk/arch/arm/mach-msm/timer.c index 38b95e949d13..56f920c55b6a 100644 --- a/trunk/arch/arm/mach-msm/timer.c +++ b/trunk/arch/arm/mach-msm/timer.c @@ -269,7 +269,7 @@ int __cpuinit local_timer_setup(struct clock_event_device *evt) /* Use existing clock_event for cpu 0 */ if (!smp_processor_id()) - return 0; + return; writel(DGT_CLK_CTL_DIV_4, MSM_TMR_BASE + DGT_CLK_CTL); diff --git a/trunk/arch/arm/mach-pxa/include/mach/gpio.h b/trunk/arch/arm/mach-pxa/include/mach/gpio.h index c4639502efca..b024a8b37439 100644 --- a/trunk/arch/arm/mach-pxa/include/mach/gpio.h +++ b/trunk/arch/arm/mach-pxa/include/mach/gpio.h @@ -99,24 +99,11 @@ #define GAFR(x) GPIO_REG(0x54 + (((x) & 0x70) >> 2)) -#define NR_BUILTIN_GPIO PXA_GPIO_IRQ_NUM +#define NR_BUILTIN_GPIO 128 #define gpio_to_bank(gpio) ((gpio) >> 5) #define gpio_to_irq(gpio) IRQ_GPIO(gpio) - -static inline int irq_to_gpio(unsigned int irq) -{ - int gpio; - - if (irq == IRQ_GPIO0 || irq == IRQ_GPIO1) - return irq - IRQ_GPIO0; - - gpio = irq - PXA_GPIO_IRQ_BASE; - if (gpio >= 2 && gpio < NR_BUILTIN_GPIO) - return gpio; - - return -1; -} +#define irq_to_gpio(irq) IRQ_TO_GPIO(irq) #ifdef CONFIG_CPU_PXA26x /* GPIO86/87/88/89 on PXA26x have their direction bits in GPDR2 inverted, diff --git a/trunk/arch/arm/mach-pxa/include/mach/irqs.h b/trunk/arch/arm/mach-pxa/include/mach/irqs.h index 038402404e39..a4285fc00878 100644 --- a/trunk/arch/arm/mach-pxa/include/mach/irqs.h +++ b/trunk/arch/arm/mach-pxa/include/mach/irqs.h @@ -93,6 +93,9 @@ #define GPIO_2_x_TO_IRQ(x) (PXA_GPIO_IRQ_BASE + (x)) #define IRQ_GPIO(x) (((x) < 2) ? (IRQ_GPIO0 + (x)) : GPIO_2_x_TO_IRQ(x)) +#define IRQ_TO_GPIO_2_x(i) ((i) - PXA_GPIO_IRQ_BASE) +#define IRQ_TO_GPIO(i) (((i) < IRQ_GPIO(2)) ? ((i) - IRQ_GPIO0) : IRQ_TO_GPIO_2_x(i)) + /* * The following interrupts are for board specific purposes. Since * the kernel can only run on one machine at a time, we can re-use diff --git a/trunk/arch/arm/mach-pxa/pxa25x.c b/trunk/arch/arm/mach-pxa/pxa25x.c index a4af8c52d7ee..6bde5956358d 100644 --- a/trunk/arch/arm/mach-pxa/pxa25x.c +++ b/trunk/arch/arm/mach-pxa/pxa25x.c @@ -285,7 +285,7 @@ static inline void pxa25x_init_pm(void) {} static int pxa25x_set_wake(struct irq_data *d, unsigned int on) { - int gpio = irq_to_gpio(d->irq); + int gpio = IRQ_TO_GPIO(d->irq); uint32_t mask = 0; if (gpio >= 0 && gpio < 85) diff --git a/trunk/arch/arm/mach-pxa/pxa27x.c b/trunk/arch/arm/mach-pxa/pxa27x.c index 909756eaf4b7..1cb5d0f9723f 100644 --- a/trunk/arch/arm/mach-pxa/pxa27x.c +++ b/trunk/arch/arm/mach-pxa/pxa27x.c @@ -345,7 +345,7 @@ static inline void pxa27x_init_pm(void) {} */ static int pxa27x_set_wake(struct irq_data *d, unsigned int on) { - int gpio = irq_to_gpio(d->irq); + int gpio = IRQ_TO_GPIO(d->irq); uint32_t mask; if (gpio >= 0 && gpio < 128) diff --git a/trunk/arch/arm/mach-tegra/gpio.c b/trunk/arch/arm/mach-tegra/gpio.c index 65a1aba6823d..76a3f654220f 100644 --- a/trunk/arch/arm/mach-tegra/gpio.c +++ b/trunk/arch/arm/mach-tegra/gpio.c @@ -257,8 +257,7 @@ static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) void tegra_gpio_resume(void) { unsigned long flags; - int b; - int p; + int b, p, i; local_irq_save(flags); @@ -281,8 +280,7 @@ void tegra_gpio_resume(void) void tegra_gpio_suspend(void) { unsigned long flags; - int b; - int p; + int b, p, i; local_irq_save(flags); for (b = 0; b < ARRAY_SIZE(tegra_gpio_banks); b++) { diff --git a/trunk/arch/arm/mach-tegra/tegra2_clocks.c b/trunk/arch/arm/mach-tegra/tegra2_clocks.c index 4459470c052d..6d7c4eea4dcb 100644 --- a/trunk/arch/arm/mach-tegra/tegra2_clocks.c +++ b/trunk/arch/arm/mach-tegra/tegra2_clocks.c @@ -1362,15 +1362,14 @@ static int tegra_clk_shared_bus_set_rate(struct clk *c, unsigned long rate) { unsigned long flags; int ret; - long new_rate = rate; - new_rate = clk_round_rate(c->parent, new_rate); - if (new_rate < 0) - return new_rate; + rate = clk_round_rate(c->parent, rate); + if (rate < 0) + return rate; spin_lock_irqsave(&c->parent->spinlock, flags); - c->u.shared_bus_user.rate = new_rate; + c->u.shared_bus_user.rate = rate; ret = tegra_clk_shared_bus_update(c->parent); spin_unlock_irqrestore(&c->parent->spinlock, flags); diff --git a/trunk/arch/arm/mm/mmap.c b/trunk/arch/arm/mm/mmap.c index 74be05f3e03a..afe209e1e1f8 100644 --- a/trunk/arch/arm/mm/mmap.c +++ b/trunk/arch/arm/mm/mmap.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -83,8 +82,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr, mm->cached_hole_size = 0; } /* 8 bits of randomness in 20 address space bits */ - if ((current->flags & PF_RANDOMIZE) && - !(current->personality & ADDR_NO_RANDOMIZE)) + if (current->flags & PF_RANDOMIZE) addr += (get_random_int() % (1 << 8)) << PAGE_SHIFT; full_search: diff --git a/trunk/arch/arm/mm/proc-arm920.S b/trunk/arch/arm/mm/proc-arm920.S index bf8a1d1cccb6..b46eb21f05c7 100644 --- a/trunk/arch/arm/mm/proc-arm920.S +++ b/trunk/arch/arm/mm/proc-arm920.S @@ -390,7 +390,7 @@ ENTRY(cpu_arm920_set_pte_ext) /* Suspend/resume support: taken from arch/arm/plat-s3c24xx/sleep.S */ .globl cpu_arm920_suspend_size .equ cpu_arm920_suspend_size, 4 * 3 -#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_PM ENTRY(cpu_arm920_do_suspend) stmfd sp!, {r4 - r7, lr} mrc p15, 0, r4, c13, c0, 0 @ PID diff --git a/trunk/arch/arm/mm/proc-arm926.S b/trunk/arch/arm/mm/proc-arm926.S index 0ed85d930c09..6a4bdb2c94a7 100644 --- a/trunk/arch/arm/mm/proc-arm926.S +++ b/trunk/arch/arm/mm/proc-arm926.S @@ -404,7 +404,7 @@ ENTRY(cpu_arm926_set_pte_ext) /* Suspend/resume support: taken from arch/arm/plat-s3c24xx/sleep.S */ .globl cpu_arm926_suspend_size .equ cpu_arm926_suspend_size, 4 * 3 -#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_PM ENTRY(cpu_arm926_do_suspend) stmfd sp!, {r4 - r7, lr} mrc p15, 0, r4, c13, c0, 0 @ PID diff --git a/trunk/arch/arm/mm/proc-sa1100.S b/trunk/arch/arm/mm/proc-sa1100.S index 184a9c997e36..74483d1977fe 100644 --- a/trunk/arch/arm/mm/proc-sa1100.S +++ b/trunk/arch/arm/mm/proc-sa1100.S @@ -171,7 +171,7 @@ ENTRY(cpu_sa1100_set_pte_ext) .globl cpu_sa1100_suspend_size .equ cpu_sa1100_suspend_size, 4*4 -#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_PM ENTRY(cpu_sa1100_do_suspend) stmfd sp!, {r4 - r7, lr} mrc p15, 0, r4, c3, c0, 0 @ domain ID diff --git a/trunk/arch/arm/mm/proc-v6.S b/trunk/arch/arm/mm/proc-v6.S index 7c99cb4c8e4f..bfa0c9f611c5 100644 --- a/trunk/arch/arm/mm/proc-v6.S +++ b/trunk/arch/arm/mm/proc-v6.S @@ -124,7 +124,7 @@ ENTRY(cpu_v6_set_pte_ext) /* Suspend/resume support: taken from arch/arm/mach-s3c64xx/sleep.S */ .globl cpu_v6_suspend_size .equ cpu_v6_suspend_size, 4 * 8 -#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_PM ENTRY(cpu_v6_do_suspend) stmfd sp!, {r4 - r11, lr} mrc p15, 0, r4, c13, c0, 0 @ FCSE/PID diff --git a/trunk/arch/arm/mm/proc-v7.S b/trunk/arch/arm/mm/proc-v7.S index babfba09c89f..c35618e42f6f 100644 --- a/trunk/arch/arm/mm/proc-v7.S +++ b/trunk/arch/arm/mm/proc-v7.S @@ -211,7 +211,7 @@ cpu_v7_name: /* Suspend/resume support: derived from arch/arm/mach-s5pv210/sleep.S */ .globl cpu_v7_suspend_size .equ cpu_v7_suspend_size, 4 * 8 -#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_PM ENTRY(cpu_v7_do_suspend) stmfd sp!, {r4 - r11, lr} mrc p15, 0, r4, c13, c0, 0 @ FCSE/PID diff --git a/trunk/arch/arm/mm/proc-xsc3.S b/trunk/arch/arm/mm/proc-xsc3.S index 596213699f37..63d8b2044e84 100644 --- a/trunk/arch/arm/mm/proc-xsc3.S +++ b/trunk/arch/arm/mm/proc-xsc3.S @@ -417,7 +417,7 @@ ENTRY(cpu_xsc3_set_pte_ext) .globl cpu_xsc3_suspend_size .equ cpu_xsc3_suspend_size, 4 * 8 -#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_PM ENTRY(cpu_xsc3_do_suspend) stmfd sp!, {r4 - r10, lr} mrc p14, 0, r4, c6, c0, 0 @ clock configuration, for turbo mode diff --git a/trunk/arch/arm/mm/proc-xscale.S b/trunk/arch/arm/mm/proc-xscale.S index ce233bcbf506..086038cd86ab 100644 --- a/trunk/arch/arm/mm/proc-xscale.S +++ b/trunk/arch/arm/mm/proc-xscale.S @@ -518,7 +518,7 @@ ENTRY(cpu_xscale_set_pte_ext) .globl cpu_xscale_suspend_size .equ cpu_xscale_suspend_size, 4 * 7 -#ifdef CONFIG_PM_SLEEP +#ifdef CONFIG_PM ENTRY(cpu_xscale_do_suspend) stmfd sp!, {r4 - r10, lr} mrc p14, 0, r4, c6, c0, 0 @ clock configuration, for turbo mode diff --git a/trunk/arch/arm/plat-s5p/pm.c b/trunk/arch/arm/plat-s5p/pm.c index d15dc47b0e3d..d592b6304b48 100644 --- a/trunk/arch/arm/plat-s5p/pm.c +++ b/trunk/arch/arm/plat-s5p/pm.c @@ -19,6 +19,17 @@ #define PFX "s5p pm: " +/* s3c_pm_check_resume_pin + * + * check to see if the pin is configured correctly for sleep mode, and + * make any necessary adjustments if it is not +*/ + +static void s3c_pm_check_resume_pin(unsigned int pin, unsigned int irqoffs) +{ + /* nothing here yet */ +} + /* s3c_pm_configure_extint * * configure all external interrupt pins diff --git a/trunk/arch/arm/plat-samsung/pm-check.c b/trunk/arch/arm/plat-samsung/pm-check.c index 6b733fafe7cd..e4baf76f374a 100644 --- a/trunk/arch/arm/plat-samsung/pm-check.c +++ b/trunk/arch/arm/plat-samsung/pm-check.c @@ -164,6 +164,7 @@ static inline int in_region(void *ptr, int size, void *what, size_t whatsz) */ static u32 *s3c_pm_runcheck(struct resource *res, u32 *val) { + void *save_at = phys_to_virt(s3c_sleep_save_phys); unsigned long addr; unsigned long left; void *stkpage; @@ -191,6 +192,11 @@ static u32 *s3c_pm_runcheck(struct resource *res, u32 *val) goto skip_check; } + if (in_region(ptr, left, save_at, 32*4 )) { + S3C_PMDBG("skipping %08lx, has save block in\n", addr); + goto skip_check; + } + /* calculate and check the checksum */ calc = crc32_le(~0, ptr, left); diff --git a/trunk/arch/arm/plat-samsung/pm.c b/trunk/arch/arm/plat-samsung/pm.c index 5c0a440d6e16..d5b58d31903c 100644 --- a/trunk/arch/arm/plat-samsung/pm.c +++ b/trunk/arch/arm/plat-samsung/pm.c @@ -214,9 +214,8 @@ void s3c_pm_do_restore_core(struct sleep_save *ptr, int count) * * print any IRQs asserted at resume time (ie, we woke from) */ -static void __maybe_unused s3c_pm_show_resume_irqs(int start, - unsigned long which, - unsigned long mask) +static void s3c_pm_show_resume_irqs(int start, unsigned long which, + unsigned long mask) { int i; diff --git a/trunk/arch/arm/vfp/vfpmodule.c b/trunk/arch/arm/vfp/vfpmodule.c index f74695075e64..bbf3da012afd 100644 --- a/trunk/arch/arm/vfp/vfpmodule.c +++ b/trunk/arch/arm/vfp/vfpmodule.c @@ -78,14 +78,6 @@ static void vfp_thread_exit(struct thread_info *thread) put_cpu(); } -static void vfp_thread_copy(struct thread_info *thread) -{ - struct thread_info *parent = current_thread_info(); - - vfp_sync_hwstate(parent); - thread->vfpstate = parent->vfpstate; -} - /* * When this function is called with the following 'cmd's, the following * is true while this function is being run: @@ -112,17 +104,12 @@ static void vfp_thread_copy(struct thread_info *thread) static int vfp_notifier(struct notifier_block *self, unsigned long cmd, void *v) { struct thread_info *thread = v; - u32 fpexc; -#ifdef CONFIG_SMP - unsigned int cpu; -#endif - switch (cmd) { - case THREAD_NOTIFY_SWITCH: - fpexc = fmrx(FPEXC); + if (likely(cmd == THREAD_NOTIFY_SWITCH)) { + u32 fpexc = fmrx(FPEXC); #ifdef CONFIG_SMP - cpu = thread->cpu; + unsigned int cpu = thread->cpu; /* * On SMP, if VFP is enabled, save the old state in @@ -147,20 +134,13 @@ static int vfp_notifier(struct notifier_block *self, unsigned long cmd, void *v) * old state. */ fmxr(FPEXC, fpexc & ~FPEXC_EN); - break; + return NOTIFY_DONE; + } - case THREAD_NOTIFY_FLUSH: + if (cmd == THREAD_NOTIFY_FLUSH) vfp_thread_flush(thread); - break; - - case THREAD_NOTIFY_EXIT: + else vfp_thread_exit(thread); - break; - - case THREAD_NOTIFY_COPY: - vfp_thread_copy(thread); - break; - } return NOTIFY_DONE; } diff --git a/trunk/arch/avr32/include/asm/setup.h b/trunk/arch/avr32/include/asm/setup.h index 160543dbec7e..ff5b7cf6be4d 100644 --- a/trunk/arch/avr32/include/asm/setup.h +++ b/trunk/arch/avr32/include/asm/setup.h @@ -94,13 +94,6 @@ struct tag_ethernet { #define ETH_INVALID_PHY 0xff -/* board information */ -#define ATAG_BOARDINFO 0x54410008 - -struct tag_boardinfo { - u32 board_number; -}; - struct tag { struct tag_header hdr; union { @@ -109,7 +102,6 @@ struct tag { struct tag_cmdline cmdline; struct tag_clock clock; struct tag_ethernet ethernet; - struct tag_boardinfo boardinfo; } u; }; @@ -136,7 +128,6 @@ extern struct tag *bootloader_tags; extern resource_size_t fbmem_start; extern resource_size_t fbmem_size; -extern u32 board_number; void setup_processor(void); diff --git a/trunk/arch/avr32/kernel/setup.c b/trunk/arch/avr32/kernel/setup.c index bb0974cce4ac..5c7083916c33 100644 --- a/trunk/arch/avr32/kernel/setup.c +++ b/trunk/arch/avr32/kernel/setup.c @@ -390,21 +390,6 @@ static int __init parse_tag_clock(struct tag *tag) } __tagtable(ATAG_CLOCK, parse_tag_clock); -/* - * The board_number correspond to the bd->bi_board_number in U-Boot. This - * parameter is only available during initialisation and can be used in some - * kind of board identification. - */ -u32 __initdata board_number; - -static int __init parse_tag_boardinfo(struct tag *tag) -{ - board_number = tag->u.boardinfo.board_number; - - return 0; -} -__tagtable(ATAG_BOARDINFO, parse_tag_boardinfo); - /* * Scan the tag table for this tag, and call its parse function. The * tag table is built by the linker from all the __tagtable diff --git a/trunk/arch/avr32/kernel/traps.c b/trunk/arch/avr32/kernel/traps.c index 7aa25756412f..b91b2044af9c 100644 --- a/trunk/arch/avr32/kernel/traps.c +++ b/trunk/arch/avr32/kernel/traps.c @@ -95,6 +95,28 @@ void _exception(long signr, struct pt_regs *regs, int code, info.si_code = code; info.si_addr = (void __user *)addr; force_sig_info(signr, &info, current); + + /* + * Init gets no signals that it doesn't have a handler for. + * That's all very well, but if it has caused a synchronous + * exception and we ignore the resulting signal, it will just + * generate the same exception over and over again and we get + * nowhere. Better to kill it and let the kernel panic. + */ + if (is_global_init(current)) { + __sighandler_t handler; + + spin_lock_irq(¤t->sighand->siglock); + handler = current->sighand->action[signr-1].sa.sa_handler; + spin_unlock_irq(¤t->sighand->siglock); + if (handler == SIG_DFL) { + /* init has generated a synchronous exception + and it doesn't have a handler for the signal */ + printk(KERN_CRIT "init has generated signal %ld " + "but has no handler for it\n", signr); + do_exit(signr); + } + } } asmlinkage void do_nmi(unsigned long ecr, struct pt_regs *regs) diff --git a/trunk/arch/avr32/mach-at32ap/clock.c b/trunk/arch/avr32/mach-at32ap/clock.c index 86925fd6ea5b..442f08c5e641 100644 --- a/trunk/arch/avr32/mach-at32ap/clock.c +++ b/trunk/arch/avr32/mach-at32ap/clock.c @@ -35,30 +35,22 @@ void at32_clk_register(struct clk *clk) spin_unlock(&clk_list_lock); } -static struct clk *__clk_get(struct device *dev, const char *id) +struct clk *clk_get(struct device *dev, const char *id) { struct clk *clk; + spin_lock(&clk_list_lock); + list_for_each_entry(clk, &at32_clock_list, list) { if (clk->dev == dev && strcmp(id, clk->name) == 0) { + spin_unlock(&clk_list_lock); return clk; } } - return ERR_PTR(-ENOENT); -} - -struct clk *clk_get(struct device *dev, const char *id) -{ - struct clk *clk; - - spin_lock(&clk_list_lock); - clk = __clk_get(dev, id); spin_unlock(&clk_list_lock); - - return clk; + return ERR_PTR(-ENOENT); } - EXPORT_SYMBOL(clk_get); void clk_put(struct clk *clk) @@ -265,15 +257,15 @@ static int clk_show(struct seq_file *s, void *unused) spin_lock(&clk_list_lock); /* show clock tree as derived from the three oscillators */ - clk = __clk_get(NULL, "osc32k"); + clk = clk_get(NULL, "osc32k"); dump_clock(clk, &r); clk_put(clk); - clk = __clk_get(NULL, "osc0"); + clk = clk_get(NULL, "osc0"); dump_clock(clk, &r); clk_put(clk); - clk = __clk_get(NULL, "osc1"); + clk = clk_get(NULL, "osc1"); dump_clock(clk, &r); clk_put(clk); diff --git a/trunk/arch/avr32/mach-at32ap/extint.c b/trunk/arch/avr32/mach-at32ap/extint.c index fbc2aeaebddb..47ba4b9b6db1 100644 --- a/trunk/arch/avr32/mach-at32ap/extint.c +++ b/trunk/arch/avr32/mach-at32ap/extint.c @@ -61,34 +61,34 @@ struct eic { static struct eic *nmi_eic; static bool nmi_enabled; -static void eic_ack_irq(struct irq_data *d) +static void eic_ack_irq(struct irq_chip *d) { - struct eic *eic = irq_data_get_irq_chip_data(d); + struct eic *eic = irq_data_get_irq_chip_data(data); eic_writel(eic, ICR, 1 << (d->irq - eic->first_irq)); } -static void eic_mask_irq(struct irq_data *d) +static void eic_mask_irq(struct irq_chip *d) { - struct eic *eic = irq_data_get_irq_chip_data(d); + struct eic *eic = irq_data_get_irq_chip_data(data); eic_writel(eic, IDR, 1 << (d->irq - eic->first_irq)); } -static void eic_mask_ack_irq(struct irq_data *d) +static void eic_mask_ack_irq(struct irq_chip *d) { - struct eic *eic = irq_data_get_irq_chip_data(d); + struct eic *eic = irq_data_get_irq_chip_data(data); eic_writel(eic, ICR, 1 << (d->irq - eic->first_irq)); eic_writel(eic, IDR, 1 << (d->irq - eic->first_irq)); } -static void eic_unmask_irq(struct irq_data *d) +static void eic_unmask_irq(struct irq_chip *d) { - struct eic *eic = irq_data_get_irq_chip_data(d); + struct eic *eic = irq_data_get_irq_chip_data(data); eic_writel(eic, IER, 1 << (d->irq - eic->first_irq)); } -static int eic_set_irq_type(struct irq_data *d, unsigned int flow_type) +static int eic_set_irq_type(struct irq_chip *d, unsigned int flow_type) { - struct eic *eic = irq_data_get_irq_chip_data(d); + struct eic *eic = irq_data_get_irq_chip_data(data); unsigned int irq = d->irq; unsigned int i = irq - eic->first_irq; u32 mode, edge, level; @@ -191,7 +191,7 @@ static int __init eic_probe(struct platform_device *pdev) regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); int_irq = platform_get_irq(pdev, 0); - if (!regs || (int)int_irq <= 0) { + if (!regs || !int_irq) { dev_dbg(&pdev->dev, "missing regs and/or irq resource\n"); return -ENXIO; } diff --git a/trunk/arch/avr32/mach-at32ap/pio.c b/trunk/arch/avr32/mach-at32ap/pio.c index 2e0aa853a4bc..f308e1ddc629 100644 --- a/trunk/arch/avr32/mach-at32ap/pio.c +++ b/trunk/arch/avr32/mach-at32ap/pio.c @@ -257,7 +257,7 @@ static void gpio_irq_mask(struct irq_data *d) pio_writel(pio, IDR, 1 << (gpio & 0x1f)); } -static void gpio_irq_unmask(struct irq_data *d) +static void gpio_irq_unmask(struct irq_data *d)) { unsigned gpio = irq_to_gpio(d->irq); struct pio_device *pio = &pio_dev[gpio >> 5]; diff --git a/trunk/arch/avr32/mach-at32ap/pm-at32ap700x.S b/trunk/arch/avr32/mach-at32ap/pm-at32ap700x.S index f868f4ce761b..17503b0ed6c9 100644 --- a/trunk/arch/avr32/mach-at32ap/pm-at32ap700x.S +++ b/trunk/arch/avr32/mach-at32ap/pm-at32ap700x.S @@ -53,7 +53,7 @@ cpu_enter_idle: st.w r8[TI_flags], r9 unmask_interrupts sleep CPU_SLEEP_IDLE - .size cpu_enter_idle, . - cpu_enter_idle + .size cpu_idle_sleep, . - cpu_idle_sleep /* * Common return path for PM functions that don't run from diff --git a/trunk/arch/blackfin/include/asm/system.h b/trunk/arch/blackfin/include/asm/system.h index 44bd0cced725..19e2c7c3e63a 100644 --- a/trunk/arch/blackfin/include/asm/system.h +++ b/trunk/arch/blackfin/include/asm/system.h @@ -19,11 +19,11 @@ * Force strict CPU ordering. */ #define nop() __asm__ __volatile__ ("nop;\n\t" : : ) -#define smp_mb() mb() -#define smp_rmb() rmb() -#define smp_wmb() wmb() -#define set_mb(var, value) do { var = value; mb(); } while (0) -#define smp_read_barrier_depends() read_barrier_depends() +#define mb() __asm__ __volatile__ ("" : : : "memory") +#define rmb() __asm__ __volatile__ ("" : : : "memory") +#define wmb() __asm__ __volatile__ ("" : : : "memory") +#define set_mb(var, value) do { (void) xchg(&var, value); } while (0) +#define read_barrier_depends() do { } while(0) #ifdef CONFIG_SMP asmlinkage unsigned long __raw_xchg_1_asm(volatile void *ptr, unsigned long value); @@ -37,16 +37,16 @@ asmlinkage unsigned long __raw_cmpxchg_4_asm(volatile void *ptr, unsigned long new, unsigned long old); #ifdef __ARCH_SYNC_CORE_DCACHE -/* Force Core data cache coherence */ -# define mb() do { barrier(); smp_check_barrier(); smp_mark_barrier(); } while (0) -# define rmb() do { barrier(); smp_check_barrier(); } while (0) -# define wmb() do { barrier(); smp_mark_barrier(); } while (0) -# define read_barrier_depends() do { barrier(); smp_check_barrier(); } while (0) +# define smp_mb() do { barrier(); smp_check_barrier(); smp_mark_barrier(); } while (0) +# define smp_rmb() do { barrier(); smp_check_barrier(); } while (0) +# define smp_wmb() do { barrier(); smp_mark_barrier(); } while (0) +#define smp_read_barrier_depends() do { barrier(); smp_check_barrier(); } while (0) + #else -# define mb() barrier() -# define rmb() barrier() -# define wmb() barrier() -# define read_barrier_depends() do { } while (0) +# define smp_mb() barrier() +# define smp_rmb() barrier() +# define smp_wmb() barrier() +#define smp_read_barrier_depends() barrier() #endif static inline unsigned long __xchg(unsigned long x, volatile void *ptr, @@ -99,10 +99,10 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old, #else /* !CONFIG_SMP */ -#define mb() barrier() -#define rmb() barrier() -#define wmb() barrier() -#define read_barrier_depends() do { } while (0) +#define smp_mb() barrier() +#define smp_rmb() barrier() +#define smp_wmb() barrier() +#define smp_read_barrier_depends() do { } while(0) struct __xchg_dummy { unsigned long a[100]; diff --git a/trunk/arch/blackfin/kernel/gptimers.c b/trunk/arch/blackfin/kernel/gptimers.c index 8b81dc04488a..cdbe075de1dc 100644 --- a/trunk/arch/blackfin/kernel/gptimers.c +++ b/trunk/arch/blackfin/kernel/gptimers.c @@ -268,7 +268,7 @@ void disable_gptimers(uint16_t mask) _disable_gptimers(mask); for (i = 0; i < MAX_BLACKFIN_GPTIMERS; ++i) if (mask & (1 << i)) - group_regs[BFIN_TIMER_OCTET(i)]->status = trun_mask[i]; + group_regs[BFIN_TIMER_OCTET(i)]->status |= trun_mask[i]; SSYNC(); } EXPORT_SYMBOL(disable_gptimers); diff --git a/trunk/arch/blackfin/kernel/time-ts.c b/trunk/arch/blackfin/kernel/time-ts.c index cdb4beb6bc8f..8c9a43daf80f 100644 --- a/trunk/arch/blackfin/kernel/time-ts.c +++ b/trunk/arch/blackfin/kernel/time-ts.c @@ -206,14 +206,8 @@ irqreturn_t bfin_gptmr0_interrupt(int irq, void *dev_id) { struct clock_event_device *evt = dev_id; smp_mb(); - /* - * We want to ACK before we handle so that we can handle smaller timer - * intervals. This way if the timer expires again while we're handling - * things, we're more likely to see that 2nd int rather than swallowing - * it by ACKing the int at the end of this handler. - */ - bfin_gptmr0_ack(); evt->event_handler(evt); + bfin_gptmr0_ack(); return IRQ_HANDLED; } diff --git a/trunk/arch/blackfin/mach-common/smp.c b/trunk/arch/blackfin/mach-common/smp.c index 8bce5ed031e4..6e17a265c4d3 100644 --- a/trunk/arch/blackfin/mach-common/smp.c +++ b/trunk/arch/blackfin/mach-common/smp.c @@ -109,23 +109,10 @@ static void ipi_flush_icache(void *info) struct blackfin_flush_data *fdata = info; /* Invalidate the memory holding the bounds of the flushed region. */ - blackfin_dcache_invalidate_range((unsigned long)fdata, - (unsigned long)fdata + sizeof(*fdata)); - - /* Make sure all write buffers in the data side of the core - * are flushed before trying to invalidate the icache. This - * needs to be after the data flush and before the icache - * flush so that the SSYNC does the right thing in preventing - * the instruction prefetcher from hitting things in cached - * memory at the wrong time -- it runs much further ahead than - * the pipeline. - */ - SSYNC(); + invalidate_dcache_range((unsigned long)fdata, + (unsigned long)fdata + sizeof(*fdata)); - /* ipi_flaush_icache is invoked by generic flush_icache_range, - * so call blackfin arch icache flush directly here. - */ - blackfin_icache_flush_range(fdata->start, fdata->end); + flush_icache_range(fdata->start, fdata->end); } static void ipi_call_function(unsigned int cpu, struct ipi_message *msg) diff --git a/trunk/arch/m68k/include/asm/unistd.h b/trunk/arch/m68k/include/asm/unistd.h index 29e17907d9f2..26d851d385bb 100644 --- a/trunk/arch/m68k/include/asm/unistd.h +++ b/trunk/arch/m68k/include/asm/unistd.h @@ -343,14 +343,10 @@ #define __NR_fanotify_init 337 #define __NR_fanotify_mark 338 #define __NR_prlimit64 339 -#define __NR_name_to_handle_at 340 -#define __NR_open_by_handle_at 341 -#define __NR_clock_adjtime 342 -#define __NR_syncfs 343 #ifdef __KERNEL__ -#define NR_syscalls 344 +#define NR_syscalls 340 #define __ARCH_WANT_IPC_PARSE_VERSION #define __ARCH_WANT_OLD_READDIR diff --git a/trunk/arch/m68k/kernel/entry_mm.S b/trunk/arch/m68k/kernel/entry_mm.S index 1359ee659574..1559dea36e55 100644 --- a/trunk/arch/m68k/kernel/entry_mm.S +++ b/trunk/arch/m68k/kernel/entry_mm.S @@ -750,8 +750,4 @@ sys_call_table: .long sys_fanotify_init .long sys_fanotify_mark .long sys_prlimit64 - .long sys_name_to_handle_at /* 340 */ - .long sys_open_by_handle_at - .long sys_clock_adjtime - .long sys_syncfs diff --git a/trunk/arch/m68k/kernel/syscalltable.S b/trunk/arch/m68k/kernel/syscalltable.S index 9b8393d8adb8..79b1ed198c07 100644 --- a/trunk/arch/m68k/kernel/syscalltable.S +++ b/trunk/arch/m68k/kernel/syscalltable.S @@ -358,10 +358,6 @@ ENTRY(sys_call_table) .long sys_fanotify_init .long sys_fanotify_mark .long sys_prlimit64 - .long sys_name_to_handle_at /* 340 */ - .long sys_open_by_handle_at - .long sys_clock_adjtime - .long sys_syncfs .rept NR_syscalls-(.-sys_call_table)/4 .long sys_ni_syscall diff --git a/trunk/arch/microblaze/Kconfig b/trunk/arch/microblaze/Kconfig index eccdefe70d4e..851b3bf6e962 100644 --- a/trunk/arch/microblaze/Kconfig +++ b/trunk/arch/microblaze/Kconfig @@ -6,6 +6,7 @@ config MICROBLAZE select HAVE_FUNCTION_GRAPH_TRACER select HAVE_DYNAMIC_FTRACE select HAVE_FTRACE_MCOUNT_RECORD + select USB_ARCH_HAS_EHCI select ARCH_WANT_OPTIONAL_GPIOLIB select HAVE_OPROFILE select HAVE_ARCH_KGDB diff --git a/trunk/arch/powerpc/Kconfig b/trunk/arch/powerpc/Kconfig index 8f4d50b0adfa..b6ff882f695b 100644 --- a/trunk/arch/powerpc/Kconfig +++ b/trunk/arch/powerpc/Kconfig @@ -209,7 +209,7 @@ config ARCH_HIBERNATION_POSSIBLE config ARCH_SUSPEND_POSSIBLE def_bool y depends on ADB_PMU || PPC_EFIKA || PPC_LITE5200 || PPC_83xx || \ - (PPC_85xx && !SMP) || PPC_86xx || PPC_PSERIES || 44x || 40x + PPC_85xx || PPC_86xx || PPC_PSERIES || 44x || 40x config PPC_DCR_NATIVE bool diff --git a/trunk/arch/powerpc/include/asm/cputable.h b/trunk/arch/powerpc/include/asm/cputable.h index 1833d1a07e79..be3cdf9134ce 100644 --- a/trunk/arch/powerpc/include/asm/cputable.h +++ b/trunk/arch/powerpc/include/asm/cputable.h @@ -382,12 +382,10 @@ extern const char *powerpc_base_platform; #define CPU_FTRS_E500_2 (CPU_FTR_MAYBE_CAN_DOZE | CPU_FTR_USE_TB | \ CPU_FTR_SPE_COMP | CPU_FTR_MAYBE_CAN_NAP | \ CPU_FTR_NODSISRALIGN | CPU_FTR_NOEXECUTE) -#define CPU_FTRS_E500MC (CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \ +#define CPU_FTRS_E500MC (CPU_FTR_MAYBE_CAN_DOZE | CPU_FTR_USE_TB | \ + CPU_FTR_MAYBE_CAN_NAP | CPU_FTR_NODSISRALIGN | \ CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \ CPU_FTR_DBELL) -#define CPU_FTRS_E5500 (CPU_FTR_USE_TB | CPU_FTR_NODSISRALIGN | \ - CPU_FTR_L2CSR | CPU_FTR_LWSYNC | CPU_FTR_NOEXECUTE | \ - CPU_FTR_DBELL | CPU_FTR_POPCNTB | CPU_FTR_POPCNTD) #define CPU_FTRS_GENERIC_32 (CPU_FTR_COMMON | CPU_FTR_NODSISRALIGN) /* 64-bit CPUs */ @@ -437,15 +435,11 @@ extern const char *powerpc_base_platform; #define CPU_FTRS_COMPATIBLE (CPU_FTR_USE_TB | CPU_FTR_PPCAS_ARCH_V2) #ifdef __powerpc64__ -#ifdef CONFIG_PPC_BOOK3E -#define CPU_FTRS_POSSIBLE (CPU_FTRS_E5500) -#else #define CPU_FTRS_POSSIBLE \ (CPU_FTRS_POWER3 | CPU_FTRS_RS64 | CPU_FTRS_POWER4 | \ CPU_FTRS_PPC970 | CPU_FTRS_POWER5 | CPU_FTRS_POWER6 | \ CPU_FTRS_POWER7 | CPU_FTRS_CELL | CPU_FTRS_PA6T | \ CPU_FTR_1T_SEGMENT | CPU_FTR_VSX) -#endif #else enum { CPU_FTRS_POSSIBLE = @@ -479,21 +473,16 @@ enum { #endif #ifdef CONFIG_E500 CPU_FTRS_E500 | CPU_FTRS_E500_2 | CPU_FTRS_E500MC | - CPU_FTRS_E5500 | #endif 0, }; #endif /* __powerpc64__ */ #ifdef __powerpc64__ -#ifdef CONFIG_PPC_BOOK3E -#define CPU_FTRS_ALWAYS (CPU_FTRS_E5500) -#else #define CPU_FTRS_ALWAYS \ (CPU_FTRS_POWER3 & CPU_FTRS_RS64 & CPU_FTRS_POWER4 & \ CPU_FTRS_PPC970 & CPU_FTRS_POWER5 & CPU_FTRS_POWER6 & \ CPU_FTRS_POWER7 & CPU_FTRS_CELL & CPU_FTRS_PA6T & CPU_FTRS_POSSIBLE) -#endif #else enum { CPU_FTRS_ALWAYS = @@ -524,7 +513,6 @@ enum { #endif #ifdef CONFIG_E500 CPU_FTRS_E500 & CPU_FTRS_E500_2 & CPU_FTRS_E500MC & - CPU_FTRS_E5500 & #endif CPU_FTRS_POSSIBLE, }; diff --git a/trunk/arch/powerpc/include/asm/pte-common.h b/trunk/arch/powerpc/include/asm/pte-common.h index 8d1569c29042..811f04ac3660 100644 --- a/trunk/arch/powerpc/include/asm/pte-common.h +++ b/trunk/arch/powerpc/include/asm/pte-common.h @@ -162,7 +162,7 @@ extern unsigned long bad_call_to_PMD_PAGE_SIZE(void); * on platforms where such control is possible. */ #if defined(CONFIG_KGDB) || defined(CONFIG_XMON) || defined(CONFIG_BDI_SWITCH) ||\ - defined(CONFIG_KPROBES) || defined(CONFIG_DYNAMIC_FTRACE) + defined(CONFIG_KPROBES) #define PAGE_KERNEL_TEXT PAGE_KERNEL_X #else #define PAGE_KERNEL_TEXT PAGE_KERNEL_ROX diff --git a/trunk/arch/powerpc/kernel/cputable.c b/trunk/arch/powerpc/kernel/cputable.c index b9602ee06deb..c9b68d07ac4f 100644 --- a/trunk/arch/powerpc/kernel/cputable.c +++ b/trunk/arch/powerpc/kernel/cputable.c @@ -1973,7 +1973,7 @@ static struct cpu_spec __initdata cpu_specs[] = { .pvr_mask = 0xffff0000, .pvr_value = 0x80240000, .cpu_name = "e5500", - .cpu_features = CPU_FTRS_E5500, + .cpu_features = CPU_FTRS_E500MC, .cpu_user_features = COMMON_USER_BOOKE, .mmu_features = MMU_FTR_TYPE_FSL_E | MMU_FTR_BIG_PHYS | MMU_FTR_USE_TLBILX, diff --git a/trunk/arch/powerpc/kernel/crash.c b/trunk/arch/powerpc/kernel/crash.c index 5b5e1f002a8e..3d3d416339dd 100644 --- a/trunk/arch/powerpc/kernel/crash.c +++ b/trunk/arch/powerpc/kernel/crash.c @@ -163,7 +163,7 @@ static void crash_kexec_prepare_cpus(int cpu) } /* wait for all the CPUs to hit real mode but timeout if they don't come in */ -#ifdef CONFIG_PPC_STD_MMU_64 +#if defined(CONFIG_PPC_STD_MMU_64) && defined(CONFIG_SMP) static void crash_kexec_wait_realmode(int cpu) { unsigned int msecs; @@ -188,7 +188,9 @@ static void crash_kexec_wait_realmode(int cpu) } mb(); } -#endif /* CONFIG_PPC_STD_MMU_64 */ +#else +static inline void crash_kexec_wait_realmode(int cpu) {} +#endif /* * This function will be called by secondary cpus or by kexec cpu @@ -233,9 +235,7 @@ void crash_kexec_secondary(struct pt_regs *regs) crash_ipi_callback(regs); } -#else /* ! CONFIG_SMP */ -static inline void crash_kexec_wait_realmode(int cpu) {} - +#else static void crash_kexec_prepare_cpus(int cpu) { /* @@ -255,7 +255,7 @@ void crash_kexec_secondary(struct pt_regs *regs) { cpus_in_sr = CPU_MASK_NONE; } -#endif /* CONFIG_SMP */ +#endif /* * Register a function to be called on shutdown. Only use this if you diff --git a/trunk/arch/powerpc/kernel/ibmebus.c b/trunk/arch/powerpc/kernel/ibmebus.c index 28581f1ad2c0..c00d4ca1ee15 100644 --- a/trunk/arch/powerpc/kernel/ibmebus.c +++ b/trunk/arch/powerpc/kernel/ibmebus.c @@ -527,7 +527,7 @@ static int ibmebus_bus_pm_resume_noirq(struct device *dev) #endif /* !CONFIG_SUSPEND */ -#ifdef CONFIG_HIBERNATE_CALLBACKS +#ifdef CONFIG_HIBERNATION static int ibmebus_bus_pm_freeze(struct device *dev) { @@ -665,7 +665,7 @@ static int ibmebus_bus_pm_restore_noirq(struct device *dev) return ret; } -#else /* !CONFIG_HIBERNATE_CALLBACKS */ +#else /* !CONFIG_HIBERNATION */ #define ibmebus_bus_pm_freeze NULL #define ibmebus_bus_pm_thaw NULL @@ -676,7 +676,7 @@ static int ibmebus_bus_pm_restore_noirq(struct device *dev) #define ibmebus_bus_pm_poweroff_noirq NULL #define ibmebus_bus_pm_restore_noirq NULL -#endif /* !CONFIG_HIBERNATE_CALLBACKS */ +#endif /* !CONFIG_HIBERNATION */ static struct dev_pm_ops ibmebus_bus_dev_pm_ops = { .prepare = ibmebus_bus_pm_prepare, diff --git a/trunk/arch/powerpc/kernel/legacy_serial.c b/trunk/arch/powerpc/kernel/legacy_serial.c index 2b97b80d6d7d..c834757bebc0 100644 --- a/trunk/arch/powerpc/kernel/legacy_serial.c +++ b/trunk/arch/powerpc/kernel/legacy_serial.c @@ -330,11 +330,9 @@ void __init find_legacy_serial_ports(void) if (!parent) continue; if (of_match_node(legacy_serial_parents, parent) != NULL) { - if (of_device_is_available(np)) { - index = add_legacy_soc_port(np, np); - if (index >= 0 && np == stdout) - legacy_serial_console = index; - } + index = add_legacy_soc_port(np, np); + if (index >= 0 && np == stdout) + legacy_serial_console = index; } of_node_put(parent); } diff --git a/trunk/arch/powerpc/kernel/perf_event.c b/trunk/arch/powerpc/kernel/perf_event.c index 822f63008ae1..c4063b7f49a0 100644 --- a/trunk/arch/powerpc/kernel/perf_event.c +++ b/trunk/arch/powerpc/kernel/perf_event.c @@ -398,25 +398,6 @@ static int check_excludes(struct perf_event **ctrs, unsigned int cflags[], return 0; } -static u64 check_and_compute_delta(u64 prev, u64 val) -{ - u64 delta = (val - prev) & 0xfffffffful; - - /* - * POWER7 can roll back counter values, if the new value is smaller - * than the previous value it will cause the delta and the counter to - * have bogus values unless we rolled a counter over. If a coutner is - * rolled back, it will be smaller, but within 256, which is the maximum - * number of events to rollback at once. If we dectect a rollback - * return 0. This can lead to a small lack of precision in the - * counters. - */ - if (prev > val && (prev - val) < 256) - delta = 0; - - return delta; -} - static void power_pmu_read(struct perf_event *event) { s64 val, delta, prev; @@ -435,11 +416,10 @@ static void power_pmu_read(struct perf_event *event) prev = local64_read(&event->hw.prev_count); barrier(); val = read_pmc(event->hw.idx); - delta = check_and_compute_delta(prev, val); - if (!delta) - return; } while (local64_cmpxchg(&event->hw.prev_count, prev, val) != prev); + /* The counters are only 32 bits wide */ + delta = (val - prev) & 0xfffffffful; local64_add(delta, &event->count); local64_sub(delta, &event->hw.period_left); } @@ -469,9 +449,8 @@ static void freeze_limited_counters(struct cpu_hw_events *cpuhw, val = (event->hw.idx == 5) ? pmc5 : pmc6; prev = local64_read(&event->hw.prev_count); event->hw.idx = 0; - delta = check_and_compute_delta(prev, val); - if (delta) - local64_add(delta, &event->count); + delta = (val - prev) & 0xfffffffful; + local64_add(delta, &event->count); } } @@ -479,16 +458,14 @@ static void thaw_limited_counters(struct cpu_hw_events *cpuhw, unsigned long pmc5, unsigned long pmc6) { struct perf_event *event; - u64 val, prev; + u64 val; int i; for (i = 0; i < cpuhw->n_limited; ++i) { event = cpuhw->limited_counter[i]; event->hw.idx = cpuhw->limited_hwidx[i]; val = (event->hw.idx == 5) ? pmc5 : pmc6; - prev = local64_read(&event->hw.prev_count); - if (check_and_compute_delta(prev, val)) - local64_set(&event->hw.prev_count, val); + local64_set(&event->hw.prev_count, val); perf_event_update_userpage(event); } } @@ -1220,7 +1197,7 @@ static void record_and_restart(struct perf_event *event, unsigned long val, /* we don't have to worry about interrupts here */ prev = local64_read(&event->hw.prev_count); - delta = check_and_compute_delta(prev, val); + delta = (val - prev) & 0xfffffffful; local64_add(delta, &event->count); /* diff --git a/trunk/arch/powerpc/kernel/time.c b/trunk/arch/powerpc/kernel/time.c index f33acfd872ad..375480c56eb9 100644 --- a/trunk/arch/powerpc/kernel/time.c +++ b/trunk/arch/powerpc/kernel/time.c @@ -229,9 +229,6 @@ static u64 scan_dispatch_log(u64 stop_tb) u64 stolen = 0; u64 dtb; - if (!dtl) - return 0; - if (i == vpa->dtl_idx) return 0; while (i < vpa->dtl_idx) { diff --git a/trunk/arch/powerpc/platforms/powermac/smp.c b/trunk/arch/powerpc/platforms/powermac/smp.c index bc5f0dc6ae1e..a830c5e80657 100644 --- a/trunk/arch/powerpc/platforms/powermac/smp.c +++ b/trunk/arch/powerpc/platforms/powermac/smp.c @@ -842,7 +842,6 @@ static void __devinit smp_core99_setup_cpu(int cpu_nr) mpic_setup_this_cpu(); } -#ifdef CONFIG_PPC64 #ifdef CONFIG_HOTPLUG_CPU static int smp_core99_cpu_notify(struct notifier_block *self, unsigned long action, void *hcpu) @@ -880,6 +879,7 @@ static struct notifier_block __cpuinitdata smp_core99_cpu_nb = { static void __init smp_core99_bringup_done(void) { +#ifdef CONFIG_PPC64 extern void g5_phy_disable_cpu1(void); /* Close i2c bus if it was used for tb sync */ @@ -894,14 +894,14 @@ static void __init smp_core99_bringup_done(void) set_cpu_present(1, false); g5_phy_disable_cpu1(); } +#endif /* CONFIG_PPC64 */ + #ifdef CONFIG_HOTPLUG_CPU register_cpu_notifier(&smp_core99_cpu_nb); #endif - if (ppc_md.progress) ppc_md.progress("smp_core99_bringup_done", 0x349); } -#endif /* CONFIG_PPC64 */ #ifdef CONFIG_HOTPLUG_CPU @@ -975,9 +975,7 @@ static void pmac_cpu_die(void) struct smp_ops_t core99_smp_ops = { .message_pass = smp_mpic_message_pass, .probe = smp_core99_probe, -#ifdef CONFIG_PPC64 .bringup_done = smp_core99_bringup_done, -#endif .kick_cpu = smp_core99_kick_cpu, .setup_cpu = smp_core99_setup_cpu, .give_timebase = smp_core99_give_timebase, diff --git a/trunk/arch/powerpc/platforms/pseries/setup.c b/trunk/arch/powerpc/platforms/pseries/setup.c index 6c42cfde8415..000724149089 100644 --- a/trunk/arch/powerpc/platforms/pseries/setup.c +++ b/trunk/arch/powerpc/platforms/pseries/setup.c @@ -287,22 +287,14 @@ static int alloc_dispatch_logs(void) int cpu, ret; struct paca_struct *pp; struct dtl_entry *dtl; - struct kmem_cache *dtl_cache; if (!firmware_has_feature(FW_FEATURE_SPLPAR)) return 0; - dtl_cache = kmem_cache_create("dtl", DISPATCH_LOG_BYTES, - DISPATCH_LOG_BYTES, 0, NULL); - if (!dtl_cache) { - pr_warn("Failed to create dispatch trace log buffer cache\n"); - pr_warn("Stolen time statistics will be unreliable\n"); - return 0; - } - for_each_possible_cpu(cpu) { pp = &paca[cpu]; - dtl = kmem_cache_alloc(dtl_cache, GFP_KERNEL); + dtl = kmalloc_node(DISPATCH_LOG_BYTES, GFP_KERNEL, + cpu_to_node(cpu)); if (!dtl) { pr_warn("Failed to allocate dispatch trace log for cpu %d\n", cpu); diff --git a/trunk/arch/powerpc/sysdev/fsl_pci.c b/trunk/arch/powerpc/sysdev/fsl_pci.c index 68ca9290df94..f8f7f28c6343 100644 --- a/trunk/arch/powerpc/sysdev/fsl_pci.c +++ b/trunk/arch/powerpc/sysdev/fsl_pci.c @@ -324,11 +324,6 @@ int __init fsl_add_bridge(struct device_node *dev, int is_primary) struct resource rsrc; const int *bus_range; - if (!of_device_is_available(dev)) { - pr_warning("%s: disabled\n", dev->full_name); - return -ENODEV; - } - pr_debug("Adding PCI host bridge %s\n", dev->full_name); /* Fetch host bridge registers address */ diff --git a/trunk/arch/powerpc/sysdev/fsl_rio.c b/trunk/arch/powerpc/sysdev/fsl_rio.c index 49798532b477..14232d57369c 100644 --- a/trunk/arch/powerpc/sysdev/fsl_rio.c +++ b/trunk/arch/powerpc/sysdev/fsl_rio.c @@ -1457,6 +1457,7 @@ int fsl_rio_setup(struct platform_device *dev) port->ops = ops; port->priv = priv; port->phys_efptr = 0x100; + rio_register_mport(port); priv->regs_win = ioremap(regs.start, regs.end - regs.start + 1); rio_regs_win = priv->regs_win; @@ -1503,9 +1504,6 @@ int fsl_rio_setup(struct platform_device *dev) dev_info(&dev->dev, "RapidIO Common Transport System size: %d\n", port->sys_size ? 65536 : 256); - if (rio_register_mport(port)) - goto err; - if (port->host_deviceid >= 0) out_be32(priv->regs_win + RIO_GCCSR, RIO_PORT_GEN_HOST | RIO_PORT_GEN_MASTER | RIO_PORT_GEN_DISCOVERED); diff --git a/trunk/arch/s390/kernel/head.S b/trunk/arch/s390/kernel/head.S index fb317bf2c378..7061398341d5 100644 --- a/trunk/arch/s390/kernel/head.S +++ b/trunk/arch/s390/kernel/head.S @@ -460,7 +460,7 @@ startup: #ifndef CONFIG_MARCH_G5 # check capabilities against MARCH_{G5,Z900,Z990,Z9_109,Z10} xc __LC_STFL_FAC_LIST(8),__LC_STFL_FAC_LIST - .insn s,0xb2b10000,__LC_STFL_FAC_LIST # store facility list + stfl __LC_STFL_FAC_LIST # store facility list tm __LC_STFL_FAC_LIST,0x01 # stfle available ? jz 0f la %r0,0 diff --git a/trunk/arch/s390/kernel/switch_cpu.S b/trunk/arch/s390/kernel/switch_cpu.S index 20530dd2eab1..469f11b574fa 100644 --- a/trunk/arch/s390/kernel/switch_cpu.S +++ b/trunk/arch/s390/kernel/switch_cpu.S @@ -46,9 +46,7 @@ smp_restart_cpu: ltr %r4,%r4 /* New stack ? */ jz 1f lr %r15,%r4 -1: lr %r14,%r2 /* r14: Function to call */ - lr %r2,%r3 /* r2 : Parameter for function*/ - basr %r14,%r14 /* Call function */ +1: basr %r14,%r2 .gprregs_addr: .long .gprregs diff --git a/trunk/arch/s390/kernel/switch_cpu64.S b/trunk/arch/s390/kernel/switch_cpu64.S index 5be3f43898f9..d94aacc898cb 100644 --- a/trunk/arch/s390/kernel/switch_cpu64.S +++ b/trunk/arch/s390/kernel/switch_cpu64.S @@ -42,9 +42,7 @@ smp_restart_cpu: ltgr %r4,%r4 /* New stack ? */ jz 1f lgr %r15,%r4 -1: lgr %r14,%r2 /* r14: Function to call */ - lgr %r2,%r3 /* r2 : Parameter for function*/ - basr %r14,%r14 /* Call function */ +1: basr %r14,%r2 .section .data,"aw",@progbits .gprregs: diff --git a/trunk/arch/s390/oprofile/hwsampler.c b/trunk/arch/s390/oprofile/hwsampler.c index 4952872d6f0a..3d48f4db246d 100644 --- a/trunk/arch/s390/oprofile/hwsampler.c +++ b/trunk/arch/s390/oprofile/hwsampler.c @@ -517,8 +517,12 @@ static int stop_sampling(int cpu) static int check_hardware_prerequisites(void) { - if (!test_facility(68)) + unsigned long long facility_bits[2]; + + memcpy(facility_bits, S390_lowcore.stfle_fac_list, 32); + if (!(facility_bits[1] & (1ULL << 59))) return -EOPNOTSUPP; + return 0; } /* diff --git a/trunk/arch/um/Kconfig.x86 b/trunk/arch/um/Kconfig.x86 index a9da516a5274..02fb017fed47 100644 --- a/trunk/arch/um/Kconfig.x86 +++ b/trunk/arch/um/Kconfig.x86 @@ -4,10 +4,6 @@ menu "UML-specific options" menu "Host processor type and features" -config CMPXCHG_LOCAL - bool - default n - source "arch/x86/Kconfig.cpu" endmenu diff --git a/trunk/arch/um/include/asm/bug.h b/trunk/arch/um/include/asm/bug.h deleted file mode 100644 index 9e33b864c359..000000000000 --- a/trunk/arch/um/include/asm/bug.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __UM_BUG_H -#define __UM_BUG_H - -#include - -#endif diff --git a/trunk/arch/x86/include/asm/msr-index.h b/trunk/arch/x86/include/asm/msr-index.h index 3cce71413d0b..fd5a1f365c95 100644 --- a/trunk/arch/x86/include/asm/msr-index.h +++ b/trunk/arch/x86/include/asm/msr-index.h @@ -96,15 +96,11 @@ #define MSR_IA32_MC0_ADDR 0x00000402 #define MSR_IA32_MC0_MISC 0x00000403 -#define MSR_AMD64_MC0_MASK 0xc0010044 - #define MSR_IA32_MCx_CTL(x) (MSR_IA32_MC0_CTL + 4*(x)) #define MSR_IA32_MCx_STATUS(x) (MSR_IA32_MC0_STATUS + 4*(x)) #define MSR_IA32_MCx_ADDR(x) (MSR_IA32_MC0_ADDR + 4*(x)) #define MSR_IA32_MCx_MISC(x) (MSR_IA32_MC0_MISC + 4*(x)) -#define MSR_AMD64_MCx_MASK(x) (MSR_AMD64_MC0_MASK + (x)) - /* These are consecutive and not in the normal 4er MCE bank block */ #define MSR_IA32_MC0_CTL2 0x00000280 #define MSR_IA32_MCx_CTL2(x) (MSR_IA32_MC0_CTL2 + (x)) diff --git a/trunk/arch/x86/kernel/cpu/amd.c b/trunk/arch/x86/kernel/cpu/amd.c index 3532d3bf8105..3ecece0217ef 100644 --- a/trunk/arch/x86/kernel/cpu/amd.c +++ b/trunk/arch/x86/kernel/cpu/amd.c @@ -615,25 +615,6 @@ static void __cpuinit init_amd(struct cpuinfo_x86 *c) /* As a rule processors have APIC timer running in deep C states */ if (c->x86 >= 0xf && !cpu_has_amd_erratum(amd_erratum_400)) set_cpu_cap(c, X86_FEATURE_ARAT); - - /* - * Disable GART TLB Walk Errors on Fam10h. We do this here - * because this is always needed when GART is enabled, even in a - * kernel which has no MCE support built in. - */ - if (c->x86 == 0x10) { - /* - * BIOS should disable GartTlbWlk Errors themself. If - * it doesn't do it here as suggested by the BKDG. - * - * Fixes: https://bugzilla.kernel.org/show_bug.cgi?id=33012 - */ - u64 mask; - - rdmsrl(MSR_AMD64_MCx_MASK(4), mask); - mask |= (1 << 10); - wrmsrl(MSR_AMD64_MCx_MASK(4), mask); - } } #ifdef CONFIG_X86_32 diff --git a/trunk/arch/x86/kernel/smpboot.c b/trunk/arch/x86/kernel/smpboot.c index 8ed8908cc9f7..c2871d3c71b6 100644 --- a/trunk/arch/x86/kernel/smpboot.c +++ b/trunk/arch/x86/kernel/smpboot.c @@ -312,26 +312,6 @@ void __cpuinit smp_store_cpu_info(int id) identify_secondary_cpu(c); } -static void __cpuinit check_cpu_siblings_on_same_node(int cpu1, int cpu2) -{ - int node1 = early_cpu_to_node(cpu1); - int node2 = early_cpu_to_node(cpu2); - - /* - * Our CPU scheduler assumes all logical cpus in the same physical cpu - * share the same node. But, buggy ACPI or NUMA emulation might assign - * them to different node. Fix it. - */ - if (node1 != node2) { - pr_warning("CPU %d in node %d and CPU %d in node %d are in the same physical CPU. forcing same node %d\n", - cpu1, node1, cpu2, node2, node2); - - numa_remove_cpu(cpu1); - numa_set_node(cpu1, node2); - numa_add_cpu(cpu1); - } -} - static void __cpuinit link_thread_siblings(int cpu1, int cpu2) { cpumask_set_cpu(cpu1, cpu_sibling_mask(cpu2)); @@ -340,7 +320,6 @@ static void __cpuinit link_thread_siblings(int cpu1, int cpu2) cpumask_set_cpu(cpu2, cpu_core_mask(cpu1)); cpumask_set_cpu(cpu1, cpu_llc_shared_mask(cpu2)); cpumask_set_cpu(cpu2, cpu_llc_shared_mask(cpu1)); - check_cpu_siblings_on_same_node(cpu1, cpu2); } @@ -382,12 +361,10 @@ void __cpuinit set_cpu_sibling_map(int cpu) per_cpu(cpu_llc_id, cpu) == per_cpu(cpu_llc_id, i)) { cpumask_set_cpu(i, cpu_llc_shared_mask(cpu)); cpumask_set_cpu(cpu, cpu_llc_shared_mask(i)); - check_cpu_siblings_on_same_node(cpu, i); } if (c->phys_proc_id == cpu_data(i).phys_proc_id) { cpumask_set_cpu(i, cpu_core_mask(cpu)); cpumask_set_cpu(cpu, cpu_core_mask(i)); - check_cpu_siblings_on_same_node(cpu, i); /* * Does this new cpu bringup a new core? */ diff --git a/trunk/arch/x86/platform/ce4100/falconfalls.dts b/trunk/arch/x86/platform/ce4100/falconfalls.dts index 2d6d226f2b10..dc701ea58546 100644 --- a/trunk/arch/x86/platform/ce4100/falconfalls.dts +++ b/trunk/arch/x86/platform/ce4100/falconfalls.dts @@ -74,7 +74,6 @@ compatible = "intel,ce4100-pci", "pci"; device_type = "pci"; bus-range = <1 1>; - reg = <0x0800 0x0 0x0 0x0 0x0>; ranges = <0x2000000 0 0xdffe0000 0x2000000 0 0xdffe0000 0 0x1000>; interrupt-parent = <&ioapic2>; @@ -413,7 +412,6 @@ #address-cells = <2>; #size-cells = <1>; compatible = "isa"; - reg = <0xf800 0x0 0x0 0x0 0x0>; ranges = <1 0 0 0 0 0x100>; rtc@70 { diff --git a/trunk/arch/x86/platform/mrst/mrst.c b/trunk/arch/x86/platform/mrst/mrst.c index 275dbc19e2cf..5c0207bf959b 100644 --- a/trunk/arch/x86/platform/mrst/mrst.c +++ b/trunk/arch/x86/platform/mrst/mrst.c @@ -97,11 +97,11 @@ static int __init sfi_parse_mtmr(struct sfi_table_header *table) pentry->freq_hz, pentry->irq); if (!pentry->irq) continue; - mp_irq.type = MP_INTSRC; + mp_irq.type = MP_IOAPIC; mp_irq.irqtype = mp_INT; /* triggering mode edge bit 2-3, active high polarity bit 0-1 */ mp_irq.irqflag = 5; - mp_irq.srcbus = MP_BUS_ISA; + mp_irq.srcbus = 0; mp_irq.srcbusirq = pentry->irq; /* IRQ */ mp_irq.dstapic = MP_APIC_ALL; mp_irq.dstirq = pentry->irq; @@ -168,10 +168,10 @@ int __init sfi_parse_mrtc(struct sfi_table_header *table) for (totallen = 0; totallen < sfi_mrtc_num; totallen++, pentry++) { pr_debug("RTC[%d]: paddr = 0x%08x, irq = %d\n", totallen, (u32)pentry->phys_addr, pentry->irq); - mp_irq.type = MP_INTSRC; + mp_irq.type = MP_IOAPIC; mp_irq.irqtype = mp_INT; mp_irq.irqflag = 0xf; /* level trigger and active low */ - mp_irq.srcbus = MP_BUS_ISA; + mp_irq.srcbus = 0; mp_irq.srcbusirq = pentry->irq; /* IRQ */ mp_irq.dstapic = MP_APIC_ALL; mp_irq.dstirq = pentry->irq; @@ -282,7 +282,7 @@ void __init x86_mrst_early_setup(void) /* Avoid searching for BIOS MP tables */ x86_init.mpparse.find_smp_config = x86_init_noop; x86_init.mpparse.get_smp_config = x86_init_uint_noop; - set_bit(MP_BUS_ISA, mp_bus_not_pci); + } /* diff --git a/trunk/arch/x86/xen/Kconfig b/trunk/arch/x86/xen/Kconfig index 5cc821cb2e09..1c7121ba18ff 100644 --- a/trunk/arch/x86/xen/Kconfig +++ b/trunk/arch/x86/xen/Kconfig @@ -39,7 +39,6 @@ config XEN_MAX_DOMAIN_MEMORY config XEN_SAVE_RESTORE bool depends on XEN - select HIBERNATE_CALLBACKS default y config XEN_DEBUG_FS diff --git a/trunk/arch/x86/xen/enlighten.c b/trunk/arch/x86/xen/enlighten.c index e3c6a06cf725..49dbd78ec3cb 100644 --- a/trunk/arch/x86/xen/enlighten.c +++ b/trunk/arch/x86/xen/enlighten.c @@ -238,7 +238,6 @@ static void xen_cpuid(unsigned int *ax, unsigned int *bx, static __init void xen_init_cpuid_mask(void) { unsigned int ax, bx, cx, dx; - unsigned int xsave_mask; cpuid_leaf1_edx_mask = ~((1 << X86_FEATURE_MCE) | /* disable MCE */ @@ -250,16 +249,24 @@ static __init void xen_init_cpuid_mask(void) cpuid_leaf1_edx_mask &= ~((1 << X86_FEATURE_APIC) | /* disable local APIC */ (1 << X86_FEATURE_ACPI)); /* disable ACPI */ + ax = 1; + cx = 0; xen_cpuid(&ax, &bx, &cx, &dx); - xsave_mask = - (1 << (X86_FEATURE_XSAVE % 32)) | - (1 << (X86_FEATURE_OSXSAVE % 32)); + /* cpuid claims we support xsave; try enabling it to see what happens */ + if (cx & (1 << (X86_FEATURE_XSAVE % 32))) { + unsigned long cr4; + + set_in_cr4(X86_CR4_OSXSAVE); + + cr4 = read_cr4(); - /* Xen will set CR4.OSXSAVE if supported and not disabled by force */ - if ((cx & xsave_mask) != xsave_mask) - cpuid_leaf1_ecx_mask &= ~xsave_mask; /* disable XSAVE & OSXSAVE */ + if ((cr4 & X86_CR4_OSXSAVE) == 0) + cpuid_leaf1_ecx_mask &= ~(1 << (X86_FEATURE_XSAVE % 32)); + + clear_in_cr4(X86_CR4_OSXSAVE); + } } static void xen_set_debugreg(int reg, unsigned long val) diff --git a/trunk/arch/x86/xen/mmu.c b/trunk/arch/x86/xen/mmu.c index a991b57f91fe..c82df6c9c0f0 100644 --- a/trunk/arch/x86/xen/mmu.c +++ b/trunk/arch/x86/xen/mmu.c @@ -565,13 +565,13 @@ pte_t xen_make_pte_debug(pteval_t pte) if (io_page && (xen_initial_domain() || addr >= ISA_END_ADDRESS)) { other_addr = pfn_to_mfn(addr >> PAGE_SHIFT) << PAGE_SHIFT; - WARN_ONCE(addr != other_addr, + WARN(addr != other_addr, "0x%lx is using VM_IO, but it is 0x%lx!\n", (unsigned long)addr, (unsigned long)other_addr); } else { pteval_t iomap_set = (_pte.pte & PTE_FLAGS_MASK) & _PAGE_IOMAP; other_addr = (_pte.pte & PTE_PFN_MASK); - WARN_ONCE((addr == other_addr) && (!io_page) && (!iomap_set), + WARN((addr == other_addr) && (!io_page) && (!iomap_set), "0x%lx is missing VM_IO (and wasn't fixed)!\n", (unsigned long)addr); } diff --git a/trunk/block/blk-core.c b/trunk/block/blk-core.c index 5fa3dd2705c6..90f22cc30799 100644 --- a/trunk/block/blk-core.c +++ b/trunk/block/blk-core.c @@ -198,13 +198,26 @@ void blk_dump_rq_flags(struct request *rq, char *msg) } EXPORT_SYMBOL(blk_dump_rq_flags); +/* + * Make sure that plugs that were pending when this function was entered, + * are now complete and requests pushed to the queue. +*/ +static inline void queue_sync_plugs(struct request_queue *q) +{ + /* + * If the current process is plugged and has barriers submitted, + * we will livelock if we don't unplug first. + */ + blk_flush_plug(current); +} + static void blk_delay_work(struct work_struct *work) { struct request_queue *q; q = container_of(work, struct request_queue, delay_work.work); spin_lock_irq(q->queue_lock); - __blk_run_queue(q); + __blk_run_queue(q, false); spin_unlock_irq(q->queue_lock); } @@ -220,8 +233,7 @@ static void blk_delay_work(struct work_struct *work) */ void blk_delay_queue(struct request_queue *q, unsigned long msecs) { - queue_delayed_work(kblockd_workqueue, &q->delay_work, - msecs_to_jiffies(msecs)); + schedule_delayed_work(&q->delay_work, msecs_to_jiffies(msecs)); } EXPORT_SYMBOL(blk_delay_queue); @@ -239,7 +251,7 @@ void blk_start_queue(struct request_queue *q) WARN_ON(!irqs_disabled()); queue_flag_clear(QUEUE_FLAG_STOPPED, q); - __blk_run_queue(q); + __blk_run_queue(q, false); } EXPORT_SYMBOL(blk_start_queue); @@ -286,6 +298,7 @@ void blk_sync_queue(struct request_queue *q) { del_timer_sync(&q->timeout); cancel_delayed_work_sync(&q->delay_work); + queue_sync_plugs(q); } EXPORT_SYMBOL(blk_sync_queue); @@ -297,8 +310,9 @@ EXPORT_SYMBOL(blk_sync_queue); * Description: * See @blk_run_queue. This variant must be called with the queue lock * held and interrupts disabled. + * */ -void __blk_run_queue(struct request_queue *q) +void __blk_run_queue(struct request_queue *q, bool force_kblockd) { if (unlikely(blk_queue_stopped(q))) return; @@ -307,7 +321,7 @@ void __blk_run_queue(struct request_queue *q) * Only recurse once to avoid overrunning the stack, let the unplug * handling reinvoke the handler shortly if we already got there. */ - if (!queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) { + if (!force_kblockd && !queue_flag_test_and_set(QUEUE_FLAG_REENTER, q)) { q->request_fn(q); queue_flag_clear(QUEUE_FLAG_REENTER, q); } else @@ -315,20 +329,6 @@ void __blk_run_queue(struct request_queue *q) } EXPORT_SYMBOL(__blk_run_queue); -/** - * blk_run_queue_async - run a single device queue in workqueue context - * @q: The queue to run - * - * Description: - * Tells kblockd to perform the equivalent of @blk_run_queue on behalf - * of us. - */ -void blk_run_queue_async(struct request_queue *q) -{ - if (likely(!blk_queue_stopped(q))) - queue_delayed_work(kblockd_workqueue, &q->delay_work, 0); -} - /** * blk_run_queue - run a single device queue * @q: The queue to run @@ -342,7 +342,7 @@ void blk_run_queue(struct request_queue *q) unsigned long flags; spin_lock_irqsave(q->queue_lock, flags); - __blk_run_queue(q); + __blk_run_queue(q, false); spin_unlock_irqrestore(q->queue_lock, flags); } EXPORT_SYMBOL(blk_run_queue); @@ -991,7 +991,7 @@ void blk_insert_request(struct request_queue *q, struct request *rq, blk_queue_end_tag(q, rq); add_acct_request(q, rq, where); - __blk_run_queue(q); + __blk_run_queue(q, false); spin_unlock_irqrestore(q->queue_lock, flags); } EXPORT_SYMBOL(blk_insert_request); @@ -1311,15 +1311,7 @@ static int __make_request(struct request_queue *q, struct bio *bio) plug = current->plug; if (plug) { - /* - * If this is the first request added after a plug, fire - * of a plug trace. If others have been added before, check - * if we have multiple devices in this plug. If so, make a - * note to sort the list before dispatch. - */ - if (list_empty(&plug->list)) - trace_block_plug(q); - else if (!plug->should_sort) { + if (!plug->should_sort && !list_empty(&plug->list)) { struct request *__rq; __rq = list_entry_rq(plug->list.prev); @@ -1335,7 +1327,7 @@ static int __make_request(struct request_queue *q, struct bio *bio) } else { spin_lock_irq(q->queue_lock); add_acct_request(q, req, where); - __blk_run_queue(q); + __blk_run_queue(q, false); out_unlock: spin_unlock_irq(q->queue_lock); } @@ -2652,7 +2644,6 @@ void blk_start_plug(struct blk_plug *plug) plug->magic = PLUG_MAGIC; INIT_LIST_HEAD(&plug->list); - INIT_LIST_HEAD(&plug->cb_list); plug->should_sort = 0; /* @@ -2677,93 +2668,33 @@ static int plug_rq_cmp(void *priv, struct list_head *a, struct list_head *b) return !(rqa->q <= rqb->q); } -/* - * If 'from_schedule' is true, then postpone the dispatch of requests - * until a safe kblockd context. We due this to avoid accidental big - * additional stack usage in driver dispatch, in places where the originally - * plugger did not intend it. - */ -static void queue_unplugged(struct request_queue *q, unsigned int depth, - bool from_schedule) - __releases(q->queue_lock) -{ - trace_block_unplug(q, depth, !from_schedule); - - /* - * If we are punting this to kblockd, then we can safely drop - * the queue_lock before waking kblockd (which needs to take - * this lock). - */ - if (from_schedule) { - spin_unlock(q->queue_lock); - blk_run_queue_async(q); - } else { - __blk_run_queue(q); - spin_unlock(q->queue_lock); - } - -} - -static void flush_plug_callbacks(struct blk_plug *plug) -{ - LIST_HEAD(callbacks); - - if (list_empty(&plug->cb_list)) - return; - - list_splice_init(&plug->cb_list, &callbacks); - - while (!list_empty(&callbacks)) { - struct blk_plug_cb *cb = list_first_entry(&callbacks, - struct blk_plug_cb, - list); - list_del(&cb->list); - cb->callback(cb); - } -} - -void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule) +static void flush_plug_list(struct blk_plug *plug) { struct request_queue *q; unsigned long flags; struct request *rq; - LIST_HEAD(list); - unsigned int depth; BUG_ON(plug->magic != PLUG_MAGIC); - flush_plug_callbacks(plug); if (list_empty(&plug->list)) return; - list_splice_init(&plug->list, &list); - - if (plug->should_sort) { - list_sort(NULL, &list, plug_rq_cmp); - plug->should_sort = 0; - } + if (plug->should_sort) + list_sort(NULL, &plug->list, plug_rq_cmp); q = NULL; - depth = 0; - - /* - * Save and disable interrupts here, to avoid doing it for every - * queue lock we have to take. - */ local_irq_save(flags); - while (!list_empty(&list)) { - rq = list_entry_rq(list.next); + while (!list_empty(&plug->list)) { + rq = list_entry_rq(plug->list.next); list_del_init(&rq->queuelist); BUG_ON(!(rq->cmd_flags & REQ_ON_PLUG)); BUG_ON(!rq->q); if (rq->q != q) { - /* - * This drops the queue lock - */ - if (q) - queue_unplugged(q, depth, from_schedule); + if (q) { + __blk_run_queue(q, false); + spin_unlock(q->queue_lock); + } q = rq->q; - depth = 0; spin_lock(q->queue_lock); } rq->cmd_flags &= ~REQ_ON_PLUG; @@ -2775,29 +2706,39 @@ void blk_flush_plug_list(struct blk_plug *plug, bool from_schedule) __elv_add_request(q, rq, ELEVATOR_INSERT_FLUSH); else __elv_add_request(q, rq, ELEVATOR_INSERT_SORT_MERGE); - - depth++; } - /* - * This drops the queue lock - */ - if (q) - queue_unplugged(q, depth, from_schedule); + if (q) { + __blk_run_queue(q, false); + spin_unlock(q->queue_lock); + } + BUG_ON(!list_empty(&plug->list)); local_irq_restore(flags); } -EXPORT_SYMBOL(blk_flush_plug_list); -void blk_finish_plug(struct blk_plug *plug) +static void __blk_finish_plug(struct task_struct *tsk, struct blk_plug *plug) { - blk_flush_plug_list(plug, false); + flush_plug_list(plug); - if (plug == current->plug) - current->plug = NULL; + if (plug == tsk->plug) + tsk->plug = NULL; +} + +void blk_finish_plug(struct blk_plug *plug) +{ + if (plug) + __blk_finish_plug(current, plug); } EXPORT_SYMBOL(blk_finish_plug); +void __blk_flush_plug(struct task_struct *tsk, struct blk_plug *plug) +{ + __blk_finish_plug(tsk, plug); + tsk->plug = plug; +} +EXPORT_SYMBOL(__blk_flush_plug); + int __init blk_dev_init(void) { BUILD_BUG_ON(__REQ_NR_BITS > 8 * diff --git a/trunk/block/blk-exec.c b/trunk/block/blk-exec.c index 81e31819a597..7482b7fa863b 100644 --- a/trunk/block/blk-exec.c +++ b/trunk/block/blk-exec.c @@ -55,7 +55,7 @@ void blk_execute_rq_nowait(struct request_queue *q, struct gendisk *bd_disk, WARN_ON(irqs_disabled()); spin_lock_irq(q->queue_lock); __elv_add_request(q, rq, where); - __blk_run_queue(q); + __blk_run_queue(q, false); /* the queue is stopped so it won't be plugged+unplugged */ if (rq->cmd_type == REQ_TYPE_PM_RESUME) q->request_fn(q); diff --git a/trunk/block/blk-flush.c b/trunk/block/blk-flush.c index 6c9b5e189e62..eba4a2790c6c 100644 --- a/trunk/block/blk-flush.c +++ b/trunk/block/blk-flush.c @@ -218,7 +218,7 @@ static void flush_end_io(struct request *flush_rq, int error) * request_fn may confuse the driver. Always use kblockd. */ if (queued) - blk_run_queue_async(q); + __blk_run_queue(q, true); } /** @@ -274,7 +274,7 @@ static void flush_data_end_io(struct request *rq, int error) * the comment in flush_end_io(). */ if (blk_flush_complete_seq(rq, REQ_FSEQ_DATA, error)) - blk_run_queue_async(q); + __blk_run_queue(q, true); } /** diff --git a/trunk/block/blk-sysfs.c b/trunk/block/blk-sysfs.c index 6d735122bc59..261c75c665ae 100644 --- a/trunk/block/blk-sysfs.c +++ b/trunk/block/blk-sysfs.c @@ -498,6 +498,7 @@ int blk_register_queue(struct gendisk *disk) { int ret; struct device *dev = disk_to_dev(disk); + struct request_queue *q = disk->queue; if (WARN_ON(!q)) @@ -520,7 +521,7 @@ int blk_register_queue(struct gendisk *disk) if (ret) { kobject_uevent(&q->kobj, KOBJ_REMOVE); kobject_del(&q->kobj); - blk_trace_remove_sysfs(dev); + blk_trace_remove_sysfs(disk_to_dev(disk)); kobject_put(&dev->kobj); return ret; } diff --git a/trunk/block/blk.h b/trunk/block/blk.h index c9df8fc3c999..61263463e38e 100644 --- a/trunk/block/blk.h +++ b/trunk/block/blk.h @@ -22,7 +22,6 @@ void blk_rq_timed_out_timer(unsigned long data); void blk_delete_timer(struct request *); void blk_add_timer(struct request *); void __generic_unplug_device(struct request_queue *); -void blk_run_queue_async(struct request_queue *q); /* * Internal atomic flags for request handling diff --git a/trunk/block/cfq-iosched.c b/trunk/block/cfq-iosched.c index 46b0a1d1d925..3be881ec95ad 100644 --- a/trunk/block/cfq-iosched.c +++ b/trunk/block/cfq-iosched.c @@ -3368,7 +3368,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq, cfqd->busy_queues > 1) { cfq_del_timer(cfqd, cfqq); cfq_clear_cfqq_wait_request(cfqq); - __blk_run_queue(cfqd->queue); + __blk_run_queue(cfqd->queue, false); } else { cfq_blkiocg_update_idle_time_stats( &cfqq->cfqg->blkg); @@ -3383,7 +3383,7 @@ cfq_rq_enqueued(struct cfq_data *cfqd, struct cfq_queue *cfqq, * this new queue is RT and the current one is BE */ cfq_preempt_queue(cfqd, cfqq); - __blk_run_queue(cfqd->queue); + __blk_run_queue(cfqd->queue, false); } } @@ -3743,7 +3743,7 @@ static void cfq_kick_queue(struct work_struct *work) struct request_queue *q = cfqd->queue; spin_lock_irq(q->queue_lock); - __blk_run_queue(cfqd->queue); + __blk_run_queue(cfqd->queue, false); spin_unlock_irq(q->queue_lock); } diff --git a/trunk/block/elevator.c b/trunk/block/elevator.c index 6f6abc08bb56..0cdb4e7ebab4 100644 --- a/trunk/block/elevator.c +++ b/trunk/block/elevator.c @@ -642,7 +642,7 @@ void elv_quiesce_start(struct request_queue *q) */ elv_drain_elevator(q); while (q->rq.elvpriv) { - __blk_run_queue(q); + __blk_run_queue(q, false); spin_unlock_irq(q->queue_lock); msleep(10); spin_lock_irq(q->queue_lock); @@ -695,7 +695,7 @@ void __elv_add_request(struct request_queue *q, struct request *rq, int where) * with anything. There's no point in delaying queue * processing. */ - __blk_run_queue(q); + __blk_run_queue(q, false); break; case ELEVATOR_INSERT_SORT_MERGE: diff --git a/trunk/drivers/amba/bus.c b/trunk/drivers/amba/bus.c index 7025593a58c8..821040503154 100644 --- a/trunk/drivers/amba/bus.c +++ b/trunk/drivers/amba/bus.c @@ -214,7 +214,7 @@ static int amba_pm_resume_noirq(struct device *dev) #endif /* !CONFIG_SUSPEND */ -#ifdef CONFIG_HIBERNATE_CALLBACKS +#ifdef CONFIG_HIBERNATION static int amba_pm_freeze(struct device *dev) { @@ -352,7 +352,7 @@ static int amba_pm_restore_noirq(struct device *dev) return ret; } -#else /* !CONFIG_HIBERNATE_CALLBACKS */ +#else /* !CONFIG_HIBERNATION */ #define amba_pm_freeze NULL #define amba_pm_thaw NULL @@ -363,7 +363,7 @@ static int amba_pm_restore_noirq(struct device *dev) #define amba_pm_poweroff_noirq NULL #define amba_pm_restore_noirq NULL -#endif /* !CONFIG_HIBERNATE_CALLBACKS */ +#endif /* !CONFIG_HIBERNATION */ #ifdef CONFIG_PM diff --git a/trunk/drivers/base/platform.c b/trunk/drivers/base/platform.c index 9e0e4fc24c46..f051cfff18af 100644 --- a/trunk/drivers/base/platform.c +++ b/trunk/drivers/base/platform.c @@ -149,7 +149,6 @@ static void platform_device_release(struct device *dev) of_device_node_put(&pa->pdev.dev); kfree(pa->pdev.dev.platform_data); - kfree(pa->pdev.mfd_cell); kfree(pa->pdev.resource); kfree(pa); } @@ -772,7 +771,7 @@ int __weak platform_pm_resume_noirq(struct device *dev) #endif /* !CONFIG_SUSPEND */ -#ifdef CONFIG_HIBERNATE_CALLBACKS +#ifdef CONFIG_HIBERNATION static int platform_pm_freeze(struct device *dev) { @@ -910,7 +909,7 @@ static int platform_pm_restore_noirq(struct device *dev) return ret; } -#else /* !CONFIG_HIBERNATE_CALLBACKS */ +#else /* !CONFIG_HIBERNATION */ #define platform_pm_freeze NULL #define platform_pm_thaw NULL @@ -921,7 +920,7 @@ static int platform_pm_restore_noirq(struct device *dev) #define platform_pm_poweroff_noirq NULL #define platform_pm_restore_noirq NULL -#endif /* !CONFIG_HIBERNATE_CALLBACKS */ +#endif /* !CONFIG_HIBERNATION */ #ifdef CONFIG_PM_RUNTIME diff --git a/trunk/drivers/base/power/main.c b/trunk/drivers/base/power/main.c index fbc5b6e7c591..052dc53eef38 100644 --- a/trunk/drivers/base/power/main.c +++ b/trunk/drivers/base/power/main.c @@ -233,7 +233,7 @@ static int pm_op(struct device *dev, } break; #endif /* CONFIG_SUSPEND */ -#ifdef CONFIG_HIBERNATE_CALLBACKS +#ifdef CONFIG_HIBERNATION case PM_EVENT_FREEZE: case PM_EVENT_QUIESCE: if (ops->freeze) { @@ -260,7 +260,7 @@ static int pm_op(struct device *dev, suspend_report_result(ops->restore, error); } break; -#endif /* CONFIG_HIBERNATE_CALLBACKS */ +#endif /* CONFIG_HIBERNATION */ default: error = -EINVAL; } @@ -308,7 +308,7 @@ static int pm_noirq_op(struct device *dev, } break; #endif /* CONFIG_SUSPEND */ -#ifdef CONFIG_HIBERNATE_CALLBACKS +#ifdef CONFIG_HIBERNATION case PM_EVENT_FREEZE: case PM_EVENT_QUIESCE: if (ops->freeze_noirq) { @@ -335,7 +335,7 @@ static int pm_noirq_op(struct device *dev, suspend_report_result(ops->restore_noirq, error); } break; -#endif /* CONFIG_HIBERNATE_CALLBACKS */ +#endif /* CONFIG_HIBERNATION */ default: error = -EINVAL; } diff --git a/trunk/drivers/dma/fsldma.c b/trunk/drivers/dma/fsldma.c index 8a781540590c..6b396759e7f5 100644 --- a/trunk/drivers/dma/fsldma.c +++ b/trunk/drivers/dma/fsldma.c @@ -1448,7 +1448,7 @@ static const struct of_device_id fsldma_of_ids[] = { {} }; -static struct platform_driver fsldma_of_driver = { +static struct of_platform_driver fsldma_of_driver = { .driver = { .name = "fsl-elo-dma", .owner = THIS_MODULE, diff --git a/trunk/drivers/gpio/ml_ioh_gpio.c b/trunk/drivers/gpio/ml_ioh_gpio.c index 0a775f7987c2..7f6f01a4b145 100644 --- a/trunk/drivers/gpio/ml_ioh_gpio.c +++ b/trunk/drivers/gpio/ml_ioh_gpio.c @@ -116,7 +116,6 @@ static int ioh_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, reg_val |= (1 << nr); else reg_val &= ~(1 << nr); - iowrite32(reg_val, &chip->reg->regs[chip->ch].po); mutex_unlock(&chip->lock); diff --git a/trunk/drivers/gpio/pca953x.c b/trunk/drivers/gpio/pca953x.c index 7630ab7b9bec..583e92592073 100644 --- a/trunk/drivers/gpio/pca953x.c +++ b/trunk/drivers/gpio/pca953x.c @@ -558,7 +558,7 @@ static int __devinit pca953x_probe(struct i2c_client *client, ret = gpiochip_add(&chip->gpio_chip); if (ret) - goto out_failed_irq; + goto out_failed; if (pdata->setup) { ret = pdata->setup(client, chip->gpio_chip.base, @@ -570,9 +570,8 @@ static int __devinit pca953x_probe(struct i2c_client *client, i2c_set_clientdata(client, chip); return 0; -out_failed_irq: - pca953x_irq_teardown(chip); out_failed: + pca953x_irq_teardown(chip); kfree(chip->dyn_pdata); kfree(chip); return ret; diff --git a/trunk/drivers/gpio/pch_gpio.c b/trunk/drivers/gpio/pch_gpio.c index f970a5f3585e..2c6af8705103 100644 --- a/trunk/drivers/gpio/pch_gpio.c +++ b/trunk/drivers/gpio/pch_gpio.c @@ -105,7 +105,6 @@ static int pch_gpio_direction_output(struct gpio_chip *gpio, unsigned nr, reg_val |= (1 << nr); else reg_val &= ~(1 << nr); - iowrite32(reg_val, &chip->reg->po); mutex_unlock(&chip->lock); diff --git a/trunk/drivers/gpu/drm/Kconfig b/trunk/drivers/gpu/drm/Kconfig index c58f691ec3ce..a6feb78c404c 100644 --- a/trunk/drivers/gpu/drm/Kconfig +++ b/trunk/drivers/gpu/drm/Kconfig @@ -96,7 +96,6 @@ config DRM_I915 # i915 depends on ACPI_VIDEO when ACPI is enabled # but for select to work, need to select ACPI_VIDEO's dependencies, ick select BACKLIGHT_CLASS_DEVICE if ACPI - select VIDEO_OUTPUT_CONTROL if ACPI select INPUT if ACPI select ACPI_VIDEO if ACPI select ACPI_BUTTON if ACPI diff --git a/trunk/drivers/gpu/drm/nouveau/nouveau_bios.c b/trunk/drivers/gpu/drm/nouveau/nouveau_bios.c index 90aef64b76f2..8314a49b6b9a 100644 --- a/trunk/drivers/gpu/drm/nouveau/nouveau_bios.c +++ b/trunk/drivers/gpu/drm/nouveau/nouveau_bios.c @@ -269,7 +269,7 @@ struct init_tbl_entry { int (*handler)(struct nvbios *, uint16_t, struct init_exec *); }; -static int parse_init_table(struct nvbios *, uint16_t, struct init_exec *); +static int parse_init_table(struct nvbios *, unsigned int, struct init_exec *); #define MACRO_INDEX_SIZE 2 #define MACRO_SIZE 8 @@ -2010,27 +2010,6 @@ init_sub_direct(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) return 3; } -static int -init_jump(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) -{ - /* - * INIT_JUMP opcode: 0x5C ('\') - * - * offset (8 bit): opcode - * offset + 1 (16 bit): offset (in bios) - * - * Continue execution of init table from 'offset' - */ - - uint16_t jmp_offset = ROM16(bios->data[offset + 1]); - - if (!iexec->execute) - return 3; - - BIOSLOG(bios, "0x%04X: Jump to 0x%04X\n", offset, jmp_offset); - return jmp_offset - offset; -} - static int init_i2c_if(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) { @@ -3680,7 +3659,6 @@ static struct init_tbl_entry itbl_entry[] = { { "INIT_ZM_REG_SEQUENCE" , 0x58, init_zm_reg_sequence }, /* INIT_INDIRECT_REG (0x5A, 7, 0, 0) removed due to no example of use */ { "INIT_SUB_DIRECT" , 0x5B, init_sub_direct }, - { "INIT_JUMP" , 0x5C, init_jump }, { "INIT_I2C_IF" , 0x5E, init_i2c_if }, { "INIT_COPY_NV_REG" , 0x5F, init_copy_nv_reg }, { "INIT_ZM_INDEX_IO" , 0x62, init_zm_index_io }, @@ -3722,7 +3700,8 @@ static struct init_tbl_entry itbl_entry[] = { #define MAX_TABLE_OPS 1000 static int -parse_init_table(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) +parse_init_table(struct nvbios *bios, unsigned int offset, + struct init_exec *iexec) { /* * Parses all commands in an init table. @@ -6354,32 +6333,6 @@ apply_dcb_encoder_quirks(struct drm_device *dev, int idx, u32 *conn, u32 *conf) } } - /* XFX GT-240X-YA - * - * So many things wrong here, replace the entire encoder table.. - */ - if (nv_match_device(dev, 0x0ca3, 0x1682, 0x3003)) { - if (idx == 0) { - *conn = 0x02001300; /* VGA, connector 1 */ - *conf = 0x00000028; - } else - if (idx == 1) { - *conn = 0x01010312; /* DVI, connector 0 */ - *conf = 0x00020030; - } else - if (idx == 2) { - *conn = 0x01010310; /* VGA, connector 0 */ - *conf = 0x00000028; - } else - if (idx == 3) { - *conn = 0x02022362; /* HDMI, connector 2 */ - *conf = 0x00020010; - } else { - *conn = 0x0000000e; /* EOL */ - *conf = 0x00000000; - } - } - return true; } diff --git a/trunk/drivers/gpu/drm/nouveau/nouveau_drv.h b/trunk/drivers/gpu/drm/nouveau/nouveau_drv.h index 856d56a98d1e..57e5302503db 100644 --- a/trunk/drivers/gpu/drm/nouveau/nouveau_drv.h +++ b/trunk/drivers/gpu/drm/nouveau/nouveau_drv.h @@ -1190,7 +1190,7 @@ extern int nv50_graph_load_context(struct nouveau_channel *); extern int nv50_graph_unload_context(struct drm_device *); extern int nv50_grctx_init(struct nouveau_grctx *); extern void nv50_graph_tlb_flush(struct drm_device *dev); -extern void nv84_graph_tlb_flush(struct drm_device *dev); +extern void nv86_graph_tlb_flush(struct drm_device *dev); extern struct nouveau_enum nv50_data_error_names[]; /* nvc0_graph.c */ diff --git a/trunk/drivers/gpu/drm/nouveau/nouveau_mem.c b/trunk/drivers/gpu/drm/nouveau/nouveau_mem.c index 78f467fe30be..2683377f4131 100644 --- a/trunk/drivers/gpu/drm/nouveau/nouveau_mem.c +++ b/trunk/drivers/gpu/drm/nouveau/nouveau_mem.c @@ -552,7 +552,6 @@ nouveau_mem_timing_init(struct drm_device *dev) u8 tRC; /* Byte 9 */ u8 tUNK_10, tUNK_11, tUNK_12, tUNK_13, tUNK_14; u8 tUNK_18, tUNK_19, tUNK_20, tUNK_21; - u8 magic_number = 0; /* Yeah... sorry*/ u8 *mem = NULL, *entry; int i, recordlen, entries; @@ -597,12 +596,6 @@ nouveau_mem_timing_init(struct drm_device *dev) if (!memtimings->timing) return; - /* Get "some number" from the timing reg for NV_40 - * Used in calculations later */ - if(dev_priv->card_type == NV_40) { - magic_number = (nv_rd32(dev,0x100228) & 0x0f000000) >> 24; - } - entry = mem + mem[1]; for (i = 0; i < entries; i++, entry += recordlen) { struct nouveau_pm_memtiming *timing = &pm->memtimings.timing[i]; @@ -642,51 +635,36 @@ nouveau_mem_timing_init(struct drm_device *dev) /* XXX: I don't trust the -1's and +1's... they must come * from somewhere! */ - timing->reg_100224 = (tUNK_0 + tUNK_19 + 1 + magic_number) << 24 | + timing->reg_100224 = ((tUNK_0 + tUNK_19 + 1) << 24 | tUNK_18 << 16 | - (tUNK_1 + tUNK_19 + 1 + magic_number) << 8; - if(dev_priv->chipset == 0xa8) { - timing->reg_100224 |= (tUNK_2 - 1); - } else { - timing->reg_100224 |= (tUNK_2 + 2 - magic_number); - } + (tUNK_1 + tUNK_19 + 1) << 8 | + (tUNK_2 - 1)); timing->reg_100228 = (tUNK_12 << 16 | tUNK_11 << 8 | tUNK_10); - if(dev_priv->chipset >= 0xa3 && dev_priv->chipset < 0xaa) { - timing->reg_100228 |= (tUNK_19 - 1) << 24; - } - - if(dev_priv->card_type == NV_40) { - /* NV40: don't know what the rest of the regs are.. - * And don't need to know either */ - timing->reg_100228 |= 0x20200000 | magic_number << 24; - } else if(dev_priv->card_type >= NV_50) { - /* XXX: reg_10022c */ - timing->reg_10022c = tUNK_2 - 1; - - timing->reg_100230 = (tUNK_20 << 24 | tUNK_21 << 16 | - tUNK_13 << 8 | tUNK_13); - - timing->reg_100234 = (tRAS << 24 | tRC); - timing->reg_100234 += max(tUNK_10,tUNK_11) << 16; - - if(dev_priv->chipset < 0xa3) { - timing->reg_100234 |= (tUNK_2 + 2) << 8; - } else { - /* XXX: +6? */ - timing->reg_100234 |= (tUNK_19 + 6) << 8; - } - - /* XXX; reg_100238, reg_10023c - * reg_100238: 0x00?????? - * reg_10023c: 0x!!??0202 for NV50+ cards (empirical evidence) */ + if(recordlen > 19) { + timing->reg_100228 += (tUNK_19 - 1) << 24; + }/* I cannot back-up this else-statement right now + else { + timing->reg_100228 += tUNK_12 << 24; + }*/ + + /* XXX: reg_10022c */ + timing->reg_10022c = tUNK_2 - 1; + + timing->reg_100230 = (tUNK_20 << 24 | tUNK_21 << 16 | + tUNK_13 << 8 | tUNK_13); + + /* XXX: +6? */ + timing->reg_100234 = (tRAS << 24 | (tUNK_19 + 6) << 8 | tRC); + timing->reg_100234 += max(tUNK_10,tUNK_11) << 16; + + /* XXX; reg_100238, reg_10023c + * reg: 0x00?????? + * reg_10023c: + * 0 for pre-NV50 cards + * 0x????0202 for NV50+ cards (empirical evidence) */ + if(dev_priv->card_type >= NV_50) { timing->reg_10023c = 0x202; - if(dev_priv->chipset < 0xa3) { - timing->reg_10023c |= 0x4000000 | (tUNK_2 - 1) << 16; - } else { - /* currently unknown - * 10023c seen as 06xxxxxx, 0bxxxxxx or 0fxxxxxx */ - } } NV_DEBUG(dev, "Entry %d: 220: %08x %08x %08x %08x\n", i, @@ -697,7 +675,7 @@ nouveau_mem_timing_init(struct drm_device *dev) timing->reg_100238, timing->reg_10023c); } - memtimings->nr_timing = entries; + memtimings->nr_timing = entries; memtimings->supported = true; } diff --git a/trunk/drivers/gpu/drm/nouveau/nouveau_perf.c b/trunk/drivers/gpu/drm/nouveau/nouveau_perf.c index 670e3cb697ec..ac62a1b8c4fc 100644 --- a/trunk/drivers/gpu/drm/nouveau/nouveau_perf.c +++ b/trunk/drivers/gpu/drm/nouveau/nouveau_perf.c @@ -134,7 +134,7 @@ nouveau_perf_init(struct drm_device *dev) case 0x13: case 0x15: perflvl->fanspeed = entry[55]; - perflvl->voltage = (recordlen > 56) ? entry[56] : 0; + perflvl->voltage = entry[56]; perflvl->core = ROM32(entry[1]) * 10; perflvl->memory = ROM32(entry[5]) * 20; break; diff --git a/trunk/drivers/gpu/drm/nouveau/nouveau_state.c b/trunk/drivers/gpu/drm/nouveau/nouveau_state.c index 6e2b1a6caa2d..5bb2859001e2 100644 --- a/trunk/drivers/gpu/drm/nouveau/nouveau_state.c +++ b/trunk/drivers/gpu/drm/nouveau/nouveau_state.c @@ -376,11 +376,15 @@ static int nouveau_init_engine_ptrs(struct drm_device *dev) engine->graph.destroy_context = nv50_graph_destroy_context; engine->graph.load_context = nv50_graph_load_context; engine->graph.unload_context = nv50_graph_unload_context; - if (dev_priv->chipset == 0x50 || - dev_priv->chipset == 0xac) + if (dev_priv->chipset != 0x86) engine->graph.tlb_flush = nv50_graph_tlb_flush; - else - engine->graph.tlb_flush = nv84_graph_tlb_flush; + else { + /* from what i can see nvidia do this on every + * pre-NVA3 board except NVAC, but, we've only + * ever seen problems on NV86 + */ + engine->graph.tlb_flush = nv86_graph_tlb_flush; + } engine->fifo.channels = 128; engine->fifo.init = nv50_fifo_init; engine->fifo.takedown = nv50_fifo_takedown; diff --git a/trunk/drivers/gpu/drm/nouveau/nv04_dfp.c b/trunk/drivers/gpu/drm/nouveau/nv04_dfp.c index 12098bf839c4..c82db37d9f41 100644 --- a/trunk/drivers/gpu/drm/nouveau/nv04_dfp.c +++ b/trunk/drivers/gpu/drm/nouveau/nv04_dfp.c @@ -581,13 +581,12 @@ static void nv04_dfp_restore(struct drm_encoder *encoder) int head = nv_encoder->restore.head; if (nv_encoder->dcb->type == OUTPUT_LVDS) { - struct nouveau_connector *connector = - nouveau_encoder_connector_get(nv_encoder); - - if (connector && connector->native_mode) - call_lvds_script(dev, nv_encoder->dcb, head, - LVDS_PANEL_ON, - connector->native_mode->clock); + struct drm_display_mode *native_mode = nouveau_encoder_connector_get(nv_encoder)->native_mode; + if (native_mode) + call_lvds_script(dev, nv_encoder->dcb, head, LVDS_PANEL_ON, + native_mode->clock); + else + NV_ERROR(dev, "Not restoring LVDS without native mode\n"); } else if (nv_encoder->dcb->type == OUTPUT_TMDS) { int clock = nouveau_hw_pllvals_to_clk diff --git a/trunk/drivers/gpu/drm/nouveau/nv50_crtc.c b/trunk/drivers/gpu/drm/nouveau/nv50_crtc.c index a19ccaa025b3..2b9984027f41 100644 --- a/trunk/drivers/gpu/drm/nouveau/nv50_crtc.c +++ b/trunk/drivers/gpu/drm/nouveau/nv50_crtc.c @@ -469,6 +469,9 @@ nv50_crtc_wait_complete(struct drm_crtc *crtc) start = ptimer->read(dev); do { + nv_wr32(dev, 0x61002c, 0x370); + nv_wr32(dev, 0x000140, 1); + if (nv_ro32(disp->ntfy, 0x000)) return 0; } while (ptimer->read(dev) - start < 2000000000ULL); diff --git a/trunk/drivers/gpu/drm/nouveau/nv50_evo.c b/trunk/drivers/gpu/drm/nouveau/nv50_evo.c index c8e83c1a4de8..a2cfaa691e9b 100644 --- a/trunk/drivers/gpu/drm/nouveau/nv50_evo.c +++ b/trunk/drivers/gpu/drm/nouveau/nv50_evo.c @@ -186,7 +186,6 @@ nv50_evo_channel_init(struct nouveau_channel *evo) nv_mask(dev, 0x610028, 0x00000000, 0x00010001 << id); evo->dma.max = (4096/4) - 2; - evo->dma.max &= ~7; evo->dma.put = 0; evo->dma.cur = evo->dma.put; evo->dma.free = evo->dma.max - evo->dma.cur; diff --git a/trunk/drivers/gpu/drm/nouveau/nv50_graph.c b/trunk/drivers/gpu/drm/nouveau/nv50_graph.c index b02a5b1e7d37..8675b00caf18 100644 --- a/trunk/drivers/gpu/drm/nouveau/nv50_graph.c +++ b/trunk/drivers/gpu/drm/nouveau/nv50_graph.c @@ -503,7 +503,7 @@ nv50_graph_tlb_flush(struct drm_device *dev) } void -nv84_graph_tlb_flush(struct drm_device *dev) +nv86_graph_tlb_flush(struct drm_device *dev) { struct drm_nouveau_private *dev_priv = dev->dev_private; struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer; diff --git a/trunk/drivers/gpu/drm/nouveau/nvc0_vm.c b/trunk/drivers/gpu/drm/nouveau/nvc0_vm.c index a0a2a0277f73..69af0ba7edd3 100644 --- a/trunk/drivers/gpu/drm/nouveau/nvc0_vm.c +++ b/trunk/drivers/gpu/drm/nouveau/nvc0_vm.c @@ -104,26 +104,20 @@ nvc0_vm_flush(struct nouveau_vm *vm) struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem; struct drm_device *dev = vm->dev; struct nouveau_vm_pgd *vpgd; - u32 engine = (dev_priv->chan_vm == vm) ? 1 : 5; + u32 r100c80, engine; pinstmem->flush(vm->dev); - spin_lock(&dev_priv->ramin_lock); + if (vm == dev_priv->chan_vm) + engine = 1; + else + engine = 5; + list_for_each_entry(vpgd, &vm->pgd_list, head) { - /* looks like maybe a "free flush slots" counter, the - * faster you write to 0x100cbc to more it decreases - */ - if (!nv_wait_ne(dev, 0x100c80, 0x00ff0000, 0x00000000)) { - NV_ERROR(dev, "vm timeout 0: 0x%08x %d\n", - nv_rd32(dev, 0x100c80), engine); - } + r100c80 = nv_rd32(dev, 0x100c80); nv_wr32(dev, 0x100cb8, vpgd->obj->vinst >> 8); nv_wr32(dev, 0x100cbc, 0x80000000 | engine); - /* wait for flush to be queued? */ - if (!nv_wait(dev, 0x100c80, 0x00008000, 0x00008000)) { - NV_ERROR(dev, "vm timeout 1: 0x%08x %d\n", - nv_rd32(dev, 0x100c80), engine); - } + if (!nv_wait(dev, 0x100c80, 0xffffffff, r100c80)) + NV_ERROR(dev, "vm flush timeout eng %d\n", engine); } - spin_unlock(&dev_priv->ramin_lock); } diff --git a/trunk/drivers/gpu/drm/radeon/atom.c b/trunk/drivers/gpu/drm/radeon/atom.c index d71d375149f8..258fa5e7a2d9 100644 --- a/trunk/drivers/gpu/drm/radeon/atom.c +++ b/trunk/drivers/gpu/drm/radeon/atom.c @@ -32,7 +32,6 @@ #include "atom.h" #include "atom-names.h" #include "atom-bits.h" -#include "radeon.h" #define ATOM_COND_ABOVE 0 #define ATOM_COND_ABOVEOREQUAL 1 @@ -102,9 +101,7 @@ static void debug_print_spaces(int n) static uint32_t atom_iio_execute(struct atom_context *ctx, int base, uint32_t index, uint32_t data) { - struct radeon_device *rdev = ctx->card->dev->dev_private; uint32_t temp = 0xCDCDCDCD; - while (1) switch (CU8(base)) { case ATOM_IIO_NOP: @@ -115,8 +112,7 @@ static uint32_t atom_iio_execute(struct atom_context *ctx, int base, base += 3; break; case ATOM_IIO_WRITE: - if (rdev->family == CHIP_RV515) - (void)ctx->card->ioreg_read(ctx->card, CU16(base + 1)); + (void)ctx->card->ioreg_read(ctx->card, CU16(base + 1)); ctx->card->ioreg_write(ctx->card, CU16(base + 1), temp); base += 3; break; diff --git a/trunk/drivers/gpu/drm/radeon/atombios_crtc.c b/trunk/drivers/gpu/drm/radeon/atombios_crtc.c index 9d516a8c4dfa..b41ec59c7100 100644 --- a/trunk/drivers/gpu/drm/radeon/atombios_crtc.c +++ b/trunk/drivers/gpu/drm/radeon/atombios_crtc.c @@ -531,12 +531,6 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc, pll->flags |= RADEON_PLL_PREFER_HIGH_FB_DIV; else pll->flags |= RADEON_PLL_PREFER_LOW_REF_DIV; - - if ((rdev->family == CHIP_R600) || - (rdev->family == CHIP_RV610) || - (rdev->family == CHIP_RV630) || - (rdev->family == CHIP_RV670)) - pll->flags |= RADEON_PLL_PREFER_MINM_OVER_MAXP; } else { pll->flags |= RADEON_PLL_LEGACY; diff --git a/trunk/drivers/gpu/drm/radeon/evergreen.c b/trunk/drivers/gpu/drm/radeon/evergreen.c index 3453910ee0f3..0b0cc74c08c0 100644 --- a/trunk/drivers/gpu/drm/radeon/evergreen.c +++ b/trunk/drivers/gpu/drm/radeon/evergreen.c @@ -120,16 +120,11 @@ void evergreen_pm_misc(struct radeon_device *rdev) struct radeon_power_state *ps = &rdev->pm.power_state[req_ps_idx]; struct radeon_voltage *voltage = &ps->clock_info[req_cm_idx].voltage; - if (voltage->type == VOLTAGE_SW) { - if (voltage->voltage && (voltage->voltage != rdev->pm.current_vddc)) { - radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC); + if ((voltage->type == VOLTAGE_SW) && voltage->voltage) { + if (voltage->voltage != rdev->pm.current_vddc) { + radeon_atom_set_voltage(rdev, voltage->voltage); rdev->pm.current_vddc = voltage->voltage; - DRM_DEBUG("Setting: vddc: %d\n", voltage->voltage); - } - if (voltage->vddci && (voltage->vddci != rdev->pm.current_vddci)) { - radeon_atom_set_voltage(rdev, voltage->vddci, SET_VOLTAGE_TYPE_ASIC_VDDCI); - rdev->pm.current_vddci = voltage->vddci; - DRM_DEBUG("Setting: vddci: %d\n", voltage->vddci); + DRM_DEBUG("Setting: v: %d\n", voltage->voltage); } } } @@ -3041,6 +3036,9 @@ int evergreen_init(struct radeon_device *rdev) { int r; + r = radeon_dummy_page_init(rdev); + if (r) + return r; /* This don't do much */ r = radeon_gem_init(rdev); if (r) @@ -3152,6 +3150,7 @@ void evergreen_fini(struct radeon_device *rdev) radeon_atombios_fini(rdev); kfree(rdev->bios); rdev->bios = NULL; + radeon_dummy_page_fini(rdev); } static void evergreen_pcie_gen2_enable(struct radeon_device *rdev) diff --git a/trunk/drivers/gpu/drm/radeon/r600.c b/trunk/drivers/gpu/drm/radeon/r600.c index 15d58292677a..be271c42de4d 100644 --- a/trunk/drivers/gpu/drm/radeon/r600.c +++ b/trunk/drivers/gpu/drm/radeon/r600.c @@ -587,7 +587,7 @@ void r600_pm_misc(struct radeon_device *rdev) if ((voltage->type == VOLTAGE_SW) && voltage->voltage) { if (voltage->voltage != rdev->pm.current_vddc) { - radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC); + radeon_atom_set_voltage(rdev, voltage->voltage); rdev->pm.current_vddc = voltage->voltage; DRM_DEBUG_DRIVER("Setting: v: %d\n", voltage->voltage); } @@ -2509,6 +2509,9 @@ int r600_init(struct radeon_device *rdev) { int r; + r = radeon_dummy_page_init(rdev); + if (r) + return r; if (r600_debugfs_mc_info_init(rdev)) { DRM_ERROR("Failed to register debugfs file for mc !\n"); } @@ -2622,6 +2625,7 @@ void r600_fini(struct radeon_device *rdev) radeon_atombios_fini(rdev); kfree(rdev->bios); rdev->bios = NULL; + radeon_dummy_page_fini(rdev); } diff --git a/trunk/drivers/gpu/drm/radeon/radeon.h b/trunk/drivers/gpu/drm/radeon/radeon.h index ba643b576054..93f536594c73 100644 --- a/trunk/drivers/gpu/drm/radeon/radeon.h +++ b/trunk/drivers/gpu/drm/radeon/radeon.h @@ -177,7 +177,7 @@ void radeon_pm_suspend(struct radeon_device *rdev); void radeon_pm_resume(struct radeon_device *rdev); void radeon_combios_get_power_modes(struct radeon_device *rdev); void radeon_atombios_get_power_modes(struct radeon_device *rdev); -void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type); +void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level); void rs690_pm_info(struct radeon_device *rdev); extern int rv6xx_get_temp(struct radeon_device *rdev); extern int rv770_get_temp(struct radeon_device *rdev); @@ -767,9 +767,7 @@ struct radeon_voltage { u8 vddci_id; /* index into vddci voltage table */ bool vddci_enabled; /* r6xx+ sw */ - u16 voltage; - /* evergreen+ vddci */ - u16 vddci; + u32 voltage; }; /* clock mode flags */ @@ -837,12 +835,10 @@ struct radeon_pm { int default_power_state_index; u32 current_sclk; u32 current_mclk; - u16 current_vddc; - u16 current_vddci; + u32 current_vddc; u32 default_sclk; u32 default_mclk; - u16 default_vddc; - u16 default_vddci; + u32 default_vddc; struct radeon_i2c_chan *i2c_bus; /* selected pm method */ enum radeon_pm_method pm_method; diff --git a/trunk/drivers/gpu/drm/radeon/radeon_asic.c b/trunk/drivers/gpu/drm/radeon/radeon_asic.c index ca576191d058..eb888ee5f674 100644 --- a/trunk/drivers/gpu/drm/radeon/radeon_asic.c +++ b/trunk/drivers/gpu/drm/radeon/radeon_asic.c @@ -94,7 +94,7 @@ static void radeon_register_accessor_init(struct radeon_device *rdev) rdev->mc_rreg = &rs600_mc_rreg; rdev->mc_wreg = &rs600_mc_wreg; } - if (rdev->family >= CHIP_R600) { + if ((rdev->family >= CHIP_R600) && (rdev->family <= CHIP_HEMLOCK)) { rdev->pciep_rreg = &r600_pciep_rreg; rdev->pciep_wreg = &r600_pciep_wreg; } diff --git a/trunk/drivers/gpu/drm/radeon/radeon_atombios.c b/trunk/drivers/gpu/drm/radeon/radeon_atombios.c index f5d12fb103fa..99768d9d91da 100644 --- a/trunk/drivers/gpu/drm/radeon/radeon_atombios.c +++ b/trunk/drivers/gpu/drm/radeon/radeon_atombios.c @@ -2176,27 +2176,24 @@ static void radeon_atombios_add_pplib_thermal_controller(struct radeon_device *r } } -static void radeon_atombios_get_default_voltages(struct radeon_device *rdev, - u16 *vddc, u16 *vddci) +static u16 radeon_atombios_get_default_vddc(struct radeon_device *rdev) { struct radeon_mode_info *mode_info = &rdev->mode_info; int index = GetIndexIntoMasterTable(DATA, FirmwareInfo); u8 frev, crev; u16 data_offset; union firmware_info *firmware_info; - - *vddc = 0; - *vddci = 0; + u16 vddc = 0; if (atom_parse_data_header(mode_info->atom_context, index, NULL, &frev, &crev, &data_offset)) { firmware_info = (union firmware_info *)(mode_info->atom_context->bios + data_offset); - *vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage); - if ((frev == 2) && (crev >= 2)) - *vddci = le16_to_cpu(firmware_info->info_22.usBootUpVDDCIVoltage); + vddc = le16_to_cpu(firmware_info->info_14.usBootUpVDDCVoltage); } + + return vddc; } static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rdev, @@ -2206,9 +2203,7 @@ static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rde int j; u32 misc = le32_to_cpu(non_clock_info->ulCapsAndSettings); u32 misc2 = le16_to_cpu(non_clock_info->usClassification); - u16 vddc, vddci; - - radeon_atombios_get_default_voltages(rdev, &vddc, &vddci); + u16 vddc = radeon_atombios_get_default_vddc(rdev); rdev->pm.power_state[state_index].misc = misc; rdev->pm.power_state[state_index].misc2 = misc2; @@ -2249,7 +2244,6 @@ static void radeon_atombios_parse_pplib_non_clock_info(struct radeon_device *rde rdev->pm.default_sclk = rdev->pm.power_state[state_index].clock_info[0].sclk; rdev->pm.default_mclk = rdev->pm.power_state[state_index].clock_info[0].mclk; rdev->pm.default_vddc = rdev->pm.power_state[state_index].clock_info[0].voltage.voltage; - rdev->pm.default_vddci = rdev->pm.power_state[state_index].clock_info[0].voltage.vddci; } else { /* patch the table values with the default slck/mclk from firmware info */ for (j = 0; j < mode_index; j++) { @@ -2292,8 +2286,6 @@ static bool radeon_atombios_parse_pplib_clock_info(struct radeon_device *rdev, VOLTAGE_SW; rdev->pm.power_state[state_index].clock_info[mode_index].voltage.voltage = le16_to_cpu(clock_info->evergreen.usVDDC); - rdev->pm.power_state[state_index].clock_info[mode_index].voltage.vddci = - le16_to_cpu(clock_info->evergreen.usVDDCI); } else { sclk = le16_to_cpu(clock_info->r600.usEngineClockLow); sclk |= clock_info->r600.ucEngineClockHigh << 16; @@ -2585,25 +2577,25 @@ union set_voltage { struct _SET_VOLTAGE_PARAMETERS_V2 v2; }; -void radeon_atom_set_voltage(struct radeon_device *rdev, u16 voltage_level, u8 voltage_type) +void radeon_atom_set_voltage(struct radeon_device *rdev, u16 level) { union set_voltage args; int index = GetIndexIntoMasterTable(COMMAND, SetVoltage); - u8 frev, crev, volt_index = voltage_level; + u8 frev, crev, volt_index = level; if (!atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev)) return; switch (crev) { case 1: - args.v1.ucVoltageType = voltage_type; + args.v1.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC; args.v1.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_ALL_SOURCE; args.v1.ucVoltageIndex = volt_index; break; case 2: - args.v2.ucVoltageType = voltage_type; + args.v2.ucVoltageType = SET_VOLTAGE_TYPE_ASIC_VDDC; args.v2.ucVoltageMode = SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE; - args.v2.usVoltageLevel = cpu_to_le16(voltage_level); + args.v2.usVoltageLevel = cpu_to_le16(level); break; default: DRM_ERROR("Unknown table version %d, %d\n", frev, crev); diff --git a/trunk/drivers/gpu/drm/radeon/radeon_fence.c b/trunk/drivers/gpu/drm/radeon/radeon_fence.c index bbcd1dd7bac0..9e59868d354e 100644 --- a/trunk/drivers/gpu/drm/radeon/radeon_fence.c +++ b/trunk/drivers/gpu/drm/radeon/radeon_fence.c @@ -79,7 +79,7 @@ static bool radeon_fence_poll_locked(struct radeon_device *rdev) scratch_index = R600_WB_EVENT_OFFSET + rdev->fence_drv.scratch_reg - rdev->scratch.reg_base; else scratch_index = RADEON_WB_SCRATCH_OFFSET + rdev->fence_drv.scratch_reg - rdev->scratch.reg_base; - seq = le32_to_cpu(rdev->wb.wb[scratch_index/4]); + seq = rdev->wb.wb[scratch_index/4]; } else seq = RREG32(rdev->fence_drv.scratch_reg); if (seq != rdev->fence_drv.last_seq) { diff --git a/trunk/drivers/gpu/drm/radeon/radeon_gart.c b/trunk/drivers/gpu/drm/radeon/radeon_gart.c index 8a955bbdb608..f0534ef2f331 100644 --- a/trunk/drivers/gpu/drm/radeon/radeon_gart.c +++ b/trunk/drivers/gpu/drm/radeon/radeon_gart.c @@ -285,6 +285,4 @@ void radeon_gart_fini(struct radeon_device *rdev) rdev->gart.pages = NULL; rdev->gart.pages_addr = NULL; rdev->gart.ttm_alloced = NULL; - - radeon_dummy_page_fini(rdev); } diff --git a/trunk/drivers/gpu/drm/radeon/radeon_i2c.c b/trunk/drivers/gpu/drm/radeon/radeon_i2c.c index ccbabf734a61..ded2a45bc95c 100644 --- a/trunk/drivers/gpu/drm/radeon/radeon_i2c.c +++ b/trunk/drivers/gpu/drm/radeon/radeon_i2c.c @@ -1062,7 +1062,7 @@ void radeon_i2c_get_byte(struct radeon_i2c_chan *i2c_bus, *val = in_buf[0]; DRM_DEBUG("val = 0x%02x\n", *val); } else { - DRM_DEBUG("i2c 0x%02x 0x%02x read failed\n", + DRM_ERROR("i2c 0x%02x 0x%02x read failed\n", addr, *val); } } @@ -1084,7 +1084,7 @@ void radeon_i2c_put_byte(struct radeon_i2c_chan *i2c_bus, out_buf[1] = val; if (i2c_transfer(&i2c_bus->adapter, &msg, 1) != 1) - DRM_DEBUG("i2c 0x%02x 0x%02x write failed\n", + DRM_ERROR("i2c 0x%02x 0x%02x write failed\n", addr, val); } diff --git a/trunk/drivers/gpu/drm/radeon/radeon_legacy_encoders.c b/trunk/drivers/gpu/drm/radeon/radeon_legacy_encoders.c index 2f46e0c8df53..5b54268ed6b2 100644 --- a/trunk/drivers/gpu/drm/radeon/radeon_legacy_encoders.c +++ b/trunk/drivers/gpu/drm/radeon/radeon_legacy_encoders.c @@ -269,7 +269,7 @@ static const struct drm_encoder_helper_funcs radeon_legacy_lvds_helper_funcs = { .disable = radeon_legacy_encoder_disable, }; -#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) +#ifdef CONFIG_BACKLIGHT_CLASS_DEVICE #define MAX_RADEON_LEVEL 0xFF diff --git a/trunk/drivers/gpu/drm/radeon/radeon_pm.c b/trunk/drivers/gpu/drm/radeon/radeon_pm.c index 86eda1ea94df..08de669e025a 100644 --- a/trunk/drivers/gpu/drm/radeon/radeon_pm.c +++ b/trunk/drivers/gpu/drm/radeon/radeon_pm.c @@ -23,7 +23,6 @@ #include "drmP.h" #include "radeon.h" #include "avivod.h" -#include "atom.h" #ifdef CONFIG_ACPI #include #endif @@ -536,11 +535,7 @@ void radeon_pm_resume(struct radeon_device *rdev) /* set up the default clocks if the MC ucode is loaded */ if (ASIC_IS_DCE5(rdev) && rdev->mc_fw) { if (rdev->pm.default_vddc) - radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, - SET_VOLTAGE_TYPE_ASIC_VDDC); - if (rdev->pm.default_vddci) - radeon_atom_set_voltage(rdev, rdev->pm.default_vddci, - SET_VOLTAGE_TYPE_ASIC_VDDCI); + radeon_atom_set_voltage(rdev, rdev->pm.default_vddc); if (rdev->pm.default_sclk) radeon_set_engine_clock(rdev, rdev->pm.default_sclk); if (rdev->pm.default_mclk) @@ -553,7 +548,6 @@ void radeon_pm_resume(struct radeon_device *rdev) rdev->pm.current_sclk = rdev->pm.default_sclk; rdev->pm.current_mclk = rdev->pm.default_mclk; rdev->pm.current_vddc = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.voltage; - rdev->pm.current_vddci = rdev->pm.power_state[rdev->pm.default_power_state_index].clock_info[0].voltage.vddci; if (rdev->pm.pm_method == PM_METHOD_DYNPM && rdev->pm.dynpm_state == DYNPM_STATE_SUSPENDED) { rdev->pm.dynpm_state = DYNPM_STATE_ACTIVE; @@ -591,8 +585,7 @@ int radeon_pm_init(struct radeon_device *rdev) /* set up the default clocks if the MC ucode is loaded */ if (ASIC_IS_DCE5(rdev) && rdev->mc_fw) { if (rdev->pm.default_vddc) - radeon_atom_set_voltage(rdev, rdev->pm.default_vddc, - SET_VOLTAGE_TYPE_ASIC_VDDC); + radeon_atom_set_voltage(rdev, rdev->pm.default_vddc); if (rdev->pm.default_sclk) radeon_set_engine_clock(rdev, rdev->pm.default_sclk); if (rdev->pm.default_mclk) diff --git a/trunk/drivers/gpu/drm/radeon/radeon_ring.c b/trunk/drivers/gpu/drm/radeon/radeon_ring.c index c6776e48fdde..bbc9cd823334 100644 --- a/trunk/drivers/gpu/drm/radeon/radeon_ring.c +++ b/trunk/drivers/gpu/drm/radeon/radeon_ring.c @@ -248,7 +248,7 @@ void radeon_ib_pool_fini(struct radeon_device *rdev) void radeon_ring_free_size(struct radeon_device *rdev) { if (rdev->wb.enabled) - rdev->cp.rptr = le32_to_cpu(rdev->wb.wb[RADEON_WB_CP_RPTR_OFFSET/4]); + rdev->cp.rptr = rdev->wb.wb[RADEON_WB_CP_RPTR_OFFSET/4]; else { if (rdev->family >= CHIP_R600) rdev->cp.rptr = RREG32(R600_CP_RB_RPTR); diff --git a/trunk/drivers/gpu/drm/radeon/rs600.c b/trunk/drivers/gpu/drm/radeon/rs600.c index 6e3b11e5abbe..876cebc4b8ba 100644 --- a/trunk/drivers/gpu/drm/radeon/rs600.c +++ b/trunk/drivers/gpu/drm/radeon/rs600.c @@ -114,7 +114,7 @@ void rs600_pm_misc(struct radeon_device *rdev) udelay(voltage->delay); } } else if (voltage->type == VOLTAGE_VDDC) - radeon_atom_set_voltage(rdev, voltage->vddc_id, SET_VOLTAGE_TYPE_ASIC_VDDC); + radeon_atom_set_voltage(rdev, voltage->vddc_id); dyn_pwrmgt_sclk_length = RREG32_PLL(DYN_PWRMGT_SCLK_LENGTH); dyn_pwrmgt_sclk_length &= ~REDUCED_POWER_SCLK_HILEN(0xf); diff --git a/trunk/drivers/gpu/drm/radeon/rv770.c b/trunk/drivers/gpu/drm/radeon/rv770.c index ef8a5babe9f7..b974ac7df8df 100644 --- a/trunk/drivers/gpu/drm/radeon/rv770.c +++ b/trunk/drivers/gpu/drm/radeon/rv770.c @@ -106,7 +106,7 @@ void rv770_pm_misc(struct radeon_device *rdev) if ((voltage->type == VOLTAGE_SW) && voltage->voltage) { if (voltage->voltage != rdev->pm.current_vddc) { - radeon_atom_set_voltage(rdev, voltage->voltage, SET_VOLTAGE_TYPE_ASIC_VDDC); + radeon_atom_set_voltage(rdev, voltage->voltage); rdev->pm.current_vddc = voltage->voltage; DRM_DEBUG("Setting: v: %d\n", voltage->voltage); } @@ -1255,6 +1255,9 @@ int rv770_init(struct radeon_device *rdev) { int r; + r = radeon_dummy_page_init(rdev); + if (r) + return r; /* This don't do much */ r = radeon_gem_init(rdev); if (r) @@ -1369,6 +1372,7 @@ void rv770_fini(struct radeon_device *rdev) radeon_atombios_fini(rdev); kfree(rdev->bios); rdev->bios = NULL; + radeon_dummy_page_fini(rdev); } static void rv770_pcie_gen2_enable(struct radeon_device *rdev) diff --git a/trunk/drivers/gpu/drm/ttm/ttm_page_alloc.c b/trunk/drivers/gpu/drm/ttm/ttm_page_alloc.c index 9d9d92945f8c..737a2a2e46a5 100644 --- a/trunk/drivers/gpu/drm/ttm/ttm_page_alloc.c +++ b/trunk/drivers/gpu/drm/ttm/ttm_page_alloc.c @@ -683,14 +683,22 @@ int ttm_get_pages(struct list_head *pages, int flags, gfp_flags |= GFP_HIGHUSER; for (r = 0; r < count; ++r) { - p = alloc_page(gfp_flags); + if ((flags & TTM_PAGE_FLAG_DMA32) && dma_address) { + void *addr; + addr = dma_alloc_coherent(NULL, PAGE_SIZE, + &dma_address[r], + gfp_flags); + if (addr == NULL) + return -ENOMEM; + p = virt_to_page(addr); + } else + p = alloc_page(gfp_flags); if (!p) { printk(KERN_ERR TTM_PFX "Unable to allocate page."); return -ENOMEM; } - list_add(&p->lru, pages); } return 0; @@ -738,12 +746,24 @@ void ttm_put_pages(struct list_head *pages, unsigned page_count, int flags, unsigned long irq_flags; struct ttm_page_pool *pool = ttm_get_pool(flags, cstate); struct page *p, *tmp; + unsigned r; if (pool == NULL) { /* No pool for this memory type so free the pages */ + r = page_count-1; list_for_each_entry_safe(p, tmp, pages, lru) { - __free_page(p); + if ((flags & TTM_PAGE_FLAG_DMA32) && dma_address) { + void *addr = page_address(p); + WARN_ON(!addr || !dma_address[r]); + if (addr) + dma_free_coherent(NULL, PAGE_SIZE, + addr, + dma_address[r]); + dma_address[r] = 0; + } else + __free_page(p); + r--; } /* Make the pages list empty */ INIT_LIST_HEAD(pages); diff --git a/trunk/drivers/gpu/stub/Kconfig b/trunk/drivers/gpu/stub/Kconfig index 419917955bf6..70e60a4bb678 100644 --- a/trunk/drivers/gpu/stub/Kconfig +++ b/trunk/drivers/gpu/stub/Kconfig @@ -5,7 +5,6 @@ config STUB_POULSBO # Poulsbo stub depends on ACPI_VIDEO when ACPI is enabled # but for select to work, need to select ACPI_VIDEO's dependencies, ick select BACKLIGHT_CLASS_DEVICE if ACPI - select VIDEO_OUTPUT_CONTROL if ACPI select INPUT if ACPI select ACPI_VIDEO if ACPI select THERMAL if ACPI diff --git a/trunk/drivers/i2c/algos/i2c-algo-bit.c b/trunk/drivers/i2c/algos/i2c-algo-bit.c index d6d58684712b..38319a69bd0a 100644 --- a/trunk/drivers/i2c/algos/i2c-algo-bit.c +++ b/trunk/drivers/i2c/algos/i2c-algo-bit.c @@ -232,17 +232,9 @@ static int i2c_inb(struct i2c_adapter *i2c_adap) * Sanity check for the adapter hardware - check the reaction of * the bus lines only if it seems to be idle. */ -static int test_bus(struct i2c_adapter *i2c_adap) +static int test_bus(struct i2c_algo_bit_data *adap, char *name) { - struct i2c_algo_bit_data *adap = i2c_adap->algo_data; - const char *name = i2c_adap->name; - int scl, sda, ret; - - if (adap->pre_xfer) { - ret = adap->pre_xfer(i2c_adap); - if (ret < 0) - return -ENODEV; - } + int scl, sda; if (adap->getscl == NULL) pr_info("%s: Testing SDA only, SCL is not readable\n", name); @@ -305,19 +297,11 @@ static int test_bus(struct i2c_adapter *i2c_adap) "while pulling SCL high!\n", name); goto bailout; } - - if (adap->post_xfer) - adap->post_xfer(i2c_adap); - pr_info("%s: Test OK\n", name); return 0; bailout: sdahi(adap); sclhi(adap); - - if (adap->post_xfer) - adap->post_xfer(i2c_adap); - return -ENODEV; } @@ -623,7 +607,7 @@ static int __i2c_bit_add_bus(struct i2c_adapter *adap, int ret; if (bit_test) { - ret = test_bus(adap); + ret = test_bus(bit_adap, adap->name); if (ret < 0) return -ENODEV; } diff --git a/trunk/drivers/i2c/i2c-core.c b/trunk/drivers/i2c/i2c-core.c index 9a58994ff7ea..70c30e6bce0b 100644 --- a/trunk/drivers/i2c/i2c-core.c +++ b/trunk/drivers/i2c/i2c-core.c @@ -797,8 +797,7 @@ static int i2c_do_add_adapter(struct i2c_driver *driver, /* Let legacy drivers scan this bus for matching devices */ if (driver->attach_adapter) { - dev_warn(&adap->dev, "%s: attach_adapter method is deprecated\n", - driver->driver.name); + dev_warn(&adap->dev, "attach_adapter method is deprecated\n"); dev_warn(&adap->dev, "Please use another way to instantiate " "your i2c_client\n"); /* We ignore the return code; if it fails, too bad */ @@ -985,8 +984,7 @@ static int i2c_do_del_adapter(struct i2c_driver *driver, if (!driver->detach_adapter) return 0; - dev_warn(&adapter->dev, "%s: detach_adapter method is deprecated\n", - driver->driver.name); + dev_warn(&adapter->dev, "detach_adapter method is deprecated\n"); res = driver->detach_adapter(adapter); if (res) dev_err(&adapter->dev, "detach_adapter failed (%d) " diff --git a/trunk/drivers/input/evdev.c b/trunk/drivers/input/evdev.c index 88d8e4cb419a..7f42d3a454d2 100644 --- a/trunk/drivers/input/evdev.c +++ b/trunk/drivers/input/evdev.c @@ -39,13 +39,13 @@ struct evdev { }; struct evdev_client { - unsigned int head; - unsigned int tail; + int head; + int tail; spinlock_t buffer_lock; /* protects access to buffer, head and tail */ struct fasync_struct *fasync; struct evdev *evdev; struct list_head node; - unsigned int bufsize; + int bufsize; struct input_event buffer[]; }; @@ -55,25 +55,16 @@ static DEFINE_MUTEX(evdev_table_mutex); static void evdev_pass_event(struct evdev_client *client, struct input_event *event) { - /* Interrupts are disabled, just acquire the lock. */ + /* + * Interrupts are disabled, just acquire the lock. + * Make sure we don't leave with the client buffer + * "empty" by having client->head == client->tail. + */ spin_lock(&client->buffer_lock); - - client->buffer[client->head++] = *event; - client->head &= client->bufsize - 1; - - if (unlikely(client->head == client->tail)) { - /* - * This effectively "drops" all unconsumed events, leaving - * EV_SYN/SYN_DROPPED plus the newest event in the queue. - */ - client->tail = (client->head - 2) & (client->bufsize - 1); - - client->buffer[client->tail].time = event->time; - client->buffer[client->tail].type = EV_SYN; - client->buffer[client->tail].code = SYN_DROPPED; - client->buffer[client->tail].value = 0; - } - + do { + client->buffer[client->head++] = *event; + client->head &= client->bufsize - 1; + } while (client->head == client->tail); spin_unlock(&client->buffer_lock); if (event->type == EV_SYN) diff --git a/trunk/drivers/input/input.c b/trunk/drivers/input/input.c index ebbceedc92f4..d6e8bd8a851c 100644 --- a/trunk/drivers/input/input.c +++ b/trunk/drivers/input/input.c @@ -1746,42 +1746,6 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int } EXPORT_SYMBOL(input_set_capability); -static unsigned int input_estimate_events_per_packet(struct input_dev *dev) -{ - int mt_slots; - int i; - unsigned int events; - - if (dev->mtsize) { - mt_slots = dev->mtsize; - } else if (test_bit(ABS_MT_TRACKING_ID, dev->absbit)) { - mt_slots = dev->absinfo[ABS_MT_TRACKING_ID].maximum - - dev->absinfo[ABS_MT_TRACKING_ID].minimum + 1, - clamp(mt_slots, 2, 32); - } else if (test_bit(ABS_MT_POSITION_X, dev->absbit)) { - mt_slots = 2; - } else { - mt_slots = 0; - } - - events = mt_slots + 1; /* count SYN_MT_REPORT and SYN_REPORT */ - - for (i = 0; i < ABS_CNT; i++) { - if (test_bit(i, dev->absbit)) { - if (input_is_mt_axis(i)) - events += mt_slots; - else - events++; - } - } - - for (i = 0; i < REL_CNT; i++) - if (test_bit(i, dev->relbit)) - events++; - - return events; -} - #define INPUT_CLEANSE_BITMASK(dev, type, bits) \ do { \ if (!test_bit(EV_##type, dev->evbit)) \ @@ -1829,10 +1793,6 @@ int input_register_device(struct input_dev *dev) /* Make sure that bitmasks not mentioned in dev->evbit are clean. */ input_cleanse_bitmasks(dev); - if (!dev->hint_events_per_packet) - dev->hint_events_per_packet = - input_estimate_events_per_packet(dev); - /* * If delay and period are pre-set by the driver, then autorepeating * is handled by the driver itself and we don't do it in input.c. diff --git a/trunk/drivers/input/keyboard/twl4030_keypad.c b/trunk/drivers/input/keyboard/twl4030_keypad.c index a26922cf0e84..09bef79d9da1 100644 --- a/trunk/drivers/input/keyboard/twl4030_keypad.c +++ b/trunk/drivers/input/keyboard/twl4030_keypad.c @@ -332,20 +332,18 @@ static int __devinit twl4030_kp_program(struct twl4030_keypad *kp) static int __devinit twl4030_kp_probe(struct platform_device *pdev) { struct twl4030_keypad_data *pdata = pdev->dev.platform_data; - const struct matrix_keymap_data *keymap_data; + const struct matrix_keymap_data *keymap_data = pdata->keymap_data; struct twl4030_keypad *kp; struct input_dev *input; u8 reg; int error; - if (!pdata || !pdata->rows || !pdata->cols || !pdata->keymap_data || + if (!pdata || !pdata->rows || !pdata->cols || pdata->rows > TWL4030_MAX_ROWS || pdata->cols > TWL4030_MAX_COLS) { dev_err(&pdev->dev, "Invalid platform_data\n"); return -EINVAL; } - keymap_data = pdata->keymap_data; - kp = kzalloc(sizeof(*kp), GFP_KERNEL); input = input_allocate_device(); if (!kp || !input) { diff --git a/trunk/drivers/input/misc/xen-kbdfront.c b/trunk/drivers/input/misc/xen-kbdfront.c index 62bae99424e6..7077f9bf5ead 100644 --- a/trunk/drivers/input/misc/xen-kbdfront.c +++ b/trunk/drivers/input/misc/xen-kbdfront.c @@ -303,7 +303,7 @@ static void xenkbd_backend_changed(struct xenbus_device *dev, enum xenbus_state backend_state) { struct xenkbd_info *info = dev_get_drvdata(&dev->dev); - int ret, val; + int val; switch (backend_state) { case XenbusStateInitialising: @@ -316,17 +316,6 @@ static void xenkbd_backend_changed(struct xenbus_device *dev, case XenbusStateInitWait: InitWait: - ret = xenbus_scanf(XBT_NIL, info->xbdev->otherend, - "feature-abs-pointer", "%d", &val); - if (ret < 0) - val = 0; - if (val) { - ret = xenbus_printf(XBT_NIL, info->xbdev->nodename, - "request-abs-pointer", "1"); - if (ret) - pr_warning("xenkbd: can't request abs-pointer"); - } - xenbus_switch_state(dev, XenbusStateConnected); break; diff --git a/trunk/drivers/input/touchscreen/h3600_ts_input.c b/trunk/drivers/input/touchscreen/h3600_ts_input.c index 45f93d0f5592..efa06882de00 100644 --- a/trunk/drivers/input/touchscreen/h3600_ts_input.c +++ b/trunk/drivers/input/touchscreen/h3600_ts_input.c @@ -399,34 +399,31 @@ static int h3600ts_connect(struct serio *serio, struct serio_driver *drv) IRQF_SHARED | IRQF_DISABLED, "h3600_action", &ts->dev)) { printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n"); err = -EBUSY; - goto fail1; + goto fail2; } if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler, IRQF_SHARED | IRQF_DISABLED, "h3600_suspend", &ts->dev)) { printk(KERN_ERR "h3600ts.c: Could not allocate Power Button IRQ!\n"); err = -EBUSY; - goto fail2; + goto fail3; } serio_set_drvdata(serio, ts); err = serio_open(serio, drv); if (err) - goto fail3; + return err; //h3600_flite_control(1, 25); /* default brightness */ - err = input_register_device(ts->dev); - if (err) - goto fail4; + input_register_device(ts->dev); return 0; -fail4: serio_close(serio); -fail3: serio_set_drvdata(serio, NULL); - free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts->dev); +fail3: free_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, ts->dev); fail2: free_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, ts->dev); -fail1: input_free_device(input_dev); +fail1: serio_set_drvdata(serio, NULL); + input_free_device(input_dev); kfree(ts); return err; } diff --git a/trunk/drivers/leds/leds-regulator.c b/trunk/drivers/leds/leds-regulator.c index 8497f56f8e46..3790816643be 100644 --- a/trunk/drivers/leds/leds-regulator.c +++ b/trunk/drivers/leds/leds-regulator.c @@ -178,10 +178,6 @@ static int __devinit regulator_led_probe(struct platform_device *pdev) led->cdev.flags |= LED_CORE_SUSPENDRESUME; led->vcc = vcc; - /* to handle correctly an already enabled regulator */ - if (regulator_is_enabled(led->vcc)) - led->enabled = 1; - mutex_init(&led->mutex); INIT_WORK(&led->work, led_work); diff --git a/trunk/drivers/md/dm-raid.c b/trunk/drivers/md/dm-raid.c index e5d8904fc8f6..5ef136cdba91 100644 --- a/trunk/drivers/md/dm-raid.c +++ b/trunk/drivers/md/dm-raid.c @@ -390,6 +390,13 @@ static int raid_is_congested(struct dm_target_callbacks *cb, int bits) return md_raid5_congested(&rs->md, bits); } +static void raid_unplug(struct dm_target_callbacks *cb) +{ + struct raid_set *rs = container_of(cb, struct raid_set, callbacks); + + md_raid5_kick_device(rs->md.private); +} + /* * Construct a RAID4/5/6 mapping: * Args: @@ -480,6 +487,7 @@ static int raid_ctr(struct dm_target *ti, unsigned argc, char **argv) } rs->callbacks.congested_fn = raid_is_congested; + rs->callbacks.unplug_fn = raid_unplug; dm_table_add_target_callbacks(ti->table, &rs->callbacks); return 0; diff --git a/trunk/drivers/md/md.c b/trunk/drivers/md/md.c index 6e853c61d87e..b12b3776c0c0 100644 --- a/trunk/drivers/md/md.c +++ b/trunk/drivers/md/md.c @@ -447,59 +447,48 @@ EXPORT_SYMBOL(md_flush_request); /* Support for plugging. * This mirrors the plugging support in request_queue, but does not - * require having a whole queue or request structures. - * We allocate an md_plug_cb for each md device and each thread it gets - * plugged on. This links tot the private plug_handle structure in the - * personality data where we keep a count of the number of outstanding - * plugs so other code can see if a plug is active. + * require having a whole queue */ -struct md_plug_cb { - struct blk_plug_cb cb; - mddev_t *mddev; -}; - -static void plugger_unplug(struct blk_plug_cb *cb) +static void plugger_work(struct work_struct *work) { - struct md_plug_cb *mdcb = container_of(cb, struct md_plug_cb, cb); - if (atomic_dec_and_test(&mdcb->mddev->plug_cnt)) - md_wakeup_thread(mdcb->mddev->thread); - kfree(mdcb); + struct plug_handle *plug = + container_of(work, struct plug_handle, unplug_work); + plug->unplug_fn(plug); } - -/* Check that an unplug wakeup will come shortly. - * If not, wakeup the md thread immediately - */ -int mddev_check_plugged(mddev_t *mddev) +static void plugger_timeout(unsigned long data) { - struct blk_plug *plug = current->plug; - struct md_plug_cb *mdcb; + struct plug_handle *plug = (void *)data; + kblockd_schedule_work(NULL, &plug->unplug_work); +} +void plugger_init(struct plug_handle *plug, + void (*unplug_fn)(struct plug_handle *)) +{ + plug->unplug_flag = 0; + plug->unplug_fn = unplug_fn; + init_timer(&plug->unplug_timer); + plug->unplug_timer.function = plugger_timeout; + plug->unplug_timer.data = (unsigned long)plug; + INIT_WORK(&plug->unplug_work, plugger_work); +} +EXPORT_SYMBOL_GPL(plugger_init); - if (!plug) - return 0; +void plugger_set_plug(struct plug_handle *plug) +{ + if (!test_and_set_bit(PLUGGED_FLAG, &plug->unplug_flag)) + mod_timer(&plug->unplug_timer, jiffies + msecs_to_jiffies(3)+1); +} +EXPORT_SYMBOL_GPL(plugger_set_plug); - list_for_each_entry(mdcb, &plug->cb_list, cb.list) { - if (mdcb->cb.callback == plugger_unplug && - mdcb->mddev == mddev) { - /* Already on the list, move to top */ - if (mdcb != list_first_entry(&plug->cb_list, - struct md_plug_cb, - cb.list)) - list_move(&mdcb->cb.list, &plug->cb_list); - return 1; - } - } - /* Not currently on the callback list */ - mdcb = kmalloc(sizeof(*mdcb), GFP_ATOMIC); - if (!mdcb) +int plugger_remove_plug(struct plug_handle *plug) +{ + if (test_and_clear_bit(PLUGGED_FLAG, &plug->unplug_flag)) { + del_timer(&plug->unplug_timer); + return 1; + } else return 0; - - mdcb->mddev = mddev; - mdcb->cb.callback = plugger_unplug; - atomic_inc(&mddev->plug_cnt); - list_add(&mdcb->cb.list, &plug->cb_list); - return 1; } -EXPORT_SYMBOL_GPL(mddev_check_plugged); +EXPORT_SYMBOL_GPL(plugger_remove_plug); + static inline mddev_t *mddev_get(mddev_t *mddev) { @@ -549,7 +538,6 @@ void mddev_init(mddev_t *mddev) atomic_set(&mddev->active, 1); atomic_set(&mddev->openers, 0); atomic_set(&mddev->active_io, 0); - atomic_set(&mddev->plug_cnt, 0); spin_lock_init(&mddev->write_lock); atomic_set(&mddev->flush_pending, 0); init_waitqueue_head(&mddev->sb_wait); @@ -4735,6 +4723,7 @@ static void md_clean(mddev_t *mddev) mddev->bitmap_info.chunksize = 0; mddev->bitmap_info.daemon_sleep = 0; mddev->bitmap_info.max_write_behind = 0; + mddev->plug = NULL; } static void __md_stop_writes(mddev_t *mddev) @@ -6699,6 +6688,12 @@ int md_allow_write(mddev_t *mddev) } EXPORT_SYMBOL_GPL(md_allow_write); +void md_unplug(mddev_t *mddev) +{ + if (mddev->plug) + mddev->plug->unplug_fn(mddev->plug); +} + #define SYNC_MARKS 10 #define SYNC_MARK_STEP (3*HZ) void md_do_sync(mddev_t *mddev) diff --git a/trunk/drivers/md/md.h b/trunk/drivers/md/md.h index 0b1fd3f1d85b..52b407369e13 100644 --- a/trunk/drivers/md/md.h +++ b/trunk/drivers/md/md.h @@ -29,6 +29,26 @@ typedef struct mddev_s mddev_t; typedef struct mdk_rdev_s mdk_rdev_t; +/* generic plugging support - like that provided with request_queue, + * but does not require a request_queue + */ +struct plug_handle { + void (*unplug_fn)(struct plug_handle *); + struct timer_list unplug_timer; + struct work_struct unplug_work; + unsigned long unplug_flag; +}; +#define PLUGGED_FLAG 1 +void plugger_init(struct plug_handle *plug, + void (*unplug_fn)(struct plug_handle *)); +void plugger_set_plug(struct plug_handle *plug); +int plugger_remove_plug(struct plug_handle *plug); +static inline void plugger_flush(struct plug_handle *plug) +{ + del_timer_sync(&plug->unplug_timer); + cancel_work_sync(&plug->unplug_work); +} + /* * MD's 'extended' device */ @@ -179,9 +199,6 @@ struct mddev_s int delta_disks, new_level, new_layout; int new_chunk_sectors; - atomic_t plug_cnt; /* If device is expecting - * more bios soon. - */ struct mdk_thread_s *thread; /* management thread */ struct mdk_thread_s *sync_thread; /* doing resync or reconstruct */ sector_t curr_resync; /* last block scheduled */ @@ -319,6 +336,7 @@ struct mddev_s struct list_head all_mddevs; struct attribute_group *to_remove; + struct plug_handle *plug; /* if used by personality */ struct bio_set *bio_set; @@ -498,6 +516,7 @@ extern int md_integrity_register(mddev_t *mddev); extern void md_integrity_add_rdev(mdk_rdev_t *rdev, mddev_t *mddev); extern int strict_strtoul_scaled(const char *cp, unsigned long *res, int scale); extern void restore_bitmap_write_access(struct file *file); +extern void md_unplug(mddev_t *mddev); extern void mddev_init(mddev_t *mddev); extern int md_run(mddev_t *mddev); @@ -511,5 +530,4 @@ extern struct bio *bio_clone_mddev(struct bio *bio, gfp_t gfp_mask, mddev_t *mddev); extern struct bio *bio_alloc_mddev(gfp_t gfp_mask, int nr_iovecs, mddev_t *mddev); -extern int mddev_check_plugged(mddev_t *mddev); #endif /* _MD_MD_H */ diff --git a/trunk/drivers/md/raid1.c b/trunk/drivers/md/raid1.c index 2b7a7ff401dc..c2a21ae56d97 100644 --- a/trunk/drivers/md/raid1.c +++ b/trunk/drivers/md/raid1.c @@ -565,6 +565,12 @@ static void flush_pending_writes(conf_t *conf) spin_unlock_irq(&conf->device_lock); } +static void md_kick_device(mddev_t *mddev) +{ + blk_flush_plug(current); + md_wakeup_thread(mddev->thread); +} + /* Barriers.... * Sometimes we need to suspend IO while we do something else, * either some resync/recovery, or reconfigure the array. @@ -594,7 +600,7 @@ static void raise_barrier(conf_t *conf) /* Wait until no block IO is waiting */ wait_event_lock_irq(conf->wait_barrier, !conf->nr_waiting, - conf->resync_lock, ); + conf->resync_lock, md_kick_device(conf->mddev)); /* block any new IO from starting */ conf->barrier++; @@ -602,7 +608,7 @@ static void raise_barrier(conf_t *conf) /* Now wait for all pending IO to complete */ wait_event_lock_irq(conf->wait_barrier, !conf->nr_pending && conf->barrier < RESYNC_DEPTH, - conf->resync_lock, ); + conf->resync_lock, md_kick_device(conf->mddev)); spin_unlock_irq(&conf->resync_lock); } @@ -624,7 +630,7 @@ static void wait_barrier(conf_t *conf) conf->nr_waiting++; wait_event_lock_irq(conf->wait_barrier, !conf->barrier, conf->resync_lock, - ); + md_kick_device(conf->mddev)); conf->nr_waiting--; } conf->nr_pending++; @@ -660,7 +666,8 @@ static void freeze_array(conf_t *conf) wait_event_lock_irq(conf->wait_barrier, conf->nr_pending == conf->nr_queued+1, conf->resync_lock, - flush_pending_writes(conf)); + ({ flush_pending_writes(conf); + md_kick_device(conf->mddev); })); spin_unlock_irq(&conf->resync_lock); } static void unfreeze_array(conf_t *conf) @@ -722,7 +729,6 @@ static int make_request(mddev_t *mddev, struct bio * bio) const unsigned long do_sync = (bio->bi_rw & REQ_SYNC); const unsigned long do_flush_fua = (bio->bi_rw & (REQ_FLUSH | REQ_FUA)); mdk_rdev_t *blocked_rdev; - int plugged; /* * Register the new request and wait if the reconstruction @@ -814,8 +820,6 @@ static int make_request(mddev_t *mddev, struct bio * bio) * inc refcount on their rdev. Record them by setting * bios[x] to bio */ - plugged = mddev_check_plugged(mddev); - disks = conf->raid_disks; retry_write: blocked_rdev = NULL; @@ -921,7 +925,7 @@ static int make_request(mddev_t *mddev, struct bio * bio) /* In case raid1d snuck in to freeze_array */ wake_up(&conf->wait_barrier); - if (do_sync || !bitmap || !plugged) + if (do_sync || !bitmap) md_wakeup_thread(mddev->thread); return 0; @@ -1512,16 +1516,13 @@ static void raid1d(mddev_t *mddev) conf_t *conf = mddev->private; struct list_head *head = &conf->retry_list; mdk_rdev_t *rdev; - struct blk_plug plug; md_check_recovery(mddev); - - blk_start_plug(&plug); + for (;;) { char b[BDEVNAME_SIZE]; - if (atomic_read(&mddev->plug_cnt) == 0) - flush_pending_writes(conf); + flush_pending_writes(conf); spin_lock_irqsave(&conf->device_lock, flags); if (list_empty(head)) { @@ -1592,7 +1593,6 @@ static void raid1d(mddev_t *mddev) } cond_resched(); } - blk_finish_plug(&plug); } @@ -2039,6 +2039,7 @@ static int stop(mddev_t *mddev) md_unregister_thread(mddev->thread); mddev->thread = NULL; + blk_sync_queue(mddev->queue); /* the unplug fn references 'conf'*/ if (conf->r1bio_pool) mempool_destroy(conf->r1bio_pool); kfree(conf->mirrors); diff --git a/trunk/drivers/md/raid10.c b/trunk/drivers/md/raid10.c index 8e9462626ec5..2da83d566592 100644 --- a/trunk/drivers/md/raid10.c +++ b/trunk/drivers/md/raid10.c @@ -634,6 +634,12 @@ static void flush_pending_writes(conf_t *conf) spin_unlock_irq(&conf->device_lock); } +static void md_kick_device(mddev_t *mddev) +{ + blk_flush_plug(current); + md_wakeup_thread(mddev->thread); +} + /* Barriers.... * Sometimes we need to suspend IO while we do something else, * either some resync/recovery, or reconfigure the array. @@ -663,15 +669,15 @@ static void raise_barrier(conf_t *conf, int force) /* Wait until no block IO is waiting (unless 'force') */ wait_event_lock_irq(conf->wait_barrier, force || !conf->nr_waiting, - conf->resync_lock, ); + conf->resync_lock, md_kick_device(conf->mddev)); /* block any new IO from starting */ conf->barrier++; - /* Now wait for all pending IO to complete */ + /* No wait for all pending IO to complete */ wait_event_lock_irq(conf->wait_barrier, !conf->nr_pending && conf->barrier < RESYNC_DEPTH, - conf->resync_lock, ); + conf->resync_lock, md_kick_device(conf->mddev)); spin_unlock_irq(&conf->resync_lock); } @@ -692,7 +698,7 @@ static void wait_barrier(conf_t *conf) conf->nr_waiting++; wait_event_lock_irq(conf->wait_barrier, !conf->barrier, conf->resync_lock, - ); + md_kick_device(conf->mddev)); conf->nr_waiting--; } conf->nr_pending++; @@ -728,8 +734,8 @@ static void freeze_array(conf_t *conf) wait_event_lock_irq(conf->wait_barrier, conf->nr_pending == conf->nr_queued+1, conf->resync_lock, - flush_pending_writes(conf)); - + ({ flush_pending_writes(conf); + md_kick_device(conf->mddev); })); spin_unlock_irq(&conf->resync_lock); } @@ -756,7 +762,6 @@ static int make_request(mddev_t *mddev, struct bio * bio) const unsigned long do_fua = (bio->bi_rw & REQ_FUA); unsigned long flags; mdk_rdev_t *blocked_rdev; - int plugged; if (unlikely(bio->bi_rw & REQ_FLUSH)) { md_flush_request(mddev, bio); @@ -865,8 +870,6 @@ static int make_request(mddev_t *mddev, struct bio * bio) * inc refcount on their rdev. Record them by setting * bios[x] to bio */ - plugged = mddev_check_plugged(mddev); - raid10_find_phys(conf, r10_bio); retry_write: blocked_rdev = NULL; @@ -943,8 +946,9 @@ static int make_request(mddev_t *mddev, struct bio * bio) /* In case raid10d snuck in to freeze_array */ wake_up(&conf->wait_barrier); - if (do_sync || !mddev->bitmap || !plugged) + if (do_sync || !mddev->bitmap) md_wakeup_thread(mddev->thread); + return 0; } @@ -1636,11 +1640,9 @@ static void raid10d(mddev_t *mddev) conf_t *conf = mddev->private; struct list_head *head = &conf->retry_list; mdk_rdev_t *rdev; - struct blk_plug plug; md_check_recovery(mddev); - blk_start_plug(&plug); for (;;) { char b[BDEVNAME_SIZE]; @@ -1714,7 +1716,6 @@ static void raid10d(mddev_t *mddev) } cond_resched(); } - blk_finish_plug(&plug); } diff --git a/trunk/drivers/md/raid5.c b/trunk/drivers/md/raid5.c index f301e6ae220c..e867ee42b152 100644 --- a/trunk/drivers/md/raid5.c +++ b/trunk/drivers/md/raid5.c @@ -27,12 +27,12 @@ * * We group bitmap updates into batches. Each batch has a number. * We may write out several batches at once, but that isn't very important. - * conf->seq_write is the number of the last batch successfully written. - * conf->seq_flush is the number of the last batch that was closed to + * conf->bm_write is the number of the last batch successfully written. + * conf->bm_flush is the number of the last batch that was closed to * new additions. * When we discover that we will need to write to any block in a stripe * (in add_stripe_bio) we update the in-memory bitmap and record in sh->bm_seq - * the number of the batch it will be in. This is seq_flush+1. + * the number of the batch it will be in. This is bm_flush+1. * When we are ready to do a write, if that batch hasn't been written yet, * we plug the array and queue the stripe for later. * When an unplug happens, we increment bm_flush, thus closing the current @@ -199,12 +199,14 @@ static void __release_stripe(raid5_conf_t *conf, struct stripe_head *sh) BUG_ON(!list_empty(&sh->lru)); BUG_ON(atomic_read(&conf->active_stripes)==0); if (test_bit(STRIPE_HANDLE, &sh->state)) { - if (test_bit(STRIPE_DELAYED, &sh->state)) + if (test_bit(STRIPE_DELAYED, &sh->state)) { list_add_tail(&sh->lru, &conf->delayed_list); - else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && - sh->bm_seq - conf->seq_write > 0) + plugger_set_plug(&conf->plug); + } else if (test_bit(STRIPE_BIT_DELAY, &sh->state) && + sh->bm_seq - conf->seq_write > 0) { list_add_tail(&sh->lru, &conf->bitmap_list); - else { + plugger_set_plug(&conf->plug); + } else { clear_bit(STRIPE_BIT_DELAY, &sh->state); list_add_tail(&sh->lru, &conf->handle_list); } @@ -459,7 +461,7 @@ get_active_stripe(raid5_conf_t *conf, sector_t sector, < (conf->max_nr_stripes *3/4) || !conf->inactive_blocked), conf->device_lock, - ); + md_raid5_kick_device(conf)); conf->inactive_blocked = 0; } else init_stripe(sh, sector, previous); @@ -1468,7 +1470,7 @@ static int resize_stripes(raid5_conf_t *conf, int newsize) wait_event_lock_irq(conf->wait_for_stripe, !list_empty(&conf->inactive_list), conf->device_lock, - ); + blk_flush_plug(current)); osh = get_free_stripe(conf); spin_unlock_irq(&conf->device_lock); atomic_set(&nsh->count, 1); @@ -3621,7 +3623,8 @@ static void raid5_activate_delayed(raid5_conf_t *conf) atomic_inc(&conf->preread_active_stripes); list_add_tail(&sh->lru, &conf->hold_list); } - } + } else + plugger_set_plug(&conf->plug); } static void activate_bit_delay(raid5_conf_t *conf) @@ -3638,6 +3641,21 @@ static void activate_bit_delay(raid5_conf_t *conf) } } +void md_raid5_kick_device(raid5_conf_t *conf) +{ + blk_flush_plug(current); + raid5_activate_delayed(conf); + md_wakeup_thread(conf->mddev->thread); +} +EXPORT_SYMBOL_GPL(md_raid5_kick_device); + +static void raid5_unplug(struct plug_handle *plug) +{ + raid5_conf_t *conf = container_of(plug, raid5_conf_t, plug); + + md_raid5_kick_device(conf); +} + int md_raid5_congested(mddev_t *mddev, int bits) { raid5_conf_t *conf = mddev->private; @@ -3927,7 +3945,6 @@ static int make_request(mddev_t *mddev, struct bio * bi) struct stripe_head *sh; const int rw = bio_data_dir(bi); int remaining; - int plugged; if (unlikely(bi->bi_rw & REQ_FLUSH)) { md_flush_request(mddev, bi); @@ -3946,7 +3963,6 @@ static int make_request(mddev_t *mddev, struct bio * bi) bi->bi_next = NULL; bi->bi_phys_segments = 1; /* over-loaded to count active stripes */ - plugged = mddev_check_plugged(mddev); for (;logical_sector < last_sector; logical_sector += STRIPE_SECTORS) { DEFINE_WAIT(w); int disks, data_disks; @@ -4041,7 +4057,7 @@ static int make_request(mddev_t *mddev, struct bio * bi) * add failed due to overlap. Flush everything * and wait a while */ - md_wakeup_thread(mddev->thread); + md_raid5_kick_device(conf); release_stripe(sh); schedule(); goto retry; @@ -4061,9 +4077,6 @@ static int make_request(mddev_t *mddev, struct bio * bi) } } - if (!plugged) - md_wakeup_thread(mddev->thread); - spin_lock_irq(&conf->device_lock); remaining = raid5_dec_bi_phys_segments(bi); spin_unlock_irq(&conf->device_lock); @@ -4465,30 +4478,24 @@ static void raid5d(mddev_t *mddev) struct stripe_head *sh; raid5_conf_t *conf = mddev->private; int handled; - struct blk_plug plug; pr_debug("+++ raid5d active\n"); md_check_recovery(mddev); - blk_start_plug(&plug); handled = 0; spin_lock_irq(&conf->device_lock); while (1) { struct bio *bio; - if (atomic_read(&mddev->plug_cnt) == 0 && - !list_empty(&conf->bitmap_list)) { - /* Now is a good time to flush some bitmap updates */ - conf->seq_flush++; + if (conf->seq_flush != conf->seq_write) { + int seq = conf->seq_flush; spin_unlock_irq(&conf->device_lock); bitmap_unplug(mddev->bitmap); spin_lock_irq(&conf->device_lock); - conf->seq_write = conf->seq_flush; + conf->seq_write = seq; activate_bit_delay(conf); } - if (atomic_read(&mddev->plug_cnt) == 0) - raid5_activate_delayed(conf); while ((bio = remove_bio_from_retry(conf))) { int ok; @@ -4518,7 +4525,6 @@ static void raid5d(mddev_t *mddev) spin_unlock_irq(&conf->device_lock); async_tx_issue_pending_all(); - blk_finish_plug(&plug); pr_debug("--- raid5d inactive\n"); } @@ -5135,6 +5141,8 @@ static int run(mddev_t *mddev) mdname(mddev)); md_set_array_sectors(mddev, raid5_size(mddev, 0, 0)); + plugger_init(&conf->plug, raid5_unplug); + mddev->plug = &conf->plug; if (mddev->queue) { int chunk_size; /* read-ahead size must cover two whole stripes, which @@ -5184,6 +5192,7 @@ static int stop(mddev_t *mddev) mddev->thread = NULL; if (mddev->queue) mddev->queue->backing_dev_info.congested_fn = NULL; + plugger_flush(&conf->plug); /* the unplug fn references 'conf'*/ free_conf(conf); mddev->private = NULL; mddev->to_remove = &raid5_attrs_group; diff --git a/trunk/drivers/md/raid5.h b/trunk/drivers/md/raid5.h index 3ca77a2613ba..8d563a4f022a 100644 --- a/trunk/drivers/md/raid5.h +++ b/trunk/drivers/md/raid5.h @@ -400,6 +400,8 @@ struct raid5_private_data { * Cleared when a sync completes. */ + struct plug_handle plug; + /* per cpu variables */ struct raid5_percpu { struct page *spare_page; /* Used when checking P/Q in raid6 */ diff --git a/trunk/drivers/mfd/mfd-core.c b/trunk/drivers/mfd/mfd-core.c index f4c8c844b913..d01574d98870 100644 --- a/trunk/drivers/mfd/mfd-core.c +++ b/trunk/drivers/mfd/mfd-core.c @@ -55,19 +55,6 @@ int mfd_cell_disable(struct platform_device *pdev) } EXPORT_SYMBOL(mfd_cell_disable); -static int mfd_platform_add_cell(struct platform_device *pdev, - const struct mfd_cell *cell) -{ - if (!cell) - return 0; - - pdev->mfd_cell = kmemdup(cell, sizeof(*cell), GFP_KERNEL); - if (!pdev->mfd_cell) - return -ENOMEM; - - return 0; -} - static int mfd_add_device(struct device *parent, int id, const struct mfd_cell *cell, struct resource *mem_base, @@ -88,7 +75,7 @@ static int mfd_add_device(struct device *parent, int id, pdev->dev.parent = parent; - ret = mfd_platform_add_cell(pdev, cell); + ret = platform_device_add_data(pdev, cell, sizeof(*cell)); if (ret) goto fail_res; @@ -136,6 +123,7 @@ static int mfd_add_device(struct device *parent, int id, return 0; +/* platform_device_del(pdev); */ fail_res: kfree(res); fail_device: diff --git a/trunk/drivers/misc/sgi-gru/grufile.c b/trunk/drivers/misc/sgi-gru/grufile.c index ecafa4ba238b..20e4e9395b61 100644 --- a/trunk/drivers/misc/sgi-gru/grufile.c +++ b/trunk/drivers/misc/sgi-gru/grufile.c @@ -348,15 +348,15 @@ static unsigned long gru_chiplet_cpu_to_mmr(int chiplet, int cpu, int *corep) static int gru_irq_count[GRU_CHIPLETS_PER_BLADE]; -static void gru_noop(struct irq_data *d) +static void gru_noop(unsigned int irq) { } static struct irq_chip gru_chip[GRU_CHIPLETS_PER_BLADE] = { [0 ... GRU_CHIPLETS_PER_BLADE - 1] { - .irq_mask = gru_noop, - .irq_unmask = gru_noop, - .irq_ack = gru_noop + .mask = gru_noop, + .unmask = gru_noop, + .ack = gru_noop } }; diff --git a/trunk/drivers/mtd/mtdswap.c b/trunk/drivers/mtd/mtdswap.c index fed215c4cfa1..237913c5c92c 100644 --- a/trunk/drivers/mtd/mtdswap.c +++ b/trunk/drivers/mtd/mtdswap.c @@ -1452,7 +1452,7 @@ static void mtdswap_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) oinfo = mtd->ecclayout; if (!mtd->oobsize || !oinfo || oinfo->oobavail < MTDSWAP_OOBSIZE) { printk(KERN_ERR "%s: Not enough free bytes in OOB, " - "%d available, %zu needed.\n", + "%d available, %lu needed.\n", MTDSWAP_PREFIX, oinfo->oobavail, MTDSWAP_OOBSIZE); return; } diff --git a/trunk/drivers/mtd/nand/atmel_nand.c b/trunk/drivers/mtd/nand/atmel_nand.c index 950646aa4c4b..6fae04b3fc6d 100644 --- a/trunk/drivers/mtd/nand/atmel_nand.c +++ b/trunk/drivers/mtd/nand/atmel_nand.c @@ -209,8 +209,22 @@ static int atmel_nand_dma_op(struct mtd_info *mtd, void *buf, int len, int err = -EIO; enum dma_data_direction dir = is_read ? DMA_FROM_DEVICE : DMA_TO_DEVICE; - if (buf >= high_memory) - goto err_buf; + if (buf >= high_memory) { + struct page *pg; + + if (((size_t)buf & PAGE_MASK) != + ((size_t)(buf + len - 1) & PAGE_MASK)) { + dev_warn(host->dev, "Buffer not fit in one page\n"); + goto err_buf; + } + + pg = vmalloc_to_page(buf); + if (pg == 0) { + dev_err(host->dev, "Failed to vmalloc_to_page\n"); + goto err_buf; + } + p = page_address(pg) + ((size_t)buf & ~PAGE_MASK); + } dma_dev = host->dma_chan->device; @@ -266,8 +280,7 @@ static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len) struct nand_chip *chip = mtd->priv; struct atmel_nand_host *host = chip->priv; - if (use_dma && len > mtd->oobsize) - /* only use DMA for bigger than oob size: better performances */ + if (use_dma && len >= mtd->oobsize) if (atmel_nand_dma_op(mtd, buf, len, 1) == 0) return; @@ -282,8 +295,7 @@ static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len) struct nand_chip *chip = mtd->priv; struct atmel_nand_host *host = chip->priv; - if (use_dma && len > mtd->oobsize) - /* only use DMA for bigger than oob size: better performances */ + if (use_dma && len >= mtd->oobsize) if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0) return; @@ -587,10 +599,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev) nand_chip->options |= NAND_USE_FLASH_BBT; } - if (!cpu_has_dma()) - use_dma = 0; - - if (use_dma) { + if (cpu_has_dma() && use_dma) { dma_cap_mask_t mask; dma_cap_zero(mask); @@ -602,8 +611,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev) } } if (use_dma) - dev_info(host->dev, "Using %s for DMA transfers.\n", - dma_chan_name(host->dma_chan)); + dev_info(host->dev, "Using DMA for NAND access.\n"); else dev_info(host->dev, "No DMA support for NAND access.\n"); diff --git a/trunk/drivers/net/benet/be.h b/trunk/drivers/net/benet/be.h index 66823eded7a3..f803c58b941d 100644 --- a/trunk/drivers/net/benet/be.h +++ b/trunk/drivers/net/benet/be.h @@ -154,7 +154,7 @@ struct be_eq_obj { u16 min_eqd; /* in usecs */ u16 max_eqd; /* in usecs */ u16 cur_eqd; /* in usecs */ - u8 eq_idx; + u8 msix_vec_idx; struct napi_struct napi; }; @@ -291,7 +291,7 @@ struct be_adapter { u32 num_rx_qs; u32 big_page_size; /* Compounded page size shared by rx wrbs */ - u8 eq_next_idx; + u8 msix_vec_next_idx; struct be_drv_stats drv_stats; struct vlan_group *vlan_grp; diff --git a/trunk/drivers/net/benet/be_main.c b/trunk/drivers/net/benet/be_main.c index 7cb5a114c733..9a54c8b24ff9 100644 --- a/trunk/drivers/net/benet/be_main.c +++ b/trunk/drivers/net/benet/be_main.c @@ -1497,7 +1497,7 @@ static int be_tx_queues_create(struct be_adapter *adapter) if (be_cmd_eq_create(adapter, eq, adapter->tx_eq.cur_eqd)) goto tx_eq_free; - adapter->tx_eq.eq_idx = adapter->eq_next_idx++; + adapter->tx_eq.msix_vec_idx = adapter->msix_vec_next_idx++; /* Alloc TX eth compl queue */ @@ -1590,7 +1590,7 @@ static int be_rx_queues_create(struct be_adapter *adapter) if (rc) goto err; - rxo->rx_eq.eq_idx = adapter->eq_next_idx++; + rxo->rx_eq.msix_vec_idx = adapter->msix_vec_next_idx++; /* CQ */ cq = &rxo->cq; @@ -1666,11 +1666,11 @@ static irqreturn_t be_intx(int irq, void *dev) if (!isr) return IRQ_NONE; - if ((1 << adapter->tx_eq.eq_idx & isr)) + if ((1 << adapter->tx_eq.msix_vec_idx & isr)) event_handle(adapter, &adapter->tx_eq); for_all_rx_queues(adapter, rxo, i) { - if ((1 << rxo->rx_eq.eq_idx & isr)) + if ((1 << rxo->rx_eq.msix_vec_idx & isr)) event_handle(adapter, &rxo->rx_eq); } } @@ -1951,7 +1951,7 @@ static void be_sriov_disable(struct be_adapter *adapter) static inline int be_msix_vec_get(struct be_adapter *adapter, struct be_eq_obj *eq_obj) { - return adapter->msix_entries[eq_obj->eq_idx].vector; + return adapter->msix_entries[eq_obj->msix_vec_idx].vector; } static int be_request_irq(struct be_adapter *adapter, @@ -2345,7 +2345,6 @@ static int be_clear(struct be_adapter *adapter) be_mcc_queues_destroy(adapter); be_rx_queues_destroy(adapter); be_tx_queues_destroy(adapter); - adapter->eq_next_idx = 0; if (be_physfn(adapter) && adapter->sriov_enabled) for (vf = 0; vf < num_vfs; vf++) @@ -3142,14 +3141,12 @@ static int be_resume(struct pci_dev *pdev) static void be_shutdown(struct pci_dev *pdev) { struct be_adapter *adapter = pci_get_drvdata(pdev); + struct net_device *netdev = adapter->netdev; - if (!adapter) - return; - - if (netif_running(adapter->netdev)) + if (netif_running(netdev)) cancel_delayed_work_sync(&adapter->work); - netif_device_detach(adapter->netdev); + netif_device_detach(netdev); be_cmd_reset_function(adapter); diff --git a/trunk/drivers/net/bna/bfa_ioc.c b/trunk/drivers/net/bna/bfa_ioc.c index e3de0b8625cd..34933cb9569f 100644 --- a/trunk/drivers/net/bna/bfa_ioc.c +++ b/trunk/drivers/net/bna/bfa_ioc.c @@ -2219,9 +2219,13 @@ bfa_nw_ioc_get_mac(struct bfa_ioc *ioc) static void bfa_ioc_recover(struct bfa_ioc *ioc) { - pr_crit("Heart Beat of IOC has failed\n"); - bfa_ioc_stats(ioc, ioc_hbfails); - bfa_fsm_send_event(ioc, IOC_E_HBFAIL); + u16 bdf; + + bdf = (ioc->pcidev.pci_slot << 8 | ioc->pcidev.pci_func << 3 | + ioc->pcidev.device_id); + + pr_crit("Firmware heartbeat failure at %d", bdf); + BUG_ON(1); } static void diff --git a/trunk/drivers/net/can/mcp251x.c b/trunk/drivers/net/can/mcp251x.c index 330140ee266d..7513c4523ac4 100644 --- a/trunk/drivers/net/can/mcp251x.c +++ b/trunk/drivers/net/can/mcp251x.c @@ -931,8 +931,7 @@ static int mcp251x_open(struct net_device *net) priv->tx_len = 0; ret = request_threaded_irq(spi->irq, NULL, mcp251x_can_ist, - pdata->irq_flags ? pdata->irq_flags : IRQF_TRIGGER_FALLING, - DEVICE_NAME, priv); + IRQF_TRIGGER_FALLING, DEVICE_NAME, priv); if (ret) { dev_err(&spi->dev, "failed to acquire irq %d\n", spi->irq); if (pdata->transceiver_enable) diff --git a/trunk/drivers/net/mlx4/en_rx.c b/trunk/drivers/net/mlx4/en_rx.c index 62dd21b06df4..cfd50bc49169 100644 --- a/trunk/drivers/net/mlx4/en_rx.c +++ b/trunk/drivers/net/mlx4/en_rx.c @@ -345,8 +345,6 @@ int mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv) err = mlx4_en_init_allocator(priv, ring); if (err) { en_err(priv, "Failed initializing ring allocator\n"); - if (ring->stride <= TXBB_SIZE) - ring->buf -= TXBB_SIZE; ring_ind--; goto err_allocator; } @@ -371,8 +369,6 @@ int mlx4_en_activate_rx_rings(struct mlx4_en_priv *priv) ring_ind = priv->rx_ring_num - 1; err_allocator: while (ring_ind >= 0) { - if (priv->rx_ring[ring_ind].stride <= TXBB_SIZE) - priv->rx_ring[ring_ind].buf -= TXBB_SIZE; mlx4_en_destroy_allocator(priv, &priv->rx_ring[ring_ind]); ring_ind--; } diff --git a/trunk/drivers/net/mlx4/main.c b/trunk/drivers/net/mlx4/main.c index 3814fc9b1145..62fa7eec5f0c 100644 --- a/trunk/drivers/net/mlx4/main.c +++ b/trunk/drivers/net/mlx4/main.c @@ -944,10 +944,6 @@ static int mlx4_setup_hca(struct mlx4_dev *dev) } for (port = 1; port <= dev->caps.num_ports; port++) { - enum mlx4_port_type port_type = 0; - mlx4_SENSE_PORT(dev, port, &port_type); - if (port_type) - dev->caps.port_type[port] = port_type; ib_port_default_caps = 0; err = mlx4_get_port_ib_caps(dev, port, &ib_port_default_caps); if (err) @@ -962,7 +958,6 @@ static int mlx4_setup_hca(struct mlx4_dev *dev) goto err_mcg_table_free; } } - mlx4_set_port_mask(dev); return 0; diff --git a/trunk/drivers/net/mlx4/mlx4.h b/trunk/drivers/net/mlx4/mlx4.h index dd7d745fbab4..c1e0e5f1bcdb 100644 --- a/trunk/drivers/net/mlx4/mlx4.h +++ b/trunk/drivers/net/mlx4/mlx4.h @@ -431,8 +431,6 @@ void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type); void mlx4_handle_catas_err(struct mlx4_dev *dev); -int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port, - enum mlx4_port_type *type); void mlx4_do_sense_ports(struct mlx4_dev *dev, enum mlx4_port_type *stype, enum mlx4_port_type *defaults); diff --git a/trunk/drivers/net/mlx4/sense.c b/trunk/drivers/net/mlx4/sense.c index e2337a7411d9..015fbe785c13 100644 --- a/trunk/drivers/net/mlx4/sense.c +++ b/trunk/drivers/net/mlx4/sense.c @@ -38,8 +38,8 @@ #include "mlx4.h" -int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port, - enum mlx4_port_type *type) +static int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port, + enum mlx4_port_type *type) { u64 out_param; int err = 0; diff --git a/trunk/drivers/net/pppoe.c b/trunk/drivers/net/pppoe.c index 718879b35b7d..693aaef4e3ce 100644 --- a/trunk/drivers/net/pppoe.c +++ b/trunk/drivers/net/pppoe.c @@ -317,7 +317,7 @@ static void pppoe_flush_dev(struct net_device *dev) lock_sock(sk); if (po->pppoe_dev == dev && - sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND | PPPOX_ZOMBIE)) { + sk->sk_state & (PPPOX_CONNECTED | PPPOX_BOUND)) { pppox_unbind_sock(sk); sk->sk_state = PPPOX_ZOMBIE; sk->sk_state_change(sk); diff --git a/trunk/drivers/net/smsc911x.c b/trunk/drivers/net/smsc911x.c index 4b42ecc63dcf..c498b720b532 100644 --- a/trunk/drivers/net/smsc911x.c +++ b/trunk/drivers/net/smsc911x.c @@ -1818,7 +1818,6 @@ static int __devinit smsc911x_init(struct net_device *dev) SMSC_TRACE(PROBE, "PHY will be autodetected."); spin_lock_init(&pdata->dev_lock); - spin_lock_init(&pdata->mac_lock); if (pdata->ioaddr == 0) { SMSC_WARNING(PROBE, "pdata->ioaddr: 0x00000000"); @@ -1896,11 +1895,8 @@ static int __devinit smsc911x_init(struct net_device *dev) /* workaround for platforms without an eeprom, where the mac address * is stored elsewhere and set by the bootloader. This saves the * mac address before resetting the device */ - if (pdata->config.flags & SMSC911X_SAVE_MAC_ADDRESS) { - spin_lock_irq(&pdata->mac_lock); + if (pdata->config.flags & SMSC911X_SAVE_MAC_ADDRESS) smsc911x_read_mac_address(dev); - spin_unlock_irq(&pdata->mac_lock); - } /* Reset the LAN911x */ if (smsc911x_soft_reset(pdata)) @@ -2063,6 +2059,8 @@ static int __devinit smsc911x_drv_probe(struct platform_device *pdev) SMSC_TRACE(PROBE, "Network interface: \"%s\"", dev->name); } + spin_lock_init(&pdata->mac_lock); + retval = smsc911x_mii_init(pdev, dev); if (retval) { SMSC_WARNING(PROBE, diff --git a/trunk/drivers/net/usb/smsc95xx.c b/trunk/drivers/net/usb/smsc95xx.c index 47a6c870b51f..727874d9deb6 100644 --- a/trunk/drivers/net/usb/smsc95xx.c +++ b/trunk/drivers/net/usb/smsc95xx.c @@ -1313,21 +1313,6 @@ static const struct usb_device_id products[] = { USB_DEVICE(0x0424, 0x9909), .driver_info = (unsigned long) &smsc95xx_info, }, - { - /* SMSC LAN9530 USB Ethernet Device */ - USB_DEVICE(0x0424, 0x9530), - .driver_info = (unsigned long) &smsc95xx_info, - }, - { - /* SMSC LAN9730 USB Ethernet Device */ - USB_DEVICE(0x0424, 0x9730), - .driver_info = (unsigned long) &smsc95xx_info, - }, - { - /* SMSC LAN89530 USB Ethernet Device */ - USB_DEVICE(0x0424, 0x9E08), - .driver_info = (unsigned long) &smsc95xx_info, - }, { }, /* END */ }; MODULE_DEVICE_TABLE(usb, products); diff --git a/trunk/drivers/net/wireless/ath/ath9k/hw.c b/trunk/drivers/net/wireless/ath/ath9k/hw.c index 1ec9bcd6b281..338b07502f1a 100644 --- a/trunk/drivers/net/wireless/ath/ath9k/hw.c +++ b/trunk/drivers/net/wireless/ath/ath9k/hw.c @@ -2546,7 +2546,6 @@ static struct { { AR_SREV_VERSION_9287, "9287" }, { AR_SREV_VERSION_9271, "9271" }, { AR_SREV_VERSION_9300, "9300" }, - { AR_SREV_VERSION_9485, "9485" }, }; /* For devices with external radios */ diff --git a/trunk/drivers/net/wireless/b43/dma.c b/trunk/drivers/net/wireless/b43/dma.c index ff0f5ba14b2c..3d5566e7af0a 100644 --- a/trunk/drivers/net/wireless/b43/dma.c +++ b/trunk/drivers/net/wireless/b43/dma.c @@ -1536,7 +1536,7 @@ static void dma_rx(struct b43_dmaring *ring, int *slot) dmaaddr = meta->dmaaddr; goto drop_recycle_buffer; } - if (unlikely(len + ring->frameoffset > ring->rx_buffersize)) { + if (unlikely(len > ring->rx_buffersize)) { /* The data did not fit into one descriptor buffer * and is split over multiple buffers. * This should never happen, as we try to allocate buffers diff --git a/trunk/drivers/net/wireless/b43/dma.h b/trunk/drivers/net/wireless/b43/dma.h index e8a80a1251bf..a01c2100f166 100644 --- a/trunk/drivers/net/wireless/b43/dma.h +++ b/trunk/drivers/net/wireless/b43/dma.h @@ -163,7 +163,7 @@ struct b43_dmadesc_generic { /* DMA engine tuning knobs */ #define B43_TXRING_SLOTS 256 #define B43_RXRING_SLOTS 64 -#define B43_DMA0_RX_BUFFERSIZE (B43_DMA0_RX_FRAMEOFFSET + IEEE80211_MAX_FRAME_LEN) +#define B43_DMA0_RX_BUFFERSIZE IEEE80211_MAX_FRAME_LEN /* Pointer poison */ #define B43_DMA_PTR_POISON ((void *)ERR_PTR(-ENOMEM)) diff --git a/trunk/drivers/net/wireless/iwlwifi/iwl-eeprom.h b/trunk/drivers/net/wireless/iwlwifi/iwl-eeprom.h index 20b66469d68f..98aa8af01192 100644 --- a/trunk/drivers/net/wireless/iwlwifi/iwl-eeprom.h +++ b/trunk/drivers/net/wireless/iwlwifi/iwl-eeprom.h @@ -241,7 +241,7 @@ struct iwl_eeprom_enhanced_txpwr { /* 6x00 Specific */ #define EEPROM_6000_TX_POWER_VERSION (4) -#define EEPROM_6000_EEPROM_VERSION (0x423) +#define EEPROM_6000_EEPROM_VERSION (0x434) /* 6x50 Specific */ #define EEPROM_6050_TX_POWER_VERSION (4) diff --git a/trunk/drivers/net/wireless/p54/p54usb.c b/trunk/drivers/net/wireless/p54/p54usb.c index e18358725b69..9b344a921e74 100644 --- a/trunk/drivers/net/wireless/p54/p54usb.c +++ b/trunk/drivers/net/wireless/p54/p54usb.c @@ -56,7 +56,6 @@ static struct usb_device_id p54u_table[] __devinitdata = { {USB_DEVICE(0x0846, 0x4210)}, /* Netgear WG121 the second ? */ {USB_DEVICE(0x0846, 0x4220)}, /* Netgear WG111 */ {USB_DEVICE(0x09aa, 0x1000)}, /* Spinnaker Proto board */ - {USB_DEVICE(0x0bf8, 0x1007)}, /* Fujitsu E-5400 USB */ {USB_DEVICE(0x0cde, 0x0006)}, /* Medion 40900, Roper Europe */ {USB_DEVICE(0x0db0, 0x6826)}, /* MSI UB54G (MS-6826) */ {USB_DEVICE(0x107b, 0x55f2)}, /* Gateway WGU-210 (Gemtek) */ @@ -69,7 +68,6 @@ static struct usb_device_id p54u_table[] __devinitdata = { {USB_DEVICE(0x1915, 0x2235)}, /* Linksys WUSB54G Portable OEM */ {USB_DEVICE(0x2001, 0x3701)}, /* DLink DWL-G120 Spinnaker */ {USB_DEVICE(0x2001, 0x3703)}, /* DLink DWL-G122 */ - {USB_DEVICE(0x2001, 0x3762)}, /* Conceptronic C54U */ {USB_DEVICE(0x5041, 0x2234)}, /* Linksys WUSB54G */ {USB_DEVICE(0x5041, 0x2235)}, /* Linksys WUSB54G Portable */ diff --git a/trunk/drivers/net/wireless/rt2x00/rt2x00dev.c b/trunk/drivers/net/wireless/rt2x00/rt2x00dev.c index 84eb6ad36377..9de9dbe94399 100644 --- a/trunk/drivers/net/wireless/rt2x00/rt2x00dev.c +++ b/trunk/drivers/net/wireless/rt2x00/rt2x00dev.c @@ -1062,10 +1062,8 @@ void rt2x00lib_remove_dev(struct rt2x00_dev *rt2x00dev) * Stop all work. */ cancel_work_sync(&rt2x00dev->intf_work); - if (rt2x00_is_usb(rt2x00dev)) { - cancel_work_sync(&rt2x00dev->rxdone_work); - cancel_work_sync(&rt2x00dev->txdone_work); - } + cancel_work_sync(&rt2x00dev->rxdone_work); + cancel_work_sync(&rt2x00dev->txdone_work); destroy_workqueue(rt2x00dev->workqueue); /* diff --git a/trunk/drivers/net/wireless/rtlwifi/efuse.c b/trunk/drivers/net/wireless/rtlwifi/efuse.c index 590f14f45a89..f74a8701c67d 100644 --- a/trunk/drivers/net/wireless/rtlwifi/efuse.c +++ b/trunk/drivers/net/wireless/rtlwifi/efuse.c @@ -685,7 +685,7 @@ static int efuse_pg_packet_read(struct ieee80211_hw *hw, u8 offset, u8 *data) u8 efuse_data, word_cnts = 0; u16 efuse_addr = 0; - u8 hworden = 0; + u8 hworden; u8 tmpdata[8]; if (data == NULL) diff --git a/trunk/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c b/trunk/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c index 28a6ce3bc239..5ef91374b230 100644 --- a/trunk/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c +++ b/trunk/drivers/net/wireless/rtlwifi/rtl8192c/fw_common.c @@ -303,7 +303,7 @@ static void _rtl92c_fill_h2c_command(struct ieee80211_hw *hw, u16 box_reg, box_extreg; u8 u1b_tmp; bool isfw_read = false; - u8 buf_index = 0; + u8 buf_index; bool bwrite_sucess = false; u8 wait_h2c_limmit = 100; u8 wait_writeh2c_limmit = 100; diff --git a/trunk/drivers/net/wireless/rtlwifi/usb.c b/trunk/drivers/net/wireless/rtlwifi/usb.c index f5d85735d642..a4b2613d6a8c 100644 --- a/trunk/drivers/net/wireless/rtlwifi/usb.c +++ b/trunk/drivers/net/wireless/rtlwifi/usb.c @@ -246,7 +246,7 @@ static void _rtl_usb_io_handler_init(struct device *dev, static void _rtl_usb_io_handler_release(struct ieee80211_hw *hw) { - struct rtl_priv __maybe_unused *rtlpriv = rtl_priv(hw); + struct rtl_priv *rtlpriv = rtl_priv(hw); mutex_destroy(&rtlpriv->io.bb_mutex); } diff --git a/trunk/drivers/net/wireless/wl12xx/sdio.c b/trunk/drivers/net/wireless/wl12xx/sdio.c index b1c7d031c391..5b9dbeafec06 100644 --- a/trunk/drivers/net/wireless/wl12xx/sdio.c +++ b/trunk/drivers/net/wireless/wl12xx/sdio.c @@ -340,7 +340,7 @@ module_init(wl1271_init); module_exit(wl1271_exit); MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Luciano Coelho "); +MODULE_AUTHOR("Luciano Coelho "); MODULE_AUTHOR("Juuso Oikarinen "); MODULE_FIRMWARE(WL1271_FW_NAME); MODULE_FIRMWARE(WL1271_AP_FW_NAME); diff --git a/trunk/drivers/net/wireless/wl12xx/spi.c b/trunk/drivers/net/wireless/wl12xx/spi.c index ffc745b17f4d..18cf01719ae0 100644 --- a/trunk/drivers/net/wireless/wl12xx/spi.c +++ b/trunk/drivers/net/wireless/wl12xx/spi.c @@ -487,7 +487,7 @@ module_init(wl1271_init); module_exit(wl1271_exit); MODULE_LICENSE("GPL"); -MODULE_AUTHOR("Luciano Coelho "); +MODULE_AUTHOR("Luciano Coelho "); MODULE_AUTHOR("Juuso Oikarinen "); MODULE_FIRMWARE(WL1271_FW_NAME); MODULE_FIRMWARE(WL1271_AP_FW_NAME); diff --git a/trunk/drivers/net/wireless/wl12xx/testmode.c b/trunk/drivers/net/wireless/wl12xx/testmode.c index 6ec06a4a4c6d..e64403b6896d 100644 --- a/trunk/drivers/net/wireless/wl12xx/testmode.c +++ b/trunk/drivers/net/wireless/wl12xx/testmode.c @@ -204,10 +204,7 @@ static int wl1271_tm_cmd_nvs_push(struct wl1271 *wl, struct nlattr *tb[]) kfree(wl->nvs); - if (len != sizeof(struct wl1271_nvs_file)) - return -EINVAL; - - wl->nvs = kzalloc(len, GFP_KERNEL); + wl->nvs = kzalloc(sizeof(struct wl1271_nvs_file), GFP_KERNEL); if (!wl->nvs) { wl1271_error("could not allocate memory for the nvs file"); ret = -ENOMEM; diff --git a/trunk/drivers/net/wireless/zd1211rw/zd_usb.c b/trunk/drivers/net/wireless/zd1211rw/zd_usb.c index ab607bbd6291..58236e6d0921 100644 --- a/trunk/drivers/net/wireless/zd1211rw/zd_usb.c +++ b/trunk/drivers/net/wireless/zd1211rw/zd_usb.c @@ -643,7 +643,7 @@ static void rx_urb_complete(struct urb *urb) usb = urb->context; rx = &usb->rx; - tasklet_schedule(&rx->reset_timer_tasklet); + zd_usb_reset_rx_idle_timer(usb); if (length%rx->usb_packet_size > rx->usb_packet_size-4) { /* If there is an old first fragment, we don't care. */ @@ -812,7 +812,6 @@ void zd_usb_disable_rx(struct zd_usb *usb) __zd_usb_disable_rx(usb); mutex_unlock(&rx->setup_mutex); - tasklet_kill(&rx->reset_timer_tasklet); cancel_delayed_work_sync(&rx->idle_work); } @@ -1107,13 +1106,6 @@ static void zd_rx_idle_timer_handler(struct work_struct *work) zd_usb_reset_rx(usb); } -static void zd_usb_reset_rx_idle_timer_tasklet(unsigned long param) -{ - struct zd_usb *usb = (struct zd_usb *)param; - - zd_usb_reset_rx_idle_timer(usb); -} - void zd_usb_reset_rx_idle_timer(struct zd_usb *usb) { struct zd_usb_rx *rx = &usb->rx; @@ -1135,7 +1127,6 @@ static inline void init_usb_interrupt(struct zd_usb *usb) static inline void init_usb_rx(struct zd_usb *usb) { struct zd_usb_rx *rx = &usb->rx; - spin_lock_init(&rx->lock); mutex_init(&rx->setup_mutex); if (interface_to_usbdev(usb->intf)->speed == USB_SPEED_HIGH) { @@ -1145,14 +1136,11 @@ static inline void init_usb_rx(struct zd_usb *usb) } ZD_ASSERT(rx->fragment_length == 0); INIT_DELAYED_WORK(&rx->idle_work, zd_rx_idle_timer_handler); - rx->reset_timer_tasklet.func = zd_usb_reset_rx_idle_timer_tasklet; - rx->reset_timer_tasklet.data = (unsigned long)usb; } static inline void init_usb_tx(struct zd_usb *usb) { struct zd_usb_tx *tx = &usb->tx; - spin_lock_init(&tx->lock); atomic_set(&tx->enabled, 0); tx->stopped = 0; @@ -1683,10 +1671,6 @@ static void iowrite16v_urb_complete(struct urb *urb) if (urb->status && !usb->cmd_error) usb->cmd_error = urb->status; - - if (!usb->cmd_error && - urb->actual_length != urb->transfer_buffer_length) - usb->cmd_error = -EIO; } static int zd_submit_waiting_urb(struct zd_usb *usb, bool last) @@ -1821,7 +1805,7 @@ int zd_usb_iowrite16v_async(struct zd_usb *usb, const struct zd_ioreq16 *ioreqs, usb_fill_int_urb(urb, udev, usb_sndintpipe(udev, EP_REGS_OUT), req, req_len, iowrite16v_urb_complete, usb, ep->desc.bInterval); - urb->transfer_flags |= URB_FREE_BUFFER; + urb->transfer_flags |= URB_FREE_BUFFER | URB_SHORT_NOT_OK; /* Submit previous URB */ r = zd_submit_waiting_urb(usb, false); diff --git a/trunk/drivers/net/wireless/zd1211rw/zd_usb.h b/trunk/drivers/net/wireless/zd1211rw/zd_usb.h index 325d0f989257..b3df2c8116cc 100644 --- a/trunk/drivers/net/wireless/zd1211rw/zd_usb.h +++ b/trunk/drivers/net/wireless/zd1211rw/zd_usb.h @@ -183,7 +183,6 @@ struct zd_usb_rx { spinlock_t lock; struct mutex setup_mutex; struct delayed_work idle_work; - struct tasklet_struct reset_timer_tasklet; u8 fragment[2 * USB_MAX_RX_SIZE]; unsigned int fragment_length; unsigned int usb_packet_size; diff --git a/trunk/drivers/pci/pci-driver.c b/trunk/drivers/pci/pci-driver.c index 135df164a4c1..d86ea8b01137 100644 --- a/trunk/drivers/pci/pci-driver.c +++ b/trunk/drivers/pci/pci-driver.c @@ -781,7 +781,7 @@ static int pci_pm_resume(struct device *dev) #endif /* !CONFIG_SUSPEND */ -#ifdef CONFIG_HIBERNATE_CALLBACKS +#ifdef CONFIG_HIBERNATION static int pci_pm_freeze(struct device *dev) { @@ -970,7 +970,7 @@ static int pci_pm_restore(struct device *dev) return error; } -#else /* !CONFIG_HIBERNATE_CALLBACKS */ +#else /* !CONFIG_HIBERNATION */ #define pci_pm_freeze NULL #define pci_pm_freeze_noirq NULL @@ -981,7 +981,7 @@ static int pci_pm_restore(struct device *dev) #define pci_pm_restore NULL #define pci_pm_restore_noirq NULL -#endif /* !CONFIG_HIBERNATE_CALLBACKS */ +#endif /* !CONFIG_HIBERNATION */ #ifdef CONFIG_PM_RUNTIME diff --git a/trunk/drivers/pci/setup-bus.c b/trunk/drivers/pci/setup-bus.c index ebf51ad1b714..89d0a6a88df7 100644 --- a/trunk/drivers/pci/setup-bus.c +++ b/trunk/drivers/pci/setup-bus.c @@ -676,10 +676,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, min_align = align1 >> 1; align += aligns[order]; } - size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), min_align); + size0 = calculate_memsize(size, min_size, 0, resource_size(b_res), align); size1 = !add_size ? size : calculate_memsize(size, min_size+add_size, 0, - resource_size(b_res), min_align); + resource_size(b_res), align); if (!size0 && !size1) { if (b_res->start || b_res->end) dev_info(&bus->self->dev, "disabling bridge window " diff --git a/trunk/drivers/pcmcia/pxa2xx_balloon3.c b/trunk/drivers/pcmcia/pxa2xx_balloon3.c index 4c3e94c0ae85..453c54c97612 100644 --- a/trunk/drivers/pcmcia/pxa2xx_balloon3.c +++ b/trunk/drivers/pcmcia/pxa2xx_balloon3.c @@ -25,8 +25,6 @@ #include -#include - #include "soc_common.h" /* @@ -129,9 +127,6 @@ static int __init balloon3_pcmcia_init(void) { int ret; - if (!machine_is_balloon3()) - return -ENODEV; - balloon3_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); if (!balloon3_pcmcia_device) return -ENOMEM; diff --git a/trunk/drivers/pcmcia/pxa2xx_trizeps4.c b/trunk/drivers/pcmcia/pxa2xx_trizeps4.c index b829e655457b..b7e596620db1 100644 --- a/trunk/drivers/pcmcia/pxa2xx_trizeps4.c +++ b/trunk/drivers/pcmcia/pxa2xx_trizeps4.c @@ -69,15 +69,15 @@ static int trizeps_pcmcia_hw_init(struct soc_pcmcia_socket *skt) for (i = 0; i < ARRAY_SIZE(irqs); i++) { if (irqs[i].sock != skt->nr) continue; - if (gpio_request(irq_to_gpio(irqs[i].irq), irqs[i].str) < 0) { + if (gpio_request(IRQ_TO_GPIO(irqs[i].irq), irqs[i].str) < 0) { pr_err("%s: sock %d unable to request gpio %d\n", - __func__, skt->nr, irq_to_gpio(irqs[i].irq)); + __func__, skt->nr, IRQ_TO_GPIO(irqs[i].irq)); ret = -EBUSY; goto error; } - if (gpio_direction_input(irq_to_gpio(irqs[i].irq)) < 0) { + if (gpio_direction_input(IRQ_TO_GPIO(irqs[i].irq)) < 0) { pr_err("%s: sock %d unable to set input gpio %d\n", - __func__, skt->nr, irq_to_gpio(irqs[i].irq)); + __func__, skt->nr, IRQ_TO_GPIO(irqs[i].irq)); ret = -EINVAL; goto error; } @@ -86,7 +86,7 @@ static int trizeps_pcmcia_hw_init(struct soc_pcmcia_socket *skt) error: for (; i >= 0; i--) { - gpio_free(irq_to_gpio(irqs[i].irq)); + gpio_free(IRQ_TO_GPIO(irqs[i].irq)); } return (ret); } @@ -97,7 +97,7 @@ static void trizeps_pcmcia_hw_shutdown(struct soc_pcmcia_socket *skt) /* free allocated gpio's */ gpio_free(GPIO_PRDY); for (i = 0; i < ARRAY_SIZE(irqs); i++) - gpio_free(irq_to_gpio(irqs[i].irq)); + gpio_free(IRQ_TO_GPIO(irqs[i].irq)); } static unsigned long trizeps_pcmcia_status[2]; @@ -226,9 +226,6 @@ static int __init trizeps_pcmcia_init(void) { int ret; - if (!machine_is_trizeps4() && !machine_is_trizeps4wl()) - return -ENODEV; - trizeps_pcmcia_device = platform_device_alloc("pxa2xx-pcmcia", -1); if (!trizeps_pcmcia_device) return -ENOMEM; diff --git a/trunk/drivers/platform/x86/Kconfig b/trunk/drivers/platform/x86/Kconfig index 0485e394712a..2ee442c2a5db 100644 --- a/trunk/drivers/platform/x86/Kconfig +++ b/trunk/drivers/platform/x86/Kconfig @@ -187,8 +187,7 @@ config MSI_LAPTOP depends on ACPI depends on BACKLIGHT_CLASS_DEVICE depends on RFKILL - depends on INPUT && SERIO_I8042 - select INPUT_SPARSEKMAP + depends on SERIO_I8042 ---help--- This is a driver for laptops built by MSI (MICRO-STAR INTERNATIONAL): diff --git a/trunk/drivers/platform/x86/acer-wmi.c b/trunk/drivers/platform/x86/acer-wmi.c index ac4e7f83ce6c..5ea6c3477d17 100644 --- a/trunk/drivers/platform/x86/acer-wmi.c +++ b/trunk/drivers/platform/x86/acer-wmi.c @@ -89,7 +89,7 @@ MODULE_LICENSE("GPL"); #define ACERWMID_EVENT_GUID "676AA15E-6A47-4D9F-A2CC-1E6D18D14026" MODULE_ALIAS("wmi:67C3371D-95A3-4C37-BB61-DD47B491DAAB"); -MODULE_ALIAS("wmi:6AF4F258-B401-42FD-BE91-3D4AC2D7C0D3"); +MODULE_ALIAS("wmi:6AF4F258-B401-42Fd-BE91-3D4AC2D7C0D3"); MODULE_ALIAS("wmi:676AA15E-6A47-4D9F-A2CC-1E6D18D14026"); enum acer_wmi_event_ids { diff --git a/trunk/drivers/platform/x86/asus-wmi.c b/trunk/drivers/platform/x86/asus-wmi.c index 832a3fd7c1c8..efc776cb0c66 100644 --- a/trunk/drivers/platform/x86/asus-wmi.c +++ b/trunk/drivers/platform/x86/asus-wmi.c @@ -201,8 +201,8 @@ static int asus_wmi_input_init(struct asus_wmi *asus) if (!asus->inputdev) return -ENOMEM; - asus->inputdev->name = asus->driver->input_name; - asus->inputdev->phys = asus->driver->input_phys; + asus->inputdev->name = asus->driver->input_phys; + asus->inputdev->phys = asus->driver->input_name; asus->inputdev->id.bustype = BUS_HOST; asus->inputdev->dev.parent = &asus->platform_device->dev; diff --git a/trunk/drivers/platform/x86/eeepc-wmi.c b/trunk/drivers/platform/x86/eeepc-wmi.c index 649dcadd8ea3..0ddc434fb93b 100644 --- a/trunk/drivers/platform/x86/eeepc-wmi.c +++ b/trunk/drivers/platform/x86/eeepc-wmi.c @@ -67,11 +67,9 @@ static const struct key_entry eeepc_wmi_keymap[] = { { KE_KEY, 0x82, { KEY_CAMERA } }, { KE_KEY, 0x83, { KEY_CAMERA_ZOOMIN } }, { KE_KEY, 0x88, { KEY_WLAN } }, - { KE_KEY, 0xbd, { KEY_CAMERA } }, { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } }, { KE_KEY, 0xe0, { KEY_PROG1 } }, /* Task Manager */ { KE_KEY, 0xe1, { KEY_F14 } }, /* Change Resolution */ - { KE_KEY, 0xe8, { KEY_SCREENLOCK } }, { KE_KEY, 0xe9, { KEY_BRIGHTNESS_ZERO } }, { KE_KEY, 0xeb, { KEY_CAMERA_ZOOMOUT } }, { KE_KEY, 0xec, { KEY_CAMERA_UP } }, diff --git a/trunk/drivers/platform/x86/intel_pmic_gpio.c b/trunk/drivers/platform/x86/intel_pmic_gpio.c index 464bb3fc4d88..d653104b59cb 100644 --- a/trunk/drivers/platform/x86/intel_pmic_gpio.c +++ b/trunk/drivers/platform/x86/intel_pmic_gpio.c @@ -74,19 +74,6 @@ struct pmic_gpio { u32 trigger_type; }; -static void pmic_program_irqtype(int gpio, int type) -{ - if (type & IRQ_TYPE_EDGE_RISING) - intel_scu_ipc_update_register(GPIO0 + gpio, 0x20, 0x20); - else - intel_scu_ipc_update_register(GPIO0 + gpio, 0x00, 0x20); - - if (type & IRQ_TYPE_EDGE_FALLING) - intel_scu_ipc_update_register(GPIO0 + gpio, 0x10, 0x10); - else - intel_scu_ipc_update_register(GPIO0 + gpio, 0x00, 0x10); -}; - static int pmic_gpio_direction_input(struct gpio_chip *chip, unsigned offset) { if (offset > 8) { @@ -179,38 +166,16 @@ static int pmic_gpio_to_irq(struct gpio_chip *chip, unsigned offset) return pg->irq_base + offset; } -static void pmic_bus_lock(struct irq_data *data) -{ - struct pmic_gpio *pg = irq_data_get_irq_chip_data(data); - - mutex_lock(&pg->buslock); -} - -static void pmic_bus_sync_unlock(struct irq_data *data) -{ - struct pmic_gpio *pg = irq_data_get_irq_chip_data(data); - - if (pg->update_type) { - unsigned int gpio = pg->update_type & ~GPIO_UPDATE_TYPE; - - pmic_program_irqtype(gpio, pg->trigger_type); - pg->update_type = 0; - } - mutex_unlock(&pg->buslock); -} - /* the gpiointr register is read-clear, so just do nothing. */ static void pmic_irq_unmask(struct irq_data *data) { } static void pmic_irq_mask(struct irq_data *data) { } static struct irq_chip pmic_irqchip = { - .name = "PMIC-GPIO", - .irq_mask = pmic_irq_mask, - .irq_unmask = pmic_irq_unmask, - .irq_set_type = pmic_irq_type, - .irq_bus_lock = pmic_bus_lock, - .irq_bus_sync_unlock = pmic_bus_sync_unlock, + .name = "PMIC-GPIO", + .irq_mask = pmic_irq_mask, + .irq_unmask = pmic_irq_unmask, + .irq_set_type = pmic_irq_type, }; static irqreturn_t pmic_irq_handler(int irq, void *data) diff --git a/trunk/drivers/platform/x86/samsung-laptop.c b/trunk/drivers/platform/x86/samsung-laptop.c index d347116d150e..de434c6dc2d6 100644 --- a/trunk/drivers/platform/x86/samsung-laptop.c +++ b/trunk/drivers/platform/x86/samsung-laptop.c @@ -570,16 +570,6 @@ static struct dmi_system_id __initdata samsung_dmi_table[] = { }, .callback = dmi_check_cb, }, - { - .ident = "R410 Plus", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, - "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, "R410P"), - DMI_MATCH(DMI_BOARD_NAME, "R460"), - }, - .callback = dmi_check_cb, - }, { .ident = "R518", .matches = { @@ -601,12 +591,12 @@ static struct dmi_system_id __initdata samsung_dmi_table[] = { .callback = dmi_check_cb, }, { - .ident = "N150/N210/N220/N230", + .ident = "N150/N210/N220", .matches = { DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), - DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220/N230"), - DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220/N230"), + DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220"), + DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220"), }, .callback = dmi_check_cb, }, @@ -781,7 +771,6 @@ static int __init samsung_init(void) /* create a backlight device to talk to this one */ memset(&props, 0, sizeof(struct backlight_properties)); - props.type = BACKLIGHT_PLATFORM; props.max_brightness = sabi_config->max_brightness; backlight_device = backlight_device_register("samsung", &sdev->dev, NULL, &backlight_ops, diff --git a/trunk/drivers/platform/x86/sony-laptop.c b/trunk/drivers/platform/x86/sony-laptop.c index 8f709aec4da0..e642f5f29504 100644 --- a/trunk/drivers/platform/x86/sony-laptop.c +++ b/trunk/drivers/platform/x86/sony-laptop.c @@ -138,8 +138,6 @@ MODULE_PARM_DESC(kbd_backlight_timeout, "1 for 30 seconds, 2 for 60 seconds and 3 to disable timeout " "(default: 0)"); -static void sony_nc_kbd_backlight_resume(void); - enum sony_nc_rfkill { SONY_WIFI, SONY_BLUETOOTH, @@ -773,6 +771,11 @@ static int sony_nc_handles_setup(struct platform_device *pd) if (!handles) return -ENOMEM; + sysfs_attr_init(&handles->devattr.attr); + handles->devattr.attr.name = "handles"; + handles->devattr.attr.mode = S_IRUGO; + handles->devattr.show = sony_nc_handles_show; + for (i = 0; i < ARRAY_SIZE(handles->cap); i++) { if (!acpi_callsetfunc(sony_nc_acpi_handle, "SN00", i + 0x20, &result)) { @@ -782,18 +785,11 @@ static int sony_nc_handles_setup(struct platform_device *pd) } } - if (debug) { - sysfs_attr_init(&handles->devattr.attr); - handles->devattr.attr.name = "handles"; - handles->devattr.attr.mode = S_IRUGO; - handles->devattr.show = sony_nc_handles_show; - - /* allow reading capabilities via sysfs */ - if (device_create_file(&pd->dev, &handles->devattr)) { - kfree(handles); - handles = NULL; - return -1; - } + /* allow reading capabilities via sysfs */ + if (device_create_file(&pd->dev, &handles->devattr)) { + kfree(handles); + handles = NULL; + return -1; } return 0; @@ -802,8 +798,7 @@ static int sony_nc_handles_setup(struct platform_device *pd) static int sony_nc_handles_cleanup(struct platform_device *pd) { if (handles) { - if (debug) - device_remove_file(&pd->dev, &handles->devattr); + device_remove_file(&pd->dev, &handles->devattr); kfree(handles); handles = NULL; } @@ -813,11 +808,6 @@ static int sony_nc_handles_cleanup(struct platform_device *pd) static int sony_find_snc_handle(int handle) { int i; - - /* not initialized yet, return early */ - if (!handles) - return -1; - for (i = 0; i < 0x10; i++) { if (handles->cap[i] == handle) { dprintk("found handle 0x%.4x (offset: 0x%.2x)\n", @@ -1178,9 +1168,6 @@ static int sony_nc_resume(struct acpi_device *device) /* re-read rfkill state */ sony_nc_rfkill_update(); - /* restore kbd backlight states */ - sony_nc_kbd_backlight_resume(); - return 0; } @@ -1368,7 +1355,6 @@ static void sony_nc_rfkill_setup(struct acpi_device *device) #define KBDBL_HANDLER 0x137 #define KBDBL_PRESENT 0xB00 #define SET_MODE 0xC00 -#define SET_STATE 0xD00 #define SET_TIMEOUT 0xE00 struct kbd_backlight { @@ -1391,10 +1377,6 @@ static ssize_t __sony_nc_kbd_backlight_mode_set(u8 value) (value << 0x10) | SET_MODE, &result)) return -EIO; - /* Try to turn the light on/off immediately */ - sony_call_snc_handle(KBDBL_HANDLER, (value << 0x10) | SET_STATE, - &result); - kbdbl_handle->mode = value; return 0; @@ -1476,7 +1458,7 @@ static int sony_nc_kbd_backlight_setup(struct platform_device *pd) { int result; - if (sony_call_snc_handle(KBDBL_HANDLER, KBDBL_PRESENT, &result)) + if (sony_call_snc_handle(0x137, KBDBL_PRESENT, &result)) return 0; if (!(result & 0x02)) return 0; @@ -1519,36 +1501,13 @@ static int sony_nc_kbd_backlight_setup(struct platform_device *pd) static int sony_nc_kbd_backlight_cleanup(struct platform_device *pd) { if (kbdbl_handle) { - int result; - device_remove_file(&pd->dev, &kbdbl_handle->mode_attr); device_remove_file(&pd->dev, &kbdbl_handle->timeout_attr); - - /* restore the default hw behaviour */ - sony_call_snc_handle(KBDBL_HANDLER, 0x1000 | SET_MODE, &result); - sony_call_snc_handle(KBDBL_HANDLER, SET_TIMEOUT, &result); - kfree(kbdbl_handle); } return 0; } -static void sony_nc_kbd_backlight_resume(void) -{ - int ignore = 0; - - if (!kbdbl_handle) - return; - - if (kbdbl_handle->mode == 0) - sony_call_snc_handle(KBDBL_HANDLER, SET_MODE, &ignore); - - if (kbdbl_handle->timeout != 0) - sony_call_snc_handle(KBDBL_HANDLER, - (kbdbl_handle->timeout << 0x10) | SET_TIMEOUT, - &ignore); -} - static void sony_nc_backlight_setup(void) { acpi_handle unused; diff --git a/trunk/drivers/platform/x86/thinkpad_acpi.c b/trunk/drivers/platform/x86/thinkpad_acpi.c index efb3b6b9bcdb..a08561f5349e 100644 --- a/trunk/drivers/platform/x86/thinkpad_acpi.c +++ b/trunk/drivers/platform/x86/thinkpad_acpi.c @@ -8618,7 +8618,8 @@ static bool __pure __init tpacpi_is_valid_fw_id(const char* const s, tpacpi_is_fw_digit(s[1]) && s[2] == t && s[3] == 'T' && tpacpi_is_fw_digit(s[4]) && - tpacpi_is_fw_digit(s[5]); + tpacpi_is_fw_digit(s[5]) && + s[6] == 'W' && s[7] == 'W'; } /* returns 0 - probe ok, or < 0 - probe error. diff --git a/trunk/drivers/rapidio/rio.c b/trunk/drivers/rapidio/rio.c index 86c9a091a2ff..c29719cacbca 100644 --- a/trunk/drivers/rapidio/rio.c +++ b/trunk/drivers/rapidio/rio.c @@ -1171,17 +1171,16 @@ static int rio_hdid_setup(char *str) __setup("riohdid=", rio_hdid_setup); -int rio_register_mport(struct rio_mport *port) +void rio_register_mport(struct rio_mport *port) { if (next_portid >= RIO_MAX_MPORTS) { pr_err("RIO: reached specified max number of mports\n"); - return 1; + return; } port->id = next_portid++; port->host_deviceid = rio_get_hdid(port->id); list_add_tail(&port->node, &rio_mports); - return 0; } EXPORT_SYMBOL_GPL(rio_local_get_device_id); diff --git a/trunk/drivers/rapidio/switches/idt_gen2.c b/trunk/drivers/rapidio/switches/idt_gen2.c index ac2701b22e71..095016a9dec1 100644 --- a/trunk/drivers/rapidio/switches/idt_gen2.c +++ b/trunk/drivers/rapidio/switches/idt_gen2.c @@ -418,4 +418,3 @@ DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1848, idtg2_switch_init); DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1616, idtg2_switch_init); DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTVPS1616, idtg2_switch_init); DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTSPS1616, idtg2_switch_init); -DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1432, idtg2_switch_init); diff --git a/trunk/drivers/rtc/class.c b/trunk/drivers/rtc/class.c index 39013867cbd6..09b4437b3e61 100644 --- a/trunk/drivers/rtc/class.c +++ b/trunk/drivers/rtc/class.c @@ -171,7 +171,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, err = __rtc_read_alarm(rtc, &alrm); if (!err && !rtc_valid_tm(&alrm.time)) - rtc_initialize_alarm(rtc, &alrm); + rtc_set_alarm(rtc, &alrm); strlcpy(rtc->name, name, RTC_DEVICE_NAME_SIZE); dev_set_name(&rtc->dev, "rtc%d", id); diff --git a/trunk/drivers/rtc/interface.c b/trunk/drivers/rtc/interface.c index ef6316acec43..23719f0acbf6 100644 --- a/trunk/drivers/rtc/interface.c +++ b/trunk/drivers/rtc/interface.c @@ -375,32 +375,6 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) } EXPORT_SYMBOL_GPL(rtc_set_alarm); -/* Called once per device from rtc_device_register */ -int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) -{ - int err; - - err = rtc_valid_tm(&alarm->time); - if (err != 0) - return err; - - err = mutex_lock_interruptible(&rtc->ops_lock); - if (err) - return err; - - rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time); - rtc->aie_timer.period = ktime_set(0, 0); - if (alarm->enabled) { - rtc->aie_timer.enabled = 1; - timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node); - } - mutex_unlock(&rtc->ops_lock); - return err; -} -EXPORT_SYMBOL_GPL(rtc_initialize_alarm); - - - int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled) { int err = mutex_lock_interruptible(&rtc->ops_lock); diff --git a/trunk/drivers/rtc/rtc-bfin.c b/trunk/drivers/rtc/rtc-bfin.c index 90d866272c8e..a0fc4cf42abf 100644 --- a/trunk/drivers/rtc/rtc-bfin.c +++ b/trunk/drivers/rtc/rtc-bfin.c @@ -250,8 +250,6 @@ static int bfin_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) bfin_rtc_int_set_alarm(rtc); else bfin_rtc_int_clear(~(RTC_ISTAT_ALARM | RTC_ISTAT_ALARM_DAY)); - - return 0; } static int bfin_rtc_read_time(struct device *dev, struct rtc_time *tm) diff --git a/trunk/drivers/rtc/rtc-mc13xxx.c b/trunk/drivers/rtc/rtc-mc13xxx.c index c5ac03793e79..c42006469559 100644 --- a/trunk/drivers/rtc/rtc-mc13xxx.c +++ b/trunk/drivers/rtc/rtc-mc13xxx.c @@ -401,7 +401,6 @@ const struct platform_device_id mc13xxx_rtc_idtable[] = { }, { .name = "mc13892-rtc", }, - { } }; static struct platform_driver mc13xxx_rtc_driver = { diff --git a/trunk/drivers/rtc/rtc-s3c.c b/trunk/drivers/rtc/rtc-s3c.c index b3466c491cd3..714964913e5e 100644 --- a/trunk/drivers/rtc/rtc-s3c.c +++ b/trunk/drivers/rtc/rtc-s3c.c @@ -336,6 +336,7 @@ static void s3c_rtc_release(struct device *dev) /* do not clear AIE here, it may be needed for wake */ + s3c_rtc_setpie(dev, 0); free_irq(s3c_rtc_alarmno, rtc_dev); free_irq(s3c_rtc_tickno, rtc_dev); } @@ -407,6 +408,7 @@ static int __devexit s3c_rtc_remove(struct platform_device *dev) platform_set_drvdata(dev, NULL); rtc_device_unregister(rtc); + s3c_rtc_setpie(&dev->dev, 0); s3c_rtc_setaie(&dev->dev, 0); clk_disable(rtc_clk); diff --git a/trunk/drivers/s390/cio/device.c b/trunk/drivers/s390/cio/device.c index 8e04c00cf0ad..df14c51f6532 100644 --- a/trunk/drivers/s390/cio/device.c +++ b/trunk/drivers/s390/cio/device.c @@ -541,24 +541,15 @@ static ssize_t online_store (struct device *dev, struct device_attribute *attr, int force, ret; unsigned long i; - /* Prevent conflict between multiple on-/offline processing requests. */ + if (!dev_fsm_final_state(cdev) && + cdev->private->state != DEV_STATE_DISCONNECTED) + return -EAGAIN; if (atomic_cmpxchg(&cdev->private->onoff, 0, 1) != 0) return -EAGAIN; - /* Prevent conflict between internal I/Os and on-/offline processing. */ - if (!dev_fsm_final_state(cdev) && - cdev->private->state != DEV_STATE_DISCONNECTED) { - ret = -EAGAIN; - goto out_onoff; - } - /* Prevent conflict between pending work and on-/offline processing.*/ - if (work_pending(&cdev->private->todo_work)) { - ret = -EAGAIN; - goto out_onoff; - } if (cdev->drv && !try_module_get(cdev->drv->driver.owner)) { - ret = -EINVAL; - goto out_onoff; + atomic_set(&cdev->private->onoff, 0); + return -EINVAL; } if (!strncmp(buf, "force\n", count)) { force = 1; @@ -583,7 +574,6 @@ static ssize_t online_store (struct device *dev, struct device_attribute *attr, out: if (cdev->drv) module_put(cdev->drv->driver.owner); -out_onoff: atomic_set(&cdev->private->onoff, 0); return (ret < 0) ? ret : count; } @@ -1321,12 +1311,10 @@ static int purge_fn(struct device *dev, void *data) spin_lock_irq(cdev->ccwlock); if (is_blacklisted(id->ssid, id->devno) && - (cdev->private->state == DEV_STATE_OFFLINE) && - (atomic_cmpxchg(&cdev->private->onoff, 0, 1) == 0)) { + (cdev->private->state == DEV_STATE_OFFLINE)) { CIO_MSG_EVENT(3, "ccw: purging 0.%x.%04x\n", id->ssid, id->devno); ccw_device_sched_todo(cdev, CDEV_TODO_UNREG); - atomic_set(&cdev->private->onoff, 0); } spin_unlock_irq(cdev->ccwlock); /* Abort loop in case of pending signal. */ diff --git a/trunk/drivers/s390/cio/qdio_main.c b/trunk/drivers/s390/cio/qdio_main.c index c532ba929ccd..479c665e9e7c 100644 --- a/trunk/drivers/s390/cio/qdio_main.c +++ b/trunk/drivers/s390/cio/qdio_main.c @@ -1649,26 +1649,26 @@ static int __init init_QDIO(void) { int rc; - rc = qdio_debug_init(); - if (rc) - return rc; rc = qdio_setup_init(); if (rc) - goto out_debug; + return rc; rc = tiqdio_allocate_memory(); if (rc) goto out_cache; - rc = tiqdio_register_thinints(); + rc = qdio_debug_init(); if (rc) goto out_ti; + rc = tiqdio_register_thinints(); + if (rc) + goto out_debug; return 0; +out_debug: + qdio_debug_exit(); out_ti: tiqdio_free_memory(); out_cache: qdio_setup_exit(); -out_debug: - qdio_debug_exit(); return rc; } @@ -1676,8 +1676,8 @@ static void __exit exit_QDIO(void) { tiqdio_unregister_thinints(); tiqdio_free_memory(); - qdio_setup_exit(); qdio_debug_exit(); + qdio_setup_exit(); } module_init(init_QDIO); diff --git a/trunk/drivers/scsi/scsi_lib.c b/trunk/drivers/scsi/scsi_lib.c index ab55c2fa7ce2..6d5c7ff43f5b 100644 --- a/trunk/drivers/scsi/scsi_lib.c +++ b/trunk/drivers/scsi/scsi_lib.c @@ -443,7 +443,7 @@ static void scsi_run_queue(struct request_queue *q) &sdev->request_queue->queue_flags); if (flagset) queue_flag_set(QUEUE_FLAG_REENTER, sdev->request_queue); - __blk_run_queue(sdev->request_queue); + __blk_run_queue(sdev->request_queue, false); if (flagset) queue_flag_clear(QUEUE_FLAG_REENTER, sdev->request_queue); spin_unlock(sdev->request_queue->queue_lock); diff --git a/trunk/drivers/scsi/scsi_transport_fc.c b/trunk/drivers/scsi/scsi_transport_fc.c index 28c33506e4ad..fdf3fa639056 100644 --- a/trunk/drivers/scsi/scsi_transport_fc.c +++ b/trunk/drivers/scsi/scsi_transport_fc.c @@ -3829,7 +3829,7 @@ fc_bsg_goose_queue(struct fc_rport *rport) !test_bit(QUEUE_FLAG_REENTER, &rport->rqst_q->queue_flags); if (flagset) queue_flag_set(QUEUE_FLAG_REENTER, rport->rqst_q); - __blk_run_queue(rport->rqst_q); + __blk_run_queue(rport->rqst_q, false); if (flagset) queue_flag_clear(QUEUE_FLAG_REENTER, rport->rqst_q); spin_unlock_irqrestore(rport->rqst_q->queue_lock, flags); diff --git a/trunk/drivers/spi/amba-pl022.c b/trunk/drivers/spi/amba-pl022.c index 08de58e7f59f..5825370bad25 100644 --- a/trunk/drivers/spi/amba-pl022.c +++ b/trunk/drivers/spi/amba-pl022.c @@ -1555,7 +1555,7 @@ static int stop_queue(struct pl022 *pl022) * A wait_queue on the pl022->busy could be used, but then the common * execution path (pump_messages) would be required to call wake_up or * friends on every SPI message. Do this instead */ - while ((!list_empty(&pl022->queue) || pl022->busy) && limit--) { + while (!list_empty(&pl022->queue) && pl022->busy && limit--) { spin_unlock_irqrestore(&pl022->queue_lock, flags); msleep(10); spin_lock_irqsave(&pl022->queue_lock, flags); diff --git a/trunk/drivers/spi/dw_spi.c b/trunk/drivers/spi/dw_spi.c index 871e337c917f..b1a4b9f503ae 100644 --- a/trunk/drivers/spi/dw_spi.c +++ b/trunk/drivers/spi/dw_spi.c @@ -821,7 +821,7 @@ static int stop_queue(struct dw_spi *dws) spin_lock_irqsave(&dws->lock, flags); dws->run = QUEUE_STOPPED; - while ((!list_empty(&dws->queue) || dws->busy) && limit--) { + while (!list_empty(&dws->queue) && dws->busy && limit--) { spin_unlock_irqrestore(&dws->lock, flags); msleep(10); spin_lock_irqsave(&dws->lock, flags); diff --git a/trunk/drivers/spi/pxa2xx_spi.c b/trunk/drivers/spi/pxa2xx_spi.c index dc25bee8d33f..9c74aad6be93 100644 --- a/trunk/drivers/spi/pxa2xx_spi.c +++ b/trunk/drivers/spi/pxa2xx_spi.c @@ -1493,7 +1493,7 @@ static int stop_queue(struct driver_data *drv_data) * execution path (pump_messages) would be required to call wake_up or * friends on every SPI message. Do this instead */ drv_data->run = QUEUE_STOPPED; - while ((!list_empty(&drv_data->queue) || drv_data->busy) && limit--) { + while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) { spin_unlock_irqrestore(&drv_data->lock, flags); msleep(10); spin_lock_irqsave(&drv_data->lock, flags); diff --git a/trunk/drivers/spi/spi_bfin5xx.c b/trunk/drivers/spi/spi_bfin5xx.c index f706dba165cf..bdb7289a1d22 100644 --- a/trunk/drivers/spi/spi_bfin5xx.c +++ b/trunk/drivers/spi/spi_bfin5xx.c @@ -1284,7 +1284,7 @@ static inline int bfin_spi_stop_queue(struct bfin_spi_master_data *drv_data) * friends on every SPI message. Do this instead */ drv_data->running = false; - while ((!list_empty(&drv_data->queue) || drv_data->busy) && limit--) { + while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) { spin_unlock_irqrestore(&drv_data->lock, flags); msleep(10); spin_lock_irqsave(&drv_data->lock, flags); diff --git a/trunk/drivers/staging/Kconfig b/trunk/drivers/staging/Kconfig index e3786f161bc3..e9254f509e85 100644 --- a/trunk/drivers/staging/Kconfig +++ b/trunk/drivers/staging/Kconfig @@ -67,10 +67,6 @@ source "drivers/staging/echo/Kconfig" source "drivers/staging/brcm80211/Kconfig" -source "drivers/staging/rt2860/Kconfig" - -source "drivers/staging/rt2870/Kconfig" - source "drivers/staging/comedi/Kconfig" source "drivers/staging/olpc_dcon/Kconfig" @@ -131,6 +127,8 @@ source "drivers/staging/wlags49_h2/Kconfig" source "drivers/staging/wlags49_h25/Kconfig" +source "drivers/staging/samsung-laptop/Kconfig" + source "drivers/staging/sm7xx/Kconfig" source "drivers/staging/dt3155v4l/Kconfig" diff --git a/trunk/drivers/staging/Makefile b/trunk/drivers/staging/Makefile index 1d11306eee21..dc642ab5974e 100644 --- a/trunk/drivers/staging/Makefile +++ b/trunk/drivers/staging/Makefile @@ -16,10 +16,7 @@ obj-$(CONFIG_USB_IP_COMMON) += usbip/ obj-$(CONFIG_W35UND) += winbond/ obj-$(CONFIG_PRISM2_USB) += wlan-ng/ obj-$(CONFIG_ECHO) += echo/ -obj-$(CONFIG_BRCMSMAC) += brcm80211/ -obj-$(CONFIG_BRCMFMAC) += brcm80211/ -obj-$(CONFIG_RT2860) += rt2860/ -obj-$(CONFIG_RT2870) += rt2870/ +obj-$(CONFIG_BRCM80211) += brcm80211/ obj-$(CONFIG_COMEDI) += comedi/ obj-$(CONFIG_FB_OLPC_DCON) += olpc_dcon/ obj-$(CONFIG_ASUS_OLED) += asus_oled/ @@ -49,6 +46,7 @@ obj-$(CONFIG_XVMALLOC) += zram/ obj-$(CONFIG_ZCACHE) += zcache/ obj-$(CONFIG_WLAGS49_H2) += wlags49_h2/ obj-$(CONFIG_WLAGS49_H25) += wlags49_h25/ +obj-$(CONFIG_SAMSUNG_LAPTOP) += samsung-laptop/ obj-$(CONFIG_FB_SM7XX) += sm7xx/ obj-$(CONFIG_VIDEO_DT3155) += dt3155v4l/ obj-$(CONFIG_CRYSTALHD) += crystalhd/ diff --git a/trunk/drivers/staging/ath6kl/Kconfig b/trunk/drivers/staging/ath6kl/Kconfig index 1f15e1fb1ab2..8a5caa30b85f 100644 --- a/trunk/drivers/staging/ath6kl/Kconfig +++ b/trunk/drivers/staging/ath6kl/Kconfig @@ -100,6 +100,12 @@ config AR600x_BT_RESET_PIN help WLAN GPIO to be used for resetting BT +config ATH6KL_CFG80211 + bool "CFG80211 support" + depends on ATH6K_LEGACY && CFG80211 + help + Enables support for CFG80211 APIs. The default option is to use WEXT. Even with this option enabled, WEXT is not explicitly disabled and the onus of not exercising WEXT lies on the application(s) running in the user space. + config ATH6KL_HTC_RAW_INTERFACE bool "RAW HTC support" depends on ATH6K_LEGACY diff --git a/trunk/drivers/staging/ath6kl/Makefile b/trunk/drivers/staging/ath6kl/Makefile index 1d3f2390a172..ab68078699f2 100644 --- a/trunk/drivers/staging/ath6kl/Makefile +++ b/trunk/drivers/staging/ath6kl/Makefile @@ -29,6 +29,26 @@ ccflags-y += -I$(obj)/os ccflags-y += -I$(obj)/bmi/include ccflags-y += -I$(obj)/include/common/AR6002/hw4.0 +ifeq ($(CONFIG_AR600x_SD31_XXX),y) +ccflags-y += -DAR600x_SD31_XXX +endif + +ifeq ($(CONFIG_AR600x_WB31_XXX),y) +ccflags-y += -DAR600x_WB31_XXX +endif + +ifeq ($(CONFIG_AR600x_SD32_XXX),y) +ccflags-y += -DAR600x_SD32_XXX +endif + +ifeq ($(CONFIG_AR600x_CUSTOM_XXX),y) +ccflags-y += -DAR600x_CUSTOM_XXX +endif + +ifeq ($(CONFIG_ATH6KL_ENABLE_COEXISTENCE),y) +ccflags-y += -DENABLE_COEXISTENCE +endif + ifeq ($(CONFIG_AR600x_DUAL_ANTENNA),y) ccflags-y += -DAR600x_DUAL_ANTENNA endif @@ -65,6 +85,11 @@ ifeq ($(CONFIG_ATH6KL_CONFIG_GPIO_BT_RESET),y) ccflags-y += -DATH6KL_CONFIG_GPIO_BT_RESET endif +ifeq ($(CONFIG_ATH6KL_CFG80211),y) +ccflags-y += -DATH6K_CONFIG_CFG80211 +ath6kl-y += os/linux/cfg80211.o +endif + ifeq ($(CONFIG_ATH6KL_HTC_RAW_INTERFACE),y) ccflags-y += -DHTC_RAW_INTERFACE endif @@ -90,8 +115,18 @@ ifeq ($(CONFIG_ATH6KL_SKIP_ABI_VERSION_CHECK),y) ccflags-y += -DATH6KL_SKIP_ABI_VERSION_CHECK endif +ccflags-y += -DLINUX -DKERNEL_2_6 +ccflags-y += -DTCMD +ccflags-y += -DSEND_EVENT_TO_APP +ccflags-y += -DUSER_KEYS +ccflags-y += -DNO_SYNC_FLUSH +ccflags-y += -DHTC_EP_STAT_PROFILING +ccflags-y += -DATH_AR6K_11N_SUPPORT ccflags-y += -DWAPI_ENABLE ccflags-y += -DCHECKSUM_OFFLOAD +ccflags-y += -DWLAN_HEADERS +ccflags-y += -DINIT_MODE_DRV_ENABLED +ccflags-y += -DBMIENABLE_SET obj-$(CONFIG_ATH6K_LEGACY) := ath6kl.o ath6kl-y += htc2/AR6000/ar6k.o @@ -101,12 +136,14 @@ ath6kl-y += htc2/htc_recv.o ath6kl-y += htc2/htc_services.o ath6kl-y += htc2/htc.o ath6kl-y += bmi/src/bmi.o -ath6kl-y += os/linux/cfg80211.o ath6kl-y += os/linux/ar6000_drv.o ath6kl-y += os/linux/ar6000_raw_if.o ath6kl-y += os/linux/ar6000_pm.o ath6kl-y += os/linux/netbuf.o +ath6kl-y += os/linux/wireless_ext.o +ath6kl-y += os/linux/ioctl.o ath6kl-y += os/linux/hci_bridge.o +ath6kl-y += os/linux/ar6k_pal.o ath6kl-y += miscdrv/common_drv.o ath6kl-y += miscdrv/credit_dist.o ath6kl-y += wmi/wmi.o diff --git a/trunk/drivers/staging/ath6kl/bmi/src/bmi.c b/trunk/drivers/staging/ath6kl/bmi/src/bmi.c index f1f085eba9c8..9268bf3eabd9 100644 --- a/trunk/drivers/staging/ath6kl/bmi/src/bmi.c +++ b/trunk/drivers/staging/ath6kl/bmi/src/bmi.c @@ -95,12 +95,12 @@ void BMICleanup(void) { if (pBMICmdCredits) { - kfree(pBMICmdCredits); + A_FREE(pBMICmdCredits); pBMICmdCredits = NULL; } if (pBMICmdBuf) { - kfree(pBMICmdBuf); + A_FREE(pBMICmdBuf); pBMICmdBuf = NULL; } } @@ -127,12 +127,12 @@ BMIDone(struct hif_device *device) } if (pBMICmdCredits) { - kfree(pBMICmdCredits); + A_FREE(pBMICmdCredits); pBMICmdCredits = NULL; } if (pBMICmdBuf) { - kfree(pBMICmdBuf); + A_FREE(pBMICmdBuf); pBMICmdBuf = NULL; } diff --git a/trunk/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif.c b/trunk/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif.c index c8f1a6ec37ad..e6d9cd802dee 100644 --- a/trunk/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif.c +++ b/trunk/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif.c @@ -53,189 +53,62 @@ #if defined(CONFIG_PM) #define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev) #define to_sdio_driver(d) container_of(d, struct sdio_driver, drv) +static int hifDeviceSuspend(struct device *dev); +static int hifDeviceResume(struct device *dev); #endif /* CONFIG_PM */ +static int hifDeviceInserted(struct sdio_func *func, const struct sdio_device_id *id); +static void hifDeviceRemoved(struct sdio_func *func); +static struct hif_device *addHifDevice(struct sdio_func *func); +static struct hif_device *getHifDevice(struct sdio_func *func); static void delHifDevice(struct hif_device * device); static int Func0_CMD52WriteByte(struct mmc_card *card, unsigned int address, unsigned char byte); static int Func0_CMD52ReadByte(struct mmc_card *card, unsigned int address, unsigned char *byte); -static int hifEnableFunc(struct hif_device *device, struct sdio_func *func); -static int hifDisableFunc(struct hif_device *device, struct sdio_func *func); -OSDRV_CALLBACKS osdrvCallbacks; - int reset_sdio_on_unload = 0; module_param(reset_sdio_on_unload, int, 0644); extern u32 nohifscattersupport; -static struct hif_device *ath6kl_alloc_hifdev(struct sdio_func *func) -{ - struct hif_device *hifdevice; - - hifdevice = kzalloc(sizeof(struct hif_device), GFP_KERNEL); -#if HIF_USE_DMA_BOUNCE_BUFFER - hifdevice->dma_buffer = kmalloc(HIF_DMA_BUFFER_SIZE, GFP_KERNEL); -#endif - hifdevice->func = func; - hifdevice->powerConfig = HIF_DEVICE_POWER_UP; - sdio_set_drvdata(func, hifdevice); - - return hifdevice; -} - -static struct hif_device *ath6kl_get_hifdev(struct sdio_func *func) -{ - return (struct hif_device *) sdio_get_drvdata(func); -} - -static const struct sdio_device_id ath6kl_hifdev_ids[] = { - { SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6002_BASE | 0x0)) }, - { SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6002_BASE | 0x1)) }, - { SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x0)) }, - { SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x1)) }, - { /* null */ }, +/* ------ Static Variables ------ */ +static const struct sdio_device_id ar6k_id_table[] = { + { SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6002_BASE | 0x0)) }, + { SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6002_BASE | 0x1)) }, + { SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x0)) }, + { SDIO_DEVICE(MANUFACTURER_CODE, (MANUFACTURER_ID_AR6003_BASE | 0x1)) }, + { /* null */ }, }; +MODULE_DEVICE_TABLE(sdio, ar6k_id_table); -MODULE_DEVICE_TABLE(sdio, ath6kl_hifdev_ids); - -static int ath6kl_hifdev_probe(struct sdio_func *func, - const struct sdio_device_id *id) -{ - int ret; - struct hif_device *device; - int count; - - AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, - ("ath6kl: Function: 0x%X, Vendor ID: 0x%X, " - "Device ID: 0x%X, block size: 0x%X/0x%X\n", - func->num, func->vendor, func->device, - func->max_blksize, func->cur_blksize)); - - ath6kl_alloc_hifdev(func); - device = ath6kl_get_hifdev(func); - - device->id = id; - device->is_disabled = true; - - spin_lock_init(&device->lock); - spin_lock_init(&device->asynclock); - - DL_LIST_INIT(&device->ScatterReqHead); - - /* Try to allow scatter unless globally overridden */ - if (!nohifscattersupport) - device->scatter_enabled = true; - - A_MEMZERO(device->busRequest, sizeof(device->busRequest)); - - for (count = 0; count < BUS_REQUEST_MAX_NUM; count++) { - sema_init(&device->busRequest[count].sem_req, 0); - hifFreeBusRequest(device, &device->busRequest[count]); - } - - sema_init(&device->sem_async, 0); - - ret = hifEnableFunc(device, func); - - return ret; -} - -static void ath6kl_hifdev_remove(struct sdio_func *func) -{ - int status = 0; - struct hif_device *device; - - device = ath6kl_get_hifdev(func); - if (device->claimedContext != NULL) - status = osdrvCallbacks. - deviceRemovedHandler(device->claimedContext, device); - - if (device->is_disabled) - device->is_disabled = false; - else - status = hifDisableFunc(device, func); - - CleanupHIFScatterResources(device); - - delHifDevice(device); -} - -#if defined(CONFIG_PM) -static int ath6kl_hifdev_suspend(struct device *dev) -{ - struct sdio_func *func = dev_to_sdio_func(dev); - int status = 0; - struct hif_device *device; - - device = ath6kl_get_hifdev(func); - - if (device && device->claimedContext && - osdrvCallbacks.deviceSuspendHandler) { - /* set true first for PowerStateChangeNotify(..) */ - device->is_suspend = true; - status = osdrvCallbacks. - deviceSuspendHandler(device->claimedContext); - if (status) - device->is_suspend = false; - } - - CleanupHIFScatterResources(device); - - switch (status) { - case 0: - return 0; - case A_EBUSY: - /* Hack for kernel in order to support deep sleep and wow */ - return -EBUSY; - default: - return -1; - } -} - -static int ath6kl_hifdev_resume(struct device *dev) -{ - struct sdio_func *func = dev_to_sdio_func(dev); - int status = 0; - struct hif_device *device; - - device = ath6kl_get_hifdev(func); - if (device && device->claimedContext && - osdrvCallbacks.deviceSuspendHandler) { - status = osdrvCallbacks. - deviceResumeHandler(device->claimedContext); - if (status == 0) - device->is_suspend = false; - } - - return status; -} - -static const struct dev_pm_ops ath6kl_hifdev_pmops = { - .suspend = ath6kl_hifdev_suspend, - .resume = ath6kl_hifdev_resume, +static struct sdio_driver ar6k_driver = { + .name = "ar6k_wlan", + .id_table = ar6k_id_table, + .probe = hifDeviceInserted, + .remove = hifDeviceRemoved, }; -#endif /* CONFIG_PM */ -static struct sdio_driver ath6kl_hifdev_driver = { - .name = "ath6kl_hifdev", - .id_table = ath6kl_hifdev_ids, - .probe = ath6kl_hifdev_probe, - .remove = ath6kl_hifdev_remove, #if defined(CONFIG_PM) - .drv = { - .pm = &ath6kl_hifdev_pmops, - }, -#endif +/* New suspend/resume based on linux-2.6.32 + * Need to patch linux-2.6.32 with mmc2.6.32_suspend.patch + * Need to patch with msmsdcc2.6.29_suspend.patch for msm_sdcc host + */ +static struct dev_pm_ops ar6k_device_pm_ops = { + .suspend = hifDeviceSuspend, + .resume = hifDeviceResume, }; +#endif /* CONFIG_PM */ /* make sure we only unregister when registered. */ static int registered = 0; +OSDRV_CALLBACKS osdrvCallbacks; extern u32 onebitmode; extern u32 busspeedlow; extern u32 debughif; static void ResetAllCards(void); +static int hifDisableFunc(struct hif_device *device, struct sdio_func *func); +static int hifEnableFunc(struct hif_device *device, struct sdio_func *func); #ifdef DEBUG @@ -252,22 +125,31 @@ ATH_DEBUG_INSTANTIATE_MODULE_VAR(hif, /* ------ Functions ------ */ int HIFInit(OSDRV_CALLBACKS *callbacks) { - int r; - AR_DEBUG_ASSERT(callbacks != NULL); + int status; + AR_DEBUG_ASSERT(callbacks != NULL); + + A_REGISTER_MODULE_DEBUG_INFO(hif); - A_REGISTER_MODULE_DEBUG_INFO(hif); + /* store the callback handlers */ + osdrvCallbacks = *callbacks; - /* store the callback handlers */ - osdrvCallbacks = *callbacks; + /* Register with bus driver core */ + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: HIFInit registering\n")); + registered = 1; +#if defined(CONFIG_PM) + if (callbacks->deviceSuspendHandler && callbacks->deviceResumeHandler) { + ar6k_driver.drv.pm = &ar6k_device_pm_ops; + } +#endif /* CONFIG_PM */ + status = sdio_register_driver(&ar6k_driver); + AR_DEBUG_ASSERT(status==0); - /* Register with bus driver core */ - registered = 1; + if (status != 0) { + return A_ERROR; + } - r = sdio_register_driver(&ath6kl_hifdev_driver); - if (r < 0) - return r; + return 0; - return 0; } static int @@ -881,7 +763,7 @@ HIFShutDownDevice(struct hif_device *device) registered = 0; AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: Unregistering with the bus driver\n")); - sdio_unregister_driver(&ath6kl_hifdev_driver); + sdio_unregister_driver(&ar6k_driver); AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: Unregistered\n")); } @@ -896,7 +778,7 @@ hifIRQHandler(struct sdio_func *func) struct hif_device *device; AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifIRQHandler\n")); - device = ath6kl_get_hifdev(func); + device = getHifDevice(func); atomic_set(&device->irqHandling, 1); /* release the host during ints so we can pick it back up when we process cmds */ sdio_release_host(device->func); @@ -941,6 +823,48 @@ static int enable_task(void *param) } #endif +static int hifDeviceInserted(struct sdio_func *func, const struct sdio_device_id *id) +{ + int ret; + struct hif_device * device; + int count; + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, + ("AR6000: hifDeviceInserted, Function: 0x%X, Vendor ID: 0x%X, Device ID: 0x%X, block size: 0x%X/0x%X\n", + func->num, func->vendor, func->device, func->max_blksize, func->cur_blksize)); + + addHifDevice(func); + device = getHifDevice(func); + + device->id = id; + device->is_disabled = true; + + spin_lock_init(&device->lock); + + spin_lock_init(&device->asynclock); + + DL_LIST_INIT(&device->ScatterReqHead); + + if (!nohifscattersupport) { + /* try to allow scatter operation on all instances, + * unless globally overridden */ + device->scatter_enabled = true; + } + + /* Initialize the bus requests to be used later */ + A_MEMZERO(device->busRequest, sizeof(device->busRequest)); + for (count = 0; count < BUS_REQUEST_MAX_NUM; count ++) { + sema_init(&device->busRequest[count].sem_req, 0); + hifFreeBusRequest(device, &device->busRequest[count]); + } + sema_init(&device->sem_async, 0); + + ret = hifEnableFunc(device, func); + + return ret; +} + + void HIFAckInterrupt(struct hif_device *device) { @@ -1031,7 +955,7 @@ static int hifDisableFunc(struct hif_device *device, struct sdio_func *func) int status = 0; AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifDisableFunc\n")); - device = ath6kl_get_hifdev(func); + device = getHifDevice(func); if (!IS_ERR(device->async_task)) { init_completion(&device->async_completion); device->async_shutdown = 1; @@ -1080,7 +1004,7 @@ static int hifEnableFunc(struct hif_device *device, struct sdio_func *func) int ret = 0; AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifEnableFunc\n")); - device = ath6kl_get_hifdev(func); + device = getHifDevice(func); if (device->is_disabled) { /* enable the SDIO function */ @@ -1092,7 +1016,7 @@ static int hifEnableFunc(struct hif_device *device, struct sdio_func *func) if (ret) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("AR6000: failed to enable 4-bit ASYNC IRQ mode %d \n",ret)); sdio_release_host(func); - return ret; + return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: 4-bit ASYNC IRQ mode enabled\n")); } @@ -1103,14 +1027,14 @@ static int hifEnableFunc(struct hif_device *device, struct sdio_func *func) AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("AR6000: %s(), Unable to enable AR6K: 0x%X\n", __FUNCTION__, ret)); sdio_release_host(func); - return ret; + return A_ERROR; } ret = sdio_set_block_size(func, HIF_MBOX_BLOCK_SIZE); sdio_release_host(func); if (ret) { AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("AR6000: %s(), Unable to set block size 0x%x AR6K: 0x%X\n", __FUNCTION__, HIF_MBOX_BLOCK_SIZE, ret)); - return ret; + return A_ERROR; } device->is_disabled = false; /* create async I/O thread */ @@ -1121,7 +1045,7 @@ static int hifEnableFunc(struct hif_device *device, struct sdio_func *func) "AR6K Async"); if (IS_ERR(device->async_task)) { AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("AR6000: %s(), to create async task\n", __FUNCTION__)); - return -ENOMEM; + return A_ERROR; } AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: start async task\n")); wake_up_process(device->async_task ); @@ -1136,14 +1060,14 @@ static int hifEnableFunc(struct hif_device *device, struct sdio_func *func) } else { taskFunc = enable_task; taskName = "AR6K enable"; - ret = -ENOMEM; + ret = A_PENDING; #endif /* CONFIG_PM */ } /* create resume thread */ pTask = kthread_create(taskFunc, (void *)device, taskName); if (IS_ERR(pTask)) { AR_DEBUG_PRINTF(ATH_DEBUG_ERROR, ("AR6000: %s(), to create enabel task\n", __FUNCTION__)); - return -ENOMEM; + return A_ERROR; } wake_up_process(pTask); AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -hifEnableFunc\n")); @@ -1152,6 +1076,79 @@ static int hifEnableFunc(struct hif_device *device, struct sdio_func *func) return ret; } +#if defined(CONFIG_PM) +static int hifDeviceSuspend(struct device *dev) +{ + struct sdio_func *func=dev_to_sdio_func(dev); + int status = 0; + struct hif_device *device; + + device = getHifDevice(func); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifDeviceSuspend\n")); + if (device && device->claimedContext && osdrvCallbacks.deviceSuspendHandler) { + device->is_suspend = true; /* set true first for PowerStateChangeNotify(..) */ + status = osdrvCallbacks.deviceSuspendHandler(device->claimedContext); + if (status) { + device->is_suspend = false; + } + } + CleanupHIFScatterResources(device); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -hifDeviceSuspend\n")); + + switch (status) { + case 0: + return 0; + case A_EBUSY: + return -EBUSY; /* Hack for kernel in order to support deep sleep and wow */ + default: + return -1; + } +} + +static int hifDeviceResume(struct device *dev) +{ + struct sdio_func *func=dev_to_sdio_func(dev); + int status = 0; + struct hif_device *device; + + device = getHifDevice(func); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifDeviceResume\n")); + if (device && device->claimedContext && osdrvCallbacks.deviceSuspendHandler) { + status = osdrvCallbacks.deviceResumeHandler(device->claimedContext); + if (status == 0) { + device->is_suspend = false; + } + } + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -hifDeviceResume\n")); + + return status; +} +#endif /* CONFIG_PM */ + +static void hifDeviceRemoved(struct sdio_func *func) +{ + int status = 0; + struct hif_device *device; + AR_DEBUG_ASSERT(func != NULL); + + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: +hifDeviceRemoved\n")); + device = getHifDevice(func); + if (device->claimedContext != NULL) { + status = osdrvCallbacks.deviceRemovedHandler(device->claimedContext, device); + } + + if (device->is_disabled) { + device->is_disabled = false; + } else { + status = hifDisableFunc(device, func); + } + CleanupHIFScatterResources(device); + + delHifDevice(device); + AR_DEBUG_ASSERT(status == 0); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: -hifDeviceRemoved\n")); +} + /* * This should be moved to AR6K HTC layer. */ @@ -1185,6 +1182,33 @@ int hifWaitForPendingRecv(struct hif_device *device) return 0; } + +static struct hif_device * +addHifDevice(struct sdio_func *func) +{ + struct hif_device *hifdevice; + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: addHifDevice\n")); + AR_DEBUG_ASSERT(func != NULL); + hifdevice = kzalloc(sizeof(struct hif_device), GFP_KERNEL); + AR_DEBUG_ASSERT(hifdevice != NULL); +#if HIF_USE_DMA_BOUNCE_BUFFER + hifdevice->dma_buffer = kmalloc(HIF_DMA_BUFFER_SIZE, GFP_KERNEL); + AR_DEBUG_ASSERT(hifdevice->dma_buffer != NULL); +#endif + hifdevice->func = func; + hifdevice->powerConfig = HIF_DEVICE_POWER_UP; + sdio_set_drvdata(func, hifdevice); + AR_DEBUG_PRINTF(ATH_DEBUG_TRACE, ("AR6000: addHifDevice; 0x%p\n", hifdevice)); + return hifdevice; +} + +static struct hif_device * +getHifDevice(struct sdio_func *func) +{ + AR_DEBUG_ASSERT(func != NULL); + return (struct hif_device *)sdio_get_drvdata(func); +} + static void delHifDevice(struct hif_device * device) { diff --git a/trunk/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif_scatter.c b/trunk/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif_scatter.c index 7516d913dab3..a1fdcc189f7e 100644 --- a/trunk/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif_scatter.c +++ b/trunk/drivers/staging/ath6kl/hif/sdio/linux_sdio/src/hif_scatter.c @@ -309,7 +309,7 @@ int SetupHIFScatterSupport(struct hif_device *device, struct hif_device_scatter_ (MAX_SCATTER_ENTRIES_PER_REQ - 1) * (sizeof(struct hif_scatter_item))); if (NULL == pReqPriv->pHifScatterReq) { - kfree(pReqPriv); + A_FREE(pReqPriv); break; } /* just zero the main part of the scatter request */ @@ -319,8 +319,8 @@ int SetupHIFScatterSupport(struct hif_device *device, struct hif_device_scatter_ /* allocate a bus request for this scatter request */ busrequest = hifAllocateBusRequest(device); if (NULL == busrequest) { - kfree(pReqPriv->pHifScatterReq); - kfree(pReqPriv); + A_FREE(pReqPriv->pHifScatterReq); + A_FREE(pReqPriv); break; } /* assign the scatter request to this bus request */ @@ -382,11 +382,11 @@ void CleanupHIFScatterResources(struct hif_device *device) } if (pReqPriv->pHifScatterReq != NULL) { - kfree(pReqPriv->pHifScatterReq); + A_FREE(pReqPriv->pHifScatterReq); pReqPriv->pHifScatterReq = NULL; } - kfree(pReqPriv); + A_FREE(pReqPriv); } } diff --git a/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k.c b/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k.c index 05f6d157d34a..eeddf6021f6d 100644 --- a/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k.c +++ b/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k.c @@ -743,7 +743,7 @@ static void DevCleanupVirtualScatterSupport(struct ar6k_device *pDev) if (NULL == pReq) { break; } - kfree(pReq); + A_FREE(pReq); } } diff --git a/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k.h b/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k.h index e551dbe674dc..1ff221838c0f 100644 --- a/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k.h +++ b/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k.h @@ -42,6 +42,7 @@ //#define MBOXHW_UNIT_TEST 1 +#include "athstartpack.h" PREPACK struct ar6k_irq_proc_registers { u8 host_int_status; u8 cpu_int_status; @@ -68,6 +69,8 @@ PREPACK struct ar6k_gmbox_ctrl_registers { u8 int_status_enable; } POSTPACK; +#include "athendpack.h" + #define AR6K_IRQ_ENABLE_REGS_SIZE sizeof(struct ar6k_irq_enable_registers) #define AR6K_REG_IO_BUFFER_SIZE 32 diff --git a/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k_gmbox_hciuart.c b/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k_gmbox_hciuart.c index 2603a928b800..41223f953589 100644 --- a/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k_gmbox_hciuart.c +++ b/trunk/drivers/staging/ath6kl/htc2/AR6000/ar6k_gmbox_hciuart.c @@ -108,7 +108,7 @@ static void HCIUartCleanup(struct gmbox_proto_hci_uart *pProtocol) A_MUTEX_DELETE(&pProtocol->HCIRxLock); A_MUTEX_DELETE(&pProtocol->HCITxLock); - kfree(pProtocol); + A_FREE(pProtocol); } static int InitTxCreditState(struct gmbox_proto_hci_uart *pProt) diff --git a/trunk/drivers/staging/ath6kl/htc2/htc.c b/trunk/drivers/staging/ath6kl/htc2/htc.c index ae54e64b6243..d40bb14a2dac 100644 --- a/trunk/drivers/staging/ath6kl/htc2/htc.c +++ b/trunk/drivers/staging/ath6kl/htc2/htc.c @@ -70,7 +70,7 @@ static void HTCCleanup(struct htc_target *target) for (i = 0;i < NUM_CONTROL_BUFFERS;i++) { if (target->HTCControlBuffers[i].Buffer) { - kfree(target->HTCControlBuffers[i].Buffer); + A_FREE(target->HTCControlBuffers[i].Buffer); } } @@ -86,7 +86,7 @@ static void HTCCleanup(struct htc_target *target) A_MUTEX_DELETE(&target->HTCTxLock); } /* free our instance */ - kfree(target); + A_FREE(target); } /* registered target arrival callback from the HIF layer */ @@ -448,7 +448,9 @@ static void ResetEndpointStates(struct htc_target *target) pEndpoint->ServiceID = 0; pEndpoint->MaxMsgLength = 0; pEndpoint->MaxTxQueueDepth = 0; +#ifdef HTC_EP_STAT_PROFILING A_MEMZERO(&pEndpoint->EndPointStats,sizeof(pEndpoint->EndPointStats)); +#endif INIT_HTC_PACKET_QUEUE(&pEndpoint->RxBuffers); INIT_HTC_PACKET_QUEUE(&pEndpoint->TxQueue); INIT_HTC_PACKET_QUEUE(&pEndpoint->RecvIndicationQueue); @@ -525,6 +527,7 @@ bool HTCGetEndpointStatistics(HTC_HANDLE HTCHandle, struct htc_endpoint_stats *pStats) { +#ifdef HTC_EP_STAT_PROFILING struct htc_target *target = GET_HTC_TARGET_FROM_HANDLE(HTCHandle); bool clearStats = false; bool sample = false; @@ -565,6 +568,9 @@ bool HTCGetEndpointStatistics(HTC_HANDLE HTCHandle, UNLOCK_HTC_TX(target); return true; +#else + return false; +#endif } struct ar6k_device *HTCGetAR6KDevice(void *HTCHandle) diff --git a/trunk/drivers/staging/ath6kl/htc2/htc_internal.h b/trunk/drivers/staging/ath6kl/htc2/htc_internal.h index 1c9aeca41143..9425ed983671 100644 --- a/trunk/drivers/staging/ath6kl/htc2/htc_internal.h +++ b/trunk/drivers/staging/ath6kl/htc2/htc_internal.h @@ -27,6 +27,7 @@ * processing errors, the last frame header is dump for comparison */ //#define HTC_CAPTURE_LAST_FRAME +//#define HTC_EP_STAT_PROFILING #ifdef __cplusplus extern "C" { @@ -81,10 +82,17 @@ struct htc_endpoint { struct htc_target *target; /* back pointer to target */ u8 SeqNo; /* TX seq no (helpful) for debugging */ u32 LocalConnectionFlags; /* local connection flags */ +#ifdef HTC_EP_STAT_PROFILING struct htc_endpoint_stats EndPointStats; /* endpoint statistics */ +#endif }; +#ifdef HTC_EP_STAT_PROFILING #define INC_HTC_EP_STAT(p,stat,count) (p)->EndPointStats.stat += (count); +#else +#define INC_HTC_EP_STAT(p,stat,count) +#endif + #define HTC_SERVICE_TX_PACKET_TAG HTC_TX_PACKET_TAG_INTERNAL #define NUM_CONTROL_BUFFERS 8 diff --git a/trunk/drivers/staging/ath6kl/htc2/htc_recv.c b/trunk/drivers/staging/ath6kl/htc2/htc_recv.c index 974cc8cd6936..c2088018c51d 100644 --- a/trunk/drivers/staging/ath6kl/htc2/htc_recv.c +++ b/trunk/drivers/staging/ath6kl/htc2/htc_recv.c @@ -36,6 +36,7 @@ (pP)->PktInfo.AsRx.ExpectedHdr, \ (pP)->Endpoint)) +#ifdef HTC_EP_STAT_PROFILING #define HTC_RX_STAT_PROFILE(t,ep,numLookAheads) \ { \ INC_HTC_EP_STAT((ep), RxReceived, 1); \ @@ -45,6 +46,9 @@ INC_HTC_EP_STAT((ep), RxBundleLookAheads, 1); \ } \ } +#else +#define HTC_RX_STAT_PROFILE(t,ep,lookAhead) +#endif static void DoRecvCompletion(struct htc_endpoint *pEndpoint, struct htc_packet_queue *pQueueToIndicate) @@ -927,10 +931,12 @@ static void HTCAsyncRecvScatterCompletion(struct hif_scatter_req *pScatterReq) } if (!status) { +#ifdef HTC_EP_STAT_PROFILING LOCK_HTC_RX(target); HTC_RX_STAT_PROFILE(target,pEndpoint,numLookAheads); INC_HTC_EP_STAT(pEndpoint, RxPacketsBundled, 1); UNLOCK_HTC_RX(target); +#endif if (i == (pScatterReq->ValidScatterEntries - 1)) { /* last packet's more packets flag is set based on the lookahead */ SET_MORE_RX_PACKET_INDICATION_FLAG(lookAheads,numLookAheads,pEndpoint,pPacket); diff --git a/trunk/drivers/staging/ath6kl/htc2/htc_send.c b/trunk/drivers/staging/ath6kl/htc2/htc_send.c index 9310d4d5c992..6f4050a98c85 100644 --- a/trunk/drivers/staging/ath6kl/htc2/htc_send.c +++ b/trunk/drivers/staging/ath6kl/htc2/htc_send.c @@ -776,6 +776,9 @@ void HTCProcessCreditRpt(struct htc_target *target, HTC_CREDIT_REPORT *pRpt, int AR_DEBUG_PRINTF(ATH_DEBUG_SEND, (" Endpoint %d got %d credits \n", pRpt->EndpointID, pRpt->Credits)); + +#ifdef HTC_EP_STAT_PROFILING + INC_HTC_EP_STAT(pEndpoint, TxCreditRpts, 1); INC_HTC_EP_STAT(pEndpoint, TxCreditsReturned, pRpt->Credits); @@ -794,6 +797,8 @@ void HTCProcessCreditRpt(struct htc_target *target, HTC_CREDIT_REPORT *pRpt, int INC_HTC_EP_STAT(pEndpoint, TxCreditRptsFromOther, 1); } +#endif + if (ENDPOINT_0 == pRpt->EndpointID) { /* always give endpoint 0 credits back */ pEndpoint->CreditDist.TxCredits += pRpt->Credits; diff --git a/trunk/drivers/staging/ath6kl/include/a_config.h b/trunk/drivers/staging/ath6kl/include/a_config.h index f7c09319433f..4a0083c65113 100644 --- a/trunk/drivers/staging/ath6kl/include/a_config.h +++ b/trunk/drivers/staging/ath6kl/include/a_config.h @@ -26,6 +26,28 @@ #ifndef _A_CONFIG_H_ #define _A_CONFIG_H_ +#ifdef UNDER_NWIFI +#include "../os/windows/include/config.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/config.h" +#endif + +#if defined(__linux__) && !defined(LINUX_EMULATION) #include "../os/linux/include/config_linux.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/config_rexos.h" +#endif + +#ifdef WIN_NWF +#include "../os/windows/include/win/config_win.h" +#endif + +#ifdef THREADX +#include "../os/threadx/include/common/config_threadx.h" +#endif #endif diff --git a/trunk/drivers/staging/ath6kl/include/a_debug.h b/trunk/drivers/staging/ath6kl/include/a_debug.h index 51cb633ee6ce..d433942e2b98 100644 --- a/trunk/drivers/staging/ath6kl/include/a_debug.h +++ b/trunk/drivers/staging/ath6kl/include/a_debug.h @@ -187,7 +187,35 @@ void a_dump_module_debug_info_by_name(char *module_name); void a_module_debug_support_init(void); void a_module_debug_support_cleanup(void); +#ifdef UNDER_NWIFI +#include "../os/windows/include/debug.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/debug.h" +#endif + +#if defined(__linux__) && !defined(LINUX_EMULATION) #include "../os/linux/include/debug_linux.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/debug_rexos.h" +#endif + +#if defined ART_WIN +#include "../os/win_art/include/debug_win.h" +#endif + +#ifdef WIN_NWF +#include +#endif + +#ifdef THREADX +#define ATH_DEBUG_MAKE_MODULE_MASK(index) (1 << (ATH_DEBUG_MODULE_MASK_SHIFT + (index))) +#include "../os/threadx/include/common/debug_threadx.h" +#endif + #ifdef __cplusplus } diff --git a/trunk/drivers/staging/ath6kl/include/a_drv.h b/trunk/drivers/staging/ath6kl/include/a_drv.h index 1548604e8465..6db10f0f2d10 100644 --- a/trunk/drivers/staging/ath6kl/include/a_drv.h +++ b/trunk/drivers/staging/ath6kl/include/a_drv.h @@ -27,6 +27,28 @@ #ifndef _A_DRV_H_ #define _A_DRV_H_ +#if defined(__linux__) && !defined(LINUX_EMULATION) #include "../os/linux/include/athdrv_linux.h" +#endif + +#ifdef UNDER_NWIFI +#include "../os/windows/include/athdrv.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/athdrv.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/athdrv_rexos.h" +#endif + +#ifdef WIN_NWF +#include "../os/windows/include/athdrv.h" +#endif + +#ifdef THREADX +#include "../os/threadx/include/common/athdrv_threadx.h" +#endif #endif /* _ADRV_H_ */ diff --git a/trunk/drivers/staging/ath6kl/include/a_drv_api.h b/trunk/drivers/staging/ath6kl/include/a_drv_api.h index a40d97a84ffc..5e098cb30f56 100644 --- a/trunk/drivers/staging/ath6kl/include/a_drv_api.h +++ b/trunk/drivers/staging/ath6kl/include/a_drv_api.h @@ -130,6 +130,34 @@ extern "C" { #define A_WMI_PEER_EVENT(devt, eventCode, bssid) \ ar6000_peer_event ((devt), (eventCode), (bssid)) +#ifdef CONFIG_HOST_GPIO_SUPPORT + +#define A_WMI_GPIO_INTR_RX(intr_mask, input_values) \ + ar6000_gpio_intr_rx((intr_mask), (input_values)) + +#define A_WMI_GPIO_DATA_RX(reg_id, value) \ + ar6000_gpio_data_rx((reg_id), (value)) + +#define A_WMI_GPIO_ACK_RX() \ + ar6000_gpio_ack_rx() + +#endif + +#ifdef SEND_EVENT_TO_APP + +#define A_WMI_SEND_EVENT_TO_APP(ar, eventId, datap, len) \ + ar6000_send_event_to_app((ar), (eventId), (datap), (len)) + +#define A_WMI_SEND_GENERIC_EVENT_TO_APP(ar, eventId, datap, len) \ + ar6000_send_generic_event_to_app((ar), (eventId), (datap), (len)) + +#else + +#define A_WMI_SEND_EVENT_TO_APP(ar, eventId, datap, len) +#define A_WMI_SEND_GENERIC_EVENT_TO_APP(ar, eventId, datap, len) + +#endif + #ifdef CONFIG_HOST_TCMD_SUPPORT #define A_WMI_TCMD_RX_REPORT_EVENT(devt, results, len) \ ar6000_tcmd_rx_report_event((devt), (results), (len)) diff --git a/trunk/drivers/staging/ath6kl/include/a_osapi.h b/trunk/drivers/staging/ath6kl/include/a_osapi.h index fd7ae0d612c6..7bdeeea21503 100644 --- a/trunk/drivers/staging/ath6kl/include/a_osapi.h +++ b/trunk/drivers/staging/ath6kl/include/a_osapi.h @@ -27,6 +27,35 @@ #ifndef _A_OSAPI_H_ #define _A_OSAPI_H_ +#if defined(__linux__) && !defined(LINUX_EMULATION) #include "../os/linux/include/osapi_linux.h" +#endif + +#ifdef UNDER_NWIFI +#include "../os/windows/include/osapi.h" +#include "../os/windows/include/netbuf.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/osapi.h" +#include "../os/windows/include/netbuf.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/osapi_rexos.h" +#endif + +#if defined ART_WIN +#include "../os/win_art/include/osapi_win.h" +#include "../os/win_art/include/netbuf.h" +#endif + +#ifdef WIN_NWF +#include +#endif + +#if defined(THREADX) +#include "../os/threadx/include/common/osapi_threadx.h" +#endif #endif /* _OSAPI_H_ */ diff --git a/trunk/drivers/staging/ath6kl/include/a_types.h b/trunk/drivers/staging/ath6kl/include/a_types.h index 4b6783f6aec7..18f4cfe4f97d 100644 --- a/trunk/drivers/staging/ath6kl/include/a_types.h +++ b/trunk/drivers/staging/ath6kl/include/a_types.h @@ -27,6 +27,32 @@ #ifndef _A_TYPES_H_ #define _A_TYPES_H_ +#if defined(__linux__) && !defined(LINUX_EMULATION) #include "../os/linux/include/athtypes_linux.h" +#endif + +#ifdef UNDER_NWIFI +#include "../os/windows/include/athtypes.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/athtypes.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/athtypes_rexos.h" +#endif + +#if defined ART_WIN +#include "../os/win_art/include/athtypes_win.h" +#endif + +#ifdef WIN_NWF +#include +#endif + +#ifdef THREADX +#include "../os/threadx/include/common/athtypes_threadx.h" +#endif #endif /* _ATHTYPES_H_ */ diff --git a/trunk/drivers/staging/ath6kl/include/ar6000_api.h b/trunk/drivers/staging/ath6kl/include/ar6000_api.h index e9460800272c..1e1d92a507e2 100644 --- a/trunk/drivers/staging/ath6kl/include/ar6000_api.h +++ b/trunk/drivers/staging/ath6kl/include/ar6000_api.h @@ -26,7 +26,29 @@ #ifndef _AR6000_API_H_ #define _AR6000_API_H_ +#if defined(__linux__) && !defined(LINUX_EMULATION) #include "../os/linux/include/ar6xapi_linux.h" +#endif + +#ifdef UNDER_NWIFI +#include "../os/windows/include/ar6xapi.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/ar6xapi.h" +#endif + +#ifdef REXOS +#include "../os/rexos/include/common/ar6xapi_rexos.h" +#endif + +#if defined ART_WIN +#include "../os/win_art/include/ar6xapi_win.h" +#endif + +#ifdef WIN_NWF +#include "../os/windows/include/ar6xapi.h" +#endif #endif /* _AR6000_API_H */ diff --git a/trunk/drivers/staging/ath6kl/include/athendpack.h b/trunk/drivers/staging/ath6kl/include/athendpack.h new file mode 100644 index 000000000000..1b940503bb21 --- /dev/null +++ b/trunk/drivers/staging/ath6kl/include/athendpack.h @@ -0,0 +1,52 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// end compiler-specific structure packing +// +// Author(s): ="Atheros" +//============================================================================== +#ifdef VXWORKS +#endif /* VXWORKS */ + +#if defined(LINUX) || defined(__linux__) +#endif /* LINUX */ + +#ifdef QNX +#endif /* QNX */ + +#ifdef INTEGRITY +#include "integrity/athendpack_integrity.h" +#endif /* INTEGRITY */ + +#ifdef NUCLEUS +#endif /* NUCLEUS */ + + +#ifdef UNDER_NWIFI +#include "../os/windows/include/athendpack.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/athendpack.h" +#endif /* WINCE */ + +#ifdef WIN_NWF +#include +#endif diff --git a/trunk/drivers/staging/ath6kl/include/athstartpack.h b/trunk/drivers/staging/ath6kl/include/athstartpack.h new file mode 100644 index 000000000000..1c45f666d8a2 --- /dev/null +++ b/trunk/drivers/staging/ath6kl/include/athstartpack.h @@ -0,0 +1,55 @@ +//------------------------------------------------------------------------------ +// +// Copyright (c) 2004-2010 Atheros Corporation. All rights reserved. +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +//------------------------------------------------------------------------------ +//============================================================================== +// start compiler-specific structure packing +// +// Author(s): ="Atheros" +//============================================================================== +#ifdef VXWORKS +#endif /* VXWORKS */ + +#if defined(LINUX) || defined(__linux__) +#endif /* LINUX */ + +#ifdef QNX +#endif /* QNX */ + +#ifdef INTEGRITY +#include "integrity/athstartpack_integrity.h" +#endif /* INTEGRITY */ + +#ifdef NUCLEUS +#endif /* NUCLEUS */ + +#ifdef UNDER_NWIFI +#include "../os/windows/include/athstartpack.h" +#endif + +#ifdef ATHR_CE_LEGACY +#include "../os/windows/include/athstartpack.h" +#endif /* WINCE */ + +#ifdef WIN_NWF +#include +#endif + +#ifdef THREADX +#include "../os/threadx/include/common/osapi_threadx.h" +#endif diff --git a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/analog_intf_reg.h b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/analog_intf_reg.h index b8de1c9efd5c..01b9eb54a43c 100644 --- a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/analog_intf_reg.h +++ b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/analog_intf_reg.h @@ -21,4 +21,17 @@ //=================================================================== +#ifdef WLAN_HEADERS + #include "analog_intf_athr_wlan_reg.h" + + +#ifndef BT_HEADERS + + + +#endif +#endif + + + diff --git a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/apb_map.h b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/apb_map.h index 0068ca31b051..e4d2d62f0bb4 100644 --- a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/apb_map.h +++ b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/apb_map.h @@ -21,8 +21,11 @@ //=================================================================== +#ifdef WLAN_HEADERS + #include "apb_athr_wlan_map.h" + #ifndef BT_HEADERS #define RTC_BASE_ADDRESS WLAN_RTC_BASE_ADDRESS @@ -37,4 +40,9 @@ #define MAC_BASE_ADDRESS WLAN_MAC_BASE_ADDRESS #define RDMA_BASE_ADDRESS WLAN_RDMA_BASE_ADDRESS + +#endif #endif + + + diff --git a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/gpio_reg.h b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/gpio_reg.h index afef47ebf1f8..b3e7126e26a2 100644 --- a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/gpio_reg.h +++ b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/gpio_reg.h @@ -21,8 +21,11 @@ //=================================================================== +#ifdef WLAN_HEADERS + #include "gpio_athr_wlan_reg.h" + #ifndef BT_HEADERS #define GPIO_OUT_ADDRESS WLAN_GPIO_OUT_ADDRESS @@ -1083,4 +1086,9 @@ #define RESET_TUPLE_STATUS_PIN_RESET_TUPLE_GET(x) WLAN_RESET_TUPLE_STATUS_PIN_RESET_TUPLE_GET(x) #define RESET_TUPLE_STATUS_PIN_RESET_TUPLE_SET(x) WLAN_RESET_TUPLE_STATUS_PIN_RESET_TUPLE_SET(x) + +#endif #endif + + + diff --git a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/mbox_host_reg.h b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/mbox_host_reg.h index 109f24e10a65..3af562156f6e 100644 --- a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/mbox_host_reg.h +++ b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/mbox_host_reg.h @@ -21,4 +21,17 @@ //=================================================================== +#ifdef WLAN_HEADERS + #include "mbox_wlan_host_reg.h" + + +#ifndef BT_HEADERS + + + +#endif +#endif + + + diff --git a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/mbox_reg.h b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/mbox_reg.h index 72fa483450d6..cc67585e2e8b 100644 --- a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/mbox_reg.h +++ b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/mbox_reg.h @@ -21,8 +21,11 @@ //=================================================================== +#ifdef WLAN_HEADERS + #include "mbox_wlan_reg.h" + #ifndef BT_HEADERS #define MBOX_FIFO_ADDRESS WLAN_MBOX_FIFO_ADDRESS @@ -549,4 +552,9 @@ #define HOST_IF_WINDOW_DATA_GET(x) WLAN_HOST_IF_WINDOW_DATA_GET(x) #define HOST_IF_WINDOW_DATA_SET(x) WLAN_HOST_IF_WINDOW_DATA_SET(x) + +#endif #endif + + + diff --git a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/rtc_reg.h b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/rtc_reg.h index 82bd708eba35..0855de5f1400 100644 --- a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/rtc_reg.h +++ b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/rtc_reg.h @@ -21,8 +21,11 @@ //=================================================================== +#ifdef WLAN_HEADERS + #include "rtc_wlan_reg.h" + #ifndef BT_HEADERS #define RESET_CONTROL_ADDRESS WLAN_RESET_CONTROL_ADDRESS @@ -964,4 +967,9 @@ #define GPIO_WAKEUP_CONTROL_ENABLE_GET(x) WLAN_GPIO_WAKEUP_CONTROL_ENABLE_GET(x) #define GPIO_WAKEUP_CONTROL_ENABLE_SET(x) WLAN_GPIO_WAKEUP_CONTROL_ENABLE_SET(x) + +#endif #endif + + + diff --git a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/umbox_reg.h b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/umbox_reg.h index b18ff48171a8..b233cbc513bc 100644 --- a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/umbox_reg.h +++ b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/umbox_reg.h @@ -20,4 +20,18 @@ // Author(s): ="Atheros" //=================================================================== + +#ifdef WLAN_HEADERS + #include "umbox_wlan_reg.h" + + +#ifndef BT_HEADERS + + + +#endif +#endif + + + diff --git a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/vmc_reg.h b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/vmc_reg.h index 990f2be2cd18..c3d8088a5554 100644 --- a/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/vmc_reg.h +++ b/trunk/drivers/staging/ath6kl/include/common/AR6002/hw4.0/hw/vmc_reg.h @@ -21,8 +21,11 @@ //=================================================================== +#ifdef WLAN_HEADERS + #include "vmc_wlan_reg.h" + #ifndef BT_HEADERS #define MC_BCAM_VALID_ADDRESS WLAN_MC_BCAM_VALID_ADDRESS @@ -156,4 +159,9 @@ #define CPU_RAM4_CONFLICT_CNT_GET(x) WLAN_CPU_RAM4_CONFLICT_CNT_GET(x) #define CPU_RAM4_CONFLICT_CNT_SET(x) WLAN_CPU_RAM4_CONFLICT_CNT_SET(x) + +#endif #endif + + + diff --git a/trunk/drivers/staging/ath6kl/include/common/bmi_msg.h b/trunk/drivers/staging/ath6kl/include/common/bmi_msg.h index 84e8db569a9f..e76624c5915c 100644 --- a/trunk/drivers/staging/ath6kl/include/common/bmi_msg.h +++ b/trunk/drivers/staging/ath6kl/include/common/bmi_msg.h @@ -22,6 +22,10 @@ #ifndef __BMI_MSG_H__ #define __BMI_MSG_H__ +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + /* * Bootloader Messaging Interface (BMI) * @@ -230,4 +234,8 @@ PREPACK struct bmi_target_info { * Note: Not supported on all versions of ROM firmware. */ +#ifndef ATH_TARGET +#include "athendpack.h" +#endif + #endif /* __BMI_MSG_H__ */ diff --git a/trunk/drivers/staging/ath6kl/include/common/dbglog.h b/trunk/drivers/staging/ath6kl/include/common/dbglog.h index 5566e568b83d..b7a123086ccf 100644 --- a/trunk/drivers/staging/ath6kl/include/common/dbglog.h +++ b/trunk/drivers/staging/ath6kl/include/common/dbglog.h @@ -24,6 +24,10 @@ #ifndef _DBGLOG_H_ #define _DBGLOG_H_ +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + #ifdef __cplusplus extern "C" { #endif @@ -123,4 +127,8 @@ PREPACK struct dbglog_config_s { } #endif +#ifndef ATH_TARGET +#include "athendpack.h" +#endif + #endif /* _DBGLOG_H_ */ diff --git a/trunk/drivers/staging/ath6kl/include/common/dset_internal.h b/trunk/drivers/staging/ath6kl/include/common/dset_internal.h index e3ecd8e1a3c3..69475331eab7 100644 --- a/trunk/drivers/staging/ath6kl/include/common/dset_internal.h +++ b/trunk/drivers/staging/ath6kl/include/common/dset_internal.h @@ -25,6 +25,10 @@ #ifndef __DSET_INTERNAL_H__ #define __DSET_INTERNAL_H__ +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + /* * Internal dset definitions, common for DataSet layer. */ @@ -52,4 +56,8 @@ typedef PREPACK struct dset_descriptor_s { Dataset descriptor for BPatch. */ } POSTPACK dset_descriptor_t; +#ifndef ATH_TARGET +#include "athendpack.h" +#endif + #endif /* __DSET_INTERNAL_H__ */ diff --git a/trunk/drivers/staging/ath6kl/include/common/dsetid.h b/trunk/drivers/staging/ath6kl/include/common/dsetid.h index cc797bab5c4c..090e30967925 100644 --- a/trunk/drivers/staging/ath6kl/include/common/dsetid.h +++ b/trunk/drivers/staging/ath6kl/include/common/dsetid.h @@ -25,6 +25,10 @@ #ifndef __DSETID_H__ #define __DSETID_H__ +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + /* Well-known DataSet IDs */ #define DSETID_UNUSED 0x00000000 #define DSETID_BOARD_DATA 0x00000001 /* Cal and board data */ @@ -123,4 +127,8 @@ PREPACK struct patch_s { */ #define DSETID_BPATCH_FLAG 0x80000000 +#ifndef ATH_TARGET +#include "athendpack.h" +#endif + #endif /* __DSETID_H__ */ diff --git a/trunk/drivers/staging/ath6kl/include/common/epping_test.h b/trunk/drivers/staging/ath6kl/include/common/epping_test.h index 9eb5fdfa746a..7027fac8f37e 100644 --- a/trunk/drivers/staging/ath6kl/include/common/epping_test.h +++ b/trunk/drivers/staging/ath6kl/include/common/epping_test.h @@ -25,6 +25,10 @@ #ifndef EPPING_TEST_H_ #define EPPING_TEST_H_ +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + /* alignment to 4-bytes */ #define EPPING_ALIGNMENT_PAD (((sizeof(struct htc_frame_hdr) + 3) & (~0x3)) - sizeof(struct htc_frame_hdr)) @@ -108,4 +112,9 @@ typedef PREPACK struct { #define HCI_TRANSPORT_STREAM_NUM 16 /* this number is higher than the define WMM AC classes so we can use this to distinguish packets */ +#ifndef ATH_TARGET +#include "athendpack.h" +#endif + + #endif /*EPPING_TEST_H_*/ diff --git a/trunk/drivers/staging/ath6kl/include/common/gmboxif.h b/trunk/drivers/staging/ath6kl/include/common/gmboxif.h index ea11c14def43..dd9afbd78ff9 100644 --- a/trunk/drivers/staging/ath6kl/include/common/gmboxif.h +++ b/trunk/drivers/staging/ath6kl/include/common/gmboxif.h @@ -23,6 +23,10 @@ #ifndef __GMBOXIF_H__ #define __GMBOXIF_H__ +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + /* GMBOX interface definitions */ #define AR6K_GMBOX_CREDIT_COUNTER 1 /* we use credit counter 1 to track credits */ @@ -66,5 +70,9 @@ typedef PREPACK struct { #define MBOX_SIG_HCI_BRIDGE_PWR_SAV_OFF 4 +#ifndef ATH_TARGET +#include "athendpack.h" +#endif + #endif /* __GMBOXIF_H__ */ diff --git a/trunk/drivers/staging/ath6kl/include/common/htc.h b/trunk/drivers/staging/ath6kl/include/common/htc.h index 85cbfa89d670..b9d4495d4324 100644 --- a/trunk/drivers/staging/ath6kl/include/common/htc.h +++ b/trunk/drivers/staging/ath6kl/include/common/htc.h @@ -24,6 +24,10 @@ #ifndef __HTC_H__ #define __HTC_H__ +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + #define A_OFFSETOF(type,field) (unsigned long)(&(((type *)NULL)->field)) #define ASSEMBLE_UNALIGNED_UINT16(p,highbyte,lowbyte) \ @@ -223,5 +227,10 @@ typedef PREPACK struct { u8 LookAhead[4]; /* 4 byte lookahead */ } POSTPACK HTC_BUNDLED_LOOKAHEAD_REPORT; +#ifndef ATH_TARGET +#include "athendpack.h" +#endif + + #endif /* __HTC_H__ */ diff --git a/trunk/drivers/staging/ath6kl/include/common/regdump.h b/trunk/drivers/staging/ath6kl/include/common/regdump.h index 614dfa102ea1..aa64821617e8 100644 --- a/trunk/drivers/staging/ath6kl/include/common/regdump.h +++ b/trunk/drivers/staging/ath6kl/include/common/regdump.h @@ -24,6 +24,10 @@ #ifndef __REGDUMP_H__ #define __REGDUMP_H__ +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + #if defined(AR6001) #include "AR6001/AR6001_regdump.h" #endif @@ -48,4 +52,8 @@ PREPACK struct register_dump_s { } POSTPACK; #endif /* __ASSEMBLER__ */ +#ifndef ATH_TARGET +#include "athendpack.h" +#endif + #endif /* __REGDUMP_H__ */ diff --git a/trunk/drivers/staging/ath6kl/include/common/targaddrs.h b/trunk/drivers/staging/ath6kl/include/common/targaddrs.h index b172209799bb..794ae2182a77 100644 --- a/trunk/drivers/staging/ath6kl/include/common/targaddrs.h +++ b/trunk/drivers/staging/ath6kl/include/common/targaddrs.h @@ -22,6 +22,10 @@ #ifndef __TARGADDRS_H__ #define __TARGADDRS_H__ +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + #if defined(AR6002) #include "AR6002/addrs.h" #endif @@ -87,7 +91,15 @@ PREPACK struct host_interest_s { /* Pointer to debug logging header */ u32 hi_dbglog_hdr; /* 0x08 */ - u32 hi_unused1; /* 0x0c */ + /* Indicates whether or not flash is present on Target. + * NB: flash_is_present indicator is here not just + * because it might be of interest to the Host; but + * also because it's set early on by Target's startup + * asm code and we need it to have a special RAM address + * so that it doesn't get reinitialized with the rest + * of data. + */ + u32 hi_flash_is_present; /* 0x0c */ /* * General-purpose flag bits, similar to AR6000_OPTION_* flags. @@ -101,7 +113,7 @@ PREPACK struct host_interest_s { */ u32 hi_serial_enable; /* 0x14 */ - /* Start address of DataSet index, if any */ + /* Start address of Flash DataSet index, if any */ u32 hi_dset_list_head; /* 0x18 */ /* Override Target application start address */ @@ -159,179 +171,35 @@ PREPACK struct host_interest_s { u32 hi_hci_uart_support_pins; /* 0xa4 */ /* NOTE: byte [0] = RESET pin (bit 7 is polarity), bytes[1]..bytes[3] are for future use */ u32 hi_hci_uart_pwr_mgmt_params; /* 0xa8 */ - /* - * 0xa8 - [1]: 0 = UART FC active low, 1 = UART FC active high - * [31:16]: wakeup timeout in ms - */ - - /* Pointer to extended board data */ - u32 hi_board_ext_data; /* 0xac */ - u32 hi_board_ext_data_config; /* 0xb0 */ - - /* - * Bit [0] : valid - * Bit[31:16: size - */ - /* - * hi_reset_flag is used to do some stuff when target reset. - * such as restore app_start after warm reset or - * preserve host Interest area, or preserve ROM data, literals etc. - */ - u32 hi_reset_flag; /* 0xb4 */ - /* indicate hi_reset_flag is valid */ - u32 hi_reset_flag_valid; /* 0xb8 */ - u32 hi_hci_uart_pwr_mgmt_params_ext; /* 0xbc */ - /* - * 0xbc - [31:0]: idle timeout in ms - */ - /* ACS flags */ - u32 hi_acs_flags; /* 0xc0 */ - u32 hi_console_flags; /* 0xc4 */ - u32 hi_nvram_state; /* 0xc8 */ - u32 hi_option_flag2; /* 0xcc */ - - /* If non-zero, override values sent to Host in WMI_READY event. */ - u32 hi_sw_version_override; /* 0xd0 */ - u32 hi_abi_version_override; /* 0xd4 */ - - /* - * Percentage of high priority RX traffic to total expected RX traffic - - * applicable only to ar6004 - */ - u32 hi_hp_rx_traffic_ratio; /* 0xd8 */ - - /* test applications flags */ - u32 hi_test_apps_related ; /* 0xdc */ - /* location of test script */ - u32 hi_ota_testscript; /* 0xe0 */ - /* location of CAL data */ - u32 hi_cal_data; /* 0xe4 */ - /* Number of packet log buffers */ - u32 hi_pktlog_num_buffers; /* 0xe8 */ - + /* 0xa8 - [0]: 1 = enable, 0 = disable + * [1]: 0 = UART FC active low, 1 = UART FC active high + * 0xa9 - [7:0]: wakeup timeout in ms + * 0xaa, 0xab - [15:0]: idle timeout in ms + */ + /* Pointer to extended board Data */ + u32 hi_board_ext_data; /* 0xac */ + u32 hi_board_ext_data_initialized; /* 0xb0 */ } POSTPACK; /* Bits defined in hi_option_flag */ #define HI_OPTION_TIMER_WAR 0x01 /* Enable timer workaround */ #define HI_OPTION_BMI_CRED_LIMIT 0x02 /* Limit BMI command credits */ #define HI_OPTION_RELAY_DOT11_HDR 0x04 /* Relay Dot11 hdr to/from host */ -/* MAC addr method 0-locally administred 1-globally unique addrs */ -#define HI_OPTION_MAC_ADDR_METHOD 0x08 -#define HI_OPTION_FW_BRIDGE 0x10 /* Firmware Bridging */ -#define HI_OPTION_ENABLE_PROFILE 0x20 /* Enable CPU profiling */ -#define HI_OPTION_DISABLE_DBGLOG 0x40 /* Disable debug logging */ -#define HI_OPTION_SKIP_ERA_TRACKING 0x80 /* Skip Era Tracking */ -#define HI_OPTION_PAPRD_DISABLE 0x100 /* Disable PAPRD (debug) */ -#define HI_OPTION_NUM_DEV_LSB 0x200 -#define HI_OPTION_NUM_DEV_MSB 0x800 -#define HI_OPTION_DEV_MODE_LSB 0x1000 -#define HI_OPTION_DEV_MODE_MSB 0x8000000 -/* Disable LowFreq Timer Stabilization */ -#define HI_OPTION_NO_LFT_STBL 0x10000000 -#define HI_OPTION_SKIP_REG_SCAN 0x20000000 /* Skip regulatory scan */ -/* Do regulatory scan during init beforesending WMI ready event to host */ -#define HI_OPTION_INIT_REG_SCAN 0x40000000 -#define HI_OPTION_SKIP_MEMMAP 0x80000000 /* REV6: Do not adjust memory - map */ - -/* hi_option_flag2 options */ -#define HI_OPTION_OFFLOAD_AMSDU 0x01 -#define HI_OPTION_DFS_SUPPORT 0x02 /* Enable DFS support */ - -#define HI_OPTION_MAC_ADDR_METHOD_SHIFT 3 +#define HI_OPTION_FW_MODE_LSB 0x08 /* low bit of MODE (see below) */ +#define HI_OPTION_FW_MODE_MSB 0x10 /* high bit of MODE (see below) */ +#define HI_OPTION_ENABLE_PROFILE 0x20 /* Enable CPU profiling */ +#define HI_OPTION_DISABLE_DBGLOG 0x40 /* Disable debug logging */ +#define HI_OPTION_SKIP_ERA_TRACKING 0x80 /* Skip Era Tracking */ +#define HI_OPTION_PAPRD_DISABLE 0x100 /* Disable PAPRD (debug) */ /* 2 bits of hi_option_flag are used to represent 3 modes */ #define HI_OPTION_FW_MODE_IBSS 0x0 /* IBSS Mode */ #define HI_OPTION_FW_MODE_BSS_STA 0x1 /* STA Mode */ #define HI_OPTION_FW_MODE_AP 0x2 /* AP Mode */ -/* 2 bits of hi_option flag are usedto represent 4 submodes */ -#define HI_OPTION_FW_SUBMODE_NONE 0x0 /* Normal mode */ -#define HI_OPTION_FW_SUBMODE_P2PDEV 0x1 /* p2p device mode */ -#define HI_OPTION_FW_SUBMODE_P2PCLIENT 0x2 /* p2p client mode */ -#define HI_OPTION_FW_SUBMODE_P2PGO 0x3 /* p2p go mode */ - -/* Num dev Mask */ -#define HI_OPTION_NUM_DEV_MASK 0x7 -#define HI_OPTION_NUM_DEV_SHIFT 0x9 - -/* firmware bridging */ -#define HI_OPTION_FW_BRIDGE_SHIFT 0x04 - -/* Fw Mode/SubMode Mask -|------------------------------------------------------------------------------| -| SUB | SUB | SUB | SUB | | | | -| MODE[3] | MODE[2] | MODE[1] | MODE[0] | MODE[3] | MODE[2] | MODE[1] | MODE[0| -| (2) | (2) | (2) | (2) | (2) | (2) | (2) | (2) -|------------------------------------------------------------------------------| -*/ -#define HI_OPTION_FW_MODE_BITS 0x2 -#define HI_OPTION_FW_MODE_MASK 0x3 -#define HI_OPTION_FW_MODE_SHIFT 0xC -#define HI_OPTION_ALL_FW_MODE_MASK 0xFF - -#define HI_OPTION_FW_SUBMODE_BITS 0x2 -#define HI_OPTION_FW_SUBMODE_MASK 0x3 -#define HI_OPTION_FW_SUBMODE_SHIFT 0x14 -#define HI_OPTION_ALL_FW_SUBMODE_MASK 0xFF00 -#define HI_OPTION_ALL_FW_SUBMODE_SHIFT 0x8 - -/* hi_reset_flag */ - -/* preserve App Start address */ -#define HI_RESET_FLAG_PRESERVE_APP_START 0x01 -/* preserve host interest */ -#define HI_RESET_FLAG_PRESERVE_HOST_INTEREST 0x02 -#define HI_RESET_FLAG_PRESERVE_ROMDATA 0x04 /* preserve ROM data */ -#define HI_RESET_FLAG_PRESERVE_NVRAM_STATE 0x08 -#define HI_RESET_FLAG_PRESERVE_BOOT_INFO 0x10 - -#define HI_RESET_FLAG_IS_VALID 0x12345678 /* indicate the reset flag is -valid */ - -#define ON_RESET_FLAGS_VALID() \ - (HOST_INTEREST->hi_reset_flag_valid == HI_RESET_FLAG_IS_VALID) - -#define RESET_FLAGS_VALIDATE() \ - (HOST_INTEREST->hi_reset_flag_valid = HI_RESET_FLAG_IS_VALID) - -#define RESET_FLAGS_INVALIDATE() \ - (HOST_INTEREST->hi_reset_flag_valid = 0) - -#define ON_RESET_PRESERVE_APP_START() \ - (HOST_INTEREST->hi_reset_flag & HI_RESET_FLAG_PRESERVE_APP_START) - -#define ON_RESET_PRESERVE_NVRAM_STATE() \ - (HOST_INTEREST->hi_reset_flag & HI_RESET_FLAG_PRESERVE_NVRAM_STATE) - -#define ON_RESET_PRESERVE_HOST_INTEREST() \ - (HOST_INTEREST->hi_reset_flag & HI_RESET_FLAG_PRESERVE_HOST_INTEREST) - -#define ON_RESET_PRESERVE_ROMDATA() \ - (HOST_INTEREST->hi_reset_flag & HI_RESET_FLAG_PRESERVE_ROMDATA) - -#define ON_RESET_PRESERVE_BOOT_INFO() \ - (HOST_INTEREST->hi_reset_flag & HI_RESET_FLAG_PRESERVE_BOOT_INFO) - -#define HI_ACS_FLAGS_ENABLED (1 << 0) /* ACS is enabled */ -#define HI_ACS_FLAGS_USE_WWAN (1 << 1) /* Use physical WWAN device */ -#define HI_ACS_FLAGS_TEST_VAP (1 << 2) /* Use test VAP */ - -/* CONSOLE FLAGS - * - * Bit Range Meaning - * --------- -------------------------------- - * 2..0 UART ID (0 = Default) - * 3 Baud Select (0 = 9600, 1 = 115200) - * 30..4 Reserved - * 31 Enable Console - * - */ - -#define HI_CONSOLE_FLAGS_ENABLE (1 << 31) -#define HI_CONSOLE_FLAGS_UART_MASK (0x7) -#define HI_CONSOLE_FLAGS_UART_SHIFT 0 -#define HI_CONSOLE_FLAGS_BAUD_SELECT (1 << 3) +/* Fw Mode Mask */ +#define HI_OPTION_FW_MODE_MASK 0x3 +#define HI_OPTION_FW_MODE_SHIFT 0x3 /* * Intended for use by Host software, this macro returns the Target RAM @@ -344,52 +212,34 @@ valid */ #define AR6003_HOST_INTEREST_ITEM_ADDRESS(item) \ (u32)((unsigned long)&((((struct host_interest_s *)(AR6003_HOST_INTEREST_ADDRESS))->item))) -#define AR6004_HOST_INTEREST_ITEM_ADDRESS(item) \ - ((A_UINT32)&((((struct host_interest_s *)(AR6004_HOST_INTEREST_ADDRESS))->item))) - - #define HOST_INTEREST_DBGLOG_IS_ENABLED() \ (!(HOST_INTEREST->hi_option_flag & HI_OPTION_DISABLE_DBGLOG)) -#define HOST_INTEREST_PKTLOG_IS_ENABLED() \ - ((HOST_INTEREST->hi_pktlog_num_buffers)) - - #define HOST_INTEREST_PROFILE_IS_ENABLED() \ (HOST_INTEREST->hi_option_flag & HI_OPTION_ENABLE_PROFILE) -#define LF_TIMER_STABILIZATION_IS_ENABLED() \ - (!(HOST_INTEREST->hi_option_flag & HI_OPTION_NO_LFT_STBL)) - -#define IS_AMSDU_OFFLAOD_ENABLED() \ - ((HOST_INTEREST->hi_option_flag2 & HI_OPTION_OFFLOAD_AMSDU)) - -#define HOST_INTEREST_DFS_IS_ENABLED() \ - ((HOST_INTEREST->hi_option_flag2 & HI_OPTION_DFS_SUPPORT)) - /* Convert a Target virtual address into a Target physical address */ #define AR6002_VTOP(vaddr) ((vaddr) & 0x001fffff) #define AR6003_VTOP(vaddr) ((vaddr) & 0x001fffff) #define TARG_VTOP(TargetType, vaddr) \ (((TargetType) == TARGET_TYPE_AR6002) ? AR6002_VTOP(vaddr) : AR6003_VTOP(vaddr)) -#define AR6003_REV2_APP_START_OVERRIDE 0x944C00 -#define AR6003_REV2_APP_LOAD_ADDRESS 0x543180 -#define AR6003_REV2_BOARD_EXT_DATA_ADDRESS 0x57E500 -#define AR6003_REV2_DATASET_PATCH_ADDRESS 0x57e884 -#define AR6003_REV2_RAM_RESERVE_SIZE 6912 - -#define AR6003_REV3_APP_START_OVERRIDE 0x945d00 -#define AR6003_REV3_APP_LOAD_ADDRESS 0x545000 -#define AR6003_REV3_BOARD_EXT_DATA_ADDRESS 0x542330 -#define AR6003_REV3_DATASET_PATCH_ADDRESS 0x57FF74 -#define AR6003_REV3_RAM_RESERVE_SIZE 512 +/* override REV2 ROM's app start address */ +#define AR6002_REV2_APP_START_OVERRIDE 0x911A00 +#define AR6003_REV1_APP_START_OVERRIDE 0x944c00 +#define AR6003_REV1_OTP_DATA_ADDRESS 0x542800 +#define AR6003_REV2_APP_START_OVERRIDE 0x945000 +#define AR6003_REV2_OTP_DATA_ADDRESS 0x543800 +#define AR6003_BOARD_EXT_DATA_ADDRESS 0x57E600 -#define AR6003_BOARD_EXT_DATA_ADDRESS 0x57E600 /* # of u32 entries in targregs, used by DIAG_FETCH_TARG_REGS */ #define AR6003_FETCH_TARG_REGS_COUNT 64 #endif /* !__ASSEMBLER__ */ +#ifndef ATH_TARGET +#include "athendpack.h" +#endif + #endif /* __TARGADDRS_H__ */ diff --git a/trunk/drivers/staging/ath6kl/include/common/wmi.h b/trunk/drivers/staging/ath6kl/include/common/wmi.h index 24636e6b9643..4e6343485362 100644 --- a/trunk/drivers/staging/ath6kl/include/common/wmi.h +++ b/trunk/drivers/staging/ath6kl/include/common/wmi.h @@ -34,6 +34,10 @@ #ifndef _WMI_H_ #define _WMI_H_ +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + #include "wmix.h" #include "wlan_defs.h" @@ -114,7 +118,7 @@ typedef enum { typedef enum { WMI_DATA_HDR_DATA_TYPE_802_3 = 0, WMI_DATA_HDR_DATA_TYPE_802_11, - WMI_DATA_HDR_DATA_TYPE_ACL, /* used to be used for the PAL */ + WMI_DATA_HDR_DATA_TYPE_ACL, } WMI_DATA_HDR_DATA_TYPE; #define WMI_DATA_HDR_DATA_TYPE_MASK 0x3 @@ -155,16 +159,6 @@ typedef enum { #define WMI_DATA_HDR_GET_META(h) (((h)->info2 >> WMI_DATA_HDR_META_SHIFT) & WMI_DATA_HDR_META_MASK) #define WMI_DATA_HDR_SET_META(h, _v) ((h)->info2 = ((h)->info2 & ~(WMI_DATA_HDR_META_MASK << WMI_DATA_HDR_META_SHIFT)) | ((_v) << WMI_DATA_HDR_META_SHIFT)) -/* Macros for operating on WMI_DATA_HDR (info3) field */ -#define WMI_DATA_HDR_DEVID_MASK 0xF -#define WMI_DATA_HDR_DEVID_SHIFT 0 -#define GET_DEVID(_v) ((_v) & WMI_DATA_HDR_DEVID_MASK) - -#define WMI_DATA_HDR_GET_DEVID(h) \ - (((h)->info3 >> WMI_DATA_HDR_DEVID_SHIFT) & WMI_DATA_HDR_DEVID_MASK) -#define WMI_DATA_HDR_SET_DEVID(h, _v) \ - ((h)->info3 = ((h)->info3 & ~(WMI_DATA_HDR_DEVID_MASK << WMI_DATA_HDR_DEVID_SHIFT)) | (GET_DEVID(_v) << WMI_DATA_HDR_DEVID_SHIFT)) - typedef PREPACK struct { s8 rssi; u8 info; /* usage of 'info' field(8-bit): @@ -181,7 +175,7 @@ typedef PREPACK struct { * b12 - A-MSDU? * b15:b13 - META_DATA_VERSION 0 - 7 */ - u16 info3; + u16 reserved; } POSTPACK WMI_DATA_HDR; /* @@ -265,17 +259,6 @@ typedef PREPACK struct { #define WMI_GET_DEVICE_ID(info1) ((info1) & 0xF) -/* Macros for operating on WMI_CMD_HDR (info1) field */ -#define WMI_CMD_HDR_DEVID_MASK 0xF -#define WMI_CMD_HDR_DEVID_SHIFT 0 -#define GET_CMD_DEVID(_v) ((_v) & WMI_CMD_HDR_DEVID_MASK) - -#define WMI_CMD_HDR_GET_DEVID(h) \ - (((h)->info1 >> WMI_CMD_HDR_DEVID_SHIFT) & WMI_CMD_HDR_DEVID_MASK) -#define WMI_CMD_HDR_SET_DEVID(h, _v) \ - ((h)->info1 = ((h)->info1 & \ - ~(WMI_CMD_HDR_DEVID_MASK << WMI_CMD_HDR_DEVID_SHIFT)) | \ - (GET_CMD_DEVID(_v) << WMI_CMD_HDR_DEVID_SHIFT)) /* * Control Path @@ -450,47 +433,13 @@ typedef enum { WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMDID, WMI_GET_BTCOEX_STATS_CMDID, WMI_GET_BTCOEX_CONFIG_CMDID, - - WMI_SET_DFS_ENABLE_CMDID, /* F034 */ - WMI_SET_DFS_MINRSSITHRESH_CMDID, - WMI_SET_DFS_MAXPULSEDUR_CMDID, - WMI_DFS_RADAR_DETECTED_CMDID, - - /* P2P CMDS */ - WMI_P2P_SET_CONFIG_CMDID, /* F038 */ - WMI_WPS_SET_CONFIG_CMDID, - WMI_SET_REQ_DEV_ATTR_CMDID, - WMI_P2P_FIND_CMDID, - WMI_P2P_STOP_FIND_CMDID, - WMI_P2P_GO_NEG_START_CMDID, - WMI_P2P_LISTEN_CMDID, - - WMI_CONFIG_TX_MAC_RULES_CMDID, /* F040 */ - WMI_SET_PROMISCUOUS_MODE_CMDID, - WMI_RX_FRAME_FILTER_CMDID, - WMI_SET_CHANNEL_CMDID, - - /* WAC commands */ - WMI_ENABLE_WAC_CMDID, - WMI_WAC_SCAN_REPLY_CMDID, - WMI_WAC_CTRL_REQ_CMDID, - WMI_SET_DIV_PARAMS_CMDID, - - WMI_GET_PMK_CMDID, - WMI_SET_PASSPHRASE_CMDID, - WMI_SEND_ASSOC_RES_CMDID, - WMI_SET_ASSOC_REQ_RELAY_CMDID, - WMI_GET_RFKILL_MODE_CMDID, - - /* ACS command, consists of sub-commands */ - WMI_ACS_CTRL_CMDID, - - /* Ultra low power store / recall commands */ - WMI_STORERECALL_CONFIGURE_CMDID, - WMI_STORERECALL_RECALL_CMDID, - WMI_STORERECALL_HOST_READY_CMDID, - WMI_FORCE_TARGET_ASSERT_CMDID, - WMI_SET_EXCESS_TX_RETRY_THRES_CMDID, + WMI_GET_PMK_CMDID, + WMI_SET_PASSPHRASE_CMDID, + WMI_ENABLE_WAC_CMDID, + WMI_WAC_SCAN_REPLY_CMDID, + WMI_WAC_CTRL_REQ_CMDID, + WMI_SET_DIV_PARAMS_CMDID, + WMI_SET_EXCESS_TX_RETRY_THRES_CMDID, } WMI_COMMAND_ID; /* @@ -2020,47 +1969,12 @@ typedef enum { #endif WMI_REPORT_BTCOEX_STATS_EVENTID, WMI_REPORT_BTCOEX_CONFIG_EVENTID, - WMI_GET_PMK_EVENTID, - - /* DFS Events */ - WMI_DFS_HOST_ATTACH_EVENTID, - WMI_DFS_HOST_INIT_EVENTID, - WMI_DFS_RESET_DELAYLINES_EVENTID, - WMI_DFS_RESET_RADARQ_EVENTID, - WMI_DFS_RESET_AR_EVENTID, - WMI_DFS_RESET_ARQ_EVENTID, - WMI_DFS_SET_DUR_MULTIPLIER_EVENTID, - WMI_DFS_SET_BANGRADAR_EVENTID, - WMI_DFS_SET_DEBUGLEVEL_EVENTID, - WMI_DFS_PHYERR_EVENTID, - /* CCX Evants */ - WMI_CCX_RM_STATUS_EVENTID, - - /* P2P Events */ - WMI_P2P_GO_NEG_RESULT_EVENTID, - - WMI_WAC_SCAN_DONE_EVENTID, - WMI_WAC_REPORT_BSS_EVENTID, - WMI_WAC_START_WPS_EVENTID, - WMI_WAC_CTRL_REQ_REPLY_EVENTID, - - /* RFKILL Events */ - WMI_RFKILL_STATE_CHANGE_EVENTID, - WMI_RFKILL_GET_MODE_CMD_EVENTID, - WMI_THIN_RESERVED_START_EVENTID = 0x8000, - - /* - * Events in this range are reserved for thinmode - * See wmi_thin.h for actual definitions - */ - WMI_THIN_RESERVED_END_EVENTID = 0x8fff, - - WMI_SET_CHANNEL_EVENTID, - WMI_ASSOC_REQ_EVENTID, - - /* generic ACS event */ - WMI_ACS_EVENTID, - WMI_REPORT_WMM_PARAMS_EVENTID + WMI_ACM_REJECT_EVENTID, + WMI_THIN_RESERVED_START_EVENTID = 0x8000, + /* Events in this range are reserved for thinmode + * See wmi_thin.h for actual definitions */ + WMI_THIN_RESERVED_END_EVENTID = 0x8fff, + } WMI_EVENT_ID; @@ -3208,6 +3122,10 @@ typedef PREPACK struct { * End of AP mode definitions */ +#ifndef ATH_TARGET +#include "athendpack.h" +#endif + #ifdef __cplusplus } #endif diff --git a/trunk/drivers/staging/ath6kl/include/common/wmix.h b/trunk/drivers/staging/ath6kl/include/common/wmix.h index 1ab6fc532934..36acba66d49f 100644 --- a/trunk/drivers/staging/ath6kl/include/common/wmix.h +++ b/trunk/drivers/staging/ath6kl/include/common/wmix.h @@ -40,6 +40,10 @@ extern "C" { #endif +#ifndef ATH_TARGET +#include "athstartpack.h" +#endif + #include "dbglog.h" /* @@ -264,6 +268,9 @@ typedef PREPACK struct { u32 count; } POSTPACK WMIX_PROF_COUNT_EVENT; +#ifndef ATH_TARGET +#include "athendpack.h" +#endif #ifdef __cplusplus } diff --git a/trunk/drivers/staging/ath6kl/include/common_drv.h b/trunk/drivers/staging/ath6kl/include/common_drv.h index 34db29958bcb..b6063347229f 100644 --- a/trunk/drivers/staging/ath6kl/include/common_drv.h +++ b/trunk/drivers/staging/ath6kl/include/common_drv.h @@ -81,6 +81,10 @@ int ar6000_set_htc_params(struct hif_device *hifDevice, u32 MboxIsrYieldValue, u8 HtcControlBuffers); +int ar6000_prepare_target(struct hif_device *hifDevice, + u32 TargetType, + u32 TargetVersion); + int ar6000_set_hci_bridge_flags(struct hif_device *hifDevice, u32 TargetType, u32 Flags); diff --git a/trunk/drivers/staging/ath6kl/miscdrv/ar3kconfig.c b/trunk/drivers/staging/ath6kl/miscdrv/ar3kconfig.c index 5125edcca90a..4f18f4306465 100644 --- a/trunk/drivers/staging/ath6kl/miscdrv/ar3kconfig.c +++ b/trunk/drivers/staging/ath6kl/miscdrv/ar3kconfig.c @@ -78,7 +78,7 @@ static int SendHCICommand(struct ar3k_config_info *pConfig, } while (false); if (pPacket != NULL) { - kfree(pPacket); + A_FREE(pPacket); } return status; @@ -116,7 +116,7 @@ static int RecvHCIEvent(struct ar3k_config_info *pConfig, } while (false); if (pRecvPacket != NULL) { - kfree(pRecvPacket); + A_FREE(pRecvPacket); } return status; @@ -203,7 +203,7 @@ int SendHCICommandWaitCommandComplete(struct ar3k_config_info *pConfig, } while (false); if (pBuffer != NULL) { - kfree(pBuffer); + A_FREE(pBuffer); } return status; @@ -268,7 +268,7 @@ static int AR3KConfigureHCIBaud(struct ar3k_config_info *pConfig) } while (false); if (pBufferToFree != NULL) { - kfree(pBufferToFree); + A_FREE(pBufferToFree); } return status; @@ -304,7 +304,7 @@ static int AR3KExitMinBoot(struct ar3k_config_info *pConfig) } if (pBufferToFree != NULL) { - kfree(pBufferToFree); + A_FREE(pBufferToFree); } return status; @@ -328,7 +328,7 @@ static int AR3KConfigureSendHCIReset(struct ar3k_config_info *pConfig) } if (pBufferToFree != NULL) { - kfree(pBufferToFree); + A_FREE(pBufferToFree); } return status; @@ -382,7 +382,7 @@ static int AR3KEnableTLPM(struct ar3k_config_info *pConfig) &pEvent, &pBufferToFree); if (pBufferToFree != NULL) { - kfree(pBufferToFree); + A_FREE(pBufferToFree); } if (status) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HostWakeup Config Failed! \n")); @@ -397,7 +397,7 @@ static int AR3KEnableTLPM(struct ar3k_config_info *pConfig) &pEvent, &pBufferToFree); if (pBufferToFree != NULL) { - kfree(pBufferToFree); + A_FREE(pBufferToFree); } if (status) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Target Wakeup Config Failed! \n")); @@ -412,7 +412,7 @@ static int AR3KEnableTLPM(struct ar3k_config_info *pConfig) &pEvent, &pBufferToFree); if (pBufferToFree != NULL) { - kfree(pBufferToFree); + A_FREE(pBufferToFree); } if (status) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("HostWakeup Enable Failed! \n")); @@ -427,7 +427,7 @@ static int AR3KEnableTLPM(struct ar3k_config_info *pConfig) &pEvent, &pBufferToFree); if (pBufferToFree != NULL) { - kfree(pBufferToFree); + A_FREE(pBufferToFree); } if (status) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Target Wakeup Enable Failed! \n")); @@ -442,7 +442,7 @@ static int AR3KEnableTLPM(struct ar3k_config_info *pConfig) &pEvent, &pBufferToFree); if (pBufferToFree != NULL) { - kfree(pBufferToFree); + A_FREE(pBufferToFree); } if (status) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Sleep Enable Failed! \n")); diff --git a/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsconfig.c b/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsconfig.c index 282ceac597b8..8393efe69f5b 100644 --- a/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsconfig.c +++ b/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsconfig.c @@ -222,7 +222,7 @@ int PSSendOps(void *arg) A_RELEASE_FIRMWARE(firmware); /* Parse the PS buffer to a global variable */ status = AthDoParsePS(buffer,len); - kfree(buffer); + A_FREE(buffer); } else { A_RELEASE_FIRMWARE(firmware); } @@ -256,7 +256,7 @@ int PSSendOps(void *arg) A_RELEASE_FIRMWARE(firmware); /* parse and store the Patch file contents to a global variables */ status = AthDoParsePatch(buffer,len); - kfree(buffer); + A_FREE(buffer); } else { A_RELEASE_FIRMWARE(firmware); } @@ -283,7 +283,7 @@ int PSSendOps(void *arg) &bufferToFree) == 0) { if(ReadPSEvent(event) == 0) { /* Exit if the status is success */ if(bufferToFree != NULL) { - kfree(bufferToFree); + A_FREE(bufferToFree); } #ifndef HCI_TRANSPORT_SDIO @@ -295,7 +295,7 @@ int PSSendOps(void *arg) goto complete; } if(bufferToFree != NULL) { - kfree(bufferToFree); + A_FREE(bufferToFree); } } else { status = 0; @@ -312,13 +312,13 @@ int PSSendOps(void *arg) &bufferToFree) == 0) { if(ReadPSEvent(event) != 0) { /* Exit if the status is success */ if(bufferToFree != NULL) { - kfree(bufferToFree); + A_FREE(bufferToFree); } status = 1; goto complete; } if(bufferToFree != NULL) { - kfree(bufferToFree); + A_FREE(bufferToFree); } } else { status = 0; @@ -376,10 +376,10 @@ int PSSendOps(void *arg) AthFreeCommandList(&HciCmdList,numCmds); } if(path) { - kfree(path); + A_FREE(path); } if(config_path) { - kfree(config_path); + A_FREE(config_path); } return status; } @@ -511,7 +511,7 @@ int write_bdaddr(struct ar3k_config_info *pConfig,u8 *bdaddr,int type) } if(bufferToFree != NULL) { - kfree(bufferToFree); + A_FREE(bufferToFree); } return result; @@ -527,7 +527,7 @@ int ReadVersionInfo(struct ar3k_config_info *pConfig) } if(bufferToFree != NULL) { - kfree(bufferToFree); + A_FREE(bufferToFree); } return result; } @@ -564,7 +564,7 @@ int getDeviceType(struct ar3k_config_info *pConfig, u32 *code) } if(bufferToFree != NULL) { - kfree(bufferToFree); + A_FREE(bufferToFree); } return result; } diff --git a/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c b/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c index c01c0cb0af4e..94a0939bfbf2 100644 --- a/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c +++ b/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.c @@ -362,7 +362,7 @@ int AthParseFilesUnified(u8 *srcbuffer,u32 srclen, int FileFormat) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("error\n")); if(Buffer != NULL) { - kfree(Buffer); + A_FREE(Buffer); } return A_ERROR; } @@ -401,7 +401,7 @@ int AthParseFilesUnified(u8 *srcbuffer,u32 srclen, int FileFormat) if(uGetInputDataFormat(pCharLine, &stPS_DataFormat)) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat fail\n")); if(Buffer != NULL) { - kfree(Buffer); + A_FREE(Buffer); } return A_ERROR; } @@ -422,7 +422,7 @@ int AthParseFilesUnified(u8 *srcbuffer,u32 srclen, int FileFormat) if(uGetInputDataFormat(pCharLine, &stPS_DataFormat)) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat fail \n")); if(Buffer != NULL) { - kfree(Buffer); + A_FREE(Buffer); } return A_ERROR; } @@ -433,7 +433,7 @@ int AthParseFilesUnified(u8 *srcbuffer,u32 srclen, int FileFormat) if (ByteCount > LINE_SIZE_MAX/2) { if(Buffer != NULL) { - kfree(Buffer); + A_FREE(Buffer); } return A_ERROR; } @@ -449,7 +449,7 @@ int AthParseFilesUnified(u8 *srcbuffer,u32 srclen, int FileFormat) if(uGetInputDataFormat(pCharLine,&stPS_DataFormat)) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("uGetInputDataFormat Fail\n")); if(Buffer != NULL) { - kfree(Buffer); + A_FREE(Buffer); } return A_ERROR; } @@ -510,7 +510,7 @@ int AthParseFilesUnified(u8 *srcbuffer,u32 srclen, int FileFormat) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("\n Buffer over flow PS File too big!!!")); if(Buffer != NULL) { - kfree(Buffer); + A_FREE(Buffer); } return A_ERROR; //Sleep (3000); @@ -524,7 +524,7 @@ int AthParseFilesUnified(u8 *srcbuffer,u32 srclen, int FileFormat) default: { if(Buffer != NULL) { - kfree(Buffer); + A_FREE(Buffer); } return A_ERROR; } @@ -541,13 +541,13 @@ int AthParseFilesUnified(u8 *srcbuffer,u32 srclen, int FileFormat) { if(Buffer != NULL) { - kfree(Buffer); + A_FREE(Buffer); } return A_ERROR; } if(Buffer != NULL) { - kfree(Buffer); + A_FREE(Buffer); } return 0; @@ -609,7 +609,7 @@ int AthDoParsePatch(u8 *patchbuffer, u32 patchlen) /* Handle case when the number of patch buffer is more than the 20K */ if(MAX_NUM_PATCH_ENTRY == Patch_Count) { for(i = 0; i < Patch_Count; i++) { - kfree(RamPatch[i].Data); + A_FREE(RamPatch[i].Data); } return A_ERROR; } @@ -812,13 +812,13 @@ int AthCreateCommandList(struct ps_cmd_packet **HciPacketList, u32 *numPackets) for(count = 0; count < Patch_Count; count++) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Freeing Patch Buffer %d \r\n",count)); - kfree(RamPatch[Patch_Count].Data); + A_FREE(RamPatch[Patch_Count].Data); } for(count = 0; count < Tag_Count; count++) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Freeing PS Buffer %d \r\n",count)); - kfree(PsTagEntry[count].TagData); + A_FREE(PsTagEntry[count].TagData); } /* @@ -962,8 +962,8 @@ int AthFreeCommandList(struct ps_cmd_packet **HciPacketList, u32 numPackets) return A_ERROR; } for(i = 0; i < numPackets;i++) { - kfree((*HciPacketList)[i].Hcipacket); + A_FREE((*HciPacketList)[i].Hcipacket); } - kfree(*HciPacketList); + A_FREE(*HciPacketList); return 0; } diff --git a/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.h b/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.h index cd0a9e827cff..9378efcd586e 100644 --- a/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.h +++ b/trunk/drivers/staging/ath6kl/miscdrv/ar3kps/ar3kpsparser.h @@ -60,6 +60,11 @@ #ifndef A_MALLOC #define A_MALLOC(size) kmalloc((size),GFP_KERNEL) #endif /* A_MALLOC */ + + +#ifndef A_FREE +#define A_FREE(addr) kfree((addr)) +#endif /* A_MALLOC */ #endif /* HCI_TRANSPORT_UART */ /* String manipulation APIs */ diff --git a/trunk/drivers/staging/ath6kl/miscdrv/common_drv.c b/trunk/drivers/staging/ath6kl/miscdrv/common_drv.c index 2be2ea494f53..a23a52412b3d 100644 --- a/trunk/drivers/staging/ath6kl/miscdrv/common_drv.c +++ b/trunk/drivers/staging/ath6kl/miscdrv/common_drv.c @@ -683,6 +683,40 @@ int ar6000_set_htc_params(struct hif_device *hifDevice, return status; } + +static int prepare_ar6002(struct hif_device *hifDevice, u32 TargetVersion) +{ + int status = 0; + + /* placeholder */ + + return status; +} + +static int prepare_ar6003(struct hif_device *hifDevice, u32 TargetVersion) +{ + int status = 0; + + /* placeholder */ + + return status; +} + +/* this function assumes the caller has already initialized the BMI APIs */ +int ar6000_prepare_target(struct hif_device *hifDevice, + u32 TargetType, + u32 TargetVersion) +{ + if (TargetType == TARGET_TYPE_AR6002) { + /* do any preparations for AR6002 devices */ + return prepare_ar6002(hifDevice,TargetVersion); + } else if (TargetType == TARGET_TYPE_AR6003) { + return prepare_ar6003(hifDevice,TargetVersion); + } + + return 0; +} + #if defined(CONFIG_AR6002_REV1_FORCE_HOST) /* * Call this function just before the call to BMIInit diff --git a/trunk/drivers/staging/ath6kl/os/linux/ar6000_android.c b/trunk/drivers/staging/ath6kl/os/linux/ar6000_android.c new file mode 100644 index 000000000000..4aa75ee2cb13 --- /dev/null +++ b/trunk/drivers/staging/ath6kl/os/linux/ar6000_android.c @@ -0,0 +1,388 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ +#include "ar6000_drv.h" +#include "htc.h" +#include +#include + +#ifdef CONFIG_HAS_EARLYSUSPEND +#include +#endif + +bool enable_mmc_host_detect_change = false; +static void ar6000_enable_mmchost_detect_change(int enable); + + +char fwpath[256] = "/system/wifi"; +int wowledon; +unsigned int enablelogcat; + +extern int bmienable; +extern struct net_device *ar6000_devices[]; +extern char ifname[]; + +const char def_ifname[] = "wlan0"; +module_param_string(fwpath, fwpath, sizeof(fwpath), 0644); +module_param(enablelogcat, uint, 0644); +module_param(wowledon, int, 0644); + +#ifdef CONFIG_HAS_EARLYSUSPEND +static int screen_is_off; +static struct early_suspend ar6k_early_suspend; +#endif + +static int (*ar6000_avail_ev_p)(void *, void *); + +#if defined(CONFIG_ANDROID_LOGGER) && (!defined(CONFIG_MMC_MSM)) +int logger_write(const enum logidx index, + const unsigned char prio, + const char __kernel * const tag, + const char __kernel * const fmt, + ...) +{ + int ret = 0; + va_list vargs; + struct file *filp = (struct file *)-ENOENT; + mm_segment_t oldfs; + struct iovec vec[3]; + int tag_bytes = strlen(tag) + 1, msg_bytes; + char *msg; + va_start(vargs, fmt); + msg = kvasprintf(GFP_ATOMIC, fmt, vargs); + va_end(vargs); + if (!msg) + return -ENOMEM; + if (in_interrupt()) { + /* we have no choice since aio_write may be blocked */ + printk(KERN_ALERT "%s", msg); + goto out_free_message; + } + msg_bytes = strlen(msg) + 1; + if (msg_bytes <= 1) /* empty message? */ + goto out_free_message; /* don't bother, then */ + if ((msg_bytes + tag_bytes + 1) > 2048) { + ret = -E2BIG; + goto out_free_message; + } + + vec[0].iov_base = (unsigned char *) &prio; + vec[0].iov_len = 1; + vec[1].iov_base = (void *) tag; + vec[1].iov_len = strlen(tag) + 1; + vec[2].iov_base = (void *) msg; + vec[2].iov_len = strlen(msg) + 1; + + oldfs = get_fs(); + set_fs(KERNEL_DS); + do { + filp = filp_open("/dev/log/main", O_WRONLY, S_IRUSR); + if (IS_ERR(filp) || !filp->f_op) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: filp_open /dev/log/main error\n", __FUNCTION__)); + ret = -ENOENT; + break; + } + + if (filp->f_op->aio_write) { + int nr_segs = sizeof(vec) / sizeof(vec[0]); + int len = vec[0].iov_len + vec[1].iov_len + vec[2].iov_len; + struct kiocb kiocb; + init_sync_kiocb(&kiocb, filp); + kiocb.ki_pos = 0; + kiocb.ki_left = len; + kiocb.ki_nbytes = len; + ret = filp->f_op->aio_write(&kiocb, vec, nr_segs, kiocb.ki_pos); + } + + } while (0); + + if (!IS_ERR(filp)) { + filp_close(filp, NULL); + } + set_fs(oldfs); +out_free_message: + kfree(msg); + return ret; +} +#endif + +int android_logger_lv(void *module, int mask) +{ + switch (mask) { + case ATH_DEBUG_ERR: + return 6; + case ATH_DEBUG_INFO: + return 4; + case ATH_DEBUG_WARN: + return 5; + case ATH_DEBUG_TRC: + return 3; + default: +#ifdef DEBUG + if (!module) { + return 3; + } else if (module == &GET_ATH_MODULE_DEBUG_VAR_NAME(driver)) { + return (mask <=ATH_DEBUG_MAKE_MODULE_MASK(3)) ? 3 : 2; + } else if (module == &GET_ATH_MODULE_DEBUG_VAR_NAME(htc)) { + return 2; + } else { + return 3; + } +#else + return 3; /* DEBUG */ +#endif + } +} + +static int android_readwrite_file(const char *filename, char *rbuf, const char *wbuf, size_t length) +{ + int ret = 0; + struct file *filp = (struct file *)-ENOENT; + mm_segment_t oldfs; + oldfs = get_fs(); + set_fs(KERNEL_DS); + do { + int mode = (wbuf) ? O_RDWR : O_RDONLY; + filp = filp_open(filename, mode, S_IRUSR); + if (IS_ERR(filp) || !filp->f_op) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: file %s filp_open error\n", __FUNCTION__, filename)); + ret = -ENOENT; + break; + } + + if (length==0) { + /* Read the length of the file only */ + struct inode *inode; + + inode = GET_INODE_FROM_FILEP(filp); + if (!inode) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Get inode from %s failed\n", __FUNCTION__, filename)); + ret = -ENOENT; + break; + } + ret = i_size_read(inode->i_mapping->host); + break; + } + + if (wbuf) { + if ( (ret=filp->f_op->write(filp, wbuf, length, &filp->f_pos)) < 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Write %u bytes to file %s error %d\n", __FUNCTION__, + length, filename, ret)); + break; + } + } else { + if ( (ret=filp->f_op->read(filp, rbuf, length, &filp->f_pos)) < 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Read %u bytes from file %s error %d\n", __FUNCTION__, + length, filename, ret)); + break; + } + } + } while (0); + + if (!IS_ERR(filp)) { + filp_close(filp, NULL); + } + set_fs(oldfs); + + return ret; +} + +int android_request_firmware(const struct firmware **firmware_p, const char *name, + struct device *device) +{ + int ret = 0; + struct firmware *firmware; + char filename[256]; + const char *raw_filename = name; + *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); + if (!firmware) + return -ENOMEM; + sprintf(filename, "%s/%s", fwpath, raw_filename); + do { + size_t length, bufsize, bmisize; + + if ( (ret=android_readwrite_file(filename, NULL, NULL, 0)) < 0) { + break; + } else { + length = ret; + } + + bufsize = ALIGN(length, PAGE_SIZE); + bmisize = A_ROUND_UP(length, 4); + bufsize = max(bmisize, bufsize); + firmware->data = vmalloc(bufsize); + firmware->size = length; + if (!firmware->data) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: Cannot allocate buffer for firmware\n", __FUNCTION__)); + ret = -ENOMEM; + break; + } + + if ( (ret=android_readwrite_file(filename, (char*)firmware->data, NULL, length)) != length) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: file read error, ret %d request %d\n", __FUNCTION__, ret, length)); + ret = -1; + break; + } + + } while (0); + + if (ret<0) { + if (firmware) { + if (firmware->data) + vfree(firmware->data); + kfree(firmware); + } + *firmware_p = NULL; + } else { + ret = 0; + } + return ret; +} + +void android_release_firmware(const struct firmware *firmware) +{ + if (firmware) { + if (firmware->data) + vfree(firmware->data); + kfree(firmware); + } +} + +static int ar6000_android_avail_ev(void *context, void *hif_handle) +{ + int ret; + ar6000_enable_mmchost_detect_change(0); + ret = ar6000_avail_ev_p(context, hif_handle); + return ret; +} + +/* Useful for qualcom platform to detect our wlan card for mmc stack */ +static void ar6000_enable_mmchost_detect_change(int enable) +{ +#ifdef CONFIG_MMC_MSM +#define MMC_MSM_DEV "msm_sdcc.1" + char buf[3]; + int length; + + if (!enable_mmc_host_detect_change) { + return; + } + length = snprintf(buf, sizeof(buf), "%d\n", enable ? 1 : 0); + if (android_readwrite_file("/sys/devices/platform/" MMC_MSM_DEV "/detect_change", + NULL, buf, length) < 0) { + /* fall back to polling */ + android_readwrite_file("/sys/devices/platform/" MMC_MSM_DEV "/polling", NULL, buf, length); + } +#endif +} + +#ifdef CONFIG_HAS_EARLYSUSPEND +static void android_early_suspend(struct early_suspend *h) +{ + screen_is_off = 1; +} + +static void android_late_resume(struct early_suspend *h) +{ + screen_is_off = 0; +} +#endif + +void android_module_init(OSDRV_CALLBACKS *osdrvCallbacks) +{ + bmienable = 1; + if (ifname[0] == '\0') + strcpy(ifname, def_ifname); +#ifdef CONFIG_HAS_EARLYSUSPEND + ar6k_early_suspend.suspend = android_early_suspend; + ar6k_early_suspend.resume = android_late_resume; + ar6k_early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN; + register_early_suspend(&ar6k_early_suspend); +#endif + + ar6000_avail_ev_p = osdrvCallbacks->deviceInsertedHandler; + osdrvCallbacks->deviceInsertedHandler = ar6000_android_avail_ev; + + ar6000_enable_mmchost_detect_change(1); +} + +void android_module_exit(void) +{ +#ifdef CONFIG_HAS_EARLYSUSPEND + unregister_early_suspend(&ar6k_early_suspend); +#endif + ar6000_enable_mmchost_detect_change(1); +} + +#ifdef CONFIG_PM +void android_ar6k_check_wow_status(struct ar6_softc *ar, struct sk_buff *skb, bool isEvent) +{ + if ( +#ifdef CONFIG_HAS_EARLYSUSPEND + screen_is_off && +#endif + skb && ar->arConnected) { + bool needWake = false; + if (isEvent) { + if (A_NETBUF_LEN(skb) >= sizeof(u16)) { + u16 cmd = *(const u16 *)A_NETBUF_DATA(skb); + switch (cmd) { + case WMI_CONNECT_EVENTID: + case WMI_DISCONNECT_EVENTID: + needWake = true; + break; + default: + /* dont wake lock the system for other event */ + break; + } + } + } else if (A_NETBUF_LEN(skb) >= sizeof(ATH_MAC_HDR)) { + ATH_MAC_HDR *datap = (ATH_MAC_HDR *)A_NETBUF_DATA(skb); + if (!IEEE80211_IS_MULTICAST(datap->dstMac)) { + switch (A_BE2CPU16(datap->typeOrLen)) { + case 0x0800: /* IP */ + case 0x888e: /* EAPOL */ + case 0x88c7: /* RSN_PREAUTH */ + case 0x88b4: /* WAPI */ + needWake = true; + break; + case 0x0806: /* ARP is not important to hold wake lock */ + default: + break; + } + } + } + if (needWake) { + /* keep host wake up if there is any event and packate coming in*/ + if (wowledon) { + char buf[32]; + int len = sprintf(buf, "on"); + android_readwrite_file("/sys/power/state", NULL, buf, len); + + len = sprintf(buf, "%d", 127); + android_readwrite_file("/sys/class/leds/lcd-backlight/brightness", + NULL, buf,len); + } + } + } +} +#endif /* CONFIG_PM */ diff --git a/trunk/drivers/staging/ath6kl/os/linux/ar6000_drv.c b/trunk/drivers/staging/ath6kl/os/linux/ar6000_drv.c index 36722ed6b533..97d6ce63b5c0 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/ar6000_drv.c +++ b/trunk/drivers/staging/ath6kl/os/linux/ar6000_drv.c @@ -27,7 +27,9 @@ */ #include "ar6000_drv.h" +#ifdef ATH6K_CONFIG_CFG80211 #include "cfg80211.h" +#endif /* ATH6K_CONFIG_CFG80211 */ #include "htc.h" #include "wmi_filter_linux.h" #include "epping_test.h" @@ -116,6 +118,7 @@ struct hci_transport_callbacks ar6kHciTransCallbacks = { NULL }; #endif unsigned int processDot11Hdr = 0; +int bmienable = BMIENABLE_DEFAULT; char ifname[IFNAMSIZ] = {0,}; @@ -131,8 +134,6 @@ unsigned int wlanNodeCaching = 1; unsigned int enableuartprint = ENABLEUARTPRINT_DEFAULT; unsigned int logWmiRawMsgs = 0; unsigned int enabletimerwar = 0; -unsigned int num_device = 1; -unsigned int regscanmode; unsigned int fwmode = 1; unsigned int mbox_yield_limit = 99; unsigned int enablerssicompensation = 0; @@ -147,6 +148,7 @@ unsigned int panic_on_assert = 1; unsigned int nohifscattersupport = NOHIFSCATTERSUPPORT_DEFAULT; unsigned int setuphci = SETUPHCI_DEFAULT; +unsigned int setuphcipal = SETUPHCIPAL_DEFAULT; unsigned int loghci = 0; unsigned int setupbtdev = SETUPBTDEV_DEFAULT; #ifndef EXPORT_HCI_BRIDGE_INTERFACE @@ -154,14 +156,15 @@ unsigned int ar3khcibaud = AR3KHCIBAUD_DEFAULT; unsigned int hciuartscale = HCIUARTSCALE_DEFAULT; unsigned int hciuartstep = HCIUARTSTEP_DEFAULT; #endif +#ifdef CONFIG_CHECKSUM_OFFLOAD unsigned int csumOffload=0; unsigned int csumOffloadTest=0; +#endif unsigned int eppingtest=0; -unsigned int mac_addr_method; -unsigned int firmware_bridge; module_param_string(ifname, ifname, sizeof(ifname), 0644); module_param(wlaninitmode, int, 0644); +module_param(bmienable, int, 0644); module_param(bypasswmi, bool, 0644); module_param(debuglevel, uint, 0644); module_param(tspecCompliance, int, 0644); @@ -179,7 +182,9 @@ module_param(reduce_credit_dribble, int, 0644); module_param(allow_trace_signal, int, 0644); module_param(enablerssicompensation, uint, 0644); module_param(processDot11Hdr, uint, 0644); +#ifdef CONFIG_CHECKSUM_OFFLOAD module_param(csumOffload, uint, 0644); +#endif #ifdef CONFIG_HOST_TCMD_SUPPORT module_param(testmode, uint, 0644); #endif @@ -187,6 +192,7 @@ module_param(irqprocmode, uint, 0644); module_param(nohifscattersupport, uint, 0644); module_param(panic_on_assert, uint, 0644); module_param(setuphci, uint, 0644); +module_param(setuphcipal, uint, 0644); module_param(loghci, uint, 0644); module_param(setupbtdev, uint, 0644); #ifndef EXPORT_HCI_BRIDGE_INTERFACE @@ -282,11 +288,20 @@ void ar6000_destroy(struct net_device *dev, unsigned int unregister); static void ar6000_detect_error(unsigned long ptr); static void ar6000_set_multicast_list(struct net_device *dev); static struct net_device_stats *ar6000_get_stats(struct net_device *dev); +static struct iw_statistics *ar6000_get_iwstats(struct net_device * dev); static void disconnect_timer_handler(unsigned long ptr); void read_rssi_compensation_param(struct ar6_softc *ar); + /* for android builds we call external APIs that handle firmware download and configuration */ +#ifdef ANDROID_ENV +/* !!!! Interim android support to make it easier to patch the default driver for + * android use. You must define an external source file ar6000_android.c that handles the following + * APIs */ +extern void android_module_init(OSDRV_CALLBACKS *osdrvCallbacks); +extern void android_module_exit(void); +#endif /* * HTC service connection handlers */ @@ -306,7 +321,9 @@ static void ar6000_tx_complete(void *Context, struct htc_packet_queue *pPackets) static HTC_SEND_FULL_ACTION ar6000_tx_queue_full(void *Context, struct htc_packet *pPacket); +#ifdef ATH_AR6K_11N_SUPPORT static void ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, u16 num); +#endif static void ar6000_deliver_frames_to_nw_stack(void * dev, void *osbuf); //static void ar6000_deliver_frames_to_bt_stack(void * dev, void *osbuf); @@ -329,6 +346,8 @@ ar6000_sysfs_bmi_write(struct file *fp, struct kobject *kobj, static int ar6000_sysfs_bmi_init(struct ar6_softc *ar); +/* HCI PAL callback function declarations */ +int ar6k_setup_hci_pal(struct ar6_softc *ar); void ar6k_cleanup_hci_pal(struct ar6_softc *ar); static void @@ -343,13 +362,16 @@ ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode); struct net_device *ar6000_devices[MAX_AR6000]; static int is_netdev_registered; +extern struct iw_handler_def ath_iw_handler_def; DECLARE_WAIT_QUEUE_HEAD(arEvent); static void ar6000_cookie_init(struct ar6_softc *ar); static void ar6000_cookie_cleanup(struct ar6_softc *ar); static void ar6000_free_cookie(struct ar6_softc *ar, struct ar_cookie * cookie); static struct ar_cookie *ar6000_alloc_cookie(struct ar6_softc *ar); +#ifdef USER_KEYS static int ar6000_reinstall_keys(struct ar6_softc *ar,u8 key_op_ctrl); +#endif #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT struct net_device *arApNetDev; @@ -367,6 +389,7 @@ static struct net_device_ops ar6000_netdev_ops = { .ndo_open = ar6000_open, .ndo_stop = ar6000_close, .ndo_get_stats = ar6000_get_stats, + .ndo_do_ioctl = ar6000_ioctl, .ndo_start_xmit = ar6000_data_tx, .ndo_set_multicast_list = ar6000_set_multicast_list, }; @@ -589,6 +612,7 @@ ar6000_dbglog_event(struct ar6_softc *ar, u32 dropped, send = dbglog_get_debug_fragment(&buffer[sent], length - sent, MAX_WIRELESS_EVENT_SIZE); while (send) { + ar6000_send_event_to_app(ar, WMIX_DBGLOG_EVENTID, (u8 *)&buffer[sent], send); sent += send; send = dbglog_get_debug_fragment(&buffer[sent], length - sent, MAX_WIRELESS_EVENT_SIZE); @@ -607,7 +631,7 @@ static int __init ar6000_init_module(void) { static int probed = 0; - int r; + int status; OSDRV_CALLBACKS osdrvCallbacks; a_module_debug_support_init(); @@ -640,6 +664,12 @@ ar6000_init_module(void) osdrvCallbacks.devicePowerChangeHandler = ar6000_power_change_ev; #endif + ar6000_pm_init(); + +#ifdef ANDROID_ENV + android_module_init(&osdrvCallbacks); +#endif + #ifdef DEBUG /* Set the debug flags if specified at load time */ if(debugflags != 0) @@ -657,9 +687,13 @@ ar6000_init_module(void) memset(&aptcTR, 0, sizeof(APTC_TRAFFIC_RECORD)); #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ - r = HIFInit(&osdrvCallbacks); - if (r) - return r; +#ifdef CONFIG_HOST_GPIO_SUPPORT + ar6000_gpio_init(); +#endif /* CONFIG_HOST_GPIO_SUPPORT */ + + status = HIFInit(&osdrvCallbacks); + if (status) + return -ENODEV; return 0; } @@ -689,6 +723,12 @@ ar6000_cleanup_module(void) a_module_debug_support_cleanup(); + ar6000_pm_exit(); + +#ifdef ANDROID_ENV + android_module_exit(); +#endif + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("ar6000_cleanup: success\n")); } @@ -729,6 +769,7 @@ aptcTimerHandler(unsigned long arg) } #endif /* ADAPTIVE_POWER_THROUGHPUT_CONTROL */ +#ifdef ATH_AR6K_11N_SUPPORT static void ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, u16 num) { @@ -747,6 +788,7 @@ ar6000_alloc_netbufs(A_NETBUF_QUEUE_T *q, u16 num) A_PRINTF("%s(), allocation of netbuf failed", __func__); } } +#endif static struct bin_attribute bmi_attr = { .attr = {.name = "bmi", .mode = 0600}, @@ -852,6 +894,8 @@ ar6000_sysfs_bmi_deinit(struct ar6_softc *ar) } \ } while(0) +#ifdef INIT_MODE_DRV_ENABLED + #ifdef SOFTMAC_FILE_USED #define AR6002_MAC_ADDRESS_OFFSET 0x0A #define AR6003_MAC_ADDRESS_OFFSET 0x16 @@ -938,7 +982,7 @@ ar6000_softmac_update(struct ar6_softc *ar, u8 *eeprom_data, size_t size) } source = "softmac file"; } - kfree(macbuf); + A_FREE(macbuf); } A_RELEASE_FIRMWARE(softmac_entry); } @@ -961,8 +1005,6 @@ ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, filename = AR6003_REV1_OTP_FILE; } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { filename = AR6003_REV2_OTP_FILE; - } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { - filename = AR6003_REV3_OTP_FILE; } else { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); return A_ERROR; @@ -974,8 +1016,6 @@ ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, filename = AR6003_REV1_FIRMWARE_FILE; } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { filename = AR6003_REV2_FIRMWARE_FILE; - } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { - filename = AR6003_REV3_FIRMWARE_FILE; } else { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); return A_ERROR; @@ -987,8 +1027,6 @@ ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, filename = AR6003_REV1_EPPING_FIRMWARE_FILE; } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { filename = AR6003_REV2_EPPING_FIRMWARE_FILE; - } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { - filename = AR6003_REV3_EPPING_FIRMWARE_FILE; } else { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("eppingtest : unsupported firmware revision: %d\n", ar->arVersion.target_ver)); @@ -1003,8 +1041,6 @@ ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, filename = AR6003_REV1_TCMD_FIRMWARE_FILE; } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { filename = AR6003_REV2_TCMD_FIRMWARE_FILE; - } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { - filename = AR6003_REV3_TCMD_FIRMWARE_FILE; } else { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); return A_ERROR; @@ -1032,8 +1068,6 @@ ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, filename = AR6003_REV1_PATCH_FILE; } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { filename = AR6003_REV2_PATCH_FILE; - } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { - filename = AR6003_REV3_PATCH_FILE; } else { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); return A_ERROR; @@ -1045,8 +1079,6 @@ ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, filename = AR6003_REV1_BOARD_DATA_FILE; } else if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { filename = AR6003_REV2_BOARD_DATA_FILE; - } else if (ar->arVersion.target_ver == AR6003_REV3_VERSION) { - filename = AR6003_REV3_BOARD_DATA_FILE; } else { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown firmware revision: %d\n", ar->arVersion.target_ver)); return A_ERROR; @@ -1101,10 +1133,8 @@ ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, } /* Record the fact that extended board Data IS initialized */ - param = (board_ext_data_size << 16) | 1; - bmifn(BMIWriteMemory(ar->arHifDevice, - HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data_config), - (unsigned char *)¶m, 4)); + param = 1; + bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data_initialized), (u8 *)¶m, 4)); } fw_entry_size = board_data_size; } @@ -1123,6 +1153,7 @@ ar6000_transfer_bin_file(struct ar6_softc *ar, AR6K_BIN_FILE file, u32 address, A_RELEASE_FIRMWARE(fw_entry); return 0; } +#endif /* INIT_MODE_DRV_ENABLED */ int ar6000_update_bdaddr(struct ar6_softc *ar) @@ -1169,6 +1200,7 @@ ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode) } A_RELEASE_FIRMWARE(fw_entry); +#ifdef INIT_MODE_DRV_ENABLED } else { /* The config is contained within the driver itself */ int status; @@ -1261,9 +1293,7 @@ ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode) bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_data_initialized), (u8 *)¶m, 4)); /* Transfer One time Programmable data */ - AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver); - if (ar->arVersion.target_ver == AR6003_REV3_VERSION) - address = 0x1234; + AR6K_DATA_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver); status = ar6000_transfer_bin_file(ar, AR6K_OTP_FILE, address, true); if (status == 0) { /* Execute the OTP code */ @@ -1279,9 +1309,7 @@ ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode) } /* Download Target firmware */ - AR6K_APP_LOAD_ADDRESS(address, ar->arVersion.target_ver); - if (ar->arVersion.target_ver == AR6003_REV3_VERSION) - address = 0x1234; + AR6K_DATA_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver); if ((ar6000_transfer_bin_file(ar, AR6K_FIRMWARE_FILE, address, true)) != 0) { return A_ERROR; } @@ -1290,16 +1318,25 @@ ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode) AR6K_APP_START_OVERRIDE_ADDRESS(address, ar->arVersion.target_ver); bmifn(BMISetAppStart(ar->arHifDevice, address)); - if(ar->arTargetType == TARGET_TYPE_AR6003) { - AR6K_DATASET_PATCH_ADDRESS(address, ar->arVersion.target_ver); - if ((ar6000_transfer_bin_file(ar, AR6K_PATCH_FILE, - address, false)) != 0) - return A_ERROR; - param = address; - bmifn(BMIWriteMemory(ar->arHifDevice, - HOST_INTEREST_ITEM_ADDRESS(ar, hi_dset_list_head), - (unsigned char *)¶m, 4)); - } + /* Apply the patches */ + AR6K_PATCH_DOWNLOAD_ADDRESS(address, ar->arVersion.target_ver); + if ((ar6000_transfer_bin_file(ar, AR6K_PATCH_FILE, address, false)) != 0) { + return A_ERROR; + } + + param = address; + bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_dset_list_head), (u8 *)¶m, 4)); + + if (ar->arTargetType == TARGET_TYPE_AR6003) { + if (ar->arVersion.target_ver == AR6003_REV1_VERSION) { + /* Reserve 5.5K of RAM */ + param = 5632; + } else { /* AR6003_REV2_VERSION */ + /* Reserve 6.5K of RAM */ + param = 6656; + } + bmifn(BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_end_RAM_reserve_sz), (u8 *)¶m, 4)); + } /* Restore system sleep */ address = RTC_BASE_ADDRESS + SYSTEM_SLEEP_ADDRESS; @@ -1353,6 +1390,8 @@ ar6000_sysfs_bmi_get_config(struct ar6_softc *ar, u32 mode) msleep(1000); } #endif /* HTC_RAW_INTERFACE */ + +#endif /* INIT_MODE_DRV_ENABLED */ } return 0; @@ -1431,11 +1470,7 @@ ar6000_configure_target(struct ar6_softc *ar) return A_ERROR; } - param |= (num_device << HI_OPTION_NUM_DEV_SHIFT); param |= (fwmode << HI_OPTION_FW_MODE_SHIFT); - param |= (mac_addr_method << HI_OPTION_MAC_ADDR_METHOD_SHIFT); - param |= (firmware_bridge << HI_OPTION_FW_BRIDGE_SHIFT); - if (BMIWriteMemory(ar->arHifDevice, HOST_INTEREST_ITEM_ADDRESS(ar, hi_option_flag), @@ -1483,34 +1518,18 @@ ar6000_configure_target(struct ar6_softc *ar) * It is difficult to patch the firmware boot code, * but possible in theory. */ + if (ar->arTargetType == TARGET_TYPE_AR6003) { + param = AR6003_BOARD_EXT_DATA_ADDRESS; + if (BMIWriteMemory(ar->arHifDevice, + HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data), + (u8 *)¶m, + 4) != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BMIWriteMemory for hi_board_ext_data failed \n")); + return A_ERROR; + } + } - if (ar->arTargetType == TARGET_TYPE_AR6003) { - A_UINT32 ramReservedSz; - if (ar->arVersion.target_ver == AR6003_REV2_VERSION) { - param = AR6003_REV2_BOARD_EXT_DATA_ADDRESS; - ramReservedSz = AR6003_REV2_RAM_RESERVE_SIZE; - } else { - param = AR6003_REV3_BOARD_EXT_DATA_ADDRESS; - ramReservedSz = AR6003_REV3_RAM_RESERVE_SIZE; - } - if (BMIWriteMemory(ar->arHifDevice, - HOST_INTEREST_ITEM_ADDRESS(ar, hi_board_ext_data), - (u8 *)¶m, 4) != 0) { - AR_DEBUG_PRINTF(ATH_DEBUG_ERR, - ("BMIWriteMemory for " - "hi_board_ext_data failed\n")); - return A_ERROR; - } - if (BMIWriteMemory(ar->arHifDevice, - HOST_INTEREST_ITEM_ADDRESS(ar, - hi_end_RAM_reserve_sz), - (u8 *)&ramReservedSz, 4) != 0) { - AR_DEBUG_PRINTF(ATH_DEBUG_ERR , - ("BMIWriteMemory for " - "hi_end_RAM_reserve_sz failed\n")); - return A_ERROR; - } - } /* since BMIInit is called in the driver layer, we have to set the block * size here for the target */ @@ -1536,6 +1555,9 @@ init_netdev(struct net_device *dev, char *name) { dev->netdev_ops = &ar6000_netdev_ops; dev->watchdog_timeo = AR6000_TX_TIMEOUT; + dev->wireless_handlers = &ath_iw_handler_def; + + ath_iw_handler_def.get_wireless_stats = ar6000_get_iwstats; /*Displayed via proc fs */ /* * We need the OS to provide us with more headroom in order to @@ -1553,6 +1575,10 @@ init_netdev(struct net_device *dev, char *name) strcpy(dev->name, name); } +#ifdef SET_MODULE_OWNER + SET_MODULE_OWNER(dev); +#endif + #ifdef CONFIG_CHECKSUM_OFFLOAD if(csumOffload){ dev->features |= NETIF_F_IP_CSUM; /*advertise kernel capability to do TCP/UDP CSUM offload for IPV4*/ @@ -1562,52 +1588,6 @@ init_netdev(struct net_device *dev, char *name) return; } -static int __ath6kl_init_netdev(struct net_device *dev) -{ - int r; - - rtnl_lock(); - r = ar6000_init(dev); - rtnl_unlock(); - - if (r) { - AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_init\n")); - return r; - } - - return 0; -} - -#ifdef HTC_RAW_INTERFACE -static int ath6kl_init_netdev_wmi(struct net_device *dev) -{ - if (!eppingtest && bypasswmi) - return 0; - - return __ath6kl_init_netdev(dev); -} -#else -static int ath6kl_init_netdev_wmi(struct net_device *dev) -{ - return __ath6kl_init_netdev(dev); -} -#endif - -static int ath6kl_init_netdev(struct ar6_softc *ar) -{ - int r; - - r = ar6000_sysfs_bmi_get_config(ar, wlaninitmode); - if (r) { - AR_DEBUG_PRINTF(ATH_DEBUG_ERR, - ("ar6000_avail: " - "ar6000_sysfs_bmi_get_config failed\n")); - return r; - } - - return ath6kl_init_netdev_wmi(ar->arNetDev); -} - /* * HTC Event handlers */ @@ -1620,8 +1600,10 @@ ar6000_avail_ev(void *context, void *hif_handle) struct ar6_softc *ar; int device_index = 0; struct htc_init_info htcInfo; +#ifdef ATH6K_CONFIG_CFG80211 struct wireless_dev *wdev; - int r = 0; +#endif /* ATH6K_CONFIG_CFG80211 */ + int init_status = 0; struct hif_device_os_device_info osDevInfo; memset(&osDevInfo, 0, sizeof(osDevInfo)); @@ -1648,12 +1630,22 @@ ar6000_avail_ev(void *context, void *hif_handle) /* we use another local "i" variable below. */ device_index = i; +#ifdef ATH6K_CONFIG_CFG80211 wdev = ar6k_cfg80211_init(osDevInfo.pOSDevice); if (IS_ERR(wdev)) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: ar6k_cfg80211_init failed\n", __func__)); return A_ERROR; } ar_netif = wdev_priv(wdev); +#else + dev = alloc_etherdev(sizeof(struct ar6_softc)); + if (dev == NULL) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_available: can't alloc etherdev\n")); + return A_ERROR; + } + ether_setup(dev); + ar_netif = ar6k_priv(dev); +#endif /* ATH6K_CONFIG_CFG80211 */ if (ar_netif == NULL) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("%s: Can't allocate ar6k priv memory\n", __func__)); @@ -1663,6 +1655,7 @@ ar6000_avail_ev(void *context, void *hif_handle) A_MEMZERO(ar_netif, sizeof(struct ar6_softc)); ar = (struct ar6_softc *)ar_netif; +#ifdef ATH6K_CONFIG_CFG80211 ar->wdev = wdev; wdev->iftype = NL80211_IFTYPE_STATION; @@ -1678,9 +1671,15 @@ ar6000_avail_ev(void *context, void *hif_handle) wdev->netdev = dev; ar->arNetworkType = INFRA_NETWORK; ar->smeState = SME_DISCONNECTED; +#endif /* ATH6K_CONFIG_CFG80211 */ init_netdev(dev, ifname); +#ifdef SET_NETDEV_DEV + if (ar_netif) { + SET_NETDEV_DEV(dev, osDevInfo.pOSDevice); + } +#endif ar->arNetDev = dev; ar->arHifDevice = hif_handle; @@ -1720,22 +1719,35 @@ ar6000_avail_ev(void *context, void *hif_handle) BMIInit(); - ar6000_sysfs_bmi_init(ar); + if (bmienable) { + ar6000_sysfs_bmi_init(ar); + } { struct bmi_target_info targ_info; - r = BMIGetTargetInfo(ar->arHifDevice, &targ_info); - if (r) + if (BMIGetTargetInfo(ar->arHifDevice, &targ_info) != 0) { + init_status = A_ERROR; goto avail_ev_failed; + } ar->arVersion.target_ver = targ_info.target_ver; ar->arTargetType = targ_info.target_type; + + /* do any target-specific preparation that can be done through BMI */ + if (ar6000_prepare_target(ar->arHifDevice, + targ_info.target_type, + targ_info.target_ver) != 0) { + init_status = A_ERROR; + goto avail_ev_failed; + } + } - r = ar6000_configure_target(ar); - if (r) + if (ar6000_configure_target(ar) != 0) { + init_status = A_ERROR; goto avail_ev_failed; + } A_MEMZERO(&htcInfo,sizeof(htcInfo)); htcInfo.pContext = ar; @@ -1743,8 +1755,8 @@ ar6000_avail_ev(void *context, void *hif_handle) ar->arHtcTarget = HTCCreate(ar->arHifDevice,&htcInfo); - if (!ar->arHtcTarget) { - r = -ENOMEM; + if (ar->arHtcTarget == NULL) { + init_status = A_ERROR; goto avail_ev_failed; } @@ -1755,19 +1767,22 @@ ar6000_avail_ev(void *context, void *hif_handle) #endif +#ifdef CONFIG_CHECKSUM_OFFLOAD if(csumOffload){ /*if external frame work is also needed, change and use an extended rxMetaVerion*/ ar->rxMetaVersion=WMI_META_VERSION_2; } +#endif - ar->aggr_cntxt = aggr_init(ar6000_alloc_netbufs); - if (!ar->aggr_cntxt) { +#ifdef ATH_AR6K_11N_SUPPORT + if((ar->aggr_cntxt = aggr_init(ar6000_alloc_netbufs)) == NULL) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s() Failed to initialize aggr.\n", __func__)); - r = -ENOMEM; + init_status = A_ERROR; goto avail_ev_failed; } aggr_register_rx_dispatcher(ar->aggr_cntxt, (void *)dev, ar6000_deliver_frames_to_nw_stack); +#endif HIFClaimDevice(ar->arHifDevice, ar); @@ -1776,20 +1791,46 @@ ar6000_avail_ev(void *context, void *hif_handle) /* when the module is unloaded. */ ar6000_devices[device_index] = dev; - AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode)); - if ((wlaninitmode == WLAN_INIT_MODE_UDEV) || - (wlaninitmode == WLAN_INIT_MODE_DRV)) { - r = ath6kl_init_netdev(ar); - if (r) - goto avail_ev_failed; + /* Don't install the init function if BMI is requested */ + if (!bmienable) { + ar6000_netdev_ops.ndo_init = ar6000_init; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("BMI enabled: %d\n", wlaninitmode)); + if ((wlaninitmode == WLAN_INIT_MODE_UDEV) || + (wlaninitmode == WLAN_INIT_MODE_DRV)) + { + int status = 0; + do { + if ((status = ar6000_sysfs_bmi_get_config(ar, wlaninitmode)) != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_sysfs_bmi_get_config failed\n")); + break; + } +#ifdef HTC_RAW_INTERFACE + if (!eppingtest && bypasswmi) { + break; /* Don't call ar6000_init for ART */ + } +#endif + rtnl_lock(); + status = (ar6000_init(dev)==0) ? 0 : A_ERROR; + rtnl_unlock(); + if (status) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: ar6000_init\n")); + } + } while (false); + + if (status) { + init_status = status; + goto avail_ev_failed; + } + } } /* This runs the init function if registered */ - r = register_netdev(dev); - if (r) { + if (register_netdev(dev)) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_avail: register_netdev failed\n")); ar6000_destroy(dev, 0); - return r; + return A_ERROR; } is_netdev_registered = 1; @@ -1802,10 +1843,13 @@ ar6000_avail_ev(void *context, void *hif_handle) (unsigned long)ar)); avail_ev_failed : - if (r) - ar6000_sysfs_bmi_deinit(ar); + if (init_status) { + if (bmienable) { + ar6000_sysfs_bmi_deinit(ar); + } + } - return r; + return init_status; } static void ar6000_target_failure(void *Instance, int Status) @@ -1836,6 +1880,9 @@ static void ar6000_target_failure(void *Instance, int Status) sip = true; errEvent.errorVal = WMI_TARGET_COM_ERR | WMI_TARGET_FATAL_ERR; + ar6000_send_event_to_app(ar, WMI_ERROR_REPORT_EVENTID, + (u8 *)&errEvent, + sizeof(WMI_TARGET_ERROR_REPORT_EVENT)); } } } @@ -1933,8 +1980,10 @@ ar6000_stop_endpoint(struct net_device *dev, bool keepprofile, bool getdbglogs) ar6000_disconnect_event(ar, DISCONNECT_CMD, ar->arBssid, 0, NULL, 0); } } +#ifdef USER_KEYS ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT; ar->user_key_ctrl = 0; +#endif } AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("%s(): WMI stopped\n", __func__)); @@ -1975,6 +2024,15 @@ ar6000_stop_endpoint(struct net_device *dev, bool keepprofile, bool getdbglogs) // END workaround if (setuphci) ar6000_cleanup_hci(ar); +#endif +#ifdef EXPORT_HCI_PAL_INTERFACE + if (setuphcipal && (NULL != ar6kHciPalCallbacks_g.cleanupTransport)) { + ar6kHciPalCallbacks_g.cleanupTransport(ar); + } +#else + /* cleanup hci pal driver data structures */ + if(setuphcipal) + ar6k_cleanup_hci_pal(ar); #endif AR_DEBUG_PRINTF(ATH_DEBUG_INFO,(" Shutting down HTC .... \n")); /* stop HTC */ @@ -2036,6 +2094,9 @@ ar6000_destroy(struct net_device *dev, unsigned int unregister) if (ar->arWlanPowerState != WLAN_POWER_STATE_CUT_PWR) { /* only stop endpoint if we are not stop it in suspend_ev */ ar6000_stop_endpoint(dev, false, true); + } else { + /* clear up the platform power state before rmmod */ + plat_setup_power(1,0); } ar->arWlanState = WLAN_DISABLED; @@ -2049,7 +2110,9 @@ ar6000_destroy(struct net_device *dev, unsigned int unregister) HIFReleaseDevice(ar->arHifDevice); HIFShutDownDevice(ar->arHifDevice); } +#ifdef ATH_AR6K_11N_SUPPORT aggr_module_destroy(ar->aggr_cntxt); +#endif /* Done with cookies */ ar6000_cookie_cleanup(ar); @@ -2057,7 +2120,9 @@ ar6000_destroy(struct net_device *dev, unsigned int unregister) /* cleanup any allocated AMSDU buffers */ ar6000_cleanup_amsdu_rxbufs(ar); - ar6000_sysfs_bmi_deinit(ar); + if (bmienable) { + ar6000_sysfs_bmi_deinit(ar); + } /* Cleanup BMI */ BMICleanup(); @@ -2069,7 +2134,7 @@ ar6000_destroy(struct net_device *dev, unsigned int unregister) #ifdef HTC_RAW_INTERFACE if (ar->arRawHtc) { - kfree(ar->arRawHtc); + A_FREE(ar->arRawHtc); ar->arRawHtc = NULL; } #endif @@ -2080,7 +2145,9 @@ ar6000_destroy(struct net_device *dev, unsigned int unregister) } free_netdev(dev); +#ifdef ATH6K_CONFIG_CFG80211 ar6k_cfg80211_deinit(ar); +#endif /* ATH6K_CONFIG_CFG80211 */ #ifdef CONFIG_AP_VIRTUL_ADAPTER_SUPPORT ar6000_remove_ap_interface(); @@ -2120,6 +2187,9 @@ static void ar6000_detect_error(unsigned long ptr) ar->arHBChallengeResp.seqNum = 0; errEvent.errorVal = WMI_TARGET_COM_ERR | WMI_TARGET_FATAL_ERR; AR6000_SPIN_UNLOCK(&ar->arLock, 0); + ar6000_send_event_to_app(ar, WMI_ERROR_REPORT_EVENTID, + (u8 *)&errEvent, + sizeof(WMI_TARGET_ERROR_REPORT_EVENT)); return; } @@ -2225,9 +2295,11 @@ ar6000_open(struct net_device *dev) spin_lock_irqsave(&ar->arLock, flags); +#ifdef ATH6K_CONFIG_CFG80211 if(ar->arWlanState == WLAN_DISABLED) { ar->arWlanState = WLAN_ENABLED; } +#endif /* ATH6K_CONFIG_CFG80211 */ if( ar->arConnected || bypasswmi) { netif_carrier_on(dev); @@ -2244,9 +2316,12 @@ ar6000_open(struct net_device *dev) static int ar6000_close(struct net_device *dev) { +#ifdef ATH6K_CONFIG_CFG80211 struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); +#endif /* ATH6K_CONFIG_CFG80211 */ netif_stop_queue(dev); +#ifdef ATH6K_CONFIG_CFG80211 ar6000_disconnect(ar); if(ar->arWmiReady == true) { @@ -2257,6 +2332,7 @@ ar6000_close(struct net_device *dev) ar->arWlanState = WLAN_DISABLED; } ar6k_cfg80211_scanComplete_event(ar, A_ECANCELED); +#endif /* ATH6K_CONFIG_CFG80211 */ return 0; } @@ -2346,52 +2422,16 @@ u8 ar6000_endpoint_id2_ac(void * devt, HTC_ENDPOINT_ID ep ) return(arEndpoint2Ac(ar, ep )); } -#if defined(CONFIG_ATH6KL_ENABLE_COEXISTENCE) -static int ath6kl_config_btcoex_params(struct ar6_softc *ar) -{ - int r; - WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD sbcb_cmd; - WMI_SET_BTCOEX_FE_ANT_CMD sbfa_cmd; - - /* Configure the type of BT collocated with WLAN */ - memset(&sbcb_cmd, 0, sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD)); - sbcb_cmd.btcoexCoLocatedBTdev = ATH6KL_BT_DEV; - - r = wmi_set_btcoex_colocated_bt_dev_cmd(ar->arWmi, &sbcb_cmd); - - if (r) { - AR_DEBUG_PRINTF(ATH_DEBUG_ERR, - ("Unable to set collocated BT type\n")); - return r; - } - - /* Configure the type of BT collocated with WLAN */ - memset(&sbfa_cmd, 0, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD)); - - sbfa_cmd.btcoexFeAntType = ATH6KL_BT_ANTENNA; - - r = wmi_set_btcoex_fe_ant_cmd(ar->arWmi, &sbfa_cmd); - if (r) { - AR_DEBUG_PRINTF(ATH_DEBUG_ERR, - ("Unable to set fornt end antenna configuration\n")); - return r; - } - - return 0; -} -#else -static int ath6kl_config_btcoex_params(struct ar6_softc *ar) -{ - return 0; -} -#endif /* CONFIG_ATH6KL_ENABLE_COEXISTENCE */ - /* * This function applies WLAN specific configuration defined in wlan_config.h */ int ar6000_target_config_wlan_params(struct ar6_softc *ar) { int status = 0; +#if defined(INIT_MODE_DRV_ENABLED) && defined(ENABLE_COEXISTENCE) + WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD sbcb_cmd; + WMI_SET_BTCOEX_FE_ANT_CMD sbfa_cmd; +#endif /* INIT_MODE_DRV_ENABLED && ENABLE_COEXISTENCE */ #ifdef CONFIG_HOST_TCMD_SUPPORT if (ar->arTargetMode != AR6000_WLAN_MODE) { @@ -2409,9 +2449,39 @@ int ar6000_target_config_wlan_params(struct ar6_softc *ar) status = A_ERROR; } - status = ath6kl_config_btcoex_params(ar); - if (status) - return status; +#if defined(INIT_MODE_DRV_ENABLED) && defined(ENABLE_COEXISTENCE) + /* Configure the type of BT collocated with WLAN */ + memset(&sbcb_cmd, 0, sizeof(WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD)); +#ifdef CONFIG_AR600x_BT_QCOM + sbcb_cmd.btcoexCoLocatedBTdev = 1; +#elif defined(CONFIG_AR600x_BT_CSR) + sbcb_cmd.btcoexCoLocatedBTdev = 2; +#elif defined(CONFIG_AR600x_BT_AR3001) + sbcb_cmd.btcoexCoLocatedBTdev = 3; +#else +#error Unsupported Bluetooth Type +#endif /* Collocated Bluetooth Type */ + + if ((wmi_set_btcoex_colocated_bt_dev_cmd(ar->arWmi, &sbcb_cmd)) != 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set collocated BT type\n")); + status = A_ERROR; + } + + /* Configure the type of BT collocated with WLAN */ + memset(&sbfa_cmd, 0, sizeof(WMI_SET_BTCOEX_FE_ANT_CMD)); +#ifdef CONFIG_AR600x_DUAL_ANTENNA + sbfa_cmd.btcoexFeAntType = 2; +#elif defined(CONFIG_AR600x_SINGLE_ANTENNA) + sbfa_cmd.btcoexFeAntType = 1; +#else +#error Unsupported Front-End Antenna Configuration +#endif /* AR600x Front-End Antenna Configuration */ + + if ((wmi_set_btcoex_fe_ant_cmd(ar->arWmi, &sbfa_cmd)) != 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Unable to set fornt end antenna configuration\n")); + status = A_ERROR; + } +#endif /* INIT_MODE_DRV_ENABLED && ENABLE_COEXISTENCE */ #if WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN if ((wmi_pmparams_cmd(ar->arWmi, 0, 1, 0, 0, 1, IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN)) != 0) { @@ -2666,6 +2736,13 @@ int ar6000_init(struct net_device *dev) status = ar6000_setup_hci(ar); } #endif +#ifdef EXPORT_HCI_PAL_INTERFACE + if (setuphcipal && (NULL != ar6kHciPalCallbacks_g.setupTransport)) + status = ar6kHciPalCallbacks_g.setupTransport(ar); +#else + if(setuphcipal) + status = ar6k_setup_hci_pal(ar); +#endif } while (false); @@ -2674,38 +2751,6 @@ int ar6000_init(struct net_device *dev) goto ar6000_init_done; } - if (regscanmode) { - A_UINT32 param; - - if (BMIReadMemory(ar->arHifDevice, - HOST_INTEREST_ITEM_ADDRESS(ar, - hi_option_flag), - (u8 *)¶m, - 4) != 0) { - AR_DEBUG_PRINTF(ATH_DEBUG_ERR, - ("BMIReadMemory forsetting " - "regscanmode failed\n")); - return A_ERROR; - } - - if (regscanmode == 1) - param |= HI_OPTION_SKIP_REG_SCAN; - else if (regscanmode == 2) - param |= HI_OPTION_INIT_REG_SCAN; - - if (BMIWriteMemory(ar->arHifDevice, - HOST_INTEREST_ITEM_ADDRESS(ar, - hi_option_flag), - (u8 *)¶m, - 4) != 0) { - AR_DEBUG_PRINTF(ATH_DEBUG_ERR, - ("BMIWriteMemory forsetting " - "regscanmode failed\n")); - return A_ERROR; - } - AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("Regulatory scan mode set\n")); - } - /* * give our connected endpoints some buffers */ @@ -3050,6 +3095,7 @@ ar6000_data_tx(struct sk_buff *skb, struct net_device *dev) } if (ar->arWmiEnabled) { +#ifdef CONFIG_CHECKSUM_OFFLOAD u8 csumStart=0; u8 csumDest=0; u8 csum=skb->ip_summed; @@ -3058,6 +3104,7 @@ ar6000_data_tx(struct sk_buff *skb, struct net_device *dev) sizeof(ATH_LLC_SNAP_HDR)); csumDest=skb->csum_offset+csumStart; } +#endif if (A_NETBUF_HEADROOM(skb) < dev->hard_header_len - LINUX_HACK_FUDGE_FACTOR) { struct sk_buff *newbuf; @@ -3088,6 +3135,7 @@ ar6000_data_tx(struct sk_buff *skb, struct net_device *dev) break; } } +#ifdef CONFIG_CHECKSUM_OFFLOAD if(csumOffload && (csum ==CHECKSUM_PARTIAL)){ WMI_TX_META_V2 metaV2; metaV2.csumStart =csumStart; @@ -3101,6 +3149,7 @@ ar6000_data_tx(struct sk_buff *skb, struct net_device *dev) } else +#endif { if (wmi_data_hdr_add(ar->arWmi, skb, DATA_MSGTYPE, bMoreData, dot11Hdr,0,NULL) != 0) { AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000_data_tx - wmi_data_hdr_add failed\n")); @@ -3655,23 +3704,8 @@ ar6000_rx(void *Context, struct htc_packet *pPacket) WMI_DATA_HDR *dhdr = (WMI_DATA_HDR *)A_NETBUF_DATA(skb); bool is_amsdu; u8 tid; - - /* - * This check can be removed if after a while we do not - * see the warning. For now we leave it to ensure - * we drop these frames accordingly in case the - * target generates them for some reason. These - * were used for an internal PAL but that's not - * used or supported anymore. These frames should - * not come up from the target. - */ - if (WARN_ON(WMI_DATA_HDR_GET_DATA_TYPE(dhdr) == - WMI_DATA_HDR_DATA_TYPE_ACL)) { - AR6000_STAT_INC(ar, rx_errors); - A_NETBUF_FREE(skb); - return; - } - + bool is_acl_data_frame; + is_acl_data_frame = WMI_DATA_HDR_GET_DATA_TYPE(dhdr) == WMI_DATA_HDR_DATA_TYPE_ACL; #ifdef CONFIG_PM ar6000_check_wow_status(ar, NULL, false); #endif /* CONFIG_PM */ @@ -3693,7 +3727,7 @@ ar6000_rx(void *Context, struct htc_packet *pPacket) * ACL data frames don't follow ethernet frame bounds for * min length */ - if (ar->arNetworkType != AP_NETWORK && + if (ar->arNetworkType != AP_NETWORK && !is_acl_data_frame && ((pPacket->ActualLength < minHdrLen) || (pPacket->ActualLength > AR6000_MAX_RX_MESSAGE_SIZE))) { @@ -3733,9 +3767,11 @@ ar6000_rx(void *Context, struct htc_packet *pPacket) case WMI_META_VERSION_1: offset += sizeof(WMI_RX_META_V1); break; +#ifdef CONFIG_CHECKSUM_OFFLOAD case WMI_META_VERSION_2: offset += sizeof(WMI_RX_META_V2); break; +#endif default: break; } @@ -3805,6 +3841,7 @@ ar6000_rx(void *Context, struct htc_packet *pPacket) A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V1)); break; } +#ifdef CONFIG_CHECKSUM_OFFLOAD case WMI_META_VERSION_2: { WMI_RX_META_V2 *pMeta = (WMI_RX_META_V2 *)A_NETBUF_DATA(skb); @@ -3815,6 +3852,7 @@ ar6000_rx(void *Context, struct htc_packet *pPacket) A_NETBUF_PULL((void*)skb, sizeof(WMI_RX_META_V2)); break; } +#endif default: break; } @@ -3824,7 +3862,7 @@ ar6000_rx(void *Context, struct htc_packet *pPacket) /* NWF: print the 802.11 hdr bytes */ if(containsDot11Hdr) { status = wmi_dot11_hdr_remove(ar->arWmi,skb); - } else if(!is_amsdu) { + } else if(!is_amsdu && !is_acl_data_frame) { status = wmi_dot3_2_dix(skb); } @@ -3834,6 +3872,16 @@ ar6000_rx(void *Context, struct htc_packet *pPacket) goto rx_done; } + if (is_acl_data_frame) { + A_NETBUF_PUSH(skb, sizeof(int)); + *((short *)A_NETBUF_DATA(skb)) = WMI_ACL_DATA_EVENTID; + /* send the data packet to PAL driver */ + if(ar6k_pal_config_g.fpar6k_pal_recv_pkt) { + if((*ar6k_pal_config_g.fpar6k_pal_recv_pkt)(ar->hcipal_info, skb) == true) + goto rx_done; + } + } + if ((ar->arNetDev->flags & IFF_UP) == IFF_UP) { if (ar->arNetworkType == AP_NETWORK) { struct sk_buff *skb1 = NULL; @@ -3867,7 +3915,9 @@ ar6000_rx(void *Context, struct htc_packet *pPacket) } } } +#ifdef ATH_AR6K_11N_SUPPORT aggr_process_recv_frm(ar->aggr_cntxt, tid, seq_no, is_amsdu, (void **)&skb); +#endif ar6000_deliver_frames_to_nw_stack((void *) ar->arNetDev, (void *)skb); } } @@ -4096,6 +4146,93 @@ ar6000_get_stats(struct net_device *dev) return &ar->arNetStats; } +static struct iw_statistics * +ar6000_get_iwstats(struct net_device * dev) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + TARGET_STATS *pStats = &ar->arTargetStats; + struct iw_statistics * pIwStats = &ar->arIwStats; + int rtnllocked; + + if (ar->bIsDestroyProgress || ar->arWmiReady == false || ar->arWlanState == WLAN_DISABLED) + { + pIwStats->status = 0; + pIwStats->qual.qual = 0; + pIwStats->qual.level =0; + pIwStats->qual.noise = 0; + pIwStats->discard.code =0; + pIwStats->discard.retries=0; + pIwStats->miss.beacon =0; + return pIwStats; + } + + /* + * The in_atomic function is used to determine if the scheduling is + * allowed in the current context or not. This was introduced in 2.6 + * From what I have read on the differences between 2.4 and 2.6, the + * 2.4 kernel did not support preemption and so this check might not + * be required for 2.4 kernels. + */ + if (in_atomic()) + { + wmi_get_stats_cmd(ar->arWmi); + + pIwStats->status = 1 ; + pIwStats->qual.qual = pStats->cs_aveBeacon_rssi - 161; + pIwStats->qual.level =pStats->cs_aveBeacon_rssi; /* noise is -95 dBm */ + pIwStats->qual.noise = pStats->noise_floor_calibation; + pIwStats->discard.code = pStats->rx_decrypt_err; + pIwStats->discard.retries = pStats->tx_retry_cnt; + pIwStats->miss.beacon = pStats->cs_bmiss_cnt; + return pIwStats; + } + + dev_hold(dev); + rtnllocked = rtnl_is_locked(); + if (rtnllocked) { + rtnl_unlock(); + } + pIwStats->status = 0; + + if (down_interruptible(&ar->arSem)) { + goto err_exit; + } + + do { + + if (ar->bIsDestroyProgress || ar->arWlanState == WLAN_DISABLED) { + break; + } + + ar->statsUpdatePending = true; + + if(wmi_get_stats_cmd(ar->arWmi) != 0) { + break; + } + + wait_event_interruptible_timeout(arEvent, ar->statsUpdatePending == false, wmitimeout * HZ); + if (signal_pending(current)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000 : WMI get stats timeout \n")); + break; + } + pIwStats->status = 1 ; + pIwStats->qual.qual = pStats->cs_aveBeacon_rssi - 161; + pIwStats->qual.level =pStats->cs_aveBeacon_rssi; /* noise is -95 dBm */ + pIwStats->qual.noise = pStats->noise_floor_calibation; + pIwStats->discard.code = pStats->rx_decrypt_err; + pIwStats->discard.retries = pStats->tx_retry_cnt; + pIwStats->miss.beacon = pStats->cs_bmiss_cnt; + } while (0); + up(&ar->arSem); + +err_exit: + if (rtnllocked) { + rtnl_lock(); + } + dev_put(dev); + return pIwStats; +} + void ar6000_ready_event(void *devt, u8 *datap, u8 phyCap, u32 sw_ver, u32 abi_ver) { @@ -4117,29 +4254,6 @@ ar6000_ready_event(void *devt, u8 *datap, u8 phyCap, u32 sw_ver, u32 abi_ver) wake_up(&arEvent); } -void ar6000_install_static_wep_keys(struct ar6_softc *ar) -{ - u8 index; - u8 keyUsage; - - for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) { - if (ar->arWepKeyList[index].arKeyLen) { - keyUsage = GROUP_USAGE; - if (index == ar->arDefTxKeyIndex) { - keyUsage |= TX_USAGE; - } - wmi_addKey_cmd(ar->arWmi, - index, - WEP_CRYPT, - keyUsage, - ar->arWepKeyList[index].arKeyLen, - NULL, - ar->arWepKeyList[index].arKey, KEY_OP_INIT_VAL, NULL, - NO_SYNC_WMIFLAG); - } - } -} - void add_new_sta(struct ar6_softc *ar, u8 *mac, u16 aid, u8 *wpaie, u8 ielen, u8 keymgmt, u8 ucipher, u8 auth) @@ -4278,11 +4392,13 @@ ar6000_connect_event(struct ar6_softc *ar, u16 channel, u8 *bssid, return; } +#ifdef ATH6K_CONFIG_CFG80211 ar6k_cfg80211_connect_event(ar, channel, bssid, listenInterval, beaconInterval, networkType, beaconIeLen, assocReqLen, assocRespLen, assocInfo); +#endif /* ATH6K_CONFIG_CFG80211 */ memcpy(ar->arBssid, bssid, sizeof(ar->arBssid)); ar->arBssChannel = channel; @@ -4379,6 +4495,7 @@ ar6000_connect_event(struct ar6_softc *ar, u16 channel, u8 *bssid, wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf); } +#ifdef USER_KEYS if (ar->user_savedkeys_stat == USER_SAVEDKEYS_STAT_RUN && ar->user_saved_keys.keyOk == true) { @@ -4391,9 +4508,30 @@ ar6000_connect_event(struct ar6_softc *ar, u16 channel, u8 *bssid, } ar6000_reinstall_keys(ar, key_op_ctrl); } +#endif /* USER_KEYS */ netif_wake_queue(ar->arNetDev); + /* For CFG80211 the key configuration and the default key comes in after connect so no point in plumbing invalid keys */ +#ifndef ATH6K_CONFIG_CFG80211 + if ((networkType & ADHOC_NETWORK) && + (OPEN_AUTH == ar->arDot11AuthMode) && + (NONE_AUTH == ar->arAuthMode) && + (WEP_CRYPT == ar->arPairwiseCrypto)) + { + if (!ar->arConnected) { + wmi_addKey_cmd(ar->arWmi, + ar->arDefTxKeyIndex, + WEP_CRYPT, + GROUP_USAGE | TX_USAGE, + ar->arWepKeyList[ar->arDefTxKeyIndex].arKeyLen, + NULL, + ar->arWepKeyList[ar->arDefTxKeyIndex].arKey, KEY_OP_INIT_VAL, NULL, + NO_SYNC_WMIFLAG); + } + } +#endif /* ATH6K_CONFIG_CFG80211 */ + /* Update connect & link status atomically */ spin_lock_irqsave(&ar->arLock, flags); ar->arConnected = true; @@ -4523,9 +4661,11 @@ ar6000_disconnect_event(struct ar6_softc *ar, u8 reason, u8 *bssid, return; } +#ifdef ATH6K_CONFIG_CFG80211 ar6k_cfg80211_disconnect_event(ar, reason, bssid, assocRespLen, assocInfo, protocolReasonStatus); +#endif /* ATH6K_CONFIG_CFG80211 */ /* Send disconnect event to supplicant */ A_MEMZERO(&wrqu, sizeof(wrqu)); @@ -4611,11 +4751,13 @@ ar6000_disconnect_event(struct ar6_softc *ar, u8 reason, u8 *bssid, reconnect_flag = 0; } +#ifdef USER_KEYS if (reason != CSERV_DISCONNECT) { ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_INIT; ar->user_key_ctrl = 0; } +#endif /* USER_KEYS */ netif_stop_queue(ar->arNetDev); A_MEMZERO(ar->arBssid, sizeof(ar->arBssid)); @@ -4632,6 +4774,7 @@ ar6000_regDomain_event(struct ar6_softc *ar, u32 regCode) ar->arRegCode = regCode; } +#ifdef ATH_AR6K_11N_SUPPORT void ar6000_aggr_rcv_addba_req_evt(struct ar6_softc *ar, WMI_ADDBA_REQ_EVENT *evt) { @@ -4653,6 +4796,7 @@ ar6000_aggr_rcv_delba_req_evt(struct ar6_softc *ar, WMI_DELBA_EVENT *evt) { aggr_recv_delba_req_evt(ar->aggr_cntxt, evt->tid); } +#endif void register_pal_cb(ar6k_pal_config_t *palConfig_p) { @@ -4684,6 +4828,12 @@ ar6000_hci_event_rcv_evt(struct ar6_softc *ar, WMI_HCI_EVENT *cmd) buf += sizeof(int); memcpy(buf, cmd->buf, cmd->evt_buf_sz); + if(ar6k_pal_config_g.fpar6k_pal_recv_pkt) + { + /* pass the cmd packet to PAL driver */ + if((*ar6k_pal_config_g.fpar6k_pal_recv_pkt)(ar->hcipal_info, osbuf) == true) + return; + } ar6000_deliver_frames_to_nw_stack(ar->arNetDev, osbuf); if(loghci) { A_PRINTF_LOG("HCI Event From PAL <-- \n"); @@ -4733,7 +4883,7 @@ ar6000_neighborReport_event(struct ar6_softc *ar, int numAps, WMI_NEIGHBOR_INFO memcpy(pmkcand->bssid.sa_data, info->bssid, ATH_MAC_LEN); wrqu.data.length = sizeof(struct iw_pmkid_cand); wireless_send_event(ar->arNetDev, IWEVPMKIDCAND, &wrqu, (char *)pmkcand); - kfree(pmkcand); + A_FREE(pmkcand); #else /* WIRELESS_EXT >= 18 */ snprintf(buf, sizeof(buf), "%s%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x", tag, @@ -4768,7 +4918,9 @@ ar6000_tkip_micerr_event(struct ar6_softc *ar, u8 keyid, bool ismcast) tag, s->mac[0],s->mac[1],s->mac[2],s->mac[3],s->mac[4],s->mac[5]); } else { +#ifdef ATH6K_CONFIG_CFG80211 ar6k_cfg80211_tkip_micerr_event(ar, keyid, ismcast); +#endif /* ATH6K_CONFIG_CFG80211 */ A_PRINTF("AR6000 TKIP MIC error received for keyid %d %scast\n", keyid & 0x3, ismcast ? "multi": "uni"); @@ -4785,7 +4937,9 @@ void ar6000_scanComplete_event(struct ar6_softc *ar, int status) { +#ifdef ATH6K_CONFIG_CFG80211 ar6k_cfg80211_scanComplete_event(ar, status); +#endif /* ATH6K_CONFIG_CFG80211 */ if (!ar->arUserBssFilter) { wmi_bssfilter_cmd(ar->arWmi, NONE_BSS_FILTER, 0); @@ -4943,13 +5097,19 @@ ar6000_rssiThreshold_event(struct ar6_softc *ar, WMI_RSSI_THRESHOLD_VAL newThre userRssiThold.rssi = rssi; A_PRINTF("rssi Threshold range = %d tag = %d rssi = %d\n", newThreshold, userRssiThold.tag, userRssiThold.rssi); + + ar6000_send_event_to_app(ar, WMI_RSSI_THRESHOLD_EVENTID,(u8 *)&userRssiThold, sizeof(USER_RSSI_THOLD)); } void ar6000_hbChallengeResp_event(struct ar6_softc *ar, u32 cookie, u32 source) { - if (source != APP_HB_CHALLENGE) { + if (source == APP_HB_CHALLENGE) { + /* Report it to the app in case it wants a positive acknowledgement */ + ar6000_send_event_to_app(ar, WMIX_HB_CHALLENGE_RESP_EVENTID, + (u8 *)&cookie, sizeof(cookie)); + } else { /* This would ignore the replys that come in after their due time */ if (cookie == ar->arHBChallengeResp.seqNum) { ar->arHBChallengeResp.outstanding = false; @@ -5402,6 +5562,100 @@ ar6000_alloc_cookie(struct ar6_softc *ar) return cookie; } +#ifdef SEND_EVENT_TO_APP +/* + * This function is used to send event which come from taget to + * the application. The buf which send to application is include + * the event ID and event content. + */ +#define EVENT_ID_LEN 2 +void ar6000_send_event_to_app(struct ar6_softc *ar, u16 eventId, + u8 *datap, int len) +{ + +#if (WIRELESS_EXT >= 15) + +/* note: IWEVCUSTOM only exists in wireless extensions after version 15 */ + + char *buf; + u16 size; + union iwreq_data wrqu; + + size = len + EVENT_ID_LEN; + + if (size > IW_CUSTOM_MAX) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI event ID : 0x%4.4X, len = %d too big for IWEVCUSTOM (max=%d) \n", + eventId, size, IW_CUSTOM_MAX)); + return; + } + + buf = A_MALLOC_NOWAIT(size); + if (NULL == buf){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: failed to allocate %d bytes\n", __func__, size)); + return; + } + + A_MEMZERO(buf, size); + memcpy(buf, &eventId, EVENT_ID_LEN); + memcpy(buf+EVENT_ID_LEN, datap, len); + + //AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("event ID = %d,len = %d\n",*(u16 *)buf, size)); + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = size; + wireless_send_event(ar->arNetDev, IWEVCUSTOM, &wrqu, buf); + A_FREE(buf); +#endif + + +} + +/* + * This function is used to send events larger than 256 bytes + * to the application. The buf which is sent to application + * includes the event ID and event content. + */ +void ar6000_send_generic_event_to_app(struct ar6_softc *ar, u16 eventId, + u8 *datap, int len) +{ + +#if (WIRELESS_EXT >= 18) + +/* IWEVGENIE exists in wireless extensions version 18 onwards */ + + char *buf; + u16 size; + union iwreq_data wrqu; + + size = len + EVENT_ID_LEN; + + if (size > IW_GENERIC_IE_MAX) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("WMI event ID : 0x%4.4X, len = %d too big for IWEVGENIE (max=%d) \n", + eventId, size, IW_GENERIC_IE_MAX)); + return; + } + + buf = A_MALLOC_NOWAIT(size); + if (NULL == buf){ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("%s: failed to allocate %d bytes\n", __func__, size)); + return; + } + + A_MEMZERO(buf, size); + memcpy(buf, &eventId, EVENT_ID_LEN); + memcpy(buf+EVENT_ID_LEN, datap, len); + + A_MEMZERO(&wrqu, sizeof(wrqu)); + wrqu.data.length = size; + wireless_send_event(ar->arNetDev, IWEVGENIE, &wrqu, buf); + + A_FREE(buf); + +#endif /* (WIRELESS_EXT >= 18) */ + +} +#endif /* SEND_EVENT_TO_APP */ + + void ar6000_tx_retry_err_event(void *devt) { @@ -5412,9 +5666,13 @@ void ar6000_snrThresholdEvent_rx(void *devt, WMI_SNR_THRESHOLD_VAL newThreshold, u8 snr) { WMI_SNR_THRESHOLD_EVENT event; + struct ar6_softc *ar = (struct ar6_softc *)devt; event.range = newThreshold; event.snr = snr; + + ar6000_send_event_to_app(ar, WMI_SNR_THRESHOLD_EVENTID, (u8 *)&event, + sizeof(WMI_SNR_THRESHOLD_EVENT)); } void @@ -5741,7 +5999,9 @@ void ap_wapi_rekey_event(struct ar6_softc *ar, u8 type, u8 *mac) } #endif +#ifdef USER_KEYS static int + ar6000_reinstall_keys(struct ar6_softc *ar, u8 key_op_ctrl) { int status = 0; @@ -5786,6 +6046,7 @@ ar6000_reinstall_keys(struct ar6_softc *ar, u8 key_op_ctrl) return status; } +#endif /* USER_KEYS */ void diff --git a/trunk/drivers/staging/ath6kl/os/linux/ar6000_pm.c b/trunk/drivers/staging/ath6kl/os/linux/ar6000_pm.c index 1e0ace8b6d13..1a9042446bcb 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/ar6000_pm.c +++ b/trunk/drivers/staging/ath6kl/os/linux/ar6000_pm.c @@ -36,6 +36,9 @@ extern unsigned int wmitimeout; extern wait_queue_head_t arEvent; +#ifdef ANDROID_ENV +extern void android_ar6k_check_wow_status(struct ar6_softc *ar, struct sk_buff *skb, bool isEvent); +#endif #undef ATH_MODULE_NAME #define ATH_MODULE_NAME pm #define ATH_DEBUG_PM ATH_DEBUG_MAKE_MODULE_MASK(0) @@ -280,6 +283,10 @@ void ar6000_check_wow_status(struct ar6_softc *ar, struct sk_buff *skb, bool isE /* Wow resume from irq interrupt */ AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("%s: WoW resume from irq thread status %d\n", __func__, ar->arWlanPowerState)); ar6000_wow_resume(ar); + } else { +#ifdef ANDROID_ENV + android_ar6k_check_wow_status(ar, skb, isEvent); +#endif } } @@ -302,6 +309,37 @@ int ar6000_power_change_ev(void *context, u32 config) return status; } +static int ar6000_pm_probe(struct platform_device *pdev) +{ + plat_setup_power(1,1); + return 0; +} + +static int ar6000_pm_remove(struct platform_device *pdev) +{ + plat_setup_power(0,1); + return 0; +} + +static int ar6000_pm_suspend(struct platform_device *pdev, pm_message_t state) +{ + return 0; +} + +static int ar6000_pm_resume(struct platform_device *pdev) +{ + return 0; +} + +static struct platform_driver ar6000_pm_device = { + .probe = ar6000_pm_probe, + .remove = ar6000_pm_remove, + .suspend = ar6000_pm_suspend, + .resume = ar6000_pm_resume, + .driver = { + .name = "wlan_ar6000_pm", + }, +}; #endif /* CONFIG_PM */ int @@ -321,6 +359,8 @@ ar6000_setup_cut_power_state(struct ar6_softc *ar, AR6000_WLAN_STATE state) break; } + plat_setup_power(1,0); + /* Change the state to ON */ ar->arWlanPowerState = WLAN_POWER_STATE_ON; @@ -333,6 +373,17 @@ ar6000_setup_cut_power_state(struct ar6_softc *ar, AR6000_WLAN_STATE state) sizeof(HIF_DEVICE_POWER_CHANGE_TYPE)); if (status == A_PENDING) { +#ifdef ANDROID_ENV + /* Wait for WMI ready event */ + u32 timeleft = wait_event_interruptible_timeout(arEvent, + (ar->arWmiReady == true), wmitimeout * HZ); + if (!timeleft || signal_pending(current)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000 : Failed to get wmi ready \n")); + status = A_ERROR; + break; + } +#endif + status = 0; } else if (status == 0) { ar6000_restart_endpoint(ar->arNetDev); status = 0; @@ -352,6 +403,8 @@ ar6000_setup_cut_power_state(struct ar6_softc *ar, AR6000_WLAN_STATE state) &config, sizeof(HIF_DEVICE_POWER_CHANGE_TYPE)); + plat_setup_power(0,0); + ar->arWlanPowerState = WLAN_POWER_STATE_CUT_PWR; } } while (0); @@ -589,6 +642,8 @@ ar6000_update_wlan_pwr_state(struct ar6_softc *ar, AR6000_WLAN_STATE state, bool } if (pSleepEvent) { AR_DEBUG_PRINTF(ATH_DEBUG_PM, ("SENT WLAN Sleep Event %d\n", wmiSleepEvent.sleepState)); + ar6000_send_event_to_app(ar, WMI_REPORT_SLEEP_STATE_EVENTID, (u8 *)pSleepEvent, + sizeof(WMI_REPORT_SLEEP_STATE_EVENTID)); } } up(&ar->arSem); @@ -624,3 +679,25 @@ ar6000_set_wlan_state(struct ar6_softc *ar, AR6000_WLAN_STATE state) status = ar6000_update_wlan_pwr_state(ar, state, false); return status; } + +void ar6000_pm_init() +{ + A_REGISTER_MODULE_DEBUG_INFO(pm); +#ifdef CONFIG_PM + /* + * Register ar6000_pm_device into system. + * We should also add platform_device into the first item of array + * of devices[] in file arch/xxx/mach-xxx/board-xxxx.c + */ + if (platform_driver_register(&ar6000_pm_device)) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("ar6000: fail to register the power control driver.\n")); + } +#endif /* CONFIG_PM */ +} + +void ar6000_pm_exit() +{ +#ifdef CONFIG_PM + platform_driver_unregister(&ar6000_pm_device); +#endif /* CONFIG_PM */ +} diff --git a/trunk/drivers/staging/ath6kl/os/linux/ar6k_pal.c b/trunk/drivers/staging/ath6kl/os/linux/ar6k_pal.c new file mode 100644 index 000000000000..1f7179acfd70 --- /dev/null +++ b/trunk/drivers/staging/ath6kl/os/linux/ar6k_pal.c @@ -0,0 +1,479 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#include "ar6000_drv.h" +#ifdef AR6K_ENABLE_HCI_PAL +#include +#include +#include + +extern unsigned int setupbtdev; +#define bt_check_bit(val, bit) (val & bit) +#define bt_set_bit(val, bit) (val |= bit) +#define bt_clear_bit(val, bit) (val &= ~bit) + +/* export ATH_AR6K_DEBUG_HCI_PAL=yes in host/localmake.linux.inc + * to enable debug information */ +#ifdef HCIPAL_DEBUG +#define PRIN_LOG(format, args...) printk(KERN_ALERT "%s:%d - %s Msg:" format "\n",__FUNCTION__, __LINE__, __FILE__, ## args) +#else +#define PRIN_LOG(format, args...) +#endif + +/********************************** + * HCI PAL private info structure + *********************************/ +typedef struct ar6k_hci_pal_info_s{ + + unsigned long ulFlags; +#define HCI_NORMAL_MODE (1) +#define HCI_REGISTERED (1<<1) + struct hci_dev *hdev; /* BT Stack HCI dev */ + struct ar6_softc *ar; + +}ar6k_hci_pal_info_t; + +/*** BT Stack Entrypoints *******/ +/*************************************** + * bt_open - open a handle to the device + ***************************************/ +static int bt_open(struct hci_dev *hdev) +{ + PRIN_LOG("HCI PAL: bt_open - enter - x\n"); + set_bit(HCI_RUNNING, &hdev->flags); + set_bit(HCI_UP, &hdev->flags); + set_bit(HCI_INIT, &hdev->flags); + return 0; +} + +/*************************************** + * bt_close - close handle to the device + ***************************************/ +static int bt_close(struct hci_dev *hdev) +{ + PRIN_LOG("HCI PAL: bt_close - enter\n"); + clear_bit(HCI_RUNNING, &hdev->flags); + return 0; +} + +/***************************** + * bt_ioctl - ioctl processing + *****************************/ +static int bt_ioctl(struct hci_dev *hdev, unsigned int cmd, unsigned long arg) +{ + PRIN_LOG("HCI PAL: bt_ioctl - enter\n"); + return -ENOIOCTLCMD; +} + +/************************************** + * bt_flush - flush outstanding packets + **************************************/ +static int bt_flush(struct hci_dev *hdev) +{ + PRIN_LOG("HCI PAL: bt_flush - enter\n"); + return 0; +} + +/*************** + * bt_destruct + ***************/ +static void bt_destruct(struct hci_dev *hdev) +{ + PRIN_LOG("HCI PAL: bt_destruct - enter\n"); + /* nothing to do here */ +} + +/**************************************************** + * Invoked from bluetooth stack via hdev->send() + * to send the packet out via ar6k to PAL firmware. + * + * For HCI command packet wmi_send_hci_cmd() is invoked. + * wmi_send_hci_cmd adds WMI_CMD_HDR and sends the packet + * to PAL firmware. + * + * For HCI ACL data packet wmi_data_hdr_add is invoked + * to add WMI_DATA_HDR to the packet. ar6000_acl_data_tx + * is then invoked to send the packet to PAL firmware. + ******************************************************/ +static int btpal_send_frame(struct sk_buff *skb) +{ + struct hci_dev *hdev = (struct hci_dev *)skb->dev; + HCI_TRANSPORT_PACKET_TYPE type; + ar6k_hci_pal_info_t *pHciPalInfo; + int status = 0; + struct sk_buff *txSkb = NULL; + struct ar6_softc *ar; + + if (!hdev) { + PRIN_LOG("HCI PAL: btpal_send_frame - no device\n"); + return -ENODEV; + } + + if (!test_bit(HCI_RUNNING, &hdev->flags)) { + PRIN_LOG("HCI PAL: btpal_send_frame - not open\n"); + return -EBUSY; + } + + pHciPalInfo = (ar6k_hci_pal_info_t *)hdev->driver_data; + A_ASSERT(pHciPalInfo != NULL); + ar = pHciPalInfo->ar; + + PRIN_LOG("+btpal_send_frame type: %d \n",bt_cb(skb)->pkt_type); + type = HCI_COMMAND_TYPE; + + switch (bt_cb(skb)->pkt_type) { + case HCI_COMMAND_PKT: + type = HCI_COMMAND_TYPE; + hdev->stat.cmd_tx++; + break; + + case HCI_ACLDATA_PKT: + type = HCI_ACL_TYPE; + hdev->stat.acl_tx++; + break; + + case HCI_SCODATA_PKT: + /* we don't support SCO over the pal */ + kfree_skb(skb); + return 0; + default: + A_ASSERT(false); + kfree_skb(skb); + return 0; + } + + if (AR_DEBUG_LVL_CHECK(ATH_DEBUG_HCI_DUMP)) { + A_PRINTF(">>> Send HCI %s packet len: %d\n", + (type == HCI_COMMAND_TYPE) ? "COMMAND" : "ACL", + skb->len); + if (type == HCI_COMMAND_TYPE) { + PRIN_LOG(" HCI Command: OGF:0x%X OCF:0x%X \r\n", + HCI_GET_OP_CODE(skb-data) >> 10, HCI_GET_OP_CODE(skb-data) & 0x3FF); + } + AR_DEBUG_PRINTBUF(skb->data,skb->len,"BT HCI SEND Packet Dump"); + } + + do { + if(type == HCI_COMMAND_TYPE) + { + PRIN_LOG("HCI command"); + + if (ar->arWmiReady == false) + { + PRIN_LOG("WMI not ready "); + break; + } + + if (wmi_send_hci_cmd(ar->arWmi, skb->data, skb->len) != 0) + { + PRIN_LOG("send hci cmd error"); + break; + } + } + else if(type == HCI_ACL_TYPE) + { + void *osbuf; + + PRIN_LOG("ACL data"); + if (ar->arWmiReady == false) + { + PRIN_LOG("WMI not ready"); + break; + } + + /* need to add WMI header so allocate a skb with more space */ + txSkb = bt_skb_alloc(TX_PACKET_RSV_OFFSET + WMI_MAX_TX_META_SZ + + sizeof(WMI_DATA_HDR) + skb->len, + GFP_ATOMIC); + + if (txSkb == NULL) { + status = A_NO_MEMORY; + PRIN_LOG("No memory"); + break; + } + + bt_cb(txSkb)->pkt_type = bt_cb(skb)->pkt_type; + txSkb->dev = (void *)pHciPalInfo->hdev; + skb_reserve(txSkb, TX_PACKET_RSV_OFFSET + WMI_MAX_TX_META_SZ + sizeof(WMI_DATA_HDR)); + memcpy(txSkb->data, skb->data, skb->len); + skb_put(txSkb,skb->len); + /* Add WMI packet type */ + osbuf = (void *)txSkb; + + if (wmi_data_hdr_add(ar->arWmi, osbuf, DATA_MSGTYPE, 0, WMI_DATA_HDR_DATA_TYPE_ACL,0,NULL) != 0) { + PRIN_LOG("XIOCTL_ACL_DATA - wmi_data_hdr_add failed\n"); + } else { + /* Send data buffer over HTC */ + PRIN_LOG("acl data tx"); + ar6000_acl_data_tx(osbuf, ar->arNetDev); + } + txSkb = NULL; + } + } while (false); + + if (txSkb != NULL) { + PRIN_LOG("Free skb"); + kfree_skb(txSkb); + } + kfree_skb(skb); + return 0; +} + + +/*********************************************** + * Unregister HCI device and free HCI device info + ***********************************************/ +static void bt_cleanup_hci_pal(ar6k_hci_pal_info_t *pHciPalInfo) +{ + int err; + + if (bt_check_bit(pHciPalInfo->ulFlags, HCI_REGISTERED)) { + bt_clear_bit(pHciPalInfo->ulFlags, HCI_REGISTERED); + clear_bit(HCI_RUNNING, &pHciPalInfo->hdev->flags); + clear_bit(HCI_UP, &pHciPalInfo->hdev->flags); + clear_bit(HCI_INIT, &pHciPalInfo->hdev->flags); + A_ASSERT(pHciPalInfo->hdev != NULL); + /* unregister */ + PRIN_LOG("Unregister PAL device"); + if ((err = hci_unregister_dev(pHciPalInfo->hdev)) < 0) { + PRIN_LOG("HCI PAL: failed to unregister with bluetooth %d\n",err); + } + } + + kfree(pHciPalInfo->hdev); + pHciPalInfo->hdev = NULL; +} + +/********************************************************* + * Allocate HCI device and store in PAL private info structure. + *********************************************************/ +static int bt_setup_hci_pal(ar6k_hci_pal_info_t *pHciPalInfo) +{ + int status = 0; + struct hci_dev *pHciDev = NULL; + + if (!setupbtdev) { + return 0; + } + + do { + /* allocate a BT HCI struct for this device */ + pHciDev = hci_alloc_dev(); + if (NULL == pHciDev) { + PRIN_LOG("HCI PAL driver - failed to allocate BT HCI struct \n"); + status = A_NO_MEMORY; + break; + } + + /* save the device, we'll register this later */ + pHciPalInfo->hdev = pHciDev; + SET_HCI_BUS_TYPE(pHciDev, HCI_VIRTUAL, HCI_80211); + pHciDev->driver_data = pHciPalInfo; + pHciDev->open = bt_open; + pHciDev->close = bt_close; + pHciDev->send = btpal_send_frame; + pHciDev->ioctl = bt_ioctl; + pHciDev->flush = bt_flush; + pHciDev->destruct = bt_destruct; + pHciDev->owner = THIS_MODULE; + /* driver is running in normal BT mode */ + PRIN_LOG("Normal mode enabled"); + bt_set_bit(pHciPalInfo->ulFlags, HCI_NORMAL_MODE); + + } while (false); + + if (status) { + bt_cleanup_hci_pal(pHciPalInfo); + } + return status; +} + +/********************************************** + * Cleanup HCI device and free HCI PAL private info + *********************************************/ +void ar6k_cleanup_hci_pal(void *ar_p) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar_p; + ar6k_hci_pal_info_t *pHciPalInfo = (ar6k_hci_pal_info_t *)ar->hcipal_info; + + if (pHciPalInfo != NULL) { + bt_cleanup_hci_pal(pHciPalInfo); + A_FREE(pHciPalInfo); + ar->hcipal_info = NULL; + } +} + +/**************************** + * Register HCI device + ****************************/ +static bool ar6k_pal_transport_ready(void *pHciPal) +{ + ar6k_hci_pal_info_t *pHciPalInfo = (ar6k_hci_pal_info_t *)pHciPal; + + PRIN_LOG("HCI device transport ready"); + if(pHciPalInfo == NULL) + return false; + + if (hci_register_dev(pHciPalInfo->hdev) < 0) { + PRIN_LOG("Can't register HCI device"); + hci_free_dev(pHciPalInfo->hdev); + return false; + } + PRIN_LOG("HCI device registered"); + pHciPalInfo->ulFlags |= HCI_REGISTERED; + return true; +} + +/************************************************** + * Called from ar6k driver when command or ACL data + * packet is received. Pass the packet to bluetooth + * stack via hci_recv_frame. + **************************************************/ +bool ar6k_pal_recv_pkt(void *pHciPal, void *osbuf) +{ + struct sk_buff *skb = (struct sk_buff *)osbuf; + ar6k_hci_pal_info_t *pHciPalInfo; + bool success = false; + u8 btType = 0; + pHciPalInfo = (ar6k_hci_pal_info_t *)pHciPal; + + do { + + /* if normal mode is not enabled pass on to the stack + * by returning failure */ + if(!(pHciPalInfo->ulFlags & HCI_NORMAL_MODE)) + { + PRIN_LOG("Normal mode not enabled"); + break; + } + + if (!test_bit(HCI_RUNNING, &pHciPalInfo->hdev->flags)) { + PRIN_LOG("HCI PAL: HCI - not running\n"); + break; + } + + if(*((short *)A_NETBUF_DATA(skb)) == WMI_ACL_DATA_EVENTID) + btType = HCI_ACLDATA_PKT; + else + btType = HCI_EVENT_PKT; + /* pull 4 bytes which contains WMI packet type */ + A_NETBUF_PULL(skb, sizeof(int)); + bt_cb(skb)->pkt_type = btType; + skb->dev = (void *)pHciPalInfo->hdev; + + /* pass the received event packet up the stack */ + if (hci_recv_frame(skb) != 0) { + PRIN_LOG("HCI PAL: hci_recv_frame failed \n"); + break; + } else { + PRIN_LOG("HCI PAL: Indicated RCV of type:%d, Length:%d \n",HCI_EVENT_PKT, skb->len); + } + PRIN_LOG("hci recv success"); + success = true; + }while(false); + return success; +} + +/********************************************************** + * HCI PAL init function called from ar6k when it is loaded.. + * Allocates PAL private info, stores the same in ar6k private info. + * Registers a HCI device. + * Registers packet receive callback function with ar6k + **********************************************************/ +int ar6k_setup_hci_pal(void *ar_p) +{ + int status = 0; + ar6k_hci_pal_info_t *pHciPalInfo; + ar6k_pal_config_t ar6k_pal_config; + struct ar6_softc *ar = (struct ar6_softc *)ar_p; + + do { + + pHciPalInfo = (ar6k_hci_pal_info_t *)A_MALLOC(sizeof(ar6k_hci_pal_info_t)); + + if (NULL == pHciPalInfo) { + status = A_NO_MEMORY; + break; + } + + A_MEMZERO(pHciPalInfo, sizeof(ar6k_hci_pal_info_t)); + ar->hcipal_info = pHciPalInfo; + pHciPalInfo->ar = ar; + + status = bt_setup_hci_pal(pHciPalInfo); + if (status) { + break; + } + + if(bt_check_bit(pHciPalInfo->ulFlags, HCI_NORMAL_MODE)) + PRIN_LOG("HCI PAL: running in normal mode... \n"); + else + PRIN_LOG("HCI PAL: running in test mode... \n"); + + ar6k_pal_config.fpar6k_pal_recv_pkt = ar6k_pal_recv_pkt; + register_pal_cb(&ar6k_pal_config); + ar6k_pal_transport_ready(ar->hcipal_info); + } while (false); + + if (status) { + ar6k_cleanup_hci_pal(ar); + } + return status; +} +#else /* AR6K_ENABLE_HCI_PAL */ +int ar6k_setup_hci_pal(void *ar_p) +{ + return 0; +} +void ar6k_cleanup_hci_pal(void *ar_p) +{ +} +#endif /* AR6K_ENABLE_HCI_PAL */ + +#ifdef EXPORT_HCI_PAL_INTERFACE +/***************************************************** + * Register init and callback function with ar6k + * when PAL driver is a separate kernel module. + ****************************************************/ +int ar6k_register_hci_pal(struct hci_transport_callbacks *hciTransCallbacks); +static int __init pal_init_module(void) +{ + struct hci_transport_callbacks hciTransCallbacks; + + hciTransCallbacks.setupTransport = ar6k_setup_hci_pal; + hciTransCallbacks.cleanupTransport = ar6k_cleanup_hci_pal; + + if(ar6k_register_hci_pal(&hciTransCallbacks) != 0) + return -ENODEV; + + return 0; +} + +static void __exit pal_cleanup_module(void) +{ +} + +module_init(pal_init_module); +module_exit(pal_cleanup_module); +MODULE_LICENSE("Dual BSD/GPL"); +#endif diff --git a/trunk/drivers/staging/ath6kl/os/linux/cfg80211.c b/trunk/drivers/staging/ath6kl/os/linux/cfg80211.c index e87d3aa8526d..bcca39418f90 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/cfg80211.c +++ b/trunk/drivers/staging/ath6kl/os/linux/cfg80211.c @@ -552,7 +552,7 @@ ar6k_cfg80211_connect_event(struct ar6_softc *ar, u16 channel, ibss_channel, mgmt, le16_to_cpu(size), signal, GFP_KERNEL); - kfree(ieeemgmtbuf); + A_FREE(ieeemgmtbuf); cfg80211_put_bss(bss); } @@ -627,10 +627,6 @@ ar6k_cfg80211_disconnect_event(struct ar6_softc *ar, u8 reason, AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: reason=%u\n", __func__, reason)); - if (ar->scan_request) { - cfg80211_scan_done(ar->scan_request, true); - ar->scan_request = NULL; - } if((ADHOC_NETWORK & ar->arNetworkType)) { if(NL80211_IFTYPE_ADHOC != ar->wdev->iftype) { AR_DEBUG_PRINTF(ATH_DEBUG_INFO, @@ -733,7 +729,7 @@ ar6k_cfg80211_scan_node(void *arg, bss_t *ni) le16_to_cpu(size), signal, GFP_KERNEL); - kfree (ieeemgmtbuf); + A_FREE (ieeemgmtbuf); } static int @@ -1209,10 +1205,10 @@ ar6k_cfg80211_set_power_mgmt(struct wiphy *wiphy, if(pmgmt) { AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: Max Perf\n", __func__)); - pwrMode.powerMode = REC_POWER; + pwrMode.powerMode = MAX_PERF_POWER; } else { AR_DEBUG_PRINTF(ATH_DEBUG_INFO, ("%s: Rec Power\n", __func__)); - pwrMode.powerMode = MAX_PERF_POWER; + pwrMode.powerMode = REC_POWER; } if(wmi_powermode_cmd(ar->arWmi, pwrMode.powerMode) != 0) { diff --git a/trunk/drivers/staging/ath6kl/os/linux/eeprom.c b/trunk/drivers/staging/ath6kl/os/linux/eeprom.c index 96f172497dbb..4cff9da2f03e 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/eeprom.c +++ b/trunk/drivers/staging/ath6kl/os/linux/eeprom.c @@ -359,3 +359,216 @@ commit_4bytes(int offset, u32 data) request_4byte_write(offset, data); wait_for_eeprom_completion(); } +/* ATHENV */ +#ifdef ANDROID_ENV +void eeprom_ar6000_transfer(struct hif_device *device, char *fake_file, char *p_mac) +{ + u32 first_word; + u32 board_data_addr; + int i; + + printk("%s: Enter\n", __FUNCTION__); + + enable_SI(device); + eeprom_type_detect(); + + if (fake_file) { + /* + * Transfer from file to Target RAM. + * Fetch source data from file. + */ + mm_segment_t oldfs; + struct file *filp; + struct inode *inode = NULL; + int length; + + /* open file */ + oldfs = get_fs(); + set_fs(KERNEL_DS); + filp = filp_open(fake_file, O_RDONLY, S_IRUSR); + + if (IS_ERR(filp)) { + printk("%s: file %s filp_open error\n", __FUNCTION__, fake_file); + set_fs(oldfs); + return; + } + + if (!filp->f_op) { + printk("%s: File Operation Method Error\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + inode = GET_INODE_FROM_FILEP(filep); + if (!inode) { + printk("%s: Get inode from filp failed\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + printk("%s file offset opsition: %xh\n", __FUNCTION__, (unsigned)filp->f_pos); + + /* file's size */ + length = i_size_read(inode->i_mapping->host); + printk("%s: length=%d\n", __FUNCTION__, length); + if (length != EEPROM_SZ) { + printk("%s: The file's size is not as expected\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + /* read data */ + if (filp->f_op->read(filp, eeprom_data, length, &filp->f_pos) != length) { + printk("%s: file read error\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + /* read data out successfully */ + filp_close(filp, NULL); + set_fs(oldfs); + } else { + /* + * Read from EEPROM to file OR transfer from EEPROM to Target RAM. + * Fetch EEPROM_SZ Bytes of Board Data, 8 bytes at a time. + */ + + fetch_8bytes(0, (u32 *)(&eeprom_data[0])); + + /* Check the first word of EEPROM for validity */ + first_word = *((u32 *)eeprom_data); + + if ((first_word == 0) || (first_word == 0xffffffff)) { + printk("Did not find EEPROM with valid Board Data.\n"); + } + + for (i=8; if_op) { + printk("%s: File Operation Method Error\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + inode = GET_INODE_FROM_FILEP(filep); + if (!inode) { + printk("%s: Get inode from filp failed\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + printk("%s file offset opsition: %xh\n", __FUNCTION__, (unsigned)filp->f_pos); + + /* file's size */ + length = i_size_read(inode->i_mapping->host); + printk("%s: length=%d\n", __FUNCTION__, length); + if (length > ATH_SOFT_MAC_TMP_BUF_LEN) { + printk("%s: MAC file's size is not as expected\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + + /* read data */ + if (filp->f_op->read(filp, soft_mac_tmp_buf, length, &filp->f_pos) != length) { + printk("%s: file read error\n", __FUNCTION__); + filp_close(filp, NULL); + set_fs(oldfs); + return; + } + +#if 0 + /* the data we just read */ + printk("%s: mac address from the file:\n", __FUNCTION__); + for (i = 0; i < length; i++) + printk("[%c(0x%x)],", soft_mac_tmp_buf[i], soft_mac_tmp_buf[i]); + printk("\n"); +#endif + + /* read data out successfully */ + filp_close(filp, NULL); + set_fs(oldfs); + + /* convert mac address */ + if (!wmic_ether_aton(soft_mac_tmp_buf, mac_addr)) { + printk("%s: convert mac value fail\n", __FUNCTION__); + return; + } + +#if 0 + /* the converted mac address */ + printk("%s: the converted mac value\n", __FUNCTION__); + for (i = 0; i < ATH_MAC_LEN; i++) + printk("[0x%x],", mac_addr[i]); + printk("\n"); +#endif + } + /* soft mac */ + + /* Determine where in Target RAM to write Board Data */ + BMI_read_mem( HOST_INTEREST_ITEM_ADDRESS(hi_board_data), &board_data_addr); + if (board_data_addr == 0) { + printk("hi_board_data is zero\n"); + } + + /* soft mac */ +#if 1 + /* Update MAC address in RAM */ + if (p_mac) { + update_mac(eeprom_data, EEPROM_SZ, mac_addr); + } +#endif +#if 0 + /* mac address in eeprom array */ + printk("%s: mac values in eeprom array\n", __FUNCTION__); + for (i = 10; i < 10 + 6; i++) + printk("[0x%x],", eeprom_data[i]); + printk("\n"); +#endif + /* soft mac */ + + /* Write EEPROM data to Target RAM */ + BMI_write_mem(board_data_addr, ((u8 *)eeprom_data), EEPROM_SZ); + + /* Record the fact that Board Data IS initialized */ + { + u32 one = 1; + BMI_write_mem(HOST_INTEREST_ITEM_ADDRESS(hi_board_data_initialized), + (u8 *)&one, sizeof(u32)); + } + + disable_SI(); +} +#endif +/* ATHENV */ + diff --git a/trunk/drivers/staging/ath6kl/os/linux/hci_bridge.c b/trunk/drivers/staging/ath6kl/os/linux/hci_bridge.c index ac08bcbc4f26..39e5798f5e80 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/hci_bridge.c +++ b/trunk/drivers/staging/ath6kl/os/linux/hci_bridge.c @@ -582,11 +582,11 @@ void ar6000_cleanup_hci(struct ar6_softc *ar) } if (pHcidevInfo->pHTCStructAlloc != NULL) { - kfree(pHcidevInfo->pHTCStructAlloc); + A_FREE(pHcidevInfo->pHTCStructAlloc); pHcidevInfo->pHTCStructAlloc = NULL; } - kfree(pHcidevInfo); + A_FREE(pHcidevInfo); #ifndef EXPORT_HCI_BRIDGE_INTERFACE ar->hcidev_info = NULL; #endif diff --git a/trunk/drivers/staging/ath6kl/os/linux/include/ar6000_drv.h b/trunk/drivers/staging/ath6kl/os/linux/include/ar6000_drv.h index b466e7f54567..89fd80a2c8ed 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/include/ar6000_drv.h +++ b/trunk/drivers/staging/ath6kl/os/linux/include/ar6000_drv.h @@ -33,7 +33,9 @@ #include #include #include +#ifdef ATH6K_CONFIG_CFG80211 #include +#endif /* ATH6K_CONFIG_CFG80211 */ #include #include @@ -92,6 +94,8 @@ #endif +#ifdef USER_KEYS + #define USER_SAVEDKEYS_STAT_INIT 0 #define USER_SAVEDKEYS_STAT_RUN 1 @@ -102,6 +106,7 @@ struct USER_SAVEDKEYS { CRYPTO_TYPE keyType; bool keyOk; }; +#endif #define DBG_INFO 0x00000001 #define DBG_ERROR 0x00000002 @@ -210,42 +215,35 @@ typedef enum _AR6K_BIN_FILE { #define SETUPHCI_DEFAULT 0 #endif /* SETUPHCI_ENABLED */ +#ifdef SETUPHCIPAL_ENABLED +#define SETUPHCIPAL_DEFAULT 1 +#else +#define SETUPHCIPAL_DEFAULT 0 +#endif /* SETUPHCIPAL_ENABLED */ + #ifdef SETUPBTDEV_ENABLED #define SETUPBTDEV_DEFAULT 1 #else #define SETUPBTDEV_DEFAULT 0 #endif /* SETUPBTDEV_ENABLED */ +#ifdef BMIENABLE_SET +#define BMIENABLE_DEFAULT 1 +#else +#define BMIENABLE_DEFAULT 0 +#endif /* BMIENABLE_SET */ + #ifdef ENABLEUARTPRINT_SET #define ENABLEUARTPRINT_DEFAULT 1 #else #define ENABLEUARTPRINT_DEFAULT 0 #endif /* ENABLEARTPRINT_SET */ -#ifdef ATH6KL_CONFIG_HIF_VIRTUAL_SCATTER +#ifdef ATH6K_CONFIG_HIF_VIRTUAL_SCATTER #define NOHIFSCATTERSUPPORT_DEFAULT 1 -#else /* ATH6KL_CONFIG_HIF_VIRTUAL_SCATTER */ +#else /* ATH6K_CONFIG_HIF_VIRTUAL_SCATTER */ #define NOHIFSCATTERSUPPORT_DEFAULT 0 -#endif /* ATH6KL_CONFIG_HIF_VIRTUAL_SCATTER */ - - -#if defined(CONFIG_ATH6KL_ENABLE_COEXISTENCE) - -#ifdef CONFIG_AR600x_BT_QCOM -#define ATH6KL_BT_DEV 1 -#elif defined(CONFIG_AR600x_BT_CSR) -#define ATH6KL_BT_DEV 2 -#else -#define ATH6KL_BT_DEV 3 -#endif - -#ifdef CONFIG_AR600x_DUAL_ANTENNA -#define ATH6KL_BT_ANTENNA 2 -#else -#define ATH6KL_BT_ANTENNA 1 -#endif - -#endif /* CONFIG_ATH6KL_ENABLE_COEXISTENCE */ +#endif /* ATH6K_CONFIG_HIF_VIRTUAL_SCATTER */ #ifdef AR600x_BT_AR3001 #define AR3KHCIBAUD_DEFAULT 3000000 @@ -257,7 +255,11 @@ typedef enum _AR6K_BIN_FILE { #define HCIUARTSTEP_DEFAULT 0 #endif /* AR600x_BT_AR3001 */ +#ifdef INIT_MODE_DRV_ENABLED #define WLAN_INIT_MODE_DEFAULT WLAN_INIT_MODE_DRV +#else +#define WLAN_INIT_MODE_DEFAULT WLAN_INIT_MODE_USR +#endif /* INIT_MODE_DRV_ENABLED */ #define AR6K_PATCH_DOWNLOAD_ADDRESS(_param, _ver) do { \ if ((_ver) == AR6003_REV1_VERSION) { \ @@ -281,37 +283,15 @@ typedef enum _AR6K_BIN_FILE { } \ } while (0) -#define AR6K_DATASET_PATCH_ADDRESS(_param, _ver) do { \ - if ((_ver) == AR6003_REV2_VERSION) { \ - (_param) = AR6003_REV2_DATASET_PATCH_ADDRESS; \ - } else if ((_ver) == AR6003_REV3_VERSION) { \ - (_param) = AR6003_REV3_DATASET_PATCH_ADDRESS; \ - } else { \ - AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \ - A_ASSERT(0); \ - } \ -} while (0) - -#define AR6K_APP_LOAD_ADDRESS(_param, _ver) do { \ - if ((_ver) == AR6003_REV2_VERSION) { \ - (_param) = AR6003_REV2_APP_LOAD_ADDRESS; \ - } else if ((_ver) == AR6003_REV3_VERSION) { \ - (_param) = AR6003_REV3_APP_LOAD_ADDRESS; \ - } else { \ - AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \ - A_ASSERT(0); \ - } \ -} while (0) - #define AR6K_APP_START_OVERRIDE_ADDRESS(_param, _ver) do { \ - if ((_ver) == AR6003_REV2_VERSION) { \ - (_param) = AR6003_REV2_APP_START_OVERRIDE; \ - } else if ((_ver) == AR6003_REV3_VERSION) { \ - (_param) = AR6003_REV3_APP_START_OVERRIDE; \ - } else { \ - AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \ - A_ASSERT(0); \ - } \ + if ((_ver) == AR6003_REV1_VERSION) { \ + (_param) = AR6003_REV1_APP_START_OVERRIDE; \ + } else if ((_ver) == AR6003_REV2_VERSION) { \ + (_param) = AR6003_REV2_APP_START_OVERRIDE; \ + } else { \ + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, ("Unknown Version: %d\n", _ver)); \ + A_ASSERT(0); \ + } \ } while (0) /* AR6003 1.0 definitions */ @@ -324,11 +304,11 @@ typedef enum _AR6K_BIN_FILE { #define AR6003_REV1_ART_FIRMWARE_FILE "ath6k/AR6003/hw1.0/device.bin" #define AR6003_REV1_PATCH_FILE "ath6k/AR6003/hw1.0/data.patch.bin" #define AR6003_REV1_EPPING_FIRMWARE_FILE "ath6k/AR6003/hw1.0/endpointping.bin" -#ifdef CONFIG_AR600x_SD31_XXX +#ifdef AR600x_SD31_XXX #define AR6003_REV1_BOARD_DATA_FILE "ath6k/AR6003/hw1.0/bdata.SD31.bin" -#elif defined(CONFIG_AR600x_SD32_XXX) +#elif defined(AR600x_SD32_XXX) #define AR6003_REV1_BOARD_DATA_FILE "ath6k/AR6003/hw1.0/bdata.SD32.bin" -#elif defined(CONFIG_AR600x_WB31_XXX) +#elif defined(AR600x_WB31_XXX) #define AR6003_REV1_BOARD_DATA_FILE "ath6k/AR6003/hw1.0/bdata.WB31.bin" #else #define AR6003_REV1_BOARD_DATA_FILE "ath6k/AR6003/hw1.0/bdata.CUSTOM.bin" @@ -344,35 +324,16 @@ typedef enum _AR6K_BIN_FILE { #define AR6003_REV2_ART_FIRMWARE_FILE "ath6k/AR6003/hw2.0/device.bin" #define AR6003_REV2_PATCH_FILE "ath6k/AR6003/hw2.0/data.patch.bin" #define AR6003_REV2_EPPING_FIRMWARE_FILE "ath6k/AR6003/hw2.0/endpointping.bin" -#ifdef CONFIG_AR600x_SD31_XXX +#ifdef AR600x_SD31_XXX #define AR6003_REV2_BOARD_DATA_FILE "ath6k/AR6003/hw2.0/bdata.SD31.bin" -#elif defined(CONFIG_AR600x_SD32_XXX) +#elif defined(AR600x_SD32_XXX) #define AR6003_REV2_BOARD_DATA_FILE "ath6k/AR6003/hw2.0/bdata.SD32.bin" -#elif defined(CONFIG_AR600x_WB31_XXX) +#elif defined(AR600x_WB31_XXX) #define AR6003_REV2_BOARD_DATA_FILE "ath6k/AR6003/hw2.0/bdata.WB31.bin" #else #define AR6003_REV2_BOARD_DATA_FILE "ath6k/AR6003/hw2.0/bdata.CUSTOM.bin" #endif /* Board Data File */ -/* AR6003 3.0 definitions */ -#define AR6003_REV3_VERSION 0x30000582 -#define AR6003_REV3_OTP_FILE "ath6k/AR6003/hw2.1.1/otp.bin" -#define AR6003_REV3_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/athwlan.bin" -#define AR6003_REV3_TCMD_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/athtcmd_ram.bin" -#define AR6003_REV3_ART_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/device.bin" -#define AR6003_REV3_PATCH_FILE "ath6k/AR6003/hw2.1.1/data.patch.bin" -#define AR6003_REV3_EPPING_FIRMWARE_FILE "ath6k/AR6003/hw2.1.1/endpointping.bin" -#ifdef CONFIG_AR600x_SD31_XXX -#define AR6003_REV3_BOARD_DATA_FILE "ath6k/AR6003/hw2.1.1/bdata.SD31.bin" -#elif defined(CONFIG_AR600x_SD32_XXX) -#define AR6003_REV3_BOARD_DATA_FILE "ath6k/AR6003/hw2.1.1/bdata.SD32.bin" -#elif defined(CONFIG_AR600x_WB31_XXX) -#define AR6003_REV3_BOARD_DATA_FILE "ath6k/AR6003/hw2.1.1/bdata.WB31.bin" -#else -#define AR6003_REV3_BOARD_DATA_FILE "ath6k/AR6003/hw2.1.1/bdata.CUSTOM.bin" -#endif /* Board Data File */ - - /* Power states */ enum { WLAN_PWR_CTRL_UP = 0, @@ -424,6 +385,7 @@ struct ar_wep_key { u8 arKey[64]; } ; +#ifdef ATH6K_CONFIG_CFG80211 struct ar_key { u8 key[WLAN_MAX_KEY_LEN]; u8 key_len; @@ -437,6 +399,8 @@ enum { SME_CONNECTING, SME_CONNECTED }; +#endif /* ATH6K_CONFIG_CFG80211 */ + struct ar_node_mapping { u8 macAddress[6]; @@ -593,9 +557,11 @@ struct ar6_softc { u32 log_cnt; u32 dbglog_init_done; u32 arConnectCtrlFlags; +#ifdef USER_KEYS s32 user_savedkeys_stat; u32 user_key_ctrl; struct USER_SAVEDKEYS user_saved_keys; +#endif USER_RSSI_THOLD rssi_map[12]; u8 arUserBssFilter; u16 ap_profile_flag; /* AP mode */ @@ -611,6 +577,7 @@ struct ar6_softc { #ifndef EXPORT_HCI_BRIDGE_INTERFACE void *hcidev_info; #endif + void *hcipal_info; WMI_AP_MODE_STAT arAPStats; u8 ap_hidden_ssid; u8 ap_country_code[3]; @@ -630,10 +597,12 @@ struct ar6_softc { WMI_BTCOEX_STATS_EVENT arBtcoexStats; s32 (*exitCallback)(void *config); /* generic callback at AR6K exit */ struct hif_device_os_device_info osDevInfo; +#ifdef ATH6K_CONFIG_CFG80211 struct wireless_dev *wdev; struct cfg80211_scan_request *scan_request; struct ar_key keys[WMI_MAX_KEY_INDEX + 1]; u32 smeState; +#endif /* ATH6K_CONFIG_CFG80211 */ u16 arWlanPowerState; bool arWlanOff; #ifdef CONFIG_PM @@ -663,10 +632,30 @@ struct ar_virtual_interface { }; #endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */ +#ifdef ATH6K_CONFIG_CFG80211 static inline void *ar6k_priv(struct net_device *dev) { return (wdev_priv(dev->ieee80211_ptr)); } +#else +#ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT +static inline void *ar6k_priv(struct net_device *dev) +{ + extern struct net_device *arApNetDev; + + if (arApNetDev == dev) { + /* return arDev saved in virtual interface context */ + struct ar_virtual_interface *arVirDev; + arVirDev = netdev_priv(dev); + return arVirDev->arDev; + } else { + return netdev_priv(dev); + } +} +#else +#define ar6k_priv netdev_priv +#endif /* CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT */ +#endif /* ATH6K_CONFIG_CFG80211 */ #define SET_HCI_BUS_TYPE(pHciDev, __bus, __type) do { \ (pHciDev)->bus = (__bus); \ @@ -712,6 +701,9 @@ struct ar_giwscan_param { spin_unlock_bh(lock); \ } while (0) +int ar6000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); +int ar6000_ioctl_dispatcher(struct net_device *dev, struct ifreq *rq, int cmd); +void ar6000_gpio_init(void); void ar6000_init_profile_info(struct ar6_softc *ar); void ar6000_install_static_wep_keys(struct ar6_softc *ar); int ar6000_init(struct net_device *dev); diff --git a/trunk/drivers/staging/ath6kl/os/linux/include/ar6xapi_linux.h b/trunk/drivers/staging/ath6kl/os/linux/include/ar6xapi_linux.h index 184dbdb50495..1acfb9cb7c73 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/include/ar6xapi_linux.h +++ b/trunk/drivers/staging/ath6kl/os/linux/include/ar6xapi_linux.h @@ -83,6 +83,11 @@ s16 rssi_compensation_reverse_calc(struct ar6_softc *ar, s16 rssi, bool Above); void ar6000_dbglog_init_done(struct ar6_softc *ar); +#ifdef SEND_EVENT_TO_APP +void ar6000_send_event_to_app(struct ar6_softc *ar, u16 eventId, u8 *datap, int len); +void ar6000_send_generic_event_to_app(struct ar6_softc *ar, u16 eventId, u8 *datap, int len); +#endif + #ifdef CONFIG_HOST_TCMD_SUPPORT void ar6000_tcmd_rx_report_event(void *devt, u8 *results, int len); #endif @@ -178,6 +183,9 @@ int ar6000_power_change_ev(void *context, u32 config); void ar6000_check_wow_status(struct ar6_softc *ar, struct sk_buff *skb, bool isEvent); #endif +void ar6000_pm_init(void); +void ar6000_pm_exit(void); + #ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT int ar6000_add_ap_interface(struct ar6_softc *ar, char *ifname); int ar6000_remove_ap_interface(struct ar6_softc *ar); diff --git a/trunk/drivers/staging/ath6kl/os/linux/include/athdrv_linux.h b/trunk/drivers/staging/ath6kl/os/linux/include/athdrv_linux.h index 3d5f01da543f..66817c2c5022 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/include/athdrv_linux.h +++ b/trunk/drivers/staging/ath6kl/os/linux/include/athdrv_linux.h @@ -620,6 +620,7 @@ typedef enum { */ #define AR6000_XIOCTL_WMI_SET_TXOP 57 +#ifdef USER_KEYS /* * arguments: * UINT32 cmd (AR6000_XIOCTL_USER_SETKEYS) @@ -627,6 +628,7 @@ typedef enum { * uses struct ar6000_user_setkeys_info */ #define AR6000_XIOCTL_USER_SETKEYS 58 +#endif /* USER_KEYS */ #define AR6000_XIOCTL_WMI_SET_KEEPALIVE 59 /* @@ -940,7 +942,7 @@ typedef enum { #define AR6000_XIOCTL_HCI_CMD 132 -#define AR6000_XIOCTL_ACL_DATA 133 /* used to be used for PAL */ +#define AR6000_XIOCTL_ACL_DATA 133 #define AR6000_XIOCTL_WLAN_CONN_PRECEDENCE 134 diff --git a/trunk/drivers/staging/ath6kl/os/linux/include/config_linux.h b/trunk/drivers/staging/ath6kl/os/linux/include/config_linux.h index d4030e26b20c..50f53d361049 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/include/config_linux.h +++ b/trunk/drivers/staging/ath6kl/os/linux/include/config_linux.h @@ -30,6 +30,13 @@ extern "C" { #include +/* + * Host-side GPIO support is optional. + * If run-time access to GPIO pins is not required, then + * this should be changed to #undef. + */ +#define CONFIG_HOST_GPIO_SUPPORT + /* * Host side Test Command support */ diff --git a/trunk/drivers/staging/ath6kl/os/linux/include/osapi_linux.h b/trunk/drivers/staging/ath6kl/os/linux/include/osapi_linux.h index 07078b49583f..53b500c1835f 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/include/osapi_linux.h +++ b/trunk/drivers/staging/ath6kl/os/linux/include/osapi_linux.h @@ -79,10 +79,33 @@ #define A_MEMZERO(addr, len) memset(addr, 0, len) #define A_MALLOC(size) kmalloc((size), GFP_KERNEL) #define A_MALLOC_NOWAIT(size) kmalloc((size), GFP_ATOMIC) - +#define A_FREE(addr) kfree(addr) + +#if defined(ANDROID_ENV) && defined(CONFIG_ANDROID_LOGGER) +extern unsigned int enablelogcat; +extern int android_logger_lv(void* module, int mask); +enum logidx { LOG_MAIN_IDX = 0 }; +extern int logger_write(const enum logidx idx, + const unsigned char prio, + const char __kernel * const tag, + const char __kernel * const fmt, + ...); +#define A_ANDROID_PRINTF(mask, module, tags, args...) do { \ + if (enablelogcat) \ + logger_write(LOG_MAIN_IDX, android_logger_lv(module, mask), tags, args); \ + else \ + printk(KERN_ALERT args); \ +} while (0) +#ifdef DEBUG +#define A_LOGGER_MODULE_NAME(x) #x +#define A_LOGGER(mask, mod, args...) \ + A_ANDROID_PRINTF(mask, &GET_ATH_MODULE_DEBUG_VAR_NAME(mod), "ar6k_" A_LOGGER_MODULE_NAME(mod), args); +#endif +#define A_PRINTF(args...) A_ANDROID_PRINTF(ATH_DEBUG_INFO, NULL, "ar6k_driver", args) +#else #define A_LOGGER(mask, mod, args...) printk(KERN_ALERT args) #define A_PRINTF(args...) printk(KERN_ALERT args) - +#endif /* ANDROID */ #define A_PRINTF_LOG(args...) printk(args) #define A_SPRINTF(buf, args...) sprintf (buf, args) @@ -188,8 +211,17 @@ extern unsigned int panic_on_assert; #define A_ASSERT(expr) #endif /* DEBUG */ +#ifdef ANDROID_ENV +struct firmware; +int android_request_firmware(const struct firmware **firmware_p, const char *filename, + struct device *device); +void android_release_firmware(const struct firmware *firmware); +#define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) android_request_firmware(_ppf, _pfile, _dev) +#define A_RELEASE_FIRMWARE(_pf) android_release_firmware(_pf) +#else #define A_REQUEST_FIRMWARE(_ppf, _pfile, _dev) request_firmware(_ppf, _pfile, _dev) #define A_RELEASE_FIRMWARE(_pf) release_firmware(_pf) +#endif /* * Initialization of the network buffer subsystem @@ -332,8 +364,19 @@ static inline void *A_ALIGN_TO_CACHE_LINE(void *ptr) { #define A_MEMZERO(addr, len) memset((addr), 0, (len)) #define A_MALLOC(size) malloc(size) - +#define A_FREE(addr) free(addr) + +#ifdef ANDROID +#ifndef err +#include +#define err(_s, args...) do { \ + fprintf(stderr, "%s: line %d ", __FILE__, __LINE__); \ + fprintf(stderr, args); fprintf(stderr, ": %d\n", errno); \ + exit(_s); } while (0) +#endif +#else #include +#endif #endif /* __KERNEL__ */ diff --git a/trunk/drivers/staging/ath6kl/os/linux/include/wlan_config.h b/trunk/drivers/staging/ath6kl/os/linux/include/wlan_config.h index c1fe0c6e4fa1..2de5cef26cce 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/include/wlan_config.h +++ b/trunk/drivers/staging/ath6kl/os/linux/include/wlan_config.h @@ -56,7 +56,11 @@ * If the firmware successly roams within the disconnect timeout * it sends a new connect event */ +#ifdef ANDROID_ENV +#define WLAN_CONFIG_DISCONNECT_TIMEOUT 3 +#else #define WLAN_CONFIG_DISCONNECT_TIMEOUT 10 +#endif /* ANDROID_ENV */ /* * This configuration item disables 11n support. @@ -105,4 +109,10 @@ */ #define WLAN_CONFIG_DISABLE_TX_BURSTING 0 +/* + * Platform specific function to power ON/OFF AR6000 + * and enable/disable SDIO card detection + */ +#define plat_setup_power(on, detect) + #endif /* _HOST_WLAN_CONFIG_H_ */ diff --git a/trunk/drivers/staging/ath6kl/os/linux/include/wmi_filter_linux.h b/trunk/drivers/staging/ath6kl/os/linux/include/wmi_filter_linux.h index 1eb6f822d64e..d172625afa18 100644 --- a/trunk/drivers/staging/ath6kl/os/linux/include/wmi_filter_linux.h +++ b/trunk/drivers/staging/ath6kl/os/linux/include/wmi_filter_linux.h @@ -266,7 +266,7 @@ u8 xioctl_filter[] = { (0xFF), /* AR6000_XIOCTL_DELE_AGGR 130 */ (0xFF), /* AR6000_XIOCTL_FETCH_TARGET_REGS 131 */ (0xFF), /* AR6000_XIOCTL_HCI_CMD 132 */ -(0xFF), /* AR6000_XIOCTL_ACL_DATA(used to be used for PAL) 133 */ +(0xFF), /* AR6000_XIOCTL_ACL_DATA 133 */ (0xFF), /* AR6000_XIOCTL_WLAN_CONN_PRECEDENCE 134 */ (AP_NETWORK), /* AR6000_XIOCTL_AP_SET_11BG_RATESET 135 */ (0xFF), diff --git a/trunk/drivers/staging/ath6kl/os/linux/ioctl.c b/trunk/drivers/staging/ath6kl/os/linux/ioctl.c new file mode 100644 index 000000000000..0daa201c6cca --- /dev/null +++ b/trunk/drivers/staging/ath6kl/os/linux/ioctl.c @@ -0,0 +1,4767 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#include "ar6000_drv.h" +#include "ieee80211_ioctl.h" +#include "ar6kap_common.h" +#include "targaddrs.h" +#include "a_hci.h" +#include "wlan_config.h" + +extern int enablerssicompensation; +u32 tcmdRxFreq; +extern unsigned int wmitimeout; +extern A_WAITQUEUE_HEAD arEvent; +extern int tspecCompliance; +extern int bmienable; +extern int loghci; + +static int +ar6000_ioctl_get_roam_tbl(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (ar->arWmiReady == false) { + return -EIO; + } + + if(wmi_get_roam_tbl_cmd(ar->arWmi) != 0) { + return -EIO; + } + + return 0; +} + +static int +ar6000_ioctl_get_roam_data(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (ar->arWmiReady == false) { + return -EIO; + } + + + /* currently assume only roam times are required */ + if(wmi_get_roam_data_cmd(ar->arWmi, ROAM_DATA_TIME) != 0) { + return -EIO; + } + + + return 0; +} + +static int +ar6000_ioctl_set_roam_ctrl(struct net_device *dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_ROAM_CTRL_CMD cmd; + u8 size = sizeof(cmd); + + if (ar->arWmiReady == false) { + return -EIO; + } + + + if (copy_from_user(&cmd, userdata, size)) { + return -EFAULT; + } + + if (cmd.roamCtrlType == WMI_SET_HOST_BIAS) { + if (cmd.info.bssBiasInfo.numBss > 1) { + size += (cmd.info.bssBiasInfo.numBss - 1) * sizeof(WMI_BSS_BIAS); + } + } + + if (copy_from_user(&cmd, userdata, size)) { + return -EFAULT; + } + + if(wmi_set_roam_ctrl_cmd(ar->arWmi, &cmd, size) != 0) { + return -EIO; + } + + return 0; +} + +static int +ar6000_ioctl_set_powersave_timers(struct net_device *dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_POWERSAVE_TIMERS_POLICY_CMD cmd; + u8 size = sizeof(cmd); + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, size)) { + return -EFAULT; + } + + if (copy_from_user(&cmd, userdata, size)) { + return -EFAULT; + } + + if(wmi_set_powersave_timers_cmd(ar->arWmi, &cmd, size) != 0) { + return -EIO; + } + + return 0; +} + +static int +ar6000_ioctl_set_qos_supp(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_QOS_SUPP_CMD cmd; + int ret; + + if ((dev->flags & IFF_UP) != IFF_UP) { + return -EIO; + } + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, (char *)((unsigned int*)rq->ifr_data + 1), + sizeof(cmd))) + { + return -EFAULT; + } + + ret = wmi_set_qos_supp_cmd(ar->arWmi, cmd.status); + + switch (ret) { + case 0: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + +static int +ar6000_ioctl_set_wmm(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_WMM_CMD cmd; + int ret; + + if ((dev->flags & IFF_UP) != IFF_UP) { + return -EIO; + } + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, (char *)((unsigned int*)rq->ifr_data + 1), + sizeof(cmd))) + { + return -EFAULT; + } + + if (cmd.status == WMI_WMM_ENABLED) { + ar->arWmmEnabled = true; + } else { + ar->arWmmEnabled = false; + } + + ret = wmi_set_wmm_cmd(ar->arWmi, cmd.status); + + switch (ret) { + case 0: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + +static int +ar6000_ioctl_set_txop(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_WMM_TXOP_CMD cmd; + int ret; + + if ((dev->flags & IFF_UP) != IFF_UP) { + return -EIO; + } + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, (char *)((unsigned int*)rq->ifr_data + 1), + sizeof(cmd))) + { + return -EFAULT; + } + + ret = wmi_set_wmm_txop(ar->arWmi, cmd.txopEnable); + + switch (ret) { + case 0: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + +static int +ar6000_ioctl_get_rd(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + int ret = 0; + + if ((dev->flags & IFF_UP) != IFF_UP || ar->arWmiReady == false) { + return -EIO; + } + + if(copy_to_user((char *)((unsigned int*)rq->ifr_data + 1), + &ar->arRegCode, sizeof(ar->arRegCode))) + ret = -EFAULT; + + return ret; +} + +static int +ar6000_ioctl_set_country(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_AP_SET_COUNTRY_CMD cmd; + int ret; + + if ((dev->flags & IFF_UP) != IFF_UP) { + return -EIO; + } + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, (char *)((unsigned int*)rq->ifr_data + 1), + sizeof(cmd))) + { + return -EFAULT; + } + + ar->ap_profile_flag = 1; /* There is a change in profile */ + + ret = wmi_set_country(ar->arWmi, cmd.countryCode); + memcpy(ar->ap_country_code, cmd.countryCode, 3); + + switch (ret) { + case 0: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + + +/* Get power mode command */ +static int +ar6000_ioctl_get_power_mode(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_POWER_MODE_CMD power_mode; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + power_mode.powerMode = wmi_get_power_mode_cmd(ar->arWmi); + if (copy_to_user(rq->ifr_data, &power_mode, sizeof(WMI_POWER_MODE_CMD))) { + ret = -EFAULT; + } + + return ret; +} + + +static int +ar6000_ioctl_set_channelParams(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_CHANNEL_PARAMS_CMD cmd, *cmdp; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if( (ar->arNextMode == AP_NETWORK) && (cmd.numChannels || cmd.scanParam) ) { + A_PRINTF("ERROR: Only wmode is allowed in AP mode\n"); + return -EIO; + } + + if (cmd.numChannels > 1) { + cmdp = A_MALLOC(130); + if (copy_from_user(cmdp, rq->ifr_data, + sizeof (*cmdp) + + ((cmd.numChannels - 1) * sizeof(u16)))) + { + kfree(cmdp); + return -EFAULT; + } + } else { + cmdp = &cmd; + } + + if ((ar->arPhyCapability == WMI_11G_CAPABILITY) && + ((cmdp->phyMode == WMI_11A_MODE) || (cmdp->phyMode == WMI_11AG_MODE))) + { + ret = -EINVAL; + } + + if (!ret && + (wmi_set_channelParams_cmd(ar->arWmi, cmdp->scanParam, cmdp->phyMode, + cmdp->numChannels, cmdp->channelList) + != 0)) + { + ret = -EIO; + } + + if (cmd.numChannels > 1) { + kfree(cmdp); + } + + ar->ap_wmode = cmdp->phyMode; + /* Set the profile change flag to allow a commit cmd */ + ar->ap_profile_flag = 1; + + return ret; +} + + +static int +ar6000_ioctl_set_snr_threshold(struct net_device *dev, struct ifreq *rq) +{ + + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SNR_THRESHOLD_PARAMS_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if( wmi_set_snr_threshold_params(ar->arWmi, &cmd) != 0 ) { + ret = -EIO; + } + + return ret; +} + +static int +ar6000_ioctl_set_rssi_threshold(struct net_device *dev, struct ifreq *rq) +{ +#define SWAP_THOLD(thold1, thold2) do { \ + USER_RSSI_THOLD tmpThold; \ + tmpThold.tag = thold1.tag; \ + tmpThold.rssi = thold1.rssi; \ + thold1.tag = thold2.tag; \ + thold1.rssi = thold2.rssi; \ + thold2.tag = tmpThold.tag; \ + thold2.rssi = tmpThold.rssi; \ +} while (0) + + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_RSSI_THRESHOLD_PARAMS_CMD cmd; + USER_RSSI_PARAMS rssiParams; + s32 i, j; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user((char *)&rssiParams, (char *)((unsigned int *)rq->ifr_data + 1), sizeof(USER_RSSI_PARAMS))) { + return -EFAULT; + } + cmd.weight = rssiParams.weight; + cmd.pollTime = rssiParams.pollTime; + + memcpy(ar->rssi_map, &rssiParams.tholds, sizeof(ar->rssi_map)); + /* + * only 6 elements, so use bubble sorting, in ascending order + */ + for (i = 5; i > 0; i--) { + for (j = 0; j < i; j++) { /* above tholds */ + if (ar->rssi_map[j+1].rssi < ar->rssi_map[j].rssi) { + SWAP_THOLD(ar->rssi_map[j+1], ar->rssi_map[j]); + } else if (ar->rssi_map[j+1].rssi == ar->rssi_map[j].rssi) { + return -EFAULT; + } + } + } + for (i = 11; i > 6; i--) { + for (j = 6; j < i; j++) { /* below tholds */ + if (ar->rssi_map[j+1].rssi < ar->rssi_map[j].rssi) { + SWAP_THOLD(ar->rssi_map[j+1], ar->rssi_map[j]); + } else if (ar->rssi_map[j+1].rssi == ar->rssi_map[j].rssi) { + return -EFAULT; + } + } + } + +#ifdef DEBUG + for (i = 0; i < 12; i++) { + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("thold[%d].tag: %d, thold[%d].rssi: %d \n", + i, ar->rssi_map[i].tag, i, ar->rssi_map[i].rssi)); + } +#endif + + if (enablerssicompensation) { + for (i = 0; i < 6; i++) + ar->rssi_map[i].rssi = rssi_compensation_reverse_calc(ar, ar->rssi_map[i].rssi, true); + for (i = 6; i < 12; i++) + ar->rssi_map[i].rssi = rssi_compensation_reverse_calc(ar, ar->rssi_map[i].rssi, false); + } + + cmd.thresholdAbove1_Val = ar->rssi_map[0].rssi; + cmd.thresholdAbove2_Val = ar->rssi_map[1].rssi; + cmd.thresholdAbove3_Val = ar->rssi_map[2].rssi; + cmd.thresholdAbove4_Val = ar->rssi_map[3].rssi; + cmd.thresholdAbove5_Val = ar->rssi_map[4].rssi; + cmd.thresholdAbove6_Val = ar->rssi_map[5].rssi; + cmd.thresholdBelow1_Val = ar->rssi_map[6].rssi; + cmd.thresholdBelow2_Val = ar->rssi_map[7].rssi; + cmd.thresholdBelow3_Val = ar->rssi_map[8].rssi; + cmd.thresholdBelow4_Val = ar->rssi_map[9].rssi; + cmd.thresholdBelow5_Val = ar->rssi_map[10].rssi; + cmd.thresholdBelow6_Val = ar->rssi_map[11].rssi; + + if( wmi_set_rssi_threshold_params(ar->arWmi, &cmd) != 0 ) { + ret = -EIO; + } + + return ret; +} + +static int +ar6000_ioctl_set_lq_threshold(struct net_device *dev, struct ifreq *rq) +{ + + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_LQ_THRESHOLD_PARAMS_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, (char *)((unsigned int *)rq->ifr_data + 1), sizeof(cmd))) { + return -EFAULT; + } + + if( wmi_set_lq_threshold_params(ar->arWmi, &cmd) != 0 ) { + ret = -EIO; + } + + return ret; +} + + +static int +ar6000_ioctl_set_probedSsid(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_PROBED_SSID_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_probedSsid_cmd(ar->arWmi, cmd.entryIndex, cmd.flag, cmd.ssidLength, + cmd.ssid) != 0) + { + ret = -EIO; + } + + return ret; +} + +static int +ar6000_ioctl_set_badAp(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_ADD_BAD_AP_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if (cmd.badApIndex > WMI_MAX_BAD_AP_INDEX) { + return -EIO; + } + + if (memcmp(cmd.bssid, null_mac, AR6000_ETH_ADDR_LEN) == 0) { + /* + * This is a delete badAP. + */ + if (wmi_deleteBadAp_cmd(ar->arWmi, cmd.badApIndex) != 0) { + ret = -EIO; + } + } else { + if (wmi_addBadAp_cmd(ar->arWmi, cmd.badApIndex, cmd.bssid) != 0) { + ret = -EIO; + } + } + + return ret; +} + +static int +ar6000_ioctl_create_qos(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_CREATE_PSTREAM_CMD cmd; + int ret; + + if (ar->arWmiReady == false) { + return -EIO; + } + + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + ret = wmi_verify_tspec_params(&cmd, tspecCompliance); + if (ret == 0) + ret = wmi_create_pstream_cmd(ar->arWmi, &cmd); + + switch (ret) { + case 0: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + +static int +ar6000_ioctl_delete_qos(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_DELETE_PSTREAM_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + ret = wmi_delete_pstream_cmd(ar->arWmi, cmd.trafficClass, cmd.tsid); + + switch (ret) { + case 0: + return 0; + case A_EBUSY : + return -EBUSY; + case A_NO_MEMORY: + return -ENOMEM; + case A_EINVAL: + default: + return -EFAULT; + } +} + +static int +ar6000_ioctl_get_qos_queue(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + struct ar6000_queuereq qreq; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if( copy_from_user(&qreq, rq->ifr_data, + sizeof(struct ar6000_queuereq))) + return -EFAULT; + + qreq.activeTsids = wmi_get_mapped_qos_queue(ar->arWmi, qreq.trafficClass); + + if (copy_to_user(rq->ifr_data, &qreq, + sizeof(struct ar6000_queuereq))) + { + ret = -EFAULT; + } + + return ret; +} + +#ifdef CONFIG_HOST_TCMD_SUPPORT +static int +ar6000_ioctl_tcmd_get_rx_report(struct net_device *dev, + struct ifreq *rq, u8 *data, u32 len) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + u32 buf[4+TCMD_MAX_RATES]; + int ret = 0; + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + return -EBUSY; + } + + ar->tcmdRxReport = 0; + if (wmi_test_cmd(ar->arWmi, data, len) != 0) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arEvent, ar->tcmdRxReport != 0, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + buf[0] = ar->tcmdRxTotalPkt; + buf[1] = ar->tcmdRxRssi; + buf[2] = ar->tcmdRxcrcErrPkt; + buf[3] = ar->tcmdRxsecErrPkt; + memcpy(((u8 *)buf)+(4*sizeof(u32)), ar->tcmdRateCnt, sizeof(ar->tcmdRateCnt)); + memcpy(((u8 *)buf)+(4*sizeof(u32))+(TCMD_MAX_RATES *sizeof(u16)), ar->tcmdRateCntShortGuard, sizeof(ar->tcmdRateCntShortGuard)); + + if (!ret && copy_to_user(rq->ifr_data, buf, sizeof(buf))) { + ret = -EFAULT; + } + + up(&ar->arSem); + + return ret; +} + +void +ar6000_tcmd_rx_report_event(void *devt, u8 *results, int len) +{ + struct ar6_softc *ar = (struct ar6_softc *)devt; + TCMD_CONT_RX * rx_rep = (TCMD_CONT_RX *)results; + + if (enablerssicompensation) { + rx_rep->u.report.rssiInDBm = rssi_compensation_calc_tcmd(tcmdRxFreq, rx_rep->u.report.rssiInDBm,rx_rep->u.report.totalPkt); + } + + + ar->tcmdRxTotalPkt = rx_rep->u.report.totalPkt; + ar->tcmdRxRssi = rx_rep->u.report.rssiInDBm; + ar->tcmdRxcrcErrPkt = rx_rep->u.report.crcErrPkt; + ar->tcmdRxsecErrPkt = rx_rep->u.report.secErrPkt; + ar->tcmdRxReport = 1; + A_MEMZERO(ar->tcmdRateCnt, sizeof(ar->tcmdRateCnt)); + A_MEMZERO(ar->tcmdRateCntShortGuard, sizeof(ar->tcmdRateCntShortGuard)); + memcpy(ar->tcmdRateCnt, rx_rep->u.report.rateCnt, sizeof(ar->tcmdRateCnt)); + memcpy(ar->tcmdRateCntShortGuard, rx_rep->u.report.rateCntShortGuard, sizeof(ar->tcmdRateCntShortGuard)); + + wake_up(&arEvent); +} +#endif /* CONFIG_HOST_TCMD_SUPPORT*/ + +static int +ar6000_ioctl_set_error_report_bitmask(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_TARGET_ERROR_REPORT_BITMASK cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + ret = wmi_set_error_report_bitmask(ar->arWmi, cmd.bitmask); + + return (ret==0 ? ret : -EINVAL); +} + +static int +ar6000_clear_target_stats(struct net_device *dev) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + TARGET_STATS *pStats = &ar->arTargetStats; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + AR6000_SPIN_LOCK(&ar->arLock, 0); + A_MEMZERO(pStats, sizeof(TARGET_STATS)); + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + return ret; +} + +static int +ar6000_ioctl_get_target_stats(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + TARGET_STATS_CMD cmd; + TARGET_STATS *pStats = &ar->arTargetStats; + int ret = 0; + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + if (ar->arWmiReady == false) { + return -EIO; + } + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + return -EBUSY; + } + + ar->statsUpdatePending = true; + + if(wmi_get_stats_cmd(ar->arWmi) != 0) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arEvent, ar->statsUpdatePending == false, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret && copy_to_user(rq->ifr_data, pStats, sizeof(*pStats))) { + ret = -EFAULT; + } + + if (cmd.clearStats == 1) { + ret = ar6000_clear_target_stats(dev); + } + + up(&ar->arSem); + + return ret; +} + +static int +ar6000_ioctl_get_ap_stats(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + u32 action; /* Allocating only the desired space on the frame. Declaring is as a WMI_AP_MODE_STAT variable results in exceeding the compiler imposed limit on the maximum frame size */ + WMI_AP_MODE_STAT *pStats = &ar->arAPStats; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + if (copy_from_user(&action, (char *)((unsigned int*)rq->ifr_data + 1), + sizeof(u32))) + { + return -EFAULT; + } + if (action == AP_CLEAR_STATS) { + u8 i; + AR6000_SPIN_LOCK(&ar->arLock, 0); + for(i = 0; i < AP_MAX_NUM_STA; i++) { + pStats->sta[i].tx_bytes = 0; + pStats->sta[i].tx_pkts = 0; + pStats->sta[i].tx_error = 0; + pStats->sta[i].tx_discard = 0; + pStats->sta[i].rx_bytes = 0; + pStats->sta[i].rx_pkts = 0; + pStats->sta[i].rx_error = 0; + pStats->sta[i].rx_discard = 0; + } + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + return ret; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + ar->statsUpdatePending = true; + + if(wmi_get_stats_cmd(ar->arWmi) != 0) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arEvent, ar->statsUpdatePending == false, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret && copy_to_user(rq->ifr_data, pStats, sizeof(*pStats))) { + ret = -EFAULT; + } + + up(&ar->arSem); + + return ret; +} + +static int +ar6000_ioctl_set_access_params(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_ACCESS_PARAMS_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_access_params_cmd(ar->arWmi, cmd.ac, cmd.txop, cmd.eCWmin, cmd.eCWmax, + cmd.aifsn) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return (ret); +} + +static int +ar6000_ioctl_set_disconnect_timeout(struct net_device *dev, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_DISC_TIMEOUT_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, rq->ifr_data, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_disctimeout_cmd(ar->arWmi, cmd.disconnectTimeout) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return (ret); +} + +static int +ar6000_xioctl_set_voice_pkt_size(struct net_device *dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_VOICE_PKT_SIZE_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_voice_pkt_size_cmd(ar->arWmi, cmd.voicePktSize) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + + return (ret); +} + +static int +ar6000_xioctl_set_max_sp_len(struct net_device *dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_MAX_SP_LEN_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_max_sp_len_cmd(ar->arWmi, cmd.maxSPLen) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return (ret); +} + + +static int +ar6000_xioctl_set_bt_status_cmd(struct net_device *dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_BT_STATUS_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_bt_status_cmd(ar->arWmi, cmd.streamType, cmd.status) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return (ret); +} + +static int +ar6000_xioctl_set_bt_params_cmd(struct net_device *dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_BT_PARAMS_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_bt_params_cmd(ar->arWmi, &cmd) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return (ret); +} + +static int +ar6000_xioctl_set_btcoex_fe_ant_cmd(struct net_device * dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_BTCOEX_FE_ANT_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_fe_ant_cmd(ar->arWmi, &cmd) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_colocated_bt_dev_cmd(struct net_device * dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_BTCOEX_COLOCATED_BT_DEV_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_colocated_bt_dev_cmd(ar->arWmi, &cmd) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_btinquiry_page_config_cmd(struct net_device * dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_btinquiry_page_config_cmd(ar->arWmi, &cmd) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_sco_config_cmd(struct net_device * dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_BTCOEX_SCO_CONFIG_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_sco_config_cmd(ar->arWmi, &cmd) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_a2dp_config_cmd(struct net_device * dev, + char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_BTCOEX_A2DP_CONFIG_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_a2dp_config_cmd(ar->arWmi, &cmd) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_aclcoex_config_cmd(struct net_device * dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_BTCOEX_ACLCOEX_CONFIG_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_aclcoex_config_cmd(ar->arWmi, &cmd) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar60000_xioctl_set_btcoex_debug_cmd(struct net_device * dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_BTCOEX_DEBUG_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_debug_cmd(ar->arWmi, &cmd) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + + return(ret); +} + +static int +ar6000_xioctl_set_btcoex_bt_operating_status_cmd(struct net_device * dev, char *userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_BTCOEX_BT_OPERATING_STATUS_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_btcoex_bt_operating_status_cmd(ar->arWmi, &cmd) == 0) + { + ret = 0; + } else { + ret = -EINVAL; + } + return(ret); +} + +static int +ar6000_xioctl_get_btcoex_config_cmd(struct net_device * dev, char *userdata, + struct ifreq *rq) +{ + + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + AR6000_BTCOEX_CONFIG btcoexConfig; + WMI_BTCOEX_CONFIG_EVENT *pbtcoexConfigEv = &ar->arBtcoexConfig; + + int ret = 0; + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + if (ar->arWmiReady == false) { + return -EIO; + } + if (copy_from_user(&btcoexConfig.configCmd, userdata, sizeof(AR6000_BTCOEX_CONFIG))) { + return -EFAULT; + } + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (wmi_get_btcoex_config_cmd(ar->arWmi, (WMI_GET_BTCOEX_CONFIG_CMD *)&btcoexConfig.configCmd) != 0) + { + up(&ar->arSem); + return -EIO; + } + + ar->statsUpdatePending = true; + + wait_event_interruptible_timeout(arEvent, ar->statsUpdatePending == false, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret && copy_to_user(btcoexConfig.configEvent, pbtcoexConfigEv, sizeof(WMI_BTCOEX_CONFIG_EVENT))) { + ret = -EFAULT; + } + up(&ar->arSem); + return ret; +} + +static int +ar6000_xioctl_get_btcoex_stats_cmd(struct net_device * dev, char *userdata, struct ifreq *rq) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + AR6000_BTCOEX_STATS btcoexStats; + WMI_BTCOEX_STATS_EVENT *pbtcoexStats = &ar->arBtcoexStats; + int ret = 0; + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + if (ar->arWmiReady == false) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (copy_from_user(&btcoexStats.statsEvent, userdata, sizeof(AR6000_BTCOEX_CONFIG))) { + return -EFAULT; + } + + if (wmi_get_btcoex_stats_cmd(ar->arWmi) != 0) + { + up(&ar->arSem); + return -EIO; + } + + ar->statsUpdatePending = true; + + wait_event_interruptible_timeout(arEvent, ar->statsUpdatePending == false, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret && copy_to_user(btcoexStats.statsEvent, pbtcoexStats, sizeof(WMI_BTCOEX_STATS_EVENT))) { + ret = -EFAULT; + } + + + up(&ar->arSem); + + return(ret); +} + +static int +ar6000_xioctl_set_excess_tx_retry_thres_cmd(struct net_device * dev, char * userdata) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_SET_EXCESS_TX_RETRY_THRES_CMD cmd; + int ret = 0; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + return -EFAULT; + } + + if (wmi_set_excess_tx_retry_thres_cmd(ar->arWmi, &cmd) != 0) + { + ret = -EINVAL; + } + return(ret); +} + +#ifdef CONFIG_HOST_GPIO_SUPPORT +struct ar6000_gpio_intr_wait_cmd_s gpio_intr_results; +/* gpio_reg_results and gpio_data_available are protected by arSem */ +static struct ar6000_gpio_register_cmd_s gpio_reg_results; +static bool gpio_data_available; /* Requested GPIO data available */ +static bool gpio_intr_available; /* GPIO interrupt info available */ +static bool gpio_ack_received; /* GPIO ack was received */ + +/* Host-side initialization for General Purpose I/O support */ +void ar6000_gpio_init(void) +{ + gpio_intr_available = false; + gpio_data_available = false; + gpio_ack_received = false; +} + +/* + * Called when a GPIO interrupt is received from the Target. + * intr_values shows which GPIO pins have interrupted. + * input_values shows a recent value of GPIO pins. + */ +void +ar6000_gpio_intr_rx(u32 intr_mask, u32 input_values) +{ + gpio_intr_results.intr_mask = intr_mask; + gpio_intr_results.input_values = input_values; + *((volatile bool *)&gpio_intr_available) = true; + wake_up(&arEvent); +} + +/* + * This is called when a response is received from the Target + * for a previous or ar6000_gpio_input_get or ar6000_gpio_register_get + * call. + */ +void +ar6000_gpio_data_rx(u32 reg_id, u32 value) +{ + gpio_reg_results.gpioreg_id = reg_id; + gpio_reg_results.value = value; + *((volatile bool *)&gpio_data_available) = true; + wake_up(&arEvent); +} + +/* + * This is called when an acknowledgement is received from the Target + * for a previous or ar6000_gpio_output_set or ar6000_gpio_register_set + * call. + */ +void +ar6000_gpio_ack_rx(void) +{ + gpio_ack_received = true; + wake_up(&arEvent); +} + +int +ar6000_gpio_output_set(struct net_device *dev, + u32 set_mask, + u32 clear_mask, + u32 enable_mask, + u32 disable_mask) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + gpio_ack_received = false; + return wmi_gpio_output_set(ar->arWmi, + set_mask, clear_mask, enable_mask, disable_mask); +} + +static int +ar6000_gpio_input_get(struct net_device *dev) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + *((volatile bool *)&gpio_data_available) = false; + return wmi_gpio_input_get(ar->arWmi); +} + +static int +ar6000_gpio_register_set(struct net_device *dev, + u32 gpioreg_id, + u32 value) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + gpio_ack_received = false; + return wmi_gpio_register_set(ar->arWmi, gpioreg_id, value); +} + +static int +ar6000_gpio_register_get(struct net_device *dev, + u32 gpioreg_id) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + *((volatile bool *)&gpio_data_available) = false; + return wmi_gpio_register_get(ar->arWmi, gpioreg_id); +} + +static int +ar6000_gpio_intr_ack(struct net_device *dev, + u32 ack_mask) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + gpio_intr_available = false; + return wmi_gpio_intr_ack(ar->arWmi, ack_mask); +} +#endif /* CONFIG_HOST_GPIO_SUPPORT */ + +#if defined(CONFIG_TARGET_PROFILE_SUPPORT) +static struct prof_count_s prof_count_results; +static bool prof_count_available; /* Requested GPIO data available */ + +static int +prof_count_get(struct net_device *dev) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + *((volatile bool *)&prof_count_available) = false; + return wmi_prof_count_get_cmd(ar->arWmi); +} + +/* + * This is called when a response is received from the Target + * for a previous prof_count_get call. + */ +void +prof_count_rx(u32 addr, u32 count) +{ + prof_count_results.addr = addr; + prof_count_results.count = count; + *((volatile bool *)&prof_count_available) = true; + wake_up(&arEvent); +} +#endif /* CONFIG_TARGET_PROFILE_SUPPORT */ + + +static int +ar6000_create_acl_data_osbuf(struct net_device *dev, u8 *userdata, void **p_osbuf) +{ + void *osbuf = NULL; + u8 tmp_space[8]; + HCI_ACL_DATA_PKT *acl; + u8 hdr_size, *datap=NULL; + int ret = 0; + + /* ACL is in data path. There is a need to create pool + * mechanism for allocating and freeing NETBUFs - ToDo later. + */ + + *p_osbuf = NULL; + acl = (HCI_ACL_DATA_PKT *)tmp_space; + hdr_size = sizeof(acl->hdl_and_flags) + sizeof(acl->data_len); + + do { + if (a_copy_from_user(acl, userdata, hdr_size)) { + ret = A_EFAULT; + break; + } + + osbuf = A_NETBUF_ALLOC(hdr_size + acl->data_len); + if (osbuf == NULL) { + ret = A_NO_MEMORY; + break; + } + A_NETBUF_PUT(osbuf, hdr_size + acl->data_len); + datap = (u8 *)A_NETBUF_DATA(osbuf); + + /* Real copy to osbuf */ + acl = (HCI_ACL_DATA_PKT *)(datap); + memcpy(acl, tmp_space, hdr_size); + if (a_copy_from_user(acl->data, userdata + hdr_size, acl->data_len)) { + ret = A_EFAULT; + break; + } + } while(false); + + if (ret == 0) { + *p_osbuf = osbuf; + } else { + A_NETBUF_FREE(osbuf); + } + return ret; +} + + + +int +ar6000_ioctl_ap_setparam(struct ar6_softc *ar, int param, int value) +{ + int ret=0; + + switch(param) { + case IEEE80211_PARAM_WPA: + switch (value) { + case WPA_MODE_WPA1: + ar->arAuthMode = WPA_AUTH; + break; + case WPA_MODE_WPA2: + ar->arAuthMode = WPA2_AUTH; + break; + case WPA_MODE_AUTO: + ar->arAuthMode = WPA_AUTH | WPA2_AUTH; + break; + case WPA_MODE_NONE: + ar->arAuthMode = NONE_AUTH; + break; + } + break; + case IEEE80211_PARAM_AUTHMODE: + if(value == IEEE80211_AUTH_WPA_PSK) { + if (WPA_AUTH == ar->arAuthMode) { + ar->arAuthMode = WPA_PSK_AUTH; + } else if (WPA2_AUTH == ar->arAuthMode) { + ar->arAuthMode = WPA2_PSK_AUTH; + } else if ((WPA_AUTH | WPA2_AUTH) == ar->arAuthMode) { + ar->arAuthMode = WPA_PSK_AUTH | WPA2_PSK_AUTH; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Error - Setting PSK "\ + "mode when WPA param was set to %d\n", + ar->arAuthMode)); + ret = -EIO; + } + } + break; + case IEEE80211_PARAM_UCASTCIPHER: + ar->arPairwiseCrypto = 0; + if(value & (1<arPairwiseCrypto |= AES_CRYPT; + } + if(value & (1<arPairwiseCrypto |= TKIP_CRYPT; + } + if(!ar->arPairwiseCrypto) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR, + ("Error - Invalid cipher in WPA \n")); + ret = -EIO; + } + break; + case IEEE80211_PARAM_PRIVACY: + if(value == 0) { + ar->arDot11AuthMode = OPEN_AUTH; + ar->arAuthMode = NONE_AUTH; + ar->arPairwiseCrypto = NONE_CRYPT; + ar->arPairwiseCryptoLen = 0; + ar->arGroupCrypto = NONE_CRYPT; + ar->arGroupCryptoLen = 0; + } + break; +#ifdef WAPI_ENABLE + case IEEE80211_PARAM_WAPI: + A_PRINTF("WAPI Policy: %d\n", value); + ar->arDot11AuthMode = OPEN_AUTH; + ar->arAuthMode = NONE_AUTH; + if(value & 0x1) { + ar->arPairwiseCrypto = WAPI_CRYPT; + ar->arGroupCrypto = WAPI_CRYPT; + } else { + ar->arPairwiseCrypto = NONE_CRYPT; + ar->arGroupCrypto = NONE_CRYPT; + } + break; +#endif + } + return ret; +} + +int +ar6000_ioctl_setparam(struct ar6_softc *ar, int param, int value) +{ + bool profChanged = false; + int ret=0; + + if(ar->arNextMode == AP_NETWORK) { + ar->ap_profile_flag = 1; /* There is a change in profile */ + switch (param) { + case IEEE80211_PARAM_WPA: + case IEEE80211_PARAM_AUTHMODE: + case IEEE80211_PARAM_UCASTCIPHER: + case IEEE80211_PARAM_PRIVACY: + case IEEE80211_PARAM_WAPI: + ret = ar6000_ioctl_ap_setparam(ar, param, value); + return ret; + } + } + + switch (param) { + case IEEE80211_PARAM_WPA: + switch (value) { + case WPA_MODE_WPA1: + ar->arAuthMode = WPA_AUTH; + profChanged = true; + break; + case WPA_MODE_WPA2: + ar->arAuthMode = WPA2_AUTH; + profChanged = true; + break; + case WPA_MODE_NONE: + ar->arAuthMode = NONE_AUTH; + profChanged = true; + break; + } + break; + case IEEE80211_PARAM_AUTHMODE: + switch(value) { + case IEEE80211_AUTH_WPA_PSK: + if (WPA_AUTH == ar->arAuthMode) { + ar->arAuthMode = WPA_PSK_AUTH; + profChanged = true; + } else if (WPA2_AUTH == ar->arAuthMode) { + ar->arAuthMode = WPA2_PSK_AUTH; + profChanged = true; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("Error - Setting PSK "\ + "mode when WPA param was set to %d\n", + ar->arAuthMode)); + ret = -EIO; + } + break; + case IEEE80211_AUTH_WPA_CCKM: + if (WPA2_AUTH == ar->arAuthMode) { + ar->arAuthMode = WPA2_AUTH_CCKM; + } else { + ar->arAuthMode = WPA_AUTH_CCKM; + } + break; + default: + break; + } + break; + case IEEE80211_PARAM_UCASTCIPHER: + switch (value) { + case IEEE80211_CIPHER_AES_CCM: + ar->arPairwiseCrypto = AES_CRYPT; + profChanged = true; + break; + case IEEE80211_CIPHER_TKIP: + ar->arPairwiseCrypto = TKIP_CRYPT; + profChanged = true; + break; + case IEEE80211_CIPHER_WEP: + ar->arPairwiseCrypto = WEP_CRYPT; + profChanged = true; + break; + case IEEE80211_CIPHER_NONE: + ar->arPairwiseCrypto = NONE_CRYPT; + profChanged = true; + break; + } + break; + case IEEE80211_PARAM_UCASTKEYLEN: + if (!IEEE80211_IS_VALID_WEP_CIPHER_LEN(value)) { + ret = -EIO; + } else { + ar->arPairwiseCryptoLen = value; + } + break; + case IEEE80211_PARAM_MCASTCIPHER: + switch (value) { + case IEEE80211_CIPHER_AES_CCM: + ar->arGroupCrypto = AES_CRYPT; + profChanged = true; + break; + case IEEE80211_CIPHER_TKIP: + ar->arGroupCrypto = TKIP_CRYPT; + profChanged = true; + break; + case IEEE80211_CIPHER_WEP: + ar->arGroupCrypto = WEP_CRYPT; + profChanged = true; + break; + case IEEE80211_CIPHER_NONE: + ar->arGroupCrypto = NONE_CRYPT; + profChanged = true; + break; + } + break; + case IEEE80211_PARAM_MCASTKEYLEN: + if (!IEEE80211_IS_VALID_WEP_CIPHER_LEN(value)) { + ret = -EIO; + } else { + ar->arGroupCryptoLen = value; + } + break; + case IEEE80211_PARAM_COUNTERMEASURES: + if (ar->arWmiReady == false) { + return -EIO; + } + wmi_set_tkip_countermeasures_cmd(ar->arWmi, value); + break; + default: + break; + } + if ((ar->arNextMode != AP_NETWORK) && (profChanged == true)) { + /* + * profile has changed. Erase ssid to signal change + */ + A_MEMZERO(ar->arSsid, sizeof(ar->arSsid)); + } + + return ret; +} + +int +ar6000_ioctl_setkey(struct ar6_softc *ar, struct ieee80211req_key *ik) +{ + KEY_USAGE keyUsage; + int status; + CRYPTO_TYPE keyType = NONE_CRYPT; + +#ifdef USER_KEYS + ar->user_saved_keys.keyOk = false; +#endif + if ( (0 == memcmp(ik->ik_macaddr, null_mac, IEEE80211_ADDR_LEN)) || + (0 == memcmp(ik->ik_macaddr, bcast_mac, IEEE80211_ADDR_LEN)) ) { + keyUsage = GROUP_USAGE; + if(ar->arNextMode == AP_NETWORK) { + memcpy(&ar->ap_mode_bkey, ik, + sizeof(struct ieee80211req_key)); +#ifdef WAPI_ENABLE + if(ar->arPairwiseCrypto == WAPI_CRYPT) { + return ap_set_wapi_key(ar, ik); + } +#endif + } +#ifdef USER_KEYS + memcpy(&ar->user_saved_keys.bcast_ik, ik, + sizeof(struct ieee80211req_key)); +#endif + } else { + keyUsage = PAIRWISE_USAGE; +#ifdef USER_KEYS + memcpy(&ar->user_saved_keys.ucast_ik, ik, + sizeof(struct ieee80211req_key)); +#endif +#ifdef WAPI_ENABLE + if(ar->arNextMode == AP_NETWORK) { + if(ar->arPairwiseCrypto == WAPI_CRYPT) { + return ap_set_wapi_key(ar, ik); + } + } +#endif + } + + switch (ik->ik_type) { + case IEEE80211_CIPHER_WEP: + keyType = WEP_CRYPT; + break; + case IEEE80211_CIPHER_TKIP: + keyType = TKIP_CRYPT; + break; + case IEEE80211_CIPHER_AES_CCM: + keyType = AES_CRYPT; + break; + default: + break; + } +#ifdef USER_KEYS + ar->user_saved_keys.keyType = keyType; +#endif + if (IEEE80211_CIPHER_CCKM_KRK != ik->ik_type) { + if (NONE_CRYPT == keyType) { + return -EIO; + } + + if ((WEP_CRYPT == keyType)&&(!ar->arConnected)) { + int index = ik->ik_keyix; + + if (!IEEE80211_IS_VALID_WEP_CIPHER_LEN(ik->ik_keylen)) { + return -EIO; + } + + A_MEMZERO(ar->arWepKeyList[index].arKey, + sizeof(ar->arWepKeyList[index].arKey)); + memcpy(ar->arWepKeyList[index].arKey, ik->ik_keydata, ik->ik_keylen); + ar->arWepKeyList[index].arKeyLen = ik->ik_keylen; + + if(ik->ik_flags & IEEE80211_KEY_DEFAULT){ + ar->arDefTxKeyIndex = index; + } + + return 0; + } + + if (((WPA_PSK_AUTH == ar->arAuthMode) || (WPA2_PSK_AUTH == ar->arAuthMode)) && + (GROUP_USAGE & keyUsage)) + { + A_UNTIMEOUT(&ar->disconnect_timer); + } + + status = wmi_addKey_cmd(ar->arWmi, ik->ik_keyix, keyType, keyUsage, + ik->ik_keylen, (u8 *)&ik->ik_keyrsc, + ik->ik_keydata, KEY_OP_INIT_VAL, ik->ik_macaddr, + SYNC_BOTH_WMIFLAG); + + if (status) { + return -EIO; + } + } else { + status = wmi_add_krk_cmd(ar->arWmi, ik->ik_keydata); + } + +#ifdef USER_KEYS + ar->user_saved_keys.keyOk = true; +#endif + + return 0; +} + +int ar6000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + struct hif_device *hifDevice = ar->arHifDevice; + int ret = 0, param; + unsigned int address = 0; + unsigned int length = 0; + unsigned char *buffer; + char *userdata; + u32 connectCtrlFlags; + + + WMI_SET_AKMP_PARAMS_CMD akmpParams; + WMI_SET_PMKID_LIST_CMD pmkidInfo; + + WMI_SET_HT_CAP_CMD htCap; + WMI_SET_HT_OP_CMD htOp; + + /* + * ioctl operations may have to wait for the Target, so we cannot hold rtnl. + * Prevent the device from disappearing under us and release the lock during + * the ioctl operation. + */ + dev_hold(dev); + rtnl_unlock(); + + if (cmd == AR6000_IOCTL_EXTENDED) { + /* + * This allows for many more wireless ioctls than would otherwise + * be available. Applications embed the actual ioctl command in + * the first word of the parameter block, and use the command + * AR6000_IOCTL_EXTENDED_CMD on the ioctl call. + */ + if (get_user(cmd, (int *)rq->ifr_data)) { + ret = -EFAULT; + goto ioctl_done; + } + userdata = (char *)(((unsigned int *)rq->ifr_data)+1); + if(is_xioctl_allowed(ar->arNextMode, cmd) != 0) { + A_PRINTF("xioctl: cmd=%d not allowed in this mode\n",cmd); + ret = -EOPNOTSUPP; + goto ioctl_done; + } + } else { + int ret = is_iwioctl_allowed(ar->arNextMode, cmd); + if(ret == A_ENOTSUP) { + A_PRINTF("iwioctl: cmd=0x%x not allowed in this mode\n", cmd); + ret = -EOPNOTSUPP; + goto ioctl_done; + } else if (ret == A_ERROR) { + /* It is not our ioctl (out of range ioctl) */ + ret = -EOPNOTSUPP; + goto ioctl_done; + } + userdata = (char *)rq->ifr_data; + } + + if ((ar->arWlanState == WLAN_DISABLED) && + ((cmd != AR6000_XIOCTRL_WMI_SET_WLAN_STATE) && + (cmd != AR6000_XIOCTL_GET_WLAN_SLEEP_STATE) && + (cmd != AR6000_XIOCTL_DIAG_READ) && + (cmd != AR6000_XIOCTL_DIAG_WRITE) && + (cmd != AR6000_XIOCTL_SET_BT_HW_POWER_STATE) && + (cmd != AR6000_XIOCTL_GET_BT_HW_POWER_STATE) && + (cmd != AR6000_XIOCTL_ADD_AP_INTERFACE) && + (cmd != AR6000_XIOCTL_REMOVE_AP_INTERFACE) && + (cmd != AR6000_IOCTL_WMI_GETREV))) + { + ret = -EIO; + goto ioctl_done; + } + + ret = 0; + switch(cmd) + { + case IEEE80211_IOCTL_SETPARAM: + { + int param, value; + int *ptr = (int *)rq->ifr_ifru.ifru_newname; + if (ar->arWmiReady == false) { + ret = -EIO; + } else { + param = *ptr++; + value = *ptr; + ret = ar6000_ioctl_setparam(ar,param,value); + } + break; + } + case IEEE80211_IOCTL_SETKEY: + { + struct ieee80211req_key keydata; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&keydata, userdata, + sizeof(struct ieee80211req_key))) { + ret = -EFAULT; + } else { + ar6000_ioctl_setkey(ar, &keydata); + } + break; + } + case IEEE80211_IOCTL_DELKEY: + case IEEE80211_IOCTL_SETOPTIE: + { + //ret = -EIO; + break; + } + case IEEE80211_IOCTL_SETMLME: + { + struct ieee80211req_mlme mlme; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&mlme, userdata, + sizeof(struct ieee80211req_mlme))) { + ret = -EFAULT; + } else { + switch (mlme.im_op) { + case IEEE80211_MLME_AUTHORIZE: + A_PRINTF("setmlme AUTHORIZE %02X:%02X\n", + mlme.im_macaddr[4], mlme.im_macaddr[5]); + break; + case IEEE80211_MLME_UNAUTHORIZE: + A_PRINTF("setmlme UNAUTHORIZE %02X:%02X\n", + mlme.im_macaddr[4], mlme.im_macaddr[5]); + break; + case IEEE80211_MLME_DEAUTH: + A_PRINTF("setmlme DEAUTH %02X:%02X\n", + mlme.im_macaddr[4], mlme.im_macaddr[5]); + //remove_sta(ar, mlme.im_macaddr); + break; + case IEEE80211_MLME_DISASSOC: + A_PRINTF("setmlme DISASSOC %02X:%02X\n", + mlme.im_macaddr[4], mlme.im_macaddr[5]); + //remove_sta(ar, mlme.im_macaddr); + break; + default: + ret = 0; + goto ioctl_done; + } + + wmi_ap_set_mlme(ar->arWmi, mlme.im_op, mlme.im_macaddr, + mlme.im_reason); + } + break; + } + case IEEE80211_IOCTL_ADDPMKID: + { + struct ieee80211req_addpmkid req; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&req, userdata, sizeof(struct ieee80211req_addpmkid))) { + ret = -EFAULT; + } else { + int status; + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("Add pmkid for %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x en=%d\n", + req.pi_bssid[0], req.pi_bssid[1], req.pi_bssid[2], + req.pi_bssid[3], req.pi_bssid[4], req.pi_bssid[5], + req.pi_enable)); + + status = wmi_setPmkid_cmd(ar->arWmi, req.pi_bssid, req.pi_pmkid, + req.pi_enable); + + if (status) { + ret = -EIO; + goto ioctl_done; + } + } + break; + } +#ifdef CONFIG_HOST_TCMD_SUPPORT + case AR6000_XIOCTL_TCMD_CONT_TX: + { + TCMD_CONT_TX txCmd; + + if ((ar->tcmdPm == TCMD_PM_SLEEP) || + (ar->tcmdPm == TCMD_PM_DEEPSLEEP)) + { + A_PRINTF("Can NOT send tx tcmd when target is asleep! \n"); + ret = -EFAULT; + goto ioctl_done; + } + + if(copy_from_user(&txCmd, userdata, sizeof(TCMD_CONT_TX))) { + ret = -EFAULT; + goto ioctl_done; + } else { + wmi_test_cmd(ar->arWmi,(u8 *)&txCmd, sizeof(TCMD_CONT_TX)); + } + } + break; + case AR6000_XIOCTL_TCMD_CONT_RX: + { + TCMD_CONT_RX rxCmd; + + if ((ar->tcmdPm == TCMD_PM_SLEEP) || + (ar->tcmdPm == TCMD_PM_DEEPSLEEP)) + { + A_PRINTF("Can NOT send rx tcmd when target is asleep! \n"); + ret = -EFAULT; + goto ioctl_done; + } + if(copy_from_user(&rxCmd, userdata, sizeof(TCMD_CONT_RX))) { + ret = -EFAULT; + goto ioctl_done; + } + + switch(rxCmd.act) + { + case TCMD_CONT_RX_PROMIS: + case TCMD_CONT_RX_FILTER: + case TCMD_CONT_RX_SETMAC: + case TCMD_CONT_RX_SET_ANT_SWITCH_TABLE: + wmi_test_cmd(ar->arWmi,(u8 *)&rxCmd, + sizeof(TCMD_CONT_RX)); + tcmdRxFreq = rxCmd.u.para.freq; + break; + case TCMD_CONT_RX_REPORT: + ar6000_ioctl_tcmd_get_rx_report(dev, rq, + (u8 *)&rxCmd, sizeof(TCMD_CONT_RX)); + break; + default: + A_PRINTF("Unknown Cont Rx mode: %d\n",rxCmd.act); + ret = -EINVAL; + goto ioctl_done; + } + } + break; + case AR6000_XIOCTL_TCMD_PM: + { + TCMD_PM pmCmd; + + if(copy_from_user(&pmCmd, userdata, sizeof(TCMD_PM))) { + ret = -EFAULT; + goto ioctl_done; + } + ar->tcmdPm = pmCmd.mode; + wmi_test_cmd(ar->arWmi, (u8 *)&pmCmd, sizeof(TCMD_PM)); + } + break; +#endif /* CONFIG_HOST_TCMD_SUPPORT */ + + case AR6000_XIOCTL_BMI_DONE: + if(bmienable) + { + rtnl_lock(); /* ar6000_init expects to be called holding rtnl lock */ + ret = ar6000_init(dev); + rtnl_unlock(); + } + else + { + ret = BMIDone(hifDevice); + } + break; + + case AR6000_XIOCTL_BMI_READ_MEMORY: + if (get_user(address, (unsigned int *)userdata) || + get_user(length, (unsigned int *)userdata + 1)) { + ret = -EFAULT; + break; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Read Memory (address: 0x%x, length: %d)\n", + address, length)); + if ((buffer = (unsigned char *)A_MALLOC(length)) != NULL) { + A_MEMZERO(buffer, length); + ret = BMIReadMemory(hifDevice, address, buffer, length); + if (copy_to_user(rq->ifr_data, buffer, length)) { + ret = -EFAULT; + } + A_FREE(buffer); + } else { + ret = -ENOMEM; + } + break; + + case AR6000_XIOCTL_BMI_WRITE_MEMORY: + if (get_user(address, (unsigned int *)userdata) || + get_user(length, (unsigned int *)userdata + 1)) { + ret = -EFAULT; + break; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Write Memory (address: 0x%x, length: %d)\n", + address, length)); + if ((buffer = (unsigned char *)A_MALLOC(length)) != NULL) { + A_MEMZERO(buffer, length); + if (copy_from_user(buffer, &userdata[sizeof(address) + + sizeof(length)], length)) + { + ret = -EFAULT; + } else { + ret = BMIWriteMemory(hifDevice, address, buffer, length); + } + A_FREE(buffer); + } else { + ret = -ENOMEM; + } + break; + + case AR6000_XIOCTL_BMI_TEST: + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("No longer supported\n")); + ret = -EOPNOTSUPP; + break; + + case AR6000_XIOCTL_BMI_EXECUTE: + if (get_user(address, (unsigned int *)userdata) || + get_user(param, (unsigned int *)userdata + 1)) { + ret = -EFAULT; + break; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Execute (address: 0x%x, param: %d)\n", + address, param)); + ret = BMIExecute(hifDevice, address, (u32 *)¶m); + /* return value */ + if (put_user(param, (unsigned int *)rq->ifr_data)) { + ret = -EFAULT; + break; + } + break; + + case AR6000_XIOCTL_BMI_SET_APP_START: + if (get_user(address, (unsigned int *)userdata)) { + ret = -EFAULT; + break; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Set App Start (address: 0x%x)\n", address)); + ret = BMISetAppStart(hifDevice, address); + break; + + case AR6000_XIOCTL_BMI_READ_SOC_REGISTER: + if (get_user(address, (unsigned int *)userdata)) { + ret = -EFAULT; + break; + } + ret = BMIReadSOCRegister(hifDevice, address, (u32 *)¶m); + /* return value */ + if (put_user(param, (unsigned int *)rq->ifr_data)) { + ret = -EFAULT; + break; + } + break; + + case AR6000_XIOCTL_BMI_WRITE_SOC_REGISTER: + if (get_user(address, (unsigned int *)userdata) || + get_user(param, (unsigned int *)userdata + 1)) { + ret = -EFAULT; + break; + } + ret = BMIWriteSOCRegister(hifDevice, address, param); + break; + +#ifdef HTC_RAW_INTERFACE + case AR6000_XIOCTL_HTC_RAW_OPEN: + ret = 0; + if (!arRawIfEnabled(ar)) { + /* make sure block size is set in case the target was reset since last + * BMI phase (i.e. flashup downloads) */ + ret = ar6000_set_htc_params(ar->arHifDevice, + ar->arTargetType, + 0, /* use default yield */ + 0 /* use default number of HTC ctrl buffers */ + ); + if (ret) { + break; + } + /* Terminate the BMI phase */ + ret = BMIDone(hifDevice); + if (ret == 0) { + ret = ar6000_htc_raw_open(ar); + } + } + break; + + case AR6000_XIOCTL_HTC_RAW_CLOSE: + if (arRawIfEnabled(ar)) { + ret = ar6000_htc_raw_close(ar); + arRawIfEnabled(ar) = false; + } else { + ret = A_ERROR; + } + break; + + case AR6000_XIOCTL_HTC_RAW_READ: + if (arRawIfEnabled(ar)) { + unsigned int streamID; + if (get_user(streamID, (unsigned int *)userdata) || + get_user(length, (unsigned int *)userdata + 1)) { + ret = -EFAULT; + break; + } + buffer = (unsigned char*)rq->ifr_data + sizeof(length); + ret = ar6000_htc_raw_read(ar, (HTC_RAW_STREAM_ID)streamID, + (char*)buffer, length); + if (put_user(ret, (unsigned int *)rq->ifr_data)) { + ret = -EFAULT; + break; + } + } else { + ret = A_ERROR; + } + break; + + case AR6000_XIOCTL_HTC_RAW_WRITE: + if (arRawIfEnabled(ar)) { + unsigned int streamID; + if (get_user(streamID, (unsigned int *)userdata) || + get_user(length, (unsigned int *)userdata + 1)) { + ret = -EFAULT; + break; + } + buffer = (unsigned char*)userdata + sizeof(streamID) + sizeof(length); + ret = ar6000_htc_raw_write(ar, (HTC_RAW_STREAM_ID)streamID, + (char*)buffer, length); + if (put_user(ret, (unsigned int *)rq->ifr_data)) { + ret = -EFAULT; + break; + } + } else { + ret = A_ERROR; + } + break; +#endif /* HTC_RAW_INTERFACE */ + + case AR6000_XIOCTL_BMI_LZ_STREAM_START: + if (get_user(address, (unsigned int *)userdata)) { + ret = -EFAULT; + break; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Start Compressed Stream (address: 0x%x)\n", address)); + ret = BMILZStreamStart(hifDevice, address); + break; + + case AR6000_XIOCTL_BMI_LZ_DATA: + if (get_user(length, (unsigned int *)userdata)) { + ret = -EFAULT; + break; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Send Compressed Data (length: %d)\n", length)); + if ((buffer = (unsigned char *)A_MALLOC(length)) != NULL) { + A_MEMZERO(buffer, length); + if (copy_from_user(buffer, &userdata[sizeof(length)], length)) + { + ret = -EFAULT; + } else { + ret = BMILZData(hifDevice, buffer, length); + } + A_FREE(buffer); + } else { + ret = -ENOMEM; + } + break; + +#if defined(CONFIG_TARGET_PROFILE_SUPPORT) + /* + * Optional support for Target-side profiling. + * Not needed in production. + */ + + /* Configure Target-side profiling */ + case AR6000_XIOCTL_PROF_CFG: + { + u32 period; + u32 nbins; + if (get_user(period, (unsigned int *)userdata) || + get_user(nbins, (unsigned int *)userdata + 1)) { + ret = -EFAULT; + break; + } + + if (wmi_prof_cfg_cmd(ar->arWmi, period, nbins) != 0) { + ret = -EIO; + } + + break; + } + + /* Start a profiling bucket/bin at the specified address */ + case AR6000_XIOCTL_PROF_ADDR_SET: + { + u32 addr; + if (get_user(addr, (unsigned int *)userdata)) { + ret = -EFAULT; + break; + } + + if (wmi_prof_addr_set_cmd(ar->arWmi, addr) != 0) { + ret = -EIO; + } + + break; + } + + /* START Target-side profiling */ + case AR6000_XIOCTL_PROF_START: + wmi_prof_start_cmd(ar->arWmi); + break; + + /* STOP Target-side profiling */ + case AR6000_XIOCTL_PROF_STOP: + wmi_prof_stop_cmd(ar->arWmi); + break; + case AR6000_XIOCTL_PROF_COUNT_GET: + { + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + prof_count_available = false; + ret = prof_count_get(dev); + if (ret != 0) { + up(&ar->arSem); + ret = -EIO; + goto ioctl_done; + } + + /* Wait for Target to respond. */ + wait_event_interruptible(arEvent, prof_count_available); + if (signal_pending(current)) { + ret = -EINTR; + } else { + if (copy_to_user(userdata, &prof_count_results, + sizeof(prof_count_results))) + { + ret = -EFAULT; + } + } + up(&ar->arSem); + break; + } +#endif /* CONFIG_TARGET_PROFILE_SUPPORT */ + + case AR6000_IOCTL_WMI_GETREV: + { + if (copy_to_user(rq->ifr_data, &ar->arVersion, + sizeof(ar->arVersion))) + { + ret = -EFAULT; + } + break; + } + case AR6000_IOCTL_WMI_SETPWR: + { + WMI_POWER_MODE_CMD pwrModeCmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&pwrModeCmd, userdata, + sizeof(pwrModeCmd))) + { + ret = -EFAULT; + } else { + if (wmi_powermode_cmd(ar->arWmi, pwrModeCmd.powerMode) + != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_IOCTL_WMI_SET_IBSS_PM_CAPS: + { + WMI_IBSS_PM_CAPS_CMD ibssPmCaps; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&ibssPmCaps, userdata, + sizeof(ibssPmCaps))) + { + ret = -EFAULT; + } else { + if (wmi_ibsspmcaps_cmd(ar->arWmi, ibssPmCaps.power_saving, ibssPmCaps.ttl, + ibssPmCaps.atim_windows, ibssPmCaps.timeout_value) != 0) + { + ret = -EIO; + } + AR6000_SPIN_LOCK(&ar->arLock, 0); + ar->arIbssPsEnable = ibssPmCaps.power_saving; + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + } + break; + } + case AR6000_XIOCTL_WMI_SET_AP_PS: + { + WMI_AP_PS_CMD apPsCmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&apPsCmd, userdata, + sizeof(apPsCmd))) + { + ret = -EFAULT; + } else { + if (wmi_apps_cmd(ar->arWmi, apPsCmd.psType, apPsCmd.idle_time, + apPsCmd.ps_period, apPsCmd.sleep_period) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_IOCTL_WMI_SET_PMPARAMS: + { + WMI_POWER_PARAMS_CMD pmParams; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&pmParams, userdata, + sizeof(pmParams))) + { + ret = -EFAULT; + } else { + if (wmi_pmparams_cmd(ar->arWmi, pmParams.idle_period, + pmParams.pspoll_number, + pmParams.dtim_policy, + pmParams.tx_wakeup_policy, + pmParams.num_tx_to_wakeup, +#if WLAN_CONFIG_IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN + IGNORE_POWER_SAVE_FAIL_EVENT_DURING_SCAN +#else + SEND_POWER_SAVE_FAIL_EVENT_ALWAYS +#endif + ) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_IOCTL_WMI_SETSCAN: + { + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&ar->scParams, userdata, + sizeof(ar->scParams))) + { + ret = -EFAULT; + } else { + if (CAN_SCAN_IN_CONNECT(ar->scParams.scanCtrlFlags)) { + ar->arSkipScan = false; + } else { + ar->arSkipScan = true; + } + + if (wmi_scanparams_cmd(ar->arWmi, ar->scParams.fg_start_period, + ar->scParams.fg_end_period, + ar->scParams.bg_period, + ar->scParams.minact_chdwell_time, + ar->scParams.maxact_chdwell_time, + ar->scParams.pas_chdwell_time, + ar->scParams.shortScanRatio, + ar->scParams.scanCtrlFlags, + ar->scParams.max_dfsch_act_time, + ar->scParams.maxact_scan_per_ssid) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_IOCTL_WMI_SETLISTENINT: + { + WMI_LISTEN_INT_CMD listenCmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&listenCmd, userdata, + sizeof(listenCmd))) + { + ret = -EFAULT; + } else { + if (wmi_listeninterval_cmd(ar->arWmi, listenCmd.listenInterval, listenCmd.numBeacons) != 0) { + ret = -EIO; + } else { + AR6000_SPIN_LOCK(&ar->arLock, 0); + ar->arListenIntervalT = listenCmd.listenInterval; + ar->arListenIntervalB = listenCmd.numBeacons; + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + } + + } + break; + } + case AR6000_IOCTL_WMI_SET_BMISS_TIME: + { + WMI_BMISS_TIME_CMD bmissCmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&bmissCmd, userdata, + sizeof(bmissCmd))) + { + ret = -EFAULT; + } else { + if (wmi_bmisstime_cmd(ar->arWmi, bmissCmd.bmissTime, bmissCmd.numBeacons) != 0) { + ret = -EIO; + } + } + break; + } + case AR6000_IOCTL_WMI_SETBSSFILTER: + { + WMI_BSS_FILTER_CMD filt; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&filt, userdata, + sizeof(filt))) + { + ret = -EFAULT; + } else { + if (wmi_bssfilter_cmd(ar->arWmi, filt.bssFilter, filt.ieMask) + != 0) { + ret = -EIO; + } else { + ar->arUserBssFilter = filt.bssFilter; + } + } + break; + } + + case AR6000_IOCTL_WMI_SET_SNRTHRESHOLD: + { + ret = ar6000_ioctl_set_snr_threshold(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_SET_RSSITHRESHOLD: + { + ret = ar6000_ioctl_set_rssi_threshold(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_CLR_RSSISNR: + { + if (ar->arWmiReady == false) { + ret = -EIO; + } + ret = wmi_clr_rssi_snr(ar->arWmi); + break; + } + case AR6000_XIOCTL_WMI_SET_LQTHRESHOLD: + { + ret = ar6000_ioctl_set_lq_threshold(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_SET_LPREAMBLE: + { + WMI_SET_LPREAMBLE_CMD setLpreambleCmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&setLpreambleCmd, userdata, + sizeof(setLpreambleCmd))) + { + ret = -EFAULT; + } else { + if (wmi_set_lpreamble_cmd(ar->arWmi, setLpreambleCmd.status, +#if WLAN_CONFIG_DONOT_IGNORE_BARKER_IN_ERP + WMI_DONOT_IGNORE_BARKER_IN_ERP +#else + WMI_IGNORE_BARKER_IN_ERP +#endif + ) != 0) + { + ret = -EIO; + } + } + + break; + } + case AR6000_XIOCTL_WMI_SET_RTS: + { + WMI_SET_RTS_CMD rtsCmd; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&rtsCmd, userdata, + sizeof(rtsCmd))) + { + ret = -EFAULT; + } else { + ar->arRTS = rtsCmd.threshold; + if (wmi_set_rts_cmd(ar->arWmi, rtsCmd.threshold) + != 0) + { + ret = -EIO; + } + } + + break; + } + case AR6000_XIOCTL_WMI_SET_WMM: + { + ret = ar6000_ioctl_set_wmm(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_SET_QOS_SUPP: + { + ret = ar6000_ioctl_set_qos_supp(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_SET_TXOP: + { + ret = ar6000_ioctl_set_txop(dev, rq); + break; + } + case AR6000_XIOCTL_WMI_GET_RD: + { + ret = ar6000_ioctl_get_rd(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_CHANNELPARAMS: + { + ret = ar6000_ioctl_set_channelParams(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_PROBEDSSID: + { + ret = ar6000_ioctl_set_probedSsid(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_BADAP: + { + ret = ar6000_ioctl_set_badAp(dev, rq); + break; + } + case AR6000_IOCTL_WMI_CREATE_QOS: + { + ret = ar6000_ioctl_create_qos(dev, rq); + break; + } + case AR6000_IOCTL_WMI_DELETE_QOS: + { + ret = ar6000_ioctl_delete_qos(dev, rq); + break; + } + case AR6000_IOCTL_WMI_GET_QOS_QUEUE: + { + ret = ar6000_ioctl_get_qos_queue(dev, rq); + break; + } + case AR6000_IOCTL_WMI_GET_TARGET_STATS: + { + ret = ar6000_ioctl_get_target_stats(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_ERROR_REPORT_BITMASK: + { + ret = ar6000_ioctl_set_error_report_bitmask(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_ASSOC_INFO: + { + WMI_SET_ASSOC_INFO_CMD cmd; + u8 assocInfo[WMI_MAX_ASSOC_INFO_LEN]; + + if (ar->arWmiReady == false) { + ret = -EIO; + break; + } + + if (get_user(cmd.ieType, userdata)) { + ret = -EFAULT; + break; + } + if (cmd.ieType >= WMI_MAX_ASSOC_INFO_TYPE) { + ret = -EIO; + break; + } + + if (get_user(cmd.bufferSize, userdata + 1) || + (cmd.bufferSize > WMI_MAX_ASSOC_INFO_LEN) || + copy_from_user(assocInfo, userdata + 2, cmd.bufferSize)) { + ret = -EFAULT; + break; + } + if (wmi_associnfo_cmd(ar->arWmi, cmd.ieType, + cmd.bufferSize, assocInfo) != 0) { + ret = -EIO; + break; + } + break; + } + case AR6000_IOCTL_WMI_SET_ACCESS_PARAMS: + { + ret = ar6000_ioctl_set_access_params(dev, rq); + break; + } + case AR6000_IOCTL_WMI_SET_DISC_TIMEOUT: + { + ret = ar6000_ioctl_set_disconnect_timeout(dev, rq); + break; + } + case AR6000_XIOCTL_FORCE_TARGET_RESET: + { + if (ar->arHtcTarget) + { +// HTCForceReset(htcTarget); + } + else + { + AR_DEBUG_PRINTF(ATH_DEBUG_WARN,("ar6000_ioctl cannot attempt reset.\n")); + } + break; + } + case AR6000_XIOCTL_TARGET_INFO: + case AR6000_XIOCTL_CHECK_TARGET_READY: /* backwards compatibility */ + { + /* If we made it to here, then the Target exists and is ready. */ + + if (cmd == AR6000_XIOCTL_TARGET_INFO) { + if (copy_to_user((u32 *)rq->ifr_data, &ar->arVersion.target_ver, + sizeof(ar->arVersion.target_ver))) + { + ret = -EFAULT; + } + if (copy_to_user(((u32 *)rq->ifr_data)+1, &ar->arTargetType, + sizeof(ar->arTargetType))) + { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_HB_CHALLENGE_RESP_PARAMS: + { + WMI_SET_HB_CHALLENGE_RESP_PARAMS_CMD hbparam; + + if (copy_from_user(&hbparam, userdata, sizeof(hbparam))) + { + ret = -EFAULT; + } else { + AR6000_SPIN_LOCK(&ar->arLock, 0); + /* Start a cyclic timer with the parameters provided. */ + if (hbparam.frequency) { + ar->arHBChallengeResp.frequency = hbparam.frequency; + } + if (hbparam.threshold) { + ar->arHBChallengeResp.missThres = hbparam.threshold; + } + + /* Delete the pending timer and start a new one */ + if (timer_pending(&ar->arHBChallengeResp.timer)) { + A_UNTIMEOUT(&ar->arHBChallengeResp.timer); + } + A_TIMEOUT_MS(&ar->arHBChallengeResp.timer, ar->arHBChallengeResp.frequency * 1000, 0); + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + } + break; + } + case AR6000_XIOCTL_WMI_GET_HB_CHALLENGE_RESP: + { + u32 cookie; + + if (copy_from_user(&cookie, userdata, sizeof(cookie))) { + ret = -EFAULT; + goto ioctl_done; + } + + /* Send the challenge on the control channel */ + if (wmi_get_challenge_resp_cmd(ar->arWmi, cookie, APP_HB_CHALLENGE) != 0) { + ret = -EIO; + goto ioctl_done; + } + break; + } +#ifdef USER_KEYS + case AR6000_XIOCTL_USER_SETKEYS: + { + + ar->user_savedkeys_stat = USER_SAVEDKEYS_STAT_RUN; + + if (copy_from_user(&ar->user_key_ctrl, userdata, + sizeof(ar->user_key_ctrl))) + { + ret = -EFAULT; + goto ioctl_done; + } + + A_PRINTF("ar6000 USER set key %x\n", ar->user_key_ctrl); + break; + } +#endif /* USER_KEYS */ + +#ifdef CONFIG_HOST_GPIO_SUPPORT + case AR6000_XIOCTL_GPIO_OUTPUT_SET: + { + struct ar6000_gpio_output_set_cmd_s gpio_output_set_cmd; + + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + if (copy_from_user(&gpio_output_set_cmd, userdata, + sizeof(gpio_output_set_cmd))) + { + ret = -EFAULT; + } else { + ret = ar6000_gpio_output_set(dev, + gpio_output_set_cmd.set_mask, + gpio_output_set_cmd.clear_mask, + gpio_output_set_cmd.enable_mask, + gpio_output_set_cmd.disable_mask); + if (ret != 0) { + ret = -EIO; + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_GPIO_INPUT_GET: + { + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + ret = ar6000_gpio_input_get(dev); + if (ret != 0) { + up(&ar->arSem); + ret = -EIO; + goto ioctl_done; + } + + /* Wait for Target to respond. */ + wait_event_interruptible(arEvent, gpio_data_available); + if (signal_pending(current)) { + ret = -EINTR; + } else { + A_ASSERT(gpio_reg_results.gpioreg_id == GPIO_ID_NONE); + + if (copy_to_user(userdata, &gpio_reg_results.value, + sizeof(gpio_reg_results.value))) + { + ret = -EFAULT; + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_GPIO_REGISTER_SET: + { + struct ar6000_gpio_register_cmd_s gpio_register_cmd; + + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + if (copy_from_user(&gpio_register_cmd, userdata, + sizeof(gpio_register_cmd))) + { + ret = -EFAULT; + } else { + ret = ar6000_gpio_register_set(dev, + gpio_register_cmd.gpioreg_id, + gpio_register_cmd.value); + if (ret != 0) { + ret = -EIO; + } + + /* Wait for acknowledgement from Target */ + wait_event_interruptible(arEvent, gpio_ack_received); + if (signal_pending(current)) { + ret = -EINTR; + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_GPIO_REGISTER_GET: + { + struct ar6000_gpio_register_cmd_s gpio_register_cmd; + + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + if (copy_from_user(&gpio_register_cmd, userdata, + sizeof(gpio_register_cmd))) + { + ret = -EFAULT; + } else { + ret = ar6000_gpio_register_get(dev, gpio_register_cmd.gpioreg_id); + if (ret != 0) { + up(&ar->arSem); + ret = -EIO; + goto ioctl_done; + } + + /* Wait for Target to respond. */ + wait_event_interruptible(arEvent, gpio_data_available); + if (signal_pending(current)) { + ret = -EINTR; + } else { + A_ASSERT(gpio_register_cmd.gpioreg_id == gpio_reg_results.gpioreg_id); + if (copy_to_user(userdata, &gpio_reg_results, + sizeof(gpio_reg_results))) + { + ret = -EFAULT; + } + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_GPIO_INTR_ACK: + { + struct ar6000_gpio_intr_ack_cmd_s gpio_intr_ack_cmd; + + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + + if (copy_from_user(&gpio_intr_ack_cmd, userdata, + sizeof(gpio_intr_ack_cmd))) + { + ret = -EFAULT; + } else { + ret = ar6000_gpio_intr_ack(dev, gpio_intr_ack_cmd.ack_mask); + if (ret != 0) { + ret = -EIO; + } + } + up(&ar->arSem); + break; + } + case AR6000_XIOCTL_GPIO_INTR_WAIT: + { + /* Wait for Target to report an interrupt. */ + wait_event_interruptible(arEvent, gpio_intr_available); + + if (signal_pending(current)) { + ret = -EINTR; + } else { + if (copy_to_user(userdata, &gpio_intr_results, + sizeof(gpio_intr_results))) + { + ret = -EFAULT; + } + } + break; + } +#endif /* CONFIG_HOST_GPIO_SUPPORT */ + + case AR6000_XIOCTL_DBGLOG_CFG_MODULE: + { + struct ar6000_dbglog_module_config_s config; + + if (copy_from_user(&config, userdata, sizeof(config))) { + ret = -EFAULT; + goto ioctl_done; + } + + /* Send the challenge on the control channel */ + if (wmi_config_debug_module_cmd(ar->arWmi, config.mmask, + config.tsr, config.rep, + config.size, config.valid) != 0) + { + ret = -EIO; + goto ioctl_done; + } + break; + } + + case AR6000_XIOCTL_DBGLOG_GET_DEBUG_LOGS: + { + /* Send the challenge on the control channel */ + if (ar6000_dbglog_get_debug_logs(ar) != 0) + { + ret = -EIO; + goto ioctl_done; + } + break; + } + + case AR6000_XIOCTL_SET_ADHOC_BSSID: + { + WMI_SET_ADHOC_BSSID_CMD adhocBssid; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&adhocBssid, userdata, + sizeof(adhocBssid))) + { + ret = -EFAULT; + } else if (memcmp(adhocBssid.bssid, bcast_mac, + AR6000_ETH_ADDR_LEN) == 0) + { + ret = -EFAULT; + } else { + + memcpy(ar->arReqBssid, adhocBssid.bssid, sizeof(ar->arReqBssid)); + } + break; + } + + case AR6000_XIOCTL_SET_OPT_MODE: + { + WMI_SET_OPT_MODE_CMD optModeCmd; + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&optModeCmd, userdata, + sizeof(optModeCmd))) + { + ret = -EFAULT; + } else if (ar->arConnected && optModeCmd.optMode == SPECIAL_ON) { + ret = -EFAULT; + + } else if (wmi_set_opt_mode_cmd(ar->arWmi, optModeCmd.optMode) + != 0) + { + ret = -EIO; + } + break; + } + + case AR6000_XIOCTL_OPT_SEND_FRAME: + { + WMI_OPT_TX_FRAME_CMD optTxFrmCmd; + u8 data[MAX_OPT_DATA_LEN]; + + if (ar->arWmiReady == false) { + ret = -EIO; + break; + } + + if (copy_from_user(&optTxFrmCmd, userdata, sizeof(optTxFrmCmd))) { + ret = -EFAULT; + break; + } + + if (optTxFrmCmd.optIEDataLen > MAX_OPT_DATA_LEN) { + ret = -EINVAL; + break; + } + + if (copy_from_user(data, userdata+sizeof(WMI_OPT_TX_FRAME_CMD) - 1, + optTxFrmCmd.optIEDataLen)) { + ret = -EFAULT; + break; + } + + ret = wmi_opt_tx_frame_cmd(ar->arWmi, + optTxFrmCmd.frmType, + optTxFrmCmd.dstAddr, + optTxFrmCmd.bssid, + optTxFrmCmd.optIEDataLen, + data); + break; + } + case AR6000_XIOCTL_WMI_SETRETRYLIMITS: + { + WMI_SET_RETRY_LIMITS_CMD setRetryParams; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&setRetryParams, userdata, + sizeof(setRetryParams))) + { + ret = -EFAULT; + } else { + if (wmi_set_retry_limits_cmd(ar->arWmi, setRetryParams.frameType, + setRetryParams.trafficClass, + setRetryParams.maxRetries, + setRetryParams.enableNotify) != 0) + { + ret = -EIO; + } + AR6000_SPIN_LOCK(&ar->arLock, 0); + ar->arMaxRetries = setRetryParams.maxRetries; + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + } + break; + } + + case AR6000_XIOCTL_SET_BEACON_INTVAL: + { + WMI_BEACON_INT_CMD bIntvlCmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&bIntvlCmd, userdata, + sizeof(bIntvlCmd))) + { + ret = -EFAULT; + } else if (wmi_set_adhoc_bconIntvl_cmd(ar->arWmi, bIntvlCmd.beaconInterval) + != 0) + { + ret = -EIO; + } + if(ret == 0) { + ar->ap_beacon_interval = bIntvlCmd.beaconInterval; + ar->ap_profile_flag = 1; /* There is a change in profile */ + } + break; + } + case IEEE80211_IOCTL_SETAUTHALG: + { + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + struct ieee80211req_authalg req; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&req, userdata, + sizeof(struct ieee80211req_authalg))) + { + ret = -EFAULT; + } else { + if (req.auth_alg & AUTH_ALG_OPEN_SYSTEM) { + ar->arDot11AuthMode |= OPEN_AUTH; + ar->arPairwiseCrypto = NONE_CRYPT; + ar->arGroupCrypto = NONE_CRYPT; + } + if (req.auth_alg & AUTH_ALG_SHARED_KEY) { + ar->arDot11AuthMode |= SHARED_AUTH; + ar->arPairwiseCrypto = WEP_CRYPT; + ar->arGroupCrypto = WEP_CRYPT; + ar->arAuthMode = NONE_AUTH; + } + if (req.auth_alg == AUTH_ALG_LEAP) { + ar->arDot11AuthMode = LEAP_AUTH; + } + } + break; + } + + case AR6000_XIOCTL_SET_VOICE_PKT_SIZE: + ret = ar6000_xioctl_set_voice_pkt_size(dev, userdata); + break; + + case AR6000_XIOCTL_SET_MAX_SP: + ret = ar6000_xioctl_set_max_sp_len(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_GET_ROAM_TBL: + ret = ar6000_ioctl_get_roam_tbl(dev, rq); + break; + case AR6000_XIOCTL_WMI_SET_ROAM_CTRL: + ret = ar6000_ioctl_set_roam_ctrl(dev, userdata); + break; + case AR6000_XIOCTRL_WMI_SET_POWERSAVE_TIMERS: + ret = ar6000_ioctl_set_powersave_timers(dev, userdata); + break; + case AR6000_XIOCTRL_WMI_GET_POWER_MODE: + ret = ar6000_ioctl_get_power_mode(dev, rq); + break; + case AR6000_XIOCTRL_WMI_SET_WLAN_STATE: + { + AR6000_WLAN_STATE state; + if (get_user(state, (unsigned int *)userdata)) + ret = -EFAULT; + else if (ar6000_set_wlan_state(ar, state) != 0) + ret = -EIO; + break; + } + case AR6000_XIOCTL_WMI_GET_ROAM_DATA: + ret = ar6000_ioctl_get_roam_data(dev, rq); + break; + + case AR6000_XIOCTL_WMI_SET_BT_STATUS: + ret = ar6000_xioctl_set_bt_status_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BT_PARAMS: + ret = ar6000_xioctl_set_bt_params_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_FE_ANT: + ret = ar6000_xioctl_set_btcoex_fe_ant_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_COLOCATED_BT_DEV: + ret = ar6000_xioctl_set_btcoex_colocated_bt_dev_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_BTINQUIRY_PAGE_CONFIG: + ret = ar6000_xioctl_set_btcoex_btinquiry_page_config_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_SCO_CONFIG: + ret = ar6000_xioctl_set_btcoex_sco_config_cmd( dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_A2DP_CONFIG: + ret = ar6000_xioctl_set_btcoex_a2dp_config_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_ACLCOEX_CONFIG: + ret = ar6000_xioctl_set_btcoex_aclcoex_config_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BTCOEX_DEBUG: + ret = ar60000_xioctl_set_btcoex_debug_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_SET_BT_OPERATING_STATUS: + ret = ar6000_xioctl_set_btcoex_bt_operating_status_cmd(dev, userdata); + break; + + case AR6000_XIOCTL_WMI_GET_BTCOEX_CONFIG: + ret = ar6000_xioctl_get_btcoex_config_cmd(dev, userdata, rq); + break; + + case AR6000_XIOCTL_WMI_GET_BTCOEX_STATS: + ret = ar6000_xioctl_get_btcoex_stats_cmd(dev, userdata, rq); + break; + + case AR6000_XIOCTL_WMI_STARTSCAN: + { + WMI_START_SCAN_CMD setStartScanCmd, *cmdp; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&setStartScanCmd, userdata, + sizeof(setStartScanCmd))) + { + ret = -EFAULT; + } else { + if (setStartScanCmd.numChannels > 1) { + cmdp = A_MALLOC(130); + if (copy_from_user(cmdp, userdata, + sizeof (*cmdp) + + ((setStartScanCmd.numChannels - 1) * + sizeof(u16)))) + { + kfree(cmdp); + ret = -EFAULT; + goto ioctl_done; + } + } else { + cmdp = &setStartScanCmd; + } + + if (wmi_startscan_cmd(ar->arWmi, cmdp->scanType, + cmdp->forceFgScan, + cmdp->isLegacy, + cmdp->homeDwellTime, + cmdp->forceScanInterval, + cmdp->numChannels, + cmdp->channelList) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_SETFIXRATES: + { + WMI_FIX_RATES_CMD setFixRatesCmd; + int returnStatus; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&setFixRatesCmd, userdata, + sizeof(setFixRatesCmd))) + { + ret = -EFAULT; + } else { + returnStatus = wmi_set_fixrates_cmd(ar->arWmi, setFixRatesCmd.fixRateMask); + if (returnStatus == A_EINVAL) { + ret = -EINVAL; + } else if(returnStatus != 0) { + ret = -EIO; + } else { + ar->ap_profile_flag = 1; /* There is a change in profile */ + } + } + break; + } + + case AR6000_XIOCTL_WMI_GETFIXRATES: + { + WMI_FIX_RATES_CMD getFixRatesCmd; + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + int ret = 0; + + if (ar->bIsDestroyProgress) { + ret = -EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } + + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + /* Used copy_from_user/copy_to_user to access user space data */ + if (copy_from_user(&getFixRatesCmd, userdata, sizeof(getFixRatesCmd))) { + ret = -EFAULT; + } else { + ar->arRateMask = 0xFFFFFFFF; + + if (wmi_get_ratemask_cmd(ar->arWmi) != 0) { + up(&ar->arSem); + ret = -EIO; + goto ioctl_done; + } + + wait_event_interruptible_timeout(arEvent, ar->arRateMask != 0xFFFFFFFF, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret) { + getFixRatesCmd.fixRateMask = ar->arRateMask; + } + + if(copy_to_user(userdata, &getFixRatesCmd, sizeof(getFixRatesCmd))) { + ret = -EFAULT; + } + + up(&ar->arSem); + } + break; + } + case AR6000_XIOCTL_WMI_SET_AUTHMODE: + { + WMI_SET_AUTH_MODE_CMD setAuthMode; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&setAuthMode, userdata, + sizeof(setAuthMode))) + { + ret = -EFAULT; + } else { + if (wmi_set_authmode_cmd(ar->arWmi, setAuthMode.mode) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_REASSOCMODE: + { + WMI_SET_REASSOC_MODE_CMD setReassocMode; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&setReassocMode, userdata, + sizeof(setReassocMode))) + { + ret = -EFAULT; + } else { + if (wmi_set_reassocmode_cmd(ar->arWmi, setReassocMode.mode) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_DIAG_READ: + { + u32 addr, data; + if (get_user(addr, (unsigned int *)userdata)) { + ret = -EFAULT; + break; + } + addr = TARG_VTOP(ar->arTargetType, addr); + if (ar6000_ReadRegDiag(ar->arHifDevice, &addr, &data) != 0) { + ret = -EIO; + } + if (put_user(data, (unsigned int *)userdata + 1)) { + ret = -EFAULT; + break; + } + break; + } + case AR6000_XIOCTL_DIAG_WRITE: + { + u32 addr, data; + if (get_user(addr, (unsigned int *)userdata) || + get_user(data, (unsigned int *)userdata + 1)) { + ret = -EFAULT; + break; + } + addr = TARG_VTOP(ar->arTargetType, addr); + if (ar6000_WriteRegDiag(ar->arHifDevice, &addr, &data) != 0) { + ret = -EIO; + } + break; + } + case AR6000_XIOCTL_WMI_SET_KEEPALIVE: + { + WMI_SET_KEEPALIVE_CMD setKeepAlive; + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&setKeepAlive, userdata, + sizeof(setKeepAlive))){ + ret = -EFAULT; + } else { + if (wmi_set_keepalive_cmd(ar->arWmi, setKeepAlive.keepaliveInterval) != 0) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_PARAMS: + { + WMI_SET_PARAMS_CMD cmd; + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&cmd, userdata, + sizeof(cmd))){ + ret = -EFAULT; + } else if (copy_from_user(&cmd, userdata, + sizeof(cmd) + cmd.length)) + { + ret = -EFAULT; + } else { + if (wmi_set_params_cmd(ar->arWmi, cmd.opcode, cmd.length, cmd.buffer) != 0) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_MCAST_FILTER: + { + WMI_SET_MCAST_FILTER_CMD cmd; + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&cmd, userdata, + sizeof(cmd))){ + ret = -EFAULT; + } else { + if (wmi_set_mcast_filter_cmd(ar->arWmi, cmd.multicast_mac[0], + cmd.multicast_mac[1], + cmd.multicast_mac[2], + cmd.multicast_mac[3]) != 0) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_DEL_MCAST_FILTER: + { + WMI_SET_MCAST_FILTER_CMD cmd; + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&cmd, userdata, + sizeof(cmd))){ + ret = -EFAULT; + } else { + if (wmi_del_mcast_filter_cmd(ar->arWmi, cmd.multicast_mac[0], + cmd.multicast_mac[1], + cmd.multicast_mac[2], + cmd.multicast_mac[3]) != 0) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_MCAST_FILTER: + { + WMI_MCAST_FILTER_CMD cmd; + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&cmd, userdata, + sizeof(cmd))){ + ret = -EFAULT; + } else { + if (wmi_mcast_filter_cmd(ar->arWmi, cmd.enable) != 0) { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_GET_KEEPALIVE: + { + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_GET_KEEPALIVE_CMD getKeepAlive; + int ret = 0; + if (ar->bIsDestroyProgress) { + ret =-EBUSY; + goto ioctl_done; + } + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } + if (down_interruptible(&ar->arSem)) { + ret = -ERESTARTSYS; + goto ioctl_done; + } + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + ret = -EBUSY; + goto ioctl_done; + } + if (copy_from_user(&getKeepAlive, userdata,sizeof(getKeepAlive))) { + ret = -EFAULT; + } else { + getKeepAlive.keepaliveInterval = wmi_get_keepalive_cmd(ar->arWmi); + ar->arKeepaliveConfigured = 0xFF; + if (wmi_get_keepalive_configured(ar->arWmi) != 0){ + up(&ar->arSem); + ret = -EIO; + goto ioctl_done; + } + wait_event_interruptible_timeout(arEvent, ar->arKeepaliveConfigured != 0xFF, wmitimeout * HZ); + if (signal_pending(current)) { + ret = -EINTR; + } + + if (!ret) { + getKeepAlive.configured = ar->arKeepaliveConfigured; + } + if (copy_to_user(userdata, &getKeepAlive, sizeof(getKeepAlive))) { + ret = -EFAULT; + } + up(&ar->arSem); + } + break; + } + case AR6000_XIOCTL_WMI_SET_APPIE: + { + WMI_SET_APPIE_CMD appIEcmd; + u8 appIeInfo[IEEE80211_APPIE_FRAME_MAX_LEN]; + u32 fType,ieLen; + + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } + if (get_user(fType, (u32 *)userdata)) { + ret = -EFAULT; + break; + } + appIEcmd.mgmtFrmType = fType; + if (appIEcmd.mgmtFrmType >= IEEE80211_APPIE_NUM_OF_FRAME) { + ret = -EIO; + } else { + if (get_user(ieLen, (u32 *)(userdata + 4))) { + ret = -EFAULT; + break; + } + appIEcmd.ieLen = ieLen; + A_PRINTF("WPSIE: Type-%d, Len-%d\n",appIEcmd.mgmtFrmType, appIEcmd.ieLen); + if (appIEcmd.ieLen > IEEE80211_APPIE_FRAME_MAX_LEN) { + ret = -EIO; + break; + } + if (copy_from_user(appIeInfo, userdata + 8, appIEcmd.ieLen)) { + ret = -EFAULT; + } else { + if (wmi_set_appie_cmd(ar->arWmi, appIEcmd.mgmtFrmType, + appIEcmd.ieLen, appIeInfo) != 0) + { + ret = -EIO; + } + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_MGMT_FRM_RX_FILTER: + { + WMI_BSS_FILTER_CMD cmd; + u32 filterType; + + if (copy_from_user(&filterType, userdata, sizeof(u32))) + { + ret = -EFAULT; + goto ioctl_done; + } + if (filterType & (IEEE80211_FILTER_TYPE_BEACON | + IEEE80211_FILTER_TYPE_PROBE_RESP)) + { + cmd.bssFilter = ALL_BSS_FILTER; + } else { + cmd.bssFilter = NONE_BSS_FILTER; + } + if (wmi_bssfilter_cmd(ar->arWmi, cmd.bssFilter, 0) != 0) { + ret = -EIO; + } else { + ar->arUserBssFilter = cmd.bssFilter; + } + + AR6000_SPIN_LOCK(&ar->arLock, 0); + ar->arMgmtFilter = filterType; + AR6000_SPIN_UNLOCK(&ar->arLock, 0); + break; + } + case AR6000_XIOCTL_WMI_SET_WSC_STATUS: + { + u32 wsc_status; + + if (ar->arWmiReady == false) { + ret = -EIO; + goto ioctl_done; + } else if (copy_from_user(&wsc_status, userdata, sizeof(u32))) + { + ret = -EFAULT; + goto ioctl_done; + } + if (wmi_set_wsc_status_cmd(ar->arWmi, wsc_status) != 0) { + ret = -EIO; + } + break; + } + case AR6000_XIOCTL_BMI_ROMPATCH_INSTALL: + { + u32 ROM_addr; + u32 RAM_addr; + u32 nbytes; + u32 do_activate; + u32 rompatch_id; + + if (get_user(ROM_addr, (u32 *)userdata) || + get_user(RAM_addr, (u32 *)userdata + 1) || + get_user(nbytes, (u32 *)userdata + 2) || + get_user(do_activate, (u32 *)userdata + 3)) { + ret = -EFAULT; + break; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Install rompatch from ROM: 0x%x to RAM: 0x%x length: %d\n", + ROM_addr, RAM_addr, nbytes)); + ret = BMIrompatchInstall(hifDevice, ROM_addr, RAM_addr, + nbytes, do_activate, &rompatch_id); + if (ret == 0) { + /* return value */ + if (put_user(rompatch_id, (unsigned int *)rq->ifr_data)) { + ret = -EFAULT; + break; + } + } + break; + } + + case AR6000_XIOCTL_BMI_ROMPATCH_UNINSTALL: + { + u32 rompatch_id; + + if (get_user(rompatch_id, (u32 *)userdata)) { + ret = -EFAULT; + break; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("UNinstall rompatch_id %d\n", rompatch_id)); + ret = BMIrompatchUninstall(hifDevice, rompatch_id); + break; + } + + case AR6000_XIOCTL_BMI_ROMPATCH_ACTIVATE: + case AR6000_XIOCTL_BMI_ROMPATCH_DEACTIVATE: + { + u32 rompatch_count; + + if (get_user(rompatch_count, (u32 *)userdata)) { + ret = -EFAULT; + break; + } + AR_DEBUG_PRINTF(ATH_DEBUG_INFO,("Change rompatch activation count=%d\n", rompatch_count)); + length = sizeof(u32) * rompatch_count; + if ((buffer = (unsigned char *)A_MALLOC(length)) != NULL) { + A_MEMZERO(buffer, length); + if (copy_from_user(buffer, &userdata[sizeof(rompatch_count)], length)) + { + ret = -EFAULT; + } else { + if (cmd == AR6000_XIOCTL_BMI_ROMPATCH_ACTIVATE) { + ret = BMIrompatchActivate(hifDevice, rompatch_count, (u32 *)buffer); + } else { + ret = BMIrompatchDeactivate(hifDevice, rompatch_count, (u32 *)buffer); + } + } + A_FREE(buffer); + } else { + ret = -ENOMEM; + } + + break; + } + case AR6000_XIOCTL_SET_IP: + { + WMI_SET_IP_CMD setIP; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&setIP, userdata, + sizeof(setIP))) + { + ret = -EFAULT; + } else { + if (wmi_set_ip_cmd(ar->arWmi, + &setIP) != 0) + { + ret = -EIO; + } + } + break; + } + + case AR6000_XIOCTL_WMI_SET_HOST_SLEEP_MODE: + { + WMI_SET_HOST_SLEEP_MODE_CMD setHostSleepMode; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&setHostSleepMode, userdata, + sizeof(setHostSleepMode))) + { + ret = -EFAULT; + } else { + if (wmi_set_host_sleep_mode_cmd(ar->arWmi, + &setHostSleepMode) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_SET_WOW_MODE: + { + WMI_SET_WOW_MODE_CMD setWowMode; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&setWowMode, userdata, + sizeof(setWowMode))) + { + ret = -EFAULT; + } else { + if (wmi_set_wow_mode_cmd(ar->arWmi, + &setWowMode) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_GET_WOW_LIST: + { + WMI_GET_WOW_LIST_CMD getWowList; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&getWowList, userdata, + sizeof(getWowList))) + { + ret = -EFAULT; + } else { + if (wmi_get_wow_list_cmd(ar->arWmi, + &getWowList) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_ADD_WOW_PATTERN: + { +#define WOW_PATTERN_SIZE 64 +#define WOW_MASK_SIZE 64 + + WMI_ADD_WOW_PATTERN_CMD cmd; + u8 mask_data[WOW_PATTERN_SIZE]={0}; + u8 pattern_data[WOW_PATTERN_SIZE]={0}; + + do { + if (ar->arWmiReady == false) { + ret = -EIO; + break; + } + if(copy_from_user(&cmd, userdata, + sizeof(WMI_ADD_WOW_PATTERN_CMD))) + { + ret = -EFAULT; + break; + } + if (copy_from_user(pattern_data, + userdata + 3, + cmd.filter_size)) + { + ret = -EFAULT; + break; + } + if (copy_from_user(mask_data, + (userdata + 3 + cmd.filter_size), + cmd.filter_size)) + { + ret = -EFAULT; + break; + } + if (wmi_add_wow_pattern_cmd(ar->arWmi, + &cmd, pattern_data, mask_data, cmd.filter_size) != 0) + { + ret = -EIO; + } + } while(false); +#undef WOW_PATTERN_SIZE +#undef WOW_MASK_SIZE + break; + } + case AR6000_XIOCTL_WMI_DEL_WOW_PATTERN: + { + WMI_DEL_WOW_PATTERN_CMD delWowPattern; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&delWowPattern, userdata, + sizeof(delWowPattern))) + { + ret = -EFAULT; + } else { + if (wmi_del_wow_pattern_cmd(ar->arWmi, + &delWowPattern) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_DUMP_HTC_CREDIT_STATE: + if (ar->arHtcTarget != NULL) { +#ifdef ATH_DEBUG_MODULE + HTCDumpCreditStates(ar->arHtcTarget); +#endif /* ATH_DEBUG_MODULE */ +#ifdef HTC_EP_STAT_PROFILING + { + struct htc_endpoint_stats stats; + int i; + + for (i = 0; i < 5; i++) { + if (HTCGetEndpointStatistics(ar->arHtcTarget, + i, + HTC_EP_STAT_SAMPLE_AND_CLEAR, + &stats)) { + A_PRINTF(KERN_ALERT"------- Profiling Endpoint : %d \n", i); + A_PRINTF(KERN_ALERT"TxCreditLowIndications : %d \n", stats.TxCreditLowIndications); + A_PRINTF(KERN_ALERT"TxIssued : %d \n", stats.TxIssued); + A_PRINTF(KERN_ALERT"TxDropped: %d \n", stats.TxDropped); + A_PRINTF(KERN_ALERT"TxPacketsBundled : %d \n", stats.TxPacketsBundled); + A_PRINTF(KERN_ALERT"TxBundles : %d \n", stats.TxBundles); + A_PRINTF(KERN_ALERT"TxCreditRpts : %d \n", stats.TxCreditRpts); + A_PRINTF(KERN_ALERT"TxCreditsRptsFromRx : %d \n", stats.TxCreditRptsFromRx); + A_PRINTF(KERN_ALERT"TxCreditsRptsFromOther : %d \n", stats.TxCreditRptsFromOther); + A_PRINTF(KERN_ALERT"TxCreditsRptsFromEp0 : %d \n", stats.TxCreditRptsFromEp0); + A_PRINTF(KERN_ALERT"TxCreditsFromRx : %d \n", stats.TxCreditsFromRx); + A_PRINTF(KERN_ALERT"TxCreditsFromOther : %d \n", stats.TxCreditsFromOther); + A_PRINTF(KERN_ALERT"TxCreditsFromEp0 : %d \n", stats.TxCreditsFromEp0); + A_PRINTF(KERN_ALERT"TxCreditsConsummed : %d \n", stats.TxCreditsConsummed); + A_PRINTF(KERN_ALERT"TxCreditsReturned : %d \n", stats.TxCreditsReturned); + A_PRINTF(KERN_ALERT"RxReceived : %d \n", stats.RxReceived); + A_PRINTF(KERN_ALERT"RxPacketsBundled : %d \n", stats.RxPacketsBundled); + A_PRINTF(KERN_ALERT"RxLookAheads : %d \n", stats.RxLookAheads); + A_PRINTF(KERN_ALERT"RxBundleLookAheads : %d \n", stats.RxBundleLookAheads); + A_PRINTF(KERN_ALERT"RxBundleIndFromHdr : %d \n", stats.RxBundleIndFromHdr); + A_PRINTF(KERN_ALERT"RxAllocThreshHit : %d \n", stats.RxAllocThreshHit); + A_PRINTF(KERN_ALERT"RxAllocThreshBytes : %d \n", stats.RxAllocThreshBytes); + A_PRINTF(KERN_ALERT"---- \n"); + + } + } + } +#endif + } + break; + case AR6000_XIOCTL_TRAFFIC_ACTIVITY_CHANGE: + if (ar->arHtcTarget != NULL) { + struct ar6000_traffic_activity_change data; + + if (copy_from_user(&data, userdata, sizeof(data))) + { + ret = -EFAULT; + goto ioctl_done; + } + /* note, this is used for testing (mbox ping testing), indicate activity + * change using the stream ID as the traffic class */ + ar6000_indicate_tx_activity(ar, + (u8)data.StreamID, + data.Active ? true : false); + } + break; + case AR6000_XIOCTL_WMI_SET_CONNECT_CTRL_FLAGS: + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&connectCtrlFlags, userdata, + sizeof(connectCtrlFlags))) + { + ret = -EFAULT; + } else { + ar->arConnectCtrlFlags = connectCtrlFlags; + } + break; + case AR6000_XIOCTL_WMI_SET_AKMP_PARAMS: + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&akmpParams, userdata, + sizeof(WMI_SET_AKMP_PARAMS_CMD))) + { + ret = -EFAULT; + } else { + if (wmi_set_akmp_params_cmd(ar->arWmi, &akmpParams) != 0) { + ret = -EIO; + } + } + break; + case AR6000_XIOCTL_WMI_SET_PMKID_LIST: + if (ar->arWmiReady == false) { + ret = -EIO; + } else { + if (copy_from_user(&pmkidInfo.numPMKID, userdata, + sizeof(pmkidInfo.numPMKID))) + { + ret = -EFAULT; + break; + } + if (copy_from_user(&pmkidInfo.pmkidList, + userdata + sizeof(pmkidInfo.numPMKID), + pmkidInfo.numPMKID * sizeof(WMI_PMKID))) + { + ret = -EFAULT; + break; + } + if (wmi_set_pmkid_list_cmd(ar->arWmi, &pmkidInfo) != 0) { + ret = -EIO; + } + } + break; + case AR6000_XIOCTL_WMI_GET_PMKID_LIST: + if (ar->arWmiReady == false) { + ret = -EIO; + } else { + if (wmi_get_pmkid_list_cmd(ar->arWmi) != 0) { + ret = -EIO; + } + } + break; + case AR6000_XIOCTL_WMI_ABORT_SCAN: + if (ar->arWmiReady == false) { + ret = -EIO; + } + ret = wmi_abort_scan_cmd(ar->arWmi); + break; + case AR6000_XIOCTL_AP_HIDDEN_SSID: + { + u8 hidden_ssid; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&hidden_ssid, userdata, sizeof(hidden_ssid))) { + ret = -EFAULT; + } else { + wmi_ap_set_hidden_ssid(ar->arWmi, hidden_ssid); + ar->ap_hidden_ssid = hidden_ssid; + ar->ap_profile_flag = 1; /* There is a change in profile */ + } + break; + } + case AR6000_XIOCTL_AP_GET_STA_LIST: + { + if (ar->arWmiReady == false) { + ret = -EIO; + } else { + u8 i; + ap_get_sta_t temp; + A_MEMZERO(&temp, sizeof(temp)); + for(i=0;ista_list[i].mac, ATH_MAC_LEN); + temp.sta[i].aid = ar->sta_list[i].aid; + temp.sta[i].keymgmt = ar->sta_list[i].keymgmt; + temp.sta[i].ucipher = ar->sta_list[i].ucipher; + temp.sta[i].auth = ar->sta_list[i].auth; + } + if(copy_to_user((ap_get_sta_t *)rq->ifr_data, &temp, + sizeof(ar->sta_list))) { + ret = -EFAULT; + } + } + break; + } + case AR6000_XIOCTL_AP_SET_NUM_STA: + { + u8 num_sta; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&num_sta, userdata, sizeof(num_sta))) { + ret = -EFAULT; + } else if(num_sta > AP_MAX_NUM_STA) { + /* value out of range */ + ret = -EINVAL; + } else { + wmi_ap_set_num_sta(ar->arWmi, num_sta); + } + break; + } + case AR6000_XIOCTL_AP_SET_ACL_POLICY: + { + u8 policy; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&policy, userdata, sizeof(policy))) { + ret = -EFAULT; + } else if(policy == ar->g_acl.policy) { + /* No change in policy */ + } else { + if(!(policy & AP_ACL_RETAIN_LIST_MASK)) { + /* clear ACL list */ + memset(&ar->g_acl,0,sizeof(WMI_AP_ACL)); + } + ar->g_acl.policy = policy; + wmi_ap_set_acl_policy(ar->arWmi, policy); + } + break; + } + case AR6000_XIOCTL_AP_SET_ACL_MAC: + { + WMI_AP_ACL_MAC_CMD acl; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&acl, userdata, sizeof(acl))) { + ret = -EFAULT; + } else { + if(acl_add_del_mac(&ar->g_acl, &acl)) { + wmi_ap_acl_mac_list(ar->arWmi, &acl); + } else { + A_PRINTF("ACL list error\n"); + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_AP_GET_ACL_LIST: + { + if (ar->arWmiReady == false) { + ret = -EIO; + } else if(copy_to_user((WMI_AP_ACL *)rq->ifr_data, &ar->g_acl, + sizeof(WMI_AP_ACL))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_COMMIT_CONFIG: + { + ret = ar6000_ap_mode_profile_commit(ar); + break; + } + case IEEE80211_IOCTL_GETWPAIE: + { + struct ieee80211req_wpaie wpaie; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&wpaie, userdata, sizeof(wpaie))) { + ret = -EFAULT; + } else if (ar6000_ap_mode_get_wpa_ie(ar, &wpaie)) { + ret = -EFAULT; + } else if(copy_to_user(userdata, &wpaie, sizeof(wpaie))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_CONN_INACT_TIME: + { + u32 period; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&period, userdata, sizeof(period))) { + ret = -EFAULT; + } else { + wmi_ap_conn_inact_time(ar->arWmi, period); + } + break; + } + case AR6000_XIOCTL_AP_PROT_SCAN_TIME: + { + WMI_AP_PROT_SCAN_TIME_CMD bgscan; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&bgscan, userdata, sizeof(bgscan))) { + ret = -EFAULT; + } else { + wmi_ap_bgscan_time(ar->arWmi, bgscan.period_min, bgscan.dwell_ms); + } + break; + } + case AR6000_XIOCTL_AP_SET_COUNTRY: + { + ret = ar6000_ioctl_set_country(dev, rq); + break; + } + case AR6000_XIOCTL_AP_SET_DTIM: + { + WMI_AP_SET_DTIM_CMD d; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&d, userdata, sizeof(d))) { + ret = -EFAULT; + } else { + if(d.dtim > 0 && d.dtim < 11) { + ar->ap_dtim_period = d.dtim; + wmi_ap_set_dtim(ar->arWmi, d.dtim); + ar->ap_profile_flag = 1; /* There is a change in profile */ + } else { + A_PRINTF("DTIM out of range. Valid range is [1-10]\n"); + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_WMI_TARGET_EVENT_REPORT: + { + WMI_SET_TARGET_EVENT_REPORT_CMD evtCfgCmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } + if (copy_from_user(&evtCfgCmd, userdata, + sizeof(evtCfgCmd))) { + ret = -EFAULT; + break; + } + ret = wmi_set_target_event_report_cmd(ar->arWmi, &evtCfgCmd); + break; + } + case AR6000_XIOCTL_AP_INTRA_BSS_COMM: + { + u8 intra=0; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&intra, userdata, sizeof(intra))) { + ret = -EFAULT; + } else { + ar->intra_bss = (intra?1:0); + } + break; + } + case AR6000_XIOCTL_DUMP_MODULE_DEBUG_INFO: + { + struct drv_debug_module_s moduleinfo; + + if (copy_from_user(&moduleinfo, userdata, sizeof(moduleinfo))) { + ret = -EFAULT; + break; + } + + a_dump_module_debug_info_by_name(moduleinfo.modulename); + ret = 0; + break; + } + case AR6000_XIOCTL_MODULE_DEBUG_SET_MASK: + { + struct drv_debug_module_s moduleinfo; + + if (copy_from_user(&moduleinfo, userdata, sizeof(moduleinfo))) { + ret = -EFAULT; + break; + } + + if (a_set_module_mask(moduleinfo.modulename, moduleinfo.mask)) { + ret = -EFAULT; + } + + break; + } + case AR6000_XIOCTL_MODULE_DEBUG_GET_MASK: + { + struct drv_debug_module_s moduleinfo; + + if (copy_from_user(&moduleinfo, userdata, sizeof(moduleinfo))) { + ret = -EFAULT; + break; + } + + if (a_get_module_mask(moduleinfo.modulename, &moduleinfo.mask)) { + ret = -EFAULT; + break; + } + + if (copy_to_user(userdata, &moduleinfo, sizeof(moduleinfo))) { + ret = -EFAULT; + break; + } + + break; + } +#ifdef ATH_AR6K_11N_SUPPORT + case AR6000_XIOCTL_DUMP_RCV_AGGR_STATS: + { + PACKET_LOG *copy_of_pkt_log; + + aggr_dump_stats(ar->aggr_cntxt, ©_of_pkt_log); + if (copy_to_user(rq->ifr_data, copy_of_pkt_log, sizeof(PACKET_LOG))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_SETUP_AGGR: + { + WMI_ADDBA_REQ_CMD cmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + ret = -EFAULT; + } else { + wmi_setup_aggr_cmd(ar->arWmi, cmd.tid); + } + } + break; + + case AR6000_XIOCTL_DELE_AGGR: + { + WMI_DELBA_REQ_CMD cmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + ret = -EFAULT; + } else { + wmi_delete_aggr_cmd(ar->arWmi, cmd.tid, cmd.is_sender_initiator); + } + } + break; + + case AR6000_XIOCTL_ALLOW_AGGR: + { + WMI_ALLOW_AGGR_CMD cmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + ret = -EFAULT; + } else { + wmi_allow_aggr_cmd(ar->arWmi, cmd.tx_allow_aggr, cmd.rx_allow_aggr); + } + } + break; + + case AR6000_XIOCTL_SET_HT_CAP: + { + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&htCap, userdata, + sizeof(htCap))) + { + ret = -EFAULT; + } else { + + if (wmi_set_ht_cap_cmd(ar->arWmi, &htCap) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_SET_HT_OP: + { + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&htOp, userdata, + sizeof(htOp))) + { + ret = -EFAULT; + } else { + + if (wmi_set_ht_op_cmd(ar->arWmi, htOp.sta_chan_width) != 0) + { + ret = -EIO; + } + } + break; + } +#endif + case AR6000_XIOCTL_ACL_DATA: + { + void *osbuf = NULL; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (ar6000_create_acl_data_osbuf(dev, (u8 *)userdata, &osbuf) != 0) { + ret = -EIO; + } else { + if (wmi_data_hdr_add(ar->arWmi, osbuf, DATA_MSGTYPE, 0, WMI_DATA_HDR_DATA_TYPE_ACL,0,NULL) != 0) { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("XIOCTL_ACL_DATA - wmi_data_hdr_add failed\n")); + } else { + /* Send data buffer over HTC */ + ar6000_acl_data_tx(osbuf, ar->arNetDev); + } + } + break; + } + case AR6000_XIOCTL_HCI_CMD: + { + char tmp_buf[512]; + s8 i; + WMI_HCI_CMD *cmd = (WMI_HCI_CMD *)tmp_buf; + u8 size; + + size = sizeof(cmd->cmd_buf_sz); + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(cmd, userdata, size)) { + ret = -EFAULT; + } else if(copy_from_user(cmd->buf, userdata + size, cmd->cmd_buf_sz)) { + ret = -EFAULT; + } else { + if (wmi_send_hci_cmd(ar->arWmi, cmd->buf, cmd->cmd_buf_sz) != 0) { + ret = -EIO; + }else if(loghci) { + A_PRINTF_LOG("HCI Command To PAL --> \n"); + for(i = 0; i < cmd->cmd_buf_sz; i++) { + A_PRINTF_LOG("0x%02x ",cmd->buf[i]); + if((i % 10) == 0) { + A_PRINTF_LOG("\n"); + } + } + A_PRINTF_LOG("\n"); + A_PRINTF_LOG("==================================\n"); + } + } + break; + } + case AR6000_XIOCTL_WLAN_CONN_PRECEDENCE: + { + WMI_SET_BT_WLAN_CONN_PRECEDENCE cmd; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&cmd, userdata, sizeof(cmd))) { + ret = -EFAULT; + } else { + if (cmd.precedence == BT_WLAN_CONN_PRECDENCE_WLAN || + cmd.precedence == BT_WLAN_CONN_PRECDENCE_PAL) { + if ( wmi_set_wlan_conn_precedence_cmd(ar->arWmi, cmd.precedence) != 0) { + ret = -EIO; + } + } else { + ret = -EINVAL; + } + } + break; + } + case AR6000_XIOCTL_AP_GET_STAT: + { + ret = ar6000_ioctl_get_ap_stats(dev, rq); + break; + } + case AR6000_XIOCTL_SET_TX_SELECT_RATES: + { + WMI_SET_TX_SELECT_RATES_CMD masks; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&masks, userdata, + sizeof(masks))) + { + ret = -EFAULT; + } else { + + if (wmi_set_tx_select_rates_cmd(ar->arWmi, masks.rateMasks) != 0) + { + ret = -EIO; + } + } + break; + } + case AR6000_XIOCTL_AP_GET_HIDDEN_SSID: + { + WMI_AP_HIDDEN_SSID_CMD ssid; + ssid.hidden_ssid = ar->ap_hidden_ssid; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if(copy_to_user((WMI_AP_HIDDEN_SSID_CMD *)rq->ifr_data, + &ssid, sizeof(WMI_AP_HIDDEN_SSID_CMD))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_GET_COUNTRY: + { + WMI_AP_SET_COUNTRY_CMD cty; + memcpy(cty.countryCode, ar->ap_country_code, 3); + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if(copy_to_user((WMI_AP_SET_COUNTRY_CMD *)rq->ifr_data, + &cty, sizeof(WMI_AP_SET_COUNTRY_CMD))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_GET_WMODE: + { + if (ar->arWmiReady == false) { + ret = -EIO; + } else if(copy_to_user((u8 *)rq->ifr_data, + &ar->ap_wmode, sizeof(u8))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_GET_DTIM: + { + WMI_AP_SET_DTIM_CMD dtim; + dtim.dtim = ar->ap_dtim_period; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if(copy_to_user((WMI_AP_SET_DTIM_CMD *)rq->ifr_data, + &dtim, sizeof(WMI_AP_SET_DTIM_CMD))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_GET_BINTVL: + { + WMI_BEACON_INT_CMD bi; + bi.beaconInterval = ar->ap_beacon_interval; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if(copy_to_user((WMI_BEACON_INT_CMD *)rq->ifr_data, + &bi, sizeof(WMI_BEACON_INT_CMD))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_AP_GET_RTS: + { + WMI_SET_RTS_CMD rts; + rts.threshold = ar->arRTS; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if(copy_to_user((WMI_SET_RTS_CMD *)rq->ifr_data, + &rts, sizeof(WMI_SET_RTS_CMD))) { + ret = -EFAULT; + } + break; + } + case AR6000_XIOCTL_FETCH_TARGET_REGS: + { + u32 targregs[AR6003_FETCH_TARG_REGS_COUNT]; + + if (ar->arTargetType == TARGET_TYPE_AR6003) { + ar6k_FetchTargetRegs(hifDevice, targregs); + if (copy_to_user((u32 *)rq->ifr_data, &targregs, sizeof(targregs))) + { + ret = -EFAULT; + } + } else { + ret = -EOPNOTSUPP; + } + break; + } + case AR6000_XIOCTL_AP_SET_11BG_RATESET: + { + WMI_AP_SET_11BG_RATESET_CMD rate; + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&rate, userdata, sizeof(rate))) { + ret = -EFAULT; + } else { + wmi_ap_set_rateset(ar->arWmi, rate.rateset); + } + break; + } + case AR6000_XIOCTL_GET_WLAN_SLEEP_STATE: + { + WMI_REPORT_SLEEP_STATE_EVENT wmiSleepEvent ; + + if (ar->arWlanState == WLAN_ENABLED) { + wmiSleepEvent.sleepState = WMI_REPORT_SLEEP_STATUS_IS_AWAKE; + } else { + wmiSleepEvent.sleepState = WMI_REPORT_SLEEP_STATUS_IS_DEEP_SLEEP; + } + rq->ifr_ifru.ifru_ivalue = ar->arWlanState; /* return value */ + + ar6000_send_event_to_app(ar, WMI_REPORT_SLEEP_STATE_EVENTID, (u8 *)&wmiSleepEvent, + sizeof(WMI_REPORT_SLEEP_STATE_EVENTID)); + break; + } +#ifdef CONFIG_PM + case AR6000_XIOCTL_SET_BT_HW_POWER_STATE: + { + unsigned int state; + if (get_user(state, (unsigned int *)userdata)) { + ret = -EFAULT; + break; + } + if (ar6000_set_bt_hw_state(ar, state)!= 0) { + ret = -EIO; + } + } + break; + case AR6000_XIOCTL_GET_BT_HW_POWER_STATE: + rq->ifr_ifru.ifru_ivalue = !ar->arBTOff; /* return value */ + break; +#endif + + case AR6000_XIOCTL_WMI_SET_TX_SGI_PARAM: + { + WMI_SET_TX_SGI_PARAM_CMD SGICmd; + + if (ar->arWmiReady == false) { + ret = -EIO; + } else if (copy_from_user(&SGICmd, userdata, + sizeof(SGICmd))){ + ret = -EFAULT; + } else{ + if (wmi_SGI_cmd(ar->arWmi, SGICmd.sgiMask, SGICmd.sgiPERThreshold) != 0) { + ret = -EIO; + } + + } + break; + } + + case AR6000_XIOCTL_ADD_AP_INTERFACE: +#ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT + { + char ap_ifname[IFNAMSIZ] = {0,}; + if (copy_from_user(ap_ifname, userdata, IFNAMSIZ)) { + ret = -EFAULT; + } else { + if (ar6000_add_ap_interface(ar, ap_ifname) != 0) { + ret = -EIO; + } + } + } +#else + ret = -EOPNOTSUPP; +#endif + break; + case AR6000_XIOCTL_REMOVE_AP_INTERFACE: +#ifdef CONFIG_AP_VIRTUAL_ADAPTER_SUPPORT + if (ar6000_remove_ap_interface(ar) != 0) { + ret = -EIO; + } +#else + ret = -EOPNOTSUPP; +#endif + break; + + case AR6000_XIOCTL_WMI_SET_EXCESS_TX_RETRY_THRES: + { + ret = ar6000_xioctl_set_excess_tx_retry_thres_cmd(dev, userdata); + break; + } + + default: + ret = -EOPNOTSUPP; + } + +ioctl_done: + rtnl_lock(); /* restore rtnl state */ + dev_put(dev); + + return ret; +} + +u8 mac_cmp_wild(u8 *mac, u8 *new_mac, u8 wild, u8 new_wild) +{ + u8 i; + + for(i=0;i=0;i--) + { + if(mac_cmp_wild(a->acl_mac[i], acl->mac, a->wildcard[i], + acl->wildcard)==0) + already_avail = i; + + if(!((1 << i) & a->index)) + free_slot = i; + } + + if(acl->action == ADD_MAC_ADDR) + { + /* Dont add mac if it is already available */ + if((already_avail >= 0) || (free_slot == -1)) + return 0; + + memcpy(a->acl_mac[free_slot], acl->mac, ATH_MAC_LEN); + a->index = a->index | (1 << free_slot); + acl->index = free_slot; + a->wildcard[free_slot] = acl->wildcard; + return 1; + } + else if(acl->action == DEL_MAC_ADDR) + { + if(acl->index > AP_ACL_SIZE) + return 0; + + if(!(a->index & (1 << acl->index))) + return 0; + + A_MEMZERO(a->acl_mac[acl->index],ATH_MAC_LEN); + a->index = a->index & ~(1 << acl->index); + a->wildcard[acl->index] = 0; + return 1; + } + + return 0; +} diff --git a/trunk/drivers/staging/ath6kl/os/linux/wireless_ext.c b/trunk/drivers/staging/ath6kl/os/linux/wireless_ext.c new file mode 100644 index 000000000000..4b779434956f --- /dev/null +++ b/trunk/drivers/staging/ath6kl/os/linux/wireless_ext.c @@ -0,0 +1,2723 @@ +//------------------------------------------------------------------------------ +// Copyright (c) 2004-2010 Atheros Communications Inc. +// All rights reserved. +// +// +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +// +// +// +// Author(s): ="Atheros" +//------------------------------------------------------------------------------ + +#include "ar6000_drv.h" + +#define IWE_STREAM_ADD_EVENT(p1, p2, p3, p4, p5) \ + iwe_stream_add_event((p1), (p2), (p3), (p4), (p5)) + +#define IWE_STREAM_ADD_POINT(p1, p2, p3, p4, p5) \ + iwe_stream_add_point((p1), (p2), (p3), (p4), (p5)) + +#define IWE_STREAM_ADD_VALUE(p1, p2, p3, p4, p5, p6) \ + iwe_stream_add_value((p1), (p2), (p3), (p4), (p5), (p6)) + +static void ar6000_set_quality(struct iw_quality *iq, s8 rssi); +extern unsigned int wmitimeout; +extern A_WAITQUEUE_HEAD arEvent; + +#if WIRELESS_EXT > 14 +/* + * Encode a WPA or RSN information element as a custom + * element using the hostap format. + */ +static u_int +encode_ie(void *buf, size_t bufsize, + const u_int8_t *ie, size_t ielen, + const char *leader, size_t leader_len) +{ + u_int8_t *p; + int i; + + if (bufsize < leader_len) + return 0; + p = buf; + memcpy(p, leader, leader_len); + bufsize -= leader_len; + p += leader_len; + for (i = 0; i < ielen && bufsize > 2; i++) + { + p += sprintf((char*)p, "%02x", ie[i]); + bufsize -= 2; + } + return (i == ielen ? p - (u_int8_t *)buf : 0); +} +#endif /* WIRELESS_EXT > 14 */ + +static u8 get_bss_phy_capability(bss_t *bss) +{ + u8 capability = 0; + struct ieee80211_common_ie *cie = &bss->ni_cie; +#define CHAN_IS_11A(x) (!((x >= 2412) && (x <= 2484))) + if (CHAN_IS_11A(cie->ie_chan)) { + if (cie->ie_htcap) { + capability = WMI_11NA_CAPABILITY; + } else { + capability = WMI_11A_CAPABILITY; + } + } else if ((cie->ie_erp) || (cie->ie_xrates)) { + if (cie->ie_htcap) { + capability = WMI_11NG_CAPABILITY; + } else { + capability = WMI_11G_CAPABILITY; + } + } + return capability; +} + +void +ar6000_scan_node(void *arg, bss_t *ni) +{ + struct iw_event iwe; +#if WIRELESS_EXT > 14 + char buf[256]; +#endif + struct ar_giwscan_param *param; + char *current_ev; + char *end_buf; + struct ieee80211_common_ie *cie; + char *current_val; + s32 j; + u32 rate_len, data_len = 0; + + param = (struct ar_giwscan_param *)arg; + + current_ev = param->current_ev; + end_buf = param->end_buf; + + cie = &ni->ni_cie; + + if ((end_buf - current_ev) > IW_EV_ADDR_LEN) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWAP; + iwe.u.ap_addr.sa_family = ARPHRD_ETHER; + memcpy(iwe.u.ap_addr.sa_data, ni->ni_macaddr, 6); + current_ev = IWE_STREAM_ADD_EVENT(param->info, current_ev, end_buf, + &iwe, IW_EV_ADDR_LEN); + } + param->bytes_needed += IW_EV_ADDR_LEN; + + data_len = cie->ie_ssid[1] + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWESSID; + iwe.u.data.flags = 1; + iwe.u.data.length = cie->ie_ssid[1]; + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, (char*)&cie->ie_ssid[2]); + } + param->bytes_needed += data_len; + + if (cie->ie_capInfo & (IEEE80211_CAPINFO_ESS|IEEE80211_CAPINFO_IBSS)) { + if ((end_buf - current_ev) > IW_EV_UINT_LEN) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWMODE; + iwe.u.mode = cie->ie_capInfo & IEEE80211_CAPINFO_ESS ? + IW_MODE_MASTER : IW_MODE_ADHOC; + current_ev = IWE_STREAM_ADD_EVENT(param->info, current_ev, end_buf, + &iwe, IW_EV_UINT_LEN); + } + param->bytes_needed += IW_EV_UINT_LEN; + } + + if ((end_buf - current_ev) > IW_EV_FREQ_LEN) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWFREQ; + iwe.u.freq.m = cie->ie_chan * 100000; + iwe.u.freq.e = 1; + current_ev = IWE_STREAM_ADD_EVENT(param->info, current_ev, end_buf, + &iwe, IW_EV_FREQ_LEN); + } + param->bytes_needed += IW_EV_FREQ_LEN; + + if ((end_buf - current_ev) > IW_EV_QUAL_LEN) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVQUAL; + ar6000_set_quality(&iwe.u.qual, ni->ni_snr); + current_ev = IWE_STREAM_ADD_EVENT(param->info, current_ev, end_buf, + &iwe, IW_EV_QUAL_LEN); + } + param->bytes_needed += IW_EV_QUAL_LEN; + + if ((end_buf - current_ev) > IW_EV_POINT_LEN) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWENCODE; + if (cie->ie_capInfo & IEEE80211_CAPINFO_PRIVACY) { + iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; + } else { + iwe.u.data.flags = IW_ENCODE_DISABLED; + } + iwe.u.data.length = 0; + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, ""); + } + param->bytes_needed += IW_EV_POINT_LEN; + + /* supported bit rate */ + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWRATE; + iwe.u.bitrate.fixed = 0; + iwe.u.bitrate.disabled = 0; + iwe.u.bitrate.value = 0; + current_val = current_ev + IW_EV_LCP_LEN; + param->bytes_needed += IW_EV_LCP_LEN; + + if (cie->ie_rates != NULL) { + rate_len = cie->ie_rates[1]; + data_len = (rate_len * (IW_EV_PARAM_LEN - IW_EV_LCP_LEN)); + if ((end_buf - current_ev) > data_len) + { + for (j = 0; j < rate_len; j++) { + unsigned char val; + val = cie->ie_rates[2 + j]; + iwe.u.bitrate.value = + (val >= 0x80)? ((val - 0x80) * 500000): (val * 500000); + current_val = IWE_STREAM_ADD_VALUE(param->info, current_ev, + current_val, end_buf, + &iwe, IW_EV_PARAM_LEN); + } + } + param->bytes_needed += data_len; + } + + if (cie->ie_xrates != NULL) { + rate_len = cie->ie_xrates[1]; + data_len = (rate_len * (IW_EV_PARAM_LEN - IW_EV_LCP_LEN)); + if ((end_buf - current_ev) > data_len) + { + for (j = 0; j < rate_len; j++) { + unsigned char val; + val = cie->ie_xrates[2 + j]; + iwe.u.bitrate.value = + (val >= 0x80)? ((val - 0x80) * 500000): (val * 500000); + current_val = IWE_STREAM_ADD_VALUE(param->info, current_ev, + current_val, end_buf, + &iwe, IW_EV_PARAM_LEN); + } + } + param->bytes_needed += data_len; + } + /* remove fixed header if no rates were added */ + if ((current_val - current_ev) > IW_EV_LCP_LEN) + current_ev = current_val; + +#if WIRELESS_EXT >= 18 + /* IE */ + if (cie->ie_wpa != NULL) { + data_len = cie->ie_wpa[1] + 2 + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVGENIE; + iwe.u.data.length = cie->ie_wpa[1] + 2; + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, (char*)cie->ie_wpa); + } + param->bytes_needed += data_len; + } + + if (cie->ie_rsn != NULL && cie->ie_rsn[0] == IEEE80211_ELEMID_RSN) { + data_len = cie->ie_rsn[1] + 2 + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVGENIE; + iwe.u.data.length = cie->ie_rsn[1] + 2; + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, (char*)cie->ie_rsn); + } + param->bytes_needed += data_len; + } + +#endif /* WIRELESS_EXT >= 18 */ + + if ((end_buf - current_ev) > IW_EV_CHAR_LEN) + { + /* protocol */ + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = SIOCGIWNAME; + switch (get_bss_phy_capability(ni)) { + case WMI_11A_CAPABILITY: + snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11a"); + break; + case WMI_11G_CAPABILITY: + snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11g"); + break; + case WMI_11NA_CAPABILITY: + snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11na"); + break; + case WMI_11NG_CAPABILITY: + snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11ng"); + break; + default: + snprintf(iwe.u.name, IFNAMSIZ, "IEEE 802.11b"); + break; + } + current_ev = IWE_STREAM_ADD_EVENT(param->info, current_ev, end_buf, + &iwe, IW_EV_CHAR_LEN); + } + param->bytes_needed += IW_EV_CHAR_LEN; + +#if WIRELESS_EXT > 14 + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = snprintf(buf, sizeof(buf), "bcn_int=%d", cie->ie_beaconInt); + data_len = iwe.u.data.length + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, buf); + } + param->bytes_needed += data_len; + +#if WIRELESS_EXT < 18 + if (cie->ie_wpa != NULL) { + static const char wpa_leader[] = "wpa_ie="; + data_len = (sizeof(wpa_leader) - 1) + ((cie->ie_wpa[1]+2) * 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = encode_ie(buf, sizeof(buf), cie->ie_wpa, + cie->ie_wpa[1]+2, + wpa_leader, sizeof(wpa_leader)-1); + + if (iwe.u.data.length != 0) { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, + end_buf, &iwe, buf); + } + } + param->bytes_needed += data_len; + } + + if (cie->ie_rsn != NULL && cie->ie_rsn[0] == IEEE80211_ELEMID_RSN) { + static const char rsn_leader[] = "rsn_ie="; + data_len = (sizeof(rsn_leader) - 1) + ((cie->ie_rsn[1]+2) * 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = encode_ie(buf, sizeof(buf), cie->ie_rsn, + cie->ie_rsn[1]+2, + rsn_leader, sizeof(rsn_leader)-1); + + if (iwe.u.data.length != 0) { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, + end_buf, &iwe, buf); + } + } + param->bytes_needed += data_len; + } +#endif /* WIRELESS_EXT < 18 */ + + if (cie->ie_wmm != NULL) { + static const char wmm_leader[] = "wmm_ie="; + data_len = (sizeof(wmm_leader) - 1) + ((cie->ie_wmm[1]+2) * 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = encode_ie(buf, sizeof(buf), cie->ie_wmm, + cie->ie_wmm[1]+2, + wmm_leader, sizeof(wmm_leader)-1); + if (iwe.u.data.length != 0) { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, + end_buf, &iwe, buf); + } + } + param->bytes_needed += data_len; + } + + if (cie->ie_ath != NULL) { + static const char ath_leader[] = "ath_ie="; + data_len = (sizeof(ath_leader) - 1) + ((cie->ie_ath[1]+2) * 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = encode_ie(buf, sizeof(buf), cie->ie_ath, + cie->ie_ath[1]+2, + ath_leader, sizeof(ath_leader)-1); + if (iwe.u.data.length != 0) { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, + end_buf, &iwe, buf); + } + } + param->bytes_needed += data_len; + } + +#ifdef WAPI_ENABLE + if (cie->ie_wapi != NULL) { + static const char wapi_leader[] = "wapi_ie="; + data_len = (sizeof(wapi_leader) - 1) + ((cie->ie_wapi[1] + 2) * 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; + iwe.u.data.length = encode_ie(buf, sizeof(buf), cie->ie_wapi, + cie->ie_wapi[1] + 2, + wapi_leader, sizeof(wapi_leader) - 1); + if (iwe.u.data.length != 0) { + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, + end_buf, &iwe, buf); + } + } + param->bytes_needed += data_len; + } +#endif /* WAPI_ENABLE */ + +#endif /* WIRELESS_EXT > 14 */ + +#if WIRELESS_EXT >= 18 + if (cie->ie_wsc != NULL) { + data_len = (cie->ie_wsc[1] + 2) + IW_EV_POINT_LEN; + if ((end_buf - current_ev) > data_len) + { + A_MEMZERO(&iwe, sizeof(iwe)); + iwe.cmd = IWEVGENIE; + iwe.u.data.length = cie->ie_wsc[1] + 2; + current_ev = IWE_STREAM_ADD_POINT(param->info, current_ev, end_buf, + &iwe, (char*)cie->ie_wsc); + } + param->bytes_needed += data_len; + } +#endif /* WIRELESS_EXT >= 18 */ + + param->current_ev = current_ev; +} + +int +ar6000_ioctl_giwscan(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + struct ar_giwscan_param param; + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ar->arWmiReady == false) { + return -EIO; + } + + param.current_ev = extra; + param.end_buf = extra + data->length; + param.bytes_needed = 0; + param.info = info; + + /* Translate data to WE format */ + wmi_iterate_nodes(ar->arWmi, ar6000_scan_node, ¶m); + + /* check if bytes needed is greater than bytes consumed */ + if (param.bytes_needed > (param.current_ev - extra)) + { + /* Request one byte more than needed, because when "data->length" equals bytes_needed, + it is not possible to add the last event data as all iwe_stream_add_xxxxx() functions + checks whether (cur_ptr + ev_len) < end_ptr, due to this one more retry would happen*/ + data->length = param.bytes_needed + 1; + + return -E2BIG; + } + + return 0; +} + +extern int reconnect_flag; +/* SIOCSIWESSID */ +static int +ar6000_ioctl_siwessid(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *ssid) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + int status; + u8 arNetworkType; + u8 prevMode = ar->arNetworkType; + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ar->arWmiReady == false) { + return -EIO; + } + +#if defined(WIRELESS_EXT) + if (WIRELESS_EXT >= 20) { + data->length += 1; + } +#endif + + /* + * iwconfig passes a null terminated string with length including this + * so we need to account for this + */ + if (data->flags && (!data->length || (data->length == 1) || + ((data->length - 1) > sizeof(ar->arSsid)))) + { + /* + * ssid is invalid + */ + return -EINVAL; + } + + if (ar->arNextMode == AP_NETWORK) { + /* SSID change for AP network - Will take effect on commit */ + if(memcmp(ar->arSsid,ssid,32) != 0) { + ar->arSsidLen = data->length - 1; + memcpy(ar->arSsid, ssid, ar->arSsidLen); + ar->ap_profile_flag = 1; /* There is a change in profile */ + } + return 0; + } else if(ar->arNetworkType == AP_NETWORK) { + u8 ctr; + struct sk_buff *skb; + + /* We are switching from AP to STA | IBSS mode, cleanup the AP state */ + for (ctr=0; ctr < AP_MAX_NUM_STA; ctr++) { + remove_sta(ar, ar->sta_list[ctr].mac, 0); + } + A_MUTEX_LOCK(&ar->mcastpsqLock); + while (!A_NETBUF_QUEUE_EMPTY(&ar->mcastpsq)) { + skb = A_NETBUF_DEQUEUE(&ar->mcastpsq); + A_NETBUF_FREE(skb); + } + A_MUTEX_UNLOCK(&ar->mcastpsqLock); + } + + /* Added for bug 25178, return an IOCTL error instead of target returning + Illegal parameter error when either the BSSID or channel is missing + and we cannot scan during connect. + */ + if (data->flags) { + if (ar->arSkipScan == true && + (ar->arChannelHint == 0 || + (!ar->arReqBssid[0] && !ar->arReqBssid[1] && !ar->arReqBssid[2] && + !ar->arReqBssid[3] && !ar->arReqBssid[4] && !ar->arReqBssid[5]))) + { + return -EINVAL; + } + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress || ar->arWlanState == WLAN_DISABLED) { + up(&ar->arSem); + return -EBUSY; + } + + if (ar->arTxPending[wmi_get_control_ep(ar->arWmi)]) { + /* + * sleep until the command queue drains + */ + wait_event_interruptible_timeout(arEvent, + ar->arTxPending[wmi_get_control_ep(ar->arWmi)] == 0, wmitimeout * HZ); + if (signal_pending(current)) { + return -EINTR; + } + } + + if (!data->flags) { + arNetworkType = ar->arNetworkType; +#ifdef ATH6K_CONFIG_CFG80211 + if (ar->arConnected) { +#endif /* ATH6K_CONFIG_CFG80211 */ + ar6000_init_profile_info(ar); +#ifdef ATH6K_CONFIG_CFG80211 + } +#endif /* ATH6K_CONFIG_CFG80211 */ + ar->arNetworkType = arNetworkType; + } + + /* Update the arNetworkType */ + ar->arNetworkType = ar->arNextMode; + + if ((prevMode != AP_NETWORK) && + ((ar->arSsidLen) || + ((ar->arSsidLen == 0) && (ar->arConnected || ar->arConnectPending)) || + (!data->flags))) + { + if ((!data->flags) || + (memcmp(ar->arSsid, ssid, ar->arSsidLen) != 0) || + (ar->arSsidLen != (data->length - 1))) + { + /* + * SSID set previously or essid off has been issued. + * + * Disconnect Command is issued in two cases after wmi is ready + * (1) ssid is different from the previous setting + * (2) essid off has been issued + * + */ + if (ar->arWmiReady == true) { + reconnect_flag = 0; + status = wmi_setPmkid_cmd(ar->arWmi, ar->arBssid, NULL, 0); + ar6000_disconnect(ar); + A_MEMZERO(ar->arSsid, sizeof(ar->arSsid)); + ar->arSsidLen = 0; + if (ar->arSkipScan == false) { + A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid)); + } + if (!data->flags) { + up(&ar->arSem); + return 0; + } + } else { + up(&ar->arSem); + } + } + else + { + /* + * SSID is same, so we assume profile hasn't changed. + * If the interface is up and wmi is ready, we issue + * a reconnect cmd. Issue a reconnect only we are already + * connected. + */ + if((ar->arConnected == true) && (ar->arWmiReady == true)) + { + reconnect_flag = true; + status = wmi_reconnect_cmd(ar->arWmi,ar->arReqBssid, + ar->arChannelHint); + up(&ar->arSem); + if (status) { + return -EIO; + } + return 0; + } + else{ + /* + * Dont return if connect is pending. + */ + if(!(ar->arConnectPending)) { + up(&ar->arSem); + return 0; + } + } + } + } + + ar->arSsidLen = data->length - 1; + memcpy(ar->arSsid, ssid, ar->arSsidLen); + + if (ar6000_connect_to_ap(ar)!= 0) { + up(&ar->arSem); + return -EIO; + }else{ + up(&ar->arSem); + } + return 0; +} + +/* SIOCGIWESSID */ +static int +ar6000_ioctl_giwessid(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *essid) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (!ar->arSsidLen) { + return -EINVAL; + } + + data->flags = 1; + data->length = ar->arSsidLen; + memcpy(essid, ar->arSsid, ar->arSsidLen); + + return 0; +} + + +void ar6000_install_static_wep_keys(struct ar6_softc *ar) +{ + u8 index; + u8 keyUsage; + + for (index = WMI_MIN_KEY_INDEX; index <= WMI_MAX_KEY_INDEX; index++) { + if (ar->arWepKeyList[index].arKeyLen) { + keyUsage = GROUP_USAGE; + if (index == ar->arDefTxKeyIndex) { + keyUsage |= TX_USAGE; + } + wmi_addKey_cmd(ar->arWmi, + index, + WEP_CRYPT, + keyUsage, + ar->arWepKeyList[index].arKeyLen, + NULL, + ar->arWepKeyList[index].arKey, KEY_OP_INIT_VAL, NULL, + NO_SYNC_WMIFLAG); + } + } +} + +/* + * SIOCSIWRATE + */ +int +ar6000_ioctl_siwrate(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + u32 kbps; + s8 rate_idx; + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (rrq->fixed) { + kbps = rrq->value / 1000; /* rrq->value is in bps */ + } else { + kbps = -1; /* -1 indicates auto rate */ + } + if(kbps != -1 && wmi_validate_bitrate(ar->arWmi, kbps, &rate_idx) != 0) + { + AR_DEBUG_PRINTF(ATH_DEBUG_ERR,("BitRate is not Valid %d\n", kbps)); + return -EINVAL; + } + ar->arBitRate = kbps; + if(ar->arWmiReady == true) + { + if (wmi_set_bitrate_cmd(ar->arWmi, kbps, -1, -1) != 0) { + return -EINVAL; + } + } + return 0; +} + +/* + * SIOCGIWRATE + */ +int +ar6000_ioctl_giwrate(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + int ret = 0; + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if ((ar->arNextMode != AP_NETWORK && !ar->arConnected) || ar->arWmiReady == false) { + rrq->value = 1000 * 1000; + return 0; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress || ar->arWlanState == WLAN_DISABLED) { + up(&ar->arSem); + return -EBUSY; + } + + ar->arBitRate = 0xFFFF; + if (wmi_get_bitrate_cmd(ar->arWmi) != 0) { + up(&ar->arSem); + return -EIO; + } + wait_event_interruptible_timeout(arEvent, ar->arBitRate != 0xFFFF, wmitimeout * HZ); + if (signal_pending(current)) { + ret = -EINTR; + } + /* If the interface is down or wmi is not ready or the target is not + connected - return the value stored in the device structure */ + if (!ret) { + if (ar->arBitRate == -1) { + rrq->fixed = true; + rrq->value = 0; + } else { + rrq->value = ar->arBitRate * 1000; + } + } + + up(&ar->arSem); + + return ret; +} + +/* + * SIOCSIWTXPOW + */ +static int +ar6000_ioctl_siwtxpow(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + u8 dbM; + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (rrq->disabled) { + return -EOPNOTSUPP; + } + + if (rrq->fixed) { + if (rrq->flags != IW_TXPOW_DBM) { + return -EOPNOTSUPP; + } + ar->arTxPwr= dbM = rrq->value; + ar->arTxPwrSet = true; + } else { + ar->arTxPwr = dbM = 0; + ar->arTxPwrSet = false; + } + if(ar->arWmiReady == true) + { + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_TX,("Set tx pwr cmd %d dbM\n", dbM)); + wmi_set_txPwr_cmd(ar->arWmi, dbM); + } + return 0; +} + +/* + * SIOCGIWTXPOW + */ +int +ar6000_ioctl_giwtxpow(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + int ret = 0; + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + return -EBUSY; + } + + if((ar->arWmiReady == true) && (ar->arConnected == true)) + { + ar->arTxPwr = 0; + + if (wmi_get_txPwr_cmd(ar->arWmi) != 0) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arEvent, ar->arTxPwr != 0, wmitimeout * HZ); + + if (signal_pending(current)) { + ret = -EINTR; + } + } + /* If the interace is down or wmi is not ready or target is not connected + then return value stored in the device structure */ + + if (!ret) { + if (ar->arTxPwrSet == true) { + rrq->fixed = true; + } + rrq->value = ar->arTxPwr; + rrq->flags = IW_TXPOW_DBM; + // + // IWLIST need this flag to get TxPower + // + rrq->disabled = 0; + } + + up(&ar->arSem); + + return ret; +} + +/* + * SIOCSIWRETRY + * since iwconfig only provides us with one max retry value, we use it + * to apply to data frames of the BE traffic class. + */ +static int +ar6000_ioctl_siwretry(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (rrq->disabled) { + return -EOPNOTSUPP; + } + + if ((rrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT) { + return -EOPNOTSUPP; + } + + if ( !(rrq->value >= WMI_MIN_RETRIES) || !(rrq->value <= WMI_MAX_RETRIES)) { + return - EINVAL; + } + if(ar->arWmiReady == true) + { + if (wmi_set_retry_limits_cmd(ar->arWmi, DATA_FRAMETYPE, WMM_AC_BE, + rrq->value, 0) != 0){ + return -EINVAL; + } + } + ar->arMaxRetries = rrq->value; + return 0; +} + +/* + * SIOCGIWRETRY + */ +static int +ar6000_ioctl_giwretry(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *rrq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + rrq->disabled = 0; + switch (rrq->flags & IW_RETRY_TYPE) { + case IW_RETRY_LIFETIME: + return -EOPNOTSUPP; + break; + case IW_RETRY_LIMIT: + rrq->flags = IW_RETRY_LIMIT; + switch (rrq->flags & IW_RETRY_MODIFIER) { + case IW_RETRY_MIN: + rrq->flags |= IW_RETRY_MIN; + rrq->value = WMI_MIN_RETRIES; + break; + case IW_RETRY_MAX: + rrq->flags |= IW_RETRY_MAX; + rrq->value = ar->arMaxRetries; + break; + } + break; + } + return 0; +} + +/* + * SIOCSIWENCODE + */ +static int +ar6000_ioctl_siwencode(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *keybuf) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + int index; + s32 auth = 0; + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if(ar->arNextMode != AP_NETWORK) { + /* + * Static WEP Keys should be configured before setting the SSID + */ + if (ar->arSsid[0] && erq->length) { + return -EIO; + } + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + index = erq->flags & IW_ENCODE_INDEX; + + if (index && (((index - 1) < WMI_MIN_KEY_INDEX) || + ((index - 1) > WMI_MAX_KEY_INDEX))) + { + return -EIO; + } + + if (erq->flags & IW_ENCODE_DISABLED) { + /* + * Encryption disabled + */ + if (index) { + /* + * If key index was specified then clear the specified key + */ + index--; + A_MEMZERO(ar->arWepKeyList[index].arKey, + sizeof(ar->arWepKeyList[index].arKey)); + ar->arWepKeyList[index].arKeyLen = 0; + } + ar->arDot11AuthMode = OPEN_AUTH; + ar->arPairwiseCrypto = NONE_CRYPT; + ar->arGroupCrypto = NONE_CRYPT; + ar->arAuthMode = NONE_AUTH; + } else { + /* + * Enabling WEP encryption + */ + if (index) { + index--; /* keyindex is off base 1 in iwconfig */ + } + + if (erq->flags & IW_ENCODE_OPEN) { + auth |= OPEN_AUTH; + ar->arDefTxKeyIndex = index; + } + if (erq->flags & IW_ENCODE_RESTRICTED) { + auth |= SHARED_AUTH; + } + + if (!auth) { + auth = OPEN_AUTH; + } + + if (erq->length) { + if (!IEEE80211_IS_VALID_WEP_CIPHER_LEN(erq->length)) { + return -EIO; + } + + A_MEMZERO(ar->arWepKeyList[index].arKey, + sizeof(ar->arWepKeyList[index].arKey)); + memcpy(ar->arWepKeyList[index].arKey, keybuf, erq->length); + ar->arWepKeyList[index].arKeyLen = erq->length; + ar->arDot11AuthMode = auth; + } else { + if (ar->arWepKeyList[index].arKeyLen == 0) { + return -EIO; + } + ar->arDefTxKeyIndex = index; + + if(ar->arSsidLen && ar->arWepKeyList[index].arKeyLen) { + wmi_addKey_cmd(ar->arWmi, + index, + WEP_CRYPT, + GROUP_USAGE | TX_USAGE, + ar->arWepKeyList[index].arKeyLen, + NULL, + ar->arWepKeyList[index].arKey, KEY_OP_INIT_VAL, NULL, + NO_SYNC_WMIFLAG); + } + } + + ar->arPairwiseCrypto = WEP_CRYPT; + ar->arGroupCrypto = WEP_CRYPT; + ar->arAuthMode = NONE_AUTH; + } + + if(ar->arNextMode != AP_NETWORK) { + /* + * profile has changed. Erase ssid to signal change + */ + A_MEMZERO(ar->arSsid, sizeof(ar->arSsid)); + ar->arSsidLen = 0; + } + ar->ap_profile_flag = 1; /* There is a change in profile */ + return 0; +} + +static int +ar6000_ioctl_giwencode(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *key) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + u8 keyIndex; + struct ar_wep_key *wk; + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ar->arPairwiseCrypto == NONE_CRYPT) { + erq->length = 0; + erq->flags = IW_ENCODE_DISABLED; + } else { + if (ar->arPairwiseCrypto == WEP_CRYPT) { + /* get the keyIndex */ + keyIndex = erq->flags & IW_ENCODE_INDEX; + if (0 == keyIndex) { + keyIndex = ar->arDefTxKeyIndex; + } else if ((keyIndex - 1 < WMI_MIN_KEY_INDEX) || + (keyIndex - 1 > WMI_MAX_KEY_INDEX)) + { + keyIndex = WMI_MIN_KEY_INDEX; + } else { + keyIndex--; + } + erq->flags = keyIndex + 1; + erq->flags &= ~IW_ENCODE_DISABLED; + wk = &ar->arWepKeyList[keyIndex]; + if (erq->length > wk->arKeyLen) { + erq->length = wk->arKeyLen; + } + if (wk->arKeyLen) { + memcpy(key, wk->arKey, erq->length); + } + } else { + erq->flags &= ~IW_ENCODE_DISABLED; + if (ar->user_saved_keys.keyOk) { + erq->length = ar->user_saved_keys.ucast_ik.ik_keylen; + if (erq->length) { + memcpy(key, ar->user_saved_keys.ucast_ik.ik_keydata, erq->length); + } + } else { + erq->length = 1; // not really printing any key but let iwconfig know enc is on + } + } + + if (ar->arDot11AuthMode & OPEN_AUTH) { + erq->flags |= IW_ENCODE_OPEN; + } + if (ar->arDot11AuthMode & SHARED_AUTH) { + erq->flags |= IW_ENCODE_RESTRICTED; + } + } + + return 0; +} + +#if WIRELESS_EXT >= 18 +/* + * SIOCSIWGENIE + */ +static int +ar6000_ioctl_siwgenie(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + +#ifdef WAPI_ENABLE + u8 *ie = erq->pointer; + u8 ie_type = ie[0]; + u16 ie_length = erq->length; + u8 wapi_ie[128]; +#endif + + if (ar->arWmiReady == false) { + return -EIO; + } +#ifdef WAPI_ENABLE + if (ie_type == IEEE80211_ELEMID_WAPI) { + if (ie_length > 0) { + if (copy_from_user(wapi_ie, ie, ie_length)) { + return -EIO; + } + } + wmi_set_appie_cmd(ar->arWmi, WMI_FRAME_ASSOC_REQ, ie_length, wapi_ie); + } else if (ie_length == 0) { + wmi_set_appie_cmd(ar->arWmi, WMI_FRAME_ASSOC_REQ, ie_length, wapi_ie); + } +#endif + return 0; +} + + +/* + * SIOCGIWGENIE + */ +static int +ar6000_ioctl_giwgenie(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (ar->arWmiReady == false) { + return -EIO; + } + erq->length = 0; + erq->flags = 0; + + return 0; +} + +/* + * SIOCSIWAUTH + */ +static int +ar6000_ioctl_siwauth(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *data, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + bool profChanged; + u16 param; + s32 ret; + s32 value; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + param = data->flags & IW_AUTH_INDEX; + value = data->value; + profChanged = true; + ret = 0; + + switch (param) { + case IW_AUTH_WPA_VERSION: + if (value & IW_AUTH_WPA_VERSION_DISABLED) { + ar->arAuthMode = NONE_AUTH; + } else if (value & IW_AUTH_WPA_VERSION_WPA) { + ar->arAuthMode = WPA_AUTH; + } else if (value & IW_AUTH_WPA_VERSION_WPA2) { + ar->arAuthMode = WPA2_AUTH; + } else { + ret = -1; + profChanged = false; + } + break; + case IW_AUTH_CIPHER_PAIRWISE: + if (value & IW_AUTH_CIPHER_NONE) { + ar->arPairwiseCrypto = NONE_CRYPT; + ar->arPairwiseCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_WEP40) { + ar->arPairwiseCrypto = WEP_CRYPT; + ar->arPairwiseCryptoLen = 5; + } else if (value & IW_AUTH_CIPHER_TKIP) { + ar->arPairwiseCrypto = TKIP_CRYPT; + ar->arPairwiseCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_CCMP) { + ar->arPairwiseCrypto = AES_CRYPT; + ar->arPairwiseCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_WEP104) { + ar->arPairwiseCrypto = WEP_CRYPT; + ar->arPairwiseCryptoLen = 13; + } else { + ret = -1; + profChanged = false; + } + break; + case IW_AUTH_CIPHER_GROUP: + if (value & IW_AUTH_CIPHER_NONE) { + ar->arGroupCrypto = NONE_CRYPT; + ar->arGroupCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_WEP40) { + ar->arGroupCrypto = WEP_CRYPT; + ar->arGroupCryptoLen = 5; + } else if (value & IW_AUTH_CIPHER_TKIP) { + ar->arGroupCrypto = TKIP_CRYPT; + ar->arGroupCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_CCMP) { + ar->arGroupCrypto = AES_CRYPT; + ar->arGroupCryptoLen = 0; + } else if (value & IW_AUTH_CIPHER_WEP104) { + ar->arGroupCrypto = WEP_CRYPT; + ar->arGroupCryptoLen = 13; + } else { + ret = -1; + profChanged = false; + } + break; + case IW_AUTH_KEY_MGMT: + if (value & IW_AUTH_KEY_MGMT_PSK) { + if (WPA_AUTH == ar->arAuthMode) { + ar->arAuthMode = WPA_PSK_AUTH; + } else if (WPA2_AUTH == ar->arAuthMode) { + ar->arAuthMode = WPA2_PSK_AUTH; + } else { + ret = -1; + } + } else if (!(value & IW_AUTH_KEY_MGMT_802_1X)) { + ar->arAuthMode = NONE_AUTH; + } + break; + case IW_AUTH_TKIP_COUNTERMEASURES: + wmi_set_tkip_countermeasures_cmd(ar->arWmi, value); + profChanged = false; + break; + case IW_AUTH_DROP_UNENCRYPTED: + profChanged = false; + break; + case IW_AUTH_80211_AUTH_ALG: + ar->arDot11AuthMode = 0; + if (value & IW_AUTH_ALG_OPEN_SYSTEM) { + ar->arDot11AuthMode |= OPEN_AUTH; + } + if (value & IW_AUTH_ALG_SHARED_KEY) { + ar->arDot11AuthMode |= SHARED_AUTH; + } + if (value & IW_AUTH_ALG_LEAP) { + ar->arDot11AuthMode = LEAP_AUTH; + } + if(ar->arDot11AuthMode == 0) { + ret = -1; + profChanged = false; + } + break; + case IW_AUTH_WPA_ENABLED: + if (!value) { + ar->arAuthMode = NONE_AUTH; + /* when the supplicant is stopped, it calls this + * handler with value=0. The followings need to be + * reset if the STA were to connect again + * without security + */ + ar->arDot11AuthMode = OPEN_AUTH; + ar->arPairwiseCrypto = NONE_CRYPT; + ar->arPairwiseCryptoLen = 0; + ar->arGroupCrypto = NONE_CRYPT; + ar->arGroupCryptoLen = 0; + } + break; + case IW_AUTH_RX_UNENCRYPTED_EAPOL: + profChanged = false; + break; + case IW_AUTH_ROAMING_CONTROL: + profChanged = false; + break; + case IW_AUTH_PRIVACY_INVOKED: + if (!value) { + ar->arPairwiseCrypto = NONE_CRYPT; + ar->arPairwiseCryptoLen = 0; + ar->arGroupCrypto = NONE_CRYPT; + ar->arGroupCryptoLen = 0; + } + break; +#ifdef WAPI_ENABLE + case IW_AUTH_WAPI_ENABLED: + ar->arWapiEnable = value; + break; +#endif + default: + ret = -1; + profChanged = false; + break; + } + + if (profChanged == true) { + /* + * profile has changed. Erase ssid to signal change + */ + A_MEMZERO(ar->arSsid, sizeof(ar->arSsid)); + ar->arSsidLen = 0; + } + + return ret; +} + + +/* + * SIOCGIWAUTH + */ +static int +ar6000_ioctl_giwauth(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *data, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + u16 param; + s32 ret; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + param = data->flags & IW_AUTH_INDEX; + ret = 0; + data->value = 0; + + + switch (param) { + case IW_AUTH_WPA_VERSION: + if (ar->arAuthMode == NONE_AUTH) { + data->value |= IW_AUTH_WPA_VERSION_DISABLED; + } else if (ar->arAuthMode == WPA_AUTH) { + data->value |= IW_AUTH_WPA_VERSION_WPA; + } else if (ar->arAuthMode == WPA2_AUTH) { + data->value |= IW_AUTH_WPA_VERSION_WPA2; + } else { + ret = -1; + } + break; + case IW_AUTH_CIPHER_PAIRWISE: + if (ar->arPairwiseCrypto == NONE_CRYPT) { + data->value |= IW_AUTH_CIPHER_NONE; + } else if (ar->arPairwiseCrypto == WEP_CRYPT) { + if (ar->arPairwiseCryptoLen == 13) { + data->value |= IW_AUTH_CIPHER_WEP104; + } else { + data->value |= IW_AUTH_CIPHER_WEP40; + } + } else if (ar->arPairwiseCrypto == TKIP_CRYPT) { + data->value |= IW_AUTH_CIPHER_TKIP; + } else if (ar->arPairwiseCrypto == AES_CRYPT) { + data->value |= IW_AUTH_CIPHER_CCMP; + } else { + ret = -1; + } + break; + case IW_AUTH_CIPHER_GROUP: + if (ar->arGroupCrypto == NONE_CRYPT) { + data->value |= IW_AUTH_CIPHER_NONE; + } else if (ar->arGroupCrypto == WEP_CRYPT) { + if (ar->arGroupCryptoLen == 13) { + data->value |= IW_AUTH_CIPHER_WEP104; + } else { + data->value |= IW_AUTH_CIPHER_WEP40; + } + } else if (ar->arGroupCrypto == TKIP_CRYPT) { + data->value |= IW_AUTH_CIPHER_TKIP; + } else if (ar->arGroupCrypto == AES_CRYPT) { + data->value |= IW_AUTH_CIPHER_CCMP; + } else { + ret = -1; + } + break; + case IW_AUTH_KEY_MGMT: + if ((ar->arAuthMode == WPA_PSK_AUTH) || + (ar->arAuthMode == WPA2_PSK_AUTH)) { + data->value |= IW_AUTH_KEY_MGMT_PSK; + } else if ((ar->arAuthMode == WPA_AUTH) || + (ar->arAuthMode == WPA2_AUTH)) { + data->value |= IW_AUTH_KEY_MGMT_802_1X; + } + break; + case IW_AUTH_TKIP_COUNTERMEASURES: + // TODO. Save countermeassure enable/disable + data->value = 0; + break; + case IW_AUTH_DROP_UNENCRYPTED: + break; + case IW_AUTH_80211_AUTH_ALG: + if (ar->arDot11AuthMode == OPEN_AUTH) { + data->value |= IW_AUTH_ALG_OPEN_SYSTEM; + } else if (ar->arDot11AuthMode == SHARED_AUTH) { + data->value |= IW_AUTH_ALG_SHARED_KEY; + } else if (ar->arDot11AuthMode == LEAP_AUTH) { + data->value |= IW_AUTH_ALG_LEAP; + } else { + ret = -1; + } + break; + case IW_AUTH_WPA_ENABLED: + if (ar->arAuthMode == NONE_AUTH) { + data->value = 0; + } else { + data->value = 1; + } + break; + case IW_AUTH_RX_UNENCRYPTED_EAPOL: + break; + case IW_AUTH_ROAMING_CONTROL: + break; + case IW_AUTH_PRIVACY_INVOKED: + if (ar->arPairwiseCrypto == NONE_CRYPT) { + data->value = 0; + } else { + data->value = 1; + } + break; +#ifdef WAPI_ENABLE + case IW_AUTH_WAPI_ENABLED: + data->value = ar->arWapiEnable; + break; +#endif + default: + ret = -1; + break; + } + + return 0; +} + +/* + * SIOCSIWPMKSA + */ +static int +ar6000_ioctl_siwpmksa(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + s32 ret; + int status; + struct iw_pmksa *pmksa; + + pmksa = (struct iw_pmksa *)extra; + + if (ar->arWmiReady == false) { + return -EIO; + } + + ret = 0; + status = 0; + + switch (pmksa->cmd) { + case IW_PMKSA_ADD: + status = wmi_setPmkid_cmd(ar->arWmi, (u8 *)pmksa->bssid.sa_data, pmksa->pmkid, true); + break; + case IW_PMKSA_REMOVE: + status = wmi_setPmkid_cmd(ar->arWmi, (u8 *)pmksa->bssid.sa_data, pmksa->pmkid, false); + break; + case IW_PMKSA_FLUSH: + if (ar->arConnected == true) { + status = wmi_setPmkid_cmd(ar->arWmi, ar->arBssid, NULL, 0); + } + break; + default: + ret=-1; + break; + } + if (status) { + ret = -1; + } + + return ret; +} + +#ifdef WAPI_ENABLE + +#define PN_INIT 0x5c365c36 + +static int ar6000_set_wapi_key(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; + KEY_USAGE keyUsage = 0; + s32 keyLen; + u8 *keyData; + s32 index; + u32 *PN; + s32 i; + int status; + u8 wapiKeyRsc[16]; + CRYPTO_TYPE keyType = WAPI_CRYPT; + const u8 broadcastMac[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; + + index = erq->flags & IW_ENCODE_INDEX; + if (index && (((index - 1) < WMI_MIN_KEY_INDEX) || + ((index - 1) > WMI_MAX_KEY_INDEX))) { + return -EIO; + } + + index--; + if (index < 0 || index > 4) { + return -EIO; + } + keyData = (u8 *)(ext + 1); + keyLen = erq->length - sizeof(struct iw_encode_ext); + memcpy(wapiKeyRsc, ext->tx_seq, sizeof(wapiKeyRsc)); + + if (memcmp(ext->addr.sa_data, broadcastMac, sizeof(broadcastMac)) == 0) { + keyUsage |= GROUP_USAGE; + PN = (u32 *)wapiKeyRsc; + for (i = 0; i < 4; i++) { + PN[i] = PN_INIT; + } + } else { + keyUsage |= PAIRWISE_USAGE; + } + status = wmi_addKey_cmd(ar->arWmi, + index, + keyType, + keyUsage, + keyLen, + wapiKeyRsc, + keyData, + KEY_OP_INIT_WAPIPN, + NULL, + SYNC_BEFORE_WMIFLAG); + if (0 != status) { + return -EIO; + } + return 0; +} + +#endif + +/* + * SIOCSIWENCODEEXT + */ +static int +ar6000_ioctl_siwencodeext(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + s32 index; + struct iw_encode_ext *ext; + KEY_USAGE keyUsage; + s32 keyLen; + u8 *keyData; + u8 keyRsc[8]; + int status; + CRYPTO_TYPE keyType; +#ifdef USER_KEYS + struct ieee80211req_key ik; +#endif /* USER_KEYS */ + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + +#ifdef USER_KEYS + ar->user_saved_keys.keyOk = false; +#endif /* USER_KEYS */ + + index = erq->flags & IW_ENCODE_INDEX; + + if (index && (((index - 1) < WMI_MIN_KEY_INDEX) || + ((index - 1) > WMI_MAX_KEY_INDEX))) + { + return -EIO; + } + + ext = (struct iw_encode_ext *)extra; + if (erq->flags & IW_ENCODE_DISABLED) { + /* + * Encryption disabled + */ + if (index) { + /* + * If key index was specified then clear the specified key + */ + index--; + A_MEMZERO(ar->arWepKeyList[index].arKey, + sizeof(ar->arWepKeyList[index].arKey)); + ar->arWepKeyList[index].arKeyLen = 0; + } + } else { + /* + * Enabling WEP encryption + */ + if (index) { + index--; /* keyindex is off base 1 in iwconfig */ + } + + keyUsage = 0; + keyLen = erq->length - sizeof(struct iw_encode_ext); + + if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { + keyUsage = TX_USAGE; + ar->arDefTxKeyIndex = index; + // Just setting the key index + if (keyLen == 0) { + return 0; + } + } + + if (keyLen <= 0) { + return -EIO; + } + + /* key follows iw_encode_ext */ + keyData = (u8 *)(ext + 1); + + switch (ext->alg) { + case IW_ENCODE_ALG_WEP: + keyType = WEP_CRYPT; +#ifdef USER_KEYS + ik.ik_type = IEEE80211_CIPHER_WEP; +#endif /* USER_KEYS */ + if (!IEEE80211_IS_VALID_WEP_CIPHER_LEN(keyLen)) { + return -EIO; + } + + /* Check whether it is static wep. */ + if (!ar->arConnected) { + A_MEMZERO(ar->arWepKeyList[index].arKey, + sizeof(ar->arWepKeyList[index].arKey)); + memcpy(ar->arWepKeyList[index].arKey, keyData, keyLen); + ar->arWepKeyList[index].arKeyLen = keyLen; + + return 0; + } + break; + case IW_ENCODE_ALG_TKIP: + keyType = TKIP_CRYPT; +#ifdef USER_KEYS + ik.ik_type = IEEE80211_CIPHER_TKIP; +#endif /* USER_KEYS */ + break; + case IW_ENCODE_ALG_CCMP: + keyType = AES_CRYPT; +#ifdef USER_KEYS + ik.ik_type = IEEE80211_CIPHER_AES_CCM; +#endif /* USER_KEYS */ + break; +#ifdef WAPI_ENABLE + case IW_ENCODE_ALG_SM4: + if (ar->arWapiEnable) { + return ar6000_set_wapi_key(dev, info, erq, extra); + } else { + return -EIO; + } +#endif + case IW_ENCODE_ALG_PMK: + ar->arConnectCtrlFlags |= CONNECT_DO_WPA_OFFLOAD; + return wmi_set_pmk_cmd(ar->arWmi, keyData); + default: + return -EIO; + } + + + if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { + keyUsage |= GROUP_USAGE; + } else { + keyUsage |= PAIRWISE_USAGE; + } + + if (ext->ext_flags & IW_ENCODE_EXT_RX_SEQ_VALID) { + memcpy(keyRsc, ext->rx_seq, sizeof(keyRsc)); + } else { + A_MEMZERO(keyRsc, sizeof(keyRsc)); + } + + if (((WPA_PSK_AUTH == ar->arAuthMode) || (WPA2_PSK_AUTH == ar->arAuthMode)) && + (GROUP_USAGE & keyUsage)) + { + A_UNTIMEOUT(&ar->disconnect_timer); + } + + status = wmi_addKey_cmd(ar->arWmi, index, keyType, keyUsage, + keyLen, keyRsc, + keyData, KEY_OP_INIT_VAL, + (u8 *)ext->addr.sa_data, + SYNC_BOTH_WMIFLAG); + if (status) { + return -EIO; + } + +#ifdef USER_KEYS + ik.ik_keyix = index; + ik.ik_keylen = keyLen; + memcpy(ik.ik_keydata, keyData, keyLen); + memcpy(&ik.ik_keyrsc, keyRsc, sizeof(keyRsc)); + memcpy(ik.ik_macaddr, ext->addr.sa_data, ETH_ALEN); + if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { + memcpy(&ar->user_saved_keys.bcast_ik, &ik, + sizeof(struct ieee80211req_key)); + } else { + memcpy(&ar->user_saved_keys.ucast_ik, &ik, + sizeof(struct ieee80211req_key)); + } + ar->user_saved_keys.keyOk = true; +#endif /* USER_KEYS */ + } + + + return 0; +} + +/* + * SIOCGIWENCODEEXT + */ +static int +ar6000_ioctl_giwencodeext(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *erq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ar->arPairwiseCrypto == NONE_CRYPT) { + erq->length = 0; + erq->flags = IW_ENCODE_DISABLED; + } else { + erq->length = 0; + } + + return 0; +} +#endif // WIRELESS_EXT >= 18 + +#if WIRELESS_EXT > 20 +static int ar6000_ioctl_siwpower(struct net_device *dev, + struct iw_request_info *info, + union iwreq_data *wrqu, char *extra) +{ +#ifndef ATH6K_CONFIG_OTA_MODE + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_POWER_MODE power_mode; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (wrqu->power.disabled) + power_mode = MAX_PERF_POWER; + else + power_mode = REC_POWER; + + if (wmi_powermode_cmd(ar->arWmi, power_mode) < 0) + return -EIO; +#endif + return 0; +} + +static int ar6000_ioctl_giwpower(struct net_device *dev, + struct iw_request_info *info, + union iwreq_data *wrqu, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + WMI_POWER_MODE power_mode; + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + power_mode = wmi_get_power_mode_cmd(ar->arWmi); + + if (power_mode == MAX_PERF_POWER) + wrqu->power.disabled = 1; + else + wrqu->power.disabled = 0; + + return 0; +} +#endif // WIRELESS_EXT > 20 + +/* + * SIOCGIWNAME + */ +int +ar6000_ioctl_giwname(struct net_device *dev, + struct iw_request_info *info, + char *name, char *extra) +{ + u8 capability; + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + capability = ar->arPhyCapability; + if(ar->arNetworkType == INFRA_NETWORK && ar->arConnected) { + bss_t *bss = wmi_find_node(ar->arWmi, ar->arBssid); + if (bss) { + capability = get_bss_phy_capability(bss); + wmi_node_return(ar->arWmi, bss); + } + } + switch (capability) { + case (WMI_11A_CAPABILITY): + strncpy(name, "AR6000 802.11a", IFNAMSIZ); + break; + case (WMI_11G_CAPABILITY): + strncpy(name, "AR6000 802.11g", IFNAMSIZ); + break; + case (WMI_11AG_CAPABILITY): + strncpy(name, "AR6000 802.11ag", IFNAMSIZ); + break; + case (WMI_11NA_CAPABILITY): + strncpy(name, "AR6000 802.11na", IFNAMSIZ); + break; + case (WMI_11NG_CAPABILITY): + strncpy(name, "AR6000 802.11ng", IFNAMSIZ); + break; + case (WMI_11NAG_CAPABILITY): + strncpy(name, "AR6000 802.11nag", IFNAMSIZ); + break; + default: + strncpy(name, "AR6000 802.11b", IFNAMSIZ); + break; + } + + return 0; +} + +/* + * SIOCSIWFREQ + */ +int +ar6000_ioctl_siwfreq(struct net_device *dev, + struct iw_request_info *info, + struct iw_freq *freq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + /* + * We support limiting the channels via wmiconfig. + * + * We use this command to configure the channel hint for the connect cmd + * so it is possible the target will end up connecting to a different + * channel. + */ + if (freq->e > 1) { + return -EINVAL; + } else if (freq->e == 1) { + ar->arChannelHint = freq->m / 100000; + } else { + if(freq->m) { + ar->arChannelHint = wlan_ieee2freq(freq->m); + } else { + /* Auto Channel Selection */ + ar->arChannelHint = 0; + } + } + + ar->ap_profile_flag = 1; /* There is a change in profile */ + + A_PRINTF("channel hint set to %d\n", ar->arChannelHint); + return 0; +} + +/* + * SIOCGIWFREQ + */ +int +ar6000_ioctl_giwfreq(struct net_device *dev, + struct iw_request_info *info, + struct iw_freq *freq, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ar->arNetworkType == AP_NETWORK) { + if(ar->arChannelHint) { + freq->m = ar->arChannelHint * 100000; + } else if(ar->arACS) { + freq->m = ar->arACS * 100000; + } else { + return -EINVAL; + } + } else { + if (ar->arConnected != true) { + return -EINVAL; + } else { + freq->m = ar->arBssChannel * 100000; + } + } + + freq->e = 1; + + return 0; +} + +/* + * SIOCSIWMODE + */ +int +ar6000_ioctl_siwmode(struct net_device *dev, + struct iw_request_info *info, + __u32 *mode, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + /* + * clear SSID during mode switch in connected state + */ + if(!(ar->arNetworkType == (((*mode) == IW_MODE_INFRA) ? INFRA_NETWORK : ADHOC_NETWORK)) && (ar->arConnected == true) ){ + A_MEMZERO(ar->arSsid, sizeof(ar->arSsid)); + ar->arSsidLen = 0; + } + + switch (*mode) { + case IW_MODE_INFRA: + ar->arNextMode = INFRA_NETWORK; + break; + case IW_MODE_ADHOC: + ar->arNextMode = ADHOC_NETWORK; + break; + case IW_MODE_MASTER: + ar->arNextMode = AP_NETWORK; + break; + default: + return -EINVAL; + } + + /* clear all shared parameters between AP and STA|IBSS modes when we + * switch between them. Switch between STA & IBSS modes does'nt clear + * the shared profile. This is as per the original design for switching + * between STA & IBSS. + */ + if (ar->arNetworkType == AP_NETWORK || ar->arNextMode == AP_NETWORK) { + ar->arDot11AuthMode = OPEN_AUTH; + ar->arAuthMode = NONE_AUTH; + ar->arPairwiseCrypto = NONE_CRYPT; + ar->arPairwiseCryptoLen = 0; + ar->arGroupCrypto = NONE_CRYPT; + ar->arGroupCryptoLen = 0; + ar->arChannelHint = 0; + ar->arBssChannel = 0; + A_MEMZERO(ar->arBssid, sizeof(ar->arBssid)); + A_MEMZERO(ar->arSsid, sizeof(ar->arSsid)); + ar->arSsidLen = 0; + } + + /* SSID has to be cleared to trigger a profile change while switching + * between STA & IBSS modes having the same SSID + */ + if (ar->arNetworkType != ar->arNextMode) { + A_MEMZERO(ar->arSsid, sizeof(ar->arSsid)); + ar->arSsidLen = 0; + } + + return 0; +} + +/* + * SIOCGIWMODE + */ +int +ar6000_ioctl_giwmode(struct net_device *dev, + struct iw_request_info *info, + __u32 *mode, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + switch (ar->arNetworkType) { + case INFRA_NETWORK: + *mode = IW_MODE_INFRA; + break; + case ADHOC_NETWORK: + *mode = IW_MODE_ADHOC; + break; + case AP_NETWORK: + *mode = IW_MODE_MASTER; + break; + default: + return -EIO; + } + return 0; +} + +/* + * SIOCSIWSENS + */ +int +ar6000_ioctl_siwsens(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *sens, char *extra) +{ + return 0; +} + +/* + * SIOCGIWSENS + */ +int +ar6000_ioctl_giwsens(struct net_device *dev, + struct iw_request_info *info, + struct iw_param *sens, char *extra) +{ + sens->value = 0; + sens->fixed = 1; + + return 0; +} + +/* + * SIOCGIWRANGE + */ +int +ar6000_ioctl_giwrange(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + struct iw_range *range = (struct iw_range *) extra; + int i, ret = 0; + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (ar->bIsDestroyProgress) { + up(&ar->arSem); + return -EBUSY; + } + + ar->arNumChannels = -1; + A_MEMZERO(ar->arChannelList, sizeof (ar->arChannelList)); + + if (wmi_get_channelList_cmd(ar->arWmi) != 0) { + up(&ar->arSem); + return -EIO; + } + + wait_event_interruptible_timeout(arEvent, ar->arNumChannels != -1, wmitimeout * HZ); + + if (signal_pending(current)) { + up(&ar->arSem); + return -EINTR; + } + + data->length = sizeof(struct iw_range); + A_MEMZERO(range, sizeof(struct iw_range)); + + range->txpower_capa = 0; + + range->min_pmp = 1 * 1024; + range->max_pmp = 65535 * 1024; + range->min_pmt = 1 * 1024; + range->max_pmt = 1000 * 1024; + range->pmp_flags = IW_POWER_PERIOD; + range->pmt_flags = IW_POWER_TIMEOUT; + range->pm_capa = 0; + + range->we_version_compiled = WIRELESS_EXT; + range->we_version_source = 13; + + range->retry_capa = IW_RETRY_LIMIT; + range->retry_flags = IW_RETRY_LIMIT; + range->min_retry = 0; + range->max_retry = 255; + + range->num_frequency = range->num_channels = ar->arNumChannels; + for (i = 0; i < ar->arNumChannels; i++) { + range->freq[i].i = wlan_freq2ieee(ar->arChannelList[i]); + range->freq[i].m = ar->arChannelList[i] * 100000; + range->freq[i].e = 1; + /* + * Linux supports max of 32 channels, bail out once you + * reach the max. + */ + if (i == IW_MAX_FREQUENCIES) { + break; + } + } + + /* Max quality is max field value minus noise floor */ + range->max_qual.qual = 0xff - 161; + + /* + * In order to use dBm measurements, 'level' must be lower + * than any possible measurement (see iw_print_stats() in + * wireless tools). It's unclear how this is meant to be + * done, but setting zero in these values forces dBm and + * the actual numbers are not used. + */ + range->max_qual.level = 0; + range->max_qual.noise = 0; + + range->sensitivity = 3; + + range->max_encoding_tokens = 4; + /* XXX query driver to find out supported key sizes */ + range->num_encoding_sizes = 3; + range->encoding_size[0] = 5; /* 40-bit */ + range->encoding_size[1] = 13; /* 104-bit */ + range->encoding_size[2] = 16; /* 128-bit */ + + range->num_bitrates = 0; + + /* estimated maximum TCP throughput values (bps) */ + range->throughput = 22000000; + + range->min_rts = 0; + range->max_rts = 2347; + range->min_frag = 256; + range->max_frag = 2346; + + up(&ar->arSem); + + return ret; +} + + +/* + * SIOCSIWAP + * This ioctl is used to set the desired bssid for the connect command. + */ +int +ar6000_ioctl_siwap(struct net_device *dev, + struct iw_request_info *info, + struct sockaddr *ap_addr, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ap_addr->sa_family != ARPHRD_ETHER) { + return -EIO; + } + + if (memcmp(&ap_addr->sa_data, bcast_mac, AR6000_ETH_ADDR_LEN) == 0) { + A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid)); + } else { + memcpy(ar->arReqBssid, &ap_addr->sa_data, sizeof(ar->arReqBssid)); + } + + return 0; +} + +/* + * SIOCGIWAP + */ +int +ar6000_ioctl_giwap(struct net_device *dev, + struct iw_request_info *info, + struct sockaddr *ap_addr, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ar->arNetworkType == AP_NETWORK) { + memcpy(&ap_addr->sa_data, dev->dev_addr, ATH_MAC_LEN); + ap_addr->sa_family = ARPHRD_ETHER; + return 0; + } + + if (ar->arConnected != true) { + return -EINVAL; + } + + memcpy(&ap_addr->sa_data, ar->arBssid, sizeof(ar->arBssid)); + ap_addr->sa_family = ARPHRD_ETHER; + + return 0; +} + +#if (WIRELESS_EXT >= 18) +/* + * SIOCSIWMLME + */ +int +ar6000_ioctl_siwmlme(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->bIsDestroyProgress) { + return -EBUSY; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (down_interruptible(&ar->arSem)) { + return -ERESTARTSYS; + } + + if (data->pointer && data->length == sizeof(struct iw_mlme)) { + + u8 arNetworkType; + struct iw_mlme mlme; + + if (copy_from_user(&mlme, data->pointer, sizeof(struct iw_mlme))) + return -EIO; + + switch (mlme.cmd) { + + case IW_MLME_DEAUTH: + /* fall through */ + case IW_MLME_DISASSOC: + if ((ar->arConnected != true) || + (memcmp(ar->arBssid, mlme.addr.sa_data, 6) != 0)) { + + up(&ar->arSem); + return -EINVAL; + } + wmi_setPmkid_cmd(ar->arWmi, ar->arBssid, NULL, 0); + arNetworkType = ar->arNetworkType; + ar6000_init_profile_info(ar); + ar->arNetworkType = arNetworkType; + reconnect_flag = 0; + ar6000_disconnect(ar); + A_MEMZERO(ar->arSsid, sizeof(ar->arSsid)); + ar->arSsidLen = 0; + if (ar->arSkipScan == false) { + A_MEMZERO(ar->arReqBssid, sizeof(ar->arReqBssid)); + } + break; + + case IW_MLME_AUTH: + /* fall through */ + case IW_MLME_ASSOC: + /* fall through */ + default: + up(&ar->arSem); + return -EOPNOTSUPP; + } + } + + up(&ar->arSem); + return 0; +} +#endif /* WIRELESS_EXT >= 18 */ + +/* + * SIOCGIWAPLIST + */ +int +ar6000_ioctl_iwaplist(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + return -EIO; /* for now */ +} + +/* + * SIOCSIWSCAN + */ +int +ar6000_ioctl_siwscan(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ +#define ACT_DWELLTIME_DEFAULT 105 +#define HOME_TXDRAIN_TIME 100 +#define SCAN_INT HOME_TXDRAIN_TIME + ACT_DWELLTIME_DEFAULT + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + int ret = 0; + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + /* If scan is issued in the middle of ongoing scan or connect, + dont issue another one */ + if ( ar->scan_triggered > 0 ) { + ++ar->scan_triggered; + if (ar->scan_triggered < 5) { + return 0; + } else { + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_SCAN,("Scan request is triggered over 5 times. Not scan complete event\n")); + } + } + + if (!ar->arUserBssFilter) { + if (wmi_bssfilter_cmd(ar->arWmi, ALL_BSS_FILTER, 0) != 0) { + return -EIO; + } + } + + if (ar->arConnected) { + if (wmi_get_stats_cmd(ar->arWmi) != 0) { + return -EIO; + } + } + +#ifdef ANDROID_ENV +#if WIRELESS_EXT >= 18 + if (data->pointer && (data->length == sizeof(struct iw_scan_req))) + { + if ((data->flags & IW_SCAN_THIS_ESSID) == IW_SCAN_THIS_ESSID) + { + struct iw_scan_req req; + if (copy_from_user(&req, data->pointer, sizeof(struct iw_scan_req))) + return -EIO; + if (wmi_probedSsid_cmd(ar->arWmi, 1, SPECIFIC_SSID_FLAG, req.essid_len, req.essid) != 0) + return -EIO; + ar->scanSpecificSsid = true; + } + else + { + if (ar->scanSpecificSsid) { + if (wmi_probedSsid_cmd(ar->arWmi, 1, DISABLE_SSID_FLAG, 0, NULL) != 0) + return -EIO; + ar->scanSpecificSsid = false; + } + } + } + else + { + if (ar->scanSpecificSsid) { + if (wmi_probedSsid_cmd(ar->arWmi, 1, DISABLE_SSID_FLAG, 0, NULL) != 0) + return -EIO; + ar->scanSpecificSsid = false; + } + } +#endif +#endif /* ANDROID_ENV */ + + if (wmi_startscan_cmd(ar->arWmi, WMI_LONG_SCAN, false, false, \ + 0, 0, 0, NULL) != 0) { + ret = -EIO; + } + + if (ret == 0) { + ar->scan_triggered = 1; + } + + return ret; +#undef ACT_DWELLTIME_DEFAULT +#undef HOME_TXDRAIN_TIME +#undef SCAN_INT +} + + +/* + * Units are in db above the noise floor. That means the + * rssi values reported in the tx/rx descriptors in the + * driver are the SNR expressed in db. + * + * If you assume that the noise floor is -95, which is an + * excellent assumption 99.5 % of the time, then you can + * derive the absolute signal level (i.e. -95 + rssi). + * There are some other slight factors to take into account + * depending on whether the rssi measurement is from 11b, + * 11g, or 11a. These differences are at most 2db and + * can be documented. + * + * NB: various calculations are based on the orinoco/wavelan + * drivers for compatibility + */ +static void +ar6000_set_quality(struct iw_quality *iq, s8 rssi) +{ + if (rssi < 0) { + iq->qual = 0; + } else { + iq->qual = rssi; + } + + /* NB: max is 94 because noise is hardcoded to 161 */ + if (iq->qual > 94) + iq->qual = 94; + + iq->noise = 161; /* -95dBm */ + iq->level = iq->noise + iq->qual; + iq->updated = 7; +} + + +int +ar6000_ioctl_siwcommit(struct net_device *dev, + struct iw_request_info *info, + struct iw_point *data, char *extra) +{ + struct ar6_softc *ar = (struct ar6_softc *)ar6k_priv(dev); + + if (is_iwioctl_allowed(ar->arNextMode, info->cmd) != 0) { + A_PRINTF("wext_ioctl: cmd=0x%x not allowed in this mode\n", info->cmd); + return -EOPNOTSUPP; + } + + if (ar->arWmiReady == false) { + return -EIO; + } + + if (ar->arWlanState == WLAN_DISABLED) { + return -EIO; + } + + AR_DEBUG_PRINTF(ATH_DEBUG_WLAN_CONNECT,("AP: SSID %s freq %d authmode %d dot11 auth %d"\ + " PW crypto %d GRP crypto %d\n", + ar->arSsid, ar->arChannelHint, + ar->arAuthMode, ar->arDot11AuthMode, + ar->arPairwiseCrypto, ar->arGroupCrypto)); + + ar6000_ap_mode_profile_commit(ar); + + /* if there is a profile switch from STA|IBSS mode to AP mode, + * update the host driver association state for the STA|IBSS mode. + */ + if (ar->arNetworkType != AP_NETWORK && ar->arNextMode == AP_NETWORK) { + /* Stop getting pkts from upper stack */ + netif_stop_queue(ar->arNetDev); + A_MEMZERO(ar->arBssid, sizeof(ar->arBssid)); + ar->arBssChannel = 0; + ar->arBeaconInterval = 0; + + /* Flush the Tx queues */ + ar6000_TxDataCleanup(ar); + + /* Start getting pkts from upper stack */ + netif_wake_queue(ar->arNetDev); + } + + return 0; +} + +#define W_PROTO(_x) wait_ ## _x +#define WAIT_HANDLER_IMPL(_x, type) \ +int wait_ ## _x (struct net_device *dev, struct iw_request_info *info, type wrqu, char *extra) {\ + int ret; \ + dev_hold(dev); \ + rtnl_unlock(); \ + ret = _x(dev, info, wrqu, extra); \ + rtnl_lock(); \ + dev_put(dev); \ + return ret;\ +} + +WAIT_HANDLER_IMPL(ar6000_ioctl_siwessid, struct iw_point *) +WAIT_HANDLER_IMPL(ar6000_ioctl_giwrate, struct iw_param *) +WAIT_HANDLER_IMPL(ar6000_ioctl_giwtxpow, struct iw_param *) +WAIT_HANDLER_IMPL(ar6000_ioctl_giwrange, struct iw_point*) + +/* Structures to export the Wireless Handlers */ +static const iw_handler ath_handlers[] = { + (iw_handler) ar6000_ioctl_siwcommit, /* SIOCSIWCOMMIT */ + (iw_handler) ar6000_ioctl_giwname, /* SIOCGIWNAME */ + (iw_handler) NULL, /* SIOCSIWNWID */ + (iw_handler) NULL, /* SIOCGIWNWID */ + (iw_handler) ar6000_ioctl_siwfreq, /* SIOCSIWFREQ */ + (iw_handler) ar6000_ioctl_giwfreq, /* SIOCGIWFREQ */ + (iw_handler) ar6000_ioctl_siwmode, /* SIOCSIWMODE */ + (iw_handler) ar6000_ioctl_giwmode, /* SIOCGIWMODE */ + (iw_handler) ar6000_ioctl_siwsens, /* SIOCSIWSENS */ + (iw_handler) ar6000_ioctl_giwsens, /* SIOCGIWSENS */ + (iw_handler) NULL /* not _used */, /* SIOCSIWRANGE */ + (iw_handler) W_PROTO(ar6000_ioctl_giwrange),/* SIOCGIWRANGE */ + (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */ + (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */ + (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */ + (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */ + (iw_handler) NULL, /* SIOCSIWSPY */ + (iw_handler) NULL, /* SIOCGIWSPY */ + (iw_handler) NULL, /* SIOCSIWTHRSPY */ + (iw_handler) NULL, /* SIOCGIWTHRSPY */ + (iw_handler) ar6000_ioctl_siwap, /* SIOCSIWAP */ + (iw_handler) ar6000_ioctl_giwap, /* SIOCGIWAP */ +#if (WIRELESS_EXT >= 18) + (iw_handler) ar6000_ioctl_siwmlme, /* SIOCSIWMLME */ +#else + (iw_handler) NULL, /* -- hole -- */ +#endif /* WIRELESS_EXT >= 18 */ + (iw_handler) ar6000_ioctl_iwaplist, /* SIOCGIWAPLIST */ + (iw_handler) ar6000_ioctl_siwscan, /* SIOCSIWSCAN */ + (iw_handler) ar6000_ioctl_giwscan, /* SIOCGIWSCAN */ + (iw_handler) W_PROTO(ar6000_ioctl_siwessid),/* SIOCSIWESSID */ + (iw_handler) ar6000_ioctl_giwessid, /* SIOCGIWESSID */ + (iw_handler) NULL, /* SIOCSIWNICKN */ + (iw_handler) NULL, /* SIOCGIWNICKN */ + (iw_handler) NULL, /* -- hole -- */ + (iw_handler) NULL, /* -- hole -- */ + (iw_handler) ar6000_ioctl_siwrate, /* SIOCSIWRATE */ + (iw_handler) W_PROTO(ar6000_ioctl_giwrate), /* SIOCGIWRATE */ + (iw_handler) NULL, /* SIOCSIWRTS */ + (iw_handler) NULL, /* SIOCGIWRTS */ + (iw_handler) NULL, /* SIOCSIWFRAG */ + (iw_handler) NULL, /* SIOCGIWFRAG */ + (iw_handler) ar6000_ioctl_siwtxpow, /* SIOCSIWTXPOW */ + (iw_handler) W_PROTO(ar6000_ioctl_giwtxpow),/* SIOCGIWTXPOW */ + (iw_handler) ar6000_ioctl_siwretry, /* SIOCSIWRETRY */ + (iw_handler) ar6000_ioctl_giwretry, /* SIOCGIWRETRY */ + (iw_handler) ar6000_ioctl_siwencode, /* SIOCSIWENCODE */ + (iw_handler) ar6000_ioctl_giwencode, /* SIOCGIWENCODE */ +#if WIRELESS_EXT > 20 + (iw_handler) ar6000_ioctl_siwpower, /* SIOCSIWPOWER */ + (iw_handler) ar6000_ioctl_giwpower, /* SIOCGIWPOWER */ +#endif // WIRELESS_EXT > 20 +#if WIRELESS_EXT >= 18 + (iw_handler) NULL, /* -- hole -- */ + (iw_handler) NULL, /* -- hole -- */ + (iw_handler) ar6000_ioctl_siwgenie, /* SIOCSIWGENIE */ + (iw_handler) ar6000_ioctl_giwgenie, /* SIOCGIWGENIE */ + (iw_handler) ar6000_ioctl_siwauth, /* SIOCSIWAUTH */ + (iw_handler) ar6000_ioctl_giwauth, /* SIOCGIWAUTH */ + (iw_handler) ar6000_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ + (iw_handler) ar6000_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */ + (iw_handler) ar6000_ioctl_siwpmksa, /* SIOCSIWPMKSA */ +#endif // WIRELESS_EXT >= 18 +}; + +struct iw_handler_def ath_iw_handler_def = { + .standard = (iw_handler *)ath_handlers, + .num_standard = ARRAY_SIZE(ath_handlers), + .private = NULL, + .num_private = 0, +}; diff --git a/trunk/drivers/staging/ath6kl/reorder/rcv_aggr.c b/trunk/drivers/staging/ath6kl/reorder/rcv_aggr.c index 788d0884f064..094b227b32c4 100644 --- a/trunk/drivers/staging/ath6kl/reorder/rcv_aggr.c +++ b/trunk/drivers/staging/ath6kl/reorder/rcv_aggr.c @@ -21,6 +21,8 @@ * */ +#ifdef ATH_AR6K_11N_SUPPORT + #include #include #include @@ -121,7 +123,7 @@ aggr_delete_tid_state(struct aggr_info *p_aggr, u8 tid) rxtid->hold_q_sz = 0; if(rxtid->hold_q) { - kfree(rxtid->hold_q); + A_FREE(rxtid->hold_q); rxtid->hold_q = NULL; } @@ -152,7 +154,7 @@ aggr_module_destroy(void *cntxt) A_NETBUF_FREE(rxtid->hold_q[k].osbuf); } } - kfree(rxtid->hold_q); + A_FREE(rxtid->hold_q); } /* Free the dispatch q contents*/ while(A_NETBUF_QUEUE_SIZE(&rxtid->q)) { @@ -166,7 +168,7 @@ aggr_module_destroy(void *cntxt) while(A_NETBUF_QUEUE_SIZE(&p_aggr->freeQ)) { A_NETBUF_FREE(A_NETBUF_DEQUEUE(&p_aggr->freeQ)); } - kfree(p_aggr); + A_FREE(p_aggr); } A_PRINTF("out aggr_module_destroy\n"); } @@ -660,3 +662,5 @@ aggr_dump_stats(void *cntxt, PACKET_LOG **log_buf) A_PRINTF("================================================\n\n"); } + +#endif /* ATH_AR6K_11N_SUPPORT */ diff --git a/trunk/drivers/staging/ath6kl/wlan/include/ieee80211.h b/trunk/drivers/staging/ath6kl/wlan/include/ieee80211.h index cf47d0657e70..532ab0eb20c3 100644 --- a/trunk/drivers/staging/ath6kl/wlan/include/ieee80211.h +++ b/trunk/drivers/staging/ath6kl/wlan/include/ieee80211.h @@ -23,6 +23,8 @@ #ifndef _NET80211_IEEE80211_H_ #define _NET80211_IEEE80211_H_ +#include "athstartpack.h" + /* * 802.11 protocol definitions. */ @@ -394,4 +396,6 @@ enum ieee80211_authmode { #define IEEE80211_PS_MAX_QUEUE 50 /*Maximum no of buffers that can be queues for PS*/ +#include "athendpack.h" + #endif /* _NET80211_IEEE80211_H_ */ diff --git a/trunk/drivers/staging/ath6kl/wlan/src/wlan_node.c b/trunk/drivers/staging/ath6kl/wlan/src/wlan_node.c index b166dd44893c..1a3ac7dd5e34 100644 --- a/trunk/drivers/staging/ath6kl/wlan/src/wlan_node.c +++ b/trunk/drivers/staging/ath6kl/wlan/src/wlan_node.c @@ -72,7 +72,7 @@ wlan_node_alloc(struct ieee80211_node_table *nt, int wh_size) { ni->ni_buf = A_MALLOC_NOWAIT(wh_size); if (ni->ni_buf == NULL) { - kfree(ni); + A_FREE(ni); ni = NULL; return ni; } @@ -104,9 +104,9 @@ void wlan_node_free(bss_t *ni) { if (ni->ni_buf != NULL) { - kfree(ni->ni_buf); + A_FREE(ni->ni_buf); } - kfree(ni); + A_FREE(ni); } void diff --git a/trunk/drivers/staging/ath6kl/wmi/wmi.c b/trunk/drivers/staging/ath6kl/wmi/wmi.c index c3a1cc5fe7be..a00bf0a59871 100644 --- a/trunk/drivers/staging/ath6kl/wmi/wmi.c +++ b/trunk/drivers/staging/ath6kl/wmi/wmi.c @@ -129,6 +129,14 @@ wmi_get_pmkid_list_event_rx(struct wmi_t *wmip, u8 *datap, u32 len); static int wmi_set_params_event_rx(struct wmi_t *wmip, u8 *datap, u32 len); +static int +wmi_acm_reject_event_rx(struct wmi_t *wmip, u8 *datap, u32 len); + +#ifdef CONFIG_HOST_GPIO_SUPPORT +static int wmi_gpio_intr_rx(struct wmi_t *wmip, u8 *datap, int len); +static int wmi_gpio_data_rx(struct wmi_t *wmip, u8 *datap, int len); +static int wmi_gpio_ack_rx(struct wmi_t *wmip, u8 *datap, int len); +#endif /* CONFIG_HOST_GPIO_SUPPORT */ #ifdef CONFIG_HOST_TCMD_SUPPORT static int @@ -179,11 +187,13 @@ static int wmi_dtimexpiry_event_rx(struct wmi_t *wmip, u8 *datap, static int wmi_peer_node_event_rx (struct wmi_t *wmip, u8 *datap, int len); +#ifdef ATH_AR6K_11N_SUPPORT static int wmi_addba_req_event_rx(struct wmi_t *, u8 *, int); static int wmi_addba_resp_event_rx(struct wmi_t *, u8 *, int); static int wmi_delba_req_event_rx(struct wmi_t *, u8 *, int); static int wmi_btcoex_config_event_rx(struct wmi_t *wmip, u8 *datap, int len); static int wmi_btcoex_stats_event_rx(struct wmi_t *wmip, u8 *datap, int len); +#endif static int wmi_hci_event_rx(struct wmi_t *, u8 *, int); #ifdef WAPI_ENABLE @@ -263,6 +273,8 @@ const u8 up_to_ac[]= { WMM_AC_VO, }; +#include "athstartpack.h" + /* This stuff is used when we want a simple layer-3 visibility */ typedef PREPACK struct _iphdr { u8 ip_ver_hdrlen; /* version and hdr length */ @@ -280,6 +292,8 @@ typedef PREPACK struct _iphdr { u8 ip_dst[4]; } POSTPACK iphdr; +#include "athendpack.h" + static s16 rssi_event_value = 0; static s16 snr_event_value = 0; @@ -367,7 +381,7 @@ wmi_shutdown(struct wmi_t *wmip) A_MUTEX_DELETE(&wmip->wmi_lock); #endif } - kfree(wmip); + A_FREE(wmip); } } @@ -461,6 +475,7 @@ int wmi_meta_add(struct wmi_t *wmip, void *osbuf, u8 *pVersion,void *pTxMetaS) *pVersion = WMI_META_VERSION_1; return (0); } +#ifdef CONFIG_CHECKSUM_OFFLOAD case WMI_META_VERSION_2: { WMI_TX_META_V2 *pV2 ; @@ -472,6 +487,7 @@ int wmi_meta_add(struct wmi_t *wmip, void *osbuf, u8 *pVersion,void *pTxMetaS) memcpy(pV2,(WMI_TX_META_V2 *)pTxMetaS,sizeof(WMI_TX_META_V2)); return (0); } +#endif default: return (0); } @@ -509,8 +525,7 @@ wmi_data_hdr_add(struct wmi_t *wmip, void *osbuf, u8 msgType, bool bMoreData, } WMI_DATA_HDR_SET_META(dtHdr, metaVersion); - - dtHdr->info3 = 0; + //dtHdr->rssi = 0; return (0); } @@ -850,6 +865,17 @@ wmi_control_rx_xtnd(struct wmi_t *wmip, void *osbuf) status = wmi_dset_data_req_rx(wmip, datap, len); break; #endif /* CONFIG_HOST_DSET_SUPPORT */ +#ifdef CONFIG_HOST_GPIO_SUPPORT + case (WMIX_GPIO_INTR_EVENTID): + wmi_gpio_intr_rx(wmip, datap, len); + break; + case (WMIX_GPIO_DATA_EVENTID): + wmi_gpio_data_rx(wmip, datap, len); + break; + case (WMIX_GPIO_ACK_EVENTID): + wmi_gpio_ack_rx(wmip, datap, len); + break; +#endif /* CONFIG_HOST_GPIO_SUPPORT */ case (WMIX_HB_CHALLENGE_RESP_EVENTID): wmi_hbChallengeResp_rx(wmip, datap, len); break; @@ -941,19 +967,23 @@ wmi_control_rx(struct wmi_t *wmip, void *osbuf) case (WMI_READY_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_READY_EVENTID\n", DBGARG)); status = wmi_ready_event_rx(wmip, datap, len); + A_WMI_SEND_EVENT_TO_APP(wmip->wmi_devt, id, datap, len); A_WMI_DBGLOG_INIT_DONE(wmip->wmi_devt); break; case (WMI_CONNECT_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_CONNECT_EVENTID\n", DBGARG)); status = wmi_connect_event_rx(wmip, datap, len); + A_WMI_SEND_GENERIC_EVENT_TO_APP(wmip->wmi_devt, id, datap, len); break; case (WMI_DISCONNECT_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_DISCONNECT_EVENTID\n", DBGARG)); status = wmi_disconnect_event_rx(wmip, datap, len); + A_WMI_SEND_EVENT_TO_APP(wmip->wmi_devt, id, datap, len); break; case (WMI_PEER_NODE_EVENTID): A_DPRINTF (DBG_WMI, (DBGFMT "WMI_PEER_NODE_EVENTID\n", DBGARG)); status = wmi_peer_node_event_rx(wmip, datap, len); + A_WMI_SEND_EVENT_TO_APP(wmip->wmi_devt, id, datap, len); break; case (WMI_TKIP_MICERR_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_TKIP_MICERR_EVENTID\n", DBGARG)); @@ -984,6 +1014,7 @@ wmi_control_rx(struct wmi_t *wmip, void *osbuf) memcpy(bih->bssid, bih2.bssid, ATH_MAC_LEN); status = wmi_bssInfo_event_rx(wmip, datap, len); + A_WMI_SEND_GENERIC_EVENT_TO_APP(wmip->wmi_devt, id, datap, len); } break; case (WMI_REGDOMAIN_EVENTID): @@ -993,6 +1024,13 @@ wmi_control_rx(struct wmi_t *wmip, void *osbuf) case (WMI_PSTREAM_TIMEOUT_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_PSTREAM_TIMEOUT_EVENTID\n", DBGARG)); status = wmi_pstream_timeout_event_rx(wmip, datap, len); + /* pstreams are fatpipe abstractions that get implicitly created. + * User apps only deal with thinstreams. creation of a thinstream + * by the user or data traffic flow in an AC triggers implicit + * pstream creation. Do we need to send this event to App..? + * no harm in sending it. + */ + A_WMI_SEND_EVENT_TO_APP(wmip->wmi_devt, id, datap, len); break; case (WMI_NEIGHBOR_REPORT_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_NEIGHBOR_REPORT_EVENTID\n", DBGARG)); @@ -1001,6 +1039,7 @@ wmi_control_rx(struct wmi_t *wmip, void *osbuf) case (WMI_SCAN_COMPLETE_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_SCAN_COMPLETE_EVENTID\n", DBGARG)); status = wmi_scanComplete_rx(wmip, datap, len); + A_WMI_SEND_EVENT_TO_APP(wmip->wmi_devt, id, datap, len); break; case (WMI_CMDERROR_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_CMDERROR_EVENTID\n", DBGARG)); @@ -1017,6 +1056,7 @@ wmi_control_rx(struct wmi_t *wmip, void *osbuf) case (WMI_ERROR_REPORT_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_ERROR_REPORT_EVENTID\n", DBGARG)); status = wmi_reportErrorEvent_rx(wmip, datap, len); + A_WMI_SEND_EVENT_TO_APP(wmip->wmi_devt, id, datap, len); break; case (WMI_OPT_RX_FRAME_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_OPT_RX_FRAME_EVENTID\n", DBGARG)); @@ -1055,6 +1095,7 @@ wmi_control_rx(struct wmi_t *wmip, void *osbuf) case (WMI_TX_RETRY_ERR_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_TX_RETRY_ERR_EVENTID\n", DBGARG)); status = wmi_txRetryErrEvent_rx(wmip, datap, len); + A_WMI_SEND_EVENT_TO_APP(wmip->wmi_devt, id, datap, len); break; case (WMI_SNR_THRESHOLD_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_SNR_THRESHOLD_EVENTID\n", DBGARG)); @@ -1063,6 +1104,7 @@ wmi_control_rx(struct wmi_t *wmip, void *osbuf) case (WMI_LQ_THRESHOLD_EVENTID): A_DPRINTF(DBG_WMI, (DBGFMT "WMI_LQ_THRESHOLD_EVENTID\n", DBGARG)); status = wmi_lqThresholdEvent_rx(wmip, datap, len); + A_WMI_SEND_EVENT_TO_APP(wmip->wmi_devt, id, datap, len); break; case (WMI_APLIST_EVENTID): AR_DEBUG_PRINTF(ATH_DEBUG_WMI, ("Received APLIST Event\n")); @@ -1091,6 +1133,11 @@ wmi_control_rx(struct wmi_t *wmip, void *osbuf) A_DPRINTF(DBG_WMI, (DBGFMT "WMI_SET_PARAMS_REPLY Event\n", DBGARG)); status = wmi_set_params_event_rx(wmip, datap, len); break; + case (WMI_ACM_REJECT_EVENTID): + A_DPRINTF(DBG_WMI, (DBGFMT "WMI_SET_PARAMS_REPLY Event\n", DBGARG)); + status = wmi_acm_reject_event_rx(wmip, datap, len); + break; +#ifdef ATH_AR6K_11N_SUPPORT case (WMI_ADDBA_REQ_EVENTID): status = wmi_addba_req_event_rx(wmip, datap, len); break; @@ -1108,6 +1155,7 @@ wmi_control_rx(struct wmi_t *wmip, void *osbuf) A_DPRINTF(DBG_WMI, (DBGFMT "WMI_BTCOEX_STATS_EVENTID", DBGARG)); status = wmi_btcoex_stats_event_rx(wmip, datap, len); break; +#endif case (WMI_TX_COMPLETE_EVENTID): { int index; @@ -1160,7 +1208,7 @@ wmi_simple_cmd(struct wmi_t *wmip, WMI_COMMAND_ID cmdid) /* Send a "simple" extended wmi command -- one with no arguments. Enabling this command only if GPIO or profiling support is enabled. This is to suppress warnings on some platforms */ -#if defined(CONFIG_TARGET_PROFILE_SUPPORT) +#if defined(CONFIG_HOST_GPIO_SUPPORT) || defined(CONFIG_TARGET_PROFILE_SUPPORT) static int wmi_simple_cmd_xtnd(struct wmi_t *wmip, WMIX_COMMAND_ID cmdid) { @@ -2250,6 +2298,46 @@ wmi_dbglog_event_rx(struct wmi_t *wmip, u8 *datap, int len) return 0; } +#ifdef CONFIG_HOST_GPIO_SUPPORT +static int +wmi_gpio_intr_rx(struct wmi_t *wmip, u8 *datap, int len) +{ + WMIX_GPIO_INTR_EVENT *gpio_intr = (WMIX_GPIO_INTR_EVENT *)datap; + + A_DPRINTF(DBG_WMI, + (DBGFMT "Enter - intrmask=0x%x input=0x%x.\n", DBGARG, + gpio_intr->intr_mask, gpio_intr->input_values)); + + A_WMI_GPIO_INTR_RX(gpio_intr->intr_mask, gpio_intr->input_values); + + return 0; +} + +static int +wmi_gpio_data_rx(struct wmi_t *wmip, u8 *datap, int len) +{ + WMIX_GPIO_DATA_EVENT *gpio_data = (WMIX_GPIO_DATA_EVENT *)datap; + + A_DPRINTF(DBG_WMI, + (DBGFMT "Enter - reg=%d value=0x%x\n", DBGARG, + gpio_data->reg_id, gpio_data->value)); + + A_WMI_GPIO_DATA_RX(gpio_data->reg_id, gpio_data->value); + + return 0; +} + +static int +wmi_gpio_ack_rx(struct wmi_t *wmip, u8 *datap, int len) +{ + A_DPRINTF(DBG_WMI, (DBGFMT "Enter\n", DBGARG)); + + A_WMI_GPIO_ACK_RX(); + + return 0; +} +#endif /* CONFIG_HOST_GPIO_SUPPORT */ + /* * Called to send a wmi command. Command specific data is already built * on osbuf and current osbuf->data points to it. @@ -2987,7 +3075,6 @@ wmi_dataSync_send(struct wmi_t *wmip, void *osbuf, HTC_ENDPOINT_ID eid) dtHdr->info = (SYNC_MSGTYPE & WMI_DATA_HDR_MSG_TYPE_MASK) << WMI_DATA_HDR_MSG_TYPE_SHIFT; - dtHdr->info3 = 0; A_DPRINTF(DBG_WMI, (DBGFMT "Enter - eid %d\n", DBGARG, eid)); return (A_WMI_CONTROL_TX(wmip->wmi_devt, osbuf, eid)); @@ -4195,6 +4282,132 @@ wmi_set_powersave_timers_cmd(struct wmi_t *wmip, NO_SYNC_WMIFLAG)); } +#ifdef CONFIG_HOST_GPIO_SUPPORT +/* Send a command to Target to change GPIO output pins. */ +int +wmi_gpio_output_set(struct wmi_t *wmip, + u32 set_mask, + u32 clear_mask, + u32 enable_mask, + u32 disable_mask) +{ + void *osbuf; + WMIX_GPIO_OUTPUT_SET_CMD *output_set; + int size; + + size = sizeof(*output_set); + + A_DPRINTF(DBG_WMI, + (DBGFMT "Enter - set=0x%x clear=0x%x enb=0x%x dis=0x%x\n", DBGARG, + set_mask, clear_mask, enable_mask, disable_mask)); + + osbuf = A_NETBUF_ALLOC(size); + if (osbuf == NULL) { + return A_NO_MEMORY; + } + A_NETBUF_PUT(osbuf, size); + output_set = (WMIX_GPIO_OUTPUT_SET_CMD *)(A_NETBUF_DATA(osbuf)); + + output_set->set_mask = set_mask; + output_set->clear_mask = clear_mask; + output_set->enable_mask = enable_mask; + output_set->disable_mask = disable_mask; + + return (wmi_cmd_send_xtnd(wmip, osbuf, WMIX_GPIO_OUTPUT_SET_CMDID, + NO_SYNC_WMIFLAG)); +} + +/* Send a command to the Target requesting state of the GPIO input pins */ +int +wmi_gpio_input_get(struct wmi_t *wmip) +{ + A_DPRINTF(DBG_WMI, (DBGFMT "Enter\n", DBGARG)); + + return wmi_simple_cmd_xtnd(wmip, WMIX_GPIO_INPUT_GET_CMDID); +} + +/* Send a command to the Target that changes the value of a GPIO register. */ +int +wmi_gpio_register_set(struct wmi_t *wmip, + u32 gpioreg_id, + u32 value) +{ + void *osbuf; + WMIX_GPIO_REGISTER_SET_CMD *register_set; + int size; + + size = sizeof(*register_set); + + A_DPRINTF(DBG_WMI, + (DBGFMT "Enter - reg=%d value=0x%x\n", DBGARG, gpioreg_id, value)); + + osbuf = A_NETBUF_ALLOC(size); + if (osbuf == NULL) { + return A_NO_MEMORY; + } + A_NETBUF_PUT(osbuf, size); + register_set = (WMIX_GPIO_REGISTER_SET_CMD *)(A_NETBUF_DATA(osbuf)); + + register_set->gpioreg_id = gpioreg_id; + register_set->value = value; + + return (wmi_cmd_send_xtnd(wmip, osbuf, WMIX_GPIO_REGISTER_SET_CMDID, + NO_SYNC_WMIFLAG)); +} + +/* Send a command to the Target to fetch the value of a GPIO register. */ +int +wmi_gpio_register_get(struct wmi_t *wmip, + u32 gpioreg_id) +{ + void *osbuf; + WMIX_GPIO_REGISTER_GET_CMD *register_get; + int size; + + size = sizeof(*register_get); + + A_DPRINTF(DBG_WMI, (DBGFMT "Enter - reg=%d\n", DBGARG, gpioreg_id)); + + osbuf = A_NETBUF_ALLOC(size); + if (osbuf == NULL) { + return A_NO_MEMORY; + } + A_NETBUF_PUT(osbuf, size); + register_get = (WMIX_GPIO_REGISTER_GET_CMD *)(A_NETBUF_DATA(osbuf)); + + register_get->gpioreg_id = gpioreg_id; + + return (wmi_cmd_send_xtnd(wmip, osbuf, WMIX_GPIO_REGISTER_GET_CMDID, + NO_SYNC_WMIFLAG)); +} + +/* Send a command to the Target acknowledging some GPIO interrupts. */ +int +wmi_gpio_intr_ack(struct wmi_t *wmip, + u32 ack_mask) +{ + void *osbuf; + WMIX_GPIO_INTR_ACK_CMD *intr_ack; + int size; + + size = sizeof(*intr_ack); + + A_DPRINTF(DBG_WMI, (DBGFMT "Enter ack_mask=0x%x\n", DBGARG, ack_mask)); + + osbuf = A_NETBUF_ALLOC(size); + if (osbuf == NULL) { + return A_NO_MEMORY; + } + A_NETBUF_PUT(osbuf, size); + intr_ack = (WMIX_GPIO_INTR_ACK_CMD *)(A_NETBUF_DATA(osbuf)); + + intr_ack->ack_mask = ack_mask; + + return (wmi_cmd_send_xtnd(wmip, osbuf, WMIX_GPIO_INTR_ACK_CMDID, + NO_SYNC_WMIFLAG)); +} +#endif /* CONFIG_HOST_GPIO_SUPPORT */ + int wmi_set_access_params_cmd(struct wmi_t *wmip, u8 ac, u16 txop, u8 eCWmin, u8 eCWmax, u8 aifsn) @@ -4470,6 +4683,8 @@ wmi_tcmd_test_report_rx(struct wmi_t *wmip, u8 *datap, int len) A_DPRINTF(DBG_WMI, (DBGFMT "Enter\n", DBGARG)); + A_WMI_TCMD_RX_REPORT_EVENT(wmip->wmi_devt, datap, len); + return 0; } @@ -5285,6 +5500,19 @@ wmi_set_params_event_rx(struct wmi_t *wmip, u8 *datap, u32 len) } + +static int +wmi_acm_reject_event_rx(struct wmi_t *wmip, u8 *datap, u32 len) +{ + WMI_ACM_REJECT_EVENT *ev; + + ev = (WMI_ACM_REJECT_EVENT *)datap; + wmip->wmi_traffic_class = ev->trafficClass; + printk("ACM REJECT %d\n",wmip->wmi_traffic_class); + return 0; +} + + #ifdef CONFIG_HOST_DSET_SUPPORT int wmi_dset_data_reply(struct wmi_t *wmip, @@ -5649,7 +5877,7 @@ wmi_scan_indication (struct wmi_t *wmip) ar6000_scan_indication (wmip->wmi_devt, pAr6kScanIndEvent, size); - kfree(pAr6kScanIndEvent); + A_FREE(pAr6kScanIndEvent); } #endif @@ -5767,6 +5995,7 @@ int wmi_add_current_bss (struct wmi_t *wmip, u8 *id, bss_t *bss) return 0; } +#ifdef ATH_AR6K_11N_SUPPORT static int wmi_addba_req_event_rx(struct wmi_t *wmip, u8 *datap, int len) { @@ -5819,6 +6048,7 @@ wmi_btcoex_stats_event_rx(struct wmi_t * wmip,u8 *datap,int len) return 0; } +#endif static int wmi_hci_event_rx(struct wmi_t *wmip, u8 *datap, int len) @@ -6142,6 +6372,7 @@ wmi_ap_set_rateset(struct wmi_t *wmip, u8 rateset) return (wmi_cmd_send(wmip, osbuf, WMI_AP_SET_11BG_RATESET_CMDID, NO_SYNC_WMIFLAG)); } +#ifdef ATH_AR6K_11N_SUPPORT int wmi_set_ht_cap_cmd(struct wmi_t *wmip, WMI_SET_HT_CAP_CMD *cmd) { @@ -6187,6 +6418,7 @@ wmi_set_ht_op_cmd(struct wmi_t *wmip, u8 sta_chan_width) return (wmi_cmd_send(wmip, osbuf, WMI_SET_HT_OP_CMDID, NO_SYNC_WMIFLAG)); } +#endif int wmi_set_tx_select_rates_cmd(struct wmi_t *wmip, u32 *pMaskArray) @@ -6228,6 +6460,7 @@ wmi_send_hci_cmd(struct wmi_t *wmip, u8 *buf, u16 sz) return (wmi_cmd_send(wmip, osbuf, WMI_HCI_CMD_CMDID, NO_SYNC_WMIFLAG)); } +#ifdef ATH_AR6K_11N_SUPPORT int wmi_allow_aggr_cmd(struct wmi_t *wmip, u16 tx_tidmask, u16 rx_tidmask) { @@ -6287,6 +6520,7 @@ wmi_delete_aggr_cmd(struct wmi_t *wmip, u8 tid, bool uplink) /* Delete the local aggr state, on host */ return (wmi_cmd_send(wmip, osbuf, WMI_DELBA_REQ_CMDID, NO_SYNC_WMIFLAG)); } +#endif int wmi_set_rx_frame_format_cmd(struct wmi_t *wmip, u8 rxMetaVersion, diff --git a/trunk/drivers/staging/brcm80211/Kconfig b/trunk/drivers/staging/brcm80211/Kconfig index af74699263a3..b6f86354b69f 100644 --- a/trunk/drivers/staging/brcm80211/Kconfig +++ b/trunk/drivers/staging/brcm80211/Kconfig @@ -1,8 +1,11 @@ +menuconfig BRCM80211 + tristate "Broadcom IEEE802.11n WLAN drivers" + depends on WLAN + config BRCMSMAC - tristate "Broadcom IEEE802.11n PCIe SoftMAC WLAN driver" - default n + bool "Broadcom IEEE802.11n PCIe SoftMAC WLAN driver" depends on PCI - depends on WLAN && MAC80211 + depends on BRCM80211 && MAC80211 select FW_LOADER ---help--- This module adds support for PCIe wireless adapters based on Broadcom @@ -10,10 +13,9 @@ config BRCMSMAC be called brcmsmac.ko. config BRCMFMAC - tristate "Broadcom IEEE802.11n embedded FullMAC WLAN driver" - default n + bool "Broadcom IEEE802.11n embedded FullMAC WLAN driver" depends on MMC - depends on WLAN && CFG80211 + depends on BRCM80211 && CFG80211 select FW_LOADER select WIRELESS_EXT select WEXT_PRIV @@ -26,6 +28,6 @@ config BRCMFMAC config BRCMDBG bool "Broadcom driver debug functions" default n - depends on BRCMSMAC || BRCMFMAC + depends on BRCM80211 ---help--- Selecting this enables additional code for debug purposes. diff --git a/trunk/drivers/staging/brcm80211/README b/trunk/drivers/staging/brcm80211/README index 8ad558675bd3..f8facb0786ec 100644 --- a/trunk/drivers/staging/brcm80211/README +++ b/trunk/drivers/staging/brcm80211/README @@ -1,64 +1,90 @@ -Broadcom brcmsmac (mac80211-based softmac PCIe) and brcmfmac (SDIO) drivers. +Broadcom Mac80211 driver -Completely open source host drivers, no binary object files. +This is a driver in progress. It has features still to be implemented well as +bugs in current code. -Support for the following chips: -=============================== - brcmsmac (PCIe) - Name Device ID - BCM4313 0x4727 - BCM43224 0x4353 - BCM43225 0x4357 +What's here and not here +======================= +- Completely open source host driver, no binary object files +- Features Broadcom's OneDriver architecture (single source base for + supported chips and architectures) +- On-chip firmware loaded using standard request_firmware() +- Support for BCM43224, BCM43225, BCM4313 (PCIe NIC) +- Framework for supporting new chips, including mac80211-aware embedded chips +- Does not support older PCI/PCIe chips with SSB backplane +- Driver includes BMAC interface for transparent dongle support +- Uses minstrel_ht rate algorithm +- HW based encryption not enabled yet - brcmfmac (SDIO) - Name - BCM4329 -Both brcmsmac and brcmfmac drivers require firmware files that need to be -separately downloaded. +What's done +========== +- Integration with mac80211 stack +- A-MPDU single & dual stream rates +- BCM43224: Dualband, Dual stream, 20MHz channels + Throughput (in chamber): ~85-90 Mbits/sec (in both 2.4 & 5 GHz bands) +- BCM43225: 2.4 GHz, Dual Stream, 20MHz channels + Throughput (in chamber): ~85-90 Mbits/sec +- BCM4313: 2.4 GHz, Single Stream + Throughput (in chamber): ~40 Mbits/sec -Firmware + +Things To Be Done +================= +See the TODO file + + +Firmware installation ====================== Firmware is available from the Linux firmware repository at: - git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git - http://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git - https://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git + git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git + http://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git + https://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git +For all chips, copy brcm/bcm43xx-0.fw and brcm/bcm43xx_hdr-0.fw to +/lib/firmware/brcm (or wherever firmware is normally installed on your system). -=============================================================== -Broadcom brcmsmac driver -=============================================================== -- Support for both 32 and 64 bit Linux kernels +Currently supported chips +============== +PCI +Name Device ID +BCM4313 0x4727 +BCM43224 0x4353 +BCM43225 0x4357 -Firmware installation -====================== -Copy brcm/bcm43xx-0.fw and brcm/bcm43xx_hdr-0.fw to -/lib/firmware/brcm (or wherever firmware is normally installed -on your system). +Bugs/Problems +============== +- Driver can get confused while scanning during high throughput, can cause + burping, hanging, and possible crashing. +- Occasional hangs & burps with BCM43224 on 2.4 GHz with dual stream rates. +- Occasional crashes with BCM43224 on multicore machines. -=============================================================== -Broadcom brcmfmac driver -=============================================================== -- Support for 32 bit Linux kernel, 64 bit untested +Note on Regulatory Implementation +================================ +This generation of chips contain additional regulatory support independent of +the driver. The devices use a single worldwide regulatory domain, with channels +12-14 (2.4 GHz band) and channels 52-64 and 100-140 (5 GHz band) restricted to +passive operation. Transmission on those channels is suppressed until +appropriate other traffic is observed on those channels. +Within the driver, we use the fictitious country code "X2" to represent this +worldwide regulatory domain. There is currently no interface to configure a +different domain. -Firmware installation -====================== -Copy brcm/bcm4329-fullmac-4.bin and brcm/bcm4329-fullmac-4.txt -to /lib/firmware/brcm (or wherever firmware is normally installed on your -system). +The driver reads the SROM country code from the chip and hands it up to +mac80211 as the regulatory hint, however this information is otherwise unused +with the driver. Contact Info: ============= Brett Rudley brudley@broadcom.com Henry Ptasinski henryp@broadcom.com -Dowan Kim dowan@broadcom.com +Dowan Kim dowan@broadcom.com Roland Vossen rvossen@broadcom.com Arend van Spriel arend@broadcom.com -For more info, refer to: http://linuxwireless.org/en/users/Drivers/brcm80211 diff --git a/trunk/drivers/staging/brcm80211/TODO b/trunk/drivers/staging/brcm80211/TODO index e9c1393a2b92..24ebadbe4241 100644 --- a/trunk/drivers/staging/brcm80211/TODO +++ b/trunk/drivers/staging/brcm80211/TODO @@ -1,15 +1,51 @@ -To Do List for Broadcom Mac80211 driver before getting in mainline +To Do List for Broadcom Mac80211 driver + +Features to be added +===================== +- 40 MHz channels +- Power Save +- AP +- IBSS +- HW-based encryption +- LED support +- RFKILL +- Debugfs and debugability + +Code cleanup +============ +- Use proper kernel coding standards +- Remove overlap with system header files. (ie much of include/proto/*.h should + be removed) +- Purge unused variables/data structs/functions BUT keep code related to + features that are being added (ie AP mode, 40 Mhz channels, IBSS etc). +- Replace proprietary utility functions with public kernel versions. Bugs ==== -- Oops on AMPDU traffic, to be solved by new ucode (currently under test) - -brcmfmac and brcmsmac -===================== -- ASSERTS not allowed in mainline, replace by warning + error handling -- Replace printk and WL_ERROR() with proper routines +- Various occasional asserts/hangs +- Scanning during data transfer sometimes causes major slowdowns. Sometimes + revcovers when scan is done, other times not. +- Mac80211 API not completely implemented (ie ops_bss_info_changed, + ops_get_stats, etc) -brcmfmac -===================== +Other +===== +- wlc_mac80211.[ch], wl_mac80211.[ch] and linux_osl.c all need to be refactored + and combined. +- Merge files that are partially duplicated between the softmac and fullmac + drivers - Replace driver's proprietary ssb interface with generic kernel ssb module -- Build and test on 64 bit linux kernel + (only used when compiling for SDIO). +- PCI and SDIO support are currently #ifdef'ed exclusive of each other, which + leads to a separate wl.ko for each. This should be changed to runtime + handling of different interfaces so that a single binary driver can be built. +- Add support for new chips (obviously an ongoing item). + +Contact +===== +Brett Rudley +Henry Ptasinski +Dowan Kim +Roland Vossen +Arend van Spriel + diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/README b/trunk/drivers/staging/brcm80211/brcmfmac/README index 139597f9cb07..be29e4236920 100644 --- a/trunk/drivers/staging/brcm80211/brcmfmac/README +++ b/trunk/drivers/staging/brcm80211/brcmfmac/README @@ -1,2 +1,37 @@ +Broadcom fullmac driver +This is production driver. + +What's here +=========== +- Completely open source host driver, no binary object files +- Features Broadcom's OneDriver architecture (single source base for + supported chips and architectures) +- On-chip firmware loaded using standard request_firmware() +- Support for BCM4329(SDIO) + +What's done +========== +- Integration with cfg80211 stack +- Most of Mac functionality is performed in dongle +- A-MPDU single stream rates +- BCM4329: Dualband, Single stream, 20MHz channels + +Firmware installation +====================== +Firmware is available from the Linux firmware repository at: + + git://git.kernel.org/pub/scm/linux/kernel/git/dwmw2/linux-firmware.git + http://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git + https://git.kernel.org/?p=linux/kernel/git/dwmw2/linux-firmware.git + +For 4329 chip, copy brcm/bcm4329-fullmac-4.bin and brcm/bcm4329-fullmac-4.txt +to /lib/firmware/brcm (or wherever firmware is normally installed on your +system). + +Contact Info: +============= +Brett Rudley brudley@broadcom.com +Henry Ptasinski henryp@broadcom.com +Nohee Ko noheek@broadcom.com diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/bcmchip.h b/trunk/drivers/staging/brcm80211/brcmfmac/bcmchip.h deleted file mode 100644 index 29eeee200c9d..000000000000 --- a/trunk/drivers/staging/brcm80211/brcmfmac/bcmchip.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2011 Broadcom Corporation - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -#ifndef _bcmchip_h_ -#define _bcmchip_h_ - -/* Core reg address translation */ -#define CORE_CC_REG(base, field) (base + offsetof(chipcregs_t, field)) -#define CORE_BUS_REG(base, field) (base + offsetof(sdpcmd_regs_t, field)) -#define CORE_SB(base, field) \ - (base + SBCONFIGOFF + offsetof(sbconfig_t, field)) - -/* bcm4329 */ -/* SDIO device core, ID 0x829 */ -#define BCM4329_CORE_BUS_BASE 0x18011000 -/* internal memory core, ID 0x80e */ -#define BCM4329_CORE_SOCRAM_BASE 0x18003000 -/* ARM Cortex M3 core, ID 0x82a */ -#define BCM4329_CORE_ARM_BASE 0x18002000 - -#endif /* _bcmchip_h_ */ diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh.c b/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh.c index f15ee63e5f28..473f57d9f00b 100644 --- a/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh.c +++ b/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh.c @@ -17,7 +17,6 @@ #include #include -#include #include #include #include @@ -581,7 +580,7 @@ int bcmsdh_stop(void *sdh) int bcmsdh_query_device(void *sdh) { bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *) sdh; - bcmsdh->vendevid = (PCI_VENDOR_ID_BROADCOM << 16) | 0; + bcmsdh->vendevid = (VENDOR_BROADCOM << 16) | 0; return bcmsdh->vendevid; } diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_linux.c b/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_linux.c index 0188417b6593..ac5bbc8722e5 100644 --- a/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_linux.c +++ b/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_linux.c @@ -87,11 +87,11 @@ bool bcmsdh_chipmatch(u16 vendor, u16 device) return true; /* Check for BRCM 27XX Standard host controller */ - if (device == BCM27XX_SDIOH_ID && vendor == PCI_VENDOR_ID_BROADCOM) + if (device == BCM27XX_SDIOH_ID && vendor == VENDOR_BROADCOM) return true; /* Check for BRCM Standard host controller */ - if (device == SDIOH_FPGA_ID && vendor == PCI_VENDOR_ID_BROADCOM) + if (device == SDIOH_FPGA_ID && vendor == VENDOR_BROADCOM) return true; /* Check for TI PCIxx21 Standard host controller */ @@ -111,7 +111,7 @@ bool bcmsdh_chipmatch(u16 vendor, u16 device) #endif /* BCMSDIOH_STD */ #ifdef BCMSDIOH_SPI /* This is the PciSpiHost. */ - if (device == SPIH_FPGA_ID && vendor == PCI_VENDOR_ID_BROADCOM) { + if (device == SPIH_FPGA_ID && vendor == VENDOR_BROADCOM) { WL_NONE("Found PCI SPI Host Controller\n"); return true; } diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc.c b/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc.c index d76546234169..71c3571ee143 100644 --- a/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc.c +++ b/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc.c @@ -68,13 +68,6 @@ DHD_PM_RESUME_WAIT_INIT(sdioh_request_buffer_wait); int sdioh_sdmmc_card_regread(sdioh_info_t *sd, int func, u32 regaddr, int regsize, u32 *data); -void sdioh_sdio_set_host_pm_flags(int flag) -{ - if (sdio_set_host_pm_flags(gInstance->func[1], flag)) - printk(KERN_ERR "%s: Failed to set pm_flags 0x%08x\n",\ - __func__, (unsigned int)flag); -} - static int sdioh_sdmmc_card_enablefuncs(sdioh_info_t *sd) { int err_ret; diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc_linux.c b/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc_linux.c index bcacc38e347f..d738d4da5443 100644 --- a/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc_linux.c +++ b/trunk/drivers/staging/brcm80211/brcmfmac/bcmsdh_sdmmc_linux.c @@ -155,7 +155,7 @@ int sdioh_sdmmc_osinit(sdioh_info_t *sd) sdos->sd = sd; spin_lock_init(&sdos->lock); - return 0; + return BCME_OK; } void sdioh_sdmmc_osfree(sdioh_info_t *sd) diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/dhd_common.c b/trunk/drivers/staging/brcm80211/brcmfmac/dhd_common.c index 7d349b76092d..aa171f6181e9 100644 --- a/trunk/drivers/staging/brcm80211/brcmfmac/dhd_common.c +++ b/trunk/drivers/staging/brcm80211/brcmfmac/dhd_common.c @@ -902,7 +902,7 @@ wl_host_event(struct dhd_info *dhd, int *ifidx, void *pktdata, wl_show_host_event(event, event_data); #endif /* SHOW_EVENTS */ - return 0; + return BCME_OK; } /* Convert user's input in hex pattern to byte-size mask */ diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/dhd_linux.c b/trunk/drivers/staging/brcm80211/brcmfmac/dhd_linux.c index 5d4b643202b9..dd0375793875 100644 --- a/trunk/drivers/staging/brcm80211/brcmfmac/dhd_linux.c +++ b/trunk/drivers/staging/brcm80211/brcmfmac/dhd_linux.c @@ -2694,7 +2694,7 @@ dhd_wl_host_event(dhd_info_t *dhd, int *ifidx, void *pktdata, ASSERT(dhd != NULL); bcmerror = wl_host_event(dhd, ifidx, pktdata, event, data); - if (bcmerror != 0) + if (bcmerror != BCME_OK) return bcmerror; #if defined(CONFIG_WIRELESS_EXT) diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c b/trunk/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c index 14f470358182..464f52af1315 100644 --- a/trunk/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c +++ b/trunk/drivers/staging/brcm80211/brcmfmac/dhd_sdio.c @@ -15,7 +15,6 @@ */ #include -#include #include #include #include @@ -53,7 +52,6 @@ #include #include #include -#include #ifndef DHDSDIO_MEM_DUMP_FNAME #define DHDSDIO_MEM_DUMP_FNAME "mem_dump" @@ -167,28 +165,12 @@ typedef struct dhd_console { } dhd_console_t; #endif /* DHD_DEBUG */ -/* misc chip info needed by some of the routines */ -struct chip_info { - u32 chip; - u32 chiprev; - u32 cccorebase; - u32 ccrev; - u32 cccaps; - u32 buscorebase; - u32 buscorerev; - u32 buscoretype; - u32 ramcorebase; - u32 armcorebase; - u32 pmurev; -}; - /* Private data for SDIO bus interaction */ typedef struct dhd_bus { dhd_pub_t *dhd; bcmsdh_info_t *sdh; /* Handle for BCMSDH calls */ si_t *sih; /* Handle for SI calls */ - struct chip_info *ci; /* Chip info struct */ char *vars; /* Variables (from CIS and/or other) */ uint varsz; /* Size of variables buffer */ u32 sbaddr; /* Current SB window pointer (-1, invalid) */ @@ -482,7 +464,6 @@ static int dhdsdio_download_nvram(struct dhd_bus *bus); #ifdef BCMEMBEDIMAGE static int dhdsdio_download_code_array(struct dhd_bus *bus); #endif -static int dhdsdio_chip_attach(struct dhd_bus *bus, void *regs); static void dhd_dongle_setmemsize(struct dhd_bus *bus, int mem_size) { @@ -576,7 +557,7 @@ static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok) DHD_INFO(("CLKCTL: set PENDING\n")); bus->clkstate = CLK_PENDING; - return 0; + return BCME_OK; } else if (bus->clkstate == CLK_PENDING) { /* Cancel CA-only interrupt filter */ devctl = @@ -652,7 +633,7 @@ static int dhdsdio_htclk(dhd_bus_t *bus, bool on, bool pendok) return BCME_ERROR; } } - return 0; + return BCME_OK; } /* Change idle/active SD state */ @@ -739,7 +720,7 @@ static int dhdsdio_sdclk(dhd_bus_t *bus, bool on) bus->clkstate = CLK_NONE; } - return 0; + return BCME_OK; } /* Transition SD and backplane clock readiness */ @@ -757,7 +738,7 @@ static int dhdsdio_clkctl(dhd_bus_t *bus, uint target, bool pendok) dhd_os_wd_timer(bus->dhd, dhd_watchdog_ms); bus->activity = true; } - return 0; + return BCME_OK; } switch (target) { @@ -796,7 +777,7 @@ static int dhdsdio_clkctl(dhd_bus_t *bus, uint target, bool pendok) DHD_INFO(("dhdsdio_clkctl: %d -> %d\n", oldstate, bus->clkstate)); #endif /* DHD_DEBUG */ - return 0; + return BCME_OK; } int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep) @@ -811,7 +792,7 @@ int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep) /* Done if we're already in the requested state */ if (sleep == bus->sleeping) - return 0; + return BCME_OK; /* Going to sleep: set the alarm and turn off the lights... */ if (sleep) { @@ -883,7 +864,7 @@ int dhdsdio_bussleep(dhd_bus_t *bus, bool sleep) } } - return 0; + return BCME_OK; } #if defined(OOB_INTR_ONLY) @@ -1133,7 +1114,7 @@ int dhd_bus_txdata(struct dhd_bus *bus, struct sk_buff *pkt) DHD_ERROR(("%s: out of bus->txq !!!\n", __func__)); ret = BCME_NORESOURCE; } else { - ret = 0; + ret = BCME_OK; } dhd_os_sdunlock_txq(bus->dhd); @@ -1823,7 +1804,7 @@ static int dhdsdio_readshared(dhd_bus_t *bus, sdpcm_shared_t *sh) return BCME_ERROR; } - return 0; + return BCME_OK; } static int dhdsdio_checkdied(dhd_bus_t *bus, u8 *data, uint size) @@ -2038,7 +2019,7 @@ static int dhdsdio_readconsole(dhd_bus_t *bus) /* Skip reading the console buffer if the index pointer has not moved */ if (idx == c->last) - return 0; + return BCME_OK; /* Read the console buffer */ addr = le32_to_cpu(c->log.buf); @@ -2076,13 +2057,13 @@ static int dhdsdio_readconsole(dhd_bus_t *bus) } break2: - return 0; + return BCME_OK; } #endif /* DHD_DEBUG */ int dhdsdio_downloadvars(dhd_bus_t *bus, void *arg, int len) { - int bcmerror = 0; + int bcmerror = BCME_OK; DHD_TRACE(("%s: Enter\n", __func__)); @@ -2758,7 +2739,7 @@ dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name, if (set && strcmp(name, "sd_divisor") == 0) { if (bcmsdh_iovar_op(bus->sdh, "sd_divisor", NULL, 0, &bus->sd_divisor, sizeof(s32), - false) != 0) { + false) != BCME_OK) { bus->sd_divisor = -1; DHD_ERROR(("%s: fail on %s get\n", __func__, name)); @@ -2771,7 +2752,7 @@ dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name, if (set && strcmp(name, "sd_mode") == 0) { if (bcmsdh_iovar_op(bus->sdh, "sd_mode", NULL, 0, &bus->sd_mode, sizeof(s32), - false) != 0) { + false) != BCME_OK) { bus->sd_mode = -1; DHD_ERROR(("%s: fail on %s get\n", __func__, name)); @@ -2786,7 +2767,7 @@ dhd_bus_iovar_op(dhd_pub_t *dhdp, const char *name, if (bcmsdh_iovar_op (bus->sdh, "sd_blocksize", &fnum, sizeof(s32), &bus->blocksize, sizeof(s32), - false) != 0) { + false) != BCME_OK) { bus->blocksize = 0; DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize")); @@ -5108,7 +5089,7 @@ static void *dhdsdio_probe(u16 venid, u16 devid, u16 bus_no, /* Check the Vendor ID */ switch (venid) { case 0x0000: - case PCI_VENDOR_ID_BROADCOM: + case VENDOR_BROADCOM: break; default: DHD_ERROR(("%s: unknown vendor: 0x%04x\n", __func__, venid)); @@ -5307,10 +5288,6 @@ dhdsdio_probe_attach(struct dhd_bus *bus, void *sdh, void *regsva, u16 devid) DHD_ERROR(("%s: si_attach failed!\n", __func__)); goto fail; } - if (dhdsdio_chip_attach(bus, regsva)) { - DHD_ERROR(("%s: dhdsdio_chip_attach failed!\n", __func__)); - goto fail; - } bcmsdh_chipinfo(sdh, bus->sih->chip, bus->sih->chiprev); @@ -5448,7 +5425,7 @@ static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh) /* Query the SD clock speed */ if (bcmsdh_iovar_op(sdh, "sd_divisor", NULL, 0, &bus->sd_divisor, sizeof(s32), - false) != 0) { + false) != BCME_OK) { DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_divisor")); bus->sd_divisor = -1; } else { @@ -5458,7 +5435,7 @@ static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh) /* Query the SD bus mode */ if (bcmsdh_iovar_op(sdh, "sd_mode", NULL, 0, - &bus->sd_mode, sizeof(s32), false) != 0) { + &bus->sd_mode, sizeof(s32), false) != BCME_OK) { DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_mode")); bus->sd_mode = -1; } else { @@ -5469,7 +5446,7 @@ static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh) /* Query the F2 block size, set roundup accordingly */ fnum = 2; if (bcmsdh_iovar_op(sdh, "sd_blocksize", &fnum, sizeof(s32), - &bus->blocksize, sizeof(s32), false) != 0) { + &bus->blocksize, sizeof(s32), false) != BCME_OK) { bus->blocksize = 0; DHD_ERROR(("%s: fail on %s get\n", __func__, "sd_blocksize")); } else { @@ -5482,7 +5459,7 @@ static bool dhdsdio_probe_init(dhd_bus_t *bus, void *sdh) default to use if supported */ if (bcmsdh_iovar_op(sdh, "sd_rxchain", NULL, 0, &bus->sd_rxchain, sizeof(s32), - false) != 0) { + false) != BCME_OK) { bus->sd_rxchain = false; } else { DHD_INFO(("%s: bus module (through bcmsdh API) %s chaining\n", @@ -6093,234 +6070,3 @@ int dhd_bus_devreset(dhd_pub_t *dhdp, u8 flag) } return bcmerror; } - -static int -dhdsdio_chip_recognition(bcmsdh_info_t *sdh, struct chip_info *ci, void *regs) -{ - u32 regdata; - - /* - * Get CC core rev - * Chipid is assume to be at offset 0 from regs arg - * For different chiptypes or old sdio hosts w/o chipcommon, - * other ways of recognition should be added here. - */ - ci->cccorebase = (u32)regs; - regdata = bcmsdh_reg_read(sdh, CORE_CC_REG(ci->cccorebase, chipid), 4); - ci->chip = regdata & CID_ID_MASK; - ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT; - - DHD_INFO(("%s: chipid=0x%x chiprev=%d\n", - __func__, ci->chip, ci->chiprev)); - - /* Address of cores for new chips should be added here */ - switch (ci->chip) { - case BCM4329_CHIP_ID: - ci->buscorebase = BCM4329_CORE_BUS_BASE; - ci->ramcorebase = BCM4329_CORE_SOCRAM_BASE; - ci->armcorebase = BCM4329_CORE_ARM_BASE; - break; - default: - DHD_ERROR(("%s: chipid 0x%x is not supported\n", - __func__, ci->chip)); - return -ENODEV; - } - - regdata = bcmsdh_reg_read(sdh, - CORE_SB(ci->cccorebase, sbidhigh), 4); - ci->ccrev = SBCOREREV(regdata); - - regdata = bcmsdh_reg_read(sdh, - CORE_CC_REG(ci->cccorebase, pmucapabilities), 4); - ci->pmurev = regdata & PCAP_REV_MASK; - - regdata = bcmsdh_reg_read(sdh, CORE_SB(ci->buscorebase, sbidhigh), 4); - ci->buscorerev = SBCOREREV(regdata); - ci->buscoretype = (regdata & SBIDH_CC_MASK) >> SBIDH_CC_SHIFT; - - DHD_INFO(("%s: ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n", - __func__, ci->ccrev, ci->pmurev, - ci->buscorerev, ci->buscoretype)); - - /* get chipcommon capabilites */ - ci->cccaps = bcmsdh_reg_read(sdh, - CORE_CC_REG(ci->cccorebase, capabilities), 4); - - return 0; -} - -static void -dhdsdio_chip_disablecore(bcmsdh_info_t *sdh, u32 corebase) -{ - u32 regdata; - - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbtmstatelow), 4); - if (regdata & SBTML_RESET) - return; - - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbtmstatelow), 4); - if ((regdata & (SICF_CLOCK_EN << SBTML_SICF_SHIFT)) != 0) { - /* - * set target reject and spin until busy is clear - * (preserve core-specific bits) - */ - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbtmstatelow), 4); - bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, - regdata | SBTML_REJ); - - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbtmstatelow), 4); - udelay(1); - SPINWAIT((bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbtmstatehigh), 4) & - SBTMH_BUSY), 100000); - - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbtmstatehigh), 4); - if (regdata & SBTMH_BUSY) - DHD_ERROR(("%s: ARM core still busy\n", __func__)); - - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbidlow), 4); - if (regdata & SBIDL_INIT) { - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbimstate), 4) | - SBIM_RJ; - bcmsdh_reg_write(sdh, - CORE_SB(corebase, sbimstate), 4, - regdata); - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbimstate), 4); - udelay(1); - SPINWAIT((bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbimstate), 4) & - SBIM_BY), 100000); - } - - /* set reset and reject while enabling the clocks */ - bcmsdh_reg_write(sdh, - CORE_SB(corebase, sbtmstatelow), 4, - (((SICF_FGC | SICF_CLOCK_EN) << SBTML_SICF_SHIFT) | - SBTML_REJ | SBTML_RESET)); - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbtmstatelow), 4); - udelay(10); - - /* clear the initiator reject bit */ - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbidlow), 4); - if (regdata & SBIDL_INIT) { - regdata = bcmsdh_reg_read(sdh, - CORE_SB(corebase, sbimstate), 4) & - ~SBIM_RJ; - bcmsdh_reg_write(sdh, - CORE_SB(corebase, sbimstate), 4, - regdata); - } - } - - /* leave reset and reject asserted */ - bcmsdh_reg_write(sdh, CORE_SB(corebase, sbtmstatelow), 4, - (SBTML_REJ | SBTML_RESET)); - udelay(1); -} - -static int -dhdsdio_chip_attach(struct dhd_bus *bus, void *regs) -{ - struct chip_info *ci; - int err; - u8 clkval, clkset; - - DHD_TRACE(("%s: Enter\n", __func__)); - - /* alloc chip_info_t */ - ci = kmalloc(sizeof(struct chip_info), GFP_ATOMIC); - if (NULL == ci) { - DHD_ERROR(("%s: malloc failed!\n", __func__)); - return -ENOMEM; - } - - memset((unsigned char *)ci, 0, sizeof(struct chip_info)); - - /* bus/core/clk setup for register access */ - /* Try forcing SDIO core to do ALPAvail request only */ - clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ; - bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, - clkset, &err); - if (err) { - DHD_ERROR(("%s: error writing for HT off\n", __func__)); - goto fail; - } - - /* If register supported, wait for ALPAvail and then force ALP */ - /* This may take up to 15 milliseconds */ - clkval = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, - SBSDIO_FUNC1_CHIPCLKCSR, NULL); - if ((clkval & ~SBSDIO_AVBITS) == clkset) { - SPINWAIT(((clkval = - bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, - SBSDIO_FUNC1_CHIPCLKCSR, - NULL)), - !SBSDIO_ALPAV(clkval)), - PMU_MAX_TRANSITION_DLY); - if (!SBSDIO_ALPAV(clkval)) { - DHD_ERROR(("%s: timeout on ALPAV wait, clkval 0x%02x\n", - __func__, clkval)); - err = -EBUSY; - goto fail; - } - clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | - SBSDIO_FORCE_ALP; - bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, - SBSDIO_FUNC1_CHIPCLKCSR, - clkset, &err); - udelay(65); - } else { - DHD_ERROR(("%s: ChipClkCSR access: wrote 0x%02x read 0x%02x\n", - __func__, clkset, clkval)); - err = -EACCES; - goto fail; - } - - /* Also, disable the extra SDIO pull-ups */ - bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_SDIOPULLUP, 0, - NULL); - - err = dhdsdio_chip_recognition(bus->sdh, ci, regs); - if (err) - goto fail; - - /* - * Make sure any on-chip ARM is off (in case strapping is wrong), - * or downloaded code was already running. - */ - dhdsdio_chip_disablecore(bus->sdh, ci->armcorebase); - - bcmsdh_reg_write(bus->sdh, - CORE_CC_REG(ci->cccorebase, gpiopullup), 4, 0); - bcmsdh_reg_write(bus->sdh, - CORE_CC_REG(ci->cccorebase, gpiopulldown), 4, 0); - - /* Disable F2 to clear any intermediate frame state on the dongle */ - bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_0, SDIOD_CCCR_IOEN, - SDIO_FUNC_ENABLE_1, NULL); - - /* WAR: cmd52 backplane read so core HW will drop ALPReq */ - clkval = bcmsdh_cfg_read(bus->sdh, SDIO_FUNC_1, - 0, NULL); - - /* Done with backplane-dependent accesses, can drop clock... */ - bcmsdh_cfg_write(bus->sdh, SDIO_FUNC_1, SBSDIO_FUNC1_CHIPCLKCSR, 0, - NULL); - - bus->ci = ci; - return 0; -fail: - bus->ci = NULL; - kfree(ci); - return err; -} diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c b/trunk/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c index b44daf959e8f..555b056b49b1 100644 --- a/trunk/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c +++ b/trunk/drivers/staging/brcm80211/brcmfmac/wl_cfg80211.c @@ -39,8 +39,6 @@ #include #include -void sdioh_sdio_set_host_pm_flags(int flag); - static struct sdio_func *cfg80211_sdio_func; static struct wl_dev *wl_cfg80211_dev; static const u8 ether_bcast[ETH_ALEN] = {255, 255, 255, 255, 255, 255}; @@ -1990,8 +1988,6 @@ static s32 wl_cfg80211_suspend(struct wiphy *wiphy) clear_bit(WL_STATUS_SCANNING, &wl->status); clear_bit(WL_STATUS_SCAN_ABORTING, &wl->status); - sdioh_sdio_set_host_pm_flags(MMC_PM_KEEP_POWER); - return err; } diff --git a/trunk/drivers/staging/brcm80211/brcmfmac/wl_iw.c b/trunk/drivers/staging/brcm80211/brcmfmac/wl_iw.c index 4e4cf36af51c..b49957fb7586 100644 --- a/trunk/drivers/staging/brcm80211/brcmfmac/wl_iw.c +++ b/trunk/drivers/staging/brcm80211/brcmfmac/wl_iw.c @@ -3672,10 +3672,8 @@ int wl_iw_attach(struct net_device *dev, void *dhdp) return -ENOMEM; iscan->iscan_ex_params_p = kmalloc(params_size, GFP_KERNEL); - if (!iscan->iscan_ex_params_p) { - kfree(iscan); + if (!iscan->iscan_ex_params_p) return -ENOMEM; - } iscan->iscan_ex_param_size = params_size; iscan->sysioc_tsk = NULL; diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/Makefile b/trunk/drivers/staging/brcm80211/brcmsmac/Makefile index 65a1a2508859..c4aafe5cf7f5 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/Makefile +++ b/trunk/drivers/staging/brcm80211/brcmsmac/Makefile @@ -38,7 +38,6 @@ BRCMSMAC_OFILES := \ wlc_channel.o \ wlc_main.o \ wlc_phy_shim.o \ - wlc_pmu.o \ wlc_rate.o \ wlc_stf.o \ phy/wlc_phy_cmn.o \ @@ -53,6 +52,7 @@ BRCMSMAC_OFILES := \ ../util/bcmotp.o \ ../util/bcmsrom.o \ ../util/hnddma.o \ + ../util/hndpmu.o \ ../util/nicpci.o \ ../util/qmath.o \ ../util/nvram/nvram_ro.o diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_cmn.c b/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_cmn.c index 873d64c9d60c..8f75af2ffc58 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_cmn.c +++ b/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_cmn.c @@ -155,6 +155,8 @@ char *phy_getvar(phy_info_t *pi, const char *name) char *s; int len; + ASSERT(pi->vars != (char *)&pi->vars); + if (!name) return NULL; @@ -239,7 +241,7 @@ u16 read_radio_reg(phy_info_t *pi, u16 addr) break; default: - break; + ASSERT(VALID_PHYTYPE(pi->pubpi.phy_type)); } if ((D11REV_GE(pi->sh->corerev, 24)) || @@ -577,6 +579,9 @@ shared_phy_t *wlc_phy_shared_attach(shared_phy_params_t *shp) void wlc_phy_shared_detach(shared_phy_t *phy_sh) { if (phy_sh) { + if (phy_sh->phy_head) { + ASSERT(!phy_sh->phy_head); + } kfree(phy_sh); } } @@ -591,7 +596,7 @@ wlc_phy_t *wlc_phy_attach(shared_phy_t *sh, void *regs, int bandtype, char *vars if (D11REV_IS(sh->corerev, 4)) sflags = SISF_2G_PHY | SISF_5G_PHY; else - sflags = ai_core_sflags(sh->sih, 0, 0); + sflags = si_core_sflags(sh->sih, 0, 0); if (BAND_5G(bandtype)) { if ((sflags & (SISF_5G_PHY | SISF_DB_PHY)) == 0) { @@ -776,6 +781,8 @@ void wlc_phy_detach(wlc_phy_t *pih) pi->sh->phy_head = pi->next; else if (pi->sh->phy_head->next == pi) pi->sh->phy_head->next = NULL; + else + ASSERT(0); if (pi->pi_fptr.detach) (pi->pi_fptr.detach) (pi); @@ -887,6 +894,7 @@ u32 wlc_phy_clk_bwbits(wlc_phy_t *pih) phy_bw_clkbits = SICF_BW40; break; default: + ASSERT(0); break; } } @@ -959,16 +967,19 @@ void WLBANDINITFN(wlc_phy_init) (wlc_phy_t *pih, chanspec_t chanspec) "wlc_phy_init: Called with the MAC running!" == NULL); } + ASSERT(pi != NULL); + if (!(pi->measure_hold & PHY_HOLD_FOR_SCAN)) { pi->measure_hold |= PHY_HOLD_FOR_NOT_ASSOC; } if (D11REV_GE(pi->sh->corerev, 5)) - ASSERT(ai_core_sflags(pi->sh->sih, 0, 0) & SISF_FCLKA); + ASSERT(si_core_sflags(pi->sh->sih, 0, 0) & SISF_FCLKA); phy_init = pi->pi_fptr.init; if (phy_init == NULL) { + ASSERT(phy_init != NULL); return; } @@ -1018,6 +1029,8 @@ int wlc_phy_down(wlc_phy_t *pih) phy_info_t *pi = (phy_info_t *) pih; int callbacks = 0; + ASSERT(pi->phytest_on == false); + if (pi->phycal_timer && !wlapi_del_timer(pi->sh->physhim, pi->phycal_timer)) callbacks++; @@ -1057,6 +1070,8 @@ wlc_phy_table_addr(phy_info_t *pi, uint tbl_id, uint tbl_offset, void wlc_phy_table_data_write(phy_info_t *pi, uint width, u32 val) { + ASSERT((width == 8) || (width == 16) || (width == 32)); + if ((pi->sh->chip == BCM43224_CHIP_ID || pi->sh->chip == BCM43421_CHIP_ID) && (pi->sh->chiprev == 1) && @@ -1090,6 +1105,8 @@ wlc_phy_write_table(phy_info_t *pi, const phytbl_info_t *ptbl_info, const u16 *ptbl_16b = (const u16 *)ptbl_info->tbl_ptr; const u32 *ptbl_32b = (const u32 *)ptbl_info->tbl_ptr; + ASSERT((tbl_width == 8) || (tbl_width == 16) || (tbl_width == 32)); + write_phy_reg(pi, tblAddr, (tbl_id << 10) | tbl_offset); for (idx = 0; idx < ptbl_info->tbl_len; idx++) { @@ -1131,6 +1148,8 @@ wlc_phy_read_table(phy_info_t *pi, const phytbl_info_t *ptbl_info, u16 *ptbl_16b = (u16 *)ptbl_info->tbl_ptr; u32 *ptbl_32b = (u32 *)ptbl_info->tbl_ptr; + ASSERT((tbl_width == 8) || (tbl_width == 16) || (tbl_width == 32)); + write_phy_reg(pi, tblAddr, (tbl_id << 10) | tbl_offset); for (idx = 0; idx < ptbl_info->tbl_len; idx++) { @@ -1239,6 +1258,7 @@ void wlc_phy_do_dummy_tx(phy_info_t *pi, bool ofdm, bool pa_on) W_REG(®s->txe_phyctl, (ofdm ? 1 : 0) | PHY_TXC_ANT_0); if (ISNPHY(pi) || ISLCNPHY(pi)) { + ASSERT(ofdm); W_REG(®s->txe_phyctl1, 0x1A02); } @@ -1297,6 +1317,7 @@ void wlc_phy_do_dummy_tx(phy_info_t *pi, bool ofdm, bool pa_on) void wlc_phy_hold_upd(wlc_phy_t *pih, mbool id, bool set) { phy_info_t *pi = (phy_info_t *) pih; + ASSERT(id); if (set) { mboolset(pi->measure_hold, id); @@ -1418,6 +1439,8 @@ void wlc_phy_chanspec_set(wlc_phy_t *ppi, chanspec_t chanspec) u16 m_cur_channel; chansetfn_t chanspec_set = NULL; + ASSERT(!wf_chspec_malformed(chanspec)); + m_cur_channel = CHSPEC_CHANNEL(chanspec); if (CHSPEC_IS5G(chanspec)) m_cur_channel |= D11_CURCHANNEL_5G; @@ -1457,7 +1480,8 @@ int wlc_phy_chanspec_bandrange_get(phy_info_t *pi, chanspec_t chanspec) range = wlc_phy_get_chan_freq_range_nphy(pi, channel); } else if (ISLCNPHY(pi)) { range = wlc_phy_chanspec_freq2bandrange_lpssn(freq); - } + } else + ASSERT(0); return range; } @@ -1487,6 +1511,8 @@ wlc_phy_chanspec_band_validch(wlc_phy_t *ppi, uint band, chanvec_t *channels) uint i; uint channel; + ASSERT((band == WLC_BAND_2G) || (band == WLC_BAND_5G)); + memset(channels, 0, sizeof(chanvec_t)); for (i = 0; i < ARRAY_SIZE(chan_info_all); i++) { @@ -1509,6 +1535,8 @@ chanspec_t wlc_phy_chanspec_band_firstch(wlc_phy_t *ppi, uint band) uint channel; chanspec_t chspec; + ASSERT((band == WLC_BAND_2G) || (band == WLC_BAND_5G)); + for (i = 0; i < ARRAY_SIZE(chan_info_all); i++) { channel = chan_info_all[i].chan; @@ -1544,6 +1572,8 @@ chanspec_t wlc_phy_chanspec_band_firstch(wlc_phy_t *ppi, uint band) return chspec; } + ASSERT(0); + return (chanspec_t) INVCHANSPEC; } @@ -1551,6 +1581,7 @@ int wlc_phy_txpower_get(wlc_phy_t *ppi, uint *qdbm, bool *override) { phy_info_t *pi = (phy_info_t *) ppi; + ASSERT(qdbm != NULL); *qdbm = pi->tx_user_target[0]; if (override != NULL) *override = pi->txpwroverride; @@ -1672,6 +1703,7 @@ wlc_phy_txpower_sromlimit(wlc_phy_t *ppi, uint channel, u8 *min_pwr, break; } } + ASSERT(i < ARRAY_SIZE(chan_info_all)); if (pi->hwtxpwr) { *max_pwr = pi->hwtxpwr[i]; @@ -2102,6 +2134,7 @@ void wlc_phy_txpower_update_shm(phy_info_t *pi) { int j; if (ISNPHY(pi)) { + ASSERT(0); return; } @@ -2433,6 +2466,8 @@ void wlc_phy_ant_rxdiv_set(wlc_phy_t *ppi, u8 val) mod_phy_reg(pi, 0x410, (0x1 << 1), 0x00 << 1); mod_phy_reg(pi, 0x410, (0x1 << 0), (u16) val << 0); } + } else { + ASSERT(0); } if (!suspend) @@ -2448,6 +2483,7 @@ wlc_phy_noise_calc_phy(phy_info_t *pi, u32 *cmplx_pwr, s8 *pwr_ant) u8 i; memset((u8 *) cmplx_pwr_dbm, 0, sizeof(cmplx_pwr_dbm)); + ASSERT(pi->pubpi.phy_corenum <= PHY_CORE_MAX); wlc_phy_compute_dB(cmplx_pwr, cmplx_pwr_dbm, pi->pubpi.phy_corenum); for (i = 0; i < pi->pubpi.phy_corenum; i++) { @@ -2493,6 +2529,7 @@ wlc_phy_noise_sample_request(wlc_phy_t *pih, u8 reason, u8 ch) break; default: + ASSERT(0); break; } @@ -2641,6 +2678,7 @@ static s8 wlc_phy_noise_read_shmem(phy_info_t *pi) s8 noise_dbm = PHY_NOISE_FIXED_VAL_NPHY; u8 idx, core; + ASSERT(pi->pubpi.phy_corenum <= PHY_CORE_MAX); memset((u8 *) cmplx_pwr, 0, sizeof(cmplx_pwr)); memset((u8 *) noise_dbm_ant, 0, sizeof(noise_dbm_ant)); @@ -2722,6 +2760,8 @@ void wlc_phy_noise_sample_intr(wlc_phy_t *pih) channel = jssi_aux & D11_CURCHANNEL_MAX; noise_dbm = wlc_phy_noise_read_shmem(pi); + } else { + ASSERT(0); } wlc_phy_noise_cb(pi, channel, noise_dbm); @@ -2831,7 +2871,10 @@ void BCMFASTPATH wlc_phy_rssi_compute(wlc_phy_t *pih, void *ctx) rssi -= 256; } else if (radioid == BCM2055_ID || radioid == BCM2056_ID || radioid == BCM2057_ID) { + ASSERT(ISNPHY(pi)); rssi = wlc_phy_rssi_compute_nphy(pi, wlc_rxhdr); + } else { + ASSERT((const char *)"Unknown radio" == NULL); } end: @@ -2857,6 +2900,9 @@ void wlc_phy_set_deaf(wlc_phy_t *ppi, bool user_flag) wlc_lcnphy_deaf_mode(pi, true); else if (ISNPHY(pi)) wlc_nphy_deaf_mode(pi, true); + else { + ASSERT(0); + } } void wlc_phy_watchdog(wlc_phy_t *pih) @@ -3117,9 +3163,13 @@ void wlc_phy_cal_perical(wlc_phy_t *pih, u8 reason) } else if (pi->nphy_perical == PHY_PERICAL_SPHASE) wlc_phy_cal_perical_nphy_run(pi, PHY_PERICAL_AUTO); + else { + ASSERT(0); + } } break; default: + ASSERT(0); break; } } @@ -3261,12 +3311,12 @@ void wlc_lcnphy_epa_switch(phy_info_t *pi, bool mode) mod_phy_reg(pi, 0x44c, (0x1 << 2), (1) << 2); } - ai_corereg(pi->sh->sih, SI_CC_IDX, + si_corereg(pi->sh->sih, SI_CC_IDX, offsetof(chipcregs_t, gpiocontrol), ~0x0, 0x0); - ai_corereg(pi->sh->sih, SI_CC_IDX, + si_corereg(pi->sh->sih, SI_CC_IDX, offsetof(chipcregs_t, gpioout), 0x40, 0x40); - ai_corereg(pi->sh->sih, SI_CC_IDX, + si_corereg(pi->sh->sih, SI_CC_IDX, offsetof(chipcregs_t, gpioouten), 0x40, 0x40); } else { @@ -3274,11 +3324,11 @@ void wlc_lcnphy_epa_switch(phy_info_t *pi, bool mode) mod_phy_reg(pi, 0x44d, (0x1 << 2), (0) << 2); - ai_corereg(pi->sh->sih, SI_CC_IDX, + si_corereg(pi->sh->sih, SI_CC_IDX, offsetof(chipcregs_t, gpioout), 0x40, 0x00); - ai_corereg(pi->sh->sih, SI_CC_IDX, + si_corereg(pi->sh->sih, SI_CC_IDX, offsetof(chipcregs_t, gpioouten), 0x40, 0x0); - ai_corereg(pi->sh->sih, SI_CC_IDX, + si_corereg(pi->sh->sih, SI_CC_IDX, offsetof(chipcregs_t, gpiocontrol), ~0x0, 0x40); } @@ -3341,6 +3391,8 @@ u32 wlc_phy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision) { u32 quotient, remainder, roundup, rbit; + ASSERT(divisor); + quotient = dividend / divisor; remainder = dividend % divisor; rbit = divisor & 1; diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_lcn.c b/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_lcn.c index 9f5ee40b2edb..a5a7bb82ab42 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_lcn.c +++ b/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_lcn.c @@ -1081,6 +1081,8 @@ wlc_lcnphy_qdiv_roundup(u32 dividend, u32 divisor, u8 precision) { u32 quotient, remainder, roundup, rbit; + ASSERT(divisor); + quotient = dividend / divisor; remainder = dividend % divisor; rbit = divisor & 1; @@ -1778,6 +1780,11 @@ void wlc_lcnphy_set_tx_pwr_ctrl(phy_info_t *pi, u16 mode) s8 index; phy_info_lcnphy_t *pi_lcn = pi->u.pi_lcnphy; + ASSERT((LCNPHY_TX_PWR_CTRL_OFF == mode) || + (LCNPHY_TX_PWR_CTRL_SW == mode) || + (LCNPHY_TX_PWR_CTRL_HW == mode) || + (LCNPHY_TX_PWR_CTRL_TEMPBASED == mode)); + mode = wlc_lcnphy_set_tx_pwr_ctrl_mode(pi, mode); old_mode = wlc_lcnphy_set_tx_pwr_ctrl_mode(pi, old_mode); @@ -1897,14 +1904,16 @@ wlc_lcnphy_tx_iqlo_cal(phy_info_t *pi, break; case LCNPHY_CAL_RECAL: + ASSERT(pi_lcn->lcnphy_cal_results.txiqlocal_bestcoeffs_valid); + start_coeffs = syst_coeffs; + cal_cmds = commands_recal; n_cal_cmds = ARRAY_SIZE(commands_recal); command_nums = command_nums_recal; break; - default: - break; + ASSERT(false); } wlc_lcnphy_common_write_table(pi, LCNPHY_TBL_ID_IQLOCAL, @@ -2451,6 +2460,8 @@ void wlc_lcnphy_set_tx_pwr_by_index(phy_info_t *pi, int index) lcnphy_txgains_t gains; phy_info_lcnphy_t *pi_lcn = pi->u.pi_lcnphy; + ASSERT(index <= LCNPHY_MAX_TX_POWER_INDEX); + pi_lcn->lcnphy_tx_power_idx_override = (s8) index; pi_lcn->lcnphy_current_index = (u8) index; @@ -2749,6 +2760,7 @@ wlc_lcnphy_start_tx_tone(phy_info_t *pi, s32 f_kHz, u16 max_val, do { bw = phy_bw * 1000 * k; num_samps = bw / ABS(f_kHz); + ASSERT(num_samps <= ARRAY_SIZE(data_buf)); k++; } while ((num_samps * (u32) (ABS(f_kHz))) != bw); } else @@ -3286,6 +3298,8 @@ wlc_lcnphy_rx_iq_cal(phy_info_t *pi, const lcnphy_rx_iqcomp_t *iqcomp, return false; } if (module == 2) { + ASSERT(iqcomp_sz); + while (iqcomp_sz--) { if (iqcomp[iqcomp_sz].chan == CHSPEC_CHANNEL(pi->radio_chanspec)) { @@ -3299,6 +3313,7 @@ wlc_lcnphy_rx_iq_cal(phy_info_t *pi, const lcnphy_rx_iqcomp_t *iqcomp, break; } } + ASSERT(result); goto cal_done; } @@ -3569,6 +3584,9 @@ void wlc_lcnphy_calib_modes(phy_info_t *pi, uint mode) if (wlc_lcnphy_tempsense_based_pwr_ctrl_enabled(pi)) wlc_lcnphy_tx_power_adjustment((wlc_phy_t *) pi); break; + default: + ASSERT(0); + break; } } @@ -5054,6 +5072,8 @@ bool wlc_phy_attach_lcnphy(phy_info_t *pi) } pi->xtalfreq = si_alp_clock(pi->sh->sih); + ASSERT(0 == (pi->xtalfreq % 1000)); + pi_lcn->lcnphy_papd_rxGnCtrl_init = 0; pi->pi_fptr.init = wlc_phy_init_lcnphy; @@ -5273,7 +5293,9 @@ wlc_lcnphy_load_tx_iir_filter(phy_info_t *pi, bool is_ofdm, s16 filt_type) } } - if (filt_index != -1) { + if (filt_index == -1) { + ASSERT(false); + } else { for (j = 0; j < LCNPHY_NUM_DIG_FILT_COEFFS; j++) { write_phy_reg(pi, addr[j], LCNPHY_txdigfiltcoeffs_cck @@ -5288,7 +5310,9 @@ wlc_lcnphy_load_tx_iir_filter(phy_info_t *pi, bool is_ofdm, s16 filt_type) } } - if (filt_index != -1) { + if (filt_index == -1) { + ASSERT(false); + } else { for (j = 0; j < LCNPHY_NUM_DIG_FILT_COEFFS; j++) { write_phy_reg(pi, addr_ofdm[j], LCNPHY_txdigfiltcoeffs_ofdm diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_n.c b/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_n.c index ccc79fde03a5..7947c6028b6e 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_n.c +++ b/trunk/drivers/staging/brcm80211/brcmsmac/phy/wlc_phy_n.c @@ -14218,6 +14218,8 @@ static void WLBANDINITFN(wlc_phy_bphy_init_nphy) (phy_info_t *pi) { u16 addr, val; + ASSERT(ISNPHY(pi)); + val = 0x1e1f; for (addr = (NPHY_TO_BPHY_OFF + BPHY_RSSI_LUT); addr <= (NPHY_TO_BPHY_OFF + BPHY_RSSI_LUT_END); addr++) { @@ -14365,6 +14367,8 @@ static void WLBANDINITFN(wlc_phy_tbl_init_nphy) (phy_info_t *pi) break; default: + + ASSERT(0); break; } @@ -14397,6 +14401,8 @@ static void WLBANDINITFN(wlc_phy_tbl_init_nphy) (phy_info_t *pi) [idx]); break; default: + + ASSERT(0); break; } } else { @@ -14544,7 +14550,7 @@ void WLBANDINITFN(wlc_phy_init_nphy) (phy_info_t *pi) (pi->sh->chippkg == BCM4718_PKG_ID))) { if ((pi->sh->boardflags & BFL_EXTLNA) && (CHSPEC_IS2G(pi->radio_chanspec))) { - ai_corereg(pi->sh->sih, SI_CC_IDX, + si_corereg(pi->sh->sih, SI_CC_IDX, offsetof(chipcregs_t, chipcontrol), 0x40, 0x40); } @@ -14560,6 +14566,8 @@ void WLBANDINITFN(wlc_phy_init_nphy) (phy_info_t *pi) regs = (d11regs_t *) si_switch_core(pi->sh->sih, D11_CORE_ID, &origidx, &intr_val); + ASSERT(regs != NULL); + d11_clk_ctl_st = R_REG(®s->clk_ctl_st); AND_REG(®s->clk_ctl_st, ~(CCS_FORCEHT | CCS_HTAREQ)); @@ -14775,7 +14783,10 @@ void WLBANDINITFN(wlc_phy_init_nphy) (phy_info_t *pi) rfpwr_offset = (s16) nphy_papd_padgain_dlt_2g_2057rev7 [pad_gn]; + } else { + ASSERT(0); } + } else { if ((pi->pubpi.radiorev == 3) || (pi->pubpi.radiorev == 4) || @@ -14789,6 +14800,8 @@ void WLBANDINITFN(wlc_phy_init_nphy) (phy_info_t *pi) rfpwr_offset = (s16) nphy_papd_pgagain_dlt_5g_2057rev7 [pga_gn]; + } else { + ASSERT(0); } } wlc_phy_table_write_nphy(pi, @@ -14892,10 +14905,10 @@ void WLBANDINITFN(wlc_phy_init_nphy) (phy_info_t *pi) } if (wlc_phy_cal_txiqlo_nphy - (pi, target_gain, true, false) == 0) { + (pi, target_gain, true, false) == BCME_OK) { if (wlc_phy_cal_rxiq_nphy (pi, target_gain, 2, - false) == 0) { + false) == BCME_OK) { wlc_phy_savecal_nphy(pi); } @@ -16117,6 +16130,8 @@ static void wlc_phy_workarounds_nphy(phy_info_t *pi) 0x18, 16, bcm_adc_vmid); wlc_phy_table_write_nphy(pi, NPHY_TBL_ID_AFECTRL, 4, 0x1c, 16, bcm_adc_gain); + } else { + ASSERT(0); } write_radio_reg(pi, @@ -17495,6 +17510,7 @@ static void wlc_phy_radio_init_2056(phy_info_t *pi) break; default: + ASSERT(0); break; } } @@ -17555,6 +17571,7 @@ static void wlc_phy_radio_init_2057(phy_info_t *pi) regs_2057_ptr = regs_2057_rev5v1; } else { + ASSERT(0); break; } @@ -17569,8 +17586,11 @@ static void wlc_phy_radio_init_2057(phy_info_t *pi) break; default: + ASSERT(0); break; } + } else { + ASSERT(0); } wlc_phy_init_radio_regs_allbands(pi, regs_2057_ptr); @@ -17688,6 +17708,7 @@ wlc_phy_chan2freq_nphy(phy_info_t *pi, uint channel, int *f, } if (i >= tbl_len) { + ASSERT(i < tbl_len); goto fail; } if (pi->pubpi.radiorev == 5) { @@ -17744,6 +17765,7 @@ wlc_phy_chan2freq_nphy(phy_info_t *pi, uint channel, int *f, } if (i >= tbl_len) { + ASSERT(i < tbl_len); goto fail; } *t1 = &chan_info_tbl_p_1[i]; @@ -17755,6 +17777,7 @@ wlc_phy_chan2freq_nphy(phy_info_t *pi, uint channel, int *f, break; if (i >= ARRAY_SIZE(chan_info_nphy_2055)) { + ASSERT(i < ARRAY_SIZE(chan_info_nphy_2055)); goto fail; } *t3 = &chan_info_nphy_2055[i]; @@ -19562,6 +19585,8 @@ void wlc_phy_antsel_init(wlc_phy_t *ppi, bool lut_init) 1, 0x08, 16, &v2); wlc_phy_table_write_nphy(pi, NPHY_TBL_ID_ANTSWCTRLLUT, 1, 0x0C, 16, &v3); + } else { + ASSERT(0); } if (pi->srom_fem5g.antswctrllut == 0) { @@ -19573,6 +19598,8 @@ void wlc_phy_antsel_init(wlc_phy_t *ppi, bool lut_init) 1, 0x18, 16, &v2); wlc_phy_table_write_nphy(pi, NPHY_TBL_ID_ANTSWCTRLLUT, 1, 0x1C, 16, &v3); + } else { + ASSERT(0); } } else { @@ -19691,6 +19718,8 @@ wlc_phy_set_rfseq_nphy(phy_info_t *pi, u8 cmd, u8 *events, u8 *dlys, 3) ? NPHY_REV3_RFSEQ_CMD_END : NPHY_RFSEQ_CMD_END; u8 end_dly = 1; + ASSERT(len <= 16); + if (pi->phyhang_avoid) wlc_phy_stay_in_carriersearch_nphy(pi, true); @@ -21474,6 +21503,8 @@ wlc_phy_rssi_compute_nphy(phy_info_t *pi, wlc_d11rxhdr_t *wlc_rxh) rxpwr = (rxpwr0 < rxpwr1) ? rxpwr0 : rxpwr1; else if (pi->sh->rssi_mode == RSSI_ANT_MERGE_AVG) rxpwr = (rxpwr0 + rxpwr1) >> 1; + else + ASSERT(0); return rxpwr; } @@ -22202,6 +22233,8 @@ static void wlc_phy_rssi_cal_nphy_rev3(phy_info_t *pi) static void wlc_phy_restore_rssical_nphy(phy_info_t *pi) { + ASSERT(NREV_GE(pi->pubpi.phy_rev, 3)); + if (CHSPEC_IS2G(pi->radio_chanspec)) { if (pi->nphy_rssical_chanspec_2G == 0) return; @@ -22372,7 +22405,7 @@ wlc_phy_tx_tone_nphy(phy_info_t *pi, u32 f_kHz, u16 max_val, wlc_phy_runsamples_nphy(pi, num_samps, loops, wait, iqmode, dac_test_mode, modify_bbmult); - return 0; + return BCME_OK; } static void @@ -22742,6 +22775,8 @@ wlc_phy_iqcal_gainparams_nphy(phy_info_t *pi, u16 core_no, } } + ASSERT(idx != -1); + params->txgm = tbl_iqcal_gainparams_nphy[band_idx][k][1]; params->pga = tbl_iqcal_gainparams_nphy[band_idx][k][2]; params->pad = tbl_iqcal_gainparams_nphy[band_idx][k][3]; @@ -23820,6 +23855,8 @@ void wlc_phy_cal_perical_nphy_run(phy_info_t *pi, u8 caltype) if (PHY_MUTED(pi)) return; + ASSERT(pi->nphy_perical != PHY_PERICAL_DISABLE); + if (caltype == PHY_PERICAL_AUTO) fullcal = (pi->radio_chanspec != pi->nphy_txiqlocal_chanspec); else if (caltype == PHY_PERICAL_PARTIAL) @@ -23876,7 +23913,7 @@ void wlc_phy_cal_perical_nphy_run(phy_info_t *pi, u8 caltype) target_gain = pi->nphy_cal_target_gain; } - if (0 == + if (BCME_OK == wlc_phy_cal_txiqlo_nphy(pi, target_gain, fullcal, mphase)) { if (PHY_IPA(pi)) wlc_phy_a4(pi, true); @@ -23888,7 +23925,7 @@ void wlc_phy_cal_perical_nphy_run(phy_info_t *pi, u8 caltype) wlapi_suspend_mac_and_wait(pi->sh->physhim); wlc_phyreg_enter((wlc_phy_t *) pi); - if (0 == wlc_phy_cal_rxiq_nphy(pi, target_gain, + if (BCME_OK == wlc_phy_cal_rxiq_nphy(pi, target_gain, (pi-> first_cal_after_assoc || (pi-> @@ -23918,6 +23955,8 @@ void wlc_phy_cal_perical_nphy_run(phy_info_t *pi, u8 caltype) wlc_phy_radio205x_vcocal_nphy(pi); } } else { + ASSERT(pi->nphy_perical >= PHY_PERICAL_MPHASE); + switch (pi->mphase_cal_phase_id) { case MPHASE_CAL_STATE_INIT: pi->nphy_perical_last = pi->sh->now; @@ -23941,7 +23980,7 @@ void wlc_phy_cal_perical_nphy_run(phy_info_t *pi, u8 caltype) if (wlc_phy_cal_txiqlo_nphy (pi, pi->nphy_cal_target_gain, fullcal, - true) != 0) { + true) != BCME_OK) { wlc_phy_cal_perical_mphase_reset(pi); break; @@ -23973,7 +24012,7 @@ void wlc_phy_cal_perical_nphy_run(phy_info_t *pi, u8 caltype) (pi->first_cal_after_assoc || (pi->cal_type_override == PHY_PERICAL_FULL)) ? 2 : 0, - false) == 0) { + false) == BCME_OK) { wlc_phy_savecal_nphy(pi); } @@ -24013,6 +24052,7 @@ void wlc_phy_cal_perical_nphy_run(phy_info_t *pi, u8 caltype) break; default: + ASSERT(0); wlc_phy_cal_perical_mphase_reset(pi); break; } @@ -24076,7 +24116,7 @@ wlc_phy_cal_txiqlo_nphy(phy_info_t *pi, nphy_txgains_t target_gain, void *tbl_ptr; bool ladder_updated[2]; u8 mphase_cal_lastphase = 0; - int bcmerror = 0; + int bcmerror = BCME_OK; bool phyhang_avoid_state = false; u16 tbl_tx_iqlo_cal_loft_ladder_20[] = { @@ -24202,13 +24242,13 @@ wlc_phy_cal_txiqlo_nphy(phy_info_t *pi, nphy_txgains_t target_gain, if (pi->mphase_cal_phase_id > MPHASE_CAL_STATE_TXPHASE0) { wlc_phy_runsamples_nphy(pi, phy_bw * 8, 0xffff, 0, 1, 0, false); - bcmerror = 0; + bcmerror = BCME_OK; } else { bcmerror = wlc_phy_tx_tone_nphy(pi, tone_freq, max_val, 1, 0, false); } - if (bcmerror == 0) { + if (bcmerror == BCME_OK) { if (pi->mphase_cal_phase_id > MPHASE_CAL_STATE_TXPHASE0) { tbl_ptr = pi->mphase_txcal_bestcoeffs; @@ -24428,6 +24468,8 @@ static void wlc_phy_reapply_txcal_coeffs_nphy(phy_info_t *pi) { u16 tbl_buf[7]; + ASSERT(NREV_LT(pi->pubpi.phy_rev, 2)); + if ((pi->nphy_txiqlocal_chanspec == pi->radio_chanspec) && (pi->nphy_txiqlocal_coeffsvalid)) { wlc_phy_table_read_nphy(pi, NPHY_TBL_ID_IQLOCAL, @@ -24505,6 +24547,7 @@ wlc_phy_rx_iq_est_nphy(phy_info_t *pi, phy_iq_est_t *est, u16 num_samps, ASSERT((read_phy_reg(pi, 0x129) & NPHY_IqestCmd_iqstart) == 0); if ((read_phy_reg(pi, 0x129) & NPHY_IqestCmd_iqstart) == 0) { + ASSERT(pi->pubpi.phy_corenum <= PHY_CORE_MAX); for (core = 0; core < pi->pubpi.phy_corenum; core++) { est[core].i_pwr = (read_phy_reg(pi, NPHY_IqestipwrAccHi(core)) << 16) @@ -24529,7 +24572,7 @@ static void wlc_phy_calc_rx_iq_comp_nphy(phy_info_t *pi, u8 core_mask) u32 ii = 0, qq = 0; s16 iq_nbits, qq_nbits, brsh, arsh; s32 a, b, temp; - int bcmerror = 0; + int bcmerror = BCME_OK; uint cal_retry = 0; if (core_mask == 0x0) @@ -24628,7 +24671,7 @@ static void wlc_phy_calc_rx_iq_comp_nphy(phy_info_t *pi, u8 core_mask) } } - if (bcmerror != 0) { + if (bcmerror != BCME_OK) { printk("%s: Failed, cnt = %d\n", __func__, cal_retry); if (cal_retry < CAL_RETRY_CNT) { @@ -25408,7 +25451,7 @@ wlc_phy_rxcal_gainctrl_nphy_rev5(phy_info_t *pi, u8 rx_core, break; default: - break; + ASSERT(0); } if ((curr_gaintbl_index < 0) || @@ -25873,7 +25916,7 @@ wlc_phy_cal_rxiq_nphy_rev3(phy_info_t *pi, nphy_txgains_t target_gain, wlc_phy_stay_in_carriersearch_nphy(pi, false); - return 0; + return BCME_OK; } static int @@ -25898,7 +25941,7 @@ wlc_phy_cal_rxiq_nphy_rev2(phy_info_t *pi, nphy_txgains_t target_gain, u16 cal_gain[2]; nphy_iqcal_params_t cal_params[2]; u8 phy_bw; - int bcmerror = 0; + int bcmerror = BCME_OK; bool first_playtone = true; wlc_phy_stay_in_carriersearch_nphy(pi, true); @@ -26048,7 +26091,7 @@ wlc_phy_cal_rxiq_nphy_rev2(phy_info_t *pi, nphy_txgains_t target_gain, 0, 0, 0, true); } - if (bcmerror == 0) { + if (bcmerror == BCME_OK) { if (gain_pass < 3) { wlc_phy_rx_iq_est_nphy(pi, est, @@ -26071,7 +26114,7 @@ wlc_phy_cal_rxiq_nphy_rev2(phy_info_t *pi, nphy_txgains_t target_gain, wlc_phy_stopplayback_nphy(pi); } - if (bcmerror != 0) + if (bcmerror != BCME_OK) break; } @@ -26087,7 +26130,7 @@ wlc_phy_cal_rxiq_nphy_rev2(phy_info_t *pi, nphy_txgains_t target_gain, 0xa7, orig_AfectrlCore); write_phy_reg(pi, 0xa2, orig_RfseqCoreActv); - if (bcmerror != 0) + if (bcmerror != BCME_OK) break; } @@ -26227,6 +26270,8 @@ static u32 *wlc_phy_get_ipa_gaintbl_nphy(phy_info_t *pi) tx_pwrctrl_tbl = nphy_tpc_txgain_ipa_2g_2057rev7; + } else { + ASSERT(0); } } else if (NREV_IS(pi->pubpi.phy_rev, 6)) { @@ -26258,6 +26303,8 @@ static u32 *wlc_phy_get_ipa_gaintbl_nphy(phy_info_t *pi) tx_pwrctrl_tbl = nphy_tpc_txgain_ipa_5g_2057rev7; + } else { + ASSERT(0); } } else { @@ -26300,6 +26347,8 @@ wlc_phy_papd_cal_setup_nphy(phy_info_t *pi, nphy_papd_restore_state *state, || (pi->pubpi.radiorev == 6)) { mixgain = 0x00; + } else { + ASSERT(0); } } else { @@ -26312,6 +26361,8 @@ wlc_phy_papd_cal_setup_nphy(phy_info_t *pi, nphy_papd_restore_state *state, || (pi->pubpi.radiorev == 8)) { mixgain = 0x0; + } else { + ASSERT(0); } } @@ -26413,6 +26464,8 @@ wlc_phy_papd_cal_setup_nphy(phy_info_t *pi, nphy_papd_restore_state *state, WRITE_RADIO_REG3(pi, RADIO_2057, TX, core, TXRXCOUPLE_2G_ATTEN, 0xf0); + } else { + ASSERT(0); } WRITE_RADIO_REG3(pi, RADIO_2057, TX, off_core, @@ -26671,6 +26724,8 @@ wlc_phy_a1_nphy(phy_info_t *pi, u8 core, u32 winsz, u32 start, u32 *buf, *src, *dst, sz; sz = end - start + 1; + ASSERT(end > start); + ASSERT(end < NPHY_PAPD_EPS_TBL_SIZE); buf = kmalloc(2 * sizeof(u32) * NPHY_PAPD_EPS_TBL_SIZE, GFP_ATOMIC); if (NULL == buf) { @@ -26732,6 +26787,8 @@ wlc_phy_a2_nphy(phy_info_t *pi, nphy_ipa_txcalgains_t *txgains, phy_a7 = (core == PHY_CORE_0) ? 1 : 0; + ASSERT((cal_mode == CAL_FULL) || (cal_mode == CAL_GCTRL) + || (cal_mode == CAL_SOFT)); phy_a6 = ((cal_mode == CAL_GCTRL) || (cal_mode == CAL_SOFT)) ? true : false; @@ -27276,6 +27333,8 @@ static void wlc_phy_a4(phy_info_t *pi, bool full_cal) nphy_papd_cal_gain_index [phy_b5], phy_b5); + } else { + ASSERT(0); } phy_b1[phy_b5].gains.pad[phy_b5] = @@ -27358,6 +27417,8 @@ static void wlc_phy_a4(phy_info_t *pi, bool full_cal) -(nphy_papd_padgain_dlt_2g_2057rev7 [phy_b8] + 1) / 2; + } else { + ASSERT(0); } } else { phy_b7 = phy_b1[phy_b5].gains.pga[phy_b5]; @@ -27374,6 +27435,8 @@ static void wlc_phy_a4(phy_info_t *pi, bool full_cal) -(nphy_papd_pgagain_dlt_5g_2057rev7 [phy_b7] + 1) / 2; + } else { + ASSERT(0); } phy_b10 = -9; @@ -27473,6 +27536,8 @@ void wlc_phy_txpwr_fixpower_nphy(phy_info_t *pi) u8 txpi[2], chan_freq_range; s32 rfpwr_offset; + ASSERT(pi->nphy_txpwrctrl == PHY_TPC_HW_OFF); + if (pi->phyhang_avoid) wlc_phy_stay_in_carriersearch_nphy(pi, true); @@ -29114,6 +29179,7 @@ wlc_phy_txpower_sromlimit_get_nphy(phy_info_t *pi, uint chan, u8 *max_pwr, *max_pwr = pi->tx_srom_max_rate_5g_hi[txp_rate_idx]; break; default: + ASSERT(0); *max_pwr = pi->tx_srom_max_rate_2g[txp_rate_idx]; break; } @@ -29141,6 +29207,8 @@ void wlc_phy_stay_in_carriersearch_nphy(phy_info_t *pi, bool enable) wlc_phy_resetcca_nphy(pi); } else { + ASSERT(pi->nphy_deaf_count > 0); + pi->nphy_deaf_count--; if (pi->nphy_deaf_count == 0) { diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/wl_mac80211.c b/trunk/drivers/staging/brcm80211/brcmsmac/wl_mac80211.c index 61da97f21060..c1b07ae31674 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/wl_mac80211.c +++ b/trunk/drivers/staging/brcm80211/brcmsmac/wl_mac80211.c @@ -48,8 +48,6 @@ #include "wl_ucode.h" #include "wl_mac80211.h" -#define N_TX_QUEUES 4 /* #tx queues on mac80211<->driver interface */ - static void wl_timer(unsigned long data); static void _wl_timer(struct wl_timer *t); @@ -554,7 +552,7 @@ wl_ops_conf_tx(struct ieee80211_hw *hw, u16 queue, params->txop, params->cw_min, params->cw_max, params->aifs); WL_LOCK(wl); - wlc_wme_setparams(wl->wlc, queue, params, true); + wlc_wme_setparams(wl->wlc, queue, (void *)params, true); WL_UNLOCK(wl); return 0; @@ -1072,7 +1070,8 @@ static int ieee_hw_init(struct ieee80211_hw *hw) | IEEE80211_HW_AMPDU_AGGREGATION; hw->extra_tx_headroom = wlc_get_header_len(); - hw->queues = N_TX_QUEUES; + /* FIXME: should get this from wlc->machwcap */ + hw->queues = 4; /* FIXME: this doesn't seem to be used properly in minstrel_ht. * mac80211/status.c:ieee80211_tx_status() checks this value, * but mac80211/rc80211_minstrel_ht.c:minstrel_ht_get_rate() diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_ampdu.c b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_ampdu.c index 07fbc3d46c8e..f00865957881 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_ampdu.c +++ b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_ampdu.c @@ -164,6 +164,10 @@ struct ampdu_info *wlc_ampdu_attach(struct wlc_info *wlc) struct ampdu_info *ampdu; int i; + /* some code depends on packed structures */ + ASSERT(DOT11_MAXNUMFRAGS == NBITS(u16)); + ASSERT(ISPOWEROF2(AMPDU_TX_BA_MAX_WSIZE)); + ASSERT(ISPOWEROF2(AMPDU_RX_BA_MAX_WSIZE)); ASSERT(wlc->pub->tunables->ampdunummpdu <= AMPDU_MAX_MPDU); ASSERT(wlc->pub->tunables->ampdunummpdu > 0); @@ -402,7 +406,7 @@ static int wlc_ffpld_check_txfunfl(struct wlc_info *wlc, int fid) /* compute a new dma xfer rate for max_mpdu @ max mcs. This is the minimum dma rate that - can achieve no underflow condition for the current mpdu size. + can achieve no unferflow condition for the current mpdu size. */ /* note : we divide/multiply by 100 to avoid integer overflows */ fifo->dmaxferrate = @@ -683,10 +687,7 @@ wlc_sendampdu(struct ampdu_info *ampdu, struct wlc_txq_info *qi, WL_NONE("sendampdu: sgi %d, is40 %d, mcs %d\n", sgi, is40, mcs); - /* XXX Fix me to honor real max_rxlen */ - /* can fix this as soon as ampdu_action() in mac80211.h - * gets extra u8buf_size par */ - maxlen = 64 * 1024; + maxlen = 64 * 1024; /* XXX Fix me to honor real max_rxlen */ if (is40) mimo_ctlchbw = @@ -1122,12 +1123,21 @@ wlc_ampdu_dotxstatus_complete(struct ampdu_info *ampdu, struct scb *scb, ini->txretry[index] = 0; /* ampdu_ack_len: number of acked aggregated frames */ + /* ampdu_ack_map: block ack bit map for the aggregation */ /* ampdu_len: number of aggregated frames */ rate_status(wlc, tx_info, txs, mcs); tx_info->flags |= IEEE80211_TX_STAT_ACK; tx_info->flags |= IEEE80211_TX_STAT_AMPDU; + + /* XXX TODO: Make these accurate. */ tx_info->status.ampdu_ack_len = - tx_info->status.ampdu_len = 1; + (txs-> + status & TX_STATUS_FRM_RTX_MASK) >> + TX_STATUS_FRM_RTX_SHIFT; + tx_info->status.ampdu_len = + (txs-> + status & TX_STATUS_FRM_RTX_MASK) >> + TX_STATUS_FRM_RTX_SHIFT; skb_pull(p, D11_PHY_HDR_LEN); skb_pull(p, D11_TXH_LEN); @@ -1153,8 +1163,6 @@ wlc_ampdu_dotxstatus_complete(struct ampdu_info *ampdu, struct scb *scb, /* Retry timeout */ ini->tx_in_transit--; ieee80211_tx_info_clear_status(tx_info); - tx_info->status.ampdu_ack_len = 0; - tx_info->status.ampdu_len = 1; tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK; skb_pull(p, D11_PHY_HDR_LEN); diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_bmac.c b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_bmac.c index f52b3392d670..4b6e181c7dc9 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_bmac.c +++ b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_bmac.c @@ -235,7 +235,7 @@ static u32 WLBANDINITFN(wlc_setband_inact) (struct wlc_info *wlc, uint bandunit) WL_TRACE("wl%d: wlc_setband_inact\n", wlc_hw->unit); ASSERT(bandunit != wlc_hw->band->bandunit); - ASSERT(ai_iscoreup(wlc_hw->sih)); + ASSERT(si_iscoreup(wlc_hw->sih)); ASSERT((R_REG(&wlc_hw->regs->maccontrol) & MCTL_EN_MAC) == 0); @@ -547,6 +547,8 @@ static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme) * TX: TX_AC_BK_FIFO (TX AC Background data packets) * RX: RX_FIFO (RX data packets) */ + ASSERT(TX_AC_BK_FIFO == 0); + ASSERT(RX_FIFO == 0); wlc_hw->di[0] = dma_attach(name, wlc_hw->sih, (wme ? DMAREG(wlc_hw, DMA_TX, 0) : NULL), DMAREG(wlc_hw, DMA_RX, 0), @@ -561,6 +563,8 @@ static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme) * (legacy) TX_DATA_FIFO (TX data packets) * RX: UNUSED */ + ASSERT(TX_AC_BE_FIFO == 1); + ASSERT(TX_DATA_FIFO == 1); wlc_hw->di[1] = dma_attach(name, wlc_hw->sih, DMAREG(wlc_hw, DMA_TX, 1), NULL, tune->ntxd, 0, 0, -1, 0, 0, @@ -572,6 +576,7 @@ static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme) * TX: TX_AC_VI_FIFO (TX AC Video data packets) * RX: UNUSED */ + ASSERT(TX_AC_VI_FIFO == 2); wlc_hw->di[2] = dma_attach(name, wlc_hw->sih, DMAREG(wlc_hw, DMA_TX, 2), NULL, tune->ntxd, 0, 0, -1, 0, 0, @@ -582,6 +587,8 @@ static bool wlc_bmac_attach_dmapio(struct wlc_info *wlc, uint j, bool wme) * TX: TX_AC_VO_FIFO (TX AC Voice data packets) * (legacy) TX_CTL_FIFO (TX control & mgmt packets) */ + ASSERT(TX_AC_VO_FIFO == 3); + ASSERT(TX_CTL_FIFO == 3); wlc_hw->di[3] = dma_attach(name, wlc_hw->sih, DMAREG(wlc_hw, DMA_TX, 3), NULL, tune->ntxd, 0, 0, -1, @@ -641,6 +648,7 @@ int wlc_bmac_attach(struct wlc_info *wlc, u16 vendor, u16 device, uint unit, WL_TRACE("wl%d: wlc_bmac_attach: vendor 0x%x device 0x%x\n", unit, vendor, device); + ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF); wme = true; @@ -707,7 +715,7 @@ int wlc_bmac_attach(struct wlc_info *wlc, u16 vendor, u16 device, uint unit, /* set bar0 window to point at D11 core */ wlc_hw->regs = (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID, 0); - wlc_hw->corerev = ai_corerev(wlc_hw->sih); + wlc_hw->corerev = si_corerev(wlc_hw->sih); regs = wlc_hw->regs; @@ -1222,7 +1230,7 @@ int wlc_bmac_down_finish(struct wlc_hw_info *wlc_hw) } else { /* Reset and disable the core */ - if (ai_iscoreup(wlc_hw->sih)) { + if (si_iscoreup(wlc_hw->sih)) { if (R_REG(&wlc_hw->regs->maccontrol) & MCTL_EN_MAC) wlc_suspend_mac_and_wait(wlc_hw->wlc); @@ -1312,7 +1320,7 @@ static void wlc_clkctl_clk(struct wlc_hw_info *wlc_hw, uint mode) /* check fast clock is available (if core is not in reset) */ if (wlc_hw->forcefastclk && wlc_hw->clk) - ASSERT(ai_core_sflags(wlc_hw->sih, 0, 0) & SISF_FCLKA); + ASSERT(si_core_sflags(wlc_hw->sih, 0, 0) & SISF_FCLKA); /* keep the ucode wake bit on if forcefastclk is on * since we do not want ucode to put us back to slow clock @@ -1376,6 +1384,7 @@ wlc_bmac_mhf(struct wlc_hw_info *wlc_hw, u8 idx, u16 mask, u16 val, ASSERT((val & ~mask) == 0); ASSERT(idx < MHFMAX); + ASSERT(ARRAY_SIZE(addr) == MHFMAX); switch (bands) { /* Current band only or all bands, @@ -1451,6 +1460,8 @@ static void wlc_write_mhf(struct wlc_hw_info *wlc_hw, u16 *mhfs) M_HOST_FLAGS5 }; + ASSERT(ARRAY_SIZE(addr) == MHFMAX); + for (idx = 0; idx < MHFMAX; idx++) { wlc_bmac_write_shm(wlc_hw, addr[idx], mhfs[idx]); } @@ -1832,17 +1843,17 @@ static void wlc_bmac_core_phy_clk(struct wlc_hw_info *wlc_hw, bool clk) if (OFF == clk) { /* clear gmode bit, put phy into reset */ - ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC | SICF_GMODE), + si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC | SICF_GMODE), (SICF_PRST | SICF_FGC)); udelay(1); - ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_PRST); + si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_PRST); udelay(1); } else { /* take phy out of reset */ - ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_FGC); + si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_FGC), SICF_FGC); udelay(1); - ai_core_cflags(wlc_hw->sih, (SICF_FGC), 0); + si_core_cflags(wlc_hw->sih, (SICF_FGC), 0); udelay(1); } @@ -1853,16 +1864,16 @@ void wlc_bmac_core_phypll_reset(struct wlc_hw_info *wlc_hw) { WL_TRACE("wl%d: wlc_bmac_core_phypll_reset\n", wlc_hw->unit); - ai_corereg(wlc_hw->sih, SI_CC_IDX, + si_corereg(wlc_hw->sih, SI_CC_IDX, offsetof(chipcregs_t, chipcontrol_addr), ~0, 0); udelay(1); - ai_corereg(wlc_hw->sih, SI_CC_IDX, + si_corereg(wlc_hw->sih, SI_CC_IDX, offsetof(chipcregs_t, chipcontrol_data), 0x4, 0); udelay(1); - ai_corereg(wlc_hw->sih, SI_CC_IDX, + si_corereg(wlc_hw->sih, SI_CC_IDX, offsetof(chipcregs_t, chipcontrol_data), 0x4, 4); udelay(1); - ai_corereg(wlc_hw->sih, SI_CC_IDX, + si_corereg(wlc_hw->sih, SI_CC_IDX, offsetof(chipcregs_t, chipcontrol_data), 0x4, 0); udelay(1); } @@ -1877,18 +1888,18 @@ void wlc_bmac_phyclk_fgc(struct wlc_hw_info *wlc_hw, bool clk) return; if (ON == clk) - ai_core_cflags(wlc_hw->sih, SICF_FGC, SICF_FGC); + si_core_cflags(wlc_hw->sih, SICF_FGC, SICF_FGC); else - ai_core_cflags(wlc_hw->sih, SICF_FGC, 0); + si_core_cflags(wlc_hw->sih, SICF_FGC, 0); } void wlc_bmac_macphyclk_set(struct wlc_hw_info *wlc_hw, bool clk) { if (ON == clk) - ai_core_cflags(wlc_hw->sih, SICF_MPCLKE, SICF_MPCLKE); + si_core_cflags(wlc_hw->sih, SICF_MPCLKE, SICF_MPCLKE); else - ai_core_cflags(wlc_hw->sih, SICF_MPCLKE, 0); + si_core_cflags(wlc_hw->sih, SICF_MPCLKE, 0); } void wlc_bmac_phy_reset(struct wlc_hw_info *wlc_hw) @@ -1908,7 +1919,7 @@ void wlc_bmac_phy_reset(struct wlc_hw_info *wlc_hw) if (WLCISNPHY(wlc_hw->band) && NREV_GE(wlc_hw->band->phyrev, 3) && NREV_LE(wlc_hw->band->phyrev, 4)) { /* Set the PHY bandwidth */ - ai_core_cflags(wlc_hw->sih, SICF_BWMASK, phy_bw_clkbits); + si_core_cflags(wlc_hw->sih, SICF_BWMASK, phy_bw_clkbits); udelay(1); @@ -1916,12 +1927,12 @@ void wlc_bmac_phy_reset(struct wlc_hw_info *wlc_hw) wlc_bmac_core_phypll_reset(wlc_hw); /* reset the PHY */ - ai_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_PCLKE), + si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_PCLKE), (SICF_PRST | SICF_PCLKE)); phy_in_reset = true; } else { - ai_core_cflags(wlc_hw->sih, + si_core_cflags(wlc_hw->sih, (SICF_PRST | SICF_PCLKE | SICF_BWMASK), (SICF_PRST | SICF_PCLKE | phy_bw_clkbits)); } @@ -1944,9 +1955,9 @@ WLBANDINITFN(wlc_bmac_setband) (struct wlc_hw_info *wlc_hw, uint bandunit, ASSERT(bandunit != wlc_hw->band->bandunit); /* Enable the d11 core before accessing it */ - if (!ai_iscoreup(wlc_hw->sih)) { - ai_core_reset(wlc_hw->sih, 0, 0); - ASSERT(ai_iscoreup(wlc_hw->sih)); + if (!si_iscoreup(wlc_hw->sih)) { + si_core_reset(wlc_hw->sih, 0, 0); + ASSERT(si_iscoreup(wlc_hw->sih)); wlc_mctrl_reset(wlc_hw); } @@ -1988,7 +1999,7 @@ void WLBANDINITFN(wlc_setxband) (struct wlc_hw_info *wlc_hw, uint bandunit) /* set gmode core flag */ if (wlc_hw->sbclk && !wlc_hw->noreset) { - ai_core_cflags(wlc_hw->sih, SICF_GMODE, + si_core_cflags(wlc_hw->sih, SICF_GMODE, ((bandunit == 0) ? SICF_GMODE : 0)); } } @@ -2023,7 +2034,7 @@ static bool wlc_validboardtype(struct wlc_hw_info *wlc_hw) goodboard = false; } - if (wlc_hw->sih->boardvendor != PCI_VENDOR_ID_BROADCOM) + if (wlc_hw->sih->boardvendor != VENDOR_BROADCOM) return goodboard; return goodboard; @@ -2085,7 +2096,7 @@ bool wlc_bmac_radio_read_hwdisabled(struct wlc_hw_info *wlc_hw) wlc_hw->regs = (d11regs_t *) si_setcore(wlc_hw->sih, D11_CORE_ID, 0); - ai_core_reset(wlc_hw->sih, flags, resetbits); + si_core_reset(wlc_hw->sih, flags, resetbits); wlc_mctrl_reset(wlc_hw); } @@ -2093,7 +2104,7 @@ bool wlc_bmac_radio_read_hwdisabled(struct wlc_hw_info *wlc_hw) /* put core back into reset */ if (!clk) - ai_core_disable(wlc_hw->sih, 0); + si_core_disable(wlc_hw->sih, 0); if (!xtal) wlc_bmac_xtal(wlc_hw, OFF); @@ -2178,7 +2189,7 @@ void wlc_bmac_corereset(struct wlc_hw_info *wlc_hw, u32 flags) wlc_clkctl_clk(wlc_hw, CLK_FAST); /* reset the dma engines except first time thru */ - if (ai_iscoreup(wlc_hw->sih)) { + if (si_iscoreup(wlc_hw->sih)) { for (i = 0; i < NFIFO; i++) if ((wlc_hw->di[i]) && (!dma_txreset(wlc_hw->di[i]))) { WL_ERROR("wl%d: %s: dma_txreset[%d]: cannot stop dma\n", @@ -2213,7 +2224,7 @@ void wlc_bmac_corereset(struct wlc_hw_info *wlc_hw, u32 flags) * with other driver like mips/arm since they may touch chipcommon as well. */ wlc_hw->clk = false; - ai_core_reset(wlc_hw->sih, flags, resetbits); + si_core_reset(wlc_hw->sih, flags, resetbits); wlc_hw->clk = true; if (wlc_hw->band && wlc_hw->band->pi) wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, true); @@ -2332,7 +2343,7 @@ static void wlc_coreinit(struct wlc_info *wlc) wlc_gpio_init(wlc); - sflags = ai_core_sflags(wlc_hw->sih, 0, 0); + sflags = si_core_sflags(wlc_hw->sih, 0, 0); if (D11REV_IS(wlc_hw->corerev, 23)) { if (WLCISNPHY(wlc_hw->band)) @@ -3469,7 +3480,7 @@ void wlc_coredisable(struct wlc_hw_info *wlc_hw) si_gpiocontrol(wlc_hw->sih, ~0, 0, GPIO_DRV_PRIORITY); wlc_hw->clk = false; - ai_core_disable(wlc_hw->sih, 0); + si_core_disable(wlc_hw->sih, 0); wlc_phy_hw_clk_state_upd(wlc_hw->band->pi, false); } diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_main.c b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_main.c index fce937821cf7..ab7ab850e199 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_main.c +++ b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_main.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -525,7 +524,7 @@ void wlc_init(struct wlc_info *wlc) /* Enable EDCF mode (while the MAC is suspended) */ if (EDCF_ENAB(wlc->pub)) { OR_REG(®s->ifs_ctl, IFS_USEEDCF); - wlc_edcf_setparams(wlc, false); + wlc_edcf_setparams(wlc->cfg, false); } /* Init precedence maps for empty FIFOs */ @@ -1356,16 +1355,17 @@ void wlc_wme_initparams_sta(struct wlc_info *wlc, wme_param_ie_t *pe) cpu_to_le16(EDCF_AC_VO_TXOP_STA)} } }; + + ASSERT(sizeof(*pe) == WME_PARAM_IE_LEN); memcpy(pe, &stadef, sizeof(*pe)); } -void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, - const struct ieee80211_tx_queue_params *params, - bool suspend) +void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, void *arg, bool suspend) { int i; shm_acparams_t acp_shm; u16 *shm_entry; + struct ieee80211_tx_queue_params *params = arg; ASSERT(wlc); @@ -1375,12 +1375,20 @@ void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, return; } + /* + * AP uses AC params from wme_param_ie_ap. + * AP advertises AC params from wme_param_ie. + * STA uses AC params from wme_param_ie. + */ + wlc->wme_admctl = 0; do { memset((char *)&acp_shm, 0, sizeof(shm_acparams_t)); /* find out which ac this set of params applies to */ ASSERT(aci < AC_COUNT); + /* set the admission control policy for this AC */ + /* wlc->wme_admctl |= 1 << aci; *//* should be set ?? seems like off by default */ /* fill in shm ac params struct */ acp_shm.txop = le16_to_cpu(params->txop); @@ -1431,17 +1439,21 @@ void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, } -void wlc_edcf_setparams(struct wlc_info *wlc, bool suspend) +void wlc_edcf_setparams(struct wlc_bsscfg *cfg, bool suspend) { - u16 aci; - int i_ac; + struct wlc_info *wlc = cfg->wlc; + uint aci, i, j; edcf_acparam_t *edcf_acp; + shm_acparams_t acp_shm; + u16 *shm_entry; - struct ieee80211_tx_queue_params txq_pars; - struct ieee80211_tx_queue_params *params = &txq_pars; - + ASSERT(cfg); ASSERT(wlc); + /* Only apply params if the core is out of reset and has clocks */ + if (!wlc->clk) + return; + /* * AP uses AC params from wme_param_ie_ap. * AP advertises AC params from wme_param_ie. @@ -1450,7 +1462,10 @@ void wlc_edcf_setparams(struct wlc_info *wlc, bool suspend) edcf_acp = (edcf_acparam_t *) &wlc->wme_param_ie.acparam[0]; - for (i_ac = 0; i_ac < AC_COUNT; i_ac++, edcf_acp++) { + wlc->wme_admctl = 0; + + for (i = 0; i < AC_COUNT; i++, edcf_acp++) { + memset((char *)&acp_shm, 0, sizeof(shm_acparams_t)); /* find out which ac this set of params applies to */ aci = (edcf_acp->ACI & EDCF_ACI_MASK) >> EDCF_ACI_SHIFT; ASSERT(aci < AC_COUNT); @@ -1460,15 +1475,46 @@ void wlc_edcf_setparams(struct wlc_info *wlc, bool suspend) } /* fill in shm ac params struct */ - params->txop = edcf_acp->TXOP; - params->aifs = edcf_acp->ACI; + acp_shm.txop = le16_to_cpu(edcf_acp->TXOP); + /* convert from units of 32us to us for ucode */ + wlc->edcf_txop[aci] = acp_shm.txop = + EDCF_TXOP2USEC(acp_shm.txop); + acp_shm.aifs = (edcf_acp->ACI & EDCF_AIFSN_MASK); + + if (aci == AC_VI && acp_shm.txop == 0 + && acp_shm.aifs < EDCF_AIFSN_MAX) + acp_shm.aifs++; + + if (acp_shm.aifs < EDCF_AIFSN_MIN + || acp_shm.aifs > EDCF_AIFSN_MAX) { + WL_ERROR("wl%d: wlc_edcf_setparams: bad aifs %d\n", + wlc->pub->unit, acp_shm.aifs); + continue; + } /* CWmin = 2^(ECWmin) - 1 */ - params->cw_min = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK); + acp_shm.cwmin = EDCF_ECW2CW(edcf_acp->ECW & EDCF_ECWMIN_MASK); /* CWmax = 2^(ECWmax) - 1 */ - params->cw_max = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK) + acp_shm.cwmax = EDCF_ECW2CW((edcf_acp->ECW & EDCF_ECWMAX_MASK) >> EDCF_ECWMAX_SHIFT); - wlc_wme_setparams(wlc, aci, params, suspend); + acp_shm.cwcur = acp_shm.cwmin; + acp_shm.bslots = + R_REG(&wlc->regs->tsf_random) & acp_shm.cwcur; + acp_shm.reggap = acp_shm.bslots + acp_shm.aifs; + /* Indicate the new params to the ucode */ + acp_shm.status = wlc_read_shm(wlc, (M_EDCF_QINFO + + wme_shmemacindex(aci) * + M_EDCF_QLEN + + M_EDCF_STATUS_OFF)); + acp_shm.status |= WME_STATUS_NEWAC; + + /* Fill in shm acparam table */ + shm_entry = (u16 *) &acp_shm; + for (j = 0; j < (int)sizeof(shm_acparams_t); j += 2) + wlc_write_shm(wlc, + M_EDCF_QINFO + + wme_shmemacindex(aci) * M_EDCF_QLEN + j, + *shm_entry++); } if (suspend) @@ -1687,6 +1733,39 @@ void *wlc_attach(void *wl, u16 vendor, u16 device, uint unit, bool piomode, WL_NONE("wl%d: %s: vendor 0x%x device 0x%x\n", unit, __func__, vendor, device); + ASSERT(WSEC_MAX_RCMTA_KEYS <= WSEC_MAX_KEYS); + ASSERT(WSEC_MAX_DEFAULT_KEYS == WLC_DEFAULT_KEYS); + + /* some code depends on packed structures */ + ASSERT(sizeof(struct ethhdr) == ETH_HLEN); + ASSERT(sizeof(d11regs_t) == SI_CORE_SIZE); + ASSERT(sizeof(ofdm_phy_hdr_t) == D11_PHY_HDR_LEN); + ASSERT(sizeof(cck_phy_hdr_t) == D11_PHY_HDR_LEN); + ASSERT(sizeof(d11txh_t) == D11_TXH_LEN); + ASSERT(sizeof(d11rxhdr_t) == RXHDR_LEN); + ASSERT(sizeof(struct ieee80211_hdr) == DOT11_A4_HDR_LEN); + ASSERT(sizeof(struct ieee80211_rts) == DOT11_RTS_LEN); + ASSERT(sizeof(tx_status_t) == TXSTATUS_LEN); + ASSERT(sizeof(struct ieee80211_ht_cap) == HT_CAP_IE_LEN); +#ifdef BRCM_FULLMAC + ASSERT(offsetof(wl_scan_params_t, channel_list) == + WL_SCAN_PARAMS_FIXED_SIZE); +#endif + ASSERT(IS_ALIGNED(offsetof(wsec_key_t, data), sizeof(u32))); + ASSERT(ISPOWEROF2(MA_WINDOW_SZ)); + + ASSERT(sizeof(wlc_d11rxhdr_t) <= WL_HWRXOFF); + + /* + * Number of replay counters value used in WPA IE must match # rxivs + * supported in wsec_key_t struct. See 802.11i/D3.0 sect. 7.3.2.17 + * 'RSN Information Element' figure 8 for this mapping. + */ + ASSERT((WPA_CAP_16_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE + && 16 == WLC_NUMRXIVS) + || (WPA_CAP_4_REPLAY_CNTRS == WLC_REPLAY_CNTRS_VALUE + && 4 == WLC_NUMRXIVS)); + /* allocate struct wlc_info state and its substructures */ wlc = (struct wlc_info *) wlc_attach_malloc(unit, &err, device); if (wlc == NULL) @@ -4040,7 +4119,7 @@ _wlc_ioctl(struct wlc_info *wlc, int cmd, void *arg, int len, ~WSEC_PRIMARY_KEY; key->flags |= WSEC_PRIMARY_KEY; bsscfg->wsec_index = i; - bcmerror = 0; + bcmerror = BCME_OK; } } break; @@ -4472,7 +4551,7 @@ wlc_doiovar(void *hdl, const bcm_iovar_t *vi, u32 actionid, err = wlc_phy_txpower_get(wlc->band->pi, &qdbm, &override); - if (err != 0) + if (err != BCME_OK) return err; /* Return qdbm units */ @@ -4792,7 +4871,7 @@ void wlc_statsupd(struct wlc_info *wlc) bool wlc_chipmatch(u16 vendor, u16 device) { - if (vendor != PCI_VENDOR_ID_BROADCOM) { + if (vendor != VENDOR_BROADCOM) { WL_ERROR("wlc_chipmatch: unknown vendor id %04x\n", vendor); return false; } @@ -6869,6 +6948,11 @@ wlc_recvctl(struct wlc_info *wlc, d11rxhdr_t *rxh, struct sk_buff *p) #if defined(BCMDBG) struct sk_buff *skb = p; #endif /* BCMDBG */ + /* Todo: + * Cache plcp for first MPDU of AMPD and use chacched version for INTERMEDIATE. + * Test for INTERMEDIATE like so: + * if (!(plcp[0] | plcp[1] | plcp[2])) + */ memset(&rx_status, 0, sizeof(rx_status)); prep_mac80211_status(wlc, rxh, p, &rx_status); @@ -7831,7 +7915,7 @@ int wlc_get_revision_info(struct wlc_info *wlc, void *buf, uint len) rinfo->chippkg = wlc->pub->sih->chippkg; } - return 0; + return BCME_OK; } void wlc_default_rateset(struct wlc_info *wlc, wlc_rateset_t *rs) @@ -8027,7 +8111,7 @@ wlc_duty_cycle_set(struct wlc_info *wlc, int duty_cycle, bool isOFDM, else wlc->tx_duty_cycle_cck = (u16) duty_cycle; - return 0; + return BCME_OK; } /* Read a single u16 from shared memory. diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_main.h b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_main.h index f11161dc0c01..960f82cbfbc9 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_main.h +++ b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_main.h @@ -942,7 +942,7 @@ extern void wlc_mimops_action_ht_send(struct wlc_info *wlc, extern void wlc_switch_shortslot(struct wlc_info *wlc, bool shortslot); extern void wlc_set_bssid(struct wlc_bsscfg *cfg); -extern void wlc_edcf_setparams(struct wlc_info *wlc, bool suspend); +extern void wlc_edcf_setparams(struct wlc_bsscfg *cfg, bool suspend); extern void wlc_set_ratetable(struct wlc_info *wlc); extern int wlc_set_mac(struct wlc_bsscfg *cfg); diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_pmu.c b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_pmu.c deleted file mode 100644 index e26df70e1ddd..000000000000 --- a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_pmu.c +++ /dev/null @@ -1,1963 +0,0 @@ -/* - * Copyright (c) 2011 Broadcom Corporation - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -#include -#include -#include -#include - -#include -#include -#include -#include "wlc_pmu.h" - -/* - * d11 slow to fast clock transition time in slow clock cycles - */ -#define D11SCC_SLOW2FAST_TRANSITION 2 - -/* - * external LPO crystal frequency - */ -#define EXT_ILP_HZ 32768 - -/* - * Duration for ILP clock frequency measurment in milliseconds - * - * remark: 1000 must be an integer multiple of this duration - */ -#define ILP_CALC_DUR 10 - -/* - * FVCO frequency - */ -#define FVCO_880 880000 /* 880MHz */ -#define FVCO_1760 1760000 /* 1760MHz */ -#define FVCO_1440 1440000 /* 1440MHz */ -#define FVCO_960 960000 /* 960MHz */ - -/* - * PMU crystal table indices for 1440MHz fvco - */ -#define PMU1_XTALTAB0_1440_12000K 0 -#define PMU1_XTALTAB0_1440_13000K 1 -#define PMU1_XTALTAB0_1440_14400K 2 -#define PMU1_XTALTAB0_1440_15360K 3 -#define PMU1_XTALTAB0_1440_16200K 4 -#define PMU1_XTALTAB0_1440_16800K 5 -#define PMU1_XTALTAB0_1440_19200K 6 -#define PMU1_XTALTAB0_1440_19800K 7 -#define PMU1_XTALTAB0_1440_20000K 8 -#define PMU1_XTALTAB0_1440_25000K 9 -#define PMU1_XTALTAB0_1440_26000K 10 -#define PMU1_XTALTAB0_1440_30000K 11 -#define PMU1_XTALTAB0_1440_37400K 12 -#define PMU1_XTALTAB0_1440_38400K 13 -#define PMU1_XTALTAB0_1440_40000K 14 -#define PMU1_XTALTAB0_1440_48000K 15 - -/* - * PMU crystal table indices for 960MHz fvco - */ -#define PMU1_XTALTAB0_960_12000K 0 -#define PMU1_XTALTAB0_960_13000K 1 -#define PMU1_XTALTAB0_960_14400K 2 -#define PMU1_XTALTAB0_960_15360K 3 -#define PMU1_XTALTAB0_960_16200K 4 -#define PMU1_XTALTAB0_960_16800K 5 -#define PMU1_XTALTAB0_960_19200K 6 -#define PMU1_XTALTAB0_960_19800K 7 -#define PMU1_XTALTAB0_960_20000K 8 -#define PMU1_XTALTAB0_960_25000K 9 -#define PMU1_XTALTAB0_960_26000K 10 -#define PMU1_XTALTAB0_960_30000K 11 -#define PMU1_XTALTAB0_960_37400K 12 -#define PMU1_XTALTAB0_960_38400K 13 -#define PMU1_XTALTAB0_960_40000K 14 -#define PMU1_XTALTAB0_960_48000K 15 - -/* - * PMU crystal table indices for 880MHz fvco - */ -#define PMU1_XTALTAB0_880_12000K 0 -#define PMU1_XTALTAB0_880_13000K 1 -#define PMU1_XTALTAB0_880_14400K 2 -#define PMU1_XTALTAB0_880_15360K 3 -#define PMU1_XTALTAB0_880_16200K 4 -#define PMU1_XTALTAB0_880_16800K 5 -#define PMU1_XTALTAB0_880_19200K 6 -#define PMU1_XTALTAB0_880_19800K 7 -#define PMU1_XTALTAB0_880_20000K 8 -#define PMU1_XTALTAB0_880_24000K 9 -#define PMU1_XTALTAB0_880_25000K 10 -#define PMU1_XTALTAB0_880_26000K 11 -#define PMU1_XTALTAB0_880_30000K 12 -#define PMU1_XTALTAB0_880_37400K 13 -#define PMU1_XTALTAB0_880_38400K 14 -#define PMU1_XTALTAB0_880_40000K 15 - -/* - * crystal frequency values - */ -#define XTAL_FREQ_24000MHZ 24000 -#define XTAL_FREQ_30000MHZ 30000 -#define XTAL_FREQ_37400MHZ 37400 -#define XTAL_FREQ_48000MHZ 48000 - -/* - * Resource dependancies mask change action - * - * @RES_DEPEND_SET: Override the dependancies mask - * @RES_DEPEND_ADD: Add to the dependancies mask - * @RES_DEPEND_REMOVE: Remove from the dependancies mask - */ -#define RES_DEPEND_SET 0 -#define RES_DEPEND_ADD 1 -#define RES_DEPEND_REMOVE -1 - -/* Setup resource up/down timers */ -typedef struct { - u8 resnum; - u16 updown; -} pmu_res_updown_t; - -/* Change resource dependancies masks */ -typedef struct { - u32 res_mask; /* resources (chip specific) */ - s8 action; /* action */ - u32 depend_mask; /* changes to the dependancies mask */ - bool(*filter) (si_t *sih); /* action is taken when filter is NULL or return true */ -} pmu_res_depend_t; - -/* setup pll and query clock speed */ -typedef struct { - u16 fref; - u8 xf; - u8 p1div; - u8 p2div; - u8 ndiv_int; - u32 ndiv_frac; -} pmu1_xtaltab0_t; - -/* - * prototypes used in resource tables - */ -static bool si_pmu_res_depfltr_bb(si_t *sih); -static bool si_pmu_res_depfltr_ncb(si_t *sih); -static bool si_pmu_res_depfltr_paldo(si_t *sih); -static bool si_pmu_res_depfltr_npaldo(si_t *sih); - -static const pmu_res_updown_t bcm4328a0_res_updown[] = { - { - RES4328_EXT_SWITCHER_PWM, 0x0101}, { - RES4328_BB_SWITCHER_PWM, 0x1f01}, { - RES4328_BB_SWITCHER_BURST, 0x010f}, { - RES4328_BB_EXT_SWITCHER_BURST, 0x0101}, { - RES4328_ILP_REQUEST, 0x0202}, { - RES4328_RADIO_SWITCHER_PWM, 0x0f01}, { - RES4328_RADIO_SWITCHER_BURST, 0x0f01}, { - RES4328_ROM_SWITCH, 0x0101}, { - RES4328_PA_REF_LDO, 0x0f01}, { - RES4328_RADIO_LDO, 0x0f01}, { - RES4328_AFE_LDO, 0x0f01}, { - RES4328_PLL_LDO, 0x0f01}, { - RES4328_BG_FILTBYP, 0x0101}, { - RES4328_TX_FILTBYP, 0x0101}, { - RES4328_RX_FILTBYP, 0x0101}, { - RES4328_XTAL_PU, 0x0101}, { - RES4328_XTAL_EN, 0xa001}, { - RES4328_BB_PLL_FILTBYP, 0x0101}, { - RES4328_RF_PLL_FILTBYP, 0x0101}, { - RES4328_BB_PLL_PU, 0x0701} -}; - -static const pmu_res_depend_t bcm4328a0_res_depend[] = { - /* Adjust ILP request resource not to force ext/BB switchers into burst mode */ - { - PMURES_BIT(RES4328_ILP_REQUEST), - RES_DEPEND_SET, - PMURES_BIT(RES4328_EXT_SWITCHER_PWM) | - PMURES_BIT(RES4328_BB_SWITCHER_PWM), NULL} -}; - -static const pmu_res_updown_t bcm4325a0_res_updown_qt[] = { - { - RES4325_HT_AVAIL, 0x0300}, { - RES4325_BBPLL_PWRSW_PU, 0x0101}, { - RES4325_RFPLL_PWRSW_PU, 0x0101}, { - RES4325_ALP_AVAIL, 0x0100}, { - RES4325_XTAL_PU, 0x1000}, { - RES4325_LNLDO1_PU, 0x0800}, { - RES4325_CLDO_CBUCK_PWM, 0x0101}, { - RES4325_CBUCK_PWM, 0x0803} -}; - -static const pmu_res_updown_t bcm4325a0_res_updown[] = { - { - RES4325_XTAL_PU, 0x1501} -}; - -static const pmu_res_depend_t bcm4325a0_res_depend[] = { - /* Adjust OTP PU resource dependencies - remove BB BURST */ - { - PMURES_BIT(RES4325_OTP_PU), - RES_DEPEND_REMOVE, - PMURES_BIT(RES4325_BUCK_BOOST_BURST), NULL}, - /* Adjust ALP/HT Avail resource dependencies - bring up BB along if it is used. */ - { - PMURES_BIT(RES4325_ALP_AVAIL) | PMURES_BIT(RES4325_HT_AVAIL), - RES_DEPEND_ADD, - PMURES_BIT(RES4325_BUCK_BOOST_BURST) | - PMURES_BIT(RES4325_BUCK_BOOST_PWM), si_pmu_res_depfltr_bb}, - /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */ - { - PMURES_BIT(RES4325_HT_AVAIL), - RES_DEPEND_ADD, - PMURES_BIT(RES4325_RX_PWRSW_PU) | - PMURES_BIT(RES4325_TX_PWRSW_PU) | - PMURES_BIT(RES4325_LOGEN_PWRSW_PU) | - PMURES_BIT(RES4325_AFE_PWRSW_PU), NULL}, - /* Adjust ALL resource dependencies - remove CBUCK dependancies if it is not used. */ - { - PMURES_BIT(RES4325_ILP_REQUEST) | - PMURES_BIT(RES4325_ABUCK_BURST) | - PMURES_BIT(RES4325_ABUCK_PWM) | - PMURES_BIT(RES4325_LNLDO1_PU) | - PMURES_BIT(RES4325C1_LNLDO2_PU) | - PMURES_BIT(RES4325_XTAL_PU) | - PMURES_BIT(RES4325_ALP_AVAIL) | - PMURES_BIT(RES4325_RX_PWRSW_PU) | - PMURES_BIT(RES4325_TX_PWRSW_PU) | - PMURES_BIT(RES4325_RFPLL_PWRSW_PU) | - PMURES_BIT(RES4325_LOGEN_PWRSW_PU) | - PMURES_BIT(RES4325_AFE_PWRSW_PU) | - PMURES_BIT(RES4325_BBPLL_PWRSW_PU) | - PMURES_BIT(RES4325_HT_AVAIL), RES_DEPEND_REMOVE, - PMURES_BIT(RES4325B0_CBUCK_LPOM) | - PMURES_BIT(RES4325B0_CBUCK_BURST) | - PMURES_BIT(RES4325B0_CBUCK_PWM), si_pmu_res_depfltr_ncb} -}; - -static const pmu_res_updown_t bcm4315a0_res_updown_qt[] = { - { - RES4315_HT_AVAIL, 0x0101}, { - RES4315_XTAL_PU, 0x0100}, { - RES4315_LNLDO1_PU, 0x0100}, { - RES4315_PALDO_PU, 0x0100}, { - RES4315_CLDO_PU, 0x0100}, { - RES4315_CBUCK_PWM, 0x0100}, { - RES4315_CBUCK_BURST, 0x0100}, { - RES4315_CBUCK_LPOM, 0x0100} -}; - -static const pmu_res_updown_t bcm4315a0_res_updown[] = { - { - RES4315_XTAL_PU, 0x2501} -}; - -static const pmu_res_depend_t bcm4315a0_res_depend[] = { - /* Adjust OTP PU resource dependencies - not need PALDO unless write */ - { - PMURES_BIT(RES4315_OTP_PU), - RES_DEPEND_REMOVE, - PMURES_BIT(RES4315_PALDO_PU), si_pmu_res_depfltr_npaldo}, - /* Adjust ALP/HT Avail resource dependencies - bring up PALDO along if it is used. */ - { - PMURES_BIT(RES4315_ALP_AVAIL) | PMURES_BIT(RES4315_HT_AVAIL), - RES_DEPEND_ADD, - PMURES_BIT(RES4315_PALDO_PU), si_pmu_res_depfltr_paldo}, - /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */ - { - PMURES_BIT(RES4315_HT_AVAIL), - RES_DEPEND_ADD, - PMURES_BIT(RES4315_RX_PWRSW_PU) | - PMURES_BIT(RES4315_TX_PWRSW_PU) | - PMURES_BIT(RES4315_LOGEN_PWRSW_PU) | - PMURES_BIT(RES4315_AFE_PWRSW_PU), NULL}, - /* Adjust ALL resource dependencies - remove CBUCK dependancies if it is not used. */ - { - PMURES_BIT(RES4315_CLDO_PU) | PMURES_BIT(RES4315_ILP_REQUEST) | - PMURES_BIT(RES4315_LNLDO1_PU) | - PMURES_BIT(RES4315_OTP_PU) | - PMURES_BIT(RES4315_LNLDO2_PU) | - PMURES_BIT(RES4315_XTAL_PU) | - PMURES_BIT(RES4315_ALP_AVAIL) | - PMURES_BIT(RES4315_RX_PWRSW_PU) | - PMURES_BIT(RES4315_TX_PWRSW_PU) | - PMURES_BIT(RES4315_RFPLL_PWRSW_PU) | - PMURES_BIT(RES4315_LOGEN_PWRSW_PU) | - PMURES_BIT(RES4315_AFE_PWRSW_PU) | - PMURES_BIT(RES4315_BBPLL_PWRSW_PU) | - PMURES_BIT(RES4315_HT_AVAIL), RES_DEPEND_REMOVE, - PMURES_BIT(RES4315_CBUCK_LPOM) | - PMURES_BIT(RES4315_CBUCK_BURST) | - PMURES_BIT(RES4315_CBUCK_PWM), si_pmu_res_depfltr_ncb} -}; - - /* 4329 specific. needs to come back this issue later */ -static const pmu_res_updown_t bcm4329_res_updown[] = { - { - RES4329_XTAL_PU, 0x1501} -}; - -static const pmu_res_depend_t bcm4329_res_depend[] = { - /* Adjust HT Avail resource dependencies */ - { - PMURES_BIT(RES4329_HT_AVAIL), - RES_DEPEND_ADD, - PMURES_BIT(RES4329_CBUCK_LPOM) | - PMURES_BIT(RES4329_CBUCK_BURST) | - PMURES_BIT(RES4329_CBUCK_PWM) | - PMURES_BIT(RES4329_CLDO_PU) | - PMURES_BIT(RES4329_PALDO_PU) | - PMURES_BIT(RES4329_LNLDO1_PU) | - PMURES_BIT(RES4329_XTAL_PU) | - PMURES_BIT(RES4329_ALP_AVAIL) | - PMURES_BIT(RES4329_RX_PWRSW_PU) | - PMURES_BIT(RES4329_TX_PWRSW_PU) | - PMURES_BIT(RES4329_RFPLL_PWRSW_PU) | - PMURES_BIT(RES4329_LOGEN_PWRSW_PU) | - PMURES_BIT(RES4329_AFE_PWRSW_PU) | - PMURES_BIT(RES4329_BBPLL_PWRSW_PU), NULL} -}; - -static const pmu_res_updown_t bcm4319a0_res_updown_qt[] = { - { - RES4319_HT_AVAIL, 0x0101}, { - RES4319_XTAL_PU, 0x0100}, { - RES4319_LNLDO1_PU, 0x0100}, { - RES4319_PALDO_PU, 0x0100}, { - RES4319_CLDO_PU, 0x0100}, { - RES4319_CBUCK_PWM, 0x0100}, { - RES4319_CBUCK_BURST, 0x0100}, { - RES4319_CBUCK_LPOM, 0x0100} -}; - -static const pmu_res_updown_t bcm4319a0_res_updown[] = { - { - RES4319_XTAL_PU, 0x3f01} -}; - -static const pmu_res_depend_t bcm4319a0_res_depend[] = { - /* Adjust OTP PU resource dependencies - not need PALDO unless write */ - { - PMURES_BIT(RES4319_OTP_PU), - RES_DEPEND_REMOVE, - PMURES_BIT(RES4319_PALDO_PU), si_pmu_res_depfltr_npaldo}, - /* Adjust HT Avail resource dependencies - bring up PALDO along if it is used. */ - { - PMURES_BIT(RES4319_HT_AVAIL), - RES_DEPEND_ADD, - PMURES_BIT(RES4319_PALDO_PU), si_pmu_res_depfltr_paldo}, - /* Adjust HT Avail resource dependencies - bring up RF switches along with HT. */ - { - PMURES_BIT(RES4319_HT_AVAIL), - RES_DEPEND_ADD, - PMURES_BIT(RES4319_RX_PWRSW_PU) | - PMURES_BIT(RES4319_TX_PWRSW_PU) | - PMURES_BIT(RES4319_RFPLL_PWRSW_PU) | - PMURES_BIT(RES4319_LOGEN_PWRSW_PU) | - PMURES_BIT(RES4319_AFE_PWRSW_PU), NULL} -}; - -static const pmu_res_updown_t bcm4336a0_res_updown_qt[] = { - { - RES4336_HT_AVAIL, 0x0101}, { - RES4336_XTAL_PU, 0x0100}, { - RES4336_CLDO_PU, 0x0100}, { - RES4336_CBUCK_PWM, 0x0100}, { - RES4336_CBUCK_BURST, 0x0100}, { - RES4336_CBUCK_LPOM, 0x0100} -}; - -static const pmu_res_updown_t bcm4336a0_res_updown[] = { - { - RES4336_HT_AVAIL, 0x0D01} -}; - -static const pmu_res_depend_t bcm4336a0_res_depend[] = { - /* Just a dummy entry for now */ - { - PMURES_BIT(RES4336_RSVD), RES_DEPEND_ADD, 0, NULL} -}; - -static const pmu_res_updown_t bcm4330a0_res_updown_qt[] = { - { - RES4330_HT_AVAIL, 0x0101}, { - RES4330_XTAL_PU, 0x0100}, { - RES4330_CLDO_PU, 0x0100}, { - RES4330_CBUCK_PWM, 0x0100}, { - RES4330_CBUCK_BURST, 0x0100}, { - RES4330_CBUCK_LPOM, 0x0100} -}; - -static const pmu_res_updown_t bcm4330a0_res_updown[] = { - { - RES4330_HT_AVAIL, 0x0e02} -}; - -static const pmu_res_depend_t bcm4330a0_res_depend[] = { - /* Just a dummy entry for now */ - { - PMURES_BIT(RES4330_HT_AVAIL), RES_DEPEND_ADD, 0, NULL} -}; - -/* the following table is based on 1440Mhz fvco */ -static const pmu1_xtaltab0_t pmu1_xtaltab0_1440[] = { - { - 12000, 1, 1, 1, 0x78, 0x0}, { - 13000, 2, 1, 1, 0x6E, 0xC4EC4E}, { - 14400, 3, 1, 1, 0x64, 0x0}, { - 15360, 4, 1, 1, 0x5D, 0xC00000}, { - 16200, 5, 1, 1, 0x58, 0xE38E38}, { - 16800, 6, 1, 1, 0x55, 0xB6DB6D}, { - 19200, 7, 1, 1, 0x4B, 0}, { - 19800, 8, 1, 1, 0x48, 0xBA2E8B}, { - 20000, 9, 1, 1, 0x48, 0x0}, { - 25000, 10, 1, 1, 0x39, 0x999999}, { - 26000, 11, 1, 1, 0x37, 0x627627}, { - 30000, 12, 1, 1, 0x30, 0x0}, { - 37400, 13, 2, 1, 0x4D, 0x15E76}, { - 38400, 13, 2, 1, 0x4B, 0x0}, { - 40000, 14, 2, 1, 0x48, 0x0}, { - 48000, 15, 2, 1, 0x3c, 0x0}, { - 0, 0, 0, 0, 0, 0} -}; - -static const pmu1_xtaltab0_t pmu1_xtaltab0_960[] = { - { - 12000, 1, 1, 1, 0x50, 0x0}, { - 13000, 2, 1, 1, 0x49, 0xD89D89}, { - 14400, 3, 1, 1, 0x42, 0xAAAAAA}, { - 15360, 4, 1, 1, 0x3E, 0x800000}, { - 16200, 5, 1, 1, 0x39, 0x425ED0}, { - 16800, 6, 1, 1, 0x39, 0x249249}, { - 19200, 7, 1, 1, 0x32, 0x0}, { - 19800, 8, 1, 1, 0x30, 0x7C1F07}, { - 20000, 9, 1, 1, 0x30, 0x0}, { - 25000, 10, 1, 1, 0x26, 0x666666}, { - 26000, 11, 1, 1, 0x24, 0xEC4EC4}, { - 30000, 12, 1, 1, 0x20, 0x0}, { - 37400, 13, 2, 1, 0x33, 0x563EF9}, { - 38400, 14, 2, 1, 0x32, 0x0}, { - 40000, 15, 2, 1, 0x30, 0x0}, { - 48000, 16, 2, 1, 0x28, 0x0}, { - 0, 0, 0, 0, 0, 0} -}; - -static const pmu1_xtaltab0_t pmu1_xtaltab0_880_4329[] = { - { - 12000, 1, 3, 22, 0x9, 0xFFFFEF}, { - 13000, 2, 1, 6, 0xb, 0x483483}, { - 14400, 3, 1, 10, 0xa, 0x1C71C7}, { - 15360, 4, 1, 5, 0xb, 0x755555}, { - 16200, 5, 1, 10, 0x5, 0x6E9E06}, { - 16800, 6, 1, 10, 0x5, 0x3Cf3Cf}, { - 19200, 7, 1, 4, 0xb, 0x755555}, { - 19800, 8, 1, 11, 0x4, 0xA57EB}, { - 20000, 9, 1, 11, 0x4, 0x0}, { - 24000, 10, 3, 11, 0xa, 0x0}, { - 25000, 11, 5, 16, 0xb, 0x0}, { - 26000, 12, 1, 1, 0x21, 0xD89D89}, { - 30000, 13, 3, 8, 0xb, 0x0}, { - 37400, 14, 3, 1, 0x46, 0x969696}, { - 38400, 15, 1, 1, 0x16, 0xEAAAAA}, { - 40000, 16, 1, 2, 0xb, 0}, { - 0, 0, 0, 0, 0, 0} -}; - -/* the following table is based on 880Mhz fvco */ -static const pmu1_xtaltab0_t pmu1_xtaltab0_880[] = { - { - 12000, 1, 3, 22, 0x9, 0xFFFFEF}, { - 13000, 2, 1, 6, 0xb, 0x483483}, { - 14400, 3, 1, 10, 0xa, 0x1C71C7}, { - 15360, 4, 1, 5, 0xb, 0x755555}, { - 16200, 5, 1, 10, 0x5, 0x6E9E06}, { - 16800, 6, 1, 10, 0x5, 0x3Cf3Cf}, { - 19200, 7, 1, 4, 0xb, 0x755555}, { - 19800, 8, 1, 11, 0x4, 0xA57EB}, { - 20000, 9, 1, 11, 0x4, 0x0}, { - 24000, 10, 3, 11, 0xa, 0x0}, { - 25000, 11, 5, 16, 0xb, 0x0}, { - 26000, 12, 1, 2, 0x10, 0xEC4EC4}, { - 30000, 13, 3, 8, 0xb, 0x0}, { - 33600, 14, 1, 2, 0xd, 0x186186}, { - 38400, 15, 1, 2, 0xb, 0x755555}, { - 40000, 16, 1, 2, 0xb, 0}, { - 0, 0, 0, 0, 0, 0} -}; - -/* true if the power topology uses the buck boost to provide 3.3V to VDDIO_RF and WLAN PA */ -static bool si_pmu_res_depfltr_bb(si_t *sih) -{ - return (sih->boardflags & BFL_BUCKBOOST) != 0; -} - -/* true if the power topology doesn't use the cbuck. Key on chiprev also if the chip is BCM4325. */ -static bool si_pmu_res_depfltr_ncb(si_t *sih) -{ - - return (sih->boardflags & BFL_NOCBUCK) != 0; -} - -/* true if the power topology uses the PALDO */ -static bool si_pmu_res_depfltr_paldo(si_t *sih) -{ - return (sih->boardflags & BFL_PALDO) != 0; -} - -/* true if the power topology doesn't use the PALDO */ -static bool si_pmu_res_depfltr_npaldo(si_t *sih) -{ - return (sih->boardflags & BFL_PALDO) == 0; -} - -/* Return dependancies (direct or all/indirect) for the given resources */ -static u32 -si_pmu_res_deps(si_t *sih, chipcregs_t *cc, u32 rsrcs, - bool all) -{ - u32 deps = 0; - u32 i; - - for (i = 0; i <= PMURES_MAX_RESNUM; i++) { - if (!(rsrcs & PMURES_BIT(i))) - continue; - W_REG(&cc->res_table_sel, i); - deps |= R_REG(&cc->res_dep_mask); - } - - return !all ? deps : (deps - ? (deps | - si_pmu_res_deps(sih, cc, deps, - true)) : 0); -} - -/* Determine min/max rsrc masks. Value 0 leaves hardware at default. */ -static void si_pmu_res_masks(si_t *sih, u32 * pmin, u32 * pmax) -{ - u32 min_mask = 0, max_mask = 0; - uint rsrcs; - char *val; - - /* # resources */ - rsrcs = (sih->pmucaps & PCAP_RC_MASK) >> PCAP_RC_SHIFT; - - /* determine min/max rsrc masks */ - switch (sih->chip) { - case BCM43224_CHIP_ID: - case BCM43225_CHIP_ID: - case BCM43421_CHIP_ID: - case BCM43235_CHIP_ID: - case BCM43236_CHIP_ID: - case BCM43238_CHIP_ID: - case BCM4331_CHIP_ID: - case BCM6362_CHIP_ID: - /* ??? */ - break; - - case BCM4329_CHIP_ID: - /* 4329 spedific issue. Needs to come back this issue later */ - /* Down to save the power. */ - min_mask = - PMURES_BIT(RES4329_CBUCK_LPOM) | - PMURES_BIT(RES4329_CLDO_PU); - /* Allow (but don't require) PLL to turn on */ - max_mask = 0x3ff63e; - break; - case BCM4319_CHIP_ID: - /* We only need a few resources to be kept on all the time */ - min_mask = PMURES_BIT(RES4319_CBUCK_LPOM) | - PMURES_BIT(RES4319_CLDO_PU); - - /* Allow everything else to be turned on upon requests */ - max_mask = ~(~0 << rsrcs); - break; - case BCM4336_CHIP_ID: - /* Down to save the power. */ - min_mask = - PMURES_BIT(RES4336_CBUCK_LPOM) | PMURES_BIT(RES4336_CLDO_PU) - | PMURES_BIT(RES4336_LDO3P3_PU) | PMURES_BIT(RES4336_OTP_PU) - | PMURES_BIT(RES4336_DIS_INT_RESET_PD); - /* Allow (but don't require) PLL to turn on */ - max_mask = 0x1ffffff; - break; - - case BCM4330_CHIP_ID: - /* Down to save the power. */ - min_mask = - PMURES_BIT(RES4330_CBUCK_LPOM) | PMURES_BIT(RES4330_CLDO_PU) - | PMURES_BIT(RES4330_DIS_INT_RESET_PD) | - PMURES_BIT(RES4330_LDO3P3_PU) | PMURES_BIT(RES4330_OTP_PU); - /* Allow (but don't require) PLL to turn on */ - max_mask = 0xfffffff; - break; - - case BCM4313_CHIP_ID: - min_mask = PMURES_BIT(RES4313_BB_PU_RSRC) | - PMURES_BIT(RES4313_XTAL_PU_RSRC) | - PMURES_BIT(RES4313_ALP_AVAIL_RSRC) | - PMURES_BIT(RES4313_BB_PLL_PWRSW_RSRC); - max_mask = 0xffff; - break; - default: - break; - } - - /* Apply nvram override to min mask */ - val = getvar(NULL, "rmin"); - if (val != NULL) { - min_mask = (u32) simple_strtoul(val, NULL, 0); - } - /* Apply nvram override to max mask */ - val = getvar(NULL, "rmax"); - if (val != NULL) { - max_mask = (u32) simple_strtoul(val, NULL, 0); - } - - *pmin = min_mask; - *pmax = max_mask; -} - -/* Return up time in ILP cycles for the given resource. */ -static uint -si_pmu_res_uptime(si_t *sih, chipcregs_t *cc, u8 rsrc) { - u32 deps; - uint up, i, dup, dmax; - u32 min_mask = 0, max_mask = 0; - - /* uptime of resource 'rsrc' */ - W_REG(&cc->res_table_sel, rsrc); - up = (R_REG(&cc->res_updn_timer) >> 8) & 0xff; - - /* direct dependancies of resource 'rsrc' */ - deps = si_pmu_res_deps(sih, cc, PMURES_BIT(rsrc), false); - for (i = 0; i <= PMURES_MAX_RESNUM; i++) { - if (!(deps & PMURES_BIT(i))) - continue; - deps &= ~si_pmu_res_deps(sih, cc, PMURES_BIT(i), true); - } - si_pmu_res_masks(sih, &min_mask, &max_mask); - deps &= ~min_mask; - - /* max uptime of direct dependancies */ - dmax = 0; - for (i = 0; i <= PMURES_MAX_RESNUM; i++) { - if (!(deps & PMURES_BIT(i))) - continue; - dup = si_pmu_res_uptime(sih, cc, (u8) i); - if (dmax < dup) - dmax = dup; - } - - return up + dmax + PMURES_UP_TRANSITION; -} - -static void -si_pmu_spuravoid_pllupdate(si_t *sih, chipcregs_t *cc, u8 spuravoid) -{ - u32 tmp = 0; - u8 phypll_offset = 0; - u8 bcm5357_bcm43236_p1div[] = { 0x1, 0x5, 0x5 }; - u8 bcm5357_bcm43236_ndiv[] = { 0x30, 0xf6, 0xfc }; - - switch (sih->chip) { - case BCM5357_CHIP_ID: - case BCM43235_CHIP_ID: - case BCM43236_CHIP_ID: - case BCM43238_CHIP_ID: - - /* BCM5357 needs to touch PLL1_PLLCTL[02], so offset PLL0_PLLCTL[02] by 6 */ - phypll_offset = (sih->chip == BCM5357_CHIP_ID) ? 6 : 0; - - /* RMW only the P1 divider */ - W_REG(&cc->pllcontrol_addr, - PMU1_PLL0_PLLCTL0 + phypll_offset); - tmp = R_REG(&cc->pllcontrol_data); - tmp &= (~(PMU1_PLL0_PC0_P1DIV_MASK)); - tmp |= - (bcm5357_bcm43236_p1div[spuravoid] << - PMU1_PLL0_PC0_P1DIV_SHIFT); - W_REG(&cc->pllcontrol_data, tmp); - - /* RMW only the int feedback divider */ - W_REG(&cc->pllcontrol_addr, - PMU1_PLL0_PLLCTL2 + phypll_offset); - tmp = R_REG(&cc->pllcontrol_data); - tmp &= ~(PMU1_PLL0_PC2_NDIV_INT_MASK); - tmp |= - (bcm5357_bcm43236_ndiv[spuravoid]) << - PMU1_PLL0_PC2_NDIV_INT_SHIFT; - W_REG(&cc->pllcontrol_data, tmp); - - tmp = 1 << 10; - break; - - case BCM4331_CHIP_ID: - if (spuravoid == 2) { - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - W_REG(&cc->pllcontrol_data, 0x11500014); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x0FC00a08); - } else if (spuravoid == 1) { - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - W_REG(&cc->pllcontrol_data, 0x11500014); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x0F600a08); - } else { - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - W_REG(&cc->pllcontrol_data, 0x11100014); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x03000a08); - } - tmp = 1 << 10; - break; - - case BCM43224_CHIP_ID: - case BCM43225_CHIP_ID: - case BCM43421_CHIP_ID: - case BCM6362_CHIP_ID: - if (spuravoid == 1) { - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - W_REG(&cc->pllcontrol_data, 0x11500010); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); - W_REG(&cc->pllcontrol_data, 0x000C0C06); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x0F600a08); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); - W_REG(&cc->pllcontrol_data, 0x00000000); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); - W_REG(&cc->pllcontrol_data, 0x2001E920); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); - W_REG(&cc->pllcontrol_data, 0x88888815); - } else { - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - W_REG(&cc->pllcontrol_data, 0x11100010); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); - W_REG(&cc->pllcontrol_data, 0x000c0c06); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x03000a08); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); - W_REG(&cc->pllcontrol_data, 0x00000000); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); - W_REG(&cc->pllcontrol_data, 0x200005c0); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); - W_REG(&cc->pllcontrol_data, 0x88888815); - } - tmp = 1 << 10; - break; - - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - W_REG(&cc->pllcontrol_data, 0x11100008); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); - W_REG(&cc->pllcontrol_data, 0x0c000c06); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x03000a08); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); - W_REG(&cc->pllcontrol_data, 0x00000000); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); - W_REG(&cc->pllcontrol_data, 0x200005c0); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); - W_REG(&cc->pllcontrol_data, 0x88888855); - - tmp = 1 << 10; - break; - - case BCM4716_CHIP_ID: - case BCM4748_CHIP_ID: - case BCM47162_CHIP_ID: - if (spuravoid == 1) { - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - W_REG(&cc->pllcontrol_data, 0x11500060); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); - W_REG(&cc->pllcontrol_data, 0x080C0C06); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x0F600000); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); - W_REG(&cc->pllcontrol_data, 0x00000000); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); - W_REG(&cc->pllcontrol_data, 0x2001E924); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); - W_REG(&cc->pllcontrol_data, 0x88888815); - } else { - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - W_REG(&cc->pllcontrol_data, 0x11100060); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); - W_REG(&cc->pllcontrol_data, 0x080c0c06); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x03000000); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); - W_REG(&cc->pllcontrol_data, 0x00000000); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); - W_REG(&cc->pllcontrol_data, 0x200005c0); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); - W_REG(&cc->pllcontrol_data, 0x88888815); - } - - tmp = 3 << 9; - break; - - case BCM4319_CHIP_ID: - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - W_REG(&cc->pllcontrol_data, 0x11100070); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); - W_REG(&cc->pllcontrol_data, 0x1014140a); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); - W_REG(&cc->pllcontrol_data, 0x88888854); - - if (spuravoid == 1) { /* spur_avoid ON, enable 41/82/164Mhz clock mode */ - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x05201828); - } else { /* enable 40/80/160Mhz clock mode */ - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x05001828); - } - break; - case BCM4336_CHIP_ID: - /* Looks like these are only for default xtal freq 26MHz */ - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - W_REG(&cc->pllcontrol_data, 0x02100020); - - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); - W_REG(&cc->pllcontrol_data, 0x0C0C0C0C); - - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - W_REG(&cc->pllcontrol_data, 0x01240C0C); - - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); - W_REG(&cc->pllcontrol_data, 0x202C2820); - - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); - W_REG(&cc->pllcontrol_data, 0x88888825); - - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); - if (spuravoid == 1) { - W_REG(&cc->pllcontrol_data, 0x00EC4EC4); - } else { - W_REG(&cc->pllcontrol_data, 0x00762762); - } - - tmp = PCTL_PLL_PLLCTL_UPD; - break; - - default: - /* bail out */ - return; - } - - tmp |= R_REG(&cc->pmucontrol); - W_REG(&cc->pmucontrol, tmp); -} - -/* select default xtal frequency for each chip */ -static const pmu1_xtaltab0_t *si_pmu1_xtaldef0(si_t *sih) -{ - switch (sih->chip) { - case BCM4329_CHIP_ID: - /* Default to 38400Khz */ - return &pmu1_xtaltab0_880_4329[PMU1_XTALTAB0_880_38400K]; - case BCM4319_CHIP_ID: - /* Default to 30000Khz */ - return &pmu1_xtaltab0_1440[PMU1_XTALTAB0_1440_30000K]; - case BCM4336_CHIP_ID: - /* Default to 26000Khz */ - return &pmu1_xtaltab0_960[PMU1_XTALTAB0_960_26000K]; - case BCM4330_CHIP_ID: - /* Default to 37400Khz */ - if (CST4330_CHIPMODE_SDIOD(sih->chipst)) - return &pmu1_xtaltab0_960[PMU1_XTALTAB0_960_37400K]; - else - return &pmu1_xtaltab0_1440[PMU1_XTALTAB0_1440_37400K]; - default: - break; - } - ASSERT(0); - return NULL; -} - -/* select xtal table for each chip */ -static const pmu1_xtaltab0_t *si_pmu1_xtaltab0(si_t *sih) -{ - switch (sih->chip) { - case BCM4329_CHIP_ID: - return pmu1_xtaltab0_880_4329; - case BCM4319_CHIP_ID: - return pmu1_xtaltab0_1440; - case BCM4336_CHIP_ID: - return pmu1_xtaltab0_960; - case BCM4330_CHIP_ID: - if (CST4330_CHIPMODE_SDIOD(sih->chipst)) - return pmu1_xtaltab0_960; - else - return pmu1_xtaltab0_1440; - default: - break; - } - ASSERT(0); - return NULL; -} - -/* query alp/xtal clock frequency */ -static u32 -si_pmu1_alpclk0(si_t *sih, chipcregs_t *cc) -{ - const pmu1_xtaltab0_t *xt; - u32 xf; - - /* Find the frequency in the table */ - xf = (R_REG(&cc->pmucontrol) & PCTL_XTALFREQ_MASK) >> - PCTL_XTALFREQ_SHIFT; - for (xt = si_pmu1_xtaltab0(sih); xt != NULL && xt->fref != 0; xt++) - if (xt->xf == xf) - break; - /* Could not find it so assign a default value */ - if (xt == NULL || xt->fref == 0) - xt = si_pmu1_xtaldef0(sih); - ASSERT(xt != NULL && xt->fref != 0); - - return xt->fref * 1000; -} - -/* select default pll fvco for each chip */ -static u32 si_pmu1_pllfvco0(si_t *sih) -{ - switch (sih->chip) { - case BCM4329_CHIP_ID: - return FVCO_880; - case BCM4319_CHIP_ID: - return FVCO_1440; - case BCM4336_CHIP_ID: - return FVCO_960; - case BCM4330_CHIP_ID: - if (CST4330_CHIPMODE_SDIOD(sih->chipst)) - return FVCO_960; - else - return FVCO_1440; - default: - break; - } - ASSERT(0); - return 0; -} - -static void si_pmu_set_4330_plldivs(si_t *sih) -{ - u32 FVCO = si_pmu1_pllfvco0(sih) / 1000; - u32 m1div, m2div, m3div, m4div, m5div, m6div; - u32 pllc1, pllc2; - - m2div = m3div = m4div = m6div = FVCO / 80; - m5div = FVCO / 160; - - if (CST4330_CHIPMODE_SDIOD(sih->chipst)) - m1div = FVCO / 80; - else - m1div = FVCO / 90; - pllc1 = - (m1div << PMU1_PLL0_PC1_M1DIV_SHIFT) | (m2div << - PMU1_PLL0_PC1_M2DIV_SHIFT) | - (m3div << PMU1_PLL0_PC1_M3DIV_SHIFT) | (m4div << - PMU1_PLL0_PC1_M4DIV_SHIFT); - si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL1, ~0, pllc1); - - pllc2 = si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL1, 0, 0); - pllc2 &= ~(PMU1_PLL0_PC2_M5DIV_MASK | PMU1_PLL0_PC2_M6DIV_MASK); - pllc2 |= - ((m5div << PMU1_PLL0_PC2_M5DIV_SHIFT) | - (m6div << PMU1_PLL0_PC2_M6DIV_SHIFT)); - si_pmu_pllcontrol(sih, PMU1_PLL0_PLLCTL2, ~0, pllc2); -} - -/* Set up PLL registers in the PMU as per the crystal speed. - * XtalFreq field in pmucontrol register being 0 indicates the PLL - * is not programmed and the h/w default is assumed to work, in which - * case the xtal frequency is unknown to the s/w so we need to call - * si_pmu1_xtaldef0() wherever it is needed to return a default value. - */ -static void si_pmu1_pllinit0(si_t *sih, chipcregs_t *cc, u32 xtal) -{ - const pmu1_xtaltab0_t *xt; - u32 tmp; - u32 buf_strength = 0; - u8 ndiv_mode = 1; - - /* Use h/w default PLL config */ - if (xtal == 0) { - return; - } - - /* Find the frequency in the table */ - for (xt = si_pmu1_xtaltab0(sih); xt != NULL && xt->fref != 0; xt++) - if (xt->fref == xtal) - break; - - /* Check current PLL state, bail out if it has been programmed or - * we don't know how to program it. - */ - if (xt == NULL || xt->fref == 0) { - return; - } - /* for 4319 bootloader already programs the PLL but bootloader does not - * program the PLL4 and PLL5. So Skip this check for 4319 - */ - if ((((R_REG(&cc->pmucontrol) & PCTL_XTALFREQ_MASK) >> - PCTL_XTALFREQ_SHIFT) == xt->xf) && - !((sih->chip == BCM4319_CHIP_ID) - || (sih->chip == BCM4330_CHIP_ID))) - return; - - switch (sih->chip) { - case BCM4329_CHIP_ID: - /* Change the BBPLL drive strength to 8 for all channels */ - buf_strength = 0x888888; - AND_REG(&cc->min_res_mask, - ~(PMURES_BIT(RES4329_BBPLL_PWRSW_PU) | - PMURES_BIT(RES4329_HT_AVAIL))); - AND_REG(&cc->max_res_mask, - ~(PMURES_BIT(RES4329_BBPLL_PWRSW_PU) | - PMURES_BIT(RES4329_HT_AVAIL))); - SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL, - PMU_MAX_TRANSITION_DLY); - ASSERT(!(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL)); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); - if (xt->fref == 38400) - tmp = 0x200024C0; - else if (xt->fref == 37400) - tmp = 0x20004500; - else if (xt->fref == 26000) - tmp = 0x200024C0; - else - tmp = 0x200005C0; /* Chip Dflt Settings */ - W_REG(&cc->pllcontrol_data, tmp); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); - tmp = - R_REG(&cc->pllcontrol_data) & PMU1_PLL0_PC5_CLK_DRV_MASK; - if ((xt->fref == 38400) || (xt->fref == 37400) - || (xt->fref == 26000)) - tmp |= 0x15; - else - tmp |= 0x25; /* Chip Dflt Settings */ - W_REG(&cc->pllcontrol_data, tmp); - break; - - case BCM4319_CHIP_ID: - /* Change the BBPLL drive strength to 2 for all channels */ - buf_strength = 0x222222; - - /* Make sure the PLL is off */ - /* WAR65104: Disable the HT_AVAIL resource first and then - * after a delay (more than downtime for HT_AVAIL) remove the - * BBPLL resource; backplane clock moves to ALP from HT. - */ - AND_REG(&cc->min_res_mask, - ~(PMURES_BIT(RES4319_HT_AVAIL))); - AND_REG(&cc->max_res_mask, - ~(PMURES_BIT(RES4319_HT_AVAIL))); - - udelay(100); - AND_REG(&cc->min_res_mask, - ~(PMURES_BIT(RES4319_BBPLL_PWRSW_PU))); - AND_REG(&cc->max_res_mask, - ~(PMURES_BIT(RES4319_BBPLL_PWRSW_PU))); - - udelay(100); - SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL, - PMU_MAX_TRANSITION_DLY); - ASSERT(!(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL)); - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL4); - tmp = 0x200005c0; - W_REG(&cc->pllcontrol_data, tmp); - break; - - case BCM4336_CHIP_ID: - AND_REG(&cc->min_res_mask, - ~(PMURES_BIT(RES4336_HT_AVAIL) | - PMURES_BIT(RES4336_MACPHY_CLKAVAIL))); - AND_REG(&cc->max_res_mask, - ~(PMURES_BIT(RES4336_HT_AVAIL) | - PMURES_BIT(RES4336_MACPHY_CLKAVAIL))); - udelay(100); - SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL, - PMU_MAX_TRANSITION_DLY); - ASSERT(!(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL)); - break; - - case BCM4330_CHIP_ID: - AND_REG(&cc->min_res_mask, - ~(PMURES_BIT(RES4330_HT_AVAIL) | - PMURES_BIT(RES4330_MACPHY_CLKAVAIL))); - AND_REG(&cc->max_res_mask, - ~(PMURES_BIT(RES4330_HT_AVAIL) | - PMURES_BIT(RES4330_MACPHY_CLKAVAIL))); - udelay(100); - SPINWAIT(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL, - PMU_MAX_TRANSITION_DLY); - ASSERT(!(R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL)); - break; - - default: - ASSERT(0); - } - - /* Write p1div and p2div to pllcontrol[0] */ - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); - tmp = R_REG(&cc->pllcontrol_data) & - ~(PMU1_PLL0_PC0_P1DIV_MASK | PMU1_PLL0_PC0_P2DIV_MASK); - tmp |= - ((xt-> - p1div << PMU1_PLL0_PC0_P1DIV_SHIFT) & PMU1_PLL0_PC0_P1DIV_MASK) | - ((xt-> - p2div << PMU1_PLL0_PC0_P2DIV_SHIFT) & PMU1_PLL0_PC0_P2DIV_MASK); - W_REG(&cc->pllcontrol_data, tmp); - - if ((sih->chip == BCM4330_CHIP_ID)) - si_pmu_set_4330_plldivs(sih); - - if ((sih->chip == BCM4329_CHIP_ID) - && (sih->chiprev == 0)) { - - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL1); - tmp = R_REG(&cc->pllcontrol_data); - tmp = tmp & (~DOT11MAC_880MHZ_CLK_DIVISOR_MASK); - tmp = tmp | DOT11MAC_880MHZ_CLK_DIVISOR_VAL; - W_REG(&cc->pllcontrol_data, tmp); - } - if ((sih->chip == BCM4319_CHIP_ID) || - (sih->chip == BCM4336_CHIP_ID) || - (sih->chip == BCM4330_CHIP_ID)) - ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MFB; - else - ndiv_mode = PMU1_PLL0_PC2_NDIV_MODE_MASH; - - /* Write ndiv_int and ndiv_mode to pllcontrol[2] */ - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); - tmp = R_REG(&cc->pllcontrol_data) & - ~(PMU1_PLL0_PC2_NDIV_INT_MASK | PMU1_PLL0_PC2_NDIV_MODE_MASK); - tmp |= - ((xt-> - ndiv_int << PMU1_PLL0_PC2_NDIV_INT_SHIFT) & - PMU1_PLL0_PC2_NDIV_INT_MASK) | ((ndiv_mode << - PMU1_PLL0_PC2_NDIV_MODE_SHIFT) & - PMU1_PLL0_PC2_NDIV_MODE_MASK); - W_REG(&cc->pllcontrol_data, tmp); - - /* Write ndiv_frac to pllcontrol[3] */ - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); - tmp = R_REG(&cc->pllcontrol_data) & ~PMU1_PLL0_PC3_NDIV_FRAC_MASK; - tmp |= ((xt->ndiv_frac << PMU1_PLL0_PC3_NDIV_FRAC_SHIFT) & - PMU1_PLL0_PC3_NDIV_FRAC_MASK); - W_REG(&cc->pllcontrol_data, tmp); - - /* Write clock driving strength to pllcontrol[5] */ - if (buf_strength) { - W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL5); - tmp = - R_REG(&cc->pllcontrol_data) & ~PMU1_PLL0_PC5_CLK_DRV_MASK; - tmp |= (buf_strength << PMU1_PLL0_PC5_CLK_DRV_SHIFT); - W_REG(&cc->pllcontrol_data, tmp); - } - - /* to operate the 4319 usb in 24MHz/48MHz; chipcontrol[2][84:83] needs - * to be updated. - */ - if ((sih->chip == BCM4319_CHIP_ID) - && (xt->fref != XTAL_FREQ_30000MHZ)) { - W_REG(&cc->chipcontrol_addr, PMU1_PLL0_CHIPCTL2); - tmp = - R_REG(&cc->chipcontrol_data) & ~CCTL_4319USB_XTAL_SEL_MASK; - if (xt->fref == XTAL_FREQ_24000MHZ) { - tmp |= - (CCTL_4319USB_24MHZ_PLL_SEL << - CCTL_4319USB_XTAL_SEL_SHIFT); - } else if (xt->fref == XTAL_FREQ_48000MHZ) { - tmp |= - (CCTL_4319USB_48MHZ_PLL_SEL << - CCTL_4319USB_XTAL_SEL_SHIFT); - } - W_REG(&cc->chipcontrol_data, tmp); - } - - /* Flush deferred pll control registers writes */ - if (sih->pmurev >= 2) - OR_REG(&cc->pmucontrol, PCTL_PLL_PLLCTL_UPD); - - /* Write XtalFreq. Set the divisor also. */ - tmp = R_REG(&cc->pmucontrol) & - ~(PCTL_ILP_DIV_MASK | PCTL_XTALFREQ_MASK); - tmp |= (((((xt->fref + 127) / 128) - 1) << PCTL_ILP_DIV_SHIFT) & - PCTL_ILP_DIV_MASK) | - ((xt->xf << PCTL_XTALFREQ_SHIFT) & PCTL_XTALFREQ_MASK); - - if ((sih->chip == BCM4329_CHIP_ID) - && sih->chiprev == 0) { - /* clear the htstretch before clearing HTReqEn */ - AND_REG(&cc->clkstretch, ~CSTRETCH_HT); - tmp &= ~PCTL_HT_REQ_EN; - } - - W_REG(&cc->pmucontrol, tmp); -} - -u32 si_pmu_ilp_clock(si_t *sih) -{ - static u32 ilpcycles_per_sec = 0; - - if (ISSIM_ENAB(sih)) - return ILP_CLOCK; - - if (ilpcycles_per_sec == 0) { - u32 start, end, delta; - u32 origidx = si_coreidx(sih); - chipcregs_t *cc = si_setcoreidx(sih, SI_CC_IDX); - ASSERT(cc != NULL); - start = R_REG(&cc->pmutimer); - mdelay(ILP_CALC_DUR); - end = R_REG(&cc->pmutimer); - delta = end - start; - ilpcycles_per_sec = delta * (1000 / ILP_CALC_DUR); - si_setcoreidx(sih, origidx); - } - - return ilpcycles_per_sec; -} - -void si_pmu_set_ldo_voltage(si_t *sih, u8 ldo, u8 voltage) -{ - u8 sr_cntl_shift = 0, rc_shift = 0, shift = 0, mask = 0; - u8 addr = 0; - - ASSERT(sih->cccaps & CC_CAP_PMU); - - switch (sih->chip) { - case BCM4336_CHIP_ID: - switch (ldo) { - case SET_LDO_VOLTAGE_CLDO_PWM: - addr = 4; - rc_shift = 1; - mask = 0xf; - break; - case SET_LDO_VOLTAGE_CLDO_BURST: - addr = 4; - rc_shift = 5; - mask = 0xf; - break; - case SET_LDO_VOLTAGE_LNLDO1: - addr = 4; - rc_shift = 17; - mask = 0xf; - break; - default: - ASSERT(false); - return; - } - break; - case BCM4330_CHIP_ID: - switch (ldo) { - case SET_LDO_VOLTAGE_CBUCK_PWM: - addr = 3; - rc_shift = 0; - mask = 0x1f; - break; - default: - ASSERT(false); - break; - } - break; - default: - ASSERT(false); - return; - } - - shift = sr_cntl_shift + rc_shift; - - si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_addr), - ~0, addr); - si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_data), - mask << shift, (voltage & mask) << shift); -} - -u16 si_pmu_fast_pwrup_delay(si_t *sih) -{ - uint delay = PMU_MAX_TRANSITION_DLY; - chipcregs_t *cc; - uint origidx; -#ifdef BCMDBG - char chn[8]; - chn[0] = 0; /* to suppress compile error */ -#endif - - ASSERT(sih->cccaps & CC_CAP_PMU); - - /* Remember original core before switch to chipc */ - origidx = si_coreidx(sih); - cc = si_setcoreidx(sih, SI_CC_IDX); - ASSERT(cc != NULL); - - switch (sih->chip) { - case BCM43224_CHIP_ID: - case BCM43225_CHIP_ID: - case BCM43421_CHIP_ID: - case BCM43235_CHIP_ID: - case BCM43236_CHIP_ID: - case BCM43238_CHIP_ID: - case BCM4331_CHIP_ID: - case BCM6362_CHIP_ID: - case BCM4313_CHIP_ID: - delay = ISSIM_ENAB(sih) ? 70 : 3700; - break; - case BCM4329_CHIP_ID: - if (ISSIM_ENAB(sih)) - delay = 70; - else { - u32 ilp = si_ilp_clock(sih); - delay = - (si_pmu_res_uptime(sih, cc, RES4329_HT_AVAIL) + - D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp - - 1) / ilp); - delay = (11 * delay) / 10; - } - break; - case BCM4319_CHIP_ID: - delay = ISSIM_ENAB(sih) ? 70 : 3700; - break; - case BCM4336_CHIP_ID: - if (ISSIM_ENAB(sih)) - delay = 70; - else { - u32 ilp = si_ilp_clock(sih); - delay = - (si_pmu_res_uptime(sih, cc, RES4336_HT_AVAIL) + - D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp - - 1) / ilp); - delay = (11 * delay) / 10; - } - break; - case BCM4330_CHIP_ID: - if (ISSIM_ENAB(sih)) - delay = 70; - else { - u32 ilp = si_ilp_clock(sih); - delay = - (si_pmu_res_uptime(sih, cc, RES4330_HT_AVAIL) + - D11SCC_SLOW2FAST_TRANSITION) * ((1000000 + ilp - - 1) / ilp); - delay = (11 * delay) / 10; - } - break; - default: - break; - } - /* Return to original core */ - si_setcoreidx(sih, origidx); - - return (u16) delay; -} - -void si_pmu_sprom_enable(si_t *sih, bool enable) -{ - chipcregs_t *cc; - uint origidx; - - /* Remember original core before switch to chipc */ - origidx = si_coreidx(sih); - cc = si_setcoreidx(sih, SI_CC_IDX); - ASSERT(cc != NULL); - - /* Return to original core */ - si_setcoreidx(sih, origidx); -} - -/* Read/write a chipcontrol reg */ -u32 si_pmu_chipcontrol(si_t *sih, uint reg, u32 mask, u32 val) -{ - si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, chipcontrol_addr), ~0, - reg); - return si_corereg(sih, SI_CC_IDX, - offsetof(chipcregs_t, chipcontrol_data), mask, val); -} - -/* Read/write a regcontrol reg */ -u32 si_pmu_regcontrol(si_t *sih, uint reg, u32 mask, u32 val) -{ - si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, regcontrol_addr), ~0, - reg); - return si_corereg(sih, SI_CC_IDX, - offsetof(chipcregs_t, regcontrol_data), mask, val); -} - -/* Read/write a pllcontrol reg */ -u32 si_pmu_pllcontrol(si_t *sih, uint reg, u32 mask, u32 val) -{ - si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, pllcontrol_addr), ~0, - reg); - return si_corereg(sih, SI_CC_IDX, - offsetof(chipcregs_t, pllcontrol_data), mask, val); -} - -/* PMU PLL update */ -void si_pmu_pllupd(si_t *sih) -{ - si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, pmucontrol), - PCTL_PLL_PLLCTL_UPD, PCTL_PLL_PLLCTL_UPD); -} - -/* query alp/xtal clock frequency */ -u32 si_pmu_alp_clock(si_t *sih) -{ - chipcregs_t *cc; - uint origidx; - u32 clock = ALP_CLOCK; - - /* bail out with default */ - if (!PMUCTL_ENAB(sih)) - return clock; - - ASSERT(sih->cccaps & CC_CAP_PMU); - - /* Remember original core before switch to chipc */ - origidx = si_coreidx(sih); - cc = si_setcoreidx(sih, SI_CC_IDX); - ASSERT(cc != NULL); - - switch (sih->chip) { - case BCM43224_CHIP_ID: - case BCM43225_CHIP_ID: - case BCM43421_CHIP_ID: - case BCM43235_CHIP_ID: - case BCM43236_CHIP_ID: - case BCM43238_CHIP_ID: - case BCM4331_CHIP_ID: - case BCM6362_CHIP_ID: - case BCM4716_CHIP_ID: - case BCM4748_CHIP_ID: - case BCM47162_CHIP_ID: - case BCM4313_CHIP_ID: - case BCM5357_CHIP_ID: - /* always 20Mhz */ - clock = 20000 * 1000; - break; - case BCM4329_CHIP_ID: - case BCM4319_CHIP_ID: - case BCM4336_CHIP_ID: - case BCM4330_CHIP_ID: - - clock = si_pmu1_alpclk0(sih, cc); - break; - case BCM5356_CHIP_ID: - /* always 25Mhz */ - clock = 25000 * 1000; - break; - default: - break; - } - - /* Return to original core */ - si_setcoreidx(sih, origidx); - return clock; -} - -void si_pmu_spuravoid(si_t *sih, u8 spuravoid) -{ - chipcregs_t *cc; - uint origidx, intr_val; - u32 tmp = 0; - - /* Remember original core before switch to chipc */ - cc = (chipcregs_t *) si_switch_core(sih, CC_CORE_ID, &origidx, - &intr_val); - ASSERT(cc != NULL); - - /* force the HT off */ - if (sih->chip == BCM4336_CHIP_ID) { - tmp = R_REG(&cc->max_res_mask); - tmp &= ~RES4336_HT_AVAIL; - W_REG(&cc->max_res_mask, tmp); - /* wait for the ht to really go away */ - SPINWAIT(((R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL) == 0), - 10000); - ASSERT((R_REG(&cc->clk_ctl_st) & CCS_HTAVAIL) == 0); - } - - /* update the pll changes */ - si_pmu_spuravoid_pllupdate(sih, cc, spuravoid); - - /* enable HT back on */ - if (sih->chip == BCM4336_CHIP_ID) { - tmp = R_REG(&cc->max_res_mask); - tmp |= RES4336_HT_AVAIL; - W_REG(&cc->max_res_mask, tmp); - } - - /* Return to original core */ - si_restore_core(sih, origidx, intr_val); -} - -/* initialize PMU */ -void si_pmu_init(si_t *sih) -{ - chipcregs_t *cc; - uint origidx; - - ASSERT(sih->cccaps & CC_CAP_PMU); - - /* Remember original core before switch to chipc */ - origidx = si_coreidx(sih); - cc = si_setcoreidx(sih, SI_CC_IDX); - ASSERT(cc != NULL); - - if (sih->pmurev == 1) - AND_REG(&cc->pmucontrol, ~PCTL_NOILP_ON_WAIT); - else if (sih->pmurev >= 2) - OR_REG(&cc->pmucontrol, PCTL_NOILP_ON_WAIT); - - if ((sih->chip == BCM4329_CHIP_ID) && (sih->chiprev == 2)) { - /* Fix for 4329b0 bad LPOM state. */ - W_REG(&cc->regcontrol_addr, 2); - OR_REG(&cc->regcontrol_data, 0x100); - - W_REG(&cc->regcontrol_addr, 3); - OR_REG(&cc->regcontrol_data, 0x4); - } - - /* Return to original core */ - si_setcoreidx(sih, origidx); -} - -/* initialize PMU chip controls and other chip level stuff */ -void si_pmu_chip_init(si_t *sih) -{ - uint origidx; - - ASSERT(sih->cccaps & CC_CAP_PMU); - - /* Gate off SPROM clock and chip select signals */ - si_pmu_sprom_enable(sih, false); - - /* Remember original core */ - origidx = si_coreidx(sih); - - /* Return to original core */ - si_setcoreidx(sih, origidx); -} - -/* initialize PMU switch/regulators */ -void si_pmu_swreg_init(si_t *sih) -{ - ASSERT(sih->cccaps & CC_CAP_PMU); - - switch (sih->chip) { - case BCM4336_CHIP_ID: - /* Reduce CLDO PWM output voltage to 1.2V */ - si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_CLDO_PWM, 0xe); - /* Reduce CLDO BURST output voltage to 1.2V */ - si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_CLDO_BURST, - 0xe); - /* Reduce LNLDO1 output voltage to 1.2V */ - si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_LNLDO1, 0xe); - if (sih->chiprev == 0) - si_pmu_regcontrol(sih, 2, 0x400000, 0x400000); - break; - - case BCM4330_CHIP_ID: - /* CBUCK Voltage is 1.8 by default and set that to 1.5 */ - si_pmu_set_ldo_voltage(sih, SET_LDO_VOLTAGE_CBUCK_PWM, 0); - break; - default: - break; - } -} - -/* initialize PLL */ -void si_pmu_pll_init(si_t *sih, uint xtalfreq) -{ - chipcregs_t *cc; - uint origidx; - - ASSERT(sih->cccaps & CC_CAP_PMU); - - /* Remember original core before switch to chipc */ - origidx = si_coreidx(sih); - cc = si_setcoreidx(sih, SI_CC_IDX); - ASSERT(cc != NULL); - - switch (sih->chip) { - case BCM4329_CHIP_ID: - if (xtalfreq == 0) - xtalfreq = 38400; - si_pmu1_pllinit0(sih, cc, xtalfreq); - break; - case BCM4313_CHIP_ID: - case BCM43224_CHIP_ID: - case BCM43225_CHIP_ID: - case BCM43421_CHIP_ID: - case BCM43235_CHIP_ID: - case BCM43236_CHIP_ID: - case BCM43238_CHIP_ID: - case BCM4331_CHIP_ID: - case BCM6362_CHIP_ID: - /* ??? */ - break; - case BCM4319_CHIP_ID: - case BCM4336_CHIP_ID: - case BCM4330_CHIP_ID: - si_pmu1_pllinit0(sih, cc, xtalfreq); - break; - default: - break; - } - - /* Return to original core */ - si_setcoreidx(sih, origidx); -} - -/* initialize PMU resources */ -void si_pmu_res_init(si_t *sih) -{ - chipcregs_t *cc; - uint origidx; - const pmu_res_updown_t *pmu_res_updown_table = NULL; - uint pmu_res_updown_table_sz = 0; - const pmu_res_depend_t *pmu_res_depend_table = NULL; - uint pmu_res_depend_table_sz = 0; - u32 min_mask = 0, max_mask = 0; - char name[8], *val; - uint i, rsrcs; - - ASSERT(sih->cccaps & CC_CAP_PMU); - - /* Remember original core before switch to chipc */ - origidx = si_coreidx(sih); - cc = si_setcoreidx(sih, SI_CC_IDX); - ASSERT(cc != NULL); - - switch (sih->chip) { - case BCM4329_CHIP_ID: - /* Optimize resources up/down timers */ - if (ISSIM_ENAB(sih)) { - pmu_res_updown_table = NULL; - pmu_res_updown_table_sz = 0; - } else { - pmu_res_updown_table = bcm4329_res_updown; - pmu_res_updown_table_sz = ARRAY_SIZE(bcm4329_res_updown); - } - /* Optimize resources dependencies */ - pmu_res_depend_table = bcm4329_res_depend; - pmu_res_depend_table_sz = ARRAY_SIZE(bcm4329_res_depend); - break; - - case BCM4319_CHIP_ID: - /* Optimize resources up/down timers */ - if (ISSIM_ENAB(sih)) { - pmu_res_updown_table = bcm4319a0_res_updown_qt; - pmu_res_updown_table_sz = - ARRAY_SIZE(bcm4319a0_res_updown_qt); - } else { - pmu_res_updown_table = bcm4319a0_res_updown; - pmu_res_updown_table_sz = - ARRAY_SIZE(bcm4319a0_res_updown); - } - /* Optimize resources dependancies masks */ - pmu_res_depend_table = bcm4319a0_res_depend; - pmu_res_depend_table_sz = ARRAY_SIZE(bcm4319a0_res_depend); - break; - - case BCM4336_CHIP_ID: - /* Optimize resources up/down timers */ - if (ISSIM_ENAB(sih)) { - pmu_res_updown_table = bcm4336a0_res_updown_qt; - pmu_res_updown_table_sz = - ARRAY_SIZE(bcm4336a0_res_updown_qt); - } else { - pmu_res_updown_table = bcm4336a0_res_updown; - pmu_res_updown_table_sz = - ARRAY_SIZE(bcm4336a0_res_updown); - } - /* Optimize resources dependancies masks */ - pmu_res_depend_table = bcm4336a0_res_depend; - pmu_res_depend_table_sz = ARRAY_SIZE(bcm4336a0_res_depend); - break; - - case BCM4330_CHIP_ID: - /* Optimize resources up/down timers */ - if (ISSIM_ENAB(sih)) { - pmu_res_updown_table = bcm4330a0_res_updown_qt; - pmu_res_updown_table_sz = - ARRAY_SIZE(bcm4330a0_res_updown_qt); - } else { - pmu_res_updown_table = bcm4330a0_res_updown; - pmu_res_updown_table_sz = - ARRAY_SIZE(bcm4330a0_res_updown); - } - /* Optimize resources dependancies masks */ - pmu_res_depend_table = bcm4330a0_res_depend; - pmu_res_depend_table_sz = ARRAY_SIZE(bcm4330a0_res_depend); - break; - - default: - break; - } - - /* # resources */ - rsrcs = (sih->pmucaps & PCAP_RC_MASK) >> PCAP_RC_SHIFT; - - /* Program up/down timers */ - while (pmu_res_updown_table_sz--) { - ASSERT(pmu_res_updown_table != NULL); - W_REG(&cc->res_table_sel, - pmu_res_updown_table[pmu_res_updown_table_sz].resnum); - W_REG(&cc->res_updn_timer, - pmu_res_updown_table[pmu_res_updown_table_sz].updown); - } - /* Apply nvram overrides to up/down timers */ - for (i = 0; i < rsrcs; i++) { - snprintf(name, sizeof(name), "r%dt", i); - val = getvar(NULL, name); - if (val == NULL) - continue; - W_REG(&cc->res_table_sel, (u32) i); - W_REG(&cc->res_updn_timer, - (u32) simple_strtoul(val, NULL, 0)); - } - - /* Program resource dependencies table */ - while (pmu_res_depend_table_sz--) { - ASSERT(pmu_res_depend_table != NULL); - if (pmu_res_depend_table[pmu_res_depend_table_sz].filter != NULL - && !(pmu_res_depend_table[pmu_res_depend_table_sz]. - filter) (sih)) - continue; - for (i = 0; i < rsrcs; i++) { - if ((pmu_res_depend_table[pmu_res_depend_table_sz]. - res_mask & PMURES_BIT(i)) == 0) - continue; - W_REG(&cc->res_table_sel, i); - switch (pmu_res_depend_table[pmu_res_depend_table_sz]. - action) { - case RES_DEPEND_SET: - W_REG(&cc->res_dep_mask, - pmu_res_depend_table - [pmu_res_depend_table_sz].depend_mask); - break; - case RES_DEPEND_ADD: - OR_REG(&cc->res_dep_mask, - pmu_res_depend_table - [pmu_res_depend_table_sz].depend_mask); - break; - case RES_DEPEND_REMOVE: - AND_REG(&cc->res_dep_mask, - ~pmu_res_depend_table - [pmu_res_depend_table_sz].depend_mask); - break; - default: - ASSERT(0); - break; - } - } - } - /* Apply nvram overrides to dependancies masks */ - for (i = 0; i < rsrcs; i++) { - snprintf(name, sizeof(name), "r%dd", i); - val = getvar(NULL, name); - if (val == NULL) - continue; - W_REG(&cc->res_table_sel, (u32) i); - W_REG(&cc->res_dep_mask, - (u32) simple_strtoul(val, NULL, 0)); - } - - /* Determine min/max rsrc masks */ - si_pmu_res_masks(sih, &min_mask, &max_mask); - - /* It is required to program max_mask first and then min_mask */ - - /* Program max resource mask */ - - if (max_mask) { - W_REG(&cc->max_res_mask, max_mask); - } - - /* Program min resource mask */ - - if (min_mask) { - W_REG(&cc->min_res_mask, min_mask); - } - - /* Add some delay; allow resources to come up and settle. */ - mdelay(2); - - /* Return to original core */ - si_setcoreidx(sih, origidx); -} - -u32 si_pmu_measure_alpclk(si_t *sih) -{ - chipcregs_t *cc; - uint origidx; - u32 alp_khz; - - if (sih->pmurev < 10) - return 0; - - ASSERT(sih->cccaps & CC_CAP_PMU); - - /* Remember original core before switch to chipc */ - origidx = si_coreidx(sih); - cc = si_setcoreidx(sih, SI_CC_IDX); - ASSERT(cc != NULL); - - if (R_REG(&cc->pmustatus) & PST_EXTLPOAVAIL) { - u32 ilp_ctr, alp_hz; - - /* Enable the reg to measure the freq, in case disabled before */ - W_REG(&cc->pmu_xtalfreq, - 1U << PMU_XTALFREQ_REG_MEASURE_SHIFT); - - /* Delay for well over 4 ILP clocks */ - udelay(1000); - - /* Read the latched number of ALP ticks per 4 ILP ticks */ - ilp_ctr = - R_REG(&cc->pmu_xtalfreq) & PMU_XTALFREQ_REG_ILPCTR_MASK; - - /* Turn off the PMU_XTALFREQ_REG_MEASURE_SHIFT bit to save power */ - W_REG(&cc->pmu_xtalfreq, 0); - - /* Calculate ALP frequency */ - alp_hz = (ilp_ctr * EXT_ILP_HZ) / 4; - - /* Round to nearest 100KHz, and at the same time convert to KHz */ - alp_khz = (alp_hz + 50000) / 100000 * 100; - } else - alp_khz = 0; - - /* Return to original core */ - si_setcoreidx(sih, origidx); - - return alp_khz; -} - -bool si_pmu_is_otp_powered(si_t *sih) -{ - uint idx; - chipcregs_t *cc; - bool st; - - /* Remember original core before switch to chipc */ - idx = si_coreidx(sih); - cc = si_setcoreidx(sih, SI_CC_IDX); - ASSERT(cc != NULL); - - switch (sih->chip) { - case BCM4329_CHIP_ID: - st = (R_REG(&cc->res_state) & PMURES_BIT(RES4329_OTP_PU)) - != 0; - break; - case BCM4319_CHIP_ID: - st = (R_REG(&cc->res_state) & PMURES_BIT(RES4319_OTP_PU)) - != 0; - break; - case BCM4336_CHIP_ID: - st = (R_REG(&cc->res_state) & PMURES_BIT(RES4336_OTP_PU)) - != 0; - break; - case BCM4330_CHIP_ID: - st = (R_REG(&cc->res_state) & PMURES_BIT(RES4330_OTP_PU)) - != 0; - break; - - /* These chip doesn't use PMU bit to power up/down OTP. OTP always on. - * Use OTP_INIT command to reset/refresh state. - */ - case BCM43224_CHIP_ID: - case BCM43225_CHIP_ID: - case BCM43421_CHIP_ID: - case BCM43236_CHIP_ID: - case BCM43235_CHIP_ID: - case BCM43238_CHIP_ID: - st = true; - break; - default: - st = true; - break; - } - - /* Return to original core */ - si_setcoreidx(sih, idx); - return st; -} - -/* power up/down OTP through PMU resources */ -void si_pmu_otp_power(si_t *sih, bool on) -{ - chipcregs_t *cc; - uint origidx; - u32 rsrcs = 0; /* rsrcs to turn on/off OTP power */ - - ASSERT(sih->cccaps & CC_CAP_PMU); - - /* Don't do anything if OTP is disabled */ - if (si_is_otp_disabled(sih)) { - return; - } - - /* Remember original core before switch to chipc */ - origidx = si_coreidx(sih); - cc = si_setcoreidx(sih, SI_CC_IDX); - ASSERT(cc != NULL); - - switch (sih->chip) { - case BCM4329_CHIP_ID: - rsrcs = PMURES_BIT(RES4329_OTP_PU); - break; - case BCM4319_CHIP_ID: - rsrcs = PMURES_BIT(RES4319_OTP_PU); - break; - case BCM4336_CHIP_ID: - rsrcs = PMURES_BIT(RES4336_OTP_PU); - break; - case BCM4330_CHIP_ID: - rsrcs = PMURES_BIT(RES4330_OTP_PU); - break; - default: - break; - } - - if (rsrcs != 0) { - u32 otps; - - /* Figure out the dependancies (exclude min_res_mask) */ - u32 deps = si_pmu_res_deps(sih, cc, rsrcs, true); - u32 min_mask = 0, max_mask = 0; - si_pmu_res_masks(sih, &min_mask, &max_mask); - deps &= ~min_mask; - /* Turn on/off the power */ - if (on) { - OR_REG(&cc->min_res_mask, (rsrcs | deps)); - SPINWAIT(!(R_REG(&cc->res_state) & rsrcs), - PMU_MAX_TRANSITION_DLY); - ASSERT(R_REG(&cc->res_state) & rsrcs); - } else { - AND_REG(&cc->min_res_mask, ~(rsrcs | deps)); - } - - SPINWAIT((((otps = R_REG(&cc->otpstatus)) & OTPS_READY) != - (on ? OTPS_READY : 0)), 100); - ASSERT((otps & OTPS_READY) == (on ? OTPS_READY : 0)); - } - - /* Return to original core */ - si_setcoreidx(sih, origidx); -} diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_pmu.h b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_pmu.h deleted file mode 100644 index 9fa48e464f8b..000000000000 --- a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_pmu.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2011 Broadcom Corporation - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - - -#ifndef WLC_PMU_H_ -#define WLC_PMU_H_ - -#include - -#include - -/* - * LDO selections used in si_pmu_set_ldo_voltage - */ -#define SET_LDO_VOLTAGE_LDO1 1 -#define SET_LDO_VOLTAGE_LDO2 2 -#define SET_LDO_VOLTAGE_LDO3 3 -#define SET_LDO_VOLTAGE_PAREF 4 -#define SET_LDO_VOLTAGE_CLDO_PWM 5 -#define SET_LDO_VOLTAGE_CLDO_BURST 6 -#define SET_LDO_VOLTAGE_CBUCK_PWM 7 -#define SET_LDO_VOLTAGE_CBUCK_BURST 8 -#define SET_LDO_VOLTAGE_LNLDO1 9 -#define SET_LDO_VOLTAGE_LNLDO2_SEL 10 - -extern void si_pmu_set_ldo_voltage(si_t *sih, u8 ldo, u8 voltage); -extern u16 si_pmu_fast_pwrup_delay(si_t *sih); -extern void si_pmu_sprom_enable(si_t *sih, bool enable); -extern u32 si_pmu_chipcontrol(si_t *sih, uint reg, u32 mask, u32 val); -extern u32 si_pmu_regcontrol(si_t *sih, uint reg, u32 mask, u32 val); -extern u32 si_pmu_ilp_clock(si_t *sih); -extern u32 si_pmu_alp_clock(si_t *sih); -extern void si_pmu_pllupd(si_t *sih); -extern void si_pmu_spuravoid(si_t *sih, u8 spuravoid); -extern u32 si_pmu_pllcontrol(si_t *sih, uint reg, u32 mask, u32 val); -extern void si_pmu_init(si_t *sih); -extern void si_pmu_chip_init(si_t *sih); -extern void si_pmu_pll_init(si_t *sih, u32 xtalfreq); -extern void si_pmu_res_init(si_t *sih); -extern void si_pmu_swreg_init(si_t *sih); -extern u32 si_pmu_measure_alpclk(si_t *sih); -extern bool si_pmu_is_otp_powered(si_t *sih); -extern void si_pmu_otp_power(si_t *sih, bool on); - -#endif /* WLC_PMU_H_ */ diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_pub.h b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_pub.h index 273c5085720f..b956c23fa467 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_pub.h +++ b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_pub.h @@ -92,8 +92,6 @@ #define AIDMAPSZ (roundup(MAXSCB, NBBY)/NBBY) /* aid bitmap size in bytes */ #endif /* AIDMAPSZ */ -struct ieee80211_tx_queue_params; - typedef struct wlc_tunables { int ntxd; /* size of tx descriptor table */ int nrxd; /* size of rx descriptor table */ @@ -517,9 +515,9 @@ extern int wlc_get_header_len(void); extern void wlc_mac_bcn_promisc_change(struct wlc_info *wlc, bool promisc); extern void wlc_set_addrmatch(struct wlc_info *wlc, int match_reg_offset, const u8 *addr); -extern void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, - const struct ieee80211_tx_queue_params *arg, +extern void wlc_wme_setparams(struct wlc_info *wlc, u16 aci, void *arg, bool suspend); + extern struct wlc_pub *wlc_pub(void *wlc); /* common functions for every port */ diff --git a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_stf.c b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_stf.c index 25bb2ca7ce38..098fd59ee153 100644 --- a/trunk/drivers/staging/brcm80211/brcmsmac/wlc_stf.c +++ b/trunk/drivers/staging/brcm80211/brcmsmac/wlc_stf.c @@ -225,7 +225,7 @@ static int wlc_stf_txcore_set(struct wlc_info *wlc, u8 Nsts, u8 core_mask) } } - return 0; + return BCME_OK; } static int wlc_stf_spatial_policy_set(struct wlc_info *wlc, int val) @@ -241,7 +241,7 @@ static int wlc_stf_spatial_policy_set(struct wlc_info *wlc, int val) wlc->stf->txchain : txcore_default[i]; wlc_stf_txcore_set(wlc, (u8) i, core_mask); } - return 0; + return BCME_OK; } int wlc_stf_txchain_set(struct wlc_info *wlc, s32 int_val, bool force) @@ -251,7 +251,7 @@ int wlc_stf_txchain_set(struct wlc_info *wlc, s32 int_val, bool force) uint i; if (wlc->stf->txchain == txchain) - return 0; + return BCME_OK; if ((txchain & ~wlc->stf->hw_txchain) || !(txchain & wlc->stf->hw_txchain)) @@ -303,7 +303,7 @@ int wlc_stf_txchain_set(struct wlc_info *wlc, s32 int_val, bool force) for (i = 1; i <= MAX_STREAMS_SUPPORTED; i++) wlc_stf_txcore_set(wlc, (u8) i, txcore_default[i]); - return 0; + return BCME_OK; } /* update wlc->stf->ss_opmode which represents the operational stf_ss mode we're using */ @@ -371,7 +371,7 @@ void wlc_stf_detach(struct wlc_info *wlc) int wlc_stf_ant_txant_validate(struct wlc_info *wlc, s8 val) { - int bcmerror = 0; + int bcmerror = BCME_OK; /* when there is only 1 tx_streams, don't allow to change the txant */ if (WLCISNPHY(wlc->band) && (wlc->stf->txstreams == 1)) @@ -395,7 +395,7 @@ int wlc_stf_ant_txant_validate(struct wlc_info *wlc, s8 val) break; } - if (bcmerror == 0) + if (bcmerror == BCME_OK) wlc->stf->txant = (s8) val; return bcmerror; diff --git a/trunk/drivers/staging/brcm80211/include/bcmdevs.h b/trunk/drivers/staging/brcm80211/include/bcmdevs.h index 26947efa83e8..075883a93529 100644 --- a/trunk/drivers/staging/brcm80211/include/bcmdevs.h +++ b/trunk/drivers/staging/brcm80211/include/bcmdevs.h @@ -17,10 +17,17 @@ #ifndef _BCMDEVS_H #define _BCMDEVS_H +/* PCI vendor IDs */ +#define VENDOR_BROADCOM 0x14e4 + +/* DONGLE VID/PIDs */ +#define BCM_DNGL_VID 0x0a5c +#define BCM_DNGL_BDC_PID 0x0bdc + #define BCM4325_D11DUAL_ID 0x431b #define BCM4325_D11G_ID 0x431c #define BCM4325_D11A_ID 0x431d - +#define BCM4329_D11N_ID 0x432e /* 4329 802.11n dualband device */ #define BCM4329_D11N2G_ID 0x432f /* 4329 802.11n 2.4G device */ #define BCM4329_D11N5G_ID 0x4330 /* 4329 802.11n 5G device */ #define BCM4329_D11NDUAL_ID 0x432e @@ -30,13 +37,22 @@ #define BCM4319_D11N5G_ID 0x4339 /* 4319 802.11n 5G device */ #define BCM43224_D11N_ID 0x4353 /* 43224 802.11n dualband device */ - #define BCM43225_D11N2G_ID 0x4357 /* 43225 802.11n 2.4GHz device */ #define BCM43236_D11N_ID 0x4346 /* 43236 802.11n dualband device */ #define BCM43236_D11N2G_ID 0x4347 /* 43236 802.11n 2.4GHz device */ +#define BCM43236_D11N5G_ID 0x4348 /* 43236 802.11n 5GHz device */ +#define BCM43421_D11N_ID 0xA99D /* 43421 802.11n dualband device */ #define BCM4313_D11N2G_ID 0x4727 /* 4313 802.11n 2.4G device */ +#define BCM4330_D11N_ID 0x4360 /* 4330 802.11n dualband device */ +#define BCM4330_D11N2G_ID 0x4361 /* 4330 802.11n 2.4G device */ +#define BCM4330_D11N5G_ID 0x4362 /* 4330 802.11n 5G device */ +#define BCM4336_D11N_ID 0x4343 /* 4336 802.11n 2.4GHz device */ +#define BCM6362_D11N_ID 0x435f /* 6362 802.11n dualband device */ +#define BCM4331_D11N_ID 0x4331 /* 4331 802.11n dualband id */ +#define BCM4331_D11N2G_ID 0x4332 /* 4331 802.11n 2.4Ghz band id */ +#define BCM4331_D11N5G_ID 0x4333 /* 4331 802.11n 5Ghz band id */ /* Chip IDs */ #define BCM4313_CHIP_ID 0x4313 /* 4313 chip id */ @@ -44,6 +60,7 @@ #define BCM43224_CHIP_ID 43224 /* 43224 chipcommon chipid */ #define BCM43225_CHIP_ID 43225 /* 43225 chipcommon chipid */ +#define BCM43228_CHIP_ID 43228 /* 43228 chipcommon chipid */ #define BCM43421_CHIP_ID 43421 /* 43421 chipcommon chipid */ #define BCM43235_CHIP_ID 43235 /* 43235 chipcommon chipid */ #define BCM43236_CHIP_ID 43236 /* 43236 chipcommon chipid */ @@ -65,23 +82,57 @@ /* Package IDs */ #define BCM4329_289PIN_PKG_ID 0 /* 4329 289-pin package id */ #define BCM4329_182PIN_PKG_ID 1 /* 4329N 182-pin package id */ +#define BCM4716_PKG_ID 8 /* 4716 package id */ #define BCM4717_PKG_ID 9 /* 4717 package id */ #define BCM4718_PKG_ID 10 /* 4718 package id */ +#define BCM5356_PKG_NONMODE 1 /* 5356 package without nmode suppport */ +#define BCM5358U_PKG_ID 8 /* 5358U package id */ +#define BCM5358_PKG_ID 9 /* 5358 package id */ +#define BCM47186_PKG_ID 10 /* 47186 package id */ +#define BCM5357_PKG_ID 11 /* 5357 package id */ +#define BCM5356U_PKG_ID 12 /* 5356U package id */ +#define HDLSIM5350_PKG_ID 1 /* HDL simulator package id for a 5350 */ #define HDLSIM_PKG_ID 14 /* HDL simulator package id */ #define HWSIM_PKG_ID 15 /* Hardware simulator package id */ +#define BCM43224_FAB_CSM 0x8 /* the chip is manufactured by CSM */ #define BCM43224_FAB_SMIC 0xa /* the chip is manufactured by SMIC */ +#define BCM4336_WLBGA_PKG_ID 0x8 /* boardflags */ +#define BFL_RESERVED1 0x00000001 #define BFL_PACTRL 0x00000002 /* Board has gpio 9 controlling the PA */ +#define BFL_AIRLINEMODE 0x00000004 /* Board implements gpio 13 radio disable indication */ +#define BFL_ADCDIV 0x00000008 /* Board has the rssi ADC divider */ +#define BFL_ENETROBO 0x00000010 /* Board has robo switch or core */ #define BFL_NOPLLDOWN 0x00000020 /* Not ok to power down the chip pll and oscillator */ +#define BFL_CCKHIPWR 0x00000040 /* Can do high-power CCK transmission */ +#define BFL_ENETADM 0x00000080 /* Board has ADMtek switch */ +#define BFL_ENETVLAN 0x00000100 /* Board has VLAN capability */ +#define BFL_NOPCI 0x00000400 /* Board leaves PCI floating */ #define BFL_FEM 0x00000800 /* Board supports the Front End Module */ #define BFL_EXTLNA 0x00001000 /* Board has an external LNA in 2.4GHz band */ +#define BFL_HGPA 0x00002000 /* Board has a high gain PA */ +#define BFL_RESERVED2 0x00004000 +#define BFL_ALTIQ 0x00008000 /* Alternate I/Q settings */ #define BFL_NOPA 0x00010000 /* Board has no PA */ +#define BFL_RSSIINV 0x00020000 /* Board's RSSI uses positive slope(not TSSI) */ +#define BFL_PAREF 0x00040000 /* Board uses the PARef LDO */ +#define BFL_3TSWITCH 0x00080000 /* Board uses a triple throw switch shared with BT */ +#define BFL_PHASESHIFT 0x00100000 /* Board can support phase shifter */ #define BFL_BUCKBOOST 0x00200000 /* Power topology uses BUCKBOOST */ #define BFL_FEM_BT 0x00400000 /* Board has FEM and switch to share antenna w/ BT */ #define BFL_NOCBUCK 0x00800000 /* Power topology doesn't use CBUCK */ +#define BFL_CCKFAVOREVM 0x01000000 /* Favor CCK EVM over spectral mask */ #define BFL_PALDO 0x02000000 /* Power topology uses PALDO */ +#define BFL_LNLDO2_2P5 0x04000000 /* Select 2.5V as LNLDO2 output voltage */ +#define BFL_FASTPWR 0x08000000 +#define BFL_UCPWRCTL_MININDX 0x08000000 /* Enforce min power index to avoid FEM damage */ #define BFL_EXTLNA_5GHz 0x10000000 /* Board has an external LNA in 5GHz band */ +#define BFL_TRSW_1by2 0x20000000 /* Board has 2 TRSW's in 1by2 designs */ +#define BFL_LO_TRSW_R_5GHz 0x40000000 /* In 5G do not throw TRSW to T for clipLO gain */ +#define BFL_ELNA_GAINDEF 0x80000000 /* Backoff InitGain based on elna_2g/5g field + * when this flag is set + */ /* boardflags2 */ #define BFL2_RXBB_INT_REG_DIS 0x00000001 /* Board has an external rxbb regulator */ @@ -90,12 +141,16 @@ #define BFL2_2X4_DIV 0x00000008 /* Board supports the 2X4 diversity switch */ #define BFL2_5G_PWRGAIN 0x00000010 /* Board supports 5G band power gain */ #define BFL2_PCIEWAR_OVR 0x00000020 /* Board overrides ASPM and Clkreq settings */ +#define BFL2_CAESERS_BRD 0x00000040 /* Board is Caesers brd (unused by sw) */ #define BFL2_LEGACY 0x00000080 #define BFL2_SKWRKFEM_BRD 0x00000100 /* 4321mcm93 board uses Skyworks FEM */ #define BFL2_SPUR_WAR 0x00000200 /* Board has a WAR for clock-harmonic spurs */ #define BFL2_GPLL_WAR 0x00000400 /* Flag to narrow G-band PLL loop b/w */ +#define BFL2_TRISTATE_LED 0x00000800 /* Tri-state the LED */ #define BFL2_SINGLEANT_CCK 0x00001000 /* Tx CCK pkts on Ant 0 only */ #define BFL2_2G_SPUR_WAR 0x00002000 /* WAR to reduce and avoid clock-harmonic spurs in 2G */ +#define BFL2_BPHY_ALL_TXCORES 0x00004000 /* Transmit bphy frames using all tx cores */ +#define BFL2_FCC_BANDEDGE_WAR 0x00008000 /* using 40Mhz LPF for 20Mhz bandedge channels */ #define BFL2_GPLL_WAR2 0x00010000 /* Flag to widen G-band PLL loop b/w */ #define BFL2_IPALVLSHIFT_3P3 0x00020000 #define BFL2_INTERNDET_TXIQCAL 0x00040000 /* Use internal envelope detector for TX IQCAL */ @@ -105,19 +160,32 @@ */ /* board specific GPIO assignment, gpio 0-3 are also customer-configurable led */ +#define BOARD_GPIO_RESERVED1 0x010 +#define BOARD_GPIO_RESERVED2 0x020 +#define BOARD_GPIO_RESERVED3 0x080 +#define BOARD_GPIO_RESERVED4 0x100 #define BOARD_GPIO_PACTRL 0x200 /* bit 9 controls the PA on new 4306 boards */ #define BOARD_GPIO_12 0x1000 /* gpio 12 */ #define BOARD_GPIO_13 0x2000 /* gpio 13 */ +#define BOARD_GPIO_RESERVED5 0x0800 +#define BOARD_GPIO_RESERVED6 0x2000 +#define BOARD_GPIO_RESERVED7 0x4000 +#define BOARD_GPIO_RESERVED8 0x8000 #define PCI_CFG_GPIO_SCS 0x10 /* PCI config space bit 4 for 4306c0 slow clock source */ +#define PCI_CFG_GPIO_HWRAD 0x20 /* PCI config space GPIO 13 for hw radio disable */ #define PCI_CFG_GPIO_XTAL 0x40 /* PCI config space GPIO 14 for Xtal power-up */ #define PCI_CFG_GPIO_PLL 0x80 /* PCI config space GPIO 15 for PLL power-down */ /* power control defines */ #define PLL_DELAY 150 /* us pll on delay */ #define FREF_DELAY 200 /* us fref change delay */ +#define MIN_SLOW_CLK 32 /* us Slow clock period */ #define XTAL_ON_DELAY 1000 /* us crystal power-on delay */ +/* # of GPIO pins */ +#define GPIO_NUMPINS 16 + /* Reference board types */ #define SPI_BOARD 0x0402 diff --git a/trunk/drivers/staging/brcm80211/include/bcmsrom_fmt.h b/trunk/drivers/staging/brcm80211/include/bcmsrom_fmt.h index 4666afd883a5..4768968f910a 100644 --- a/trunk/drivers/staging/brcm80211/include/bcmsrom_fmt.h +++ b/trunk/drivers/staging/brcm80211/include/bcmsrom_fmt.h @@ -105,7 +105,7 @@ /* SROM Rev 4: Reallocate the software part of the srom to accommodate * MIMO features. It assumes up to two PCIE functions and 440 bytes - * of usable srom i.e. the usable storage in chips with OTP that + * of useable srom i.e. the useable storage in chips with OTP that * implements hardware redundancy. */ diff --git a/trunk/drivers/staging/brcm80211/include/bcmutils.h b/trunk/drivers/staging/brcm80211/include/bcmutils.h index 462bd89b9992..fc2a2a910129 100644 --- a/trunk/drivers/staging/brcm80211/include/bcmutils.h +++ b/trunk/drivers/staging/brcm80211/include/bcmutils.h @@ -251,12 +251,16 @@ extern struct sk_buff *pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out); * update osl files with os specific errorcode map */ +#define BCME_OK 0 /* Success */ #define BCME_ERROR -1 /* Error generic */ #define BCME_BADARG -2 /* Bad Argument */ +#define BCME_BADOPTION -3 /* Bad option */ #define BCME_NOTUP -4 /* Not up */ #define BCME_NOTDOWN -5 /* Not down */ +#define BCME_NOTAP -6 /* Not AP */ +#define BCME_NOTSTA -7 /* Not STA */ #define BCME_BADKEYIDX -8 /* BAD Key Index */ -#define BCME_RADIOOFF -9 /* Radio Off */ +#define BCME_RADIOOFF -9 /* Radio Off */ #define BCME_NOTBANDLOCKED -10 /* Not band locked */ #define BCME_NOCLK -11 /* No Clock */ #define BCME_BADRATESET -12 /* BAD Rate valueset */ @@ -264,19 +268,31 @@ extern struct sk_buff *pktq_mdeq(struct pktq *pq, uint prec_bmp, int *prec_out); #define BCME_BUFTOOSHORT -14 /* Buffer too short */ #define BCME_BUFTOOLONG -15 /* Buffer too long */ #define BCME_BUSY -16 /* Busy */ +#define BCME_NOTASSOCIATED -17 /* Not Associated */ +#define BCME_BADSSIDLEN -18 /* Bad SSID len */ #define BCME_OUTOFRANGECHAN -19 /* Out of Range Channel */ #define BCME_BADCHAN -20 /* Bad Channel */ #define BCME_BADADDR -21 /* Bad Address */ #define BCME_NORESOURCE -22 /* Not Enough Resources */ #define BCME_UNSUPPORTED -23 /* Unsupported */ +#define BCME_BADLEN -24 /* Bad length */ #define BCME_NOTREADY -25 /* Not Ready */ #define BCME_EPERM -26 /* Not Permitted */ #define BCME_NOMEM -27 /* No Memory */ #define BCME_ASSOCIATED -28 /* Associated */ #define BCME_RANGE -29 /* Not In Range */ #define BCME_NOTFOUND -30 /* Not Found */ +#define BCME_WME_NOT_ENABLED -31 /* WME Not Enabled */ +#define BCME_TSPEC_NOTFOUND -32 /* TSPEC Not Found */ +#define BCME_ACM_NOTSUPPORTED -33 /* ACM Not Supported */ +#define BCME_NOT_WME_ASSOCIATION -34 /* Not WME Association */ #define BCME_SDIO_ERROR -35 /* SDIO Bus Error */ #define BCME_DONGLE_DOWN -36 /* Dongle Not Accessible */ +#define BCME_VERSION -37 /* Incorrect version */ +#define BCME_TXFAIL -38 /* TX failure */ +#define BCME_RXFAIL -39 /* RX failure */ +#define BCME_NODEVICE -40 /* Device not present */ +#define BCME_NMODE_DISABLED -41 /* NMODE disabled */ #define BCME_NONRESIDENT -42 /* access to nonresident overlay */ #define BCME_LAST BCME_NONRESIDENT diff --git a/trunk/drivers/staging/brcm80211/include/hndpmu.h b/trunk/drivers/staging/brcm80211/include/hndpmu.h index b2b2095c4ced..3eea1f9fbc39 100644 --- a/trunk/drivers/staging/brcm80211/include/hndpmu.h +++ b/trunk/drivers/staging/brcm80211/include/hndpmu.h @@ -56,6 +56,7 @@ extern u32 si_pmu_measure_alpclk(si_t *sih); extern u32 si_pmu_chipcontrol(si_t *sih, uint reg, u32 mask, u32 val); extern u32 si_pmu_regcontrol(si_t *sih, uint reg, u32 mask, u32 val); extern u32 si_pmu_pllcontrol(si_t *sih, uint reg, u32 mask, u32 val); +extern void si_pmu_pllupd(si_t *sih); extern void si_pmu_sprom_enable(si_t *sih, bool enable); extern void si_pmu_radio_enable(si_t *sih, bool enable); diff --git a/trunk/drivers/staging/brcm80211/include/pcicfg.h b/trunk/drivers/staging/brcm80211/include/pcicfg.h index d0c617a63c4f..675554a1d341 100644 --- a/trunk/drivers/staging/brcm80211/include/pcicfg.h +++ b/trunk/drivers/staging/brcm80211/include/pcicfg.h @@ -17,34 +17,508 @@ #ifndef _h_pcicfg_ #define _h_pcicfg_ -#include +/* The following inside ifndef's so we don't collide with NTDDK.H */ +#ifndef PCI_MAX_BUS +#define PCI_MAX_BUS 0x100 +#endif +#ifndef PCI_MAX_DEVICES +#define PCI_MAX_DEVICES 0x20 +#endif +#ifndef PCI_MAX_FUNCTION +#define PCI_MAX_FUNCTION 0x8 +#endif -/* PCI configuration address space size */ -#define PCI_SZPCR 256 +#ifndef PCI_INVALID_VENDORID +#define PCI_INVALID_VENDORID 0xffff +#endif +#ifndef PCI_INVALID_DEVICEID +#define PCI_INVALID_DEVICEID 0xffff +#endif + +/* Convert between bus-slot-function-register and config addresses */ + +#define PCICFG_BUS_SHIFT 16 /* Bus shift */ +#define PCICFG_SLOT_SHIFT 11 /* Slot shift */ +#define PCICFG_FUN_SHIFT 8 /* Function shift */ +#define PCICFG_OFF_SHIFT 0 /* Register shift */ + +#define PCICFG_BUS_MASK 0xff /* Bus mask */ +#define PCICFG_SLOT_MASK 0x1f /* Slot mask */ +#define PCICFG_FUN_MASK 7 /* Function mask */ +#define PCICFG_OFF_MASK 0xff /* Bus mask */ + +#define PCI_CONFIG_ADDR(b, s, f, o) \ + ((((b) & PCICFG_BUS_MASK) << PCICFG_BUS_SHIFT) \ + | (((s) & PCICFG_SLOT_MASK) << PCICFG_SLOT_SHIFT) \ + | (((f) & PCICFG_FUN_MASK) << PCICFG_FUN_SHIFT) \ + | (((o) & PCICFG_OFF_MASK) << PCICFG_OFF_SHIFT)) + +#define PCI_CONFIG_BUS(a) (((a) >> PCICFG_BUS_SHIFT) & PCICFG_BUS_MASK) +#define PCI_CONFIG_SLOT(a) (((a) >> PCICFG_SLOT_SHIFT) & PCICFG_SLOT_MASK) +#define PCI_CONFIG_FUN(a) (((a) >> PCICFG_FUN_SHIFT) & PCICFG_FUN_MASK) +#define PCI_CONFIG_OFF(a) (((a) >> PCICFG_OFF_SHIFT) & PCICFG_OFF_MASK) + +/* PCIE Config space accessing MACROS */ + +#define PCIECFG_BUS_SHIFT 24 /* Bus shift */ +#define PCIECFG_SLOT_SHIFT 19 /* Slot/Device shift */ +#define PCIECFG_FUN_SHIFT 16 /* Function shift */ +#define PCIECFG_OFF_SHIFT 0 /* Register shift */ + +#define PCIECFG_BUS_MASK 0xff /* Bus mask */ +#define PCIECFG_SLOT_MASK 0x1f /* Slot/Device mask */ +#define PCIECFG_FUN_MASK 7 /* Function mask */ +#define PCIECFG_OFF_MASK 0xfff /* Register mask */ + +#define PCIE_CONFIG_ADDR(b, s, f, o) \ + ((((b) & PCIECFG_BUS_MASK) << PCIECFG_BUS_SHIFT) \ + | (((s) & PCIECFG_SLOT_MASK) << PCIECFG_SLOT_SHIFT) \ + | (((f) & PCIECFG_FUN_MASK) << PCIECFG_FUN_SHIFT) \ + | (((o) & PCIECFG_OFF_MASK) << PCIECFG_OFF_SHIFT)) + +#define PCIE_CONFIG_BUS(a) (((a) >> PCIECFG_BUS_SHIFT) & PCIECFG_BUS_MASK) +#define PCIE_CONFIG_SLOT(a) (((a) >> PCIECFG_SLOT_SHIFT) & PCIECFG_SLOT_MASK) +#define PCIE_CONFIG_FUN(a) (((a) >> PCIECFG_FUN_SHIFT) & PCIECFG_FUN_MASK) +#define PCIE_CONFIG_OFF(a) (((a) >> PCIECFG_OFF_SHIFT) & PCIECFG_OFF_MASK) + +/* The actual config space */ + +#define PCI_BAR_MAX 6 + +#define PCI_ROM_BAR 8 + +#define PCR_RSVDA_MAX 2 + +/* Bits in PCI bars' flags */ + +#define PCIBAR_FLAGS 0xf +#define PCIBAR_IO 0x1 +#define PCIBAR_MEM1M 0x2 +#define PCIBAR_MEM64 0x4 +#define PCIBAR_PREFETCH 0x8 +#define PCIBAR_MEM32_MASK 0xFFFFFF80 + +/* pci config status reg has a bit to indicate that capability ptr is present */ + +#define PCI_CAPPTR_PRESENT 0x0010 + +typedef struct _pci_config_regs { + u16 vendor; + u16 device; + u16 command; + u16 status; + u8 rev_id; + u8 prog_if; + u8 sub_class; + u8 base_class; + u8 cache_line_size; + u8 latency_timer; + u8 header_type; + u8 bist; + u32 base[PCI_BAR_MAX]; + u32 cardbus_cis; + u16 subsys_vendor; + u16 subsys_id; + u32 baserom; + u32 rsvd_a[PCR_RSVDA_MAX]; + u8 int_line; + u8 int_pin; + u8 min_gnt; + u8 max_lat; + u8 dev_dep[192]; +} pci_config_regs; + +#define SZPCR (sizeof (pci_config_regs)) +#define MINSZPCR 64 /* offsetof (dev_dep[0] */ + +/* A structure for the config registers is nice, but in most + * systems the config space is not memory mapped, so we need + * field offsetts. :-( + */ +#define PCI_CFG_VID 0 +#define PCI_CFG_DID 2 +#define PCI_CFG_CMD 4 +#define PCI_CFG_STAT 6 +#define PCI_CFG_REV 8 +#define PCI_CFG_PROGIF 9 +#define PCI_CFG_SUBCL 0xa +#define PCI_CFG_BASECL 0xb +#define PCI_CFG_CLSZ 0xc +#define PCI_CFG_LATTIM 0xd +#define PCI_CFG_HDR 0xe +#define PCI_CFG_BIST 0xf +#define PCI_CFG_BAR0 0x10 +#define PCI_CFG_BAR1 0x14 +#define PCI_CFG_BAR2 0x18 +#define PCI_CFG_BAR3 0x1c +#define PCI_CFG_BAR4 0x20 +#define PCI_CFG_BAR5 0x24 +#define PCI_CFG_CIS 0x28 +#define PCI_CFG_SVID 0x2c +#define PCI_CFG_SSID 0x2e +#define PCI_CFG_ROMBAR 0x30 +#define PCI_CFG_CAPPTR 0x34 +#define PCI_CFG_INT 0x3c +#define PCI_CFG_PIN 0x3d +#define PCI_CFG_MINGNT 0x3e +#define PCI_CFG_MAXLAT 0x3f + +/* Classes and subclasses */ + +typedef enum { + PCI_CLASS_OLD = 0, + PCI_CLASS_DASDI, + PCI_CLASS_NET, + PCI_CLASS_DISPLAY, + PCI_CLASS_MMEDIA, + PCI_CLASS_MEMORY, + PCI_CLASS_BRIDGE, + PCI_CLASS_COMM, + PCI_CLASS_BASE, + PCI_CLASS_INPUT, + PCI_CLASS_DOCK, + PCI_CLASS_CPU, + PCI_CLASS_SERIAL, + PCI_CLASS_INTELLIGENT = 0xe, + PCI_CLASS_SATELLITE, + PCI_CLASS_CRYPT, + PCI_CLASS_DSP, + PCI_CLASS_XOR = 0xfe +} pci_classes; + +typedef enum { + PCI_DASDI_SCSI, + PCI_DASDI_IDE, + PCI_DASDI_FLOPPY, + PCI_DASDI_IPI, + PCI_DASDI_RAID, + PCI_DASDI_OTHER = 0x80 +} pci_dasdi_subclasses; + +typedef enum { + PCI_NET_ETHER, + PCI_NET_TOKEN, + PCI_NET_FDDI, + PCI_NET_ATM, + PCI_NET_OTHER = 0x80 +} pci_net_subclasses; + +typedef enum { + PCI_DISPLAY_VGA, + PCI_DISPLAY_XGA, + PCI_DISPLAY_3D, + PCI_DISPLAY_OTHER = 0x80 +} pci_display_subclasses; + +typedef enum { + PCI_MMEDIA_VIDEO, + PCI_MMEDIA_AUDIO, + PCI_MMEDIA_PHONE, + PCI_MEDIA_OTHER = 0x80 +} pci_mmedia_subclasses; + +typedef enum { + PCI_MEMORY_RAM, + PCI_MEMORY_FLASH, + PCI_MEMORY_OTHER = 0x80 +} pci_memory_subclasses; + +typedef enum { + PCI_BRIDGE_HOST, + PCI_BRIDGE_ISA, + PCI_BRIDGE_EISA, + PCI_BRIDGE_MC, + PCI_BRIDGE_PCI, + PCI_BRIDGE_PCMCIA, + PCI_BRIDGE_NUBUS, + PCI_BRIDGE_CARDBUS, + PCI_BRIDGE_RACEWAY, + PCI_BRIDGE_OTHER = 0x80 +} pci_bridge_subclasses; + +typedef enum { + PCI_COMM_UART, + PCI_COMM_PARALLEL, + PCI_COMM_MULTIUART, + PCI_COMM_MODEM, + PCI_COMM_OTHER = 0x80 +} pci_comm_subclasses; + +typedef enum { + PCI_BASE_PIC, + PCI_BASE_DMA, + PCI_BASE_TIMER, + PCI_BASE_RTC, + PCI_BASE_PCI_HOTPLUG, + PCI_BASE_OTHER = 0x80 +} pci_base_subclasses; + +typedef enum { + PCI_INPUT_KBD, + PCI_INPUT_PEN, + PCI_INPUT_MOUSE, + PCI_INPUT_SCANNER, + PCI_INPUT_GAMEPORT, + PCI_INPUT_OTHER = 0x80 +} pci_input_subclasses; + +typedef enum { + PCI_DOCK_GENERIC, + PCI_DOCK_OTHER = 0x80 +} pci_dock_subclasses; + +typedef enum { + PCI_CPU_386, + PCI_CPU_486, + PCI_CPU_PENTIUM, + PCI_CPU_ALPHA = 0x10, + PCI_CPU_POWERPC = 0x20, + PCI_CPU_MIPS = 0x30, + PCI_CPU_COPROC = 0x40, + PCI_CPU_OTHER = 0x80 +} pci_cpu_subclasses; + +typedef enum { + PCI_SERIAL_IEEE1394, + PCI_SERIAL_ACCESS, + PCI_SERIAL_SSA, + PCI_SERIAL_USB, + PCI_SERIAL_FIBER, + PCI_SERIAL_SMBUS, + PCI_SERIAL_OTHER = 0x80 +} pci_serial_subclasses; + +typedef enum { + PCI_INTELLIGENT_I2O +} pci_intelligent_subclasses; + +typedef enum { + PCI_SATELLITE_TV, + PCI_SATELLITE_AUDIO, + PCI_SATELLITE_VOICE, + PCI_SATELLITE_DATA, + PCI_SATELLITE_OTHER = 0x80 +} pci_satellite_subclasses; + +typedef enum { + PCI_CRYPT_NETWORK, + PCI_CRYPT_ENTERTAINMENT, + PCI_CRYPT_OTHER = 0x80 +} pci_crypt_subclasses; + +typedef enum { + PCI_DSP_DPIO, + PCI_DSP_OTHER = 0x80 +} pci_dsp_subclasses; + +typedef enum { + PCI_XOR_QDMA, + PCI_XOR_OTHER = 0x80 +} pci_xor_subclasses; + +/* Header types */ +#define PCI_HEADER_MULTI 0x80 +#define PCI_HEADER_MASK 0x7f +typedef enum { + PCI_HEADER_NORMAL, + PCI_HEADER_BRIDGE, + PCI_HEADER_CARDBUS +} pci_header_types; + +/* Overlay for a PCI-to-PCI bridge */ + +#define PPB_RSVDA_MAX 2 +#define PPB_RSVDD_MAX 8 + +typedef struct _ppb_config_regs { + u16 vendor; + u16 device; + u16 command; + u16 status; + u8 rev_id; + u8 prog_if; + u8 sub_class; + u8 base_class; + u8 cache_line_size; + u8 latency_timer; + u8 header_type; + u8 bist; + u32 rsvd_a[PPB_RSVDA_MAX]; + u8 prim_bus; + u8 sec_bus; + u8 sub_bus; + u8 sec_lat; + u8 io_base; + u8 io_lim; + u16 sec_status; + u16 mem_base; + u16 mem_lim; + u16 pf_mem_base; + u16 pf_mem_lim; + u32 pf_mem_base_hi; + u32 pf_mem_lim_hi; + u16 io_base_hi; + u16 io_lim_hi; + u16 subsys_vendor; + u16 subsys_id; + u32 rsvd_b; + u8 rsvd_c; + u8 int_pin; + u16 bridge_ctrl; + u8 chip_ctrl; + u8 diag_ctrl; + u16 arb_ctrl; + u32 rsvd_d[PPB_RSVDD_MAX]; + u8 dev_dep[192]; +} ppb_config_regs; + +/* PCI CAPABILITY DEFINES */ +#define PCI_CAP_POWERMGMTCAP_ID 0x01 +#define PCI_CAP_MSICAP_ID 0x05 +#define PCI_CAP_VENDSPEC_ID 0x09 +#define PCI_CAP_PCIECAP_ID 0x10 + +/* Data structure to define the Message Signalled Interrupt facility + * Valid for PCI and PCIE configurations + */ +typedef struct _pciconfig_cap_msi { + u8 capID; + u8 nextptr; + u16 msgctrl; + u32 msgaddr; +} pciconfig_cap_msi; + +/* Data structure to define the Power management facility + * Valid for PCI and PCIE configurations + */ +typedef struct _pciconfig_cap_pwrmgmt { + u8 capID; + u8 nextptr; + u16 pme_cap; + u16 pme_sts_ctrl; + u8 pme_bridge_ext; + u8 data; +} pciconfig_cap_pwrmgmt; + +#define PME_CAP_PM_STATES (0x1f << 27) /* Bits 31:27 states that can generate PME */ +#define PME_CSR_OFFSET 0x4 /* 4-bytes offset */ +#define PME_CSR_PME_EN (1 << 8) /* Bit 8 Enable generating of PME */ +#define PME_CSR_PME_STAT (1 << 15) /* Bit 15 PME got asserted */ + +/* Data structure to define the PCIE capability */ +typedef struct _pciconfig_cap_pcie { + u8 capID; + u8 nextptr; + u16 pcie_cap; + u32 dev_cap; + u16 dev_ctrl; + u16 dev_status; + u32 link_cap; + u16 link_ctrl; + u16 link_status; + u32 slot_cap; + u16 slot_ctrl; + u16 slot_status; + u16 root_ctrl; + u16 root_cap; + u32 root_status; +} pciconfig_cap_pcie; + +/* PCIE Enhanced CAPABILITY DEFINES */ +#define PCIE_EXTCFG_OFFSET 0x100 +#define PCIE_ADVERRREP_CAPID 0x0001 +#define PCIE_VC_CAPID 0x0002 +#define PCIE_DEVSNUM_CAPID 0x0003 +#define PCIE_PWRBUDGET_CAPID 0x0004 + +/* PCIE Extended configuration */ +#define PCIE_ADV_CORR_ERR_MASK 0x114 +#define CORR_ERR_RE (1 << 0) /* Receiver */ +#define CORR_ERR_BT (1 << 6) /* Bad TLP */ +#define CORR_ERR_BD (1 << 7) /* Bad DLLP */ +#define CORR_ERR_RR (1 << 8) /* REPLAY_NUM rollover */ +#define CORR_ERR_RT (1 << 12) /* Reply timer timeout */ +#define ALL_CORR_ERRORS (CORR_ERR_RE | CORR_ERR_BT | CORR_ERR_BD | \ + CORR_ERR_RR | CORR_ERR_RT) + +/* PCIE Root Control Register bits (Host mode only) */ +#define PCIE_RC_CORR_SERR_EN 0x0001 +#define PCIE_RC_NONFATAL_SERR_EN 0x0002 +#define PCIE_RC_FATAL_SERR_EN 0x0004 +#define PCIE_RC_PME_INT_EN 0x0008 +#define PCIE_RC_CRS_EN 0x0010 + +/* PCIE Root Capability Register bits (Host mode only) */ +#define PCIE_RC_CRS_VISIBILITY 0x0001 + +/* Header to define the PCIE specific capabilities in the extended config space */ +typedef struct _pcie_enhanced_caphdr { + u16 capID; + u16 cap_ver:4; + u16 next_ptr:12; +} pcie_enhanced_caphdr; /* Everything below is BRCM HND proprietary */ /* Brcm PCI configuration registers */ -#define PCI_BAR0_WIN 0x80 /* backplane address space accessed by BAR0 */ -#define PCI_SPROM_CONTROL 0x88 /* sprom property control */ -#define PCI_INT_MASK 0x94 /* mask of PCI and other cores interrupts */ -#define PCI_SBIM_SHIFT 8 /* backplane core interrupt mask bits offset */ -#define PCI_BAR0_WIN2 0xac /* backplane address space accessed by second 4KB of BAR0 */ -#define PCI_GPIO_IN 0xb0 /* pci config space gpio input (>=rev3) */ -#define PCI_GPIO_OUT 0xb4 /* pci config space gpio output (>=rev3) */ -#define PCI_GPIO_OUTEN 0xb8 /* pci config space gpio output enable (>=rev3) */ - -#define PCI_BAR0_SPROM_OFFSET (4 * 1024) /* bar0 + 4K accesses external sprom */ -#define PCI_BAR0_PCIREGS_OFFSET (6 * 1024) /* bar0 + 6K accesses pci core registers */ -#define PCI_BAR0_PCISBR_OFFSET (4 * 1024) /* pci core SB registers are at the end of the +#define cap_list rsvd_a[0] +#define bar0_window dev_dep[0x80 - 0x40] +#define bar1_window dev_dep[0x84 - 0x40] +#define sprom_control dev_dep[0x88 - 0x40] +#define PCI_BAR0_WIN 0x80 /* backplane address space accessed by BAR0 */ +#define PCI_BAR1_WIN 0x84 /* backplane address space accessed by BAR1 */ +#define PCI_SPROM_CONTROL 0x88 /* sprom property control */ +#define PCI_BAR1_CONTROL 0x8c /* BAR1 region burst control */ +#define PCI_INT_STATUS 0x90 /* PCI and other cores interrupts */ +#define PCI_INT_MASK 0x94 /* mask of PCI and other cores interrupts */ +#define PCI_TO_SB_MB 0x98 /* signal backplane interrupts */ +#define PCI_BACKPLANE_ADDR 0xa0 /* address an arbitrary location on the system backplane */ +#define PCI_BACKPLANE_DATA 0xa4 /* data at the location specified by above address */ +#define PCI_CLK_CTL_ST 0xa8 /* pci config space clock control/status (>=rev14) */ +#define PCI_BAR0_WIN2 0xac /* backplane address space accessed by second 4KB of BAR0 */ +#define PCI_GPIO_IN 0xb0 /* pci config space gpio input (>=rev3) */ +#define PCI_GPIO_OUT 0xb4 /* pci config space gpio output (>=rev3) */ +#define PCI_GPIO_OUTEN 0xb8 /* pci config space gpio output enable (>=rev3) */ + +#define PCI_BAR0_SHADOW_OFFSET (2 * 1024) /* bar0 + 2K accesses sprom shadow (in pci core) */ +#define PCI_BAR0_SPROM_OFFSET (4 * 1024) /* bar0 + 4K accesses external sprom */ +#define PCI_BAR0_PCIREGS_OFFSET (6 * 1024) /* bar0 + 6K accesses pci core registers */ +#define PCI_BAR0_PCISBR_OFFSET (4 * 1024) /* pci core SB registers are at the end of the * 8KB window, so their address is the "regular" * address plus 4K */ #define PCI_BAR0_WINSZ (16 * 1024) /* bar0 window size Match with corerev 13 */ /* On pci corerev >= 13 and all pcie, the bar0 is now 16KB and it maps: */ -#define PCI_16KB0_PCIREGS_OFFSET (8 * 1024) /* bar0 + 8K accesses pci/pcie core registers */ -#define PCI_16KB0_CCREGS_OFFSET (12 * 1024) /* bar0 + 12K accesses chipc core registers */ +#define PCI_16KB0_PCIREGS_OFFSET (8 * 1024) /* bar0 + 8K accesses pci/pcie core registers */ +#define PCI_16KB0_CCREGS_OFFSET (12 * 1024) /* bar0 + 12K accesses chipc core registers */ +#define PCI_16KBB0_WINSZ (16 * 1024) /* bar0 window size */ + +/* On AI chips we have a second window to map DMP regs are mapped: */ +#define PCI_16KB0_WIN2_OFFSET (4 * 1024) /* bar0 + 4K is "Window 2" */ + +/* PCI_INT_STATUS */ +#define PCI_SBIM_STATUS_SERR 0x4 /* backplane SBErr interrupt status */ + +/* PCI_INT_MASK */ +#define PCI_SBIM_SHIFT 8 /* backplane core interrupt mask bits offset */ +#define PCI_SBIM_MASK 0xff00 /* backplane core interrupt mask */ +#define PCI_SBIM_MASK_SERR 0x4 /* backplane SBErr interrupt mask */ -#define PCI_SBIM_STATUS_SERR 0x4 /* backplane SBErr interrupt status */ +/* PCI_SPROM_CONTROL */ +#define SPROM_SZ_MSK 0x02 /* SPROM Size Mask */ +#define SPROM_LOCKED 0x08 /* SPROM Locked */ +#define SPROM_BLANK 0x04 /* indicating a blank SPROM */ +#define SPROM_WRITEEN 0x10 /* SPROM write enable */ +#define SPROM_BOOTROM_WE 0x20 /* external bootrom write enable */ +#define SPROM_BACKPLANE_EN 0x40 /* Enable indirect backplane access */ +#define SPROM_OTPIN_USE 0x80 /* device OTP In use */ +/* Bits in PCI command and status regs */ +#define PCI_CMD_IO 0x00000001 /* I/O enable */ +#define PCI_CMD_MEMORY 0x00000002 /* Memory enable */ +#define PCI_CMD_MASTER 0x00000004 /* Master enable */ +#define PCI_CMD_SPECIAL 0x00000008 /* Special cycles enable */ +#define PCI_CMD_INVALIDATE 0x00000010 /* Invalidate? */ +#define PCI_CMD_VGA_PAL 0x00000040 /* VGA Palate */ +#define PCI_STAT_TA 0x08000000 /* target abort status */ #endif /* _h_pcicfg_ */ diff --git a/trunk/drivers/staging/brcm80211/util/bcmsrom.c b/trunk/drivers/staging/brcm80211/util/bcmsrom.c index 2f8d7f7dd62d..850bfa6593e0 100644 --- a/trunk/drivers/staging/brcm80211/util/bcmsrom.c +++ b/trunk/drivers/staging/brcm80211/util/bcmsrom.c @@ -28,10 +28,24 @@ #include #include #include +#ifdef BCMSDIO +#include +#include +#endif #include #include +#if defined(BCMSDIO) +#include +#include +#include +#endif + +#include + +#define BS_ERROR(args) + #define SROM_OFFSET(sih) ((sih->ccrev > 31) ? \ (((sih->cccaps & CC_CAP_SROM) == 0) ? NULL : \ ((u8 *)curmap + PCI_16KB0_CCREGS_OFFSET + CC_SROM_OTP)) : \ @@ -50,10 +64,17 @@ typedef struct varbuf { extern char *_vars; extern uint _varsz; +#define SROM_CIS_SINGLE 1 + static int initvars_srom_si(si_t *sih, void *curmap, char **vars, uint *count); static void _initvars_srom_pci(u8 sromrev, u16 *srom, uint off, varbuf_t *b); static int initvars_srom_pci(si_t *sih, void *curmap, char **vars, uint *count); static int initvars_flash_si(si_t *sih, char **vars, uint *count); +#ifdef BCMSDIO +static int initvars_cis_sdio(char **vars, uint *count); +static int sprom_cmd_sdio(u8 cmd); +static int sprom_read_sdio(u16 addr, u16 *data); +#endif /* BCMSDIO */ static int sprom_read_pci(si_t *sih, u16 *sprom, uint wordoff, u16 *buf, uint nwords, bool check_crc); #if defined(BCMNVRAMR) @@ -158,12 +179,1227 @@ int srom_var_init(si_t *sih, uint bustype, void *curmap, return initvars_srom_pci(sih, curmap, vars, count); +#ifdef BCMSDIO + case SDIO_BUS: + return initvars_cis_sdio(vars, count); +#endif /* BCMSDIO */ + default: ASSERT(0); } return -1; } +/* support only 16-bit word read from srom */ +int +srom_read(si_t *sih, uint bustype, void *curmap, + uint byteoff, uint nbytes, u16 *buf, bool check_crc) +{ + uint off, nw; +#ifdef BCMSDIO + uint i; +#endif /* BCMSDIO */ + + ASSERT(bustype == bustype); + + /* check input - 16-bit access only */ + if (byteoff & 1 || nbytes & 1 || (byteoff + nbytes) > SROM_MAX) + return 1; + + off = byteoff / 2; + nw = nbytes / 2; + + if (bustype == PCI_BUS) { + if (!curmap) + return 1; + + if (si_is_sprom_available(sih)) { + u16 *srom; + + srom = (u16 *) SROM_OFFSET(sih); + if (srom == NULL) + return 1; + + if (sprom_read_pci + (sih, srom, off, buf, nw, check_crc)) + return 1; + } +#if defined(BCMNVRAMR) + else { + if (otp_read_pci(sih, buf, SROM_MAX)) + return 1; + } +#endif +#ifdef BCMSDIO + } else if (bustype == SDIO_BUS) { + off = byteoff / 2; + nw = nbytes / 2; + for (i = 0; i < nw; i++) { + if (sprom_read_sdio + ((u16) (off + i), (u16 *) (buf + i))) + return 1; + } +#endif /* BCMSDIO */ + } else if (bustype == SI_BUS) { + return 1; + } else { + return 1; + } + + return 0; +} + +static const char vstr_manf[] = "manf=%s"; +static const char vstr_productname[] = "productname=%s"; +static const char vstr_manfid[] = "manfid=0x%x"; +static const char vstr_prodid[] = "prodid=0x%x"; +#ifdef BCMSDIO +static const char vstr_sdmaxspeed[] = "sdmaxspeed=%d"; +static const char vstr_sdmaxblk[][13] = { +"sdmaxblk0=%d", "sdmaxblk1=%d", "sdmaxblk2=%d"}; +#endif +static const char vstr_regwindowsz[] = "regwindowsz=%d"; +static const char vstr_sromrev[] = "sromrev=%d"; +static const char vstr_chiprev[] = "chiprev=%d"; +static const char vstr_subvendid[] = "subvendid=0x%x"; +static const char vstr_subdevid[] = "subdevid=0x%x"; +static const char vstr_boardrev[] = "boardrev=0x%x"; +static const char vstr_aa2g[] = "aa2g=0x%x"; +static const char vstr_aa5g[] = "aa5g=0x%x"; +static const char vstr_ag[] = "ag%d=0x%x"; +static const char vstr_cc[] = "cc=%d"; +static const char vstr_opo[] = "opo=%d"; +static const char vstr_pa0b[][9] = { +"pa0b0=%d", "pa0b1=%d", "pa0b2=%d"}; + +static const char vstr_pa0itssit[] = "pa0itssit=%d"; +static const char vstr_pa0maxpwr[] = "pa0maxpwr=%d"; +static const char vstr_pa1b[][9] = { +"pa1b0=%d", "pa1b1=%d", "pa1b2=%d"}; + +static const char vstr_pa1lob[][11] = { +"pa1lob0=%d", "pa1lob1=%d", "pa1lob2=%d"}; + +static const char vstr_pa1hib[][11] = { +"pa1hib0=%d", "pa1hib1=%d", "pa1hib2=%d"}; + +static const char vstr_pa1itssit[] = "pa1itssit=%d"; +static const char vstr_pa1maxpwr[] = "pa1maxpwr=%d"; +static const char vstr_pa1lomaxpwr[] = "pa1lomaxpwr=%d"; +static const char vstr_pa1himaxpwr[] = "pa1himaxpwr=%d"; +static const char vstr_oem[] = + "oem=%02x%02x%02x%02x%02x%02x%02x%02x"; +static const char vstr_boardflags[] = "boardflags=0x%x"; +static const char vstr_boardflags2[] = "boardflags2=0x%x"; +static const char vstr_ledbh[] = "ledbh%d=0x%x"; +static const char vstr_noccode[] = "ccode=0x0"; +static const char vstr_ccode[] = "ccode=%c%c"; +static const char vstr_cctl[] = "cctl=0x%x"; +static const char vstr_cckpo[] = "cckpo=0x%x"; +static const char vstr_ofdmpo[] = "ofdmpo=0x%x"; +static const char vstr_rdlid[] = "rdlid=0x%x"; +static const char vstr_rdlrndis[] = "rdlrndis=%d"; +static const char vstr_rdlrwu[] = "rdlrwu=%d"; +static const char vstr_usbfs[] = "usbfs=%d"; +static const char vstr_wpsgpio[] = "wpsgpio=%d"; +static const char vstr_wpsled[] = "wpsled=%d"; +static const char vstr_rdlsn[] = "rdlsn=%d"; +static const char vstr_rssismf2g[] = "rssismf2g=%d"; +static const char vstr_rssismc2g[] = "rssismc2g=%d"; +static const char vstr_rssisav2g[] = "rssisav2g=%d"; +static const char vstr_bxa2g[] = "bxa2g=%d"; +static const char vstr_rssismf5g[] = "rssismf5g=%d"; +static const char vstr_rssismc5g[] = "rssismc5g=%d"; +static const char vstr_rssisav5g[] = "rssisav5g=%d"; +static const char vstr_bxa5g[] = "bxa5g=%d"; +static const char vstr_tri2g[] = "tri2g=%d"; +static const char vstr_tri5gl[] = "tri5gl=%d"; +static const char vstr_tri5g[] = "tri5g=%d"; +static const char vstr_tri5gh[] = "tri5gh=%d"; +static const char vstr_rxpo2g[] = "rxpo2g=%d"; +static const char vstr_rxpo5g[] = "rxpo5g=%d"; +static const char vstr_boardtype[] = "boardtype=0x%x"; +static const char vstr_leddc[] = "leddc=0x%04x"; +static const char vstr_vendid[] = "vendid=0x%x"; +static const char vstr_devid[] = "devid=0x%x"; +static const char vstr_xtalfreq[] = "xtalfreq=%d"; +static const char vstr_txchain[] = "txchain=0x%x"; +static const char vstr_rxchain[] = "rxchain=0x%x"; +static const char vstr_antswitch[] = "antswitch=0x%x"; +static const char vstr_regrev[] = "regrev=0x%x"; +static const char vstr_antswctl2g[] = "antswctl2g=0x%x"; +static const char vstr_triso2g[] = "triso2g=0x%x"; +static const char vstr_pdetrange2g[] = "pdetrange2g=0x%x"; +static const char vstr_extpagain2g[] = "extpagain2g=0x%x"; +static const char vstr_tssipos2g[] = "tssipos2g=0x%x"; +static const char vstr_antswctl5g[] = "antswctl5g=0x%x"; +static const char vstr_triso5g[] = "triso5g=0x%x"; +static const char vstr_pdetrange5g[] = "pdetrange5g=0x%x"; +static const char vstr_extpagain5g[] = "extpagain5g=0x%x"; +static const char vstr_tssipos5g[] = "tssipos5g=0x%x"; +static const char vstr_maxp2ga0[] = "maxp2ga0=0x%x"; +static const char vstr_itt2ga0[] = "itt2ga0=0x%x"; +static const char vstr_pa[] = "pa%dgw%da%d=0x%x"; +static const char vstr_pahl[] = "pa%dg%cw%da%d=0x%x"; +static const char vstr_maxp5ga0[] = "maxp5ga0=0x%x"; +static const char vstr_itt5ga0[] = "itt5ga0=0x%x"; +static const char vstr_maxp5gha0[] = "maxp5gha0=0x%x"; +static const char vstr_maxp5gla0[] = "maxp5gla0=0x%x"; +static const char vstr_maxp2ga1[] = "maxp2ga1=0x%x"; +static const char vstr_itt2ga1[] = "itt2ga1=0x%x"; +static const char vstr_maxp5ga1[] = "maxp5ga1=0x%x"; +static const char vstr_itt5ga1[] = "itt5ga1=0x%x"; +static const char vstr_maxp5gha1[] = "maxp5gha1=0x%x"; +static const char vstr_maxp5gla1[] = "maxp5gla1=0x%x"; +static const char vstr_cck2gpo[] = "cck2gpo=0x%x"; +static const char vstr_ofdm2gpo[] = "ofdm2gpo=0x%x"; +static const char vstr_ofdm5gpo[] = "ofdm5gpo=0x%x"; +static const char vstr_ofdm5glpo[] = "ofdm5glpo=0x%x"; +static const char vstr_ofdm5ghpo[] = "ofdm5ghpo=0x%x"; +static const char vstr_cddpo[] = "cddpo=0x%x"; +static const char vstr_stbcpo[] = "stbcpo=0x%x"; +static const char vstr_bw40po[] = "bw40po=0x%x"; +static const char vstr_bwduppo[] = "bwduppo=0x%x"; +static const char vstr_mcspo[] = "mcs%dgpo%d=0x%x"; +static const char vstr_mcspohl[] = "mcs%dg%cpo%d=0x%x"; +static const char vstr_custom[] = "customvar%d=0x%x"; +static const char vstr_cckdigfilttype[] = "cckdigfilttype=%d"; +static const char vstr_boardnum[] = "boardnum=%d"; +static const char vstr_macaddr[] = "macaddr=%s"; +static const char vstr_usbepnum[] = "usbepnum=0x%x"; +static const char vstr_end[] = "END\0"; + +u8 patch_pair; + +/* For dongle HW, accept partial calibration parameters */ +#define BCMDONGLECASE(n) + +int srom_parsecis(u8 *pcis[], uint ciscnt, char **vars, + uint *count) +{ + char eabuf[32]; + char *base; + varbuf_t b; + u8 *cis, tup, tlen, sromrev = 1; + int i, j; + bool ag_init = false; + u32 w32; + uint funcid; + uint cisnum; + s32 boardnum; + int err; + bool standard_cis; + + ASSERT(vars != NULL); + ASSERT(count != NULL); + + boardnum = -1; + + base = kmalloc(MAXSZ_NVRAM_VARS, GFP_ATOMIC); + ASSERT(base != NULL); + if (!base) + return -2; + + varbuf_init(&b, base, MAXSZ_NVRAM_VARS); + memset(base, 0, MAXSZ_NVRAM_VARS); + eabuf[0] = '\0'; + for (cisnum = 0; cisnum < ciscnt; cisnum++) { + cis = *pcis++; + i = 0; + funcid = 0; + standard_cis = true; + do { + if (standard_cis) { + tup = cis[i++]; + if (tup == CISTPL_NULL || tup == CISTPL_END) + tlen = 0; + else + tlen = cis[i++]; + } else { + if (cis[i] == CISTPL_NULL + || cis[i] == CISTPL_END) { + tlen = 0; + tup = cis[i]; + } else { + tlen = cis[i]; + tup = CISTPL_BRCM_HNBU; + } + ++i; + } + if ((i + tlen) >= CIS_SIZE) + break; + + switch (tup) { + case CISTPL_VERS_1: + /* assume the strings are good if the version field checks out */ + if (((cis[i + 1] << 8) + cis[i]) >= 0x0008) { + varbuf_append(&b, vstr_manf, + &cis[i + 2]); + varbuf_append(&b, vstr_productname, + &cis[i + 3 + + strlen((char *) + &cis[i + + 2])]); + break; + } + + case CISTPL_MANFID: + varbuf_append(&b, vstr_manfid, + (cis[i + 1] << 8) + cis[i]); + varbuf_append(&b, vstr_prodid, + (cis[i + 3] << 8) + cis[i + 2]); + break; + + case CISTPL_FUNCID: + funcid = cis[i]; + break; + + case CISTPL_FUNCE: + switch (funcid) { + case CISTPL_FID_SDIO: +#ifdef BCMSDIO + if (cis[i] == 0) { + u8 spd = cis[i + 3]; + static int base[] = { + -1, 10, 12, 13, 15, 20, + 25, 30, + 35, 40, 45, 50, 55, 60, + 70, 80 + }; + static int mult[] = { + 10, 100, 1000, 10000, + -1, -1, -1, -1 + }; + ASSERT((mult[spd & 0x7] != -1) + && + (base + [(spd >> 3) & 0x0f])); + varbuf_append(&b, + vstr_sdmaxblk[0], + (cis[i + 2] << 8) + + cis[i + 1]); + varbuf_append(&b, + vstr_sdmaxspeed, + (mult[spd & 0x7] * + base[(spd >> 3) & + 0x0f])); + } else if (cis[i] == 1) { + varbuf_append(&b, + vstr_sdmaxblk + [cisnum], + (cis[i + 13] << 8) + | cis[i + 12]); + } +#endif /* BCMSDIO */ + funcid = 0; + break; + default: + /* set macaddr if HNBU_MACADDR not seen yet */ + if (eabuf[0] == '\0' && + cis[i] == LAN_NID && + !is_zero_ether_addr(&cis[i + 2]) && + !is_multicast_ether_addr(&cis[i + 2])) { + ASSERT(cis[i + 1] == + ETH_ALEN); + snprintf(eabuf, sizeof(eabuf), + "%pM", &cis[i + 2]); + + /* set boardnum if HNBU_BOARDNUM not seen yet */ + if (boardnum == -1) + boardnum = + (cis[i + 6] << 8) + + cis[i + 7]; + } + break; + } + break; + + case CISTPL_CFTABLE: + varbuf_append(&b, vstr_regwindowsz, + (cis[i + 7] << 8) | cis[i + 6]); + break; + + case CISTPL_BRCM_HNBU: + switch (cis[i]) { + case HNBU_SROMREV: + sromrev = cis[i + 1]; + varbuf_append(&b, vstr_sromrev, + sromrev); + break; + + case HNBU_XTALFREQ: + varbuf_append(&b, vstr_xtalfreq, + (cis[i + 4] << 24) | + (cis[i + 3] << 16) | + (cis[i + 2] << 8) | + cis[i + 1]); + break; + + case HNBU_CHIPID: + varbuf_append(&b, vstr_vendid, + (cis[i + 2] << 8) + + cis[i + 1]); + varbuf_append(&b, vstr_devid, + (cis[i + 4] << 8) + + cis[i + 3]); + if (tlen >= 7) { + varbuf_append(&b, vstr_chiprev, + (cis[i + 6] << 8) + + cis[i + 5]); + } + if (tlen >= 9) { + varbuf_append(&b, + vstr_subvendid, + (cis[i + 8] << 8) + + cis[i + 7]); + } + if (tlen >= 11) { + varbuf_append(&b, vstr_subdevid, + (cis[i + 10] << 8) + + cis[i + 9]); + /* subdevid doubles for boardtype */ + varbuf_append(&b, + vstr_boardtype, + (cis[i + 10] << 8) + + cis[i + 9]); + } + break; + + case HNBU_BOARDNUM: + boardnum = + (cis[i + 2] << 8) + cis[i + 1]; + break; + + case HNBU_PATCH: + { + char vstr_paddr[16]; + char vstr_pdata[16]; + + /* retrieve the patch pairs + * from tlen/6; where 6 is + * sizeof(patch addr(2)) + + * sizeof(patch data(4)). + */ + patch_pair = tlen / 6; + + for (j = 0; j < patch_pair; j++) { + snprintf(vstr_paddr, + sizeof + (vstr_paddr), + "pa%d=0x%%x", + j); + snprintf(vstr_pdata, + sizeof + (vstr_pdata), + "pd%d=0x%%x", + j); + + varbuf_append(&b, + vstr_paddr, + (cis + [i + + (j * + 6) + + 2] << 8) + | cis[i + + (j * + 6) + + + 1]); + + varbuf_append(&b, + vstr_pdata, + (cis + [i + + (j * + 6) + + 6] << + 24) | + (cis + [i + + (j * + 6) + + 5] << + 16) | + (cis + [i + + (j * + 6) + + 4] << 8) + | cis[i + + (j * + 6) + + + 3]); + } + } + break; + + case HNBU_BOARDREV: + if (tlen == 2) + varbuf_append(&b, vstr_boardrev, + cis[i + 1]); + else + varbuf_append(&b, vstr_boardrev, + (cis[i + 2] << 8) + + cis[i + 1]); + break; + + case HNBU_BOARDFLAGS: + w32 = (cis[i + 2] << 8) + cis[i + 1]; + if (tlen >= 5) + w32 |= + ((cis[i + 4] << 24) + + (cis[i + 3] << 16)); + varbuf_append(&b, vstr_boardflags, w32); + + if (tlen >= 7) { + w32 = + (cis[i + 6] << 8) + cis[i + + 5]; + if (tlen >= 9) + w32 |= + ((cis[i + 8] << 24) + + + (cis[i + 7] << + 16)); + varbuf_append(&b, + vstr_boardflags2, + w32); + } + break; + + case HNBU_USBFS: + varbuf_append(&b, vstr_usbfs, + cis[i + 1]); + break; + + case HNBU_BOARDTYPE: + varbuf_append(&b, vstr_boardtype, + (cis[i + 2] << 8) + + cis[i + 1]); + break; + + case HNBU_HNBUCIS: + /* + * what follows is a nonstandard HNBU CIS + * that lacks CISTPL_BRCM_HNBU tags + * + * skip 0xff (end of standard CIS) + * after this tuple + */ + tlen++; + standard_cis = false; + break; + + case HNBU_USBEPNUM: + varbuf_append(&b, vstr_usbepnum, + (cis[i + 2] << 8) | cis[i + + + 1]); + break; + + case HNBU_AA: + varbuf_append(&b, vstr_aa2g, + cis[i + 1]); + if (tlen >= 3) + varbuf_append(&b, vstr_aa5g, + cis[i + 2]); + break; + + case HNBU_AG: + varbuf_append(&b, vstr_ag, 0, + cis[i + 1]); + if (tlen >= 3) + varbuf_append(&b, vstr_ag, 1, + cis[i + 2]); + if (tlen >= 4) + varbuf_append(&b, vstr_ag, 2, + cis[i + 3]); + if (tlen >= 5) + varbuf_append(&b, vstr_ag, 3, + cis[i + 4]); + ag_init = true; + break; + + case HNBU_ANT5G: + varbuf_append(&b, vstr_aa5g, + cis[i + 1]); + varbuf_append(&b, vstr_ag, 1, + cis[i + 2]); + break; + + case HNBU_CC: + ASSERT(sromrev == 1); + varbuf_append(&b, vstr_cc, cis[i + 1]); + break; + + case HNBU_PAPARMS: + switch (tlen) { + case 2: + ASSERT(sromrev == 1); + varbuf_append(&b, + vstr_pa0maxpwr, + cis[i + 1]); + break; + case 10: + ASSERT(sromrev >= 2); + varbuf_append(&b, vstr_opo, + cis[i + 9]); + /* FALLTHROUGH */ + case 9: + varbuf_append(&b, + vstr_pa0maxpwr, + cis[i + 8]); + /* FALLTHROUGH */ + BCMDONGLECASE(8) + varbuf_append(&b, + vstr_pa0itssit, + cis[i + 7]); + /* FALLTHROUGH */ + BCMDONGLECASE(7) + for (j = 0; j < 3; j++) { + varbuf_append(&b, + vstr_pa0b + [j], + (cis + [i + + (j * + 2) + + 2] << 8) + + cis[i + + (j * + 2) + + + 1]); + } + break; + default: + ASSERT((tlen == 2) + || (tlen == 9) + || (tlen == 10)); + break; + } + break; + + case HNBU_PAPARMS5G: + ASSERT((sromrev == 2) + || (sromrev == 3)); + switch (tlen) { + case 23: + varbuf_append(&b, + vstr_pa1himaxpwr, + cis[i + 22]); + varbuf_append(&b, + vstr_pa1lomaxpwr, + cis[i + 21]); + varbuf_append(&b, + vstr_pa1maxpwr, + cis[i + 20]); + /* FALLTHROUGH */ + case 20: + varbuf_append(&b, + vstr_pa1itssit, + cis[i + 19]); + /* FALLTHROUGH */ + case 19: + for (j = 0; j < 3; j++) { + varbuf_append(&b, + vstr_pa1b + [j], + (cis + [i + + (j * + 2) + + 2] << 8) + + cis[i + + (j * + 2) + + + 1]); + } + for (j = 3; j < 6; j++) { + varbuf_append(&b, + vstr_pa1lob + [j - 3], + (cis + [i + + (j * + 2) + + 2] << 8) + + cis[i + + (j * + 2) + + + 1]); + } + for (j = 6; j < 9; j++) { + varbuf_append(&b, + vstr_pa1hib + [j - 6], + (cis + [i + + (j * + 2) + + 2] << 8) + + cis[i + + (j * + 2) + + + 1]); + } + break; + default: + ASSERT((tlen == 19) || + (tlen == 20) + || (tlen == 23)); + break; + } + break; + + case HNBU_OEM: + ASSERT(sromrev == 1); + varbuf_append(&b, vstr_oem, + cis[i + 1], cis[i + 2], + cis[i + 3], cis[i + 4], + cis[i + 5], cis[i + 6], + cis[i + 7], cis[i + 8]); + break; + + case HNBU_LEDS: + for (j = 1; j <= 4; j++) { + if (cis[i + j] != 0xff) { + varbuf_append(&b, + vstr_ledbh, + j - 1, + cis[i + + j]); + } + } + break; + + case HNBU_CCODE: + ASSERT(sromrev > 1); + if ((cis[i + 1] == 0) + || (cis[i + 2] == 0)) + varbuf_append(&b, vstr_noccode); + else + varbuf_append(&b, vstr_ccode, + cis[i + 1], + cis[i + 2]); + varbuf_append(&b, vstr_cctl, + cis[i + 3]); + break; + + case HNBU_CCKPO: + ASSERT(sromrev > 2); + varbuf_append(&b, vstr_cckpo, + (cis[i + 2] << 8) | cis[i + + + 1]); + break; + + case HNBU_OFDMPO: + ASSERT(sromrev > 2); + varbuf_append(&b, vstr_ofdmpo, + (cis[i + 4] << 24) | + (cis[i + 3] << 16) | + (cis[i + 2] << 8) | + cis[i + 1]); + break; + + case HNBU_WPS: + varbuf_append(&b, vstr_wpsgpio, + cis[i + 1]); + if (tlen >= 3) + varbuf_append(&b, vstr_wpsled, + cis[i + 2]); + break; + + case HNBU_RSSISMBXA2G: + ASSERT(sromrev == 3); + varbuf_append(&b, vstr_rssismf2g, + cis[i + 1] & 0xf); + varbuf_append(&b, vstr_rssismc2g, + (cis[i + 1] >> 4) & 0xf); + varbuf_append(&b, vstr_rssisav2g, + cis[i + 2] & 0x7); + varbuf_append(&b, vstr_bxa2g, + (cis[i + 2] >> 3) & 0x3); + break; + + case HNBU_RSSISMBXA5G: + ASSERT(sromrev == 3); + varbuf_append(&b, vstr_rssismf5g, + cis[i + 1] & 0xf); + varbuf_append(&b, vstr_rssismc5g, + (cis[i + 1] >> 4) & 0xf); + varbuf_append(&b, vstr_rssisav5g, + cis[i + 2] & 0x7); + varbuf_append(&b, vstr_bxa5g, + (cis[i + 2] >> 3) & 0x3); + break; + + case HNBU_TRI2G: + ASSERT(sromrev == 3); + varbuf_append(&b, vstr_tri2g, + cis[i + 1]); + break; + + case HNBU_TRI5G: + ASSERT(sromrev == 3); + varbuf_append(&b, vstr_tri5gl, + cis[i + 1]); + varbuf_append(&b, vstr_tri5g, + cis[i + 2]); + varbuf_append(&b, vstr_tri5gh, + cis[i + 3]); + break; + + case HNBU_RXPO2G: + ASSERT(sromrev == 3); + varbuf_append(&b, vstr_rxpo2g, + cis[i + 1]); + break; + + case HNBU_RXPO5G: + ASSERT(sromrev == 3); + varbuf_append(&b, vstr_rxpo5g, + cis[i + 1]); + break; + + case HNBU_MACADDR: + if (!is_zero_ether_addr(&cis[i + 1]) && + !is_multicast_ether_addr(&cis[i + 1])) { + snprintf(eabuf, sizeof(eabuf), + "%pM", &cis[i + 1]); + + /* set boardnum if HNBU_BOARDNUM not seen yet */ + if (boardnum == -1) + boardnum = + (cis[i + 5] << 8) + + cis[i + 6]; + } + break; + + case HNBU_LEDDC: + /* CIS leddc only has 16bits, convert it to 32bits */ + w32 = ((cis[i + 2] << 24) | /* oncount */ + (cis[i + 1] << 8)); /* offcount */ + varbuf_append(&b, vstr_leddc, w32); + break; + + case HNBU_CHAINSWITCH: + varbuf_append(&b, vstr_txchain, + cis[i + 1]); + varbuf_append(&b, vstr_rxchain, + cis[i + 2]); + varbuf_append(&b, vstr_antswitch, + (cis[i + 4] << 8) + + cis[i + 3]); + break; + + case HNBU_REGREV: + varbuf_append(&b, vstr_regrev, + cis[i + 1]); + break; + + case HNBU_FEM:{ + u16 fem = + (cis[i + 2] << 8) + cis[i + + 1]; + varbuf_append(&b, + vstr_antswctl2g, + (fem & + SROM8_FEM_ANTSWLUT_MASK) + >> + SROM8_FEM_ANTSWLUT_SHIFT); + varbuf_append(&b, vstr_triso2g, + (fem & + SROM8_FEM_TR_ISO_MASK) + >> + SROM8_FEM_TR_ISO_SHIFT); + varbuf_append(&b, + vstr_pdetrange2g, + (fem & + SROM8_FEM_PDET_RANGE_MASK) + >> + SROM8_FEM_PDET_RANGE_SHIFT); + varbuf_append(&b, + vstr_extpagain2g, + (fem & + SROM8_FEM_EXTPA_GAIN_MASK) + >> + SROM8_FEM_EXTPA_GAIN_SHIFT); + varbuf_append(&b, + vstr_tssipos2g, + (fem & + SROM8_FEM_TSSIPOS_MASK) + >> + SROM8_FEM_TSSIPOS_SHIFT); + if (tlen < 5) + break; + + fem = + (cis[i + 4] << 8) + cis[i + + 3]; + varbuf_append(&b, + vstr_antswctl5g, + (fem & + SROM8_FEM_ANTSWLUT_MASK) + >> + SROM8_FEM_ANTSWLUT_SHIFT); + varbuf_append(&b, vstr_triso5g, + (fem & + SROM8_FEM_TR_ISO_MASK) + >> + SROM8_FEM_TR_ISO_SHIFT); + varbuf_append(&b, + vstr_pdetrange5g, + (fem & + SROM8_FEM_PDET_RANGE_MASK) + >> + SROM8_FEM_PDET_RANGE_SHIFT); + varbuf_append(&b, + vstr_extpagain5g, + (fem & + SROM8_FEM_EXTPA_GAIN_MASK) + >> + SROM8_FEM_EXTPA_GAIN_SHIFT); + varbuf_append(&b, + vstr_tssipos5g, + (fem & + SROM8_FEM_TSSIPOS_MASK) + >> + SROM8_FEM_TSSIPOS_SHIFT); + break; + } + + case HNBU_PAPARMS_C0: + varbuf_append(&b, vstr_maxp2ga0, + cis[i + 1]); + varbuf_append(&b, vstr_itt2ga0, + cis[i + 2]); + varbuf_append(&b, vstr_pa, 2, 0, 0, + (cis[i + 4] << 8) + + cis[i + 3]); + varbuf_append(&b, vstr_pa, 2, 1, 0, + (cis[i + 6] << 8) + + cis[i + 5]); + varbuf_append(&b, vstr_pa, 2, 2, 0, + (cis[i + 8] << 8) + + cis[i + 7]); + if (tlen < 31) + break; + + varbuf_append(&b, vstr_maxp5ga0, + cis[i + 9]); + varbuf_append(&b, vstr_itt5ga0, + cis[i + 10]); + varbuf_append(&b, vstr_maxp5gha0, + cis[i + 11]); + varbuf_append(&b, vstr_maxp5gla0, + cis[i + 12]); + varbuf_append(&b, vstr_pa, 5, 0, 0, + (cis[i + 14] << 8) + + cis[i + 13]); + varbuf_append(&b, vstr_pa, 5, 1, 0, + (cis[i + 16] << 8) + + cis[i + 15]); + varbuf_append(&b, vstr_pa, 5, 2, 0, + (cis[i + 18] << 8) + + cis[i + 17]); + varbuf_append(&b, vstr_pahl, 5, 'l', 0, + 0, + (cis[i + 20] << 8) + + cis[i + 19]); + varbuf_append(&b, vstr_pahl, 5, 'l', 1, + 0, + (cis[i + 22] << 8) + + cis[i + 21]); + varbuf_append(&b, vstr_pahl, 5, 'l', 2, + 0, + (cis[i + 24] << 8) + + cis[i + 23]); + varbuf_append(&b, vstr_pahl, 5, 'h', 0, + 0, + (cis[i + 26] << 8) + + cis[i + 25]); + varbuf_append(&b, vstr_pahl, 5, 'h', 1, + 0, + (cis[i + 28] << 8) + + cis[i + 27]); + varbuf_append(&b, vstr_pahl, 5, 'h', 2, + 0, + (cis[i + 30] << 8) + + cis[i + 29]); + break; + + case HNBU_PAPARMS_C1: + varbuf_append(&b, vstr_maxp2ga1, + cis[i + 1]); + varbuf_append(&b, vstr_itt2ga1, + cis[i + 2]); + varbuf_append(&b, vstr_pa, 2, 0, 1, + (cis[i + 4] << 8) + + cis[i + 3]); + varbuf_append(&b, vstr_pa, 2, 1, 1, + (cis[i + 6] << 8) + + cis[i + 5]); + varbuf_append(&b, vstr_pa, 2, 2, 1, + (cis[i + 8] << 8) + + cis[i + 7]); + if (tlen < 31) + break; + + varbuf_append(&b, vstr_maxp5ga1, + cis[i + 9]); + varbuf_append(&b, vstr_itt5ga1, + cis[i + 10]); + varbuf_append(&b, vstr_maxp5gha1, + cis[i + 11]); + varbuf_append(&b, vstr_maxp5gla1, + cis[i + 12]); + varbuf_append(&b, vstr_pa, 5, 0, 1, + (cis[i + 14] << 8) + + cis[i + 13]); + varbuf_append(&b, vstr_pa, 5, 1, 1, + (cis[i + 16] << 8) + + cis[i + 15]); + varbuf_append(&b, vstr_pa, 5, 2, 1, + (cis[i + 18] << 8) + + cis[i + 17]); + varbuf_append(&b, vstr_pahl, 5, 'l', 0, + 1, + (cis[i + 20] << 8) + + cis[i + 19]); + varbuf_append(&b, vstr_pahl, 5, 'l', 1, + 1, + (cis[i + 22] << 8) + + cis[i + 21]); + varbuf_append(&b, vstr_pahl, 5, 'l', 2, + 1, + (cis[i + 24] << 8) + + cis[i + 23]); + varbuf_append(&b, vstr_pahl, 5, 'h', 0, + 1, + (cis[i + 26] << 8) + + cis[i + 25]); + varbuf_append(&b, vstr_pahl, 5, 'h', 1, + 1, + (cis[i + 28] << 8) + + cis[i + 27]); + varbuf_append(&b, vstr_pahl, 5, 'h', 2, + 1, + (cis[i + 30] << 8) + + cis[i + 29]); + break; + + case HNBU_PO_CCKOFDM: + varbuf_append(&b, vstr_cck2gpo, + (cis[i + 2] << 8) + + cis[i + 1]); + varbuf_append(&b, vstr_ofdm2gpo, + (cis[i + 6] << 24) + + (cis[i + 5] << 16) + + (cis[i + 4] << 8) + + cis[i + 3]); + if (tlen < 19) + break; + + varbuf_append(&b, vstr_ofdm5gpo, + (cis[i + 10] << 24) + + (cis[i + 9] << 16) + + (cis[i + 8] << 8) + + cis[i + 7]); + varbuf_append(&b, vstr_ofdm5glpo, + (cis[i + 14] << 24) + + (cis[i + 13] << 16) + + (cis[i + 12] << 8) + + cis[i + 11]); + varbuf_append(&b, vstr_ofdm5ghpo, + (cis[i + 18] << 24) + + (cis[i + 17] << 16) + + (cis[i + 16] << 8) + + cis[i + 15]); + break; + + case HNBU_PO_MCS2G: + for (j = 0; j <= (tlen / 2); j++) { + varbuf_append(&b, vstr_mcspo, 2, + j, + (cis + [i + 2 + + 2 * j] << 8) + + cis[i + 1 + + 2 * j]); + } + break; + + case HNBU_PO_MCS5GM: + for (j = 0; j <= (tlen / 2); j++) { + varbuf_append(&b, vstr_mcspo, 5, + j, + (cis + [i + 2 + + 2 * j] << 8) + + cis[i + 1 + + 2 * j]); + } + break; + + case HNBU_PO_MCS5GLH: + for (j = 0; j <= (tlen / 4); j++) { + varbuf_append(&b, vstr_mcspohl, + 5, 'l', j, + (cis + [i + 2 + + 2 * j] << 8) + + cis[i + 1 + + 2 * j]); + } + + for (j = 0; j <= (tlen / 4); j++) { + varbuf_append(&b, vstr_mcspohl, + 5, 'h', j, + (cis + [i + + ((tlen / 2) + + 2) + + 2 * j] << 8) + + cis[i + + ((tlen / 2) + + 1) + 2 * j]); + } + + break; + + case HNBU_PO_CDD: + varbuf_append(&b, vstr_cddpo, + (cis[i + 2] << 8) + + cis[i + 1]); + break; + + case HNBU_PO_STBC: + varbuf_append(&b, vstr_stbcpo, + (cis[i + 2] << 8) + + cis[i + 1]); + break; + + case HNBU_PO_40M: + varbuf_append(&b, vstr_bw40po, + (cis[i + 2] << 8) + + cis[i + 1]); + break; + + case HNBU_PO_40MDUP: + varbuf_append(&b, vstr_bwduppo, + (cis[i + 2] << 8) + + cis[i + 1]); + break; + + case HNBU_OFDMPO5G: + varbuf_append(&b, vstr_ofdm5gpo, + (cis[i + 4] << 24) + + (cis[i + 3] << 16) + + (cis[i + 2] << 8) + + cis[i + 1]); + varbuf_append(&b, vstr_ofdm5glpo, + (cis[i + 8] << 24) + + (cis[i + 7] << 16) + + (cis[i + 6] << 8) + + cis[i + 5]); + varbuf_append(&b, vstr_ofdm5ghpo, + (cis[i + 12] << 24) + + (cis[i + 11] << 16) + + (cis[i + 10] << 8) + + cis[i + 9]); + break; + + case HNBU_CUSTOM1: + varbuf_append(&b, vstr_custom, 1, + ((cis[i + 4] << 24) + + (cis[i + 3] << 16) + + (cis[i + 2] << 8) + + cis[i + 1])); + break; + +#if defined(BCMSDIO) + case HNBU_SROM3SWRGN: + if (tlen >= 73) { + u16 srom[35]; + u8 srev = cis[i + 1 + 70]; + ASSERT(srev == 3); + /* make tuple value 16-bit aligned and parse it */ + memcpy(srom, &cis[i + 1], + sizeof(srom)); + _initvars_srom_pci(srev, srom, + SROM3_SWRGN_OFF, + &b); + /* 2.4G antenna gain is included in SROM */ + ag_init = true; + /* Ethernet MAC address is included in SROM */ + eabuf[0] = 0; + boardnum = -1; + } + /* create extra variables */ + if (tlen >= 75) + varbuf_append(&b, vstr_vendid, + (cis[i + 1 + 73] + << 8) + cis[i + + 1 + + 72]); + if (tlen >= 77) + varbuf_append(&b, vstr_devid, + (cis[i + 1 + 75] + << 8) + cis[i + + 1 + + 74]); + if (tlen >= 79) + varbuf_append(&b, vstr_xtalfreq, + (cis[i + 1 + 77] + << 8) + cis[i + + 1 + + 76]); + break; +#endif /* defined(BCMSDIO) */ + + case HNBU_CCKFILTTYPE: + varbuf_append(&b, vstr_cckdigfilttype, + (cis[i + 1])); + break; + } + + break; + } + i += tlen; + } while (tup != CISTPL_END); + } + + if (boardnum != -1) { + varbuf_append(&b, vstr_boardnum, boardnum); + } + + if (eabuf[0]) { + varbuf_append(&b, vstr_macaddr, eabuf); + } + + /* if there is no antenna gain field, set default */ + if (getvar(NULL, "ag0") == NULL && ag_init == false) { + varbuf_append(&b, vstr_ag, 0, 0xff); + } + + /* final nullbyte terminator */ + ASSERT(b.size >= 1); + *b.buf++ = '\0'; + + ASSERT(b.buf - base <= MAXSZ_NVRAM_VARS); + err = initvars_table(base, b.buf, vars, count); + + kfree(base); + return err; +} + /* In chips with chipcommon rev 32 and later, the srom is in chipcommon, * not in the bus cores. */ @@ -188,6 +1424,7 @@ srom_cc_cmd(si_t *sih, void *ccregs, u32 cmd, } if (!wait_cnt) { + BS_ERROR(("%s: Command 0x%x timed out\n", __func__, cmd)); return 0xffff; } if (cmd == SRC_OP_READ) @@ -253,6 +1490,8 @@ sprom_read_pci(si_t *sih, u16 *sprom, uint wordoff, * is blank, regardless of the rest of the content, so declare * it bad. */ + BS_ERROR(("%s: buf[0] = 0x%x, returning bad-crc\n", + __func__, buf[0])); return 1; } @@ -261,6 +1500,7 @@ sprom_read_pci(si_t *sih, u16 *sprom, uint wordoff, if (hndcrc8((u8 *) buf, nwords * 2, CRC8_INIT_VALUE) != CRC8_GOOD_VALUE) { /* DBG only pci always read srom4 first, then srom8/9 */ + /* BS_ERROR(("%s: bad crc\n", __func__)); */ err = 1; } /* now correct the endianness of the byte array */ @@ -295,6 +1535,8 @@ static int otp_read_pci(si_t *sih, u16 *buf, uint bufsz) * is blank, regardless of the rest of the content, so declare * it bad. */ + BS_ERROR(("%s: buf[0] = 0x%x, returning bad-crc\n", __func__, + buf[0])); return 1; } @@ -302,6 +1544,7 @@ static int otp_read_pci(si_t *sih, u16 *buf, uint bufsz) htol16_buf(buf, bufsz); if (hndcrc8((u8 *) buf, SROM4_WORDS * 2, CRC8_INIT_VALUE) != CRC8_GOOD_VALUE) { + BS_ERROR(("%s: bad crc\n", __func__)); err = 1; } /* now correct the endianness of the byte array */ @@ -641,6 +1884,10 @@ static int initvars_srom_pci(si_t *sih, void *curmap, char **vars, uint *count) sprom_read_pci(sih, sromwindow, 0, srom, SROM4_WORDS, true); sromrev = srom[SROM4_CRCREV] & 0xff; + if (err) + BS_ERROR(("%s: srom %d, bad crc\n", __func__, + sromrev)); + } else if (err == 0) { /* srom is good and is rev < 4 */ /* top word of sprom contains version and crc8 */ @@ -674,6 +1921,7 @@ static int initvars_srom_pci(si_t *sih, void *curmap, char **vars, uint *count) u32 val; val = 0; + BS_ERROR(("Neither SPROM nor OTP has valid image\n")); value = si_getdevpathvar(sih, "sromrev"); if (value) { sromrev = (u8) simple_strtoul(value, NULL, 0); @@ -681,6 +1929,8 @@ static int initvars_srom_pci(si_t *sih, void *curmap, char **vars, uint *count) goto varscont; } + BS_ERROR(("%s, SROM CRC Error\n", __func__)); + value = si_getnvramflvar(sih, "sromrev"); if (value) { err = 0; @@ -744,6 +1994,92 @@ static int initvars_srom_pci(si_t *sih, void *curmap, char **vars, uint *count) return err; } +#ifdef BCMSDIO +/* + * Read the SDIO cis and call parsecis to initialize the vars. + * Return 0 on success, nonzero on error. + */ +static int initvars_cis_sdio(char **vars, uint *count) +{ + u8 *cis[SBSDIO_NUM_FUNCTION + 1]; + uint fn, numfn; + int rc = 0; + + numfn = bcmsdh_query_iofnum(NULL); + ASSERT(numfn <= SDIOD_MAX_IOFUNCS); + + for (fn = 0; fn <= numfn; fn++) { + cis[fn] = kzalloc(SBSDIO_CIS_SIZE_LIMIT, GFP_ATOMIC); + if (cis[fn] == NULL) { + rc = -1; + break; + } + + if (bcmsdh_cis_read(NULL, fn, cis[fn], SBSDIO_CIS_SIZE_LIMIT) != + 0) { + kfree(cis[fn]); + rc = -2; + break; + } + } + + if (!rc) + rc = srom_parsecis(cis, fn, vars, count); + + while (fn-- > 0) + kfree(cis[fn]); + + return rc; +} + +/* set SDIO sprom command register */ +static int sprom_cmd_sdio(u8 cmd) +{ + u8 status = 0; + uint wait_cnt = 1000; + + /* write sprom command register */ + bcmsdh_cfg_write(NULL, SDIO_FUNC_1, SBSDIO_SPROM_CS, cmd, NULL); + + /* wait status */ + while (wait_cnt--) { + status = + bcmsdh_cfg_read(NULL, SDIO_FUNC_1, SBSDIO_SPROM_CS, NULL); + if (status & SBSDIO_SPROM_DONE) + return 0; + } + + return 1; +} + +/* read a word from the SDIO srom */ +static int sprom_read_sdio(u16 addr, u16 *data) +{ + u8 addr_l, addr_h, data_l, data_h; + + addr_l = (u8) ((addr * 2) & 0xff); + addr_h = (u8) (((addr * 2) >> 8) & 0xff); + + /* set address */ + bcmsdh_cfg_write(NULL, SDIO_FUNC_1, SBSDIO_SPROM_ADDR_HIGH, addr_h, + NULL); + bcmsdh_cfg_write(NULL, SDIO_FUNC_1, SBSDIO_SPROM_ADDR_LOW, addr_l, + NULL); + + /* do read */ + if (sprom_cmd_sdio(SBSDIO_SPROM_READ)) + return 1; + + /* read data */ + data_h = + bcmsdh_cfg_read(NULL, SDIO_FUNC_1, SBSDIO_SPROM_DATA_HIGH, NULL); + data_l = + bcmsdh_cfg_read(NULL, SDIO_FUNC_1, SBSDIO_SPROM_DATA_LOW, NULL); + + *data = (data_h << 8) | data_l; + return 0; +} +#endif /* BCMSDIO */ static int initvars_srom_si(si_t *sih, void *curmap, char **vars, uint *varsz) { diff --git a/trunk/drivers/staging/brcm80211/util/hnddma.c b/trunk/drivers/staging/brcm80211/util/hnddma.c index 0684fb1fadc0..be339feae77d 100644 --- a/trunk/drivers/staging/brcm80211/util/hnddma.c +++ b/trunk/drivers/staging/brcm80211/util/hnddma.c @@ -1451,6 +1451,9 @@ static int BCMFASTPATH dma64_txfast(dma_info_t *di, struct sk_buff *p0, data = p->data; len = p->len; +#ifdef BCM_DMAPAD + len += PKTDMAPAD(di->osh, p); +#endif /* BCM_DMAPAD */ next = p->next; /* return nonzero if out of tx descriptors */ diff --git a/trunk/drivers/staging/brcm80211/util/hndpmu.c b/trunk/drivers/staging/brcm80211/util/hndpmu.c index 8426a279e857..59e3ede89fe7 100644 --- a/trunk/drivers/staging/brcm80211/util/hndpmu.c +++ b/trunk/drivers/staging/brcm80211/util/hndpmu.c @@ -34,6 +34,7 @@ /* debug-only definitions */ /* #define BCMDBG_FORCEHT */ +/* #define CHIPC_UART_ALWAYS_ON */ #else #define PMU_MSG(args) #endif /* BCMDBG */ @@ -1448,6 +1449,10 @@ static u32 si_pmu1_cpuclk0(si_t *sih, chipcregs_t *cc) { u32 tmp, m1div; +#ifdef BCMDBG + u32 ndiv_int, ndiv_frac, p2div, p1div, fvco; + u32 fref; +#endif u32 FVCO = si_pmu1_pllfvco0(sih); /* Read m1div from pllcontrol[1] */ @@ -1455,6 +1460,41 @@ si_pmu1_cpuclk0(si_t *sih, chipcregs_t *cc) tmp = R_REG(&cc->pllcontrol_data); m1div = (tmp & PMU1_PLL0_PC1_M1DIV_MASK) >> PMU1_PLL0_PC1_M1DIV_SHIFT; +#ifdef BCMDBG + /* Read p2div/p1div from pllcontrol[0] */ + W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL0); + tmp = R_REG(&cc->pllcontrol_data); + p2div = (tmp & PMU1_PLL0_PC0_P2DIV_MASK) >> PMU1_PLL0_PC0_P2DIV_SHIFT; + p1div = (tmp & PMU1_PLL0_PC0_P1DIV_MASK) >> PMU1_PLL0_PC0_P1DIV_SHIFT; + + /* Calculate fvco based on xtal freq and ndiv and pdiv */ + W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL2); + tmp = R_REG(&cc->pllcontrol_data); + ndiv_int = + (tmp & PMU1_PLL0_PC2_NDIV_INT_MASK) >> PMU1_PLL0_PC2_NDIV_INT_SHIFT; + + W_REG(&cc->pllcontrol_addr, PMU1_PLL0_PLLCTL3); + tmp = R_REG(&cc->pllcontrol_data); + ndiv_frac = + (tmp & PMU1_PLL0_PC3_NDIV_FRAC_MASK) >> + PMU1_PLL0_PC3_NDIV_FRAC_SHIFT; + + fref = si_pmu1_alpclk0(sih, cc) / 1000; + + fvco = (fref * ndiv_int) << 8; + fvco += (fref * (ndiv_frac >> 12)) >> 4; + fvco += (fref * (ndiv_frac & 0xfff)) >> 12; + fvco >>= 8; + fvco *= p2div; + fvco /= p1div; + fvco /= 1000; + fvco *= 1000; + + PMU_MSG(("si_pmu1_cpuclk0: ndiv_int %u ndiv_frac %u p2div %u p1div %u fvco %u\n", ndiv_int, ndiv_frac, p2div, p1div, fvco)); + + FVCO = fvco; +#endif /* BCMDBG */ + /* Return ARM/SB clock */ return FVCO / m1div * 1000; } @@ -1504,6 +1544,10 @@ void si_pmu_pll_init(si_t *sih, uint xtalfreq) break; } +#ifdef BCMDBG_FORCEHT + OR_REG(&cc->clk_ctl_st, CCS_FORCEHT); +#endif + /* Return to original core */ si_setcoreidx(sih, origidx); } @@ -2467,6 +2511,11 @@ void si_pmu_chip_init(si_t *sih) ASSERT(sih->cccaps & CC_CAP_PMU); +#ifdef CHIPC_UART_ALWAYS_ON + si_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, clk_ctl_st), + CCS_FORCEALP, CCS_FORCEALP); +#endif /* CHIPC_UART_ALWAYS_ON */ + /* Gate off SPROM clock and chip select signals */ si_pmu_sprom_enable(sih, false); diff --git a/trunk/drivers/staging/brcm80211/util/nicpci.c b/trunk/drivers/staging/brcm80211/util/nicpci.c index 6eabbed5cd27..a1fb2f08984d 100644 --- a/trunk/drivers/staging/brcm80211/util/nicpci.c +++ b/trunk/drivers/staging/brcm80211/util/nicpci.c @@ -98,8 +98,9 @@ void *pcicore_init(si_t *sih, void *pdev, void *regs) if (sih->buscoretype == PCIE_CORE_ID) { u8 cap_ptr; pi->regs.pcieregs = (sbpcieregs_t *) regs; - cap_ptr = pcicore_find_pci_capability(pi->dev, PCI_CAP_ID_EXP, - NULL, NULL); + cap_ptr = + pcicore_find_pci_capability(pi->dev, PCI_CAP_PCIECAP_ID, + NULL, NULL); ASSERT(cap_ptr); pi->pciecap_lcreg_offset = cap_ptr + PCIE_CAP_LINKCTRL_OFFSET; } else @@ -129,16 +130,16 @@ pcicore_find_pci_capability(void *dev, u8 req_cap_id, u8 byte_val; /* check for Header type 0 */ - pci_read_config_byte(dev, PCI_HEADER_TYPE, &byte_val); - if ((byte_val & 0x7f) != PCI_HEADER_TYPE_NORMAL) + pci_read_config_byte(dev, PCI_CFG_HDR, &byte_val); + if ((byte_val & 0x7f) != PCI_HEADER_NORMAL) goto end; /* check if the capability pointer field exists */ - pci_read_config_byte(dev, PCI_STATUS, &byte_val); - if (!(byte_val & PCI_STATUS_CAP_LIST)) + pci_read_config_byte(dev, PCI_CFG_STAT, &byte_val); + if (!(byte_val & PCI_CAPPTR_PRESENT)) goto end; - pci_read_config_byte(dev, PCI_CAPABILITY_LIST, &cap_ptr); + pci_read_config_byte(dev, PCI_CFG_CAPPTR, &cap_ptr); /* check if the capability pointer is 0x00 */ if (cap_ptr == 0x00) goto end; @@ -166,8 +167,8 @@ pcicore_find_pci_capability(void *dev, u8 req_cap_id, *buflen = 0; /* copy the cpability data excluding cap ID and next ptr */ cap_data = cap_ptr + 2; - if ((bufsize + cap_data) > PCI_SZPCR) - bufsize = PCI_SZPCR - cap_data; + if ((bufsize + cap_data) > SZPCR) + bufsize = SZPCR - cap_data; *buflen = bufsize; while (bufsize--) { pci_read_config_byte(dev, cap_data, buf); @@ -692,15 +693,16 @@ bool pcicore_pmecap_fast(void *pch) u8 cap_ptr; u32 pmecap; - cap_ptr = pcicore_find_pci_capability(pi->dev, PCI_CAP_ID_PM, NULL, - NULL); + cap_ptr = + pcicore_find_pci_capability(pi->dev, PCI_CAP_POWERMGMTCAP_ID, NULL, + NULL); if (!cap_ptr) return false; pci_read_config_dword(pi->dev, cap_ptr, &pmecap); - return (pmecap & (PCI_PM_CAP_PME_MASK << 16)) != 0; + return (pmecap & PME_CAP_PM_STATES) != 0; } /* return true if PM capability exists in the pci config space @@ -712,9 +714,10 @@ static bool pcicore_pmecap(pcicore_info_t *pi) u32 pmecap; if (!pi->pmecap_offset) { - cap_ptr = pcicore_find_pci_capability(pi->dev, - PCI_CAP_ID_PM, - NULL, NULL); + cap_ptr = + pcicore_find_pci_capability(pi->dev, + PCI_CAP_POWERMGMTCAP_ID, NULL, + NULL); if (!cap_ptr) return false; @@ -724,7 +727,7 @@ static bool pcicore_pmecap(pcicore_info_t *pi) &pmecap); /* At least one state can generate PME */ - pi->pmecap = (pmecap & (PCI_PM_CAP_PME_MASK << 16)) != 0; + pi->pmecap = (pmecap & PME_CAP_PM_STATES) != 0; } return pi->pmecap; @@ -740,11 +743,11 @@ void pcicore_pmeen(void *pch) if (!pcicore_pmecap(pi)) return; - pci_read_config_dword(pi->dev, pi->pmecap_offset + PCI_PM_CTRL, + pci_read_config_dword(pi->dev, pi->pmecap_offset + PME_CSR_OFFSET, &w); - w |= (PCI_PM_CTRL_PME_ENABLE); + w |= (PME_CSR_PME_EN); pci_write_config_dword(pi->dev, - pi->pmecap_offset + PCI_PM_CTRL, w); + pi->pmecap_offset + PME_CSR_OFFSET, w); } /* @@ -758,10 +761,10 @@ bool pcicore_pmestat(void *pch) if (!pcicore_pmecap(pi)) return false; - pci_read_config_dword(pi->dev, pi->pmecap_offset + PCI_PM_CTRL, + pci_read_config_dword(pi->dev, pi->pmecap_offset + PME_CSR_OFFSET, &w); - return (w & PCI_PM_CTRL_PME_STATUS) == PCI_PM_CTRL_PME_STATUS; + return (w & PME_CSR_PME_STAT) == PME_CSR_PME_STAT; } /* Disable PME generation, clear the PME status bit if set @@ -774,16 +777,16 @@ void pcicore_pmeclr(void *pch) if (!pcicore_pmecap(pi)) return; - pci_read_config_dword(pi->dev, pi->pmecap_offset + PCI_PM_CTRL, + pci_read_config_dword(pi->dev, pi->pmecap_offset + PME_CSR_OFFSET, &w); PCI_ERROR(("pcicore_pci_pmeclr PMECSR : 0x%x\n", w)); /* PMESTAT is cleared by writing 1 to it */ - w &= ~(PCI_PM_CTRL_PME_ENABLE); + w &= ~(PME_CSR_PME_EN); pci_write_config_dword(pi->dev, - pi->pmecap_offset + PCI_PM_CTRL, w); + pi->pmecap_offset + PME_CSR_OFFSET, w); } u32 pcie_lcreg(void *pch, u32 mask, u32 val) diff --git a/trunk/drivers/staging/brcm80211/util/nvram/nvram_ro.c b/trunk/drivers/staging/brcm80211/util/nvram/nvram_ro.c index 397eb8cde5c1..a697ff10ef36 100644 --- a/trunk/drivers/staging/brcm80211/util/nvram/nvram_ro.c +++ b/trunk/drivers/staging/brcm80211/util/nvram/nvram_ro.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -97,7 +98,7 @@ int nvram_append(void *si, char *varlst, uint varsz) new->next = vars; vars = new; - return 0; + return BCME_OK; } void nvram_exit(void *si) diff --git a/trunk/drivers/staging/brcm80211/util/siutils.c b/trunk/drivers/staging/brcm80211/util/siutils.c index 9e181d60c201..6ebd7f58af81 100644 --- a/trunk/drivers/staging/brcm80211/util/siutils.c +++ b/trunk/drivers/staging/brcm80211/util/siutils.c @@ -312,8 +312,7 @@ static __used void si_nvram_process(si_info_t *sii, char *pvars) switch (sii->pub.bustype) { case PCI_BUS: /* do a pci config read to get subsystem id and subvendor id */ - pci_read_config_dword(sii->pbus, PCI_SUBSYSTEM_VENDOR_ID, - &w); + pci_read_config_dword(sii->pbus, PCI_CFG_SVID, &w); /* Let nvram variables override subsystem Vend/ID */ sii->pub.boardvendor = (u16)si_getdevpathintvar(&sii->pub, "boardvendor"); @@ -338,14 +337,14 @@ static __used void si_nvram_process(si_info_t *sii, char *pvars) #ifdef BCMSDIO case SPI_BUS: - sii->pub.boardvendor = PCI_VENDOR_ID_BROADCOM; + sii->pub.boardvendor = VENDOR_BROADCOM; sii->pub.boardtype = SPI_BOARD; break; #endif case SI_BUS: case JTAG_BUS: - sii->pub.boardvendor = PCI_VENDOR_ID_BROADCOM; + sii->pub.boardvendor = VENDOR_BROADCOM; sii->pub.boardtype = getintvar(pvars, "prodid"); if (pvars == NULL || (sii->pub.boardtype == 0)) { sii->pub.boardtype = getintvar(NULL, "boardtype"); @@ -365,7 +364,7 @@ static __used void si_nvram_process(si_info_t *sii, char *pvars) /* this is will make Sonics calls directly, since Sonics is no longer supported in the Si abstraction */ /* this has been customized for the bcm 4329 ONLY */ -#ifdef BRCM_FULLMAC +#ifdef BCMSDIO static si_info_t *si_doattach(si_info_t *sii, uint devid, void *regs, uint bustype, void *pbus, char **vars, uint *varsz) @@ -373,6 +372,7 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, struct si_pub *sih = &sii->pub; u32 w, savewin; chipcregs_t *cc; + char *pvars = NULL; uint origidx; ASSERT(GOODREGS(regs)); @@ -431,17 +431,69 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, goto exit; } +#ifdef BRCM_FULLMAC + pvars = NULL; +#else + /* Init nvram from flash if it exists */ + nvram_init((void *)&(sii->pub)); + + /* Init nvram from sprom/otp if they exist */ + if (srom_var_init + (&sii->pub, bustype, regs, sii->osh, vars, varsz)) { + SI_ERROR(("si_doattach: srom_var_init failed: bad srom\n")); + goto exit; + } + pvars = vars ? *vars : NULL; + si_nvram_process(sii, pvars); +#endif + + /* === NVRAM, clock is ready === */ + +#ifdef BRCM_FULLMAC + if (sii->pub.ccrev >= 20) { +#endif cc = (chipcregs_t *) si_setcore(sih, CC_CORE_ID, 0); W_REG(&cc->gpiopullup, 0); W_REG(&cc->gpiopulldown, 0); sb_setcoreidx(sih, origidx); +#ifdef BRCM_FULLMAC + } +#endif + +#ifndef BRCM_FULLMAC + /* PMU specific initializations */ + if (PMUCTL_ENAB(sih)) { + u32 xtalfreq; + si_pmu_init(sih); + si_pmu_chip_init(sih); + xtalfreq = getintvar(pvars, "xtalfreq"); + /* If xtalfreq var not available, try to measure it */ + if (xtalfreq == 0) + xtalfreq = si_pmu_measure_alpclk(sih); + si_pmu_pll_init(sih, xtalfreq); + si_pmu_res_init(sih); + si_pmu_swreg_init(sih); + } + + /* setup the GPIO based LED powersave register */ + w = getintvar(pvars, "leddc"); + if (w == 0) + w = DEFAULT_GPIOTIMERVAL; + sb_corereg(sih, SI_CC_IDX, offsetof(chipcregs_t, gpiotimerval), ~0, w); + +#ifdef BCMDBG + /* clear any previous epidiag-induced target abort */ + sb_taclear(sih, false); +#endif /* BCMDBG */ +#endif return sii; exit: return NULL; } -#else /* BRCM_FULLMAC */ + +#else /* BCMSDIO */ static si_info_t *si_doattach(si_info_t *sii, uint devid, void *regs, uint bustype, void *pbus, char **vars, uint *varsz) @@ -633,7 +685,7 @@ static si_info_t *si_doattach(si_info_t *sii, uint devid, return NULL; } -#endif /* BRCM_FULLMAC */ +#endif /* BCMSDIO */ /* may be called with core in reset */ void si_detach(si_t *sih) @@ -1486,8 +1538,9 @@ static __used bool si_ispcie(si_info_t *sii) if (sii->pub.bustype != PCI_BUS) return false; - cap_ptr = pcicore_find_pci_capability(sii->pbus, PCI_CAP_ID_EXP, NULL, - NULL); + cap_ptr = + pcicore_find_pci_capability(sii->pbus, PCI_CAP_PCIECAP_ID, NULL, + NULL); if (!cap_ptr) return false; @@ -1864,8 +1917,8 @@ bool si_deviceremoved(si_t *sih) switch (sih->bustype) { case PCI_BUS: ASSERT(sii->pbus != NULL); - pci_read_config_dword(sii->pbus, PCI_VENDOR_ID, &w); - if ((w & 0xFFFF) != PCI_VENDOR_ID_BROADCOM) + pci_read_config_dword(sii->pbus, PCI_CFG_VID, &w); + if ((w & 0xFFFF) != VENDOR_BROADCOM) return true; break; } diff --git a/trunk/drivers/staging/comedi/drivers/addi-data/APCI1710_Ssi.c b/trunk/drivers/staging/comedi/drivers/addi-data/APCI1710_Ssi.c index c13b00274923..0c890a969bb1 100644 --- a/trunk/drivers/staging/comedi/drivers/addi-data/APCI1710_Ssi.c +++ b/trunk/drivers/staging/comedi/drivers/addi-data/APCI1710_Ssi.c @@ -35,8 +35,22 @@ You should also find the complete GPL in the COPYING file accompanying this sour | Project manager: Eric Stolz | Date : 02/12/2002 | +-----------------------------------------------------------------------+ | Description : APCI-1710 SSI counter module | + | | + | | +-----------------------------------------------------------------------+ - | several changes done by S. Weber in 1998 and C. Guinot in 2000 | + | UPDATES | + +-----------------------------------------------------------------------+ + | Date | Author | Description of updates | + +----------+-----------+------------------------------------------------+ + | 13/05/98 | S. Weber | SSI digital input / output implementation | + |----------|-----------|------------------------------------------------| + | 22/03/00 | C.Guinot | 0100/0226 -> 0200/0227 | + | | | Änderung in InitSSI Funktion | + | | | b_SSIProfile >= 2 anstatt b_SSIProfile > 2 | + | | | | + +-----------------------------------------------------------------------+ + | 08/05/00 | Guinot C | - 0400/0228 All Function in RING 0 | + | | | available | +-----------------------------------------------------------------------+ */ diff --git a/trunk/drivers/staging/crystalhd/bc_dts_types.h b/trunk/drivers/staging/crystalhd/bc_dts_types.h index d2131e7fe2fb..6fd8089415d6 100644 --- a/trunk/drivers/staging/crystalhd/bc_dts_types.h +++ b/trunk/drivers/staging/crystalhd/bc_dts_types.h @@ -65,6 +65,7 @@ typedef unsigned char *PUCHAR; #else /* For Kernel usage.. */ +typedef bool bc_bool_t; #endif #else diff --git a/trunk/drivers/staging/cx25821/cx25821-video.c b/trunk/drivers/staging/cx25821/cx25821-video.c index 04b18f4d98f8..ab05392386e8 100644 --- a/trunk/drivers/staging/cx25821/cx25821-video.c +++ b/trunk/drivers/staging/cx25821/cx25821-video.c @@ -832,7 +832,6 @@ static int video_open(struct file *file) if (NULL == dev) { mutex_unlock(&cx25821_devlist_mutex); - kfree(fh); return -ENODEV; } diff --git a/trunk/drivers/staging/easycap/easycap_main.c b/trunk/drivers/staging/easycap/easycap_main.c index 74adfb0ff347..cee3252ea2d9 100644 --- a/trunk/drivers/staging/easycap/easycap_main.c +++ b/trunk/drivers/staging/easycap/easycap_main.c @@ -201,9 +201,9 @@ static int easycap_open(struct inode *inode, struct file *file) static int reset(struct easycap *peasycap) { struct easycap_standard const *peasycap_standard; - int fmtidx, input, rate; + int i, rc, input, rate; bool ntsc, other; - int rc; + int fmtidx; if (!peasycap) { SAY("ERROR: peasycap is NULL\n"); @@ -226,27 +226,33 @@ static int reset(struct easycap *peasycap) JOM(8, "peasycap->ntsc=%d\n", peasycap->ntsc); rate = ready_saa(peasycap->pusb_device); - if (rate < 0) { + if (0 > rate) { JOM(8, "not ready to capture after %i ms ...\n", PATIENCE); - ntsc = !peasycap->ntsc; - JOM(8, "... trying %s ..\n", ntsc ? "NTSC" : "PAL"); - rc = setup_stk(peasycap->pusb_device, ntsc); - if (rc) { - SAM("ERROR: setup_stk() rc = %i\n", rc); - return -EFAULT; - } - rc = setup_saa(peasycap->pusb_device, ntsc); - if (rc) { - SAM("ERROR: setup_saa() rc = %i\n", rc); - return -EFAULT; - } - - rate = ready_saa(peasycap->pusb_device); - if (rate < 0) { - JOM(8, "not ready to capture after %i ms\n", PATIENCE); - JOM(8, "... saa register 0x1F has 0x%02X\n", + if (peasycap->ntsc) { + JOM(8, "... trying PAL ...\n"); ntsc = false; + } else { + JOM(8, "... trying NTSC ...\n"); ntsc = true; + } + rc = setup_stk(peasycap->pusb_device, ntsc); + if (0 == rc) + JOM(4, "setup_stk() OK\n"); + else { + SAM("ERROR: setup_stk() rc = %i\n", rc); + return -EFAULT; + } + rc = setup_saa(peasycap->pusb_device, ntsc); + if (0 == rc) + JOM(4, "setup_saa() OK\n"); + else { + SAM("ERROR: setup_saa() rc = %i\n", rc); + return -EFAULT; + } + rate = ready_saa(peasycap->pusb_device); + if (0 > rate) { + JOM(8, "not ready to capture after %i ms ...\n", PATIENCE); + JOM(8, "... saa register 0x1F has 0x%02X\n", read_saa(peasycap->pusb_device, 0x1F)); - ntsc = peasycap->ntsc; + ntsc = peasycap->ntsc; } else { JOM(8, "... success at second try: %i=rate\n", rate); ntsc = (0 < (rate/2)) ? true : false ; @@ -260,17 +266,22 @@ static int reset(struct easycap *peasycap) /*---------------------------------------------------------------------------*/ rc = setup_stk(peasycap->pusb_device, ntsc); - if (rc) { + if (0 == rc) + JOM(4, "setup_stk() OK\n"); + else { SAM("ERROR: setup_stk() rc = %i\n", rc); return -EFAULT; } rc = setup_saa(peasycap->pusb_device, ntsc); - if (rc) { + if (0 == rc) + JOM(4, "setup_saa() OK\n"); + else { SAM("ERROR: setup_saa() rc = %i\n", rc); return -EFAULT; } - memset(peasycap->merit, 0, sizeof(peasycap->merit)); + for (i = 0; i < 180; i++) + peasycap->merit[i] = 0; peasycap->video_eof = 0; peasycap->audio_eof = 0; @@ -2975,19 +2986,25 @@ static const struct v4l2_file_operations v4l2_fops = { * TIMES, ONCE FOR EACH OF THE THREE INTERFACES. BEWARE. */ /*---------------------------------------------------------------------------*/ -static int easycap_usb_probe(struct usb_interface *intf, - const struct usb_device_id *id) +static int easycap_usb_probe(struct usb_interface *pusb_interface, + const struct usb_device_id *pusb_device_id) { - struct usb_device *usbdev; - struct usb_host_interface *alt; - struct usb_endpoint_descriptor *ep; - struct usb_interface_descriptor *interface; + struct usb_device *pusb_device; + struct usb_host_interface *pusb_host_interface; + struct usb_endpoint_descriptor *pepd; + struct usb_interface_descriptor *pusb_interface_descriptor; struct urb *purb; struct easycap *peasycap; int ndong; struct data_urb *pdata_urb; size_t wMaxPacketSize; + int ISOCwMaxPacketSize; + int BULKwMaxPacketSize; + int INTwMaxPacketSize; + int CTRLwMaxPacketSize; u8 bEndpointAddress; + u8 ISOCbEndpointAddress; + u8 INTbEndpointAddress; int isin, i, j, k, m, rc; u8 bInterfaceNumber; u8 bInterfaceClass; @@ -3004,17 +3021,23 @@ static int easycap_usb_probe(struct usb_interface *intf, struct inputset *inputset; struct v4l2_device *pv4l2_device; - usbdev = interface_to_usbdev(intf); +/*---------------------------------------------------------------------------*/ +/* + * GET POINTER TO STRUCTURE usb_device + */ +/*---------------------------------------------------------------------------*/ + pusb_device = interface_to_usbdev(pusb_interface); + JOT(4, "bNumConfigurations=%i\n", pusb_device->descriptor.bNumConfigurations); /*---------------------------------------------------------------------------*/ - alt = usb_altnum_to_altsetting(intf, 0); - if (!alt) { - SAY("ERROR: usb_host_interface not found\n"); + pusb_host_interface = pusb_interface->cur_altsetting; + if (!pusb_host_interface) { + SAY("ERROR: pusb_host_interface is NULL\n"); return -EFAULT; } - interface = &alt->desc; - if (!interface) { - SAY("ERROR: intf_descriptor is NULL\n"); + pusb_interface_descriptor = &(pusb_host_interface->desc); + if (!pusb_interface_descriptor) { + SAY("ERROR: pusb_interface_descriptor is NULL\n"); return -EFAULT; } /*---------------------------------------------------------------------------*/ @@ -3022,15 +3045,16 @@ static int easycap_usb_probe(struct usb_interface *intf, * GET PROPERTIES OF PROBED INTERFACE */ /*---------------------------------------------------------------------------*/ - bInterfaceNumber = interface->bInterfaceNumber; - bInterfaceClass = interface->bInterfaceClass; - bInterfaceSubClass = interface->bInterfaceSubClass; + bInterfaceNumber = pusb_interface_descriptor->bInterfaceNumber; + bInterfaceClass = pusb_interface_descriptor->bInterfaceClass; + bInterfaceSubClass = pusb_interface_descriptor->bInterfaceSubClass; JOT(4, "intf[%i]: num_altsetting=%i\n", - bInterfaceNumber, intf->num_altsetting); + bInterfaceNumber, pusb_interface->num_altsetting); JOT(4, "intf[%i]: cur_altsetting - altsetting=%li\n", bInterfaceNumber, - (long int)(intf->cur_altsetting - intf->altsetting)); + (long int)(pusb_interface->cur_altsetting - + pusb_interface->altsetting)); JOT(4, "intf[%i]: bInterfaceClass=0x%02X bInterfaceSubClass=0x%02X\n", bInterfaceNumber, bInterfaceClass, bInterfaceSubClass); /*---------------------------------------------------------------------------*/ @@ -3116,8 +3140,8 @@ static int easycap_usb_probe(struct usb_interface *intf, * ... AND FURTHER INITIALIZE THE STRUCTURE */ /*---------------------------------------------------------------------------*/ - peasycap->pusb_device = usbdev; - peasycap->pusb_interface = intf; + peasycap->pusb_device = pusb_device; + peasycap->pusb_interface = pusb_interface; peasycap->ilk = 0; peasycap->microphone = false; @@ -3251,7 +3275,7 @@ static int easycap_usb_probe(struct usb_interface *intf, */ /*---------------------------------------------------------------------------*/ for (ndong = 0; ndong < DONGLE_MANY; ndong++) { - if (usbdev == easycapdc60_dongle[ndong].peasycap-> + if (pusb_device == easycapdc60_dongle[ndong].peasycap-> pusb_device) { peasycap = easycapdc60_dongle[ndong].peasycap; JOT(8, "intf[%i]: dongle[%i].peasycap\n", @@ -3278,7 +3302,7 @@ static int easycap_usb_probe(struct usb_interface *intf, */ /*---------------------------------------------------------------------------*/ if (memcmp(&peasycap->telltale[0], TELLTALE, strlen(TELLTALE))) { - pv4l2_device = usb_get_intfdata(intf); + pv4l2_device = usb_get_intfdata(pusb_interface); if (!pv4l2_device) { SAY("ERROR: pv4l2_device is NULL\n"); return -ENODEV; @@ -3327,63 +3351,70 @@ static int easycap_usb_probe(struct usb_interface *intf, /*---------------------------------------------------------------------------*/ isokalt = 0; - for (i = 0; i < intf->num_altsetting; i++) { - alt = usb_altnum_to_altsetting(intf, i); - if (!alt) { - SAM("ERROR: alt is NULL\n"); + for (i = 0; i < pusb_interface->num_altsetting; i++) { + pusb_host_interface = &(pusb_interface->altsetting[i]); + if (!pusb_host_interface) { + SAM("ERROR: pusb_host_interface is NULL\n"); return -EFAULT; } - interface = &alt->desc; - if (!interface) { - SAM("ERROR: intf_descriptor is NULL\n"); + pusb_interface_descriptor = &(pusb_host_interface->desc); + if (!pusb_interface_descriptor) { + SAM("ERROR: pusb_interface_descriptor is NULL\n"); return -EFAULT; } JOM(4, "intf[%i]alt[%i]: desc.bDescriptorType=0x%02X\n", - bInterfaceNumber, i, interface->bDescriptorType); + bInterfaceNumber, i, pusb_interface_descriptor->bDescriptorType); JOM(4, "intf[%i]alt[%i]: desc.bInterfaceNumber=0x%02X\n", - bInterfaceNumber, i, interface->bInterfaceNumber); + bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceNumber); JOM(4, "intf[%i]alt[%i]: desc.bAlternateSetting=0x%02X\n", - bInterfaceNumber, i, interface->bAlternateSetting); + bInterfaceNumber, i, pusb_interface_descriptor->bAlternateSetting); JOM(4, "intf[%i]alt[%i]: desc.bNumEndpoints=0x%02X\n", - bInterfaceNumber, i, interface->bNumEndpoints); + bInterfaceNumber, i, pusb_interface_descriptor->bNumEndpoints); JOM(4, "intf[%i]alt[%i]: desc.bInterfaceClass=0x%02X\n", - bInterfaceNumber, i, interface->bInterfaceClass); + bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceClass); JOM(4, "intf[%i]alt[%i]: desc.bInterfaceSubClass=0x%02X\n", - bInterfaceNumber, i, interface->bInterfaceSubClass); + bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceSubClass); JOM(4, "intf[%i]alt[%i]: desc.bInterfaceProtocol=0x%02X\n", - bInterfaceNumber, i, interface->bInterfaceProtocol); + bInterfaceNumber, i, pusb_interface_descriptor->bInterfaceProtocol); JOM(4, "intf[%i]alt[%i]: desc.iInterface=0x%02X\n", - bInterfaceNumber, i, interface->iInterface); + bInterfaceNumber, i, pusb_interface_descriptor->iInterface); + + ISOCwMaxPacketSize = -1; + BULKwMaxPacketSize = -1; + INTwMaxPacketSize = -1; + CTRLwMaxPacketSize = -1; + ISOCbEndpointAddress = 0; + INTbEndpointAddress = 0; - if (0 == interface->bNumEndpoints) + if (0 == pusb_interface_descriptor->bNumEndpoints) JOM(4, "intf[%i]alt[%i] has no endpoints\n", bInterfaceNumber, i); /*---------------------------------------------------------------------------*/ - for (j = 0; j < interface->bNumEndpoints; j++) { - ep = &alt->endpoint[j].desc; - if (!ep) { - SAM("ERROR: ep is NULL.\n"); + for (j = 0; j < pusb_interface_descriptor->bNumEndpoints; j++) { + pepd = &(pusb_host_interface->endpoint[j].desc); + if (!pepd) { + SAM("ERROR: pepd is NULL.\n"); SAM("...... skipping\n"); continue; } - wMaxPacketSize = le16_to_cpu(ep->wMaxPacketSize); - bEndpointAddress = ep->bEndpointAddress; + wMaxPacketSize = le16_to_cpu(pepd->wMaxPacketSize); + bEndpointAddress = pepd->bEndpointAddress; JOM(4, "intf[%i]alt[%i]end[%i]: bEndpointAddress=0x%X\n", bInterfaceNumber, i, j, - ep->bEndpointAddress); + pepd->bEndpointAddress); JOM(4, "intf[%i]alt[%i]end[%i]: bmAttributes=0x%X\n", bInterfaceNumber, i, j, - ep->bmAttributes); + pepd->bmAttributes); JOM(4, "intf[%i]alt[%i]end[%i]: wMaxPacketSize=%i\n", bInterfaceNumber, i, j, - ep->wMaxPacketSize); + pepd->wMaxPacketSize); JOM(4, "intf[%i]alt[%i]end[%i]: bInterval=%i\n", bInterfaceNumber, i, j, - ep->bInterval); + pepd->bInterval); - if (ep->bEndpointAddress & USB_DIR_IN) { + if (pepd->bEndpointAddress & USB_DIR_IN) { JOM(4, "intf[%i]alt[%i]end[%i] is an IN endpoint\n", bInterfaceNumber, i, j); isin = 1; @@ -3394,7 +3425,7 @@ static int easycap_usb_probe(struct usb_interface *intf, SAM("...... continuing\n"); isin = 0; } - if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == + if ((pepd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC) { JOM(4, "intf[%i]alt[%i]end[%i] is an ISOC endpoint\n", bInterfaceNumber, i, j); @@ -3407,7 +3438,7 @@ static int easycap_usb_probe(struct usb_interface *intf, "peasycap is NULL\n"); return -EFAULT; } - if (ep->wMaxPacketSize) { + if (pepd->wMaxPacketSize) { if (8 > isokalt) { okalt[isokalt] = i; JOM(4, @@ -3415,7 +3446,7 @@ static int easycap_usb_probe(struct usb_interface *intf, okalt[isokalt], isokalt); okepn[isokalt] = - ep-> + pepd-> bEndpointAddress & 0x0F; JOM(4, @@ -3423,7 +3454,7 @@ static int easycap_usb_probe(struct usb_interface *intf, okepn[isokalt], isokalt); okmps[isokalt] = - le16_to_cpu(ep-> + le16_to_cpu(pepd-> wMaxPacketSize); JOM(4, "%i=okmps[%i]\n", @@ -3465,7 +3496,7 @@ static int easycap_usb_probe(struct usb_interface *intf, "peasycap is NULL\n"); return -EFAULT; } - if (ep->wMaxPacketSize) { + if (pepd->wMaxPacketSize) { if (8 > isokalt) { okalt[isokalt] = i ; JOM(4, @@ -3473,7 +3504,7 @@ static int easycap_usb_probe(struct usb_interface *intf, okalt[isokalt], isokalt); okepn[isokalt] = - ep-> + pepd-> bEndpointAddress & 0x0F; JOM(4, @@ -3481,7 +3512,7 @@ static int easycap_usb_probe(struct usb_interface *intf, okepn[isokalt], isokalt); okmps[isokalt] = - le16_to_cpu(ep-> + le16_to_cpu(pepd-> wMaxPacketSize); JOM(4, "%i=okmps[%i]\n", @@ -3519,12 +3550,12 @@ static int easycap_usb_probe(struct usb_interface *intf, break; } } - } else if ((ep->bmAttributes & + } else if ((pepd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK) { JOM(4, "intf[%i]alt[%i]end[%i] is a BULK endpoint\n", bInterfaceNumber, i, j); - } else if ((ep->bmAttributes & + } else if ((pepd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT) { JOM(4, "intf[%i]alt[%i]end[%i] is an INT endpoint\n", @@ -3533,7 +3564,7 @@ static int easycap_usb_probe(struct usb_interface *intf, JOM(4, "intf[%i]alt[%i]end[%i] is a CTRL endpoint\n", bInterfaceNumber, i, j); } - if (0 == ep->wMaxPacketSize) { + if (0 == pepd->wMaxPacketSize) { JOM(4, "intf[%i]alt[%i]end[%i] " "has zero packet size\n", bInterfaceNumber, i, j); @@ -3546,7 +3577,7 @@ static int easycap_usb_probe(struct usb_interface *intf, */ /*---------------------------------------------------------------------------*/ JOM(4, "initialization begins for interface %i\n", - interface->bInterfaceNumber); + pusb_interface_descriptor->bInterfaceNumber); switch (bInterfaceNumber) { /*---------------------------------------------------------------------------*/ /* @@ -3813,7 +3844,7 @@ static int easycap_usb_probe(struct usb_interface *intf, * SAVE POINTER peasycap IN THIS INTERFACE. */ /*--------------------------------------------------------------------------*/ - usb_set_intfdata(intf, peasycap); + usb_set_intfdata(pusb_interface, peasycap); /*---------------------------------------------------------------------------*/ /* * IT IS ESSENTIAL TO INITIALIZE THE HARDWARE BEFORE, RATHER THAN AFTER, @@ -3835,7 +3866,7 @@ static int easycap_usb_probe(struct usb_interface *intf, * THE VIDEO DEVICE CAN BE REGISTERED NOW, AS IT IS READY. */ /*--------------------------------------------------------------------------*/ - if (0 != (v4l2_device_register(&(intf->dev), + if (0 != (v4l2_device_register(&(pusb_interface->dev), &(peasycap->v4l2_device)))) { SAM("v4l2_device_register() failed\n"); return -ENODEV; @@ -3893,9 +3924,9 @@ static int easycap_usb_probe(struct usb_interface *intf, * SAVE POINTER peasycap IN INTERFACE 1 */ /*--------------------------------------------------------------------------*/ - usb_set_intfdata(intf, peasycap); + usb_set_intfdata(pusb_interface, peasycap); JOM(4, "no initialization required for interface %i\n", - interface->bInterfaceNumber); + pusb_interface_descriptor->bInterfaceNumber); break; } /*--------------------------------------------------------------------------*/ @@ -4157,7 +4188,7 @@ static int easycap_usb_probe(struct usb_interface *intf, * SAVE POINTER peasycap IN THIS INTERFACE. */ /*---------------------------------------------------------------------------*/ - usb_set_intfdata(intf, peasycap); + usb_set_intfdata(pusb_interface, peasycap); /*---------------------------------------------------------------------------*/ /* * THE AUDIO DEVICE CAN BE REGISTERED NOW, AS IT IS READY. @@ -4170,22 +4201,28 @@ static int easycap_usb_probe(struct usb_interface *intf, if (rc) { err("easycap_alsa_probe() rc = %i\n", rc); return -ENODEV; + } else { + JOM(8, "kref_get() with %i=kref.refcount.counter\n", + peasycap->kref.refcount.counter); + kref_get(&peasycap->kref); + peasycap->registered_audio++; } #else /* CONFIG_EASYCAP_OSS */ - rc = usb_register_dev(intf, &easyoss_class); + rc = usb_register_dev(pusb_interface, &easyoss_class); if (rc) { SAY("ERROR: usb_register_dev() failed\n"); - usb_set_intfdata(intf, NULL); + usb_set_intfdata(pusb_interface, NULL); return -ENODEV; + } else { + JOM(8, "kref_get() with %i=kref.refcount.counter\n", + peasycap->kref.refcount.counter); + kref_get(&peasycap->kref); + peasycap->registered_audio++; } - SAM("easyoss attached to minor #%d\n", intf->minor); + SAM("easyoss attached to minor #%d\n", pusb_interface->minor); #endif /* CONFIG_EASYCAP_OSS */ - JOM(8, "kref_get() with %i=kref.refcount.counter\n", - peasycap->kref.refcount.counter); - kref_get(&peasycap->kref); - peasycap->registered_audio++; break; } /*---------------------------------------------------------------------------*/ diff --git a/trunk/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c b/trunk/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c index 97a29268bb65..684e69eacb71 100644 --- a/trunk/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c +++ b/trunk/drivers/staging/ft1000/ft1000-usb/ft1000_hw.c @@ -6,6 +6,8 @@ // // $Id: //==================================================== +// 20090926; aelias; removed compiler warnings & errors; ubuntu 9.04; 2.6.28-15-generic + #include #include #include @@ -36,6 +38,8 @@ static int ft1000_open (struct net_device *dev); static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev); static int ft1000_chkcard (struct ft1000_device *dev); +//Jim + static u8 tempbuffer[1600]; #define MAX_RCV_LOOP 100 @@ -488,6 +492,8 @@ void card_send_command(struct ft1000_device *ft1000dev, void *ptempbuffer, commandbuf = (unsigned char *)kmalloc(size + 2, GFP_KERNEL); memcpy((void *)commandbuf + 2, (void *)ptempbuffer, size); + //DEBUG("card_send_command: Command Send\n"); + ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL); if (temp & 0x0100) @@ -500,14 +506,16 @@ void card_send_command(struct ft1000_device *ft1000dev, void *ptempbuffer, if (size % 4) size += 4 - (size % 4); + //DEBUG("card_send_command: write dpram ... size=%d\n", size); ft1000_write_dpram32(ft1000dev, 0, commandbuf, size); msleep(1); + //DEBUG("card_send_command: write into doorbell ...\n"); ft1000_write_register(ft1000dev, FT1000_DB_DPRAM_TX, FT1000_REG_DOORBELL); msleep(1); ft1000_read_register(ft1000dev, &temp, FT1000_REG_DOORBELL); - + //DEBUG("card_send_command: read doorbell ...temp=%x\n", temp); if ((temp & 0x0100) == 0) { //DEBUG("card_send_command: Message sent\n"); } @@ -675,6 +683,8 @@ static int ft1000_reset_card(struct net_device *dev) return TRUE; } + +//mbelian #ifdef HAVE_NET_DEVICE_OPS static const struct net_device_ops ftnet_ops = { @@ -894,10 +904,14 @@ static void ft1000_usb_transmit_complete(struct urb *urb) struct ft1000_device *ft1000dev = urb->context; + //DEBUG("ft1000_usb_transmit_complete entered\n"); + if (urb->status) pr_err("%s: TX status %d\n", ft1000dev->net->name, urb->status); netif_wake_queue(ft1000dev->net); + + //DEBUG("Return from ft1000_usb_transmit_complete\n"); } //--------------------------------------------------------------------------- @@ -929,6 +943,8 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) return -ENODEV; } + //DEBUG("ft1000_copy_down_pkt() entered, len = %d\n", len); + count = sizeof(struct pseudo_hdr) + len; if (count > MAX_BUF_SIZE) { DEBUG("Error:ft1000_copy_down_pkt:Message Size Overflow!\n"); @@ -957,6 +973,8 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) netif_stop_queue(netdev); + //DEBUG ("ft1000_copy_down_pkt: count = %d\n", count); + usb_fill_bulk_urb(pFt1000Dev->tx_urb, pFt1000Dev->dev, usb_sndbulkpipe(pFt1000Dev->dev, @@ -965,6 +983,11 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) ft1000_usb_transmit_complete, (void *)pFt1000Dev); t = (u8 *) pFt1000Dev->tx_urb->transfer_buffer; + //DEBUG("transfer_length=%d\n", pFt1000Dev->tx_urb->transfer_buffer_length); + /*for (i=0; itx_urb, GFP_ATOMIC); @@ -976,6 +999,8 @@ static int ft1000_copy_down_pkt(struct net_device *netdev, u8 * packet, u16 len) pInfo->stats.tx_bytes += (len + 14); } + //DEBUG("ft1000_copy_down_pkt() exit\n"); + return 0; } @@ -1001,6 +1026,8 @@ static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) u8 *pdata; int maxlen, pipe; + //DEBUG(" ft1000_start_xmit() entered\n"); + if (skb == NULL) { DEBUG("ft1000_hw: ft1000_start_xmit:skb == NULL!!!\n"); return NETDEV_TX_OK; @@ -1010,12 +1037,17 @@ static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) DEBUG("network driver is closed, return\n"); goto err; } - + //DEBUG("ft1000_start_xmit 1:length of packet = %d\n", skb->len); pipe = usb_sndbulkpipe(pFt1000Dev->dev, pFt1000Dev->bulk_out_endpointAddr); maxlen = usb_maxpacket(pFt1000Dev->dev, pipe, usb_pipeout(pipe)); + //DEBUG("ft1000_start_xmit 2: pipe=%d dev->maxpacket = %d\n", pipe, maxlen); pdata = (u8 *) skb->data; + /*for (i=0; ilen; i++) + DEBUG("skb->data[%d]=%x ", i, *(skb->data+i)); + + DEBUG("\n"); */ if (pInfo->mediastate == 0) { /* Drop packet is mediastate is down */ @@ -1028,12 +1060,13 @@ static int ft1000_start_xmit(struct sk_buff *skb, struct net_device *dev) DEBUG("ft1000_hw:ft1000_start_xmit:invalid ethernet length\n"); goto err; } - +//mbelian ft1000_copy_down_pkt(dev, (pdata + ENET_HEADER_SIZE - 2), skb->len - ENET_HEADER_SIZE + 2); err: dev_kfree_skb(skb); + //DEBUG(" ft1000_start_xmit() exit\n"); return NETDEV_TX_OK; } @@ -1060,20 +1093,24 @@ static int ft1000_copy_up_pkt(struct urb *urb) u16 tempword; u16 len; - u16 lena; + u16 lena; //mbelian struct sk_buff *skb; u16 i; u8 *pbuffer = NULL; u8 *ptemp = NULL; u16 *chksum; + //DEBUG("ft1000_copy_up_pkt entered\n"); + if (ft1000dev->status & FT1000_STATUS_CLOSING) { DEBUG("network driver is closed, return\n"); return STATUS_SUCCESS; } // Read length len = urb->transfer_buffer_length; - lena = urb->actual_length; + lena = urb->actual_length; //mbelian + //DEBUG("ft1000_copy_up_pkt: transfer_buffer_length=%d, actual_buffer_len=%d\n", + // urb->transfer_buffer_length, urb->actual_length); chksum = (u16 *) ft1000dev->rx_buf; @@ -1087,6 +1124,8 @@ static int ft1000_copy_up_pkt(struct urb *urb) return STATUS_FAILURE; } + //DEBUG("ft1000_copy_up_pkt: checksum is correct %x\n", *chksum); + skb = dev_alloc_skb(len + 12 + 2); if (skb == NULL) { @@ -1118,6 +1157,12 @@ static int ft1000_copy_up_pkt(struct urb *urb) memcpy(pbuffer, ft1000dev->rx_buf + sizeof(struct pseudo_hdr), len - sizeof(struct pseudo_hdr)); + //DEBUG("ft1000_copy_up_pkt: Data passed to Protocol layer\n"); + /*for (i=0; idev = net; skb->protocol = eth_type_trans(skb, net); @@ -1126,10 +1171,10 @@ static int ft1000_copy_up_pkt(struct urb *urb) info->stats.rx_packets++; /* Add on 12 bytes for MAC address which was removed */ - info->stats.rx_bytes += (lena + 12); + info->stats.rx_bytes += (lena + 12); //mbelian ft1000_submit_rx_urb(info); - + //DEBUG("ft1000_copy_up_pkt exited\n"); return SUCCESS; } @@ -1152,8 +1197,10 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info) int result; struct ft1000_device *pFt1000Dev = info->pFt1000Dev; + //DEBUG ("ft1000_submit_rx_urb entered: sizeof rx_urb is %d\n", sizeof(*pFt1000Dev->rx_urb)); if (pFt1000Dev->status & FT1000_STATUS_CLOSING) { DEBUG("network driver is closed, return\n"); + //usb_kill_urb(pFt1000Dev->rx_urb); //mbelian return -ENODEV; } @@ -1171,6 +1218,7 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info) result); return result; } + //DEBUG("ft1000_submit_rx_urb exit: result=%d\n", result); return 0; } @@ -1193,22 +1241,23 @@ static int ft1000_submit_rx_urb(struct ft1000_info *info) static int ft1000_open(struct net_device *dev) { struct ft1000_info *pInfo = netdev_priv(dev); - struct timeval tv; + struct timeval tv; //mbelian int ret; DEBUG("ft1000_open is called for card %d\n", pInfo->CardNumber); + //DEBUG("ft1000_open: dev->addr=%x, dev->addr_len=%d\n", dev->addr, dev->addr_len); - pInfo->stats.rx_bytes = 0; - pInfo->stats.tx_bytes = 0; - pInfo->stats.rx_packets = 0; - pInfo->stats.tx_packets = 0; + pInfo->stats.rx_bytes = 0; //mbelian + pInfo->stats.tx_bytes = 0; //mbelian + pInfo->stats.rx_packets = 0; //mbelian + pInfo->stats.tx_packets = 0; //mbelian do_gettimeofday(&tv); pInfo->ConTm = tv.tv_sec; - pInfo->ProgConStat = 0; + pInfo->ProgConStat = 0; //mbelian netif_start_queue(dev); - netif_carrier_on(dev); + netif_carrier_on(dev); //mbelian ret = ft1000_submit_rx_urb(pInfo); @@ -1234,14 +1283,19 @@ int ft1000_close(struct net_device *net) struct ft1000_info *pInfo = netdev_priv(net); struct ft1000_device *ft1000dev = pInfo->pFt1000Dev; + //DEBUG ("ft1000_close: netdev->refcnt=%d\n", net->refcnt); + ft1000dev->status |= FT1000_STATUS_CLOSING; + //DEBUG("ft1000_close: calling usb_kill_urb \n"); + DEBUG("ft1000_close: pInfo=%p, ft1000dev=%p\n", pInfo, ft1000dev); - netif_carrier_off(net); + netif_carrier_off(net); //mbelian netif_stop_queue(net); + //DEBUG("ft1000_close: netif_stop_queue called\n"); ft1000dev->status &= ~FT1000_STATUS_CLOSING; - pInfo->ProgConStat = 0xff; + pInfo->ProgConStat = 0xff; //mbelian return 0; } @@ -1250,10 +1304,15 @@ static struct net_device_stats *ft1000_netdev_stats(struct net_device *dev) { struct ft1000_info *info = netdev_priv(dev); - return &(info->stats); + return &(info->stats); //mbelian } +/********************************************************************************* +Jim +*/ + + //--------------------------------------------------------------------------- // // Function: ft1000_chkcard @@ -1281,6 +1340,7 @@ static int ft1000_chkcard(struct ft1000_device *dev) * set to zero. */ status = ft1000_read_register(dev, &tempword, FT1000_REG_SUP_IMASK); + //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_SUP_IMASK = %x\n", tempword); if (tempword == 0) { DEBUG ("ft1000_hw:ft1000_chkcard: IMASK = 0 Card not detected\n"); @@ -1290,8 +1350,9 @@ static int ft1000_chkcard(struct ft1000_device *dev) * if the device is not present. */ status = ft1000_read_register(dev, &tempword, FT1000_REG_ASIC_ID); + //DEBUG("ft1000_hw:ft1000_chkcard: read FT1000_REG_ASIC_ID = %x\n", tempword); if (tempword != 0x1b01) { - dev->status |= FT1000_STATUS_CLOSING; + dev->status |= FT1000_STATUS_CLOSING; //mbelian DEBUG ("ft1000_hw:ft1000_chkcard: Version = 0xffff Card not detected\n"); return FALSE; @@ -1334,6 +1395,7 @@ static bool ft1000_receive_cmd(struct ft1000_device *dev, u16 *pbuffer, FT1000_REG_DPRAM_ADDR); ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH); + //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer); pbuffer++; ft1000_write_register(dev, FT1000_DPRAM_MAG_RX_BASE + 1, FT1000_REG_DPRAM_ADDR); @@ -1350,11 +1412,11 @@ static bool ft1000_receive_cmd(struct ft1000_device *dev, u16 *pbuffer, /* copy odd aligned word */ ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAL); - + //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer); pbuffer++; ret = ft1000_read_register(dev, pbuffer, FT1000_REG_MAG_DPDATAH); - + //DEBUG("ft1000_hw:received data = 0x%x\n", *pbuffer); pbuffer++; if (size & 0x0001) { /* copy odd byte from fifo */ @@ -1433,8 +1495,10 @@ static int ft1000_dsp_prov(void *arg) ppseudo_hdr->portsrc = 0; /* Calculate new checksum */ ppseudo_hdr->checksum = *pmsg++; + //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); for (i = 1; i < 7; i++) { ppseudo_hdr->checksum ^= *pmsg++; + //DEBUG("checksum = 0x%x\n", ppseudo_hdr->checksum); } TempShortBuf[0] = 0; @@ -1518,16 +1582,21 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) DEBUG("Media is up\n"); if (info->mediastate == 0) { if (info->NetDevRegDone) { + //netif_carrier_on(dev->net);//mbelian netif_wake_queue(dev-> net); } info->mediastate = 1; + /*do_gettimeofday(&tv); + info->ConTm = tv.tv_sec; *///mbelian } } else { DEBUG("Media is down\n"); if (info->mediastate == 1) { info->mediastate = 0; if (info->NetDevRegDone) { + //netif_carrier_off(dev->net); mbelian + //netif_stop_queue(dev->net); } info->ConTm = 0; } @@ -1536,6 +1605,10 @@ static int ft1000_proc_drvmsg(struct ft1000_device *dev, u16 size) DEBUG("Media is down\n"); if (info->mediastate == 1) { info->mediastate = 0; + if (info->NetDevRegDone) { + //netif_carrier_off(dev->net); //mbelian + //netif_stop_queue(dev->net); + } info->ConTm = 0; } } @@ -1787,26 +1860,31 @@ int ft1000_poll(void* dev_id) { struct pseudo_hdr *ppseudo_hdr; unsigned long flags; + //DEBUG("Enter ft1000_poll...\n"); if (ft1000_chkcard(dev) == FALSE) { DEBUG("ft1000_poll::ft1000_chkcard: failed\n"); return STATUS_FAILURE; } status = ft1000_read_register (dev, &tempword, FT1000_REG_DOORBELL); + // DEBUG("ft1000_poll: read FT1000_REG_DOORBELL message 0x%x\n", tempword); if ( !status ) { if (tempword & FT1000_DB_DPRAM_RX) { + //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX\n"); status = ft1000_read_dpram16(dev, 0x200, (u8 *)&data, 0); - size = ntohs(data) + 16 + 2; + //DEBUG("ft1000_poll:FT1000_DB_DPRAM_RX:ft1000_read_dpram16:size = 0x%x\n", data); + size = ntohs(data) + 16 + 2; //wai if (size % 4) { modulo = 4 - (size % 4); size = size + modulo; } status = ft1000_read_dpram16(dev, 0x201, (u8 *)&portid, 1); portid &= 0xff; + //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid 0x%x\n", portid); if (size < MAX_CMD_SQSIZE) { switch (portid) @@ -1821,11 +1899,13 @@ int ft1000_poll(void* dev_id) { case DSPBCMSGID: // This is a dsp broadcast message // Check which application has registered for dsp broadcast messages + //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_DPRAM_RX : portid DSPBCMSGID\n"); for (i=0; iapp_info[i].DspBCMsgFlag) && (info->app_info[i].fileobject) && (info->app_info[i].NumOfMsg < MAX_MSG_LIMIT) ) { + //DEBUG("Dsp broadcast message detected for app id %d\n", i); nxtph = FT1000_DPRAM_RX_BASE + 2; pdpram_blk = ft1000_get_buffer (&freercvpool); if (pdpram_blk != NULL) { @@ -1849,13 +1929,15 @@ int ft1000_poll(void* dev_id) { else { DEBUG("Out of memory in free receive command pool\n"); info->app_info[i].nRxMsgMiss++; - } - } - } + }//endof if (pdpram_blk != NULL) + }//endof if + //else + // DEBUG("app_info mismatch\n"); + }// endof for break; default: pdpram_blk = ft1000_get_buffer (&freercvpool); - + //DEBUG("Memory allocated = 0x%8x\n", (u32)pdpram_blk); if (pdpram_blk != NULL) { if ( ft1000_receive_cmd(dev, pdpram_blk->pbuffer, MAX_CMD_SQSIZE, &nxtph) ) { ppseudo_hdr = (struct pseudo_hdr *)pdpram_blk->pbuffer; @@ -1879,8 +1961,11 @@ int ft1000_poll(void* dev_id) { else { info->app_info[i].nRxMsg++; // Put message into the appropriate application block + //pxu spin_lock_irqsave(&free_buff_lock, flags); list_add_tail(&pdpram_blk->list, &info->app_info[i].app_sqlist); info->app_info[i].NumOfMsg++; + //pxu spin_unlock_irqrestore(&free_buff_lock, flags); + //pxu wake_up_interruptible(&info->app_info[i].wait_dpram_msg); } } } @@ -1893,14 +1978,15 @@ int ft1000_poll(void* dev_id) { DEBUG("Out of memory in free receive command pool\n"); } break; - } - } + } //end of switch + } //endof if (size < MAX_CMD_SQSIZE) else { DEBUG("FT1000:dpc:Invalid total length for SlowQ = %d\n", size); } status = ft1000_write_register (dev, FT1000_DB_DPRAM_RX, FT1000_REG_DOORBELL); } else if (tempword & FT1000_DSP_ASIC_RESET) { + //DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DSP_ASIC_RESET\n"); // Let's reset the ASIC from the Host side as well status = ft1000_write_register (dev, ASIC_RESET_BIT, FT1000_REG_RESET); @@ -1939,8 +2025,10 @@ int ft1000_poll(void* dev_id) { } else if (tempword & FT1000_DB_COND_RESET) { DEBUG("ft1000_poll: FT1000_REG_DOORBELL message type: FT1000_DB_COND_RESET\n"); - - if (info->fAppMsgPend == 0) { +//By Jim +// Reset ASIC and DSP +//MAG + if (info->fAppMsgPend == 0) { // Reset ASIC and DSP status = ft1000_read_dpram16(dev, FT1000_MAG_DSP_TIMER0, (u8 *)&(info->DSP_TIME[0]), FT1000_MAG_DSP_TIMER0_INDX); @@ -1960,8 +2048,11 @@ int ft1000_poll(void* dev_id) { ft1000_write_register(dev, FT1000_DB_COND_RESET, FT1000_REG_DOORBELL); } - } + }//endof if ( !status ) + //DEBUG("return from ft1000_poll.\n"); return STATUS_SUCCESS; } + +/*end of Jim*/ diff --git a/trunk/drivers/staging/gma500/Kconfig b/trunk/drivers/staging/gma500/Kconfig index ce8bedaeaac2..5501eb9b3355 100644 --- a/trunk/drivers/staging/gma500/Kconfig +++ b/trunk/drivers/staging/gma500/Kconfig @@ -1,6 +1,6 @@ config DRM_PSB tristate "Intel GMA500 KMS Framebuffer" - depends on DRM && PCI && X86 + depends on DRM && PCI select FB_CFB_COPYAREA select FB_CFB_FILLRECT select FB_CFB_IMAGEBLIT diff --git a/trunk/drivers/staging/gma500/Makefile b/trunk/drivers/staging/gma500/Makefile index e00557e40a59..a52ba48be518 100644 --- a/trunk/drivers/staging/gma500/Makefile +++ b/trunk/drivers/staging/gma500/Makefile @@ -15,12 +15,17 @@ psb_gfx-y += psb_bl.o \ psb_intel_lvds.o \ psb_intel_modes.o \ psb_intel_sdvo.o \ - psb_lid.o \ + psb_reset.o \ + psb_sgx.o \ psb_pvr_glue.o \ + psb_buffer.o \ + psb_fence.o \ psb_mmu.o \ + psb_ttm_glue.o \ + psb_ttm_fence.o \ + psb_ttm_fence_user.o \ + psb_ttm_placement_user.o \ psb_powermgmt.o \ - psb_irq.o \ - mrst_crtc.o \ - mrst_lvds.o + psb_irq.o obj-$(CONFIG_DRM_PSB) += psb_gfx.o diff --git a/trunk/drivers/staging/gma500/mrst.h b/trunk/drivers/staging/gma500/mrst.h deleted file mode 100644 index 5e4aaeb3711b..000000000000 --- a/trunk/drivers/staging/gma500/mrst.h +++ /dev/null @@ -1,217 +0,0 @@ -/************************************************************************** - * Copyright (c) 2007-2011, Intel Corporation. - * All Rights Reserved. - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * - **************************************************************************/ - -/* MID device specific descriptors */ - -struct mrst_vbt { - s8 signature[4]; /*4 bytes,"$GCT" */ - u8 revision; - u8 size; - u8 checksum; - void *mrst_gct; -} __attribute__ ((packed)); - -struct mrst_timing_info { - u16 pixel_clock; - u8 hactive_lo; - u8 hblank_lo; - u8 hblank_hi:4; - u8 hactive_hi:4; - u8 vactive_lo; - u8 vblank_lo; - u8 vblank_hi:4; - u8 vactive_hi:4; - u8 hsync_offset_lo; - u8 hsync_pulse_width_lo; - u8 vsync_pulse_width_lo:4; - u8 vsync_offset_lo:4; - u8 vsync_pulse_width_hi:2; - u8 vsync_offset_hi:2; - u8 hsync_pulse_width_hi:2; - u8 hsync_offset_hi:2; - u8 width_mm_lo; - u8 height_mm_lo; - u8 height_mm_hi:4; - u8 width_mm_hi:4; - u8 hborder; - u8 vborder; - u8 unknown0:1; - u8 hsync_positive:1; - u8 vsync_positive:1; - u8 separate_sync:2; - u8 stereo:1; - u8 unknown6:1; - u8 interlaced:1; -} __attribute__((packed)); - -struct gct_r10_timing_info { - u16 pixel_clock; - u32 hactive_lo:8; - u32 hactive_hi:4; - u32 hblank_lo:8; - u32 hblank_hi:4; - u32 hsync_offset_lo:8; - u16 hsync_offset_hi:2; - u16 hsync_pulse_width_lo:8; - u16 hsync_pulse_width_hi:2; - u16 hsync_positive:1; - u16 rsvd_1:3; - u8 vactive_lo:8; - u16 vactive_hi:4; - u16 vblank_lo:8; - u16 vblank_hi:4; - u16 vsync_offset_lo:4; - u16 vsync_offset_hi:2; - u16 vsync_pulse_width_lo:4; - u16 vsync_pulse_width_hi:2; - u16 vsync_positive:1; - u16 rsvd_2:3; -} __attribute__((packed)); - -struct mrst_panel_descriptor_v1 { - u32 Panel_Port_Control; /* 1 dword, Register 0x61180 if LVDS */ - /* 0x61190 if MIPI */ - u32 Panel_Power_On_Sequencing;/*1 dword,Register 0x61208,*/ - u32 Panel_Power_Off_Sequencing;/*1 dword,Register 0x6120C,*/ - u32 Panel_Power_Cycle_Delay_and_Reference_Divisor;/* 1 dword */ - /* Register 0x61210 */ - struct mrst_timing_info DTD;/*18 bytes, Standard definition */ - u16 Panel_Backlight_Inverter_Descriptor;/* 16 bits, as follows */ - /* Bit 0, Frequency, 15 bits,0 - 32767Hz */ - /* Bit 15, Polarity, 1 bit, 0: Normal, 1: Inverted */ - u16 Panel_MIPI_Display_Descriptor; - /*16 bits, Defined as follows: */ - /* if MIPI, 0x0000 if LVDS */ - /* Bit 0, Type, 2 bits, */ - /* 0: Type-1, */ - /* 1: Type-2, */ - /* 2: Type-3, */ - /* 3: Type-4 */ - /* Bit 2, Pixel Format, 4 bits */ - /* Bit0: 16bpp (not supported in LNC), */ - /* Bit1: 18bpp loosely packed, */ - /* Bit2: 18bpp packed, */ - /* Bit3: 24bpp */ - /* Bit 6, Reserved, 2 bits, 00b */ - /* Bit 8, Minimum Supported Frame Rate, 6 bits, 0 - 63Hz */ - /* Bit 14, Reserved, 2 bits, 00b */ -} __attribute__ ((packed)); - -struct mrst_panel_descriptor_v2 { - u32 Panel_Port_Control; /* 1 dword, Register 0x61180 if LVDS */ - /* 0x61190 if MIPI */ - u32 Panel_Power_On_Sequencing;/*1 dword,Register 0x61208,*/ - u32 Panel_Power_Off_Sequencing;/*1 dword,Register 0x6120C,*/ - u8 Panel_Power_Cycle_Delay_and_Reference_Divisor;/* 1 byte */ - /* Register 0x61210 */ - struct mrst_timing_info DTD;/*18 bytes, Standard definition */ - u16 Panel_Backlight_Inverter_Descriptor;/*16 bits, as follows*/ - /*Bit 0, Frequency, 16 bits, 0 - 32767Hz*/ - u8 Panel_Initial_Brightness;/* [7:0] 0 - 100% */ - /*Bit 7, Polarity, 1 bit,0: Normal, 1: Inverted*/ - u16 Panel_MIPI_Display_Descriptor; - /*16 bits, Defined as follows: */ - /* if MIPI, 0x0000 if LVDS */ - /* Bit 0, Type, 2 bits, */ - /* 0: Type-1, */ - /* 1: Type-2, */ - /* 2: Type-3, */ - /* 3: Type-4 */ - /* Bit 2, Pixel Format, 4 bits */ - /* Bit0: 16bpp (not supported in LNC), */ - /* Bit1: 18bpp loosely packed, */ - /* Bit2: 18bpp packed, */ - /* Bit3: 24bpp */ - /* Bit 6, Reserved, 2 bits, 00b */ - /* Bit 8, Minimum Supported Frame Rate, 6 bits, 0 - 63Hz */ - /* Bit 14, Reserved, 2 bits, 00b */ -} __attribute__ ((packed)); - -union mrst_panel_rx { - struct{ - u16 NumberOfLanes:2; /*Num of Lanes, 2 bits,0 = 1 lane,*/ - /* 1 = 2 lanes, 2 = 3 lanes, 3 = 4 lanes. */ - u16 MaxLaneFreq:3; /* 0: 100MHz, 1: 200MHz, 2: 300MHz, */ - /*3: 400MHz, 4: 500MHz, 5: 600MHz, 6: 700MHz, 7: 800MHz.*/ - u16 SupportedVideoTransferMode:2; /*0: Non-burst only */ - /* 1: Burst and non-burst */ - /* 2/3: Reserved */ - u16 HSClkBehavior:1; /*0: Continuous, 1: Non-continuous*/ - u16 DuoDisplaySupport:1; /*1 bit,0: No, 1: Yes*/ - u16 ECC_ChecksumCapabilities:1;/*1 bit,0: No, 1: Yes*/ - u16 BidirectionalCommunication:1;/*1 bit,0: No, 1: Yes */ - u16 Rsvd:5;/*5 bits,00000b */ - } panelrx; - u16 panel_receiver; -} __attribute__ ((packed)); - -struct mrst_gct_v1 { - union{ /*8 bits,Defined as follows: */ - struct { - u8 PanelType:4; /*4 bits, Bit field for panels*/ - /* 0 - 3: 0 = LVDS, 1 = MIPI*/ - /*2 bits,Specifies which of the*/ - u8 BootPanelIndex:2; - /* 4 panels to use by default*/ - u8 BootMIPI_DSI_RxIndex:2;/*Specifies which of*/ - /* the 4 MIPI DSI receivers to use*/ - } PD; - u8 PanelDescriptor; - }; - struct mrst_panel_descriptor_v1 panel[4];/*panel descrs,38 bytes each*/ - union mrst_panel_rx panelrx[4]; /* panel receivers*/ -} __attribute__ ((packed)); - -struct mrst_gct_v2 { - union{ /*8 bits,Defined as follows: */ - struct { - u8 PanelType:4; /*4 bits, Bit field for panels*/ - /* 0 - 3: 0 = LVDS, 1 = MIPI*/ - /*2 bits,Specifies which of the*/ - u8 BootPanelIndex:2; - /* 4 panels to use by default*/ - u8 BootMIPI_DSI_RxIndex:2;/*Specifies which of*/ - /* the 4 MIPI DSI receivers to use*/ - } PD; - u8 PanelDescriptor; - }; - struct mrst_panel_descriptor_v2 panel[4];/*panel descrs,38 bytes each*/ - union mrst_panel_rx panelrx[4]; /* panel receivers*/ -} __attribute__ ((packed)); - -struct mrst_gct_data { - u8 bpi; /* boot panel index, number of panel used during boot */ - u8 pt; /* panel type, 4 bit field, 0=lvds, 1=mipi */ - struct mrst_timing_info DTD; /* timing info for the selected panel */ - u32 Panel_Port_Control; - u32 PP_On_Sequencing;/*1 dword,Register 0x61208,*/ - u32 PP_Off_Sequencing;/*1 dword,Register 0x6120C,*/ - u32 PP_Cycle_Delay; - u16 Panel_Backlight_Inverter_Descriptor; - u16 Panel_MIPI_Display_Descriptor; -} __attribute__ ((packed)); - -#define MODE_SETTING_IN_CRTC 0x1 -#define MODE_SETTING_IN_ENCODER 0x2 -#define MODE_SETTING_ON_GOING 0x3 -#define MODE_SETTING_IN_DSR 0x4 -#define MODE_SETTING_ENCODER_DONE 0x8 -#define GCT_R10_HEADER_SIZE 16 -#define GCT_R10_DISPLAY_DESC_SIZE 28 - diff --git a/trunk/drivers/staging/gma500/mrst_crtc.c b/trunk/drivers/staging/gma500/mrst_crtc.c deleted file mode 100644 index 664d0e7bbc18..000000000000 --- a/trunk/drivers/staging/gma500/mrst_crtc.c +++ /dev/null @@ -1,620 +0,0 @@ -/* - * Copyright © 2009 Intel Corporation - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include - -#include -#include "psb_fb.h" -#include "psb_drv.h" -#include "psb_intel_drv.h" -#include "psb_intel_reg.h" -#include "psb_intel_display.h" -#include "psb_powermgmt.h" - -struct psb_intel_range_t { - int min, max; -}; - -struct mrst_limit_t { - struct psb_intel_range_t dot, m, p1; -}; - -struct mrst_clock_t { - /* derived values */ - int dot; - int m; - int p1; -}; - -#define MRST_LIMIT_LVDS_100L 0 -#define MRST_LIMIT_LVDS_83 1 -#define MRST_LIMIT_LVDS_100 2 - -#define MRST_DOT_MIN 19750 -#define MRST_DOT_MAX 120000 -#define MRST_M_MIN_100L 20 -#define MRST_M_MIN_100 10 -#define MRST_M_MIN_83 12 -#define MRST_M_MAX_100L 34 -#define MRST_M_MAX_100 17 -#define MRST_M_MAX_83 20 -#define MRST_P1_MIN 2 -#define MRST_P1_MAX_0 7 -#define MRST_P1_MAX_1 8 - -static const struct mrst_limit_t mrst_limits[] = { - { /* MRST_LIMIT_LVDS_100L */ - .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX}, - .m = {.min = MRST_M_MIN_100L, .max = MRST_M_MAX_100L}, - .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_1}, - }, - { /* MRST_LIMIT_LVDS_83L */ - .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX}, - .m = {.min = MRST_M_MIN_83, .max = MRST_M_MAX_83}, - .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_0}, - }, - { /* MRST_LIMIT_LVDS_100 */ - .dot = {.min = MRST_DOT_MIN, .max = MRST_DOT_MAX}, - .m = {.min = MRST_M_MIN_100, .max = MRST_M_MAX_100}, - .p1 = {.min = MRST_P1_MIN, .max = MRST_P1_MAX_1}, - }, -}; - -#define MRST_M_MIN 10 -static const u32 mrst_m_converts[] = { - 0x2B, 0x15, 0x2A, 0x35, 0x1A, 0x0D, 0x26, 0x33, 0x19, 0x2C, - 0x36, 0x3B, 0x1D, 0x2E, 0x37, 0x1B, 0x2D, 0x16, 0x0B, 0x25, - 0x12, 0x09, 0x24, 0x32, 0x39, 0x1c, -}; - -static const struct mrst_limit_t *mrst_limit(struct drm_crtc *crtc) -{ - const struct mrst_limit_t *limit = NULL; - struct drm_device *dev = crtc->dev; - DRM_DRIVER_PRIVATE_T *dev_priv = dev->dev_private; - - if (psb_intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) - || psb_intel_pipe_has_type(crtc, INTEL_OUTPUT_MIPI)) { - switch (dev_priv->core_freq) { - case 100: - limit = &mrst_limits[MRST_LIMIT_LVDS_100L]; - break; - case 166: - limit = &mrst_limits[MRST_LIMIT_LVDS_83]; - break; - case 200: - limit = &mrst_limits[MRST_LIMIT_LVDS_100]; - break; - } - } else { - limit = NULL; - PSB_DEBUG_ENTRY("mrst_limit Wrong display type.\n"); - } - - return limit; -} - -/** Derive the pixel clock for the given refclk and divisors for 8xx chips. */ -static void mrst_clock(int refclk, struct mrst_clock_t *clock) -{ - clock->dot = (refclk * clock->m) / (14 * clock->p1); -} - -void mrstPrintPll(char *prefix, struct mrst_clock_t *clock) -{ - PSB_DEBUG_ENTRY("%s: dotclock = %d, m = %d, p1 = %d.\n", - prefix, clock->dot, clock->m, clock->p1); -} - -/** - * Returns a set of divisors for the desired target clock with the given refclk, - * or FALSE. Divisor values are the actual divisors for - */ -static bool -mrstFindBestPLL(struct drm_crtc *crtc, int target, int refclk, - struct mrst_clock_t *best_clock) -{ - struct mrst_clock_t clock; - const struct mrst_limit_t *limit = mrst_limit(crtc); - int err = target; - - memset(best_clock, 0, sizeof(*best_clock)); - - for (clock.m = limit->m.min; clock.m <= limit->m.max; clock.m++) { - for (clock.p1 = limit->p1.min; clock.p1 <= limit->p1.max; - clock.p1++) { - int this_err; - - mrst_clock(refclk, &clock); - - this_err = abs(clock.dot - target); - if (this_err < err) { - *best_clock = clock; - err = this_err; - } - } - } - DRM_DEBUG("mrstFindBestPLL err = %d.\n", err); - - return err != target; -} - -/** - * Sets the power management mode of the pipe and plane. - * - * This code should probably grow support for turning the cursor off and back - * on appropriately at the same time as we're turning the pipe off/on. - */ -static void mrst_crtc_dpms(struct drm_crtc *crtc, int mode) -{ - struct drm_device *dev = crtc->dev; - struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc); - int pipe = psb_intel_crtc->pipe; - int dpll_reg = (pipe == 0) ? MRST_DPLL_A : DPLL_B; - int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR; - int dspbase_reg = (pipe == 0) ? MRST_DSPABASE : DSPBBASE; - int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; - u32 temp; - bool enabled; - - PSB_DEBUG_ENTRY("mode = %d, pipe = %d\n", mode, pipe); - - if (!gma_power_begin(dev, true)) - return; - - /* XXX: When our outputs are all unaware of DPMS modes other than off - * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC. - */ - switch (mode) { - case DRM_MODE_DPMS_ON: - case DRM_MODE_DPMS_STANDBY: - case DRM_MODE_DPMS_SUSPEND: - /* Enable the DPLL */ - temp = REG_READ(dpll_reg); - if ((temp & DPLL_VCO_ENABLE) == 0) { - REG_WRITE(dpll_reg, temp); - REG_READ(dpll_reg); - /* Wait for the clocks to stabilize. */ - udelay(150); - REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE); - REG_READ(dpll_reg); - /* Wait for the clocks to stabilize. */ - udelay(150); - REG_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE); - REG_READ(dpll_reg); - /* Wait for the clocks to stabilize. */ - udelay(150); - } - /* Enable the pipe */ - temp = REG_READ(pipeconf_reg); - if ((temp & PIPEACONF_ENABLE) == 0) - REG_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE); - /* Enable the plane */ - temp = REG_READ(dspcntr_reg); - if ((temp & DISPLAY_PLANE_ENABLE) == 0) { - REG_WRITE(dspcntr_reg, - temp | DISPLAY_PLANE_ENABLE); - /* Flush the plane changes */ - REG_WRITE(dspbase_reg, REG_READ(dspbase_reg)); - } - - psb_intel_crtc_load_lut(crtc); - - /* Give the overlay scaler a chance to enable - if it's on this pipe */ - /* psb_intel_crtc_dpms_video(crtc, true); TODO */ - break; - case DRM_MODE_DPMS_OFF: - /* Give the overlay scaler a chance to disable - * if it's on this pipe */ - /* psb_intel_crtc_dpms_video(crtc, FALSE); TODO */ - - /* Disable the VGA plane that we never use */ - REG_WRITE(VGACNTRL, VGA_DISP_DISABLE); - /* Disable display plane */ - temp = REG_READ(dspcntr_reg); - if ((temp & DISPLAY_PLANE_ENABLE) != 0) { - REG_WRITE(dspcntr_reg, - temp & ~DISPLAY_PLANE_ENABLE); - /* Flush the plane changes */ - REG_WRITE(dspbase_reg, REG_READ(dspbase_reg)); - REG_READ(dspbase_reg); - } - - /* Next, disable display pipes */ - temp = REG_READ(pipeconf_reg); - if ((temp & PIPEACONF_ENABLE) != 0) { - REG_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE); - REG_READ(pipeconf_reg); - } - /* Wait for for the pipe disable to take effect. */ - psb_intel_wait_for_vblank(dev); - - temp = REG_READ(dpll_reg); - if ((temp & DPLL_VCO_ENABLE) != 0) { - REG_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE); - REG_READ(dpll_reg); - } - - /* Wait for the clocks to turn off. */ - udelay(150); - break; - } - - enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF; - - /*Set FIFO Watermarks*/ - REG_WRITE(DSPARB, 0x3FFF); - REG_WRITE(DSPFW1, 0x3F88080A); - REG_WRITE(DSPFW2, 0x0b060808); - REG_WRITE(DSPFW3, 0x0); - REG_WRITE(DSPFW4, 0x08030404); - REG_WRITE(DSPFW5, 0x04040404); - REG_WRITE(DSPFW6, 0x78); - REG_WRITE(0x70400, REG_READ(0x70400) | 0x4000); - /* Must write Bit 14 of the Chicken Bit Register */ - - gma_power_end(dev); -} - -/** - * Return the pipe currently connected to the panel fitter, - * or -1 if the panel fitter is not present or not in use - */ -static int mrst_panel_fitter_pipe(struct drm_device *dev) -{ - u32 pfit_control; - - pfit_control = REG_READ(PFIT_CONTROL); - - /* See if the panel fitter is in use */ - if ((pfit_control & PFIT_ENABLE) == 0) - return -1; - return (pfit_control >> 29) & 3; -} - -static int mrst_crtc_mode_set(struct drm_crtc *crtc, - struct drm_display_mode *mode, - struct drm_display_mode *adjusted_mode, - int x, int y, - struct drm_framebuffer *old_fb) -{ - struct drm_device *dev = crtc->dev; - struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc); - DRM_DRIVER_PRIVATE_T *dev_priv = dev->dev_private; - int pipe = psb_intel_crtc->pipe; - int fp_reg = (pipe == 0) ? MRST_FPA0 : FPB0; - int dpll_reg = (pipe == 0) ? MRST_DPLL_A : DPLL_B; - int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR; - int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF; - int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B; - int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B; - int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B; - int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B; - int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B; - int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B; - int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC; - int refclk = 0; - struct mrst_clock_t clock; - u32 dpll = 0, fp = 0, dspcntr, pipeconf; - bool ok, is_sdvo = false; - bool is_crt = false, is_lvds = false, is_tv = false; - bool is_mipi = false; - struct drm_mode_config *mode_config = &dev->mode_config; - struct psb_intel_output *psb_intel_output = NULL; - uint64_t scalingType = DRM_MODE_SCALE_FULLSCREEN; - struct drm_encoder *encoder; - - PSB_DEBUG_ENTRY("pipe = 0x%x\n", pipe); - - if (!gma_power_begin(dev, true)) - return 0; - - memcpy(&psb_intel_crtc->saved_mode, - mode, - sizeof(struct drm_display_mode)); - memcpy(&psb_intel_crtc->saved_adjusted_mode, - adjusted_mode, - sizeof(struct drm_display_mode)); - - list_for_each_entry(encoder, &mode_config->encoder_list, head) { - - if (encoder->crtc != crtc) - continue; - - psb_intel_output = enc_to_psb_intel_output(encoder); - switch (psb_intel_output->type) { - case INTEL_OUTPUT_LVDS: - is_lvds = true; - break; - case INTEL_OUTPUT_SDVO: - is_sdvo = true; - break; - case INTEL_OUTPUT_TVOUT: - is_tv = true; - break; - case INTEL_OUTPUT_ANALOG: - is_crt = true; - break; - case INTEL_OUTPUT_MIPI: - is_mipi = true; - break; - } - } - - /* Disable the VGA plane that we never use */ - REG_WRITE(VGACNTRL, VGA_DISP_DISABLE); - - /* Disable the panel fitter if it was on our pipe */ - if (mrst_panel_fitter_pipe(dev) == pipe) - REG_WRITE(PFIT_CONTROL, 0); - - REG_WRITE(pipesrc_reg, - ((mode->crtc_hdisplay - 1) << 16) | - (mode->crtc_vdisplay - 1)); - - if (psb_intel_output) - drm_connector_property_get_value(&psb_intel_output->base, - dev->mode_config.scaling_mode_property, &scalingType); - - if (scalingType == DRM_MODE_SCALE_NO_SCALE) { - /* Moorestown doesn't have register support for centering so - * we need to mess with the h/vblank and h/vsync start and - * ends to get centering */ - int offsetX = 0, offsetY = 0; - - offsetX = (adjusted_mode->crtc_hdisplay - - mode->crtc_hdisplay) / 2; - offsetY = (adjusted_mode->crtc_vdisplay - - mode->crtc_vdisplay) / 2; - - REG_WRITE(htot_reg, (mode->crtc_hdisplay - 1) | - ((adjusted_mode->crtc_htotal - 1) << 16)); - REG_WRITE(vtot_reg, (mode->crtc_vdisplay - 1) | - ((adjusted_mode->crtc_vtotal - 1) << 16)); - REG_WRITE(hblank_reg, - (adjusted_mode->crtc_hblank_start - offsetX - 1) | - ((adjusted_mode->crtc_hblank_end - offsetX - 1) << 16)); - REG_WRITE(hsync_reg, - (adjusted_mode->crtc_hsync_start - offsetX - 1) | - ((adjusted_mode->crtc_hsync_end - offsetX - 1) << 16)); - REG_WRITE(vblank_reg, - (adjusted_mode->crtc_vblank_start - offsetY - 1) | - ((adjusted_mode->crtc_vblank_end - offsetY - 1) << 16)); - REG_WRITE(vsync_reg, - (adjusted_mode->crtc_vsync_start - offsetY - 1) | - ((adjusted_mode->crtc_vsync_end - offsetY - 1) << 16)); - } else { - REG_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) | - ((adjusted_mode->crtc_htotal - 1) << 16)); - REG_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) | - ((adjusted_mode->crtc_vtotal - 1) << 16)); - REG_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) | - ((adjusted_mode->crtc_hblank_end - 1) << 16)); - REG_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) | - ((adjusted_mode->crtc_hsync_end - 1) << 16)); - REG_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) | - ((adjusted_mode->crtc_vblank_end - 1) << 16)); - REG_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) | - ((adjusted_mode->crtc_vsync_end - 1) << 16)); - } - - /* Flush the plane changes */ - { - struct drm_crtc_helper_funcs *crtc_funcs = - crtc->helper_private; - crtc_funcs->mode_set_base(crtc, x, y, old_fb); - } - - /* setup pipeconf */ - pipeconf = REG_READ(pipeconf_reg); - - /* Set up the display plane register */ - dspcntr = REG_READ(dspcntr_reg); - dspcntr |= DISPPLANE_GAMMA_ENABLE; - - if (pipe == 0) - dspcntr |= DISPPLANE_SEL_PIPE_A; - else - dspcntr |= DISPPLANE_SEL_PIPE_B; - - dev_priv->dspcntr = dspcntr |= DISPLAY_PLANE_ENABLE; - dev_priv->pipeconf = pipeconf |= PIPEACONF_ENABLE; - - if (is_mipi) - goto mrst_crtc_mode_set_exit; - - refclk = dev_priv->core_freq * 1000; - - dpll = 0; /*BIT16 = 0 for 100MHz reference */ - - ok = mrstFindBestPLL(crtc, adjusted_mode->clock, refclk, &clock); - - if (!ok) { - PSB_DEBUG_ENTRY( - "mrstFindBestPLL fail in mrst_crtc_mode_set.\n"); - } else { - PSB_DEBUG_ENTRY("mrst_crtc_mode_set pixel clock = %d," - "m = %x, p1 = %x.\n", clock.dot, clock.m, - clock.p1); - } - - fp = mrst_m_converts[(clock.m - MRST_M_MIN)] << 8; - - dpll |= DPLL_VGA_MODE_DIS; - - - dpll |= DPLL_VCO_ENABLE; - - if (is_lvds) - dpll |= DPLLA_MODE_LVDS; - else - dpll |= DPLLB_MODE_DAC_SERIAL; - - if (is_sdvo) { - int sdvo_pixel_multiply = - adjusted_mode->clock / mode->clock; - - dpll |= DPLL_DVO_HIGH_SPEED; - dpll |= - (sdvo_pixel_multiply - - 1) << SDVO_MULTIPLIER_SHIFT_HIRES; - } - - - /* compute bitmask from p1 value */ - dpll |= (1 << (clock.p1 - 2)) << 17; - - dpll |= DPLL_VCO_ENABLE; - - mrstPrintPll("chosen", &clock); - - if (dpll & DPLL_VCO_ENABLE) { - REG_WRITE(fp_reg, fp); - REG_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE); - REG_READ(dpll_reg); - /* Check the DPLLA lock bit PIPEACONF[29] */ - udelay(150); - } - - REG_WRITE(fp_reg, fp); - REG_WRITE(dpll_reg, dpll); - REG_READ(dpll_reg); - /* Wait for the clocks to stabilize. */ - udelay(150); - - /* write it again -- the BIOS does, after all */ - REG_WRITE(dpll_reg, dpll); - REG_READ(dpll_reg); - /* Wait for the clocks to stabilize. */ - udelay(150); - - REG_WRITE(pipeconf_reg, pipeconf); - REG_READ(pipeconf_reg); - psb_intel_wait_for_vblank(dev); - - REG_WRITE(dspcntr_reg, dspcntr); - psb_intel_wait_for_vblank(dev); - -mrst_crtc_mode_set_exit: - gma_power_end(dev); - return 0; -} - -static bool mrst_crtc_mode_fixup(struct drm_crtc *crtc, - struct drm_display_mode *mode, - struct drm_display_mode *adjusted_mode) -{ - return true; -} - -int mrst_pipe_set_base(struct drm_crtc *crtc, - int x, int y, struct drm_framebuffer *old_fb) -{ - struct drm_device *dev = crtc->dev; - /* struct drm_i915_master_private *master_priv; */ - struct psb_intel_crtc *psb_intel_crtc = to_psb_intel_crtc(crtc); - struct psb_framebuffer *psbfb = to_psb_fb(crtc->fb); - struct psb_intel_mode_device *mode_dev = psb_intel_crtc->mode_dev; - int pipe = psb_intel_crtc->pipe; - unsigned long Start, Offset; - /* FIXME: check if we need this surely MRST is pipe 0 only */ - int dspbase = (pipe == 0 ? DSPALINOFF : DSPBBASE); - int dspsurf = (pipe == 0 ? DSPASURF : DSPBSURF); - int dspstride = (pipe == 0) ? DSPASTRIDE : DSPBSTRIDE; - int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR; - u32 dspcntr; - int ret = 0; - - PSB_DEBUG_ENTRY("\n"); - - /* no fb bound */ - if (!crtc->fb) { - DRM_DEBUG("No FB bound\n"); - return 0; - } - - if (!gma_power_begin(dev, true)) - return 0; - - Start = mode_dev->bo_offset(dev, psbfb); - Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8); - - REG_WRITE(dspstride, crtc->fb->pitch); - - dspcntr = REG_READ(dspcntr_reg); - dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; - - switch (crtc->fb->bits_per_pixel) { - case 8: - dspcntr |= DISPPLANE_8BPP; - break; - case 16: - if (crtc->fb->depth == 15) - dspcntr |= DISPPLANE_15_16BPP; - else - dspcntr |= DISPPLANE_16BPP; - break; - case 24: - case 32: - dspcntr |= DISPPLANE_32BPP_NO_ALPHA; - break; - default: - DRM_ERROR("Unknown color depth\n"); - ret = -EINVAL; - goto pipe_set_base_exit; - } - REG_WRITE(dspcntr_reg, dspcntr); - - DRM_DEBUG("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y); - if (0 /* FIXMEAC - check what PSB needs */) { - REG_WRITE(dspbase, Offset); - REG_READ(dspbase); - REG_WRITE(dspsurf, Start); - REG_READ(dspsurf); - } else { - REG_WRITE(dspbase, Start + Offset); - REG_READ(dspbase); - } - -pipe_set_base_exit: - gma_power_end(dev); - return ret; -} - -static void mrst_crtc_prepare(struct drm_crtc *crtc) -{ - struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; - crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF); -} - -static void mrst_crtc_commit(struct drm_crtc *crtc) -{ - struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; - crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON); -} - -const struct drm_crtc_helper_funcs mrst_helper_funcs = { - .dpms = mrst_crtc_dpms, - .mode_fixup = mrst_crtc_mode_fixup, - .mode_set = mrst_crtc_mode_set, - .mode_set_base = mrst_pipe_set_base, - .prepare = mrst_crtc_prepare, - .commit = mrst_crtc_commit, -}; - diff --git a/trunk/drivers/staging/gma500/mrst_lvds.c b/trunk/drivers/staging/gma500/mrst_lvds.c deleted file mode 100644 index 4a08b74f5ff9..000000000000 --- a/trunk/drivers/staging/gma500/mrst_lvds.c +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright © 2006-2009 Intel Corporation - * - * This program is free software; you can redistribute it and/or modify it - * under the terms and conditions of the GNU General Public License, - * version 2, as published by the Free Software Foundation. - * - * This program is distributed in the hope it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. - * - * Authors: - * Eric Anholt - * Dave Airlie - * Jesse Barnes - */ - -#include -#include -#include - -#include "psb_intel_bios.h" -#include "psb_drv.h" -#include "psb_intel_drv.h" -#include "psb_intel_reg.h" -#include "psb_powermgmt.h" -#include - -/* The max/min PWM frequency in BPCR[31:17] - */ -/* The smallest number is 1 (not 0) that can fit in the - * 15-bit field of the and then*/ -/* shifts to the left by one bit to get the actual 16-bit - * value that the 15-bits correspond to.*/ -#define MRST_BLC_MAX_PWM_REG_FREQ 0xFFFF -#define BRIGHTNESS_MAX_LEVEL 100 - -/** - * Sets the power state for the panel. - */ -static void mrst_lvds_set_power(struct drm_device *dev, - struct psb_intel_output *output, bool on) -{ - u32 pp_status; - DRM_DRIVER_PRIVATE_T *dev_priv = dev->dev_private; - PSB_DEBUG_ENTRY("\n"); - - if (!gma_power_begin(dev, true)) - return; - - if (on) { - REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) | - POWER_TARGET_ON); - do { - pp_status = REG_READ(PP_STATUS); - } while ((pp_status & (PP_ON | PP_READY)) == PP_READY); - dev_priv->is_lvds_on = true; - } else { - REG_WRITE(PP_CONTROL, REG_READ(PP_CONTROL) & - ~POWER_TARGET_ON); - do { - pp_status = REG_READ(PP_STATUS); - } while (pp_status & PP_ON); - dev_priv->is_lvds_on = false; - pm_request_idle(&dev->pdev->dev); - } - - gma_power_end(dev); -} - -static void mrst_lvds_dpms(struct drm_encoder *encoder, int mode) -{ - struct drm_device *dev = encoder->dev; - struct psb_intel_output *output = enc_to_psb_intel_output(encoder); - - PSB_DEBUG_ENTRY("\n"); - - if (mode == DRM_MODE_DPMS_ON) - mrst_lvds_set_power(dev, output, true); - else - mrst_lvds_set_power(dev, output, false); - - /* XXX: We never power down the LVDS pairs. */ -} - -static void mrst_lvds_mode_set(struct drm_encoder *encoder, - struct drm_display_mode *mode, - struct drm_display_mode *adjusted_mode) -{ - struct psb_intel_mode_device *mode_dev = - enc_to_psb_intel_output(encoder)->mode_dev; - struct drm_device *dev = encoder->dev; - u32 lvds_port; - uint64_t v = DRM_MODE_SCALE_FULLSCREEN; - - PSB_DEBUG_ENTRY("\n"); - - if (!gma_power_begin(dev, true)) - return; - - /* - * The LVDS pin pair will already have been turned on in the - * psb_intel_crtc_mode_set since it has a large impact on the DPLL - * settings. - */ - lvds_port = (REG_READ(LVDS) & - (~LVDS_PIPEB_SELECT)) | - LVDS_PORT_EN | - LVDS_BORDER_EN; - - if (mode_dev->panel_wants_dither) - lvds_port |= MRST_PANEL_8TO6_DITHER_ENABLE; - - REG_WRITE(LVDS, lvds_port); - - drm_connector_property_get_value( - &enc_to_psb_intel_output(encoder)->base, - dev->mode_config.scaling_mode_property, - &v); - - if (v == DRM_MODE_SCALE_NO_SCALE) - REG_WRITE(PFIT_CONTROL, 0); - else if (v == DRM_MODE_SCALE_ASPECT) { - if ((mode->vdisplay != adjusted_mode->crtc_vdisplay) || - (mode->hdisplay != adjusted_mode->crtc_hdisplay)) { - if ((adjusted_mode->crtc_hdisplay * mode->vdisplay) == - (mode->hdisplay * adjusted_mode->crtc_vdisplay)) - REG_WRITE(PFIT_CONTROL, PFIT_ENABLE); - else if ((adjusted_mode->crtc_hdisplay * - mode->vdisplay) > (mode->hdisplay * - adjusted_mode->crtc_vdisplay)) - REG_WRITE(PFIT_CONTROL, PFIT_ENABLE | - PFIT_SCALING_MODE_PILLARBOX); - else - REG_WRITE(PFIT_CONTROL, PFIT_ENABLE | - PFIT_SCALING_MODE_LETTERBOX); - } else - REG_WRITE(PFIT_CONTROL, PFIT_ENABLE); - } else /*(v == DRM_MODE_SCALE_FULLSCREEN)*/ - REG_WRITE(PFIT_CONTROL, PFIT_ENABLE); - - gma_power_end(dev); -} - - -static const struct drm_encoder_helper_funcs mrst_lvds_helper_funcs = { - .dpms = mrst_lvds_dpms, - .mode_fixup = psb_intel_lvds_mode_fixup, - .prepare = psb_intel_lvds_prepare, - .mode_set = mrst_lvds_mode_set, - .commit = psb_intel_lvds_commit, -}; - -static struct drm_display_mode lvds_configuration_modes[] = { - /* hard coded fixed mode for TPO LTPS LPJ040K001A */ - { DRM_MODE("800x480", DRM_MODE_TYPE_DRIVER, 33264, 800, 836, - 846, 1056, 0, 480, 489, 491, 525, 0, 0) }, - /* hard coded fixed mode for LVDS 800x480 */ - { DRM_MODE("800x480", DRM_MODE_TYPE_DRIVER, 30994, 800, 801, - 802, 1024, 0, 480, 481, 482, 525, 0, 0) }, - /* hard coded fixed mode for Samsung 480wsvga LVDS 1024x600@75 */ - { DRM_MODE("1024x600", DRM_MODE_TYPE_DRIVER, 53990, 1024, 1072, - 1104, 1184, 0, 600, 603, 604, 608, 0, 0) }, - /* hard coded fixed mode for Samsung 480wsvga LVDS 1024x600@75 */ - { DRM_MODE("1024x600", DRM_MODE_TYPE_DRIVER, 53990, 1024, 1104, - 1136, 1184, 0, 600, 603, 604, 608, 0, 0) }, - /* hard coded fixed mode for Sharp wsvga LVDS 1024x600 */ - { DRM_MODE("1024x600", DRM_MODE_TYPE_DRIVER, 48885, 1024, 1124, - 1204, 1312, 0, 600, 607, 610, 621, 0, 0) }, - /* hard coded fixed mode for LVDS 1024x768 */ - { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 65000, 1024, 1048, - 1184, 1344, 0, 768, 771, 777, 806, 0, 0) }, - /* hard coded fixed mode for LVDS 1366x768 */ - { DRM_MODE("1366x768", DRM_MODE_TYPE_DRIVER, 77500, 1366, 1430, - 1558, 1664, 0, 768, 769, 770, 776, 0, 0) }, -}; - -/* Returns the panel fixed mode from configuration. */ - -static struct drm_display_mode * -mrst_lvds_get_configuration_mode(struct drm_device *dev) -{ - struct drm_display_mode *mode = NULL; - struct drm_psb_private *dev_priv = dev->dev_private; - struct mrst_timing_info *ti = &dev_priv->gct_data.DTD; - - if (dev_priv->vbt_data.size != 0x00) { /*if non-zero, then use vbt*/ - mode = kzalloc(sizeof(*mode), GFP_KERNEL); - if (!mode) - return NULL; - - mode->hdisplay = (ti->hactive_hi << 8) | ti->hactive_lo; - mode->vdisplay = (ti->vactive_hi << 8) | ti->vactive_lo; - mode->hsync_start = mode->hdisplay + \ - ((ti->hsync_offset_hi << 8) | \ - ti->hsync_offset_lo); - mode->hsync_end = mode->hsync_start + \ - ((ti->hsync_pulse_width_hi << 8) | \ - ti->hsync_pulse_width_lo); - mode->htotal = mode->hdisplay + ((ti->hblank_hi << 8) | \ - ti->hblank_lo); - mode->vsync_start = \ - mode->vdisplay + ((ti->vsync_offset_hi << 4) | \ - ti->vsync_offset_lo); - mode->vsync_end = \ - mode->vsync_start + ((ti->vsync_pulse_width_hi << 4) | \ - ti->vsync_pulse_width_lo); - mode->vtotal = mode->vdisplay + \ - ((ti->vblank_hi << 8) | ti->vblank_lo); - mode->clock = ti->pixel_clock * 10; -#if 0 - printk(KERN_INFO "hdisplay is %d\n", mode->hdisplay); - printk(KERN_INFO "vdisplay is %d\n", mode->vdisplay); - printk(KERN_INFO "HSS is %d\n", mode->hsync_start); - printk(KERN_INFO "HSE is %d\n", mode->hsync_end); - printk(KERN_INFO "htotal is %d\n", mode->htotal); - printk(KERN_INFO "VSS is %d\n", mode->vsync_start); - printk(KERN_INFO "VSE is %d\n", mode->vsync_end); - printk(KERN_INFO "vtotal is %d\n", mode->vtotal); - printk(KERN_INFO "clock is %d\n", mode->clock); -#endif - } else - mode = drm_mode_duplicate(dev, &lvds_configuration_modes[2]); - - drm_mode_set_name(mode); - drm_mode_set_crtcinfo(mode, 0); - - return mode; -} - -/** - * mrst_lvds_init - setup LVDS connectors on this device - * @dev: drm device - * - * Create the connector, register the LVDS DDC bus, and try to figure out what - * modes we can display on the LVDS panel (if present). - */ -void mrst_lvds_init(struct drm_device *dev, - struct psb_intel_mode_device *mode_dev) -{ - struct psb_intel_output *psb_intel_output; - struct drm_connector *connector; - struct drm_encoder *encoder; - struct drm_psb_private *dev_priv = - (struct drm_psb_private *) dev->dev_private; - struct edid *edid; - int ret = 0; - struct i2c_adapter *i2c_adap; - struct drm_display_mode *scan; /* *modes, *bios_mode; */ - - PSB_DEBUG_ENTRY("\n"); - - psb_intel_output = kzalloc(sizeof(struct psb_intel_output), GFP_KERNEL); - if (!psb_intel_output) - return; - - psb_intel_output->mode_dev = mode_dev; - connector = &psb_intel_output->base; - encoder = &psb_intel_output->enc; - dev_priv->is_lvds_on = true; - drm_connector_init(dev, &psb_intel_output->base, - &psb_intel_lvds_connector_funcs, - DRM_MODE_CONNECTOR_LVDS); - - drm_encoder_init(dev, &psb_intel_output->enc, &psb_intel_lvds_enc_funcs, - DRM_MODE_ENCODER_LVDS); - - drm_mode_connector_attach_encoder(&psb_intel_output->base, - &psb_intel_output->enc); - psb_intel_output->type = INTEL_OUTPUT_LVDS; - - drm_encoder_helper_add(encoder, &mrst_lvds_helper_funcs); - drm_connector_helper_add(connector, - &psb_intel_lvds_connector_helper_funcs); - connector->display_info.subpixel_order = SubPixelHorizontalRGB; - connector->interlace_allowed = false; - connector->doublescan_allowed = false; - - drm_connector_attach_property(connector, - dev->mode_config.scaling_mode_property, - DRM_MODE_SCALE_FULLSCREEN); - drm_connector_attach_property(connector, - dev_priv->backlight_property, - BRIGHTNESS_MAX_LEVEL); - - mode_dev->panel_wants_dither = false; - if (dev_priv->vbt_data.size != 0x00) - mode_dev->panel_wants_dither = (dev_priv->gct_data. - Panel_Port_Control & MRST_PANEL_8TO6_DITHER_ENABLE); - - /* - * LVDS discovery: - * 1) check for EDID on DDC - * 2) check for VBT data - * 3) check to see if LVDS is already on - * if none of the above, no panel - * 4) make sure lid is open - * if closed, act like it's not there for now - */ - - /* This ifdef can go once the cpu ident stuff is cleaned up in arch */ -#if defined(CONFIG_X86_MRST) - if (mrst_identify_cpu()) - i2c_adap = i2c_get_adapter(2); - else /* Oaktrail uses I2C 1 */ -#endif - i2c_adap = i2c_get_adapter(1); - - if (i2c_adap == NULL) - printk(KERN_ALERT "No ddc adapter available!\n"); - /* - * Attempt to get the fixed panel mode from DDC. Assume that the - * preferred mode is the right one. - */ - if (i2c_adap) { - edid = drm_get_edid(connector, i2c_adap); - if (edid) { - drm_mode_connector_update_edid_property(connector, - edid); - ret = drm_add_edid_modes(connector, edid); - kfree(edid); - } - - list_for_each_entry(scan, &connector->probed_modes, head) { - if (scan->type & DRM_MODE_TYPE_PREFERRED) { - mode_dev->panel_fixed_mode = - drm_mode_duplicate(dev, scan); - goto out; /* FIXME: check for quirks */ - } - } - } - - /* - * If we didn't get EDID, try geting panel timing - * from configuration data - */ - mode_dev->panel_fixed_mode = mrst_lvds_get_configuration_mode(dev); - - if (mode_dev->panel_fixed_mode) { - mode_dev->panel_fixed_mode->type |= - DRM_MODE_TYPE_PREFERRED; - goto out; /* FIXME: check for quirks */ - } - - /* If we still don't have a mode after all that, give up. */ - if (!mode_dev->panel_fixed_mode) { - DRM_DEBUG - ("Found no modes on the lvds, ignoring the LVDS\n"); - goto failed_find; - } - -out: - drm_sysfs_connector_add(connector); - return; - -failed_find: - DRM_DEBUG("No LVDS modes found, disabling.\n"); - if (psb_intel_output->ddc_bus) - psb_intel_i2c_destroy(psb_intel_output->ddc_bus); - -/* failed_ddc: */ - - drm_encoder_cleanup(encoder); - drm_connector_cleanup(connector); - kfree(connector); -} - diff --git a/trunk/drivers/staging/gma500/psb_2d.c b/trunk/drivers/staging/gma500/psb_2d.c index 29959ded78fc..e4cae5d77d01 100644 --- a/trunk/drivers/staging/gma500/psb_2d.c +++ b/trunk/drivers/staging/gma500/psb_2d.c @@ -40,6 +40,7 @@ #include "psb_reg.h" #include "psb_drv.h" #include "psb_fb.h" +#include "psb_sgx.h" void psb_spank(struct drm_psb_private *dev_priv) { @@ -84,7 +85,7 @@ static int psb_2d_wait_available(struct drm_psb_private *dev_priv, /* FIXME: Remember if we expose the 2D engine to the DRM we need to serialize it with console use */ -int psbfb_2d_submit(struct drm_psb_private *dev_priv, uint32_t *cmdbuf, +static int psbfb_2d_submit(struct drm_psb_private *dev_priv, uint32_t *cmdbuf, unsigned size) { int ret = 0; @@ -343,7 +344,7 @@ void psbfb_copyarea(struct fb_info *info, if (unlikely(info->state != FBINFO_STATE_RUNNING)) return; - if (info->flags & FBINFO_HWACCEL_DISABLED) + if (1 || (info->flags & FBINFO_HWACCEL_DISABLED)) return cfb_copyarea(info, region); /* psb_check_power_state(dev, PSB_DEVICE_SGX); */ diff --git a/trunk/drivers/staging/gma500/psb_bl.c b/trunk/drivers/staging/gma500/psb_bl.c index 57b9a5e5e7b3..70c17b352f9f 100644 --- a/trunk/drivers/staging/gma500/psb_bl.c +++ b/trunk/drivers/staging/gma500/psb_bl.c @@ -33,6 +33,7 @@ #define BLC_PWM_FREQ_CALC_CONSTANT 32 #define MHz 1000000 #define BRIGHTNESS_MIN_LEVEL 1 +#define BRIGHTNESS_MAX_LEVEL 100 #define BRIGHTNESS_MASK 0xFF #define BLC_POLARITY_NORMAL 0 #define BLC_POLARITY_INVERSE 1 @@ -58,57 +59,15 @@ int psb_set_brightness(struct backlight_device *bd) DRM_DEBUG_DRIVER("backlight level set to %d\n", level); - /* Percentage 1-100% being valid */ - if (level < 1) - level = 1; + /* Perform value bounds checking */ + if (level < BRIGHTNESS_MIN_LEVEL) + level = BRIGHTNESS_MIN_LEVEL; psb_intel_lvds_set_brightness(dev, level); psb_brightness = level; return 0; } -int mrst_set_brightness(struct backlight_device *bd) -{ - struct drm_device *dev = bl_get_data(psb_backlight_device); - struct drm_psb_private *dev_priv = dev->dev_private; - int level = bd->props.brightness; - u32 blc_pwm_ctl; - u32 max_pwm_blc; - - DRM_DEBUG_DRIVER("backlight level set to %d\n", level); - - /* Percentage 1-100% being valid */ - if (level < 1) - level = 1; - - if (gma_power_begin(dev, 0)) { - /* Calculate and set the brightness value */ - max_pwm_blc = REG_READ(BLC_PWM_CTL) >> 16; - blc_pwm_ctl = level * max_pwm_blc / 100; - - /* Adjust the backlight level with the percent in - * dev_priv->blc_adj1; - */ - blc_pwm_ctl = blc_pwm_ctl * dev_priv->blc_adj1; - blc_pwm_ctl = blc_pwm_ctl / 100; - - /* Adjust the backlight level with the percent in - * dev_priv->blc_adj2; - */ - blc_pwm_ctl = blc_pwm_ctl * dev_priv->blc_adj2; - blc_pwm_ctl = blc_pwm_ctl / 100; - - if (blc_pol == BLC_POLARITY_INVERSE) - blc_pwm_ctl = max_pwm_blc - blc_pwm_ctl; - /* force PWM bit on */ - REG_WRITE(BLC_PWM_CTL2, (0x80000000 | REG_READ(BLC_PWM_CTL2))); - REG_WRITE(BLC_PWM_CTL, (max_pwm_blc << 16) | blc_pwm_ctl); - gma_power_end(dev); - } - psb_brightness = level; - return 0; -} - int psb_get_brightness(struct backlight_device *bd) { DRM_DEBUG_DRIVER("brightness = 0x%x\n", psb_brightness); @@ -126,33 +85,24 @@ static const struct backlight_ops psb_ops = { static int device_backlight_init(struct drm_device *dev) { - struct drm_psb_private *dev_priv = dev->dev_private; unsigned long core_clock; /* u32 bl_max_freq; */ /* unsigned long value; */ u16 bl_max_freq; uint32_t value; uint32_t blc_pwm_precision_factor; + struct drm_psb_private *dev_priv = dev->dev_private; - if (IS_MRST(dev)) { - dev_priv->blc_adj1 = BLC_ADJUSTMENT_MAX; - dev_priv->blc_adj2 = BLC_ADJUSTMENT_MAX; - bl_max_freq = 256; - /* this needs to be set elsewhere */ - blc_pol = BLC_POLARITY_NORMAL; - blc_pwm_precision_factor = BLC_PWM_PRECISION_FACTOR; - } else { - /* get bl_max_freq and pol from dev_priv*/ - if (!dev_priv->lvds_bl) { - DRM_ERROR("Has no valid LVDS backlight info\n"); - return 1; - } - bl_max_freq = dev_priv->lvds_bl->freq; - blc_pol = dev_priv->lvds_bl->pol; - blc_pwm_precision_factor = PSB_BLC_PWM_PRECISION_FACTOR; - blc_brightnesscmd = dev_priv->lvds_bl->brightnesscmd; - blc_type = dev_priv->lvds_bl->type; + /* get bl_max_freq and pol from dev_priv*/ + if (!dev_priv->lvds_bl) { + DRM_ERROR("Has no valid LVDS backlight info\n"); + return 1; } + bl_max_freq = dev_priv->lvds_bl->freq; + blc_pol = dev_priv->lvds_bl->pol; + blc_pwm_precision_factor = PSB_BLC_PWM_PRECISION_FACTOR; + blc_brightnesscmd = dev_priv->lvds_bl->brightnesscmd; + blc_type = dev_priv->lvds_bl->type; core_clock = dev_priv->core_freq; @@ -161,27 +111,20 @@ static int device_backlight_init(struct drm_device *dev) value /= bl_max_freq; value /= blc_pwm_precision_factor; - if (gma_power_begin(dev, false)) { - if (IS_MRST(dev)) { - if (value > (unsigned long long)MRST_BLC_MAX_PWM_REG_FREQ) - return 2; - else { - REG_WRITE(BLC_PWM_CTL2, - (0x80000000 | REG_READ(BLC_PWM_CTL2))); - REG_WRITE(BLC_PWM_CTL, value | (value << 16)); - } - } else { - if (value > (unsigned long long)PSB_BLC_MAX_PWM_REG_FREQ || - value < (unsigned long long)PSB_BLC_MIN_PWM_REG_FREQ) - return 2; - else { - value &= PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR; - REG_WRITE(BLC_PWM_CTL, - (value << PSB_BACKLIGHT_PWM_CTL_SHIFT) | - (value)); - } + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { + /* Check: may be MFLD only */ + if ( + value > (unsigned long long)PSB_BLC_MAX_PWM_REG_FREQ || + value < (unsigned long long)PSB_BLC_MIN_PWM_REG_FREQ) + return 2; + else { + value &= PSB_BACKLIGHT_PWM_POLARITY_BIT_CLEAR; + REG_WRITE(BLC_PWM_CTL, + (value << PSB_BACKLIGHT_PWM_CTL_SHIFT) | + (value)); } - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } return 0; } @@ -193,7 +136,7 @@ int psb_backlight_init(struct drm_device *dev) struct backlight_properties props; memset(&props, 0, sizeof(struct backlight_properties)); - props.max_brightness = 100; + props.max_brightness = BRIGHTNESS_MAX_LEVEL; psb_backlight_device = backlight_device_register("psb-bl", NULL, (void *)dev, &psb_ops, &props); @@ -204,8 +147,8 @@ int psb_backlight_init(struct drm_device *dev) if (ret < 0) return ret; - psb_backlight_device->props.brightness = 100; - psb_backlight_device->props.max_brightness = 100; + psb_backlight_device->props.brightness = BRIGHTNESS_MAX_LEVEL; + psb_backlight_device->props.max_brightness = BRIGHTNESS_MAX_LEVEL; backlight_update_status(psb_backlight_device); #endif return 0; diff --git a/trunk/drivers/staging/gma500/psb_buffer.c b/trunk/drivers/staging/gma500/psb_buffer.c new file mode 100644 index 000000000000..3077f6a7b7dc --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_buffer.c @@ -0,0 +1,450 @@ +/************************************************************************** + * Copyright (c) 2007, Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ +/* + * Authors: Thomas Hellstrom + */ +#include "ttm/ttm_placement.h" +#include "ttm/ttm_execbuf_util.h" +#include "psb_ttm_fence_api.h" +#include +#include "psb_drv.h" + +#define DRM_MEM_TTM 26 + +struct drm_psb_ttm_backend { + struct ttm_backend base; + struct page **pages; + unsigned int desired_tile_stride; + unsigned int hw_tile_stride; + int mem_type; + unsigned long offset; + unsigned long num_pages; +}; + +/* + * MSVDX/TOPAZ GPU virtual space looks like this + * (We currently use only one MMU context). + * PSB_MEM_MMU_START: from 0x00000000~0xe000000, for generic buffers + * TTM_PL_CI: from 0xe0000000+half GTT space, for camear/video buffer sharing + * TTM_PL_RAR: from TTM_PL_CI+CI size, for RAR/video buffer sharing + * TTM_PL_TT: from TTM_PL_RAR+RAR size, for buffers need to mapping into GTT + */ +static int psb_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, + struct ttm_mem_type_manager *man) +{ + + struct drm_psb_private *dev_priv = + container_of(bdev, struct drm_psb_private, bdev); + struct psb_gtt *pg = dev_priv->pg; + + switch (type) { + case TTM_PL_SYSTEM: + man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; + man->available_caching = TTM_PL_FLAG_CACHED | + TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC; + man->default_caching = TTM_PL_FLAG_CACHED; + break; + case DRM_PSB_MEM_MMU: + man->func = &ttm_bo_manager_func; + man->flags = TTM_MEMTYPE_FLAG_MAPPABLE | + TTM_MEMTYPE_FLAG_CMA; + man->gpu_offset = PSB_MEM_MMU_START; + man->available_caching = TTM_PL_FLAG_CACHED | + TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC; + man->default_caching = TTM_PL_FLAG_WC; + break; + case TTM_PL_CI: + man->func = &ttm_bo_manager_func; + man->flags = TTM_MEMTYPE_FLAG_MAPPABLE | + TTM_MEMTYPE_FLAG_FIXED; + man->gpu_offset = pg->mmu_gatt_start + (pg->ci_start); + man->available_caching = TTM_PL_FLAG_UNCACHED; + man->default_caching = TTM_PL_FLAG_UNCACHED; + break; + case TTM_PL_RAR: /* Unmappable RAR memory */ + man->func = &ttm_bo_manager_func; + man->flags = TTM_MEMTYPE_FLAG_MAPPABLE | + TTM_MEMTYPE_FLAG_FIXED; + man->available_caching = TTM_PL_FLAG_UNCACHED; + man->default_caching = TTM_PL_FLAG_UNCACHED; + man->gpu_offset = pg->mmu_gatt_start + (pg->rar_start); + break; + case TTM_PL_TT: /* Mappable GATT memory */ + man->func = &ttm_bo_manager_func; +#ifdef PSB_WORKING_HOST_MMU_ACCESS + man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; +#else + man->flags = TTM_MEMTYPE_FLAG_MAPPABLE | + TTM_MEMTYPE_FLAG_CMA; +#endif + man->available_caching = TTM_PL_FLAG_CACHED | + TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC; + man->default_caching = TTM_PL_FLAG_WC; + man->gpu_offset = pg->mmu_gatt_start + + (pg->rar_start + dev_priv->rar_region_size); + break; + default: + DRM_ERROR("Unsupported memory type %u\n", (unsigned) type); + return -EINVAL; + } + return 0; +} + + +static void psb_evict_mask(struct ttm_buffer_object *bo, + struct ttm_placement *placement) +{ + static uint32_t cur_placement; + + cur_placement = bo->mem.placement & ~TTM_PL_MASK_MEM; + cur_placement |= TTM_PL_FLAG_SYSTEM; + + placement->fpfn = 0; + placement->lpfn = 0; + placement->num_placement = 1; + placement->placement = &cur_placement; + placement->num_busy_placement = 0; + placement->busy_placement = NULL; + + /* all buffers evicted to system memory */ + /* return cur_placement | TTM_PL_FLAG_SYSTEM; */ +} + +static int psb_invalidate_caches(struct ttm_bo_device *bdev, + uint32_t placement) +{ + return 0; +} + +static int psb_move_blit(struct ttm_buffer_object *bo, + bool evict, bool no_wait, + struct ttm_mem_reg *new_mem) +{ + BUG(); + return 0; +} + +/* + * Flip destination ttm into GATT, + * then blit and subsequently move out again. + */ + +static int psb_move_flip(struct ttm_buffer_object *bo, + bool evict, bool interruptible, bool no_wait, + struct ttm_mem_reg *new_mem) +{ + /*struct ttm_bo_device *bdev = bo->bdev;*/ + struct ttm_mem_reg tmp_mem; + int ret; + struct ttm_placement placement; + uint32_t flags = TTM_PL_FLAG_TT; + + tmp_mem = *new_mem; + tmp_mem.mm_node = NULL; + + placement.fpfn = 0; + placement.lpfn = 0; + placement.num_placement = 1; + placement.placement = &flags; + placement.num_busy_placement = 0; /* FIXME */ + placement.busy_placement = NULL; + + ret = ttm_bo_mem_space(bo, &placement, &tmp_mem, interruptible, + false, no_wait); + if (ret) + return ret; + ret = ttm_tt_bind(bo->ttm, &tmp_mem); + if (ret) + goto out_cleanup; + ret = psb_move_blit(bo, true, no_wait, &tmp_mem); + if (ret) + goto out_cleanup; + + ret = ttm_bo_move_ttm(bo, evict, false, no_wait, new_mem); +out_cleanup: + if (tmp_mem.mm_node) { + drm_mm_put_block(tmp_mem.mm_node); + tmp_mem.mm_node = NULL; + } + return ret; +} + +static int psb_move(struct ttm_buffer_object *bo, + bool evict, bool interruptible, bool no_wait_reserve, + bool no_wait, struct ttm_mem_reg *new_mem) +{ + struct ttm_mem_reg *old_mem = &bo->mem; + + if ((old_mem->mem_type == TTM_PL_RAR) || + (new_mem->mem_type == TTM_PL_RAR)) { + if (old_mem->mm_node) { + spin_lock(&bo->glob->lru_lock); + drm_mm_put_block(old_mem->mm_node); + spin_unlock(&bo->glob->lru_lock); + } + old_mem->mm_node = NULL; + *old_mem = *new_mem; + } else if (old_mem->mem_type == TTM_PL_SYSTEM) { + return ttm_bo_move_memcpy(bo, evict, false, no_wait, new_mem); + } else if (new_mem->mem_type == TTM_PL_SYSTEM) { + int ret = psb_move_flip(bo, evict, interruptible, + no_wait, new_mem); + if (unlikely(ret != 0)) { + if (ret == -ERESTART) + return ret; + else + return ttm_bo_move_memcpy(bo, evict, false, + no_wait, new_mem); + } + } else { + if (psb_move_blit(bo, evict, no_wait, new_mem)) + return ttm_bo_move_memcpy(bo, evict, false, no_wait, + new_mem); + } + return 0; +} + +static int drm_psb_tbe_populate(struct ttm_backend *backend, + unsigned long num_pages, + struct page **pages, + struct page *dummy_read_page, + dma_addr_t *dma_addrs) +{ + struct drm_psb_ttm_backend *psb_be = + container_of(backend, struct drm_psb_ttm_backend, base); + + psb_be->pages = pages; + return 0; +} + +static int drm_psb_tbe_unbind(struct ttm_backend *backend) +{ + struct ttm_bo_device *bdev = backend->bdev; + struct drm_psb_private *dev_priv = + container_of(bdev, struct drm_psb_private, bdev); + struct drm_psb_ttm_backend *psb_be = + container_of(backend, struct drm_psb_ttm_backend, base); + struct psb_mmu_pd *pd = psb_mmu_get_default_pd(dev_priv->mmu); + /* struct ttm_mem_type_manager *man = &bdev->man[psb_be->mem_type]; */ + + if (psb_be->mem_type == TTM_PL_TT) { + uint32_t gatt_p_offset = + (psb_be->offset - dev_priv->pg->mmu_gatt_start) + >> PAGE_SHIFT; + + (void) psb_gtt_remove_pages(dev_priv->pg, gatt_p_offset, + psb_be->num_pages, + psb_be->desired_tile_stride, + psb_be->hw_tile_stride, 0); + } + + psb_mmu_remove_pages(pd, psb_be->offset, + psb_be->num_pages, + psb_be->desired_tile_stride, + psb_be->hw_tile_stride); + + return 0; +} + +static int drm_psb_tbe_bind(struct ttm_backend *backend, + struct ttm_mem_reg *bo_mem) +{ + struct ttm_bo_device *bdev = backend->bdev; + struct drm_psb_private *dev_priv = + container_of(bdev, struct drm_psb_private, bdev); + struct drm_psb_ttm_backend *psb_be = + container_of(backend, struct drm_psb_ttm_backend, base); + struct psb_mmu_pd *pd = psb_mmu_get_default_pd(dev_priv->mmu); + struct ttm_mem_type_manager *man = &bdev->man[bo_mem->mem_type]; + struct drm_mm_node *mm_node = bo_mem->mm_node; + int type; + int ret = 0; + + psb_be->mem_type = bo_mem->mem_type; + psb_be->num_pages = bo_mem->num_pages; + psb_be->desired_tile_stride = 0; + psb_be->hw_tile_stride = 0; + psb_be->offset = (mm_node->start << PAGE_SHIFT) + + man->gpu_offset; + + type = + (bo_mem-> + placement & TTM_PL_FLAG_CACHED) ? PSB_MMU_CACHED_MEMORY : 0; + + if (psb_be->mem_type == TTM_PL_TT) { + uint32_t gatt_p_offset = + (psb_be->offset - dev_priv->pg->mmu_gatt_start) + >> PAGE_SHIFT; + + ret = psb_gtt_insert_pages(dev_priv->pg, psb_be->pages, + gatt_p_offset, + psb_be->num_pages, + psb_be->desired_tile_stride, + psb_be->hw_tile_stride, type); + } + + ret = psb_mmu_insert_pages(pd, psb_be->pages, + psb_be->offset, psb_be->num_pages, + psb_be->desired_tile_stride, + psb_be->hw_tile_stride, type); + if (ret) + goto out_err; + + return 0; +out_err: + drm_psb_tbe_unbind(backend); + return ret; + +} + +static void drm_psb_tbe_clear(struct ttm_backend *backend) +{ + struct drm_psb_ttm_backend *psb_be = + container_of(backend, struct drm_psb_ttm_backend, base); + + psb_be->pages = NULL; + return; +} + +static void drm_psb_tbe_destroy(struct ttm_backend *backend) +{ + struct drm_psb_ttm_backend *psb_be = + container_of(backend, struct drm_psb_ttm_backend, base); + + if (backend) + kfree(psb_be); +} + +static struct ttm_backend_func psb_ttm_backend = { + .populate = drm_psb_tbe_populate, + .clear = drm_psb_tbe_clear, + .bind = drm_psb_tbe_bind, + .unbind = drm_psb_tbe_unbind, + .destroy = drm_psb_tbe_destroy, +}; + +static struct ttm_backend *drm_psb_tbe_init(struct ttm_bo_device *bdev) +{ + struct drm_psb_ttm_backend *psb_be; + + psb_be = kzalloc(sizeof(*psb_be), GFP_KERNEL); + if (!psb_be) + return NULL; + psb_be->pages = NULL; + psb_be->base.func = &psb_ttm_backend; + psb_be->base.bdev = bdev; + return &psb_be->base; +} + +static int psb_ttm_io_mem_reserve(struct ttm_bo_device *bdev, + struct ttm_mem_reg *mem) +{ + struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; + struct drm_psb_private *dev_priv = + container_of(bdev, struct drm_psb_private, bdev); + struct psb_gtt *pg = dev_priv->pg; + struct drm_mm_node *mm_node = mem->mm_node; + + mem->bus.addr = NULL; + mem->bus.offset = 0; + mem->bus.size = mem->num_pages << PAGE_SHIFT; + mem->bus.base = 0; + mem->bus.is_iomem = false; + if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE)) + return -EINVAL; + switch (mem->mem_type) { + case TTM_PL_SYSTEM: + /* system memory */ + return 0; + case TTM_PL_TT: + mem->bus.offset = mm_node->start << PAGE_SHIFT; + mem->bus.base = pg->gatt_start; + mem->bus.is_iomem = false; + /* Don't know whether it is IO_MEM, this flag + used in vm_fault handle */ + break; + case DRM_PSB_MEM_MMU: + mem->bus.offset = mm_node->start << PAGE_SHIFT; + mem->bus.base = 0x00000000; + break; + case TTM_PL_CI: + mem->bus.offset = mm_node->start << PAGE_SHIFT; + mem->bus.base = dev_priv->ci_region_start;; + mem->bus.is_iomem = true; + break; + case TTM_PL_RAR: + mem->bus.offset = mm_node->start << PAGE_SHIFT; + mem->bus.base = dev_priv->rar_region_start;; + mem->bus.is_iomem = true; + break; + default: + return -EINVAL; + } + return 0; +} + +static void psb_ttm_io_mem_free(struct ttm_bo_device *bdev, + struct ttm_mem_reg *mem) +{ +} + +/* + * Use this memory type priority if no eviction is needed. + */ +/* +static uint32_t psb_mem_prios[] = { + TTM_PL_CI, + TTM_PL_RAR, + TTM_PL_TT, + DRM_PSB_MEM_MMU, + TTM_PL_SYSTEM +}; +*/ +/* + * Use this memory type priority if need to evict. + */ +/* +static uint32_t psb_busy_prios[] = { + TTM_PL_TT, + TTM_PL_CI, + TTM_PL_RAR, + DRM_PSB_MEM_MMU, + TTM_PL_SYSTEM +}; +*/ +struct ttm_bo_driver psb_ttm_bo_driver = { +/* + .mem_type_prio = psb_mem_prios, + .mem_busy_prio = psb_busy_prios, + .num_mem_type_prio = ARRAY_SIZE(psb_mem_prios), + .num_mem_busy_prio = ARRAY_SIZE(psb_busy_prios), +*/ + .create_ttm_backend_entry = &drm_psb_tbe_init, + .invalidate_caches = &psb_invalidate_caches, + .init_mem_type = &psb_init_mem_type, + .evict_flags = &psb_evict_mask, + .move = &psb_move, + .verify_access = &psb_verify_access, + .sync_obj_signaled = &ttm_fence_sync_obj_signaled, + .sync_obj_wait = &ttm_fence_sync_obj_wait, + .sync_obj_flush = &ttm_fence_sync_obj_flush, + .sync_obj_unref = &ttm_fence_sync_obj_unref, + .sync_obj_ref = &ttm_fence_sync_obj_ref, + .io_mem_reserve = &psb_ttm_io_mem_reserve, + .io_mem_free = &psb_ttm_io_mem_free +}; diff --git a/trunk/drivers/staging/gma500/psb_drm.h b/trunk/drivers/staging/gma500/psb_drm.h index 28862c7e0949..a339406052ef 100644 --- a/trunk/drivers/staging/gma500/psb_drm.h +++ b/trunk/drivers/staging/gma500/psb_drm.h @@ -28,6 +28,9 @@ #include "drm_mode.h" #endif +#include "psb_ttm_fence_user.h" +#include "psb_ttm_placement_user.h" + #define DRM_PSB_SAREA_MAJOR 0 #define DRM_PSB_SAREA_MINOR 2 #define PSB_FIXED_SHIFT 16 @@ -38,6 +41,15 @@ * Public memory types. */ +#define DRM_PSB_MEM_MMU TTM_PL_PRIV1 +#define DRM_PSB_FLAG_MEM_MMU TTM_PL_FLAG_PRIV1 + +#define TTM_PL_CI TTM_PL_PRIV0 +#define TTM_PL_FLAG_CI TTM_PL_FLAG_PRIV0 + +#define TTM_PL_RAR TTM_PL_PRIV2 +#define TTM_PL_FLAG_RAR TTM_PL_FLAG_PRIV2 + typedef s32 psb_fixed; typedef u32 psb_ufixed; @@ -100,12 +112,111 @@ struct drm_psb_sarea { u32 num_active_scanouts; }; +#define PSB_RELOC_MAGIC 0x67676767 +#define PSB_RELOC_SHIFT_MASK 0x0000FFFF +#define PSB_RELOC_SHIFT_SHIFT 0 +#define PSB_RELOC_ALSHIFT_MASK 0xFFFF0000 +#define PSB_RELOC_ALSHIFT_SHIFT 16 + +#define PSB_RELOC_OP_OFFSET 0 /* Offset of the indicated + * buffer + */ + +struct drm_psb_reloc { + u32 reloc_op; + u32 where; /* offset in destination buffer */ + u32 buffer; /* Buffer reloc applies to */ + u32 mask; /* Destination format: */ + u32 shift; /* Destination format: */ + u32 pre_add; /* Destination format: */ + u32 background; /* Destination add */ + u32 dst_buffer; /* Destination buffer. Index into buffer_list */ + u32 arg0; /* Reloc-op dependent */ + u32 arg1; +}; + + #define PSB_GPU_ACCESS_READ (1ULL << 32) #define PSB_GPU_ACCESS_WRITE (1ULL << 33) #define PSB_GPU_ACCESS_MASK (PSB_GPU_ACCESS_READ | PSB_GPU_ACCESS_WRITE) #define PSB_BO_FLAG_COMMAND (1ULL << 52) +#define PSB_ENGINE_2D 0 +#define PSB_ENGINE_VIDEO 1 +#define LNC_ENGINE_ENCODE 5 + +/* + * For this fence class we have a couple of + * fence types. + */ + +#define _PSB_FENCE_EXE_SHIFT 0 +#define _PSB_FENCE_FEEDBACK_SHIFT 4 + +#define _PSB_FENCE_TYPE_EXE (1 << _PSB_FENCE_EXE_SHIFT) +#define _PSB_FENCE_TYPE_FEEDBACK (1 << _PSB_FENCE_FEEDBACK_SHIFT) + +#define PSB_NUM_ENGINES 6 + + +#define PSB_FEEDBACK_OP_VISTEST (1 << 0) + +struct drm_psb_extension_rep { + s32 exists; + u32 driver_ioctl_offset; + u32 sarea_offset; + u32 major; + u32 minor; + u32 pl; +}; + +#define DRM_PSB_EXT_NAME_LEN 128 + +union drm_psb_extension_arg { + char extension[DRM_PSB_EXT_NAME_LEN]; + struct drm_psb_extension_rep rep; +}; + +struct psb_validate_req { + u64 set_flags; + u64 clear_flags; + u64 next; + u64 presumed_gpu_offset; + u32 buffer_handle; + u32 presumed_flags; + u32 group; + u32 pad64; +}; + +struct psb_validate_rep { + u64 gpu_offset; + u32 placement; + u32 fence_type_mask; +}; + +#define PSB_USE_PRESUMED (1 << 0) + +struct psb_validate_arg { + int handled; + int ret; + union { + struct psb_validate_req req; + struct psb_validate_rep rep; + } d; +}; + + +#define DRM_PSB_FENCE_NO_USER (1 << 0) + +struct psb_ttm_fence_rep { + u32 handle; + u32 fence_class; + u32 fence_type; + u32 signaled_types; + u32 error; +}; + /* * Feedback components: */ diff --git a/trunk/drivers/staging/gma500/psb_drv.c b/trunk/drivers/staging/gma500/psb_drv.c index 711e5a997c95..d01d45e7a14d 100644 --- a/trunk/drivers/staging/gma500/psb_drv.c +++ b/trunk/drivers/staging/gma500/psb_drv.c @@ -38,29 +38,30 @@ int drm_psb_debug; static int drm_psb_trap_pagefaults; +int drm_psb_disable_vsync = 1; int drm_psb_no_fb; +int gfxrtdelay = 2 * 1000; static int psb_probe(struct pci_dev *pdev, const struct pci_device_id *ent); MODULE_PARM_DESC(debug, "Enable debug output"); MODULE_PARM_DESC(no_fb, "Disable FBdev"); MODULE_PARM_DESC(trap_pagefaults, "Error and reset on MMU pagefaults"); +MODULE_PARM_DESC(disable_vsync, "Disable vsync interrupts"); +MODULE_PARM_DESC(force_pipeb, "Forces PIPEB to become primary fb"); +MODULE_PARM_DESC(ta_mem_size, "TA memory size in kiB"); +MODULE_PARM_DESC(ospm, "switch for ospm support"); +MODULE_PARM_DESC(rtpm, "Specifies Runtime PM delay for GFX"); +MODULE_PARM_DESC(hdmi_edid, "EDID info for HDMI monitor"); module_param_named(debug, drm_psb_debug, int, 0600); module_param_named(no_fb, drm_psb_no_fb, int, 0600); module_param_named(trap_pagefaults, drm_psb_trap_pagefaults, int, 0600); +module_param_named(rtpm, gfxrtdelay, int, 0600); static struct pci_device_id pciidlist[] = { { 0x8086, 0x8108, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PSB_8108 }, { 0x8086, 0x8109, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_PSB_8109 }, - { 0x8086, 0x4100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MRST_4100}, - { 0x8086, 0x4101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MRST_4100}, - { 0x8086, 0x4102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MRST_4100}, - { 0x8086, 0x4103, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MRST_4100}, - { 0x8086, 0x4104, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MRST_4100}, - { 0x8086, 0x4105, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MRST_4100}, - { 0x8086, 0x4106, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MRST_4100}, - { 0x8086, 0x4107, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_MRST_4100}, { 0, 0, 0} }; MODULE_DEVICE_TABLE(pci, pciidlist); @@ -102,6 +103,9 @@ MODULE_DEVICE_TABLE(pci, pciidlist); #define DRM_IOCTL_PSB_GTT_UNMAP \ DRM_IOW(DRM_PSB_GTT_UNMAP + DRM_COMMAND_BASE, \ struct psb_gtt_mapping_arg) +#define DRM_IOCTL_PSB_GETPAGEADDRS \ + DRM_IOWR(DRM_COMMAND_BASE + DRM_PSB_GETPAGEADDRS,\ + struct drm_psb_getpageaddrs_arg) #define DRM_IOCTL_PSB_UPDATE_GUARD \ DRM_IOWR(DRM_PSB_UPDATE_GUARD + DRM_COMMAND_BASE, \ uint32_t) @@ -118,8 +122,69 @@ MODULE_DEVICE_TABLE(pci, pciidlist); DRM_IOWR(DRM_PSB_GET_PIPE_FROM_CRTC_ID + DRM_COMMAND_BASE, \ struct drm_psb_get_pipe_from_crtc_id_arg) +/* + * TTM execbuf extension. + */ + +#define DRM_PSB_CMDBUF 0x23 +#define DRM_PSB_SCENE_UNREF 0x24 #define DRM_IOCTL_PSB_KMS_OFF DRM_IO(DRM_PSB_KMS_OFF + DRM_COMMAND_BASE) #define DRM_IOCTL_PSB_KMS_ON DRM_IO(DRM_PSB_KMS_ON + DRM_COMMAND_BASE) +/* + * TTM placement user extension. + */ + +#define DRM_PSB_PLACEMENT_OFFSET (DRM_PSB_SCENE_UNREF + 1) + +#define DRM_PSB_TTM_PL_CREATE (TTM_PL_CREATE + DRM_PSB_PLACEMENT_OFFSET) +#define DRM_PSB_TTM_PL_REFERENCE (TTM_PL_REFERENCE + DRM_PSB_PLACEMENT_OFFSET) +#define DRM_PSB_TTM_PL_UNREF (TTM_PL_UNREF + DRM_PSB_PLACEMENT_OFFSET) +#define DRM_PSB_TTM_PL_SYNCCPU (TTM_PL_SYNCCPU + DRM_PSB_PLACEMENT_OFFSET) +#define DRM_PSB_TTM_PL_WAITIDLE (TTM_PL_WAITIDLE + DRM_PSB_PLACEMENT_OFFSET) +#define DRM_PSB_TTM_PL_SETSTATUS (TTM_PL_SETSTATUS + DRM_PSB_PLACEMENT_OFFSET) +#define DRM_PSB_TTM_PL_CREATE_UB (TTM_PL_CREATE_UB + DRM_PSB_PLACEMENT_OFFSET) + +/* + * TTM fence extension. + */ + +#define DRM_PSB_FENCE_OFFSET (DRM_PSB_TTM_PL_CREATE_UB + 1) +#define DRM_PSB_TTM_FENCE_SIGNALED (TTM_FENCE_SIGNALED + DRM_PSB_FENCE_OFFSET) +#define DRM_PSB_TTM_FENCE_FINISH (TTM_FENCE_FINISH + DRM_PSB_FENCE_OFFSET) +#define DRM_PSB_TTM_FENCE_UNREF (TTM_FENCE_UNREF + DRM_PSB_FENCE_OFFSET) + +#define DRM_PSB_FLIP (DRM_PSB_TTM_FENCE_UNREF + 1) /*20*/ + +#define DRM_IOCTL_PSB_TTM_PL_CREATE \ + DRM_IOWR(DRM_COMMAND_BASE + DRM_PSB_TTM_PL_CREATE,\ + union ttm_pl_create_arg) +#define DRM_IOCTL_PSB_TTM_PL_REFERENCE \ + DRM_IOWR(DRM_COMMAND_BASE + DRM_PSB_TTM_PL_REFERENCE,\ + union ttm_pl_reference_arg) +#define DRM_IOCTL_PSB_TTM_PL_UNREF \ + DRM_IOW(DRM_COMMAND_BASE + DRM_PSB_TTM_PL_UNREF,\ + struct ttm_pl_reference_req) +#define DRM_IOCTL_PSB_TTM_PL_SYNCCPU \ + DRM_IOW(DRM_COMMAND_BASE + DRM_PSB_TTM_PL_SYNCCPU,\ + struct ttm_pl_synccpu_arg) +#define DRM_IOCTL_PSB_TTM_PL_WAITIDLE \ + DRM_IOW(DRM_COMMAND_BASE + DRM_PSB_TTM_PL_WAITIDLE,\ + struct ttm_pl_waitidle_arg) +#define DRM_IOCTL_PSB_TTM_PL_SETSTATUS \ + DRM_IOWR(DRM_COMMAND_BASE + DRM_PSB_TTM_PL_SETSTATUS,\ + union ttm_pl_setstatus_arg) +#define DRM_IOCTL_PSB_TTM_PL_CREATE_UB \ + DRM_IOWR(DRM_COMMAND_BASE + DRM_PSB_TTM_PL_CREATE_UB,\ + union ttm_pl_create_ub_arg) +#define DRM_IOCTL_PSB_TTM_FENCE_SIGNALED \ + DRM_IOWR(DRM_COMMAND_BASE + DRM_PSB_TTM_FENCE_SIGNALED, \ + union ttm_fence_signaled_arg) +#define DRM_IOCTL_PSB_TTM_FENCE_FINISH \ + DRM_IOWR(DRM_COMMAND_BASE + DRM_PSB_TTM_FENCE_FINISH, \ + union ttm_fence_finish_arg) +#define DRM_IOCTL_PSB_TTM_FENCE_UNREF \ + DRM_IOW(DRM_COMMAND_BASE + DRM_PSB_TTM_FENCE_UNREF, \ + struct ttm_fence_unref_arg) static int psb_vt_leave_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); @@ -173,226 +238,86 @@ static struct drm_ioctl_desc psb_ioctls[] = { PSB_IOCTL_DEF(DRM_IOCTL_PSB_GTT_UNMAP, psb_gtt_unmap_meminfo_ioctl, DRM_AUTH), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_GETPAGEADDRS, + psb_getpageaddrs_ioctl, + DRM_AUTH), PSB_IOCTL_DEF(DRM_IOCTL_PSB_DPST, psb_dpst_ioctl, DRM_AUTH), PSB_IOCTL_DEF(DRM_IOCTL_PSB_GAMMA, psb_gamma_ioctl, DRM_AUTH), PSB_IOCTL_DEF(DRM_IOCTL_PSB_DPST_BL, psb_dpst_bl_ioctl, DRM_AUTH), PSB_IOCTL_DEF(DRM_IOCTL_PSB_GET_PIPE_FROM_CRTC_ID, psb_intel_get_pipe_from_crtc_id, 0), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_TTM_PL_CREATE, psb_pl_create_ioctl, + DRM_AUTH), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_TTM_PL_REFERENCE, psb_pl_reference_ioctl, + DRM_AUTH), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_TTM_PL_UNREF, psb_pl_unref_ioctl, + DRM_AUTH), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_TTM_PL_SYNCCPU, psb_pl_synccpu_ioctl, + DRM_AUTH), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_TTM_PL_WAITIDLE, psb_pl_waitidle_ioctl, + DRM_AUTH), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_TTM_PL_SETSTATUS, psb_pl_setstatus_ioctl, + DRM_AUTH), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_TTM_PL_CREATE_UB, psb_pl_ub_create_ioctl, + DRM_AUTH), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_TTM_FENCE_SIGNALED, + psb_fence_signaled_ioctl, DRM_AUTH), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_TTM_FENCE_FINISH, psb_fence_finish_ioctl, + DRM_AUTH), + PSB_IOCTL_DEF(DRM_IOCTL_PSB_TTM_FENCE_UNREF, psb_fence_unref_ioctl, + DRM_AUTH), }; -static void psb_lastclose(struct drm_device *dev) +static void psb_set_uopt(struct drm_psb_uopt *uopt) { return; } -static void psb_do_takedown(struct drm_device *dev) -{ - /* FIXME: do we need to clean up the gtt here ? */ -} - -void mrst_get_fuse_settings(struct drm_device *dev) +static void psb_lastclose(struct drm_device *dev) { - struct drm_psb_private *dev_priv = dev->dev_private; - struct pci_dev *pci_root = pci_get_bus_and_slot(0, 0); - uint32_t fuse_value = 0; - uint32_t fuse_value_tmp = 0; - -#define FB_REG06 0xD0810600 -#define FB_MIPI_DISABLE (1 << 11) -#define FB_REG09 0xD0810900 -#define FB_REG09 0xD0810900 -#define FB_SKU_MASK 0x7000 -#define FB_SKU_SHIFT 12 -#define FB_SKU_100 0 -#define FB_SKU_100L 1 -#define FB_SKU_83 2 - pci_write_config_dword(pci_root, 0xD0, FB_REG06); - pci_read_config_dword(pci_root, 0xD4, &fuse_value); - - dev_priv->iLVDS_enable = fuse_value & FB_MIPI_DISABLE; - - DRM_INFO("internal display is %s\n", - dev_priv->iLVDS_enable ? "LVDS display" : "MIPI display"); - - /*prevent Runtime suspend at start*/ - if (dev_priv->iLVDS_enable) { - dev_priv->is_lvds_on = true; - dev_priv->is_mipi_on = false; - } - else { - dev_priv->is_mipi_on = true; - dev_priv->is_lvds_on = false; - } - - dev_priv->video_device_fuse = fuse_value; - - pci_write_config_dword(pci_root, 0xD0, FB_REG09); - pci_read_config_dword(pci_root, 0xD4, &fuse_value); + struct drm_psb_private *dev_priv = + (struct drm_psb_private *) dev->dev_private; - DRM_INFO("SKU values is 0x%x. \n", fuse_value); - fuse_value_tmp = (fuse_value & FB_SKU_MASK) >> FB_SKU_SHIFT; + return; - dev_priv->fuse_reg_value = fuse_value; + if (!dev->dev_private) + return; - switch (fuse_value_tmp) { - case FB_SKU_100: - dev_priv->core_freq = 200; - break; - case FB_SKU_100L: - dev_priv->core_freq = 100; - break; - case FB_SKU_83: - dev_priv->core_freq = 166; - break; - default: - DRM_ERROR("Invalid SKU values, SKU value = 0x%08x\n", fuse_value_tmp); - dev_priv->core_freq = 0; + mutex_lock(&dev_priv->cmdbuf_mutex); + if (dev_priv->context.buffers) { + vfree(dev_priv->context.buffers); + dev_priv->context.buffers = NULL; } - DRM_INFO("LNC core clk is %dMHz.\n", dev_priv->core_freq); - pci_dev_put(pci_root); + mutex_unlock(&dev_priv->cmdbuf_mutex); } -void mid_get_pci_revID (struct drm_psb_private *dev_priv) -{ - uint32_t platform_rev_id = 0; - struct pci_dev *pci_gfx_root = pci_get_bus_and_slot(0, PCI_DEVFN(2, 0)); - - /*get the revison ID, B0:D2:F0;0x08 */ - pci_read_config_dword(pci_gfx_root, 0x08, &platform_rev_id); - dev_priv->platform_rev_id = (uint8_t) platform_rev_id; - pci_dev_put(pci_gfx_root); - PSB_DEBUG_ENTRY("platform_rev_id is %x\n", dev_priv->platform_rev_id); -} - -void mrst_get_vbt_data(struct drm_psb_private *dev_priv) +static void psb_do_takedown(struct drm_device *dev) { - struct mrst_vbt *vbt = &dev_priv->vbt_data; - u32 platform_config_address; - u16 new_size; - u8 *vbt_virtual; - u8 bpi; - u8 number_desc = 0; - struct mrst_timing_info *dp_ti = &dev_priv->gct_data.DTD; - struct gct_r10_timing_info ti; - void *pGCT; - struct pci_dev *pci_gfx_root = pci_get_bus_and_slot(0, PCI_DEVFN(2, 0)); - - /*get the address of the platform config vbt, B0:D2:F0;0xFC */ - pci_read_config_dword(pci_gfx_root, 0xFC, &platform_config_address); - pci_dev_put(pci_gfx_root); - DRM_INFO("drm platform config address is %x\n", - platform_config_address); + struct drm_psb_private *dev_priv = + (struct drm_psb_private *) dev->dev_private; + struct ttm_bo_device *bdev = &dev_priv->bdev; - /* check for platform config address == 0. */ - /* this means fw doesn't support vbt */ - if (platform_config_address == 0) { - vbt->size = 0; - return; + if (dev_priv->have_mem_mmu) { + ttm_bo_clean_mm(bdev, DRM_PSB_MEM_MMU); + dev_priv->have_mem_mmu = 0; } - /* get the virtual address of the vbt */ - vbt_virtual = ioremap(platform_config_address, sizeof(*vbt)); - - memcpy(vbt, vbt_virtual, sizeof(*vbt)); - iounmap(vbt_virtual); /* Free virtual address space */ - - printk(KERN_ALERT "GCT revision is %x\n", vbt->revision); + if (dev_priv->have_tt) { + ttm_bo_clean_mm(bdev, TTM_PL_TT); + dev_priv->have_tt = 0; + } - switch (vbt->revision) { - case 0: - vbt->mrst_gct = NULL; - vbt->mrst_gct = \ - ioremap(platform_config_address + sizeof(*vbt) - 4, - vbt->size - sizeof(*vbt) + 4); - pGCT = vbt->mrst_gct; - bpi = ((struct mrst_gct_v1 *)pGCT)->PD.BootPanelIndex; - dev_priv->gct_data.bpi = bpi; - dev_priv->gct_data.pt = - ((struct mrst_gct_v1 *)pGCT)->PD.PanelType; - memcpy(&dev_priv->gct_data.DTD, - &((struct mrst_gct_v1 *)pGCT)->panel[bpi].DTD, - sizeof(struct mrst_timing_info)); - dev_priv->gct_data.Panel_Port_Control = - ((struct mrst_gct_v1 *)pGCT)->panel[bpi].Panel_Port_Control; - dev_priv->gct_data.Panel_MIPI_Display_Descriptor = - ((struct mrst_gct_v1 *)pGCT)->panel[bpi].Panel_MIPI_Display_Descriptor; - break; - case 1: - vbt->mrst_gct = NULL; - vbt->mrst_gct = \ - ioremap(platform_config_address + sizeof(*vbt) - 4, - vbt->size - sizeof(*vbt) + 4); - pGCT = vbt->mrst_gct; - bpi = ((struct mrst_gct_v2 *)pGCT)->PD.BootPanelIndex; - dev_priv->gct_data.bpi = bpi; - dev_priv->gct_data.pt = - ((struct mrst_gct_v2 *)pGCT)->PD.PanelType; - memcpy(&dev_priv->gct_data.DTD, - &((struct mrst_gct_v2 *)pGCT)->panel[bpi].DTD, - sizeof(struct mrst_timing_info)); - dev_priv->gct_data.Panel_Port_Control = - ((struct mrst_gct_v2 *)pGCT)->panel[bpi].Panel_Port_Control; - dev_priv->gct_data.Panel_MIPI_Display_Descriptor = - ((struct mrst_gct_v2 *)pGCT)->panel[bpi].Panel_MIPI_Display_Descriptor; - break; - case 0x10: - /*header definition changed from rev 01 (v2) to rev 10h. */ - /*so, some values have changed location*/ - new_size = vbt->checksum; /*checksum contains lo size byte*/ - /*LSB of mrst_gct contains hi size byte*/ - new_size |= ((0xff & (unsigned int)vbt->mrst_gct)) << 8; - - vbt->checksum = vbt->size; /*size contains the checksum*/ - if (new_size > 0xff) - vbt->size = 0xff; /*restrict size to 255*/ - else - vbt->size = new_size; - - /* number of descriptors defined in the GCT */ - number_desc = ((0xff00 & (unsigned int)vbt->mrst_gct)) >> 8; - bpi = ((0xff0000 & (unsigned int)vbt->mrst_gct)) >> 16; - vbt->mrst_gct = NULL; - vbt->mrst_gct = \ - ioremap(platform_config_address + GCT_R10_HEADER_SIZE, - GCT_R10_DISPLAY_DESC_SIZE * number_desc); - pGCT = vbt->mrst_gct; - pGCT = (u8 *)pGCT + (bpi*GCT_R10_DISPLAY_DESC_SIZE); - dev_priv->gct_data.bpi = bpi; /*save boot panel id*/ - - /*copy the GCT display timings into a temp structure*/ - memcpy(&ti, pGCT, sizeof(struct gct_r10_timing_info)); - - /*now copy the temp struct into the dev_priv->gct_data*/ - dp_ti->pixel_clock = ti.pixel_clock; - dp_ti->hactive_hi = ti.hactive_hi; - dp_ti->hactive_lo = ti.hactive_lo; - dp_ti->hblank_hi = ti.hblank_hi; - dp_ti->hblank_lo = ti.hblank_lo; - dp_ti->hsync_offset_hi = ti.hsync_offset_hi; - dp_ti->hsync_offset_lo = ti.hsync_offset_lo; - dp_ti->hsync_pulse_width_hi = ti.hsync_pulse_width_hi; - dp_ti->hsync_pulse_width_lo = ti.hsync_pulse_width_lo; - dp_ti->vactive_hi = ti.vactive_hi; - dp_ti->vactive_lo = ti.vactive_lo; - dp_ti->vblank_hi = ti.vblank_hi; - dp_ti->vblank_lo = ti.vblank_lo; - dp_ti->vsync_offset_hi = ti.vsync_offset_hi; - dp_ti->vsync_offset_lo = ti.vsync_offset_lo; - dp_ti->vsync_pulse_width_hi = ti.vsync_pulse_width_hi; - dp_ti->vsync_pulse_width_lo = ti.vsync_pulse_width_lo; - - /*mov the MIPI_Display_Descriptor data from GCT to dev priv*/ - dev_priv->gct_data.Panel_MIPI_Display_Descriptor = - *((u8 *)pGCT + 0x0d); - dev_priv->gct_data.Panel_MIPI_Display_Descriptor |= - (*((u8 *)pGCT + 0x0e)) << 8; - break; - default: - printk(KERN_ERR "Unknown revision of GCT!\n"); - vbt->size = 0; + if (dev_priv->have_camera) { + ttm_bo_clean_mm(bdev, TTM_PL_CI); + dev_priv->have_camera = 0; } + if (dev_priv->have_rar) { + ttm_bo_clean_mm(bdev, TTM_PL_RAR); + dev_priv->have_rar = 0; + } + } static void psb_get_core_freq(struct drm_device *dev) @@ -433,10 +358,36 @@ static void psb_get_core_freq(struct drm_device *dev) } } +#define FB_REG06 0xD0810600 +#define FB_TOPAZ_DISABLE BIT0 +#define FB_MIPI_DISABLE BIT11 +#define FB_REG09 0xD0810900 +#define FB_SKU_MASK (BIT12|BIT13|BIT14) +#define FB_SKU_SHIFT 12 +#define FB_SKU_100 0 +#define FB_SKU_100L 1 +#define FB_SKU_83 2 + +bool mid_get_pci_revID(struct drm_psb_private *dev_priv) +{ + uint32_t platform_rev_id = 0; + struct pci_dev *pci_gfx_root = pci_get_bus_and_slot(0, PCI_DEVFN(2, 0)); + + /*get the revison ID, B0:D2:F0;0x08 */ + pci_read_config_dword(pci_gfx_root, 0x08, &platform_rev_id); + dev_priv->platform_rev_id = (uint8_t) platform_rev_id; + pci_dev_put(pci_gfx_root); + PSB_DEBUG_ENTRY("platform_rev_id is %x\n", + dev_priv->platform_rev_id); + + return true; +} + static int psb_do_init(struct drm_device *dev) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; + struct ttm_bo_device *bdev = &dev_priv->bdev; struct psb_gtt *pg = dev_priv->pg; uint32_t stolen_gtt; @@ -445,6 +396,16 @@ static int psb_do_init(struct drm_device *dev) int ret = -ENOMEM; + + /* + * Initialize sequence numbers for the different command + * submission mechanisms. + */ + + dev_priv->sequence[PSB_ENGINE_2D] = 0; + dev_priv->sequence[PSB_ENGINE_VIDEO] = 0; + dev_priv->sequence[LNC_ENGINE_ENCODE] = 0; + if (pg->mmu_gatt_start & 0x0FFFFFFF) { DRM_ERROR("Gatt must be 256M aligned. This is a bug.\n"); ret = -EINVAL; @@ -484,7 +445,6 @@ static int psb_do_init(struct drm_device *dev) pg->gatt_pages : PSB_TT_PRIV0_PLIMIT; tt_start = dev_priv->gatt_free_offset - pg->mmu_gatt_start; tt_pages -= tt_start >> PAGE_SHIFT; - /* FIXME: can we kill ta_mem_size ? */ dev_priv->sizes.ta_mem_size = 0; PSB_WSGX32(0x00000000, PSB_CR_BIF_BANK0); @@ -493,11 +453,30 @@ static int psb_do_init(struct drm_device *dev) PSB_WSGX32(PSB_RSGX32(PSB_CR_BIF_CTRL) | _PSB_MMU_ER_MASK, PSB_CR_BIF_CTRL); psb_spank(dev_priv); + + PSB_WSGX32(pg->mmu_gatt_start, PSB_CR_BIF_TWOD_REQ_BASE); + + /* TT region managed by TTM. */ + if (!ttm_bo_init_mm(bdev, TTM_PL_TT, + pg->gatt_pages - + (pg->ci_start >> PAGE_SHIFT) - + ((dev_priv->ci_region_size + dev_priv->rar_region_size) + >> PAGE_SHIFT))) { + + dev_priv->have_tt = 1; + dev_priv->sizes.tt_size = + (tt_pages << PAGE_SHIFT) / (1024 * 1024) / 2; + } - /* mmu_gatt ?? */ - printk(KERN_INFO "TWOD base %08lX\n", (u32) pg->gatt_start); - PSB_WSGX32(pg->gatt_start, PSB_CR_BIF_TWOD_REQ_BASE); + if (!ttm_bo_init_mm(bdev, + DRM_PSB_MEM_MMU, + PSB_MEM_TT_START >> PAGE_SHIFT)) { + dev_priv->have_mem_mmu = 1; + dev_priv->sizes.mmu_size = + PSB_MEM_TT_START / (1024*1024); + } + PSB_DEBUG_INIT("Init MSVDX\n"); return 0; out_err: psb_do_takedown(dev); @@ -535,6 +514,18 @@ static int psb_driver_unload(struct drm_device *dev) (dev_priv->mmu), pg->mmu_gatt_start, pg->vram_stolen_size >> PAGE_SHIFT); + if (pg->ci_stolen_size != 0) + psb_mmu_remove_pfn_sequence( + psb_mmu_get_default_pd + (dev_priv->mmu), + pg->ci_start, + pg->ci_stolen_size >> PAGE_SHIFT); + if (pg->rar_stolen_size != 0) + psb_mmu_remove_pfn_sequence( + psb_mmu_get_default_pd + (dev_priv->mmu), + pg->rar_start, + pg->rar_stolen_size >> PAGE_SHIFT); up_read(&pg->sem); psb_mmu_driver_takedown(dev_priv->mmu); dev_priv->mmu = NULL; @@ -544,6 +535,14 @@ static int psb_driver_unload(struct drm_device *dev) __free_page(dev_priv->scratch_page); dev_priv->scratch_page = NULL; } + if (dev_priv->has_bo_device) { + ttm_bo_device_release(&dev_priv->bdev); + dev_priv->has_bo_device = 0; + } + if (dev_priv->has_fence_device) { + ttm_fence_device_release(&dev_priv->fdev); + dev_priv->has_fence_device = 0; + } if (dev_priv->vdc_reg) { iounmap(dev_priv->vdc_reg); dev_priv->vdc_reg = NULL; @@ -553,6 +552,12 @@ static int psb_driver_unload(struct drm_device *dev) dev_priv->sgx_reg = NULL; } + if (dev_priv->tdev) + ttm_object_device_release(&dev_priv->tdev); + + if (dev_priv->has_global) + psb_ttm_global_release(dev_priv); + kfree(dev_priv); dev->dev_private = NULL; @@ -560,7 +565,7 @@ static int psb_driver_unload(struct drm_device *dev) psb_intel_destroy_bios(dev); } - gma_power_uninit(dev); + ospm_power_uninit(); return 0; } @@ -569,6 +574,7 @@ static int psb_driver_unload(struct drm_device *dev) static int psb_driver_load(struct drm_device *dev, unsigned long chipset) { struct drm_psb_private *dev_priv; + struct ttm_bo_device *bdev; unsigned long resource_start; struct psb_gtt *pg; unsigned long irqflags; @@ -578,16 +584,39 @@ static int psb_driver_load(struct drm_device *dev, unsigned long chipset) dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL); if (dev_priv == NULL) return -ENOMEM; + INIT_LIST_HEAD(&dev_priv->video_ctx); + + dev_priv->num_pipe = 2; - if (IS_MRST(dev)) - dev_priv->num_pipe = 1; - else - dev_priv->num_pipe = 2; dev_priv->dev = dev; + bdev = &dev_priv->bdev; + + ret = psb_ttm_global_init(dev_priv); + if (unlikely(ret != 0)) + goto out_err; + dev_priv->has_global = 1; + + dev_priv->tdev = ttm_object_device_init + (dev_priv->mem_global_ref.object, PSB_OBJECT_HASH_ORDER); + if (unlikely(dev_priv->tdev == NULL)) + goto out_err; + + mutex_init(&dev_priv->temp_mem); + mutex_init(&dev_priv->cmdbuf_mutex); + mutex_init(&dev_priv->reset_mutex); + INIT_LIST_HEAD(&dev_priv->context.validate_list); + INIT_LIST_HEAD(&dev_priv->context.kern_validate_list); + +/* mutex_init(&dev_priv->dsr_mutex); */ + + spin_lock_init(&dev_priv->reloc_lock); + + DRM_INIT_WAITQUEUE(&dev_priv->rel_mapped_queue); dev->dev_private = (void *) dev_priv; dev_priv->chipset = chipset; + psb_set_uopt(&dev_priv->uopt); PSB_DEBUG_INIT("Mapping MMIO\n"); resource_start = pci_resource_start(dev->pdev, PSB_MMIO_RESOURCE); @@ -603,18 +632,28 @@ static int psb_driver_load(struct drm_device *dev, unsigned long chipset) if (!dev_priv->sgx_reg) goto out_err; - if (IS_MRST(dev)) { - mrst_get_fuse_settings(dev); - mrst_get_vbt_data(dev_priv); - mid_get_pci_revID(dev_priv); - } else { - psb_get_core_freq(dev); - psb_intel_opregion_init(dev); - psb_intel_init_bios(dev); - } + psb_get_core_freq(dev); + psb_intel_opregion_init(dev); + psb_intel_init_bios(dev); + + PSB_DEBUG_INIT("Init TTM fence and BO driver\n"); /* Init OSPM support */ - gma_power_init(dev); + ospm_power_init(dev); + + ret = psb_ttm_fence_device_init(&dev_priv->fdev); + if (unlikely(ret != 0)) + goto out_err; + + dev_priv->has_fence_device = 1; + ret = ttm_bo_device_init(bdev, + dev_priv->bo_global_ref.ref.object, + &psb_ttm_bo_driver, + DRM_PSB_FILE_PAGE_OFFSET, false); + if (unlikely(ret != 0)) + goto out_err; + dev_priv->has_bo_device = 1; + ttm_lock_init(&dev_priv->ttm_lock); ret = -ENOMEM; @@ -647,6 +686,40 @@ static int psb_driver_load(struct drm_device *dev, unsigned long chipset) tt_pages = (pg->gatt_pages < PSB_TT_PRIV0_PLIMIT) ? (pg->gatt_pages) : PSB_TT_PRIV0_PLIMIT; + /* CI/RAR use the lower half of TT. */ + pg->ci_start = (tt_pages / 2) << PAGE_SHIFT; + pg->rar_start = pg->ci_start + pg->ci_stolen_size; + + + /* + * Make MSVDX/TOPAZ MMU aware of the CI stolen memory area. + */ + if (dev_priv->pg->ci_stolen_size != 0) { + down_read(&pg->sem); + ret = psb_mmu_insert_pfn_sequence(psb_mmu_get_default_pd + (dev_priv->mmu), + dev_priv->ci_region_start >> PAGE_SHIFT, + pg->mmu_gatt_start + pg->ci_start, + pg->ci_stolen_size >> PAGE_SHIFT, 0); + up_read(&pg->sem); + if (ret) + goto out_err; + } + + /* + * Make MSVDX/TOPAZ MMU aware of the rar stolen memory area. + */ + if (dev_priv->pg->rar_stolen_size != 0) { + down_read(&pg->sem); + ret = psb_mmu_insert_pfn_sequence( + psb_mmu_get_default_pd(dev_priv->mmu), + dev_priv->rar_region_start >> PAGE_SHIFT, + pg->mmu_gatt_start + pg->rar_start, + pg->rar_stolen_size >> PAGE_SHIFT, 0); + up_read(&pg->sem); + if (ret) + goto out_err; + } dev_priv->pf_pd = psb_mmu_alloc_pd(dev_priv->mmu, 1, 0); if (!dev_priv->pf_pd) @@ -655,13 +728,14 @@ static int psb_driver_load(struct drm_device *dev, unsigned long chipset) psb_mmu_set_pd_context(psb_mmu_get_default_pd(dev_priv->mmu), 0); psb_mmu_set_pd_context(dev_priv->pf_pd, 1); + spin_lock_init(&dev_priv->sequence_lock); + + PSB_DEBUG_INIT("Begin to init MSVDX/Topaz\n"); + ret = psb_do_init(dev); if (ret) return ret; - PSB_WSGX32(0x20000000, PSB_CR_PDS_EXEC_BASE); - PSB_WSGX32(0x30000000, PSB_CR_BIF_3D_REQ_BASE); - /* igd_opregion_init(&dev_priv->opregion_dev); */ acpi_video_register(); if (dev_priv->lid_state) @@ -709,6 +783,11 @@ static int psb_driver_load(struct drm_device *dev, unsigned long chipset) #endif /*Intel drm driver load is done, continue doing pvr load*/ DRM_DEBUG("Pvr driver load\n"); + +/* if (PVRCore_Init() < 0) + goto out_err; */ +/* if (MRSTLFBInit(dev) < 0) + goto out_err;*/ return 0; out_err: psb_driver_unload(dev); @@ -724,13 +803,40 @@ int psb_driver_device_is_agp(struct drm_device *dev) static int psb_vt_leave_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { + struct drm_psb_private *dev_priv = psb_priv(dev); + struct ttm_bo_device *bdev = &dev_priv->bdev; + struct ttm_mem_type_manager *man; + int ret; + + ret = ttm_vt_lock(&dev_priv->ttm_lock, 1, + psb_fpriv(file_priv)->tfile); + if (unlikely(ret != 0)) + return ret; + + ret = ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_TT); + if (unlikely(ret != 0)) + goto out_unlock; + + man = &bdev->man[TTM_PL_TT]; + +#if 0 /* What to do with this ? */ + if (unlikely(!drm_mm_clean(&man->manager))) + DRM_INFO("Warning: GATT was not clean after VT switch.\n"); +#endif + + ttm_bo_swapout_all(&dev_priv->bdev); + return 0; +out_unlock: + (void) ttm_vt_unlock(&dev_priv->ttm_lock); + return ret; } static int psb_vt_enter_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { - return 0; + struct drm_psb_private *dev_priv = psb_priv(dev); + return ttm_vt_unlock(&dev_priv->ttm_lock); } static int psb_sizes_ioctl(struct drm_device *dev, void *data, @@ -839,12 +945,13 @@ static int psb_dpst_ioctl(struct drm_device *dev, void *data, uint32_t y; uint32_t reg; - if (!gma_power_begin(dev, 0)) + if (!ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) return 0; reg = PSB_RVDC32(PIPEASRC); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); /* horizontal is the left 16 bits */ x = reg >> 16; @@ -921,10 +1028,11 @@ static int psb_mode_operation_ioctl(struct drm_device *dev, void *data, drm_fb = obj_to_fb(obj); psb_fb = to_psb_fb(drm_fb); - if (gma_power_begin(dev, 0)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { REG_WRITE(DSPASURF, psb_fb->offset); REG_READ(DSPASURF); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } else { dev_priv->saveDSPASURF = psb_fb->offset; } @@ -1010,10 +1118,11 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, { struct drm_psb_private *dev_priv = psb_priv(dev); struct drm_psb_register_rw_arg *arg = data; - bool usage = arg->b_force_hw_on ? true : false; + UHBUsage usage = + arg->b_force_hw_on ? OSPM_UHB_FORCE_POWER_ON : OSPM_UHB_ONLY_IF_ON; if (arg->display_write_mask != 0) { - if (gma_power_begin(dev, usage)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, usage)) { if (arg->display_write_mask & REGRWBITS_PFIT_CONTROLS) PSB_WVDC32(arg->display.pfit_controls, PFIT_CONTROL); @@ -1038,7 +1147,7 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, if (arg->display_write_mask & REGRWBITS_VTOTAL_B) PSB_WVDC32(arg->display.vtotal_b, VTOTAL_B); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } else { if (arg->display_write_mask & REGRWBITS_PFIT_CONTROLS) dev_priv->savePFIT_CONTROL = @@ -1063,7 +1172,7 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, } if (arg->display_read_mask != 0) { - if (gma_power_begin(dev, usage)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, usage)) { if (arg->display_read_mask & REGRWBITS_PFIT_CONTROLS) arg->display.pfit_controls = @@ -1084,7 +1193,7 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, arg->display.vtotal_a = PSB_RVDC32(VTOTAL_A); if (arg->display_read_mask & REGRWBITS_VTOTAL_B) arg->display.vtotal_b = PSB_RVDC32(VTOTAL_B); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } else { if (arg->display_read_mask & REGRWBITS_PFIT_CONTROLS) @@ -1110,7 +1219,7 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, } if (arg->overlay_write_mask != 0) { - if (gma_power_begin(dev, usage)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, usage)) { if (arg->overlay_write_mask & OV_REGRWBITS_OGAM_ALL) { PSB_WVDC32(arg->overlay.OGAMC5, OV_OGAMC5); PSB_WVDC32(arg->overlay.OGAMC4, OV_OGAMC4); @@ -1161,7 +1270,7 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, } } } - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } else { if (arg->overlay_write_mask & OV_REGRWBITS_OGAM_ALL) { dev_priv->saveOV_OGAMC5 = arg->overlay.OGAMC5; @@ -1187,7 +1296,7 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, } if (arg->overlay_read_mask != 0) { - if (gma_power_begin(dev, usage)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, usage)) { if (arg->overlay_read_mask & OV_REGRWBITS_OGAM_ALL) { arg->overlay.OGAMC5 = PSB_RVDC32(OV_OGAMC5); arg->overlay.OGAMC4 = PSB_RVDC32(OV_OGAMC4); @@ -1208,7 +1317,7 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, arg->overlay.OVADD = PSB_RVDC32(OV_OVADD); if (arg->overlay_read_mask & OVC_REGRWBITS_OVADD) arg->overlay.OVADD = PSB_RVDC32(OVC_OVADD); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } else { if (arg->overlay_read_mask & OV_REGRWBITS_OGAM_ALL) { arg->overlay.OGAMC5 = dev_priv->saveOV_OGAMC5; @@ -1234,7 +1343,7 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, } if (arg->sprite_enable_mask != 0) { - if (gma_power_begin(dev, usage)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, usage)) { PSB_WVDC32(0x1F3E, DSPARB); PSB_WVDC32(arg->sprite.dspa_control | PSB_RVDC32(DSPACNTR), DSPACNTR); @@ -1249,22 +1358,22 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, PSB_WVDC32(arg->sprite.dspc_size, DSPCSIZE); PSB_WVDC32(arg->sprite.dspc_surface, DSPCSURF); PSB_RVDC32(DSPCSURF); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } } if (arg->sprite_disable_mask != 0) { - if (gma_power_begin(dev, usage)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, usage)) { PSB_WVDC32(0x3F3E, DSPARB); PSB_WVDC32(0x0, DSPCCNTR); PSB_WVDC32(arg->sprite.dspc_surface, DSPCSURF); PSB_RVDC32(DSPCSURF); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } } if (arg->subpicture_enable_mask != 0) { - if (gma_power_begin(dev, usage)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, usage)) { uint32_t temp; if (arg->subpicture_enable_mask & REGRWBITS_DSPACNTR) { temp = PSB_RVDC32(DSPACNTR); @@ -1308,12 +1417,12 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, PSB_WVDC32(temp, DSPCSURF); PSB_RVDC32(DSPCSURF); } - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } } if (arg->subpicture_disable_mask != 0) { - if (gma_power_begin(dev, usage)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, usage)) { uint32_t temp; if (arg->subpicture_disable_mask & REGRWBITS_DSPACNTR) { temp = PSB_RVDC32(DSPACNTR); @@ -1354,7 +1463,7 @@ static int psb_register_rw_ioctl(struct drm_device *dev, void *data, PSB_WVDC32(temp, DSPCSURF); PSB_RVDC32(DSPCSURF); } - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } } @@ -1409,7 +1518,8 @@ static long psb_unlocked_ioctl(struct file *filp, unsigned int cmd, dev_priv->rpm_enabled = 1; } /* - * The driver private ioctls should be thread-safe. + * The driver private ioctls and TTM ioctls should be + * thread-safe. */ if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_END) @@ -1447,16 +1557,6 @@ static void psb_remove(struct pci_dev *pdev) drm_put_dev(dev); } -static int psb_open(struct inode *inode, struct file *filp) -{ - return 0; -} - -static int psb_release(struct inode *inode, struct file *filp) -{ - return 0; -} - static const struct dev_pm_ops psb_pm_ops = { .runtime_suspend = psb_runtime_suspend, @@ -1496,7 +1596,7 @@ static struct drm_driver driver = { .open = psb_open, .release = psb_release, .unlocked_ioctl = psb_unlocked_ioctl, - /* .mmap = psb_mmap, */ + .mmap = psb_mmap, .poll = psb_poll, .fasync = drm_fasync, .read = drm_read, @@ -1512,8 +1612,8 @@ static struct drm_driver driver = { static struct pci_driver psb_pci_driver = { .name = DRIVER_NAME, .id_table = pciidlist, - .resume = gma_power_resume, - .suspend = gma_power_suspend, + .resume = ospm_power_resume, + .suspend = ospm_power_suspend, .probe = psb_probe, .remove = psb_remove, #ifdef CONFIG_PM diff --git a/trunk/drivers/staging/gma500/psb_drv.h b/trunk/drivers/staging/gma500/psb_drv.h index c3609e01f6c9..29a36056d664 100644 --- a/trunk/drivers/staging/gma500/psb_drv.h +++ b/trunk/drivers/staging/gma500/psb_drv.h @@ -29,7 +29,11 @@ #include "psb_intel_drv.h" #include "psb_gtt.h" #include "psb_powermgmt.h" -#include "mrst.h" +#include "ttm/ttm_object.h" +#include "psb_ttm_fence_driver.h" +#include "psb_ttm_userobj_api.h" +#include "ttm/ttm_bo_driver.h" +#include "ttm/ttm_lock.h" /*Append new drm mode definition here, align with libdrm definition*/ #define DRM_MODE_SCALE_NO_SCALE 2 @@ -39,11 +43,8 @@ extern struct ttm_bo_driver psb_ttm_bo_driver; enum { CHIP_PSB_8108 = 0, CHIP_PSB_8109 = 1, - CHIP_MRST_4100 = 2, }; -#define IS_MRST(dev) (((dev)->pci_device & 0xfffc) == 0x4100) - /* *Hardware bugfixes */ @@ -51,6 +52,10 @@ enum { #define DRIVER_NAME "pvrsrvkm" #define DRIVER_DESC "drm driver for the Intel GMA500" #define DRIVER_AUTHOR "Intel Corporation" +#define OSPM_PROC_ENTRY "ospm" +#define RTPM_PROC_ENTRY "rtpm" +#define BLC_PROC_ENTRY "mrst_blc" +#define DISPLAY_PROC_ENTRY "display_status" #define PSB_DRM_DRIVER_DATE "2009-03-10" #define PSB_DRM_DRIVER_MAJOR 8 @@ -87,10 +92,26 @@ enum { #define PSB_TT_PRIV0_PLIMIT (PSB_TT_PRIV0_LIMIT >> PAGE_SHIFT) #define PSB_NUM_VALIDATE_BUFFERS 2048 +#define PSB_MEM_MMU_START 0x00000000 +#define PSB_MEM_TT_START 0xE0000000 + +#define PSB_GL3_CACHE_CTL 0x2100 +#define PSB_GL3_CACHE_STAT 0x2108 + /* *Flags for external memory type field. */ +#define MRST_MSVDX_OFFSET 0x90000 /*MSVDX Base offset */ +#define PSB_MSVDX_OFFSET 0x50000 /*MSVDX Base offset */ +/* MSVDX MMIO region is 0x50000 - 0x57fff ==> 32KB */ +#define PSB_MSVDX_SIZE 0x10000 + +#define LNC_TOPAZ_OFFSET 0xA0000 +#define PNW_TOPAZ_OFFSET 0xC0000 +#define PNW_GL3_OFFSET 0xB0000 +#define LNC_TOPAZ_SIZE 0x10000 +#define PNW_TOPAZ_SIZE 0x30000 /* PNW VXE285 has two cores */ #define PSB_MMU_CACHED_MEMORY 0x0001 /* Bind to MMU only */ #define PSB_MMU_RO_MEMORY 0x0002 /* MMU RO memory */ #define PSB_MMU_WO_MEMORY 0x0004 /* MMU WO memory */ @@ -202,6 +223,20 @@ enum { #define MDFLD_PNW_B0 0x04 #define MDFLD_PNW_C0 0x08 +#define MDFLD_DSR_2D_3D_0 BIT0 +#define MDFLD_DSR_2D_3D_2 BIT1 +#define MDFLD_DSR_CURSOR_0 BIT2 +#define MDFLD_DSR_CURSOR_2 BIT3 +#define MDFLD_DSR_OVERLAY_0 BIT4 +#define MDFLD_DSR_OVERLAY_2 BIT5 +#define MDFLD_DSR_MIPI_CONTROL BIT6 +#define MDFLD_DSR_2D_3D (MDFLD_DSR_2D_3D_0 | MDFLD_DSR_2D_3D_2) + +#define MDFLD_DSR_RR 45 +#define MDFLD_DPU_ENABLE BIT31 +#define MDFLD_DSR_FULLSCREEN BIT30 +#define MDFLD_DSR_DELAY (DRM_HZ / MDFLD_DSR_RR) + #define PSB_PWR_STATE_ON 1 #define PSB_PWR_STATE_OFF 2 @@ -215,6 +250,9 @@ enum { #define PSB_PCIx_MSI_ADDR_LOC 0x94 #define PSB_PCIx_MSI_DATA_LOC 0x98 +#define MDFLD_PLANE_MAX_WIDTH 2048 +#define MDFLD_PLANE_MAX_HEIGHT 2048 + struct opregion_header; struct opregion_acpi; struct opregion_swsci; @@ -228,16 +266,119 @@ struct psb_intel_opregion { int enabled; }; +/* + *User options. + */ + +struct drm_psb_uopt { + int pad; /*keep it here in case we use it in future*/ +}; + +/** + *struct psb_context + * + *@buffers: array of pre-allocated validate buffers. + *@used_buffers: number of buffers in @buffers array currently in use. + *@validate_buffer: buffers validated from user-space. + *@kern_validate_buffers : buffers validated from kernel-space. + *@fence_flags : Fence flags to be used for fence creation. + * + *This structure is used during execbuf validation. + */ + +struct psb_context { + struct psb_validate_buffer *buffers; + uint32_t used_buffers; + struct list_head validate_list; + struct list_head kern_validate_list; + uint32_t fence_types; + uint32_t val_seq; +}; + +struct psb_validate_buffer; + +/* Currently defined profiles */ +enum VAProfile { + VAProfileMPEG2Simple = 0, + VAProfileMPEG2Main = 1, + VAProfileMPEG4Simple = 2, + VAProfileMPEG4AdvancedSimple = 3, + VAProfileMPEG4Main = 4, + VAProfileH264Baseline = 5, + VAProfileH264Main = 6, + VAProfileH264High = 7, + VAProfileVC1Simple = 8, + VAProfileVC1Main = 9, + VAProfileVC1Advanced = 10, + VAProfileH263Baseline = 11, + VAProfileJPEGBaseline = 12, + VAProfileH264ConstrainedBaseline = 13 +}; + +/* Currently defined entrypoints */ +enum VAEntrypoint { + VAEntrypointVLD = 1, + VAEntrypointIZZ = 2, + VAEntrypointIDCT = 3, + VAEntrypointMoComp = 4, + VAEntrypointDeblocking = 5, + VAEntrypointEncSlice = 6, /* slice level encode */ + VAEntrypointEncPicture = 7 /* pictuer encode, JPEG, etc */ +}; + + +struct psb_video_ctx { + struct list_head head; + struct file *filp; /* DRM device file pointer */ + int ctx_type; /* profile<<8|entrypoint */ + /* todo: more context specific data for multi-context support */ +}; + +#define MODE_SETTING_IN_CRTC 0x1 +#define MODE_SETTING_IN_ENCODER 0x2 +#define MODE_SETTING_ON_GOING 0x3 +#define MODE_SETTING_IN_DSR 0x4 +#define MODE_SETTING_ENCODER_DONE 0x8 +#define GCT_R10_HEADER_SIZE 16 +#define GCT_R10_DISPLAY_DESC_SIZE 28 + struct drm_psb_private { + /* + * DSI info. + */ + void * dbi_dsr_info; + void * dsi_configs[2]; + + /* + *TTM Glue. + */ + + struct drm_global_reference mem_global_ref; + struct ttm_bo_global_ref bo_global_ref; + int has_global; + struct drm_device *dev; + struct ttm_object_device *tdev; + struct ttm_fence_device fdev; + struct ttm_bo_device bdev; + struct ttm_lock ttm_lock; + struct vm_operations_struct *ttm_vm_ops; + int has_fence_device; + int has_bo_device; unsigned long chipset; + struct drm_psb_uopt uopt; + struct psb_gtt *pg; /*GTT Memory manager*/ struct psb_gtt_mm *gtt_mm; + struct page *scratch_page; + uint32_t sequence[PSB_NUM_ENGINES]; + uint32_t last_sequence[PSB_NUM_ENGINES]; + uint32_t last_submitted_seq[PSB_NUM_ENGINES]; struct psb_mmu_driver *mmu; struct psb_mmu_pd *pf_pd; @@ -246,22 +387,21 @@ struct drm_psb_private { uint8_t *vdc_reg; uint32_t gatt_free_offset; + /* IMG video context */ + struct list_head video_ctx; + + + /* *Fencing / irq. */ uint32_t vdc_irq_mask; uint32_t pipestat[PSB_NUM_PIPE]; + bool vblanksEnabledForFlips; spinlock_t irqmask_lock; - - /* - * Power - */ - - bool suspended; - bool display_power; - int display_count; + spinlock_t sequence_lock; /* *Modesetting @@ -272,10 +412,41 @@ struct drm_psb_private { struct drm_crtc *pipe_to_crtc_mapping[PSB_NUM_PIPE]; uint32_t num_pipe; + /* + * CI share buffer + */ + unsigned int ci_region_start; + unsigned int ci_region_size; + + /* + * RAR share buffer; + */ + unsigned int rar_region_start; + unsigned int rar_region_size; + /* *Memory managers */ + int have_camera; + int have_rar; + int have_tt; + int have_mem_mmu; + struct mutex temp_mem; + + /* + *Relocation buffer mapping. + */ + + spinlock_t reloc_lock; + unsigned int rel_mapped_pages; + wait_queue_head_t rel_mapped_queue; + + /* + *SAREA + */ + struct drm_psb_sarea *sarea_priv; + /* *OSPM info */ @@ -287,8 +458,7 @@ struct drm_psb_private { struct drm_psb_sizes_arg sizes; - u32 fuse_reg_value; - u32 video_device_fuse; + uint32_t fuse_reg_value; /* pci revision id for B0:D2:F0 */ uint8_t platform_rev_id; @@ -313,7 +483,6 @@ struct drm_psb_private { unsigned int lvds_use_ssc:1; int lvds_ssc_freq; bool is_lvds_on; - bool is_mipi_on; unsigned int core_freq; uint32_t iLVDS_enable; @@ -321,20 +490,6 @@ struct drm_psb_private { /*runtime PM state*/ int rpm_enabled; - /* Moorestown specific */ - struct mrst_vbt vbt_data; - struct mrst_gct_data gct_data; - - /* Moorestown pipe config register value cache */ - uint32_t pipeconf; - uint32_t pipeconf1; - uint32_t pipeconf2; - - /* Moorestown plane control register value cache */ - uint32_t dspcntr; - uint32_t dspcntr1; - uint32_t dspcntr2; - /* *Register state */ @@ -440,10 +595,97 @@ struct drm_psb_private { uint32_t saveOVC_OGAMC4; uint32_t saveOVC_OGAMC5; + /* + * extra MDFLD Register state + */ + uint32_t saveHDMIPHYMISCCTL; + uint32_t saveHDMIB_CONTROL; + uint32_t saveDSPCCNTR; + uint32_t savePIPECCONF; + uint32_t savePIPECSRC; + uint32_t saveHTOTAL_C; + uint32_t saveHBLANK_C; + uint32_t saveHSYNC_C; + uint32_t saveVTOTAL_C; + uint32_t saveVBLANK_C; + uint32_t saveVSYNC_C; + uint32_t saveDSPCSTRIDE; + uint32_t saveDSPCSIZE; + uint32_t saveDSPCPOS; + uint32_t saveDSPCSURF; + uint32_t saveDSPCLINOFF; + uint32_t saveDSPCTILEOFF; + uint32_t saveDSPCCURSOR_CTRL; + uint32_t saveDSPCCURSOR_BASE; + uint32_t saveDSPCCURSOR_POS; + uint32_t save_palette_c[256]; + uint32_t saveOV_OVADD_C; + uint32_t saveOV_OGAMC0_C; + uint32_t saveOV_OGAMC1_C; + uint32_t saveOV_OGAMC2_C; + uint32_t saveOV_OGAMC3_C; + uint32_t saveOV_OGAMC4_C; + uint32_t saveOV_OGAMC5_C; + + /* DSI reg save */ + uint32_t saveDEVICE_READY_REG; + uint32_t saveINTR_EN_REG; + uint32_t saveDSI_FUNC_PRG_REG; + uint32_t saveHS_TX_TIMEOUT_REG; + uint32_t saveLP_RX_TIMEOUT_REG; + uint32_t saveTURN_AROUND_TIMEOUT_REG; + uint32_t saveDEVICE_RESET_REG; + uint32_t saveDPI_RESOLUTION_REG; + uint32_t saveHORIZ_SYNC_PAD_COUNT_REG; + uint32_t saveHORIZ_BACK_PORCH_COUNT_REG; + uint32_t saveHORIZ_FRONT_PORCH_COUNT_REG; + uint32_t saveHORIZ_ACTIVE_AREA_COUNT_REG; + uint32_t saveVERT_SYNC_PAD_COUNT_REG; + uint32_t saveVERT_BACK_PORCH_COUNT_REG; + uint32_t saveVERT_FRONT_PORCH_COUNT_REG; + uint32_t saveHIGH_LOW_SWITCH_COUNT_REG; + uint32_t saveINIT_COUNT_REG; + uint32_t saveMAX_RET_PAK_REG; + uint32_t saveVIDEO_FMT_REG; + uint32_t saveEOT_DISABLE_REG; + uint32_t saveLP_BYTECLK_REG; + uint32_t saveHS_LS_DBI_ENABLE_REG; + uint32_t saveTXCLKESC_REG; + uint32_t saveDPHY_PARAM_REG; + uint32_t saveMIPI_CONTROL_REG; + uint32_t saveMIPI; + uint32_t saveMIPI_C; + void (*init_drvIC)(struct drm_device *dev); + void (*dsi_prePowerState)(struct drm_device *dev); + void (*dsi_postPowerState)(struct drm_device *dev); + + /* DPST Register Save */ + uint32_t saveHISTOGRAM_INT_CONTROL_REG; + uint32_t saveHISTOGRAM_LOGIC_CONTROL_REG; + uint32_t savePWM_CONTROL_LOGIC; + /* MSI reg save */ + uint32_t msi_addr; uint32_t msi_data; + /* + *Scheduling. + */ + + struct mutex reset_mutex; + struct mutex cmdbuf_mutex; + /*uint32_t ta_mem_pages; + struct psb_ta_mem *ta_mem; + int force_ta_mem_load;*/ + atomic_t val_seq; + + /* + *TODO: change this to be per drm-context. + */ + + struct psb_context context; + /* * LID-Switch */ @@ -457,6 +699,8 @@ struct drm_psb_private { *Watchdog */ + int timer_available; + uint32_t apm_reg; uint16_t apm_base; @@ -472,16 +716,72 @@ struct drm_psb_private { }; +struct psb_file_data { /* TODO: Audit this, remove the indirection and set + it up properly in open/postclose ACFIXME */ + void *priv; +}; + +struct psb_fpriv { + struct ttm_object_file *tfile; +}; + struct psb_mmu_driver; extern int drm_crtc_probe_output_modes(struct drm_device *dev, int, int); extern int drm_pick_crtcs(struct drm_device *dev); +static inline struct psb_fpriv *psb_fpriv(struct drm_file *file_priv) +{ + struct psb_file_data *pvr_file_priv + = (struct psb_file_data *)file_priv->driver_priv; + return (struct psb_fpriv *) pvr_file_priv->priv; +} + static inline struct drm_psb_private *psb_priv(struct drm_device *dev) { return (struct drm_psb_private *) dev->dev_private; } +/* + *TTM glue. psb_ttm_glue.c + */ + +extern int psb_open(struct inode *inode, struct file *filp); +extern int psb_release(struct inode *inode, struct file *filp); +extern int psb_mmap(struct file *filp, struct vm_area_struct *vma); + +extern int psb_fence_signaled_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_verify_access(struct ttm_buffer_object *bo, + struct file *filp); +extern ssize_t psb_ttm_read(struct file *filp, char __user *buf, + size_t count, loff_t *f_pos); +extern ssize_t psb_ttm_write(struct file *filp, const char __user *buf, + size_t count, loff_t *f_pos); +extern int psb_fence_finish_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_fence_unref_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_pl_waitidle_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_pl_setstatus_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_pl_synccpu_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_pl_unref_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_pl_reference_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_pl_create_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_pl_ub_create_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_extension_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_ttm_global_init(struct drm_psb_private *dev_priv); +extern void psb_ttm_global_release(struct drm_psb_private *dev_priv); +extern int psb_getpageaddrs_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); /* *MMU stuff. */ @@ -524,6 +824,31 @@ extern void psb_mmu_remove_pages(struct psb_mmu_pd *pd, unsigned long address, uint32_t num_pages, uint32_t desired_tile_stride, uint32_t hw_tile_stride); +/* + *psb_sgx.c + */ + + + +extern int psb_cmdbuf_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +extern int psb_reg_submit(struct drm_psb_private *dev_priv, + uint32_t *regs, unsigned int cmds); + + +extern void psb_fence_or_sync(struct drm_file *file_priv, + uint32_t engine, + uint32_t fence_types, + uint32_t fence_flags, + struct list_head *list, + struct psb_ttm_fence_rep *fence_arg, + struct ttm_fence_object **fence_p); +extern int psb_validate_kernel_buffer(struct psb_context *context, + struct ttm_buffer_object *bo, + uint32_t fence_class, + uint64_t set_flags, + uint64_t clr_flags); + /* *psb_irq.c */ @@ -534,6 +859,8 @@ extern int psb_irq_disable_dpst(struct drm_device *dev); extern void psb_irq_preinstall(struct drm_device *dev); extern int psb_irq_postinstall(struct drm_device *dev); extern void psb_irq_uninstall(struct drm_device *dev); +extern void psb_irq_preinstall_islands(struct drm_device *dev, int hw_islands); +extern int psb_irq_postinstall_islands(struct drm_device *dev, int hw_islands); extern void psb_irq_turn_on_dpst(struct drm_device *dev); extern void psb_irq_turn_off_dpst(struct drm_device *dev); @@ -550,6 +877,29 @@ psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask); extern u32 psb_get_vblank_counter(struct drm_device *dev, int crtc); +/* + *psb_fence.c + */ + +extern void psb_fence_handler(struct drm_device *dev, uint32_t class); + +extern int psb_fence_emit_sequence(struct ttm_fence_device *fdev, + uint32_t fence_class, + uint32_t flags, uint32_t *sequence, + unsigned long *timeout_jiffies); +extern void psb_fence_error(struct drm_device *dev, + uint32_t class, + uint32_t sequence, uint32_t type, int error); +extern int psb_ttm_fence_device_init(struct ttm_fence_device *fdev); + +/* MSVDX/Topaz stuff */ +extern int psb_remove_videoctx(struct drm_psb_private *dev_priv, struct file *filp); + +extern int lnc_video_frameskip(struct drm_device *dev, + uint64_t user_pointer); +extern int lnc_video_getparam(struct drm_device *dev, void *data, + struct drm_file *file_priv); + /* * psb_opregion.c */ @@ -580,9 +930,6 @@ extern int psbfb_sync(struct fb_info *info); extern void psb_spank(struct drm_psb_private *dev_priv); -extern int psbfb_2d_submit(struct drm_psb_private *dev_priv, uint32_t *cmdbuf, - unsigned size); - /* *psb_reset.c */ @@ -603,21 +950,6 @@ int psb_set_brightness(struct backlight_device *bd); int psb_get_brightness(struct backlight_device *bd); struct backlight_device * psb_get_backlight_device(void); -/* mrst_crtc.c */ -extern const struct drm_crtc_helper_funcs mrst_helper_funcs; - -/* mrst_lvds.c */ -extern void mrst_lvds_init(struct drm_device *dev, - struct psb_intel_mode_device *mode_dev); - -/* psb_intel_lvds.c */ -extern void psb_intel_lvds_prepare(struct drm_encoder *encoder); -extern void psb_intel_lvds_commit(struct drm_encoder *encoder); -extern const struct drm_connector_helper_funcs - psb_intel_lvds_connector_helper_funcs; -extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs; - - /* *Debug print bits setting */ @@ -643,6 +975,7 @@ extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs; extern int drm_psb_debug; extern int drm_psb_no_fb; +extern int drm_psb_disable_vsync; extern int drm_idle_check_interval; #define PSB_DEBUG_GENERAL(_fmt, _arg...) \ diff --git a/trunk/drivers/staging/gma500/psb_fb.c b/trunk/drivers/staging/gma500/psb_fb.c index 665096f6a843..f67f53b12937 100644 --- a/trunk/drivers/staging/gma500/psb_fb.c +++ b/trunk/drivers/staging/gma500/psb_fb.c @@ -36,7 +36,9 @@ #include "psb_drv.h" #include "psb_intel_reg.h" #include "psb_intel_drv.h" +#include "psb_ttm_userobj_api.h" #include "psb_fb.h" +#include "psb_sgx.h" #include "psb_pvr_glue.h" static void psb_user_framebuffer_destroy(struct drm_framebuffer *fb); @@ -192,7 +194,7 @@ static int psbfb_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf) struct drm_device *dev = psbfb->base.dev; struct drm_psb_private *dev_priv = dev->dev_private; struct psb_gtt *pg = dev_priv->pg; - unsigned long phys_addr = (unsigned long)pg->stolen_base; + unsigned long phys_addr = (unsigned long)pg->stolen_base;; page_num = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; @@ -270,31 +272,6 @@ static int psbfb_mmap(struct fb_info *info, struct vm_area_struct *vma) return 0; } -static int psbfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long arg) -{ - struct psb_fbdev *fbdev = info->par; - struct psb_framebuffer *psbfb = fbdev->pfb; - struct drm_device *dev = psbfb->base.dev; - struct drm_psb_private *dev_priv = dev->dev_private; - u32 __user *p = (u32 __user *)arg; - u32 l; - u32 buf[32]; - switch (cmd) { - case 0x12345678: - if (!capable(CAP_SYS_RAWIO)) - return -EPERM; - if (get_user(l, p)) - return -EFAULT; - if (l > 32) - return -EMSGSIZE; - if (copy_from_user(buf, p + 1, l * sizeof(u32))) - return -EFAULT; - psbfb_2d_submit(dev_priv, buf, l); - return 0; - default: - return -ENOTTY; - } -} static struct fb_ops psbfb_ops = { .owner = THIS_MODULE, @@ -307,7 +284,6 @@ static struct fb_ops psbfb_ops = { .fb_imageblit = psbfb_imageblit, .fb_mmap = psbfb_mmap, .fb_sync = psbfb_sync, - .fb_ioctl = psbfb_ioctl, }; static struct drm_framebuffer *psb_framebuffer_create @@ -341,8 +317,6 @@ static struct drm_framebuffer *psb_user_framebuffer_create (struct drm_device *dev, struct drm_file *filp, struct drm_mode_fb_cmd *r) { - return NULL; -#if 0 struct ttm_buffer_object *bo = NULL; uint64_t size; @@ -358,6 +332,7 @@ static struct drm_framebuffer *psb_user_framebuffer_create /* JB: TODO not drop, refcount buffer */ return psb_framebuffer_create(dev, r, bo); +#if 0 struct psb_framebuffer *psbfb; struct drm_framebuffer *fb; struct fb_info *info; @@ -723,15 +698,8 @@ static void psb_setup_outputs(struct drm_device *dev) psb_create_backlight_property(dev); - if (IS_MRST(dev)) { - if (dev_priv->iLVDS_enable) - mrst_lvds_init(dev, &dev_priv->mode_dev); - else - DRM_ERROR("DSI is not supported\n"); - } else { - psb_intel_lvds_init(dev, &dev_priv->mode_dev); - psb_intel_sdvo_init(dev, SDVOB); - } + psb_intel_lvds_init(dev, &dev_priv->mode_dev); + /* psb_intel_sdvo_init(dev, SDVOB); */ list_for_each_entry(connector, &dev->mode_config.connector_list, head) { @@ -748,10 +716,7 @@ static void psb_setup_outputs(struct drm_device *dev) break; case INTEL_OUTPUT_LVDS: PSB_DEBUG_ENTRY("LVDS.\n"); - if (IS_MRST(dev)) - crtc_mask = (1 << 0); - else - crtc_mask = (1 << 1); + crtc_mask = (1 << 1); clone_mask = (1 << INTEL_OUTPUT_LVDS); break; case INTEL_OUTPUT_MIPI: diff --git a/trunk/drivers/staging/gma500/psb_fence.c b/trunk/drivers/staging/gma500/psb_fence.c new file mode 100644 index 000000000000..a70aa64f2cad --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_fence.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2007, Intel Corporation. + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + * + * Authors: Thomas Hellstrom + */ + +#include +#include "psb_drv.h" + + +static void psb_fence_poll(struct ttm_fence_device *fdev, + uint32_t fence_class, uint32_t waiting_types) +{ + struct drm_psb_private *dev_priv = + container_of(fdev, struct drm_psb_private, fdev); + + + if (unlikely(!dev_priv)) + return; + + if (waiting_types == 0) + return; + + /* DRM_ERROR("Polling fence sequence, got 0x%08x\n", sequence); */ + ttm_fence_handler(fdev, fence_class, 0 /* Sequence */, + _PSB_FENCE_TYPE_EXE, 0); +} + +void psb_fence_error(struct drm_device *dev, + uint32_t fence_class, + uint32_t sequence, uint32_t type, int error) +{ + struct drm_psb_private *dev_priv = psb_priv(dev); + struct ttm_fence_device *fdev = &dev_priv->fdev; + unsigned long irq_flags; + struct ttm_fence_class_manager *fc = + &fdev->fence_class[fence_class]; + + BUG_ON(fence_class >= PSB_NUM_ENGINES); + write_lock_irqsave(&fc->lock, irq_flags); + ttm_fence_handler(fdev, fence_class, sequence, type, error); + write_unlock_irqrestore(&fc->lock, irq_flags); +} + +int psb_fence_emit_sequence(struct ttm_fence_device *fdev, + uint32_t fence_class, + uint32_t flags, uint32_t *sequence, + unsigned long *timeout_jiffies) +{ + struct drm_psb_private *dev_priv = + container_of(fdev, struct drm_psb_private, fdev); + + if (!dev_priv) + return -EINVAL; + + if (fence_class >= PSB_NUM_ENGINES) + return -EINVAL; + + DRM_ERROR("Unexpected fence class\n"); + return -EINVAL; +} + +static void psb_fence_lockup(struct ttm_fence_object *fence, + uint32_t fence_types) +{ + DRM_ERROR("Unsupported fence class\n"); +} + +void psb_fence_handler(struct drm_device *dev, uint32_t fence_class) +{ + struct drm_psb_private *dev_priv = psb_priv(dev); + struct ttm_fence_device *fdev = &dev_priv->fdev; + struct ttm_fence_class_manager *fc = + &fdev->fence_class[fence_class]; + unsigned long irq_flags; + + write_lock_irqsave(&fc->lock, irq_flags); + psb_fence_poll(fdev, fence_class, fc->waiting_types); + write_unlock_irqrestore(&fc->lock, irq_flags); +} + + +static struct ttm_fence_driver psb_ttm_fence_driver = { + .has_irq = NULL, + .emit = psb_fence_emit_sequence, + .flush = NULL, + .poll = psb_fence_poll, + .needed_flush = NULL, + .wait = NULL, + .signaled = NULL, + .lockup = psb_fence_lockup, +}; + +int psb_ttm_fence_device_init(struct ttm_fence_device *fdev) +{ + struct drm_psb_private *dev_priv = + container_of(fdev, struct drm_psb_private, fdev); + struct ttm_fence_class_init fci = {.wrap_diff = (1 << 30), + .flush_diff = (1 << 29), + .sequence_mask = 0xFFFFFFFF + }; + + return ttm_fence_device_init(PSB_NUM_ENGINES, + dev_priv->mem_global_ref.object, + fdev, &fci, 1, + &psb_ttm_fence_driver); +} diff --git a/trunk/drivers/staging/gma500/psb_gtt.c b/trunk/drivers/staging/gma500/psb_gtt.c index 093d7dfee893..53c1e1ed3bd2 100644 --- a/trunk/drivers/staging/gma500/psb_gtt.c +++ b/trunk/drivers/staging/gma500/psb_gtt.c @@ -75,10 +75,11 @@ int psb_gtt_init(struct psb_gtt *pg, int resume) struct drm_device *dev = pg->dev; struct drm_psb_private *dev_priv = dev->dev_private; unsigned gtt_pages; - unsigned long stolen_size, vram_stolen_size; + unsigned long stolen_size, vram_stolen_size, ci_stolen_size; + unsigned long rar_stolen_size; unsigned i, num_pages; unsigned pfn_base; - uint32_t vram_pages; + uint32_t ci_pages, vram_pages; uint32_t tt_pages; uint32_t *ttm_gtt_map; uint32_t dvmt_mode = 0; @@ -101,7 +102,7 @@ int psb_gtt_init(struct psb_gtt *pg, int resume) pg->gatt_start = pci_resource_start(dev->pdev, PSB_GATT_RESOURCE); /* fix me: video mmu has hw bug to access 0x0D0000000, * then make gatt start at 0x0e000,0000 */ - pg->mmu_gatt_start = 0xE0000000; + pg->mmu_gatt_start = PSB_MEM_TT_START; pg->gtt_start = pci_resource_start(dev->pdev, PSB_GTT_RESOURCE); gtt_pages = pci_resource_len(dev->pdev, PSB_GTT_RESOURCE) >> PAGE_SHIFT; @@ -111,20 +112,35 @@ int psb_gtt_init(struct psb_gtt *pg, int resume) pci_read_config_dword(dev->pdev, PSB_BSM, &pg->stolen_base); vram_stolen_size = pg->gtt_phys_start - pg->stolen_base - PAGE_SIZE; + /* CI is not included in the stolen size since the TOPAZ MMU bug */ + ci_stolen_size = dev_priv->ci_region_size; + /* Don't add CI & RAR share buffer space + * managed by TTM to stolen_size */ stolen_size = vram_stolen_size; + rar_stolen_size = dev_priv->rar_region_size; + printk(KERN_INFO"GMMADR(region 0) start: 0x%08x (%dM).\n", pg->gatt_start, pg->gatt_pages/256); printk(KERN_INFO"GTTADR(region 3) start: 0x%08x (can map %dM RAM), and actual RAM base 0x%08x.\n", pg->gtt_start, gtt_pages * 4, pg->gtt_phys_start); - printk(KERN_INFO "Stolen memory information\n"); - printk(KERN_INFO " base in RAM: 0x%x\n", pg->stolen_base); - printk(KERN_INFO " size: %luK, calculated by (GTT RAM base) - (Stolen base), seems wrong\n", + printk(KERN_INFO "Stole memory information\n"); + printk(KERN_INFO " base in RAM: 0x%x\n", pg->stolen_base); + printk(KERN_INFO " size: %luK, calculated by (GTT RAM base) - (Stolen base), seems wrong\n", vram_stolen_size/1024); dvmt_mode = (pg->gmch_ctrl >> 4) & 0x7; printk(KERN_INFO " the correct size should be: %dM(dvmt mode=%d)\n", (dvmt_mode == 1) ? 1 : (2 << (dvmt_mode - 1)), dvmt_mode); + if (ci_stolen_size > 0) + printk(KERN_INFO"CI Stole memory: RAM base = 0x%08x, size = %lu M\n", + dev_priv->ci_region_start, + ci_stolen_size / 1024 / 1024); + if (rar_stolen_size > 0) + printk(KERN_INFO "RAR Stole memory: RAM base = 0x%08x, size = %lu M\n", + dev_priv->rar_region_start, + rar_stolen_size / 1024 / 1024); + if (resume && (gtt_pages != pg->gtt_pages) && (stolen_size != pg->stolen_size)) { DRM_ERROR("GTT resume error.\n"); @@ -135,6 +151,8 @@ int psb_gtt_init(struct psb_gtt *pg, int resume) pg->gtt_pages = gtt_pages; pg->stolen_size = stolen_size; pg->vram_stolen_size = vram_stolen_size; + pg->ci_stolen_size = ci_stolen_size; + pg->rar_stolen_size = rar_stolen_size; pg->gtt_map = ioremap_nocache(pg->gtt_phys_start, gtt_pages << PAGE_SHIFT); if (!pg->gtt_map) { @@ -178,6 +196,33 @@ int psb_gtt_init(struct psb_gtt *pg, int resume) for (; i < tt_pages / 2 - 1; ++i) iowrite32(pte, pg->gtt_map + i); + /* + * insert CI stolen pages + */ + + pfn_base = dev_priv->ci_region_start >> PAGE_SHIFT; + ci_pages = num_pages = ci_stolen_size >> PAGE_SHIFT; + printk(KERN_INFO"Set up %d CI stolen pages starting at 0x%08x, GTT offset %dK\n", + num_pages, pfn_base, (ttm_gtt_map - pg->gtt_map) * 4); + for (i = 0; i < num_pages; ++i) { + pte = psb_gtt_mask_pte(pfn_base + i, 0); + iowrite32(pte, ttm_gtt_map + i); + } + + /* + * insert RAR stolen pages + */ + if (rar_stolen_size != 0) { + pfn_base = dev_priv->rar_region_start >> PAGE_SHIFT; + num_pages = rar_stolen_size >> PAGE_SHIFT; + printk(KERN_INFO"Set up %d RAR stolen pages starting at 0x%08x, GTT offset %dK\n", + num_pages, pfn_base, + (ttm_gtt_map - pg->gtt_map + i) * 4); + for (; i < num_pages + ci_pages; ++i) { + pte = psb_gtt_mask_pte(pfn_base + i - ci_pages, 0); + iowrite32(pte, ttm_gtt_map + i); + } + } /* * Init rest of gtt managed by TTM. */ diff --git a/trunk/drivers/staging/gma500/psb_gtt.h b/trunk/drivers/staging/gma500/psb_gtt.h index 8a0ef7783abd..0272f83b461e 100644 --- a/trunk/drivers/staging/gma500/psb_gtt.h +++ b/trunk/drivers/staging/gma500/psb_gtt.h @@ -29,6 +29,8 @@ struct psb_gtt { int initialized; uint32_t gatt_start; uint32_t mmu_gatt_start; + uint32_t ci_start; + uint32_t rar_start; uint32_t gtt_start; uint32_t gtt_phys_start; unsigned gtt_pages; @@ -39,6 +41,8 @@ struct psb_gtt { u16 gmch_ctrl; unsigned long stolen_size; unsigned long vram_stolen_size; + unsigned long ci_stolen_size; + unsigned long rar_stolen_size; uint32_t *gtt_map; struct rw_semaphore sem; }; diff --git a/trunk/drivers/staging/gma500/psb_intel_display.c b/trunk/drivers/staging/gma500/psb_intel_display.c index b462f32670b8..80b37f4ca10a 100644 --- a/trunk/drivers/staging/gma500/psb_intel_display.c +++ b/trunk/drivers/staging/gma500/psb_intel_display.c @@ -359,7 +359,8 @@ int psb_intel_pipe_set_base(struct drm_crtc *crtc, return 0; } - if (!gma_power_begin(dev, true)) + if (!ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_FORCE_POWER_ON)) return 0; Start = mode_dev->bo_offset(dev, psbfb); @@ -404,7 +405,7 @@ int psb_intel_pipe_set_base(struct drm_crtc *crtc, psb_intel_pipe_set_base_exit: - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); return ret; } @@ -815,7 +816,8 @@ void psb_intel_crtc_load_lut(struct drm_crtc *crtc) return; } - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { for (i = 0; i < 256; i++) { REG_WRITE(palreg + 4 * i, ((psb_intel_crtc->lut_r[i] + @@ -825,7 +827,7 @@ void psb_intel_crtc_load_lut(struct drm_crtc *crtc) (psb_intel_crtc->lut_b[i] + psb_intel_crtc->lut_adj[i])); } - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } else { for (i = 0; i < 256; i++) { dev_priv->save_palette_a[i] = @@ -1044,10 +1046,11 @@ static int psb_intel_crtc_cursor_set(struct drm_crtc *crtc, temp = 0; temp |= CURSOR_MODE_DISABLE; - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { REG_WRITE(control, temp); REG_WRITE(base, 0); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } /* unpin the old bo */ @@ -1101,10 +1104,11 @@ static int psb_intel_crtc_cursor_set(struct drm_crtc *crtc, temp |= (pipe << 28); temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE; - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { REG_WRITE(control, temp); REG_WRITE(base, addr); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } /* unpin the old bo */ @@ -1139,10 +1143,11 @@ static int psb_intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) adder = psb_intel_crtc->cursor_addr; - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { REG_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp); REG_WRITE((pipe == 0) ? CURABASE : CURBBASE, adder); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } return 0; } @@ -1192,14 +1197,15 @@ static int psb_intel_crtc_clock_get(struct drm_device *dev, bool is_lvds; struct drm_psb_private *dev_priv = dev->dev_private; - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { dpll = REG_READ((pipe == 0) ? DPLL_A : DPLL_B); if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) fp = REG_READ((pipe == 0) ? FPA0 : FPB0); else fp = REG_READ((pipe == 0) ? FPA1 : FPB1); is_lvds = (pipe == 1) && (REG_READ(LVDS) & LVDS_PORT_EN); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } else { dpll = (pipe == 0) ? dev_priv->saveDPLL_A : dev_priv->saveDPLL_B; @@ -1271,12 +1277,13 @@ struct drm_display_mode *psb_intel_crtc_mode_get(struct drm_device *dev, int vsync; struct drm_psb_private *dev_priv = dev->dev_private; - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { htot = REG_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B); hsync = REG_READ((pipe == 0) ? HSYNC_A : HSYNC_B); vtot = REG_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B); vsync = REG_READ((pipe == 0) ? VSYNC_A : VSYNC_B); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } else { htot = (pipe == 0) ? dev_priv->saveHTOTAL_A : dev_priv->saveHTOTAL_B; @@ -1326,6 +1333,10 @@ static const struct drm_crtc_helper_funcs psb_intel_helper_funcs = { .commit = psb_intel_crtc_commit, }; +static const struct drm_crtc_helper_funcs mrst_helper_funcs; +static const struct drm_crtc_helper_funcs mdfld_helper_funcs; +const struct drm_crtc_funcs mdfld_intel_crtc_funcs; + const struct drm_crtc_funcs psb_intel_crtc_funcs = { .save = psb_intel_crtc_save, .restore = psb_intel_crtc_restore, @@ -1386,11 +1397,7 @@ void psb_intel_crtc_init(struct drm_device *dev, int pipe, psb_intel_crtc->mode_dev = mode_dev; psb_intel_crtc->cursor_addr = 0; - if (IS_MRST(dev)) - drm_crtc_helper_add(&psb_intel_crtc->base, - &mrst_helper_funcs); - else - drm_crtc_helper_add(&psb_intel_crtc->base, + drm_crtc_helper_add(&psb_intel_crtc->base, &psb_intel_helper_funcs); /* Setup the array of drm_connector pointer array */ diff --git a/trunk/drivers/staging/gma500/psb_intel_lvds.c b/trunk/drivers/staging/gma500/psb_intel_lvds.c index 28e04a3e7b6f..d3d210a1026a 100644 --- a/trunk/drivers/staging/gma500/psb_intel_lvds.c +++ b/trunk/drivers/staging/gma500/psb_intel_lvds.c @@ -83,12 +83,13 @@ static u32 psb_intel_lvds_get_max_backlight(struct drm_device *dev) struct drm_psb_private *dev_priv = dev->dev_private; u32 retVal; - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { retVal = ((REG_READ(BLC_PWM_CTL) & BACKLIGHT_MODULATION_FREQ_MASK) >> BACKLIGHT_MODULATION_FREQ_SHIFT) * 2; - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } else retVal = ((dev_priv->saveBLC_PWM_CTL & BACKLIGHT_MODULATION_FREQ_MASK) >> @@ -199,13 +200,14 @@ static void psb_intel_lvds_set_backlight(struct drm_device *dev, int level) struct drm_psb_private *dev_priv = dev->dev_private; u32 blc_pwm_ctl; - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { blc_pwm_ctl = REG_READ(BLC_PWM_CTL) & ~BACKLIGHT_DUTY_CYCLE_MASK; REG_WRITE(BLC_PWM_CTL, (blc_pwm_ctl | (level << BACKLIGHT_DUTY_CYCLE_SHIFT))); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } else { blc_pwm_ctl = dev_priv->saveBLC_PWM_CTL & ~BACKLIGHT_DUTY_CYCLE_MASK; @@ -222,7 +224,8 @@ static void psb_intel_lvds_set_power(struct drm_device *dev, { u32 pp_status; - if (!gma_power_begin(dev, true)) + if (!ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_FORCE_POWER_ON)) return; if (on) { @@ -245,7 +248,7 @@ static void psb_intel_lvds_set_power(struct drm_device *dev, } while (pp_status & PP_ON); } - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } static void psb_intel_lvds_encoder_dpms(struct drm_encoder *encoder, int mode) @@ -397,15 +400,11 @@ bool psb_intel_lvds_mode_fixup(struct drm_encoder *encoder, if (psb_intel_output->type == INTEL_OUTPUT_MIPI2) panel_fixed_mode = mode_dev->panel_fixed_mode2; - /* PSB requires the LVDS is on pipe B, MRST has only one pipe anyway */ - if (!IS_MRST(dev) && psb_intel_crtc->pipe == 0) { + /* PSB doesn't appear to be GEN4 */ + if (psb_intel_crtc->pipe == 0) { printk(KERN_ERR "Can't support LVDS on pipe A\n"); return false; } - if (IS_MRST(dev) && psb_intel_crtc->pipe != 0) { - printk(KERN_ERR "Must use PIPE A\n"); - return false; - } /* Should never happen!! */ list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) { @@ -446,7 +445,7 @@ bool psb_intel_lvds_mode_fixup(struct drm_encoder *encoder, return true; } -void psb_intel_lvds_prepare(struct drm_encoder *encoder) +static void psb_intel_lvds_prepare(struct drm_encoder *encoder) { struct drm_device *dev = encoder->dev; struct psb_intel_output *output = enc_to_psb_intel_output(encoder); @@ -454,7 +453,8 @@ void psb_intel_lvds_prepare(struct drm_encoder *encoder) PSB_DEBUG_ENTRY("\n"); - if (!gma_power_begin(dev, true)) + if (!ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_FORCE_POWER_ON)) return; mode_dev->saveBLC_PWM_CTL = REG_READ(BLC_PWM_CTL); @@ -463,10 +463,10 @@ void psb_intel_lvds_prepare(struct drm_encoder *encoder) psb_intel_lvds_set_power(dev, output, false); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } -void psb_intel_lvds_commit(struct drm_encoder *encoder) +static void psb_intel_lvds_commit(struct drm_encoder *encoder) { struct drm_device *dev = encoder->dev; struct psb_intel_output *output = enc_to_psb_intel_output(encoder); @@ -669,14 +669,14 @@ static const struct drm_encoder_helper_funcs psb_intel_lvds_helper_funcs = { .commit = psb_intel_lvds_commit, }; -const struct drm_connector_helper_funcs +static const struct drm_connector_helper_funcs psb_intel_lvds_connector_helper_funcs = { .get_modes = psb_intel_lvds_get_modes, .mode_valid = psb_intel_lvds_mode_valid, .best_encoder = psb_intel_best_encoder, }; -const struct drm_connector_funcs psb_intel_lvds_connector_funcs = { +static const struct drm_connector_funcs psb_intel_lvds_connector_funcs = { .dpms = drm_helper_connector_dpms, .save = psb_intel_lvds_save, .restore = psb_intel_lvds_restore, diff --git a/trunk/drivers/staging/gma500/psb_intel_sdvo.c b/trunk/drivers/staging/gma500/psb_intel_sdvo.c index df1c006ecfaa..1d2bb021c0a5 100644 --- a/trunk/drivers/staging/gma500/psb_intel_sdvo.c +++ b/trunk/drivers/staging/gma500/psb_intel_sdvo.c @@ -204,7 +204,7 @@ static void psb_intel_sdvo_write_cmd(struct psb_intel_output *psb_intel_output, struct psb_intel_sdvo_priv *sdvo_priv = psb_intel_output->dev_priv; int i; - if (0) { + if (1) { DRM_DEBUG("%s: W: %02X ", SDVO_NAME(sdvo_priv), cmd); for (i = 0; i < args_len; i++) printk(KERN_INFO"%02X ", ((u8 *) args)[i]); @@ -266,7 +266,7 @@ static u8 psb_intel_sdvo_read_response( SDVO_I2C_CMD_STATUS, &status); - if (0) { + if (1) { DRM_DEBUG("%s: R: ", SDVO_NAME(sdvo_priv)); for (i = 0; i < response_len; i++) printk(KERN_INFO"%02X ", ((u8 *) response)[i]); diff --git a/trunk/drivers/staging/gma500/psb_irq.c b/trunk/drivers/staging/gma500/psb_irq.c index 9ea37e588874..4597c8824721 100644 --- a/trunk/drivers/staging/gma500/psb_irq.c +++ b/trunk/drivers/staging/gma500/psb_irq.c @@ -88,12 +88,13 @@ psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask) u32 reg = psb_pipestat(pipe); dev_priv->pipestat[pipe] |= mask; /* Enable the interrupt, clear any pending status */ - if (gma_power_begin(dev_priv->dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { u32 writeVal = PSB_RVDC32(reg); writeVal |= (mask | (mask >> 16)); PSB_WVDC32(writeVal, reg); (void) PSB_RVDC32(reg); - gma_power_end(dev_priv->dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } } } @@ -104,36 +105,39 @@ psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask) if ((dev_priv->pipestat[pipe] & mask) != 0) { u32 reg = psb_pipestat(pipe); dev_priv->pipestat[pipe] &= ~mask; - if (gma_power_begin(dev_priv->dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { u32 writeVal = PSB_RVDC32(reg); writeVal &= ~mask; PSB_WVDC32(writeVal, reg); (void) PSB_RVDC32(reg); - gma_power_end(dev_priv->dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } } } void mid_enable_pipe_event(struct drm_psb_private *dev_priv, int pipe) { - if (gma_power_begin(dev_priv->dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { u32 pipe_event = mid_pipe_event(pipe); dev_priv->vdc_irq_mask |= pipe_event; PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R); PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); - gma_power_end(dev_priv->dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } } void mid_disable_pipe_event(struct drm_psb_private *dev_priv, int pipe) { if (dev_priv->pipestat[pipe] == 0) { - if (gma_power_begin(dev_priv->dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { u32 pipe_event = mid_pipe_event(pipe); dev_priv->vdc_irq_mask &= ~pipe_event; PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R); PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); - gma_power_end(dev_priv->dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } } } @@ -238,7 +242,7 @@ irqreturn_t psb_irq_handler(DRM_IRQ_ARGS) vdc_stat &= dev_priv->vdc_irq_mask; spin_unlock(&dev_priv->irqmask_lock); - if (dsp_int && gma_power_is_on(dev)) { + if (dsp_int && ospm_power_is_hw_on(OSPM_DISPLAY_ISLAND)) { psb_vdc_interrupt(dev, vdc_stat); handled = 1; } @@ -266,29 +270,55 @@ irqreturn_t psb_irq_handler(DRM_IRQ_ARGS) } void psb_irq_preinstall(struct drm_device *dev) +{ + psb_irq_preinstall_islands(dev, OSPM_ALL_ISLANDS); +} + +/** + * FIXME: should I remove display irq enable here?? + */ +void psb_irq_preinstall_islands(struct drm_device *dev, int hw_islands) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; unsigned long irqflags; - spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); + PSB_DEBUG_ENTRY("\n"); - if (gma_power_is_on(dev)) - PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); - if (dev->vblank_enabled[0]) - dev_priv->vdc_irq_mask |= _PSB_PIPEA_EVENT_FLAG; - if (dev->vblank_enabled[1]) - dev_priv->vdc_irq_mask |= _MDFLD_PIPEB_EVENT_FLAG; - if (dev->vblank_enabled[2]) - dev_priv->vdc_irq_mask |= _MDFLD_PIPEC_EVENT_FLAG; + spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); + if (hw_islands & OSPM_DISPLAY_ISLAND) { + if (ospm_power_is_hw_on(OSPM_DISPLAY_ISLAND)) { + PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); + if (dev->vblank_enabled[0]) + dev_priv->vdc_irq_mask |= + _PSB_PIPEA_EVENT_FLAG; + if (dev->vblank_enabled[1]) + dev_priv->vdc_irq_mask |= + _MDFLD_PIPEB_EVENT_FLAG; + if (dev->vblank_enabled[2]) + dev_priv->vdc_irq_mask |= + _MDFLD_PIPEC_EVENT_FLAG; + } + } +/* NO I DONT WANT ANY IRQS GRRR FIXMEAC */ + if (hw_islands & OSPM_GRAPHICS_ISLAND) + dev_priv->vdc_irq_mask |= _PSB_IRQ_SGX_FLAG; +/* */ /*This register is safe even if display island is off*/ PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R); + spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); } int psb_irq_postinstall(struct drm_device *dev) { + return psb_irq_postinstall_islands(dev, OSPM_ALL_ISLANDS); +} + +int psb_irq_postinstall_islands(struct drm_device *dev, int hw_islands) +{ + struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; unsigned long irqflags; @@ -297,30 +327,47 @@ int psb_irq_postinstall(struct drm_device *dev) spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); - /* This register is safe even if display island is off */ + /*This register is safe even if display island is off*/ PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); - PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); - - if (dev->vblank_enabled[0]) - psb_enable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE); - else - psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE); - if (dev->vblank_enabled[1]) - psb_enable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE); - else - psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE); - - if (dev->vblank_enabled[2]) - psb_enable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE); - else - psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE); + if (hw_islands & OSPM_DISPLAY_ISLAND) { + if (true/*powermgmt_is_hw_on(dev->pdev, PSB_DISPLAY_ISLAND)*/) { + PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); + + if (dev->vblank_enabled[0]) + psb_enable_pipestat(dev_priv, 0, + PIPE_VBLANK_INTERRUPT_ENABLE); + else + psb_disable_pipestat(dev_priv, 0, + PIPE_VBLANK_INTERRUPT_ENABLE); + + if (dev->vblank_enabled[1]) + psb_enable_pipestat(dev_priv, 1, + PIPE_VBLANK_INTERRUPT_ENABLE); + else + psb_disable_pipestat(dev_priv, 1, + PIPE_VBLANK_INTERRUPT_ENABLE); + + if (dev->vblank_enabled[2]) + psb_enable_pipestat(dev_priv, 2, + PIPE_VBLANK_INTERRUPT_ENABLE); + else + psb_disable_pipestat(dev_priv, 2, + PIPE_VBLANK_INTERRUPT_ENABLE); + } + } spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); + return 0; } void psb_irq_uninstall(struct drm_device *dev) +{ + psb_irq_uninstall_islands(dev, OSPM_ALL_ISLANDS); +} + +void psb_irq_uninstall_islands(struct drm_device *dev, int hw_islands) { struct drm_psb_private *dev_priv = (struct drm_psb_private *) dev->dev_private; @@ -330,29 +377,39 @@ void psb_irq_uninstall(struct drm_device *dev) spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); - PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); - - if (dev->vblank_enabled[0]) - psb_disable_pipestat(dev_priv, 0, PIPE_VBLANK_INTERRUPT_ENABLE); + if (hw_islands & OSPM_DISPLAY_ISLAND) { + if (true/*powermgmt_is_hw_on(dev->pdev, PSB_DISPLAY_ISLAND)*/) { + PSB_WVDC32(0xFFFFFFFF, PSB_HWSTAM); - if (dev->vblank_enabled[1]) - psb_disable_pipestat(dev_priv, 1, PIPE_VBLANK_INTERRUPT_ENABLE); + if (dev->vblank_enabled[0]) + psb_disable_pipestat(dev_priv, 0, + PIPE_VBLANK_INTERRUPT_ENABLE); - if (dev->vblank_enabled[2]) - psb_disable_pipestat(dev_priv, 2, PIPE_VBLANK_INTERRUPT_ENABLE); + if (dev->vblank_enabled[1]) + psb_disable_pipestat(dev_priv, 1, + PIPE_VBLANK_INTERRUPT_ENABLE); - dev_priv->vdc_irq_mask &= _PSB_IRQ_SGX_FLAG | - _PSB_IRQ_MSVDX_FLAG | - _LNC_IRQ_TOPAZ_FLAG; + if (dev->vblank_enabled[2]) + psb_disable_pipestat(dev_priv, 2, + PIPE_VBLANK_INTERRUPT_ENABLE); + } + dev_priv->vdc_irq_mask &= _PSB_IRQ_SGX_FLAG | + _PSB_IRQ_MSVDX_FLAG | + _LNC_IRQ_TOPAZ_FLAG; + } + /*TODO: remove following code*/ + if (hw_islands & OSPM_GRAPHICS_ISLAND) + dev_priv->vdc_irq_mask &= ~_PSB_IRQ_SGX_FLAG; - /* These two registers are safe even if display island is off */ + /*These two registers are safe even if display island is off*/ PSB_WVDC32(~dev_priv->vdc_irq_mask, PSB_INT_MASK_R); PSB_WVDC32(dev_priv->vdc_irq_mask, PSB_INT_ENABLE_R); wmb(); - /* This register is safe even if display island is off */ + /*This register is safe even if display island is off*/ PSB_WVDC32(PSB_RVDC32(PSB_INT_IDENTITY_R), PSB_INT_IDENTITY_R); + spin_unlock_irqrestore(&dev_priv->irqmask_lock, irqflags); } @@ -363,7 +420,8 @@ void psb_irq_turn_on_dpst(struct drm_device *dev) u32 hist_reg; u32 pwm_reg; - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { PSB_WVDC32(1 << 31, HISTOGRAM_LOGIC_CONTROL); hist_reg = PSB_RVDC32(HISTOGRAM_LOGIC_CONTROL); PSB_WVDC32(1 << 31, HISTOGRAM_INT_CONTROL); @@ -385,7 +443,7 @@ void psb_irq_turn_on_dpst(struct drm_device *dev) PSB_WVDC32(pwm_reg | 0x80010100 | PWM_PHASEIN_ENABLE, PWM_CONTROL_LOGIC); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } } @@ -414,7 +472,8 @@ void psb_irq_turn_off_dpst(struct drm_device *dev) u32 hist_reg; u32 pwm_reg; - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { PSB_WVDC32(0x00000000, HISTOGRAM_INT_CONTROL); hist_reg = PSB_RVDC32(HISTOGRAM_INT_CONTROL); @@ -425,7 +484,7 @@ void psb_irq_turn_off_dpst(struct drm_device *dev) PWM_CONTROL_LOGIC); pwm_reg = PSB_RVDC32(PWM_CONTROL_LOGIC); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } } @@ -467,16 +526,18 @@ static int psb_vblank_do_wait(struct drm_device *dev, */ int psb_enable_vblank(struct drm_device *dev, int pipe) { - struct drm_psb_private *dev_priv = dev->dev_private; + struct drm_psb_private *dev_priv = + (struct drm_psb_private *) dev->dev_private; unsigned long irqflags; uint32_t reg_val = 0; uint32_t pipeconf_reg = mid_pipeconf(pipe); PSB_DEBUG_ENTRY("\n"); - if (gma_power_begin(dev, false)) { + if (ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, + OSPM_UHB_ONLY_IF_ON)) { reg_val = REG_READ(pipeconf_reg); - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); } if (!(reg_val & PIPEACONF_ENABLE)) @@ -484,6 +545,7 @@ int psb_enable_vblank(struct drm_device *dev, int pipe) spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); + drm_psb_disable_vsync = 0; mid_enable_pipe_event(dev_priv, pipe); psb_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE); @@ -497,13 +559,15 @@ int psb_enable_vblank(struct drm_device *dev, int pipe) */ void psb_disable_vblank(struct drm_device *dev, int pipe) { - struct drm_psb_private *dev_priv = dev->dev_private; + struct drm_psb_private *dev_priv = + (struct drm_psb_private *) dev->dev_private; unsigned long irqflags; PSB_DEBUG_ENTRY("\n"); spin_lock_irqsave(&dev_priv->irqmask_lock, irqflags); + drm_psb_disable_vsync = 1; mid_disable_pipe_event(dev_priv, pipe); psb_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_ENABLE); @@ -539,7 +603,7 @@ u32 psb_get_vblank_counter(struct drm_device *dev, int pipe) return 0; } - if (!gma_power_begin(dev, false)) + if (!ospm_power_using_hw_begin(OSPM_DISPLAY_ISLAND, false)) return 0; reg_val = REG_READ(pipeconf_reg); @@ -568,7 +632,7 @@ u32 psb_get_vblank_counter(struct drm_device *dev, int pipe) psb_get_vblank_counter_exit: - gma_power_end(dev); + ospm_power_using_hw_end(OSPM_DISPLAY_ISLAND); return count; } diff --git a/trunk/drivers/staging/gma500/psb_mmu.c b/trunk/drivers/staging/gma500/psb_mmu.c index c904d73b1de3..edd0d4923e0f 100644 --- a/trunk/drivers/staging/gma500/psb_mmu.c +++ b/trunk/drivers/staging/gma500/psb_mmu.c @@ -444,6 +444,67 @@ static inline void psb_mmu_invalidate_pte(struct psb_mmu_pt *pt, pt->v[psb_mmu_pt_index(addr)] = pt->pd->invalid_pte; } +#if 0 +static uint32_t psb_mmu_check_pte_locked(struct psb_mmu_pd *pd, + uint32_t mmu_offset) +{ + uint32_t *v; + uint32_t pfn; + + v = kmap_atomic(pd->p, KM_USER0); + if (!v) { + printk(KERN_INFO "Could not kmap pde page.\n"); + return 0; + } + pfn = v[psb_mmu_pd_index(mmu_offset)]; + /* printk(KERN_INFO "pde is 0x%08x\n",pfn); */ + kunmap_atomic(v, KM_USER0); + if (((pfn & 0x0F) != PSB_PTE_VALID)) { + printk(KERN_INFO "Strange pde at 0x%08x: 0x%08x.\n", + mmu_offset, pfn); + } + v = ioremap(pfn & 0xFFFFF000, 4096); + if (!v) { + printk(KERN_INFO "Could not kmap pte page.\n"); + return 0; + } + pfn = v[psb_mmu_pt_index(mmu_offset)]; + /* printk(KERN_INFO "pte is 0x%08x\n",pfn); */ + iounmap(v); + if (((pfn & 0x0F) != PSB_PTE_VALID)) { + printk(KERN_INFO "Strange pte at 0x%08x: 0x%08x.\n", + mmu_offset, pfn); + } + return pfn >> PAGE_SHIFT; +} + +static void psb_mmu_check_mirrored_gtt(struct psb_mmu_pd *pd, + uint32_t mmu_offset, + uint32_t gtt_pages) +{ + uint32_t start; + uint32_t next; + + printk(KERN_INFO "Checking mirrored gtt 0x%08x %d\n", + mmu_offset, gtt_pages); + down_read(&pd->driver->sem); + start = psb_mmu_check_pte_locked(pd, mmu_offset); + mmu_offset += PAGE_SIZE; + gtt_pages -= 1; + while (gtt_pages--) { + next = psb_mmu_check_pte_locked(pd, mmu_offset); + if (next != start + 1) { + printk(KERN_INFO + "Ptes out of order: 0x%08x, 0x%08x.\n", + start, next); + } + start = next; + mmu_offset += PAGE_SIZE; + } + up_read(&pd->driver->sem); +} + +#endif void psb_mmu_mirror_gtt(struct psb_mmu_pd *pd, uint32_t mmu_offset, uint32_t gtt_start, diff --git a/trunk/drivers/staging/gma500/psb_powermgmt.c b/trunk/drivers/staging/gma500/psb_powermgmt.c index fc0ed7ab1973..7deb1ba82545 100644 --- a/trunk/drivers/staging/gma500/psb_powermgmt.c +++ b/trunk/drivers/staging/gma500/psb_powermgmt.c @@ -24,73 +24,83 @@ * Authors: * Benjamin Defnet * Rajesh Poornachandran - * Massively reworked - * Alan Cox + * */ #include "psb_powermgmt.h" #include "psb_drv.h" -#include "psb_reg.h" #include "psb_intel_reg.h" #include #include +#undef OSPM_GFX_DPK + +extern u32 gui32SGXDeviceID; +extern u32 gui32MRSTDisplayDeviceID; +extern u32 gui32MRSTMSVDXDeviceID; +extern u32 gui32MRSTTOPAZDeviceID; + +struct drm_device *gpDrmDevice = NULL; static struct mutex power_mutex; +static bool gbSuspendInProgress = false; +static bool gbResumeInProgress = false; +static int g_hw_power_status_mask; +static atomic_t g_display_access_count; +static atomic_t g_graphics_access_count; +static atomic_t g_videoenc_access_count; +static atomic_t g_videodec_access_count; +int allow_runtime_pm = 0; + +void ospm_power_island_up(int hw_islands); +void ospm_power_island_down(int hw_islands); +static bool gbSuspended = false; +bool gbgfxsuspended = false; -/** - * gma_power_init - initialise power manager - * @dev: our device +/* + * ospm_power_init * - * Set up for power management tracking of our hardware. + * Description: Initialize this ospm power management module */ -void gma_power_init(struct drm_device *dev) +void ospm_power_init(struct drm_device *dev) { - struct drm_psb_private *dev_priv = dev->dev_private; + struct drm_psb_private *dev_priv = (struct drm_psb_private *)dev->dev_private; + + gpDrmDevice = dev; dev_priv->apm_base = dev_priv->apm_reg & 0xffff; dev_priv->ospm_base &= 0xffff; - dev_priv->display_power = true; /* We start active */ - dev_priv->display_count = 0; /* Currently no users */ - dev_priv->suspended = false; /* And not suspended */ mutex_init(&power_mutex); - - if (!IS_MRST(dev)) { - /* FIXME: wants further review */ - u32 gating = PSB_RSGX32(PSB_CR_CLKGATECTL); - /* Disable 2D clock gating */ - gating &= ~3; - gating |= 1; - PSB_WSGX32(gating, PSB_CR_CLKGATECTL); - PSB_RSGX32(PSB_CR_CLKGATECTL); - } + g_hw_power_status_mask = OSPM_ALL_ISLANDS; + atomic_set(&g_display_access_count, 0); + atomic_set(&g_graphics_access_count, 0); + atomic_set(&g_videoenc_access_count, 0); + atomic_set(&g_videodec_access_count, 0); } -/** - * gma_power_uninit - end power manager - * @dev: device to end for +/* + * ospm_power_uninit * - * Undo the effects of gma_power_init + * Description: Uninitialize this ospm power management module */ -void gma_power_uninit(struct drm_device *dev) +void ospm_power_uninit(void) { mutex_destroy(&power_mutex); - pm_runtime_disable(&dev->pdev->dev); - pm_runtime_set_suspended(&dev->pdev->dev); + pm_runtime_disable(&gpDrmDevice->pdev->dev); + pm_runtime_set_suspended(&gpDrmDevice->pdev->dev); } -/** - * save_display_registers - save registers lost on suspend - * @dev: our DRM device +/* + * save_display_registers * - * Save the state we need in order to be able to restore the interface - * upon resume from suspend + * Description: We are going to suspend so save current display + * register state. */ static int save_display_registers(struct drm_device *dev) { struct drm_psb_private *dev_priv = dev->dev_private; - struct drm_crtc *crtc; - struct drm_connector *connector; + struct drm_crtc * crtc; + struct drm_connector * connector; /* Display arbitration control + watermarks */ dev_priv->saveDSPARB = PSB_RVDC32(DSPARB); @@ -102,31 +112,37 @@ static int save_display_registers(struct drm_device *dev) dev_priv->saveDSPFW6 = PSB_RVDC32(DSPFW6); dev_priv->saveCHICKENBIT = PSB_RVDC32(DSPCHICKENBIT); - /* Save crtc and output state */ + /*save crtc and output state*/ mutex_lock(&dev->mode_config.mutex); list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { - if (drm_helper_crtc_in_use(crtc)) + if(drm_helper_crtc_in_use(crtc)) { crtc->funcs->save(crtc); + } } - list_for_each_entry(connector, &dev->mode_config.connector_list, head) + list_for_each_entry(connector, &dev->mode_config.connector_list, head) { connector->funcs->save(connector); - + } mutex_unlock(&dev->mode_config.mutex); + + /* Interrupt state */ + /* + * Handled in psb_irq.c + */ + return 0; } -/** - * restore_display_registers - restore lost register state - * @dev: our DRM device +/* + * restore_display_registers * - * Restore register state that was lost during suspend and resume. + * Description: We are going to resume so restore display register state. */ static int restore_display_registers(struct drm_device *dev) { struct drm_psb_private *dev_priv = dev->dev_private; - struct drm_crtc *crtc; - struct drm_connector *connector; + struct drm_crtc * crtc; + struct drm_connector * connector; /* Display arbitration + watermarks */ PSB_WVDC32(dev_priv->saveDSPARB, DSPARB); @@ -142,57 +158,39 @@ static int restore_display_registers(struct drm_device *dev) PSB_WVDC32(0x80000000, VGACNTRL); mutex_lock(&dev->mode_config.mutex); - list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) - if (drm_helper_crtc_in_use(crtc)) + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + if(drm_helper_crtc_in_use(crtc)) crtc->funcs->restore(crtc); - - list_for_each_entry(connector, &dev->mode_config.connector_list, head) + } + list_for_each_entry(connector, &dev->mode_config.connector_list, head) { connector->funcs->restore(connector); - + } mutex_unlock(&dev->mode_config.mutex); - return 0; -} - -/** - * power_down - power down the display island - * @dev: our DRM device - * - * Power down the display interface of our device - */ -static void power_down(struct drm_device *dev) -{ - struct drm_psb_private *dev_priv = dev->dev_private; - u32 pwr_mask ; - u32 pwr_sts; - if (IS_MRST(dev)) { - pwr_mask = PSB_PWRGT_DISPLAY_MASK; - outl(pwr_mask, dev_priv->ospm_base + PSB_PM_SSC); + /*Interrupt state*/ + /* + * Handled in psb_irq.c + */ - while (true) { - pwr_sts = inl(dev_priv->ospm_base + PSB_PM_SSS); - if ((pwr_sts & pwr_mask) == pwr_mask) - break; - else - udelay(10); - } - dev_priv->display_power = false; - } + return 0; } - - -/** - * gma_suspend_display - suspend the display logic - * @dev: our DRM device +/* + * powermgmt_suspend_display * - * Suspend the display logic of the graphics interface + * Description: Suspend the display hardware saving state and disabling + * as necessary. */ -static void gma_suspend_display(struct drm_device *dev) +void ospm_suspend_display(struct drm_device *dev) { struct drm_psb_private *dev_priv = dev->dev_private; - int pp_stat; + int pp_stat, ret=0; + + printk(KERN_ALERT "%s \n", __func__); - if (dev_priv->suspended) +#ifdef OSPM_GFX_DPK + printk(KERN_ALERT "%s \n", __func__); +#endif + if (!(g_hw_power_status_mask & OSPM_DISPLAY_ISLAND)) return; save_display_registers(dev); @@ -227,55 +225,33 @@ static void gma_suspend_display(struct drm_device *dev) != DPI_FIFO_EMPTY); PSB_WVDC32(0, DEVICE_READY_REG); /* turn off panel power */ + ret = 0; } - power_down(dev); + ospm_power_island_down(OSPM_DISPLAY_ISLAND); } /* - * power_up + * ospm_resume_display * - * Description: Restore power to the specified island(s) (powergating) + * Description: Resume the display hardware restoring state and enabling + * as necessary. */ -static void power_up(struct drm_device *dev) -{ - struct drm_psb_private *dev_priv = dev->dev_private; - u32 pwr_mask = PSB_PWRGT_DISPLAY_MASK; - u32 pwr_sts, pwr_cnt; - - if (IS_MRST(dev)) { - pwr_cnt = inl(dev_priv->ospm_base + PSB_PM_SSC); - pwr_cnt &= ~pwr_mask; - outl(pwr_cnt, (dev_priv->ospm_base + PSB_PM_SSC)); - - while (true) { - pwr_sts = inl(dev_priv->ospm_base + PSB_PM_SSS); - if ((pwr_sts & pwr_mask) == 0) - break; - else - udelay(10); - } - } - dev_priv->suspended = false; - dev_priv->display_power = true; -} - -/** - * gma_resume_display - resume display side logic - * - * Resume the display hardware restoring state and enabling - * as necessary. - */ -static void gma_resume_display(struct pci_dev *pdev) +void ospm_resume_display(struct pci_dev *pdev) { struct drm_device *dev = pci_get_drvdata(pdev); struct drm_psb_private *dev_priv = dev->dev_private; struct psb_gtt *pg = dev_priv->pg; - if (dev_priv->suspended == false) + printk(KERN_ALERT "%s \n", __func__); + +#ifdef OSPM_GFX_DPK + printk(KERN_ALERT "%s \n", __func__); +#endif + if (g_hw_power_status_mask & OSPM_DISPLAY_ISLAND) return; /* turn on the display power island */ - power_up(dev); + ospm_power_island_up(OSPM_DISPLAY_ISLAND); PSB_WVDC32(pg->pge_ctl | _PSB_PGETBL_ENABLED, PSB_PGETBL_CTL); pci_write_config_word(pdev, PSB_GMCH_CTRL, @@ -291,21 +267,26 @@ static void gma_resume_display(struct pci_dev *pdev) restore_display_registers(dev); } -/** - * gma_suspend_pci - suspend PCI side - * @pdev: PCI device +#if 1 +/* + * ospm_suspend_pci * - * Perform the suspend processing on our PCI device state + * Description: Suspend the pci device saving state and disabling + * as necessary. */ -static void gma_suspend_pci(struct pci_dev *pdev) +static void ospm_suspend_pci(struct pci_dev *pdev) { struct drm_device *dev = pci_get_drvdata(pdev); struct drm_psb_private *dev_priv = dev->dev_private; int bsm, vbt; - if (dev_priv->suspended) + if (gbSuspended) return; +#ifdef OSPM_GFX_DPK + printk(KERN_ALERT "ospm_suspend_pci\n"); +#endif + pci_save_state(pdev); pci_read_config_dword(pdev, 0x5C, &bsm); dev_priv->saveBSM = bsm; @@ -317,25 +298,29 @@ static void gma_suspend_pci(struct pci_dev *pdev) pci_disable_device(pdev); pci_set_power_state(pdev, PCI_D3hot); - dev_priv->suspended = true; + gbSuspended = true; + gbgfxsuspended = true; } -/** - * gma_resume_pci - resume helper - * @dev: our PCI device +/* + * ospm_resume_pci * - * Perform the resume processing on our PCI device state - rewrite - * register state and re-enable the PCI device + * Description: Resume the pci device restoring state and enabling + * as necessary. */ -static bool gma_resume_pci(struct pci_dev *pdev) +static bool ospm_resume_pci(struct pci_dev *pdev) { struct drm_device *dev = pci_get_drvdata(pdev); struct drm_psb_private *dev_priv = dev->dev_private; - int ret; + int ret = 0; - if (!dev_priv->suspended) + if (!gbSuspended) return true; +#ifdef OSPM_GFX_DPK + printk(KERN_ALERT "ospm_resume_pci\n"); +#endif + pci_set_power_state(pdev, PCI_D0); pci_restore_state(pdev); pci_write_config_dword(pdev, 0x5c, dev_priv->saveBSM); @@ -346,131 +331,448 @@ static bool gma_resume_pci(struct pci_dev *pdev) ret = pci_enable_device(pdev); if (ret != 0) - dev_err(&pdev->dev, "pci_enable failed: %d\n", ret); + printk(KERN_ALERT "ospm_resume_pci: pci_enable_device failed: %d\n", ret); else - dev_priv->suspended = false; - return !dev_priv->suspended; + gbSuspended = false; + + return !gbSuspended; +} +#endif +/* + * ospm_power_suspend + * + * Description: OSPM is telling our driver to suspend so save state + * and power down all hardware. + */ +int ospm_power_suspend(struct pci_dev *pdev, pm_message_t state) +{ + int ret = 0; + int graphics_access_count; + int videoenc_access_count; + int videodec_access_count; + int display_access_count; + bool suspend_pci = true; + + if(gbSuspendInProgress || gbResumeInProgress) + { +#ifdef OSPM_GFX_DPK + printk(KERN_ALERT "OSPM_GFX_DPK: %s system BUSY \n", __func__); +#endif + return -EBUSY; + } + + mutex_lock(&power_mutex); + + if (!gbSuspended) { + graphics_access_count = atomic_read(&g_graphics_access_count); + videoenc_access_count = atomic_read(&g_videoenc_access_count); + videodec_access_count = atomic_read(&g_videodec_access_count); + display_access_count = atomic_read(&g_display_access_count); + + if (graphics_access_count || + videoenc_access_count || + videodec_access_count || + display_access_count) + ret = -EBUSY; + + if (!ret) { + gbSuspendInProgress = true; + + psb_irq_uninstall_islands(gpDrmDevice, OSPM_DISPLAY_ISLAND); + ospm_suspend_display(gpDrmDevice); + if (suspend_pci == true) { + ospm_suspend_pci(pdev); + } + gbSuspendInProgress = false; + } else { + printk(KERN_ALERT "ospm_power_suspend: device busy: graphics %d videoenc %d videodec %d display %d\n", graphics_access_count, videoenc_access_count, videodec_access_count, display_access_count); + } + } + + + mutex_unlock(&power_mutex); + return ret; } -/** - * gma_power_suspend - bus callback for suspend - * @pdev: our PCI device - * @state: suspend type +/* + * ospm_power_island_up * - * Called back by the PCI layer during a suspend of the system. We - * perform the necessary shut down steps and save enough state that - * we can undo this when resume is called. + * Description: Restore power to the specified island(s) (powergating) */ -int gma_power_suspend(struct pci_dev *pdev, pm_message_t state) +void ospm_power_island_up(int hw_islands) { - struct drm_device *dev = pci_get_drvdata(pdev); - struct drm_psb_private *dev_priv = dev->dev_private; + u32 pwr_cnt = 0; + u32 pwr_sts = 0; + u32 pwr_mask = 0; + + struct drm_psb_private *dev_priv = + (struct drm_psb_private *) gpDrmDevice->dev_private; - mutex_lock(&power_mutex); - if (!dev_priv->suspended) { - if (dev_priv->display_count) { - mutex_unlock(&power_mutex); - return -EBUSY; + + if (hw_islands & OSPM_DISPLAY_ISLAND) { + pwr_mask = PSB_PWRGT_DISPLAY_MASK; + + pwr_cnt = inl(dev_priv->ospm_base + PSB_PM_SSC); + pwr_cnt &= ~pwr_mask; + outl(pwr_cnt, (dev_priv->ospm_base + PSB_PM_SSC)); + + while (true) { + pwr_sts = inl(dev_priv->ospm_base + PSB_PM_SSS); + if ((pwr_sts & pwr_mask) == 0) + break; + else + udelay(10); } - psb_irq_uninstall(dev); - gma_suspend_display(dev); - gma_suspend_pci(pdev); } - mutex_unlock(&power_mutex); + + g_hw_power_status_mask |= hw_islands; +} + +/* + * ospm_power_resume + */ +int ospm_power_resume(struct pci_dev *pdev) +{ + if(gbSuspendInProgress || gbResumeInProgress) + { +#ifdef OSPM_GFX_DPK + printk(KERN_ALERT "OSPM_GFX_DPK: %s hw_island: Suspend || gbResumeInProgress!!!! \n", __func__); +#endif + return 0; + } + + mutex_lock(&power_mutex); + +#ifdef OSPM_GFX_DPK + printk(KERN_ALERT "OSPM_GFX_DPK: ospm_power_resume \n"); +#endif + + gbResumeInProgress = true; + + ospm_resume_pci(pdev); + + ospm_resume_display(gpDrmDevice->pdev); + psb_irq_preinstall_islands(gpDrmDevice, OSPM_DISPLAY_ISLAND); + psb_irq_postinstall_islands(gpDrmDevice, OSPM_DISPLAY_ISLAND); + + gbResumeInProgress = false; + + mutex_unlock(&power_mutex); + return 0; } -/** - * gma_power_resume - resume power - * @pdev: PCI device +/* + * ospm_power_island_down * - * Resume the PCI side of the graphics and then the displays + * Description: Cut power to the specified island(s) (powergating) */ -int gma_power_resume(struct pci_dev *pdev) +void ospm_power_island_down(int islands) { - struct drm_device *dev = pci_get_drvdata(pdev); +#if 0 + u32 pwr_cnt = 0; + u32 pwr_mask = 0; + u32 pwr_sts = 0; + + struct drm_psb_private *dev_priv = + (struct drm_psb_private *) gpDrmDevice->dev_private; + + g_hw_power_status_mask &= ~islands; + + if (islands & OSPM_GRAPHICS_ISLAND) { + pwr_cnt |= PSB_PWRGT_GFX_MASK; + pwr_mask |= PSB_PWRGT_GFX_MASK; + if (dev_priv->graphics_state == PSB_PWR_STATE_ON) { + dev_priv->gfx_on_time += (jiffies - dev_priv->gfx_last_mode_change) * 1000 / HZ; + dev_priv->gfx_last_mode_change = jiffies; + dev_priv->graphics_state = PSB_PWR_STATE_OFF; + dev_priv->gfx_off_cnt++; + } + } + if (islands & OSPM_VIDEO_ENC_ISLAND) { + pwr_cnt |= PSB_PWRGT_VID_ENC_MASK; + pwr_mask |= PSB_PWRGT_VID_ENC_MASK; + } + if (islands & OSPM_VIDEO_DEC_ISLAND) { + pwr_cnt |= PSB_PWRGT_VID_DEC_MASK; + pwr_mask |= PSB_PWRGT_VID_DEC_MASK; + } + if (pwr_cnt) { + pwr_cnt |= inl(dev_priv->apm_base); + outl(pwr_cnt, dev_priv->apm_base + PSB_APM_CMD); + while (true) { + pwr_sts = inl(dev_priv->apm_base + PSB_APM_STS); - mutex_lock(&power_mutex); - gma_resume_pci(pdev); - gma_resume_display(pdev); - psb_irq_preinstall(dev); - psb_irq_postinstall(dev); - mutex_unlock(&power_mutex); - return 0; -} + if ((pwr_sts & pwr_mask) == pwr_mask) + break; + else + udelay(10); + } + } + if (islands & OSPM_DISPLAY_ISLAND) { + pwr_mask = PSB_PWRGT_DISPLAY_MASK; + outl(pwr_mask, (dev_priv->ospm_base + PSB_PM_SSC)); -/** - * gma_power_is_on - returne true if power is on - * @dev: our DRM device + while (true) { + pwr_sts = inl(dev_priv->ospm_base + PSB_PM_SSS); + if ((pwr_sts & pwr_mask) == pwr_mask) + break; + else + udelay(10); + } + } +#endif +} + + +/* + * ospm_power_is_hw_on * - * Returns true if the display island power is on at this moment + * Description: do an instantaneous check for if the specified islands + * are on. Only use this in cases where you know the g_state_change_mutex + * is already held such as in irq install/uninstall. Otherwise, use + * ospm_power_using_hw_begin(). */ -bool gma_power_is_on(struct drm_device *dev) +bool ospm_power_is_hw_on(int hw_islands) { - struct drm_psb_private *dev_priv = dev->dev_private; - return dev_priv->display_power; + return ((g_hw_power_status_mask & hw_islands) == hw_islands) ? true:false; } - -/** - * gma_power_begin - begin requiring power - * @dev: our DRM device - * @force_on: true to force power on +/* + * ospm_power_using_hw_begin * - * Begin an action that requires the display power island is enabled. - * We refcount the islands. + * Description: Notify PowerMgmt module that you will be accessing the + * specified island's hw so don't power it off. If force_on is true, + * this will power on the specified island if it is off. + * Otherwise, this will return false and the caller is expected to not + * access the hw. * - * FIXME: locking + * NOTE *** If this is called from and interrupt handler or other atomic + * context, then it will return false if we are in the middle of a + * power state transition and the caller will be expected to handle that + * even if force_on is set to true. */ -bool gma_power_begin(struct drm_device *dev, bool force_on) +bool ospm_power_using_hw_begin(int hw_island, UHBUsage usage) { - struct drm_psb_private *dev_priv = dev->dev_private; - int ret; + return 1; /*FIXMEAC */ +#if 0 + bool ret = true; + bool island_is_off = false; + bool b_atomic = (in_interrupt() || in_atomic()); + bool locked = true; + struct pci_dev *pdev = gpDrmDevice->pdev; + u32 deviceID = 0; + bool force_on = usage ? true: false; + /*quick path, not 100% race safe, but should be enough comapre to current other code in this file */ + if (!force_on) { + if (hw_island & (OSPM_ALL_ISLANDS & ~g_hw_power_status_mask)) + return false; + else { + locked = false; +#ifdef CONFIG_PM_RUNTIME + /* increment pm_runtime_refcount */ + pm_runtime_get(&pdev->dev); +#endif + goto increase_count; + } + } - /* Power already on ? */ - if (dev_priv->display_power) { - dev_priv->display_count++; - pm_runtime_get(&dev->pdev->dev); - return true; + + if (!b_atomic) + mutex_lock(&power_mutex); + + island_is_off = hw_island & (OSPM_ALL_ISLANDS & ~g_hw_power_status_mask); + + if (b_atomic && (gbSuspendInProgress || gbResumeInProgress || gbSuspended) && force_on && island_is_off) + ret = false; + + if (ret && island_is_off && !force_on) + ret = false; + + if (ret && island_is_off && force_on) { + gbResumeInProgress = true; + + ret = ospm_resume_pci(pdev); + + if (ret) { + switch(hw_island) + { + case OSPM_DISPLAY_ISLAND: + deviceID = gui32MRSTDisplayDeviceID; + ospm_resume_display(pdev); + psb_irq_preinstall_islands(gpDrmDevice, OSPM_DISPLAY_ISLAND); + psb_irq_postinstall_islands(gpDrmDevice, OSPM_DISPLAY_ISLAND); + break; + case OSPM_GRAPHICS_ISLAND: + deviceID = gui32SGXDeviceID; + ospm_power_island_up(OSPM_GRAPHICS_ISLAND); + psb_irq_preinstall_islands(gpDrmDevice, OSPM_GRAPHICS_ISLAND); + psb_irq_postinstall_islands(gpDrmDevice, OSPM_GRAPHICS_ISLAND); + break; +#if 1 + case OSPM_VIDEO_DEC_ISLAND: + if(!ospm_power_is_hw_on(OSPM_DISPLAY_ISLAND)) { + //printk(KERN_ALERT "%s power on display for video decode use\n", __func__); + deviceID = gui32MRSTDisplayDeviceID; + ospm_resume_display(pdev); + psb_irq_preinstall_islands(gpDrmDevice, OSPM_DISPLAY_ISLAND); + psb_irq_postinstall_islands(gpDrmDevice, OSPM_DISPLAY_ISLAND); + } + else{ + //printk(KERN_ALERT "%s display is already on for video decode use\n", __func__); + } + + if(!ospm_power_is_hw_on(OSPM_VIDEO_DEC_ISLAND)) { + //printk(KERN_ALERT "%s power on video decode\n", __func__); + deviceID = gui32MRSTMSVDXDeviceID; + ospm_power_island_up(OSPM_VIDEO_DEC_ISLAND); + psb_irq_preinstall_islands(gpDrmDevice, OSPM_VIDEO_DEC_ISLAND); + psb_irq_postinstall_islands(gpDrmDevice, OSPM_VIDEO_DEC_ISLAND); + } + else{ + //printk(KERN_ALERT "%s video decode is already on\n", __func__); + } + + break; + case OSPM_VIDEO_ENC_ISLAND: + if(!ospm_power_is_hw_on(OSPM_DISPLAY_ISLAND)) { + //printk(KERN_ALERT "%s power on display for video encode\n", __func__); + deviceID = gui32MRSTDisplayDeviceID; + ospm_resume_display(pdev); + psb_irq_preinstall_islands(gpDrmDevice, OSPM_DISPLAY_ISLAND); + psb_irq_postinstall_islands(gpDrmDevice, OSPM_DISPLAY_ISLAND); + } + else{ + //printk(KERN_ALERT "%s display is already on for video encode use\n", __func__); + } + + if(!ospm_power_is_hw_on(OSPM_VIDEO_ENC_ISLAND)) { + //printk(KERN_ALERT "%s power on video encode\n", __func__); + deviceID = gui32MRSTTOPAZDeviceID; + ospm_power_island_up(OSPM_VIDEO_ENC_ISLAND); + psb_irq_preinstall_islands(gpDrmDevice, OSPM_VIDEO_ENC_ISLAND); + psb_irq_postinstall_islands(gpDrmDevice, OSPM_VIDEO_ENC_ISLAND); + } + else{ + //printk(KERN_ALERT "%s video decode is already on\n", __func__); + } +#endif + break; + + default: + printk(KERN_ALERT "%s unknown island !!!! \n", __func__); + break; + } + + } + + if (!ret) + printk(KERN_ALERT "ospm_power_using_hw_begin: forcing on %d failed\n", hw_island); + + gbResumeInProgress = false; } - if (force_on == false) - return false; - - /* Ok power up needed */ - ret = gma_resume_pci(dev->pdev); - if (ret == 0) { - psb_irq_preinstall(dev); - psb_irq_postinstall(dev); - pm_runtime_get(&dev->pdev->dev); - dev_priv->display_count++; - return true; +increase_count: + if (ret) { + switch(hw_island) + { + case OSPM_GRAPHICS_ISLAND: + atomic_inc(&g_graphics_access_count); + break; + case OSPM_VIDEO_ENC_ISLAND: + atomic_inc(&g_videoenc_access_count); + break; + case OSPM_VIDEO_DEC_ISLAND: + atomic_inc(&g_videodec_access_count); + break; + case OSPM_DISPLAY_ISLAND: + atomic_inc(&g_display_access_count); + break; + } } - return false; + + if (!b_atomic && locked) + mutex_unlock(&power_mutex); + + return ret; +#endif } -/** - * gma_power_end - end use of power - * @dev: Our DRM device +/* + * ospm_power_using_hw_end * - * Indicate that one of our gma_power_begin() requested periods when - * the diplay island power is needed has completed. + * Description: Notify PowerMgmt module that you are done accessing the + * specified island's hw so feel free to power it off. Note that this + * function doesn't actually power off the islands. */ -void gma_power_end(struct drm_device *dev) +void ospm_power_using_hw_end(int hw_island) { - struct drm_psb_private *dev_priv = dev->dev_private; - dev_priv->display_count--; - WARN_ON(dev_priv->display_count < 0); - pm_runtime_put(&dev->pdev->dev); +#if 0 /* FIXMEAC */ + switch(hw_island) + { + case OSPM_GRAPHICS_ISLAND: + atomic_dec(&g_graphics_access_count); + break; + case OSPM_VIDEO_ENC_ISLAND: + atomic_dec(&g_videoenc_access_count); + break; + case OSPM_VIDEO_DEC_ISLAND: + atomic_dec(&g_videodec_access_count); + break; + case OSPM_DISPLAY_ISLAND: + atomic_dec(&g_display_access_count); + break; + } + + //decrement runtime pm ref count + pm_runtime_put(&gpDrmDevice->pdev->dev); + + WARN_ON(atomic_read(&g_graphics_access_count) < 0); + WARN_ON(atomic_read(&g_videoenc_access_count) < 0); + WARN_ON(atomic_read(&g_videodec_access_count) < 0); + WARN_ON(atomic_read(&g_display_access_count) < 0); +#endif +} + +int ospm_runtime_pm_allow(struct drm_device * dev) +{ + return 0; +} + +void ospm_runtime_pm_forbid(struct drm_device * dev) +{ + struct drm_psb_private * dev_priv = dev->dev_private; + + DRM_INFO("%s\n", __FUNCTION__); + + pm_runtime_forbid(&dev->pdev->dev); + dev_priv->rpm_enabled = 0; } int psb_runtime_suspend(struct device *dev) { - static pm_message_t dummy; - return gma_power_suspend(to_pci_dev(dev), dummy); + pm_message_t state; + int ret = 0; + state.event = 0; + +#ifdef OSPM_GFX_DPK + printk(KERN_ALERT "OSPM_GFX_DPK: %s \n", __func__); +#endif + if (atomic_read(&g_graphics_access_count) || atomic_read(&g_videoenc_access_count) + || atomic_read(&g_videodec_access_count) || atomic_read(&g_display_access_count)){ +#ifdef OSPM_GFX_DPK + printk(KERN_ALERT "OSPM_GFX_DPK: GFX: %d VEC: %d VED: %d DC: %d DSR: %d \n", atomic_read(&g_graphics_access_count), + atomic_read(&g_videoenc_access_count), atomic_read(&g_videodec_access_count), atomic_read(&g_display_access_count)); +#endif + return -EBUSY; + } + else + ret = ospm_power_suspend(gpDrmDevice->pdev, state); + + return ret; } int psb_runtime_resume(struct device *dev) @@ -480,11 +782,11 @@ int psb_runtime_resume(struct device *dev) int psb_runtime_idle(struct device *dev) { - struct drm_device *drmdev = pci_get_drvdata(to_pci_dev(dev)); - struct drm_psb_private *dev_priv = drmdev->dev_private; - if (dev_priv->display_count) - return 0; - else + /*printk (KERN_ALERT "lvds:%d,mipi:%d\n", dev_priv->is_lvds_on, dev_priv->is_mipi_on);*/ + if (atomic_read(&g_graphics_access_count) || atomic_read(&g_videoenc_access_count) + || atomic_read(&g_videodec_access_count) || atomic_read(&g_display_access_count)) return 1; + else + return 0; } diff --git a/trunk/drivers/staging/gma500/psb_powermgmt.h b/trunk/drivers/staging/gma500/psb_powermgmt.h index e005229af798..bf6f27af03a8 100644 --- a/trunk/drivers/staging/gma500/psb_powermgmt.h +++ b/trunk/drivers/staging/gma500/psb_powermgmt.h @@ -24,8 +24,7 @@ * Authors: * Benjamin Defnet * Rajesh Poornachandran - * Massively reworked - * Alan Cox + * */ #ifndef _PSB_POWERMGMT_H_ #define _PSB_POWERMGMT_H_ @@ -33,35 +32,65 @@ #include #include -void gma_power_init(struct drm_device *dev); -void gma_power_uninit(struct drm_device *dev); +#define OSPM_GRAPHICS_ISLAND 0x1 +#define OSPM_VIDEO_ENC_ISLAND 0x2 +#define OSPM_VIDEO_DEC_ISLAND 0x4 +#define OSPM_DISPLAY_ISLAND 0x8 +#define OSPM_GL3_CACHE_ISLAND 0x10 +#define OSPM_ALL_ISLANDS 0x1f + +/* IPC message and command defines used to enable/disable mipi panel voltages */ +#define IPC_MSG_PANEL_ON_OFF 0xE9 +#define IPC_CMD_PANEL_ON 1 +#define IPC_CMD_PANEL_OFF 0 + +typedef enum _UHBUsage +{ + OSPM_UHB_ONLY_IF_ON = 0, + OSPM_UHB_FORCE_POWER_ON, +} UHBUsage; + +/* Use these functions to power down video HW for D0i3 purpose */ + +void ospm_power_init(struct drm_device *dev); +void ospm_power_uninit(void); + /* - * The kernel bus power management will call these functions + * OSPM will call these functions */ -int gma_power_suspend(struct pci_dev *pdev, pm_message_t state); -int gma_power_resume(struct pci_dev *pdev); +int ospm_power_suspend(struct pci_dev *pdev, pm_message_t state); +int ospm_power_resume(struct pci_dev *pdev); /* * These are the functions the driver should use to wrap all hw access * (i.e. register reads and writes) */ -bool gma_power_begin(struct drm_device *dev, bool force); -void gma_power_end(struct drm_device *dev); +bool ospm_power_using_hw_begin(int hw_island, UHBUsage usage); +void ospm_power_using_hw_end(int hw_island); /* * Use this function to do an instantaneous check for if the hw is on. - * Only use this in cases where you know the mutex is already held such - * as in irq install/uninstall and you need to - * prevent a deadlock situation. Otherwise use gma_power_begin(). + * Only use this in cases where you know the g_state_change_mutex + * is already held such as in irq install/uninstall and you need to + * prevent a deadlock situation. Otherwise use ospm_power_using_hw_begin(). */ -bool gma_power_is_on(struct drm_device *dev); +bool ospm_power_is_hw_on(int hw_islands); +/* + * Power up/down different hw component rails/islands + */ +void ospm_power_island_down(int hw_islands); +void ospm_power_island_up(int hw_islands); +void ospm_suspend_graphics(void); /* * GFX-Runtime PM callbacks */ int psb_runtime_suspend(struct device *dev); int psb_runtime_resume(struct device *dev); int psb_runtime_idle(struct device *dev); +int ospm_runtime_pm_allow(struct drm_device * dev); +void ospm_runtime_pm_forbid(struct drm_device * dev); + #endif /*_PSB_POWERMGMT_H_*/ diff --git a/trunk/drivers/staging/gma500/psb_lid.c b/trunk/drivers/staging/gma500/psb_reset.c similarity index 100% rename from trunk/drivers/staging/gma500/psb_lid.c rename to trunk/drivers/staging/gma500/psb_reset.c diff --git a/trunk/drivers/staging/gma500/psb_sgx.c b/trunk/drivers/staging/gma500/psb_sgx.c new file mode 100644 index 000000000000..973134bc2345 --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_sgx.c @@ -0,0 +1,238 @@ +/************************************************************************** + * Copyright (c) 2007, Intel Corporation. + * All Rights Reserved. + * Copyright (c) 2008, Tungsten Graphics, Inc. Cedar Park, TX. USA. + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ + +#include +#include "psb_drv.h" +#include "psb_drm.h" +#include "psb_reg.h" +#include "ttm/ttm_bo_api.h" +#include "ttm/ttm_execbuf_util.h" +#include "psb_ttm_userobj_api.h" +#include "ttm/ttm_placement.h" +#include "psb_sgx.h" +#include "psb_intel_reg.h" +#include "psb_powermgmt.h" + + +static inline int psb_same_page(unsigned long offset, + unsigned long offset2) +{ + return (offset & PAGE_MASK) == (offset2 & PAGE_MASK); +} + +static inline unsigned long psb_offset_end(unsigned long offset, + unsigned long end) +{ + offset = (offset + PAGE_SIZE) & PAGE_MASK; + return (end < offset) ? end : offset; +} + +struct psb_dstbuf_cache { + unsigned int dst; + struct ttm_buffer_object *dst_buf; + unsigned long dst_offset; + uint32_t *dst_page; + unsigned int dst_page_offset; + struct ttm_bo_kmap_obj dst_kmap; + bool dst_is_iomem; +}; + +struct psb_validate_buffer { + struct ttm_validate_buffer base; + struct psb_validate_req req; + int ret; + struct psb_validate_arg __user *user_val_arg; + uint32_t flags; + uint32_t offset; + int po_correct; +}; +static int +psb_placement_fence_type(struct ttm_buffer_object *bo, + uint64_t set_val_flags, + uint64_t clr_val_flags, + uint32_t new_fence_class, + uint32_t *new_fence_type) +{ + int ret; + uint32_t n_fence_type; + /* + uint32_t set_flags = set_val_flags & 0xFFFFFFFF; + uint32_t clr_flags = clr_val_flags & 0xFFFFFFFF; + */ + struct ttm_fence_object *old_fence; + uint32_t old_fence_type; + struct ttm_placement placement; + + if (unlikely + (!(set_val_flags & + (PSB_GPU_ACCESS_READ | PSB_GPU_ACCESS_WRITE)))) { + DRM_ERROR + ("GPU access type (read / write) is not indicated.\n"); + return -EINVAL; + } + + /* User space driver doesn't set any TTM placement flags in + set_val_flags or clr_val_flags */ + placement.num_placement = 0;/* FIXME */ + placement.num_busy_placement = 0; + placement.fpfn = 0; + placement.lpfn = 0; + ret = psb_ttm_bo_check_placement(bo, &placement); + if (unlikely(ret != 0)) + return ret; + + switch (new_fence_class) { + default: + n_fence_type = _PSB_FENCE_TYPE_EXE; + } + + *new_fence_type = n_fence_type; + old_fence = (struct ttm_fence_object *) bo->sync_obj; + old_fence_type = (uint32_t) (unsigned long) bo->sync_obj_arg; + + if (old_fence && ((new_fence_class != old_fence->fence_class) || + ((n_fence_type ^ old_fence_type) & + old_fence_type))) { + ret = ttm_bo_wait(bo, 0, 1, 0); + if (unlikely(ret != 0)) + return ret; + } + /* + bo->proposed_flags = (bo->proposed_flags | set_flags) + & ~clr_flags & TTM_PL_MASK_MEMTYPE; + */ + return 0; +} + +int psb_validate_kernel_buffer(struct psb_context *context, + struct ttm_buffer_object *bo, + uint32_t fence_class, + uint64_t set_flags, uint64_t clr_flags) +{ + struct psb_validate_buffer *item; + uint32_t cur_fence_type; + int ret; + + if (unlikely(context->used_buffers >= PSB_NUM_VALIDATE_BUFFERS)) { + DRM_ERROR("Out of free validation buffer entries for " + "kernel buffer validation.\n"); + return -ENOMEM; + } + + item = &context->buffers[context->used_buffers]; + item->user_val_arg = NULL; + item->base.reserved = 0; + + ret = ttm_bo_reserve(bo, 1, 0, 1, context->val_seq); + if (unlikely(ret != 0)) + return ret; + + ret = psb_placement_fence_type(bo, set_flags, clr_flags, fence_class, + &cur_fence_type); + if (unlikely(ret != 0)) { + ttm_bo_unreserve(bo); + return ret; + } + + item->base.bo = ttm_bo_reference(bo); + item->base.new_sync_obj_arg = (void *) (unsigned long) cur_fence_type; + item->base.reserved = 1; + + /* Internal locking ??? FIXMEAC */ + list_add_tail(&item->base.head, &context->kern_validate_list); + context->used_buffers++; + /* + ret = ttm_bo_validate(bo, 1, 0, 0); + if (unlikely(ret != 0)) + goto out_unlock; + */ + item->offset = bo->offset; + item->flags = bo->mem.placement; + context->fence_types |= cur_fence_type; + + return ret; +} + +void psb_fence_or_sync(struct drm_file *file_priv, + uint32_t engine, + uint32_t fence_types, + uint32_t fence_flags, + struct list_head *list, + struct psb_ttm_fence_rep *fence_arg, + struct ttm_fence_object **fence_p) +{ + struct drm_device *dev = file_priv->minor->dev; + struct drm_psb_private *dev_priv = psb_priv(dev); + struct ttm_fence_device *fdev = &dev_priv->fdev; + int ret; + struct ttm_fence_object *fence; + struct ttm_object_file *tfile = psb_fpriv(file_priv)->tfile; + uint32_t handle; + + ret = ttm_fence_user_create(fdev, tfile, + engine, fence_types, + TTM_FENCE_FLAG_EMIT, &fence, &handle); + if (ret) { + + /* + * Fence creation failed. + * Fall back to synchronous operation and idle the engine. + */ + + if (!(fence_flags & DRM_PSB_FENCE_NO_USER)) { + + /* + * Communicate to user-space that + * fence creation has failed and that + * the engine is idle. + */ + + fence_arg->handle = ~0; + fence_arg->error = ret; + } + + ttm_eu_backoff_reservation(list); + if (fence_p) + *fence_p = NULL; + return; + } + + ttm_eu_fence_buffer_objects(list, fence); + if (!(fence_flags & DRM_PSB_FENCE_NO_USER)) { + struct ttm_fence_info info = ttm_fence_get_info(fence); + fence_arg->handle = handle; + fence_arg->fence_class = ttm_fence_class(fence); + fence_arg->fence_type = ttm_fence_types(fence); + fence_arg->signaled_types = info.signaled_types; + fence_arg->error = 0; + } else { + ret = + ttm_ref_object_base_unref(tfile, handle, + ttm_fence_type); + BUG_ON(ret); + } + + if (fence_p) + *fence_p = fence; + else if (fence) + ttm_fence_object_unref(&fence); +} + diff --git a/trunk/drivers/staging/gma500/psb_sgx.h b/trunk/drivers/staging/gma500/psb_sgx.h new file mode 100644 index 000000000000..9300e2da993a --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_sgx.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2008, Intel Corporation + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + * Authors: + * Eric Anholt + * + **/ +#ifndef _PSB_SGX_H_ +#define _PSB_SGX_H_ + +extern int psb_submit_video_cmdbuf(struct drm_device *dev, + struct ttm_buffer_object *cmd_buffer, + unsigned long cmd_offset, + unsigned long cmd_size, + struct ttm_fence_object *fence); + +extern int drm_idle_check_interval; + +#endif diff --git a/trunk/drivers/staging/gma500/psb_ttm_fence.c b/trunk/drivers/staging/gma500/psb_ttm_fence.c new file mode 100644 index 000000000000..d1c359018cba --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_ttm_fence.c @@ -0,0 +1,605 @@ +/************************************************************************** + * + * Copyright (c) 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA + * All Rights Reserved. + * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ +/* + * Authors: Thomas Hellstrom + */ + +#include "psb_ttm_fence_api.h" +#include "psb_ttm_fence_driver.h" +#include +#include + +#include + +/* + * Simple implementation for now. + */ + +static void ttm_fence_lockup(struct ttm_fence_object *fence, uint32_t mask) +{ + struct ttm_fence_class_manager *fc = ttm_fence_fc(fence); + + printk(KERN_ERR "GPU lockup dectected on engine %u " + "fence type 0x%08x\n", + (unsigned int)fence->fence_class, (unsigned int)mask); + /* + * Give engines some time to idle? + */ + + write_lock(&fc->lock); + ttm_fence_handler(fence->fdev, fence->fence_class, + fence->sequence, mask, -EBUSY); + write_unlock(&fc->lock); +} + +/* + * Convenience function to be called by fence::wait methods that + * need polling. + */ + +int ttm_fence_wait_polling(struct ttm_fence_object *fence, bool lazy, + bool interruptible, uint32_t mask) +{ + struct ttm_fence_class_manager *fc = ttm_fence_fc(fence); + const struct ttm_fence_driver *driver = ttm_fence_driver(fence); + uint32_t count = 0; + int ret; + unsigned long end_jiffies = fence->timeout_jiffies; + + DECLARE_WAITQUEUE(entry, current); + add_wait_queue(&fc->fence_queue, &entry); + + ret = 0; + + for (;;) { + __set_current_state((interruptible) ? + TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE); + if (ttm_fence_object_signaled(fence, mask)) + break; + if (time_after_eq(jiffies, end_jiffies)) { + if (driver->lockup) + driver->lockup(fence, mask); + else + ttm_fence_lockup(fence, mask); + continue; + } + if (lazy) + schedule_timeout(1); + else if ((++count & 0x0F) == 0) { + __set_current_state(TASK_RUNNING); + schedule(); + __set_current_state((interruptible) ? + TASK_INTERRUPTIBLE : + TASK_UNINTERRUPTIBLE); + } + if (interruptible && signal_pending(current)) { + ret = -ERESTART; + break; + } + } + __set_current_state(TASK_RUNNING); + remove_wait_queue(&fc->fence_queue, &entry); + return ret; +} + +/* + * Typically called by the IRQ handler. + */ + +void ttm_fence_handler(struct ttm_fence_device *fdev, uint32_t fence_class, + uint32_t sequence, uint32_t type, uint32_t error) +{ + int wake = 0; + uint32_t diff; + uint32_t relevant_type; + uint32_t new_type; + struct ttm_fence_class_manager *fc = &fdev->fence_class[fence_class]; + const struct ttm_fence_driver *driver = ttm_fence_driver_from_dev(fdev); + struct list_head *head; + struct ttm_fence_object *fence, *next; + bool found = false; + + if (list_empty(&fc->ring)) + return; + + list_for_each_entry(fence, &fc->ring, ring) { + diff = (sequence - fence->sequence) & fc->sequence_mask; + if (diff > fc->wrap_diff) { + found = true; + break; + } + } + + fc->waiting_types &= ~type; + head = (found) ? &fence->ring : &fc->ring; + + list_for_each_entry_safe_reverse(fence, next, head, ring) { + if (&fence->ring == &fc->ring) + break; + + DRM_DEBUG("Fence 0x%08lx, sequence 0x%08x, type 0x%08x\n", + (unsigned long)fence, fence->sequence, + fence->fence_type); + + if (error) { + fence->info.error = error; + fence->info.signaled_types = fence->fence_type; + list_del_init(&fence->ring); + wake = 1; + break; + } + + relevant_type = type & fence->fence_type; + new_type = (fence->info.signaled_types | relevant_type) ^ + fence->info.signaled_types; + + if (new_type) { + fence->info.signaled_types |= new_type; + DRM_DEBUG("Fence 0x%08lx signaled 0x%08x\n", + (unsigned long)fence, + fence->info.signaled_types); + + if (unlikely(driver->signaled)) + driver->signaled(fence); + + if (driver->needed_flush) + fc->pending_flush |= + driver->needed_flush(fence); + + if (new_type & fence->waiting_types) + wake = 1; + } + + fc->waiting_types |= + fence->waiting_types & ~fence->info.signaled_types; + + if (!(fence->fence_type & ~fence->info.signaled_types)) { + DRM_DEBUG("Fence completely signaled 0x%08lx\n", + (unsigned long)fence); + list_del_init(&fence->ring); + } + } + + /* + * Reinstate lost waiting types. + */ + + if ((fc->waiting_types & type) != type) { + head = head->prev; + list_for_each_entry(fence, head, ring) { + if (&fence->ring == &fc->ring) + break; + diff = + (fc->highest_waiting_sequence - + fence->sequence) & fc->sequence_mask; + if (diff > fc->wrap_diff) + break; + + fc->waiting_types |= + fence->waiting_types & ~fence->info.signaled_types; + } + } + + if (wake) + wake_up_all(&fc->fence_queue); +} + +static void ttm_fence_unring(struct ttm_fence_object *fence) +{ + struct ttm_fence_class_manager *fc = ttm_fence_fc(fence); + unsigned long irq_flags; + + write_lock_irqsave(&fc->lock, irq_flags); + list_del_init(&fence->ring); + write_unlock_irqrestore(&fc->lock, irq_flags); +} + +bool ttm_fence_object_signaled(struct ttm_fence_object *fence, uint32_t mask) +{ + unsigned long flags; + bool signaled; + const struct ttm_fence_driver *driver = ttm_fence_driver(fence); + struct ttm_fence_class_manager *fc = ttm_fence_fc(fence); + + mask &= fence->fence_type; + read_lock_irqsave(&fc->lock, flags); + signaled = (mask & fence->info.signaled_types) == mask; + read_unlock_irqrestore(&fc->lock, flags); + if (!signaled && driver->poll) { + write_lock_irqsave(&fc->lock, flags); + driver->poll(fence->fdev, fence->fence_class, mask); + signaled = (mask & fence->info.signaled_types) == mask; + write_unlock_irqrestore(&fc->lock, flags); + } + return signaled; +} + +int ttm_fence_object_flush(struct ttm_fence_object *fence, uint32_t type) +{ + const struct ttm_fence_driver *driver = ttm_fence_driver(fence); + struct ttm_fence_class_manager *fc = ttm_fence_fc(fence); + unsigned long irq_flags; + uint32_t saved_pending_flush; + uint32_t diff; + bool call_flush; + + if (type & ~fence->fence_type) { + DRM_ERROR("Flush trying to extend fence type, " + "0x%x, 0x%x\n", type, fence->fence_type); + return -EINVAL; + } + + write_lock_irqsave(&fc->lock, irq_flags); + fence->waiting_types |= type; + fc->waiting_types |= fence->waiting_types; + diff = (fence->sequence - fc->highest_waiting_sequence) & + fc->sequence_mask; + + if (diff < fc->wrap_diff) + fc->highest_waiting_sequence = fence->sequence; + + /* + * fence->waiting_types has changed. Determine whether + * we need to initiate some kind of flush as a result of this. + */ + + saved_pending_flush = fc->pending_flush; + if (driver->needed_flush) + fc->pending_flush |= driver->needed_flush(fence); + + if (driver->poll) + driver->poll(fence->fdev, fence->fence_class, + fence->waiting_types); + + call_flush = (fc->pending_flush != 0); + write_unlock_irqrestore(&fc->lock, irq_flags); + + if (call_flush && driver->flush) + driver->flush(fence->fdev, fence->fence_class); + + return 0; +} + +/* + * Make sure old fence objects are signaled before their fence sequences are + * wrapped around and reused. + */ + +void ttm_fence_flush_old(struct ttm_fence_device *fdev, + uint32_t fence_class, uint32_t sequence) +{ + struct ttm_fence_class_manager *fc = &fdev->fence_class[fence_class]; + struct ttm_fence_object *fence; + unsigned long irq_flags; + const struct ttm_fence_driver *driver = fdev->driver; + bool call_flush; + + uint32_t diff; + + write_lock_irqsave(&fc->lock, irq_flags); + + list_for_each_entry_reverse(fence, &fc->ring, ring) { + diff = (sequence - fence->sequence) & fc->sequence_mask; + if (diff <= fc->flush_diff) + break; + + fence->waiting_types = fence->fence_type; + fc->waiting_types |= fence->fence_type; + + if (driver->needed_flush) + fc->pending_flush |= driver->needed_flush(fence); + } + + if (driver->poll) + driver->poll(fdev, fence_class, fc->waiting_types); + + call_flush = (fc->pending_flush != 0); + write_unlock_irqrestore(&fc->lock, irq_flags); + + if (call_flush && driver->flush) + driver->flush(fdev, fence->fence_class); + + /* + * FIXME: Shold we implement a wait here for really old fences? + */ + +} + +int ttm_fence_object_wait(struct ttm_fence_object *fence, + bool lazy, bool interruptible, uint32_t mask) +{ + const struct ttm_fence_driver *driver = ttm_fence_driver(fence); + struct ttm_fence_class_manager *fc = ttm_fence_fc(fence); + int ret = 0; + unsigned long timeout; + unsigned long cur_jiffies; + unsigned long to_jiffies; + + if (mask & ~fence->fence_type) { + DRM_ERROR("Wait trying to extend fence type" + " 0x%08x 0x%08x\n", mask, fence->fence_type); + BUG(); + return -EINVAL; + } + + if (driver->wait) + return driver->wait(fence, lazy, interruptible, mask); + + ttm_fence_object_flush(fence, mask); +retry: + if (!driver->has_irq || + driver->has_irq(fence->fdev, fence->fence_class, mask)) { + + cur_jiffies = jiffies; + to_jiffies = fence->timeout_jiffies; + + timeout = (time_after(to_jiffies, cur_jiffies)) ? + to_jiffies - cur_jiffies : 1; + + if (interruptible) + ret = wait_event_interruptible_timeout + (fc->fence_queue, + ttm_fence_object_signaled(fence, mask), timeout); + else + ret = wait_event_timeout + (fc->fence_queue, + ttm_fence_object_signaled(fence, mask), timeout); + + if (unlikely(ret == -ERESTARTSYS)) + return -ERESTART; + + if (unlikely(ret == 0)) { + if (driver->lockup) + driver->lockup(fence, mask); + else + ttm_fence_lockup(fence, mask); + goto retry; + } + + return 0; + } + + return ttm_fence_wait_polling(fence, lazy, interruptible, mask); +} + +int ttm_fence_object_emit(struct ttm_fence_object *fence, uint32_t fence_flags, + uint32_t fence_class, uint32_t type) +{ + const struct ttm_fence_driver *driver = ttm_fence_driver(fence); + struct ttm_fence_class_manager *fc = ttm_fence_fc(fence); + unsigned long flags; + uint32_t sequence; + unsigned long timeout; + int ret; + + ttm_fence_unring(fence); + ret = driver->emit(fence->fdev, + fence_class, fence_flags, &sequence, &timeout); + if (ret) + return ret; + + write_lock_irqsave(&fc->lock, flags); + fence->fence_class = fence_class; + fence->fence_type = type; + fence->waiting_types = 0; + fence->info.signaled_types = 0; + fence->info.error = 0; + fence->sequence = sequence; + fence->timeout_jiffies = timeout; + if (list_empty(&fc->ring)) + fc->highest_waiting_sequence = sequence - 1; + list_add_tail(&fence->ring, &fc->ring); + fc->latest_queued_sequence = sequence; + write_unlock_irqrestore(&fc->lock, flags); + return 0; +} + +int ttm_fence_object_init(struct ttm_fence_device *fdev, + uint32_t fence_class, + uint32_t type, + uint32_t create_flags, + void (*destroy) (struct ttm_fence_object *), + struct ttm_fence_object *fence) +{ + int ret = 0; + + kref_init(&fence->kref); + fence->fence_class = fence_class; + fence->fence_type = type; + fence->info.signaled_types = 0; + fence->waiting_types = 0; + fence->sequence = 0; + fence->info.error = 0; + fence->fdev = fdev; + fence->destroy = destroy; + INIT_LIST_HEAD(&fence->ring); + atomic_inc(&fdev->count); + + if (create_flags & TTM_FENCE_FLAG_EMIT) { + ret = ttm_fence_object_emit(fence, create_flags, + fence->fence_class, type); + } + + return ret; +} + +int ttm_fence_object_create(struct ttm_fence_device *fdev, + uint32_t fence_class, + uint32_t type, + uint32_t create_flags, + struct ttm_fence_object **c_fence) +{ + struct ttm_fence_object *fence; + int ret; + + ret = ttm_mem_global_alloc(fdev->mem_glob, + sizeof(*fence), + false, + false); + if (unlikely(ret != 0)) { + printk(KERN_ERR "Out of memory creating fence object\n"); + return ret; + } + + fence = kmalloc(sizeof(*fence), GFP_KERNEL); + if (!fence) { + printk(KERN_ERR "Out of memory creating fence object\n"); + ttm_mem_global_free(fdev->mem_glob, sizeof(*fence)); + return -ENOMEM; + } + + ret = ttm_fence_object_init(fdev, fence_class, type, + create_flags, NULL, fence); + if (ret) { + ttm_fence_object_unref(&fence); + return ret; + } + *c_fence = fence; + + return 0; +} + +static void ttm_fence_object_destroy(struct kref *kref) +{ + struct ttm_fence_object *fence = + container_of(kref, struct ttm_fence_object, kref); + struct ttm_fence_class_manager *fc = ttm_fence_fc(fence); + unsigned long irq_flags; + + write_lock_irqsave(&fc->lock, irq_flags); + list_del_init(&fence->ring); + write_unlock_irqrestore(&fc->lock, irq_flags); + + atomic_dec(&fence->fdev->count); + if (fence->destroy) + fence->destroy(fence); + else { + ttm_mem_global_free(fence->fdev->mem_glob, + sizeof(*fence)); + kfree(fence); + } +} + +void ttm_fence_device_release(struct ttm_fence_device *fdev) +{ + kfree(fdev->fence_class); +} + +int +ttm_fence_device_init(int num_classes, + struct ttm_mem_global *mem_glob, + struct ttm_fence_device *fdev, + const struct ttm_fence_class_init *init, + bool replicate_init, + const struct ttm_fence_driver *driver) +{ + struct ttm_fence_class_manager *fc; + const struct ttm_fence_class_init *fci; + int i; + + fdev->mem_glob = mem_glob; + fdev->fence_class = kzalloc(num_classes * + sizeof(*fdev->fence_class), GFP_KERNEL); + + if (unlikely(!fdev->fence_class)) + return -ENOMEM; + + fdev->num_classes = num_classes; + atomic_set(&fdev->count, 0); + fdev->driver = driver; + + for (i = 0; i < fdev->num_classes; ++i) { + fc = &fdev->fence_class[i]; + fci = &init[(replicate_init) ? 0 : i]; + + fc->wrap_diff = fci->wrap_diff; + fc->flush_diff = fci->flush_diff; + fc->sequence_mask = fci->sequence_mask; + + rwlock_init(&fc->lock); + INIT_LIST_HEAD(&fc->ring); + init_waitqueue_head(&fc->fence_queue); + } + + return 0; +} + +struct ttm_fence_info ttm_fence_get_info(struct ttm_fence_object *fence) +{ + struct ttm_fence_class_manager *fc = ttm_fence_fc(fence); + struct ttm_fence_info tmp; + unsigned long irq_flags; + + read_lock_irqsave(&fc->lock, irq_flags); + tmp = fence->info; + read_unlock_irqrestore(&fc->lock, irq_flags); + + return tmp; +} + +void ttm_fence_object_unref(struct ttm_fence_object **p_fence) +{ + struct ttm_fence_object *fence = *p_fence; + + *p_fence = NULL; + (void)kref_put(&fence->kref, &ttm_fence_object_destroy); +} + +/* + * Placement / BO sync object glue. + */ + +bool ttm_fence_sync_obj_signaled(void *sync_obj, void *sync_arg) +{ + struct ttm_fence_object *fence = (struct ttm_fence_object *)sync_obj; + uint32_t fence_types = (uint32_t) (unsigned long)sync_arg; + + return ttm_fence_object_signaled(fence, fence_types); +} + +int ttm_fence_sync_obj_wait(void *sync_obj, void *sync_arg, + bool lazy, bool interruptible) +{ + struct ttm_fence_object *fence = (struct ttm_fence_object *)sync_obj; + uint32_t fence_types = (uint32_t) (unsigned long)sync_arg; + + return ttm_fence_object_wait(fence, lazy, interruptible, fence_types); +} + +int ttm_fence_sync_obj_flush(void *sync_obj, void *sync_arg) +{ + struct ttm_fence_object *fence = (struct ttm_fence_object *)sync_obj; + uint32_t fence_types = (uint32_t) (unsigned long)sync_arg; + + return ttm_fence_object_flush(fence, fence_types); +} + +void ttm_fence_sync_obj_unref(void **sync_obj) +{ + ttm_fence_object_unref((struct ttm_fence_object **)sync_obj); +} + +void *ttm_fence_sync_obj_ref(void *sync_obj) +{ + return (void *) + ttm_fence_object_ref((struct ttm_fence_object *)sync_obj); +} diff --git a/trunk/drivers/staging/gma500/psb_ttm_fence_api.h b/trunk/drivers/staging/gma500/psb_ttm_fence_api.h new file mode 100644 index 000000000000..b14a42711d03 --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_ttm_fence_api.h @@ -0,0 +1,272 @@ +/************************************************************************** + * + * Copyright (c) 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA + * All Rights Reserved. + * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ +/* + * Authors: Thomas Hellstrom + */ +#ifndef _TTM_FENCE_API_H_ +#define _TTM_FENCE_API_H_ + +#include +#include + +#define TTM_FENCE_FLAG_EMIT (1 << 0) +#define TTM_FENCE_TYPE_EXE (1 << 0) + +struct ttm_fence_device; + +/** + * struct ttm_fence_info + * + * @fence_class: The fence class. + * @fence_type: Bitfield indicating types for this fence. + * @signaled_types: Bitfield indicating which types are signaled. + * @error: Last error reported from the device. + * + * Used as output from the ttm_fence_get_info + */ + +struct ttm_fence_info { + uint32_t signaled_types; + uint32_t error; +}; + +/** + * struct ttm_fence_object + * + * @fdev: Pointer to the fence device struct. + * @kref: Holds the reference count of this fence object. + * @ring: List head used for the circular list of not-completely + * signaled fences. + * @info: Data for fast retrieval using the ttm_fence_get_info() + * function. + * @timeout_jiffies: Absolute jiffies value indicating when this fence + * object times out and, if waited on, calls ttm_fence_lockup + * to check for and resolve a GPU lockup. + * @sequence: Fence sequence number. + * @waiting_types: Types currently waited on. + * @destroy: Called to free the fence object, when its refcount has + * reached zero. If NULL, kfree is used. + * + * This struct is provided in the driver interface so that drivers can + * derive from it and create their own fence implementation. All members + * are private to the fence implementation and the fence driver callbacks. + * Otherwise a driver may access the derived object using container_of(). + */ + +struct ttm_fence_object { + struct ttm_fence_device *fdev; + struct kref kref; + uint32_t fence_class; + uint32_t fence_type; + + /* + * The below fields are protected by the fence class + * manager spinlock. + */ + + struct list_head ring; + struct ttm_fence_info info; + unsigned long timeout_jiffies; + uint32_t sequence; + uint32_t waiting_types; + void (*destroy) (struct ttm_fence_object *); +}; + +/** + * ttm_fence_object_init + * + * @fdev: Pointer to a struct ttm_fence_device. + * @fence_class: Fence class for this fence. + * @type: Fence type for this fence. + * @create_flags: Flags indicating varios actions at init time. At this point + * there's only TTM_FENCE_FLAG_EMIT, which triggers a sequence emission to + * the command stream. + * @destroy: Destroy function. If NULL, kfree() is used. + * @fence: The struct ttm_fence_object to initialize. + * + * Initialize a pre-allocated fence object. This function, together with the + * destroy function makes it possible to derive driver-specific fence objects. + */ + +extern int +ttm_fence_object_init(struct ttm_fence_device *fdev, + uint32_t fence_class, + uint32_t type, + uint32_t create_flags, + void (*destroy) (struct ttm_fence_object *fence), + struct ttm_fence_object *fence); + +/** + * ttm_fence_object_create + * + * @fdev: Pointer to a struct ttm_fence_device. + * @fence_class: Fence class for this fence. + * @type: Fence type for this fence. + * @create_flags: Flags indicating varios actions at init time. At this point + * there's only TTM_FENCE_FLAG_EMIT, which triggers a sequence emission to + * the command stream. + * @c_fence: On successful termination, *(@c_fence) will point to the created + * fence object. + * + * Create and initialize a struct ttm_fence_object. The destroy function will + * be set to kfree(). + */ + +extern int +ttm_fence_object_create(struct ttm_fence_device *fdev, + uint32_t fence_class, + uint32_t type, + uint32_t create_flags, + struct ttm_fence_object **c_fence); + +/** + * ttm_fence_object_wait + * + * @fence: The fence object to wait on. + * @lazy: Allow sleeps to reduce the cpu-usage if polling. + * @interruptible: Sleep interruptible when waiting. + * @type_mask: Wait for the given type_mask to signal. + * + * Wait for a fence to signal the given type_mask. The function will + * perform a fence_flush using type_mask. (See ttm_fence_object_flush). + * + * Returns + * -ERESTART if interrupted by a signal. + * May return driver-specific error codes if timed-out. + */ + +extern int +ttm_fence_object_wait(struct ttm_fence_object *fence, + bool lazy, bool interruptible, uint32_t type_mask); + +/** + * ttm_fence_object_flush + * + * @fence: The fence object to flush. + * @flush_mask: Fence types to flush. + * + * Make sure that the given fence eventually signals the + * types indicated by @flush_mask. Note that this may or may not + * map to a CPU or GPU flush. + */ + +extern int +ttm_fence_object_flush(struct ttm_fence_object *fence, uint32_t flush_mask); + +/** + * ttm_fence_get_info + * + * @fence: The fence object. + * + * Copy the info block from the fence while holding relevant locks. + */ + +struct ttm_fence_info ttm_fence_get_info(struct ttm_fence_object *fence); + +/** + * ttm_fence_object_ref + * + * @fence: The fence object. + * + * Return a ref-counted pointer to the fence object indicated by @fence. + */ + +static inline struct ttm_fence_object *ttm_fence_object_ref(struct + ttm_fence_object + *fence) +{ + kref_get(&fence->kref); + return fence; +} + +/** + * ttm_fence_object_unref + * + * @p_fence: Pointer to a ref-counted pinter to a struct ttm_fence_object. + * + * Unreference the fence object pointed to by *(@p_fence), clearing + * *(p_fence). + */ + +extern void ttm_fence_object_unref(struct ttm_fence_object **p_fence); + +/** + * ttm_fence_object_signaled + * + * @fence: Pointer to the struct ttm_fence_object. + * @mask: Type mask to check whether signaled. + * + * This function checks (without waiting) whether the fence object + * pointed to by @fence has signaled the types indicated by @mask, + * and returns 1 if true, 0 if false. This function does NOT perform + * an implicit fence flush. + */ + +extern bool +ttm_fence_object_signaled(struct ttm_fence_object *fence, uint32_t mask); + +/** + * ttm_fence_class + * + * @fence: Pointer to the struct ttm_fence_object. + * + * Convenience function that returns the fence class of a + * struct ttm_fence_object. + */ + +static inline uint32_t ttm_fence_class(const struct ttm_fence_object *fence) +{ + return fence->fence_class; +} + +/** + * ttm_fence_types + * + * @fence: Pointer to the struct ttm_fence_object. + * + * Convenience function that returns the fence types of a + * struct ttm_fence_object. + */ + +static inline uint32_t ttm_fence_types(const struct ttm_fence_object *fence) +{ + return fence->fence_type; +} + +/* + * The functions below are wrappers to the above functions, with + * similar names but with sync_obj omitted. These wrappers are intended + * to be plugged directly into the buffer object driver's sync object + * API, if the driver chooses to use ttm_fence_objects as buffer object + * sync objects. In the prototypes below, a sync_obj is cast to a + * struct ttm_fence_object, whereas a sync_arg is cast to an + * uint32_t representing a fence_type argument. + */ + +extern bool ttm_fence_sync_obj_signaled(void *sync_obj, void *sync_arg); +extern int ttm_fence_sync_obj_wait(void *sync_obj, void *sync_arg, + bool lazy, bool interruptible); +extern int ttm_fence_sync_obj_flush(void *sync_obj, void *sync_arg); +extern void ttm_fence_sync_obj_unref(void **sync_obj); +extern void *ttm_fence_sync_obj_ref(void *sync_obj); + +#endif diff --git a/trunk/drivers/staging/gma500/psb_ttm_fence_driver.h b/trunk/drivers/staging/gma500/psb_ttm_fence_driver.h new file mode 100644 index 000000000000..c35c569fa3f0 --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_ttm_fence_driver.h @@ -0,0 +1,302 @@ +/************************************************************************** + * + * Copyright (c) 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA + * All Rights Reserved. + * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ +/* + * Authors: Thomas Hellstrom + */ +#ifndef _TTM_FENCE_DRIVER_H_ +#define _TTM_FENCE_DRIVER_H_ + +#include +#include +#include +#include "psb_ttm_fence_api.h" +#include "ttm/ttm_memory.h" + +/** @file ttm_fence_driver.h + * + * Definitions needed for a driver implementing the + * ttm_fence subsystem. + */ + +/** + * struct ttm_fence_class_manager: + * + * @wrap_diff: Sequence difference to catch 32-bit wrapping. + * if (seqa - seqb) > @wrap_diff, then seqa < seqb. + * @flush_diff: Sequence difference to trigger fence flush. + * if (cur_seq - seqa) > @flush_diff, then consider fence object with + * seqa as old an needing a flush. + * @sequence_mask: Mask of valid bits in a fence sequence. + * @lock: Lock protecting this struct as well as fence objects + * associated with this struct. + * @ring: Circular sequence-ordered list of fence objects. + * @pending_flush: Fence types currently needing a flush. + * @waiting_types: Fence types that are currently waited for. + * @fence_queue: Queue of waiters on fences belonging to this fence class. + * @highest_waiting_sequence: Sequence number of the fence with highest + * sequence number and that is waited for. + * @latest_queued_sequence: Sequence number of the fence latest queued + * on the ring. + */ + +struct ttm_fence_class_manager { + + /* + * Unprotected constant members. + */ + + uint32_t wrap_diff; + uint32_t flush_diff; + uint32_t sequence_mask; + + /* + * The rwlock protects this structure as well as + * the data in all fence objects belonging to this + * class. This should be OK as most fence objects are + * only read from once they're created. + */ + + rwlock_t lock; + struct list_head ring; + uint32_t pending_flush; + uint32_t waiting_types; + wait_queue_head_t fence_queue; + uint32_t highest_waiting_sequence; + uint32_t latest_queued_sequence; +}; + +/** + * struct ttm_fence_device + * + * @fence_class: Array of fence class managers. + * @num_classes: Array dimension of @fence_class. + * @count: Current number of fence objects for statistics. + * @driver: Driver struct. + * + * Provided in the driver interface so that the driver can derive + * from this struct for its driver_private, and accordingly + * access the driver_private from the fence driver callbacks. + * + * All members except "count" are initialized at creation and + * never touched after that. No protection needed. + * + * This struct is private to the fence implementation and to the fence + * driver callbacks, and may otherwise be used by drivers only to + * obtain the derived device_private object using container_of(). + */ + +struct ttm_fence_device { + struct ttm_mem_global *mem_glob; + struct ttm_fence_class_manager *fence_class; + uint32_t num_classes; + atomic_t count; + const struct ttm_fence_driver *driver; +}; + +/** + * struct ttm_fence_class_init + * + * @wrap_diff: Fence sequence number wrap indicator. If + * (sequence1 - sequence2) > @wrap_diff, then sequence1 is + * considered to be older than sequence2. + * @flush_diff: Fence sequence number flush indicator. + * If a non-completely-signaled fence has a fence sequence number + * sequence1 and (sequence1 - current_emit_sequence) > @flush_diff, + * the fence is considered too old and it will be flushed upon the + * next call of ttm_fence_flush_old(), to make sure no fences with + * stale sequence numbers remains unsignaled. @flush_diff should + * be sufficiently less than @wrap_diff. + * @sequence_mask: Mask with valid bits of the fence sequence + * number set to 1. + * + * This struct is used as input to ttm_fence_device_init. + */ + +struct ttm_fence_class_init { + uint32_t wrap_diff; + uint32_t flush_diff; + uint32_t sequence_mask; +}; + +/** + * struct ttm_fence_driver + * + * @has_irq: Called by a potential waiter. Should return 1 if a + * fence object with indicated parameters is expected to signal + * automatically, and 0 if the fence implementation needs to + * repeatedly call @poll to make it signal. + * @emit: Make sure a fence with the given parameters is + * present in the indicated command stream. Return its sequence number + * in "breadcrumb". + * @poll: Check and report sequences of the given "fence_class" + * that have signaled "types" + * @flush: Make sure that the types indicated by the bitfield + * ttm_fence_class_manager::pending_flush will eventually + * signal. These bits have been put together using the + * result from the needed_flush function described below. + * @needed_flush: Given the fence_class and fence_types indicated by + * "fence", and the last received fence sequence of this + * fence class, indicate what types need a fence flush to + * signal. Return as a bitfield. + * @wait: Set to non-NULL if the driver wants to override the fence + * wait implementation. Return 0 on success, -EBUSY on failure, + * and -ERESTART if interruptible and a signal is pending. + * @signaled: Driver callback that is called whenever a + * ttm_fence_object::signaled_types has changed status. + * This function is called from atomic context, + * with the ttm_fence_class_manager::lock held in write mode. + * @lockup: Driver callback that is called whenever a wait has exceeded + * the lifetime of a fence object. + * If there is a GPU lockup, + * this function should, if possible, reset the GPU, + * call the ttm_fence_handler with an error status, and + * return. If no lockup was detected, simply extend the + * fence timeout_jiffies and return. The driver might + * want to protect the lockup check with a mutex and cache a + * non-locked-up status for a while to avoid an excessive + * amount of lockup checks from every waiting thread. + */ + +struct ttm_fence_driver { + bool (*has_irq) (struct ttm_fence_device *fdev, + uint32_t fence_class, uint32_t flags); + int (*emit) (struct ttm_fence_device *fdev, + uint32_t fence_class, + uint32_t flags, + uint32_t *breadcrumb, unsigned long *timeout_jiffies); + void (*flush) (struct ttm_fence_device *fdev, uint32_t fence_class); + void (*poll) (struct ttm_fence_device *fdev, + uint32_t fence_class, uint32_t types); + uint32_t(*needed_flush) + (struct ttm_fence_object *fence); + int (*wait) (struct ttm_fence_object *fence, bool lazy, + bool interruptible, uint32_t mask); + void (*signaled) (struct ttm_fence_object *fence); + void (*lockup) (struct ttm_fence_object *fence, uint32_t fence_types); +}; + +/** + * function ttm_fence_device_init + * + * @num_classes: Number of fence classes for this fence implementation. + * @mem_global: Pointer to the global memory accounting info. + * @fdev: Pointer to an uninitialised struct ttm_fence_device. + * @init: Array of initialization info for each fence class. + * @replicate_init: Use the first @init initialization info for all classes. + * @driver: Driver callbacks. + * + * Initialize a struct ttm_fence_driver structure. Returns -ENOMEM if + * out-of-memory. Otherwise returns 0. + */ +extern int +ttm_fence_device_init(int num_classes, + struct ttm_mem_global *mem_glob, + struct ttm_fence_device *fdev, + const struct ttm_fence_class_init *init, + bool replicate_init, + const struct ttm_fence_driver *driver); + +/** + * function ttm_fence_device_release + * + * @fdev: Pointer to the fence device. + * + * Release all resources held by a fence device. Note that before + * this function is called, the caller must have made sure all fence + * objects belonging to this fence device are completely signaled. + */ + +extern void ttm_fence_device_release(struct ttm_fence_device *fdev); + +/** + * ttm_fence_handler - the fence handler. + * + * @fdev: Pointer to the fence device. + * @fence_class: Fence class that signals. + * @sequence: Signaled sequence. + * @type: Types that signal. + * @error: Error from the engine. + * + * This function signals all fences with a sequence previous to the + * @sequence argument, and belonging to @fence_class. The signaled fence + * types are provided in @type. If error is non-zero, the error member + * of the fence with sequence = @sequence is set to @error. This value + * may be reported back to user-space, indicating, for example an illegal + * 3D command or illegal mpeg data. + * + * This function is typically called from the driver::poll method when the + * command sequence preceding the fence marker has executed. It should be + * called with the ttm_fence_class_manager::lock held in write mode and + * may be called from interrupt context. + */ + +extern void +ttm_fence_handler(struct ttm_fence_device *fdev, + uint32_t fence_class, + uint32_t sequence, uint32_t type, uint32_t error); + +/** + * ttm_fence_driver_from_dev + * + * @fdev: The ttm fence device. + * + * Returns a pointer to the fence driver struct. + */ + +static inline const struct ttm_fence_driver *ttm_fence_driver_from_dev( + struct ttm_fence_device *fdev) +{ + return fdev->driver; +} + +/** + * ttm_fence_driver + * + * @fence: Pointer to a ttm fence object. + * + * Returns a pointer to the fence driver struct. + */ + +static inline const struct ttm_fence_driver *ttm_fence_driver(struct + ttm_fence_object + *fence) +{ + return ttm_fence_driver_from_dev(fence->fdev); +} + +/** + * ttm_fence_fc + * + * @fence: Pointer to a ttm fence object. + * + * Returns a pointer to the struct ttm_fence_class_manager for the + * fence class of @fence. + */ + +static inline struct ttm_fence_class_manager *ttm_fence_fc(struct + ttm_fence_object + *fence) +{ + return &fence->fdev->fence_class[fence->fence_class]; +} + +#endif diff --git a/trunk/drivers/staging/gma500/psb_ttm_fence_user.c b/trunk/drivers/staging/gma500/psb_ttm_fence_user.c new file mode 100644 index 000000000000..36f974fc607d --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_ttm_fence_user.c @@ -0,0 +1,237 @@ +/************************************************************************** + * + * Copyright (c) 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA + * All Rights Reserved. + * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ +/* + * Authors: Thomas Hellstrom + */ + +#include +#include "psb_ttm_fence_user.h" +#include "ttm/ttm_object.h" +#include "psb_ttm_fence_driver.h" +#include "psb_ttm_userobj_api.h" + +/** + * struct ttm_fence_user_object + * + * @base: The base object used for user-space visibility and refcounting. + * + * @fence: The fence object itself. + * + */ + +struct ttm_fence_user_object { + struct ttm_base_object base; + struct ttm_fence_object fence; +}; + +static struct ttm_fence_user_object *ttm_fence_user_object_lookup( + struct ttm_object_file *tfile, + uint32_t handle) +{ + struct ttm_base_object *base; + + base = ttm_base_object_lookup(tfile, handle); + if (unlikely(base == NULL)) { + printk(KERN_ERR "Invalid fence handle 0x%08lx\n", + (unsigned long)handle); + return NULL; + } + + if (unlikely(base->object_type != ttm_fence_type)) { + ttm_base_object_unref(&base); + printk(KERN_ERR "Invalid fence handle 0x%08lx\n", + (unsigned long)handle); + return NULL; + } + + return container_of(base, struct ttm_fence_user_object, base); +} + +/* + * The fence object destructor. + */ + +static void ttm_fence_user_destroy(struct ttm_fence_object *fence) +{ + struct ttm_fence_user_object *ufence = + container_of(fence, struct ttm_fence_user_object, fence); + + ttm_mem_global_free(fence->fdev->mem_glob, sizeof(*ufence)); + kfree(ufence); +} + +/* + * The base object destructor. We basically unly unreference the + * attached fence object. + */ + +static void ttm_fence_user_release(struct ttm_base_object **p_base) +{ + struct ttm_fence_user_object *ufence; + struct ttm_base_object *base = *p_base; + struct ttm_fence_object *fence; + + *p_base = NULL; + + if (unlikely(base == NULL)) + return; + + ufence = container_of(base, struct ttm_fence_user_object, base); + fence = &ufence->fence; + ttm_fence_object_unref(&fence); +} + +int +ttm_fence_user_create(struct ttm_fence_device *fdev, + struct ttm_object_file *tfile, + uint32_t fence_class, + uint32_t fence_types, + uint32_t create_flags, + struct ttm_fence_object **fence, + uint32_t *user_handle) +{ + int ret; + struct ttm_fence_object *tmp; + struct ttm_fence_user_object *ufence; + + ret = ttm_mem_global_alloc(fdev->mem_glob, + sizeof(*ufence), + false, + false); + if (unlikely(ret != 0)) + return -ENOMEM; + + ufence = kmalloc(sizeof(*ufence), GFP_KERNEL); + if (unlikely(ufence == NULL)) { + ttm_mem_global_free(fdev->mem_glob, sizeof(*ufence)); + return -ENOMEM; + } + + ret = ttm_fence_object_init(fdev, + fence_class, + fence_types, create_flags, + &ttm_fence_user_destroy, &ufence->fence); + + if (unlikely(ret != 0)) + goto out_err0; + + /* + * One fence ref is held by the fence ptr we return. + * The other one by the base object. Need to up the + * fence refcount before we publish this object to + * user-space. + */ + + tmp = ttm_fence_object_ref(&ufence->fence); + ret = ttm_base_object_init(tfile, &ufence->base, + false, ttm_fence_type, + &ttm_fence_user_release, NULL); + + if (unlikely(ret != 0)) + goto out_err1; + + *fence = &ufence->fence; + *user_handle = ufence->base.hash.key; + + return 0; +out_err1: + ttm_fence_object_unref(&tmp); + tmp = &ufence->fence; + ttm_fence_object_unref(&tmp); + return ret; +out_err0: + ttm_mem_global_free(fdev->mem_glob, sizeof(*ufence)); + kfree(ufence); + return ret; +} + +int ttm_fence_signaled_ioctl(struct ttm_object_file *tfile, void *data) +{ + int ret; + union ttm_fence_signaled_arg *arg = data; + struct ttm_fence_object *fence; + struct ttm_fence_info info; + struct ttm_fence_user_object *ufence; + struct ttm_base_object *base; + ret = 0; + + ufence = ttm_fence_user_object_lookup(tfile, arg->req.handle); + if (unlikely(ufence == NULL)) + return -EINVAL; + + fence = &ufence->fence; + + if (arg->req.flush) { + ret = ttm_fence_object_flush(fence, arg->req.fence_type); + if (unlikely(ret != 0)) + goto out; + } + + info = ttm_fence_get_info(fence); + arg->rep.signaled_types = info.signaled_types; + arg->rep.fence_error = info.error; + +out: + base = &ufence->base; + ttm_base_object_unref(&base); + return ret; +} + +int ttm_fence_finish_ioctl(struct ttm_object_file *tfile, void *data) +{ + int ret; + union ttm_fence_finish_arg *arg = data; + struct ttm_fence_user_object *ufence; + struct ttm_base_object *base; + struct ttm_fence_object *fence; + ret = 0; + + ufence = ttm_fence_user_object_lookup(tfile, arg->req.handle); + if (unlikely(ufence == NULL)) + return -EINVAL; + + fence = &ufence->fence; + + ret = ttm_fence_object_wait(fence, + arg->req.mode & TTM_FENCE_FINISH_MODE_LAZY, + true, arg->req.fence_type); + if (likely(ret == 0)) { + struct ttm_fence_info info = ttm_fence_get_info(fence); + + arg->rep.signaled_types = info.signaled_types; + arg->rep.fence_error = info.error; + } + + base = &ufence->base; + ttm_base_object_unref(&base); + + return ret; +} + +int ttm_fence_unref_ioctl(struct ttm_object_file *tfile, void *data) +{ + struct ttm_fence_unref_arg *arg = data; + int ret = 0; + + ret = ttm_ref_object_base_unref(tfile, arg->handle, ttm_fence_type); + return ret; +} diff --git a/trunk/drivers/staging/gma500/psb_ttm_fence_user.h b/trunk/drivers/staging/gma500/psb_ttm_fence_user.h new file mode 100644 index 000000000000..762a05728632 --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_ttm_fence_user.h @@ -0,0 +1,140 @@ +/************************************************************************** + * + * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA + * All Rights Reserved. + * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ +/* + * Authors + * Thomas Hellström + */ + +#ifndef TTM_FENCE_USER_H +#define TTM_FENCE_USER_H + +#if !defined(__KERNEL__) && !defined(_KERNEL) +#include +#endif + +#define TTM_FENCE_MAJOR 0 +#define TTM_FENCE_MINOR 1 +#define TTM_FENCE_PL 0 +#define TTM_FENCE_DATE "080819" + +/** + * struct ttm_fence_signaled_req + * + * @handle: Handle to the fence object. Input. + * + * @fence_type: Fence types we want to flush. Input. + * + * @flush: Boolean. Flush the indicated fence_types. Input. + * + * Argument to the TTM_FENCE_SIGNALED ioctl. + */ + +struct ttm_fence_signaled_req { + uint32_t handle; + uint32_t fence_type; + int32_t flush; + uint32_t pad64; +}; + +/** + * struct ttm_fence_rep + * + * @signaled_types: Fence type that has signaled. + * + * @fence_error: Command execution error. + * Hardware errors that are consequences of the execution + * of the command stream preceding the fence are reported + * here. + * + * Output argument to the TTM_FENCE_SIGNALED and + * TTM_FENCE_FINISH ioctls. + */ + +struct ttm_fence_rep { + uint32_t signaled_types; + uint32_t fence_error; +}; + +union ttm_fence_signaled_arg { + struct ttm_fence_signaled_req req; + struct ttm_fence_rep rep; +}; + +/* + * Waiting mode flags for the TTM_FENCE_FINISH ioctl. + * + * TTM_FENCE_FINISH_MODE_LAZY: Allow for sleeps during polling + * wait. + * + * TTM_FENCE_FINISH_MODE_NO_BLOCK: Don't block waiting for GPU, + * but return -EBUSY if the buffer is busy. + */ + +#define TTM_FENCE_FINISH_MODE_LAZY (1 << 0) +#define TTM_FENCE_FINISH_MODE_NO_BLOCK (1 << 1) + +/** + * struct ttm_fence_finish_req + * + * @handle: Handle to the fence object. Input. + * + * @fence_type: Fence types we want to finish. + * + * @mode: Wait mode. + * + * Input to the TTM_FENCE_FINISH ioctl. + */ + +struct ttm_fence_finish_req { + uint32_t handle; + uint32_t fence_type; + uint32_t mode; + uint32_t pad64; +}; + +union ttm_fence_finish_arg { + struct ttm_fence_finish_req req; + struct ttm_fence_rep rep; +}; + +/** + * struct ttm_fence_unref_arg + * + * @handle: Handle to the fence object. + * + * Argument to the TTM_FENCE_UNREF ioctl. + */ + +struct ttm_fence_unref_arg { + uint32_t handle; + uint32_t pad64; +}; + +/* + * Ioctl offsets from extenstion start. + */ + +#define TTM_FENCE_SIGNALED 0x01 +#define TTM_FENCE_FINISH 0x02 +#define TTM_FENCE_UNREF 0x03 + +#endif diff --git a/trunk/drivers/staging/gma500/psb_ttm_glue.c b/trunk/drivers/staging/gma500/psb_ttm_glue.c new file mode 100644 index 000000000000..d1d965e69ecd --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_ttm_glue.c @@ -0,0 +1,349 @@ +/************************************************************************** + * Copyright (c) 2008, Intel Corporation. + * All Rights Reserved. + * Copyright (c) 2008, Tungsten Graphics Inc. Cedar Park, TX., USA. + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ + + +#include +#include "psb_drv.h" +#include "psb_ttm_userobj_api.h" +#include + + +static struct vm_operations_struct psb_ttm_vm_ops; + +/** + * NOTE: driver_private of drm_file is now a struct psb_file_data struct + * pPriv in struct psb_file_data contains the original psb_fpriv; + */ +int psb_open(struct inode *inode, struct file *filp) +{ + struct drm_file *file_priv; + struct drm_psb_private *dev_priv; + struct psb_fpriv *psb_fp; + struct psb_file_data *pvr_file_priv; + int ret; + + DRM_DEBUG("\n"); + + ret = drm_open(inode, filp); + if (unlikely(ret)) + return ret; + + psb_fp = kzalloc(sizeof(*psb_fp), GFP_KERNEL); + + if (unlikely(psb_fp == NULL)) + goto out_err0; + + file_priv = (struct drm_file *) filp->private_data; + dev_priv = psb_priv(file_priv->minor->dev); + + DRM_DEBUG("is_master %d\n", file_priv->is_master ? 1 : 0); + + psb_fp->tfile = ttm_object_file_init(dev_priv->tdev, + PSB_FILE_OBJECT_HASH_ORDER); + if (unlikely(psb_fp->tfile == NULL)) + goto out_err1; + + pvr_file_priv = (struct psb_file_data *)file_priv->driver_priv; + if (!pvr_file_priv) { + DRM_ERROR("drm file private is NULL\n"); + goto out_err1; + } + + pvr_file_priv->priv = psb_fp; + if (unlikely(dev_priv->bdev.dev_mapping == NULL)) + dev_priv->bdev.dev_mapping = dev_priv->dev->dev_mapping; + + return 0; + +out_err1: + kfree(psb_fp); +out_err0: + (void) drm_release(inode, filp); + return ret; +} + +int psb_release(struct inode *inode, struct file *filp) +{ + struct drm_file *file_priv; + struct psb_fpriv *psb_fp; + struct drm_psb_private *dev_priv; + int ret; + file_priv = (struct drm_file *) filp->private_data; + psb_fp = psb_fpriv(file_priv); + dev_priv = psb_priv(file_priv->minor->dev); + + ttm_object_file_release(&psb_fp->tfile); + kfree(psb_fp); + + ret = drm_release(inode, filp); + + return ret; +} + +int psb_fence_signaled_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + + return ttm_fence_signaled_ioctl(psb_fpriv(file_priv)->tfile, data); +} + +int psb_fence_finish_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + return ttm_fence_finish_ioctl(psb_fpriv(file_priv)->tfile, data); +} + +int psb_fence_unref_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + return ttm_fence_unref_ioctl(psb_fpriv(file_priv)->tfile, data); +} + +int psb_pl_waitidle_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + return ttm_pl_waitidle_ioctl(psb_fpriv(file_priv)->tfile, data); +} + +int psb_pl_setstatus_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + return ttm_pl_setstatus_ioctl(psb_fpriv(file_priv)->tfile, + &psb_priv(dev)->ttm_lock, data); + +} + +int psb_pl_synccpu_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + return ttm_pl_synccpu_ioctl(psb_fpriv(file_priv)->tfile, data); +} + +int psb_pl_unref_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + return ttm_pl_unref_ioctl(psb_fpriv(file_priv)->tfile, data); + +} + +int psb_pl_reference_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + return ttm_pl_reference_ioctl(psb_fpriv(file_priv)->tfile, data); + +} + +int psb_pl_create_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + struct drm_psb_private *dev_priv = psb_priv(dev); + + return ttm_pl_create_ioctl(psb_fpriv(file_priv)->tfile, + &dev_priv->bdev, &dev_priv->ttm_lock, data); + +} + +int psb_pl_ub_create_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + struct drm_psb_private *dev_priv = psb_priv(dev); + + return ttm_pl_ub_create_ioctl(psb_fpriv(file_priv)->tfile, + &dev_priv->bdev, &dev_priv->ttm_lock, data); + +} +/** + * psb_ttm_fault - Wrapper around the ttm fault method. + * + * @vma: The struct vm_area_struct as in the vm fault() method. + * @vmf: The struct vm_fault as in the vm fault() method. + * + * Since ttm_fault() will reserve buffers while faulting, + * we need to take the ttm read lock around it, as this driver + * relies on the ttm_lock in write mode to exclude all threads from + * reserving and thus validating buffers in aperture- and memory shortage + * situations. + */ + +static int psb_ttm_fault(struct vm_area_struct *vma, + struct vm_fault *vmf) +{ + struct ttm_buffer_object *bo = (struct ttm_buffer_object *) + vma->vm_private_data; + struct drm_psb_private *dev_priv = + container_of(bo->bdev, struct drm_psb_private, bdev); + int ret; + + ret = ttm_read_lock(&dev_priv->ttm_lock, true); + if (unlikely(ret != 0)) + return VM_FAULT_NOPAGE; + + ret = dev_priv->ttm_vm_ops->fault(vma, vmf); + + ttm_read_unlock(&dev_priv->ttm_lock); + return ret; +} + +/** + * if vm_pgoff < DRM_PSB_FILE_PAGE_OFFSET call directly to + * PVRMMap + */ +int psb_mmap(struct file *filp, struct vm_area_struct *vma) +{ + struct drm_file *file_priv; + struct drm_psb_private *dev_priv; + int ret; + + if (vma->vm_pgoff < DRM_PSB_FILE_PAGE_OFFSET || + vma->vm_pgoff > 2 * DRM_PSB_FILE_PAGE_OFFSET) +#if 0 /* FIXMEAC */ + return PVRMMap(filp, vma); +#else + return -EINVAL; +#endif + + file_priv = (struct drm_file *) filp->private_data; + dev_priv = psb_priv(file_priv->minor->dev); + + ret = ttm_bo_mmap(filp, vma, &dev_priv->bdev); + if (unlikely(ret != 0)) + return ret; + + if (unlikely(dev_priv->ttm_vm_ops == NULL)) { + dev_priv->ttm_vm_ops = (struct vm_operations_struct *) + vma->vm_ops; + psb_ttm_vm_ops = *vma->vm_ops; + psb_ttm_vm_ops.fault = &psb_ttm_fault; + } + + vma->vm_ops = &psb_ttm_vm_ops; + + return 0; +} +/* +ssize_t psb_ttm_write(struct file *filp, const char __user *buf, + size_t count, loff_t *f_pos) +{ + struct drm_file *file_priv = (struct drm_file *)filp->private_data; + struct drm_psb_private *dev_priv = psb_priv(file_priv->minor->dev); + + return ttm_bo_io(&dev_priv->bdev, filp, buf, NULL, count, f_pos, 1); +} + +ssize_t psb_ttm_read(struct file *filp, char __user *buf, + size_t count, loff_t *f_pos) +{ + struct drm_file *file_priv = (struct drm_file *)filp->private_data; + struct drm_psb_private *dev_priv = psb_priv(file_priv->minor->dev); + + return ttm_bo_io(&dev_priv->bdev, filp, NULL, buf, count, f_pos, 1); +} +*/ +int psb_verify_access(struct ttm_buffer_object *bo, + struct file *filp) +{ + struct drm_file *file_priv = (struct drm_file *)filp->private_data; + + if (capable(CAP_SYS_ADMIN)) + return 0; + + if (unlikely(!file_priv->authenticated)) + return -EPERM; + + return ttm_pl_verify_access(bo, psb_fpriv(file_priv)->tfile); +} + +static int psb_ttm_mem_global_init(struct drm_global_reference *ref) +{ + return ttm_mem_global_init(ref->object); +} + +static void psb_ttm_mem_global_release(struct drm_global_reference *ref) +{ + ttm_mem_global_release(ref->object); +} + +int psb_ttm_global_init(struct drm_psb_private *dev_priv) +{ + struct drm_global_reference *global_ref; + int ret; + + global_ref = &dev_priv->mem_global_ref; + global_ref->global_type = DRM_GLOBAL_TTM_MEM; + global_ref->size = sizeof(struct ttm_mem_global); + global_ref->init = &psb_ttm_mem_global_init; + global_ref->release = &psb_ttm_mem_global_release; + + ret = drm_global_item_ref(global_ref); + if (unlikely(ret != 0)) { + DRM_ERROR("Failed referencing a global TTM memory object.\n"); + return ret; + } + + dev_priv->bo_global_ref.mem_glob = dev_priv->mem_global_ref.object; + global_ref = &dev_priv->bo_global_ref.ref; + global_ref->global_type = DRM_GLOBAL_TTM_BO; + global_ref->size = sizeof(struct ttm_bo_global); + global_ref->init = &ttm_bo_global_init; + global_ref->release = &ttm_bo_global_release; + ret = drm_global_item_ref(global_ref); + if (ret != 0) { + DRM_ERROR("Failed setting up TTM BO subsystem.\n"); + drm_global_item_unref(global_ref); + return ret; + } + return 0; +} + +void psb_ttm_global_release(struct drm_psb_private *dev_priv) +{ + drm_global_item_unref(&dev_priv->mem_global_ref); +} + +int psb_getpageaddrs_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv) +{ + struct drm_psb_getpageaddrs_arg *arg = data; + struct ttm_buffer_object *bo; + struct ttm_tt *ttm; + struct page **tt_pages; + unsigned long i, num_pages; + unsigned long *p = arg->page_addrs; + int ret = 0; + + bo = ttm_buffer_object_lookup(psb_fpriv(file_priv)->tfile, + arg->handle); + if (unlikely(bo == NULL)) { + printk(KERN_ERR + "Could not find buffer object for getpageaddrs.\n"); + return -EINVAL; + } + + arg->gtt_offset = bo->offset; + ttm = bo->ttm; + num_pages = ttm->num_pages; + tt_pages = ttm->pages; + + for (i = 0; i < num_pages; i++) + p[i] = (unsigned long)page_to_phys(tt_pages[i]); + + return ret; +} diff --git a/trunk/drivers/staging/gma500/psb_ttm_placement_user.c b/trunk/drivers/staging/gma500/psb_ttm_placement_user.c new file mode 100644 index 000000000000..272b397982ed --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_ttm_placement_user.c @@ -0,0 +1,628 @@ +/************************************************************************** + * + * Copyright (c) 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ +/* + * Authors: Thomas Hellstrom + */ + +#include "psb_ttm_placement_user.h" +#include "ttm/ttm_bo_driver.h" +#include "ttm/ttm_object.h" +#include "psb_ttm_userobj_api.h" +#include "ttm/ttm_lock.h" +#include +#include + +struct ttm_bo_user_object { + struct ttm_base_object base; + struct ttm_buffer_object bo; +}; + +static size_t pl_bo_size; + +static uint32_t psb_busy_prios[] = { + TTM_PL_TT, + TTM_PL_PRIV0, /* CI */ + TTM_PL_PRIV2, /* RAR */ + TTM_PL_PRIV1, /* DRM_PSB_MEM_MMU */ + TTM_PL_SYSTEM +}; + +static const struct ttm_placement default_placement = { + 0, 0, 0, NULL, 5, psb_busy_prios +}; + +static size_t ttm_pl_size(struct ttm_bo_device *bdev, unsigned long num_pages) +{ + size_t page_array_size = + (num_pages * sizeof(void *) + PAGE_SIZE - 1) & PAGE_MASK; + + if (unlikely(pl_bo_size == 0)) { + pl_bo_size = bdev->glob->ttm_bo_extra_size + + ttm_round_pot(sizeof(struct ttm_bo_user_object)); + } + + return bdev->glob->ttm_bo_size + 2 * page_array_size; +} + +static struct ttm_bo_user_object *ttm_bo_user_lookup(struct ttm_object_file + *tfile, uint32_t handle) +{ + struct ttm_base_object *base; + + base = ttm_base_object_lookup(tfile, handle); + if (unlikely(base == NULL)) { + printk(KERN_ERR "Invalid buffer object handle 0x%08lx.\n", + (unsigned long)handle); + return NULL; + } + + if (unlikely(base->object_type != ttm_buffer_type)) { + ttm_base_object_unref(&base); + printk(KERN_ERR "Invalid buffer object handle 0x%08lx.\n", + (unsigned long)handle); + return NULL; + } + + return container_of(base, struct ttm_bo_user_object, base); +} + +struct ttm_buffer_object *ttm_buffer_object_lookup(struct ttm_object_file + *tfile, uint32_t handle) +{ + struct ttm_bo_user_object *user_bo; + struct ttm_base_object *base; + + user_bo = ttm_bo_user_lookup(tfile, handle); + if (unlikely(user_bo == NULL)) + return NULL; + + (void)ttm_bo_reference(&user_bo->bo); + base = &user_bo->base; + ttm_base_object_unref(&base); + return &user_bo->bo; +} + +static void ttm_bo_user_destroy(struct ttm_buffer_object *bo) +{ + struct ttm_bo_user_object *user_bo = + container_of(bo, struct ttm_bo_user_object, bo); + + ttm_mem_global_free(bo->glob->mem_glob, bo->acc_size); + kfree(user_bo); +} + +static void ttm_bo_user_release(struct ttm_base_object **p_base) +{ + struct ttm_bo_user_object *user_bo; + struct ttm_base_object *base = *p_base; + struct ttm_buffer_object *bo; + + *p_base = NULL; + + if (unlikely(base == NULL)) + return; + + user_bo = container_of(base, struct ttm_bo_user_object, base); + bo = &user_bo->bo; + ttm_bo_unref(&bo); +} + +static void ttm_bo_user_ref_release(struct ttm_base_object *base, + enum ttm_ref_type ref_type) +{ + struct ttm_bo_user_object *user_bo = + container_of(base, struct ttm_bo_user_object, base); + struct ttm_buffer_object *bo = &user_bo->bo; + + switch (ref_type) { + case TTM_REF_SYNCCPU_WRITE: + ttm_bo_synccpu_write_release(bo); + break; + default: + BUG(); + } +} + +static void ttm_pl_fill_rep(struct ttm_buffer_object *bo, + struct ttm_pl_rep *rep) +{ + struct ttm_bo_user_object *user_bo = + container_of(bo, struct ttm_bo_user_object, bo); + + rep->gpu_offset = bo->offset; + rep->bo_size = bo->num_pages << PAGE_SHIFT; + rep->map_handle = bo->addr_space_offset; + rep->placement = bo->mem.placement; + rep->handle = user_bo->base.hash.key; + rep->sync_object_arg = (uint32_t) (unsigned long)bo->sync_obj_arg; +} + +/* FIXME Copy from upstream TTM */ +static inline size_t ttm_bo_size(struct ttm_bo_global *glob, + unsigned long num_pages) +{ + size_t page_array_size = (num_pages * sizeof(void *) + PAGE_SIZE - 1) & + PAGE_MASK; + + return glob->ttm_bo_size + 2 * page_array_size; +} + +/* FIXME Copy from upstream TTM "ttm_bo_create", upstream TTM does not + export this, so copy it here */ +static int ttm_bo_create_private(struct ttm_bo_device *bdev, + unsigned long size, + enum ttm_bo_type type, + struct ttm_placement *placement, + uint32_t page_alignment, + unsigned long buffer_start, + bool interruptible, + struct file *persistant_swap_storage, + struct ttm_buffer_object **p_bo) +{ + struct ttm_buffer_object *bo; + struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; + int ret; + + size_t acc_size = + ttm_bo_size(bdev->glob, (size + PAGE_SIZE - 1) >> PAGE_SHIFT); + ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false); + if (unlikely(ret != 0)) + return ret; + + bo = kzalloc(sizeof(*bo), GFP_KERNEL); + + if (unlikely(bo == NULL)) { + ttm_mem_global_free(mem_glob, acc_size); + return -ENOMEM; + } + + ret = ttm_bo_init(bdev, bo, size, type, placement, page_alignment, + buffer_start, interruptible, + persistant_swap_storage, acc_size, NULL); + if (likely(ret == 0)) + *p_bo = bo; + + return ret; +} + +int psb_ttm_bo_check_placement(struct ttm_buffer_object *bo, + struct ttm_placement *placement) +{ + int i; + + for (i = 0; i < placement->num_placement; i++) { + if (!capable(CAP_SYS_ADMIN)) { + if (placement->placement[i] & TTM_PL_FLAG_NO_EVICT) { + printk(KERN_ERR TTM_PFX "Need to be root to " + "modify NO_EVICT status.\n"); + return -EINVAL; + } + } + } + for (i = 0; i < placement->num_busy_placement; i++) { + if (!capable(CAP_SYS_ADMIN)) { + if (placement->busy_placement[i] + & TTM_PL_FLAG_NO_EVICT) { + printk(KERN_ERR TTM_PFX "Need to be root to modify NO_EVICT status.\n"); + return -EINVAL; + } + } + } + return 0; +} + +int ttm_buffer_object_create(struct ttm_bo_device *bdev, + unsigned long size, + enum ttm_bo_type type, + uint32_t flags, + uint32_t page_alignment, + unsigned long buffer_start, + bool interruptible, + struct file *persistant_swap_storage, + struct ttm_buffer_object **p_bo) +{ + struct ttm_placement placement = default_placement; + int ret; + + if ((flags & TTM_PL_MASK_CACHING) == 0) + flags |= TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED; + + placement.num_placement = 1; + placement.placement = &flags; + + ret = ttm_bo_create_private(bdev, + size, + type, + &placement, + page_alignment, + buffer_start, + interruptible, + persistant_swap_storage, + p_bo); + + return ret; +} + + +int ttm_pl_create_ioctl(struct ttm_object_file *tfile, + struct ttm_bo_device *bdev, + struct ttm_lock *lock, void *data) +{ + union ttm_pl_create_arg *arg = data; + struct ttm_pl_create_req *req = &arg->req; + struct ttm_pl_rep *rep = &arg->rep; + struct ttm_buffer_object *bo; + struct ttm_buffer_object *tmp; + struct ttm_bo_user_object *user_bo; + uint32_t flags; + int ret = 0; + struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; + struct ttm_placement placement = default_placement; + size_t acc_size = + ttm_pl_size(bdev, (req->size + PAGE_SIZE - 1) >> PAGE_SHIFT); + ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false); + if (unlikely(ret != 0)) + return ret; + + flags = req->placement; + user_bo = kzalloc(sizeof(*user_bo), GFP_KERNEL); + if (unlikely(user_bo == NULL)) { + ttm_mem_global_free(mem_glob, acc_size); + return -ENOMEM; + } + + bo = &user_bo->bo; + ret = ttm_read_lock(lock, true); + if (unlikely(ret != 0)) { + ttm_mem_global_free(mem_glob, acc_size); + kfree(user_bo); + return ret; + } + + placement.num_placement = 1; + placement.placement = &flags; + + if ((flags & TTM_PL_MASK_CACHING) == 0) + flags |= TTM_PL_FLAG_WC | TTM_PL_FLAG_UNCACHED; + + ret = ttm_bo_init(bdev, bo, req->size, + ttm_bo_type_device, &placement, + req->page_alignment, 0, true, + NULL, acc_size, &ttm_bo_user_destroy); + ttm_read_unlock(lock); + + /* + * Note that the ttm_buffer_object_init function + * would've called the destroy function on failure!! + */ + + if (unlikely(ret != 0)) + goto out; + + tmp = ttm_bo_reference(bo); + ret = ttm_base_object_init(tfile, &user_bo->base, + flags & TTM_PL_FLAG_SHARED, + ttm_buffer_type, + &ttm_bo_user_release, + &ttm_bo_user_ref_release); + if (unlikely(ret != 0)) + goto out_err; + + ttm_pl_fill_rep(bo, rep); + ttm_bo_unref(&bo); +out: + return 0; +out_err: + ttm_bo_unref(&tmp); + ttm_bo_unref(&bo); + return ret; +} + +int ttm_pl_ub_create_ioctl(struct ttm_object_file *tfile, + struct ttm_bo_device *bdev, + struct ttm_lock *lock, void *data) +{ + union ttm_pl_create_ub_arg *arg = data; + struct ttm_pl_create_ub_req *req = &arg->req; + struct ttm_pl_rep *rep = &arg->rep; + struct ttm_buffer_object *bo; + struct ttm_buffer_object *tmp; + struct ttm_bo_user_object *user_bo; + uint32_t flags; + int ret = 0; + struct ttm_mem_global *mem_glob = bdev->glob->mem_glob; + struct ttm_placement placement = default_placement; + size_t acc_size = + ttm_pl_size(bdev, (req->size + PAGE_SIZE - 1) >> PAGE_SHIFT); + ret = ttm_mem_global_alloc(mem_glob, acc_size, false, false); + if (unlikely(ret != 0)) + return ret; + + flags = req->placement; + user_bo = kzalloc(sizeof(*user_bo), GFP_KERNEL); + if (unlikely(user_bo == NULL)) { + ttm_mem_global_free(mem_glob, acc_size); + return -ENOMEM; + } + ret = ttm_read_lock(lock, true); + if (unlikely(ret != 0)) { + ttm_mem_global_free(mem_glob, acc_size); + kfree(user_bo); + return ret; + } + bo = &user_bo->bo; + + placement.num_placement = 1; + placement.placement = &flags; + + ret = ttm_bo_init(bdev, + bo, + req->size, + ttm_bo_type_user, + &placement, + req->page_alignment, + req->user_address, + true, + NULL, + acc_size, + &ttm_bo_user_destroy); + + /* + * Note that the ttm_buffer_object_init function + * would've called the destroy function on failure!! + */ + ttm_read_unlock(lock); + if (unlikely(ret != 0)) + goto out; + + tmp = ttm_bo_reference(bo); + ret = ttm_base_object_init(tfile, &user_bo->base, + flags & TTM_PL_FLAG_SHARED, + ttm_buffer_type, + &ttm_bo_user_release, + &ttm_bo_user_ref_release); + if (unlikely(ret != 0)) + goto out_err; + + ttm_pl_fill_rep(bo, rep); + ttm_bo_unref(&bo); +out: + return 0; +out_err: + ttm_bo_unref(&tmp); + ttm_bo_unref(&bo); + return ret; +} + +int ttm_pl_reference_ioctl(struct ttm_object_file *tfile, void *data) +{ + union ttm_pl_reference_arg *arg = data; + struct ttm_pl_rep *rep = &arg->rep; + struct ttm_bo_user_object *user_bo; + struct ttm_buffer_object *bo; + struct ttm_base_object *base; + int ret; + + user_bo = ttm_bo_user_lookup(tfile, arg->req.handle); + if (unlikely(user_bo == NULL)) { + printk(KERN_ERR "Could not reference buffer object.\n"); + return -EINVAL; + } + + bo = &user_bo->bo; + ret = ttm_ref_object_add(tfile, &user_bo->base, TTM_REF_USAGE, NULL); + if (unlikely(ret != 0)) { + printk(KERN_ERR + "Could not add a reference to buffer object.\n"); + goto out; + } + + ttm_pl_fill_rep(bo, rep); + +out: + base = &user_bo->base; + ttm_base_object_unref(&base); + return ret; +} + +int ttm_pl_unref_ioctl(struct ttm_object_file *tfile, void *data) +{ + struct ttm_pl_reference_req *arg = data; + + return ttm_ref_object_base_unref(tfile, arg->handle, TTM_REF_USAGE); +} + +int ttm_pl_synccpu_ioctl(struct ttm_object_file *tfile, void *data) +{ + struct ttm_pl_synccpu_arg *arg = data; + struct ttm_bo_user_object *user_bo; + struct ttm_buffer_object *bo; + struct ttm_base_object *base; + bool existed; + int ret; + + switch (arg->op) { + case TTM_PL_SYNCCPU_OP_GRAB: + user_bo = ttm_bo_user_lookup(tfile, arg->handle); + if (unlikely(user_bo == NULL)) { + printk(KERN_ERR + "Could not find buffer object for synccpu.\n"); + return -EINVAL; + } + bo = &user_bo->bo; + base = &user_bo->base; + ret = ttm_bo_synccpu_write_grab(bo, + arg->access_mode & + TTM_PL_SYNCCPU_MODE_NO_BLOCK); + if (unlikely(ret != 0)) { + ttm_base_object_unref(&base); + goto out; + } + ret = ttm_ref_object_add(tfile, &user_bo->base, + TTM_REF_SYNCCPU_WRITE, &existed); + if (existed || ret != 0) + ttm_bo_synccpu_write_release(bo); + ttm_base_object_unref(&base); + break; + case TTM_PL_SYNCCPU_OP_RELEASE: + ret = ttm_ref_object_base_unref(tfile, arg->handle, + TTM_REF_SYNCCPU_WRITE); + break; + default: + ret = -EINVAL; + break; + } +out: + return ret; +} + +int ttm_pl_setstatus_ioctl(struct ttm_object_file *tfile, + struct ttm_lock *lock, void *data) +{ + union ttm_pl_setstatus_arg *arg = data; + struct ttm_pl_setstatus_req *req = &arg->req; + struct ttm_pl_rep *rep = &arg->rep; + struct ttm_buffer_object *bo; + struct ttm_bo_device *bdev; + struct ttm_placement placement = default_placement; + uint32_t flags[2]; + int ret; + + bo = ttm_buffer_object_lookup(tfile, req->handle); + if (unlikely(bo == NULL)) { + printk(KERN_ERR + "Could not find buffer object for setstatus.\n"); + return -EINVAL; + } + + bdev = bo->bdev; + + ret = ttm_read_lock(lock, true); + if (unlikely(ret != 0)) + goto out_err0; + + ret = ttm_bo_reserve(bo, true, false, false, 0); + if (unlikely(ret != 0)) + goto out_err1; + + ret = ttm_bo_wait_cpu(bo, false); + if (unlikely(ret != 0)) + goto out_err2; + + flags[0] = req->set_placement; + flags[1] = req->clr_placement; + + placement.num_placement = 2; + placement.placement = flags; + + /* Review internal locking ? FIXMEAC */ + ret = psb_ttm_bo_check_placement(bo, &placement); + if (unlikely(ret != 0)) + goto out_err2; + + placement.num_placement = 1; + flags[0] = (req->set_placement | bo->mem.placement) + & ~req->clr_placement; + + ret = ttm_bo_validate(bo, &placement, true, false, false); + if (unlikely(ret != 0)) + goto out_err2; + + ttm_pl_fill_rep(bo, rep); +out_err2: + ttm_bo_unreserve(bo); +out_err1: + ttm_read_unlock(lock); +out_err0: + ttm_bo_unref(&bo); + return ret; +} + +static int psb_ttm_bo_block_reservation(struct ttm_buffer_object *bo, + bool interruptible, bool no_wait) +{ + int ret; + + while (unlikely(atomic_cmpxchg(&bo->reserved, 0, 1) != 0)) { + if (no_wait) + return -EBUSY; + else if (interruptible) { + ret = wait_event_interruptible(bo->event_queue, + atomic_read(&bo->reserved) == 0); + if (unlikely(ret != 0)) + return -ERESTART; + } else { + wait_event(bo->event_queue, + atomic_read(&bo->reserved) == 0); + } + } + return 0; +} + +static void psb_ttm_bo_unblock_reservation(struct ttm_buffer_object *bo) +{ + atomic_set(&bo->reserved, 0); + wake_up_all(&bo->event_queue); +} + +int ttm_pl_waitidle_ioctl(struct ttm_object_file *tfile, void *data) +{ + struct ttm_pl_waitidle_arg *arg = data; + struct ttm_buffer_object *bo; + int ret; + + bo = ttm_buffer_object_lookup(tfile, arg->handle); + if (unlikely(bo == NULL)) { + printk(KERN_ERR "Could not find buffer object for waitidle.\n"); + return -EINVAL; + } + + ret = + psb_ttm_bo_block_reservation(bo, true, + arg->mode & TTM_PL_WAITIDLE_MODE_NO_BLOCK); + if (unlikely(ret != 0)) + goto out; + ret = ttm_bo_wait(bo, + arg->mode & TTM_PL_WAITIDLE_MODE_LAZY, + true, arg->mode & TTM_PL_WAITIDLE_MODE_NO_BLOCK); + psb_ttm_bo_unblock_reservation(bo); +out: + ttm_bo_unref(&bo); + return ret; +} + +int ttm_pl_verify_access(struct ttm_buffer_object *bo, + struct ttm_object_file *tfile) +{ + struct ttm_bo_user_object *ubo; + + /* + * Check bo subclass. + */ + + if (unlikely(bo->destroy != &ttm_bo_user_destroy)) + return -EPERM; + + ubo = container_of(bo, struct ttm_bo_user_object, bo); + if (likely(ubo->base.shareable || ubo->base.tfile == tfile)) + return 0; + + return -EPERM; +} diff --git a/trunk/drivers/staging/gma500/psb_ttm_placement_user.h b/trunk/drivers/staging/gma500/psb_ttm_placement_user.h new file mode 100644 index 000000000000..8b7068b54441 --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_ttm_placement_user.h @@ -0,0 +1,252 @@ +/************************************************************************** + * + * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA + * All Rights Reserved. + * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ +/* + * Authors + * Thomas Hellström + */ + +#ifndef _TTM_PLACEMENT_USER_H_ +#define _TTM_PLACEMENT_USER_H_ + +#if !defined(__KERNEL__) && !defined(_KERNEL) +#include +#else +#include +#endif + +#include "ttm/ttm_placement.h" + +#define TTM_PLACEMENT_MAJOR 0 +#define TTM_PLACEMENT_MINOR 1 +#define TTM_PLACEMENT_PL 0 +#define TTM_PLACEMENT_DATE "080819" + +/** + * struct ttm_pl_create_req + * + * @size: The buffer object size. + * @placement: Flags that indicate initial acceptable + * placement. + * @page_alignment: Required alignment in pages. + * + * Input to the TTM_BO_CREATE ioctl. + */ + +struct ttm_pl_create_req { + uint64_t size; + uint32_t placement; + uint32_t page_alignment; +}; + +/** + * struct ttm_pl_create_ub_req + * + * @size: The buffer object size. + * @user_address: User-space address of the memory area that + * should be used to back the buffer object cast to 64-bit. + * @placement: Flags that indicate initial acceptable + * placement. + * @page_alignment: Required alignment in pages. + * + * Input to the TTM_BO_CREATE_UB ioctl. + */ + +struct ttm_pl_create_ub_req { + uint64_t size; + uint64_t user_address; + uint32_t placement; + uint32_t page_alignment; +}; + +/** + * struct ttm_pl_rep + * + * @gpu_offset: The current offset into the memory region used. + * This can be used directly by the GPU if there are no + * additional GPU mapping procedures used by the driver. + * + * @bo_size: Actual buffer object size. + * + * @map_handle: Offset into the device address space. + * Used for map, seek, read, write. This will never change + * during the lifetime of an object. + * + * @placement: Flag indicating the placement status of + * the buffer object using the TTM_PL flags above. + * + * @sync_object_arg: Used for user-space synchronization and + * depends on the synchronization model used. If fences are + * used, this is the buffer_object::fence_type_mask + * + * Output from the TTM_PL_CREATE and TTM_PL_REFERENCE, and + * TTM_PL_SETSTATUS ioctls. + */ + +struct ttm_pl_rep { + uint64_t gpu_offset; + uint64_t bo_size; + uint64_t map_handle; + uint32_t placement; + uint32_t handle; + uint32_t sync_object_arg; + uint32_t pad64; +}; + +/** + * struct ttm_pl_setstatus_req + * + * @set_placement: Placement flags to set. + * + * @clr_placement: Placement flags to clear. + * + * @handle: The object handle + * + * Input to the TTM_PL_SETSTATUS ioctl. + */ + +struct ttm_pl_setstatus_req { + uint32_t set_placement; + uint32_t clr_placement; + uint32_t handle; + uint32_t pad64; +}; + +/** + * struct ttm_pl_reference_req + * + * @handle: The object to put a reference on. + * + * Input to the TTM_PL_REFERENCE and the TTM_PL_UNREFERENCE ioctls. + */ + +struct ttm_pl_reference_req { + uint32_t handle; + uint32_t pad64; +}; + +/* + * ACCESS mode flags for SYNCCPU. + * + * TTM_SYNCCPU_MODE_READ will guarantee that the GPU is not + * writing to the buffer. + * + * TTM_SYNCCPU_MODE_WRITE will guarantee that the GPU is not + * accessing the buffer. + * + * TTM_SYNCCPU_MODE_NO_BLOCK makes sure the call does not wait + * for GPU accesses to finish but return -EBUSY. + * + * TTM_SYNCCPU_MODE_TRYCACHED Try to place the buffer in cacheable + * memory while synchronized for CPU. + */ + +#define TTM_PL_SYNCCPU_MODE_READ TTM_ACCESS_READ +#define TTM_PL_SYNCCPU_MODE_WRITE TTM_ACCESS_WRITE +#define TTM_PL_SYNCCPU_MODE_NO_BLOCK (1 << 2) +#define TTM_PL_SYNCCPU_MODE_TRYCACHED (1 << 3) + +/** + * struct ttm_pl_synccpu_arg + * + * @handle: The object to synchronize. + * + * @access_mode: access mode indicated by the + * TTM_SYNCCPU_MODE flags. + * + * @op: indicates whether to grab or release the + * buffer for cpu usage. + * + * Input to the TTM_PL_SYNCCPU ioctl. + */ + +struct ttm_pl_synccpu_arg { + uint32_t handle; + uint32_t access_mode; + enum { + TTM_PL_SYNCCPU_OP_GRAB, + TTM_PL_SYNCCPU_OP_RELEASE + } op; + uint32_t pad64; +}; + +/* + * Waiting mode flags for the TTM_BO_WAITIDLE ioctl. + * + * TTM_WAITIDLE_MODE_LAZY: Allow for sleeps during polling + * wait. + * + * TTM_WAITIDLE_MODE_NO_BLOCK: Don't block waiting for GPU, + * but return -EBUSY if the buffer is busy. + */ + +#define TTM_PL_WAITIDLE_MODE_LAZY (1 << 0) +#define TTM_PL_WAITIDLE_MODE_NO_BLOCK (1 << 1) + +/** + * struct ttm_waitidle_arg + * + * @handle: The object to synchronize. + * + * @mode: wait mode indicated by the + * TTM_SYNCCPU_MODE flags. + * + * Argument to the TTM_BO_WAITIDLE ioctl. + */ + +struct ttm_pl_waitidle_arg { + uint32_t handle; + uint32_t mode; +}; + +union ttm_pl_create_arg { + struct ttm_pl_create_req req; + struct ttm_pl_rep rep; +}; + +union ttm_pl_reference_arg { + struct ttm_pl_reference_req req; + struct ttm_pl_rep rep; +}; + +union ttm_pl_setstatus_arg { + struct ttm_pl_setstatus_req req; + struct ttm_pl_rep rep; +}; + +union ttm_pl_create_ub_arg { + struct ttm_pl_create_ub_req req; + struct ttm_pl_rep rep; +}; + +/* + * Ioctl offsets. + */ + +#define TTM_PL_CREATE 0x00 +#define TTM_PL_REFERENCE 0x01 +#define TTM_PL_UNREF 0x02 +#define TTM_PL_SYNCCPU 0x03 +#define TTM_PL_WAITIDLE 0x04 +#define TTM_PL_SETSTATUS 0x05 +#define TTM_PL_CREATE_UB 0x06 + +#endif diff --git a/trunk/drivers/staging/gma500/psb_ttm_userobj_api.h b/trunk/drivers/staging/gma500/psb_ttm_userobj_api.h new file mode 100644 index 000000000000..6a8f7c4ddc78 --- /dev/null +++ b/trunk/drivers/staging/gma500/psb_ttm_userobj_api.h @@ -0,0 +1,85 @@ +/************************************************************************** + * + * Copyright (c) 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA + * All Rights Reserved. + * Copyright (c) 2009 VMware, Inc., Palo Alto, CA., USA + * All Rights Reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + * + **************************************************************************/ +/* + * Authors: Thomas Hellstrom + */ + +#ifndef _TTM_USEROBJ_API_H_ +#define _TTM_USEROBJ_API_H_ + +#include "psb_ttm_placement_user.h" +#include "psb_ttm_fence_user.h" +#include "ttm/ttm_object.h" +#include "psb_ttm_fence_api.h" +#include "ttm/ttm_bo_api.h" + +struct ttm_lock; + +/* + * User ioctls. + */ + +extern int ttm_pl_create_ioctl(struct ttm_object_file *tfile, + struct ttm_bo_device *bdev, + struct ttm_lock *lock, void *data); +extern int ttm_pl_ub_create_ioctl(struct ttm_object_file *tfile, + struct ttm_bo_device *bdev, + struct ttm_lock *lock, void *data); +extern int ttm_pl_reference_ioctl(struct ttm_object_file *tfile, void *data); +extern int ttm_pl_unref_ioctl(struct ttm_object_file *tfile, void *data); +extern int ttm_pl_synccpu_ioctl(struct ttm_object_file *tfile, void *data); +extern int ttm_pl_setstatus_ioctl(struct ttm_object_file *tfile, + struct ttm_lock *lock, void *data); +extern int ttm_pl_waitidle_ioctl(struct ttm_object_file *tfile, void *data); +extern int ttm_fence_signaled_ioctl(struct ttm_object_file *tfile, void *data); +extern int ttm_fence_finish_ioctl(struct ttm_object_file *tfile, void *data); +extern int ttm_fence_unref_ioctl(struct ttm_object_file *tfile, void *data); + +extern int +ttm_fence_user_create(struct ttm_fence_device *fdev, + struct ttm_object_file *tfile, + uint32_t fence_class, + uint32_t fence_types, + uint32_t create_flags, + struct ttm_fence_object **fence, uint32_t * user_handle); + +extern struct ttm_buffer_object *ttm_buffer_object_lookup(struct ttm_object_file + *tfile, + uint32_t handle); + +extern int +ttm_pl_verify_access(struct ttm_buffer_object *bo, + struct ttm_object_file *tfile); + +extern int ttm_buffer_object_create(struct ttm_bo_device *bdev, + unsigned long size, + enum ttm_bo_type type, + uint32_t flags, + uint32_t page_alignment, + unsigned long buffer_start, + bool interruptible, + struct file *persistant_swap_storage, + struct ttm_buffer_object **p_bo); + +extern int psb_ttm_bo_check_placement(struct ttm_buffer_object *bo, + struct ttm_placement *placement); +#endif diff --git a/trunk/drivers/staging/hv/Makefile b/trunk/drivers/staging/hv/Makefile index 30046743a0b4..abeb2f7ef4e2 100644 --- a/trunk/drivers/staging/hv/Makefile +++ b/trunk/drivers/staging/hv/Makefile @@ -9,6 +9,6 @@ hv_vmbus-y := vmbus_drv.o \ hv.o connection.o channel.o \ channel_mgmt.o ring_buffer.o hv_storvsc-y := storvsc_drv.o storvsc.o -hv_blkvsc-y := blkvsc_drv.o storvsc.o +hv_blkvsc-y := blkvsc_drv.o blkvsc.o hv_netvsc-y := netvsc_drv.o netvsc.o rndis_filter.o hv_utils-y := hv_util.o hv_kvp.o diff --git a/trunk/drivers/staging/hv/blkvsc.c b/trunk/drivers/staging/hv/blkvsc.c new file mode 100644 index 000000000000..7c8729bc8329 --- /dev/null +++ b/trunk/drivers/staging/hv/blkvsc.c @@ -0,0 +1,102 @@ +/* + * + * Copyright (c) 2009, Microsoft Corporation. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 59 Temple + * Place - Suite 330, Boston, MA 02111-1307 USA. + * + * Authors: + * Haiyang Zhang + * Hank Janssen + * + */ +#include +#include +#include "hv_api.h" +#include "storvsc.c" + +static const char *g_blk_driver_name = "blkvsc"; + +/* {32412632-86cb-44a2-9b5c-50d1417354f5} */ +static const struct hv_guid g_blk_device_type = { + .data = { + 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, + 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 + } +}; + +static int blk_vsc_on_device_add(struct hv_device *device, void *additional_info) +{ + struct storvsc_device_info *device_info; + int ret = 0; + + device_info = (struct storvsc_device_info *)additional_info; + + ret = stor_vsc_on_device_add(device, additional_info); + if (ret != 0) + return ret; + + /* + * We need to use the device instance guid to set the path and target + * id. For IDE devices, the device instance id is formatted as + * * - - 8899 - 000000000000. + */ + device_info->path_id = device->dev_instance.data[3] << 24 | + device->dev_instance.data[2] << 16 | + device->dev_instance.data[1] << 8 | + device->dev_instance.data[0]; + + device_info->target_id = device->dev_instance.data[5] << 8 | + device->dev_instance.data[4]; + + return ret; +} + +int blk_vsc_initialize(struct hv_driver *driver) +{ + struct storvsc_driver_object *stor_driver; + int ret = 0; + + stor_driver = (struct storvsc_driver_object *)driver; + + /* Make sure we are at least 2 pages since 1 page is used for control */ + /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */ + + driver->name = g_blk_driver_name; + memcpy(&driver->dev_type, &g_blk_device_type, sizeof(struct hv_guid)); + + stor_driver->request_ext_size = sizeof(struct storvsc_request_extension); + + /* + * Divide the ring buffer data size (which is 1 page less than the ring + * buffer size since that page is reserved for the ring buffer indices) + * by the max request size (which is + * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) + */ + stor_driver->max_outstanding_req_per_channel = + ((stor_driver->ring_buffer_size - PAGE_SIZE) / + ALIGN(MAX_MULTIPAGE_BUFFER_PACKET + + sizeof(struct vstor_packet) + sizeof(u64), + sizeof(u64))); + + DPRINT_INFO(BLKVSC, "max io outstd %u", + stor_driver->max_outstanding_req_per_channel); + + /* Setup the dispatch table */ + stor_driver->base.dev_add = blk_vsc_on_device_add; + stor_driver->base.dev_rm = stor_vsc_on_device_remove; + stor_driver->base.cleanup = stor_vsc_on_cleanup; + stor_driver->on_io_request = stor_vsc_on_io_request; + + return ret; +} diff --git a/trunk/drivers/staging/hv/blkvsc_drv.c b/trunk/drivers/staging/hv/blkvsc_drv.c index acc5435e218e..68ad17d67098 100644 --- a/trunk/drivers/staging/hv/blkvsc_drv.c +++ b/trunk/drivers/staging/hv/blkvsc_drv.c @@ -17,8 +17,6 @@ * Authors: * Haiyang Zhang * Hank Janssen - * - * 4/3/2011: K. Y. Srinivasan - Significant restructuring and cleanup. */ #include #include @@ -48,12 +46,6 @@ enum blkvsc_device_type { DVD_TYPE, }; -enum blkvsc_op_type { - DO_INQUIRY, - DO_CAPACITY, - DO_FLUSH, -}; - /* * This request ties the struct request and struct * blkvsc_request/hv_storvsc_request together A struct request may be @@ -80,6 +72,9 @@ struct blkvsc_request { /* The group this request is part of. Maybe null */ struct blkvsc_request_group *group; + wait_queue_head_t wevent; + int cond; + int write; sector_t sector_start; unsigned long sector_count; @@ -89,6 +84,12 @@ struct blkvsc_request { unsigned char cmnd[MAX_COMMAND_SIZE]; struct hv_storvsc_request request; + /* + * !!!DO NOT ADD ANYTHING BELOW HERE!!! Otherwise, memory can overlap, + * because - The extension buffer falls right here and is pointed to by + * request.Extension; + * Which sounds like a horrible idea, who designed this? + */ }; /* Per device structure */ @@ -105,6 +106,7 @@ struct block_device_context { unsigned int device_id_len; int num_outstanding_reqs; int shutting_down; + int media_not_present; unsigned int sector_size; sector_t capacity; unsigned int port; @@ -113,350 +115,515 @@ struct block_device_context { int users; }; -static DEFINE_MUTEX(blkvsc_mutex); - -static const char *g_blk_driver_name = "blkvsc"; -/* {32412632-86cb-44a2-9b5c-50d1417354f5} */ -static const struct hv_guid g_blk_device_type = { - .data = { - 0x32, 0x26, 0x41, 0x32, 0xcb, 0x86, 0xa2, 0x44, - 0x9b, 0x5c, 0x50, 0xd1, 0x41, 0x73, 0x54, 0xf5 - } -}; - -/* - * There is a circular dependency involving blkvsc_request_completion() - * and blkvsc_do_request(). - */ +/* Static decl */ +static DEFINE_MUTEX(blkvsc_mutex); +static int blkvsc_probe(struct device *dev); +static int blkvsc_remove(struct device *device); +static void blkvsc_shutdown(struct device *device); + +static int blkvsc_open(struct block_device *bdev, fmode_t mode); +static int blkvsc_release(struct gendisk *disk, fmode_t mode); +static unsigned int blkvsc_check_events(struct gendisk *gd, + unsigned int clearing); +static int blkvsc_revalidate_disk(struct gendisk *gd); +static int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg); +static int blkvsc_ioctl(struct block_device *bd, fmode_t mode, + unsigned cmd, unsigned long argument); +static void blkvsc_request(struct request_queue *queue); static void blkvsc_request_completion(struct hv_storvsc_request *request); +static int blkvsc_do_request(struct block_device_context *blkdev, + struct request *req); +static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, + void (*request_completion)(struct hv_storvsc_request *)); +static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req); +static void blkvsc_cmd_completion(struct hv_storvsc_request *request); +static int blkvsc_do_inquiry(struct block_device_context *blkdev); +static int blkvsc_do_read_capacity(struct block_device_context *blkdev); +static int blkvsc_do_read_capacity16(struct block_device_context *blkdev); +static int blkvsc_do_flush(struct block_device_context *blkdev); +static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev); +static int blkvsc_do_pending_reqs(struct block_device_context *blkdev); static int blkvsc_ringbuffer_size = BLKVSC_RING_BUFFER_SIZE; - module_param(blkvsc_ringbuffer_size, int, S_IRUGO); MODULE_PARM_DESC(ring_size, "Ring buffer size (in bytes)"); +/* The one and only one */ +static struct storvsc_driver_object g_blkvsc_drv; + +static const struct block_device_operations block_ops = { + .owner = THIS_MODULE, + .open = blkvsc_open, + .release = blkvsc_release, + .check_events = blkvsc_check_events, + .revalidate_disk = blkvsc_revalidate_disk, + .getgeo = blkvsc_getgeo, + .ioctl = blkvsc_ioctl, +}; + /* - * There is a circular dependency involving blkvsc_probe() - * and block_ops. + * blkvsc_drv_init - BlkVsc driver initialization. */ -static int blkvsc_probe(struct device *dev); - -static int blk_vsc_on_device_add(struct hv_device *device, - void *additional_info) +static int blkvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) { - struct storvsc_device_info *device_info; - int ret = 0; + struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv; + struct hv_driver *drv = &g_blkvsc_drv.base; + int ret; - device_info = (struct storvsc_device_info *)additional_info; + storvsc_drv_obj->ring_buffer_size = blkvsc_ringbuffer_size; - ret = stor_vsc_on_device_add(device, additional_info); - if (ret != 0) - return ret; + drv->priv = storvsc_drv_obj; - /* - * We need to use the device instance guid to set the path and target - * id. For IDE devices, the device instance id is formatted as - * * - - 8899 - 000000000000. - */ - device_info->path_id = device->dev_instance.data[3] << 24 | - device->dev_instance.data[2] << 16 | - device->dev_instance.data[1] << 8 | - device->dev_instance.data[0]; + /* Callback to client driver to complete the initialization */ + drv_init(&storvsc_drv_obj->base); + + drv->driver.name = storvsc_drv_obj->base.name; + + drv->driver.probe = blkvsc_probe; + drv->driver.remove = blkvsc_remove; + drv->driver.shutdown = blkvsc_shutdown; - device_info->target_id = device->dev_instance.data[5] << 8 | - device->dev_instance.data[4]; + /* The driver belongs to vmbus */ + ret = vmbus_child_driver_register(&drv->driver); return ret; } +static int blkvsc_drv_exit_cb(struct device *dev, void *data) +{ + struct device **curr = (struct device **)data; + *curr = dev; + return 1; /* stop iterating */ +} -static int blk_vsc_initialize(struct hv_driver *driver) +static void blkvsc_drv_exit(void) { - struct storvsc_driver_object *stor_driver; - int ret = 0; + struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv; + struct hv_driver *drv = &g_blkvsc_drv.base; + struct device *current_dev; + int ret; + + while (1) { + current_dev = NULL; - stor_driver = hvdr_to_stordr(driver); + /* Get the device */ + ret = driver_for_each_device(&drv->driver, NULL, + (void *) ¤t_dev, + blkvsc_drv_exit_cb); - /* Make sure we are at least 2 pages since 1 page is used for control */ + if (ret) + DPRINT_WARN(BLKVSC_DRV, + "driver_for_each_device returned %d", ret); - driver->name = g_blk_driver_name; - memcpy(&driver->dev_type, &g_blk_device_type, sizeof(struct hv_guid)); + if (current_dev == NULL) + break; - /* - * Divide the ring buffer data size (which is 1 page less than the ring - * buffer size since that page is reserved for the ring buffer indices) - * by the max request size (which is - * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) - */ - stor_driver->max_outstanding_req_per_channel = - ((stor_driver->ring_buffer_size - PAGE_SIZE) / - ALIGN(MAX_MULTIPAGE_BUFFER_PACKET + - sizeof(struct vstor_packet) + sizeof(u64), - sizeof(u64))); + /* Initiate removal from the top-down */ + device_unregister(current_dev); + } - DPRINT_INFO(BLKVSC, "max io outstd %u", - stor_driver->max_outstanding_req_per_channel); + if (storvsc_drv_obj->base.cleanup) + storvsc_drv_obj->base.cleanup(&storvsc_drv_obj->base); - /* Setup the dispatch table */ - stor_driver->base.dev_add = blk_vsc_on_device_add; - stor_driver->base.dev_rm = stor_vsc_on_device_remove; - stor_driver->base.cleanup = stor_vsc_on_cleanup; - stor_driver->on_io_request = stor_vsc_on_io_request; + vmbus_child_driver_unregister(&drv->driver); - return ret; + return; } - -static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, - void (*request_completion)(struct hv_storvsc_request *)) +/* + * blkvsc_probe - Add a new device for this driver + */ +static int blkvsc_probe(struct device *device) { - struct block_device_context *blkdev = blkvsc_req->dev; - struct hv_device *device_ctx = blkdev->device_ctx; struct hv_driver *drv = - drv_to_hv_drv(device_ctx->device.driver); + drv_to_hv_drv(device->driver); struct storvsc_driver_object *storvsc_drv_obj = - drv->priv; - struct hv_storvsc_request *storvsc_req; - struct vmscsi_request *vm_srb; - int ret; - - - storvsc_req = &blkvsc_req->request; - vm_srb = &storvsc_req->vstor_packet.vm_srb; - - vm_srb->data_in = blkvsc_req->write ? WRITE_TYPE : READ_TYPE; + drv->priv; + struct hv_device *device_obj = device_to_hv_device(device); - storvsc_req->on_io_completion = request_completion; - storvsc_req->context = blkvsc_req; + struct block_device_context *blkdev = NULL; + struct storvsc_device_info device_info; + int major = 0; + int devnum = 0; + int ret = 0; + static int ide0_registered; + static int ide1_registered; - vm_srb->port_number = blkdev->port; - vm_srb->path_id = blkdev->path; - vm_srb->target_id = blkdev->target; - vm_srb->lun = 0; /* this is not really used at all */ + DPRINT_DBG(BLKVSC_DRV, "blkvsc_probe - enter"); - vm_srb->cdb_length = blkvsc_req->cmd_len; + if (!storvsc_drv_obj->base.dev_add) { + DPRINT_ERR(BLKVSC_DRV, "OnDeviceAdd() not set"); + ret = -1; + goto Cleanup; + } - memcpy(vm_srb->cdb, blkvsc_req->cmnd, vm_srb->cdb_length); + blkdev = kzalloc(sizeof(struct block_device_context), GFP_KERNEL); + if (!blkdev) { + ret = -ENOMEM; + goto Cleanup; + } - storvsc_req->sense_buffer = blkvsc_req->sense_buffer; + INIT_LIST_HEAD(&blkdev->pending_list); - ret = storvsc_drv_obj->on_io_request(blkdev->device_ctx, - &blkvsc_req->request); - if (ret == 0) - blkdev->num_outstanding_reqs++; + /* Initialize what we can here */ + spin_lock_init(&blkdev->lock); - return ret; -} + /* ASSERT(sizeof(struct blkvsc_request_group) <= */ + /* sizeof(struct blkvsc_request)); */ + blkdev->request_pool = kmem_cache_create(dev_name(&device_obj->device), + sizeof(struct blkvsc_request) + + storvsc_drv_obj->request_ext_size, 0, + SLAB_HWCACHE_ALIGN, NULL); + if (!blkdev->request_pool) { + ret = -ENOMEM; + goto Cleanup; + } -static int blkvsc_open(struct block_device *bdev, fmode_t mode) -{ - struct block_device_context *blkdev = bdev->bd_disk->private_data; - spin_lock(&blkdev->lock); + /* Call to the vsc driver to add the device */ + ret = storvsc_drv_obj->base.dev_add(device_obj, &device_info); + if (ret != 0) { + DPRINT_ERR(BLKVSC_DRV, "unable to add blkvsc device"); + goto Cleanup; + } - blkdev->users++; + blkdev->device_ctx = device_obj; + /* this identified the device 0 or 1 */ + blkdev->target = device_info.target_id; + /* this identified the ide ctrl 0 or 1 */ + blkdev->path = device_info.path_id; - spin_unlock(&blkdev->lock); + dev_set_drvdata(device, blkdev); - return 0; -} + /* Calculate the major and device num */ + if (blkdev->path == 0) { + major = IDE0_MAJOR; + devnum = blkdev->path + blkdev->target; /* 0 or 1 */ + + if (!ide0_registered) { + ret = register_blkdev(major, "ide"); + if (ret != 0) { + DPRINT_ERR(BLKVSC_DRV, + "register_blkdev() failed! ret %d", + ret); + goto Remove; + } + ide0_registered = 1; + } + } else if (blkdev->path == 1) { + major = IDE1_MAJOR; + devnum = blkdev->path + blkdev->target + 1; /* 2 or 3 */ + + if (!ide1_registered) { + ret = register_blkdev(major, "ide"); + if (ret != 0) { + DPRINT_ERR(BLKVSC_DRV, + "register_blkdev() failed! ret %d", + ret); + goto Remove; + } -static int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg) -{ - sector_t nsect = get_capacity(bd->bd_disk); - sector_t cylinders = nsect; + ide1_registered = 1; + } + } else { + DPRINT_ERR(BLKVSC_DRV, "invalid pathid"); + ret = -1; + goto Cleanup; + } - /* - * We are making up these values; let us keep it simple. - */ - hg->heads = 0xff; - hg->sectors = 0x3f; - sector_div(cylinders, hg->heads * hg->sectors); - hg->cylinders = cylinders; - if ((sector_t)(hg->cylinders + 1) * hg->heads * hg->sectors < nsect) - hg->cylinders = 0xffff; - return 0; + DPRINT_INFO(BLKVSC_DRV, "blkvsc registered for major %d!!", major); -} + blkdev->gd = alloc_disk(BLKVSC_MINORS); + if (!blkdev->gd) { + DPRINT_ERR(BLKVSC_DRV, "register_blkdev() failed! ret %d", ret); + ret = -1; + goto Cleanup; + } + blkdev->gd->queue = blk_init_queue(blkvsc_request, &blkdev->lock); -static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req) -{ + blk_queue_max_segment_size(blkdev->gd->queue, PAGE_SIZE); + blk_queue_max_segments(blkdev->gd->queue, MAX_MULTIPAGE_BUFFER_COUNT); + blk_queue_segment_boundary(blkdev->gd->queue, PAGE_SIZE-1); + blk_queue_bounce_limit(blkdev->gd->queue, BLK_BOUNCE_ANY); + blk_queue_dma_alignment(blkdev->gd->queue, 511); - blkvsc_req->cmd_len = 16; + blkdev->gd->major = major; + if (devnum == 1 || devnum == 3) + blkdev->gd->first_minor = BLKVSC_MINORS; + else + blkdev->gd->first_minor = 0; + blkdev->gd->fops = &block_ops; + blkdev->gd->events = DISK_EVENT_MEDIA_CHANGE; + blkdev->gd->private_data = blkdev; + blkdev->gd->driverfs_dev = &(blkdev->device_ctx->device); + sprintf(blkdev->gd->disk_name, "hd%c", 'a' + devnum); - if (rq_data_dir(blkvsc_req->req)) { - blkvsc_req->write = 1; - blkvsc_req->cmnd[0] = WRITE_16; + blkvsc_do_inquiry(blkdev); + if (blkdev->device_type == DVD_TYPE) { + set_disk_ro(blkdev->gd, 1); + blkdev->gd->flags |= GENHD_FL_REMOVABLE; + blkvsc_do_read_capacity(blkdev); } else { - blkvsc_req->write = 0; - blkvsc_req->cmnd[0] = READ_16; + blkvsc_do_read_capacity16(blkdev); } - blkvsc_req->cmnd[1] |= - (blkvsc_req->req->cmd_flags & REQ_FUA) ? 0x8 : 0; + set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512)); + blk_queue_logical_block_size(blkdev->gd->queue, blkdev->sector_size); + /* go! */ + add_disk(blkdev->gd); - *(unsigned long long *)&blkvsc_req->cmnd[2] = - cpu_to_be64(blkvsc_req->sector_start); - *(unsigned int *)&blkvsc_req->cmnd[10] = - cpu_to_be32(blkvsc_req->sector_count); -} + DPRINT_INFO(BLKVSC_DRV, "%s added!! capacity %lu sector_size %d", + blkdev->gd->disk_name, (unsigned long)blkdev->capacity, + blkdev->sector_size); + return ret; -static int blkvsc_ioctl(struct block_device *bd, fmode_t mode, - unsigned cmd, unsigned long arg) -{ - struct block_device_context *blkdev = bd->bd_disk->private_data; - int ret = 0; +Remove: + storvsc_drv_obj->base.dev_rm(device_obj); - switch (cmd) { - case HDIO_GET_IDENTITY: - if (copy_to_user((void __user *)arg, blkdev->device_id, - blkdev->device_id_len)) - ret = -EFAULT; - break; - default: - ret = -EINVAL; - break; +Cleanup: + if (blkdev) { + if (blkdev->request_pool) { + kmem_cache_destroy(blkdev->request_pool); + blkdev->request_pool = NULL; + } + kfree(blkdev); + blkdev = NULL; } return ret; } -static void blkvsc_cmd_completion(struct hv_storvsc_request *request) +static void blkvsc_shutdown(struct device *device) { - struct blkvsc_request *blkvsc_req = - (struct blkvsc_request *)request->context; - struct block_device_context *blkdev = - (struct block_device_context *)blkvsc_req->dev; - struct scsi_sense_hdr sense_hdr; - struct vmscsi_request *vm_srb; + struct block_device_context *blkdev = dev_get_drvdata(device); + unsigned long flags; + if (!blkdev) + return; - vm_srb = &blkvsc_req->request.vstor_packet.vm_srb; - blkdev->num_outstanding_reqs--; + DPRINT_DBG(BLKVSC_DRV, "blkvsc_shutdown - users %d disk %s\n", + blkdev->users, blkdev->gd->disk_name); - if (vm_srb->scsi_status) - if (scsi_normalize_sense(blkvsc_req->sense_buffer, - SCSI_SENSE_BUFFERSIZE, &sense_hdr)) - scsi_print_sense_hdr("blkvsc", &sense_hdr); + spin_lock_irqsave(&blkdev->lock, flags); - complete(&blkvsc_req->request.wait_event); -} + blkdev->shutting_down = 1; + + blk_stop_queue(blkdev->gd->queue); + + spin_unlock_irqrestore(&blkdev->lock, flags); + + while (blkdev->num_outstanding_reqs) { + DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", + blkdev->num_outstanding_reqs); + udelay(100); + } + + blkvsc_do_flush(blkdev); + + spin_lock_irqsave(&blkdev->lock, flags); + + blkvsc_cancel_pending_reqs(blkdev); + spin_unlock_irqrestore(&blkdev->lock, flags); +} -static int blkvsc_do_operation(struct block_device_context *blkdev, - enum blkvsc_op_type op) +static int blkvsc_do_flush(struct block_device_context *blkdev) { struct blkvsc_request *blkvsc_req; - struct page *page_buf; - unsigned char *buf; - unsigned char device_type; - struct scsi_sense_hdr sense_hdr; - struct vmscsi_request *vm_srb; - int ret = 0; + DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_flush()\n"); + + if (blkdev->device_type != HARDDISK_TYPE) + return 0; - blkvsc_req = kmem_cache_zalloc(blkdev->request_pool, GFP_KERNEL); + blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL); if (!blkvsc_req) return -ENOMEM; - page_buf = alloc_page(GFP_KERNEL); - if (!page_buf) { - kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); - return -ENOMEM; + memset(blkvsc_req, 0, sizeof(struct blkvsc_request)); + init_waitqueue_head(&blkvsc_req->wevent); + blkvsc_req->dev = blkdev; + blkvsc_req->req = NULL; + blkvsc_req->write = 0; + + blkvsc_req->request.data_buffer.pfn_array[0] = 0; + blkvsc_req->request.data_buffer.offset = 0; + blkvsc_req->request.data_buffer.len = 0; + + blkvsc_req->cmnd[0] = SYNCHRONIZE_CACHE; + blkvsc_req->cmd_len = 10; + + /* + * Set this here since the completion routine may be invoked and + * completed before we return + */ + blkvsc_req->cond = 0; + blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion); + + wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); + + kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); + + return 0; +} + +/* Do a scsi INQUIRY cmd here to get the device type (ie disk or dvd) */ +static int blkvsc_do_inquiry(struct block_device_context *blkdev) +{ + struct blkvsc_request *blkvsc_req; + struct page *page_buf; + unsigned char *buf; + unsigned char device_type; + + DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_inquiry()\n"); + + blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL); + if (!blkvsc_req) + return -ENOMEM; + + memset(blkvsc_req, 0, sizeof(struct blkvsc_request)); + page_buf = alloc_page(GFP_KERNEL); + if (!page_buf) { + kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); + return -ENOMEM; } - vm_srb = &blkvsc_req->request.vstor_packet.vm_srb; - init_completion(&blkvsc_req->request.wait_event); + init_waitqueue_head(&blkvsc_req->wevent); blkvsc_req->dev = blkdev; blkvsc_req->req = NULL; blkvsc_req->write = 0; - blkvsc_req->request.data_buffer.pfn_array[0] = - page_to_pfn(page_buf); + blkvsc_req->request.data_buffer.pfn_array[0] = page_to_pfn(page_buf); blkvsc_req->request.data_buffer.offset = 0; + blkvsc_req->request.data_buffer.len = 64; - switch (op) { - case DO_INQUIRY: - blkvsc_req->cmnd[0] = INQUIRY; - blkvsc_req->cmnd[1] = 0x1; /* Get product data */ - blkvsc_req->cmnd[2] = 0x83; /* mode page 83 */ - blkvsc_req->cmnd[4] = 64; - blkvsc_req->cmd_len = 6; - blkvsc_req->request.data_buffer.len = 64; - break; + blkvsc_req->cmnd[0] = INQUIRY; + blkvsc_req->cmnd[1] = 0x1; /* Get product data */ + blkvsc_req->cmnd[2] = 0x83; /* mode page 83 */ + blkvsc_req->cmnd[4] = 64; + blkvsc_req->cmd_len = 6; - case DO_CAPACITY: - blkdev->sector_size = 0; - blkdev->capacity = 0; + /* + * Set this here since the completion routine may be invoked and + * completed before we return + */ + blkvsc_req->cond = 0; - blkvsc_req->cmnd[0] = READ_CAPACITY; - blkvsc_req->cmd_len = 16; - blkvsc_req->request.data_buffer.len = 8; - break; + blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion); - case DO_FLUSH: - blkvsc_req->cmnd[0] = SYNCHRONIZE_CACHE; - blkvsc_req->cmd_len = 10; - blkvsc_req->request.data_buffer.pfn_array[0] = 0; - blkvsc_req->request.data_buffer.len = 0; - break; - default: - ret = -EINVAL; - goto cleanup; + DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", + blkvsc_req, blkvsc_req->cond); + + wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); + + buf = kmap(page_buf); + + /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, buf, 64); */ + /* be to le */ + device_type = buf[0] & 0x1F; + + if (device_type == 0x0) { + blkdev->device_type = HARDDISK_TYPE; + } else if (device_type == 0x5) { + blkdev->device_type = DVD_TYPE; + } else { + /* TODO: this is currently unsupported device type */ + blkdev->device_type = UNKNOWN_DEV_TYPE; } - blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion); + DPRINT_DBG(BLKVSC_DRV, "device type %d\n", device_type); - wait_for_completion_interruptible(&blkvsc_req->request.wait_event); + blkdev->device_id_len = buf[7]; + if (blkdev->device_id_len > 64) + blkdev->device_id_len = 64; - /* check error */ - if (vm_srb->scsi_status) { - scsi_normalize_sense(blkvsc_req->sense_buffer, - SCSI_SENSE_BUFFERSIZE, &sense_hdr); + memcpy(blkdev->device_id, &buf[8], blkdev->device_id_len); + /* printk_hex_dump_bytes("", DUMP_PREFIX_NONE, blkdev->device_id, + * blkdev->device_id_len); */ - return 0; + kunmap(page_buf); + + __free_page(page_buf); + + kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); + + return 0; +} + +/* Do a scsi READ_CAPACITY cmd here to get the size of the disk */ +static int blkvsc_do_read_capacity(struct block_device_context *blkdev) +{ + struct blkvsc_request *blkvsc_req; + struct page *page_buf; + unsigned char *buf; + struct scsi_sense_hdr sense_hdr; + + DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_read_capacity()\n"); + + blkdev->sector_size = 0; + blkdev->capacity = 0; + blkdev->media_not_present = 0; /* assume a disk is present */ + + blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL); + if (!blkvsc_req) + return -ENOMEM; + + memset(blkvsc_req, 0, sizeof(struct blkvsc_request)); + page_buf = alloc_page(GFP_KERNEL); + if (!page_buf) { + kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); + return -ENOMEM; } - buf = kmap(page_buf); + init_waitqueue_head(&blkvsc_req->wevent); + blkvsc_req->dev = blkdev; + blkvsc_req->req = NULL; + blkvsc_req->write = 0; + + blkvsc_req->request.data_buffer.pfn_array[0] = page_to_pfn(page_buf); + blkvsc_req->request.data_buffer.offset = 0; + blkvsc_req->request.data_buffer.len = 8; - switch (op) { - case DO_INQUIRY: - device_type = buf[0] & 0x1F; + blkvsc_req->cmnd[0] = READ_CAPACITY; + blkvsc_req->cmd_len = 16; - if (device_type == 0x0) - blkdev->device_type = HARDDISK_TYPE; - else - blkdev->device_type = UNKNOWN_DEV_TYPE; + /* + * Set this here since the completion routine may be invoked + * and completed before we return + */ + blkvsc_req->cond = 0; - blkdev->device_id_len = buf[7]; - if (blkdev->device_id_len > 64) - blkdev->device_id_len = 64; + blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion); - memcpy(blkdev->device_id, &buf[8], blkdev->device_id_len); - break; + DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", + blkvsc_req, blkvsc_req->cond); - case DO_CAPACITY: - /* be to le */ - blkdev->capacity = - ((buf[0] << 24) | (buf[1] << 16) | - (buf[2] << 8) | buf[3]) + 1; + wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); - blkdev->sector_size = - (buf[4] << 24) | (buf[5] << 16) | - (buf[6] << 8) | buf[7]; - break; - default: - break; + /* check error */ + if (blkvsc_req->request.status) { + scsi_normalize_sense(blkvsc_req->sense_buffer, + SCSI_SENSE_BUFFERSIZE, &sense_hdr); + if (sense_hdr.asc == 0x3A) { + /* Medium not present */ + blkdev->media_not_present = 1; + } + return 0; } + buf = kmap(page_buf); -cleanup: + /* be to le */ + blkdev->capacity = ((buf[0] << 24) | (buf[1] << 16) | + (buf[2] << 8) | buf[3]) + 1; + blkdev->sector_size = (buf[4] << 24) | (buf[5] << 16) | + (buf[6] << 8) | buf[7]; kunmap(page_buf); @@ -464,77 +631,89 @@ static int blkvsc_do_operation(struct block_device_context *blkdev, kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); - return ret; + return 0; } - -static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev) +static int blkvsc_do_read_capacity16(struct block_device_context *blkdev) { - struct blkvsc_request *pend_req, *tmp; - struct blkvsc_request *comp_req, *tmp2; - struct vmscsi_request *vm_srb; + struct blkvsc_request *blkvsc_req; + struct page *page_buf; + unsigned char *buf; + struct scsi_sense_hdr sense_hdr; - int ret = 0; + DPRINT_DBG(BLKVSC_DRV, "blkvsc_do_read_capacity16()\n"); + blkdev->sector_size = 0; + blkdev->capacity = 0; + blkdev->media_not_present = 0; /* assume a disk is present */ - /* Flush the pending list first */ - list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, - pend_entry) { - /* - * The pend_req could be part of a partially completed - * request. If so, complete those req first until we - * hit the pend_req - */ - list_for_each_entry_safe(comp_req, tmp2, - &pend_req->group->blkvsc_req_list, - req_entry) { + blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_KERNEL); + if (!blkvsc_req) + return -ENOMEM; - if (comp_req == pend_req) - break; + memset(blkvsc_req, 0, sizeof(struct blkvsc_request)); + page_buf = alloc_page(GFP_KERNEL); + if (!page_buf) { + kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); + return -ENOMEM; + } - list_del(&comp_req->req_entry); + init_waitqueue_head(&blkvsc_req->wevent); + blkvsc_req->dev = blkdev; + blkvsc_req->req = NULL; + blkvsc_req->write = 0; - if (comp_req->req) { - vm_srb = - &comp_req->request.vstor_packet. - vm_srb; - ret = __blk_end_request(comp_req->req, - (!vm_srb->scsi_status ? 0 : -EIO), - comp_req->sector_count * - blkdev->sector_size); + blkvsc_req->request.data_buffer.pfn_array[0] = page_to_pfn(page_buf); + blkvsc_req->request.data_buffer.offset = 0; + blkvsc_req->request.data_buffer.len = 12; - /* FIXME: shouldn't this do more than return? */ - if (ret) - goto out; - } + blkvsc_req->cmnd[0] = 0x9E; /* READ_CAPACITY16; */ + blkvsc_req->cmd_len = 16; - kmem_cache_free(blkdev->request_pool, comp_req); - } + /* + * Set this here since the completion routine may be invoked + * and completed before we return + */ + blkvsc_req->cond = 0; - list_del(&pend_req->pend_entry); + blkvsc_submit_request(blkvsc_req, blkvsc_cmd_completion); - list_del(&pend_req->req_entry); + DPRINT_DBG(BLKVSC_DRV, "waiting %p to complete - cond %d\n", + blkvsc_req, blkvsc_req->cond); - if (comp_req->req) { - if (!__blk_end_request(pend_req->req, -EIO, - pend_req->sector_count * - blkdev->sector_size)) { - /* - * All the sectors have been xferred ie the - * request is done - */ - kmem_cache_free(blkdev->request_pool, - pend_req->group); - } - } + wait_event_interruptible(blkvsc_req->wevent, blkvsc_req->cond); - kmem_cache_free(blkdev->request_pool, pend_req); + /* check error */ + if (blkvsc_req->request.status) { + scsi_normalize_sense(blkvsc_req->sense_buffer, + SCSI_SENSE_BUFFERSIZE, &sense_hdr); + if (sense_hdr.asc == 0x3A) { + /* Medium not present */ + blkdev->media_not_present = 1; + } + return 0; } + buf = kmap(page_buf); -out: - return ret; -} + /* be to le */ + blkdev->capacity = be64_to_cpu(*(unsigned long long *) &buf[0]) + 1; + blkdev->sector_size = be32_to_cpu(*(unsigned int *)&buf[8]); +#if 0 + blkdev->capacity = ((buf[0] << 24) | (buf[1] << 16) | + (buf[2] << 8) | buf[3]) + 1; + blkdev->sector_size = (buf[4] << 24) | (buf[5] << 16) | + (buf[6] << 8) | buf[7]; +#endif + + kunmap(page_buf); + + __free_page(page_buf); + + kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req); + + return 0; +} /* * blkvsc_remove() - Callback when our device is removed @@ -548,12 +727,23 @@ static int blkvsc_remove(struct device *device) struct hv_device *device_obj = device_to_hv_device(device); struct block_device_context *blkdev = dev_get_drvdata(device); unsigned long flags; + int ret; + + DPRINT_DBG(BLKVSC_DRV, "blkvsc_remove()\n"); + + if (!storvsc_drv_obj->base.dev_rm) + return -1; /* * Call to the vsc driver to let it know that the device is being * removed */ - storvsc_drv_obj->base.dev_rm(device_obj); + ret = storvsc_drv_obj->base.dev_rm(device_obj); + if (ret != 0) { + /* TODO: */ + DPRINT_ERR(BLKVSC_DRV, + "unable to remove blkvsc device (ret %d)", ret); + } /* Get to a known state */ spin_lock_irqsave(&blkdev->lock, flags); @@ -570,7 +760,7 @@ static int blkvsc_remove(struct device *device) udelay(100); } - blkvsc_do_operation(blkdev, DO_FLUSH); + blkvsc_do_flush(blkdev); spin_lock_irqsave(&blkdev->lock, flags); @@ -586,64 +776,125 @@ static int blkvsc_remove(struct device *device) kfree(blkdev); - return 0; - + return ret; } -static void blkvsc_shutdown(struct device *device) +static void blkvsc_init_rw(struct blkvsc_request *blkvsc_req) { - struct block_device_context *blkdev = dev_get_drvdata(device); - unsigned long flags; + /* ASSERT(blkvsc_req->req); */ + /* ASSERT(blkvsc_req->sector_count <= (MAX_MULTIPAGE_BUFFER_COUNT*8)); */ - if (!blkdev) - return; + blkvsc_req->cmd_len = 16; - spin_lock_irqsave(&blkdev->lock, flags); + if (blkvsc_req->sector_start > 0xffffffff) { + if (rq_data_dir(blkvsc_req->req)) { + blkvsc_req->write = 1; + blkvsc_req->cmnd[0] = WRITE_16; + } else { + blkvsc_req->write = 0; + blkvsc_req->cmnd[0] = READ_16; + } - blkdev->shutting_down = 1; + blkvsc_req->cmnd[1] |= + (blkvsc_req->req->cmd_flags & REQ_FUA) ? 0x8 : 0; + + *(unsigned long long *)&blkvsc_req->cmnd[2] = + cpu_to_be64(blkvsc_req->sector_start); + *(unsigned int *)&blkvsc_req->cmnd[10] = + cpu_to_be32(blkvsc_req->sector_count); + } else if ((blkvsc_req->sector_count > 0xff) || + (blkvsc_req->sector_start > 0x1fffff)) { + if (rq_data_dir(blkvsc_req->req)) { + blkvsc_req->write = 1; + blkvsc_req->cmnd[0] = WRITE_10; + } else { + blkvsc_req->write = 0; + blkvsc_req->cmnd[0] = READ_10; + } - blk_stop_queue(blkdev->gd->queue); + blkvsc_req->cmnd[1] |= + (blkvsc_req->req->cmd_flags & REQ_FUA) ? 0x8 : 0; - spin_unlock_irqrestore(&blkdev->lock, flags); + *(unsigned int *)&blkvsc_req->cmnd[2] = + cpu_to_be32(blkvsc_req->sector_start); + *(unsigned short *)&blkvsc_req->cmnd[7] = + cpu_to_be16(blkvsc_req->sector_count); + } else { + if (rq_data_dir(blkvsc_req->req)) { + blkvsc_req->write = 1; + blkvsc_req->cmnd[0] = WRITE_6; + } else { + blkvsc_req->write = 0; + blkvsc_req->cmnd[0] = READ_6; + } - while (blkdev->num_outstanding_reqs) { - DPRINT_INFO(STORVSC, "waiting for %d requests to complete...", - blkdev->num_outstanding_reqs); - udelay(100); + *(unsigned int *)&blkvsc_req->cmnd[1] = + cpu_to_be32(blkvsc_req->sector_start) >> 8; + blkvsc_req->cmnd[1] &= 0x1f; + blkvsc_req->cmnd[4] = (unsigned char)blkvsc_req->sector_count; } +} - blkvsc_do_operation(blkdev, DO_FLUSH); +static int blkvsc_submit_request(struct blkvsc_request *blkvsc_req, + void (*request_completion)(struct hv_storvsc_request *)) +{ + struct block_device_context *blkdev = blkvsc_req->dev; + struct hv_device *device_ctx = blkdev->device_ctx; + struct hv_driver *drv = + drv_to_hv_drv(device_ctx->device.driver); + struct storvsc_driver_object *storvsc_drv_obj = + drv->priv; + struct hv_storvsc_request *storvsc_req; + int ret; - spin_lock_irqsave(&blkdev->lock, flags); + DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - " + "req %p type %s start_sector %lu count %ld offset %d " + "len %d\n", blkvsc_req, + (blkvsc_req->write) ? "WRITE" : "READ", + (unsigned long) blkvsc_req->sector_start, + blkvsc_req->sector_count, + blkvsc_req->request.data_buffer.offset, + blkvsc_req->request.data_buffer.len); +#if 0 + for (i = 0; i < (blkvsc_req->request.data_buffer.len >> 12); i++) { + DPRINT_DBG(BLKVSC_DRV, "blkvsc_submit_request() - " + "req %p pfn[%d] %llx\n", + blkvsc_req, i, + blkvsc_req->request.data_buffer.pfn_array[i]); + } +#endif - blkvsc_cancel_pending_reqs(blkdev); + storvsc_req = &blkvsc_req->request; + storvsc_req->extension = (void *)((unsigned long)blkvsc_req + + sizeof(struct blkvsc_request)); - spin_unlock_irqrestore(&blkdev->lock, flags); -} + storvsc_req->type = blkvsc_req->write ? WRITE_TYPE : READ_TYPE; -static int blkvsc_release(struct gendisk *disk, fmode_t mode) -{ - struct block_device_context *blkdev = disk->private_data; + storvsc_req->on_io_completion = request_completion; + storvsc_req->context = blkvsc_req; - mutex_lock(&blkvsc_mutex); - spin_lock(&blkdev->lock); - if (blkdev->users == 1) { - spin_unlock(&blkdev->lock); - blkvsc_do_operation(blkdev, DO_FLUSH); - spin_lock(&blkdev->lock); - } + storvsc_req->host = blkdev->port; + storvsc_req->bus = blkdev->path; + storvsc_req->target_id = blkdev->target; + storvsc_req->lun_id = 0; /* this is not really used at all */ - blkdev->users--; + storvsc_req->cdb_len = blkvsc_req->cmd_len; + storvsc_req->cdb = blkvsc_req->cmnd; - spin_unlock(&blkdev->lock); - mutex_unlock(&blkvsc_mutex); - return 0; -} + storvsc_req->sense_buffer = blkvsc_req->sense_buffer; + storvsc_req->sense_buffer_size = SCSI_SENSE_BUFFERSIZE; + + ret = storvsc_drv_obj->on_io_request(blkdev->device_ctx, + &blkvsc_req->request); + if (ret == 0) + blkdev->num_outstanding_reqs++; + return ret; +} /* * We break the request into 1 or more blkvsc_requests and submit - * them. If we cant submit them all, we put them on the + * them. If we can't submit them all, we put them on the * pending_list. The blkvsc_request() will work on the pending_list. */ static int blkvsc_do_request(struct block_device_context *blkdev, @@ -662,8 +913,11 @@ static int blkvsc_do_request(struct block_device_context *blkdev, int pending = 0; struct blkvsc_request_group *group = NULL; + DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p sect %lu\n", blkdev, req, + (unsigned long)blk_rq_pos(req)); + /* Create a group to tie req to list of blkvsc_reqs */ - group = kmem_cache_zalloc(blkdev->request_pool, GFP_ATOMIC); + group = kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC); if (!group) return -ENOMEM; @@ -679,6 +933,11 @@ static int blkvsc_do_request(struct block_device_context *blkdev, * Map this bio into an existing or new storvsc request */ bio_for_each_segment(bvec, bio, seg_idx) { + DPRINT_DBG(BLKVSC_DRV, "bio_for_each_segment() " + "- req %p bio %p bvec %p seg_idx %d " + "databuf_idx %d\n", req, bio, bvec, + seg_idx, databuf_idx); + /* Get a new storvsc request */ /* 1st-time */ if ((!blkvsc_req) || @@ -690,15 +949,10 @@ static int blkvsc_do_request(struct block_device_context *blkdev, (prev_bvec->bv_len != PAGE_SIZE))) { /* submit the prev one */ if (blkvsc_req) { - blkvsc_req->sector_start = - start_sector; - sector_div( - blkvsc_req->sector_start, - (blkdev->sector_size >> 9)); - - blkvsc_req->sector_count = - num_sectors / - (blkdev->sector_size >> 9); + blkvsc_req->sector_start = start_sector; + sector_div(blkvsc_req->sector_start, (blkdev->sector_size >> 9)); + + blkvsc_req->sector_count = num_sectors / (blkdev->sector_size >> 9); blkvsc_init_rw(blkvsc_req); } @@ -706,24 +960,18 @@ static int blkvsc_do_request(struct block_device_context *blkdev, * Create new blkvsc_req to represent * the current bvec */ - blkvsc_req = - kmem_cache_zalloc( - blkdev->request_pool, GFP_ATOMIC); + blkvsc_req = kmem_cache_alloc(blkdev->request_pool, GFP_ATOMIC); if (!blkvsc_req) { /* free up everything */ list_for_each_entry_safe( blkvsc_req, tmp, &group->blkvsc_req_list, req_entry) { - list_del( - &blkvsc_req->req_entry); - kmem_cache_free( - blkdev->request_pool, - blkvsc_req); + list_del(&blkvsc_req->req_entry); + kmem_cache_free(blkdev->request_pool, blkvsc_req); } - kmem_cache_free( - blkdev->request_pool, group); + kmem_cache_free(blkdev->request_pool, group); return -ENOMEM; } @@ -732,27 +980,23 @@ static int blkvsc_do_request(struct block_device_context *blkdev, blkvsc_req->dev = blkdev; blkvsc_req->req = req; - blkvsc_req->request. - data_buffer.offset - = bvec->bv_offset; - blkvsc_req->request. - data_buffer.len = 0; + blkvsc_req->request.data_buffer.offset + = bvec->bv_offset; + blkvsc_req->request.data_buffer.len + = 0; /* Add to the group */ blkvsc_req->group = group; blkvsc_req->group->outstanding++; list_add_tail(&blkvsc_req->req_entry, - &blkvsc_req->group->blkvsc_req_list); + &blkvsc_req->group->blkvsc_req_list); start_sector += num_sectors; num_sectors = 0; databuf_idx = 0; } - /* - * Add the curr bvec/segment to the curr - * blkvsc_req - */ + /* Add the curr bvec/segment to the curr blkvsc_req */ blkvsc_req->request.data_buffer. pfn_array[databuf_idx] = page_to_pfn(bvec->bv_page); @@ -771,6 +1015,10 @@ static int blkvsc_do_request(struct block_device_context *blkdev, /* Handle the last one */ if (blkvsc_req) { + DPRINT_DBG(BLKVSC_DRV, "blkdev %p req %p group %p count %d\n", + blkdev, req, blkvsc_req->group, + blkvsc_req->group->outstanding); + blkvsc_req->sector_start = start_sector; sector_div(blkvsc_req->sector_start, (blkdev->sector_size >> 9)); @@ -783,6 +1031,13 @@ static int blkvsc_do_request(struct block_device_context *blkdev, list_for_each_entry(blkvsc_req, &group->blkvsc_req_list, req_entry) { if (pending) { + DPRINT_DBG(BLKVSC_DRV, "adding blkvsc_req to " + "pending_list - blkvsc_req %p start_sect %lu" + " sect_count %ld (%lu %ld)\n", blkvsc_req, + (unsigned long)blkvsc_req->sector_start, + blkvsc_req->sector_count, + (unsigned long)start_sector, + (unsigned long)num_sectors); list_add_tail(&blkvsc_req->pend_entry, &blkdev->pending_list); @@ -795,20 +1050,196 @@ static int blkvsc_do_request(struct block_device_context *blkdev, &blkdev->pending_list); } + DPRINT_DBG(BLKVSC_DRV, "submitted blkvsc_req %p " + "start_sect %lu sect_count %ld (%lu %ld) " + "ret %d\n", blkvsc_req, + (unsigned long)blkvsc_req->sector_start, + blkvsc_req->sector_count, + (unsigned long)start_sector, + num_sectors, ret); } } return pending; } -static int blkvsc_do_pending_reqs(struct block_device_context *blkdev) +static void blkvsc_cmd_completion(struct hv_storvsc_request *request) +{ + struct blkvsc_request *blkvsc_req = + (struct blkvsc_request *)request->context; + struct block_device_context *blkdev = + (struct block_device_context *)blkvsc_req->dev; + struct scsi_sense_hdr sense_hdr; + + DPRINT_DBG(BLKVSC_DRV, "blkvsc_cmd_completion() - req %p\n", + blkvsc_req); + + blkdev->num_outstanding_reqs--; + + if (blkvsc_req->request.status) + if (scsi_normalize_sense(blkvsc_req->sense_buffer, + SCSI_SENSE_BUFFERSIZE, &sense_hdr)) + scsi_print_sense_hdr("blkvsc", &sense_hdr); + + blkvsc_req->cond = 1; + wake_up_interruptible(&blkvsc_req->wevent); +} + +static void blkvsc_request_completion(struct hv_storvsc_request *request) +{ + struct blkvsc_request *blkvsc_req = + (struct blkvsc_request *)request->context; + struct block_device_context *blkdev = + (struct block_device_context *)blkvsc_req->dev; + unsigned long flags; + struct blkvsc_request *comp_req, *tmp; + + /* ASSERT(blkvsc_req->group); */ + + DPRINT_DBG(BLKVSC_DRV, "blkdev %p blkvsc_req %p group %p type %s " + "sect_start %lu sect_count %ld len %d group outstd %d " + "total outstd %d\n", + blkdev, blkvsc_req, blkvsc_req->group, + (blkvsc_req->write) ? "WRITE" : "READ", + (unsigned long)blkvsc_req->sector_start, + blkvsc_req->sector_count, + blkvsc_req->request.data_buffer.len, + blkvsc_req->group->outstanding, + blkdev->num_outstanding_reqs); + + spin_lock_irqsave(&blkdev->lock, flags); + + blkdev->num_outstanding_reqs--; + blkvsc_req->group->outstanding--; + + /* + * Only start processing when all the blkvsc_reqs are + * completed. This guarantees no out-of-order blkvsc_req + * completion when calling end_that_request_first() + */ + if (blkvsc_req->group->outstanding == 0) { + list_for_each_entry_safe(comp_req, tmp, + &blkvsc_req->group->blkvsc_req_list, + req_entry) { + DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p " + "sect_start %lu sect_count %ld\n", + comp_req, + (unsigned long)comp_req->sector_start, + comp_req->sector_count); + + list_del(&comp_req->req_entry); + + if (!__blk_end_request(comp_req->req, + (!comp_req->request.status ? 0 : -EIO), + comp_req->sector_count * blkdev->sector_size)) { + /* + * All the sectors have been xferred ie the + * request is done + */ + DPRINT_DBG(BLKVSC_DRV, "req %p COMPLETED\n", + comp_req->req); + kmem_cache_free(blkdev->request_pool, + comp_req->group); + } + + kmem_cache_free(blkdev->request_pool, comp_req); + } + + if (!blkdev->shutting_down) { + blkvsc_do_pending_reqs(blkdev); + blk_start_queue(blkdev->gd->queue); + blkvsc_request(blkdev->gd->queue); + } + } + + spin_unlock_irqrestore(&blkdev->lock, flags); +} + +static int blkvsc_cancel_pending_reqs(struct block_device_context *blkdev) { struct blkvsc_request *pend_req, *tmp; + struct blkvsc_request *comp_req, *tmp2; + int ret = 0; + DPRINT_DBG(BLKVSC_DRV, "blkvsc_cancel_pending_reqs()"); + /* Flush the pending list first */ list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, pend_entry) { + /* + * The pend_req could be part of a partially completed + * request. If so, complete those req first until we + * hit the pend_req + */ + list_for_each_entry_safe(comp_req, tmp2, + &pend_req->group->blkvsc_req_list, + req_entry) { + DPRINT_DBG(BLKVSC_DRV, "completing blkvsc_req %p " + "sect_start %lu sect_count %ld\n", + comp_req, + (unsigned long) comp_req->sector_start, + comp_req->sector_count); + + if (comp_req == pend_req) + break; + + list_del(&comp_req->req_entry); + + if (comp_req->req) { + ret = __blk_end_request(comp_req->req, + (!comp_req->request.status ? 0 : -EIO), + comp_req->sector_count * + blkdev->sector_size); + + /* FIXME: shouldn't this do more than return? */ + if (ret) + goto out; + } + + kmem_cache_free(blkdev->request_pool, comp_req); + } + + DPRINT_DBG(BLKVSC_DRV, "cancelling pending request - %p\n", + pend_req); + + list_del(&pend_req->pend_entry); + + list_del(&pend_req->req_entry); + + if (comp_req->req) { + if (!__blk_end_request(pend_req->req, -EIO, + pend_req->sector_count * + blkdev->sector_size)) { + /* + * All the sectors have been xferred ie the + * request is done + */ + DPRINT_DBG(BLKVSC_DRV, + "blkvsc_cancel_pending_reqs() - " + "req %p COMPLETED\n", pend_req->req); + kmem_cache_free(blkdev->request_pool, + pend_req->group); + } + } + + kmem_cache_free(blkdev->request_pool, pend_req); + } + +out: + return ret; +} + +static int blkvsc_do_pending_reqs(struct block_device_context *blkdev) +{ + struct blkvsc_request *pend_req, *tmp; + int ret = 0; + + /* Flush the pending list first */ + list_for_each_entry_safe(pend_req, tmp, &blkdev->pending_list, + pend_entry) { + DPRINT_DBG(BLKVSC_DRV, "working off pending_list - %p\n", + pend_req); ret = blkvsc_submit_request(pend_req, blkvsc_request_completion); @@ -821,17 +1252,19 @@ static int blkvsc_do_pending_reqs(struct block_device_context *blkdev) return ret; } - static void blkvsc_request(struct request_queue *queue) { struct block_device_context *blkdev = NULL; struct request *req; int ret = 0; + DPRINT_DBG(BLKVSC_DRV, "- enter\n"); while ((req = blk_peek_request(queue)) != NULL) { + DPRINT_DBG(BLKVSC_DRV, "- req %p\n", req); blkdev = req->rq_disk->private_data; - if (blkdev->shutting_down || req->cmd_type != REQ_TYPE_FS) { + if (blkdev->shutting_down || req->cmd_type != REQ_TYPE_FS || + blkdev->media_not_present) { __blk_end_request_cur(req, 0); continue; } @@ -839,6 +1272,8 @@ static void blkvsc_request(struct request_queue *queue) ret = blkvsc_do_pending_reqs(blkdev); if (ret != 0) { + DPRINT_DBG(BLKVSC_DRV, + "- stop queue - pending_list not empty\n"); blk_stop_queue(queue); break; } @@ -847,9 +1282,11 @@ static void blkvsc_request(struct request_queue *queue) ret = blkvsc_do_request(blkdev, req); if (ret > 0) { + DPRINT_DBG(BLKVSC_DRV, "- stop queue - no room\n"); blk_stop_queue(queue); break; } else if (ret < 0) { + DPRINT_DBG(BLKVSC_DRV, "- stop queue - no mem\n"); blk_requeue_request(queue, req); blk_stop_queue(queue); break; @@ -857,265 +1294,178 @@ static void blkvsc_request(struct request_queue *queue) } } - - -/* The one and only one */ -static struct storvsc_driver_object g_blkvsc_drv; - -static const struct block_device_operations block_ops = { - .owner = THIS_MODULE, - .open = blkvsc_open, - .release = blkvsc_release, - .getgeo = blkvsc_getgeo, - .ioctl = blkvsc_ioctl, -}; - -/* - * blkvsc_drv_init - BlkVsc driver initialization. - */ -static int blkvsc_drv_init(void) +static int blkvsc_open(struct block_device *bdev, fmode_t mode) { - struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv; - struct hv_driver *drv = &g_blkvsc_drv.base; - int ret; - - storvsc_drv_obj->ring_buffer_size = blkvsc_ringbuffer_size; - - drv->priv = storvsc_drv_obj; - - /* Callback to client driver to complete the initialization */ - blk_vsc_initialize(&storvsc_drv_obj->base); + struct block_device_context *blkdev = bdev->bd_disk->private_data; - drv->driver.name = storvsc_drv_obj->base.name; + DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, + blkdev->gd->disk_name); - drv->driver.probe = blkvsc_probe; - drv->driver.remove = blkvsc_remove; - drv->driver.shutdown = blkvsc_shutdown; + mutex_lock(&blkvsc_mutex); + spin_lock(&blkdev->lock); - /* The driver belongs to vmbus */ - ret = vmbus_child_driver_register(&drv->driver); + if (!blkdev->users && blkdev->device_type == DVD_TYPE) { + spin_unlock(&blkdev->lock); + check_disk_change(bdev); + spin_lock(&blkdev->lock); + } - return ret; -} + blkdev->users++; -static int blkvsc_drv_exit_cb(struct device *dev, void *data) -{ - struct device **curr = (struct device **)data; - *curr = dev; - return 1; /* stop iterating */ + spin_unlock(&blkdev->lock); + mutex_unlock(&blkvsc_mutex); + return 0; } -static void blkvsc_drv_exit(void) +static int blkvsc_release(struct gendisk *disk, fmode_t mode) { - struct storvsc_driver_object *storvsc_drv_obj = &g_blkvsc_drv; - struct hv_driver *drv = &g_blkvsc_drv.base; - struct device *current_dev; - int ret; - - while (1) { - current_dev = NULL; - - /* Get the device */ - ret = driver_for_each_device(&drv->driver, NULL, - (void *) ¤t_dev, - blkvsc_drv_exit_cb); - - if (ret) - DPRINT_WARN(BLKVSC_DRV, - "driver_for_each_device returned %d", ret); - + struct block_device_context *blkdev = disk->private_data; - if (current_dev == NULL) - break; + DPRINT_DBG(BLKVSC_DRV, "- users %d disk %s\n", blkdev->users, + blkdev->gd->disk_name); - /* Initiate removal from the top-down */ - device_unregister(current_dev); + mutex_lock(&blkvsc_mutex); + spin_lock(&blkdev->lock); + if (blkdev->users == 1) { + spin_unlock(&blkdev->lock); + blkvsc_do_flush(blkdev); + spin_lock(&blkdev->lock); } - if (storvsc_drv_obj->base.cleanup) - storvsc_drv_obj->base.cleanup(&storvsc_drv_obj->base); - - vmbus_child_driver_unregister(&drv->driver); + blkdev->users--; - return; + spin_unlock(&blkdev->lock); + mutex_unlock(&blkvsc_mutex); + return 0; } -/* - * blkvsc_probe - Add a new device for this driver - */ -static int blkvsc_probe(struct device *device) +static unsigned int blkvsc_check_events(struct gendisk *gd, + unsigned int clearing) { - struct hv_driver *drv = - drv_to_hv_drv(device->driver); - struct storvsc_driver_object *storvsc_drv_obj = - drv->priv; - struct hv_device *device_obj = device_to_hv_device(device); + DPRINT_DBG(BLKVSC_DRV, "- enter\n"); + return DISK_EVENT_MEDIA_CHANGE; +} - struct block_device_context *blkdev = NULL; - struct storvsc_device_info device_info; - struct storvsc_major_info major_info; - int ret = 0; +static int blkvsc_revalidate_disk(struct gendisk *gd) +{ + struct block_device_context *blkdev = gd->private_data; + DPRINT_DBG(BLKVSC_DRV, "- enter\n"); - blkdev = kzalloc(sizeof(struct block_device_context), GFP_KERNEL); - if (!blkdev) { - ret = -ENOMEM; - goto cleanup; + if (blkdev->device_type == DVD_TYPE) { + blkvsc_do_read_capacity(blkdev); + set_capacity(blkdev->gd, blkdev->capacity * + (blkdev->sector_size/512)); + blk_queue_logical_block_size(gd->queue, blkdev->sector_size); } + return 0; +} - INIT_LIST_HEAD(&blkdev->pending_list); +static int blkvsc_getgeo(struct block_device *bd, struct hd_geometry *hg) +{ + sector_t total_sectors = get_capacity(bd->bd_disk); + sector_t cylinder_times_heads = 0; + sector_t temp = 0; - /* Initialize what we can here */ - spin_lock_init(&blkdev->lock); + int sectors_per_track = 0; + int heads = 0; + int cylinders = 0; + int rem = 0; + if (total_sectors > (65535 * 16 * 255)) + total_sectors = (65535 * 16 * 255); - blkdev->request_pool = kmem_cache_create(dev_name(&device_obj->device), - sizeof(struct blkvsc_request), 0, - SLAB_HWCACHE_ALIGN, NULL); - if (!blkdev->request_pool) { - ret = -ENOMEM; - goto cleanup; - } + if (total_sectors >= (65535 * 16 * 63)) { + sectors_per_track = 255; + heads = 16; + cylinder_times_heads = total_sectors; + /* sector_div stores the quotient in cylinder_times_heads */ + rem = sector_div(cylinder_times_heads, sectors_per_track); + } else { + sectors_per_track = 17; - /* Call to the vsc driver to add the device */ - ret = storvsc_drv_obj->base.dev_add(device_obj, &device_info); - if (ret != 0) - goto cleanup; + cylinder_times_heads = total_sectors; + /* sector_div stores the quotient in cylinder_times_heads */ + rem = sector_div(cylinder_times_heads, sectors_per_track); - blkdev->device_ctx = device_obj; - /* this identified the device 0 or 1 */ - blkdev->target = device_info.target_id; - /* this identified the ide ctrl 0 or 1 */ - blkdev->path = device_info.path_id; + temp = cylinder_times_heads + 1023; + /* sector_div stores the quotient in temp */ + rem = sector_div(temp, 1024); - dev_set_drvdata(device, blkdev); + heads = temp; - ret = stor_vsc_get_major_info(&device_info, &major_info); + if (heads < 4) + heads = 4; - if (ret) - goto cleanup; - if (major_info.do_register) { - ret = register_blkdev(major_info.major, major_info.devname); + if (cylinder_times_heads >= (heads * 1024) || (heads > 16)) { + sectors_per_track = 31; + heads = 16; - if (ret != 0) { - DPRINT_ERR(BLKVSC_DRV, - "register_blkdev() failed! ret %d", ret); - goto remove; + cylinder_times_heads = total_sectors; + /* + * sector_div stores the quotient in + * cylinder_times_heads + */ + rem = sector_div(cylinder_times_heads, + sectors_per_track); } - } - DPRINT_INFO(BLKVSC_DRV, "blkvsc registered for major %d!!", - major_info.major); + if (cylinder_times_heads >= (heads * 1024)) { + sectors_per_track = 63; + heads = 16; - blkdev->gd = alloc_disk(BLKVSC_MINORS); - if (!blkdev->gd) { - ret = -1; - goto cleanup; + cylinder_times_heads = total_sectors; + /* + * sector_div stores the quotient in + * cylinder_times_heads + */ + rem = sector_div(cylinder_times_heads, + sectors_per_track); + } } - blkdev->gd->queue = blk_init_queue(blkvsc_request, &blkdev->lock); - - blk_queue_max_segment_size(blkdev->gd->queue, PAGE_SIZE); - blk_queue_max_segments(blkdev->gd->queue, MAX_MULTIPAGE_BUFFER_COUNT); - blk_queue_segment_boundary(blkdev->gd->queue, PAGE_SIZE-1); - blk_queue_bounce_limit(blkdev->gd->queue, BLK_BOUNCE_ANY); - blk_queue_dma_alignment(blkdev->gd->queue, 511); - - blkdev->gd->major = major_info.major; - if (major_info.index == 1 || major_info.index == 3) - blkdev->gd->first_minor = BLKVSC_MINORS; - else - blkdev->gd->first_minor = 0; - blkdev->gd->fops = &block_ops; - blkdev->gd->events = DISK_EVENT_MEDIA_CHANGE; - blkdev->gd->private_data = blkdev; - blkdev->gd->driverfs_dev = &(blkdev->device_ctx->device); - sprintf(blkdev->gd->disk_name, "hd%c", 'a' + major_info.index); + temp = cylinder_times_heads; + /* sector_div stores the quotient in temp */ + rem = sector_div(temp, heads); + cylinders = temp; - blkvsc_do_operation(blkdev, DO_INQUIRY); - blkvsc_do_operation(blkdev, DO_CAPACITY); - - set_capacity(blkdev->gd, blkdev->capacity * (blkdev->sector_size/512)); - blk_queue_logical_block_size(blkdev->gd->queue, blkdev->sector_size); - /* go! */ - add_disk(blkdev->gd); - - DPRINT_INFO(BLKVSC_DRV, "%s added!! capacity %lu sector_size %d", - blkdev->gd->disk_name, (unsigned long)blkdev->capacity, - blkdev->sector_size); - - return ret; - -remove: - storvsc_drv_obj->base.dev_rm(device_obj); + hg->heads = heads; + hg->sectors = sectors_per_track; + hg->cylinders = cylinders; -cleanup: - if (blkdev) { - if (blkdev->request_pool) { - kmem_cache_destroy(blkdev->request_pool); - blkdev->request_pool = NULL; - } - kfree(blkdev); - blkdev = NULL; - } + DPRINT_INFO(BLKVSC_DRV, "CHS (%d, %d, %d)", cylinders, heads, + sectors_per_track); - return ret; + return 0; } -static void blkvsc_request_completion(struct hv_storvsc_request *request) +static int blkvsc_ioctl(struct block_device *bd, fmode_t mode, + unsigned cmd, unsigned long argument) { - struct blkvsc_request *blkvsc_req = - (struct blkvsc_request *)request->context; - struct block_device_context *blkdev = - (struct block_device_context *)blkvsc_req->dev; - unsigned long flags; - struct blkvsc_request *comp_req, *tmp; - struct vmscsi_request *vm_srb; - - - spin_lock_irqsave(&blkdev->lock, flags); - - blkdev->num_outstanding_reqs--; - blkvsc_req->group->outstanding--; +/* struct block_device_context *blkdev = bd->bd_disk->private_data; */ + int ret; + switch (cmd) { /* - * Only start processing when all the blkvsc_reqs are - * completed. This guarantees no out-of-order blkvsc_req - * completion when calling end_that_request_first() + * TODO: I think there is certain format for HDIO_GET_IDENTITY rather + * than just a GUID. Commented it out for now. */ - if (blkvsc_req->group->outstanding == 0) { - list_for_each_entry_safe(comp_req, tmp, - &blkvsc_req->group->blkvsc_req_list, - req_entry) { - - list_del(&comp_req->req_entry); - - vm_srb = - &comp_req->request.vstor_packet.vm_srb; - if (!__blk_end_request(comp_req->req, - (!vm_srb->scsi_status ? 0 : -EIO), - comp_req->sector_count * blkdev->sector_size)) { - /* - * All the sectors have been xferred ie the - * request is done - */ - kmem_cache_free(blkdev->request_pool, - comp_req->group); - } - - kmem_cache_free(blkdev->request_pool, comp_req); - } - - if (!blkdev->shutting_down) { - blkvsc_do_pending_reqs(blkdev); - blk_start_queue(blkdev->gd->queue); - blkvsc_request(blkdev->gd->queue); - } +#if 0 + case HDIO_GET_IDENTITY: + DPRINT_INFO(BLKVSC_DRV, "HDIO_GET_IDENTITY\n"); + if (copy_to_user((void __user *)arg, blkdev->device_id, + blkdev->device_id_len)) + ret = -EFAULT; + break; +#endif + default: + ret = -EINVAL; + break; } - spin_unlock_irqrestore(&blkdev->lock, flags); + return ret; } static int __init blkvsc_init(void) @@ -1124,7 +1474,9 @@ static int __init blkvsc_init(void) BUILD_BUG_ON(sizeof(sector_t) != 8); - ret = blkvsc_drv_init(); + DPRINT_INFO(BLKVSC_DRV, "Blkvsc initializing...."); + + ret = blkvsc_drv_init(blk_vsc_initialize); return ret; } diff --git a/trunk/drivers/staging/hv/channel.c b/trunk/drivers/staging/hv/channel.c index b53be5847a34..f7ce7d2494b3 100644 --- a/trunk/drivers/staging/hv/channel.c +++ b/trunk/drivers/staging/hv/channel.c @@ -18,8 +18,6 @@ * Haiyang Zhang * Hank Janssen */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -215,6 +213,9 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, /* Establish the gpadl for the ring buffer */ + DPRINT_DBG(VMBUS, "Establishing ring buffer's gpadl for channel %p...", + newchannel); + newchannel->ringbuffer_gpadlhandle = 0; ret = vmbus_establish_gpadl(newchannel, @@ -228,6 +229,16 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, goto errorout; } + DPRINT_DBG(VMBUS, "channel %p ", + newchannel, newchannel->offermsg.child_relid, + newchannel->ringbuffer_gpadlhandle, + newchannel->outbound.ring_buffer, + newchannel->outbound.ring_size, + newchannel->inbound.ring_buffer, + newchannel->inbound.ring_size, + send_ringbuffer_size); + /* Create and init the channel open message */ openInfo = kmalloc(sizeof(*openInfo) + sizeof(struct vmbus_channel_open_channel), @@ -261,11 +272,14 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, &vmbus_connection.chn_msg_list); spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); + DPRINT_DBG(VMBUS, "Sending channel open msg..."); + ret = vmbus_post_msg(openMsg, sizeof(struct vmbus_channel_open_channel)); - - if (ret != 0) + if (ret != 0) { + DPRINT_ERR(VMBUS, "unable to open channel - %d", ret); goto Cleanup; + } openInfo->wait_condition = 0; wait_event_timeout(openInfo->waitevent, @@ -277,8 +291,11 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, } - if (openInfo->response.open_result.status) - err = openInfo->response.open_result.status; + if (openInfo->response.open_result.status == 0) + DPRINT_INFO(VMBUS, "channel <%p> open success!!", newchannel); + else + DPRINT_INFO(VMBUS, "channel <%p> open failed - %d!!", + newchannel, openInfo->response.open_result.status); Cleanup: spin_lock_irqsave(&vmbus_connection.channelmsg_lock, flags); @@ -286,7 +303,7 @@ int vmbus_open(struct vmbus_channel *newchannel, u32 send_ringbuffer_size, spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); kfree(openInfo); - return err; + return 0; errorout: ringbuffer_cleanup(&newchannel->outbound); @@ -309,7 +326,6 @@ static void dump_gpadl_body(struct vmbus_channel_gpadl_body *gpadl, u32 len) pfncount = (len - sizeof(struct vmbus_channel_gpadl_body)) / sizeof(u64); - DPRINT_DBG(VMBUS, "gpadl body - len %d pfn count %d", len, pfncount); for (i = 0; i < pfncount; i++) @@ -514,12 +530,19 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, &vmbus_connection.chn_msg_list); spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); + DPRINT_DBG(VMBUS, "buffer %p, size %d msg cnt %d", + kbuffer, size, msgcount); + + DPRINT_DBG(VMBUS, "Sending GPADL Header - len %zd", + msginfo->msgsize - sizeof(*msginfo)); msginfo->wait_condition = 0; ret = vmbus_post_msg(gpadlmsg, msginfo->msgsize - sizeof(*msginfo)); - if (ret != 0) + if (ret != 0) { + DPRINT_ERR(VMBUS, "Unable to open channel - %d", ret); goto Cleanup; + } if (msgcount > 1) { list_for_each(curr, &msginfo->submsglist) { @@ -533,6 +556,10 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, CHANNELMSG_GPADL_BODY; gpadl_body->gpadl = next_gpadl_handle; + DPRINT_DBG(VMBUS, "Sending GPADL Body - len %zd", + submsginfo->msgsize - + sizeof(*submsginfo)); + dump_gpadl_body(gpadl_body, submsginfo->msgsize - sizeof(*submsginfo)); ret = vmbus_post_msg(gpadl_body, @@ -550,6 +577,12 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer, /* At this point, we received the gpadl created msg */ + DPRINT_DBG(VMBUS, "Received GPADL created " + "(relid %d, status %d handle %x)", + channel->offermsg.child_relid, + msginfo->response.gpadl_created.creation_status, + gpadlmsg->gpadl); + *gpadl_handle = gpadlmsg->gpadl; Cleanup: @@ -697,6 +730,9 @@ int vmbus_sendpacket(struct vmbus_channel *channel, const void *buffer, u64 aligned_data = 0; int ret; + DPRINT_DBG(VMBUS, "channel %p buffer %p len %d", + channel, buffer, bufferlen); + dump_vmbus_channel(channel); /* ASSERT((packetLenAligned - packetLen) < sizeof(u64)); */ @@ -810,6 +846,10 @@ int vmbus_sendpacket_multipagebuffer(struct vmbus_channel *channel, dump_vmbus_channel(channel); + DPRINT_DBG(VMBUS, "data buffer - offset %u len %u pfn count %u", + multi_pagebuffer->offset, + multi_pagebuffer->len, pfncount); + if ((pfncount < 0) || (pfncount > MAX_MULTIPAGE_BUFFER_COUNT)) return -EINVAL; @@ -886,6 +926,8 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, sizeof(struct vmpacket_descriptor)); if (ret != 0) { spin_unlock_irqrestore(&channel->inbound_lock, flags); + + /* DPRINT_DBG(VMBUS, "nothing to read!!"); */ return 0; } @@ -895,12 +937,17 @@ int vmbus_recvpacket(struct vmbus_channel *channel, void *buffer, userlen = packetlen - (desc.offset8 << 3); /* ASSERT(userLen > 0); */ + DPRINT_DBG(VMBUS, "packet received on channel %p relid %d ", + channel, channel->offermsg.child_relid, desc.type, + desc.flags, desc.trans_id, packetlen, userlen); + *buffer_actual_len = userlen; if (userlen > bufferlen) { spin_unlock_irqrestore(&channel->inbound_lock, flags); - pr_err("Buffer too small - got %d needs %d\n", + DPRINT_ERR(VMBUS, "buffer too small - got %d needs %d", bufferlen, userlen); return -1; } @@ -939,6 +986,8 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, sizeof(struct vmpacket_descriptor)); if (ret != 0) { spin_unlock_irqrestore(&channel->inbound_lock, flags); + + /* DPRINT_DBG(VMBUS, "nothing to read!!"); */ return 0; } @@ -947,14 +996,18 @@ int vmbus_recvpacket_raw(struct vmbus_channel *channel, void *buffer, packetlen = desc.len8 << 3; userlen = packetlen - (desc.offset8 << 3); + DPRINT_DBG(VMBUS, "packet received on channel %p relid %d ", + channel, channel->offermsg.child_relid, desc.type, + desc.flags, desc.trans_id, packetlen, userlen); + *buffer_actual_len = packetlen; if (packetlen > bufferlen) { spin_unlock_irqrestore(&channel->inbound_lock, flags); - pr_err("Buffer too small - needed %d bytes but " - "got space for only %d bytes\n", - packetlen, bufferlen); + DPRINT_ERR(VMBUS, "buffer too small - needed %d bytes but " + "got space for only %d bytes", packetlen, bufferlen); return -2; } diff --git a/trunk/drivers/staging/hv/channel_mgmt.c b/trunk/drivers/staging/hv/channel_mgmt.c index fe32f7e3e081..06b573227e8d 100644 --- a/trunk/drivers/staging/hv/channel_mgmt.c +++ b/trunk/drivers/staging/hv/channel_mgmt.c @@ -18,8 +18,6 @@ * Haiyang Zhang * Hank Janssen */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -292,7 +290,9 @@ static void release_channel(struct work_struct *work) struct vmbus_channel, work); + DPRINT_DBG(VMBUS, "releasing channel (%p)", channel); destroy_workqueue(channel->controlwq); + DPRINT_DBG(VMBUS, "channel released (%p)", channel); kfree(channel); } @@ -384,6 +384,8 @@ static void vmbus_process_offer(struct work_struct *work) spin_unlock_irqrestore(&vmbus_connection.channel_lock, flags); if (!fnew) { + DPRINT_DBG(VMBUS, "Ignoring duplicate offer for relid (%d)", + newchannel->offermsg.child_relid); free_channel(newchannel); return; } @@ -398,6 +400,9 @@ static void vmbus_process_offer(struct work_struct *work) &newchannel->offermsg.offer.if_instance, newchannel); + DPRINT_DBG(VMBUS, "child device object allocated - %p", + newchannel->device_obj); + /* * Add the new device to the bus. This will kick off device-driver * binding which eventually invokes the device driver's AddDevice() @@ -405,7 +410,8 @@ static void vmbus_process_offer(struct work_struct *work) */ ret = vmbus_child_device_register(newchannel->device_obj); if (ret != 0) { - pr_err("unable to add child device object (relid %d)\n", + DPRINT_ERR(VMBUS, + "unable to add child device object (relid %d)", newchannel->offermsg.child_relid); spin_lock_irqsave(&vmbus_connection.channel_lock, flags); @@ -431,9 +437,8 @@ static void vmbus_process_offer(struct work_struct *work) hv_cb_utils[cnt].callback, newchannel) == 0) { hv_cb_utils[cnt].channel = newchannel; - - pr_info("%s\n", hv_cb_utils[cnt].log_msg); - + DPRINT_INFO(VMBUS, "%s", + hv_cb_utils[cnt].log_msg); count_hv_channel(); } } @@ -465,19 +470,49 @@ static void vmbus_onoffer(struct vmbus_channel_message_header *hdr) } } - if (!fsupported) + if (!fsupported) { + DPRINT_DBG(VMBUS, "Ignoring channel offer notification for " + "child relid %d", offer->child_relid); return; + } guidtype = &offer->offer.if_type; guidinstance = &offer->offer.if_instance; + DPRINT_INFO(VMBUS, "Channel offer notification - " + "child relid %d monitor id %d allocated %d, " + "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x%02x%02x} " + "instance {%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x%02x%02x}", + offer->child_relid, offer->monitorid, + offer->monitor_allocated, + guidtype->data[3], guidtype->data[2], + guidtype->data[1], guidtype->data[0], + guidtype->data[5], guidtype->data[4], + guidtype->data[7], guidtype->data[6], + guidtype->data[8], guidtype->data[9], + guidtype->data[10], guidtype->data[11], + guidtype->data[12], guidtype->data[13], + guidtype->data[14], guidtype->data[15], + guidinstance->data[3], guidinstance->data[2], + guidinstance->data[1], guidinstance->data[0], + guidinstance->data[5], guidinstance->data[4], + guidinstance->data[7], guidinstance->data[6], + guidinstance->data[8], guidinstance->data[9], + guidinstance->data[10], guidinstance->data[11], + guidinstance->data[12], guidinstance->data[13], + guidinstance->data[14], guidinstance->data[15]); + /* Allocate the channel object and save this offer. */ newchannel = alloc_channel(); if (!newchannel) { - pr_err("Unable to allocate channel object\n"); + DPRINT_ERR(VMBUS, "unable to allocate channel object"); return; } + DPRINT_DBG(VMBUS, "channel object allocated - %p", newchannel); + memcpy(&newchannel->offermsg, offer, sizeof(struct vmbus_channel_offer_channel)); newchannel->monitor_grp = (u8)offer->monitorid / 32; @@ -500,10 +535,11 @@ static void vmbus_onoffer_rescind(struct vmbus_channel_message_header *hdr) rescind = (struct vmbus_channel_rescind_offer *)hdr; channel = relid2channel(rescind->child_relid); - - if (channel == NULL) - /* Just return here, no channel found */ + if (channel == NULL) { + DPRINT_DBG(VMBUS, "channel not found for relId %d", + rescind->child_relid); return; + } /* work is initialized for vmbus_process_rescind_offer() from * vmbus_process_offer() where the channel got created */ @@ -537,6 +573,7 @@ static void vmbus_onopen_result(struct vmbus_channel_message_header *hdr) unsigned long flags; result = (struct vmbus_channel_open_result *)hdr; + DPRINT_DBG(VMBUS, "vmbus open result - %d", result->status); /* * Find the open msg, copy the result and signal/unblock the wait event @@ -581,6 +618,8 @@ static void vmbus_ongpadl_created(struct vmbus_channel_message_header *hdr) unsigned long flags; gpadlcreated = (struct vmbus_channel_gpadl_created *)hdr; + DPRINT_DBG(VMBUS, "vmbus gpadl created result - %d", + gpadlcreated->creation_status); /* * Find the establish msg, copy the result and signal/unblock the wait @@ -731,8 +770,11 @@ void vmbus_onmessage(void *context) hdr = (struct vmbus_channel_message_header *)msg->u.payload; size = msg->header.payload_size; + DPRINT_DBG(VMBUS, "message type %d size %d", hdr->msgtype, size); + if (hdr->msgtype >= CHANNELMSG_COUNT) { - pr_err("Received invalid channel message type %d size %d\n", + DPRINT_ERR(VMBUS, + "Received invalid channel message type %d size %d", hdr->msgtype, size); print_hex_dump_bytes("", DUMP_PREFIX_NONE, (unsigned char *)msg->u.payload, size); @@ -742,7 +784,8 @@ void vmbus_onmessage(void *context) if (gChannelMessageTable[hdr->msgtype].messageHandler) gChannelMessageTable[hdr->msgtype].messageHandler(hdr); else - pr_err("Unhandled channel message type %d\n", hdr->msgtype); + DPRINT_ERR(VMBUS, "Unhandled channel message type %d", + hdr->msgtype); } /* @@ -770,7 +813,7 @@ int vmbus_request_offers(void) ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_message_header)); if (ret != 0) { - pr_err("Unable to request offers - %d\n", ret); + DPRINT_ERR(VMBUS, "Unable to request offers - %d", ret); goto cleanup; } @@ -810,8 +853,9 @@ void vmbus_release_unattached_channels(void) if (!channel->device_obj->drv) { list_del(&channel->listentry); - - pr_err("Releasing unattached device object\n"); + DPRINT_INFO(VMBUS, + "Releasing unattached device object %p", + channel->device_obj); vmbus_child_device_unregister(channel->device_obj); free_channel(channel); diff --git a/trunk/drivers/staging/hv/connection.c b/trunk/drivers/staging/hv/connection.c index 4f411a9f2a5a..afc8116e7aa4 100644 --- a/trunk/drivers/staging/hv/connection.c +++ b/trunk/drivers/staging/hv/connection.c @@ -20,8 +20,6 @@ * Hank Janssen * */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -123,6 +121,11 @@ int vmbus_connect(void) spin_unlock_irqrestore(&vmbus_connection.channelmsg_lock, flags); + DPRINT_DBG(VMBUS, "Vmbus connection - interrupt pfn %llx, " + "monitor1 pfn %llx,, monitor2 pfn %llx", + msg->interrupt_page, msg->monitor_page1, msg->monitor_page2); + + DPRINT_DBG(VMBUS, "Sending channel initiate msg..."); ret = vmbus_post_msg(msg, sizeof(struct vmbus_channel_initiate_contact)); if (ret != 0) { @@ -153,11 +156,13 @@ int vmbus_connect(void) /* Check if successful */ if (msginfo->response.version_response.version_supported) { + DPRINT_INFO(VMBUS, "Vmbus connected!!"); vmbus_connection.conn_state = CONNECTED; + } else { - pr_err("Unable to connect, " - "Version %d not supported by Hyper-V\n", - VMBUS_REVISION_NUMBER); + DPRINT_ERR(VMBUS, "Vmbus connection failed!!..." + "current version (%d) not supported", + VMBUS_REVISION_NUMBER); ret = -1; goto Cleanup; } @@ -218,7 +223,7 @@ int vmbus_disconnect(void) vmbus_connection.conn_state = DISCONNECTED; - pr_info("hv_vmbus disconnected\n"); + DPRINT_INFO(VMBUS, "Vmbus disconnected!!"); Cleanup: kfree(msg); @@ -250,9 +255,10 @@ struct vmbus_channel *relid2channel(u32 relid) /* * process_chn_event - Process a channel event notification */ -static void process_chn_event(u32 relid) +static void process_chn_event(void *context) { struct vmbus_channel *channel; + u32 relid = (u32)(unsigned long)context; /* ASSERT(relId > 0); */ @@ -270,7 +276,7 @@ static void process_chn_event(u32 relid) * (void*)channel); */ } else { - pr_err("channel not found for relid - %u\n", relid); + DPRINT_ERR(VMBUS, "channel not found for relid - %d.", relid); } } @@ -279,30 +285,39 @@ static void process_chn_event(u32 relid) */ void vmbus_on_event(unsigned long data) { - u32 dword; - u32 maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5; + int dword; + int maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5; int bit; - u32 relid; + int relid; u32 *recv_int_page = vmbus_connection.recv_int_page; /* Check events */ - if (!recv_int_page) - return; - for (dword = 0; dword < maxdword; dword++) { - if (!recv_int_page[dword]) - continue; - for (bit = 0; bit < 32; bit++) { - if (sync_test_and_clear_bit(bit, (unsigned long *)&recv_int_page[dword])) { - relid = (dword << 5) + bit; - - if (relid == 0) { - /* special case - vmbus channel protocol msg */ - continue; + if (recv_int_page) { + for (dword = 0; dword < maxdword; dword++) { + if (recv_int_page[dword]) { + for (bit = 0; bit < 32; bit++) { + if (sync_test_and_clear_bit(bit, + (unsigned long *) + &recv_int_page[dword])) { + relid = (dword << 5) + bit; + DPRINT_DBG(VMBUS, "event detected for relid - %d", relid); + + if (relid == 0) { + /* special case - vmbus channel protocol msg */ + DPRINT_DBG(VMBUS, "invalid relid - %d", relid); + continue; + } else { + /* QueueWorkItem(VmbusProcessEvent, (void*)relid); */ + /* ret = WorkQueueQueueWorkItem(gVmbusConnection.workQueue, VmbusProcessChannelEvent, (void*)relid); */ + process_chn_event((void *) + (unsigned long)relid); + } + } } - process_chn_event(relid); } - } + } } + return; } /* diff --git a/trunk/drivers/staging/hv/hv.c b/trunk/drivers/staging/hv/hv.c index e6312bd47d7e..0b06f4fe5838 100644 --- a/trunk/drivers/staging/hv/hv.c +++ b/trunk/drivers/staging/hv/hv.c @@ -19,8 +19,6 @@ * Hank Janssen * */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -82,7 +80,7 @@ static int query_hypervisor_info(void) op = HVCPUID_VENDOR_MAXFUNCTION; cpuid(op, &eax, &ebx, &ecx, &edx); -/* DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c", + DPRINT_INFO(VMBUS, "Vendor ID: %c%c%c%c%c%c%c%c%c%c%c%c", (ebx & 0xFF), ((ebx >> 8) & 0xFF), ((ebx >> 16) & 0xFF), @@ -95,9 +93,9 @@ static int query_hypervisor_info(void) ((edx >> 8) & 0xFF), ((edx >> 16) & 0xFF), ((edx >> 24) & 0xFF)); -*/ + max_leaf = eax; -/* eax = 0; + eax = 0; ebx = 0; ecx = 0; edx = 0; @@ -109,7 +107,6 @@ static int query_hypervisor_info(void) ((eax >> 8) & 0xFF), ((eax >> 16) & 0xFF), ((eax >> 24) & 0xFF)); -*/ if (max_leaf >= HVCPUID_VERSION) { eax = 0; @@ -118,7 +115,7 @@ static int query_hypervisor_info(void) edx = 0; op = HVCPUID_VERSION; cpuid(op, &eax, &ebx, &ecx, &edx); - pr_info("Hyper-V Host OS Build:%d-%d.%d-%d-%d.%d\n", + DPRINT_INFO(VMBUS, "OS Build:%d-%d.%d-%d-%d.%d",\ eax, ebx >> 16, ebx & 0xFFFF, @@ -140,11 +137,18 @@ static u64 do_hypercall(u64 control, void *input, void *output) u64 output_address = (output) ? virt_to_phys(output) : 0; volatile void *hypercall_page = hv_context.hypercall_page; + DPRINT_DBG(VMBUS, "Hypercall ", + control, input_address, input, + output_address, output, hypercall_page); + __asm__ __volatile__("mov %0, %%r8" : : "r" (output_address) : "r8"); __asm__ __volatile__("call *%3" : "=a" (hv_status) : "c" (control), "d" (input_address), "m" (hypercall_page)); + DPRINT_DBG(VMBUS, "Hypercall ", hv_status); + return hv_status; #else @@ -161,12 +165,18 @@ static u64 do_hypercall(u64 control, void *input, void *output) u32 output_address_lo = output_address & 0xFFFFFFFF; volatile void *hypercall_page = hv_context.hypercall_page; + DPRINT_DBG(VMBUS, "Hypercall ", + control, input, output); + __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi), "=a"(hv_status_lo) : "d" (control_hi), "a" (control_lo), "b" (input_address_hi), "c" (input_address_lo), "D"(output_address_hi), "S"(output_address_lo), "m" (hypercall_page)); + DPRINT_DBG(VMBUS, "Hypercall ", + hv_status_lo | ((u64)hv_status_hi << 32)); + return hv_status_lo | ((u64)hv_status_hi << 32); #endif /* !x86_64 */ } @@ -187,8 +197,13 @@ int hv_init(void) memset(hv_context.synic_message_page, 0, sizeof(void *) * MAX_NUM_CPUS); - if (!query_hypervisor_presence()) + if (!query_hypervisor_presence()) { + DPRINT_ERR(VMBUS, "No Windows hypervisor detected!!"); goto Cleanup; + } + + DPRINT_INFO(VMBUS, + "Windows hypervisor detected! Retrieving more info..."); max_leaf = query_hypervisor_info(); /* HvQueryHypervisorFeatures(maxLeaf); */ @@ -198,8 +213,11 @@ int hv_init(void) */ rdmsrl(HV_X64_MSR_GUEST_OS_ID, hv_context.guestid); - if (hv_context.guestid != 0) + if (hv_context.guestid != 0) { + DPRINT_ERR(VMBUS, "Unknown guest id (0x%llx)!!", + hv_context.guestid); goto Cleanup; + } /* Write our OS info */ wrmsrl(HV_X64_MSR_GUEST_OS_ID, HV_LINUX_GUEST_ID); @@ -214,8 +232,11 @@ int hv_init(void) */ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC); - if (!virtaddr) + if (!virtaddr) { + DPRINT_ERR(VMBUS, + "unable to allocate hypercall page!!"); goto Cleanup; + } hypercall_msr.enable = 1; @@ -226,11 +247,17 @@ int hv_init(void) hypercall_msr.as_uint64 = 0; rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64); - if (!hypercall_msr.enable) + if (!hypercall_msr.enable) { + DPRINT_ERR(VMBUS, "unable to set hypercall page!!"); goto Cleanup; + } hv_context.hypercall_page = virtaddr; + DPRINT_INFO(VMBUS, "Hypercall page VA=%p, PA=0x%0llx", + hv_context.hypercall_page, + (u64)hypercall_msr.guest_physical_address << PAGE_SHIFT); + /* Setup the global signal event param for the signal event hypercall */ hv_context.signal_event_buffer = kmalloc(sizeof(struct hv_input_signal_event_buffer), @@ -367,11 +394,14 @@ void hv_synic_init(void *irqarg) /* Check the version */ rdmsrl(HV_X64_MSR_SVERSION, version); + DPRINT_INFO(VMBUS, "SynIC version: %llx", version); + hv_context.synic_message_page[cpu] = (void *)get_zeroed_page(GFP_ATOMIC); if (hv_context.synic_message_page[cpu] == NULL) { - pr_err("Unable to allocate SYNIC message page\n"); + DPRINT_ERR(VMBUS, + "unable to allocate SYNIC message page!!"); goto Cleanup; } @@ -379,7 +409,8 @@ void hv_synic_init(void *irqarg) (void *)get_zeroed_page(GFP_ATOMIC); if (hv_context.synic_event_page[cpu] == NULL) { - pr_err("Unable to allocate SYNIC event page\n"); + DPRINT_ERR(VMBUS, + "unable to allocate SYNIC event page!!"); goto Cleanup; } @@ -389,6 +420,8 @@ void hv_synic_init(void *irqarg) simp.base_simp_gpa = virt_to_phys(hv_context.synic_message_page[cpu]) >> PAGE_SHIFT; + DPRINT_DBG(VMBUS, "HV_X64_MSR_SIMP msr set to: %llx", simp.as_uint64); + wrmsrl(HV_X64_MSR_SIMP, simp.as_uint64); /* Setup the Synic's event page */ @@ -397,6 +430,8 @@ void hv_synic_init(void *irqarg) siefp.base_siefp_gpa = virt_to_phys(hv_context.synic_event_page[cpu]) >> PAGE_SHIFT; + DPRINT_DBG(VMBUS, "HV_X64_MSR_SIEFP msr set to: %llx", siefp.as_uint64); + wrmsrl(HV_X64_MSR_SIEFP, siefp.as_uint64); /* Setup the interception SINT. */ @@ -411,6 +446,9 @@ void hv_synic_init(void *irqarg) shared_sint.masked = false; shared_sint.auto_eoi = true; + DPRINT_DBG(VMBUS, "HV_X64_MSR_SINT1 msr set to: %llx", + shared_sint.as_uint64); + wrmsrl(HV_X64_MSR_SINT0 + VMBUS_MESSAGE_SINT, shared_sint.as_uint64); /* Enable the global synic bit */ diff --git a/trunk/drivers/staging/hv/hv_kvp.c b/trunk/drivers/staging/hv/hv_kvp.c index c71a1486544d..faf692e4126e 100644 --- a/trunk/drivers/staging/hv/hv_kvp.c +++ b/trunk/drivers/staging/hv/hv_kvp.c @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include @@ -114,7 +114,7 @@ kvp_cn_callback(struct cn_msg *msg, struct netlink_skb_parms *nsp) message = (struct hv_ku_msg *)msg->data; if (msg->seq == KVP_REGISTER) { - pr_info("KVP: user-mode registering done.\n"); + printk(KERN_INFO "KVP: user-mode registering done.\n"); kvp_register(); } @@ -174,7 +174,7 @@ kvp_respond_to_host(char *key, char *value, int error) /* * This is a spurious call! */ - pr_warn("KVP: Transaction not active\n"); + printk(KERN_WARNING "KVP: Transaction not active\n"); return; } /* @@ -259,6 +259,9 @@ void hv_kvp_onchannelcallback(void *context) vmbus_recvpacket(channel, recv_buffer, PAGE_SIZE, &recvlen, &requestid); if (recvlen > 0) { + DPRINT_DBG(VMBUS, "KVP packet: len=%d, requestid=%lld", + recvlen, requestid); + icmsghdrp = (struct icmsg_hdr *)&recv_buffer[ sizeof(struct vmbuspipe_hdr)]; diff --git a/trunk/drivers/staging/hv/hv_mouse.c b/trunk/drivers/staging/hv/hv_mouse.c index bd935489a2a3..118c7be22562 100644 --- a/trunk/drivers/staging/hv/hv_mouse.c +++ b/trunk/drivers/staging/hv/hv_mouse.c @@ -48,7 +48,7 @@ struct hv_input_dev_info { /* Represents the input vsc driver */ /* FIXME - can be removed entirely */ struct mousevsc_drv_obj { - struct hv_driver base; + struct hv_driver Base; }; @@ -169,23 +169,23 @@ struct mousevsc_prt_msg { * Represents an mousevsc device */ struct mousevsc_dev { - struct hv_device *device; + struct hv_device *Device; /* 0 indicates the device is being destroyed */ - atomic_t ref_count; - int num_outstanding_req; - unsigned char init_complete; - struct mousevsc_prt_msg protocol_req; - struct mousevsc_prt_msg protocol_resp; + atomic_t RefCount; + int NumOutstandingRequests; + unsigned char bInitializeComplete; + struct mousevsc_prt_msg ProtocolReq; + struct mousevsc_prt_msg ProtocolResp; /* Synchronize the request/response if needed */ - wait_queue_head_t protocol_wait_event; - wait_queue_head_t dev_info_wait_event; + wait_queue_head_t ProtocolWaitEvent; + wait_queue_head_t DeviceInfoWaitEvent; int protocol_wait_condition; int device_wait_condition; - int dev_info_status; + int DeviceInfoStatus; - struct hid_descriptor *hid_desc; - unsigned char *report_desc; - u32 report_desc_size; + struct hid_descriptor *HidDesc; + unsigned char *ReportDesc; + u32 ReportDescSize; struct hv_input_dev_info hid_dev_info; }; @@ -202,41 +202,41 @@ static void deviceinfo_callback(struct hv_device *dev, struct hv_input_dev_info static void inputreport_callback(struct hv_device *dev, void *packet, u32 len); static void reportdesc_callback(struct hv_device *dev, void *packet, u32 len); -static struct mousevsc_dev *alloc_input_device(struct hv_device *device) +static struct mousevsc_dev *AllocInputDevice(struct hv_device *Device) { - struct mousevsc_dev *input_dev; + struct mousevsc_dev *inputDevice; - input_dev = kzalloc(sizeof(struct mousevsc_dev), GFP_KERNEL); + inputDevice = kzalloc(sizeof(struct mousevsc_dev), GFP_KERNEL); - if (!input_dev) + if (!inputDevice) return NULL; /* * Set to 2 to allow both inbound and outbound traffics - * (ie get_input_device() and must_get_input_device()) to proceed. + * (ie GetInputDevice() and MustGetInputDevice()) to proceed. */ - atomic_cmpxchg(&input_dev->ref_count, 0, 2); + atomic_cmpxchg(&inputDevice->RefCount, 0, 2); - input_dev->device = device; - device->ext = input_dev; + inputDevice->Device = Device; + Device->ext = inputDevice; - return input_dev; + return inputDevice; } -static void free_input_device(struct mousevsc_dev *device) +static void FreeInputDevice(struct mousevsc_dev *Device) { - WARN_ON(atomic_read(&device->ref_count) == 0); - kfree(device); + WARN_ON(atomic_read(&Device->RefCount) == 0); + kfree(Device); } /* * Get the inputdevice object if exists and its refcount > 1 */ -static struct mousevsc_dev *get_input_device(struct hv_device *device) +static struct mousevsc_dev *GetInputDevice(struct hv_device *Device) { - struct mousevsc_dev *input_dev; + struct mousevsc_dev *inputDevice; - input_dev = (struct mousevsc_dev *)device->ext; + inputDevice = (struct mousevsc_dev *)Device->ext; /* * FIXME @@ -244,137 +244,134 @@ static struct mousevsc_dev *get_input_device(struct hv_device *device) * what the intention is... * * printk(KERN_ERR "-------------------------> REFCOUNT = %d", - * input_dev->ref_count); + * inputDevice->RefCount); */ - if (input_dev && atomic_read(&input_dev->ref_count) > 1) - atomic_inc(&input_dev->ref_count); + if (inputDevice && atomic_read(&inputDevice->RefCount) > 1) + atomic_inc(&inputDevice->RefCount); else - input_dev = NULL; + inputDevice = NULL; - return input_dev; + return inputDevice; } /* * Get the inputdevice object iff exists and its refcount > 0 */ -static struct mousevsc_dev *must_get_input_device(struct hv_device *device) +static struct mousevsc_dev *MustGetInputDevice(struct hv_device *Device) { - struct mousevsc_dev *input_dev; + struct mousevsc_dev *inputDevice; - input_dev = (struct mousevsc_dev *)device->ext; + inputDevice = (struct mousevsc_dev *)Device->ext; - if (input_dev && atomic_read(&input_dev->ref_count)) - atomic_inc(&input_dev->ref_count); + if (inputDevice && atomic_read(&inputDevice->RefCount)) + atomic_inc(&inputDevice->RefCount); else - input_dev = NULL; + inputDevice = NULL; - return input_dev; + return inputDevice; } -static void put_input_device(struct hv_device *device) +static void PutInputDevice(struct hv_device *Device) { - struct mousevsc_dev *input_dev; + struct mousevsc_dev *inputDevice; - input_dev = (struct mousevsc_dev *)device->ext; + inputDevice = (struct mousevsc_dev *)Device->ext; - atomic_dec(&input_dev->ref_count); + atomic_dec(&inputDevice->RefCount); } /* - * Drop ref count to 1 to effectively disable get_input_device() + * Drop ref count to 1 to effectively disable GetInputDevice() */ -static struct mousevsc_dev *release_input_device(struct hv_device *device) +static struct mousevsc_dev *ReleaseInputDevice(struct hv_device *Device) { - struct mousevsc_dev *input_dev; + struct mousevsc_dev *inputDevice; - input_dev = (struct mousevsc_dev *)device->ext; + inputDevice = (struct mousevsc_dev *)Device->ext; /* Busy wait until the ref drop to 2, then set it to 1 */ - while (atomic_cmpxchg(&input_dev->ref_count, 2, 1) != 2) + while (atomic_cmpxchg(&inputDevice->RefCount, 2, 1) != 2) udelay(100); - return input_dev; + return inputDevice; } /* - * Drop ref count to 0. No one can use input_device object. + * Drop ref count to 0. No one can use InputDevice object. */ -static struct mousevsc_dev *final_release_input_device(struct hv_device *device) +static struct mousevsc_dev *FinalReleaseInputDevice(struct hv_device *Device) { - struct mousevsc_dev *input_dev; + struct mousevsc_dev *inputDevice; - input_dev = (struct mousevsc_dev *)device->ext; + inputDevice = (struct mousevsc_dev *)Device->ext; /* Busy wait until the ref drop to 1, then set it to 0 */ - while (atomic_cmpxchg(&input_dev->ref_count, 1, 0) != 1) + while (atomic_cmpxchg(&inputDevice->RefCount, 1, 0) != 1) udelay(100); - device->ext = NULL; - return input_dev; + Device->ext = NULL; + return inputDevice; } -static void mousevsc_on_send_completion(struct hv_device *device, - struct vmpacket_descriptor *packet) +static void MousevscOnSendCompletion(struct hv_device *Device, struct vmpacket_descriptor *Packet) { - struct mousevsc_dev *input_dev; + struct mousevsc_dev *inputDevice; void *request; - input_dev = must_get_input_device(device); - if (!input_dev) { + inputDevice = MustGetInputDevice(Device); + if (!inputDevice) { pr_err("unable to get input device...device being destroyed?"); return; } - request = (void *)(unsigned long)packet->trans_id; + request = (void *)(unsigned long)Packet->trans_id; - if (request == &input_dev->protocol_req) { + if (request == &inputDevice->ProtocolReq) { /* FIXME */ /* Shouldn't we be doing something here? */ } - put_input_device(device); + PutInputDevice(Device); } -static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device, - struct synthhid_device_info *device_info) +static void MousevscOnReceiveDeviceInfo(struct mousevsc_dev *InputDevice, struct synthhid_device_info *DeviceInfo) { int ret = 0; struct hid_descriptor *desc; struct mousevsc_prt_msg ack; /* Assume success for now */ - input_device->dev_info_status = 0; + InputDevice->DeviceInfoStatus = 0; /* Save the device attr */ - memcpy(&input_device->hid_dev_info, &device_info->hid_dev_info, - sizeof(struct hv_input_dev_info)); + memcpy(&InputDevice->hid_dev_info, &DeviceInfo->hid_dev_info, sizeof(struct hv_input_dev_info)); /* Save the hid desc */ - desc = &device_info->hid_descriptor; + desc = &DeviceInfo->hid_descriptor; WARN_ON(desc->bLength > 0); - input_device->hid_desc = kzalloc(desc->bLength, GFP_KERNEL); + InputDevice->HidDesc = kzalloc(desc->bLength, GFP_KERNEL); - if (!input_device->hid_desc) { + if (!InputDevice->HidDesc) { pr_err("unable to allocate hid descriptor - size %d", desc->bLength); goto Cleanup; } - memcpy(input_device->hid_desc, desc, desc->bLength); + memcpy(InputDevice->HidDesc, desc, desc->bLength); /* Save the report desc */ - input_device->report_desc_size = desc->desc[0].wDescriptorLength; - input_device->report_desc = kzalloc(input_device->report_desc_size, + InputDevice->ReportDescSize = desc->desc[0].wDescriptorLength; + InputDevice->ReportDesc = kzalloc(InputDevice->ReportDescSize, GFP_KERNEL); - if (!input_device->report_desc) { + if (!InputDevice->ReportDesc) { pr_err("unable to allocate report descriptor - size %d", - input_device->report_desc_size); + InputDevice->ReportDescSize); goto Cleanup; } - memcpy(input_device->report_desc, + memcpy(InputDevice->ReportDesc, ((unsigned char *)desc) + desc->bLength, desc->desc[0].wDescriptorLength); @@ -388,7 +385,7 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device, ack.ack.header.size = 1; ack.ack.reserved = 0; - ret = vmbus_sendpacket(input_device->device->channel, + ret = vmbus_sendpacket(InputDevice->Device->channel, &ack, sizeof(struct pipe_prt_msg) - sizeof(unsigned char) + sizeof(struct synthhid_device_info_ack), @@ -401,143 +398,138 @@ static void mousevsc_on_receive_device_info(struct mousevsc_dev *input_device, goto Cleanup; } - input_device->device_wait_condition = 1; - wake_up(&input_device->dev_info_wait_event); + InputDevice->device_wait_condition = 1; + wake_up(&InputDevice->DeviceInfoWaitEvent); return; Cleanup: - kfree(input_device->hid_desc); - input_device->hid_desc = NULL; + kfree(InputDevice->HidDesc); + InputDevice->HidDesc = NULL; - kfree(input_device->report_desc); - input_device->report_desc = NULL; + kfree(InputDevice->ReportDesc); + InputDevice->ReportDesc = NULL; - input_device->dev_info_status = -1; - input_device->device_wait_condition = 1; - wake_up(&input_device->dev_info_wait_event); + InputDevice->DeviceInfoStatus = -1; + InputDevice->device_wait_condition = 1; + wake_up(&InputDevice->DeviceInfoWaitEvent); } -static void mousevsc_on_receive_input_report(struct mousevsc_dev *input_device, - struct synthhid_input_report *input_report) +static void MousevscOnReceiveInputReport(struct mousevsc_dev *InputDevice, struct synthhid_input_report *InputReport) { - struct mousevsc_drv_obj *input_drv; + struct mousevsc_drv_obj *inputDriver; - if (!input_device->init_complete) { - pr_info("Initialization incomplete...ignoring input_report msg"); + if (!InputDevice->bInitializeComplete) { + pr_info("Initialization incomplete...ignoring InputReport msg"); return; } - input_drv = (struct mousevsc_drv_obj *)input_device->device->drv; + inputDriver = (struct mousevsc_drv_obj *)InputDevice->Device->drv; - inputreport_callback(input_device->device, - input_report->buffer, - input_report->header.size); + inputreport_callback(InputDevice->Device, + InputReport->buffer, + InputReport->header.size); } -static void mousevsc_on_receive(struct hv_device *device, - struct vmpacket_descriptor *packet) +static void MousevscOnReceive(struct hv_device *Device, struct vmpacket_descriptor *Packet) { - struct pipe_prt_msg *pipe_msg; - struct synthhid_msg *hid_msg; - struct mousevsc_dev *input_dev; + struct pipe_prt_msg *pipeMsg; + struct synthhid_msg *hidMsg; + struct mousevsc_dev *inputDevice; - input_dev = must_get_input_device(device); - if (!input_dev) { + inputDevice = MustGetInputDevice(Device); + if (!inputDevice) { pr_err("unable to get input device...device being destroyed?"); return; } - pipe_msg = (struct pipe_prt_msg *)((unsigned long)packet + - (packet->offset8 << 3)); + pipeMsg = (struct pipe_prt_msg *)((unsigned long)Packet + (Packet->offset8 << 3)); - if (pipe_msg->type != PipeMessageData) { + if (pipeMsg->type != PipeMessageData) { pr_err("unknown pipe msg type - type %d len %d", - pipe_msg->type, pipe_msg->size); - put_input_device(device); + pipeMsg->type, pipeMsg->size); + PutInputDevice(Device); return ; } - hid_msg = (struct synthhid_msg *)&pipe_msg->data[0]; + hidMsg = (struct synthhid_msg *)&pipeMsg->data[0]; - switch (hid_msg->header.type) { + switch (hidMsg->header.type) { case SynthHidProtocolResponse: - memcpy(&input_dev->protocol_resp, pipe_msg, - pipe_msg->size + sizeof(struct pipe_prt_msg) - + memcpy(&inputDevice->ProtocolResp, pipeMsg, + pipeMsg->size + sizeof(struct pipe_prt_msg) - sizeof(unsigned char)); - input_dev->protocol_wait_condition = 1; - wake_up(&input_dev->protocol_wait_event); + inputDevice->protocol_wait_condition = 1; + wake_up(&inputDevice->ProtocolWaitEvent); break; case SynthHidInitialDeviceInfo: - WARN_ON(pipe_msg->size >= sizeof(struct hv_input_dev_info)); + WARN_ON(pipeMsg->size >= sizeof(struct hv_input_dev_info)); /* * Parse out the device info into device attr, * hid desc and report desc */ - mousevsc_on_receive_device_info(input_dev, - (struct synthhid_device_info *)&pipe_msg->data[0]); + MousevscOnReceiveDeviceInfo(inputDevice, + (struct synthhid_device_info *)&pipeMsg->data[0]); break; case SynthHidInputReport: - mousevsc_on_receive_input_report(input_dev, - (struct synthhid_input_report *)&pipe_msg->data[0]); + MousevscOnReceiveInputReport(inputDevice, + (struct synthhid_input_report *)&pipeMsg->data[0]); break; default: pr_err("unsupported hid msg type - type %d len %d", - hid_msg->header.type, hid_msg->header.size); + hidMsg->header.type, hidMsg->header.size); break; } - put_input_device(device); + PutInputDevice(Device); } -static void mousevsc_on_channel_callback(void *context) +static void MousevscOnChannelCallback(void *Context) { const int packetSize = 0x100; int ret = 0; - struct hv_device *device = (struct hv_device *)context; - struct mousevsc_dev *input_dev; + struct hv_device *device = (struct hv_device *)Context; + struct mousevsc_dev *inputDevice; - u32 bytes_recvd; - u64 req_id; + u32 bytesRecvd; + u64 requestId; unsigned char packet[packetSize]; struct vmpacket_descriptor *desc; unsigned char *buffer = packet; int bufferlen = packetSize; - input_dev = must_get_input_device(device); + inputDevice = MustGetInputDevice(device); - if (!input_dev) { + if (!inputDevice) { pr_err("unable to get input device...device being destroyed?"); return; } do { - ret = vmbus_recvpacket_raw(device->channel, buffer, - bufferlen, &bytes_recvd, &req_id); + ret = vmbus_recvpacket_raw(device->channel, buffer, bufferlen, &bytesRecvd, &requestId); if (ret == 0) { - if (bytes_recvd > 0) { + if (bytesRecvd > 0) { desc = (struct vmpacket_descriptor *)buffer; switch (desc->type) { case VM_PKT_COMP: - mousevsc_on_send_completion( - device, desc); + MousevscOnSendCompletion(device, + desc); break; case VM_PKT_DATA_INBAND: - mousevsc_on_receive( - device, desc); + MousevscOnReceive(device, desc); break; default: pr_err("unhandled packet type %d, tid %llx len %d\n", desc->type, - req_id, - bytes_recvd); + requestId, + bytesRecvd); break; } @@ -563,8 +555,8 @@ static void mousevsc_on_channel_callback(void *context) } } else if (ret == -2) { /* Handle large packet */ - bufferlen = bytes_recvd; - buffer = kzalloc(bytes_recvd, GFP_KERNEL); + bufferlen = bytesRecvd; + buffer = kzalloc(bytesRecvd, GFP_KERNEL); if (buffer == NULL) { buffer = packet; @@ -572,35 +564,35 @@ static void mousevsc_on_channel_callback(void *context) /* Try again next time around */ pr_err("unable to allocate buffer of size %d!", - bytes_recvd); + bytesRecvd); break; } } } while (1); - put_input_device(device); + PutInputDevice(device); return; } -static int mousevsc_connect_to_vsp(struct hv_device *device) +static int MousevscConnectToVsp(struct hv_device *Device) { int ret = 0; - struct mousevsc_dev *input_dev; + struct mousevsc_dev *inputDevice; struct mousevsc_prt_msg *request; struct mousevsc_prt_msg *response; - input_dev = get_input_device(device); + inputDevice = GetInputDevice(Device); - if (!input_dev) { + if (!inputDevice) { pr_err("unable to get input device...device being destroyed?"); return -1; } - init_waitqueue_head(&input_dev->protocol_wait_event); - init_waitqueue_head(&input_dev->dev_info_wait_event); + init_waitqueue_head(&inputDevice->ProtocolWaitEvent); + init_waitqueue_head(&inputDevice->DeviceInfoWaitEvent); - request = &input_dev->protocol_req; + request = &inputDevice->ProtocolReq; /* * Now, initiate the vsc/vsp initialization protocol on the open channel @@ -616,7 +608,7 @@ static int mousevsc_connect_to_vsp(struct hv_device *device) pr_info("synthhid protocol request..."); - ret = vmbus_sendpacket(device->channel, request, + ret = vmbus_sendpacket(Device->channel, request, sizeof(struct pipe_prt_msg) - sizeof(unsigned char) + sizeof(struct synthhid_protocol_request), @@ -628,15 +620,14 @@ static int mousevsc_connect_to_vsp(struct hv_device *device) goto Cleanup; } - input_dev->protocol_wait_condition = 0; - wait_event_timeout(input_dev->protocol_wait_event, - input_dev->protocol_wait_condition, msecs_to_jiffies(1000)); - if (input_dev->protocol_wait_condition == 0) { + inputDevice->protocol_wait_condition = 0; + wait_event_timeout(inputDevice->ProtocolWaitEvent, inputDevice->protocol_wait_condition, msecs_to_jiffies(1000)); + if (inputDevice->protocol_wait_condition == 0) { ret = -ETIMEDOUT; goto Cleanup; } - response = &input_dev->protocol_resp; + response = &inputDevice->ProtocolResp; if (!response->response.approved) { pr_err("synthhid protocol request failed (version %d)", @@ -645,10 +636,9 @@ static int mousevsc_connect_to_vsp(struct hv_device *device) goto Cleanup; } - input_dev->device_wait_condition = 0; - wait_event_timeout(input_dev->dev_info_wait_event, - input_dev->device_wait_condition, msecs_to_jiffies(1000)); - if (input_dev->device_wait_condition == 0) { + inputDevice->device_wait_condition = 0; + wait_event_timeout(inputDevice->DeviceInfoWaitEvent, inputDevice->device_wait_condition, msecs_to_jiffies(1000)); + if (inputDevice->device_wait_condition == 0) { ret = -ETIMEDOUT; goto Cleanup; } @@ -657,95 +647,94 @@ static int mousevsc_connect_to_vsp(struct hv_device *device) * We should have gotten the device attr, hid desc and report * desc at this point */ - if (!input_dev->dev_info_status) + if (!inputDevice->DeviceInfoStatus) pr_info("**** input channel up and running!! ****"); else ret = -1; Cleanup: - put_input_device(device); + PutInputDevice(Device); return ret; } -static int mousevsc_on_device_add(struct hv_device *device, - void *additional_info) +static int MousevscOnDeviceAdd(struct hv_device *Device, void *AdditionalInfo) { int ret = 0; - struct mousevsc_dev *input_dev; - struct mousevsc_drv_obj *input_drv; + struct mousevsc_dev *inputDevice; + struct mousevsc_drv_obj *inputDriver; struct hv_input_dev_info dev_info; - input_dev = alloc_input_device(device); + inputDevice = AllocInputDevice(Device); - if (!input_dev) { + if (!inputDevice) { ret = -1; goto Cleanup; } - input_dev->init_complete = false; + inputDevice->bInitializeComplete = false; /* Open the channel */ - ret = vmbus_open(device->channel, + ret = vmbus_open(Device->channel, INPUTVSC_SEND_RING_BUFFER_SIZE, INPUTVSC_RECV_RING_BUFFER_SIZE, NULL, 0, - mousevsc_on_channel_callback, - device + MousevscOnChannelCallback, + Device ); if (ret != 0) { pr_err("unable to open channel: %d", ret); - free_input_device(input_dev); + FreeInputDevice(inputDevice); return -1; } pr_info("InputVsc channel open: %d", ret); - ret = mousevsc_connect_to_vsp(device); + ret = MousevscConnectToVsp(Device); if (ret != 0) { pr_err("unable to connect channel: %d", ret); - vmbus_close(device->channel); - free_input_device(input_dev); + vmbus_close(Device->channel); + FreeInputDevice(inputDevice); return ret; } - input_drv = (struct mousevsc_drv_obj *)input_dev->device->drv; + inputDriver = (struct mousevsc_drv_obj *)inputDevice->Device->drv; - dev_info.vendor = input_dev->hid_dev_info.vendor; - dev_info.product = input_dev->hid_dev_info.product; - dev_info.version = input_dev->hid_dev_info.version; + dev_info.vendor = inputDevice->hid_dev_info.vendor; + dev_info.product = inputDevice->hid_dev_info.product; + dev_info.version = inputDevice->hid_dev_info.version; strcpy(dev_info.name, "Microsoft Vmbus HID-compliant Mouse"); /* Send the device info back up */ - deviceinfo_callback(device, &dev_info); + deviceinfo_callback(Device, &dev_info); /* Send the report desc back up */ /* workaround SA-167 */ - if (input_dev->report_desc[14] == 0x25) - input_dev->report_desc[14] = 0x29; + if (inputDevice->ReportDesc[14] == 0x25) + inputDevice->ReportDesc[14] = 0x29; - reportdesc_callback(device, input_dev->report_desc, - input_dev->report_desc_size); + reportdesc_callback(Device, inputDevice->ReportDesc, + inputDevice->ReportDescSize); - input_dev->init_complete = true; + inputDevice->bInitializeComplete = true; Cleanup: return ret; } -static int mousevsc_on_device_remove(struct hv_device *device) +static int MousevscOnDeviceRemove(struct hv_device *Device) { - struct mousevsc_dev *input_dev; + struct mousevsc_dev *inputDevice; int ret = 0; pr_info("disabling input device (%p)...", - device->ext); + Device->ext); - input_dev = release_input_device(device); + inputDevice = ReleaseInputDevice(Device); /* @@ -754,28 +743,27 @@ static int mousevsc_on_device_remove(struct hv_device *device) * * so that outstanding requests can be completed. */ - while (input_dev->num_outstanding_req) { - pr_info("waiting for %d requests to complete...", - input_dev->num_outstanding_req); + while (inputDevice->NumOutstandingRequests) { + pr_info("waiting for %d requests to complete...", inputDevice->NumOutstandingRequests); udelay(100); } - pr_info("removing input device (%p)...", device->ext); + pr_info("removing input device (%p)...", Device->ext); - input_dev = final_release_input_device(device); + inputDevice = FinalReleaseInputDevice(Device); - pr_info("input device (%p) safe to remove", input_dev); + pr_info("input device (%p) safe to remove", inputDevice); /* Close the channel */ - vmbus_close(device->channel); + vmbus_close(Device->channel); - free_input_device(input_dev); + FreeInputDevice(inputDevice); return ret; } -static void mousevsc_on_cleanup(struct hv_driver *drv) +static void MousevscOnCleanup(struct hv_driver *drv) { } @@ -842,7 +830,7 @@ static int mousevsc_probe(struct device *device) dev_set_drvdata(device, input_dev_ctx); /* Call to the vsc driver to add the device */ - ret = mousevsc_drv_obj->base.dev_add(device_obj, NULL); + ret = mousevsc_drv_obj->Base.dev_add(device_obj, NULL); if (ret != 0) { DPRINT_ERR(INPUTVSC_DRV, "unable to add input vsc device"); @@ -874,14 +862,14 @@ static int mousevsc_remove(struct device *device) input_dev_ctx->connected = 0; } - if (!mousevsc_drv_obj->base.dev_rm) + if (!mousevsc_drv_obj->Base.dev_rm) return -1; /* * Call to the vsc driver to let it know that the device * is being removed */ - ret = mousevsc_drv_obj->base.dev_rm(device_obj); + ret = mousevsc_drv_obj->Base.dev_rm(device_obj); if (ret != 0) { DPRINT_ERR(INPUTVSC_DRV, @@ -957,7 +945,7 @@ static int mousevsc_drv_exit_cb(struct device *dev, void *data) static void mousevsc_drv_exit(void) { struct mousevsc_drv_obj *mousevsc_drv_obj = &g_mousevsc_drv; - struct hv_driver *drv = &g_mousevsc_drv.base; + struct hv_driver *drv = &g_mousevsc_drv.Base; int ret; struct device *current_dev = NULL; @@ -979,28 +967,28 @@ static void mousevsc_drv_exit(void) device_unregister(current_dev); } - if (mousevsc_drv_obj->base.cleanup) - mousevsc_drv_obj->base.cleanup(&mousevsc_drv_obj->base); + if (mousevsc_drv_obj->Base.cleanup) + mousevsc_drv_obj->Base.cleanup(&mousevsc_drv_obj->Base); vmbus_child_driver_unregister(&drv->driver); return; } -static int mouse_vsc_initialize(struct hv_driver *driver) +static int mouse_vsc_initialize(struct hv_driver *Driver) { - struct mousevsc_drv_obj *input_drv = - (struct mousevsc_drv_obj *)driver; + struct mousevsc_drv_obj *inputDriver = + (struct mousevsc_drv_obj *)Driver; int ret = 0; - driver->name = driver_name; - memcpy(&driver->dev_type, &mouse_guid, + Driver->name = driver_name; + memcpy(&Driver->dev_type, &mouse_guid, sizeof(struct hv_guid)); /* Setup the dispatch table */ - input_drv->base.dev_add = mousevsc_on_device_add; - input_drv->base.dev_rm = mousevsc_on_device_remove; - input_drv->base.cleanup = mousevsc_on_cleanup; + inputDriver->Base.dev_add = MousevscOnDeviceAdd; + inputDriver->Base.dev_rm = MousevscOnDeviceRemove; + inputDriver->Base.cleanup = MousevscOnCleanup; return ret; } @@ -1009,14 +997,14 @@ static int mouse_vsc_initialize(struct hv_driver *driver) static int __init mousevsc_init(void) { struct mousevsc_drv_obj *input_drv_obj = &g_mousevsc_drv; - struct hv_driver *drv = &g_mousevsc_drv.base; + struct hv_driver *drv = &g_mousevsc_drv.Base; DPRINT_INFO(INPUTVSC_DRV, "Hyper-V Mouse driver initializing."); /* Callback to client driver to complete the initialization */ - mouse_vsc_initialize(&input_drv_obj->base); + mouse_vsc_initialize(&input_drv_obj->Base); - drv->driver.name = input_drv_obj->base.name; + drv->driver.name = input_drv_obj->Base.name; drv->priv = input_drv_obj; drv->driver.probe = mousevsc_probe; diff --git a/trunk/drivers/staging/hv/hv_timesource.c b/trunk/drivers/staging/hv/hv_timesource.c index 0efb04915255..a7ee533303b4 100644 --- a/trunk/drivers/staging/hv/hv_timesource.c +++ b/trunk/drivers/staging/hv/hv_timesource.c @@ -20,7 +20,6 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include #include @@ -92,7 +91,7 @@ static int __init init_hv_clocksource(void) if (!dmi_check_system(hv_timesource_dmi_table)) return -ENODEV; - pr_info("Registering HyperV clock source\n"); + printk(KERN_INFO "Registering HyperV clock source\n"); return clocksource_register(&hyperv_cs); } diff --git a/trunk/drivers/staging/hv/hv_util.c b/trunk/drivers/staging/hv/hv_util.c index 8038589e2c05..2df15683f8fa 100644 --- a/trunk/drivers/staging/hv/hv_util.c +++ b/trunk/drivers/staging/hv/hv_util.c @@ -18,8 +18,6 @@ * Haiyang Zhang * Hank Janssen */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -61,6 +59,9 @@ static void shutdown_onchannelcallback(void *context) PAGE_SIZE, &recvlen, &requestid); if (recvlen > 0) { + DPRINT_DBG(VMBUS, "shutdown packet: len=%d, requestid=%lld", + recvlen, requestid); + icmsghdrp = (struct icmsg_hdr *)&shut_txf_buf[ sizeof(struct vmbuspipe_hdr)]; @@ -78,15 +79,15 @@ static void shutdown_onchannelcallback(void *context) icmsghdrp->status = HV_S_OK; execute_shutdown = true; - pr_info("Shutdown request received -" - " graceful shutdown initiated\n"); + DPRINT_INFO(VMBUS, "Shutdown request received -" + " graceful shutdown initiated"); break; default: icmsghdrp->status = HV_E_FAIL; execute_shutdown = false; - pr_info("Shutdown request received -" - " Invalid request\n"); + DPRINT_INFO(VMBUS, "Shutdown request received -" + " Invalid request"); break; }; } @@ -158,6 +159,9 @@ static void timesync_onchannelcallback(void *context) PAGE_SIZE, &recvlen, &requestid); if (recvlen > 0) { + DPRINT_DBG(VMBUS, "timesync packet: recvlen=%d, requestid=%lld", + recvlen, requestid); + icmsghdrp = (struct icmsg_hdr *)&time_txf_buf[ sizeof(struct vmbuspipe_hdr)]; @@ -196,6 +200,9 @@ static void heartbeat_onchannelcallback(void *context) PAGE_SIZE, &recvlen, &requestid); if (recvlen > 0) { + DPRINT_DBG(VMBUS, "heartbeat packet: len=%d, requestid=%lld", + recvlen, requestid); + icmsghdrp = (struct icmsg_hdr *)&hbeat_txf_buf[ sizeof(struct vmbuspipe_hdr)]; @@ -207,6 +214,9 @@ static void heartbeat_onchannelcallback(void *context) sizeof(struct vmbuspipe_hdr) + sizeof(struct icmsg_hdr)]; + DPRINT_DBG(VMBUS, "heartbeat seq = %lld", + heartbeat_msg->seq_num); + heartbeat_msg->seq_num += 1; } @@ -244,7 +254,7 @@ MODULE_DEVICE_TABLE(dmi, hv_utils_dmi_table); static int __init init_hyperv_utils(void) { - pr_info("Registering HyperV Utility Driver\n"); + printk(KERN_INFO "Registering HyperV Utility Driver\n"); if (hv_kvp_init()) return -ENODEV; @@ -258,7 +268,8 @@ static int __init init_hyperv_utils(void) hbeat_txf_buf = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!shut_txf_buf || !time_txf_buf || !hbeat_txf_buf) { - pr_info("Unable to allocate memory for receive buffer\n"); + printk(KERN_INFO + "Unable to allocate memory for receive buffer\n"); kfree(shut_txf_buf); kfree(time_txf_buf); kfree(hbeat_txf_buf); @@ -287,7 +298,7 @@ static int __init init_hyperv_utils(void) static void exit_hyperv_utils(void) { - pr_info("De-Registered HyperV Utility Driver\n"); + printk(KERN_INFO "De-Registered HyperV Utility Driver\n"); hv_cb_utils[HV_SHUTDOWN_MSG].channel->onchannel_callback = &chn_cb_negotiate; diff --git a/trunk/drivers/staging/hv/netvsc.c b/trunk/drivers/staging/hv/netvsc.c index b3e649785ceb..20b159775e88 100644 --- a/trunk/drivers/staging/hv/netvsc.c +++ b/trunk/drivers/staging/hv/netvsc.c @@ -18,8 +18,6 @@ * Haiyang Zhang * Hank Janssen */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -45,6 +43,38 @@ static const struct hv_guid netvsc_device_type = { } }; +static int netvsc_device_add(struct hv_device *device, void *additional_info); + +static int netvsc_device_remove(struct hv_device *device); + +static void netvsc_cleanup(struct hv_driver *driver); + +static void netvsc_channel_cb(void *context); + +static int netvsc_init_send_buf(struct hv_device *device); + +static int netvsc_init_recv_buf(struct hv_device *device); + +static int netvsc_destroy_send_buf(struct netvsc_device *net_device); + +static int netvsc_destroy_recv_buf(struct netvsc_device *net_device); + +static int netvsc_connect_vsp(struct hv_device *device); + +static void netvsc_send_completion(struct hv_device *device, + struct vmpacket_descriptor *packet); + +static int netvsc_send(struct hv_device *device, + struct hv_netvsc_packet *packet); + +static void netvsc_receive(struct hv_device *device, + struct vmpacket_descriptor *packet); + +static void netvsc_receive_completion(void *context); + +static void netvsc_send_recv_completion(struct hv_device *device, + u64 transaction_id); + static struct netvsc_device *alloc_net_device(struct hv_device *device) { @@ -141,73 +171,32 @@ static struct netvsc_device *release_inbound_net_device( return net_device; } -static int netvsc_destroy_recv_buf(struct netvsc_device *net_device) +/* + * netvsc_initialize - Main entry point + */ +int netvsc_initialize(struct hv_driver *drv) { - struct nvsp_message *revoke_packet; - int ret = 0; - - /* - * If we got a section count, it means we received a - * SendReceiveBufferComplete msg (ie sent - * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need - * to send a revoke msg here - */ - if (net_device->recv_section_cnt) { - /* Send the revoke receive buffer */ - revoke_packet = &net_device->revoke_packet; - memset(revoke_packet, 0, sizeof(struct nvsp_message)); - - revoke_packet->hdr.msg_type = - NVSP_MSG1_TYPE_REVOKE_RECV_BUF; - revoke_packet->msg.v1_msg. - revoke_recv_buf.id = NETVSC_RECEIVE_BUFFER_ID; - - ret = vmbus_sendpacket(net_device->dev->channel, - revoke_packet, - sizeof(struct nvsp_message), - (unsigned long)revoke_packet, - VM_PKT_DATA_INBAND, 0); - /* - * If we failed here, we might as well return and - * have a leak rather than continue and a bugchk - */ - if (ret != 0) { - dev_err(&net_device->dev->device, "unable to send " - "revoke receive buffer to netvsp"); - return -1; - } - } + struct netvsc_driver *driver = (struct netvsc_driver *)drv; - /* Teardown the gpadl on the vsp end */ - if (net_device->recv_buf_gpadl_handle) { - ret = vmbus_teardown_gpadl(net_device->dev->channel, - net_device->recv_buf_gpadl_handle); + DPRINT_DBG(NETVSC, "sizeof(struct hv_netvsc_packet)=%zd, " + "sizeof(struct nvsp_message)=%zd, " + "sizeof(struct vmtransfer_page_packet_header)=%zd", + sizeof(struct hv_netvsc_packet), + sizeof(struct nvsp_message), + sizeof(struct vmtransfer_page_packet_header)); - /* If we failed here, we might as well return and have a leak - * rather than continue and a bugchk - */ - if (ret != 0) { - dev_err(&net_device->dev->device, - "unable to teardown receive buffer's gpadl"); - return -1; - } - net_device->recv_buf_gpadl_handle = 0; - } + drv->name = driver_name; + memcpy(&drv->dev_type, &netvsc_device_type, sizeof(struct hv_guid)); - if (net_device->recv_buf) { - /* Free up the receive buffer */ - free_pages((unsigned long)net_device->recv_buf, - get_order(net_device->recv_buf_size)); - net_device->recv_buf = NULL; - } + /* Setup the dispatch table */ + driver->base.dev_add = netvsc_device_add; + driver->base.dev_rm = netvsc_device_remove; + driver->base.cleanup = netvsc_cleanup; - if (net_device->recv_section) { - net_device->recv_section_cnt = 0; - kfree(net_device->recv_section); - net_device->recv_section = NULL; - } + driver->send = netvsc_send; - return ret; + rndis_filter_init(driver); + return 0; } static int netvsc_init_recv_buf(struct hv_device *device) @@ -218,7 +207,7 @@ static int netvsc_init_recv_buf(struct hv_device *device) net_device = get_outbound_net_device(device); if (!net_device) { - dev_err(&device->device, "unable to get net device..." + DPRINT_ERR(NETVSC, "unable to get net device..." "device being destroyed?"); return -1; } @@ -227,12 +216,15 @@ static int netvsc_init_recv_buf(struct hv_device *device) (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, get_order(net_device->recv_buf_size)); if (!net_device->recv_buf) { - dev_err(&device->device, "unable to allocate receive " - "buffer of size %d", net_device->recv_buf_size); + DPRINT_ERR(NETVSC, + "unable to allocate receive buffer of size %d", + net_device->recv_buf_size); ret = -1; goto cleanup; } + DPRINT_INFO(NETVSC, "Establishing receive buffer's GPADL..."); + /* * Establish the gpadl handle for this buffer on this * channel. Note: This call uses the vmbus connection rather @@ -242,13 +234,15 @@ static int netvsc_init_recv_buf(struct hv_device *device) net_device->recv_buf_size, &net_device->recv_buf_gpadl_handle); if (ret != 0) { - dev_err(&device->device, - "unable to establish receive buffer's gpadl"); + DPRINT_ERR(NETVSC, + "unable to establish receive buffer's gpadl"); goto cleanup; } /* Notify the NetVsp of the gpadl handle */ + DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendReceiveBuffer..."); + init_packet = &net_device->channel_init_pkt; memset(init_packet, 0, sizeof(struct nvsp_message)); @@ -267,8 +261,8 @@ static int netvsc_init_recv_buf(struct hv_device *device) VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { - dev_err(&device->device, - "unable to send receive buffer's gpadl to netvsp"); + DPRINT_ERR(NETVSC, + "unable to send receive buffer's gpadl to netvsp"); goto cleanup; } @@ -281,7 +275,7 @@ static int netvsc_init_recv_buf(struct hv_device *device) /* Check the response */ if (init_packet->msg.v1_msg. send_recv_buf_complete.status != NVSP_STAT_SUCCESS) { - dev_err(&device->device, "Unable to complete receive buffer " + DPRINT_ERR(NETVSC, "Unable to complete receive buffer " "initialzation with NetVsp - status %d", init_packet->msg.v1_msg. send_recv_buf_complete.status); @@ -307,6 +301,14 @@ static int netvsc_init_recv_buf(struct hv_device *device) net_device->recv_section_cnt * sizeof(struct nvsp_1_receive_buffer_section)); + DPRINT_INFO(NETVSC, "Receive sections info (count %d, offset %d, " + "endoffset %d, suballoc size %d, num suballocs %d)", + net_device->recv_section_cnt, + net_device->recv_section[0].offset, + net_device->recv_section[0].end_offset, + net_device->recv_section[0].sub_alloc_size, + net_device->recv_section[0].num_sub_allocs); + /* * For 1st release, there should only be 1 section that represents the * entire receive buffer @@ -327,70 +329,6 @@ static int netvsc_init_recv_buf(struct hv_device *device) return ret; } -static int netvsc_destroy_send_buf(struct netvsc_device *net_device) -{ - struct nvsp_message *revoke_packet; - int ret = 0; - - /* - * If we got a section count, it means we received a - * SendReceiveBufferComplete msg (ie sent - * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need - * to send a revoke msg here - */ - if (net_device->send_section_size) { - /* Send the revoke send buffer */ - revoke_packet = &net_device->revoke_packet; - memset(revoke_packet, 0, sizeof(struct nvsp_message)); - - revoke_packet->hdr.msg_type = - NVSP_MSG1_TYPE_REVOKE_SEND_BUF; - revoke_packet->msg.v1_msg. - revoke_send_buf.id = NETVSC_SEND_BUFFER_ID; - - ret = vmbus_sendpacket(net_device->dev->channel, - revoke_packet, - sizeof(struct nvsp_message), - (unsigned long)revoke_packet, - VM_PKT_DATA_INBAND, 0); - /* - * If we failed here, we might as well return and have a leak - * rather than continue and a bugchk - */ - if (ret != 0) { - dev_err(&net_device->dev->device, "unable to send " - "revoke send buffer to netvsp"); - return -1; - } - } - - /* Teardown the gpadl on the vsp end */ - if (net_device->send_buf_gpadl_handle) { - ret = vmbus_teardown_gpadl(net_device->dev->channel, - net_device->send_buf_gpadl_handle); - - /* - * If we failed here, we might as well return and have a leak - * rather than continue and a bugchk - */ - if (ret != 0) { - dev_err(&net_device->dev->device, - "unable to teardown send buffer's gpadl"); - return -1; - } - net_device->send_buf_gpadl_handle = 0; - } - - if (net_device->send_buf) { - /* Free up the receive buffer */ - free_pages((unsigned long)net_device->send_buf, - get_order(net_device->send_buf_size)); - net_device->send_buf = NULL; - } - - return ret; -} - static int netvsc_init_send_buf(struct hv_device *device) { int ret = 0; @@ -399,7 +337,7 @@ static int netvsc_init_send_buf(struct hv_device *device) net_device = get_outbound_net_device(device); if (!net_device) { - dev_err(&device->device, "unable to get net device..." + DPRINT_ERR(NETVSC, "unable to get net device..." "device being destroyed?"); return -1; } @@ -412,12 +350,14 @@ static int netvsc_init_send_buf(struct hv_device *device) (void *)__get_free_pages(GFP_KERNEL|__GFP_ZERO, get_order(net_device->send_buf_size)); if (!net_device->send_buf) { - dev_err(&device->device, "unable to allocate send " - "buffer of size %d", net_device->send_buf_size); + DPRINT_ERR(NETVSC, "unable to allocate send buffer of size %d", + net_device->send_buf_size); ret = -1; goto cleanup; } + DPRINT_INFO(NETVSC, "Establishing send buffer's GPADL..."); + /* * Establish the gpadl handle for this buffer on this * channel. Note: This call uses the vmbus connection rather @@ -427,11 +367,13 @@ static int netvsc_init_send_buf(struct hv_device *device) net_device->send_buf_size, &net_device->send_buf_gpadl_handle); if (ret != 0) { - dev_err(&device->device, "unable to establish send buffer's gpadl"); + DPRINT_ERR(NETVSC, "unable to establish send buffer's gpadl"); goto cleanup; } /* Notify the NetVsp of the gpadl handle */ + DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendSendBuffer..."); + init_packet = &net_device->channel_init_pkt; memset(init_packet, 0, sizeof(struct nvsp_message)); @@ -450,7 +392,7 @@ static int netvsc_init_send_buf(struct hv_device *device) VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); if (ret != 0) { - dev_err(&device->device, + DPRINT_ERR(NETVSC, "unable to send receive buffer's gpadl to netvsp"); goto cleanup; } @@ -463,7 +405,7 @@ static int netvsc_init_send_buf(struct hv_device *device) /* Check the response */ if (init_packet->msg.v1_msg. send_send_buf_complete.status != NVSP_STAT_SUCCESS) { - dev_err(&device->device, "Unable to complete send buffer " + DPRINT_ERR(NETVSC, "Unable to complete send buffer " "initialzation with NetVsp - status %d", init_packet->msg.v1_msg. send_send_buf_complete.status); @@ -484,69 +426,231 @@ static int netvsc_init_send_buf(struct hv_device *device) return ret; } - -static int netvsc_connect_vsp(struct hv_device *device) +static int netvsc_destroy_recv_buf(struct netvsc_device *net_device) { - int ret; - struct netvsc_device *net_device; - struct nvsp_message *init_packet; - int ndis_version; + struct nvsp_message *revoke_packet; + int ret = 0; - net_device = get_outbound_net_device(device); - if (!net_device) { - dev_err(&device->device, "unable to get net device..." - "device being destroyed?"); - return -1; - } + /* + * If we got a section count, it means we received a + * SendReceiveBufferComplete msg (ie sent + * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need + * to send a revoke msg here + */ + if (net_device->recv_section_cnt) { + DPRINT_INFO(NETVSC, + "Sending NvspMessage1TypeRevokeReceiveBuffer..."); - init_packet = &net_device->channel_init_pkt; + /* Send the revoke receive buffer */ + revoke_packet = &net_device->revoke_packet; + memset(revoke_packet, 0, sizeof(struct nvsp_message)); - memset(init_packet, 0, sizeof(struct nvsp_message)); - init_packet->hdr.msg_type = NVSP_MSG_TYPE_INIT; - init_packet->msg.init_msg.init.min_protocol_ver = - NVSP_MIN_PROTOCOL_VERSION; - init_packet->msg.init_msg.init.max_protocol_ver = - NVSP_MAX_PROTOCOL_VERSION; + revoke_packet->hdr.msg_type = + NVSP_MSG1_TYPE_REVOKE_RECV_BUF; + revoke_packet->msg.v1_msg. + revoke_recv_buf.id = NETVSC_RECEIVE_BUFFER_ID; - /* Send the init request */ - net_device->wait_condition = 0; - ret = vmbus_sendpacket(device->channel, init_packet, - sizeof(struct nvsp_message), - (unsigned long)init_packet, - VM_PKT_DATA_INBAND, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + ret = vmbus_sendpacket(net_device->dev->channel, + revoke_packet, + sizeof(struct nvsp_message), + (unsigned long)revoke_packet, + VM_PKT_DATA_INBAND, 0); + /* + * If we failed here, we might as well return and + * have a leak rather than continue and a bugchk + */ + if (ret != 0) { + DPRINT_ERR(NETVSC, "unable to send revoke receive " + "buffer to netvsp"); + return -1; + } + } - if (ret != 0) - goto cleanup; + /* Teardown the gpadl on the vsp end */ + if (net_device->recv_buf_gpadl_handle) { + DPRINT_INFO(NETVSC, "Tearing down receive buffer's GPADL..."); - wait_event_timeout(net_device->channel_init_wait, - net_device->wait_condition, - msecs_to_jiffies(1000)); - if (net_device->wait_condition == 0) { - ret = -ETIMEDOUT; - goto cleanup; + ret = vmbus_teardown_gpadl(net_device->dev->channel, + net_device->recv_buf_gpadl_handle); + + /* If we failed here, we might as well return and have a leak rather than continue and a bugchk */ + if (ret != 0) { + DPRINT_ERR(NETVSC, + "unable to teardown receive buffer's gpadl"); + return -1; + } + net_device->recv_buf_gpadl_handle = 0; } - if (init_packet->msg.init_msg.init_complete.status != - NVSP_STAT_SUCCESS) { - ret = -1; - goto cleanup; + if (net_device->recv_buf) { + DPRINT_INFO(NETVSC, "Freeing up receive buffer..."); + + /* Free up the receive buffer */ + free_pages((unsigned long)net_device->recv_buf, + get_order(net_device->recv_buf_size)); + net_device->recv_buf = NULL; } - if (init_packet->msg.init_msg.init_complete. - negotiated_protocol_ver != NVSP_PROTOCOL_VERSION_1) { - ret = -1; - goto cleanup; + if (net_device->recv_section) { + net_device->recv_section_cnt = 0; + kfree(net_device->recv_section); + net_device->recv_section = NULL; } - /* Send the ndis version */ - memset(init_packet, 0, sizeof(struct nvsp_message)); - ndis_version = 0x00050000; + return ret; +} - init_packet->hdr.msg_type = NVSP_MSG1_TYPE_SEND_NDIS_VER; - init_packet->msg.v1_msg. - send_ndis_ver.ndis_major_ver = - (ndis_version & 0xFFFF0000) >> 16; +static int netvsc_destroy_send_buf(struct netvsc_device *net_device) +{ + struct nvsp_message *revoke_packet; + int ret = 0; + + /* + * If we got a section count, it means we received a + * SendReceiveBufferComplete msg (ie sent + * NvspMessage1TypeSendReceiveBuffer msg) therefore, we need + * to send a revoke msg here + */ + if (net_device->send_section_size) { + DPRINT_INFO(NETVSC, + "Sending NvspMessage1TypeRevokeSendBuffer..."); + + /* Send the revoke send buffer */ + revoke_packet = &net_device->revoke_packet; + memset(revoke_packet, 0, sizeof(struct nvsp_message)); + + revoke_packet->hdr.msg_type = + NVSP_MSG1_TYPE_REVOKE_SEND_BUF; + revoke_packet->msg.v1_msg. + revoke_send_buf.id = NETVSC_SEND_BUFFER_ID; + + ret = vmbus_sendpacket(net_device->dev->channel, + revoke_packet, + sizeof(struct nvsp_message), + (unsigned long)revoke_packet, + VM_PKT_DATA_INBAND, 0); + /* + * If we failed here, we might as well return and have a leak + * rather than continue and a bugchk + */ + if (ret != 0) { + DPRINT_ERR(NETVSC, "unable to send revoke send buffer " + "to netvsp"); + return -1; + } + } + + /* Teardown the gpadl on the vsp end */ + if (net_device->send_buf_gpadl_handle) { + DPRINT_INFO(NETVSC, "Tearing down send buffer's GPADL..."); + ret = vmbus_teardown_gpadl(net_device->dev->channel, + net_device->send_buf_gpadl_handle); + + /* + * If we failed here, we might as well return and have a leak + * rather than continue and a bugchk + */ + if (ret != 0) { + DPRINT_ERR(NETVSC, "unable to teardown send buffer's " + "gpadl"); + return -1; + } + net_device->send_buf_gpadl_handle = 0; + } + + if (net_device->send_buf) { + DPRINT_INFO(NETVSC, "Freeing up send buffer..."); + + /* Free up the receive buffer */ + free_pages((unsigned long)net_device->send_buf, + get_order(net_device->send_buf_size)); + net_device->send_buf = NULL; + } + + return ret; +} + + +static int netvsc_connect_vsp(struct hv_device *device) +{ + int ret; + struct netvsc_device *net_device; + struct nvsp_message *init_packet; + int ndis_version; + + net_device = get_outbound_net_device(device); + if (!net_device) { + DPRINT_ERR(NETVSC, "unable to get net device..." + "device being destroyed?"); + return -1; + } + + init_packet = &net_device->channel_init_pkt; + + memset(init_packet, 0, sizeof(struct nvsp_message)); + init_packet->hdr.msg_type = NVSP_MSG_TYPE_INIT; + init_packet->msg.init_msg.init.min_protocol_ver = + NVSP_MIN_PROTOCOL_VERSION; + init_packet->msg.init_msg.init.max_protocol_ver = + NVSP_MAX_PROTOCOL_VERSION; + + DPRINT_INFO(NETVSC, "Sending NvspMessageTypeInit..."); + + /* Send the init request */ + net_device->wait_condition = 0; + ret = vmbus_sendpacket(device->channel, init_packet, + sizeof(struct nvsp_message), + (unsigned long)init_packet, + VM_PKT_DATA_INBAND, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + + if (ret != 0) { + DPRINT_ERR(NETVSC, "unable to send NvspMessageTypeInit"); + goto cleanup; + } + + wait_event_timeout(net_device->channel_init_wait, + net_device->wait_condition, + msecs_to_jiffies(1000)); + if (net_device->wait_condition == 0) { + ret = -ETIMEDOUT; + goto cleanup; + } + + DPRINT_INFO(NETVSC, "NvspMessageTypeInit status(%d) max mdl chain (%d)", + init_packet->msg.init_msg.init_complete.status, + init_packet->msg.init_msg. + init_complete.max_mdl_chain_len); + + if (init_packet->msg.init_msg.init_complete.status != + NVSP_STAT_SUCCESS) { + DPRINT_ERR(NETVSC, + "unable to initialize with netvsp (status 0x%x)", + init_packet->msg.init_msg.init_complete.status); + ret = -1; + goto cleanup; + } + + if (init_packet->msg.init_msg.init_complete. + negotiated_protocol_ver != NVSP_PROTOCOL_VERSION_1) { + DPRINT_ERR(NETVSC, "unable to initialize with netvsp " + "(version expected 1 got %d)", + init_packet->msg.init_msg. + init_complete.negotiated_protocol_ver); + ret = -1; + goto cleanup; + } + DPRINT_INFO(NETVSC, "Sending NvspMessage1TypeSendNdisVersion..."); + + /* Send the ndis version */ + memset(init_packet, 0, sizeof(struct nvsp_message)); + + ndis_version = 0x00050000; + + init_packet->hdr.msg_type = NVSP_MSG1_TYPE_SEND_NDIS_VER; + init_packet->msg.v1_msg. + send_ndis_ver.ndis_major_ver = + (ndis_version & 0xFFFF0000) >> 16; init_packet->msg.v1_msg. send_ndis_ver.ndis_minor_ver = ndis_version & 0xFFFF; @@ -557,6 +661,8 @@ static int netvsc_connect_vsp(struct hv_device *device) (unsigned long)init_packet, VM_PKT_DATA_INBAND, 0); if (ret != 0) { + DPRINT_ERR(NETVSC, + "unable to send NvspMessage1TypeSendNdisVersion"); ret = -1; goto cleanup; } @@ -571,12 +677,106 @@ static int netvsc_connect_vsp(struct hv_device *device) return ret; } -static void netvsc_disconnect_vsp(struct netvsc_device *net_device) +static void NetVscDisconnectFromVsp(struct netvsc_device *net_device) { netvsc_destroy_recv_buf(net_device); netvsc_destroy_send_buf(net_device); } +/* + * netvsc_device_add - Callback when the device belonging to this + * driver is added + */ +static int netvsc_device_add(struct hv_device *device, void *additional_info) +{ + int ret = 0; + int i; + struct netvsc_device *net_device; + struct hv_netvsc_packet *packet, *pos; + struct netvsc_driver *net_driver = + (struct netvsc_driver *)device->drv; + + net_device = alloc_net_device(device); + if (!net_device) { + ret = -1; + goto cleanup; + } + + DPRINT_DBG(NETVSC, "netvsc channel object allocated - %p", net_device); + + /* Initialize the NetVSC channel extension */ + net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE; + spin_lock_init(&net_device->recv_pkt_list_lock); + + net_device->send_buf_size = NETVSC_SEND_BUFFER_SIZE; + + INIT_LIST_HEAD(&net_device->recv_pkt_list); + + for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) { + packet = kzalloc(sizeof(struct hv_netvsc_packet) + + (NETVSC_RECEIVE_SG_COUNT * + sizeof(struct hv_page_buffer)), GFP_KERNEL); + if (!packet) { + DPRINT_DBG(NETVSC, "unable to allocate netvsc pkts " + "for receive pool (wanted %d got %d)", + NETVSC_RECEIVE_PACKETLIST_COUNT, i); + break; + } + list_add_tail(&packet->list_ent, + &net_device->recv_pkt_list); + } + init_waitqueue_head(&net_device->channel_init_wait); + + /* Open the channel */ + ret = vmbus_open(device->channel, net_driver->ring_buf_size, + net_driver->ring_buf_size, NULL, 0, + netvsc_channel_cb, device); + + if (ret != 0) { + DPRINT_ERR(NETVSC, "unable to open channel: %d", ret); + ret = -1; + goto cleanup; + } + + /* Channel is opened */ + DPRINT_INFO(NETVSC, "*** NetVSC channel opened successfully! ***"); + + /* Connect with the NetVsp */ + ret = netvsc_connect_vsp(device); + if (ret != 0) { + DPRINT_ERR(NETVSC, "unable to connect to NetVSP - %d", ret); + ret = -1; + goto close; + } + + DPRINT_INFO(NETVSC, "*** NetVSC channel handshake result - %d ***", + ret); + + return ret; + +close: + /* Now, we can close the channel safely */ + vmbus_close(device->channel); + +cleanup: + + if (net_device) { + list_for_each_entry_safe(packet, pos, + &net_device->recv_pkt_list, + list_ent) { + list_del(&packet->list_ent); + kfree(packet); + } + + release_outbound_net_device(device); + release_inbound_net_device(device); + + free_net_device(net_device); + } + + return ret; +} + /* * netvsc_device_remove - Callback when the root bus device is removed */ @@ -585,28 +785,35 @@ static int netvsc_device_remove(struct hv_device *device) struct netvsc_device *net_device; struct hv_netvsc_packet *netvsc_packet, *pos; + DPRINT_INFO(NETVSC, "Disabling outbound traffic on net device (%p)...", + device->ext); + /* Stop outbound traffic ie sends and receives completions */ net_device = release_outbound_net_device(device); if (!net_device) { - dev_err(&device->device, "No net device present!!"); + DPRINT_ERR(NETVSC, "No net device present!!"); return -1; } /* Wait for all send completions */ while (atomic_read(&net_device->num_outstanding_sends)) { - dev_err(&device->device, - "waiting for %d requests to complete...", - atomic_read(&net_device->num_outstanding_sends)); + DPRINT_INFO(NETVSC, "waiting for %d requests to complete...", + atomic_read(&net_device->num_outstanding_sends)); udelay(100); } - netvsc_disconnect_vsp(net_device); + DPRINT_INFO(NETVSC, "Disconnecting from netvsp..."); + + NetVscDisconnectFromVsp(net_device); + + DPRINT_INFO(NETVSC, "Disabling inbound traffic on net device (%p)...", + device->ext); /* Stop inbound traffic ie receives and sends completions */ net_device = release_inbound_net_device(device); /* At this point, no one should be accessing netDevice except in here */ - dev_notice(&device->device, "net device safe to remove"); + DPRINT_INFO(NETVSC, "net device (%p) safe to remove", net_device); /* Now, we can close the channel safely */ vmbus_close(device->channel); @@ -638,7 +845,7 @@ static void netvsc_send_completion(struct hv_device *device, net_device = get_inbound_net_device(device); if (!net_device) { - dev_err(&device->device, "unable to get net device..." + DPRINT_ERR(NETVSC, "unable to get net device..." "device being destroyed?"); return; } @@ -646,6 +853,9 @@ static void netvsc_send_completion(struct hv_device *device, nvsp_packet = (struct nvsp_message *)((unsigned long)packet + (packet->offset8 << 3)); + DPRINT_DBG(NETVSC, "send completion packet - type %d", + nvsp_packet->hdr.msg_type); + if ((nvsp_packet->hdr.msg_type == NVSP_MSG_TYPE_INIT_COMPLETE) || (nvsp_packet->hdr.msg_type == NVSP_MSG1_TYPE_SEND_RECV_BUF_COMPLETE) || @@ -668,7 +878,7 @@ static void netvsc_send_completion(struct hv_device *device, atomic_dec(&net_device->num_outstanding_sends); } else { - dev_err(&device->device, "Unknown send completion packet type- " + DPRINT_ERR(NETVSC, "Unknown send completion packet type - " "%d received!!", nvsp_packet->hdr.msg_type); } @@ -685,7 +895,7 @@ static int netvsc_send(struct hv_device *device, net_device = get_outbound_net_device(device); if (!net_device) { - dev_err(&device->device, "net device (%p) shutting down..." + DPRINT_ERR(NETVSC, "net device (%p) shutting down..." "ignoring outbound packets", net_device); return -2; } @@ -721,7 +931,7 @@ static int netvsc_send(struct hv_device *device, } if (ret != 0) - dev_err(&device->device, "Unable to send packet %p ret %d", + DPRINT_ERR(NETVSC, "Unable to send packet %p ret %d", packet, ret); atomic_inc(&net_device->num_outstanding_sends); @@ -729,98 +939,6 @@ static int netvsc_send(struct hv_device *device, return ret; } -static void netvsc_send_recv_completion(struct hv_device *device, - u64 transaction_id) -{ - struct nvsp_message recvcompMessage; - int retries = 0; - int ret; - - recvcompMessage.hdr.msg_type = - NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE; - - /* FIXME: Pass in the status */ - recvcompMessage.msg.v1_msg.send_rndis_pkt_complete.status = - NVSP_STAT_SUCCESS; - -retry_send_cmplt: - /* Send the completion */ - ret = vmbus_sendpacket(device->channel, &recvcompMessage, - sizeof(struct nvsp_message), transaction_id, - VM_PKT_COMP, 0); - if (ret == 0) { - /* success */ - /* no-op */ - } else if (ret == -1) { - /* no more room...wait a bit and attempt to retry 3 times */ - retries++; - dev_err(&device->device, "unable to send receive completion pkt" - " (tid %llx)...retrying %d", transaction_id, retries); - - if (retries < 4) { - udelay(100); - goto retry_send_cmplt; - } else { - dev_err(&device->device, "unable to send receive " - "completion pkt (tid %llx)...give up retrying", - transaction_id); - } - } else { - dev_err(&device->device, "unable to send receive " - "completion pkt - %llx", transaction_id); - } -} - -/* Send a receive completion packet to RNDIS device (ie NetVsp) */ -static void netvsc_receive_completion(void *context) -{ - struct hv_netvsc_packet *packet = context; - struct hv_device *device = (struct hv_device *)packet->device; - struct netvsc_device *net_device; - u64 transaction_id = 0; - bool fsend_receive_comp = false; - unsigned long flags; - - /* - * Even though it seems logical to do a GetOutboundNetDevice() here to - * send out receive completion, we are using GetInboundNetDevice() - * since we may have disable outbound traffic already. - */ - net_device = get_inbound_net_device(device); - if (!net_device) { - dev_err(&device->device, "unable to get net device..." - "device being destroyed?"); - return; - } - - /* Overloading use of the lock. */ - spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags); - - packet->xfer_page_pkt->count--; - - /* - * Last one in the line that represent 1 xfer page packet. - * Return the xfer page packet itself to the freelist - */ - if (packet->xfer_page_pkt->count == 0) { - fsend_receive_comp = true; - transaction_id = packet->completion.recv.recv_completion_tid; - list_add_tail(&packet->xfer_page_pkt->list_ent, - &net_device->recv_pkt_list); - - } - - /* Put the packet back */ - list_add_tail(&packet->list_ent, &net_device->recv_pkt_list); - spin_unlock_irqrestore(&net_device->recv_pkt_list_lock, flags); - - /* Send a receive completion for the xfer page packet */ - if (fsend_receive_comp) - netvsc_send_recv_completion(device, transaction_id); - - put_net_device(device); -} - static void netvsc_receive(struct hv_device *device, struct vmpacket_descriptor *packet) { @@ -839,7 +957,7 @@ static void netvsc_receive(struct hv_device *device, net_device = get_inbound_net_device(device); if (!net_device) { - dev_err(&device->device, "unable to get net device..." + DPRINT_ERR(NETVSC, "unable to get net device..." "device being destroyed?"); return; } @@ -849,7 +967,7 @@ static void netvsc_receive(struct hv_device *device, * packet */ if (packet->type != VM_PKT_DATA_USING_XFER_PAGES) { - dev_err(&device->device, "Unknown packet type received - %d", + DPRINT_ERR(NETVSC, "Unknown packet type received - %d", packet->type); put_net_device(device); return; @@ -861,22 +979,28 @@ static void netvsc_receive(struct hv_device *device, /* Make sure this is a valid nvsp packet */ if (nvsp_packet->hdr.msg_type != NVSP_MSG1_TYPE_SEND_RNDIS_PKT) { - dev_err(&device->device, "Unknown nvsp packet type received-" - " %d", nvsp_packet->hdr.msg_type); + DPRINT_ERR(NETVSC, "Unknown nvsp packet type received - %d", + nvsp_packet->hdr.msg_type); put_net_device(device); return; } + DPRINT_DBG(NETVSC, "NVSP packet received - type %d", + nvsp_packet->hdr.msg_type); + vmxferpage_packet = (struct vmtransfer_page_packet_header *)packet; if (vmxferpage_packet->xfer_pageset_id != NETVSC_RECEIVE_BUFFER_ID) { - dev_err(&device->device, "Invalid xfer page set id - " + DPRINT_ERR(NETVSC, "Invalid xfer page set id - " "expecting %x got %x", NETVSC_RECEIVE_BUFFER_ID, vmxferpage_packet->xfer_pageset_id); put_net_device(device); return; } + DPRINT_DBG(NETVSC, "xfer page - range count %d", + vmxferpage_packet->range_cnt); + /* * Grab free packets (range count + 1) to represent this xfer * page packet. +1 to represent the xfer page packet itself. @@ -897,9 +1021,9 @@ static void netvsc_receive(struct hv_device *device, * some of the xfer page packet ranges... */ if (count < 2) { - dev_err(&device->device, "Got only %d netvsc pkt...needed " - "%d pkts. Dropping this xfer page packet completely!", - count, vmxferpage_packet->range_cnt + 1); + DPRINT_ERR(NETVSC, "Got only %d netvsc pkt...needed %d pkts. " + "Dropping this xfer page packet completely!", + count, vmxferpage_packet->range_cnt + 1); /* Return it to the freelist */ spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags); @@ -925,9 +1049,9 @@ static void netvsc_receive(struct hv_device *device, xferpage_packet->count = count - 1; if (xferpage_packet->count != vmxferpage_packet->range_cnt) { - dev_err(&device->device, "Needed %d netvsc pkts to satisy " - "this xfer page...got %d", - vmxferpage_packet->range_cnt, xferpage_packet->count); + DPRINT_INFO(NETVSC, "Needed %d netvsc pkts to satisy this xfer " + "page...got %d", vmxferpage_packet->range_cnt, + xferpage_packet->count); } /* Each range represents 1 RNDIS pkt that contains 1 ethernet frame */ @@ -993,6 +1117,13 @@ static void netvsc_receive(struct hv_device *device, break; } } + DPRINT_DBG(NETVSC, "[%d] - (abs offset %u len %u) => " + "(pfn %llx, offset %u, len %u)", i, + vmxferpage_packet->ranges[i].byte_offset, + vmxferpage_packet->ranges[i].byte_count, + netvsc_packet->page_buf[0].pfn, + netvsc_packet->page_buf[0].offset, + netvsc_packet->page_buf[0].len); /* Pass it to the upper layer */ ((struct netvsc_driver *)device->drv)-> @@ -1005,6 +1136,101 @@ static void netvsc_receive(struct hv_device *device, put_net_device(device); } +static void netvsc_send_recv_completion(struct hv_device *device, + u64 transaction_id) +{ + struct nvsp_message recvcompMessage; + int retries = 0; + int ret; + + DPRINT_DBG(NETVSC, "Sending receive completion pkt - %llx", + transaction_id); + + recvcompMessage.hdr.msg_type = + NVSP_MSG1_TYPE_SEND_RNDIS_PKT_COMPLETE; + + /* FIXME: Pass in the status */ + recvcompMessage.msg.v1_msg.send_rndis_pkt_complete.status = + NVSP_STAT_SUCCESS; + +retry_send_cmplt: + /* Send the completion */ + ret = vmbus_sendpacket(device->channel, &recvcompMessage, + sizeof(struct nvsp_message), transaction_id, + VM_PKT_COMP, 0); + if (ret == 0) { + /* success */ + /* no-op */ + } else if (ret == -1) { + /* no more room...wait a bit and attempt to retry 3 times */ + retries++; + DPRINT_ERR(NETVSC, "unable to send receive completion pkt " + "(tid %llx)...retrying %d", transaction_id, retries); + + if (retries < 4) { + udelay(100); + goto retry_send_cmplt; + } else { + DPRINT_ERR(NETVSC, "unable to send receive completion " + "pkt (tid %llx)...give up retrying", + transaction_id); + } + } else { + DPRINT_ERR(NETVSC, "unable to send receive completion pkt - " + "%llx", transaction_id); + } +} + +/* Send a receive completion packet to RNDIS device (ie NetVsp) */ +static void netvsc_receive_completion(void *context) +{ + struct hv_netvsc_packet *packet = context; + struct hv_device *device = (struct hv_device *)packet->device; + struct netvsc_device *net_device; + u64 transaction_id = 0; + bool fsend_receive_comp = false; + unsigned long flags; + + /* + * Even though it seems logical to do a GetOutboundNetDevice() here to + * send out receive completion, we are using GetInboundNetDevice() + * since we may have disable outbound traffic already. + */ + net_device = get_inbound_net_device(device); + if (!net_device) { + DPRINT_ERR(NETVSC, "unable to get net device..." + "device being destroyed?"); + return; + } + + /* Overloading use of the lock. */ + spin_lock_irqsave(&net_device->recv_pkt_list_lock, flags); + + packet->xfer_page_pkt->count--; + + /* + * Last one in the line that represent 1 xfer page packet. + * Return the xfer page packet itself to the freelist + */ + if (packet->xfer_page_pkt->count == 0) { + fsend_receive_comp = true; + transaction_id = packet->completion.recv.recv_completion_tid; + list_add_tail(&packet->xfer_page_pkt->list_ent, + &net_device->recv_pkt_list); + + } + + /* Put the packet back */ + list_add_tail(&packet->list_ent, &net_device->recv_pkt_list); + spin_unlock_irqrestore(&net_device->recv_pkt_list_lock, flags); + + /* Send a receive completion for the xfer page packet */ + if (fsend_receive_comp) + netvsc_send_recv_completion(device, transaction_id); + + put_net_device(device); +} + static void netvsc_channel_cb(void *context) { int ret; @@ -1025,7 +1251,7 @@ static void netvsc_channel_cb(void *context) net_device = get_inbound_net_device(device); if (!net_device) { - dev_err(&device->device, "net device (%p) shutting down..." + DPRINT_ERR(NETVSC, "net device (%p) shutting down..." "ignoring inbound packets", net_device); goto out; } @@ -1035,6 +1261,9 @@ static void netvsc_channel_cb(void *context) &bytes_recvd, &request_id); if (ret == 0) { if (bytes_recvd > 0) { + DPRINT_DBG(NETVSC, "receive %d bytes, tid %llx", + bytes_recvd, request_id); + desc = (struct vmpacket_descriptor *)buffer; switch (desc->type) { case VM_PKT_COMP: @@ -1046,7 +1275,7 @@ static void netvsc_channel_cb(void *context) break; default: - dev_err(&device->device, + DPRINT_ERR(NETVSC, "unhandled packet type %d, " "tid %llx len %d\n", desc->type, request_id, @@ -1075,7 +1304,7 @@ static void netvsc_channel_cb(void *context) buffer = kmalloc(bytes_recvd, GFP_ATOMIC); if (buffer == NULL) { /* Try again next time around */ - dev_err(&device->device, + DPRINT_ERR(NETVSC, "unable to allocate buffer of size " "(%d)!!", bytes_recvd); break; @@ -1090,111 +1319,3 @@ static void netvsc_channel_cb(void *context) kfree(buffer); return; } - -/* - * netvsc_device_add - Callback when the device belonging to this - * driver is added - */ -static int netvsc_device_add(struct hv_device *device, void *additional_info) -{ - int ret = 0; - int i; - struct netvsc_device *net_device; - struct hv_netvsc_packet *packet, *pos; - struct netvsc_driver *net_driver = - (struct netvsc_driver *)device->drv; - - net_device = alloc_net_device(device); - if (!net_device) { - ret = -1; - goto cleanup; - } - - /* Initialize the NetVSC channel extension */ - net_device->recv_buf_size = NETVSC_RECEIVE_BUFFER_SIZE; - spin_lock_init(&net_device->recv_pkt_list_lock); - - net_device->send_buf_size = NETVSC_SEND_BUFFER_SIZE; - - INIT_LIST_HEAD(&net_device->recv_pkt_list); - - for (i = 0; i < NETVSC_RECEIVE_PACKETLIST_COUNT; i++) { - packet = kzalloc(sizeof(struct hv_netvsc_packet) + - (NETVSC_RECEIVE_SG_COUNT * - sizeof(struct hv_page_buffer)), GFP_KERNEL); - if (!packet) - break; - - list_add_tail(&packet->list_ent, - &net_device->recv_pkt_list); - } - init_waitqueue_head(&net_device->channel_init_wait); - - /* Open the channel */ - ret = vmbus_open(device->channel, net_driver->ring_buf_size, - net_driver->ring_buf_size, NULL, 0, - netvsc_channel_cb, device); - - if (ret != 0) { - dev_err(&device->device, "unable to open channel: %d", ret); - ret = -1; - goto cleanup; - } - - /* Channel is opened */ - pr_info("hv_netvsc channel opened successfully"); - - /* Connect with the NetVsp */ - ret = netvsc_connect_vsp(device); - if (ret != 0) { - dev_err(&device->device, - "unable to connect to NetVSP - %d", ret); - ret = -1; - goto close; - } - - return ret; - -close: - /* Now, we can close the channel safely */ - vmbus_close(device->channel); - -cleanup: - - if (net_device) { - list_for_each_entry_safe(packet, pos, - &net_device->recv_pkt_list, - list_ent) { - list_del(&packet->list_ent); - kfree(packet); - } - - release_outbound_net_device(device); - release_inbound_net_device(device); - - free_net_device(net_device); - } - - return ret; -} - -/* - * netvsc_initialize - Main entry point - */ -int netvsc_initialize(struct hv_driver *drv) -{ - struct netvsc_driver *driver = (struct netvsc_driver *)drv; - - drv->name = driver_name; - memcpy(&drv->dev_type, &netvsc_device_type, sizeof(struct hv_guid)); - - /* Setup the dispatch table */ - driver->base.dev_add = netvsc_device_add; - driver->base.dev_rm = netvsc_device_remove; - driver->base.cleanup = netvsc_cleanup; - - driver->send = netvsc_send; - - rndis_filter_init(driver); - return 0; -} diff --git a/trunk/drivers/staging/hv/netvsc_drv.c b/trunk/drivers/staging/hv/netvsc_drv.c index 096a7323cea7..33973568214f 100644 --- a/trunk/drivers/staging/hv/netvsc_drv.c +++ b/trunk/drivers/staging/hv/netvsc_drv.c @@ -18,8 +18,6 @@ * Haiyang Zhang * Hank Janssen */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -80,14 +78,14 @@ static int netvsc_open(struct net_device *net) /* Open up the device */ ret = rndis_filter_open(device_obj); if (ret != 0) { - netdev_err(net, "unable to open device (ret %d).\n", - ret); + DPRINT_ERR(NETVSC_DRV, + "unable to open device (ret %d).", ret); return ret; } netif_start_queue(net); } else { - netdev_err(net, "unable to open device...link is down.\n"); + DPRINT_ERR(NETVSC_DRV, "unable to open device...link is down."); } return ret; @@ -103,7 +101,7 @@ static int netvsc_close(struct net_device *net) ret = rndis_filter_close(device_obj); if (ret != 0) - netdev_err(net, "unable to close device (ret %d).\n", ret); + DPRINT_ERR(NETVSC_DRV, "unable to close device (ret %d).", ret); return ret; } @@ -139,6 +137,9 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) int ret; unsigned int i, num_pages; + DPRINT_DBG(NETVSC_DRV, "xmit packet - len %d data_len %d", + skb->len, skb->data_len); + /* Add 1 for skb->data and additional one for RNDIS */ num_pages = skb_shinfo(skb)->nr_frags + 1 + 1; if (num_pages > net_device_ctx->avail) @@ -150,7 +151,7 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) net_drv_obj->req_ext_size, GFP_ATOMIC); if (!packet) { /* out of memory, silently drop packet */ - netdev_err(net, "unable to allocate hv_netvsc_packet\n"); + DPRINT_ERR(NETVSC_DRV, "unable to allocate hv_netvsc_packet"); dev_kfree_skb(skb); net->stats.tx_dropped++; @@ -196,6 +197,10 @@ static int netvsc_start_xmit(struct sk_buff *skb, struct net_device *net) net->stats.tx_bytes += skb->len; net->stats.tx_packets++; + DPRINT_DBG(NETVSC_DRV, "# of xmits %lu total size %lu", + net->stats.tx_packets, + net->stats.tx_bytes); + net_device_ctx->avail -= num_pages; if (net_device_ctx->avail < PACKET_PAGES_LOWATER) netif_stop_queue(net); @@ -218,8 +223,8 @@ static void netvsc_linkstatus_callback(struct hv_device *device_obj, struct net_device_context *ndev_ctx; if (!net) { - netdev_err(net, "got link status but net device " - "not initialized yet\n"); + DPRINT_ERR(NETVSC_DRV, "got link status but net device " + "not initialized yet"); return; } @@ -249,8 +254,8 @@ static int netvsc_recv_callback(struct hv_device *device_obj, unsigned long flags; if (!net) { - netdev_err(net, "got receive callback but net device" - " not initialized yet\n"); + DPRINT_ERR(NETVSC_DRV, "got receive callback but net device " + "not initialized yet"); return 0; } @@ -296,6 +301,9 @@ static int netvsc_recv_callback(struct hv_device *device_obj, */ netif_rx(skb); + DPRINT_DBG(NETVSC_DRV, "# of recvs %lu total size %lu", + net->stats.rx_packets, net->stats.rx_bytes); + return 0; } @@ -309,6 +317,8 @@ static void netvsc_get_drvinfo(struct net_device *net, static const struct ethtool_ops ethtool_ops = { .get_drvinfo = netvsc_get_drvinfo, + .get_sg = ethtool_op_get_sg, + .set_sg = ethtool_op_set_sg, .get_link = ethtool_op_get_link, }; @@ -374,7 +384,8 @@ static int netvsc_probe(struct device *device) free_netdev(net); dev_set_drvdata(device, NULL); - netdev_err(net, "unable to add netvsc device (ret %d)\n", ret); + DPRINT_ERR(NETVSC_DRV, "unable to add netvsc device (ret %d)", + ret); return ret; } @@ -395,7 +406,6 @@ static int netvsc_probe(struct device *device) net->netdev_ops = &device_ops; /* TODO: Add GSO and Checksum offload */ - net->hw_features = NETIF_F_SG; net->features = NETIF_F_SG; SET_ETHTOOL_OPS(net, ðtool_ops); @@ -421,7 +431,7 @@ static int netvsc_remove(struct device *device) int ret; if (net == NULL) { - dev_err(device, "No net device to remove\n"); + DPRINT_INFO(NETVSC, "no net device to remove"); return 0; } @@ -441,7 +451,7 @@ static int netvsc_remove(struct device *device) ret = net_drv_obj->base.dev_rm(device_obj); if (ret != 0) { /* TODO: */ - netdev_err(net, "unable to remove vsc device (ret %d)\n", ret); + DPRINT_ERR(NETVSC, "unable to remove vsc device (ret %d)", ret); } free_netdev(net); @@ -470,13 +480,16 @@ static void netvsc_drv_exit(void) /* Get the device */ ret = driver_for_each_device(&drv->driver, NULL, ¤t_dev, netvsc_drv_exit_cb); + if (ret) + DPRINT_WARN(NETVSC_DRV, + "driver_for_each_device returned %d", ret); if (current_dev == NULL) break; /* Initiate removal from the top-down */ - dev_err(current_dev, "unregistering device (%s)...\n", - dev_name(current_dev)); + DPRINT_INFO(NETVSC_DRV, "unregistering device (%p)...", + current_dev); device_unregister(current_dev); } @@ -530,7 +543,7 @@ MODULE_DEVICE_TABLE(dmi, hv_netvsc_dmi_table); static int __init netvsc_init(void) { - pr_info("initializing...."); + DPRINT_INFO(NETVSC_DRV, "Netvsc initializing...."); if (!dmi_check_system(hv_netvsc_dmi_table)) return -ENODEV; diff --git a/trunk/drivers/staging/hv/ring_buffer.c b/trunk/drivers/staging/hv/ring_buffer.c index 66e1b3f16d9a..66688fb69741 100644 --- a/trunk/drivers/staging/hv/ring_buffer.c +++ b/trunk/drivers/staging/hv/ring_buffer.c @@ -20,7 +20,6 @@ * Hank Janssen * */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include #include @@ -373,12 +372,20 @@ int ringbuffer_write(struct hv_ring_buffer_info *outring_info, &bytes_avail_toread, &bytes_avail_towrite); + DPRINT_DBG(VMBUS, "Writing %u bytes...", totalbytes_towrite); + /* Dumpring_info(Outring_info, "BEFORE "); */ /* If there is only room for the packet, assume it is full. */ /* Otherwise, the next time around, we think the ring buffer */ /* is empty since the read index == write index */ if (bytes_avail_towrite <= totalbytes_towrite) { + DPRINT_DBG(VMBUS, + "No more space left on outbound ring buffer " + "(needed %u, avail %u)", + totalbytes_towrite, + bytes_avail_towrite); + spin_unlock_irqrestore(&outring_info->ring_lock, flags); return -1; } @@ -492,10 +499,18 @@ int ringbuffer_read(struct hv_ring_buffer_info *inring_info, void *buffer, &bytes_avail_toread, &bytes_avail_towrite); + DPRINT_DBG(VMBUS, "Reading %u bytes...", buflen); + /* Dumpring_info(Inring_info, "BEFORE "); */ /* Make sure there is something to read */ if (bytes_avail_toread < buflen) { + DPRINT_DBG(VMBUS, + "got callback but not enough to read " + "!!", + bytes_avail_toread, + buflen); + spin_unlock_irqrestore(&inring_info->ring_lock, flags); return -1; @@ -553,6 +568,8 @@ copyto_ringbuffer( /* wrap-around detected! */ if (srclen > ring_buffer_size - start_write_offset) { + DPRINT_DBG(VMBUS, "wrap-around detected!"); + frag_len = ring_buffer_size - start_write_offset; memcpy(ring_buffer + start_write_offset, src, frag_len); memcpy(ring_buffer, src + frag_len, srclen - frag_len); @@ -590,6 +607,8 @@ copyfrom_ringbuffer( /* wrap-around detected at the src */ if (destlen > ring_buffer_size - start_read_offset) { + DPRINT_DBG(VMBUS, "src wrap-around detected!"); + frag_len = ring_buffer_size - start_read_offset; memcpy(dest, ring_buffer + start_read_offset, frag_len); diff --git a/trunk/drivers/staging/hv/rndis_filter.c b/trunk/drivers/staging/hv/rndis_filter.c index 6305050f9e8d..048376b2b676 100644 --- a/trunk/drivers/staging/hv/rndis_filter.c +++ b/trunk/drivers/staging/hv/rndis_filter.c @@ -25,7 +25,7 @@ #include #include #include -#include + #include "logging.h" #include "hv_api.h" #include "netvsc_api.h" @@ -283,6 +283,14 @@ static void rndis_filter_receive_response(struct rndis_device *dev, */ if (request->request_msg.msg.init_req.req_id == resp->msg.init_complete.req_id) { + DPRINT_DBG(NETVSC, "found rndis request for " + "this response (id 0x%x req type 0x%x res " + "type 0x%x)", + request->request_msg.msg. + init_req.req_id, + request->request_msg.ndis_msg_type, + resp->ndis_msg_type); + found = true; break; } @@ -294,11 +302,10 @@ static void rndis_filter_receive_response(struct rndis_device *dev, memcpy(&request->response_msg, resp, resp->msg_len); } else { - dev_err(&dev->net_dev->dev->device, - "rndis response buffer overflow " - "detected (size %u max %zu)\n", - resp->msg_len, - sizeof(struct rndis_filter_packet)); + DPRINT_ERR(NETVSC, "rndis response buffer overflow " + "detected (size %u max %zu)", + resp->msg_len, + sizeof(struct rndis_filter_packet)); if (resp->ndis_msg_type == REMOTE_NDIS_RESET_CMPLT) { @@ -315,11 +322,10 @@ static void rndis_filter_receive_response(struct rndis_device *dev, request->wait_condition = 1; wake_up(&request->wait_event); } else { - dev_err(&dev->net_dev->dev->device, - "no rndis request found for this response " - "(id 0x%x res type 0x%x)\n", - resp->msg.init_complete.req_id, - resp->ndis_msg_type); + DPRINT_ERR(NETVSC, "no rndis request found for this response " + "(id 0x%x res type 0x%x)", + resp->msg.init_complete.req_id, + resp->ndis_msg_type); } } @@ -382,15 +388,15 @@ static int rndis_filter_receive(struct hv_device *dev, /* Make sure the rndis device state is initialized */ if (!net_dev->extension) { - dev_err(&dev->device, "got rndis message but no rndis device - " - "dropping this message!\n"); + DPRINT_ERR(NETVSC, "got rndis message but no rndis device..." + "dropping this message!"); return -1; } rndis_dev = (struct rndis_device *)net_dev->extension; if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED) { - dev_err(&dev->device, "got rndis message but rndis device " - "uninitialized...dropping this message!\n"); + DPRINT_ERR(NETVSC, "got rndis message but rndis device " + "uninitialized...dropping this message!"); return -1; } @@ -411,8 +417,8 @@ static int rndis_filter_receive(struct hv_device *dev, kunmap_atomic(rndis_hdr - pkt->page_buf[0].offset, KM_IRQ0); - dev_err(&dev->device, "invalid rndis message? (expected %u " - "bytes got %u)...dropping this message!\n", + DPRINT_ERR(NETVSC, "invalid rndis message? (expected %u " + "bytes got %u)...dropping this message!", rndis_hdr->msg_len, pkt->total_data_buflen); return -1; @@ -421,8 +427,8 @@ static int rndis_filter_receive(struct hv_device *dev, if ((rndis_hdr->ndis_msg_type != REMOTE_NDIS_PACKET_MSG) && (rndis_hdr->msg_len > sizeof(struct rndis_message))) { - dev_err(&dev->device, "incoming rndis message buffer overflow " - "detected (got %u, max %zu)..marking it an error!\n", + DPRINT_ERR(NETVSC, "incoming rndis message buffer overflow " + "detected (got %u, max %zu)...marking it an error!", rndis_hdr->msg_len, sizeof(struct rndis_message)); } @@ -454,8 +460,7 @@ static int rndis_filter_receive(struct hv_device *dev, rndis_filter_receive_indicate_status(rndis_dev, &rndis_msg); break; default: - dev_err(&dev->device, - "unhandled rndis message (type %u len %u)\n", + DPRINT_ERR(NETVSC, "unhandled rndis message (type %u len %u)", rndis_msg.ndis_msg_type, rndis_msg.msg_len); break; @@ -578,8 +583,7 @@ static int rndis_filter_set_packet_filter(struct rndis_device *dev, msecs_to_jiffies(2000)); if (request->wait_condition == 0) { ret = -1; - dev_err(&dev->net_dev->dev->device, - "timeout before we got a set response...\n"); + DPRINT_ERR(NETVSC, "timeout before we got a set response..."); /* * We can't deallocate the request since we may still receive a * send completion for it. @@ -601,6 +605,9 @@ static int rndis_filter_set_packet_filter(struct rndis_device *dev, int rndis_filter_init(struct netvsc_driver *drv) { + DPRINT_DBG(NETVSC, "sizeof(struct rndis_filter_packet) == %zd", + sizeof(struct rndis_filter_packet)); + drv->req_ext_size = sizeof(struct rndis_filter_packet); /* Driver->Context = rndisDriver; */ @@ -758,6 +765,8 @@ static int rndis_filte_device_add(struct hv_device *dev, if (!rndisDevice) return -1; + DPRINT_DBG(NETVSC, "rndis device object allocated - %p", rndisDevice); + /* * Let the inner driver handle this first to create the netvsc channel * NOTE! Once the channel is created, we may get a receive callback @@ -793,15 +802,16 @@ static int rndis_filte_device_add(struct hv_device *dev, */ } + DPRINT_INFO(NETVSC, "Device 0x%p mac addr %pM", + rndisDevice, rndisDevice->hw_mac_adr); + memcpy(deviceInfo->mac_adr, rndisDevice->hw_mac_adr, ETH_ALEN); rndis_filter_query_device_link_status(rndisDevice); deviceInfo->link_state = rndisDevice->link_stat; - - dev_info(&dev->device, "Device MAC %pM link state %s", - rndisDevice->hw_mac_adr, - ((deviceInfo->link_state) ? ("down\n") : ("up\n"))); + DPRINT_INFO(NETVSC, "Device 0x%p link state %s", rndisDevice, + ((deviceInfo->link_state) ? ("down") : ("up"))); return ret; } diff --git a/trunk/drivers/staging/hv/storvsc.c b/trunk/drivers/staging/hv/storvsc.c index 85bae5af3c45..e2ad72924184 100644 --- a/trunk/drivers/staging/hv/storvsc.c +++ b/trunk/drivers/staging/hv/storvsc.c @@ -17,12 +17,10 @@ * Authors: * Haiyang Zhang * Hank Janssen - * - * 4/3/2011: K. Y. Srinivasan - Significant restructuring and cleanup. */ #include #include -#include +#include #include #include #include @@ -35,6 +33,57 @@ #include "channel.h" +struct storvsc_request_extension { + /* LIST_ENTRY ListEntry; */ + + struct hv_storvsc_request *request; + struct hv_device *device; + + /* Synchronize the request/response if needed */ + int wait_condition; + wait_queue_head_t wait_event; + + struct vstor_packet vstor_packet; +}; + +/* A storvsc device is a device object that contains a vmbus channel */ +struct storvsc_device { + struct hv_device *device; + + /* 0 indicates the device is being destroyed */ + atomic_t ref_count; + + atomic_t num_outstanding_req; + + /* + * Each unique Port/Path/Target represents 1 channel ie scsi + * controller. In reality, the pathid, targetid is always 0 + * and the port is set by us + */ + unsigned int port_number; + unsigned char path_id; + unsigned char target_id; + + /* LIST_ENTRY OutstandingRequestList; */ + /* HANDLE OutstandingRequestLock; */ + + /* Used for vsc/vsp channel reset process */ + struct storvsc_request_extension init_request; + struct storvsc_request_extension reset_request; +}; + + +static const char *g_driver_name = "storvsc"; + +/* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */ +static const struct hv_guid gStorVscDeviceType = { + .data = { + 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, + 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f + } +}; + + static inline struct storvsc_device *alloc_stor_device(struct hv_device *device) { struct storvsc_device *stor_device; @@ -55,9 +104,24 @@ static inline struct storvsc_device *alloc_stor_device(struct hv_device *device) static inline void free_stor_device(struct storvsc_device *device) { + /* ASSERT(atomic_read(&device->ref_count) == 0); */ kfree(device); } +/* Get the stordevice object iff exists and its refcount > 1 */ +static inline struct storvsc_device *get_stor_device(struct hv_device *device) +{ + struct storvsc_device *stor_device; + + stor_device = (struct storvsc_device *)device->ext; + if (stor_device && atomic_read(&stor_device->ref_count) > 1) + atomic_inc(&stor_device->ref_count); + else + stor_device = NULL; + + return stor_device; +} + /* Get the stordevice object iff exists and its refcount > 0 */ static inline struct storvsc_device *must_get_stor_device( struct hv_device *device) @@ -73,6 +137,17 @@ static inline struct storvsc_device *must_get_stor_device( return stor_device; } +static inline void put_stor_device(struct hv_device *device) +{ + struct storvsc_device *stor_device; + + stor_device = (struct storvsc_device *)device->ext; + /* ASSERT(stor_device); */ + + atomic_dec(&stor_device->ref_count); + /* ASSERT(atomic_read(&stor_device->ref_count)); */ +} + /* Drop ref count to 1 to effectively disable get_stor_device() */ static inline struct storvsc_device *release_stor_device( struct hv_device *device) @@ -80,6 +155,7 @@ static inline struct storvsc_device *release_stor_device( struct storvsc_device *stor_device; stor_device = (struct storvsc_device *)device->ext; + /* ASSERT(stor_device); */ /* Busy wait until the ref drop to 2, then set it to 1 */ while (atomic_cmpxchg(&stor_device->ref_count, 2, 1) != 2) @@ -95,6 +171,7 @@ static inline struct storvsc_device *final_release_stor_device( struct storvsc_device *stor_device; stor_device = (struct storvsc_device *)device->ext; + /* ASSERT(stor_device); */ /* Busy wait until the ref drop to 1, then set it to 0 */ while (atomic_cmpxchg(&stor_device->ref_count, 1, 0) != 1) @@ -107,9 +184,9 @@ static inline struct storvsc_device *final_release_stor_device( static int stor_vsc_channel_init(struct hv_device *device) { struct storvsc_device *stor_device; - struct hv_storvsc_request *request; + struct storvsc_request_extension *request; struct vstor_packet *vstor_packet; - int ret, t; + int ret; stor_device = get_stor_device(device); if (!stor_device) { @@ -125,13 +202,14 @@ static int stor_vsc_channel_init(struct hv_device *device) * Now, initiate the vsc/vsp initialization protocol on the open * channel */ - memset(request, 0, sizeof(struct hv_storvsc_request)); - init_completion(&request->wait_event); + memset(request, 0, sizeof(struct storvsc_request_extension)); + init_waitqueue_head(&request->wait_event); vstor_packet->operation = VSTOR_OPERATION_BEGIN_INITIALIZATION; vstor_packet->flags = REQUEST_COMPLETION_FLAG; DPRINT_INFO(STORVSC, "BEGIN_INITIALIZATION_OPERATION..."); + request->wait_condition = 0; ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, @@ -143,12 +221,14 @@ static int stor_vsc_channel_init(struct hv_device *device) goto cleanup; } - t = wait_for_completion_timeout(&request->wait_event, HZ); - if (t == 0) { + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { ret = -ETIMEDOUT; goto cleanup; } + if (vstor_packet->operation != VSTOR_OPERATION_COMPLETE_IO || vstor_packet->status != 0) { DPRINT_ERR(STORVSC, "BEGIN_INITIALIZATION_OPERATION failed " @@ -167,6 +247,7 @@ static int stor_vsc_channel_init(struct hv_device *device) vstor_packet->version.major_minor = VMSTOR_PROTOCOL_VERSION_CURRENT; FILL_VMSTOR_REVISION(vstor_packet->version.revision); + request->wait_condition = 0; ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, @@ -178,8 +259,9 @@ static int stor_vsc_channel_init(struct hv_device *device) goto cleanup; } - t = wait_for_completion_timeout(&request->wait_event, HZ); - if (t == 0) { + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { ret = -ETIMEDOUT; goto cleanup; } @@ -202,6 +284,7 @@ static int stor_vsc_channel_init(struct hv_device *device) vstor_packet->storage_channel_properties.port_number = stor_device->port_number; + request->wait_condition = 0; ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, @@ -214,8 +297,9 @@ static int stor_vsc_channel_init(struct hv_device *device) goto cleanup; } - t = wait_for_completion_timeout(&request->wait_event, HZ); - if (t == 0) { + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { ret = -ETIMEDOUT; goto cleanup; } @@ -243,6 +327,7 @@ static int stor_vsc_channel_init(struct hv_device *device) vstor_packet->operation = VSTOR_OPERATION_END_INITIALIZATION; vstor_packet->flags = REQUEST_COMPLETION_FLAG; + request->wait_condition = 0; ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), (unsigned long)request, @@ -255,8 +340,9 @@ static int stor_vsc_channel_init(struct hv_device *device) goto cleanup; } - t = wait_for_completion_timeout(&request->wait_event, HZ); - if (t == 0) { + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { ret = -ETIMEDOUT; goto cleanup; } @@ -278,10 +364,10 @@ static int stor_vsc_channel_init(struct hv_device *device) static void stor_vsc_on_io_completion(struct hv_device *device, struct vstor_packet *vstor_packet, - struct hv_storvsc_request *request) + struct storvsc_request_extension *request_ext) { + struct hv_storvsc_request *request; struct storvsc_device *stor_device; - struct vstor_packet *stor_pkt; stor_device = must_get_stor_device(device); if (!stor_device) { @@ -290,45 +376,48 @@ static void stor_vsc_on_io_completion(struct hv_device *device, return; } - DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request %p " - "completed bytes xfer %u", request, + DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION - request extension %p " + "completed bytes xfer %u", request_ext, vstor_packet->vm_srb.data_transfer_length); - stor_pkt = &request->vstor_packet; + /* ASSERT(request_ext != NULL); */ + /* ASSERT(request_ext->request != NULL); */ + + request = request_ext->request; + /* ASSERT(request->OnIOCompletion != NULL); */ /* Copy over the status...etc */ - stor_pkt->vm_srb.scsi_status = vstor_packet->vm_srb.scsi_status; - stor_pkt->vm_srb.srb_status = vstor_packet->vm_srb.srb_status; - stor_pkt->vm_srb.sense_info_length = - vstor_packet->vm_srb.sense_info_length; + request->status = vstor_packet->vm_srb.scsi_status; - if (vstor_packet->vm_srb.scsi_status != 0 || - vstor_packet->vm_srb.srb_status != 1) { + if (request->status != 0 || vstor_packet->vm_srb.srb_status != 1) { DPRINT_WARN(STORVSC, "cmd 0x%x scsi status 0x%x srb status 0x%x\n", - stor_pkt->vm_srb.cdb[0], - vstor_packet->vm_srb.scsi_status, + request->cdb[0], vstor_packet->vm_srb.scsi_status, vstor_packet->vm_srb.srb_status); } - if ((vstor_packet->vm_srb.scsi_status & 0xFF) == 0x02) { + if ((request->status & 0xFF) == 0x02) { /* CHECK_CONDITION */ if (vstor_packet->vm_srb.srb_status & 0x80) { /* autosense data available */ DPRINT_WARN(STORVSC, "storvsc pkt %p autosense data " - "valid - len %d\n", request, + "valid - len %d\n", request_ext, vstor_packet->vm_srb.sense_info_length); + /* ASSERT(vstor_packet->vm_srb.sense_info_length <= */ + /* request->SenseBufferSize); */ memcpy(request->sense_buffer, vstor_packet->vm_srb.sense_data, vstor_packet->vm_srb.sense_info_length); + request->sense_buffer_size = + vstor_packet->vm_srb.sense_info_length; } } - stor_pkt->vm_srb.data_transfer_length = - vstor_packet->vm_srb.data_transfer_length; + /* TODO: */ + request->bytes_xfer = vstor_packet->vm_srb.data_transfer_length; request->on_io_completion(request); @@ -339,12 +428,12 @@ static void stor_vsc_on_io_completion(struct hv_device *device, static void stor_vsc_on_receive(struct hv_device *device, struct vstor_packet *vstor_packet, - struct hv_storvsc_request *request) + struct storvsc_request_extension *request_ext) { switch (vstor_packet->operation) { case VSTOR_OPERATION_COMPLETE_IO: DPRINT_DBG(STORVSC, "IO_COMPLETE_OPERATION"); - stor_vsc_on_io_completion(device, vstor_packet, request); + stor_vsc_on_io_completion(device, vstor_packet, request_ext); break; case VSTOR_OPERATION_REMOVE_DEVICE: DPRINT_INFO(STORVSC, "REMOVE_DEVICE_OPERATION"); @@ -365,9 +454,10 @@ static void stor_vsc_on_channel_callback(void *context) u32 bytes_recvd; u64 request_id; unsigned char packet[ALIGN(sizeof(struct vstor_packet), 8)]; - struct hv_storvsc_request *request; + struct storvsc_request_extension *request; int ret; + /* ASSERT(device); */ stor_device = must_get_stor_device(device); if (!stor_device) { @@ -384,22 +474,33 @@ static void stor_vsc_on_channel_callback(void *context) DPRINT_DBG(STORVSC, "receive %d bytes - tid %llx", bytes_recvd, request_id); + /* ASSERT(bytes_recvd == + sizeof(struct vstor_packet)); */ - request = (struct hv_storvsc_request *) + request = (struct storvsc_request_extension *) (unsigned long)request_id; + /* ASSERT(request);c */ + /* if (vstor_packet.Flags & SYNTHETIC_FLAG) */ if ((request == &stor_device->init_request) || (request == &stor_device->reset_request)) { + /* DPRINT_INFO(STORVSC, + * "reset completion - operation " + * "%u status %u", + * vstor_packet.Operation, + * vstor_packet.Status); */ memcpy(&request->vstor_packet, packet, sizeof(struct vstor_packet)); - complete(&request->wait_event); + request->wait_condition = 1; + wake_up(&request->wait_event); } else { stor_vsc_on_receive(device, (struct vstor_packet *)packet, request); } } else { + /* DPRINT_DBG(STORVSC, "nothing else to read..."); */ break; } } while (1); @@ -442,10 +543,11 @@ static int stor_vsc_connect_to_vsp(struct hv_device *device) * stor_vsc_on_device_add - Callback when the device belonging to this driver * is added */ -int stor_vsc_on_device_add(struct hv_device *device, +static int stor_vsc_on_device_add(struct hv_device *device, void *additional_info) { struct storvsc_device *stor_device; + /* struct vmstorage_channel_properties *props; */ struct storvsc_device_info *device_info; int ret = 0; @@ -457,6 +559,8 @@ int stor_vsc_on_device_add(struct hv_device *device, } /* Save the channel properties to our storvsc channel */ + /* props = (struct vmstorage_channel_properties *) + * channel->offerMsg.Offer.u.Standard.UserDefined; */ /* FIXME: */ /* @@ -465,10 +569,15 @@ int stor_vsc_on_device_add(struct hv_device *device, * scsi channel prior to the bus scan */ + /* storChannel->PortNumber = 0; + storChannel->PathId = props->PathId; + storChannel->TargetId = props->TargetId; */ + stor_device->port_number = device_info->port_number; /* Send it back up */ ret = stor_vsc_connect_to_vsp(device); + /* device_info->PortNumber = stor_device->PortNumber; */ device_info->path_id = stor_device->path_id; device_info->target_id = stor_device->target_id; @@ -483,7 +592,7 @@ int stor_vsc_on_device_add(struct hv_device *device, /* * stor_vsc_on_device_remove - Callback when the our device is being removed */ -int stor_vsc_on_device_remove(struct hv_device *device) +static int stor_vsc_on_device_remove(struct hv_device *device) { struct storvsc_device *stor_device; @@ -517,24 +626,85 @@ int stor_vsc_on_device_remove(struct hv_device *device) return 0; } +int stor_vsc_on_host_reset(struct hv_device *device) +{ + struct storvsc_device *stor_device; + struct storvsc_request_extension *request; + struct vstor_packet *vstor_packet; + int ret; + + DPRINT_INFO(STORVSC, "resetting host adapter..."); + + stor_device = get_stor_device(device); + if (!stor_device) { + DPRINT_ERR(STORVSC, "unable to get stor device..." + "device being destroyed?"); + return -1; + } + + request = &stor_device->reset_request; + vstor_packet = &request->vstor_packet; + + init_waitqueue_head(&request->wait_event); + + vstor_packet->operation = VSTOR_OPERATION_RESET_BUS; + vstor_packet->flags = REQUEST_COMPLETION_FLAG; + vstor_packet->vm_srb.path_id = stor_device->path_id; + + request->wait_condition = 0; + ret = vmbus_sendpacket(device->channel, vstor_packet, + sizeof(struct vstor_packet), + (unsigned long)&stor_device->reset_request, + VM_PKT_DATA_INBAND, + VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); + if (ret != 0) { + DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", + vstor_packet, ret); + goto cleanup; + } + + wait_event_timeout(request->wait_event, request->wait_condition, + msecs_to_jiffies(1000)); + if (request->wait_condition == 0) { + ret = -ETIMEDOUT; + goto cleanup; + } + + DPRINT_INFO(STORVSC, "host adapter reset completed"); + + /* + * At this point, all outstanding requests in the adapter + * should have been flushed out and return to us + */ + +cleanup: + put_stor_device(device); + return ret; +} + /* * stor_vsc_on_io_request - Callback to initiate an I/O request */ -int stor_vsc_on_io_request(struct hv_device *device, +static int stor_vsc_on_io_request(struct hv_device *device, struct hv_storvsc_request *request) { struct storvsc_device *stor_device; + struct storvsc_request_extension *request_extension; struct vstor_packet *vstor_packet; int ret = 0; - vstor_packet = &request->vstor_packet; + request_extension = + (struct storvsc_request_extension *)request->extension; + vstor_packet = &request_extension->vstor_packet; stor_device = get_stor_device(device); DPRINT_DBG(STORVSC, "enter - Device %p, DeviceExt %p, Request %p, " - , device, stor_device, request); + "Extension %p", device, stor_device, request, + request_extension); - DPRINT_DBG(STORVSC, "req %p len %d", - request, request->data_buffer.len); + DPRINT_DBG(STORVSC, "req %p len %d bus %d, target %d, lun %d cdblen %d", + request, request->data_buffer.len, request->bus, + request->target_id, request->lun_id, request->cdb_len); if (!stor_device) { DPRINT_ERR(STORVSC, "unable to get stor device..." @@ -542,20 +712,31 @@ int stor_vsc_on_io_request(struct hv_device *device, return -2; } + /* print_hex_dump_bytes("", DUMP_PREFIX_NONE, request->Cdb, + * request->CdbLen); */ - request->device = device; + request_extension->request = request; + request_extension->device = device; + memset(vstor_packet, 0 , sizeof(struct vstor_packet)); vstor_packet->flags |= REQUEST_COMPLETION_FLAG; vstor_packet->vm_srb.length = sizeof(struct vmscsi_request); + vstor_packet->vm_srb.port_number = request->host; + vstor_packet->vm_srb.path_id = request->bus; + vstor_packet->vm_srb.target_id = request->target_id; + vstor_packet->vm_srb.lun = request->lun_id; vstor_packet->vm_srb.sense_info_length = SENSE_BUFFER_SIZE; + /* Copy over the scsi command descriptor block */ + vstor_packet->vm_srb.cdb_length = request->cdb_len; + memcpy(&vstor_packet->vm_srb.cdb, request->cdb, request->cdb_len); - vstor_packet->vm_srb.data_transfer_length = - request->data_buffer.len; + vstor_packet->vm_srb.data_in = request->type; + vstor_packet->vm_srb.data_transfer_length = request->data_buffer.len; vstor_packet->operation = VSTOR_OPERATION_EXECUTE_SRB; @@ -569,16 +750,16 @@ int stor_vsc_on_io_request(struct hv_device *device, vstor_packet->vm_srb.sense_info_length, vstor_packet->vm_srb.cdb_length); - if (request->data_buffer.len) { + if (request_extension->request->data_buffer.len) { ret = vmbus_sendpacket_multipagebuffer(device->channel, - &request->data_buffer, + &request_extension->request->data_buffer, vstor_packet, sizeof(struct vstor_packet), - (unsigned long)request); + (unsigned long)request_extension); } else { ret = vmbus_sendpacket(device->channel, vstor_packet, sizeof(struct vstor_packet), - (unsigned long)request, + (unsigned long)request_extension, VM_PKT_DATA_INBAND, VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); } @@ -595,75 +776,62 @@ int stor_vsc_on_io_request(struct hv_device *device, } /* - * The channel properties uniquely specify how the device is to be - * presented to the guest. Map this information for use by the block - * driver. For Linux guests on Hyper-V, we emulate a scsi HBA in the guest - * (storvsc_drv) and so scsi devices in the guest are handled by - * native upper level Linux drivers. Consequently, Hyper-V - * block driver, while being a generic block driver, presently does not - * deal with anything other than devices that would need to be presented - * to the guest as an IDE disk. - * - * This function maps the channel properties as embedded in the input - * parameter device_info onto information necessary to register the - * corresponding block device. - * - * Currently, there is no way to stop the emulation of the block device - * on the host side. And so, to prevent the native IDE drivers in Linux - * from taking over these devices (to be managedby Hyper-V block - * driver), we will take over if need be the major of the IDE controllers. - * + * stor_vsc_on_cleanup - Perform any cleanup when the driver is removed */ +static void stor_vsc_on_cleanup(struct hv_driver *driver) +{ +} -int stor_vsc_get_major_info(struct storvsc_device_info *device_info, - struct storvsc_major_info *major_info) +/* + * stor_vsc_initialize - Main entry point + */ +int stor_vsc_initialize(struct hv_driver *driver) { - static bool ide0_registered; - static bool ide1_registered; + struct storvsc_driver_object *stor_driver; + + stor_driver = (struct storvsc_driver_object *)driver; + + DPRINT_DBG(STORVSC, "sizeof(STORVSC_REQUEST)=%zd " + "sizeof(struct storvsc_request_extension)=%zd " + "sizeof(struct vstor_packet)=%zd, " + "sizeof(struct vmscsi_request)=%zd", + sizeof(struct hv_storvsc_request), + sizeof(struct storvsc_request_extension), + sizeof(struct vstor_packet), + sizeof(struct vmscsi_request)); + + /* Make sure we are at least 2 pages since 1 page is used for control */ + /* ASSERT(stor_driver->RingBufferSize >= (PAGE_SIZE << 1)); */ + + driver->name = g_driver_name; + memcpy(&driver->dev_type, &gStorVscDeviceType, + sizeof(struct hv_guid)); + + stor_driver->request_ext_size = + sizeof(struct storvsc_request_extension); /* - * For now we only support IDE disks. + * Divide the ring buffer data size (which is 1 page less + * than the ring buffer size since that page is reserved for + * the ring buffer indices) by the max request size (which is + * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) */ - major_info->devname = "ide"; - major_info->diskname = "hd"; - - if (device_info->path_id) { - major_info->major = 22; - if (!ide1_registered) { - major_info->do_register = true; - ide1_registered = true; - } else - major_info->do_register = false; - - if (device_info->target_id) - major_info->index = 3; - else - major_info->index = 2; - - return 0; - } else { - major_info->major = 3; - if (!ide0_registered) { - major_info->do_register = true; - ide0_registered = true; - } else - major_info->do_register = false; - - if (device_info->target_id) - major_info->index = 1; - else - major_info->index = 0; - - return 0; - } + stor_driver->max_outstanding_req_per_channel = + ((stor_driver->ring_buffer_size - PAGE_SIZE) / + ALIGN(MAX_MULTIPAGE_BUFFER_PACKET + + sizeof(struct vstor_packet) + sizeof(u64), + sizeof(u64))); - return -ENODEV; -} + DPRINT_INFO(STORVSC, "max io %u, currently %u\n", + stor_driver->max_outstanding_req_per_channel, + STORVSC_MAX_IO_REQUESTS); -/* - * stor_vsc_on_cleanup - Perform any cleanup when the driver is removed - */ -void stor_vsc_on_cleanup(struct hv_driver *driver) -{ -} + /* Setup the dispatch table */ + stor_driver->base.dev_add = stor_vsc_on_device_add; + stor_driver->base.dev_rm = stor_vsc_on_device_remove; + stor_driver->base.cleanup = stor_vsc_on_cleanup; + stor_driver->on_io_request = stor_vsc_on_io_request; + + return 0; +} diff --git a/trunk/drivers/staging/hv/storvsc_api.h b/trunk/drivers/staging/hv/storvsc_api.h index c98139cc7baf..fbf57556d890 100644 --- a/trunk/drivers/staging/hv/storvsc_api.h +++ b/trunk/drivers/staging/hv/storvsc_api.h @@ -25,8 +25,6 @@ #ifndef _STORVSC_API_H_ #define _STORVSC_API_H_ -#include -#include "vstorage.h" #include "vmbus_api.h" /* Defines */ @@ -54,30 +52,42 @@ enum storvsc_request_type{ UNKNOWN_TYPE, }; - struct hv_storvsc_request { - struct hv_storvsc_request *request; - struct hv_device *device; - - /* Synchronize the request/response if needed */ - struct completion wait_event; + enum storvsc_request_type type; + u32 host; + u32 bus; + u32 target_id; + u32 lun_id; + u8 *cdb; + u32 cdb_len; + u32 status; + u32 bytes_xfer; unsigned char *sense_buffer; + u32 sense_buffer_size; + void *context; + void (*on_io_completion)(struct hv_storvsc_request *request); - struct hv_multipage_buffer data_buffer; - struct vstor_packet vstor_packet; -}; + /* This points to the memory after DataBuffer */ + void *extension; + struct hv_multipage_buffer data_buffer; +}; /* Represents the block vsc driver */ struct storvsc_driver_object { + /* Must be the first field */ + /* Which is a bug FIXME! */ struct hv_driver base; /* Set by caller (in bytes) */ u32 ring_buffer_size; + /* Allocate this much private extension for each I/O request */ + u32 request_ext_size; + /* Maximum # of requests in flight per channel/device */ u32 max_outstanding_req_per_channel; @@ -92,78 +102,9 @@ struct storvsc_device_info { unsigned char target_id; }; -struct storvsc_major_info { - int major; - int index; - bool do_register; - char *devname; - char *diskname; -}; - -/* A storvsc device is a device object that contains a vmbus channel */ -struct storvsc_device { - struct hv_device *device; - - /* 0 indicates the device is being destroyed */ - atomic_t ref_count; - - atomic_t num_outstanding_req; - - /* - * Each unique Port/Path/Target represents 1 channel ie scsi - * controller. In reality, the pathid, targetid is always 0 - * and the port is set by us - */ - unsigned int port_number; - unsigned char path_id; - unsigned char target_id; - - /* Used for vsc/vsp channel reset process */ - struct hv_storvsc_request init_request; - struct hv_storvsc_request reset_request; -}; - - -/* Get the stordevice object iff exists and its refcount > 1 */ -static inline struct storvsc_device *get_stor_device(struct hv_device *device) -{ - struct storvsc_device *stor_device; - - stor_device = (struct storvsc_device *)device->ext; - if (stor_device && atomic_read(&stor_device->ref_count) > 1) - atomic_inc(&stor_device->ref_count); - else - stor_device = NULL; - - return stor_device; -} - - -static inline void put_stor_device(struct hv_device *device) -{ - struct storvsc_device *stor_device; - - stor_device = (struct storvsc_device *)device->ext; - - atomic_dec(&stor_device->ref_count); -} - -static inline struct storvsc_driver_object *hvdr_to_stordr(struct hv_driver *d) -{ - return container_of(d, struct storvsc_driver_object, base); -} - /* Interface */ - -int stor_vsc_on_device_add(struct hv_device *device, - void *additional_info); -int stor_vsc_on_device_remove(struct hv_device *device); - -int stor_vsc_on_io_request(struct hv_device *device, - struct hv_storvsc_request *request); -void stor_vsc_on_cleanup(struct hv_driver *driver); - -int stor_vsc_get_major_info(struct storvsc_device_info *device_info, - struct storvsc_major_info *major_info); +int stor_vsc_initialize(struct hv_driver *driver); +int stor_vsc_on_host_reset(struct hv_device *device); +int blk_vsc_initialize(struct hv_driver *driver); #endif /* _STORVSC_API_H_ */ diff --git a/trunk/drivers/staging/hv/storvsc_drv.c b/trunk/drivers/staging/hv/storvsc_drv.c index f819c6aa8e8d..e6462a2fe9ab 100644 --- a/trunk/drivers/staging/hv/storvsc_drv.c +++ b/trunk/drivers/staging/hv/storvsc_drv.c @@ -36,20 +36,8 @@ #include "version_info.h" #include "vmbus.h" #include "storvsc_api.h" -#include "vstorage.h" -#include "channel.h" -static const char *g_driver_name = "storvsc"; - -/* {ba6163d9-04a1-4d29-b605-72e2ffb1dc7f} */ -static const struct hv_guid gStorVscDeviceType = { - .data = { - 0xd9, 0x63, 0x61, 0xba, 0xa1, 0x04, 0x29, 0x4d, - 0xb6, 0x05, 0x72, 0xe2, 0xff, 0xb1, 0xdc, 0x7f - } -}; - struct host_device_context { /* must be 1st field * FIXME this is a bug */ @@ -69,59 +57,13 @@ struct storvsc_cmd_request { struct scatterlist *bounce_sgl; struct hv_storvsc_request request; + /* !!!DO NOT ADD ANYTHING BELOW HERE!!! */ + /* The extension buffer falls right here and is pointed to by + * request.Extension; + * Which sounds like a very bad design... */ }; -/* - * stor_vsc_initialize - Main entry point - */ -static int stor_vsc_initialize(struct hv_driver *driver) -{ - struct storvsc_driver_object *stor_driver; - - stor_driver = hvdr_to_stordr(driver); - - DPRINT_DBG(STORVSC, - "sizeof(struct hv_storvsc_request)=%zd " - "sizeof(struct vstor_packet)=%zd, " - "sizeof(struct vmscsi_request)=%zd", - sizeof(struct hv_storvsc_request), - sizeof(struct vstor_packet), - sizeof(struct vmscsi_request)); - - /* Make sure we are at least 2 pages since 1 page is used for control */ - - driver->name = g_driver_name; - memcpy(&driver->dev_type, &gStorVscDeviceType, - sizeof(struct hv_guid)); - - - /* - * Divide the ring buffer data size (which is 1 page less - * than the ring buffer size since that page is reserved for - * the ring buffer indices) by the max request size (which is - * vmbus_channel_packet_multipage_buffer + struct vstor_packet + u64) - */ - stor_driver->max_outstanding_req_per_channel = - ((stor_driver->ring_buffer_size - PAGE_SIZE) / - ALIGN(MAX_MULTIPAGE_BUFFER_PACKET + - sizeof(struct vstor_packet) + sizeof(u64), - sizeof(u64))); - - DPRINT_INFO(STORVSC, "max io %u, currently %u\n", - stor_driver->max_outstanding_req_per_channel, - STORVSC_MAX_IO_REQUESTS); - - /* Setup the dispatch table */ - stor_driver->base.dev_add = stor_vsc_on_device_add; - stor_driver->base.dev_rm = stor_vsc_on_device_remove; - stor_driver->base.cleanup = stor_vsc_on_cleanup; - - stor_driver->on_io_request = stor_vsc_on_io_request; - - return 0; -} - /* Static decl */ static int storvsc_probe(struct device *dev); static int storvsc_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd); @@ -186,7 +128,7 @@ static struct scsi_host_template scsi_driver = { /* * storvsc_drv_init - StorVsc driver initialization. */ -static int storvsc_drv_init(void) +static int storvsc_drv_init(int (*drv_init)(struct hv_driver *drv)) { int ret; struct storvsc_driver_object *storvsc_drv_obj = &g_storvsc_drv; @@ -195,12 +137,13 @@ static int storvsc_drv_init(void) storvsc_drv_obj->ring_buffer_size = storvsc_ringbuffer_size; /* Callback to client driver to complete the initialization */ - stor_vsc_initialize(&storvsc_drv_obj->base); + drv_init(&storvsc_drv_obj->base); drv->priv = storvsc_drv_obj; DPRINT_INFO(STORVSC_DRV, - "max outstanding reqs %u", + "request extension size %u, max outstanding reqs %u", + storvsc_drv_obj->request_ext_size, storvsc_drv_obj->max_outstanding_req_per_channel); if (storvsc_drv_obj->max_outstanding_req_per_channel < @@ -224,61 +167,6 @@ static int storvsc_drv_init(void) return ret; } - -static int stor_vsc_on_host_reset(struct hv_device *device) -{ - struct storvsc_device *stor_device; - struct hv_storvsc_request *request; - struct vstor_packet *vstor_packet; - int ret, t; - - DPRINT_INFO(STORVSC, "resetting host adapter..."); - - stor_device = get_stor_device(device); - if (!stor_device) { - DPRINT_ERR(STORVSC, "unable to get stor device..." - "device being destroyed?"); - return -1; - } - - request = &stor_device->reset_request; - vstor_packet = &request->vstor_packet; - - init_completion(&request->wait_event); - - vstor_packet->operation = VSTOR_OPERATION_RESET_BUS; - vstor_packet->flags = REQUEST_COMPLETION_FLAG; - vstor_packet->vm_srb.path_id = stor_device->path_id; - - ret = vmbus_sendpacket(device->channel, vstor_packet, - sizeof(struct vstor_packet), - (unsigned long)&stor_device->reset_request, - VM_PKT_DATA_INBAND, - VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED); - if (ret != 0) { - DPRINT_ERR(STORVSC, "Unable to send reset packet %p ret %d", - vstor_packet, ret); - goto cleanup; - } - - t = wait_for_completion_timeout(&request->wait_event, HZ); - if (t == 0) { - ret = -ETIMEDOUT; - goto cleanup; - } - - DPRINT_INFO(STORVSC, "host adapter reset completed"); - - /* - * At this point, all outstanding requests in the adapter - * should have been flushed out and return to us - */ - -cleanup: - put_stor_device(device); - return ret; -} - static int storvsc_drv_exit_cb(struct device *dev, void *data) { struct device **curr = (struct device **)data; @@ -353,7 +241,8 @@ static int storvsc_probe(struct device *device) host_device_ctx->request_pool = kmem_cache_create(dev_name(&device_obj->device), - sizeof(struct storvsc_cmd_request), 0, + sizeof(struct storvsc_cmd_request) + + storvsc_drv_obj->request_ext_size, 0, SLAB_HWCACHE_ALIGN, NULL); if (!host_device_ctx->request_pool) { @@ -404,6 +293,7 @@ static int storvsc_probe(struct device *device) */ static int storvsc_remove(struct device *device) { + int ret; struct hv_driver *drv = drv_to_hv_drv(device->driver); struct storvsc_driver_object *storvsc_drv_obj = drv->priv; @@ -412,11 +302,20 @@ static int storvsc_remove(struct device *device) struct host_device_context *host_device_ctx = (struct host_device_context *)host->hostdata; + + if (!storvsc_drv_obj->base.dev_rm) + return -1; + /* * Call to the vsc driver to let it know that the device is being * removed */ - storvsc_drv_obj->base.dev_rm(device_obj); + ret = storvsc_drv_obj->base.dev_rm(device_obj); + if (ret != 0) { + /* TODO: */ + DPRINT_ERR(STORVSC, "unable to remove vsc device (ret %d)", + ret); + } if (host_device_ctx->request_pool) { kmem_cache_destroy(host_device_ctx->request_pool); @@ -428,7 +327,7 @@ static int storvsc_remove(struct device *device) DPRINT_INFO(STORVSC, "releasing host adapter (%p)...", host); scsi_host_put(host); - return 0; + return ret; } /* @@ -443,7 +342,6 @@ static void storvsc_commmand_completion(struct hv_storvsc_request *request) (struct host_device_context *)scmnd->device->host->hostdata; void (*scsi_done_fn)(struct scsi_cmnd *); struct scsi_sense_hdr sense_hdr; - struct vmscsi_request *vm_srb; /* ASSERT(request == &cmd_request->request); */ /* ASSERT(scmnd); */ @@ -463,19 +361,17 @@ static void storvsc_commmand_completion(struct hv_storvsc_request *request) cmd_request->bounce_sgl_count); } - vm_srb = &request->vstor_packet.vm_srb; - scmnd->result = vm_srb->scsi_status; + scmnd->result = request->status; if (scmnd->result) { if (scsi_normalize_sense(scmnd->sense_buffer, - SCSI_SENSE_BUFFERSIZE, &sense_hdr)) + request->sense_buffer_size, &sense_hdr)) scsi_print_sense_hdr("storvsc", &sense_hdr); } /* ASSERT(request->BytesXfer <= request->data_buffer.Length); */ scsi_set_resid(scmnd, - request->data_buffer.len - - vm_srb->data_transfer_length); + request->data_buffer.len - request->bytes_xfer); scsi_done_fn = scmnd->scsi_done; @@ -701,7 +597,6 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, int i; struct scatterlist *sgl; unsigned int sg_count = 0; - struct vmscsi_request *vm_srb; DPRINT_DBG(STORVSC_DRV, "scmnd %p dir %d, use_sg %d buf %p len %d " "queue depth %d tagged %d", scmnd, scmnd->sc_data_direction, @@ -728,7 +623,7 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, request_size = sizeof(struct storvsc_cmd_request); - cmd_request = kmem_cache_zalloc(host_device_ctx->request_pool, + cmd_request = kmem_cache_alloc(host_device_ctx->request_pool, GFP_ATOMIC); if (!cmd_request) { DPRINT_ERR(STORVSC_DRV, "scmnd (%p) - unable to allocate " @@ -745,20 +640,22 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, scmnd->host_scribble = (unsigned char *)cmd_request; request = &cmd_request->request; - vm_srb = &request->vstor_packet.vm_srb; - DPRINT_DBG(STORVSC_DRV, "req %p size %d", request, request_size); + request->extension = + (void *)((unsigned long)cmd_request + request_size); + DPRINT_DBG(STORVSC_DRV, "req %p size %d ext %d", request, request_size, + storvsc_drv_obj->request_ext_size); /* Build the SRB */ switch (scmnd->sc_data_direction) { case DMA_TO_DEVICE: - vm_srb->data_in = WRITE_TYPE; + request->type = WRITE_TYPE; break; case DMA_FROM_DEVICE: - vm_srb->data_in = READ_TYPE; + request->type = READ_TYPE; break; default: - vm_srb->data_in = UNKNOWN_TYPE; + request->type = UNKNOWN_TYPE; break; } @@ -766,17 +663,17 @@ static int storvsc_queuecommand_lck(struct scsi_cmnd *scmnd, request->context = cmd_request;/* scmnd; */ /* request->PortId = scmnd->device->channel; */ - vm_srb->port_number = host_device_ctx->port; - vm_srb->path_id = scmnd->device->channel; - vm_srb->target_id = scmnd->device->id; - vm_srb->lun = scmnd->device->lun; + request->host = host_device_ctx->port; + request->bus = scmnd->device->channel; + request->target_id = scmnd->device->id; + request->lun_id = scmnd->device->lun; /* ASSERT(scmnd->cmd_len <= 16); */ - vm_srb->cdb_length = scmnd->cmd_len; - - memcpy(vm_srb->cdb, scmnd->cmnd, vm_srb->cdb_length); + request->cdb_len = scmnd->cmd_len; + request->cdb = scmnd->cmnd; request->sense_buffer = scmnd->sense_buffer; + request->sense_buffer_size = SCSI_SENSE_BUFFERSIZE; request->data_buffer.len = scsi_bufflen(scmnd); @@ -1026,7 +923,7 @@ static int __init storvsc_init(void) int ret; DPRINT_INFO(STORVSC_DRV, "Storvsc initializing...."); - ret = storvsc_drv_init(); + ret = storvsc_drv_init(stor_vsc_initialize); return ret; } diff --git a/trunk/drivers/staging/hv/vmbus_drv.c b/trunk/drivers/staging/hv/vmbus_drv.c index c85d79614f27..79089f85d903 100644 --- a/trunk/drivers/staging/hv/vmbus_drv.c +++ b/trunk/drivers/staging/hv/vmbus_drv.c @@ -17,11 +17,7 @@ * Authors: * Haiyang Zhang * Hank Janssen - * - * 3/9/2011: K. Y. Srinivasan - Significant restructuring and cleanup */ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -40,169 +36,43 @@ #include "vmbus_private.h" -struct pci_dev *hv_pci_dev; +/* FIXME! We need to do this dynamically for PIC and APIC system */ +#define VMBUS_IRQ 0x5 +#define VMBUS_IRQ_VECTOR IRQ5_VECTOR /* Main vmbus driver data structure */ -struct hv_bus { +struct vmbus_driver_context { + struct bus_type bus; struct tasklet_struct msg_dpc; struct tasklet_struct event_dpc; -}; - -unsigned int vmbus_loglevel = (ALL_MODULES << 16 | INFO_LVL); -EXPORT_SYMBOL(vmbus_loglevel); - /* (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */ - /* (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */ - - -static void get_channel_info(struct hv_device *device, - struct hv_device_info *info) -{ - struct vmbus_channel_debug_info debug_info; - - if (!device->channel) - return; - - vmbus_get_debug_info(device->channel, &debug_info); - - info->chn_id = debug_info.relid; - info->chn_state = debug_info.state; - memcpy(&info->chn_type, &debug_info.interfacetype, - sizeof(struct hv_guid)); - memcpy(&info->chn_instance, &debug_info.interface_instance, - sizeof(struct hv_guid)); - - info->monitor_id = debug_info.monitorid; - info->server_monitor_pending = debug_info.servermonitor_pending; - info->server_monitor_latency = debug_info.servermonitor_latency; - info->server_monitor_conn_id = debug_info.servermonitor_connectionid; + /* The bus root device */ + struct hv_device device_ctx; +}; - info->client_monitor_pending = debug_info.clientmonitor_pending; - info->client_monitor_latency = debug_info.clientmonitor_latency; - info->client_monitor_conn_id = debug_info.clientmonitor_connectionid; +static int vmbus_match(struct device *device, struct device_driver *driver); +static int vmbus_probe(struct device *device); +static int vmbus_remove(struct device *device); +static void vmbus_shutdown(struct device *device); +static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env); - info->inbound.int_mask = debug_info.inbound.current_interrupt_mask; - info->inbound.read_idx = debug_info.inbound.current_read_index; - info->inbound.write_idx = debug_info.inbound.current_write_index; - info->inbound.bytes_avail_toread = - debug_info.inbound.bytes_avail_toread; - info->inbound.bytes_avail_towrite = - debug_info.inbound.bytes_avail_towrite; +static irqreturn_t vmbus_isr(int irq, void *dev_id); - info->outbound.int_mask = - debug_info.outbound.current_interrupt_mask; - info->outbound.read_idx = debug_info.outbound.current_read_index; - info->outbound.write_idx = debug_info.outbound.current_write_index; - info->outbound.bytes_avail_toread = - debug_info.outbound.bytes_avail_toread; - info->outbound.bytes_avail_towrite = - debug_info.outbound.bytes_avail_towrite; -} +static void vmbus_device_release(struct device *device); +static void vmbus_bus_release(struct device *device); -/* - * vmbus_show_device_attr - Show the device attribute in sysfs. - * - * This is invoked when user does a - * "cat /sys/bus/vmbus/devices//" - */ static ssize_t vmbus_show_device_attr(struct device *dev, struct device_attribute *dev_attr, - char *buf) -{ - struct hv_device *device_ctx = device_to_hv_device(dev); - struct hv_device_info device_info; + char *buf); - memset(&device_info, 0, sizeof(struct hv_device_info)); - get_channel_info(device_ctx, &device_info); +unsigned int vmbus_loglevel = (ALL_MODULES << 16 | INFO_LVL); +EXPORT_SYMBOL(vmbus_loglevel); + /* (ALL_MODULES << 16 | DEBUG_LVL_ENTEREXIT); */ + /* (((VMBUS | VMBUS_DRV)<<16) | DEBUG_LVL_ENTEREXIT); */ - if (!strcmp(dev_attr->attr.name, "class_id")) { - return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" - "%02x%02x%02x%02x%02x%02x%02x%02x}\n", - device_info.chn_type.data[3], - device_info.chn_type.data[2], - device_info.chn_type.data[1], - device_info.chn_type.data[0], - device_info.chn_type.data[5], - device_info.chn_type.data[4], - device_info.chn_type.data[7], - device_info.chn_type.data[6], - device_info.chn_type.data[8], - device_info.chn_type.data[9], - device_info.chn_type.data[10], - device_info.chn_type.data[11], - device_info.chn_type.data[12], - device_info.chn_type.data[13], - device_info.chn_type.data[14], - device_info.chn_type.data[15]); - } else if (!strcmp(dev_attr->attr.name, "device_id")) { - return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" - "%02x%02x%02x%02x%02x%02x%02x%02x}\n", - device_info.chn_instance.data[3], - device_info.chn_instance.data[2], - device_info.chn_instance.data[1], - device_info.chn_instance.data[0], - device_info.chn_instance.data[5], - device_info.chn_instance.data[4], - device_info.chn_instance.data[7], - device_info.chn_instance.data[6], - device_info.chn_instance.data[8], - device_info.chn_instance.data[9], - device_info.chn_instance.data[10], - device_info.chn_instance.data[11], - device_info.chn_instance.data[12], - device_info.chn_instance.data[13], - device_info.chn_instance.data[14], - device_info.chn_instance.data[15]); - } else if (!strcmp(dev_attr->attr.name, "state")) { - return sprintf(buf, "%d\n", device_info.chn_state); - } else if (!strcmp(dev_attr->attr.name, "id")) { - return sprintf(buf, "%d\n", device_info.chn_id); - } else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) { - return sprintf(buf, "%d\n", device_info.outbound.int_mask); - } else if (!strcmp(dev_attr->attr.name, "out_read_index")) { - return sprintf(buf, "%d\n", device_info.outbound.read_idx); - } else if (!strcmp(dev_attr->attr.name, "out_write_index")) { - return sprintf(buf, "%d\n", device_info.outbound.write_idx); - } else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) { - return sprintf(buf, "%d\n", - device_info.outbound.bytes_avail_toread); - } else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) { - return sprintf(buf, "%d\n", - device_info.outbound.bytes_avail_towrite); - } else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) { - return sprintf(buf, "%d\n", device_info.inbound.int_mask); - } else if (!strcmp(dev_attr->attr.name, "in_read_index")) { - return sprintf(buf, "%d\n", device_info.inbound.read_idx); - } else if (!strcmp(dev_attr->attr.name, "in_write_index")) { - return sprintf(buf, "%d\n", device_info.inbound.write_idx); - } else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) { - return sprintf(buf, "%d\n", - device_info.inbound.bytes_avail_toread); - } else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) { - return sprintf(buf, "%d\n", - device_info.inbound.bytes_avail_towrite); - } else if (!strcmp(dev_attr->attr.name, "monitor_id")) { - return sprintf(buf, "%d\n", device_info.monitor_id); - } else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) { - return sprintf(buf, "%d\n", device_info.server_monitor_pending); - } else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) { - return sprintf(buf, "%d\n", device_info.server_monitor_latency); - } else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) { - return sprintf(buf, "%d\n", - device_info.server_monitor_conn_id); - } else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) { - return sprintf(buf, "%d\n", device_info.client_monitor_pending); - } else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) { - return sprintf(buf, "%d\n", device_info.client_monitor_latency); - } else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) { - return sprintf(buf, "%d\n", - device_info.client_monitor_conn_id); - } else { - return 0; - } -} +static int vmbus_irq = VMBUS_IRQ; /* Set up per device attributes in /sys/bus/vmbus/devices/ */ static struct device_attribute vmbus_device_attrs[] = { @@ -234,215 +104,68 @@ static struct device_attribute vmbus_device_attrs[] = { __ATTR_NULL }; +/* The one and only one */ +static struct vmbus_driver_context vmbus_drv = { + .bus.name = "vmbus", + .bus.match = vmbus_match, + .bus.shutdown = vmbus_shutdown, + .bus.remove = vmbus_remove, + .bus.probe = vmbus_probe, + .bus.uevent = vmbus_uevent, + .bus.dev_attrs = vmbus_device_attrs, +}; -/* - * vmbus_uevent - add uevent for our device - * - * This routine is invoked when a device is added or removed on the vmbus to - * generate a uevent to udev in the userspace. The udev will then look at its - * rule and the uevent generated here to load the appropriate driver - */ -static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) -{ - struct hv_device *dev = device_to_hv_device(device); - int ret; - - ret = add_uevent_var(env, "VMBUS_DEVICE_CLASS_GUID={" - "%02x%02x%02x%02x-%02x%02x-%02x%02x-" - "%02x%02x%02x%02x%02x%02x%02x%02x}", - dev->dev_type.data[3], - dev->dev_type.data[2], - dev->dev_type.data[1], - dev->dev_type.data[0], - dev->dev_type.data[5], - dev->dev_type.data[4], - dev->dev_type.data[7], - dev->dev_type.data[6], - dev->dev_type.data[8], - dev->dev_type.data[9], - dev->dev_type.data[10], - dev->dev_type.data[11], - dev->dev_type.data[12], - dev->dev_type.data[13], - dev->dev_type.data[14], - dev->dev_type.data[15]); - - if (ret) - return ret; - - ret = add_uevent_var(env, "VMBUS_DEVICE_DEVICE_GUID={" - "%02x%02x%02x%02x-%02x%02x-%02x%02x-" - "%02x%02x%02x%02x%02x%02x%02x%02x}", - dev->dev_instance.data[3], - dev->dev_instance.data[2], - dev->dev_instance.data[1], - dev->dev_instance.data[0], - dev->dev_instance.data[5], - dev->dev_instance.data[4], - dev->dev_instance.data[7], - dev->dev_instance.data[6], - dev->dev_instance.data[8], - dev->dev_instance.data[9], - dev->dev_instance.data[10], - dev->dev_instance.data[11], - dev->dev_instance.data[12], - dev->dev_instance.data[13], - dev->dev_instance.data[14], - dev->dev_instance.data[15]); - if (ret) - return ret; - - return 0; -} - - -/* - * vmbus_match - Attempt to match the specified device to the specified driver - */ -static int vmbus_match(struct device *device, struct device_driver *driver) -{ - int match = 0; - struct hv_driver *drv = drv_to_hv_drv(driver); - struct hv_device *device_ctx = device_to_hv_device(device); - - /* We found our driver ? */ - if (memcmp(&device_ctx->dev_type, &drv->dev_type, - sizeof(struct hv_guid)) == 0) { - - device_ctx->drv = drv->priv; - - match = 1; - } - return match; -} - - -/* - * vmbus_probe_failed_cb - Callback when a driver probe failed in vmbus_probe() - * - * We need a callback because we cannot invoked device_unregister() inside - * vmbus_probe() since vmbus_probe() may be invoked inside device_register() - * i.e. we cannot call device_unregister() inside device_register() - */ -static void vmbus_probe_failed_cb(struct work_struct *context) -{ - struct hv_device *device_ctx = (struct hv_device *)context; - - /* - * Kick off the process of unregistering the device. - * This will call vmbus_remove() and eventually vmbus_device_release() - */ - device_unregister(&device_ctx->device); - - /* put_device(&device_ctx->device); */ -} +static const char *driver_name = "hyperv"; /* - * vmbus_probe - Add the new vmbus's child device + * Windows vmbus does not defined this. + * We defined this to be consistent with other devices */ -static int vmbus_probe(struct device *child_device) -{ - int ret = 0; - struct hv_driver *drv = - drv_to_hv_drv(child_device->driver); - struct hv_device *dev = device_to_hv_device(child_device); - - /* Let the specific open-source driver handles the probe if it can */ - if (drv->driver.probe) { - ret = dev->probe_error = - drv->driver.probe(child_device); - if (ret != 0) { - pr_err("probe failed for device %s (%d)\n", - dev_name(child_device), ret); - - INIT_WORK(&dev->probe_failed_work_item, - vmbus_probe_failed_cb); - schedule_work(&dev->probe_failed_work_item); - } - } else { - pr_err("probe not set for driver %s\n", - dev_name(child_device)); - ret = -1; +/* {c5295816-f63a-4d5f-8d1a-4daf999ca185} */ +static const struct hv_guid device_type = { + .data = { + 0x16, 0x58, 0x29, 0xc5, 0x3a, 0xf6, 0x5f, 0x4d, + 0x8d, 0x1a, 0x4d, 0xaf, 0x99, 0x9c, 0xa1, 0x85 } - return ret; -} - -/* - * vmbus_remove - Remove a vmbus device - */ -static int vmbus_remove(struct device *child_device) -{ - int ret; - struct hv_driver *drv; - - - if (child_device->driver) { - drv = drv_to_hv_drv(child_device->driver); +}; - /* - * Let the specific open-source driver handles the removal if - * it can - */ - if (drv->driver.remove) { - ret = drv->driver.remove(child_device); - } else { - pr_err("remove not set for driver %s\n", - dev_name(child_device)); - ret = -1; - } +/* {ac3760fc-9adf-40aa-9427-a70ed6de95c5} */ +static const struct hv_guid device_id = { + .data = { + 0xfc, 0x60, 0x37, 0xac, 0xdf, 0x9a, 0xaa, 0x40, + 0x94, 0x27, 0xa7, 0x0e, 0xd6, 0xde, 0x95, 0xc5 } +}; - return 0; -} +static struct hv_device *vmbus_device; /* vmbus root device */ /* - * vmbus_shutdown - Shutdown a vmbus device + * vmbus_dev_add - Callback when the root bus device is added */ -static void vmbus_shutdown(struct device *child_device) +static int vmbus_dev_add(struct hv_device *dev, void *info) { - struct hv_driver *drv; + u32 *irqvector = info; + int ret; + vmbus_device = dev; - /* The device may not be attached yet */ - if (!child_device->driver) - return; + memcpy(&vmbus_device->dev_type, &device_type, sizeof(struct hv_guid)); + memcpy(&vmbus_device->dev_instance, &device_id, + sizeof(struct hv_guid)); - drv = drv_to_hv_drv(child_device->driver); + /* strcpy(dev->name, "vmbus"); */ + /* SynIC setup... */ + on_each_cpu(hv_synic_init, (void *)irqvector, 1); - /* Let the specific open-source driver handles the removal if it can */ - if (drv->driver.shutdown) - drv->driver.shutdown(child_device); + /* Connect to VMBus in the root partition */ + ret = vmbus_connect(); - return; + /* VmbusSendEvent(device->localPortId+1); */ + return ret; } -/* - * vmbus_device_release - Final callback release of the vmbus child device - */ -static void vmbus_device_release(struct device *device) -{ - struct hv_device *device_ctx = device_to_hv_device(device); - - kfree(device_ctx); - -} - -/* The one and only one */ -static struct hv_bus hv_bus = { - .bus.name = "vmbus", - .bus.match = vmbus_match, - .bus.shutdown = vmbus_shutdown, - .bus.remove = vmbus_remove, - .bus.probe = vmbus_probe, - .bus.uevent = vmbus_uevent, - .bus.dev_attrs = vmbus_device_attrs, -}; - -static const char *driver_name = "hyperv"; - - struct onmessage_work_context { struct work_struct work; struct hv_message msg; @@ -519,38 +242,172 @@ static int vmbus_on_isr(void) msg = (struct hv_message *)page_addr + VMBUS_MESSAGE_SINT; /* Check if there are actual msgs to be process */ - if (msg->header.message_type != HVMSG_NONE) + if (msg->header.message_type != HVMSG_NONE) { + DPRINT_DBG(VMBUS, "received msg type %d size %d", + msg->header.message_type, + msg->header.payload_size); ret |= 0x1; + } /* TODO: Check if there are events to be process */ page_addr = hv_context.synic_event_page[cpu]; event = (union hv_synic_event_flags *)page_addr + VMBUS_MESSAGE_SINT; /* Since we are a child, we only need to check bit 0 */ - if (sync_test_and_clear_bit(0, (unsigned long *) &event->flags32[0])) + if (sync_test_and_clear_bit(0, (unsigned long *) &event->flags32[0])) { + DPRINT_DBG(VMBUS, "received event %d", event->flags32[0]); ret |= 0x2; + } return ret; } - -static irqreturn_t vmbus_isr(int irq, void *dev_id) +static void get_channel_info(struct hv_device *device, + struct hv_device_info *info) { - int ret; + struct vmbus_channel_debug_info debug_info; - ret = vmbus_on_isr(); + if (!device->channel) + return; - /* Schedules a dpc if necessary */ - if (ret > 0) { - if (test_bit(0, (unsigned long *)&ret)) - tasklet_schedule(&hv_bus.msg_dpc); + vmbus_get_debug_info(device->channel, &debug_info); - if (test_bit(1, (unsigned long *)&ret)) - tasklet_schedule(&hv_bus.event_dpc); + info->chn_id = debug_info.relid; + info->chn_state = debug_info.state; + memcpy(&info->chn_type, &debug_info.interfacetype, + sizeof(struct hv_guid)); + memcpy(&info->chn_instance, &debug_info.interface_instance, + sizeof(struct hv_guid)); - return IRQ_HANDLED; + info->monitor_id = debug_info.monitorid; + + info->server_monitor_pending = debug_info.servermonitor_pending; + info->server_monitor_latency = debug_info.servermonitor_latency; + info->server_monitor_conn_id = debug_info.servermonitor_connectionid; + + info->client_monitor_pending = debug_info.clientmonitor_pending; + info->client_monitor_latency = debug_info.clientmonitor_latency; + info->client_monitor_conn_id = debug_info.clientmonitor_connectionid; + + info->inbound.int_mask = debug_info.inbound.current_interrupt_mask; + info->inbound.read_idx = debug_info.inbound.current_read_index; + info->inbound.write_idx = debug_info.inbound.current_write_index; + info->inbound.bytes_avail_toread = + debug_info.inbound.bytes_avail_toread; + info->inbound.bytes_avail_towrite = + debug_info.inbound.bytes_avail_towrite; + + info->outbound.int_mask = + debug_info.outbound.current_interrupt_mask; + info->outbound.read_idx = debug_info.outbound.current_read_index; + info->outbound.write_idx = debug_info.outbound.current_write_index; + info->outbound.bytes_avail_toread = + debug_info.outbound.bytes_avail_toread; + info->outbound.bytes_avail_towrite = + debug_info.outbound.bytes_avail_towrite; +} + +/* + * vmbus_show_device_attr - Show the device attribute in sysfs. + * + * This is invoked when user does a + * "cat /sys/bus/vmbus/devices//" + */ +static ssize_t vmbus_show_device_attr(struct device *dev, + struct device_attribute *dev_attr, + char *buf) +{ + struct hv_device *device_ctx = device_to_hv_device(dev); + struct hv_device_info device_info; + + memset(&device_info, 0, sizeof(struct hv_device_info)); + + get_channel_info(device_ctx, &device_info); + + if (!strcmp(dev_attr->attr.name, "class_id")) { + return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x%02x%02x}\n", + device_info.chn_type.data[3], + device_info.chn_type.data[2], + device_info.chn_type.data[1], + device_info.chn_type.data[0], + device_info.chn_type.data[5], + device_info.chn_type.data[4], + device_info.chn_type.data[7], + device_info.chn_type.data[6], + device_info.chn_type.data[8], + device_info.chn_type.data[9], + device_info.chn_type.data[10], + device_info.chn_type.data[11], + device_info.chn_type.data[12], + device_info.chn_type.data[13], + device_info.chn_type.data[14], + device_info.chn_type.data[15]); + } else if (!strcmp(dev_attr->attr.name, "device_id")) { + return sprintf(buf, "{%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x%02x%02x}\n", + device_info.chn_instance.data[3], + device_info.chn_instance.data[2], + device_info.chn_instance.data[1], + device_info.chn_instance.data[0], + device_info.chn_instance.data[5], + device_info.chn_instance.data[4], + device_info.chn_instance.data[7], + device_info.chn_instance.data[6], + device_info.chn_instance.data[8], + device_info.chn_instance.data[9], + device_info.chn_instance.data[10], + device_info.chn_instance.data[11], + device_info.chn_instance.data[12], + device_info.chn_instance.data[13], + device_info.chn_instance.data[14], + device_info.chn_instance.data[15]); + } else if (!strcmp(dev_attr->attr.name, "state")) { + return sprintf(buf, "%d\n", device_info.chn_state); + } else if (!strcmp(dev_attr->attr.name, "id")) { + return sprintf(buf, "%d\n", device_info.chn_id); + } else if (!strcmp(dev_attr->attr.name, "out_intr_mask")) { + return sprintf(buf, "%d\n", device_info.outbound.int_mask); + } else if (!strcmp(dev_attr->attr.name, "out_read_index")) { + return sprintf(buf, "%d\n", device_info.outbound.read_idx); + } else if (!strcmp(dev_attr->attr.name, "out_write_index")) { + return sprintf(buf, "%d\n", device_info.outbound.write_idx); + } else if (!strcmp(dev_attr->attr.name, "out_read_bytes_avail")) { + return sprintf(buf, "%d\n", + device_info.outbound.bytes_avail_toread); + } else if (!strcmp(dev_attr->attr.name, "out_write_bytes_avail")) { + return sprintf(buf, "%d\n", + device_info.outbound.bytes_avail_towrite); + } else if (!strcmp(dev_attr->attr.name, "in_intr_mask")) { + return sprintf(buf, "%d\n", device_info.inbound.int_mask); + } else if (!strcmp(dev_attr->attr.name, "in_read_index")) { + return sprintf(buf, "%d\n", device_info.inbound.read_idx); + } else if (!strcmp(dev_attr->attr.name, "in_write_index")) { + return sprintf(buf, "%d\n", device_info.inbound.write_idx); + } else if (!strcmp(dev_attr->attr.name, "in_read_bytes_avail")) { + return sprintf(buf, "%d\n", + device_info.inbound.bytes_avail_toread); + } else if (!strcmp(dev_attr->attr.name, "in_write_bytes_avail")) { + return sprintf(buf, "%d\n", + device_info.inbound.bytes_avail_towrite); + } else if (!strcmp(dev_attr->attr.name, "monitor_id")) { + return sprintf(buf, "%d\n", device_info.monitor_id); + } else if (!strcmp(dev_attr->attr.name, "server_monitor_pending")) { + return sprintf(buf, "%d\n", device_info.server_monitor_pending); + } else if (!strcmp(dev_attr->attr.name, "server_monitor_latency")) { + return sprintf(buf, "%d\n", device_info.server_monitor_latency); + } else if (!strcmp(dev_attr->attr.name, "server_monitor_conn_id")) { + return sprintf(buf, "%d\n", + device_info.server_monitor_conn_id); + } else if (!strcmp(dev_attr->attr.name, "client_monitor_pending")) { + return sprintf(buf, "%d\n", device_info.client_monitor_pending); + } else if (!strcmp(dev_attr->attr.name, "client_monitor_latency")) { + return sprintf(buf, "%d\n", device_info.client_monitor_latency); + } else if (!strcmp(dev_attr->attr.name, "client_monitor_conn_id")) { + return sprintf(buf, "%d\n", + device_info.client_monitor_conn_id); } else { - return IRQ_NONE; + return 0; } } @@ -559,64 +416,111 @@ static irqreturn_t vmbus_isr(int irq, void *dev_id) * * Here, we * - initialize the vmbus driver context + * - setup various driver entry points * - invoke the vmbus hv main init routine * - get the irq resource + * - invoke the vmbus to add the vmbus root device + * - setup the vmbus root device * - retrieve the channel offers */ -static int vmbus_bus_init(struct pci_dev *pdev) +static int vmbus_bus_init(void) { + struct vmbus_driver_context *vmbus_drv_ctx = &vmbus_drv; + struct hv_device *dev_ctx = &vmbus_drv.device_ctx; int ret; unsigned int vector; + DPRINT_INFO(VMBUS, "+++++++ HV Driver version = %s +++++++", + HV_DRV_VERSION); + DPRINT_INFO(VMBUS, "+++++++ Vmbus supported version = %d +++++++", + VMBUS_REVISION_NUMBER); + DPRINT_INFO(VMBUS, "+++++++ Vmbus using SINT %d +++++++", + VMBUS_MESSAGE_SINT); + DPRINT_DBG(VMBUS, "sizeof(vmbus_channel_packet_page_buffer)=%zd, " + "sizeof(VMBUS_CHANNEL_PACKET_MULITPAGE_BUFFER)=%zd", + sizeof(struct vmbus_channel_packet_page_buffer), + sizeof(struct vmbus_channel_packet_multipage_buffer)); + + /* Hypervisor initialization...setup hypercall page..etc */ ret = hv_init(); if (ret != 0) { - pr_err("Unable to initialize the hypervisor - 0x%x\n", ret); + DPRINT_ERR(VMBUS, "Unable to initialize the hypervisor - 0x%x", + ret); goto cleanup; } - hv_bus.bus.name = driver_name; + + vmbus_drv_ctx->bus.name = driver_name; /* Initialize the bus context */ - tasklet_init(&hv_bus.msg_dpc, vmbus_on_msg_dpc, 0); - tasklet_init(&hv_bus.event_dpc, vmbus_on_event, 0); + tasklet_init(&vmbus_drv_ctx->msg_dpc, vmbus_on_msg_dpc, + (unsigned long)NULL); + tasklet_init(&vmbus_drv_ctx->event_dpc, vmbus_on_event, + (unsigned long)NULL); /* Now, register the bus with LDM */ - ret = bus_register(&hv_bus.bus); + ret = bus_register(&vmbus_drv_ctx->bus); if (ret) { ret = -1; goto cleanup; } /* Get the interrupt resource */ - ret = request_irq(pdev->irq, vmbus_isr, - IRQF_SHARED | IRQF_SAMPLE_RANDOM, - driver_name, pdev); + ret = request_irq(vmbus_irq, vmbus_isr, IRQF_SAMPLE_RANDOM, + driver_name, NULL); if (ret != 0) { - pr_err("Unable to request IRQ %d\n", - pdev->irq); + DPRINT_ERR(VMBUS_DRV, "ERROR - Unable to request IRQ %d", + vmbus_irq); - bus_unregister(&hv_bus.bus); + bus_unregister(&vmbus_drv_ctx->bus); ret = -1; goto cleanup; } + vector = VMBUS_IRQ_VECTOR; - vector = IRQ0_VECTOR + pdev->irq; + DPRINT_INFO(VMBUS_DRV, "irq 0x%x vector 0x%x", vmbus_irq, vector); - /* - * Notify the hypervisor of our irq and - * connect to the host. - */ - on_each_cpu(hv_synic_init, (void *)&vector, 1); - ret = vmbus_connect(); - if (ret) { - free_irq(pdev->irq, pdev); - bus_unregister(&hv_bus.bus); + /* Add the root device */ + memset(dev_ctx, 0, sizeof(struct hv_device)); + + ret = vmbus_dev_add(dev_ctx, &vector); + if (ret != 0) { + DPRINT_ERR(VMBUS_DRV, + "ERROR - Unable to add vmbus root device"); + + free_irq(vmbus_irq, NULL); + + bus_unregister(&vmbus_drv_ctx->bus); + + ret = -1; goto cleanup; } + /* strcpy(dev_ctx->device.bus_id, dev_ctx->device_obj.name); */ + dev_set_name(&dev_ctx->device, "vmbus_0_0"); + + /* No need to bind a driver to the root device. */ + dev_ctx->device.parent = NULL; + /* NULL; vmbus_remove() does not get invoked */ + dev_ctx->device.bus = &vmbus_drv_ctx->bus; + + /* Setup the device dispatch table */ + dev_ctx->device.release = vmbus_bus_release; + + /* register the root device */ + ret = device_register(&dev_ctx->device); + if (ret) { + DPRINT_ERR(VMBUS_DRV, + "ERROR - Unable to register vmbus root device"); + + free_irq(vmbus_irq, NULL); + bus_unregister(&vmbus_drv_ctx->bus); + ret = -1; + goto cleanup; + } vmbus_request_offers(); wait_for_completion(&hv_channel_ready); @@ -632,7 +536,9 @@ static int vmbus_bus_init(struct pci_dev *pdev) */ static void vmbus_bus_exit(void) { + struct vmbus_driver_context *vmbus_drv_ctx = &vmbus_drv; + struct hv_device *dev_ctx = &vmbus_drv.device_ctx; vmbus_release_unattached_channels(); vmbus_disconnect(); @@ -640,12 +546,15 @@ static void vmbus_bus_exit(void) hv_cleanup(); - bus_unregister(&hv_bus.bus); + /* Unregister the root bus device */ + device_unregister(&dev_ctx->device); + + bus_unregister(&vmbus_drv_ctx->bus); - free_irq(hv_pci_dev->irq, hv_pci_dev); + free_irq(vmbus_irq, NULL); - tasklet_kill(&hv_bus.msg_dpc); - tasklet_kill(&hv_bus.event_dpc); + tasklet_kill(&vmbus_drv_ctx->msg_dpc); + tasklet_kill(&vmbus_drv_ctx->event_dpc); } @@ -664,10 +573,11 @@ int vmbus_child_driver_register(struct device_driver *drv) { int ret; - pr_info("child driver registering - name %s\n", drv->name); + DPRINT_INFO(VMBUS_DRV, "child driver (%p) registering - name %s", + drv, drv->name); /* The child driver on this vmbus */ - drv->bus = &hv_bus.bus; + drv->bus = &vmbus_drv.bus; ret = driver_register(drv); @@ -689,7 +599,8 @@ EXPORT_SYMBOL(vmbus_child_driver_register); */ void vmbus_child_driver_unregister(struct device_driver *drv) { - pr_info("child driver unregistering - name %s\n", drv->name); + DPRINT_INFO(VMBUS_DRV, "child driver (%p) unregistering - name %s", + drv, drv->name); driver_unregister(drv); @@ -710,10 +621,30 @@ struct hv_device *vmbus_child_device_create(struct hv_guid *type, /* Allocate the new child device */ child_device_obj = kzalloc(sizeof(struct hv_device), GFP_KERNEL); if (!child_device_obj) { - pr_err("Unable to allocate device object for child device\n"); + DPRINT_ERR(VMBUS_DRV, + "unable to allocate device_context for child device"); return NULL; } + DPRINT_DBG(VMBUS_DRV, "child device (%p) allocated - " + "type {%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x%02x%02x}," + "id {%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x%02x%02x}", + &child_device_obj->device, + type->data[3], type->data[2], type->data[1], type->data[0], + type->data[5], type->data[4], type->data[7], type->data[6], + type->data[8], type->data[9], type->data[10], type->data[11], + type->data[12], type->data[13], type->data[14], type->data[15], + instance->data[3], instance->data[2], + instance->data[1], instance->data[0], + instance->data[5], instance->data[4], + instance->data[7], instance->data[6], + instance->data[8], instance->data[9], + instance->data[10], instance->data[11], + instance->data[12], instance->data[13], + instance->data[14], instance->data[15]); + child_device_obj->channel = channel; memcpy(&child_device_obj->dev_type, type, sizeof(struct hv_guid)); memcpy(&child_device_obj->dev_instance, instance, @@ -732,13 +663,16 @@ int vmbus_child_device_register(struct hv_device *child_device_obj) static atomic_t device_num = ATOMIC_INIT(0); + DPRINT_DBG(VMBUS_DRV, "child device (%p) registering", + child_device_obj); + /* Set the device name. Otherwise, device_register() will fail. */ dev_set_name(&child_device_obj->device, "vmbus_0_%d", atomic_inc_return(&device_num)); /* The new device belongs to this bus */ - child_device_obj->device.bus = &hv_bus.bus; /* device->dev.bus; */ - child_device_obj->device.parent = &hv_pci_dev->dev; + child_device_obj->device.bus = &vmbus_drv.bus; /* device->dev.bus; */ + child_device_obj->device.parent = &vmbus_device->device; child_device_obj->device.release = vmbus_device_release; /* @@ -751,10 +685,11 @@ int vmbus_child_device_register(struct hv_device *child_device_obj) ret = child_device_obj->probe_error; if (ret) - pr_err("Unable to register child device\n"); + DPRINT_ERR(VMBUS_DRV, "unable to register child device (%p)", + &child_device_obj->device); else - pr_info("child device %s registered\n", - dev_name(&child_device_obj->device)); + DPRINT_INFO(VMBUS_DRV, "child device (%p) registered", + &child_device_obj->device); return ret; } @@ -765,69 +700,331 @@ int vmbus_child_device_register(struct hv_device *child_device_obj) */ void vmbus_child_device_unregister(struct hv_device *device_obj) { + + DPRINT_INFO(VMBUS_DRV, "unregistering child device (%p)", + &device_obj->device); + /* * Kick off the process of unregistering the device. * This will call vmbus_remove() and eventually vmbus_device_release() */ device_unregister(&device_obj->device); - pr_info("child device %s unregistered\n", - dev_name(&device_obj->device)); + DPRINT_INFO(VMBUS_DRV, "child device (%p) unregistered", + &device_obj->device); } +/* + * vmbus_uevent - add uevent for our device + * + * This routine is invoked when a device is added or removed on the vmbus to + * generate a uevent to udev in the userspace. The udev will then look at its + * rule and the uevent generated here to load the appropriate driver + */ +static int vmbus_uevent(struct device *device, struct kobj_uevent_env *env) +{ + struct hv_device *dev = device_to_hv_device(device); + int ret; + + DPRINT_INFO(VMBUS_DRV, "generating uevent - VMBUS_DEVICE_CLASS_GUID={" + "%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x%02x%02x}", + dev->dev_type.data[3], dev->dev_type.data[2], + dev->dev_type.data[1], dev->dev_type.data[0], + dev->dev_type.data[5], dev->dev_type.data[4], + dev->dev_type.data[7], dev->dev_type.data[6], + dev->dev_type.data[8], dev->dev_type.data[9], + dev->dev_type.data[10], + dev->dev_type.data[11], + dev->dev_type.data[12], + dev->dev_type.data[13], + dev->dev_type.data[14], + dev->dev_type.data[15]); + + ret = add_uevent_var(env, "VMBUS_DEVICE_CLASS_GUID={" + "%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x%02x%02x}", + dev->dev_type.data[3], + dev->dev_type.data[2], + dev->dev_type.data[1], + dev->dev_type.data[0], + dev->dev_type.data[5], + dev->dev_type.data[4], + dev->dev_type.data[7], + dev->dev_type.data[6], + dev->dev_type.data[8], + dev->dev_type.data[9], + dev->dev_type.data[10], + dev->dev_type.data[11], + dev->dev_type.data[12], + dev->dev_type.data[13], + dev->dev_type.data[14], + dev->dev_type.data[15]); + + if (ret) + return ret; + + ret = add_uevent_var(env, "VMBUS_DEVICE_DEVICE_GUID={" + "%02x%02x%02x%02x-%02x%02x-%02x%02x-" + "%02x%02x%02x%02x%02x%02x%02x%02x}", + dev->dev_instance.data[3], + dev->dev_instance.data[2], + dev->dev_instance.data[1], + dev->dev_instance.data[0], + dev->dev_instance.data[5], + dev->dev_instance.data[4], + dev->dev_instance.data[7], + dev->dev_instance.data[6], + dev->dev_instance.data[8], + dev->dev_instance.data[9], + dev->dev_instance.data[10], + dev->dev_instance.data[11], + dev->dev_instance.data[12], + dev->dev_instance.data[13], + dev->dev_instance.data[14], + dev->dev_instance.data[15]); + if (ret) + return ret; + + return 0; +} -static int __devinit hv_pci_probe(struct pci_dev *pdev, - const struct pci_device_id *ent) +/* + * vmbus_match - Attempt to match the specified device to the specified driver + */ +static int vmbus_match(struct device *device, struct device_driver *driver) { - int err; + int match = 0; + struct hv_driver *drv = drv_to_hv_drv(driver); + struct hv_device *device_ctx = device_to_hv_device(device); + + /* We found our driver ? */ + if (memcmp(&device_ctx->dev_type, &drv->dev_type, + sizeof(struct hv_guid)) == 0) { + + device_ctx->drv = drv->priv; + DPRINT_INFO(VMBUS_DRV, + "device object (%p) set to driver object (%p)", + &device_ctx, + device_ctx->drv); - hv_pci_dev = pdev; + match = 1; + } + return match; +} - err = pci_enable_device(pdev); - if (err) - return err; +/* + * vmbus_probe_failed_cb - Callback when a driver probe failed in vmbus_probe() + * + * We need a callback because we cannot invoked device_unregister() inside + * vmbus_probe() since vmbus_probe() may be invoked inside device_register() + * i.e. we cannot call device_unregister() inside device_register() + */ +static void vmbus_probe_failed_cb(struct work_struct *context) +{ + struct hv_device *device_ctx = (struct hv_device *)context; - err = vmbus_bus_init(pdev); - if (err) - pci_disable_device(pdev); + /* + * Kick off the process of unregistering the device. + * This will call vmbus_remove() and eventually vmbus_device_release() + */ + device_unregister(&device_ctx->device); - return err; + /* put_device(&device_ctx->device); */ } /* - * We use a PCI table to determine if we should autoload this driver This is - * needed by distro tools to determine if the hyperv drivers should be - * installed and/or configured. We don't do anything else with the table, but - * it needs to be present. + * vmbus_probe - Add the new vmbus's child device */ -static const struct pci_device_id microsoft_hv_pci_table[] = { - { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */ - { 0 } -}; -MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table); +static int vmbus_probe(struct device *child_device) +{ + int ret = 0; + struct hv_driver *drv = + drv_to_hv_drv(child_device->driver); + struct hv_device *dev = device_to_hv_device(child_device); + + /* Let the specific open-source driver handles the probe if it can */ + if (drv->driver.probe) { + ret = dev->probe_error = + drv->driver.probe(child_device); + if (ret != 0) { + DPRINT_ERR(VMBUS_DRV, "probe() failed for device %s " + "(%p) on driver %s (%d)...", + dev_name(child_device), child_device, + child_device->driver->name, ret); + + INIT_WORK(&dev->probe_failed_work_item, + vmbus_probe_failed_cb); + schedule_work(&dev->probe_failed_work_item); + } + } else { + DPRINT_ERR(VMBUS_DRV, "probe() method not set for driver - %s", + child_device->driver->name); + ret = -1; + } + return ret; +} + +/* + * vmbus_remove - Remove a vmbus device + */ +static int vmbus_remove(struct device *child_device) +{ + int ret; + struct hv_driver *drv; + + /* Special case root bus device */ + if (child_device->parent == NULL) { + /* + * No-op since it is statically defined and handle in + * vmbus_bus_exit() + */ + return 0; + } + + if (child_device->driver) { + drv = drv_to_hv_drv(child_device->driver); + + /* + * Let the specific open-source driver handles the removal if + * it can + */ + if (drv->driver.remove) { + ret = drv->driver.remove(child_device); + } else { + DPRINT_ERR(VMBUS_DRV, + "remove() method not set for driver - %s", + child_device->driver->name); + ret = -1; + } + } + + return 0; +} + +/* + * vmbus_shutdown - Shutdown a vmbus device + */ +static void vmbus_shutdown(struct device *child_device) +{ + struct hv_driver *drv; + + /* Special case root bus device */ + if (child_device->parent == NULL) { + /* + * No-op since it is statically defined and handle in + * vmbus_bus_exit() + */ + return; + } + + /* The device may not be attached yet */ + if (!child_device->driver) + return; + + drv = drv_to_hv_drv(child_device->driver); + + /* Let the specific open-source driver handles the removal if it can */ + if (drv->driver.shutdown) + drv->driver.shutdown(child_device); + + return; +} + +/* + * vmbus_bus_release - Final callback release of the vmbus root device + */ +static void vmbus_bus_release(struct device *device) +{ + /* FIXME */ + /* Empty release functions are a bug, or a major sign + * of a problem design, this MUST BE FIXED! */ + dev_err(device, "%s needs to be fixed!\n", __func__); + WARN_ON(1); +} + +/* + * vmbus_device_release - Final callback release of the vmbus child device + */ +static void vmbus_device_release(struct device *device) +{ + struct hv_device *device_ctx = device_to_hv_device(device); + + kfree(device_ctx); + + /* !!DO NOT REFERENCE device_ctx anymore at this point!! */ +} + + -static struct pci_driver hv_bus_driver = { - .name = "hv_bus", - .probe = hv_pci_probe, - .id_table = microsoft_hv_pci_table, +static irqreturn_t vmbus_isr(int irq, void *dev_id) +{ + int ret; + + ret = vmbus_on_isr(); + + /* Schedules a dpc if necessary */ + if (ret > 0) { + if (test_bit(0, (unsigned long *)&ret)) + tasklet_schedule(&vmbus_drv.msg_dpc); + + if (test_bit(1, (unsigned long *)&ret)) + tasklet_schedule(&vmbus_drv.event_dpc); + + return IRQ_HANDLED; + } else { + return IRQ_NONE; + } +} + +static struct dmi_system_id __initdata microsoft_hv_dmi_table[] = { + { + .ident = "Hyper-V", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"), + DMI_MATCH(DMI_PRODUCT_NAME, "Virtual Machine"), + DMI_MATCH(DMI_BOARD_NAME, "Virtual Machine"), + }, + }, + { }, }; +MODULE_DEVICE_TABLE(dmi, microsoft_hv_dmi_table); -static int __init hv_pci_init(void) +static int __init vmbus_init(void) { - return pci_register_driver(&hv_bus_driver); + DPRINT_INFO(VMBUS_DRV, + "Vmbus initializing.... current log level 0x%x (%x,%x)", + vmbus_loglevel, HIWORD(vmbus_loglevel), LOWORD(vmbus_loglevel)); + /* Todo: it is used for loglevel, to be ported to new kernel. */ + + if (!dmi_check_system(microsoft_hv_dmi_table)) + return -ENODEV; + + return vmbus_bus_init(); } -static void __exit hv_pci_exit(void) +static void __exit vmbus_exit(void) { vmbus_bus_exit(); - pci_unregister_driver(&hv_bus_driver); + /* Todo: it is used for loglevel, to be ported to new kernel. */ } - +/* + * We use a PCI table to determine if we should autoload this driver This is + * needed by distro tools to determine if the hyperv drivers should be + * installed and/or configured. We don't do anything else with the table, but + * it needs to be present. + */ +static const struct pci_device_id microsoft_hv_pci_table[] = { + { PCI_DEVICE(0x1414, 0x5353) }, /* VGA compatible controller */ + { 0 } +}; +MODULE_DEVICE_TABLE(pci, microsoft_hv_pci_table); MODULE_LICENSE("GPL"); MODULE_VERSION(HV_DRV_VERSION); -module_param(vmbus_loglevel, int, S_IRUGO|S_IWUSR); +module_param(vmbus_irq, int, S_IRUGO); +module_param(vmbus_loglevel, int, S_IRUGO); -module_init(hv_pci_init); -module_exit(hv_pci_exit); +module_init(vmbus_init); +module_exit(vmbus_exit); diff --git a/trunk/drivers/staging/hv/vstorage.h b/trunk/drivers/staging/hv/vstorage.h index 83060cd86842..ebb4d671c424 100644 --- a/trunk/drivers/staging/hv/vstorage.h +++ b/trunk/drivers/staging/hv/vstorage.h @@ -25,9 +25,6 @@ /* to alert the user that structure sizes may be mismatched even though the */ /* protocol versions match. */ -#ifndef _VSTORAGE_H_ -#define _VSTORAGE_H_ - #define REVISION_STRING(REVISION_) #REVISION_ #define FILL_VMSTOR_REVISION(RESULT_LVALUE_) \ do { \ @@ -193,5 +190,3 @@ struct vstor_packet { /* This is the set of flags that the vsc can set in any packets it sends */ #define VSC_LEGAL_FLAGS (REQUEST_COMPLETION_FLAG) - -#endif /* _VSTORAGE_H_ */ diff --git a/trunk/drivers/staging/iio/Documentation/sysfs-bus-iio b/trunk/drivers/staging/iio/Documentation/sysfs-bus-iio index 49047ad1ee40..4915aee14d88 100644 --- a/trunk/drivers/staging/iio/Documentation/sysfs-bus-iio +++ b/trunk/drivers/staging/iio/Documentation/sysfs-bus-iio @@ -698,10 +698,3 @@ Description: with all _en attributes to establish which channels are present, and the relevant _type attributes to establish the data storage format. - -What: /sys/bus/iio/devices/deviceX/gyro_z_quadrature_correction_raw -KernelVersion: 2.6.38 -Contact: linux-iio@xxxxxxxxxxxxxxx -Description: - This attribute is used to read the amount of quadrature error - present in the device at a given time. diff --git a/trunk/drivers/staging/iio/adc/Kconfig b/trunk/drivers/staging/iio/adc/Kconfig index 41593890ce88..6692a3d87f23 100644 --- a/trunk/drivers/staging/iio/adc/Kconfig +++ b/trunk/drivers/staging/iio/adc/Kconfig @@ -142,17 +142,6 @@ config AD7887 To compile this driver as a module, choose M here: the module will be called ad7887. -config AD7780 - tristate "Analog Devices AD7780 AD7781 ADC driver" - depends on SPI - help - Say yes here to build support for Analog Devices - AD7780 and AD7781 SPI analog to digital convertors (ADC). - If unsure, say N (but it's safe to say "Y"). - - To compile this driver as a module, choose M here: the - module will be called ad7780. - config AD7745 tristate "Analog Devices AD7745, AD7746 AD7747 capacitive sensor driver" depends on I2C diff --git a/trunk/drivers/staging/iio/adc/Makefile b/trunk/drivers/staging/iio/adc/Makefile index 1d9b3f582eab..31067defd79b 100644 --- a/trunk/drivers/staging/iio/adc/Makefile +++ b/trunk/drivers/staging/iio/adc/Makefile @@ -34,7 +34,6 @@ obj-$(CONFIG_AD7152) += ad7152.o obj-$(CONFIG_AD7291) += ad7291.o obj-$(CONFIG_AD7314) += ad7314.o obj-$(CONFIG_AD7745) += ad7745.o -obj-$(CONFIG_AD7780) += ad7780.o obj-$(CONFIG_AD7816) += ad7816.o obj-$(CONFIG_ADT75) += adt75.o obj-$(CONFIG_ADT7310) += adt7310.o diff --git a/trunk/drivers/staging/iio/adc/ad7780.c b/trunk/drivers/staging/iio/adc/ad7780.c deleted file mode 100644 index 0fd994fdee46..000000000000 --- a/trunk/drivers/staging/iio/adc/ad7780.c +++ /dev/null @@ -1,329 +0,0 @@ -/* - * AD7780/AD7781 SPI ADC driver - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../iio.h" -#include "../sysfs.h" -#include "../ring_generic.h" -#include "adc.h" - -#include "ad7780.h" - -#define AD7780_RDY (1 << 7) -#define AD7780_FILTER (1 << 6) -#define AD7780_ERR (1 << 5) -#define AD7780_ID1 (1 << 4) -#define AD7780_ID0 (1 << 3) -#define AD7780_GAIN (1 << 2) -#define AD7780_PAT1 (1 << 1) -#define AD7780_PAT0 (1 << 0) - -struct ad7780_chip_info { - u8 bits; - u8 storagebits; - u8 res_shift; -}; - -struct ad7780_state { - struct iio_dev *indio_dev; - struct spi_device *spi; - const struct ad7780_chip_info *chip_info; - struct regulator *reg; - struct ad7780_platform_data *pdata; - wait_queue_head_t wq_data_avail; - bool done; - u16 int_vref_mv; - struct spi_transfer xfer; - struct spi_message msg; - /* - * DMA (thus cache coherency maintenance) requires the - * transfer buffers to live in their own cache lines. - */ - unsigned int data ____cacheline_aligned; -}; - -enum ad7780_supported_device_ids { - ID_AD7780, - ID_AD7781, -}; - -static int ad7780_read(struct ad7780_state *st, int *val) -{ - int ret; - - spi_bus_lock(st->spi->master); - - enable_irq(st->spi->irq); - st->done = false; - gpio_set_value(st->pdata->gpio_pdrst, 1); - - ret = wait_event_interruptible(st->wq_data_avail, st->done); - disable_irq_nosync(st->spi->irq); - if (ret) - goto out; - - ret = spi_sync_locked(st->spi, &st->msg); - *val = be32_to_cpu(st->data); -out: - gpio_set_value(st->pdata->gpio_pdrst, 0); - spi_bus_unlock(st->spi->master); - - return ret; -} - -static ssize_t ad7780_scan(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7780_state *st = dev_info->dev_data; - int ret, val, smpl; - - mutex_lock(&dev_info->mlock); - ret = ad7780_read(st, &smpl); - mutex_unlock(&dev_info->mlock); - - if (ret < 0) - return ret; - - if ((smpl & AD7780_ERR) || - !((smpl & AD7780_PAT0) && !(smpl & AD7780_PAT1))) - return -EIO; - - val = (smpl >> st->chip_info->res_shift) & - ((1 << (st->chip_info->bits)) - 1); - val -= (1 << (st->chip_info->bits - 1)); - - if (!(smpl & AD7780_GAIN)) - val *= 128; - - return sprintf(buf, "%d\n", val); -} -static IIO_DEV_ATTR_IN_RAW(0, ad7780_scan, 0); - -static ssize_t ad7780_show_scale(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7780_state *st = iio_dev_get_devdata(dev_info); - /* Corresponds to Vref / 2^(bits-1) */ - unsigned int scale = (st->int_vref_mv * 100000) >> - (st->chip_info->bits - 1); - - return sprintf(buf, "%d.%05d\n", scale / 100000, scale % 100000); -} -static IIO_DEVICE_ATTR(in_scale, S_IRUGO, ad7780_show_scale, NULL, 0); - -static ssize_t ad7780_show_name(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *dev_info = dev_get_drvdata(dev); - struct ad7780_state *st = iio_dev_get_devdata(dev_info); - - return sprintf(buf, "%s\n", spi_get_device_id(st->spi)->name); -} -static IIO_DEVICE_ATTR(name, S_IRUGO, ad7780_show_name, NULL, 0); - -static struct attribute *ad7780_attributes[] = { - &iio_dev_attr_in0_raw.dev_attr.attr, - &iio_dev_attr_in_scale.dev_attr.attr, - &iio_dev_attr_name.dev_attr.attr, - NULL, -}; - -static const struct attribute_group ad7780_attribute_group = { - .attrs = ad7780_attributes, -}; - -static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { - [ID_AD7780] = { - .bits = 24, - .storagebits = 32, - .res_shift = 8, - }, - [ID_AD7781] = { - .bits = 20, - .storagebits = 32, - .res_shift = 12, - }, -}; - -/** - * Interrupt handler - */ -static irqreturn_t ad7780_interrupt(int irq, void *dev_id) -{ - struct ad7780_state *st = dev_id; - - st->done = true; - wake_up_interruptible(&st->wq_data_avail); - - return IRQ_HANDLED; -}; - -static int __devinit ad7780_probe(struct spi_device *spi) -{ - struct ad7780_platform_data *pdata = spi->dev.platform_data; - struct ad7780_state *st; - int ret, voltage_uv = 0; - - if (!pdata) { - dev_dbg(&spi->dev, "no platform data?\n"); - return -ENODEV; - } - - st = kzalloc(sizeof(*st), GFP_KERNEL); - if (st == NULL) { - ret = -ENOMEM; - goto error_ret; - } - - st->reg = regulator_get(&spi->dev, "vcc"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); - if (ret) - goto error_put_reg; - - voltage_uv = regulator_get_voltage(st->reg); - } - - st->chip_info = - &ad7780_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - - st->pdata = pdata; - - if (pdata && pdata->vref_mv) - st->int_vref_mv = pdata->vref_mv; - else if (voltage_uv) - st->int_vref_mv = voltage_uv / 1000; - else - dev_warn(&spi->dev, "reference voltage unspecified\n"); - - spi_set_drvdata(spi, st); - st->spi = spi; - - st->indio_dev = iio_allocate_device(); - if (st->indio_dev == NULL) { - ret = -ENOMEM; - goto error_disable_reg; - } - - /* Establish that the iio_dev is a child of the spi device */ - st->indio_dev->dev.parent = &spi->dev; - st->indio_dev->attrs = &ad7780_attribute_group; - st->indio_dev->dev_data = (void *)(st); - st->indio_dev->driver_module = THIS_MODULE; - st->indio_dev->modes = INDIO_DIRECT_MODE; - - init_waitqueue_head(&st->wq_data_avail); - - /* Setup default message */ - - st->xfer.rx_buf = &st->data; - st->xfer.len = st->chip_info->storagebits / 8; - - spi_message_init(&st->msg); - spi_message_add_tail(&st->xfer, &st->msg); - - ret = gpio_request_one(st->pdata->gpio_pdrst, GPIOF_OUT_INIT_LOW, - "AD7877 /PDRST"); - if (ret) { - dev_err(&spi->dev, "failed to request GPIO PDRST\n"); - goto error_free_device; - } - - ret = request_irq(spi->irq, ad7780_interrupt, - IRQF_TRIGGER_FALLING, spi_get_device_id(spi)->name, st); - if (ret) - goto error_free_device; - - disable_irq(spi->irq); - - ret = iio_device_register(st->indio_dev); - if (ret) - goto error_free_irq; - - return 0; - -error_free_irq: - free_irq(spi->irq, st); - -error_free_device: - iio_free_device(st->indio_dev); -error_disable_reg: - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); -error_put_reg: - if (!IS_ERR(st->reg)) - regulator_put(st->reg); - kfree(st); -error_ret: - return ret; -} - -static int ad7780_remove(struct spi_device *spi) -{ - struct ad7780_state *st = spi_get_drvdata(spi); - struct iio_dev *indio_dev = st->indio_dev; - free_irq(spi->irq, st); - gpio_free(st->pdata->gpio_pdrst); - iio_device_unregister(indio_dev); - if (!IS_ERR(st->reg)) { - regulator_disable(st->reg); - regulator_put(st->reg); - } - kfree(st); - return 0; -} - -static const struct spi_device_id ad7780_id[] = { - {"ad7780", ID_AD7780}, - {"ad7781", ID_AD7781}, - {} -}; - -static struct spi_driver ad7780_driver = { - .driver = { - .name = "ad7780", - .bus = &spi_bus_type, - .owner = THIS_MODULE, - }, - .probe = ad7780_probe, - .remove = __devexit_p(ad7780_remove), - .id_table = ad7780_id, -}; - -static int __init ad7780_init(void) -{ - return spi_register_driver(&ad7780_driver); -} -module_init(ad7780_init); - -static void __exit ad7780_exit(void) -{ - spi_unregister_driver(&ad7780_driver); -} -module_exit(ad7780_exit); - -MODULE_AUTHOR("Michael Hennerich "); -MODULE_DESCRIPTION("Analog Devices AD7780/1 ADC"); -MODULE_LICENSE("GPL v2"); diff --git a/trunk/drivers/staging/iio/adc/ad7780.h b/trunk/drivers/staging/iio/adc/ad7780.h deleted file mode 100644 index 67e511c3d6f0..000000000000 --- a/trunk/drivers/staging/iio/adc/ad7780.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * AD7780/AD7781 SPI ADC driver - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ -#ifndef IIO_ADC_AD7780_H_ -#define IIO_ADC_AD7780_H_ - -/* - * TODO: struct ad7780_platform_data needs to go into include/linux/iio - */ - -/* NOTE: - * The AD7780 doesn't feature a dedicated SPI chip select, in addition it - * features a dual use data out ready DOUT/RDY output. - * In order to avoid contentions on the SPI bus, it's therefore necessary - * to use spi bus locking combined with a dedicated GPIO to control the - * power down reset signal of the AD7780. - * - * The DOUT/RDY output must also be wired to an interrupt capable GPIO. - */ - -struct ad7780_platform_data { - u16 vref_mv; - int gpio_pdrst; -}; - -#endif /* IIO_ADC_AD7780_H_ */ diff --git a/trunk/drivers/staging/iio/dac/Kconfig b/trunk/drivers/staging/iio/dac/Kconfig index 1b0188a2c559..67defcb359b1 100644 --- a/trunk/drivers/staging/iio/dac/Kconfig +++ b/trunk/drivers/staging/iio/dac/Kconfig @@ -21,16 +21,6 @@ config AD5446 To compile this driver as a module, choose M here: the module will be called ad5446. -config AD5504 - tristate "Analog Devices AD5504/AD5501 DAC SPI driver" - depends on SPI - help - Say yes here to build support for Analog Devices AD5504, AD5501, - High Voltage Digital to Analog Converter. - - To compile this driver as a module, choose M here: the - module will be called ad5504. - config MAX517 tristate "Maxim MAX517/518/519 DAC driver" depends on I2C && EXPERIMENTAL diff --git a/trunk/drivers/staging/iio/dac/Makefile b/trunk/drivers/staging/iio/dac/Makefile index 020df4a1130a..1197aef54abb 100644 --- a/trunk/drivers/staging/iio/dac/Makefile +++ b/trunk/drivers/staging/iio/dac/Makefile @@ -3,6 +3,5 @@ # obj-$(CONFIG_AD5624R_SPI) += ad5624r_spi.o -obj-$(CONFIG_AD5504) += ad5504.o obj-$(CONFIG_AD5446) += ad5446.o obj-$(CONFIG_MAX517) += max517.o diff --git a/trunk/drivers/staging/iio/dac/ad5504.c b/trunk/drivers/staging/iio/dac/ad5504.c deleted file mode 100644 index 153c36e7f70e..000000000000 --- a/trunk/drivers/staging/iio/dac/ad5504.c +++ /dev/null @@ -1,426 +0,0 @@ -/* - * AD5504, AD5501 High Voltage Digital to Analog Converter - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../iio.h" -#include "../sysfs.h" -#include "dac.h" -#include "ad5504.h" - -static int ad5504_spi_write(struct spi_device *spi, u8 addr, u16 val) -{ - u16 tmp = cpu_to_be16(AD5504_CMD_WRITE | - AD5504_ADDR(addr) | - (val & AD5504_RES_MASK)); - - return spi_write(spi, (u8 *)&tmp, 2); -} - -static int ad5504_spi_read(struct spi_device *spi, u8 addr, u16 *val) -{ - u16 tmp = cpu_to_be16(AD5504_CMD_READ | AD5504_ADDR(addr)); - int ret; - struct spi_transfer t = { - .tx_buf = &tmp, - .rx_buf = val, - .len = 2, - }; - struct spi_message m; - - spi_message_init(&m); - spi_message_add_tail(&t, &m); - ret = spi_sync(spi, &m); - - *val = be16_to_cpu(*val) & AD5504_RES_MASK; - - return ret; -} - -static ssize_t ad5504_write_dac(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ad5504_state *st = iio_dev_get_devdata(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - long readin; - int ret; - - ret = strict_strtol(buf, 10, &readin); - if (ret) - return ret; - - ret = ad5504_spi_write(st->spi, this_attr->address, readin); - return ret ? ret : len; -} - -static ssize_t ad5504_read_dac(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ad5504_state *st = iio_dev_get_devdata(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - int ret; - u16 val; - - ret = ad5504_spi_read(st->spi, this_attr->address, &val); - if (ret) - return ret; - - return sprintf(buf, "%d\n", val); -} - -static ssize_t ad5504_read_powerdown_mode(struct device *dev, - struct device_attribute *attr, char *buf) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ad5504_state *st = iio_dev_get_devdata(indio_dev); - - const char mode[][14] = {"20kohm_to_gnd", "three_state"}; - - return sprintf(buf, "%s\n", mode[st->pwr_down_mode]); -} - -static ssize_t ad5504_write_powerdown_mode(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ad5504_state *st = iio_dev_get_devdata(indio_dev); - int ret; - - if (sysfs_streq(buf, "20kohm_to_gnd")) - st->pwr_down_mode = AD5504_DAC_PWRDN_20K; - else if (sysfs_streq(buf, "three_state")) - st->pwr_down_mode = AD5504_DAC_PWRDN_3STATE; - else - ret = -EINVAL; - - return ret ? ret : len; -} - -static ssize_t ad5504_read_dac_powerdown(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ad5504_state *st = iio_dev_get_devdata(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - - return sprintf(buf, "%d\n", - !(st->pwr_down_mask & (1 << this_attr->address))); -} - -static ssize_t ad5504_write_dac_powerdown(struct device *dev, - struct device_attribute *attr, - const char *buf, size_t len) -{ - long readin; - int ret; - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ad5504_state *st = iio_dev_get_devdata(indio_dev); - struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); - - ret = strict_strtol(buf, 10, &readin); - if (ret) - return ret; - - if (readin == 0) - st->pwr_down_mask |= (1 << this_attr->address); - else if (readin == 1) - st->pwr_down_mask &= ~(1 << this_attr->address); - else - ret = -EINVAL; - - ret = ad5504_spi_write(st->spi, AD5504_ADDR_CTRL, - AD5504_DAC_PWRDWN_MODE(st->pwr_down_mode) | - AD5504_DAC_PWR(st->pwr_down_mask)); - - /* writes to the CTRL register must be followed by a NOOP */ - ad5504_spi_write(st->spi, AD5504_ADDR_NOOP, 0); - - return ret ? ret : len; -} - -static ssize_t ad5504_show_scale(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ad5504_state *st = iio_dev_get_devdata(indio_dev); - /* Corresponds to Vref / 2^(bits) */ - unsigned int scale_uv = (st->vref_mv * 1000) >> AD5505_BITS; - - return sprintf(buf, "%d.%03d\n", scale_uv / 1000, scale_uv % 1000); -} -static IIO_DEVICE_ATTR(out_scale, S_IRUGO, ad5504_show_scale, NULL, 0); - -static ssize_t ad5504_show_name(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct ad5504_state *st = iio_dev_get_devdata(indio_dev); - - return sprintf(buf, "%s\n", spi_get_device_id(st->spi)->name); -} -static IIO_DEVICE_ATTR(name, S_IRUGO, ad5504_show_name, NULL, 0); - -#define IIO_DEV_ATTR_OUT_RW_RAW(_num, _show, _store, _addr) \ - IIO_DEVICE_ATTR(out##_num##_raw, \ - S_IRUGO | S_IWUSR, _show, _store, _addr) - -static IIO_DEV_ATTR_OUT_RW_RAW(0, ad5504_read_dac, - ad5504_write_dac, AD5504_ADDR_DAC0); -static IIO_DEV_ATTR_OUT_RW_RAW(1, ad5504_read_dac, - ad5504_write_dac, AD5504_ADDR_DAC1); -static IIO_DEV_ATTR_OUT_RW_RAW(2, ad5504_read_dac, - ad5504_write_dac, AD5504_ADDR_DAC2); -static IIO_DEV_ATTR_OUT_RW_RAW(3, ad5504_read_dac, - ad5504_write_dac, AD5504_ADDR_DAC3); - -static IIO_DEVICE_ATTR(out_powerdown_mode, S_IRUGO | - S_IWUSR, ad5504_read_powerdown_mode, - ad5504_write_powerdown_mode, 0); - -static IIO_CONST_ATTR(out_powerdown_mode_available, - "20kohm_to_gnd three_state"); - -#define IIO_DEV_ATTR_DAC_POWERDOWN(_num, _show, _store, _addr) \ - IIO_DEVICE_ATTR(out##_num##_powerdown, \ - S_IRUGO | S_IWUSR, _show, _store, _addr) - -static IIO_DEV_ATTR_DAC_POWERDOWN(0, ad5504_read_dac_powerdown, - ad5504_write_dac_powerdown, 0); -static IIO_DEV_ATTR_DAC_POWERDOWN(1, ad5504_read_dac_powerdown, - ad5504_write_dac_powerdown, 1); -static IIO_DEV_ATTR_DAC_POWERDOWN(2, ad5504_read_dac_powerdown, - ad5504_write_dac_powerdown, 2); -static IIO_DEV_ATTR_DAC_POWERDOWN(3, ad5504_read_dac_powerdown, - ad5504_write_dac_powerdown, 3); - -static struct attribute *ad5504_attributes[] = { - &iio_dev_attr_out0_raw.dev_attr.attr, - &iio_dev_attr_out1_raw.dev_attr.attr, - &iio_dev_attr_out2_raw.dev_attr.attr, - &iio_dev_attr_out3_raw.dev_attr.attr, - &iio_dev_attr_out0_powerdown.dev_attr.attr, - &iio_dev_attr_out1_powerdown.dev_attr.attr, - &iio_dev_attr_out2_powerdown.dev_attr.attr, - &iio_dev_attr_out3_powerdown.dev_attr.attr, - &iio_dev_attr_out_powerdown_mode.dev_attr.attr, - &iio_const_attr_out_powerdown_mode_available.dev_attr.attr, - &iio_dev_attr_out_scale.dev_attr.attr, - &iio_dev_attr_name.dev_attr.attr, - NULL, -}; - -static const struct attribute_group ad5504_attribute_group = { - .attrs = ad5504_attributes, -}; - -static struct attribute *ad5501_attributes[] = { - &iio_dev_attr_out0_raw.dev_attr.attr, - &iio_dev_attr_out0_powerdown.dev_attr.attr, - &iio_dev_attr_out_powerdown_mode.dev_attr.attr, - &iio_const_attr_out_powerdown_mode_available.dev_attr.attr, - &iio_dev_attr_out_scale.dev_attr.attr, - &iio_dev_attr_name.dev_attr.attr, - NULL, -}; - -static const struct attribute_group ad5501_attribute_group = { - .attrs = ad5501_attributes, -}; - -static IIO_CONST_ATTR(temp0_thresh_rising_value, "110000"); -static IIO_CONST_ATTR(temp0_thresh_rising_en, "1"); - -static struct attribute *ad5504_ev_attributes[] = { - &iio_const_attr_temp0_thresh_rising_value.dev_attr.attr, - &iio_const_attr_temp0_thresh_rising_en.dev_attr.attr, - NULL, -}; - -static struct attribute_group ad5504_ev_attribute_group = { - .attrs = ad5504_ev_attributes, -}; - -static void ad5504_interrupt_bh(struct work_struct *work_s) -{ - struct ad5504_state *st = container_of(work_s, - struct ad5504_state, work_alarm); - - iio_push_event(st->indio_dev, 0, - IIO_UNMOD_EVENT_CODE(IIO_EV_CLASS_TEMP, - 0, - IIO_EV_TYPE_THRESH, - IIO_EV_DIR_RISING), - st->last_timestamp); - - enable_irq(st->spi->irq); -} - -static int ad5504_interrupt(struct iio_dev *dev_info, - int index, - s64 timestamp, - int no_test) -{ - struct ad5504_state *st = dev_info->dev_data; - - st->last_timestamp = timestamp; - schedule_work(&st->work_alarm); - return 0; -} - -IIO_EVENT_SH(ad5504, &ad5504_interrupt); - -static int __devinit ad5504_probe(struct spi_device *spi) -{ - struct ad5504_platform_data *pdata = spi->dev.platform_data; - struct ad5504_state *st; - int ret, voltage_uv = 0; - - st = kzalloc(sizeof(*st), GFP_KERNEL); - if (st == NULL) { - ret = -ENOMEM; - goto error_ret; - } - - spi_set_drvdata(spi, st); - - st->reg = regulator_get(&spi->dev, "vcc"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); - if (ret) - goto error_put_reg; - - voltage_uv = regulator_get_voltage(st->reg); - } - - if (voltage_uv) - st->vref_mv = voltage_uv / 1000; - else if (pdata) - st->vref_mv = pdata->vref_mv; - else - dev_warn(&spi->dev, "reference voltage unspecified\n"); - - st->spi = spi; - st->indio_dev = iio_allocate_device(); - if (st->indio_dev == NULL) { - ret = -ENOMEM; - goto error_disable_reg; - } - st->indio_dev->dev.parent = &spi->dev; - - st->indio_dev->attrs = spi_get_device_id(st->spi)->driver_data - == ID_AD5501 ? &ad5501_attribute_group : - &ad5504_attribute_group; - st->indio_dev->dev_data = (void *)(st); - st->indio_dev->driver_module = THIS_MODULE; - st->indio_dev->modes = INDIO_DIRECT_MODE; - st->indio_dev->num_interrupt_lines = 1; - st->indio_dev->event_attrs = &ad5504_ev_attribute_group, - - ret = iio_device_register(st->indio_dev); - if (ret) - goto error_free_dev; - - if (spi->irq) { - INIT_WORK(&st->work_alarm, ad5504_interrupt_bh); - - ret = iio_register_interrupt_line(spi->irq, - st->indio_dev, - 0, - IRQF_TRIGGER_FALLING, - spi_get_device_id(st->spi)->name); - if (ret) - goto error_unreg_iio_device; - - iio_add_event_to_list(&iio_event_ad5504, - &st->indio_dev->interrupts[0]->ev_list); - } - - return 0; - -error_unreg_iio_device: - iio_device_unregister(st->indio_dev); -error_free_dev: - iio_free_device(st->indio_dev); -error_disable_reg: - if (!IS_ERR(st->reg)) - regulator_disable(st->reg); -error_put_reg: - if (!IS_ERR(st->reg)) - regulator_put(st->reg); - - kfree(st); -error_ret: - return ret; -} - -static int __devexit ad5504_remove(struct spi_device *spi) -{ - struct ad5504_state *st = spi_get_drvdata(spi); - - if (spi->irq) - iio_unregister_interrupt_line(st->indio_dev, 0); - - iio_device_unregister(st->indio_dev); - - if (!IS_ERR(st->reg)) { - regulator_disable(st->reg); - regulator_put(st->reg); - } - - kfree(st); - - return 0; -} - -static const struct spi_device_id ad5504_id[] = { - {"ad5504", ID_AD5504}, - {"ad5501", ID_AD5501}, - {} -}; - -static struct spi_driver ad5504_driver = { - .driver = { - .name = "ad5504", - .owner = THIS_MODULE, - }, - .probe = ad5504_probe, - .remove = __devexit_p(ad5504_remove), - .id_table = ad5504_id, -}; - -static __init int ad5504_spi_init(void) -{ - return spi_register_driver(&ad5504_driver); -} -module_init(ad5504_spi_init); - -static __exit void ad5504_spi_exit(void) -{ - spi_unregister_driver(&ad5504_driver); -} -module_exit(ad5504_spi_exit); - -MODULE_AUTHOR("Michael Hennerich "); -MODULE_DESCRIPTION("Analog Devices AD5501/AD5501 DAC"); -MODULE_LICENSE("GPL v2"); diff --git a/trunk/drivers/staging/iio/dac/ad5504.h b/trunk/drivers/staging/iio/dac/ad5504.h deleted file mode 100644 index d2fac631a43a..000000000000 --- a/trunk/drivers/staging/iio/dac/ad5504.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * AD5504 SPI DAC driver - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2. - */ - -#ifndef SPI_AD5504_H_ -#define SPI_AD5504_H_ - -#define AD5505_BITS 12 -#define AD5504_RES_MASK ((1 << (AD5505_BITS)) - 1) - -#define AD5504_CMD_READ (1 << 15) -#define AD5504_CMD_WRITE (0 << 15) -#define AD5504_ADDR(addr) ((addr) << 12) - -/* Registers */ -#define AD5504_ADDR_NOOP 0 -#define AD5504_ADDR_DAC0 1 -#define AD5504_ADDR_DAC1 2 -#define AD5504_ADDR_DAC2 3 -#define AD5504_ADDR_DAC3 4 -#define AD5504_ADDR_ALL_DAC 5 -#define AD5504_ADDR_CTRL 7 - -/* Control Register */ -#define AD5504_DAC_PWR(ch) ((ch) << 2) -#define AD5504_DAC_PWRDWN_MODE(mode) ((mode) << 6) -#define AD5504_DAC_PWRDN_20K 0 -#define AD5504_DAC_PWRDN_3STATE 1 - -/* - * TODO: struct ad5504_platform_data needs to go into include/linux/iio - */ - -struct ad5504_platform_data { - u16 vref_mv; -}; - -/** - * struct ad5446_state - driver instance specific data - * @indio_dev: the industrial I/O device - * @us: spi_device - * @reg: supply regulator - * @vref_mv: actual reference voltage used - * @work_alarm: bh work structure for event handling - * @last_timestamp: timestamp of last event interrupt - * @pwr_down_mask power down mask - * @pwr_down_mode current power down mode - */ - -struct ad5504_state { - struct iio_dev *indio_dev; - struct spi_device *spi; - struct regulator *reg; - unsigned short vref_mv; - struct work_struct work_alarm; - s64 last_timestamp; - unsigned pwr_down_mask; - unsigned pwr_down_mode; -}; - -/** - * ad5504_supported_device_ids: - */ - -enum ad5504_supported_device_ids { - ID_AD5504, - ID_AD5501, -}; - -#endif /* SPI_AD5504_H_ */ diff --git a/trunk/drivers/staging/iio/gyro/Kconfig b/trunk/drivers/staging/iio/gyro/Kconfig index ae2e7d3095ae..8b78fa0e6316 100644 --- a/trunk/drivers/staging/iio/gyro/Kconfig +++ b/trunk/drivers/staging/iio/gyro/Kconfig @@ -35,13 +35,3 @@ config ADIS16260 This driver can also be built as a module. If so, the module will be called adis16260. - -config ADXRS450 - tristate "Analog Devices ADXRS450 Digital Output Gyroscope SPI driver" - depends on SPI - help - Say yes here to build support for Analog Devices ADXRS450 programmable - digital output gyroscope. - - This driver can also be built as a module. If so, the module - will be called adxrs450. diff --git a/trunk/drivers/staging/iio/gyro/Makefile b/trunk/drivers/staging/iio/gyro/Makefile index 2212240f7de3..2764c15025a5 100644 --- a/trunk/drivers/staging/iio/gyro/Makefile +++ b/trunk/drivers/staging/iio/gyro/Makefile @@ -17,6 +17,3 @@ obj-$(CONFIG_ADIS16260) += adis16260.o adis16251-y := adis16251_core.o obj-$(CONFIG_ADIS16251) += adis16251.o - -adxrs450-y := adxrs450_core.o -obj-$(CONFIG_ADXRS450) += adxrs450.o diff --git a/trunk/drivers/staging/iio/gyro/adxrs450.h b/trunk/drivers/staging/iio/gyro/adxrs450.h deleted file mode 100644 index c92f6945f00f..000000000000 --- a/trunk/drivers/staging/iio/gyro/adxrs450.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef SPI_ADXRS450_H_ -#define SPI_ADXRS450_H_ - -#define ADXRS450_STARTUP_DELAY 50 /* ms */ - -/* The MSB for the spi commands */ -#define ADXRS450_SENSOR_DATA 0x20 -#define ADXRS450_WRITE_DATA 0x40 -#define ADXRS450_READ_DATA 0x80 - -#define ADXRS450_RATE1 0x00 /* Rate Registers */ -#define ADXRS450_TEMP1 0x02 /* Temperature Registers */ -#define ADXRS450_LOCST1 0x04 /* Low CST Memory Registers */ -#define ADXRS450_HICST1 0x06 /* High CST Memory Registers */ -#define ADXRS450_QUAD1 0x08 /* Quad Memory Registers */ -#define ADXRS450_FAULT1 0x0A /* Fault Registers */ -#define ADXRS450_PID1 0x0C /* Part ID Register 1 */ -#define ADXRS450_SNH 0x0E /* Serial Number Registers, 4 bytes */ -#define ADXRS450_SNL 0x10 -#define ADXRS450_DNC1 0x12 /* Dynamic Null Correction Registers */ -/* Check bits */ -#define ADXRS450_P 0x01 -#define ADXRS450_CHK 0x02 -#define ADXRS450_CST 0x04 -#define ADXRS450_PWR 0x08 -#define ADXRS450_POR 0x10 -#define ADXRS450_NVM 0x20 -#define ADXRS450_Q 0x40 -#define ADXRS450_PLL 0x80 -#define ADXRS450_UV 0x100 -#define ADXRS450_OV 0x200 -#define ADXRS450_AMP 0x400 -#define ADXRS450_FAIL 0x800 - -#define ADXRS450_WRERR_MASK (0x7 << 29) - -#define ADXRS450_MAX_RX 4 -#define ADXRS450_MAX_TX 4 - -#define ADXRS450_GET_ST(a) ((a >> 26) & 0x3) - -/** - * struct adxrs450_state - device instance specific data - * @us: actual spi_device - * @indio_dev: industrial I/O device structure - * @tx: transmit buffer - * @rx: recieve buffer - * @buf_lock: mutex to protect tx and rx - **/ -struct adxrs450_state { - struct spi_device *us; - struct iio_dev *indio_dev; - u8 *tx; - u8 *rx; - struct mutex buf_lock; -}; - -#endif /* SPI_ADXRS450_H_ */ diff --git a/trunk/drivers/staging/iio/gyro/adxrs450_core.c b/trunk/drivers/staging/iio/gyro/adxrs450_core.c deleted file mode 100644 index d70bf684b7ac..000000000000 --- a/trunk/drivers/staging/iio/gyro/adxrs450_core.c +++ /dev/null @@ -1,446 +0,0 @@ -/* - * ADXRS450 Digital Output Gyroscope Driver - * - * Copyright 2011 Analog Devices Inc. - * - * Licensed under the GPL-2 or later. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "../iio.h" -#include "../sysfs.h" -#include "gyro.h" -#include "../adc/adc.h" - -#include "adxrs450.h" - -/** - * adxrs450_spi_read_reg_16() - read 2 bytes from a register pair - * @dev: device associated with child of actual iio_dev - * @reg_address: the address of the lower of the two registers,which should be an even address, - * Second register's address is reg_address + 1. - * @val: somewhere to pass back the value read - **/ -static int adxrs450_spi_read_reg_16(struct device *dev, - u8 reg_address, - u16 *val) -{ - struct spi_message msg; - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct adxrs450_state *st = iio_dev_get_devdata(indio_dev); - int ret; - struct spi_transfer xfers = { - .tx_buf = st->tx, - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 4, - }; - /* Needs to send the command twice to get the wanted value */ - mutex_lock(&st->buf_lock); - st->tx[0] = ADXRS450_READ_DATA | reg_address >> 7; - st->tx[1] = reg_address << 1; - st->tx[2] = 0; - st->tx[3] = 0; - spi_message_init(&msg); - spi_message_add_tail(&xfers, &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", - reg_address); - goto error_ret; - } - - spi_message_init(&msg); - spi_message_add_tail(&xfers, &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "problem while reading 16 bit register 0x%02x\n", - reg_address); - goto error_ret; - } - - *val = (st->rx[1] & 0x1f) << 11 | st->rx[2] << 3 | (st->rx[3] & 0xe0) >> 5; - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -/** - * adxrs450_spi_write_reg_16() - write 2 bytes data to a register pair - * @dev: device associated with child of actual actual iio_dev - * @reg_address: the address of the lower of the two registers,which should be an even address, - * Second register's address is reg_address + 1. - * @val: value to be written. - **/ -static int adxrs450_spi_write_reg_16(struct device *dev, - u8 reg_address, - u16 val) -{ - struct spi_message msg; - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct adxrs450_state *st = iio_dev_get_devdata(indio_dev); - int ret; - struct spi_transfer xfers = { - .tx_buf = st->tx, - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 4, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADXRS450_WRITE_DATA | reg_address >> 7; - st->tx[1] = reg_address << 1 | val >> 15; - st->tx[2] = val >> 7; - st->tx[3] = val << 1; - spi_message_init(&msg); - spi_message_add_tail(&xfers, &msg); - ret = spi_sync(st->us, &msg); - if (ret) - dev_err(&st->us->dev, "problem while writing 16 bit register 0x%02x\n", - reg_address); - mutex_unlock(&st->buf_lock); - return ret; -} - -/** - * adxrs450_spi_sensor_data() - read 2 bytes sensor data - * @dev: device associated with child of actual iio_dev - * @val: somewhere to pass back the value read - **/ -static int adxrs450_spi_sensor_data(struct device *dev, u16 *val) -{ - struct spi_message msg; - struct iio_dev *indio_dev = dev_get_drvdata(dev); - struct adxrs450_state *st = iio_dev_get_devdata(indio_dev); - int ret; - struct spi_transfer xfers = { - .tx_buf = st->tx, - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 4, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADXRS450_SENSOR_DATA; - st->tx[1] = 0; - st->tx[2] = 0; - st->tx[3] = 0; - - spi_message_init(&msg); - spi_message_add_tail(&xfers, &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "Problem while reading sensor data\n"); - goto error_ret; - } - - spi_message_init(&msg); - spi_message_add_tail(&xfers, &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "Problem while reading sensor data\n"); - goto error_ret; - } - - *val = (st->rx[0] & 0x03) << 14 | st->rx[1] << 6 | (st->rx[2] & 0xfc) >> 2; -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -/** - * adxrs450_spi_initial() - use for initializing procedure. - * @st: device instance specific data - * @val: somewhere to pass back the value read - **/ -static int adxrs450_spi_initial(struct adxrs450_state *st, - u32 *val, char chk) -{ - struct spi_message msg; - int ret; - struct spi_transfer xfers = { - .tx_buf = st->tx, - .rx_buf = st->rx, - .bits_per_word = 8, - .len = 4, - }; - - mutex_lock(&st->buf_lock); - st->tx[0] = ADXRS450_SENSOR_DATA; - st->tx[1] = 0; - st->tx[2] = 0; - st->tx[3] = 0; - if (chk) - st->tx[3] |= (ADXRS450_CHK | ADXRS450_P); - spi_message_init(&msg); - spi_message_add_tail(&xfers, &msg); - ret = spi_sync(st->us, &msg); - if (ret) { - dev_err(&st->us->dev, "Problem while reading initializing data\n"); - goto error_ret; - } - - *val = be32_to_cpu(*(u32 *)st->rx); - -error_ret: - mutex_unlock(&st->buf_lock); - return ret; -} - -static ssize_t adxrs450_read_temp(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int ret; - u16 t; - ret = adxrs450_spi_read_reg_16(dev, - ADXRS450_TEMP1, - &t); - if (ret) - return ret; - return sprintf(buf, "%d\n", t); -} - -static ssize_t adxrs450_read_quad(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int ret; - u16 t; - ret = adxrs450_spi_read_reg_16(dev, - ADXRS450_QUAD1, - &t); - if (ret) - return ret; - return sprintf(buf, "%d\n", t); -} - -static ssize_t adxrs450_write_dnc(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) -{ - int ret; - long val; - - ret = strict_strtol(buf, 10, &val); - if (ret) - goto error_ret; - ret = adxrs450_spi_write_reg_16(dev, - ADXRS450_DNC1, - val); -error_ret: - return ret ? ret : len; -} - -static ssize_t adxrs450_read_sensor_data(struct device *dev, - struct device_attribute *attr, - char *buf) -{ - int ret; - u16 t; - - ret = adxrs450_spi_sensor_data(dev, &t); - if (ret) - return ret; - - return sprintf(buf, "%d\n", t); -} - -/* Recommended Startup Sequence by spec */ -static int adxrs450_initial_setup(struct adxrs450_state *st) -{ - u32 t; - u16 data; - int ret; - struct device *dev = &st->indio_dev->dev; - - msleep(ADXRS450_STARTUP_DELAY*2); - ret = adxrs450_spi_initial(st, &t, 1); - if (ret) - return ret; - if (t != 0x01) { - dev_err(&st->us->dev, "The initial response is not correct!\n"); - return -ENODEV; - - } - - msleep(ADXRS450_STARTUP_DELAY); - ret = adxrs450_spi_initial(st, &t, 0); - if (ret) - return ret; - - msleep(ADXRS450_STARTUP_DELAY); - ret = adxrs450_spi_initial(st, &t, 0); - if (ret) - return ret; - if (((t & 0xff) | 0x01) != 0xff || ADXRS450_GET_ST(t) != 2) { - dev_err(&st->us->dev, "The second response is not correct!\n"); - return -EIO; - - } - ret = adxrs450_spi_initial(st, &t, 0); - if (ret) - return ret; - if (((t & 0xff) | 0x01) != 0xff || ADXRS450_GET_ST(t) != 2) { - dev_err(&st->us->dev, "The third response is not correct!\n"); - return -EIO; - - } - ret = adxrs450_spi_read_reg_16(dev, ADXRS450_FAULT1, &data); - if (ret) - return ret; - if (data & 0x0fff) { - dev_err(&st->us->dev, "The device is not in normal status!\n"); - return -EINVAL; - } - ret = adxrs450_spi_read_reg_16(dev, ADXRS450_PID1, &data); - if (ret) - return ret; - dev_info(&st->us->dev, "The Part ID is 0x%x\n", data); - - ret = adxrs450_spi_read_reg_16(dev, ADXRS450_SNL, &data); - if (ret) - return ret; - t = data; - ret = adxrs450_spi_read_reg_16(dev, ADXRS450_SNH, &data); - if (ret) - return ret; - t |= data << 16; - dev_info(&st->us->dev, "The Serial Number is 0x%x\n", t); - - return 0; -} - -static IIO_DEV_ATTR_GYRO_Z(adxrs450_read_sensor_data, 0); -static IIO_DEV_ATTR_TEMP_RAW(adxrs450_read_temp); -static IIO_DEV_ATTR_GYRO_Z_QUADRATURE_CORRECTION(adxrs450_read_quad, 0); -static IIO_DEV_ATTR_GYRO_Z_CALIBBIAS(S_IWUSR, - NULL, adxrs450_write_dnc, 0); -static IIO_CONST_ATTR(name, "adxrs450"); - -static struct attribute *adxrs450_attributes[] = { - &iio_dev_attr_gyro_z_raw.dev_attr.attr, - &iio_dev_attr_temp_raw.dev_attr.attr, - &iio_dev_attr_gyro_z_quadrature_correction_raw.dev_attr.attr, - &iio_dev_attr_gyro_z_calibbias.dev_attr.attr, - &iio_const_attr_name.dev_attr.attr, - NULL -}; - -static const struct attribute_group adxrs450_attribute_group = { - .attrs = adxrs450_attributes, -}; - -static int __devinit adxrs450_probe(struct spi_device *spi) -{ - int ret, regdone = 0; - struct adxrs450_state *st = kzalloc(sizeof *st, GFP_KERNEL); - if (!st) { - ret = -ENOMEM; - goto error_ret; - } - /* This is only used for removal purposes */ - spi_set_drvdata(spi, st); - - /* Allocate the comms buffers */ - st->rx = kzalloc(sizeof(*st->rx)*ADXRS450_MAX_RX, GFP_KERNEL); - if (st->rx == NULL) { - ret = -ENOMEM; - goto error_free_st; - } - st->tx = kzalloc(sizeof(*st->tx)*ADXRS450_MAX_TX, GFP_KERNEL); - if (st->tx == NULL) { - ret = -ENOMEM; - goto error_free_rx; - } - st->us = spi; - mutex_init(&st->buf_lock); - /* setup the industrialio driver allocated elements */ - st->indio_dev = iio_allocate_device(); - if (st->indio_dev == NULL) { - ret = -ENOMEM; - goto error_free_tx; - } - - st->indio_dev->dev.parent = &spi->dev; - st->indio_dev->attrs = &adxrs450_attribute_group; - st->indio_dev->dev_data = (void *)(st); - st->indio_dev->driver_module = THIS_MODULE; - st->indio_dev->modes = INDIO_DIRECT_MODE; - - ret = iio_device_register(st->indio_dev); - if (ret) - goto error_free_dev; - regdone = 1; - - /* Get the device into a sane initial state */ - ret = adxrs450_initial_setup(st); - if (ret) - goto error_initial; - return 0; - -error_initial: -error_free_dev: - if (regdone) - iio_device_unregister(st->indio_dev); - else - iio_free_device(st->indio_dev); -error_free_tx: - kfree(st->tx); -error_free_rx: - kfree(st->rx); -error_free_st: - kfree(st); -error_ret: - return ret; -} - -static int adxrs450_remove(struct spi_device *spi) -{ - struct adxrs450_state *st = spi_get_drvdata(spi); - - iio_device_unregister(st->indio_dev); - kfree(st->tx); - kfree(st->rx); - kfree(st); - - return 0; -} - -static struct spi_driver adxrs450_driver = { - .driver = { - .name = "adxrs450", - .owner = THIS_MODULE, - }, - .probe = adxrs450_probe, - .remove = __devexit_p(adxrs450_remove), -}; - -static __init int adxrs450_init(void) -{ - return spi_register_driver(&adxrs450_driver); -} -module_init(adxrs450_init); - -static __exit void adxrs450_exit(void) -{ - spi_unregister_driver(&adxrs450_driver); -} -module_exit(adxrs450_exit); - -MODULE_AUTHOR("Cliff Cai "); -MODULE_DESCRIPTION("Analog Devices ADXRS450 Gyroscope SPI driver"); -MODULE_LICENSE("GPL v2"); diff --git a/trunk/drivers/staging/iio/gyro/gyro.h b/trunk/drivers/staging/iio/gyro/gyro.h index b5495613407b..b4ea5bf161ff 100644 --- a/trunk/drivers/staging/iio/gyro/gyro.h +++ b/trunk/drivers/staging/iio/gyro/gyro.h @@ -57,9 +57,6 @@ #define IIO_DEV_ATTR_GYRO_Z_CALIBSCALE(_mode, _show, _store, _addr) \ IIO_DEVICE_ATTR(gyro_z_calibscale, _mode, _show, _store, _addr) -#define IIO_DEV_ATTR_GYRO_Z_QUADRATURE_CORRECTION(_show, _addr) \ - IIO_DEVICE_ATTR(gyro_z_quadrature_correction_raw, S_IRUGO, _show, NULL, _addr) - #define IIO_DEV_ATTR_GYRO(_show, _addr) \ IIO_DEVICE_ATTR(gyro_raw, S_IRUGO, _show, NULL, _addr) diff --git a/trunk/drivers/staging/iio/magnetometer/ak8975.c b/trunk/drivers/staging/iio/magnetometer/ak8975.c index d71904a83706..420f206cf517 100644 --- a/trunk/drivers/staging/iio/magnetometer/ak8975.c +++ b/trunk/drivers/staging/iio/magnetometer/ak8975.c @@ -206,7 +206,7 @@ static int ak8975_setup(struct i2c_client *client) } /* Precalculate scale factor for each axis and - store in the device data. */ + store in the device data. */ data->raw_to_gauss[0] = ((data->asa[0] + 128) * 30) >> 8; data->raw_to_gauss[1] = ((data->asa[1] + 128) * 30) >> 8; data->raw_to_gauss[2] = ((data->asa[2] + 128) * 30) >> 8; @@ -316,59 +316,6 @@ static ssize_t show_scale(struct device *dev, struct device_attribute *devattr, return sprintf(buf, "%ld\n", data->raw_to_gauss[this_attr->address]); } -static int wait_conversion_complete_gpio(struct ak8975_data *data) -{ - struct i2c_client *client = data->client; - u8 read_status; - u32 timeout_ms = AK8975_MAX_CONVERSION_TIMEOUT; - int ret; - - /* Wait for the conversion to complete. */ - while (timeout_ms) { - msleep(AK8975_CONVERSION_DONE_POLL_TIME); - if (gpio_get_value(data->eoc_gpio)) - break; - timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME; - } - if (!timeout_ms) { - dev_err(&client->dev, "Conversion timeout happened\n"); - return -EINVAL; - } - - ret = ak8975_read_data(client, AK8975_REG_ST1, 1, &read_status); - if (ret < 0) { - dev_err(&client->dev, "Error in reading ST1\n"); - return ret; - } - return read_status; -} - -static int wait_conversion_complete_polled(struct ak8975_data *data) -{ - struct i2c_client *client = data->client; - u8 read_status; - u32 timeout_ms = AK8975_MAX_CONVERSION_TIMEOUT; - int ret; - - /* Wait for the conversion to complete. */ - while (timeout_ms) { - msleep(AK8975_CONVERSION_DONE_POLL_TIME); - ret = ak8975_read_data(client, AK8975_REG_ST1, 1, &read_status); - if (ret < 0) { - dev_err(&client->dev, "Error in reading ST1\n"); - return ret; - } - if (read_status) - break; - timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME; - } - if (!timeout_ms) { - dev_err(&client->dev, "Conversion timeout happened\n"); - return -EINVAL; - } - return read_status; -} - /* * Emits the raw flux value for the x, y, or z axis. */ @@ -379,6 +326,7 @@ static ssize_t show_raw(struct device *dev, struct device_attribute *devattr, struct ak8975_data *data = indio_dev->dev_data; struct i2c_client *client = data->client; struct iio_dev_attr *this_attr = to_iio_dev_attr(devattr); + u32 timeout_ms = AK8975_MAX_CONVERSION_TIMEOUT; u16 meas_reg; s16 raw; u8 read_status; @@ -404,14 +352,23 @@ static ssize_t show_raw(struct device *dev, struct device_attribute *devattr, } /* Wait for the conversion to complete. */ - if (data->eoc_gpio) - ret = wait_conversion_complete_gpio(data); - else - ret = wait_conversion_complete_polled(data); - if (ret < 0) + while (timeout_ms) { + msleep(AK8975_CONVERSION_DONE_POLL_TIME); + if (gpio_get_value(data->eoc_gpio)) + break; + timeout_ms -= AK8975_CONVERSION_DONE_POLL_TIME; + } + if (!timeout_ms) { + dev_err(&client->dev, "Conversion timeout happened\n"); + ret = -EINVAL; goto exit; + } - read_status = ret; + ret = ak8975_read_data(client, AK8975_REG_ST1, 1, &read_status); + if (ret < 0) { + dev_err(&client->dev, "Error in reading ST1\n"); + goto exit; + } if (read_status & AK8975_REG_ST1_DRDY_MASK) { ret = ak8975_read_data(client, AK8975_REG_ST2, 1, &read_status); @@ -497,26 +454,25 @@ static int ak8975_probe(struct i2c_client *client, data->eoc_irq = client->irq; data->eoc_gpio = irq_to_gpio(client->irq); - /* We may not have a GPIO based IRQ to scan, that is fine, we will - poll if so */ - if (data->eoc_gpio > 0) { - err = gpio_request(data->eoc_gpio, "ak_8975"); - if (err < 0) { - dev_err(&client->dev, - "failed to request GPIO %d, error %d\n", - data->eoc_gpio, err); - goto exit_free; - } + if (!data->eoc_gpio) { + dev_err(&client->dev, "failed, no valid GPIO\n"); + err = -EINVAL; + goto exit_free; + } - err = gpio_direction_input(data->eoc_gpio); - if (err < 0) { - dev_err(&client->dev, - "Failed to configure input direction for GPIO %d, error %d\n", - data->eoc_gpio, err); - goto exit_gpio; - } - } else - data->eoc_gpio = 0; /* No GPIO available */ + err = gpio_request(data->eoc_gpio, "ak_8975"); + if (err < 0) { + dev_err(&client->dev, "failed to request GPIO %d, error %d\n", + data->eoc_gpio, err); + goto exit_free; + } + + err = gpio_direction_input(data->eoc_gpio); + if (err < 0) { + dev_err(&client->dev, "Failed to configure input direction for" + " GPIO %d, error %d\n", data->eoc_gpio, err); + goto exit_gpio; + } /* Perform some basic start-of-day setup of the device. */ err = ak8975_setup(client); @@ -547,8 +503,7 @@ static int ak8975_probe(struct i2c_client *client, exit_free_iio: iio_free_device(data->indio_dev); exit_gpio: - if (data->eoc_gpio) - gpio_free(data->eoc_gpio); + gpio_free(data->eoc_gpio); exit_free: kfree(data); exit: @@ -562,8 +517,7 @@ static int ak8975_remove(struct i2c_client *client) iio_device_unregister(data->indio_dev); iio_free_device(data->indio_dev); - if (data->eoc_gpio) - gpio_free(data->eoc_gpio); + gpio_free(data->eoc_gpio); kfree(data); diff --git a/trunk/drivers/staging/iio/sysfs.h b/trunk/drivers/staging/iio/sysfs.h index 8f4d5474c093..24b74ddcd083 100644 --- a/trunk/drivers/staging/iio/sysfs.h +++ b/trunk/drivers/staging/iio/sysfs.h @@ -266,7 +266,6 @@ struct iio_const_attr { #define IIO_EV_CLASS_MAGN 4 #define IIO_EV_CLASS_LIGHT 5 #define IIO_EV_CLASS_PROXIMITY 6 -#define IIO_EV_CLASS_TEMP 7 #define IIO_EV_MOD_X 0 #define IIO_EV_MOD_Y 1 diff --git a/trunk/drivers/staging/intel_sst/intel_sst_app_interface.c b/trunk/drivers/staging/intel_sst/intel_sst_app_interface.c index d7454e210aae..1d0621260ea8 100644 --- a/trunk/drivers/staging/intel_sst/intel_sst_app_interface.c +++ b/trunk/drivers/staging/intel_sst/intel_sst_app_interface.c @@ -418,6 +418,10 @@ static int snd_sst_fill_kernel_list(struct stream_info *stream, static int sent_offset; static unsigned long sent_index; + stream_bufs = kzalloc(sizeof(*stream_bufs), GFP_KERNEL); + if (!stream_bufs) + return -ENOMEM; + stream_bufs->addr = sst_drv_ctx->mmap_mem; #ifdef CONFIG_MRST_RAR_HANDLER if (stream->ops == STREAM_OPS_PLAYBACK_DRM) { for (index = stream->sg_index; index < nr_segs; index++) { @@ -444,10 +448,6 @@ static int snd_sst_fill_kernel_list(struct stream_info *stream, return retval; } #endif - stream_bufs = kzalloc(sizeof(*stream_bufs), GFP_KERNEL); - if (!stream_bufs) - return -ENOMEM; - stream_bufs->addr = sst_drv_ctx->mmap_mem; mmap_len = sst_drv_ctx->mmap_len; stream_bufs->addr = sst_drv_ctx->mmap_mem; bufp = stream->cur_ptr; diff --git a/trunk/drivers/staging/keucr/msscsi.c b/trunk/drivers/staging/keucr/msscsi.c index d1a919b8823a..cb92d25acee0 100644 --- a/trunk/drivers/staging/keucr/msscsi.c +++ b/trunk/drivers/staging/keucr/msscsi.c @@ -1,5 +1,3 @@ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -46,7 +44,7 @@ int MS_SCSIIrp(struct us_data *us, struct scsi_cmnd *srb) //----- MS_SCSI_Test_Unit_Ready() -------------------------------------------------- int MS_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb) { - /* pr_info("MS_SCSI_Test_Unit_Ready\n"); */ + //printk("MS_SCSI_Test_Unit_Ready\n"); if (us->MS_Status.Insert && us->MS_Status.Ready) return USB_STOR_TRANSPORT_GOOD; else @@ -61,7 +59,7 @@ int MS_SCSI_Test_Unit_Ready(struct us_data *us, struct scsi_cmnd *srb) //----- MS_SCSI_Inquiry() -------------------------------------------------- int MS_SCSI_Inquiry(struct us_data *us, struct scsi_cmnd *srb) { - /* pr_info("MS_SCSI_Inquiry\n"); */ + //printk("MS_SCSI_Inquiry\n"); BYTE data_ptr[36] = {0x00, 0x80, 0x02, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x55, 0x53, 0x42, 0x32, 0x2E, 0x30, 0x20, 0x20, 0x43, 0x61, 0x72, 0x64, 0x52, 0x65, 0x61, 0x64, 0x65, 0x72, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x30, 0x30}; usb_stor_set_xfer_buf(us, data_ptr, 36, srb, TO_XFER_BUF); @@ -93,7 +91,7 @@ int MS_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb) WORD bl_len; BYTE buf[8]; - pr_info("MS_SCSI_Read_Capacity\n"); + printk("MS_SCSI_Read_Capacity\n"); bl_len = 0x200; if ( us->MS_Status.IsMSPro ) @@ -102,8 +100,8 @@ int MS_SCSI_Read_Capacity(struct us_data *us, struct scsi_cmnd *srb) bl_num = us->MS_Lib.NumberOfLogBlock * us->MS_Lib.blockSize * 2 - 1; us->bl_num = bl_num; - pr_info("bl_len = %x\n", bl_len); - pr_info("bl_num = %x\n", bl_num); + printk("bl_len = %x\n", bl_len); + printk("bl_num = %x\n", bl_num); //srb->request_bufflen = 8; buf[0] = (bl_num>>24) & 0xff; @@ -132,8 +130,7 @@ int MS_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb) WORD blen = ((Cdb[7]<< 8) & 0xff00) | ((Cdb[8]<< 0) & 0x00ff); DWORD blenByte = blen * 0x200; - /* pr_info("SCSIOP_READ --- bn = %X, blen = %X, srb->use_sg = %X\n", - bn, blen, srb->use_sg); */ + //printk("SCSIOP_READ --- bn = %X, blen = %X, srb->use_sg = %X\n", bn, blen, srb->use_sg); if (bn > us->bl_num) return USB_STOR_TRANSPORT_ERROR; @@ -143,7 +140,7 @@ int MS_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb) result = ENE_LoadBinCode(us, MSP_RW_PATTERN); if (result != USB_STOR_XFER_GOOD) { - pr_info("Load MSP RW pattern Fail !!\n"); + printk("Load MSP RW pattern Fail !!\n"); return USB_STOR_TRANSPORT_ERROR; } @@ -177,7 +174,7 @@ int MS_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb) result = ENE_LoadBinCode(us, MS_RW_PATTERN); if (result != USB_STOR_XFER_GOOD) { - pr_info("Load MS RW pattern Fail !!\n"); + printk("Load MS RW pattern Fail !!\n"); result = USB_STOR_TRANSPORT_ERROR; goto exit; } @@ -210,8 +207,7 @@ int MS_SCSI_Read(struct us_data *us, struct scsi_cmnd *srb) result = ENE_SendScsiCmd(us, FDIR_READ, buf+offset, 0); if (result != USB_STOR_XFER_GOOD) { - pr_info("MS_SCSI_Read --- result = %x\n", - result); + printk("MS_SCSI_Read --- result = %x\n", result); result = USB_STOR_TRANSPORT_ERROR; goto exit; } @@ -249,7 +245,7 @@ int MS_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb) result = ENE_LoadBinCode(us, MSP_RW_PATTERN); if (result != USB_STOR_XFER_GOOD) { - pr_info("Load MSP RW pattern Fail !!\n"); + printk("Load MSP RW pattern Fail !!\n"); return USB_STOR_TRANSPORT_ERROR; } @@ -284,7 +280,7 @@ int MS_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb) result = ENE_LoadBinCode(us, MS_RW_PATTERN); if (result != USB_STOR_XFER_GOOD) { - pr_info("Load MS RW pattern Fail !!\n"); + printk("Load MS RW pattern Fail !!\n"); result = USB_STOR_TRANSPORT_ERROR; goto exit; } @@ -305,8 +301,7 @@ int MS_SCSI_Write(struct us_data *us, struct scsi_cmnd *srb) result = MS_ReaderCopyBlock(us, oldphy, newphy, PhyBlockAddr, PageNum, buf+offset, len); if (result != USB_STOR_XFER_GOOD) { - pr_info("MS_SCSI_Write --- result = %x\n", - result); + printk("MS_SCSI_Write --- result = %x\n", result); result = USB_STOR_TRANSPORT_ERROR; goto exit; } diff --git a/trunk/drivers/staging/keucr/scsiglue.c b/trunk/drivers/staging/keucr/scsiglue.c index 5e35d94c6a1b..da4f42af3838 100644 --- a/trunk/drivers/staging/keucr/scsiglue.c +++ b/trunk/drivers/staging/keucr/scsiglue.c @@ -1,5 +1,3 @@ -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - #include #include #include @@ -18,7 +16,7 @@ //----- host_info() --------------------- static const char* host_info(struct Scsi_Host *host) { - /* pr_info("scsiglue --- host_info\n"); */ + //printk("scsiglue --- host_info\n"); return "SCSI emulation for USB Mass Storage devices"; } @@ -27,7 +25,7 @@ static int slave_alloc(struct scsi_device *sdev) { struct us_data *us = host_to_us(sdev->host); - /* pr_info("scsiglue --- slave_alloc\n"); */ + //printk("scsiglue --- slave_alloc\n"); sdev->inquiry_len = 36; blk_queue_update_dma_alignment(sdev->request_queue, (512 - 1)); @@ -43,7 +41,7 @@ static int slave_configure(struct scsi_device *sdev) { struct us_data *us = host_to_us(sdev->host); - /* pr_info("scsiglue --- slave_configure\n"); */ + //printk("scsiglue --- slave_configure\n"); if (us->fflags & (US_FL_MAX_SECTORS_64 | US_FL_MAX_SECTORS_MIN)) { unsigned int max_sectors = 64; @@ -93,20 +91,19 @@ static int queuecommand_lck(struct scsi_cmnd *srb, void (*done)(struct scsi_cmnd { struct us_data *us = host_to_us(srb->device->host); - /* pr_info("scsiglue --- queuecommand\n"); */ + //printk("scsiglue --- queuecommand\n"); /* check for state-transition errors */ if (us->srb != NULL) { - /* pr_info("Error in %s: us->srb = %p\n" - __FUNCTION__, us->srb); */ + printk("Error in %s: us->srb = %p\n", __FUNCTION__, us->srb); return SCSI_MLQUEUE_HOST_BUSY; } /* fail the command if we are disconnecting */ if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) { - pr_info("Fail command during disconnect\n"); + printk("Fail command during disconnect\n"); srb->result = DID_NO_CONNECT << 16; done(srb); return 0; @@ -132,7 +129,7 @@ static int command_abort(struct scsi_cmnd *srb) { struct us_data *us = host_to_us(srb->device->host); - /* pr_info("scsiglue --- command_abort\n"); */ + //printk("scsiglue --- command_abort\n"); scsi_lock(us_to_host(us)); if (us->srb != srb) @@ -162,7 +159,7 @@ static int device_reset(struct scsi_cmnd *srb) struct us_data *us = host_to_us(srb->device->host); int result; - /* pr_info("scsiglue --- device_reset\n"); */ + //printk("scsiglue --- device_reset\n"); /* lock the device pointers and do the reset */ mutex_lock(&(us->dev_mutex)); @@ -178,7 +175,7 @@ static int bus_reset(struct scsi_cmnd *srb) struct us_data *us = host_to_us(srb->device->host); int result; - /* pr_info("scsiglue --- bus_reset\n"); */ + //printk("scsiglue --- bus_reset\n"); result = usb_stor_port_reset(us); return result < 0 ? FAILED : SUCCESS; } @@ -189,7 +186,7 @@ void usb_stor_report_device_reset(struct us_data *us) int i; struct Scsi_Host *host = us_to_host(us); - /* pr_info("scsiglue --- usb_stor_report_device_reset\n"); */ + //printk("scsiglue --- usb_stor_report_device_reset\n"); scsi_report_device_reset(host, 0, 0); if (us->fflags & US_FL_SCM_MULT_TARG) { @@ -203,7 +200,7 @@ void usb_stor_report_bus_reset(struct us_data *us) { struct Scsi_Host *host = us_to_host(us); - /* pr_info("scsiglue --- usb_stor_report_bus_reset\n"); */ + //printk("scsiglue --- usb_stor_report_bus_reset\n"); scsi_lock(host); scsi_report_bus_reset(host, 0); scsi_unlock(host); @@ -225,7 +222,7 @@ static int proc_info (struct Scsi_Host *host, char *buffer, char **start, off_t char *pos = buffer; const char *string; - /* pr_info("scsiglue --- proc_info\n"); */ + //printk("scsiglue --- proc_info\n"); if (inout) return length; @@ -291,7 +288,7 @@ static ssize_t show_max_sectors(struct device *dev, struct device_attribute *att { struct scsi_device *sdev = to_scsi_device(dev); - /* pr_info("scsiglue --- ssize_t show_max_sectors\n"); */ + //printk("scsiglue --- ssize_t show_max_sectors\n"); return sprintf(buf, "%u\n", queue_max_sectors(sdev->request_queue)); } @@ -302,7 +299,7 @@ static ssize_t store_max_sectors(struct device *dev, struct device_attribute *at struct scsi_device *sdev = to_scsi_device(dev); unsigned short ms; - /* pr_info("scsiglue --- ssize_t store_max_sectors\n"); */ + //printk("scsiglue --- ssize_t store_max_sectors\n"); if (sscanf(buf, "%hu", &ms) > 0 && ms <= SCSI_DEFAULT_MAX_SECTORS) { blk_queue_max_hw_sectors(sdev->request_queue, ms); @@ -386,7 +383,7 @@ unsigned int usb_stor_access_xfer_buf(struct us_data *us, unsigned char *buffer, { unsigned int cnt; - /* pr_info("transport --- usb_stor_access_xfer_buf\n"); */ + //printk("transport --- usb_stor_access_xfer_buf\n"); struct scatterlist *sg = *sgptr; if (!sg) @@ -444,7 +441,7 @@ void usb_stor_set_xfer_buf(struct us_data *us, unsigned char *buffer, unsigned i unsigned int offset = 0; struct scatterlist *sg = NULL; - /* pr_info("transport --- usb_stor_set_xfer_buf\n"); */ + //printk("transport --- usb_stor_set_xfer_buf\n"); // TO_XFER_BUF = 0, FROM_XFER_BUF = 1 buflen = min(buflen, scsi_bufflen(srb)); buflen = usb_stor_access_xfer_buf(us, buffer, buflen, srb, &sg, &offset, dir); diff --git a/trunk/drivers/staging/keucr/smilmain.c b/trunk/drivers/staging/keucr/smilmain.c index 566dac0ed426..95c688a5c95a 100644 --- a/trunk/drivers/staging/keucr/smilmain.c +++ b/trunk/drivers/staging/keucr/smilmain.c @@ -102,12 +102,12 @@ int SM_FreeMem(void) { int i; - pr_info("SM_FreeMem start\n"); + printk("SM_FreeMem start\n"); for (i=0; i #include #include @@ -20,7 +18,7 @@ static void usb_stor_blocking_completion(struct urb *urb) { struct completion *urb_done_ptr = urb->context; - /* pr_info("transport --- usb_stor_blocking_completion\n"); */ + //printk("transport --- usb_stor_blocking_completion\n"); complete(urb_done_ptr); } @@ -31,7 +29,7 @@ static int usb_stor_msg_common(struct us_data *us, int timeout) long timeleft; int status; - /* pr_info("transport --- usb_stor_msg_common\n"); */ + //printk("transport --- usb_stor_msg_common\n"); if (test_bit(US_FLIDX_ABORTING, &us->dflags)) return -EIO; @@ -58,7 +56,7 @@ static int usb_stor_msg_common(struct us_data *us, int timeout) { if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) { - /* pr_info("-- cancelling URB\n"); */ + //printk("-- cancelling URB\n"); usb_unlink_urb(us->current_urb); } } @@ -68,8 +66,7 @@ static int usb_stor_msg_common(struct us_data *us, int timeout) if (timeleft <= 0) { - /* pr_info("%s -- cancelling URB\n", - timeleft == 0 ? "Timeout" : "Signal"); */ + //printk("%s -- cancelling URB\n", timeleft == 0 ? "Timeout" : "Signal"); usb_kill_urb(us->current_urb); } @@ -83,7 +80,7 @@ int usb_stor_control_msg(struct us_data *us, unsigned int pipe, { int status; - /* pr_info("transport --- usb_stor_control_msg\n"); */ + //printk("transport --- usb_stor_control_msg\n"); /* fill in the devrequest structure */ us->cr->bRequestType = requesttype; @@ -110,7 +107,7 @@ int usb_stor_clear_halt(struct us_data *us, unsigned int pipe) int result; int endp = usb_pipeendpoint(pipe); - /* pr_info("transport --- usb_stor_clear_halt\n"); */ + //printk("transport --- usb_stor_clear_halt\n"); if (usb_pipein (pipe)) endp |= USB_DIR_IN; @@ -131,41 +128,41 @@ int usb_stor_clear_halt(struct us_data *us, unsigned int pipe) static int interpret_urb_result(struct us_data *us, unsigned int pipe, unsigned int length, int result, unsigned int partial) { - /* pr_info("transport --- interpret_urb_result\n"); */ + //printk("transport --- interpret_urb_result\n"); switch (result) { /* no error code; did we send all the data? */ case 0: if (partial != length) { - /* pr_info("-- short transfer\n"); */ + //printk("-- short transfer\n"); return USB_STOR_XFER_SHORT; } - /* pr_info("-- transfer complete\n"); */ + //printk("-- transfer complete\n"); return USB_STOR_XFER_GOOD; case -EPIPE: if (usb_pipecontrol(pipe)) { - /* pr_info("-- stall on control pipe\n"); */ + //printk("-- stall on control pipe\n"); return USB_STOR_XFER_STALLED; } - /* pr_info("clearing endpoint halt for pipe 0x%x\n", pipe); */ + //printk("clearing endpoint halt for pipe 0x%x\n", pipe); if (usb_stor_clear_halt(us, pipe) < 0) return USB_STOR_XFER_ERROR; return USB_STOR_XFER_STALLED; case -EOVERFLOW: - /* pr_info("-- babble\n"); */ + //printk("-- babble\n"); return USB_STOR_XFER_LONG; case -ECONNRESET: - /* pr_info("-- transfer cancelled\n"); */ + //printk("-- transfer cancelled\n"); return USB_STOR_XFER_ERROR; case -EREMOTEIO: - /* pr_info("-- short read transfer\n"); */ + //printk("-- short read transfer\n"); return USB_STOR_XFER_SHORT; case -EIO: - /* pr_info("-- abort or disconnect in progress\n"); */ + //printk("-- abort or disconnect in progress\n"); return USB_STOR_XFER_ERROR; default: - /* pr_info("-- unknown error\n"); */ + //printk("-- unknown error\n"); return USB_STOR_XFER_ERROR; } } @@ -176,7 +173,7 @@ int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe, { int result; - /* pr_info("transport --- usb_stor_bulk_transfer_buf\n"); */ + //printk("transport --- usb_stor_bulk_transfer_buf\n"); /* fill and submit the URB */ usb_fill_bulk_urb(us->current_urb, us->pusb_dev, pipe, buf, length, usb_stor_blocking_completion, NULL); @@ -196,7 +193,7 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe, { int result; - /* pr_info("transport --- usb_stor_bulk_transfer_sglist\n"); */ + //printk("transport --- usb_stor_bulk_transfer_sglist\n"); if (test_bit(US_FLIDX_ABORTING, &us->dflags)) return USB_STOR_XFER_ERROR; @@ -204,7 +201,7 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe, result = usb_sg_init(&us->current_sg, us->pusb_dev, pipe, 0, sg, num_sg, length, GFP_NOIO); if (result) { - /* pr_info("usb_sg_init returned %d\n", result); */ + //printk("usb_sg_init returned %d\n", result); return USB_STOR_XFER_ERROR; } @@ -217,7 +214,7 @@ static int usb_stor_bulk_transfer_sglist(struct us_data *us, unsigned int pipe, /* cancel the request, if it hasn't been cancelled already */ if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) { - /* pr_info("-- cancelling sg request\n"); */ + //printk("-- cancelling sg request\n"); usb_sg_cancel(&us->current_sg); } } @@ -252,7 +249,7 @@ int usb_stor_bulk_transfer_sg(struct us_data* us, unsigned int pipe, int result; unsigned int partial; - /* pr_info("transport --- usb_stor_bulk_transfer_sg\n"); */ + //printk("transport --- usb_stor_bulk_transfer_sg\n"); /* are we scatter-gathering? */ if (use_sg) { @@ -284,7 +281,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) int need_auto_sense; int result; - /* pr_info("transport --- usb_stor_invoke_transport\n"); */ + //printk("transport --- usb_stor_invoke_transport\n"); usb_stor_print_cmd(srb); /* send the command to the transport layer */ scsi_set_resid(srb, 0); @@ -293,7 +290,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) /* if the command gets aborted by the higher layers, we need to short-circuit all other processing */ if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { - /* pr_info("-- command was aborted\n"); */ + //printk("-- command was aborted\n"); srb->result = DID_ABORT << 16; goto Handle_Errors; } @@ -301,7 +298,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) /* if there is a transport error, reset and don't auto-sense */ if (result == USB_STOR_TRANSPORT_ERROR) { - /* pr_info("-- transport indicates error, resetting\n"); */ + //printk("-- transport indicates error, resetting\n"); srb->result = DID_ERROR << 16; goto Handle_Errors; } @@ -320,13 +317,13 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) if ((us->protocol == USB_PR_CB || us->protocol == USB_PR_DPCM_USB) && srb->sc_data_direction != DMA_FROM_DEVICE) { - /* pr_info("-- CB transport device requiring auto-sense\n"); */ + //printk("-- CB transport device requiring auto-sense\n"); need_auto_sense = 1; } if (result == USB_STOR_TRANSPORT_FAILED) { - /* pr_info("-- transport indicates command failure\n"); */ + //printk("-- transport indicates command failure\n"); need_auto_sense = 1; } @@ -336,7 +333,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) int temp_result; struct scsi_eh_save ses; - pr_info("Issuing auto-REQUEST_SENSE\n"); + printk("Issuing auto-REQUEST_SENSE\n"); scsi_eh_prep_cmnd(srb, &ses, NULL, 0, US_SENSE_SIZE); @@ -355,13 +352,13 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { - /* pr_info("-- auto-sense aborted\n"); */ + //printk("-- auto-sense aborted\n"); srb->result = DID_ABORT << 16; goto Handle_Errors; } if (temp_result != USB_STOR_TRANSPORT_GOOD) { - /* pr_info("-- auto-sense failure\n"); */ + //printk("-- auto-sense failure\n"); srb->result = DID_ERROR << 16; if (!(us->fflags & US_FL_SCM_MULT_TARG)) goto Handle_Errors; @@ -412,7 +409,7 @@ void ENE_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) { int result=0; - /* pr_info("transport --- ENE_stor_invoke_transport\n"); */ + //printk("transport --- ENE_stor_invoke_transport\n"); usb_stor_print_cmd(srb); /* send the command to the transport layer */ scsi_set_resid(srb, 0); @@ -430,7 +427,7 @@ void ENE_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) /* if the command gets aborted by the higher layers, we need to short-circuit all other processing */ if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) { - /* pr_info("-- command was aborted\n"); */ + //printk("-- command was aborted\n"); srb->result = DID_ABORT << 16; goto Handle_Errors; } @@ -438,7 +435,7 @@ void ENE_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) /* if there is a transport error, reset and don't auto-sense */ if (result == USB_STOR_TRANSPORT_ERROR) { - /* pr_info("-- transport indicates error, resetting\n"); */ + //printk("-- transport indicates error, resetting\n"); srb->result = DID_ERROR << 16; goto Handle_Errors; } @@ -453,7 +450,7 @@ void ENE_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us) srb->result = SAM_STAT_GOOD; if (result == USB_STOR_TRANSPORT_FAILED) { - /* pr_info("-- transport indicates command failure\n"); */ + //printk("-- transport indicates command failure\n"); //need_auto_sense = 1; BuildSenseBuffer(srb, us->SrbStatus); srb->result = SAM_STAT_CHECK_CONDITION; @@ -491,7 +488,7 @@ void BuildSenseBuffer(struct scsi_cmnd *srb, int SrbStatus) BYTE *buf = srb->sense_buffer; BYTE asc; - pr_info("transport --- BuildSenseBuffer\n"); + printk("transport --- BuildSenseBuffer\n"); switch (SrbStatus) { case SS_NOT_READY: asc = 0x3a; break; // sense key = 0x02 @@ -510,17 +507,17 @@ void BuildSenseBuffer(struct scsi_cmnd *srb, int SrbStatus) //----- usb_stor_stop_transport() --------------------- void usb_stor_stop_transport(struct us_data *us) { - /* pr_info("transport --- usb_stor_stop_transport\n"); */ + //printk("transport --- usb_stor_stop_transport\n"); if (test_and_clear_bit(US_FLIDX_URB_ACTIVE, &us->dflags)) { - /* pr_info("-- cancelling URB\n"); */ + //printk("-- cancelling URB\n"); usb_unlink_urb(us->current_urb); } if (test_and_clear_bit(US_FLIDX_SG_ACTIVE, &us->dflags)) { - /* pr_info("-- cancelling sg request\n"); */ + //printk("-- cancelling sg request\n"); usb_sg_cancel(&us->current_sg); } } @@ -530,7 +527,7 @@ int usb_stor_Bulk_max_lun(struct us_data *us) { int result; - /* pr_info("transport --- usb_stor_Bulk_max_lun\n"); */ + //printk("transport --- usb_stor_Bulk_max_lun\n"); /* issue the command */ us->iobuf[0] = 0; result = usb_stor_control_msg(us, us->recv_ctrl_pipe, @@ -539,8 +536,7 @@ int usb_stor_Bulk_max_lun(struct us_data *us) USB_RECIP_INTERFACE, 0, us->ifnum, us->iobuf, 1, HZ); - /* pr_info("GetMaxLUN command result is %d, data is %d\n", - result, us->iobuf[0]); */ + //printk("GetMaxLUN command result is %d, data is %d\n", result, us->iobuf[0]); /* if we have a successful request, return the result */ if (result > 0) @@ -561,7 +557,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us) unsigned int cswlen; unsigned int cbwlen = US_BULK_CB_WRAP_LEN; - /* pr_info("transport --- usb_stor_Bulk_transport\n"); */ + //printk("transport --- usb_stor_Bulk_transport\n"); /* Take care of BULK32 devices; set extra byte to 0 */ if (unlikely(us->fflags & US_FL_BULK32)) { @@ -585,13 +581,13 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us) // send command /* send it to out endpoint */ - /* pr_info("Bulk Command S 0x%x T 0x%x L %d F %d Trg %d LUN %d CL %d\n", + /*printk("Bulk Command S 0x%x T 0x%x L %d F %d Trg %d LUN %d CL %d\n", le32_to_cpu(bcb->Signature), bcb->Tag, le32_to_cpu(bcb->DataTransferLength), bcb->Flags, (bcb->Lun >> 4), (bcb->Lun & 0x0F), - bcb->Length); */ + bcb->Length);*/ result = usb_stor_bulk_transfer_buf(us, us->send_bulk_pipe, bcb, cbwlen, NULL); - /* pr_info("Bulk command transfer result=%d\n", result); */ + //printk("Bulk command transfer result=%d\n", result); if (result != USB_STOR_XFER_GOOD) return USB_STOR_TRANSPORT_ERROR; @@ -603,7 +599,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us) { unsigned int pipe = srb->sc_data_direction == DMA_FROM_DEVICE ? us->recv_bulk_pipe : us->send_bulk_pipe; result = usb_stor_bulk_srb(us, pipe, srb); - /* pr_info("Bulk data transfer result 0x%x\n", result); */ + //printk("Bulk data transfer result 0x%x\n", result); if (result == USB_STOR_XFER_ERROR) return USB_STOR_TRANSPORT_ERROR; @@ -612,12 +608,12 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us) } /* get CSW for device status */ - /* pr_info("Attempting to get CSW...\n"); */ + //printk("Attempting to get CSW...\n"); result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, &cswlen); if (result == USB_STOR_XFER_SHORT && cswlen == 0) { - /* pr_info("Received 0-length CSW; retrying...\n"); */ + //printk("Received 0-length CSW; retrying...\n"); result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, &cswlen); } @@ -625,23 +621,21 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us) if (result == USB_STOR_XFER_STALLED) { /* get the status again */ - /* pr_info("Attempting to get CSW (2nd try)...\n"); */ + //printk("Attempting to get CSW (2nd try)...\n"); result = usb_stor_bulk_transfer_buf(us, us->recv_bulk_pipe, bcs, US_BULK_CS_WRAP_LEN, NULL); } /* if we still have a failure at this point, we're in trouble */ - /* pr_info("Bulk status result = %d\n", result); */ + //printk("Bulk status result = %d\n", result); if (result != USB_STOR_XFER_GOOD) return USB_STOR_TRANSPORT_ERROR; /* check bulk status */ residue = le32_to_cpu(bcs->Residue); - /* pr_info("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n", - le32_to_cpu(bcs->Signature), - bcs->Tag, residue, bcs->Status); */ + //printk("Bulk Status S 0x%x T 0x%x R %u Stat 0x%x\n", le32_to_cpu(bcs->Signature), bcs->Tag, residue, bcs->Status); if (!(bcs->Tag == us->tag || (us->fflags & US_FL_BULK_IGNORE_TAG)) || bcs->Status > US_BULK_STAT_PHASE) { - /* pr_info("Bulk logical error\n"); */ + //printk("Bulk logical error\n"); return USB_STOR_TRANSPORT_ERROR; } @@ -649,14 +643,13 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us) { us->bcs_signature = bcs->Signature; //if (us->bcs_signature != cpu_to_le32(US_BULK_CS_SIGN)) - /* pr_info("Learnt BCS signature 0x%08X\n", - le32_to_cpu(us->bcs_signature)); */ + // printk("Learnt BCS signature 0x%08X\n", le32_to_cpu(us->bcs_signature)); } else if (bcs->Signature != us->bcs_signature) { - /* pr_info("Signature mismatch: got %08X, expecting %08X\n", + /*printk("Signature mismatch: got %08X, expecting %08X\n", le32_to_cpu(bcs->Signature), - le32_to_cpu(us->bcs_signature)); */ + le32_to_cpu(us->bcs_signature));*/ return USB_STOR_TRANSPORT_ERROR; } @@ -717,47 +710,47 @@ static int usb_stor_reset_common(struct us_data *us, int result; int result2; - /* pr_info("transport --- usb_stor_reset_common\n"); */ + //printk("transport --- usb_stor_reset_common\n"); if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) { - /* pr_info("No reset during disconnect\n"); */ + //printk("No reset during disconnect\n"); return -EIO; } result = usb_stor_control_msg(us, us->send_ctrl_pipe, request, requesttype, value, index, data, size, 5*HZ); if (result < 0) { - /* pr_info("Soft reset failed: %d\n", result); */ + //printk("Soft reset failed: %d\n", result); return result; } wait_event_interruptible_timeout(us->delay_wait, test_bit(US_FLIDX_DISCONNECTING, &us->dflags), HZ*6); if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) { - /* pr_info("Reset interrupted by disconnect\n"); */ + //printk("Reset interrupted by disconnect\n"); return -EIO; } - /* pr_info("Soft reset: clearing bulk-in endpoint halt\n"); */ + //printk("Soft reset: clearing bulk-in endpoint halt\n"); result = usb_stor_clear_halt(us, us->recv_bulk_pipe); - /* pr_info("Soft reset: clearing bulk-out endpoint halt\n"); */ + //printk("Soft reset: clearing bulk-out endpoint halt\n"); result2 = usb_stor_clear_halt(us, us->send_bulk_pipe); /* return a result code based on the result of the clear-halts */ if (result >= 0) result = result2; //if (result < 0) - /* pr_info("Soft reset failed\n"); */ + // printk("Soft reset failed\n"); //else - /* pr_info("Soft reset done\n"); */ + // printk("Soft reset done\n"); return result; } //----- usb_stor_Bulk_reset() --------------------- int usb_stor_Bulk_reset(struct us_data *us) { - /* pr_info("transport --- usb_stor_Bulk_reset\n"); */ + //printk("transport --- usb_stor_Bulk_reset\n"); return usb_stor_reset_common(us, US_BULK_RESET_REQUEST, USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, us->ifnum, NULL, 0); @@ -768,19 +761,18 @@ int usb_stor_port_reset(struct us_data *us) { int result; - /* pr_info("transport --- usb_stor_port_reset\n"); */ + //printk("transport --- usb_stor_port_reset\n"); result = usb_lock_device_for_reset(us->pusb_dev, us->pusb_intf); if (result < 0) - pr_info("unable to lock device for reset: %d\n", result); + printk("unable to lock device for reset: %d\n", result); else { /* Were we disconnected while waiting for the lock? */ if (test_bit(US_FLIDX_DISCONNECTING, &us->dflags)) { result = -EIO; - /* pr_info("No reset during disconnect\n"); */ + //printk("No reset during disconnect\n"); } else { result = usb_reset_device(us->pusb_dev); - /* pr_info("usb_reset_composite_device returns %d\n", - result); */ + //printk("usb_reset_composite_device returns %d\n", result); } usb_unlock_device(us->pusb_dev); } diff --git a/trunk/drivers/staging/keucr/usb.c b/trunk/drivers/staging/keucr/usb.c index b0d16700a5d7..8c2332ec4f5c 100644 --- a/trunk/drivers/staging/keucr/usb.c +++ b/trunk/drivers/staging/keucr/usb.c @@ -37,7 +37,7 @@ MODULE_DEVICE_TABLE (usb, eucr_usb_ids); int eucr_suspend(struct usb_interface *iface, pm_message_t message) { struct us_data *us = usb_get_intfdata(iface); - pr_info("--- eucr_suspend ---\n"); + printk("--- eucr_suspend ---\n"); /* Wait until no command is running */ mutex_lock(&us->dev_mutex); @@ -60,7 +60,7 @@ int eucr_resume(struct usb_interface *iface) BYTE tmp = 0; struct us_data *us = usb_get_intfdata(iface); - pr_info("--- eucr_resume---\n"); + printk("--- eucr_resume---\n"); mutex_lock(&us->dev_mutex); //US_DEBUGP("%s\n", __func__); @@ -85,7 +85,7 @@ int eucr_reset_resume(struct usb_interface *iface) BYTE tmp = 0; struct us_data *us = usb_get_intfdata(iface); - pr_info("--- eucr_reset_resume---\n"); + printk("--- eucr_reset_resume---\n"); //US_DEBUGP("%s\n", __func__); /* Report the reset to the SCSI core */ @@ -116,7 +116,7 @@ static int eucr_pre_reset(struct usb_interface *iface) { struct us_data *us = usb_get_intfdata(iface); - pr_info("usb --- eucr_pre_reset\n"); + printk("usb --- eucr_pre_reset\n"); /* Make sure no command runs during the reset */ mutex_lock(&us->dev_mutex); @@ -128,7 +128,7 @@ static int eucr_post_reset(struct usb_interface *iface) { struct us_data *us = usb_get_intfdata(iface); - pr_info("usb --- eucr_post_reset\n"); + printk("usb --- eucr_post_reset\n"); /* Report the reset to the SCSI core */ usb_stor_report_bus_reset(us); @@ -140,7 +140,7 @@ static int eucr_post_reset(struct usb_interface *iface) //----- fill_inquiry_response() --------------------- void fill_inquiry_response(struct us_data *us, unsigned char *data, unsigned int data_len) { - pr_info("usb --- fill_inquiry_response\n"); + printk("usb --- fill_inquiry_response\n"); if (data_len<36) // You lose. return; @@ -171,7 +171,7 @@ static int usb_stor_control_thread(void * __us) struct us_data *us = (struct us_data *)__us; struct Scsi_Host *host = us_to_host(us); - pr_info("usb --- usb_stor_control_thread\n"); + printk("usb --- usb_stor_control_thread\n"); for(;;) { if (wait_for_completion_interruptible(&us->cmnd_ready)) @@ -242,7 +242,7 @@ static int usb_stor_control_thread(void * __us) else { SkipForAbort: - pr_info("scsi command aborted\n"); + printk("scsi command aborted\n"); } if (test_bit(US_FLIDX_TIMED_OUT, &us->dflags)) @@ -277,7 +277,7 @@ static int usb_stor_control_thread(void * __us) //----- associate_dev() --------------------- static int associate_dev(struct us_data *us, struct usb_interface *intf) { - pr_info("usb --- associate_dev\n"); + printk("usb --- associate_dev\n"); /* Fill in the device-related fields */ us->pusb_dev = interface_to_usbdev(intf); @@ -291,21 +291,21 @@ static int associate_dev(struct us_data *us, struct usb_interface *intf) us->cr = usb_alloc_coherent(us->pusb_dev, sizeof(*us->cr), GFP_KERNEL, &us->cr_dma); if (!us->cr) { - pr_info("usb_ctrlrequest allocation failed\n"); + printk("usb_ctrlrequest allocation failed\n"); return -ENOMEM; } us->iobuf = usb_alloc_coherent(us->pusb_dev, US_IOBUF_SIZE, GFP_KERNEL, &us->iobuf_dma); if (!us->iobuf) { - pr_info("I/O buffer allocation failed\n"); + printk("I/O buffer allocation failed\n"); return -ENOMEM; } us->sensebuf = kmalloc(US_SENSE_SIZE, GFP_KERNEL); if (!us->sensebuf) { - pr_info("Sense buffer allocation failed\n"); + printk("Sense buffer allocation failed\n"); return -ENOMEM; } return 0; @@ -317,7 +317,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id) struct usb_device *dev = us->pusb_dev; struct usb_interface_descriptor *idesc = &us->pusb_intf->cur_altsetting->desc; - pr_info("usb --- get_device_info\n"); + printk("usb --- get_device_info\n"); us->subclass = idesc->bInterfaceSubClass; us->protocol = idesc->bInterfaceProtocol; @@ -326,7 +326,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id) if (us->fflags & US_FL_IGNORE_DEVICE) { - pr_info("device ignored\n"); + printk("device ignored\n"); return -ENODEV; } @@ -339,7 +339,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id) //----- get_transport() --------------------- static int get_transport(struct us_data *us) { - pr_info("usb --- get_transport\n"); + printk("usb --- get_transport\n"); switch (us->protocol) { case USB_PR_BULK: us->transport_name = "Bulk"; @@ -350,7 +350,7 @@ static int get_transport(struct us_data *us) default: return -EIO; } - /* pr_info("Transport: %s\n", us->transport_name); */ + //printk("Transport: %s\n", us->transport_name); /* fix for single-lun devices */ if (us->fflags & US_FL_SINGLE_LUN) @@ -361,11 +361,9 @@ static int get_transport(struct us_data *us) //----- get_protocol() --------------------- static int get_protocol(struct us_data *us) { - pr_info("usb --- get_protocol\n"); - pr_info("us->pusb_dev->descriptor.idVendor = %x\n", - us->pusb_dev->descriptor.idVendor); - pr_info("us->pusb_dev->descriptor.idProduct = %x\n", - us->pusb_dev->descriptor.idProduct); + printk("usb --- get_protocol\n"); + printk("us->pusb_dev->descriptor.idVendor = %x\n", us->pusb_dev->descriptor.idVendor); + printk("us->pusb_dev->descriptor.idProduct = %x\n", us->pusb_dev->descriptor.idProduct); switch (us->subclass) { case USB_SC_SCSI: us->protocol_name = "Transparent SCSI"; @@ -378,7 +376,7 @@ static int get_protocol(struct us_data *us) default: return -EIO; } - /* pr_info("Protocol: %s\n", us->protocol_name); */ + //printk("Protocol: %s\n", us->protocol_name); return 0; } @@ -392,7 +390,7 @@ static int get_pipes(struct us_data *us) struct usb_endpoint_descriptor *ep_out = NULL; struct usb_endpoint_descriptor *ep_int = NULL; - pr_info("usb --- get_pipes\n"); + printk("usb --- get_pipes\n"); for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { @@ -420,7 +418,7 @@ static int get_pipes(struct us_data *us) if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) { - pr_info("Endpoint sanity check failed! Rejecting dev.\n"); + printk("Endpoint sanity check failed! Rejecting dev.\n"); return -EIO; } @@ -442,11 +440,11 @@ static int usb_stor_acquire_resources(struct us_data *us) { struct task_struct *th; - pr_info("usb --- usb_stor_acquire_resources\n"); + printk("usb --- usb_stor_acquire_resources\n"); us->current_urb = usb_alloc_urb(0, GFP_KERNEL); if (!us->current_urb) { - pr_info("URB allocation failed\n"); + printk("URB allocation failed\n"); return -ENOMEM; } @@ -454,7 +452,7 @@ static int usb_stor_acquire_resources(struct us_data *us) th = kthread_run(usb_stor_control_thread, us, "eucr-storage"); if (IS_ERR(th)) { - pr_info("Unable to start control thread\n"); + printk("Unable to start control thread\n"); return PTR_ERR(th); } us->ctl_thread = th; @@ -465,7 +463,7 @@ static int usb_stor_acquire_resources(struct us_data *us) //----- usb_stor_release_resources() --------------------- static void usb_stor_release_resources(struct us_data *us) { - pr_info("usb --- usb_stor_release_resources\n"); + printk("usb --- usb_stor_release_resources\n"); SM_FreeMem(); @@ -476,7 +474,7 @@ static void usb_stor_release_resources(struct us_data *us) /* Call the destructor routine, if it exists */ if (us->extra_destructor) { - pr_info("-- calling extra_destructor()\n"); + printk("-- calling extra_destructor()\n"); us->extra_destructor(us->extra); } @@ -488,7 +486,7 @@ static void usb_stor_release_resources(struct us_data *us) //----- dissociate_dev() --------------------- static void dissociate_dev(struct us_data *us) { - pr_info("usb --- dissociate_dev\n"); + printk("usb --- dissociate_dev\n"); kfree(us->sensebuf); @@ -507,7 +505,7 @@ static void quiesce_and_remove_host(struct us_data *us) { struct Scsi_Host *host = us_to_host(us); - pr_info("usb --- quiesce_and_remove_host\n"); + printk("usb --- quiesce_and_remove_host\n"); /* If the device is really gone, cut short reset delays */ if (us->pusb_dev->state == USB_STATE_NOTATTACHED) @@ -537,7 +535,7 @@ static void quiesce_and_remove_host(struct us_data *us) //----- release_everything() --------------------- static void release_everything(struct us_data *us) { - pr_info("usb --- release_everything\n"); + printk("usb --- release_everything\n"); usb_stor_release_resources(us); dissociate_dev(us); @@ -549,8 +547,8 @@ static int usb_stor_scan_thread(void * __us) { struct us_data *us = (struct us_data *)__us; - pr_info("usb --- usb_stor_scan_thread\n"); - pr_info("EUCR : device found at %d\n", us->pusb_dev->devnum); + printk("usb --- usb_stor_scan_thread\n"); + printk("EUCR : device found at %d\n", us->pusb_dev->devnum); set_freezable(); /* Wait for the timeout to expire or for a disconnect */ @@ -571,7 +569,7 @@ static int usb_stor_scan_thread(void * __us) mutex_unlock(&us->dev_mutex); } scsi_scan_host(us_to_host(us)); - pr_info("EUCR : device scan complete\n"); + printk("EUCR : device scan complete\n"); } complete_and_exit(&us->scanning_done, 0); } @@ -585,12 +583,12 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id BYTE MiscReg03 = 0; struct task_struct *th; - pr_info("usb --- eucr_probe\n"); + printk("usb --- eucr_probe\n"); host = scsi_host_alloc(&usb_stor_host_template, sizeof(*us)); if (!host) { - pr_info("Unable to allocate the scsi host\n"); + printk("Unable to allocate the scsi host\n"); return -ENOMEM; } @@ -633,7 +631,7 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id result = scsi_add_host(host, &intf->dev); if (result) { - pr_info("Unable to add the scsi host\n"); + printk("Unable to add the scsi host\n"); goto BadDevice; } @@ -641,7 +639,7 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id th = kthread_create(usb_stor_scan_thread, us, "eucr-stor-scan"); if (IS_ERR(th)) { - pr_info("Unable to start the device-scanning thread\n"); + printk("Unable to start the device-scanning thread\n"); complete(&us->scanning_done); quiesce_and_remove_host(us); result = PTR_ERR(th); @@ -660,7 +658,7 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id if (!(MiscReg03 & 0x02)) { result = -ENODEV; quiesce_and_remove_host(us); - pr_info("keucr: The driver only supports SM/MS card.\ + printk(KERN_NOTICE "keucr: The driver only supports SM/MS card.\ To use SD card, \ please build driver/usb/storage/ums-eneub6250.ko\n"); goto BadDevice; @@ -670,7 +668,7 @@ static int eucr_probe(struct usb_interface *intf, const struct usb_device_id *id /* We come here if there are any problems */ BadDevice: - pr_info("usb --- eucr_probe failed\n"); + printk("usb --- eucr_probe failed\n"); release_everything(us); return result; } @@ -680,7 +678,7 @@ static void eucr_disconnect(struct usb_interface *intf) { struct us_data *us = usb_get_intfdata(intf); - pr_info("usb --- eucr_disconnect\n"); + printk("usb --- eucr_disconnect\n"); quiesce_and_remove_host(us); release_everything(us); } @@ -707,11 +705,11 @@ static struct usb_driver usb_storage_driver = { static int __init usb_stor_init(void) { int retval; - pr_info("usb --- usb_stor_init start\n"); + printk("usb --- usb_stor_init start\n"); retval = usb_register(&usb_storage_driver); if (retval == 0) - pr_info("ENE USB Mass Storage support registered.\n"); + printk("ENE USB Mass Storage support registered.\n"); return retval; } @@ -719,7 +717,7 @@ static int __init usb_stor_init(void) //----- usb_stor_exit() --------------------- static void __exit usb_stor_exit(void) { - pr_info("usb --- usb_stor_exit\n"); + printk("usb --- usb_stor_exit\n"); usb_deregister(&usb_storage_driver) ; } diff --git a/trunk/drivers/staging/rt2860/Kconfig b/trunk/drivers/staging/rt2860/Kconfig deleted file mode 100644 index f3a7e47df5e9..000000000000 --- a/trunk/drivers/staging/rt2860/Kconfig +++ /dev/null @@ -1,10 +0,0 @@ -config RT2860 - tristate "Ralink 2860/3090 wireless support" - depends on PCI && X86 && WLAN - select WIRELESS_EXT - select WEXT_PRIV - select CRC_CCITT - select FW_LOADER - ---help--- - This is an experimental driver for the Ralink 2860 and 3090 - wireless chips. diff --git a/trunk/drivers/staging/rt2860/Makefile b/trunk/drivers/staging/rt2860/Makefile deleted file mode 100644 index 6dd0aa5d0791..000000000000 --- a/trunk/drivers/staging/rt2860/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -obj-$(CONFIG_RT2860) += rt2860sta.o - -# TODO: all of these should be removed -ccflags-y := -DLINUX -DAGGREGATION_SUPPORT -DPIGGYBACK_SUPPORT -DWMM_SUPPORT -ccflags-y += -DRTMP_MAC_PCI -DRTMP_PCI_SUPPORT -DRT2860 -ccflags-y += -DRTMP_RF_RW_SUPPORT -DRTMP_EFUSE_SUPPORT -DRT30xx -DRT3090 -ccflags-y += -DDBG - -rt2860sta-y := \ - common/crypt_md5.o \ - common/crypt_sha2.o \ - common/crypt_hmac.o \ - common/mlme.o \ - common/cmm_wep.o \ - common/action.o \ - common/cmm_data.o \ - common/rtmp_init.o \ - common/cmm_tkip.o \ - common/cmm_aes.o \ - common/cmm_sync.o \ - common/eeprom.o \ - common/cmm_sanity.o \ - common/cmm_info.o \ - common/cmm_cfg.o \ - common/cmm_wpa.o \ - common/dfs.o \ - common/spectrum.o \ - common/rtmp_timer.o \ - common/rt_channel.o \ - common/cmm_asic.o \ - sta/assoc.o \ - sta/auth.o \ - sta/auth_rsp.o \ - sta/sync.o \ - sta/sanity.o \ - sta/rtmp_data.o \ - sta/connect.o \ - sta/wpa.o \ - rt_linux.o \ - rt_main_dev.o \ - sta_ioctl.o \ - common/ba_action.o \ - pci_main_dev.o \ - rt_pci_rbus.o \ - common/cmm_mac_pci.o \ - common/cmm_data_pci.o \ - common/ee_prom.o \ - common/rtmp_mcu.o \ - common/ee_efuse.o \ - chips/rt30xx.o \ - common/rt_rf.o \ - chips/rt3090.o diff --git a/trunk/drivers/staging/rt2860/TODO b/trunk/drivers/staging/rt2860/TODO deleted file mode 100644 index 8e2f6ee0a2be..000000000000 --- a/trunk/drivers/staging/rt2860/TODO +++ /dev/null @@ -1,16 +0,0 @@ -I'm hesitant to add a TODO file here, as the wireless developers would -really have people help them out on the "clean" rt2860 driver that can -be found at the http://rt2x00.serialmonkey.com/ site. - -But, if you wish to clean up this driver instead, here's a short list of -things that need to be done to get it into a more mergable shape: - -TODO: - - checkpatch.pl clean - - sparse clean - - port to in-kernel 80211 stack and common rt2x00 infrastructure - - review by the wireless developer community - -Please send any patches or complaints about this driver to Greg -Kroah-Hartman and don't bother the upstream wireless -kernel developers about it, they want nothing to do with it. diff --git a/trunk/drivers/staging/rt2860/ap.h b/trunk/drivers/staging/rt2860/ap.h deleted file mode 100644 index 2737c0c022f9..000000000000 --- a/trunk/drivers/staging/rt2860/ap.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - -Module Name: -ap.h - -Abstract: -Miniport generic portion header file - -Revision History: -Who When What --------- ---------- ---------------------------------------------- -Paul Lin 08-01-2002 created -James Tan 09-06-2002 modified (Revise NTCRegTable) -John Chang 12-22-2004 modified for RT2561/2661. merge with STA driver -*/ -#ifndef __AP_H__ -#define __AP_H__ - -/* ap_wpa.c */ -void WpaStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *Sm, - OUT STATE_MACHINE_FUNC Trans[]); - -#ifdef RTMP_MAC_USB -void BeaconUpdateExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); -#endif /* RTMP_MAC_USB // */ - -void RTMPSetPiggyBack(struct rt_rtmp_adapter *pAd, IN BOOLEAN bPiggyBack); - -void MacTableReset(struct rt_rtmp_adapter *pAd); - -struct rt_mac_table_entry *MacTableInsertEntry(struct rt_rtmp_adapter *pAd, - u8 *pAddr, - u8 apidx, IN BOOLEAN CleanAll); - -BOOLEAN MacTableDeleteEntry(struct rt_rtmp_adapter *pAd, - u16 wcid, u8 *pAddr); - -struct rt_mac_table_entry *MacTableLookup(struct rt_rtmp_adapter *pAd, - u8 *pAddr); - -#endif /* __AP_H__ */ diff --git a/trunk/drivers/staging/rt2860/chip/mac_pci.h b/trunk/drivers/staging/rt2860/chip/mac_pci.h deleted file mode 100644 index b8868a5b9e04..000000000000 --- a/trunk/drivers/staging/rt2860/chip/mac_pci.h +++ /dev/null @@ -1,355 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - mac_pci.h - - Abstract: - - Revision History: - Who When What - Justin P. Mattock 11/07/2010 Fix some typos - --------- ---------- ---------------------------------------------- - */ - -#ifndef __MAC_PCI_H__ -#define __MAC_PCI_H__ - -#include "../rtmp_type.h" -#include "rtmp_mac.h" -#include "rtmp_phy.h" -#include "../rtmp_iface.h" -#include "../rtmp_dot11.h" - -/* */ -/* Device ID & Vendor ID related definitions, */ -/* NOTE: you should not add the new VendorID/DeviceID here unless you know for sure what chip it belongs too. */ -/* */ -#define NIC_PCI_VENDOR_ID 0x1814 -#define PCIBUS_INTEL_VENDOR 0x8086 - -#if !defined(PCI_CAP_ID_EXP) -#define PCI_CAP_ID_EXP 0x10 -#endif -#if !defined(PCI_EXP_LNKCTL) -#define PCI_EXP_LNKCTL 0x10 -#endif -#if !defined(PCI_CLASS_BRIDGE_PCI) -#define PCI_CLASS_BRIDGE_PCI 0x0604 -#endif - -#define TXINFO_SIZE 0 -#define RTMP_PKT_TAIL_PADDING 0 -#define fRTMP_ADAPTER_NEED_STOP_TX 0 - -#define AUX_CTRL 0x10c - -/* */ -/* TX descriptor format, Tx ring, Mgmt Ring */ -/* */ -struct PACKED rt_txd { - /* Word 0 */ - u32 SDPtr0; - /* Word 1 */ - u32 SDLen1:14; - u32 LastSec1:1; - u32 Burst:1; - u32 SDLen0:14; - u32 LastSec0:1; - u32 DMADONE:1; - /*Word2 */ - u32 SDPtr1; - /*Word3 */ - u32 rsv2:24; - u32 WIV:1; /* Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correct position */ - u32 QSEL:2; /* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */ - u32 rsv:2; - u32 TCO:1; /* */ - u32 UCO:1; /* */ - u32 ICO:1; /* */ -}; - -/* */ -/* Rx descriptor format, Rx Ring */ -/* */ -typedef struct PACKED rt_rxd { - /* Word 0 */ - u32 SDP0; - /* Word 1 */ - u32 SDL1:14; - u32 Rsv:2; - u32 SDL0:14; - u32 LS0:1; - u32 DDONE:1; - /* Word 2 */ - u32 SDP1; - /* Word 3 */ - u32 BA:1; - u32 DATA:1; - u32 NULLDATA:1; - u32 FRAG:1; - u32 U2M:1; /* 1: this RX frame is unicast to me */ - u32 Mcast:1; /* 1: this is a multicast frame */ - u32 Bcast:1; /* 1: this is a broadcast frame */ - u32 MyBss:1; /* 1: this frame belongs to the same BSSID */ - u32 Crc:1; /* 1: CRC error */ - u32 CipherErr:2; /* 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid */ - u32 AMSDU:1; /* rx with 802.3 header, not 802.11 header. */ - u32 HTC:1; - u32 RSSI:1; - u32 L2PAD:1; - u32 AMPDU:1; - u32 Decrypted:1; /* this frame is being decrypted. */ - u32 PlcpSignal:1; /* To be moved */ - u32 PlcpRssil:1; /* To be moved */ - u32 Rsv1:13; -} RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC; - -typedef union _TX_ATTENUATION_CTRL_STRUC { - struct { - unsigned long RF_ISOLATION_ENABLE:1; - unsigned long Reserve2:7; - unsigned long PCIE_PHY_TX_ATTEN_VALUE:3; - unsigned long PCIE_PHY_TX_ATTEN_EN:1; - unsigned long Reserve1:20; - } field; - - unsigned long word; -} TX_ATTENUATION_CTRL_STRUC, *PTX_ATTENUATION_CTRL_STRUC; - -/* ----------------- EEPROM Related MACRO ----------------- */ - -/* 8051 firmware image for RT2860 - base address = 0x4000 */ -#define FIRMWARE_IMAGE_BASE 0x2000 -#define MAX_FIRMWARE_IMAGE_SIZE 0x2000 /* 8kbyte */ - -/* ----------------- Frimware Related MACRO ----------------- */ -#define RTMP_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen) \ - do { \ - unsigned long _i, _firm; \ - RTMP_IO_WRITE32(_pAd, PBF_SYS_CTRL, 0x10000); \ - \ - for (_i = 0; _i < _FwLen; _i += 4) { \ - _firm = _pFwImage[_i] + \ - (_pFwImage[_i+3] << 24) + \ - (_pFwImage[_i+2] << 16) + \ - (_pFwImage[_i+1] << 8); \ - RTMP_IO_WRITE32(_pAd, FIRMWARE_IMAGE_BASE + _i, _firm); \ - } \ - RTMP_IO_WRITE32(_pAd, PBF_SYS_CTRL, 0x00000); \ - RTMP_IO_WRITE32(_pAd, PBF_SYS_CTRL, 0x00001); \ - \ - /* initialize BBP R/W access agent */ \ - RTMP_IO_WRITE32(_pAd, H2M_BBP_AGENT, 0); \ - RTMP_IO_WRITE32(_pAd, H2M_MAILBOX_CSR, 0); \ - } while (0) - -/* ----------------- TX Related MACRO ----------------- */ -#define RTMP_START_DEQUEUE(pAd, QueIdx, irqFlags) do {} while (0) -#define RTMP_STOP_DEQUEUE(pAd, QueIdx, irqFlags) do {} while (0) - -#define RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \ - ((freeNum) >= (unsigned long)(pTxBlk->TotalFragNum + RTMP_GET_PACKET_FRAGMENTS(pPacket) + 3)) /* rough estimate we will use 3 more descriptor. */ -#define RTMP_RELEASE_DESC_RESOURCE(pAd, QueIdx) do {} while (0) - -#define NEED_QUEUE_BACK_FOR_AGG(pAd, QueIdx, freeNum, _TxFrameType) \ - (((freeNum != (TX_RING_SIZE-1)) && \ - (pAd->TxSwQueue[QueIdx].Number == 0)) || (freeNum < 3)) - -#define HAL_KickOutMgmtTx(_pAd, _QueIdx, _pPacket, _pSrcBufVA, _SrcBufLen) \ - RtmpPCIMgmtKickOut(_pAd, _QueIdx, _pPacket, _pSrcBufVA, _SrcBufLen) - -#define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \ - /* RtmpPCI_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) */ - -#define HAL_WriteTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \ - RtmpPCI_WriteSingleTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) - -#define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \ - RtmpPCI_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) - -#define HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber) \ - RtmpPCI_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber) - -#define HAL_FinalWriteTxResource(_pAd, _pTxBlk, _TotalMPDUSize, _FirstTxIdx) \ - RtmpPCI_FinalWriteTxResource(_pAd, _pTxBlk, _TotalMPDUSize, _FirstTxIdx) - -#define HAL_LastTxIdx(_pAd, _QueIdx, _LastTxIdx) \ - /*RtmpPCIDataLastTxIdx(_pAd, _QueIdx,_LastTxIdx) */ - -#define HAL_KickOutTx(_pAd, _pTxBlk, _QueIdx) \ - RTMP_IO_WRITE32((_pAd), TX_CTX_IDX0+((_QueIdx)*0x10), (_pAd)->TxRing[(_QueIdx)].TxCpuIdx) -/* RtmpPCIDataKickOut(_pAd, _pTxBlk, _QueIdx)*/ - -#define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen) \ - MiniportMMRequest(_pAd, _QueIdx, _pNullFrame, _frameLen) - -#define GET_TXRING_FREENO(_pAd, _QueIdx) \ - (_pAd->TxRing[_QueIdx].TxSwFreeIdx > _pAd->TxRing[_QueIdx].TxCpuIdx) ? \ - (_pAd->TxRing[_QueIdx].TxSwFreeIdx - _pAd->TxRing[_QueIdx].TxCpuIdx - 1) \ - : \ - (_pAd->TxRing[_QueIdx].TxSwFreeIdx + TX_RING_SIZE - _pAd->TxRing[_QueIdx].TxCpuIdx - 1); - -#define GET_MGMTRING_FREENO(_pAd) \ - (_pAd->MgmtRing.TxSwFreeIdx > _pAd->MgmtRing.TxCpuIdx) ? \ - (_pAd->MgmtRing.TxSwFreeIdx - _pAd->MgmtRing.TxCpuIdx - 1) \ - : \ - (_pAd->MgmtRing.TxSwFreeIdx + MGMT_RING_SIZE - _pAd->MgmtRing.TxCpuIdx - 1); - -/* ----------------- RX Related MACRO ----------------- */ - -/* ----------------- ASIC Related MACRO ----------------- */ -/* reset MAC of a station entry to 0x000000000000 */ -#define RTMP_STA_ENTRY_MAC_RESET(pAd, Wcid) \ - AsicDelWcidTab(pAd, Wcid); - -/* add this entry into ASIC RX WCID search table */ -#define RTMP_STA_ENTRY_ADD(pAd, pEntry) \ - AsicUpdateRxWCIDTable(pAd, pEntry->Aid, pEntry->Addr); - -/* add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */ -/* Set MAC register value according operation mode */ -#define RTMP_UPDATE_PROTECT(pAd) \ - AsicUpdateProtect(pAd, 0, (ALLN_SETPROTECT), TRUE, 0); -/* end johnli */ - -/* remove Pair-wise key material from ASIC */ -#define RTMP_STA_ENTRY_KEY_DEL(pAd, BssIdx, Wcid) \ - AsicRemovePairwiseKeyEntry(pAd, BssIdx, (u8)Wcid); - -/* add Client security information into ASIC WCID table and IVEIV table */ -#define RTMP_STA_SECURITY_INFO_ADD(pAd, apidx, KeyID, pEntry) \ - RTMPAddWcidAttributeEntry(pAd, apidx, KeyID, \ - pAd->SharedKey[apidx][KeyID].CipherAlg, pEntry); - -#define RTMP_SECURITY_KEY_ADD(pAd, apidx, KeyID, pEntry) \ - { /* update pairwise key information to ASIC Shared Key Table */ \ - AsicAddSharedKeyEntry(pAd, apidx, KeyID, \ - pAd->SharedKey[apidx][KeyID].CipherAlg, \ - pAd->SharedKey[apidx][KeyID].Key, \ - pAd->SharedKey[apidx][KeyID].TxMic, \ - pAd->SharedKey[apidx][KeyID].RxMic); \ - /* update ASIC WCID attribute table and IVEIV table */ \ - RTMPAddWcidAttributeEntry(pAd, apidx, KeyID, \ - pAd->SharedKey[apidx][KeyID].CipherAlg, \ - pEntry); } - -/* Insert the BA bitmap to ASIC for the Wcid entry */ -#define RTMP_ADD_BA_SESSION_TO_ASIC(_pAd, _Aid, _TID) \ - do { \ - u32 _Value = 0, _Offset; \ - _Offset = MAC_WCID_BASE + (_Aid) * HW_WCID_ENTRY_SIZE + 4; \ - RTMP_IO_READ32((_pAd), _Offset, &_Value);\ - _Value |= (0x10000<<(_TID)); \ - RTMP_IO_WRITE32((_pAd), _Offset, _Value);\ - } while (0) - -/* Remove the BA bitmap from ASIC for the Wcid entry */ -/* bitmap field starts at 0x10000 in ASIC WCID table */ -#define RTMP_DEL_BA_SESSION_FROM_ASIC(_pAd, _Wcid, _TID) \ - do { \ - u32 _Value = 0, _Offset; \ - _Offset = MAC_WCID_BASE + (_Wcid) * HW_WCID_ENTRY_SIZE + 4; \ - RTMP_IO_READ32((_pAd), _Offset, &_Value); \ - _Value &= (~(0x10000 << (_TID))); \ - RTMP_IO_WRITE32((_pAd), _Offset, _Value); \ - } while (0) - -/* ----------------- Interface Related MACRO ----------------- */ - -/* */ -/* Enable & Disable NIC interrupt via writing interrupt mask register */ -/* Since it use ADAPTER structure, it have to be put after structure definition. */ -/* */ -#define RTMP_ASIC_INTERRUPT_DISABLE(_pAd) \ - do { \ - RTMP_IO_WRITE32((_pAd), INT_MASK_CSR, 0x0); /* 0: disable */ \ - RTMP_CLEAR_FLAG((_pAd), fRTMP_ADAPTER_INTERRUPT_ACTIVE); \ - } while (0) - -#define RTMP_ASIC_INTERRUPT_ENABLE(_pAd)\ - do { \ - RTMP_IO_WRITE32((_pAd), INT_MASK_CSR, (_pAd)->int_enable_reg /*DELAYINTMASK*/); /* 1:enable */ \ - RTMP_SET_FLAG((_pAd), fRTMP_ADAPTER_INTERRUPT_ACTIVE); \ - } while (0) - -#define RTMP_IRQ_INIT(pAd) \ - { pAd->int_enable_reg = ((DELAYINTMASK) | \ - (RxINT|TxDataInt|TxMgmtInt)) & ~(0x03); \ - pAd->int_disable_mask = 0; \ - pAd->int_pending = 0; } - -#define RTMP_IRQ_ENABLE(pAd) \ - { /* clear garbage ints */ \ - RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, 0xffffffff);\ - RTMP_ASIC_INTERRUPT_ENABLE(pAd); } - -/* ----------------- MLME Related MACRO ----------------- */ -#define RTMP_MLME_HANDLER(pAd) MlmeHandler(pAd) - -#define RTMP_MLME_PRE_SANITY_CHECK(pAd) - -#define RTMP_MLME_STA_QUICK_RSP_WAKE_UP(pAd) \ - RTMPSetTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, 100); - -#define RTMP_MLME_RESET_STATE_MACHINE(pAd) \ - MlmeRestartStateMachine(pAd) - -#define RTMP_HANDLE_COUNTER_MEASURE(_pAd, _pEntry)\ - HandleCounterMeasure(_pAd, _pEntry) - -/* ----------------- Power Save Related MACRO ----------------- */ -#define RTMP_PS_POLL_ENQUEUE(pAd) EnqueuePsPoll(pAd) - -/* For RTMPPCIePowerLinkCtrlRestore () function */ -#define RESTORE_HALT 1 -#define RESTORE_WAKEUP 2 -#define RESTORE_CLOSE 3 - -#define PowerSafeCID 1 -#define PowerRadioOffCID 2 -#define PowerWakeCID 3 -#define CID0MASK 0x000000ff -#define CID1MASK 0x0000ff00 -#define CID2MASK 0x00ff0000 -#define CID3MASK 0xff000000 - -#define RTMP_STA_FORCE_WAKEUP(pAd, bFromTx) \ - RT28xxPciStaAsicForceWakeup(pAd, bFromTx); - -#define RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \ - RT28xxPciStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp); - -#define RTMP_SET_PSM_BIT(_pAd, _val) \ - MlmeSetPsmBit(_pAd, _val); - -#define RTMP_MLME_RADIO_ON(pAd) \ - RT28xxPciMlmeRadioOn(pAd); - -#define RTMP_MLME_RADIO_OFF(pAd) \ - RT28xxPciMlmeRadioOFF(pAd); - -#endif /*__MAC_PCI_H__ // */ diff --git a/trunk/drivers/staging/rt2860/chip/mac_usb.h b/trunk/drivers/staging/rt2860/chip/mac_usb.h deleted file mode 100644 index e8158fb58648..000000000000 --- a/trunk/drivers/staging/rt2860/chip/mac_usb.h +++ /dev/null @@ -1,345 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - mac_usb.h - - Abstract: - - Revision History: - Who When What - Justin P. Mattock 11/07/2010 Fix a typo - --------- ---------- ---------------------------------------------- - */ - -#ifndef __MAC_USB_H__ -#define __MAC_USB_H__ - -#include "../rtmp_type.h" -#include "rtmp_mac.h" -#include "rtmp_phy.h" -#include "../rtmp_iface.h" -#include "../rtmp_dot11.h" - -#define USB_CYC_CFG 0x02a4 - -#define BEACON_RING_SIZE 2 -#define MGMTPIPEIDX 0 /* EP6 is highest priority */ - -#define RTMP_PKT_TAIL_PADDING 11 /* 3(max 4 byte padding) + 4 (last packet padding) + 4 (MaxBulkOutsize align padding) */ - -#define fRTMP_ADAPTER_NEED_STOP_TX \ - (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \ - fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_BULKOUT_RESET | \ - fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_REMOVE_IN_PROGRESS) - -/* */ -/* RXINFO appends at the end of each rx packet. */ -/* */ -#define RXINFO_SIZE 4 -#define RT2870_RXDMALEN_FIELD_SIZE 4 - -typedef struct PACKED rt_rxinfo { - u32 BA:1; - u32 DATA:1; - u32 NULLDATA:1; - u32 FRAG:1; - u32 U2M:1; /* 1: this RX frame is unicast to me */ - u32 Mcast:1; /* 1: this is a multicast frame */ - u32 Bcast:1; /* 1: this is a broadcast frame */ - u32 MyBss:1; /* 1: this frame belongs to the same BSSID */ - u32 Crc:1; /* 1: CRC error */ - u32 CipherErr:2; /* 0: decryption okay, 1:ICV error, 2:MIC error, 3:KEY not valid */ - u32 AMSDU:1; /* rx with 802.3 header, not 802.11 header. */ - u32 HTC:1; - u32 RSSI:1; - u32 L2PAD:1; - u32 AMPDU:1; /* To be moved */ - u32 Decrypted:1; - u32 PlcpRssil:1; - u32 CipherAlg:1; - u32 LastAMSDU:1; - u32 PlcpSignal:12; -} RT28XX_RXD_STRUC, *PRT28XX_RXD_STRUC; - -/* */ -/* TXINFO */ -/* */ -#define TXINFO_SIZE 4 - -struct rt_txinfo { - /* Word 0 */ - u32 USBDMATxPktLen:16; /*used ONLY in USB bulk Aggregation, Total byte counts of all sub-frame. */ - u32 rsv:8; - u32 WIV:1; /* Wireless Info Valid. 1 if Driver already fill WI, o if DMA needs to copy WI to correct position */ - u32 QSEL:2; /* select on-chip FIFO ID for 2nd-stage output scheduler.0:MGMT, 1:HCCA 2:EDCA */ - u32 SwUseLastRound:1; /* Software use. */ - u32 rsv2:2; /* Software use. */ - u32 USBDMANextVLD:1; /*used ONLY in USB bulk Aggregation, NextValid */ - u32 USBDMATxburst:1; /*used ONLY in USB bulk Aggre. Force USB DMA transmit frame from current selected endpoint */ -}; - -/* */ -/* Management ring buffer format */ -/* */ -struct rt_mgmt { - BOOLEAN Valid; - u8 *pBuffer; - unsigned long Length; -}; - -/*////////////////////////////////////////////////////////////////////////// */ -/* The struct rt_tx_buffer structure forms the transmitted USB packet to the device */ -/*////////////////////////////////////////////////////////////////////////// */ -struct rt_tx_buffer { - union { - u8 WirelessPacket[TX_BUFFER_NORMSIZE]; - struct rt_header_802_11 NullFrame; - struct rt_pspoll_frame PsPollPacket; - struct rt_rts_frame RTSFrame; - } field; - u8 Aggregation[4]; /*Buffer for save Aggregation size. */ -}; - -struct rt_httx_buffer { - union { - u8 WirelessPacket[MAX_TXBULK_SIZE]; - struct rt_header_802_11 NullFrame; - struct rt_pspoll_frame PsPollPacket; - struct rt_rts_frame RTSFrame; - } field; - u8 Aggregation[4]; /*Buffer for save Aggregation size. */ -}; - -/* used to track driver-generated write irps */ -struct rt_tx_context { - void *pAd; /*Initialized in MiniportInitialize */ - PURB pUrb; /*Initialized in MiniportInitialize */ - PIRP pIrp; /*used to cancel pending bulk out. */ - /*Initialized in MiniportInitialize */ - struct rt_tx_buffer *TransferBuffer; /*Initialized in MiniportInitialize */ - unsigned long BulkOutSize; - u8 BulkOutPipeId; - u8 SelfIdx; - BOOLEAN InUse; - BOOLEAN bWaitingBulkOut; /* at least one packet is in this TxContext, ready for making IRP anytime. */ - BOOLEAN bFullForBulkOut; /* all tx buffer are full , so waiting for tx bulkout. */ - BOOLEAN IRPPending; - BOOLEAN LastOne; - BOOLEAN bAggregatible; - u8 Header_802_3[LENGTH_802_3]; - u8 Rsv[2]; - unsigned long DataOffset; - u32 TxRate; - dma_addr_t data_dma; /* urb dma on linux */ - -}; - -/* used to track driver-generated write irps */ -struct rt_ht_tx_context { - void *pAd; /*Initialized in MiniportInitialize */ - PURB pUrb; /*Initialized in MiniportInitialize */ - PIRP pIrp; /*used to cancel pending bulk out. */ - /*Initialized in MiniportInitialize */ - struct rt_httx_buffer *TransferBuffer; /*Initialized in MiniportInitialize */ - unsigned long BulkOutSize; /* Indicate the total bulk-out size in bytes in one bulk-transmission */ - u8 BulkOutPipeId; - BOOLEAN IRPPending; - BOOLEAN LastOne; - BOOLEAN bCurWriting; - BOOLEAN bRingEmpty; - BOOLEAN bCopySavePad; - u8 SavedPad[8]; - u8 Header_802_3[LENGTH_802_3]; - unsigned long CurWritePosition; /* Indicate the buffer offset which packet will be inserted start from. */ - unsigned long CurWriteRealPos; /* Indicate the buffer offset which packet now are writing to. */ - unsigned long NextBulkOutPosition; /* Indicate the buffer start offset of a bulk-transmission */ - unsigned long ENextBulkOutPosition; /* Indicate the buffer end offset of a bulk-transmission */ - u32 TxRate; - dma_addr_t data_dma; /* urb dma on linux */ -}; - -/* */ -/* Structure to keep track of receive packets and buffers to indicate */ -/* receive data to the protocol. */ -/* */ -struct rt_rx_context { - u8 *TransferBuffer; - void *pAd; - PIRP pIrp; /*used to cancel pending bulk in. */ - PURB pUrb; - /*These 2 Boolean shouldn't both be 1 at the same time. */ - unsigned long BulkInOffset; /* number of packets waiting for reordering . */ -/* BOOLEAN ReorderInUse; // At least one packet in this buffer are in reordering buffer and wait for receive indication */ - BOOLEAN bRxHandling; /* Notify this packet is being process now. */ - BOOLEAN InUse; /* USB Hardware Occupied. Wait for USB HW to put packet. */ - BOOLEAN Readable; /* Receive Complete back. OK for driver to indicate receiving packet. */ - BOOLEAN IRPPending; /* TODO: To be removed */ - atomic_t IrpLock; - spinlock_t RxContextLock; - dma_addr_t data_dma; /* urb dma on linux */ -}; - -/****************************************************************************** - - USB Frimware Related MACRO - -******************************************************************************/ -/* 8051 firmware image for usb - use last-half base address = 0x3000 */ -#define FIRMWARE_IMAGE_BASE 0x3000 -#define MAX_FIRMWARE_IMAGE_SIZE 0x1000 /* 4kbyte */ - -#define RTMP_WRITE_FIRMWARE(_pAd, _pFwImage, _FwLen) \ - RTUSBFirmwareWrite(_pAd, _pFwImage, _FwLen) - -/****************************************************************************** - - USB TX Related MACRO - -******************************************************************************/ -#define RTMP_START_DEQUEUE(pAd, QueIdx, irqFlags) \ - do { \ - RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \ - if (pAd->DeQueueRunning[QueIdx]) { \ - RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \ - DBGPRINT(RT_DEBUG_OFF, ("DeQueueRunning[%d]= TRUE!\n", QueIdx)); \ - continue; \ - } else { \ - pAd->DeQueueRunning[QueIdx] = TRUE; \ - RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags);\ - } \ - } while (0) - -#define RTMP_STOP_DEQUEUE(pAd, QueIdx, irqFlags) \ - do { \ - RTMP_IRQ_LOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \ - pAd->DeQueueRunning[QueIdx] = FALSE; \ - RTMP_IRQ_UNLOCK(&pAd->DeQueueLock[QueIdx], irqFlags); \ - } while (0) - -#define RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, freeNum, pPacket) \ - (RTUSBFreeDescriptorRequest(pAd, pTxBlk->QueIdx, (pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket))) == NDIS_STATUS_SUCCESS) - -#define RTMP_RELEASE_DESC_RESOURCE(pAd, QueIdx) \ - do {} while (0) - -#define NEED_QUEUE_BACK_FOR_AGG(_pAd, _QueIdx, _freeNum, _TxFrameType) \ - ((_TxFrameType == TX_RALINK_FRAME) && \ - (RTUSBNeedQueueBackForAgg(_pAd, _QueIdx))) - -#define HAL_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \ - RtmpUSB_WriteSubTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) - -#define HAL_WriteTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) \ - RtmpUSB_WriteSingleTxResource(pAd, pTxBlk, bIsLast, pFreeNumber) - -#define HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) \ - RtmpUSB_WriteFragTxResource(pAd, pTxBlk, fragNum, pFreeNumber) - -#define HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber) \ - RtmpUSB_WriteMultiTxResource(pAd, pTxBlk, frameNum, pFreeNumber) - -#define HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx) \ - RtmpUSB_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, TxIdx) - -#define HAL_LastTxIdx(pAd, QueIdx, TxIdx) \ - /*RtmpUSBDataLastTxIdx(pAd, QueIdx,TxIdx) */ - -#define HAL_KickOutTx(pAd, pTxBlk, QueIdx) \ - RtmpUSBDataKickOut(pAd, pTxBlk, QueIdx) - -#define HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen) \ - RtmpUSBMgmtKickOut(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen) - -#define HAL_KickOutNullFrameTx(_pAd, _QueIdx, _pNullFrame, _frameLen) \ - RtmpUSBNullFrameKickOut(_pAd, _QueIdx, _pNullFrame, _frameLen) - -#define GET_TXRING_FREENO(_pAd, _QueIdx) (_QueIdx) /*(_pAd->TxRing[_QueIdx].TxSwFreeIdx) */ -#define GET_MGMTRING_FREENO(_pAd) (_pAd->MgmtRing.TxSwFreeIdx) - -/* ----------------- RX Related MACRO ----------------- */ - -/* - * Device Hardware Interface Related MACRO - */ -#define RTMP_IRQ_INIT(pAd) do {} while (0) -#define RTMP_IRQ_ENABLE(pAd) do {} while (0) - -/* - * MLME Related MACRO - */ -#define RTMP_MLME_HANDLER(pAd) RTUSBMlmeUp(pAd) - -#define RTMP_MLME_PRE_SANITY_CHECK(pAd) \ - { if ((pAd->CommonCfg.bHardwareRadio == TRUE) && \ - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && \ - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { \ - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_CHECK_GPIO, NULL, 0); } } - -#define RTMP_MLME_STA_QUICK_RSP_WAKE_UP(pAd) \ - { RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_QKERIODIC_EXECUT, NULL, 0); \ - RTUSBMlmeUp(pAd); } - -#define RTMP_MLME_RESET_STATE_MACHINE(pAd) \ - { MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_RESET_CONF, 0, NULL); \ - RTUSBMlmeUp(pAd); } - -#define RTMP_HANDLE_COUNTER_MEASURE(_pAd, _pEntry) \ - { RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_802_11_COUNTER_MEASURE, _pEntry, sizeof(struct rt_mac_table_entry)); \ - RTUSBMlmeUp(_pAd); \ - } - -/* - * Power Save Related MACRO - */ -#define RTMP_PS_POLL_ENQUEUE(pAd) \ - { RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL); \ - RTUSBKickBulkOut(pAd); } - -#define RTMP_STA_FORCE_WAKEUP(_pAd, bFromTx) \ - RT28xxUsbStaAsicForceWakeup(_pAd, bFromTx); - -#define RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp) \ - RT28xxUsbStaAsicSleepThenAutoWakeup(pAd, TbttNumToNextWakeUp); - -#define RTMP_SET_PSM_BIT(_pAd, _val) \ - {\ - if ((_pAd)->StaCfg.WindowsPowerMode == Ndis802_11PowerModeFast_PSP) \ - MlmeSetPsmBit(_pAd, _val);\ - else { \ - u16 _psm_val; \ - _psm_val = _val; \ - RTUSBEnqueueInternalCmd(_pAd, CMDTHREAD_SET_PSM_BIT, &(_psm_val), sizeof(u16)); \ - } \ - } - -#define RTMP_MLME_RADIO_ON(pAd) \ - RT28xxUsbMlmeRadioOn(pAd); - -#define RTMP_MLME_RADIO_OFF(pAd) \ - RT28xxUsbMlmeRadioOFF(pAd); - -#endif /*__MAC_USB_H__ // */ diff --git a/trunk/drivers/staging/rt2860/chip/rt2860.h b/trunk/drivers/staging/rt2860/chip/rt2860.h deleted file mode 100644 index f30b80820b92..000000000000 --- a/trunk/drivers/staging/rt2860/chip/rt2860.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - */ - -#ifndef __RT2860_H__ -#define __RT2860_H__ - -#include "mac_pci.h" - -#ifndef RTMP_PCI_SUPPORT -#error "For RT2860, you should define the compile flag -DRTMP_PCI_SUPPORT" -#endif - -#ifndef RTMP_MAC_PCI -#error "For RT2880, you should define the compile flag -DRTMP_MAC_PCI" -#endif - -/* */ -/* Device ID & Vendor ID, these values should match EEPROM value */ -/* */ -#define NIC2860_PCI_DEVICE_ID 0x0601 -#define NIC2860_PCIe_DEVICE_ID 0x0681 -#define NIC2760_PCI_DEVICE_ID 0x0701 /* 1T/2R Cardbus ??? */ -#define NIC2790_PCIe_DEVICE_ID 0x0781 /* 1T/2R miniCard */ - -#define VEN_AWT_PCIe_DEVICE_ID 0x1059 -#define VEN_AWT_PCI_VENDOR_ID 0x1A3B - -#define EDIMAX_PCI_VENDOR_ID 0x1432 - -#endif /*__RT2860_H__ // */ diff --git a/trunk/drivers/staging/rt2860/chip/rt2870.h b/trunk/drivers/staging/rt2860/chip/rt2870.h deleted file mode 100644 index 8263f1baefae..000000000000 --- a/trunk/drivers/staging/rt2860/chip/rt2870.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - */ -#ifndef __RT2870_H__ -#define __RT2870_H__ - -#ifdef RT2870 - -#ifndef RTMP_USB_SUPPORT -#error "For RT2870, you should define the compile flag -DRTMP_USB_SUPPORT" -#endif - -#ifndef RTMP_MAC_USB -#error "For RT2870, you should define the compile flag -DRTMP_MAC_USB" -#endif - -#include "../rtmp_type.h" -#include "mac_usb.h" - -/*#define RTMP_CHIP_NAME "RT2870" */ - -#endif /* RT2870 // */ -#endif /*__RT2870_H__ // */ diff --git a/trunk/drivers/staging/rt2860/chip/rt3070.h b/trunk/drivers/staging/rt2860/chip/rt3070.h deleted file mode 100644 index 172ce7054233..000000000000 --- a/trunk/drivers/staging/rt2860/chip/rt3070.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt3070.h - - Abstract: - - Revision History: - Who When What - --------- ---------- ---------------------------------------------- - */ - -#ifndef __RT3070_H__ -#define __RT3070_H__ - -#ifdef RT3070 - -#ifndef RTMP_USB_SUPPORT -#error "For RT3070, you should define the compile flag -DRTMP_USB_SUPPORT" -#endif - -#ifndef RTMP_MAC_USB -#error "For RT3070, you should define the compile flag -DRTMP_MAC_USB" -#endif - -#ifndef RTMP_RF_RW_SUPPORT -#error "For RT3070, you should define the compile flag -DRTMP_RF_RW_SUPPORT" -#endif - -#ifndef RT30xx -#error "For RT3070, you should define the compile flag -DRT30xx" -#endif - -#include "mac_usb.h" -#include "rt30xx.h" - -/* */ -/* Device ID & Vendor ID, these values should match EEPROM value */ -/* */ - -#endif /* RT3070 // */ - -#endif /*__RT3070_H__ // */ diff --git a/trunk/drivers/staging/rt2860/chip/rt3090.h b/trunk/drivers/staging/rt2860/chip/rt3090.h deleted file mode 100644 index 102b938e74bd..000000000000 --- a/trunk/drivers/staging/rt2860/chip/rt3090.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt3090.h - - Abstract: - - Revision History: - Who When What - --------- ---------- ---------------------------------------------- - */ - -#ifndef __RT3090_H__ -#define __RT3090_H__ - -#ifdef RT3090 - -#ifndef RTMP_PCI_SUPPORT -#error "For RT3090, you should define the compile flag -DRTMP_PCI_SUPPORT" -#endif - -#ifndef RTMP_MAC_PCI -#error "For RT3090, you should define the compile flag -DRTMP_MAC_PCI" -#endif - -#ifndef RTMP_RF_RW_SUPPORT -#error "For RT3090, you should define the compile flag -DRTMP_RF_RW_SUPPORT" -#endif - -#ifndef RT30xx -#error "For RT3090, you should define the compile flag -DRT30xx" -#endif - -#define PCIE_PS_SUPPORT - -#include "mac_pci.h" -#include "rt30xx.h" - -/* */ -/* Device ID & Vendor ID, these values should match EEPROM value */ -/* */ -#define NIC3090_PCIe_DEVICE_ID 0x3090 /* 1T/1R miniCard */ -#define NIC3091_PCIe_DEVICE_ID 0x3091 /* 1T/2R miniCard */ -#define NIC3092_PCIe_DEVICE_ID 0x3092 /* 2T/2R miniCard */ - -#endif /* RT3090 // */ - -#endif /*__RT3090_H__ // */ diff --git a/trunk/drivers/staging/rt2860/chip/rt30xx.h b/trunk/drivers/staging/rt2860/chip/rt30xx.h deleted file mode 100644 index 02e1d728fb41..000000000000 --- a/trunk/drivers/staging/rt2860/chip/rt30xx.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt30xx.h - - Abstract: - - Revision History: - Who When What - --------- ---------- ---------------------------------------------- - */ - -#ifndef __RT30XX_H__ -#define __RT30XX_H__ - -#ifdef RT30xx - -extern struct rt_reg_pair RT30xx_RFRegTable[]; -extern u8 NUM_RF_REG_PARMS; - -#endif /* RT30xx // */ - -#endif /*__RT30XX_H__ // */ diff --git a/trunk/drivers/staging/rt2860/chip/rtmp_mac.h b/trunk/drivers/staging/rt2860/chip/rtmp_mac.h deleted file mode 100644 index 3d1e4915b956..000000000000 --- a/trunk/drivers/staging/rt2860/chip/rtmp_mac.h +++ /dev/null @@ -1,1308 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_mac.h - - Abstract: - Ralink Wireless Chip MAC related definition & structures - - Revision History: - Who When What - Justin P. Mattock 11/07/2010 Fix a comments, and typos - -------- ---------- ---------------------------------------------- -*/ - -#ifndef __RTMP_MAC_H__ -#define __RTMP_MAC_H__ - -/* ================================================================================= */ -/* TX / RX ring descriptor format */ -/* ================================================================================= */ - -/* the first 24-byte in TXD is called TXINFO and will be DMAed to MAC block through TXFIFO. */ -/* MAC block uses this TXINFO to control the transmission behavior of this frame. */ -#define FIFO_MGMT 0 -#define FIFO_HCCA 1 -#define FIFO_EDCA 2 - -/* */ -/* TXD Wireless Information format for Tx ring and Mgmt Ring */ -/* */ -/*txop : for txop mode */ -/* 0:txop for the MPDU frame will be handles by ASIC by register */ -/* 1/2/3:the MPDU frame is send after PIFS/backoff/SIFS */ -struct PACKED rt_txwi { - /* Word 0 */ - /* ex: 00 03 00 40 means txop = 3, PHYMODE = 1 */ - u32 FRAG:1; /* 1 to inform TKIP engine this is a fragment. */ - u32 MIMOps:1; /* the remote peer is in dynamic MIMO-PS mode */ - u32 CFACK:1; - u32 TS:1; - - u32 AMPDU:1; - u32 MpduDensity:3; - u32 txop:2; /*FOR "THIS" frame. 0:HT TXOP rule , 1:PIFS TX ,2:Backoff, 3:sifs only when previous frame exchange is successful. */ - u32 rsv:6; - - u32 MCS:7; - u32 BW:1; /*channel bandwidth 20MHz or 40 MHz */ - u32 ShortGI:1; - u32 STBC:2; /* 1: STBC support MCS =0-7, 2,3 : RESERVE */ - u32 Ifs:1; /* */ -/* u32 rsv2:2; //channel bandwidth 20MHz or 40 MHz */ - u32 rsv2:1; - u32 TxBF:1; /* 3*3 */ - u32 PHYMODE:2; - /* Word1 */ - /* ex: 1c ff 38 00 means ACK=0, BAWinSize=7, MPDUtotalByteCount = 0x38 */ - u32 ACK:1; - u32 NSEQ:1; - u32 BAWinSize:6; - u32 WirelessCliID:8; - u32 MPDUtotalByteCount:12; - u32 PacketId:4; - /*Word2 */ - u32 IV; - /*Word3 */ - u32 EIV; -}; - -/* */ -/* RXWI wireless information format, in PBF. invisible in driver. */ -/* */ -struct PACKED rt_rxwi { - /* Word 0 */ - u32 WirelessCliID:8; - u32 KeyIndex:2; - u32 BSSID:3; - u32 UDF:3; - u32 MPDUtotalByteCount:12; - u32 TID:4; - /* Word 1 */ - u32 FRAG:4; - u32 SEQUENCE:12; - u32 MCS:7; - u32 BW:1; - u32 ShortGI:1; - u32 STBC:2; - u32 rsv:3; - u32 PHYMODE:2; /* 1: this RX frame is unicast to me */ - /*Word2 */ - u32 RSSI0:8; - u32 RSSI1:8; - u32 RSSI2:8; - u32 rsv1:8; - /*Word3 */ - u32 SNR0:8; - u32 SNR1:8; - u32 FOFFSET:8; /* RT35xx */ - u32 rsv2:8; - /*u32 rsv2:16; */ -}; - -/* ================================================================================= */ -/* Register format */ -/* ================================================================================= */ - -/* */ -/* SCH/DMA registers - base address 0x0200 */ -/* */ -/* INT_SOURCE_CSR: Interrupt source register. Write one to clear corresponding bit */ -/* */ -#define DMA_CSR0 0x200 -#define INT_SOURCE_CSR 0x200 -typedef union _INT_SOURCE_CSR_STRUC { - struct { - u32 RxDelayINT:1; - u32 TxDelayINT:1; - u32 RxDone:1; - u32 Ac0DmaDone:1; /*4 */ - u32 Ac1DmaDone:1; - u32 Ac2DmaDone:1; - u32 Ac3DmaDone:1; - u32 HccaDmaDone:1; /* bit7 */ - u32 MgmtDmaDone:1; - u32 MCUCommandINT:1; /*bit 9 */ - u32 RxTxCoherent:1; - u32 TBTTInt:1; - u32 PreTBTT:1; - u32 TXFifoStatusInt:1; /*FIFO Statistics is full, sw should read 0x171c */ - u32 AutoWakeup:1; /*bit14 */ - u32 GPTimer:1; - u32 RxCoherent:1; /*bit16 */ - u32 TxCoherent:1; - u32: 14; - } field; - u32 word; -} INT_SOURCE_CSR_STRUC, *PINT_SOURCE_CSR_STRUC; - -/* */ -/* INT_MASK_CSR: Interrupt MASK register. 1: the interrupt is mask OFF */ -/* */ -#define INT_MASK_CSR 0x204 -typedef union _INT_MASK_CSR_STRUC { - struct { - u32 RXDelay_INT_MSK:1; - u32 TxDelay:1; - u32 RxDone:1; - u32 Ac0DmaDone:1; - u32 Ac1DmaDone:1; - u32 Ac2DmaDone:1; - u32 Ac3DmaDone:1; - u32 HccaDmaDone:1; - u32 MgmtDmaDone:1; - u32 MCUCommandINT:1; - u32: 20; - u32 RxCoherent:1; - u32 TxCoherent:1; - } field; - u32 word; -} INT_MASK_CSR_STRUC, *PINT_MASK_CSR_STRUC; - -#define WPDMA_GLO_CFG 0x208 -typedef union _WPDMA_GLO_CFG_STRUC { - struct { - u32 EnableTxDMA:1; - u32 TxDMABusy:1; - u32 EnableRxDMA:1; - u32 RxDMABusy:1; - u32 WPDMABurstSIZE:2; - u32 EnTXWriteBackDDONE:1; - u32 BigEndian:1; - u32 RXHdrScater:8; - u32 HDR_SEG_LEN:16; - } field; - u32 word; -} WPDMA_GLO_CFG_STRUC, *PWPDMA_GLO_CFG_STRUC; - -#define WPDMA_RST_IDX 0x20c -typedef union _WPDMA_RST_IDX_STRUC { - struct { - u32 RST_DTX_IDX0:1; - u32 RST_DTX_IDX1:1; - u32 RST_DTX_IDX2:1; - u32 RST_DTX_IDX3:1; - u32 RST_DTX_IDX4:1; - u32 RST_DTX_IDX5:1; - u32 rsv:10; - u32 RST_DRX_IDX0:1; - u32: 15; - } field; - u32 word; -} WPDMA_RST_IDX_STRUC, *PWPDMA_RST_IDX_STRUC; -#define DELAY_INT_CFG 0x0210 -typedef union _DELAY_INT_CFG_STRUC { - struct { - u32 RXMAX_PTIME:8; - u32 RXMAX_PINT:7; - u32 RXDLY_INT_EN:1; - u32 TXMAX_PTIME:8; - u32 TXMAX_PINT:7; - u32 TXDLY_INT_EN:1; - } field; - u32 word; -} DELAY_INT_CFG_STRUC, *PDELAY_INT_CFG_STRUC; -#define WMM_AIFSN_CFG 0x0214 -typedef union _AIFSN_CSR_STRUC { - struct { - u32 Aifsn0:4; /* for AC_BE */ - u32 Aifsn1:4; /* for AC_BK */ - u32 Aifsn2:4; /* for AC_VI */ - u32 Aifsn3:4; /* for AC_VO */ - u32 Rsv:16; - } field; - u32 word; -} AIFSN_CSR_STRUC, *PAIFSN_CSR_STRUC; -/* */ -/* CWMIN_CSR: CWmin for each EDCA AC */ -/* */ -#define WMM_CWMIN_CFG 0x0218 -typedef union _CWMIN_CSR_STRUC { - struct { - u32 Cwmin0:4; /* for AC_BE */ - u32 Cwmin1:4; /* for AC_BK */ - u32 Cwmin2:4; /* for AC_VI */ - u32 Cwmin3:4; /* for AC_VO */ - u32 Rsv:16; - } field; - u32 word; -} CWMIN_CSR_STRUC, *PCWMIN_CSR_STRUC; - -/* */ -/* CWMAX_CSR: CWmin for each EDCA AC */ -/* */ -#define WMM_CWMAX_CFG 0x021c -typedef union _CWMAX_CSR_STRUC { - struct { - u32 Cwmax0:4; /* for AC_BE */ - u32 Cwmax1:4; /* for AC_BK */ - u32 Cwmax2:4; /* for AC_VI */ - u32 Cwmax3:4; /* for AC_VO */ - u32 Rsv:16; - } field; - u32 word; -} CWMAX_CSR_STRUC, *PCWMAX_CSR_STRUC; - -/* */ -/* AC_TXOP_CSR0: AC_BK/AC_BE TXOP register */ -/* */ -#define WMM_TXOP0_CFG 0x0220 -typedef union _AC_TXOP_CSR0_STRUC { - struct { - u16 Ac0Txop; /* for AC_BK, in unit of 32us */ - u16 Ac1Txop; /* for AC_BE, in unit of 32us */ - } field; - u32 word; -} AC_TXOP_CSR0_STRUC, *PAC_TXOP_CSR0_STRUC; - -/* */ -/* AC_TXOP_CSR1: AC_VO/AC_VI TXOP register */ -/* */ -#define WMM_TXOP1_CFG 0x0224 -typedef union _AC_TXOP_CSR1_STRUC { - struct { - u16 Ac2Txop; /* for AC_VI, in unit of 32us */ - u16 Ac3Txop; /* for AC_VO, in unit of 32us */ - } field; - u32 word; -} AC_TXOP_CSR1_STRUC, *PAC_TXOP_CSR1_STRUC; - -#define RINGREG_DIFF 0x10 -#define GPIO_CTRL_CFG 0x0228 /*MAC_CSR13 */ -#define MCU_CMD_CFG 0x022c -#define TX_BASE_PTR0 0x0230 /*AC_BK base address */ -#define TX_MAX_CNT0 0x0234 -#define TX_CTX_IDX0 0x0238 -#define TX_DTX_IDX0 0x023c -#define TX_BASE_PTR1 0x0240 /*AC_BE base address */ -#define TX_MAX_CNT1 0x0244 -#define TX_CTX_IDX1 0x0248 -#define TX_DTX_IDX1 0x024c -#define TX_BASE_PTR2 0x0250 /*AC_VI base address */ -#define TX_MAX_CNT2 0x0254 -#define TX_CTX_IDX2 0x0258 -#define TX_DTX_IDX2 0x025c -#define TX_BASE_PTR3 0x0260 /*AC_VO base address */ -#define TX_MAX_CNT3 0x0264 -#define TX_CTX_IDX3 0x0268 -#define TX_DTX_IDX3 0x026c -#define TX_BASE_PTR4 0x0270 /*HCCA base address */ -#define TX_MAX_CNT4 0x0274 -#define TX_CTX_IDX4 0x0278 -#define TX_DTX_IDX4 0x027c -#define TX_BASE_PTR5 0x0280 /*MGMT base address */ -#define TX_MAX_CNT5 0x0284 -#define TX_CTX_IDX5 0x0288 -#define TX_DTX_IDX5 0x028c -#define TX_MGMTMAX_CNT TX_MAX_CNT5 -#define TX_MGMTCTX_IDX TX_CTX_IDX5 -#define TX_MGMTDTX_IDX TX_DTX_IDX5 -#define RX_BASE_PTR 0x0290 /*RX base address */ -#define RX_MAX_CNT 0x0294 -#define RX_CRX_IDX 0x0298 -#define RX_DRX_IDX 0x029c - -#define USB_DMA_CFG 0x02a0 -typedef union _USB_DMA_CFG_STRUC { - struct { - u32 RxBulkAggTOut:8; /*Rx Bulk Aggregation TimeOut in unit of 33ns */ - u32 RxBulkAggLmt:8; /*Rx Bulk Aggregation Limit in unit of 256 bytes */ - u32 phyclear:1; /*phy watch dog enable. write 1 */ - u32 rsv:2; - u32 TxClear:1; /*Clear USB DMA TX path */ - u32 TxopHalt:1; /*Halt TXOP count down when TX buffer is full. */ - u32 RxBulkAggEn:1; /*Enable Rx Bulk Aggregation */ - u32 RxBulkEn:1; /*Enable USB DMA Rx */ - u32 TxBulkEn:1; /*Enable USB DMA Tx */ - u32 EpoutValid:6; /*OUT endpoint data valid */ - u32 RxBusy:1; /*USB DMA RX FSM busy */ - u32 TxBusy:1; /*USB DMA TX FSM busy */ - } field; - u32 word; -} USB_DMA_CFG_STRUC, *PUSB_DMA_CFG_STRUC; - -/* */ -/* 3 PBF registers */ -/* */ -/* */ -/* Most are for debug. Driver doesn't touch PBF register. */ -#define PBF_SYS_CTRL 0x0400 -#define PBF_CFG 0x0408 -#define PBF_MAX_PCNT 0x040C -#define PBF_CTRL 0x0410 -#define PBF_INT_STA 0x0414 -#define PBF_INT_ENA 0x0418 -#define TXRXQ_PCNT 0x0438 -#define PBF_DBG 0x043c -#define PBF_CAP_CTRL 0x0440 - -#ifdef RT30xx -#ifdef RTMP_EFUSE_SUPPORT -/* eFuse registers */ -#define EFUSE_CTRL 0x0580 -#define EFUSE_DATA0 0x0590 -#define EFUSE_DATA1 0x0594 -#define EFUSE_DATA2 0x0598 -#define EFUSE_DATA3 0x059c -#endif /* RTMP_EFUSE_SUPPORT // */ -#endif /* RT30xx // */ - -#define OSC_CTRL 0x5a4 -#define PCIE_PHY_TX_ATTENUATION_CTRL 0x05C8 -#define LDO_CFG0 0x05d4 -#define GPIO_SWITCH 0x05dc - -/* */ -/* 4 MAC registers */ -/* */ -/* */ -/* 4.1 MAC SYSTEM configuration registers (offset:0x1000) */ -/* */ -#define MAC_CSR0 0x1000 -typedef union _ASIC_VER_ID_STRUC { - struct { - u16 ASICRev; /* reversion : 0 */ - u16 ASICVer; /* version : 2860 */ - } field; - u32 word; -} ASIC_VER_ID_STRUC, *PASIC_VER_ID_STRUC; -#define MAC_SYS_CTRL 0x1004 /*MAC_CSR1 */ -#define MAC_ADDR_DW0 0x1008 /* MAC ADDR DW0 */ -#define MAC_ADDR_DW1 0x100c /* MAC ADDR DW1 */ -/* */ -/* MAC_CSR2: STA MAC register 0 */ -/* */ -typedef union _MAC_DW0_STRUC { - struct { - u8 Byte0; /* MAC address byte 0 */ - u8 Byte1; /* MAC address byte 1 */ - u8 Byte2; /* MAC address byte 2 */ - u8 Byte3; /* MAC address byte 3 */ - } field; - u32 word; -} MAC_DW0_STRUC, *PMAC_DW0_STRUC; - -/* */ -/* MAC_CSR3: STA MAC register 1 */ -/* */ -typedef union _MAC_DW1_STRUC { - struct { - u8 Byte4; /* MAC address byte 4 */ - u8 Byte5; /* MAC address byte 5 */ - u8 U2MeMask; - u8 Rsvd1; - } field; - u32 word; -} MAC_DW1_STRUC, *PMAC_DW1_STRUC; - -#define MAC_BSSID_DW0 0x1010 /* MAC BSSID DW0 */ -#define MAC_BSSID_DW1 0x1014 /* MAC BSSID DW1 */ - -/* */ -/* MAC_CSR5: BSSID register 1 */ -/* */ -typedef union _MAC_CSR5_STRUC { - struct { - u8 Byte4; /* BSSID byte 4 */ - u8 Byte5; /* BSSID byte 5 */ - u16 BssIdMask:2; /* 0: one BSSID, 10: 4 BSSID, 01: 2 BSSID , 11: 8BSSID */ - u16 MBssBcnNum:3; - u16 Rsvd:11; - } field; - u32 word; -} MAC_CSR5_STRUC, *PMAC_CSR5_STRUC; - -#define MAX_LEN_CFG 0x1018 /* rt2860b max 16k bytes. bit12:13 Maximum PSDU length (power factor) 0:2^13, 1:2^14, 2:2^15, 3:2^16 */ -#define BBP_CSR_CFG 0x101c /* */ -/* */ -/* BBP_CSR_CFG: BBP serial control register */ -/* */ -typedef union _BBP_CSR_CFG_STRUC { - struct { - u32 Value:8; /* Register value to program into BBP */ - u32 RegNum:8; /* Selected BBP register */ - u32 fRead:1; /* 0: Write BBP, 1: Read BBP */ - u32 Busy:1; /* 1: ASIC is busy execute BBP programming. */ - u32 BBP_PAR_DUR:1; /* 0: 4 MAC clock cycles 1: 8 MAC clock cycles */ - u32 BBP_RW_MODE:1; /* 0: use serial mode 1:parallel */ - u32: 12; - } field; - u32 word; -} BBP_CSR_CFG_STRUC, *PBBP_CSR_CFG_STRUC; -#define RF_CSR_CFG0 0x1020 -/* */ -/* RF_CSR_CFG: RF control register */ -/* */ -typedef union _RF_CSR_CFG0_STRUC { - struct { - u32 RegIdAndContent:24; /* Register value to program into BBP */ - u32 bitwidth:5; /* Selected BBP register */ - u32 StandbyMode:1; /* 0: high when stand by 1: low when standby */ - u32 Sel:1; /* 0:RF_LE0 activate 1:RF_LE1 activate */ - u32 Busy:1; /* 0: idle 1: 8busy */ - } field; - u32 word; -} RF_CSR_CFG0_STRUC, *PRF_CSR_CFG0_STRUC; -#define RF_CSR_CFG1 0x1024 -typedef union _RF_CSR_CFG1_STRUC { - struct { - u32 RegIdAndContent:24; /* Register value to program into BBP */ - u32 RFGap:5; /* Gap between BB_CONTROL_RF and RF_LE. 0: 3 system clock cycle (37.5usec) 1: 5 system clock cycle (62.5usec) */ - u32 rsv:7; /* 0: idle 1: 8busy */ - } field; - u32 word; -} RF_CSR_CFG1_STRUC, *PRF_CSR_CFG1_STRUC; -#define RF_CSR_CFG2 0x1028 /* */ -typedef union _RF_CSR_CFG2_STRUC { - struct { - u32 RegIdAndContent:24; /* Register value to program into BBP */ - u32 rsv:8; /* 0: idle 1: 8busy */ - } field; - u32 word; -} RF_CSR_CFG2_STRUC, *PRF_CSR_CFG2_STRUC; -#define LED_CFG 0x102c /* MAC_CSR14 */ -typedef union _LED_CFG_STRUC { - struct { - u32 OnPeriod:8; /* blinking on period unit 1ms */ - u32 OffPeriod:8; /* blinking off period unit 1ms */ - u32 SlowBlinkPeriod:6; /* slow blinking period. unit:1ms */ - u32 rsv:2; - u32 RLedMode:2; /* red Led Mode 0: off1: blinking upon TX2: periodic slow blinking3: always on */ - u32 GLedMode:2; /* green Led Mode */ - u32 YLedMode:2; /* yellow Led Mode */ - u32 LedPolar:1; /* Led Polarity. 0: active low1: active high */ - u32: 1; - } field; - u32 word; -} LED_CFG_STRUC, *PLED_CFG_STRUC; -/* */ -/* 4.2 MAC TIMING configuration registers (offset:0x1100) */ -/* */ -#define XIFS_TIME_CFG 0x1100 /* MAC_CSR8 MAC_CSR9 */ -typedef union _IFS_SLOT_CFG_STRUC { - struct { - u32 CckmSifsTime:8; /* unit 1us. Applied after CCK RX/TX */ - u32 OfdmSifsTime:8; /* unit 1us. Applied after OFDM RX/TX */ - u32 OfdmXifsTime:4; /*OFDM SIFS. unit 1us. Applied after OFDM RX when MAC doesn't reference BBP signal BBRXEND */ - u32 EIFS:9; /* unit 1us */ - u32 BBRxendEnable:1; /* reference RXEND signal to begin XIFS defer */ - u32 rsv:2; - } field; - u32 word; -} IFS_SLOT_CFG_STRUC, *PIFS_SLOT_CFG_STRUC; - -#define BKOFF_SLOT_CFG 0x1104 /* mac_csr9 last 8 bits */ -#define NAV_TIME_CFG 0x1108 /* NAV (MAC_CSR15) */ -#define CH_TIME_CFG 0x110C /* Count as channel busy */ -#define PBF_LIFE_TIMER 0x1110 /*TX/RX MPDU timestamp timer (free run)Unit: 1us */ -#define BCN_TIME_CFG 0x1114 /* TXRX_CSR9 */ - -#define BCN_OFFSET0 0x042C -#define BCN_OFFSET1 0x0430 - -/* */ -/* BCN_TIME_CFG : Synchronization control register */ -/* */ -typedef union _BCN_TIME_CFG_STRUC { - struct { - u32 BeaconInterval:16; /* in unit of 1/16 TU */ - u32 bTsfTicking:1; /* Enable TSF auto counting */ - u32 TsfSyncMode:2; /* Enable TSF sync, 00: disable, 01: infra mode, 10: ad-hoc mode */ - u32 bTBTTEnable:1; - u32 bBeaconGen:1; /* Enable beacon generator */ - u32: 3; - u32 TxTimestampCompensate:8; - } field; - u32 word; -} BCN_TIME_CFG_STRUC, *PBCN_TIME_CFG_STRUC; -#define TBTT_SYNC_CFG 0x1118 /* txrx_csr10 */ -#define TSF_TIMER_DW0 0x111C /* Local TSF timer lsb 32 bits. Read-only */ -#define TSF_TIMER_DW1 0x1120 /* msb 32 bits. Read-only. */ -#define TBTT_TIMER 0x1124 /* TImer remains till next TBTT. Read-only. TXRX_CSR14 */ -#define INT_TIMER_CFG 0x1128 /* */ -#define INT_TIMER_EN 0x112c /* GP-timer and pre-tbtt Int enable */ -#define CH_IDLE_STA 0x1130 /* channel idle time */ -#define CH_BUSY_STA 0x1134 /* channle busy time */ -/* */ -/* 4.2 MAC POWER configuration registers (offset:0x1200) */ -/* */ -#define MAC_STATUS_CFG 0x1200 /* old MAC_CSR12 */ -#define PWR_PIN_CFG 0x1204 /* old MAC_CSR12 */ -#define AUTO_WAKEUP_CFG 0x1208 /* old MAC_CSR10 */ -/* */ -/* AUTO_WAKEUP_CFG: Manual power control / status register */ -/* */ -typedef union _AUTO_WAKEUP_STRUC { - struct { - u32 AutoLeadTime:8; - u32 NumofSleepingTbtt:7; /* ForceWake has high privilege than PutToSleep when both set */ - u32 EnableAutoWakeup:1; /* 0:sleep, 1:awake */ - u32: 16; - } field; - u32 word; -} AUTO_WAKEUP_STRUC, *PAUTO_WAKEUP_STRUC; -/* */ -/* 4.3 MAC TX configuration registers (offset:0x1300) */ -/* */ - -#define EDCA_AC0_CFG 0x1300 /*AC_TXOP_CSR0 0x3474 */ -#define EDCA_AC1_CFG 0x1304 -#define EDCA_AC2_CFG 0x1308 -#define EDCA_AC3_CFG 0x130c -typedef union _EDCA_AC_CFG_STRUC { - struct { - u32 AcTxop:8; /* in unit of 32us */ - u32 Aifsn:4; /* # of slot time */ - u32 Cwmin:4; /* */ - u32 Cwmax:4; /*unit power of 2 */ - u32: 12; /* */ - } field; - u32 word; -} EDCA_AC_CFG_STRUC, *PEDCA_AC_CFG_STRUC; - -#define EDCA_TID_AC_MAP 0x1310 -#define TX_PWR_CFG_0 0x1314 -#define TX_PWR_CFG_1 0x1318 -#define TX_PWR_CFG_2 0x131C -#define TX_PWR_CFG_3 0x1320 -#define TX_PWR_CFG_4 0x1324 -#define TX_PIN_CFG 0x1328 -#define TX_BAND_CFG 0x132c /* 0x1 use upper 20MHz. 0 juse lower 20MHz */ -#define TX_SW_CFG0 0x1330 -#define TX_SW_CFG1 0x1334 -#define TX_SW_CFG2 0x1338 -#define TXOP_THRES_CFG 0x133c -#define TXOP_CTRL_CFG 0x1340 -#define TX_RTS_CFG 0x1344 - -typedef union _TX_RTS_CFG_STRUC { - struct { - u32 AutoRtsRetryLimit:8; - u32 RtsThres:16; /* unit:byte */ - u32 RtsFbkEn:1; /* enable rts rate fallback */ - u32 rsv:7; /* 1: HT non-STBC control frame enable */ - } field; - u32 word; -} TX_RTS_CFG_STRUC, *PTX_RTS_CFG_STRUC; -#define TX_TIMEOUT_CFG 0x1348 -typedef union _TX_TIMEOUT_CFG_STRUC { - struct { - u32 rsv:4; - u32 MpduLifeTime:4; /* expiration time = 2^(9+MPDU LIFE TIME) us */ - u32 RxAckTimeout:8; /* unit:slot. Used for TX precedure */ - u32 TxopTimeout:8; /*TXOP timeout value for TXOP truncation. It is recommended that (SLOT_TIME) > (TX_OP_TIMEOUT) > (RX_ACK_TIMEOUT) */ - u32 rsv2:8; /* 1: HT non-STBC control frame enable */ - } field; - u32 word; -} TX_TIMEOUT_CFG_STRUC, *PTX_TIMEOUT_CFG_STRUC; -#define TX_RTY_CFG 0x134c -typedef union PACKED _TX_RTY_CFG_STRUC { - struct { - u32 ShortRtyLimit:8; /* short retry limit */ - u32 LongRtyLimit:8; /* long retry limit */ - u32 LongRtyThre:12; /* Long retry threshold */ - u32 NonAggRtyMode:1; /* Non-Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer */ - u32 AggRtyMode:1; /* Aggregate MPDU retry mode. 0:expired by retry limit, 1: expired by mpdu life timer */ - u32 TxautoFBEnable:1; /* Tx retry PHY rate auto fallback enable */ - u32 rsv:1; /* 1: HT non-STBC control frame enable */ - } field; - u32 word; -} TX_RTY_CFG_STRUC, *PTX_RTY_CFG_STRUC; -#define TX_LINK_CFG 0x1350 -typedef union PACKED _TX_LINK_CFG_STRUC { - struct PACKED { - u32 RemoteMFBLifeTime:8; /*remote MFB life time. unit : 32us */ - u32 MFBEnable:1; /* TX apply remote MFB 1:enable */ - u32 RemoteUMFSEnable:1; /* remote unsolicit MFB enable. 0: not apply remote remote unsolicit (MFS=7) */ - u32 TxMRQEn:1; /* MCS request TX enable */ - u32 TxRDGEn:1; /* RDG TX enable */ - u32 TxCFAckEn:1; /* Piggyback CF-ACK enable */ - u32 rsv:3; /* */ - u32 RemotMFB:8; /* remote MCS feedback */ - u32 RemotMFS:8; /*remote MCS feedback sequence number */ - } field; - u32 word; -} TX_LINK_CFG_STRUC, *PTX_LINK_CFG_STRUC; -#define HT_FBK_CFG0 0x1354 -typedef union PACKED _HT_FBK_CFG0_STRUC { - struct { - u32 HTMCS0FBK:4; - u32 HTMCS1FBK:4; - u32 HTMCS2FBK:4; - u32 HTMCS3FBK:4; - u32 HTMCS4FBK:4; - u32 HTMCS5FBK:4; - u32 HTMCS6FBK:4; - u32 HTMCS7FBK:4; - } field; - u32 word; -} HT_FBK_CFG0_STRUC, *PHT_FBK_CFG0_STRUC; -#define HT_FBK_CFG1 0x1358 -typedef union _HT_FBK_CFG1_STRUC { - struct { - u32 HTMCS8FBK:4; - u32 HTMCS9FBK:4; - u32 HTMCS10FBK:4; - u32 HTMCS11FBK:4; - u32 HTMCS12FBK:4; - u32 HTMCS13FBK:4; - u32 HTMCS14FBK:4; - u32 HTMCS15FBK:4; - } field; - u32 word; -} HT_FBK_CFG1_STRUC, *PHT_FBK_CFG1_STRUC; -#define LG_FBK_CFG0 0x135c -typedef union _LG_FBK_CFG0_STRUC { - struct { - u32 OFDMMCS0FBK:4; /*initial value is 0 */ - u32 OFDMMCS1FBK:4; /*initial value is 0 */ - u32 OFDMMCS2FBK:4; /*initial value is 1 */ - u32 OFDMMCS3FBK:4; /*initial value is 2 */ - u32 OFDMMCS4FBK:4; /*initial value is 3 */ - u32 OFDMMCS5FBK:4; /*initial value is 4 */ - u32 OFDMMCS6FBK:4; /*initial value is 5 */ - u32 OFDMMCS7FBK:4; /*initial value is 6 */ - } field; - u32 word; -} LG_FBK_CFG0_STRUC, *PLG_FBK_CFG0_STRUC; -#define LG_FBK_CFG1 0x1360 -typedef union _LG_FBK_CFG1_STRUC { - struct { - u32 CCKMCS0FBK:4; /*initial value is 0 */ - u32 CCKMCS1FBK:4; /*initial value is 0 */ - u32 CCKMCS2FBK:4; /*initial value is 1 */ - u32 CCKMCS3FBK:4; /*initial value is 2 */ - u32 rsv:16; - } field; - u32 word; -} LG_FBK_CFG1_STRUC, *PLG_FBK_CFG1_STRUC; - -/*======================================================= */ -/*================ Protection Paramater================================ */ -/*======================================================= */ -#define CCK_PROT_CFG 0x1364 /*CCK Protection */ -#define ASIC_SHORTNAV 1 -#define ASIC_longNAV 2 -#define ASIC_RTS 1 -#define ASIC_CTS 2 -typedef union _PROT_CFG_STRUC { - struct { - u32 ProtectRate:16; /*Protection control frame rate for CCK TX(RTS/CTS/CFEnd). */ - u32 ProtectCtrl:2; /*Protection control frame type for CCK TX. 1:RTS/CTS, 2:CTS-to-self, 0:None, 3:rsv */ - u32 ProtectNav:2; /*TXOP protection type for CCK TX. 0:None, 1:ShortNAVprotect, 2:LongNAVProtect, 3:rsv */ - u32 TxopAllowCck:1; /*CCK TXOP allowance.0:disallow. */ - u32 TxopAllowOfdm:1; /*CCK TXOP allowance.0:disallow. */ - u32 TxopAllowMM20:1; /*CCK TXOP allowance. 0:disallow. */ - u32 TxopAllowMM40:1; /*CCK TXOP allowance.0:disallow. */ - u32 TxopAllowGF20:1; /*CCK TXOP allowance.0:disallow. */ - u32 TxopAllowGF40:1; /*CCK TXOP allowance.0:disallow. */ - u32 RTSThEn:1; /*RTS threshold enable on CCK TX */ - u32 rsv:5; - } field; - u32 word; -} PROT_CFG_STRUC, *PPROT_CFG_STRUC; - -#define OFDM_PROT_CFG 0x1368 /*OFDM Protection */ -#define MM20_PROT_CFG 0x136C /*MM20 Protection */ -#define MM40_PROT_CFG 0x1370 /*MM40 Protection */ -#define GF20_PROT_CFG 0x1374 /*GF20 Protection */ -#define GF40_PROT_CFG 0x1378 /*GR40 Protection */ -#define EXP_CTS_TIME 0x137C /* */ -#define EXP_ACK_TIME 0x1380 /* */ - -/* */ -/* 4.4 MAC RX configuration registers (offset:0x1400) */ -/* */ -#define RX_FILTR_CFG 0x1400 /*TXRX_CSR0 */ -#define AUTO_RSP_CFG 0x1404 /*TXRX_CSR4 */ -/* */ -/* TXRX_CSR4: Auto-Responder/ */ -/* */ -typedef union _AUTO_RSP_CFG_STRUC { - struct { - u32 AutoResponderEnable:1; - u32 BACAckPolicyEnable:1; /* 0:long, 1:short preamble */ - u32 CTS40MMode:1; /* Response CTS 40MHz duplicate mode */ - u32 CTS40MRef:1; /* Response CTS 40MHz duplicate mode */ - u32 AutoResponderPreamble:1; /* 0:long, 1:short preamble */ - u32 rsv:1; /* Power bit value in conrtrol frame */ - u32 DualCTSEn:1; /* Power bit value in conrtrol frame */ - u32 AckCtsPsmBit:1; /* Power bit value in conrtrol frame */ - u32: 24; - } field; - u32 word; -} AUTO_RSP_CFG_STRUC, *PAUTO_RSP_CFG_STRUC; - -#define LEGACY_BASIC_RATE 0x1408 /* TXRX_CSR5 0x3054 */ -#define HT_BASIC_RATE 0x140c -#define HT_CTRL_CFG 0x1410 -#define SIFS_COST_CFG 0x1414 -#define RX_PARSER_CFG 0x1418 /*Set NAV for all received frames */ - -/* */ -/* 4.5 MAC Security configuration (offset:0x1500) */ -/* */ -#define TX_SEC_CNT0 0x1500 /* */ -#define RX_SEC_CNT0 0x1504 /* */ -#define CCMP_FC_MUTE 0x1508 /* */ -/* */ -/* 4.6 HCCA/PSMP (offset:0x1600) */ -/* */ -#define TXOP_HLDR_ADDR0 0x1600 -#define TXOP_HLDR_ADDR1 0x1604 -#define TXOP_HLDR_ET 0x1608 -#define QOS_CFPOLL_RA_DW0 0x160c -#define QOS_CFPOLL_A1_DW1 0x1610 -#define QOS_CFPOLL_QC 0x1614 -/* */ -/* 4.7 MAC Statistis registers (offset:0x1700) */ -/* */ -#define RX_STA_CNT0 0x1700 /* */ -#define RX_STA_CNT1 0x1704 /* */ -#define RX_STA_CNT2 0x1708 /* */ - -/* */ -/* RX_STA_CNT0_STRUC: RX PLCP error count & RX CRC error count */ -/* */ -typedef union _RX_STA_CNT0_STRUC { - struct { - u16 CrcErr; - u16 PhyErr; - } field; - u32 word; -} RX_STA_CNT0_STRUC, *PRX_STA_CNT0_STRUC; - -/* */ -/* RX_STA_CNT1_STRUC: RX False CCA count & RX long frame count */ -/* */ -typedef union _RX_STA_CNT1_STRUC { - struct { - u16 FalseCca; - u16 PlcpErr; - } field; - u32 word; -} RX_STA_CNT1_STRUC, *PRX_STA_CNT1_STRUC; - -/* */ -/* RX_STA_CNT2_STRUC: */ -/* */ -typedef union _RX_STA_CNT2_STRUC { - struct { - u16 RxDupliCount; - u16 RxFifoOverflowCount; - } field; - u32 word; -} RX_STA_CNT2_STRUC, *PRX_STA_CNT2_STRUC; -#define TX_STA_CNT0 0x170C /* */ -/* */ -/* STA_CSR3: TX Beacon count */ -/* */ -typedef union _TX_STA_CNT0_STRUC { - struct { - u16 TxFailCount; - u16 TxBeaconCount; - } field; - u32 word; -} TX_STA_CNT0_STRUC, *PTX_STA_CNT0_STRUC; -#define TX_STA_CNT1 0x1710 /* */ -/* */ -/* TX_STA_CNT1: TX tx count */ -/* */ -typedef union _TX_STA_CNT1_STRUC { - struct { - u16 TxSuccess; - u16 TxRetransmit; - } field; - u32 word; -} TX_STA_CNT1_STRUC, *PTX_STA_CNT1_STRUC; -#define TX_STA_CNT2 0x1714 /* */ -/* */ -/* TX_STA_CNT2: TX tx count */ -/* */ -typedef union _TX_STA_CNT2_STRUC { - struct { - u16 TxZeroLenCount; - u16 TxUnderFlowCount; - } field; - u32 word; -} TX_STA_CNT2_STRUC, *PTX_STA_CNT2_STRUC; -#define TX_STA_FIFO 0x1718 /* */ -/* */ -/* TX_STA_FIFO_STRUC: TX Result for specific PID status fifo register */ -/* */ -typedef union PACKED _TX_STA_FIFO_STRUC { - struct { - u32 bValid:1; /* 1:This register contains a valid TX result */ - u32 PidType:4; - u32 TxSuccess:1; /* Tx No retry success */ - u32 TxAggre:1; /* Tx Retry Success */ - u32 TxAckRequired:1; /* Tx fail */ - u32 wcid:8; /*wireless client index */ -/* u32 SuccessRate:16; //include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16. */ - u32 SuccessRate:13; /*include MCS, mode ,shortGI, BW settingSame format as TXWI Word 0 Bit 31-16. */ - u32 TxBF:1; - u32 Reserve:2; - } field; - u32 word; -} TX_STA_FIFO_STRUC, *PTX_STA_FIFO_STRUC; -/* Debug counter */ -#define TX_AGG_CNT 0x171c -typedef union _TX_AGG_CNT_STRUC { - struct { - u16 NonAggTxCount; - u16 AggTxCount; - } field; - u32 word; -} TX_AGG_CNT_STRUC, *PTX_AGG_CNT_STRUC; -/* Debug counter */ -#define TX_AGG_CNT0 0x1720 -typedef union _TX_AGG_CNT0_STRUC { - struct { - u16 AggSize1Count; - u16 AggSize2Count; - } field; - u32 word; -} TX_AGG_CNT0_STRUC, *PTX_AGG_CNT0_STRUC; -/* Debug counter */ -#define TX_AGG_CNT1 0x1724 -typedef union _TX_AGG_CNT1_STRUC { - struct { - u16 AggSize3Count; - u16 AggSize4Count; - } field; - u32 word; -} TX_AGG_CNT1_STRUC, *PTX_AGG_CNT1_STRUC; -#define TX_AGG_CNT2 0x1728 -typedef union _TX_AGG_CNT2_STRUC { - struct { - u16 AggSize5Count; - u16 AggSize6Count; - } field; - u32 word; -} TX_AGG_CNT2_STRUC, *PTX_AGG_CNT2_STRUC; -/* Debug counter */ -#define TX_AGG_CNT3 0x172c -typedef union _TX_AGG_CNT3_STRUC { - struct { - u16 AggSize7Count; - u16 AggSize8Count; - } field; - u32 word; -} TX_AGG_CNT3_STRUC, *PTX_AGG_CNT3_STRUC; -/* Debug counter */ -#define TX_AGG_CNT4 0x1730 -typedef union _TX_AGG_CNT4_STRUC { - struct { - u16 AggSize9Count; - u16 AggSize10Count; - } field; - u32 word; -} TX_AGG_CNT4_STRUC, *PTX_AGG_CNT4_STRUC; -#define TX_AGG_CNT5 0x1734 -typedef union _TX_AGG_CNT5_STRUC { - struct { - u16 AggSize11Count; - u16 AggSize12Count; - } field; - u32 word; -} TX_AGG_CNT5_STRUC, *PTX_AGG_CNT5_STRUC; -#define TX_AGG_CNT6 0x1738 -typedef union _TX_AGG_CNT6_STRUC { - struct { - u16 AggSize13Count; - u16 AggSize14Count; - } field; - u32 word; -} TX_AGG_CNT6_STRUC, *PTX_AGG_CNT6_STRUC; -#define TX_AGG_CNT7 0x173c -typedef union _TX_AGG_CNT7_STRUC { - struct { - u16 AggSize15Count; - u16 AggSize16Count; - } field; - u32 word; -} TX_AGG_CNT7_STRUC, *PTX_AGG_CNT7_STRUC; -#define MPDU_DENSITY_CNT 0x1740 -typedef union _MPDU_DEN_CNT_STRUC { - struct { - u16 TXZeroDelCount; /*TX zero length delimiter count */ - u16 RXZeroDelCount; /*RX zero length delimiter count */ - } field; - u32 word; -} MPDU_DEN_CNT_STRUC, *PMPDU_DEN_CNT_STRUC; -/* */ -/* TXRX control registers - base address 0x3000 */ -/* */ -/* rt2860b UNKNOWN reg use R/O Reg Addr 0x77d0 first.. */ -#define TXRX_CSR1 0x77d0 - -/* */ -/* Security key table memory, base address = 0x1000 */ -/* */ -#define MAC_WCID_BASE 0x1800 /*8-bytes(use only 6-bytes) * 256 entry = */ -#define HW_WCID_ENTRY_SIZE 8 -#define PAIRWISE_KEY_TABLE_BASE 0x4000 /* 32-byte * 256-entry = -byte */ -#define HW_KEY_ENTRY_SIZE 0x20 -#define PAIRWISE_IVEIV_TABLE_BASE 0x6000 /* 8-byte * 256-entry = -byte */ -#define MAC_IVEIV_TABLE_BASE 0x6000 /* 8-byte * 256-entry = -byte */ -#define HW_IVEIV_ENTRY_SIZE 8 -#define MAC_WCID_ATTRIBUTE_BASE 0x6800 /* 4-byte * 256-entry = -byte */ -#define HW_WCID_ATTRI_SIZE 4 -#define WCID_RESERVED 0x6bfc -#define SHARED_KEY_TABLE_BASE 0x6c00 /* 32-byte * 16-entry = 512-byte */ -#define SHARED_KEY_MODE_BASE 0x7000 /* 32-byte * 16-entry = 512-byte */ -#define HW_SHARED_KEY_MODE_SIZE 4 -#define SHAREDKEYTABLE 0 -#define PAIRWISEKEYTABLE 1 - -typedef union _SHAREDKEY_MODE_STRUC { - struct { - u32 Bss0Key0CipherAlg:3; - u32: 1; - u32 Bss0Key1CipherAlg:3; - u32: 1; - u32 Bss0Key2CipherAlg:3; - u32: 1; - u32 Bss0Key3CipherAlg:3; - u32: 1; - u32 Bss1Key0CipherAlg:3; - u32: 1; - u32 Bss1Key1CipherAlg:3; - u32: 1; - u32 Bss1Key2CipherAlg:3; - u32: 1; - u32 Bss1Key3CipherAlg:3; - u32: 1; - } field; - u32 word; -} SHAREDKEY_MODE_STRUC, *PSHAREDKEY_MODE_STRUC; - -/* 8-byte per entry, 64-entry for pairwise key table */ -struct rt_hw_wcid_entry { - u8 Address[6]; - u8 Rsv[2]; -}; - -/* ================================================================================= */ -/* WCID format */ -/* ================================================================================= */ -/*7.1 WCID ENTRY format : 8bytes */ -struct rt_wcid_entry { - u8 RXBABitmap7; /* bit0 for TID8, bit7 for TID 15 */ - u8 RXBABitmap0; /* bit0 for TID0, bit7 for TID 7 */ - u8 MAC[6]; /* 0 for shared key table. 1 for pairwise key table */ -}; - -/*8.1.1 SECURITY KEY format : 8DW */ -/* 32-byte per entry, total 16-entry for shared key table, 64-entry for pairwise key table */ -struct rt_hw_key_entry { - u8 Key[16]; - u8 TxMic[8]; - u8 RxMic[8]; -}; - -/*8.1.2 IV/EIV format : 2DW */ - -/*8.1.3 RX attribute entry format : 1DW */ -struct rt_mac_attribute { - u32 KeyTab:1; /* 0 for shared key table. 1 for pairwise key table */ - u32 PairKeyMode:3; - u32 BSSIDIdx:3; /*multipleBSS index for the WCID */ - u32 RXWIUDF:3; - u32 rsv:22; -}; - -/* ================================================================================= */ -/* HOST-MCU communication data structure */ -/* ================================================================================= */ - -/* */ -/* H2M_MAILBOX_CSR: Host-to-MCU Mailbox */ -/* */ -typedef union _H2M_MAILBOX_STRUC { - struct { - u32 LowByte:8; - u32 HighByte:8; - u32 CmdToken:8; - u32 Owner:8; - } field; - u32 word; -} H2M_MAILBOX_STRUC, *PH2M_MAILBOX_STRUC; - -/* */ -/* M2H_CMD_DONE_CSR: MCU-to-Host command complete indication */ -/* */ -typedef union _M2H_CMD_DONE_STRUC { - struct { - u32 CmdToken0; - u32 CmdToken1; - u32 CmdToken2; - u32 CmdToken3; - } field; - u32 word; -} M2H_CMD_DONE_STRUC, *PM2H_CMD_DONE_STRUC; - -/*NAV_TIME_CFG :NAV */ -typedef union _NAV_TIME_CFG_STRUC { - struct { - u8 Sifs; /* in unit of 1-us */ - u8 SlotTime; /* in unit of 1-us */ - u16 Eifs:9; /* in unit of 1-us */ - u16 ZeroSifs:1; /* Applied zero SIFS timer after OFDM RX 0: disable */ - u16 rsv:6; - } field; - u32 word; -} NAV_TIME_CFG_STRUC, *PNAV_TIME_CFG_STRUC; - -/* */ -/* RX_FILTR_CFG: /RX configuration register */ -/* */ -typedef union _RX_FILTR_CFG_STRUC { - struct { - u32 DropCRCErr:1; /* Drop CRC error */ - u32 DropPhyErr:1; /* Drop physical error */ - u32 DropNotToMe:1; /* Drop not to me unicast frame */ - u32 DropNotMyBSSID:1; /* Drop fram ToDs bit is true */ - - u32 DropVerErr:1; /* Drop version error frame */ - u32 DropMcast:1; /* Drop multicast frames */ - u32 DropBcast:1; /* Drop broadcast frames */ - u32 DropDuplicate:1; /* Drop duplicate frame */ - - u32 DropCFEndAck:1; /* Drop Ps-Poll */ - u32 DropCFEnd:1; /* Drop Ps-Poll */ - u32 DropAck:1; /* Drop Ps-Poll */ - u32 DropCts:1; /* Drop Ps-Poll */ - - u32 DropRts:1; /* Drop Ps-Poll */ - u32 DropPsPoll:1; /* Drop Ps-Poll */ - u32 DropBA:1; /* */ - u32 DropBAR:1; /* */ - - u32 DropRsvCntlType:1; - u32: 15; - } field; - u32 word; -} RX_FILTR_CFG_STRUC, *PRX_FILTR_CFG_STRUC; - -/* */ -/* PHY_CSR4: RF serial control register */ -/* */ -typedef union _PHY_CSR4_STRUC { - struct { - u32 RFRegValue:24; /* Register value (include register id) serial out to RF/IF chip. */ - u32 NumberOfBits:5; /* Number of bits used in RFRegValue (I:20, RFMD:22) */ - u32 IFSelect:1; /* 1: select IF to program, 0: select RF to program */ - u32 PLL_LD:1; /* RF PLL_LD status */ - u32 Busy:1; /* 1: ASIC is busy execute RF programming. */ - } field; - u32 word; -} PHY_CSR4_STRUC, *PPHY_CSR4_STRUC; - -/* */ -/* SEC_CSR5: shared key table security mode register */ -/* */ -typedef union _SEC_CSR5_STRUC { - struct { - u32 Bss2Key0CipherAlg:3; - u32: 1; - u32 Bss2Key1CipherAlg:3; - u32: 1; - u32 Bss2Key2CipherAlg:3; - u32: 1; - u32 Bss2Key3CipherAlg:3; - u32: 1; - u32 Bss3Key0CipherAlg:3; - u32: 1; - u32 Bss3Key1CipherAlg:3; - u32: 1; - u32 Bss3Key2CipherAlg:3; - u32: 1; - u32 Bss3Key3CipherAlg:3; - u32: 1; - } field; - u32 word; -} SEC_CSR5_STRUC, *PSEC_CSR5_STRUC; - -/* */ -/* HOST_CMD_CSR: For HOST to interrupt embedded processor */ -/* */ -typedef union _HOST_CMD_CSR_STRUC { - struct { - u32 HostCommand:8; - u32 Rsv:24; - } field; - u32 word; -} HOST_CMD_CSR_STRUC, *PHOST_CMD_CSR_STRUC; - -/* */ -/* AIFSN_CSR: AIFSN for each EDCA AC */ -/* */ - -/* */ -/* E2PROM_CSR: EEPROM control register */ -/* */ -typedef union _E2PROM_CSR_STRUC { - struct { - u32 Reload:1; /* Reload EEPROM content, write one to reload, self-cleared. */ - u32 EepromSK:1; - u32 EepromCS:1; - u32 EepromDI:1; - u32 EepromDO:1; - u32 Type:1; /* 1: 93C46, 0:93C66 */ - u32 LoadStatus:1; /* 1:loading, 0:done */ - u32 Rsvd:25; - } field; - u32 word; -} E2PROM_CSR_STRUC, *PE2PROM_CSR_STRUC; - -/* */ -/* QOS_CSR0: TXOP holder address0 register */ -/* */ -typedef union _QOS_CSR0_STRUC { - struct { - u8 Byte0; /* MAC address byte 0 */ - u8 Byte1; /* MAC address byte 1 */ - u8 Byte2; /* MAC address byte 2 */ - u8 Byte3; /* MAC address byte 3 */ - } field; - u32 word; -} QOS_CSR0_STRUC, *PQOS_CSR0_STRUC; - -/* */ -/* QOS_CSR1: TXOP holder address1 register */ -/* */ -typedef union _QOS_CSR1_STRUC { - struct { - u8 Byte4; /* MAC address byte 4 */ - u8 Byte5; /* MAC address byte 5 */ - u8 Rsvd0; - u8 Rsvd1; - } field; - u32 word; -} QOS_CSR1_STRUC, *PQOS_CSR1_STRUC; - -#define RF_CSR_CFG 0x500 -typedef union _RF_CSR_CFG_STRUC { - struct { - u32 RF_CSR_DATA:8; /* DATA */ - u32 TESTCSR_RFACC_REGNUM:5; /* RF register ID */ - u32 Rsvd2:3; /* Reserved */ - u32 RF_CSR_WR:1; /* 0: read 1: write */ - u32 RF_CSR_KICK:1; /* kick RF register read/write */ - u32 Rsvd1:14; /* Reserved */ - } field; - u32 word; -} RF_CSR_CFG_STRUC, *PRF_CSR_CFG_STRUC; - -/* */ -/* Other on-chip shared memory space, base = 0x2000 */ -/* */ - -/* CIS space - base address = 0x2000 */ -#define HW_CIS_BASE 0x2000 - -/* Carrier-sense CTS frame base address. It's where mac stores carrier-sense frame for carrier-sense function. */ -#define HW_CS_CTS_BASE 0x7700 -/* DFS CTS frame base address. It's where mac stores CTS frame for DFS. */ -#define HW_DFS_CTS_BASE 0x7780 -#define HW_CTS_FRAME_SIZE 0x80 - -/* 2004-11-08 john - since NULL frame won't be that long (256 byte). We steal 16 tail bytes */ -/* to save debugging settings */ -#define HW_DEBUG_SETTING_BASE 0x77f0 /* 0x77f0~0x77ff total 16 bytes */ -#define HW_DEBUG_SETTING_BASE2 0x7770 /* 0x77f0~0x77ff total 16 bytes */ - -/* In order to support maximum 8 MBSS and its maximum length is 512 for each beacon */ -/* Three section discontinue memory segments will be used. */ -/* 1. The original region for BCN 0~3 */ -/* 2. Extract memory from FCE table for BCN 4~5 */ -/* 3. Extract memory from Pair-wise key table for BCN 6~7 */ -/* It occupied those memory of wcid 238~253 for BCN 6 */ -/* and wcid 222~237 for BCN 7 */ -#define HW_BEACON_MAX_SIZE 0x1000 /* unit: byte */ -#define HW_BEACON_BASE0 0x7800 -#define HW_BEACON_BASE1 0x7A00 -#define HW_BEACON_BASE2 0x7C00 -#define HW_BEACON_BASE3 0x7E00 -#define HW_BEACON_BASE4 0x7200 -#define HW_BEACON_BASE5 0x7400 -#define HW_BEACON_BASE6 0x5DC0 -#define HW_BEACON_BASE7 0x5BC0 - -#define HW_BEACON_MAX_COUNT 8 -#define HW_BEACON_OFFSET 0x0200 -#define HW_BEACON_CONTENT_LEN (HW_BEACON_OFFSET - TXWI_SIZE) - -/* HOST-MCU shared memory - base address = 0x2100 */ -#define HOST_CMD_CSR 0x404 -#define H2M_MAILBOX_CSR 0x7010 -#define H2M_MAILBOX_CID 0x7014 -#define H2M_MAILBOX_STATUS 0x701c -#define H2M_INT_SRC 0x7024 -#define H2M_BBP_AGENT 0x7028 -#define M2H_CMD_DONE_CSR 0x000c -#define MCU_TXOP_ARRAY_BASE 0x000c /* TODO: to be provided by Albert */ -#define MCU_TXOP_ENTRY_SIZE 32 /* TODO: to be provided by Albert */ -#define MAX_NUM_OF_TXOP_ENTRY 16 /* TODO: must be same with 8051 firmware */ -#define MCU_MBOX_VERSION 0x01 /* TODO: to be confirmed by Albert */ -#define MCU_MBOX_VERSION_OFFSET 5 /* TODO: to be provided by Albert */ - -/* */ -/* Host DMA registers - base address 0x200 . TX0-3=EDCAQid0-3, TX4=HCCA, TX5=MGMT, */ -/* */ -/* */ -/* DMA RING DESCRIPTOR */ -/* */ -#define E2PROM_CSR 0x0004 -#define IO_CNTL_CSR 0x77d0 - -/* ================================================================ */ -/* Tx / Rx / Mgmt ring descriptor definition */ -/* ================================================================ */ - -/* the following PID values are used to mark outgoing frame type in TXD->PID so that */ -/* proper TX statistics can be collected based on these categories */ -/* b3-2 of PID field - */ -#define PID_MGMT 0x05 -#define PID_BEACON 0x0c -#define PID_DATA_NORMALUCAST 0x02 -#define PID_DATA_AMPDU 0x04 -#define PID_DATA_NO_ACK 0x08 -#define PID_DATA_NOT_NORM_ACK 0x03 -/* value domain of pTxD->HostQId (4-bit: 0~15) */ -#define QID_AC_BK 1 /* meet ACI definition in 802.11e */ -#define QID_AC_BE 0 /* meet ACI definition in 802.11e */ -#define QID_AC_VI 2 -#define QID_AC_VO 3 -#define QID_HCCA 4 -#define NUM_OF_TX_RING 4 -#define QID_MGMT 13 -#define QID_RX 14 -#define QID_OTHER 15 - -#endif /* __RTMP_MAC_H__ // */ diff --git a/trunk/drivers/staging/rt2860/chip/rtmp_phy.h b/trunk/drivers/staging/rt2860/chip/rtmp_phy.h deleted file mode 100644 index a52221f1294e..000000000000 --- a/trunk/drivers/staging/rt2860/chip/rtmp_phy.h +++ /dev/null @@ -1,516 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_phy.h - - Abstract: - Ralink Wireless Chip PHY(BBP/RF) related definition & structures - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ - -#ifndef __RTMP_PHY_H__ -#define __RTMP_PHY_H__ - -/* - RF sections -*/ -#define RF_R00 0 -#define RF_R01 1 -#define RF_R02 2 -#define RF_R03 3 -#define RF_R04 4 -#define RF_R05 5 -#define RF_R06 6 -#define RF_R07 7 -#define RF_R08 8 -#define RF_R09 9 -#define RF_R10 10 -#define RF_R11 11 -#define RF_R12 12 -#define RF_R13 13 -#define RF_R14 14 -#define RF_R15 15 -#define RF_R16 16 -#define RF_R17 17 -#define RF_R18 18 -#define RF_R19 19 -#define RF_R20 20 -#define RF_R21 21 -#define RF_R22 22 -#define RF_R23 23 -#define RF_R24 24 -#define RF_R25 25 -#define RF_R26 26 -#define RF_R27 27 -#define RF_R28 28 -#define RF_R29 29 -#define RF_R30 30 -#define RF_R31 31 - -/* value domain of pAd->RfIcType */ -#define RFIC_2820 1 /* 2.4G 2T3R */ -#define RFIC_2850 2 /* 2.4G/5G 2T3R */ -#define RFIC_2720 3 /* 2.4G 1T2R */ -#define RFIC_2750 4 /* 2.4G/5G 1T2R */ -#define RFIC_3020 5 /* 2.4G 1T1R */ -#define RFIC_2020 6 /* 2.4G B/G */ -#define RFIC_3021 7 /* 2.4G 1T2R */ -#define RFIC_3022 8 /* 2.4G 2T2R */ -#define RFIC_3052 9 /* 2.4G/5G 2T2R */ - -/* - BBP sections -*/ -#define BBP_R0 0 /* version */ -#define BBP_R1 1 /* TSSI */ -#define BBP_R2 2 /* TX configure */ -#define BBP_R3 3 -#define BBP_R4 4 -#define BBP_R5 5 -#define BBP_R6 6 -#define BBP_R14 14 /* RX configure */ -#define BBP_R16 16 -#define BBP_R17 17 /* RX sensibility */ -#define BBP_R18 18 -#define BBP_R21 21 -#define BBP_R22 22 -#define BBP_R24 24 -#define BBP_R25 25 -#define BBP_R26 26 -#define BBP_R27 27 -#define BBP_R31 31 -#define BBP_R49 49 /*TSSI */ -#define BBP_R50 50 -#define BBP_R51 51 -#define BBP_R52 52 -#define BBP_R55 55 -#define BBP_R62 62 /* Rx SQ0 Threshold HIGH */ -#define BBP_R63 63 -#define BBP_R64 64 -#define BBP_R65 65 -#define BBP_R66 66 -#define BBP_R67 67 -#define BBP_R68 68 -#define BBP_R69 69 -#define BBP_R70 70 /* Rx AGC SQ CCK Xcorr threshold */ -#define BBP_R73 73 -#define BBP_R75 75 -#define BBP_R77 77 -#define BBP_R78 78 -#define BBP_R79 79 -#define BBP_R80 80 -#define BBP_R81 81 -#define BBP_R82 82 -#define BBP_R83 83 -#define BBP_R84 84 -#define BBP_R86 86 -#define BBP_R91 91 -#define BBP_R92 92 -#define BBP_R94 94 /* Tx Gain Control */ -#define BBP_R103 103 -#define BBP_R105 105 -#define BBP_R106 106 -#define BBP_R113 113 -#define BBP_R114 114 -#define BBP_R115 115 -#define BBP_R116 116 -#define BBP_R117 117 -#define BBP_R118 118 -#define BBP_R119 119 -#define BBP_R120 120 -#define BBP_R121 121 -#define BBP_R122 122 -#define BBP_R123 123 -#ifdef RT30xx -#define BBP_R138 138 /* add by johnli, RF power sequence setup, ADC dynamic on/off control */ -#endif /* RT30xx // */ - -#define BBPR94_DEFAULT 0x06 /* Add 1 value will gain 1db */ - -/* */ -/* BBP & RF are using indirect access. Before write any value into it. */ -/* We have to make sure there is no outstanding command pending via checking busy bit. */ -/* */ -#define MAX_BUSY_COUNT 100 /* Number of retry before failing access BBP & RF indirect register */ - -/*#define PHY_TR_SWITCH_TIME 5 // usec */ - -/*#define BBP_R17_LOW_SENSIBILITY 0x50 */ -/*#define BBP_R17_MID_SENSIBILITY 0x41 */ -/*#define BBP_R17_DYNAMIC_UP_BOUND 0x40 */ - -#define RSSI_FOR_VERY_LOW_SENSIBILITY -35 -#define RSSI_FOR_LOW_SENSIBILITY -58 -#define RSSI_FOR_MID_LOW_SENSIBILITY -80 -#define RSSI_FOR_MID_SENSIBILITY -90 - -/***************************************************************************** - RF register Read/Write marco definition - *****************************************************************************/ -#ifdef RTMP_MAC_PCI -#define RTMP_RF_IO_WRITE32(_A, _V) \ -{ \ - if ((_A)->bPCIclkOff == FALSE) { \ - PHY_CSR4_STRUC _value; \ - unsigned long _busyCnt = 0; \ - \ - do { \ - RTMP_IO_READ32((_A), RF_CSR_CFG0, &_value.word); \ - if (_value.field.Busy == IDLE) \ - break; \ - _busyCnt++; \ - } while (_busyCnt < MAX_BUSY_COUNT); \ - if (_busyCnt < MAX_BUSY_COUNT) { \ - RTMP_IO_WRITE32((_A), RF_CSR_CFG0, (_V)); \ - } \ - } \ -} -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB -#define RTMP_RF_IO_WRITE32(_A, _V) RTUSBWriteRFRegister(_A, _V) -#endif /* RTMP_MAC_USB // */ - -#ifdef RT30xx -#define RTMP_RF_IO_READ8_BY_REG_ID(_A, _I, _pV) RT30xxReadRFRegister(_A, _I, _pV) -#define RTMP_RF_IO_WRITE8_BY_REG_ID(_A, _I, _V) RT30xxWriteRFRegister(_A, _I, _V) -#endif /* RT30xx // */ - -/***************************************************************************** - BBP register Read/Write marco definitions. - we read/write the bbp value by register's ID. - Generate PER to test BA - *****************************************************************************/ -#ifdef RTMP_MAC_PCI -/* - basic marco for BBP read operation. - _pAd: the data structure pointer of struct rt_rtmp_adapter - _bbpID : the bbp register ID - _pV: data pointer used to save the value of queried bbp register. - _bViaMCU: if we need access the bbp via the MCU. -*/ -#define RTMP_BBP_IO_READ8(_pAd, _bbpID, _pV, _bViaMCU) \ - do { \ - BBP_CSR_CFG_STRUC BbpCsr; \ - int _busyCnt, _secCnt, _regID; \ - \ - _regID = ((_bViaMCU) == TRUE ? H2M_BBP_AGENT : BBP_CSR_CFG); \ - for (_busyCnt = 0; _busyCnt < MAX_BUSY_COUNT; _busyCnt++) { \ - RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \ - if (BbpCsr.field.Busy == BUSY) \ - continue; \ - BbpCsr.word = 0; \ - BbpCsr.field.fRead = 1; \ - BbpCsr.field.BBP_RW_MODE = 1; \ - BbpCsr.field.Busy = 1; \ - BbpCsr.field.RegNum = _bbpID; \ - RTMP_IO_WRITE32(_pAd, _regID, BbpCsr.word); \ - if ((_bViaMCU) == TRUE) { \ - AsicSendCommandToMcu(_pAd, 0x80, 0xff, 0x0, 0x0); \ - RTMPusecDelay(1000); \ - } \ - for (_secCnt = 0; _secCnt < MAX_BUSY_COUNT; _secCnt++) { \ - RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \ - if (BbpCsr.field.Busy == IDLE) \ - break; \ - } \ - if ((BbpCsr.field.Busy == IDLE) && \ - (BbpCsr.field.RegNum == _bbpID)) { \ - *(_pV) = (u8)BbpCsr.field.Value; \ - break; \ - } \ - } \ - if (BbpCsr.field.Busy == BUSY) { \ - DBGPRINT_ERR("BBP(viaMCU=%d) read R%d fail\n", (_bViaMCU), _bbpID); \ - *(_pV) = (_pAd)->BbpWriteLatch[_bbpID]; \ - if ((_bViaMCU) == TRUE) { \ - RTMP_IO_READ32(_pAd, _regID, &BbpCsr.word); \ - BbpCsr.field.Busy = 0; \ - RTMP_IO_WRITE32(_pAd, _regID, BbpCsr.word); \ - } \ - } \ - } while (0) - -/* - This marco used for the BBP read operation which didn't need via MCU. -*/ -#define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) \ - RTMP_BBP_IO_READ8((_A), (_I), (_pV), FALSE) - -/* - This marco used for the BBP read operation which need via MCU. - But for some chipset which didn't have mcu (e.g., RBUS based chipset), we - will use this function too and didn't access the bbp register via the MCU. -*/ -/* Read BBP register by register's ID. Generate PER to test BA */ -#define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) \ -{ \ - BBP_CSR_CFG_STRUC BbpCsr; \ - int i, k; \ - BOOLEAN brc; \ - BbpCsr.field.Busy = IDLE; \ - if ((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) \ - && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \ - && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE) \ - && ((_A)->bPCIclkOff == FALSE) \ - && ((_A)->brt30xxBanMcuCmd == FALSE)) { \ - for (i = 0; i < MAX_BUSY_COUNT; i++) { \ - RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \ - if (BbpCsr.field.Busy == BUSY) { \ - continue; \ - } \ - BbpCsr.word = 0; \ - BbpCsr.field.fRead = 1; \ - BbpCsr.field.BBP_RW_MODE = 1; \ - BbpCsr.field.Busy = 1; \ - BbpCsr.field.RegNum = _I; \ - RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \ - brc = AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \ - if (brc == TRUE) { \ - for (k = 0; k < MAX_BUSY_COUNT; k++) { \ - RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \ - if (BbpCsr.field.Busy == IDLE) \ - break; \ - } \ - if ((BbpCsr.field.Busy == IDLE) && \ - (BbpCsr.field.RegNum == _I)) { \ - *(_pV) = (u8)BbpCsr.field.Value; \ - break; \ - } \ - } else { \ - BbpCsr.field.Busy = 0; \ - RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \ - } \ - } \ - } \ - else if (!((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \ - && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE)) \ - && ((_A)->bPCIclkOff == FALSE)) { \ - for (i = 0; i < MAX_BUSY_COUNT; i++) { \ - RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \ - if (BbpCsr.field.Busy == BUSY) { \ - continue; \ - } \ - BbpCsr.word = 0; \ - BbpCsr.field.fRead = 1; \ - BbpCsr.field.BBP_RW_MODE = 1; \ - BbpCsr.field.Busy = 1; \ - BbpCsr.field.RegNum = _I; \ - RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \ - AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \ - for (k = 0; k < MAX_BUSY_COUNT; k++) { \ - RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \ - if (BbpCsr.field.Busy == IDLE) \ - break; \ - } \ - if ((BbpCsr.field.Busy == IDLE) && \ - (BbpCsr.field.RegNum == _I)) { \ - *(_pV) = (u8)BbpCsr.field.Value; \ - break; \ - } \ - } \ - } else { \ - DBGPRINT_ERR(" , brt30xxBanMcuCmd = %d, Read BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I)); \ - *(_pV) = (_A)->BbpWriteLatch[_I]; \ - } \ - if ((BbpCsr.field.Busy == BUSY) || ((_A)->bPCIclkOff == TRUE)) { \ - DBGPRINT_ERR("BBP read R%d=0x%x fail\n", _I, BbpCsr.word); \ - *(_pV) = (_A)->BbpWriteLatch[_I]; \ - } \ -} - -/* - basic marco for BBP write operation. - _pAd: the data structure pointer of struct rt_rtmp_adapter - _bbpID : the bbp register ID - _pV: data used to save the value of queried bbp register. - _bViaMCU: if we need access the bbp via the MCU. -*/ -#define RTMP_BBP_IO_WRITE8(_pAd, _bbpID, _pV, _bViaMCU) \ - do { \ - BBP_CSR_CFG_STRUC BbpCsr; \ - int _busyCnt, _regID; \ - \ - _regID = ((_bViaMCU) == TRUE ? H2M_BBP_AGENT : BBP_CSR_CFG); \ - for (_busyCnt = 0; _busyCnt < MAX_BUSY_COUNT; _busyCnt++) { \ - RTMP_IO_READ32((_pAd), BBP_CSR_CFG, &BbpCsr.word); \ - if (BbpCsr.field.Busy == BUSY) \ - continue; \ - BbpCsr.word = 0; \ - BbpCsr.field.fRead = 0; \ - BbpCsr.field.BBP_RW_MODE = 1; \ - BbpCsr.field.Busy = 1; \ - BbpCsr.field.Value = _pV; \ - BbpCsr.field.RegNum = _bbpID; \ - RTMP_IO_WRITE32((_pAd), BBP_CSR_CFG, BbpCsr.word); \ - if ((_bViaMCU) == TRUE) { \ - AsicSendCommandToMcu(_pAd, 0x80, 0xff, 0x0, 0x0); \ - if ((_pAd)->OpMode == OPMODE_AP) \ - RTMPusecDelay(1000); \ - } \ - (_pAd)->BbpWriteLatch[_bbpID] = _pV; \ - break; \ - } \ - if (_busyCnt == MAX_BUSY_COUNT) { \ - DBGPRINT_ERR("BBP write R%d fail\n", _bbpID); \ - if ((_bViaMCU) == TRUE) { \ - RTMP_IO_READ32(_pAd, H2M_BBP_AGENT, &BbpCsr.word); \ - BbpCsr.field.Busy = 0; \ - RTMP_IO_WRITE32(_pAd, H2M_BBP_AGENT, BbpCsr.word); \ - } \ - } \ - } while (0) - -/* - This marco used for the BBP write operation which didn't need via MCU. -*/ -#define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _pV) \ - RTMP_BBP_IO_WRITE8((_A), (_I), (_pV), FALSE) - -/* - This marco used for the BBP write operation which need via MCU. - But for some chipset which didn't have mcu (e.g., RBUS based chipset), we - will use this function too and didn't access the bbp register via the MCU. -*/ -/* Write BBP register by register's ID & value */ -#define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) \ -{ \ - BBP_CSR_CFG_STRUC BbpCsr; \ - int BusyCnt = 0; \ - BOOLEAN brc; \ - if (_I < MAX_NUM_OF_BBP_LATCH) { \ - if ((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) \ - && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \ - && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE) \ - && ((_A)->bPCIclkOff == FALSE) \ - && ((_A)->brt30xxBanMcuCmd == FALSE)) { \ - if (_A->AccessBBPFailCount > 20) { \ - AsicResetBBPAgent(_A); \ - _A->AccessBBPFailCount = 0; \ - } \ - for (BusyCnt = 0; BusyCnt < MAX_BUSY_COUNT; BusyCnt++) { \ - RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \ - if (BbpCsr.field.Busy == BUSY) \ - continue; \ - BbpCsr.word = 0; \ - BbpCsr.field.fRead = 0; \ - BbpCsr.field.BBP_RW_MODE = 1; \ - BbpCsr.field.Busy = 1; \ - BbpCsr.field.Value = _V; \ - BbpCsr.field.RegNum = _I; \ - RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \ - brc = AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \ - if (brc == TRUE) { \ - (_A)->BbpWriteLatch[_I] = _V; \ - } else { \ - BbpCsr.field.Busy = 0; \ - RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \ - } \ - break; \ - } \ - } \ - else if (!((IS_RT3090((_A)) || IS_RT3572((_A)) || IS_RT3390((_A))) \ - && ((_A)->StaCfg.PSControl.field.rt30xxPowerMode == 3) \ - && ((_A)->StaCfg.PSControl.field.EnableNewPS == TRUE)) \ - && ((_A)->bPCIclkOff == FALSE)) { \ - if (_A->AccessBBPFailCount > 20) { \ - AsicResetBBPAgent(_A); \ - _A->AccessBBPFailCount = 0; \ - } \ - for (BusyCnt = 0; BusyCnt < MAX_BUSY_COUNT; BusyCnt++) { \ - RTMP_IO_READ32(_A, H2M_BBP_AGENT, &BbpCsr.word); \ - if (BbpCsr.field.Busy == BUSY) \ - continue; \ - BbpCsr.word = 0; \ - BbpCsr.field.fRead = 0; \ - BbpCsr.field.BBP_RW_MODE = 1; \ - BbpCsr.field.Busy = 1; \ - BbpCsr.field.Value = _V; \ - BbpCsr.field.RegNum = _I; \ - RTMP_IO_WRITE32(_A, H2M_BBP_AGENT, BbpCsr.word); \ - AsicSendCommandToMcu(_A, 0x80, 0xff, 0x0, 0x0); \ - (_A)->BbpWriteLatch[_I] = _V; \ - break; \ - } \ - } else { \ - DBGPRINT_ERR(" brt30xxBanMcuCmd = %d. Write BBP %d \n", (_A)->brt30xxBanMcuCmd, (_I)); \ - } \ - if ((BusyCnt == MAX_BUSY_COUNT) || ((_A)->bPCIclkOff == TRUE)) { \ - if (BusyCnt == MAX_BUSY_COUNT) \ - (_A)->AccessBBPFailCount++; \ - DBGPRINT_ERR("BBP write R%d=0x%x fail. BusyCnt= %d.bPCIclkOff = %d. \n", _I, BbpCsr.word, BusyCnt, (_A)->bPCIclkOff); \ - } \ - } else { \ - DBGPRINT_ERR("****** BBP_Write_Latch Buffer exceeds max boundary ****** \n"); \ - } \ -} -#endif /* RTMP_MAC_PCI // */ - -#ifdef RTMP_MAC_USB -#define RTMP_BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTUSBReadBBPRegister(_A, _I, _pV) -#define RTMP_BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTUSBWriteBBPRegister(_A, _I, _V) - -#define BBP_IO_WRITE8_BY_REG_ID(_A, _I, _V) RTUSBWriteBBPRegister(_A, _I, _V) -#define BBP_IO_READ8_BY_REG_ID(_A, _I, _pV) RTUSBReadBBPRegister(_A, _I, _pV) -#endif /* RTMP_MAC_USB // */ - -#ifdef RT30xx -#define RTMP_ASIC_MMPS_DISABLE(_pAd) \ - do { \ - u32 _macData; \ - u8 _bbpData = 0; \ - /* disable MMPS BBP control register */ \ - RTMP_BBP_IO_READ8_BY_REG_ID(_pAd, BBP_R3, &_bbpData); \ - _bbpData &= ~(0x04); /*bit 2*/ \ - RTMP_BBP_IO_WRITE8_BY_REG_ID(_pAd, BBP_R3, _bbpData); \ - \ - /* disable MMPS MAC control register */ \ - RTMP_IO_READ32(_pAd, 0x1210, &_macData); \ - _macData &= ~(0x09); /*bit 0, 3*/ \ - RTMP_IO_WRITE32(_pAd, 0x1210, _macData); \ - } while (0) - -#define RTMP_ASIC_MMPS_ENABLE(_pAd) \ - do { \ - u32 _macData; \ - u8 _bbpData = 0; \ - /* enable MMPS BBP control register */ \ - RTMP_BBP_IO_READ8_BY_REG_ID(_pAd, BBP_R3, &_bbpData); \ - _bbpData |= (0x04); /*bit 2*/ \ - RTMP_BBP_IO_WRITE8_BY_REG_ID(_pAd, BBP_R3, _bbpData); \ - \ - /* enable MMPS MAC control register */ \ - RTMP_IO_READ32(_pAd, 0x1210, &_macData); \ - _macData |= (0x09); /*bit 0, 3*/ \ - RTMP_IO_WRITE32(_pAd, 0x1210, _macData); \ - } while (0) - -#endif /* RT30xx // */ - -#endif /* __RTMP_PHY_H__ // */ diff --git a/trunk/drivers/staging/rt2860/chips/rt3070.c b/trunk/drivers/staging/rt2860/chips/rt3070.c deleted file mode 100644 index 3a17fd10ec1f..000000000000 --- a/trunk/drivers/staging/rt2860/chips/rt3070.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt3070.c - - Abstract: - Specific funcitons and variables for RT3070 - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ - -#ifdef RT3070 - -#include "../rt_config.h" - -#ifndef RTMP_RF_RW_SUPPORT -#error "You Should Enable compile flag RTMP_RF_RW_SUPPORT for this chip" -#endif /* RTMP_RF_RW_SUPPORT // */ - -void NICInitRT3070RFRegisters(struct rt_rtmp_adapter *pAd) -{ - int i; - u8 RFValue; - - /* Driver must read EEPROM to get RfIcType before initial RF registers */ - /* Initialize RF register to default value */ - if (IS_RT3070(pAd) || IS_RT3071(pAd)) { - /* Init RF calibration */ - /* Driver should toggle RF R30 bit7 before init RF registers */ - u32 RfReg = 0; - u32 data; - - RT30xxReadRFRegister(pAd, RF_R30, (u8 *)&RfReg); - RfReg |= 0x80; - RT30xxWriteRFRegister(pAd, RF_R30, (u8)RfReg); - RTMPusecDelay(1000); - RfReg &= 0x7F; - RT30xxWriteRFRegister(pAd, RF_R30, (u8)RfReg); - - /* Initialize RF register to default value */ - for (i = 0; i < NUM_RF_REG_PARMS; i++) { - RT30xxWriteRFRegister(pAd, - RT30xx_RFRegTable[i].Register, - RT30xx_RFRegTable[i].Value); - } - - /* add by johnli */ - if (IS_RT3070(pAd)) { - /* */ - /* The DAC issue(LDO_CFG0) has been fixed in RT3070(F). */ - /* The voltage raising patch is no longer needed for RT3070(F) */ - /* */ - if ((pAd->MACVersion & 0xffff) < 0x0201) { - /* Update MAC 0x05D4 from 01xxxxxx to 0Dxxxxxx (voltage 1.2V to 1.35V) for RT3070 to improve yield rate */ - RTUSBReadMACRegister(pAd, LDO_CFG0, &data); - data = ((data & 0xF0FFFFFF) | 0x0D000000); - RTUSBWriteMACRegister(pAd, LDO_CFG0, data); - } - } else if (IS_RT3071(pAd)) { - /* Driver should set RF R6 bit6 on before init RF registers */ - RT30xxReadRFRegister(pAd, RF_R06, (u8 *)&RfReg); - RfReg |= 0x40; - RT30xxWriteRFRegister(pAd, RF_R06, (u8)RfReg); - - /* init R31 */ - RT30xxWriteRFRegister(pAd, RF_R31, 0x14); - - /* RT3071 version E has fixed this issue */ - if ((pAd->NicConfig2.field.DACTestBit == 1) - && ((pAd->MACVersion & 0xffff) < 0x0211)) { - /* patch tx EVM issue temporarily */ - RTUSBReadMACRegister(pAd, LDO_CFG0, &data); - data = ((data & 0xE0FFFFFF) | 0x0D000000); - RTUSBWriteMACRegister(pAd, LDO_CFG0, data); - } else { - RTMP_IO_READ32(pAd, LDO_CFG0, &data); - data = ((data & 0xE0FFFFFF) | 0x01000000); - RTMP_IO_WRITE32(pAd, LDO_CFG0, data); - } - - /* patch LNA_PE_G1 failed issue */ - RTUSBReadMACRegister(pAd, GPIO_SWITCH, &data); - data &= ~(0x20); - RTUSBWriteMACRegister(pAd, GPIO_SWITCH, data); - } - /*For RF filter Calibration */ - RTMPFilterCalibration(pAd); - - /* Initialize RF R27 register, set RF R27 must be behind RTMPFilterCalibration() */ - /* */ - /* TX to RX IQ glitch(RF_R27) has been fixed in RT3070(F). */ - /* Raising RF voltage is no longer needed for RT3070(F) */ - /* */ - if ((IS_RT3070(pAd)) && ((pAd->MACVersion & 0xffff) < 0x0201)) { - RT30xxWriteRFRegister(pAd, RF_R27, 0x3); - } else if ((IS_RT3071(pAd)) - && ((pAd->MACVersion & 0xffff) < 0x0211)) { - RT30xxWriteRFRegister(pAd, RF_R27, 0x3); - } - /* set led open drain enable */ - RTUSBReadMACRegister(pAd, OPT_14, &data); - data |= 0x01; - RTUSBWriteMACRegister(pAd, OPT_14, data); - - /* move from RT30xxLoadRFNormalModeSetup because it's needed for both RT3070 and RT3071 */ - /* TX_LO1_en, RF R17 register Bit 3 to 0 */ - RT30xxReadRFRegister(pAd, RF_R17, &RFValue); - RFValue &= (~0x08); - /* to fix rx long range issue */ - if (pAd->NicConfig2.field.ExternalLNAForG == 0) { - if ((IS_RT3071(pAd) - && ((pAd->MACVersion & 0xffff) >= 0x0211)) - || IS_RT3070(pAd)) { - RFValue |= 0x20; - } - } - /* set RF_R17_bit[2:0] equal to EEPROM setting at 0x48h */ - if (pAd->TxMixerGain24G >= 1) { - RFValue &= (~0x7); /* clean bit [2:0] */ - RFValue |= pAd->TxMixerGain24G; - } - RT30xxWriteRFRegister(pAd, RF_R17, RFValue); - - if (IS_RT3071(pAd)) { - /* add by johnli, RF power sequence setup, load RF normal operation-mode setup */ - RT30xxLoadRFNormalModeSetup(pAd); - } else if (IS_RT3070(pAd)) { - /* add by johnli, reset RF_R27 when interface down & up to fix throughput problem */ - /* LDORF_VC, RF R27 register Bit 2 to 0 */ - RT30xxReadRFRegister(pAd, RF_R27, &RFValue); - /* TX to RX IQ glitch(RF_R27) has been fixed in RT3070(F). */ - /* Raising RF voltage is no longer needed for RT3070(F) */ - if ((pAd->MACVersion & 0xffff) < 0x0201) - RFValue = (RFValue & (~0x77)) | 0x3; - else - RFValue = (RFValue & (~0x77)); - RT30xxWriteRFRegister(pAd, RF_R27, RFValue); - /* end johnli */ - } - } - -} -#endif /* RT3070 // */ diff --git a/trunk/drivers/staging/rt2860/chips/rt3090.c b/trunk/drivers/staging/rt2860/chips/rt3090.c deleted file mode 100644 index 334720ee1345..000000000000 --- a/trunk/drivers/staging/rt2860/chips/rt3090.c +++ /dev/null @@ -1,121 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt3090.c - - Abstract: - Specific functions and variables for RT3070 - - Revision History: - Who When What - Justin P. Mattock 11/07/2010 Fix a typo - -------- ---------- ---------------------------------------------- -*/ - -#ifdef RT3090 - -#include "../rt_config.h" - -#ifndef RTMP_RF_RW_SUPPORT -#error "You Should Enable compile flag RTMP_RF_RW_SUPPORT for this chip" -#endif /* RTMP_RF_RW_SUPPORT // */ - -void NICInitRT3090RFRegisters(struct rt_rtmp_adapter *pAd) -{ - int i; - /* Driver must read EEPROM to get RfIcType before initial RF registers */ - /* Initialize RF register to default value */ - if (IS_RT3090(pAd)) { - /* Init RF calibration */ - /* Driver should toggle RF R30 bit7 before init RF registers */ - u8 RfReg; - u32 data; - - RT30xxReadRFRegister(pAd, RF_R30, (u8 *)&RfReg); - RfReg |= 0x80; - RT30xxWriteRFRegister(pAd, RF_R30, (u8)RfReg); - RTMPusecDelay(1000); - RfReg &= 0x7F; - RT30xxWriteRFRegister(pAd, RF_R30, (u8)RfReg); - - /* init R24, R31 */ - RT30xxWriteRFRegister(pAd, RF_R24, 0x0F); - RT30xxWriteRFRegister(pAd, RF_R31, 0x0F); - - /* RT309x version E has fixed this issue */ - if ((pAd->NicConfig2.field.DACTestBit == 1) - && ((pAd->MACVersion & 0xffff) < 0x0211)) { - /* patch tx EVM issue temporarily */ - RTMP_IO_READ32(pAd, LDO_CFG0, &data); - data = ((data & 0xE0FFFFFF) | 0x0D000000); - RTMP_IO_WRITE32(pAd, LDO_CFG0, data); - } else { - RTMP_IO_READ32(pAd, LDO_CFG0, &data); - data = ((data & 0xE0FFFFFF) | 0x01000000); - RTMP_IO_WRITE32(pAd, LDO_CFG0, data); - } - - /* patch LNA_PE_G1 failed issue */ - RTMP_IO_READ32(pAd, GPIO_SWITCH, &data); - data &= ~(0x20); - RTMP_IO_WRITE32(pAd, GPIO_SWITCH, data); - - /* Initialize RF register to default value */ - for (i = 0; i < NUM_RF_REG_PARMS; i++) { - RT30xxWriteRFRegister(pAd, - RT30xx_RFRegTable[i].Register, - RT30xx_RFRegTable[i].Value); - } - - /* Driver should set RF R6 bit6 on before calibration */ - RT30xxReadRFRegister(pAd, RF_R06, (u8 *)&RfReg); - RfReg |= 0x40; - RT30xxWriteRFRegister(pAd, RF_R06, (u8)RfReg); - - /*For RF filter Calibration */ - RTMPFilterCalibration(pAd); - - /* Initialize RF R27 register, set RF R27 must be behind RTMPFilterCalibration() */ - if ((pAd->MACVersion & 0xffff) < 0x0211) - RT30xxWriteRFRegister(pAd, RF_R27, 0x3); - - /* set led open drain enable */ - RTMP_IO_READ32(pAd, OPT_14, &data); - data |= 0x01; - RTMP_IO_WRITE32(pAd, OPT_14, data); - - /* set default antenna as main */ - if (pAd->RfIcType == RFIC_3020) - AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt); - - /* add by johnli, RF power sequence setup, load RF normal operation-mode setup */ - RT30xxLoadRFNormalModeSetup(pAd); - } - -} - -#endif /* RT3090 // */ diff --git a/trunk/drivers/staging/rt2860/chips/rt30xx.c b/trunk/drivers/staging/rt2860/chips/rt30xx.c deleted file mode 100644 index 354debfe1477..000000000000 --- a/trunk/drivers/staging/rt2860/chips/rt30xx.c +++ /dev/null @@ -1,516 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt30xx.c - - Abstract: - Specific functions and variables for RT30xx. - - Revision History: - Who When What - Justin P. Mattock 11/07/2010 Fix some typos - -------- ---------- ---------------------------------------------- -*/ - -#ifdef RT30xx - -#ifndef RTMP_RF_RW_SUPPORT -#error "You Should Enable compile flag RTMP_RF_RW_SUPPORT for this chip" -#endif /* RTMP_RF_RW_SUPPORT // */ - -#include "../rt_config.h" - -/* */ -/* RF register initialization set */ -/* */ -struct rt_reg_pair RT30xx_RFRegTable[] = { - {RF_R04, 0x40} - , - {RF_R05, 0x03} - , - {RF_R06, 0x02} - , - {RF_R07, 0x60} - , - {RF_R09, 0x0F} - , - {RF_R10, 0x41} - , - {RF_R11, 0x21} - , - {RF_R12, 0x7B} - , - {RF_R14, 0x90} - , - {RF_R15, 0x58} - , - {RF_R16, 0xB3} - , - {RF_R17, 0x92} - , - {RF_R18, 0x2C} - , - {RF_R19, 0x02} - , - {RF_R20, 0xBA} - , - {RF_R21, 0xDB} - , - {RF_R24, 0x16} - , - {RF_R25, 0x01} - , - {RF_R29, 0x1F} - , -}; - -u8 NUM_RF_REG_PARMS = (sizeof(RT30xx_RFRegTable) / sizeof(struct rt_reg_pair)); - -/* Antenna diversity use GPIO3 and EESK pin for control */ -/* Antenna and EEPROM access are both using EESK pin, */ -/* Therefor we should avoid accessing EESK at the same time */ -/* Then restore antenna after EEPROM access */ -/* The original name of this function is AsicSetRxAnt(), now change to */ -/*void AsicSetRxAnt( */ -void RT30xxSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant) -{ - u32 Value; -#ifdef RTMP_MAC_PCI - u32 x; -#endif - - if ((pAd->EepromAccess) || - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) || - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) || - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) || - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { - return; - } - /* the antenna selection is through firmware and MAC register(GPIO3) */ - if (Ant == 0) { - /* Main antenna */ -#ifdef RTMP_MAC_PCI - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); - x |= (EESK); - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); -#else - AsicSendCommandToMcu(pAd, 0x73, 0xFF, 0x1, 0x0); -#endif /* RTMP_MAC_PCI // */ - - RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &Value); - Value &= ~(0x0808); - RTMP_IO_WRITE32(pAd, GPIO_CTRL_CFG, Value); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("AsicSetRxAnt, switch to main antenna\n")); - } else { - /* Aux antenna */ -#ifdef RTMP_MAC_PCI - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); - x &= ~(EESK); - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); -#else - AsicSendCommandToMcu(pAd, 0x73, 0xFF, 0x0, 0x0); -#endif /* RTMP_MAC_PCI // */ - RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &Value); - Value &= ~(0x0808); - Value |= 0x08; - RTMP_IO_WRITE32(pAd, GPIO_CTRL_CFG, Value); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("AsicSetRxAnt, switch to aux antenna\n")); - } -} - -/* - ======================================================================== - - Routine Description: - For RF filter calibration purpose - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - ======================================================================== -*/ -void RTMPFilterCalibration(struct rt_rtmp_adapter *pAd) -{ - u8 R55x = 0, value, FilterTarget = 0x1E, BBPValue = 0; - u32 loop = 0, count = 0, loopcnt = 0, ReTry = 0; - u8 RF_R24_Value = 0; - - /* Give bbp filter initial value */ - pAd->Mlme.CaliBW20RfR24 = 0x1F; - pAd->Mlme.CaliBW40RfR24 = 0x2F; /*Bit[5] must be 1 for BW 40 */ - - do { - if (loop == 1) { /*BandWidth = 40 MHz */ - /* Write 0x27 to RF_R24 to program filter */ - RF_R24_Value = 0x27; - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); - if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - FilterTarget = 0x15; - else - FilterTarget = 0x19; - - /* when calibrate BW40, BBP mask must set to BW40. */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); - BBPValue &= (~0x18); - BBPValue |= (0x10); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); - - /* set to BW40 */ - RT30xxReadRFRegister(pAd, RF_R31, &value); - value |= 0x20; - RT30xxWriteRFRegister(pAd, RF_R31, value); - } else { /*BandWidth = 20 MHz */ - /* Write 0x07 to RF_R24 to program filter */ - RF_R24_Value = 0x07; - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); - if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - FilterTarget = 0x13; - else - FilterTarget = 0x16; - - /* set to BW20 */ - RT30xxReadRFRegister(pAd, RF_R31, &value); - value &= (~0x20); - RT30xxWriteRFRegister(pAd, RF_R31, value); - } - - /* Write 0x01 to RF_R22 to enable baseband loopback mode */ - RT30xxReadRFRegister(pAd, RF_R22, &value); - value |= 0x01; - RT30xxWriteRFRegister(pAd, RF_R22, value); - - /* Write 0x00 to BBP_R24 to set power & frequency of passband test tone */ - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0); - - do { - /* Write 0x90 to BBP_R25 to transmit test tone */ - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R25, 0x90); - - RTMPusecDelay(1000); - /* Read BBP_R55[6:0] for received power, set R55x = BBP_R55[6:0] */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R55, &value); - R55x = value & 0xFF; - - } while ((ReTry++ < 100) && (R55x == 0)); - - /* Write 0x06 to BBP_R24 to set power & frequency of stopband test tone */ - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0x06); - - while (TRUE) { - /* Write 0x90 to BBP_R25 to transmit test tone */ - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R25, 0x90); - - /*We need to wait for calibration */ - RTMPusecDelay(1000); - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R55, &value); - value &= 0xFF; - if ((R55x - value) < FilterTarget) { - RF_R24_Value++; - } else if ((R55x - value) == FilterTarget) { - RF_R24_Value++; - count++; - } else { - break; - } - - /* prevent infinite loop; causes driver hang. */ - if (loopcnt++ > 100) { - DBGPRINT(RT_DEBUG_ERROR, - ("RTMPFilterCalibration - can't find a valid value, loopcnt=%d stop calibrating", - loopcnt)); - break; - } - /* Write RF_R24 to program filter */ - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); - } - - if (count > 0) { - RF_R24_Value = RF_R24_Value - ((count) ? (1) : (0)); - } - /* Store for future usage */ - if (loopcnt < 100) { - if (loop++ == 0) { - /*BandWidth = 20 MHz */ - pAd->Mlme.CaliBW20RfR24 = (u8)RF_R24_Value; - } else { - /*BandWidth = 40 MHz */ - pAd->Mlme.CaliBW40RfR24 = (u8)RF_R24_Value; - break; - } - } else - break; - - RT30xxWriteRFRegister(pAd, RF_R24, RF_R24_Value); - - /* reset count */ - count = 0; - } while (TRUE); - - /* */ - /* Set back to initial state */ - /* */ - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R24, 0); - - RT30xxReadRFRegister(pAd, RF_R22, &value); - value &= ~(0x01); - RT30xxWriteRFRegister(pAd, RF_R22, value); - - /* set BBP back to BW20 */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); - BBPValue &= (~0x18); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPFilterCalibration - CaliBW20RfR24=0x%x, CaliBW40RfR24=0x%x\n", - pAd->Mlme.CaliBW20RfR24, pAd->Mlme.CaliBW40RfR24)); -} - -/* add by johnli, RF power sequence setup */ -/* - ========================================================================== - Description: - - Load RF normal operation-mode setup - - ========================================================================== - */ -void RT30xxLoadRFNormalModeSetup(struct rt_rtmp_adapter *pAd) -{ - u8 RFValue; - - /* RX0_PD & TX0_PD, RF R1 register Bit 2 & Bit 3 to 0 and RF_BLOCK_en,RX1_PD & TX1_PD, Bit0, Bit 4 & Bit5 to 1 */ - RT30xxReadRFRegister(pAd, RF_R01, &RFValue); - RFValue = (RFValue & (~0x0C)) | 0x31; - RT30xxWriteRFRegister(pAd, RF_R01, RFValue); - - /* TX_LO2_en, RF R15 register Bit 3 to 0 */ - RT30xxReadRFRegister(pAd, RF_R15, &RFValue); - RFValue &= (~0x08); - RT30xxWriteRFRegister(pAd, RF_R15, RFValue); - - /* move to NICInitRT30xxRFRegisters - // TX_LO1_en, RF R17 register Bit 3 to 0 - RT30xxReadRFRegister(pAd, RF_R17, &RFValue); - RFValue &= (~0x08); - // to fix rx long range issue - if (((pAd->MACVersion & 0xffff) >= 0x0211) && (pAd->NicConfig2.field.ExternalLNAForG == 0)) - { - RFValue |= 0x20; - } - // set RF_R17_bit[2:0] equal to EEPROM setting at 0x48h - if (pAd->TxMixerGain24G >= 2) - { - RFValue &= (~0x7); // clean bit [2:0] - RFValue |= pAd->TxMixerGain24G; - } - RT30xxWriteRFRegister(pAd, RF_R17, RFValue); - */ - - /* RX_LO1_en, RF R20 register Bit 3 to 0 */ - RT30xxReadRFRegister(pAd, RF_R20, &RFValue); - RFValue &= (~0x08); - RT30xxWriteRFRegister(pAd, RF_R20, RFValue); - - /* RX_LO2_en, RF R21 register Bit 3 to 0 */ - RT30xxReadRFRegister(pAd, RF_R21, &RFValue); - RFValue &= (~0x08); - RT30xxWriteRFRegister(pAd, RF_R21, RFValue); - - /* add by johnli, reset RF_R27 when interface down & up to fix throughput problem */ - /* LDORF_VC, RF R27 register Bit 2 to 0 */ - RT30xxReadRFRegister(pAd, RF_R27, &RFValue); - /* TX to RX IQ glitch(RF_R27) has been fixed in RT3070(F). */ - /* Raising RF voltage is no longer needed for RT3070(F) */ - if (IS_RT3090(pAd)) { /* RT309x and RT3071/72 */ - if ((pAd->MACVersion & 0xffff) < 0x0211) - RFValue = (RFValue & (~0x77)) | 0x3; - else - RFValue = (RFValue & (~0x77)); - RT30xxWriteRFRegister(pAd, RF_R27, RFValue); - } - /* end johnli */ -} - -/* - ========================================================================== - Description: - - Load RF sleep-mode setup - - ========================================================================== - */ -void RT30xxLoadRFSleepModeSetup(struct rt_rtmp_adapter *pAd) -{ - u8 RFValue; - u32 MACValue; - -#ifdef RTMP_MAC_USB - if (!IS_RT3572(pAd)) -#endif /* RTMP_MAC_USB // */ - { - /* RF_BLOCK_en. RF R1 register Bit 0 to 0 */ - RT30xxReadRFRegister(pAd, RF_R01, &RFValue); - RFValue &= (~0x01); - RT30xxWriteRFRegister(pAd, RF_R01, RFValue); - - /* VCO_IC, RF R7 register Bit 4 & Bit 5 to 0 */ - RT30xxReadRFRegister(pAd, RF_R07, &RFValue); - RFValue &= (~0x30); - RT30xxWriteRFRegister(pAd, RF_R07, RFValue); - - /* Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 0 */ - RT30xxReadRFRegister(pAd, RF_R09, &RFValue); - RFValue &= (~0x0E); - RT30xxWriteRFRegister(pAd, RF_R09, RFValue); - - /* RX_CTB_en, RF R21 register Bit 7 to 0 */ - RT30xxReadRFRegister(pAd, RF_R21, &RFValue); - RFValue &= (~0x80); - RT30xxWriteRFRegister(pAd, RF_R21, RFValue); - } - - if (IS_RT3090(pAd) || /* IS_RT3090 including RT309x and RT3071/72 */ - IS_RT3572(pAd) || - (IS_RT3070(pAd) && ((pAd->MACVersion & 0xffff) < 0x0201))) { -#ifdef RTMP_MAC_USB - if (!IS_RT3572(pAd)) -#endif /* RTMP_MAC_USB // */ - { - RT30xxReadRFRegister(pAd, RF_R27, &RFValue); - RFValue |= 0x77; - RT30xxWriteRFRegister(pAd, RF_R27, RFValue); - } - - RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue); - MACValue |= 0x1D000000; - RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue); - } -} - -/* - ========================================================================== - Description: - - Reverse RF sleep-mode setup - - ========================================================================== - */ -void RT30xxReverseRFSleepModeSetup(struct rt_rtmp_adapter *pAd) -{ - u8 RFValue; - u32 MACValue; - -#ifdef RTMP_MAC_USB - if (!IS_RT3572(pAd)) -#endif /* RTMP_MAC_USB // */ - { - /* RF_BLOCK_en, RF R1 register Bit 0 to 1 */ - RT30xxReadRFRegister(pAd, RF_R01, &RFValue); - RFValue |= 0x01; - RT30xxWriteRFRegister(pAd, RF_R01, RFValue); - - /* VCO_IC, RF R7 register Bit 4 & Bit 5 to 1 */ - RT30xxReadRFRegister(pAd, RF_R07, &RFValue); - RFValue |= 0x20; - RT30xxWriteRFRegister(pAd, RF_R07, RFValue); - - /* Idoh, RF R9 register Bit 1, Bit 2 & Bit 3 to 1 */ - RT30xxReadRFRegister(pAd, RF_R09, &RFValue); - RFValue |= 0x0E; - RT30xxWriteRFRegister(pAd, RF_R09, RFValue); - - /* RX_CTB_en, RF R21 register Bit 7 to 1 */ - RT30xxReadRFRegister(pAd, RF_R21, &RFValue); - RFValue |= 0x80; - RT30xxWriteRFRegister(pAd, RF_R21, RFValue); - } - - if (IS_RT3090(pAd) || /* IS_RT3090 including RT309x and RT3071/72 */ - IS_RT3572(pAd) || - IS_RT3390(pAd) || - (IS_RT3070(pAd) && ((pAd->MACVersion & 0xffff) < 0x0201))) { -#ifdef RTMP_MAC_USB - if (!IS_RT3572(pAd)) -#endif /* RTMP_MAC_USB // */ - { - RT30xxReadRFRegister(pAd, RF_R27, &RFValue); - if ((pAd->MACVersion & 0xffff) < 0x0211) - RFValue = (RFValue & (~0x77)) | 0x3; - else - RFValue = (RFValue & (~0x77)); - RT30xxWriteRFRegister(pAd, RF_R27, RFValue); - } - /* RT3071 version E has fixed this issue */ - if ((pAd->NicConfig2.field.DACTestBit == 1) - && ((pAd->MACVersion & 0xffff) < 0x0211)) { - /* patch tx EVM issue temporarily */ - RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue); - MACValue = ((MACValue & 0xE0FFFFFF) | 0x0D000000); - RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue); - } else { - RTMP_IO_READ32(pAd, LDO_CFG0, &MACValue); - MACValue = ((MACValue & 0xE0FFFFFF) | 0x01000000); - RTMP_IO_WRITE32(pAd, LDO_CFG0, MACValue); - } - } - - if (IS_RT3572(pAd)) - RT30xxWriteRFRegister(pAd, RF_R08, 0x80); -} - -/* end johnli */ - -void RT30xxHaltAction(struct rt_rtmp_adapter *pAd) -{ - u32 TxPinCfg = 0x00050F0F; - - /* */ - /* Turn off LNA_PE or TRSW_POL */ - /* */ - if (IS_RT3070(pAd) || IS_RT3071(pAd) || IS_RT3572(pAd)) { - if ((IS_RT3071(pAd) || IS_RT3572(pAd)) -#ifdef RTMP_EFUSE_SUPPORT - && (pAd->bUseEfuse) -#endif /* RTMP_EFUSE_SUPPORT // */ - ) { - TxPinCfg &= 0xFFFBF0F0; /* bit18 off */ - } else { - TxPinCfg &= 0xFFFFF0F0; - } - - RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg); - } -} - -#endif /* RT30xx // */ diff --git a/trunk/drivers/staging/rt2860/chlist.h b/trunk/drivers/staging/rt2860/chlist.h deleted file mode 100644 index 1231e69d518b..000000000000 --- a/trunk/drivers/staging/rt2860/chlist.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - chlist.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Fonchi Wu 2007-12-19 created -*/ - -#ifndef __CHLIST_H__ -#define __CHLIST_H__ - -#include "rtmp_type.h" -#include "rtmp_def.h" - -#define ODOR 0 -#define IDOR 1 -#define BOTH 2 - -#define BAND_5G 0 -#define BAND_24G 1 -#define BAND_BOTH 2 - -struct rt_ch_desp { - u8 FirstChannel; - u8 NumOfCh; - char MaxTxPwr; /* dBm */ - u8 Geography; /* 0:out door, 1:in door, 2:both */ - BOOLEAN DfsReq; /* Dfs require, 0: No, 1: yes. */ -}; - -struct rt_ch_region { - u8 CountReg[3]; - u8 DfsType; /* 0: CE, 1: FCC, 2: JAP, 3:JAP_W53, JAP_W56 */ - struct rt_ch_desp ChDesp[10]; -}; - -extern struct rt_ch_region ChRegion[]; - -struct rt_ch_freq_map { - u16 channel; - u16 freqKHz; -}; - -extern struct rt_ch_freq_map CH_HZ_ID_MAP[]; -extern int CH_HZ_ID_MAP_NUM; - -#define MAP_CHANNEL_ID_TO_KHZ(_ch, _khz) \ - do { \ - int _chIdx; \ - for (_chIdx = 0; _chIdx < CH_HZ_ID_MAP_NUM; _chIdx++) {\ - if ((_ch) == CH_HZ_ID_MAP[_chIdx].channel) { \ - (_khz) = CH_HZ_ID_MAP[_chIdx].freqKHz * 1000;\ - break; \ - } \ - } \ - if (_chIdx == CH_HZ_ID_MAP_NUM) \ - (_khz) = 2412000; \ - } while (0) - -#define MAP_KHZ_TO_CHANNEL_ID(_khz, _ch) \ - do { \ - int _chIdx; \ - for (_chIdx = 0; _chIdx < CH_HZ_ID_MAP_NUM; _chIdx++) {\ - if ((_khz) == CH_HZ_ID_MAP[_chIdx].freqKHz) {\ - (_ch) = CH_HZ_ID_MAP[_chIdx].channel; \ - break; \ - } \ - } \ - if (_chIdx == CH_HZ_ID_MAP_NUM) \ - (_ch) = 1; \ - } while (0) - -void BuildChannelListEx(struct rt_rtmp_adapter *pAd); - -void BuildBeaconChList(struct rt_rtmp_adapter *pAd, - u8 *pBuf, unsigned long *pBufLen); - -void N_ChannelCheck(struct rt_rtmp_adapter *pAd); - -void N_SetCenCh(struct rt_rtmp_adapter *pAd); - -u8 GetCuntryMaxTxPwr(struct rt_rtmp_adapter *pAd, u8 channel); - -#endif /* __CHLIST_H__ */ diff --git a/trunk/drivers/staging/rt2860/common/action.c b/trunk/drivers/staging/rt2860/common/action.c deleted file mode 100644 index 56ad236e1144..000000000000 --- a/trunk/drivers/staging/rt2860/common/action.c +++ /dev/null @@ -1,606 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - action.c - - Abstract: - Handle association related requests either from WSTA or from local MLME - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Jan Lee 2006 created for rt2860 - */ - -#include "../rt_config.h" -#include "action.h" - -static void ReservedAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -/* - ========================================================================== - Description: - association state machine init, including state transition and timer init - Parameters: - S - pointer to the association state machine - Note: - The state machine looks like the following - - ASSOC_IDLE - MT2_MLME_DISASSOC_REQ mlme_disassoc_req_action - MT2_PEER_DISASSOC_REQ peer_disassoc_action - MT2_PEER_ASSOC_REQ drop - MT2_PEER_REASSOC_REQ drop - MT2_CLS3ERR cls3err_action - ========================================================================== - */ -void ActionStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *S, - OUT STATE_MACHINE_FUNC Trans[]) -{ - StateMachineInit(S, (STATE_MACHINE_FUNC *) Trans, MAX_ACT_STATE, - MAX_ACT_MSG, (STATE_MACHINE_FUNC) Drop, ACT_IDLE, - ACT_MACHINE_BASE); - - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_SPECTRUM_CATE, - (STATE_MACHINE_FUNC) PeerSpectrumAction); - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_QOS_CATE, - (STATE_MACHINE_FUNC) PeerQOSAction); - - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_DLS_CATE, - (STATE_MACHINE_FUNC) ReservedAction); - - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_BA_CATE, - (STATE_MACHINE_FUNC) PeerBAAction); - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_HT_CATE, - (STATE_MACHINE_FUNC) PeerHTAction); - StateMachineSetAction(S, ACT_IDLE, MT2_MLME_ADD_BA_CATE, - (STATE_MACHINE_FUNC) MlmeADDBAAction); - StateMachineSetAction(S, ACT_IDLE, MT2_MLME_ORI_DELBA_CATE, - (STATE_MACHINE_FUNC) MlmeDELBAAction); - StateMachineSetAction(S, ACT_IDLE, MT2_MLME_REC_DELBA_CATE, - (STATE_MACHINE_FUNC) MlmeDELBAAction); - - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_PUBLIC_CATE, - (STATE_MACHINE_FUNC) PeerPublicAction); - StateMachineSetAction(S, ACT_IDLE, MT2_PEER_RM_CATE, - (STATE_MACHINE_FUNC) PeerRMAction); - - StateMachineSetAction(S, ACT_IDLE, MT2_MLME_QOS_CATE, - (STATE_MACHINE_FUNC) MlmeQOSAction); - StateMachineSetAction(S, ACT_IDLE, MT2_MLME_DLS_CATE, - (STATE_MACHINE_FUNC) MlmeDLSAction); - StateMachineSetAction(S, ACT_IDLE, MT2_ACT_INVALID, - (STATE_MACHINE_FUNC) MlmeInvalidAction); -} - -void MlmeADDBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_mlme_addba_req *pInfo; - u8 Addr[6]; - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long Idx; - struct rt_frame_addba_req Frame; - unsigned long FrameLen; - struct rt_ba_ori_entry *pBAEntry = NULL; - - pInfo = (struct rt_mlme_addba_req *)Elem->Msg; - NdisZeroMemory(&Frame, sizeof(struct rt_frame_addba_req)); - - if (MlmeAddBAReqSanity(pAd, Elem->Msg, Elem->MsgLen, Addr)) { - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("BA - MlmeADDBAAction() allocate memory failed \n")); - return; - } - /* 1. find entry */ - Idx = - pAd->MacTab.Content[pInfo->Wcid].BAOriWcidArray[pInfo->TID]; - if (Idx == 0) { - MlmeFreeMemory(pAd, pOutBuffer); - DBGPRINT(RT_DEBUG_ERROR, - ("BA - MlmeADDBAAction() can't find BAOriEntry \n")); - return; - } else { - pBAEntry = &pAd->BATable.BAOriEntry[Idx]; - } - - { - if (ADHOC_ON(pAd)) - ActHeaderInit(pAd, &Frame.Hdr, pInfo->pAddr, - pAd->CurrentAddress, - pAd->CommonCfg.Bssid); - else - ActHeaderInit(pAd, &Frame.Hdr, - pAd->CommonCfg.Bssid, - pAd->CurrentAddress, - pInfo->pAddr); - } - - Frame.Category = CATEGORY_BA; - Frame.Action = ADDBA_REQ; - Frame.BaParm.AMSDUSupported = 0; - Frame.BaParm.BAPolicy = IMMED_BA; - Frame.BaParm.TID = pInfo->TID; - Frame.BaParm.BufSize = pInfo->BaBufSize; - Frame.Token = pInfo->Token; - Frame.TimeOutValue = pInfo->TimeOutValue; - Frame.BaStartSeq.field.FragNum = 0; - Frame.BaStartSeq.field.StartSeq = - pAd->MacTab.Content[pInfo->Wcid].TxSeq[pInfo->TID]; - - *(u16 *) (&Frame.BaParm) = - cpu2le16(*(u16 *) (&Frame.BaParm)); - Frame.TimeOutValue = cpu2le16(Frame.TimeOutValue); - Frame.BaStartSeq.word = cpu2le16(Frame.BaStartSeq.word); - - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_frame_addba_req), &Frame, END_OF_ARGS); - - MiniportMMRequest(pAd, - (MGMT_USE_QUEUE_FLAG | - MapUserPriorityToAccessCategory[pInfo->TID]), - pOutBuffer, FrameLen); - - MlmeFreeMemory(pAd, pOutBuffer); - - DBGPRINT(RT_DEBUG_TRACE, - ("BA - Send ADDBA request. StartSeq = %x, FrameLen = %ld. BufSize = %d\n", - Frame.BaStartSeq.field.StartSeq, FrameLen, - Frame.BaParm.BufSize)); - } -} - -/* - ========================================================================== - Description: - send DELBA and delete BaEntry if any - Parametrs: - Elem - MLME message struct rt_mlme_delba_req - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void MlmeDELBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_mlme_delba_req *pInfo; - u8 *pOutBuffer = NULL; - u8 *pOutBuffer2 = NULL; - int NStatus; - unsigned long Idx; - struct rt_frame_delba_req Frame; - unsigned long FrameLen; - struct rt_frame_bar FrameBar; - - pInfo = (struct rt_mlme_delba_req *)Elem->Msg; - /* must send back DELBA */ - NdisZeroMemory(&Frame, sizeof(struct rt_frame_delba_req)); - DBGPRINT(RT_DEBUG_TRACE, - ("==> MlmeDELBAAction(), Initiator(%d) \n", pInfo->Initiator)); - - if (MlmeDelBAReqSanity(pAd, Elem->Msg, Elem->MsgLen)) { - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_ERROR, - ("BA - MlmeDELBAAction() allocate memory failed 1. \n")); - return; - } - - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - MlmeFreeMemory(pAd, pOutBuffer); - DBGPRINT(RT_DEBUG_ERROR, - ("BA - MlmeDELBAAction() allocate memory failed 2. \n")); - return; - } - /* SEND BAR (Send BAR to refresh peer reordering buffer.) */ - Idx = - pAd->MacTab.Content[pInfo->Wcid].BAOriWcidArray[pInfo->TID]; - - BarHeaderInit(pAd, &FrameBar, - pAd->MacTab.Content[pInfo->Wcid].Addr, - pAd->CurrentAddress); - - FrameBar.StartingSeq.field.FragNum = 0; /* make sure sequence not clear in DEL funciton. */ - FrameBar.StartingSeq.field.StartSeq = pAd->MacTab.Content[pInfo->Wcid].TxSeq[pInfo->TID]; /* make sure sequence not clear in DEL funciton. */ - FrameBar.BarControl.TID = pInfo->TID; /* make sure sequence not clear in DEL funciton. */ - FrameBar.BarControl.ACKPolicy = IMMED_BA; /* make sure sequence not clear in DEL funciton. */ - FrameBar.BarControl.Compressed = 1; /* make sure sequence not clear in DEL funciton. */ - FrameBar.BarControl.MTID = 0; /* make sure sequence not clear in DEL funciton. */ - - MakeOutgoingFrame(pOutBuffer2, &FrameLen, - sizeof(struct rt_frame_bar), &FrameBar, END_OF_ARGS); - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer2); - DBGPRINT(RT_DEBUG_TRACE, - ("BA - MlmeDELBAAction() . Send BAR to refresh peer reordering buffer \n")); - - /* SEND DELBA FRAME */ - FrameLen = 0; - - { - if (ADHOC_ON(pAd)) - ActHeaderInit(pAd, &Frame.Hdr, - pAd->MacTab.Content[pInfo->Wcid]. - Addr, pAd->CurrentAddress, - pAd->CommonCfg.Bssid); - else - ActHeaderInit(pAd, &Frame.Hdr, - pAd->CommonCfg.Bssid, - pAd->CurrentAddress, - pAd->MacTab.Content[pInfo->Wcid]. - Addr); - } - - Frame.Category = CATEGORY_BA; - Frame.Action = DELBA; - Frame.DelbaParm.Initiator = pInfo->Initiator; - Frame.DelbaParm.TID = pInfo->TID; - Frame.ReasonCode = 39; /* Time Out */ - *(u16 *) (&Frame.DelbaParm) = - cpu2le16(*(u16 *) (&Frame.DelbaParm)); - Frame.ReasonCode = cpu2le16(Frame.ReasonCode); - - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_frame_delba_req), &Frame, END_OF_ARGS); - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - DBGPRINT(RT_DEBUG_TRACE, - ("BA - MlmeDELBAAction() . 3 DELBA sent. Initiator(%d)\n", - pInfo->Initiator)); - } -} - -void MlmeQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ -} - -void MlmeDLSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ -} - -void MlmeInvalidAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - /*u8 * pOutBuffer = NULL; */ - /*Return the receiving frame except the MSB of category filed set to 1. 7.3.1.11 */ -} - -void PeerQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ -} - -void PeerBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Action = Elem->Msg[LENGTH_802_11 + 1]; - - switch (Action) { - case ADDBA_REQ: - PeerAddBAReqAction(pAd, Elem); - break; - case ADDBA_RESP: - PeerAddBARspAction(pAd, Elem); - break; - case DELBA: - PeerDelBAAction(pAd, Elem); - break; - } -} - -void PeerPublicAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE) - return; -} - -static void ReservedAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Category; - - if (Elem->MsgLen <= LENGTH_802_11) { - return; - } - - Category = Elem->Msg[LENGTH_802_11]; - DBGPRINT(RT_DEBUG_TRACE, - ("Rcv reserved category(%d) Action Frame\n", Category)); - hex_dump("Reserved Action Frame", &Elem->Msg[0], Elem->MsgLen); -} - -void PeerRMAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - return; -} - -static void respond_ht_information_exchange_action(struct rt_rtmp_adapter *pAd, - struct rt_mlme_queue_elem *Elem) -{ - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen; - struct rt_frame_ht_info HTINFOframe, *pFrame; - u8 *pAddr; - - /* 2. Always send back ADDBA Response */ - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("ACTION - respond_ht_information_exchange_action() allocate memory failed \n")); - return; - } - /* get RA */ - pFrame = (struct rt_frame_ht_info *) & Elem->Msg[0]; - pAddr = pFrame->Hdr.Addr2; - - NdisZeroMemory(&HTINFOframe, sizeof(struct rt_frame_ht_info)); - /* 2-1. Prepare ADDBA Response frame. */ - { - if (ADHOC_ON(pAd)) - ActHeaderInit(pAd, &HTINFOframe.Hdr, pAddr, - pAd->CurrentAddress, - pAd->CommonCfg.Bssid); - else - ActHeaderInit(pAd, &HTINFOframe.Hdr, - pAd->CommonCfg.Bssid, pAd->CurrentAddress, - pAddr); - } - - HTINFOframe.Category = CATEGORY_HT; - HTINFOframe.Action = HT_INFO_EXCHANGE; - HTINFOframe.HT_Info.Request = 0; - HTINFOframe.HT_Info.Forty_MHz_Intolerant = - pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant; - HTINFOframe.HT_Info.STA_Channel_Width = - pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth; - - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_frame_ht_info), &HTINFOframe, END_OF_ARGS); - - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); -} - -void PeerHTAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Action = Elem->Msg[LENGTH_802_11 + 1]; - - if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE) - return; - - switch (Action) { - case NOTIFY_BW_ACTION: - DBGPRINT(RT_DEBUG_TRACE, - ("ACTION - HT Notify Channel bandwidth action----> \n")); - - if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) { - /* Note, this is to patch DIR-1353 AP. When the AP set to Wep, it will use legacy mode. But AP still keeps */ - /* sending BW_Notify Action frame, and cause us to linkup and linkdown. */ - /* In legacy mode, don't need to parse HT action frame. */ - DBGPRINT(RT_DEBUG_TRACE, - ("ACTION -Ignore HT Notify Channel BW when link as legacy mode. BW = %d---> \n", - Elem->Msg[LENGTH_802_11 + 2])); - break; - } - - if (Elem->Msg[LENGTH_802_11 + 2] == 0) /* 7.4.8.2. if value is 1, keep the same as supported channel bandwidth. */ - pAd->MacTab.Content[Elem->Wcid].HTPhyMode.field.BW = 0; - - break; - case SMPS_ACTION: - /* 7.3.1.25 */ - DBGPRINT(RT_DEBUG_TRACE, ("ACTION - SMPS action----> \n")); - if (((Elem->Msg[LENGTH_802_11 + 2] & 0x1) == 0)) { - pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_ENABLE; - } else if (((Elem->Msg[LENGTH_802_11 + 2] & 0x2) == 0)) { - pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_STATIC; - } else { - pAd->MacTab.Content[Elem->Wcid].MmpsMode = MMPS_DYNAMIC; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("Aid(%d) MIMO PS = %d\n", Elem->Wcid, - pAd->MacTab.Content[Elem->Wcid].MmpsMode)); - /* rt2860c : add something for smps change. */ - break; - - case SETPCO_ACTION: - break; - case MIMO_CHA_MEASURE_ACTION: - break; - case HT_INFO_EXCHANGE: - { - struct rt_ht_information_octet *pHT_info; - - pHT_info = - (struct rt_ht_information_octet *) & Elem->Msg[LENGTH_802_11 + - 2]; - /* 7.4.8.10 */ - DBGPRINT(RT_DEBUG_TRACE, - ("ACTION - HT Information Exchange action----> \n")); - if (pHT_info->Request) { - respond_ht_information_exchange_action(pAd, - Elem); - } - } - break; - } -} - -/* - ========================================================================== - Description: - Retry sending ADDBA Reqest. - - IRQL = DISPATCH_LEVEL - - Parametrs: - p8023Header: if this is already 802.3 format, p8023Header is NULL - - Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere. - FALSE , then continue indicaterx at this moment. - ========================================================================== - */ -void ORIBATimerTimeout(struct rt_rtmp_adapter *pAd) -{ - struct rt_mac_table_entry *pEntry; - int i, total; - u8 TID; - - total = pAd->MacTab.Size * NUM_OF_TID; - - for (i = 1; ((i < MAX_LEN_OF_BA_ORI_TABLE) && (total > 0)); i++) { - if (pAd->BATable.BAOriEntry[i].ORI_BA_Status == Originator_Done) { - pEntry = - &pAd->MacTab.Content[pAd->BATable.BAOriEntry[i]. - Wcid]; - TID = pAd->BATable.BAOriEntry[i].TID; - - ASSERT(pAd->BATable.BAOriEntry[i].Wcid < - MAX_LEN_OF_MAC_TABLE); - } - total--; - } -} - -void SendRefreshBAR(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry) -{ - struct rt_frame_bar FrameBar; - unsigned long FrameLen; - int NStatus; - u8 *pOutBuffer = NULL; - u16 Sequence; - u8 i, TID; - u16 idx; - struct rt_ba_ori_entry *pBAEntry; - - for (i = 0; i < NUM_OF_TID; i++) { - idx = pEntry->BAOriWcidArray[i]; - if (idx == 0) { - continue; - } - pBAEntry = &pAd->BATable.BAOriEntry[idx]; - - if (pBAEntry->ORI_BA_Status == Originator_Done) { - TID = pBAEntry->TID; - - ASSERT(pBAEntry->Wcid < MAX_LEN_OF_MAC_TABLE); - - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_ERROR, - ("BA - MlmeADDBAAction() allocate memory failed \n")); - return; - } - - Sequence = pEntry->TxSeq[TID]; - - BarHeaderInit(pAd, &FrameBar, pEntry->Addr, - pAd->CurrentAddress); - - FrameBar.StartingSeq.field.FragNum = 0; /* make sure sequence not clear in DEL function. */ - FrameBar.StartingSeq.field.StartSeq = Sequence; /* make sure sequence not clear in DEL funciton. */ - FrameBar.BarControl.TID = TID; /* make sure sequence not clear in DEL funciton. */ - - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_frame_bar), &FrameBar, - END_OF_ARGS); - /*if (!(CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_RALINK_CHIPSET))) */ - if (1) /* Now we always send BAR. */ - { - /*MiniportMMRequestUnlock(pAd, 0, pOutBuffer, FrameLen); */ - MiniportMMRequest(pAd, - (MGMT_USE_QUEUE_FLAG | - MapUserPriorityToAccessCategory - [TID]), pOutBuffer, - FrameLen); - - } - MlmeFreeMemory(pAd, pOutBuffer); - } - } -} - -void ActHeaderInit(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 * pHdr80211, - u8 *Addr1, u8 *Addr2, u8 *Addr3) -{ - NdisZeroMemory(pHdr80211, sizeof(struct rt_header_802_11)); - pHdr80211->FC.Type = BTYPE_MGMT; - pHdr80211->FC.SubType = SUBTYPE_ACTION; - - COPY_MAC_ADDR(pHdr80211->Addr1, Addr1); - COPY_MAC_ADDR(pHdr80211->Addr2, Addr2); - COPY_MAC_ADDR(pHdr80211->Addr3, Addr3); -} - -void BarHeaderInit(struct rt_rtmp_adapter *pAd, - struct rt_frame_bar * pCntlBar, u8 *pDA, u8 *pSA) -{ - NdisZeroMemory(pCntlBar, sizeof(struct rt_frame_bar)); - pCntlBar->FC.Type = BTYPE_CNTL; - pCntlBar->FC.SubType = SUBTYPE_BLOCK_ACK_REQ; - pCntlBar->BarControl.MTID = 0; - pCntlBar->BarControl.Compressed = 1; - pCntlBar->BarControl.ACKPolicy = 0; - - pCntlBar->Duration = - 16 + RTMPCalcDuration(pAd, RATE_1, sizeof(struct rt_frame_ba)); - - COPY_MAC_ADDR(pCntlBar->Addr1, pDA); - COPY_MAC_ADDR(pCntlBar->Addr2, pSA); -} - -/* - ========================================================================== - Description: - Insert Category and action code into the action frame. - - Parametrs: - 1. frame buffer pointer. - 2. frame length. - 3. category code of the frame. - 4. action code of the frame. - - Return : None. - ========================================================================== - */ -void InsertActField(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, u8 Category, u8 ActCode) -{ - unsigned long TempLen; - - MakeOutgoingFrame(pFrameBuf, &TempLen, - 1, &Category, 1, &ActCode, END_OF_ARGS); - - *pFrameLen = *pFrameLen + TempLen; - - return; -} diff --git a/trunk/drivers/staging/rt2860/common/action.h b/trunk/drivers/staging/rt2860/common/action.h deleted file mode 100644 index 974f8b84039f..000000000000 --- a/trunk/drivers/staging/rt2860/common/action.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - aironet.h - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs - Paul Lin 04-06-15 Initial -*/ - -#ifndef __ACTION_H__ -#define __ACTION_H__ - -struct PACKED rt_ht_information_octet { - u8 Request:1; - u8 Forty_MHz_Intolerant:1; - u8 STA_Channel_Width:1; - u8 Reserved:5; -}; - -struct PACKED rt_frame_ht_info { - struct rt_header_802_11 Hdr; - u8 Category; - u8 Action; - struct rt_ht_information_octet HT_Info; -}; - -#endif /* __ACTION_H__ */ diff --git a/trunk/drivers/staging/rt2860/common/ba_action.c b/trunk/drivers/staging/rt2860/common/ba_action.c deleted file mode 100644 index 133bc1b87d2c..000000000000 --- a/trunk/drivers/staging/rt2860/common/ba_action.c +++ /dev/null @@ -1,1650 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - */ - -#include "../rt_config.h" -#include - -#define BA_ORI_INIT_SEQ (pEntry->TxSeq[TID]) /*1 // initial sequence number of BA session */ - -#define ORI_SESSION_MAX_RETRY 8 -#define ORI_BA_SESSION_TIMEOUT (2000) /* ms */ -#define REC_BA_SESSION_IDLE_TIMEOUT (1000) /* ms */ - -#define REORDERING_PACKET_TIMEOUT ((100 * OS_HZ)/1000) /* system ticks -- 100 ms */ -#define MAX_REORDERING_PACKET_TIMEOUT ((3000 * OS_HZ)/1000) /* system ticks -- 100 ms */ - -#define RESET_RCV_SEQ (0xFFFF) - -static void ba_mpdu_blk_free(struct rt_rtmp_adapter *pAd, - struct reordering_mpdu *mpdu_blk); - -struct rt_ba_ori_entry *BATableAllocOriEntry(struct rt_rtmp_adapter *pAd, u16 * Idx); - -struct rt_ba_rec_entry *BATableAllocRecEntry(struct rt_rtmp_adapter *pAd, u16 * Idx); - -void BAOriSessionSetupTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, - void *SystemSpecific3); - -void BARecSessionIdleTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, - void *SystemSpecific3); - -BUILD_TIMER_FUNCTION(BAOriSessionSetupTimeout); -BUILD_TIMER_FUNCTION(BARecSessionIdleTimeout); - -#define ANNOUNCE_REORDERING_PACKET(_pAd, _mpdu_blk) \ - Announce_Reordering_Packet(_pAd, _mpdu_blk); - -void BA_MaxWinSizeReasign(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntryPeer, u8 * pWinSize) -{ - u8 MaxSize; - - if (pAd->MACVersion >= RALINK_2883_VERSION) /* 3*3 */ - { - if (pAd->MACVersion >= RALINK_3070_VERSION) { - if (pEntryPeer->WepStatus != - Ndis802_11EncryptionDisabled) - MaxSize = 7; /* for non-open mode */ - else - MaxSize = 13; - } else - MaxSize = 31; - } else if (pAd->MACVersion >= RALINK_2880E_VERSION) /* 2880 e */ - { - if (pEntryPeer->WepStatus != Ndis802_11EncryptionDisabled) - MaxSize = 7; /* for non-open mode */ - else - MaxSize = 13; - } else - MaxSize = 7; - - DBGPRINT(RT_DEBUG_TRACE, ("ba> Win Size = %d, Max Size = %d\n", - *pWinSize, MaxSize)); - - if ((*pWinSize) > MaxSize) { - DBGPRINT(RT_DEBUG_TRACE, - ("ba> reassign max win size from %d to %d\n", - *pWinSize, MaxSize)); - - *pWinSize = MaxSize; - } -} - -void Announce_Reordering_Packet(struct rt_rtmp_adapter *pAd, - IN struct reordering_mpdu *mpdu) -{ - void *pPacket; - - pPacket = mpdu->pPacket; - - if (mpdu->bAMSDU) { - ASSERT(0); - BA_Reorder_AMSDU_Announce(pAd, pPacket); - } else { - /* */ - /* pass this 802.3 packet to upper layer or forward this packet to WM directly */ - /* */ - - ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket, - RTMP_GET_PACKET_IF(pPacket)); - } -} - -/* - * Insert a reordering mpdu into sorted linked list by sequence no. - */ -BOOLEAN ba_reordering_mpdu_insertsorted(struct reordering_list *list, - struct reordering_mpdu *mpdu) -{ - - struct reordering_mpdu **ppScan = &list->next; - - while (*ppScan != NULL) { - if (SEQ_SMALLER((*ppScan)->Sequence, mpdu->Sequence, MAXSEQ)) { - ppScan = &(*ppScan)->next; - } else if ((*ppScan)->Sequence == mpdu->Sequence) { - /* give up this duplicated frame */ - return (FALSE); - } else { - /* find position */ - break; - } - } - - mpdu->next = *ppScan; - *ppScan = mpdu; - list->qlen++; - return TRUE; -} - -/* - * caller lock critical section if necessary - */ -static inline void ba_enqueue(struct reordering_list *list, - struct reordering_mpdu *mpdu_blk) -{ - list->qlen++; - mpdu_blk->next = list->next; - list->next = mpdu_blk; -} - -/* - * caller lock critical section if necessary - */ -static inline struct reordering_mpdu *ba_dequeue(struct reordering_list *list) -{ - struct reordering_mpdu *mpdu_blk = NULL; - - ASSERT(list); - - if (list->qlen) { - list->qlen--; - mpdu_blk = list->next; - if (mpdu_blk) { - list->next = mpdu_blk->next; - mpdu_blk->next = NULL; - } - } - return mpdu_blk; -} - -static inline struct reordering_mpdu *ba_reordering_mpdu_dequeue(struct - reordering_list - *list) -{ - return (ba_dequeue(list)); -} - -static inline struct reordering_mpdu *ba_reordering_mpdu_probe(struct - reordering_list - *list) -{ - ASSERT(list); - - return (list->next); -} - -/* - * free all resource for reordering mechanism - */ -void ba_reordering_resource_release(struct rt_rtmp_adapter *pAd) -{ - struct rt_ba_table *Tab; - struct rt_ba_rec_entry *pBAEntry; - struct reordering_mpdu *mpdu_blk; - int i; - - Tab = &pAd->BATable; - - /* I. release all pending reordering packet */ - NdisAcquireSpinLock(&pAd->BATabLock); - for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++) { - pBAEntry = &Tab->BARecEntry[i]; - if (pBAEntry->REC_BA_Status != Recipient_NONE) { - while ((mpdu_blk = - ba_reordering_mpdu_dequeue(&pBAEntry->list))) { - ASSERT(mpdu_blk->pPacket); - RELEASE_NDIS_PACKET(pAd, mpdu_blk->pPacket, - NDIS_STATUS_FAILURE); - ba_mpdu_blk_free(pAd, mpdu_blk); - } - } - } - NdisReleaseSpinLock(&pAd->BATabLock); - - ASSERT(pBAEntry->list.qlen == 0); - /* II. free memory of reordering mpdu table */ - NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); - os_free_mem(pAd, pAd->mpdu_blk_pool.mem); - NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); -} - -/* - * Allocate all resource for reordering mechanism - */ -BOOLEAN ba_reordering_resource_init(struct rt_rtmp_adapter *pAd, int num) -{ - int i; - u8 *mem; - struct reordering_mpdu *mpdu_blk; - struct reordering_list *freelist; - - /* allocate spinlock */ - NdisAllocateSpinLock(&pAd->mpdu_blk_pool.lock); - - /* initialize freelist */ - freelist = &pAd->mpdu_blk_pool.freelist; - freelist->next = NULL; - freelist->qlen = 0; - - DBGPRINT(RT_DEBUG_TRACE, - ("Allocate %d memory for BA reordering\n", - (u32)(num * sizeof(struct reordering_mpdu)))); - - /* allocate number of mpdu_blk memory */ - os_alloc_mem(pAd, (u8 **) & mem, - (num * sizeof(struct reordering_mpdu))); - - pAd->mpdu_blk_pool.mem = mem; - - if (mem == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("Can't Allocate Memory for BA Reordering\n")); - return (FALSE); - } - - /* build mpdu_blk free list */ - for (i = 0; i < num; i++) { - /* get mpdu_blk */ - mpdu_blk = (struct reordering_mpdu *)mem; - /* initial mpdu_blk */ - NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu)); - /* next mpdu_blk */ - mem += sizeof(struct reordering_mpdu); - /* insert mpdu_blk into freelist */ - ba_enqueue(freelist, mpdu_blk); - } - - return (TRUE); -} - -/*static int blk_count=0; // sample take off, no use */ - -static struct reordering_mpdu *ba_mpdu_blk_alloc(struct rt_rtmp_adapter *pAd) -{ - struct reordering_mpdu *mpdu_blk; - - NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); - mpdu_blk = ba_dequeue(&pAd->mpdu_blk_pool.freelist); - if (mpdu_blk) { -/* blk_count++; */ - /* reset mpdu_blk */ - NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu)); - } - NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); - return mpdu_blk; -} - -static void ba_mpdu_blk_free(struct rt_rtmp_adapter *pAd, - struct reordering_mpdu *mpdu_blk) -{ - ASSERT(mpdu_blk); - - NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); -/* blk_count--; */ - ba_enqueue(&pAd->mpdu_blk_pool.freelist, mpdu_blk); - NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); -} - -static u16 ba_indicate_reordering_mpdus_in_order(struct rt_rtmp_adapter *pAd, - struct rt_ba_rec_entry *pBAEntry, - u16 StartSeq) -{ - struct reordering_mpdu *mpdu_blk; - u16 LastIndSeq = RESET_RCV_SEQ; - - NdisAcquireSpinLock(&pBAEntry->RxReRingLock); - - while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list))) { - /* find in-order frame */ - if (!SEQ_STEPONE(mpdu_blk->Sequence, StartSeq, MAXSEQ)) { - break; - } - /* dequeue in-order frame from reodering list */ - mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list); - /* pass this frame up */ - ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk); - /* move to next sequence */ - StartSeq = mpdu_blk->Sequence; - LastIndSeq = StartSeq; - /* free mpdu_blk */ - ba_mpdu_blk_free(pAd, mpdu_blk); - } - - NdisReleaseSpinLock(&pBAEntry->RxReRingLock); - - /* update last indicated sequence */ - return LastIndSeq; -} - -static void ba_indicate_reordering_mpdus_le_seq(struct rt_rtmp_adapter *pAd, - struct rt_ba_rec_entry *pBAEntry, - u16 Sequence) -{ - struct reordering_mpdu *mpdu_blk; - - NdisAcquireSpinLock(&pBAEntry->RxReRingLock); - while ((mpdu_blk = ba_reordering_mpdu_probe(&pBAEntry->list))) { - /* find in-order frame */ - if ((mpdu_blk->Sequence == Sequence) - || SEQ_SMALLER(mpdu_blk->Sequence, Sequence, MAXSEQ)) { - /* dequeue in-order frame from reodering list */ - mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list); - /* pass this frame up */ - ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk); - /* free mpdu_blk */ - ba_mpdu_blk_free(pAd, mpdu_blk); - } else { - break; - } - } - NdisReleaseSpinLock(&pBAEntry->RxReRingLock); -} - -static void ba_refresh_reordering_mpdus(struct rt_rtmp_adapter *pAd, - struct rt_ba_rec_entry *pBAEntry) -{ - struct reordering_mpdu *mpdu_blk; - - NdisAcquireSpinLock(&pBAEntry->RxReRingLock); - - /* dequeue in-order frame from reodering list */ - while ((mpdu_blk = ba_reordering_mpdu_dequeue(&pBAEntry->list))) { - /* pass this frame up */ - ANNOUNCE_REORDERING_PACKET(pAd, mpdu_blk); - - pBAEntry->LastIndSeq = mpdu_blk->Sequence; - ba_mpdu_blk_free(pAd, mpdu_blk); - - /* update last indicated sequence */ - } - ASSERT(pBAEntry->list.qlen == 0); - pBAEntry->LastIndSeq = RESET_RCV_SEQ; - NdisReleaseSpinLock(&pBAEntry->RxReRingLock); -} - -/*static */ -void ba_flush_reordering_timeout_mpdus(struct rt_rtmp_adapter *pAd, - struct rt_ba_rec_entry *pBAEntry, - unsigned long Now32) -{ - u16 Sequence; - -/* if ((RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+REORDERING_PACKET_TIMEOUT)) && */ -/* (pBAEntry->list.qlen > ((pBAEntry->BAWinSize*7)/8))) //|| */ -/* (RTMP_TIME_AFTER((unsigned long)Now32, (unsigned long)(pBAEntry->LastIndSeqAtTimer+(10*REORDERING_PACKET_TIMEOUT))) && */ -/* (pBAEntry->list.qlen > (pBAEntry->BAWinSize/8))) */ - if (RTMP_TIME_AFTER - ((unsigned long)Now32, - (unsigned long)(pBAEntry->LastIndSeqAtTimer + - (MAX_REORDERING_PACKET_TIMEOUT / 6))) - && (pBAEntry->list.qlen > 1) - ) { - DBGPRINT(RT_DEBUG_TRACE, - ("timeout[%d] (%08lx-%08lx = %d > %d): %x, flush all!\n ", - pBAEntry->list.qlen, Now32, - (pBAEntry->LastIndSeqAtTimer), - (int)((long)Now32 - - (long)(pBAEntry->LastIndSeqAtTimer)), - MAX_REORDERING_PACKET_TIMEOUT, pBAEntry->LastIndSeq)); - ba_refresh_reordering_mpdus(pAd, pBAEntry); - pBAEntry->LastIndSeqAtTimer = Now32; - } else - if (RTMP_TIME_AFTER - ((unsigned long)Now32, - (unsigned long)(pBAEntry->LastIndSeqAtTimer + - (REORDERING_PACKET_TIMEOUT))) - && (pBAEntry->list.qlen > 0) - ) { - /* */ - /* force LastIndSeq to shift to LastIndSeq+1 */ - /* */ - Sequence = (pBAEntry->LastIndSeq + 1) & MAXSEQ; - ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence); - pBAEntry->LastIndSeqAtTimer = Now32; - pBAEntry->LastIndSeq = Sequence; - /* */ - /* indicate in-order mpdus */ - /* */ - Sequence = - ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, - Sequence); - if (Sequence != RESET_RCV_SEQ) { - pBAEntry->LastIndSeq = Sequence; - } - - DBGPRINT(RT_DEBUG_OFF, - ("%x, flush one!\n", pBAEntry->LastIndSeq)); - - } -} - -/* - * generate ADDBA request to - * set up BA agreement - */ -void BAOriSessionSetUp(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 TID, - u16 TimeOut, - unsigned long DelayTime, IN BOOLEAN isForced) -{ - /*struct rt_mlme_addba_req AddbaReq; */ - struct rt_ba_ori_entry *pBAEntry = NULL; - u16 Idx; - BOOLEAN Cancelled; - - if ((pAd->CommonCfg.BACapability.field.AutoBA != TRUE) - && (isForced == FALSE)) - return; - - /* if this entry is limited to use legacy tx mode, it doesn't generate BA. */ - if (RTMPStaFixedTxMode(pAd, pEntry) != FIXED_TXMODE_HT) - return; - - if ((pEntry->BADeclineBitmap & (1 << TID)) && (isForced == FALSE)) { - /* try again after 3 secs */ - DelayTime = 3000; -/* DBGPRINT(RT_DEBUG_TRACE, ("DeCline BA from Peer\n")); */ -/* return; */ - } - - Idx = pEntry->BAOriWcidArray[TID]; - if (Idx == 0) { - /* allocate a BA session */ - pBAEntry = BATableAllocOriEntry(pAd, &Idx); - if (pBAEntry == NULL) { - DBGPRINT(RT_DEBUG_TRACE, - ("ADDBA - MlmeADDBAAction() allocate BA session failed \n")); - return; - } - } else { - pBAEntry = &pAd->BATable.BAOriEntry[Idx]; - } - - if (pBAEntry->ORI_BA_Status >= Originator_WaitRes) { - return; - } - - pEntry->BAOriWcidArray[TID] = Idx; - - /* Initialize BA session */ - pBAEntry->ORI_BA_Status = Originator_WaitRes; - pBAEntry->Wcid = pEntry->Aid; - pBAEntry->BAWinSize = pAd->CommonCfg.BACapability.field.RxBAWinLimit; - pBAEntry->Sequence = BA_ORI_INIT_SEQ; - pBAEntry->Token = 1; /* (2008-01-21) Jan Lee recommends it - this token can't be 0 */ - pBAEntry->TID = TID; - pBAEntry->TimeOutValue = TimeOut; - pBAEntry->pAdapter = pAd; - - if (!(pEntry->TXBAbitmap & (1 << TID))) { - RTMPInitTimer(pAd, &pBAEntry->ORIBATimer, - GET_TIMER_FUNCTION(BAOriSessionSetupTimeout), - pBAEntry, FALSE); - } else - RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled); - - /* set timer to send ADDBA request */ - RTMPSetTimer(&pBAEntry->ORIBATimer, DelayTime); -} - -void BAOriSessionAdd(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_frame_addba_rsp * pFrame) -{ - struct rt_ba_ori_entry *pBAEntry = NULL; - BOOLEAN Cancelled; - u8 TID; - u16 Idx; - u8 *pOutBuffer2 = NULL; - int NStatus; - unsigned long FrameLen; - struct rt_frame_bar FrameBar; - - TID = pFrame->BaParm.TID; - Idx = pEntry->BAOriWcidArray[TID]; - pBAEntry = &pAd->BATable.BAOriEntry[Idx]; - - /* Start fill in parameters. */ - if ((Idx != 0) && (pBAEntry->TID == TID) - && (pBAEntry->ORI_BA_Status == Originator_WaitRes)) { - pBAEntry->BAWinSize = - min(pBAEntry->BAWinSize, ((u8)pFrame->BaParm.BufSize)); - BA_MaxWinSizeReasign(pAd, pEntry, &pBAEntry->BAWinSize); - - pBAEntry->TimeOutValue = pFrame->TimeOutValue; - pBAEntry->ORI_BA_Status = Originator_Done; - pAd->BATable.numDoneOriginator++; - - /* reset sequence number */ - pBAEntry->Sequence = BA_ORI_INIT_SEQ; - /* Set Bitmap flag. */ - pEntry->TXBAbitmap |= (1 << TID); - RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled); - - pBAEntry->ORIBATimer.TimerValue = 0; /*pFrame->TimeOutValue; */ - - DBGPRINT(RT_DEBUG_TRACE, - ("%s : TXBAbitmap = %x, BAWinSize = %d, TimeOut = %ld\n", - __func__, pEntry->TXBAbitmap, pBAEntry->BAWinSize, - pBAEntry->ORIBATimer.TimerValue)); - - /* SEND BAR ; */ - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer2); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("BA - BAOriSessionAdd() allocate memory failed \n")); - return; - } - - BarHeaderInit(pAd, &FrameBar, - pAd->MacTab.Content[pBAEntry->Wcid].Addr, - pAd->CurrentAddress); - - FrameBar.StartingSeq.field.FragNum = 0; /* make sure sequence not clear in DEL function. */ - FrameBar.StartingSeq.field.StartSeq = pBAEntry->Sequence; /* make sure sequence not clear in DEL funciton. */ - FrameBar.BarControl.TID = pBAEntry->TID; /* make sure sequence not clear in DEL funciton. */ - MakeOutgoingFrame(pOutBuffer2, &FrameLen, - sizeof(struct rt_frame_bar), &FrameBar, END_OF_ARGS); - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer2, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer2); - - if (pBAEntry->ORIBATimer.TimerValue) - RTMPSetTimer(&pBAEntry->ORIBATimer, pBAEntry->ORIBATimer.TimerValue); /* in mSec */ - } -} - -BOOLEAN BARecSessionAdd(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_frame_addba_req * pFrame) -{ - struct rt_ba_rec_entry *pBAEntry = NULL; - BOOLEAN Status = TRUE; - BOOLEAN Cancelled; - u16 Idx; - u8 TID; - u8 BAWinSize; - /*u32 Value; */ - /*u32 offset; */ - - ASSERT(pEntry); - - /* find TID */ - TID = pFrame->BaParm.TID; - - BAWinSize = - min(((u8)pFrame->BaParm.BufSize), - (u8)pAd->CommonCfg.BACapability.field.RxBAWinLimit); - - /* Intel patch */ - if (BAWinSize == 0) { - BAWinSize = 64; - } - - Idx = pEntry->BARecWcidArray[TID]; - - if (Idx == 0) { - pBAEntry = BATableAllocRecEntry(pAd, &Idx); - } else { - pBAEntry = &pAd->BATable.BARecEntry[Idx]; - /* flush all pending reordering mpdus */ - ba_refresh_reordering_mpdus(pAd, pBAEntry); - } - - DBGPRINT(RT_DEBUG_TRACE, - ("%s(%ld): Idx = %d, BAWinSize(req %d) = %d\n", __func__, - pAd->BATable.numAsRecipient, Idx, pFrame->BaParm.BufSize, - BAWinSize)); - - /* Start fill in parameters. */ - if (pBAEntry != NULL) { - ASSERT(pBAEntry->list.qlen == 0); - - pBAEntry->REC_BA_Status = Recipient_HandleRes; - pBAEntry->BAWinSize = BAWinSize; - pBAEntry->Wcid = pEntry->Aid; - pBAEntry->TID = TID; - pBAEntry->TimeOutValue = pFrame->TimeOutValue; - pBAEntry->REC_BA_Status = Recipient_Accept; - /* initial sequence number */ - pBAEntry->LastIndSeq = RESET_RCV_SEQ; /*pFrame->BaStartSeq.field.StartSeq; */ - - DBGPRINT(RT_DEBUG_OFF, - ("Start Seq = %08x\n", - pFrame->BaStartSeq.field.StartSeq)); - - if (pEntry->RXBAbitmap & (1 << TID)) { - RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled); - } else { - RTMPInitTimer(pAd, &pBAEntry->RECBATimer, - GET_TIMER_FUNCTION - (BARecSessionIdleTimeout), pBAEntry, - TRUE); - } - - /* Set Bitmap flag. */ - pEntry->RXBAbitmap |= (1 << TID); - pEntry->BARecWcidArray[TID] = Idx; - - pEntry->BADeclineBitmap &= ~(1 << TID); - - /* Set BA session mask in WCID table. */ - RTMP_ADD_BA_SESSION_TO_ASIC(pAd, pEntry->Aid, TID); - - DBGPRINT(RT_DEBUG_TRACE, - ("MACEntry[%d]RXBAbitmap = 0x%x. BARecWcidArray=%d\n", - pEntry->Aid, pEntry->RXBAbitmap, - pEntry->BARecWcidArray[TID])); - } else { - Status = FALSE; - DBGPRINT(RT_DEBUG_TRACE, - ("Can't Accept ADDBA for %pM TID = %d\n", - pEntry->Addr, TID)); - } - return (Status); -} - -struct rt_ba_rec_entry *BATableAllocRecEntry(struct rt_rtmp_adapter *pAd, u16 * Idx) -{ - int i; - struct rt_ba_rec_entry *pBAEntry = NULL; - - NdisAcquireSpinLock(&pAd->BATabLock); - - if (pAd->BATable.numAsRecipient >= MAX_BARECI_SESSION) { - DBGPRINT(RT_DEBUG_OFF, ("BA Recipeint Session (%ld) > %d\n", - pAd->BATable.numAsRecipient, - MAX_BARECI_SESSION)); - goto done; - } - /* reserve idx 0 to identify BAWcidArray[TID] as empty */ - for (i = 1; i < MAX_LEN_OF_BA_REC_TABLE; i++) { - pBAEntry = &pAd->BATable.BARecEntry[i]; - if ((pBAEntry->REC_BA_Status == Recipient_NONE)) { - /* get one */ - pAd->BATable.numAsRecipient++; - pBAEntry->REC_BA_Status = Recipient_USED; - *Idx = i; - break; - } - } - -done: - NdisReleaseSpinLock(&pAd->BATabLock); - return pBAEntry; -} - -struct rt_ba_ori_entry *BATableAllocOriEntry(struct rt_rtmp_adapter *pAd, u16 * Idx) -{ - int i; - struct rt_ba_ori_entry *pBAEntry = NULL; - - NdisAcquireSpinLock(&pAd->BATabLock); - - if (pAd->BATable.numAsOriginator >= (MAX_LEN_OF_BA_ORI_TABLE)) { - goto done; - } - /* reserve idx 0 to identify BAWcidArray[TID] as empty */ - for (i = 1; i < MAX_LEN_OF_BA_ORI_TABLE; i++) { - pBAEntry = &pAd->BATable.BAOriEntry[i]; - if ((pBAEntry->ORI_BA_Status == Originator_NONE)) { - /* get one */ - pAd->BATable.numAsOriginator++; - pBAEntry->ORI_BA_Status = Originator_USED; - pBAEntry->pAdapter = pAd; - *Idx = i; - break; - } - } - -done: - NdisReleaseSpinLock(&pAd->BATabLock); - return pBAEntry; -} - -void BATableFreeOriEntry(struct rt_rtmp_adapter *pAd, unsigned long Idx) -{ - struct rt_ba_ori_entry *pBAEntry = NULL; - struct rt_mac_table_entry *pEntry; - - if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE)) - return; - - pBAEntry = &pAd->BATable.BAOriEntry[Idx]; - - if (pBAEntry->ORI_BA_Status != Originator_NONE) { - pEntry = &pAd->MacTab.Content[pBAEntry->Wcid]; - pEntry->BAOriWcidArray[pBAEntry->TID] = 0; - - NdisAcquireSpinLock(&pAd->BATabLock); - if (pBAEntry->ORI_BA_Status == Originator_Done) { - pAd->BATable.numDoneOriginator -= 1; - pEntry->TXBAbitmap &= (~(1 << (pBAEntry->TID))); - DBGPRINT(RT_DEBUG_TRACE, - ("BATableFreeOriEntry numAsOriginator= %ld\n", - pAd->BATable.numAsRecipient)); - /* Erase Bitmap flag. */ - } - - ASSERT(pAd->BATable.numAsOriginator != 0); - - pAd->BATable.numAsOriginator -= 1; - - pBAEntry->ORI_BA_Status = Originator_NONE; - pBAEntry->Token = 0; - NdisReleaseSpinLock(&pAd->BATabLock); - } -} - -void BATableFreeRecEntry(struct rt_rtmp_adapter *pAd, unsigned long Idx) -{ - struct rt_ba_rec_entry *pBAEntry = NULL; - struct rt_mac_table_entry *pEntry; - - if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_REC_TABLE)) - return; - - pBAEntry = &pAd->BATable.BARecEntry[Idx]; - - if (pBAEntry->REC_BA_Status != Recipient_NONE) { - pEntry = &pAd->MacTab.Content[pBAEntry->Wcid]; - pEntry->BARecWcidArray[pBAEntry->TID] = 0; - - NdisAcquireSpinLock(&pAd->BATabLock); - - ASSERT(pAd->BATable.numAsRecipient != 0); - - pAd->BATable.numAsRecipient -= 1; - - pBAEntry->REC_BA_Status = Recipient_NONE; - NdisReleaseSpinLock(&pAd->BATabLock); - } -} - -void BAOriSessionTearDown(struct rt_rtmp_adapter *pAd, - u8 Wcid, - u8 TID, - IN BOOLEAN bPassive, IN BOOLEAN bForceSend) -{ - unsigned long Idx = 0; - struct rt_ba_ori_entry *pBAEntry; - BOOLEAN Cancelled; - - if (Wcid >= MAX_LEN_OF_MAC_TABLE) { - return; - } - /* */ - /* Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID). */ - /* */ - Idx = pAd->MacTab.Content[Wcid].BAOriWcidArray[TID]; - if ((Idx == 0) || (Idx >= MAX_LEN_OF_BA_ORI_TABLE)) { - if (bForceSend == TRUE) { - /* force send specified TID DelBA */ - struct rt_mlme_delba_req DelbaReq; - struct rt_mlme_queue_elem *Elem = - kmalloc(sizeof(struct rt_mlme_queue_elem), - MEM_ALLOC_FLAG); - if (Elem != NULL) { - NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); - NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem)); - - COPY_MAC_ADDR(DelbaReq.Addr, - pAd->MacTab.Content[Wcid].Addr); - DelbaReq.Wcid = Wcid; - DelbaReq.TID = TID; - DelbaReq.Initiator = ORIGINATOR; - Elem->MsgLen = sizeof(DelbaReq); - NdisMoveMemory(Elem->Msg, &DelbaReq, - sizeof(DelbaReq)); - MlmeDELBAAction(pAd, Elem); - kfree(Elem); - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("%s(bForceSend):alloc memory failed!\n", - __func__)); - } - } - - return; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("%s===>Wcid=%d.TID=%d \n", __func__, Wcid, TID)); - - pBAEntry = &pAd->BATable.BAOriEntry[Idx]; - DBGPRINT(RT_DEBUG_TRACE, - ("\t===>Idx = %ld, Wcid=%d.TID=%d, ORI_BA_Status = %d \n", Idx, - Wcid, TID, pBAEntry->ORI_BA_Status)); - /* */ - /* Prepare DelBA action frame and send to the peer. */ - /* */ - if ((bPassive == FALSE) && (TID == pBAEntry->TID) - && (pBAEntry->ORI_BA_Status == Originator_Done)) { - struct rt_mlme_delba_req DelbaReq; - struct rt_mlme_queue_elem *Elem = - kmalloc(sizeof(struct rt_mlme_queue_elem), - MEM_ALLOC_FLAG); - if (Elem != NULL) { - NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); - NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem)); - - COPY_MAC_ADDR(DelbaReq.Addr, - pAd->MacTab.Content[Wcid].Addr); - DelbaReq.Wcid = Wcid; - DelbaReq.TID = pBAEntry->TID; - DelbaReq.Initiator = ORIGINATOR; - Elem->MsgLen = sizeof(DelbaReq); - NdisMoveMemory(Elem->Msg, &DelbaReq, sizeof(DelbaReq)); - MlmeDELBAAction(pAd, Elem); - kfree(Elem); - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("%s():alloc memory failed!\n", __func__)); - return; - } - } - RTMPCancelTimer(&pBAEntry->ORIBATimer, &Cancelled); - BATableFreeOriEntry(pAd, Idx); - - if (bPassive) { - /*BAOriSessionSetUp(pAd, &pAd->MacTab.Content[Wcid], TID, 0, 10000, TRUE); */ - } -} - -void BARecSessionTearDown(struct rt_rtmp_adapter *pAd, - u8 Wcid, u8 TID, IN BOOLEAN bPassive) -{ - unsigned long Idx = 0; - struct rt_ba_rec_entry *pBAEntry; - - if (Wcid >= MAX_LEN_OF_MAC_TABLE) { - return; - } - /* */ - /* Locate corresponding BA Originator Entry in BA Table with the (pAddr,TID). */ - /* */ - Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; - if (Idx == 0) - return; - - DBGPRINT(RT_DEBUG_TRACE, - ("%s===>Wcid=%d.TID=%d \n", __func__, Wcid, TID)); - - pBAEntry = &pAd->BATable.BARecEntry[Idx]; - DBGPRINT(RT_DEBUG_TRACE, - ("\t===>Idx = %ld, Wcid=%d.TID=%d, REC_BA_Status = %d \n", Idx, - Wcid, TID, pBAEntry->REC_BA_Status)); - /* */ - /* Prepare DelBA action frame and send to the peer. */ - /* */ - if ((TID == pBAEntry->TID) - && (pBAEntry->REC_BA_Status == Recipient_Accept)) { - struct rt_mlme_delba_req DelbaReq; - BOOLEAN Cancelled; - /*unsigned long offset; */ - /*u32 VALUE; */ - - RTMPCancelTimer(&pBAEntry->RECBATimer, &Cancelled); - - /* */ - /* 1. Send DELBA Action Frame */ - /* */ - if (bPassive == FALSE) { - struct rt_mlme_queue_elem *Elem = - kmalloc(sizeof(struct rt_mlme_queue_elem), - MEM_ALLOC_FLAG); - if (Elem != NULL) { - NdisZeroMemory(&DelbaReq, sizeof(DelbaReq)); - NdisZeroMemory(Elem, sizeof(struct rt_mlme_queue_elem)); - - COPY_MAC_ADDR(DelbaReq.Addr, - pAd->MacTab.Content[Wcid].Addr); - DelbaReq.Wcid = Wcid; - DelbaReq.TID = TID; - DelbaReq.Initiator = RECIPIENT; - Elem->MsgLen = sizeof(DelbaReq); - NdisMoveMemory(Elem->Msg, &DelbaReq, - sizeof(DelbaReq)); - MlmeDELBAAction(pAd, Elem); - kfree(Elem); - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("%s():alloc memory failed!\n", - __func__)); - return; - } - } - - /* */ - /* 2. Free resource of BA session */ - /* */ - /* flush all pending reordering mpdus */ - ba_refresh_reordering_mpdus(pAd, pBAEntry); - - NdisAcquireSpinLock(&pAd->BATabLock); - - /* Erase Bitmap flag. */ - pBAEntry->LastIndSeq = RESET_RCV_SEQ; - pBAEntry->BAWinSize = 0; - /* Erase Bitmap flag at software mactable */ - pAd->MacTab.Content[Wcid].RXBAbitmap &= - (~(1 << (pBAEntry->TID))); - pAd->MacTab.Content[Wcid].BARecWcidArray[TID] = 0; - - RTMP_DEL_BA_SESSION_FROM_ASIC(pAd, Wcid, TID); - - NdisReleaseSpinLock(&pAd->BATabLock); - - } - - BATableFreeRecEntry(pAd, Idx); -} - -void BASessionTearDownALL(struct rt_rtmp_adapter *pAd, u8 Wcid) -{ - int i; - - for (i = 0; i < NUM_OF_TID; i++) { - BAOriSessionTearDown(pAd, Wcid, i, FALSE, FALSE); - BARecSessionTearDown(pAd, Wcid, i, FALSE); - } -} - -/* - ========================================================================== - Description: - Retry sending ADDBA Reqest. - - IRQL = DISPATCH_LEVEL - - Parametrs: - p8023Header: if this is already 802.3 format, p8023Header is NULL - - Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere. - FALSE , then continue indicaterx at this moment. - ========================================================================== - */ -void BAOriSessionSetupTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, - void *SystemSpecific3) -{ - struct rt_ba_ori_entry *pBAEntry = (struct rt_ba_ori_entry *)FunctionContext; - struct rt_mac_table_entry *pEntry; - struct rt_rtmp_adapter *pAd; - - if (pBAEntry == NULL) - return; - - pAd = pBAEntry->pAdapter; - - { - /* Do nothing if monitor mode is on */ - if (MONITOR_ON(pAd)) - return; - } - - pEntry = &pAd->MacTab.Content[pBAEntry->Wcid]; - - if ((pBAEntry->ORI_BA_Status == Originator_WaitRes) - && (pBAEntry->Token < ORI_SESSION_MAX_RETRY)) { - struct rt_mlme_addba_req AddbaReq; - - NdisZeroMemory(&AddbaReq, sizeof(AddbaReq)); - COPY_MAC_ADDR(AddbaReq.pAddr, pEntry->Addr); - AddbaReq.Wcid = (u8)(pEntry->Aid); - AddbaReq.TID = pBAEntry->TID; - AddbaReq.BaBufSize = - pAd->CommonCfg.BACapability.field.RxBAWinLimit; - AddbaReq.TimeOutValue = 0; - AddbaReq.Token = pBAEntry->Token; - MlmeEnqueue(pAd, ACTION_STATE_MACHINE, MT2_MLME_ADD_BA_CATE, - sizeof(struct rt_mlme_addba_req), (void *)& AddbaReq); - RTMP_MLME_HANDLER(pAd); - DBGPRINT(RT_DEBUG_TRACE, - ("BA Ori Session Timeout(%d) : Send ADD BA again\n", - pBAEntry->Token)); - - pBAEntry->Token++; - RTMPSetTimer(&pBAEntry->ORIBATimer, ORI_BA_SESSION_TIMEOUT); - } else { - BATableFreeOriEntry(pAd, pEntry->BAOriWcidArray[pBAEntry->TID]); - } -} - -/* - ========================================================================== - Description: - Retry sending ADDBA Reqest. - - IRQL = DISPATCH_LEVEL - - Parametrs: - p8023Header: if this is already 802.3 format, p8023Header is NULL - - Return : TRUE if put into rx reordering buffer, shouldn't indicaterxhere. - FALSE , then continue indicaterx at this moment. - ========================================================================== - */ -void BARecSessionIdleTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - - struct rt_ba_rec_entry *pBAEntry = (struct rt_ba_rec_entry *)FunctionContext; - struct rt_rtmp_adapter *pAd; - unsigned long Now32; - - if (pBAEntry == NULL) - return; - - if ((pBAEntry->REC_BA_Status == Recipient_Accept)) { - NdisGetSystemUpTime(&Now32); - - if (RTMP_TIME_AFTER - ((unsigned long)Now32, - (unsigned long)(pBAEntry->LastIndSeqAtTimer + - REC_BA_SESSION_IDLE_TIMEOUT))) { - pAd = pBAEntry->pAdapter; - /* flush all pending reordering mpdus */ - ba_refresh_reordering_mpdus(pAd, pBAEntry); - DBGPRINT(RT_DEBUG_OFF, - ("%ld: REC BA session Timeout\n", Now32)); - } - } -} - -void PeerAddBAReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - /* 7.4.4.1 */ - /*unsigned long Idx; */ - u8 Status = 1; - u8 pAddr[6]; - struct rt_frame_addba_rsp ADDframe; - u8 *pOutBuffer = NULL; - int NStatus; - struct rt_frame_addba_req * pAddreqFrame = NULL; - /*u8 BufSize; */ - unsigned long FrameLen; - unsigned long *ptemp; - struct rt_mac_table_entry *pMacEntry; - - DBGPRINT(RT_DEBUG_TRACE, - ("%s ==> (Wcid = %d)\n", __func__, Elem->Wcid)); - - /*hex_dump("AddBAReq", Elem->Msg, Elem->MsgLen); */ - - /*ADDBA Request from unknown peer, ignore this. */ - if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE) - return; - - pMacEntry = &pAd->MacTab.Content[Elem->Wcid]; - DBGPRINT(RT_DEBUG_TRACE, ("BA - PeerAddBAReqAction----> \n")); - ptemp = (unsigned long *)Elem->Msg; - /*DBGPRINT_RAW(RT_DEBUG_EMU, ("%08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x:: %08x\n", *(ptemp), *(ptemp+1), *(ptemp+2), *(ptemp+3), *(ptemp+4), *(ptemp+5), *(ptemp+6), *(ptemp+7), *(ptemp+8))); */ - - if (PeerAddBAReqActionSanity(pAd, Elem->Msg, Elem->MsgLen, pAddr)) { - - if ((pAd->CommonCfg.bBADecline == FALSE) - && IS_HT_STA(pMacEntry)) { - pAddreqFrame = (struct rt_frame_addba_req *) (&Elem->Msg[0]); - DBGPRINT(RT_DEBUG_OFF, - ("Rcv Wcid(%d) AddBAReq\n", Elem->Wcid)); - if (BARecSessionAdd - (pAd, &pAd->MacTab.Content[Elem->Wcid], - pAddreqFrame)) - Status = 0; - else - Status = 38; /* more parameters have invalid values */ - } else { - Status = 37; /* the request has been declined. */ - } - } - - if (pAd->MacTab.Content[Elem->Wcid].ValidAsCLI) - ASSERT(pAd->MacTab.Content[Elem->Wcid].Sst == SST_ASSOC); - - pAddreqFrame = (struct rt_frame_addba_req *) (&Elem->Msg[0]); - /* 2. Always send back ADDBA Response */ - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("ACTION - PeerBAAction() allocate memory failed \n")); - return; - } - - NdisZeroMemory(&ADDframe, sizeof(struct rt_frame_addba_rsp)); - - /* 2-1. Prepare ADDBA Response frame. */ - { - if (ADHOC_ON(pAd)) - ActHeaderInit(pAd, &ADDframe.Hdr, pAddr, - pAd->CurrentAddress, - pAd->CommonCfg.Bssid); - else - ActHeaderInit(pAd, &ADDframe.Hdr, pAd->CommonCfg.Bssid, - pAd->CurrentAddress, pAddr); - } - - ADDframe.Category = CATEGORY_BA; - ADDframe.Action = ADDBA_RESP; - ADDframe.Token = pAddreqFrame->Token; - /* What is the Status code?? need to check. */ - ADDframe.StatusCode = Status; - ADDframe.BaParm.BAPolicy = IMMED_BA; - ADDframe.BaParm.AMSDUSupported = 0; - ADDframe.BaParm.TID = pAddreqFrame->BaParm.TID; - ADDframe.BaParm.BufSize = - min(((u8)pAddreqFrame->BaParm.BufSize), - (u8)pAd->CommonCfg.BACapability.field.RxBAWinLimit); - if (ADDframe.BaParm.BufSize == 0) { - ADDframe.BaParm.BufSize = 64; - } - ADDframe.TimeOutValue = 0; /*pAddreqFrame->TimeOutValue; */ - - *(u16 *) (&ADDframe.BaParm) = - cpu2le16(*(u16 *) (&ADDframe.BaParm)); - ADDframe.StatusCode = cpu2le16(ADDframe.StatusCode); - ADDframe.TimeOutValue = cpu2le16(ADDframe.TimeOutValue); - - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_frame_addba_rsp), &ADDframe, END_OF_ARGS); - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - DBGPRINT(RT_DEBUG_TRACE, - ("%s(%d): TID(%d), BufSize(%d) <== \n", __func__, Elem->Wcid, - ADDframe.BaParm.TID, ADDframe.BaParm.BufSize)); -} - -void PeerAddBARspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - /*u8 Idx, i; */ - /*u8 * pOutBuffer = NULL; */ - struct rt_frame_addba_rsp * pFrame = NULL; - /*struct rt_ba_ori_entry *pBAEntry; */ - - /*ADDBA Response from unknown peer, ignore this. */ - if (Elem->Wcid >= MAX_LEN_OF_MAC_TABLE) - return; - - DBGPRINT(RT_DEBUG_TRACE, ("%s ==> Wcid(%d)\n", __func__, Elem->Wcid)); - - /*hex_dump("PeerAddBARspAction()", Elem->Msg, Elem->MsgLen); */ - - if (PeerAddBARspActionSanity(pAd, Elem->Msg, Elem->MsgLen)) { - pFrame = (struct rt_frame_addba_rsp *) (&Elem->Msg[0]); - - DBGPRINT(RT_DEBUG_TRACE, - ("\t\t StatusCode = %d\n", pFrame->StatusCode)); - switch (pFrame->StatusCode) { - case 0: - /* I want a BAsession with this peer as an originator. */ - BAOriSessionAdd(pAd, &pAd->MacTab.Content[Elem->Wcid], - pFrame); - break; - default: - /* check status == USED ??? */ - BAOriSessionTearDown(pAd, Elem->Wcid, - pFrame->BaParm.TID, TRUE, FALSE); - break; - } - /* Rcv Decline StatusCode */ - if ((pFrame->StatusCode == 37) - || ((pAd->OpMode == OPMODE_STA) && STA_TGN_WIFI_ON(pAd) - && (pFrame->StatusCode != 0)) - ) { - pAd->MacTab.Content[Elem->Wcid].BADeclineBitmap |= - 1 << pFrame->BaParm.TID; - } - } -} - -void PeerDelBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - /*u8 Idx; */ - /*u8 * pOutBuffer = NULL; */ - struct rt_frame_delba_req * pDelFrame = NULL; - - DBGPRINT(RT_DEBUG_TRACE, ("%s ==>\n", __func__)); - /*DELBA Request from unknown peer, ignore this. */ - if (PeerDelBAActionSanity(pAd, Elem->Wcid, Elem->Msg, Elem->MsgLen)) { - pDelFrame = (struct rt_frame_delba_req *) (&Elem->Msg[0]); - if (pDelFrame->DelbaParm.Initiator == ORIGINATOR) { - DBGPRINT(RT_DEBUG_TRACE, - ("BA - PeerDelBAAction----> ORIGINATOR\n")); - BARecSessionTearDown(pAd, Elem->Wcid, - pDelFrame->DelbaParm.TID, TRUE); - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("BA - PeerDelBAAction----> RECIPIENT, Reason = %d\n", - pDelFrame->ReasonCode)); - /*hex_dump("DelBA Frame", pDelFrame, Elem->MsgLen); */ - BAOriSessionTearDown(pAd, Elem->Wcid, - pDelFrame->DelbaParm.TID, TRUE, - FALSE); - } - } -} - -BOOLEAN CntlEnqueueForRecv(struct rt_rtmp_adapter *pAd, - unsigned long Wcid, - unsigned long MsgLen, struct rt_frame_ba_req * pMsg) -{ - struct rt_frame_ba_req * pFrame = pMsg; - /*PRTMP_REORDERBUF pBuffer; */ - /*PRTMP_REORDERBUF pDmaBuf; */ - struct rt_ba_rec_entry *pBAEntry; - /*BOOLEAN Result; */ - unsigned long Idx; - /*u8 NumRxPkt; */ - u8 TID; /*, i; */ - - TID = (u8)pFrame->BARControl.TID; - - DBGPRINT(RT_DEBUG_TRACE, - ("%s(): BAR-Wcid(%ld), Tid (%d)\n", __func__, Wcid, TID)); - /*hex_dump("BAR", (char *)pFrame, MsgLen); */ - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return FALSE; - - /* First check the size, it MUST not exceed the mlme queue size */ - if (MsgLen > MGMT_DMA_BUFFER_SIZE) { - DBGPRINT_ERR("CntlEnqueueForRecv: frame too large, size = %ld \n", MsgLen); - return FALSE; - } else if (MsgLen != sizeof(struct rt_frame_ba_req)) { - DBGPRINT_ERR("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen); - return FALSE; - } else if (MsgLen != sizeof(struct rt_frame_ba_req)) { - DBGPRINT_ERR("CntlEnqueueForRecv: BlockAck Request frame length size = %ld incorrect\n", MsgLen); - return FALSE; - } - - if ((Wcid < MAX_LEN_OF_MAC_TABLE) && (TID < 8)) { - /* if this receiving packet is from SA that is in our OriEntry. Since WCID <9 has direct mapping. no need search. */ - Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; - pBAEntry = &pAd->BATable.BARecEntry[Idx]; - } else { - return FALSE; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("BAR(%ld) : Tid (%d) - %04x:%04x\n", Wcid, TID, - pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq)); - - if (SEQ_SMALLER - (pBAEntry->LastIndSeq, pFrame->BAStartingSeq.field.StartSeq, - MAXSEQ)) { - /*DBGPRINT(RT_DEBUG_TRACE, ("BAR Seq = %x, LastIndSeq = %x\n", pFrame->BAStartingSeq.field.StartSeq, pBAEntry->LastIndSeq)); */ - ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, - pFrame->BAStartingSeq.field. - StartSeq); - pBAEntry->LastIndSeq = - (pFrame->BAStartingSeq.field.StartSeq == - 0) ? MAXSEQ : (pFrame->BAStartingSeq.field.StartSeq - 1); - } - /*ba_refresh_reordering_mpdus(pAd, pBAEntry); */ - return TRUE; -} - -/* -Description : Send PSMP Action frame If PSMP mode switches. -*/ -void SendPSMPAction(struct rt_rtmp_adapter *pAd, u8 Wcid, u8 Psmp) -{ - u8 *pOutBuffer = NULL; - int NStatus; - /*unsigned long Idx; */ - struct rt_frame_psmp_action Frame; - unsigned long FrameLen; - - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_ERROR, - ("BA - MlmeADDBAAction() allocate memory failed \n")); - return; - } - - ActHeaderInit(pAd, &Frame.Hdr, pAd->CommonCfg.Bssid, - pAd->CurrentAddress, pAd->MacTab.Content[Wcid].Addr); - - Frame.Category = CATEGORY_HT; - Frame.Action = SMPS_ACTION; - switch (Psmp) { - case MMPS_ENABLE: -#ifdef RT30xx - if (IS_RT30xx(pAd) - && (pAd->Antenna.field.RxPath > 1 - || pAd->Antenna.field.TxPath > 1)) { - RTMP_ASIC_MMPS_DISABLE(pAd); - } -#endif /* RT30xx // */ - Frame.Psmp = 0; - break; - case MMPS_DYNAMIC: - Frame.Psmp = 3; - break; - case MMPS_STATIC: -#ifdef RT30xx - if (IS_RT30xx(pAd) - && (pAd->Antenna.field.RxPath > 1 - || pAd->Antenna.field.TxPath > 1)) { - RTMP_ASIC_MMPS_ENABLE(pAd); - } -#endif /* RT30xx // */ - Frame.Psmp = 1; - break; - } - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_frame_psmp_action), &Frame, END_OF_ARGS); - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - DBGPRINT(RT_DEBUG_ERROR, ("HT - SendPSMPAction( %d ) \n", Frame.Psmp)); -} - -#define RADIO_MEASUREMENT_REQUEST_ACTION 0 - -struct PACKED rt_beacon_request { - u8 RegulatoryClass; - u8 ChannelNumber; - u16 RandomInterval; - u16 MeasurementDuration; - u8 MeasurementMode; - u8 BSSID[MAC_ADDR_LEN]; - u8 ReportingCondition; - u8 Threshold; - u8 SSIDIE[2]; /* 2 byte */ -}; - -struct PACKED rt_measurement_req { - u8 ID; - u8 Length; - u8 Token; - u8 RequestMode; - u8 Type; -}; - -void convert_reordering_packet_to_preAMSDU_or_802_3_packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, - u8 - FromWhichBSSID) -{ - void *pRxPkt; - u8 Header802_3[LENGTH_802_3]; - - /* 1. get 802.3 Header */ - /* 2. remove LLC */ - /* a. pointer pRxBlk->pData to payload */ - /* b. modify pRxBlk->DataSize */ - - RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3); - - ASSERT(pRxBlk->pRxPacket); - pRxPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket); - - SET_OS_PKT_NETDEV(pRxPkt, get_netdev_from_bssid(pAd, FromWhichBSSID)); - SET_OS_PKT_DATAPTR(pRxPkt, pRxBlk->pData); - SET_OS_PKT_LEN(pRxPkt, pRxBlk->DataSize); - SET_OS_PKT_DATATAIL(pRxPkt, pRxBlk->pData, pRxBlk->DataSize); - - /* */ - /* copy 802.3 header, if necessary */ - /* */ - if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU)) { - { -#ifdef LINUX - NdisMoveMemory(skb_push(pRxPkt, LENGTH_802_3), - Header802_3, LENGTH_802_3); -#endif - } - } -} - -#define INDICATE_LEGACY_OR_AMSDU(_pAd, _pRxBlk, _fromWhichBSSID) \ - do \ - { \ - if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_AMSDU)) \ - { \ - Indicate_AMSDU_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \ - } \ - else if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_EAP)) \ - { \ - Indicate_EAPOL_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \ - } \ - else \ - { \ - Indicate_Legacy_Packet(_pAd, _pRxBlk, _fromWhichBSSID); \ - } \ - } while (0); - -static void ba_enqueue_reordering_packet(struct rt_rtmp_adapter *pAd, - struct rt_ba_rec_entry *pBAEntry, - struct rt_rx_blk *pRxBlk, - u8 FromWhichBSSID) -{ - struct reordering_mpdu *mpdu_blk; - u16 Sequence = (u16)pRxBlk->pHeader->Sequence; - - mpdu_blk = ba_mpdu_blk_alloc(pAd); - if ((mpdu_blk != NULL) && (!RX_BLK_TEST_FLAG(pRxBlk, fRX_EAP))) { - /* Write RxD buffer address & allocated buffer length */ - NdisAcquireSpinLock(&pBAEntry->RxReRingLock); - - mpdu_blk->Sequence = Sequence; - - mpdu_blk->bAMSDU = RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU); - - convert_reordering_packet_to_preAMSDU_or_802_3_packet(pAd, - pRxBlk, - FromWhichBSSID); - - STATS_INC_RX_PACKETS(pAd, FromWhichBSSID); - - /* */ - /* it is necessary for reordering packet to record */ - /* which BSS it come from */ - /* */ - RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID); - - mpdu_blk->pPacket = pRxBlk->pRxPacket; - - if (ba_reordering_mpdu_insertsorted(&pBAEntry->list, mpdu_blk) - == FALSE) { - /* had been already within reordering list */ - /* don't indicate */ - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, - NDIS_STATUS_SUCCESS); - ba_mpdu_blk_free(pAd, mpdu_blk); - } - - ASSERT((0 <= pBAEntry->list.qlen) - && (pBAEntry->list.qlen <= pBAEntry->BAWinSize)); - NdisReleaseSpinLock(&pBAEntry->RxReRingLock); - } else { - DBGPRINT(RT_DEBUG_ERROR, - (" (%d) Can't allocate reordering mpdu blk\n", - pBAEntry->list.qlen)); - - /* - * flush all pending reordering mpdus - * and receiving mpdu to upper layer - * make tcp/ip to take care reordering mechanism - */ - /*ba_refresh_reordering_mpdus(pAd, pBAEntry); */ - ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, Sequence); - - pBAEntry->LastIndSeq = Sequence; - INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); - } -} - -/* - ========================================================================== - Description: - Indicate this packet to upper layer or put it into reordering buffer - - Parametrs: - pRxBlk : carry necessary packet info 802.11 format - FromWhichBSSID : the packet received from which BSS - - Return : - none - - Note : - the packet queued into reordering buffer need to cover to 802.3 format - or pre_AMSDU format - ========================================================================== - */ - -void Indicate_AMPDU_Packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID) -{ - u16 Idx; - struct rt_ba_rec_entry *pBAEntry = NULL; - u16 Sequence = pRxBlk->pHeader->Sequence; - unsigned long Now32; - u8 Wcid = pRxBlk->pRxWI->WirelessCliID; - u8 TID = pRxBlk->pRxWI->TID; - - if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU) - && (pRxBlk->DataSize > MAX_RX_PKT_LEN)) { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - - if (Wcid < MAX_LEN_OF_MAC_TABLE) { - Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; - if (Idx == 0) { - /* Rec BA Session had been torn down */ - INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); - return; - } - pBAEntry = &pAd->BATable.BARecEntry[Idx]; - } else { - /* impossible ! */ - ASSERT(0); - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - - ASSERT(pBAEntry); - - /* update last rx time */ - NdisGetSystemUpTime(&Now32); - - pBAEntry->rcvSeq = Sequence; - - ba_flush_reordering_timeout_mpdus(pAd, pBAEntry, Now32); - pBAEntry->LastIndSeqAtTimer = Now32; - - /* */ - /* Reset Last Indicate Sequence */ - /* */ - if (pBAEntry->LastIndSeq == RESET_RCV_SEQ) { - ASSERT((pBAEntry->list.qlen == 0) - && (pBAEntry->list.next == NULL)); - - /* reset rcv sequence of BA session */ - pBAEntry->LastIndSeq = Sequence; - pBAEntry->LastIndSeqAtTimer = Now32; - INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); - return; - } - - /* */ - /* I. Check if in order. */ - /* */ - if (SEQ_STEPONE(Sequence, pBAEntry->LastIndSeq, MAXSEQ)) { - u16 LastIndSeq; - - pBAEntry->LastIndSeq = Sequence; - INDICATE_LEGACY_OR_AMSDU(pAd, pRxBlk, FromWhichBSSID); - LastIndSeq = - ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, - pBAEntry->LastIndSeq); - if (LastIndSeq != RESET_RCV_SEQ) { - pBAEntry->LastIndSeq = LastIndSeq; - } - pBAEntry->LastIndSeqAtTimer = Now32; - } - /* */ - /* II. Drop Duplicated Packet */ - /* */ - else if (Sequence == pBAEntry->LastIndSeq) { - - /* drop and release packet */ - pBAEntry->nDropPacket++; - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, - NDIS_STATUS_FAILURE); - } - /* */ - /* III. Drop Old Received Packet */ - /* */ - else if (SEQ_SMALLER(Sequence, pBAEntry->LastIndSeq, MAXSEQ)) { - - /* drop and release packet */ - pBAEntry->nDropPacket++; - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, - NDIS_STATUS_FAILURE); - } - /* */ - /* IV. Receive Sequence within Window Size */ - /* */ - else if (SEQ_SMALLER - (Sequence, - (((pBAEntry->LastIndSeq + pBAEntry->BAWinSize + 1)) & MAXSEQ), - MAXSEQ)) { - ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk, - FromWhichBSSID); - } - /* */ - /* V. Receive seq surpasses Win(lastseq + nMSDU). So refresh all reorder buffer */ - /* */ - else { - long WinStartSeq, TmpSeq; - - TmpSeq = Sequence - (pBAEntry->BAWinSize) - 1; - if (TmpSeq < 0) { - TmpSeq = (MAXSEQ + 1) + TmpSeq; - } - WinStartSeq = (TmpSeq + 1) & MAXSEQ; - ba_indicate_reordering_mpdus_le_seq(pAd, pBAEntry, WinStartSeq); - pBAEntry->LastIndSeq = WinStartSeq; /*TmpSeq; */ - - pBAEntry->LastIndSeqAtTimer = Now32; - - ba_enqueue_reordering_packet(pAd, pBAEntry, pRxBlk, - FromWhichBSSID); - - TmpSeq = - ba_indicate_reordering_mpdus_in_order(pAd, pBAEntry, - pBAEntry->LastIndSeq); - if (TmpSeq != RESET_RCV_SEQ) { - pBAEntry->LastIndSeq = TmpSeq; - } - } -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_aes.c b/trunk/drivers/staging/rt2860/common/cmm_aes.c deleted file mode 100644 index d70d229a6e53..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_aes.c +++ /dev/null @@ -1,1311 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - cmm_aes.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Paul Wu 02-25-02 Initial -*/ - -#include "../rt_config.h" - -struct aes_context { - u32 erk[64]; /* encryption round keys */ - u32 drk[64]; /* decryption round keys */ - int nr; /* number of rounds */ -}; - -/*****************************/ -/******** SBOX Table *********/ -/*****************************/ - -u8 SboxTable[256] = { - 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, - 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, - 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, - 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, - 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, - 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, - 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, - 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, - 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, - 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, - 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, - 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, - 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, - 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, - 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, - 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, - 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, - 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, - 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, - 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, - 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, - 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, - 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, - 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, - 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, - 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, - 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, - 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, - 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, - 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, - 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, - 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 -}; - -void xor_32(u8 *a, u8 *b, u8 *out) -{ - int i; - - for (i = 0; i < 4; i++) { - out[i] = a[i] ^ b[i]; - } -} - -void xor_128(u8 *a, u8 *b, u8 *out) -{ - int i; - - for (i = 0; i < 16; i++) { - out[i] = a[i] ^ b[i]; - } -} - -u8 RTMPCkipSbox(u8 a) -{ - return SboxTable[(int)a]; -} - -void next_key(u8 *key, int round) -{ - u8 rcon; - u8 sbox_key[4]; - u8 rcon_table[12] = { - 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, - 0x1b, 0x36, 0x36, 0x36 - }; - - sbox_key[0] = RTMPCkipSbox(key[13]); - sbox_key[1] = RTMPCkipSbox(key[14]); - sbox_key[2] = RTMPCkipSbox(key[15]); - sbox_key[3] = RTMPCkipSbox(key[12]); - - rcon = rcon_table[round]; - - xor_32(&key[0], sbox_key, &key[0]); - key[0] = key[0] ^ rcon; - - xor_32(&key[4], &key[0], &key[4]); - xor_32(&key[8], &key[4], &key[8]); - xor_32(&key[12], &key[8], &key[12]); -} - -void byte_sub(u8 *in, u8 *out) -{ - int i; - - for (i = 0; i < 16; i++) { - out[i] = RTMPCkipSbox(in[i]); - } -} - -/************************************/ -/* bitwise_xor() */ -/* A 128 bit, bitwise exclusive or */ -/************************************/ - -void bitwise_xor(unsigned char *ina, unsigned char *inb, unsigned char *out) -{ - int i; - for (i = 0; i < 16; i++) { - out[i] = ina[i] ^ inb[i]; - } -} - -void shift_row(u8 *in, u8 *out) -{ - out[0] = in[0]; - out[1] = in[5]; - out[2] = in[10]; - out[3] = in[15]; - out[4] = in[4]; - out[5] = in[9]; - out[6] = in[14]; - out[7] = in[3]; - out[8] = in[8]; - out[9] = in[13]; - out[10] = in[2]; - out[11] = in[7]; - out[12] = in[12]; - out[13] = in[1]; - out[14] = in[6]; - out[15] = in[11]; -} - -void mix_column(u8 *in, u8 *out) -{ - int i; - u8 add1b[4]; - u8 add1bf7[4]; - u8 rotl[4]; - u8 swap_halfs[4]; - u8 andf7[4]; - u8 rotr[4]; - u8 temp[4]; - u8 tempb[4]; - - for (i = 0; i < 4; i++) { - if ((in[i] & 0x80) == 0x80) - add1b[i] = 0x1b; - else - add1b[i] = 0x00; - } - - swap_halfs[0] = in[2]; /* Swap halfs */ - swap_halfs[1] = in[3]; - swap_halfs[2] = in[0]; - swap_halfs[3] = in[1]; - - rotl[0] = in[3]; /* Rotate left 8 bits */ - rotl[1] = in[0]; - rotl[2] = in[1]; - rotl[3] = in[2]; - - andf7[0] = in[0] & 0x7f; - andf7[1] = in[1] & 0x7f; - andf7[2] = in[2] & 0x7f; - andf7[3] = in[3] & 0x7f; - - for (i = 3; i > 0; i--) { /* logical shift left 1 bit */ - andf7[i] = andf7[i] << 1; - if ((andf7[i - 1] & 0x80) == 0x80) { - andf7[i] = (andf7[i] | 0x01); - } - } - andf7[0] = andf7[0] << 1; - andf7[0] = andf7[0] & 0xfe; - - xor_32(add1b, andf7, add1bf7); - - xor_32(in, add1bf7, rotr); - - temp[0] = rotr[0]; /* Rotate right 8 bits */ - rotr[0] = rotr[1]; - rotr[1] = rotr[2]; - rotr[2] = rotr[3]; - rotr[3] = temp[0]; - - xor_32(add1bf7, rotr, temp); - xor_32(swap_halfs, rotl, tempb); - xor_32(temp, tempb, out); -} - -/************************************************/ -/* construct_mic_header1() */ -/* Builds the first MIC header block from */ -/* header fields. */ -/************************************************/ - -void construct_mic_header1(unsigned char *mic_header1, - int header_length, unsigned char *mpdu) -{ - mic_header1[0] = (unsigned char)((header_length - 2) / 256); - mic_header1[1] = (unsigned char)((header_length - 2) % 256); - mic_header1[2] = mpdu[0] & 0xcf; /* Mute CF poll & CF ack bits */ - mic_header1[3] = mpdu[1] & 0xc7; /* Mute retry, more data and pwr mgt bits */ - mic_header1[4] = mpdu[4]; /* A1 */ - mic_header1[5] = mpdu[5]; - mic_header1[6] = mpdu[6]; - mic_header1[7] = mpdu[7]; - mic_header1[8] = mpdu[8]; - mic_header1[9] = mpdu[9]; - mic_header1[10] = mpdu[10]; /* A2 */ - mic_header1[11] = mpdu[11]; - mic_header1[12] = mpdu[12]; - mic_header1[13] = mpdu[13]; - mic_header1[14] = mpdu[14]; - mic_header1[15] = mpdu[15]; -} - -/************************************************/ -/* construct_mic_header2() */ -/* Builds the last MIC header block from */ -/* header fields. */ -/************************************************/ - -void construct_mic_header2(unsigned char *mic_header2, - unsigned char *mpdu, int a4_exists, int qc_exists) -{ - int i; - - for (i = 0; i < 16; i++) - mic_header2[i] = 0x00; - - mic_header2[0] = mpdu[16]; /* A3 */ - mic_header2[1] = mpdu[17]; - mic_header2[2] = mpdu[18]; - mic_header2[3] = mpdu[19]; - mic_header2[4] = mpdu[20]; - mic_header2[5] = mpdu[21]; - - /* In Sequence Control field, mute sequence numer bits (12-bit) */ - mic_header2[6] = mpdu[22] & 0x0f; /* SC */ - mic_header2[7] = 0x00; /* mpdu[23]; */ - - if ((!qc_exists) && a4_exists) { - for (i = 0; i < 6; i++) - mic_header2[8 + i] = mpdu[24 + i]; /* A4 */ - - } - - if (qc_exists && (!a4_exists)) { - mic_header2[8] = mpdu[24] & 0x0f; /* mute bits 15 - 4 */ - mic_header2[9] = mpdu[25] & 0x00; - } - - if (qc_exists && a4_exists) { - for (i = 0; i < 6; i++) - mic_header2[8 + i] = mpdu[24 + i]; /* A4 */ - - mic_header2[14] = mpdu[30] & 0x0f; - mic_header2[15] = mpdu[31] & 0x00; - } -} - -/************************************************/ -/* construct_mic_iv() */ -/* Builds the MIC IV from header fields and PN */ -/************************************************/ - -void construct_mic_iv(unsigned char *mic_iv, - int qc_exists, - int a4_exists, - unsigned char *mpdu, - unsigned int payload_length, unsigned char *pn_vector) -{ - int i; - - mic_iv[0] = 0x59; - if (qc_exists && a4_exists) - mic_iv[1] = mpdu[30] & 0x0f; /* QoS_TC */ - if (qc_exists && !a4_exists) - mic_iv[1] = mpdu[24] & 0x0f; /* mute bits 7-4 */ - if (!qc_exists) - mic_iv[1] = 0x00; - for (i = 2; i < 8; i++) - mic_iv[i] = mpdu[i + 8]; /* mic_iv[2:7] = A2[0:5] = mpdu[10:15] */ -#ifdef CONSISTENT_PN_ORDER - for (i = 8; i < 14; i++) - mic_iv[i] = pn_vector[i - 8]; /* mic_iv[8:13] = PN[0:5] */ -#else - for (i = 8; i < 14; i++) - mic_iv[i] = pn_vector[13 - i]; /* mic_iv[8:13] = PN[5:0] */ -#endif - mic_iv[14] = (unsigned char)(payload_length / 256); - mic_iv[15] = (unsigned char)(payload_length % 256); - -} - -/****************************************/ -/* aes128k128d() */ -/* Performs a 128 bit AES encrypt with */ -/* 128 bit data. */ -/****************************************/ -void aes128k128d(unsigned char *key, unsigned char *data, - unsigned char *ciphertext) -{ - int round; - int i; - unsigned char intermediatea[16]; - unsigned char intermediateb[16]; - unsigned char round_key[16]; - - for (i = 0; i < 16; i++) - round_key[i] = key[i]; - - for (round = 0; round < 11; round++) { - if (round == 0) { - xor_128(round_key, data, ciphertext); - next_key(round_key, round); - } else if (round == 10) { - byte_sub(ciphertext, intermediatea); - shift_row(intermediatea, intermediateb); - xor_128(intermediateb, round_key, ciphertext); - } else { /* 1 - 9 */ - - byte_sub(ciphertext, intermediatea); - shift_row(intermediatea, intermediateb); - mix_column(&intermediateb[0], &intermediatea[0]); - mix_column(&intermediateb[4], &intermediatea[4]); - mix_column(&intermediateb[8], &intermediatea[8]); - mix_column(&intermediateb[12], &intermediatea[12]); - xor_128(intermediatea, round_key, ciphertext); - next_key(round_key, round); - } - } - -} - -void construct_ctr_preload(unsigned char *ctr_preload, - int a4_exists, - int qc_exists, - unsigned char *mpdu, unsigned char *pn_vector, int c) -{ - - int i = 0; - for (i = 0; i < 16; i++) - ctr_preload[i] = 0x00; - i = 0; - - ctr_preload[0] = 0x01; /* flag */ - if (qc_exists && a4_exists) - ctr_preload[1] = mpdu[30] & 0x0f; /* QoC_Control */ - if (qc_exists && !a4_exists) - ctr_preload[1] = mpdu[24] & 0x0f; - - for (i = 2; i < 8; i++) - ctr_preload[i] = mpdu[i + 8]; /* ctr_preload[2:7] = A2[0:5] = mpdu[10:15] */ -#ifdef CONSISTENT_PN_ORDER - for (i = 8; i < 14; i++) - ctr_preload[i] = pn_vector[i - 8]; /* ctr_preload[8:13] = PN[0:5] */ -#else - for (i = 8; i < 14; i++) - ctr_preload[i] = pn_vector[13 - i]; /* ctr_preload[8:13] = PN[5:0] */ -#endif - ctr_preload[14] = (unsigned char)(c / 256); /* Ctr */ - ctr_preload[15] = (unsigned char)(c % 256); - -} - -BOOLEAN RTMPSoftDecryptAES(struct rt_rtmp_adapter *pAd, - u8 *pData, - unsigned long DataByteCnt, struct rt_cipher_key *pWpaKey) -{ - u8 KeyID; - u32 HeaderLen; - u8 PN[6]; - u32 payload_len; - u32 num_blocks; - u32 payload_remainder; - u16 fc; - u8 fc0; - u8 fc1; - u32 frame_type; - u32 frame_subtype; - u32 from_ds; - u32 to_ds; - int a4_exists; - int qc_exists; - u8 aes_out[16]; - int payload_index; - u32 i; - u8 ctr_preload[16]; - u8 chain_buffer[16]; - u8 padded_buffer[16]; - u8 mic_iv[16]; - u8 mic_header1[16]; - u8 mic_header2[16]; - u8 MIC[8]; - u8 TrailMIC[8]; - - fc0 = *pData; - fc1 = *(pData + 1); - - fc = *((u16 *)pData); - - frame_type = ((fc0 >> 2) & 0x03); - frame_subtype = ((fc0 >> 4) & 0x0f); - - from_ds = (fc1 & 0x2) >> 1; - to_ds = (fc1 & 0x1); - - a4_exists = (from_ds & to_ds); - qc_exists = ((frame_subtype == 0x08) || /* Assumed QoS subtypes */ - (frame_subtype == 0x09) || /* Likely to change. */ - (frame_subtype == 0x0a) || (frame_subtype == 0x0b) - ); - - HeaderLen = 24; - if (a4_exists) - HeaderLen += 6; - - KeyID = *((u8 *)(pData + HeaderLen + 3)); - KeyID = KeyID >> 6; - - if (pWpaKey[KeyID].KeyLen == 0) { - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPSoftDecryptAES failed!(KeyID[%d] Length can not be 0)\n", - KeyID)); - return FALSE; - } - - PN[0] = *(pData + HeaderLen); - PN[1] = *(pData + HeaderLen + 1); - PN[2] = *(pData + HeaderLen + 4); - PN[3] = *(pData + HeaderLen + 5); - PN[4] = *(pData + HeaderLen + 6); - PN[5] = *(pData + HeaderLen + 7); - - payload_len = DataByteCnt - HeaderLen - 8 - 8; /* 8 bytes for CCMP header , 8 bytes for MIC */ - payload_remainder = (payload_len) % 16; - num_blocks = (payload_len) / 16; - - /* Find start of payload */ - payload_index = HeaderLen + 8; /*IV+EIV */ - - for (i = 0; i < num_blocks; i++) { - construct_ctr_preload(ctr_preload, - a4_exists, qc_exists, pData, PN, i + 1); - - aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out); - - bitwise_xor(aes_out, pData + payload_index, chain_buffer); - NdisMoveMemory(pData + payload_index - 8, chain_buffer, 16); - payload_index += 16; - } - - /* */ - /* If there is a short final block, then pad it */ - /* encrypt it and copy the unpadded part back */ - /* */ - if (payload_remainder > 0) { - construct_ctr_preload(ctr_preload, - a4_exists, - qc_exists, pData, PN, num_blocks + 1); - - NdisZeroMemory(padded_buffer, 16); - NdisMoveMemory(padded_buffer, pData + payload_index, - payload_remainder); - - aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out); - - bitwise_xor(aes_out, padded_buffer, chain_buffer); - NdisMoveMemory(pData + payload_index - 8, chain_buffer, - payload_remainder); - payload_index += payload_remainder; - } - /* */ - /* Descrypt the MIC */ - /* */ - construct_ctr_preload(ctr_preload, a4_exists, qc_exists, pData, PN, 0); - NdisZeroMemory(padded_buffer, 16); - NdisMoveMemory(padded_buffer, pData + payload_index, 8); - - aes128k128d(pWpaKey[KeyID].Key, ctr_preload, aes_out); - - bitwise_xor(aes_out, padded_buffer, chain_buffer); - - NdisMoveMemory(TrailMIC, chain_buffer, 8); - - /* */ - /* Calculate MIC */ - /* */ - - /*Force the protected frame bit on */ - *(pData + 1) = *(pData + 1) | 0x40; - - /* Find start of payload */ - /* Because the CCMP header has been removed */ - payload_index = HeaderLen; - - construct_mic_iv(mic_iv, qc_exists, a4_exists, pData, payload_len, PN); - - construct_mic_header1(mic_header1, HeaderLen, pData); - - construct_mic_header2(mic_header2, pData, a4_exists, qc_exists); - - aes128k128d(pWpaKey[KeyID].Key, mic_iv, aes_out); - bitwise_xor(aes_out, mic_header1, chain_buffer); - aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out); - bitwise_xor(aes_out, mic_header2, chain_buffer); - aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out); - - /* iterate through each 16 byte payload block */ - for (i = 0; i < num_blocks; i++) { - bitwise_xor(aes_out, pData + payload_index, chain_buffer); - payload_index += 16; - aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out); - } - - /* Add on the final payload block if it needs padding */ - if (payload_remainder > 0) { - NdisZeroMemory(padded_buffer, 16); - NdisMoveMemory(padded_buffer, pData + payload_index, - payload_remainder); - - bitwise_xor(aes_out, padded_buffer, chain_buffer); - aes128k128d(pWpaKey[KeyID].Key, chain_buffer, aes_out); - } - /* aes_out contains padded mic, discard most significant */ - /* 8 bytes to generate 64 bit MIC */ - for (i = 0; i < 8; i++) - MIC[i] = aes_out[i]; - - if (!NdisEqualMemory(MIC, TrailMIC, 8)) { - DBGPRINT(RT_DEBUG_ERROR, ("RTMPSoftDecryptAES, MIC Error !\n")); /*MIC error. */ - return FALSE; - } - - return TRUE; -} - -/* ========================= AES En/Decryption ========================== */ -#ifndef uint8 -#define uint8 unsigned char -#endif - -#ifndef uint32 -#define uint32 unsigned int -#endif - -/* forward S-box */ -static uint32 FSb[256] = { - 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5, - 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76, - 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0, - 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0, - 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC, - 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15, - 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A, - 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75, - 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0, - 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84, - 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B, - 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF, - 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85, - 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8, - 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5, - 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2, - 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17, - 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73, - 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88, - 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB, - 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C, - 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79, - 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9, - 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08, - 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6, - 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A, - 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E, - 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E, - 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94, - 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF, - 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68, - 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16 -}; - -/* forward table */ -#define FT \ -\ - V(C6,63,63,A5), V(F8,7C,7C,84), V(EE,77,77,99), V(F6,7B,7B,8D), \ - V(FF,F2,F2,0D), V(D6,6B,6B,BD), V(DE,6F,6F,B1), V(91,C5,C5,54), \ - V(60,30,30,50), V(02,01,01,03), V(CE,67,67,A9), V(56,2B,2B,7D), \ - V(E7,FE,FE,19), V(B5,D7,D7,62), V(4D,AB,AB,E6), V(EC,76,76,9A), \ - V(8F,CA,CA,45), V(1F,82,82,9D), V(89,C9,C9,40), V(FA,7D,7D,87), \ - V(EF,FA,FA,15), V(B2,59,59,EB), V(8E,47,47,C9), V(FB,F0,F0,0B), \ - V(41,AD,AD,EC), V(B3,D4,D4,67), V(5F,A2,A2,FD), V(45,AF,AF,EA), \ - V(23,9C,9C,BF), V(53,A4,A4,F7), V(E4,72,72,96), V(9B,C0,C0,5B), \ - V(75,B7,B7,C2), V(E1,FD,FD,1C), V(3D,93,93,AE), V(4C,26,26,6A), \ - V(6C,36,36,5A), V(7E,3F,3F,41), V(F5,F7,F7,02), V(83,CC,CC,4F), \ - V(68,34,34,5C), V(51,A5,A5,F4), V(D1,E5,E5,34), V(F9,F1,F1,08), \ - V(E2,71,71,93), V(AB,D8,D8,73), V(62,31,31,53), V(2A,15,15,3F), \ - V(08,04,04,0C), V(95,C7,C7,52), V(46,23,23,65), V(9D,C3,C3,5E), \ - V(30,18,18,28), V(37,96,96,A1), V(0A,05,05,0F), V(2F,9A,9A,B5), \ - V(0E,07,07,09), V(24,12,12,36), V(1B,80,80,9B), V(DF,E2,E2,3D), \ - V(CD,EB,EB,26), V(4E,27,27,69), V(7F,B2,B2,CD), V(EA,75,75,9F), \ - V(12,09,09,1B), V(1D,83,83,9E), V(58,2C,2C,74), V(34,1A,1A,2E), \ - V(36,1B,1B,2D), V(DC,6E,6E,B2), V(B4,5A,5A,EE), V(5B,A0,A0,FB), \ - V(A4,52,52,F6), V(76,3B,3B,4D), V(B7,D6,D6,61), V(7D,B3,B3,CE), \ - V(52,29,29,7B), V(DD,E3,E3,3E), V(5E,2F,2F,71), V(13,84,84,97), \ - V(A6,53,53,F5), V(B9,D1,D1,68), V(00,00,00,00), V(C1,ED,ED,2C), \ - V(40,20,20,60), V(E3,FC,FC,1F), V(79,B1,B1,C8), V(B6,5B,5B,ED), \ - V(D4,6A,6A,BE), V(8D,CB,CB,46), V(67,BE,BE,D9), V(72,39,39,4B), \ - V(94,4A,4A,DE), V(98,4C,4C,D4), V(B0,58,58,E8), V(85,CF,CF,4A), \ - V(BB,D0,D0,6B), V(C5,EF,EF,2A), V(4F,AA,AA,E5), V(ED,FB,FB,16), \ - V(86,43,43,C5), V(9A,4D,4D,D7), V(66,33,33,55), V(11,85,85,94), \ - V(8A,45,45,CF), V(E9,F9,F9,10), V(04,02,02,06), V(FE,7F,7F,81), \ - V(A0,50,50,F0), V(78,3C,3C,44), V(25,9F,9F,BA), V(4B,A8,A8,E3), \ - V(A2,51,51,F3), V(5D,A3,A3,FE), V(80,40,40,C0), V(05,8F,8F,8A), \ - V(3F,92,92,AD), V(21,9D,9D,BC), V(70,38,38,48), V(F1,F5,F5,04), \ - V(63,BC,BC,DF), V(77,B6,B6,C1), V(AF,DA,DA,75), V(42,21,21,63), \ - V(20,10,10,30), V(E5,FF,FF,1A), V(FD,F3,F3,0E), V(BF,D2,D2,6D), \ - V(81,CD,CD,4C), V(18,0C,0C,14), V(26,13,13,35), V(C3,EC,EC,2F), \ - V(BE,5F,5F,E1), V(35,97,97,A2), V(88,44,44,CC), V(2E,17,17,39), \ - V(93,C4,C4,57), V(55,A7,A7,F2), V(FC,7E,7E,82), V(7A,3D,3D,47), \ - V(C8,64,64,AC), V(BA,5D,5D,E7), V(32,19,19,2B), V(E6,73,73,95), \ - V(C0,60,60,A0), V(19,81,81,98), V(9E,4F,4F,D1), V(A3,DC,DC,7F), \ - V(44,22,22,66), V(54,2A,2A,7E), V(3B,90,90,AB), V(0B,88,88,83), \ - V(8C,46,46,CA), V(C7,EE,EE,29), V(6B,B8,B8,D3), V(28,14,14,3C), \ - V(A7,DE,DE,79), V(BC,5E,5E,E2), V(16,0B,0B,1D), V(AD,DB,DB,76), \ - V(DB,E0,E0,3B), V(64,32,32,56), V(74,3A,3A,4E), V(14,0A,0A,1E), \ - V(92,49,49,DB), V(0C,06,06,0A), V(48,24,24,6C), V(B8,5C,5C,E4), \ - V(9F,C2,C2,5D), V(BD,D3,D3,6E), V(43,AC,AC,EF), V(C4,62,62,A6), \ - V(39,91,91,A8), V(31,95,95,A4), V(D3,E4,E4,37), V(F2,79,79,8B), \ - V(D5,E7,E7,32), V(8B,C8,C8,43), V(6E,37,37,59), V(DA,6D,6D,B7), \ - V(01,8D,8D,8C), V(B1,D5,D5,64), V(9C,4E,4E,D2), V(49,A9,A9,E0), \ - V(D8,6C,6C,B4), V(AC,56,56,FA), V(F3,F4,F4,07), V(CF,EA,EA,25), \ - V(CA,65,65,AF), V(F4,7A,7A,8E), V(47,AE,AE,E9), V(10,08,08,18), \ - V(6F,BA,BA,D5), V(F0,78,78,88), V(4A,25,25,6F), V(5C,2E,2E,72), \ - V(38,1C,1C,24), V(57,A6,A6,F1), V(73,B4,B4,C7), V(97,C6,C6,51), \ - V(CB,E8,E8,23), V(A1,DD,DD,7C), V(E8,74,74,9C), V(3E,1F,1F,21), \ - V(96,4B,4B,DD), V(61,BD,BD,DC), V(0D,8B,8B,86), V(0F,8A,8A,85), \ - V(E0,70,70,90), V(7C,3E,3E,42), V(71,B5,B5,C4), V(CC,66,66,AA), \ - V(90,48,48,D8), V(06,03,03,05), V(F7,F6,F6,01), V(1C,0E,0E,12), \ - V(C2,61,61,A3), V(6A,35,35,5F), V(AE,57,57,F9), V(69,B9,B9,D0), \ - V(17,86,86,91), V(99,C1,C1,58), V(3A,1D,1D,27), V(27,9E,9E,B9), \ - V(D9,E1,E1,38), V(EB,F8,F8,13), V(2B,98,98,B3), V(22,11,11,33), \ - V(D2,69,69,BB), V(A9,D9,D9,70), V(07,8E,8E,89), V(33,94,94,A7), \ - V(2D,9B,9B,B6), V(3C,1E,1E,22), V(15,87,87,92), V(C9,E9,E9,20), \ - V(87,CE,CE,49), V(AA,55,55,FF), V(50,28,28,78), V(A5,DF,DF,7A), \ - V(03,8C,8C,8F), V(59,A1,A1,F8), V(09,89,89,80), V(1A,0D,0D,17), \ - V(65,BF,BF,DA), V(D7,E6,E6,31), V(84,42,42,C6), V(D0,68,68,B8), \ - V(82,41,41,C3), V(29,99,99,B0), V(5A,2D,2D,77), V(1E,0F,0F,11), \ - V(7B,B0,B0,CB), V(A8,54,54,FC), V(6D,BB,BB,D6), V(2C,16,16,3A) - -#define V(a,b,c,d) 0x##a##b##c##d -static uint32 FT0[256] = { FT }; - -#undef V - -#define V(a,b,c,d) 0x##d##a##b##c -static uint32 FT1[256] = { FT }; - -#undef V - -#define V(a,b,c,d) 0x##c##d##a##b -static uint32 FT2[256] = { FT }; - -#undef V - -#define V(a,b,c,d) 0x##b##c##d##a -static uint32 FT3[256] = { FT }; - -#undef V - -#undef FT - -/* reverse S-box */ - -static uint32 RSb[256] = { - 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38, - 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB, - 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87, - 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB, - 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D, - 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E, - 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2, - 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25, - 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16, - 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92, - 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA, - 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84, - 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A, - 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06, - 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02, - 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B, - 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA, - 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73, - 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85, - 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E, - 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89, - 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B, - 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20, - 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4, - 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31, - 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F, - 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D, - 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF, - 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0, - 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61, - 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26, - 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D -}; - -/* reverse table */ - -#define RT \ -\ - V(51,F4,A7,50), V(7E,41,65,53), V(1A,17,A4,C3), V(3A,27,5E,96), \ - V(3B,AB,6B,CB), V(1F,9D,45,F1), V(AC,FA,58,AB), V(4B,E3,03,93), \ - V(20,30,FA,55), V(AD,76,6D,F6), V(88,CC,76,91), V(F5,02,4C,25), \ - V(4F,E5,D7,FC), V(C5,2A,CB,D7), V(26,35,44,80), V(B5,62,A3,8F), \ - V(DE,B1,5A,49), V(25,BA,1B,67), V(45,EA,0E,98), V(5D,FE,C0,E1), \ - V(C3,2F,75,02), V(81,4C,F0,12), V(8D,46,97,A3), V(6B,D3,F9,C6), \ - V(03,8F,5F,E7), V(15,92,9C,95), V(BF,6D,7A,EB), V(95,52,59,DA), \ - V(D4,BE,83,2D), V(58,74,21,D3), V(49,E0,69,29), V(8E,C9,C8,44), \ - V(75,C2,89,6A), V(F4,8E,79,78), V(99,58,3E,6B), V(27,B9,71,DD), \ - V(BE,E1,4F,B6), V(F0,88,AD,17), V(C9,20,AC,66), V(7D,CE,3A,B4), \ - V(63,DF,4A,18), V(E5,1A,31,82), V(97,51,33,60), V(62,53,7F,45), \ - V(B1,64,77,E0), V(BB,6B,AE,84), V(FE,81,A0,1C), V(F9,08,2B,94), \ - V(70,48,68,58), V(8F,45,FD,19), V(94,DE,6C,87), V(52,7B,F8,B7), \ - V(AB,73,D3,23), V(72,4B,02,E2), V(E3,1F,8F,57), V(66,55,AB,2A), \ - V(B2,EB,28,07), V(2F,B5,C2,03), V(86,C5,7B,9A), V(D3,37,08,A5), \ - V(30,28,87,F2), V(23,BF,A5,B2), V(02,03,6A,BA), V(ED,16,82,5C), \ - V(8A,CF,1C,2B), V(A7,79,B4,92), V(F3,07,F2,F0), V(4E,69,E2,A1), \ - V(65,DA,F4,CD), V(06,05,BE,D5), V(D1,34,62,1F), V(C4,A6,FE,8A), \ - V(34,2E,53,9D), V(A2,F3,55,A0), V(05,8A,E1,32), V(A4,F6,EB,75), \ - V(0B,83,EC,39), V(40,60,EF,AA), V(5E,71,9F,06), V(BD,6E,10,51), \ - V(3E,21,8A,F9), V(96,DD,06,3D), V(DD,3E,05,AE), V(4D,E6,BD,46), \ - V(91,54,8D,B5), V(71,C4,5D,05), V(04,06,D4,6F), V(60,50,15,FF), \ - V(19,98,FB,24), V(D6,BD,E9,97), V(89,40,43,CC), V(67,D9,9E,77), \ - V(B0,E8,42,BD), V(07,89,8B,88), V(E7,19,5B,38), V(79,C8,EE,DB), \ - V(A1,7C,0A,47), V(7C,42,0F,E9), V(F8,84,1E,C9), V(00,00,00,00), \ - V(09,80,86,83), V(32,2B,ED,48), V(1E,11,70,AC), V(6C,5A,72,4E), \ - V(FD,0E,FF,FB), V(0F,85,38,56), V(3D,AE,D5,1E), V(36,2D,39,27), \ - V(0A,0F,D9,64), V(68,5C,A6,21), V(9B,5B,54,D1), V(24,36,2E,3A), \ - V(0C,0A,67,B1), V(93,57,E7,0F), V(B4,EE,96,D2), V(1B,9B,91,9E), \ - V(80,C0,C5,4F), V(61,DC,20,A2), V(5A,77,4B,69), V(1C,12,1A,16), \ - V(E2,93,BA,0A), V(C0,A0,2A,E5), V(3C,22,E0,43), V(12,1B,17,1D), \ - V(0E,09,0D,0B), V(F2,8B,C7,AD), V(2D,B6,A8,B9), V(14,1E,A9,C8), \ - V(57,F1,19,85), V(AF,75,07,4C), V(EE,99,DD,BB), V(A3,7F,60,FD), \ - V(F7,01,26,9F), V(5C,72,F5,BC), V(44,66,3B,C5), V(5B,FB,7E,34), \ - V(8B,43,29,76), V(CB,23,C6,DC), V(B6,ED,FC,68), V(B8,E4,F1,63), \ - V(D7,31,DC,CA), V(42,63,85,10), V(13,97,22,40), V(84,C6,11,20), \ - V(85,4A,24,7D), V(D2,BB,3D,F8), V(AE,F9,32,11), V(C7,29,A1,6D), \ - V(1D,9E,2F,4B), V(DC,B2,30,F3), V(0D,86,52,EC), V(77,C1,E3,D0), \ - V(2B,B3,16,6C), V(A9,70,B9,99), V(11,94,48,FA), V(47,E9,64,22), \ - V(A8,FC,8C,C4), V(A0,F0,3F,1A), V(56,7D,2C,D8), V(22,33,90,EF), \ - V(87,49,4E,C7), V(D9,38,D1,C1), V(8C,CA,A2,FE), V(98,D4,0B,36), \ - V(A6,F5,81,CF), V(A5,7A,DE,28), V(DA,B7,8E,26), V(3F,AD,BF,A4), \ - V(2C,3A,9D,E4), V(50,78,92,0D), V(6A,5F,CC,9B), V(54,7E,46,62), \ - V(F6,8D,13,C2), V(90,D8,B8,E8), V(2E,39,F7,5E), V(82,C3,AF,F5), \ - V(9F,5D,80,BE), V(69,D0,93,7C), V(6F,D5,2D,A9), V(CF,25,12,B3), \ - V(C8,AC,99,3B), V(10,18,7D,A7), V(E8,9C,63,6E), V(DB,3B,BB,7B), \ - V(CD,26,78,09), V(6E,59,18,F4), V(EC,9A,B7,01), V(83,4F,9A,A8), \ - V(E6,95,6E,65), V(AA,FF,E6,7E), V(21,BC,CF,08), V(EF,15,E8,E6), \ - V(BA,E7,9B,D9), V(4A,6F,36,CE), V(EA,9F,09,D4), V(29,B0,7C,D6), \ - V(31,A4,B2,AF), V(2A,3F,23,31), V(C6,A5,94,30), V(35,A2,66,C0), \ - V(74,4E,BC,37), V(FC,82,CA,A6), V(E0,90,D0,B0), V(33,A7,D8,15), \ - V(F1,04,98,4A), V(41,EC,DA,F7), V(7F,CD,50,0E), V(17,91,F6,2F), \ - V(76,4D,D6,8D), V(43,EF,B0,4D), V(CC,AA,4D,54), V(E4,96,04,DF), \ - V(9E,D1,B5,E3), V(4C,6A,88,1B), V(C1,2C,1F,B8), V(46,65,51,7F), \ - V(9D,5E,EA,04), V(01,8C,35,5D), V(FA,87,74,73), V(FB,0B,41,2E), \ - V(B3,67,1D,5A), V(92,DB,D2,52), V(E9,10,56,33), V(6D,D6,47,13), \ - V(9A,D7,61,8C), V(37,A1,0C,7A), V(59,F8,14,8E), V(EB,13,3C,89), \ - V(CE,A9,27,EE), V(B7,61,C9,35), V(E1,1C,E5,ED), V(7A,47,B1,3C), \ - V(9C,D2,DF,59), V(55,F2,73,3F), V(18,14,CE,79), V(73,C7,37,BF), \ - V(53,F7,CD,EA), V(5F,FD,AA,5B), V(DF,3D,6F,14), V(78,44,DB,86), \ - V(CA,AF,F3,81), V(B9,68,C4,3E), V(38,24,34,2C), V(C2,A3,40,5F), \ - V(16,1D,C3,72), V(BC,E2,25,0C), V(28,3C,49,8B), V(FF,0D,95,41), \ - V(39,A8,01,71), V(08,0C,B3,DE), V(D8,B4,E4,9C), V(64,56,C1,90), \ - V(7B,CB,84,61), V(D5,32,B6,70), V(48,6C,5C,74), V(D0,B8,57,42) - -#define V(a,b,c,d) 0x##a##b##c##d -static uint32 RT0[256] = { RT }; - -#undef V - -#define V(a,b,c,d) 0x##d##a##b##c -static uint32 RT1[256] = { RT }; - -#undef V - -#define V(a,b,c,d) 0x##c##d##a##b -static uint32 RT2[256] = { RT }; - -#undef V - -#define V(a,b,c,d) 0x##b##c##d##a -static uint32 RT3[256] = { RT }; - -#undef V - -#undef RT - -/* round constants */ - -static uint32 RCON[10] = { - 0x01000000, 0x02000000, 0x04000000, 0x08000000, - 0x10000000, 0x20000000, 0x40000000, 0x80000000, - 0x1B000000, 0x36000000 -}; - -/* key schedule tables */ - -static int KT_init = 1; - -static uint32 KT0[256]; -static uint32 KT1[256]; -static uint32 KT2[256]; -static uint32 KT3[256]; - -/* platform-independent 32-bit integer manipulation macros */ - -#define GET_UINT32(n,b,i) \ -{ \ - (n) = ( (uint32) (b)[(i) ] << 24 ) \ - | ( (uint32) (b)[(i) + 1] << 16 ) \ - | ( (uint32) (b)[(i) + 2] << 8 ) \ - | ( (uint32) (b)[(i) + 3] ); \ -} - -#define PUT_UINT32(n,b,i) \ -{ \ - (b)[(i) ] = (uint8) ( (n) >> 24 ); \ - (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \ - (b)[(i) + 2] = (uint8) ( (n) >> 8 ); \ - (b)[(i) + 3] = (uint8) ( (n) ); \ -} - -int rt_aes_set_key(struct aes_context * ctx, uint8 * key, int nbits) -{ - int i; - uint32 *RK, *SK; - - switch (nbits) { - case 128: - ctx->nr = 10; - break; - case 192: - ctx->nr = 12; - break; - case 256: - ctx->nr = 14; - break; - default: - return (1); - } - - RK = (uint32 *) ctx->erk; - - for (i = 0; i < (nbits >> 5); i++) { - GET_UINT32(RK[i], key, i * 4); - } - - /* setup encryption round keys */ - - switch (nbits) { - case 128: - - for (i = 0; i < 10; i++, RK += 4) { - RK[4] = RK[0] ^ RCON[i] ^ - (FSb[(uint8) (RK[3] >> 16)] << 24) ^ - (FSb[(uint8) (RK[3] >> 8)] << 16) ^ - (FSb[(uint8) (RK[3])] << 8) ^ - (FSb[(uint8) (RK[3] >> 24)]); - - RK[5] = RK[1] ^ RK[4]; - RK[6] = RK[2] ^ RK[5]; - RK[7] = RK[3] ^ RK[6]; - } - break; - - case 192: - - for (i = 0; i < 8; i++, RK += 6) { - RK[6] = RK[0] ^ RCON[i] ^ - (FSb[(uint8) (RK[5] >> 16)] << 24) ^ - (FSb[(uint8) (RK[5] >> 8)] << 16) ^ - (FSb[(uint8) (RK[5])] << 8) ^ - (FSb[(uint8) (RK[5] >> 24)]); - - RK[7] = RK[1] ^ RK[6]; - RK[8] = RK[2] ^ RK[7]; - RK[9] = RK[3] ^ RK[8]; - RK[10] = RK[4] ^ RK[9]; - RK[11] = RK[5] ^ RK[10]; - } - break; - - case 256: - - for (i = 0; i < 7; i++, RK += 8) { - RK[8] = RK[0] ^ RCON[i] ^ - (FSb[(uint8) (RK[7] >> 16)] << 24) ^ - (FSb[(uint8) (RK[7] >> 8)] << 16) ^ - (FSb[(uint8) (RK[7])] << 8) ^ - (FSb[(uint8) (RK[7] >> 24)]); - - RK[9] = RK[1] ^ RK[8]; - RK[10] = RK[2] ^ RK[9]; - RK[11] = RK[3] ^ RK[10]; - - RK[12] = RK[4] ^ - (FSb[(uint8) (RK[11] >> 24)] << 24) ^ - (FSb[(uint8) (RK[11] >> 16)] << 16) ^ - (FSb[(uint8) (RK[11] >> 8)] << 8) ^ - (FSb[(uint8) (RK[11])]); - - RK[13] = RK[5] ^ RK[12]; - RK[14] = RK[6] ^ RK[13]; - RK[15] = RK[7] ^ RK[14]; - } - break; - } - - /* setup decryption round keys */ - - if (KT_init) { - for (i = 0; i < 256; i++) { - KT0[i] = RT0[FSb[i]]; - KT1[i] = RT1[FSb[i]]; - KT2[i] = RT2[FSb[i]]; - KT3[i] = RT3[FSb[i]]; - } - - KT_init = 0; - } - - SK = (uint32 *) ctx->drk; - - *SK++ = *RK++; - *SK++ = *RK++; - *SK++ = *RK++; - *SK++ = *RK++; - - for (i = 1; i < ctx->nr; i++) { - RK -= 8; - - *SK++ = KT0[(uint8) (*RK >> 24)] ^ - KT1[(uint8) (*RK >> 16)] ^ - KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)]; - RK++; - - *SK++ = KT0[(uint8) (*RK >> 24)] ^ - KT1[(uint8) (*RK >> 16)] ^ - KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)]; - RK++; - - *SK++ = KT0[(uint8) (*RK >> 24)] ^ - KT1[(uint8) (*RK >> 16)] ^ - KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)]; - RK++; - - *SK++ = KT0[(uint8) (*RK >> 24)] ^ - KT1[(uint8) (*RK >> 16)] ^ - KT2[(uint8) (*RK >> 8)] ^ KT3[(uint8) (*RK)]; - RK++; - } - - RK -= 8; - - *SK++ = *RK++; - *SK++ = *RK++; - *SK++ = *RK++; - *SK++ = *RK++; - - return (0); -} - -/* AES 128-bit block encryption routine */ - -void rt_aes_encrypt(struct aes_context * ctx, uint8 input[16], uint8 output[16]) -{ - uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; - - RK = (uint32 *) ctx->erk; - GET_UINT32(X0, input, 0); - X0 ^= RK[0]; - GET_UINT32(X1, input, 4); - X1 ^= RK[1]; - GET_UINT32(X2, input, 8); - X2 ^= RK[2]; - GET_UINT32(X3, input, 12); - X3 ^= RK[3]; - -#define AES_FROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ -{ \ - RK += 4; \ - \ - X0 = RK[0] ^ FT0[ (uint8) ( Y0 >> 24 ) ] ^ \ - FT1[ (uint8) ( Y1 >> 16 ) ] ^ \ - FT2[ (uint8) ( Y2 >> 8 ) ] ^ \ - FT3[ (uint8) ( Y3 ) ]; \ - \ - X1 = RK[1] ^ FT0[ (uint8) ( Y1 >> 24 ) ] ^ \ - FT1[ (uint8) ( Y2 >> 16 ) ] ^ \ - FT2[ (uint8) ( Y3 >> 8 ) ] ^ \ - FT3[ (uint8) ( Y0 ) ]; \ - \ - X2 = RK[2] ^ FT0[ (uint8) ( Y2 >> 24 ) ] ^ \ - FT1[ (uint8) ( Y3 >> 16 ) ] ^ \ - FT2[ (uint8) ( Y0 >> 8 ) ] ^ \ - FT3[ (uint8) ( Y1 ) ]; \ - \ - X3 = RK[3] ^ FT0[ (uint8) ( Y3 >> 24 ) ] ^ \ - FT1[ (uint8) ( Y0 >> 16 ) ] ^ \ - FT2[ (uint8) ( Y1 >> 8 ) ] ^ \ - FT3[ (uint8) ( Y2 ) ]; \ -} - - AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 1 */ - AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 2 */ - AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 3 */ - AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 4 */ - AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 5 */ - AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 6 */ - AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 7 */ - AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 8 */ - AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 9 */ - - if (ctx->nr > 10) { - AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 10 */ - AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 11 */ - } - - if (ctx->nr > 12) { - AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 12 */ - AES_FROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 13 */ - } - - /* last round */ - - RK += 4; - - X0 = RK[0] ^ (FSb[(uint8) (Y0 >> 24)] << 24) ^ - (FSb[(uint8) (Y1 >> 16)] << 16) ^ - (FSb[(uint8) (Y2 >> 8)] << 8) ^ (FSb[(uint8) (Y3)]); - - X1 = RK[1] ^ (FSb[(uint8) (Y1 >> 24)] << 24) ^ - (FSb[(uint8) (Y2 >> 16)] << 16) ^ - (FSb[(uint8) (Y3 >> 8)] << 8) ^ (FSb[(uint8) (Y0)]); - - X2 = RK[2] ^ (FSb[(uint8) (Y2 >> 24)] << 24) ^ - (FSb[(uint8) (Y3 >> 16)] << 16) ^ - (FSb[(uint8) (Y0 >> 8)] << 8) ^ (FSb[(uint8) (Y1)]); - - X3 = RK[3] ^ (FSb[(uint8) (Y3 >> 24)] << 24) ^ - (FSb[(uint8) (Y0 >> 16)] << 16) ^ - (FSb[(uint8) (Y1 >> 8)] << 8) ^ (FSb[(uint8) (Y2)]); - - PUT_UINT32(X0, output, 0); - PUT_UINT32(X1, output, 4); - PUT_UINT32(X2, output, 8); - PUT_UINT32(X3, output, 12); -} - -/* AES 128-bit block decryption routine */ - -void rt_aes_decrypt(struct aes_context * ctx, uint8 input[16], uint8 output[16]) -{ - uint32 *RK, X0, X1, X2, X3, Y0, Y1, Y2, Y3; - - RK = (uint32 *) ctx->drk; - - GET_UINT32(X0, input, 0); - X0 ^= RK[0]; - GET_UINT32(X1, input, 4); - X1 ^= RK[1]; - GET_UINT32(X2, input, 8); - X2 ^= RK[2]; - GET_UINT32(X3, input, 12); - X3 ^= RK[3]; - -#define AES_RROUND(X0,X1,X2,X3,Y0,Y1,Y2,Y3) \ -{ \ - RK += 4; \ - \ - X0 = RK[0] ^ RT0[ (uint8) ( Y0 >> 24 ) ] ^ \ - RT1[ (uint8) ( Y3 >> 16 ) ] ^ \ - RT2[ (uint8) ( Y2 >> 8 ) ] ^ \ - RT3[ (uint8) ( Y1 ) ]; \ - \ - X1 = RK[1] ^ RT0[ (uint8) ( Y1 >> 24 ) ] ^ \ - RT1[ (uint8) ( Y0 >> 16 ) ] ^ \ - RT2[ (uint8) ( Y3 >> 8 ) ] ^ \ - RT3[ (uint8) ( Y2 ) ]; \ - \ - X2 = RK[2] ^ RT0[ (uint8) ( Y2 >> 24 ) ] ^ \ - RT1[ (uint8) ( Y1 >> 16 ) ] ^ \ - RT2[ (uint8) ( Y0 >> 8 ) ] ^ \ - RT3[ (uint8) ( Y3 ) ]; \ - \ - X3 = RK[3] ^ RT0[ (uint8) ( Y3 >> 24 ) ] ^ \ - RT1[ (uint8) ( Y2 >> 16 ) ] ^ \ - RT2[ (uint8) ( Y1 >> 8 ) ] ^ \ - RT3[ (uint8) ( Y0 ) ]; \ -} - - AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 1 */ - AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 2 */ - AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 3 */ - AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 4 */ - AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 5 */ - AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 6 */ - AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 7 */ - AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 8 */ - AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 9 */ - - if (ctx->nr > 10) { - AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 10 */ - AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 11 */ - } - - if (ctx->nr > 12) { - AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3); /* round 12 */ - AES_RROUND(Y0, Y1, Y2, Y3, X0, X1, X2, X3); /* round 13 */ - } - - /* last round */ - - RK += 4; - - X0 = RK[0] ^ (RSb[(uint8) (Y0 >> 24)] << 24) ^ - (RSb[(uint8) (Y3 >> 16)] << 16) ^ - (RSb[(uint8) (Y2 >> 8)] << 8) ^ (RSb[(uint8) (Y1)]); - - X1 = RK[1] ^ (RSb[(uint8) (Y1 >> 24)] << 24) ^ - (RSb[(uint8) (Y0 >> 16)] << 16) ^ - (RSb[(uint8) (Y3 >> 8)] << 8) ^ (RSb[(uint8) (Y2)]); - - X2 = RK[2] ^ (RSb[(uint8) (Y2 >> 24)] << 24) ^ - (RSb[(uint8) (Y1 >> 16)] << 16) ^ - (RSb[(uint8) (Y0 >> 8)] << 8) ^ (RSb[(uint8) (Y3)]); - - X3 = RK[3] ^ (RSb[(uint8) (Y3 >> 24)] << 24) ^ - (RSb[(uint8) (Y2 >> 16)] << 16) ^ - (RSb[(uint8) (Y1 >> 8)] << 8) ^ (RSb[(uint8) (Y0)]); - - PUT_UINT32(X0, output, 0); - PUT_UINT32(X1, output, 4); - PUT_UINT32(X2, output, 8); - PUT_UINT32(X3, output, 12); -} - -/* - ========================================================================== - Description: - ENCRYPT AES GTK before sending in EAPOL frame. - AES GTK length = 128 bit, so fix blocks for aes-key-wrap as 2 in this function. - This function references to RFC 3394 for aes key wrap algorithm. - Return: - ========================================================================== -*/ -void AES_GTK_KEY_WRAP(u8 * key, - u8 * plaintext, - u32 p_len, u8 * ciphertext) -{ - u8 A[8], BIN[16], BOUT[16]; - u8 R[512]; - int num_blocks = p_len / 8; /* unit:64bits */ - int i, j; - struct aes_context aesctx; - u8 xor; - - rt_aes_set_key(&aesctx, key, 128); - - /* Init IA */ - for (i = 0; i < 8; i++) - A[i] = 0xa6; - - /*Input plaintext */ - for (i = 0; i < num_blocks; i++) { - for (j = 0; j < 8; j++) - R[8 * (i + 1) + j] = plaintext[8 * i + j]; - } - - /* Key Mix */ - for (j = 0; j < 6; j++) { - for (i = 1; i <= num_blocks; i++) { - /*phase 1 */ - NdisMoveMemory(BIN, A, 8); - NdisMoveMemory(&BIN[8], &R[8 * i], 8); - rt_aes_encrypt(&aesctx, BIN, BOUT); - - NdisMoveMemory(A, &BOUT[0], 8); - xor = num_blocks * j + i; - A[7] = BOUT[7] ^ xor; - NdisMoveMemory(&R[8 * i], &BOUT[8], 8); - } - } - - /* Output ciphertext */ - NdisMoveMemory(ciphertext, A, 8); - - for (i = 1; i <= num_blocks; i++) { - for (j = 0; j < 8; j++) - ciphertext[8 * i + j] = R[8 * i + j]; - } -} - -/* - ======================================================================== - - Routine Description: - Misc function to decrypt AES body - - Arguments: - - Return Value: - - Note: - This function references to RFC 3394 for aes key unwrap algorithm. - - ======================================================================== -*/ -void AES_GTK_KEY_UNWRAP(u8 * key, - u8 * plaintext, - u32 c_len, u8 * ciphertext) -{ - u8 A[8], BIN[16], BOUT[16]; - u8 xor; - int i, j; - struct aes_context aesctx; - u8 *R; - int num_blocks = c_len / 8; /* unit:64bits */ - - os_alloc_mem(NULL, (u8 **) & R, 512); - - if (R == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("AES_GTK_KEY_UNWRAP: no memory!\n")); - return; - } - /* End of if */ - /* Initialize */ - NdisMoveMemory(A, ciphertext, 8); - /*Input plaintext */ - for (i = 0; i < (c_len - 8); i++) { - R[i] = ciphertext[i + 8]; - } - - rt_aes_set_key(&aesctx, key, 128); - - for (j = 5; j >= 0; j--) { - for (i = (num_blocks - 1); i > 0; i--) { - xor = (num_blocks - 1) * j + i; - NdisMoveMemory(BIN, A, 8); - BIN[7] = A[7] ^ xor; - NdisMoveMemory(&BIN[8], &R[(i - 1) * 8], 8); - rt_aes_decrypt(&aesctx, BIN, BOUT); - NdisMoveMemory(A, &BOUT[0], 8); - NdisMoveMemory(&R[(i - 1) * 8], &BOUT[8], 8); - } - } - - /* OUTPUT */ - for (i = 0; i < c_len; i++) { - plaintext[i] = R[i]; - } - - os_free_mem(NULL, R); -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_asic.c b/trunk/drivers/staging/rt2860/common/cmm_asic.c deleted file mode 100644 index 4d77e83eb418..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_asic.c +++ /dev/null @@ -1,2565 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - cmm_asic.c - - Abstract: - Functions used to communicate with ASIC - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ - -#include "../rt_config.h" - -/* Reset the RFIC setting to new series */ -struct rt_rtmp_rf_regs RF2850RegTable[] = { -/* ch R1 R2 R3(TX0~4=0) R4 */ - {1, 0x98402ecc, 0x984c0786, 0x9816b455, 0x9800510b} - , - {2, 0x98402ecc, 0x984c0786, 0x98168a55, 0x9800519f} - , - {3, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800518b} - , - {4, 0x98402ecc, 0x984c078a, 0x98168a55, 0x9800519f} - , - {5, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800518b} - , - {6, 0x98402ecc, 0x984c078e, 0x98168a55, 0x9800519f} - , - {7, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800518b} - , - {8, 0x98402ecc, 0x984c0792, 0x98168a55, 0x9800519f} - , - {9, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800518b} - , - {10, 0x98402ecc, 0x984c0796, 0x98168a55, 0x9800519f} - , - {11, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800518b} - , - {12, 0x98402ecc, 0x984c079a, 0x98168a55, 0x9800519f} - , - {13, 0x98402ecc, 0x984c079e, 0x98168a55, 0x9800518b} - , - {14, 0x98402ecc, 0x984c07a2, 0x98168a55, 0x98005193} - , - - /* 802.11 UNI / HyperLan 2 */ - {36, 0x98402ecc, 0x984c099a, 0x98158a55, 0x980ed1a3} - , - {38, 0x98402ecc, 0x984c099e, 0x98158a55, 0x980ed193} - , - {40, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed183} - , - {44, 0x98402ec8, 0x984c0682, 0x98158a55, 0x980ed1a3} - , - {46, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed18b} - , - {48, 0x98402ec8, 0x984c0686, 0x98158a55, 0x980ed19b} - , - {52, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed193} - , - {54, 0x98402ec8, 0x984c068a, 0x98158a55, 0x980ed1a3} - , - {56, 0x98402ec8, 0x984c068e, 0x98158a55, 0x980ed18b} - , - {60, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed183} - , - {62, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed193} - , - {64, 0x98402ec8, 0x984c0692, 0x98158a55, 0x980ed1a3} - , /* Plugfest#4, Day4, change RFR3 left4th 9->5. */ - - /* 802.11 HyperLan 2 */ - {100, 0x98402ec8, 0x984c06b2, 0x98178a55, 0x980ed783} - , - - /* 2008.04.30 modified */ - /* The system team has AN to improve the EVM value */ - /* for channel 102 to 108 for the RT2850/RT2750 dual band solution. */ - {102, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed793} - , - {104, 0x98402ec8, 0x985c06b2, 0x98578a55, 0x980ed1a3} - , - {108, 0x98402ecc, 0x985c0a32, 0x98578a55, 0x980ed193} - , - - {110, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed183} - , - {112, 0x98402ecc, 0x984c0a36, 0x98178a55, 0x980ed19b} - , - {116, 0x98402ecc, 0x984c0a3a, 0x98178a55, 0x980ed1a3} - , - {118, 0x98402ecc, 0x984c0a3e, 0x98178a55, 0x980ed193} - , - {120, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed183} - , - {124, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed193} - , - {126, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed15b} - , /* 0x980ed1bb->0x980ed15b required by Rory 20070927 */ - {128, 0x98402ec4, 0x984c0382, 0x98178a55, 0x980ed1a3} - , - {132, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed18b} - , - {134, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed193} - , - {136, 0x98402ec4, 0x984c0386, 0x98178a55, 0x980ed19b} - , - {140, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed183} - , - - /* 802.11 UNII */ - {149, 0x98402ec4, 0x984c038a, 0x98178a55, 0x980ed1a7} - , - {151, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed187} - , - {153, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed18f} - , - {157, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed19f} - , - {159, 0x98402ec4, 0x984c038e, 0x98178a55, 0x980ed1a7} - , - {161, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed187} - , - {165, 0x98402ec4, 0x984c0392, 0x98178a55, 0x980ed197} - , - {167, 0x98402ec4, 0x984c03d2, 0x98179855, 0x9815531f} - , - {169, 0x98402ec4, 0x984c03d2, 0x98179855, 0x98155327} - , - {171, 0x98402ec4, 0x984c03d6, 0x98179855, 0x98155307} - , - {173, 0x98402ec4, 0x984c03d6, 0x98179855, 0x9815530f} - , - - /* Japan */ - {184, 0x95002ccc, 0x9500491e, 0x9509be55, 0x950c0a0b} - , - {188, 0x95002ccc, 0x95004922, 0x9509be55, 0x950c0a13} - , - {192, 0x95002ccc, 0x95004926, 0x9509be55, 0x950c0a1b} - , - {196, 0x95002ccc, 0x9500492a, 0x9509be55, 0x950c0a23} - , - {208, 0x95002ccc, 0x9500493a, 0x9509be55, 0x950c0a13} - , - {212, 0x95002ccc, 0x9500493e, 0x9509be55, 0x950c0a1b} - , - {216, 0x95002ccc, 0x95004982, 0x9509be55, 0x950c0a23} - , - - /* still lack of MMAC(Japan) ch 34,38,42,46 */ -}; - -u8 NUM_OF_2850_CHNL = (sizeof(RF2850RegTable) / sizeof(struct rt_rtmp_rf_regs)); - -struct rt_frequency_item FreqItems3020[] = { - /**************************************************/ - /* ISM : 2.4 to 2.483 GHz // */ - /**************************************************/ - /* 11g */ - /**************************************************/ - /*-CH---N-------R---K----------- */ - {1, 241, 2, 2} - , - {2, 241, 2, 7} - , - {3, 242, 2, 2} - , - {4, 242, 2, 7} - , - {5, 243, 2, 2} - , - {6, 243, 2, 7} - , - {7, 244, 2, 2} - , - {8, 244, 2, 7} - , - {9, 245, 2, 2} - , - {10, 245, 2, 7} - , - {11, 246, 2, 2} - , - {12, 246, 2, 7} - , - {13, 247, 2, 2} - , - {14, 248, 2, 4} - , -}; - -u8 NUM_OF_3020_CHNL = (sizeof(FreqItems3020) / sizeof(struct rt_frequency_item)); - -void AsicUpdateAutoFallBackTable(struct rt_rtmp_adapter *pAd, u8 *pRateTable) -{ - u8 i; - HT_FBK_CFG0_STRUC HtCfg0; - HT_FBK_CFG1_STRUC HtCfg1; - LG_FBK_CFG0_STRUC LgCfg0; - LG_FBK_CFG1_STRUC LgCfg1; - struct rt_rtmp_tx_rate_switch *pCurrTxRate, *pNextTxRate; - - /* set to initial value */ - HtCfg0.word = 0x65432100; - HtCfg1.word = 0xedcba988; - LgCfg0.word = 0xedcba988; - LgCfg1.word = 0x00002100; - - pNextTxRate = (struct rt_rtmp_tx_rate_switch *) pRateTable + 1; - for (i = 1; i < *((u8 *)pRateTable); i++) { - pCurrTxRate = (struct rt_rtmp_tx_rate_switch *) pRateTable + 1 + i; - switch (pCurrTxRate->Mode) { - case 0: /*CCK */ - break; - case 1: /*OFDM */ - { - switch (pCurrTxRate->CurrMCS) { - case 0: - LgCfg0.field.OFDMMCS0FBK = - (pNextTxRate->Mode == - MODE_OFDM) ? (pNextTxRate-> - CurrMCS + - 8) : pNextTxRate-> - CurrMCS; - break; - case 1: - LgCfg0.field.OFDMMCS1FBK = - (pNextTxRate->Mode == - MODE_OFDM) ? (pNextTxRate-> - CurrMCS + - 8) : pNextTxRate-> - CurrMCS; - break; - case 2: - LgCfg0.field.OFDMMCS2FBK = - (pNextTxRate->Mode == - MODE_OFDM) ? (pNextTxRate-> - CurrMCS + - 8) : pNextTxRate-> - CurrMCS; - break; - case 3: - LgCfg0.field.OFDMMCS3FBK = - (pNextTxRate->Mode == - MODE_OFDM) ? (pNextTxRate-> - CurrMCS + - 8) : pNextTxRate-> - CurrMCS; - break; - case 4: - LgCfg0.field.OFDMMCS4FBK = - (pNextTxRate->Mode == - MODE_OFDM) ? (pNextTxRate-> - CurrMCS + - 8) : pNextTxRate-> - CurrMCS; - break; - case 5: - LgCfg0.field.OFDMMCS5FBK = - (pNextTxRate->Mode == - MODE_OFDM) ? (pNextTxRate-> - CurrMCS + - 8) : pNextTxRate-> - CurrMCS; - break; - case 6: - LgCfg0.field.OFDMMCS6FBK = - (pNextTxRate->Mode == - MODE_OFDM) ? (pNextTxRate-> - CurrMCS + - 8) : pNextTxRate-> - CurrMCS; - break; - case 7: - LgCfg0.field.OFDMMCS7FBK = - (pNextTxRate->Mode == - MODE_OFDM) ? (pNextTxRate-> - CurrMCS + - 8) : pNextTxRate-> - CurrMCS; - break; - } - } - break; - case 2: /*HT-MIX */ - case 3: /*HT-GF */ - { - if ((pNextTxRate->Mode >= MODE_HTMIX) - && (pCurrTxRate->CurrMCS != - pNextTxRate->CurrMCS)) { - switch (pCurrTxRate->CurrMCS) { - case 0: - HtCfg0.field.HTMCS0FBK = - pNextTxRate->CurrMCS; - break; - case 1: - HtCfg0.field.HTMCS1FBK = - pNextTxRate->CurrMCS; - break; - case 2: - HtCfg0.field.HTMCS2FBK = - pNextTxRate->CurrMCS; - break; - case 3: - HtCfg0.field.HTMCS3FBK = - pNextTxRate->CurrMCS; - break; - case 4: - HtCfg0.field.HTMCS4FBK = - pNextTxRate->CurrMCS; - break; - case 5: - HtCfg0.field.HTMCS5FBK = - pNextTxRate->CurrMCS; - break; - case 6: - HtCfg0.field.HTMCS6FBK = - pNextTxRate->CurrMCS; - break; - case 7: - HtCfg0.field.HTMCS7FBK = - pNextTxRate->CurrMCS; - break; - case 8: - HtCfg1.field.HTMCS8FBK = - pNextTxRate->CurrMCS; - break; - case 9: - HtCfg1.field.HTMCS9FBK = - pNextTxRate->CurrMCS; - break; - case 10: - HtCfg1.field.HTMCS10FBK = - pNextTxRate->CurrMCS; - break; - case 11: - HtCfg1.field.HTMCS11FBK = - pNextTxRate->CurrMCS; - break; - case 12: - HtCfg1.field.HTMCS12FBK = - pNextTxRate->CurrMCS; - break; - case 13: - HtCfg1.field.HTMCS13FBK = - pNextTxRate->CurrMCS; - break; - case 14: - HtCfg1.field.HTMCS14FBK = - pNextTxRate->CurrMCS; - break; - case 15: - HtCfg1.field.HTMCS15FBK = - pNextTxRate->CurrMCS; - break; - default: - DBGPRINT(RT_DEBUG_ERROR, - ("AsicUpdateAutoFallBackTable: not support CurrMCS=%d\n", - pCurrTxRate-> - CurrMCS)); - } - } - } - break; - } - - pNextTxRate = pCurrTxRate; - } - - RTMP_IO_WRITE32(pAd, HT_FBK_CFG0, HtCfg0.word); - RTMP_IO_WRITE32(pAd, HT_FBK_CFG1, HtCfg1.word); - RTMP_IO_WRITE32(pAd, LG_FBK_CFG0, LgCfg0.word); - RTMP_IO_WRITE32(pAd, LG_FBK_CFG1, LgCfg1.word); -} - -/* - ======================================================================== - - Routine Description: - Set MAC register value according operation mode. - OperationMode AND bNonGFExist are for MM and GF Proteciton. - If MM or GF mask is not set, those passing argument doesn't not take effect. - - Operation mode meaning: - = 0 : Pure HT, no preotection. - = 0x01; there may be non-HT devices in both the control and extension channel, protection is optional in BSS. - = 0x10: No Transmission in 40M is protected. - = 0x11: Transmission in both 40M and 20M shall be protected - if (bNonGFExist) - we should choose not to use GF. But still set correct ASIC registers. - ======================================================================== -*/ -void AsicUpdateProtect(struct rt_rtmp_adapter *pAd, - u16 OperationMode, - u8 SetMask, - IN BOOLEAN bDisableBGProtect, IN BOOLEAN bNonGFExist) -{ - PROT_CFG_STRUC ProtCfg, ProtCfg4; - u32 Protect[6]; - u16 offset; - u8 i; - u32 MacReg = 0; - - if (!(pAd->CommonCfg.bHTProtect) && (OperationMode != 8)) { - return; - } - - if (pAd->BATable.numDoneOriginator) { - /* */ - /* enable the RTS/CTS to avoid channel collision */ - /* */ - SetMask = ALLN_SETPROTECT; - OperationMode = 8; - } - /* Config ASIC RTS threshold register */ - RTMP_IO_READ32(pAd, TX_RTS_CFG, &MacReg); - MacReg &= 0xFF0000FF; - /* If the user want disable RtsThreshold and enable Amsdu/Ralink-Aggregation, set the RtsThreshold as 4096 */ - if (((pAd->CommonCfg.BACapability.field.AmsduEnable) || - (pAd->CommonCfg.bAggregationCapable == TRUE)) - && pAd->CommonCfg.RtsThreshold == MAX_RTS_THRESHOLD) { - MacReg |= (0x1000 << 8); - } else { - MacReg |= (pAd->CommonCfg.RtsThreshold << 8); - } - - RTMP_IO_WRITE32(pAd, TX_RTS_CFG, MacReg); - - /* Initial common protection settings */ - RTMPZeroMemory(Protect, sizeof(Protect)); - ProtCfg4.word = 0; - ProtCfg.word = 0; - ProtCfg.field.TxopAllowGF40 = 1; - ProtCfg.field.TxopAllowGF20 = 1; - ProtCfg.field.TxopAllowMM40 = 1; - ProtCfg.field.TxopAllowMM20 = 1; - ProtCfg.field.TxopAllowOfdm = 1; - ProtCfg.field.TxopAllowCck = 1; - ProtCfg.field.RTSThEn = 1; - ProtCfg.field.ProtectNav = ASIC_SHORTNAV; - - /* update PHY mode and rate */ - if (pAd->CommonCfg.Channel > 14) - ProtCfg.field.ProtectRate = 0x4000; - ProtCfg.field.ProtectRate |= pAd->CommonCfg.RtsRate; - - /* Handle legacy(B/G) protection */ - if (bDisableBGProtect) { - /*ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate; */ - ProtCfg.field.ProtectCtrl = 0; - Protect[0] = ProtCfg.word; - Protect[1] = ProtCfg.word; - pAd->FlgCtsEnabled = 0; /* CTS-self is not used */ - } else { - /*ProtCfg.field.ProtectRate = pAd->CommonCfg.RtsRate; */ - ProtCfg.field.ProtectCtrl = 0; /* CCK do not need to be protected */ - Protect[0] = ProtCfg.word; - ProtCfg.field.ProtectCtrl = ASIC_CTS; /* OFDM needs using CCK to protect */ - Protect[1] = ProtCfg.word; - pAd->FlgCtsEnabled = 1; /* CTS-self is used */ - } - - /* Decide HT frame protection. */ - if ((SetMask & ALLN_SETPROTECT) != 0) { - switch (OperationMode) { - case 0x0: - /* NO PROTECT */ - /* 1.All STAs in the BSS are 20/40 MHz HT */ - /* 2. in ai 20/40MHz BSS */ - /* 3. all STAs are 20MHz in a 20MHz BSS */ - /* Pure HT. no protection. */ - - /* MM20_PROT_CFG */ - /* Reserved (31:27) */ - /* PROT_TXOP(25:20) -- 010111 */ - /* PROT_NAV(19:18) -- 01 (Short NAV protection) */ - /* PROT_CTRL(17:16) -- 00 (None) */ - /* PROT_RATE(15:0) -- 0x4004 (OFDM 24M) */ - Protect[2] = 0x01744004; - - /* MM40_PROT_CFG */ - /* Reserved (31:27) */ - /* PROT_TXOP(25:20) -- 111111 */ - /* PROT_NAV(19:18) -- 01 (Short NAV protection) */ - /* PROT_CTRL(17:16) -- 00 (None) */ - /* PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M) */ - Protect[3] = 0x03f44084; - - /* CF20_PROT_CFG */ - /* Reserved (31:27) */ - /* PROT_TXOP(25:20) -- 010111 */ - /* PROT_NAV(19:18) -- 01 (Short NAV protection) */ - /* PROT_CTRL(17:16) -- 00 (None) */ - /* PROT_RATE(15:0) -- 0x4004 (OFDM 24M) */ - Protect[4] = 0x01744004; - - /* CF40_PROT_CFG */ - /* Reserved (31:27) */ - /* PROT_TXOP(25:20) -- 111111 */ - /* PROT_NAV(19:18) -- 01 (Short NAV protection) */ - /* PROT_CTRL(17:16) -- 00 (None) */ - /* PROT_RATE(15:0) -- 0x4084 (duplicate OFDM 24M) */ - Protect[5] = 0x03f44084; - - if (bNonGFExist) { - /* PROT_NAV(19:18) -- 01 (Short NAV protectiion) */ - /* PROT_CTRL(17:16) -- 01 (RTS/CTS) */ - Protect[4] = 0x01754004; - Protect[5] = 0x03f54084; - } - pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE; - break; - - case 1: - /* This is "HT non-member protection mode." */ - /* If there may be non-HT STAs my BSS */ - ProtCfg.word = 0x01744004; /* PROT_CTRL(17:16) : 0 (None) */ - ProtCfg4.word = 0x03f44084; /* duplicaet legacy 24M. BW set 1. */ - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_BG_PROTECTION_INUSED)) { - ProtCfg.word = 0x01740003; /*ERP use Protection bit is set, use protection rate at Clause 18.. */ - ProtCfg4.word = 0x03f40003; /* Don't duplicate RTS/CTS in CCK mode. 0x03f40083; */ - } - /*Assign Protection method for 20&40 MHz packets */ - ProtCfg.field.ProtectCtrl = ASIC_RTS; - ProtCfg.field.ProtectNav = ASIC_SHORTNAV; - ProtCfg4.field.ProtectCtrl = ASIC_RTS; - ProtCfg4.field.ProtectNav = ASIC_SHORTNAV; - Protect[2] = ProtCfg.word; - Protect[3] = ProtCfg4.word; - Protect[4] = ProtCfg.word; - Protect[5] = ProtCfg4.word; - pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE; - break; - - case 2: - /* If only HT STAs are in BSS. at least one is 20MHz. Only protect 40MHz packets */ - ProtCfg.word = 0x01744004; /* PROT_CTRL(17:16) : 0 (None) */ - ProtCfg4.word = 0x03f44084; /* duplicaet legacy 24M. BW set 1. */ - - /*Assign Protection method for 40MHz packets */ - ProtCfg4.field.ProtectCtrl = ASIC_RTS; - ProtCfg4.field.ProtectNav = ASIC_SHORTNAV; - Protect[2] = ProtCfg.word; - Protect[3] = ProtCfg4.word; - if (bNonGFExist) { - ProtCfg.field.ProtectCtrl = ASIC_RTS; - ProtCfg.field.ProtectNav = ASIC_SHORTNAV; - } - Protect[4] = ProtCfg.word; - Protect[5] = ProtCfg4.word; - - pAd->CommonCfg.IOTestParm.bRTSLongProtOn = FALSE; - break; - - case 3: - /* HT mixed mode. PROTECT ALL! */ - /* Assign Rate */ - ProtCfg.word = 0x01744004; /*duplicaet legacy 24M. BW set 1. */ - ProtCfg4.word = 0x03f44084; - /* both 20MHz and 40MHz are protected. Whether use RTS or CTS-to-self depends on the */ - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_BG_PROTECTION_INUSED)) { - ProtCfg.word = 0x01740003; /*ERP use Protection bit is set, use protection rate at Clause 18.. */ - ProtCfg4.word = 0x03f40003; /* Don't duplicate RTS/CTS in CCK mode. 0x03f40083 */ - } - /*Assign Protection method for 20&40 MHz packets */ - ProtCfg.field.ProtectCtrl = ASIC_RTS; - ProtCfg.field.ProtectNav = ASIC_SHORTNAV; - ProtCfg4.field.ProtectCtrl = ASIC_RTS; - ProtCfg4.field.ProtectNav = ASIC_SHORTNAV; - Protect[2] = ProtCfg.word; - Protect[3] = ProtCfg4.word; - Protect[4] = ProtCfg.word; - Protect[5] = ProtCfg4.word; - pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE; - break; - - case 8: - /* Special on for Atheros problem n chip. */ - Protect[2] = 0x01754004; - Protect[3] = 0x03f54084; - Protect[4] = 0x01754004; - Protect[5] = 0x03f54084; - pAd->CommonCfg.IOTestParm.bRTSLongProtOn = TRUE; - break; - } - } - - offset = CCK_PROT_CFG; - for (i = 0; i < 6; i++) { - if ((SetMask & (1 << i))) { - RTMP_IO_WRITE32(pAd, offset + i * 4, Protect[i]); - } - } -} - -/* - ========================================================================== - Description: - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicSwitchChannel(struct rt_rtmp_adapter *pAd, u8 Channel, IN BOOLEAN bScan) -{ - unsigned long R2 = 0, R3 = DEFAULT_RF_TX_POWER, R4 = 0; - char TxPwer = 0, TxPwer2 = DEFAULT_RF_TX_POWER; /*Bbp94 = BBPR94_DEFAULT, TxPwer2 = DEFAULT_RF_TX_POWER; */ - u8 index; - u32 Value = 0; /*BbpReg, Value; */ - struct rt_rtmp_rf_regs *RFRegTable; - u8 RFValue; - - RFValue = 0; - /* Search Tx power value */ - /* We can't use ChannelList to search channel, since some central channl's txpowr doesn't list */ - /* in ChannelList, so use TxPower array instead. */ - /* */ - for (index = 0; index < MAX_NUM_OF_CHANNELS; index++) { - if (Channel == pAd->TxPower[index].Channel) { - TxPwer = pAd->TxPower[index].Power; - TxPwer2 = pAd->TxPower[index].Power2; - break; - } - } - - if (index == MAX_NUM_OF_CHANNELS) { - DBGPRINT(RT_DEBUG_ERROR, - ("AsicSwitchChannel: Can't find the Channel#%d \n", - Channel)); - } -#ifdef RT30xx - /* The RF programming sequence is difference between 3xxx and 2xxx */ - if ((IS_RT3070(pAd) || IS_RT3090(pAd) || IS_RT3390(pAd)) - && ((pAd->RfIcType == RFIC_3020) || (pAd->RfIcType == RFIC_2020) - || (pAd->RfIcType == RFIC_3021) - || (pAd->RfIcType == RFIC_3022))) { - /* modify by WY for Read RF Reg. error */ - - for (index = 0; index < NUM_OF_3020_CHNL; index++) { - if (Channel == FreqItems3020[index].Channel) { - /* Programming channel parameters */ - RT30xxWriteRFRegister(pAd, RF_R02, - FreqItems3020[index].N); - RT30xxWriteRFRegister(pAd, RF_R03, - FreqItems3020[index].K); - RT30xxReadRFRegister(pAd, RF_R06, &RFValue); - RFValue = - (RFValue & 0xFC) | FreqItems3020[index].R; - RT30xxWriteRFRegister(pAd, RF_R06, RFValue); - - /* Set Tx0 Power */ - RT30xxReadRFRegister(pAd, RF_R12, &RFValue); - RFValue = (RFValue & 0xE0) | TxPwer; - RT30xxWriteRFRegister(pAd, RF_R12, RFValue); - - /* Set Tx1 Power */ - RT30xxReadRFRegister(pAd, RF_R13, &RFValue); - RFValue = (RFValue & 0xE0) | TxPwer2; - RT30xxWriteRFRegister(pAd, RF_R13, RFValue); - - /* Tx/Rx Stream setting */ - RT30xxReadRFRegister(pAd, RF_R01, &RFValue); - /*if (IS_RT3090(pAd)) */ - /* RFValue |= 0x01; // Enable RF block. */ - RFValue &= 0x03; /*clear bit[7~2] */ - if (pAd->Antenna.field.TxPath == 1) - RFValue |= 0xA0; - else if (pAd->Antenna.field.TxPath == 2) - RFValue |= 0x80; - if (pAd->Antenna.field.RxPath == 1) - RFValue |= 0x50; - else if (pAd->Antenna.field.RxPath == 2) - RFValue |= 0x40; - RT30xxWriteRFRegister(pAd, RF_R01, RFValue); - - /* Set RF offset */ - RT30xxReadRFRegister(pAd, RF_R23, &RFValue); - RFValue = (RFValue & 0x80) | pAd->RfFreqOffset; - RT30xxWriteRFRegister(pAd, RF_R23, RFValue); - - /* Set BW */ - if (!bScan - && (pAd->CommonCfg.BBPCurrentBW == BW_40)) { - RFValue = pAd->Mlme.CaliBW40RfR24; - /*DISABLE_11N_CHECK(pAd); */ - } else { - RFValue = pAd->Mlme.CaliBW20RfR24; - } - RT30xxWriteRFRegister(pAd, RF_R24, RFValue); - RT30xxWriteRFRegister(pAd, RF_R31, RFValue); - - /* Enable RF tuning */ - RT30xxReadRFRegister(pAd, RF_R07, &RFValue); - RFValue = RFValue | 0x1; - RT30xxWriteRFRegister(pAd, RF_R07, RFValue); - - /* latch channel for future usage. */ - pAd->LatchRfRegs.Channel = Channel; - - DBGPRINT(RT_DEBUG_TRACE, - ("SwitchChannel#%d(RF=%d, Pwr0=%d, Pwr1=%d, %dT), N=0x%02X, K=0x%02X, R=0x%02X\n", - Channel, pAd->RfIcType, TxPwer, - TxPwer2, pAd->Antenna.field.TxPath, - FreqItems3020[index].N, - FreqItems3020[index].K, - FreqItems3020[index].R)); - - break; - } - } - } else -#endif /* RT30xx // */ - { - RFRegTable = RF2850RegTable; - switch (pAd->RfIcType) { - case RFIC_2820: - case RFIC_2850: - case RFIC_2720: - case RFIC_2750: - - for (index = 0; index < NUM_OF_2850_CHNL; index++) { - if (Channel == RFRegTable[index].Channel) { - R2 = RFRegTable[index].R2; - if (pAd->Antenna.field.TxPath == 1) { - R2 |= 0x4000; /* If TXpath is 1, bit 14 = 1; */ - } - - if (pAd->Antenna.field.RxPath == 2) { - R2 |= 0x40; /* write 1 to off Rxpath. */ - } else if (pAd->Antenna.field.RxPath == - 1) { - R2 |= 0x20040; /* write 1 to off RxPath */ - } - - if (Channel > 14) { - /* initialize R3, R4 */ - R3 = (RFRegTable[index]. - R3 & 0xffffc1ff); - R4 = (RFRegTable[index]. - R4 & (~0x001f87c0)) | - (pAd->RfFreqOffset << 15); - - /* 5G band power range: 0xF9~0X0F, TX0 Reg3 bit9/TX1 Reg4 bit6="0" means the TX power reduce 7dB */ - /* R3 */ - if ((TxPwer >= -7) - && (TxPwer < 0)) { - TxPwer = (7 + TxPwer); - TxPwer = - (TxPwer > - 0xF) ? (0xF) - : (TxPwer); - R3 |= (TxPwer << 10); - DBGPRINT(RT_DEBUG_ERROR, - ("AsicSwitchChannel: TxPwer=%d \n", - TxPwer)); - } else { - TxPwer = - (TxPwer > - 0xF) ? (0xF) - : (TxPwer); - R3 |= - (TxPwer << 10) | (1 - << - 9); - } - - /* R4 */ - if ((TxPwer2 >= -7) - && (TxPwer2 < 0)) { - TxPwer2 = (7 + TxPwer2); - TxPwer2 = - (TxPwer2 > - 0xF) ? (0xF) - : (TxPwer2); - R4 |= (TxPwer2 << 7); - DBGPRINT(RT_DEBUG_ERROR, - ("AsicSwitchChannel: TxPwer2=%d \n", - TxPwer2)); - } else { - TxPwer2 = - (TxPwer2 > - 0xF) ? (0xF) - : (TxPwer2); - R4 |= - (TxPwer2 << 7) | (1 - << - 6); - } - } else { - R3 = (RFRegTable[index].R3 & 0xffffc1ff) | (TxPwer << 9); /* set TX power0 */ - R4 = (RFRegTable[index].R4 & (~0x001f87c0)) | (pAd->RfFreqOffset << 15) | (TxPwer2 << 6); /* Set freq Offset & TxPwr1 */ - } - - /* Based on BBP current mode before changing RF channel. */ - if (!bScan - && (pAd->CommonCfg.BBPCurrentBW == - BW_40)) { - R4 |= 0x200000; - } - /* Update variables */ - pAd->LatchRfRegs.Channel = Channel; - pAd->LatchRfRegs.R1 = - RFRegTable[index].R1; - pAd->LatchRfRegs.R2 = R2; - pAd->LatchRfRegs.R3 = R3; - pAd->LatchRfRegs.R4 = R4; - - /* Set RF value 1's set R3[bit2] = [0] */ - RTMP_RF_IO_WRITE32(pAd, - pAd->LatchRfRegs.R1); - RTMP_RF_IO_WRITE32(pAd, - pAd->LatchRfRegs.R2); - RTMP_RF_IO_WRITE32(pAd, - (pAd->LatchRfRegs. - R3 & (~0x04))); - RTMP_RF_IO_WRITE32(pAd, - pAd->LatchRfRegs.R4); - - RTMPusecDelay(200); - - /* Set RF value 2's set R3[bit2] = [1] */ - RTMP_RF_IO_WRITE32(pAd, - pAd->LatchRfRegs.R1); - RTMP_RF_IO_WRITE32(pAd, - pAd->LatchRfRegs.R2); - RTMP_RF_IO_WRITE32(pAd, - (pAd->LatchRfRegs. - R3 | 0x04)); - RTMP_RF_IO_WRITE32(pAd, - pAd->LatchRfRegs.R4); - - RTMPusecDelay(200); - - /* Set RF value 3's set R3[bit2] = [0] */ - RTMP_RF_IO_WRITE32(pAd, - pAd->LatchRfRegs.R1); - RTMP_RF_IO_WRITE32(pAd, - pAd->LatchRfRegs.R2); - RTMP_RF_IO_WRITE32(pAd, - (pAd->LatchRfRegs. - R3 & (~0x04))); - RTMP_RF_IO_WRITE32(pAd, - pAd->LatchRfRegs.R4); - - break; - } - } - break; - - default: - break; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("SwitchChannel#%d(RF=%d, Pwr0=%lu, Pwr1=%lu, %dT) to , R1=0x%08lx, R2=0x%08lx, R3=0x%08lx, R4=0x%08lx\n", - Channel, pAd->RfIcType, (R3 & 0x00003e00) >> 9, - (R4 & 0x000007c0) >> 6, pAd->Antenna.field.TxPath, - pAd->LatchRfRegs.R1, pAd->LatchRfRegs.R2, - pAd->LatchRfRegs.R3, pAd->LatchRfRegs.R4)); - } - - /* Change BBP setting during siwtch from a->g, g->a */ - if (Channel <= 14) { - unsigned long TxPinCfg = 0x00050F0A; /*Gary 2007/08/09 0x050A0A */ - - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, - (0x37 - GET_LNA_GAIN(pAd))); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, - (0x37 - GET_LNA_GAIN(pAd))); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, - (0x37 - GET_LNA_GAIN(pAd))); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0); /*(0x44 - GET_LNA_GAIN(pAd))); // According the Rory's suggestion to solve the middle range issue. */ - /*RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62); */ - - /* Rx High power VGA offset for LNA select */ - if (pAd->NicConfig2.field.ExternalLNAForG) { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x62); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46); - } else { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0x84); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50); - } - - /* 5G band selection PIN, bit1 and bit2 are complement */ - RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value); - Value &= (~0x6); - Value |= (0x04); - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value); - - /* Turn off unused PA or LNA when only 1T or 1R */ - if (pAd->Antenna.field.TxPath == 1) { - TxPinCfg &= 0xFFFFFFF3; - } - if (pAd->Antenna.field.RxPath == 1) { - TxPinCfg &= 0xFFFFF3FF; - } - - RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg); - -#if defined(RT3090) || defined(RT3390) - /* PCIe PHY Transmit attenuation adjustment */ - if (IS_RT3090A(pAd) || IS_RT3390(pAd)) { - TX_ATTENUATION_CTRL_STRUC TxAttenuationCtrl = { - .word = 0}; - - RTMP_IO_READ32(pAd, PCIE_PHY_TX_ATTENUATION_CTRL, - &TxAttenuationCtrl.word); - - if (Channel == 14) /* Channel #14 */ - { - TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_EN = 1; /* Enable PCIe PHY Tx attenuation */ - TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_VALUE = 4; /* 9/16 full drive level */ - } else /* Channel #1~#13 */ - { - TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_EN = 0; /* Disable PCIe PHY Tx attenuation */ - TxAttenuationCtrl.field.PCIE_PHY_TX_ATTEN_VALUE = 0; /* n/a */ - } - - RTMP_IO_WRITE32(pAd, PCIE_PHY_TX_ATTENUATION_CTRL, - TxAttenuationCtrl.word); - } -#endif - } else { - unsigned long TxPinCfg = 0x00050F05; /*Gary 2007/8/9 0x050505 */ - - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R62, - (0x37 - GET_LNA_GAIN(pAd))); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R63, - (0x37 - GET_LNA_GAIN(pAd))); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R64, - (0x37 - GET_LNA_GAIN(pAd))); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R86, 0); /*(0x44 - GET_LNA_GAIN(pAd))); // According the Rory's suggestion to solve the middle range issue. */ - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R82, 0xF2); - - /* Rx High power VGA offset for LNA select */ - if (pAd->NicConfig2.field.ExternalLNAForA) { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x46); - } else { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R75, 0x50); - } - - /* 5G band selection PIN, bit1 and bit2 are complement */ - RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value); - Value &= (~0x6); - Value |= (0x02); - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value); - - /* Turn off unused PA or LNA when only 1T or 1R */ - if (pAd->Antenna.field.TxPath == 1) { - TxPinCfg &= 0xFFFFFFF3; - } - if (pAd->Antenna.field.RxPath == 1) { - TxPinCfg &= 0xFFFFF3FF; - } - - RTMP_IO_WRITE32(pAd, TX_PIN_CFG, TxPinCfg); - - } - - /* R66 should be set according to Channel and use 20MHz when scanning */ - /*RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, (0x2E + GET_LNA_GAIN(pAd))); */ - if (bScan) - RTMPSetAGCInitValue(pAd, BW_20); - else - RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW); - - /* */ - /* On 11A, We should delay and wait RF/BBP to be stable */ - /* and the appropriate time should be 1000 micro seconds */ - /* 2005/06/05 - On 11G, We also need this delay time. Otherwise it's difficult to pass the WHQL. */ - /* */ - RTMPusecDelay(1000); -} - -void AsicResetBBPAgent(struct rt_rtmp_adapter *pAd) -{ - BBP_CSR_CFG_STRUC BbpCsr; - DBGPRINT(RT_DEBUG_ERROR, ("Reset BBP Agent busy bit!\n")); - /* Still need to find why BBP agent keeps busy, but in fact, hardware still function ok. Now clear busy first. */ - RTMP_IO_READ32(pAd, H2M_BBP_AGENT, &BbpCsr.word); - BbpCsr.field.Busy = 0; - RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, BbpCsr.word); -} - -/* - ========================================================================== - Description: - This function is required for 2421 only, and should not be used during - site survey. It's only required after NIC decided to stay at a channel - for a longer period. - When this function is called, it's always after AsicSwitchChannel(). - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicLockChannel(struct rt_rtmp_adapter *pAd, u8 Channel) -{ -} - -void AsicRfTuningExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ -} - -/* - ========================================================================== - Description: - Gives CCK TX rate 2 more dB TX power. - This routine works only in LINK UP in INFRASTRUCTURE mode. - - calculate desired Tx power in RF R3.Tx0~5, should consider - - 0. if current radio is a noisy environment (pAd->DrsCounters.fNoisyEnvironment) - 1. TxPowerPercentage - 2. auto calibration based on TSSI feedback - 3. extra 2 db for CCK - 4. -10 db upon very-short distance (AvgRSSI >= -40db) to AP - - NOTE: Since this routine requires the value of (pAd->DrsCounters.fNoisyEnvironment), - it should be called AFTER MlmeDynamicTxRatSwitching() - ========================================================================== - */ -void AsicAdjustTxPower(struct rt_rtmp_adapter *pAd) -{ - int i, j; - char DeltaPwr = 0; - BOOLEAN bAutoTxAgc = FALSE; - u8 TssiRef, *pTssiMinusBoundary, *pTssiPlusBoundary, TxAgcStep; - u8 BbpR1 = 0, BbpR49 = 0, idx; - char *pTxAgcCompensate; - unsigned long TxPwr[5]; - char Value; - char Rssi = -127; - - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) || -#ifdef RTMP_MAC_PCI - (pAd->bPCIclkOff == TRUE) || -#endif /* RTMP_MAC_PCI // */ - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF) || - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) - return; - - Rssi = RTMPMaxRssi(pAd, - pAd->StaCfg.RssiSample.AvgRssi0, - pAd->StaCfg.RssiSample.AvgRssi1, - pAd->StaCfg.RssiSample.AvgRssi2); - - if (pAd->CommonCfg.BBPCurrentBW == BW_40) { - if (pAd->CommonCfg.CentralChannel > 14) { - TxPwr[0] = pAd->Tx40MPwrCfgABand[0]; - TxPwr[1] = pAd->Tx40MPwrCfgABand[1]; - TxPwr[2] = pAd->Tx40MPwrCfgABand[2]; - TxPwr[3] = pAd->Tx40MPwrCfgABand[3]; - TxPwr[4] = pAd->Tx40MPwrCfgABand[4]; - } else { - TxPwr[0] = pAd->Tx40MPwrCfgGBand[0]; - TxPwr[1] = pAd->Tx40MPwrCfgGBand[1]; - TxPwr[2] = pAd->Tx40MPwrCfgGBand[2]; - TxPwr[3] = pAd->Tx40MPwrCfgGBand[3]; - TxPwr[4] = pAd->Tx40MPwrCfgGBand[4]; - } - } else { - if (pAd->CommonCfg.Channel > 14) { - TxPwr[0] = pAd->Tx20MPwrCfgABand[0]; - TxPwr[1] = pAd->Tx20MPwrCfgABand[1]; - TxPwr[2] = pAd->Tx20MPwrCfgABand[2]; - TxPwr[3] = pAd->Tx20MPwrCfgABand[3]; - TxPwr[4] = pAd->Tx20MPwrCfgABand[4]; - } else { - TxPwr[0] = pAd->Tx20MPwrCfgGBand[0]; - TxPwr[1] = pAd->Tx20MPwrCfgGBand[1]; - TxPwr[2] = pAd->Tx20MPwrCfgGBand[2]; - TxPwr[3] = pAd->Tx20MPwrCfgGBand[3]; - TxPwr[4] = pAd->Tx20MPwrCfgGBand[4]; - } - } - - /* TX power compensation for temperature variation based on TSSI. try every 4 second */ - if (pAd->Mlme.OneSecPeriodicRound % 4 == 0) { - if (pAd->CommonCfg.Channel <= 14) { - /* bg channel */ - bAutoTxAgc = pAd->bAutoTxAgcG; - TssiRef = pAd->TssiRefG; - pTssiMinusBoundary = &pAd->TssiMinusBoundaryG[0]; - pTssiPlusBoundary = &pAd->TssiPlusBoundaryG[0]; - TxAgcStep = pAd->TxAgcStepG; - pTxAgcCompensate = &pAd->TxAgcCompensateG; - } else { - /* a channel */ - bAutoTxAgc = pAd->bAutoTxAgcA; - TssiRef = pAd->TssiRefA; - pTssiMinusBoundary = &pAd->TssiMinusBoundaryA[0]; - pTssiPlusBoundary = &pAd->TssiPlusBoundaryA[0]; - TxAgcStep = pAd->TxAgcStepA; - pTxAgcCompensate = &pAd->TxAgcCompensateA; - } - - if (bAutoTxAgc) { - /* BbpR1 is unsigned char */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R49, &BbpR49); - - /* (p) TssiPlusBoundaryG[0] = 0 = (m) TssiMinusBoundaryG[0] */ - /* compensate: +4 +3 +2 +1 0 -1 -2 -3 -4 * steps */ - /* step value is defined in pAd->TxAgcStepG for tx power value */ - - /* [4]+1+[4] p4 p3 p2 p1 o1 m1 m2 m3 m4 */ - /* ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0 - above value are examined in mass factory production */ - /* [4] [3] [2] [1] [0] [1] [2] [3] [4] */ - - /* plus (+) is 0x00 ~ 0x45, minus (-) is 0xa0 ~ 0xf0 */ - /* if value is between p1 ~ o1 or o1 ~ s1, no need to adjust tx power */ - /* if value is 0xa5, tx power will be -= TxAgcStep*(2-1) */ - - if (BbpR49 > pTssiMinusBoundary[1]) { - /* Reading is larger than the reference value */ - /* check for how large we need to decrease the Tx power */ - for (idx = 1; idx < 5; idx++) { - if (BbpR49 <= pTssiMinusBoundary[idx]) /* Found the range */ - break; - } - /* The index is the step we should decrease, idx = 0 means there is nothing to compensate */ -/* if (R3 > (unsigned long)(TxAgcStep * (idx-1))) */ - *pTxAgcCompensate = -(TxAgcStep * (idx - 1)); -/* else */ -/* *pTxAgcCompensate = -((u8)R3); */ - - DeltaPwr += (*pTxAgcCompensate); - DBGPRINT(RT_DEBUG_TRACE, - ("-- Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = -%d\n", - BbpR49, TssiRef, TxAgcStep, idx - 1)); - } else if (BbpR49 < pTssiPlusBoundary[1]) { - /* Reading is smaller than the reference value */ - /* check for how large we need to increase the Tx power */ - for (idx = 1; idx < 5; idx++) { - if (BbpR49 >= pTssiPlusBoundary[idx]) /* Found the range */ - break; - } - /* The index is the step we should increase, idx = 0 means there is nothing to compensate */ - *pTxAgcCompensate = TxAgcStep * (idx - 1); - DeltaPwr += (*pTxAgcCompensate); - DBGPRINT(RT_DEBUG_TRACE, - ("++ Tx Power, BBP R1=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n", - BbpR49, TssiRef, TxAgcStep, idx - 1)); - } else { - *pTxAgcCompensate = 0; - DBGPRINT(RT_DEBUG_TRACE, - (" Tx Power, BBP R49=%x, TssiRef=%x, TxAgcStep=%x, step = +%d\n", - BbpR49, TssiRef, TxAgcStep, 0)); - } - } - } else { - if (pAd->CommonCfg.Channel <= 14) { - bAutoTxAgc = pAd->bAutoTxAgcG; - pTxAgcCompensate = &pAd->TxAgcCompensateG; - } else { - bAutoTxAgc = pAd->bAutoTxAgcA; - pTxAgcCompensate = &pAd->TxAgcCompensateA; - } - - if (bAutoTxAgc) - DeltaPwr += (*pTxAgcCompensate); - } - - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BbpR1); - BbpR1 &= 0xFC; - - /* calculate delta power based on the percentage specified from UI */ - /* E2PROM setting is calibrated for maximum TX power (i.e. 100%) */ - /* We lower TX power here according to the percentage specified from UI */ - if (pAd->CommonCfg.TxPowerPercentage == 0xffffffff) /* AUTO TX POWER control */ - { - { - /* to patch high power issue with some APs, like Belkin N1. */ - if (Rssi > -35) { - BbpR1 |= 0x02; /* DeltaPwr -= 12; */ - } else if (Rssi > -40) { - BbpR1 |= 0x01; /* DeltaPwr -= 6; */ - } else; - } - } else if (pAd->CommonCfg.TxPowerPercentage > 90) /* 91 ~ 100% & AUTO, treat as 100% in terms of mW */ - ; - else if (pAd->CommonCfg.TxPowerPercentage > 60) /* 61 ~ 90%, treat as 75% in terms of mW // DeltaPwr -= 1; */ - { - DeltaPwr -= 1; - } else if (pAd->CommonCfg.TxPowerPercentage > 30) /* 31 ~ 60%, treat as 50% in terms of mW // DeltaPwr -= 3; */ - { - DeltaPwr -= 3; - } else if (pAd->CommonCfg.TxPowerPercentage > 15) /* 16 ~ 30%, treat as 25% in terms of mW // DeltaPwr -= 6; */ - { - BbpR1 |= 0x01; - } else if (pAd->CommonCfg.TxPowerPercentage > 9) /* 10 ~ 15%, treat as 12.5% in terms of mW // DeltaPwr -= 9; */ - { - BbpR1 |= 0x01; - DeltaPwr -= 3; - } else /* 0 ~ 9 %, treat as MIN(~3%) in terms of mW // DeltaPwr -= 12; */ - { - BbpR1 |= 0x02; - } - - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BbpR1); - - /* reset different new tx power for different TX rate */ - for (i = 0; i < 5; i++) { - if (TxPwr[i] != 0xffffffff) { - for (j = 0; j < 8; j++) { - Value = (char)((TxPwr[i] >> j * 4) & 0x0F); /* 0 ~ 15 */ - - if ((Value + DeltaPwr) < 0) { - Value = 0; /* min */ - } else if ((Value + DeltaPwr) > 0xF) { - Value = 0xF; /* max */ - } else { - Value += DeltaPwr; /* temperature compensation */ - } - - /* fill new value to CSR offset */ - TxPwr[i] = - (TxPwr[i] & ~(0x0000000F << j * 4)) | (Value - << j - * 4); - } - - /* write tx power value to CSR */ - /* TX_PWR_CFG_0 (8 tx rate) for TX power for OFDM 12M/18M - TX power for OFDM 6M/9M - TX power for CCK5.5M/11M - TX power for CCK1M/2M */ - /* TX_PWR_CFG_1 ~ TX_PWR_CFG_4 */ - RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i * 4, TxPwr[i]); - } - } - -} - -/* - ========================================================================== - Description: - put PHY to sleep here, and set next wakeup timer. PHY doesn't not wakeup - automatically. Instead, MCU will issue a TwakeUpInterrupt to host after - the wakeup timer timeout. Driver has to issue a separate command to wake - PHY up. - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd, - u16 TbttNumToNextWakeUp) -{ - RTMP_STA_SLEEP_THEN_AUTO_WAKEUP(pAd, TbttNumToNextWakeUp); -} - -/* - ========================================================================== - Description: - AsicForceWakeup() is used whenever manual wakeup is required - AsicForceSleep() should only be used when not in INFRA BSS. When - in INFRA BSS, we should use AsicSleepThenAutoWakeup() instead. - ========================================================================== - */ -void AsicForceSleep(struct rt_rtmp_adapter *pAd) -{ - -} - -/* - ========================================================================== - Description: - AsicForceWakeup() is used whenever Twakeup timer (set via AsicSleepThenAutoWakeup) - expired. - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - ========================================================================== - */ -void AsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx) -{ - DBGPRINT(RT_DEBUG_INFO, ("--> AsicForceWakeup \n")); - RTMP_STA_FORCE_WAKEUP(pAd, bFromTx); -} - -/* - ========================================================================== - Description: - Set My BSSID - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicSetBssid(struct rt_rtmp_adapter *pAd, u8 *pBssid) -{ - unsigned long Addr4; - DBGPRINT(RT_DEBUG_TRACE, - ("==============> AsicSetBssid %x:%x:%x:%x:%x:%x\n", pBssid[0], - pBssid[1], pBssid[2], pBssid[3], pBssid[4], pBssid[5])); - - Addr4 = (unsigned long)(pBssid[0]) | - (unsigned long)(pBssid[1] << 8) | - (unsigned long)(pBssid[2] << 16) | (unsigned long)(pBssid[3] << 24); - RTMP_IO_WRITE32(pAd, MAC_BSSID_DW0, Addr4); - - Addr4 = 0; - /* always one BSSID in STA mode */ - Addr4 = (unsigned long)(pBssid[4]) | (unsigned long)(pBssid[5] << 8); - - RTMP_IO_WRITE32(pAd, MAC_BSSID_DW1, Addr4); -} - -void AsicSetMcastWC(struct rt_rtmp_adapter *pAd) -{ - struct rt_mac_table_entry *pEntry = &pAd->MacTab.Content[MCAST_WCID]; - u16 offset; - - pEntry->Sst = SST_ASSOC; - pEntry->Aid = MCAST_WCID; /* Softap supports 1 BSSID and use WCID=0 as multicast Wcid index */ - pEntry->PsMode = PWR_ACTIVE; - pEntry->CurrTxRate = pAd->CommonCfg.MlmeRate; - offset = MAC_WCID_BASE + BSS0Mcast_WCID * HW_WCID_ENTRY_SIZE; -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicDelWcidTab(struct rt_rtmp_adapter *pAd, u8 Wcid) -{ - unsigned long Addr0 = 0x0, Addr1 = 0x0; - unsigned long offset; - - DBGPRINT(RT_DEBUG_TRACE, ("AsicDelWcidTab==>Wcid = 0x%x\n", Wcid)); - offset = MAC_WCID_BASE + Wcid * HW_WCID_ENTRY_SIZE; - RTMP_IO_WRITE32(pAd, offset, Addr0); - offset += 4; - RTMP_IO_WRITE32(pAd, offset, Addr1); -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicEnableRDG(struct rt_rtmp_adapter *pAd) -{ - TX_LINK_CFG_STRUC TxLinkCfg; - u32 Data = 0; - - RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word); - TxLinkCfg.field.TxRDGEn = 1; - RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word); - - RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data); - Data &= 0xFFFFFF00; - Data |= 0x80; - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data); - - /*OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED); */ -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicDisableRDG(struct rt_rtmp_adapter *pAd) -{ - TX_LINK_CFG_STRUC TxLinkCfg; - u32 Data = 0; - - RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word); - TxLinkCfg.field.TxRDGEn = 0; - RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word); - - RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data); - - Data &= 0xFFFFFF00; - /*Data |= 0x20; */ -#ifndef WIFI_TEST - /*if ( pAd->CommonCfg.bEnableTxBurst ) */ - /* Data |= 0x60; // for performance issue not set the TXOP to 0 */ -#endif - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE) - && (pAd->MacTab.fAnyStationMIMOPSDynamic == FALSE) - ) { - /* For CWC test, change txop from 0x30 to 0x20 in TxBurst mode */ - if (pAd->CommonCfg.bEnableTxBurst) - Data |= 0x20; - } - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data); -} - -/* - ========================================================================== - Description: - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicDisableSync(struct rt_rtmp_adapter *pAd) -{ - BCN_TIME_CFG_STRUC csr; - - DBGPRINT(RT_DEBUG_TRACE, ("--->Disable TSF synchronization\n")); - - /* 2003-12-20 disable TSF and TBTT while NIC in power-saving have side effect */ - /* that NIC will never wakes up because TSF stops and no more */ - /* TBTT interrupts */ - pAd->TbttTickCount = 0; - RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word); - csr.field.bBeaconGen = 0; - csr.field.bTBTTEnable = 0; - csr.field.TsfSyncMode = 0; - csr.field.bTsfTicking = 0; - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word); - -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicEnableBssSync(struct rt_rtmp_adapter *pAd) -{ - BCN_TIME_CFG_STRUC csr; - - DBGPRINT(RT_DEBUG_TRACE, ("--->AsicEnableBssSync(INFRA mode)\n")); - - RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word); -/* RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, 0x00000000); */ - { - csr.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; /* ASIC register in units of 1/16 TU */ - csr.field.bTsfTicking = 1; - csr.field.TsfSyncMode = 1; /* sync TSF in INFRASTRUCTURE mode */ - csr.field.bBeaconGen = 0; /* do NOT generate BEACON */ - csr.field.bTBTTEnable = 1; - } - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word); -} - -/* - ========================================================================== - Description: - Note: - BEACON frame in shared memory should be built ok before this routine - can be called. Otherwise, a garbage frame maybe transmitted out every - Beacon period. - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicEnableIbssSync(struct rt_rtmp_adapter *pAd) -{ - BCN_TIME_CFG_STRUC csr9; - u8 *ptr; - u32 i; - - DBGPRINT(RT_DEBUG_TRACE, - ("--->AsicEnableIbssSync(ADHOC mode. MPDUtotalByteCount = %d)\n", - pAd->BeaconTxWI.MPDUtotalByteCount)); - - RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr9.word); - csr9.field.bBeaconGen = 0; - csr9.field.bTBTTEnable = 0; - csr9.field.bTsfTicking = 0; - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word); - -#ifdef RTMP_MAC_PCI - /* move BEACON TXD and frame content to on-chip memory */ - ptr = (u8 *)& pAd->BeaconTxWI; - for (i = 0; i < TXWI_SIZE; i += 4) /* 16-byte TXWI field */ - { - u32 longptr = - *ptr + (*(ptr + 1) << 8) + (*(ptr + 2) << 16) + - (*(ptr + 3) << 24); - RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + i, longptr); - ptr += 4; - } - - /* start right after the 16-byte TXWI field */ - ptr = pAd->BeaconBuf; - for (i = 0; i < pAd->BeaconTxWI.MPDUtotalByteCount; i += 4) { - u32 longptr = - *ptr + (*(ptr + 1) << 8) + (*(ptr + 2) << 16) + - (*(ptr + 3) << 24); - RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, longptr); - ptr += 4; - } -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - /* move BEACON TXD and frame content to on-chip memory */ - ptr = (u8 *)& pAd->BeaconTxWI; - for (i = 0; i < TXWI_SIZE; i += 2) /* 16-byte TXWI field */ - { - /*u32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24); */ - /*RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + i, longptr); */ - RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + i, ptr, 2); - ptr += 2; - } - - /* start right after the 16-byte TXWI field */ - ptr = pAd->BeaconBuf; - for (i = 0; i < pAd->BeaconTxWI.MPDUtotalByteCount; i += 2) { - /*u32 longptr = *ptr + (*(ptr+1)<<8) + (*(ptr+2)<<16) + (*(ptr+3)<<24); */ - /*RTMP_IO_WRITE32(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, longptr); */ - RTUSBMultiWrite(pAd, HW_BEACON_BASE0 + TXWI_SIZE + i, ptr, 2); - ptr += 2; - } -#endif /* RTMP_MAC_USB // */ - - /* */ - /* For Wi-Fi faily generated beacons between participating stations. */ - /* Set TBTT phase adaptive adjustment step to 8us (default 16us) */ - /* don't change settings 2006-5- by Jerry */ - /*RTMP_IO_WRITE32(pAd, TBTT_SYNC_CFG, 0x00001010); */ - - /* start sending BEACON */ - csr9.field.BeaconInterval = pAd->CommonCfg.BeaconPeriod << 4; /* ASIC register in units of 1/16 TU */ - csr9.field.bTsfTicking = 1; - csr9.field.TsfSyncMode = 2; /* sync TSF in IBSS mode */ - csr9.field.bTBTTEnable = 1; - csr9.field.bBeaconGen = 1; - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr9.word); -} - -/* - ========================================================================== - Description: - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicSetEdcaParm(struct rt_rtmp_adapter *pAd, struct rt_edca_parm *pEdcaParm) -{ - EDCA_AC_CFG_STRUC Ac0Cfg, Ac1Cfg, Ac2Cfg, Ac3Cfg; - AC_TXOP_CSR0_STRUC csr0; - AC_TXOP_CSR1_STRUC csr1; - AIFSN_CSR_STRUC AifsnCsr; - CWMIN_CSR_STRUC CwminCsr; - CWMAX_CSR_STRUC CwmaxCsr; - int i; - - Ac0Cfg.word = 0; - Ac1Cfg.word = 0; - Ac2Cfg.word = 0; - Ac3Cfg.word = 0; - if ((pEdcaParm == NULL) || (pEdcaParm->bValid == FALSE)) { - DBGPRINT(RT_DEBUG_TRACE, ("AsicSetEdcaParm\n")); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WMM_INUSED); - for (i = 0; i < MAX_LEN_OF_MAC_TABLE; i++) { - if (pAd->MacTab.Content[i].ValidAsCLI - || pAd->MacTab.Content[i].ValidAsApCli) - CLIENT_STATUS_CLEAR_FLAG(&pAd->MacTab. - Content[i], - fCLIENT_STATUS_WMM_CAPABLE); - } - - /*======================================================== */ - /* MAC Register has a copy . */ - /*======================================================== */ -/*#ifndef WIFI_TEST */ - if (pAd->CommonCfg.bEnableTxBurst) { - /* For CWC test, change txop from 0x30 to 0x20 in TxBurst mode */ - Ac0Cfg.field.AcTxop = 0x20; /* Suggest by John for TxBurst in HT Mode */ - } else - Ac0Cfg.field.AcTxop = 0; /* QID_AC_BE */ -/*#else */ -/* Ac0Cfg.field.AcTxop = 0; // QID_AC_BE */ -/*#endif */ - Ac0Cfg.field.Cwmin = CW_MIN_IN_BITS; - Ac0Cfg.field.Cwmax = CW_MAX_IN_BITS; - Ac0Cfg.field.Aifsn = 2; - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word); - - Ac1Cfg.field.AcTxop = 0; /* QID_AC_BK */ - Ac1Cfg.field.Cwmin = CW_MIN_IN_BITS; - Ac1Cfg.field.Cwmax = CW_MAX_IN_BITS; - Ac1Cfg.field.Aifsn = 2; - RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word); - - if (pAd->CommonCfg.PhyMode == PHY_11B) { - Ac2Cfg.field.AcTxop = 192; /* AC_VI: 192*32us ~= 6ms */ - Ac3Cfg.field.AcTxop = 96; /* AC_VO: 96*32us ~= 3ms */ - } else { - Ac2Cfg.field.AcTxop = 96; /* AC_VI: 96*32us ~= 3ms */ - Ac3Cfg.field.AcTxop = 48; /* AC_VO: 48*32us ~= 1.5ms */ - } - Ac2Cfg.field.Cwmin = CW_MIN_IN_BITS; - Ac2Cfg.field.Cwmax = CW_MAX_IN_BITS; - Ac2Cfg.field.Aifsn = 2; - RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word); - Ac3Cfg.field.Cwmin = CW_MIN_IN_BITS; - Ac3Cfg.field.Cwmax = CW_MAX_IN_BITS; - Ac3Cfg.field.Aifsn = 2; - RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word); - - /*======================================================== */ - /* DMA Register has a copy too. */ - /*======================================================== */ - csr0.field.Ac0Txop = 0; /* QID_AC_BE */ - csr0.field.Ac1Txop = 0; /* QID_AC_BK */ - RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word); - if (pAd->CommonCfg.PhyMode == PHY_11B) { - csr1.field.Ac2Txop = 192; /* AC_VI: 192*32us ~= 6ms */ - csr1.field.Ac3Txop = 96; /* AC_VO: 96*32us ~= 3ms */ - } else { - csr1.field.Ac2Txop = 96; /* AC_VI: 96*32us ~= 3ms */ - csr1.field.Ac3Txop = 48; /* AC_VO: 48*32us ~= 1.5ms */ - } - RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word); - - CwminCsr.word = 0; - CwminCsr.field.Cwmin0 = CW_MIN_IN_BITS; - CwminCsr.field.Cwmin1 = CW_MIN_IN_BITS; - CwminCsr.field.Cwmin2 = CW_MIN_IN_BITS; - CwminCsr.field.Cwmin3 = CW_MIN_IN_BITS; - RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word); - - CwmaxCsr.word = 0; - CwmaxCsr.field.Cwmax0 = CW_MAX_IN_BITS; - CwmaxCsr.field.Cwmax1 = CW_MAX_IN_BITS; - CwmaxCsr.field.Cwmax2 = CW_MAX_IN_BITS; - CwmaxCsr.field.Cwmax3 = CW_MAX_IN_BITS; - RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word); - - RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, 0x00002222); - - NdisZeroMemory(&pAd->CommonCfg.APEdcaParm, sizeof(struct rt_edca_parm)); - } else { - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_WMM_INUSED); - /*======================================================== */ - /* MAC Register has a copy. */ - /*======================================================== */ - /* */ - /* Modify Cwmin/Cwmax/Txop on queue[QID_AC_VI], Recommend by Jerry 2005/07/27 */ - /* To degrade our VIDO Queue's throughput for WiFi WMM S3T07 Issue. */ - /* */ - /*pEdcaParm->Txop[QID_AC_VI] = pEdcaParm->Txop[QID_AC_VI] * 7 / 10; // rt2860c need this */ - - Ac0Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BE]; - Ac0Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_BE]; - Ac0Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BE]; - Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE]; /*+1; */ - - Ac1Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_BK]; - Ac1Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_BK]; /*+2; */ - Ac1Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_BK]; - Ac1Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BK]; /*+1; */ - - Ac2Cfg.field.AcTxop = (pEdcaParm->Txop[QID_AC_VI] * 6) / 10; - if (pAd->Antenna.field.TxPath == 1) { - Ac2Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VI] + 1; - Ac2Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VI] + 1; - } else { - Ac2Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VI]; - Ac2Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VI]; - } - Ac2Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VI] + 1; -#ifdef RTMP_MAC_USB - Ac2Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VI] + 3; -#endif /* RTMP_MAC_USB // */ - - { - /* Tuning for Wi-Fi WMM S06 */ - if (pAd->CommonCfg.bWiFiTest && - pEdcaParm->Aifsn[QID_AC_VI] == 10) - Ac2Cfg.field.Aifsn -= 1; - - /* Tuning for TGn Wi-Fi 5.2.32 */ - /* STA TestBed changes in this item: conexant legacy sta ==> broadcom 11n sta */ - if (STA_TGN_WIFI_ON(pAd) && - pEdcaParm->Aifsn[QID_AC_VI] == 10) { - Ac0Cfg.field.Aifsn = 3; - Ac2Cfg.field.AcTxop = 5; - } -#ifdef RT30xx - if (pAd->RfIcType == RFIC_3020 - || pAd->RfIcType == RFIC_2020) { - /* Tuning for WiFi WMM S3-T07: connexant legacy sta ==> broadcom 11n sta. */ - Ac2Cfg.field.Aifsn = 5; - } -#endif /* RT30xx // */ - } - - Ac3Cfg.field.AcTxop = pEdcaParm->Txop[QID_AC_VO]; - Ac3Cfg.field.Cwmin = pEdcaParm->Cwmin[QID_AC_VO]; - Ac3Cfg.field.Cwmax = pEdcaParm->Cwmax[QID_AC_VO]; - Ac3Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_VO]; - -/*#ifdef WIFI_TEST */ - if (pAd->CommonCfg.bWiFiTest) { - if (Ac3Cfg.field.AcTxop == 102) { - Ac0Cfg.field.AcTxop = - pEdcaParm->Txop[QID_AC_BE] ? pEdcaParm-> - Txop[QID_AC_BE] : 10; - Ac0Cfg.field.Aifsn = pEdcaParm->Aifsn[QID_AC_BE] - 1; /* AIFSN must >= 1 */ - Ac1Cfg.field.AcTxop = - pEdcaParm->Txop[QID_AC_BK]; - Ac1Cfg.field.Aifsn = - pEdcaParm->Aifsn[QID_AC_BK]; - Ac2Cfg.field.AcTxop = - pEdcaParm->Txop[QID_AC_VI]; - } /* End of if */ - } -/*#endif // WIFI_TEST // */ - - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Ac0Cfg.word); - RTMP_IO_WRITE32(pAd, EDCA_AC1_CFG, Ac1Cfg.word); - RTMP_IO_WRITE32(pAd, EDCA_AC2_CFG, Ac2Cfg.word); - RTMP_IO_WRITE32(pAd, EDCA_AC3_CFG, Ac3Cfg.word); - - /*======================================================== */ - /* DMA Register has a copy too. */ - /*======================================================== */ - csr0.field.Ac0Txop = Ac0Cfg.field.AcTxop; - csr0.field.Ac1Txop = Ac1Cfg.field.AcTxop; - RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word); - - csr1.field.Ac2Txop = Ac2Cfg.field.AcTxop; - csr1.field.Ac3Txop = Ac3Cfg.field.AcTxop; - RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr1.word); - - CwminCsr.word = 0; - CwminCsr.field.Cwmin0 = pEdcaParm->Cwmin[QID_AC_BE]; - CwminCsr.field.Cwmin1 = pEdcaParm->Cwmin[QID_AC_BK]; - CwminCsr.field.Cwmin2 = pEdcaParm->Cwmin[QID_AC_VI]; - CwminCsr.field.Cwmin3 = pEdcaParm->Cwmin[QID_AC_VO] - 1; /*for TGn wifi test */ - RTMP_IO_WRITE32(pAd, WMM_CWMIN_CFG, CwminCsr.word); - - CwmaxCsr.word = 0; - CwmaxCsr.field.Cwmax0 = pEdcaParm->Cwmax[QID_AC_BE]; - CwmaxCsr.field.Cwmax1 = pEdcaParm->Cwmax[QID_AC_BK]; - CwmaxCsr.field.Cwmax2 = pEdcaParm->Cwmax[QID_AC_VI]; - CwmaxCsr.field.Cwmax3 = pEdcaParm->Cwmax[QID_AC_VO]; - RTMP_IO_WRITE32(pAd, WMM_CWMAX_CFG, CwmaxCsr.word); - - AifsnCsr.word = 0; - AifsnCsr.field.Aifsn0 = Ac0Cfg.field.Aifsn; /*pEdcaParm->Aifsn[QID_AC_BE]; */ - AifsnCsr.field.Aifsn1 = Ac1Cfg.field.Aifsn; /*pEdcaParm->Aifsn[QID_AC_BK]; */ - AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn; /*pEdcaParm->Aifsn[QID_AC_VI]; */ - - { - /* Tuning for Wi-Fi WMM S06 */ - if (pAd->CommonCfg.bWiFiTest && - pEdcaParm->Aifsn[QID_AC_VI] == 10) - AifsnCsr.field.Aifsn2 = Ac2Cfg.field.Aifsn - 4; - - /* Tuning for TGn Wi-Fi 5.2.32 */ - /* STA TestBed changes in this item: connexant legacy sta ==> broadcom 11n sta */ - if (STA_TGN_WIFI_ON(pAd) && - pEdcaParm->Aifsn[QID_AC_VI] == 10) { - AifsnCsr.field.Aifsn0 = 3; - AifsnCsr.field.Aifsn2 = 7; - } - - if (INFRA_ON(pAd)) - CLIENT_STATUS_SET_FLAG(&pAd->MacTab. - Content[BSSID_WCID], - fCLIENT_STATUS_WMM_CAPABLE); - } - - { - AifsnCsr.field.Aifsn3 = Ac3Cfg.field.Aifsn - 1; /*pEdcaParm->Aifsn[QID_AC_VO]; //for TGn wifi test */ -#ifdef RT30xx - /* TODO: Shiang, this modification also suitable for RT3052/RT3050 ??? */ - if (pAd->RfIcType == RFIC_3020 - || pAd->RfIcType == RFIC_2020) { - AifsnCsr.field.Aifsn2 = 0x2; /*pEdcaParm->Aifsn[QID_AC_VI]; //for WiFi WMM S4-T04. */ - } -#endif /* RT30xx // */ - } - RTMP_IO_WRITE32(pAd, WMM_AIFSN_CFG, AifsnCsr.word); - - NdisMoveMemory(&pAd->CommonCfg.APEdcaParm, pEdcaParm, - sizeof(struct rt_edca_parm)); - if (!ADHOC_ON(pAd)) { - DBGPRINT(RT_DEBUG_TRACE, - ("EDCA [#%d]: AIFSN CWmin CWmax TXOP(us) ACM\n", - pEdcaParm->EdcaUpdateCount)); - DBGPRINT(RT_DEBUG_TRACE, - (" AC_BE %2d %2d %2d %4d %d\n", - pEdcaParm->Aifsn[0], pEdcaParm->Cwmin[0], - pEdcaParm->Cwmax[0], pEdcaParm->Txop[0] << 5, - pEdcaParm->bACM[0])); - DBGPRINT(RT_DEBUG_TRACE, - (" AC_BK %2d %2d %2d %4d %d\n", - pEdcaParm->Aifsn[1], pEdcaParm->Cwmin[1], - pEdcaParm->Cwmax[1], pEdcaParm->Txop[1] << 5, - pEdcaParm->bACM[1])); - DBGPRINT(RT_DEBUG_TRACE, - (" AC_VI %2d %2d %2d %4d %d\n", - pEdcaParm->Aifsn[2], pEdcaParm->Cwmin[2], - pEdcaParm->Cwmax[2], pEdcaParm->Txop[2] << 5, - pEdcaParm->bACM[2])); - DBGPRINT(RT_DEBUG_TRACE, - (" AC_VO %2d %2d %2d %4d %d\n", - pEdcaParm->Aifsn[3], pEdcaParm->Cwmin[3], - pEdcaParm->Cwmax[3], pEdcaParm->Txop[3] << 5, - pEdcaParm->bACM[3])); - } - } - -} - -/* - ========================================================================== - Description: - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicSetSlotTime(struct rt_rtmp_adapter *pAd, IN BOOLEAN bUseShortSlotTime) -{ - unsigned long SlotTime; - u32 RegValue = 0; - - if (pAd->CommonCfg.Channel > 14) - bUseShortSlotTime = TRUE; - - if (bUseShortSlotTime - && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED)) - return; - else if ((!bUseShortSlotTime) - && (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED))) - return; - - if (bUseShortSlotTime) - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED); - else - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED); - - SlotTime = (bUseShortSlotTime) ? 9 : 20; - - { - /* force using short SLOT time for FAE to demo performance when TxBurst is ON */ - if (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) - && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED))) - || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) - && (pAd->CommonCfg.BACapability.field.Policy == - BA_NOTUSE)) - ) { - /* In this case, we will think it is doing Wi-Fi test */ - /* And we will not set to short slot when bEnableTxBurst is TRUE. */ - } else if (pAd->CommonCfg.bEnableTxBurst) { - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED); - SlotTime = 9; - } - } - - /* */ - /* For some reasons, always set it to short slot time. */ - /* */ - /* ToDo: Should consider capability with 11B */ - /* */ - { - if (pAd->StaCfg.BssType == BSS_ADHOC) { - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_SLOT_INUSED); - SlotTime = 20; - } - } - - RTMP_IO_READ32(pAd, BKOFF_SLOT_CFG, &RegValue); - RegValue = RegValue & 0xFFFFFF00; - - RegValue |= SlotTime; - - RTMP_IO_WRITE32(pAd, BKOFF_SLOT_CFG, RegValue); -} - -/* - ======================================================================== - Description: - Add Shared key information into ASIC. - Update shared key, TxMic and RxMic to Asic Shared key table - Update its cipherAlg to Asic Shared key Mode. - - Return: - ======================================================================== -*/ -void AsicAddSharedKeyEntry(struct rt_rtmp_adapter *pAd, - u8 BssIndex, - u8 KeyIdx, - u8 CipherAlg, - u8 *pKey, u8 *pTxMic, u8 *pRxMic) -{ - unsigned long offset; /*, csr0; */ - SHAREDKEY_MODE_STRUC csr1; -#ifdef RTMP_MAC_PCI - int i; -#endif /* RTMP_MAC_PCI // */ - - DBGPRINT(RT_DEBUG_TRACE, - ("AsicAddSharedKeyEntry BssIndex=%d, KeyIdx=%d\n", BssIndex, - KeyIdx)); -/*============================================================================================ */ - - DBGPRINT(RT_DEBUG_TRACE, - ("AsicAddSharedKeyEntry: %s key #%d\n", CipherName[CipherAlg], - BssIndex * 4 + KeyIdx)); - DBGPRINT_RAW(RT_DEBUG_TRACE, - (" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - pKey[0], pKey[1], pKey[2], pKey[3], pKey[4], - pKey[5], pKey[6], pKey[7], pKey[8], pKey[9], - pKey[10], pKey[11], pKey[12], pKey[13], pKey[14], - pKey[15])); - if (pRxMic) { - DBGPRINT_RAW(RT_DEBUG_TRACE, - (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - pRxMic[0], pRxMic[1], pRxMic[2], pRxMic[3], - pRxMic[4], pRxMic[5], pRxMic[6], pRxMic[7])); - } - if (pTxMic) { - DBGPRINT_RAW(RT_DEBUG_TRACE, - (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - pTxMic[0], pTxMic[1], pTxMic[2], pTxMic[3], - pTxMic[4], pTxMic[5], pTxMic[6], pTxMic[7])); - } -/*============================================================================================ */ - /* */ - /* fill key material - key + TX MIC + RX MIC */ - /* */ -#ifdef RTMP_MAC_PCI - offset = - SHARED_KEY_TABLE_BASE + (4 * BssIndex + KeyIdx) * HW_KEY_ENTRY_SIZE; - for (i = 0; i < MAX_LEN_OF_SHARE_KEY; i++) { - RTMP_IO_WRITE8(pAd, offset + i, pKey[i]); - } - - offset += MAX_LEN_OF_SHARE_KEY; - if (pTxMic) { - for (i = 0; i < 8; i++) { - RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]); - } - } - - offset += 8; - if (pRxMic) { - for (i = 0; i < 8; i++) { - RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]); - } - } -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - { - offset = - SHARED_KEY_TABLE_BASE + (4 * BssIndex + - KeyIdx) * HW_KEY_ENTRY_SIZE; - RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_SHARE_KEY); - - offset += MAX_LEN_OF_SHARE_KEY; - if (pTxMic) { - RTUSBMultiWrite(pAd, offset, pTxMic, 8); - } - - offset += 8; - if (pRxMic) { - RTUSBMultiWrite(pAd, offset, pRxMic, 8); - } - } -#endif /* RTMP_MAC_USB // */ - - /* */ - /* Update cipher algorithm. WSTA always use BSS0 */ - /* */ - RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), - &csr1.word); - DBGPRINT(RT_DEBUG_TRACE, - ("Read: SHARED_KEY_MODE_BASE at this Bss[%d] KeyIdx[%d]= 0x%x \n", - BssIndex, KeyIdx, csr1.word)); - if ((BssIndex % 2) == 0) { - if (KeyIdx == 0) - csr1.field.Bss0Key0CipherAlg = CipherAlg; - else if (KeyIdx == 1) - csr1.field.Bss0Key1CipherAlg = CipherAlg; - else if (KeyIdx == 2) - csr1.field.Bss0Key2CipherAlg = CipherAlg; - else - csr1.field.Bss0Key3CipherAlg = CipherAlg; - } else { - if (KeyIdx == 0) - csr1.field.Bss1Key0CipherAlg = CipherAlg; - else if (KeyIdx == 1) - csr1.field.Bss1Key1CipherAlg = CipherAlg; - else if (KeyIdx == 2) - csr1.field.Bss1Key2CipherAlg = CipherAlg; - else - csr1.field.Bss1Key3CipherAlg = CipherAlg; - } - DBGPRINT(RT_DEBUG_TRACE, - ("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n", - BssIndex, csr1.word)); - RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), - csr1.word); - -} - -/* IRQL = DISPATCH_LEVEL */ -void AsicRemoveSharedKeyEntry(struct rt_rtmp_adapter *pAd, - u8 BssIndex, u8 KeyIdx) -{ - /*unsigned long SecCsr0; */ - SHAREDKEY_MODE_STRUC csr1; - - DBGPRINT(RT_DEBUG_TRACE, - ("AsicRemoveSharedKeyEntry: #%d \n", BssIndex * 4 + KeyIdx)); - - RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), - &csr1.word); - if ((BssIndex % 2) == 0) { - if (KeyIdx == 0) - csr1.field.Bss0Key0CipherAlg = 0; - else if (KeyIdx == 1) - csr1.field.Bss0Key1CipherAlg = 0; - else if (KeyIdx == 2) - csr1.field.Bss0Key2CipherAlg = 0; - else - csr1.field.Bss0Key3CipherAlg = 0; - } else { - if (KeyIdx == 0) - csr1.field.Bss1Key0CipherAlg = 0; - else if (KeyIdx == 1) - csr1.field.Bss1Key1CipherAlg = 0; - else if (KeyIdx == 2) - csr1.field.Bss1Key2CipherAlg = 0; - else - csr1.field.Bss1Key3CipherAlg = 0; - } - DBGPRINT(RT_DEBUG_TRACE, - ("Write: SHARED_KEY_MODE_BASE at this Bss[%d] = 0x%x \n", - BssIndex, csr1.word)); - RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), - csr1.word); - ASSERT(BssIndex < 4); - ASSERT(KeyIdx < 4); - -} - -void AsicUpdateWCIDAttribute(struct rt_rtmp_adapter *pAd, - u16 WCID, - u8 BssIndex, - u8 CipherAlg, - IN BOOLEAN bUsePairewiseKeyTable) -{ - unsigned long WCIDAttri = 0, offset; - - /* */ - /* Update WCID attribute. */ - /* Only TxKey could update WCID attribute. */ - /* */ - offset = MAC_WCID_ATTRIBUTE_BASE + (WCID * HW_WCID_ATTRI_SIZE); - WCIDAttri = - (BssIndex << 4) | (CipherAlg << 1) | (bUsePairewiseKeyTable); - RTMP_IO_WRITE32(pAd, offset, WCIDAttri); -} - -void AsicUpdateWCIDIVEIV(struct rt_rtmp_adapter *pAd, - u16 WCID, unsigned long uIV, unsigned long uEIV) -{ - unsigned long offset; - - offset = MAC_IVEIV_TABLE_BASE + (WCID * HW_IVEIV_ENTRY_SIZE); - - RTMP_IO_WRITE32(pAd, offset, uIV); - RTMP_IO_WRITE32(pAd, offset + 4, uEIV); -} - -void AsicUpdateRxWCIDTable(struct rt_rtmp_adapter *pAd, - u16 WCID, u8 *pAddr) -{ - unsigned long offset; - unsigned long Addr; - - offset = MAC_WCID_BASE + (WCID * HW_WCID_ENTRY_SIZE); - Addr = pAddr[0] + (pAddr[1] << 8) + (pAddr[2] << 16) + (pAddr[3] << 24); - RTMP_IO_WRITE32(pAd, offset, Addr); - Addr = pAddr[4] + (pAddr[5] << 8); - RTMP_IO_WRITE32(pAd, offset + 4, Addr); -} - -/* - ======================================================================== - - Routine Description: - Set Cipher Key, Cipher algorithm, IV/EIV to Asic - - Arguments: - pAd Pointer to our adapter - WCID WCID Entry number. - BssIndex BSSID index, station or none multiple BSSID support - this value should be 0. - KeyIdx This KeyIdx will set to IV's KeyID if bTxKey enabled - pCipherKey Pointer to Cipher Key. - bUsePairewiseKeyTable TRUE means saved the key in SharedKey table, - otherwise PairewiseKey table - bTxKey This is the transmit key if enabled. - - Return Value: - None - - Note: - This routine will set the relative key stuff to Asic including WCID attribute, - Cipher Key, Cipher algorithm and IV/EIV. - - IV/EIV will be update if this CipherKey is the transmission key because - ASIC will base on IV's KeyID value to select Cipher Key. - - If bTxKey sets to FALSE, this is not the TX key, but it could be - RX key - - For AP mode bTxKey must be always set to TRUE. - ======================================================================== -*/ -void AsicAddKeyEntry(struct rt_rtmp_adapter *pAd, - u16 WCID, - u8 BssIndex, - u8 KeyIdx, - struct rt_cipher_key *pCipherKey, - IN BOOLEAN bUsePairewiseKeyTable, IN BOOLEAN bTxKey) -{ - unsigned long offset; -/* unsigned long WCIDAttri = 0; */ - u8 IV4 = 0; - u8 *pKey = pCipherKey->Key; -/* unsigned long KeyLen = pCipherKey->KeyLen; */ - u8 *pTxMic = pCipherKey->TxMic; - u8 *pRxMic = pCipherKey->RxMic; - u8 *pTxtsc = pCipherKey->TxTsc; - u8 CipherAlg = pCipherKey->CipherAlg; - SHAREDKEY_MODE_STRUC csr1; -#ifdef RTMP_MAC_PCI - u8 i; -#endif /* RTMP_MAC_PCI // */ - -/* ASSERT(KeyLen <= MAX_LEN_OF_PEER_KEY); */ - - DBGPRINT(RT_DEBUG_TRACE, ("==> AsicAddKeyEntry\n")); - /* */ - /* 1.) decide key table offset */ - /* */ - if (bUsePairewiseKeyTable) - offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE); - else - offset = - SHARED_KEY_TABLE_BASE + (4 * BssIndex + - KeyIdx) * HW_KEY_ENTRY_SIZE; - - /* */ - /* 2.) Set Key to Asic */ - /* */ - /*for (i = 0; i < KeyLen; i++) */ -#ifdef RTMP_MAC_PCI - for (i = 0; i < MAX_LEN_OF_PEER_KEY; i++) { - RTMP_IO_WRITE8(pAd, offset + i, pKey[i]); - } - offset += MAX_LEN_OF_PEER_KEY; - - /* */ - /* 3.) Set MIC key if available */ - /* */ - if (pTxMic) { - for (i = 0; i < 8; i++) { - RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]); - } - } - offset += LEN_TKIP_TXMICK; - - if (pRxMic) { - for (i = 0; i < 8; i++) { - RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]); - } - } -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - RTUSBMultiWrite(pAd, offset, pKey, MAX_LEN_OF_PEER_KEY); - offset += MAX_LEN_OF_PEER_KEY; - - /* */ - /* 3.) Set MIC key if available */ - /* */ - if (pTxMic) { - RTUSBMultiWrite(pAd, offset, pTxMic, 8); - } - offset += LEN_TKIP_TXMICK; - - if (pRxMic) { - RTUSBMultiWrite(pAd, offset, pRxMic, 8); - } -#endif /* RTMP_MAC_USB // */ - - /* */ - /* 4.) Modify IV/EIV if needs */ - /* This will force Asic to use this key ID by setting IV. */ - /* */ - if (bTxKey) { -#ifdef RTMP_MAC_PCI - offset = MAC_IVEIV_TABLE_BASE + (WCID * HW_IVEIV_ENTRY_SIZE); - /* */ - /* Write IV */ - /* */ - RTMP_IO_WRITE8(pAd, offset, pTxtsc[1]); - RTMP_IO_WRITE8(pAd, offset + 1, ((pTxtsc[1] | 0x20) & 0x7f)); - RTMP_IO_WRITE8(pAd, offset + 2, pTxtsc[0]); - - IV4 = (KeyIdx << 6); - if ((CipherAlg == CIPHER_TKIP) - || (CipherAlg == CIPHER_TKIP_NO_MIC) - || (CipherAlg == CIPHER_AES)) - IV4 |= 0x20; /* turn on extension bit means EIV existence */ - - RTMP_IO_WRITE8(pAd, offset + 3, IV4); - - /* */ - /* Write EIV */ - /* */ - offset += 4; - for (i = 0; i < 4; i++) { - RTMP_IO_WRITE8(pAd, offset + i, pTxtsc[i + 2]); - } -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - u32 tmpVal; - - /* */ - /* Write IV */ - /* */ - IV4 = (KeyIdx << 6); - if ((CipherAlg == CIPHER_TKIP) - || (CipherAlg == CIPHER_TKIP_NO_MIC) - || (CipherAlg == CIPHER_AES)) - IV4 |= 0x20; /* turn on extension bit means EIV existence */ - - tmpVal = - pTxtsc[1] + (((pTxtsc[1] | 0x20) & 0x7f) << 8) + - (pTxtsc[0] << 16) + (IV4 << 24); - RTMP_IO_WRITE32(pAd, offset, tmpVal); - - /* */ - /* Write EIV */ - /* */ - offset += 4; - RTMP_IO_WRITE32(pAd, offset, *(u32 *)& pCipherKey->TxTsc[2]); -#endif /* RTMP_MAC_USB // */ - - AsicUpdateWCIDAttribute(pAd, WCID, BssIndex, CipherAlg, - bUsePairewiseKeyTable); - } - - if (!bUsePairewiseKeyTable) { - /* */ - /* Only update the shared key security mode */ - /* */ - RTMP_IO_READ32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), - &csr1.word); - if ((BssIndex % 2) == 0) { - if (KeyIdx == 0) - csr1.field.Bss0Key0CipherAlg = CipherAlg; - else if (KeyIdx == 1) - csr1.field.Bss0Key1CipherAlg = CipherAlg; - else if (KeyIdx == 2) - csr1.field.Bss0Key2CipherAlg = CipherAlg; - else - csr1.field.Bss0Key3CipherAlg = CipherAlg; - } else { - if (KeyIdx == 0) - csr1.field.Bss1Key0CipherAlg = CipherAlg; - else if (KeyIdx == 1) - csr1.field.Bss1Key1CipherAlg = CipherAlg; - else if (KeyIdx == 2) - csr1.field.Bss1Key2CipherAlg = CipherAlg; - else - csr1.field.Bss1Key3CipherAlg = CipherAlg; - } - RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * (BssIndex / 2), - csr1.word); - } - - DBGPRINT(RT_DEBUG_TRACE, ("<== AsicAddKeyEntry\n")); -} - -/* - ======================================================================== - Description: - Add Pair-wise key material into ASIC. - Update pairwise key, TxMic and RxMic to Asic Pair-wise key table - - Return: - ======================================================================== -*/ -void AsicAddPairwiseKeyEntry(struct rt_rtmp_adapter *pAd, - u8 *pAddr, - u8 WCID, struct rt_cipher_key *pCipherKey) -{ - int i; - unsigned long offset; - u8 *pKey = pCipherKey->Key; - u8 *pTxMic = pCipherKey->TxMic; - u8 *pRxMic = pCipherKey->RxMic; -#ifdef DBG - u8 CipherAlg = pCipherKey->CipherAlg; -#endif /* DBG // */ - - /* EKEY */ - offset = PAIRWISE_KEY_TABLE_BASE + (WCID * HW_KEY_ENTRY_SIZE); -#ifdef RTMP_MAC_PCI - for (i = 0; i < MAX_LEN_OF_PEER_KEY; i++) { - RTMP_IO_WRITE8(pAd, offset + i, pKey[i]); - } -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - RTUSBMultiWrite(pAd, offset, &pCipherKey->Key[0], MAX_LEN_OF_PEER_KEY); -#endif /* RTMP_MAC_USB // */ - for (i = 0; i < MAX_LEN_OF_PEER_KEY; i += 4) { - u32 Value; - RTMP_IO_READ32(pAd, offset + i, &Value); - } - - offset += MAX_LEN_OF_PEER_KEY; - - /* MIC KEY */ - if (pTxMic) { -#ifdef RTMP_MAC_PCI - for (i = 0; i < 8; i++) { - RTMP_IO_WRITE8(pAd, offset + i, pTxMic[i]); - } -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - RTUSBMultiWrite(pAd, offset, &pCipherKey->TxMic[0], 8); -#endif /* RTMP_MAC_USB // */ - } - offset += 8; - if (pRxMic) { -#ifdef RTMP_MAC_PCI - for (i = 0; i < 8; i++) { - RTMP_IO_WRITE8(pAd, offset + i, pRxMic[i]); - } -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - RTUSBMultiWrite(pAd, offset, &pCipherKey->RxMic[0], 8); -#endif /* RTMP_MAC_USB // */ - } - - DBGPRINT(RT_DEBUG_TRACE, - ("AsicAddPairwiseKeyEntry: WCID #%d Alg=%s\n", WCID, - CipherName[CipherAlg])); - DBGPRINT(RT_DEBUG_TRACE, - (" Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - pKey[0], pKey[1], pKey[2], pKey[3], pKey[4], pKey[5], - pKey[6], pKey[7], pKey[8], pKey[9], pKey[10], pKey[11], - pKey[12], pKey[13], pKey[14], pKey[15])); - if (pRxMic) { - DBGPRINT(RT_DEBUG_TRACE, - (" Rx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - pRxMic[0], pRxMic[1], pRxMic[2], pRxMic[3], - pRxMic[4], pRxMic[5], pRxMic[6], pRxMic[7])); - } - if (pTxMic) { - DBGPRINT(RT_DEBUG_TRACE, - (" Tx MIC Key = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - pTxMic[0], pTxMic[1], pTxMic[2], pTxMic[3], - pTxMic[4], pTxMic[5], pTxMic[6], pTxMic[7])); - } -} - -/* - ======================================================================== - Description: - Remove Pair-wise key material from ASIC. - - Return: - ======================================================================== -*/ -void AsicRemovePairwiseKeyEntry(struct rt_rtmp_adapter *pAd, - u8 BssIdx, u8 Wcid) -{ - unsigned long WCIDAttri; - u16 offset; - - /* re-set the entry's WCID attribute as OPEN-NONE. */ - offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE); - WCIDAttri = (BssIdx << 4) | PAIRWISEKEYTABLE; - RTMP_IO_WRITE32(pAd, offset, WCIDAttri); -} - -BOOLEAN AsicSendCommandToMcu(struct rt_rtmp_adapter *pAd, - u8 Command, - u8 Token, u8 Arg0, u8 Arg1) -{ - - if (pAd->chipOps.sendCommandToMcu) - pAd->chipOps.sendCommandToMcu(pAd, Command, Token, Arg0, Arg1); - - return TRUE; -} - -void AsicSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant) -{ -#ifdef RT30xx - /* RT3572 ATE need not to do this. */ - RT30xxSetRxAnt(pAd, Ant); -#endif /* RT30xx // */ -} - -void AsicTurnOffRFClk(struct rt_rtmp_adapter *pAd, u8 Channel) -{ - if (pAd->chipOps.AsicRfTurnOff) { - pAd->chipOps.AsicRfTurnOff(pAd); - } else { - /* RF R2 bit 18 = 0 */ - u32 R1 = 0, R2 = 0, R3 = 0; - u8 index; - struct rt_rtmp_rf_regs *RFRegTable; - - RFRegTable = RF2850RegTable; - - switch (pAd->RfIcType) { - case RFIC_2820: - case RFIC_2850: - case RFIC_2720: - case RFIC_2750: - - for (index = 0; index < NUM_OF_2850_CHNL; index++) { - if (Channel == RFRegTable[index].Channel) { - R1 = RFRegTable[index].R1 & 0xffffdfff; - R2 = RFRegTable[index].R2 & 0xfffbffff; - R3 = RFRegTable[index].R3 & 0xfff3ffff; - - RTMP_RF_IO_WRITE32(pAd, R1); - RTMP_RF_IO_WRITE32(pAd, R2); - - /* Program R1b13 to 1, R3/b18,19 to 0, R2b18 to 0. */ - /* Set RF R2 bit18=0, R3 bit[18:19]=0 */ - /*if (pAd->StaCfg.bRadio == FALSE) */ - if (1) { - RTMP_RF_IO_WRITE32(pAd, R3); - - DBGPRINT(RT_DEBUG_TRACE, - ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x, R3 = 0x%08x \n", - Channel, - pAd->RfIcType, R2, - R3)); - } else - DBGPRINT(RT_DEBUG_TRACE, - ("AsicTurnOffRFClk#%d(RF=%d, ) , R2=0x%08x \n", - Channel, - pAd->RfIcType, R2)); - break; - } - } - break; - - default: - break; - } - } -} - -void AsicTurnOnRFClk(struct rt_rtmp_adapter *pAd, u8 Channel) -{ - /* RF R2 bit 18 = 0 */ - u32 R1 = 0, R2 = 0, R3 = 0; - u8 index; - struct rt_rtmp_rf_regs *RFRegTable; - -#ifdef PCIE_PS_SUPPORT - /* The RF programming sequence is difference between 3xxx and 2xxx */ - if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))) { - return; - } -#endif /* PCIE_PS_SUPPORT // */ - - RFRegTable = RF2850RegTable; - - switch (pAd->RfIcType) { - case RFIC_2820: - case RFIC_2850: - case RFIC_2720: - case RFIC_2750: - - for (index = 0; index < NUM_OF_2850_CHNL; index++) { - if (Channel == RFRegTable[index].Channel) { - R3 = pAd->LatchRfRegs.R3; - R3 &= 0xfff3ffff; - R3 |= 0x00080000; - RTMP_RF_IO_WRITE32(pAd, R3); - - R1 = RFRegTable[index].R1; - RTMP_RF_IO_WRITE32(pAd, R1); - - R2 = RFRegTable[index].R2; - if (pAd->Antenna.field.TxPath == 1) { - R2 |= 0x4000; /* If TXpath is 1, bit 14 = 1; */ - } - - if (pAd->Antenna.field.RxPath == 2) { - R2 |= 0x40; /* write 1 to off Rxpath. */ - } else if (pAd->Antenna.field.RxPath == 1) { - R2 |= 0x20040; /* write 1 to off RxPath */ - } - RTMP_RF_IO_WRITE32(pAd, R2); - - break; - } - } - break; - - default: - break; - } - - DBGPRINT(RT_DEBUG_TRACE, ("AsicTurnOnRFClk#%d(RF=%d, ) , R2=0x%08x\n", - Channel, pAd->RfIcType, R2)); -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_cfg.c b/trunk/drivers/staging/rt2860/common/cmm_cfg.c deleted file mode 100644 index 727f79929258..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_cfg.c +++ /dev/null @@ -1,258 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - cmm_cfg.c - - Abstract: - Ralink WiFi Driver configuration related subroutines - - Revision History: - Who When What - --------- ---------- ---------------------------------------------- -*/ - -#include "../rt_config.h" - -char *GetPhyMode(int Mode) -{ - switch (Mode) { - case MODE_CCK: - return "CCK"; - - case MODE_OFDM: - return "OFDM"; - case MODE_HTMIX: - return "HTMIX"; - - case MODE_HTGREENFIELD: - return "GREEN"; - default: - return "N/A"; - } -} - -char *GetBW(int BW) -{ - switch (BW) { - case BW_10: - return "10M"; - - case BW_20: - return "20M"; - case BW_40: - return "40M"; - default: - return "N/A"; - } -} - -/* - ========================================================================== - Description: - Set Country Region to pAd->CommonCfg.CountryRegion. - This command will not work, if the field of CountryRegion in eeprom is programmed. - - Return: - TRUE if all parameters are OK, FALSE otherwise - ========================================================================== -*/ -int RT_CfgSetCountryRegion(struct rt_rtmp_adapter *pAd, char *arg, int band) -{ - long region, regionMax; - u8 *pCountryRegion; - - region = simple_strtol(arg, 0, 10); - - if (band == BAND_24G) { - pCountryRegion = &pAd->CommonCfg.CountryRegion; - regionMax = REGION_MAXIMUM_BG_BAND; - } else { - pCountryRegion = &pAd->CommonCfg.CountryRegionForABand; - regionMax = REGION_MAXIMUM_A_BAND; - } - - /* TODO: Is it neccesay for following check??? */ - /* Country can be set only when EEPROM not programmed */ - if (*pCountryRegion & 0x80) { - DBGPRINT(RT_DEBUG_ERROR, - ("CfgSetCountryRegion():CountryRegion in eeprom was programmed\n")); - return FALSE; - } - - if ((region >= 0) && (region <= REGION_MAXIMUM_BG_BAND)) { - *pCountryRegion = (u8)region; - } else if ((region == REGION_31_BG_BAND) && (band == BAND_24G)) { - *pCountryRegion = (u8)region; - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("CfgSetCountryRegion():region(%ld) out of range!\n", - region)); - return FALSE; - } - - return TRUE; - -} - -/* - ========================================================================== - Description: - Set Wireless Mode - Return: - TRUE if all parameters are OK, FALSE otherwise - ========================================================================== -*/ -int RT_CfgSetWirelessMode(struct rt_rtmp_adapter *pAd, char *arg) -{ - int MaxPhyMode = PHY_11G; - long WirelessMode; - - MaxPhyMode = PHY_11N_5G; - - WirelessMode = simple_strtol(arg, 0, 10); - if (WirelessMode <= MaxPhyMode) { - pAd->CommonCfg.PhyMode = WirelessMode; - return TRUE; - } - - return FALSE; - -} - -int RT_CfgSetShortSlot(struct rt_rtmp_adapter *pAd, char *arg) -{ - long ShortSlot; - - ShortSlot = simple_strtol(arg, 0, 10); - - if (ShortSlot == 1) - pAd->CommonCfg.bUseShortSlotTime = TRUE; - else if (ShortSlot == 0) - pAd->CommonCfg.bUseShortSlotTime = FALSE; - else - return FALSE; /*Invalid argument */ - - return TRUE; -} - -/* - ========================================================================== - Description: - Set WEP KEY base on KeyIdx - Return: - TRUE if all parameters are OK, FALSE otherwise - ========================================================================== -*/ -int RT_CfgSetWepKey(struct rt_rtmp_adapter *pAd, - char *keyString, - struct rt_cipher_key *pSharedKey, int keyIdx) -{ - int KeyLen; - int i; - u8 CipherAlg = CIPHER_NONE; - BOOLEAN bKeyIsHex = FALSE; - - /* TODO: Shall we do memset for the original key info?? */ - memset(pSharedKey, 0, sizeof(struct rt_cipher_key)); - KeyLen = strlen(keyString); - switch (KeyLen) { - case 5: /*wep 40 Ascii type */ - case 13: /*wep 104 Ascii type */ - bKeyIsHex = FALSE; - pSharedKey->KeyLen = KeyLen; - NdisMoveMemory(pSharedKey->Key, keyString, KeyLen); - break; - - case 10: /*wep 40 Hex type */ - case 26: /*wep 104 Hex type */ - for (i = 0; i < KeyLen; i++) { - if (!isxdigit(*(keyString + i))) - return FALSE; /*Not Hex value; */ - } - bKeyIsHex = TRUE; - pSharedKey->KeyLen = KeyLen / 2; - AtoH(keyString, pSharedKey->Key, pSharedKey->KeyLen); - break; - - default: /*Invalid argument */ - DBGPRINT(RT_DEBUG_TRACE, - ("RT_CfgSetWepKey(keyIdx=%d):Invalid argument (arg=%s)\n", - keyIdx, keyString)); - return FALSE; - } - - pSharedKey->CipherAlg = ((KeyLen % 5) ? CIPHER_WEP128 : CIPHER_WEP64); - DBGPRINT(RT_DEBUG_TRACE, - ("RT_CfgSetWepKey:(KeyIdx=%d,type=%s, Alg=%s)\n", keyIdx, - (bKeyIsHex == FALSE ? "Ascii" : "Hex"), - CipherName[CipherAlg])); - - return TRUE; -} - -/* - ========================================================================== - Description: - Set WPA PSK key - - Arguments: - pAdapter Pointer to our adapter - keyString WPA pre-shared key string - pHashStr String used for password hash function - hashStrLen Length of the hash string - pPMKBuf Output buffer of WPAPSK key - - Return: - TRUE if all parameters are OK, FALSE otherwise - ========================================================================== -*/ -int RT_CfgSetWPAPSKKey(struct rt_rtmp_adapter *pAd, - char *keyString, - u8 * pHashStr, - int hashStrLen, u8 *pPMKBuf) -{ - int keyLen; - u8 keyMaterial[40]; - - keyLen = strlen(keyString); - if ((keyLen < 8) || (keyLen > 64)) { - DBGPRINT(RT_DEBUG_TRACE, - ("WPAPSK Key length(%d) error, required 8 ~ 64 characters!(keyStr=%s)\n", - keyLen, keyString)); - return FALSE; - } - - memset(pPMKBuf, 0, 32); - if (keyLen == 64) { - AtoH(keyString, pPMKBuf, 32); - } else { - PasswordHash(keyString, pHashStr, hashStrLen, keyMaterial); - NdisMoveMemory(pPMKBuf, keyMaterial, 32); - } - - return TRUE; -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_data.c b/trunk/drivers/staging/rt2860/common/cmm_data.c deleted file mode 100644 index 33799e1449ae..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_data.c +++ /dev/null @@ -1,2361 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* -*/ - -#include "../rt_config.h" - -u8 SNAP_802_1H[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; -u8 SNAP_BRIDGE_TUNNEL[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 }; - -/* Add Cisco Aironet SNAP heade for CCX2 support */ -u8 SNAP_AIRONET[] = { 0xaa, 0xaa, 0x03, 0x00, 0x40, 0x96, 0x00, 0x00 }; -u8 CKIP_LLC_SNAP[] = { 0xaa, 0xaa, 0x03, 0x00, 0x40, 0x96, 0x00, 0x02 }; -u8 EAPOL_LLC_SNAP[] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x88, 0x8e }; -u8 EAPOL[] = { 0x88, 0x8e }; -u8 TPID[] = { 0x81, 0x00 }; /* VLAN related */ - -u8 IPX[] = { 0x81, 0x37 }; -u8 APPLE_TALK[] = { 0x80, 0xf3 }; - -u8 RateIdToPlcpSignal[12] = { - 0, /* RATE_1 */ 1, /* RATE_2 */ 2, /* RATE_5_5 */ 3, /* RATE_11 *//* see BBP spec */ - 11, /* RATE_6 */ 15, /* RATE_9 */ 10, /* RATE_12 */ 14, /* RATE_18 *//* see IEEE802.11a-1999 p.14 */ - 9, /* RATE_24 */ 13, /* RATE_36 */ 8, /* RATE_48 */ 12 /* RATE_54 */ -}; /* see IEEE802.11a-1999 p.14 */ - -u8 OfdmSignalToRateId[16] = { - RATE_54, RATE_54, RATE_54, RATE_54, /* OFDM PLCP Signal = 0, 1, 2, 3 respectively */ - RATE_54, RATE_54, RATE_54, RATE_54, /* OFDM PLCP Signal = 4, 5, 6, 7 respectively */ - RATE_48, RATE_24, RATE_12, RATE_6, /* OFDM PLCP Signal = 8, 9, 10, 11 respectively */ - RATE_54, RATE_36, RATE_18, RATE_9, /* OFDM PLCP Signal = 12, 13, 14, 15 respectively */ -}; - -u8 OfdmRateToRxwiMCS[12] = { - 0, 0, 0, 0, - 0, 1, 2, 3, /* OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3 */ - 4, 5, 6, 7, /* OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7 */ -}; - -u8 RxwiMCSToOfdmRate[12] = { - RATE_6, RATE_9, RATE_12, RATE_18, - RATE_24, RATE_36, RATE_48, RATE_54, /* OFDM rate 6,9,12,18 = rxwi mcs 0,1,2,3 */ - 4, 5, 6, 7, /* OFDM rate 24,36,48,54 = rxwi mcs 4,5,6,7 */ -}; - -char *MCSToMbps[] = - { "1Mbps", "2Mbps", "5.5Mbps", "11Mbps", "06Mbps", "09Mbps", "12Mbps", -"18Mbps", "24Mbps", "36Mbps", "48Mbps", "54Mbps", "MM-0", "MM-1", "MM-2", "MM-3", -"MM-4", "MM-5", "MM-6", "MM-7", "MM-8", "MM-9", "MM-10", "MM-11", "MM-12", "MM-13", -"MM-14", "MM-15", "MM-32", "ee1", "ee2", "ee3" }; - -u8 default_cwmin[] = - { CW_MIN_IN_BITS, CW_MIN_IN_BITS, CW_MIN_IN_BITS - 1, CW_MIN_IN_BITS - 2 }; -/*u8 default_cwmax[]={CW_MAX_IN_BITS, CW_MAX_IN_BITS, CW_MIN_IN_BITS, CW_MIN_IN_BITS-1}; */ -u8 default_sta_aifsn[] = { 3, 7, 2, 2 }; - -u8 MapUserPriorityToAccessCategory[8] = - { QID_AC_BE, QID_AC_BK, QID_AC_BK, QID_AC_BE, QID_AC_VI, QID_AC_VI, -QID_AC_VO, QID_AC_VO }; - -/* - ======================================================================== - - Routine Description: - API for MLME to transmit management frame to AP (BSS Mode) - or station (IBSS Mode) - - Arguments: - pAd Pointer to our adapter - pData Pointer to the outgoing 802.11 frame - Length Size of outgoing management frame - - Return Value: - NDIS_STATUS_FAILURE - NDIS_STATUS_PENDING - NDIS_STATUS_SUCCESS - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -int MiniportMMRequest(struct rt_rtmp_adapter *pAd, - u8 QueIdx, u8 *pData, u32 Length) -{ - void *pPacket; - int Status = NDIS_STATUS_SUCCESS; - unsigned long FreeNum; - u8 rtmpHwHdr[TXINFO_SIZE + TXWI_SIZE]; /*RTMP_HW_HDR_LEN]; */ -#ifdef RTMP_MAC_PCI - unsigned long IrqFlags = 0; - u8 IrqState; -#endif /* RTMP_MAC_PCI // */ - BOOLEAN bUseDataQ = FALSE; - int retryCnt = 0; - - ASSERT(Length <= MGMT_DMA_BUFFER_SIZE); - - if ((QueIdx & MGMT_USE_QUEUE_FLAG) == MGMT_USE_QUEUE_FLAG) { - bUseDataQ = TRUE; - QueIdx &= (~MGMT_USE_QUEUE_FLAG); - } -#ifdef RTMP_MAC_PCI - /* 2860C use Tx Ring */ - IrqState = pAd->irq_disabled; - if (pAd->MACVersion == 0x28600100) { - QueIdx = (bUseDataQ == TRUE ? QueIdx : 3); - bUseDataQ = TRUE; - } - if (bUseDataQ && (!IrqState)) - RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); -#endif /* RTMP_MAC_PCI // */ - - do { - /* Reset is in progress, stop immediately */ - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) || - RTMP_TEST_FLAG(pAd, - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST) - || !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)) { - Status = NDIS_STATUS_FAILURE; - break; - } - /* Check Free priority queue */ - /* Since we use PBF Queue2 for management frame. Its corresponding DMA ring should be using TxRing. */ -#ifdef RTMP_MAC_PCI - if (bUseDataQ) { - retryCnt = MAX_DATAMM_RETRY; - /* free Tx(QueIdx) resources */ - RTMPFreeTXDUponTxDmaDone(pAd, QueIdx); - FreeNum = GET_TXRING_FREENO(pAd, QueIdx); - } else -#endif /* RTMP_MAC_PCI // */ - { - FreeNum = GET_MGMTRING_FREENO(pAd); - } - - if ((FreeNum > 0)) { - /* We need to reserve space for rtmp hardware header. i.e., TxWI for RT2860 and TxInfo+TxWI for RT2870 */ - NdisZeroMemory(&rtmpHwHdr, (TXINFO_SIZE + TXWI_SIZE)); - Status = - RTMPAllocateNdisPacket(pAd, &pPacket, - (u8 *)& rtmpHwHdr, - (TXINFO_SIZE + TXWI_SIZE), - pData, Length); - if (Status != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_WARN, - ("MiniportMMRequest (error:: can't allocate NDIS PACKET)\n")); - break; - } - /*pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK; */ - /*pAd->CommonCfg.MlmeRate = RATE_2; */ - -#ifdef RTMP_MAC_PCI - if (bUseDataQ) { - Status = - MlmeDataHardTransmit(pAd, QueIdx, pPacket); - retryCnt--; - } else -#endif /* RTMP_MAC_PCI // */ - Status = MlmeHardTransmit(pAd, QueIdx, pPacket); - if (Status == NDIS_STATUS_SUCCESS) - retryCnt = 0; - else - RTMPFreeNdisPacket(pAd, pPacket); - } else { - pAd->RalinkCounters.MgmtRingFullCount++; -#ifdef RTMP_MAC_PCI - if (bUseDataQ) { - retryCnt--; - DBGPRINT(RT_DEBUG_TRACE, - ("retryCnt %d\n", retryCnt)); - if (retryCnt == 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("Qidx(%d), not enough space in DataRing, MgmtRingFullCount=%ld!\n", - QueIdx, - pAd->RalinkCounters. - MgmtRingFullCount)); - } - } -#endif /* RTMP_MAC_PCI // */ - DBGPRINT(RT_DEBUG_ERROR, - ("Qidx(%d), not enough space in MgmtRing, MgmtRingFullCount=%ld!\n", - QueIdx, - pAd->RalinkCounters.MgmtRingFullCount)); - } - } while (retryCnt > 0); - -#ifdef RTMP_MAC_PCI - if (bUseDataQ && (!IrqState)) - RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); -#endif /* RTMP_MAC_PCI // */ - - return Status; -} - -/* - ======================================================================== - - Routine Description: - Copy frame from waiting queue into relative ring buffer and set - appropriate ASIC register to kick hardware transmit function - - Arguments: - pAd Pointer to our adapter - pBuffer Pointer to memory of outgoing frame - Length Size of outgoing management frame - - Return Value: - NDIS_STATUS_FAILURE - NDIS_STATUS_PENDING - NDIS_STATUS_SUCCESS - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -int MlmeHardTransmit(struct rt_rtmp_adapter *pAd, - u8 QueIdx, void *pPacket) -{ - struct rt_packet_info PacketInfo; - u8 *pSrcBufVA; - u32 SrcBufLen; - struct rt_header_802_11 * pHeader_802_11; - - if ((pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE) - ) { - return NDIS_STATUS_FAILURE; - } - - RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen); - if (pSrcBufVA == NULL) - return NDIS_STATUS_FAILURE; - - pHeader_802_11 = (struct rt_header_802_11 *) (pSrcBufVA + TXINFO_SIZE + TXWI_SIZE); - -#ifdef RTMP_MAC_PCI - if (pAd->MACVersion == 0x28600100) - return MlmeHardTransmitTxRing(pAd, QueIdx, pPacket); - else -#endif /* RTMP_MAC_PCI // */ - return MlmeHardTransmitMgmtRing(pAd, QueIdx, pPacket); - -} - -int MlmeHardTransmitMgmtRing(struct rt_rtmp_adapter *pAd, - u8 QueIdx, void *pPacket) -{ - struct rt_packet_info PacketInfo; - u8 *pSrcBufVA; - u32 SrcBufLen; - struct rt_header_802_11 * pHeader_802_11; - BOOLEAN bAckRequired, bInsertTimestamp; - u8 MlmeRate; - struct rt_txwi * pFirstTxWI; - struct rt_mac_table_entry *pMacEntry = NULL; - u8 PID; - - RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen); - - /* Make sure MGMT ring resource won't be used by other threads */ - RTMP_SEM_LOCK(&pAd->MgmtRingLock); - if (pSrcBufVA == NULL) { - /* The buffer shouldn't be NULL */ - RTMP_SEM_UNLOCK(&pAd->MgmtRingLock); - return NDIS_STATUS_FAILURE; - } - - { - /* outgoing frame always wakeup PHY to prevent frame lost */ - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) - AsicForceWakeup(pAd, TRUE); - } - - pFirstTxWI = (struct rt_txwi *) (pSrcBufVA + TXINFO_SIZE); - pHeader_802_11 = (struct rt_header_802_11 *) (pSrcBufVA + TXINFO_SIZE + TXWI_SIZE); /*TXWI_SIZE); */ - - if (pHeader_802_11->Addr1[0] & 0x01) { - MlmeRate = pAd->CommonCfg.BasicMlmeRate; - } else { - MlmeRate = pAd->CommonCfg.MlmeRate; - } - - /* Verify Mlme rate for a / g bands. */ - if ((pAd->LatchRfRegs.Channel > 14) && (MlmeRate < RATE_6)) /* 11A band */ - MlmeRate = RATE_6; - - if ((pHeader_802_11->FC.Type == BTYPE_DATA) && - (pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL)) { - pMacEntry = MacTableLookup(pAd, pHeader_802_11->Addr1); - } - - { - /* Fixed W52 with Activity scan issue in ABG_MIXED and ABGN_MIXED mode. */ - if (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED - || pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) { - if (pAd->LatchRfRegs.Channel > 14) - pAd->CommonCfg.MlmeTransmit.field.MODE = 1; - else - pAd->CommonCfg.MlmeTransmit.field.MODE = 0; - } - } - - /* */ - /* Should not be hard code to set PwrMgmt to 0 (PWR_ACTIVE) */ - /* Snice it's been set to 0 while on MgtMacHeaderInit */ - /* By the way this will cause frame to be send on PWR_SAVE failed. */ - /* */ - pHeader_802_11->FC.PwrMgmt = PWR_ACTIVE; /* (pAd->StaCfg.Psm == PWR_SAVE); */ - - /* */ - /* In WMM-UAPSD, mlme frame should be set psm as power saving but probe request frame */ - /* Data-Null packets also pass through MMRequest in RT2860, however, we hope control the psm bit to pass APSD */ -/* if ((pHeader_802_11->FC.Type != BTYPE_DATA) && (pHeader_802_11->FC.Type != BTYPE_CNTL)) */ - { - if ((pHeader_802_11->FC.SubType == SUBTYPE_ACTION) || - ((pHeader_802_11->FC.Type == BTYPE_DATA) && - ((pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL) || - (pHeader_802_11->FC.SubType == SUBTYPE_NULL_FUNC)))) { - if (pAd->StaCfg.Psm == PWR_SAVE) - pHeader_802_11->FC.PwrMgmt = PWR_SAVE; - else - pHeader_802_11->FC.PwrMgmt = - pAd->CommonCfg.bAPSDForcePowerSave; - } - } - - bInsertTimestamp = FALSE; - if (pHeader_802_11->FC.Type == BTYPE_CNTL) /* must be PS-POLL */ - { - /*Set PM bit in ps-poll, to fix WLK 1.2 PowerSaveMode_ext failure issue. */ - if ((pAd->OpMode == OPMODE_STA) - && (pHeader_802_11->FC.SubType == SUBTYPE_PS_POLL)) { - pHeader_802_11->FC.PwrMgmt = PWR_SAVE; - } - bAckRequired = FALSE; - } else /* BTYPE_MGMT or BTYPE_DATA(must be NULL frame) */ - { - /*pAd->Sequence++; */ - /*pHeader_802_11->Sequence = pAd->Sequence; */ - - if (pHeader_802_11->Addr1[0] & 0x01) /* MULTICAST, BROADCAST */ - { - bAckRequired = FALSE; - pHeader_802_11->Duration = 0; - } else { - bAckRequired = TRUE; - pHeader_802_11->Duration = - RTMPCalcDuration(pAd, MlmeRate, 14); - if ((pHeader_802_11->FC.SubType == SUBTYPE_PROBE_RSP) - && (pHeader_802_11->FC.Type == BTYPE_MGMT)) { - bInsertTimestamp = TRUE; - bAckRequired = FALSE; /* Disable ACK to prevent retry 0x1f for Probe Response */ - } else - if ((pHeader_802_11->FC.SubType == - SUBTYPE_PROBE_REQ) - && (pHeader_802_11->FC.Type == BTYPE_MGMT)) { - bAckRequired = FALSE; /* Disable ACK to prevent retry 0x1f for Probe Request */ - } - } - } - - pHeader_802_11->Sequence = pAd->Sequence++; - if (pAd->Sequence > 0xfff) - pAd->Sequence = 0; - - /* Before radar detection done, mgmt frame can not be sent but probe req */ - /* Because we need to use probe req to trigger driver to send probe req in passive scan */ - if ((pHeader_802_11->FC.SubType != SUBTYPE_PROBE_REQ) - && (pAd->CommonCfg.bIEEE80211H == 1) - && (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)) { - DBGPRINT(RT_DEBUG_ERROR, - ("MlmeHardTransmit --> radar detect not in normal mode!\n")); -/* if (!IrqState) */ - RTMP_SEM_UNLOCK(&pAd->MgmtRingLock); - return (NDIS_STATUS_FAILURE); - } - - /* */ - /* fill scatter-and-gather buffer list into TXD. Internally created NDIS PACKET */ - /* should always has only one physical buffer, and the whole frame size equals */ - /* to the first scatter buffer size */ - /* */ - - /* Initialize TX Descriptor */ - /* For inter-frame gap, the number is for this frame and next frame */ - /* For MLME rate, we will fix as 2Mb to match other vendor's implement */ -/* pAd->CommonCfg.MlmeTransmit.field.MODE = 1; */ - -/* management frame doesn't need encryption. so use RESERVED_WCID no matter u are sending to specific wcid or not. */ - PID = PID_MGMT; - - if (pMacEntry == NULL) { - RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, bInsertTimestamp, - FALSE, bAckRequired, FALSE, 0, RESERVED_WCID, - (SrcBufLen - TXINFO_SIZE - TXWI_SIZE), PID, 0, - (u8)pAd->CommonCfg.MlmeTransmit.field.MCS, - IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit); - } else { - /* dont use low rate to send QoS Null data frame */ - RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, - bInsertTimestamp, FALSE, bAckRequired, FALSE, - 0, pMacEntry->Aid, - (SrcBufLen - TXINFO_SIZE - TXWI_SIZE), - pMacEntry->MaxHTPhyMode.field.MCS, 0, - (u8)pMacEntry->MaxHTPhyMode.field.MCS, - IFS_BACKOFF, FALSE, &pMacEntry->MaxHTPhyMode); - } - - /* Now do hardware-depened kick out. */ - HAL_KickOutMgmtTx(pAd, QueIdx, pPacket, pSrcBufVA, SrcBufLen); - - /* Make sure to release MGMT ring resource */ -/* if (!IrqState) */ - RTMP_SEM_UNLOCK(&pAd->MgmtRingLock); - return NDIS_STATUS_SUCCESS; -} - -/******************************************************************************** - - New DeQueue Procedures. - - ********************************************************************************/ - -#define DEQUEUE_LOCK(lock, bIntContext, IrqFlags) \ - do{ \ - if (bIntContext == FALSE) \ - RTMP_IRQ_LOCK((lock), IrqFlags); \ - }while(0) - -#define DEQUEUE_UNLOCK(lock, bIntContext, IrqFlags) \ - do{ \ - if (bIntContext == FALSE) \ - RTMP_IRQ_UNLOCK((lock), IrqFlags); \ - }while(0) - -/* - ======================================================================== - Tx Path design algorithm: - Basically, we divide the packets into four types, Broadcast/Multicast, 11N Rate(AMPDU, AMSDU, Normal), B/G Rate(ARALINK, Normal), - Specific Packet Type. Following show the classification rule and policy for each kinds of packets. - Classification Rule=> - Multicast: (*addr1 & 0x01) == 0x01 - Specific : bDHCPFrame, bARPFrame, bEAPOLFrame, etc. - 11N Rate : If peer support HT - (1).AMPDU -- If TXBA is negotiated. - (2).AMSDU -- If AMSDU is capable for both peer and ourself. - *). AMSDU can embedded in a AMPDU, but now we didn't support it. - (3).Normal -- Other packets which send as 11n rate. - - B/G Rate : If peer is b/g only. - (1).ARALINK-- If both of peer/us supprot Ralink proprietary Aggregation and the TxRate is large than RATE_6 - (2).Normal -- Other packets which send as b/g rate. - Fragment: - The packet must be unicast, NOT A-RALINK, NOT A-MSDU, NOT 11n, then can consider about fragment. - - Classified Packet Handle Rule=> - Multicast: - No ACK, //pTxBlk->bAckRequired = FALSE; - No WMM, //pTxBlk->bWMM = FALSE; - No piggyback, //pTxBlk->bPiggyBack = FALSE; - Force LowRate, //pTxBlk->bForceLowRate = TRUE; - Specific : Basically, for specific packet, we should handle it specifically, but now all specific packets are use - the same policy to handle it. - Force LowRate, //pTxBlk->bForceLowRate = TRUE; - - 11N Rate : - No piggyback, //pTxBlk->bPiggyBack = FALSE; - - (1).AMSDU - pTxBlk->bWMM = TRUE; - (2).AMPDU - pTxBlk->bWMM = TRUE; - (3).Normal - - B/G Rate : - (1).ARALINK - - (2).Normal - ======================================================================== -*/ -static u8 TxPktClassification(struct rt_rtmp_adapter *pAd, void *pPacket) -{ - u8 TxFrameType = TX_UNKOWN_FRAME; - u8 Wcid; - struct rt_mac_table_entry *pMacEntry = NULL; - BOOLEAN bHTRate = FALSE; - - Wcid = RTMP_GET_PACKET_WCID(pPacket); - if (Wcid == MCAST_WCID) { /* Handle for RA is Broadcast/Multicast Address. */ - return TX_MCAST_FRAME; - } - /* Handle for unicast packets */ - pMacEntry = &pAd->MacTab.Content[Wcid]; - if (RTMP_GET_PACKET_LOWRATE(pPacket)) { /* It's a specific packet need to force low rate, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame */ - TxFrameType = TX_LEGACY_FRAME; - } else if (IS_HT_RATE(pMacEntry)) { /* it's a 11n capable packet */ - - /* Depends on HTPhyMode to check if the peer support the HTRate transmission. */ - /* Currently didn't support A-MSDU embedded in A-MPDU */ - bHTRate = TRUE; - if (RTMP_GET_PACKET_MOREDATA(pPacket) - || (pMacEntry->PsMode == PWR_SAVE)) - TxFrameType = TX_LEGACY_FRAME; - else if ((pMacEntry-> - TXBAbitmap & (1 << (RTMP_GET_PACKET_UP(pPacket)))) != - 0) - return TX_AMPDU_FRAME; - else if (CLIENT_STATUS_TEST_FLAG - (pMacEntry, fCLIENT_STATUS_AMSDU_INUSED)) - return TX_AMSDU_FRAME; - else - TxFrameType = TX_LEGACY_FRAME; - } else { /* it's a legacy b/g packet. */ - if ((CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_AGGREGATION_CAPABLE) && pAd->CommonCfg.bAggregationCapable) && (RTMP_GET_PACKET_TXRATE(pPacket) >= RATE_6) && (!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE)))) { /* if peer support Ralink Aggregation, we use it. */ - TxFrameType = TX_RALINK_FRAME; - } else { - TxFrameType = TX_LEGACY_FRAME; - } - } - - /* Currently, our fragment only support when a unicast packet send as NOT-ARALINK, NOT-AMSDU and NOT-AMPDU. */ - if ((RTMP_GET_PACKET_FRAGMENTS(pPacket) > 1) - && (TxFrameType == TX_LEGACY_FRAME)) - TxFrameType = TX_FRAG_FRAME; - - return TxFrameType; -} - -BOOLEAN RTMP_FillTxBlkInfo(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk) -{ - struct rt_packet_info PacketInfo; - void *pPacket; - struct rt_mac_table_entry *pMacEntry = NULL; - - pPacket = pTxBlk->pPacket; - RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pTxBlk->pSrcBufHeader, - &pTxBlk->SrcBufLen); - - pTxBlk->Wcid = RTMP_GET_PACKET_WCID(pPacket); - pTxBlk->apidx = RTMP_GET_PACKET_IF(pPacket); - pTxBlk->UserPriority = RTMP_GET_PACKET_UP(pPacket); - pTxBlk->FrameGap = IFS_HTTXOP; /* ASIC determine Frame Gap */ - - if (RTMP_GET_PACKET_CLEAR_EAP_FRAME(pTxBlk->pPacket)) - TX_BLK_SET_FLAG(pTxBlk, fTX_bClearEAPFrame); - else - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bClearEAPFrame); - - /* Default to clear this flag */ - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bForceNonQoS); - - if (pTxBlk->Wcid == MCAST_WCID) { - pTxBlk->pMacEntry = NULL; - { - pTxBlk->pTransmit = - &pAd->MacTab.Content[MCAST_WCID].HTPhyMode; - } - - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired); /* AckRequired = FALSE, when broadcast packet in Adhoc mode. */ - /*TX_BLK_SET_FLAG(pTxBlk, fTX_bForceLowRate); */ - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAllowFrag); - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM); - if (RTMP_GET_PACKET_MOREDATA(pPacket)) { - TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData); - } - - } else { - pTxBlk->pMacEntry = &pAd->MacTab.Content[pTxBlk->Wcid]; - pTxBlk->pTransmit = &pTxBlk->pMacEntry->HTPhyMode; - - pMacEntry = pTxBlk->pMacEntry; - - /* For all unicast packets, need Ack unless the Ack Policy is not set as NORMAL_ACK. */ - if (pAd->CommonCfg.AckPolicy[pTxBlk->QueIdx] != NORMAL_ACK) - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired); - else - TX_BLK_SET_FLAG(pTxBlk, fTX_bAckRequired); - - if ((pAd->OpMode == OPMODE_STA) && - (ADHOC_ON(pAd)) && - (RX_FILTER_TEST_FLAG(pAd, fRX_FILTER_ACCEPT_PROMISCUOUS))) { - if (pAd->CommonCfg.PSPXlink) - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bAckRequired); - } - - { - { - - /* If support WMM, enable it. */ - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_WMM_INUSED) - && CLIENT_STATUS_TEST_FLAG(pMacEntry, - fCLIENT_STATUS_WMM_CAPABLE)) - TX_BLK_SET_FLAG(pTxBlk, fTX_bWMM); - -/* if (pAd->StaCfg.bAutoTxRateSwitch) */ -/* TX_BLK_SET_FLAG(pTxBlk, fTX_AutoRateSwitch); */ - } - } - - if (pTxBlk->TxFrameType == TX_LEGACY_FRAME) { - if ((RTMP_GET_PACKET_LOWRATE(pPacket)) || ((pAd->OpMode == OPMODE_AP) && (pMacEntry->MaxHTPhyMode.field.MODE == MODE_CCK) && (pMacEntry->MaxHTPhyMode.field.MCS == RATE_1))) { /* Specific packet, i.e., bDHCPFrame, bEAPOLFrame, bWAIFrame, need force low rate. */ - pTxBlk->pTransmit = - &pAd->MacTab.Content[MCAST_WCID].HTPhyMode; - - /* Modify the WMM bit for ICV issue. If we have a packet with EOSP field need to set as 1, how to handle it??? */ - if (IS_HT_STA(pTxBlk->pMacEntry) && - (CLIENT_STATUS_TEST_FLAG - (pMacEntry, fCLIENT_STATUS_RALINK_CHIPSET)) - && ((pAd->CommonCfg.bRdg == TRUE) - && CLIENT_STATUS_TEST_FLAG(pMacEntry, - fCLIENT_STATUS_RDG_CAPABLE))) - { - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bWMM); - TX_BLK_SET_FLAG(pTxBlk, - fTX_bForceNonQoS); - } - } - - if ((IS_HT_RATE(pMacEntry) == FALSE) && (CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_PIGGYBACK_CAPABLE))) { /* Currently piggy-back only support when peer is operate in b/g mode. */ - TX_BLK_SET_FLAG(pTxBlk, fTX_bPiggyBack); - } - - if (RTMP_GET_PACKET_MOREDATA(pPacket)) { - TX_BLK_SET_FLAG(pTxBlk, fTX_bMoreData); - } - } else if (pTxBlk->TxFrameType == TX_FRAG_FRAME) { - TX_BLK_SET_FLAG(pTxBlk, fTX_bAllowFrag); - } - - pMacEntry->DebugTxCount++; - } - - return TRUE; -} - -BOOLEAN CanDoAggregateTransmit(struct rt_rtmp_adapter *pAd, - char * pPacket, struct rt_tx_blk *pTxBlk) -{ - - /*DBGPRINT(RT_DEBUG_TRACE, ("Check if can do aggregation! TxFrameType=%d!\n", pTxBlk->TxFrameType)); */ - - if (RTMP_GET_PACKET_WCID(pPacket) == MCAST_WCID) - return FALSE; - - if (RTMP_GET_PACKET_DHCP(pPacket) || - RTMP_GET_PACKET_EAPOL(pPacket) || RTMP_GET_PACKET_WAI(pPacket)) - return FALSE; - - if ((pTxBlk->TxFrameType == TX_AMSDU_FRAME) && ((pTxBlk->TotalFrameLen + GET_OS_PKT_LEN(pPacket)) > (RX_BUFFER_AGGRESIZE - 100))) { /* For AMSDU, allow the packets with total length < max-amsdu size */ - return FALSE; - } - - if ((pTxBlk->TxFrameType == TX_RALINK_FRAME) && (pTxBlk->TxPacketList.Number == 2)) { /* For RALINK-Aggregation, allow two frames in one batch. */ - return FALSE; - } - - if ((INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) /* must be unicast to AP */ - return TRUE; - else - return FALSE; - -} - -/* - ======================================================================== - - Routine Description: - To do the enqueue operation and extract the first item of waiting - list. If a number of available shared memory segments could meet - the request of extracted item, the extracted item will be fragmented - into shared memory segments. - - Arguments: - pAd Pointer to our adapter - pQueue Pointer to Waiting Queue - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPDeQueuePacket(struct rt_rtmp_adapter *pAd, IN BOOLEAN bIntContext, u8 QIdx, /* BulkOutPipeId */ - u8 Max_Tx_Packets) -{ - struct rt_queue_entry *pEntry = NULL; - void *pPacket; - int Status = NDIS_STATUS_SUCCESS; - u8 Count = 0; - struct rt_queue_header *pQueue; - unsigned long FreeNumber[NUM_OF_TX_RING]; - u8 QueIdx, sQIdx, eQIdx; - unsigned long IrqFlags = 0; - BOOLEAN hasTxDesc = FALSE; - struct rt_tx_blk TxBlk; - struct rt_tx_blk *pTxBlk; - - if (QIdx == NUM_OF_TX_RING) { - sQIdx = 0; - eQIdx = 3; /* 4 ACs, start from 0. */ - } else { - sQIdx = eQIdx = QIdx; - } - - for (QueIdx = sQIdx; QueIdx <= eQIdx; QueIdx++) { - Count = 0; - - RTMP_START_DEQUEUE(pAd, QueIdx, IrqFlags); - - while (1) { - if ((RTMP_TEST_FLAG - (pAd, - (fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS | - fRTMP_ADAPTER_RADIO_OFF | - fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST)))) { - RTMP_STOP_DEQUEUE(pAd, QueIdx, IrqFlags); - return; - } - - if (Count >= Max_Tx_Packets) - break; - - DEQUEUE_LOCK(&pAd->irq_lock, bIntContext, IrqFlags); - if (&pAd->TxSwQueue[QueIdx] == NULL) { - DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, - IrqFlags); - break; - } -#ifdef RTMP_MAC_PCI - FreeNumber[QueIdx] = GET_TXRING_FREENO(pAd, QueIdx); - - if (FreeNumber[QueIdx] <= 5) { - /* free Tx(QueIdx) resources */ - RTMPFreeTXDUponTxDmaDone(pAd, QueIdx); - FreeNumber[QueIdx] = - GET_TXRING_FREENO(pAd, QueIdx); - } -#endif /* RTMP_MAC_PCI // */ - - /* probe the Queue Head */ - pQueue = &pAd->TxSwQueue[QueIdx]; - pEntry = pQueue->Head; - if (pEntry == NULL) { - DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, - IrqFlags); - break; - } - - pTxBlk = &TxBlk; - NdisZeroMemory((u8 *)pTxBlk, sizeof(struct rt_tx_blk)); - /*InitializeQueueHeader(&pTxBlk->TxPacketList); // Didn't need it because we already memzero it. */ - pTxBlk->QueIdx = QueIdx; - - pPacket = QUEUE_ENTRY_TO_PACKET(pEntry); - - /* Early check to make sure we have enoguh Tx Resource. */ - hasTxDesc = - RTMP_HAS_ENOUGH_FREE_DESC(pAd, pTxBlk, - FreeNumber[QueIdx], - pPacket); - if (!hasTxDesc) { - pAd->PrivateInfo.TxRingFullCnt++; - - DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, - IrqFlags); - - break; - } - - pTxBlk->TxFrameType = TxPktClassification(pAd, pPacket); - pEntry = RemoveHeadQueue(pQueue); - pTxBlk->TotalFrameNum++; - pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); /* The real fragment number maybe vary */ - pTxBlk->TotalFrameLen += GET_OS_PKT_LEN(pPacket); - pTxBlk->pPacket = pPacket; - InsertTailQueue(&pTxBlk->TxPacketList, - PACKET_TO_QUEUE_ENTRY(pPacket)); - - if (pTxBlk->TxFrameType == TX_RALINK_FRAME - || pTxBlk->TxFrameType == TX_AMSDU_FRAME) { - /* Enhance SW Aggregation Mechanism */ - if (NEED_QUEUE_BACK_FOR_AGG - (pAd, QueIdx, FreeNumber[QueIdx], - pTxBlk->TxFrameType)) { - InsertHeadQueue(pQueue, - PACKET_TO_QUEUE_ENTRY - (pPacket)); - DEQUEUE_UNLOCK(&pAd->irq_lock, - bIntContext, IrqFlags); - break; - } - - do { - pEntry = pQueue->Head; - if (pEntry == NULL) - break; - - /* For TX_AMSDU_FRAME/TX_RALINK_FRAME, Need to check if next pakcet can do aggregation. */ - pPacket = QUEUE_ENTRY_TO_PACKET(pEntry); - FreeNumber[QueIdx] = - GET_TXRING_FREENO(pAd, QueIdx); - hasTxDesc = - RTMP_HAS_ENOUGH_FREE_DESC(pAd, - pTxBlk, - FreeNumber - [QueIdx], - pPacket); - if ((hasTxDesc == FALSE) - || - (CanDoAggregateTransmit - (pAd, pPacket, pTxBlk) == FALSE)) - break; - - /*Remove the packet from the TxSwQueue and insert into pTxBlk */ - pEntry = RemoveHeadQueue(pQueue); - ASSERT(pEntry); - pPacket = QUEUE_ENTRY_TO_PACKET(pEntry); - pTxBlk->TotalFrameNum++; - pTxBlk->TotalFragNum += RTMP_GET_PACKET_FRAGMENTS(pPacket); /* The real fragment number maybe vary */ - pTxBlk->TotalFrameLen += - GET_OS_PKT_LEN(pPacket); - InsertTailQueue(&pTxBlk->TxPacketList, - PACKET_TO_QUEUE_ENTRY - (pPacket)); - } while (1); - - if (pTxBlk->TxPacketList.Number == 1) - pTxBlk->TxFrameType = TX_LEGACY_FRAME; - } -#ifdef RTMP_MAC_USB - DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags); -#endif /* RTMP_MAC_USB // */ - Count += pTxBlk->TxPacketList.Number; - - /* Do HardTransmit now. */ - Status = STAHardTransmit(pAd, pTxBlk, QueIdx); - -#ifdef RTMP_MAC_PCI - DEQUEUE_UNLOCK(&pAd->irq_lock, bIntContext, IrqFlags); - /* static rate also need NICUpdateFifoStaCounters() function. */ - /*if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)) */ - NICUpdateFifoStaCounters(pAd); -#endif /* RTMP_MAC_PCI // */ - - } - - RTMP_STOP_DEQUEUE(pAd, QueIdx, IrqFlags); - -#ifdef RTMP_MAC_USB - if (!hasTxDesc) - RTUSBKickBulkOut(pAd); -#endif /* RTMP_MAC_USB // */ - } - -} - -/* - ======================================================================== - - Routine Description: - Calculates the duration which is required to transmit out frames - with given size and specified rate. - - Arguments: - pAd Pointer to our adapter - Rate Transmit rate - Size Frame size in units of byte - - Return Value: - Duration number in units of usec - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -u16 RTMPCalcDuration(struct rt_rtmp_adapter *pAd, u8 Rate, unsigned long Size) -{ - unsigned long Duration = 0; - - if (Rate < RATE_FIRST_OFDM_RATE) /* CCK */ - { - if ((Rate > RATE_1) - && OPSTATUS_TEST_FLAG(pAd, - fOP_STATUS_SHORT_PREAMBLE_INUSED)) - Duration = 96; /* 72+24 preamble+plcp */ - else - Duration = 192; /* 144+48 preamble+plcp */ - - Duration += (u16)((Size << 4) / RateIdTo500Kbps[Rate]); - if ((Size << 4) % RateIdTo500Kbps[Rate]) - Duration++; - } else if (Rate <= RATE_LAST_OFDM_RATE) /* OFDM rates */ - { - Duration = 20 + 6; /* 16+4 preamble+plcp + Signal Extension */ - Duration += - 4 * (u16)((11 + Size * 4) / RateIdTo500Kbps[Rate]); - if ((11 + Size * 4) % RateIdTo500Kbps[Rate]) - Duration += 4; - } else /*mimo rate */ - { - Duration = 20 + 6; /* 16+4 preamble+plcp + Signal Extension */ - } - - return (u16)Duration; -} - -/* - ======================================================================== - - Routine Description: - Calculates the duration which is required to transmit out frames - with given size and specified rate. - - Arguments: - pTxWI Pointer to head of each MPDU to HW. - Ack Setting for Ack requirement bit - Fragment Setting for Fragment bit - RetryMode Setting for retry mode - Ifs Setting for IFS gap - Rate Setting for transmit rate - Service Setting for service - Length Frame length - TxPreamble Short or Long preamble when using CCK rates - QueIdx - 0-3, according to 802.11e/d4.4 June/2003 - - Return Value: - None - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - See also : BASmartHardTransmit() ! - - ======================================================================== -*/ -void RTMPWriteTxWI(struct rt_rtmp_adapter *pAd, struct rt_txwi * pOutTxWI, IN BOOLEAN FRAG, IN BOOLEAN CFACK, IN BOOLEAN InsTimestamp, IN BOOLEAN AMPDU, IN BOOLEAN Ack, IN BOOLEAN NSeq, /* HW new a sequence. */ - u8 BASize, - u8 WCID, - unsigned long Length, - u8 PID, - u8 TID, - u8 TxRate, - u8 Txopmode, - IN BOOLEAN CfAck, IN HTTRANSMIT_SETTING * pTransmit) -{ - struct rt_mac_table_entry *pMac = NULL; - struct rt_txwi TxWI; - struct rt_txwi * pTxWI; - - if (WCID < MAX_LEN_OF_MAC_TABLE) - pMac = &pAd->MacTab.Content[WCID]; - - /* */ - /* Always use Long preamble before verifiation short preamble functionality works well. */ - /* Todo: remove the following line if short preamble functionality works */ - /* */ - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); - NdisZeroMemory(&TxWI, TXWI_SIZE); - pTxWI = &TxWI; - - pTxWI->FRAG = FRAG; - - pTxWI->CFACK = CFACK; - pTxWI->TS = InsTimestamp; - pTxWI->AMPDU = AMPDU; - pTxWI->ACK = Ack; - pTxWI->txop = Txopmode; - - pTxWI->NSEQ = NSeq; - /* John tune the performace with Intel Client in 20 MHz performance */ - BASize = pAd->CommonCfg.TxBASize; - if (pAd->MACVersion == 0x28720200) { - if (BASize > 13) - BASize = 13; - } else { - if (BASize > 7) - BASize = 7; - } - pTxWI->BAWinSize = BASize; - pTxWI->ShortGI = pTransmit->field.ShortGI; - pTxWI->STBC = pTransmit->field.STBC; - - pTxWI->WirelessCliID = WCID; - pTxWI->MPDUtotalByteCount = Length; - pTxWI->PacketId = PID; - - /* If CCK or OFDM, BW must be 20 */ - pTxWI->BW = - (pTransmit->field.MODE <= - MODE_OFDM) ? (BW_20) : (pTransmit->field.BW); - - pTxWI->MCS = pTransmit->field.MCS; - pTxWI->PHYMODE = pTransmit->field.MODE; - pTxWI->CFACK = CfAck; - - if (pMac) { - if (pAd->CommonCfg.bMIMOPSEnable) { - if ((pMac->MmpsMode == MMPS_DYNAMIC) - && (pTransmit->field.MCS > 7)) { - /* Dynamic MIMO Power Save Mode */ - pTxWI->MIMOps = 1; - } else if (pMac->MmpsMode == MMPS_STATIC) { - /* Static MIMO Power Save Mode */ - if (pTransmit->field.MODE >= MODE_HTMIX - && pTransmit->field.MCS > 7) { - pTxWI->MCS = 7; - pTxWI->MIMOps = 0; - } - } - } - /*pTxWI->MIMOps = (pMac->PsMode == PWR_MMPS)? 1:0; */ - if (pMac->bIAmBadAtheros - && (pMac->WepStatus != Ndis802_11WEPDisabled)) { - pTxWI->MpduDensity = 7; - } else { - pTxWI->MpduDensity = pMac->MpduDensity; - } - } - - pTxWI->PacketId = pTxWI->MCS; - NdisMoveMemory(pOutTxWI, &TxWI, sizeof(struct rt_txwi)); -} - -void RTMPWriteTxWI_Data(struct rt_rtmp_adapter *pAd, - struct rt_txwi * pTxWI, struct rt_tx_blk *pTxBlk) -{ - HTTRANSMIT_SETTING *pTransmit; - struct rt_mac_table_entry *pMacEntry; - u8 BASize; - - ASSERT(pTxWI); - - pTransmit = pTxBlk->pTransmit; - pMacEntry = pTxBlk->pMacEntry; - - /* */ - /* Always use Long preamble before verifiation short preamble functionality works well. */ - /* Todo: remove the following line if short preamble functionality works */ - /* */ - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); - NdisZeroMemory(pTxWI, TXWI_SIZE); - - pTxWI->FRAG = TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag); - pTxWI->ACK = TX_BLK_TEST_FLAG(pTxBlk, fTX_bAckRequired); - pTxWI->txop = pTxBlk->FrameGap; - - pTxWI->WirelessCliID = pTxBlk->Wcid; - - pTxWI->MPDUtotalByteCount = pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen; - pTxWI->CFACK = TX_BLK_TEST_FLAG(pTxBlk, fTX_bPiggyBack); - - /* If CCK or OFDM, BW must be 20 */ - pTxWI->BW = - (pTransmit->field.MODE <= - MODE_OFDM) ? (BW_20) : (pTransmit->field.BW); - pTxWI->AMPDU = ((pTxBlk->TxFrameType == TX_AMPDU_FRAME) ? TRUE : FALSE); - - /* John tune the performace with Intel Client in 20 MHz performance */ - BASize = pAd->CommonCfg.TxBASize; - if ((pTxBlk->TxFrameType == TX_AMPDU_FRAME) && (pMacEntry)) { - u8 RABAOriIdx = 0; /*The RA's BA Originator table index. */ - - RABAOriIdx = - pTxBlk->pMacEntry->BAOriWcidArray[pTxBlk->UserPriority]; - BASize = pAd->BATable.BAOriEntry[RABAOriIdx].BAWinSize; - } - - pTxWI->TxBF = pTransmit->field.TxBF; - pTxWI->BAWinSize = BASize; - pTxWI->ShortGI = pTransmit->field.ShortGI; - pTxWI->STBC = pTransmit->field.STBC; - - pTxWI->MCS = pTransmit->field.MCS; - pTxWI->PHYMODE = pTransmit->field.MODE; - - if (pMacEntry) { - if ((pMacEntry->MmpsMode == MMPS_DYNAMIC) - && (pTransmit->field.MCS > 7)) { - /* Dynamic MIMO Power Save Mode */ - pTxWI->MIMOps = 1; - } else if (pMacEntry->MmpsMode == MMPS_STATIC) { - /* Static MIMO Power Save Mode */ - if (pTransmit->field.MODE >= MODE_HTMIX - && pTransmit->field.MCS > 7) { - pTxWI->MCS = 7; - pTxWI->MIMOps = 0; - } - } - - if (pMacEntry->bIAmBadAtheros - && (pMacEntry->WepStatus != Ndis802_11WEPDisabled)) { - pTxWI->MpduDensity = 7; - } else { - pTxWI->MpduDensity = pMacEntry->MpduDensity; - } - } - - /* for rate adapation */ - pTxWI->PacketId = pTxWI->MCS; -} - -void RTMPWriteTxWI_Cache(struct rt_rtmp_adapter *pAd, - struct rt_txwi * pTxWI, struct rt_tx_blk *pTxBlk) -{ - PHTTRANSMIT_SETTING /*pTxHTPhyMode, */ pTransmit; - struct rt_mac_table_entry *pMacEntry; - - /* */ - /* update TXWI */ - /* */ - pMacEntry = pTxBlk->pMacEntry; - pTransmit = pTxBlk->pTransmit; - - /*if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)) */ - /*if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pMacEntry)) */ - /*if (TX_BLK_TEST_FLAG(pTxBlk, fTX_AutoRateSwitch)) */ - if (pMacEntry->bAutoTxRateSwitch) { - pTxWI->txop = IFS_HTTXOP; - - /* If CCK or OFDM, BW must be 20 */ - pTxWI->BW = - (pTransmit->field.MODE <= - MODE_OFDM) ? (BW_20) : (pTransmit->field.BW); - pTxWI->ShortGI = pTransmit->field.ShortGI; - pTxWI->STBC = pTransmit->field.STBC; - - pTxWI->MCS = pTransmit->field.MCS; - pTxWI->PHYMODE = pTransmit->field.MODE; - - /* set PID for TxRateSwitching */ - pTxWI->PacketId = pTransmit->field.MCS; - } - - pTxWI->AMPDU = ((pMacEntry->NoBADataCountDown == 0) ? TRUE : FALSE); - pTxWI->MIMOps = 0; - - if (pAd->CommonCfg.bMIMOPSEnable) { - /* MIMO Power Save Mode */ - if ((pMacEntry->MmpsMode == MMPS_DYNAMIC) - && (pTransmit->field.MCS > 7)) { - /* Dynamic MIMO Power Save Mode */ - pTxWI->MIMOps = 1; - } else if (pMacEntry->MmpsMode == MMPS_STATIC) { - /* Static MIMO Power Save Mode */ - if ((pTransmit->field.MODE >= MODE_HTMIX) - && (pTransmit->field.MCS > 7)) { - pTxWI->MCS = 7; - pTxWI->MIMOps = 0; - } - } - } - - pTxWI->MPDUtotalByteCount = pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen; - -} - -/* should be called only when - */ -/* 1. MEADIA_CONNECTED */ -/* 2. AGGREGATION_IN_USED */ -/* 3. Fragmentation not in used */ -/* 4. either no previous frame (pPrevAddr1=NULL) .OR. previoud frame is aggregatible */ -BOOLEAN TxFrameIsAggregatible(struct rt_rtmp_adapter *pAd, - u8 *pPrevAddr1, u8 *p8023hdr) -{ - - /* can't aggregate EAPOL (802.1x) frame */ - if ((p8023hdr[12] == 0x88) && (p8023hdr[13] == 0x8e)) - return FALSE; - - /* can't aggregate multicast/broadcast frame */ - if (p8023hdr[0] & 0x01) - return FALSE; - - if (INFRA_ON(pAd)) /* must be unicast to AP */ - return TRUE; - else if ((pPrevAddr1 == NULL) || MAC_ADDR_EQUAL(pPrevAddr1, p8023hdr)) /* unicast to same STA */ - return TRUE; - else - return FALSE; -} - -/* - ======================================================================== - - Routine Description: - Check the MSDU Aggregation policy - 1.HT aggregation is A-MSDU - 2.legaacy rate aggregation is software aggregation by Ralink. - - Arguments: - - Return Value: - - Note: - - ======================================================================== -*/ -BOOLEAN PeerIsAggreOn(struct rt_rtmp_adapter *pAd, - unsigned long TxRate, struct rt_mac_table_entry *pMacEntry) -{ - unsigned long AFlags = - (fCLIENT_STATUS_AMSDU_INUSED | fCLIENT_STATUS_AGGREGATION_CAPABLE); - - if (pMacEntry != NULL && CLIENT_STATUS_TEST_FLAG(pMacEntry, AFlags)) { - if (pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX) { - return TRUE; - } -#ifdef AGGREGATION_SUPPORT - if (TxRate >= RATE_6 && pAd->CommonCfg.bAggregationCapable && (!(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && CLIENT_STATUS_TEST_FLAG(pMacEntry, fCLIENT_STATUS_WMM_CAPABLE)))) { /* legacy Ralink Aggregation support */ - return TRUE; - } -#endif /* AGGREGATION_SUPPORT // */ - } - - return FALSE; - -} - -/* - ======================================================================== - - Routine Description: - Check and fine the packet waiting in SW queue with highest priority - - Arguments: - pAd Pointer to our adapter - - Return Value: - pQueue Pointer to Waiting Queue - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -struct rt_queue_header *RTMPCheckTxSwQueue(struct rt_rtmp_adapter *pAd, u8 *pQueIdx) -{ - - unsigned long Number; - /* 2004-11-15 to be removed. test aggregation only */ -/* if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)) && (*pNumber < 2)) */ -/* return NULL; */ - - Number = pAd->TxSwQueue[QID_AC_BK].Number - + pAd->TxSwQueue[QID_AC_BE].Number - + pAd->TxSwQueue[QID_AC_VI].Number - + pAd->TxSwQueue[QID_AC_VO].Number; - - if (pAd->TxSwQueue[QID_AC_VO].Head != NULL) { - *pQueIdx = QID_AC_VO; - return (&pAd->TxSwQueue[QID_AC_VO]); - } else if (pAd->TxSwQueue[QID_AC_VI].Head != NULL) { - *pQueIdx = QID_AC_VI; - return (&pAd->TxSwQueue[QID_AC_VI]); - } else if (pAd->TxSwQueue[QID_AC_BE].Head != NULL) { - *pQueIdx = QID_AC_BE; - return (&pAd->TxSwQueue[QID_AC_BE]); - } else if (pAd->TxSwQueue[QID_AC_BK].Head != NULL) { - *pQueIdx = QID_AC_BK; - return (&pAd->TxSwQueue[QID_AC_BK]); - } - /* No packet pending in Tx Sw queue */ - *pQueIdx = QID_AC_BK; - - return (NULL); -} - -/* - ======================================================================== - - Routine Description: - Suspend MSDU transmission - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - Note: - - ======================================================================== -*/ -void RTMPSuspendMsduTransmission(struct rt_rtmp_adapter *pAd) -{ - DBGPRINT(RT_DEBUG_TRACE, ("SCANNING, suspend MSDU transmission ...\n")); - - /* */ - /* Before BSS_SCAN_IN_PROGRESS, we need to keep Current R66 value and */ - /* use Lowbound as R66 value on ScanNextChannel(...) */ - /* */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, - &pAd->BbpTuning.R66CurrentValue); - - /* set BBP_R66 to 0x30/0x40 when scanning (AsicSwitchChannel will set R66 according to channel when scanning) */ - /*RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, (0x26 + GET_LNA_GAIN(pAd))); */ - RTMPSetAGCInitValue(pAd, BW_20); - - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS); - /*RTMP_IO_WRITE32(pAd, TX_CNTL_CSR, 0x000f0000); // abort all TX rings */ -} - -/* - ======================================================================== - - Routine Description: - Resume MSDU transmission - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPResumeMsduTransmission(struct rt_rtmp_adapter *pAd) -{ -/* u8 IrqState; */ - - DBGPRINT(RT_DEBUG_TRACE, ("SCAN done, resume MSDU transmission ...\n")); - - /* After finish BSS_SCAN_IN_PROGRESS, we need to restore Current R66 value */ - /* R66 should not be 0 */ - if (pAd->BbpTuning.R66CurrentValue == 0) { - pAd->BbpTuning.R66CurrentValue = 0x38; - DBGPRINT_ERR("RTMPResumeMsduTransmission, R66CurrentValue=0...\n"); - } - - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, - pAd->BbpTuning.R66CurrentValue); - - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS); -/* sample, for IRQ LOCK to SEM LOCK */ -/* IrqState = pAd->irq_disabled; */ -/* if (IrqState) */ -/* RTMPDeQueuePacket(pAd, TRUE, NUM_OF_TX_RING, MAX_TX_PROCESS); */ -/* else */ - RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); -} - -u32 deaggregate_AMSDU_announce(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 *pData, unsigned long DataSize) -{ - u16 PayloadSize; - u16 SubFrameSize; - struct rt_header_802_3 * pAMSDUsubheader; - u32 nMSDU; - u8 Header802_3[14]; - - u8 *pPayload, *pDA, *pSA, *pRemovedLLCSNAP; - void *pClonePacket; - - nMSDU = 0; - - while (DataSize > LENGTH_802_3) { - - nMSDU++; - - /*hex_dump("subheader", pData, 64); */ - pAMSDUsubheader = (struct rt_header_802_3 *) pData; - /*pData += LENGTH_802_3; */ - PayloadSize = - pAMSDUsubheader->Octet[1] + - (pAMSDUsubheader->Octet[0] << 8); - SubFrameSize = PayloadSize + LENGTH_802_3; - - if ((DataSize < SubFrameSize) || (PayloadSize > 1518)) { - break; - } - /*DBGPRINT(RT_DEBUG_TRACE,("%d subframe: Size = %d\n", nMSDU, PayloadSize)); */ - - pPayload = pData + LENGTH_802_3; - pDA = pData; - pSA = pData + MAC_ADDR_LEN; - - /* convert to 802.3 header */ - CONVERT_TO_802_3(Header802_3, pDA, pSA, pPayload, PayloadSize, - pRemovedLLCSNAP); - - if ((Header802_3[12] == 0x88) && (Header802_3[13] == 0x8E)) { - /* avoid local heap overflow, use dyanamic allocation */ - struct rt_mlme_queue_elem *Elem = - kmalloc(sizeof(struct rt_mlme_queue_elem), - MEM_ALLOC_FLAG); - if (Elem != NULL) { - memmove(Elem->Msg + - (LENGTH_802_11 + LENGTH_802_1_H), - pPayload, PayloadSize); - Elem->MsgLen = - LENGTH_802_11 + LENGTH_802_1_H + - PayloadSize; - /*WpaEAPOLKeyAction(pAd, Elem); */ - REPORT_MGMT_FRAME_TO_MLME(pAd, BSSID_WCID, - Elem->Msg, - Elem->MsgLen, 0, 0, 0, - 0); - kfree(Elem); - } - } - - { - if (pRemovedLLCSNAP) { - pPayload -= LENGTH_802_3; - PayloadSize += LENGTH_802_3; - NdisMoveMemory(pPayload, &Header802_3[0], - LENGTH_802_3); - } - } - - pClonePacket = ClonePacket(pAd, pPacket, pPayload, PayloadSize); - if (pClonePacket) { - ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pClonePacket, - RTMP_GET_PACKET_IF - (pPacket)); - } - - /* A-MSDU has padding to multiple of 4 including subframe header. */ - /* align SubFrameSize up to multiple of 4 */ - SubFrameSize = (SubFrameSize + 3) & (~0x3); - - if (SubFrameSize > 1528 || SubFrameSize < 32) { - break; - } - - if (DataSize > SubFrameSize) { - pData += SubFrameSize; - DataSize -= SubFrameSize; - } else { - /* end of A-MSDU */ - DataSize = 0; - } - } - - /* finally release original rx packet */ - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); - - return nMSDU; -} - -u32 BA_Reorder_AMSDU_Announce(struct rt_rtmp_adapter *pAd, void *pPacket) -{ - u8 *pData; - u16 DataSize; - u32 nMSDU = 0; - - pData = (u8 *)GET_OS_PKT_DATAPTR(pPacket); - DataSize = (u16)GET_OS_PKT_LEN(pPacket); - - nMSDU = deaggregate_AMSDU_announce(pAd, pPacket, pData, DataSize); - - return nMSDU; -} - -/* - ========================================================================== - Description: - Look up the MAC address in the MAC table. Return NULL if not found. - Return: - pEntry - pointer to the MAC entry; NULL is not found - ========================================================================== -*/ -struct rt_mac_table_entry *MacTableLookup(struct rt_rtmp_adapter *pAd, u8 *pAddr) -{ - unsigned long HashIdx; - struct rt_mac_table_entry *pEntry = NULL; - - HashIdx = MAC_ADDR_HASH_INDEX(pAddr); - pEntry = pAd->MacTab.Hash[HashIdx]; - - while (pEntry - && (pEntry->ValidAsCLI || pEntry->ValidAsWDS - || pEntry->ValidAsApCli || pEntry->ValidAsMesh)) { - if (MAC_ADDR_EQUAL(pEntry->Addr, pAddr)) { - break; - } else - pEntry = pEntry->pNext; - } - - return pEntry; -} - -struct rt_mac_table_entry *MacTableInsertEntry(struct rt_rtmp_adapter *pAd, - u8 *pAddr, - u8 apidx, IN BOOLEAN CleanAll) -{ - u8 HashIdx; - int i, FirstWcid; - struct rt_mac_table_entry *pEntry = NULL, *pCurrEntry; -/* u16 offset; */ -/* unsigned long addr; */ - - /* if FULL, return */ - if (pAd->MacTab.Size >= MAX_LEN_OF_MAC_TABLE) - return NULL; - - FirstWcid = 1; - - if (pAd->StaCfg.BssType == BSS_INFRA) - FirstWcid = 2; - - /* allocate one MAC entry */ - NdisAcquireSpinLock(&pAd->MacTabLock); - for (i = FirstWcid; i < MAX_LEN_OF_MAC_TABLE; i++) /* skip entry#0 so that "entry index == AID" for fast lookup */ - { - /* pick up the first available vacancy */ - if ((pAd->MacTab.Content[i].ValidAsCLI == FALSE) && - (pAd->MacTab.Content[i].ValidAsWDS == FALSE) && - (pAd->MacTab.Content[i].ValidAsApCli == FALSE) && - (pAd->MacTab.Content[i].ValidAsMesh == FALSE) - ) { - pEntry = &pAd->MacTab.Content[i]; - if (CleanAll == TRUE) { - pEntry->MaxSupportedRate = RATE_11; - pEntry->CurrTxRate = RATE_11; - NdisZeroMemory(pEntry, sizeof(struct rt_mac_table_entry)); - pEntry->PairwiseKey.KeyLen = 0; - pEntry->PairwiseKey.CipherAlg = CIPHER_NONE; - } - { - { - pEntry->ValidAsCLI = TRUE; - pEntry->ValidAsWDS = FALSE; - pEntry->ValidAsApCli = FALSE; - pEntry->ValidAsMesh = FALSE; - pEntry->ValidAsDls = FALSE; - } - } - - pEntry->bIAmBadAtheros = FALSE; - pEntry->pAd = pAd; - pEntry->CMTimerRunning = FALSE; - pEntry->EnqueueEapolStartTimerRunning = - EAPOL_START_DISABLE; - pEntry->RSNIE_Len = 0; - NdisZeroMemory(pEntry->R_Counter, - sizeof(pEntry->R_Counter)); - pEntry->ReTryCounter = PEER_MSG1_RETRY_TIMER_CTR; - - if (pEntry->ValidAsMesh) - pEntry->apidx = - (apidx - MIN_NET_DEVICE_FOR_MESH); - else if (pEntry->ValidAsApCli) - pEntry->apidx = - (apidx - MIN_NET_DEVICE_FOR_APCLI); - else if (pEntry->ValidAsWDS) - pEntry->apidx = - (apidx - MIN_NET_DEVICE_FOR_WDS); - else - pEntry->apidx = apidx; - - { - { - pEntry->AuthMode = pAd->StaCfg.AuthMode; - pEntry->WepStatus = - pAd->StaCfg.WepStatus; - pEntry->PrivacyFilter = - Ndis802_11PrivFilterAcceptAll; -#ifdef RTMP_MAC_PCI - AsicRemovePairwiseKeyEntry(pAd, - pEntry-> - apidx, - (u8)i); -#endif /* RTMP_MAC_PCI // */ - } - } - - pEntry->GTKState = REKEY_NEGOTIATING; - pEntry->PairwiseKey.KeyLen = 0; - pEntry->PairwiseKey.CipherAlg = CIPHER_NONE; - pEntry->PortSecured = WPA_802_1X_PORT_NOT_SECURED; - - pEntry->PMKID_CacheIdx = ENTRY_NOT_FOUND; - COPY_MAC_ADDR(pEntry->Addr, pAddr); - pEntry->Sst = SST_NOT_AUTH; - pEntry->AuthState = AS_NOT_AUTH; - pEntry->Aid = (u16)i; /*0; */ - pEntry->CapabilityInfo = 0; - pEntry->PsMode = PWR_ACTIVE; - pEntry->PsQIdleCount = 0; - pEntry->NoDataIdleCount = 0; - pEntry->AssocDeadLine = MAC_TABLE_ASSOC_TIMEOUT; - pEntry->ContinueTxFailCnt = 0; - InitializeQueueHeader(&pEntry->PsQueue); - - pAd->MacTab.Size++; - /* Add this entry into ASIC RX WCID search table */ - RTMP_STA_ENTRY_ADD(pAd, pEntry); - - DBGPRINT(RT_DEBUG_TRACE, - ("MacTableInsertEntry - allocate entry #%d, Total= %d\n", - i, pAd->MacTab.Size)); - break; - } - } - - /* add this MAC entry into HASH table */ - if (pEntry) { - HashIdx = MAC_ADDR_HASH_INDEX(pAddr); - if (pAd->MacTab.Hash[HashIdx] == NULL) { - pAd->MacTab.Hash[HashIdx] = pEntry; - } else { - pCurrEntry = pAd->MacTab.Hash[HashIdx]; - while (pCurrEntry->pNext != NULL) - pCurrEntry = pCurrEntry->pNext; - pCurrEntry->pNext = pEntry; - } - } - - NdisReleaseSpinLock(&pAd->MacTabLock); - return pEntry; -} - -/* - ========================================================================== - Description: - Delete a specified client from MAC table - ========================================================================== - */ -BOOLEAN MacTableDeleteEntry(struct rt_rtmp_adapter *pAd, - u16 wcid, u8 *pAddr) -{ - u16 HashIdx; - struct rt_mac_table_entry *pEntry, *pPrevEntry, *pProbeEntry; - BOOLEAN Cancelled; - /*u16 offset; // unused variable */ - /*u8 j; // unused variable */ - - if (wcid >= MAX_LEN_OF_MAC_TABLE) - return FALSE; - - NdisAcquireSpinLock(&pAd->MacTabLock); - - HashIdx = MAC_ADDR_HASH_INDEX(pAddr); - /*pEntry = pAd->MacTab.Hash[HashIdx]; */ - pEntry = &pAd->MacTab.Content[wcid]; - - if (pEntry - && (pEntry->ValidAsCLI || pEntry->ValidAsApCli || pEntry->ValidAsWDS - || pEntry->ValidAsMesh)) { - if (MAC_ADDR_EQUAL(pEntry->Addr, pAddr)) { - - /* Delete this entry from ASIC on-chip WCID Table */ - RTMP_STA_ENTRY_MAC_RESET(pAd, wcid); - - /* free resources of BA */ - BASessionTearDownALL(pAd, pEntry->Aid); - - pPrevEntry = NULL; - pProbeEntry = pAd->MacTab.Hash[HashIdx]; - ASSERT(pProbeEntry); - - /* update Hash list */ - do { - if (pProbeEntry == pEntry) { - if (pPrevEntry == NULL) { - pAd->MacTab.Hash[HashIdx] = - pEntry->pNext; - } else { - pPrevEntry->pNext = - pEntry->pNext; - } - break; - } - - pPrevEntry = pProbeEntry; - pProbeEntry = pProbeEntry->pNext; - } while (pProbeEntry); - - /* not found ! */ - ASSERT(pProbeEntry != NULL); - - RTMP_STA_ENTRY_KEY_DEL(pAd, BSS0, wcid); - - if (pEntry->EnqueueEapolStartTimerRunning != - EAPOL_START_DISABLE) { - RTMPCancelTimer(&pEntry-> - EnqueueStartForPSKTimer, - &Cancelled); - pEntry->EnqueueEapolStartTimerRunning = - EAPOL_START_DISABLE; - } - - NdisZeroMemory(pEntry, sizeof(struct rt_mac_table_entry)); - pAd->MacTab.Size--; - DBGPRINT(RT_DEBUG_TRACE, - ("MacTableDeleteEntry1 - Total= %d\n", - pAd->MacTab.Size)); - } else { - DBGPRINT(RT_DEBUG_OFF, - ("\n%s: Impossible Wcid = %d !\n", - __func__, wcid)); - } - } - - NdisReleaseSpinLock(&pAd->MacTabLock); - - /*Reset operating mode when no Sta. */ - if (pAd->MacTab.Size == 0) { - pAd->CommonCfg.AddHTInfo.AddHtInfo2.OperaionMode = 0; - RTMP_UPDATE_PROTECT(pAd); /* edit by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */ - } - - return TRUE; -} - -/* - ========================================================================== - Description: - This routine reset the entire MAC table. All packets pending in - the power-saving queues are freed here. - ========================================================================== - */ -void MacTableReset(struct rt_rtmp_adapter *pAd) -{ - int i; - - DBGPRINT(RT_DEBUG_TRACE, ("MacTableReset\n")); - /*NdisAcquireSpinLock(&pAd->MacTabLock); */ - - for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) { -#ifdef RTMP_MAC_PCI - RTMP_STA_ENTRY_MAC_RESET(pAd, i); -#endif /* RTMP_MAC_PCI // */ - if (pAd->MacTab.Content[i].ValidAsCLI == TRUE) { - - /* free resources of BA */ - BASessionTearDownALL(pAd, i); - - pAd->MacTab.Content[i].ValidAsCLI = FALSE; - -#ifdef RTMP_MAC_USB - NdisZeroMemory(pAd->MacTab.Content[i].Addr, 6); - RTMP_STA_ENTRY_MAC_RESET(pAd, i); -#endif /* RTMP_MAC_USB // */ - - /*AsicDelWcidTab(pAd, i); */ - } - } - - return; -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void AssocParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_assoc_req *AssocReq, - u8 *pAddr, - u16 CapabilityInfo, - unsigned long Timeout, u16 ListenIntv) -{ - COPY_MAC_ADDR(AssocReq->Addr, pAddr); - /* Add mask to support 802.11b mode only */ - AssocReq->CapabilityInfo = CapabilityInfo & SUPPORTED_CAPABILITY_INFO; /* not cf-pollable, not cf-poll-request */ - AssocReq->Timeout = Timeout; - AssocReq->ListenIntv = ListenIntv; -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void DisassocParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_disassoc_req *DisassocReq, - u8 *pAddr, u16 Reason) -{ - COPY_MAC_ADDR(DisassocReq->Addr, pAddr); - DisassocReq->Reason = Reason; -} - -/* - ======================================================================== - - Routine Description: - Check the out going frame, if this is an DHCP or ARP datagram - will be duplicate another frame at low data rate transmit. - - Arguments: - pAd Pointer to our adapter - pPacket Pointer to outgoing Ndis frame - - Return Value: - TRUE To be duplicate at Low data rate transmit. (1mb) - FALSE Do nothing. - - IRQL = DISPATCH_LEVEL - - Note: - - MAC header + IP Header + UDP Header - 14 Bytes 20 Bytes - - UDP Header - 00|01|02|03|04|05|06|07|08|09|10|11|12|13|14|15| - Source Port - 16|17|18|19|20|21|22|23|24|25|26|27|28|29|30|31| - Destination Port - - port 0x43 means Bootstrap Protocol, server. - Port 0x44 means Bootstrap Protocol, client. - - ======================================================================== -*/ - -BOOLEAN RTMPCheckDHCPFrame(struct rt_rtmp_adapter *pAd, void *pPacket) -{ - struct rt_packet_info PacketInfo; - unsigned long NumberOfBytesRead = 0; - unsigned long CurrentOffset = 0; - void *pVirtualAddress = NULL; - u32 NdisBufferLength; - u8 *pSrc; - u16 Protocol; - u8 ByteOffset36 = 0; - u8 ByteOffset38 = 0; - BOOLEAN ReadFirstParm = TRUE; - - RTMP_QueryPacketInfo(pPacket, &PacketInfo, (u8 **) & pVirtualAddress, - &NdisBufferLength); - - NumberOfBytesRead += NdisBufferLength; - pSrc = (u8 *)pVirtualAddress; - Protocol = *(pSrc + 12) * 256 + *(pSrc + 13); - - /* */ - /* Check DHCP & BOOTP protocol */ - /* */ - while (NumberOfBytesRead <= PacketInfo.TotalPacketLength) { - if ((NumberOfBytesRead >= 35) && (ReadFirstParm == TRUE)) { - CurrentOffset = - 35 - (NumberOfBytesRead - NdisBufferLength); - ByteOffset36 = *(pSrc + CurrentOffset); - ReadFirstParm = FALSE; - } - - if (NumberOfBytesRead >= 37) { - CurrentOffset = - 37 - (NumberOfBytesRead - NdisBufferLength); - ByteOffset38 = *(pSrc + CurrentOffset); - /*End of Read */ - break; - } - return FALSE; - } - - /* Check for DHCP & BOOTP protocol */ - if ((ByteOffset36 != 0x44) || (ByteOffset38 != 0x43)) { - /* */ - /* 2054 (hex 0806) for ARP datagrams */ - /* if this packet is not ARP datagrams, then do nothing */ - /* ARP datagrams will also be duplicate at 1mb broadcast frames */ - /* */ - if (Protocol != 0x0806) - return FALSE; - } - - return TRUE; -} - -BOOLEAN RTMPCheckEtherType(struct rt_rtmp_adapter *pAd, void *pPacket) -{ - u16 TypeLen; - u8 Byte0, Byte1; - u8 *pSrcBuf; - u32 pktLen; - u16 srcPort, dstPort; - BOOLEAN status = TRUE; - - pSrcBuf = GET_OS_PKT_DATAPTR(pPacket); - pktLen = GET_OS_PKT_LEN(pPacket); - - ASSERT(pSrcBuf); - - RTMP_SET_PACKET_SPECIFIC(pPacket, 0); - - /* get Ethernet protocol field */ - TypeLen = (pSrcBuf[12] << 8) | pSrcBuf[13]; - - pSrcBuf += LENGTH_802_3; /* Skip the Ethernet Header. */ - - if (TypeLen <= 1500) { /* 802.3, 802.3 LLC */ - /* - DestMAC(6) + SrcMAC(6) + Length(2) + - DSAP(1) + SSAP(1) + Control(1) + - if the DSAP = 0xAA, SSAP=0xAA, Contorl = 0x03, it has a 5-bytes SNAP header. - => + SNAP (5, OriginationID(3) + etherType(2)) - */ - if (pSrcBuf[0] == 0xAA && pSrcBuf[1] == 0xAA - && pSrcBuf[2] == 0x03) { - Sniff2BytesFromNdisBuffer((char *)pSrcBuf, 6, - &Byte0, &Byte1); - RTMP_SET_PACKET_LLCSNAP(pPacket, 1); - TypeLen = (u16)((Byte0 << 8) + Byte1); - pSrcBuf += 8; /* Skip this LLC/SNAP header */ - } else { - /*It just has 3-byte LLC header, maybe a legacy ether type frame. we didn't handle it. */ - } - } - /* If it's a VLAN packet, get the real Type/Length field. */ - if (TypeLen == 0x8100) { - /* 0x8100 means VLAN packets */ - - /* Dest. MAC Address (6-bytes) + - Source MAC Address (6-bytes) + - Length/Type = 802.1Q Tag Type (2-byte) + - Tag Control Information (2-bytes) + - Length / Type (2-bytes) + - data payload (0-n bytes) + - Pad (0-p bytes) + - Frame Check Sequence (4-bytes) */ - - RTMP_SET_PACKET_VLAN(pPacket, 1); - Sniff2BytesFromNdisBuffer((char *)pSrcBuf, 2, &Byte0, - &Byte1); - TypeLen = (u16)((Byte0 << 8) + Byte1); - - pSrcBuf += 4; /* Skip the VLAN Header. */ - } - - switch (TypeLen) { - case 0x0800: - { - ASSERT((pktLen > 34)); - if (*(pSrcBuf + 9) == 0x11) { /* udp packet */ - ASSERT((pktLen > 34)); /* 14 for ethernet header, 20 for IP header */ - - pSrcBuf += 20; /* Skip the IP header */ - srcPort = - OS_NTOHS(get_unaligned - ((u16 *)(pSrcBuf))); - dstPort = - OS_NTOHS(get_unaligned - ((u16 *)(pSrcBuf + 2))); - - if ((srcPort == 0x44 && dstPort == 0x43) || (srcPort == 0x43 && dstPort == 0x44)) { /*It's a BOOTP/DHCP packet */ - RTMP_SET_PACKET_DHCP(pPacket, 1); - } - } - } - break; - case 0x0806: - { - /*ARP Packet. */ - RTMP_SET_PACKET_DHCP(pPacket, 1); - } - break; - case 0x888e: - { - /* EAPOL Packet. */ - RTMP_SET_PACKET_EAPOL(pPacket, 1); - } - break; - default: - status = FALSE; - break; - } - - return status; - -} - -void Update_Rssi_Sample(struct rt_rtmp_adapter *pAd, - struct rt_rssi_sample *pRssi, struct rt_rxwi * pRxWI) -{ - char rssi0 = pRxWI->RSSI0; - char rssi1 = pRxWI->RSSI1; - char rssi2 = pRxWI->RSSI2; - - if (rssi0 != 0) { - pRssi->LastRssi0 = ConvertToRssi(pAd, (char)rssi0, RSSI_0); - pRssi->AvgRssi0X8 = - (pRssi->AvgRssi0X8 - pRssi->AvgRssi0) + pRssi->LastRssi0; - pRssi->AvgRssi0 = pRssi->AvgRssi0X8 >> 3; - } - - if (rssi1 != 0) { - pRssi->LastRssi1 = ConvertToRssi(pAd, (char)rssi1, RSSI_1); - pRssi->AvgRssi1X8 = - (pRssi->AvgRssi1X8 - pRssi->AvgRssi1) + pRssi->LastRssi1; - pRssi->AvgRssi1 = pRssi->AvgRssi1X8 >> 3; - } - - if (rssi2 != 0) { - pRssi->LastRssi2 = ConvertToRssi(pAd, (char)rssi2, RSSI_2); - pRssi->AvgRssi2X8 = - (pRssi->AvgRssi2X8 - pRssi->AvgRssi2) + pRssi->LastRssi2; - pRssi->AvgRssi2 = pRssi->AvgRssi2X8 >> 3; - } -} - -/* Normal legacy Rx packet indication */ -void Indicate_Legacy_Packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID) -{ - void *pRxPacket = pRxBlk->pRxPacket; - u8 Header802_3[LENGTH_802_3]; - - /* 1. get 802.3 Header */ - /* 2. remove LLC */ - /* a. pointer pRxBlk->pData to payload */ - /* b. modify pRxBlk->DataSize */ - RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3); - - if (pRxBlk->DataSize > MAX_RX_PKT_LEN) { - - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); - return; - } - - STATS_INC_RX_PACKETS(pAd, FromWhichBSSID); - -#ifdef RTMP_MAC_USB - if (pAd->CommonCfg.bDisableReordering == 0) { - struct rt_ba_rec_entry *pBAEntry; - unsigned long Now32; - u8 Wcid = pRxBlk->pRxWI->WirelessCliID; - u8 TID = pRxBlk->pRxWI->TID; - u16 Idx; - -#define REORDERING_PACKET_TIMEOUT ((100 * OS_HZ)/1000) /* system ticks -- 100 ms */ - - if (Wcid < MAX_LEN_OF_MAC_TABLE) { - Idx = pAd->MacTab.Content[Wcid].BARecWcidArray[TID]; - if (Idx != 0) { - pBAEntry = &pAd->BATable.BARecEntry[Idx]; - /* update last rx time */ - NdisGetSystemUpTime(&Now32); - if ((pBAEntry->list.qlen > 0) && - RTMP_TIME_AFTER((unsigned long)Now32, - (unsigned long)(pBAEntry-> - LastIndSeqAtTimer - + - (REORDERING_PACKET_TIMEOUT))) - ) { - DBGPRINT(RT_DEBUG_OFF, - ("Indicate_Legacy_Packet():flush reordering_timeout_mpdus! RxWI->Flags=%d, pRxWI.TID=%d, RxD->AMPDU=%d!\n", - pRxBlk->Flags, - pRxBlk->pRxWI->TID, - pRxBlk->RxD.AMPDU)); - hex_dump("Dump the legacy Packet:", - GET_OS_PKT_DATAPTR(pRxBlk-> - pRxPacket), - 64); - ba_flush_reordering_timeout_mpdus(pAd, - pBAEntry, - Now32); - } - } - } - } -#endif /* RTMP_MAC_USB // */ - - wlan_802_11_to_802_3_packet(pAd, pRxBlk, Header802_3, FromWhichBSSID); - - /* */ - /* pass this 802.3 packet to upper layer or forward this packet to WM directly */ - /* */ - ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pRxPacket, FromWhichBSSID); -} - -/* Normal, AMPDU or AMSDU */ -void CmmRxnonRalinkFrameIndicate(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID) -{ - if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU) - && (pAd->CommonCfg.bDisableReordering == 0)) { - Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID); - } else { - if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMSDU)) { - /* handle A-MSDU */ - Indicate_AMSDU_Packet(pAd, pRxBlk, FromWhichBSSID); - } else { - Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID); - } - } -} - -void CmmRxRalinkFrameIndicate(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID) -{ - u8 Header802_3[LENGTH_802_3]; - u16 Msdu2Size; - u16 Payload1Size, Payload2Size; - u8 *pData2; - void *pPacket2 = NULL; - - Msdu2Size = *(pRxBlk->pData) + (*(pRxBlk->pData + 1) << 8); - - if ((Msdu2Size <= 1536) && (Msdu2Size < pRxBlk->DataSize)) { - /* skip two byte MSDU2 len */ - pRxBlk->pData += 2; - pRxBlk->DataSize -= 2; - } else { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - - /* get 802.3 Header and remove LLC */ - RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(pRxBlk, Header802_3); - - ASSERT(pRxBlk->pRxPacket); - - /* Ralink Aggregation frame */ - pAd->RalinkCounters.OneSecRxAggregationCount++; - Payload1Size = pRxBlk->DataSize - Msdu2Size; - Payload2Size = Msdu2Size - LENGTH_802_3; - - pData2 = pRxBlk->pData + Payload1Size + LENGTH_802_3; - - pPacket2 = - duplicate_pkt(pAd, (pData2 - LENGTH_802_3), LENGTH_802_3, pData2, - Payload2Size, FromWhichBSSID); - - if (!pPacket2) { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - /* update payload size of 1st packet */ - pRxBlk->DataSize = Payload1Size; - wlan_802_11_to_802_3_packet(pAd, pRxBlk, Header802_3, FromWhichBSSID); - - ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pRxBlk->pRxPacket, - FromWhichBSSID); - - if (pPacket2) { - ANNOUNCE_OR_FORWARD_802_3_PACKET(pAd, pPacket2, FromWhichBSSID); - } -} - -#define RESET_FRAGFRAME(_fragFrame) \ - { \ - _fragFrame.RxSize = 0; \ - _fragFrame.Sequence = 0; \ - _fragFrame.LastFrag = 0; \ - _fragFrame.Flags = 0; \ - } - -void *RTMPDeFragmentDataFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk) -{ - struct rt_header_802_11 * pHeader = pRxBlk->pHeader; - void *pRxPacket = pRxBlk->pRxPacket; - u8 *pData = pRxBlk->pData; - u16 DataSize = pRxBlk->DataSize; - void *pRetPacket = NULL; - u8 *pFragBuffer = NULL; - BOOLEAN bReassDone = FALSE; - u8 HeaderRoom = 0; - - ASSERT(pHeader); - - HeaderRoom = pData - (u8 *) pHeader; - - /* Re-assemble the fragmented packets */ - if (pHeader->Frag == 0) /* Frag. Number is 0 : First frag or only one pkt */ - { - /* the first pkt of fragment, record it. */ - if (pHeader->FC.MoreFrag) { - ASSERT(pAd->FragFrame.pFragPacket); - pFragBuffer = - GET_OS_PKT_DATAPTR(pAd->FragFrame.pFragPacket); - pAd->FragFrame.RxSize = DataSize + HeaderRoom; - NdisMoveMemory(pFragBuffer, pHeader, - pAd->FragFrame.RxSize); - pAd->FragFrame.Sequence = pHeader->Sequence; - pAd->FragFrame.LastFrag = pHeader->Frag; /* Should be 0 */ - ASSERT(pAd->FragFrame.LastFrag == 0); - goto done; /* end of processing this frame */ - } - } else /*Middle & End of fragment */ - { - if ((pHeader->Sequence != pAd->FragFrame.Sequence) || - (pHeader->Frag != (pAd->FragFrame.LastFrag + 1))) { - /* Fragment is not the same sequence or out of fragment number order */ - /* Reset Fragment control blk */ - RESET_FRAGFRAME(pAd->FragFrame); - DBGPRINT(RT_DEBUG_ERROR, - ("Fragment is not the same sequence or out of fragment number order.\n")); - goto done; /* give up this frame */ - } else if ((pAd->FragFrame.RxSize + DataSize) > MAX_FRAME_SIZE) { - /* Fragment frame is too large, it exeeds the maximum frame size. */ - /* Reset Fragment control blk */ - RESET_FRAGFRAME(pAd->FragFrame); - DBGPRINT(RT_DEBUG_ERROR, - ("Fragment frame is too large, it exeeds the maximum frame size.\n")); - goto done; /* give up this frame */ - } - /* */ - /* Broadcom AP(BCM94704AGR) will send out LLC in fragment's packet, LLC only can accpet at first fragment. */ - /* In this case, we will dropt it. */ - /* */ - if (NdisEqualMemory(pData, SNAP_802_1H, sizeof(SNAP_802_1H))) { - DBGPRINT(RT_DEBUG_ERROR, - ("Find another LLC at Middle or End fragment(SN=%d, Frag=%d)\n", - pHeader->Sequence, pHeader->Frag)); - goto done; /* give up this frame */ - } - - pFragBuffer = GET_OS_PKT_DATAPTR(pAd->FragFrame.pFragPacket); - - /* concatenate this fragment into the re-assembly buffer */ - NdisMoveMemory((pFragBuffer + pAd->FragFrame.RxSize), pData, - DataSize); - pAd->FragFrame.RxSize += DataSize; - pAd->FragFrame.LastFrag = pHeader->Frag; /* Update fragment number */ - - /* Last fragment */ - if (pHeader->FC.MoreFrag == FALSE) { - bReassDone = TRUE; - } - } - -done: - /* always release rx fragmented packet */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); - - /* return defragmented packet if packet is reassembled completely */ - /* otherwise return NULL */ - if (bReassDone) { - void *pNewFragPacket; - - /* allocate a new packet buffer for fragment */ - pNewFragPacket = - RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE); - if (pNewFragPacket) { - /* update RxBlk */ - pRetPacket = pAd->FragFrame.pFragPacket; - pAd->FragFrame.pFragPacket = pNewFragPacket; - pRxBlk->pHeader = - (struct rt_header_802_11 *) GET_OS_PKT_DATAPTR(pRetPacket); - pRxBlk->pData = (u8 *) pRxBlk->pHeader + HeaderRoom; - pRxBlk->DataSize = pAd->FragFrame.RxSize - HeaderRoom; - pRxBlk->pRxPacket = pRetPacket; - } else { - RESET_FRAGFRAME(pAd->FragFrame); - } - } - - return pRetPacket; -} - -void Indicate_AMSDU_Packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID) -{ - u32 nMSDU; - - update_os_packet_info(pAd, pRxBlk, FromWhichBSSID); - RTMP_SET_PACKET_IF(pRxBlk->pRxPacket, FromWhichBSSID); - nMSDU = - deaggregate_AMSDU_announce(pAd, pRxBlk->pRxPacket, pRxBlk->pData, - pRxBlk->DataSize); -} - -void Indicate_EAPOL_Packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID) -{ - struct rt_mac_table_entry *pEntry = NULL; - - { - pEntry = &pAd->MacTab.Content[BSSID_WCID]; - STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, FromWhichBSSID); - return; - } - - if (pEntry == NULL) { - DBGPRINT(RT_DEBUG_WARN, - ("Indicate_EAPOL_Packet: drop and release the invalid packet.\n")); - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, - NDIS_STATUS_FAILURE); - return; - } -} - -#define BCN_TBTT_OFFSET 64 /*defer 64 us */ -void ReSyncBeaconTime(struct rt_rtmp_adapter *pAd) -{ - - u32 Offset; - - Offset = (pAd->TbttTickCount) % (BCN_TBTT_OFFSET); - - pAd->TbttTickCount++; - - /* */ - /* The updated BeaconInterval Value will affect Beacon Interval after two TBTT */ - /* beacasue the original BeaconInterval had been loaded into next TBTT_TIMER */ - /* */ - if (Offset == (BCN_TBTT_OFFSET - 2)) { - BCN_TIME_CFG_STRUC csr; - RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word); - csr.field.BeaconInterval = (pAd->CommonCfg.BeaconPeriod << 4) - 1; /* ASIC register in units of 1/16 TU = 64us */ - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word); - } else { - if (Offset == (BCN_TBTT_OFFSET - 1)) { - BCN_TIME_CFG_STRUC csr; - - RTMP_IO_READ32(pAd, BCN_TIME_CFG, &csr.word); - csr.field.BeaconInterval = (pAd->CommonCfg.BeaconPeriod) << 4; /* ASIC register in units of 1/16 TU */ - RTMP_IO_WRITE32(pAd, BCN_TIME_CFG, csr.word); - } - } -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_data_pci.c b/trunk/drivers/staging/rt2860/common/cmm_data_pci.c deleted file mode 100644 index bef0bbd8cef7..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_data_pci.c +++ /dev/null @@ -1,1096 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - */ - -/* - All functions in this file must be PCI-depended, or you should out your function - in other files. - -*/ -#include "../rt_config.h" - -u16 RtmpPCI_WriteTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - IN BOOLEAN bIsLast, u16 * FreeNumber) -{ - - u8 *pDMAHeaderBufVA; - u16 TxIdx, RetTxIdx; - struct rt_txd * pTxD; - u32 BufBasePaLow; - struct rt_rtmp_tx_ring *pTxRing; - u16 hwHeaderLen; - - /* */ - /* get Tx Ring Resource */ - /* */ - pTxRing = &pAd->TxRing[pTxBlk->QueIdx]; - TxIdx = pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx; - pDMAHeaderBufVA = (u8 *)pTxRing->Cell[TxIdx].DmaBuf.AllocVa; - BufBasePaLow = - RTMP_GetPhysicalAddressLow(pTxRing->Cell[TxIdx].DmaBuf.AllocPa); - - /* copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer */ - if (pTxBlk->TxFrameType == TX_AMSDU_FRAME) { - /*hwHeaderLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_AMSDU_SUBFRAMEHEAD, 4)+LENGTH_AMSDU_SUBFRAMEHEAD; */ - hwHeaderLen = - pTxBlk->MpduHeaderLen - LENGTH_AMSDU_SUBFRAMEHEAD + - pTxBlk->HdrPadLen + LENGTH_AMSDU_SUBFRAMEHEAD; - } else { - /*hwHeaderLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */ - hwHeaderLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen; - } - NdisMoveMemory(pDMAHeaderBufVA, pTxBlk->HeaderBuf, - TXINFO_SIZE + TXWI_SIZE + hwHeaderLen); - - pTxRing->Cell[TxIdx].pNdisPacket = pTxBlk->pPacket; - pTxRing->Cell[TxIdx].pNextNdisPacket = NULL; - - /* */ - /* build Tx Descriptor */ - /* */ - - pTxD = (struct rt_txd *) pTxRing->Cell[TxIdx].AllocVa; - NdisZeroMemory(pTxD, TXD_SIZE); - - pTxD->SDPtr0 = BufBasePaLow; - pTxD->SDLen0 = TXINFO_SIZE + TXWI_SIZE + hwHeaderLen; /* include padding */ - pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE); - pTxD->SDLen1 = pTxBlk->SrcBufLen; - pTxD->LastSec0 = 0; - pTxD->LastSec1 = (bIsLast) ? 1 : 0; - - RTMPWriteTxDescriptor(pAd, pTxD, FALSE, FIFO_EDCA); - - RetTxIdx = TxIdx; - /* */ - /* Update Tx index */ - /* */ - INC_RING_INDEX(TxIdx, TX_RING_SIZE); - pTxRing->TxCpuIdx = TxIdx; - - *FreeNumber -= 1; - - return RetTxIdx; -} - -u16 RtmpPCI_WriteSingleTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - IN BOOLEAN bIsLast, - u16 * FreeNumber) -{ - - u8 *pDMAHeaderBufVA; - u16 TxIdx, RetTxIdx; - struct rt_txd * pTxD; - u32 BufBasePaLow; - struct rt_rtmp_tx_ring *pTxRing; - u16 hwHeaderLen; - - /* */ - /* get Tx Ring Resource */ - /* */ - pTxRing = &pAd->TxRing[pTxBlk->QueIdx]; - TxIdx = pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx; - pDMAHeaderBufVA = (u8 *)pTxRing->Cell[TxIdx].DmaBuf.AllocVa; - BufBasePaLow = - RTMP_GetPhysicalAddressLow(pTxRing->Cell[TxIdx].DmaBuf.AllocPa); - - /* copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer */ - /*hwHeaderLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */ - hwHeaderLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen; - - NdisMoveMemory(pDMAHeaderBufVA, pTxBlk->HeaderBuf, - TXINFO_SIZE + TXWI_SIZE + hwHeaderLen); - - pTxRing->Cell[TxIdx].pNdisPacket = pTxBlk->pPacket; - pTxRing->Cell[TxIdx].pNextNdisPacket = NULL; - - /* */ - /* build Tx Descriptor */ - /* */ - pTxD = (struct rt_txd *) pTxRing->Cell[TxIdx].AllocVa; - NdisZeroMemory(pTxD, TXD_SIZE); - - pTxD->SDPtr0 = BufBasePaLow; - pTxD->SDLen0 = TXINFO_SIZE + TXWI_SIZE + hwHeaderLen; /* include padding */ - pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE); - pTxD->SDLen1 = pTxBlk->SrcBufLen; - pTxD->LastSec0 = 0; - pTxD->LastSec1 = (bIsLast) ? 1 : 0; - - RTMPWriteTxDescriptor(pAd, pTxD, FALSE, FIFO_EDCA); - - RetTxIdx = TxIdx; - /* */ - /* Update Tx index */ - /* */ - INC_RING_INDEX(TxIdx, TX_RING_SIZE); - pTxRing->TxCpuIdx = TxIdx; - - *FreeNumber -= 1; - - return RetTxIdx; -} - -u16 RtmpPCI_WriteMultiTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u8 frameNum, u16 * FreeNumber) -{ - BOOLEAN bIsLast; - u8 *pDMAHeaderBufVA; - u16 TxIdx, RetTxIdx; - struct rt_txd * pTxD; - u32 BufBasePaLow; - struct rt_rtmp_tx_ring *pTxRing; - u16 hwHdrLen; - u32 firstDMALen; - - bIsLast = ((frameNum == (pTxBlk->TotalFrameNum - 1)) ? 1 : 0); - - /* */ - /* get Tx Ring Resource */ - /* */ - pTxRing = &pAd->TxRing[pTxBlk->QueIdx]; - TxIdx = pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx; - pDMAHeaderBufVA = (u8 *)pTxRing->Cell[TxIdx].DmaBuf.AllocVa; - BufBasePaLow = - RTMP_GetPhysicalAddressLow(pTxRing->Cell[TxIdx].DmaBuf.AllocPa); - - if (frameNum == 0) { - /* copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer */ - if (pTxBlk->TxFrameType == TX_AMSDU_FRAME) - /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_AMSDU_SUBFRAMEHEAD, 4)+LENGTH_AMSDU_SUBFRAMEHEAD; */ - hwHdrLen = - pTxBlk->MpduHeaderLen - LENGTH_AMSDU_SUBFRAMEHEAD + - pTxBlk->HdrPadLen + LENGTH_AMSDU_SUBFRAMEHEAD; - else if (pTxBlk->TxFrameType == TX_RALINK_FRAME) - /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_ARALINK_HEADER_FIELD, 4)+LENGTH_ARALINK_HEADER_FIELD; */ - hwHdrLen = - pTxBlk->MpduHeaderLen - - LENGTH_ARALINK_HEADER_FIELD + pTxBlk->HdrPadLen + - LENGTH_ARALINK_HEADER_FIELD; - else - /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */ - hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen; - - firstDMALen = TXINFO_SIZE + TXWI_SIZE + hwHdrLen; - } else { - firstDMALen = pTxBlk->MpduHeaderLen; - } - - NdisMoveMemory(pDMAHeaderBufVA, pTxBlk->HeaderBuf, firstDMALen); - - pTxRing->Cell[TxIdx].pNdisPacket = pTxBlk->pPacket; - pTxRing->Cell[TxIdx].pNextNdisPacket = NULL; - - /* */ - /* build Tx Descriptor */ - /* */ - pTxD = (struct rt_txd *) pTxRing->Cell[TxIdx].AllocVa; - NdisZeroMemory(pTxD, TXD_SIZE); - - pTxD->SDPtr0 = BufBasePaLow; - pTxD->SDLen0 = firstDMALen; /* include padding */ - pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE); - pTxD->SDLen1 = pTxBlk->SrcBufLen; - pTxD->LastSec0 = 0; - pTxD->LastSec1 = (bIsLast) ? 1 : 0; - - RTMPWriteTxDescriptor(pAd, pTxD, FALSE, FIFO_EDCA); - - RetTxIdx = TxIdx; - /* */ - /* Update Tx index */ - /* */ - INC_RING_INDEX(TxIdx, TX_RING_SIZE); - pTxRing->TxCpuIdx = TxIdx; - - *FreeNumber -= 1; - - return RetTxIdx; - -} - -void RtmpPCI_FinalWriteTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u16 totalMPDUSize, u16 FirstTxIdx) -{ - - struct rt_txwi * pTxWI; - struct rt_rtmp_tx_ring *pTxRing; - - /* */ - /* get Tx Ring Resource */ - /* */ - pTxRing = &pAd->TxRing[pTxBlk->QueIdx]; - pTxWI = (struct rt_txwi *) pTxRing->Cell[FirstTxIdx].DmaBuf.AllocVa; - pTxWI->MPDUtotalByteCount = totalMPDUSize; - -} - -void RtmpPCIDataLastTxIdx(struct rt_rtmp_adapter *pAd, - u8 QueIdx, u16 LastTxIdx) -{ - struct rt_txd * pTxD; - struct rt_rtmp_tx_ring *pTxRing; - - /* */ - /* get Tx Ring Resource */ - /* */ - pTxRing = &pAd->TxRing[QueIdx]; - - /* */ - /* build Tx Descriptor */ - /* */ - pTxD = (struct rt_txd *) pTxRing->Cell[LastTxIdx].AllocVa; - - pTxD->LastSec1 = 1; - -} - -u16 RtmpPCI_WriteFragTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u8 fragNum, u16 * FreeNumber) -{ - u8 *pDMAHeaderBufVA; - u16 TxIdx, RetTxIdx; - struct rt_txd * pTxD; - u32 BufBasePaLow; - struct rt_rtmp_tx_ring *pTxRing; - u16 hwHeaderLen; - u32 firstDMALen; - - /* */ - /* Get Tx Ring Resource */ - /* */ - pTxRing = &pAd->TxRing[pTxBlk->QueIdx]; - TxIdx = pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx; - pDMAHeaderBufVA = (u8 *)pTxRing->Cell[TxIdx].DmaBuf.AllocVa; - BufBasePaLow = - RTMP_GetPhysicalAddressLow(pTxRing->Cell[TxIdx].DmaBuf.AllocPa); - - /* */ - /* Copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer */ - /* */ - /*hwHeaderLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */ - hwHeaderLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen; - - firstDMALen = TXINFO_SIZE + TXWI_SIZE + hwHeaderLen; - NdisMoveMemory(pDMAHeaderBufVA, pTxBlk->HeaderBuf, firstDMALen); - - /* */ - /* Build Tx Descriptor */ - /* */ - pTxD = (struct rt_txd *) pTxRing->Cell[TxIdx].AllocVa; - NdisZeroMemory(pTxD, TXD_SIZE); - - if (fragNum == pTxBlk->TotalFragNum) { - pTxRing->Cell[TxIdx].pNdisPacket = pTxBlk->pPacket; - pTxRing->Cell[TxIdx].pNextNdisPacket = NULL; - } - - pTxD->SDPtr0 = BufBasePaLow; - pTxD->SDLen0 = firstDMALen; /* include padding */ - pTxD->SDPtr1 = PCI_MAP_SINGLE(pAd, pTxBlk, 0, 1, PCI_DMA_TODEVICE); - pTxD->SDLen1 = pTxBlk->SrcBufLen; - pTxD->LastSec0 = 0; - pTxD->LastSec1 = 1; - - RTMPWriteTxDescriptor(pAd, pTxD, FALSE, FIFO_EDCA); - - RetTxIdx = TxIdx; - pTxBlk->Priv += pTxBlk->SrcBufLen; - - /* */ - /* Update Tx index */ - /* */ - INC_RING_INDEX(TxIdx, TX_RING_SIZE); - pTxRing->TxCpuIdx = TxIdx; - - *FreeNumber -= 1; - - return RetTxIdx; - -} - -/* - Must be run in Interrupt context - This function handle PCI specific TxDesc and cpu index update and kick the packet out. - */ -int RtmpPCIMgmtKickOut(struct rt_rtmp_adapter *pAd, - u8 QueIdx, - void *pPacket, - u8 *pSrcBufVA, u32 SrcBufLen) -{ - struct rt_txd * pTxD; - unsigned long SwIdx = pAd->MgmtRing.TxCpuIdx; - - pTxD = (struct rt_txd *) pAd->MgmtRing.Cell[SwIdx].AllocVa; - - pAd->MgmtRing.Cell[SwIdx].pNdisPacket = pPacket; - pAd->MgmtRing.Cell[SwIdx].pNextNdisPacket = NULL; - - RTMPWriteTxDescriptor(pAd, pTxD, TRUE, FIFO_MGMT); - pTxD->LastSec0 = 1; - pTxD->LastSec1 = 1; - pTxD->DMADONE = 0; - pTxD->SDLen1 = 0; - pTxD->SDPtr0 = - PCI_MAP_SINGLE(pAd, pSrcBufVA, SrcBufLen, 0, PCI_DMA_TODEVICE); - pTxD->SDLen0 = SrcBufLen; - -/*================================================================== */ -/* DBGPRINT_RAW(RT_DEBUG_TRACE, ("MLMEHardTransmit\n")); - for (i = 0; i < (TXWI_SIZE+24); i++) - { - - DBGPRINT_RAW(RT_DEBUG_TRACE, ("%x:", *(pSrcBufVA+i))); - if ( i%4 == 3) - DBGPRINT_RAW(RT_DEBUG_TRACE, (" :: ")); - if ( i%16 == 15) - DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n ")); - } - DBGPRINT_RAW(RT_DEBUG_TRACE, ("\n "));*/ -/*======================================================================= */ - - pAd->RalinkCounters.KickTxCount++; - pAd->RalinkCounters.OneSecTxDoneCount++; - - /* Increase TX_CTX_IDX, but write to register later. */ - INC_RING_INDEX(pAd->MgmtRing.TxCpuIdx, MGMT_RING_SIZE); - - RTMP_IO_WRITE32(pAd, TX_MGMTCTX_IDX, pAd->MgmtRing.TxCpuIdx); - - return 0; -} - -/* - ======================================================================== - - Routine Description: - Check Rx descriptor, return NDIS_STATUS_FAILURE if any error dound - - Arguments: - pRxD Pointer to the Rx descriptor - - Return Value: - NDIS_STATUS_SUCCESS No err - NDIS_STATUS_FAILURE Error - - Note: - - ======================================================================== -*/ -int RTMPCheckRxError(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 * pHeader, - struct rt_rxwi * pRxWI, IN PRT28XX_RXD_STRUC pRxD) -{ - struct rt_cipher_key *pWpaKey; - int dBm; - - /* Phy errors & CRC errors */ - if ( /*(pRxD->PhyErr) || */ (pRxD->Crc)) { - /* Check RSSI for Noise Hist statistic collection. */ - dBm = (int)(pRxWI->RSSI0) - pAd->BbpRssiToDbmDelta; - if (dBm <= -87) - pAd->StaCfg.RPIDensity[0] += 1; - else if (dBm <= -82) - pAd->StaCfg.RPIDensity[1] += 1; - else if (dBm <= -77) - pAd->StaCfg.RPIDensity[2] += 1; - else if (dBm <= -72) - pAd->StaCfg.RPIDensity[3] += 1; - else if (dBm <= -67) - pAd->StaCfg.RPIDensity[4] += 1; - else if (dBm <= -62) - pAd->StaCfg.RPIDensity[5] += 1; - else if (dBm <= -57) - pAd->StaCfg.RPIDensity[6] += 1; - else if (dBm > -57) - pAd->StaCfg.RPIDensity[7] += 1; - - return (NDIS_STATUS_FAILURE); - } - /* Add Rx size to channel load counter, we should ignore error counts */ - pAd->StaCfg.CLBusyBytes += (pRxD->SDL0 + 14); - - /* Drop ToDs promiscuous frame, it is opened due to CCX 2 channel load statistics */ - if (pHeader != NULL) { - if (pHeader->FC.ToDs) { - return (NDIS_STATUS_FAILURE); - } - } - /* Drop not U2M frames, can't's drop here because we will drop beacon in this case */ - /* I am kind of doubting the U2M bit operation */ - /* if (pRxD->U2M == 0) */ - /* return(NDIS_STATUS_FAILURE); */ - - /* drop decyption fail frame */ - if (pRxD->CipherErr) { - if (pRxD->CipherErr == 2) { - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("pRxD ERROR: ICV ok but MICErr ")); - } else if (pRxD->CipherErr == 1) { - DBGPRINT_RAW(RT_DEBUG_TRACE, ("pRxD ERROR: ICV Err ")); - } else if (pRxD->CipherErr == 3) - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("pRxD ERROR: Key not valid ")); - - if (((pRxD->CipherErr & 1) == 1) - && pAd->CommonCfg.bWirelessEvent && INFRA_ON(pAd)) - RTMPSendWirelessEvent(pAd, IW_ICV_ERROR_EVENT_FLAG, - pAd->MacTab.Content[BSSID_WCID]. - Addr, BSS0, 0); - - DBGPRINT_RAW(RT_DEBUG_TRACE, - (" %d (len=%d, Mcast=%d, MyBss=%d, Wcid=%d, KeyId=%d)\n", - pRxD->CipherErr, pRxD->SDL0, - pRxD->Mcast | pRxD->Bcast, pRxD->MyBss, - pRxWI->WirelessCliID, -/* CipherName[pRxD->CipherAlg], */ - pRxWI->KeyIndex)); - - /* */ - /* MIC Error */ - /* */ - if (pRxD->CipherErr == 2) { - pWpaKey = &pAd->SharedKey[BSS0][pRxWI->KeyIndex]; - if (pAd->StaCfg.WpaSupplicantUP) - WpaSendMicFailureToWpaSupplicant(pAd, - (pWpaKey-> - Type == - PAIRWISEKEY) ? - TRUE : FALSE); - else - RTMPReportMicError(pAd, pWpaKey); - - if (((pRxD->CipherErr & 2) == 2) - && pAd->CommonCfg.bWirelessEvent && INFRA_ON(pAd)) - RTMPSendWirelessEvent(pAd, - IW_MIC_ERROR_EVENT_FLAG, - pAd->MacTab. - Content[BSSID_WCID].Addr, - BSS0, 0); - - DBGPRINT_RAW(RT_DEBUG_ERROR, ("Rx MIC Value error\n")); - } - - if (pHeader == NULL) - return (NDIS_STATUS_SUCCESS); - /*if ((pRxD->CipherAlg == CIPHER_AES) && - (pHeader->Sequence == pAd->FragFrame.Sequence)) - { - // - // Acceptable since the First FragFrame no CipherErr problem. - // - return(NDIS_STATUS_SUCCESS); - } */ - - return (NDIS_STATUS_FAILURE); - } - - return (NDIS_STATUS_SUCCESS); -} - -BOOLEAN RTMPFreeTXDUponTxDmaDone(struct rt_rtmp_adapter *pAd, u8 QueIdx) -{ - struct rt_rtmp_tx_ring *pTxRing; - struct rt_txd * pTxD; - void *pPacket; - u8 FREE = 0; - struct rt_txd TxD, *pOriTxD; - /*unsigned long IrqFlags; */ - BOOLEAN bReschedule = FALSE; - - ASSERT(QueIdx < NUM_OF_TX_RING); - pTxRing = &pAd->TxRing[QueIdx]; - - RTMP_IO_READ32(pAd, TX_DTX_IDX0 + QueIdx * RINGREG_DIFF, - &pTxRing->TxDmaIdx); - while (pTxRing->TxSwFreeIdx != pTxRing->TxDmaIdx) { -/* RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); */ - - /* static rate also need NICUpdateFifoStaCounters() function. */ - /*if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)) */ - NICUpdateFifoStaCounters(pAd); - - /* Note : If (pAd->ate.bQATxStart == TRUE), we will never reach here. */ - FREE++; - pTxD = - (struct rt_txd *) (pTxRing->Cell[pTxRing->TxSwFreeIdx].AllocVa); - pOriTxD = pTxD; - NdisMoveMemory(&TxD, pTxD, sizeof(struct rt_txd)); - pTxD = &TxD; - - pTxD->DMADONE = 0; - - { - pPacket = - pTxRing->Cell[pTxRing->TxSwFreeIdx].pNdisPacket; - if (pPacket) { - PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, - pTxD->SDLen1, - PCI_DMA_TODEVICE); - RELEASE_NDIS_PACKET(pAd, pPacket, - NDIS_STATUS_SUCCESS); - } - /*Always assign pNdisPacket as NULL after clear */ - pTxRing->Cell[pTxRing->TxSwFreeIdx].pNdisPacket = NULL; - - pPacket = - pTxRing->Cell[pTxRing->TxSwFreeIdx].pNextNdisPacket; - - ASSERT(pPacket == NULL); - if (pPacket) { - PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, - pTxD->SDLen1, - PCI_DMA_TODEVICE); - RELEASE_NDIS_PACKET(pAd, pPacket, - NDIS_STATUS_SUCCESS); - } - /*Always assign pNextNdisPacket as NULL after clear */ - pTxRing->Cell[pTxRing->TxSwFreeIdx].pNextNdisPacket = - NULL; - } - - pAd->RalinkCounters.TransmittedByteCount += - (pTxD->SDLen1 + pTxD->SDLen0); - pAd->RalinkCounters.OneSecDmaDoneCount[QueIdx]++; - INC_RING_INDEX(pTxRing->TxSwFreeIdx, TX_RING_SIZE); - /* get tx_tdx_idx again */ - RTMP_IO_READ32(pAd, TX_DTX_IDX0 + QueIdx * RINGREG_DIFF, - &pTxRing->TxDmaIdx); - NdisMoveMemory(pOriTxD, pTxD, sizeof(struct rt_txd)); - -/* RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); */ - } - - return bReschedule; - -} - -/* - ======================================================================== - - Routine Description: - Process TX Rings DMA Done interrupt, running in DPC level - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - ======================================================================== -*/ -BOOLEAN RTMPHandleTxRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd, - INT_SOURCE_CSR_STRUC TxRingBitmap) -{ -/* u8 Count = 0; */ - unsigned long IrqFlags; - BOOLEAN bReschedule = FALSE; - - /* Make sure Tx ring resource won't be used by other threads */ - /*NdisAcquireSpinLock(&pAd->TxRingLock); */ - - RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); - - if (TxRingBitmap.field.Ac0DmaDone) - bReschedule = RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_BE); - - if (TxRingBitmap.field.Ac3DmaDone) - bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_VO); - - if (TxRingBitmap.field.Ac2DmaDone) - bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_VI); - - if (TxRingBitmap.field.Ac1DmaDone) - bReschedule |= RTMPFreeTXDUponTxDmaDone(pAd, QID_AC_BK); - - /* Make sure to release Tx ring resource */ - /*NdisReleaseSpinLock(&pAd->TxRingLock); */ - RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); - - /* Dequeue outgoing frames from TxSwQueue[] and process it */ - RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); - - return bReschedule; -} - -/* - ======================================================================== - - Routine Description: - Process MGMT ring DMA done interrupt, running in DPC level - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPHandleMgmtRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd) -{ - struct rt_txd * pTxD; - void *pPacket; -/* int i; */ - u8 FREE = 0; - struct rt_rtmp_mgmt_ring *pMgmtRing = &pAd->MgmtRing; - - NdisAcquireSpinLock(&pAd->MgmtRingLock); - - RTMP_IO_READ32(pAd, TX_MGMTDTX_IDX, &pMgmtRing->TxDmaIdx); - while (pMgmtRing->TxSwFreeIdx != pMgmtRing->TxDmaIdx) { - FREE++; - pTxD = - (struct rt_txd *) (pMgmtRing->Cell[pAd->MgmtRing.TxSwFreeIdx]. - AllocVa); - pTxD->DMADONE = 0; - pPacket = pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNdisPacket; - - if (pPacket) { - PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, pTxD->SDLen0, - PCI_DMA_TODEVICE); - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); - } - pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNdisPacket = NULL; - - pPacket = - pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNextNdisPacket; - if (pPacket) { - PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, pTxD->SDLen1, - PCI_DMA_TODEVICE); - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_SUCCESS); - } - pMgmtRing->Cell[pMgmtRing->TxSwFreeIdx].pNextNdisPacket = NULL; - INC_RING_INDEX(pMgmtRing->TxSwFreeIdx, MGMT_RING_SIZE); - - } - NdisReleaseSpinLock(&pAd->MgmtRingLock); - -} - -/* - ======================================================================== - - Routine Description: - Arguments: - Adapter Pointer to our adapter. Dequeue all power safe delayed braodcast frames after beacon. - - IRQL = DISPATCH_LEVEL - - ======================================================================== -*/ -void RTMPHandleTBTTInterrupt(struct rt_rtmp_adapter *pAd) -{ - { - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) { - } - } -} - -/* - ======================================================================== - - Routine Description: - Arguments: - pAd Pointer to our adapter. Rewrite beacon content before next send-out. - - IRQL = DISPATCH_LEVEL - - ======================================================================== -*/ -void RTMPHandlePreTBTTInterrupt(struct rt_rtmp_adapter *pAd) -{ - { - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) { - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPHandlePreTBTTInterrupt...\n")); - } - } - -} - -void RTMPHandleRxCoherentInterrupt(struct rt_rtmp_adapter *pAd) -{ - WPDMA_GLO_CFG_STRUC GloCfg; - - if (pAd == NULL) { - DBGPRINT(RT_DEBUG_TRACE, ("====> pAd is NULL, return.\n")); - return; - } - - DBGPRINT(RT_DEBUG_TRACE, ("==> RTMPHandleRxCoherentInterrupt \n")); - - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); - - GloCfg.field.EnTXWriteBackDDONE = 0; - GloCfg.field.EnableRxDMA = 0; - GloCfg.field.EnableTxDMA = 0; - RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word); - - RTMPRingCleanUp(pAd, QID_AC_BE); - RTMPRingCleanUp(pAd, QID_AC_BK); - RTMPRingCleanUp(pAd, QID_AC_VI); - RTMPRingCleanUp(pAd, QID_AC_VO); - RTMPRingCleanUp(pAd, QID_MGMT); - RTMPRingCleanUp(pAd, QID_RX); - - RTMPEnableRxTx(pAd); - - DBGPRINT(RT_DEBUG_TRACE, ("<== RTMPHandleRxCoherentInterrupt \n")); -} - -void *GetPacketFromRxRing(struct rt_rtmp_adapter *pAd, - OUT PRT28XX_RXD_STRUC pSaveRxD, - OUT BOOLEAN * pbReschedule, - IN u32 * pRxPending) -{ - struct rt_rxd * pRxD; - void *pRxPacket = NULL; - void *pNewPacket; - void *AllocVa; - dma_addr_t AllocPa; - BOOLEAN bReschedule = FALSE; - struct rt_rtmp_dmacb *pRxCell; - - RTMP_SEM_LOCK(&pAd->RxRingLock); - - if (*pRxPending == 0) { - /* Get how may packets had been received */ - RTMP_IO_READ32(pAd, RX_DRX_IDX, &pAd->RxRing.RxDmaIdx); - - if (pAd->RxRing.RxSwReadIdx == pAd->RxRing.RxDmaIdx) { - /* no more rx packets */ - bReschedule = FALSE; - goto done; - } - /* get rx pending count */ - if (pAd->RxRing.RxDmaIdx > pAd->RxRing.RxSwReadIdx) - *pRxPending = - pAd->RxRing.RxDmaIdx - pAd->RxRing.RxSwReadIdx; - else - *pRxPending = - pAd->RxRing.RxDmaIdx + RX_RING_SIZE - - pAd->RxRing.RxSwReadIdx; - - } - - pRxCell = &pAd->RxRing.Cell[pAd->RxRing.RxSwReadIdx]; - - /* Point to Rx indexed rx ring descriptor */ - pRxD = (struct rt_rxd *) pRxCell->AllocVa; - - if (pRxD->DDONE == 0) { - *pRxPending = 0; - /* DMAIndx had done but DDONE bit not ready */ - bReschedule = TRUE; - goto done; - } - - /* return rx descriptor */ - NdisMoveMemory(pSaveRxD, pRxD, RXD_SIZE); - - pNewPacket = - RTMP_AllocateRxPacketBuffer(pAd, RX_BUFFER_AGGRESIZE, FALSE, - &AllocVa, &AllocPa); - - if (pNewPacket) { - /* unmap the rx buffer */ - PCI_UNMAP_SINGLE(pAd, pRxCell->DmaBuf.AllocPa, - pRxCell->DmaBuf.AllocSize, PCI_DMA_FROMDEVICE); - pRxPacket = pRxCell->pNdisPacket; - - pRxCell->DmaBuf.AllocSize = RX_BUFFER_AGGRESIZE; - pRxCell->pNdisPacket = (void *)pNewPacket; - pRxCell->DmaBuf.AllocVa = AllocVa; - pRxCell->DmaBuf.AllocPa = AllocPa; - /* update SDP0 to new buffer of rx packet */ - pRxD->SDP0 = AllocPa; - } else { - /*DBGPRINT(RT_DEBUG_TRACE,("No Rx Buffer\n")); */ - pRxPacket = NULL; - bReschedule = TRUE; - } - - pRxD->DDONE = 0; - - /* had handled one rx packet */ - *pRxPending = *pRxPending - 1; - - /* update rx descriptor and kick rx */ - INC_RING_INDEX(pAd->RxRing.RxSwReadIdx, RX_RING_SIZE); - - pAd->RxRing.RxCpuIdx = - (pAd->RxRing.RxSwReadIdx == - 0) ? (RX_RING_SIZE - 1) : (pAd->RxRing.RxSwReadIdx - 1); - RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RxCpuIdx); - -done: - RTMP_SEM_UNLOCK(&pAd->RxRingLock); - *pbReschedule = bReschedule; - return pRxPacket; -} - -int MlmeHardTransmitTxRing(struct rt_rtmp_adapter *pAd, - u8 QueIdx, void *pPacket) -{ - struct rt_packet_info PacketInfo; - u8 *pSrcBufVA; - u32 SrcBufLen; - struct rt_txd * pTxD; - struct rt_header_802_11 * pHeader_802_11; - BOOLEAN bAckRequired, bInsertTimestamp; - unsigned long SrcBufPA; - /*u8 TxBufIdx; */ - u8 MlmeRate; - unsigned long SwIdx = pAd->TxRing[QueIdx].TxCpuIdx; - struct rt_txwi * pFirstTxWI; - /*unsigned long i; */ - /*HTTRANSMIT_SETTING MlmeTransmit; //Rate for this MGMT frame. */ - unsigned long FreeNum; - struct rt_mac_table_entry *pMacEntry = NULL; - - RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen); - - if (pSrcBufVA == NULL) { - /* The buffer shouldn't be NULL */ - return NDIS_STATUS_FAILURE; - } - /* Make sure MGMT ring resource won't be used by other threads */ - /*NdisAcquireSpinLock(&pAd->TxRingLock); */ - - FreeNum = GET_TXRING_FREENO(pAd, QueIdx); - - if (FreeNum == 0) { - /*NdisReleaseSpinLock(&pAd->TxRingLock); */ - return NDIS_STATUS_FAILURE; - } - - SwIdx = pAd->TxRing[QueIdx].TxCpuIdx; - - pTxD = (struct rt_txd *) pAd->TxRing[QueIdx].Cell[SwIdx].AllocVa; - - if (pAd->TxRing[QueIdx].Cell[SwIdx].pNdisPacket) { - DBGPRINT(RT_DEBUG_OFF, ("MlmeHardTransmit Error\n")); - /*NdisReleaseSpinLock(&pAd->TxRingLock); */ - return NDIS_STATUS_FAILURE; - } - - { - /* outgoing frame always wakeup PHY to prevent frame lost */ - /* if (pAd->StaCfg.Psm == PWR_SAVE) */ - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) - AsicForceWakeup(pAd, TRUE); - } - pFirstTxWI = (struct rt_txwi *) pSrcBufVA; - - pHeader_802_11 = (struct rt_header_802_11 *) (pSrcBufVA + TXWI_SIZE); - if (pHeader_802_11->Addr1[0] & 0x01) { - MlmeRate = pAd->CommonCfg.BasicMlmeRate; - } else { - MlmeRate = pAd->CommonCfg.MlmeRate; - } - - if ((pHeader_802_11->FC.Type == BTYPE_DATA) && - (pHeader_802_11->FC.SubType == SUBTYPE_QOS_NULL)) { - pMacEntry = MacTableLookup(pAd, pHeader_802_11->Addr1); - } - /* Verify Mlme rate for a / g bands. */ - if ((pAd->LatchRfRegs.Channel > 14) && (MlmeRate < RATE_6)) /* 11A band */ - MlmeRate = RATE_6; - - /* */ - /* Should not be hard code to set PwrMgmt to 0 (PWR_ACTIVE) */ - /* Snice it's been set to 0 while on MgtMacHeaderInit */ - /* By the way this will cause frame to be send on PWR_SAVE failed. */ - /* */ - /* */ - /* In WMM-UAPSD, mlme frame should be set psm as power saving but probe request frame */ - /* Data-Null packets also pass through MMRequest in RT2860, however, we hope control the psm bit to pass APSD */ - if (pHeader_802_11->FC.Type != BTYPE_DATA) { - if ((pHeader_802_11->FC.SubType == SUBTYPE_PROBE_REQ) - || !(pAd->CommonCfg.bAPSDCapable - && pAd->CommonCfg.APEdcaParm.bAPSDCapable)) { - pHeader_802_11->FC.PwrMgmt = PWR_ACTIVE; - } else { - pHeader_802_11->FC.PwrMgmt = - pAd->CommonCfg.bAPSDForcePowerSave; - } - } - - bInsertTimestamp = FALSE; - if (pHeader_802_11->FC.Type == BTYPE_CNTL) /* must be PS-POLL */ - { - bAckRequired = FALSE; - } else /* BTYPE_MGMT or BTYPE_DATA(must be NULL frame) */ - { - if (pHeader_802_11->Addr1[0] & 0x01) /* MULTICAST, BROADCAST */ - { - bAckRequired = FALSE; - pHeader_802_11->Duration = 0; - } else { - bAckRequired = TRUE; - pHeader_802_11->Duration = - RTMPCalcDuration(pAd, MlmeRate, 14); - if (pHeader_802_11->FC.SubType == SUBTYPE_PROBE_RSP) { - bInsertTimestamp = TRUE; - } - } - } - pHeader_802_11->Sequence = pAd->Sequence++; - if (pAd->Sequence > 0xfff) - pAd->Sequence = 0; - /* Before radar detection done, mgmt frame can not be sent but probe req */ - /* Because we need to use probe req to trigger driver to send probe req in passive scan */ - if ((pHeader_802_11->FC.SubType != SUBTYPE_PROBE_REQ) - && (pAd->CommonCfg.bIEEE80211H == 1) - && (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE)) { - DBGPRINT(RT_DEBUG_ERROR, - ("MlmeHardTransmit --> radar detect not in normal mode!\n")); - /*NdisReleaseSpinLock(&pAd->TxRingLock); */ - return (NDIS_STATUS_FAILURE); - } - /* */ - /* fill scatter-and-gather buffer list into TXD. Internally created NDIS PACKET */ - /* should always has only one ohysical buffer, and the whole frame size equals */ - /* to the first scatter buffer size */ - /* */ - - /* Initialize TX Descriptor */ - /* For inter-frame gap, the number is for this frame and next frame */ - /* For MLME rate, we will fix as 2Mb to match other vendor's implement */ -/* pAd->CommonCfg.MlmeTransmit.field.MODE = 1; */ - -/* management frame doesn't need encryption. so use RESERVED_WCID no matter u are sending to specific wcid or not. */ - /* Only beacon use Nseq=TRUE. So here we use Nseq=FALSE. */ - if (pMacEntry == NULL) { - RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, bInsertTimestamp, - FALSE, bAckRequired, FALSE, 0, RESERVED_WCID, - (SrcBufLen - TXWI_SIZE), PID_MGMT, 0, - (u8)pAd->CommonCfg.MlmeTransmit.field.MCS, - IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit); - } else { - RTMPWriteTxWI(pAd, pFirstTxWI, FALSE, FALSE, - bInsertTimestamp, FALSE, bAckRequired, FALSE, - 0, pMacEntry->Aid, (SrcBufLen - TXWI_SIZE), - pMacEntry->MaxHTPhyMode.field.MCS, 0, - (u8)pMacEntry->MaxHTPhyMode.field.MCS, - IFS_BACKOFF, FALSE, &pMacEntry->MaxHTPhyMode); - } - - pAd->TxRing[QueIdx].Cell[SwIdx].pNdisPacket = pPacket; - pAd->TxRing[QueIdx].Cell[SwIdx].pNextNdisPacket = NULL; -/* pFirstTxWI->MPDUtotalByteCount = SrcBufLen - TXWI_SIZE; */ - SrcBufPA = - PCI_MAP_SINGLE(pAd, pSrcBufVA, SrcBufLen, 0, PCI_DMA_TODEVICE); - - RTMPWriteTxDescriptor(pAd, pTxD, TRUE, FIFO_EDCA); - pTxD->LastSec0 = 1; - pTxD->LastSec1 = 1; - pTxD->SDLen0 = SrcBufLen; - pTxD->SDLen1 = 0; - pTxD->SDPtr0 = SrcBufPA; - pTxD->DMADONE = 0; - - pAd->RalinkCounters.KickTxCount++; - pAd->RalinkCounters.OneSecTxDoneCount++; - - /* Increase TX_CTX_IDX, but write to register later. */ - INC_RING_INDEX(pAd->TxRing[QueIdx].TxCpuIdx, TX_RING_SIZE); - - RTMP_IO_WRITE32(pAd, TX_CTX_IDX0 + QueIdx * 0x10, - pAd->TxRing[QueIdx].TxCpuIdx); - - /* Make sure to release MGMT ring resource */ -/* NdisReleaseSpinLock(&pAd->TxRingLock); */ - - return NDIS_STATUS_SUCCESS; -} - -int MlmeDataHardTransmit(struct rt_rtmp_adapter *pAd, - u8 QueIdx, void *pPacket) -{ - if ((pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE) - ) { - return NDIS_STATUS_FAILURE; - } - - return MlmeHardTransmitTxRing(pAd, QueIdx, pPacket); -} - -/* - ======================================================================== - - Routine Description: - Calculates the duration which is required to transmit out frames - with given size and specified rate. - - Arguments: - pTxD Pointer to transmit descriptor - Ack Setting for Ack requirement bit - Fragment Setting for Fragment bit - RetryMode Setting for retry mode - Ifs Setting for IFS gap - Rate Setting for transmit rate - Service Setting for service - Length Frame length - TxPreamble Short or Long preamble when using CCK rates - QueIdx - 0-3, according to 802.11e/d4.4 June/2003 - - Return Value: - None - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ======================================================================== -*/ -void RTMPWriteTxDescriptor(struct rt_rtmp_adapter *pAd, - struct rt_txd * pTxD, - IN BOOLEAN bWIV, u8 QueueSEL) -{ - /* */ - /* Always use Long preamble before verifiation short preamble functionality works well. */ - /* Todo: remove the following line if short preamble functionality works */ - /* */ - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); - - pTxD->WIV = (bWIV) ? 1 : 0; - pTxD->QSEL = (QueueSEL); - /*RT2860c?? fixed using EDCA queue for test... We doubt Queue1 has problem. 2006-09-26 Jan */ - /*pTxD->QSEL= FIFO_EDCA; */ - pTxD->DMADONE = 0; -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_data_usb.c b/trunk/drivers/staging/rt2860/common/cmm_data_usb.c deleted file mode 100644 index 5637857ae9eb..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_data_usb.c +++ /dev/null @@ -1,951 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* -*/ - -/* - All functions in this file must be USB-depended, or you should out your function - in other files. - -*/ - -#ifdef RTMP_MAC_USB - -#include "../rt_config.h" - -/* - We can do copy the frame into pTxContext when match following conditions. - => - => - => -*/ -static inline int RtmpUSBCanDoWrite(struct rt_rtmp_adapter *pAd, - u8 QueIdx, - struct rt_ht_tx_context *pHTTXContext) -{ - int canWrite = NDIS_STATUS_RESOURCES; - - if (((pHTTXContext->CurWritePosition) < - pHTTXContext->NextBulkOutPosition) - && (pHTTXContext->CurWritePosition + LOCAL_TXBUF_SIZE) > - pHTTXContext->NextBulkOutPosition) { - DBGPRINT(RT_DEBUG_ERROR, ("RtmpUSBCanDoWrite c1!\n")); - RTUSB_SET_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx)); - } else if ((pHTTXContext->CurWritePosition == 8) - && (pHTTXContext->NextBulkOutPosition < LOCAL_TXBUF_SIZE)) { - DBGPRINT(RT_DEBUG_ERROR, ("RtmpUSBCanDoWrite c2!\n")); - RTUSB_SET_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx)); - } else if (pHTTXContext->bCurWriting == TRUE) { - DBGPRINT(RT_DEBUG_ERROR, ("RtmpUSBCanDoWrite c3!\n")); - } else { - canWrite = NDIS_STATUS_SUCCESS; - } - - return canWrite; -} - -u16 RtmpUSB_WriteSubTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - IN BOOLEAN bIsLast, u16 * FreeNumber) -{ - - /* Dummy function. Should be removed in the future. */ - return 0; - -} - -u16 RtmpUSB_WriteFragTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u8 fragNum, u16 * FreeNumber) -{ - struct rt_ht_tx_context *pHTTXContext; - u16 hwHdrLen; /* The hwHdrLen consist of 802.11 header length plus the header padding length. */ - u32 fillOffset; - struct rt_txinfo *pTxInfo; - struct rt_txwi *pTxWI; - u8 *pWirelessPacket = NULL; - u8 QueIdx; - int Status; - unsigned long IrqFlags; - u32 USBDMApktLen = 0, DMAHdrLen, padding; - BOOLEAN TxQLastRound = FALSE; - - /* */ - /* get Tx Ring Resource & Dma Buffer address */ - /* */ - QueIdx = pTxBlk->QueIdx; - pHTTXContext = &pAd->TxContext[QueIdx]; - - RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - - pHTTXContext = &pAd->TxContext[QueIdx]; - fillOffset = pHTTXContext->CurWritePosition; - - if (fragNum == 0) { - /* Check if we have enough space for this bulk-out batch. */ - Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext); - if (Status == NDIS_STATUS_SUCCESS) { - pHTTXContext->bCurWriting = TRUE; - - /* Reserve space for 8 bytes padding. */ - if ((pHTTXContext->ENextBulkOutPosition == - pHTTXContext->CurWritePosition)) { - pHTTXContext->ENextBulkOutPosition += 8; - pHTTXContext->CurWritePosition += 8; - fillOffset += 8; - } - pTxBlk->Priv = 0; - pHTTXContext->CurWriteRealPos = - pHTTXContext->CurWritePosition; - } else { - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], - IrqFlags); - - RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, - NDIS_STATUS_FAILURE); - return (Status); - } - } else { - /* For sub-sequent frames of this bulk-out batch. Just copy it to our bulk-out buffer. */ - Status = - ((pHTTXContext->bCurWriting == - TRUE) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE); - if (Status == NDIS_STATUS_SUCCESS) { - fillOffset += pTxBlk->Priv; - } else { - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], - IrqFlags); - - RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, - NDIS_STATUS_FAILURE); - return (Status); - } - } - - NdisZeroMemory((u8 *)(&pTxBlk->HeaderBuf[0]), TXINFO_SIZE); - pTxInfo = (struct rt_txinfo *)(&pTxBlk->HeaderBuf[0]); - pTxWI = (struct rt_txwi *) (&pTxBlk->HeaderBuf[TXINFO_SIZE]); - - pWirelessPacket = - &pHTTXContext->TransferBuffer->field.WirelessPacket[fillOffset]; - - /* copy TXWI + WLAN Header + LLC into DMA Header Buffer */ - /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */ - hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen; - - /* Build our URB for USBD */ - DMAHdrLen = TXWI_SIZE + hwHdrLen; - USBDMApktLen = DMAHdrLen + pTxBlk->SrcBufLen; - padding = (4 - (USBDMApktLen % 4)) & 0x03; /* round up to 4 byte alignment */ - USBDMApktLen += padding; - - pTxBlk->Priv += (TXINFO_SIZE + USBDMApktLen); - - /* For TxInfo, the length of USBDMApktLen = TXWI_SIZE + 802.11 header + payload */ - RTMPWriteTxInfo(pAd, pTxInfo, (u16)(USBDMApktLen), FALSE, FIFO_EDCA, - FALSE /*NextValid */ , FALSE); - - if (fragNum == pTxBlk->TotalFragNum) { - pTxInfo->USBDMATxburst = 0; - if ((pHTTXContext->CurWritePosition + pTxBlk->Priv + 3906) > - MAX_TXBULK_LIMIT) { - pTxInfo->SwUseLastRound = 1; - TxQLastRound = TRUE; - } - } else { - pTxInfo->USBDMATxburst = 1; - } - - NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, - TXINFO_SIZE + TXWI_SIZE + hwHdrLen); - pWirelessPacket += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen); - pHTTXContext->CurWriteRealPos += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen); - - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - - NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen); - - /* Zero the last padding. */ - pWirelessPacket += pTxBlk->SrcBufLen; - NdisZeroMemory(pWirelessPacket, padding + 8); - - if (fragNum == pTxBlk->TotalFragNum) { - RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - - /* Update the pHTTXContext->CurWritePosition. 3906 used to prevent the NextBulkOut is a A-RALINK/A-MSDU Frame. */ - pHTTXContext->CurWritePosition += pTxBlk->Priv; - if (TxQLastRound == TRUE) - pHTTXContext->CurWritePosition = 8; - pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition; - - /* Finally, set bCurWriting as FALSE */ - pHTTXContext->bCurWriting = FALSE; - - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - - /* succeed and release the skb buffer */ - RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS); - } - - return (Status); - -} - -u16 RtmpUSB_WriteSingleTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - IN BOOLEAN bIsLast, - u16 * FreeNumber) -{ - struct rt_ht_tx_context *pHTTXContext; - u16 hwHdrLen; - u32 fillOffset; - struct rt_txinfo *pTxInfo; - struct rt_txwi *pTxWI; - u8 *pWirelessPacket; - u8 QueIdx; - unsigned long IrqFlags; - int Status; - u32 USBDMApktLen = 0, DMAHdrLen, padding; - BOOLEAN bTxQLastRound = FALSE; - - /* For USB, didn't need PCI_MAP_SINGLE() */ - /*SrcBufPA = PCI_MAP_SINGLE(pAd, (char *) pTxBlk->pSrcBufData, pTxBlk->SrcBufLen, PCI_DMA_TODEVICE); */ - - /* */ - /* get Tx Ring Resource & Dma Buffer address */ - /* */ - QueIdx = pTxBlk->QueIdx; - - RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - pHTTXContext = &pAd->TxContext[QueIdx]; - fillOffset = pHTTXContext->CurWritePosition; - - /* Check ring full. */ - Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext); - if (Status == NDIS_STATUS_SUCCESS) { - pHTTXContext->bCurWriting = TRUE; - - pTxInfo = (struct rt_txinfo *)(&pTxBlk->HeaderBuf[0]); - pTxWI = (struct rt_txwi *) (&pTxBlk->HeaderBuf[TXINFO_SIZE]); - - /* Reserve space for 8 bytes padding. */ - if ((pHTTXContext->ENextBulkOutPosition == - pHTTXContext->CurWritePosition)) { - pHTTXContext->ENextBulkOutPosition += 8; - pHTTXContext->CurWritePosition += 8; - fillOffset += 8; - } - pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition; - - pWirelessPacket = - &pHTTXContext->TransferBuffer->field. - WirelessPacket[fillOffset]; - - /* copy TXWI + WLAN Header + LLC into DMA Header Buffer */ - /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */ - hwHdrLen = pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen; - - /* Build our URB for USBD */ - DMAHdrLen = TXWI_SIZE + hwHdrLen; - USBDMApktLen = DMAHdrLen + pTxBlk->SrcBufLen; - padding = (4 - (USBDMApktLen % 4)) & 0x03; /* round up to 4 byte alignment */ - USBDMApktLen += padding; - - pTxBlk->Priv = (TXINFO_SIZE + USBDMApktLen); - - /* For TxInfo, the length of USBDMApktLen = TXWI_SIZE + 802.11 header + payload */ - RTMPWriteTxInfo(pAd, pTxInfo, (u16)(USBDMApktLen), FALSE, - FIFO_EDCA, FALSE /*NextValid */ , FALSE); - - if ((pHTTXContext->CurWritePosition + 3906 + pTxBlk->Priv) > - MAX_TXBULK_LIMIT) { - pTxInfo->SwUseLastRound = 1; - bTxQLastRound = TRUE; - } - NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, - TXINFO_SIZE + TXWI_SIZE + hwHdrLen); - pWirelessPacket += (TXINFO_SIZE + TXWI_SIZE + hwHdrLen); - - /* We unlock it here to prevent the first 8 bytes maybe over-writed issue. */ - /* 1. First we got CurWritePosition but the first 8 bytes still not write to the pTxcontext. */ - /* 2. An interrupt break our routine and handle bulk-out complete. */ - /* 3. In the bulk-out compllete, it need to do another bulk-out, */ - /* if the ENextBulkOutPosition is just the same as CurWritePosition, it will save the first 8 bytes from CurWritePosition, */ - /* but the payload still not copyed. the pTxContext->SavedPad[] will save as allzero. and set the bCopyPad = TRUE. */ - /* 4. Interrupt complete. */ - /* 5. Our interrupted routine go back and fill the first 8 bytes to pTxContext. */ - /* 6. Next time when do bulk-out, it found the bCopyPad==TRUE and will copy the SavedPad[] to pTxContext->NextBulkOutPosition. */ - /* and the packet will wrong. */ - pHTTXContext->CurWriteRealPos += - (TXINFO_SIZE + TXWI_SIZE + hwHdrLen); - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - - NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, - pTxBlk->SrcBufLen); - pWirelessPacket += pTxBlk->SrcBufLen; - NdisZeroMemory(pWirelessPacket, padding + 8); - - RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - - pHTTXContext->CurWritePosition += pTxBlk->Priv; - if (bTxQLastRound) - pHTTXContext->CurWritePosition = 8; - pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition; - - pHTTXContext->bCurWriting = FALSE; - } - - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - - /* succeed and release the skb buffer */ - RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS); - - return (Status); - -} - -u16 RtmpUSB_WriteMultiTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u8 frameNum, u16 * FreeNumber) -{ - struct rt_ht_tx_context *pHTTXContext; - u16 hwHdrLen; /* The hwHdrLen consist of 802.11 header length plus the header padding length. */ - u32 fillOffset; - struct rt_txinfo *pTxInfo; - struct rt_txwi *pTxWI; - u8 *pWirelessPacket = NULL; - u8 QueIdx; - int Status; - unsigned long IrqFlags; - /*u32 USBDMApktLen = 0, DMAHdrLen, padding; */ - - /* */ - /* get Tx Ring Resource & Dma Buffer address */ - /* */ - QueIdx = pTxBlk->QueIdx; - pHTTXContext = &pAd->TxContext[QueIdx]; - - RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - - if (frameNum == 0) { - /* Check if we have enough space for this bulk-out batch. */ - Status = RtmpUSBCanDoWrite(pAd, QueIdx, pHTTXContext); - if (Status == NDIS_STATUS_SUCCESS) { - pHTTXContext->bCurWriting = TRUE; - - pTxInfo = (struct rt_txinfo *)(&pTxBlk->HeaderBuf[0]); - pTxWI = (struct rt_txwi *) (&pTxBlk->HeaderBuf[TXINFO_SIZE]); - - /* Reserve space for 8 bytes padding. */ - if ((pHTTXContext->ENextBulkOutPosition == - pHTTXContext->CurWritePosition)) { - - pHTTXContext->CurWritePosition += 8; - pHTTXContext->ENextBulkOutPosition += 8; - } - fillOffset = pHTTXContext->CurWritePosition; - pHTTXContext->CurWriteRealPos = - pHTTXContext->CurWritePosition; - - pWirelessPacket = - &pHTTXContext->TransferBuffer->field. - WirelessPacket[fillOffset]; - - /* */ - /* Copy TXINFO + TXWI + WLAN Header + LLC into DMA Header Buffer */ - /* */ - if (pTxBlk->TxFrameType == TX_AMSDU_FRAME) - /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_AMSDU_SUBFRAMEHEAD, 4)+LENGTH_AMSDU_SUBFRAMEHEAD; */ - hwHdrLen = - pTxBlk->MpduHeaderLen - - LENGTH_AMSDU_SUBFRAMEHEAD + - pTxBlk->HdrPadLen + - LENGTH_AMSDU_SUBFRAMEHEAD; - else if (pTxBlk->TxFrameType == TX_RALINK_FRAME) - /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen-LENGTH_ARALINK_HEADER_FIELD, 4)+LENGTH_ARALINK_HEADER_FIELD; */ - hwHdrLen = - pTxBlk->MpduHeaderLen - - LENGTH_ARALINK_HEADER_FIELD + - pTxBlk->HdrPadLen + - LENGTH_ARALINK_HEADER_FIELD; - else - /*hwHdrLen = ROUND_UP(pTxBlk->MpduHeaderLen, 4); */ - hwHdrLen = - pTxBlk->MpduHeaderLen + pTxBlk->HdrPadLen; - - /* Update the pTxBlk->Priv. */ - pTxBlk->Priv = TXINFO_SIZE + TXWI_SIZE + hwHdrLen; - - /* pTxInfo->USBDMApktLen now just a temp value and will to correct latter. */ - RTMPWriteTxInfo(pAd, pTxInfo, (u16)(pTxBlk->Priv), - FALSE, FIFO_EDCA, FALSE /*NextValid */ , - FALSE); - - /* Copy it. */ - NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, - pTxBlk->Priv); - pHTTXContext->CurWriteRealPos += pTxBlk->Priv; - pWirelessPacket += pTxBlk->Priv; - } - } else { /* For sub-sequent frames of this bulk-out batch. Just copy it to our bulk-out buffer. */ - - Status = - ((pHTTXContext->bCurWriting == - TRUE) ? NDIS_STATUS_SUCCESS : NDIS_STATUS_FAILURE); - if (Status == NDIS_STATUS_SUCCESS) { - fillOffset = - (pHTTXContext->CurWritePosition + pTxBlk->Priv); - pWirelessPacket = - &pHTTXContext->TransferBuffer->field. - WirelessPacket[fillOffset]; - - /*hwHdrLen = pTxBlk->MpduHeaderLen; */ - NdisMoveMemory(pWirelessPacket, pTxBlk->HeaderBuf, - pTxBlk->MpduHeaderLen); - pWirelessPacket += (pTxBlk->MpduHeaderLen); - pTxBlk->Priv += pTxBlk->MpduHeaderLen; - } else { /* It should not happened now unless we are going to shutdown. */ - DBGPRINT(RT_DEBUG_ERROR, - ("WriteMultiTxResource():bCurWriting is FALSE when handle sub-sequent frames.\n")); - Status = NDIS_STATUS_FAILURE; - } - } - - /* We unlock it here to prevent the first 8 bytes maybe over-write issue. */ - /* 1. First we got CurWritePosition but the first 8 bytes still not write to the pTxContext. */ - /* 2. An interrupt break our routine and handle bulk-out complete. */ - /* 3. In the bulk-out compllete, it need to do another bulk-out, */ - /* if the ENextBulkOutPosition is just the same as CurWritePosition, it will save the first 8 bytes from CurWritePosition, */ - /* but the payload still not copyed. the pTxContext->SavedPad[] will save as allzero. and set the bCopyPad = TRUE. */ - /* 4. Interrupt complete. */ - /* 5. Our interrupted routine go back and fill the first 8 bytes to pTxContext. */ - /* 6. Next time when do bulk-out, it found the bCopyPad==TRUE and will copy the SavedPad[] to pTxContext->NextBulkOutPosition. */ - /* and the packet will wrong. */ - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - - if (Status != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_ERROR, - ("WriteMultiTxResource: CWPos = %ld, NBOutPos = %ld.\n", - pHTTXContext->CurWritePosition, - pHTTXContext->NextBulkOutPosition)); - goto done; - } - /* Copy the frame content into DMA buffer and update the pTxBlk->Priv */ - NdisMoveMemory(pWirelessPacket, pTxBlk->pSrcBufData, pTxBlk->SrcBufLen); - pWirelessPacket += pTxBlk->SrcBufLen; - pTxBlk->Priv += pTxBlk->SrcBufLen; - -done: - /* Release the skb buffer here */ - RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_SUCCESS); - - return (Status); - -} - -void RtmpUSB_FinalWriteTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u16 totalMPDUSize, u16 TxIdx) -{ - u8 QueIdx; - struct rt_ht_tx_context *pHTTXContext; - u32 fillOffset; - struct rt_txinfo *pTxInfo; - struct rt_txwi *pTxWI; - u32 USBDMApktLen, padding; - unsigned long IrqFlags; - u8 *pWirelessPacket; - - QueIdx = pTxBlk->QueIdx; - pHTTXContext = &pAd->TxContext[QueIdx]; - - RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - - if (pHTTXContext->bCurWriting == TRUE) { - fillOffset = pHTTXContext->CurWritePosition; - if (((pHTTXContext->ENextBulkOutPosition == - pHTTXContext->CurWritePosition) - || ((pHTTXContext->ENextBulkOutPosition - 8) == - pHTTXContext->CurWritePosition)) - && (pHTTXContext->bCopySavePad == TRUE)) - pWirelessPacket = (u8 *)(&pHTTXContext->SavedPad[0]); - else - pWirelessPacket = - (u8 *)(&pHTTXContext->TransferBuffer->field. - WirelessPacket[fillOffset]); - - /* */ - /* Update TxInfo->USBDMApktLen , */ - /* the length = TXWI_SIZE + 802.11_hdr + 802.11_hdr_pad + payload_of_all_batch_frames + Bulk-Out-padding */ - /* */ - pTxInfo = (struct rt_txinfo *)(pWirelessPacket); - - /* Calculate the bulk-out padding */ - USBDMApktLen = pTxBlk->Priv - TXINFO_SIZE; - padding = (4 - (USBDMApktLen % 4)) & 0x03; /* round up to 4 byte alignment */ - USBDMApktLen += padding; - - pTxInfo->USBDMATxPktLen = USBDMApktLen; - - /* */ - /* Update TXWI->MPDUtotalByteCount , */ - /* the length = 802.11 header + payload_of_all_batch_frames */ - pTxWI = (struct rt_txwi *) (pWirelessPacket + TXINFO_SIZE); - pTxWI->MPDUtotalByteCount = totalMPDUSize; - - /* */ - /* Update the pHTTXContext->CurWritePosition */ - /* */ - pHTTXContext->CurWritePosition += (TXINFO_SIZE + USBDMApktLen); - if ((pHTTXContext->CurWritePosition + 3906) > MAX_TXBULK_LIMIT) { /* Add 3906 for prevent the NextBulkOut packet size is a A-RALINK/A-MSDU Frame. */ - pHTTXContext->CurWritePosition = 8; - pTxInfo->SwUseLastRound = 1; - } - pHTTXContext->CurWriteRealPos = pHTTXContext->CurWritePosition; - - /* */ - /* Zero the last padding. */ - /* */ - pWirelessPacket = - (&pHTTXContext->TransferBuffer->field. - WirelessPacket[fillOffset + pTxBlk->Priv]); - NdisZeroMemory(pWirelessPacket, padding + 8); - - /* Finally, set bCurWriting as FALSE */ - pHTTXContext->bCurWriting = FALSE; - - } else { /* It should not happened now unless we are going to shutdown. */ - DBGPRINT(RT_DEBUG_ERROR, - ("FinalWriteTxResource():bCurWriting is FALSE when handle last frames.\n")); - } - - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], IrqFlags); - -} - -void RtmpUSBDataLastTxIdx(struct rt_rtmp_adapter *pAd, - u8 QueIdx, u16 TxIdx) -{ - /* DO nothing for USB. */ -} - -/* - When can do bulk-out: - 1. TxSwFreeIdx < TX_RING_SIZE; - It means has at least one Ring entity is ready for bulk-out, kick it out. - 2. If TxSwFreeIdx == TX_RING_SIZE - Check if the CurWriting flag is FALSE, if it's FALSE, we can do kick out. - -*/ -void RtmpUSBDataKickOut(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, u8 QueIdx) -{ - RTUSB_SET_BULK_FLAG(pAd, (fRTUSB_BULK_OUT_DATA_NORMAL << QueIdx)); - RTUSBKickBulkOut(pAd); - -} - -/* - Must be run in Interrupt context - This function handle RT2870 specific TxDesc and cpu index update and kick the packet out. - */ -int RtmpUSBMgmtKickOut(struct rt_rtmp_adapter *pAd, - u8 QueIdx, - void *pPacket, - u8 *pSrcBufVA, u32 SrcBufLen) -{ - struct rt_txinfo *pTxInfo; - unsigned long BulkOutSize; - u8 padLen; - u8 *pDest; - unsigned long SwIdx = pAd->MgmtRing.TxCpuIdx; - struct rt_tx_context *pMLMEContext = - (struct rt_tx_context *)pAd->MgmtRing.Cell[SwIdx].AllocVa; - unsigned long IrqFlags; - - pTxInfo = (struct rt_txinfo *)(pSrcBufVA); - - /* Build our URB for USBD */ - BulkOutSize = SrcBufLen; - BulkOutSize = (BulkOutSize + 3) & (~3); - RTMPWriteTxInfo(pAd, pTxInfo, (u16)(BulkOutSize - TXINFO_SIZE), - TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE); - - BulkOutSize += 4; /* Always add 4 extra bytes at every packet. */ - - /* If BulkOutSize is multiple of BulkOutMaxPacketSize, add extra 4 bytes again. */ - if ((BulkOutSize % pAd->BulkOutMaxPacketSize) == 0) - BulkOutSize += 4; - - padLen = BulkOutSize - SrcBufLen; - ASSERT((padLen <= RTMP_PKT_TAIL_PADDING)); - - /* Now memzero all extra padding bytes. */ - pDest = (u8 *)(pSrcBufVA + SrcBufLen); - skb_put(GET_OS_PKT_TYPE(pPacket), padLen); - NdisZeroMemory(pDest, padLen); - - RTMP_IRQ_LOCK(&pAd->MLMEBulkOutLock, IrqFlags); - - pAd->MgmtRing.Cell[pAd->MgmtRing.TxCpuIdx].pNdisPacket = pPacket; - pMLMEContext->TransferBuffer = - (struct rt_tx_buffer *)(GET_OS_PKT_DATAPTR(pPacket)); - - /* Length in TxInfo should be 8 less than bulkout size. */ - pMLMEContext->BulkOutSize = BulkOutSize; - pMLMEContext->InUse = TRUE; - pMLMEContext->bWaitingBulkOut = TRUE; - - /*for debug */ - /*hex_dump("RtmpUSBMgmtKickOut", &pMLMEContext->TransferBuffer->field.WirelessPacket[0], (pMLMEContext->BulkOutSize > 16 ? 16 : pMLMEContext->BulkOutSize)); */ - - /*pAd->RalinkCounters.KickTxCount++; */ - /*pAd->RalinkCounters.OneSecTxDoneCount++; */ - - /*if (pAd->MgmtRing.TxSwFreeIdx == MGMT_RING_SIZE) */ - /* needKickOut = TRUE; */ - - /* Decrease the TxSwFreeIdx and Increase the TX_CTX_IDX */ - pAd->MgmtRing.TxSwFreeIdx--; - INC_RING_INDEX(pAd->MgmtRing.TxCpuIdx, MGMT_RING_SIZE); - - RTMP_IRQ_UNLOCK(&pAd->MLMEBulkOutLock, IrqFlags); - - RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME); - /*if (needKickOut) */ - RTUSBKickBulkOut(pAd); - - return 0; -} - -void RtmpUSBNullFrameKickOut(struct rt_rtmp_adapter *pAd, - u8 QueIdx, - u8 * pNullFrame, u32 frameLen) -{ - if (pAd->NullContext.InUse == FALSE) { - struct rt_tx_context *pNullContext; - struct rt_txinfo *pTxInfo; - struct rt_txwi * pTxWI; - u8 *pWirelessPkt; - - pNullContext = &(pAd->NullContext); - - /* Set the in use bit */ - pNullContext->InUse = TRUE; - pWirelessPkt = - (u8 *)& pNullContext->TransferBuffer->field. - WirelessPacket[0]; - - RTMPZeroMemory(&pWirelessPkt[0], 100); - pTxInfo = (struct rt_txinfo *)& pWirelessPkt[0]; - RTMPWriteTxInfo(pAd, pTxInfo, - (u16)(sizeof(struct rt_header_802_11) + TXWI_SIZE), - TRUE, EpToQueue[MGMTPIPEIDX], FALSE, FALSE); - pTxInfo->QSEL = FIFO_EDCA; - pTxWI = (struct rt_txwi *) & pWirelessPkt[TXINFO_SIZE]; - RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, - FALSE, 0, BSSID_WCID, (sizeof(struct rt_header_802_11)), 0, - 0, (u8)pAd->CommonCfg.MlmeTransmit.field.MCS, - IFS_HTTXOP, FALSE, &pAd->CommonCfg.MlmeTransmit); - - RTMPMoveMemory(&pWirelessPkt[TXWI_SIZE + TXINFO_SIZE], - &pAd->NullFrame, sizeof(struct rt_header_802_11)); - pAd->NullContext.BulkOutSize = - TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4; - - /* Fill out frame length information for global Bulk out arbitor */ - /*pNullContext->BulkOutSize = TransferBufferLength; */ - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - send NULL Frame @%d Mbps...\n", - RateIdToMbps[pAd->CommonCfg.TxRate])); - RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL); - - /* Kick bulk out */ - RTUSBKickBulkOut(pAd); - } - -} - -/* -======================================================================== -Routine Description: - Get a received packet. - -Arguments: - pAd device control block - pSaveRxD receive descriptor information - *pbReschedule need reschedule flag - *pRxPending pending received packet flag - -Return Value: - the received packet - -Note: -======================================================================== -*/ -void *GetPacketFromRxRing(struct rt_rtmp_adapter *pAd, - OUT PRT28XX_RXD_STRUC pSaveRxD, - OUT BOOLEAN * pbReschedule, - IN u32 * pRxPending) -{ - struct rt_rx_context *pRxContext; - void *pSkb; - u8 *pData; - unsigned long ThisFrameLen; - unsigned long RxBufferLength; - struct rt_rxwi * pRxWI; - - pRxContext = &pAd->RxContext[pAd->NextRxBulkInReadIndex]; - if ((pRxContext->Readable == FALSE) || (pRxContext->InUse == TRUE)) - return NULL; - - RxBufferLength = pRxContext->BulkInOffset - pAd->ReadPosition; - if (RxBufferLength < - (RT2870_RXDMALEN_FIELD_SIZE + sizeof(struct rt_rxwi) + - sizeof(struct rt_rxinfo))) { - goto label_null; - } - - pData = &pRxContext->TransferBuffer[pAd->ReadPosition]; /* 4KB */ - /* The RXDMA field is 4 bytes, now just use the first 2 bytes. The Length including the (RXWI + MSDU + Padding) */ - ThisFrameLen = *pData + (*(pData + 1) << 8); - if (ThisFrameLen == 0) { - DBGPRINT(RT_DEBUG_TRACE, - ("BIRIdx(%d): RXDMALen is zero.[%ld], BulkInBufLen = %ld)\n", - pAd->NextRxBulkInReadIndex, ThisFrameLen, - pRxContext->BulkInOffset)); - goto label_null; - } - if ((ThisFrameLen & 0x3) != 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("BIRIdx(%d): RXDMALen not multiple of 4.[%ld], BulkInBufLen = %ld)\n", - pAd->NextRxBulkInReadIndex, ThisFrameLen, - pRxContext->BulkInOffset)); - goto label_null; - } - - if ((ThisFrameLen + 8) > RxBufferLength) /* 8 for (RT2870_RXDMALEN_FIELD_SIZE + sizeof(struct rt_rxinfo)) */ - { - DBGPRINT(RT_DEBUG_TRACE, - ("BIRIdx(%d):FrameLen(0x%lx) outranges. BulkInLen=0x%lx, remaining RxBufLen=0x%lx, ReadPos=0x%lx\n", - pAd->NextRxBulkInReadIndex, ThisFrameLen, - pRxContext->BulkInOffset, RxBufferLength, - pAd->ReadPosition)); - - /* error frame. finish this loop */ - goto label_null; - } - /* skip USB frame length field */ - pData += RT2870_RXDMALEN_FIELD_SIZE; - pRxWI = (struct rt_rxwi *) pData; - if (pRxWI->MPDUtotalByteCount > ThisFrameLen) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s():pRxWIMPDUtotalByteCount(%d) large than RxDMALen(%ld)\n", - __FUNCTION__, pRxWI->MPDUtotalByteCount, - ThisFrameLen)); - goto label_null; - } - /* allocate a rx packet */ - pSkb = dev_alloc_skb(ThisFrameLen); - if (pSkb == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s():Cannot Allocate sk buffer for this Bulk-In buffer!\n", - __FUNCTION__)); - goto label_null; - } - /* copy the rx packet */ - memcpy(skb_put(pSkb, ThisFrameLen), pData, ThisFrameLen); - RTPKT_TO_OSPKT(pSkb)->dev = get_netdev_from_bssid(pAd, BSS0); - RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pSkb), PKTSRC_NDIS); - - /* copy RxD */ - *pSaveRxD = *(struct rt_rxinfo *) (pData + ThisFrameLen); - - /* update next packet read position. */ - pAd->ReadPosition += (ThisFrameLen + RT2870_RXDMALEN_FIELD_SIZE + RXINFO_SIZE); /* 8 for (RT2870_RXDMALEN_FIELD_SIZE + sizeof(struct rt_rxinfo)) */ - - return pSkb; - -label_null: - - return NULL; -} - -/* - ======================================================================== - - Routine Description: - Check Rx descriptor, return NDIS_STATUS_FAILURE if any error dound - - Arguments: - pRxD Pointer to the Rx descriptor - - Return Value: - NDIS_STATUS_SUCCESS No err - NDIS_STATUS_FAILURE Error - - Note: - - ======================================================================== -*/ -int RTMPCheckRxError(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 * pHeader, - struct rt_rxwi * pRxWI, IN PRT28XX_RXD_STRUC pRxINFO) -{ - struct rt_cipher_key *pWpaKey; - int dBm; - - if (pAd->bPromiscuous == TRUE) - return (NDIS_STATUS_SUCCESS); - if (pRxINFO == NULL) - return (NDIS_STATUS_FAILURE); - - /* Phy errors & CRC errors */ - if (pRxINFO->Crc) { - /* Check RSSI for Noise Hist statistic collection. */ - dBm = (int)(pRxWI->RSSI0) - pAd->BbpRssiToDbmDelta; - if (dBm <= -87) - pAd->StaCfg.RPIDensity[0] += 1; - else if (dBm <= -82) - pAd->StaCfg.RPIDensity[1] += 1; - else if (dBm <= -77) - pAd->StaCfg.RPIDensity[2] += 1; - else if (dBm <= -72) - pAd->StaCfg.RPIDensity[3] += 1; - else if (dBm <= -67) - pAd->StaCfg.RPIDensity[4] += 1; - else if (dBm <= -62) - pAd->StaCfg.RPIDensity[5] += 1; - else if (dBm <= -57) - pAd->StaCfg.RPIDensity[6] += 1; - else if (dBm > -57) - pAd->StaCfg.RPIDensity[7] += 1; - - return (NDIS_STATUS_FAILURE); - } - /* Add Rx size to channel load counter, we should ignore error counts */ - pAd->StaCfg.CLBusyBytes += (pRxWI->MPDUtotalByteCount + 14); - - /* Drop ToDs promiscuous frame, it is opened due to CCX 2 channel load statistics */ - if (pHeader->FC.ToDs) { - DBGPRINT_RAW(RT_DEBUG_ERROR, ("Err;FC.ToDs\n")); - return NDIS_STATUS_FAILURE; - } - /* Paul 04-03 for OFDM Rx length issue */ - if (pRxWI->MPDUtotalByteCount > MAX_AGGREGATION_SIZE) { - DBGPRINT_RAW(RT_DEBUG_ERROR, ("received packet too long\n")); - return NDIS_STATUS_FAILURE; - } - /* Drop not U2M frames, can't's drop here because we will drop beacon in this case */ - /* I am kind of doubting the U2M bit operation */ - /* if (pRxD->U2M == 0) */ - /* return(NDIS_STATUS_FAILURE); */ - - /* drop decyption fail frame */ - if (pRxINFO->Decrypted && pRxINFO->CipherErr) { - - if (((pRxINFO->CipherErr & 1) == 1) - && pAd->CommonCfg.bWirelessEvent && INFRA_ON(pAd)) - RTMPSendWirelessEvent(pAd, IW_ICV_ERROR_EVENT_FLAG, - pAd->MacTab.Content[BSSID_WCID]. - Addr, BSS0, 0); - - if (((pRxINFO->CipherErr & 2) == 2) - && pAd->CommonCfg.bWirelessEvent && INFRA_ON(pAd)) - RTMPSendWirelessEvent(pAd, IW_MIC_ERROR_EVENT_FLAG, - pAd->MacTab.Content[BSSID_WCID]. - Addr, BSS0, 0); - /* */ - /* MIC Error */ - /* */ - if ((pRxINFO->CipherErr == 2) && pRxINFO->MyBss) { - pWpaKey = &pAd->SharedKey[BSS0][pRxWI->KeyIndex]; - RTMPReportMicError(pAd, pWpaKey); - DBGPRINT_RAW(RT_DEBUG_ERROR, ("Rx MIC Value error\n")); - } - - if (pRxINFO->Decrypted && - (pAd->SharedKey[BSS0][pRxWI->KeyIndex].CipherAlg == - CIPHER_AES) - && (pHeader->Sequence == pAd->FragFrame.Sequence)) { - /* */ - /* Acceptable since the First FragFrame no CipherErr problem. */ - /* */ - return (NDIS_STATUS_SUCCESS); - } - - return (NDIS_STATUS_FAILURE); - } - - return (NDIS_STATUS_SUCCESS); -} - -void RtmpUsbStaAsicForceWakeupTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, - void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - - if (pAd && pAd->Mlme.AutoWakeupTimerRunning) { - AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x02); - - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE); - pAd->Mlme.AutoWakeupTimerRunning = FALSE; - } -} - -void RT28xxUsbStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx) -{ - BOOLEAN Canceled; - - if (pAd->Mlme.AutoWakeupTimerRunning) - RTMPCancelTimer(&pAd->Mlme.AutoWakeupTimer, &Canceled); - - AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x02); - - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE); -} - -void RT28xxUsbStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd, - u16 TbttNumToNextWakeUp) -{ - - /* we have decided to SLEEP, so at least do it for a BEACON period. */ - if (TbttNumToNextWakeUp == 0) - TbttNumToNextWakeUp = 1; - - RTMPSetTimer(&pAd->Mlme.AutoWakeupTimer, AUTO_WAKEUP_TIMEOUT); - pAd->Mlme.AutoWakeupTimerRunning = TRUE; - - AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02); /* send POWER-SAVE command to MCU. Timeout 40us. */ - - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_DOZE); - -} - -#endif /* RTMP_MAC_USB // */ diff --git a/trunk/drivers/staging/rt2860/common/cmm_info.c b/trunk/drivers/staging/rt2860/common/cmm_info.c deleted file mode 100644 index 25302e8363b9..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_info.c +++ /dev/null @@ -1,955 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - */ - -#include -#include "../rt_config.h" - -/* - ======================================================================== - - Routine Description: - Remove WPA Key process - - Arguments: - pAd Pointer to our adapter - pBuf Pointer to the where the key stored - - Return Value: - NDIS_SUCCESS Add key successfully - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPSetDesiredRates(struct rt_rtmp_adapter *pAdapter, long Rates) -{ - NDIS_802_11_RATES aryRates; - - memset(&aryRates, 0x00, sizeof(NDIS_802_11_RATES)); - switch (pAdapter->CommonCfg.PhyMode) { - case PHY_11A: /* A only */ - switch (Rates) { - case 6000000: /*6M */ - aryRates[0] = 0x0c; /* 6M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_0; - break; - case 9000000: /*9M */ - aryRates[0] = 0x12; /* 9M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_1; - break; - case 12000000: /*12M */ - aryRates[0] = 0x18; /* 12M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_2; - break; - case 18000000: /*18M */ - aryRates[0] = 0x24; /* 18M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_3; - break; - case 24000000: /*24M */ - aryRates[0] = 0x30; /* 24M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_4; - break; - case 36000000: /*36M */ - aryRates[0] = 0x48; /* 36M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_5; - break; - case 48000000: /*48M */ - aryRates[0] = 0x60; /* 48M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_6; - break; - case 54000000: /*54M */ - aryRates[0] = 0x6c; /* 54M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_7; - break; - case -1: /*Auto */ - default: - aryRates[0] = 0x6c; /* 54Mbps */ - aryRates[1] = 0x60; /* 48Mbps */ - aryRates[2] = 0x48; /* 36Mbps */ - aryRates[3] = 0x30; /* 24Mbps */ - aryRates[4] = 0x24; /* 18M */ - aryRates[5] = 0x18; /* 12M */ - aryRates[6] = 0x12; /* 9M */ - aryRates[7] = 0x0c; /* 6M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_AUTO; - break; - } - break; - case PHY_11BG_MIXED: /* B/G Mixed */ - case PHY_11B: /* B only */ - case PHY_11ABG_MIXED: /* A/B/G Mixed */ - default: - switch (Rates) { - case 1000000: /*1M */ - aryRates[0] = 0x02; - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_0; - break; - case 2000000: /*2M */ - aryRates[0] = 0x04; - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_1; - break; - case 5000000: /*5.5M */ - aryRates[0] = 0x0b; /* 5.5M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_2; - break; - case 11000000: /*11M */ - aryRates[0] = 0x16; /* 11M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_3; - break; - case 6000000: /*6M */ - aryRates[0] = 0x0c; /* 6M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_0; - break; - case 9000000: /*9M */ - aryRates[0] = 0x12; /* 9M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_1; - break; - case 12000000: /*12M */ - aryRates[0] = 0x18; /* 12M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_2; - break; - case 18000000: /*18M */ - aryRates[0] = 0x24; /* 18M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_3; - break; - case 24000000: /*24M */ - aryRates[0] = 0x30; /* 24M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_4; - break; - case 36000000: /*36M */ - aryRates[0] = 0x48; /* 36M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_5; - break; - case 48000000: /*48M */ - aryRates[0] = 0x60; /* 48M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_6; - break; - case 54000000: /*54M */ - aryRates[0] = 0x6c; /* 54M */ - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_7; - break; - case -1: /*Auto */ - default: - if (pAdapter->CommonCfg.PhyMode == PHY_11B) { /*B Only */ - aryRates[0] = 0x16; /* 11Mbps */ - aryRates[1] = 0x0b; /* 5.5Mbps */ - aryRates[2] = 0x04; /* 2Mbps */ - aryRates[3] = 0x02; /* 1Mbps */ - } else { /*(B/G) Mixed or (A/B/G) Mixed */ - aryRates[0] = 0x6c; /* 54Mbps */ - aryRates[1] = 0x60; /* 48Mbps */ - aryRates[2] = 0x48; /* 36Mbps */ - aryRates[3] = 0x30; /* 24Mbps */ - aryRates[4] = 0x16; /* 11Mbps */ - aryRates[5] = 0x0b; /* 5.5Mbps */ - aryRates[6] = 0x04; /* 2Mbps */ - aryRates[7] = 0x02; /* 1Mbps */ - } - pAdapter->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_AUTO; - break; - } - break; - } - - NdisZeroMemory(pAdapter->CommonCfg.DesireRate, - MAX_LEN_OF_SUPPORTED_RATES); - NdisMoveMemory(pAdapter->CommonCfg.DesireRate, &aryRates, - sizeof(NDIS_802_11_RATES)); - DBGPRINT(RT_DEBUG_TRACE, - (" RTMPSetDesiredRates (%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x)\n", - pAdapter->CommonCfg.DesireRate[0], - pAdapter->CommonCfg.DesireRate[1], - pAdapter->CommonCfg.DesireRate[2], - pAdapter->CommonCfg.DesireRate[3], - pAdapter->CommonCfg.DesireRate[4], - pAdapter->CommonCfg.DesireRate[5], - pAdapter->CommonCfg.DesireRate[6], - pAdapter->CommonCfg.DesireRate[7])); - /* Changing DesiredRate may affect the MAX TX rate we used to TX frames out */ - MlmeUpdateTxRates(pAdapter, FALSE, 0); -} - -/* - ======================================================================== - - Routine Description: - Remove All WPA Keys - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPWPARemoveAllKeys(struct rt_rtmp_adapter *pAd) -{ - - u8 i; - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPWPARemoveAllKeys(AuthMode=%d, WepStatus=%d)\n", - pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus)); - RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP); - /* For WEP/CKIP, there is no need to remove it, since WinXP won't set it again after */ - /* Link up. And it will be replaced if user changed it. */ - if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA) - return; - - /* For WPA-None, there is no need to remove it, since WinXP won't set it again after */ - /* Link up. And it will be replaced if user changed it. */ - if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) - return; - - /* set BSSID wcid entry of the Pair-wise Key table as no-security mode */ - AsicRemovePairwiseKeyEntry(pAd, BSS0, BSSID_WCID); - - /* set all shared key mode as no-security. */ - for (i = 0; i < SHARE_KEY_NUM; i++) { - DBGPRINT(RT_DEBUG_TRACE, - ("remove %s key #%d\n", - CipherName[pAd->SharedKey[BSS0][i].CipherAlg], i)); - NdisZeroMemory(&pAd->SharedKey[BSS0][i], sizeof(struct rt_cipher_key)); - - AsicRemoveSharedKeyEntry(pAd, BSS0, i); - } - RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP); -} - -/* - ======================================================================== - - Routine Description: - As STA's BSSID is a WC too, it uses shared key table. - This function write correct unicast TX key to ASIC WCID. - And we still make a copy in our MacTab.Content[BSSID_WCID].PairwiseKey. - Caller guarantee TKIP/AES always has keyidx = 0. (pairwise key) - Caller guarantee WEP calls this function when set Txkey, default key index=0~3. - - Arguments: - pAd Pointer to our adapter - pKey Pointer to the where the key stored - - Return Value: - NDIS_SUCCESS Add key successfully - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -/* - ======================================================================== - Routine Description: - Change NIC PHY mode. Re-association may be necessary. possible settings - include - PHY_11B, PHY_11BG_MIXED, PHY_11A, and PHY_11ABG_MIXED - - Arguments: - pAd - Pointer to our adapter - phymode - - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ======================================================================== -*/ -void RTMPSetPhyMode(struct rt_rtmp_adapter *pAd, unsigned long phymode) -{ - int i; - /* the selected phymode must be supported by the RF IC encoded in E2PROM */ - - /* if no change, do nothing */ - /* bug fix - if (pAd->CommonCfg.PhyMode == phymode) - return; - */ - pAd->CommonCfg.PhyMode = (u8)phymode; - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPSetPhyMode : PhyMode=%d, channel=%d \n", - pAd->CommonCfg.PhyMode, pAd->CommonCfg.Channel)); - - BuildChannelList(pAd); - - /* sanity check user setting */ - for (i = 0; i < pAd->ChannelListNum; i++) { - if (pAd->CommonCfg.Channel == pAd->ChannelList[i].Channel) - break; - } - - if (i == pAd->ChannelListNum) { - pAd->CommonCfg.Channel = FirstChannel(pAd); - DBGPRINT(RT_DEBUG_ERROR, - ("RTMPSetPhyMode: channel is out of range, use first channel=%d \n", - pAd->CommonCfg.Channel)); - } - - NdisZeroMemory(pAd->CommonCfg.SupRate, MAX_LEN_OF_SUPPORTED_RATES); - NdisZeroMemory(pAd->CommonCfg.ExtRate, MAX_LEN_OF_SUPPORTED_RATES); - NdisZeroMemory(pAd->CommonCfg.DesireRate, MAX_LEN_OF_SUPPORTED_RATES); - switch (phymode) { - case PHY_11B: - pAd->CommonCfg.SupRate[0] = 0x82; /* 1 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRate[1] = 0x84; /* 2 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRate[2] = 0x8B; /* 5.5 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRate[3] = 0x96; /* 11 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRateLen = 4; - pAd->CommonCfg.ExtRateLen = 0; - pAd->CommonCfg.DesireRate[0] = 2; /* 1 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[1] = 4; /* 2 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[2] = 11; /* 5.5 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[3] = 22; /* 11 mbps, in units of 0.5 Mbps */ - /*pAd->CommonCfg.HTPhyMode.field.MODE = MODE_CCK; // This MODE is only FYI. not use */ - break; - - case PHY_11G: - case PHY_11BG_MIXED: - case PHY_11ABG_MIXED: - case PHY_11N_2_4G: - case PHY_11ABGN_MIXED: - case PHY_11BGN_MIXED: - case PHY_11GN_MIXED: - pAd->CommonCfg.SupRate[0] = 0x82; /* 1 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRate[1] = 0x84; /* 2 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRate[2] = 0x8B; /* 5.5 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRate[3] = 0x96; /* 11 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRate[4] = 0x12; /* 9 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.SupRate[5] = 0x24; /* 18 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.SupRate[6] = 0x48; /* 36 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.SupRate[7] = 0x6c; /* 54 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.SupRateLen = 8; - pAd->CommonCfg.ExtRate[0] = 0x0C; /* 6 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.ExtRate[1] = 0x18; /* 12 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.ExtRate[2] = 0x30; /* 24 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.ExtRate[3] = 0x60; /* 48 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.ExtRateLen = 4; - pAd->CommonCfg.DesireRate[0] = 2; /* 1 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[1] = 4; /* 2 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[2] = 11; /* 5.5 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[3] = 22; /* 11 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[4] = 12; /* 6 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[5] = 18; /* 9 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[6] = 24; /* 12 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[7] = 36; /* 18 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[8] = 48; /* 24 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[9] = 72; /* 36 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[10] = 96; /* 48 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[11] = 108; /* 54 mbps, in units of 0.5 Mbps */ - break; - - case PHY_11A: - case PHY_11AN_MIXED: - case PHY_11AGN_MIXED: - case PHY_11N_5G: - pAd->CommonCfg.SupRate[0] = 0x8C; /* 6 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRate[1] = 0x12; /* 9 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.SupRate[2] = 0x98; /* 12 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRate[3] = 0x24; /* 18 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.SupRate[4] = 0xb0; /* 24 mbps, in units of 0.5 Mbps, basic rate */ - pAd->CommonCfg.SupRate[5] = 0x48; /* 36 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.SupRate[6] = 0x60; /* 48 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.SupRate[7] = 0x6c; /* 54 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.SupRateLen = 8; - pAd->CommonCfg.ExtRateLen = 0; - pAd->CommonCfg.DesireRate[0] = 12; /* 6 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[1] = 18; /* 9 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[2] = 24; /* 12 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[3] = 36; /* 18 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[4] = 48; /* 24 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[5] = 72; /* 36 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[6] = 96; /* 48 mbps, in units of 0.5 Mbps */ - pAd->CommonCfg.DesireRate[7] = 108; /* 54 mbps, in units of 0.5 Mbps */ - /*pAd->CommonCfg.HTPhyMode.field.MODE = MODE_OFDM; // This MODE is only FYI. not use */ - break; - - default: - break; - } - - pAd->CommonCfg.BandState = UNKNOWN_BAND; -} - -/* - ======================================================================== - Routine Description: - Caller ensures we has 802.11n support. - Calls at setting HT from AP/STASetinformation - - Arguments: - pAd - Pointer to our adapter - phymode - - - ======================================================================== -*/ -void RTMPSetHT(struct rt_rtmp_adapter *pAd, struct rt_oid_set_ht_phymode *pHTPhyMode) -{ - /*unsigned long *pmcs; */ - u32 Value = 0; - u8 BBPValue = 0; - u8 BBP3Value = 0; - u8 RxStream = pAd->CommonCfg.RxStream; - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPSetHT : HT_mode(%d), ExtOffset(%d), MCS(%d), BW(%d), STBC(%d), SHORTGI(%d)\n", - pHTPhyMode->HtMode, pHTPhyMode->ExtOffset, pHTPhyMode->MCS, - pHTPhyMode->BW, pHTPhyMode->STBC, pHTPhyMode->SHORTGI)); - - /* Don't zero supportedHyPhy structure. */ - RTMPZeroMemory(&pAd->CommonCfg.HtCapability, - sizeof(pAd->CommonCfg.HtCapability)); - RTMPZeroMemory(&pAd->CommonCfg.AddHTInfo, - sizeof(pAd->CommonCfg.AddHTInfo)); - RTMPZeroMemory(&pAd->CommonCfg.NewExtChanOffset, - sizeof(pAd->CommonCfg.NewExtChanOffset)); - RTMPZeroMemory(&pAd->CommonCfg.DesiredHtPhy, - sizeof(pAd->CommonCfg.DesiredHtPhy)); - - if (pAd->CommonCfg.bRdg) { - pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 1; - pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 1; - } else { - pAd->CommonCfg.HtCapability.ExtHtCapInfo.PlusHTC = 0; - pAd->CommonCfg.HtCapability.ExtHtCapInfo.RDGSupport = 0; - } - - pAd->CommonCfg.HtCapability.HtCapParm.MaxRAmpduFactor = 3; - pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor = 3; - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPSetHT : RxBAWinLimit = %d\n", - pAd->CommonCfg.BACapability.field.RxBAWinLimit)); - - /* Mimo power save, A-MSDU size, */ - pAd->CommonCfg.DesiredHtPhy.AmsduEnable = - (u16)pAd->CommonCfg.BACapability.field.AmsduEnable; - pAd->CommonCfg.DesiredHtPhy.AmsduSize = - (u8)pAd->CommonCfg.BACapability.field.AmsduSize; - pAd->CommonCfg.DesiredHtPhy.MimoPs = - (u8)pAd->CommonCfg.BACapability.field.MMPSmode; - pAd->CommonCfg.DesiredHtPhy.MpduDensity = - (u8)pAd->CommonCfg.BACapability.field.MpduDensity; - - pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = - (u16)pAd->CommonCfg.BACapability.field.AmsduSize; - pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = - (u16)pAd->CommonCfg.BACapability.field.MMPSmode; - pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = - (u8)pAd->CommonCfg.BACapability.field.MpduDensity; - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPSetHT : AMsduSize = %d, MimoPs = %d, MpduDensity = %d, MaxRAmpduFactor = %d\n", - pAd->CommonCfg.DesiredHtPhy.AmsduSize, - pAd->CommonCfg.DesiredHtPhy.MimoPs, - pAd->CommonCfg.DesiredHtPhy.MpduDensity, - pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor)); - - if (pHTPhyMode->HtMode == HTMODE_GF) { - pAd->CommonCfg.HtCapability.HtCapInfo.GF = 1; - pAd->CommonCfg.DesiredHtPhy.GF = 1; - } else - pAd->CommonCfg.DesiredHtPhy.GF = 0; - - /* Decide Rx MCSSet */ - switch (RxStream) { - case 1: - pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff; - pAd->CommonCfg.HtCapability.MCSSet[1] = 0x00; - break; - - case 2: - pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff; - pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff; - break; - - case 3: /* 3*3 */ - pAd->CommonCfg.HtCapability.MCSSet[0] = 0xff; - pAd->CommonCfg.HtCapability.MCSSet[1] = 0xff; - pAd->CommonCfg.HtCapability.MCSSet[2] = 0xff; - break; - } - - if (pAd->CommonCfg.bForty_Mhz_Intolerant - && (pAd->CommonCfg.Channel <= 14) && (pHTPhyMode->BW == BW_40)) { - pHTPhyMode->BW = BW_20; - pAd->CommonCfg.HtCapability.HtCapInfo.Forty_Mhz_Intolerant = 1; - } - - if (pHTPhyMode->BW == BW_40) { - pAd->CommonCfg.HtCapability.MCSSet[4] = 0x1; /* MCS 32 */ - pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 1; - if (pAd->CommonCfg.Channel <= 14) - pAd->CommonCfg.HtCapability.HtCapInfo.CCKmodein40 = 1; - - pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 1; - pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 1; - pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = - (pHTPhyMode->ExtOffset == - EXTCHA_BELOW) ? (EXTCHA_BELOW) : EXTCHA_ABOVE; - /* Set Regsiter for extension channel position. */ - RTMP_IO_READ32(pAd, TX_BAND_CFG, &Value); - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBP3Value); - if ((pHTPhyMode->ExtOffset == EXTCHA_BELOW)) { - Value |= 0x1; - BBP3Value |= (0x20); - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value); - } else if ((pHTPhyMode->ExtOffset == EXTCHA_ABOVE)) { - Value &= 0xfe; - BBP3Value &= (~0x20); - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Value); - } - /* Turn on BBP 40MHz mode now only as AP . */ - /* Sta can turn on BBP 40MHz after connection with 40MHz AP. Sta only broadcast 40MHz capability before connection. */ - if ((pAd->OpMode == OPMODE_AP) || INFRA_ON(pAd) || ADHOC_ON(pAd) - ) { - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); - BBPValue &= (~0x18); - BBPValue |= 0x10; - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); - - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBP3Value); - pAd->CommonCfg.BBPCurrentBW = BW_40; - } - } else { - pAd->CommonCfg.HtCapability.HtCapInfo.ChannelWidth = 0; - pAd->CommonCfg.DesiredHtPhy.ChannelWidth = 0; - pAd->CommonCfg.AddHTInfo.AddHtInfo.RecomWidth = 0; - pAd->CommonCfg.AddHTInfo.AddHtInfo.ExtChanOffset = EXTCHA_NONE; - pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel; - /* Turn on BBP 20MHz mode by request here. */ - { - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); - BBPValue &= (~0x18); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); - pAd->CommonCfg.BBPCurrentBW = BW_20; - } - } - - if (pHTPhyMode->STBC == STBC_USE) { - pAd->CommonCfg.HtCapability.HtCapInfo.TxSTBC = 1; - pAd->CommonCfg.DesiredHtPhy.TxSTBC = 1; - pAd->CommonCfg.HtCapability.HtCapInfo.RxSTBC = 1; - pAd->CommonCfg.DesiredHtPhy.RxSTBC = 1; - } else { - pAd->CommonCfg.DesiredHtPhy.TxSTBC = 0; - pAd->CommonCfg.DesiredHtPhy.RxSTBC = 0; - } - - if (pHTPhyMode->SHORTGI == GI_400) { - pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 1; - pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 1; - pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 1; - pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 1; - } else { - pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor20 = 0; - pAd->CommonCfg.HtCapability.HtCapInfo.ShortGIfor40 = 0; - pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 = 0; - pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 = 0; - } - - /* We support link adaptation for unsolicit MCS feedback, set to 2. */ - pAd->CommonCfg.HtCapability.ExtHtCapInfo.MCSFeedback = MCSFBK_NONE; /*MCSFBK_UNSOLICIT; */ - pAd->CommonCfg.AddHTInfo.ControlChan = pAd->CommonCfg.Channel; - /* 1, the extension channel above the control channel. */ - - /* EDCA parameters used for AP's own transmission */ - if (pAd->CommonCfg.APEdcaParm.bValid == FALSE) { - pAd->CommonCfg.APEdcaParm.bValid = TRUE; - pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3; - pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7; - pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1; - pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1; - - pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4; - pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4; - pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3; - pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2; - - pAd->CommonCfg.APEdcaParm.Cwmax[0] = 6; - pAd->CommonCfg.APEdcaParm.Cwmax[1] = 10; - pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4; - pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3; - - pAd->CommonCfg.APEdcaParm.Txop[0] = 0; - pAd->CommonCfg.APEdcaParm.Txop[1] = 0; - pAd->CommonCfg.APEdcaParm.Txop[2] = 94; - pAd->CommonCfg.APEdcaParm.Txop[3] = 47; - } - AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm); - - { - RTMPSetIndividualHT(pAd, 0); - } - -} - -/* - ======================================================================== - Routine Description: - Caller ensures we has 802.11n support. - Calls at setting HT from AP/STASetinformation - - Arguments: - pAd - Pointer to our adapter - phymode - - - ======================================================================== -*/ -void RTMPSetIndividualHT(struct rt_rtmp_adapter *pAd, u8 apidx) -{ - struct rt_ht_phy_info *pDesired_ht_phy = NULL; - u8 TxStream = pAd->CommonCfg.TxStream; - u8 DesiredMcs = MCS_AUTO; - - do { - { - pDesired_ht_phy = &pAd->StaCfg.DesiredHtPhyInfo; - DesiredMcs = - pAd->StaCfg.DesiredTransmitSetting.field.MCS; - /*pAd->StaCfg.bAutoTxRateSwitch = (DesiredMcs == MCS_AUTO) ? TRUE : FALSE; */ - break; - } - } while (FALSE); - - if (pDesired_ht_phy == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("RTMPSetIndividualHT: invalid apidx(%d)\n", apidx)); - return; - } - RTMPZeroMemory(pDesired_ht_phy, sizeof(struct rt_ht_phy_info)); - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPSetIndividualHT : Desired MCS = %d\n", DesiredMcs)); - /* Check the validity of MCS */ - if ((TxStream == 1) - && ((DesiredMcs >= MCS_8) && (DesiredMcs <= MCS_15))) { - DBGPRINT(RT_DEBUG_WARN, - ("RTMPSetIndividualHT: MCS(%d) is invalid in 1S, reset it as MCS_7\n", - DesiredMcs)); - DesiredMcs = MCS_7; - } - - if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_20) - && (DesiredMcs == MCS_32)) { - DBGPRINT(RT_DEBUG_WARN, - ("RTMPSetIndividualHT: MCS_32 is only supported in 40-MHz, reset it as MCS_0\n")); - DesiredMcs = MCS_0; - } - - pDesired_ht_phy->bHtEnable = TRUE; - - /* Decide desired Tx MCS */ - switch (TxStream) { - case 1: - if (DesiredMcs == MCS_AUTO) { - pDesired_ht_phy->MCSSet[0] = 0xff; - pDesired_ht_phy->MCSSet[1] = 0x00; - } else if (DesiredMcs <= MCS_7) { - pDesired_ht_phy->MCSSet[0] = 1 << DesiredMcs; - pDesired_ht_phy->MCSSet[1] = 0x00; - } - break; - - case 2: - if (DesiredMcs == MCS_AUTO) { - pDesired_ht_phy->MCSSet[0] = 0xff; - pDesired_ht_phy->MCSSet[1] = 0xff; - } else if (DesiredMcs <= MCS_15) { - unsigned long mode; - - mode = DesiredMcs / 8; - if (mode < 2) - pDesired_ht_phy->MCSSet[mode] = - (1 << (DesiredMcs - mode * 8)); - } - break; - - case 3: /* 3*3 */ - if (DesiredMcs == MCS_AUTO) { - /* MCS0 ~ MCS23, 3 bytes */ - pDesired_ht_phy->MCSSet[0] = 0xff; - pDesired_ht_phy->MCSSet[1] = 0xff; - pDesired_ht_phy->MCSSet[2] = 0xff; - } else if (DesiredMcs <= MCS_23) { - unsigned long mode; - - mode = DesiredMcs / 8; - if (mode < 3) - pDesired_ht_phy->MCSSet[mode] = - (1 << (DesiredMcs - mode * 8)); - } - break; - } - - if (pAd->CommonCfg.DesiredHtPhy.ChannelWidth == BW_40) { - if (DesiredMcs == MCS_AUTO || DesiredMcs == MCS_32) - pDesired_ht_phy->MCSSet[4] = 0x1; - } - /* update HT Rate setting */ - if (pAd->OpMode == OPMODE_STA) - MlmeUpdateHtTxRates(pAd, BSS0); - else - MlmeUpdateHtTxRates(pAd, apidx); -} - -/* - ======================================================================== - Routine Description: - Update HT IE from our capability. - - Arguments: - Send all HT IE in beacon/probe rsp/assoc rsp/action frame. - - ======================================================================== -*/ -void RTMPUpdateHTIE(struct rt_ht_capability *pRtHt, - u8 * pMcsSet, - struct rt_ht_capability_ie * pHtCapability, - struct rt_add_ht_info_ie * pAddHtInfo) -{ - RTMPZeroMemory(pHtCapability, sizeof(struct rt_ht_capability_ie)); - RTMPZeroMemory(pAddHtInfo, sizeof(struct rt_add_ht_info_ie)); - - pHtCapability->HtCapInfo.ChannelWidth = pRtHt->ChannelWidth; - pHtCapability->HtCapInfo.MimoPs = pRtHt->MimoPs; - pHtCapability->HtCapInfo.GF = pRtHt->GF; - pHtCapability->HtCapInfo.ShortGIfor20 = pRtHt->ShortGIfor20; - pHtCapability->HtCapInfo.ShortGIfor40 = pRtHt->ShortGIfor40; - pHtCapability->HtCapInfo.TxSTBC = pRtHt->TxSTBC; - pHtCapability->HtCapInfo.RxSTBC = pRtHt->RxSTBC; - pHtCapability->HtCapInfo.AMsduSize = pRtHt->AmsduSize; - pHtCapability->HtCapParm.MaxRAmpduFactor = pRtHt->MaxRAmpduFactor; - pHtCapability->HtCapParm.MpduDensity = pRtHt->MpduDensity; - - pAddHtInfo->AddHtInfo.ExtChanOffset = pRtHt->ExtChanOffset; - pAddHtInfo->AddHtInfo.RecomWidth = pRtHt->RecomWidth; - pAddHtInfo->AddHtInfo2.OperaionMode = pRtHt->OperaionMode; - pAddHtInfo->AddHtInfo2.NonGfPresent = pRtHt->NonGfPresent; - RTMPMoveMemory(pAddHtInfo->MCSSet, /*pRtHt->MCSSet */ pMcsSet, 4); /* rt2860 only support MCS max=32, no need to copy all 16 uchar. */ - - DBGPRINT(RT_DEBUG_TRACE, ("RTMPUpdateHTIE <== \n")); -} - -/* - ======================================================================== - Description: - Add Client security information into ASIC WCID table and IVEIV table. - Return: - ======================================================================== -*/ -void RTMPAddWcidAttributeEntry(struct rt_rtmp_adapter *pAd, - u8 BssIdx, - u8 KeyIdx, - u8 CipherAlg, struct rt_mac_table_entry *pEntry) -{ - u32 WCIDAttri = 0; - u16 offset; - u8 IVEIV = 0; - u16 Wcid = 0; - - { - { - if (BssIdx > BSS0) { - DBGPRINT(RT_DEBUG_ERROR, - ("RTMPAddWcidAttributeEntry: The BSS-index(%d) is out of range for Infra link. \n", - BssIdx)); - return; - } - /* 1. In ADHOC mode, the AID is wcid number. And NO mesh link exists. */ - /* 2. In Infra mode, the AID:1 MUST be wcid of infra STA. */ - /* the AID:2~ assign to mesh link entry. */ - if (pEntry) - Wcid = pEntry->Aid; - else - Wcid = MCAST_WCID; - } - } - - /* Update WCID attribute table */ - offset = MAC_WCID_ATTRIBUTE_BASE + (Wcid * HW_WCID_ATTRI_SIZE); - - { - if (pEntry && pEntry->ValidAsMesh) - WCIDAttri = (CipherAlg << 1) | PAIRWISEKEYTABLE; - else - WCIDAttri = (CipherAlg << 1) | SHAREDKEYTABLE; - } - - RTMP_IO_WRITE32(pAd, offset, WCIDAttri); - - /* Update IV/EIV table */ - offset = MAC_IVEIV_TABLE_BASE + (Wcid * HW_IVEIV_ENTRY_SIZE); - - /* WPA mode */ - if ((CipherAlg == CIPHER_TKIP) || (CipherAlg == CIPHER_TKIP_NO_MIC) - || (CipherAlg == CIPHER_AES)) { - /* Eiv bit on. keyid always is 0 for pairwise key */ - IVEIV = (KeyIdx << 6) | 0x20; - } else { - /* WEP KeyIdx is default tx key. */ - IVEIV = (KeyIdx << 6); - } - - /* For key index and ext IV bit, so only need to update the position(offset+3). */ -#ifdef RTMP_MAC_PCI - RTMP_IO_WRITE8(pAd, offset + 3, IVEIV); -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - RTUSBMultiWrite_OneByte(pAd, offset + 3, &IVEIV); -#endif /* RTMP_MAC_USB // */ - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPAddWcidAttributeEntry: WCID #%d, KeyIndex #%d, Alg=%s\n", - Wcid, KeyIdx, CipherName[CipherAlg])); - DBGPRINT(RT_DEBUG_TRACE, (" WCIDAttri = 0x%x \n", WCIDAttri)); - -} - -/* - ========================================================================== - Description: - Parse encryption type -Arguments: - pAdapter Pointer to our adapter - wrq Pointer to the ioctl argument - - Return Value: - None - - Note: - ========================================================================== -*/ -char *GetEncryptType(char enc) -{ - if (enc == Ndis802_11WEPDisabled) - return "NONE"; - if (enc == Ndis802_11WEPEnabled) - return "WEP"; - if (enc == Ndis802_11Encryption2Enabled) - return "TKIP"; - if (enc == Ndis802_11Encryption3Enabled) - return "AES"; - if (enc == Ndis802_11Encryption4Enabled) - return "TKIPAES"; - else - return "UNKNOW"; -} - -char *GetAuthMode(char auth) -{ - if (auth == Ndis802_11AuthModeOpen) - return "OPEN"; - if (auth == Ndis802_11AuthModeShared) - return "SHARED"; - if (auth == Ndis802_11AuthModeAutoSwitch) - return "AUTOWEP"; - if (auth == Ndis802_11AuthModeWPA) - return "WPA"; - if (auth == Ndis802_11AuthModeWPAPSK) - return "WPAPSK"; - if (auth == Ndis802_11AuthModeWPANone) - return "WPANONE"; - if (auth == Ndis802_11AuthModeWPA2) - return "WPA2"; - if (auth == Ndis802_11AuthModeWPA2PSK) - return "WPA2PSK"; - if (auth == Ndis802_11AuthModeWPA1WPA2) - return "WPA1WPA2"; - if (auth == Ndis802_11AuthModeWPA1PSKWPA2PSK) - return "WPA1PSKWPA2PSK"; - - return "UNKNOW"; -} - -int SetCommonHT(struct rt_rtmp_adapter *pAd) -{ - struct rt_oid_set_ht_phymode SetHT; - - if (pAd->CommonCfg.PhyMode < PHY_11ABGN_MIXED) - return FALSE; - - SetHT.PhyMode = pAd->CommonCfg.PhyMode; - SetHT.TransmitNo = ((u8)pAd->Antenna.field.TxPath); - SetHT.HtMode = (u8)pAd->CommonCfg.RegTransmitSetting.field.HTMODE; - SetHT.ExtOffset = - (u8)pAd->CommonCfg.RegTransmitSetting.field.EXTCHA; - SetHT.MCS = MCS_AUTO; - SetHT.BW = (u8)pAd->CommonCfg.RegTransmitSetting.field.BW; - SetHT.STBC = (u8)pAd->CommonCfg.RegTransmitSetting.field.STBC; - SetHT.SHORTGI = (u8)pAd->CommonCfg.RegTransmitSetting.field.ShortGI; - - RTMPSetHT(pAd, &SetHT); - - return TRUE; -} - -char *RTMPGetRalinkEncryModeStr(u16 encryMode) -{ - switch (encryMode) { - case Ndis802_11WEPDisabled: - return "NONE"; - case Ndis802_11WEPEnabled: - return "WEP"; - case Ndis802_11Encryption2Enabled: - return "TKIP"; - case Ndis802_11Encryption3Enabled: - return "AES"; - case Ndis802_11Encryption4Enabled: - return "TKIPAES"; - default: - return "UNKNOW"; - } -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_mac_pci.c b/trunk/drivers/staging/rt2860/common/cmm_mac_pci.c deleted file mode 100644 index d06f0a6dc379..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_mac_pci.c +++ /dev/null @@ -1,1661 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* -*/ - -#ifdef RTMP_MAC_PCI -#include "../rt_config.h" - -/* - ======================================================================== - - Routine Description: - Allocate DMA memory blocks for send, receive - - Arguments: - Adapter Pointer to our adapter - - Return Value: - NDIS_STATUS_SUCCESS - NDIS_STATUS_FAILURE - NDIS_STATUS_RESOURCES - - IRQL = PASSIVE_LEVEL - - Note: - - ======================================================================== -*/ -int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd) -{ - int Status = NDIS_STATUS_SUCCESS; - unsigned long RingBasePaHigh; - unsigned long RingBasePaLow; - void *RingBaseVa; - int index, num; - struct rt_txd * pTxD; - struct rt_rxd * pRxD; - unsigned long ErrorValue = 0; - struct rt_rtmp_tx_ring *pTxRing; - struct rt_rtmp_dmabuf *pDmaBuf; - void *pPacket; -/* PRTMP_REORDERBUF pReorderBuf; */ - - DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocTxRxRingMemory\n")); - do { - /* */ - /* Allocate all ring descriptors, include TxD, RxD, MgmtD. */ - /* Although each size is different, to prevent cacheline and alignment */ - /* issue, I intentional set them all to 64 bytes. */ - /* */ - for (num = 0; num < NUM_OF_TX_RING; num++) { - unsigned long BufBasePaHigh; - unsigned long BufBasePaLow; - void *BufBaseVa; - - /* */ - /* Allocate Tx ring descriptor's memory (5 TX rings = 4 ACs + 1 HCCA) */ - /* */ - pAd->TxDescRing[num].AllocSize = - TX_RING_SIZE * TXD_SIZE; - RTMP_AllocateTxDescMemory(pAd, num, - pAd->TxDescRing[num]. - AllocSize, FALSE, - &pAd->TxDescRing[num].AllocVa, - &pAd->TxDescRing[num]. - AllocPa); - - if (pAd->TxDescRing[num].AllocVa == NULL) { - ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; - DBGPRINT_ERR("Failed to allocate a big buffer\n"); - Status = NDIS_STATUS_RESOURCES; - break; - } - /* Zero init this memory block */ - NdisZeroMemory(pAd->TxDescRing[num].AllocVa, - pAd->TxDescRing[num].AllocSize); - - /* Save PA & VA for further operation */ - RingBasePaHigh = - RTMP_GetPhysicalAddressHigh(pAd->TxDescRing[num]. - AllocPa); - RingBasePaLow = - RTMP_GetPhysicalAddressLow(pAd->TxDescRing[num]. - AllocPa); - RingBaseVa = pAd->TxDescRing[num].AllocVa; - - /* */ - /* Allocate all 1st TXBuf's memory for this TxRing */ - /* */ - pAd->TxBufSpace[num].AllocSize = - TX_RING_SIZE * TX_DMA_1ST_BUFFER_SIZE; - RTMP_AllocateFirstTxBuffer(pAd, num, - pAd->TxBufSpace[num]. - AllocSize, FALSE, - &pAd->TxBufSpace[num]. - AllocVa, - &pAd->TxBufSpace[num]. - AllocPa); - - if (pAd->TxBufSpace[num].AllocVa == NULL) { - ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; - DBGPRINT_ERR("Failed to allocate a big buffer\n"); - Status = NDIS_STATUS_RESOURCES; - break; - } - /* Zero init this memory block */ - NdisZeroMemory(pAd->TxBufSpace[num].AllocVa, - pAd->TxBufSpace[num].AllocSize); - - /* Save PA & VA for further operation */ - BufBasePaHigh = - RTMP_GetPhysicalAddressHigh(pAd->TxBufSpace[num]. - AllocPa); - BufBasePaLow = - RTMP_GetPhysicalAddressLow(pAd->TxBufSpace[num]. - AllocPa); - BufBaseVa = pAd->TxBufSpace[num].AllocVa; - - /* */ - /* Initialize Tx Ring Descriptor and associated buffer memory */ - /* */ - pTxRing = &pAd->TxRing[num]; - for (index = 0; index < TX_RING_SIZE; index++) { - pTxRing->Cell[index].pNdisPacket = NULL; - pTxRing->Cell[index].pNextNdisPacket = NULL; - /* Init Tx Ring Size, Va, Pa variables */ - pTxRing->Cell[index].AllocSize = TXD_SIZE; - pTxRing->Cell[index].AllocVa = RingBaseVa; - RTMP_SetPhysicalAddressHigh(pTxRing-> - Cell[index].AllocPa, - RingBasePaHigh); - RTMP_SetPhysicalAddressLow(pTxRing->Cell[index]. - AllocPa, - RingBasePaLow); - - /* Setup Tx Buffer size & address. only 802.11 header will store in this space */ - pDmaBuf = &pTxRing->Cell[index].DmaBuf; - pDmaBuf->AllocSize = TX_DMA_1ST_BUFFER_SIZE; - pDmaBuf->AllocVa = BufBaseVa; - RTMP_SetPhysicalAddressHigh(pDmaBuf->AllocPa, - BufBasePaHigh); - RTMP_SetPhysicalAddressLow(pDmaBuf->AllocPa, - BufBasePaLow); - - /* link the pre-allocated TxBuf to TXD */ - pTxD = - (struct rt_txd *) pTxRing->Cell[index].AllocVa; - pTxD->SDPtr0 = BufBasePaLow; - /* advance to next ring descriptor address */ - pTxD->DMADONE = 1; - RingBasePaLow += TXD_SIZE; - RingBaseVa = (u8 *)RingBaseVa + TXD_SIZE; - - /* advance to next TxBuf address */ - BufBasePaLow += TX_DMA_1ST_BUFFER_SIZE; - BufBaseVa = - (u8 *)BufBaseVa + TX_DMA_1ST_BUFFER_SIZE; - } - DBGPRINT(RT_DEBUG_TRACE, - ("TxRing[%d]: total %d entry allocated\n", num, - index)); - } - if (Status == NDIS_STATUS_RESOURCES) - break; - - /* */ - /* Allocate MGMT ring descriptor's memory except Tx ring which allocated eariler */ - /* */ - pAd->MgmtDescRing.AllocSize = MGMT_RING_SIZE * TXD_SIZE; - RTMP_AllocateMgmtDescMemory(pAd, - pAd->MgmtDescRing.AllocSize, - FALSE, - &pAd->MgmtDescRing.AllocVa, - &pAd->MgmtDescRing.AllocPa); - - if (pAd->MgmtDescRing.AllocVa == NULL) { - ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; - DBGPRINT_ERR("Failed to allocate a big buffer\n"); - Status = NDIS_STATUS_RESOURCES; - break; - } - /* Zero init this memory block */ - NdisZeroMemory(pAd->MgmtDescRing.AllocVa, - pAd->MgmtDescRing.AllocSize); - - /* Save PA & VA for further operation */ - RingBasePaHigh = - RTMP_GetPhysicalAddressHigh(pAd->MgmtDescRing.AllocPa); - RingBasePaLow = - RTMP_GetPhysicalAddressLow(pAd->MgmtDescRing.AllocPa); - RingBaseVa = pAd->MgmtDescRing.AllocVa; - - /* */ - /* Initialize MGMT Ring and associated buffer memory */ - /* */ - for (index = 0; index < MGMT_RING_SIZE; index++) { - pAd->MgmtRing.Cell[index].pNdisPacket = NULL; - pAd->MgmtRing.Cell[index].pNextNdisPacket = NULL; - /* Init MGMT Ring Size, Va, Pa variables */ - pAd->MgmtRing.Cell[index].AllocSize = TXD_SIZE; - pAd->MgmtRing.Cell[index].AllocVa = RingBaseVa; - RTMP_SetPhysicalAddressHigh(pAd->MgmtRing.Cell[index]. - AllocPa, RingBasePaHigh); - RTMP_SetPhysicalAddressLow(pAd->MgmtRing.Cell[index]. - AllocPa, RingBasePaLow); - - /* Offset to next ring descriptor address */ - RingBasePaLow += TXD_SIZE; - RingBaseVa = (u8 *)RingBaseVa + TXD_SIZE; - - /* link the pre-allocated TxBuf to TXD */ - pTxD = (struct rt_txd *) pAd->MgmtRing.Cell[index].AllocVa; - pTxD->DMADONE = 1; - - /* no pre-allocated buffer required in MgmtRing for scatter-gather case */ - } - DBGPRINT(RT_DEBUG_TRACE, - ("MGMT Ring: total %d entry allocated\n", index)); - - /* */ - /* Allocate RX ring descriptor's memory except Tx ring which allocated eariler */ - /* */ - pAd->RxDescRing.AllocSize = RX_RING_SIZE * RXD_SIZE; - RTMP_AllocateRxDescMemory(pAd, - pAd->RxDescRing.AllocSize, - FALSE, - &pAd->RxDescRing.AllocVa, - &pAd->RxDescRing.AllocPa); - - if (pAd->RxDescRing.AllocVa == NULL) { - ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; - DBGPRINT_ERR("Failed to allocate a big buffer\n"); - Status = NDIS_STATUS_RESOURCES; - break; - } - /* Zero init this memory block */ - NdisZeroMemory(pAd->RxDescRing.AllocVa, - pAd->RxDescRing.AllocSize); - - DBGPRINT(RT_DEBUG_OFF, - ("RX DESC %p size = %ld\n", pAd->RxDescRing.AllocVa, - pAd->RxDescRing.AllocSize)); - - /* Save PA & VA for further operation */ - RingBasePaHigh = - RTMP_GetPhysicalAddressHigh(pAd->RxDescRing.AllocPa); - RingBasePaLow = - RTMP_GetPhysicalAddressLow(pAd->RxDescRing.AllocPa); - RingBaseVa = pAd->RxDescRing.AllocVa; - - /* */ - /* Initialize Rx Ring and associated buffer memory */ - /* */ - for (index = 0; index < RX_RING_SIZE; index++) { - /* Init RX Ring Size, Va, Pa variables */ - pAd->RxRing.Cell[index].AllocSize = RXD_SIZE; - pAd->RxRing.Cell[index].AllocVa = RingBaseVa; - RTMP_SetPhysicalAddressHigh(pAd->RxRing.Cell[index]. - AllocPa, RingBasePaHigh); - RTMP_SetPhysicalAddressLow(pAd->RxRing.Cell[index]. - AllocPa, RingBasePaLow); - - /*NdisZeroMemory(RingBaseVa, RXD_SIZE); */ - - /* Offset to next ring descriptor address */ - RingBasePaLow += RXD_SIZE; - RingBaseVa = (u8 *)RingBaseVa + RXD_SIZE; - - /* Setup Rx associated Buffer size & allocate share memory */ - pDmaBuf = &pAd->RxRing.Cell[index].DmaBuf; - pDmaBuf->AllocSize = RX_BUFFER_AGGRESIZE; - pPacket = RTMP_AllocateRxPacketBuffer(pAd, - pDmaBuf-> - AllocSize, FALSE, - &pDmaBuf->AllocVa, - &pDmaBuf-> - AllocPa); - - /* keep allocated rx packet */ - pAd->RxRing.Cell[index].pNdisPacket = pPacket; - - /* Error handling */ - if (pDmaBuf->AllocVa == NULL) { - ErrorValue = ERRLOG_OUT_OF_SHARED_MEMORY; - DBGPRINT_ERR("Failed to allocate RxRing's 1st buffer\n"); - Status = NDIS_STATUS_RESOURCES; - break; - } - /* Zero init this memory block */ - NdisZeroMemory(pDmaBuf->AllocVa, pDmaBuf->AllocSize); - - /* Write RxD buffer address & allocated buffer length */ - pRxD = (struct rt_rxd *) pAd->RxRing.Cell[index].AllocVa; - pRxD->SDP0 = - RTMP_GetPhysicalAddressLow(pDmaBuf->AllocPa); - pRxD->DDONE = 0; - - } - - DBGPRINT(RT_DEBUG_TRACE, - ("Rx Ring: total %d entry allocated\n", index)); - - } while (FALSE); - - NdisZeroMemory(&pAd->FragFrame, sizeof(struct rt_fragment_frame)); - pAd->FragFrame.pFragPacket = - RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE); - - if (pAd->FragFrame.pFragPacket == NULL) { - Status = NDIS_STATUS_RESOURCES; - } - - if (Status != NDIS_STATUS_SUCCESS) { - /* Log error inforamtion */ - NdisWriteErrorLogEntry(pAd->AdapterHandle, - NDIS_ERROR_CODE_OUT_OF_RESOURCES, - 1, ErrorValue); - } - /* Following code segment get from original func:NICInitTxRxRingAndBacklogQueue(), now should integrate it to here. */ - { - DBGPRINT(RT_DEBUG_TRACE, - ("--> NICInitTxRxRingAndBacklogQueue\n")); - -/* - // Disable DMA. - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); - GloCfg.word &= 0xff0; - GloCfg.field.EnTXWriteBackDDONE =1; - RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word); -*/ - - /* Initialize all transmit related software queues */ - for (index = 0; index < NUM_OF_TX_RING; index++) { - InitializeQueueHeader(&pAd->TxSwQueue[index]); - /* Init TX rings index pointer */ - pAd->TxRing[index].TxSwFreeIdx = 0; - pAd->TxRing[index].TxCpuIdx = 0; - /*RTMP_IO_WRITE32(pAd, (TX_CTX_IDX0 + i * 0x10) , pAd->TxRing[i].TX_CTX_IDX); */ - } - - /* Init RX Ring index pointer */ - pAd->RxRing.RxSwReadIdx = 0; - pAd->RxRing.RxCpuIdx = RX_RING_SIZE - 1; - /*RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RX_CRX_IDX0); */ - - /* init MGMT ring index pointer */ - pAd->MgmtRing.TxSwFreeIdx = 0; - pAd->MgmtRing.TxCpuIdx = 0; - - pAd->PrivateInfo.TxRingFullCnt = 0; - - DBGPRINT(RT_DEBUG_TRACE, - ("<-- NICInitTxRxRingAndBacklogQueue\n")); - } - - DBGPRINT_S(Status, - ("<-- RTMPAllocTxRxRingMemory, Status=%x\n", Status)); - return Status; -} - -/* - ======================================================================== - - Routine Description: - Reset NIC Asics. Call after rest DMA. So reset TX_CTX_IDX to zero. - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - Note: - Reset NIC to initial state AS IS system boot up time. - - ======================================================================== -*/ -void RTMPRingCleanUp(struct rt_rtmp_adapter *pAd, u8 RingType) -{ - struct rt_txd * pTxD; - struct rt_rxd * pRxD; - struct rt_queue_entry *pEntry; - void *pPacket; - int i; - struct rt_rtmp_tx_ring *pTxRing; - unsigned long IrqFlags; - /*u32 RxSwReadIdx; */ - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPRingCleanUp(RingIdx=%d, Pending-NDIS=%ld)\n", RingType, - pAd->RalinkCounters.PendingNdisPacketCount)); - switch (RingType) { - case QID_AC_BK: - case QID_AC_BE: - case QID_AC_VI: - case QID_AC_VO: - - pTxRing = &pAd->TxRing[RingType]; - - RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); - /* We have to clean all descriptors in case some error happened with reset */ - for (i = 0; i < TX_RING_SIZE; i++) /* We have to scan all TX ring */ - { - pTxD = (struct rt_txd *) pTxRing->Cell[i].AllocVa; - - pPacket = (void *)pTxRing->Cell[i].pNdisPacket; - /* release scatter-and-gather char */ - if (pPacket) { - RELEASE_NDIS_PACKET(pAd, pPacket, - NDIS_STATUS_FAILURE); - pTxRing->Cell[i].pNdisPacket = NULL; - } - - pPacket = - (void *)pTxRing->Cell[i].pNextNdisPacket; - /* release scatter-and-gather char */ - if (pPacket) { - RELEASE_NDIS_PACKET(pAd, pPacket, - NDIS_STATUS_FAILURE); - pTxRing->Cell[i].pNextNdisPacket = NULL; - } - } - - RTMP_IO_READ32(pAd, TX_DTX_IDX0 + RingType * 0x10, - &pTxRing->TxDmaIdx); - pTxRing->TxSwFreeIdx = pTxRing->TxDmaIdx; - pTxRing->TxCpuIdx = pTxRing->TxDmaIdx; - RTMP_IO_WRITE32(pAd, TX_CTX_IDX0 + RingType * 0x10, - pTxRing->TxCpuIdx); - - RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); - - RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); - while (pAd->TxSwQueue[RingType].Head != NULL) { - pEntry = RemoveHeadQueue(&pAd->TxSwQueue[RingType]); - pPacket = QUEUE_ENTRY_TO_PACKET(pEntry); - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - DBGPRINT(RT_DEBUG_TRACE, - ("Release 1 NDIS packet from s/w backlog queue\n")); - } - RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); - break; - - case QID_MGMT: - /* We have to clean all descriptors in case some error happened with reset */ - NdisAcquireSpinLock(&pAd->MgmtRingLock); - - for (i = 0; i < MGMT_RING_SIZE; i++) { - pTxD = (struct rt_txd *) pAd->MgmtRing.Cell[i].AllocVa; - - pPacket = - (void *)pAd->MgmtRing.Cell[i].pNdisPacket; - /* rlease scatter-and-gather char */ - if (pPacket) { - PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, - pTxD->SDLen0, - PCI_DMA_TODEVICE); - RELEASE_NDIS_PACKET(pAd, pPacket, - NDIS_STATUS_FAILURE); - } - pAd->MgmtRing.Cell[i].pNdisPacket = NULL; - - pPacket = - (void *)pAd->MgmtRing.Cell[i]. - pNextNdisPacket; - /* release scatter-and-gather char */ - if (pPacket) { - PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, - pTxD->SDLen1, - PCI_DMA_TODEVICE); - RELEASE_NDIS_PACKET(pAd, pPacket, - NDIS_STATUS_FAILURE); - } - pAd->MgmtRing.Cell[i].pNextNdisPacket = NULL; - - } - - RTMP_IO_READ32(pAd, TX_MGMTDTX_IDX, &pAd->MgmtRing.TxDmaIdx); - pAd->MgmtRing.TxSwFreeIdx = pAd->MgmtRing.TxDmaIdx; - pAd->MgmtRing.TxCpuIdx = pAd->MgmtRing.TxDmaIdx; - RTMP_IO_WRITE32(pAd, TX_MGMTCTX_IDX, pAd->MgmtRing.TxCpuIdx); - - NdisReleaseSpinLock(&pAd->MgmtRingLock); - pAd->RalinkCounters.MgmtRingFullCount = 0; - break; - - case QID_RX: - /* We have to clean all descriptors in case some error happened with reset */ - NdisAcquireSpinLock(&pAd->RxRingLock); - - for (i = 0; i < RX_RING_SIZE; i++) { - pRxD = (struct rt_rxd *) pAd->RxRing.Cell[i].AllocVa; - pRxD->DDONE = 0; - } - - RTMP_IO_READ32(pAd, RX_DRX_IDX, &pAd->RxRing.RxDmaIdx); - pAd->RxRing.RxSwReadIdx = pAd->RxRing.RxDmaIdx; - pAd->RxRing.RxCpuIdx = - ((pAd->RxRing.RxDmaIdx == - 0) ? (RX_RING_SIZE - 1) : (pAd->RxRing.RxDmaIdx - 1)); - RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RxCpuIdx); - - NdisReleaseSpinLock(&pAd->RxRingLock); - break; - - default: - break; - } -} - -void RTMPFreeTxRxRingMemory(struct rt_rtmp_adapter *pAd) -{ - int index, num, j; - struct rt_rtmp_tx_ring *pTxRing; - struct rt_txd * pTxD; - void *pPacket; - unsigned int IrqFlags; - - /*struct os_cookie *pObj =(struct os_cookie *)pAd->OS_Cookie; */ - - DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPFreeTxRxRingMemory\n")); - - /* Free TxSwQueue Packet */ - for (index = 0; index < NUM_OF_TX_RING; index++) { - struct rt_queue_entry *pEntry; - void *pPacket; - struct rt_queue_header *pQueue; - - RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); - pQueue = &pAd->TxSwQueue[index]; - while (pQueue->Head) { - pEntry = RemoveHeadQueue(pQueue); - pPacket = QUEUE_ENTRY_TO_PACKET(pEntry); - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - } - RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); - } - - /* Free Tx Ring Packet */ - for (index = 0; index < NUM_OF_TX_RING; index++) { - pTxRing = &pAd->TxRing[index]; - - for (j = 0; j < TX_RING_SIZE; j++) { - pTxD = (struct rt_txd *) (pTxRing->Cell[j].AllocVa); - pPacket = pTxRing->Cell[j].pNdisPacket; - - if (pPacket) { - PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr0, - pTxD->SDLen0, - PCI_DMA_TODEVICE); - RELEASE_NDIS_PACKET(pAd, pPacket, - NDIS_STATUS_SUCCESS); - } - /*Always assign pNdisPacket as NULL after clear */ - pTxRing->Cell[j].pNdisPacket = NULL; - - pPacket = pTxRing->Cell[j].pNextNdisPacket; - - if (pPacket) { - PCI_UNMAP_SINGLE(pAd, pTxD->SDPtr1, - pTxD->SDLen1, - PCI_DMA_TODEVICE); - RELEASE_NDIS_PACKET(pAd, pPacket, - NDIS_STATUS_SUCCESS); - } - /*Always assign pNextNdisPacket as NULL after clear */ - pTxRing->Cell[pTxRing->TxSwFreeIdx].pNextNdisPacket = - NULL; - - } - } - - for (index = RX_RING_SIZE - 1; index >= 0; index--) { - if ((pAd->RxRing.Cell[index].DmaBuf.AllocVa) - && (pAd->RxRing.Cell[index].pNdisPacket)) { - PCI_UNMAP_SINGLE(pAd, - pAd->RxRing.Cell[index].DmaBuf.AllocPa, - pAd->RxRing.Cell[index].DmaBuf. - AllocSize, PCI_DMA_FROMDEVICE); - RELEASE_NDIS_PACKET(pAd, - pAd->RxRing.Cell[index].pNdisPacket, - NDIS_STATUS_SUCCESS); - } - } - NdisZeroMemory(pAd->RxRing.Cell, RX_RING_SIZE * sizeof(struct rt_rtmp_dmacb)); - - if (pAd->RxDescRing.AllocVa) { - RTMP_FreeDescMemory(pAd, pAd->RxDescRing.AllocSize, - pAd->RxDescRing.AllocVa, - pAd->RxDescRing.AllocPa); - } - NdisZeroMemory(&pAd->RxDescRing, sizeof(struct rt_rtmp_dmabuf)); - - if (pAd->MgmtDescRing.AllocVa) { - RTMP_FreeDescMemory(pAd, pAd->MgmtDescRing.AllocSize, - pAd->MgmtDescRing.AllocVa, - pAd->MgmtDescRing.AllocPa); - } - NdisZeroMemory(&pAd->MgmtDescRing, sizeof(struct rt_rtmp_dmabuf)); - - for (num = 0; num < NUM_OF_TX_RING; num++) { - if (pAd->TxBufSpace[num].AllocVa) { - RTMP_FreeFirstTxBuffer(pAd, - pAd->TxBufSpace[num].AllocSize, - FALSE, - pAd->TxBufSpace[num].AllocVa, - pAd->TxBufSpace[num].AllocPa); - } - NdisZeroMemory(&pAd->TxBufSpace[num], sizeof(struct rt_rtmp_dmabuf)); - - if (pAd->TxDescRing[num].AllocVa) { - RTMP_FreeDescMemory(pAd, pAd->TxDescRing[num].AllocSize, - pAd->TxDescRing[num].AllocVa, - pAd->TxDescRing[num].AllocPa); - } - NdisZeroMemory(&pAd->TxDescRing[num], sizeof(struct rt_rtmp_dmabuf)); - } - - if (pAd->FragFrame.pFragPacket) - RELEASE_NDIS_PACKET(pAd, pAd->FragFrame.pFragPacket, - NDIS_STATUS_SUCCESS); - - DBGPRINT(RT_DEBUG_TRACE, ("<-- RTMPFreeTxRxRingMemory\n")); -} - -/*************************************************************************** - * - * register related procedures. - * - **************************************************************************/ -/* -======================================================================== -Routine Description: - Disable DMA. - -Arguments: - *pAd the raxx interface data pointer - -Return Value: - None - -Note: -======================================================================== -*/ -void RT28XXDMADisable(struct rt_rtmp_adapter *pAd) -{ - WPDMA_GLO_CFG_STRUC GloCfg; - - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); - GloCfg.word &= 0xff0; - GloCfg.field.EnTXWriteBackDDONE = 1; - RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word); -} - -/* -======================================================================== -Routine Description: - Enable DMA. - -Arguments: - *pAd the raxx interface data pointer - -Return Value: - None - -Note: -======================================================================== -*/ -void RT28XXDMAEnable(struct rt_rtmp_adapter *pAd) -{ - WPDMA_GLO_CFG_STRUC GloCfg; - int i = 0; - - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4); - do { - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); - if ((GloCfg.field.TxDMABusy == 0) - && (GloCfg.field.RxDMABusy == 0)) - break; - - DBGPRINT(RT_DEBUG_TRACE, ("==> DMABusy\n")); - RTMPusecDelay(1000); - i++; - } while (i < 200); - - RTMPusecDelay(50); - - GloCfg.field.EnTXWriteBackDDONE = 1; - GloCfg.field.WPDMABurstSIZE = 2; - GloCfg.field.EnableRxDMA = 1; - GloCfg.field.EnableTxDMA = 1; - - DBGPRINT(RT_DEBUG_TRACE, - ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word)); - RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word); - -} - -BOOLEAN AsicCheckCommanOk(struct rt_rtmp_adapter *pAd, u8 Command) -{ - u32 CmdStatus = 0, CID = 0, i; - u32 ThisCIDMask = 0; - - i = 0; - do { - RTMP_IO_READ32(pAd, H2M_MAILBOX_CID, &CID); - /* Find where the command is. Because this is randomly specified by firmware. */ - if ((CID & CID0MASK) == Command) { - ThisCIDMask = CID0MASK; - break; - } else if ((((CID & CID1MASK) >> 8) & 0xff) == Command) { - ThisCIDMask = CID1MASK; - break; - } else if ((((CID & CID2MASK) >> 16) & 0xff) == Command) { - ThisCIDMask = CID2MASK; - break; - } else if ((((CID & CID3MASK) >> 24) & 0xff) == Command) { - ThisCIDMask = CID3MASK; - break; - } - - RTMPusecDelay(100); - i++; - } while (i < 200); - - /* Get CommandStatus Value */ - RTMP_IO_READ32(pAd, H2M_MAILBOX_STATUS, &CmdStatus); - - /* This command's status is at the same position as command. So AND command position's bitmask to read status. */ - if (i < 200) { - /* If Status is 1, the command is success. */ - if (((CmdStatus & ThisCIDMask) == 0x1) - || ((CmdStatus & ThisCIDMask) == 0x100) - || ((CmdStatus & ThisCIDMask) == 0x10000) - || ((CmdStatus & ThisCIDMask) == 0x1000000)) { - DBGPRINT(RT_DEBUG_TRACE, - ("--> AsicCheckCommanOk CID = 0x%x, CmdStatus= 0x%x \n", - CID, CmdStatus)); - RTMP_IO_WRITE32(pAd, H2M_MAILBOX_STATUS, 0xffffffff); - RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CID, 0xffffffff); - return TRUE; - } - DBGPRINT(RT_DEBUG_TRACE, - ("--> AsicCheckCommanFail1 CID = 0x%x, CmdStatus= 0x%x \n", - CID, CmdStatus)); - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("--> AsicCheckCommanFail2 Timeout Command = %d, CmdStatus= 0x%x \n", - Command, CmdStatus)); - } - /* Clear Command and Status. */ - RTMP_IO_WRITE32(pAd, H2M_MAILBOX_STATUS, 0xffffffff); - RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CID, 0xffffffff); - - return FALSE; -} - -/* -======================================================================== -Routine Description: - Write Beacon buffer to Asic. - -Arguments: - *pAd the raxx interface data pointer - -Return Value: - None - -Note: -======================================================================== -*/ -void RT28xx_UpdateBeaconToAsic(struct rt_rtmp_adapter *pAd, - int apidx, - unsigned long FrameLen, unsigned long UpdatePos) -{ - unsigned long CapInfoPos = 0; - u8 *ptr, *ptr_update, *ptr_capinfo; - u32 i; - BOOLEAN bBcnReq = FALSE; - u8 bcn_idx = 0; - - { - DBGPRINT(RT_DEBUG_ERROR, - ("%s() : No valid Interface be found.\n", __func__)); - return; - } - - /*if ((pAd->WdsTab.Mode == WDS_BRIDGE_MODE) */ - /* || ((pAd->ApCfg.MBSSID[apidx].MSSIDDev == NULL) */ - /* || !(pAd->ApCfg.MBSSID[apidx].MSSIDDev->flags & IFF_UP)) */ - /* ) */ - if (bBcnReq == FALSE) { - /* when the ra interface is down, do not send its beacon frame */ - /* clear all zero */ - for (i = 0; i < TXWI_SIZE; i += 4) - RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, - 0x00); - } else { - ptr = (u8 *)& pAd->BeaconTxWI; - for (i = 0; i < TXWI_SIZE; i += 4) /* 16-byte TXWI field */ - { - u32 longptr = - *ptr + (*(ptr + 1) << 8) + (*(ptr + 2) << 16) + - (*(ptr + 3) << 24); - RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, - longptr); - ptr += 4; - } - - /* Update CapabilityInfo in Beacon */ - for (i = CapInfoPos; i < (CapInfoPos + 2); i++) { - RTMP_IO_WRITE8(pAd, - pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + - i, *ptr_capinfo); - ptr_capinfo++; - } - - if (FrameLen > UpdatePos) { - for (i = UpdatePos; i < (FrameLen); i++) { - RTMP_IO_WRITE8(pAd, - pAd->BeaconOffset[bcn_idx] + - TXWI_SIZE + i, *ptr_update); - ptr_update++; - } - } - - } - -} - -void RT28xxPciStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx) -{ - AUTO_WAKEUP_STRUC AutoWakeupCfg; - - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) - return; - - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WAKEUP_NOW)) { - DBGPRINT(RT_DEBUG_TRACE, ("waking up now!\n")); - return; - } - - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_WAKEUP_NOW); - - RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW); - - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE) - && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) { - /* Support PCIe Advance Power Save */ - if (bFromTx == TRUE && (pAd->Mlme.bPsPollTimerRunning == TRUE)) { - pAd->Mlme.bPsPollTimerRunning = FALSE; - RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_WAKEUP); - RTMPusecDelay(3000); - DBGPRINT(RT_DEBUG_TRACE, - ("=======AsicForceWakeup===bFromTx\n")); - } - - AutoWakeupCfg.word = 0; - RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word); - - if (RT28xxPciAsicRadioOn(pAd, DOT11POWERSAVE)) { -#ifdef PCIE_PS_SUPPORT - /* add by johnli, RF power sequence setup, load RF normal operation-mode setup */ - if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd)) { - struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps; - - if (pChipOps->AsicReverseRfFromSleepMode) - pChipOps-> - AsicReverseRfFromSleepMode(pAd); - } else -#endif /* PCIE_PS_SUPPORT // */ - { - /* end johnli */ - /* In Radio Off, we turn off RF clk, So now need to call ASICSwitchChannel again. */ - if (INFRA_ON(pAd) - && (pAd->CommonCfg.CentralChannel != - pAd->CommonCfg.Channel) - && (pAd->MlmeAux.HtCapability.HtCapInfo. - ChannelWidth == BW_40)) { - /* Must using 40MHz. */ - AsicSwitchChannel(pAd, - pAd->CommonCfg. - CentralChannel, - FALSE); - AsicLockChannel(pAd, - pAd->CommonCfg. - CentralChannel); - } else { - /* Must using 20MHz. */ - AsicSwitchChannel(pAd, - pAd->CommonCfg. - Channel, FALSE); - AsicLockChannel(pAd, - pAd->CommonCfg.Channel); - } - } - } -#ifdef PCIE_PS_SUPPORT - /* 3090 MCU Wakeup command needs more time to be stable. */ - /* Before stable, don't issue other MCU command to prevent from firmware error. */ - if (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd)) && IS_VERSION_AFTER_F(pAd) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) { - DBGPRINT(RT_DEBUG_TRACE, - ("<==RT28xxPciStaAsicForceWakeup::Release the MCU Lock(3090)\n")); - RTMP_SEM_LOCK(&pAd->McuCmdLock); - pAd->brt30xxBanMcuCmd = FALSE; - RTMP_SEM_UNLOCK(&pAd->McuCmdLock); - } -#endif /* PCIE_PS_SUPPORT // */ - } else { - /* PCI, 2860-PCIe */ - DBGPRINT(RT_DEBUG_TRACE, - ("<==RT28xxPciStaAsicForceWakeup::Original PCI Power Saving\n")); - AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x02); - AutoWakeupCfg.word = 0; - RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word); - } - - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WAKEUP_NOW); - DBGPRINT(RT_DEBUG_TRACE, ("<=======RT28xxPciStaAsicForceWakeup\n")); -} - -void RT28xxPciStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd, - u16 TbttNumToNextWakeUp) -{ - BOOLEAN brc; - - if (pAd->StaCfg.bRadio == FALSE) { - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE); - return; - } - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE) - && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) { - unsigned long Now = 0; - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WAKEUP_NOW)) { - DBGPRINT(RT_DEBUG_TRACE, ("waking up now!\n")); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE); - return; - } - - NdisGetSystemUpTime(&Now); - /* If last send NULL fram time is too close to this receiving beacon (within 8ms), don't go to sleep for this DTM. */ - /* Because Some AP can't queuing outgoing frames immediately. */ - if (((pAd->Mlme.LastSendNULLpsmTime + 8) >= Now) - && (pAd->Mlme.LastSendNULLpsmTime <= Now)) { - DBGPRINT(RT_DEBUG_TRACE, - ("Now = %lu, LastSendNULLpsmTime=%lu : RxCountSinceLastNULL = %lu. \n", - Now, pAd->Mlme.LastSendNULLpsmTime, - pAd->RalinkCounters.RxCountSinceLastNULL)); - return; - } else if ((pAd->RalinkCounters.RxCountSinceLastNULL > 0) - && - ((pAd->Mlme.LastSendNULLpsmTime + - pAd->CommonCfg.BeaconPeriod) >= Now)) { - DBGPRINT(RT_DEBUG_TRACE, - ("Now = %lu, LastSendNULLpsmTime=%lu: RxCountSinceLastNULL = %lu > 0 \n", - Now, pAd->Mlme.LastSendNULLpsmTime, - pAd->RalinkCounters.RxCountSinceLastNULL)); - return; - } - - brc = - RT28xxPciAsicRadioOff(pAd, DOT11POWERSAVE, - TbttNumToNextWakeUp); - if (brc == TRUE) - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_DOZE); - } else { - AUTO_WAKEUP_STRUC AutoWakeupCfg; - /* we have decided to SLEEP, so at least do it for a BEACON period. */ - if (TbttNumToNextWakeUp == 0) - TbttNumToNextWakeUp = 1; - - /*RTMP_IO_WRITE32(pAd, INT_MASK_CSR, AutoWakeupInt); */ - - AutoWakeupCfg.word = 0; - RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word); - AutoWakeupCfg.field.NumofSleepingTbtt = TbttNumToNextWakeUp - 1; - AutoWakeupCfg.field.EnableAutoWakeup = 1; - AutoWakeupCfg.field.AutoLeadTime = 5; - RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word); - AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x00); /* send POWER-SAVE command to MCU. Timeout 40us. */ - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_DOZE); - DBGPRINT(RT_DEBUG_TRACE, - ("<-- %s, TbttNumToNextWakeUp=%d \n", __func__, - TbttNumToNextWakeUp)); - } - -} - -void PsPollWakeExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - unsigned long flags; - - DBGPRINT(RT_DEBUG_TRACE, ("-->PsPollWakeExec \n")); - RTMP_INT_LOCK(&pAd->irq_lock, flags); - if (pAd->Mlme.bPsPollTimerRunning) { - RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_WAKEUP); - } - pAd->Mlme.bPsPollTimerRunning = FALSE; - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); -#ifdef PCIE_PS_SUPPORT - /* For rt30xx power solution 3, Use software timer to wake up in psm. So call */ - /* AsicForceWakeup here instead of handling twakeup interrupt. */ - if (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd)) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) { - DBGPRINT(RT_DEBUG_TRACE, - ("<--PsPollWakeExec::3090 calls AsicForceWakeup(pAd, DOT11POWERSAVE) in advance \n")); - AsicForceWakeup(pAd, DOT11POWERSAVE); - } -#endif /* PCIE_PS_SUPPORT // */ -} - -void RadioOnExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps; - WPDMA_GLO_CFG_STRUC DmaCfg; - BOOLEAN Cancelled; - - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) { - DBGPRINT(RT_DEBUG_TRACE, - ("-->RadioOnExec() return on fOP_STATUS_DOZE == TRUE; \n")); -/*KH Debug: Add the compile flag "RT2860 and condition */ -#ifdef RTMP_PCI_SUPPORT - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE) - && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) - RTMPSetTimer(&pAd->Mlme.RadioOnOffTimer, 10); -#endif /* RTMP_PCI_SUPPORT // */ - return; - } - - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) { - DBGPRINT(RT_DEBUG_TRACE, - ("-->RadioOnExec() return on SCAN_IN_PROGRESS; \n")); -#ifdef RTMP_PCI_SUPPORT - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE) - && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) - RTMPSetTimer(&pAd->Mlme.RadioOnOffTimer, 10); -#endif /* RTMP_PCI_SUPPORT // */ - return; - } -/*KH Debug: need to check. I add the compile flag "CONFIG_STA_SUPPORT" to enclose the following codes. */ -#ifdef RTMP_PCI_SUPPORT - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE) - && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) { - pAd->Mlme.bPsPollTimerRunning = FALSE; - RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); - } -#endif /* RTMP_PCI_SUPPORT // */ - if (pAd->StaCfg.bRadio == TRUE) { - pAd->bPCIclkOff = FALSE; - RTMPRingCleanUp(pAd, QID_AC_BK); - RTMPRingCleanUp(pAd, QID_AC_BE); - RTMPRingCleanUp(pAd, QID_AC_VI); - RTMPRingCleanUp(pAd, QID_AC_VO); - RTMPRingCleanUp(pAd, QID_MGMT); - RTMPRingCleanUp(pAd, QID_RX); - - /* 2. Send wake up command. */ - AsicSendCommandToMcu(pAd, 0x31, PowerWakeCID, 0x00, 0x02); - /* 2-1. wait command ok. */ - AsicCheckCommanOk(pAd, PowerWakeCID); - - /* When PCI clock is off, don't want to service interrupt. So when back to clock on, enable interrupt. */ - /*RTMP_IO_WRITE32(pAd, INT_MASK_CSR, (DELAYINTMASK|RxINT)); */ - RTMP_ASIC_INTERRUPT_ENABLE(pAd); - - /* 3. Enable Tx DMA. */ - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &DmaCfg.word); - DmaCfg.field.EnableTxDMA = 1; - RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, DmaCfg.word); - - /* In Radio Off, we turn off RF clk, So now need to call ASICSwitchChannel again. */ - if (INFRA_ON(pAd) - && (pAd->CommonCfg.CentralChannel != pAd->CommonCfg.Channel) - && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == - BW_40)) { - /* Must using 40MHz. */ - AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, - FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); - } else { - /* Must using 20MHz. */ - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.Channel); - } - -/*KH Debug:The following codes should be enclosed by RT3090 compile flag */ - if (pChipOps->AsicReverseRfFromSleepMode) - pChipOps->AsicReverseRfFromSleepMode(pAd); - -#ifdef PCIE_PS_SUPPORT -/* 3090 MCU Wakeup command needs more time to be stable. */ -/* Before stable, don't issue other MCU command to prevent from firmware error. */ - if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) { - RTMP_SEM_LOCK(&pAd->McuCmdLock); - pAd->brt30xxBanMcuCmd = FALSE; - RTMP_SEM_UNLOCK(&pAd->McuCmdLock); - } -#endif /* PCIE_PS_SUPPORT // */ - - /* Clear Radio off flag */ - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); - - /* Set LED */ - RTMPSetLED(pAd, LED_RADIO_ON); - - if (pAd->StaCfg.Psm == PWR_ACTIVE) { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, - pAd->StaCfg.BBPR3); - } - } else { - RT28xxPciAsicRadioOff(pAd, GUIRADIO_OFF, 0); - } -} - -/* - ========================================================================== - Description: - This routine sends command to firmware and turn our chip to wake up mode from power save mode. - Both RadioOn and .11 power save function needs to call this routine. - Input: - Level = GUIRADIO_OFF : call this function is from Radio Off to Radio On. Need to restore PCI host value. - Level = other value : normal wake up function. - - ========================================================================== - */ -BOOLEAN RT28xxPciAsicRadioOn(struct rt_rtmp_adapter *pAd, u8 Level) -{ - /*WPDMA_GLO_CFG_STRUC DmaCfg; */ - BOOLEAN Cancelled; - /*u32 MACValue; */ - - if (pAd->OpMode == OPMODE_AP && Level == DOT11POWERSAVE) - return FALSE; - - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) { - if (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) { - pAd->Mlme.bPsPollTimerRunning = FALSE; - RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); - } - if ((pAd->StaCfg.PSControl.field.EnableNewPS == TRUE && - (Level == GUIRADIO_OFF || Level == GUI_IDLE_POWER_SAVE)) || - RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND)) { - /* Some chips don't need to delay 6ms, so copy RTMPPCIePowerLinkCtrlRestore */ - /* return condition here. */ - /* - if (((pAd->MACVersion&0xffff0000) != 0x28600000) - && ((pAd->DeviceID == NIC2860_PCIe_DEVICE_ID) - ||(pAd->DeviceID == NIC2790_PCIe_DEVICE_ID))) - */ - { - DBGPRINT(RT_DEBUG_TRACE, - ("RT28xxPciAsicRadioOn ()\n")); - /* 1. Set PCI Link Control in Configuration Space. */ - RTMPPCIeLinkCtrlValueRestore(pAd, - RESTORE_WAKEUP); - RTMPusecDelay(6000); - } - } - } -#ifdef PCIE_PS_SUPPORT - if (! - (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)))) -#endif /* PCIE_PS_SUPPORT // */ - { - pAd->bPCIclkOff = FALSE; - DBGPRINT(RT_DEBUG_TRACE, - ("PSM :309xbPCIclkOff == %d\n", pAd->bPCIclkOff)); - } - /* 2. Send wake up command. */ - AsicSendCommandToMcu(pAd, 0x31, PowerWakeCID, 0x00, 0x02); - pAd->bPCIclkOff = FALSE; - /* 2-1. wait command ok. */ - AsicCheckCommanOk(pAd, PowerWakeCID); - RTMP_ASIC_INTERRUPT_ENABLE(pAd); - - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF); - if (Level == GUI_IDLE_POWER_SAVE) { -#ifdef PCIE_PS_SUPPORT - - /* add by johnli, RF power sequence setup, load RF normal operation-mode setup */ - if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))) { - struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps; - - if (pChipOps->AsicReverseRfFromSleepMode) - pChipOps->AsicReverseRfFromSleepMode(pAd); - /* 3090 MCU Wakeup command needs more time to be stable. */ - /* Before stable, don't issue other MCU command to prevent from firmware error. */ - if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == - 3) - && (pAd->StaCfg.PSControl.field.EnableNewPS == - TRUE)) { - RTMP_SEM_LOCK(&pAd->McuCmdLock); - pAd->brt30xxBanMcuCmd = FALSE; - RTMP_SEM_UNLOCK(&pAd->McuCmdLock); - } - } else - /* end johnli */ -#endif /* PCIE_PS_SUPPORT // */ - { - /* In Radio Off, we turn off RF clk, So now need to call ASICSwitchChannel again. */ - { - if (INFRA_ON(pAd) - && (pAd->CommonCfg.CentralChannel != - pAd->CommonCfg.Channel) - && (pAd->MlmeAux.HtCapability.HtCapInfo. - ChannelWidth == BW_40)) { - /* Must using 40MHz. */ - AsicSwitchChannel(pAd, - pAd->CommonCfg. - CentralChannel, - FALSE); - AsicLockChannel(pAd, - pAd->CommonCfg. - CentralChannel); - } else { - /* Must using 20MHz. */ - AsicSwitchChannel(pAd, - pAd->CommonCfg. - Channel, FALSE); - AsicLockChannel(pAd, - pAd->CommonCfg.Channel); - } - } - - } - } - return TRUE; - -} - -/* - ========================================================================== - Description: - This routine sends command to firmware and turn our chip to power save mode. - Both RadioOff and .11 power save function needs to call this routine. - Input: - Level = GUIRADIO_OFF : GUI Radio Off mode - Level = DOT11POWERSAVE : 802.11 power save mode - Level = RTMP_HALT : When Disable device. - - ========================================================================== - */ -BOOLEAN RT28xxPciAsicRadioOff(struct rt_rtmp_adapter *pAd, - u8 Level, u16 TbttNumToNextWakeUp) -{ - WPDMA_GLO_CFG_STRUC DmaCfg; - u8 i, tempBBP_R3 = 0; - BOOLEAN brc = FALSE, Cancelled; - u32 TbTTTime = 0; - u32 PsPollTime = 0 /*, MACValue */ ; - unsigned long BeaconPeriodTime; - u32 RxDmaIdx, RxCpuIdx; - DBGPRINT(RT_DEBUG_TRACE, - ("AsicRadioOff ===> Lv= %d, TxCpuIdx = %d, TxDmaIdx = %d. RxCpuIdx = %d, RxDmaIdx = %d.\n", - Level, pAd->TxRing[0].TxCpuIdx, pAd->TxRing[0].TxDmaIdx, - pAd->RxRing.RxCpuIdx, pAd->RxRing.RxDmaIdx)); - - if (pAd->OpMode == OPMODE_AP && Level == DOT11POWERSAVE) - return FALSE; - - /* Check Rx DMA busy status, if more than half is occupied, give up this radio off. */ - RTMP_IO_READ32(pAd, RX_DRX_IDX, &RxDmaIdx); - RTMP_IO_READ32(pAd, RX_CRX_IDX, &RxCpuIdx); - if ((RxDmaIdx > RxCpuIdx) && ((RxDmaIdx - RxCpuIdx) > RX_RING_SIZE / 3)) { - DBGPRINT(RT_DEBUG_TRACE, - ("AsicRadioOff ===> return1. RxDmaIdx = %d , RxCpuIdx = %d. \n", - RxDmaIdx, RxCpuIdx)); - return FALSE; - } else if ((RxCpuIdx >= RxDmaIdx) - && ((RxCpuIdx - RxDmaIdx) < RX_RING_SIZE / 3)) { - DBGPRINT(RT_DEBUG_TRACE, - ("AsicRadioOff ===> return2. RxCpuIdx = %d. RxDmaIdx = %d , \n", - RxCpuIdx, RxDmaIdx)); - return FALSE; - } - /* Once go into this function, disable tx because don't want too many packets in queue to prevent HW stops. */ - /*pAd->bPCIclkOffDisableTx = TRUE; */ - RTMP_SET_PSFLAG(pAd, fRTMP_PS_DISABLE_TX); - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE) - && pAd->OpMode == OPMODE_STA - && pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) { - RTMPCancelTimer(&pAd->Mlme.RadioOnOffTimer, &Cancelled); - RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); - - if (Level == DOT11POWERSAVE) { - RTMP_IO_READ32(pAd, TBTT_TIMER, &TbTTTime); - TbTTTime &= 0x1ffff; - /* 00. check if need to do sleep in this DTIM period. If next beacon will arrive within 30ms , ...doesn't necessarily sleep. */ - /* TbTTTime uint = 64us, LEAD_TIME unit = 1024us, PsPollTime unit = 1ms */ - if (((64 * TbTTTime) < ((LEAD_TIME * 1024) + 40000)) - && (TbttNumToNextWakeUp == 0)) { - DBGPRINT(RT_DEBUG_TRACE, - ("TbTTTime = 0x%x , give up this sleep. \n", - TbTTTime)); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE); - /*pAd->bPCIclkOffDisableTx = FALSE; */ - RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_DISABLE_TX); - return FALSE; - } else { - PsPollTime = - (64 * TbTTTime - LEAD_TIME * 1024) / 1000; -#ifdef PCIE_PS_SUPPORT - if ((IS_RT3090(pAd) || IS_RT3572(pAd) - || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd) - && (pAd->StaCfg.PSControl.field. - rt30xxPowerMode == 3) - && (pAd->StaCfg.PSControl.field. - EnableNewPS == TRUE)) { - PsPollTime -= 5; - } else -#endif /* PCIE_PS_SUPPORT // */ - PsPollTime -= 3; - - BeaconPeriodTime = - pAd->CommonCfg.BeaconPeriod * 102 / 100; - if (TbttNumToNextWakeUp > 0) - PsPollTime += - ((TbttNumToNextWakeUp - - 1) * BeaconPeriodTime); - - pAd->Mlme.bPsPollTimerRunning = TRUE; - RTMPSetTimer(&pAd->Mlme.PsPollTimer, - PsPollTime); - } - } - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("RT28xxPciAsicRadioOff::Level!=DOT11POWERSAVE \n")); - } - - pAd->bPCIclkOffDisableTx = FALSE; - - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF); - - /* Set to 1R. */ - if (pAd->Antenna.field.RxPath > 1 && pAd->OpMode == OPMODE_STA) { - tempBBP_R3 = (pAd->StaCfg.BBPR3 & 0xE7); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, tempBBP_R3); - } - /* In Radio Off, we turn off RF clk, So now need to call ASICSwitchChannel again. */ - if ((INFRA_ON(pAd) || pAd->OpMode == OPMODE_AP) - && (pAd->CommonCfg.CentralChannel != pAd->CommonCfg.Channel) - && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40)) { - /* Must using 40MHz. */ - AsicTurnOffRFClk(pAd, pAd->CommonCfg.CentralChannel); - } else { - /* Must using 20MHz. */ - AsicTurnOffRFClk(pAd, pAd->CommonCfg.Channel); - } - - if (Level != RTMP_HALT) { - /* Change Interrupt bitmask. */ - /* When PCI clock is off, don't want to service interrupt. */ - RTMP_IO_WRITE32(pAd, INT_MASK_CSR, AutoWakeupInt); - } else { - RTMP_ASIC_INTERRUPT_DISABLE(pAd); - } - - RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RxCpuIdx); - /* 2. Send Sleep command */ - RTMP_IO_WRITE32(pAd, H2M_MAILBOX_STATUS, 0xffffffff); - RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CID, 0xffffffff); - /* send POWER-SAVE command to MCU. high-byte = 1 save power as much as possible. high byte = 0 save less power */ - AsicSendCommandToMcu(pAd, 0x30, PowerSafeCID, 0xff, 0x1); - /* 2-1. Wait command success */ - /* Status = 1 : success, Status = 2, already sleep, Status = 3, Maybe MAC is busy so can't finish this task. */ - brc = AsicCheckCommanOk(pAd, PowerSafeCID); - - /* 3. After 0x30 command is ok, send radio off command. lowbyte = 0 for power safe. */ - /* If 0x30 command is not ok this time, we can ignore 0x35 command. It will make sure not cause firmware'r problem. */ - if ((Level == DOT11POWERSAVE) && (brc == TRUE)) { - AsicSendCommandToMcu(pAd, 0x35, PowerRadioOffCID, 0, 0x00); /* lowbyte = 0 means to do power safe, NOT turn off radio. */ - /* 3-1. Wait command success */ - AsicCheckCommanOk(pAd, PowerRadioOffCID); - } else if (brc == TRUE) { - AsicSendCommandToMcu(pAd, 0x35, PowerRadioOffCID, 1, 0x00); /* lowbyte = 0 means to do power safe, NOT turn off radio. */ - /* 3-1. Wait command success */ - AsicCheckCommanOk(pAd, PowerRadioOffCID); - } - /* 1. Wait DMA not busy */ - i = 0; - do { - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &DmaCfg.word); - if ((DmaCfg.field.RxDMABusy == 0) - && (DmaCfg.field.TxDMABusy == 0)) - break; - RTMPusecDelay(20); - i++; - } while (i < 50); - - /* - if (i >= 50) - { - pAd->CheckDmaBusyCount++; - DBGPRINT(RT_DEBUG_TRACE, ("DMA Rx keeps busy. return on AsicRadioOff () CheckDmaBusyCount = %d \n", pAd->CheckDmaBusyCount)); - } - else - { - pAd->CheckDmaBusyCount = 0; - } - */ -/*KH Debug:My original codes have the following codes, but currecnt codes do not have it. */ -/* Disable for stability. If PCIE Link Control is modified for advance power save, re-covery this code segment. */ - RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0x1280); -/*OPSTATUS_SET_FLAG(pAd, fOP_STATUS_CLKSELECT_40MHZ); */ - -#ifdef PCIE_PS_SUPPORT - if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) { - DBGPRINT(RT_DEBUG_TRACE, - ("RT28xxPciAsicRadioOff::3090 return to skip the following TbttNumToNextWakeUp setting for 279x\n")); - pAd->bPCIclkOff = TRUE; - RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_DISABLE_TX); - /* For this case, doesn't need to below actions, so return here. */ - return brc; - } -#endif /* PCIE_PS_SUPPORT // */ - - if (Level == DOT11POWERSAVE) { - AUTO_WAKEUP_STRUC AutoWakeupCfg; - /*RTMPSetTimer(&pAd->Mlme.PsPollTimer, 90); */ - - /* we have decided to SLEEP, so at least do it for a BEACON period. */ - if (TbttNumToNextWakeUp == 0) - TbttNumToNextWakeUp = 1; - - AutoWakeupCfg.word = 0; - RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word); - - /* 1. Set auto wake up timer. */ - AutoWakeupCfg.field.NumofSleepingTbtt = TbttNumToNextWakeUp - 1; - AutoWakeupCfg.field.EnableAutoWakeup = 1; - AutoWakeupCfg.field.AutoLeadTime = LEAD_TIME; - RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word); - } - /* 4-1. If it's to disable our device. Need to restore PCI Configuration Space to its original value. */ - if (Level == RTMP_HALT && pAd->OpMode == OPMODE_STA) { - if ((brc == TRUE) && (i < 50)) - RTMPPCIeLinkCtrlSetting(pAd, 1); - } - /* 4. Set PCI configuration Space Link Comtrol fields. Only Radio Off needs to call this function */ - else if (pAd->OpMode == OPMODE_STA) { - if ((brc == TRUE) && (i < 50)) - RTMPPCIeLinkCtrlSetting(pAd, 3); - } - /*pAd->bPCIclkOffDisableTx = FALSE; */ - RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_DISABLE_TX); - return TRUE; -} - -void RT28xxPciMlmeRadioOn(struct rt_rtmp_adapter *pAd) -{ - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) - return; - - DBGPRINT(RT_DEBUG_TRACE, ("%s===>\n", __func__)); - - if ((pAd->OpMode == OPMODE_AP) || ((pAd->OpMode == OPMODE_STA) - && - (!OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_PCIE_DEVICE) - || pAd->StaCfg.PSControl.field. - EnableNewPS == FALSE))) { - RT28xxPciAsicRadioOn(pAd, GUI_IDLE_POWER_SAVE); - /*NICResetFromError(pAd); */ - - RTMPRingCleanUp(pAd, QID_AC_BK); - RTMPRingCleanUp(pAd, QID_AC_BE); - RTMPRingCleanUp(pAd, QID_AC_VI); - RTMPRingCleanUp(pAd, QID_AC_VO); - RTMPRingCleanUp(pAd, QID_MGMT); - RTMPRingCleanUp(pAd, QID_RX); - - /* Enable Tx/Rx */ - RTMPEnableRxTx(pAd); - - /* Clear Radio off flag */ - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); - - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF); - - /* Set LED */ - RTMPSetLED(pAd, LED_RADIO_ON); - } - - if ((pAd->OpMode == OPMODE_STA) && - (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) { - BOOLEAN Cancelled; - - RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_WAKEUP); - - pAd->Mlme.bPsPollTimerRunning = FALSE; - RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); - RTMPCancelTimer(&pAd->Mlme.RadioOnOffTimer, &Cancelled); - RTMPSetTimer(&pAd->Mlme.RadioOnOffTimer, 40); - } -} - -void RT28xxPciMlmeRadioOFF(struct rt_rtmp_adapter *pAd) -{ - BOOLEAN brc = TRUE; - - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) - return; - - /* Link down first if any association exists */ - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) { - if (INFRA_ON(pAd) || ADHOC_ON(pAd)) { - struct rt_mlme_disassoc_req DisReq; - struct rt_mlme_queue_elem *pMsgElem = - kmalloc(sizeof(struct rt_mlme_queue_elem), - MEM_ALLOC_FLAG); - - if (pMsgElem) { - COPY_MAC_ADDR(&DisReq.Addr, - pAd->CommonCfg.Bssid); - DisReq.Reason = REASON_DISASSOC_STA_LEAVING; - - pMsgElem->Machine = ASSOC_STATE_MACHINE; - pMsgElem->MsgType = MT2_MLME_DISASSOC_REQ; - pMsgElem->MsgLen = - sizeof(struct rt_mlme_disassoc_req); - NdisMoveMemory(pMsgElem->Msg, &DisReq, - sizeof - (struct rt_mlme_disassoc_req)); - - MlmeDisassocReqAction(pAd, pMsgElem); - kfree(pMsgElem); - - RTMPusecDelay(1000); - } - } - } - - DBGPRINT(RT_DEBUG_TRACE, ("%s===>\n", __func__)); - - /* Set Radio off flag */ - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); - - { - BOOLEAN Cancelled; - if (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) { - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) { - RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, - &Cancelled); - RTMP_CLEAR_FLAG(pAd, - fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS); - } - /* If during power safe mode. */ - if (pAd->StaCfg.bRadio == TRUE) { - DBGPRINT(RT_DEBUG_TRACE, - ("-->MlmeRadioOff() return on bRadio == TRUE; \n")); - return; - } - /* Always radio on since the NIC needs to set the MCU command (LED_RADIO_OFF). */ - if (IDLE_ON(pAd) && - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))) - { - RT28xxPciAsicRadioOn(pAd, GUI_IDLE_POWER_SAVE); - } - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) { - BOOLEAN Cancelled; - pAd->Mlme.bPsPollTimerRunning = FALSE; - RTMPCancelTimer(&pAd->Mlme.PsPollTimer, - &Cancelled); - RTMPCancelTimer(&pAd->Mlme.RadioOnOffTimer, - &Cancelled); - } - } - /* Link down first if any association exists */ - if (INFRA_ON(pAd) || ADHOC_ON(pAd)) - LinkDown(pAd, FALSE); - RTMPusecDelay(10000); - /*========================================== */ - /* Clean up old bss table */ - BssTableInit(&pAd->ScanTab); - - /* - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) - { - RTMPSetTimer(&pAd->Mlme.RadioOnOffTimer, 10); - return; - } - */ - } - - /* Set LED.Move to here for fixing LED bug. This flag must be called after LinkDown */ - RTMPSetLED(pAd, LED_RADIO_OFF); - -/*KH Debug:All PCIe devices need to use timer to execute radio off function, or the PCIe&&EnableNewPS needs. */ -/*KH Ans:It is right, because only when the PCIe and EnableNewPs is true, we need to delay the RadioOffTimer */ -/*to avoid the deadlock with PCIe Power saving function. */ - if (pAd->OpMode == OPMODE_STA && - OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE) && - pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) { - RTMPSetTimer(&pAd->Mlme.RadioOnOffTimer, 10); - } else { - brc = RT28xxPciAsicRadioOff(pAd, GUIRADIO_OFF, 0); - - if (brc == FALSE) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s call RT28xxPciAsicRadioOff fail!\n", - __func__)); - } - } -/* -*/ -} - -#endif /* RTMP_MAC_PCI // */ diff --git a/trunk/drivers/staging/rt2860/common/cmm_mac_usb.c b/trunk/drivers/staging/rt2860/common/cmm_mac_usb.c deleted file mode 100644 index 64a65a460c29..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_mac_usb.c +++ /dev/null @@ -1,1162 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* -*/ - -#ifdef RTMP_MAC_USB - -#include "../rt_config.h" - -/* -======================================================================== -Routine Description: - Initialize receive data structures. - -Arguments: - pAd Pointer to our adapter - -Return Value: - NDIS_STATUS_SUCCESS - NDIS_STATUS_RESOURCES - -Note: - Initialize all receive releated private buffer, include those define - in struct rt_rtmp_adapter structure and all private data structures. The mahor - work is to allocate buffer for each packet and chain buffer to - NDIS packet descriptor. -======================================================================== -*/ -int NICInitRecv(struct rt_rtmp_adapter *pAd) -{ - u8 i; - int Status = NDIS_STATUS_SUCCESS; - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitRecv\n")); - pObj = pObj; - - /*InterlockedExchange(&pAd->PendingRx, 0); */ - pAd->PendingRx = 0; - pAd->NextRxBulkInReadIndex = 0; /* Next Rx Read index */ - pAd->NextRxBulkInIndex = 0; /*RX_RING_SIZE -1; // Rx Bulk pointer */ - pAd->NextRxBulkInPosition = 0; - - for (i = 0; i < (RX_RING_SIZE); i++) { - struct rt_rx_context *pRxContext = &(pAd->RxContext[i]); - - /*Allocate URB */ - pRxContext->pUrb = RTUSB_ALLOC_URB(0); - if (pRxContext->pUrb == NULL) { - Status = NDIS_STATUS_RESOURCES; - goto out1; - } - /* Allocate transfer buffer */ - pRxContext->TransferBuffer = - RTUSB_URB_ALLOC_BUFFER(pObj->pUsb_Dev, MAX_RXBULK_SIZE, - &pRxContext->data_dma); - if (pRxContext->TransferBuffer == NULL) { - Status = NDIS_STATUS_RESOURCES; - goto out1; - } - - NdisZeroMemory(pRxContext->TransferBuffer, MAX_RXBULK_SIZE); - - pRxContext->pAd = pAd; - pRxContext->pIrp = NULL; - pRxContext->InUse = FALSE; - pRxContext->IRPPending = FALSE; - pRxContext->Readable = FALSE; - /*pRxContext->ReorderInUse = FALSE; */ - pRxContext->bRxHandling = FALSE; - pRxContext->BulkInOffset = 0; - } - - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitRecv(Status=%d)\n", Status)); - return Status; - -out1: - for (i = 0; i < (RX_RING_SIZE); i++) { - struct rt_rx_context *pRxContext = &(pAd->RxContext[i]); - - if (NULL != pRxContext->TransferBuffer) { - RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, MAX_RXBULK_SIZE, - pRxContext->TransferBuffer, - pRxContext->data_dma); - pRxContext->TransferBuffer = NULL; - } - - if (NULL != pRxContext->pUrb) { - RTUSB_UNLINK_URB(pRxContext->pUrb); - RTUSB_FREE_URB(pRxContext->pUrb); - pRxContext->pUrb = NULL; - } - } - - return Status; -} - -/* -======================================================================== -Routine Description: - Initialize transmit data structures. - -Arguments: - pAd Pointer to our adapter - -Return Value: - NDIS_STATUS_SUCCESS - NDIS_STATUS_RESOURCES - -Note: -======================================================================== -*/ -int NICInitTransmit(struct rt_rtmp_adapter *pAd) -{ -#define LM_USB_ALLOC(pObj, Context, TB_Type, BufferSize, Status, msg1, err1, msg2, err2) \ - Context->pUrb = RTUSB_ALLOC_URB(0); \ - if (Context->pUrb == NULL) { \ - DBGPRINT(RT_DEBUG_ERROR, msg1); \ - Status = NDIS_STATUS_RESOURCES; \ - goto err1; } \ - \ - Context->TransferBuffer = \ - (TB_Type)RTUSB_URB_ALLOC_BUFFER(pObj->pUsb_Dev, BufferSize, &Context->data_dma); \ - if (Context->TransferBuffer == NULL) { \ - DBGPRINT(RT_DEBUG_ERROR, msg2); \ - Status = NDIS_STATUS_RESOURCES; \ - goto err2; } - -#define LM_URB_FREE(pObj, Context, BufferSize) \ - if (NULL != Context->pUrb) { \ - RTUSB_UNLINK_URB(Context->pUrb); \ - RTUSB_FREE_URB(Context->pUrb); \ - Context->pUrb = NULL; } \ - if (NULL != Context->TransferBuffer) { \ - RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, BufferSize, \ - Context->TransferBuffer, \ - Context->data_dma); \ - Context->TransferBuffer = NULL; } - - u8 i, acidx; - int Status = NDIS_STATUS_SUCCESS; - struct rt_tx_context *pNullContext = &(pAd->NullContext); - struct rt_tx_context *pPsPollContext = &(pAd->PsPollContext); - struct rt_tx_context *pRTSContext = &(pAd->RTSContext); - struct rt_tx_context *pMLMEContext = NULL; -/* struct rt_ht_tx_context *pHTTXContext = NULL; */ - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - void *RingBaseVa; -/* struct rt_rtmp_tx_ring *pTxRing; */ - struct rt_rtmp_mgmt_ring *pMgmtRing; - - DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitTransmit\n")); - pObj = pObj; - - /* Init 4 set of Tx parameters */ - for (acidx = 0; acidx < NUM_OF_TX_RING; acidx++) { - /* Initialize all Transmit releated queues */ - InitializeQueueHeader(&pAd->TxSwQueue[acidx]); - - /* Next Local tx ring pointer waiting for buck out */ - pAd->NextBulkOutIndex[acidx] = acidx; - pAd->BulkOutPending[acidx] = FALSE; /* Buck Out control flag */ - /*pAd->DataBulkDoneIdx[acidx] = 0; */ - } - - /*pAd->NextMLMEIndex = 0; */ - /*pAd->PushMgmtIndex = 0; */ - /*pAd->PopMgmtIndex = 0; */ - /*InterlockedExchange(&pAd->MgmtQueueSize, 0); */ - /*InterlockedExchange(&pAd->TxCount, 0); */ - - /*pAd->PrioRingFirstIndex = 0; */ - /*pAd->PrioRingTxCnt = 0; */ - - do { - /* */ - /* TX_RING_SIZE, 4 ACs */ - /* */ - for (acidx = 0; acidx < 4; acidx++) { - struct rt_ht_tx_context *pHTTXContext = &(pAd->TxContext[acidx]); - - NdisZeroMemory(pHTTXContext, sizeof(struct rt_ht_tx_context)); - /*Allocate URB */ - LM_USB_ALLOC(pObj, pHTTXContext, struct rt_httx_buffer *, - sizeof(struct rt_httx_buffer), Status, - ("<-- ERROR in Alloc TX TxContext[%d] urb!\n", - acidx), done, - ("<-- ERROR in Alloc TX TxContext[%d] struct rt_httx_buffer!\n", - acidx), out1); - - NdisZeroMemory(pHTTXContext->TransferBuffer-> - Aggregation, 4); - pHTTXContext->pAd = pAd; - pHTTXContext->pIrp = NULL; - pHTTXContext->IRPPending = FALSE; - pHTTXContext->NextBulkOutPosition = 0; - pHTTXContext->ENextBulkOutPosition = 0; - pHTTXContext->CurWritePosition = 0; - pHTTXContext->CurWriteRealPos = 0; - pHTTXContext->BulkOutSize = 0; - pHTTXContext->BulkOutPipeId = acidx; - pHTTXContext->bRingEmpty = TRUE; - pHTTXContext->bCopySavePad = FALSE; - pAd->BulkOutPending[acidx] = FALSE; - } - - /* */ - /* MGMT_RING_SIZE */ - /* */ - - /* Allocate MGMT ring descriptor's memory */ - pAd->MgmtDescRing.AllocSize = - MGMT_RING_SIZE * sizeof(struct rt_tx_context); - os_alloc_mem(pAd, (u8 **) (&pAd->MgmtDescRing.AllocVa), - pAd->MgmtDescRing.AllocSize); - if (pAd->MgmtDescRing.AllocVa == NULL) { - DBGPRINT_ERR("Failed to allocate a big buffer for MgmtDescRing!\n"); - Status = NDIS_STATUS_RESOURCES; - goto out1; - } - NdisZeroMemory(pAd->MgmtDescRing.AllocVa, - pAd->MgmtDescRing.AllocSize); - RingBaseVa = pAd->MgmtDescRing.AllocVa; - - /* Initialize MGMT Ring and associated buffer memory */ - pMgmtRing = &pAd->MgmtRing; - for (i = 0; i < MGMT_RING_SIZE; i++) { - /* link the pre-allocated Mgmt buffer to MgmtRing.Cell */ - pMgmtRing->Cell[i].AllocSize = sizeof(struct rt_tx_context); - pMgmtRing->Cell[i].AllocVa = RingBaseVa; - pMgmtRing->Cell[i].pNdisPacket = NULL; - pMgmtRing->Cell[i].pNextNdisPacket = NULL; - - /*Allocate URB for MLMEContext */ - pMLMEContext = - (struct rt_tx_context *)pAd->MgmtRing.Cell[i].AllocVa; - pMLMEContext->pUrb = RTUSB_ALLOC_URB(0); - if (pMLMEContext->pUrb == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("<-- ERROR in Alloc TX MLMEContext[%d] urb!\n", - i)); - Status = NDIS_STATUS_RESOURCES; - goto out2; - } - pMLMEContext->pAd = pAd; - pMLMEContext->pIrp = NULL; - pMLMEContext->TransferBuffer = NULL; - pMLMEContext->InUse = FALSE; - pMLMEContext->IRPPending = FALSE; - pMLMEContext->bWaitingBulkOut = FALSE; - pMLMEContext->BulkOutSize = 0; - pMLMEContext->SelfIdx = i; - - /* Offset to next ring descriptor address */ - RingBaseVa = (u8 *)RingBaseVa + sizeof(struct rt_tx_context); - } - DBGPRINT(RT_DEBUG_TRACE, - ("MGMT Ring: total %d entry allocated\n", i)); - - /*pAd->MgmtRing.TxSwFreeIdx = (MGMT_RING_SIZE - 1); */ - pAd->MgmtRing.TxSwFreeIdx = MGMT_RING_SIZE; - pAd->MgmtRing.TxCpuIdx = 0; - pAd->MgmtRing.TxDmaIdx = 0; - - /* */ - /* BEACON_RING_SIZE */ - /* */ - for (i = 0; i < BEACON_RING_SIZE; i++) /* 2 */ - { - struct rt_tx_context *pBeaconContext = &(pAd->BeaconContext[i]); - - NdisZeroMemory(pBeaconContext, sizeof(struct rt_tx_context)); - - /*Allocate URB */ - LM_USB_ALLOC(pObj, pBeaconContext, struct rt_tx_buffer *, - sizeof(struct rt_tx_buffer), Status, - ("<-- ERROR in Alloc TX BeaconContext[%d] urb!\n", - i), out2, - ("<-- ERROR in Alloc TX BeaconContext[%d] struct rt_tx_buffer!\n", - i), out3); - - pBeaconContext->pAd = pAd; - pBeaconContext->pIrp = NULL; - pBeaconContext->InUse = FALSE; - pBeaconContext->IRPPending = FALSE; - } - - /* */ - /* NullContext */ - /* */ - NdisZeroMemory(pNullContext, sizeof(struct rt_tx_context)); - - /*Allocate URB */ - LM_USB_ALLOC(pObj, pNullContext, struct rt_tx_buffer *, sizeof(struct rt_tx_buffer), - Status, - ("<-- ERROR in Alloc TX NullContext urb!\n"), - out3, - ("<-- ERROR in Alloc TX NullContext struct rt_tx_buffer!\n"), - out4); - - pNullContext->pAd = pAd; - pNullContext->pIrp = NULL; - pNullContext->InUse = FALSE; - pNullContext->IRPPending = FALSE; - - /* */ - /* RTSContext */ - /* */ - NdisZeroMemory(pRTSContext, sizeof(struct rt_tx_context)); - - /*Allocate URB */ - LM_USB_ALLOC(pObj, pRTSContext, struct rt_tx_buffer *, sizeof(struct rt_tx_buffer), - Status, - ("<-- ERROR in Alloc TX RTSContext urb!\n"), - out4, - ("<-- ERROR in Alloc TX RTSContext struct rt_tx_buffer!\n"), - out5); - - pRTSContext->pAd = pAd; - pRTSContext->pIrp = NULL; - pRTSContext->InUse = FALSE; - pRTSContext->IRPPending = FALSE; - - /* */ - /* PsPollContext */ - /* */ - /*NdisZeroMemory(pPsPollContext, sizeof(struct rt_tx_context)); */ - /*Allocate URB */ - LM_USB_ALLOC(pObj, pPsPollContext, struct rt_tx_buffer *, - sizeof(struct rt_tx_buffer), Status, - ("<-- ERROR in Alloc TX PsPollContext urb!\n"), - out5, - ("<-- ERROR in Alloc TX PsPollContext struct rt_tx_buffer!\n"), - out6); - - pPsPollContext->pAd = pAd; - pPsPollContext->pIrp = NULL; - pPsPollContext->InUse = FALSE; - pPsPollContext->IRPPending = FALSE; - pPsPollContext->bAggregatible = FALSE; - pPsPollContext->LastOne = TRUE; - - } while (FALSE); - -done: - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitTransmit(Status=%d)\n", Status)); - - return Status; - - /* --------------------------- ERROR HANDLE --------------------------- */ -out6: - LM_URB_FREE(pObj, pPsPollContext, sizeof(struct rt_tx_buffer)); - -out5: - LM_URB_FREE(pObj, pRTSContext, sizeof(struct rt_tx_buffer)); - -out4: - LM_URB_FREE(pObj, pNullContext, sizeof(struct rt_tx_buffer)); - -out3: - for (i = 0; i < BEACON_RING_SIZE; i++) { - struct rt_tx_context *pBeaconContext = &(pAd->BeaconContext[i]); - if (pBeaconContext) - LM_URB_FREE(pObj, pBeaconContext, sizeof(struct rt_tx_buffer)); - } - -out2: - if (pAd->MgmtDescRing.AllocVa) { - pMgmtRing = &pAd->MgmtRing; - for (i = 0; i < MGMT_RING_SIZE; i++) { - pMLMEContext = - (struct rt_tx_context *)pAd->MgmtRing.Cell[i].AllocVa; - if (pMLMEContext) - LM_URB_FREE(pObj, pMLMEContext, - sizeof(struct rt_tx_buffer)); - } - os_free_mem(pAd, pAd->MgmtDescRing.AllocVa); - pAd->MgmtDescRing.AllocVa = NULL; - } - -out1: - for (acidx = 0; acidx < 4; acidx++) { - struct rt_ht_tx_context *pTxContext = &(pAd->TxContext[acidx]); - if (pTxContext) - LM_URB_FREE(pObj, pTxContext, sizeof(struct rt_httx_buffer)); - } - - /* Here we didn't have any pre-allocated memory need to free. */ - - return Status; -} - -/* -======================================================================== -Routine Description: - Allocate DMA memory blocks for send, receive. - -Arguments: - pAd Pointer to our adapter - -Return Value: - NDIS_STATUS_SUCCESS - NDIS_STATUS_FAILURE - NDIS_STATUS_RESOURCES - -Note: -======================================================================== -*/ -int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd) -{ -/* struct rt_counter_802_11 pCounter = &pAd->WlanCounters; */ - int Status; - int num; - - DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocTxRxRingMemory\n")); - - do { - /* Init the struct rt_cmdq and CmdQLock */ - NdisAllocateSpinLock(&pAd->CmdQLock); - NdisAcquireSpinLock(&pAd->CmdQLock); - RTUSBInitializeCmdQ(&pAd->CmdQ); - NdisReleaseSpinLock(&pAd->CmdQLock); - - NdisAllocateSpinLock(&pAd->MLMEBulkOutLock); - /*NdisAllocateSpinLock(&pAd->MLMEWaitQueueLock); */ - NdisAllocateSpinLock(&pAd->BulkOutLock[0]); - NdisAllocateSpinLock(&pAd->BulkOutLock[1]); - NdisAllocateSpinLock(&pAd->BulkOutLock[2]); - NdisAllocateSpinLock(&pAd->BulkOutLock[3]); - NdisAllocateSpinLock(&pAd->BulkOutLock[4]); - NdisAllocateSpinLock(&pAd->BulkOutLock[5]); - NdisAllocateSpinLock(&pAd->BulkInLock); - - for (num = 0; num < NUM_OF_TX_RING; num++) { - NdisAllocateSpinLock(&pAd->TxContextQueueLock[num]); - } - -/* NdisAllocateSpinLock(&pAd->MemLock); // Not used in RT28XX */ - -/* NdisAllocateSpinLock(&pAd->MacTabLock); // init it in UserCfgInit() */ -/* NdisAllocateSpinLock(&pAd->BATabLock); // init it in BATableInit() */ - -/* for(num=0; numBATable.BARecEntry[num].RxReRingLock); */ -/* } */ - - /* */ - /* Init Mac Table */ - /* */ -/* MacTableInitialize(pAd); */ - - /* */ - /* Init send data structures and related parameters */ - /* */ - Status = NICInitTransmit(pAd); - if (Status != NDIS_STATUS_SUCCESS) - break; - - /* */ - /* Init receive data structures and related parameters */ - /* */ - Status = NICInitRecv(pAd); - if (Status != NDIS_STATUS_SUCCESS) - break; - - pAd->PendingIoCount = 1; - - } while (FALSE); - - NdisZeroMemory(&pAd->FragFrame, sizeof(struct rt_fragment_frame)); - pAd->FragFrame.pFragPacket = - RTMP_AllocateFragPacketBuffer(pAd, RX_BUFFER_NORMSIZE); - - if (pAd->FragFrame.pFragPacket == NULL) { - Status = NDIS_STATUS_RESOURCES; - } - - DBGPRINT_S(Status, - ("<-- RTMPAllocTxRxRingMemory, Status=%x\n", Status)); - return Status; -} - -/* -======================================================================== -Routine Description: - Calls USB_InterfaceStop and frees memory allocated for the URBs - calls NdisMDeregisterDevice and frees the memory - allocated in VNetInitialize for the Adapter Object - -Arguments: - *pAd the raxx interface data pointer - -Return Value: - None - -Note: -======================================================================== -*/ -void RTMPFreeTxRxRingMemory(struct rt_rtmp_adapter *pAd) -{ -#define LM_URB_FREE(pObj, Context, BufferSize) \ - if (NULL != Context->pUrb) { \ - RTUSB_UNLINK_URB(Context->pUrb); \ - RTUSB_FREE_URB(Context->pUrb); \ - Context->pUrb = NULL; } \ - if (NULL != Context->TransferBuffer) { \ - RTUSB_URB_FREE_BUFFER(pObj->pUsb_Dev, BufferSize, \ - Context->TransferBuffer, \ - Context->data_dma); \ - Context->TransferBuffer = NULL; } - - u32 i, acidx; - struct rt_tx_context *pNullContext = &pAd->NullContext; - struct rt_tx_context *pPsPollContext = &pAd->PsPollContext; - struct rt_tx_context *pRTSContext = &pAd->RTSContext; -/* struct rt_ht_tx_context *pHTTXContext; */ - /*PRTMP_REORDERBUF pReorderBuf; */ - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; -/* struct rt_rtmp_tx_ring *pTxRing; */ - - DBGPRINT(RT_DEBUG_ERROR, ("---> RTMPFreeTxRxRingMemory\n")); - pObj = pObj; - - /* Free all resources for the RECEIVE buffer queue. */ - for (i = 0; i < (RX_RING_SIZE); i++) { - struct rt_rx_context *pRxContext = &(pAd->RxContext[i]); - if (pRxContext) - LM_URB_FREE(pObj, pRxContext, MAX_RXBULK_SIZE); - } - - /* Free PsPoll frame resource */ - LM_URB_FREE(pObj, pPsPollContext, sizeof(struct rt_tx_buffer)); - - /* Free NULL frame resource */ - LM_URB_FREE(pObj, pNullContext, sizeof(struct rt_tx_buffer)); - - /* Free RTS frame resource */ - LM_URB_FREE(pObj, pRTSContext, sizeof(struct rt_tx_buffer)); - - /* Free beacon frame resource */ - for (i = 0; i < BEACON_RING_SIZE; i++) { - struct rt_tx_context *pBeaconContext = &(pAd->BeaconContext[i]); - if (pBeaconContext) - LM_URB_FREE(pObj, pBeaconContext, sizeof(struct rt_tx_buffer)); - } - - /* Free mgmt frame resource */ - for (i = 0; i < MGMT_RING_SIZE; i++) { - struct rt_tx_context *pMLMEContext = - (struct rt_tx_context *)pAd->MgmtRing.Cell[i].AllocVa; - /*LM_URB_FREE(pObj, pMLMEContext, sizeof(struct rt_tx_buffer)); */ - if (NULL != pAd->MgmtRing.Cell[i].pNdisPacket) { - RTMPFreeNdisPacket(pAd, - pAd->MgmtRing.Cell[i].pNdisPacket); - pAd->MgmtRing.Cell[i].pNdisPacket = NULL; - pMLMEContext->TransferBuffer = NULL; - } - - if (pMLMEContext) { - if (NULL != pMLMEContext->pUrb) { - RTUSB_UNLINK_URB(pMLMEContext->pUrb); - RTUSB_FREE_URB(pMLMEContext->pUrb); - pMLMEContext->pUrb = NULL; - } - } - } - if (pAd->MgmtDescRing.AllocVa) - os_free_mem(pAd, pAd->MgmtDescRing.AllocVa); - - /* Free Tx frame resource */ - for (acidx = 0; acidx < 4; acidx++) { - struct rt_ht_tx_context *pHTTXContext = &(pAd->TxContext[acidx]); - if (pHTTXContext) - LM_URB_FREE(pObj, pHTTXContext, sizeof(struct rt_httx_buffer)); - } - - if (pAd->FragFrame.pFragPacket) - RELEASE_NDIS_PACKET(pAd, pAd->FragFrame.pFragPacket, - NDIS_STATUS_SUCCESS); - - for (i = 0; i < 6; i++) { - NdisFreeSpinLock(&pAd->BulkOutLock[i]); - } - - NdisFreeSpinLock(&pAd->BulkInLock); - NdisFreeSpinLock(&pAd->MLMEBulkOutLock); - - NdisFreeSpinLock(&pAd->CmdQLock); - /* Clear all pending bulk-out request flags. */ - RTUSB_CLEAR_BULK_FLAG(pAd, 0xffffffff); - -/* NdisFreeSpinLock(&pAd->MacTabLock); */ - -/* for(i=0; iBATable.BARecEntry[i].RxReRingLock); */ -/* } */ - - DBGPRINT(RT_DEBUG_ERROR, ("<--- RTMPFreeTxRxRingMemory\n")); -} - -/* -======================================================================== -Routine Description: - Write WLAN MAC address to USB 2870. - -Arguments: - pAd Pointer to our adapter - -Return Value: - NDIS_STATUS_SUCCESS - -Note: -======================================================================== -*/ -int RTUSBWriteHWMACAddress(struct rt_rtmp_adapter *pAd) -{ - MAC_DW0_STRUC StaMacReg0; - MAC_DW1_STRUC StaMacReg1; - int Status = NDIS_STATUS_SUCCESS; - LARGE_INTEGER NOW; - - /* initialize the random number generator */ - RTMP_GetCurrentSystemTime(&NOW); - - if (pAd->bLocalAdminMAC != TRUE) { - pAd->CurrentAddress[0] = pAd->PermanentAddress[0]; - pAd->CurrentAddress[1] = pAd->PermanentAddress[1]; - pAd->CurrentAddress[2] = pAd->PermanentAddress[2]; - pAd->CurrentAddress[3] = pAd->PermanentAddress[3]; - pAd->CurrentAddress[4] = pAd->PermanentAddress[4]; - pAd->CurrentAddress[5] = pAd->PermanentAddress[5]; - } - /* Write New MAC address to MAC_CSR2 & MAC_CSR3 & let ASIC know our new MAC */ - StaMacReg0.field.Byte0 = pAd->CurrentAddress[0]; - StaMacReg0.field.Byte1 = pAd->CurrentAddress[1]; - StaMacReg0.field.Byte2 = pAd->CurrentAddress[2]; - StaMacReg0.field.Byte3 = pAd->CurrentAddress[3]; - StaMacReg1.field.Byte4 = pAd->CurrentAddress[4]; - StaMacReg1.field.Byte5 = pAd->CurrentAddress[5]; - StaMacReg1.field.U2MeMask = 0xff; - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("Local MAC = %pM\n", pAd->CurrentAddress)); - - RTUSBWriteMACRegister(pAd, MAC_ADDR_DW0, StaMacReg0.word); - RTUSBWriteMACRegister(pAd, MAC_ADDR_DW1, StaMacReg1.word); - return Status; -} - -/* -======================================================================== -Routine Description: - Disable DMA. - -Arguments: - *pAd the raxx interface data pointer - -Return Value: - None - -Note: -======================================================================== -*/ -void RT28XXDMADisable(struct rt_rtmp_adapter *pAd) -{ - /* no use */ -} - -/* -======================================================================== -Routine Description: - Enable DMA. - -Arguments: - *pAd the raxx interface data pointer - -Return Value: - None - -Note: -======================================================================== -*/ -void RT28XXDMAEnable(struct rt_rtmp_adapter *pAd) -{ - WPDMA_GLO_CFG_STRUC GloCfg; - USB_DMA_CFG_STRUC UsbCfg; - int i = 0; - - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x4); - do { - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); - if ((GloCfg.field.TxDMABusy == 0) - && (GloCfg.field.RxDMABusy == 0)) - break; - - DBGPRINT(RT_DEBUG_TRACE, ("==> DMABusy\n")); - RTMPusecDelay(1000); - i++; - } while (i < 200); - - RTMPusecDelay(50); - GloCfg.field.EnTXWriteBackDDONE = 1; - GloCfg.field.EnableRxDMA = 1; - GloCfg.field.EnableTxDMA = 1; - DBGPRINT(RT_DEBUG_TRACE, - ("<== WRITE DMA offset 0x208 = 0x%x\n", GloCfg.word)); - RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word); - - UsbCfg.word = 0; - UsbCfg.field.phyclear = 0; - /* usb version is 1.1,do not use bulk in aggregation */ - if (pAd->BulkInMaxPacketSize == 512) - UsbCfg.field.RxBulkAggEn = 1; - /* for last packet, PBF might use more than limited, so minus 2 to prevent from error */ - UsbCfg.field.RxBulkAggLmt = (MAX_RXBULK_SIZE / 1024) - 3; - UsbCfg.field.RxBulkAggTOut = 0x80; /* 2006-10-18 */ - UsbCfg.field.RxBulkEn = 1; - UsbCfg.field.TxBulkEn = 1; - - RTUSBWriteMACRegister(pAd, USB_DMA_CFG, UsbCfg.word); - -} - -/******************************************************************** - * - * 2870 Beacon Update Related functions. - * - ********************************************************************/ - -/* -======================================================================== -Routine Description: - Write Beacon buffer to Asic. - -Arguments: - *pAd the raxx interface data pointer - -Return Value: - None - -Note: -======================================================================== -*/ -void RT28xx_UpdateBeaconToAsic(struct rt_rtmp_adapter *pAd, - int apidx, - unsigned long FrameLen, unsigned long UpdatePos) -{ - u8 *pBeaconFrame = NULL; - u8 *ptr; - u32 i, padding; - struct rt_beacon_sync *pBeaconSync = pAd->CommonCfg.pBeaconSync; - u32 longValue; -/* u16 shortValue; */ - BOOLEAN bBcnReq = FALSE; - u8 bcn_idx = 0; - - if (pBeaconFrame == NULL) { - DBGPRINT(RT_DEBUG_ERROR, ("pBeaconFrame is NULL!\n")); - return; - } - - if (pBeaconSync == NULL) { - DBGPRINT(RT_DEBUG_ERROR, ("pBeaconSync is NULL!\n")); - return; - } - /*if ((pAd->WdsTab.Mode == WDS_BRIDGE_MODE) || */ - /* ((pAd->ApCfg.MBSSID[apidx].MSSIDDev == NULL) || !(pAd->ApCfg.MBSSID[apidx].MSSIDDev->flags & IFF_UP)) */ - /* ) */ - if (bBcnReq == FALSE) { - /* when the ra interface is down, do not send its beacon frame */ - /* clear all zero */ - for (i = 0; i < TXWI_SIZE; i += 4) { - RTMP_IO_WRITE32(pAd, pAd->BeaconOffset[bcn_idx] + i, - 0x00); - } - pBeaconSync->BeaconBitMap &= - (~(BEACON_BITMAP_MASK & (1 << bcn_idx))); - NdisZeroMemory(pBeaconSync->BeaconTxWI[bcn_idx], TXWI_SIZE); - } else { - ptr = (u8 *)& pAd->BeaconTxWI; - if (NdisEqualMemory(pBeaconSync->BeaconTxWI[bcn_idx], &pAd->BeaconTxWI, TXWI_SIZE) == FALSE) { /* If BeaconTxWI changed, we need to rewrite the TxWI for the Beacon frames. */ - pBeaconSync->BeaconBitMap &= - (~(BEACON_BITMAP_MASK & (1 << bcn_idx))); - NdisMoveMemory(pBeaconSync->BeaconTxWI[bcn_idx], - &pAd->BeaconTxWI, TXWI_SIZE); - } - - if ((pBeaconSync->BeaconBitMap & (1 << bcn_idx)) != - (1 << bcn_idx)) { - for (i = 0; i < TXWI_SIZE; i += 4) /* 16-byte TXWI field */ - { - longValue = - *ptr + (*(ptr + 1) << 8) + - (*(ptr + 2) << 16) + (*(ptr + 3) << 24); - RTMP_IO_WRITE32(pAd, - pAd->BeaconOffset[bcn_idx] + i, - longValue); - ptr += 4; - } - } - - ptr = pBeaconSync->BeaconBuf[bcn_idx]; - padding = (FrameLen & 0x01); - NdisZeroMemory((u8 *)(pBeaconFrame + FrameLen), padding); - FrameLen += padding; - for (i = 0; i < FrameLen /*HW_BEACON_OFFSET */ ; i += 2) { - if (NdisEqualMemory(ptr, pBeaconFrame, 2) == FALSE) { - NdisMoveMemory(ptr, pBeaconFrame, 2); - /*shortValue = *ptr + (*(ptr+1)<<8); */ - /*RTMP_IO_WRITE8(pAd, pAd->BeaconOffset[bcn_idx] + TXWI_SIZE + i, shortValue); */ - RTUSBMultiWrite(pAd, - pAd->BeaconOffset[bcn_idx] + - TXWI_SIZE + i, ptr, 2); - } - ptr += 2; - pBeaconFrame += 2; - } - - pBeaconSync->BeaconBitMap |= (1 << bcn_idx); - - /* For AP interface, set the DtimBitOn so that we can send Bcast/Mcast frame out after this beacon frame. */ - } - -} - -void RTUSBBssBeaconStop(struct rt_rtmp_adapter *pAd) -{ - struct rt_beacon_sync *pBeaconSync; - int i, offset; - BOOLEAN Cancelled = TRUE; - - pBeaconSync = pAd->CommonCfg.pBeaconSync; - if (pBeaconSync && pBeaconSync->EnableBeacon) { - int NumOfBcn; - - { - NumOfBcn = MAX_MESH_NUM; - } - - RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled); - - for (i = 0; i < NumOfBcn; i++) { - NdisZeroMemory(pBeaconSync->BeaconBuf[i], - HW_BEACON_OFFSET); - NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE); - - for (offset = 0; offset < HW_BEACON_OFFSET; offset += 4) - RTMP_IO_WRITE32(pAd, - pAd->BeaconOffset[i] + offset, - 0x00); - - pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0; - pBeaconSync->TimIELocationInBeacon[i] = 0; - } - pBeaconSync->BeaconBitMap = 0; - pBeaconSync->DtimBitOn = 0; - } -} - -void RTUSBBssBeaconStart(struct rt_rtmp_adapter *pAd) -{ - int apidx; - struct rt_beacon_sync *pBeaconSync; -/* LARGE_INTEGER tsfTime, deltaTime; */ - - pBeaconSync = pAd->CommonCfg.pBeaconSync; - if (pBeaconSync && pBeaconSync->EnableBeacon) { - int NumOfBcn; - - { - NumOfBcn = MAX_MESH_NUM; - } - - for (apidx = 0; apidx < NumOfBcn; apidx++) { - u8 CapabilityInfoLocationInBeacon = 0; - u8 TimIELocationInBeacon = 0; - - NdisZeroMemory(pBeaconSync->BeaconBuf[apidx], - HW_BEACON_OFFSET); - pBeaconSync->CapabilityInfoLocationInBeacon[apidx] = - CapabilityInfoLocationInBeacon; - pBeaconSync->TimIELocationInBeacon[apidx] = - TimIELocationInBeacon; - NdisZeroMemory(pBeaconSync->BeaconTxWI[apidx], - TXWI_SIZE); - } - pBeaconSync->BeaconBitMap = 0; - pBeaconSync->DtimBitOn = 0; - pAd->CommonCfg.BeaconUpdateTimer.Repeat = TRUE; - - pAd->CommonCfg.BeaconAdjust = 0; - pAd->CommonCfg.BeaconFactor = - 0xffffffff / (pAd->CommonCfg.BeaconPeriod << 10); - pAd->CommonCfg.BeaconRemain = - (0xffffffff % (pAd->CommonCfg.BeaconPeriod << 10)) + 1; - DBGPRINT(RT_DEBUG_TRACE, - ("RTUSBBssBeaconStart:BeaconFactor=%d, BeaconRemain=%d!\n", - pAd->CommonCfg.BeaconFactor, - pAd->CommonCfg.BeaconRemain)); - RTMPSetTimer(&pAd->CommonCfg.BeaconUpdateTimer, - 10 /*pAd->CommonCfg.BeaconPeriod */ ); - - } -} - -void RTUSBBssBeaconInit(struct rt_rtmp_adapter *pAd) -{ - struct rt_beacon_sync *pBeaconSync; - int i; - - os_alloc_mem(pAd, (u8 **) (&pAd->CommonCfg.pBeaconSync), - sizeof(struct rt_beacon_sync)); - /*NdisAllocMemory(pAd->CommonCfg.pBeaconSync, sizeof(struct rt_beacon_sync), MEM_ALLOC_FLAG); */ - if (pAd->CommonCfg.pBeaconSync) { - pBeaconSync = pAd->CommonCfg.pBeaconSync; - NdisZeroMemory(pBeaconSync, sizeof(struct rt_beacon_sync)); - for (i = 0; i < HW_BEACON_MAX_COUNT; i++) { - NdisZeroMemory(pBeaconSync->BeaconBuf[i], - HW_BEACON_OFFSET); - pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0; - pBeaconSync->TimIELocationInBeacon[i] = 0; - NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE); - } - pBeaconSync->BeaconBitMap = 0; - - /*RTMPInitTimer(pAd, &pAd->CommonCfg.BeaconUpdateTimer, GET_TIMER_FUNCTION(BeaconUpdateExec), pAd, TRUE); */ - pBeaconSync->EnableBeacon = TRUE; - } -} - -void RTUSBBssBeaconExit(struct rt_rtmp_adapter *pAd) -{ - struct rt_beacon_sync *pBeaconSync; - BOOLEAN Cancelled = TRUE; - int i; - - if (pAd->CommonCfg.pBeaconSync) { - pBeaconSync = pAd->CommonCfg.pBeaconSync; - pBeaconSync->EnableBeacon = FALSE; - RTMPCancelTimer(&pAd->CommonCfg.BeaconUpdateTimer, &Cancelled); - pBeaconSync->BeaconBitMap = 0; - - for (i = 0; i < HW_BEACON_MAX_COUNT; i++) { - NdisZeroMemory(pBeaconSync->BeaconBuf[i], - HW_BEACON_OFFSET); - pBeaconSync->CapabilityInfoLocationInBeacon[i] = 0; - pBeaconSync->TimIELocationInBeacon[i] = 0; - NdisZeroMemory(pBeaconSync->BeaconTxWI[i], TXWI_SIZE); - } - - os_free_mem(pAd, pAd->CommonCfg.pBeaconSync); - pAd->CommonCfg.pBeaconSync = NULL; - } -} - -/* - ======================================================================== - Routine Description: - For device work as AP mode but didn't have TBTT interrupt event, we need a mechanism - to update the beacon context in each Beacon interval. Here we use a periodical timer - to simulate the TBTT interrupt to handle the beacon context update. - - Arguments: - SystemSpecific1 - Not used. - FunctionContext - Pointer to our Adapter context. - SystemSpecific2 - Not used. - SystemSpecific3 - Not used. - - Return Value: - None - - ======================================================================== -*/ -void BeaconUpdateExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - LARGE_INTEGER tsfTime_a; /*, tsfTime_b, deltaTime_exp, deltaTime_ab; */ - u32 delta, delta2MS, period2US, remain, remain_low, remain_high; -/* BOOLEAN positive; */ - - if (pAd->CommonCfg.IsUpdateBeacon == TRUE) { - ReSyncBeaconTime(pAd); - - } - - RTMP_IO_READ32(pAd, TSF_TIMER_DW0, &tsfTime_a.u.LowPart); - RTMP_IO_READ32(pAd, TSF_TIMER_DW1, &tsfTime_a.u.HighPart); - - /*positive=getDeltaTime(tsfTime_a, expectedTime, &deltaTime_exp); */ - period2US = (pAd->CommonCfg.BeaconPeriod << 10); - remain_high = pAd->CommonCfg.BeaconRemain * tsfTime_a.u.HighPart; - remain_low = tsfTime_a.u.LowPart % (pAd->CommonCfg.BeaconPeriod << 10); - remain = - (remain_high + remain_low) % (pAd->CommonCfg.BeaconPeriod << 10); - delta = (pAd->CommonCfg.BeaconPeriod << 10) - remain; - - delta2MS = (delta >> 10); - if (delta2MS > 150) { - pAd->CommonCfg.BeaconUpdateTimer.TimerValue = 100; - pAd->CommonCfg.IsUpdateBeacon = FALSE; - } else { - pAd->CommonCfg.BeaconUpdateTimer.TimerValue = delta2MS + 10; - pAd->CommonCfg.IsUpdateBeacon = TRUE; - } - -} - -/******************************************************************** - * - * 2870 Radio on/off Related functions. - * - ********************************************************************/ -void RT28xxUsbMlmeRadioOn(struct rt_rtmp_adapter *pAd) -{ - struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps; - - DBGPRINT(RT_DEBUG_TRACE, ("RT28xxUsbMlmeRadioOn()\n")); - - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) - return; - - { - AsicSendCommandToMcu(pAd, 0x31, 0xff, 0x00, 0x02); - RTMPusecDelay(10000); - } - /*NICResetFromError(pAd); */ - - /* Enable Tx/Rx */ - RTMPEnableRxTx(pAd); - - if (pChipOps->AsicReverseRfFromSleepMode) - pChipOps->AsicReverseRfFromSleepMode(pAd); - - /* Clear Radio off flag */ - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); - - RTUSBBulkReceive(pAd); - - /* Set LED */ - RTMPSetLED(pAd, LED_RADIO_ON); -} - -void RT28xxUsbMlmeRadioOFF(struct rt_rtmp_adapter *pAd) -{ - WPDMA_GLO_CFG_STRUC GloCfg; - u32 Value, i; - - DBGPRINT(RT_DEBUG_TRACE, ("RT28xxUsbMlmeRadioOFF()\n")); - - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) - return; - - /* Clear PMKID cache. */ - pAd->StaCfg.SavedPMKNum = 0; - RTMPZeroMemory(pAd->StaCfg.SavedPMK, (PMKID_NO * sizeof(struct rt_bssid_info))); - - /* Link down first if any association exists */ - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) { - if (INFRA_ON(pAd) || ADHOC_ON(pAd)) { - struct rt_mlme_disassoc_req DisReq; - struct rt_mlme_queue_elem *pMsgElem = - kmalloc(sizeof(struct rt_mlme_queue_elem), - MEM_ALLOC_FLAG); - - if (pMsgElem) { - COPY_MAC_ADDR(&DisReq.Addr, - pAd->CommonCfg.Bssid); - DisReq.Reason = REASON_DISASSOC_STA_LEAVING; - - pMsgElem->Machine = ASSOC_STATE_MACHINE; - pMsgElem->MsgType = MT2_MLME_DISASSOC_REQ; - pMsgElem->MsgLen = - sizeof(struct rt_mlme_disassoc_req); - NdisMoveMemory(pMsgElem->Msg, &DisReq, - sizeof - (struct rt_mlme_disassoc_req)); - - MlmeDisassocReqAction(pAd, pMsgElem); - kfree(pMsgElem); - - RTMPusecDelay(1000); - } - } - } - /* Set Radio off flag */ - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); - - { - /* Link down first if any association exists */ - if (INFRA_ON(pAd) || ADHOC_ON(pAd)) - LinkDown(pAd, FALSE); - RTMPusecDelay(10000); - - /*========================================== */ - /* Clean up old bss table */ - BssTableInit(&pAd->ScanTab); - } - - /* Set LED */ - RTMPSetLED(pAd, LED_RADIO_OFF); - - if (pAd->CommonCfg.BBPCurrentBW == BW_40) { - /* Must using 40MHz. */ - AsicTurnOffRFClk(pAd, pAd->CommonCfg.CentralChannel); - } else { - /* Must using 20MHz. */ - AsicTurnOffRFClk(pAd, pAd->CommonCfg.Channel); - } - - /* Disable Tx/Rx DMA */ - RTUSBReadMACRegister(pAd, WPDMA_GLO_CFG, &GloCfg.word); /* disable DMA */ - GloCfg.field.EnableTxDMA = 0; - GloCfg.field.EnableRxDMA = 0; - RTUSBWriteMACRegister(pAd, WPDMA_GLO_CFG, GloCfg.word); /* abort all TX rings */ - - /* Waiting for DMA idle */ - i = 0; - do { - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); - if ((GloCfg.field.TxDMABusy == 0) - && (GloCfg.field.RxDMABusy == 0)) - break; - - RTMPusecDelay(1000); - } while (i++ < 100); - - /* Disable MAC Tx/Rx */ - RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value); - Value &= (0xfffffff3); - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value); - - { - AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02); - } -} - -#endif /* RTMP_MAC_USB // */ diff --git a/trunk/drivers/staging/rt2860/common/cmm_sanity.c b/trunk/drivers/staging/rt2860/common/cmm_sanity.c deleted file mode 100644 index 3bfb4ad00c1a..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_sanity.c +++ /dev/null @@ -1,1205 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - sanity.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - John Chang 2004-09-01 add WMM support -*/ -#include "../rt_config.h" - -extern u8 CISCO_OUI[]; - -extern u8 WPA_OUI[]; -extern u8 RSN_OUI[]; -extern u8 WME_INFO_ELEM[]; -extern u8 WME_PARM_ELEM[]; -extern u8 Ccx2QosInfo[]; -extern u8 RALINK_OUI[]; -extern u8 BROADCOM_OUI[]; -extern u8 WPS_OUI[]; - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -BOOLEAN MlmeAddBAReqSanity(struct rt_rtmp_adapter *pAd, - void * Msg, unsigned long MsgLen, u8 *pAddr2) -{ - struct rt_mlme_addba_req *pInfo; - - pInfo = (struct rt_mlme_addba_req *)Msg; - - if ((MsgLen != sizeof(struct rt_mlme_addba_req))) { - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeAddBAReqSanity fail - message length not correct.\n")); - return FALSE; - } - - if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE)) { - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeAddBAReqSanity fail - The peer Mac is not associated yet.\n")); - return FALSE; - } - - if ((pInfo->pAddr[0] & 0x01) == 0x01) { - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeAddBAReqSanity fail - broadcast address not support BA\n")); - return FALSE; - } - - return TRUE; -} - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -BOOLEAN MlmeDelBAReqSanity(struct rt_rtmp_adapter *pAd, void * Msg, unsigned long MsgLen) -{ - struct rt_mlme_delba_req *pInfo; - pInfo = (struct rt_mlme_delba_req *)Msg; - - if ((MsgLen != sizeof(struct rt_mlme_delba_req))) { - DBGPRINT(RT_DEBUG_ERROR, - ("MlmeDelBAReqSanity fail - message length not correct.\n")); - return FALSE; - } - - if ((pInfo->Wcid >= MAX_LEN_OF_MAC_TABLE)) { - DBGPRINT(RT_DEBUG_ERROR, - ("MlmeDelBAReqSanity fail - The peer Mac is not associated yet.\n")); - return FALSE; - } - - if ((pInfo->TID & 0xf0)) { - DBGPRINT(RT_DEBUG_ERROR, - ("MlmeDelBAReqSanity fail - The peer TID is incorrect.\n")); - return FALSE; - } - - if (NdisEqualMemory - (pAd->MacTab.Content[pInfo->Wcid].Addr, pInfo->Addr, - MAC_ADDR_LEN) == 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("MlmeDelBAReqSanity fail - the peer addr dosen't exist.\n")); - return FALSE; - } - - return TRUE; -} - -BOOLEAN PeerAddBAReqActionSanity(struct rt_rtmp_adapter *pAd, - void * pMsg, - unsigned long MsgLen, u8 *pAddr2) -{ - struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) pMsg; - struct rt_frame_addba_req * pAddFrame; - pAddFrame = (struct rt_frame_addba_req *) (pMsg); - if (MsgLen < (sizeof(struct rt_frame_addba_req))) { - DBGPRINT(RT_DEBUG_ERROR, - ("PeerAddBAReqActionSanity: ADDBA Request frame length size = %ld incorrect\n", - MsgLen)); - return FALSE; - } - /* we support immediate BA. */ - *(u16 *) (&pAddFrame->BaParm) = - cpu2le16(*(u16 *) (&pAddFrame->BaParm)); - pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue); - pAddFrame->BaStartSeq.word = cpu2le16(pAddFrame->BaStartSeq.word); - - if (pAddFrame->BaParm.BAPolicy != IMMED_BA) { - DBGPRINT(RT_DEBUG_ERROR, - ("PeerAddBAReqActionSanity: ADDBA Request Ba Policy[%d] not support\n", - pAddFrame->BaParm.BAPolicy)); - DBGPRINT(RT_DEBUG_ERROR, - ("ADDBA Request. tid=%x, Bufsize=%x, AMSDUSupported=%x \n", - pAddFrame->BaParm.TID, pAddFrame->BaParm.BufSize, - pAddFrame->BaParm.AMSDUSupported)); - return FALSE; - } - /* we support immediate BA. */ - if (pAddFrame->BaParm.TID & 0xfff0) { - DBGPRINT(RT_DEBUG_ERROR, - ("PeerAddBAReqActionSanity: ADDBA Request incorrect TID = %d\n", - pAddFrame->BaParm.TID)); - return FALSE; - } - COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); - return TRUE; -} - -BOOLEAN PeerAddBARspActionSanity(struct rt_rtmp_adapter *pAd, - void * pMsg, unsigned long MsgLen) -{ - struct rt_frame_addba_rsp * pAddFrame; - - pAddFrame = (struct rt_frame_addba_rsp *) (pMsg); - if (MsgLen < (sizeof(struct rt_frame_addba_rsp))) { - DBGPRINT(RT_DEBUG_ERROR, - ("PeerAddBARspActionSanity: ADDBA Response frame length size = %ld incorrect\n", - MsgLen)); - return FALSE; - } - /* we support immediate BA. */ - *(u16 *) (&pAddFrame->BaParm) = - cpu2le16(*(u16 *) (&pAddFrame->BaParm)); - pAddFrame->StatusCode = cpu2le16(pAddFrame->StatusCode); - pAddFrame->TimeOutValue = cpu2le16(pAddFrame->TimeOutValue); - - if (pAddFrame->BaParm.BAPolicy != IMMED_BA) { - DBGPRINT(RT_DEBUG_ERROR, - ("PeerAddBAReqActionSanity: ADDBA Response Ba Policy[%d] not support\n", - pAddFrame->BaParm.BAPolicy)); - return FALSE; - } - /* we support immediate BA. */ - if (pAddFrame->BaParm.TID & 0xfff0) { - DBGPRINT(RT_DEBUG_ERROR, - ("PeerAddBARspActionSanity: ADDBA Response incorrect TID = %d\n", - pAddFrame->BaParm.TID)); - return FALSE; - } - return TRUE; - -} - -BOOLEAN PeerDelBAActionSanity(struct rt_rtmp_adapter *pAd, - u8 Wcid, void * pMsg, unsigned long MsgLen) -{ - /*struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *)pMsg; */ - struct rt_frame_delba_req * pDelFrame; - if (MsgLen != (sizeof(struct rt_frame_delba_req))) - return FALSE; - - if (Wcid >= MAX_LEN_OF_MAC_TABLE) - return FALSE; - - pDelFrame = (struct rt_frame_delba_req *) (pMsg); - - *(u16 *) (&pDelFrame->DelbaParm) = - cpu2le16(*(u16 *) (&pDelFrame->DelbaParm)); - pDelFrame->ReasonCode = cpu2le16(pDelFrame->ReasonCode); - - if (pDelFrame->DelbaParm.TID & 0xfff0) - return FALSE; - - return TRUE; -} - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -BOOLEAN PeerBeaconAndProbeRspSanity(struct rt_rtmp_adapter *pAd, void * Msg, unsigned long MsgLen, u8 MsgChannel, u8 *pAddr2, u8 *pBssid, char Ssid[], u8 * pSsidLen, u8 * pBssType, u16 * pBeaconPeriod, u8 * pChannel, u8 * pNewChannel, OUT LARGE_INTEGER * pTimestamp, struct rt_cf_parm * pCfParm, u16 * pAtimWin, u16 * pCapabilityInfo, u8 * pErp, u8 * pDtimCount, u8 * pDtimPeriod, u8 * pBcastFlag, u8 * pMessageToMe, u8 SupRate[], u8 * pSupRateLen, u8 ExtRate[], u8 * pExtRateLen, u8 * pCkipFlag, u8 * pAironetCellPowerLimit, struct rt_edca_parm *pEdcaParm, struct rt_qbss_load_parm *pQbssLoad, struct rt_qos_capability_parm *pQosCapability, unsigned long * pRalinkIe, u8 * pHtCapabilityLen, u8 * pPreNHtCapabilityLen, struct rt_ht_capability_ie * pHtCapability, u8 * AddHtInfoLen, struct rt_add_ht_info_ie * AddHtInfo, u8 * NewExtChannelOffset, /* Ht extension channel offset(above or below) */ - u16 * LengthVIE, - struct rt_ndis_802_11_variable_ies *pVIE) -{ - u8 *Ptr; - u8 TimLen; - struct rt_frame_802_11 * pFrame; - struct rt_eid * pEid; - u8 SubType; - u8 Sanity; - /*u8 ECWMin, ECWMax; */ - /*MAC_CSR9_STRUC Csr9; */ - unsigned long Length = 0; - - /* For some 11a AP which didn't have DS_IE, we use two conditions to decide the channel */ - /* 1. If the AP is 11n enabled, then check the control channel. */ - /* 2. If the AP didn't have any info about channel, use the channel we received this frame as the channel. (May inaccuracy!) */ - u8 CtrlChannel = 0; - - /* Add for 3 necessary EID field check */ - Sanity = 0; - - *pAtimWin = 0; - *pErp = 0; - *pDtimCount = 0; - *pDtimPeriod = 0; - *pBcastFlag = 0; - *pMessageToMe = 0; - *pExtRateLen = 0; - *pCkipFlag = 0; /* Default of CkipFlag is 0 */ - *pAironetCellPowerLimit = 0xFF; /* Default of AironetCellPowerLimit is 0xFF */ - *LengthVIE = 0; /* Set the length of VIE to init value 0 */ - *pHtCapabilityLen = 0; /* Set the length of VIE to init value 0 */ - if (pAd->OpMode == OPMODE_STA) - *pPreNHtCapabilityLen = 0; /* Set the length of VIE to init value 0 */ - *AddHtInfoLen = 0; /* Set the length of VIE to init value 0 */ - *pRalinkIe = 0; - *pNewChannel = 0; - *NewExtChannelOffset = 0xff; /*Default 0xff means no such IE */ - pCfParm->bValid = FALSE; /* default: no IE_CF found */ - pQbssLoad->bValid = FALSE; /* default: no IE_QBSS_LOAD found */ - pEdcaParm->bValid = FALSE; /* default: no IE_EDCA_PARAMETER found */ - pQosCapability->bValid = FALSE; /* default: no IE_QOS_CAPABILITY found */ - - pFrame = (struct rt_frame_802_11 *) Msg; - - /* get subtype from header */ - SubType = (u8)pFrame->Hdr.FC.SubType; - - /* get Addr2 and BSSID from header */ - COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); - COPY_MAC_ADDR(pBssid, pFrame->Hdr.Addr3); - - Ptr = pFrame->Octet; - Length += LENGTH_802_11; - - /* get timestamp from payload and advance the pointer */ - NdisMoveMemory(pTimestamp, Ptr, TIMESTAMP_LEN); - - pTimestamp->u.LowPart = cpu2le32(pTimestamp->u.LowPart); - pTimestamp->u.HighPart = cpu2le32(pTimestamp->u.HighPart); - - Ptr += TIMESTAMP_LEN; - Length += TIMESTAMP_LEN; - - /* get beacon interval from payload and advance the pointer */ - NdisMoveMemory(pBeaconPeriod, Ptr, 2); - Ptr += 2; - Length += 2; - - /* get capability info from payload and advance the pointer */ - NdisMoveMemory(pCapabilityInfo, Ptr, 2); - Ptr += 2; - Length += 2; - - if (CAP_IS_ESS_ON(*pCapabilityInfo)) - *pBssType = BSS_INFRA; - else - *pBssType = BSS_ADHOC; - - pEid = (struct rt_eid *) Ptr; - - /* get variable fields from payload and advance the pointer */ - while ((Length + 2 + pEid->Len) <= MsgLen) { - /* */ - /* Secure copy VIE to VarIE[MAX_VIE_LEN] didn't overflow. */ - /* */ - if ((*LengthVIE + pEid->Len + 2) >= MAX_VIE_LEN) { - DBGPRINT(RT_DEBUG_WARN, - ("PeerBeaconAndProbeRspSanity - Variable IEs out of resource [len(=%d) > MAX_VIE_LEN(=%d)]\n", - (*LengthVIE + pEid->Len + 2), MAX_VIE_LEN)); - break; - } - - switch (pEid->Eid) { - case IE_SSID: - /* Already has one SSID EID in this beacon, ignore the second one */ - if (Sanity & 0x1) - break; - if (pEid->Len <= MAX_LEN_OF_SSID) { - NdisMoveMemory(Ssid, pEid->Octet, pEid->Len); - *pSsidLen = pEid->Len; - Sanity |= 0x1; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerBeaconAndProbeRspSanity - wrong IE_SSID (len=%d)\n", - pEid->Len)); - return FALSE; - } - break; - - case IE_SUPP_RATES: - if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) { - Sanity |= 0x2; - NdisMoveMemory(SupRate, pEid->Octet, pEid->Len); - *pSupRateLen = pEid->Len; - - /* TODO: 2004-09-14 not a good design here, cause it exclude extra rates */ - /* from ScanTab. We should report as is. And filter out unsupported */ - /* rates in MlmeAux. */ - /* Check against the supported rates */ - /* RTMPCheckRates(pAd, SupRate, pSupRateLen); */ - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerBeaconAndProbeRspSanity - wrong IE_SUPP_RATES (len=%d)\n", - pEid->Len)); - return FALSE; - } - break; - - case IE_HT_CAP: - if (pEid->Len >= SIZE_HT_CAP_IE) /*Note: allow extension! */ - { - NdisMoveMemory(pHtCapability, pEid->Octet, - sizeof(struct rt_ht_capability_ie)); - *pHtCapabilityLen = SIZE_HT_CAP_IE; /* Nnow we only support 26 bytes. */ - - *(u16 *) (&pHtCapability->HtCapInfo) = - cpu2le16(*(u16 *) - (&pHtCapability->HtCapInfo)); - *(u16 *) (&pHtCapability->ExtHtCapInfo) = - cpu2le16(*(u16 *) - (&pHtCapability->ExtHtCapInfo)); - - { - *pPreNHtCapabilityLen = 0; /* Nnow we only support 26 bytes. */ - - Ptr = (u8 *)pVIE; - NdisMoveMemory(Ptr + *LengthVIE, - &pEid->Eid, - pEid->Len + 2); - *LengthVIE += (pEid->Len + 2); - } - } else { - DBGPRINT(RT_DEBUG_WARN, - ("PeerBeaconAndProbeRspSanity - wrong IE_HT_CAP. pEid->Len = %d\n", - pEid->Len)); - } - - break; - case IE_ADD_HT: - if (pEid->Len >= sizeof(struct rt_add_ht_info_ie)) { - /* This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only */ - /* copy first sizeof(struct rt_add_ht_info_ie) */ - NdisMoveMemory(AddHtInfo, pEid->Octet, - sizeof(struct rt_add_ht_info_ie)); - *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; - - CtrlChannel = AddHtInfo->ControlChan; - - *(u16 *) (&AddHtInfo->AddHtInfo2) = - cpu2le16(*(u16 *) - (&AddHtInfo->AddHtInfo2)); - *(u16 *) (&AddHtInfo->AddHtInfo3) = - cpu2le16(*(u16 *) - (&AddHtInfo->AddHtInfo3)); - - { - Ptr = (u8 *)pVIE; - NdisMoveMemory(Ptr + *LengthVIE, - &pEid->Eid, - pEid->Len + 2); - *LengthVIE += (pEid->Len + 2); - } - } else { - DBGPRINT(RT_DEBUG_WARN, - ("PeerBeaconAndProbeRspSanity - wrong IE_ADD_HT. \n")); - } - - break; - case IE_SECONDARY_CH_OFFSET: - if (pEid->Len == 1) { - *NewExtChannelOffset = pEid->Octet[0]; - } else { - DBGPRINT(RT_DEBUG_WARN, - ("PeerBeaconAndProbeRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n")); - } - - break; - case IE_FH_PARM: - DBGPRINT(RT_DEBUG_TRACE, - ("PeerBeaconAndProbeRspSanity(IE_FH_PARM) \n")); - break; - - case IE_DS_PARM: - if (pEid->Len == 1) { - *pChannel = *pEid->Octet; - - { - if (ChannelSanity(pAd, *pChannel) == 0) { - - return FALSE; - } - } - - Sanity |= 0x4; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerBeaconAndProbeRspSanity - wrong IE_DS_PARM (len=%d)\n", - pEid->Len)); - return FALSE; - } - break; - - case IE_CF_PARM: - if (pEid->Len == 6) { - pCfParm->bValid = TRUE; - pCfParm->CfpCount = pEid->Octet[0]; - pCfParm->CfpPeriod = pEid->Octet[1]; - pCfParm->CfpMaxDuration = - pEid->Octet[2] + 256 * pEid->Octet[3]; - pCfParm->CfpDurRemaining = - pEid->Octet[4] + 256 * pEid->Octet[5]; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerBeaconAndProbeRspSanity - wrong IE_CF_PARM\n")); - return FALSE; - } - break; - - case IE_IBSS_PARM: - if (pEid->Len == 2) { - NdisMoveMemory(pAtimWin, pEid->Octet, - pEid->Len); - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerBeaconAndProbeRspSanity - wrong IE_IBSS_PARM\n")); - return FALSE; - } - break; - - case IE_TIM: - if (INFRA_ON(pAd) && SubType == SUBTYPE_BEACON) { - GetTimBit((char *)pEid, pAd->StaActive.Aid, - &TimLen, pBcastFlag, pDtimCount, - pDtimPeriod, pMessageToMe); - } - break; - case IE_CHANNEL_SWITCH_ANNOUNCEMENT: - if (pEid->Len == 3) { - *pNewChannel = pEid->Octet[1]; /*extract new channel number */ - } - break; - - /* New for WPA */ - /* CCX v2 has the same IE, we need to parse that too */ - /* Wifi WMM use the same IE vale, need to parse that too */ - /* case IE_WPA: */ - case IE_VENDOR_SPECIFIC: - /* Check Broadcom/Atheros 802.11n OUI version, for HT Capability IE. */ - /* This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan. */ - /*if (NdisEqualMemory(pEid->Octet, BROADCOM_OUI, 3) && (pEid->Len >= 4)) - { - if ((pEid->Octet[3] == OUI_BROADCOM_HT) && (pEid->Len >= 30)) - { - { - NdisMoveMemory(pHtCapability, &pEid->Octet[4], sizeof(struct rt_ht_capability_ie)); - *pHtCapabilityLen = SIZE_HT_CAP_IE; // Nnow we only support 26 bytes. - } - } - if ((pEid->Octet[3] == OUI_BROADCOM_HT) && (pEid->Len >= 26)) - { - { - NdisMoveMemory(AddHtInfo, &pEid->Octet[4], sizeof(struct rt_add_ht_info_ie)); - *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; // Nnow we only support 26 bytes. - } - } - } - */ - /* Check the OUI version, filter out non-standard usage */ - if (NdisEqualMemory(pEid->Octet, RALINK_OUI, 3) - && (pEid->Len == 7)) { - /**pRalinkIe = pEid->Octet[3]; */ - if (pEid->Octet[3] != 0) - *pRalinkIe = pEid->Octet[3]; - else - *pRalinkIe = 0xf0000000; /* Set to non-zero value (can't set bit0-2) to represent this is Ralink Chip. So at linkup, we will set ralinkchip flag. */ - } - /* This HT IE is before IEEE draft set HT IE value.2006-09-28 by Jan. */ - - /* Other vendors had production before IE_HT_CAP value is assigned. To backward support those old-firmware AP, */ - /* Check broadcom-defiend pre-802.11nD1.0 OUI for HT related IE, including HT Capatilities IE and HT Information IE */ - else if ((*pHtCapabilityLen == 0) - && NdisEqualMemory(pEid->Octet, PRE_N_HT_OUI, - 3) && (pEid->Len >= 4) - && (pAd->OpMode == OPMODE_STA)) { - if ((pEid->Octet[3] == OUI_PREN_HT_CAP) - && (pEid->Len >= 30) - && (*pHtCapabilityLen == 0)) { - NdisMoveMemory(pHtCapability, - &pEid->Octet[4], - sizeof - (struct rt_ht_capability_ie)); - *pPreNHtCapabilityLen = SIZE_HT_CAP_IE; - } - - if ((pEid->Octet[3] == OUI_PREN_ADD_HT) - && (pEid->Len >= 26)) { - NdisMoveMemory(AddHtInfo, - &pEid->Octet[4], - sizeof(struct rt_add_ht_info_ie)); - *AddHtInfoLen = SIZE_ADD_HT_INFO_IE; - } - } else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)) { - /* Copy to pVIE which will report to microsoft bssid list. */ - Ptr = (u8 *)pVIE; - NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, - pEid->Len + 2); - *LengthVIE += (pEid->Len + 2); - } else - if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6) - && (pEid->Len == 24)) { - u8 *ptr; - int i; - - /* parsing EDCA parameters */ - pEdcaParm->bValid = TRUE; - pEdcaParm->bQAck = FALSE; /* pEid->Octet[0] & 0x10; */ - pEdcaParm->bQueueRequest = FALSE; /* pEid->Octet[0] & 0x20; */ - pEdcaParm->bTxopRequest = FALSE; /* pEid->Octet[0] & 0x40; */ - pEdcaParm->EdcaUpdateCount = - pEid->Octet[6] & 0x0f; - pEdcaParm->bAPSDCapable = - (pEid->Octet[6] & 0x80) ? 1 : 0; - ptr = &pEid->Octet[8]; - for (i = 0; i < 4; i++) { - u8 aci = (*ptr & 0x60) >> 5; /* b5~6 is AC INDEX */ - pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); /* b5 is ACM */ - pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; /* b0~3 is AIFSN */ - pEdcaParm->Cwmin[aci] = *(ptr + 1) & 0x0f; /* b0~4 is Cwmin */ - pEdcaParm->Cwmax[aci] = *(ptr + 1) >> 4; /* b5~8 is Cwmax */ - pEdcaParm->Txop[aci] = *(ptr + 2) + 256 * (*(ptr + 3)); /* in unit of 32-us */ - ptr += 4; /* point to next AC */ - } - } else - if (NdisEqualMemory(pEid->Octet, WME_INFO_ELEM, 6) - && (pEid->Len == 7)) { - /* parsing EDCA parameters */ - pEdcaParm->bValid = TRUE; - pEdcaParm->bQAck = FALSE; /* pEid->Octet[0] & 0x10; */ - pEdcaParm->bQueueRequest = FALSE; /* pEid->Octet[0] & 0x20; */ - pEdcaParm->bTxopRequest = FALSE; /* pEid->Octet[0] & 0x40; */ - pEdcaParm->EdcaUpdateCount = - pEid->Octet[6] & 0x0f; - pEdcaParm->bAPSDCapable = - (pEid->Octet[6] & 0x80) ? 1 : 0; - - /* use default EDCA parameter */ - pEdcaParm->bACM[QID_AC_BE] = 0; - pEdcaParm->Aifsn[QID_AC_BE] = 3; - pEdcaParm->Cwmin[QID_AC_BE] = CW_MIN_IN_BITS; - pEdcaParm->Cwmax[QID_AC_BE] = CW_MAX_IN_BITS; - pEdcaParm->Txop[QID_AC_BE] = 0; - - pEdcaParm->bACM[QID_AC_BK] = 0; - pEdcaParm->Aifsn[QID_AC_BK] = 7; - pEdcaParm->Cwmin[QID_AC_BK] = CW_MIN_IN_BITS; - pEdcaParm->Cwmax[QID_AC_BK] = CW_MAX_IN_BITS; - pEdcaParm->Txop[QID_AC_BK] = 0; - - pEdcaParm->bACM[QID_AC_VI] = 0; - pEdcaParm->Aifsn[QID_AC_VI] = 2; - pEdcaParm->Cwmin[QID_AC_VI] = - CW_MIN_IN_BITS - 1; - pEdcaParm->Cwmax[QID_AC_VI] = CW_MAX_IN_BITS; - pEdcaParm->Txop[QID_AC_VI] = 96; /* AC_VI: 96*32us ~= 3ms */ - - pEdcaParm->bACM[QID_AC_VO] = 0; - pEdcaParm->Aifsn[QID_AC_VO] = 2; - pEdcaParm->Cwmin[QID_AC_VO] = - CW_MIN_IN_BITS - 2; - pEdcaParm->Cwmax[QID_AC_VO] = - CW_MAX_IN_BITS - 1; - pEdcaParm->Txop[QID_AC_VO] = 48; /* AC_VO: 48*32us ~= 1.5ms */ - } - - break; - - case IE_EXT_SUPP_RATES: - if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) { - NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len); - *pExtRateLen = pEid->Len; - - /* TODO: 2004-09-14 not a good design here, cause it exclude extra rates */ - /* from ScanTab. We should report as is. And filter out unsupported */ - /* rates in MlmeAux. */ - /* Check against the supported rates */ - /* RTMPCheckRates(pAd, ExtRate, pExtRateLen); */ - } - break; - - case IE_ERP: - if (pEid->Len == 1) { - *pErp = (u8)pEid->Octet[0]; - } - break; - - case IE_AIRONET_CKIP: - /* 0. Check Aironet IE length, it must be larger or equal to 28 */ - /* Cisco AP350 used length as 28 */ - /* Cisco AP12XX used length as 30 */ - if (pEid->Len < (CKIP_NEGOTIATION_LENGTH - 2)) - break; - - /* 1. Copy CKIP flag byte to buffer for process */ - *pCkipFlag = *(pEid->Octet + 8); - break; - - case IE_AP_TX_POWER: - /* AP Control of Client Transmit Power */ - /*0. Check Aironet IE length, it must be 6 */ - if (pEid->Len != 0x06) - break; - - /* Get cell power limit in dBm */ - if (NdisEqualMemory(pEid->Octet, CISCO_OUI, 3) == 1) - *pAironetCellPowerLimit = *(pEid->Octet + 4); - break; - - /* WPA2 & 802.11i RSN */ - case IE_RSN: - /* There is no OUI for version anymore, check the group cipher OUI before copying */ - if (RTMPEqualMemory(pEid->Octet + 2, RSN_OUI, 3)) { - /* Copy to pVIE which will report to microsoft bssid list. */ - Ptr = (u8 *)pVIE; - NdisMoveMemory(Ptr + *LengthVIE, &pEid->Eid, - pEid->Len + 2); - *LengthVIE += (pEid->Len + 2); - } - break; - - default: - break; - } - - Length = Length + 2 + pEid->Len; /* Eid[1] + Len[1]+ content[Len] */ - pEid = (struct rt_eid *) ((u8 *) pEid + 2 + pEid->Len); - } - - /* For some 11a AP. it did not have the channel EID, patch here */ - { - u8 LatchRfChannel = MsgChannel; - if ((pAd->LatchRfRegs.Channel > 14) && ((Sanity & 0x4) == 0)) { - if (CtrlChannel != 0) - *pChannel = CtrlChannel; - else - *pChannel = LatchRfChannel; - Sanity |= 0x4; - } - } - - if (Sanity != 0x7) { - DBGPRINT(RT_DEBUG_LOUD, - ("PeerBeaconAndProbeRspSanity - missing field, Sanity=0x%02x\n", - Sanity)); - return FALSE; - } else { - return TRUE; - } - -} - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - ========================================================================== - */ -BOOLEAN MlmeScanReqSanity(struct rt_rtmp_adapter *pAd, - void * Msg, - unsigned long MsgLen, - u8 * pBssType, - char Ssid[], - u8 * pSsidLen, u8 * pScanType) -{ - struct rt_mlme_scan_req *Info; - - Info = (struct rt_mlme_scan_req *)(Msg); - *pBssType = Info->BssType; - *pSsidLen = Info->SsidLen; - NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen); - *pScanType = Info->ScanType; - - if ((*pBssType == BSS_INFRA || *pBssType == BSS_ADHOC - || *pBssType == BSS_ANY) - && (*pScanType == SCAN_ACTIVE || *pScanType == SCAN_PASSIVE)) { - return TRUE; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeScanReqSanity fail - wrong BssType or ScanType\n")); - return FALSE; - } -} - -/* IRQL = DISPATCH_LEVEL */ -u8 ChannelSanity(struct rt_rtmp_adapter *pAd, u8 channel) -{ - int i; - - for (i = 0; i < pAd->ChannelListNum; i++) { - if (channel == pAd->ChannelList[i].Channel) - return 1; - } - return 0; -} - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -BOOLEAN PeerDeauthSanity(struct rt_rtmp_adapter *pAd, - void * Msg, - unsigned long MsgLen, - u8 *pAddr2, u16 * pReason) -{ - struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg; - - COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); - NdisMoveMemory(pReason, &pFrame->Octet[0], 2); - - return TRUE; -} - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -BOOLEAN PeerAuthSanity(struct rt_rtmp_adapter *pAd, - void * Msg, - unsigned long MsgLen, - u8 *pAddr, - u16 * pAlg, - u16 * pSeq, - u16 * pStatus, char * pChlgText) -{ - struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg; - - COPY_MAC_ADDR(pAddr, pFrame->Hdr.Addr2); - NdisMoveMemory(pAlg, &pFrame->Octet[0], 2); - NdisMoveMemory(pSeq, &pFrame->Octet[2], 2); - NdisMoveMemory(pStatus, &pFrame->Octet[4], 2); - - if (*pAlg == AUTH_MODE_OPEN) { - if (*pSeq == 1 || *pSeq == 2) { - return TRUE; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerAuthSanity fail - wrong Seg#\n")); - return FALSE; - } - } else if (*pAlg == AUTH_MODE_KEY) { - if (*pSeq == 1 || *pSeq == 4) { - return TRUE; - } else if (*pSeq == 2 || *pSeq == 3) { - NdisMoveMemory(pChlgText, &pFrame->Octet[8], - CIPHER_TEXT_LEN); - return TRUE; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerAuthSanity fail - wrong Seg#\n")); - return FALSE; - } - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerAuthSanity fail - wrong algorithm\n")); - return FALSE; - } -} - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - ========================================================================== - */ -BOOLEAN MlmeAuthReqSanity(struct rt_rtmp_adapter *pAd, - void * Msg, - unsigned long MsgLen, - u8 *pAddr, - unsigned long * pTimeout, u16 * pAlg) -{ - struct rt_mlme_auth_req *pInfo; - - pInfo = (struct rt_mlme_auth_req *)Msg; - COPY_MAC_ADDR(pAddr, pInfo->Addr); - *pTimeout = pInfo->Timeout; - *pAlg = pInfo->Alg; - - if (((*pAlg == AUTH_MODE_KEY) || (*pAlg == AUTH_MODE_OPEN) - ) && ((*pAddr & 0x01) == 0)) { - return TRUE; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeAuthReqSanity fail - wrong algorithm\n")); - return FALSE; - } -} - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -BOOLEAN MlmeAssocReqSanity(struct rt_rtmp_adapter *pAd, - void * Msg, - unsigned long MsgLen, - u8 *pApAddr, - u16 * pCapabilityInfo, - unsigned long * pTimeout, u16 * pListenIntv) -{ - struct rt_mlme_assoc_req *pInfo; - - pInfo = (struct rt_mlme_assoc_req *)Msg; - *pTimeout = pInfo->Timeout; /* timeout */ - COPY_MAC_ADDR(pApAddr, pInfo->Addr); /* AP address */ - *pCapabilityInfo = pInfo->CapabilityInfo; /* capability info */ - *pListenIntv = pInfo->ListenIntv; - - return TRUE; -} - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -BOOLEAN PeerDisassocSanity(struct rt_rtmp_adapter *pAd, - void * Msg, - unsigned long MsgLen, - u8 *pAddr2, u16 * pReason) -{ - struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg; - - COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); - NdisMoveMemory(pReason, &pFrame->Octet[0], 2); - - return TRUE; -} - -/* - ======================================================================== - Routine Description: - Sanity check NetworkType (11b, 11g or 11a) - - Arguments: - pBss - Pointer to BSS table. - - Return Value: - Ndis802_11DS .......(11b) - Ndis802_11OFDM24....(11g) - Ndis802_11OFDM5.....(11a) - - IRQL = DISPATCH_LEVEL - - ======================================================================== -*/ -NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(struct rt_bss_entry *pBss) -{ - NDIS_802_11_NETWORK_TYPE NetWorkType; - u8 rate, i; - - NetWorkType = Ndis802_11DS; - - if (pBss->Channel <= 14) { - /* */ - /* First check support Rate. */ - /* */ - for (i = 0; i < pBss->SupRateLen; i++) { - rate = pBss->SupRate[i] & 0x7f; /* Mask out basic rate set bit */ - if ((rate == 2) || (rate == 4) || (rate == 11) - || (rate == 22)) { - continue; - } else { - /* */ - /* Otherwise (even rate > 108) means Ndis802_11OFDM24 */ - /* */ - NetWorkType = Ndis802_11OFDM24; - break; - } - } - - /* */ - /* Second check Extend Rate. */ - /* */ - if (NetWorkType != Ndis802_11OFDM24) { - for (i = 0; i < pBss->ExtRateLen; i++) { - rate = pBss->SupRate[i] & 0x7f; /* Mask out basic rate set bit */ - if ((rate == 2) || (rate == 4) || (rate == 11) - || (rate == 22)) { - continue; - } else { - /* */ - /* Otherwise (even rate > 108) means Ndis802_11OFDM24 */ - /* */ - NetWorkType = Ndis802_11OFDM24; - break; - } - } - } - } else { - NetWorkType = Ndis802_11OFDM5; - } - - if (pBss->HtCapabilityLen != 0) { - if (NetWorkType == Ndis802_11OFDM5) - NetWorkType = Ndis802_11OFDM5_N; - else - NetWorkType = Ndis802_11OFDM24_N; - } - - return NetWorkType; -} - -/* - ========================================================================== - Description: - Check the validity of the received EAPoL frame - Return: - TRUE if all parameters are OK, - FALSE otherwise - ========================================================================== - */ -BOOLEAN PeerWpaMessageSanity(struct rt_rtmp_adapter *pAd, - struct rt_eapol_packet * pMsg, - unsigned long MsgLen, - u8 MsgType, struct rt_mac_table_entry *pEntry) -{ - u8 mic[LEN_KEY_DESC_MIC], digest[80], KEYDATA[MAX_LEN_OF_RSNIE]; - BOOLEAN bReplayDiff = FALSE; - BOOLEAN bWPA2 = FALSE; - struct rt_key_info EapolKeyInfo; - u8 GroupKeyIndex = 0; - - NdisZeroMemory(mic, sizeof(mic)); - NdisZeroMemory(digest, sizeof(digest)); - NdisZeroMemory(KEYDATA, sizeof(KEYDATA)); - NdisZeroMemory((u8 *)& EapolKeyInfo, sizeof(EapolKeyInfo)); - - NdisMoveMemory((u8 *)& EapolKeyInfo, - (u8 *)& pMsg->KeyDesc.KeyInfo, sizeof(struct rt_key_info)); - - *((u16 *) & EapolKeyInfo) = cpu2le16(*((u16 *) & EapolKeyInfo)); - - /* Choose WPA2 or not */ - if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) - || (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK)) - bWPA2 = TRUE; - - /* 0. Check MsgType */ - if ((MsgType > EAPOL_GROUP_MSG_2) || (MsgType < EAPOL_PAIR_MSG_1)) { - DBGPRINT(RT_DEBUG_ERROR, - ("The message type is invalid(%d)! \n", MsgType)); - return FALSE; - } - /* 1. Replay counter check */ - if (MsgType == EAPOL_PAIR_MSG_1 || MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1) /* For supplicant */ - { - /* First validate replay counter, only accept message with larger replay counter. */ - /* Let equal pass, some AP start with all zero replay counter */ - u8 ZeroReplay[LEN_KEY_DESC_REPLAY]; - - NdisZeroMemory(ZeroReplay, LEN_KEY_DESC_REPLAY); - if ((RTMPCompareMemory - (pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, - LEN_KEY_DESC_REPLAY) != 1) - && - (RTMPCompareMemory - (pMsg->KeyDesc.ReplayCounter, ZeroReplay, - LEN_KEY_DESC_REPLAY) != 0)) { - bReplayDiff = TRUE; - } - } else if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2) /* For authenticator */ - { - /* check Replay Counter coresponds to MSG from authenticator, otherwise discard */ - if (!NdisEqualMemory - (pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, - LEN_KEY_DESC_REPLAY)) { - bReplayDiff = TRUE; - } - } - /* Replay Counter different condition */ - if (bReplayDiff) { - /* send wireless event - for replay counter different */ - if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, - IW_REPLAY_COUNTER_DIFF_EVENT_FLAG, - pEntry->Addr, pEntry->apidx, 0); - - if (MsgType < EAPOL_GROUP_MSG_1) { - DBGPRINT(RT_DEBUG_ERROR, - ("Replay Counter Different in pairwise msg %d of 4-way handshake!\n", - MsgType)); - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("Replay Counter Different in group msg %d of 2-way handshake!\n", - (MsgType - EAPOL_PAIR_MSG_4))); - } - - hex_dump("Receive replay counter ", pMsg->KeyDesc.ReplayCounter, - LEN_KEY_DESC_REPLAY); - hex_dump("Current replay counter ", pEntry->R_Counter, - LEN_KEY_DESC_REPLAY); - return FALSE; - } - /* 2. Verify MIC except Pairwise Msg1 */ - if (MsgType != EAPOL_PAIR_MSG_1) { - u8 rcvd_mic[LEN_KEY_DESC_MIC]; - - /* Record the received MIC for check later */ - NdisMoveMemory(rcvd_mic, pMsg->KeyDesc.KeyMic, - LEN_KEY_DESC_MIC); - NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC); - - if (EapolKeyInfo.KeyDescVer == DESC_TYPE_TKIP) /* TKIP */ - { - HMAC_MD5(pEntry->PTK, LEN_EAP_MICK, (u8 *)pMsg, - MsgLen, mic, MD5_DIGEST_SIZE); - } else if (EapolKeyInfo.KeyDescVer == DESC_TYPE_AES) /* AES */ - { - HMAC_SHA1(pEntry->PTK, LEN_EAP_MICK, (u8 *)pMsg, - MsgLen, digest, SHA1_DIGEST_SIZE); - NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC); - } - - if (!NdisEqualMemory(rcvd_mic, mic, LEN_KEY_DESC_MIC)) { - /* send wireless event - for MIC different */ - if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, - IW_MIC_DIFF_EVENT_FLAG, - pEntry->Addr, - pEntry->apidx, 0); - - if (MsgType < EAPOL_GROUP_MSG_1) { - DBGPRINT(RT_DEBUG_ERROR, - ("MIC Different in pairwise msg %d of 4-way handshake!\n", - MsgType)); - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("MIC Different in group msg %d of 2-way handshake!\n", - (MsgType - EAPOL_PAIR_MSG_4))); - } - - hex_dump("Received MIC", rcvd_mic, LEN_KEY_DESC_MIC); - hex_dump("Desired MIC", mic, LEN_KEY_DESC_MIC); - - return FALSE; - } - } - /* 1. Decrypt the Key Data field if GTK is included. */ - /* 2. Extract the context of the Key Data field if it exist. */ - /* The field in pairwise_msg_2_WPA1(WPA2) & pairwise_msg_3_WPA1 is clear. */ - /* The field in group_msg_1_WPA1(WPA2) & pairwise_msg_3_WPA2 is encrypted. */ - if (CONV_ARRARY_TO_u16(pMsg->KeyDesc.KeyDataLen) > 0) { - /* Decrypt this field */ - if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) - || (MsgType == EAPOL_GROUP_MSG_1)) { - if ((EapolKeyInfo.KeyDescVer == DESC_TYPE_AES)) { - /* AES */ - AES_GTK_KEY_UNWRAP(&pEntry->PTK[16], KEYDATA, - CONV_ARRARY_TO_u16(pMsg-> - KeyDesc. - KeyDataLen), - pMsg->KeyDesc.KeyData); - } else { - int i; - u8 Key[32]; - /* Decrypt TKIP GTK */ - /* Construct 32 bytes RC4 Key */ - NdisMoveMemory(Key, pMsg->KeyDesc.KeyIv, 16); - NdisMoveMemory(&Key[16], &pEntry->PTK[16], 16); - ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, Key, - 32); - /*discard first 256 bytes */ - for (i = 0; i < 256; i++) - ARCFOUR_BYTE(&pAd->PrivateInfo. - WEPCONTEXT); - /* Decrypt GTK. Becareful, there is no ICV to check the result is correct or not */ - ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, - KEYDATA, pMsg->KeyDesc.KeyData, - CONV_ARRARY_TO_u16(pMsg-> - KeyDesc. - KeyDataLen)); - } - - if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1)) - GroupKeyIndex = EapolKeyInfo.KeyIndex; - - } else if ((MsgType == EAPOL_PAIR_MSG_2) - || (MsgType == EAPOL_PAIR_MSG_3 && !bWPA2)) { - NdisMoveMemory(KEYDATA, pMsg->KeyDesc.KeyData, - CONV_ARRARY_TO_u16(pMsg->KeyDesc. - KeyDataLen)); - } else { - - return TRUE; - } - - /* Parse Key Data field to */ - /* 1. verify RSN IE for pairwise_msg_2_WPA1(WPA2) ,pairwise_msg_3_WPA1(WPA2) */ - /* 2. verify KDE format for pairwise_msg_3_WPA2, group_msg_1_WPA2 */ - /* 3. update shared key for pairwise_msg_3_WPA2, group_msg_1_WPA1(WPA2) */ - if (!RTMPParseEapolKeyData(pAd, KEYDATA, - CONV_ARRARY_TO_u16(pMsg->KeyDesc. - KeyDataLen), - GroupKeyIndex, MsgType, bWPA2, - pEntry)) { - return FALSE; - } - } - - return TRUE; - -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_sync.c b/trunk/drivers/staging/rt2860/common/cmm_sync.c deleted file mode 100644 index aefe1b774650..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_sync.c +++ /dev/null @@ -1,718 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - cmm_sync.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - John Chang 2004-09-01 modified for rt2561/2661 -*/ -#include "../rt_config.h" - -/* 2.4 Ghz channel plan index in the TxPower arrays. */ -#define BG_BAND_REGION_0_START 0 /* 1,2,3,4,5,6,7,8,9,10,11 */ -#define BG_BAND_REGION_0_SIZE 11 -#define BG_BAND_REGION_1_START 0 /* 1,2,3,4,5,6,7,8,9,10,11,12,13 */ -#define BG_BAND_REGION_1_SIZE 13 -#define BG_BAND_REGION_2_START 9 /* 10,11 */ -#define BG_BAND_REGION_2_SIZE 2 -#define BG_BAND_REGION_3_START 9 /* 10,11,12,13 */ -#define BG_BAND_REGION_3_SIZE 4 -#define BG_BAND_REGION_4_START 13 /* 14 */ -#define BG_BAND_REGION_4_SIZE 1 -#define BG_BAND_REGION_5_START 0 /* 1,2,3,4,5,6,7,8,9,10,11,12,13,14 */ -#define BG_BAND_REGION_5_SIZE 14 -#define BG_BAND_REGION_6_START 2 /* 3,4,5,6,7,8,9 */ -#define BG_BAND_REGION_6_SIZE 7 -#define BG_BAND_REGION_7_START 4 /* 5,6,7,8,9,10,11,12,13 */ -#define BG_BAND_REGION_7_SIZE 9 -#define BG_BAND_REGION_31_START 0 /* 1,2,3,4,5,6,7,8,9,10,11,12,13,14 */ -#define BG_BAND_REGION_31_SIZE 14 - -/* 5 Ghz channel plan index in the TxPower arrays. */ -u8 A_BAND_REGION_0_CHANNEL_LIST[] = - { 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165 }; -u8 A_BAND_REGION_1_CHANNEL_LIST[] = - { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, -132, 136, 140 }; -u8 A_BAND_REGION_2_CHANNEL_LIST[] = { 36, 40, 44, 48, 52, 56, 60, 64 }; -u8 A_BAND_REGION_3_CHANNEL_LIST[] = { 52, 56, 60, 64, 149, 153, 157, 161 }; -u8 A_BAND_REGION_4_CHANNEL_LIST[] = { 149, 153, 157, 161, 165 }; -u8 A_BAND_REGION_5_CHANNEL_LIST[] = { 149, 153, 157, 161 }; -u8 A_BAND_REGION_6_CHANNEL_LIST[] = { 36, 40, 44, 48 }; -u8 A_BAND_REGION_7_CHANNEL_LIST[] = - { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, -132, 136, 140, 149, 153, 157, 161, 165, 169, 173 }; -u8 A_BAND_REGION_8_CHANNEL_LIST[] = { 52, 56, 60, 64 }; -u8 A_BAND_REGION_9_CHANNEL_LIST[] = - { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, -149, 153, 157, 161, 165 }; -u8 A_BAND_REGION_10_CHANNEL_LIST[] = - { 36, 40, 44, 48, 149, 153, 157, 161, 165 }; -u8 A_BAND_REGION_11_CHANNEL_LIST[] = - { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 149, 153, -157, 161 }; -u8 A_BAND_REGION_12_CHANNEL_LIST[] = - { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, -132, 136, 140 }; -u8 A_BAND_REGION_13_CHANNEL_LIST[] = - { 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, -149, 153, 157, 161 }; -u8 A_BAND_REGION_14_CHANNEL_LIST[] = - { 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 136, 140, 149, -153, 157, 161, 165 }; -u8 A_BAND_REGION_15_CHANNEL_LIST[] = { 149, 153, 157, 161, 165, 169, 173 }; - -/*BaSizeArray follows the 802.11n definition as MaxRxFactor. 2^(13+factor) bytes. When factor =0, it's about Ba buffer size =8. */ -u8 BaSizeArray[4] = { 8, 16, 32, 64 }; - -/* - ========================================================================== - Description: - Update StaCfg->ChannelList[] according to 1) Country Region 2) RF IC type, - and 3) PHY-mode user selected. - The outcome is used by driver when doing site survey. - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void BuildChannelList(struct rt_rtmp_adapter *pAd) -{ - u8 i, j, index = 0, num = 0; - u8 *pChannelList = NULL; - - NdisZeroMemory(pAd->ChannelList, - MAX_NUM_OF_CHANNELS * sizeof(struct rt_channel_tx_power)); - - /* if not 11a-only mode, channel list starts from 2.4Ghz band */ - if ((pAd->CommonCfg.PhyMode != PHY_11A) - && (pAd->CommonCfg.PhyMode != PHY_11AN_MIXED) - && (pAd->CommonCfg.PhyMode != PHY_11N_5G) - ) { - switch (pAd->CommonCfg.CountryRegion & 0x7f) { - case REGION_0_BG_BAND: /* 1 -11 */ - NdisMoveMemory(&pAd->ChannelList[index], - &pAd->TxPower[BG_BAND_REGION_0_START], - sizeof(struct rt_channel_tx_power) * - BG_BAND_REGION_0_SIZE); - index += BG_BAND_REGION_0_SIZE; - break; - case REGION_1_BG_BAND: /* 1 - 13 */ - NdisMoveMemory(&pAd->ChannelList[index], - &pAd->TxPower[BG_BAND_REGION_1_START], - sizeof(struct rt_channel_tx_power) * - BG_BAND_REGION_1_SIZE); - index += BG_BAND_REGION_1_SIZE; - break; - case REGION_2_BG_BAND: /* 10 - 11 */ - NdisMoveMemory(&pAd->ChannelList[index], - &pAd->TxPower[BG_BAND_REGION_2_START], - sizeof(struct rt_channel_tx_power) * - BG_BAND_REGION_2_SIZE); - index += BG_BAND_REGION_2_SIZE; - break; - case REGION_3_BG_BAND: /* 10 - 13 */ - NdisMoveMemory(&pAd->ChannelList[index], - &pAd->TxPower[BG_BAND_REGION_3_START], - sizeof(struct rt_channel_tx_power) * - BG_BAND_REGION_3_SIZE); - index += BG_BAND_REGION_3_SIZE; - break; - case REGION_4_BG_BAND: /* 14 */ - NdisMoveMemory(&pAd->ChannelList[index], - &pAd->TxPower[BG_BAND_REGION_4_START], - sizeof(struct rt_channel_tx_power) * - BG_BAND_REGION_4_SIZE); - index += BG_BAND_REGION_4_SIZE; - break; - case REGION_5_BG_BAND: /* 1 - 14 */ - NdisMoveMemory(&pAd->ChannelList[index], - &pAd->TxPower[BG_BAND_REGION_5_START], - sizeof(struct rt_channel_tx_power) * - BG_BAND_REGION_5_SIZE); - index += BG_BAND_REGION_5_SIZE; - break; - case REGION_6_BG_BAND: /* 3 - 9 */ - NdisMoveMemory(&pAd->ChannelList[index], - &pAd->TxPower[BG_BAND_REGION_6_START], - sizeof(struct rt_channel_tx_power) * - BG_BAND_REGION_6_SIZE); - index += BG_BAND_REGION_6_SIZE; - break; - case REGION_7_BG_BAND: /* 5 - 13 */ - NdisMoveMemory(&pAd->ChannelList[index], - &pAd->TxPower[BG_BAND_REGION_7_START], - sizeof(struct rt_channel_tx_power) * - BG_BAND_REGION_7_SIZE); - index += BG_BAND_REGION_7_SIZE; - break; - case REGION_31_BG_BAND: /* 1 - 14 */ - NdisMoveMemory(&pAd->ChannelList[index], - &pAd->TxPower[BG_BAND_REGION_31_START], - sizeof(struct rt_channel_tx_power) * - BG_BAND_REGION_31_SIZE); - index += BG_BAND_REGION_31_SIZE; - break; - default: /* Error. should never happen */ - break; - } - for (i = 0; i < index; i++) - pAd->ChannelList[i].MaxTxPwr = 20; - } - - if ((pAd->CommonCfg.PhyMode == PHY_11A) - || (pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED) - || (pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) - || (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED) - || (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) - || (pAd->CommonCfg.PhyMode == PHY_11N_5G) - ) { - switch (pAd->CommonCfg.CountryRegionForABand & 0x7f) { - case REGION_0_A_BAND: - num = - sizeof(A_BAND_REGION_0_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_0_CHANNEL_LIST; - break; - case REGION_1_A_BAND: - num = - sizeof(A_BAND_REGION_1_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_1_CHANNEL_LIST; - break; - case REGION_2_A_BAND: - num = - sizeof(A_BAND_REGION_2_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_2_CHANNEL_LIST; - break; - case REGION_3_A_BAND: - num = - sizeof(A_BAND_REGION_3_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_3_CHANNEL_LIST; - break; - case REGION_4_A_BAND: - num = - sizeof(A_BAND_REGION_4_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_4_CHANNEL_LIST; - break; - case REGION_5_A_BAND: - num = - sizeof(A_BAND_REGION_5_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_5_CHANNEL_LIST; - break; - case REGION_6_A_BAND: - num = - sizeof(A_BAND_REGION_6_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_6_CHANNEL_LIST; - break; - case REGION_7_A_BAND: - num = - sizeof(A_BAND_REGION_7_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_7_CHANNEL_LIST; - break; - case REGION_8_A_BAND: - num = - sizeof(A_BAND_REGION_8_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_8_CHANNEL_LIST; - break; - case REGION_9_A_BAND: - num = - sizeof(A_BAND_REGION_9_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_9_CHANNEL_LIST; - break; - - case REGION_10_A_BAND: - num = - sizeof(A_BAND_REGION_10_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_10_CHANNEL_LIST; - break; - - case REGION_11_A_BAND: - num = - sizeof(A_BAND_REGION_11_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_11_CHANNEL_LIST; - break; - case REGION_12_A_BAND: - num = - sizeof(A_BAND_REGION_12_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_12_CHANNEL_LIST; - break; - case REGION_13_A_BAND: - num = - sizeof(A_BAND_REGION_13_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_13_CHANNEL_LIST; - break; - case REGION_14_A_BAND: - num = - sizeof(A_BAND_REGION_14_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_14_CHANNEL_LIST; - break; - case REGION_15_A_BAND: - num = - sizeof(A_BAND_REGION_15_CHANNEL_LIST) / - sizeof(u8); - pChannelList = A_BAND_REGION_15_CHANNEL_LIST; - break; - default: /* Error. should never happen */ - DBGPRINT(RT_DEBUG_WARN, - ("countryregion=%d not support", - pAd->CommonCfg.CountryRegionForABand)); - break; - } - - if (num != 0) { - u8 RadarCh[15] = - { 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, - 128, 132, 136, 140 }; - for (i = 0; i < num; i++) { - for (j = 0; j < MAX_NUM_OF_CHANNELS; j++) { - if (pChannelList[i] == - pAd->TxPower[j].Channel) - NdisMoveMemory(&pAd-> - ChannelList[index - + i], - &pAd->TxPower[j], - sizeof - (struct rt_channel_tx_power)); - } - for (j = 0; j < 15; j++) { - if (pChannelList[i] == RadarCh[j]) - pAd->ChannelList[index + - i].DfsReq = - TRUE; - } - pAd->ChannelList[index + i].MaxTxPwr = 20; - } - index += num; - } - } - - pAd->ChannelListNum = index; - DBGPRINT(RT_DEBUG_TRACE, - ("country code=%d/%d, RFIC=%d, PHY mode=%d, support %d channels\n", - pAd->CommonCfg.CountryRegion, - pAd->CommonCfg.CountryRegionForABand, pAd->RfIcType, - pAd->CommonCfg.PhyMode, pAd->ChannelListNum)); -#ifdef DBG - for (i = 0; i < pAd->ChannelListNum; i++) { - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("BuildChannel # %d :: Pwr0 = %d, Pwr1 =%d, \n ", - pAd->ChannelList[i].Channel, - pAd->ChannelList[i].Power, - pAd->ChannelList[i].Power2)); - } -#endif -} - -/* - ========================================================================== - Description: - This routine return the first channel number according to the country - code selection and RF IC selection (signal band or dual band). It is called - whenever driver need to start a site survey of all supported channels. - Return: - ch - the first channel number of current country code setting - - IRQL = PASSIVE_LEVEL - - ========================================================================== - */ -u8 FirstChannel(struct rt_rtmp_adapter *pAd) -{ - return pAd->ChannelList[0].Channel; -} - -/* - ========================================================================== - Description: - This routine returns the next channel number. This routine is called - during driver need to start a site survey of all supported channels. - Return: - next_channel - the next channel number valid in current country code setting. - Note: - return 0 if no more next channel - ========================================================================== - */ -u8 NextChannel(struct rt_rtmp_adapter *pAd, u8 channel) -{ - int i; - u8 next_channel = 0; - - for (i = 0; i < (pAd->ChannelListNum - 1); i++) - if (channel == pAd->ChannelList[i].Channel) { - next_channel = pAd->ChannelList[i + 1].Channel; - break; - } - return next_channel; -} - -/* - ========================================================================== - Description: - This routine is for Cisco Compatible Extensions 2.X - Spec31. AP Control of Client Transmit Power - Return: - None - Note: - Required by Aironet dBm(mW) - 0dBm(1mW), 1dBm(5mW), 13dBm(20mW), 15dBm(30mW), - 17dBm(50mw), 20dBm(100mW) - - We supported - 3dBm(Lowest), 6dBm(10%), 9dBm(25%), 12dBm(50%), - 14dBm(75%), 15dBm(100%) - - The client station's actual transmit power shall be within +/- 5dB of - the minimum value or next lower value. - ========================================================================== - */ -void ChangeToCellPowerLimit(struct rt_rtmp_adapter *pAd, - u8 AironetCellPowerLimit) -{ - /*valud 0xFF means that hasn't found power limit information */ - /*from the AP's Beacon/Probe response. */ - if (AironetCellPowerLimit == 0xFF) - return; - - if (AironetCellPowerLimit < 6) /*Used Lowest Power Percentage. */ - pAd->CommonCfg.TxPowerPercentage = 6; - else if (AironetCellPowerLimit < 9) - pAd->CommonCfg.TxPowerPercentage = 10; - else if (AironetCellPowerLimit < 12) - pAd->CommonCfg.TxPowerPercentage = 25; - else if (AironetCellPowerLimit < 14) - pAd->CommonCfg.TxPowerPercentage = 50; - else if (AironetCellPowerLimit < 15) - pAd->CommonCfg.TxPowerPercentage = 75; - else - pAd->CommonCfg.TxPowerPercentage = 100; /*else used maximum */ - - if (pAd->CommonCfg.TxPowerPercentage > pAd->CommonCfg.TxPowerDefault) - pAd->CommonCfg.TxPowerPercentage = - pAd->CommonCfg.TxPowerDefault; - -} - -char ConvertToRssi(struct rt_rtmp_adapter *pAd, char Rssi, u8 RssiNumber) -{ - u8 RssiOffset, LNAGain; - - /* Rssi equals to zero should be an invalid value */ - if (Rssi == 0) - return -99; - - LNAGain = GET_LNA_GAIN(pAd); - if (pAd->LatchRfRegs.Channel > 14) { - if (RssiNumber == 0) - RssiOffset = pAd->ARssiOffset0; - else if (RssiNumber == 1) - RssiOffset = pAd->ARssiOffset1; - else - RssiOffset = pAd->ARssiOffset2; - } else { - if (RssiNumber == 0) - RssiOffset = pAd->BGRssiOffset0; - else if (RssiNumber == 1) - RssiOffset = pAd->BGRssiOffset1; - else - RssiOffset = pAd->BGRssiOffset2; - } - - return (-12 - RssiOffset - LNAGain - Rssi); -} - -/* - ========================================================================== - Description: - Scan next channel - ========================================================================== - */ -void ScanNextChannel(struct rt_rtmp_adapter *pAd) -{ - struct rt_header_802_11 Hdr80211; - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen = 0; - u8 SsidLen = 0, ScanType = pAd->MlmeAux.ScanType, BBPValue = 0; - u16 Status; - struct rt_header_802_11 * pHdr80211; - u32 ScanTimeIn5gChannel = SHORT_CHANNEL_TIME; - - { - if (MONITOR_ON(pAd)) - return; - } - - if (pAd->MlmeAux.Channel == 0) { - if ((pAd->CommonCfg.BBPCurrentBW == BW_40) - && (INFRA_ON(pAd) - || (pAd->OpMode == OPMODE_AP)) - ) { - AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, - FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); - BBPValue &= (~0x18); - BBPValue |= 0x10; - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n", - pAd->CommonCfg.CentralChannel, - pAd->ScanTab.BssNr)); - } else { - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.Channel); - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - End of SCAN, restore to channel %d, Total BSS[%02d]\n", - pAd->CommonCfg.Channel, pAd->ScanTab.BssNr)); - } - - { - /* */ - /* To prevent data lost. */ - /* Send an NULL data with turned PSM bit on to current associated AP before SCAN progress. */ - /* Now, we need to send an NULL data with turned PSM bit off to AP, when scan progress done */ - /* */ - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) - && (INFRA_ON(pAd))) { - NStatus = - MlmeAllocateMemory(pAd, - (void *)& pOutBuffer); - if (NStatus == NDIS_STATUS_SUCCESS) { - pHdr80211 = (struct rt_header_802_11 *) pOutBuffer; - MgtMacHeaderInit(pAd, pHdr80211, - SUBTYPE_NULL_FUNC, 1, - pAd->CommonCfg.Bssid, - pAd->CommonCfg.Bssid); - pHdr80211->Duration = 0; - pHdr80211->FC.Type = BTYPE_DATA; - pHdr80211->FC.PwrMgmt = - (pAd->StaCfg.Psm == PWR_SAVE); - - /* Send using priority queue */ - MiniportMMRequest(pAd, 0, pOutBuffer, - sizeof - (struct rt_header_802_11)); - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeScanReqAction -- Send PSM Data frame\n")); - MlmeFreeMemory(pAd, pOutBuffer); - RTMPusecDelay(5000); - } - } - - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - Status = MLME_SUCCESS; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, - 2, &Status); - } - - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS); - } -#ifdef RTMP_MAC_USB - else if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) - && (pAd->OpMode == OPMODE_STA)) { - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - MlmeCntlConfirm(pAd, MT2_SCAN_CONF, MLME_FAIL_NO_RESOURCE); - } -#endif /* RTMP_MAC_USB // */ - else { - { - /* BBP and RF are not accessible in PS mode, we has to wake them up first */ - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) - AsicForceWakeup(pAd, TRUE); - - /* leave PSM during scanning. otherwise we may lost ProbeRsp & BEACON */ - if (pAd->StaCfg.Psm == PWR_SAVE) - RTMP_SET_PSM_BIT(pAd, PWR_ACTIVE); - } - - AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, TRUE); - AsicLockChannel(pAd, pAd->MlmeAux.Channel); - - { - if (pAd->MlmeAux.Channel > 14) { - if ((pAd->CommonCfg.bIEEE80211H == 1) - && RadarChannelCheck(pAd, - pAd->MlmeAux. - Channel)) { - ScanType = SCAN_PASSIVE; - ScanTimeIn5gChannel = MIN_CHANNEL_TIME; - } - } - } - - /*Global country domain(ch1-11:active scan, ch12-14 passive scan) */ - if ((pAd->MlmeAux.Channel <= 14) && (pAd->MlmeAux.Channel >= 12) - && ((pAd->CommonCfg.CountryRegion & 0x7f) == - REGION_31_BG_BAND)) { - ScanType = SCAN_PASSIVE; - } - /* We need to shorten active scan time in order for WZC connect issue */ - /* Chnage the channel scan time for CISCO stuff based on its IAPP announcement */ - if (ScanType == FAST_SCAN_ACTIVE) - RTMPSetTimer(&pAd->MlmeAux.ScanTimer, - FAST_ACTIVE_SCAN_TIME); - else /* must be SCAN_PASSIVE or SCAN_ACTIVE */ - { - if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED) - || (pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) - || (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) - ) { - if (pAd->MlmeAux.Channel > 14) - RTMPSetTimer(&pAd->MlmeAux.ScanTimer, - ScanTimeIn5gChannel); - else - RTMPSetTimer(&pAd->MlmeAux.ScanTimer, - MIN_CHANNEL_TIME); - } else - RTMPSetTimer(&pAd->MlmeAux.ScanTimer, - MAX_CHANNEL_TIME); - } - - if ((ScanType == SCAN_ACTIVE) - || (ScanType == FAST_SCAN_ACTIVE) - ) { - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - ScanNextChannel() allocate memory fail\n")); - - { - pAd->Mlme.SyncMachine.CurrState = - SYNC_IDLE; - Status = MLME_FAIL_NO_RESOURCE; - MlmeEnqueue(pAd, - MLME_CNTL_STATE_MACHINE, - MT2_SCAN_CONF, 2, &Status); - } - - return; - } - /* There is no need to send broadcast probe request if active scan is in effect. */ - if ((ScanType == SCAN_ACTIVE) - || (ScanType == FAST_SCAN_ACTIVE) - ) - SsidLen = pAd->MlmeAux.SsidLen; - else - SsidLen = 0; - - MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, - BROADCAST_ADDR, BROADCAST_ADDR); - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_header_802_11), &Hdr80211, 1, - &SsidIe, 1, &SsidLen, SsidLen, - pAd->MlmeAux.Ssid, 1, &SupRateIe, 1, - &pAd->CommonCfg.SupRateLen, - pAd->CommonCfg.SupRateLen, - pAd->CommonCfg.SupRate, END_OF_ARGS); - - if (pAd->CommonCfg.ExtRateLen) { - unsigned long Tmp; - MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp, - 1, &ExtRateIe, - 1, &pAd->CommonCfg.ExtRateLen, - pAd->CommonCfg.ExtRateLen, - pAd->CommonCfg.ExtRate, - END_OF_ARGS); - FrameLen += Tmp; - } - - if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) { - unsigned long Tmp; - u8 HtLen; - u8 BROADCOM[4] = { 0x0, 0x90, 0x4c, 0x33 }; - - if (pAd->bBroadComHT == TRUE) { - HtLen = - pAd->MlmeAux.HtCapabilityLen + 4; - - MakeOutgoingFrame(pOutBuffer + FrameLen, - &Tmp, 1, &WpaIe, 1, - &HtLen, 4, - &BROADCOM[0], - pAd->MlmeAux. - HtCapabilityLen, - &pAd->MlmeAux. - HtCapability, - END_OF_ARGS); - } else { - HtLen = pAd->MlmeAux.HtCapabilityLen; - - MakeOutgoingFrame(pOutBuffer + FrameLen, - &Tmp, 1, &HtCapIe, 1, - &HtLen, HtLen, - &pAd->CommonCfg. - HtCapability, - END_OF_ARGS); - } - FrameLen += Tmp; - } - - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - } - /* For SCAN_CISCO_PASSIVE, do nothing and silently wait for beacon or other probe response */ - - pAd->Mlme.SyncMachine.CurrState = SCAN_LISTEN; - } -} - -void MgtProbReqMacHeaderInit(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 * pHdr80211, - u8 SubType, - u8 ToDs, u8 *pDA, u8 *pBssid) -{ - NdisZeroMemory(pHdr80211, sizeof(struct rt_header_802_11)); - - pHdr80211->FC.Type = BTYPE_MGMT; - pHdr80211->FC.SubType = SubType; - if (SubType == SUBTYPE_ACK) - pHdr80211->FC.Type = BTYPE_CNTL; - pHdr80211->FC.ToDs = ToDs; - COPY_MAC_ADDR(pHdr80211->Addr1, pDA); - COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress); - COPY_MAC_ADDR(pHdr80211->Addr3, pBssid); -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_tkip.c b/trunk/drivers/staging/rt2860/common/cmm_tkip.c deleted file mode 100644 index 4881ef9ba022..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_tkip.c +++ /dev/null @@ -1,833 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - cmm_tkip.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Paul Wu 02-25-02 Initial -*/ - -#include "../rt_config.h" - -/* Rotation functions on 32 bit values */ -#define ROL32( A, n ) \ - ( ((A) << (n)) | ( ((A)>>(32-(n))) & ( (1UL << (n)) - 1 ) ) ) -#define ROR32( A, n ) ROL32( (A), 32-(n) ) - -u32 Tkip_Sbox_Lower[256] = { - 0xA5, 0x84, 0x99, 0x8D, 0x0D, 0xBD, 0xB1, 0x54, - 0x50, 0x03, 0xA9, 0x7D, 0x19, 0x62, 0xE6, 0x9A, - 0x45, 0x9D, 0x40, 0x87, 0x15, 0xEB, 0xC9, 0x0B, - 0xEC, 0x67, 0xFD, 0xEA, 0xBF, 0xF7, 0x96, 0x5B, - 0xC2, 0x1C, 0xAE, 0x6A, 0x5A, 0x41, 0x02, 0x4F, - 0x5C, 0xF4, 0x34, 0x08, 0x93, 0x73, 0x53, 0x3F, - 0x0C, 0x52, 0x65, 0x5E, 0x28, 0xA1, 0x0F, 0xB5, - 0x09, 0x36, 0x9B, 0x3D, 0x26, 0x69, 0xCD, 0x9F, - 0x1B, 0x9E, 0x74, 0x2E, 0x2D, 0xB2, 0xEE, 0xFB, - 0xF6, 0x4D, 0x61, 0xCE, 0x7B, 0x3E, 0x71, 0x97, - 0xF5, 0x68, 0x00, 0x2C, 0x60, 0x1F, 0xC8, 0xED, - 0xBE, 0x46, 0xD9, 0x4B, 0xDE, 0xD4, 0xE8, 0x4A, - 0x6B, 0x2A, 0xE5, 0x16, 0xC5, 0xD7, 0x55, 0x94, - 0xCF, 0x10, 0x06, 0x81, 0xF0, 0x44, 0xBA, 0xE3, - 0xF3, 0xFE, 0xC0, 0x8A, 0xAD, 0xBC, 0x48, 0x04, - 0xDF, 0xC1, 0x75, 0x63, 0x30, 0x1A, 0x0E, 0x6D, - 0x4C, 0x14, 0x35, 0x2F, 0xE1, 0xA2, 0xCC, 0x39, - 0x57, 0xF2, 0x82, 0x47, 0xAC, 0xE7, 0x2B, 0x95, - 0xA0, 0x98, 0xD1, 0x7F, 0x66, 0x7E, 0xAB, 0x83, - 0xCA, 0x29, 0xD3, 0x3C, 0x79, 0xE2, 0x1D, 0x76, - 0x3B, 0x56, 0x4E, 0x1E, 0xDB, 0x0A, 0x6C, 0xE4, - 0x5D, 0x6E, 0xEF, 0xA6, 0xA8, 0xA4, 0x37, 0x8B, - 0x32, 0x43, 0x59, 0xB7, 0x8C, 0x64, 0xD2, 0xE0, - 0xB4, 0xFA, 0x07, 0x25, 0xAF, 0x8E, 0xE9, 0x18, - 0xD5, 0x88, 0x6F, 0x72, 0x24, 0xF1, 0xC7, 0x51, - 0x23, 0x7C, 0x9C, 0x21, 0xDD, 0xDC, 0x86, 0x85, - 0x90, 0x42, 0xC4, 0xAA, 0xD8, 0x05, 0x01, 0x12, - 0xA3, 0x5F, 0xF9, 0xD0, 0x91, 0x58, 0x27, 0xB9, - 0x38, 0x13, 0xB3, 0x33, 0xBB, 0x70, 0x89, 0xA7, - 0xB6, 0x22, 0x92, 0x20, 0x49, 0xFF, 0x78, 0x7A, - 0x8F, 0xF8, 0x80, 0x17, 0xDA, 0x31, 0xC6, 0xB8, - 0xC3, 0xB0, 0x77, 0x11, 0xCB, 0xFC, 0xD6, 0x3A -}; - -u32 Tkip_Sbox_Upper[256] = { - 0xC6, 0xF8, 0xEE, 0xF6, 0xFF, 0xD6, 0xDE, 0x91, - 0x60, 0x02, 0xCE, 0x56, 0xE7, 0xB5, 0x4D, 0xEC, - 0x8F, 0x1F, 0x89, 0xFA, 0xEF, 0xB2, 0x8E, 0xFB, - 0x41, 0xB3, 0x5F, 0x45, 0x23, 0x53, 0xE4, 0x9B, - 0x75, 0xE1, 0x3D, 0x4C, 0x6C, 0x7E, 0xF5, 0x83, - 0x68, 0x51, 0xD1, 0xF9, 0xE2, 0xAB, 0x62, 0x2A, - 0x08, 0x95, 0x46, 0x9D, 0x30, 0x37, 0x0A, 0x2F, - 0x0E, 0x24, 0x1B, 0xDF, 0xCD, 0x4E, 0x7F, 0xEA, - 0x12, 0x1D, 0x58, 0x34, 0x36, 0xDC, 0xB4, 0x5B, - 0xA4, 0x76, 0xB7, 0x7D, 0x52, 0xDD, 0x5E, 0x13, - 0xA6, 0xB9, 0x00, 0xC1, 0x40, 0xE3, 0x79, 0xB6, - 0xD4, 0x8D, 0x67, 0x72, 0x94, 0x98, 0xB0, 0x85, - 0xBB, 0xC5, 0x4F, 0xED, 0x86, 0x9A, 0x66, 0x11, - 0x8A, 0xE9, 0x04, 0xFE, 0xA0, 0x78, 0x25, 0x4B, - 0xA2, 0x5D, 0x80, 0x05, 0x3F, 0x21, 0x70, 0xF1, - 0x63, 0x77, 0xAF, 0x42, 0x20, 0xE5, 0xFD, 0xBF, - 0x81, 0x18, 0x26, 0xC3, 0xBE, 0x35, 0x88, 0x2E, - 0x93, 0x55, 0xFC, 0x7A, 0xC8, 0xBA, 0x32, 0xE6, - 0xC0, 0x19, 0x9E, 0xA3, 0x44, 0x54, 0x3B, 0x0B, - 0x8C, 0xC7, 0x6B, 0x28, 0xA7, 0xBC, 0x16, 0xAD, - 0xDB, 0x64, 0x74, 0x14, 0x92, 0x0C, 0x48, 0xB8, - 0x9F, 0xBD, 0x43, 0xC4, 0x39, 0x31, 0xD3, 0xF2, - 0xD5, 0x8B, 0x6E, 0xDA, 0x01, 0xB1, 0x9C, 0x49, - 0xD8, 0xAC, 0xF3, 0xCF, 0xCA, 0xF4, 0x47, 0x10, - 0x6F, 0xF0, 0x4A, 0x5C, 0x38, 0x57, 0x73, 0x97, - 0xCB, 0xA1, 0xE8, 0x3E, 0x96, 0x61, 0x0D, 0x0F, - 0xE0, 0x7C, 0x71, 0xCC, 0x90, 0x06, 0xF7, 0x1C, - 0xC2, 0x6A, 0xAE, 0x69, 0x17, 0x99, 0x3A, 0x27, - 0xD9, 0xEB, 0x2B, 0x22, 0xD2, 0xA9, 0x07, 0x33, - 0x2D, 0x3C, 0x15, 0xC9, 0x87, 0xAA, 0x50, 0xA5, - 0x03, 0x59, 0x09, 0x1A, 0x65, 0xD7, 0x84, 0xD0, - 0x82, 0x29, 0x5A, 0x1E, 0x7B, 0xA8, 0x6D, 0x2C -}; - -/* */ -/* Expanded IV for TKIP function. */ -/* */ -struct PACKED rt_tkip_iv { - union PACKED { - struct PACKED { - u8 rc0; - u8 rc1; - u8 rc2; - - union PACKED { - struct PACKED { - u8 Rsvd:5; - u8 ExtIV:1; - u8 KeyID:2; - } field; - u8 Byte; - } CONTROL; - } field; - - unsigned long word; - } IV16; - - unsigned long IV32; -}; - -/* - ======================================================================== - - Routine Description: - Convert from u8[] to unsigned long in a portable way - - Arguments: - pMICKey pointer to MIC Key - - Return Value: - None - - Note: - - ======================================================================== -*/ -unsigned long RTMPTkipGetUInt32(u8 *pMICKey) -{ - unsigned long res = 0; - int i; - - for (i = 0; i < 4; i++) { - res |= (*pMICKey++) << (8 * i); - } - - return res; -} - -/* - ======================================================================== - - Routine Description: - Convert from unsigned long to u8[] in a portable way - - Arguments: - pDst pointer to destination for convert unsigned long to u8[] - val the value for convert - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPTkipPutUInt32(IN u8 *pDst, unsigned long val) -{ - int i; - - for (i = 0; i < 4; i++) { - *pDst++ = (u8)(val & 0xff); - val >>= 8; - } -} - -/* - ======================================================================== - - Routine Description: - Set the MIC Key. - - Arguments: - pAd Pointer to our adapter - pMICKey pointer to MIC Key - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPTkipSetMICKey(struct rt_tkip_key_info *pTkip, u8 *pMICKey) -{ - /* Set the key */ - pTkip->K0 = RTMPTkipGetUInt32(pMICKey); - pTkip->K1 = RTMPTkipGetUInt32(pMICKey + 4); - /* and reset the message */ - pTkip->L = pTkip->K0; - pTkip->R = pTkip->K1; - pTkip->nBytesInM = 0; - pTkip->M = 0; -} - -/* - ======================================================================== - - Routine Description: - Calculate the MIC Value. - - Arguments: - pAd Pointer to our adapter - uChar Append this uChar - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPTkipAppendByte(struct rt_tkip_key_info *pTkip, u8 uChar) -{ - /* Append the byte to our word-sized buffer */ - pTkip->M |= (uChar << (8 * pTkip->nBytesInM)); - pTkip->nBytesInM++; - /* Process the word if it is full. */ - if (pTkip->nBytesInM >= 4) { - pTkip->L ^= pTkip->M; - pTkip->R ^= ROL32(pTkip->L, 17); - pTkip->L += pTkip->R; - pTkip->R ^= - ((pTkip->L & 0xff00ff00) >> 8) | ((pTkip-> - L & 0x00ff00ff) << 8); - pTkip->L += pTkip->R; - pTkip->R ^= ROL32(pTkip->L, 3); - pTkip->L += pTkip->R; - pTkip->R ^= ROR32(pTkip->L, 2); - pTkip->L += pTkip->R; - /* Clear the buffer */ - pTkip->M = 0; - pTkip->nBytesInM = 0; - } -} - -/* - ======================================================================== - - Routine Description: - Calculate the MIC Value. - - Arguments: - pAd Pointer to our adapter - pSrc Pointer to source data for Calculate MIC Value - Len Indicate the length of the source data - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPTkipAppend(struct rt_tkip_key_info *pTkip, u8 *pSrc, u32 nBytes) -{ - /* This is simple */ - while (nBytes > 0) { - RTMPTkipAppendByte(pTkip, *pSrc++); - nBytes--; - } -} - -/* - ======================================================================== - - Routine Description: - Get the MIC Value. - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - the MIC Value is store in pAd->PrivateInfo.MIC - ======================================================================== -*/ -void RTMPTkipGetMIC(struct rt_tkip_key_info *pTkip) -{ - /* Append the minimum padding */ - RTMPTkipAppendByte(pTkip, 0x5a); - RTMPTkipAppendByte(pTkip, 0); - RTMPTkipAppendByte(pTkip, 0); - RTMPTkipAppendByte(pTkip, 0); - RTMPTkipAppendByte(pTkip, 0); - /* and then zeroes until the length is a multiple of 4 */ - while (pTkip->nBytesInM != 0) { - RTMPTkipAppendByte(pTkip, 0); - } - /* The appendByte function has already computed the result. */ - RTMPTkipPutUInt32(pTkip->MIC, pTkip->L); - RTMPTkipPutUInt32(pTkip->MIC + 4, pTkip->R); -} - -/* - ======================================================================== - - Routine Description: - Init Tkip function. - - Arguments: - pAd Pointer to our adapter - pTKey Pointer to the Temporal Key (TK), TK shall be 128bits. - KeyId TK Key ID - pTA Pointer to transmitter address - pMICKey pointer to MIC Key - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPInitTkipEngine(struct rt_rtmp_adapter *pAd, - u8 *pKey, - u8 KeyId, - u8 *pTA, - u8 *pMICKey, - u8 *pTSC, unsigned long *pIV16, unsigned long *pIV32) -{ - struct rt_tkip_iv tkipIv; - - /* Prepare 8 bytes TKIP encapsulation for MPDU */ - NdisZeroMemory(&tkipIv, sizeof(struct rt_tkip_iv)); - tkipIv.IV16.field.rc0 = *(pTSC + 1); - tkipIv.IV16.field.rc1 = (tkipIv.IV16.field.rc0 | 0x20) & 0x7f; - tkipIv.IV16.field.rc2 = *pTSC; - tkipIv.IV16.field.CONTROL.field.ExtIV = 1; /* 0: non-extended IV, 1: an extended IV */ - tkipIv.IV16.field.CONTROL.field.KeyID = KeyId; -/* tkipIv.IV32 = *(unsigned long *)(pTSC + 2); */ - NdisMoveMemory(&tkipIv.IV32, (pTSC + 2), 4); /* Copy IV */ - - *pIV16 = tkipIv.IV16.word; - *pIV32 = tkipIv.IV32; -} - -/* - ======================================================================== - - Routine Description: - Init MIC Value calculation function which include set MIC key & - calculate first 16 bytes (DA + SA + priority + 0) - - Arguments: - pAd Pointer to our adapter - pTKey Pointer to the Temporal Key (TK), TK shall be 128bits. - pDA Pointer to DA address - pSA Pointer to SA address - pMICKey pointer to MIC Key - - Return Value: - None - - Note: - - ======================================================================== -*/ -void RTMPInitMICEngine(struct rt_rtmp_adapter *pAd, - u8 *pKey, - u8 *pDA, - u8 *pSA, u8 UserPriority, u8 *pMICKey) -{ - unsigned long Priority = UserPriority; - - /* Init MIC value calculation */ - RTMPTkipSetMICKey(&pAd->PrivateInfo.Tx, pMICKey); - /* DA */ - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pDA, MAC_ADDR_LEN); - /* SA */ - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSA, MAC_ADDR_LEN); - /* Priority + 3 bytes of 0 */ - RTMPTkipAppend(&pAd->PrivateInfo.Tx, (u8 *)& Priority, 4); -} - -/* - ======================================================================== - - Routine Description: - Compare MIC value of received MSDU - - Arguments: - pAd Pointer to our adapter - pSrc Pointer to the received Plain text data - pDA Pointer to DA address - pSA Pointer to SA address - pMICKey pointer to MIC Key - Len the length of the received plain text data exclude MIC value - - Return Value: - TRUE MIC value matched - FALSE MIC value mismatched - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -BOOLEAN RTMPTkipCompareMICValue(struct rt_rtmp_adapter *pAd, - u8 *pSrc, - u8 *pDA, - u8 *pSA, - u8 *pMICKey, - u8 UserPriority, u32 Len) -{ - u8 OldMic[8]; - unsigned long Priority = UserPriority; - - /* Init MIC value calculation */ - RTMPTkipSetMICKey(&pAd->PrivateInfo.Rx, pMICKey); - /* DA */ - RTMPTkipAppend(&pAd->PrivateInfo.Rx, pDA, MAC_ADDR_LEN); - /* SA */ - RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSA, MAC_ADDR_LEN); - /* Priority + 3 bytes of 0 */ - RTMPTkipAppend(&pAd->PrivateInfo.Rx, (u8 *)& Priority, 4); - - /* Calculate MIC value from plain text data */ - RTMPTkipAppend(&pAd->PrivateInfo.Rx, pSrc, Len); - - /* Get MIC valude from received frame */ - NdisMoveMemory(OldMic, pSrc + Len, 8); - - /* Get MIC value from decrypted plain data */ - RTMPTkipGetMIC(&pAd->PrivateInfo.Rx); - - /* Move MIC value from MSDU, this steps should move to data path. */ - /* Since the MIC value might cross MPDUs. */ - if (!NdisEqualMemory(pAd->PrivateInfo.Rx.MIC, OldMic, 8)) { - DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTMPTkipCompareMICValue(): TKIP MIC Error !\n")); /*MIC error. */ - - return (FALSE); - } - return (TRUE); -} - -/* - ======================================================================== - - Routine Description: - Copy frame from waiting queue into relative ring buffer and set - appropriate ASIC register to kick hardware transmit function - - Arguments: - pAd Pointer to our adapter - void * Pointer to Ndis Packet for MIC calculation - pEncap Pointer to LLC encap data - LenEncap Total encap length, might be 0 which indicates no encap - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPCalculateMICValue(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 *pEncap, - struct rt_cipher_key *pKey, u8 apidx) -{ - struct rt_packet_info PacketInfo; - u8 *pSrcBufVA; - u32 SrcBufLen; - u8 *pSrc; - u8 UserPriority; - u8 vlan_offset = 0; - - RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen); - - UserPriority = RTMP_GET_PACKET_UP(pPacket); - pSrc = pSrcBufVA; - - /* determine if this is a vlan packet */ - if (((*(pSrc + 12) << 8) + *(pSrc + 13)) == 0x8100) - vlan_offset = 4; - - { - RTMPInitMICEngine(pAd, - pKey->Key, - pSrc, pSrc + 6, UserPriority, pKey->TxMic); - } - - if (pEncap != NULL) { - /* LLC encapsulation */ - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pEncap, 6); - /* Protocol Type */ - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSrc + 12 + vlan_offset, - 2); - } - SrcBufLen -= (14 + vlan_offset); - pSrc += (14 + vlan_offset); - do { - if (SrcBufLen > 0) { - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pSrc, SrcBufLen); - } - - break; /* No need handle next packet */ - - } while (TRUE); /* End of copying payload */ - - /* Compute the final MIC Value */ - RTMPTkipGetMIC(&pAd->PrivateInfo.Tx); -} - -/************************************************************/ -/* tkip_sbox() */ -/* Returns a 16 bit value from a 64K entry table. The Table */ -/* is synthesized from two 256 entry byte wide tables. */ -/************************************************************/ - -u32 tkip_sbox(u32 index) -{ - u32 index_low; - u32 index_high; - u32 left, right; - - index_low = (index % 256); - index_high = ((index >> 8) % 256); - - left = Tkip_Sbox_Lower[index_low] + (Tkip_Sbox_Upper[index_low] * 256); - right = - Tkip_Sbox_Upper[index_high] + (Tkip_Sbox_Lower[index_high] * 256); - - return (left ^ right); -} - -u32 rotr1(u32 a) -{ - unsigned int b; - - if ((a & 0x01) == 0x01) { - b = (a >> 1) | 0x8000; - } else { - b = (a >> 1) & 0x7fff; - } - b = b % 65536; - return b; -} - -void RTMPTkipMixKey(u8 * key, u8 * ta, unsigned long pnl, /* Least significant 16 bits of PN */ - unsigned long pnh, /* Most significant 32 bits of PN */ - u8 * rc4key, u32 * p1k) -{ - - u32 tsc0; - u32 tsc1; - u32 tsc2; - - u32 ppk0; - u32 ppk1; - u32 ppk2; - u32 ppk3; - u32 ppk4; - u32 ppk5; - - int i; - int j; - - tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */ - tsc1 = (unsigned int)(pnh % 65536); - tsc2 = (unsigned int)(pnl % 65536); /* lsb */ - - /* Phase 1, step 1 */ - p1k[0] = tsc1; - p1k[1] = tsc0; - p1k[2] = (u32)(ta[0] + (ta[1] * 256)); - p1k[3] = (u32)(ta[2] + (ta[3] * 256)); - p1k[4] = (u32)(ta[4] + (ta[5] * 256)); - - /* Phase 1, step 2 */ - for (i = 0; i < 8; i++) { - j = 2 * (i & 1); - p1k[0] = - (p1k[0] + - tkip_sbox((p1k[4] ^ ((256 * key[1 + j]) + key[j])) % - 65536)) % 65536; - p1k[1] = - (p1k[1] + - tkip_sbox((p1k[0] ^ ((256 * key[5 + j]) + key[4 + j])) % - 65536)) % 65536; - p1k[2] = - (p1k[2] + - tkip_sbox((p1k[1] ^ ((256 * key[9 + j]) + key[8 + j])) % - 65536)) % 65536; - p1k[3] = - (p1k[3] + - tkip_sbox((p1k[2] ^ ((256 * key[13 + j]) + key[12 + j])) % - 65536)) % 65536; - p1k[4] = - (p1k[4] + - tkip_sbox((p1k[3] ^ (((256 * key[1 + j]) + key[j]))) % - 65536)) % 65536; - p1k[4] = (p1k[4] + i) % 65536; - } - - /* Phase 2, Step 1 */ - ppk0 = p1k[0]; - ppk1 = p1k[1]; - ppk2 = p1k[2]; - ppk3 = p1k[3]; - ppk4 = p1k[4]; - ppk5 = (p1k[4] + tsc2) % 65536; - - /* Phase2, Step 2 */ - ppk0 = ppk0 + tkip_sbox((ppk5 ^ ((256 * key[1]) + key[0])) % 65536); - ppk1 = ppk1 + tkip_sbox((ppk0 ^ ((256 * key[3]) + key[2])) % 65536); - ppk2 = ppk2 + tkip_sbox((ppk1 ^ ((256 * key[5]) + key[4])) % 65536); - ppk3 = ppk3 + tkip_sbox((ppk2 ^ ((256 * key[7]) + key[6])) % 65536); - ppk4 = ppk4 + tkip_sbox((ppk3 ^ ((256 * key[9]) + key[8])) % 65536); - ppk5 = ppk5 + tkip_sbox((ppk4 ^ ((256 * key[11]) + key[10])) % 65536); - - ppk0 = ppk0 + rotr1(ppk5 ^ ((256 * key[13]) + key[12])); - ppk1 = ppk1 + rotr1(ppk0 ^ ((256 * key[15]) + key[14])); - ppk2 = ppk2 + rotr1(ppk1); - ppk3 = ppk3 + rotr1(ppk2); - ppk4 = ppk4 + rotr1(ppk3); - ppk5 = ppk5 + rotr1(ppk4); - - /* Phase 2, Step 3 */ - /* Phase 2, Step 3 */ - - tsc0 = (unsigned int)((pnh >> 16) % 65536); /* msb */ - tsc1 = (unsigned int)(pnh % 65536); - tsc2 = (unsigned int)(pnl % 65536); /* lsb */ - - rc4key[0] = (tsc2 >> 8) % 256; - rc4key[1] = (((tsc2 >> 8) % 256) | 0x20) & 0x7f; - rc4key[2] = tsc2 % 256; - rc4key[3] = ((ppk5 ^ ((256 * key[1]) + key[0])) >> 1) % 256; - - rc4key[4] = ppk0 % 256; - rc4key[5] = (ppk0 >> 8) % 256; - - rc4key[6] = ppk1 % 256; - rc4key[7] = (ppk1 >> 8) % 256; - - rc4key[8] = ppk2 % 256; - rc4key[9] = (ppk2 >> 8) % 256; - - rc4key[10] = ppk3 % 256; - rc4key[11] = (ppk3 >> 8) % 256; - - rc4key[12] = ppk4 % 256; - rc4key[13] = (ppk4 >> 8) % 256; - - rc4key[14] = ppk5 % 256; - rc4key[15] = (ppk5 >> 8) % 256; -} - -/* */ -/* TRUE: Success! */ -/* FALSE: Decrypt Error! */ -/* */ -BOOLEAN RTMPSoftDecryptTKIP(struct rt_rtmp_adapter *pAd, - u8 *pData, - unsigned long DataByteCnt, - u8 UserPriority, struct rt_cipher_key *pWpaKey) -{ - u8 KeyID; - u32 HeaderLen; - u8 fc0; - u8 fc1; - u16 fc; - u32 frame_type; - u32 frame_subtype; - u32 from_ds; - u32 to_ds; - int a4_exists; - int qc_exists; - u16 duration; - u16 seq_control; - u16 qos_control; - u8 TA[MAC_ADDR_LEN]; - u8 DA[MAC_ADDR_LEN]; - u8 SA[MAC_ADDR_LEN]; - u8 RC4Key[16]; - u32 p1k[5]; /*for mix_key; */ - unsigned long pnl; /* Least significant 16 bits of PN */ - unsigned long pnh; /* Most significant 32 bits of PN */ - u32 num_blocks; - u32 payload_remainder; - struct rt_arcfourcontext ArcFourContext; - u32 crc32 = 0; - u32 trailfcs = 0; - u8 MIC[8]; - u8 TrailMIC[8]; - - fc0 = *pData; - fc1 = *(pData + 1); - - fc = *((u16 *)pData); - - frame_type = ((fc0 >> 2) & 0x03); - frame_subtype = ((fc0 >> 4) & 0x0f); - - from_ds = (fc1 & 0x2) >> 1; - to_ds = (fc1 & 0x1); - - a4_exists = (from_ds & to_ds); - qc_exists = ((frame_subtype == 0x08) || /* Assumed QoS subtypes */ - (frame_subtype == 0x09) || /* Likely to change. */ - (frame_subtype == 0x0a) || (frame_subtype == 0x0b) - ); - - HeaderLen = 24; - if (a4_exists) - HeaderLen += 6; - - KeyID = *((u8 *)(pData + HeaderLen + 3)); - KeyID = KeyID >> 6; - - if (pWpaKey[KeyID].KeyLen == 0) { - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPSoftDecryptTKIP failed!(KeyID[%d] Length can not be 0)\n", - KeyID)); - return FALSE; - } - - duration = *((u16 *)(pData + 2)); - - seq_control = *((u16 *)(pData + 22)); - - if (qc_exists) { - if (a4_exists) { - qos_control = *((u16 *)(pData + 30)); - } else { - qos_control = *((u16 *)(pData + 24)); - } - } - - if (to_ds == 0 && from_ds == 1) { - NdisMoveMemory(DA, pData + 4, MAC_ADDR_LEN); - NdisMoveMemory(SA, pData + 16, MAC_ADDR_LEN); - NdisMoveMemory(TA, pData + 10, MAC_ADDR_LEN); /*BSSID */ - } else if (to_ds == 0 && from_ds == 0) { - NdisMoveMemory(TA, pData + 10, MAC_ADDR_LEN); - NdisMoveMemory(DA, pData + 4, MAC_ADDR_LEN); - NdisMoveMemory(SA, pData + 10, MAC_ADDR_LEN); - } else if (to_ds == 1 && from_ds == 0) { - NdisMoveMemory(SA, pData + 10, MAC_ADDR_LEN); - NdisMoveMemory(TA, pData + 10, MAC_ADDR_LEN); - NdisMoveMemory(DA, pData + 16, MAC_ADDR_LEN); - } else if (to_ds == 1 && from_ds == 1) { - NdisMoveMemory(TA, pData + 10, MAC_ADDR_LEN); - NdisMoveMemory(DA, pData + 16, MAC_ADDR_LEN); - NdisMoveMemory(SA, pData + 22, MAC_ADDR_LEN); - } - - num_blocks = (DataByteCnt - 16) / 16; - payload_remainder = (DataByteCnt - 16) % 16; - - pnl = (*(pData + HeaderLen)) * 256 + *(pData + HeaderLen + 2); - pnh = *((unsigned long *)(pData + HeaderLen + 4)); - pnh = cpu2le32(pnh); - RTMPTkipMixKey(pWpaKey[KeyID].Key, TA, pnl, pnh, RC4Key, p1k); - - ARCFOUR_INIT(&ArcFourContext, RC4Key, 16); - - ARCFOUR_DECRYPT(&ArcFourContext, pData + HeaderLen, - pData + HeaderLen + 8, DataByteCnt - HeaderLen - 8); - NdisMoveMemory(&trailfcs, pData + DataByteCnt - 8 - 4, 4); - crc32 = RTMP_CALC_FCS32(PPPINITFCS32, pData + HeaderLen, DataByteCnt - HeaderLen - 8 - 4); /*Skip IV+EIV 8 bytes & Skip last 4 bytes(FCS). */ - crc32 ^= 0xffffffff; /* complement */ - - if (crc32 != cpu2le32(trailfcs)) { - DBGPRINT(RT_DEBUG_TRACE, ("RTMPSoftDecryptTKIP, WEP Data ICV Error !\n")); /*ICV error. */ - - return (FALSE); - } - - NdisMoveMemory(TrailMIC, pData + DataByteCnt - 8 - 8 - 4, 8); - RTMPInitMICEngine(pAd, pWpaKey[KeyID].Key, DA, SA, UserPriority, - pWpaKey[KeyID].RxMic); - RTMPTkipAppend(&pAd->PrivateInfo.Tx, pData + HeaderLen, - DataByteCnt - HeaderLen - 8 - 12); - RTMPTkipGetMIC(&pAd->PrivateInfo.Tx); - NdisMoveMemory(MIC, pAd->PrivateInfo.Tx.MIC, 8); - - if (!NdisEqualMemory(MIC, TrailMIC, 8)) { - DBGPRINT(RT_DEBUG_ERROR, ("RTMPSoftDecryptTKIP, WEP Data MIC Error !\n")); /*MIC error. */ - /*RTMPReportMicError(pAd, &pWpaKey[KeyID]); // marked by AlbertY @ 20060630 */ - return (FALSE); - } - /*DBGPRINT(RT_DEBUG_TRACE, "RTMPSoftDecryptTKIP Decript done!\n"); */ - return TRUE; -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_wep.c b/trunk/drivers/staging/rt2860/common/cmm_wep.c deleted file mode 100644 index 76f880cb39b0..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_wep.c +++ /dev/null @@ -1,473 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_wep.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Paul Wu 10-28-02 Initial -*/ - -#include "../rt_config.h" - -u32 FCSTAB_32[256] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, - 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, - 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, - 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, - 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, - 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, - 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, - 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, - 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, - 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, - 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, - 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, - 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, - 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, - 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, - 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, - 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, - 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, - 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, - 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, - 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, - 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, - 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, - 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, - 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, - 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, - 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, - 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, - 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, - 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, - 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, - 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, - 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, - 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, - 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, - 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, - 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, - 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, - 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d -}; - -/* -u8 WEPKEY[] = { - //IV - 0x00, 0x11, 0x22, - //WEP KEY - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC - }; - */ - -/* - ======================================================================== - - Routine Description: - Init WEP function. - - Arguments: - pAd Pointer to our adapter - pKey Pointer to the WEP KEY - KeyId WEP Key ID - KeyLen the length of WEP KEY - pDest Pointer to the destination which Encryption data will store in. - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPInitWepEngine(struct rt_rtmp_adapter *pAd, - u8 *pKey, - u8 KeyId, u8 KeyLen, IN u8 *pDest) -{ - u32 i; - u8 WEPKEY[] = { - /*IV */ - 0x00, 0x11, 0x22, - /*WEP KEY */ - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, - 0xAA, 0xBB, 0xCC - }; - - pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; /*Init crc32. */ - - { - NdisMoveMemory(WEPKEY + 3, pKey, KeyLen); - - for (i = 0; i < 3; i++) - WEPKEY[i] = RandomByte(pAd); /*Call mlme RandomByte() function. */ - ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, WEPKEY, KeyLen + 3); /*INIT SBOX, KEYLEN+3(IV) */ - - NdisMoveMemory(pDest, WEPKEY, 3); /*Append Init Vector */ - } - *(pDest + 3) = (KeyId << 6); /*Append KEYID */ - -} - -/* - ======================================================================== - - Routine Description: - Encrypt transimitted data - - Arguments: - pAd Pointer to our adapter - pSrc Pointer to the transimitted source data that will be encrypt - pDest Pointer to the destination where entryption data will be store in. - Len Indicate the length of the source data - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPEncryptData(struct rt_rtmp_adapter *pAd, - u8 *pSrc, u8 *pDest, u32 Len) -{ - pAd->PrivateInfo.FCSCRC32 = - RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, pSrc, Len); - ARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, pDest, pSrc, Len); -} - -/* - ======================================================================== - - Routine Description: - Decrypt received WEP data - - Arguments: - pAdapter Pointer to our adapter - pSrc Pointer to the received data - Len the length of the received data - - Return Value: - TRUE Decrypt WEP data success - FALSE Decrypt WEP data failed - - Note: - - ======================================================================== -*/ -BOOLEAN RTMPSoftDecryptWEP(struct rt_rtmp_adapter *pAd, - u8 *pData, - unsigned long DataByteCnt, struct rt_cipher_key *pGroupKey) -{ - u32 trailfcs; - u32 crc32; - u8 KeyIdx; - u8 WEPKEY[] = { - /*IV */ - 0x00, 0x11, 0x22, - /*WEP KEY */ - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, - 0xAA, 0xBB, 0xCC - }; - u8 *pPayload = (u8 *) pData + LENGTH_802_11; - unsigned long payload_len = DataByteCnt - LENGTH_802_11; - - NdisMoveMemory(WEPKEY, pPayload, 3); /*Get WEP IV */ - - KeyIdx = (*(pPayload + 3) & 0xc0) >> 6; - if (pGroupKey[KeyIdx].KeyLen == 0) - return (FALSE); - - NdisMoveMemory(WEPKEY + 3, pGroupKey[KeyIdx].Key, - pGroupKey[KeyIdx].KeyLen); - ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, WEPKEY, - pGroupKey[KeyIdx].KeyLen + 3); - ARCFOUR_DECRYPT(&pAd->PrivateInfo.WEPCONTEXT, pPayload, pPayload + 4, - payload_len - 4); - NdisMoveMemory(&trailfcs, pPayload + payload_len - 8, 4); - crc32 = RTMP_CALC_FCS32(PPPINITFCS32, pPayload, payload_len - 8); /*Skip last 4 bytes(FCS). */ - crc32 ^= 0xffffffff; /* complement */ - - if (crc32 != cpu2le32(trailfcs)) { - DBGPRINT(RT_DEBUG_TRACE, ("WEP Data CRC Error!\n")); /*CRC error. */ - return (FALSE); - } - return (TRUE); -} - -/* - ======================================================================== - - Routine Description: - The Stream Cipher Encryption Algorithm "struct rt_arcfour" initialize - - Arguments: - Ctx Pointer to struct rt_arcfour CONTEXT (SBOX) - pKey Pointer to the WEP KEY - KeyLen Indicate the length fo the WEP KEY - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void ARCFOUR_INIT(struct rt_arcfourcontext *Ctx, u8 *pKey, u32 KeyLen) -{ - u8 t, u; - u32 keyindex; - u32 stateindex; - u8 *state; - u32 counter; - - state = Ctx->STATE; - Ctx->X = 0; - Ctx->Y = 0; - for (counter = 0; counter < 256; counter++) - state[counter] = (u8)counter; - keyindex = 0; - stateindex = 0; - for (counter = 0; counter < 256; counter++) { - t = state[counter]; - stateindex = (stateindex + pKey[keyindex] + t) & 0xff; - u = state[stateindex]; - state[stateindex] = t; - state[counter] = u; - if (++keyindex >= KeyLen) - keyindex = 0; - } -} - -/* - ======================================================================== - - Routine Description: - Get bytes from struct rt_arcfour CONTEXT (S-BOX) - - Arguments: - Ctx Pointer to struct rt_arcfour CONTEXT (SBOX) - - Return Value: - u8 - the value of the struct rt_arcfour CONTEXT (S-BOX) - - Note: - - ======================================================================== -*/ -u8 ARCFOUR_BYTE(struct rt_arcfourcontext *Ctx) -{ - u32 x; - u32 y; - u8 sx, sy; - u8 *state; - - state = Ctx->STATE; - x = (Ctx->X + 1) & 0xff; - sx = state[x]; - y = (sx + Ctx->Y) & 0xff; - sy = state[y]; - Ctx->X = x; - Ctx->Y = y; - state[y] = sx; - state[x] = sy; - - return (state[(sx + sy) & 0xff]); - -} - -/* - ======================================================================== - - Routine Description: - The Stream Cipher Decryption Algorithm - - Arguments: - Ctx Pointer to struct rt_arcfour CONTEXT (SBOX) - pDest Pointer to the Destination - pSrc Pointer to the Source data - Len Indicate the length of the Source data - - Return Value: - None - - Note: - - ======================================================================== -*/ -void ARCFOUR_DECRYPT(struct rt_arcfourcontext *Ctx, - u8 *pDest, u8 *pSrc, u32 Len) -{ - u32 i; - - for (i = 0; i < Len; i++) - pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx); -} - -/* - ======================================================================== - - Routine Description: - The Stream Cipher Encryption Algorithm - - Arguments: - Ctx Pointer to struct rt_arcfour CONTEXT (SBOX) - pDest Pointer to the Destination - pSrc Pointer to the Source data - Len Indicate the length of the Source dta - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void ARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx, - u8 *pDest, u8 *pSrc, u32 Len) -{ - u32 i; - - for (i = 0; i < Len; i++) - pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx); -} - -/* - ======================================================================== - - Routine Description: - The Stream Cipher Encryption Algorithm which conform to the special requirement to encrypt GTK. - - Arguments: - Ctx Pointer to struct rt_arcfour CONTEXT (SBOX) - pDest Pointer to the Destination - pSrc Pointer to the Source data - Len Indicate the length of the Source dta - - ======================================================================== -*/ - -void WPAARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx, - u8 *pDest, u8 *pSrc, u32 Len) -{ - u32 i; - /*discard first 256 bytes */ - for (i = 0; i < 256; i++) - ARCFOUR_BYTE(Ctx); - - for (i = 0; i < Len; i++) - pDest[i] = pSrc[i] ^ ARCFOUR_BYTE(Ctx); -} - -/* - ======================================================================== - - Routine Description: - Calculate a new FCS given the current FCS and the new data. - - Arguments: - Fcs the original FCS value - Cp pointer to the data which will be calculate the FCS - Len the length of the data - - Return Value: - u32 - FCS 32 bits - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -u32 RTMP_CALC_FCS32(u32 Fcs, u8 *Cp, int Len) -{ - while (Len--) - Fcs = (((Fcs) >> 8) ^ FCSTAB_32[((Fcs) ^ (*Cp++)) & 0xff]); - - return (Fcs); -} - -/* - ======================================================================== - - Routine Description: - Get last FCS and encrypt it to the destination - - Arguments: - pDest Pointer to the Destination - - Return Value: - None - - Note: - - ======================================================================== -*/ -void RTMPSetICV(struct rt_rtmp_adapter *pAd, u8 *pDest) -{ - pAd->PrivateInfo.FCSCRC32 ^= 0xffffffff; /* complement */ - pAd->PrivateInfo.FCSCRC32 = cpu2le32(pAd->PrivateInfo.FCSCRC32); - - ARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, pDest, - (u8 *)& pAd->PrivateInfo.FCSCRC32, 4); -} diff --git a/trunk/drivers/staging/rt2860/common/cmm_wpa.c b/trunk/drivers/staging/rt2860/common/cmm_wpa.c deleted file mode 100644 index 616ebec50c61..000000000000 --- a/trunk/drivers/staging/rt2860/common/cmm_wpa.c +++ /dev/null @@ -1,3010 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - wpa.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Jan Lee 03-07-22 Initial - Paul Lin 03-11-28 Modify for supplicant -*/ -#include "../rt_config.h" -/* WPA OUI */ -u8 OUI_WPA_NONE_AKM[4] = { 0x00, 0x50, 0xF2, 0x00 }; -u8 OUI_WPA_VERSION[4] = { 0x00, 0x50, 0xF2, 0x01 }; -u8 OUI_WPA_WEP40[4] = { 0x00, 0x50, 0xF2, 0x01 }; -u8 OUI_WPA_TKIP[4] = { 0x00, 0x50, 0xF2, 0x02 }; -u8 OUI_WPA_CCMP[4] = { 0x00, 0x50, 0xF2, 0x04 }; -u8 OUI_WPA_WEP104[4] = { 0x00, 0x50, 0xF2, 0x05 }; -u8 OUI_WPA_8021X_AKM[4] = { 0x00, 0x50, 0xF2, 0x01 }; -u8 OUI_WPA_PSK_AKM[4] = { 0x00, 0x50, 0xF2, 0x02 }; - -/* WPA2 OUI */ -u8 OUI_WPA2_WEP40[4] = { 0x00, 0x0F, 0xAC, 0x01 }; -u8 OUI_WPA2_TKIP[4] = { 0x00, 0x0F, 0xAC, 0x02 }; -u8 OUI_WPA2_CCMP[4] = { 0x00, 0x0F, 0xAC, 0x04 }; -u8 OUI_WPA2_8021X_AKM[4] = { 0x00, 0x0F, 0xAC, 0x01 }; -u8 OUI_WPA2_PSK_AKM[4] = { 0x00, 0x0F, 0xAC, 0x02 }; -u8 OUI_WPA2_WEP104[4] = { 0x00, 0x0F, 0xAC, 0x05 }; - -static void ConstructEapolKeyData(struct rt_mac_table_entry *pEntry, - u8 GroupKeyWepStatus, - u8 keyDescVer, - u8 MsgType, - u8 DefaultKeyIdx, - u8 * GTK, - u8 * RSNIE, - u8 RSNIE_LEN, struct rt_eapol_packet * pMsg); - -static void CalculateMIC(u8 KeyDescVer, - u8 * PTK, struct rt_eapol_packet * pMsg); - -static void WpaEAPPacketAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -static void WpaEAPOLASFAlertAction(struct rt_rtmp_adapter *pAd, - struct rt_mlme_queue_elem *Elem); - -static void WpaEAPOLLogoffAction(struct rt_rtmp_adapter *pAd, - struct rt_mlme_queue_elem *Elem); - -static void WpaEAPOLStartAction(struct rt_rtmp_adapter *pAd, - struct rt_mlme_queue_elem *Elem); - -static void WpaEAPOLKeyAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -/* - ========================================================================== - Description: - association state machine init, including state transition and timer init - Parameters: - S - pointer to the association state machine - ========================================================================== - */ -void WpaStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[]) -{ - StateMachineInit(S, (STATE_MACHINE_FUNC *) Trans, MAX_WPA_PTK_STATE, - MAX_WPA_MSG, (STATE_MACHINE_FUNC) Drop, WPA_PTK, - WPA_MACHINE_BASE); - - StateMachineSetAction(S, WPA_PTK, MT2_EAPPacket, - (STATE_MACHINE_FUNC) WpaEAPPacketAction); - StateMachineSetAction(S, WPA_PTK, MT2_EAPOLStart, - (STATE_MACHINE_FUNC) WpaEAPOLStartAction); - StateMachineSetAction(S, WPA_PTK, MT2_EAPOLLogoff, - (STATE_MACHINE_FUNC) WpaEAPOLLogoffAction); - StateMachineSetAction(S, WPA_PTK, MT2_EAPOLKey, - (STATE_MACHINE_FUNC) WpaEAPOLKeyAction); - StateMachineSetAction(S, WPA_PTK, MT2_EAPOLASFAlert, - (STATE_MACHINE_FUNC) WpaEAPOLASFAlertAction); -} - -/* - ========================================================================== - Description: - this is state machine function. - When receiving EAP packets which is for 802.1x authentication use. - Not use in PSK case - Return: - ========================================================================== -*/ -void WpaEAPPacketAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ -} - -void WpaEAPOLASFAlertAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ -} - -void WpaEAPOLLogoffAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ -} - -/* - ========================================================================== - Description: - Start 4-way HS when rcv EAPOL_START which may create by our driver in assoc.c - Return: - ========================================================================== -*/ -void WpaEAPOLStartAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_mac_table_entry *pEntry; - struct rt_header_802_11 * pHeader; - - DBGPRINT(RT_DEBUG_TRACE, ("WpaEAPOLStartAction ===> \n")); - - pHeader = (struct rt_header_802_11 *) Elem->Msg; - - /*For normaol PSK, we enqueue an EAPOL-Start command to trigger the process. */ - if (Elem->MsgLen == 6) - pEntry = MacTableLookup(pAd, Elem->Msg); - else { - pEntry = MacTableLookup(pAd, pHeader->Addr2); - } - - if (pEntry) { - DBGPRINT(RT_DEBUG_TRACE, - (" PortSecured(%d), WpaState(%d), AuthMode(%d), PMKID_CacheIdx(%d) \n", - pEntry->PortSecured, pEntry->WpaState, - pEntry->AuthMode, pEntry->PMKID_CacheIdx)); - - if ((pEntry->PortSecured == WPA_802_1X_PORT_NOT_SECURED) - && (pEntry->WpaState < AS_PTKSTART) - && ((pEntry->AuthMode == Ndis802_11AuthModeWPAPSK) - || (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK) - || ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) - && (pEntry->PMKID_CacheIdx != ENTRY_NOT_FOUND)))) { - pEntry->PrivacyFilter = Ndis802_11PrivFilter8021xWEP; - pEntry->WpaState = AS_INITPSK; - pEntry->PortSecured = WPA_802_1X_PORT_NOT_SECURED; - NdisZeroMemory(pEntry->R_Counter, - sizeof(pEntry->R_Counter)); - pEntry->ReTryCounter = PEER_MSG1_RETRY_TIMER_CTR; - - WPAStart4WayHS(pAd, pEntry, PEER_MSG1_RETRY_EXEC_INTV); - } - } -} - -/* - ========================================================================== - Description: - This is state machine function. - When receiving EAPOL packets which is for 802.1x key management. - Use both in WPA, and WPAPSK case. - In this function, further dispatch to different functions according to the received packet. 3 categories are : - 1. normal 4-way pairwisekey and 2-way groupkey handshake - 2. MIC error (Countermeasures attack) report packet from STA. - 3. Request for pairwise/group key update from STA - Return: - ========================================================================== -*/ -void WpaEAPOLKeyAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_mac_table_entry *pEntry; - struct rt_header_802_11 * pHeader; - struct rt_eapol_packet * pEapol_packet; - struct rt_key_info peerKeyInfo; - - DBGPRINT(RT_DEBUG_TRACE, ("WpaEAPOLKeyAction ===>\n")); - - pHeader = (struct rt_header_802_11 *) Elem->Msg; - pEapol_packet = - (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H]; - - NdisZeroMemory((u8 *)& peerKeyInfo, sizeof(peerKeyInfo)); - NdisMoveMemory((u8 *)& peerKeyInfo, - (u8 *)& pEapol_packet->KeyDesc.KeyInfo, - sizeof(struct rt_key_info)); - - hex_dump("Received Eapol frame", (unsigned char *)pEapol_packet, - (Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H)); - - *((u16 *) & peerKeyInfo) = cpu2le16(*((u16 *) & peerKeyInfo)); - - do { - pEntry = MacTableLookup(pAd, pHeader->Addr2); - - if (!pEntry - || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli))) - break; - - if (pEntry->AuthMode < Ndis802_11AuthModeWPA) - break; - - DBGPRINT(RT_DEBUG_TRACE, - ("Receive EAPoL-Key frame from STA %pMF\n", - pEntry->Addr)); - - if (((pEapol_packet->ProVer != EAPOL_VER) - && (pEapol_packet->ProVer != EAPOL_VER2)) - || ((pEapol_packet->KeyDesc.Type != WPA1_KEY_DESC) - && (pEapol_packet->KeyDesc.Type != WPA2_KEY_DESC))) { - DBGPRINT(RT_DEBUG_ERROR, - ("Key descripter does not match with WPA rule\n")); - break; - } - /* The value 1 shall be used for all EAPOL-Key frames to and from a STA when */ - /* neither the group nor pairwise ciphers are CCMP for Key Descriptor 1. */ - if ((pEntry->WepStatus == Ndis802_11Encryption2Enabled) - && (peerKeyInfo.KeyDescVer != DESC_TYPE_TKIP)) { - DBGPRINT(RT_DEBUG_ERROR, - ("Key descripter version not match(TKIP) \n")); - break; - } - /* The value 2 shall be used for all EAPOL-Key frames to and from a STA when */ - /* either the pairwise or the group cipher is AES-CCMP for Key Descriptor 2. */ - else if ((pEntry->WepStatus == Ndis802_11Encryption3Enabled) - && (peerKeyInfo.KeyDescVer != DESC_TYPE_AES)) { - DBGPRINT(RT_DEBUG_ERROR, - ("Key descripter version not match(AES) \n")); - break; - } - /* Check if this STA is in class 3 state and the WPA state is started */ - if ((pEntry->Sst == SST_ASSOC) - && (pEntry->WpaState >= AS_INITPSK)) { - /* Check the Key Ack (bit 7) of the Key Information to determine the Authenticator */ - /* or not. */ - /* An EAPOL-Key frame that is sent by the Supplicant in response to an EAPOL- */ - /* Key frame from the Authenticator must not have the Ack bit set. */ - if (peerKeyInfo.KeyAck == 1) { - /* The frame is snet by Authenticator. */ - /* So the Supplicant side shall handle this. */ - - if ((peerKeyInfo.Secure == 0) - && (peerKeyInfo.Request == 0) - && (peerKeyInfo.Error == 0) - && (peerKeyInfo.KeyType == PAIRWISEKEY)) { - /* Process 1. the message 1 of 4-way HS in WPA or WPA2 */ - /* EAPOL-Key(0,0,1,0,P,0,0,ANonce,0,DataKD_M1) */ - /* 2. the message 3 of 4-way HS in WPA */ - /* EAPOL-Key(0,1,1,1,P,0,KeyRSC,ANonce,MIC,DataKD_M3) */ - if (peerKeyInfo.KeyMic == 0) - PeerPairMsg1Action(pAd, pEntry, - Elem); - else - PeerPairMsg3Action(pAd, pEntry, - Elem); - } else if ((peerKeyInfo.Secure == 1) - && (peerKeyInfo.KeyMic == 1) - && (peerKeyInfo.Request == 0) - && (peerKeyInfo.Error == 0)) { - /* Process 1. the message 3 of 4-way HS in WPA2 */ - /* EAPOL-Key(1,1,1,1,P,0,KeyRSC,ANonce,MIC,DataKD_M3) */ - /* 2. the message 1 of group KS in WPA or WPA2 */ - /* EAPOL-Key(1,1,1,0,G,0,Key RSC,0, MIC,GTK[N]) */ - if (peerKeyInfo.KeyType == PAIRWISEKEY) - PeerPairMsg3Action(pAd, pEntry, - Elem); - else - PeerGroupMsg1Action(pAd, pEntry, - Elem); - } - } else { - /* The frame is snet by Supplicant. */ - /* So the Authenticator side shall handle this. */ - if ((peerKeyInfo.Request == 0) && - (peerKeyInfo.Error == 0) && - (peerKeyInfo.KeyMic == 1)) { - if (peerKeyInfo.Secure == 0 - && peerKeyInfo.KeyType == - PAIRWISEKEY) { - /* EAPOL-Key(0,1,0,0,P,0,0,SNonce,MIC,Data) */ - /* Process 1. message 2 of 4-way HS in WPA or WPA2 */ - /* 2. message 4 of 4-way HS in WPA */ - if (CONV_ARRARY_TO_u16 - (pEapol_packet->KeyDesc. - KeyDataLen) == 0) { - PeerPairMsg4Action(pAd, - pEntry, - Elem); - } else { - PeerPairMsg2Action(pAd, - pEntry, - Elem); - } - } else if (peerKeyInfo.Secure == 1 - && peerKeyInfo.KeyType == - PAIRWISEKEY) { - /* EAPOL-Key(1,1,0,0,P,0,0,0,MIC,0) */ - /* Process message 4 of 4-way HS in WPA2 */ - PeerPairMsg4Action(pAd, pEntry, - Elem); - } else if (peerKeyInfo.Secure == 1 - && peerKeyInfo.KeyType == - GROUPKEY) { - /* EAPOL-Key(1,1,0,0,G,0,0,0,MIC,0) */ - /* Process message 2 of Group key HS in WPA or WPA2 */ - PeerGroupMsg2Action(pAd, pEntry, - &Elem-> - Msg - [LENGTH_802_11], - (Elem-> - MsgLen - - LENGTH_802_11)); - } - } - } - } - } while (FALSE); -} - -/* - ======================================================================== - - Routine Description: - Copy frame from waiting queue into relative ring buffer and set - appropriate ASIC register to kick hardware encryption before really - sent out to air. - - Arguments: - pAd Pointer to our adapter - void * Pointer to outgoing Ndis frame - NumberOfFrag Number of fragment required - - Return Value: - None - - Note: - - ======================================================================== -*/ -void RTMPToWirelessSta(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 *pHeader802_3, - u32 HdrLen, - u8 *pData, u32 DataLen, IN BOOLEAN bClearFrame) -{ - void *pPacket; - int Status; - - if ((!pEntry) || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli))) - return; - - do { - /* build a NDIS packet */ - Status = - RTMPAllocateNdisPacket(pAd, &pPacket, pHeader802_3, HdrLen, - pData, DataLen); - if (Status != NDIS_STATUS_SUCCESS) - break; - - if (bClearFrame) - RTMP_SET_PACKET_CLEAR_EAP_FRAME(pPacket, 1); - else - RTMP_SET_PACKET_CLEAR_EAP_FRAME(pPacket, 0); - { - RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS); - - RTMP_SET_PACKET_NET_DEVICE_MBSSID(pPacket, MAIN_MBSSID); /* set a default value */ - if (pEntry->apidx != 0) - RTMP_SET_PACKET_NET_DEVICE_MBSSID(pPacket, - pEntry-> - apidx); - - RTMP_SET_PACKET_WCID(pPacket, (u8)pEntry->Aid); - RTMP_SET_PACKET_MOREDATA(pPacket, FALSE); - } - - { - /* send out the packet */ - Status = STASendPacket(pAd, pPacket); - if (Status == NDIS_STATUS_SUCCESS) { - u8 Index; - - /* Dequeue one frame from TxSwQueue0..3 queue and process it */ - /* There are three place calling dequeue for TX ring. */ - /* 1. Here, right after queueing the frame. */ - /* 2. At the end of TxRingTxDone service routine. */ - /* 3. Upon NDIS call RTMPSendPackets */ - if ((!RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) - && - (!RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS))) { - for (Index = 0; Index < 5; Index++) - if (pAd->TxSwQueue[Index]. - Number > 0) - RTMPDeQueuePacket(pAd, - FALSE, - Index, - MAX_TX_PROCESS); - } - } - } - - } while (FALSE); -} - -/* - ========================================================================== - Description: - This is a function to initialize 4-way handshake - - Return: - - ========================================================================== -*/ -void WPAStart4WayHS(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, unsigned long TimeInterval) -{ - u8 Header802_3[14]; - struct rt_eapol_packet EAPOLPKT; - u8 *pBssid = NULL; - u8 group_cipher = Ndis802_11WEPDisabled; - - DBGPRINT(RT_DEBUG_TRACE, ("===> WPAStart4WayHS\n")); - - if (RTMP_TEST_FLAG - (pAd, - fRTMP_ADAPTER_RESET_IN_PROGRESS | fRTMP_ADAPTER_HALT_IN_PROGRESS)) - { - DBGPRINT(RT_DEBUG_ERROR, - ("[ERROR]WPAStart4WayHS : The interface is closed...\n")); - return; - } - - if (pBssid == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("[ERROR]WPAStart4WayHS : No corresponding Authenticator.\n")); - return; - } - /* Check the status */ - if ((pEntry->WpaState > AS_PTKSTART) || (pEntry->WpaState < AS_INITPMK)) { - DBGPRINT(RT_DEBUG_ERROR, - ("[ERROR]WPAStart4WayHS : Not expect calling\n")); - return; - } - - /* Increment replay counter by 1 */ - ADD_ONE_To_64BIT_VAR(pEntry->R_Counter); - - /* Randomly generate ANonce */ - GenRandom(pAd, (u8 *) pBssid, pEntry->ANonce); - - /* Construct EAPoL message - Pairwise Msg 1 */ - /* EAPOL-Key(0,0,1,0,P,0,0,ANonce,0,DataKD_M1) */ - NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet)); - ConstructEapolMsg(pEntry, group_cipher, EAPOL_PAIR_MSG_1, 0, /* Default key index */ - pEntry->ANonce, NULL, /* TxRSC */ - NULL, /* GTK */ - NULL, /* RSNIE */ - 0, /* RSNIE length */ - &EAPOLPKT); - - /* Make outgoing frame */ - MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pBssid, EAPOL); - RTMPToWirelessSta(pAd, pEntry, Header802_3, - LENGTH_802_3, (u8 *)& EAPOLPKT, - CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4, - (pEntry->PortSecured == - WPA_802_1X_PORT_SECURED) ? FALSE : TRUE); - - /* Trigger Retry Timer */ - RTMPModTimer(&pEntry->RetryTimer, TimeInterval); - - /* Update State */ - pEntry->WpaState = AS_PTKSTART; - - DBGPRINT(RT_DEBUG_TRACE, - ("<=== WPAStart4WayHS: send Msg1 of 4-way \n")); - -} - -/* - ======================================================================== - - Routine Description: - Process Pairwise key Msg-1 of 4-way handshaking and send Msg-2 - - Arguments: - pAd Pointer to our adapter - Elem Message body - - Return Value: - None - - Note: - - ======================================================================== -*/ -void PeerPairMsg1Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem) -{ - u8 PTK[80]; - u8 Header802_3[14]; - struct rt_eapol_packet * pMsg1; - u32 MsgLen; - struct rt_eapol_packet EAPOLPKT; - u8 *pCurrentAddr = NULL; - u8 *pmk_ptr = NULL; - u8 group_cipher = Ndis802_11WEPDisabled; - u8 *rsnie_ptr = NULL; - u8 rsnie_len = 0; - - DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg1Action \n")); - - if ((!pEntry) || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli))) - return; - - if (Elem->MsgLen < - (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H + - sizeof(struct rt_key_descripter) - MAX_LEN_OF_RSNIE - 2)) - return; - - { - pCurrentAddr = pAd->CurrentAddress; - pmk_ptr = pAd->StaCfg.PMK; - group_cipher = pAd->StaCfg.GroupCipher; - rsnie_ptr = pAd->StaCfg.RSN_IE; - rsnie_len = pAd->StaCfg.RSNIE_Len; - } - - /* Store the received frame */ - pMsg1 = (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H]; - MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H; - - /* Sanity Check peer Pairwise message 1 - Replay Counter */ - if (PeerWpaMessageSanity(pAd, pMsg1, MsgLen, EAPOL_PAIR_MSG_1, pEntry) - == FALSE) - return; - - /* Store Replay counter, it will use to verify message 3 and construct message 2 */ - NdisMoveMemory(pEntry->R_Counter, pMsg1->KeyDesc.ReplayCounter, - LEN_KEY_DESC_REPLAY); - - /* Store ANonce */ - NdisMoveMemory(pEntry->ANonce, pMsg1->KeyDesc.KeyNonce, - LEN_KEY_DESC_NONCE); - - /* Generate random SNonce */ - GenRandom(pAd, (u8 *) pCurrentAddr, pEntry->SNonce); - - { - /* Calculate PTK(ANonce, SNonce) */ - WpaDerivePTK(pAd, - pmk_ptr, - pEntry->ANonce, - pEntry->Addr, - pEntry->SNonce, pCurrentAddr, PTK, LEN_PTK); - - /* Save key to PTK entry */ - NdisMoveMemory(pEntry->PTK, PTK, LEN_PTK); - } - - /* Update WpaState */ - pEntry->WpaState = AS_PTKINIT_NEGOTIATING; - - /* Construct EAPoL message - Pairwise Msg 2 */ - /* EAPOL-Key(0,1,0,0,P,0,0,SNonce,MIC,DataKD_M2) */ - NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet)); - ConstructEapolMsg(pEntry, group_cipher, EAPOL_PAIR_MSG_2, 0, /* DefaultKeyIdx */ - pEntry->SNonce, NULL, /* TxRsc */ - NULL, /* GTK */ - (u8 *) rsnie_ptr, rsnie_len, &EAPOLPKT); - - /* Make outgoing frame */ - MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pCurrentAddr, EAPOL); - - RTMPToWirelessSta(pAd, pEntry, - Header802_3, sizeof(Header802_3), (u8 *)& EAPOLPKT, - CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4, TRUE); - - DBGPRINT(RT_DEBUG_TRACE, - ("<=== PeerPairMsg1Action: send Msg2 of 4-way \n")); -} - -/* - ========================================================================== - Description: - When receiving the second packet of 4-way pairwisekey handshake. - Return: - ========================================================================== -*/ -void PeerPairMsg2Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem) -{ - u8 PTK[80]; - BOOLEAN Cancelled; - struct rt_header_802_11 * pHeader; - struct rt_eapol_packet EAPOLPKT; - struct rt_eapol_packet * pMsg2; - u32 MsgLen; - u8 Header802_3[LENGTH_802_3]; - u8 TxTsc[6]; - u8 *pBssid = NULL; - u8 *pmk_ptr = NULL; - u8 *gtk_ptr = NULL; - u8 default_key = 0; - u8 group_cipher = Ndis802_11WEPDisabled; - u8 *rsnie_ptr = NULL; - u8 rsnie_len = 0; - - DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg2Action \n")); - - if ((!pEntry) || (!pEntry->ValidAsCLI)) - return; - - if (Elem->MsgLen < - (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H + - sizeof(struct rt_key_descripter) - MAX_LEN_OF_RSNIE - 2)) - return; - - /* check Entry in valid State */ - if (pEntry->WpaState < AS_PTKSTART) - return; - - /* pointer to 802.11 header */ - pHeader = (struct rt_header_802_11 *) Elem->Msg; - - /* skip 802.11_header(24-byte) and LLC_header(8) */ - pMsg2 = (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H]; - MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H; - - /* Store SNonce */ - NdisMoveMemory(pEntry->SNonce, pMsg2->KeyDesc.KeyNonce, - LEN_KEY_DESC_NONCE); - - { - /* Derive PTK */ - WpaDerivePTK(pAd, (u8 *) pmk_ptr, pEntry->ANonce, /* ANONCE */ - (u8 *) pBssid, pEntry->SNonce, /* SNONCE */ - pEntry->Addr, PTK, LEN_PTK); - - NdisMoveMemory(pEntry->PTK, PTK, LEN_PTK); - } - - /* Sanity Check peer Pairwise message 2 - Replay Counter, MIC, RSNIE */ - if (PeerWpaMessageSanity(pAd, pMsg2, MsgLen, EAPOL_PAIR_MSG_2, pEntry) - == FALSE) - return; - - do { - /* delete retry timer */ - RTMPCancelTimer(&pEntry->RetryTimer, &Cancelled); - - /* Change state */ - pEntry->WpaState = AS_PTKINIT_NEGOTIATING; - - /* Increment replay counter by 1 */ - ADD_ONE_To_64BIT_VAR(pEntry->R_Counter); - - /* Construct EAPoL message - Pairwise Msg 3 */ - NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet)); - ConstructEapolMsg(pEntry, - group_cipher, - EAPOL_PAIR_MSG_3, - default_key, - pEntry->ANonce, - TxTsc, - (u8 *) gtk_ptr, - (u8 *) rsnie_ptr, rsnie_len, &EAPOLPKT); - - /* Make outgoing frame */ - MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pBssid, EAPOL); - RTMPToWirelessSta(pAd, pEntry, Header802_3, LENGTH_802_3, - (u8 *)& EAPOLPKT, - CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4, - (pEntry->PortSecured == - WPA_802_1X_PORT_SECURED) ? FALSE : TRUE); - - pEntry->ReTryCounter = PEER_MSG3_RETRY_TIMER_CTR; - RTMPSetTimer(&pEntry->RetryTimer, PEER_MSG3_RETRY_EXEC_INTV); - - /* Update State */ - pEntry->WpaState = AS_PTKINIT_NEGOTIATING; - } while (FALSE); - - DBGPRINT(RT_DEBUG_TRACE, - ("<=== PeerPairMsg2Action: send Msg3 of 4-way \n")); -} - -/* - ======================================================================== - - Routine Description: - Process Pairwise key Msg 3 of 4-way handshaking and send Msg 4 - - Arguments: - pAd Pointer to our adapter - Elem Message body - - Return Value: - None - - Note: - - ======================================================================== -*/ -void PeerPairMsg3Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem) -{ - struct rt_header_802_11 * pHeader; - u8 Header802_3[14]; - struct rt_eapol_packet EAPOLPKT; - struct rt_eapol_packet * pMsg3; - u32 MsgLen; - u8 *pCurrentAddr = NULL; - u8 group_cipher = Ndis802_11WEPDisabled; - - DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg3Action \n")); - - if ((!pEntry) || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli))) - return; - - if (Elem->MsgLen < - (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H + - sizeof(struct rt_key_descripter) - MAX_LEN_OF_RSNIE - 2)) - return; - - { - pCurrentAddr = pAd->CurrentAddress; - group_cipher = pAd->StaCfg.GroupCipher; - - } - - /* Record 802.11 header & the received EAPOL packet Msg3 */ - pHeader = (struct rt_header_802_11 *) Elem->Msg; - pMsg3 = (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H]; - MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H; - - /* Sanity Check peer Pairwise message 3 - Replay Counter, MIC, RSNIE */ - if (PeerWpaMessageSanity(pAd, pMsg3, MsgLen, EAPOL_PAIR_MSG_3, pEntry) - == FALSE) - return; - - /* Save Replay counter, it will use construct message 4 */ - NdisMoveMemory(pEntry->R_Counter, pMsg3->KeyDesc.ReplayCounter, - LEN_KEY_DESC_REPLAY); - - /* Double check ANonce */ - if (!NdisEqualMemory - (pEntry->ANonce, pMsg3->KeyDesc.KeyNonce, LEN_KEY_DESC_NONCE)) { - return; - } - /* Construct EAPoL message - Pairwise Msg 4 */ - NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet)); - ConstructEapolMsg(pEntry, group_cipher, EAPOL_PAIR_MSG_4, 0, /* group key index not used in message 4 */ - NULL, /* Nonce not used in message 4 */ - NULL, /* TxRSC not used in message 4 */ - NULL, /* GTK not used in message 4 */ - NULL, /* RSN IE not used in message 4 */ - 0, &EAPOLPKT); - - /* Update WpaState */ - pEntry->WpaState = AS_PTKINITDONE; - - /* Update pairwise key */ - { - struct rt_cipher_key *pSharedKey; - - pSharedKey = &pAd->SharedKey[BSS0][0]; - - NdisMoveMemory(pAd->StaCfg.PTK, pEntry->PTK, LEN_PTK); - - /* Prepare pair-wise key information into shared key table */ - NdisZeroMemory(pSharedKey, sizeof(struct rt_cipher_key)); - pSharedKey->KeyLen = LEN_TKIP_EK; - NdisMoveMemory(pSharedKey->Key, &pAd->StaCfg.PTK[32], - LEN_TKIP_EK); - NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.PTK[48], - LEN_TKIP_RXMICK); - NdisMoveMemory(pSharedKey->TxMic, - &pAd->StaCfg.PTK[48 + LEN_TKIP_RXMICK], - LEN_TKIP_TXMICK); - - /* Decide its ChiperAlg */ - if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled) - pSharedKey->CipherAlg = CIPHER_TKIP; - else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled) - pSharedKey->CipherAlg = CIPHER_AES; - else - pSharedKey->CipherAlg = CIPHER_NONE; - - /* Update these related information to struct rt_mac_table_entry */ - pEntry = &pAd->MacTab.Content[BSSID_WCID]; - NdisMoveMemory(pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], - LEN_TKIP_EK); - NdisMoveMemory(pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], - LEN_TKIP_RXMICK); - NdisMoveMemory(pEntry->PairwiseKey.TxMic, - &pAd->StaCfg.PTK[48 + LEN_TKIP_RXMICK], - LEN_TKIP_TXMICK); - pEntry->PairwiseKey.CipherAlg = pSharedKey->CipherAlg; - - /* Update pairwise key information to ASIC Shared Key Table */ - AsicAddSharedKeyEntry(pAd, - BSS0, - 0, - pSharedKey->CipherAlg, - pSharedKey->Key, - pSharedKey->TxMic, pSharedKey->RxMic); - - /* Update ASIC WCID attribute table and IVEIV table */ - RTMPAddWcidAttributeEntry(pAd, - BSS0, - 0, pSharedKey->CipherAlg, pEntry); - - } - - /* open 802.1x port control and privacy filter */ - if (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK || - pEntry->AuthMode == Ndis802_11AuthModeWPA2) { - pEntry->PortSecured = WPA_802_1X_PORT_SECURED; - pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll; - - STA_PORT_SECURED(pAd); - /* Indicate Connected for GUI */ - pAd->IndicateMediaState = NdisMediaStateConnected; - DBGPRINT(RT_DEBUG_TRACE, - ("PeerPairMsg3Action: AuthMode(%s) PairwiseCipher(%s) GroupCipher(%s) \n", - GetAuthMode(pEntry->AuthMode), - GetEncryptType(pEntry->WepStatus), - GetEncryptType(group_cipher))); - } else { - } - - /* Init 802.3 header and send out */ - MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pCurrentAddr, EAPOL); - RTMPToWirelessSta(pAd, pEntry, - Header802_3, sizeof(Header802_3), - (u8 *)& EAPOLPKT, - CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4, TRUE); - - DBGPRINT(RT_DEBUG_TRACE, - ("<=== PeerPairMsg3Action: send Msg4 of 4-way \n")); -} - -/* - ========================================================================== - Description: - When receiving the last packet of 4-way pairwisekey handshake. - Initialize 2-way groupkey handshake following. - Return: - ========================================================================== -*/ -void PeerPairMsg4Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem) -{ - struct rt_eapol_packet * pMsg4; - struct rt_header_802_11 * pHeader; - u32 MsgLen; - BOOLEAN Cancelled; - u8 group_cipher = Ndis802_11WEPDisabled; - - DBGPRINT(RT_DEBUG_TRACE, ("===> PeerPairMsg4Action\n")); - - do { - if ((!pEntry) || (!pEntry->ValidAsCLI)) - break; - - if (Elem->MsgLen < - (LENGTH_802_11 + LENGTH_802_1_H + LENGTH_EAPOL_H + - sizeof(struct rt_key_descripter) - MAX_LEN_OF_RSNIE - 2)) - break; - - if (pEntry->WpaState < AS_PTKINIT_NEGOTIATING) - break; - - /* pointer to 802.11 header */ - pHeader = (struct rt_header_802_11 *) Elem->Msg; - - /* skip 802.11_header(24-byte) and LLC_header(8) */ - pMsg4 = - (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H]; - MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H; - - /* Sanity Check peer Pairwise message 4 - Replay Counter, MIC */ - if (PeerWpaMessageSanity - (pAd, pMsg4, MsgLen, EAPOL_PAIR_MSG_4, pEntry) == FALSE) - break; - - /* 3. uses the MLME.SETKEYS.request to configure PTK into MAC */ - NdisZeroMemory(&pEntry->PairwiseKey, sizeof(struct rt_cipher_key)); - - /* reset IVEIV in Asic */ - AsicUpdateWCIDIVEIV(pAd, pEntry->Aid, 1, 0); - - pEntry->PairwiseKey.KeyLen = LEN_TKIP_EK; - NdisMoveMemory(pEntry->PairwiseKey.Key, &pEntry->PTK[32], - LEN_TKIP_EK); - NdisMoveMemory(pEntry->PairwiseKey.RxMic, - &pEntry->PTK[TKIP_AP_RXMICK_OFFSET], - LEN_TKIP_RXMICK); - NdisMoveMemory(pEntry->PairwiseKey.TxMic, - &pEntry->PTK[TKIP_AP_TXMICK_OFFSET], - LEN_TKIP_TXMICK); - - /* Set pairwise key to Asic */ - { - pEntry->PairwiseKey.CipherAlg = CIPHER_NONE; - if (pEntry->WepStatus == Ndis802_11Encryption2Enabled) - pEntry->PairwiseKey.CipherAlg = CIPHER_TKIP; - else if (pEntry->WepStatus == - Ndis802_11Encryption3Enabled) - pEntry->PairwiseKey.CipherAlg = CIPHER_AES; - - /* Add Pair-wise key to Asic */ - AsicAddPairwiseKeyEntry(pAd, - pEntry->Addr, - (u8)pEntry->Aid, - &pEntry->PairwiseKey); - - /* update WCID attribute table and IVEIV table for this entry */ - RTMPAddWcidAttributeEntry(pAd, - pEntry->apidx, - 0, - pEntry->PairwiseKey.CipherAlg, - pEntry); - } - - /* 4. upgrade state */ - pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll; - pEntry->WpaState = AS_PTKINITDONE; - pEntry->PortSecured = WPA_802_1X_PORT_SECURED; - - if (pEntry->AuthMode == Ndis802_11AuthModeWPA2 || - pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK) { - pEntry->GTKState = REKEY_ESTABLISHED; - RTMPCancelTimer(&pEntry->RetryTimer, &Cancelled); - - /* send wireless event - for set key done WPA2 */ - if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, - IW_SET_KEY_DONE_WPA2_EVENT_FLAG, - pEntry->Addr, - pEntry->apidx, 0); - - DBGPRINT(RT_DEBUG_OFF, - ("AP SETKEYS DONE - WPA2, AuthMode(%d)=%s, WepStatus(%d)=%s, GroupWepStatus(%d)=%s\n\n", - pEntry->AuthMode, - GetAuthMode(pEntry->AuthMode), - pEntry->WepStatus, - GetEncryptType(pEntry->WepStatus), - group_cipher, GetEncryptType(group_cipher))); - } else { - /* 5. init Group 2-way handshake if necessary. */ - WPAStart2WayGroupHS(pAd, pEntry); - - pEntry->ReTryCounter = GROUP_MSG1_RETRY_TIMER_CTR; - RTMPModTimer(&pEntry->RetryTimer, - PEER_MSG3_RETRY_EXEC_INTV); - } - } while (FALSE); - -} - -/* - ========================================================================== - Description: - This is a function to send the first packet of 2-way groupkey handshake - Return: - - ========================================================================== -*/ -void WPAStart2WayGroupHS(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry) -{ - u8 Header802_3[14]; - u8 TxTsc[6]; - struct rt_eapol_packet EAPOLPKT; - u8 group_cipher = Ndis802_11WEPDisabled; - u8 default_key = 0; - u8 *gnonce_ptr = NULL; - u8 *gtk_ptr = NULL; - u8 *pBssid = NULL; - - DBGPRINT(RT_DEBUG_TRACE, ("===> WPAStart2WayGroupHS\n")); - - if ((!pEntry) || (!pEntry->ValidAsCLI)) - return; - - do { - /* Increment replay counter by 1 */ - ADD_ONE_To_64BIT_VAR(pEntry->R_Counter); - - /* Construct EAPoL message - Group Msg 1 */ - NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet)); - ConstructEapolMsg(pEntry, - group_cipher, - EAPOL_GROUP_MSG_1, - default_key, - (u8 *) gnonce_ptr, - TxTsc, (u8 *) gtk_ptr, NULL, 0, &EAPOLPKT); - - /* Make outgoing frame */ - MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pBssid, EAPOL); - RTMPToWirelessSta(pAd, pEntry, - Header802_3, LENGTH_802_3, - (u8 *)& EAPOLPKT, - CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4, - FALSE); - - } while (FALSE); - - DBGPRINT(RT_DEBUG_TRACE, - ("<=== WPAStart2WayGroupHS : send out Group Message 1 \n")); - - return; -} - -/* - ======================================================================== - - Routine Description: - Process Group key 2-way handshaking - - Arguments: - pAd Pointer to our adapter - Elem Message body - - Return Value: - None - - Note: - - ======================================================================== -*/ -void PeerGroupMsg1Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem) -{ - u8 Header802_3[14]; - struct rt_eapol_packet EAPOLPKT; - struct rt_eapol_packet * pGroup; - u32 MsgLen; - BOOLEAN Cancelled; - u8 default_key = 0; - u8 group_cipher = Ndis802_11WEPDisabled; - u8 *pCurrentAddr = NULL; - - DBGPRINT(RT_DEBUG_TRACE, ("===> PeerGroupMsg1Action \n")); - - if ((!pEntry) || ((!pEntry->ValidAsCLI) && (!pEntry->ValidAsApCli))) - return; - - { - pCurrentAddr = pAd->CurrentAddress; - group_cipher = pAd->StaCfg.GroupCipher; - default_key = pAd->StaCfg.DefaultKeyId; - } - - /* Process Group Message 1 frame. skip 802.11 header(24) & LLC_SNAP header(8) */ - pGroup = (struct rt_eapol_packet *) & Elem->Msg[LENGTH_802_11 + LENGTH_802_1_H]; - MsgLen = Elem->MsgLen - LENGTH_802_11 - LENGTH_802_1_H; - - /* Sanity Check peer group message 1 - Replay Counter, MIC, RSNIE */ - if (PeerWpaMessageSanity(pAd, pGroup, MsgLen, EAPOL_GROUP_MSG_1, pEntry) - == FALSE) - return; - - /* delete retry timer */ - RTMPCancelTimer(&pEntry->RetryTimer, &Cancelled); - - /* Save Replay counter, it will use to construct message 2 */ - NdisMoveMemory(pEntry->R_Counter, pGroup->KeyDesc.ReplayCounter, - LEN_KEY_DESC_REPLAY); - - /* Construct EAPoL message - Group Msg 2 */ - NdisZeroMemory(&EAPOLPKT, sizeof(struct rt_eapol_packet)); - ConstructEapolMsg(pEntry, group_cipher, EAPOL_GROUP_MSG_2, default_key, NULL, /* Nonce not used */ - NULL, /* TxRSC not used */ - NULL, /* GTK not used */ - NULL, /* RSN IE not used */ - 0, &EAPOLPKT); - - /* open 802.1x port control and privacy filter */ - pEntry->PortSecured = WPA_802_1X_PORT_SECURED; - pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll; - - STA_PORT_SECURED(pAd); - /* Indicate Connected for GUI */ - pAd->IndicateMediaState = NdisMediaStateConnected; - - DBGPRINT(RT_DEBUG_TRACE, - ("PeerGroupMsg1Action: AuthMode(%s) PairwiseCipher(%s) GroupCipher(%s) \n", - GetAuthMode(pEntry->AuthMode), - GetEncryptType(pEntry->WepStatus), - GetEncryptType(group_cipher))); - - /* init header and Fill Packet and send Msg 2 to authenticator */ - MAKE_802_3_HEADER(Header802_3, pEntry->Addr, pCurrentAddr, EAPOL); - RTMPToWirelessSta(pAd, pEntry, - Header802_3, sizeof(Header802_3), - (u8 *)& EAPOLPKT, - CONV_ARRARY_TO_u16(EAPOLPKT.Body_Len) + 4, FALSE); - - DBGPRINT(RT_DEBUG_TRACE, - ("<=== PeerGroupMsg1Action: sned group message 2\n")); -} - -/* - ========================================================================== - Description: - When receiving the last packet of 2-way groupkey handshake. - Return: - ========================================================================== -*/ -void PeerGroupMsg2Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - void * Msg, u32 MsgLen) -{ - u32 Len; - u8 *pData; - BOOLEAN Cancelled; - struct rt_eapol_packet * pMsg2; - u8 group_cipher = Ndis802_11WEPDisabled; - - DBGPRINT(RT_DEBUG_TRACE, ("===> PeerGroupMsg2Action \n")); - - do { - if ((!pEntry) || (!pEntry->ValidAsCLI)) - break; - - if (MsgLen < - (LENGTH_802_1_H + LENGTH_EAPOL_H + sizeof(struct rt_key_descripter) - - MAX_LEN_OF_RSNIE - 2)) - break; - - if (pEntry->WpaState != AS_PTKINITDONE) - break; - - pData = (u8 *)Msg; - pMsg2 = (struct rt_eapol_packet *) (pData + LENGTH_802_1_H); - Len = MsgLen - LENGTH_802_1_H; - - /* Sanity Check peer group message 2 - Replay Counter, MIC */ - if (PeerWpaMessageSanity - (pAd, pMsg2, Len, EAPOL_GROUP_MSG_2, pEntry) == FALSE) - break; - - /* 3. upgrade state */ - - RTMPCancelTimer(&pEntry->RetryTimer, &Cancelled); - pEntry->GTKState = REKEY_ESTABLISHED; - - if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) - || (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK)) { - /* send wireless event - for set key done WPA2 */ - if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, - IW_SET_KEY_DONE_WPA2_EVENT_FLAG, - pEntry->Addr, - pEntry->apidx, 0); - - DBGPRINT(RT_DEBUG_OFF, - ("AP SETKEYS DONE - WPA2, AuthMode(%d)=%s, WepStatus(%d)=%s, GroupWepStatus(%d)=%s\n\n", - pEntry->AuthMode, - GetAuthMode(pEntry->AuthMode), - pEntry->WepStatus, - GetEncryptType(pEntry->WepStatus), - group_cipher, GetEncryptType(group_cipher))); - } else { - /* send wireless event - for set key done WPA */ - if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, - IW_SET_KEY_DONE_WPA1_EVENT_FLAG, - pEntry->Addr, - pEntry->apidx, 0); - - DBGPRINT(RT_DEBUG_OFF, - ("AP SETKEYS DONE - WPA1, AuthMode(%d)=%s, WepStatus(%d)=%s, GroupWepStatus(%d)=%s\n\n", - pEntry->AuthMode, - GetAuthMode(pEntry->AuthMode), - pEntry->WepStatus, - GetEncryptType(pEntry->WepStatus), - group_cipher, GetEncryptType(group_cipher))); - } - } while (FALSE); -} - -/* - ======================================================================== - - Routine Description: - Classify WPA EAP message type - - Arguments: - EAPType Value of EAP message type - MsgType Internal Message definition for MLME state machine - - Return Value: - TRUE Found appropriate message type - FALSE No appropriate message type - - IRQL = DISPATCH_LEVEL - - Note: - All these constants are defined in wpa.h - For supplicant, there is only EAPOL Key message available - - ======================================================================== -*/ -BOOLEAN WpaMsgTypeSubst(u8 EAPType, int * MsgType) -{ - switch (EAPType) { - case EAPPacket: - *MsgType = MT2_EAPPacket; - break; - case EAPOLStart: - *MsgType = MT2_EAPOLStart; - break; - case EAPOLLogoff: - *MsgType = MT2_EAPOLLogoff; - break; - case EAPOLKey: - *MsgType = MT2_EAPOLKey; - break; - case EAPOLASFAlert: - *MsgType = MT2_EAPOLASFAlert; - break; - default: - return FALSE; - } - return TRUE; -} - -/* - ======================================================================== - - Routine Description: - The pseudo-random function(PRF) that hashes various inputs to - derive a pseudo-random value. To add liveness to the pseudo-random - value, a nonce should be one of the inputs. - - It is used to generate PTK, GTK or some specific random value. - - Arguments: - u8 *key, - the key material for HMAC_SHA1 use - int key_len - the length of key - u8 *prefix - a prefix label - int prefix_len - the length of the label - u8 *data - a specific data with variable length - int data_len - the length of a specific data - int len - the output length - - Return Value: - u8 *output - the calculated result - - Note: - 802.11i-2004 Annex H.3 - - ======================================================================== -*/ -void PRF(u8 * key, - int key_len, - u8 * prefix, - int prefix_len, - u8 * data, int data_len, u8 * output, int len) -{ - int i; - u8 *input; - int currentindex = 0; - int total_len; - - /* Allocate memory for input */ - os_alloc_mem(NULL, (u8 **) & input, 1024); - - if (input == NULL) { - DBGPRINT(RT_DEBUG_ERROR, ("PRF: no memory!\n")); - return; - } - /* Generate concatenation input */ - NdisMoveMemory(input, prefix, prefix_len); - - /* Concatenate a single octet containing 0 */ - input[prefix_len] = 0; - - /* Concatenate specific data */ - NdisMoveMemory(&input[prefix_len + 1], data, data_len); - total_len = prefix_len + 1 + data_len; - - /* Concatenate a single octet containing 0 */ - /* This octet shall be update later */ - input[total_len] = 0; - total_len++; - - /* Iterate to calculate the result by hmac-sha-1 */ - /* Then concatenate to last result */ - for (i = 0; i < (len + 19) / 20; i++) { - HMAC_SHA1(key, key_len, input, total_len, &output[currentindex], - SHA1_DIGEST_SIZE); - currentindex += 20; - - /* update the last octet */ - input[total_len - 1]++; - } - os_free_mem(NULL, input); -} - -/* -* F(P, S, c, i) = U1 xor U2 xor ... Uc -* U1 = PRF(P, S || Int(i)) -* U2 = PRF(P, U1) -* Uc = PRF(P, Uc-1) -*/ - -static void F(char *password, unsigned char *ssid, int ssidlength, - int iterations, int count, unsigned char *output) -{ - unsigned char digest[36], digest1[SHA1_DIGEST_SIZE]; - int i, j; - - /* U1 = PRF(P, S || int(i)) */ - memcpy(digest, ssid, ssidlength); - digest[ssidlength] = (unsigned char)((count >> 24) & 0xff); - digest[ssidlength + 1] = (unsigned char)((count >> 16) & 0xff); - digest[ssidlength + 2] = (unsigned char)((count >> 8) & 0xff); - digest[ssidlength + 3] = (unsigned char)(count & 0xff); - HMAC_SHA1((unsigned char *)password, (int)strlen(password), digest, ssidlength + 4, digest1, SHA1_DIGEST_SIZE); /* for WPA update */ - - /* output = U1 */ - memcpy(output, digest1, SHA1_DIGEST_SIZE); - - for (i = 1; i < iterations; i++) { - /* Un = PRF(P, Un-1) */ - HMAC_SHA1((unsigned char *)password, (int)strlen(password), digest1, SHA1_DIGEST_SIZE, digest, SHA1_DIGEST_SIZE); /* for WPA update */ - memcpy(digest1, digest, SHA1_DIGEST_SIZE); - - /* output = output xor Un */ - for (j = 0; j < SHA1_DIGEST_SIZE; j++) { - output[j] ^= digest[j]; - } - } -} - -/* -* password - ascii string up to 63 characters in length -* ssid - octet string up to 32 octets -* ssidlength - length of ssid in octets -* output must be 40 octets in length and outputs 256 bits of key -*/ -int PasswordHash(char *password, u8 *ssid, int ssidlength, u8 *output) -{ - if ((strlen(password) > 63) || (ssidlength > 32)) - return 0; - - F(password, ssid, ssidlength, 4096, 1, output); - F(password, ssid, ssidlength, 4096, 2, &output[SHA1_DIGEST_SIZE]); - return 1; -} - -/* - ======================================================================== - - Routine Description: - It utilizes PRF-384 or PRF-512 to derive session-specific keys from a PMK. - It shall be called by 4-way handshake processing. - - Arguments: - pAd - pointer to our pAdapter context - PMK - pointer to PMK - ANonce - pointer to ANonce - AA - pointer to Authenticator Address - SNonce - pointer to SNonce - SA - pointer to Supplicant Address - len - indicate the length of PTK (octet) - - Return Value: - Output pointer to the PTK - - Note: - Refer to IEEE 802.11i-2004 8.5.1.2 - - ======================================================================== -*/ -void WpaDerivePTK(struct rt_rtmp_adapter *pAd, - u8 * PMK, - u8 * ANonce, - u8 * AA, - u8 * SNonce, - u8 * SA, u8 * output, u32 len) -{ - u8 concatenation[76]; - u32 CurrPos = 0; - u8 temp[32]; - u8 Prefix[] = - { 'P', 'a', 'i', 'r', 'w', 'i', 's', 'e', ' ', 'k', 'e', 'y', ' ', - 'e', 'x', 'p', 'a', 'n', 's', 'i', 'o', 'n' - }; - - /* initiate the concatenation input */ - NdisZeroMemory(temp, sizeof(temp)); - NdisZeroMemory(concatenation, 76); - - /* Get smaller address */ - if (RTMPCompareMemory(SA, AA, 6) == 1) - NdisMoveMemory(concatenation, AA, 6); - else - NdisMoveMemory(concatenation, SA, 6); - CurrPos += 6; - - /* Get larger address */ - if (RTMPCompareMemory(SA, AA, 6) == 1) - NdisMoveMemory(&concatenation[CurrPos], SA, 6); - else - NdisMoveMemory(&concatenation[CurrPos], AA, 6); - - /* store the larger mac address for backward compatible of */ - /* ralink proprietary STA-key issue */ - NdisMoveMemory(temp, &concatenation[CurrPos], MAC_ADDR_LEN); - CurrPos += 6; - - /* Get smaller Nonce */ - if (RTMPCompareMemory(ANonce, SNonce, 32) == 0) - NdisMoveMemory(&concatenation[CurrPos], temp, 32); /* patch for ralink proprietary STA-key issue */ - else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1) - NdisMoveMemory(&concatenation[CurrPos], SNonce, 32); - else - NdisMoveMemory(&concatenation[CurrPos], ANonce, 32); - CurrPos += 32; - - /* Get larger Nonce */ - if (RTMPCompareMemory(ANonce, SNonce, 32) == 0) - NdisMoveMemory(&concatenation[CurrPos], temp, 32); /* patch for ralink proprietary STA-key issue */ - else if (RTMPCompareMemory(ANonce, SNonce, 32) == 1) - NdisMoveMemory(&concatenation[CurrPos], ANonce, 32); - else - NdisMoveMemory(&concatenation[CurrPos], SNonce, 32); - CurrPos += 32; - - hex_dump("concatenation=", concatenation, 76); - - /* Use PRF to generate PTK */ - PRF(PMK, LEN_MASTER_KEY, Prefix, 22, concatenation, 76, output, len); - -} - -/* - ======================================================================== - - Routine Description: - Generate random number by software. - - Arguments: - pAd - pointer to our pAdapter context - macAddr - pointer to local MAC address - - Return Value: - - Note: - 802.1ii-2004 Annex H.5 - - ======================================================================== -*/ -void GenRandom(struct rt_rtmp_adapter *pAd, u8 * macAddr, u8 * random) -{ - int i, curr; - u8 local[80], KeyCounter[32]; - u8 result[80]; - unsigned long CurrentTime; - u8 prefix[] = - { 'I', 'n', 'i', 't', ' ', 'C', 'o', 'u', 'n', 't', 'e', 'r' }; - - /* Zero the related information */ - NdisZeroMemory(result, 80); - NdisZeroMemory(local, 80); - NdisZeroMemory(KeyCounter, 32); - - for (i = 0; i < 32; i++) { - /* copy the local MAC address */ - COPY_MAC_ADDR(local, macAddr); - curr = MAC_ADDR_LEN; - - /* concatenate the current time */ - NdisGetSystemUpTime(&CurrentTime); - NdisMoveMemory(&local[curr], &CurrentTime, sizeof(CurrentTime)); - curr += sizeof(CurrentTime); - - /* concatenate the last result */ - NdisMoveMemory(&local[curr], result, 32); - curr += 32; - - /* concatenate a variable */ - NdisMoveMemory(&local[curr], &i, 2); - curr += 2; - - /* calculate the result */ - PRF(KeyCounter, 32, prefix, 12, local, curr, result, 32); - } - - NdisMoveMemory(random, result, 32); -} - -/* - ======================================================================== - - Routine Description: - Build cipher suite in RSN-IE. - It only shall be called by RTMPMakeRSNIE. - - Arguments: - pAd - pointer to our pAdapter context - ElementID - indicate the WPA1 or WPA2 - WepStatus - indicate the encryption type - bMixCipher - a boolean to indicate the pairwise cipher and group - cipher are the same or not - - Return Value: - - Note: - - ======================================================================== -*/ -static void RTMPMakeRsnIeCipher(struct rt_rtmp_adapter *pAd, - u8 ElementID, - u32 WepStatus, - IN BOOLEAN bMixCipher, - u8 FlexibleCipher, - u8 *pRsnIe, u8 * rsn_len) -{ - u8 PairwiseCnt; - - *rsn_len = 0; - - /* decide WPA2 or WPA1 */ - if (ElementID == Wpa2Ie) { - struct rt_rsnie2 *pRsnie_cipher = (struct rt_rsnie2 *)pRsnIe; - - /* Assign the verson as 1 */ - pRsnie_cipher->version = 1; - - switch (WepStatus) { - /* TKIP mode */ - case Ndis802_11Encryption2Enabled: - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4); - pRsnie_cipher->ucount = 1; - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, - OUI_WPA2_TKIP, 4); - *rsn_len = sizeof(struct rt_rsnie2); - break; - - /* AES mode */ - case Ndis802_11Encryption3Enabled: - if (bMixCipher) - NdisMoveMemory(pRsnie_cipher->mcast, - OUI_WPA2_TKIP, 4); - else - NdisMoveMemory(pRsnie_cipher->mcast, - OUI_WPA2_CCMP, 4); - pRsnie_cipher->ucount = 1; - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, - OUI_WPA2_CCMP, 4); - *rsn_len = sizeof(struct rt_rsnie2); - break; - - /* TKIP-AES mix mode */ - case Ndis802_11Encryption4Enabled: - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA2_TKIP, 4); - - PairwiseCnt = 1; - /* Insert WPA2 TKIP as the first pairwise cipher */ - if (MIX_CIPHER_WPA2_TKIP_ON(FlexibleCipher)) { - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, - OUI_WPA2_TKIP, 4); - /* Insert WPA2 AES as the secondary pairwise cipher */ - if (MIX_CIPHER_WPA2_AES_ON(FlexibleCipher)) { - NdisMoveMemory(pRsnie_cipher->ucast[0]. - oui + 4, OUI_WPA2_CCMP, - 4); - PairwiseCnt = 2; - } - } else { - /* Insert WPA2 AES as the first pairwise cipher */ - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, - OUI_WPA2_CCMP, 4); - } - - pRsnie_cipher->ucount = PairwiseCnt; - *rsn_len = sizeof(struct rt_rsnie2) + (4 * (PairwiseCnt - 1)); - break; - } - - if ((pAd->OpMode == OPMODE_STA) && - (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) && - (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled)) { - u32 GroupCipher = pAd->StaCfg.GroupCipher; - switch (GroupCipher) { - case Ndis802_11GroupWEP40Enabled: - NdisMoveMemory(pRsnie_cipher->mcast, - OUI_WPA2_WEP40, 4); - break; - case Ndis802_11GroupWEP104Enabled: - NdisMoveMemory(pRsnie_cipher->mcast, - OUI_WPA2_WEP104, 4); - break; - } - } - /* swap for big-endian platform */ - pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version); - pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount); - } else { - struct rt_rsnie *pRsnie_cipher = (struct rt_rsnie *)pRsnIe; - - /* Assign OUI and version */ - NdisMoveMemory(pRsnie_cipher->oui, OUI_WPA_VERSION, 4); - pRsnie_cipher->version = 1; - - switch (WepStatus) { - /* TKIP mode */ - case Ndis802_11Encryption2Enabled: - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4); - pRsnie_cipher->ucount = 1; - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, - OUI_WPA_TKIP, 4); - *rsn_len = sizeof(struct rt_rsnie); - break; - - /* AES mode */ - case Ndis802_11Encryption3Enabled: - if (bMixCipher) - NdisMoveMemory(pRsnie_cipher->mcast, - OUI_WPA_TKIP, 4); - else - NdisMoveMemory(pRsnie_cipher->mcast, - OUI_WPA_CCMP, 4); - pRsnie_cipher->ucount = 1; - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, - OUI_WPA_CCMP, 4); - *rsn_len = sizeof(struct rt_rsnie); - break; - - /* TKIP-AES mix mode */ - case Ndis802_11Encryption4Enabled: - NdisMoveMemory(pRsnie_cipher->mcast, OUI_WPA_TKIP, 4); - - PairwiseCnt = 1; - /* Insert WPA TKIP as the first pairwise cipher */ - if (MIX_CIPHER_WPA_TKIP_ON(FlexibleCipher)) { - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, - OUI_WPA_TKIP, 4); - /* Insert WPA AES as the secondary pairwise cipher */ - if (MIX_CIPHER_WPA_AES_ON(FlexibleCipher)) { - NdisMoveMemory(pRsnie_cipher->ucast[0]. - oui + 4, OUI_WPA_CCMP, - 4); - PairwiseCnt = 2; - } - } else { - /* Insert WPA AES as the first pairwise cipher */ - NdisMoveMemory(pRsnie_cipher->ucast[0].oui, - OUI_WPA_CCMP, 4); - } - - pRsnie_cipher->ucount = PairwiseCnt; - *rsn_len = sizeof(struct rt_rsnie) + (4 * (PairwiseCnt - 1)); - break; - } - - if ((pAd->OpMode == OPMODE_STA) && - (pAd->StaCfg.GroupCipher != Ndis802_11Encryption2Enabled) && - (pAd->StaCfg.GroupCipher != Ndis802_11Encryption3Enabled)) { - u32 GroupCipher = pAd->StaCfg.GroupCipher; - switch (GroupCipher) { - case Ndis802_11GroupWEP40Enabled: - NdisMoveMemory(pRsnie_cipher->mcast, - OUI_WPA_WEP40, 4); - break; - case Ndis802_11GroupWEP104Enabled: - NdisMoveMemory(pRsnie_cipher->mcast, - OUI_WPA_WEP104, 4); - break; - } - } - /* swap for big-endian platform */ - pRsnie_cipher->version = cpu2le16(pRsnie_cipher->version); - pRsnie_cipher->ucount = cpu2le16(pRsnie_cipher->ucount); - } -} - -/* - ======================================================================== - - Routine Description: - Build AKM suite in RSN-IE. - It only shall be called by RTMPMakeRSNIE. - - Arguments: - pAd - pointer to our pAdapter context - ElementID - indicate the WPA1 or WPA2 - AuthMode - indicate the authentication mode - apidx - indicate the interface index - - Return Value: - - Note: - - ======================================================================== -*/ -static void RTMPMakeRsnIeAKM(struct rt_rtmp_adapter *pAd, - u8 ElementID, - u32 AuthMode, - u8 apidx, - u8 *pRsnIe, u8 * rsn_len) -{ - struct rt_rsnie_auth *pRsnie_auth; - u8 AkmCnt = 1; /* default as 1 */ - - pRsnie_auth = (struct rt_rsnie_auth *) (pRsnIe + (*rsn_len)); - - /* decide WPA2 or WPA1 */ - if (ElementID == Wpa2Ie) { - - switch (AuthMode) { - case Ndis802_11AuthModeWPA2: - case Ndis802_11AuthModeWPA1WPA2: - NdisMoveMemory(pRsnie_auth->auth[0].oui, - OUI_WPA2_8021X_AKM, 4); - break; - - case Ndis802_11AuthModeWPA2PSK: - case Ndis802_11AuthModeWPA1PSKWPA2PSK: - NdisMoveMemory(pRsnie_auth->auth[0].oui, - OUI_WPA2_PSK_AKM, 4); - break; - default: - AkmCnt = 0; - break; - - } - } else { - switch (AuthMode) { - case Ndis802_11AuthModeWPA: - case Ndis802_11AuthModeWPA1WPA2: - NdisMoveMemory(pRsnie_auth->auth[0].oui, - OUI_WPA_8021X_AKM, 4); - break; - - case Ndis802_11AuthModeWPAPSK: - case Ndis802_11AuthModeWPA1PSKWPA2PSK: - NdisMoveMemory(pRsnie_auth->auth[0].oui, - OUI_WPA_PSK_AKM, 4); - break; - - case Ndis802_11AuthModeWPANone: - NdisMoveMemory(pRsnie_auth->auth[0].oui, - OUI_WPA_NONE_AKM, 4); - break; - default: - AkmCnt = 0; - break; - } - } - - pRsnie_auth->acount = AkmCnt; - pRsnie_auth->acount = cpu2le16(pRsnie_auth->acount); - - /* update current RSNIE length */ - (*rsn_len) += (sizeof(struct rt_rsnie_auth) + (4 * (AkmCnt - 1))); - -} - -/* - ======================================================================== - - Routine Description: - Build capability in RSN-IE. - It only shall be called by RTMPMakeRSNIE. - - Arguments: - pAd - pointer to our pAdapter context - ElementID - indicate the WPA1 or WPA2 - apidx - indicate the interface index - - Return Value: - - Note: - - ======================================================================== -*/ -static void RTMPMakeRsnIeCap(struct rt_rtmp_adapter *pAd, - u8 ElementID, - u8 apidx, - u8 *pRsnIe, u8 * rsn_len) -{ - RSN_CAPABILITIES *pRSN_Cap; - - /* it could be ignored in WPA1 mode */ - if (ElementID == WpaIe) - return; - - pRSN_Cap = (RSN_CAPABILITIES *) (pRsnIe + (*rsn_len)); - - pRSN_Cap->word = cpu2le16(pRSN_Cap->word); - - (*rsn_len) += sizeof(RSN_CAPABILITIES); /* update current RSNIE length */ - -} - -/* - ======================================================================== - - Routine Description: - Build RSN IE context. It is not included element-ID and length. - - Arguments: - pAd - pointer to our pAdapter context - AuthMode - indicate the authentication mode - WepStatus - indicate the encryption type - apidx - indicate the interface index - - Return Value: - - Note: - - ======================================================================== -*/ -void RTMPMakeRSNIE(struct rt_rtmp_adapter *pAd, - u32 AuthMode, u32 WepStatus, u8 apidx) -{ - u8 *pRsnIe = NULL; /* primary RSNIE */ - u8 *rsnielen_cur_p = 0; /* the length of the primary RSNIE */ - u8 *rsnielen_ex_cur_p = 0; /* the length of the secondary RSNIE */ - u8 PrimaryRsnie; - BOOLEAN bMixCipher = FALSE; /* indicate the pairwise and group cipher are different */ - u8 p_offset; - WPA_MIX_PAIR_CIPHER FlexibleCipher = WPA_TKIPAES_WPA2_TKIPAES; /* it provide the more flexible cipher combination in WPA-WPA2 and TKIPAES mode */ - - rsnielen_cur_p = NULL; - rsnielen_ex_cur_p = NULL; - - { - { - if (pAd->StaCfg.WpaSupplicantUP != - WPA_SUPPLICANT_DISABLE) { - if (AuthMode < Ndis802_11AuthModeWPA) - return; - } else { - /* Support WPAPSK or WPA2PSK in STA-Infra mode */ - /* Support WPANone in STA-Adhoc mode */ - if ((AuthMode != Ndis802_11AuthModeWPAPSK) && - (AuthMode != Ndis802_11AuthModeWPA2PSK) && - (AuthMode != Ndis802_11AuthModeWPANone) - ) - return; - } - - DBGPRINT(RT_DEBUG_TRACE, ("==> RTMPMakeRSNIE(STA)\n")); - - /* Zero RSNIE context */ - pAd->StaCfg.RSNIE_Len = 0; - NdisZeroMemory(pAd->StaCfg.RSN_IE, MAX_LEN_OF_RSNIE); - - /* Pointer to RSNIE */ - rsnielen_cur_p = &pAd->StaCfg.RSNIE_Len; - pRsnIe = pAd->StaCfg.RSN_IE; - - bMixCipher = pAd->StaCfg.bMixCipher; - } - } - - /* indicate primary RSNIE as WPA or WPA2 */ - if ((AuthMode == Ndis802_11AuthModeWPA) || - (AuthMode == Ndis802_11AuthModeWPAPSK) || - (AuthMode == Ndis802_11AuthModeWPANone) || - (AuthMode == Ndis802_11AuthModeWPA1WPA2) || - (AuthMode == Ndis802_11AuthModeWPA1PSKWPA2PSK)) - PrimaryRsnie = WpaIe; - else - PrimaryRsnie = Wpa2Ie; - - { - /* Build the primary RSNIE */ - /* 1. insert cipher suite */ - RTMPMakeRsnIeCipher(pAd, PrimaryRsnie, WepStatus, bMixCipher, - FlexibleCipher, pRsnIe, &p_offset); - - /* 2. insert AKM */ - RTMPMakeRsnIeAKM(pAd, PrimaryRsnie, AuthMode, apidx, pRsnIe, - &p_offset); - - /* 3. insert capability */ - RTMPMakeRsnIeCap(pAd, PrimaryRsnie, apidx, pRsnIe, &p_offset); - } - - /* 4. update the RSNIE length */ - *rsnielen_cur_p = p_offset; - - hex_dump("The primary RSNIE", pRsnIe, (*rsnielen_cur_p)); - -} - -/* - ========================================================================== - Description: - Check whether the received frame is EAP frame. - - Arguments: - pAd - pointer to our pAdapter context - pEntry - pointer to active entry - pData - the received frame - DataByteCount - the received frame's length - FromWhichBSSID - indicate the interface index - - Return: - TRUE - This frame is EAP frame - FALSE - otherwise - ========================================================================== -*/ -BOOLEAN RTMPCheckWPAframe(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 *pData, - unsigned long DataByteCount, u8 FromWhichBSSID) -{ - unsigned long Body_len; - BOOLEAN Cancelled; - - if (DataByteCount < (LENGTH_802_1_H + LENGTH_EAPOL_H)) - return FALSE; - - /* Skip LLC header */ - if (NdisEqualMemory(SNAP_802_1H, pData, 6) || - /* Cisco 1200 AP may send packet with SNAP_BRIDGE_TUNNEL */ - NdisEqualMemory(SNAP_BRIDGE_TUNNEL, pData, 6)) { - pData += 6; - } - /* Skip 2-bytes EAPoL type */ - if (NdisEqualMemory(EAPOL, pData, 2)) { - pData += 2; - } else - return FALSE; - - switch (*(pData + 1)) { - case EAPPacket: - Body_len = (*(pData + 2) << 8) | (*(pData + 3)); - DBGPRINT(RT_DEBUG_TRACE, - ("Receive EAP-Packet frame, TYPE = 0, Length = %ld\n", - Body_len)); - break; - case EAPOLStart: - DBGPRINT(RT_DEBUG_TRACE, - ("Receive EAPOL-Start frame, TYPE = 1 \n")); - if (pEntry->EnqueueEapolStartTimerRunning != - EAPOL_START_DISABLE) { - DBGPRINT(RT_DEBUG_TRACE, - ("Cancel the EnqueueEapolStartTimerRunning \n")); - RTMPCancelTimer(&pEntry->EnqueueStartForPSKTimer, - &Cancelled); - pEntry->EnqueueEapolStartTimerRunning = - EAPOL_START_DISABLE; - } - break; - case EAPOLLogoff: - DBGPRINT(RT_DEBUG_TRACE, - ("Receive EAPOLLogoff frame, TYPE = 2 \n")); - break; - case EAPOLKey: - Body_len = (*(pData + 2) << 8) | (*(pData + 3)); - DBGPRINT(RT_DEBUG_TRACE, - ("Receive EAPOL-Key frame, TYPE = 3, Length = %ld\n", - Body_len)); - break; - case EAPOLASFAlert: - DBGPRINT(RT_DEBUG_TRACE, - ("Receive EAPOLASFAlert frame, TYPE = 4 \n")); - break; - default: - return FALSE; - - } - return TRUE; -} - -/* - ========================================================================== - Description: - Report the EAP message type - - Arguments: - msg - EAPOL_PAIR_MSG_1 - EAPOL_PAIR_MSG_2 - EAPOL_PAIR_MSG_3 - EAPOL_PAIR_MSG_4 - EAPOL_GROUP_MSG_1 - EAPOL_GROUP_MSG_2 - - Return: - message type string - - ========================================================================== -*/ -char *GetEapolMsgType(char msg) -{ - if (msg == EAPOL_PAIR_MSG_1) - return "Pairwise Message 1"; - else if (msg == EAPOL_PAIR_MSG_2) - return "Pairwise Message 2"; - else if (msg == EAPOL_PAIR_MSG_3) - return "Pairwise Message 3"; - else if (msg == EAPOL_PAIR_MSG_4) - return "Pairwise Message 4"; - else if (msg == EAPOL_GROUP_MSG_1) - return "Group Message 1"; - else if (msg == EAPOL_GROUP_MSG_2) - return "Group Message 2"; - else - return "Invalid Message"; -} - -/* - ======================================================================== - - Routine Description: - Check Sanity RSN IE of EAPoL message - - Arguments: - - Return Value: - - ======================================================================== -*/ -BOOLEAN RTMPCheckRSNIE(struct rt_rtmp_adapter *pAd, - u8 *pData, - u8 DataLen, - struct rt_mac_table_entry *pEntry, u8 * Offset) -{ - u8 *pVIE; - u8 len; - struct rt_eid * pEid; - BOOLEAN result = FALSE; - - pVIE = pData; - len = DataLen; - *Offset = 0; - - while (len > sizeof(struct rt_rsnie2)) { - pEid = (struct rt_eid *) pVIE; - /* WPA RSN IE */ - if ((pEid->Eid == IE_WPA) - && (NdisEqualMemory(pEid->Octet, WPA_OUI, 4))) { - if ((pEntry->AuthMode == Ndis802_11AuthModeWPA - || pEntry->AuthMode == Ndis802_11AuthModeWPAPSK) - && - (NdisEqualMemory - (pVIE, pEntry->RSN_IE, pEntry->RSNIE_Len)) - && (pEntry->RSNIE_Len == (pEid->Len + 2))) { - result = TRUE; - } - - *Offset += (pEid->Len + 2); - } - /* WPA2 RSN IE */ - else if ((pEid->Eid == IE_RSN) - && (NdisEqualMemory(pEid->Octet + 2, RSN_OUI, 3))) { - if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2 - || pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK) - && (pEid->Eid == pEntry->RSN_IE[0]) - && ((pEid->Len + 2) >= pEntry->RSNIE_Len) - && - (NdisEqualMemory - (pEid->Octet, &pEntry->RSN_IE[2], - pEntry->RSNIE_Len - 2))) { - - result = TRUE; - } - - *Offset += (pEid->Len + 2); - } else { - break; - } - - pVIE += (pEid->Len + 2); - len -= (pEid->Len + 2); - } - - return result; - -} - -/* - ======================================================================== - - Routine Description: - Parse KEYDATA field. KEYDATA[] May contain 2 RSN IE and optionally GTK. - GTK is encaptulated in KDE format at p.83 802.11i D10 - - Arguments: - - Return Value: - - Note: - 802.11i D10 - - ======================================================================== -*/ -BOOLEAN RTMPParseEapolKeyData(struct rt_rtmp_adapter *pAd, - u8 *pKeyData, - u8 KeyDataLen, - u8 GroupKeyIndex, - u8 MsgType, - IN BOOLEAN bWPA2, struct rt_mac_table_entry *pEntry) -{ - struct rt_kde_encap * pKDE = NULL; - u8 *pMyKeyData = pKeyData; - u8 KeyDataLength = KeyDataLen; - u8 GTKLEN = 0; - u8 DefaultIdx = 0; - u8 skip_offset; - - /* Verify The RSN IE contained in pairewise_msg_2 && pairewise_msg_3 and skip it */ - if (MsgType == EAPOL_PAIR_MSG_2 || MsgType == EAPOL_PAIR_MSG_3) { - /* Check RSN IE whether it is WPA2/WPA2PSK */ - if (!RTMPCheckRSNIE - (pAd, pKeyData, KeyDataLen, pEntry, &skip_offset)) { - /* send wireless event - for RSN IE different */ - if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, - IW_RSNIE_DIFF_EVENT_FLAG, - pEntry->Addr, - pEntry->apidx, 0); - - DBGPRINT(RT_DEBUG_ERROR, - ("RSN_IE Different in msg %d of 4-way handshake!\n", - MsgType)); - hex_dump("Receive RSN_IE ", pKeyData, KeyDataLen); - hex_dump("Desired RSN_IE ", pEntry->RSN_IE, - pEntry->RSNIE_Len); - - return FALSE; - } else { - if (bWPA2 && MsgType == EAPOL_PAIR_MSG_3) { - WpaShowAllsuite(pMyKeyData, skip_offset); - - /* skip RSN IE */ - pMyKeyData += skip_offset; - KeyDataLength -= skip_offset; - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPParseEapolKeyData ==> WPA2/WPA2PSK RSN IE matched in Msg 3, Length(%d) \n", - skip_offset)); - } else - return TRUE; - } - } - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPParseEapolKeyData ==> KeyDataLength %d without RSN_IE \n", - KeyDataLength)); - /*hex_dump("remain data", pMyKeyData, KeyDataLength); */ - - /* Parse EKD format in pairwise_msg_3_WPA2 && group_msg_1_WPA2 */ - if (bWPA2 - && (MsgType == EAPOL_PAIR_MSG_3 || MsgType == EAPOL_GROUP_MSG_1)) { - if (KeyDataLength >= 8) /* KDE format exclude GTK length */ - { - pKDE = (struct rt_kde_encap *) pMyKeyData; - - DefaultIdx = pKDE->GTKEncap.Kid; - - /* Sanity check - KED length */ - if (KeyDataLength < (pKDE->Len + 2)) { - DBGPRINT(RT_DEBUG_ERROR, - ("ERROR: The len from KDE is too short \n")); - return FALSE; - } - /* Get GTK length - refer to IEEE 802.11i-2004 p.82 */ - GTKLEN = pKDE->Len - 6; - if (GTKLEN < LEN_AES_KEY) { - DBGPRINT(RT_DEBUG_ERROR, - ("ERROR: GTK Key length is too short (%d) \n", - GTKLEN)); - return FALSE; - } - - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("ERROR: KDE format length is too short \n")); - return FALSE; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("GTK in KDE format ,DefaultKeyID=%d, KeyLen=%d \n", - DefaultIdx, GTKLEN)); - /* skip it */ - pMyKeyData += 8; - KeyDataLength -= 8; - - } else if (!bWPA2 && MsgType == EAPOL_GROUP_MSG_1) { - DefaultIdx = GroupKeyIndex; - DBGPRINT(RT_DEBUG_TRACE, - ("GTK DefaultKeyID=%d \n", DefaultIdx)); - } - /* Sanity check - shared key index must be 1 ~ 3 */ - if (DefaultIdx < 1 || DefaultIdx > 3) { - DBGPRINT(RT_DEBUG_ERROR, - ("ERROR: GTK Key index(%d) is invalid in %s %s \n", - DefaultIdx, ((bWPA2) ? "WPA2" : "WPA"), - GetEapolMsgType(MsgType))); - return FALSE; - } - - { - struct rt_cipher_key *pSharedKey; - - /* set key material, TxMic and RxMic */ - NdisMoveMemory(pAd->StaCfg.GTK, pMyKeyData, 32); - pAd->StaCfg.DefaultKeyId = DefaultIdx; - - pSharedKey = &pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId]; - - /* Prepare pair-wise key information into shared key table */ - NdisZeroMemory(pSharedKey, sizeof(struct rt_cipher_key)); - pSharedKey->KeyLen = LEN_TKIP_EK; - NdisMoveMemory(pSharedKey->Key, pAd->StaCfg.GTK, LEN_TKIP_EK); - NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.GTK[16], - LEN_TKIP_RXMICK); - NdisMoveMemory(pSharedKey->TxMic, &pAd->StaCfg.GTK[24], - LEN_TKIP_TXMICK); - - /* Update Shared Key CipherAlg */ - pSharedKey->CipherAlg = CIPHER_NONE; - if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled) - pSharedKey->CipherAlg = CIPHER_TKIP; - else if (pAd->StaCfg.GroupCipher == - Ndis802_11Encryption3Enabled) - pSharedKey->CipherAlg = CIPHER_AES; - else if (pAd->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled) - pSharedKey->CipherAlg = CIPHER_WEP64; - else if (pAd->StaCfg.GroupCipher == - Ndis802_11GroupWEP104Enabled) - pSharedKey->CipherAlg = CIPHER_WEP128; - - /* Update group key information to ASIC Shared Key Table */ - AsicAddSharedKeyEntry(pAd, - BSS0, - pAd->StaCfg.DefaultKeyId, - pSharedKey->CipherAlg, - pSharedKey->Key, - pSharedKey->TxMic, pSharedKey->RxMic); - - /* Update ASIC WCID attribute table and IVEIV table */ - RTMPAddWcidAttributeEntry(pAd, - BSS0, - pAd->StaCfg.DefaultKeyId, - pSharedKey->CipherAlg, NULL); - } - - return TRUE; - -} - -/* - ======================================================================== - - Routine Description: - Construct EAPoL message for WPA handshaking - Its format is below, - - +--------------------+ - | Protocol Version | 1 octet - +--------------------+ - | Protocol Type | 1 octet - +--------------------+ - | Body Length | 2 octets - +--------------------+ - | Descriptor Type | 1 octet - +--------------------+ - | Key Information | 2 octets - +--------------------+ - | Key Length | 1 octet - +--------------------+ - | Key Repaly Counter | 8 octets - +--------------------+ - | Key Nonce | 32 octets - +--------------------+ - | Key IV | 16 octets - +--------------------+ - | Key RSC | 8 octets - +--------------------+ - | Key ID or Reserved | 8 octets - +--------------------+ - | Key MIC | 16 octets - +--------------------+ - | Key Data Length | 2 octets - +--------------------+ - | Key Data | n octets - +--------------------+ - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - Note: - - ======================================================================== -*/ -void ConstructEapolMsg(struct rt_mac_table_entry *pEntry, - u8 GroupKeyWepStatus, - u8 MsgType, - u8 DefaultKeyIdx, - u8 * KeyNonce, - u8 * TxRSC, - u8 * GTK, - u8 * RSNIE, - u8 RSNIE_Len, struct rt_eapol_packet * pMsg) -{ - BOOLEAN bWPA2 = FALSE; - u8 KeyDescVer; - - /* Choose WPA2 or not */ - if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) || - (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK)) - bWPA2 = TRUE; - - /* Init Packet and Fill header */ - pMsg->ProVer = EAPOL_VER; - pMsg->ProType = EAPOLKey; - - /* Default 95 bytes, the EAPoL-Key descriptor exclude Key-data field */ - SET_u16_TO_ARRARY(pMsg->Body_Len, LEN_EAPOL_KEY_MSG); - - /* Fill in EAPoL descriptor */ - if (bWPA2) - pMsg->KeyDesc.Type = WPA2_KEY_DESC; - else - pMsg->KeyDesc.Type = WPA1_KEY_DESC; - - /* Key Descriptor Version (bits 0-2) specifies the key descriptor version type */ - { - /* Fill in Key information, refer to IEEE Std 802.11i-2004 page 78 */ - /* When either the pairwise or the group cipher is AES, the DESC_TYPE_AES(2) shall be used. */ - KeyDescVer = - (((pEntry->WepStatus == Ndis802_11Encryption3Enabled) - || (GroupKeyWepStatus == - Ndis802_11Encryption3Enabled)) ? (DESC_TYPE_AES) - : (DESC_TYPE_TKIP)); - } - - pMsg->KeyDesc.KeyInfo.KeyDescVer = KeyDescVer; - - /* Specify Key Type as Group(0) or Pairwise(1) */ - if (MsgType >= EAPOL_GROUP_MSG_1) - pMsg->KeyDesc.KeyInfo.KeyType = GROUPKEY; - else - pMsg->KeyDesc.KeyInfo.KeyType = PAIRWISEKEY; - - /* Specify Key Index, only group_msg1_WPA1 */ - if (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1)) - pMsg->KeyDesc.KeyInfo.KeyIndex = DefaultKeyIdx; - - if (MsgType == EAPOL_PAIR_MSG_3) - pMsg->KeyDesc.KeyInfo.Install = 1; - - if ((MsgType == EAPOL_PAIR_MSG_1) || (MsgType == EAPOL_PAIR_MSG_3) - || (MsgType == EAPOL_GROUP_MSG_1)) - pMsg->KeyDesc.KeyInfo.KeyAck = 1; - - if (MsgType != EAPOL_PAIR_MSG_1) - pMsg->KeyDesc.KeyInfo.KeyMic = 1; - - if ((bWPA2 && (MsgType >= EAPOL_PAIR_MSG_3)) || - (!bWPA2 && (MsgType >= EAPOL_GROUP_MSG_1))) { - pMsg->KeyDesc.KeyInfo.Secure = 1; - } - - if (bWPA2 && ((MsgType == EAPOL_PAIR_MSG_3) || - (MsgType == EAPOL_GROUP_MSG_1))) { - pMsg->KeyDesc.KeyInfo.EKD_DL = 1; - } - /* key Information element has done. */ - *(u16 *) (&pMsg->KeyDesc.KeyInfo) = - cpu2le16(*(u16 *) (&pMsg->KeyDesc.KeyInfo)); - - /* Fill in Key Length */ - { - if (MsgType >= EAPOL_GROUP_MSG_1) { - /* the length of group key cipher */ - pMsg->KeyDesc.KeyLength[1] = - ((GroupKeyWepStatus == - Ndis802_11Encryption2Enabled) ? TKIP_GTK_LENGTH : - LEN_AES_KEY); - } else { - /* the length of pairwise key cipher */ - pMsg->KeyDesc.KeyLength[1] = - ((pEntry->WepStatus == - Ndis802_11Encryption2Enabled) ? LEN_TKIP_KEY : - LEN_AES_KEY); - } - } - - /* Fill in replay counter */ - NdisMoveMemory(pMsg->KeyDesc.ReplayCounter, pEntry->R_Counter, - LEN_KEY_DESC_REPLAY); - - /* Fill Key Nonce field */ - /* ANonce : pairwise_msg1 & pairwise_msg3 */ - /* SNonce : pairwise_msg2 */ - /* GNonce : group_msg1_wpa1 */ - if ((MsgType <= EAPOL_PAIR_MSG_3) - || ((!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1)))) - NdisMoveMemory(pMsg->KeyDesc.KeyNonce, KeyNonce, - LEN_KEY_DESC_NONCE); - - /* Fill key IV - WPA2 as 0, WPA1 as random */ - if (!bWPA2 && (MsgType == EAPOL_GROUP_MSG_1)) { - /* Suggest IV be random number plus some number, */ - NdisMoveMemory(pMsg->KeyDesc.KeyIv, &KeyNonce[16], - LEN_KEY_DESC_IV); - pMsg->KeyDesc.KeyIv[15] += 2; - } - /* Fill Key RSC field */ - /* It contains the RSC for the GTK being installed. */ - if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2) - || (MsgType == EAPOL_GROUP_MSG_1)) { - NdisMoveMemory(pMsg->KeyDesc.KeyRsc, TxRSC, 6); - } - /* Clear Key MIC field for MIC calculation later */ - NdisZeroMemory(pMsg->KeyDesc.KeyMic, LEN_KEY_DESC_MIC); - - ConstructEapolKeyData(pEntry, - GroupKeyWepStatus, - KeyDescVer, - MsgType, - DefaultKeyIdx, GTK, RSNIE, RSNIE_Len, pMsg); - - /* Calculate MIC and fill in KeyMic Field except Pairwise Msg 1. */ - if (MsgType != EAPOL_PAIR_MSG_1) { - CalculateMIC(KeyDescVer, pEntry->PTK, pMsg); - } - - DBGPRINT(RT_DEBUG_TRACE, - ("===> ConstructEapolMsg for %s %s\n", - ((bWPA2) ? "WPA2" : "WPA"), GetEapolMsgType(MsgType))); - DBGPRINT(RT_DEBUG_TRACE, - (" Body length = %d \n", - CONV_ARRARY_TO_u16(pMsg->Body_Len))); - DBGPRINT(RT_DEBUG_TRACE, - (" Key length = %d \n", - CONV_ARRARY_TO_u16(pMsg->KeyDesc.KeyLength))); - -} - -/* - ======================================================================== - - Routine Description: - Construct the Key Data field of EAPoL message - - Arguments: - pAd Pointer to our adapter - Elem Message body - - Return Value: - None - - Note: - - ======================================================================== -*/ -void ConstructEapolKeyData(struct rt_mac_table_entry *pEntry, - u8 GroupKeyWepStatus, - u8 keyDescVer, - u8 MsgType, - u8 DefaultKeyIdx, - u8 * GTK, - u8 * RSNIE, - u8 RSNIE_LEN, struct rt_eapol_packet * pMsg) -{ - u8 *mpool, *Key_Data, *Rc4GTK; - u8 ekey[(LEN_KEY_DESC_IV + LEN_EAP_EK)]; - unsigned long data_offset; - BOOLEAN bWPA2Capable = FALSE; - struct rt_rtmp_adapter *pAd = pEntry->pAd; - BOOLEAN GTK_Included = FALSE; - - /* Choose WPA2 or not */ - if ((pEntry->AuthMode == Ndis802_11AuthModeWPA2) || - (pEntry->AuthMode == Ndis802_11AuthModeWPA2PSK)) - bWPA2Capable = TRUE; - - if (MsgType == EAPOL_PAIR_MSG_1 || - MsgType == EAPOL_PAIR_MSG_4 || MsgType == EAPOL_GROUP_MSG_2) - return; - - /* allocate memory pool */ - os_alloc_mem(NULL, (u8 **) & mpool, 1500); - - if (mpool == NULL) - return; - - /* Rc4GTK Len = 512 */ - Rc4GTK = (u8 *) ROUND_UP(mpool, 4); - /* Key_Data Len = 512 */ - Key_Data = (u8 *) ROUND_UP(Rc4GTK + 512, 4); - - NdisZeroMemory(Key_Data, 512); - SET_u16_TO_ARRARY(pMsg->KeyDesc.KeyDataLen, 0); - data_offset = 0; - - /* Encapsulate RSNIE in pairwise_msg2 & pairwise_msg3 */ - if (RSNIE_LEN - && ((MsgType == EAPOL_PAIR_MSG_2) - || (MsgType == EAPOL_PAIR_MSG_3))) { - u8 *pmkid_ptr = NULL; - u8 pmkid_len = 0; - - RTMPInsertRSNIE(&Key_Data[data_offset], - &data_offset, - RSNIE, RSNIE_LEN, pmkid_ptr, pmkid_len); - } - - /* Encapsulate KDE format in pairwise_msg3_WPA2 & group_msg1_WPA2 */ - if (bWPA2Capable - && ((MsgType == EAPOL_PAIR_MSG_3) - || (MsgType == EAPOL_GROUP_MSG_1))) { - /* Key Data Encapsulation (KDE) format - 802.11i-2004 Figure-43w and Table-20h */ - Key_Data[data_offset + 0] = 0xDD; - - if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled) { - Key_Data[data_offset + 1] = 0x16; /* 4+2+16(OUI+DataType+DataField) */ - } else { - Key_Data[data_offset + 1] = 0x26; /* 4+2+32(OUI+DataType+DataField) */ - } - - Key_Data[data_offset + 2] = 0x00; - Key_Data[data_offset + 3] = 0x0F; - Key_Data[data_offset + 4] = 0xAC; - Key_Data[data_offset + 5] = 0x01; - - /* GTK KDE format - 802.11i-2004 Figure-43x */ - Key_Data[data_offset + 6] = (DefaultKeyIdx & 0x03); - Key_Data[data_offset + 7] = 0x00; /* Reserved Byte */ - - data_offset += 8; - } - - /* Encapsulate GTK */ - /* Only for pairwise_msg3_WPA2 and group_msg1 */ - if ((MsgType == EAPOL_PAIR_MSG_3 && bWPA2Capable) - || (MsgType == EAPOL_GROUP_MSG_1)) { - /* Fill in GTK */ - if (GroupKeyWepStatus == Ndis802_11Encryption3Enabled) { - NdisMoveMemory(&Key_Data[data_offset], GTK, - LEN_AES_KEY); - data_offset += LEN_AES_KEY; - } else { - NdisMoveMemory(&Key_Data[data_offset], GTK, - TKIP_GTK_LENGTH); - data_offset += TKIP_GTK_LENGTH; - } - - GTK_Included = TRUE; - } - - /* This whole key-data field shall be encrypted if a GTK is included. */ - /* Encrypt the data material in key data field with KEK */ - if (GTK_Included) { - /*hex_dump("GTK_Included", Key_Data, data_offset); */ - - if ((keyDescVer == DESC_TYPE_AES)) { - u8 remainder = 0; - u8 pad_len = 0; - - /* Key Descriptor Version 2 or 3: AES key wrap, defined in IETF RFC 3394, */ - /* shall be used to encrypt the Key Data field using the KEK field from */ - /* the derived PTK. */ - - /* If the Key Data field uses the NIST AES key wrap, then the Key Data field */ - /* shall be padded before encrypting if the key data length is less than 16 */ - /* octets or if it is not a multiple of 8. The padding consists of appending */ - /* a single octet 0xdd followed by zero or more 0x00 octets. */ - if ((remainder = data_offset & 0x07) != 0) { - int i; - - pad_len = (8 - remainder); - Key_Data[data_offset] = 0xDD; - for (i = 1; i < pad_len; i++) - Key_Data[data_offset + i] = 0; - - data_offset += pad_len; - } - - AES_GTK_KEY_WRAP(&pEntry->PTK[16], Key_Data, - data_offset, Rc4GTK); - /* AES wrap function will grow 8 bytes in length */ - data_offset += 8; - } else { - /* Key Descriptor Version 1: ARC4 is used to encrypt the Key Data field - using the KEK field from the derived PTK. */ - - /* PREPARE Encrypted "Key DATA" field. (Encrypt GTK with RC4, usinf PTK[16]->[31] as Key, IV-field as IV) */ - /* put TxTsc in Key RSC field */ - pAd->PrivateInfo.FCSCRC32 = PPPINITFCS32; /*Init crc32. */ - - /* ekey is the contanetion of IV-field, and PTK[16]->PTK[31] */ - NdisMoveMemory(ekey, pMsg->KeyDesc.KeyIv, - LEN_KEY_DESC_IV); - NdisMoveMemory(&ekey[LEN_KEY_DESC_IV], &pEntry->PTK[16], - LEN_EAP_EK); - ARCFOUR_INIT(&pAd->PrivateInfo.WEPCONTEXT, ekey, sizeof(ekey)); /*INIT SBOX, KEYLEN+3(IV) */ - pAd->PrivateInfo.FCSCRC32 = - RTMP_CALC_FCS32(pAd->PrivateInfo.FCSCRC32, Key_Data, - data_offset); - WPAARCFOUR_ENCRYPT(&pAd->PrivateInfo.WEPCONTEXT, Rc4GTK, - Key_Data, data_offset); - } - - NdisMoveMemory(pMsg->KeyDesc.KeyData, Rc4GTK, data_offset); - } else { - NdisMoveMemory(pMsg->KeyDesc.KeyData, Key_Data, data_offset); - } - - /* Update key data length field and total body length */ - SET_u16_TO_ARRARY(pMsg->KeyDesc.KeyDataLen, data_offset); - INC_u16_TO_ARRARY(pMsg->Body_Len, data_offset); - - os_free_mem(NULL, mpool); - -} - -/* - ======================================================================== - - Routine Description: - Calcaulate MIC. It is used during 4-ways handsharking. - - Arguments: - pAd - pointer to our pAdapter context - PeerWepStatus - indicate the encryption type - - Return Value: - - Note: - - ======================================================================== -*/ -static void CalculateMIC(u8 KeyDescVer, - u8 * PTK, struct rt_eapol_packet * pMsg) -{ - u8 *OutBuffer; - unsigned long FrameLen = 0; - u8 mic[LEN_KEY_DESC_MIC]; - u8 digest[80]; - - /* allocate memory for MIC calculation */ - os_alloc_mem(NULL, (u8 **) & OutBuffer, 512); - - if (OutBuffer == NULL) { - DBGPRINT(RT_DEBUG_ERROR, ("CalculateMIC: no memory!\n")); - return; - } - /* make a frame for calculating MIC. */ - MakeOutgoingFrame(OutBuffer, &FrameLen, - CONV_ARRARY_TO_u16(pMsg->Body_Len) + 4, pMsg, - END_OF_ARGS); - - NdisZeroMemory(mic, sizeof(mic)); - - /* Calculate MIC */ - if (KeyDescVer == DESC_TYPE_AES) { - HMAC_SHA1(PTK, LEN_EAP_MICK, OutBuffer, FrameLen, digest, - SHA1_DIGEST_SIZE); - NdisMoveMemory(mic, digest, LEN_KEY_DESC_MIC); - } else { - HMAC_MD5(PTK, LEN_EAP_MICK, OutBuffer, FrameLen, mic, - MD5_DIGEST_SIZE); - } - - /* store the calculated MIC */ - NdisMoveMemory(pMsg->KeyDesc.KeyMic, mic, LEN_KEY_DESC_MIC); - - os_free_mem(NULL, OutBuffer); -} - -/* - ======================================================================== - - Routine Description: - Some received frames can't decrypt by Asic, so decrypt them by software. - - Arguments: - pAd - pointer to our pAdapter context - PeerWepStatus - indicate the encryption type - - Return Value: - NDIS_STATUS_SUCCESS - decryption successful - NDIS_STATUS_FAILURE - decryption failure - - ======================================================================== -*/ -int RTMPSoftDecryptBroadCastData(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, - IN NDIS_802_11_ENCRYPTION_STATUS - GroupCipher, struct rt_cipher_key *pShard_key) -{ - struct rt_rxwi * pRxWI = pRxBlk->pRxWI; - - /* handle WEP decryption */ - if (GroupCipher == Ndis802_11Encryption1Enabled) { - if (RTMPSoftDecryptWEP - (pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, - pShard_key)) { - - /*Minus IV[4] & ICV[4] */ - pRxWI->MPDUtotalByteCount -= 8; - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("ERROR : Software decrypt WEP data fails.\n")); - /* give up this frame */ - return NDIS_STATUS_FAILURE; - } - } - /* handle TKIP decryption */ - else if (GroupCipher == Ndis802_11Encryption2Enabled) { - if (RTMPSoftDecryptTKIP - (pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, 0, - pShard_key)) { - - /*Minus 8 bytes MIC, 8 bytes IV/EIV, 4 bytes ICV */ - pRxWI->MPDUtotalByteCount -= 20; - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("ERROR : RTMPSoftDecryptTKIP Failed\n")); - /* give up this frame */ - return NDIS_STATUS_FAILURE; - } - } - /* handle AES decryption */ - else if (GroupCipher == Ndis802_11Encryption3Enabled) { - if (RTMPSoftDecryptAES - (pAd, pRxBlk->pData, pRxWI->MPDUtotalByteCount, - pShard_key)) { - - /*8 bytes MIC, 8 bytes IV/EIV (CCMP Header) */ - pRxWI->MPDUtotalByteCount -= 16; - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("ERROR : RTMPSoftDecryptAES Failed\n")); - /* give up this frame */ - return NDIS_STATUS_FAILURE; - } - } else { - /* give up this frame */ - return NDIS_STATUS_FAILURE; - } - - return NDIS_STATUS_SUCCESS; - -} - -u8 *GetSuiteFromRSNIE(u8 *rsnie, - u32 rsnie_len, u8 type, u8 * count) -{ - struct rt_eid * pEid; - int len; - u8 *pBuf; - int offset = 0; - struct rt_rsnie_auth *pAkm; - u16 acount; - BOOLEAN isWPA2 = FALSE; - - pEid = (struct rt_eid *) rsnie; - len = rsnie_len - 2; /* exclude IE and length */ - pBuf = (u8 *)& pEid->Octet[0]; - - /* set default value */ - *count = 0; - - /* Check length */ - if ((len <= 0) || (pEid->Len != len)) { - DBGPRINT_ERR("%s : The length is invalid\n", __func__); - return NULL; - } - /* Check WPA or WPA2 */ - if (pEid->Eid == IE_WPA) { - struct rt_rsnie *pRsnie = (struct rt_rsnie *)pBuf; - u16 ucount; - - if (len < sizeof(struct rt_rsnie)) { - DBGPRINT_ERR("%s : The length is too short for WPA\n", __func__); - return NULL; - } - /* Get the count of pairwise cipher */ - ucount = cpu2le16(pRsnie->ucount); - if (ucount > 2) { - DBGPRINT_ERR("%s : The count(%d) of pairwise cipher is invlaid\n", __func__, ucount); - return NULL; - } - /* Get the group cipher */ - if (type == GROUP_SUITE) { - *count = 1; - return pRsnie->mcast; - } - /* Get the pairwise cipher suite */ - else if (type == PAIRWISE_SUITE) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s : The count of pairwise cipher is %d\n", - __func__, ucount)); - *count = ucount; - return pRsnie->ucast[0].oui; - } - - offset = sizeof(struct rt_rsnie) + (4 * (ucount - 1)); - - } else if (pEid->Eid == IE_RSN) { - struct rt_rsnie2 *pRsnie = (struct rt_rsnie2 *)pBuf; - u16 ucount; - - isWPA2 = TRUE; - - if (len < sizeof(struct rt_rsnie2)) { - DBGPRINT_ERR("%s : The length is too short for WPA2\n", __func__); - return NULL; - } - /* Get the count of pairwise cipher */ - ucount = cpu2le16(pRsnie->ucount); - if (ucount > 2) { - DBGPRINT_ERR("%s : The count(%d) of pairwise cipher is invlaid\n", __func__, ucount); - return NULL; - } - /* Get the group cipher */ - if (type == GROUP_SUITE) { - *count = 1; - return pRsnie->mcast; - } - /* Get the pairwise cipher suite */ - else if (type == PAIRWISE_SUITE) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s : The count of pairwise cipher is %d\n", - __func__, ucount)); - *count = ucount; - return pRsnie->ucast[0].oui; - } - - offset = sizeof(struct rt_rsnie2) + (4 * (ucount - 1)); - - } else { - DBGPRINT_ERR("%s : Unknown IE (%d)\n", __func__, pEid->Eid); - return NULL; - } - - /* skip group cipher and pairwise cipher suite */ - pBuf += offset; - len -= offset; - - if (len < sizeof(struct rt_rsnie_auth)) { - DBGPRINT_ERR("%s : The length of RSNIE is too short\n", __func__); - return NULL; - } - /* pointer to AKM count */ - pAkm = (struct rt_rsnie_auth *)pBuf; - - /* Get the count of pairwise cipher */ - acount = cpu2le16(pAkm->acount); - if (acount > 2) { - DBGPRINT_ERR("%s : The count(%d) of AKM is invlaid\n", __func__, acount); - return NULL; - } - /* Get the AKM suite */ - if (type == AKM_SUITE) { - DBGPRINT(RT_DEBUG_TRACE, ("%s : The count of AKM is %d\n", - __func__, acount)); - *count = acount; - return pAkm->auth[0].oui; - } - offset = sizeof(struct rt_rsnie_auth) + (4 * (acount - 1)); - - pBuf += offset; - len -= offset; - - /* The remaining length must larger than (RSN-Capability(2) + PMKID-Count(2) + PMKID(16~)) */ - if (len >= (sizeof(RSN_CAPABILITIES) + 2 + LEN_PMKID)) { - /* Skip RSN capability and PMKID-Count */ - pBuf += (sizeof(RSN_CAPABILITIES) + 2); - len -= (sizeof(RSN_CAPABILITIES) + 2); - - /* Get PMKID */ - if (type == PMKID_LIST) { - *count = 1; - return pBuf; - } - } else { - DBGPRINT_ERR("%s : it can't get any more information beyond AKM \n", __func__); - return NULL; - } - - *count = 0; - /*DBGPRINT_ERR(("%s : The type(%d) doesn't support \n", __func__, type)); */ - return NULL; - -} - -void WpaShowAllsuite(u8 *rsnie, u32 rsnie_len) -{ - u8 *pSuite = NULL; - u8 count; - - hex_dump("RSNIE", rsnie, rsnie_len); - - /* group cipher */ - pSuite = GetSuiteFromRSNIE(rsnie, rsnie_len, GROUP_SUITE, &count); - if (pSuite != NULL) { - hex_dump("group cipher", pSuite, 4 * count); - } - /* pairwise cipher */ - pSuite = GetSuiteFromRSNIE(rsnie, rsnie_len, PAIRWISE_SUITE, &count); - if (pSuite != NULL) { - hex_dump("pairwise cipher", pSuite, 4 * count); - } - /* AKM */ - pSuite = GetSuiteFromRSNIE(rsnie, rsnie_len, AKM_SUITE, &count); - if (pSuite != NULL) { - hex_dump("AKM suite", pSuite, 4 * count); - } - /* PMKID */ - pSuite = GetSuiteFromRSNIE(rsnie, rsnie_len, PMKID_LIST, &count); - if (pSuite != NULL) { - hex_dump("PMKID", pSuite, LEN_PMKID); - } - -} - -void RTMPInsertRSNIE(u8 *pFrameBuf, - unsigned long *pFrameLen, - u8 *rsnie_ptr, - u8 rsnie_len, - u8 *pmkid_ptr, u8 pmkid_len) -{ - u8 *pTmpBuf; - unsigned long TempLen = 0; - u8 extra_len = 0; - u16 pmk_count = 0; - u8 ie_num; - u8 total_len = 0; - u8 WPA2_OUI[3] = { 0x00, 0x0F, 0xAC }; - - pTmpBuf = pFrameBuf; - - /* PMKID-List Must larger than 0 and the multiple of 16. */ - if (pmkid_len > 0 && ((pmkid_len & 0x0f) == 0)) { - extra_len = sizeof(u16)+ pmkid_len; - - pmk_count = (pmkid_len >> 4); - pmk_count = cpu2le16(pmk_count); - } else { - DBGPRINT(RT_DEBUG_WARN, - ("%s : The length is PMKID-List is invalid (%d), so don't insert it.\n", - __func__, pmkid_len)); - } - - if (rsnie_len != 0) { - ie_num = IE_WPA; - total_len = rsnie_len; - - if (NdisEqualMemory(rsnie_ptr + 2, WPA2_OUI, sizeof(WPA2_OUI))) { - ie_num = IE_RSN; - total_len += extra_len; - } - - /* construct RSNIE body */ - MakeOutgoingFrame(pTmpBuf, &TempLen, - 1, &ie_num, - 1, &total_len, - rsnie_len, rsnie_ptr, END_OF_ARGS); - - pTmpBuf += TempLen; - *pFrameLen = *pFrameLen + TempLen; - - if (ie_num == IE_RSN) { - /* Insert PMKID-List field */ - if (extra_len > 0) { - MakeOutgoingFrame(pTmpBuf, &TempLen, - 2, &pmk_count, - pmkid_len, pmkid_ptr, - END_OF_ARGS); - - pTmpBuf += TempLen; - *pFrameLen = *pFrameLen + TempLen; - } - } - } - - return; -} diff --git a/trunk/drivers/staging/rt2860/common/crypt_hmac.c b/trunk/drivers/staging/rt2860/common/crypt_hmac.c deleted file mode 100644 index d7ab08ec1a41..000000000000 --- a/trunk/drivers/staging/rt2860/common/crypt_hmac.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - *************************************************************************/ - -#include "../crypt_hmac.h" - -#ifdef HMAC_SHA1_SUPPORT -/* -======================================================================== -Routine Description: - HMAC using SHA1 hash function - -Arguments: - key Secret key - key_len The length of the key in bytes - message Message context - message_len The length of message in bytes - macLen Request the length of message authentication code - -Return Value: - mac Message authentication code - -Note: - None -======================================================================== -*/ -void HMAC_SHA1(IN const u8 Key[], - u32 KeyLen, - IN const u8 Message[], - u32 MessageLen, u8 MAC[], u32 MACLen) -{ - struct rt_sha1_ctx sha_ctx1; - struct rt_sha1_ctx sha_ctx2; - u8 K0[SHA1_BLOCK_SIZE]; - u8 Digest[SHA1_DIGEST_SIZE]; - u32 index; - - NdisZeroMemory(&sha_ctx1, sizeof(struct rt_sha1_ctx)); - NdisZeroMemory(&sha_ctx2, sizeof(struct rt_sha1_ctx)); - /* - * If the length of K = B(Block size): K0 = K. - * If the length of K > B: hash K to obtain an L byte string, - * then append (B-L) zeros to create a B-byte string K0 (i.e., K0 = H(K) || 00...00). - * If the length of K < B: append zeros to the end of K to create a B-byte string K0 - */ - NdisZeroMemory(K0, SHA1_BLOCK_SIZE); - if (KeyLen <= SHA1_BLOCK_SIZE) - NdisMoveMemory(K0, Key, KeyLen); - else - RT_SHA1(Key, KeyLen, K0); - /* End of if */ - - /* Exclusive-Or K0 with ipad */ - /* ipad: Inner pad; the byte x¡¦36¡¦ repeated B times. */ - for (index = 0; index < SHA1_BLOCK_SIZE; index++) - K0[index] ^= 0x36; - /* End of for */ - - RT_SHA1_Init(&sha_ctx1); - /* H(K0^ipad) */ - SHA1_Append(&sha_ctx1, K0, sizeof(K0)); - /* H((K0^ipad)||text) */ - SHA1_Append(&sha_ctx1, Message, MessageLen); - SHA1_End(&sha_ctx1, Digest); - - /* Exclusive-Or K0 with opad and remove ipad */ - /* opad: Outer pad; the byte x¡¦5c¡¦ repeated B times. */ - for (index = 0; index < SHA1_BLOCK_SIZE; index++) - K0[index] ^= 0x36 ^ 0x5c; - /* End of for */ - - RT_SHA1_Init(&sha_ctx2); - /* H(K0^opad) */ - SHA1_Append(&sha_ctx2, K0, sizeof(K0)); - /* H( (K0^opad) || H((K0^ipad)||text) ) */ - SHA1_Append(&sha_ctx2, Digest, SHA1_DIGEST_SIZE); - SHA1_End(&sha_ctx2, Digest); - - if (MACLen > SHA1_DIGEST_SIZE) - NdisMoveMemory(MAC, Digest, SHA1_DIGEST_SIZE); - else - NdisMoveMemory(MAC, Digest, MACLen); -} /* End of HMAC_SHA1 */ -#endif /* HMAC_SHA1_SUPPORT */ - -#ifdef HMAC_MD5_SUPPORT -/* -======================================================================== -Routine Description: - HMAC using MD5 hash function - -Arguments: - key Secret key - key_len The length of the key in bytes - message Message context - message_len The length of message in bytes - macLen Request the length of message authentication code - -Return Value: - mac Message authentication code - -Note: - None -======================================================================== -*/ -void HMAC_MD5(IN const u8 Key[], - u32 KeyLen, - IN const u8 Message[], - u32 MessageLen, u8 MAC[], u32 MACLen) -{ - struct rt_md5_ctx_struc md5_ctx1; - struct rt_md5_ctx_struc md5_ctx2; - u8 K0[MD5_BLOCK_SIZE]; - u8 Digest[MD5_DIGEST_SIZE]; - u32 index; - - NdisZeroMemory(&md5_ctx1, sizeof(struct rt_md5_ctx_struc)); - NdisZeroMemory(&md5_ctx2, sizeof(struct rt_md5_ctx_struc)); - /* - * If the length of K = B(Block size): K0 = K. - * If the length of K > B: hash K to obtain an L byte string, - * then append (B-L) zeros to create a B-byte string K0 (i.e., K0 = H(K) || 00...00). - * If the length of K < B: append zeros to the end of K to create a B-byte string K0 - */ - NdisZeroMemory(K0, MD5_BLOCK_SIZE); - if (KeyLen <= MD5_BLOCK_SIZE) { - NdisMoveMemory(K0, Key, KeyLen); - } else { - RT_MD5(Key, KeyLen, K0); - } - - /* Exclusive-Or K0 with ipad */ - /* ipad: Inner pad; the byte x¡¦36¡¦ repeated B times. */ - for (index = 0; index < MD5_BLOCK_SIZE; index++) - K0[index] ^= 0x36; - /* End of for */ - - MD5_Init(&md5_ctx1); - /* H(K0^ipad) */ - MD5_Append(&md5_ctx1, K0, sizeof(K0)); - /* H((K0^ipad)||text) */ - MD5_Append(&md5_ctx1, Message, MessageLen); - MD5_End(&md5_ctx1, Digest); - - /* Exclusive-Or K0 with opad and remove ipad */ - /* opad: Outer pad; the byte x¡¦5c¡¦ repeated B times. */ - for (index = 0; index < MD5_BLOCK_SIZE; index++) - K0[index] ^= 0x36 ^ 0x5c; - /* End of for */ - - MD5_Init(&md5_ctx2); - /* H(K0^opad) */ - MD5_Append(&md5_ctx2, K0, sizeof(K0)); - /* H( (K0^opad) || H((K0^ipad)||text) ) */ - MD5_Append(&md5_ctx2, Digest, MD5_DIGEST_SIZE); - MD5_End(&md5_ctx2, Digest); - - if (MACLen > MD5_DIGEST_SIZE) - NdisMoveMemory(MAC, Digest, MD5_DIGEST_SIZE); - else - NdisMoveMemory(MAC, Digest, MACLen); -} /* End of HMAC_SHA256 */ -#endif /* HMAC_MD5_SUPPORT */ - -/* End of crypt_hmac.c */ diff --git a/trunk/drivers/staging/rt2860/common/crypt_md5.c b/trunk/drivers/staging/rt2860/common/crypt_md5.c deleted file mode 100644 index 6deab659c22b..000000000000 --- a/trunk/drivers/staging/rt2860/common/crypt_md5.c +++ /dev/null @@ -1,339 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - *************************************************************************/ - -#include "../crypt_md5.h" - -#ifdef MD5_SUPPORT -/* - * F, G, H and I are basic MD5 functions. - */ -#define F(x, y, z) (((x) & (y)) | ((~x) & (z))) -#define G(x, y, z) (((x) & (z)) | ((y) & (~z))) -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define I(x, y, z) ((y) ^ ((x) | (~z))) - -#define ROTL(x,n,w) ((x << n) | (x >> (w - n))) -#define ROTL32(x,n) ROTL(x,n,32) /* 32 bits word */ - -#define ROUND1(a, b, c, d, x, s, ac) { \ - (a) += F((b),(c),(d)) + (x) + (u32)(ac); \ - (a) = ROTL32((a),(s)); \ - (a) += (b); \ -} -#define ROUND2(a, b, c, d, x, s, ac) { \ - (a) += G((b),(c),(d)) + (x) + (u32)(ac); \ - (a) = ROTL32((a),(s)); \ - (a) += (b); \ -} -#define ROUND3(a, b, c, d, x, s, ac) { \ - (a) += H((b),(c),(d)) + (x) + (u32)(ac); \ - (a) = ROTL32((a),(s)); \ - (a) += (b); \ -} -#define ROUND4(a, b, c, d, x, s, ac) { \ - (a) += I((b),(c),(d)) + (x) + (u32)(ac); \ - (a) = ROTL32((a),(s)); \ - (a) += (b); \ -} -static const u32 MD5_DefaultHashValue[4] = { - 0x67452301UL, 0xefcdab89UL, 0x98badcfeUL, 0x10325476UL -}; -#endif /* MD5_SUPPORT */ - -#ifdef MD5_SUPPORT -/* -======================================================================== -Routine Description: - Initial Md5_CTX_STRUC - -Arguments: - pMD5_CTX Pointer to Md5_CTX_STRUC - -Return Value: - None - -Note: - None -======================================================================== -*/ -void MD5_Init(struct rt_md5_ctx_struc *pMD5_CTX) -{ - NdisMoveMemory(pMD5_CTX->HashValue, MD5_DefaultHashValue, - sizeof(MD5_DefaultHashValue)); - NdisZeroMemory(pMD5_CTX->Block, MD5_BLOCK_SIZE); - pMD5_CTX->BlockLen = 0; - pMD5_CTX->MessageLen = 0; -} /* End of MD5_Init */ - -/* -======================================================================== -Routine Description: - MD5 computation for one block (512 bits) - -Arguments: - pMD5_CTX Pointer to Md5_CTX_STRUC - -Return Value: - None - -Note: - T[i] := floor(abs(sin(i + 1)) * (2 pow 32)), i is number of round -======================================================================== -*/ -void MD5_Hash(struct rt_md5_ctx_struc *pMD5_CTX) -{ - u32 X_i; - u32 X[16]; - u32 a, b, c, d; - - /* Prepare the message schedule, {X_i} */ - NdisMoveMemory(X, pMD5_CTX->Block, MD5_BLOCK_SIZE); - for (X_i = 0; X_i < 16; X_i++) - X[X_i] = cpu2le32(X[X_i]); /* Endian Swap */ - /* End of for */ - - /* MD5 hash computation */ - /* Initialize the working variables */ - a = pMD5_CTX->HashValue[0]; - b = pMD5_CTX->HashValue[1]; - c = pMD5_CTX->HashValue[2]; - d = pMD5_CTX->HashValue[3]; - - /* - * Round 1 - * Let [abcd k s i] denote the operation - * a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s) - */ - ROUND1(a, b, c, d, X[0], 7, 0xd76aa478); /* 1 */ - ROUND1(d, a, b, c, X[1], 12, 0xe8c7b756); /* 2 */ - ROUND1(c, d, a, b, X[2], 17, 0x242070db); /* 3 */ - ROUND1(b, c, d, a, X[3], 22, 0xc1bdceee); /* 4 */ - ROUND1(a, b, c, d, X[4], 7, 0xf57c0faf); /* 5 */ - ROUND1(d, a, b, c, X[5], 12, 0x4787c62a); /* 6 */ - ROUND1(c, d, a, b, X[6], 17, 0xa8304613); /* 7 */ - ROUND1(b, c, d, a, X[7], 22, 0xfd469501); /* 8 */ - ROUND1(a, b, c, d, X[8], 7, 0x698098d8); /* 9 */ - ROUND1(d, a, b, c, X[9], 12, 0x8b44f7af); /* 10 */ - ROUND1(c, d, a, b, X[10], 17, 0xffff5bb1); /* 11 */ - ROUND1(b, c, d, a, X[11], 22, 0x895cd7be); /* 12 */ - ROUND1(a, b, c, d, X[12], 7, 0x6b901122); /* 13 */ - ROUND1(d, a, b, c, X[13], 12, 0xfd987193); /* 14 */ - ROUND1(c, d, a, b, X[14], 17, 0xa679438e); /* 15 */ - ROUND1(b, c, d, a, X[15], 22, 0x49b40821); /* 16 */ - - /* - * Round 2 - * Let [abcd k s i] denote the operation - * a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s) - */ - ROUND2(a, b, c, d, X[1], 5, 0xf61e2562); /* 17 */ - ROUND2(d, a, b, c, X[6], 9, 0xc040b340); /* 18 */ - ROUND2(c, d, a, b, X[11], 14, 0x265e5a51); /* 19 */ - ROUND2(b, c, d, a, X[0], 20, 0xe9b6c7aa); /* 20 */ - ROUND2(a, b, c, d, X[5], 5, 0xd62f105d); /* 21 */ - ROUND2(d, a, b, c, X[10], 9, 0x2441453); /* 22 */ - ROUND2(c, d, a, b, X[15], 14, 0xd8a1e681); /* 23 */ - ROUND2(b, c, d, a, X[4], 20, 0xe7d3fbc8); /* 24 */ - ROUND2(a, b, c, d, X[9], 5, 0x21e1cde6); /* 25 */ - ROUND2(d, a, b, c, X[14], 9, 0xc33707d6); /* 26 */ - ROUND2(c, d, a, b, X[3], 14, 0xf4d50d87); /* 27 */ - ROUND2(b, c, d, a, X[8], 20, 0x455a14ed); /* 28 */ - ROUND2(a, b, c, d, X[13], 5, 0xa9e3e905); /* 29 */ - ROUND2(d, a, b, c, X[2], 9, 0xfcefa3f8); /* 30 */ - ROUND2(c, d, a, b, X[7], 14, 0x676f02d9); /* 31 */ - ROUND2(b, c, d, a, X[12], 20, 0x8d2a4c8a); /* 32 */ - - /* - * Round 3 - * Let [abcd k s t] denote the operation - * a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s) - */ - ROUND3(a, b, c, d, X[5], 4, 0xfffa3942); /* 33 */ - ROUND3(d, a, b, c, X[8], 11, 0x8771f681); /* 34 */ - ROUND3(c, d, a, b, X[11], 16, 0x6d9d6122); /* 35 */ - ROUND3(b, c, d, a, X[14], 23, 0xfde5380c); /* 36 */ - ROUND3(a, b, c, d, X[1], 4, 0xa4beea44); /* 37 */ - ROUND3(d, a, b, c, X[4], 11, 0x4bdecfa9); /* 38 */ - ROUND3(c, d, a, b, X[7], 16, 0xf6bb4b60); /* 39 */ - ROUND3(b, c, d, a, X[10], 23, 0xbebfbc70); /* 40 */ - ROUND3(a, b, c, d, X[13], 4, 0x289b7ec6); /* 41 */ - ROUND3(d, a, b, c, X[0], 11, 0xeaa127fa); /* 42 */ - ROUND3(c, d, a, b, X[3], 16, 0xd4ef3085); /* 43 */ - ROUND3(b, c, d, a, X[6], 23, 0x4881d05); /* 44 */ - ROUND3(a, b, c, d, X[9], 4, 0xd9d4d039); /* 45 */ - ROUND3(d, a, b, c, X[12], 11, 0xe6db99e5); /* 46 */ - ROUND3(c, d, a, b, X[15], 16, 0x1fa27cf8); /* 47 */ - ROUND3(b, c, d, a, X[2], 23, 0xc4ac5665); /* 48 */ - - /* - * Round 4 - * Let [abcd k s t] denote the operation - * a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s) - */ - ROUND4(a, b, c, d, X[0], 6, 0xf4292244); /* 49 */ - ROUND4(d, a, b, c, X[7], 10, 0x432aff97); /* 50 */ - ROUND4(c, d, a, b, X[14], 15, 0xab9423a7); /* 51 */ - ROUND4(b, c, d, a, X[5], 21, 0xfc93a039); /* 52 */ - ROUND4(a, b, c, d, X[12], 6, 0x655b59c3); /* 53 */ - ROUND4(d, a, b, c, X[3], 10, 0x8f0ccc92); /* 54 */ - ROUND4(c, d, a, b, X[10], 15, 0xffeff47d); /* 55 */ - ROUND4(b, c, d, a, X[1], 21, 0x85845dd1); /* 56 */ - ROUND4(a, b, c, d, X[8], 6, 0x6fa87e4f); /* 57 */ - ROUND4(d, a, b, c, X[15], 10, 0xfe2ce6e0); /* 58 */ - ROUND4(c, d, a, b, X[6], 15, 0xa3014314); /* 59 */ - ROUND4(b, c, d, a, X[13], 21, 0x4e0811a1); /* 60 */ - ROUND4(a, b, c, d, X[4], 6, 0xf7537e82); /* 61 */ - ROUND4(d, a, b, c, X[11], 10, 0xbd3af235); /* 62 */ - ROUND4(c, d, a, b, X[2], 15, 0x2ad7d2bb); /* 63 */ - ROUND4(b, c, d, a, X[9], 21, 0xeb86d391); /* 64 */ - - /* Compute the i^th intermediate hash value H^(i) */ - pMD5_CTX->HashValue[0] += a; - pMD5_CTX->HashValue[1] += b; - pMD5_CTX->HashValue[2] += c; - pMD5_CTX->HashValue[3] += d; - - NdisZeroMemory(pMD5_CTX->Block, MD5_BLOCK_SIZE); - pMD5_CTX->BlockLen = 0; -} /* End of MD5_Hash */ - -/* -======================================================================== -Routine Description: - The message is appended to block. If block size > 64 bytes, the MD5_Hash -will be called. - -Arguments: - pMD5_CTX Pointer to struct rt_md5_ctx_struc - message Message context - messageLen The length of message in bytes - -Return Value: - None - -Note: - None -======================================================================== -*/ -void MD5_Append(struct rt_md5_ctx_struc *pMD5_CTX, - IN const u8 Message[], u32 MessageLen) -{ - u32 appendLen = 0; - u32 diffLen = 0; - - while (appendLen != MessageLen) { - diffLen = MessageLen - appendLen; - if ((pMD5_CTX->BlockLen + diffLen) < MD5_BLOCK_SIZE) { - NdisMoveMemory(pMD5_CTX->Block + pMD5_CTX->BlockLen, - Message + appendLen, diffLen); - pMD5_CTX->BlockLen += diffLen; - appendLen += diffLen; - } else { - NdisMoveMemory(pMD5_CTX->Block + pMD5_CTX->BlockLen, - Message + appendLen, - MD5_BLOCK_SIZE - pMD5_CTX->BlockLen); - appendLen += (MD5_BLOCK_SIZE - pMD5_CTX->BlockLen); - pMD5_CTX->BlockLen = MD5_BLOCK_SIZE; - MD5_Hash(pMD5_CTX); - } /* End of if */ - } /* End of while */ - pMD5_CTX->MessageLen += MessageLen; -} /* End of MD5_Append */ - -/* -======================================================================== -Routine Description: - 1. Append bit 1 to end of the message - 2. Append the length of message in rightmost 64 bits - 3. Transform the Hash Value to digest message - -Arguments: - pMD5_CTX Pointer to struct rt_md5_ctx_struc - -Return Value: - digestMessage Digest message - -Note: - None -======================================================================== -*/ -void MD5_End(struct rt_md5_ctx_struc *pMD5_CTX, u8 DigestMessage[]) -{ - u32 index; - u64 message_length_bits; - - /* append 1 bits to end of the message */ - NdisFillMemory(pMD5_CTX->Block + pMD5_CTX->BlockLen, 1, 0x80); - - /* 55 = 64 - 8 - 1: append 1 bit(1 byte) and message length (8 bytes) */ - if (pMD5_CTX->BlockLen > 55) - MD5_Hash(pMD5_CTX); - /* End of if */ - - /* Append the length of message in rightmost 64 bits */ - message_length_bits = pMD5_CTX->MessageLen * 8; - message_length_bits = cpu2le64(message_length_bits); - NdisMoveMemory(&pMD5_CTX->Block[56], &message_length_bits, 8); - MD5_Hash(pMD5_CTX); - - /* Return message digest, transform the u32 hash value to bytes */ - for (index = 0; index < 4; index++) - pMD5_CTX->HashValue[index] = - cpu2le32(pMD5_CTX->HashValue[index]); - /* End of for */ - NdisMoveMemory(DigestMessage, pMD5_CTX->HashValue, MD5_DIGEST_SIZE); -} /* End of MD5_End */ - -/* -======================================================================== -Routine Description: - MD5 algorithm - -Arguments: - message Message context - messageLen The length of message in bytes - -Return Value: - digestMessage Digest message - -Note: - None -======================================================================== -*/ -void RT_MD5(IN const u8 Message[], - u32 MessageLen, u8 DigestMessage[]) -{ - struct rt_md5_ctx_struc md5_ctx; - - NdisZeroMemory(&md5_ctx, sizeof(struct rt_md5_ctx_struc)); - MD5_Init(&md5_ctx); - MD5_Append(&md5_ctx, Message, MessageLen); - MD5_End(&md5_ctx, DigestMessage); -} /* End of RT_MD5 */ - -#endif /* MD5_SUPPORT */ - -/* End of crypt_md5.c */ diff --git a/trunk/drivers/staging/rt2860/common/crypt_sha2.c b/trunk/drivers/staging/rt2860/common/crypt_sha2.c deleted file mode 100644 index fa83fb287fe5..000000000000 --- a/trunk/drivers/staging/rt2860/common/crypt_sha2.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - *************************************************************************/ - -#include "../crypt_sha2.h" - -/* Basic operations */ -#define SHR(x,n) (x >> n) /* SHR(x)^n, right shift n bits , x is w-bit word, 0 <= n <= w */ -#define ROTR(x,n,w) ((x >> n) | (x << (w - n))) /* ROTR(x)^n, circular right shift n bits , x is w-bit word, 0 <= n <= w */ -#define ROTL(x,n,w) ((x << n) | (x >> (w - n))) /* ROTL(x)^n, circular left shift n bits , x is w-bit word, 0 <= n <= w */ -#define ROTR32(x,n) ROTR(x,n,32) /* 32 bits word */ -#define ROTL32(x,n) ROTL(x,n,32) /* 32 bits word */ - -/* Basic functions */ -#define Ch(x,y,z) ((x & y) ^ ((~x) & z)) -#define Maj(x,y,z) ((x & y) ^ (x & z) ^ (y & z)) -#define Parity(x,y,z) (x ^ y ^ z) - -#ifdef SHA1_SUPPORT -/* SHA1 constants */ -#define SHA1_MASK 0x0000000f -static const u32 SHA1_K[4] = { - 0x5a827999UL, 0x6ed9eba1UL, 0x8f1bbcdcUL, 0xca62c1d6UL -}; - -static const u32 SHA1_DefaultHashValue[5] = { - 0x67452301UL, 0xefcdab89UL, 0x98badcfeUL, 0x10325476UL, 0xc3d2e1f0UL -}; - -/* -======================================================================== -Routine Description: - Initial struct rt_sha1_ctx - -Arguments: - pSHA_CTX Pointer to struct rt_sha1_ctx - -Return Value: - None - -Note: - None -======================================================================== -*/ -void RT_SHA1_Init(struct rt_sha1_ctx *pSHA_CTX) -{ - NdisMoveMemory(pSHA_CTX->HashValue, SHA1_DefaultHashValue, - sizeof(SHA1_DefaultHashValue)); - NdisZeroMemory(pSHA_CTX->Block, SHA1_BLOCK_SIZE); - pSHA_CTX->MessageLen = 0; - pSHA_CTX->BlockLen = 0; -} /* End of RT_SHA1_Init */ - -/* -======================================================================== -Routine Description: - SHA1 computation for one block (512 bits) - -Arguments: - pSHA_CTX Pointer to struct rt_sha1_ctx - -Return Value: - None - -Note: - None -======================================================================== -*/ -void SHA1_Hash(struct rt_sha1_ctx *pSHA_CTX) -{ - u32 W_i, t, s; - u32 W[16]; - u32 a, b, c, d, e, T, f_t = 0; - - /* Prepare the message schedule, {W_i}, 0 < t < 15 */ - NdisMoveMemory(W, pSHA_CTX->Block, SHA1_BLOCK_SIZE); - for (W_i = 0; W_i < 16; W_i++) - W[W_i] = cpu2be32(W[W_i]); /* Endian Swap */ - /* End of for */ - - /* SHA256 hash computation */ - /* Initialize the working variables */ - a = pSHA_CTX->HashValue[0]; - b = pSHA_CTX->HashValue[1]; - c = pSHA_CTX->HashValue[2]; - d = pSHA_CTX->HashValue[3]; - e = pSHA_CTX->HashValue[4]; - - /* 80 rounds */ - for (t = 0; t < 80; t++) { - s = t & SHA1_MASK; - if (t > 15) { /* Prepare the message schedule, {W_i}, 16 < t < 79 */ - W[s] = - (W[(s + 13) & SHA1_MASK]) ^ (W[(s + 8) & SHA1_MASK]) - ^ (W[(s + 2) & SHA1_MASK]) ^ W[s]; - W[s] = ROTL32(W[s], 1); - } /* End of if */ - switch (t / 20) { - case 0: - f_t = Ch(b, c, d); - break; - case 1: - f_t = Parity(b, c, d); - break; - case 2: - f_t = Maj(b, c, d); - break; - case 3: - f_t = Parity(b, c, d); - break; - } /* End of switch */ - T = ROTL32(a, 5) + f_t + e + SHA1_K[t / 20] + W[s]; - e = d; - d = c; - c = ROTL32(b, 30); - b = a; - a = T; - } /* End of for */ - - /* Compute the i^th intermediate hash value H^(i) */ - pSHA_CTX->HashValue[0] += a; - pSHA_CTX->HashValue[1] += b; - pSHA_CTX->HashValue[2] += c; - pSHA_CTX->HashValue[3] += d; - pSHA_CTX->HashValue[4] += e; - - NdisZeroMemory(pSHA_CTX->Block, SHA1_BLOCK_SIZE); - pSHA_CTX->BlockLen = 0; -} /* End of SHA1_Hash */ - -/* -======================================================================== -Routine Description: - The message is appended to block. If block size > 64 bytes, the SHA1_Hash -will be called. - -Arguments: - pSHA_CTX Pointer to struct rt_sha1_ctx - message Message context - messageLen The length of message in bytes - -Return Value: - None - -Note: - None -======================================================================== -*/ -void SHA1_Append(struct rt_sha1_ctx *pSHA_CTX, - IN const u8 Message[], u32 MessageLen) -{ - u32 appendLen = 0; - u32 diffLen = 0; - - while (appendLen != MessageLen) { - diffLen = MessageLen - appendLen; - if ((pSHA_CTX->BlockLen + diffLen) < SHA1_BLOCK_SIZE) { - NdisMoveMemory(pSHA_CTX->Block + pSHA_CTX->BlockLen, - Message + appendLen, diffLen); - pSHA_CTX->BlockLen += diffLen; - appendLen += diffLen; - } else { - NdisMoveMemory(pSHA_CTX->Block + pSHA_CTX->BlockLen, - Message + appendLen, - SHA1_BLOCK_SIZE - pSHA_CTX->BlockLen); - appendLen += (SHA1_BLOCK_SIZE - pSHA_CTX->BlockLen); - pSHA_CTX->BlockLen = SHA1_BLOCK_SIZE; - SHA1_Hash(pSHA_CTX); - } /* End of if */ - } /* End of while */ - pSHA_CTX->MessageLen += MessageLen; -} /* End of SHA1_Append */ - -/* -======================================================================== -Routine Description: - 1. Append bit 1 to end of the message - 2. Append the length of message in rightmost 64 bits - 3. Transform the Hash Value to digest message - -Arguments: - pSHA_CTX Pointer to struct rt_sha1_ctx - -Return Value: - digestMessage Digest message - -Note: - None -======================================================================== -*/ -void SHA1_End(struct rt_sha1_ctx *pSHA_CTX, u8 DigestMessage[]) -{ - u32 index; - u64 message_length_bits; - - /* Append bit 1 to end of the message */ - NdisFillMemory(pSHA_CTX->Block + pSHA_CTX->BlockLen, 1, 0x80); - - /* 55 = 64 - 8 - 1: append 1 bit(1 byte) and message length (8 bytes) */ - if (pSHA_CTX->BlockLen > 55) - SHA1_Hash(pSHA_CTX); - /* End of if */ - - /* Append the length of message in rightmost 64 bits */ - message_length_bits = pSHA_CTX->MessageLen * 8; - message_length_bits = cpu2be64(message_length_bits); - NdisMoveMemory(&pSHA_CTX->Block[56], &message_length_bits, 8); - SHA1_Hash(pSHA_CTX); - - /* Return message digest, transform the u32 hash value to bytes */ - for (index = 0; index < 5; index++) - pSHA_CTX->HashValue[index] = - cpu2be32(pSHA_CTX->HashValue[index]); - /* End of for */ - NdisMoveMemory(DigestMessage, pSHA_CTX->HashValue, SHA1_DIGEST_SIZE); -} /* End of SHA1_End */ - -/* -======================================================================== -Routine Description: - SHA1 algorithm - -Arguments: - message Message context - messageLen The length of message in bytes - -Return Value: - digestMessage Digest message - -Note: - None -======================================================================== -*/ -void RT_SHA1(IN const u8 Message[], - u32 MessageLen, u8 DigestMessage[]) -{ - - struct rt_sha1_ctx sha_ctx; - - NdisZeroMemory(&sha_ctx, sizeof(struct rt_sha1_ctx)); - RT_SHA1_Init(&sha_ctx); - SHA1_Append(&sha_ctx, Message, MessageLen); - SHA1_End(&sha_ctx, DigestMessage); -} /* End of RT_SHA1 */ -#endif /* SHA1_SUPPORT */ - -/* End of crypt_sha2.c */ diff --git a/trunk/drivers/staging/rt2860/common/dfs.c b/trunk/drivers/staging/rt2860/common/dfs.c deleted file mode 100644 index 71cbb2665243..000000000000 --- a/trunk/drivers/staging/rt2860/common/dfs.c +++ /dev/null @@ -1,68 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - ap_dfs.c - - Abstract: - Support DFS function. - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ - -#include "../rt_config.h" - -/* - ======================================================================== - - Routine Description: - Radar channel check routine - - Arguments: - pAd Pointer to our adapter - - Return Value: - TRUE need to do radar detect - FALSE need not to do radar detect - - ======================================================================== -*/ -BOOLEAN RadarChannelCheck(struct rt_rtmp_adapter *pAd, u8 Ch) -{ - int i; - BOOLEAN result = FALSE; - - for (i = 0; i < pAd->ChannelListNum; i++) { - if (Ch == pAd->ChannelList[i].Channel) { - result = pAd->ChannelList[i].DfsReq; - break; - } - } - - return result; -} diff --git a/trunk/drivers/staging/rt2860/common/ee_efuse.c b/trunk/drivers/staging/rt2860/common/ee_efuse.c deleted file mode 100644 index fed0ba452271..000000000000 --- a/trunk/drivers/staging/rt2860/common/ee_efuse.c +++ /dev/null @@ -1,351 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - ee_efuse.c - - Abstract: - Miniport generic portion header file - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ - -#include "../rt_config.h" - -#define EFUSE_USAGE_MAP_START 0x2d0 -#define EFUSE_USAGE_MAP_END 0x2fc -#define EFUSE_USAGE_MAP_SIZE 45 - -#define EFUSE_EEPROM_DEFULT_FILE "RT30xxEEPROM.bin" -#define MAX_EEPROM_BIN_FILE_SIZE 1024 - -#define EFUSE_TAG 0x2fe - -typedef union _EFUSE_CTRL_STRUC { - struct { - u32 EFSROM_AOUT:6; - u32 EFSROM_MODE:2; - u32 EFSROM_LDO_OFF_TIME:6; - u32 EFSROM_LDO_ON_TIME:2; - u32 EFSROM_AIN:10; - u32 RESERVED:4; - u32 EFSROM_KICK:1; - u32 SEL_EFUSE:1; - } field; - u32 word; -} EFUSE_CTRL_STRUC, *PEFUSE_CTRL_STRUC; - -/* -======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: - -======================================================================== -*/ -u8 eFuseReadRegisters(struct rt_rtmp_adapter *pAd, - u16 Offset, u16 Length, u16 * pData) -{ - EFUSE_CTRL_STRUC eFuseCtrlStruc; - int i; - u16 efuseDataOffset; - u32 data; - - RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word); - - /*Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment. */ - /*Use the eeprom logical address and covert to address to block number */ - eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0; - - /*Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 0. */ - eFuseCtrlStruc.field.EFSROM_MODE = 0; - - /*Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure. */ - eFuseCtrlStruc.field.EFSROM_KICK = 1; - - NdisMoveMemory(&data, &eFuseCtrlStruc, 4); - RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data); - - /*Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. */ - i = 0; - while (i < 500) { - /*rtmp.HwMemoryReadDword(EFUSE_CTRL, (DWORD *) &eFuseCtrlStruc, 4); */ - RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word); - if (eFuseCtrlStruc.field.EFSROM_KICK == 0) { - break; - } - RTMPusecDelay(2); - i++; - } - - /*if EFSROM_AOUT is not found in physical address, write 0xffff */ - if (eFuseCtrlStruc.field.EFSROM_AOUT == 0x3f) { - for (i = 0; i < Length / 2; i++) - *(pData + 2 * i) = 0xffff; - } else { - /*Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x590-0x59C) */ - efuseDataOffset = EFUSE_DATA3 - (Offset & 0xC); - /*data hold 4 bytes data. */ - /*In RTMP_IO_READ32 will automatically execute 32-bytes swapping */ - RTMP_IO_READ32(pAd, efuseDataOffset, &data); - /*Decide the upper 2 bytes or the bottom 2 bytes. */ - /* Little-endian S | S Big-endian */ - /* addr 3 2 1 0 | 0 1 2 3 */ - /* Ori-V D C B A | A B C D */ - /*After swapping */ - /* D C B A | D C B A */ - /*Return 2-bytes */ - /*The return byte statrs from S. Therefore, the little-endian will return BA, the Big-endian will return DC. */ - /*For returning the bottom 2 bytes, the Big-endian should shift right 2-bytes. */ - data = data >> (8 * (Offset & 0x3)); - - NdisMoveMemory(pData, &data, Length); - } - - return (u8)eFuseCtrlStruc.field.EFSROM_AOUT; - -} - -/* -======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: - -======================================================================== -*/ -void eFusePhysicalReadRegisters(struct rt_rtmp_adapter *pAd, - u16 Offset, - u16 Length, u16 * pData) -{ - EFUSE_CTRL_STRUC eFuseCtrlStruc; - int i; - u16 efuseDataOffset; - u32 data; - - RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word); - - /*Step0. Write 10-bit of address to EFSROM_AIN (0x580, bit25:bit16). The address must be 16-byte alignment. */ - eFuseCtrlStruc.field.EFSROM_AIN = Offset & 0xfff0; - - /*Step1. Write EFSROM_MODE (0x580, bit7:bit6) to 1. */ - /*Read in physical view */ - eFuseCtrlStruc.field.EFSROM_MODE = 1; - - /*Step2. Write EFSROM_KICK (0x580, bit30) to 1 to kick-off physical read procedure. */ - eFuseCtrlStruc.field.EFSROM_KICK = 1; - - NdisMoveMemory(&data, &eFuseCtrlStruc, 4); - RTMP_IO_WRITE32(pAd, EFUSE_CTRL, data); - - /*Step3. Polling EFSROM_KICK(0x580, bit30) until it become 0 again. */ - i = 0; - while (i < 500) { - RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrlStruc.word); - if (eFuseCtrlStruc.field.EFSROM_KICK == 0) - break; - RTMPusecDelay(2); - i++; - } - - /*Step4. Read 16-byte of data from EFUSE_DATA0-3 (0x59C-0x590) */ - /*Because the size of each EFUSE_DATA is 4 Bytes, the size of address of each is 2 bits. */ - /*The previous 2 bits is the EFUSE_DATA number, the last 2 bits is used to decide which bytes */ - /*Decide which EFUSE_DATA to read */ - /*590:F E D C */ - /*594:B A 9 8 */ - /*598:7 6 5 4 */ - /*59C:3 2 1 0 */ - efuseDataOffset = EFUSE_DATA3 - (Offset & 0xC); - - RTMP_IO_READ32(pAd, efuseDataOffset, &data); - - data = data >> (8 * (Offset & 0x3)); - - NdisMoveMemory(pData, &data, Length); - -} - -/* -======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: - -======================================================================== -*/ -static void eFuseReadPhysical(struct rt_rtmp_adapter *pAd, - u16 *lpInBuffer, - unsigned long nInBufferSize, - u16 *lpOutBuffer, unsigned long nOutBufferSize) -{ - u16 *pInBuf = (u16 *) lpInBuffer; - u16 *pOutBuf = (u16 *) lpOutBuffer; - - u16 Offset = pInBuf[0]; /*addr */ - u16 Length = pInBuf[1]; /*length */ - int i; - - for (i = 0; i < Length; i += 2) { - eFusePhysicalReadRegisters(pAd, Offset + i, 2, &pOutBuf[i / 2]); - } -} - -/* -======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: - -======================================================================== -*/ -int set_eFuseGetFreeBlockCount_Proc(struct rt_rtmp_adapter *pAd, char *arg) -{ - u16 i; - u16 LogicalAddress; - u16 efusefreenum = 0; - if (!pAd->bUseEfuse) - return FALSE; - for (i = EFUSE_USAGE_MAP_START; i <= EFUSE_USAGE_MAP_END; i += 2) { - eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress); - if ((LogicalAddress & 0xff) == 0) { - efusefreenum = (u8)(EFUSE_USAGE_MAP_END - i + 1); - break; - } else if (((LogicalAddress >> 8) & 0xff) == 0) { - efusefreenum = (u8)(EFUSE_USAGE_MAP_END - i); - break; - } - - if (i == EFUSE_USAGE_MAP_END) - efusefreenum = 0; - } - printk(KERN_DEBUG "efuseFreeNumber is %d\n", efusefreenum); - return TRUE; -} - -int set_eFusedump_Proc(struct rt_rtmp_adapter *pAd, char *arg) -{ - u16 InBuf[3]; - int i = 0; - if (!pAd->bUseEfuse) - return FALSE; - - printk(KERN_DEBUG "Block 0: "); - - for (i = 0; i < EFUSE_USAGE_MAP_END / 2; i++) { - InBuf[0] = 2 * i; - InBuf[1] = 2; - InBuf[2] = 0x0; - - eFuseReadPhysical(pAd, &InBuf[0], 4, &InBuf[2], 2); - if (i && i % 4 == 0) { - printk(KERN_CONT "\n"); - printk(KERN_DEBUG "Block %x:", i / 8); - } - printk(KERN_CONT "%04x ", InBuf[2]); - } - printk(KERN_CONT "\n"); - - return TRUE; -} - -int rtmp_ee_efuse_read16(struct rt_rtmp_adapter *pAd, - u16 Offset, u16 * pValue) -{ - eFuseReadRegisters(pAd, Offset, 2, pValue); - return (*pValue); -} - -int RtmpEfuseSupportCheck(struct rt_rtmp_adapter *pAd) -{ - u16 value; - - if (IS_RT30xx(pAd)) { - eFusePhysicalReadRegisters(pAd, EFUSE_TAG, 2, &value); - pAd->EFuseTag = (value & 0xff); - } - return 0; -} - -void eFuseGetFreeBlockCount(struct rt_rtmp_adapter *pAd, u32 *EfuseFreeBlock) -{ - u16 i; - u16 LogicalAddress; - if (!pAd->bUseEfuse) { - DBGPRINT(RT_DEBUG_TRACE, - ("eFuseGetFreeBlockCount Only supports efuse Mode\n")); - return; - } - for (i = EFUSE_USAGE_MAP_START; i <= EFUSE_USAGE_MAP_END; i += 2) { - eFusePhysicalReadRegisters(pAd, i, 2, &LogicalAddress); - if ((LogicalAddress & 0xff) == 0) { - *EfuseFreeBlock = (u8)(EFUSE_USAGE_MAP_END - i + 1); - break; - } else if (((LogicalAddress >> 8) & 0xff) == 0) { - *EfuseFreeBlock = (u8)(EFUSE_USAGE_MAP_END - i); - break; - } - - if (i == EFUSE_USAGE_MAP_END) - *EfuseFreeBlock = 0; - } - DBGPRINT(RT_DEBUG_TRACE, - ("eFuseGetFreeBlockCount is 0x%x\n", *EfuseFreeBlock)); -} - -int eFuse_init(struct rt_rtmp_adapter *pAd) -{ - u32 EfuseFreeBlock = 0; - DBGPRINT(RT_DEBUG_ERROR, - ("NVM is Efuse and its size =%x[%x-%x] \n", - EFUSE_USAGE_MAP_SIZE, EFUSE_USAGE_MAP_START, - EFUSE_USAGE_MAP_END)); - eFuseGetFreeBlockCount(pAd, &EfuseFreeBlock); - - return 0; -} diff --git a/trunk/drivers/staging/rt2860/common/ee_prom.c b/trunk/drivers/staging/rt2860/common/ee_prom.c deleted file mode 100644 index 2083740a844b..000000000000 --- a/trunk/drivers/staging/rt2860/common/ee_prom.c +++ /dev/null @@ -1,197 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - ee_prom.c - - Abstract: - Miniport generic portion header file - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ - -#include "../rt_config.h" - -/* IRQL = PASSIVE_LEVEL */ -static inline void RaiseClock(struct rt_rtmp_adapter *pAd, u32 * x) -{ - *x = *x | EESK; - RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x); - RTMPusecDelay(1); /* Max frequency = 1MHz in Spec. definition */ -} - -/* IRQL = PASSIVE_LEVEL */ -static inline void LowerClock(struct rt_rtmp_adapter *pAd, u32 * x) -{ - *x = *x & ~EESK; - RTMP_IO_WRITE32(pAd, E2PROM_CSR, *x); - RTMPusecDelay(1); -} - -/* IRQL = PASSIVE_LEVEL */ -static inline u16 ShiftInBits(struct rt_rtmp_adapter *pAd) -{ - u32 x, i; - u16 data = 0; - - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); - - x &= ~(EEDO | EEDI); - - for (i = 0; i < 16; i++) { - data = data << 1; - RaiseClock(pAd, &x); - - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); - LowerClock(pAd, &x); /*prevent read failed */ - - x &= ~(EEDI); - if (x & EEDO) - data |= 1; - } - - return data; -} - -/* IRQL = PASSIVE_LEVEL */ -static inline void ShiftOutBits(struct rt_rtmp_adapter *pAd, - u16 data, u16 count) -{ - u32 x, mask; - - mask = 0x01 << (count - 1); - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); - - x &= ~(EEDO | EEDI); - - do { - x &= ~EEDI; - if (data & mask) - x |= EEDI; - - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); - - RaiseClock(pAd, &x); - LowerClock(pAd, &x); - - mask = mask >> 1; - } while (mask); - - x &= ~EEDI; - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); -} - -/* IRQL = PASSIVE_LEVEL */ -static inline void EEpromCleanup(struct rt_rtmp_adapter *pAd) -{ - u32 x; - - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); - - x &= ~(EECS | EEDI); - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); - - RaiseClock(pAd, &x); - LowerClock(pAd, &x); -} - -static inline void EWEN(struct rt_rtmp_adapter *pAd) -{ - u32 x; - - /* reset bits and set EECS */ - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); - x &= ~(EEDI | EEDO | EESK); - x |= EECS; - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); - - /* kick a pulse */ - RaiseClock(pAd, &x); - LowerClock(pAd, &x); - - /* output the read_opcode and six pulse in that order */ - ShiftOutBits(pAd, EEPROM_EWEN_OPCODE, 5); - ShiftOutBits(pAd, 0, 6); - - EEpromCleanup(pAd); -} - -static inline void EWDS(struct rt_rtmp_adapter *pAd) -{ - u32 x; - - /* reset bits and set EECS */ - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); - x &= ~(EEDI | EEDO | EESK); - x |= EECS; - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); - - /* kick a pulse */ - RaiseClock(pAd, &x); - LowerClock(pAd, &x); - - /* output the read_opcode and six pulse in that order */ - ShiftOutBits(pAd, EEPROM_EWDS_OPCODE, 5); - ShiftOutBits(pAd, 0, 6); - - EEpromCleanup(pAd); -} - -/* IRQL = PASSIVE_LEVEL */ -int rtmp_ee_prom_read16(struct rt_rtmp_adapter *pAd, - u16 Offset, u16 * pValue) -{ - u32 x; - u16 data; - - Offset /= 2; - /* reset bits and set EECS */ - RTMP_IO_READ32(pAd, E2PROM_CSR, &x); - x &= ~(EEDI | EEDO | EESK); - x |= EECS; - RTMP_IO_WRITE32(pAd, E2PROM_CSR, x); - - /* patch can not access e-Fuse issue */ - if (!(IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))) { - /* kick a pulse */ - RaiseClock(pAd, &x); - LowerClock(pAd, &x); - } - /* output the read_opcode and register number in that order */ - ShiftOutBits(pAd, EEPROM_READ_OPCODE, 3); - ShiftOutBits(pAd, Offset, pAd->EEPROMAddressNum); - - /* Now read the data (16 bits) in from the selected EEPROM word */ - data = ShiftInBits(pAd); - - EEpromCleanup(pAd); - - *pValue = data; - - return NDIS_STATUS_SUCCESS; -} diff --git a/trunk/drivers/staging/rt2860/common/eeprom.c b/trunk/drivers/staging/rt2860/common/eeprom.c deleted file mode 100644 index 94670076d32b..000000000000 --- a/trunk/drivers/staging/rt2860/common/eeprom.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - eeprom.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs -*/ -#include "../rt_config.h" - -int RtmpChipOpsEepromHook(struct rt_rtmp_adapter *pAd, int infType) -{ - struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps; -#ifdef RT30xx -#ifdef RTMP_EFUSE_SUPPORT - u32 eFuseCtrl, MacCsr0; - int index; - - index = 0; - do { - RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0); - pAd->MACVersion = MacCsr0; - - if ((pAd->MACVersion != 0x00) - && (pAd->MACVersion != 0xFFFFFFFF)) - break; - - RTMPusecDelay(10); - } while (index++ < 100); - - pAd->bUseEfuse = FALSE; - RTMP_IO_READ32(pAd, EFUSE_CTRL, &eFuseCtrl); - pAd->bUseEfuse = ((eFuseCtrl & 0x80000000) == 0x80000000) ? 1 : 0; - if (pAd->bUseEfuse) { - pChipOps->eeinit = eFuse_init; - pChipOps->eeread = rtmp_ee_efuse_read16; - return 0; - } else - DBGPRINT(RT_DEBUG_TRACE, ("NVM is EEPROM\n")); -#endif /* RTMP_EFUSE_SUPPORT // */ -#endif /* RT30xx // */ - - switch (infType) { -#ifdef RTMP_PCI_SUPPORT - case RTMP_DEV_INF_PCI: - pChipOps->eeinit = NULL; - pChipOps->eeread = rtmp_ee_prom_read16; - break; -#endif /* RTMP_PCI_SUPPORT // */ -#ifdef RTMP_USB_SUPPORT - case RTMP_DEV_INF_USB: - pChipOps->eeinit = NULL; - pChipOps->eeread = RTUSBReadEEPROM16; - break; -#endif /* RTMP_USB_SUPPORT // */ - - default: - DBGPRINT(RT_DEBUG_ERROR, ("RtmpChipOpsEepromHook() failed!\n")); - break; - } - - return 0; -} diff --git a/trunk/drivers/staging/rt2860/common/mlme.c b/trunk/drivers/staging/rt2860/common/mlme.c deleted file mode 100644 index e48eac0f3a29..000000000000 --- a/trunk/drivers/staging/rt2860/common/mlme.c +++ /dev/null @@ -1,6068 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - mlme.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - John Chang 2004-08-25 Modify from RT2500 code base - John Chang 2004-09-06 modified for RT2600 -*/ - -#include "../rt_config.h" -#include -#include - -u8 CISCO_OUI[] = { 0x00, 0x40, 0x96 }; - -u8 WPA_OUI[] = { 0x00, 0x50, 0xf2, 0x01 }; -u8 RSN_OUI[] = { 0x00, 0x0f, 0xac }; -u8 WME_INFO_ELEM[] = { 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01 }; -u8 WME_PARM_ELEM[] = { 0x00, 0x50, 0xf2, 0x02, 0x01, 0x01 }; -u8 Ccx2QosInfo[] = { 0x00, 0x40, 0x96, 0x04 }; -u8 RALINK_OUI[] = { 0x00, 0x0c, 0x43 }; -u8 BROADCOM_OUI[] = { 0x00, 0x90, 0x4c }; -u8 WPS_OUI[] = { 0x00, 0x50, 0xf2, 0x04 }; -u8 PRE_N_HT_OUI[] = { 0x00, 0x90, 0x4c }; - -u8 RateSwitchTable[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x11, 0x00, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x00, 0, 40, 101, - 0x01, 0x00, 1, 40, 50, - 0x02, 0x00, 2, 35, 45, - 0x03, 0x00, 3, 20, 45, - 0x04, 0x21, 0, 30, 50, - 0x05, 0x21, 1, 20, 50, - 0x06, 0x21, 2, 20, 50, - 0x07, 0x21, 3, 15, 50, - 0x08, 0x21, 4, 15, 30, - 0x09, 0x21, 5, 10, 25, - 0x0a, 0x21, 6, 8, 25, - 0x0b, 0x21, 7, 8, 25, - 0x0c, 0x20, 12, 15, 30, - 0x0d, 0x20, 13, 8, 20, - 0x0e, 0x20, 14, 8, 20, - 0x0f, 0x20, 15, 8, 25, - 0x10, 0x22, 15, 8, 25, - 0x11, 0x00, 0, 0, 0, - 0x12, 0x00, 0, 0, 0, - 0x13, 0x00, 0, 0, 0, - 0x14, 0x00, 0, 0, 0, - 0x15, 0x00, 0, 0, 0, - 0x16, 0x00, 0, 0, 0, - 0x17, 0x00, 0, 0, 0, - 0x18, 0x00, 0, 0, 0, - 0x19, 0x00, 0, 0, 0, - 0x1a, 0x00, 0, 0, 0, - 0x1b, 0x00, 0, 0, 0, - 0x1c, 0x00, 0, 0, 0, - 0x1d, 0x00, 0, 0, 0, - 0x1e, 0x00, 0, 0, 0, - 0x1f, 0x00, 0, 0, 0, -}; - -u8 RateSwitchTable11B[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x04, 0x03, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x00, 0, 40, 101, - 0x01, 0x00, 1, 40, 50, - 0x02, 0x00, 2, 35, 45, - 0x03, 0x00, 3, 20, 45, -}; - -u8 RateSwitchTable11BG[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0a, 0x00, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x00, 0, 40, 101, - 0x01, 0x00, 1, 40, 50, - 0x02, 0x00, 2, 35, 45, - 0x03, 0x00, 3, 20, 45, - 0x04, 0x10, 2, 20, 35, - 0x05, 0x10, 3, 16, 35, - 0x06, 0x10, 4, 10, 25, - 0x07, 0x10, 5, 16, 25, - 0x08, 0x10, 6, 10, 25, - 0x09, 0x10, 7, 10, 13, -}; - -u8 RateSwitchTable11G[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x08, 0x00, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x10, 0, 20, 101, - 0x01, 0x10, 1, 20, 35, - 0x02, 0x10, 2, 20, 35, - 0x03, 0x10, 3, 16, 35, - 0x04, 0x10, 4, 10, 25, - 0x05, 0x10, 5, 16, 25, - 0x06, 0x10, 6, 10, 25, - 0x07, 0x10, 7, 10, 13, -}; - -u8 RateSwitchTable11N1S[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0c, 0x0a, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x00, 0, 40, 101, - 0x01, 0x00, 1, 40, 50, - 0x02, 0x00, 2, 25, 45, - 0x03, 0x21, 0, 20, 35, - 0x04, 0x21, 1, 20, 35, - 0x05, 0x21, 2, 20, 35, - 0x06, 0x21, 3, 15, 35, - 0x07, 0x21, 4, 15, 30, - 0x08, 0x21, 5, 10, 25, - 0x09, 0x21, 6, 8, 14, - 0x0a, 0x21, 7, 8, 14, - 0x0b, 0x23, 7, 8, 14, -}; - -u8 RateSwitchTable11N2S[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0e, 0x0c, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x00, 0, 40, 101, - 0x01, 0x00, 1, 40, 50, - 0x02, 0x00, 2, 25, 45, - 0x03, 0x21, 0, 20, 35, - 0x04, 0x21, 1, 20, 35, - 0x05, 0x21, 2, 20, 35, - 0x06, 0x21, 3, 15, 35, - 0x07, 0x21, 4, 15, 30, - 0x08, 0x20, 11, 15, 30, - 0x09, 0x20, 12, 15, 30, - 0x0a, 0x20, 13, 8, 20, - 0x0b, 0x20, 14, 8, 20, - 0x0c, 0x20, 15, 8, 25, - 0x0d, 0x22, 15, 8, 15, -}; - -u8 RateSwitchTable11N3S[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0b, 0x00, 0, 0, 0, /* 0x0a, 0x00, 0, 0, 0, // Initial used item after association */ - 0x00, 0x21, 0, 30, 101, - 0x01, 0x21, 1, 20, 50, - 0x02, 0x21, 2, 20, 50, - 0x03, 0x21, 3, 15, 50, - 0x04, 0x21, 4, 15, 30, - 0x05, 0x20, 11, 15, 30, /* Required by System-Alan @ 20080812 */ - 0x06, 0x20, 12, 15, 30, /* 0x05, 0x20, 12, 15, 30, */ - 0x07, 0x20, 13, 8, 20, /* 0x06, 0x20, 13, 8, 20, */ - 0x08, 0x20, 14, 8, 20, /* 0x07, 0x20, 14, 8, 20, */ - 0x09, 0x20, 15, 8, 25, /* 0x08, 0x20, 15, 8, 25, */ - 0x0a, 0x22, 15, 8, 25, /* 0x09, 0x22, 15, 8, 25, */ -}; - -u8 RateSwitchTable11N2SForABand[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0b, 0x09, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x21, 0, 30, 101, - 0x01, 0x21, 1, 20, 50, - 0x02, 0x21, 2, 20, 50, - 0x03, 0x21, 3, 15, 50, - 0x04, 0x21, 4, 15, 30, - 0x05, 0x21, 5, 15, 30, - 0x06, 0x20, 12, 15, 30, - 0x07, 0x20, 13, 8, 20, - 0x08, 0x20, 14, 8, 20, - 0x09, 0x20, 15, 8, 25, - 0x0a, 0x22, 15, 8, 25, -}; - -u8 RateSwitchTable11N3SForABand[] = { /* 3*3 */ -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0b, 0x09, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x21, 0, 30, 101, - 0x01, 0x21, 1, 20, 50, - 0x02, 0x21, 2, 20, 50, - 0x03, 0x21, 3, 15, 50, - 0x04, 0x21, 4, 15, 30, - 0x05, 0x21, 5, 15, 30, - 0x06, 0x20, 12, 15, 30, - 0x07, 0x20, 13, 8, 20, - 0x08, 0x20, 14, 8, 20, - 0x09, 0x20, 15, 8, 25, - 0x0a, 0x22, 15, 8, 25, -}; - -u8 RateSwitchTable11BGN1S[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0c, 0x0a, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x00, 0, 40, 101, - 0x01, 0x00, 1, 40, 50, - 0x02, 0x00, 2, 25, 45, - 0x03, 0x21, 0, 20, 35, - 0x04, 0x21, 1, 20, 35, - 0x05, 0x21, 2, 20, 35, - 0x06, 0x21, 3, 15, 35, - 0x07, 0x21, 4, 15, 30, - 0x08, 0x21, 5, 10, 25, - 0x09, 0x21, 6, 8, 14, - 0x0a, 0x21, 7, 8, 14, - 0x0b, 0x23, 7, 8, 14, -}; - -u8 RateSwitchTable11BGN2S[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0e, 0x0c, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x00, 0, 40, 101, - 0x01, 0x00, 1, 40, 50, - 0x02, 0x00, 2, 25, 45, - 0x03, 0x21, 0, 20, 35, - 0x04, 0x21, 1, 20, 35, - 0x05, 0x21, 2, 20, 35, - 0x06, 0x21, 3, 15, 35, - 0x07, 0x21, 4, 15, 30, - 0x08, 0x20, 11, 15, 30, - 0x09, 0x20, 12, 15, 30, - 0x0a, 0x20, 13, 8, 20, - 0x0b, 0x20, 14, 8, 20, - 0x0c, 0x20, 15, 8, 25, - 0x0d, 0x22, 15, 8, 15, -}; - -u8 RateSwitchTable11BGN3S[] = { /* 3*3 */ -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0a, 0x00, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x21, 0, 30, 101, /*50 */ - 0x01, 0x21, 1, 20, 50, - 0x02, 0x21, 2, 20, 50, - 0x03, 0x21, 3, 20, 50, - 0x04, 0x21, 4, 15, 50, - 0x05, 0x20, 20, 15, 30, - 0x06, 0x20, 21, 8, 20, - 0x07, 0x20, 22, 8, 20, - 0x08, 0x20, 23, 8, 25, - 0x09, 0x22, 23, 8, 25, -}; - -u8 RateSwitchTable11BGN2SForABand[] = { -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0b, 0x09, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x21, 0, 30, 101, /*50 */ - 0x01, 0x21, 1, 20, 50, - 0x02, 0x21, 2, 20, 50, - 0x03, 0x21, 3, 15, 50, - 0x04, 0x21, 4, 15, 30, - 0x05, 0x21, 5, 15, 30, - 0x06, 0x20, 12, 15, 30, - 0x07, 0x20, 13, 8, 20, - 0x08, 0x20, 14, 8, 20, - 0x09, 0x20, 15, 8, 25, - 0x0a, 0x22, 15, 8, 25, -}; - -u8 RateSwitchTable11BGN3SForABand[] = { /* 3*3 */ -/* Item No. Mode Curr-MCS TrainUp TrainDown // Mode- Bit0: STBC, Bit1: Short GI, Bit4,5: Mode(0:CCK, 1:OFDM, 2:HT Mix, 3:HT GF) */ - 0x0c, 0x09, 0, 0, 0, /* Initial used item after association */ - 0x00, 0x21, 0, 30, 101, /*50 */ - 0x01, 0x21, 1, 20, 50, - 0x02, 0x21, 2, 20, 50, - 0x03, 0x21, 3, 15, 50, - 0x04, 0x21, 4, 15, 30, - 0x05, 0x21, 5, 15, 30, - 0x06, 0x21, 12, 15, 30, - 0x07, 0x20, 20, 15, 30, - 0x08, 0x20, 21, 8, 20, - 0x09, 0x20, 22, 8, 20, - 0x0a, 0x20, 23, 8, 25, - 0x0b, 0x22, 23, 8, 25, -}; - -extern u8 OfdmRateToRxwiMCS[]; -/* since RT61 has better RX sensibility, we have to limit TX ACK rate not to exceed our normal data TX rate. */ -/* otherwise the WLAN peer may not be able to receive the ACK thus downgrade its data TX rate */ -unsigned long BasicRateMask[12] = - { 0xfffff001 /* 1-Mbps */ , 0xfffff003 /* 2 Mbps */ , 0xfffff007 /* 5.5 */ , -0xfffff00f /* 11 */ , - 0xfffff01f /* 6 */ , 0xfffff03f /* 9 */ , 0xfffff07f /* 12 */ , - 0xfffff0ff /* 18 */ , - 0xfffff1ff /* 24 */ , 0xfffff3ff /* 36 */ , 0xfffff7ff /* 48 */ , - 0xffffffff /* 54 */ -}; - -u8 BROADCAST_ADDR[MAC_ADDR_LEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -u8 ZERO_MAC_ADDR[MAC_ADDR_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - -/* e.g. RssiSafeLevelForTxRate[RATE_36]" means if the current RSSI is greater than */ -/* this value, then it's quaranteed capable of operating in 36 mbps TX rate in */ -/* clean environment. */ -/* TxRate: 1 2 5.5 11 6 9 12 18 24 36 48 54 72 100 */ -char RssiSafeLevelForTxRate[] = - { -92, -91, -90, -87, -88, -86, -85, -83, -81, -78, -72, -71, -40, -40 }; - -u8 RateIdToMbps[] = { 1, 2, 5, 11, 6, 9, 12, 18, 24, 36, 48, 54, 72, 100 }; -u16 RateIdTo500Kbps[] = - { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 144, 200 }; - -u8 SsidIe = IE_SSID; -u8 SupRateIe = IE_SUPP_RATES; -u8 ExtRateIe = IE_EXT_SUPP_RATES; -u8 HtCapIe = IE_HT_CAP; -u8 AddHtInfoIe = IE_ADD_HT; -u8 NewExtChanIe = IE_SECONDARY_CH_OFFSET; -u8 ErpIe = IE_ERP; -u8 DsIe = IE_DS_PARM; -u8 TimIe = IE_TIM; -u8 WpaIe = IE_WPA; -u8 Wpa2Ie = IE_WPA2; -u8 IbssIe = IE_IBSS_PARM; - -extern u8 WPA_OUI[]; - -u8 SES_OUI[] = { 0x00, 0x90, 0x4c }; - -u8 ZeroSsid[32] = - { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00 -}; - -/* - ========================================================================== - Description: - initialize the MLME task and its data structure (queue, spinlock, - timer, state machines). - - IRQL = PASSIVE_LEVEL - - Return: - always return NDIS_STATUS_SUCCESS - - ========================================================================== -*/ -int MlmeInit(struct rt_rtmp_adapter *pAd) -{ - int Status = NDIS_STATUS_SUCCESS; - - DBGPRINT(RT_DEBUG_TRACE, ("--> MLME Initialize\n")); - - do { - Status = MlmeQueueInit(&pAd->Mlme.Queue); - if (Status != NDIS_STATUS_SUCCESS) - break; - - pAd->Mlme.bRunning = FALSE; - NdisAllocateSpinLock(&pAd->Mlme.TaskLock); - - { - BssTableInit(&pAd->ScanTab); - - /* init STA state machines */ - AssocStateMachineInit(pAd, &pAd->Mlme.AssocMachine, - pAd->Mlme.AssocFunc); - AuthStateMachineInit(pAd, &pAd->Mlme.AuthMachine, - pAd->Mlme.AuthFunc); - AuthRspStateMachineInit(pAd, &pAd->Mlme.AuthRspMachine, - pAd->Mlme.AuthRspFunc); - SyncStateMachineInit(pAd, &pAd->Mlme.SyncMachine, - pAd->Mlme.SyncFunc); - - /* Since we are using switch/case to implement it, the init is different from the above */ - /* state machine init */ - MlmeCntlInit(pAd, &pAd->Mlme.CntlMachine, NULL); - } - - WpaStateMachineInit(pAd, &pAd->Mlme.WpaMachine, - pAd->Mlme.WpaFunc); - - ActionStateMachineInit(pAd, &pAd->Mlme.ActMachine, - pAd->Mlme.ActFunc); - - /* Init mlme periodic timer */ - RTMPInitTimer(pAd, &pAd->Mlme.PeriodicTimer, - GET_TIMER_FUNCTION(MlmePeriodicExec), pAd, TRUE); - - /* Set mlme periodic timer */ - RTMPSetTimer(&pAd->Mlme.PeriodicTimer, MLME_TASK_EXEC_INTV); - - /* software-based RX Antenna diversity */ - RTMPInitTimer(pAd, &pAd->Mlme.RxAntEvalTimer, - GET_TIMER_FUNCTION(AsicRxAntEvalTimeout), pAd, - FALSE); - - { -#ifdef RTMP_PCI_SUPPORT - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) { - /* only PCIe cards need these two timers */ - RTMPInitTimer(pAd, &pAd->Mlme.PsPollTimer, - GET_TIMER_FUNCTION - (PsPollWakeExec), pAd, FALSE); - RTMPInitTimer(pAd, &pAd->Mlme.RadioOnOffTimer, - GET_TIMER_FUNCTION(RadioOnExec), - pAd, FALSE); - } -#endif /* RTMP_PCI_SUPPORT // */ - - RTMPInitTimer(pAd, &pAd->Mlme.LinkDownTimer, - GET_TIMER_FUNCTION(LinkDownExec), pAd, - FALSE); - -#ifdef RTMP_MAC_USB - RTMPInitTimer(pAd, &pAd->Mlme.AutoWakeupTimer, - GET_TIMER_FUNCTION - (RtmpUsbStaAsicForceWakeupTimeout), pAd, - FALSE); - pAd->Mlme.AutoWakeupTimerRunning = FALSE; -#endif /* RTMP_MAC_USB // */ - } - - } while (FALSE); - - DBGPRINT(RT_DEBUG_TRACE, ("<-- MLME Initialize\n")); - - return Status; -} - -/* - ========================================================================== - Description: - main loop of the MLME - Pre: - Mlme has to be initialized, and there are something inside the queue - Note: - This function is invoked from MPSetInformation and MPReceive; - This task guarantee only one MlmeHandler will run. - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void MlmeHandler(struct rt_rtmp_adapter *pAd) -{ - struct rt_mlme_queue_elem *Elem = NULL; - - /* Only accept MLME and Frame from peer side, no other (control/data) frame should */ - /* get into this state machine */ - - NdisAcquireSpinLock(&pAd->Mlme.TaskLock); - if (pAd->Mlme.bRunning) { - NdisReleaseSpinLock(&pAd->Mlme.TaskLock); - return; - } else { - pAd->Mlme.bRunning = TRUE; - } - NdisReleaseSpinLock(&pAd->Mlme.TaskLock); - - while (!MlmeQueueEmpty(&pAd->Mlme.Queue)) { - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MLME_RESET_IN_PROGRESS) || - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS) || - RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) { - DBGPRINT(RT_DEBUG_TRACE, - ("Device Halted or Removed or MlmeRest, exit MlmeHandler! (queue num = %ld)\n", - pAd->Mlme.Queue.Num)); - break; - } - /*From message type, determine which state machine I should drive */ - if (MlmeDequeue(&pAd->Mlme.Queue, &Elem)) { -#ifdef RTMP_MAC_USB - if (Elem->MsgType == MT2_RESET_CONF) { - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("reset MLME state machine!\n")); - MlmeRestartStateMachine(pAd); - Elem->Occupied = FALSE; - Elem->MsgLen = 0; - continue; - } -#endif /* RTMP_MAC_USB // */ - - /* if dequeue success */ - switch (Elem->Machine) { - /* STA state machines */ - case ASSOC_STATE_MACHINE: - StateMachinePerformAction(pAd, - &pAd->Mlme. - AssocMachine, Elem); - break; - case AUTH_STATE_MACHINE: - StateMachinePerformAction(pAd, - &pAd->Mlme. - AuthMachine, Elem); - break; - case AUTH_RSP_STATE_MACHINE: - StateMachinePerformAction(pAd, - &pAd->Mlme. - AuthRspMachine, Elem); - break; - case SYNC_STATE_MACHINE: - StateMachinePerformAction(pAd, - &pAd->Mlme. - SyncMachine, Elem); - break; - case MLME_CNTL_STATE_MACHINE: - MlmeCntlMachinePerformAction(pAd, - &pAd->Mlme. - CntlMachine, Elem); - break; - case WPA_PSK_STATE_MACHINE: - StateMachinePerformAction(pAd, - &pAd->Mlme. - WpaPskMachine, Elem); - break; - - case ACTION_STATE_MACHINE: - StateMachinePerformAction(pAd, - &pAd->Mlme.ActMachine, - Elem); - break; - - case WPA_STATE_MACHINE: - StateMachinePerformAction(pAd, - &pAd->Mlme.WpaMachine, - Elem); - break; - - default: - DBGPRINT(RT_DEBUG_TRACE, - ("ERROR: Illegal machine %ld in MlmeHandler()\n", - Elem->Machine)); - break; - } /* end of switch */ - - /* free MLME element */ - Elem->Occupied = FALSE; - Elem->MsgLen = 0; - - } else { - DBGPRINT_ERR("MlmeHandler: MlmeQueue empty\n"); - } - } - - NdisAcquireSpinLock(&pAd->Mlme.TaskLock); - pAd->Mlme.bRunning = FALSE; - NdisReleaseSpinLock(&pAd->Mlme.TaskLock); -} - -/* - ========================================================================== - Description: - Destructor of MLME (Destroy queue, state machine, spin lock and timer) - Parameters: - Adapter - NIC Adapter pointer - Post: - The MLME task will no longer work properly - - IRQL = PASSIVE_LEVEL - - ========================================================================== - */ -void MlmeHalt(struct rt_rtmp_adapter *pAd) -{ - BOOLEAN Cancelled; - - DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeHalt\n")); - - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) { - /* disable BEACON generation and other BEACON related hardware timers */ - AsicDisableSync(pAd); - } - - { - /* Cancel pending timers */ - RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled); - RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled); - RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled); - RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled); - RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled); - RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled); - -#ifdef RTMP_MAC_PCI - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) { - RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); - RTMPCancelTimer(&pAd->Mlme.RadioOnOffTimer, &Cancelled); - } -#endif /* RTMP_MAC_PCI // */ - - RTMPCancelTimer(&pAd->Mlme.LinkDownTimer, &Cancelled); - -#ifdef RTMP_MAC_USB - RTMPCancelTimer(&pAd->Mlme.AutoWakeupTimer, &Cancelled); -#endif /* RTMP_MAC_USB // */ - } - - RTMPCancelTimer(&pAd->Mlme.PeriodicTimer, &Cancelled); - RTMPCancelTimer(&pAd->Mlme.RxAntEvalTimer, &Cancelled); - - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) { - struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps; - - /* Set LED */ - RTMPSetLED(pAd, LED_HALT); - RTMPSetSignalLED(pAd, -100); /* Force signal strength Led to be turned off, firmware is not done it. */ -#ifdef RTMP_MAC_USB - { - LED_CFG_STRUC LedCfg; - RTMP_IO_READ32(pAd, LED_CFG, &LedCfg.word); - LedCfg.field.LedPolar = 0; - LedCfg.field.RLedMode = 0; - LedCfg.field.GLedMode = 0; - LedCfg.field.YLedMode = 0; - RTMP_IO_WRITE32(pAd, LED_CFG, LedCfg.word); - } -#endif /* RTMP_MAC_USB // */ - - if (pChipOps->AsicHaltAction) - pChipOps->AsicHaltAction(pAd); - } - - RTMPusecDelay(5000); /* 5 msec to guarantee Ant Diversity timer canceled */ - - MlmeQueueDestroy(&pAd->Mlme.Queue); - NdisFreeSpinLock(&pAd->Mlme.TaskLock); - - DBGPRINT(RT_DEBUG_TRACE, ("<== MlmeHalt\n")); -} - -void MlmeResetRalinkCounters(struct rt_rtmp_adapter *pAd) -{ - pAd->RalinkCounters.LastOneSecRxOkDataCnt = - pAd->RalinkCounters.OneSecRxOkDataCnt; - /* clear all OneSecxxx counters. */ - pAd->RalinkCounters.OneSecBeaconSentCnt = 0; - pAd->RalinkCounters.OneSecFalseCCACnt = 0; - pAd->RalinkCounters.OneSecRxFcsErrCnt = 0; - pAd->RalinkCounters.OneSecRxOkCnt = 0; - pAd->RalinkCounters.OneSecTxFailCount = 0; - pAd->RalinkCounters.OneSecTxNoRetryOkCount = 0; - pAd->RalinkCounters.OneSecTxRetryOkCount = 0; - pAd->RalinkCounters.OneSecRxOkDataCnt = 0; - pAd->RalinkCounters.OneSecReceivedByteCount = 0; - pAd->RalinkCounters.OneSecTransmittedByteCount = 0; - - /* TODO: for debug only. to be removed */ - pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BE] = 0; - pAd->RalinkCounters.OneSecOsTxCount[QID_AC_BK] = 0; - pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VI] = 0; - pAd->RalinkCounters.OneSecOsTxCount[QID_AC_VO] = 0; - pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BE] = 0; - pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_BK] = 0; - pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VI] = 0; - pAd->RalinkCounters.OneSecDmaDoneCount[QID_AC_VO] = 0; - pAd->RalinkCounters.OneSecTxDoneCount = 0; - pAd->RalinkCounters.OneSecRxCount = 0; - pAd->RalinkCounters.OneSecTxAggregationCount = 0; - pAd->RalinkCounters.OneSecRxAggregationCount = 0; - - return; -} - -/* - ========================================================================== - Description: - This routine is executed periodically to - - 1. Decide if it's a right time to turn on PwrMgmt bit of all - outgoiing frames - 2. Calculate ChannelQuality based on statistics of the last - period, so that TX rate won't toggling very frequently between a - successful TX and a failed TX. - 3. If the calculated ChannelQuality indicated current connection not - healthy, then a ROAMing attempt is tried here. - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -#define ADHOC_BEACON_LOST_TIME (8*OS_HZ) /* 8 sec */ -void MlmePeriodicExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - unsigned long TxTotalCnt; - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - -#ifdef RTMP_MAC_PCI - { - /* If Hardware controlled Radio enabled, we have to check GPIO pin2 every 2 second. */ - /* Move code to here, because following code will return when radio is off */ - if ((pAd->Mlme.PeriodicRound % (MLME_TASK_EXEC_MULTIPLE * 2) == - 0) && (pAd->StaCfg.bHardwareRadio == TRUE) - && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) - && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) - /*&&(pAd->bPCIclkOff == FALSE) */ - ) { - u32 data = 0; - - /* Read GPIO pin2 as Hardware controlled radio state */ -#ifndef RT3090 - RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &data); -#endif /* RT3090 // */ -/*KH(PCIE PS):Added based on Jane<-- */ -#ifdef RT3090 -/* Read GPIO pin2 as Hardware controlled radio state */ -/* We need to Read GPIO if HW said so no mater what advance power saving */ - if ((pAd->OpMode == OPMODE_STA) && (IDLE_ON(pAd)) - && - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF)) - && (pAd->StaCfg.PSControl.field.EnablePSinIdle == - TRUE)) { - /* Want to make sure device goes to L0 state before reading register. */ - RTMPPCIeLinkCtrlValueRestore(pAd, 0); - RTMP_IO_FORCE_READ32(pAd, GPIO_CTRL_CFG, &data); - RTMPPCIeLinkCtrlSetting(pAd, 3); - } else - RTMP_IO_FORCE_READ32(pAd, GPIO_CTRL_CFG, &data); -#endif /* RT3090 // */ -/*KH(PCIE PS):Added based on Jane--> */ - - if (data & 0x04) { - pAd->StaCfg.bHwRadio = TRUE; - } else { - pAd->StaCfg.bHwRadio = FALSE; - } - if (pAd->StaCfg.bRadio != - (pAd->StaCfg.bHwRadio && pAd->StaCfg.bSwRadio)) { - pAd->StaCfg.bRadio = (pAd->StaCfg.bHwRadio - && pAd->StaCfg.bSwRadio); - if (pAd->StaCfg.bRadio == TRUE) { - MlmeRadioOn(pAd); - /* Update extra information */ - pAd->ExtraInfo = EXTRA_INFO_CLEAR; - } else { - MlmeRadioOff(pAd); - /* Update extra information */ - pAd->ExtraInfo = HW_RADIO_OFF; - } - } - } - } -#endif /* RTMP_MAC_PCI // */ - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_RADIO_OFF | - fRTMP_ADAPTER_RADIO_MEASUREMENT | - fRTMP_ADAPTER_RESET_IN_PROGRESS)))) - return; - - RTMP_MLME_PRE_SANITY_CHECK(pAd); - - { - /* Do nothing if monitor mode is on */ - if (MONITOR_ON(pAd)) - return; - - if (pAd->Mlme.PeriodicRound & 0x1) { - /* This is the fix for wifi 11n extension channel overlapping test case. for 2860D */ - if (((pAd->MACVersion & 0xffff) == 0x0101) && - (STA_TGN_WIFI_ON(pAd)) && - (pAd->CommonCfg.IOTestParm.bToggle == FALSE)) - { - RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x24Bf); - pAd->CommonCfg.IOTestParm.bToggle = TRUE; - } else if ((STA_TGN_WIFI_ON(pAd)) && - ((pAd->MACVersion & 0xffff) == 0x0101)) { - RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x243f); - pAd->CommonCfg.IOTestParm.bToggle = FALSE; - } - } - } - - pAd->bUpdateBcnCntDone = FALSE; - -/* RECBATimerTimeout(SystemSpecific1,FunctionContext,SystemSpecific2,SystemSpecific3); */ - pAd->Mlme.PeriodicRound++; - -#ifdef RTMP_MAC_USB - /* execute every 100ms, update the Tx FIFO Cnt for update Tx Rate. */ - NICUpdateFifoStaCounters(pAd); -#endif /* RTMP_MAC_USB // */ - - /* execute every 500ms */ - if ((pAd->Mlme.PeriodicRound % 5 == 0) - && RTMPAutoRateSwitchCheck(pAd) - /*(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED)) */ ) - { - /* perform dynamic tx rate switching based on past TX history */ - { - if ((OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) - ) - && (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE))) - MlmeDynamicTxRateSwitching(pAd); - } - } - /* Normal 1 second Mlme PeriodicExec. */ - if (pAd->Mlme.PeriodicRound % MLME_TASK_EXEC_MULTIPLE == 0) { - pAd->Mlme.OneSecPeriodicRound++; - - /*ORIBATimerTimeout(pAd); */ - - /* Media status changed, report to NDIS */ - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE)) { - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE); - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) { - pAd->IndicateMediaState = - NdisMediaStateConnected; - RTMP_IndicateMediaState(pAd); - - } else { - pAd->IndicateMediaState = - NdisMediaStateDisconnected; - RTMP_IndicateMediaState(pAd); - } - } - - NdisGetSystemUpTime(&pAd->Mlme.Now32); - - /* add the most up-to-date h/w raw counters into software variable, so that */ - /* the dynamic tuning mechanism below are based on most up-to-date information */ - NICUpdateRawCounters(pAd); - -#ifdef RTMP_MAC_USB - RTUSBWatchDog(pAd); -#endif /* RTMP_MAC_USB // */ - - /* Need statistics after read counter. So put after NICUpdateRawCounters */ - ORIBATimerTimeout(pAd); - - /* if MGMT RING is full more than twice within 1 second, we consider there's */ - /* a hardware problem stucking the TX path. In this case, try a hardware reset */ - /* to recover the system */ - /* if (pAd->RalinkCounters.MgmtRingFullCount >= 2) */ - /* RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HARDWARE_ERROR); */ - /* else */ - /* pAd->RalinkCounters.MgmtRingFullCount = 0; */ - - /* The time period for checking antenna is according to traffic */ - { - if (pAd->Mlme.bEnableAutoAntennaCheck) { - TxTotalCnt = - pAd->RalinkCounters.OneSecTxNoRetryOkCount + - pAd->RalinkCounters.OneSecTxRetryOkCount + - pAd->RalinkCounters.OneSecTxFailCount; - - /* dynamic adjust antenna evaluation period according to the traffic */ - if (TxTotalCnt > 50) { - if (pAd->Mlme.OneSecPeriodicRound % - 10 == 0) { - AsicEvaluateRxAnt(pAd); - } - } else { - if (pAd->Mlme.OneSecPeriodicRound % 3 == - 0) { - AsicEvaluateRxAnt(pAd); - } - } - } - } - - STAMlmePeriodicExec(pAd); - - MlmeResetRalinkCounters(pAd); - - { -#ifdef RTMP_MAC_PCI - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) - && (pAd->bPCIclkOff == FALSE)) -#endif /* RTMP_MAC_PCI // */ - { - /* When Adhoc beacon is enabled and RTS/CTS is enabled, there is a chance that hardware MAC FSM will run into a deadlock */ - /* and sending CTS-to-self over and over. */ - /* Software Patch Solution: */ - /* 1. Polling debug state register 0x10F4 every one second. */ - /* 2. If in 0x10F4 the ((bit29==1) && (bit7==1)) OR ((bit29==1) && (bit5==1)), it means the deadlock has occurred. */ - /* 3. If the deadlock occurred, reset MAC/BBP by setting 0x1004 to 0x0001 for a while then setting it back to 0x000C again. */ - - u32 MacReg = 0; - - RTMP_IO_READ32(pAd, 0x10F4, &MacReg); - if (((MacReg & 0x20000000) && (MacReg & 0x80)) - || ((MacReg & 0x20000000) - && (MacReg & 0x20))) { - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1); - RTMPusecDelay(1); - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xC); - - DBGPRINT(RT_DEBUG_WARN, - ("Warning, MAC specific condition occurs \n")); - } - } - } - - RTMP_MLME_HANDLER(pAd); - } - - pAd->bUpdateBcnCntDone = FALSE; -} - -/* - ========================================================================== - Validate SSID for connection try and rescan purpose - Valid SSID will have visible chars only. - The valid length is from 0 to 32. - IRQL = DISPATCH_LEVEL - ========================================================================== - */ -BOOLEAN MlmeValidateSSID(u8 *pSsid, u8 SsidLen) -{ - int index; - - if (SsidLen > MAX_LEN_OF_SSID) - return (FALSE); - - /* Check each character value */ - for (index = 0; index < SsidLen; index++) { - if (pSsid[index] < 0x20) - return (FALSE); - } - - /* All checked */ - return (TRUE); -} - -void MlmeSelectTxRateTable(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 ** ppTable, - u8 *pTableSize, u8 *pInitTxRateIdx) -{ - do { - /* decide the rate table for tuning */ - if (pAd->CommonCfg.TxRateTableSize > 0) { - *ppTable = RateSwitchTable; - *pTableSize = RateSwitchTable[0]; - *pInitTxRateIdx = RateSwitchTable[1]; - - break; - } - - if ((pAd->OpMode == OPMODE_STA) && ADHOC_ON(pAd)) { - if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && (pEntry->HTCapability.MCSSet[0] == 0xff) && ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1))) { /* 11N 1S Adhoc */ - *ppTable = RateSwitchTable11N1S; - *pTableSize = RateSwitchTable11N1S[0]; - *pInitTxRateIdx = RateSwitchTable11N1S[1]; - - } else if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) && (pEntry->HTCapability.MCSSet[0] == 0xff) && (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->Antenna.field.TxPath == 2)) { /* 11N 2S Adhoc */ - if (pAd->LatchRfRegs.Channel <= 14) { - *ppTable = RateSwitchTable11N2S; - *pTableSize = RateSwitchTable11N2S[0]; - *pInitTxRateIdx = - RateSwitchTable11N2S[1]; - } else { - *ppTable = RateSwitchTable11N2SForABand; - *pTableSize = - RateSwitchTable11N2SForABand[0]; - *pInitTxRateIdx = - RateSwitchTable11N2SForABand[1]; - } - - } else if ((pEntry->RateLen == 4) - && (pEntry->HTCapability.MCSSet[0] == 0) - && (pEntry->HTCapability.MCSSet[1] == 0) - ) { - *ppTable = RateSwitchTable11B; - *pTableSize = RateSwitchTable11B[0]; - *pInitTxRateIdx = RateSwitchTable11B[1]; - - } else if (pAd->LatchRfRegs.Channel <= 14) { - *ppTable = RateSwitchTable11BG; - *pTableSize = RateSwitchTable11BG[0]; - *pInitTxRateIdx = RateSwitchTable11BG[1]; - - } else { - *ppTable = RateSwitchTable11G; - *pTableSize = RateSwitchTable11G[0]; - *pInitTxRateIdx = RateSwitchTable11G[1]; - - } - break; - } - /*if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 12) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && */ - /* ((pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1))) */ - if (((pEntry->RateLen == 12) || (pAd->OpMode == OPMODE_STA)) && (pEntry->HTCapability.MCSSet[0] == 0xff) && ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1))) { /* 11BGN 1S AP */ - *ppTable = RateSwitchTable11BGN1S; - *pTableSize = RateSwitchTable11BGN1S[0]; - *pInitTxRateIdx = RateSwitchTable11BGN1S[1]; - - break; - } - /*else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 12) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && */ - /* (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0xff) && (pAd->Antenna.field.TxPath == 2)) */ - if (((pEntry->RateLen == 12) || (pAd->OpMode == OPMODE_STA)) && (pEntry->HTCapability.MCSSet[0] == 0xff) && (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->CommonCfg.TxStream == 2)) { /* 11BGN 2S AP */ - if (pAd->LatchRfRegs.Channel <= 14) { - *ppTable = RateSwitchTable11BGN2S; - *pTableSize = RateSwitchTable11BGN2S[0]; - *pInitTxRateIdx = RateSwitchTable11BGN2S[1]; - - } else { - *ppTable = RateSwitchTable11BGN2SForABand; - *pTableSize = RateSwitchTable11BGN2SForABand[0]; - *pInitTxRateIdx = - RateSwitchTable11BGN2SForABand[1]; - - } - break; - } - /*else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && ((pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0x00) || (pAd->Antenna.field.TxPath == 1))) */ - if ((pEntry->HTCapability.MCSSet[0] == 0xff) && ((pEntry->HTCapability.MCSSet[1] == 0x00) || (pAd->CommonCfg.TxStream == 1))) { /* 11N 1S AP */ - *ppTable = RateSwitchTable11N1S; - *pTableSize = RateSwitchTable11N1S[0]; - *pInitTxRateIdx = RateSwitchTable11N1S[1]; - - break; - } - /*else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0xff) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0xff) && (pAd->Antenna.field.TxPath == 2)) */ - if ((pEntry->HTCapability.MCSSet[0] == 0xff) && (pEntry->HTCapability.MCSSet[1] == 0xff) && (pAd->CommonCfg.TxStream == 2)) { /* 11N 2S AP */ - if (pAd->LatchRfRegs.Channel <= 14) { - *ppTable = RateSwitchTable11N2S; - *pTableSize = RateSwitchTable11N2S[0]; - *pInitTxRateIdx = RateSwitchTable11N2S[1]; - } else { - *ppTable = RateSwitchTable11N2SForABand; - *pTableSize = RateSwitchTable11N2SForABand[0]; - *pInitTxRateIdx = - RateSwitchTable11N2SForABand[1]; - } - - break; - } - /*else if ((pAd->StaActive.SupRateLen == 4) && (pAd->StaActive.ExtRateLen == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) */ - if ((pEntry->RateLen == 4 || pAd->CommonCfg.PhyMode == PHY_11B) - /*Iverson mark for Adhoc b mode,sta will use rate 54 Mbps when connect with sta b/g/n mode */ - /* && (pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0) */ - ) { /* B only AP */ - *ppTable = RateSwitchTable11B; - *pTableSize = RateSwitchTable11B[0]; - *pInitTxRateIdx = RateSwitchTable11B[1]; - - break; - } - /*else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen > 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) */ - if ((pEntry->RateLen > 8) - && (pEntry->HTCapability.MCSSet[0] == 0) - && (pEntry->HTCapability.MCSSet[1] == 0) - ) { /* B/G mixed AP */ - *ppTable = RateSwitchTable11BG; - *pTableSize = RateSwitchTable11BG[0]; - *pInitTxRateIdx = RateSwitchTable11BG[1]; - - break; - } - /*else if ((pAd->StaActive.SupRateLen + pAd->StaActive.ExtRateLen == 8) && (pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) */ - if ((pEntry->RateLen == 8) - && (pEntry->HTCapability.MCSSet[0] == 0) - && (pEntry->HTCapability.MCSSet[1] == 0) - ) { /* G only AP */ - *ppTable = RateSwitchTable11G; - *pTableSize = RateSwitchTable11G[0]; - *pInitTxRateIdx = RateSwitchTable11G[1]; - - break; - } - - { - /*else if ((pAd->StaActive.SupportedPhyInfo.MCSSet[0] == 0) && (pAd->StaActive.SupportedPhyInfo.MCSSet[1] == 0)) */ - if ((pEntry->HTCapability.MCSSet[0] == 0) && (pEntry->HTCapability.MCSSet[1] == 0)) { /* Legacy mode */ - if (pAd->CommonCfg.MaxTxRate <= RATE_11) { - *ppTable = RateSwitchTable11B; - *pTableSize = RateSwitchTable11B[0]; - *pInitTxRateIdx = RateSwitchTable11B[1]; - } else if ((pAd->CommonCfg.MaxTxRate > RATE_11) - && (pAd->CommonCfg.MinTxRate > - RATE_11)) { - *ppTable = RateSwitchTable11G; - *pTableSize = RateSwitchTable11G[0]; - *pInitTxRateIdx = RateSwitchTable11G[1]; - - } else { - *ppTable = RateSwitchTable11BG; - *pTableSize = RateSwitchTable11BG[0]; - *pInitTxRateIdx = - RateSwitchTable11BG[1]; - } - break; - } - if (pAd->LatchRfRegs.Channel <= 14) { - if (pAd->CommonCfg.TxStream == 1) { - *ppTable = RateSwitchTable11N1S; - *pTableSize = RateSwitchTable11N1S[0]; - *pInitTxRateIdx = - RateSwitchTable11N1S[1]; - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("DRS: unknown mode,default use 11N 1S AP \n")); - } else { - *ppTable = RateSwitchTable11N2S; - *pTableSize = RateSwitchTable11N2S[0]; - *pInitTxRateIdx = - RateSwitchTable11N2S[1]; - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("DRS: unknown mode,default use 11N 2S AP \n")); - } - } else { - if (pAd->CommonCfg.TxStream == 1) { - *ppTable = RateSwitchTable11N1S; - *pTableSize = RateSwitchTable11N1S[0]; - *pInitTxRateIdx = - RateSwitchTable11N1S[1]; - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("DRS: unknown mode,default use 11N 1S AP \n")); - } else { - *ppTable = RateSwitchTable11N2SForABand; - *pTableSize = - RateSwitchTable11N2SForABand[0]; - *pInitTxRateIdx = - RateSwitchTable11N2SForABand[1]; - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("DRS: unknown mode,default use 11N 2S AP \n")); - } - } - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("DRS: unknown mode (SupRateLen=%d, ExtRateLen=%d, MCSSet[0]=0x%x, MCSSet[1]=0x%x)\n", - pAd->StaActive.SupRateLen, - pAd->StaActive.ExtRateLen, - pAd->StaActive.SupportedPhyInfo.MCSSet[0], - pAd->StaActive.SupportedPhyInfo. - MCSSet[1])); - } - } while (FALSE); -} - -void STAMlmePeriodicExec(struct rt_rtmp_adapter *pAd) -{ - unsigned long TxTotalCnt; - int i; - - /* - We return here in ATE mode, because the statistics - that ATE need are not collected via this routine. - */ -#if defined(RT305x)||defined(RT3070) - /* request by Gary, if Rssi0 > -42, BBP 82 need to be changed from 0x62 to 0x42, , bbp 67 need to be changed from 0x20 to 0x18 */ - if (!pAd->CommonCfg.HighPowerPatchDisabled) { -#ifdef RT3070 - if ((IS_RT3070(pAd) && ((pAd->MACVersion & 0xffff) < 0x0201))) -#endif /* RT3070 // */ - { - if ((pAd->StaCfg.RssiSample.AvgRssi0 != 0) - && (pAd->StaCfg.RssiSample.AvgRssi0 > - (pAd->BbpRssiToDbmDelta - 35))) { - RT30xxWriteRFRegister(pAd, RF_R27, 0x20); - } else { - RT30xxWriteRFRegister(pAd, RF_R27, 0x23); - } - } - } -#endif -#ifdef PCIE_PS_SUPPORT -/* don't perform idle-power-save mechanism within 3 min after driver initialization. */ -/* This can make rebooter test more robust */ - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) { - if ((pAd->OpMode == OPMODE_STA) && (IDLE_ON(pAd)) - && (pAd->Mlme.SyncMachine.CurrState == SYNC_IDLE) - && (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) - && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))) { - if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) { - if (pAd->StaCfg.PSControl.field.EnableNewPS == - TRUE) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s\n", __func__)); - RT28xxPciAsicRadioOff(pAd, - GUI_IDLE_POWER_SAVE, - 0); - } else { - AsicSendCommandToMcu(pAd, 0x30, - PowerSafeCID, 0xff, - 0x2); - /* Wait command success */ - AsicCheckCommanOk(pAd, PowerSafeCID); - RTMP_SET_FLAG(pAd, - fRTMP_ADAPTER_IDLE_RADIO_OFF); - DBGPRINT(RT_DEBUG_TRACE, - ("PSM - rt30xx Issue Sleep command)\n")); - } - } else if (pAd->Mlme.OneSecPeriodicRound > 180) { - if (pAd->StaCfg.PSControl.field.EnableNewPS == - TRUE) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s\n", __func__)); - RT28xxPciAsicRadioOff(pAd, - GUI_IDLE_POWER_SAVE, - 0); - } else { - AsicSendCommandToMcu(pAd, 0x30, - PowerSafeCID, 0xff, - 0x02); - /* Wait command success */ - AsicCheckCommanOk(pAd, PowerSafeCID); - RTMP_SET_FLAG(pAd, - fRTMP_ADAPTER_IDLE_RADIO_OFF); - DBGPRINT(RT_DEBUG_TRACE, - ("PSM - rt28xx Issue Sleep command)\n")); - } - } - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("STAMlmePeriodicExec MMCHK - CommonCfg.Ssid[%d]=%c%c%c%c... MlmeAux.Ssid[%d]=%c%c%c%c...\n", - pAd->CommonCfg.SsidLen, - pAd->CommonCfg.Ssid[0], - pAd->CommonCfg.Ssid[1], - pAd->CommonCfg.Ssid[2], - pAd->CommonCfg.Ssid[3], pAd->MlmeAux.SsidLen, - pAd->MlmeAux.Ssid[0], pAd->MlmeAux.Ssid[1], - pAd->MlmeAux.Ssid[2], pAd->MlmeAux.Ssid[3])); - } - } -#endif /* PCIE_PS_SUPPORT // */ - - if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE) { - /* WPA MIC error should block association attempt for 60 seconds */ - if (pAd->StaCfg.bBlockAssoc && - RTMP_TIME_AFTER(pAd->Mlme.Now32, - pAd->StaCfg.LastMicErrorTime + - (60 * OS_HZ))) - pAd->StaCfg.bBlockAssoc = FALSE; - } - - if ((pAd->PreMediaState != pAd->IndicateMediaState) - && (pAd->CommonCfg.bWirelessEvent)) { - if (pAd->IndicateMediaState == NdisMediaStateConnected) { - RTMPSendWirelessEvent(pAd, IW_STA_LINKUP_EVENT_FLAG, - pAd->MacTab.Content[BSSID_WCID]. - Addr, BSS0, 0); - } - pAd->PreMediaState = pAd->IndicateMediaState; - } - - if (pAd->CommonCfg.PSPXlink && ADHOC_ON(pAd)) { - } else { - AsicStaBbpTuning(pAd); - } - - TxTotalCnt = pAd->RalinkCounters.OneSecTxNoRetryOkCount + - pAd->RalinkCounters.OneSecTxRetryOkCount + - pAd->RalinkCounters.OneSecTxFailCount; - - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) { - /* update channel quality for Roaming and UI LinkQuality display */ - MlmeCalculateChannelQuality(pAd, NULL, pAd->Mlme.Now32); - } - /* must be AFTER MlmeDynamicTxRateSwitching() because it needs to know if */ - /* Radio is currently in noisy environment */ - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) - AsicAdjustTxPower(pAd); - - if (INFRA_ON(pAd)) { - - /* Is PSM bit consistent with user power management policy? */ - /* This is the only place that will set PSM bit ON. */ - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) - MlmeCheckPsmChange(pAd, pAd->Mlme.Now32); - - pAd->RalinkCounters.LastOneSecTotalTxCount = TxTotalCnt; - - if ((RTMP_TIME_AFTER - (pAd->Mlme.Now32, - pAd->StaCfg.LastBeaconRxTime + (1 * OS_HZ))) - && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) - && - (((TxTotalCnt + pAd->RalinkCounters.OneSecRxOkCnt) < - 600))) { - RTMPSetAGCInitValue(pAd, BW_20); - DBGPRINT(RT_DEBUG_TRACE, - ("MMCHK - No BEACON. restore R66 to the low bound(%d) \n", - (0x2E + GET_LNA_GAIN(pAd)))); - } - /*if ((pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) && */ - /* (pAd->RalinkCounters.OneSecTxRetryOkCount == 0)) */ - { - if (pAd->CommonCfg.bAPSDCapable - && pAd->CommonCfg.APEdcaParm.bAPSDCapable) { - /* When APSD is enabled, the period changes as 20 sec */ - if ((pAd->Mlme.OneSecPeriodicRound % 20) == 8) - RTMPSendNullFrame(pAd, - pAd->CommonCfg.TxRate, - TRUE); - } else { - /* Send out a NULL frame every 10 sec to inform AP that STA is still alive (Avoid being age out) */ - if ((pAd->Mlme.OneSecPeriodicRound % 10) == 8) { - if (pAd->CommonCfg.bWmmCapable) - RTMPSendNullFrame(pAd, - pAd-> - CommonCfg. - TxRate, TRUE); - else - RTMPSendNullFrame(pAd, - pAd-> - CommonCfg. - TxRate, - FALSE); - } - } - } - - if (CQI_IS_DEAD(pAd->Mlme.ChannelQuality)) { - DBGPRINT(RT_DEBUG_TRACE, - ("MMCHK - No BEACON. Dead CQI. Auto Recovery attempt #%ld\n", - pAd->RalinkCounters.BadCQIAutoRecoveryCount)); - - /* Lost AP, send disconnect & link down event */ - LinkDown(pAd, FALSE); - - RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL, - 0); - - /* RTMPPatchMacBbpBug(pAd); */ - MlmeAutoReconnectLastSSID(pAd); - } else if (CQI_IS_BAD(pAd->Mlme.ChannelQuality)) { - pAd->RalinkCounters.BadCQIAutoRecoveryCount++; - DBGPRINT(RT_DEBUG_TRACE, - ("MMCHK - Bad CQI. Auto Recovery attempt #%ld\n", - pAd->RalinkCounters.BadCQIAutoRecoveryCount)); - MlmeAutoReconnectLastSSID(pAd); - } - - if (pAd->StaCfg.bAutoRoaming) { - BOOLEAN rv = FALSE; - char dBmToRoam = pAd->StaCfg.dBmToRoam; - char MaxRssi = RTMPMaxRssi(pAd, - pAd->StaCfg.RssiSample. - LastRssi0, - pAd->StaCfg.RssiSample. - LastRssi1, - pAd->StaCfg.RssiSample. - LastRssi2); - - /* Scanning, ignore Roaming */ - if (!RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS) - && (pAd->Mlme.SyncMachine.CurrState == SYNC_IDLE) - && (MaxRssi <= dBmToRoam)) { - DBGPRINT(RT_DEBUG_TRACE, - ("Rssi=%d, dBmToRoam=%d\n", MaxRssi, - (char)dBmToRoam)); - - /* Add auto seamless roaming */ - if (rv == FALSE) - rv = MlmeCheckForFastRoaming(pAd); - - if (rv == FALSE) { - if ((pAd->StaCfg.LastScanTime + - 10 * OS_HZ) < pAd->Mlme.Now32) { - DBGPRINT(RT_DEBUG_TRACE, - ("MMCHK - Roaming, No eligible entry, try new scan!\n")); - pAd->StaCfg.ScanCnt = 2; - pAd->StaCfg.LastScanTime = - pAd->Mlme.Now32; - MlmeAutoScan(pAd); - } - } - } - } - } else if (ADHOC_ON(pAd)) { - /* If all peers leave, and this STA becomes the last one in this IBSS, then change MediaState */ - /* to DISCONNECTED. But still holding this IBSS (i.e. sending BEACON) so that other STAs can */ - /* join later. */ - if (RTMP_TIME_AFTER - (pAd->Mlme.Now32, - pAd->StaCfg.LastBeaconRxTime + ADHOC_BEACON_LOST_TIME) - && OPSTATUS_TEST_FLAG(pAd, - fOP_STATUS_MEDIA_STATE_CONNECTED)) { - struct rt_mlme_start_req StartReq; - - DBGPRINT(RT_DEBUG_TRACE, - ("MMCHK - excessive BEACON lost, last STA in this IBSS, MediaState=Disconnected\n")); - LinkDown(pAd, FALSE); - - StartParmFill(pAd, &StartReq, - (char *) pAd->MlmeAux.Ssid, - pAd->MlmeAux.SsidLen); - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, - sizeof(struct rt_mlme_start_req), &StartReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START; - } - - for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) { - struct rt_mac_table_entry *pEntry = &pAd->MacTab.Content[i]; - - if (pEntry->ValidAsCLI == FALSE) - continue; - - if (RTMP_TIME_AFTER - (pAd->Mlme.Now32, - pEntry->LastBeaconRxTime + ADHOC_BEACON_LOST_TIME)) - MacTableDeleteEntry(pAd, pEntry->Aid, - pEntry->Addr); - } - } else /* no INFRA nor ADHOC connection */ - { - - if (pAd->StaCfg.bScanReqIsFromWebUI && - RTMP_TIME_BEFORE(pAd->Mlme.Now32, - pAd->StaCfg.LastScanTime + (30 * OS_HZ))) - goto SKIP_AUTO_SCAN_CONN; - else - pAd->StaCfg.bScanReqIsFromWebUI = FALSE; - - if ((pAd->StaCfg.bAutoReconnect == TRUE) - && RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP) - && - (MlmeValidateSSID - (pAd->MlmeAux.AutoReconnectSsid, - pAd->MlmeAux.AutoReconnectSsidLen) == TRUE)) { - if ((pAd->ScanTab.BssNr == 0) - && (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE)) { - struct rt_mlme_scan_req ScanReq; - - if (RTMP_TIME_AFTER - (pAd->Mlme.Now32, - pAd->StaCfg.LastScanTime + (10 * OS_HZ))) { - DBGPRINT(RT_DEBUG_TRACE, - ("STAMlmePeriodicExec():CNTL - ScanTab.BssNr==0, start a new ACTIVE scan SSID[%s]\n", - pAd->MlmeAux. - AutoReconnectSsid)); - ScanParmFill(pAd, &ScanReq, - (char *)pAd->MlmeAux. - AutoReconnectSsid, - pAd->MlmeAux. - AutoReconnectSsidLen, - BSS_ANY, SCAN_ACTIVE); - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, - MT2_MLME_SCAN_REQ, - sizeof - (struct rt_mlme_scan_req), - &ScanReq); - pAd->Mlme.CntlMachine.CurrState = - CNTL_WAIT_OID_LIST_SCAN; - /* Reset Missed scan number */ - pAd->StaCfg.LastScanTime = - pAd->Mlme.Now32; - } else if (pAd->StaCfg.BssType == BSS_ADHOC) /* Quit the forever scan when in a very clean room */ - MlmeAutoReconnectLastSSID(pAd); - } else if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) { - if ((pAd->Mlme.OneSecPeriodicRound % 7) == 0) { - MlmeAutoScan(pAd); - pAd->StaCfg.LastScanTime = - pAd->Mlme.Now32; - } else { - MlmeAutoReconnectLastSSID(pAd); - } - } - } - } - -SKIP_AUTO_SCAN_CONN: - - if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap != 0) - && (pAd->MacTab.fAnyBASession == FALSE)) { - pAd->MacTab.fAnyBASession = TRUE; - AsicUpdateProtect(pAd, HT_FORCERTSCTS, ALLN_SETPROTECT, FALSE, - FALSE); - } else if ((pAd->MacTab.Content[BSSID_WCID].TXBAbitmap == 0) - && (pAd->MacTab.fAnyBASession == TRUE)) { - pAd->MacTab.fAnyBASession = FALSE; - AsicUpdateProtect(pAd, - pAd->MlmeAux.AddHtInfo.AddHtInfo2. - OperaionMode, ALLN_SETPROTECT, FALSE, FALSE); - } - - return; -} - -/* Link down report */ -void LinkDownExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - - if (pAd != NULL) { - struct rt_mlme_disassoc_req DisassocReq; - - if ((pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED) && - (INFRA_ON(pAd))) { - DBGPRINT(RT_DEBUG_TRACE, - ("LinkDownExec(): disassociate with current AP...\n")); - DisassocParmFill(pAd, &DisassocReq, - pAd->CommonCfg.Bssid, - REASON_DISASSOC_STA_LEAVING); - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, - MT2_MLME_DISASSOC_REQ, - sizeof(struct rt_mlme_disassoc_req), - &DisassocReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC; - - pAd->IndicateMediaState = NdisMediaStateDisconnected; - RTMP_IndicateMediaState(pAd); - pAd->ExtraInfo = GENERAL_LINK_DOWN; - } - } -} - -/* IRQL = DISPATCH_LEVEL */ -void MlmeAutoScan(struct rt_rtmp_adapter *pAd) -{ - /* check CntlMachine.CurrState to avoid collision with NDIS SetOID request */ - if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) { - DBGPRINT(RT_DEBUG_TRACE, ("MMCHK - Driver auto scan\n")); - MlmeEnqueue(pAd, - MLME_CNTL_STATE_MACHINE, - OID_802_11_BSSID_LIST_SCAN, - pAd->MlmeAux.AutoReconnectSsidLen, - pAd->MlmeAux.AutoReconnectSsid); - RTMP_MLME_HANDLER(pAd); - } -} - -/* IRQL = DISPATCH_LEVEL */ -void MlmeAutoReconnectLastSSID(struct rt_rtmp_adapter *pAd) -{ - if (pAd->StaCfg.bAutoConnectByBssid) { - DBGPRINT(RT_DEBUG_TRACE, - ("Driver auto reconnect to last OID_802_11_BSSID " - "setting - %pM\n", pAd->MlmeAux.Bssid)); - - pAd->MlmeAux.Channel = pAd->CommonCfg.Channel; - MlmeEnqueue(pAd, - MLME_CNTL_STATE_MACHINE, - OID_802_11_BSSID, MAC_ADDR_LEN, pAd->MlmeAux.Bssid); - - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - - RTMP_MLME_HANDLER(pAd); - } - /* check CntlMachine.CurrState to avoid collision with NDIS SetOID request */ - else if ((pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) && - (MlmeValidateSSID - (pAd->MlmeAux.AutoReconnectSsid, - pAd->MlmeAux.AutoReconnectSsidLen) == TRUE)) { - struct rt_ndis_802_11_ssid OidSsid; - OidSsid.SsidLength = pAd->MlmeAux.AutoReconnectSsidLen; - NdisMoveMemory(OidSsid.Ssid, pAd->MlmeAux.AutoReconnectSsid, - pAd->MlmeAux.AutoReconnectSsidLen); - - DBGPRINT(RT_DEBUG_TRACE, - ("Driver auto reconnect to last OID_802_11_SSID setting - %s, len - %d\n", - pAd->MlmeAux.AutoReconnectSsid, - pAd->MlmeAux.AutoReconnectSsidLen)); - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, OID_802_11_SSID, - sizeof(struct rt_ndis_802_11_ssid), &OidSsid); - RTMP_MLME_HANDLER(pAd); - } -} - -/* - ========================================================================== - Description: - This routine checks if there're other APs out there capable for - roaming. Caller should call this routine only when Link up in INFRA mode - and channel quality is below CQI_GOOD_THRESHOLD. - - IRQL = DISPATCH_LEVEL - - Output: - ========================================================================== - */ -void MlmeCheckForRoaming(struct rt_rtmp_adapter *pAd, unsigned long Now32) -{ - u16 i; - struct rt_bss_table *pRoamTab = &pAd->MlmeAux.RoamTab; - struct rt_bss_entry *pBss; - - DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeCheckForRoaming\n")); - /* put all roaming candidates into RoamTab, and sort in RSSI order */ - BssTableInit(pRoamTab); - for (i = 0; i < pAd->ScanTab.BssNr; i++) { - pBss = &pAd->ScanTab.BssEntry[i]; - - if ((pBss->LastBeaconRxTime + pAd->StaCfg.BeaconLostTime) < - Now32) - continue; /* AP disappear */ - if (pBss->Rssi <= RSSI_THRESHOLD_FOR_ROAMING) - continue; /* RSSI too weak. forget it. */ - if (MAC_ADDR_EQUAL(pBss->Bssid, pAd->CommonCfg.Bssid)) - continue; /* skip current AP */ - if (pBss->Rssi < - (pAd->StaCfg.RssiSample.LastRssi0 + RSSI_DELTA)) - continue; /* only AP with stronger RSSI is eligible for roaming */ - - /* AP passing all above rules is put into roaming candidate table */ - NdisMoveMemory(&pRoamTab->BssEntry[pRoamTab->BssNr], pBss, - sizeof(struct rt_bss_entry)); - pRoamTab->BssNr += 1; - } - - if (pRoamTab->BssNr > 0) { - /* check CntlMachine.CurrState to avoid collision with NDIS SetOID request */ - if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) { - pAd->RalinkCounters.PoorCQIRoamingCount++; - DBGPRINT(RT_DEBUG_TRACE, - ("MMCHK - Roaming attempt #%ld\n", - pAd->RalinkCounters.PoorCQIRoamingCount)); - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, - MT2_MLME_ROAMING_REQ, 0, NULL); - RTMP_MLME_HANDLER(pAd); - } - } - DBGPRINT(RT_DEBUG_TRACE, - ("<== MlmeCheckForRoaming(# of candidate= %d)\n", - pRoamTab->BssNr)); -} - -/* - ========================================================================== - Description: - This routine checks if there're other APs out there capable for - roaming. Caller should call this routine only when link up in INFRA mode - and channel quality is below CQI_GOOD_THRESHOLD. - - IRQL = DISPATCH_LEVEL - - Output: - ========================================================================== - */ -BOOLEAN MlmeCheckForFastRoaming(struct rt_rtmp_adapter *pAd) -{ - u16 i; - struct rt_bss_table *pRoamTab = &pAd->MlmeAux.RoamTab; - struct rt_bss_entry *pBss; - - DBGPRINT(RT_DEBUG_TRACE, ("==> MlmeCheckForFastRoaming\n")); - /* put all roaming candidates into RoamTab, and sort in RSSI order */ - BssTableInit(pRoamTab); - for (i = 0; i < pAd->ScanTab.BssNr; i++) { - pBss = &pAd->ScanTab.BssEntry[i]; - - if ((pBss->Rssi <= -50) - && (pBss->Channel == pAd->CommonCfg.Channel)) - continue; /* RSSI too weak. forget it. */ - if (MAC_ADDR_EQUAL(pBss->Bssid, pAd->CommonCfg.Bssid)) - continue; /* skip current AP */ - if (!SSID_EQUAL - (pBss->Ssid, pBss->SsidLen, pAd->CommonCfg.Ssid, - pAd->CommonCfg.SsidLen)) - continue; /* skip different SSID */ - if (pBss->Rssi < - (RTMPMaxRssi - (pAd, pAd->StaCfg.RssiSample.LastRssi0, - pAd->StaCfg.RssiSample.LastRssi1, - pAd->StaCfg.RssiSample.LastRssi2) + RSSI_DELTA)) - continue; /* skip AP without better RSSI */ - - DBGPRINT(RT_DEBUG_TRACE, - ("LastRssi0 = %d, pBss->Rssi = %d\n", - RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, - pAd->StaCfg.RssiSample.LastRssi1, - pAd->StaCfg.RssiSample.LastRssi2), - pBss->Rssi)); - /* AP passing all above rules is put into roaming candidate table */ - NdisMoveMemory(&pRoamTab->BssEntry[pRoamTab->BssNr], pBss, - sizeof(struct rt_bss_entry)); - pRoamTab->BssNr += 1; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("<== MlmeCheckForFastRoaming (BssNr=%d)\n", pRoamTab->BssNr)); - if (pRoamTab->BssNr > 0) { - /* check CntlMachine.CurrState to avoid collision with NDIS SetOID request */ - if (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) { - pAd->RalinkCounters.PoorCQIRoamingCount++; - DBGPRINT(RT_DEBUG_TRACE, - ("MMCHK - Roaming attempt #%ld\n", - pAd->RalinkCounters.PoorCQIRoamingCount)); - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, - MT2_MLME_ROAMING_REQ, 0, NULL); - RTMP_MLME_HANDLER(pAd); - return TRUE; - } - } - - return FALSE; -} - -void MlmeSetTxRate(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_rtmp_tx_rate_switch * pTxRate) -{ - u8 MaxMode = MODE_OFDM; - - MaxMode = MODE_HTGREENFIELD; - - if (pTxRate->STBC && (pAd->StaCfg.MaxHTPhyMode.field.STBC) - && (pAd->Antenna.field.TxPath == 2)) - pAd->StaCfg.HTPhyMode.field.STBC = STBC_USE; - else - pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE; - - if (pTxRate->CurrMCS < MCS_AUTO) - pAd->StaCfg.HTPhyMode.field.MCS = pTxRate->CurrMCS; - - if (pAd->StaCfg.HTPhyMode.field.MCS > 7) - pAd->StaCfg.HTPhyMode.field.STBC = STBC_NONE; - - if (ADHOC_ON(pAd)) { - /* If peer adhoc is b-only mode, we can't send 11g rate. */ - pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800; - pEntry->HTPhyMode.field.STBC = STBC_NONE; - - /* */ - /* For Adhoc MODE_CCK, driver will use AdhocBOnlyJoined flag to roll back to B only if necessary */ - /* */ - pEntry->HTPhyMode.field.MODE = pTxRate->Mode; - pEntry->HTPhyMode.field.ShortGI = - pAd->StaCfg.HTPhyMode.field.ShortGI; - pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS; - - /* Patch speed error in status page */ - pAd->StaCfg.HTPhyMode.field.MODE = pEntry->HTPhyMode.field.MODE; - } else { - if (pTxRate->Mode <= MaxMode) - pAd->StaCfg.HTPhyMode.field.MODE = pTxRate->Mode; - - if (pTxRate->ShortGI - && (pAd->StaCfg.MaxHTPhyMode.field.ShortGI)) - pAd->StaCfg.HTPhyMode.field.ShortGI = GI_400; - else - pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800; - - /* Reexam each bandwidth's SGI support. */ - if (pAd->StaCfg.HTPhyMode.field.ShortGI == GI_400) { - if ((pEntry->HTPhyMode.field.BW == BW_20) - && - (!CLIENT_STATUS_TEST_FLAG - (pEntry, fCLIENT_STATUS_SGI20_CAPABLE))) - pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800; - if ((pEntry->HTPhyMode.field.BW == BW_40) - && - (!CLIENT_STATUS_TEST_FLAG - (pEntry, fCLIENT_STATUS_SGI40_CAPABLE))) - pAd->StaCfg.HTPhyMode.field.ShortGI = GI_800; - } - /* Turn RTS/CTS rate to 6Mbps. */ - if ((pEntry->HTPhyMode.field.MCS == 0) - && (pAd->StaCfg.HTPhyMode.field.MCS != 0)) { - pEntry->HTPhyMode.field.MCS = - pAd->StaCfg.HTPhyMode.field.MCS; - if (pAd->MacTab.fAnyBASession) { - AsicUpdateProtect(pAd, HT_FORCERTSCTS, - ALLN_SETPROTECT, TRUE, - (BOOLEAN) pAd->MlmeAux. - AddHtInfo.AddHtInfo2. - NonGfPresent); - } else { - AsicUpdateProtect(pAd, - pAd->MlmeAux.AddHtInfo. - AddHtInfo2.OperaionMode, - ALLN_SETPROTECT, TRUE, - (BOOLEAN) pAd->MlmeAux. - AddHtInfo.AddHtInfo2. - NonGfPresent); - } - } else if ((pEntry->HTPhyMode.field.MCS == 8) - && (pAd->StaCfg.HTPhyMode.field.MCS != 8)) { - pEntry->HTPhyMode.field.MCS = - pAd->StaCfg.HTPhyMode.field.MCS; - if (pAd->MacTab.fAnyBASession) { - AsicUpdateProtect(pAd, HT_FORCERTSCTS, - ALLN_SETPROTECT, TRUE, - (BOOLEAN) pAd->MlmeAux. - AddHtInfo.AddHtInfo2. - NonGfPresent); - } else { - AsicUpdateProtect(pAd, - pAd->MlmeAux.AddHtInfo. - AddHtInfo2.OperaionMode, - ALLN_SETPROTECT, TRUE, - (BOOLEAN) pAd->MlmeAux. - AddHtInfo.AddHtInfo2. - NonGfPresent); - } - } else if ((pEntry->HTPhyMode.field.MCS != 0) - && (pAd->StaCfg.HTPhyMode.field.MCS == 0)) { - AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT, - TRUE, - (BOOLEAN) pAd->MlmeAux.AddHtInfo. - AddHtInfo2.NonGfPresent); - - } else if ((pEntry->HTPhyMode.field.MCS != 8) - && (pAd->StaCfg.HTPhyMode.field.MCS == 8)) { - AsicUpdateProtect(pAd, HT_RTSCTS_6M, ALLN_SETPROTECT, - TRUE, - (BOOLEAN) pAd->MlmeAux.AddHtInfo. - AddHtInfo2.NonGfPresent); - } - - pEntry->HTPhyMode.field.STBC = pAd->StaCfg.HTPhyMode.field.STBC; - pEntry->HTPhyMode.field.ShortGI = - pAd->StaCfg.HTPhyMode.field.ShortGI; - pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS; - pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE; - if ((pAd->StaCfg.MaxHTPhyMode.field.MODE == MODE_HTGREENFIELD) - && pAd->WIFItestbed.bGreenField) - pEntry->HTPhyMode.field.MODE = MODE_HTGREENFIELD; - } - - pAd->LastTxRate = (u16)(pEntry->HTPhyMode.word); -} - -/* - ========================================================================== - Description: - This routine calculates the acumulated TxPER of eaxh TxRate. And - according to the calculation result, change CommonCfg.TxRate which - is the stable TX Rate we expect the Radio situation could sustained. - - CommonCfg.TxRate will change dynamically within {RATE_1/RATE_6, MaxTxRate} - Output: - CommonCfg.TxRate - - - IRQL = DISPATCH_LEVEL - - NOTE: - call this routine every second - ========================================================================== - */ -void MlmeDynamicTxRateSwitching(struct rt_rtmp_adapter *pAd) -{ - u8 UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx; - unsigned long i, AccuTxTotalCnt = 0, TxTotalCnt; - unsigned long TxErrorRatio = 0; - BOOLEAN bTxRateChanged = FALSE, bUpgradeQuality = FALSE; - struct rt_rtmp_tx_rate_switch *pCurrTxRate, *pNextTxRate = NULL; - u8 *pTable; - u8 TableSize = 0; - u8 InitTxRateIdx = 0, TrainUp, TrainDown; - char Rssi, RssiOffset = 0; - TX_STA_CNT1_STRUC StaTx1; - TX_STA_CNT0_STRUC TxStaCnt0; - unsigned long TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0; - struct rt_mac_table_entry *pEntry; - struct rt_rssi_sample *pRssi = &pAd->StaCfg.RssiSample; - - /* */ - /* walk through MAC table, see if need to change AP's TX rate toward each entry */ - /* */ - for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) { - pEntry = &pAd->MacTab.Content[i]; - - /* check if this entry need to switch rate automatically */ - if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE) - continue; - - if ((pAd->MacTab.Size == 1) || (pEntry->ValidAsDls)) { - Rssi = RTMPMaxRssi(pAd, - pRssi->AvgRssi0, - pRssi->AvgRssi1, pRssi->AvgRssi2); - - /* Update statistic counter */ - RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word); - RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word); - pAd->bUpdateBcnCntDone = TRUE; - TxRetransmit = StaTx1.field.TxRetransmit; - TxSuccess = StaTx1.field.TxSuccess; - TxFailCount = TxStaCnt0.field.TxFailCount; - TxTotalCnt = TxRetransmit + TxSuccess + TxFailCount; - - pAd->RalinkCounters.OneSecTxRetryOkCount += - StaTx1.field.TxRetransmit; - pAd->RalinkCounters.OneSecTxNoRetryOkCount += - StaTx1.field.TxSuccess; - pAd->RalinkCounters.OneSecTxFailCount += - TxStaCnt0.field.TxFailCount; - pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += - StaTx1.field.TxSuccess; - pAd->WlanCounters.RetryCount.u.LowPart += - StaTx1.field.TxRetransmit; - pAd->WlanCounters.FailedCount.u.LowPart += - TxStaCnt0.field.TxFailCount; - - /* if no traffic in the past 1-sec period, don't change TX rate, */ - /* but clear all bad history. because the bad history may affect the next */ - /* Chariot throughput test */ - AccuTxTotalCnt = - pAd->RalinkCounters.OneSecTxNoRetryOkCount + - pAd->RalinkCounters.OneSecTxRetryOkCount + - pAd->RalinkCounters.OneSecTxFailCount; - - if (TxTotalCnt) - TxErrorRatio = - ((TxRetransmit + - TxFailCount) * 100) / TxTotalCnt; - } else { - if (INFRA_ON(pAd) && (i == 1)) - Rssi = RTMPMaxRssi(pAd, - pRssi->AvgRssi0, - pRssi->AvgRssi1, - pRssi->AvgRssi2); - else - Rssi = RTMPMaxRssi(pAd, - pEntry->RssiSample.AvgRssi0, - pEntry->RssiSample.AvgRssi1, - pEntry->RssiSample.AvgRssi2); - - TxTotalCnt = pEntry->OneSecTxNoRetryOkCount + - pEntry->OneSecTxRetryOkCount + - pEntry->OneSecTxFailCount; - - if (TxTotalCnt) - TxErrorRatio = - ((pEntry->OneSecTxRetryOkCount + - pEntry->OneSecTxFailCount) * 100) / - TxTotalCnt; - } - - if (TxTotalCnt) { - /* - Three AdHoc connections can not work normally if one AdHoc connection is disappeared from a heavy traffic environment generated by ping tool - We force to set LongRtyLimit and ShortRtyLimit to 0 to stop retransmitting packet, after a while, resoring original settings - */ - if (TxErrorRatio == 100) { - TX_RTY_CFG_STRUC TxRtyCfg, TxRtyCfgtmp; - unsigned long Index; - unsigned long MACValue; - - RTMP_IO_READ32(pAd, TX_RTY_CFG, &TxRtyCfg.word); - TxRtyCfgtmp.word = TxRtyCfg.word; - TxRtyCfg.field.LongRtyLimit = 0x0; - TxRtyCfg.field.ShortRtyLimit = 0x0; - RTMP_IO_WRITE32(pAd, TX_RTY_CFG, TxRtyCfg.word); - - RTMPusecDelay(1); - - Index = 0; - MACValue = 0; - do { - RTMP_IO_READ32(pAd, TXRXQ_PCNT, - &MACValue); - if ((MACValue & 0xffffff) == 0) - break; - Index++; - RTMPusecDelay(1000); - } while ((Index < 330) - && - (!RTMP_TEST_FLAG - (pAd, - fRTMP_ADAPTER_HALT_IN_PROGRESS))); - - RTMP_IO_READ32(pAd, TX_RTY_CFG, &TxRtyCfg.word); - TxRtyCfg.field.LongRtyLimit = - TxRtyCfgtmp.field.LongRtyLimit; - TxRtyCfg.field.ShortRtyLimit = - TxRtyCfgtmp.field.ShortRtyLimit; - RTMP_IO_WRITE32(pAd, TX_RTY_CFG, TxRtyCfg.word); - } - } - - CurrRateIdx = pEntry->CurrTxRateIndex; - - MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, - &InitTxRateIdx); - - if (CurrRateIdx >= TableSize) { - CurrRateIdx = TableSize - 1; - } - /* When switch from Fixed rate -> auto rate, the REAL TX rate might be different from pAd->CommonCfg.TxRateIndex. */ - /* So need to sync here. */ - pCurrTxRate = - (struct rt_rtmp_tx_rate_switch *) & pTable[(CurrRateIdx + 1) * 5]; - if ((pEntry->HTPhyMode.field.MCS != pCurrTxRate->CurrMCS) - /*&& (pAd->StaCfg.bAutoTxRateSwitch == TRUE) */ - ) { - - /* Need to sync Real Tx rate and our record. */ - /* Then return for next DRS. */ - pCurrTxRate = - (struct rt_rtmp_tx_rate_switch *) & pTable[(InitTxRateIdx + 1) - * 5]; - pEntry->CurrTxRateIndex = InitTxRateIdx; - MlmeSetTxRate(pAd, pEntry, pCurrTxRate); - - /* reset all OneSecTx counters */ - RESET_ONE_SEC_TX_CNT(pEntry); - continue; - } - /* decide the next upgrade rate and downgrade rate, if any */ - if ((CurrRateIdx > 0) && (CurrRateIdx < (TableSize - 1))) { - UpRateIdx = CurrRateIdx + 1; - DownRateIdx = CurrRateIdx - 1; - } else if (CurrRateIdx == 0) { - UpRateIdx = CurrRateIdx + 1; - DownRateIdx = CurrRateIdx; - } else if (CurrRateIdx == (TableSize - 1)) { - UpRateIdx = CurrRateIdx; - DownRateIdx = CurrRateIdx - 1; - } - - pCurrTxRate = - (struct rt_rtmp_tx_rate_switch *) & pTable[(CurrRateIdx + 1) * 5]; - - if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX)) { - TrainUp = - (pCurrTxRate->TrainUp + - (pCurrTxRate->TrainUp >> 1)); - TrainDown = - (pCurrTxRate->TrainDown + - (pCurrTxRate->TrainDown >> 1)); - } else { - TrainUp = pCurrTxRate->TrainUp; - TrainDown = pCurrTxRate->TrainDown; - } - - /*pAd->DrsCounters.LastTimeTxRateChangeAction = pAd->DrsCounters.LastSecTxRateChangeAction; */ - - /* */ - /* Keep the last time TxRateChangeAction status. */ - /* */ - pEntry->LastTimeTxRateChangeAction = - pEntry->LastSecTxRateChangeAction; - - /* */ - /* CASE 1. when TX samples are fewer than 15, then decide TX rate solely on RSSI */ - /* (criteria copied from RT2500 for Netopia case) */ - /* */ - if (TxTotalCnt <= 15) { - char idx = 0; - u8 TxRateIdx; - u8 MCS0 = 0, MCS1 = 0, MCS2 = 0, MCS3 = 0, MCS4 = - 0, MCS5 = 0, MCS6 = 0, MCS7 = 0; - u8 MCS12 = 0, MCS13 = 0, MCS14 = 0, MCS15 = 0; - u8 MCS20 = 0, MCS21 = 0, MCS22 = 0, MCS23 = 0; /* 3*3 */ - - /* check the existence and index of each needed MCS */ - while (idx < pTable[0]) { - pCurrTxRate = - (struct rt_rtmp_tx_rate_switch *) & pTable[(idx + 1) * - 5]; - - if (pCurrTxRate->CurrMCS == MCS_0) { - MCS0 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_1) { - MCS1 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_2) { - MCS2 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_3) { - MCS3 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_4) { - MCS4 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_5) { - MCS5 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_6) { - MCS6 = idx; - } - /*else if (pCurrTxRate->CurrMCS == MCS_7) */ - else if ((pCurrTxRate->CurrMCS == MCS_7) && (pCurrTxRate->ShortGI == GI_800)) /* prevent the highest MCS using short GI when 1T and low throughput */ - { - MCS7 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_12) { - MCS12 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_13) { - MCS13 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_14) { - MCS14 = idx; - } - else if ((pCurrTxRate->CurrMCS == MCS_15) && (pCurrTxRate->ShortGI == GI_800)) /*we hope to use ShortGI as initial rate, however Atheros's chip has bugs when short GI */ - { - MCS15 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_20) /* 3*3 */ - { - MCS20 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_21) { - MCS21 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_22) { - MCS22 = idx; - } else if (pCurrTxRate->CurrMCS == MCS_23) { - MCS23 = idx; - } - idx++; - } - - if (pAd->LatchRfRegs.Channel <= 14) { - if (pAd->NicConfig2.field.ExternalLNAForG) { - RssiOffset = 2; - } else { - RssiOffset = 5; - } - } else { - if (pAd->NicConfig2.field.ExternalLNAForA) { - RssiOffset = 5; - } else { - RssiOffset = 8; - } - } - - /*if (MCS15) */ - if ((pTable == RateSwitchTable11BGN3S) || (pTable == RateSwitchTable11N3S) || (pTable == RateSwitchTable)) { /* N mode with 3 stream // 3*3 */ - if (MCS23 && (Rssi >= -70)) - TxRateIdx = MCS23; - else if (MCS22 && (Rssi >= -72)) - TxRateIdx = MCS22; - else if (MCS21 && (Rssi >= -76)) - TxRateIdx = MCS21; - else if (MCS20 && (Rssi >= -78)) - TxRateIdx = MCS20; - else if (MCS4 && (Rssi >= -82)) - TxRateIdx = MCS4; - else if (MCS3 && (Rssi >= -84)) - TxRateIdx = MCS3; - else if (MCS2 && (Rssi >= -86)) - TxRateIdx = MCS2; - else if (MCS1 && (Rssi >= -88)) - TxRateIdx = MCS1; - else - TxRateIdx = MCS0; - } -/* else if ((pTable == RateSwitchTable11BGN2S) || (pTable == RateSwitchTable11BGN2SForABand) ||(pTable == RateSwitchTable11N2S) ||(pTable == RateSwitchTable11N2SForABand) || (pTable == RateSwitchTable)) */ - else if ((pTable == RateSwitchTable11BGN2S) || (pTable == RateSwitchTable11BGN2SForABand) || (pTable == RateSwitchTable11N2S) || (pTable == RateSwitchTable11N2SForABand)) /* 3*3 */ - { /* N mode with 2 stream */ - if (MCS15 && (Rssi >= (-70 + RssiOffset))) - TxRateIdx = MCS15; - else if (MCS14 && (Rssi >= (-72 + RssiOffset))) - TxRateIdx = MCS14; - else if (MCS13 && (Rssi >= (-76 + RssiOffset))) - TxRateIdx = MCS13; - else if (MCS12 && (Rssi >= (-78 + RssiOffset))) - TxRateIdx = MCS12; - else if (MCS4 && (Rssi >= (-82 + RssiOffset))) - TxRateIdx = MCS4; - else if (MCS3 && (Rssi >= (-84 + RssiOffset))) - TxRateIdx = MCS3; - else if (MCS2 && (Rssi >= (-86 + RssiOffset))) - TxRateIdx = MCS2; - else if (MCS1 && (Rssi >= (-88 + RssiOffset))) - TxRateIdx = MCS1; - else - TxRateIdx = MCS0; - } else if ((pTable == RateSwitchTable11BGN1S) || (pTable == RateSwitchTable11N1S)) { /* N mode with 1 stream */ - if (MCS7 && (Rssi > (-72 + RssiOffset))) - TxRateIdx = MCS7; - else if (MCS6 && (Rssi > (-74 + RssiOffset))) - TxRateIdx = MCS6; - else if (MCS5 && (Rssi > (-77 + RssiOffset))) - TxRateIdx = MCS5; - else if (MCS4 && (Rssi > (-79 + RssiOffset))) - TxRateIdx = MCS4; - else if (MCS3 && (Rssi > (-81 + RssiOffset))) - TxRateIdx = MCS3; - else if (MCS2 && (Rssi > (-83 + RssiOffset))) - TxRateIdx = MCS2; - else if (MCS1 && (Rssi > (-86 + RssiOffset))) - TxRateIdx = MCS1; - else - TxRateIdx = MCS0; - } else { /* Legacy mode */ - if (MCS7 && (Rssi > -70)) - TxRateIdx = MCS7; - else if (MCS6 && (Rssi > -74)) - TxRateIdx = MCS6; - else if (MCS5 && (Rssi > -78)) - TxRateIdx = MCS5; - else if (MCS4 && (Rssi > -82)) - TxRateIdx = MCS4; - else if (MCS4 == 0) /* for B-only mode */ - TxRateIdx = MCS3; - else if (MCS3 && (Rssi > -85)) - TxRateIdx = MCS3; - else if (MCS2 && (Rssi > -87)) - TxRateIdx = MCS2; - else if (MCS1 && (Rssi > -90)) - TxRateIdx = MCS1; - else - TxRateIdx = MCS0; - } - - /* if (TxRateIdx != pAd->CommonCfg.TxRateIndex) */ - { - pEntry->CurrTxRateIndex = TxRateIdx; - pNextTxRate = - (struct rt_rtmp_tx_rate_switch *) & - pTable[(pEntry->CurrTxRateIndex + 1) * 5]; - MlmeSetTxRate(pAd, pEntry, pNextTxRate); - } - - NdisZeroMemory(pEntry->TxQuality, - sizeof(u16)* - MAX_STEP_OF_TX_RATE_SWITCH); - NdisZeroMemory(pEntry->PER, - sizeof(u8)* - MAX_STEP_OF_TX_RATE_SWITCH); - pEntry->fLastSecAccordingRSSI = TRUE; - /* reset all OneSecTx counters */ - RESET_ONE_SEC_TX_CNT(pEntry); - - continue; - } - - if (pEntry->fLastSecAccordingRSSI == TRUE) { - pEntry->fLastSecAccordingRSSI = FALSE; - pEntry->LastSecTxRateChangeAction = 0; - /* reset all OneSecTx counters */ - RESET_ONE_SEC_TX_CNT(pEntry); - - continue; - } - - do { - BOOLEAN bTrainUpDown = FALSE; - - pEntry->CurrTxRateStableTime++; - - /* downgrade TX quality if PER >= Rate-Down threshold */ - if (TxErrorRatio >= TrainDown) { - bTrainUpDown = TRUE; - pEntry->TxQuality[CurrRateIdx] = - DRS_TX_QUALITY_WORST_BOUND; - } - /* upgrade TX quality if PER <= Rate-Up threshold */ - else if (TxErrorRatio <= TrainUp) { - bTrainUpDown = TRUE; - bUpgradeQuality = TRUE; - if (pEntry->TxQuality[CurrRateIdx]) - pEntry->TxQuality[CurrRateIdx]--; /* quality very good in CurrRate */ - - if (pEntry->TxRateUpPenalty) - pEntry->TxRateUpPenalty--; - else if (pEntry->TxQuality[UpRateIdx]) - pEntry->TxQuality[UpRateIdx]--; /* may improve next UP rate's quality */ - } - - pEntry->PER[CurrRateIdx] = (u8)TxErrorRatio; - - if (bTrainUpDown) { - /* perform DRS - consider TxRate Down first, then rate up. */ - if ((CurrRateIdx != DownRateIdx) - && (pEntry->TxQuality[CurrRateIdx] >= - DRS_TX_QUALITY_WORST_BOUND)) { - pEntry->CurrTxRateIndex = DownRateIdx; - } else if ((CurrRateIdx != UpRateIdx) - && (pEntry->TxQuality[UpRateIdx] <= - 0)) { - pEntry->CurrTxRateIndex = UpRateIdx; - } - } - } while (FALSE); - - /* if rate-up happen, clear all bad history of all TX rates */ - if (pEntry->CurrTxRateIndex > CurrRateIdx) { - pEntry->CurrTxRateStableTime = 0; - pEntry->TxRateUpPenalty = 0; - pEntry->LastSecTxRateChangeAction = 1; /* rate UP */ - NdisZeroMemory(pEntry->TxQuality, - sizeof(u16)* - MAX_STEP_OF_TX_RATE_SWITCH); - NdisZeroMemory(pEntry->PER, - sizeof(u8)* - MAX_STEP_OF_TX_RATE_SWITCH); - - /* */ - /* For TxRate fast train up */ - /* */ - if (!pAd->StaCfg.StaQuickResponeForRateUpTimerRunning) { - RTMPSetTimer(&pAd->StaCfg. - StaQuickResponeForRateUpTimer, - 100); - - pAd->StaCfg. - StaQuickResponeForRateUpTimerRunning = TRUE; - } - bTxRateChanged = TRUE; - } - /* if rate-down happen, only clear DownRate's bad history */ - else if (pEntry->CurrTxRateIndex < CurrRateIdx) { - pEntry->CurrTxRateStableTime = 0; - pEntry->TxRateUpPenalty = 0; /* no penalty */ - pEntry->LastSecTxRateChangeAction = 2; /* rate DOWN */ - pEntry->TxQuality[pEntry->CurrTxRateIndex] = 0; - pEntry->PER[pEntry->CurrTxRateIndex] = 0; - - /* */ - /* For TxRate fast train down */ - /* */ - if (!pAd->StaCfg.StaQuickResponeForRateUpTimerRunning) { - RTMPSetTimer(&pAd->StaCfg. - StaQuickResponeForRateUpTimer, - 100); - - pAd->StaCfg. - StaQuickResponeForRateUpTimerRunning = TRUE; - } - bTxRateChanged = TRUE; - } else { - pEntry->LastSecTxRateChangeAction = 0; /* rate no change */ - bTxRateChanged = FALSE; - } - - pEntry->LastTxOkCount = TxSuccess; - { - u8 tmpTxRate; - - /* to fix tcp ack issue */ - if (!bTxRateChanged - && (pAd->RalinkCounters.OneSecReceivedByteCount > - (pAd->RalinkCounters. - OneSecTransmittedByteCount * 5))) { - tmpTxRate = DownRateIdx; - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("DRS: Rx(%d) is 5 times larger than Tx(%d), use low rate (curr=%d, tmp=%d)\n", - pAd->RalinkCounters. - OneSecReceivedByteCount, - pAd->RalinkCounters. - OneSecTransmittedByteCount, - pEntry->CurrTxRateIndex, - tmpTxRate)); - } else { - tmpTxRate = pEntry->CurrTxRateIndex; - } - - pNextTxRate = - (struct rt_rtmp_tx_rate_switch *) & pTable[(tmpTxRate + 1) * - 5]; - } - if (bTxRateChanged && pNextTxRate) { - MlmeSetTxRate(pAd, pEntry, pNextTxRate); - } - /* reset all OneSecTx counters */ - RESET_ONE_SEC_TX_CNT(pEntry); - } -} - -/* - ======================================================================== - Routine Description: - Station side, Auto TxRate faster train up timer call back function. - - Arguments: - SystemSpecific1 - Not used. - FunctionContext - Pointer to our Adapter context. - SystemSpecific2 - Not used. - SystemSpecific3 - Not used. - - Return Value: - None - - ======================================================================== -*/ -void StaQuickResponeForRateUpExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, - void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - u8 UpRateIdx = 0, DownRateIdx = 0, CurrRateIdx = 0; - unsigned long TxTotalCnt; - unsigned long TxErrorRatio = 0; - BOOLEAN bTxRateChanged; /*, bUpgradeQuality = FALSE; */ - struct rt_rtmp_tx_rate_switch *pCurrTxRate, *pNextTxRate = NULL; - u8 *pTable; - u8 TableSize = 0; - u8 InitTxRateIdx = 0, TrainUp, TrainDown; - TX_STA_CNT1_STRUC StaTx1; - TX_STA_CNT0_STRUC TxStaCnt0; - char Rssi, ratio; - unsigned long TxRetransmit = 0, TxSuccess = 0, TxFailCount = 0; - struct rt_mac_table_entry *pEntry; - unsigned long i; - - pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE; - - /* */ - /* walk through MAC table, see if need to change AP's TX rate toward each entry */ - /* */ - for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) { - pEntry = &pAd->MacTab.Content[i]; - - /* check if this entry need to switch rate automatically */ - if (RTMPCheckEntryEnableAutoRateSwitch(pAd, pEntry) == FALSE) - continue; - - if (INFRA_ON(pAd) && (i == 1)) - Rssi = RTMPMaxRssi(pAd, - pAd->StaCfg.RssiSample.AvgRssi0, - pAd->StaCfg.RssiSample.AvgRssi1, - pAd->StaCfg.RssiSample.AvgRssi2); - else - Rssi = RTMPMaxRssi(pAd, - pEntry->RssiSample.AvgRssi0, - pEntry->RssiSample.AvgRssi1, - pEntry->RssiSample.AvgRssi2); - - CurrRateIdx = pAd->CommonCfg.TxRateIndex; - - MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, - &InitTxRateIdx); - - /* decide the next upgrade rate and downgrade rate, if any */ - if ((CurrRateIdx > 0) && (CurrRateIdx < (TableSize - 1))) { - UpRateIdx = CurrRateIdx + 1; - DownRateIdx = CurrRateIdx - 1; - } else if (CurrRateIdx == 0) { - UpRateIdx = CurrRateIdx + 1; - DownRateIdx = CurrRateIdx; - } else if (CurrRateIdx == (TableSize - 1)) { - UpRateIdx = CurrRateIdx; - DownRateIdx = CurrRateIdx - 1; - } - - pCurrTxRate = - (struct rt_rtmp_tx_rate_switch *) & pTable[(CurrRateIdx + 1) * 5]; - - if ((Rssi > -65) && (pCurrTxRate->Mode >= MODE_HTMIX)) { - TrainUp = - (pCurrTxRate->TrainUp + - (pCurrTxRate->TrainUp >> 1)); - TrainDown = - (pCurrTxRate->TrainDown + - (pCurrTxRate->TrainDown >> 1)); - } else { - TrainUp = pCurrTxRate->TrainUp; - TrainDown = pCurrTxRate->TrainDown; - } - - if (pAd->MacTab.Size == 1) { - /* Update statistic counter */ - RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word); - RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word); - - TxRetransmit = StaTx1.field.TxRetransmit; - TxSuccess = StaTx1.field.TxSuccess; - TxFailCount = TxStaCnt0.field.TxFailCount; - TxTotalCnt = TxRetransmit + TxSuccess + TxFailCount; - - pAd->RalinkCounters.OneSecTxRetryOkCount += - StaTx1.field.TxRetransmit; - pAd->RalinkCounters.OneSecTxNoRetryOkCount += - StaTx1.field.TxSuccess; - pAd->RalinkCounters.OneSecTxFailCount += - TxStaCnt0.field.TxFailCount; - pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += - StaTx1.field.TxSuccess; - pAd->WlanCounters.RetryCount.u.LowPart += - StaTx1.field.TxRetransmit; - pAd->WlanCounters.FailedCount.u.LowPart += - TxStaCnt0.field.TxFailCount; - - if (TxTotalCnt) - TxErrorRatio = - ((TxRetransmit + - TxFailCount) * 100) / TxTotalCnt; - } else { - TxTotalCnt = pEntry->OneSecTxNoRetryOkCount + - pEntry->OneSecTxRetryOkCount + - pEntry->OneSecTxFailCount; - - if (TxTotalCnt) - TxErrorRatio = - ((pEntry->OneSecTxRetryOkCount + - pEntry->OneSecTxFailCount) * 100) / - TxTotalCnt; - } - - /* */ - /* CASE 1. when TX samples are fewer than 15, then decide TX rate solely on RSSI */ - /* (criteria copied from RT2500 for Netopia case) */ - /* */ - if (TxTotalCnt <= 12) { - NdisZeroMemory(pAd->DrsCounters.TxQuality, - sizeof(u16)* - MAX_STEP_OF_TX_RATE_SWITCH); - NdisZeroMemory(pAd->DrsCounters.PER, - sizeof(u8)* - MAX_STEP_OF_TX_RATE_SWITCH); - - if ((pAd->DrsCounters.LastSecTxRateChangeAction == 1) - && (CurrRateIdx != DownRateIdx)) { - pAd->CommonCfg.TxRateIndex = DownRateIdx; - pAd->DrsCounters.TxQuality[CurrRateIdx] = - DRS_TX_QUALITY_WORST_BOUND; - } else - if ((pAd->DrsCounters.LastSecTxRateChangeAction == - 2) && (CurrRateIdx != UpRateIdx)) { - pAd->CommonCfg.TxRateIndex = UpRateIdx; - } - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("QuickDRS: TxTotalCnt <= 15, train back to original rate \n")); - return; - } - - do { - unsigned long OneSecTxNoRetryOKRationCount; - - if (pAd->DrsCounters.LastTimeTxRateChangeAction == 0) - ratio = 5; - else - ratio = 4; - - /* downgrade TX quality if PER >= Rate-Down threshold */ - if (TxErrorRatio >= TrainDown) { - pAd->DrsCounters.TxQuality[CurrRateIdx] = - DRS_TX_QUALITY_WORST_BOUND; - } - - pAd->DrsCounters.PER[CurrRateIdx] = - (u8)TxErrorRatio; - - OneSecTxNoRetryOKRationCount = (TxSuccess * ratio); - - /* perform DRS - consider TxRate Down first, then rate up. */ - if ((pAd->DrsCounters.LastSecTxRateChangeAction == 1) - && (CurrRateIdx != DownRateIdx)) { - if ((pAd->DrsCounters.LastTxOkCount + 2) >= - OneSecTxNoRetryOKRationCount) { - pAd->CommonCfg.TxRateIndex = - DownRateIdx; - pAd->DrsCounters. - TxQuality[CurrRateIdx] = - DRS_TX_QUALITY_WORST_BOUND; - - } - - } else - if ((pAd->DrsCounters.LastSecTxRateChangeAction == - 2) && (CurrRateIdx != UpRateIdx)) { - if ((TxErrorRatio >= 50) - || (TxErrorRatio >= TrainDown)) { - - } else if ((pAd->DrsCounters.LastTxOkCount + 2) - >= OneSecTxNoRetryOKRationCount) { - pAd->CommonCfg.TxRateIndex = UpRateIdx; - } - } - } while (FALSE); - - /* if rate-up happen, clear all bad history of all TX rates */ - if (pAd->CommonCfg.TxRateIndex > CurrRateIdx) { - pAd->DrsCounters.TxRateUpPenalty = 0; - NdisZeroMemory(pAd->DrsCounters.TxQuality, - sizeof(u16)* - MAX_STEP_OF_TX_RATE_SWITCH); - NdisZeroMemory(pAd->DrsCounters.PER, - sizeof(u8)* - MAX_STEP_OF_TX_RATE_SWITCH); - bTxRateChanged = TRUE; - } - /* if rate-down happen, only clear DownRate's bad history */ - else if (pAd->CommonCfg.TxRateIndex < CurrRateIdx) { - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("QuickDRS: --TX rate from %d to %d \n", - CurrRateIdx, pAd->CommonCfg.TxRateIndex)); - - pAd->DrsCounters.TxRateUpPenalty = 0; /* no penalty */ - pAd->DrsCounters.TxQuality[pAd->CommonCfg.TxRateIndex] = - 0; - pAd->DrsCounters.PER[pAd->CommonCfg.TxRateIndex] = 0; - bTxRateChanged = TRUE; - } else { - bTxRateChanged = FALSE; - } - - pNextTxRate = - (struct rt_rtmp_tx_rate_switch *) & - pTable[(pAd->CommonCfg.TxRateIndex + 1) * 5]; - if (bTxRateChanged && pNextTxRate) { - MlmeSetTxRate(pAd, pEntry, pNextTxRate); - } - } -} - -/* - ========================================================================== - Description: - This routine is executed periodically inside MlmePeriodicExec() after - association with an AP. - It checks if StaCfg.Psm is consistent with user policy (recorded in - StaCfg.WindowsPowerMode). If not, enforce user policy. However, - there're some conditions to consider: - 1. we don't support power-saving in ADHOC mode, so Psm=PWR_ACTIVE all - the time when Mibss==TRUE - 2. When link up in INFRA mode, Psm should not be switch to PWR_SAVE - if outgoing traffic available in TxRing or MgmtRing. - Output: - 1. change pAd->StaCfg.Psm to PWR_SAVE or leave it untouched - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void MlmeCheckPsmChange(struct rt_rtmp_adapter *pAd, unsigned long Now32) -{ - unsigned long PowerMode; - - /* condition - */ - /* 1. Psm maybe ON only happen in INFRASTRUCTURE mode */ - /* 2. user wants either MAX_PSP or FAST_PSP */ - /* 3. but current psm is not in PWR_SAVE */ - /* 4. CNTL state machine is not doing SCANning */ - /* 5. no TX SUCCESS event for the past 1-sec period */ - PowerMode = pAd->StaCfg.WindowsPowerMode; - - if (INFRA_ON(pAd) && - (PowerMode != Ndis802_11PowerModeCAM) && - (pAd->StaCfg.Psm == PWR_ACTIVE) && -/* (! RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) */ - (pAd->Mlme.CntlMachine.CurrState == CNTL_IDLE) && - RTMP_TEST_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP) - /*&& - (pAd->RalinkCounters.OneSecTxNoRetryOkCount == 0) && - (pAd->RalinkCounters.OneSecTxRetryOkCount == 0) */ - ) { - NdisGetSystemUpTime(&pAd->Mlme.LastSendNULLpsmTime); - pAd->RalinkCounters.RxCountSinceLastNULL = 0; - RTMP_SET_PSM_BIT(pAd, PWR_SAVE); - if (! - (pAd->CommonCfg.bAPSDCapable - && pAd->CommonCfg.APEdcaParm.bAPSDCapable)) { - RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, FALSE); - } else { - RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE); - } - } -} - -/* IRQL = PASSIVE_LEVEL */ -/* IRQL = DISPATCH_LEVEL */ -void MlmeSetPsmBit(struct rt_rtmp_adapter *pAd, u16 psm) -{ - AUTO_RSP_CFG_STRUC csr4; - - pAd->StaCfg.Psm = psm; - RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word); - csr4.field.AckCtsPsmBit = (psm == PWR_SAVE) ? 1 : 0; - RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word); - - DBGPRINT(RT_DEBUG_TRACE, ("MlmeSetPsmBit = %d\n", psm)); -} - -/* - ========================================================================== - Description: - This routine calculates TxPER, RxPER of the past N-sec period. And - according to the calculation result, ChannelQuality is calculated here - to decide if current AP is still doing the job. - - If ChannelQuality is not good, a ROAMing attempt may be tried later. - Output: - StaCfg.ChannelQuality - 0..100 - - IRQL = DISPATCH_LEVEL - - NOTE: This routine decide channle quality based on RX CRC error ratio. - Caller should make sure a function call to NICUpdateRawCounters(pAd) - is performed right before this routine, so that this routine can decide - channel quality based on the most up-to-date information - ========================================================================== - */ -void MlmeCalculateChannelQuality(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pMacEntry, unsigned long Now32) -{ - unsigned long TxOkCnt, TxCnt, TxPER, TxPRR; - unsigned long RxCnt, RxPER; - u8 NorRssi; - char MaxRssi; - struct rt_rssi_sample *pRssiSample = NULL; - u32 OneSecTxNoRetryOkCount = 0; - u32 OneSecTxRetryOkCount = 0; - u32 OneSecTxFailCount = 0; - u32 OneSecRxOkCnt = 0; - u32 OneSecRxFcsErrCnt = 0; - unsigned long ChannelQuality = 0; /* 0..100, Channel Quality Indication for Roaming */ - unsigned long BeaconLostTime = pAd->StaCfg.BeaconLostTime; - - if (pAd->OpMode == OPMODE_STA) { - pRssiSample = &pAd->StaCfg.RssiSample; - OneSecTxNoRetryOkCount = - pAd->RalinkCounters.OneSecTxNoRetryOkCount; - OneSecTxRetryOkCount = pAd->RalinkCounters.OneSecTxRetryOkCount; - OneSecTxFailCount = pAd->RalinkCounters.OneSecTxFailCount; - OneSecRxOkCnt = pAd->RalinkCounters.OneSecRxOkCnt; - OneSecRxFcsErrCnt = pAd->RalinkCounters.OneSecRxFcsErrCnt; - } - - MaxRssi = RTMPMaxRssi(pAd, pRssiSample->LastRssi0, - pRssiSample->LastRssi1, pRssiSample->LastRssi2); - - /* */ - /* calculate TX packet error ratio and TX retry ratio - if too few TX samples, skip TX related statistics */ - /* */ - TxOkCnt = OneSecTxNoRetryOkCount + OneSecTxRetryOkCount; - TxCnt = TxOkCnt + OneSecTxFailCount; - if (TxCnt < 5) { - TxPER = 0; - TxPRR = 0; - } else { - TxPER = (OneSecTxFailCount * 100) / TxCnt; - TxPRR = ((TxCnt - OneSecTxNoRetryOkCount) * 100) / TxCnt; - } - - /* */ - /* calculate RX PER - don't take RxPER into consideration if too few sample */ - /* */ - RxCnt = OneSecRxOkCnt + OneSecRxFcsErrCnt; - if (RxCnt < 5) - RxPER = 0; - else - RxPER = (OneSecRxFcsErrCnt * 100) / RxCnt; - - /* */ - /* decide ChannelQuality based on: 1)last BEACON received time, 2)last RSSI, 3)TxPER, and 4)RxPER */ - /* */ - if ((pAd->OpMode == OPMODE_STA) && INFRA_ON(pAd) && (OneSecTxNoRetryOkCount < 2) && /* no heavy traffic */ - ((pAd->StaCfg.LastBeaconRxTime + BeaconLostTime) < Now32)) { - DBGPRINT(RT_DEBUG_TRACE, - ("BEACON lost > %ld msec with TxOkCnt=%ld -> CQI=0\n", - BeaconLostTime, TxOkCnt)); - ChannelQuality = 0; - } else { - /* Normalize Rssi */ - if (MaxRssi > -40) - NorRssi = 100; - else if (MaxRssi < -90) - NorRssi = 0; - else - NorRssi = (MaxRssi + 90) * 2; - - /* ChannelQuality = W1*RSSI + W2*TxPRR + W3*RxPER (RSSI 0..100), (TxPER 100..0), (RxPER 100..0) */ - ChannelQuality = (RSSI_WEIGHTING * NorRssi + - TX_WEIGHTING * (100 - TxPRR) + - RX_WEIGHTING * (100 - RxPER)) / 100; - } - - if (pAd->OpMode == OPMODE_STA) - pAd->Mlme.ChannelQuality = - (ChannelQuality > 100) ? 100 : ChannelQuality; - -} - -/* IRQL = DISPATCH_LEVEL */ -void MlmeSetTxPreamble(struct rt_rtmp_adapter *pAd, u16 TxPreamble) -{ - AUTO_RSP_CFG_STRUC csr4; - - /* */ - /* Always use Long preamble before verifiation short preamble functionality works well. */ - /* Todo: remove the following line if short preamble functionality works */ - /* */ - /*TxPreamble = Rt802_11PreambleLong; */ - - RTMP_IO_READ32(pAd, AUTO_RSP_CFG, &csr4.word); - if (TxPreamble == Rt802_11PreambleLong) { - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeSetTxPreamble (= long PREAMBLE)\n")); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); - csr4.field.AutoResponderPreamble = 0; - } else { - /* NOTE: 1Mbps should always use long preamble */ - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeSetTxPreamble (= short PREAMBLE)\n")); - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); - csr4.field.AutoResponderPreamble = 1; - } - - RTMP_IO_WRITE32(pAd, AUTO_RSP_CFG, csr4.word); -} - -/* - ========================================================================== - Description: - Update basic rate bitmap - ========================================================================== - */ - -void UpdateBasicRateBitmap(struct rt_rtmp_adapter *pAdapter) -{ - int i, j; - /* 1 2 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */ - u8 rate[] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 }; - u8 *sup_p = pAdapter->CommonCfg.SupRate; - u8 *ext_p = pAdapter->CommonCfg.ExtRate; - unsigned long bitmap = pAdapter->CommonCfg.BasicRateBitmap; - - /* if A mode, always use fix BasicRateBitMap */ - /*if (pAdapter->CommonCfg.Channel == PHY_11A) */ - if (pAdapter->CommonCfg.Channel > 14) - pAdapter->CommonCfg.BasicRateBitmap = 0x150; /* 6, 12, 24M */ - /* End of if */ - - if (pAdapter->CommonCfg.BasicRateBitmap > 4095) { - /* (2 ^ MAX_LEN_OF_SUPPORTED_RATES) -1 */ - return; - } - /* End of if */ - for (i = 0; i < MAX_LEN_OF_SUPPORTED_RATES; i++) { - sup_p[i] &= 0x7f; - ext_p[i] &= 0x7f; - } /* End of for */ - - for (i = 0; i < MAX_LEN_OF_SUPPORTED_RATES; i++) { - if (bitmap & (1 << i)) { - for (j = 0; j < MAX_LEN_OF_SUPPORTED_RATES; j++) { - if (sup_p[j] == rate[i]) - sup_p[j] |= 0x80; - /* End of if */ - } /* End of for */ - - for (j = 0; j < MAX_LEN_OF_SUPPORTED_RATES; j++) { - if (ext_p[j] == rate[i]) - ext_p[j] |= 0x80; - /* End of if */ - } /* End of for */ - } /* End of if */ - } /* End of for */ -} /* End of UpdateBasicRateBitmap */ - -/* IRQL = PASSIVE_LEVEL */ -/* IRQL = DISPATCH_LEVEL */ -/* bLinkUp is to identify the initial link speed. */ -/* TRUE indicates the rate update at linkup, we should not try to set the rate at 54Mbps. */ -void MlmeUpdateTxRates(struct rt_rtmp_adapter *pAd, IN BOOLEAN bLinkUp, u8 apidx) -{ - int i, num; - u8 Rate = RATE_6, MaxDesire = RATE_1, MaxSupport = RATE_1; - u8 MinSupport = RATE_54; - unsigned long BasicRateBitmap = 0; - u8 CurrBasicRate = RATE_1; - u8 *pSupRate, SupRateLen, *pExtRate, ExtRateLen; - PHTTRANSMIT_SETTING pHtPhy = NULL; - PHTTRANSMIT_SETTING pMaxHtPhy = NULL; - PHTTRANSMIT_SETTING pMinHtPhy = NULL; - BOOLEAN *auto_rate_cur_p; - u8 HtMcs = MCS_AUTO; - - /* find max desired rate */ - UpdateBasicRateBitmap(pAd); - - num = 0; - auto_rate_cur_p = NULL; - for (i = 0; i < MAX_LEN_OF_SUPPORTED_RATES; i++) { - switch (pAd->CommonCfg.DesireRate[i] & 0x7f) { - case 2: - Rate = RATE_1; - num++; - break; - case 4: - Rate = RATE_2; - num++; - break; - case 11: - Rate = RATE_5_5; - num++; - break; - case 22: - Rate = RATE_11; - num++; - break; - case 12: - Rate = RATE_6; - num++; - break; - case 18: - Rate = RATE_9; - num++; - break; - case 24: - Rate = RATE_12; - num++; - break; - case 36: - Rate = RATE_18; - num++; - break; - case 48: - Rate = RATE_24; - num++; - break; - case 72: - Rate = RATE_36; - num++; - break; - case 96: - Rate = RATE_48; - num++; - break; - case 108: - Rate = RATE_54; - num++; - break; - /*default: Rate = RATE_1; break; */ - } - if (MaxDesire < Rate) - MaxDesire = Rate; - } - -/*=========================================================================== */ -/*=========================================================================== */ - { - pHtPhy = &pAd->StaCfg.HTPhyMode; - pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode; - pMinHtPhy = &pAd->StaCfg.MinHTPhyMode; - - auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch; - HtMcs = pAd->StaCfg.DesiredTransmitSetting.field.MCS; - - if ((pAd->StaCfg.BssType == BSS_ADHOC) && - (pAd->CommonCfg.PhyMode == PHY_11B) && - (MaxDesire > RATE_11)) { - MaxDesire = RATE_11; - } - } - - pAd->CommonCfg.MaxDesiredRate = MaxDesire; - pMinHtPhy->word = 0; - pMaxHtPhy->word = 0; - pHtPhy->word = 0; - - /* Auto rate switching is enabled only if more than one DESIRED RATES are */ - /* specified; otherwise disabled */ - if (num <= 1) { - /*OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED); */ - /*pAd->CommonCfg.bAutoTxRateSwitch = FALSE; */ - *auto_rate_cur_p = FALSE; - } else { - /*OPSTATUS_SET_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED); */ - /*pAd->CommonCfg.bAutoTxRateSwitch = TRUE; */ - *auto_rate_cur_p = TRUE; - } - - if (HtMcs != MCS_AUTO) { - /*OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED); */ - /*pAd->CommonCfg.bAutoTxRateSwitch = FALSE; */ - *auto_rate_cur_p = FALSE; - } else { - /*OPSTATUS_SET_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED); */ - /*pAd->CommonCfg.bAutoTxRateSwitch = TRUE; */ - *auto_rate_cur_p = TRUE; - } - - if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) { - pSupRate = &pAd->StaActive.SupRate[0]; - pExtRate = &pAd->StaActive.ExtRate[0]; - SupRateLen = pAd->StaActive.SupRateLen; - ExtRateLen = pAd->StaActive.ExtRateLen; - } else { - pSupRate = &pAd->CommonCfg.SupRate[0]; - pExtRate = &pAd->CommonCfg.ExtRate[0]; - SupRateLen = pAd->CommonCfg.SupRateLen; - ExtRateLen = pAd->CommonCfg.ExtRateLen; - } - - /* find max supported rate */ - for (i = 0; i < SupRateLen; i++) { - switch (pSupRate[i] & 0x7f) { - case 2: - Rate = RATE_1; - if (pSupRate[i] & 0x80) - BasicRateBitmap |= 0x0001; - break; - case 4: - Rate = RATE_2; - if (pSupRate[i] & 0x80) - BasicRateBitmap |= 0x0002; - break; - case 11: - Rate = RATE_5_5; - if (pSupRate[i] & 0x80) - BasicRateBitmap |= 0x0004; - break; - case 22: - Rate = RATE_11; - if (pSupRate[i] & 0x80) - BasicRateBitmap |= 0x0008; - break; - case 12: - Rate = RATE_6; /*if (pSupRate[i] & 0x80) */ - BasicRateBitmap |= 0x0010; - break; - case 18: - Rate = RATE_9; - if (pSupRate[i] & 0x80) - BasicRateBitmap |= 0x0020; - break; - case 24: - Rate = RATE_12; /*if (pSupRate[i] & 0x80) */ - BasicRateBitmap |= 0x0040; - break; - case 36: - Rate = RATE_18; - if (pSupRate[i] & 0x80) - BasicRateBitmap |= 0x0080; - break; - case 48: - Rate = RATE_24; /*if (pSupRate[i] & 0x80) */ - BasicRateBitmap |= 0x0100; - break; - case 72: - Rate = RATE_36; - if (pSupRate[i] & 0x80) - BasicRateBitmap |= 0x0200; - break; - case 96: - Rate = RATE_48; - if (pSupRate[i] & 0x80) - BasicRateBitmap |= 0x0400; - break; - case 108: - Rate = RATE_54; - if (pSupRate[i] & 0x80) - BasicRateBitmap |= 0x0800; - break; - default: - Rate = RATE_1; - break; - } - if (MaxSupport < Rate) - MaxSupport = Rate; - - if (MinSupport > Rate) - MinSupport = Rate; - } - - for (i = 0; i < ExtRateLen; i++) { - switch (pExtRate[i] & 0x7f) { - case 2: - Rate = RATE_1; - if (pExtRate[i] & 0x80) - BasicRateBitmap |= 0x0001; - break; - case 4: - Rate = RATE_2; - if (pExtRate[i] & 0x80) - BasicRateBitmap |= 0x0002; - break; - case 11: - Rate = RATE_5_5; - if (pExtRate[i] & 0x80) - BasicRateBitmap |= 0x0004; - break; - case 22: - Rate = RATE_11; - if (pExtRate[i] & 0x80) - BasicRateBitmap |= 0x0008; - break; - case 12: - Rate = RATE_6; /*if (pExtRate[i] & 0x80) */ - BasicRateBitmap |= 0x0010; - break; - case 18: - Rate = RATE_9; - if (pExtRate[i] & 0x80) - BasicRateBitmap |= 0x0020; - break; - case 24: - Rate = RATE_12; /*if (pExtRate[i] & 0x80) */ - BasicRateBitmap |= 0x0040; - break; - case 36: - Rate = RATE_18; - if (pExtRate[i] & 0x80) - BasicRateBitmap |= 0x0080; - break; - case 48: - Rate = RATE_24; /*if (pExtRate[i] & 0x80) */ - BasicRateBitmap |= 0x0100; - break; - case 72: - Rate = RATE_36; - if (pExtRate[i] & 0x80) - BasicRateBitmap |= 0x0200; - break; - case 96: - Rate = RATE_48; - if (pExtRate[i] & 0x80) - BasicRateBitmap |= 0x0400; - break; - case 108: - Rate = RATE_54; - if (pExtRate[i] & 0x80) - BasicRateBitmap |= 0x0800; - break; - default: - Rate = RATE_1; - break; - } - if (MaxSupport < Rate) - MaxSupport = Rate; - - if (MinSupport > Rate) - MinSupport = Rate; - } - - RTMP_IO_WRITE32(pAd, LEGACY_BASIC_RATE, BasicRateBitmap); - - /* bug fix */ - /* pAd->CommonCfg.BasicRateBitmap = BasicRateBitmap; */ - - /* calculate the exptected ACK rate for each TX rate. This info is used to caculate */ - /* the DURATION field of outgoing uniicast DATA/MGMT frame */ - for (i = 0; i < MAX_LEN_OF_SUPPORTED_RATES; i++) { - if (BasicRateBitmap & (0x01 << i)) - CurrBasicRate = (u8)i; - pAd->CommonCfg.ExpectedACKRate[i] = CurrBasicRate; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeUpdateTxRates[MaxSupport = %d] = MaxDesire %d Mbps\n", - RateIdToMbps[MaxSupport], RateIdToMbps[MaxDesire])); - /* max tx rate = min {max desire rate, max supported rate} */ - if (MaxSupport < MaxDesire) - pAd->CommonCfg.MaxTxRate = MaxSupport; - else - pAd->CommonCfg.MaxTxRate = MaxDesire; - - pAd->CommonCfg.MinTxRate = MinSupport; - /* 2003-07-31 john - 2500 doesn't have good sensitivity at high OFDM rates. to increase the success */ - /* ratio of initial DHCP packet exchange, TX rate starts from a lower rate depending */ - /* on average RSSI */ - /* 1. RSSI >= -70db, start at 54 Mbps (short distance) */ - /* 2. -70 > RSSI >= -75, start at 24 Mbps (mid distance) */ - /* 3. -75 > RSSI, start at 11 Mbps (long distance) */ - if (*auto_rate_cur_p) { - short dbm = 0; - - dbm = pAd->StaCfg.RssiSample.AvgRssi0 - pAd->BbpRssiToDbmDelta; - - if (bLinkUp == TRUE) - pAd->CommonCfg.TxRate = RATE_24; - else - pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate; - - if (dbm < -75) - pAd->CommonCfg.TxRate = RATE_11; - else if (dbm < -70) - pAd->CommonCfg.TxRate = RATE_24; - - /* should never exceed MaxTxRate (consider 11B-only mode) */ - if (pAd->CommonCfg.TxRate > pAd->CommonCfg.MaxTxRate) - pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate; - - pAd->CommonCfg.TxRateIndex = 0; - } else { - pAd->CommonCfg.TxRate = pAd->CommonCfg.MaxTxRate; - pHtPhy->field.MCS = - (pAd->CommonCfg.MaxTxRate > - 3) ? (pAd->CommonCfg.MaxTxRate - - 4) : pAd->CommonCfg.MaxTxRate; - pHtPhy->field.MODE = - (pAd->CommonCfg.MaxTxRate > 3) ? MODE_OFDM : MODE_CCK; - - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.STBC = - pHtPhy->field.STBC; - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.ShortGI = - pHtPhy->field.ShortGI; - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MCS = - pHtPhy->field.MCS; - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE = - pHtPhy->field.MODE; - } - - if (pAd->CommonCfg.TxRate <= RATE_11) { - pMaxHtPhy->field.MODE = MODE_CCK; - pMaxHtPhy->field.MCS = pAd->CommonCfg.TxRate; - pMinHtPhy->field.MCS = pAd->CommonCfg.MinTxRate; - } else { - pMaxHtPhy->field.MODE = MODE_OFDM; - pMaxHtPhy->field.MCS = OfdmRateToRxwiMCS[pAd->CommonCfg.TxRate]; - if (pAd->CommonCfg.MinTxRate >= RATE_6 - && (pAd->CommonCfg.MinTxRate <= RATE_54)) { - pMinHtPhy->field.MCS = - OfdmRateToRxwiMCS[pAd->CommonCfg.MinTxRate]; - } else { - pMinHtPhy->field.MCS = pAd->CommonCfg.MinTxRate; - } - } - - pHtPhy->word = (pMaxHtPhy->word); - if (bLinkUp && (pAd->OpMode == OPMODE_STA)) { - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word = pHtPhy->word; - pAd->MacTab.Content[BSSID_WCID].MaxHTPhyMode.word = - pMaxHtPhy->word; - pAd->MacTab.Content[BSSID_WCID].MinHTPhyMode.word = - pMinHtPhy->word; - } else { - switch (pAd->CommonCfg.PhyMode) { - case PHY_11BG_MIXED: - case PHY_11B: - case PHY_11BGN_MIXED: - pAd->CommonCfg.MlmeRate = RATE_1; - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK; - pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1; - -/*#ifdef WIFI_TEST */ - pAd->CommonCfg.RtsRate = RATE_11; -/*#else */ -/* pAd->CommonCfg.RtsRate = RATE_1; */ -/*#endif */ - break; - case PHY_11G: - case PHY_11A: - case PHY_11AGN_MIXED: - case PHY_11GN_MIXED: - case PHY_11N_2_4G: - case PHY_11AN_MIXED: - case PHY_11N_5G: - pAd->CommonCfg.MlmeRate = RATE_6; - pAd->CommonCfg.RtsRate = RATE_6; - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; - pAd->CommonCfg.MlmeTransmit.field.MCS = - OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; - break; - case PHY_11ABG_MIXED: - case PHY_11ABGN_MIXED: - if (pAd->CommonCfg.Channel <= 14) { - pAd->CommonCfg.MlmeRate = RATE_1; - pAd->CommonCfg.RtsRate = RATE_1; - pAd->CommonCfg.MlmeTransmit.field.MODE = - MODE_CCK; - pAd->CommonCfg.MlmeTransmit.field.MCS = RATE_1; - } else { - pAd->CommonCfg.MlmeRate = RATE_6; - pAd->CommonCfg.RtsRate = RATE_6; - pAd->CommonCfg.MlmeTransmit.field.MODE = - MODE_OFDM; - pAd->CommonCfg.MlmeTransmit.field.MCS = - OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; - } - break; - default: /* error */ - pAd->CommonCfg.MlmeRate = RATE_6; - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; - pAd->CommonCfg.MlmeTransmit.field.MCS = - OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; - pAd->CommonCfg.RtsRate = RATE_1; - break; - } - /* */ - /* Keep Basic Mlme Rate. */ - /* */ - pAd->MacTab.Content[MCAST_WCID].HTPhyMode.word = - pAd->CommonCfg.MlmeTransmit.word; - if (pAd->CommonCfg.MlmeTransmit.field.MODE == MODE_OFDM) - pAd->MacTab.Content[MCAST_WCID].HTPhyMode.field.MCS = - OfdmRateToRxwiMCS[RATE_24]; - else - pAd->MacTab.Content[MCAST_WCID].HTPhyMode.field.MCS = - RATE_1; - pAd->CommonCfg.BasicMlmeRate = pAd->CommonCfg.MlmeRate; - } - - DBGPRINT(RT_DEBUG_TRACE, - (" MlmeUpdateTxRates (MaxDesire=%d, MaxSupport=%d, MaxTxRate=%d, MinRate=%d, Rate Switching =%d)\n", - RateIdToMbps[MaxDesire], RateIdToMbps[MaxSupport], - RateIdToMbps[pAd->CommonCfg.MaxTxRate], - RateIdToMbps[pAd->CommonCfg.MinTxRate], - /*OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) */ - *auto_rate_cur_p)); - DBGPRINT(RT_DEBUG_TRACE, - (" MlmeUpdateTxRates (TxRate=%d, RtsRate=%d, BasicRateBitmap=0x%04lx)\n", - RateIdToMbps[pAd->CommonCfg.TxRate], - RateIdToMbps[pAd->CommonCfg.RtsRate], BasicRateBitmap)); - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeUpdateTxRates (MlmeTransmit=0x%x, MinHTPhyMode=%x, MaxHTPhyMode=0x%x, HTPhyMode=0x%x)\n", - pAd->CommonCfg.MlmeTransmit.word, - pAd->MacTab.Content[BSSID_WCID].MinHTPhyMode.word, - pAd->MacTab.Content[BSSID_WCID].MaxHTPhyMode.word, - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word)); -} - -/* - ========================================================================== - Description: - This function update HT Rate setting. - Input Wcid value is valid for 2 case : - 1. it's used for Station in infra mode that copy AP rate to Mactable. - 2. OR Station in adhoc mode to copy peer's HT rate to Mactable. - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void MlmeUpdateHtTxRates(struct rt_rtmp_adapter *pAd, u8 apidx) -{ - u8 StbcMcs; /*j, StbcMcs, bitmask; */ - char i; /* 3*3 */ - struct rt_ht_capability *pRtHtCap = NULL; - struct rt_ht_phy_info *pActiveHtPhy = NULL; - unsigned long BasicMCS; - u8 j, bitmask; - struct rt_ht_phy_info *pDesireHtPhy = NULL; - PHTTRANSMIT_SETTING pHtPhy = NULL; - PHTTRANSMIT_SETTING pMaxHtPhy = NULL; - PHTTRANSMIT_SETTING pMinHtPhy = NULL; - BOOLEAN *auto_rate_cur_p; - - DBGPRINT(RT_DEBUG_TRACE, ("MlmeUpdateHtTxRates===> \n")); - - auto_rate_cur_p = NULL; - - { - pDesireHtPhy = &pAd->StaCfg.DesiredHtPhyInfo; - pActiveHtPhy = &pAd->StaCfg.DesiredHtPhyInfo; - pHtPhy = &pAd->StaCfg.HTPhyMode; - pMaxHtPhy = &pAd->StaCfg.MaxHTPhyMode; - pMinHtPhy = &pAd->StaCfg.MinHTPhyMode; - - auto_rate_cur_p = &pAd->StaCfg.bAutoTxRateSwitch; - } - - if ((ADHOC_ON(pAd) || INFRA_ON(pAd)) && (pAd->OpMode == OPMODE_STA)) { - if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) - return; - - pRtHtCap = &pAd->StaActive.SupportedHtPhy; - pActiveHtPhy = &pAd->StaActive.SupportedPhyInfo; - StbcMcs = (u8)pAd->MlmeAux.AddHtInfo.AddHtInfo3.StbcMcs; - BasicMCS = - pAd->MlmeAux.AddHtInfo.MCSSet[0] + - (pAd->MlmeAux.AddHtInfo.MCSSet[1] << 8) + (StbcMcs << 16); - if ((pAd->CommonCfg.DesiredHtPhy.TxSTBC) && (pRtHtCap->RxSTBC) - && (pAd->Antenna.field.TxPath == 2)) - pMaxHtPhy->field.STBC = STBC_USE; - else - pMaxHtPhy->field.STBC = STBC_NONE; - } else { - if (pDesireHtPhy->bHtEnable == FALSE) - return; - - pRtHtCap = &pAd->CommonCfg.DesiredHtPhy; - StbcMcs = (u8)pAd->CommonCfg.AddHTInfo.AddHtInfo3.StbcMcs; - BasicMCS = - pAd->CommonCfg.AddHTInfo.MCSSet[0] + - (pAd->CommonCfg.AddHTInfo.MCSSet[1] << 8) + (StbcMcs << 16); - if ((pAd->CommonCfg.DesiredHtPhy.TxSTBC) && (pRtHtCap->RxSTBC) - && (pAd->Antenna.field.TxPath == 2)) - pMaxHtPhy->field.STBC = STBC_USE; - else - pMaxHtPhy->field.STBC = STBC_NONE; - } - - /* Decide MAX ht rate. */ - if ((pRtHtCap->GF) && (pAd->CommonCfg.DesiredHtPhy.GF)) - pMaxHtPhy->field.MODE = MODE_HTGREENFIELD; - else - pMaxHtPhy->field.MODE = MODE_HTMIX; - - if ((pAd->CommonCfg.DesiredHtPhy.ChannelWidth) - && (pRtHtCap->ChannelWidth)) - pMaxHtPhy->field.BW = BW_40; - else - pMaxHtPhy->field.BW = BW_20; - - if (pMaxHtPhy->field.BW == BW_20) - pMaxHtPhy->field.ShortGI = - (pAd->CommonCfg.DesiredHtPhy.ShortGIfor20 & pRtHtCap-> - ShortGIfor20); - else - pMaxHtPhy->field.ShortGI = - (pAd->CommonCfg.DesiredHtPhy.ShortGIfor40 & pRtHtCap-> - ShortGIfor40); - - if (pDesireHtPhy->MCSSet[4] != 0) { - pMaxHtPhy->field.MCS = 32; - } - - for (i = 23; i >= 0; i--) /* 3*3 */ - { - j = i / 8; - bitmask = (1 << (i - (j * 8))); - - if ((pActiveHtPhy->MCSSet[j] & bitmask) - && (pDesireHtPhy->MCSSet[j] & bitmask)) { - pMaxHtPhy->field.MCS = i; - break; - } - - if (i == 0) - break; - } - - /* Copy MIN ht rate. rt2860??? */ - pMinHtPhy->field.BW = BW_20; - pMinHtPhy->field.MCS = 0; - pMinHtPhy->field.STBC = 0; - pMinHtPhy->field.ShortGI = 0; - /*If STA assigns fixed rate. update to fixed here. */ - if ((pAd->OpMode == OPMODE_STA) && (pDesireHtPhy->MCSSet[0] != 0xff)) { - if (pDesireHtPhy->MCSSet[4] != 0) { - pMaxHtPhy->field.MCS = 32; - pMinHtPhy->field.MCS = 32; - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeUpdateHtTxRates<=== Use Fixed MCS = %d\n", - pMinHtPhy->field.MCS)); - } - - for (i = 23; (char)i >= 0; i--) /* 3*3 */ - { - j = i / 8; - bitmask = (1 << (i - (j * 8))); - if ((pDesireHtPhy->MCSSet[j] & bitmask) - && (pActiveHtPhy->MCSSet[j] & bitmask)) { - pMaxHtPhy->field.MCS = i; - pMinHtPhy->field.MCS = i; - break; - } - if (i == 0) - break; - } - } - - /* Decide ht rate */ - pHtPhy->field.STBC = pMaxHtPhy->field.STBC; - pHtPhy->field.BW = pMaxHtPhy->field.BW; - pHtPhy->field.MODE = pMaxHtPhy->field.MODE; - pHtPhy->field.MCS = pMaxHtPhy->field.MCS; - pHtPhy->field.ShortGI = pMaxHtPhy->field.ShortGI; - - /* use default now. rt2860 */ - if (pDesireHtPhy->MCSSet[0] != 0xff) - *auto_rate_cur_p = FALSE; - else - *auto_rate_cur_p = TRUE; - - DBGPRINT(RT_DEBUG_TRACE, - (" MlmeUpdateHtTxRates<---.AMsduSize = %d \n", - pAd->CommonCfg.DesiredHtPhy.AmsduSize)); - DBGPRINT(RT_DEBUG_TRACE, - ("TX: MCS[0] = %x (choose %d), BW = %d, ShortGI = %d, MODE = %d, \n", - pActiveHtPhy->MCSSet[0], pHtPhy->field.MCS, pHtPhy->field.BW, - pHtPhy->field.ShortGI, pHtPhy->field.MODE)); - DBGPRINT(RT_DEBUG_TRACE, ("MlmeUpdateHtTxRates<=== \n")); -} - -void BATableInit(struct rt_rtmp_adapter *pAd, struct rt_ba_table *Tab) -{ - int i; - - Tab->numAsOriginator = 0; - Tab->numAsRecipient = 0; - Tab->numDoneOriginator = 0; - NdisAllocateSpinLock(&pAd->BATabLock); - for (i = 0; i < MAX_LEN_OF_BA_REC_TABLE; i++) { - Tab->BARecEntry[i].REC_BA_Status = Recipient_NONE; - NdisAllocateSpinLock(&(Tab->BARecEntry[i].RxReRingLock)); - } - for (i = 0; i < MAX_LEN_OF_BA_ORI_TABLE; i++) { - Tab->BAOriEntry[i].ORI_BA_Status = Originator_NONE; - } -} - -/* IRQL = DISPATCH_LEVEL */ -void MlmeRadioOff(struct rt_rtmp_adapter *pAd) -{ - RTMP_MLME_RADIO_OFF(pAd); -} - -/* IRQL = DISPATCH_LEVEL */ -void MlmeRadioOn(struct rt_rtmp_adapter *pAd) -{ - RTMP_MLME_RADIO_ON(pAd); -} - -/* =========================================================================================== */ -/* bss_table.c */ -/* =========================================================================================== */ - -/*! \brief initialize BSS table - * \param p_tab pointer to the table - * \return none - * \pre - * \post - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - */ -void BssTableInit(struct rt_bss_table *Tab) -{ - int i; - - Tab->BssNr = 0; - Tab->BssOverlapNr = 0; - for (i = 0; i < MAX_LEN_OF_BSS_TABLE; i++) { - NdisZeroMemory(&Tab->BssEntry[i], sizeof(struct rt_bss_entry)); - Tab->BssEntry[i].Rssi = -127; /* initial the rssi as a minimum value */ - } -} - -/*! \brief search the BSS table by SSID - * \param p_tab pointer to the bss table - * \param ssid SSID string - * \return index of the table, BSS_NOT_FOUND if not in the table - * \pre - * \post - * \note search by sequential search - - IRQL = DISPATCH_LEVEL - - */ -unsigned long BssTableSearch(struct rt_bss_table *Tab, u8 *pBssid, u8 Channel) -{ - u8 i; - - for (i = 0; i < Tab->BssNr; i++) { - /* */ - /* Some AP that support A/B/G mode that may used the same BSSID on 11A and 11B/G. */ - /* We should distinguish this case. */ - /* */ - if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) || - ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) && - MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid)) { - return i; - } - } - return (unsigned long)BSS_NOT_FOUND; -} - -unsigned long BssSsidTableSearch(struct rt_bss_table *Tab, - u8 *pBssid, - u8 *pSsid, u8 SsidLen, u8 Channel) -{ - u8 i; - - for (i = 0; i < Tab->BssNr; i++) { - /* */ - /* Some AP that support A/B/G mode that may used the same BSSID on 11A and 11B/G. */ - /* We should distinguish this case. */ - /* */ - if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) || - ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) && - MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid) && - SSID_EQUAL(pSsid, SsidLen, Tab->BssEntry[i].Ssid, - Tab->BssEntry[i].SsidLen)) { - return i; - } - } - return (unsigned long)BSS_NOT_FOUND; -} - -unsigned long BssTableSearchWithSSID(struct rt_bss_table *Tab, - u8 *Bssid, - u8 *pSsid, - u8 SsidLen, u8 Channel) -{ - u8 i; - - for (i = 0; i < Tab->BssNr; i++) { - if ((((Tab->BssEntry[i].Channel <= 14) && (Channel <= 14)) || - ((Tab->BssEntry[i].Channel > 14) && (Channel > 14))) && - MAC_ADDR_EQUAL(&(Tab->BssEntry[i].Bssid), Bssid) && - (SSID_EQUAL - (pSsid, SsidLen, Tab->BssEntry[i].Ssid, - Tab->BssEntry[i].SsidLen) - || (NdisEqualMemory(pSsid, ZeroSsid, SsidLen)) - || - (NdisEqualMemory - (Tab->BssEntry[i].Ssid, ZeroSsid, - Tab->BssEntry[i].SsidLen)))) { - return i; - } - } - return (unsigned long)BSS_NOT_FOUND; -} - -unsigned long BssSsidTableSearchBySSID(struct rt_bss_table *Tab, - u8 *pSsid, u8 SsidLen) -{ - u8 i; - - for (i = 0; i < Tab->BssNr; i++) { - if (SSID_EQUAL - (pSsid, SsidLen, Tab->BssEntry[i].Ssid, - Tab->BssEntry[i].SsidLen)) { - return i; - } - } - return (unsigned long)BSS_NOT_FOUND; -} - -/* IRQL = DISPATCH_LEVEL */ -void BssTableDeleteEntry(struct rt_bss_table *Tab, - u8 *pBssid, u8 Channel) -{ - u8 i, j; - - for (i = 0; i < Tab->BssNr; i++) { - if ((Tab->BssEntry[i].Channel == Channel) && - (MAC_ADDR_EQUAL(Tab->BssEntry[i].Bssid, pBssid))) { - for (j = i; j < Tab->BssNr - 1; j++) { - NdisMoveMemory(&(Tab->BssEntry[j]), - &(Tab->BssEntry[j + 1]), - sizeof(struct rt_bss_entry)); - } - NdisZeroMemory(&(Tab->BssEntry[Tab->BssNr - 1]), - sizeof(struct rt_bss_entry)); - Tab->BssNr -= 1; - return; - } - } -} - -/* - ======================================================================== - Routine Description: - Delete the Originator Entry in BAtable. Or decrease numAs Originator by 1 if needed. - - Arguments: - // IRQL = DISPATCH_LEVEL - ======================================================================== -*/ -void BATableDeleteORIEntry(struct rt_rtmp_adapter *pAd, - struct rt_ba_ori_entry *pBAORIEntry) -{ - - if (pBAORIEntry->ORI_BA_Status != Originator_NONE) { - NdisAcquireSpinLock(&pAd->BATabLock); - if (pBAORIEntry->ORI_BA_Status == Originator_Done) { - pAd->BATable.numAsOriginator -= 1; - DBGPRINT(RT_DEBUG_TRACE, - ("BATableDeleteORIEntry numAsOriginator= %ld\n", - pAd->BATable.numAsRecipient)); - /* Erase Bitmap flag. */ - } - pAd->MacTab.Content[pBAORIEntry->Wcid].TXBAbitmap &= (~(1 << (pBAORIEntry->TID))); /* If STA mode, erase flag here */ - pAd->MacTab.Content[pBAORIEntry->Wcid].BAOriWcidArray[pBAORIEntry->TID] = 0; /* If STA mode, erase flag here */ - pBAORIEntry->ORI_BA_Status = Originator_NONE; - pBAORIEntry->Token = 1; - /* Not clear Sequence here. */ - NdisReleaseSpinLock(&pAd->BATabLock); - } -} - -/*! \brief - * \param - * \return - * \pre - * \post - - IRQL = DISPATCH_LEVEL - - */ -void BssEntrySet(struct rt_rtmp_adapter *pAd, struct rt_bss_entry *pBss, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * pCfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */ - u8 HtCapabilityLen, - u8 AddHtInfoLen, - u8 NewExtChanOffset, - u8 Channel, - char Rssi, - IN LARGE_INTEGER TimeStamp, - u8 CkipFlag, - struct rt_edca_parm *pEdcaParm, - struct rt_qos_capability_parm *pQosCapability, - struct rt_qbss_load_parm *pQbssLoad, - u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE) -{ - COPY_MAC_ADDR(pBss->Bssid, pBssid); - /* Default Hidden SSID to be TRUE, it will be turned to FALSE after coping SSID */ - pBss->Hidden = 1; - if (SsidLen > 0) { - /* For hidden SSID AP, it might send beacon with SSID len equal to 0 */ - /* Or send beacon /probe response with SSID len matching real SSID length, */ - /* but SSID is all zero. such as "00-00-00-00" with length 4. */ - /* We have to prevent this case overwrite correct table */ - if (NdisEqualMemory(Ssid, ZeroSsid, SsidLen) == 0) { - NdisZeroMemory(pBss->Ssid, MAX_LEN_OF_SSID); - NdisMoveMemory(pBss->Ssid, Ssid, SsidLen); - pBss->SsidLen = SsidLen; - pBss->Hidden = 0; - } - } else - pBss->SsidLen = 0; - pBss->BssType = BssType; - pBss->BeaconPeriod = BeaconPeriod; - if (BssType == BSS_INFRA) { - if (pCfParm->bValid) { - pBss->CfpCount = pCfParm->CfpCount; - pBss->CfpPeriod = pCfParm->CfpPeriod; - pBss->CfpMaxDuration = pCfParm->CfpMaxDuration; - pBss->CfpDurRemaining = pCfParm->CfpDurRemaining; - } - } else { - pBss->AtimWin = AtimWin; - } - - pBss->CapabilityInfo = CapabilityInfo; - /* The privacy bit indicate security is ON, it maight be WEP, TKIP or AES */ - /* Combine with AuthMode, they will decide the connection methods. */ - pBss->Privacy = CAP_IS_PRIVACY_ON(pBss->CapabilityInfo); - ASSERT(SupRateLen <= MAX_LEN_OF_SUPPORTED_RATES); - if (SupRateLen <= MAX_LEN_OF_SUPPORTED_RATES) - NdisMoveMemory(pBss->SupRate, SupRate, SupRateLen); - else - NdisMoveMemory(pBss->SupRate, SupRate, - MAX_LEN_OF_SUPPORTED_RATES); - pBss->SupRateLen = SupRateLen; - ASSERT(ExtRateLen <= MAX_LEN_OF_SUPPORTED_RATES); - NdisMoveMemory(pBss->ExtRate, ExtRate, ExtRateLen); - pBss->NewExtChanOffset = NewExtChanOffset; - pBss->ExtRateLen = ExtRateLen; - pBss->Channel = Channel; - pBss->CentralChannel = Channel; - pBss->Rssi = Rssi; - /* Update CkipFlag. if not exists, the value is 0x0 */ - pBss->CkipFlag = CkipFlag; - - /* New for microsoft Fixed IEs */ - NdisMoveMemory(pBss->FixIEs.Timestamp, &TimeStamp, 8); - pBss->FixIEs.BeaconInterval = BeaconPeriod; - pBss->FixIEs.Capabilities = CapabilityInfo; - - /* New for microsoft Variable IEs */ - if (LengthVIE != 0) { - pBss->VarIELen = LengthVIE; - NdisMoveMemory(pBss->VarIEs, pVIE, pBss->VarIELen); - } else { - pBss->VarIELen = 0; - } - - pBss->AddHtInfoLen = 0; - pBss->HtCapabilityLen = 0; - if (HtCapabilityLen > 0) { - pBss->HtCapabilityLen = HtCapabilityLen; - NdisMoveMemory(&pBss->HtCapability, pHtCapability, - HtCapabilityLen); - if (AddHtInfoLen > 0) { - pBss->AddHtInfoLen = AddHtInfoLen; - NdisMoveMemory(&pBss->AddHtInfo, pAddHtInfo, - AddHtInfoLen); - - if ((pAddHtInfo->ControlChan > 2) - && (pAddHtInfo->AddHtInfo.ExtChanOffset == - EXTCHA_BELOW) - && (pHtCapability->HtCapInfo.ChannelWidth == - BW_40)) { - pBss->CentralChannel = - pAddHtInfo->ControlChan - 2; - } else - if ((pAddHtInfo->AddHtInfo.ExtChanOffset == - EXTCHA_ABOVE) - && (pHtCapability->HtCapInfo.ChannelWidth == - BW_40)) { - pBss->CentralChannel = - pAddHtInfo->ControlChan + 2; - } - } - } - - BssCipherParse(pBss); - - /* new for QOS */ - if (pEdcaParm) - NdisMoveMemory(&pBss->EdcaParm, pEdcaParm, sizeof(struct rt_edca_parm)); - else - pBss->EdcaParm.bValid = FALSE; - if (pQosCapability) - NdisMoveMemory(&pBss->QosCapability, pQosCapability, - sizeof(struct rt_qos_capability_parm)); - else - pBss->QosCapability.bValid = FALSE; - if (pQbssLoad) - NdisMoveMemory(&pBss->QbssLoad, pQbssLoad, - sizeof(struct rt_qbss_load_parm)); - else - pBss->QbssLoad.bValid = FALSE; - - { - struct rt_eid * pEid; - u16 Length = 0; - - NdisZeroMemory(&pBss->WpaIE.IE[0], MAX_CUSTOM_LEN); - NdisZeroMemory(&pBss->RsnIE.IE[0], MAX_CUSTOM_LEN); - pEid = (struct rt_eid *) pVIE; - while ((Length + 2 + (u16)pEid->Len) <= LengthVIE) { - switch (pEid->Eid) { - case IE_WPA: - if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)) { - if ((pEid->Len + 2) > MAX_CUSTOM_LEN) { - pBss->WpaIE.IELen = 0; - break; - } - pBss->WpaIE.IELen = pEid->Len + 2; - NdisMoveMemory(pBss->WpaIE.IE, pEid, - pBss->WpaIE.IELen); - } - break; - case IE_RSN: - if (NdisEqualMemory - (pEid->Octet + 2, RSN_OUI, 3)) { - if ((pEid->Len + 2) > MAX_CUSTOM_LEN) { - pBss->RsnIE.IELen = 0; - break; - } - pBss->RsnIE.IELen = pEid->Len + 2; - NdisMoveMemory(pBss->RsnIE.IE, pEid, - pBss->RsnIE.IELen); - } - break; - } - Length = Length + 2 + (u16)pEid->Len; /* Eid[1] + Len[1]+ content[Len] */ - pEid = (struct rt_eid *) ((u8 *) pEid + 2 + pEid->Len); - } - } -} - -/*! - * \brief insert an entry into the bss table - * \param p_tab The BSS table - * \param Bssid BSSID - * \param ssid SSID - * \param ssid_len Length of SSID - * \param bss_type - * \param beacon_period - * \param timestamp - * \param p_cf - * \param atim_win - * \param cap - * \param rates - * \param rates_len - * \param channel_idx - * \return none - * \pre - * \post - * \note If SSID is identical, the old entry will be replaced by the new one - - IRQL = DISPATCH_LEVEL - - */ -unsigned long BssTableSetEntry(struct rt_rtmp_adapter *pAd, struct rt_bss_table *Tab, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * CfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */ - u8 HtCapabilityLen, - u8 AddHtInfoLen, - u8 NewExtChanOffset, - u8 ChannelNo, - char Rssi, - IN LARGE_INTEGER TimeStamp, - u8 CkipFlag, - struct rt_edca_parm *pEdcaParm, - struct rt_qos_capability_parm *pQosCapability, - struct rt_qbss_load_parm *pQbssLoad, - u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE) -{ - unsigned long Idx; - - Idx = - BssTableSearchWithSSID(Tab, pBssid, (u8 *) Ssid, SsidLen, - ChannelNo); - if (Idx == BSS_NOT_FOUND) { - if (Tab->BssNr >= MAX_LEN_OF_BSS_TABLE) { - /* */ - /* It may happen when BSS Table was full. */ - /* The desired AP will not be added into BSS Table */ - /* In this case, if we found the desired AP then overwrite BSS Table. */ - /* */ - if (!OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) { - if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, pBssid) - || SSID_EQUAL(pAd->MlmeAux.Ssid, - pAd->MlmeAux.SsidLen, Ssid, - SsidLen)) { - Idx = Tab->BssOverlapNr; - BssEntrySet(pAd, &Tab->BssEntry[Idx], - pBssid, Ssid, SsidLen, - BssType, BeaconPeriod, - CfParm, AtimWin, - CapabilityInfo, SupRate, - SupRateLen, ExtRate, - ExtRateLen, pHtCapability, - pAddHtInfo, HtCapabilityLen, - AddHtInfoLen, - NewExtChanOffset, ChannelNo, - Rssi, TimeStamp, CkipFlag, - pEdcaParm, pQosCapability, - pQbssLoad, LengthVIE, pVIE); - Tab->BssOverlapNr = - (Tab->BssOverlapNr++) % - MAX_LEN_OF_BSS_TABLE; - } - return Idx; - } else { - return BSS_NOT_FOUND; - } - } - Idx = Tab->BssNr; - BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, SsidLen, - BssType, BeaconPeriod, CfParm, AtimWin, - CapabilityInfo, SupRate, SupRateLen, ExtRate, - ExtRateLen, pHtCapability, pAddHtInfo, - HtCapabilityLen, AddHtInfoLen, NewExtChanOffset, - ChannelNo, Rssi, TimeStamp, CkipFlag, pEdcaParm, - pQosCapability, pQbssLoad, LengthVIE, pVIE); - Tab->BssNr++; - } else { - /* avoid Hidden SSID form beacon to overwirite correct SSID from probe response */ - if ((SSID_EQUAL - (Ssid, SsidLen, Tab->BssEntry[Idx].Ssid, - Tab->BssEntry[Idx].SsidLen)) - || - (NdisEqualMemory - (Tab->BssEntry[Idx].Ssid, ZeroSsid, - Tab->BssEntry[Idx].SsidLen))) { - BssEntrySet(pAd, &Tab->BssEntry[Idx], pBssid, Ssid, - SsidLen, BssType, BeaconPeriod, CfParm, - AtimWin, CapabilityInfo, SupRate, - SupRateLen, ExtRate, ExtRateLen, - pHtCapability, pAddHtInfo, HtCapabilityLen, - AddHtInfoLen, NewExtChanOffset, ChannelNo, - Rssi, TimeStamp, CkipFlag, pEdcaParm, - pQosCapability, pQbssLoad, LengthVIE, pVIE); - } - } - - return Idx; -} - -/* IRQL = DISPATCH_LEVEL */ -void BssTableSsidSort(struct rt_rtmp_adapter *pAd, - struct rt_bss_table *OutTab, char Ssid[], u8 SsidLen) -{ - int i; - BssTableInit(OutTab); - - for (i = 0; i < pAd->ScanTab.BssNr; i++) { - struct rt_bss_entry *pInBss = &pAd->ScanTab.BssEntry[i]; - BOOLEAN bIsHiddenApIncluded = FALSE; - - if (((pAd->CommonCfg.bIEEE80211H == 1) && - (pAd->MlmeAux.Channel > 14) && - RadarChannelCheck(pAd, pInBss->Channel)) - ) { - if (pInBss->Hidden) - bIsHiddenApIncluded = TRUE; - } - - if ((pInBss->BssType == pAd->StaCfg.BssType) && - (SSID_EQUAL(Ssid, SsidLen, pInBss->Ssid, pInBss->SsidLen) - || bIsHiddenApIncluded)) { - struct rt_bss_entry *pOutBss = &OutTab->BssEntry[OutTab->BssNr]; - - /* 2.4G/5G N only mode */ - if ((pInBss->HtCapabilityLen == 0) && - ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) - || (pAd->CommonCfg.PhyMode == PHY_11N_5G))) { - DBGPRINT(RT_DEBUG_TRACE, - ("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n")); - continue; - } - /* New for WPA2 */ - /* Check the Authmode first */ - if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) { - /* Check AuthMode and AuthModeAux for matching, in case AP support dual-mode */ - if ((pAd->StaCfg.AuthMode != pInBss->AuthMode) - && (pAd->StaCfg.AuthMode != - pInBss->AuthModeAux)) - /* None matched */ - continue; - - /* Check cipher suite, AP must have more secured cipher than station setting */ - if ((pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA) - || (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPAPSK)) { - /* If it's not mixed mode, we should only let BSS pass with the same encryption */ - if (pInBss->WPA.bMixMode == FALSE) - if (pAd->StaCfg.WepStatus != - pInBss->WPA.GroupCipher) - continue; - - /* check group cipher */ - if ((pAd->StaCfg.WepStatus < - pInBss->WPA.GroupCipher) - && (pInBss->WPA.GroupCipher != - Ndis802_11GroupWEP40Enabled) - && (pInBss->WPA.GroupCipher != - Ndis802_11GroupWEP104Enabled)) - continue; - - /* check pairwise cipher, skip if none matched */ - /* If profile set to AES, let it pass without question. */ - /* If profile set to TKIP, we must find one mateched */ - if ((pAd->StaCfg.WepStatus == - Ndis802_11Encryption2Enabled) - && (pAd->StaCfg.WepStatus != - pInBss->WPA.PairCipher) - && (pAd->StaCfg.WepStatus != - pInBss->WPA.PairCipherAux)) - continue; - } else - if ((pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA2) - || (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA2PSK)) { - /* If it's not mixed mode, we should only let BSS pass with the same encryption */ - if (pInBss->WPA2.bMixMode == FALSE) - if (pAd->StaCfg.WepStatus != - pInBss->WPA2.GroupCipher) - continue; - - /* check group cipher */ - if ((pAd->StaCfg.WepStatus < - pInBss->WPA.GroupCipher) - && (pInBss->WPA2.GroupCipher != - Ndis802_11GroupWEP40Enabled) - && (pInBss->WPA2.GroupCipher != - Ndis802_11GroupWEP104Enabled)) - continue; - - /* check pairwise cipher, skip if none matched */ - /* If profile set to AES, let it pass without question. */ - /* If profile set to TKIP, we must find one mateched */ - if ((pAd->StaCfg.WepStatus == - Ndis802_11Encryption2Enabled) - && (pAd->StaCfg.WepStatus != - pInBss->WPA2.PairCipher) - && (pAd->StaCfg.WepStatus != - pInBss->WPA2.PairCipherAux)) - continue; - } - } - /* Bss Type matched, SSID matched. */ - /* We will check wepstatus for qualification Bss */ - else if (pAd->StaCfg.WepStatus != pInBss->WepStatus) { - DBGPRINT(RT_DEBUG_TRACE, - ("StaCfg.WepStatus=%d, while pInBss->WepStatus=%d\n", - pAd->StaCfg.WepStatus, - pInBss->WepStatus)); - /* */ - /* For the SESv2 case, we will not qualify WepStatus. */ - /* */ - if (!pInBss->bSES) - continue; - } - /* Since the AP is using hidden SSID, and we are trying to connect to ANY */ - /* It definitely will fail. So, skip it. */ - /* CCX also require not even try to connect it! */ - if (SsidLen == 0) - continue; - - /* If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region */ - /* If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead, */ - if ((pInBss->CentralChannel != pInBss->Channel) && - (pAd->CommonCfg.RegTransmitSetting.field.BW == - BW_40)) { - if (RTMPCheckChannel - (pAd, pInBss->CentralChannel, - pInBss->Channel) == FALSE) { - pAd->CommonCfg.RegTransmitSetting.field. - BW = BW_20; - SetCommonHT(pAd); - pAd->CommonCfg.RegTransmitSetting.field. - BW = BW_40; - } else { - if (pAd->CommonCfg.DesiredHtPhy. - ChannelWidth == BAND_WIDTH_20) { - SetCommonHT(pAd); - } - } - } - /* copy matching BSS from InTab to OutTab */ - NdisMoveMemory(pOutBss, pInBss, sizeof(struct rt_bss_entry)); - - OutTab->BssNr++; - } else if ((pInBss->BssType == pAd->StaCfg.BssType) - && (SsidLen == 0)) { - struct rt_bss_entry *pOutBss = &OutTab->BssEntry[OutTab->BssNr]; - - /* 2.4G/5G N only mode */ - if ((pInBss->HtCapabilityLen == 0) && - ((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) - || (pAd->CommonCfg.PhyMode == PHY_11N_5G))) { - DBGPRINT(RT_DEBUG_TRACE, - ("STA is in N-only Mode, this AP don't have Ht capability in Beacon.\n")); - continue; - } - /* New for WPA2 */ - /* Check the Authmode first */ - if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) { - /* Check AuthMode and AuthModeAux for matching, in case AP support dual-mode */ - if ((pAd->StaCfg.AuthMode != pInBss->AuthMode) - && (pAd->StaCfg.AuthMode != - pInBss->AuthModeAux)) - /* None matched */ - continue; - - /* Check cipher suite, AP must have more secured cipher than station setting */ - if ((pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA) - || (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPAPSK)) { - /* If it's not mixed mode, we should only let BSS pass with the same encryption */ - if (pInBss->WPA.bMixMode == FALSE) - if (pAd->StaCfg.WepStatus != - pInBss->WPA.GroupCipher) - continue; - - /* check group cipher */ - if (pAd->StaCfg.WepStatus < - pInBss->WPA.GroupCipher) - continue; - - /* check pairwise cipher, skip if none matched */ - /* If profile set to AES, let it pass without question. */ - /* If profile set to TKIP, we must find one mateched */ - if ((pAd->StaCfg.WepStatus == - Ndis802_11Encryption2Enabled) - && (pAd->StaCfg.WepStatus != - pInBss->WPA.PairCipher) - && (pAd->StaCfg.WepStatus != - pInBss->WPA.PairCipherAux)) - continue; - } else - if ((pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA2) - || (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA2PSK)) { - /* If it's not mixed mode, we should only let BSS pass with the same encryption */ - if (pInBss->WPA2.bMixMode == FALSE) - if (pAd->StaCfg.WepStatus != - pInBss->WPA2.GroupCipher) - continue; - - /* check group cipher */ - if (pAd->StaCfg.WepStatus < - pInBss->WPA2.GroupCipher) - continue; - - /* check pairwise cipher, skip if none matched */ - /* If profile set to AES, let it pass without question. */ - /* If profile set to TKIP, we must find one mateched */ - if ((pAd->StaCfg.WepStatus == - Ndis802_11Encryption2Enabled) - && (pAd->StaCfg.WepStatus != - pInBss->WPA2.PairCipher) - && (pAd->StaCfg.WepStatus != - pInBss->WPA2.PairCipherAux)) - continue; - } - } - /* Bss Type matched, SSID matched. */ - /* We will check wepstatus for qualification Bss */ - else if (pAd->StaCfg.WepStatus != pInBss->WepStatus) - continue; - - /* If both station and AP use 40MHz, still need to check if the 40MHZ band's legality in my country region */ - /* If this 40MHz wideband is not allowed in my country list, use bandwidth 20MHZ instead, */ - if ((pInBss->CentralChannel != pInBss->Channel) && - (pAd->CommonCfg.RegTransmitSetting.field.BW == - BW_40)) { - if (RTMPCheckChannel - (pAd, pInBss->CentralChannel, - pInBss->Channel) == FALSE) { - pAd->CommonCfg.RegTransmitSetting.field. - BW = BW_20; - SetCommonHT(pAd); - pAd->CommonCfg.RegTransmitSetting.field. - BW = BW_40; - } - } - /* copy matching BSS from InTab to OutTab */ - NdisMoveMemory(pOutBss, pInBss, sizeof(struct rt_bss_entry)); - - OutTab->BssNr++; - } - - if (OutTab->BssNr >= MAX_LEN_OF_BSS_TABLE) - break; - } - - BssTableSortByRssi(OutTab); -} - -/* IRQL = DISPATCH_LEVEL */ -void BssTableSortByRssi(struct rt_bss_table *OutTab) -{ - int i, j; - struct rt_bss_entry TmpBss; - - for (i = 0; i < OutTab->BssNr - 1; i++) { - for (j = i + 1; j < OutTab->BssNr; j++) { - if (OutTab->BssEntry[j].Rssi > OutTab->BssEntry[i].Rssi) { - NdisMoveMemory(&TmpBss, &OutTab->BssEntry[j], - sizeof(struct rt_bss_entry)); - NdisMoveMemory(&OutTab->BssEntry[j], - &OutTab->BssEntry[i], - sizeof(struct rt_bss_entry)); - NdisMoveMemory(&OutTab->BssEntry[i], &TmpBss, - sizeof(struct rt_bss_entry)); - } - } - } -} - -void BssCipherParse(struct rt_bss_entry *pBss) -{ - struct rt_eid * pEid; - u8 *pTmp; - struct rt_rsn_ie_header * pRsnHeader; - struct rt_cipher_suite_struct * pCipher; - struct rt_akm_suite * pAKM; - u16 Count; - int Length; - NDIS_802_11_ENCRYPTION_STATUS TmpCipher; - - /* */ - /* WepStatus will be reset later, if AP announce TKIP or AES on the beacon frame. */ - /* */ - if (pBss->Privacy) { - pBss->WepStatus = Ndis802_11WEPEnabled; - } else { - pBss->WepStatus = Ndis802_11WEPDisabled; - } - /* Set default to disable & open authentication before parsing variable IE */ - pBss->AuthMode = Ndis802_11AuthModeOpen; - pBss->AuthModeAux = Ndis802_11AuthModeOpen; - - /* Init WPA setting */ - pBss->WPA.PairCipher = Ndis802_11WEPDisabled; - pBss->WPA.PairCipherAux = Ndis802_11WEPDisabled; - pBss->WPA.GroupCipher = Ndis802_11WEPDisabled; - pBss->WPA.RsnCapability = 0; - pBss->WPA.bMixMode = FALSE; - - /* Init WPA2 setting */ - pBss->WPA2.PairCipher = Ndis802_11WEPDisabled; - pBss->WPA2.PairCipherAux = Ndis802_11WEPDisabled; - pBss->WPA2.GroupCipher = Ndis802_11WEPDisabled; - pBss->WPA2.RsnCapability = 0; - pBss->WPA2.bMixMode = FALSE; - - Length = (int)pBss->VarIELen; - - while (Length > 0) { - /* Parse cipher suite base on WPA1 & WPA2, they should be parsed differently */ - pTmp = ((u8 *)pBss->VarIEs) + pBss->VarIELen - Length; - pEid = (struct rt_eid *) pTmp; - switch (pEid->Eid) { - case IE_WPA: - if (NdisEqualMemory(pEid->Octet, SES_OUI, 3) - && (pEid->Len == 7)) { - pBss->bSES = TRUE; - break; - } else if (NdisEqualMemory(pEid->Octet, WPA_OUI, 4) != - 1) { - /* if unsupported vendor specific IE */ - break; - } - /* Skip OUI, version, and multicast suite */ - /* This part should be improved in the future when AP supported multiple cipher suite. */ - /* For now, it's OK since almost all APs have fixed cipher suite supported. */ - /* pTmp = (u8 *)pEid->Octet; */ - pTmp += 11; - - /* Cipher Suite Selectors from Spec P802.11i/D3.2 P26. */ - /* Value Meaning */ - /* 0 None */ - /* 1 WEP-40 */ - /* 2 Tkip */ - /* 3 WRAP */ - /* 4 AES */ - /* 5 WEP-104 */ - /* Parse group cipher */ - switch (*pTmp) { - case 1: - pBss->WPA.GroupCipher = - Ndis802_11GroupWEP40Enabled; - break; - case 5: - pBss->WPA.GroupCipher = - Ndis802_11GroupWEP104Enabled; - break; - case 2: - pBss->WPA.GroupCipher = - Ndis802_11Encryption2Enabled; - break; - case 4: - pBss->WPA.GroupCipher = - Ndis802_11Encryption3Enabled; - break; - default: - break; - } - /* number of unicast suite */ - pTmp += 1; - - /* skip all unicast cipher suites */ - /*Count = *(u16 *)pTmp; */ - Count = (pTmp[1] << 8) + pTmp[0]; - pTmp += sizeof(u16); - - /* Parsing all unicast cipher suite */ - while (Count > 0) { - /* Skip OUI */ - pTmp += 3; - TmpCipher = Ndis802_11WEPDisabled; - switch (*pTmp) { - case 1: - case 5: /* Although WEP is not allowed in WPA related auth mode, we parse it anyway */ - TmpCipher = - Ndis802_11Encryption1Enabled; - break; - case 2: - TmpCipher = - Ndis802_11Encryption2Enabled; - break; - case 4: - TmpCipher = - Ndis802_11Encryption3Enabled; - break; - default: - break; - } - if (TmpCipher > pBss->WPA.PairCipher) { - /* Move the lower cipher suite to PairCipherAux */ - pBss->WPA.PairCipherAux = - pBss->WPA.PairCipher; - pBss->WPA.PairCipher = TmpCipher; - } else { - pBss->WPA.PairCipherAux = TmpCipher; - } - pTmp++; - Count--; - } - - /* 4. get AKM suite counts */ - /*Count = *(u16 *)pTmp; */ - Count = (pTmp[1] << 8) + pTmp[0]; - pTmp += sizeof(u16); - pTmp += 3; - - switch (*pTmp) { - case 1: - /* Set AP support WPA-enterprise mode */ - if (pBss->AuthMode == Ndis802_11AuthModeOpen) - pBss->AuthMode = Ndis802_11AuthModeWPA; - else - pBss->AuthModeAux = - Ndis802_11AuthModeWPA; - break; - case 2: - /* Set AP support WPA-PSK mode */ - if (pBss->AuthMode == Ndis802_11AuthModeOpen) - pBss->AuthMode = - Ndis802_11AuthModeWPAPSK; - else - pBss->AuthModeAux = - Ndis802_11AuthModeWPAPSK; - break; - default: - break; - } - pTmp += 1; - - /* Fixed for WPA-None */ - if (pBss->BssType == BSS_ADHOC) { - pBss->AuthMode = Ndis802_11AuthModeWPANone; - pBss->AuthModeAux = Ndis802_11AuthModeWPANone; - pBss->WepStatus = pBss->WPA.GroupCipher; - /* Patched bugs for old driver */ - if (pBss->WPA.PairCipherAux == - Ndis802_11WEPDisabled) - pBss->WPA.PairCipherAux = - pBss->WPA.GroupCipher; - } else - pBss->WepStatus = pBss->WPA.PairCipher; - - /* Check the Pair & Group, if different, turn on mixed mode flag */ - if (pBss->WPA.GroupCipher != pBss->WPA.PairCipher) - pBss->WPA.bMixMode = TRUE; - - break; - - case IE_RSN: - pRsnHeader = (struct rt_rsn_ie_header *) pTmp; - - /* 0. Version must be 1 */ - if (le2cpu16(pRsnHeader->Version) != 1) - break; - pTmp += sizeof(struct rt_rsn_ie_header); - - /* 1. Check group cipher */ - pCipher = (struct rt_cipher_suite_struct *) pTmp; - if (!RTMPEqualMemory(pTmp, RSN_OUI, 3)) - break; - - /* Parse group cipher */ - switch (pCipher->Type) { - case 1: - pBss->WPA2.GroupCipher = - Ndis802_11GroupWEP40Enabled; - break; - case 5: - pBss->WPA2.GroupCipher = - Ndis802_11GroupWEP104Enabled; - break; - case 2: - pBss->WPA2.GroupCipher = - Ndis802_11Encryption2Enabled; - break; - case 4: - pBss->WPA2.GroupCipher = - Ndis802_11Encryption3Enabled; - break; - default: - break; - } - /* set to correct offset for next parsing */ - pTmp += sizeof(struct rt_cipher_suite_struct); - - /* 2. Get pairwise cipher counts */ - /*Count = *(u16 *)pTmp; */ - Count = (pTmp[1] << 8) + pTmp[0]; - pTmp += sizeof(u16); - - /* 3. Get pairwise cipher */ - /* Parsing all unicast cipher suite */ - while (Count > 0) { - /* Skip OUI */ - pCipher = (struct rt_cipher_suite_struct *) pTmp; - TmpCipher = Ndis802_11WEPDisabled; - switch (pCipher->Type) { - case 1: - case 5: /* Although WEP is not allowed in WPA related auth mode, we parse it anyway */ - TmpCipher = - Ndis802_11Encryption1Enabled; - break; - case 2: - TmpCipher = - Ndis802_11Encryption2Enabled; - break; - case 4: - TmpCipher = - Ndis802_11Encryption3Enabled; - break; - default: - break; - } - if (TmpCipher > pBss->WPA2.PairCipher) { - /* Move the lower cipher suite to PairCipherAux */ - pBss->WPA2.PairCipherAux = - pBss->WPA2.PairCipher; - pBss->WPA2.PairCipher = TmpCipher; - } else { - pBss->WPA2.PairCipherAux = TmpCipher; - } - pTmp += sizeof(struct rt_cipher_suite_struct); - Count--; - } - - /* 4. get AKM suite counts */ - /*Count = *(u16 *)pTmp; */ - Count = (pTmp[1] << 8) + pTmp[0]; - pTmp += sizeof(u16); - - /* 5. Get AKM ciphers */ - /* Parsing all AKM ciphers */ - while (Count > 0) { - pAKM = (struct rt_akm_suite *) pTmp; - if (!RTMPEqualMemory(pTmp, RSN_OUI, 3)) - break; - - switch (pAKM->Type) { - case 1: - /* Set AP support WPA-enterprise mode */ - if (pBss->AuthMode == - Ndis802_11AuthModeOpen) - pBss->AuthMode = - Ndis802_11AuthModeWPA2; - else - pBss->AuthModeAux = - Ndis802_11AuthModeWPA2; - break; - case 2: - /* Set AP support WPA-PSK mode */ - if (pBss->AuthMode == - Ndis802_11AuthModeOpen) - pBss->AuthMode = - Ndis802_11AuthModeWPA2PSK; - else - pBss->AuthModeAux = - Ndis802_11AuthModeWPA2PSK; - break; - default: - if (pBss->AuthMode == - Ndis802_11AuthModeOpen) - pBss->AuthMode = - Ndis802_11AuthModeMax; - else - pBss->AuthModeAux = - Ndis802_11AuthModeMax; - break; - } - pTmp += (Count * sizeof(struct rt_akm_suite)); - Count--; - } - - /* Fixed for WPA-None */ - if (pBss->BssType == BSS_ADHOC) { - pBss->AuthMode = Ndis802_11AuthModeWPANone; - pBss->AuthModeAux = Ndis802_11AuthModeWPANone; - pBss->WPA.PairCipherAux = - pBss->WPA2.PairCipherAux; - pBss->WPA.GroupCipher = pBss->WPA2.GroupCipher; - pBss->WepStatus = pBss->WPA.GroupCipher; - /* Patched bugs for old driver */ - if (pBss->WPA.PairCipherAux == - Ndis802_11WEPDisabled) - pBss->WPA.PairCipherAux = - pBss->WPA.GroupCipher; - } - pBss->WepStatus = pBss->WPA2.PairCipher; - - /* 6. Get RSN capability */ - /*pBss->WPA2.RsnCapability = *(u16 *)pTmp; */ - pBss->WPA2.RsnCapability = (pTmp[1] << 8) + pTmp[0]; - pTmp += sizeof(u16); - - /* Check the Pair & Group, if different, turn on mixed mode flag */ - if (pBss->WPA2.GroupCipher != pBss->WPA2.PairCipher) - pBss->WPA2.bMixMode = TRUE; - - break; - default: - break; - } - Length -= (pEid->Len + 2); - } -} - -/* =========================================================================================== */ -/* mac_table.c */ -/* =========================================================================================== */ - -/*! \brief generates a random mac address value for IBSS BSSID - * \param Addr the bssid location - * \return none - * \pre - * \post - */ -void MacAddrRandomBssid(struct rt_rtmp_adapter *pAd, u8 *pAddr) -{ - int i; - - for (i = 0; i < MAC_ADDR_LEN; i++) { - pAddr[i] = RandomByte(pAd); - } - - pAddr[0] = (pAddr[0] & 0xfe) | 0x02; /* the first 2 bits must be 01xxxxxxxx */ -} - -/*! \brief init the management mac frame header - * \param p_hdr mac header - * \param subtype subtype of the frame - * \param p_ds destination address, don't care if it is a broadcast address - * \return none - * \pre the station has the following information in the pAd->StaCfg - * - bssid - * - station address - * \post - * \note this function initializes the following field - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - */ -void MgtMacHeaderInit(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 * pHdr80211, - u8 SubType, - u8 ToDs, u8 *pDA, u8 *pBssid) -{ - NdisZeroMemory(pHdr80211, sizeof(struct rt_header_802_11)); - - pHdr80211->FC.Type = BTYPE_MGMT; - pHdr80211->FC.SubType = SubType; -/* if (SubType == SUBTYPE_ACK) // sample, no use, it will conflict with ACTION frame sub type */ -/* pHdr80211->FC.Type = BTYPE_CNTL; */ - pHdr80211->FC.ToDs = ToDs; - COPY_MAC_ADDR(pHdr80211->Addr1, pDA); - COPY_MAC_ADDR(pHdr80211->Addr2, pAd->CurrentAddress); - COPY_MAC_ADDR(pHdr80211->Addr3, pBssid); -} - -/* =========================================================================================== */ -/* mem_mgmt.c */ -/* =========================================================================================== */ - -/*!*************************************************************************** - * This routine build an outgoing frame, and fill all information specified - * in argument list to the frame body. The actual frame size is the summation - * of all arguments. - * input params: - * Buffer - pointer to a pre-allocated memory segment - * args - a list of pairs. - * NOTE NOTE NOTE! the last argument must be NULL, otherwise this - * function will FAIL! - * return: - * Size of the buffer - * usage: - * MakeOutgoingFrame(Buffer, output_length, 2, &fc, 2, &dur, 6, p_addr1, 6,p_addr2, END_OF_ARGS); - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ****************************************************************************/ -unsigned long MakeOutgoingFrame(u8 * Buffer, unsigned long * FrameLen, ...) -{ - u8 *p; - int leng; - unsigned long TotLeng; - va_list Args; - - /* calculates the total length */ - TotLeng = 0; - va_start(Args, FrameLen); - do { - leng = va_arg(Args, int); - if (leng == END_OF_ARGS) { - break; - } - p = va_arg(Args, void *); - NdisMoveMemory(&Buffer[TotLeng], p, leng); - TotLeng = TotLeng + leng; - } while (TRUE); - - va_end(Args); /* clean up */ - *FrameLen = TotLeng; - return TotLeng; -} - -/* =========================================================================================== */ -/* mlme_queue.c */ -/* =========================================================================================== */ - -/*! \brief Initialize The MLME Queue, used by MLME Functions - * \param *Queue The MLME Queue - * \return Always Return NDIS_STATE_SUCCESS in this implementation - * \pre - * \post - * \note Because this is done only once (at the init stage), no need to be locked - - IRQL = PASSIVE_LEVEL - - */ -int MlmeQueueInit(struct rt_mlme_queue *Queue) -{ - int i; - - NdisAllocateSpinLock(&Queue->Lock); - - Queue->Num = 0; - Queue->Head = 0; - Queue->Tail = 0; - - for (i = 0; i < MAX_LEN_OF_MLME_QUEUE; i++) { - Queue->Entry[i].Occupied = FALSE; - Queue->Entry[i].MsgLen = 0; - NdisZeroMemory(Queue->Entry[i].Msg, MGMT_DMA_BUFFER_SIZE); - } - - return NDIS_STATUS_SUCCESS; -} - -/*! \brief Enqueue a message for other threads, if they want to send messages to MLME thread - * \param *Queue The MLME Queue - * \param Machine The State Machine Id - * \param MsgType The Message Type - * \param MsgLen The Message length - * \param *Msg The message pointer - * \return TRUE if enqueue is successful, FALSE if the queue is full - * \pre - * \post - * \note The message has to be initialized - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - */ -BOOLEAN MlmeEnqueue(struct rt_rtmp_adapter *pAd, - unsigned long Machine, - unsigned long MsgType, unsigned long MsgLen, void * Msg) -{ - int Tail; - struct rt_mlme_queue *Queue = (struct rt_mlme_queue *)& pAd->Mlme.Queue; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return FALSE; - - /* First check the size, it MUST not exceed the mlme queue size */ - if (MsgLen > MGMT_DMA_BUFFER_SIZE) { - DBGPRINT_ERR("MlmeEnqueue: msg too large, size = %ld \n", MsgLen); - return FALSE; - } - - if (MlmeQueueFull(Queue)) { - return FALSE; - } - - NdisAcquireSpinLock(&(Queue->Lock)); - Tail = Queue->Tail; - Queue->Tail++; - Queue->Num++; - if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE) { - Queue->Tail = 0; - } - - Queue->Entry[Tail].Wcid = RESERVED_WCID; - Queue->Entry[Tail].Occupied = TRUE; - Queue->Entry[Tail].Machine = Machine; - Queue->Entry[Tail].MsgType = MsgType; - Queue->Entry[Tail].MsgLen = MsgLen; - - if (Msg != NULL) { - NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen); - } - - NdisReleaseSpinLock(&(Queue->Lock)); - return TRUE; -} - -/*! \brief This function is used when Recv gets a MLME message - * \param *Queue The MLME Queue - * \param TimeStampHigh The upper 32 bit of timestamp - * \param TimeStampLow The lower 32 bit of timestamp - * \param Rssi The receiving RSSI strength - * \param MsgLen The length of the message - * \param *Msg The message pointer - * \return TRUE if everything ok, FALSE otherwise (like Queue Full) - * \pre - * \post - - IRQL = DISPATCH_LEVEL - - */ -BOOLEAN MlmeEnqueueForRecv(struct rt_rtmp_adapter *pAd, - unsigned long Wcid, - unsigned long TimeStampHigh, - unsigned long TimeStampLow, - u8 Rssi0, - u8 Rssi1, - u8 Rssi2, - unsigned long MsgLen, void * Msg, u8 Signal) -{ - int Tail, Machine; - struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg; - int MsgType; - struct rt_mlme_queue *Queue = (struct rt_mlme_queue *)& pAd->Mlme.Queue; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, - fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) { - DBGPRINT_ERR("MlmeEnqueueForRecv: fRTMP_ADAPTER_HALT_IN_PROGRESS\n"); - return FALSE; - } - /* First check the size, it MUST not exceed the mlme queue size */ - if (MsgLen > MGMT_DMA_BUFFER_SIZE) { - DBGPRINT_ERR("MlmeEnqueueForRecv: frame too large, size = %ld \n", MsgLen); - return FALSE; - } - - if (MlmeQueueFull(Queue)) { - return FALSE; - } - - { - if (!MsgTypeSubst(pAd, pFrame, &Machine, &MsgType)) { - DBGPRINT_ERR("MlmeEnqueueForRecv: un-recongnized mgmt->subtype=%d\n", pFrame->Hdr.FC.SubType); - return FALSE; - } - } - - /* OK, we got all the informations, it is time to put things into queue */ - NdisAcquireSpinLock(&(Queue->Lock)); - Tail = Queue->Tail; - Queue->Tail++; - Queue->Num++; - if (Queue->Tail == MAX_LEN_OF_MLME_QUEUE) { - Queue->Tail = 0; - } - Queue->Entry[Tail].Occupied = TRUE; - Queue->Entry[Tail].Machine = Machine; - Queue->Entry[Tail].MsgType = MsgType; - Queue->Entry[Tail].MsgLen = MsgLen; - Queue->Entry[Tail].TimeStamp.u.LowPart = TimeStampLow; - Queue->Entry[Tail].TimeStamp.u.HighPart = TimeStampHigh; - Queue->Entry[Tail].Rssi0 = Rssi0; - Queue->Entry[Tail].Rssi1 = Rssi1; - Queue->Entry[Tail].Rssi2 = Rssi2; - Queue->Entry[Tail].Signal = Signal; - Queue->Entry[Tail].Wcid = (u8)Wcid; - - Queue->Entry[Tail].Channel = pAd->LatchRfRegs.Channel; - - if (Msg != NULL) { - NdisMoveMemory(Queue->Entry[Tail].Msg, Msg, MsgLen); - } - - NdisReleaseSpinLock(&(Queue->Lock)); - - RTMP_MLME_HANDLER(pAd); - - return TRUE; -} - -/*! \brief Dequeue a message from the MLME Queue - * \param *Queue The MLME Queue - * \param *Elem The message dequeued from MLME Queue - * \return TRUE if the Elem contains something, FALSE otherwise - * \pre - * \post - - IRQL = DISPATCH_LEVEL - - */ -BOOLEAN MlmeDequeue(struct rt_mlme_queue *Queue, struct rt_mlme_queue_elem ** Elem) -{ - NdisAcquireSpinLock(&(Queue->Lock)); - *Elem = &(Queue->Entry[Queue->Head]); - Queue->Num--; - Queue->Head++; - if (Queue->Head == MAX_LEN_OF_MLME_QUEUE) { - Queue->Head = 0; - } - NdisReleaseSpinLock(&(Queue->Lock)); - return TRUE; -} - -/* IRQL = DISPATCH_LEVEL */ -void MlmeRestartStateMachine(struct rt_rtmp_adapter *pAd) -{ -#ifdef RTMP_MAC_PCI - struct rt_mlme_queue_elem *Elem = NULL; -#endif /* RTMP_MAC_PCI // */ - BOOLEAN Cancelled; - - DBGPRINT(RT_DEBUG_TRACE, ("MlmeRestartStateMachine \n")); - -#ifdef RTMP_MAC_PCI - NdisAcquireSpinLock(&pAd->Mlme.TaskLock); - if (pAd->Mlme.bRunning) { - NdisReleaseSpinLock(&pAd->Mlme.TaskLock); - return; - } else { - pAd->Mlme.bRunning = TRUE; - } - NdisReleaseSpinLock(&pAd->Mlme.TaskLock); - - /* Remove all Mlme queues elements */ - while (!MlmeQueueEmpty(&pAd->Mlme.Queue)) { - /*From message type, determine which state machine I should drive */ - if (MlmeDequeue(&pAd->Mlme.Queue, &Elem)) { - /* free MLME element */ - Elem->Occupied = FALSE; - Elem->MsgLen = 0; - - } else { - DBGPRINT_ERR("MlmeRestartStateMachine: MlmeQueue empty\n"); - } - } -#endif /* RTMP_MAC_PCI // */ - - { - /* Cancel all timer events */ - /* Be careful to cancel new added timer */ - RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &Cancelled); - RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &Cancelled); - RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled); - RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, &Cancelled); - RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &Cancelled); - RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &Cancelled); - - } - - /* Change back to original channel in case of doing scan */ - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.Channel); - - /* Resume MSDU which is turned off durning scan */ - RTMPResumeMsduTransmission(pAd); - - { - /* Set all state machines back IDLE */ - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; - pAd->Mlme.AuthRspMachine.CurrState = AUTH_RSP_IDLE; - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - pAd->Mlme.ActMachine.CurrState = ACT_IDLE; - } - -#ifdef RTMP_MAC_PCI - /* Remove running state */ - NdisAcquireSpinLock(&pAd->Mlme.TaskLock); - pAd->Mlme.bRunning = FALSE; - NdisReleaseSpinLock(&pAd->Mlme.TaskLock); -#endif /* RTMP_MAC_PCI // */ -} - -/*! \brief test if the MLME Queue is empty - * \param *Queue The MLME Queue - * \return TRUE if the Queue is empty, FALSE otherwise - * \pre - * \post - - IRQL = DISPATCH_LEVEL - - */ -BOOLEAN MlmeQueueEmpty(struct rt_mlme_queue *Queue) -{ - BOOLEAN Ans; - - NdisAcquireSpinLock(&(Queue->Lock)); - Ans = (Queue->Num == 0); - NdisReleaseSpinLock(&(Queue->Lock)); - - return Ans; -} - -/*! \brief test if the MLME Queue is full - * \param *Queue The MLME Queue - * \return TRUE if the Queue is empty, FALSE otherwise - * \pre - * \post - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - */ -BOOLEAN MlmeQueueFull(struct rt_mlme_queue *Queue) -{ - BOOLEAN Ans; - - NdisAcquireSpinLock(&(Queue->Lock)); - Ans = (Queue->Num == MAX_LEN_OF_MLME_QUEUE - || Queue->Entry[Queue->Tail].Occupied); - NdisReleaseSpinLock(&(Queue->Lock)); - - return Ans; -} - -/*! \brief The destructor of MLME Queue - * \param - * \return - * \pre - * \post - * \note Clear Mlme Queue, Set Queue->Num to Zero. - - IRQL = PASSIVE_LEVEL - - */ -void MlmeQueueDestroy(struct rt_mlme_queue *pQueue) -{ - NdisAcquireSpinLock(&(pQueue->Lock)); - pQueue->Num = 0; - pQueue->Head = 0; - pQueue->Tail = 0; - NdisReleaseSpinLock(&(pQueue->Lock)); - NdisFreeSpinLock(&(pQueue->Lock)); -} - -/*! \brief To substitute the message type if the message is coming from external - * \param pFrame The frame received - * \param *Machine The state machine - * \param *MsgType the message type for the state machine - * \return TRUE if the substitution is successful, FALSE otherwise - * \pre - * \post - - IRQL = DISPATCH_LEVEL - - */ -BOOLEAN MsgTypeSubst(struct rt_rtmp_adapter *pAd, - struct rt_frame_802_11 * pFrame, - int * Machine, int * MsgType) -{ - u16 Seq, Alg; - u8 EAPType; - u8 *pData; - - /* Pointer to start of data frames including SNAP header */ - pData = (u8 *)pFrame + LENGTH_802_11; - - /* The only data type will pass to this function is EAPOL frame */ - if (pFrame->Hdr.FC.Type == BTYPE_DATA) { - { - *Machine = WPA_STATE_MACHINE; - EAPType = - *((u8 *) pFrame + LENGTH_802_11 + - LENGTH_802_1_H + 1); - return (WpaMsgTypeSubst(EAPType, (int *) MsgType)); - } - } - - switch (pFrame->Hdr.FC.SubType) { - case SUBTYPE_ASSOC_REQ: - *Machine = ASSOC_STATE_MACHINE; - *MsgType = MT2_PEER_ASSOC_REQ; - break; - case SUBTYPE_ASSOC_RSP: - *Machine = ASSOC_STATE_MACHINE; - *MsgType = MT2_PEER_ASSOC_RSP; - break; - case SUBTYPE_REASSOC_REQ: - *Machine = ASSOC_STATE_MACHINE; - *MsgType = MT2_PEER_REASSOC_REQ; - break; - case SUBTYPE_REASSOC_RSP: - *Machine = ASSOC_STATE_MACHINE; - *MsgType = MT2_PEER_REASSOC_RSP; - break; - case SUBTYPE_PROBE_REQ: - *Machine = SYNC_STATE_MACHINE; - *MsgType = MT2_PEER_PROBE_REQ; - break; - case SUBTYPE_PROBE_RSP: - *Machine = SYNC_STATE_MACHINE; - *MsgType = MT2_PEER_PROBE_RSP; - break; - case SUBTYPE_BEACON: - *Machine = SYNC_STATE_MACHINE; - *MsgType = MT2_PEER_BEACON; - break; - case SUBTYPE_ATIM: - *Machine = SYNC_STATE_MACHINE; - *MsgType = MT2_PEER_ATIM; - break; - case SUBTYPE_DISASSOC: - *Machine = ASSOC_STATE_MACHINE; - *MsgType = MT2_PEER_DISASSOC_REQ; - break; - case SUBTYPE_AUTH: - /* get the sequence number from payload 24 Mac Header + 2 bytes algorithm */ - NdisMoveMemory(&Seq, &pFrame->Octet[2], sizeof(u16)); - NdisMoveMemory(&Alg, &pFrame->Octet[0], sizeof(u16)); - if (Seq == 1 || Seq == 3) { - *Machine = AUTH_RSP_STATE_MACHINE; - *MsgType = MT2_PEER_AUTH_ODD; - } else if (Seq == 2 || Seq == 4) { - if (Alg == AUTH_MODE_OPEN || Alg == AUTH_MODE_KEY) { - *Machine = AUTH_STATE_MACHINE; - *MsgType = MT2_PEER_AUTH_EVEN; - } - } else { - return FALSE; - } - break; - case SUBTYPE_DEAUTH: - *Machine = AUTH_RSP_STATE_MACHINE; - *MsgType = MT2_PEER_DEAUTH; - break; - case SUBTYPE_ACTION: - *Machine = ACTION_STATE_MACHINE; - /* Sometimes Sta will return with category bytes with MSB = 1, if they receive catogory out of their support */ - if ((pFrame->Octet[0] & 0x7F) > MAX_PEER_CATE_MSG) { - *MsgType = MT2_ACT_INVALID; - } else { - *MsgType = (pFrame->Octet[0] & 0x7F); - } - break; - default: - return FALSE; - break; - } - - return TRUE; -} - -/* =========================================================================================== */ -/* state_machine.c */ -/* =========================================================================================== */ - -/*! \brief Initialize the state machine. - * \param *S pointer to the state machine - * \param Trans State machine transition function - * \param StNr number of states - * \param MsgNr number of messages - * \param DefFunc default function, when there is invalid state/message combination - * \param InitState initial state of the state machine - * \param Base StateMachine base, internal use only - * \pre p_sm should be a legal pointer - * \post - - IRQL = PASSIVE_LEVEL - - */ -void StateMachineInit(struct rt_state_machine *S, - IN STATE_MACHINE_FUNC Trans[], - unsigned long StNr, - unsigned long MsgNr, - IN STATE_MACHINE_FUNC DefFunc, - unsigned long InitState, unsigned long Base) -{ - unsigned long i, j; - - /* set number of states and messages */ - S->NrState = StNr; - S->NrMsg = MsgNr; - S->Base = Base; - - S->TransFunc = Trans; - - /* init all state transition to default function */ - for (i = 0; i < StNr; i++) { - for (j = 0; j < MsgNr; j++) { - S->TransFunc[i * MsgNr + j] = DefFunc; - } - } - - /* set the starting state */ - S->CurrState = InitState; -} - -/*! \brief This function fills in the function pointer into the cell in the state machine - * \param *S pointer to the state machine - * \param St state - * \param Msg incoming message - * \param f the function to be executed when (state, message) combination occurs at the state machine - * \pre *S should be a legal pointer to the state machine, st, msg, should be all within the range, Base should be set in the initial state - * \post - - IRQL = PASSIVE_LEVEL - - */ -void StateMachineSetAction(struct rt_state_machine *S, - unsigned long St, - unsigned long Msg, IN STATE_MACHINE_FUNC Func) -{ - unsigned long MsgIdx; - - MsgIdx = Msg - S->Base; - - if (St < S->NrState && MsgIdx < S->NrMsg) { - /* boundary checking before setting the action */ - S->TransFunc[St * S->NrMsg + MsgIdx] = Func; - } -} - -/*! \brief This function does the state transition - * \param *Adapter the NIC adapter pointer - * \param *S the state machine - * \param *Elem the message to be executed - * \return None - - IRQL = DISPATCH_LEVEL - - */ -void StateMachinePerformAction(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *S, struct rt_mlme_queue_elem *Elem) -{ - (*(S->TransFunc[S->CurrState * S->NrMsg + Elem->MsgType - S->Base])) - (pAd, Elem); -} - -/* - ========================================================================== - Description: - The drop function, when machine executes this, the message is simply - ignored. This function does nothing, the message is freed in - StateMachinePerformAction() - ========================================================================== - */ -void Drop(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ -} - -/* =========================================================================================== */ -/* lfsr.c */ -/* =========================================================================================== */ - -/* - ========================================================================== - Description: - - IRQL = PASSIVE_LEVEL - - ========================================================================== - */ -void LfsrInit(struct rt_rtmp_adapter *pAd, unsigned long Seed) -{ - if (Seed == 0) - pAd->Mlme.ShiftReg = 1; - else - pAd->Mlme.ShiftReg = Seed; -} - -/* - ========================================================================== - Description: - ========================================================================== - */ -u8 RandomByte(struct rt_rtmp_adapter *pAd) -{ - unsigned long i; - u8 R, Result; - - R = 0; - - if (pAd->Mlme.ShiftReg == 0) - NdisGetSystemUpTime((unsigned long *) & pAd->Mlme.ShiftReg); - - for (i = 0; i < 8; i++) { - if (pAd->Mlme.ShiftReg & 0x00000001) { - pAd->Mlme.ShiftReg = - ((pAd->Mlme. - ShiftReg ^ LFSR_MASK) >> 1) | 0x80000000; - Result = 1; - } else { - pAd->Mlme.ShiftReg = pAd->Mlme.ShiftReg >> 1; - Result = 0; - } - R = (R << 1) | Result; - } - - return R; -} - -/* - ======================================================================== - - Routine Description: - Verify the support rate for different PHY type - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - ======================================================================== -*/ -void RTMPCheckRates(struct rt_rtmp_adapter *pAd, - IN u8 SupRate[], IN u8 * SupRateLen) -{ - u8 RateIdx, i, j; - u8 NewRate[12], NewRateLen; - - NewRateLen = 0; - - if (pAd->CommonCfg.PhyMode == PHY_11B) - RateIdx = 4; - else - RateIdx = 12; - - /* Check for support rates exclude basic rate bit */ - for (i = 0; i < *SupRateLen; i++) - for (j = 0; j < RateIdx; j++) - if ((SupRate[i] & 0x7f) == RateIdTo500Kbps[j]) - NewRate[NewRateLen++] = SupRate[i]; - - *SupRateLen = NewRateLen; - NdisMoveMemory(SupRate, NewRate, NewRateLen); -} - -BOOLEAN RTMPCheckChannel(struct rt_rtmp_adapter *pAd, - u8 CentralChannel, u8 Channel) -{ - u8 k; - u8 UpperChannel = 0, LowerChannel = 0; - u8 NoEffectChannelinList = 0; - - /* Find upper and lower channel according to 40MHz current operation. */ - if (CentralChannel < Channel) { - UpperChannel = Channel; - if (CentralChannel > 2) - LowerChannel = CentralChannel - 2; - else - return FALSE; - } else if (CentralChannel > Channel) { - UpperChannel = CentralChannel + 2; - LowerChannel = Channel; - } - - for (k = 0; k < pAd->ChannelListNum; k++) { - if (pAd->ChannelList[k].Channel == UpperChannel) { - NoEffectChannelinList++; - } - if (pAd->ChannelList[k].Channel == LowerChannel) { - NoEffectChannelinList++; - } - } - - DBGPRINT(RT_DEBUG_TRACE, - ("Total Channel in Channel List = [%d]\n", - NoEffectChannelinList)); - if (NoEffectChannelinList == 2) - return TRUE; - else - return FALSE; -} - -/* - ======================================================================== - - Routine Description: - Verify the support rate for HT phy type - - Arguments: - pAd Pointer to our adapter - - Return Value: - FALSE if pAd->CommonCfg.SupportedHtPhy doesn't accept the pHtCapability. (AP Mode) - - IRQL = PASSIVE_LEVEL - - ======================================================================== -*/ -BOOLEAN RTMPCheckHt(struct rt_rtmp_adapter *pAd, - u8 Wcid, - struct rt_ht_capability_ie * pHtCapability, - struct rt_add_ht_info_ie * pAddHtInfo) -{ - if (Wcid >= MAX_LEN_OF_MAC_TABLE) - return FALSE; - - /* If use AMSDU, set flag. */ - if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable) - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], - fCLIENT_STATUS_AMSDU_INUSED); - /* Save Peer Capability */ - if (pHtCapability->HtCapInfo.ShortGIfor20) - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], - fCLIENT_STATUS_SGI20_CAPABLE); - if (pHtCapability->HtCapInfo.ShortGIfor40) - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], - fCLIENT_STATUS_SGI40_CAPABLE); - if (pHtCapability->HtCapInfo.TxSTBC) - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], - fCLIENT_STATUS_TxSTBC_CAPABLE); - if (pHtCapability->HtCapInfo.RxSTBC) - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], - fCLIENT_STATUS_RxSTBC_CAPABLE); - if (pAd->CommonCfg.bRdg && pHtCapability->ExtHtCapInfo.RDGSupport) { - CLIENT_STATUS_SET_FLAG(&pAd->MacTab.Content[Wcid], - fCLIENT_STATUS_RDG_CAPABLE); - } - - if (Wcid < MAX_LEN_OF_MAC_TABLE) { - pAd->MacTab.Content[Wcid].MpduDensity = - pHtCapability->HtCapParm.MpduDensity; - } - /* Will check ChannelWidth for MCSSet[4] below */ - pAd->MlmeAux.HtCapability.MCSSet[4] = 0x1; - switch (pAd->CommonCfg.RxStream) { - case 1: - pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff; - pAd->MlmeAux.HtCapability.MCSSet[1] = 0x00; - pAd->MlmeAux.HtCapability.MCSSet[2] = 0x00; - pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00; - break; - case 2: - pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff; - pAd->MlmeAux.HtCapability.MCSSet[1] = 0xff; - pAd->MlmeAux.HtCapability.MCSSet[2] = 0x00; - pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00; - break; - case 3: - pAd->MlmeAux.HtCapability.MCSSet[0] = 0xff; - pAd->MlmeAux.HtCapability.MCSSet[1] = 0xff; - pAd->MlmeAux.HtCapability.MCSSet[2] = 0xff; - pAd->MlmeAux.HtCapability.MCSSet[3] = 0x00; - break; - } - - pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth = - pAddHtInfo->AddHtInfo.RecomWidth & pAd->CommonCfg.DesiredHtPhy. - ChannelWidth; - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPCheckHt:: HtCapInfo.ChannelWidth=%d, RecomWidth=%d, DesiredHtPhy.ChannelWidth=%d, BW40MAvailForA/G=%d/%d, PhyMode=%d \n", - pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth, - pAddHtInfo->AddHtInfo.RecomWidth, - pAd->CommonCfg.DesiredHtPhy.ChannelWidth, - pAd->NicConfig2.field.BW40MAvailForA, - pAd->NicConfig2.field.BW40MAvailForG, - pAd->CommonCfg.PhyMode)); - - pAd->MlmeAux.HtCapability.HtCapInfo.GF = - pHtCapability->HtCapInfo.GF & pAd->CommonCfg.DesiredHtPhy.GF; - - /* Send Assoc Req with my HT capability. */ - pAd->MlmeAux.HtCapability.HtCapInfo.AMsduSize = - pAd->CommonCfg.DesiredHtPhy.AmsduSize; - pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs = - pAd->CommonCfg.DesiredHtPhy.MimoPs; - pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20 = - (pAd->CommonCfg.DesiredHtPhy.ShortGIfor20) & (pHtCapability-> - HtCapInfo. - ShortGIfor20); - pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40 = - (pAd->CommonCfg.DesiredHtPhy.ShortGIfor40) & (pHtCapability-> - HtCapInfo. - ShortGIfor40); - pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC = - (pAd->CommonCfg.DesiredHtPhy.TxSTBC) & (pHtCapability->HtCapInfo. - RxSTBC); - pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC = - (pAd->CommonCfg.DesiredHtPhy.RxSTBC) & (pHtCapability->HtCapInfo. - TxSTBC); - pAd->MlmeAux.HtCapability.HtCapParm.MaxRAmpduFactor = - pAd->CommonCfg.DesiredHtPhy.MaxRAmpduFactor; - pAd->MlmeAux.HtCapability.HtCapParm.MpduDensity = - pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity; - pAd->MlmeAux.HtCapability.ExtHtCapInfo.PlusHTC = - pHtCapability->ExtHtCapInfo.PlusHTC; - pAd->MacTab.Content[Wcid].HTCapability.ExtHtCapInfo.PlusHTC = - pHtCapability->ExtHtCapInfo.PlusHTC; - if (pAd->CommonCfg.bRdg) { - pAd->MlmeAux.HtCapability.ExtHtCapInfo.RDGSupport = - pHtCapability->ExtHtCapInfo.RDGSupport; - pAd->MlmeAux.HtCapability.ExtHtCapInfo.PlusHTC = 1; - } - - if (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_20) - pAd->MlmeAux.HtCapability.MCSSet[4] = 0x0; /* BW20 can't transmit MCS32 */ - - COPY_AP_HTSETTINGS_FROM_BEACON(pAd, pHtCapability); - return TRUE; -} - -/* - ======================================================================== - - Routine Description: - Verify the support rate for different PHY type - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - ======================================================================== -*/ -void RTMPUpdateMlmeRate(struct rt_rtmp_adapter *pAd) -{ - u8 MinimumRate; - u8 ProperMlmeRate; /*= RATE_54; */ - u8 i, j, RateIdx = 12; /*1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */ - BOOLEAN bMatch = FALSE; - - switch (pAd->CommonCfg.PhyMode) { - case PHY_11B: - ProperMlmeRate = RATE_11; - MinimumRate = RATE_1; - break; - case PHY_11BG_MIXED: - case PHY_11ABGN_MIXED: - case PHY_11BGN_MIXED: - if ((pAd->MlmeAux.SupRateLen == 4) && - (pAd->MlmeAux.ExtRateLen == 0)) - /* B only AP */ - ProperMlmeRate = RATE_11; - else - ProperMlmeRate = RATE_24; - - if (pAd->MlmeAux.Channel <= 14) - MinimumRate = RATE_1; - else - MinimumRate = RATE_6; - break; - case PHY_11A: - case PHY_11N_2_4G: /* rt2860 need to check mlmerate for 802.11n */ - case PHY_11GN_MIXED: - case PHY_11AGN_MIXED: - case PHY_11AN_MIXED: - case PHY_11N_5G: - ProperMlmeRate = RATE_24; - MinimumRate = RATE_6; - break; - case PHY_11ABG_MIXED: - ProperMlmeRate = RATE_24; - if (pAd->MlmeAux.Channel <= 14) - MinimumRate = RATE_1; - else - MinimumRate = RATE_6; - break; - default: /* error */ - ProperMlmeRate = RATE_1; - MinimumRate = RATE_1; - break; - } - - for (i = 0; i < pAd->MlmeAux.SupRateLen; i++) { - for (j = 0; j < RateIdx; j++) { - if ((pAd->MlmeAux.SupRate[i] & 0x7f) == - RateIdTo500Kbps[j]) { - if (j == ProperMlmeRate) { - bMatch = TRUE; - break; - } - } - } - - if (bMatch) - break; - } - - if (bMatch == FALSE) { - for (i = 0; i < pAd->MlmeAux.ExtRateLen; i++) { - for (j = 0; j < RateIdx; j++) { - if ((pAd->MlmeAux.ExtRate[i] & 0x7f) == - RateIdTo500Kbps[j]) { - if (j == ProperMlmeRate) { - bMatch = TRUE; - break; - } - } - } - - if (bMatch) - break; - } - } - - if (bMatch == FALSE) { - ProperMlmeRate = MinimumRate; - } - - pAd->CommonCfg.MlmeRate = MinimumRate; - pAd->CommonCfg.RtsRate = ProperMlmeRate; - if (pAd->CommonCfg.MlmeRate >= RATE_6) { - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; - pAd->CommonCfg.MlmeTransmit.field.MCS = - OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; - pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = - MODE_OFDM; - pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = - OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; - } else { - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_CCK; - pAd->CommonCfg.MlmeTransmit.field.MCS = pAd->CommonCfg.MlmeRate; - pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = - MODE_CCK; - pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = - pAd->CommonCfg.MlmeRate; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPUpdateMlmeRate ==> MlmeTransmit = 0x%x \n", - pAd->CommonCfg.MlmeTransmit.word)); -} - -char RTMPMaxRssi(struct rt_rtmp_adapter *pAd, - char Rssi0, char Rssi1, char Rssi2) -{ - char larger = -127; - - if ((pAd->Antenna.field.RxPath == 1) && (Rssi0 != 0)) { - larger = Rssi0; - } - - if ((pAd->Antenna.field.RxPath >= 2) && (Rssi1 != 0)) { - larger = max(Rssi0, Rssi1); - } - - if ((pAd->Antenna.field.RxPath == 3) && (Rssi2 != 0)) { - larger = max(larger, Rssi2); - } - - if (larger == -127) - larger = 0; - - return larger; -} - -/* - ======================================================================== - Routine Description: - Periodic evaluate antenna link status - - Arguments: - pAd - Adapter pointer - - Return Value: - None - - ======================================================================== -*/ -void AsicEvaluateRxAnt(struct rt_rtmp_adapter *pAd) -{ - u8 BBPR3 = 0; - - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_RADIO_OFF | - fRTMP_ADAPTER_NIC_NOT_EXIST | - fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS) || - OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) -#ifdef RT30xx - || (pAd->EepromAccess) -#endif /* RT30xx // */ -#ifdef RT3090 - || (pAd->bPCIclkOff == TRUE) -#endif /* RT3090 // */ - ) - return; - - { - /*if (pAd->StaCfg.Psm == PWR_SAVE) */ - /* return; */ - - { - - if (pAd->StaCfg.Psm == PWR_SAVE) - return; - - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); - BBPR3 &= (~0x18); - if (pAd->Antenna.field.RxPath == 3) { - BBPR3 |= (0x10); - } else if (pAd->Antenna.field.RxPath == 2) { - BBPR3 |= (0x8); - } else if (pAd->Antenna.field.RxPath == 1) { - BBPR3 |= (0x0); - } - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); -#ifdef RTMP_MAC_PCI - pAd->StaCfg.BBPR3 = BBPR3; -#endif /* RTMP_MAC_PCI // */ - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) - ) { - unsigned long TxTotalCnt = - pAd->RalinkCounters.OneSecTxNoRetryOkCount + - pAd->RalinkCounters.OneSecTxRetryOkCount + - pAd->RalinkCounters.OneSecTxFailCount; - - /* dynamic adjust antenna evaluation period according to the traffic */ - if (TxTotalCnt > 50) { - RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, - 20); - pAd->Mlme.bLowThroughput = FALSE; - } else { - RTMPSetTimer(&pAd->Mlme.RxAntEvalTimer, - 300); - pAd->Mlme.bLowThroughput = TRUE; - } - } - } - - } - -} - -/* - ======================================================================== - Routine Description: - After evaluation, check antenna link status - - Arguments: - pAd - Adapter pointer - - Return Value: - None - - ======================================================================== -*/ -void AsicRxAntEvalTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - u8 BBPR3 = 0; - char larger = -127, rssi0, rssi1, rssi2; - - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_RADIO_OFF | - fRTMP_ADAPTER_NIC_NOT_EXIST) || - OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) -#ifdef RT30xx - || (pAd->EepromAccess) -#endif /* RT30xx // */ -#ifdef RT3090 - || (pAd->bPCIclkOff == TRUE) -#endif /* RT3090 // */ - ) - return; - - { - /*if (pAd->StaCfg.Psm == PWR_SAVE) */ - /* return; */ - { - if (pAd->StaCfg.Psm == PWR_SAVE) - return; - - /* if the traffic is low, use average rssi as the criteria */ - if (pAd->Mlme.bLowThroughput == TRUE) { - rssi0 = pAd->StaCfg.RssiSample.LastRssi0; - rssi1 = pAd->StaCfg.RssiSample.LastRssi1; - rssi2 = pAd->StaCfg.RssiSample.LastRssi2; - } else { - rssi0 = pAd->StaCfg.RssiSample.AvgRssi0; - rssi1 = pAd->StaCfg.RssiSample.AvgRssi1; - rssi2 = pAd->StaCfg.RssiSample.AvgRssi2; - } - - if (pAd->Antenna.field.RxPath == 3) { - larger = max(rssi0, rssi1); - - if (larger > (rssi2 + 20)) - pAd->Mlme.RealRxPath = 2; - else - pAd->Mlme.RealRxPath = 3; - } else if (pAd->Antenna.field.RxPath == 2) { - if (rssi0 > (rssi1 + 20)) - pAd->Mlme.RealRxPath = 1; - else - pAd->Mlme.RealRxPath = 2; - } - - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); - BBPR3 &= (~0x18); - if (pAd->Mlme.RealRxPath == 3) { - BBPR3 |= (0x10); - } else if (pAd->Mlme.RealRxPath == 2) { - BBPR3 |= (0x8); - } else if (pAd->Mlme.RealRxPath == 1) { - BBPR3 |= (0x0); - } - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); -#ifdef RTMP_MAC_PCI - pAd->StaCfg.BBPR3 = BBPR3; -#endif /* RTMP_MAC_PCI // */ - } - } - -} - -void APSDPeriodicExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) - return; - - pAd->CommonCfg.TriggerTimerCount++; - -/* Driver should not send trigger frame, it should be send by application layer */ -/* - if (pAd->CommonCfg.bAPSDCapable && pAd->CommonCfg.APEdcaParm.bAPSDCapable - && (pAd->CommonCfg.bNeedSendTriggerFrame || - (((pAd->CommonCfg.TriggerTimerCount%20) == 19) && (!pAd->CommonCfg.bAPSDAC_BE || !pAd->CommonCfg.bAPSDAC_BK || !pAd->CommonCfg.bAPSDAC_VI || !pAd->CommonCfg.bAPSDAC_VO)))) - { - DBGPRINT(RT_DEBUG_TRACE,("Sending trigger frame and enter service period when support APSD\n")); - RTMPSendNullFrame(pAd, pAd->CommonCfg.TxRate, TRUE); - pAd->CommonCfg.bNeedSendTriggerFrame = FALSE; - pAd->CommonCfg.TriggerTimerCount = 0; - pAd->CommonCfg.bInServicePeriod = TRUE; - }*/ -} - -/* - ======================================================================== - Routine Description: - Set/reset MAC registers according to bPiggyBack parameter - - Arguments: - pAd - Adapter pointer - bPiggyBack - Enable / Disable Piggy-Back - - Return Value: - None - - ======================================================================== -*/ -void RTMPSetPiggyBack(struct rt_rtmp_adapter *pAd, IN BOOLEAN bPiggyBack) -{ - TX_LINK_CFG_STRUC TxLinkCfg; - - RTMP_IO_READ32(pAd, TX_LINK_CFG, &TxLinkCfg.word); - - TxLinkCfg.field.TxCFAckEn = bPiggyBack; - RTMP_IO_WRITE32(pAd, TX_LINK_CFG, TxLinkCfg.word); -} - -/* - ======================================================================== - Routine Description: - check if this entry need to switch rate automatically - - Arguments: - pAd - pEntry - - Return Value: - TURE - FALSE - - ======================================================================== -*/ -BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry) -{ - BOOLEAN result = TRUE; - - { - /* only associated STA counts */ - if (pEntry && (pEntry->ValidAsCLI) - && (pEntry->Sst == SST_ASSOC)) { - result = pAd->StaCfg.bAutoTxRateSwitch; - } else - result = FALSE; - } - - return result; -} - -BOOLEAN RTMPAutoRateSwitchCheck(struct rt_rtmp_adapter *pAd) -{ - { - if (pAd->StaCfg.bAutoTxRateSwitch) - return TRUE; - } - return FALSE; -} - -/* - ======================================================================== - Routine Description: - check if this entry need to fix tx legacy rate - - Arguments: - pAd - pEntry - - Return Value: - TURE - FALSE - - ======================================================================== -*/ -u8 RTMPStaFixedTxMode(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry) -{ - u8 tx_mode = FIXED_TXMODE_HT; - - { - tx_mode = - (u8)pAd->StaCfg.DesiredTransmitSetting.field. - FixedTxMode; - } - - return tx_mode; -} - -/* - ======================================================================== - Routine Description: - Overwrite HT Tx Mode by Fixed Legency Tx Mode, if specified. - - Arguments: - pAd - pEntry - - Return Value: - TURE - FALSE - - ======================================================================== -*/ -void RTMPUpdateLegacyTxSetting(u8 fixed_tx_mode, struct rt_mac_table_entry *pEntry) -{ - HTTRANSMIT_SETTING TransmitSetting; - - if (fixed_tx_mode == FIXED_TXMODE_HT) - return; - - TransmitSetting.word = 0; - - TransmitSetting.field.MODE = pEntry->HTPhyMode.field.MODE; - TransmitSetting.field.MCS = pEntry->HTPhyMode.field.MCS; - - if (fixed_tx_mode == FIXED_TXMODE_CCK) { - TransmitSetting.field.MODE = MODE_CCK; - /* CCK mode allow MCS 0~3 */ - if (TransmitSetting.field.MCS > MCS_3) - TransmitSetting.field.MCS = MCS_3; - } else { - TransmitSetting.field.MODE = MODE_OFDM; - /* OFDM mode allow MCS 0~7 */ - if (TransmitSetting.field.MCS > MCS_7) - TransmitSetting.field.MCS = MCS_7; - } - - if (pEntry->HTPhyMode.field.MODE >= TransmitSetting.field.MODE) { - pEntry->HTPhyMode.word = TransmitSetting.word; - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPUpdateLegacyTxSetting : wcid-%d, MODE=%s, MCS=%d \n", - pEntry->Aid, GetPhyMode(pEntry->HTPhyMode.field.MODE), - pEntry->HTPhyMode.field.MCS)); - } -} - -/* - ========================================================================== - Description: - dynamic tune BBP R66 to find a balance between sensibility and - noise isolation - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AsicStaBbpTuning(struct rt_rtmp_adapter *pAd) -{ - u8 OrigR66Value = 0, R66; /*, R66UpperBound = 0x30, R66LowerBound = 0x30; */ - char Rssi; - - /* 2860C did not support Fase CCA, therefore can't tune */ - if (pAd->MACVersion == 0x28600100) - return; - - /* */ - /* work as a STA */ - /* */ - if (pAd->Mlme.CntlMachine.CurrState != CNTL_IDLE) /* no R66 tuning when SCANNING */ - return; - - if ((pAd->OpMode == OPMODE_STA) - && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) - ) - && !(OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) -#ifdef RTMP_MAC_PCI - && (pAd->bPCIclkOff == FALSE) -#endif /* RTMP_MAC_PCI // */ - ) { - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, &OrigR66Value); - R66 = OrigR66Value; - - if (pAd->Antenna.field.RxPath > 1) - Rssi = - (pAd->StaCfg.RssiSample.AvgRssi0 + - pAd->StaCfg.RssiSample.AvgRssi1) >> 1; - else - Rssi = pAd->StaCfg.RssiSample.AvgRssi0; - - if (pAd->LatchRfRegs.Channel <= 14) { /*BG band */ -#ifdef RT30xx - /* RT3070 is a no LNA solution, it should have different control regarding to AGC gain control */ - /* Otherwise, it will have some throughput side effect when low RSSI */ - - if (IS_RT3070(pAd) || IS_RT3090(pAd) || IS_RT3572(pAd) - || IS_RT3390(pAd)) { - if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) { - R66 = - 0x1C + 2 * GET_LNA_GAIN(pAd) + 0x20; - if (OrigR66Value != R66) { - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R66, R66); - } - } else { - R66 = 0x1C + 2 * GET_LNA_GAIN(pAd); - if (OrigR66Value != R66) { - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R66, R66); - } - } - } else -#endif /* RT30xx // */ - { - if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) { - R66 = (0x2E + GET_LNA_GAIN(pAd)) + 0x10; - if (OrigR66Value != R66) { - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R66, R66); - } - } else { - R66 = 0x2E + GET_LNA_GAIN(pAd); - if (OrigR66Value != R66) { - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R66, R66); - } - } - } - } else { /*A band */ - if (pAd->CommonCfg.BBPCurrentBW == BW_20) { - if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) { - R66 = - 0x32 + (GET_LNA_GAIN(pAd) * 5) / 3 + - 0x10; - if (OrigR66Value != R66) { - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R66, R66); - } - } else { - R66 = - 0x32 + (GET_LNA_GAIN(pAd) * 5) / 3; - if (OrigR66Value != R66) { - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R66, R66); - } - } - } else { - if (Rssi > RSSI_FOR_MID_LOW_SENSIBILITY) { - R66 = - 0x3A + (GET_LNA_GAIN(pAd) * 5) / 3 + - 0x10; - if (OrigR66Value != R66) { - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R66, R66); - } - } else { - R66 = - 0x3A + (GET_LNA_GAIN(pAd) * 5) / 3; - if (OrigR66Value != R66) { - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R66, R66); - } - } - } - } - - } -} - -void RTMPSetAGCInitValue(struct rt_rtmp_adapter *pAd, u8 BandWidth) -{ - u8 R66 = 0x30; - - if (pAd->LatchRfRegs.Channel <= 14) { /* BG band */ -#ifdef RT30xx - /* Gary was verified Amazon AP and find that RT307x has BBP_R66 invalid default value */ - - if (IS_RT3070(pAd) || IS_RT3090(pAd) || IS_RT3572(pAd) - || IS_RT3390(pAd)) { - R66 = 0x1C + 2 * GET_LNA_GAIN(pAd); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); - } else -#endif /* RT30xx // */ - { - R66 = 0x2E + GET_LNA_GAIN(pAd); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); - } - } else { /*A band */ - { - if (BandWidth == BW_20) { - R66 = - (u8)(0x32 + - (GET_LNA_GAIN(pAd) * 5) / 3); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); - } else { - R66 = - (u8)(0x3A + - (GET_LNA_GAIN(pAd) * 5) / 3); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R66, R66); - } - } - } - -} diff --git a/trunk/drivers/staging/rt2860/common/rt_channel.c b/trunk/drivers/staging/rt2860/common/rt_channel.c deleted file mode 100644 index 538798981177..000000000000 --- a/trunk/drivers/staging/rt2860/common/rt_channel.c +++ /dev/null @@ -1,1705 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* -*/ -#include "../rt_config.h" - -struct rt_ch_freq_map CH_HZ_ID_MAP[] = { - {1, 2412} - , - {2, 2417} - , - {3, 2422} - , - {4, 2427} - , - {5, 2432} - , - {6, 2437} - , - {7, 2442} - , - {8, 2447} - , - {9, 2452} - , - {10, 2457} - , - {11, 2462} - , - {12, 2467} - , - {13, 2472} - , - {14, 2484} - , - - /* UNII */ - {36, 5180} - , - {40, 5200} - , - {44, 5220} - , - {48, 5240} - , - {52, 5260} - , - {56, 5280} - , - {60, 5300} - , - {64, 5320} - , - {149, 5745} - , - {153, 5765} - , - {157, 5785} - , - {161, 5805} - , - {165, 5825} - , - {167, 5835} - , - {169, 5845} - , - {171, 5855} - , - {173, 5865} - , - - /* HiperLAN2 */ - {100, 5500} - , - {104, 5520} - , - {108, 5540} - , - {112, 5560} - , - {116, 5580} - , - {120, 5600} - , - {124, 5620} - , - {128, 5640} - , - {132, 5660} - , - {136, 5680} - , - {140, 5700} - , - - /* Japan MMAC */ - {34, 5170} - , - {38, 5190} - , - {42, 5210} - , - {46, 5230} - , - - /* Japan */ - {184, 4920} - , - {188, 4940} - , - {192, 4960} - , - {196, 4980} - , - - {208, 5040} - , /* Japan, means J08 */ - {212, 5060} - , /* Japan, means J12 */ - {216, 5080} - , /* Japan, means J16 */ -}; - -int CH_HZ_ID_MAP_NUM = (sizeof(CH_HZ_ID_MAP) / sizeof(struct rt_ch_freq_map)); - -struct rt_ch_region ChRegion[] = { - { /* Antigua and Berbuda */ - "AG", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Argentina */ - "AR", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 4, 30, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Aruba */ - "AW", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Australia */ - "AU", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 5, 30, BOTH, FALSE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , - - { /* Austria */ - "AT", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, TRUE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Bahamas */ - "BS", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 5, 30, BOTH, FALSE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , - - { /* Barbados */ - "BB", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Bermuda */ - "BM", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Brazil */ - "BR", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {100, 11, 24, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {149, 5, 30, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Belgium */ - "BE", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 18, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 18, IDOR, FALSE} - , /* 5G, ch 52~64 */ - {0} - , /* end */ - } - } - , - - { /* Bulgaria */ - "BG", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, ODOR, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Canada */ - "CA", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 5, 30, BOTH, FALSE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , - - { /* Cayman IsLands */ - "KY", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Chile */ - "CL", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 20, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 20, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 5, 20, BOTH, FALSE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , - - { /* China */ - "CN", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {149, 4, 27, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Colombia */ - "CO", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 17, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {149, 5, 30, BOTH, FALSE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , - - { /* Costa Rica */ - "CR", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 17, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 4, 30, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Cyprus */ - "CY", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Czech_Republic */ - "CZ", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {0} - , /* end */ - } - } - , - - { /* Denmark */ - "DK", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Dominican Republic */ - "DO", - CE, - { - {1, 0, 20, BOTH, FALSE} - , /* 2.4 G, ch 0 */ - {149, 4, 20, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Equador */ - "EC", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {100, 11, 27, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* El Salvador */ - "SV", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 30, BOTH, TRUE} - , /* 5G, ch 52~64 */ - {149, 4, 36, BOTH, TRUE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , - - { /* Finland */ - "FI", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* France */ - "FR", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {0} - , /* end */ - } - } - , - - { /* Germany */ - "DE", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Greece */ - "GR", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, ODOR, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Guam */ - "GU", - CE, - { - {1, 11, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~11 */ - {36, 4, 17, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {149, 5, 30, BOTH, FALSE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , - - { /* Guatemala */ - "GT", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 17, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 4, 30, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Haiti */ - "HT", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 17, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 4, 30, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Honduras */ - "HN", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {149, 4, 27, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Hong Kong */ - "HK", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, FALSE} - , /* 5G, ch 52~64 */ - {149, 4, 30, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Hungary */ - "HU", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {0} - , /* end */ - } - } - , - - { /* Iceland */ - "IS", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* India */ - "IN", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {149, 4, 24, IDOR, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Indonesia */ - "ID", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {149, 4, 27, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Ireland */ - "IE", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, ODOR, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Israel */ - "IL", - CE, - { - {1, 3, 20, IDOR, FALSE} - , /* 2.4 G, ch 1~3 */ - {4, 6, 20, BOTH, FALSE} - , /* 2.4 G, ch 4~9 */ - {10, 4, 20, IDOR, FALSE} - , /* 2.4 G, ch 10~13 */ - {0} - , /* end */ - } - } - , - - { /* Italy */ - "IT", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, ODOR, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Japan */ - "JP", - JAP, - { - {1, 14, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~14 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {0} - , /* end */ - } - } - , - - { /* Jordan */ - "JO", - CE, - { - {1, 13, 20, IDOR, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {149, 4, 23, IDOR, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Latvia */ - "LV", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Liechtenstein */ - "LI", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Lithuania */ - "LT", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Luxemburg */ - "LU", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Malaysia */ - "MY", - CE, - { - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 5, 20, BOTH, FALSE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , - - { /* Malta */ - "MT", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Marocco */ - "MA", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 24, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {0} - , /* end */ - } - } - , - - { /* Mexico */ - "MX", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 5, 30, IDOR, FALSE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , - - { /* Netherlands */ - "NL", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* New Zealand */ - "NZ", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 24, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 4, 30, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Norway */ - "NO", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 24, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 24, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Peru */ - "PE", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {149, 4, 27, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Portugal */ - "PT", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Poland */ - "PL", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Romania */ - "RO", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Russia */ - "RU", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {149, 4, 20, IDOR, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Saudi Arabia */ - "SA", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 4, 23, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Serbia_and_Montenegro */ - "CS", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {0} - , /* end */ - } - } - , - - { /* Singapore */ - "SG", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {149, 4, 20, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Slovakia */ - "SK", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Slovenia */ - "SI", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {0} - , /* end */ - } - } - , - - { /* South Africa */ - "ZA", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, FALSE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {149, 4, 30, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* South Korea */ - "KR", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 20, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 20, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {100, 8, 20, BOTH, FALSE} - , /* 5G, ch 100~128 */ - {149, 4, 20, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Spain */ - "ES", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 17, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Sweden */ - "SE", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Switzerland */ - "CH", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~13 */ - {36, 4, 23, IDOR, TRUE} - , /* 5G, ch 36~48 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {0} - , /* end */ - } - } - , - - { /* Taiwan */ - "TW", - CE, - { - {1, 11, 30, BOTH, FALSE} - , /* 2.4 G, ch 1~11 */ - {52, 4, 23, IDOR, FALSE} - , /* 5G, ch 52~64 */ - {0} - , /* end */ - } - } - , - - { /* Turkey */ - "TR", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~11 */ - {36, 4, 23, BOTH, FALSE} - , /* 5G, ch 36~48 */ - {52, 4, 23, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {0} - , /* end */ - } - } - , - - { /* UK */ - "GB", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~11 */ - {36, 4, 23, IDOR, FALSE} - , /* 5G, ch 52~64 */ - {52, 4, 23, IDOR, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {0} - , /* end */ - } - } - , - - { /* Ukraine */ - "UA", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~11 */ - {0} - , /* end */ - } - } - , - - { /* United_Arab_Emirates */ - "AE", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~11 */ - {0} - , /* end */ - } - } - , - - { /* United_States */ - "US", - CE, - { - {1, 11, 30, BOTH, FALSE} - , /* 2.4 G, ch 1~11 */ - {36, 4, 17, IDOR, FALSE} - , /* 5G, ch 52~64 */ - {52, 4, 24, BOTH, TRUE} - , /* 5G, ch 52~64 */ - {100, 11, 30, BOTH, TRUE} - , /* 5G, ch 100~140 */ - {149, 5, 30, BOTH, FALSE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , - - { /* Venezuela */ - "VE", - CE, - { - {1, 13, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~11 */ - {149, 4, 27, BOTH, FALSE} - , /* 5G, ch 149~161 */ - {0} - , /* end */ - } - } - , - - { /* Default */ - "", - CE, - { - {1, 11, 20, BOTH, FALSE} - , /* 2.4 G, ch 1~11 */ - {36, 4, 20, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {52, 4, 20, BOTH, FALSE} - , /* 5G, ch 52~64 */ - {100, 11, 20, BOTH, FALSE} - , /* 5G, ch 100~140 */ - {149, 5, 20, BOTH, FALSE} - , /* 5G, ch 149~165 */ - {0} - , /* end */ - } - } - , -}; - -static struct rt_ch_region *GetChRegion(u8 *CntryCode) -{ - int loop = 0; - struct rt_ch_region *pChRegion = NULL; - - while (strcmp((char *)ChRegion[loop].CountReg, "") != 0) { - if (strncmp - ((char *)ChRegion[loop].CountReg, (char *)CntryCode, - 2) == 0) { - pChRegion = &ChRegion[loop]; - break; - } - loop++; - } - - if (pChRegion == NULL) - pChRegion = &ChRegion[loop]; - return pChRegion; -} - -static void ChBandCheck(u8 PhyMode, u8 *pChType) -{ - switch (PhyMode) { - case PHY_11A: - case PHY_11AN_MIXED: - *pChType = BAND_5G; - break; - case PHY_11ABG_MIXED: - case PHY_11AGN_MIXED: - case PHY_11ABGN_MIXED: - *pChType = BAND_BOTH; - break; - - default: - *pChType = BAND_24G; - break; - } -} - -static u8 FillChList(struct rt_rtmp_adapter *pAd, - struct rt_ch_desp *pChDesp, - u8 Offset, u8 increment) -{ - int i, j, l; - u8 channel; - - j = Offset; - for (i = 0; i < pChDesp->NumOfCh; i++) { - channel = pChDesp->FirstChannel + i * increment; - for (l = 0; l < MAX_NUM_OF_CHANNELS; l++) { - if (channel == pAd->TxPower[l].Channel) { - pAd->ChannelList[j].Power = - pAd->TxPower[l].Power; - pAd->ChannelList[j].Power2 = - pAd->TxPower[l].Power2; - break; - } - } - if (l == MAX_NUM_OF_CHANNELS) - continue; - - pAd->ChannelList[j].Channel = - pChDesp->FirstChannel + i * increment; - pAd->ChannelList[j].MaxTxPwr = pChDesp->MaxTxPwr; - pAd->ChannelList[j].DfsReq = pChDesp->DfsReq; - j++; - } - pAd->ChannelListNum = j; - - return j; -} - -static inline void CreateChList(struct rt_rtmp_adapter *pAd, - struct rt_ch_region *pChRegion, u8 Geography) -{ - int i; - u8 offset = 0; - struct rt_ch_desp *pChDesp; - u8 ChType; - u8 increment; - - if (pChRegion == NULL) - return; - - ChBandCheck(pAd->CommonCfg.PhyMode, &ChType); - - for (i = 0; i < 10; i++) { - pChDesp = &pChRegion->ChDesp[i]; - if (pChDesp->FirstChannel == 0) - break; - - if (ChType == BAND_5G) { - if (pChDesp->FirstChannel <= 14) - continue; - } else if (ChType == BAND_24G) { - if (pChDesp->FirstChannel > 14) - continue; - } - - if ((pChDesp->Geography == BOTH) - || (pChDesp->Geography == Geography)) { - if (pChDesp->FirstChannel > 14) - increment = 4; - else - increment = 1; - offset = FillChList(pAd, pChDesp, offset, increment); - } - } -} - -void BuildChannelListEx(struct rt_rtmp_adapter *pAd) -{ - struct rt_ch_region *pChReg; - - pChReg = GetChRegion(pAd->CommonCfg.CountryCode); - CreateChList(pAd, pChReg, pAd->CommonCfg.Geography); -} - -void BuildBeaconChList(struct rt_rtmp_adapter *pAd, - u8 *pBuf, unsigned long *pBufLen) -{ - int i; - unsigned long TmpLen; - struct rt_ch_region *pChRegion; - struct rt_ch_desp *pChDesp; - u8 ChType; - - pChRegion = GetChRegion(pAd->CommonCfg.CountryCode); - - if (pChRegion == NULL) - return; - - ChBandCheck(pAd->CommonCfg.PhyMode, &ChType); - *pBufLen = 0; - - for (i = 0; i < 10; i++) { - pChDesp = &pChRegion->ChDesp[i]; - if (pChDesp->FirstChannel == 0) - break; - - if (ChType == BAND_5G) { - if (pChDesp->FirstChannel <= 14) - continue; - } else if (ChType == BAND_24G) { - if (pChDesp->FirstChannel > 14) - continue; - } - - if ((pChDesp->Geography == BOTH) - || (pChDesp->Geography == pAd->CommonCfg.Geography)) { - MakeOutgoingFrame(pBuf + *pBufLen, &TmpLen, - 1, &pChDesp->FirstChannel, - 1, &pChDesp->NumOfCh, - 1, &pChDesp->MaxTxPwr, END_OF_ARGS); - *pBufLen += TmpLen; - } - } -} - -static BOOLEAN IsValidChannel(struct rt_rtmp_adapter *pAd, u8 channel) -{ - int i; - - for (i = 0; i < pAd->ChannelListNum; i++) { - if (pAd->ChannelList[i].Channel == channel) - break; - } - - if (i == pAd->ChannelListNum) - return FALSE; - else - return TRUE; -} - -static u8 GetExtCh(u8 Channel, u8 Direction) -{ - char ExtCh; - - if (Direction == EXTCHA_ABOVE) - ExtCh = Channel + 4; - else - ExtCh = (Channel - 4) > 0 ? (Channel - 4) : 0; - - return ExtCh; -} - -void N_ChannelCheck(struct rt_rtmp_adapter *pAd) -{ - /*u8 ChannelNum = pAd->ChannelListNum; */ - u8 Channel = pAd->CommonCfg.Channel; - - if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) - && (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40)) { - if (Channel > 14) { - if ((Channel == 36) || (Channel == 44) - || (Channel == 52) || (Channel == 60) - || (Channel == 100) || (Channel == 108) - || (Channel == 116) || (Channel == 124) - || (Channel == 132) || (Channel == 149) - || (Channel == 157)) { - pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = - EXTCHA_ABOVE; - } else if ((Channel == 40) || (Channel == 48) - || (Channel == 56) || (Channel == 64) - || (Channel == 104) || (Channel == 112) - || (Channel == 120) || (Channel == 128) - || (Channel == 136) || (Channel == 153) - || (Channel == 161)) { - pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = - EXTCHA_BELOW; - } else { - pAd->CommonCfg.RegTransmitSetting.field.BW = - BW_20; - } - } else { - do { - u8 ExtCh; - u8 Dir = - pAd->CommonCfg.RegTransmitSetting.field. - EXTCHA; - ExtCh = GetExtCh(Channel, Dir); - if (IsValidChannel(pAd, ExtCh)) - break; - - Dir = - (Dir == - EXTCHA_ABOVE) ? EXTCHA_BELOW : - EXTCHA_ABOVE; - ExtCh = GetExtCh(Channel, Dir); - if (IsValidChannel(pAd, ExtCh)) { - pAd->CommonCfg.RegTransmitSetting.field. - EXTCHA = Dir; - break; - } - pAd->CommonCfg.RegTransmitSetting.field.BW = - BW_20; - } while (FALSE); - - if (Channel == 14) { - pAd->CommonCfg.RegTransmitSetting.field.BW = - BW_20; - /*pAd->CommonCfg.RegTransmitSetting.field.EXTCHA = EXTCHA_NONE; // We didn't set the ExtCh as NONE due to it'll set in RTMPSetHT() */ - } - } - } - -} - -void N_SetCenCh(struct rt_rtmp_adapter *pAd) -{ - if (pAd->CommonCfg.RegTransmitSetting.field.BW == BW_40) { - if (pAd->CommonCfg.RegTransmitSetting.field.EXTCHA == - EXTCHA_ABOVE) { - pAd->CommonCfg.CentralChannel = - pAd->CommonCfg.Channel + 2; - } else { - if (pAd->CommonCfg.Channel == 14) - pAd->CommonCfg.CentralChannel = - pAd->CommonCfg.Channel - 1; - else - pAd->CommonCfg.CentralChannel = - pAd->CommonCfg.Channel - 2; - } - } else { - pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel; - } -} - -u8 GetCuntryMaxTxPwr(struct rt_rtmp_adapter *pAd, u8 channel) -{ - int i; - for (i = 0; i < pAd->ChannelListNum; i++) { - if (pAd->ChannelList[i].Channel == channel) - break; - } - - if (i == pAd->ChannelListNum) - return 0xff; - else - return pAd->ChannelList[i].MaxTxPwr; -} diff --git a/trunk/drivers/staging/rt2860/common/rt_rf.c b/trunk/drivers/staging/rt2860/common/rt_rf.c deleted file mode 100644 index 2895447ffc48..000000000000 --- a/trunk/drivers/staging/rt2860/common/rt_rf.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt_rf.c - - Abstract: - Ralink Wireless driver RF related functions - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ - -#include "../rt_config.h" - -#ifdef RTMP_RF_RW_SUPPORT -/* - ======================================================================== - - Routine Description: Write RT30xx RF register through MAC - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RT30xxWriteRFRegister(struct rt_rtmp_adapter *pAd, - u8 regID, u8 value) -{ - RF_CSR_CFG_STRUC rfcsr; - u32 i = 0; - - do { - RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); - - if (!rfcsr.field.RF_CSR_KICK) - break; - i++; - } - while ((i < RETRY_LIMIT) - && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))); - - if ((i == RETRY_LIMIT) - || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("Retry count exhausted or device removed!\n")); - return STATUS_UNSUCCESSFUL; - } - - rfcsr.field.RF_CSR_WR = 1; - rfcsr.field.RF_CSR_KICK = 1; - rfcsr.field.TESTCSR_RFACC_REGNUM = regID; - rfcsr.field.RF_CSR_DATA = value; - - RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); - - return NDIS_STATUS_SUCCESS; -} - -/* - ======================================================================== - - Routine Description: Read RT30xx RF register through MAC - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RT30xxReadRFRegister(struct rt_rtmp_adapter *pAd, - u8 regID, u8 *pValue) -{ - RF_CSR_CFG_STRUC rfcsr; - u32 i = 0, k = 0; - - for (i = 0; i < MAX_BUSY_COUNT; i++) { - RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); - - if (rfcsr.field.RF_CSR_KICK == BUSY) { - continue; - } - rfcsr.word = 0; - rfcsr.field.RF_CSR_WR = 0; - rfcsr.field.RF_CSR_KICK = 1; - rfcsr.field.TESTCSR_RFACC_REGNUM = regID; - RTMP_IO_WRITE32(pAd, RF_CSR_CFG, rfcsr.word); - for (k = 0; k < MAX_BUSY_COUNT; k++) { - RTMP_IO_READ32(pAd, RF_CSR_CFG, &rfcsr.word); - - if (rfcsr.field.RF_CSR_KICK == IDLE) - break; - } - if ((rfcsr.field.RF_CSR_KICK == IDLE) && - (rfcsr.field.TESTCSR_RFACC_REGNUM == regID)) { - *pValue = (u8)rfcsr.field.RF_CSR_DATA; - break; - } - } - if (rfcsr.field.RF_CSR_KICK == BUSY) { - DBGPRINT_ERR("RF read R%d=0x%x fail, i[%d], k[%d]\n", regID, rfcsr.word, i, k); - return STATUS_UNSUCCESSFUL; - } - - return STATUS_SUCCESS; -} - -void NICInitRFRegisters(struct rt_rtmp_adapter *pAd) -{ - if (pAd->chipOps.AsicRfInit) - pAd->chipOps.AsicRfInit(pAd); -} - -void RtmpChipOpsRFHook(struct rt_rtmp_adapter *pAd) -{ - struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps; - - pChipOps->pRFRegTable = NULL; - pChipOps->AsicRfInit = NULL; - pChipOps->AsicRfTurnOn = NULL; - pChipOps->AsicRfTurnOff = NULL; - pChipOps->AsicReverseRfFromSleepMode = NULL; - pChipOps->AsicHaltAction = NULL; - /* We depends on RfICType and MACVersion to assign the corresponding operation callbacks. */ - -#ifdef RT30xx - if (IS_RT30xx(pAd)) { - pChipOps->pRFRegTable = RT30xx_RFRegTable; - pChipOps->AsicHaltAction = RT30xxHaltAction; -#ifdef RT3070 - if ((IS_RT3070(pAd) || IS_RT3071(pAd)) - && (pAd->infType == RTMP_DEV_INF_USB)) { - pChipOps->AsicRfInit = NICInitRT3070RFRegisters; - if (IS_RT3071(pAd)) { - pChipOps->AsicRfTurnOff = - RT30xxLoadRFSleepModeSetup; - pChipOps->AsicReverseRfFromSleepMode = - RT30xxReverseRFSleepModeSetup; - } - } -#endif /* RT3070 // */ -#ifdef RT3090 - if (IS_RT3090(pAd) && (pAd->infType == RTMP_DEV_INF_PCI)) { - pChipOps->AsicRfTurnOff = RT30xxLoadRFSleepModeSetup; - pChipOps->AsicRfInit = NICInitRT3090RFRegisters; - pChipOps->AsicReverseRfFromSleepMode = - RT30xxReverseRFSleepModeSetup; - } -#endif /* RT3090 // */ - } -#endif /* RT30xx // */ -} - -#endif /* RTMP_RF_RW_SUPPORT // */ diff --git a/trunk/drivers/staging/rt2860/common/rtmp_init.c b/trunk/drivers/staging/rt2860/common/rtmp_init.c deleted file mode 100644 index 5fa193eac0d3..000000000000 --- a/trunk/drivers/staging/rt2860/common/rtmp_init.c +++ /dev/null @@ -1,3536 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_init.c - - Abstract: - Miniport generic portion header file - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ -#include "../rt_config.h" - -u8 BIT8[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 }; -char *CipherName[] = - { "none", "wep64", "wep128", "TKIP", "AES", "CKIP64", "CKIP128" }; - -/* */ -/* BBP register initialization set */ -/* */ -struct rt_reg_pair BBPRegTable[] = { - {BBP_R65, 0x2C}, /* fix rssi issue */ - {BBP_R66, 0x38}, /* Also set this default value to pAd->BbpTuning.R66CurrentValue at initial */ - {BBP_R69, 0x12}, - {BBP_R70, 0xa}, /* BBP_R70 will change to 0x8 in ApStartUp and LinkUp for rt2860C, otherwise value is 0xa */ - {BBP_R73, 0x10}, - {BBP_R81, 0x37}, - {BBP_R82, 0x62}, - {BBP_R83, 0x6A}, - {BBP_R84, 0x99}, /* 0x19 is for rt2860E and after. This is for extension channel overlapping IOT. 0x99 is for rt2860D and before */ - {BBP_R86, 0x00}, /* middle range issue, Rory @2008-01-28 */ - {BBP_R91, 0x04}, /* middle range issue, Rory @2008-01-28 */ - {BBP_R92, 0x00}, /* middle range issue, Rory @2008-01-28 */ - {BBP_R103, 0x00}, /* near range high-power issue, requested from Gary @2008-0528 */ - {BBP_R105, 0x05}, /* 0x05 is for rt2860E to turn on FEQ control. It is safe for rt2860D and before, because Bit 7:2 are reserved in rt2860D and before. */ - {BBP_R106, 0x35}, /* for ShortGI throughput */ -}; - -#define NUM_BBP_REG_PARMS (sizeof(BBPRegTable) / sizeof(struct rt_reg_pair)) - -/* */ -/* ASIC register initialization sets */ -/* */ - -struct rt_rtmp_reg_pair MACRegTable[] = { -#if defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x200) - {BCN_OFFSET0, 0xf8f0e8e0}, /* 0x3800(e0), 0x3A00(e8), 0x3C00(f0), 0x3E00(f8), 512B for each beacon */ - {BCN_OFFSET1, 0x6f77d0c8}, /* 0x3200(c8), 0x3400(d0), 0x1DC0(77), 0x1BC0(6f), 512B for each beacon */ -#elif defined(HW_BEACON_OFFSET) && (HW_BEACON_OFFSET == 0x100) - {BCN_OFFSET0, 0xece8e4e0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */ - {BCN_OFFSET1, 0xfcf8f4f0}, /* 0x3800, 0x3A00, 0x3C00, 0x3E00, 512B for each beacon */ -#else -#error You must re-calculate new value for BCN_OFFSET0 & BCN_OFFSET1 in MACRegTable[]! -#endif /* HW_BEACON_OFFSET // */ - - {LEGACY_BASIC_RATE, 0x0000013f}, /* Basic rate set bitmap */ - {HT_BASIC_RATE, 0x00008003}, /* Basic HT rate set , 20M, MCS=3, MM. Format is the same as in TXWI. */ - {MAC_SYS_CTRL, 0x00}, /* 0x1004, , default Disable RX */ - {RX_FILTR_CFG, 0x17f97}, /*0x1400 , RX filter control, */ - {BKOFF_SLOT_CFG, 0x209}, /* default set short slot time, CC_DELAY_TIME should be 2 */ - /*{TX_SW_CFG0, 0x40a06}, // Gary,2006-08-23 */ - {TX_SW_CFG0, 0x0}, /* Gary,2008-05-21 for CWC test */ - {TX_SW_CFG1, 0x80606}, /* Gary,2006-08-23 */ - {TX_LINK_CFG, 0x1020}, /* Gary,2006-08-23 */ - /*{TX_TIMEOUT_CFG, 0x00182090}, // CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT */ - {TX_TIMEOUT_CFG, 0x000a2090}, /* CCK has some problem. So increase timieout value. 2006-10-09// MArvek RT , Modify for 2860E ,2007-08-01 */ - {MAX_LEN_CFG, MAX_AGGREGATION_SIZE | 0x00001000}, /* 0x3018, MAX frame length. Max PSDU = 16kbytes. */ - {LED_CFG, 0x7f031e46}, /* Gary, 2006-08-23 */ - - {PBF_MAX_PCNT, 0x1F3FBF9F}, /*0x1F3f7f9f}, //Jan, 2006/04/20 */ - - {TX_RTY_CFG, 0x47d01f0f}, /* Jan, 2006/11/16, Set TxWI->ACK =0 in Probe Rsp Modify for 2860E ,2007-08-03 */ - - {AUTO_RSP_CFG, 0x00000013}, /* Initial Auto_Responder, because QA will turn off Auto-Responder */ - {CCK_PROT_CFG, 0x05740003 /*0x01740003 */ }, /* Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled. */ - {OFDM_PROT_CFG, 0x05740003 /*0x01740003 */ }, /* Initial Auto_Responder, because QA will turn off Auto-Responder. And RTS threshold is enabled. */ -#ifdef RTMP_MAC_USB - {PBF_CFG, 0xf40006}, /* Only enable Queue 2 */ - {MM40_PROT_CFG, 0x3F44084}, /* Initial Auto_Responder, because QA will turn off Auto-Responder */ - {WPDMA_GLO_CFG, 0x00000030}, -#endif /* RTMP_MAC_USB // */ - {GF20_PROT_CFG, 0x01744004}, /* set 19:18 --> Short NAV for MIMO PS */ - {GF40_PROT_CFG, 0x03F44084}, - {MM20_PROT_CFG, 0x01744004}, -#ifdef RTMP_MAC_PCI - {MM40_PROT_CFG, 0x03F54084}, -#endif /* RTMP_MAC_PCI // */ - {TXOP_CTRL_CFG, 0x0000583f, /*0x0000243f *//*0x000024bf */ }, /*Extension channel backoff. */ - {TX_RTS_CFG, 0x00092b20}, - {EXP_ACK_TIME, 0x002400ca}, /* default value */ - - {TXOP_HLDR_ET, 0x00000002}, - - /* Jerry comments 2008/01/16: we use SIFS = 10us in CCK defaultly, but it seems that 10us - is too small for INTEL 2200bg card, so in MBSS mode, the delta time between beacon0 - and beacon1 is SIFS (10us), so if INTEL 2200bg card connects to BSS0, the ping - will always lost. So we change the SIFS of CCK from 10us to 16us. */ - {XIFS_TIME_CFG, 0x33a41010}, - {PWR_PIN_CFG, 0x00000003}, /* patch for 2880-E */ -}; - -struct rt_rtmp_reg_pair STAMACRegTable[] = { - {WMM_AIFSN_CFG, 0x00002273}, - {WMM_CWMIN_CFG, 0x00002344}, - {WMM_CWMAX_CFG, 0x000034aa}, -}; - -#define NUM_MAC_REG_PARMS (sizeof(MACRegTable) / sizeof(struct rt_rtmp_reg_pair)) -#define NUM_STA_MAC_REG_PARMS (sizeof(STAMACRegTable) / sizeof(struct rt_rtmp_reg_pair)) - -/* - ======================================================================== - - Routine Description: - Allocate struct rt_rtmp_adapter data block and do some initialization - - Arguments: - Adapter Pointer to our adapter - - Return Value: - NDIS_STATUS_SUCCESS - NDIS_STATUS_FAILURE - - IRQL = PASSIVE_LEVEL - - Note: - - ======================================================================== -*/ -int RTMPAllocAdapterBlock(void *handle, - struct rt_rtmp_adapter * * ppAdapter) -{ - struct rt_rtmp_adapter *pAd; - int Status; - int index; - u8 *pBeaconBuf = NULL; - - DBGPRINT(RT_DEBUG_TRACE, ("--> RTMPAllocAdapterBlock\n")); - - *ppAdapter = NULL; - - do { - /* Allocate struct rt_rtmp_adapter memory block */ - pBeaconBuf = kmalloc(MAX_BEACON_SIZE, MEM_ALLOC_FLAG); - if (pBeaconBuf == NULL) { - Status = NDIS_STATUS_FAILURE; - DBGPRINT_ERR("Failed to allocate memory - BeaconBuf!\n"); - break; - } - NdisZeroMemory(pBeaconBuf, MAX_BEACON_SIZE); - - Status = AdapterBlockAllocateMemory(handle, (void **) & pAd); - if (Status != NDIS_STATUS_SUCCESS) { - DBGPRINT_ERR("Failed to allocate memory - ADAPTER\n"); - break; - } - pAd->BeaconBuf = pBeaconBuf; - DBGPRINT(RT_DEBUG_OFF, - ("=== pAd = %p, size = %d ===\n", pAd, - (u32)sizeof(struct rt_rtmp_adapter))); - - /* Init spin locks */ - NdisAllocateSpinLock(&pAd->MgmtRingLock); -#ifdef RTMP_MAC_PCI - NdisAllocateSpinLock(&pAd->RxRingLock); -#ifdef RT3090 - NdisAllocateSpinLock(&pAd->McuCmdLock); -#endif /* RT3090 // */ -#endif /* RTMP_MAC_PCI // */ - - for (index = 0; index < NUM_OF_TX_RING; index++) { - NdisAllocateSpinLock(&pAd->TxSwQueueLock[index]); - NdisAllocateSpinLock(&pAd->DeQueueLock[index]); - pAd->DeQueueRunning[index] = FALSE; - } - - NdisAllocateSpinLock(&pAd->irq_lock); - - } while (FALSE); - - if ((Status != NDIS_STATUS_SUCCESS) && (pBeaconBuf)) - kfree(pBeaconBuf); - - *ppAdapter = pAd; - - DBGPRINT_S(Status, ("<-- RTMPAllocAdapterBlock, Status=%x\n", Status)); - return Status; -} - -/* - ======================================================================== - - Routine Description: - Read initial Tx power per MCS and BW from EEPROM - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPReadTxPwrPerRate(struct rt_rtmp_adapter *pAd) -{ - unsigned long data, Adata, Gdata; - u16 i, value, value2; - int Apwrdelta, Gpwrdelta; - u8 t1, t2, t3, t4; - BOOLEAN bApwrdeltaMinus = TRUE, bGpwrdeltaMinus = TRUE; - - /* */ - /* Get power delta for 20MHz and 40MHz. */ - /* */ - DBGPRINT(RT_DEBUG_TRACE, ("Txpower per Rate\n")); - RT28xx_EEPROM_READ16(pAd, EEPROM_TXPOWER_DELTA, value2); - Apwrdelta = 0; - Gpwrdelta = 0; - - if ((value2 & 0xff) != 0xff) { - if ((value2 & 0x80)) - Gpwrdelta = (value2 & 0xf); - - if ((value2 & 0x40)) - bGpwrdeltaMinus = FALSE; - else - bGpwrdeltaMinus = TRUE; - } - if ((value2 & 0xff00) != 0xff00) { - if ((value2 & 0x8000)) - Apwrdelta = ((value2 & 0xf00) >> 8); - - if ((value2 & 0x4000)) - bApwrdeltaMinus = FALSE; - else - bApwrdeltaMinus = TRUE; - } - DBGPRINT(RT_DEBUG_TRACE, - ("Gpwrdelta = %x, Apwrdelta = %x .\n", Gpwrdelta, Apwrdelta)); - - /* */ - /* Get Txpower per MCS for 20MHz in 2.4G. */ - /* */ - for (i = 0; i < 5; i++) { - RT28xx_EEPROM_READ16(pAd, - EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i * 4, - value); - data = value; - if (bApwrdeltaMinus == FALSE) { - t1 = (value & 0xf) + (Apwrdelta); - if (t1 > 0xf) - t1 = 0xf; - t2 = ((value & 0xf0) >> 4) + (Apwrdelta); - if (t2 > 0xf) - t2 = 0xf; - t3 = ((value & 0xf00) >> 8) + (Apwrdelta); - if (t3 > 0xf) - t3 = 0xf; - t4 = ((value & 0xf000) >> 12) + (Apwrdelta); - if (t4 > 0xf) - t4 = 0xf; - } else { - if ((value & 0xf) > Apwrdelta) - t1 = (value & 0xf) - (Apwrdelta); - else - t1 = 0; - if (((value & 0xf0) >> 4) > Apwrdelta) - t2 = ((value & 0xf0) >> 4) - (Apwrdelta); - else - t2 = 0; - if (((value & 0xf00) >> 8) > Apwrdelta) - t3 = ((value & 0xf00) >> 8) - (Apwrdelta); - else - t3 = 0; - if (((value & 0xf000) >> 12) > Apwrdelta) - t4 = ((value & 0xf000) >> 12) - (Apwrdelta); - else - t4 = 0; - } - Adata = t1 + (t2 << 4) + (t3 << 8) + (t4 << 12); - if (bGpwrdeltaMinus == FALSE) { - t1 = (value & 0xf) + (Gpwrdelta); - if (t1 > 0xf) - t1 = 0xf; - t2 = ((value & 0xf0) >> 4) + (Gpwrdelta); - if (t2 > 0xf) - t2 = 0xf; - t3 = ((value & 0xf00) >> 8) + (Gpwrdelta); - if (t3 > 0xf) - t3 = 0xf; - t4 = ((value & 0xf000) >> 12) + (Gpwrdelta); - if (t4 > 0xf) - t4 = 0xf; - } else { - if ((value & 0xf) > Gpwrdelta) - t1 = (value & 0xf) - (Gpwrdelta); - else - t1 = 0; - if (((value & 0xf0) >> 4) > Gpwrdelta) - t2 = ((value & 0xf0) >> 4) - (Gpwrdelta); - else - t2 = 0; - if (((value & 0xf00) >> 8) > Gpwrdelta) - t3 = ((value & 0xf00) >> 8) - (Gpwrdelta); - else - t3 = 0; - if (((value & 0xf000) >> 12) > Gpwrdelta) - t4 = ((value & 0xf000) >> 12) - (Gpwrdelta); - else - t4 = 0; - } - Gdata = t1 + (t2 << 4) + (t3 << 8) + (t4 << 12); - - RT28xx_EEPROM_READ16(pAd, - EEPROM_TXPOWER_BYRATE_20MHZ_2_4G + i * 4 + - 2, value); - if (bApwrdeltaMinus == FALSE) { - t1 = (value & 0xf) + (Apwrdelta); - if (t1 > 0xf) - t1 = 0xf; - t2 = ((value & 0xf0) >> 4) + (Apwrdelta); - if (t2 > 0xf) - t2 = 0xf; - t3 = ((value & 0xf00) >> 8) + (Apwrdelta); - if (t3 > 0xf) - t3 = 0xf; - t4 = ((value & 0xf000) >> 12) + (Apwrdelta); - if (t4 > 0xf) - t4 = 0xf; - } else { - if ((value & 0xf) > Apwrdelta) - t1 = (value & 0xf) - (Apwrdelta); - else - t1 = 0; - if (((value & 0xf0) >> 4) > Apwrdelta) - t2 = ((value & 0xf0) >> 4) - (Apwrdelta); - else - t2 = 0; - if (((value & 0xf00) >> 8) > Apwrdelta) - t3 = ((value & 0xf00) >> 8) - (Apwrdelta); - else - t3 = 0; - if (((value & 0xf000) >> 12) > Apwrdelta) - t4 = ((value & 0xf000) >> 12) - (Apwrdelta); - else - t4 = 0; - } - Adata |= ((t1 << 16) + (t2 << 20) + (t3 << 24) + (t4 << 28)); - if (bGpwrdeltaMinus == FALSE) { - t1 = (value & 0xf) + (Gpwrdelta); - if (t1 > 0xf) - t1 = 0xf; - t2 = ((value & 0xf0) >> 4) + (Gpwrdelta); - if (t2 > 0xf) - t2 = 0xf; - t3 = ((value & 0xf00) >> 8) + (Gpwrdelta); - if (t3 > 0xf) - t3 = 0xf; - t4 = ((value & 0xf000) >> 12) + (Gpwrdelta); - if (t4 > 0xf) - t4 = 0xf; - } else { - if ((value & 0xf) > Gpwrdelta) - t1 = (value & 0xf) - (Gpwrdelta); - else - t1 = 0; - if (((value & 0xf0) >> 4) > Gpwrdelta) - t2 = ((value & 0xf0) >> 4) - (Gpwrdelta); - else - t2 = 0; - if (((value & 0xf00) >> 8) > Gpwrdelta) - t3 = ((value & 0xf00) >> 8) - (Gpwrdelta); - else - t3 = 0; - if (((value & 0xf000) >> 12) > Gpwrdelta) - t4 = ((value & 0xf000) >> 12) - (Gpwrdelta); - else - t4 = 0; - } - Gdata |= ((t1 << 16) + (t2 << 20) + (t3 << 24) + (t4 << 28)); - data |= (value << 16); - - /* For 20M/40M Power Delta issue */ - pAd->Tx20MPwrCfgABand[i] = data; - pAd->Tx20MPwrCfgGBand[i] = data; - pAd->Tx40MPwrCfgABand[i] = Adata; - pAd->Tx40MPwrCfgGBand[i] = Gdata; - - if (data != 0xffffffff) - RTMP_IO_WRITE32(pAd, TX_PWR_CFG_0 + i * 4, data); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("20MHz BW, 2.4G band-%lx, Adata = %lx, Gdata = %lx \n", - data, Adata, Gdata)); - } -} - -/* - ======================================================================== - - Routine Description: - Read initial channel power parameters from EEPROM - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPReadChannelPwr(struct rt_rtmp_adapter *pAd) -{ - u8 i, choffset; - EEPROM_TX_PWR_STRUC Power; - EEPROM_TX_PWR_STRUC Power2; - - /* Read Tx power value for all channels */ - /* Value from 1 - 0x7f. Default value is 24. */ - /* Power value : 2.4G 0x00 (0) ~ 0x1F (31) */ - /* : 5.5G 0xF9 (-7) ~ 0x0F (15) */ - - /* 0. 11b/g, ch1 - ch 14 */ - for (i = 0; i < 7; i++) { - RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX_PWR_OFFSET + i * 2, - Power.word); - RT28xx_EEPROM_READ16(pAd, EEPROM_G_TX2_PWR_OFFSET + i * 2, - Power2.word); - pAd->TxPower[i * 2].Channel = i * 2 + 1; - pAd->TxPower[i * 2 + 1].Channel = i * 2 + 2; - - if ((Power.field.Byte0 > 31) || (Power.field.Byte0 < 0)) - pAd->TxPower[i * 2].Power = DEFAULT_RF_TX_POWER; - else - pAd->TxPower[i * 2].Power = Power.field.Byte0; - - if ((Power.field.Byte1 > 31) || (Power.field.Byte1 < 0)) - pAd->TxPower[i * 2 + 1].Power = DEFAULT_RF_TX_POWER; - else - pAd->TxPower[i * 2 + 1].Power = Power.field.Byte1; - - if ((Power2.field.Byte0 > 31) || (Power2.field.Byte0 < 0)) - pAd->TxPower[i * 2].Power2 = DEFAULT_RF_TX_POWER; - else - pAd->TxPower[i * 2].Power2 = Power2.field.Byte0; - - if ((Power2.field.Byte1 > 31) || (Power2.field.Byte1 < 0)) - pAd->TxPower[i * 2 + 1].Power2 = DEFAULT_RF_TX_POWER; - else - pAd->TxPower[i * 2 + 1].Power2 = Power2.field.Byte1; - } - - /* 1. U-NII lower/middle band: 36, 38, 40; 44, 46, 48; 52, 54, 56; 60, 62, 64 (including central frequency in BW 40MHz) */ - /* 1.1 Fill up channel */ - choffset = 14; - for (i = 0; i < 4; i++) { - pAd->TxPower[3 * i + choffset + 0].Channel = 36 + i * 8 + 0; - pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER; - - pAd->TxPower[3 * i + choffset + 1].Channel = 36 + i * 8 + 2; - pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER; - - pAd->TxPower[3 * i + choffset + 2].Channel = 36 + i * 8 + 4; - pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER; - } - - /* 1.2 Fill up power */ - for (i = 0; i < 6; i++) { - RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX_PWR_OFFSET + i * 2, - Power.word); - RT28xx_EEPROM_READ16(pAd, EEPROM_A_TX2_PWR_OFFSET + i * 2, - Power2.word); - - if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7)) - pAd->TxPower[i * 2 + choffset + 0].Power = - Power.field.Byte0; - - if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7)) - pAd->TxPower[i * 2 + choffset + 1].Power = - Power.field.Byte1; - - if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7)) - pAd->TxPower[i * 2 + choffset + 0].Power2 = - Power2.field.Byte0; - - if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7)) - pAd->TxPower[i * 2 + choffset + 1].Power2 = - Power2.field.Byte1; - } - - /* 2. HipperLAN 2 100, 102 ,104; 108, 110, 112; 116, 118, 120; 124, 126, 128; 132, 134, 136; 140 (including central frequency in BW 40MHz) */ - /* 2.1 Fill up channel */ - choffset = 14 + 12; - for (i = 0; i < 5; i++) { - pAd->TxPower[3 * i + choffset + 0].Channel = 100 + i * 8 + 0; - pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER; - - pAd->TxPower[3 * i + choffset + 1].Channel = 100 + i * 8 + 2; - pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER; - - pAd->TxPower[3 * i + choffset + 2].Channel = 100 + i * 8 + 4; - pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER; - } - pAd->TxPower[3 * 5 + choffset + 0].Channel = 140; - pAd->TxPower[3 * 5 + choffset + 0].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * 5 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER; - - /* 2.2 Fill up power */ - for (i = 0; i < 8; i++) { - RT28xx_EEPROM_READ16(pAd, - EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + - i * 2, Power.word); - RT28xx_EEPROM_READ16(pAd, - EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + - i * 2, Power2.word); - - if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7)) - pAd->TxPower[i * 2 + choffset + 0].Power = - Power.field.Byte0; - - if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7)) - pAd->TxPower[i * 2 + choffset + 1].Power = - Power.field.Byte1; - - if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7)) - pAd->TxPower[i * 2 + choffset + 0].Power2 = - Power2.field.Byte0; - - if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7)) - pAd->TxPower[i * 2 + choffset + 1].Power2 = - Power2.field.Byte1; - } - - /* 3. U-NII upper band: 149, 151, 153; 157, 159, 161; 165, 167, 169; 171, 173 (including central frequency in BW 40MHz) */ - /* 3.1 Fill up channel */ - choffset = 14 + 12 + 16; - /*for (i = 0; i < 2; i++) */ - for (i = 0; i < 3; i++) { - pAd->TxPower[3 * i + choffset + 0].Channel = 149 + i * 8 + 0; - pAd->TxPower[3 * i + choffset + 0].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * i + choffset + 0].Power2 = DEFAULT_RF_TX_POWER; - - pAd->TxPower[3 * i + choffset + 1].Channel = 149 + i * 8 + 2; - pAd->TxPower[3 * i + choffset + 1].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * i + choffset + 1].Power2 = DEFAULT_RF_TX_POWER; - - pAd->TxPower[3 * i + choffset + 2].Channel = 149 + i * 8 + 4; - pAd->TxPower[3 * i + choffset + 2].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * i + choffset + 2].Power2 = DEFAULT_RF_TX_POWER; - } - pAd->TxPower[3 * 3 + choffset + 0].Channel = 171; - pAd->TxPower[3 * 3 + choffset + 0].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * 3 + choffset + 0].Power2 = DEFAULT_RF_TX_POWER; - - pAd->TxPower[3 * 3 + choffset + 1].Channel = 173; - pAd->TxPower[3 * 3 + choffset + 1].Power = DEFAULT_RF_TX_POWER; - pAd->TxPower[3 * 3 + choffset + 1].Power2 = DEFAULT_RF_TX_POWER; - - /* 3.2 Fill up power */ - /*for (i = 0; i < 4; i++) */ - for (i = 0; i < 6; i++) { - RT28xx_EEPROM_READ16(pAd, - EEPROM_A_TX_PWR_OFFSET + (choffset - 14) + - i * 2, Power.word); - RT28xx_EEPROM_READ16(pAd, - EEPROM_A_TX2_PWR_OFFSET + (choffset - 14) + - i * 2, Power2.word); - - if ((Power.field.Byte0 < 16) && (Power.field.Byte0 >= -7)) - pAd->TxPower[i * 2 + choffset + 0].Power = - Power.field.Byte0; - - if ((Power.field.Byte1 < 16) && (Power.field.Byte1 >= -7)) - pAd->TxPower[i * 2 + choffset + 1].Power = - Power.field.Byte1; - - if ((Power2.field.Byte0 < 16) && (Power2.field.Byte0 >= -7)) - pAd->TxPower[i * 2 + choffset + 0].Power2 = - Power2.field.Byte0; - - if ((Power2.field.Byte1 < 16) && (Power2.field.Byte1 >= -7)) - pAd->TxPower[i * 2 + choffset + 1].Power2 = - Power2.field.Byte1; - } - - /* 4. Print and Debug */ - /*choffset = 14 + 12 + 16 + 7; */ - choffset = 14 + 12 + 16 + 11; - -} - -/* - ======================================================================== - - Routine Description: - Read the following from the registry - 1. All the parameters - 2. NetworkAddres - - Arguments: - Adapter Pointer to our adapter - WrapperConfigurationContext For use by NdisOpenConfiguration - - Return Value: - NDIS_STATUS_SUCCESS - NDIS_STATUS_FAILURE - NDIS_STATUS_RESOURCES - - IRQL = PASSIVE_LEVEL - - Note: - - ======================================================================== -*/ -int NICReadRegParameters(struct rt_rtmp_adapter *pAd, - void *WrapperConfigurationContext) -{ - int Status = NDIS_STATUS_SUCCESS; - DBGPRINT_S(Status, ("<-- NICReadRegParameters, Status=%x\n", Status)); - return Status; -} - -/* - ======================================================================== - - Routine Description: - Read initial parameters from EEPROM - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - Note: - - ======================================================================== -*/ -void NICReadEEPROMParameters(struct rt_rtmp_adapter *pAd, u8 *mac_addr) -{ - u32 data = 0; - u16 i, value, value2; - u8 TmpPhy; - EEPROM_TX_PWR_STRUC Power; - EEPROM_VERSION_STRUC Version; - EEPROM_ANTENNA_STRUC Antenna; - EEPROM_NIC_CONFIG2_STRUC NicConfig2; - - DBGPRINT(RT_DEBUG_TRACE, ("--> NICReadEEPROMParameters\n")); - - if (pAd->chipOps.eeinit) - pAd->chipOps.eeinit(pAd); - - /* Init EEPROM Address Number, before access EEPROM; if 93c46, EEPROMAddressNum=6, else if 93c66, EEPROMAddressNum=8 */ - RTMP_IO_READ32(pAd, E2PROM_CSR, &data); - DBGPRINT(RT_DEBUG_TRACE, ("--> E2PROM_CSR = 0x%x\n", data)); - - if ((data & 0x30) == 0) - pAd->EEPROMAddressNum = 6; /* 93C46 */ - else if ((data & 0x30) == 0x10) - pAd->EEPROMAddressNum = 8; /* 93C66 */ - else - pAd->EEPROMAddressNum = 8; /* 93C86 */ - DBGPRINT(RT_DEBUG_TRACE, - ("--> EEPROMAddressNum = %d\n", pAd->EEPROMAddressNum)); - - /* RT2860 MAC no longer auto load MAC address from E2PROM. Driver has to initialize */ - /* MAC address registers according to E2PROM setting */ - if (mac_addr == NULL || - strlen((char *)mac_addr) != 17 || - mac_addr[2] != ':' || mac_addr[5] != ':' || mac_addr[8] != ':' || - mac_addr[11] != ':' || mac_addr[14] != ':') { - u16 Addr01, Addr23, Addr45; - - RT28xx_EEPROM_READ16(pAd, 0x04, Addr01); - RT28xx_EEPROM_READ16(pAd, 0x06, Addr23); - RT28xx_EEPROM_READ16(pAd, 0x08, Addr45); - - pAd->PermanentAddress[0] = (u8)(Addr01 & 0xff); - pAd->PermanentAddress[1] = (u8)(Addr01 >> 8); - pAd->PermanentAddress[2] = (u8)(Addr23 & 0xff); - pAd->PermanentAddress[3] = (u8)(Addr23 >> 8); - pAd->PermanentAddress[4] = (u8)(Addr45 & 0xff); - pAd->PermanentAddress[5] = (u8)(Addr45 >> 8); - - DBGPRINT(RT_DEBUG_TRACE, - ("Initialize MAC Address from E2PROM \n")); - } else { - int j; - char *macptr; - - macptr = (char *)mac_addr; - - for (j = 0; j < MAC_ADDR_LEN; j++) { - AtoH(macptr, &pAd->PermanentAddress[j], 1); - macptr = macptr + 3; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("Initialize MAC Address from module parameter \n")); - } - - { - /*more conveninet to test mbssid, so ap's bssid &0xf1 */ - if (pAd->PermanentAddress[0] == 0xff) - pAd->PermanentAddress[0] = RandomByte(pAd) & 0xf8; - - /*if (pAd->PermanentAddress[5] == 0xff) */ - /* pAd->PermanentAddress[5] = RandomByte(pAd)&0xf8; */ - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("E2PROM MAC: =%pM\n", pAd->PermanentAddress)); - if (pAd->bLocalAdminMAC == FALSE) { - MAC_DW0_STRUC csr2; - MAC_DW1_STRUC csr3; - COPY_MAC_ADDR(pAd->CurrentAddress, - pAd->PermanentAddress); - csr2.field.Byte0 = pAd->CurrentAddress[0]; - csr2.field.Byte1 = pAd->CurrentAddress[1]; - csr2.field.Byte2 = pAd->CurrentAddress[2]; - csr2.field.Byte3 = pAd->CurrentAddress[3]; - RTMP_IO_WRITE32(pAd, MAC_ADDR_DW0, csr2.word); - csr3.word = 0; - csr3.field.Byte4 = pAd->CurrentAddress[4]; - csr3.field.Byte5 = pAd->CurrentAddress[5]; - csr3.field.U2MeMask = 0xff; - RTMP_IO_WRITE32(pAd, MAC_ADDR_DW1, csr3.word); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("E2PROM MAC: =%pM\n", - pAd->PermanentAddress)); - } - } - - /* if not return early. cause fail at emulation. */ - /* Init the channel number for TX channel power */ - RTMPReadChannelPwr(pAd); - - /* if E2PROM version mismatch with driver's expectation, then skip */ - /* all subsequent E2RPOM retieval and set a system error bit to notify GUI */ - RT28xx_EEPROM_READ16(pAd, EEPROM_VERSION_OFFSET, Version.word); - pAd->EepromVersion = - Version.field.Version + Version.field.FaeReleaseNumber * 256; - DBGPRINT(RT_DEBUG_TRACE, - ("E2PROM: Version = %d, FAE release #%d\n", - Version.field.Version, Version.field.FaeReleaseNumber)); - - if (Version.field.Version > VALID_EEPROM_VERSION) { - DBGPRINT_ERR("E2PROM: WRONG VERSION 0x%x, should be %d\n", Version.field.Version, VALID_EEPROM_VERSION); - /*pAd->SystemErrorBitmap |= 0x00000001; - - // hard-code default value when no proper E2PROM installed - pAd->bAutoTxAgcA = FALSE; - pAd->bAutoTxAgcG = FALSE; - - // Default the channel power - for (i = 0; i < MAX_NUM_OF_CHANNELS; i++) - pAd->TxPower[i].Power = DEFAULT_RF_TX_POWER; - - // Default the channel power - for (i = 0; i < MAX_NUM_OF_11JCHANNELS; i++) - pAd->TxPower11J[i].Power = DEFAULT_RF_TX_POWER; - - for(i = 0; i < NUM_EEPROM_BBP_PARMS; i++) - pAd->EEPROMDefaultValue[i] = 0xffff; - return; */ - } - /* Read BBP default value from EEPROM and store to array(EEPROMDefaultValue) in pAd */ - RT28xx_EEPROM_READ16(pAd, EEPROM_NIC1_OFFSET, value); - pAd->EEPROMDefaultValue[0] = value; - - RT28xx_EEPROM_READ16(pAd, EEPROM_NIC2_OFFSET, value); - pAd->EEPROMDefaultValue[1] = value; - - RT28xx_EEPROM_READ16(pAd, 0x38, value); /* Country Region */ - pAd->EEPROMDefaultValue[2] = value; - - for (i = 0; i < 8; i++) { - RT28xx_EEPROM_READ16(pAd, EEPROM_BBP_BASE_OFFSET + i * 2, - value); - pAd->EEPROMDefaultValue[i + 3] = value; - } - - /* We have to parse NIC configuration 0 at here. */ - /* If TSSI did not have preloaded value, it should reset the TxAutoAgc to false */ - /* Therefore, we have to read TxAutoAgc control beforehand. */ - /* Read Tx AGC control bit */ - Antenna.word = pAd->EEPROMDefaultValue[0]; - if (Antenna.word == 0xFFFF) { -#ifdef RT30xx - if (IS_RT3090(pAd) || IS_RT3390(pAd)) { - Antenna.word = 0; - Antenna.field.RfIcType = RFIC_3020; - Antenna.field.TxPath = 1; - Antenna.field.RxPath = 1; - } else -#endif /* RT30xx // */ - { - - Antenna.word = 0; - Antenna.field.RfIcType = RFIC_2820; - Antenna.field.TxPath = 1; - Antenna.field.RxPath = 2; - DBGPRINT(RT_DEBUG_WARN, - ("E2PROM error, hard code as 0x%04x\n", - Antenna.word)); - } - } - /* Choose the desired Tx&Rx stream. */ - if ((pAd->CommonCfg.TxStream == 0) - || (pAd->CommonCfg.TxStream > Antenna.field.TxPath)) - pAd->CommonCfg.TxStream = Antenna.field.TxPath; - - if ((pAd->CommonCfg.RxStream == 0) - || (pAd->CommonCfg.RxStream > Antenna.field.RxPath)) { - pAd->CommonCfg.RxStream = Antenna.field.RxPath; - - if ((pAd->MACVersion < RALINK_2883_VERSION) && - (pAd->CommonCfg.RxStream > 2)) { - /* only 2 Rx streams for RT2860 series */ - pAd->CommonCfg.RxStream = 2; - } - } - /* 3*3 */ - /* read value from EEPROM and set them to CSR174 ~ 177 in chain0 ~ chain2 */ - /* yet implement */ - for (i = 0; i < 3; i++) { - } - - NicConfig2.word = pAd->EEPROMDefaultValue[1]; - - { - if ((NicConfig2.word & 0x00ff) == 0xff) { - NicConfig2.word &= 0xff00; - } - - if ((NicConfig2.word >> 8) == 0xff) { - NicConfig2.word &= 0x00ff; - } - } - - if (NicConfig2.field.DynamicTxAgcControl == 1) - pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE; - else - pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE; - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("NICReadEEPROMParameters: RxPath = %d, TxPath = %d\n", - Antenna.field.RxPath, Antenna.field.TxPath)); - - /* Save the antenna for future use */ - pAd->Antenna.word = Antenna.word; - - /* Set the RfICType here, then we can initialize RFIC related operation callbacks */ - pAd->Mlme.RealRxPath = (u8)Antenna.field.RxPath; - pAd->RfIcType = (u8)Antenna.field.RfIcType; - -#ifdef RTMP_RF_RW_SUPPORT - RtmpChipOpsRFHook(pAd); -#endif /* RTMP_RF_RW_SUPPORT // */ - -#ifdef RTMP_MAC_PCI - sprintf((char *)pAd->nickname, "RT2860STA"); -#endif /* RTMP_MAC_PCI // */ - - /* */ - /* Reset PhyMode if we don't support 802.11a */ - /* Only RFIC_2850 & RFIC_2750 support 802.11a */ - /* */ - if ((Antenna.field.RfIcType != RFIC_2850) - && (Antenna.field.RfIcType != RFIC_2750) - && (Antenna.field.RfIcType != RFIC_3052)) { - if ((pAd->CommonCfg.PhyMode == PHY_11ABG_MIXED) || - (pAd->CommonCfg.PhyMode == PHY_11A)) - pAd->CommonCfg.PhyMode = PHY_11BG_MIXED; - else if ((pAd->CommonCfg.PhyMode == PHY_11ABGN_MIXED) || - (pAd->CommonCfg.PhyMode == PHY_11AN_MIXED) || - (pAd->CommonCfg.PhyMode == PHY_11AGN_MIXED) || - (pAd->CommonCfg.PhyMode == PHY_11N_5G)) - pAd->CommonCfg.PhyMode = PHY_11BGN_MIXED; - } - /* Read TSSI reference and TSSI boundary for temperature compensation. This is ugly */ - /* 0. 11b/g */ - { - /* these are tempature reference value (0x00 ~ 0xFE) - ex: 0x00 0x15 0x25 0x45 0x88 0xA0 0xB5 0xD0 0xF0 - TssiPlusBoundaryG [4] [3] [2] [1] [0] (smaller) + - TssiMinusBoundaryG[0] [1] [2] [3] [4] (larger) */ - RT28xx_EEPROM_READ16(pAd, 0x6E, Power.word); - pAd->TssiMinusBoundaryG[4] = Power.field.Byte0; - pAd->TssiMinusBoundaryG[3] = Power.field.Byte1; - RT28xx_EEPROM_READ16(pAd, 0x70, Power.word); - pAd->TssiMinusBoundaryG[2] = Power.field.Byte0; - pAd->TssiMinusBoundaryG[1] = Power.field.Byte1; - RT28xx_EEPROM_READ16(pAd, 0x72, Power.word); - pAd->TssiRefG = Power.field.Byte0; /* reference value [0] */ - pAd->TssiPlusBoundaryG[1] = Power.field.Byte1; - RT28xx_EEPROM_READ16(pAd, 0x74, Power.word); - pAd->TssiPlusBoundaryG[2] = Power.field.Byte0; - pAd->TssiPlusBoundaryG[3] = Power.field.Byte1; - RT28xx_EEPROM_READ16(pAd, 0x76, Power.word); - pAd->TssiPlusBoundaryG[4] = Power.field.Byte0; - pAd->TxAgcStepG = Power.field.Byte1; - pAd->TxAgcCompensateG = 0; - pAd->TssiMinusBoundaryG[0] = pAd->TssiRefG; - pAd->TssiPlusBoundaryG[0] = pAd->TssiRefG; - - /* Disable TxAgc if the based value is not right */ - if (pAd->TssiRefG == 0xff) - pAd->bAutoTxAgcG = FALSE; - - DBGPRINT(RT_DEBUG_TRACE, - ("E2PROM: G Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n", - pAd->TssiMinusBoundaryG[4], - pAd->TssiMinusBoundaryG[3], - pAd->TssiMinusBoundaryG[2], - pAd->TssiMinusBoundaryG[1], pAd->TssiRefG, - pAd->TssiPlusBoundaryG[1], pAd->TssiPlusBoundaryG[2], - pAd->TssiPlusBoundaryG[3], pAd->TssiPlusBoundaryG[4], - pAd->TxAgcStepG, pAd->bAutoTxAgcG)); - } - /* 1. 11a */ - { - RT28xx_EEPROM_READ16(pAd, 0xD4, Power.word); - pAd->TssiMinusBoundaryA[4] = Power.field.Byte0; - pAd->TssiMinusBoundaryA[3] = Power.field.Byte1; - RT28xx_EEPROM_READ16(pAd, 0xD6, Power.word); - pAd->TssiMinusBoundaryA[2] = Power.field.Byte0; - pAd->TssiMinusBoundaryA[1] = Power.field.Byte1; - RT28xx_EEPROM_READ16(pAd, 0xD8, Power.word); - pAd->TssiRefA = Power.field.Byte0; - pAd->TssiPlusBoundaryA[1] = Power.field.Byte1; - RT28xx_EEPROM_READ16(pAd, 0xDA, Power.word); - pAd->TssiPlusBoundaryA[2] = Power.field.Byte0; - pAd->TssiPlusBoundaryA[3] = Power.field.Byte1; - RT28xx_EEPROM_READ16(pAd, 0xDC, Power.word); - pAd->TssiPlusBoundaryA[4] = Power.field.Byte0; - pAd->TxAgcStepA = Power.field.Byte1; - pAd->TxAgcCompensateA = 0; - pAd->TssiMinusBoundaryA[0] = pAd->TssiRefA; - pAd->TssiPlusBoundaryA[0] = pAd->TssiRefA; - - /* Disable TxAgc if the based value is not right */ - if (pAd->TssiRefA == 0xff) - pAd->bAutoTxAgcA = FALSE; - - DBGPRINT(RT_DEBUG_TRACE, - ("E2PROM: A Tssi[-4 .. +4] = %d %d %d %d - %d -%d %d %d %d, step=%d, tuning=%d\n", - pAd->TssiMinusBoundaryA[4], - pAd->TssiMinusBoundaryA[3], - pAd->TssiMinusBoundaryA[2], - pAd->TssiMinusBoundaryA[1], pAd->TssiRefA, - pAd->TssiPlusBoundaryA[1], pAd->TssiPlusBoundaryA[2], - pAd->TssiPlusBoundaryA[3], pAd->TssiPlusBoundaryA[4], - pAd->TxAgcStepA, pAd->bAutoTxAgcA)); - } - pAd->BbpRssiToDbmDelta = 0x0; - - /* Read frequency offset setting for RF */ - RT28xx_EEPROM_READ16(pAd, EEPROM_FREQ_OFFSET, value); - if ((value & 0x00FF) != 0x00FF) - pAd->RfFreqOffset = (unsigned long)(value & 0x00FF); - else - pAd->RfFreqOffset = 0; - DBGPRINT(RT_DEBUG_TRACE, - ("E2PROM: RF FreqOffset=0x%lx \n", pAd->RfFreqOffset)); - - /*CountryRegion byte offset (38h) */ - value = pAd->EEPROMDefaultValue[2] >> 8; /* 2.4G band */ - value2 = pAd->EEPROMDefaultValue[2] & 0x00FF; /* 5G band */ - - if ((value <= REGION_MAXIMUM_BG_BAND) - && (value2 <= REGION_MAXIMUM_A_BAND)) { - pAd->CommonCfg.CountryRegion = ((u8)value) | 0x80; - pAd->CommonCfg.CountryRegionForABand = ((u8)value2) | 0x80; - TmpPhy = pAd->CommonCfg.PhyMode; - pAd->CommonCfg.PhyMode = 0xff; - RTMPSetPhyMode(pAd, TmpPhy); - SetCommonHT(pAd); - } - /* */ - /* Get RSSI Offset on EEPROM 0x9Ah & 0x9Ch. */ - /* The valid value are (-10 ~ 10) */ - /* */ - RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET, value); - pAd->BGRssiOffset0 = value & 0x00ff; - pAd->BGRssiOffset1 = (value >> 8); - RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_BG_OFFSET + 2, value); - pAd->BGRssiOffset2 = value & 0x00ff; - pAd->ALNAGain1 = (value >> 8); - RT28xx_EEPROM_READ16(pAd, EEPROM_LNA_OFFSET, value); - pAd->BLNAGain = value & 0x00ff; - pAd->ALNAGain0 = (value >> 8); - - /* Validate 11b/g RSSI_0 offset. */ - if ((pAd->BGRssiOffset0 < -10) || (pAd->BGRssiOffset0 > 10)) - pAd->BGRssiOffset0 = 0; - - /* Validate 11b/g RSSI_1 offset. */ - if ((pAd->BGRssiOffset1 < -10) || (pAd->BGRssiOffset1 > 10)) - pAd->BGRssiOffset1 = 0; - - /* Validate 11b/g RSSI_2 offset. */ - if ((pAd->BGRssiOffset2 < -10) || (pAd->BGRssiOffset2 > 10)) - pAd->BGRssiOffset2 = 0; - - RT28xx_EEPROM_READ16(pAd, EEPROM_RSSI_A_OFFSET, value); - pAd->ARssiOffset0 = value & 0x00ff; - pAd->ARssiOffset1 = (value >> 8); - RT28xx_EEPROM_READ16(pAd, (EEPROM_RSSI_A_OFFSET + 2), value); - pAd->ARssiOffset2 = value & 0x00ff; - pAd->ALNAGain2 = (value >> 8); - - if (((u8)pAd->ALNAGain1 == 0xFF) || (pAd->ALNAGain1 == 0x00)) - pAd->ALNAGain1 = pAd->ALNAGain0; - if (((u8)pAd->ALNAGain2 == 0xFF) || (pAd->ALNAGain2 == 0x00)) - pAd->ALNAGain2 = pAd->ALNAGain0; - - /* Validate 11a RSSI_0 offset. */ - if ((pAd->ARssiOffset0 < -10) || (pAd->ARssiOffset0 > 10)) - pAd->ARssiOffset0 = 0; - - /* Validate 11a RSSI_1 offset. */ - if ((pAd->ARssiOffset1 < -10) || (pAd->ARssiOffset1 > 10)) - pAd->ARssiOffset1 = 0; - - /*Validate 11a RSSI_2 offset. */ - if ((pAd->ARssiOffset2 < -10) || (pAd->ARssiOffset2 > 10)) - pAd->ARssiOffset2 = 0; - -#ifdef RT30xx - /* */ - /* Get TX mixer gain setting */ - /* 0xff are invalid value */ - /* Note: RT30xX default value is 0x00 and will program to RF_R17 only when this value is not zero. */ - /* RT359X default value is 0x02 */ - /* */ - if (IS_RT30xx(pAd) || IS_RT3572(pAd)) { - RT28xx_EEPROM_READ16(pAd, EEPROM_TXMIXER_GAIN_2_4G, value); - pAd->TxMixerGain24G = 0; - value &= 0x00ff; - if (value != 0xff) { - value &= 0x07; - pAd->TxMixerGain24G = (u8)value; - } - } -#endif /* RT30xx // */ - - /* */ - /* Get LED Setting. */ - /* */ - RT28xx_EEPROM_READ16(pAd, 0x3a, value); - pAd->LedCntl.word = (value >> 8); - RT28xx_EEPROM_READ16(pAd, EEPROM_LED1_OFFSET, value); - pAd->Led1 = value; - RT28xx_EEPROM_READ16(pAd, EEPROM_LED2_OFFSET, value); - pAd->Led2 = value; - RT28xx_EEPROM_READ16(pAd, EEPROM_LED3_OFFSET, value); - pAd->Led3 = value; - - RTMPReadTxPwrPerRate(pAd); - -#ifdef RT30xx -#ifdef RTMP_EFUSE_SUPPORT - RtmpEfuseSupportCheck(pAd); -#endif /* RTMP_EFUSE_SUPPORT // */ -#endif /* RT30xx // */ - - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICReadEEPROMParameters\n")); -} - -/* - ======================================================================== - - Routine Description: - Set default value from EEPROM - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - Note: - - ======================================================================== -*/ -void NICInitAsicFromEEPROM(struct rt_rtmp_adapter *pAd) -{ - u32 data = 0; - u8 BBPR1 = 0; - u16 i; -/* EEPROM_ANTENNA_STRUC Antenna; */ - EEPROM_NIC_CONFIG2_STRUC NicConfig2; - u8 BBPR3 = 0; - - DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitAsicFromEEPROM\n")); - for (i = 3; i < NUM_EEPROM_BBP_PARMS; i++) { - u8 BbpRegIdx, BbpValue; - - if ((pAd->EEPROMDefaultValue[i] != 0xFFFF) - && (pAd->EEPROMDefaultValue[i] != 0)) { - BbpRegIdx = (u8)(pAd->EEPROMDefaultValue[i] >> 8); - BbpValue = (u8)(pAd->EEPROMDefaultValue[i] & 0xff); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BbpRegIdx, BbpValue); - } - } - - NicConfig2.word = pAd->EEPROMDefaultValue[1]; - - { - if ((NicConfig2.word & 0x00ff) == 0xff) { - NicConfig2.word &= 0xff00; - } - - if ((NicConfig2.word >> 8) == 0xff) { - NicConfig2.word &= 0x00ff; - } - } - - /* Save the antenna for future use */ - pAd->NicConfig2.word = NicConfig2.word; - -#ifdef RT30xx - /* set default antenna as main */ - if (pAd->RfIcType == RFIC_3020) - AsicSetRxAnt(pAd, pAd->RxAnt.Pair1PrimaryRxAnt); -#endif /* RT30xx // */ - - /* */ - /* Send LED Setting to MCU. */ - /* */ - if (pAd->LedCntl.word == 0xFF) { - pAd->LedCntl.word = 0x01; - pAd->Led1 = 0x5555; - pAd->Led2 = 0x2221; - -#ifdef RTMP_MAC_PCI - pAd->Led3 = 0xA9F8; -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - pAd->Led3 = 0x5627; -#endif /* RTMP_MAC_USB // */ - } - - AsicSendCommandToMcu(pAd, 0x52, 0xff, (u8)pAd->Led1, - (u8)(pAd->Led1 >> 8)); - AsicSendCommandToMcu(pAd, 0x53, 0xff, (u8)pAd->Led2, - (u8)(pAd->Led2 >> 8)); - AsicSendCommandToMcu(pAd, 0x54, 0xff, (u8)pAd->Led3, - (u8)(pAd->Led3 >> 8)); - AsicSendCommandToMcu(pAd, 0x51, 0xff, 0, pAd->LedCntl.field.Polarity); - - pAd->LedIndicatorStrength = 0xFF; - RTMPSetSignalLED(pAd, -100); /* Force signal strength Led to be turned off, before link up */ - - { - /* Read Hardware controlled Radio state enable bit */ - if (NicConfig2.field.HardwareRadioControl == 1) { - pAd->StaCfg.bHardwareRadio = TRUE; - - /* Read GPIO pin2 as Hardware controlled radio state */ - RTMP_IO_READ32(pAd, GPIO_CTRL_CFG, &data); - if ((data & 0x04) == 0) { - pAd->StaCfg.bHwRadio = FALSE; - pAd->StaCfg.bRadio = FALSE; -/* RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818); */ - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); - } - } else - pAd->StaCfg.bHardwareRadio = FALSE; - - if (pAd->StaCfg.bRadio == FALSE) { - RTMPSetLED(pAd, LED_RADIO_OFF); - } else { - RTMPSetLED(pAd, LED_RADIO_ON); -#ifdef RTMP_MAC_PCI -#ifdef RT3090 - AsicSendCommandToMcu(pAd, 0x30, PowerRadioOffCID, 0xff, - 0x02); - AsicCheckCommanOk(pAd, PowerRadioOffCID); -#endif /* RT3090 // */ -#ifndef RT3090 - AsicSendCommandToMcu(pAd, 0x30, 0xff, 0xff, 0x02); -#endif /* RT3090 // */ - AsicSendCommandToMcu(pAd, 0x31, PowerWakeCID, 0x00, - 0x00); - /* 2-1. wait command ok. */ - AsicCheckCommanOk(pAd, PowerWakeCID); -#endif /* RTMP_MAC_PCI // */ - } - } - -#ifdef RTMP_MAC_PCI -#ifdef RT30xx - if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) { - struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps; - if (pChipOps->AsicReverseRfFromSleepMode) - pChipOps->AsicReverseRfFromSleepMode(pAd); - } - /* 3090 MCU Wakeup command needs more time to be stable. */ - /* Before stable, don't issue other MCU command to prevent from firmware error. */ - - if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) { - DBGPRINT(RT_DEBUG_TRACE, ("%s, release Mcu Lock\n", __func__)); - RTMP_SEM_LOCK(&pAd->McuCmdLock); - pAd->brt30xxBanMcuCmd = FALSE; - RTMP_SEM_UNLOCK(&pAd->McuCmdLock); - } -#endif /* RT30xx // */ -#endif /* RTMP_MAC_PCI // */ - - /* Turn off patching for cardbus controller */ - if (NicConfig2.field.CardbusAcceleration == 1) { -/* pAd->bTest1 = TRUE; */ - } - - if (NicConfig2.field.DynamicTxAgcControl == 1) - pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = TRUE; - else - pAd->bAutoTxAgcA = pAd->bAutoTxAgcG = FALSE; - /* */ - /* Since BBP has been progamed, to make sure BBP setting will be */ - /* upate inside of AsicAntennaSelect, so reset to UNKNOWN_BAND! */ - /* */ - pAd->CommonCfg.BandState = UNKNOWN_BAND; - - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &BBPR3); - BBPR3 &= (~0x18); - if (pAd->Antenna.field.RxPath == 3) { - BBPR3 |= (0x10); - } else if (pAd->Antenna.field.RxPath == 2) { - BBPR3 |= (0x8); - } else if (pAd->Antenna.field.RxPath == 1) { - BBPR3 |= (0x0); - } - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, BBPR3); - - { - /* Handle the difference when 1T */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &BBPR1); - if (pAd->Antenna.field.TxPath == 1) { - BBPR1 &= (~0x18); - } - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, BBPR1); - - DBGPRINT(RT_DEBUG_TRACE, - ("Use Hw Radio Control Pin=%d; if used Pin=%d;\n", - pAd->CommonCfg.bHardwareRadio, - pAd->CommonCfg.bHardwareRadio)); - } - -#ifdef RTMP_MAC_USB -#ifdef RT30xx - /* update registers from EEPROM for RT3071 or later(3572/3592). */ - - if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) { - u8 RegIdx, RegValue; - u16 value; - - /* after RT3071, write BBP from EEPROM 0xF0 to 0x102 */ - for (i = 0xF0; i <= 0x102; i = i + 2) { - value = 0xFFFF; - RT28xx_EEPROM_READ16(pAd, i, value); - if ((value != 0xFFFF) && (value != 0)) { - RegIdx = (u8)(value >> 8); - RegValue = (u8)(value & 0xff); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, RegIdx, - RegValue); - DBGPRINT(RT_DEBUG_TRACE, - ("Update BBP Registers from EEPROM(0x%0x), BBP(0x%x) = 0x%x\n", - i, RegIdx, RegValue)); - } - } - - /* after RT3071, write RF from EEPROM 0x104 to 0x116 */ - for (i = 0x104; i <= 0x116; i = i + 2) { - value = 0xFFFF; - RT28xx_EEPROM_READ16(pAd, i, value); - if ((value != 0xFFFF) && (value != 0)) { - RegIdx = (u8)(value >> 8); - RegValue = (u8)(value & 0xff); - RT30xxWriteRFRegister(pAd, RegIdx, RegValue); - DBGPRINT(RT_DEBUG_TRACE, - ("Update RF Registers from EEPROM0x%x), BBP(0x%x) = 0x%x\n", - i, RegIdx, RegValue)); - } - } - } -#endif /* RT30xx // */ -#endif /* RTMP_MAC_USB // */ - - DBGPRINT(RT_DEBUG_TRACE, - ("TxPath = %d, RxPath = %d, RFIC=%d, Polar+LED mode=%x\n", - pAd->Antenna.field.TxPath, pAd->Antenna.field.RxPath, - pAd->RfIcType, pAd->LedCntl.word)); - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitAsicFromEEPROM\n")); -} - -/* - ======================================================================== - - Routine Description: - Initialize NIC hardware - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - Note: - - ======================================================================== -*/ -int NICInitializeAdapter(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset) -{ - int Status = NDIS_STATUS_SUCCESS; - WPDMA_GLO_CFG_STRUC GloCfg; -#ifdef RTMP_MAC_PCI - u32 Value; - DELAY_INT_CFG_STRUC IntCfg; -#endif /* RTMP_MAC_PCI // */ -/* INT_MASK_CSR_STRUC IntMask; */ - unsigned long i = 0, j = 0; - AC_TXOP_CSR0_STRUC csr0; - - DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAdapter\n")); - - /* 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits: */ -retry: - i = 0; - do { - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); - if ((GloCfg.field.TxDMABusy == 0) - && (GloCfg.field.RxDMABusy == 0)) - break; - - RTMPusecDelay(1000); - i++; - } while (i < 100); - DBGPRINT(RT_DEBUG_TRACE, - ("<== DMA offset 0x208 = 0x%x\n", GloCfg.word)); - GloCfg.word &= 0xff0; - GloCfg.field.EnTXWriteBackDDONE = 1; - RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word); - - /* Record HW Beacon offset */ - pAd->BeaconOffset[0] = HW_BEACON_BASE0; - pAd->BeaconOffset[1] = HW_BEACON_BASE1; - pAd->BeaconOffset[2] = HW_BEACON_BASE2; - pAd->BeaconOffset[3] = HW_BEACON_BASE3; - pAd->BeaconOffset[4] = HW_BEACON_BASE4; - pAd->BeaconOffset[5] = HW_BEACON_BASE5; - pAd->BeaconOffset[6] = HW_BEACON_BASE6; - pAd->BeaconOffset[7] = HW_BEACON_BASE7; - - /* */ - /* write all shared Ring's base address into ASIC */ - /* */ - - /* asic simulation sequence put this ahead before loading firmware. */ - /* pbf hardware reset */ -#ifdef RTMP_MAC_PCI - RTMP_IO_WRITE32(pAd, WPDMA_RST_IDX, 0x1003f); /* 0x10000 for reset rx, 0x3f resets all 6 tx rings. */ - RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0xe1f); - RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, 0xe00); -#endif /* RTMP_MAC_PCI // */ - - /* Initialze ASIC for TX & Rx operation */ - if (NICInitializeAsic(pAd, bHardReset) != NDIS_STATUS_SUCCESS) { - if (j++ == 0) { - NICLoadFirmware(pAd); - goto retry; - } - return NDIS_STATUS_FAILURE; - } - -#ifdef RTMP_MAC_PCI - /* Write AC_BK base address register */ - Value = - RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_BK].Cell[0].AllocPa); - RTMP_IO_WRITE32(pAd, TX_BASE_PTR1, Value); - DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR1 : 0x%x\n", Value)); - - /* Write AC_BE base address register */ - Value = - RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_BE].Cell[0].AllocPa); - RTMP_IO_WRITE32(pAd, TX_BASE_PTR0, Value); - DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR0 : 0x%x\n", Value)); - - /* Write AC_VI base address register */ - Value = - RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_VI].Cell[0].AllocPa); - RTMP_IO_WRITE32(pAd, TX_BASE_PTR2, Value); - DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR2 : 0x%x\n", Value)); - - /* Write AC_VO base address register */ - Value = - RTMP_GetPhysicalAddressLow(pAd->TxRing[QID_AC_VO].Cell[0].AllocPa); - RTMP_IO_WRITE32(pAd, TX_BASE_PTR3, Value); - DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR3 : 0x%x\n", Value)); - - /* Write MGMT_BASE_CSR register */ - Value = RTMP_GetPhysicalAddressLow(pAd->MgmtRing.Cell[0].AllocPa); - RTMP_IO_WRITE32(pAd, TX_BASE_PTR5, Value); - DBGPRINT(RT_DEBUG_TRACE, ("--> TX_BASE_PTR5 : 0x%x\n", Value)); - - /* Write RX_BASE_CSR register */ - Value = RTMP_GetPhysicalAddressLow(pAd->RxRing.Cell[0].AllocPa); - RTMP_IO_WRITE32(pAd, RX_BASE_PTR, Value); - DBGPRINT(RT_DEBUG_TRACE, ("--> RX_BASE_PTR : 0x%x\n", Value)); - - /* Init RX Ring index pointer */ - pAd->RxRing.RxSwReadIdx = 0; - pAd->RxRing.RxCpuIdx = RX_RING_SIZE - 1; - RTMP_IO_WRITE32(pAd, RX_CRX_IDX, pAd->RxRing.RxCpuIdx); - - /* Init TX rings index pointer */ - { - for (i = 0; i < NUM_OF_TX_RING; i++) { - pAd->TxRing[i].TxSwFreeIdx = 0; - pAd->TxRing[i].TxCpuIdx = 0; - RTMP_IO_WRITE32(pAd, (TX_CTX_IDX0 + i * 0x10), - pAd->TxRing[i].TxCpuIdx); - } - } - - /* init MGMT ring index pointer */ - pAd->MgmtRing.TxSwFreeIdx = 0; - pAd->MgmtRing.TxCpuIdx = 0; - RTMP_IO_WRITE32(pAd, TX_MGMTCTX_IDX, pAd->MgmtRing.TxCpuIdx); - - /* */ - /* set each Ring's SIZE into ASIC. Descriptor Size is fixed by design. */ - /* */ - - /* Write TX_RING_CSR0 register */ - Value = TX_RING_SIZE; - RTMP_IO_WRITE32(pAd, TX_MAX_CNT0, Value); - RTMP_IO_WRITE32(pAd, TX_MAX_CNT1, Value); - RTMP_IO_WRITE32(pAd, TX_MAX_CNT2, Value); - RTMP_IO_WRITE32(pAd, TX_MAX_CNT3, Value); - RTMP_IO_WRITE32(pAd, TX_MAX_CNT4, Value); - Value = MGMT_RING_SIZE; - RTMP_IO_WRITE32(pAd, TX_MGMTMAX_CNT, Value); - - /* Write RX_RING_CSR register */ - Value = RX_RING_SIZE; - RTMP_IO_WRITE32(pAd, RX_MAX_CNT, Value); -#endif /* RTMP_MAC_PCI // */ - - /* WMM parameter */ - csr0.word = 0; - RTMP_IO_WRITE32(pAd, WMM_TXOP0_CFG, csr0.word); - if (pAd->CommonCfg.PhyMode == PHY_11B) { - csr0.field.Ac0Txop = 192; /* AC_VI: 192*32us ~= 6ms */ - csr0.field.Ac1Txop = 96; /* AC_VO: 96*32us ~= 3ms */ - } else { - csr0.field.Ac0Txop = 96; /* AC_VI: 96*32us ~= 3ms */ - csr0.field.Ac1Txop = 48; /* AC_VO: 48*32us ~= 1.5ms */ - } - RTMP_IO_WRITE32(pAd, WMM_TXOP1_CFG, csr0.word); - -#ifdef RTMP_MAC_PCI - /* 3. Set DMA global configuration except TX_DMA_EN and RX_DMA_EN bits: */ - i = 0; - do { - RTMP_IO_READ32(pAd, WPDMA_GLO_CFG, &GloCfg.word); - if ((GloCfg.field.TxDMABusy == 0) - && (GloCfg.field.RxDMABusy == 0)) - break; - - RTMPusecDelay(1000); - i++; - } while (i < 100); - - GloCfg.word &= 0xff0; - GloCfg.field.EnTXWriteBackDDONE = 1; - RTMP_IO_WRITE32(pAd, WPDMA_GLO_CFG, GloCfg.word); - - IntCfg.word = 0; - RTMP_IO_WRITE32(pAd, DELAY_INT_CFG, IntCfg.word); -#endif /* RTMP_MAC_PCI // */ - - /* reset action */ - /* Load firmware */ - /* Status = NICLoadFirmware(pAd); */ - - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAdapter\n")); - return Status; -} - -/* - ======================================================================== - - Routine Description: - Initialize ASIC - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - Note: - - ======================================================================== -*/ -int NICInitializeAsic(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset) -{ - unsigned long Index = 0; - u8 R0 = 0xff; - u32 MacCsr12 = 0, Counter = 0; -#ifdef RTMP_MAC_USB - u32 MacCsr0 = 0; - int Status; - u8 Value = 0xff; -#endif /* RTMP_MAC_USB // */ -#ifdef RT30xx - u8 bbpreg = 0; - u8 RFValue = 0; -#endif /* RT30xx // */ - u16 KeyIdx; - int i, apidx; - - DBGPRINT(RT_DEBUG_TRACE, ("--> NICInitializeAsic\n")); - -#ifdef RTMP_MAC_PCI - RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x3); /* To fix driver disable/enable hang issue when radio off */ - if (bHardReset == TRUE) { - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x3); - } else - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1); - - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0); - /* Initialize MAC register to default value */ - for (Index = 0; Index < NUM_MAC_REG_PARMS; Index++) { - RTMP_IO_WRITE32(pAd, MACRegTable[Index].Register, - MACRegTable[Index].Value); - } - - { - for (Index = 0; Index < NUM_STA_MAC_REG_PARMS; Index++) { - RTMP_IO_WRITE32(pAd, STAMACRegTable[Index].Register, - STAMACRegTable[Index].Value); - } - } -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - /* */ - /* Make sure MAC gets ready after NICLoadFirmware(). */ - /* */ - Index = 0; - - /*To avoid hang-on issue when interface up in kernel 2.4, */ - /*we use a local variable "MacCsr0" instead of using "pAd->MACVersion" directly. */ - do { - RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0); - - if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF)) - break; - - RTMPusecDelay(10); - } while (Index++ < 100); - - pAd->MACVersion = MacCsr0; - DBGPRINT(RT_DEBUG_TRACE, - ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion)); - /* turn on bit13 (set to zero) after rt2860D. This is to solve high-current issue. */ - RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacCsr12); - MacCsr12 &= (~0x2000); - RTMP_IO_WRITE32(pAd, PBF_SYS_CTRL, MacCsr12); - - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x3); - RTMP_IO_WRITE32(pAd, USB_DMA_CFG, 0x0); - Status = RTUSBVenderReset(pAd); - - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0); - - /* Initialize MAC register to default value */ - for (Index = 0; Index < NUM_MAC_REG_PARMS; Index++) { -#ifdef RT30xx - if ((MACRegTable[Index].Register == TX_SW_CFG0) - && (IS_RT3070(pAd) || IS_RT3071(pAd) || IS_RT3572(pAd) - || IS_RT3090(pAd) || IS_RT3390(pAd))) { - MACRegTable[Index].Value = 0x00000400; - } -#endif /* RT30xx // */ - RTMP_IO_WRITE32(pAd, (u16)MACRegTable[Index].Register, - MACRegTable[Index].Value); - } - - { - for (Index = 0; Index < NUM_STA_MAC_REG_PARMS; Index++) { - RTMP_IO_WRITE32(pAd, - (u16)STAMACRegTable[Index].Register, - STAMACRegTable[Index].Value); - } - } -#endif /* RTMP_MAC_USB // */ - -#ifdef RT30xx - /* Initialize RT3070 serial MAC registers which is different from RT2870 serial */ - if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) { - RTMP_IO_WRITE32(pAd, TX_SW_CFG1, 0); - - /* RT3071 version E has fixed this issue */ - if ((pAd->MACVersion & 0xffff) < 0x0211) { - if (pAd->NicConfig2.field.DACTestBit == 1) { - RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x2C); /* To fix throughput drop drastically */ - } else { - RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x0F); /* To fix throughput drop drastically */ - } - } else { - RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x0); - } - } else if (IS_RT3070(pAd)) { - if (((pAd->MACVersion & 0xffff) < 0x0201)) { - RTMP_IO_WRITE32(pAd, TX_SW_CFG1, 0); - RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0x2C); /* To fix throughput drop drastically */ - } else { - RTMP_IO_WRITE32(pAd, TX_SW_CFG2, 0); - } - } -#endif /* RT30xx // */ - - /* */ - /* Before program BBP, we need to wait BBP/RF get wake up. */ - /* */ - Index = 0; - do { - RTMP_IO_READ32(pAd, MAC_STATUS_CFG, &MacCsr12); - - if ((MacCsr12 & 0x03) == 0) /* if BB.RF is stable */ - break; - - DBGPRINT(RT_DEBUG_TRACE, - ("Check MAC_STATUS_CFG = Busy = %x\n", MacCsr12)); - RTMPusecDelay(1000); - } while (Index++ < 100); - - /* The commands to firmware should be after these commands, these commands will init firmware */ - /* PCI and USB are not the same because PCI driver needs to wait for PCI bus ready */ - RTMP_IO_WRITE32(pAd, H2M_BBP_AGENT, 0); /* initialize BBP R/W access agent */ - RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, 0); -#ifdef RT3090 - /*2008/11/28:KH add to fix the dead rf frequency offset bug<-- */ - AsicSendCommandToMcu(pAd, 0x72, 0, 0, 0); - /*2008/11/28:KH add to fix the dead rf frequency offset bug--> */ -#endif /* RT3090 // */ - RTMPusecDelay(1000); - - /* Read BBP register, make sure BBP is up and running before write new data */ - Index = 0; - do { - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R0, &R0); - DBGPRINT(RT_DEBUG_TRACE, ("BBP version = %x\n", R0)); - } while ((++Index < 20) && ((R0 == 0xff) || (R0 == 0x00))); - /*ASSERT(Index < 20); //this will cause BSOD on Check-build driver */ - - if ((R0 == 0xff) || (R0 == 0x00)) - return NDIS_STATUS_FAILURE; - - /* Initialize BBP register to default value */ - for (Index = 0; Index < NUM_BBP_REG_PARMS; Index++) { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBPRegTable[Index].Register, - BBPRegTable[Index].Value); - } - -#ifdef RTMP_MAC_PCI - /* TODO: shiang, check MACVersion, currently, rbus-based chip use this. */ - if (pAd->MACVersion == 0x28720200) { - /*u8 value; */ - unsigned long value2; - - /*disable MLD by Bruce 20080704 */ - /*BBP_IO_READ8_BY_REG_ID(pAd, BBP_R105, &value); */ - /*BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R105, value | 4); */ - - /*Maximum PSDU length from 16K to 32K bytes */ - RTMP_IO_READ32(pAd, MAX_LEN_CFG, &value2); - value2 &= ~(0x3 << 12); - value2 |= (0x2 << 12); - RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, value2); - } -#endif /* RTMP_MAC_PCI // */ - - /* for rt2860E and after, init BBP_R84 with 0x19. This is for extension channel overlapping IOT. */ - /* RT3090 should not program BBP R84 to 0x19, otherwise TX will block. */ - /*3070/71/72,3090,3090A( are included in RT30xx),3572,3390 */ - if (((pAd->MACVersion & 0xffff) != 0x0101) - && !(IS_RT30xx(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))) - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R84, 0x19); - -#ifdef RT30xx -/* add by johnli, RF power sequence setup */ - if (IS_RT30xx(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) { /*update for RT3070/71/72/90/91/92,3572,3390. */ - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R79, 0x13); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R80, 0x05); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R81, 0x33); - } - - if (IS_RT3090(pAd) || IS_RT3390(pAd)) /* RT309x, RT3071/72 */ - { - /* enable DC filter */ - if ((pAd->MACVersion & 0xffff) >= 0x0211) { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R103, 0xc0); - } - /* improve power consumption */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R138, &bbpreg); - if (pAd->Antenna.field.TxPath == 1) { - /* turn off tx DAC_1 */ - bbpreg = (bbpreg | 0x20); - } - - if (pAd->Antenna.field.RxPath == 1) { - /* turn off tx ADC_1 */ - bbpreg &= (~0x2); - } - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R138, bbpreg); - - /* improve power consumption in RT3071 Ver.E */ - if ((pAd->MACVersion & 0xffff) >= 0x0211) { - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R31, &bbpreg); - bbpreg &= (~0x3); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R31, bbpreg); - } - } else if (IS_RT3070(pAd)) { - if ((pAd->MACVersion & 0xffff) >= 0x0201) { - /* enable DC filter */ - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R103, 0xc0); - - /* improve power consumption in RT3070 Ver.F */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R31, &bbpreg); - bbpreg &= (~0x3); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R31, bbpreg); - } - /* TX_LO1_en, RF R17 register Bit 3 to 0 */ - RT30xxReadRFRegister(pAd, RF_R17, &RFValue); - RFValue &= (~0x08); - /* to fix rx long range issue */ - if (pAd->NicConfig2.field.ExternalLNAForG == 0) { - RFValue |= 0x20; - } - /* set RF_R17_bit[2:0] equal to EEPROM setting at 0x48h */ - if (pAd->TxMixerGain24G >= 1) { - RFValue &= (~0x7); /* clean bit [2:0] */ - RFValue |= pAd->TxMixerGain24G; - } - RT30xxWriteRFRegister(pAd, RF_R17, RFValue); - } -/* end johnli */ -#endif /* RT30xx // */ - - if (pAd->MACVersion == 0x28600100) { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x12); - } - - if (pAd->MACVersion >= RALINK_2880E_VERSION && pAd->MACVersion < RALINK_3070_VERSION) /* 3*3 */ - { - /* enlarge MAX_LEN_CFG */ - u32 csr; - RTMP_IO_READ32(pAd, MAX_LEN_CFG, &csr); - csr &= 0xFFF; - csr |= 0x2000; - RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, csr); - } -#ifdef RTMP_MAC_USB - { - u8 MAC_Value[] = - { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0 }; - - /*Initialize WCID table */ - Value = 0xff; - for (Index = 0; Index < 254; Index++) { - RTUSBMultiWrite(pAd, - (u16)(MAC_WCID_BASE + Index * 8), - MAC_Value, 8); - } - } -#endif /* RTMP_MAC_USB // */ - - /* Add radio off control */ - { - if (pAd->StaCfg.bRadio == FALSE) { -/* RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x00001818); */ - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); - DBGPRINT(RT_DEBUG_TRACE, ("Set Radio Off\n")); - } - } - - /* Clear raw counters */ - RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter); - RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter); - RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter); - RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter); - RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter); - RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter); - - /* ASIC will keep garbage value after boot */ - /* Clear all shared key table when initial */ - /* This routine can be ignored in radio-ON/OFF operation. */ - if (bHardReset) { - for (KeyIdx = 0; KeyIdx < 4; KeyIdx++) { - RTMP_IO_WRITE32(pAd, SHARED_KEY_MODE_BASE + 4 * KeyIdx, - 0); - } - - /* Clear all pairwise key table when initial */ - for (KeyIdx = 0; KeyIdx < 256; KeyIdx++) { - RTMP_IO_WRITE32(pAd, - MAC_WCID_ATTRIBUTE_BASE + - (KeyIdx * HW_WCID_ATTRI_SIZE), 1); - } - } - /* assert HOST ready bit */ -/* RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x0); // 2004-09-14 asked by Mark */ -/* RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x4); */ - - /* It isn't necessary to clear this space when not hard reset. */ - if (bHardReset == TRUE) { - /* clear all on-chip BEACON frame space */ - for (apidx = 0; apidx < HW_BEACON_MAX_COUNT; apidx++) { - for (i = 0; i < HW_BEACON_OFFSET >> 2; i += 4) - RTMP_IO_WRITE32(pAd, - pAd->BeaconOffset[apidx] + i, - 0x00); - } - } -#ifdef RTMP_MAC_USB - AsicDisableSync(pAd); - /* Clear raw counters */ - RTMP_IO_READ32(pAd, RX_STA_CNT0, &Counter); - RTMP_IO_READ32(pAd, RX_STA_CNT1, &Counter); - RTMP_IO_READ32(pAd, RX_STA_CNT2, &Counter); - RTMP_IO_READ32(pAd, TX_STA_CNT0, &Counter); - RTMP_IO_READ32(pAd, TX_STA_CNT1, &Counter); - RTMP_IO_READ32(pAd, TX_STA_CNT2, &Counter); - /* Default PCI clock cycle per ms is different as default setting, which is based on PCI. */ - RTMP_IO_READ32(pAd, USB_CYC_CFG, &Counter); - Counter &= 0xffffff00; - Counter |= 0x000001e; - RTMP_IO_WRITE32(pAd, USB_CYC_CFG, Counter); -#endif /* RTMP_MAC_USB // */ - - { - /* for rt2860E and after, init TXOP_CTRL_CFG with 0x583f. This is for extension channel overlapping IOT. */ - if ((pAd->MACVersion & 0xffff) != 0x0101) - RTMP_IO_WRITE32(pAd, TXOP_CTRL_CFG, 0x583f); - } - - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICInitializeAsic\n")); - return NDIS_STATUS_SUCCESS; -} - -/* - ======================================================================== - - Routine Description: - Reset NIC Asics - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - Note: - Reset NIC to initial state AS IS system boot up time. - - ======================================================================== -*/ -void NICIssueReset(struct rt_rtmp_adapter *pAd) -{ - u32 Value = 0; - DBGPRINT(RT_DEBUG_TRACE, ("--> NICIssueReset\n")); - - /* Abort Tx, prevent ASIC from writing to Host memory */ - /*RTMP_IO_WRITE32(pAd, TX_CNTL_CSR, 0x001f0000); */ - - /* Disable Rx, register value supposed will remain after reset */ - RTMP_IO_READ32(pAd, MAC_SYS_CTRL, &Value); - Value &= (0xfffffff3); - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, Value); - - /* Issue reset and clear from reset state */ - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x03); /* 2004-09-17 change from 0x01 */ - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x00); - - DBGPRINT(RT_DEBUG_TRACE, ("<-- NICIssueReset\n")); -} - -/* - ======================================================================== - - Routine Description: - Check ASIC registers and find any reason the system might hang - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - ======================================================================== -*/ -BOOLEAN NICCheckForHang(struct rt_rtmp_adapter *pAd) -{ - return (FALSE); -} - -void NICUpdateFifoStaCounters(struct rt_rtmp_adapter *pAd) -{ - TX_STA_FIFO_STRUC StaFifo; - struct rt_mac_table_entry *pEntry; - u8 i = 0; - u8 pid = 0, wcid = 0; - char reTry; - u8 succMCS; - - do { - RTMP_IO_READ32(pAd, TX_STA_FIFO, &StaFifo.word); - - if (StaFifo.field.bValid == 0) - break; - - wcid = (u8)StaFifo.field.wcid; - - /* ignore NoACK and MGMT frame use 0xFF as WCID */ - if ((StaFifo.field.TxAckRequired == 0) - || (wcid >= MAX_LEN_OF_MAC_TABLE)) { - i++; - continue; - } - - /* PID store Tx MCS Rate */ - pid = (u8)StaFifo.field.PidType; - - pEntry = &pAd->MacTab.Content[wcid]; - - pEntry->DebugFIFOCount++; - - if (StaFifo.field.TxBF) /* 3*3 */ - pEntry->TxBFCount++; - - if (!StaFifo.field.TxSuccess) { - pEntry->FIFOCount++; - pEntry->OneSecTxFailCount++; - - if (pEntry->FIFOCount >= 1) { - DBGPRINT(RT_DEBUG_TRACE, ("#")); - pEntry->NoBADataCountDown = 64; - - if (pEntry->PsMode == PWR_ACTIVE) { - int tid; - for (tid = 0; tid < NUM_OF_TID; tid++) { - BAOriSessionTearDown(pAd, - pEntry-> - Aid, tid, - FALSE, - FALSE); - } - - /* Update the continuous transmission counter except PS mode */ - pEntry->ContinueTxFailCnt++; - } else { - /* Clear the FIFOCount when sta in Power Save mode. Basically we assume */ - /* this tx error happened due to sta just go to sleep. */ - pEntry->FIFOCount = 0; - pEntry->ContinueTxFailCnt = 0; - } - /*pEntry->FIFOCount = 0; */ - } - /*pEntry->bSendBAR = TRUE; */ - } else { - if ((pEntry->PsMode != PWR_SAVE) - && (pEntry->NoBADataCountDown > 0)) { - pEntry->NoBADataCountDown--; - if (pEntry->NoBADataCountDown == 0) { - DBGPRINT(RT_DEBUG_TRACE, ("@\n")); - } - } - - pEntry->FIFOCount = 0; - pEntry->OneSecTxNoRetryOkCount++; - /* update NoDataIdleCount when successful send packet to STA. */ - pEntry->NoDataIdleCount = 0; - pEntry->ContinueTxFailCnt = 0; - } - - succMCS = StaFifo.field.SuccessRate & 0x7F; - - reTry = pid - succMCS; - - if (StaFifo.field.TxSuccess) { - pEntry->TXMCSExpected[pid]++; - if (pid == succMCS) { - pEntry->TXMCSSuccessful[pid]++; - } else { - pEntry->TXMCSAutoFallBack[pid][succMCS]++; - } - } else { - pEntry->TXMCSFailed[pid]++; - } - - if (reTry > 0) { - if ((pid >= 12) && succMCS <= 7) { - reTry -= 4; - } - pEntry->OneSecTxRetryOkCount += reTry; - } - - i++; - /* ASIC store 16 stack */ - } while (i < (2 * TX_RING_SIZE)); - -} - -/* - ======================================================================== - - Routine Description: - Read statistical counters from hardware registers and record them - in software variables for later on query - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - ======================================================================== -*/ -void NICUpdateRawCounters(struct rt_rtmp_adapter *pAd) -{ - u32 OldValue; /*, Value2; */ - /*unsigned long PageSum, OneSecTransmitCount; */ - /*unsigned long TxErrorRatio, Retry, Fail; */ - RX_STA_CNT0_STRUC RxStaCnt0; - RX_STA_CNT1_STRUC RxStaCnt1; - RX_STA_CNT2_STRUC RxStaCnt2; - TX_STA_CNT0_STRUC TxStaCnt0; - TX_STA_CNT1_STRUC StaTx1; - TX_STA_CNT2_STRUC StaTx2; - TX_AGG_CNT_STRUC TxAggCnt; - TX_AGG_CNT0_STRUC TxAggCnt0; - TX_AGG_CNT1_STRUC TxAggCnt1; - TX_AGG_CNT2_STRUC TxAggCnt2; - TX_AGG_CNT3_STRUC TxAggCnt3; - TX_AGG_CNT4_STRUC TxAggCnt4; - TX_AGG_CNT5_STRUC TxAggCnt5; - TX_AGG_CNT6_STRUC TxAggCnt6; - TX_AGG_CNT7_STRUC TxAggCnt7; - struct rt_counter_ralink *pRalinkCounters; - - pRalinkCounters = &pAd->RalinkCounters; - - RTMP_IO_READ32(pAd, RX_STA_CNT0, &RxStaCnt0.word); - RTMP_IO_READ32(pAd, RX_STA_CNT2, &RxStaCnt2.word); - - { - RTMP_IO_READ32(pAd, RX_STA_CNT1, &RxStaCnt1.word); - /* Update RX PLCP error counter */ - pAd->PrivateInfo.PhyRxErrCnt += RxStaCnt1.field.PlcpErr; - /* Update False CCA counter */ - pAd->RalinkCounters.OneSecFalseCCACnt += - RxStaCnt1.field.FalseCca; - } - - /* Update FCS counters */ - OldValue = pAd->WlanCounters.FCSErrorCount.u.LowPart; - pAd->WlanCounters.FCSErrorCount.u.LowPart += (RxStaCnt0.field.CrcErr); /* >> 7); */ - if (pAd->WlanCounters.FCSErrorCount.u.LowPart < OldValue) - pAd->WlanCounters.FCSErrorCount.u.HighPart++; - - /* Add FCS error count to private counters */ - pRalinkCounters->OneSecRxFcsErrCnt += RxStaCnt0.field.CrcErr; - OldValue = pRalinkCounters->RealFcsErrCount.u.LowPart; - pRalinkCounters->RealFcsErrCount.u.LowPart += RxStaCnt0.field.CrcErr; - if (pRalinkCounters->RealFcsErrCount.u.LowPart < OldValue) - pRalinkCounters->RealFcsErrCount.u.HighPart++; - - /* Update Duplicate Rcv check */ - pRalinkCounters->DuplicateRcv += RxStaCnt2.field.RxDupliCount; - pAd->WlanCounters.FrameDuplicateCount.u.LowPart += - RxStaCnt2.field.RxDupliCount; - /* Update RX Overflow counter */ - pAd->Counters8023.RxNoBuffer += (RxStaCnt2.field.RxFifoOverflowCount); - - /*pAd->RalinkCounters.RxCount = 0; */ -#ifdef RTMP_MAC_USB - if (pRalinkCounters->RxCount != pAd->watchDogRxCnt) { - pAd->watchDogRxCnt = pRalinkCounters->RxCount; - pAd->watchDogRxOverFlowCnt = 0; - } else { - if (RxStaCnt2.field.RxFifoOverflowCount) - pAd->watchDogRxOverFlowCnt++; - else - pAd->watchDogRxOverFlowCnt = 0; - } -#endif /* RTMP_MAC_USB // */ - - /*if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) || */ - /* (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_TX_RATE_SWITCH_ENABLED) && (pAd->MacTab.Size != 1))) */ - if (!pAd->bUpdateBcnCntDone) { - /* Update BEACON sent count */ - RTMP_IO_READ32(pAd, TX_STA_CNT0, &TxStaCnt0.word); - RTMP_IO_READ32(pAd, TX_STA_CNT1, &StaTx1.word); - RTMP_IO_READ32(pAd, TX_STA_CNT2, &StaTx2.word); - pRalinkCounters->OneSecBeaconSentCnt += - TxStaCnt0.field.TxBeaconCount; - pRalinkCounters->OneSecTxRetryOkCount += - StaTx1.field.TxRetransmit; - pRalinkCounters->OneSecTxNoRetryOkCount += - StaTx1.field.TxSuccess; - pRalinkCounters->OneSecTxFailCount += - TxStaCnt0.field.TxFailCount; - pAd->WlanCounters.TransmittedFragmentCount.u.LowPart += - StaTx1.field.TxSuccess; - pAd->WlanCounters.RetryCount.u.LowPart += - StaTx1.field.TxRetransmit; - pAd->WlanCounters.FailedCount.u.LowPart += - TxStaCnt0.field.TxFailCount; - } - - /*if (pAd->bStaFifoTest == TRUE) */ - { - RTMP_IO_READ32(pAd, TX_AGG_CNT, &TxAggCnt.word); - RTMP_IO_READ32(pAd, TX_AGG_CNT0, &TxAggCnt0.word); - RTMP_IO_READ32(pAd, TX_AGG_CNT1, &TxAggCnt1.word); - RTMP_IO_READ32(pAd, TX_AGG_CNT2, &TxAggCnt2.word); - RTMP_IO_READ32(pAd, TX_AGG_CNT3, &TxAggCnt3.word); - RTMP_IO_READ32(pAd, TX_AGG_CNT4, &TxAggCnt4.word); - RTMP_IO_READ32(pAd, TX_AGG_CNT5, &TxAggCnt5.word); - RTMP_IO_READ32(pAd, TX_AGG_CNT6, &TxAggCnt6.word); - RTMP_IO_READ32(pAd, TX_AGG_CNT7, &TxAggCnt7.word); - pRalinkCounters->TxAggCount += TxAggCnt.field.AggTxCount; - pRalinkCounters->TxNonAggCount += TxAggCnt.field.NonAggTxCount; - pRalinkCounters->TxAgg1MPDUCount += - TxAggCnt0.field.AggSize1Count; - pRalinkCounters->TxAgg2MPDUCount += - TxAggCnt0.field.AggSize2Count; - - pRalinkCounters->TxAgg3MPDUCount += - TxAggCnt1.field.AggSize3Count; - pRalinkCounters->TxAgg4MPDUCount += - TxAggCnt1.field.AggSize4Count; - pRalinkCounters->TxAgg5MPDUCount += - TxAggCnt2.field.AggSize5Count; - pRalinkCounters->TxAgg6MPDUCount += - TxAggCnt2.field.AggSize6Count; - - pRalinkCounters->TxAgg7MPDUCount += - TxAggCnt3.field.AggSize7Count; - pRalinkCounters->TxAgg8MPDUCount += - TxAggCnt3.field.AggSize8Count; - pRalinkCounters->TxAgg9MPDUCount += - TxAggCnt4.field.AggSize9Count; - pRalinkCounters->TxAgg10MPDUCount += - TxAggCnt4.field.AggSize10Count; - - pRalinkCounters->TxAgg11MPDUCount += - TxAggCnt5.field.AggSize11Count; - pRalinkCounters->TxAgg12MPDUCount += - TxAggCnt5.field.AggSize12Count; - pRalinkCounters->TxAgg13MPDUCount += - TxAggCnt6.field.AggSize13Count; - pRalinkCounters->TxAgg14MPDUCount += - TxAggCnt6.field.AggSize14Count; - - pRalinkCounters->TxAgg15MPDUCount += - TxAggCnt7.field.AggSize15Count; - pRalinkCounters->TxAgg16MPDUCount += - TxAggCnt7.field.AggSize16Count; - - /* Calculate the transmitted A-MPDU count */ - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - TxAggCnt0.field.AggSize1Count; - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt0.field.AggSize2Count / 2); - - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt1.field.AggSize3Count / 3); - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt1.field.AggSize4Count / 4); - - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt2.field.AggSize5Count / 5); - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt2.field.AggSize6Count / 6); - - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt3.field.AggSize7Count / 7); - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt3.field.AggSize8Count / 8); - - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt4.field.AggSize9Count / 9); - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt4.field.AggSize10Count / 10); - - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt5.field.AggSize11Count / 11); - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt5.field.AggSize12Count / 12); - - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt6.field.AggSize13Count / 13); - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt6.field.AggSize14Count / 14); - - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt7.field.AggSize15Count / 15); - pRalinkCounters->TransmittedAMPDUCount.u.LowPart += - (TxAggCnt7.field.AggSize16Count / 16); - } - -} - -/* - ======================================================================== - - Routine Description: - Reset NIC from error - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - Note: - Reset NIC from error state - - ======================================================================== -*/ -void NICResetFromError(struct rt_rtmp_adapter *pAd) -{ - /* Reset BBP (according to alex, reset ASIC will force reset BBP */ - /* Therefore, skip the reset BBP */ - /* RTMP_IO_WRITE32(pAd, MAC_CSR1, 0x2); */ - - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x1); - /* Remove ASIC from reset state */ - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0x0); - - NICInitializeAdapter(pAd, FALSE); - NICInitAsicFromEEPROM(pAd); - - /* Switch to current channel, since during reset process, the connection should remains on. */ - AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); -} - -int NICLoadFirmware(struct rt_rtmp_adapter *pAd) -{ - int status = NDIS_STATUS_SUCCESS; - if (pAd->chipOps.loadFirmware) - status = pAd->chipOps.loadFirmware(pAd); - - return status; -} - -/* - ======================================================================== - - Routine Description: - erase 8051 firmware image in MAC ASIC - - Arguments: - Adapter Pointer to our adapter - - IRQL = PASSIVE_LEVEL - - ======================================================================== -*/ -void NICEraseFirmware(struct rt_rtmp_adapter *pAd) -{ - if (pAd->chipOps.eraseFirmware) - pAd->chipOps.eraseFirmware(pAd); - -} /* End of NICEraseFirmware */ - -/* - ======================================================================== - - Routine Description: - Load Tx rate switching parameters - - Arguments: - Adapter Pointer to our adapter - - Return Value: - NDIS_STATUS_SUCCESS firmware image load ok - NDIS_STATUS_FAILURE image not found - - IRQL = PASSIVE_LEVEL - - Rate Table Format: - 1. (B0: Valid Item number) (B1:Initial item from zero) - 2. Item Number(Dec) Mode(Hex) Current MCS(Dec) TrainUp(Dec) TrainDown(Dec) - - ======================================================================== -*/ -int NICLoadRateSwitchingParams(struct rt_rtmp_adapter *pAd) -{ - return NDIS_STATUS_SUCCESS; -} - -/* - ======================================================================== - - Routine Description: - Compare two memory block - - Arguments: - pSrc1 Pointer to first memory address - pSrc2 Pointer to second memory address - - Return Value: - 0: memory is equal - 1: pSrc1 memory is larger - 2: pSrc2 memory is larger - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -unsigned long RTMPCompareMemory(void *pSrc1, void *pSrc2, unsigned long Length) -{ - u8 *pMem1; - u8 *pMem2; - unsigned long Index = 0; - - pMem1 = (u8 *)pSrc1; - pMem2 = (u8 *)pSrc2; - - for (Index = 0; Index < Length; Index++) { - if (pMem1[Index] > pMem2[Index]) - return (1); - else if (pMem1[Index] < pMem2[Index]) - return (2); - } - - /* Equal */ - return (0); -} - -/* - ======================================================================== - - Routine Description: - Zero out memory block - - Arguments: - pSrc1 Pointer to memory address - Length Size - - Return Value: - None - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPZeroMemory(void *pSrc, unsigned long Length) -{ - u8 *pMem; - unsigned long Index = 0; - - pMem = (u8 *)pSrc; - - for (Index = 0; Index < Length; Index++) { - pMem[Index] = 0x00; - } -} - -/* - ======================================================================== - - Routine Description: - Copy data from memory block 1 to memory block 2 - - Arguments: - pDest Pointer to destination memory address - pSrc Pointer to source memory address - Length Copy size - - Return Value: - None - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPMoveMemory(void *pDest, void *pSrc, unsigned long Length) -{ - u8 *pMem1; - u8 *pMem2; - u32 Index; - - ASSERT((Length == 0) || (pDest && pSrc)); - - pMem1 = (u8 *)pDest; - pMem2 = (u8 *)pSrc; - - for (Index = 0; Index < Length; Index++) { - pMem1[Index] = pMem2[Index]; - } -} - -/* - ======================================================================== - - Routine Description: - Initialize port configuration structure - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - Note: - - ======================================================================== -*/ -void UserCfgInit(struct rt_rtmp_adapter *pAd) -{ - u32 key_index, bss_index; - - DBGPRINT(RT_DEBUG_TRACE, ("--> UserCfgInit\n")); - - /* */ - /* part I. initialize common configuration */ - /* */ -#ifdef RTMP_MAC_USB - pAd->BulkOutReq = 0; - - pAd->BulkOutComplete = 0; - pAd->BulkOutCompleteOther = 0; - pAd->BulkOutCompleteCancel = 0; - pAd->BulkInReq = 0; - pAd->BulkInComplete = 0; - pAd->BulkInCompleteFail = 0; - - /*pAd->QuickTimerP = 100; */ - /*pAd->TurnAggrBulkInCount = 0; */ - pAd->bUsbTxBulkAggre = 0; - - /* init as unused value to ensure driver will set to MCU once. */ - pAd->LedIndicatorStrength = 0xFF; - - pAd->CommonCfg.MaxPktOneTxBulk = 2; - pAd->CommonCfg.TxBulkFactor = 1; - pAd->CommonCfg.RxBulkFactor = 1; - - pAd->CommonCfg.TxPower = 100; /*mW */ - - NdisZeroMemory(&pAd->CommonCfg.IOTestParm, - sizeof(pAd->CommonCfg.IOTestParm)); -#endif /* RTMP_MAC_USB // */ - - for (key_index = 0; key_index < SHARE_KEY_NUM; key_index++) { - for (bss_index = 0; bss_index < MAX_MBSSID_NUM; bss_index++) { - pAd->SharedKey[bss_index][key_index].KeyLen = 0; - pAd->SharedKey[bss_index][key_index].CipherAlg = - CIPHER_NONE; - } - } - - pAd->EepromAccess = FALSE; - - pAd->Antenna.word = 0; - pAd->CommonCfg.BBPCurrentBW = BW_20; - - pAd->LedCntl.word = 0; -#ifdef RTMP_MAC_PCI - pAd->LedIndicatorStrength = 0; - pAd->RLnkCtrlOffset = 0; - pAd->HostLnkCtrlOffset = 0; - pAd->StaCfg.PSControl.field.EnableNewPS = TRUE; - pAd->CheckDmaBusyCount = 0; -#endif /* RTMP_MAC_PCI // */ - - pAd->bAutoTxAgcA = FALSE; /* Default is OFF */ - pAd->bAutoTxAgcG = FALSE; /* Default is OFF */ - pAd->RfIcType = RFIC_2820; - - /* Init timer for reset complete event */ - pAd->CommonCfg.CentralChannel = 1; - pAd->bForcePrintTX = FALSE; - pAd->bForcePrintRX = FALSE; - pAd->bStaFifoTest = FALSE; - pAd->bProtectionTest = FALSE; - pAd->CommonCfg.Dsifs = 10; /* in units of usec */ - pAd->CommonCfg.TxPower = 100; /*mW */ - pAd->CommonCfg.TxPowerPercentage = 0xffffffff; /* AUTO */ - pAd->CommonCfg.TxPowerDefault = 0xffffffff; /* AUTO */ - pAd->CommonCfg.TxPreamble = Rt802_11PreambleAuto; /* use Long preamble on TX by defaut */ - pAd->CommonCfg.bUseZeroToDisableFragment = FALSE; - pAd->CommonCfg.RtsThreshold = 2347; - pAd->CommonCfg.FragmentThreshold = 2346; - pAd->CommonCfg.UseBGProtection = 0; /* 0: AUTO */ - pAd->CommonCfg.bEnableTxBurst = TRUE; /*0; */ - pAd->CommonCfg.PhyMode = 0xff; /* unknown */ - pAd->CommonCfg.BandState = UNKNOWN_BAND; - pAd->CommonCfg.RadarDetect.CSPeriod = 10; - pAd->CommonCfg.RadarDetect.CSCount = 0; - pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE; - - pAd->CommonCfg.RadarDetect.ChMovingTime = 65; - pAd->CommonCfg.RadarDetect.LongPulseRadarTh = 3; - pAd->CommonCfg.bAPSDCapable = FALSE; - pAd->CommonCfg.bNeedSendTriggerFrame = FALSE; - pAd->CommonCfg.TriggerTimerCount = 0; - pAd->CommonCfg.bAPSDForcePowerSave = FALSE; - pAd->CommonCfg.bCountryFlag = FALSE; - pAd->CommonCfg.TxStream = 0; - pAd->CommonCfg.RxStream = 0; - - NdisZeroMemory(&pAd->BeaconTxWI, sizeof(pAd->BeaconTxWI)); - - NdisZeroMemory(&pAd->CommonCfg.HtCapability, - sizeof(pAd->CommonCfg.HtCapability)); - pAd->HTCEnable = FALSE; - pAd->bBroadComHT = FALSE; - pAd->CommonCfg.bRdg = FALSE; - - NdisZeroMemory(&pAd->CommonCfg.AddHTInfo, - sizeof(pAd->CommonCfg.AddHTInfo)); - pAd->CommonCfg.BACapability.field.MMPSmode = MMPS_ENABLE; - pAd->CommonCfg.BACapability.field.MpduDensity = 0; - pAd->CommonCfg.BACapability.field.Policy = IMMED_BA; - pAd->CommonCfg.BACapability.field.RxBAWinLimit = 64; /*32; */ - pAd->CommonCfg.BACapability.field.TxBAWinLimit = 64; /*32; */ - DBGPRINT(RT_DEBUG_TRACE, - ("--> UserCfgInit. BACapability = 0x%x\n", - pAd->CommonCfg.BACapability.word)); - - pAd->CommonCfg.BACapability.field.AutoBA = FALSE; - BATableInit(pAd, &pAd->BATable); - - pAd->CommonCfg.bExtChannelSwitchAnnouncement = 1; - pAd->CommonCfg.bHTProtect = 1; - pAd->CommonCfg.bMIMOPSEnable = TRUE; - /*2008/11/05:KH add to support Antenna power-saving of AP<-- */ - pAd->CommonCfg.bGreenAPEnable = FALSE; - /*2008/11/05:KH add to support Antenna power-saving of AP--> */ - pAd->CommonCfg.bBADecline = FALSE; - pAd->CommonCfg.bDisableReordering = FALSE; - - if (pAd->MACVersion == 0x28720200) { - pAd->CommonCfg.TxBASize = 13; /*by Jerry recommend */ - } else { - pAd->CommonCfg.TxBASize = 7; - } - - pAd->CommonCfg.REGBACapability.word = pAd->CommonCfg.BACapability.word; - - /*pAd->CommonCfg.HTPhyMode.field.BW = BW_20; */ - /*pAd->CommonCfg.HTPhyMode.field.MCS = MCS_AUTO; */ - /*pAd->CommonCfg.HTPhyMode.field.ShortGI = GI_800; */ - /*pAd->CommonCfg.HTPhyMode.field.STBC = STBC_NONE; */ - pAd->CommonCfg.TxRate = RATE_6; - - pAd->CommonCfg.MlmeTransmit.field.MCS = MCS_RATE_6; - pAd->CommonCfg.MlmeTransmit.field.BW = BW_20; - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; - - pAd->CommonCfg.BeaconPeriod = 100; /* in mSec */ - - /* */ - /* part II. initialize STA specific configuration */ - /* */ - { - RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_DIRECT); - RX_FILTER_CLEAR_FLAG(pAd, fRX_FILTER_ACCEPT_MULTICAST); - RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_BROADCAST); - RX_FILTER_SET_FLAG(pAd, fRX_FILTER_ACCEPT_ALL_MULTICAST); - - pAd->StaCfg.Psm = PWR_ACTIVE; - - pAd->StaCfg.OrigWepStatus = Ndis802_11EncryptionDisabled; - pAd->StaCfg.PairCipher = Ndis802_11EncryptionDisabled; - pAd->StaCfg.GroupCipher = Ndis802_11EncryptionDisabled; - pAd->StaCfg.bMixCipher = FALSE; - pAd->StaCfg.DefaultKeyId = 0; - - /* 802.1x port control */ - pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP; - pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED; - pAd->StaCfg.LastMicErrorTime = 0; - pAd->StaCfg.MicErrCnt = 0; - pAd->StaCfg.bBlockAssoc = FALSE; - pAd->StaCfg.WpaState = SS_NOTUSE; - - pAd->CommonCfg.NdisRadioStateOff = FALSE; /* New to support microsoft disable radio with OID command */ - - pAd->StaCfg.RssiTrigger = 0; - NdisZeroMemory(&pAd->StaCfg.RssiSample, sizeof(struct rt_rssi_sample)); - pAd->StaCfg.RssiTriggerMode = - RSSI_TRIGGERED_UPON_BELOW_THRESHOLD; - pAd->StaCfg.AtimWin = 0; - pAd->StaCfg.DefaultListenCount = 3; /*default listen count; */ - pAd->StaCfg.BssType = BSS_INFRA; /* BSS_INFRA or BSS_ADHOC or BSS_MONITOR */ - pAd->StaCfg.bScanReqIsFromWebUI = FALSE; - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_WAKEUP_NOW); - - pAd->StaCfg.bAutoTxRateSwitch = TRUE; - pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO; - } - -#ifdef PCIE_PS_SUPPORT - pAd->brt30xxBanMcuCmd = FALSE; - pAd->b3090ESpecialChip = FALSE; -/*KH Debug:the following must be removed */ - pAd->StaCfg.PSControl.field.rt30xxPowerMode = 3; - pAd->StaCfg.PSControl.field.rt30xxForceASPMTest = 0; - pAd->StaCfg.PSControl.field.rt30xxFollowHostASPM = 1; -#endif /* PCIE_PS_SUPPORT // */ - - /* global variables mXXXX used in MAC protocol state machines */ - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_RECEIVE_DTIM); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON); - - /* PHY specification */ - pAd->CommonCfg.PhyMode = PHY_11BG_MIXED; /* default PHY mode */ - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED); /* CCK use long preamble */ - - { - /* user desired power mode */ - pAd->StaCfg.WindowsPowerMode = Ndis802_11PowerModeCAM; - pAd->StaCfg.WindowsBatteryPowerMode = Ndis802_11PowerModeCAM; - pAd->StaCfg.bWindowsACCAMEnable = FALSE; - - RTMPInitTimer(pAd, &pAd->StaCfg.StaQuickResponeForRateUpTimer, - GET_TIMER_FUNCTION(StaQuickResponeForRateUpExec), - pAd, FALSE); - pAd->StaCfg.StaQuickResponeForRateUpTimerRunning = FALSE; - - /* Patch for Ndtest */ - pAd->StaCfg.ScanCnt = 0; - - pAd->StaCfg.bHwRadio = TRUE; /* Default Hardware Radio status is On */ - pAd->StaCfg.bSwRadio = TRUE; /* Default Software Radio status is On */ - pAd->StaCfg.bRadio = TRUE; /* bHwRadio && bSwRadio */ - pAd->StaCfg.bHardwareRadio = FALSE; /* Default is OFF */ - pAd->StaCfg.bShowHiddenSSID = FALSE; /* Default no show */ - - /* Nitro mode control */ - pAd->StaCfg.bAutoReconnect = TRUE; - - /* Save the init time as last scan time, the system should do scan after 2 seconds. */ - /* This patch is for driver wake up from standby mode, system will do scan right away. */ - NdisGetSystemUpTime(&pAd->StaCfg.LastScanTime); - if (pAd->StaCfg.LastScanTime > 10 * OS_HZ) - pAd->StaCfg.LastScanTime -= (10 * OS_HZ); - - NdisZeroMemory(pAd->nickname, IW_ESSID_MAX_SIZE + 1); -#ifdef RTMP_MAC_PCI - sprintf((char *)pAd->nickname, "RT2860STA"); -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - sprintf((char *)pAd->nickname, "RT2870STA"); -#endif /* RTMP_MAC_USB // */ - RTMPInitTimer(pAd, &pAd->StaCfg.WpaDisassocAndBlockAssocTimer, - GET_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc), - pAd, FALSE); - pAd->StaCfg.IEEE8021X = FALSE; - pAd->StaCfg.IEEE8021x_required_keys = FALSE; - pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_DISABLE; - pAd->StaCfg.bRSN_IE_FromWpaSupplicant = FALSE; - pAd->StaCfg.WpaSupplicantUP = WPA_SUPPLICANT_ENABLE; - - NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8); - - pAd->StaCfg.bAutoConnectByBssid = FALSE; - pAd->StaCfg.BeaconLostTime = BEACON_LOST_TIME; - NdisZeroMemory(pAd->StaCfg.WpaPassPhrase, 64); - pAd->StaCfg.WpaPassPhraseLen = 0; - pAd->StaCfg.bAutoRoaming = FALSE; - pAd->StaCfg.bForceTxBurst = FALSE; - } - - /* Default for extra information is not valid */ - pAd->ExtraInfo = EXTRA_INFO_CLEAR; - - /* Default Config change flag */ - pAd->bConfigChanged = FALSE; - - /* */ - /* part III. AP configurations */ - /* */ - - /* */ - /* part IV. others */ - /* */ - /* dynamic BBP R66:sensibity tuning to overcome background noise */ - pAd->BbpTuning.bEnable = TRUE; - pAd->BbpTuning.FalseCcaLowerThreshold = 100; - pAd->BbpTuning.FalseCcaUpperThreshold = 512; - pAd->BbpTuning.R66Delta = 4; - pAd->Mlme.bEnableAutoAntennaCheck = TRUE; - - /* */ - /* Also initial R66CurrentValue, RTUSBResumeMsduTransmission might use this value. */ - /* if not initial this value, the default value will be 0. */ - /* */ - pAd->BbpTuning.R66CurrentValue = 0x38; - - pAd->Bbp94 = BBPR94_DEFAULT; - pAd->BbpForCCK = FALSE; - - /* Default is FALSE for test bit 1 */ - /*pAd->bTest1 = FALSE; */ - - /* initialize MAC table and allocate spin lock */ - NdisZeroMemory(&pAd->MacTab, sizeof(struct rt_mac_table)); - InitializeQueueHeader(&pAd->MacTab.McastPsQueue); - NdisAllocateSpinLock(&pAd->MacTabLock); - - /*RTMPInitTimer(pAd, &pAd->RECBATimer, RECBATimerTimeout, pAd, TRUE); */ - /*RTMPSetTimer(&pAd->RECBATimer, REORDER_EXEC_INTV); */ - - pAd->CommonCfg.bWiFiTest = FALSE; -#ifdef RTMP_MAC_PCI - pAd->bPCIclkOff = FALSE; -#endif /* RTMP_MAC_PCI // */ - - RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP); - DBGPRINT(RT_DEBUG_TRACE, ("<-- UserCfgInit\n")); -} - -/* IRQL = PASSIVE_LEVEL */ -/* */ -/* FUNCTION: AtoH(char *, u8 *, int) */ -/* */ -/* PURPOSE: Converts ascii string to network order hex */ -/* */ -/* PARAMETERS: */ -/* src - pointer to input ascii string */ -/* dest - pointer to output hex */ -/* destlen - size of dest */ -/* */ -/* COMMENTS: */ -/* */ -/* 2 ascii bytes make a hex byte so must put 1st ascii byte of pair */ -/* into upper nibble and 2nd ascii byte of pair into lower nibble. */ -/* */ -/* IRQL = PASSIVE_LEVEL */ - -void AtoH(char *src, u8 *dest, int destlen) -{ - char *srcptr; - u8 *destTemp; - - srcptr = src; - destTemp = (u8 *)dest; - - while (destlen--) { - *destTemp = hex_to_bin(*srcptr++) << 4; /* Put 1st ascii byte in upper nibble. */ - *destTemp += hex_to_bin(*srcptr++); /* Add 2nd ascii byte to above. */ - destTemp++; - } -} - -/*+++Mark by shiang, not use now, need to remove after confirm */ -/*---Mark by shiang, not use now, need to remove after confirm */ - -/* - ======================================================================== - - Routine Description: - Init timer objects - - Arguments: - pAd Pointer to our adapter - pTimer Timer structure - pTimerFunc Function to execute when timer expired - Repeat Ture for period timer - - Return Value: - None - - Note: - - ======================================================================== -*/ -void RTMPInitTimer(struct rt_rtmp_adapter *pAd, - struct rt_ralink_timer *pTimer, - void *pTimerFunc, void *pData, IN BOOLEAN Repeat) -{ - /* */ - /* Set Valid to TRUE for later used. */ - /* It will crash if we cancel a timer or set a timer */ - /* that we haven't initialize before. */ - /* */ - pTimer->Valid = TRUE; - - pTimer->PeriodicType = Repeat; - pTimer->State = FALSE; - pTimer->cookie = (unsigned long)pData; - -#ifdef RTMP_TIMER_TASK_SUPPORT - pTimer->pAd = pAd; -#endif /* RTMP_TIMER_TASK_SUPPORT // */ - - RTMP_OS_Init_Timer(pAd, &pTimer->TimerObj, pTimerFunc, (void *)pTimer); -} - -/* - ======================================================================== - - Routine Description: - Init timer objects - - Arguments: - pTimer Timer structure - Value Timer value in milliseconds - - Return Value: - None - - Note: - To use this routine, must call RTMPInitTimer before. - - ======================================================================== -*/ -void RTMPSetTimer(struct rt_ralink_timer *pTimer, unsigned long Value) -{ - if (pTimer->Valid) { - pTimer->TimerValue = Value; - pTimer->State = FALSE; - if (pTimer->PeriodicType == TRUE) { - pTimer->Repeat = TRUE; - RTMP_SetPeriodicTimer(&pTimer->TimerObj, Value); - } else { - pTimer->Repeat = FALSE; - RTMP_OS_Add_Timer(&pTimer->TimerObj, Value); - } - } else { - DBGPRINT_ERR("RTMPSetTimer failed, Timer hasn't been initialize!\n"); - } -} - -/* - ======================================================================== - - Routine Description: - Init timer objects - - Arguments: - pTimer Timer structure - Value Timer value in milliseconds - - Return Value: - None - - Note: - To use this routine, must call RTMPInitTimer before. - - ======================================================================== -*/ -void RTMPModTimer(struct rt_ralink_timer *pTimer, unsigned long Value) -{ - BOOLEAN Cancel; - - if (pTimer->Valid) { - pTimer->TimerValue = Value; - pTimer->State = FALSE; - if (pTimer->PeriodicType == TRUE) { - RTMPCancelTimer(pTimer, &Cancel); - RTMPSetTimer(pTimer, Value); - } else { - RTMP_OS_Mod_Timer(&pTimer->TimerObj, Value); - } - } else { - DBGPRINT_ERR("RTMPModTimer failed, Timer hasn't been initialize!\n"); - } -} - -/* - ======================================================================== - - Routine Description: - Cancel timer objects - - Arguments: - Adapter Pointer to our adapter - - Return Value: - None - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - Note: - 1.) To use this routine, must call RTMPInitTimer before. - 2.) Reset NIC to initial state AS IS system boot up time. - - ======================================================================== -*/ -void RTMPCancelTimer(struct rt_ralink_timer *pTimer, OUT BOOLEAN * pCancelled) -{ - if (pTimer->Valid) { - if (pTimer->State == FALSE) - pTimer->Repeat = FALSE; - - RTMP_OS_Del_Timer(&pTimer->TimerObj, pCancelled); - - if (*pCancelled == TRUE) - pTimer->State = TRUE; - -#ifdef RTMP_TIMER_TASK_SUPPORT - /* We need to go-through the TimerQ to findout this timer handler and remove it if */ - /* it's still waiting for execution. */ - RtmpTimerQRemove(pTimer->pAd, pTimer); -#endif /* RTMP_TIMER_TASK_SUPPORT // */ - } else { - DBGPRINT_ERR("RTMPCancelTimer failed, Timer hasn't been initialize!\n"); - } -} - -/* - ======================================================================== - - Routine Description: - Set LED Status - - Arguments: - pAd Pointer to our adapter - Status LED Status - - Return Value: - None - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPSetLED(struct rt_rtmp_adapter *pAd, u8 Status) -{ - /*unsigned long data; */ - u8 HighByte = 0; - u8 LowByte; - - LowByte = pAd->LedCntl.field.LedMode & 0x7f; - switch (Status) { - case LED_LINK_DOWN: - HighByte = 0x20; - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); - pAd->LedIndicatorStrength = 0; - break; - case LED_LINK_UP: - if (pAd->CommonCfg.Channel > 14) - HighByte = 0xa0; - else - HighByte = 0x60; - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); - break; - case LED_RADIO_ON: - HighByte = 0x20; - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); - break; - case LED_HALT: - LowByte = 0; /* Driver sets MAC register and MAC controls LED */ - case LED_RADIO_OFF: - HighByte = 0; - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); - break; - case LED_WPS: - HighByte = 0x10; - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); - break; - case LED_ON_SITE_SURVEY: - HighByte = 0x08; - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); - break; - case LED_POWER_UP: - HighByte = 0x04; - AsicSendCommandToMcu(pAd, 0x50, 0xff, LowByte, HighByte); - break; - default: - DBGPRINT(RT_DEBUG_WARN, - ("RTMPSetLED::Unknown Status %d\n", Status)); - break; - } - - /* */ - /* Keep LED status for LED SiteSurvey mode. */ - /* After SiteSurvey, we will set the LED mode to previous status. */ - /* */ - if ((Status != LED_ON_SITE_SURVEY) && (Status != LED_POWER_UP)) - pAd->LedStatus = Status; - - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPSetLED::Mode=%d,HighByte=0x%02x,LowByte=0x%02x\n", - pAd->LedCntl.field.LedMode, HighByte, LowByte)); -} - -/* - ======================================================================== - - Routine Description: - Set LED Signal Strength - - Arguments: - pAd Pointer to our adapter - Dbm Signal Strength - - Return Value: - None - - IRQL = PASSIVE_LEVEL - - Note: - Can be run on any IRQL level. - - According to Microsoft Zero Config Wireless Signal Strength definition as belows. - <= -90 No Signal - <= -81 Very Low - <= -71 Low - <= -67 Good - <= -57 Very Good - > -57 Excellent - ======================================================================== -*/ -void RTMPSetSignalLED(struct rt_rtmp_adapter *pAd, IN NDIS_802_11_RSSI Dbm) -{ - u8 nLed = 0; - - if (pAd->LedCntl.field.LedMode == LED_MODE_SIGNAL_STREGTH) { - if (Dbm <= -90) - nLed = 0; - else if (Dbm <= -81) - nLed = 1; - else if (Dbm <= -71) - nLed = 3; - else if (Dbm <= -67) - nLed = 7; - else if (Dbm <= -57) - nLed = 15; - else - nLed = 31; - - /* */ - /* Update Signal Strength to firmware if changed. */ - /* */ - if (pAd->LedIndicatorStrength != nLed) { - AsicSendCommandToMcu(pAd, 0x51, 0xff, nLed, - pAd->LedCntl.field.Polarity); - pAd->LedIndicatorStrength = nLed; - } - } -} - -/* - ======================================================================== - - Routine Description: - Enable RX - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - IRQL <= DISPATCH_LEVEL - - Note: - Before Enable RX, make sure you have enabled Interrupt. - ======================================================================== -*/ -void RTMPEnableRxTx(struct rt_rtmp_adapter *pAd) -{ -/* WPDMA_GLO_CFG_STRUC GloCfg; */ -/* unsigned long i = 0; */ - u32 rx_filter_flag; - - DBGPRINT(RT_DEBUG_TRACE, ("==> RTMPEnableRxTx\n")); - - /* Enable Rx DMA. */ - RT28XXDMAEnable(pAd); - - /* enable RX of MAC block */ - if (pAd->OpMode == OPMODE_AP) { - rx_filter_flag = APNORMAL; - - RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, rx_filter_flag); /* enable RX of DMA block */ - } else { - if (pAd->CommonCfg.PSPXlink) - rx_filter_flag = PSPXLINK; - else - rx_filter_flag = STANORMAL; /* Station not drop control frame will fail WiFi Certification. */ - RTMP_IO_WRITE32(pAd, RX_FILTR_CFG, rx_filter_flag); - } - - RTMP_IO_WRITE32(pAd, MAC_SYS_CTRL, 0xc); - DBGPRINT(RT_DEBUG_TRACE, ("<== RTMPEnableRxTx\n")); -} - -/*+++Add by shiang, move from os/linux/rt_main_dev.c */ -void CfgInitHook(struct rt_rtmp_adapter *pAd) -{ - pAd->bBroadComHT = TRUE; -} - -int rt28xx_init(struct rt_rtmp_adapter *pAd, - char *pDefaultMac, char *pHostName) -{ - u32 index; - u8 TmpPhy; - int Status; - u32 MacCsr0 = 0; - -#ifdef RTMP_MAC_PCI - { - /* If dirver doesn't wake up firmware here, */ - /* NICLoadFirmware will hang forever when interface is up again. */ - /* RT2860 PCI */ - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) && - OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) { - AUTO_WAKEUP_STRUC AutoWakeupCfg; - AsicForceWakeup(pAd, TRUE); - AutoWakeupCfg.word = 0; - RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, - AutoWakeupCfg.word); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE); - } - } -#endif /* RTMP_MAC_PCI // */ - - /* reset Adapter flags */ - RTMP_CLEAR_FLAGS(pAd); - - /* Init BssTab & ChannelInfo tabbles for auto channel select. */ - - /* Allocate BA Reordering memory */ - ba_reordering_resource_init(pAd, MAX_REORDERING_MPDU_NUM); - - /* Make sure MAC gets ready. */ - index = 0; - do { - RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0); - pAd->MACVersion = MacCsr0; - - if ((pAd->MACVersion != 0x00) - && (pAd->MACVersion != 0xFFFFFFFF)) - break; - - RTMPusecDelay(10); - } while (index++ < 100); - DBGPRINT(RT_DEBUG_TRACE, - ("MAC_CSR0 [ Ver:Rev=0x%08x]\n", pAd->MACVersion)); - -#ifdef RTMP_MAC_PCI -#ifdef PCIE_PS_SUPPORT - /*Iverson patch PCIE L1 issue to make sure that driver can be read,write ,BBP and RF register at pcie L.1 level */ - if ((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) { - RTMP_IO_READ32(pAd, AUX_CTRL, &MacCsr0); - MacCsr0 |= 0x402; - RTMP_IO_WRITE32(pAd, AUX_CTRL, MacCsr0); - DBGPRINT(RT_DEBUG_TRACE, ("AUX_CTRL = 0x%x\n", MacCsr0)); - } -#endif /* PCIE_PS_SUPPORT // */ - - /* To fix driver disable/enable hang issue when radio off */ - RTMP_IO_WRITE32(pAd, PWR_PIN_CFG, 0x2); -#endif /* RTMP_MAC_PCI // */ - - /* Disable DMA */ - RT28XXDMADisable(pAd); - - /* Load 8051 firmware */ - Status = NICLoadFirmware(pAd); - if (Status != NDIS_STATUS_SUCCESS) { - DBGPRINT_ERR("NICLoadFirmware failed, Status[=0x%08x]\n", Status); - goto err1; - } - - NICLoadRateSwitchingParams(pAd); - - /* Disable interrupts here which is as soon as possible */ - /* This statement should never be true. We might consider to remove it later */ -#ifdef RTMP_MAC_PCI - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE)) { - RTMP_ASIC_INTERRUPT_DISABLE(pAd); - } -#endif /* RTMP_MAC_PCI // */ - - Status = RTMPAllocTxRxRingMemory(pAd); - if (Status != NDIS_STATUS_SUCCESS) { - DBGPRINT_ERR("RTMPAllocDMAMemory failed, Status[=0x%08x]\n", Status); - goto err1; - } - - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE); - - /* initialize MLME */ - /* */ - - Status = RtmpMgmtTaskInit(pAd); - if (Status != NDIS_STATUS_SUCCESS) - goto err2; - - Status = MlmeInit(pAd); - if (Status != NDIS_STATUS_SUCCESS) { - DBGPRINT_ERR("MlmeInit failed, Status[=0x%08x]\n", Status); - goto err2; - } - /* Initialize pAd->StaCfg, pAd->ApCfg, pAd->CommonCfg to manufacture default */ - /* */ - UserCfgInit(pAd); - Status = RtmpNetTaskInit(pAd); - if (Status != NDIS_STATUS_SUCCESS) - goto err3; - -/* COPY_MAC_ADDR(pAd->ApCfg.MBSSID[apidx].Bssid, netif->hwaddr); */ -/* pAd->bForcePrintTX = TRUE; */ - - CfgInitHook(pAd); - - NdisAllocateSpinLock(&pAd->MacTabLock); - - MeasureReqTabInit(pAd); - TpcReqTabInit(pAd); - - /* */ - /* Init the hardware, we need to init asic before read registry, otherwise mac register will be reset */ - /* */ - Status = NICInitializeAdapter(pAd, TRUE); - if (Status != NDIS_STATUS_SUCCESS) { - DBGPRINT_ERR("NICInitializeAdapter failed, Status[=0x%08x]\n", Status); - if (Status != NDIS_STATUS_SUCCESS) - goto err3; - } - - DBGPRINT(RT_DEBUG_OFF, ("1. Phy Mode = %d\n", pAd->CommonCfg.PhyMode)); - -#ifdef RTMP_MAC_USB - pAd->CommonCfg.bMultipleIRP = FALSE; - - if (pAd->CommonCfg.bMultipleIRP) - pAd->CommonCfg.NumOfBulkInIRP = RX_RING_SIZE; - else - pAd->CommonCfg.NumOfBulkInIRP = 1; -#endif /* RTMP_MAC_USB // */ - - /*Init Ba Capability parameters. */ -/* RT28XX_BA_INIT(pAd); */ - pAd->CommonCfg.DesiredHtPhy.MpduDensity = - (u8)pAd->CommonCfg.BACapability.field.MpduDensity; - pAd->CommonCfg.DesiredHtPhy.AmsduEnable = - (u16)pAd->CommonCfg.BACapability.field.AmsduEnable; - pAd->CommonCfg.DesiredHtPhy.AmsduSize = - (u16)pAd->CommonCfg.BACapability.field.AmsduSize; - pAd->CommonCfg.DesiredHtPhy.MimoPs = - (u16)pAd->CommonCfg.BACapability.field.MMPSmode; - /* UPdata to HT IE */ - pAd->CommonCfg.HtCapability.HtCapInfo.MimoPs = - (u16)pAd->CommonCfg.BACapability.field.MMPSmode; - pAd->CommonCfg.HtCapability.HtCapInfo.AMsduSize = - (u16)pAd->CommonCfg.BACapability.field.AmsduSize; - pAd->CommonCfg.HtCapability.HtCapParm.MpduDensity = - (u8)pAd->CommonCfg.BACapability.field.MpduDensity; - - /* after reading Registry, we now know if in AP mode or STA mode */ - - /* Load 8051 firmware; crash when FW image not existent */ - /* Status = NICLoadFirmware(pAd); */ - /* if (Status != NDIS_STATUS_SUCCESS) */ - /* break; */ - - DBGPRINT(RT_DEBUG_OFF, ("2. Phy Mode = %d\n", pAd->CommonCfg.PhyMode)); - - /* We should read EEPROM for all cases. rt2860b */ - NICReadEEPROMParameters(pAd, (u8 *)pDefaultMac); - - DBGPRINT(RT_DEBUG_OFF, ("3. Phy Mode = %d\n", pAd->CommonCfg.PhyMode)); - - NICInitAsicFromEEPROM(pAd); /*rt2860b */ - - /* Set PHY to appropriate mode */ - TmpPhy = pAd->CommonCfg.PhyMode; - pAd->CommonCfg.PhyMode = 0xff; - RTMPSetPhyMode(pAd, TmpPhy); - SetCommonHT(pAd); - - /* No valid channels. */ - if (pAd->ChannelListNum == 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("Wrong configuration. No valid channel found. Check \"ContryCode\" and \"ChannelGeography\" setting.\n")); - goto err4; - } - - DBGPRINT(RT_DEBUG_OFF, - ("MCS Set = %02x %02x %02x %02x %02x\n", - pAd->CommonCfg.HtCapability.MCSSet[0], - pAd->CommonCfg.HtCapability.MCSSet[1], - pAd->CommonCfg.HtCapability.MCSSet[2], - pAd->CommonCfg.HtCapability.MCSSet[3], - pAd->CommonCfg.HtCapability.MCSSet[4])); - -#ifdef RTMP_RF_RW_SUPPORT - /*Init RT30xx RFRegisters after read RFIC type from EEPROM */ - NICInitRFRegisters(pAd); -#endif /* RTMP_RF_RW_SUPPORT // */ - -/* APInitialize(pAd); */ - - /* */ - /* Initialize RF register to default value */ - /* */ - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.Channel); - - /* 8051 firmware require the signal during booting time. */ - /*2008/11/28:KH marked the following codes to patch Frequency offset bug */ - /*AsicSendCommandToMcu(pAd, 0x72, 0xFF, 0x00, 0x00); */ - - if (pAd && (Status != NDIS_STATUS_SUCCESS)) { - /* */ - /* Undo everything if it failed */ - /* */ - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { -/* NdisMDeregisterInterrupt(&pAd->Interrupt); */ - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE); - } -/* RTMPFreeAdapter(pAd); // we will free it in disconnect() */ - } else if (pAd) { - /* Microsoft HCT require driver send a disconnect event after driver initialization. */ - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED); -/* pAd->IndicateMediaState = NdisMediaStateDisconnected; */ - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_MEDIA_STATE_CHANGE); - - DBGPRINT(RT_DEBUG_TRACE, - ("NDIS_STATUS_MEDIA_DISCONNECT Event B!\n")); - -#ifdef RTMP_MAC_USB - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS); - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS); - - /* */ - /* Support multiple BulkIn IRP, */ - /* the value on pAd->CommonCfg.NumOfBulkInIRP may be large than 1. */ - /* */ - for (index = 0; index < pAd->CommonCfg.NumOfBulkInIRP; index++) { - RTUSBBulkReceive(pAd); - DBGPRINT(RT_DEBUG_TRACE, ("RTUSBBulkReceive!\n")); - } -#endif /* RTMP_MAC_USB // */ - } /* end of else */ - - /* Set up the Mac address */ - RtmpOSNetDevAddrSet(pAd->net_dev, &pAd->CurrentAddress[0]); - - DBGPRINT_S(Status, ("<==== rt28xx_init, Status=%x\n", Status)); - - return TRUE; - -err4: -err3: - MlmeHalt(pAd); -err2: - RTMPFreeTxRxRingMemory(pAd); -err1: - - os_free_mem(pAd, pAd->mpdu_blk_pool.mem); /* free BA pool */ - - /* shall not set priv to NULL here because the priv didn't been free yet. */ - /*net_dev->ml_priv = 0; */ -#ifdef ST -err0: -#endif /* ST // */ - - DBGPRINT(RT_DEBUG_ERROR, ("rt28xx Initialized fail!\n")); - return FALSE; -} - -/*---Add by shiang, move from os/linux/rt_main_dev.c */ - -static int RtmpChipOpsRegister(struct rt_rtmp_adapter *pAd, int infType) -{ - struct rt_rtmp_chip_op *pChipOps = &pAd->chipOps; - int status; - - memset(pChipOps, 0, sizeof(struct rt_rtmp_chip_op)); - - /* set eeprom related hook functions */ - status = RtmpChipOpsEepromHook(pAd, infType); - - /* set mcu related hook functions */ - switch (infType) { -#ifdef RTMP_PCI_SUPPORT - case RTMP_DEV_INF_PCI: - pChipOps->loadFirmware = RtmpAsicLoadFirmware; - pChipOps->eraseFirmware = RtmpAsicEraseFirmware; - pChipOps->sendCommandToMcu = RtmpAsicSendCommandToMcu; - break; -#endif /* RTMP_PCI_SUPPORT // */ -#ifdef RTMP_USB_SUPPORT - case RTMP_DEV_INF_USB: - pChipOps->loadFirmware = RtmpAsicLoadFirmware; - pChipOps->sendCommandToMcu = RtmpAsicSendCommandToMcu; - break; -#endif /* RTMP_USB_SUPPORT // */ - default: - break; - } - - return status; -} - -int RtmpRaDevCtrlInit(struct rt_rtmp_adapter *pAd, IN RTMP_INF_TYPE infType) -{ - /*void *handle; */ - - /* Assign the interface type. We need use it when do register/EEPROM access. */ - pAd->infType = infType; - - pAd->OpMode = OPMODE_STA; - DBGPRINT(RT_DEBUG_TRACE, - ("STA Driver version-%s\n", STA_DRIVER_VERSION)); - -#ifdef RTMP_MAC_USB - sema_init(&(pAd->UsbVendorReq_semaphore), 1); - os_alloc_mem(pAd, (u8 **) & pAd->UsbVendorReqBuf, - MAX_PARAM_BUFFER_SIZE - 1); - if (pAd->UsbVendorReqBuf == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("Allocate vendor request temp buffer failed!\n")); - return FALSE; - } -#endif /* RTMP_MAC_USB // */ - - RtmpChipOpsRegister(pAd, infType); - - return 0; -} - -BOOLEAN RtmpRaDevCtrlExit(struct rt_rtmp_adapter *pAd) -{ - - RTMPFreeAdapter(pAd); - - return TRUE; -} - -/* not yet support MBSS */ -struct net_device *get_netdev_from_bssid(struct rt_rtmp_adapter *pAd, u8 FromWhichBSSID) -{ - struct net_device *dev_p = NULL; - - { - dev_p = pAd->net_dev; - } - - ASSERT(dev_p); - return dev_p; /* return one of MBSS */ -} diff --git a/trunk/drivers/staging/rt2860/common/rtmp_mcu.c b/trunk/drivers/staging/rt2860/common/rtmp_mcu.c deleted file mode 100644 index 80fa4160ed62..000000000000 --- a/trunk/drivers/staging/rt2860/common/rtmp_mcu.c +++ /dev/null @@ -1,336 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_mcu.c - - Abstract: - Miniport generic portion header file - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ - -#include "../rt_config.h" - -#include -#include - -#ifdef RTMP_MAC_USB - -#define FIRMWAREIMAGE_LENGTH 0x1000 - -#define FIRMWARE_2870_MIN_VERSION 12 -#define FIRMWARE_2870_FILENAME "rt2870.bin" -MODULE_FIRMWARE(FIRMWARE_2870_FILENAME); - -#define FIRMWARE_3070_MIN_VERSION 17 -#define FIRMWARE_3070_FILENAME "rt3070.bin" -MODULE_FIRMWARE(FIRMWARE_3070_FILENAME); - -#define FIRMWARE_3071_MIN_VERSION 17 -#define FIRMWARE_3071_FILENAME "rt3071.bin" /* for RT3071/RT3072 */ -MODULE_FIRMWARE(FIRMWARE_3071_FILENAME); - -#else /* RTMP_MAC_PCI */ - -#define FIRMWAREIMAGE_LENGTH 0x2000 - -#define FIRMWARE_2860_MIN_VERSION 11 -#define FIRMWARE_2860_FILENAME "rt2860.bin" -MODULE_FIRMWARE(FIRMWARE_2860_FILENAME); - -#define FIRMWARE_3090_MIN_VERSION 19 -#define FIRMWARE_3090_FILENAME "rt3090.bin" /* for RT3090/RT3390 */ -MODULE_FIRMWARE(FIRMWARE_3090_FILENAME); - -#endif - -/* - ======================================================================== - - Routine Description: - erase 8051 firmware image in MAC ASIC - - Arguments: - Adapter Pointer to our adapter - - IRQL = PASSIVE_LEVEL - - ======================================================================== -*/ -int RtmpAsicEraseFirmware(struct rt_rtmp_adapter *pAd) -{ - unsigned long i; - - for (i = 0; i < MAX_FIRMWARE_IMAGE_SIZE; i += 4) - RTMP_IO_WRITE32(pAd, FIRMWARE_IMAGE_BASE + i, 0); - - return 0; -} - -static const struct firmware *rtmp_get_firmware(struct rt_rtmp_adapter *adapter) -{ - const char *name; - const struct firmware *fw = NULL; - u8 min_version; - struct device *dev; - int err; - - if (adapter->firmware) - return adapter->firmware; - -#ifdef RTMP_MAC_USB - if (IS_RT3071(adapter)) { - name = FIRMWARE_3071_FILENAME; - min_version = FIRMWARE_3071_MIN_VERSION; - } else if (IS_RT3070(adapter)) { - name = FIRMWARE_3070_FILENAME; - min_version = FIRMWARE_3070_MIN_VERSION; - } else { - name = FIRMWARE_2870_FILENAME; - min_version = FIRMWARE_2870_MIN_VERSION; - } - dev = &((struct os_cookie *)adapter->OS_Cookie)->pUsb_Dev->dev; -#else /* RTMP_MAC_PCI */ - if (IS_RT3090(adapter) || IS_RT3390(adapter)) { - name = FIRMWARE_3090_FILENAME; - min_version = FIRMWARE_3090_MIN_VERSION; - } else { - name = FIRMWARE_2860_FILENAME; - min_version = FIRMWARE_2860_MIN_VERSION; - } - dev = &((struct os_cookie *)adapter->OS_Cookie)->pci_dev->dev; -#endif - - err = request_firmware(&fw, name, dev); - if (err) { - dev_err(dev, "firmware file %s request failed (%d)\n", - name, err); - return NULL; - } - - if (fw->size < FIRMWAREIMAGE_LENGTH) { - dev_err(dev, "firmware file %s size is invalid\n", name); - goto invalid; - } - - /* is it new enough? */ - adapter->FirmwareVersion = fw->data[FIRMWAREIMAGE_LENGTH - 3]; - if (adapter->FirmwareVersion < min_version) { - dev_err(dev, - "firmware file %s is too old;" - " driver requires v%d or later\n", - name, min_version); - goto invalid; - } - - /* is the internal CRC correct? */ - if (crc_ccitt(0xffff, fw->data, FIRMWAREIMAGE_LENGTH - 2) != - (fw->data[FIRMWAREIMAGE_LENGTH - 2] | - (fw->data[FIRMWAREIMAGE_LENGTH - 1] << 8))) { - dev_err(dev, "firmware file %s failed internal CRC\n", name); - goto invalid; - } - - adapter->firmware = fw; - return fw; - -invalid: - release_firmware(fw); - return NULL; -} - -/* - ======================================================================== - - Routine Description: - Load 8051 firmware file into MAC ASIC - - Arguments: - Adapter Pointer to our adapter - - Return Value: - NDIS_STATUS_SUCCESS firmware image load ok - NDIS_STATUS_FAILURE image not found - - IRQL = PASSIVE_LEVEL - - ======================================================================== -*/ -int RtmpAsicLoadFirmware(struct rt_rtmp_adapter *pAd) -{ - const struct firmware *fw; - int Status = NDIS_STATUS_SUCCESS; - unsigned long Index; - u32 MacReg = 0; - - fw = rtmp_get_firmware(pAd); - if (!fw) - return NDIS_STATUS_FAILURE; - - RTMP_WRITE_FIRMWARE(pAd, fw->data, FIRMWAREIMAGE_LENGTH); - - /* check if MCU is ready */ - Index = 0; - do { - RTMP_IO_READ32(pAd, PBF_SYS_CTRL, &MacReg); - - if (MacReg & 0x80) - break; - - RTMPusecDelay(1000); - } while (Index++ < 1000); - - if (Index > 1000) { - DBGPRINT(RT_DEBUG_ERROR, - ("NICLoadFirmware: MCU is not ready\n")); - Status = NDIS_STATUS_FAILURE; - } - - DBGPRINT(RT_DEBUG_TRACE, ("<=== %s (status=%d)\n", __func__, Status)); - - return Status; -} - -int RtmpAsicSendCommandToMcu(struct rt_rtmp_adapter *pAd, - u8 Command, - u8 Token, u8 Arg0, u8 Arg1) -{ - HOST_CMD_CSR_STRUC H2MCmd; - H2M_MAILBOX_STRUC H2MMailbox; - unsigned long i = 0; - -#ifdef PCIE_PS_SUPPORT - /* 3090F power solution 3 has hw limitation that needs to ban all mcu command */ - /* when firmware is in radio state. For other chip doesn't have this limitation. */ - if (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd)) && IS_VERSION_AFTER_F(pAd) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE)) { - RTMP_SEM_LOCK(&pAd->McuCmdLock); - if ((pAd->brt30xxBanMcuCmd == TRUE) - && (Command != WAKE_MCU_CMD) && (Command != RFOFF_MCU_CMD)) { - RTMP_SEM_UNLOCK(&pAd->McuCmdLock); - DBGPRINT(RT_DEBUG_TRACE, - (" Ban Mcu Cmd %x in sleep mode\n", Command)); - return FALSE; - } else if ((Command == SLEEP_MCU_CMD) - || (Command == RFOFF_MCU_CMD)) { - pAd->brt30xxBanMcuCmd = TRUE; - } else if (Command != WAKE_MCU_CMD) { - pAd->brt30xxBanMcuCmd = FALSE; - } - - RTMP_SEM_UNLOCK(&pAd->McuCmdLock); - - } - if (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd)) && IS_VERSION_AFTER_F(pAd) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) - && (Command == WAKE_MCU_CMD)) { - - do { - RTMP_IO_FORCE_READ32(pAd, H2M_MAILBOX_CSR, - &H2MMailbox.word); - if (H2MMailbox.field.Owner == 0) - break; - - RTMPusecDelay(2); - DBGPRINT(RT_DEBUG_INFO, - ("AsicSendCommanToMcu::Mail box is busy\n")); - } while (i++ < 100); - - if (i > 100) { - DBGPRINT_ERR("H2M_MAILBOX still hold by MCU. command fail\n"); - return FALSE; - } - - H2MMailbox.field.Owner = 1; /* pass ownership to MCU */ - H2MMailbox.field.CmdToken = Token; - H2MMailbox.field.HighByte = Arg1; - H2MMailbox.field.LowByte = Arg0; - RTMP_IO_FORCE_WRITE32(pAd, H2M_MAILBOX_CSR, H2MMailbox.word); - - H2MCmd.word = 0; - H2MCmd.field.HostCommand = Command; - RTMP_IO_FORCE_WRITE32(pAd, HOST_CMD_CSR, H2MCmd.word); - - } else -#endif /* PCIE_PS_SUPPORT // */ - { - do { - RTMP_IO_READ32(pAd, H2M_MAILBOX_CSR, &H2MMailbox.word); - if (H2MMailbox.field.Owner == 0) - break; - - RTMPusecDelay(2); - } while (i++ < 100); - - if (i > 100) { -#ifdef RTMP_MAC_PCI -#endif /* RTMP_MAC_PCI // */ - { - DBGPRINT_ERR("H2M_MAILBOX still hold by MCU. command fail\n"); - } - return FALSE; - } -#ifdef RTMP_MAC_PCI -#endif /* RTMP_MAC_PCI // */ - - H2MMailbox.field.Owner = 1; /* pass ownership to MCU */ - H2MMailbox.field.CmdToken = Token; - H2MMailbox.field.HighByte = Arg1; - H2MMailbox.field.LowByte = Arg0; - RTMP_IO_WRITE32(pAd, H2M_MAILBOX_CSR, H2MMailbox.word); - - H2MCmd.word = 0; - H2MCmd.field.HostCommand = Command; - RTMP_IO_WRITE32(pAd, HOST_CMD_CSR, H2MCmd.word); - - if (Command != 0x80) { - } - } -#ifdef PCIE_PS_SUPPORT - /* 3090 MCU Wakeup command needs more time to be stable. */ - /* Before stable, don't issue other MCU command to prevent from firmware error. */ - if (((IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) - && IS_VERSION_AFTER_F(pAd)) && IS_VERSION_AFTER_F(pAd) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode == 3) - && (pAd->StaCfg.PSControl.field.EnableNewPS == TRUE) - && (Command == WAKE_MCU_CMD)) { - RTMPusecDelay(2000); - /*Put this is after RF programming. */ - /*NdisAcquireSpinLock(&pAd->McuCmdLock); */ - /*pAd->brt30xxBanMcuCmd = FALSE; */ - /*NdisReleaseSpinLock(&pAd->McuCmdLock); */ - } -#endif /* PCIE_PS_SUPPORT // */ - - return TRUE; -} diff --git a/trunk/drivers/staging/rt2860/common/rtmp_timer.c b/trunk/drivers/staging/rt2860/common/rtmp_timer.c deleted file mode 100644 index ab520909490f..000000000000 --- a/trunk/drivers/staging/rt2860/common/rtmp_timer.c +++ /dev/null @@ -1,302 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_timer.c - - Abstract: - task for timer handling - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs - Shiang Tu 08-28-2008 init version - -*/ - -#include "../rt_config.h" - -BUILD_TIMER_FUNCTION(MlmePeriodicExec); -/*BUILD_TIMER_FUNCTION(MlmeRssiReportExec); */ -BUILD_TIMER_FUNCTION(AsicRxAntEvalTimeout); -BUILD_TIMER_FUNCTION(APSDPeriodicExec); -BUILD_TIMER_FUNCTION(AsicRfTuningExec); -#ifdef RTMP_MAC_USB -BUILD_TIMER_FUNCTION(BeaconUpdateExec); -#endif /* RTMP_MAC_USB // */ - -BUILD_TIMER_FUNCTION(BeaconTimeout); -BUILD_TIMER_FUNCTION(ScanTimeout); -BUILD_TIMER_FUNCTION(AuthTimeout); -BUILD_TIMER_FUNCTION(AssocTimeout); -BUILD_TIMER_FUNCTION(ReassocTimeout); -BUILD_TIMER_FUNCTION(DisassocTimeout); -BUILD_TIMER_FUNCTION(LinkDownExec); -BUILD_TIMER_FUNCTION(StaQuickResponeForRateUpExec); -BUILD_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc); -#ifdef RTMP_MAC_PCI -BUILD_TIMER_FUNCTION(PsPollWakeExec); -BUILD_TIMER_FUNCTION(RadioOnExec); -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB -BUILD_TIMER_FUNCTION(RtmpUsbStaAsicForceWakeupTimeout); -#endif /* RTMP_MAC_USB // */ - -#if defined(AP_LED) || defined(STA_LED) -extern void LedCtrlMain(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); -BUILD_TIMER_FUNCTION(LedCtrlMain); -#endif - -#ifdef RTMP_TIMER_TASK_SUPPORT -static void RtmpTimerQHandle(struct rt_rtmp_adapter *pAd) -{ -#ifndef KTHREAD_SUPPORT - int status; -#endif - struct rt_ralink_timer *pTimer; - struct rt_rtmp_timer_task_entry *pEntry; - unsigned long irqFlag; - struct rt_rtmp_os_task *pTask; - - pTask = &pAd->timerTask; - while (!pTask->task_killed) { - pTimer = NULL; - -#ifdef KTHREAD_SUPPORT - RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask); -#else - RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status); -#endif - - if (pAd->TimerQ.status == RTMP_TASK_STAT_STOPED) - break; - - /* event happened. */ - while (pAd->TimerQ.pQHead) { - RTMP_INT_LOCK(&pAd->TimerQLock, irqFlag); - pEntry = pAd->TimerQ.pQHead; - if (pEntry) { - pTimer = pEntry->pRaTimer; - - /* update pQHead */ - pAd->TimerQ.pQHead = pEntry->pNext; - if (pEntry == pAd->TimerQ.pQTail) - pAd->TimerQ.pQTail = NULL; - - /* return this queue entry to timerQFreeList. */ - pEntry->pNext = pAd->TimerQ.pQPollFreeList; - pAd->TimerQ.pQPollFreeList = pEntry; - } - RTMP_INT_UNLOCK(&pAd->TimerQLock, irqFlag); - - if (pTimer) { - if ((pTimer->handle != NULL) - && (!pAd->PM_FlgSuspend)) - pTimer->handle(NULL, - (void *)pTimer->cookie, - NULL, pTimer); - if ((pTimer->Repeat) - && (pTimer->State == FALSE)) - RTMP_OS_Add_Timer(&pTimer->TimerObj, - pTimer->TimerValue); - } - } - -#ifndef KTHREAD_SUPPORT - if (status != 0) { - pAd->TimerQ.status = RTMP_TASK_STAT_STOPED; - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); - break; - } -#endif - } -} - -int RtmpTimerQThread(IN void *Context) -{ - struct rt_rtmp_os_task *pTask; - struct rt_rtmp_adapter *pAd; - - pTask = Context; - pAd = pTask->priv; - - RtmpOSTaskCustomize(pTask); - - RtmpTimerQHandle(pAd); - - DBGPRINT(RT_DEBUG_TRACE, ("<---%s\n", __func__)); -#ifndef KTHREAD_SUPPORT - pTask->taskPID = THREAD_PID_INIT_VALUE; -#endif - /* notify the exit routine that we're actually exiting now - * - * complete()/wait_for_completion() is similar to up()/down(), - * except that complete() is safe in the case where the structure - * is getting deleted in a parallel mode of execution (i.e. just - * after the down() -- that's necessary for the thread-shutdown - * case. - * - * complete_and_exit() goes even further than this -- it is safe in - * the case that the thread of the caller is going away (not just - * the structure) -- this is necessary for the module-remove case. - * This is important in preemption kernels, which transfer the flow - * of execution immediately upon a complete(). - */ - RtmpOSTaskNotifyToExit(pTask); - - return 0; - -} - -struct rt_rtmp_timer_task_entry *RtmpTimerQInsert(struct rt_rtmp_adapter *pAd, - struct rt_ralink_timer *pTimer) -{ - struct rt_rtmp_timer_task_entry *pQNode = NULL, *pQTail; - unsigned long irqFlags; - struct rt_rtmp_os_task *pTask = &pAd->timerTask; - - RTMP_INT_LOCK(&pAd->TimerQLock, irqFlags); - if (pAd->TimerQ.status & RTMP_TASK_CAN_DO_INSERT) { - if (pAd->TimerQ.pQPollFreeList) { - pQNode = pAd->TimerQ.pQPollFreeList; - pAd->TimerQ.pQPollFreeList = pQNode->pNext; - - pQNode->pRaTimer = pTimer; - pQNode->pNext = NULL; - - pQTail = pAd->TimerQ.pQTail; - if (pAd->TimerQ.pQTail != NULL) - pQTail->pNext = pQNode; - pAd->TimerQ.pQTail = pQNode; - if (pAd->TimerQ.pQHead == NULL) - pAd->TimerQ.pQHead = pQNode; - } - } - RTMP_INT_UNLOCK(&pAd->TimerQLock, irqFlags); - - if (pQNode) { -#ifdef KTHREAD_SUPPORT - WAKE_UP(pTask); -#else - RTMP_SEM_EVENT_UP(&pTask->taskSema); -#endif - } - - return pQNode; -} - -BOOLEAN RtmpTimerQRemove(struct rt_rtmp_adapter *pAd, struct rt_ralink_timer *pTimer) -{ - struct rt_rtmp_timer_task_entry *pNode, *pPrev = NULL; - unsigned long irqFlags; - - RTMP_INT_LOCK(&pAd->TimerQLock, irqFlags); - if (pAd->TimerQ.status >= RTMP_TASK_STAT_INITED) { - pNode = pAd->TimerQ.pQHead; - while (pNode) { - if (pNode->pRaTimer == pTimer) - break; - pPrev = pNode; - pNode = pNode->pNext; - } - - /* Now move it to freeList queue. */ - if (pNode) { - if (pNode == pAd->TimerQ.pQHead) - pAd->TimerQ.pQHead = pNode->pNext; - if (pNode == pAd->TimerQ.pQTail) - pAd->TimerQ.pQTail = pPrev; - if (pPrev != NULL) - pPrev->pNext = pNode->pNext; - - /* return this queue entry to timerQFreeList. */ - pNode->pNext = pAd->TimerQ.pQPollFreeList; - pAd->TimerQ.pQPollFreeList = pNode; - } - } - RTMP_INT_UNLOCK(&pAd->TimerQLock, irqFlags); - - return TRUE; -} - -void RtmpTimerQExit(struct rt_rtmp_adapter *pAd) -{ - struct rt_rtmp_timer_task_entry *pTimerQ; - unsigned long irqFlags; - - RTMP_INT_LOCK(&pAd->TimerQLock, irqFlags); - while (pAd->TimerQ.pQHead) { - pTimerQ = pAd->TimerQ.pQHead; - pAd->TimerQ.pQHead = pTimerQ->pNext; - /* remove the timeQ */ - } - pAd->TimerQ.pQPollFreeList = NULL; - os_free_mem(pAd, pAd->TimerQ.pTimerQPoll); - pAd->TimerQ.pQTail = NULL; - pAd->TimerQ.pQHead = NULL; -#ifndef KTHREAD_SUPPORT - pAd->TimerQ.status = RTMP_TASK_STAT_STOPED; -#endif - RTMP_INT_UNLOCK(&pAd->TimerQLock, irqFlags); - -} - -void RtmpTimerQInit(struct rt_rtmp_adapter *pAd) -{ - int i; - struct rt_rtmp_timer_task_entry *pQNode, *pEntry; - unsigned long irqFlags; - - NdisAllocateSpinLock(&pAd->TimerQLock); - - NdisZeroMemory(&pAd->TimerQ, sizeof(pAd->TimerQ)); - - os_alloc_mem(pAd, &pAd->TimerQ.pTimerQPoll, - sizeof(struct rt_rtmp_timer_task_entry) * TIMER_QUEUE_SIZE_MAX); - if (pAd->TimerQ.pTimerQPoll) { - pEntry = NULL; - pQNode = (struct rt_rtmp_timer_task_entry *)pAd->TimerQ.pTimerQPoll; - NdisZeroMemory(pAd->TimerQ.pTimerQPoll, - sizeof(struct rt_rtmp_timer_task_entry) * - TIMER_QUEUE_SIZE_MAX); - - RTMP_INT_LOCK(&pAd->TimerQLock, irqFlags); - for (i = 0; i < TIMER_QUEUE_SIZE_MAX; i++) { - pQNode->pNext = pEntry; - pEntry = pQNode; - pQNode++; - } - pAd->TimerQ.pQPollFreeList = pEntry; - pAd->TimerQ.pQHead = NULL; - pAd->TimerQ.pQTail = NULL; - pAd->TimerQ.status = RTMP_TASK_STAT_INITED; - RTMP_INT_UNLOCK(&pAd->TimerQLock, irqFlags); - } -} -#endif /* RTMP_TIMER_TASK_SUPPORT // */ diff --git a/trunk/drivers/staging/rt2860/common/spectrum.c b/trunk/drivers/staging/rt2860/common/spectrum.c deleted file mode 100644 index ceb622df12d7..000000000000 --- a/trunk/drivers/staging/rt2860/common/spectrum.c +++ /dev/null @@ -1,2205 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - action.c - - Abstract: - Handle association related requests either from WSTA or from local MLME - - Revision History: - Who When What - --------- ---------- ---------------------------------------------- - Fonchi Wu 2008 created for 802.11h - */ - -#include "../rt_config.h" -#include "action.h" - -/* The regulatory information in the USA (US) */ -struct rt_dot11_regulatory_information USARegulatoryInfo[] = { -/* "regulatory class" "number of channels" "Max Tx Pwr" "channel list" */ - {0, {0, 0, {0} - } - } - , /* Invlid entry */ - {1, {4, 16, {36, 40, 44, 48} - } - } - , - {2, {4, 23, {52, 56, 60, 64} - } - } - , - {3, {4, 29, {149, 153, 157, 161} - } - } - , - {4, {11, 23, {100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140} - } - } - , - {5, {5, 30, {149, 153, 157, 161, 165} - } - } - , - {6, {10, 14, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - } - } - , - {7, {10, 27, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} - } - } - , - {8, {5, 17, {11, 13, 15, 17, 19} - } - } - , - {9, {5, 30, {11, 13, 15, 17, 19} - } - } - , - {10, {2, 20, {21, 25} - } - } - , - {11, {2, 33, {21, 25} - } - } - , - {12, {11, 30, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} - } - } -}; - -#define USA_REGULATORY_INFO_SIZE (sizeof(USARegulatoryInfo) / sizeof(struct rt_dot11_regulatory_information)) - -/* The regulatory information in Europe */ -struct rt_dot11_regulatory_information EuropeRegulatoryInfo[] = { -/* "regulatory class" "number of channels" "Max Tx Pwr" "channel list" */ - {0, {0, 0, {0} - } - } - , /* Invalid entry */ - {1, {4, 20, {36, 40, 44, 48} - } - } - , - {2, {4, 20, {52, 56, 60, 64} - } - } - , - {3, {11, 30, {100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140} - } - } - , - {4, {13, 20, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13} - } - } -}; - -#define EU_REGULATORY_INFO_SIZE (sizeof(EuropeRegulatoryInfo) / sizeof(struct rt_dot11_regulatory_information)) - -/* The regulatory information in Japan */ -struct rt_dot11_regulatory_information JapanRegulatoryInfo[] = { -/* "regulatory class" "number of channels" "Max Tx Pwr" "channel list" */ - {0, {0, 0, {0} - } - } - , /* Invalid entry */ - {1, {4, 22, {34, 38, 42, 46} - } - } - , - {2, {3, 24, {8, 12, 16} - } - } - , - {3, {3, 24, {8, 12, 16} - } - } - , - {4, {3, 24, {8, 12, 16} - } - } - , - {5, {3, 24, {8, 12, 16} - } - } - , - {6, {3, 22, {8, 12, 16} - } - } - , - {7, {4, 24, {184, 188, 192, 196} - } - } - , - {8, {4, 24, {184, 188, 192, 196} - } - } - , - {9, {4, 24, {184, 188, 192, 196} - } - } - , - {10, {4, 24, {184, 188, 192, 196} - } - } - , - {11, {4, 22, {184, 188, 192, 196} - } - } - , - {12, {4, 24, {7, 8, 9, 11} - } - } - , - {13, {4, 24, {7, 8, 9, 11} - } - } - , - {14, {4, 24, {7, 8, 9, 11} - } - } - , - {15, {4, 24, {7, 8, 9, 11} - } - } - , - {16, {6, 24, {183, 184, 185, 187, 188, 189} - } - } - , - {17, {6, 24, {183, 184, 185, 187, 188, 189} - } - } - , - {18, {6, 24, {183, 184, 185, 187, 188, 189} - } - } - , - {19, {6, 24, {183, 184, 185, 187, 188, 189} - } - } - , - {20, {6, 17, {183, 184, 185, 187, 188, 189} - } - } - , - {21, {6, 24, {6, 7, 8, 9, 10, 11} - } - } - , - {22, {6, 24, {6, 7, 8, 9, 10, 11} - } - } - , - {23, {6, 24, {6, 7, 8, 9, 10, 11} - } - } - , - {24, {6, 24, {6, 7, 8, 9, 10, 11} - } - } - , - {25, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189} - } - } - , - {26, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189} - } - } - , - {27, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189} - } - } - , - {28, {8, 24, {182, 183, 184, 185, 186, 187, 188, 189} - } - } - , - {29, {8, 17, {182, 183, 184, 185, 186, 187, 188, 189} - } - } - , - {30, {13, 23, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13} - } - } - , - {31, {1, 23, {14} - } - } - , - {32, {4, 22, {52, 56, 60, 64} - } - } -}; - -#define JP_REGULATORY_INFO_SIZE (sizeof(JapanRegulatoryInfo) / sizeof(struct rt_dot11_regulatory_information)) - -char RTMP_GetTxPwr(struct rt_rtmp_adapter *pAd, IN HTTRANSMIT_SETTING HTTxMode) -{ - struct tx_pwr_cfg { - u8 Mode; - u8 MCS; - u16 req; - u8 shift; - u32 BitMask; - }; - - u32 Value; - int Idx; - u8 PhyMode; - char CurTxPwr; - u8 TxPwrRef = 0; - char DaltaPwr; - unsigned long TxPwr[5]; - - struct tx_pwr_cfg TxPwrCfg[] = { - {MODE_CCK, 0, 0, 4, 0x000000f0}, - {MODE_CCK, 1, 0, 0, 0x0000000f}, - {MODE_CCK, 2, 0, 12, 0x0000f000}, - {MODE_CCK, 3, 0, 8, 0x00000f00}, - - {MODE_OFDM, 0, 0, 20, 0x00f00000}, - {MODE_OFDM, 1, 0, 16, 0x000f0000}, - {MODE_OFDM, 2, 0, 28, 0xf0000000}, - {MODE_OFDM, 3, 0, 24, 0x0f000000}, - {MODE_OFDM, 4, 1, 4, 0x000000f0}, - {MODE_OFDM, 5, 1, 0, 0x0000000f}, - {MODE_OFDM, 6, 1, 12, 0x0000f000}, - {MODE_OFDM, 7, 1, 8, 0x00000f00} - , {MODE_HTMIX, 0, 1, 20, 0x00f00000}, - {MODE_HTMIX, 1, 1, 16, 0x000f0000}, - {MODE_HTMIX, 2, 1, 28, 0xf0000000}, - {MODE_HTMIX, 3, 1, 24, 0x0f000000}, - {MODE_HTMIX, 4, 2, 4, 0x000000f0}, - {MODE_HTMIX, 5, 2, 0, 0x0000000f}, - {MODE_HTMIX, 6, 2, 12, 0x0000f000}, - {MODE_HTMIX, 7, 2, 8, 0x00000f00}, - {MODE_HTMIX, 8, 2, 20, 0x00f00000}, - {MODE_HTMIX, 9, 2, 16, 0x000f0000}, - {MODE_HTMIX, 10, 2, 28, 0xf0000000}, - {MODE_HTMIX, 11, 2, 24, 0x0f000000}, - {MODE_HTMIX, 12, 3, 4, 0x000000f0}, - {MODE_HTMIX, 13, 3, 0, 0x0000000f}, - {MODE_HTMIX, 14, 3, 12, 0x0000f000}, - {MODE_HTMIX, 15, 3, 8, 0x00000f00} - }; -#define MAX_TXPWR_TAB_SIZE (sizeof(TxPwrCfg) / sizeof(struct tx_pwr_cfg)) - - CurTxPwr = 19; - - /* check Tx Power setting from UI. */ - if (pAd->CommonCfg.TxPowerPercentage > 90) ; - else if (pAd->CommonCfg.TxPowerPercentage > 60) /* reduce Pwr for 1 dB. */ - CurTxPwr -= 1; - else if (pAd->CommonCfg.TxPowerPercentage > 30) /* reduce Pwr for 3 dB. */ - CurTxPwr -= 3; - else if (pAd->CommonCfg.TxPowerPercentage > 15) /* reduce Pwr for 6 dB. */ - CurTxPwr -= 6; - else if (pAd->CommonCfg.TxPowerPercentage > 9) /* reduce Pwr for 9 dB. */ - CurTxPwr -= 9; - else /* reduce Pwr for 12 dB. */ - CurTxPwr -= 12; - - if (pAd->CommonCfg.BBPCurrentBW == BW_40) { - if (pAd->CommonCfg.CentralChannel > 14) { - TxPwr[0] = pAd->Tx40MPwrCfgABand[0]; - TxPwr[1] = pAd->Tx40MPwrCfgABand[1]; - TxPwr[2] = pAd->Tx40MPwrCfgABand[2]; - TxPwr[3] = pAd->Tx40MPwrCfgABand[3]; - TxPwr[4] = pAd->Tx40MPwrCfgABand[4]; - } else { - TxPwr[0] = pAd->Tx40MPwrCfgGBand[0]; - TxPwr[1] = pAd->Tx40MPwrCfgGBand[1]; - TxPwr[2] = pAd->Tx40MPwrCfgGBand[2]; - TxPwr[3] = pAd->Tx40MPwrCfgGBand[3]; - TxPwr[4] = pAd->Tx40MPwrCfgGBand[4]; - } - } else { - if (pAd->CommonCfg.Channel > 14) { - TxPwr[0] = pAd->Tx20MPwrCfgABand[0]; - TxPwr[1] = pAd->Tx20MPwrCfgABand[1]; - TxPwr[2] = pAd->Tx20MPwrCfgABand[2]; - TxPwr[3] = pAd->Tx20MPwrCfgABand[3]; - TxPwr[4] = pAd->Tx20MPwrCfgABand[4]; - } else { - TxPwr[0] = pAd->Tx20MPwrCfgGBand[0]; - TxPwr[1] = pAd->Tx20MPwrCfgGBand[1]; - TxPwr[2] = pAd->Tx20MPwrCfgGBand[2]; - TxPwr[3] = pAd->Tx20MPwrCfgGBand[3]; - TxPwr[4] = pAd->Tx20MPwrCfgGBand[4]; - } - } - - switch (HTTxMode.field.MODE) { - case MODE_CCK: - case MODE_OFDM: - Value = TxPwr[1]; - TxPwrRef = (Value & 0x00000f00) >> 8; - - break; - - case MODE_HTMIX: - case MODE_HTGREENFIELD: - if (pAd->CommonCfg.TxStream == 1) { - Value = TxPwr[2]; - TxPwrRef = (Value & 0x00000f00) >> 8; - } else if (pAd->CommonCfg.TxStream == 2) { - Value = TxPwr[3]; - TxPwrRef = (Value & 0x00000f00) >> 8; - } - break; - } - - PhyMode = (HTTxMode.field.MODE == MODE_HTGREENFIELD) - ? MODE_HTMIX : HTTxMode.field.MODE; - - for (Idx = 0; Idx < MAX_TXPWR_TAB_SIZE; Idx++) { - if ((TxPwrCfg[Idx].Mode == PhyMode) - && (TxPwrCfg[Idx].MCS == HTTxMode.field.MCS)) { - Value = TxPwr[TxPwrCfg[Idx].req]; - DaltaPwr = - TxPwrRef - (char)((Value & TxPwrCfg[Idx].BitMask) - >> TxPwrCfg[Idx].shift); - CurTxPwr -= DaltaPwr; - break; - } - } - - return CurTxPwr; -} - -void MeasureReqTabInit(struct rt_rtmp_adapter *pAd) -{ - NdisAllocateSpinLock(&pAd->CommonCfg.MeasureReqTabLock); - - pAd->CommonCfg.pMeasureReqTab = - kmalloc(sizeof(struct rt_measure_req_tab), GFP_ATOMIC); - if (pAd->CommonCfg.pMeasureReqTab) - NdisZeroMemory(pAd->CommonCfg.pMeasureReqTab, - sizeof(struct rt_measure_req_tab)); - else - DBGPRINT(RT_DEBUG_ERROR, - ("%s Fail to alloc memory for pAd->CommonCfg.pMeasureReqTab.\n", - __func__)); - - return; -} - -void MeasureReqTabExit(struct rt_rtmp_adapter *pAd) -{ - NdisFreeSpinLock(&pAd->CommonCfg.MeasureReqTabLock); - - kfree(pAd->CommonCfg.pMeasureReqTab); - pAd->CommonCfg.pMeasureReqTab = NULL; - - return; -} - -struct rt_measure_req_entry *MeasureReqLookUp(struct rt_rtmp_adapter *pAd, u8 DialogToken) -{ - u32 HashIdx; - struct rt_measure_req_tab *pTab = pAd->CommonCfg.pMeasureReqTab; - struct rt_measure_req_entry *pEntry = NULL; - struct rt_measure_req_entry *pPrevEntry = NULL; - - if (pTab == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: pMeasureReqTab doesn't exist.\n", __func__)); - return NULL; - } - - RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock); - - HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken); - pEntry = pTab->Hash[HashIdx]; - - while (pEntry) { - if (pEntry->DialogToken == DialogToken) - break; - else { - pPrevEntry = pEntry; - pEntry = pEntry->pNext; - } - } - - RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock); - - return pEntry; -} - -struct rt_measure_req_entry *MeasureReqInsert(struct rt_rtmp_adapter *pAd, u8 DialogToken) -{ - int i; - unsigned long HashIdx; - struct rt_measure_req_tab *pTab = pAd->CommonCfg.pMeasureReqTab; - struct rt_measure_req_entry *pEntry = NULL, *pCurrEntry; - unsigned long Now; - - if (pTab == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: pMeasureReqTab doesn't exist.\n", __func__)); - return NULL; - } - - pEntry = MeasureReqLookUp(pAd, DialogToken); - if (pEntry == NULL) { - RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock); - for (i = 0; i < MAX_MEASURE_REQ_TAB_SIZE; i++) { - NdisGetSystemUpTime(&Now); - pEntry = &pTab->Content[i]; - - if ((pEntry->Valid == TRUE) - && RTMP_TIME_AFTER((unsigned long)Now, - (unsigned long)(pEntry-> - lastTime + - MQ_REQ_AGE_OUT))) - { - struct rt_measure_req_entry *pPrevEntry = NULL; - unsigned long HashIdx = - MQ_DIALOGTOKEN_HASH_INDEX(pEntry-> - DialogToken); - struct rt_measure_req_entry *pProbeEntry = - pTab->Hash[HashIdx]; - - /* update Hash list */ - do { - if (pProbeEntry == pEntry) { - if (pPrevEntry == NULL) { - pTab->Hash[HashIdx] = - pEntry->pNext; - } else { - pPrevEntry->pNext = - pEntry->pNext; - } - break; - } - - pPrevEntry = pProbeEntry; - pProbeEntry = pProbeEntry->pNext; - } while (pProbeEntry); - - NdisZeroMemory(pEntry, - sizeof(struct rt_measure_req_entry)); - pTab->Size--; - - break; - } - - if (pEntry->Valid == FALSE) - break; - } - - if (i < MAX_MEASURE_REQ_TAB_SIZE) { - NdisGetSystemUpTime(&Now); - pEntry->lastTime = Now; - pEntry->Valid = TRUE; - pEntry->DialogToken = DialogToken; - pTab->Size++; - } else { - pEntry = NULL; - DBGPRINT(RT_DEBUG_ERROR, - ("%s: pMeasureReqTab tab full.\n", __func__)); - } - - /* add this Neighbor entry into HASH table */ - if (pEntry) { - HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(DialogToken); - if (pTab->Hash[HashIdx] == NULL) { - pTab->Hash[HashIdx] = pEntry; - } else { - pCurrEntry = pTab->Hash[HashIdx]; - while (pCurrEntry->pNext != NULL) - pCurrEntry = pCurrEntry->pNext; - pCurrEntry->pNext = pEntry; - } - } - - RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock); - } - - return pEntry; -} - -void MeasureReqDelete(struct rt_rtmp_adapter *pAd, u8 DialogToken) -{ - struct rt_measure_req_tab *pTab = pAd->CommonCfg.pMeasureReqTab; - struct rt_measure_req_entry *pEntry = NULL; - - if (pTab == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: pMeasureReqTab doesn't exist.\n", __func__)); - return; - } - /* if empty, return */ - if (pTab->Size == 0) { - DBGPRINT(RT_DEBUG_ERROR, ("pMeasureReqTab empty.\n")); - return; - } - - pEntry = MeasureReqLookUp(pAd, DialogToken); - if (pEntry != NULL) { - struct rt_measure_req_entry *pPrevEntry = NULL; - unsigned long HashIdx = MQ_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken); - struct rt_measure_req_entry *pProbeEntry = pTab->Hash[HashIdx]; - - RTMP_SEM_LOCK(&pAd->CommonCfg.MeasureReqTabLock); - /* update Hash list */ - do { - if (pProbeEntry == pEntry) { - if (pPrevEntry == NULL) { - pTab->Hash[HashIdx] = pEntry->pNext; - } else { - pPrevEntry->pNext = pEntry->pNext; - } - break; - } - - pPrevEntry = pProbeEntry; - pProbeEntry = pProbeEntry->pNext; - } while (pProbeEntry); - - NdisZeroMemory(pEntry, sizeof(struct rt_measure_req_entry)); - pTab->Size--; - - RTMP_SEM_UNLOCK(&pAd->CommonCfg.MeasureReqTabLock); - } - - return; -} - -void TpcReqTabInit(struct rt_rtmp_adapter *pAd) -{ - NdisAllocateSpinLock(&pAd->CommonCfg.TpcReqTabLock); - - pAd->CommonCfg.pTpcReqTab = kmalloc(sizeof(struct rt_tpc_req_tab), GFP_ATOMIC); - if (pAd->CommonCfg.pTpcReqTab) - NdisZeroMemory(pAd->CommonCfg.pTpcReqTab, sizeof(struct rt_tpc_req_tab)); - else - DBGPRINT(RT_DEBUG_ERROR, - ("%s Fail to alloc memory for pAd->CommonCfg.pTpcReqTab.\n", - __func__)); - - return; -} - -void TpcReqTabExit(struct rt_rtmp_adapter *pAd) -{ - NdisFreeSpinLock(&pAd->CommonCfg.TpcReqTabLock); - - kfree(pAd->CommonCfg.pTpcReqTab); - pAd->CommonCfg.pTpcReqTab = NULL; - - return; -} - -static struct rt_tpc_req_entry *TpcReqLookUp(struct rt_rtmp_adapter *pAd, u8 DialogToken) -{ - u32 HashIdx; - struct rt_tpc_req_tab *pTab = pAd->CommonCfg.pTpcReqTab; - struct rt_tpc_req_entry *pEntry = NULL; - struct rt_tpc_req_entry *pPrevEntry = NULL; - - if (pTab == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: pTpcReqTab doesn't exist.\n", __func__)); - return NULL; - } - - RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock); - - HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken); - pEntry = pTab->Hash[HashIdx]; - - while (pEntry) { - if (pEntry->DialogToken == DialogToken) - break; - else { - pPrevEntry = pEntry; - pEntry = pEntry->pNext; - } - } - - RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock); - - return pEntry; -} - -static struct rt_tpc_req_entry *TpcReqInsert(struct rt_rtmp_adapter *pAd, u8 DialogToken) -{ - int i; - unsigned long HashIdx; - struct rt_tpc_req_tab *pTab = pAd->CommonCfg.pTpcReqTab; - struct rt_tpc_req_entry *pEntry = NULL, *pCurrEntry; - unsigned long Now; - - if (pTab == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: pTpcReqTab doesn't exist.\n", __func__)); - return NULL; - } - - pEntry = TpcReqLookUp(pAd, DialogToken); - if (pEntry == NULL) { - RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock); - for (i = 0; i < MAX_TPC_REQ_TAB_SIZE; i++) { - NdisGetSystemUpTime(&Now); - pEntry = &pTab->Content[i]; - - if ((pEntry->Valid == TRUE) - && RTMP_TIME_AFTER((unsigned long)Now, - (unsigned long)(pEntry-> - lastTime + - TPC_REQ_AGE_OUT))) - { - struct rt_tpc_req_entry *pPrevEntry = NULL; - unsigned long HashIdx = - TPC_DIALOGTOKEN_HASH_INDEX(pEntry-> - DialogToken); - struct rt_tpc_req_entry *pProbeEntry = - pTab->Hash[HashIdx]; - - /* update Hash list */ - do { - if (pProbeEntry == pEntry) { - if (pPrevEntry == NULL) { - pTab->Hash[HashIdx] = - pEntry->pNext; - } else { - pPrevEntry->pNext = - pEntry->pNext; - } - break; - } - - pPrevEntry = pProbeEntry; - pProbeEntry = pProbeEntry->pNext; - } while (pProbeEntry); - - NdisZeroMemory(pEntry, sizeof(struct rt_tpc_req_entry)); - pTab->Size--; - - break; - } - - if (pEntry->Valid == FALSE) - break; - } - - if (i < MAX_TPC_REQ_TAB_SIZE) { - NdisGetSystemUpTime(&Now); - pEntry->lastTime = Now; - pEntry->Valid = TRUE; - pEntry->DialogToken = DialogToken; - pTab->Size++; - } else { - pEntry = NULL; - DBGPRINT(RT_DEBUG_ERROR, - ("%s: pTpcReqTab tab full.\n", __func__)); - } - - /* add this Neighbor entry into HASH table */ - if (pEntry) { - HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(DialogToken); - if (pTab->Hash[HashIdx] == NULL) { - pTab->Hash[HashIdx] = pEntry; - } else { - pCurrEntry = pTab->Hash[HashIdx]; - while (pCurrEntry->pNext != NULL) - pCurrEntry = pCurrEntry->pNext; - pCurrEntry->pNext = pEntry; - } - } - - RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock); - } - - return pEntry; -} - -static void TpcReqDelete(struct rt_rtmp_adapter *pAd, u8 DialogToken) -{ - struct rt_tpc_req_tab *pTab = pAd->CommonCfg.pTpcReqTab; - struct rt_tpc_req_entry *pEntry = NULL; - - if (pTab == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: pTpcReqTab doesn't exist.\n", __func__)); - return; - } - /* if empty, return */ - if (pTab->Size == 0) { - DBGPRINT(RT_DEBUG_ERROR, ("pTpcReqTab empty.\n")); - return; - } - - pEntry = TpcReqLookUp(pAd, DialogToken); - if (pEntry != NULL) { - struct rt_tpc_req_entry *pPrevEntry = NULL; - unsigned long HashIdx = TPC_DIALOGTOKEN_HASH_INDEX(pEntry->DialogToken); - struct rt_tpc_req_entry *pProbeEntry = pTab->Hash[HashIdx]; - - RTMP_SEM_LOCK(&pAd->CommonCfg.TpcReqTabLock); - /* update Hash list */ - do { - if (pProbeEntry == pEntry) { - if (pPrevEntry == NULL) { - pTab->Hash[HashIdx] = pEntry->pNext; - } else { - pPrevEntry->pNext = pEntry->pNext; - } - break; - } - - pPrevEntry = pProbeEntry; - pProbeEntry = pProbeEntry->pNext; - } while (pProbeEntry); - - NdisZeroMemory(pEntry, sizeof(struct rt_tpc_req_entry)); - pTab->Size--; - - RTMP_SEM_UNLOCK(&pAd->CommonCfg.TpcReqTabLock); - } - - return; -} - -/* - ========================================================================== - Description: - Get Current TimeS tamp. - - Parametrs: - - Return : Current Time Stamp. - ========================================================================== - */ -static u64 GetCurrentTimeStamp(struct rt_rtmp_adapter *pAd) -{ - /* get current time stamp. */ - return 0; -} - -/* - ========================================================================== - Description: - Get Current Transmit Power. - - Parametrs: - - Return : Current Time Stamp. - ========================================================================== - */ -static u8 GetCurTxPwr(struct rt_rtmp_adapter *pAd, u8 Wcid) -{ - return 16; /* 16 dBm */ -} - -/* - ========================================================================== - Description: - Get Current Transmit Power. - - Parametrs: - - Return : Current Time Stamp. - ========================================================================== - */ -void InsertChannelRepIE(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, - char *pCountry, u8 RegulatoryClass) -{ - unsigned long TempLen; - u8 Len; - u8 IEId = IE_AP_CHANNEL_REPORT; - u8 *pChListPtr = NULL; - - Len = 1; - if (strncmp(pCountry, "US", 2) == 0) { - if (RegulatoryClass >= USA_REGULATORY_INFO_SIZE) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: USA Unknow Requlatory class (%d)\n", - __func__, RegulatoryClass)); - return; - } - - Len += - USARegulatoryInfo[RegulatoryClass].ChannelSet. - NumberOfChannels; - pChListPtr = - USARegulatoryInfo[RegulatoryClass].ChannelSet.ChannelList; - } else if (strncmp(pCountry, "JP", 2) == 0) { - if (RegulatoryClass >= JP_REGULATORY_INFO_SIZE) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: JP Unknow Requlatory class (%d)\n", - __func__, RegulatoryClass)); - return; - } - - Len += - JapanRegulatoryInfo[RegulatoryClass].ChannelSet. - NumberOfChannels; - pChListPtr = - JapanRegulatoryInfo[RegulatoryClass].ChannelSet.ChannelList; - } else { - DBGPRINT(RT_DEBUG_ERROR, ("%s: Unknow Country (%s)\n", - __func__, pCountry)); - return; - } - - MakeOutgoingFrame(pFrameBuf, &TempLen, - 1, &IEId, - 1, &Len, - 1, &RegulatoryClass, - Len - 1, pChListPtr, END_OF_ARGS); - - *pFrameLen = *pFrameLen + TempLen; - - return; -} - -/* - ========================================================================== - Description: - Insert Dialog Token into frame. - - Parametrs: - 1. frame buffer pointer. - 2. frame length. - 3. Dialog token. - - Return : None. - ========================================================================== - */ -void InsertDialogToken(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, u8 DialogToken) -{ - unsigned long TempLen; - MakeOutgoingFrame(pFrameBuf, &TempLen, 1, &DialogToken, END_OF_ARGS); - - *pFrameLen = *pFrameLen + TempLen; - - return; -} - -/* - ========================================================================== - Description: - Insert TPC Request IE into frame. - - Parametrs: - 1. frame buffer pointer. - 2. frame length. - - Return : None. - ========================================================================== - */ -static void InsertTpcReqIE(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, unsigned long *pFrameLen) -{ - unsigned long TempLen; - unsigned long Len = 0; - u8 ElementID = IE_TPC_REQUEST; - - MakeOutgoingFrame(pFrameBuf, &TempLen, - 1, &ElementID, 1, &Len, END_OF_ARGS); - - *pFrameLen = *pFrameLen + TempLen; - - return; -} - -/* - ========================================================================== - Description: - Insert TPC Report IE into frame. - - Parametrs: - 1. frame buffer pointer. - 2. frame length. - 3. Transmit Power. - 4. Link Margin. - - Return : None. - ========================================================================== - */ -void InsertTpcReportIE(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, - u8 TxPwr, u8 LinkMargin) -{ - unsigned long TempLen; - unsigned long Len = sizeof(struct rt_tpc_report_info); - u8 ElementID = IE_TPC_REPORT; - struct rt_tpc_report_info TpcReportIE; - - TpcReportIE.TxPwr = TxPwr; - TpcReportIE.LinkMargin = LinkMargin; - - MakeOutgoingFrame(pFrameBuf, &TempLen, - 1, &ElementID, - 1, &Len, Len, &TpcReportIE, END_OF_ARGS); - - *pFrameLen = *pFrameLen + TempLen; - - return; -} - -/* - ========================================================================== - Description: - Insert Channel Switch Announcement IE into frame. - - Parametrs: - 1. frame buffer pointer. - 2. frame length. - 3. channel switch announcement mode. - 4. new selected channel. - 5. channel switch announcement count. - - Return : None. - ========================================================================== - */ -static void InsertChSwAnnIE(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, - u8 ChSwMode, - u8 NewChannel, u8 ChSwCnt) -{ - unsigned long TempLen; - unsigned long Len = sizeof(struct rt_ch_sw_ann_info); - u8 ElementID = IE_CHANNEL_SWITCH_ANNOUNCEMENT; - struct rt_ch_sw_ann_info ChSwAnnIE; - - ChSwAnnIE.ChSwMode = ChSwMode; - ChSwAnnIE.Channel = NewChannel; - ChSwAnnIE.ChSwCnt = ChSwCnt; - - MakeOutgoingFrame(pFrameBuf, &TempLen, - 1, &ElementID, 1, &Len, Len, &ChSwAnnIE, END_OF_ARGS); - - *pFrameLen = *pFrameLen + TempLen; - - return; -} - -/* - ========================================================================== - Description: - Insert Measure Request IE into frame. - - Parametrs: - 1. frame buffer pointer. - 2. frame length. - 3. Measure Token. - 4. Measure Request Mode. - 5. Measure Request Type. - 6. Measure Channel. - 7. Measure Start time. - 8. Measure Duration. - - Return : None. - ========================================================================== - */ -static void InsertMeasureReqIE(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, - u8 Len, struct rt_measure_req_info * pMeasureReqIE) -{ - unsigned long TempLen; - u8 ElementID = IE_MEASUREMENT_REQUEST; - - MakeOutgoingFrame(pFrameBuf, &TempLen, - 1, &ElementID, - 1, &Len, - sizeof(struct rt_measure_req_info), pMeasureReqIE, END_OF_ARGS); - - *pFrameLen = *pFrameLen + TempLen; - - return; -} - -/* - ========================================================================== - Description: - Insert Measure Report IE into frame. - - Parametrs: - 1. frame buffer pointer. - 2. frame length. - 3. Measure Token. - 4. Measure Request Mode. - 5. Measure Request Type. - 6. Length of Report Information - 7. Pointer of Report Information Buffer. - - Return : None. - ========================================================================== - */ -static void InsertMeasureReportIE(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, - struct rt_measure_report_info * pMeasureReportIE, - u8 ReportLnfoLen, u8 *pReportInfo) -{ - unsigned long TempLen; - unsigned long Len; - u8 ElementID = IE_MEASUREMENT_REPORT; - - Len = sizeof(struct rt_measure_report_info) + ReportLnfoLen; - - MakeOutgoingFrame(pFrameBuf, &TempLen, - 1, &ElementID, - 1, &Len, Len, pMeasureReportIE, END_OF_ARGS); - - *pFrameLen = *pFrameLen + TempLen; - - if ((ReportLnfoLen > 0) && (pReportInfo != NULL)) { - MakeOutgoingFrame(pFrameBuf + *pFrameLen, &TempLen, - ReportLnfoLen, pReportInfo, END_OF_ARGS); - - *pFrameLen = *pFrameLen + TempLen; - } - return; -} - -/* - ========================================================================== - Description: - Prepare Measurement request action frame and enqueue it into - management queue waiting for transmition. - - Parametrs: - 1. the destination mac address of the frame. - - Return : None. - ========================================================================== - */ -void MakeMeasurementReqFrame(struct rt_rtmp_adapter *pAd, - u8 *pOutBuffer, - unsigned long *pFrameLen, - u8 TotalLen, - u8 Category, - u8 Action, - u8 MeasureToken, - u8 MeasureReqMode, - u8 MeasureReqType, u8 NumOfRepetitions) -{ - unsigned long TempLen; - struct rt_measure_req_info MeasureReqIE; - - InsertActField(pAd, (pOutBuffer + *pFrameLen), pFrameLen, Category, - Action); - - /* fill Dialog Token */ - InsertDialogToken(pAd, (pOutBuffer + *pFrameLen), pFrameLen, - MeasureToken); - - /* fill Number of repetitions. */ - if (Category == CATEGORY_RM) { - MakeOutgoingFrame((pOutBuffer + *pFrameLen), &TempLen, - 2, &NumOfRepetitions, END_OF_ARGS); - - *pFrameLen += TempLen; - } - /* prepare Measurement IE. */ - NdisZeroMemory(&MeasureReqIE, sizeof(struct rt_measure_req_info)); - MeasureReqIE.Token = MeasureToken; - MeasureReqIE.ReqMode.word = MeasureReqMode; - MeasureReqIE.ReqType = MeasureReqType; - InsertMeasureReqIE(pAd, (pOutBuffer + *pFrameLen), pFrameLen, - TotalLen, &MeasureReqIE); - - return; -} - -/* - ========================================================================== - Description: - Prepare Measurement report action frame and enqueue it into - management queue waiting for transmition. - - Parametrs: - 1. the destination mac address of the frame. - - Return : None. - ========================================================================== - */ -void EnqueueMeasurementRep(struct rt_rtmp_adapter *pAd, - u8 *pDA, - u8 DialogToken, - u8 MeasureToken, - u8 MeasureReqMode, - u8 MeasureReqType, - u8 ReportInfoLen, u8 *pReportInfo) -{ - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen; - struct rt_header_802_11 ActHdr; - struct rt_measure_report_info MeasureRepIE; - - /* build action frame header. */ - MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA, - pAd->CurrentAddress); - - NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s() allocate memory failed \n", __func__)); - return; - } - NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11)); - FrameLen = sizeof(struct rt_header_802_11); - - InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, - CATEGORY_SPECTRUM, SPEC_MRP); - - /* fill Dialog Token */ - InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken); - - /* prepare Measurement IE. */ - NdisZeroMemory(&MeasureRepIE, sizeof(struct rt_measure_report_info)); - MeasureRepIE.Token = MeasureToken; - MeasureRepIE.ReportMode = MeasureReqMode; - MeasureRepIE.ReportType = MeasureReqType; - InsertMeasureReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, - &MeasureRepIE, ReportInfoLen, pReportInfo); - - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - return; -} - -/* - ========================================================================== - Description: - Prepare TPC Request action frame and enqueue it into - management queue waiting for transmition. - - Parametrs: - 1. the destination mac address of the frame. - - Return : None. - ========================================================================== - */ -void EnqueueTPCReq(struct rt_rtmp_adapter *pAd, u8 *pDA, u8 DialogToken) -{ - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen; - - struct rt_header_802_11 ActHdr; - - /* build action frame header. */ - MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA, - pAd->CurrentAddress); - - NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s() allocate memory failed \n", __func__)); - return; - } - NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11)); - FrameLen = sizeof(struct rt_header_802_11); - - InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, - CATEGORY_SPECTRUM, SPEC_TPCRQ); - - /* fill Dialog Token */ - InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken); - - /* Insert TPC Request IE. */ - InsertTpcReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen); - - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - return; -} - -/* - ========================================================================== - Description: - Prepare TPC Report action frame and enqueue it into - management queue waiting for transmition. - - Parametrs: - 1. the destination mac address of the frame. - - Return : None. - ========================================================================== - */ -void EnqueueTPCRep(struct rt_rtmp_adapter *pAd, - u8 *pDA, - u8 DialogToken, u8 TxPwr, u8 LinkMargin) -{ - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen; - - struct rt_header_802_11 ActHdr; - - /* build action frame header. */ - MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA, - pAd->CurrentAddress); - - NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s() allocate memory failed \n", __func__)); - return; - } - NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11)); - FrameLen = sizeof(struct rt_header_802_11); - - InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, - CATEGORY_SPECTRUM, SPEC_TPCRP); - - /* fill Dialog Token */ - InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, DialogToken); - - /* Insert TPC Request IE. */ - InsertTpcReportIE(pAd, (pOutBuffer + FrameLen), &FrameLen, TxPwr, - LinkMargin); - - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - return; -} - -/* - ========================================================================== - Description: - Prepare Channel Switch Announcement action frame and enqueue it into - management queue waiting for transmition. - - Parametrs: - 1. the destination mac address of the frame. - 2. Channel switch announcement mode. - 2. a New selected channel. - - Return : None. - ========================================================================== - */ -void EnqueueChSwAnn(struct rt_rtmp_adapter *pAd, - u8 *pDA, u8 ChSwMode, u8 NewCh) -{ - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen; - - struct rt_header_802_11 ActHdr; - - /* build action frame header. */ - MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA, - pAd->CurrentAddress); - - NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s() allocate memory failed \n", __func__)); - return; - } - NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11)); - FrameLen = sizeof(struct rt_header_802_11); - - InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, - CATEGORY_SPECTRUM, SPEC_CHANNEL_SWITCH); - - InsertChSwAnnIE(pAd, (pOutBuffer + FrameLen), &FrameLen, ChSwMode, - NewCh, 0); - - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - return; -} - -static BOOLEAN DfsRequirementCheck(struct rt_rtmp_adapter *pAd, u8 Channel) -{ - BOOLEAN Result = FALSE; - int i; - - do { - /* check DFS procedure is running. */ - /* make sure DFS procedure won't start twice. */ - if (pAd->CommonCfg.RadarDetect.RDMode != RD_NORMAL_MODE) { - Result = FALSE; - break; - } - /* check the new channel carried from Channel Switch Announcemnet is valid. */ - for (i = 0; i < pAd->ChannelListNum; i++) { - if ((Channel == pAd->ChannelList[i].Channel) - && (pAd->ChannelList[i].RemainingTimeForUse == 0)) { - /* found radar signal in the channel. the channel can't use at least for 30 minutes. */ - pAd->ChannelList[i].RemainingTimeForUse = 1800; /*30 min = 1800 sec */ - Result = TRUE; - break; - } - } - } while (FALSE); - - return Result; -} - -void NotifyChSwAnnToPeerAPs(struct rt_rtmp_adapter *pAd, - u8 *pRA, - u8 *pTA, u8 ChSwMode, u8 Channel) -{ -} - -static void StartDFSProcedure(struct rt_rtmp_adapter *pAd, - u8 Channel, u8 ChSwMode) -{ - /* start DFS procedure */ - pAd->CommonCfg.Channel = Channel; - - N_ChannelCheck(pAd); - - pAd->CommonCfg.RadarDetect.RDMode = RD_SWITCHING_MODE; - pAd->CommonCfg.RadarDetect.CSCount = 0; -} - -/* - ========================================================================== - Description: - Channel Switch Announcement action frame sanity check. - - Parametrs: - 1. MLME message containing the received frame - 2. message length. - 3. Channel switch announcement information buffer. - - Return : None. - ========================================================================== - */ - -/* - Channel Switch Announcement IE. - +----+-----+-----------+------------+-----------+ - | ID | Len |Ch Sw Mode | New Ch Num | Ch Sw Cnt | - +----+-----+-----------+------------+-----------+ - 1 1 1 1 1 -*/ -static BOOLEAN PeerChSwAnnSanity(struct rt_rtmp_adapter *pAd, - void * pMsg, - unsigned long MsgLen, - struct rt_ch_sw_ann_info * pChSwAnnInfo) -{ - struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg; - u8 *pFramePtr = Fr->Octet; - BOOLEAN result = FALSE; - struct rt_eid * eid_ptr; - - /* skip 802.11 header. */ - MsgLen -= sizeof(struct rt_header_802_11); - - /* skip category and action code. */ - pFramePtr += 2; - MsgLen -= 2; - - if (pChSwAnnInfo == NULL) - return result; - - eid_ptr = (struct rt_eid *) pFramePtr; - while (((u8 *) eid_ptr + eid_ptr->Len + 1) < - ((u8 *)pFramePtr + MsgLen)) { - switch (eid_ptr->Eid) { - case IE_CHANNEL_SWITCH_ANNOUNCEMENT: - NdisMoveMemory(&pChSwAnnInfo->ChSwMode, eid_ptr->Octet, - 1); - NdisMoveMemory(&pChSwAnnInfo->Channel, - eid_ptr->Octet + 1, 1); - NdisMoveMemory(&pChSwAnnInfo->ChSwCnt, - eid_ptr->Octet + 2, 1); - - result = TRUE; - break; - - default: - break; - } - eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len); - } - - return result; -} - -/* - ========================================================================== - Description: - Measurement request action frame sanity check. - - Parametrs: - 1. MLME message containing the received frame - 2. message length. - 3. Measurement request information buffer. - - Return : None. - ========================================================================== - */ -static BOOLEAN PeerMeasureReqSanity(struct rt_rtmp_adapter *pAd, - void * pMsg, - unsigned long MsgLen, - u8 *pDialogToken, - struct rt_measure_req_info * pMeasureReqInfo, - struct rt_measure_req * pMeasureReq) -{ - struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg; - u8 *pFramePtr = Fr->Octet; - BOOLEAN result = FALSE; - struct rt_eid * eid_ptr; - u8 *ptr; - u64 MeasureStartTime; - u16 MeasureDuration; - - /* skip 802.11 header. */ - MsgLen -= sizeof(struct rt_header_802_11); - - /* skip category and action code. */ - pFramePtr += 2; - MsgLen -= 2; - - if (pMeasureReqInfo == NULL) - return result; - - NdisMoveMemory(pDialogToken, pFramePtr, 1); - pFramePtr += 1; - MsgLen -= 1; - - eid_ptr = (struct rt_eid *) pFramePtr; - while (((u8 *) eid_ptr + eid_ptr->Len + 1) < - ((u8 *)pFramePtr + MsgLen)) { - switch (eid_ptr->Eid) { - case IE_MEASUREMENT_REQUEST: - NdisMoveMemory(&pMeasureReqInfo->Token, eid_ptr->Octet, - 1); - NdisMoveMemory(&pMeasureReqInfo->ReqMode.word, - eid_ptr->Octet + 1, 1); - NdisMoveMemory(&pMeasureReqInfo->ReqType, - eid_ptr->Octet + 2, 1); - ptr = (u8 *)(eid_ptr->Octet + 3); - NdisMoveMemory(&pMeasureReq->ChNum, ptr, 1); - NdisMoveMemory(&MeasureStartTime, ptr + 1, 8); - pMeasureReq->MeasureStartTime = - SWAP64(MeasureStartTime); - NdisMoveMemory(&MeasureDuration, ptr + 9, 2); - pMeasureReq->MeasureDuration = SWAP16(MeasureDuration); - - result = TRUE; - break; - - default: - break; - } - eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len); - } - - return result; -} - -/* - ========================================================================== - Description: - Measurement report action frame sanity check. - - Parametrs: - 1. MLME message containing the received frame - 2. message length. - 3. Measurement report information buffer. - 4. basic report information buffer. - - Return : None. - ========================================================================== - */ - -/* - Measurement Report IE. - +----+-----+-------+-------------+--------------+----------------+ - | ID | Len | Token | Report Mode | Measure Type | Measure Report | - +----+-----+-------+-------------+--------------+----------------+ - 1 1 1 1 1 variable - - Basic Report. - +--------+------------+----------+-----+ - | Ch Num | Start Time | Duration | Map | - +--------+------------+----------+-----+ - 1 8 2 1 - - Map Field Bit Format. - +-----+---------------+---------------------+-------+------------+----------+ - | Bss | OFDM Preamble | Unidentified signal | Radar | Unmeasured | Reserved | - +-----+---------------+---------------------+-------+------------+----------+ - 0 1 2 3 4 5-7 -*/ -static BOOLEAN PeerMeasureReportSanity(struct rt_rtmp_adapter *pAd, - void * pMsg, - unsigned long MsgLen, - u8 *pDialogToken, - struct rt_measure_report_info * - pMeasureReportInfo, - u8 *pReportBuf) -{ - struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg; - u8 *pFramePtr = Fr->Octet; - BOOLEAN result = FALSE; - struct rt_eid * eid_ptr; - u8 *ptr; - - /* skip 802.11 header. */ - MsgLen -= sizeof(struct rt_header_802_11); - - /* skip category and action code. */ - pFramePtr += 2; - MsgLen -= 2; - - if (pMeasureReportInfo == NULL) - return result; - - NdisMoveMemory(pDialogToken, pFramePtr, 1); - pFramePtr += 1; - MsgLen -= 1; - - eid_ptr = (struct rt_eid *) pFramePtr; - while (((u8 *) eid_ptr + eid_ptr->Len + 1) < - ((u8 *)pFramePtr + MsgLen)) { - switch (eid_ptr->Eid) { - case IE_MEASUREMENT_REPORT: - NdisMoveMemory(&pMeasureReportInfo->Token, - eid_ptr->Octet, 1); - NdisMoveMemory(&pMeasureReportInfo->ReportMode, - eid_ptr->Octet + 1, 1); - NdisMoveMemory(&pMeasureReportInfo->ReportType, - eid_ptr->Octet + 2, 1); - if (pMeasureReportInfo->ReportType == RM_BASIC) { - struct rt_measure_basic_report * pReport = - (struct rt_measure_basic_report *) pReportBuf; - ptr = (u8 *)(eid_ptr->Octet + 3); - NdisMoveMemory(&pReport->ChNum, ptr, 1); - NdisMoveMemory(&pReport->MeasureStartTime, - ptr + 1, 8); - NdisMoveMemory(&pReport->MeasureDuration, - ptr + 9, 2); - NdisMoveMemory(&pReport->Map, ptr + 11, 1); - - } else if (pMeasureReportInfo->ReportType == RM_CCA) { - struct rt_measure_cca_report * pReport = - (struct rt_measure_cca_report *) pReportBuf; - ptr = (u8 *)(eid_ptr->Octet + 3); - NdisMoveMemory(&pReport->ChNum, ptr, 1); - NdisMoveMemory(&pReport->MeasureStartTime, - ptr + 1, 8); - NdisMoveMemory(&pReport->MeasureDuration, - ptr + 9, 2); - NdisMoveMemory(&pReport->CCA_Busy_Fraction, - ptr + 11, 1); - - } else if (pMeasureReportInfo->ReportType == - RM_RPI_HISTOGRAM) { - struct rt_measure_rpi_report * pReport = - (struct rt_measure_rpi_report *) pReportBuf; - ptr = (u8 *)(eid_ptr->Octet + 3); - NdisMoveMemory(&pReport->ChNum, ptr, 1); - NdisMoveMemory(&pReport->MeasureStartTime, - ptr + 1, 8); - NdisMoveMemory(&pReport->MeasureDuration, - ptr + 9, 2); - NdisMoveMemory(&pReport->RPI_Density, ptr + 11, - 8); - } - result = TRUE; - break; - - default: - break; - } - eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len); - } - - return result; -} - -/* - ========================================================================== - Description: - TPC Request action frame sanity check. - - Parametrs: - 1. MLME message containing the received frame - 2. message length. - 3. Dialog Token. - - Return : None. - ========================================================================== - */ -static BOOLEAN PeerTpcReqSanity(struct rt_rtmp_adapter *pAd, - void * pMsg, - unsigned long MsgLen, u8 *pDialogToken) -{ - struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg; - u8 *pFramePtr = Fr->Octet; - BOOLEAN result = FALSE; - struct rt_eid * eid_ptr; - - MsgLen -= sizeof(struct rt_header_802_11); - - /* skip category and action code. */ - pFramePtr += 2; - MsgLen -= 2; - - if (pDialogToken == NULL) - return result; - - NdisMoveMemory(pDialogToken, pFramePtr, 1); - pFramePtr += 1; - MsgLen -= 1; - - eid_ptr = (struct rt_eid *) pFramePtr; - while (((u8 *) eid_ptr + eid_ptr->Len + 1) < - ((u8 *)pFramePtr + MsgLen)) { - switch (eid_ptr->Eid) { - case IE_TPC_REQUEST: - result = TRUE; - break; - - default: - break; - } - eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len); - } - - return result; -} - -/* - ========================================================================== - Description: - TPC Report action frame sanity check. - - Parametrs: - 1. MLME message containing the received frame - 2. message length. - 3. Dialog Token. - 4. TPC Report IE. - - Return : None. - ========================================================================== - */ -static BOOLEAN PeerTpcRepSanity(struct rt_rtmp_adapter *pAd, - void * pMsg, - unsigned long MsgLen, - u8 *pDialogToken, - struct rt_tpc_report_info * pTpcRepInfo) -{ - struct rt_frame_802_11 * Fr = (struct rt_frame_802_11 *) pMsg; - u8 *pFramePtr = Fr->Octet; - BOOLEAN result = FALSE; - struct rt_eid * eid_ptr; - - MsgLen -= sizeof(struct rt_header_802_11); - - /* skip category and action code. */ - pFramePtr += 2; - MsgLen -= 2; - - if (pDialogToken == NULL) - return result; - - NdisMoveMemory(pDialogToken, pFramePtr, 1); - pFramePtr += 1; - MsgLen -= 1; - - eid_ptr = (struct rt_eid *) pFramePtr; - while (((u8 *) eid_ptr + eid_ptr->Len + 1) < - ((u8 *)pFramePtr + MsgLen)) { - switch (eid_ptr->Eid) { - case IE_TPC_REPORT: - NdisMoveMemory(&pTpcRepInfo->TxPwr, eid_ptr->Octet, 1); - NdisMoveMemory(&pTpcRepInfo->LinkMargin, - eid_ptr->Octet + 1, 1); - result = TRUE; - break; - - default: - break; - } - eid_ptr = (struct rt_eid *) ((u8 *) eid_ptr + 2 + eid_ptr->Len); - } - - return result; -} - -/* - ========================================================================== - Description: - Channel Switch Announcement action frame handler. - - Parametrs: - Elme - MLME message containing the received frame - - Return : None. - ========================================================================== - */ -static void PeerChSwAnnAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_ch_sw_ann_info ChSwAnnInfo; - struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg; - u8 index = 0, Channel = 0, NewChannel = 0; - unsigned long Bssidx = 0; - - NdisZeroMemory(&ChSwAnnInfo, sizeof(struct rt_ch_sw_ann_info)); - if (!PeerChSwAnnSanity(pAd, Elem->Msg, Elem->MsgLen, &ChSwAnnInfo)) { - DBGPRINT(RT_DEBUG_TRACE, - ("Invalid Channel Switch Action Frame.\n")); - return; - } - - if (pAd->OpMode == OPMODE_STA) { - Bssidx = - BssTableSearch(&pAd->ScanTab, pFr->Hdr.Addr3, - pAd->CommonCfg.Channel); - if (Bssidx == BSS_NOT_FOUND) { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerChSwAnnAction - Bssidx is not found\n")); - return; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("\n****Bssidx is %d, Channel = %d\n", index, - pAd->ScanTab.BssEntry[Bssidx].Channel)); - hex_dump("SSID", pAd->ScanTab.BssEntry[Bssidx].Bssid, 6); - - Channel = pAd->CommonCfg.Channel; - NewChannel = ChSwAnnInfo.Channel; - - if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0) - && (Channel != NewChannel)) { - /* Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection). */ - /* In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results. */ - AsicSwitchChannel(pAd, 1, FALSE); - AsicLockChannel(pAd, 1); - LinkDown(pAd, FALSE); - MlmeQueueInit(&pAd->Mlme.Queue); - BssTableInit(&pAd->ScanTab); - RTMPusecDelay(1000000); /* use delay to prevent STA do reassoc */ - - /* channel sanity check */ - for (index = 0; index < pAd->ChannelListNum; index++) { - if (pAd->ChannelList[index].Channel == - NewChannel) { - pAd->ScanTab.BssEntry[Bssidx].Channel = - NewChannel; - pAd->CommonCfg.Channel = NewChannel; - AsicSwitchChannel(pAd, - pAd->CommonCfg. - Channel, FALSE); - AsicLockChannel(pAd, - pAd->CommonCfg.Channel); - DBGPRINT(RT_DEBUG_TRACE, - ("&&&&&&&&&&&&&&&&PeerChSwAnnAction - STA receive channel switch announcement IE (New Channel =%d)\n", - NewChannel)); - break; - } - } - - if (index >= pAd->ChannelListNum) { - DBGPRINT_ERR("&&&&&&&&&&&&&&&&&&&&&&&&&&PeerChSwAnnAction(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum); - } - } - } - - return; -} - -/* - ========================================================================== - Description: - Measurement Request action frame handler. - - Parametrs: - Elme - MLME message containing the received frame - - Return : None. - ========================================================================== - */ -static void PeerMeasureReqAction(struct rt_rtmp_adapter *pAd, - struct rt_mlme_queue_elem *Elem) -{ - struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg; - u8 DialogToken; - struct rt_measure_req_info MeasureReqInfo; - struct rt_measure_req MeasureReq; - MEASURE_REPORT_MODE ReportMode; - - if (PeerMeasureReqSanity - (pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReqInfo, - &MeasureReq)) { - ReportMode.word = 0; - ReportMode.field.Incapable = 1; - EnqueueMeasurementRep(pAd, pFr->Hdr.Addr2, DialogToken, - MeasureReqInfo.Token, ReportMode.word, - MeasureReqInfo.ReqType, 0, NULL); - } - - return; -} - -/* - ========================================================================== - Description: - Measurement Report action frame handler. - - Parametrs: - Elme - MLME message containing the received frame - - Return : None. - ========================================================================== - */ -static void PeerMeasureReportAction(struct rt_rtmp_adapter *pAd, - struct rt_mlme_queue_elem *Elem) -{ - struct rt_measure_report_info MeasureReportInfo; - struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg; - u8 DialogToken; - u8 *pMeasureReportInfo; - -/* if (pAd->CommonCfg.bIEEE80211H != TRUE) */ -/* return; */ - - pMeasureReportInfo = kmalloc(sizeof(struct rt_measure_rpi_report), GFP_ATOMIC); - if (pMeasureReportInfo == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s unable to alloc memory for measure report buffer (size=%zu).\n", - __func__, sizeof(struct rt_measure_rpi_report))); - return; - } - - NdisZeroMemory(&MeasureReportInfo, sizeof(struct rt_measure_report_info)); - NdisZeroMemory(pMeasureReportInfo, sizeof(struct rt_measure_rpi_report)); - if (PeerMeasureReportSanity - (pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &MeasureReportInfo, - pMeasureReportInfo)) { - do { - struct rt_measure_req_entry *pEntry = NULL; - - /* Not a autonomous measure report. */ - /* check the dialog token field. drop it if the dialog token doesn't match. */ - if ((DialogToken != 0) - && ((pEntry = MeasureReqLookUp(pAd, DialogToken)) == - NULL)) - break; - - if (pEntry != NULL) - MeasureReqDelete(pAd, pEntry->DialogToken); - - if (MeasureReportInfo.ReportType == RM_BASIC) { - struct rt_measure_basic_report * pBasicReport = - (struct rt_measure_basic_report *) pMeasureReportInfo; - if ((pBasicReport->Map.field.Radar) - && - (DfsRequirementCheck - (pAd, pBasicReport->ChNum) == TRUE)) { - NotifyChSwAnnToPeerAPs(pAd, - pFr->Hdr.Addr1, - pFr->Hdr.Addr2, - 1, - pBasicReport-> - ChNum); - StartDFSProcedure(pAd, - pBasicReport->ChNum, - 1); - } - } - } while (FALSE); - } else - DBGPRINT(RT_DEBUG_TRACE, - ("Invalid Measurement Report Frame.\n")); - - kfree(pMeasureReportInfo); - - return; -} - -/* - ========================================================================== - Description: - TPC Request action frame handler. - - Parametrs: - Elme - MLME message containing the received frame - - Return : None. - ========================================================================== - */ -static void PeerTpcReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_frame_802_11 * pFr = (struct rt_frame_802_11 *) Elem->Msg; - u8 *pFramePtr = pFr->Octet; - u8 DialogToken; - u8 TxPwr = GetCurTxPwr(pAd, Elem->Wcid); - u8 LinkMargin = 0; - char RealRssi; - - /* link margin: Ratio of the received signal power to the minimum desired by the station (STA). The */ - /* STA may incorporate rate information and channel conditions, including interference, into its computation */ - /* of link margin. */ - - RealRssi = RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), - ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), - ConvertToRssi(pAd, Elem->Rssi2, RSSI_2)); - - /* skip Category and action code. */ - pFramePtr += 2; - - /* Dialog token. */ - NdisMoveMemory(&DialogToken, pFramePtr, 1); - - LinkMargin = (RealRssi / MIN_RCV_PWR); - if (PeerTpcReqSanity(pAd, Elem->Msg, Elem->MsgLen, &DialogToken)) - EnqueueTPCRep(pAd, pFr->Hdr.Addr2, DialogToken, TxPwr, - LinkMargin); - - return; -} - -/* - ========================================================================== - Description: - TPC Report action frame handler. - - Parametrs: - Elme - MLME message containing the received frame - - Return : None. - ========================================================================== - */ -static void PeerTpcRepAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 DialogToken; - struct rt_tpc_report_info TpcRepInfo; - struct rt_tpc_req_entry *pEntry = NULL; - - NdisZeroMemory(&TpcRepInfo, sizeof(struct rt_tpc_report_info)); - if (PeerTpcRepSanity - (pAd, Elem->Msg, Elem->MsgLen, &DialogToken, &TpcRepInfo)) { - pEntry = TpcReqLookUp(pAd, DialogToken); - if (pEntry != NULL) { - TpcReqDelete(pAd, pEntry->DialogToken); - DBGPRINT(RT_DEBUG_TRACE, - ("%s: DialogToken=%x, TxPwr=%d, LinkMargin=%d\n", - __func__, DialogToken, TpcRepInfo.TxPwr, - TpcRepInfo.LinkMargin)); - } - } - - return; -} - -/* - ========================================================================== - Description: - Spectrun action frames Handler such as channel switch annoucement, - measurement report, measurement request actions frames. - - Parametrs: - Elme - MLME message containing the received frame - - Return : None. - ========================================================================== - */ -void PeerSpectrumAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - - u8 Action = Elem->Msg[LENGTH_802_11 + 1]; - - if (pAd->CommonCfg.bIEEE80211H != TRUE) - return; - - switch (Action) { - case SPEC_MRQ: - /* current rt2860 unable do such measure specified in Measurement Request. */ - /* reject all measurement request. */ - PeerMeasureReqAction(pAd, Elem); - break; - - case SPEC_MRP: - PeerMeasureReportAction(pAd, Elem); - break; - - case SPEC_TPCRQ: - PeerTpcReqAction(pAd, Elem); - break; - - case SPEC_TPCRP: - PeerTpcRepAction(pAd, Elem); - break; - - case SPEC_CHANNEL_SWITCH: - - PeerChSwAnnAction(pAd, Elem); - break; - } - - return; -} - -/* - ========================================================================== - Description: - - Parametrs: - - Return : None. - ========================================================================== - */ -int Set_MeasureReq_Proc(struct rt_rtmp_adapter *pAd, char *arg) -{ - u32 Aid = 1; - u32 ArgIdx; - char *thisChar; - - MEASURE_REQ_MODE MeasureReqMode; - u8 MeasureReqToken = RandomByte(pAd); - u8 MeasureReqType = RM_BASIC; - u8 MeasureCh = 1; - u64 MeasureStartTime = GetCurrentTimeStamp(pAd); - struct rt_measure_req MeasureReq; - u8 TotalLen; - - struct rt_header_802_11 ActHdr; - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen; - - NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s() allocate memory failed \n", __func__)); - goto END_OF_MEASURE_REQ; - } - - ArgIdx = 1; - while ((thisChar = strsep((char **)&arg, "-")) != NULL) { - switch (ArgIdx) { - case 1: /* Aid. */ - Aid = (u8)simple_strtol(thisChar, 0, 16); - break; - - case 2: /* Measurement Request Type. */ - MeasureReqType = simple_strtol(thisChar, 0, 16); - if (MeasureReqType > 3) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: unknow MeasureReqType(%d)\n", - __func__, MeasureReqType)); - goto END_OF_MEASURE_REQ; - } - break; - - case 3: /* Measurement channel. */ - MeasureCh = (u8)simple_strtol(thisChar, 0, 16); - break; - } - ArgIdx++; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("%s::Aid = %d, MeasureReqType=%d MeasureCh=%d\n", __func__, - Aid, MeasureReqType, MeasureCh)); - if (!VALID_WCID(Aid)) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: unknow sta of Aid(%d)\n", __func__, Aid)); - goto END_OF_MEASURE_REQ; - } - - MeasureReqMode.word = 0; - MeasureReqMode.field.Enable = 1; - - MeasureReqInsert(pAd, MeasureReqToken); - - /* build action frame header. */ - MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, - pAd->MacTab.Content[Aid].Addr, pAd->CurrentAddress); - - NdisMoveMemory(pOutBuffer, (char *)& ActHdr, sizeof(struct rt_header_802_11)); - FrameLen = sizeof(struct rt_header_802_11); - - TotalLen = sizeof(struct rt_measure_req_info) + sizeof(struct rt_measure_req); - - MakeMeasurementReqFrame(pAd, pOutBuffer, &FrameLen, - sizeof(struct rt_measure_req_info), CATEGORY_RM, RM_BASIC, - MeasureReqToken, MeasureReqMode.word, - MeasureReqType, 0); - - MeasureReq.ChNum = MeasureCh; - MeasureReq.MeasureStartTime = cpu2le64(MeasureStartTime); - MeasureReq.MeasureDuration = cpu2le16(2000); - - { - unsigned long TempLen; - MakeOutgoingFrame(pOutBuffer + FrameLen, &TempLen, - sizeof(struct rt_measure_req), &MeasureReq, - END_OF_ARGS); - FrameLen += TempLen; - } - - MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, (u32)FrameLen); - -END_OF_MEASURE_REQ: - MlmeFreeMemory(pAd, pOutBuffer); - - return TRUE; -} - -int Set_TpcReq_Proc(struct rt_rtmp_adapter *pAd, char *arg) -{ - u32 Aid; - - u8 TpcReqToken = RandomByte(pAd); - - Aid = (u32)simple_strtol(arg, 0, 16); - - DBGPRINT(RT_DEBUG_TRACE, ("%s::Aid = %d\n", __func__, Aid)); - if (!VALID_WCID(Aid)) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s: unknow sta of Aid(%d)\n", __func__, Aid)); - return TRUE; - } - - TpcReqInsert(pAd, TpcReqToken); - - EnqueueTPCReq(pAd, pAd->MacTab.Content[Aid].Addr, TpcReqToken); - - return TRUE; -} diff --git a/trunk/drivers/staging/rt2860/crypt_hmac.h b/trunk/drivers/staging/rt2860/crypt_hmac.h deleted file mode 100644 index 7a56515d7266..000000000000 --- a/trunk/drivers/staging/rt2860/crypt_hmac.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - */ - -/**************************************************************************** - Module Name: - HMAC - - Abstract: - FIPS 198: The Keyed-Hash Message Authentication Code (HMAC) - - Revision History: - Who When What - -------- ---------- ------------------------------------------ - Eddy 2008/11/24 Create HMAC-SHA1, HMAC-SHA256 -***************************************************************************/ -#ifndef __CRYPT_HMAC_H__ -#define __CRYPT_HMAC_H__ - -#ifdef CRYPT_TESTPLAN -#include "crypt_testplan.h" -#else -#include "rt_config.h" -#endif /* CRYPT_TESTPLAN */ - -#ifdef SHA1_SUPPORT -#define HMAC_SHA1_SUPPORT -void HMAC_SHA1(IN const u8 Key[], - u32 KeyLen, - IN const u8 Message[], - u32 MessageLen, u8 MAC[], u32 MACLen); -#endif /* SHA1_SUPPORT */ - -#ifdef MD5_SUPPORT -#define HMAC_MD5_SUPPORT -void HMAC_MD5(IN const u8 Key[], - u32 KeyLen, - IN const u8 Message[], - u32 MessageLen, u8 MAC[], u32 MACLen); -#endif /* MD5_SUPPORT */ - -#endif /* __CRYPT_HMAC_H__ */ diff --git a/trunk/drivers/staging/rt2860/crypt_md5.h b/trunk/drivers/staging/rt2860/crypt_md5.h deleted file mode 100644 index 26f974554b26..000000000000 --- a/trunk/drivers/staging/rt2860/crypt_md5.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - */ - -/**************************************************************************** - Module Name: - MD5 - - Abstract: - RFC1321: The MD5 Message-Digest Algorithm - - Revision History: - Who When What - -------- ---------- ------------------------------------------ - Eddy 2008/11/24 Create md5 -***************************************************************************/ - -#ifndef __CRYPT_MD5_H__ -#define __CRYPT_MD5_H__ - -#ifdef CRYPT_TESTPLAN -#include "crypt_testplan.h" -#else -#include "rt_config.h" -#endif /* CRYPT_TESTPLAN */ - -/* Algorithm options */ -#define MD5_SUPPORT - -#ifdef MD5_SUPPORT -#define MD5_BLOCK_SIZE 64 /* 512 bits = 64 bytes */ -#define MD5_DIGEST_SIZE 16 /* 128 bits = 16 bytes */ - -struct rt_md5_ctx_struc { - u32 HashValue[4]; - u64 MessageLen; - u8 Block[MD5_BLOCK_SIZE]; - u32 BlockLen; -}; - -void MD5_Init(struct rt_md5_ctx_struc *pMD5_CTX); -void MD5_Hash(struct rt_md5_ctx_struc *pMD5_CTX); -void MD5_Append(struct rt_md5_ctx_struc *pMD5_CTX, - IN const u8 Message[], u32 MessageLen); -void MD5_End(struct rt_md5_ctx_struc *pMD5_CTX, u8 DigestMessage[]); -void RT_MD5(IN const u8 Message[], - u32 MessageLen, u8 DigestMessage[]); -#endif /* MD5_SUPPORT */ - -#endif /* __CRYPT_MD5_H__ */ diff --git a/trunk/drivers/staging/rt2860/crypt_sha2.h b/trunk/drivers/staging/rt2860/crypt_sha2.h deleted file mode 100644 index 20d11ab865c1..000000000000 --- a/trunk/drivers/staging/rt2860/crypt_sha2.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - */ - -/**************************************************************************** - Module Name: - SHA2 - - Abstract: - FIPS 180-2: Secure Hash Standard (SHS) - - Revision History: - Who When What - -------- ---------- ------------------------------------------ - Eddy 2008/11/24 Create SHA1 - Eddy 2008/07/23 Create SHA256 -***************************************************************************/ - -#ifndef __CRYPT_SHA2_H__ -#define __CRYPT_SHA2_H__ - -#ifdef CRYPT_TESTPLAN -#include "crypt_testplan.h" -#else -#include "rt_config.h" -#endif /* CRYPT_TESTPLAN */ - -/* Algorithm options */ -#define SHA1_SUPPORT - -#ifdef SHA1_SUPPORT -#define SHA1_BLOCK_SIZE 64 /* 512 bits = 64 bytes */ -#define SHA1_DIGEST_SIZE 20 /* 160 bits = 20 bytes */ -struct rt_sha1_ctx { - u32 HashValue[5]; /* 5 = (SHA1_DIGEST_SIZE / 32) */ - u64 MessageLen; /* total size */ - u8 Block[SHA1_BLOCK_SIZE]; - u32 BlockLen; -}; - -void RT_SHA1_Init(struct rt_sha1_ctx *pSHA_CTX); -void SHA1_Hash(struct rt_sha1_ctx *pSHA_CTX); -void SHA1_Append(struct rt_sha1_ctx *pSHA_CTX, - IN const u8 Message[], u32 MessageLen); -void SHA1_End(struct rt_sha1_ctx *pSHA_CTX, u8 DigestMessage[]); -void RT_SHA1(IN const u8 Message[], - u32 MessageLen, u8 DigestMessage[]); -#endif /* SHA1_SUPPORT */ - -#endif /* __CRYPT_SHA2_H__ */ diff --git a/trunk/drivers/staging/rt2860/dfs.h b/trunk/drivers/staging/rt2860/dfs.h deleted file mode 100644 index 5fbab259acae..000000000000 --- a/trunk/drivers/staging/rt2860/dfs.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - dfs.h - - Abstract: - Support DFS function. - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Fonchi 03-12-2007 created -*/ - -BOOLEAN RadarChannelCheck(struct rt_rtmp_adapter *pAd, u8 Ch); diff --git a/trunk/drivers/staging/rt2860/eeprom.h b/trunk/drivers/staging/rt2860/eeprom.h deleted file mode 100644 index 72c8fb941655..000000000000 --- a/trunk/drivers/staging/rt2860/eeprom.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - eeprom.h - - Abstract: - Miniport header file for eeprom related information - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ -#ifndef __EEPROM_H__ -#define __EEPROM_H__ - -#ifdef RTMP_PCI_SUPPORT -/************************************************************************* - * Public function declarations for prom-based chipset - ************************************************************************/ -int rtmp_ee_prom_read16(struct rt_rtmp_adapter *pAd, - u16 Offset, u16 *pValue); -#endif /* RTMP_PCI_SUPPORT // */ -#ifdef RTMP_USB_SUPPORT -/************************************************************************* - * Public function declarations for usb-based prom chipset - ************************************************************************/ -int RTUSBReadEEPROM16(struct rt_rtmp_adapter *pAd, - u16 offset, u16 *pData); -#endif /* RTMP_USB_SUPPORT // */ - -#ifdef RT30xx -#ifdef RTMP_EFUSE_SUPPORT -int rtmp_ee_efuse_read16(struct rt_rtmp_adapter *pAd, - u16 Offset, u16 *pValue); -#endif /* RTMP_EFUSE_SUPPORT // */ -#endif /* RT30xx // */ - -/************************************************************************* - * Public function declarations for prom operation callback functions setting - ************************************************************************/ -int RtmpChipOpsEepromHook(struct rt_rtmp_adapter *pAd, int infType); - -#endif /* __EEPROM_H__ // */ diff --git a/trunk/drivers/staging/rt2860/iface/rtmp_pci.h b/trunk/drivers/staging/rt2860/iface/rtmp_pci.h deleted file mode 100644 index 3d66e386bd8a..000000000000 --- a/trunk/drivers/staging/rt2860/iface/rtmp_pci.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* -*/ - -#ifndef __RTMP_PCI_H__ -#define __RTMP_PCI_H__ - -#define RT28XX_HANDLE_DEV_ASSIGN(handle, dev_p) \ - ((struct os_cookie *)handle)->pci_dev = dev_p; - -#ifdef LINUX -/* set driver data */ -#define RT28XX_DRVDATA_SET(_a) pci_set_drvdata(_a, net_dev); - -#define RT28XX_PUT_DEVICE(dev_p) - -#define SA_SHIRQ IRQF_SHARED - -#ifdef PCI_MSI_SUPPORT -#define RTMP_MSI_ENABLE(_pAd) \ - { struct os_cookie *_pObj = (struct os_cookie *)(_pAd->OS_Cookie); \ - (_pAd)->HaveMsi = pci_enable_msi(_pObj->pci_dev) \ - == 0 ? TRUE : FALSE; \ - } - -#define RTMP_MSI_DISABLE(_pAd) \ - { struct os_cookie *_pObj = (struct os_cookie *)(_pAd->OS_Cookie); \ - if (_pAd->HaveMsi == TRUE) \ - pci_disable_msi(_pObj->pci_dev); \ - _pAd->HaveMsi = FALSE; \ - } -#else -#define RTMP_MSI_ENABLE(_pAd) do {} while (0) -#define RTMP_MSI_DISABLE(_pAd) do {} while (0) -#endif /* PCI_MSI_SUPPORT */ - -#define RTMP_PCI_DEV_UNMAP() \ -{ if (net_dev->base_addr) { \ - iounmap((void *)(net_dev->base_addr)); \ - release_mem_region(pci_resource_start(dev_p, 0), \ - pci_resource_len(dev_p, 0)); } \ - if (net_dev->irq) \ - pci_release_regions(dev_p); } - -#define PCI_REG_READ_WORD(pci_dev, offset, Configuration) {\ - if (pci_read_config_word(pci_dev, offset, ®16) == 0) \ - Configuration = le2cpu16(reg16); \ - else \ - Configuration = 0; } - -#define PCI_REG_WIRTE_WORD(pci_dev, offset, Configuration) {\ - reg16 = cpu2le16(Configuration); \ - pci_write_config_word(pci_dev, offset, reg16); } - -#endif /* LINUX */ - -#endif /* __RTMP_PCI_H__ */ diff --git a/trunk/drivers/staging/rt2860/iface/rtmp_usb.h b/trunk/drivers/staging/rt2860/iface/rtmp_usb.h deleted file mode 100644 index 571289637973..000000000000 --- a/trunk/drivers/staging/rt2860/iface/rtmp_usb.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* -*/ - -#ifndef __RTMP_USB_H__ -#define __RTMP_USB_H__ - -#include "../rtusb_io.h" - -#ifdef LINUX -#include -#endif /* LINUX */ - -extern u8 EpToQueue[6]; - -#define RXBULKAGGRE_ZISE 12 -#define MAX_TXBULK_LIMIT (LOCAL_TXBUF_SIZE*(BULKAGGRE_ZISE-1)) -#define MAX_TXBULK_SIZE (LOCAL_TXBUF_SIZE*BULKAGGRE_ZISE) -#define MAX_RXBULK_SIZE (LOCAL_TXBUF_SIZE*RXBULKAGGRE_ZISE) -#define MAX_MLME_HANDLER_MEMORY 20 - -/* Flags for Bulkflags control for bulk out data */ -#define fRTUSB_BULK_OUT_DATA_NULL 0x00000001 -#define fRTUSB_BULK_OUT_RTS 0x00000002 -#define fRTUSB_BULK_OUT_MLME 0x00000004 - -#define fRTUSB_BULK_OUT_PSPOLL 0x00000010 -#define fRTUSB_BULK_OUT_DATA_FRAG 0x00000020 -#define fRTUSB_BULK_OUT_DATA_FRAG_2 0x00000040 -#define fRTUSB_BULK_OUT_DATA_FRAG_3 0x00000080 -#define fRTUSB_BULK_OUT_DATA_FRAG_4 0x00000100 - -#define fRTUSB_BULK_OUT_DATA_NORMAL 0x00010000 -#define fRTUSB_BULK_OUT_DATA_NORMAL_2 0x00020000 -#define fRTUSB_BULK_OUT_DATA_NORMAL_3 0x00040000 -#define fRTUSB_BULK_OUT_DATA_NORMAL_4 0x00080000 - -/* TODO:move to ./ate/include/iface/ate_usb.h */ - -#define FREE_HTTX_RING(_pCookie, _pipeId, _txContext) \ -{ \ - if ((_txContext)->ENextBulkOutPosition == \ - (_txContext)->CurWritePosition) {\ - (_txContext)->bRingEmpty = TRUE; \ - } \ - /*NdisInterlockedDecrement(&(_p)->TxCount); */\ -} - -/****************************************************************************** - - USB Bulk operation related definitions - -******************************************************************************/ - -#ifdef LINUX -#define BULKAGGRE_ZISE 100 -#define RT28XX_PUT_DEVICE usb_put_dev -#define RTUSB_ALLOC_URB(iso) usb_alloc_urb(iso, GFP_ATOMIC) -#define RTUSB_SUBMIT_URB(pUrb) usb_submit_urb(pUrb, \ - GFP_ATOMIC) -#define RTUSB_URB_ALLOC_BUFFER(pUsb_Dev, \ - BufSize, \ - pDma_addr) \ - usb_alloc_coherent(\ - pUsb_Dev, \ - BufSize, \ - GFP_ATOMIC, \ - pDma_addr) -#define RTUSB_URB_FREE_BUFFER(pUsb_Dev, \ - BufSize, \ - pTransferBuf, \ - Dma_addr) \ - usb_free_coherent( \ - pUsb_Dev, \ - BufSize, \ - pTransferBuf, \ - Dma_addr) - -#define RTUSB_FREE_URB(pUrb) usb_free_urb(pUrb) - -/* unlink urb */ -#define RTUSB_UNLINK_URB(pUrb) usb_kill_urb(pUrb) - -extern void dump_urb(struct urb *purb); - -#define InterlockedIncrement atomic_inc -#define NdisInterlockedIncrement atomic_inc -#define InterlockedDecrement atomic_dec -#define NdisInterlockedDecrement atomic_dec -#define InterlockedExchange atomic_set - -#endif /* LINUX */ - -#define NT_SUCCESS(status) (((status) >= 0) ? (TRUE) : (FALSE)) - -#define USBD_TRANSFER_DIRECTION_OUT 0 -#define USBD_TRANSFER_DIRECTION_IN 0 -#define USBD_SHORT_TRANSFER_OK 0 -#define PURB struct urb * - -#define PIRP void * -#define NDIS_OID u32 -#ifndef USB_ST_NOERROR -#define USB_ST_NOERROR 0 -#endif - -/* vendor-specific control operations */ -#define CONTROL_TIMEOUT_JIFFIES ((100 * OS_HZ) / 1000) -#define UNLINK_TIMEOUT_MS 3 - -void RTUSBBulkOutDataPacketComplete(struct urb *purb, struct pt_regs *pt_regs); -void RTUSBBulkOutMLMEPacketComplete(struct urb *pUrb, struct pt_regs *pt_regs); -void RTUSBBulkOutNullFrameComplete(struct urb *pUrb, struct pt_regs *pt_regs); -void RTUSBBulkOutRTSFrameComplete(struct urb *pUrb, struct pt_regs *pt_regs); -void RTUSBBulkOutPsPollComplete(struct urb *pUrb, struct pt_regs *pt_regs); -void RTUSBBulkRxComplete(struct urb *pUrb, struct pt_regs *pt_regs); - -#ifdef KTHREAD_SUPPORT -#define RTUSBMlmeUp(pAd) \ - do { \ - struct rt_rtmp_os_task *_pTask = &((pAd)->mlmeTask);\ - if (_pTask->kthread_task) {\ - _pTask->kthread_running = TRUE; \ - wake_up(&_pTask->kthread_q); \ - } \ - } while (0) -#else -#define RTUSBMlmeUp(pAd) \ - do { \ - struct rt_rtmp_os_task *_pTask = &((pAd)->mlmeTask);\ - CHECK_PID_LEGALITY(_pTask->taskPID) \ - { \ - RTMP_SEM_EVENT_UP(&(_pTask->taskSema)); \ - } \ - } while (0) -#endif - -#ifdef KTHREAD_SUPPORT -#define RTUSBCMDUp(pAd) \ - do { \ - struct rt_rtmp_os_task *_pTask = &((pAd)->cmdQTask); \ - { \ - _pTask->kthread_running = TRUE; \ - wake_up(&_pTask->kthread_q); \ - } \ - } while (0) - -#else -#define RTUSBCMDUp(pAd) \ - do { \ - struct rt_rtmp_os_task *_pTask = &((pAd)->cmdQTask); \ - CHECK_PID_LEGALITY(_pTask->taskPID) \ - {\ - RTMP_SEM_EVENT_UP(&(_pTask->taskSema)); \ - } \ - } while (0) -#endif - -#define DEVICE_VENDOR_REQUEST_OUT 0x40 -#define DEVICE_VENDOR_REQUEST_IN 0xc0 -/*#define INTERFACE_VENDOR_REQUEST_OUT 0x41*/ -/*#define INTERFACE_VENDOR_REQUEST_IN 0xc1*/ - -#define BULKOUT_MGMT_RESET_FLAG 0x80 - -#define RTUSB_SET_BULK_FLAG(_M, _F) ((_M)->BulkFlags |= (_F)) -#define RTUSB_CLEAR_BULK_FLAG(_M, _F) ((_M)->BulkFlags &= ~(_F)) -#define RTUSB_TEST_BULK_FLAG(_M, _F) (((_M)->BulkFlags & (_F)) != 0) - -#define RTMP_IRQ_REQUEST(net_dev) do {} while (0) -#define RTMP_IRQ_RELEASE(net_dev) do {} while (0) - -#endif /* __RTMP_USB_H__ */ diff --git a/trunk/drivers/staging/rt2860/mlme.h b/trunk/drivers/staging/rt2860/mlme.h deleted file mode 100644 index a285851692ee..000000000000 --- a/trunk/drivers/staging/rt2860/mlme.h +++ /dev/null @@ -1,1050 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - mlme.h - - Abstract: - - Revision History: - Who When What - -------- ---------- ------------------------------ - John Chang 2003-08-28 Created - John Chang 2004-09-06 modified for RT2600 - Justin P. Mattock 11/07/2010 Fix typos in comments - -*/ -#ifndef __MLME_H__ -#define __MLME_H__ - -#include "rtmp_dot11.h" - -/* maximum supported capability information */ -/* ESS, IBSS, Privacy, Short Preamble, Spectrum mgmt, Short Slot */ -#define SUPPORTED_CAPABILITY_INFO 0x0533 - -#define END_OF_ARGS -1 -#define LFSR_MASK 0x80000057 -#define MLME_TASK_EXEC_INTV 100/*200*/ /* */ -#define LEAD_TIME 5 -#define MLME_TASK_EXEC_MULTIPLE 10 /*5*/ /* MLME_TASK_EXEC_MULTIPLE * MLME_TASK_EXEC_INTV = 1 sec */ -#define REORDER_EXEC_INTV 100 /* 0.1 sec */ - -/* The definition of Radar detection duration region */ -#define CE 0 -#define FCC 1 -#define JAP 2 -#define JAP_W53 3 -#define JAP_W56 4 -#define MAX_RD_REGION 5 - -#define BEACON_LOST_TIME (4 * OS_HZ) /* 2048 msec = 2 sec */ - -#define DLS_TIMEOUT 1200 /* unit: msec */ -#define AUTH_TIMEOUT 300 /* unit: msec */ -#define ASSOC_TIMEOUT 300 /* unit: msec */ -#define JOIN_TIMEOUT 2000 /* unit: msec */ -#define SHORT_CHANNEL_TIME 90 /* unit: msec */ -#define MIN_CHANNEL_TIME 110 /* unit: msec, for dual band scan */ -#define MAX_CHANNEL_TIME 140 /* unit: msec, for single band scan */ -#define FAST_ACTIVE_SCAN_TIME 30 /* Active scan waiting for probe response time */ -#define CW_MIN_IN_BITS 4 /* actual CwMin = 2^CW_MIN_IN_BITS - 1 */ -#define LINK_DOWN_TIMEOUT 20000 /* unit: msec */ -#define AUTO_WAKEUP_TIMEOUT 70 /*unit: msec */ - -#define CW_MAX_IN_BITS 10 /* actual CwMax = 2^CW_MAX_IN_BITS - 1 */ - -/* Note: RSSI_TO_DBM_OFFSET has been changed to variable for new RF (2004-0720). */ -/* Should not refer to this constant anymore */ -/*#define RSSI_TO_DBM_OFFSET 120 // for RT2530 RSSI-115 = dBm */ -#define RSSI_FOR_MID_TX_POWER -55 /* -55 db is considered mid-distance */ -#define RSSI_FOR_LOW_TX_POWER -45 /* -45 db is considered very short distance and */ - /* eligible to use a lower TX power */ -#define RSSI_FOR_LOWEST_TX_POWER -30 -/*#define MID_TX_POWER_DELTA 0 // 0 db from full TX power upon mid-distance to AP */ -#define LOW_TX_POWER_DELTA 6 /* -3 db from full TX power upon very short distance. 1 grade is 0.5 db */ -#define LOWEST_TX_POWER_DELTA 16 /* -8 db from full TX power upon shortest distance. 1 grade is 0.5 db */ - -#define RSSI_TRIGGERED_UPON_BELOW_THRESHOLD 0 -#define RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD 1 -#define RSSI_THRESHOLD_FOR_ROAMING 25 -#define RSSI_DELTA 5 - -/* Channel Quality Indication */ -#define CQI_IS_GOOD(cqi) ((cqi) >= 50) -/*#define CQI_IS_FAIR(cqi) (((cqi) >= 20) && ((cqi) < 50)) */ -#define CQI_IS_POOR(cqi) (cqi < 50) /*(((cqi) >= 5) && ((cqi) < 20)) */ -#define CQI_IS_BAD(cqi) (cqi < 5) -#define CQI_IS_DEAD(cqi) (cqi == 0) - -/* weighting factor to calculate Channel quality, total should be 100% */ -#define RSSI_WEIGHTING 50 -#define TX_WEIGHTING 30 -#define RX_WEIGHTING 20 - -#define BSS_NOT_FOUND 0xFFFFFFFF - -#define MAX_LEN_OF_MLME_QUEUE 40 /*10 */ - -#define SCAN_PASSIVE 18 /* scan with no probe request, only wait beacon and probe response */ -#define SCAN_ACTIVE 19 /* scan with probe request, and wait beacon and probe response */ -#define SCAN_CISCO_PASSIVE 20 /* Single channel passive scan */ -#define SCAN_CISCO_ACTIVE 21 /* Single channel active scan */ -#define SCAN_CISCO_NOISE 22 /* Single channel passive scan for noise histogram collection */ -#define SCAN_CISCO_CHANNEL_LOAD 23 /* Single channel passive scan for channel load collection */ -#define FAST_SCAN_ACTIVE 24 /* scan with probe request, and wait beacon and probe response */ - -#define MAC_ADDR_IS_GROUP(Addr) (((Addr[0]) & 0x01)) -#define MAC_ADDR_HASH(Addr) (Addr[0] ^ Addr[1] ^ Addr[2] ^ Addr[3] ^ Addr[4] ^ Addr[5]) -#define MAC_ADDR_HASH_INDEX(Addr) (MAC_ADDR_HASH(Addr) % HASH_TABLE_SIZE) -#define TID_MAC_HASH(Addr, TID) (TID^Addr[0] ^ Addr[1] ^ Addr[2] ^ Addr[3] ^ Addr[4] ^ Addr[5]) -#define TID_MAC_HASH_INDEX(Addr, TID) (TID_MAC_HASH(Addr, TID) % HASH_TABLE_SIZE) - -/* LED Control */ -/* association ON. one LED ON. another blinking when TX, OFF when idle */ -/* no association, both LED off */ -#define ASIC_LED_ACT_ON(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00031e46) -#define ASIC_LED_ACT_OFF(pAd) RTMP_IO_WRITE32(pAd, MAC_CSR14, 0x00001e46) - -/* bit definition of the 2-byte pBEACON->Capability field */ -#define CAP_IS_ESS_ON(x) (((x) & 0x0001) != 0) -#define CAP_IS_IBSS_ON(x) (((x) & 0x0002) != 0) -#define CAP_IS_CF_POLLABLE_ON(x) (((x) & 0x0004) != 0) -#define CAP_IS_CF_POLL_REQ_ON(x) (((x) & 0x0008) != 0) -#define CAP_IS_PRIVACY_ON(x) (((x) & 0x0010) != 0) -#define CAP_IS_SHORT_PREAMBLE_ON(x) (((x) & 0x0020) != 0) -#define CAP_IS_PBCC_ON(x) (((x) & 0x0040) != 0) -#define CAP_IS_AGILITY_ON(x) (((x) & 0x0080) != 0) -#define CAP_IS_SPECTRUM_MGMT(x) (((x) & 0x0100) != 0) /* 802.11e d9 */ -#define CAP_IS_QOS(x) (((x) & 0x0200) != 0) /* 802.11e d9 */ -#define CAP_IS_SHORT_SLOT(x) (((x) & 0x0400) != 0) -#define CAP_IS_APSD(x) (((x) & 0x0800) != 0) /* 802.11e d9 */ -#define CAP_IS_IMMED_BA(x) (((x) & 0x1000) != 0) /* 802.11e d9 */ -#define CAP_IS_DSSS_OFDM(x) (((x) & 0x2000) != 0) -#define CAP_IS_DELAY_BA(x) (((x) & 0x4000) != 0) /* 802.11e d9 */ - -#define CAP_GENERATE(ess, ibss, priv, s_pre, s_slot, spectrum) (((ess) ? 0x0001 : 0x0000) | ((ibss) ? 0x0002 : 0x0000) | ((priv) ? 0x0010 : 0x0000) | ((s_pre) ? 0x0020 : 0x0000) | ((s_slot) ? 0x0400 : 0x0000) | ((spectrum) ? 0x0100 : 0x0000)) - -#define ERP_IS_NON_ERP_PRESENT(x) (((x) & 0x01) != 0) /* 802.11g */ -#define ERP_IS_USE_PROTECTION(x) (((x) & 0x02) != 0) /* 802.11g */ -#define ERP_IS_USE_BARKER_PREAMBLE(x) (((x) & 0x04) != 0) /* 802.11g */ - -#define DRS_TX_QUALITY_WORST_BOUND 8 /* 3 // just test by gary */ -#define DRS_PENALTY 8 - -#define BA_NOTUSE 2 -/*BA Policy subfiled value in ADDBA frame */ -#define IMMED_BA 1 -#define DELAY_BA 0 - -/* BA Initiator subfield in DELBA frame */ -#define ORIGINATOR 1 -#define RECIPIENT 0 - -/* ADDBA Status Code */ -#define ADDBA_RESULTCODE_SUCCESS 0 -#define ADDBA_RESULTCODE_REFUSED 37 -#define ADDBA_RESULTCODE_INVALID_PARAMETERS 38 - -/* DELBA Reason Code */ -#define DELBA_REASONCODE_QSTA_LEAVING 36 -#define DELBA_REASONCODE_END_BA 37 -#define DELBA_REASONCODE_UNKNOWN_BA 38 -#define DELBA_REASONCODE_TIMEOUT 39 - -/* reset all OneSecTx counters */ -#define RESET_ONE_SEC_TX_CNT(__pEntry) \ -if (((__pEntry)) != NULL) { \ - (__pEntry)->OneSecTxRetryOkCount = 0; \ - (__pEntry)->OneSecTxFailCount = 0; \ - (__pEntry)->OneSecTxNoRetryOkCount = 0; \ -} - -/* */ -/* 802.11 frame formats */ -/* */ -/* HT Capability INFO field in HT Cap IE . */ -struct PACKED rt_ht_cap_info { - u16 AdvCoding:1; - u16 ChannelWidth:1; - u16 MimoPs:2; /*momi power safe */ - u16 GF:1; /*green field */ - u16 ShortGIfor20:1; - u16 ShortGIfor40:1; /*for40MHz */ - u16 TxSTBC:1; - u16 RxSTBC:2; - u16 DelayedBA:1; /*rt2860c not support */ - u16 AMsduSize:1; /* only support as zero */ - u16 CCKmodein40:1; - u16 PSMP:1; - u16 Forty_Mhz_Intolerant:1; - u16 LSIGTxopProSup:1; -}; - -/* HT Capability INFO field in HT Cap IE . */ -struct PACKED rt_ht_cap_parm { - u8 MaxRAmpduFactor:2; - u8 MpduDensity:3; - u8 rsv:3; /*momi power safe */ -}; - -/* HT Capability INFO field in HT Cap IE . */ -struct PACKED rt_ht_mcs_set { - u8 MCSSet[10]; - u8 SupRate[2]; /* unit : 1Mbps */ - u8 TxMCSSetDefined:1; - u8 TxRxNotEqual:1; - u8 TxStream:2; - u8 MpduDensity:1; - u8 rsv:3; - u8 rsv3[3]; -}; - -/* HT Capability INFO field in HT Cap IE . */ -struct PACKED rt_ext_ht_cap_info { - u16 Pco:1; - u16 TranTime:2; - u16 rsv:5; /*momi power safe */ - u16 MCSFeedback:2; /*0:no MCS feedback, 2:unsolicited MCS feedback, 3:Full MCS feedback, 1:rsv. */ - u16 PlusHTC:1; /*+HTC control field support */ - u16 RDGSupport:1; /*reverse Direction Grant support */ - u16 rsv2:4; -}; - -/* HT Beamforming field in HT Cap IE . */ -struct PACKED rt_ht_bf_cap { - unsigned long TxBFRecCapable:1; - unsigned long RxSoundCapable:1; - unsigned long TxSoundCapable:1; - unsigned long RxNDPCapable:1; - unsigned long TxNDPCapable:1; - unsigned long ImpTxBFCapable:1; - unsigned long Calibration:2; - unsigned long ExpCSICapable:1; - unsigned long ExpNoComSteerCapable:1; - unsigned long ExpComSteerCapable:1; - unsigned long ExpCSIFbk:2; - unsigned long ExpNoComBF:2; - unsigned long ExpComBF:2; - unsigned long MinGrouping:2; - unsigned long CSIBFAntSup:2; - unsigned long NoComSteerBFAntSup:2; - unsigned long ComSteerBFAntSup:2; - unsigned long CSIRowBFSup:2; - unsigned long ChanEstimation:2; - unsigned long rsv:3; -}; - -/* HT antenna selection field in HT Cap IE . */ -struct PACKED rt_ht_as_cap { - u8 AntSelect:1; - u8 ExpCSIFbkTxASEL:1; - u8 AntIndFbkTxASEL:1; - u8 ExpCSIFbk:1; - u8 AntIndFbk:1; - u8 RxASel:1; - u8 TxSoundPPDU:1; - u8 rsv:1; -}; - -/* Draft 1.0 set IE length 26, but is extensible.. */ -#define SIZE_HT_CAP_IE 26 -/* The structure for HT Capability IE. */ -struct PACKED rt_ht_capability_ie { - struct rt_ht_cap_info HtCapInfo; - struct rt_ht_cap_parm HtCapParm; -/* struct rt_ht_mcs_set HtMCSSet; */ - u8 MCSSet[16]; - struct rt_ext_ht_cap_info ExtHtCapInfo; - struct rt_ht_bf_cap TxBFCap; /* beamforming cap. rt2860c not support beamforming. */ - struct rt_ht_as_cap ASCap; /*antenna selection. */ -}; - -/* 802.11n draft3 related structure definitions. */ -/* 7.3.2.60 */ -#define dot11OBSSScanPassiveDwell 20 /* in TU. min amount of time that the STA continuously scans each channel when performing an active OBSS scan. */ -#define dot11OBSSScanActiveDwell 10 /* in TU.min amount of time that the STA continuously scans each channel when performing an passive OBSS scan. */ -#define dot11BSSWidthTriggerScanInterval 300 /* in sec. max interval between scan operations to be performed to detect BSS channel width trigger events. */ -#define dot11OBSSScanPassiveTotalPerChannel 200 /* in TU. min total amount of time that the STA scans each channel when performing a passive OBSS scan. */ -#define dot11OBSSScanActiveTotalPerChannel 20 /*in TU. min total amount of time that the STA scans each channel when performing a active OBSS scan */ -#define dot11BSSWidthChannelTransactionDelayFactor 5 /* min ratio between the delay time in performing a switch from 20MHz BSS to 20/40 BSS operation and the maximum */ - /* interval between overlapping BSS scan operations. */ -#define dot11BSSScanActivityThreshold 25 /* in %%, max total time that a STA may be active on the medium during a period of */ - /* (dot11BSSWidthChannelTransactionDelayFactor * dot11BSSWidthTriggerScanInterval) seconds without */ - /* being obligated to perform OBSS Scan operations. default is 25(== 0.25%) */ - -struct PACKED rt_overlap_bss_scan_ie { - u16 ScanPassiveDwell; - u16 ScanActiveDwell; - u16 TriggerScanInt; /* Trigger scan interval */ - u16 PassiveTalPerChannel; /* passive total per channel */ - u16 ActiveTalPerChannel; /* active total per channel */ - u16 DelayFactor; /* BSS width channel transition delay factor */ - u16 ScanActThre; /* Scan Activity threshold */ -}; - -/* 7.3.2.56. 20/40 Coexistence element used in Element ID = 72 = IE_2040_BSS_COEXIST */ -typedef union PACKED _BSS_2040_COEXIST_IE { - struct PACKED { - u8 InfoReq:1; - u8 Intolerant40:1; /* Inter-BSS. set 1 when prohibits a receiving BSS from operating as a 20/40 Mhz BSS. */ - u8 BSS20WidthReq:1; /* Intra-BSS set 1 when prohibits a receiving AP from operating its BSS as a 20/40MHz BSS. */ - u8 rsv:5; - } field; - u8 word; -} BSS_2040_COEXIST_IE, *PBSS_2040_COEXIST_IE; - -struct rt_trigger_eventa { - BOOLEAN bValid; - u8 BSSID[6]; - u8 RegClass; /* Regulatory Class */ - u16 Channel; - unsigned long CDCounter; /* Maintain a separate count down counter for each Event A. */ -}; - -/* 20/40 trigger event table */ -/* If one Event (A) is deleted or created, or if Event (B) is detected or not detected, STA should send 2040BSSCoexistence to AP. */ -#define MAX_TRIGGER_EVENT 64 -struct rt_trigger_event_tab { - u8 EventANo; - struct rt_trigger_eventa EventA[MAX_TRIGGER_EVENT]; - unsigned long EventBCountDown; /* Count down counter for Event B. */ -}; - -/* 7.3.27 20/40 Bss Coexistence Mgmt capability used in extended capabilities information IE( ID = 127 = IE_EXT_CAPABILITY). */ -/* This is the first octet and was defined in 802.11n D3.03 and 802.11yD9.0 */ -struct PACKED rt_ext_cap_info_element { - u8 BssCoexistMgmtSupport:1; - u8 rsv:1; - u8 ExtendChannelSwitch:1; - u8 rsv2:5; -}; - -/* 802.11n 7.3.2.61 */ -struct PACKED rt_bss_2040_coexist_element { - u8 ElementID; /* ID = IE_2040_BSS_COEXIST = 72 */ - u8 Len; - BSS_2040_COEXIST_IE BssCoexistIe; -}; - -/*802.11n 7.3.2.59 */ -struct PACKED rt_bss_2040_intolerant_ch_report { - u8 ElementID; /* ID = IE_2040_BSS_INTOLERANT_REPORT = 73 */ - u8 Len; - u8 RegulatoryClass; - u8 ChList[0]; -}; - -/* The structure for channel switch announcement IE. This is in 802.11n D3.03 */ -struct PACKED rt_cha_switch_announce_ie { - u8 SwitchMode; /*channel switch mode */ - u8 NewChannel; /* */ - u8 SwitchCount; /* */ -}; - -/* The structure for channel switch announcement IE. This is in 802.11n D3.03 */ -struct PACKED rt_sec_cha_offset_ie { - u8 SecondaryChannelOffset; /* 1: Secondary above, 3: Secondary below, 0: no Secondary */ -}; - -/* This structure is extracted from struct struct rt_ht_capability */ -struct rt_ht_phy_info { - BOOLEAN bHtEnable; /* If we should use ht rate. */ - BOOLEAN bPreNHt; /* If we should use ht rate. */ - /*Subtract from HT Capability IE */ - u8 MCSSet[16]; -}; - -/*This structure subtracts ralink supports from all 802.11n-related features. */ -/*Features not listed here but contained in 802.11n spec are not supported in rt2860. */ -struct rt_ht_capability { - u16 ChannelWidth:1; - u16 MimoPs:2; /*mimo power safe MMPS_ */ - u16 GF:1; /*green field */ - u16 ShortGIfor20:1; - u16 ShortGIfor40:1; /*for40MHz */ - u16 TxSTBC:1; - u16 RxSTBC:2; /* 2 bits */ - u16 AmsduEnable:1; /* Enable to transmit A-MSDU. Suggest disable. We should use A-MPDU to gain best benefit of 802.11n */ - u16 AmsduSize:1; /* Max receiving A-MSDU size */ - u16 rsv:5; - - /*Subtract from Addiont HT INFO IE */ - u8 MaxRAmpduFactor:2; - u8 MpduDensity:3; - u8 ExtChanOffset:2; /* Please note the difference with following u8 NewExtChannelOffset; from 802.11n */ - u8 RecomWidth:1; - - u16 OperaionMode:2; - u16 NonGfPresent:1; - u16 rsv3:1; - u16 OBSS_NonHTExist:1; - u16 rsv2:11; - - /* New Extension Channel Offset IE */ - u8 NewExtChannelOffset; - /* Extension Capability IE = 127 */ - u8 BSSCoexist2040; -}; - -/* field in Additional HT Information IE . */ -struct PACKED rt_add_htinfo { - u8 ExtChanOffset:2; - u8 RecomWidth:1; - u8 RifsMode:1; - u8 S_PSMPSup:1; /*Indicate support for scheduled PSMP */ - u8 SerInterGranu:3; /*service interval granularity */ -}; - -struct PACKED rt_add_htinfo2 { - u16 OperaionMode:2; - u16 NonGfPresent:1; - u16 rsv:1; - u16 OBSS_NonHTExist:1; - u16 rsv2:11; -}; - -/* TODO: Need sync with spec about the definition of StbcMcs. In Draft 3.03, it's reserved. */ -struct PACKED rt_add_htinfo3 { - u16 StbcMcs:6; - u16 DualBeacon:1; - u16 DualCTSProtect:1; - u16 STBCBeacon:1; - u16 LsigTxopProt:1; /* L-SIG TXOP protection full support */ - u16 PcoActive:1; - u16 PcoPhase:1; - u16 rsv:4; -}; - -#define SIZE_ADD_HT_INFO_IE 22 -struct PACKED rt_add_ht_info_ie { - u8 ControlChan; - struct rt_add_htinfo AddHtInfo; - struct rt_add_htinfo2 AddHtInfo2; - struct rt_add_htinfo3 AddHtInfo3; - u8 MCSSet[16]; /* Basic MCS set */ -}; - -struct PACKED rt_new_ext_chan_ie { - u8 NewExtChanOffset; -}; - -struct PACKED rt_frame_802_11 { - struct rt_header_802_11 Hdr; - u8 Octet[1]; -}; - -/* QoSNull embedding of management action. When HT Control MA field set to 1. */ -struct PACKED rt_ma_body { - u8 Category; - u8 Action; - u8 Octet[1]; -}; - -struct PACKED rt_header_802_3 { - u8 DAAddr1[MAC_ADDR_LEN]; - u8 SAAddr2[MAC_ADDR_LEN]; - u8 Octet[2]; -}; -/*//Block ACK related format */ -/* 2-byte BA Parameter field in DELBA frames to terminate an already set up bA */ -struct PACKED rt_delba_parm { - u16 Rsv:11; /* always set to 0 */ - u16 Initiator:1; /* 1: originator 0:recipient */ - u16 TID:4; /* value of TC os TS */ -}; - -/* 2-byte BA Parameter Set field in ADDBA frames to signal parm for setting up a BA */ -struct PACKED rt_ba_parm { - u16 AMSDUSupported:1; /* 0: not permitted 1: permitted */ - u16 BAPolicy:1; /* 1: immediately BA 0:delayed BA */ - u16 TID:4; /* value of TC os TS */ - u16 BufSize:10; /* number of buffer of size 2304 octetsr */ -}; - -/* 2-byte BA Starting Seq CONTROL field */ -typedef union PACKED _BASEQ_CONTROL { - struct PACKED { - u16 FragNum:4; /* always set to 0 */ - u16 StartSeq:12; /* sequence number of the 1st MSDU for which this BAR is sent */ - } field; - u16 word; -} BASEQ_CONTROL, *PBASEQ_CONTROL; - -/*BAControl and BARControl are the same */ -/* 2-byte BA CONTROL field in BA frame */ -struct PACKED rt_ba_control { - u16 ACKPolicy:1; /* only related to N-Delayed BA. But not support in RT2860b. 0:NormalACK 1:No ACK */ - u16 MTID:1; /*EWC V1.24 */ - u16 Compressed:1; - u16 Rsv:9; - u16 TID:4; -}; - -/* 2-byte BAR CONTROL field in BAR frame */ -struct PACKED rt_bar_control { - u16 ACKPolicy:1; /* 0:normal ack, 1:no ack. */ - u16 MTID:1; /*if this bit1, use struct rt_frame_mtba_req, if 0, use struct rt_frame_ba_req */ - u16 Compressed:1; - u16 Rsv1:9; - u16 TID:4; -}; - -/* BARControl in MTBAR frame */ -struct PACKED rt_mtbar_control { - u16 ACKPolicy:1; - u16 MTID:1; - u16 Compressed:1; - u16 Rsv1:9; - u16 NumTID:4; -}; - -struct PACKED rt_per_tid_info { - u16 Rsv1:12; - u16 TID:4; -}; - -struct rt_each_tid { - struct rt_per_tid_info PerTID; - BASEQ_CONTROL BAStartingSeq; -}; - -/* BAREQ AND MTBAREQ have the same subtype BAR, 802.11n BAR use compressed bitmap. */ -struct PACKED rt_frame_ba_req { - struct rt_frame_control FC; - u16 Duration; - u8 Addr1[MAC_ADDR_LEN]; - u8 Addr2[MAC_ADDR_LEN]; - struct rt_bar_control BARControl; - BASEQ_CONTROL BAStartingSeq; -}; - -struct PACKED rt_frame_mtba_req { - struct rt_frame_control FC; - u16 Duration; - u8 Addr1[MAC_ADDR_LEN]; - u8 Addr2[MAC_ADDR_LEN]; - struct rt_mtbar_control MTBARControl; - struct rt_per_tid_info PerTIDInfo; - BASEQ_CONTROL BAStartingSeq; -}; - -/* Compressed format is mandatory in HT STA */ -struct PACKED rt_frame_mtba { - struct rt_frame_control FC; - u16 Duration; - u8 Addr1[MAC_ADDR_LEN]; - u8 Addr2[MAC_ADDR_LEN]; - struct rt_ba_control BAControl; - BASEQ_CONTROL BAStartingSeq; - u8 BitMap[8]; -}; - -struct PACKED rt_frame_psmp_action { - struct rt_header_802_11 Hdr; - u8 Category; - u8 Action; - u8 Psmp; /* 7.3.1.25 */ -}; - -struct PACKED rt_frame_action_hdr { - struct rt_header_802_11 Hdr; - u8 Category; - u8 Action; -}; - -/*Action Frame */ -/*Action Frame Category:Spectrum, Action:Channel Switch. 7.3.2.20 */ -struct PACKED rt_chan_switch_announce { - u8 ElementID; /* ID = IE_CHANNEL_SWITCH_ANNOUNCEMENT = 37 */ - u8 Len; - struct rt_cha_switch_announce_ie CSAnnounceIe; -}; - -/*802.11n : 7.3.2.20a */ -struct PACKED rt_second_chan_offset { - u8 ElementID; /* ID = IE_SECONDARY_CH_OFFSET = 62 */ - u8 Len; - struct rt_sec_cha_offset_ie SecChOffsetIe; -}; - -struct PACKED rt_frame_spetrum_cs { - struct rt_header_802_11 Hdr; - u8 Category; - u8 Action; - struct rt_chan_switch_announce CSAnnounce; - struct rt_second_chan_offset SecondChannel; -}; - -struct PACKED rt_frame_addba_req { - struct rt_header_802_11 Hdr; - u8 Category; - u8 Action; - u8 Token; /* 1 */ - struct rt_ba_parm BaParm; /* 2 - 10 */ - u16 TimeOutValue; /* 0 - 0 */ - BASEQ_CONTROL BaStartSeq; /* 0-0 */ -}; - -struct PACKED rt_frame_addba_rsp { - struct rt_header_802_11 Hdr; - u8 Category; - u8 Action; - u8 Token; - u16 StatusCode; - struct rt_ba_parm BaParm; /*0 - 2 */ - u16 TimeOutValue; -}; - -struct PACKED rt_frame_delba_req { - struct rt_header_802_11 Hdr; - u8 Category; - u8 Action; - struct rt_delba_parm DelbaParm; - u16 ReasonCode; -}; - -/*7.2.1.7 */ -struct PACKED rt_frame_bar { - struct rt_frame_control FC; - u16 Duration; - u8 Addr1[MAC_ADDR_LEN]; - u8 Addr2[MAC_ADDR_LEN]; - struct rt_bar_control BarControl; - BASEQ_CONTROL StartingSeq; -}; - -/*7.2.1.7 */ -struct PACKED rt_frame_ba { - struct rt_frame_control FC; - u16 Duration; - u8 Addr1[MAC_ADDR_LEN]; - u8 Addr2[MAC_ADDR_LEN]; - struct rt_bar_control BarControl; - BASEQ_CONTROL StartingSeq; - u8 bitmask[8]; -}; - -/* Radio Measurement Request Frame Format */ -struct PACKED rt_frame_rm_req_action { - struct rt_header_802_11 Hdr; - u8 Category; - u8 Action; - u8 Token; - u16 Repetition; - u8 data[0]; -}; - -struct PACKED rt_ht_ext_channel_switch_announcement_ie { - u8 ID; - u8 Length; - u8 ChannelSwitchMode; - u8 NewRegClass; - u8 NewChannelNum; - u8 ChannelSwitchCount; -}; - -/* */ -/* _Limit must be the 2**n - 1 */ -/* _SEQ1 , _SEQ2 must be within 0 ~ _Limit */ -/* */ -#define SEQ_STEPONE(_SEQ1, _SEQ2, _Limit) ((_SEQ1 == ((_SEQ2+1) & _Limit))) -#define SEQ_SMALLER(_SEQ1, _SEQ2, _Limit) (((_SEQ1-_SEQ2) & ((_Limit+1)>>1))) -#define SEQ_LARGER(_SEQ1, _SEQ2, _Limit) ((_SEQ1 != _SEQ2) && !(((_SEQ1-_SEQ2) & ((_Limit+1)>>1)))) -#define SEQ_WITHIN_WIN(_SEQ1, _SEQ2, _WIN, _Limit) (SEQ_LARGER(_SEQ1, _SEQ2, _Limit) && \ - SEQ_SMALLER(_SEQ1, ((_SEQ2+_WIN+1)&_Limit), _Limit)) - -/* */ -/* Contention-free parameter (without ID and Length) */ -/* */ -struct PACKED rt_cf_parm { - BOOLEAN bValid; /* 1: variable contains valid value */ - u8 CfpCount; - u8 CfpPeriod; - u16 CfpMaxDuration; - u16 CfpDurRemaining; -}; - -struct rt_cipher_suite { - NDIS_802_11_ENCRYPTION_STATUS PairCipher; /* Unicast cipher 1, this one has more secured cipher suite */ - NDIS_802_11_ENCRYPTION_STATUS PairCipherAux; /* Unicast cipher 2 if AP announce two unicast cipher suite */ - NDIS_802_11_ENCRYPTION_STATUS GroupCipher; /* Group cipher */ - u16 RsnCapability; /* RSN capability from beacon */ - BOOLEAN bMixMode; /* Indicate Pair & Group cipher might be different */ -}; - -/* EDCA configuration from AP's BEACON/ProbeRsp */ -struct rt_edca_parm { - BOOLEAN bValid; /* 1: variable contains valid value */ - BOOLEAN bAdd; /* 1: variable contains valid value */ - BOOLEAN bQAck; - BOOLEAN bQueueRequest; - BOOLEAN bTxopRequest; - BOOLEAN bAPSDCapable; -/* BOOLEAN bMoreDataAck; */ - u8 EdcaUpdateCount; - u8 Aifsn[4]; /* 0:AC_BK, 1:AC_BE, 2:AC_VI, 3:AC_VO */ - u8 Cwmin[4]; - u8 Cwmax[4]; - u16 Txop[4]; /* in unit of 32-us */ - BOOLEAN bACM[4]; /* 1: Admission Control of AC_BK is mandatory */ -}; - -/* QBSS LOAD information from QAP's BEACON/ProbeRsp */ -struct rt_qbss_load_parm { - BOOLEAN bValid; /* 1: variable contains valid value */ - u16 StaNum; - u8 ChannelUtilization; - u16 RemainingAdmissionControl; /* in unit of 32-us */ -}; - -/* QBSS Info field in QSTA's assoc req */ -struct PACKED rt_qbss_sta_info_parm { - u8 UAPSD_AC_VO:1; - u8 UAPSD_AC_VI:1; - u8 UAPSD_AC_BK:1; - u8 UAPSD_AC_BE:1; - u8 Rsv1:1; - u8 MaxSPLength:2; - u8 Rsv2:1; -}; - -/* QBSS Info field in QAP's Beacon/ProbeRsp */ -struct PACKED rt_qbss_ap_info_parm { - u8 ParamSetCount:4; - u8 Rsv:3; - u8 UAPSD:1; -}; - -/* QOS Capability reported in QAP's BEACON/ProbeRsp */ -/* QOS Capability sent out in QSTA's AssociateReq/ReAssociateReq */ -struct rt_qos_capability_parm { - BOOLEAN bValid; /* 1: variable contains valid value */ - BOOLEAN bQAck; - BOOLEAN bQueueRequest; - BOOLEAN bTxopRequest; -/* BOOLEAN bMoreDataAck; */ - u8 EdcaUpdateCount; -}; - -struct rt_wpa_ie { - u8 IELen; - u8 IE[MAX_CUSTOM_LEN]; -}; - -struct rt_bss_entry { - u8 Bssid[MAC_ADDR_LEN]; - u8 Channel; - u8 CentralChannel; /*Store the wide-band central channel for 40MHz. used in 40MHz AP. Or this is the same as Channel. */ - u8 BssType; - u16 AtimWin; - u16 BeaconPeriod; - - u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 SupRateLen; - u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 ExtRateLen; - struct rt_ht_capability_ie HtCapability; - u8 HtCapabilityLen; - struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */ - u8 AddHtInfoLen; - u8 NewExtChanOffset; - char Rssi; - u8 Privacy; /* Indicate security function ON/OFF. Don't mess up with auth mode. */ - u8 Hidden; - - u16 DtimPeriod; - u16 CapabilityInfo; - - u16 CfpCount; - u16 CfpPeriod; - u16 CfpMaxDuration; - u16 CfpDurRemaining; - u8 SsidLen; - char Ssid[MAX_LEN_OF_SSID]; - - unsigned long LastBeaconRxTime; /* OS's timestamp */ - - BOOLEAN bSES; - - /* New for WPA2 */ - struct rt_cipher_suite WPA; /* AP announced WPA cipher suite */ - struct rt_cipher_suite WPA2; /* AP announced WPA2 cipher suite */ - - /* New for microsoft WPA support */ - struct rt_ndis_802_11_fixed_ies FixIEs; - NDIS_802_11_AUTHENTICATION_MODE AuthModeAux; /* Addition mode for WPA2 / WPA capable AP */ - NDIS_802_11_AUTHENTICATION_MODE AuthMode; - NDIS_802_11_WEP_STATUS WepStatus; /* Unicast Encryption Algorithm extract from VAR_IE */ - u16 VarIELen; /* Length of next VIE include EID & Length */ - u8 VarIEs[MAX_VIE_LEN]; - - /* CCX Ckip information */ - u8 CkipFlag; - - /* CCX 2 TSF */ - u8 PTSF[4]; /* Parent TSF */ - u8 TTSF[8]; /* Target TSF */ - - /* 802.11e d9, and WMM */ - struct rt_edca_parm EdcaParm; - struct rt_qos_capability_parm QosCapability; - struct rt_qbss_load_parm QbssLoad; - struct rt_wpa_ie WpaIE; - struct rt_wpa_ie RsnIE; -}; - -struct rt_bss_table { - u8 BssNr; - u8 BssOverlapNr; - struct rt_bss_entry BssEntry[MAX_LEN_OF_BSS_TABLE]; -}; - -struct rt_mlme_queue_elem { - unsigned long Machine; - unsigned long MsgType; - unsigned long MsgLen; - u8 Msg[MGMT_DMA_BUFFER_SIZE]; - LARGE_INTEGER TimeStamp; - u8 Rssi0; - u8 Rssi1; - u8 Rssi2; - u8 Signal; - u8 Channel; - u8 Wcid; - BOOLEAN Occupied; -}; - -struct rt_mlme_queue { - unsigned long Num; - unsigned long Head; - unsigned long Tail; - spinlock_t Lock; - struct rt_mlme_queue_elem Entry[MAX_LEN_OF_MLME_QUEUE]; -}; - -typedef void(*STATE_MACHINE_FUNC) (void *Adaptor, struct rt_mlme_queue_elem *Elem); - -struct rt_state_machine { - unsigned long Base; - unsigned long NrState; - unsigned long NrMsg; - unsigned long CurrState; - STATE_MACHINE_FUNC *TransFunc; -}; - -/* MLME AUX data structure that holds temporarliy settings during a connection attempt. */ -/* Once this attempt succeeds, all settings will be copy to pAd->StaActive. */ -/* A connection attempt (user set OID, roaming, CCX fast roaming,..) consists of */ -/* several steps (JOIN, AUTH, ASSOC or REASSOC) and may fail at any step. We purposely */ -/* separate this under-trial settings away from pAd->StaActive so that once */ -/* this new attempt failed, driver can auto-recover back to the active settings. */ -struct rt_mlme_aux { - u8 BssType; - u8 Ssid[MAX_LEN_OF_SSID]; - u8 SsidLen; - u8 Bssid[MAC_ADDR_LEN]; - u8 AutoReconnectSsid[MAX_LEN_OF_SSID]; - u8 AutoReconnectSsidLen; - u16 Alg; - u8 ScanType; - u8 Channel; - u8 CentralChannel; - u16 Aid; - u16 CapabilityInfo; - u16 BeaconPeriod; - u16 CfpMaxDuration; - u16 CfpPeriod; - u16 AtimWin; - - /* Copy supported rate from desired AP's beacon. We are trying to match */ - /* AP's supported and extended rate settings. */ - u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 SupRateLen; - u8 ExtRateLen; - struct rt_ht_capability_ie HtCapability; - u8 HtCapabilityLen; - struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */ - u8 NewExtChannelOffset; - /*struct rt_ht_capability SupportedHtPhy; */ - - /* new for QOS */ - struct rt_qos_capability_parm APQosCapability; /* QOS capability of the current associated AP */ - struct rt_edca_parm APEdcaParm; /* EDCA parameters of the current associated AP */ - struct rt_qbss_load_parm APQbssLoad; /* QBSS load of the current associated AP */ - - /* new to keep Ralink specific feature */ - unsigned long APRalinkIe; - - struct rt_bss_table SsidBssTab; /* AP list for the same SSID */ - struct rt_bss_table RoamTab; /* AP list eligible for roaming */ - unsigned long BssIdx; - unsigned long RoamIdx; - - BOOLEAN CurrReqIsFromNdis; - - struct rt_ralink_timer BeaconTimer, ScanTimer; - struct rt_ralink_timer AuthTimer; - struct rt_ralink_timer AssocTimer, ReassocTimer, DisassocTimer; -}; - -struct rt_mlme_addba_req { - u8 Wcid; /* */ - u8 pAddr[MAC_ADDR_LEN]; - u8 BaBufSize; - u16 TimeOutValue; - u8 TID; - u8 Token; - u16 BaStartSeq; -}; - -struct rt_mlme_delba_req { - u8 Wcid; /* */ - u8 Addr[MAC_ADDR_LEN]; - u8 TID; - u8 Initiator; -}; - -/* assoc struct is equal to reassoc */ -struct rt_mlme_assoc_req { - u8 Addr[MAC_ADDR_LEN]; - u16 CapabilityInfo; - u16 ListenIntv; - unsigned long Timeout; -}; - -struct rt_mlme_disassoc_req { - u8 Addr[MAC_ADDR_LEN]; - u16 Reason; -}; - -struct rt_mlme_auth_req { - u8 Addr[MAC_ADDR_LEN]; - u16 Alg; - unsigned long Timeout; -}; - -struct rt_mlme_deauth_req { - u8 Addr[MAC_ADDR_LEN]; - u16 Reason; -}; - -struct rt_mlme_join_req { - unsigned long BssIdx; -}; - -struct rt_mlme_scan_req { - u8 Bssid[MAC_ADDR_LEN]; - u8 BssType; - u8 ScanType; - u8 SsidLen; - char Ssid[MAX_LEN_OF_SSID]; -}; - -struct rt_mlme_start_req { - char Ssid[MAX_LEN_OF_SSID]; - u8 SsidLen; -}; - -struct PACKED rt_eid { - u8 Eid; - u8 Len; - u8 Octet[1]; -}; - -struct PACKED rt_rtmp_tx_rate_switch { - u8 ItemNo; - u8 STBC:1; - u8 ShortGI:1; - u8 BW:1; - u8 Rsv1:1; - u8 Mode:2; - u8 Rsv2:2; - u8 CurrMCS; - u8 TrainUp; - u8 TrainDown; -}; - -/* ========================== AP mlme.h =============================== */ -#define TBTT_PRELOAD_TIME 384 /* usec. LomgPreamble + 24-byte at 1Mbps */ -#define DEFAULT_DTIM_PERIOD 1 - -#define MAC_TABLE_AGEOUT_TIME 300 /* unit: sec */ -#define MAC_TABLE_ASSOC_TIMEOUT 5 /* unit: sec */ -#define MAC_TABLE_FULL(Tab) ((Tab).size == MAX_LEN_OF_MAC_TABLE) - -/* AP shall drop the sta if continue Tx fail count reach it. */ -#define MAC_ENTRY_LIFE_CHECK_CNT 20 /* packet cnt. */ - -/* Value domain of pMacEntry->Sst */ -typedef enum _Sst { - SST_NOT_AUTH, /* 0: equivalent to IEEE 802.11/1999 state 1 */ - SST_AUTH, /* 1: equivalent to IEEE 802.11/1999 state 2 */ - SST_ASSOC /* 2: equivalent to IEEE 802.11/1999 state 3 */ -} SST; - -/* value domain of pMacEntry->AuthState */ -typedef enum _AuthState { - AS_NOT_AUTH, - AS_AUTH_OPEN, /* STA has been authenticated using OPEN SYSTEM */ - AS_AUTH_KEY, /* STA has been authenticated using SHARED KEY */ - AS_AUTHENTICATING /* STA is waiting for AUTH seq#3 using SHARED KEY */ -} AUTH_STATE; - -/*for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114 */ -typedef enum _ApWpaState { - AS_NOTUSE, /* 0 */ - AS_DISCONNECT, /* 1 */ - AS_DISCONNECTED, /* 2 */ - AS_INITIALIZE, /* 3 */ - AS_AUTHENTICATION, /* 4 */ - AS_AUTHENTICATION2, /* 5 */ - AS_INITPMK, /* 6 */ - AS_INITPSK, /* 7 */ - AS_PTKSTART, /* 8 */ - AS_PTKINIT_NEGOTIATING, /* 9 */ - AS_PTKINITDONE, /* 10 */ - AS_UPDATEKEYS, /* 11 */ - AS_INTEGRITY_FAILURE, /* 12 */ - AS_KEYUPDATE, /* 13 */ -} AP_WPA_STATE; - -/* for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114 */ -typedef enum _GTKState { - REKEY_NEGOTIATING, - REKEY_ESTABLISHED, - KEYERROR, -} GTK_STATE; - -/* for-wpa value domain of pMacEntry->WpaState 802.1i D3 p.114 */ -typedef enum _WpaGTKState { - SETKEYS, - SETKEYS_DONE, -} WPA_GTK_STATE; -/* ====================== end of AP mlme.h ============================ */ - -#endif /* MLME_H__ */ diff --git a/trunk/drivers/staging/rt2860/oid.h b/trunk/drivers/staging/rt2860/oid.h deleted file mode 100644 index 5a25f0d3cfeb..000000000000 --- a/trunk/drivers/staging/rt2860/oid.h +++ /dev/null @@ -1,779 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - oid.h - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs - Justin P. Mattock 11/07/2010 Fix typos in comments -*/ -#ifndef _OID_H_ -#define _OID_H_ - -/*#include */ - -#ifndef TRUE -#define TRUE 1 -#endif -#ifndef FALSE -#define FALSE 0 -#endif -/* */ -/* IEEE 802.11 Structures and definitions */ -/* */ -#define MAX_TX_POWER_LEVEL 100 /* mW */ -#define MAX_RSSI_TRIGGER -10 /* dBm */ -#define MIN_RSSI_TRIGGER -200 /* dBm */ -#define MAX_FRAG_THRESHOLD 2346 /* byte count */ -#define MIN_FRAG_THRESHOLD 256 /* byte count */ -#define MAX_RTS_THRESHOLD 2347 /* byte count */ - -/* new types for Media Specific Indications */ -/* Extension channel offset */ -#define EXTCHA_NONE 0 -#define EXTCHA_ABOVE 0x1 -#define EXTCHA_BELOW 0x3 - -/* BW */ -#define BAND_WIDTH_20 0 -#define BAND_WIDTH_40 1 -#define BAND_WIDTH_BOTH 2 -#define BAND_WIDTH_10 3 /* 802.11j has 10MHz. This definition is for internal usage. doesn't fill in the IE or other field. */ -/* SHORTGI */ -#define GAP_INTERVAL_400 1 /* only support in HT mode */ -#define GAP_INTERVAL_800 0 -#define GAP_INTERVAL_BOTH 2 - -#define NdisMediaStateConnected 1 -#define NdisMediaStateDisconnected 0 - -#define NDIS_802_11_LENGTH_SSID 32 -#define NDIS_802_11_LENGTH_RATES 8 -#define NDIS_802_11_LENGTH_RATES_EX 16 -#define MAC_ADDR_LENGTH 6 -/*#define MAX_NUM_OF_CHS 49 // 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL termination */ -#define MAX_NUM_OF_CHS 54 /* 14 channels @2.4G + 12@UNII(lower/middle) + 16@HiperLAN2 + 11@UNII(upper) + 0 @Japan + 1 as NULL termination */ -#define MAX_NUMBER_OF_EVENT 10 /* entry # in EVENT table */ -#define MAX_NUMBER_OF_MAC 32 /* if MAX_MBSSID_NUM is 8, this value can't be larger than 211 */ -#define MAX_NUMBER_OF_ACL 64 -#define MAX_LENGTH_OF_SUPPORT_RATES 12 /* 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */ -#define MAX_NUMBER_OF_DLS_ENTRY 4 - -#define RT_QUERY_SIGNAL_CONTEXT 0x0402 -#define RT_SET_IAPP_PID 0x0404 -#define RT_SET_APD_PID 0x0405 -#define RT_SET_DEL_MAC_ENTRY 0x0406 -#define RT_QUERY_EVENT_TABLE 0x0407 -/* */ -/* IEEE 802.11 OIDs */ -/* */ -#define OID_GET_SET_TOGGLE 0x8000 -#define OID_GET_SET_FROM_UI 0x4000 - -#define OID_802_11_ADD_WEP 0x0112 -#define OID_802_11_DISASSOCIATE 0x0114 -#define OID_802_11_BSSID_LIST_SCAN 0x0508 -#define OID_802_11_SSID 0x0509 -#define OID_802_11_BSSID 0x050A -#define OID_802_11_MIC_FAILURE_REPORT_FRAME 0x0528 - -#define RT_OID_DEVICE_NAME 0x0607 -#define RT_OID_VERSION_INFO 0x0608 -#define OID_802_11_BSSID_LIST 0x0609 -#define OID_802_3_CURRENT_ADDRESS 0x060A -#define OID_GEN_MEDIA_CONNECT_STATUS 0x060B -#define RT_OID_802_11_QUERY_LINK_STATUS 0x060C -#define OID_802_11_RSSI 0x060D -#define OID_802_11_STATISTICS 0x060E -#define OID_GEN_RCV_OK 0x060F -#define OID_GEN_RCV_NO_BUFFER 0x0610 -#define RT_OID_802_11_QUERY_EEPROM_VERSION 0x0611 -#define RT_OID_802_11_QUERY_FIRMWARE_VERSION 0x0612 -#define RT_OID_802_11_QUERY_LAST_RX_RATE 0x0613 -#define RT_OID_802_11_TX_POWER_LEVEL_1 0x0614 -#define RT_OID_802_11_QUERY_PIDVID 0x0615 -/*for WPA_SUPPLICANT_SUPPORT */ -#define OID_SET_COUNTERMEASURES 0x0616 -#define RT_OID_WPA_SUPPLICANT_SUPPORT 0x0621 -#define RT_OID_WE_VERSION_COMPILED 0x0622 -#define RT_OID_NEW_DRIVER 0x0623 - -#define RT_OID_DRIVER_DEVICE_NAME 0x0645 -#define RT_OID_QUERY_MULTIPLE_CARD_SUPPORT 0x0647 - -typedef enum _NDIS_802_11_STATUS_TYPE { - Ndis802_11StatusType_Authentication, - Ndis802_11StatusType_MediaStreamMode, - Ndis802_11StatusType_PMKID_CandidateList, - Ndis802_11StatusTypeMax /* not a real type, defined as an upper bound */ -} NDIS_802_11_STATUS_TYPE, *PNDIS_802_11_STATUS_TYPE; - -typedef u8 NDIS_802_11_MAC_ADDRESS[6]; - -struct rt_ndis_802_11_status_indication { - NDIS_802_11_STATUS_TYPE StatusType; -}; - -/* mask for authentication/integrity fields */ -#define NDIS_802_11_AUTH_REQUEST_AUTH_FIELDS 0x0f - -#define NDIS_802_11_AUTH_REQUEST_REAUTH 0x01 -#define NDIS_802_11_AUTH_REQUEST_KEYUPDATE 0x02 -#define NDIS_802_11_AUTH_REQUEST_PAIRWISE_ERROR 0x06 -#define NDIS_802_11_AUTH_REQUEST_GROUP_ERROR 0x0E - -struct rt_ndis_802_11_authentication_request { - unsigned long Length; /* Length of structure */ - NDIS_802_11_MAC_ADDRESS Bssid; - unsigned long Flags; -}; - -/*Added new types for PMKID Candidate lists. */ -struct rt_pmkid_candidate { - NDIS_802_11_MAC_ADDRESS BSSID; - unsigned long Flags; -}; - -struct rt_ndis_802_11_pmkid_candidate_list { - unsigned long Version; /* Version of the structure */ - unsigned long NumCandidates; /* No. of pmkid candidates */ - struct rt_pmkid_candidate CandidateList[1]; -}; - -/*Flags for PMKID Candidate list structure */ -#define NDIS_802_11_PMKID_CANDIDATE_PREAUTH_ENABLED 0x01 - -/* Added new types for OFDM 5G and 2.4G */ -typedef enum _NDIS_802_11_NETWORK_TYPE { - Ndis802_11FH, - Ndis802_11DS, - Ndis802_11OFDM5, - Ndis802_11OFDM24, - Ndis802_11Automode, - Ndis802_11OFDM5_N, - Ndis802_11OFDM24_N, - Ndis802_11NetworkTypeMax /* not a real type, defined as an upper bound */ -} NDIS_802_11_NETWORK_TYPE, *PNDIS_802_11_NETWORK_TYPE; - -struct rt_ndis_802_11_network_type_list { - u32 NumberOfItems; /* in list below, at least 1 */ - NDIS_802_11_NETWORK_TYPE NetworkType[1]; -}; - -typedef enum _NDIS_802_11_POWER_MODE { - Ndis802_11PowerModeCAM, - Ndis802_11PowerModeMAX_PSP, - Ndis802_11PowerModeFast_PSP, - Ndis802_11PowerModeLegacy_PSP, - Ndis802_11PowerModeMax /* not a real mode, defined as an upper bound */ -} NDIS_802_11_POWER_MODE, *PNDIS_802_11_POWER_MODE; - -typedef unsigned long NDIS_802_11_TX_POWER_LEVEL; /* in milliwatts */ - -/* */ -/* Received Signal Strength Indication */ -/* */ -typedef long NDIS_802_11_RSSI; /* in dBm */ - -struct rt_ndis_802_11_configuration_fh { - unsigned long Length; /* Length of structure */ - unsigned long HopPattern; /* As defined by 802.11, MSB set */ - unsigned long HopSet; /* to one if non-802.11 */ - unsigned long DwellTime; /* units are Kusec */ -}; - -struct rt_ndis_802_11_configuration { - unsigned long Length; /* Length of structure */ - unsigned long BeaconPeriod; /* units are Kusec */ - unsigned long ATIMWindow; /* units are Kusec */ - unsigned long DSConfig; /* Frequency, units are kHz */ - struct rt_ndis_802_11_configuration_fh FHConfig; -}; - -struct rt_ndis_802_11_statistics { - unsigned long Length; /* Length of structure */ - LARGE_INTEGER TransmittedFragmentCount; - LARGE_INTEGER MulticastTransmittedFrameCount; - LARGE_INTEGER FailedCount; - LARGE_INTEGER RetryCount; - LARGE_INTEGER MultipleRetryCount; - LARGE_INTEGER RTSSuccessCount; - LARGE_INTEGER RTSFailureCount; - LARGE_INTEGER ACKFailureCount; - LARGE_INTEGER FrameDuplicateCount; - LARGE_INTEGER ReceivedFragmentCount; - LARGE_INTEGER MulticastReceivedFrameCount; - LARGE_INTEGER FCSErrorCount; - LARGE_INTEGER TKIPLocalMICFailures; - LARGE_INTEGER TKIPRemoteMICErrors; - LARGE_INTEGER TKIPICVErrors; - LARGE_INTEGER TKIPCounterMeasuresInvoked; - LARGE_INTEGER TKIPReplays; - LARGE_INTEGER CCMPFormatErrors; - LARGE_INTEGER CCMPReplays; - LARGE_INTEGER CCMPDecryptErrors; - LARGE_INTEGER FourWayHandshakeFailures; -}; - -typedef unsigned long NDIS_802_11_KEY_INDEX; -typedef unsigned long long NDIS_802_11_KEY_RSC; - -#define MAX_RADIUS_SRV_NUM 2 /* 802.1x failover number */ - -struct PACKED rt_radius_srv_info { - u32 radius_ip; - u32 radius_port; - u8 radius_key[64]; - u8 radius_key_len; -}; - -struct PACKED rt_radius_key_info { - u8 radius_srv_num; - struct rt_radius_srv_info radius_srv_info[MAX_RADIUS_SRV_NUM]; - u8 ieee8021xWEP; /* dynamic WEP */ - u8 key_index; - u8 key_length; /* length of key in bytes */ - u8 key_material[13]; -}; - -/* It's used by 802.1x daemon to require relative configuration */ -struct PACKED rt_radius_conf { - u32 Length; /* Length of this structure */ - u8 mbss_num; /* indicate multiple BSS number */ - u32 own_ip_addr; - u32 retry_interval; - u32 session_timeout_interval; - u8 EAPifname[8][IFNAMSIZ]; - u8 EAPifname_len[8]; - u8 PreAuthifname[8][IFNAMSIZ]; - u8 PreAuthifname_len[8]; - struct rt_radius_key_info RadiusInfo[8]; -}; - -/* Key mapping keys require a BSSID */ -struct rt_ndis_802_11_key { - u32 Length; /* Length of this structure */ - u32 KeyIndex; - u32 KeyLength; /* length of key in bytes */ - NDIS_802_11_MAC_ADDRESS BSSID; - NDIS_802_11_KEY_RSC KeyRSC; - u8 KeyMaterial[1]; /* variable length depending on above field */ -}; - -struct rt_ndis_802_11_passphrase { - u32 KeyLength; /* length of key in bytes */ - NDIS_802_11_MAC_ADDRESS BSSID; - u8 KeyMaterial[1]; /* variable length depending on above field */ -}; - -struct rt_ndis_802_11_remove_key { - u32 Length; /* Length of this structure */ - u32 KeyIndex; - NDIS_802_11_MAC_ADDRESS BSSID; -}; - -struct rt_ndis_802_11_wep { - u32 Length; /* Length of this structure */ - u32 KeyIndex; /* 0 is the per-client key, 1-N are the */ - /* global keys */ - u32 KeyLength; /* length of key in bytes */ - u8 KeyMaterial[1]; /* variable length depending on above field */ -}; - -typedef enum _NDIS_802_11_NETWORK_INFRASTRUCTURE { - Ndis802_11IBSS, - Ndis802_11Infrastructure, - Ndis802_11AutoUnknown, - Ndis802_11Monitor, - Ndis802_11InfrastructureMax /* Not a real value, defined as upper bound */ -} NDIS_802_11_NETWORK_INFRASTRUCTURE, *PNDIS_802_11_NETWORK_INFRASTRUCTURE; - -/* Add new authentication modes */ -typedef enum _NDIS_802_11_AUTHENTICATION_MODE { - Ndis802_11AuthModeOpen, - Ndis802_11AuthModeShared, - Ndis802_11AuthModeAutoSwitch, - Ndis802_11AuthModeWPA, - Ndis802_11AuthModeWPAPSK, - Ndis802_11AuthModeWPANone, - Ndis802_11AuthModeWPA2, - Ndis802_11AuthModeWPA2PSK, - Ndis802_11AuthModeWPA1WPA2, - Ndis802_11AuthModeWPA1PSKWPA2PSK, - Ndis802_11AuthModeMax /* Not a real mode, defined as upper bound */ -} NDIS_802_11_AUTHENTICATION_MODE, *PNDIS_802_11_AUTHENTICATION_MODE; - -typedef u8 NDIS_802_11_RATES[NDIS_802_11_LENGTH_RATES]; /* Set of 8 data rates */ -typedef u8 NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX]; /* Set of 16 data rates */ - -struct PACKED rt_ndis_802_11_ssid { - u32 SsidLength; /* length of SSID field below, in bytes; */ - /* this can be zero. */ - u8 Ssid[NDIS_802_11_LENGTH_SSID]; /* SSID information field */ -}; - -struct PACKED rt_ndis_wlan_bssid { - unsigned long Length; /* Length of this structure */ - NDIS_802_11_MAC_ADDRESS MacAddress; /* BSSID */ - u8 Reserved[2]; - struct rt_ndis_802_11_ssid Ssid; /* SSID */ - unsigned long Privacy; /* WEP encryption requirement */ - NDIS_802_11_RSSI Rssi; /* receive signal strength in dBm */ - NDIS_802_11_NETWORK_TYPE NetworkTypeInUse; - struct rt_ndis_802_11_configuration Configuration; - NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode; - NDIS_802_11_RATES SupportedRates; -}; - -struct PACKED rt_ndis_802_11_bssid_list { - u32 NumberOfItems; /* in list below, at least 1 */ - struct rt_ndis_wlan_bssid Bssid[1]; -}; - -/* Added Capabilities, IELength and IEs for each BSSID */ -struct PACKED rt_ndis_wlan_bssid_ex { - unsigned long Length; /* Length of this structure */ - NDIS_802_11_MAC_ADDRESS MacAddress; /* BSSID */ - u8 Reserved[2]; - struct rt_ndis_802_11_ssid Ssid; /* SSID */ - u32 Privacy; /* WEP encryption requirement */ - NDIS_802_11_RSSI Rssi; /* receive signal */ - /* strength in dBm */ - NDIS_802_11_NETWORK_TYPE NetworkTypeInUse; - struct rt_ndis_802_11_configuration Configuration; - NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode; - NDIS_802_11_RATES_EX SupportedRates; - unsigned long IELength; - u8 IEs[1]; -}; - -struct PACKED rt_ndis_802_11_bssid_list_ex { - u32 NumberOfItems; /* in list below, at least 1 */ - struct rt_ndis_wlan_bssid_ex Bssid[1]; -}; - -struct PACKED rt_ndis_802_11_fixed_ies { - u8 Timestamp[8]; - u16 BeaconInterval; - u16 Capabilities; -}; - -struct rt_ndis_802_11_variable_ies { - u8 ElementID; - u8 Length; /* Number of bytes in data field */ - u8 data[1]; -}; - -typedef unsigned long NDIS_802_11_FRAGMENTATION_THRESHOLD; - -typedef unsigned long NDIS_802_11_RTS_THRESHOLD; - -typedef unsigned long NDIS_802_11_ANTENNA; - -typedef enum _NDIS_802_11_PRIVACY_FILTER { - Ndis802_11PrivFilterAcceptAll, - Ndis802_11PrivFilter8021xWEP -} NDIS_802_11_PRIVACY_FILTER, *PNDIS_802_11_PRIVACY_FILTER; - -/* Added new encryption types */ -/* Also aliased typedef to new name */ -typedef enum _NDIS_802_11_WEP_STATUS { - Ndis802_11WEPEnabled, - Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled, - Ndis802_11WEPDisabled, - Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled, - Ndis802_11WEPKeyAbsent, - Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent, - Ndis802_11WEPNotSupported, - Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported, - Ndis802_11Encryption2Enabled, - Ndis802_11Encryption2KeyAbsent, - Ndis802_11Encryption3Enabled, - Ndis802_11Encryption3KeyAbsent, - Ndis802_11Encryption4Enabled, /* TKIP or AES mix */ - Ndis802_11Encryption4KeyAbsent, - Ndis802_11GroupWEP40Enabled, - Ndis802_11GroupWEP104Enabled, -} NDIS_802_11_WEP_STATUS, *PNDIS_802_11_WEP_STATUS, - NDIS_802_11_ENCRYPTION_STATUS, *PNDIS_802_11_ENCRYPTION_STATUS; - -typedef enum _NDIS_802_11_RELOAD_DEFAULTS { - Ndis802_11ReloadWEPKeys -} NDIS_802_11_RELOAD_DEFAULTS, *PNDIS_802_11_RELOAD_DEFAULTS; - -#define NDIS_802_11_AI_REQFI_CAPABILITIES 1 -#define NDIS_802_11_AI_REQFI_LISTENINTERVAL 2 -#define NDIS_802_11_AI_REQFI_CURRENTAPADDRESS 4 - -#define NDIS_802_11_AI_RESFI_CAPABILITIES 1 -#define NDIS_802_11_AI_RESFI_STATUSCODE 2 -#define NDIS_802_11_AI_RESFI_ASSOCIATIONID 4 - -struct rt_ndis_802_11_ai_reqfi { - u16 Capabilities; - u16 ListenInterval; - NDIS_802_11_MAC_ADDRESS CurrentAPAddress; -}; - -struct rt_ndis_802_11_ai_resfi { - u16 Capabilities; - u16 StatusCode; - u16 AssociationId; -}; - -struct rt_ndis_802_11_association_information { - unsigned long Length; - u16 AvailableRequestFixedIEs; - struct rt_ndis_802_11_ai_reqfi RequestFixedIEs; - unsigned long RequestIELength; - unsigned long OffsetRequestIEs; - u16 AvailableResponseFixedIEs; - struct rt_ndis_802_11_ai_resfi ResponseFixedIEs; - unsigned long ResponseIELength; - unsigned long OffsetResponseIEs; -}; - -struct rt_ndis_802_11_authentication_event { - struct rt_ndis_802_11_status_indication Status; - struct rt_ndis_802_11_authentication_request Request[1]; -}; - -/* 802.11 Media stream constraints, associated with OID_802_11_MEDIA_STREAM_MODE */ -typedef enum _NDIS_802_11_MEDIA_STREAM_MODE { - Ndis802_11MediaStreamOff, - Ndis802_11MediaStreamOn, -} NDIS_802_11_MEDIA_STREAM_MODE, *PNDIS_802_11_MEDIA_STREAM_MODE; - -/* PMKID Structures */ -typedef u8 NDIS_802_11_PMKID_VALUE[16]; - -struct rt_bssid_info { - NDIS_802_11_MAC_ADDRESS BSSID; - NDIS_802_11_PMKID_VALUE PMKID; -}; - -struct rt_ndis_802_11_pmkid { - u32 Length; - u32 BSSIDInfoCount; - struct rt_bssid_info BSSIDInfo[1]; -}; - -struct rt_ndis_802_11_authentication_encryption { - NDIS_802_11_AUTHENTICATION_MODE AuthModeSupported; - NDIS_802_11_ENCRYPTION_STATUS EncryptStatusSupported; -}; - -struct rt_ndis_802_11_capability { - unsigned long Length; - unsigned long Version; - unsigned long NoOfPMKIDs; - unsigned long NoOfAuthEncryptPairsSupported; - struct rt_ndis_802_11_authentication_encryption - AuthenticationEncryptionSupported[1]; -}; - -#define RT_PRIV_IOCTL (SIOCIWFIRSTPRIV + 0x01) /* Sync. with AP for wsc upnp daemon */ -#define RTPRIV_IOCTL_SET (SIOCIWFIRSTPRIV + 0x02) - -#define RTPRIV_IOCTL_STATISTICS (SIOCIWFIRSTPRIV + 0x09) -#define RTPRIV_IOCTL_ADD_PMKID_CACHE (SIOCIWFIRSTPRIV + 0x0A) -#define RTPRIV_IOCTL_RADIUS_DATA (SIOCIWFIRSTPRIV + 0x0C) -#define RTPRIV_IOCTL_GSITESURVEY (SIOCIWFIRSTPRIV + 0x0D) -#define RT_PRIV_IOCTL_EXT (SIOCIWFIRSTPRIV + 0x0E) /* Sync. with RT61 (for wpa_supplicant) */ -#define RTPRIV_IOCTL_GET_MAC_TABLE (SIOCIWFIRSTPRIV + 0x0F) - -#define RTPRIV_IOCTL_SHOW (SIOCIWFIRSTPRIV + 0x11) -enum { - SHOW_CONN_STATUS = 4, - SHOW_DRVIER_VERION = 5, - SHOW_BA_INFO = 6, - SHOW_DESC_INFO = 7, -#ifdef RTMP_MAC_USB - SHOW_RXBULK_INFO = 8, - SHOW_TXBULK_INFO = 9, -#endif /* RTMP_MAC_USB // */ - RAIO_OFF = 10, - RAIO_ON = 11, - SHOW_CFG_VALUE = 20, - SHOW_ADHOC_ENTRY_INFO = 21, -}; - -#define OID_802_11_BUILD_CHANNEL_EX 0x0714 -#define OID_802_11_GET_CH_LIST 0x0715 -#define OID_802_11_GET_COUNTRY_CODE 0x0716 -#define OID_802_11_GET_CHANNEL_GEOGRAPHY 0x0717 - -#define RT_OID_WSC_SET_PASSPHRASE 0x0740 /* passphrase for wpa(2)-psk */ -#define RT_OID_WSC_DRIVER_AUTO_CONNECT 0x0741 -#define RT_OID_WSC_QUERY_DEFAULT_PROFILE 0x0742 -#define RT_OID_WSC_SET_CONN_BY_PROFILE_INDEX 0x0743 -#define RT_OID_WSC_SET_ACTION 0x0744 -#define RT_OID_WSC_SET_SSID 0x0745 -#define RT_OID_WSC_SET_PIN_CODE 0x0746 -#define RT_OID_WSC_SET_MODE 0x0747 /* PIN or PBC */ -#define RT_OID_WSC_SET_CONF_MODE 0x0748 /* Enrollee or Registrar */ -#define RT_OID_WSC_SET_PROFILE 0x0749 -#define RT_OID_WSC_CONFIG_STATUS 0x074F -#define RT_OID_802_11_WSC_QUERY_PROFILE 0x0750 -/* for consistency with RT61 */ -#define RT_OID_WSC_QUERY_STATUS 0x0751 -#define RT_OID_WSC_PIN_CODE 0x0752 -#define RT_OID_WSC_UUID 0x0753 -#define RT_OID_WSC_SET_SELECTED_REGISTRAR 0x0754 -#define RT_OID_WSC_EAPMSG 0x0755 -#define RT_OID_WSC_MANUFACTURER 0x0756 -#define RT_OID_WSC_MODEL_NAME 0x0757 -#define RT_OID_WSC_MODEL_NO 0x0758 -#define RT_OID_WSC_SERIAL_NO 0x0759 -#define RT_OID_WSC_MAC_ADDRESS 0x0760 - -/* New for MeetingHouse Api support */ -#define OID_MH_802_1X_SUPPORTED 0xFFEDC100 - -/* MIMO Tx parameter, ShortGI, MCS, STBC, etc. these are fields in TXWI. Don't change this definition! */ -typedef union _HTTRANSMIT_SETTING { - struct { - u16 MCS:7; /* MCS */ - u16 BW:1; /*channel bandwidth 20MHz or 40 MHz */ - u16 ShortGI:1; - u16 STBC:2; /*SPACE */ -/* u16 rsv:3; */ - u16 rsv:2; - u16 TxBF:1; - u16 MODE:2; /* Use definition MODE_xxx. */ - } field; - u16 word; -} HTTRANSMIT_SETTING, *PHTTRANSMIT_SETTING; - -typedef enum _RT_802_11_PREAMBLE { - Rt802_11PreambleLong, - Rt802_11PreambleShort, - Rt802_11PreambleAuto -} RT_802_11_PREAMBLE, *PRT_802_11_PREAMBLE; - -typedef enum _RT_802_11_PHY_MODE { - PHY_11BG_MIXED = 0, - PHY_11B, - PHY_11A, - PHY_11ABG_MIXED, - PHY_11G, - PHY_11ABGN_MIXED, /* both band 5 */ - PHY_11N_2_4G, /* 11n-only with 2.4G band 6 */ - PHY_11GN_MIXED, /* 2.4G band 7 */ - PHY_11AN_MIXED, /* 5G band 8 */ - PHY_11BGN_MIXED, /* if check 802.11b. 9 */ - PHY_11AGN_MIXED, /* if check 802.11b. 10 */ - PHY_11N_5G, /* 11n-only with 5G band 11 */ -} RT_802_11_PHY_MODE; - -/* put all proprietery for-query objects here to reduce # of Query_OID */ -struct rt_802_11_link_status { - unsigned long CurrTxRate; /* in units of 0.5Mbps */ - unsigned long ChannelQuality; /* 0..100 % */ - unsigned long TxByteCount; /* both ok and fail */ - unsigned long RxByteCount; /* both ok and fail */ - unsigned long CentralChannel; /* 40MHz central channel number */ -}; - -struct rt_802_11_event_log { - LARGE_INTEGER SystemTime; /* timestammp via NdisGetCurrentSystemTime() */ - u8 Addr[MAC_ADDR_LENGTH]; - u16 Event; /* EVENT_xxx */ -}; - -struct rt_802_11_event_table { - unsigned long Num; - unsigned long Rsv; /* to align Log[] at LARGE_INTEGER boundary */ - struct rt_802_11_event_log Log[MAX_NUMBER_OF_EVENT]; -}; - -/* MIMO Tx parameter, ShortGI, MCS, STBC, etc. these are fields in TXWI. Don't change this definition! */ -typedef union _MACHTTRANSMIT_SETTING { - struct { - u16 MCS:7; /* MCS */ - u16 BW:1; /*channel bandwidth 20MHz or 40 MHz */ - u16 ShortGI:1; - u16 STBC:2; /*SPACE */ - u16 rsv:3; - u16 MODE:2; /* Use definition MODE_xxx. */ - } field; - u16 word; -} MACHTTRANSMIT_SETTING, *PMACHTTRANSMIT_SETTING; - -struct rt_802_11_mac_entry { - u8 Addr[MAC_ADDR_LENGTH]; - u8 Aid; - u8 Psm; /* 0:PWR_ACTIVE, 1:PWR_SAVE */ - u8 MimoPs; /* 0:MMPS_STATIC, 1:MMPS_DYNAMIC, 3:MMPS_Enabled */ - char AvgRssi0; - char AvgRssi1; - char AvgRssi2; - u32 ConnectedTime; - MACHTTRANSMIT_SETTING TxRate; -}; - -struct rt_802_11_mac_table { - unsigned long Num; - struct rt_802_11_mac_entry Entry[MAX_NUMBER_OF_MAC]; -}; - -/* structure for query/set hardware register - MAC, BBP, RF register */ -struct rt_802_11_hardware_register { - unsigned long HardwareType; /* 0:MAC, 1:BBP, 2:RF register, 3:EEPROM */ - unsigned long Offset; /* Q/S register offset addr */ - unsigned long Data; /* R/W data buffer */ -}; - -struct rt_802_11_ap_config { - unsigned long EnableTxBurst; /* 0-disable, 1-enable */ - unsigned long EnableTurboRate; /* 0-disable, 1-enable 72/100mbps turbo rate */ - unsigned long IsolateInterStaTraffic; /* 0-disable, 1-enable isolation */ - unsigned long HideSsid; /* 0-disable, 1-enable hiding */ - unsigned long UseBGProtection; /* 0-AUTO, 1-always ON, 2-always OFF */ - unsigned long UseShortSlotTime; /* 0-no use, 1-use 9-us short slot time */ - unsigned long Rsv1; /* must be 0 */ - unsigned long SystemErrorBitmap; /* ignore upon SET, return system error upon QUERY */ -}; - -/* structure to query/set STA_CONFIG */ -struct rt_802_11_sta_config { - unsigned long EnableTxBurst; /* 0-disable, 1-enable */ - unsigned long EnableTurboRate; /* 0-disable, 1-enable 72/100mbps turbo rate */ - unsigned long UseBGProtection; /* 0-AUTO, 1-always ON, 2-always OFF */ - unsigned long UseShortSlotTime; /* 0-no use, 1-use 9-us short slot time when applicable */ - unsigned long AdhocMode; /* 0-11b rates only (WIFI spec), 1 - b/g mixed, 2 - g only */ - unsigned long HwRadioStatus; /* 0-OFF, 1-ON, default is 1, Read-Only */ - unsigned long Rsv1; /* must be 0 */ - unsigned long SystemErrorBitmap; /* ignore upon SET, return system error upon QUERY */ -}; - -/* */ -/* For OID Query or Set about BA structure */ -/* */ -struct rt_oid_bacap { - u8 RxBAWinLimit; - u8 TxBAWinLimit; - u8 Policy; /* 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use. other value invalid */ - u8 MpduDensity; /* 0: DELAY_BA 1:IMMED_BA (//BA Policy subfiled value in ADDBA frame) 2:BA-not use. other value invalid */ - u8 AmsduEnable; /*Enable AMSDU transmisstion */ - u8 AmsduSize; /* 0:3839, 1:7935 bytes. u32 MSDUSizeToBytes[] = { 3839, 7935}; */ - u8 MMPSmode; /* MIMO power save more, 0:static, 1:dynamic, 2:rsv, 3:mimo enable */ - BOOLEAN AutoBA; /* Auto BA will automatically */ -}; - -struct rt_802_11_acl_entry { - u8 Addr[MAC_ADDR_LENGTH]; - u16 Rsv; -}; - -struct PACKED rt_rt_802_11_acl { - unsigned long Policy; /* 0-disable, 1-positive list, 2-negative list */ - unsigned long Num; - struct rt_802_11_acl_entry Entry[MAX_NUMBER_OF_ACL]; -}; - -struct rt_802_11_wds { - unsigned long Num; - NDIS_802_11_MAC_ADDRESS Entry[24 /*MAX_NUM_OF_WDS_LINK */]; - unsigned long KeyLength; - u8 KeyMaterial[32]; -}; - -struct rt_802_11_tx_rates { - u8 SupRateLen; - u8 SupRate[MAX_LENGTH_OF_SUPPORT_RATES]; - u8 ExtRateLen; - u8 ExtRate[MAX_LENGTH_OF_SUPPORT_RATES]; -}; - -/* Definition of extra information code */ -#define GENERAL_LINK_UP 0x0 /* Link is Up */ -#define GENERAL_LINK_DOWN 0x1 /* Link is Down */ -#define HW_RADIO_OFF 0x2 /* Hardware radio off */ -#define SW_RADIO_OFF 0x3 /* Software radio off */ -#define AUTH_FAIL 0x4 /* Open authentication fail */ -#define AUTH_FAIL_KEYS 0x5 /* Shared authentication fail */ -#define ASSOC_FAIL 0x6 /* Association failed */ -#define EAP_MIC_FAILURE 0x7 /* Deauthentication because MIC failure */ -#define EAP_4WAY_TIMEOUT 0x8 /* Deauthentication on 4-way handshake timeout */ -#define EAP_GROUP_KEY_TIMEOUT 0x9 /* Deauthentication on group key handshake timeout */ -#define EAP_SUCCESS 0xa /* EAP succeed */ -#define DETECT_RADAR_SIGNAL 0xb /* Radar signal occur in current channel */ -#define EXTRA_INFO_MAX 0xb /* Indicate Last OID */ - -#define EXTRA_INFO_CLEAR 0xffffffff - -/* This is OID setting structure. So only GF or MM as Mode. This is valid when our wirelss mode has 802.11n in use. */ -struct rt_oid_set_ht_phymode { - RT_802_11_PHY_MODE PhyMode; /* */ - u8 TransmitNo; - u8 HtMode; /*HTMODE_GF or HTMODE_MM */ - u8 ExtOffset; /*extension channel above or below */ - u8 MCS; - u8 BW; - u8 STBC; - u8 SHORTGI; - u8 rsv; -}; - -#define MAX_CUSTOM_LEN 128 - -typedef enum _RT_802_11_D_CLIENT_MODE { - Rt802_11_D_None, - Rt802_11_D_Flexible, - Rt802_11_D_Strict, -} RT_802_11_D_CLIENT_MODE, *PRT_802_11_D_CLIENT_MODE; - -struct rt_channel_list_info { - u8 ChannelList[MAX_NUM_OF_CHS]; /* list all supported channels for site survey */ - u8 ChannelListNum; /* number of channel in ChannelList[] */ -}; - -/* WSC configured credential */ -struct rt_wsc_credential { - struct rt_ndis_802_11_ssid SSID; /* mandatory */ - u16 AuthType; /* mandatory, 1: open, 2: wpa-psk, 4: shared, 8:wpa, 0x10: wpa2, 0x20: wpa2-psk */ - u16 EncrType; /* mandatory, 1: none, 2: wep, 4: tkip, 8: aes */ - u8 Key[64]; /* mandatory, Maximum 64 byte */ - u16 KeyLength; - u8 MacAddr[6]; /* mandatory, AP MAC address */ - u8 KeyIndex; /* optional, default is 1 */ - u8 Rsvd[3]; /* Make alignment */ -}; - -/* WSC configured profiles */ -struct rt_wsc_profile { - u32 ProfileCnt; - u32 ApplyProfileIdx; /* add by johnli, fix WPS test plan 5.1.1 */ - struct rt_wsc_credential Profile[8]; /* Support up to 8 profiles */ -}; - -#endif /* _OID_H_ */ diff --git a/trunk/drivers/staging/rt2860/pci_main_dev.c b/trunk/drivers/staging/rt2860/pci_main_dev.c deleted file mode 100644 index 25fbb1880ff2..000000000000 --- a/trunk/drivers/staging/rt2860/pci_main_dev.c +++ /dev/null @@ -1,1192 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - pci_main_dev.c - - Abstract: - Create and register network interface for PCI based chipsets in Linux platform. - - Revision History: - Who When What - Justin P. Mattock 11/07/2010 Fix typos in some comments - -------- ---------- ---------------------------------------------- -*/ - -#include "rt_config.h" -#include -#include - -/* Following information will be show when you run 'modinfo' */ -/* If you have a solution for a bug in current version of driver, please e-mail me. */ -/* Otherwise post to forum in ralinktech's web site(www.ralinktech.com) and let all users help you. */ -MODULE_AUTHOR("Jett Chen "); -MODULE_DESCRIPTION("RT2860/RT3090 Wireless Lan Linux Driver"); -MODULE_LICENSE("GPL"); -MODULE_ALIAS("rt3090sta"); - -/* */ -/* Function declarations */ -/* */ -static void __devexit rt2860_remove_one(struct pci_dev *pci_dev); -static int __devinit rt2860_probe(struct pci_dev *pci_dev, - const struct pci_device_id *ent); -static void __exit rt2860_cleanup_module(void); -static int __init rt2860_init_module(void); - -static void RTMPInitPCIeDevice(IN struct pci_dev *pci_dev, - struct rt_rtmp_adapter *pAd); - -#ifdef CONFIG_PM -static int rt2860_suspend(struct pci_dev *pci_dev, pm_message_t state); -static int rt2860_resume(struct pci_dev *pci_dev); -#endif /* CONFIG_PM // */ - -/* */ -/* Ralink PCI device table, include all supported chipsets */ -/* */ -static struct pci_device_id rt2860_pci_tbl[] __devinitdata = { -#ifdef RT2860 - {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2860_PCI_DEVICE_ID)}, /*RT28602.4G */ - {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2860_PCIe_DEVICE_ID)}, - {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2760_PCI_DEVICE_ID)}, - {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC2790_PCIe_DEVICE_ID)}, - {PCI_DEVICE(VEN_AWT_PCI_VENDOR_ID, VEN_AWT_PCIe_DEVICE_ID)}, - {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7708)}, - {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7728)}, - {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7758)}, - {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7727)}, - {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7738)}, - {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7748)}, - {PCI_DEVICE(EDIMAX_PCI_VENDOR_ID, 0x7768)}, -#endif -#ifdef RT3090 - {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3090_PCIe_DEVICE_ID)}, - {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3091_PCIe_DEVICE_ID)}, - {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3092_PCIe_DEVICE_ID)}, -#endif /* RT3090 // */ -#ifdef RT3390 - {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3390_PCIe_DEVICE_ID)}, - {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3391_PCIe_DEVICE_ID)}, - {PCI_DEVICE(NIC_PCI_VENDOR_ID, NIC3392_PCIe_DEVICE_ID)}, -#endif /* RT3390 // */ - {0,} /* terminate list */ -}; - -MODULE_DEVICE_TABLE(pci, rt2860_pci_tbl); -#ifdef MODULE_VERSION -MODULE_VERSION(STA_DRIVER_VERSION); -#endif - -/* */ -/* Our PCI driver structure */ -/* */ -static struct pci_driver rt2860_driver = { -name: "rt2860", -id_table : rt2860_pci_tbl, -probe : rt2860_probe, -remove : __devexit_p(rt2860_remove_one), -#ifdef CONFIG_PM -suspend : rt2860_suspend, -resume : rt2860_resume, -#endif -}; - -/*************************************************************************** - * - * PCI device initialization related procedures. - * - ***************************************************************************/ -#ifdef CONFIG_PM - -void RT2860RejectPendingPackets(struct rt_rtmp_adapter *pAd) -{ - /* clear PS packets */ - /* clear TxSw packets */ -} - -static int rt2860_suspend(struct pci_dev *pci_dev, pm_message_t state) -{ - struct net_device *net_dev = pci_get_drvdata(pci_dev); - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL; - int retval = 0; - - DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_suspend()\n")); - - if (net_dev == NULL) { - DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n")); - } else { - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - /* we can not use IFF_UP because ra0 down but ra1 up */ - /* and 1 suspend/resume function for 1 module, not for each interface */ - /* so Linux will call suspend/resume function once */ - if (VIRTUAL_IF_NUM(pAd) > 0) { - /* avoid users do suspend after interface is down */ - - /* stop interface */ - netif_carrier_off(net_dev); - netif_stop_queue(net_dev); - - /* mark device as removed from system and therefore no longer available */ - netif_device_detach(net_dev); - - /* mark halt flag */ - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); - - /* take down the device */ - rt28xx_close((struct net_device *)net_dev); - - RT_MOD_DEC_USE_COUNT(); - } - } - - /* reference to http://vovo2000.com/type-lab/linux/kernel-api/linux-kernel-api.html */ - /* enable device to generate PME# when suspended */ - /* pci_choose_state(): Choose the power state of a PCI device to be suspended */ - retval = pci_enable_wake(pci_dev, pci_choose_state(pci_dev, state), 1); - /* save the PCI configuration space of a device before suspending */ - pci_save_state(pci_dev); - /* disable PCI device after use */ - pci_disable_device(pci_dev); - - retval = pci_set_power_state(pci_dev, pci_choose_state(pci_dev, state)); - - DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_suspend()\n")); - return retval; -} - -static int rt2860_resume(struct pci_dev *pci_dev) -{ - struct net_device *net_dev = pci_get_drvdata(pci_dev); - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL; - int retval; - - /* set the power state of a PCI device */ - /* PCI has 4 power states, DO (normal) ~ D3(less power) */ - /* in include/linux/pci.h, you can find that */ - /* #define PCI_D0 ((pci_power_t __force) 0) */ - /* #define PCI_D1 ((pci_power_t __force) 1) */ - /* #define PCI_D2 ((pci_power_t __force) 2) */ - /* #define PCI_D3hot ((pci_power_t __force) 3) */ - /* #define PCI_D3cold ((pci_power_t __force) 4) */ - /* #define PCI_UNKNOWN ((pci_power_t __force) 5) */ - /* #define PCI_POWER_ERROR ((pci_power_t __force) -1) */ - retval = pci_set_power_state(pci_dev, PCI_D0); - - /* restore the saved state of a PCI device */ - pci_restore_state(pci_dev); - - /* initialize device before it's used by a driver */ - if (pci_enable_device(pci_dev)) { - printk(KERN_ERR "rt2860: pci enable fail!\n"); - return 0; - } - - DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_resume()\n")); - - if (net_dev == NULL) - DBGPRINT(RT_DEBUG_ERROR, ("net_dev == NULL!\n")); - else - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - if (pAd != NULL) { - /* we can not use IFF_UP because ra0 down but ra1 up */ - /* and 1 suspend/resume function for 1 module, not for each interface */ - /* so Linux will call suspend/resume function once */ - if (VIRTUAL_IF_NUM(pAd) > 0) { - /* mark device as attached from system and restart if needed */ - netif_device_attach(net_dev); - - if (rt28xx_open((struct net_device *)net_dev) != 0) { - /* open fail */ - DBGPRINT(RT_DEBUG_TRACE, - ("<=== rt2860_resume()\n")); - return 0; - } - /* increase MODULE use count */ - RT_MOD_INC_USE_COUNT(); - - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF); - - netif_start_queue(net_dev); - netif_carrier_on(net_dev); - netif_wake_queue(net_dev); - } - } - - DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_resume()\n")); - return 0; -} -#endif /* CONFIG_PM // */ - -static int __init rt2860_init_module(void) -{ - return pci_register_driver(&rt2860_driver); -} - -/* */ -/* Driver module unload function */ -/* */ -static void __exit rt2860_cleanup_module(void) -{ - pci_unregister_driver(&rt2860_driver); -} - -module_init(rt2860_init_module); -module_exit(rt2860_cleanup_module); - -/* */ -/* PCI device probe & initialization function */ -/* */ -static int __devinit rt2860_probe(IN struct pci_dev *pci_dev, - IN const struct pci_device_id *pci_id) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL; - struct net_device *net_dev; - void *handle; - char *print_name; - unsigned long csr_addr; - int rv = 0; - struct rt_rtmp_os_netdev_op_hook netDevHook; - - DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_probe\n")); - -/*PCIDevInit============================================== */ - /* wake up and enable device */ - rv = pci_enable_device(pci_dev); - - if (rv != 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("Enable PCI device failed, errno=%d!\n", rv)); - return rv; - } - - print_name = (char *)pci_name(pci_dev); - - rv = pci_request_regions(pci_dev, print_name); - - if (rv != 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("Request PCI resource failed, errno=%d!\n", rv)); - goto err_out; - } - /* map physical address to virtual address for accessing register */ - csr_addr = - (unsigned long)ioremap(pci_resource_start(pci_dev, 0), - pci_resource_len(pci_dev, 0)); - if (!csr_addr) { - DBGPRINT(RT_DEBUG_ERROR, - ("ioremap failed for device %s, region 0x%lX @ 0x%lX\n", - print_name, (unsigned long)pci_resource_len(pci_dev, 0), - (unsigned long)pci_resource_start(pci_dev, 0))); - goto err_out_free_res; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("%s: at 0x%lx, VA 0x%lx, IRQ %d. \n", print_name, - (unsigned long)pci_resource_start(pci_dev, 0), - (unsigned long)csr_addr, pci_dev->irq)); - } - - /* Set DMA master */ - pci_set_master(pci_dev); - -/*RtmpDevInit============================================== */ - /* Allocate struct rt_rtmp_adapter adapter structure */ - handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL); - if (handle == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s(): Allocate memory for os handle failed!\n", - __func__)); - goto err_out_iounmap; - } - - ((struct os_cookie *)handle)->pci_dev = pci_dev; - - rv = RTMPAllocAdapterBlock(handle, &pAd); /*shiang: we may need the pci_dev for allocate structure of "struct rt_rtmp_adapter" */ - if (rv != NDIS_STATUS_SUCCESS) - goto err_out_iounmap; - /* Here are the struct rt_rtmp_adapter structure with pci-bus specific parameters. */ - pAd->CSRBaseAddress = (u8 *)csr_addr; - DBGPRINT(RT_DEBUG_ERROR, - ("pAd->CSRBaseAddress =0x%lx, csr_addr=0x%lx!\n", - (unsigned long)pAd->CSRBaseAddress, csr_addr)); - RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_PCI); - -/*NetDevInit============================================== */ - net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); - if (net_dev == NULL) - goto err_out_free_radev; - - /* Here are the net_device structure with pci-bus specific parameters. */ - net_dev->irq = pci_dev->irq; /* Interrupt IRQ number */ - net_dev->base_addr = csr_addr; /* Save CSR virtual address and irq to device structure */ - pci_set_drvdata(pci_dev, net_dev); /* Set driver data */ - -/* for supporting Network Manager */ - /* Set the sysfs physical device reference for the network logical device - * if set prior to registration will cause a symlink during initialization. - */ - SET_NETDEV_DEV(net_dev, &(pci_dev->dev)); - -/*All done, it's time to register the net device to linux kernel. */ - /* Register this device */ - rv = RtmpOSNetDevAttach(net_dev, &netDevHook); - if (rv) - goto err_out_free_netdev; - - pAd->StaCfg.OriDevType = net_dev->type; - RTMPInitPCIeDevice(pci_dev, pAd); - - DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2860_probe\n")); - - return 0; /* probe ok */ - - /* --------------------------- ERROR HANDLE --------------------------- */ -err_out_free_netdev: - RtmpOSNetDevFree(net_dev); - -err_out_free_radev: - /* free struct rt_rtmp_adapter strcuture and os_cookie */ - RTMPFreeAdapter(pAd); - -err_out_iounmap: - iounmap((void *)(csr_addr)); - release_mem_region(pci_resource_start(pci_dev, 0), - pci_resource_len(pci_dev, 0)); - -err_out_free_res: - pci_release_regions(pci_dev); - -err_out: - pci_disable_device(pci_dev); - - DBGPRINT(RT_DEBUG_ERROR, - ("<=== rt2860_probe failed with rv = %d!\n", rv)); - - return -ENODEV; /* probe fail */ -} - -static void __devexit rt2860_remove_one(IN struct pci_dev *pci_dev) -{ - struct net_device *net_dev = pci_get_drvdata(pci_dev); - struct rt_rtmp_adapter *pAd = NULL; - unsigned long csr_addr = net_dev->base_addr; /* pAd->CSRBaseAddress; */ - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - DBGPRINT(RT_DEBUG_TRACE, ("===> rt2860_remove_one\n")); - - if (pAd != NULL) { - /* Unregister/Free all allocated net_device. */ - RtmpPhyNetDevExit(pAd, net_dev); - - /* Unmap CSR base address */ - iounmap((char *)(csr_addr)); - - /* release memory region */ - release_mem_region(pci_resource_start(pci_dev, 0), - pci_resource_len(pci_dev, 0)); - - /* Free struct rt_rtmp_adapter related structures. */ - RtmpRaDevCtrlExit(pAd); - - } else { - /* Unregister network device */ - RtmpOSNetDevDetach(net_dev); - - /* Unmap CSR base address */ - iounmap((char *)(net_dev->base_addr)); - - /* release memory region */ - release_mem_region(pci_resource_start(pci_dev, 0), - pci_resource_len(pci_dev, 0)); - } - - /* Free the root net_device */ - RtmpOSNetDevFree(net_dev); - -} - -/* -======================================================================== -Routine Description: - Check the chipset vendor/product ID. - -Arguments: - _dev_p Point to the PCI or USB device - -Return Value: - TRUE Check ok - FALSE Check fail - -Note: -======================================================================== -*/ -BOOLEAN RT28XXChipsetCheck(IN void *_dev_p) -{ - /* always TRUE */ - return TRUE; -} - -/*************************************************************************** - * - * PCIe device initialization related procedures. - * - ***************************************************************************/ -static void RTMPInitPCIeDevice(struct pci_dev *pci_dev, struct rt_rtmp_adapter *pAd) -{ - u16 device_id; - struct os_cookie *pObj; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - pci_read_config_word(pci_dev, PCI_DEVICE_ID, &device_id); - device_id = le2cpu16(device_id); - pObj->DeviceID = device_id; - if ( -#ifdef RT2860 - (device_id == NIC2860_PCIe_DEVICE_ID) || - (device_id == NIC2790_PCIe_DEVICE_ID) || - (device_id == VEN_AWT_PCIe_DEVICE_ID) || -#endif -#ifdef RT3090 - (device_id == NIC3090_PCIe_DEVICE_ID) || - (device_id == NIC3091_PCIe_DEVICE_ID) || - (device_id == NIC3092_PCIe_DEVICE_ID) || -#endif /* RT3090 // */ - 0) { - u32 MacCsr0 = 0, Index = 0; - do { - RTMP_IO_READ32(pAd, MAC_CSR0, &MacCsr0); - - if ((MacCsr0 != 0x00) && (MacCsr0 != 0xFFFFFFFF)) - break; - - RTMPusecDelay(10); - } while (Index++ < 100); - - /* Support advanced power save after 2892/2790. */ - /* MAC version at offset 0x1000 is 0x2872XXXX/0x2870XXXX(PCIe, USB, SDIO). */ - if ((MacCsr0 & 0xffff0000) != 0x28600000) - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_PCIE_DEVICE); - } -} - -void RTMPInitPCIeLinkCtrlValue(struct rt_rtmp_adapter *pAd) -{ - int pos; - u16 reg16, data2, PCIePowerSaveLevel, Configuration; - u32 MacValue; - BOOLEAN bFindIntel = FALSE; - struct os_cookie *pObj; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) - return; - - DBGPRINT(RT_DEBUG_TRACE, ("%s.===>\n", __func__)); - /* Init EEPROM, and save settings */ - if (!(IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd))) { - RT28xx_EEPROM_READ16(pAd, 0x22, PCIePowerSaveLevel); - pAd->PCIePowerSaveLevel = PCIePowerSaveLevel & 0xff; - - pAd->LnkCtrlBitMask = 0; - if ((PCIePowerSaveLevel & 0xff) == 0xff) { - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_PCIE_DEVICE); - DBGPRINT(RT_DEBUG_TRACE, - ("====> PCIePowerSaveLevel = 0x%x.\n", - PCIePowerSaveLevel)); - return; - } else { - PCIePowerSaveLevel &= 0x3; - RT28xx_EEPROM_READ16(pAd, 0x24, data2); - - if (! - (((data2 & 0xff00) == 0x9200) - && ((data2 & 0x80) != 0))) { - if (PCIePowerSaveLevel > 1) - PCIePowerSaveLevel = 1; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("====> Write 0x83 = 0x%x.\n", - PCIePowerSaveLevel)); - AsicSendCommandToMcu(pAd, 0x83, 0xff, - (u8)PCIePowerSaveLevel, 0x00); - RT28xx_EEPROM_READ16(pAd, 0x22, PCIePowerSaveLevel); - PCIePowerSaveLevel &= 0xff; - PCIePowerSaveLevel = PCIePowerSaveLevel >> 6; - switch (PCIePowerSaveLevel) { - case 0: /* Only support L0 */ - pAd->LnkCtrlBitMask = 0; - break; - case 1: /* Only enable L0s */ - pAd->LnkCtrlBitMask = 1; - break; - case 2: /* enable L1, L0s */ - pAd->LnkCtrlBitMask = 3; - break; - case 3: /* sync with host clk and enable L1, L0s */ - pAd->LnkCtrlBitMask = 0x103; - break; - } - RT28xx_EEPROM_READ16(pAd, 0x24, data2); - if ((PCIePowerSaveLevel & 0xff) != 0xff) { - PCIePowerSaveLevel &= 0x3; - - if (! - (((data2 & 0xff00) == 0x9200) - && ((data2 & 0x80) != 0))) { - if (PCIePowerSaveLevel > 1) - PCIePowerSaveLevel = 1; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("====> rt28xx Write 0x83 Command = 0x%x.\n", - PCIePowerSaveLevel)); - - AsicSendCommandToMcu(pAd, 0x83, 0xff, - (u8)PCIePowerSaveLevel, - 0x00); - } - DBGPRINT(RT_DEBUG_TRACE, - ("====> LnkCtrlBitMask = 0x%x.\n", - pAd->LnkCtrlBitMask)); - } - } else if (IS_RT3090(pAd) || IS_RT3572(pAd) || IS_RT3390(pAd)) { - u8 LinkCtrlSetting = 0; - - /* Check 3090E special setting chip. */ - RT28xx_EEPROM_READ16(pAd, 0x24, data2); - if ((data2 == 0x9280) && ((pAd->MACVersion & 0xffff) == 0x0211)) { - pAd->b3090ESpecialChip = TRUE; - DBGPRINT_RAW(RT_DEBUG_ERROR, ("Special 3090E chip \n")); - } - - RTMP_IO_READ32(pAd, AUX_CTRL, &MacValue); - /*enable WAKE_PCIE function, which forces to enable PCIE clock when mpu interrupt asserting. */ - /*Force PCIE 125MHz CLK to toggle */ - MacValue |= 0x402; - RTMP_IO_WRITE32(pAd, AUX_CTRL, MacValue); - DBGPRINT_RAW(RT_DEBUG_ERROR, - (" AUX_CTRL = 0x%32x\n", MacValue)); - - /* for RT30xx F and after, PCIe interface, and for power solution 3 */ - if ((IS_VERSION_AFTER_F(pAd)) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode >= 2) - && (pAd->StaCfg.PSControl.field.rt30xxPowerMode <= 3)) { - RTMP_IO_READ32(pAd, AUX_CTRL, &MacValue); - DBGPRINT_RAW(RT_DEBUG_ERROR, - (" Read AUX_CTRL = 0x%x\n", MacValue)); - /* turn on bit 12. */ - /*enable 32KHz clock mode for power saving */ - MacValue |= 0x1000; - if (MacValue != 0xffffffff) { - RTMP_IO_WRITE32(pAd, AUX_CTRL, MacValue); - DBGPRINT_RAW(RT_DEBUG_ERROR, - (" Write AUX_CTRL = 0x%x\n", - MacValue)); - /* 1. if use PCIePowerSetting is 2 or 3, need to program OSC_CTRL to 0x3ff11. */ - MacValue = 0x3ff11; - RTMP_IO_WRITE32(pAd, OSC_CTRL, MacValue); - DBGPRINT_RAW(RT_DEBUG_ERROR, - (" OSC_CTRL = 0x%x\n", MacValue)); - /* 2. Write PCI register Clk ref bit */ - RTMPrt3xSetPCIePowerLinkCtrl(pAd); - } else { - /* Error read Aux_Ctrl value. Force to use solution 1 */ - DBGPRINT(RT_DEBUG_ERROR, - (" Error Value in AUX_CTRL = 0x%x\n", - MacValue)); - pAd->StaCfg.PSControl.field.rt30xxPowerMode = 1; - DBGPRINT(RT_DEBUG_ERROR, - (" Force to use power solution1 \n")); - } - } - /* 1. read setting from inf file. */ - - PCIePowerSaveLevel = - (u16)pAd->StaCfg.PSControl.field.rt30xxPowerMode; - DBGPRINT(RT_DEBUG_ERROR, - ("====> rt30xx Read PowerLevelMode = 0x%x.\n", - PCIePowerSaveLevel)); - /* 2. Check EnableNewPS. */ - if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE) - PCIePowerSaveLevel = 1; - - if (IS_VERSION_BEFORE_F(pAd) - && (pAd->b3090ESpecialChip == FALSE)) { - /* Chip Version E only allow 1, So force set 1. */ - PCIePowerSaveLevel &= 0x1; - pAd->PCIePowerSaveLevel = (u16)PCIePowerSaveLevel; - DBGPRINT(RT_DEBUG_TRACE, - ("====> rt30xx E Write 0x83 Command = 0x%x.\n", - PCIePowerSaveLevel)); - - AsicSendCommandToMcu(pAd, 0x83, 0xff, - (u8)PCIePowerSaveLevel, 0x00); - } else { - /* Chip Version F and after only allow 1 or 2 or 3. This might be modified after new chip version come out. */ - if (! - ((PCIePowerSaveLevel == 1) - || (PCIePowerSaveLevel == 3))) - PCIePowerSaveLevel = 1; - DBGPRINT(RT_DEBUG_ERROR, - ("====> rt30xx F Write 0x83 Command = 0x%x.\n", - PCIePowerSaveLevel)); - pAd->PCIePowerSaveLevel = (u16)PCIePowerSaveLevel; - /* for 3090F , we need to add high-byte arg for 0x83 command to indicate the link control setting in */ - /* PCI Configuration Space. Because firmware can't read PCI Configuration Space */ - if ((pAd->Rt3xxRalinkLinkCtrl & 0x2) - && (pAd->Rt3xxHostLinkCtrl & 0x2)) { - LinkCtrlSetting = 1; - } - DBGPRINT(RT_DEBUG_TRACE, - ("====> rt30xxF LinkCtrlSetting = 0x%x.\n", - LinkCtrlSetting)); - AsicSendCommandToMcu(pAd, 0x83, 0xff, - (u8)PCIePowerSaveLevel, - LinkCtrlSetting); - } - } - /* Find Ralink PCIe Device's Express Capability Offset */ - pos = pci_find_capability(pObj->pci_dev, PCI_CAP_ID_EXP); - - if (pos != 0) { - /* Ralink PCIe Device's Link Control Register Offset */ - pAd->RLnkCtrlOffset = pos + PCI_EXP_LNKCTL; - pci_read_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset, - ®16); - Configuration = le2cpu16(reg16); - DBGPRINT(RT_DEBUG_TRACE, - ("Read (Ralink PCIe Link Control Register) offset 0x%x = 0x%x\n", - pAd->RLnkCtrlOffset, Configuration)); - pAd->RLnkCtrlConfiguration = (Configuration & 0x103); - Configuration &= 0xfefc; - Configuration |= (0x0); -#ifdef RT2860 - if ((pObj->DeviceID == NIC2860_PCIe_DEVICE_ID) - || (pObj->DeviceID == NIC2790_PCIe_DEVICE_ID)) { - reg16 = cpu2le16(Configuration); - pci_write_config_word(pObj->pci_dev, - pAd->RLnkCtrlOffset, reg16); - DBGPRINT(RT_DEBUG_TRACE, - ("Write (Ralink PCIe Link Control Register) offset 0x%x = 0x%x\n", - pos + PCI_EXP_LNKCTL, Configuration)); - } -#endif /* RT2860 // */ - - RTMPFindHostPCIDev(pAd); - if (pObj->parent_pci_dev) { - u16 vendor_id; - - pci_read_config_word(pObj->parent_pci_dev, - PCI_VENDOR_ID, &vendor_id); - vendor_id = le2cpu16(vendor_id); - if (vendor_id == PCIBUS_INTEL_VENDOR) { - bFindIntel = TRUE; - RTMP_SET_PSFLAG(pAd, fRTMP_PS_TOGGLE_L1); - } - /* Find PCI-to-PCI Bridge Express Capability Offset */ - pos = - pci_find_capability(pObj->parent_pci_dev, - PCI_CAP_ID_EXP); - - if (pos != 0) { - BOOLEAN bChange = FALSE; - /* PCI-to-PCI Bridge Link Control Register Offset */ - pAd->HostLnkCtrlOffset = pos + PCI_EXP_LNKCTL; - pci_read_config_word(pObj->parent_pci_dev, - pAd->HostLnkCtrlOffset, - ®16); - Configuration = le2cpu16(reg16); - DBGPRINT(RT_DEBUG_TRACE, - ("Read (Host PCI-to-PCI Bridge Link Control Register) offset 0x%x = 0x%x\n", - pAd->HostLnkCtrlOffset, - Configuration)); - pAd->HostLnkCtrlConfiguration = - (Configuration & 0x103); - Configuration &= 0xfefc; - Configuration |= (0x0); - - switch (pObj->DeviceID) { -#ifdef RT2860 - case NIC2860_PCIe_DEVICE_ID: - case NIC2790_PCIe_DEVICE_ID: - bChange = TRUE; - break; -#endif /* RT2860 // */ -#ifdef RT3090 - case NIC3090_PCIe_DEVICE_ID: - case NIC3091_PCIe_DEVICE_ID: - case NIC3092_PCIe_DEVICE_ID: - if (bFindIntel == FALSE) - bChange = TRUE; - break; -#endif /* RT3090 // */ - default: - break; - } - - if (bChange) { - reg16 = cpu2le16(Configuration); - pci_write_config_word(pObj-> - parent_pci_dev, - pAd-> - HostLnkCtrlOffset, - reg16); - DBGPRINT(RT_DEBUG_TRACE, - ("Write (Host PCI-to-PCI Bridge Link Control Register) offset 0x%x = 0x%x\n", - pAd->HostLnkCtrlOffset, - Configuration)); - } - } else { - pAd->HostLnkCtrlOffset = 0; - DBGPRINT(RT_DEBUG_ERROR, - ("%s: cannot find PCI-to-PCI Bridge PCI Express Capability!\n", - __func__)); - } - } - } else { - pAd->RLnkCtrlOffset = 0; - pAd->HostLnkCtrlOffset = 0; - DBGPRINT(RT_DEBUG_ERROR, - ("%s: cannot find Ralink PCIe Device's PCI Express Capability!\n", - __func__)); - } - - if (bFindIntel == FALSE) { - DBGPRINT(RT_DEBUG_TRACE, - ("Doesn't find Intel PCI host controller. \n")); - /* Doesn't switch L0, L1, So set PCIePowerSaveLevel to 0xff */ - pAd->PCIePowerSaveLevel = 0xff; - if ((pAd->RLnkCtrlOffset != 0) -#ifdef RT3090 - && ((pObj->DeviceID == NIC3090_PCIe_DEVICE_ID) - || (pObj->DeviceID == NIC3091_PCIe_DEVICE_ID) - || (pObj->DeviceID == NIC3092_PCIe_DEVICE_ID)) -#endif /* RT3090 // */ - ) { - pci_read_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset, - ®16); - Configuration = le2cpu16(reg16); - DBGPRINT(RT_DEBUG_TRACE, - ("Read (Ralink 30xx PCIe Link Control Register) offset 0x%x = 0x%x\n", - pAd->RLnkCtrlOffset, Configuration)); - pAd->RLnkCtrlConfiguration = (Configuration & 0x103); - Configuration &= 0xfefc; - Configuration |= (0x0); - reg16 = cpu2le16(Configuration); - pci_write_config_word(pObj->pci_dev, - pAd->RLnkCtrlOffset, reg16); - DBGPRINT(RT_DEBUG_TRACE, - ("Write (Ralink PCIe Link Control Register) offset 0x%x = 0x%x\n", - pos + PCI_EXP_LNKCTL, Configuration)); - } - } -} - -void RTMPFindHostPCIDev(struct rt_rtmp_adapter *pAd) -{ - u16 reg16; - u8 reg8; - u32 DevFn; - struct pci_dev *pPci_dev; - struct os_cookie *pObj; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) - return; - - DBGPRINT(RT_DEBUG_TRACE, ("%s.===>\n", __func__)); - - pObj->parent_pci_dev = NULL; - if (pObj->pci_dev->bus->parent) { - for (DevFn = 0; DevFn < 255; DevFn++) { - pPci_dev = - pci_get_slot(pObj->pci_dev->bus->parent, DevFn); - if (pPci_dev) { - pci_read_config_word(pPci_dev, PCI_CLASS_DEVICE, - ®16); - reg16 = le2cpu16(reg16); - pci_read_config_byte(pPci_dev, PCI_CB_CARD_BUS, - ®8); - if ((reg16 == PCI_CLASS_BRIDGE_PCI) - && (reg8 == pObj->pci_dev->bus->number)) { - pObj->parent_pci_dev = pPci_dev; - } - } - } - } -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - Level = RESTORE_HALT : Restore PCI host and Ralink PCIe Link Control field to its default value. - Level = Other Value : Restore from dot11 power save or radio off status. And force PCI host Link Control fields to 0x1 - - ======================================================================== -*/ -void RTMPPCIeLinkCtrlValueRestore(struct rt_rtmp_adapter *pAd, u8 Level) -{ - u16 PCIePowerSaveLevel, reg16; - u16 Configuration; - struct os_cookie *pObj; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) - return; - -#ifdef RT2860 - if (!((pObj->DeviceID == NIC2860_PCIe_DEVICE_ID) - || (pObj->DeviceID == NIC2790_PCIe_DEVICE_ID))) - return; -#endif /* RT2860 // */ - /* Check PSControl Configuration */ - if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE) - return; - - /*3090 will not execute the following codes. */ - /* Check interface : If not PCIe interface, return. */ - -#ifdef RT3090 - if ((pObj->DeviceID == NIC3090_PCIe_DEVICE_ID) - || (pObj->DeviceID == NIC3091_PCIe_DEVICE_ID) - || (pObj->DeviceID == NIC3092_PCIe_DEVICE_ID)) - return; -#endif /* RT3090 // */ - - DBGPRINT(RT_DEBUG_TRACE, ("%s.===>\n", __func__)); - PCIePowerSaveLevel = pAd->PCIePowerSaveLevel; - if ((PCIePowerSaveLevel & 0xff) == 0xff) { - DBGPRINT(RT_DEBUG_TRACE, ("return \n")); - return; - } - - if (pObj->parent_pci_dev && (pAd->HostLnkCtrlOffset != 0)) { - PCI_REG_READ_WORD(pObj->parent_pci_dev, pAd->HostLnkCtrlOffset, - Configuration); - if ((Configuration != 0) && (Configuration != 0xFFFF)) { - Configuration &= 0xfefc; - /* If call from interface down, restore to original setting. */ - if (Level == RESTORE_CLOSE) - Configuration |= pAd->HostLnkCtrlConfiguration; - else - Configuration |= 0x0; - PCI_REG_WIRTE_WORD(pObj->parent_pci_dev, - pAd->HostLnkCtrlOffset, - Configuration); - DBGPRINT(RT_DEBUG_TRACE, - ("Restore PCI host : offset 0x%x = 0x%x\n", - pAd->HostLnkCtrlOffset, Configuration)); - } else - DBGPRINT(RT_DEBUG_ERROR, - ("Restore PCI host : PCI_REG_READ_WORD failed (Configuration = 0x%x)\n", - Configuration)); - } - - if (pObj->pci_dev && (pAd->RLnkCtrlOffset != 0)) { - PCI_REG_READ_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset, - Configuration); - if ((Configuration != 0) && (Configuration != 0xFFFF)) { - Configuration &= 0xfefc; - /* If call from interface down, restore to original setting. */ - if (Level == RESTORE_CLOSE) - Configuration |= pAd->RLnkCtrlConfiguration; - else - Configuration |= 0x0; - PCI_REG_WIRTE_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset, - Configuration); - DBGPRINT(RT_DEBUG_TRACE, - ("Restore Ralink : offset 0x%x = 0x%x\n", - pAd->RLnkCtrlOffset, Configuration)); - } else - DBGPRINT(RT_DEBUG_ERROR, - ("Restore Ralink : PCI_REG_READ_WORD failed (Configuration = 0x%x)\n", - Configuration)); - } - - DBGPRINT(RT_DEBUG_TRACE, ("%s <===\n", __func__)); -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - Max : limit Host PCI and Ralink PCIe device's LINK CONTROL field's value. - Because now frequently set our device to mode 1 or mode 3 will cause problem. - - ======================================================================== -*/ -void RTMPPCIeLinkCtrlSetting(struct rt_rtmp_adapter *pAd, u16 Max) -{ - u16 PCIePowerSaveLevel, reg16; - u16 Configuration; - struct os_cookie *pObj; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) - return; - -#ifdef RT2860 - if (!((pObj->DeviceID == NIC2860_PCIe_DEVICE_ID) - || (pObj->DeviceID == NIC2790_PCIe_DEVICE_ID))) - return; -#endif /* RT2860 // */ - /* Check PSControl Configuration */ - if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE) - return; - - /* Check interface : If not PCIe interface, return. */ - /*Block 3090 to enter the following function */ - -#ifdef RT3090 - if ((pObj->DeviceID == NIC3090_PCIe_DEVICE_ID) - || (pObj->DeviceID == NIC3091_PCIe_DEVICE_ID) - || (pObj->DeviceID == NIC3092_PCIe_DEVICE_ID)) - return; -#endif /* RT3090 // */ - if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP)) { - DBGPRINT(RT_DEBUG_INFO, - ("RTMPPCIePowerLinkCtrl return on fRTMP_PS_CAN_GO_SLEEP flag\n")); - return; - } - - DBGPRINT(RT_DEBUG_TRACE, ("%s===>\n", __func__)); - PCIePowerSaveLevel = pAd->PCIePowerSaveLevel; - if ((PCIePowerSaveLevel & 0xff) == 0xff) { - DBGPRINT(RT_DEBUG_TRACE, ("return \n")); - return; - } - PCIePowerSaveLevel = PCIePowerSaveLevel >> 6; - - /* Skip non-exist deice right away */ - if (pObj->parent_pci_dev && (pAd->HostLnkCtrlOffset != 0)) { - PCI_REG_READ_WORD(pObj->parent_pci_dev, pAd->HostLnkCtrlOffset, - Configuration); - switch (PCIePowerSaveLevel) { - case 0: - /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 00 */ - Configuration &= 0xfefc; - break; - case 1: - /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 01 */ - Configuration &= 0xfefc; - Configuration |= 0x1; - break; - case 2: - /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 11 */ - Configuration &= 0xfefc; - Configuration |= 0x3; - break; - case 3: - /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 11 and bit 8 of LinkControl of 2892 to 1 */ - Configuration &= 0xfefc; - Configuration |= 0x103; - break; - } - PCI_REG_WIRTE_WORD(pObj->parent_pci_dev, pAd->HostLnkCtrlOffset, - Configuration); - DBGPRINT(RT_DEBUG_TRACE, - ("Write PCI host offset 0x%x = 0x%x\n", - pAd->HostLnkCtrlOffset, Configuration)); - } - - if (pObj->pci_dev && (pAd->RLnkCtrlOffset != 0)) { - /* first 2892 chip not allow to frequently set mode 3. will cause hang problem. */ - if (PCIePowerSaveLevel > Max) - PCIePowerSaveLevel = Max; - - PCI_REG_READ_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset, - Configuration); - switch (PCIePowerSaveLevel) { - case 0: - /* No PCI power safe */ - /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 00 . */ - Configuration &= 0xfefc; - break; - case 1: - /* L0 */ - /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 01 . */ - Configuration &= 0xfefc; - Configuration |= 0x1; - break; - case 2: - /* L0 and L1 */ - /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 11 */ - Configuration &= 0xfefc; - Configuration |= 0x3; - break; - case 3: - /* L0 , L1 and clock management. */ - /* Set b0 and b1 of LinkControl (both 2892 and PCIe bridge) to 11 and bit 8 of LinkControl of 2892 to 1 */ - Configuration &= 0xfefc; - Configuration |= 0x103; - pAd->bPCIclkOff = TRUE; - break; - } - PCI_REG_WIRTE_WORD(pObj->pci_dev, pAd->RLnkCtrlOffset, - Configuration); - DBGPRINT(RT_DEBUG_TRACE, - ("Write Ralink device : offset 0x%x = 0x%x\n", - pAd->RLnkCtrlOffset, Configuration)); - } - - DBGPRINT(RT_DEBUG_TRACE, ("RTMPPCIePowerLinkCtrl <==============\n")); -} - -/* - ======================================================================== - - Routine Description: - 1. Write a PCI register for rt30xx power solution 3 - - ======================================================================== -*/ -void RTMPrt3xSetPCIePowerLinkCtrl(struct rt_rtmp_adapter *pAd) -{ - - unsigned long HostConfiguration = 0; - unsigned long Configuration; - struct os_cookie *pObj; - int pos; - u16 reg16; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - DBGPRINT(RT_DEBUG_INFO, - ("RTMPrt3xSetPCIePowerLinkCtrl.===> %lx\n", - pAd->StaCfg.PSControl.word)); - - /* Check PSControl Configuration */ - if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE) - return; - RTMPFindHostPCIDev(pAd); - if (pObj->parent_pci_dev) { - /* Find PCI-to-PCI Bridge Express Capability Offset */ - pos = pci_find_capability(pObj->parent_pci_dev, PCI_CAP_ID_EXP); - - if (pos != 0) - pAd->HostLnkCtrlOffset = pos + PCI_EXP_LNKCTL; - - /* If configured to turn on L1. */ - HostConfiguration = 0; - if (pAd->StaCfg.PSControl.field.rt30xxForceASPMTest == 1) { - DBGPRINT(RT_DEBUG_TRACE, ("Enter,PSM : Force ASPM\n")); - - /* Skip non-exist device right away */ - if ((pAd->HostLnkCtrlOffset != 0)) { - PCI_REG_READ_WORD(pObj->parent_pci_dev, - pAd->HostLnkCtrlOffset, - HostConfiguration); - /* Prepare Configuration to write to Host */ - HostConfiguration |= 0x3; - PCI_REG_WIRTE_WORD(pObj->parent_pci_dev, - pAd->HostLnkCtrlOffset, - HostConfiguration); - pAd->Rt3xxHostLinkCtrl = HostConfiguration; - /* Because in rt30xxForceASPMTest Mode, Force turn on L0s, L1. */ - /* Fix HostConfiguration bit0:1 = 0x3 for later use. */ - HostConfiguration = 0x3; - DBGPRINT(RT_DEBUG_TRACE, - ("PSM : Force ASPM : " - "Host device L1/L0s Value = 0x%lx\n", - HostConfiguration)); - } - } else if (pAd->StaCfg.PSControl.field.rt30xxFollowHostASPM == - 1) { - - /* Skip non-exist deice right away */ - if ((pAd->HostLnkCtrlOffset != 0)) { - PCI_REG_READ_WORD(pObj->parent_pci_dev, - pAd->HostLnkCtrlOffset, - HostConfiguration); - pAd->Rt3xxHostLinkCtrl = HostConfiguration; - HostConfiguration &= 0x3; - DBGPRINT(RT_DEBUG_TRACE, - ("PSM : Follow Host ASPM : " - "Host device L1/L0s Value = 0x%lx\n", - HostConfiguration)); - } - } - } - /* Prepare to write Ralink setting. */ - /* Find Ralink PCIe Device's Express Capability Offset */ - pos = pci_find_capability(pObj->pci_dev, PCI_CAP_ID_EXP); - - if (pos != 0) { - /* Ralink PCIe Device's Link Control Register Offset */ - pAd->RLnkCtrlOffset = pos + PCI_EXP_LNKCTL; - pci_read_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset, - ®16); - Configuration = le2cpu16(reg16); - DBGPRINT(RT_DEBUG_TRACE, - ("Read (Ralink PCIe Link Control Register) " - "offset 0x%x = 0x%lx\n", - pAd->RLnkCtrlOffset, Configuration)); - Configuration |= 0x100; - if ((pAd->StaCfg.PSControl.field.rt30xxFollowHostASPM == 1) - || (pAd->StaCfg.PSControl.field.rt30xxForceASPMTest == 1)) { - switch (HostConfiguration) { - case 0: - Configuration &= 0xffffffc; - break; - case 1: - Configuration &= 0xffffffc; - Configuration |= 0x1; - break; - case 2: - Configuration &= 0xffffffc; - Configuration |= 0x2; - break; - case 3: - Configuration |= 0x3; - break; - } - } - reg16 = cpu2le16(Configuration); - pci_write_config_word(pObj->pci_dev, pAd->RLnkCtrlOffset, - reg16); - pAd->Rt3xxRalinkLinkCtrl = Configuration; - DBGPRINT(RT_DEBUG_TRACE, - ("PSM :Write Ralink device L1/L0s Value = 0x%lx\n", - Configuration)); - } - DBGPRINT(RT_DEBUG_INFO, - ("PSM :RTMPrt3xSetPCIePowerLinkCtrl <==============\n")); -} diff --git a/trunk/drivers/staging/rt2860/rt_config.h b/trunk/drivers/staging/rt2860/rt_config.h deleted file mode 100644 index d1adef8948af..000000000000 --- a/trunk/drivers/staging/rt2860/rt_config.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt_config.h - - Abstract: - Central header file to maintain all include files for all NDIS - miniport driver routines. - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Paul Lin 08-01-2002 created - -*/ -#ifndef __RT_CONFIG_H__ -#define __RT_CONFIG_H__ - -#include "rtmp_type.h" -#include "rtmp_os.h" - -#include "rtmp_def.h" -#include "rtmp_chip.h" -#include "rtmp_timer.h" - -#include "oid.h" -#include "mlme.h" -#include "wpa.h" -#include "crypt_md5.h" -#include "crypt_sha2.h" -#include "crypt_hmac.h" -#include "rtmp.h" -#include "ap.h" -#include "dfs.h" -#include "chlist.h" -#include "spectrum.h" - -#include "eeprom.h" -#if defined(RTMP_PCI_SUPPORT) || defined(RTMP_USB_SUPPORT) -#include "rtmp_mcu.h" -#endif - -#ifdef IGMP_SNOOP_SUPPORT -#include "igmp_snoop.h" -#endif /* IGMP_SNOOP_SUPPORT // */ - -#endif /* __RT_CONFIG_H__ */ diff --git a/trunk/drivers/staging/rt2860/rt_linux.c b/trunk/drivers/staging/rt2860/rt_linux.c deleted file mode 100644 index 1583347fcd52..000000000000 --- a/trunk/drivers/staging/rt2860/rt_linux.c +++ /dev/null @@ -1,1367 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - */ - -#include -#include -#include -#include "rt_config.h" - -unsigned long RTDebugLevel = RT_DEBUG_ERROR; - -/* for wireless system event message */ -char const *pWirelessSysEventText[IW_SYS_EVENT_TYPE_NUM] = { - /* system status event */ - "had associated successfully", /* IW_ASSOC_EVENT_FLAG */ - "had disassociated", /* IW_DISASSOC_EVENT_FLAG */ - "had deauthenticated", /* IW_DEAUTH_EVENT_FLAG */ - "had been aged-out and disassociated", /* IW_AGEOUT_EVENT_FLAG */ - "occurred CounterMeasures attack", /* IW_COUNTER_MEASURES_EVENT_FLAG */ - "occurred replay counter different in Key Handshaking", /* IW_REPLAY_COUNTER_DIFF_EVENT_FLAG */ - "occurred RSNIE different in Key Handshaking", /* IW_RSNIE_DIFF_EVENT_FLAG */ - "occurred MIC different in Key Handshaking", /* IW_MIC_DIFF_EVENT_FLAG */ - "occurred ICV error in RX", /* IW_ICV_ERROR_EVENT_FLAG */ - "occurred MIC error in RX", /* IW_MIC_ERROR_EVENT_FLAG */ - "Group Key Handshaking timeout", /* IW_GROUP_HS_TIMEOUT_EVENT_FLAG */ - "Pairwise Key Handshaking timeout", /* IW_PAIRWISE_HS_TIMEOUT_EVENT_FLAG */ - "RSN IE sanity check failure", /* IW_RSNIE_SANITY_FAIL_EVENT_FLAG */ - "set key done in WPA/WPAPSK", /* IW_SET_KEY_DONE_WPA1_EVENT_FLAG */ - "set key done in WPA2/WPA2PSK", /* IW_SET_KEY_DONE_WPA2_EVENT_FLAG */ - "connects with our wireless client", /* IW_STA_LINKUP_EVENT_FLAG */ - "disconnects with our wireless client", /* IW_STA_LINKDOWN_EVENT_FLAG */ - "scan completed" /* IW_SCAN_COMPLETED_EVENT_FLAG */ - "scan terminate! Busy! Enqueue fail!" /* IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG */ -}; - -/* for wireless IDS_spoof_attack event message */ -char const *pWirelessSpoofEventText[IW_SPOOF_EVENT_TYPE_NUM] = { - "detected conflict SSID", /* IW_CONFLICT_SSID_EVENT_FLAG */ - "detected spoofed association response", /* IW_SPOOF_ASSOC_RESP_EVENT_FLAG */ - "detected spoofed reassociation responses", /* IW_SPOOF_REASSOC_RESP_EVENT_FLAG */ - "detected spoofed probe response", /* IW_SPOOF_PROBE_RESP_EVENT_FLAG */ - "detected spoofed beacon", /* IW_SPOOF_BEACON_EVENT_FLAG */ - "detected spoofed disassociation", /* IW_SPOOF_DISASSOC_EVENT_FLAG */ - "detected spoofed authentication", /* IW_SPOOF_AUTH_EVENT_FLAG */ - "detected spoofed deauthentication", /* IW_SPOOF_DEAUTH_EVENT_FLAG */ - "detected spoofed unknown management frame", /* IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG */ - "detected replay attack" /* IW_REPLAY_ATTACK_EVENT_FLAG */ -}; - -/* for wireless IDS_flooding_attack event message */ -char const *pWirelessFloodEventText[IW_FLOOD_EVENT_TYPE_NUM] = { - "detected authentication flooding", /* IW_FLOOD_AUTH_EVENT_FLAG */ - "detected association request flooding", /* IW_FLOOD_ASSOC_REQ_EVENT_FLAG */ - "detected reassociation request flooding", /* IW_FLOOD_REASSOC_REQ_EVENT_FLAG */ - "detected probe request flooding", /* IW_FLOOD_PROBE_REQ_EVENT_FLAG */ - "detected disassociation flooding", /* IW_FLOOD_DISASSOC_EVENT_FLAG */ - "detected deauthentication flooding", /* IW_FLOOD_DEAUTH_EVENT_FLAG */ - "detected 802.1x eap-request flooding" /* IW_FLOOD_EAP_REQ_EVENT_FLAG */ -}; - -/* timeout -- ms */ -void RTMP_SetPeriodicTimer(struct timer_list *pTimer, - IN unsigned long timeout) -{ - timeout = ((timeout * OS_HZ) / 1000); - pTimer->expires = jiffies + timeout; - add_timer(pTimer); -} - -/* convert NdisMInitializeTimer --> RTMP_OS_Init_Timer */ -void RTMP_OS_Init_Timer(struct rt_rtmp_adapter *pAd, - struct timer_list *pTimer, - IN TIMER_FUNCTION function, void *data) -{ - init_timer(pTimer); - pTimer->data = (unsigned long)data; - pTimer->function = function; -} - -void RTMP_OS_Add_Timer(struct timer_list *pTimer, - IN unsigned long timeout) -{ - if (timer_pending(pTimer)) - return; - - timeout = ((timeout * OS_HZ) / 1000); - pTimer->expires = jiffies + timeout; - add_timer(pTimer); -} - -void RTMP_OS_Mod_Timer(struct timer_list *pTimer, - IN unsigned long timeout) -{ - timeout = ((timeout * OS_HZ) / 1000); - mod_timer(pTimer, jiffies + timeout); -} - -void RTMP_OS_Del_Timer(struct timer_list *pTimer, OUT BOOLEAN *pCancelled) -{ - if (timer_pending(pTimer)) { - *pCancelled = del_timer_sync(pTimer); - } else { - *pCancelled = TRUE; - } - -} - -void RTMP_OS_Release_Packet(struct rt_rtmp_adapter *pAd, struct rt_queue_entry *pEntry) -{ - /*RTMPFreeNdisPacket(pAd, (struct sk_buff *)pEntry); */ -} - -/* Unify all delay routine by using udelay */ -void RTMPusecDelay(unsigned long usec) -{ - unsigned long i; - - for (i = 0; i < (usec / 50); i++) - udelay(50); - - if (usec % 50) - udelay(usec % 50); -} - -void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time) -{ - time->u.LowPart = jiffies; -} - -/* pAd MUST allow to be NULL */ -int os_alloc_mem(struct rt_rtmp_adapter *pAd, u8 ** mem, unsigned long size) -{ - *mem = kmalloc(size, GFP_ATOMIC); - if (*mem) - return NDIS_STATUS_SUCCESS; - else - return NDIS_STATUS_FAILURE; -} - -/* pAd MUST allow to be NULL */ -int os_free_mem(struct rt_rtmp_adapter *pAd, void *mem) -{ - - ASSERT(mem); - kfree(mem); - return NDIS_STATUS_SUCCESS; -} - -void *RtmpOSNetPktAlloc(struct rt_rtmp_adapter *pAd, IN int size) -{ - struct sk_buff *skb; - /* Add 2 more bytes for ip header alignment */ - skb = dev_alloc_skb(size + 2); - - return (void *)skb; -} - -void *RTMP_AllocateFragPacketBuffer(struct rt_rtmp_adapter *pAd, - unsigned long Length) -{ - struct sk_buff *pkt; - - pkt = dev_alloc_skb(Length); - - if (pkt == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("can't allocate frag rx %ld size packet\n", Length)); - } - - if (pkt) { - RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS); - } - - return (void *)pkt; -} - -void *RTMP_AllocateTxPacketBuffer(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress) -{ - struct sk_buff *pkt; - - pkt = dev_alloc_skb(Length); - - if (pkt == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("can't allocate tx %ld size packet\n", Length)); - } - - if (pkt) { - RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS); - *VirtualAddress = (void *)pkt->data; - } else { - *VirtualAddress = (void *)NULL; - } - - return (void *)pkt; -} - -void build_tx_packet(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 *pFrame, unsigned long FrameLen) -{ - - struct sk_buff *pTxPkt; - - ASSERT(pPacket); - pTxPkt = RTPKT_TO_OSPKT(pPacket); - - NdisMoveMemory(skb_put(pTxPkt, FrameLen), pFrame, FrameLen); -} - -void RTMPFreeAdapter(struct rt_rtmp_adapter *pAd) -{ - struct os_cookie *os_cookie; - int index; - - os_cookie = (struct os_cookie *)pAd->OS_Cookie; - - kfree(pAd->BeaconBuf); - - NdisFreeSpinLock(&pAd->MgmtRingLock); - -#ifdef RTMP_MAC_PCI - NdisFreeSpinLock(&pAd->RxRingLock); -#ifdef RT3090 - NdisFreeSpinLock(&pAd->McuCmdLock); -#endif /* RT3090 // */ -#endif /* RTMP_MAC_PCI // */ - - for (index = 0; index < NUM_OF_TX_RING; index++) { - NdisFreeSpinLock(&pAd->TxSwQueueLock[index]); - NdisFreeSpinLock(&pAd->DeQueueLock[index]); - pAd->DeQueueRunning[index] = FALSE; - } - - NdisFreeSpinLock(&pAd->irq_lock); - - release_firmware(pAd->firmware); - - vfree(pAd); /* pci_free_consistent(os_cookie->pci_dev,sizeof(struct rt_rtmp_adapter),pAd,os_cookie->pAd_pa); */ - kfree(os_cookie); -} - -BOOLEAN OS_Need_Clone_Packet(void) -{ - return FALSE; -} - -/* - ======================================================================== - - Routine Description: - clone an input NDIS PACKET to another one. The new internally created NDIS PACKET - must have only one NDIS BUFFER - return - byte copied. 0 means can't create NDIS PACKET - NOTE: internally created char should be destroyed by RTMPFreeNdisPacket - - Arguments: - pAd Pointer to our adapter - pInsAMSDUHdr EWC A-MSDU format has extra 14-bytes header. if TRUE, insert this 14-byte hdr in front of MSDU. - *pSrcTotalLen return total packet length. This length is calculated with 802.3 format packet. - - Return Value: - NDIS_STATUS_SUCCESS - NDIS_STATUS_FAILURE - - Note: - - ======================================================================== -*/ -int RTMPCloneNdisPacket(struct rt_rtmp_adapter *pAd, - IN BOOLEAN pInsAMSDUHdr, - void *pInPacket, - void **ppOutPacket) -{ - - struct sk_buff *pkt; - - ASSERT(pInPacket); - ASSERT(ppOutPacket); - - /* 1. Allocate a packet */ - pkt = dev_alloc_skb(2048); - - if (pkt == NULL) { - return NDIS_STATUS_FAILURE; - } - - skb_put(pkt, GET_OS_PKT_LEN(pInPacket)); - NdisMoveMemory(pkt->data, GET_OS_PKT_DATAPTR(pInPacket), - GET_OS_PKT_LEN(pInPacket)); - *ppOutPacket = OSPKT_TO_RTPKT(pkt); - - RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS); - - printk(KERN_DEBUG "###Clone###\n"); - - return NDIS_STATUS_SUCCESS; -} - -/* the allocated NDIS PACKET must be freed via RTMPFreeNdisPacket() */ -int RTMPAllocateNdisPacket(struct rt_rtmp_adapter *pAd, - void **ppPacket, - u8 *pHeader, - u32 HeaderLen, - u8 *pData, u32 DataLen) -{ - void *pPacket; - ASSERT(pData); - ASSERT(DataLen); - - /* 1. Allocate a packet */ - pPacket = - (void **) dev_alloc_skb(HeaderLen + DataLen + - RTMP_PKT_TAIL_PADDING); - if (pPacket == NULL) { - *ppPacket = NULL; - pr_devel("RTMPAllocateNdisPacket Fail\n"); - - return NDIS_STATUS_FAILURE; - } - /* 2. clone the frame content */ - if (HeaderLen > 0) - NdisMoveMemory(GET_OS_PKT_DATAPTR(pPacket), pHeader, HeaderLen); - if (DataLen > 0) - NdisMoveMemory(GET_OS_PKT_DATAPTR(pPacket) + HeaderLen, pData, - DataLen); - - /* 3. update length of packet */ - skb_put(GET_OS_PKT_TYPE(pPacket), HeaderLen + DataLen); - - RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS); -/* printk("%s : pPacket = %p, len = %d\n", __func__, pPacket, GET_OS_PKT_LEN(pPacket)); */ - *ppPacket = pPacket; - return NDIS_STATUS_SUCCESS; -} - -/* - ======================================================================== - Description: - This routine frees a miniport internally allocated char and its - corresponding NDIS_BUFFER and allocated memory. - ======================================================================== -*/ -void RTMPFreeNdisPacket(struct rt_rtmp_adapter *pAd, void *pPacket) -{ - dev_kfree_skb_any(RTPKT_TO_OSPKT(pPacket)); -} - -/* IRQL = DISPATCH_LEVEL */ -/* NOTE: we do have an assumption here, that Byte0 and Byte1 always reasid at the same */ -/* scatter gather buffer */ -int Sniff2BytesFromNdisBuffer(char *pFirstBuffer, - u8 DesiredOffset, - u8 *pByte0, u8 *pByte1) -{ - *pByte0 = *(u8 *)(pFirstBuffer + DesiredOffset); - *pByte1 = *(u8 *)(pFirstBuffer + DesiredOffset + 1); - - return NDIS_STATUS_SUCCESS; -} - -void RTMP_QueryPacketInfo(void *pPacket, - struct rt_packet_info *pPacketInfo, - u8 **pSrcBufVA, u32 * pSrcBufLen) -{ - pPacketInfo->BufferCount = 1; - pPacketInfo->pFirstBuffer = (char *)GET_OS_PKT_DATAPTR(pPacket); - pPacketInfo->PhysicalBufferCount = 1; - pPacketInfo->TotalPacketLength = GET_OS_PKT_LEN(pPacket); - - *pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket); - *pSrcBufLen = GET_OS_PKT_LEN(pPacket); -} - -void RTMP_QueryNextPacketInfo(void **ppPacket, - struct rt_packet_info *pPacketInfo, - u8 **pSrcBufVA, u32 * pSrcBufLen) -{ - void *pPacket = NULL; - - if (*ppPacket) - pPacket = GET_OS_PKT_NEXT(*ppPacket); - - if (pPacket) { - pPacketInfo->BufferCount = 1; - pPacketInfo->pFirstBuffer = - (char *)GET_OS_PKT_DATAPTR(pPacket); - pPacketInfo->PhysicalBufferCount = 1; - pPacketInfo->TotalPacketLength = GET_OS_PKT_LEN(pPacket); - - *pSrcBufVA = GET_OS_PKT_DATAPTR(pPacket); - *pSrcBufLen = GET_OS_PKT_LEN(pPacket); - *ppPacket = GET_OS_PKT_NEXT(pPacket); - } else { - pPacketInfo->BufferCount = 0; - pPacketInfo->pFirstBuffer = NULL; - pPacketInfo->PhysicalBufferCount = 0; - pPacketInfo->TotalPacketLength = 0; - - *pSrcBufVA = NULL; - *pSrcBufLen = 0; - *ppPacket = NULL; - } -} - -void *DuplicatePacket(struct rt_rtmp_adapter *pAd, - void *pPacket, u8 FromWhichBSSID) -{ - struct sk_buff *skb; - void *pRetPacket = NULL; - u16 DataSize; - u8 *pData; - - DataSize = (u16)GET_OS_PKT_LEN(pPacket); - pData = (u8 *)GET_OS_PKT_DATAPTR(pPacket); - - skb = skb_clone(RTPKT_TO_OSPKT(pPacket), MEM_ALLOC_FLAG); - if (skb) { - skb->dev = get_netdev_from_bssid(pAd, FromWhichBSSID); - pRetPacket = OSPKT_TO_RTPKT(skb); - } - - return pRetPacket; - -} - -void *duplicate_pkt(struct rt_rtmp_adapter *pAd, - u8 *pHeader802_3, - u32 HdrLen, - u8 *pData, - unsigned long DataSize, u8 FromWhichBSSID) -{ - struct sk_buff *skb; - void *pPacket = NULL; - - skb = __dev_alloc_skb(HdrLen + DataSize + 2, MEM_ALLOC_FLAG); - if (skb != NULL) { - skb_reserve(skb, 2); - NdisMoveMemory(skb_tail_pointer(skb), pHeader802_3, HdrLen); - skb_put(skb, HdrLen); - NdisMoveMemory(skb_tail_pointer(skb), pData, DataSize); - skb_put(skb, DataSize); - skb->dev = get_netdev_from_bssid(pAd, FromWhichBSSID); - pPacket = OSPKT_TO_RTPKT(skb); - } - - return pPacket; -} - -#define TKIP_TX_MIC_SIZE 8 -void *duplicate_pkt_with_TKIP_MIC(struct rt_rtmp_adapter *pAd, - void *pPacket) -{ - struct sk_buff *skb, *newskb; - - skb = RTPKT_TO_OSPKT(pPacket); - if (skb_tailroom(skb) < TKIP_TX_MIC_SIZE) { - /* alloc a new skb and copy the packet */ - newskb = - skb_copy_expand(skb, skb_headroom(skb), TKIP_TX_MIC_SIZE, - GFP_ATOMIC); - dev_kfree_skb_any(skb); - if (newskb == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("Extend Tx.MIC for packet failed!, dropping packet!\n")); - return NULL; - } - skb = newskb; - } - - return OSPKT_TO_RTPKT(skb); -} - -void *ClonePacket(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 *pData, unsigned long DataSize) -{ - struct sk_buff *pRxPkt; - struct sk_buff *pClonedPkt; - - ASSERT(pPacket); - pRxPkt = RTPKT_TO_OSPKT(pPacket); - - /* clone the packet */ - pClonedPkt = skb_clone(pRxPkt, MEM_ALLOC_FLAG); - - if (pClonedPkt) { - /* set the correct dataptr and data len */ - pClonedPkt->dev = pRxPkt->dev; - pClonedPkt->data = pData; - pClonedPkt->len = DataSize; - skb_set_tail_pointer(pClonedPkt, DataSize) - ASSERT(DataSize < 1530); - } - return pClonedPkt; -} - -/* */ -/* change OS packet DataPtr and DataLen */ -/* */ -void update_os_packet_info(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID) -{ - struct sk_buff *pOSPkt; - - ASSERT(pRxBlk->pRxPacket); - pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket); - - pOSPkt->dev = get_netdev_from_bssid(pAd, FromWhichBSSID); - pOSPkt->data = pRxBlk->pData; - pOSPkt->len = pRxBlk->DataSize; - skb_set_tail_pointer(pOSPkt, pOSPkt->len); -} - -void wlan_802_11_to_802_3_packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, - u8 *pHeader802_3, - u8 FromWhichBSSID) -{ - struct sk_buff *pOSPkt; - - ASSERT(pRxBlk->pRxPacket); - ASSERT(pHeader802_3); - - pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket); - - pOSPkt->dev = get_netdev_from_bssid(pAd, FromWhichBSSID); - pOSPkt->data = pRxBlk->pData; - pOSPkt->len = pRxBlk->DataSize; - skb_set_tail_pointer(pOSPkt, pOSPkt->len); - - /* */ - /* copy 802.3 header */ - /* */ - /* */ - - NdisMoveMemory(skb_push(pOSPkt, LENGTH_802_3), pHeader802_3, - LENGTH_802_3); -} - -void announce_802_3_packet(struct rt_rtmp_adapter *pAd, void *pPacket) -{ - - struct sk_buff *pRxPkt; - - ASSERT(pPacket); - - pRxPkt = RTPKT_TO_OSPKT(pPacket); - - /* Push up the protocol stack */ - pRxPkt->protocol = eth_type_trans(pRxPkt, pRxPkt->dev); - - netif_rx(pRxPkt); -} - -struct rt_rtmp_sg_list * -rt_get_sg_list_from_packet(void *pPacket, struct rt_rtmp_sg_list *sg) -{ - sg->NumberOfElements = 1; - sg->Elements[0].Address = GET_OS_PKT_DATAPTR(pPacket); - sg->Elements[0].Length = GET_OS_PKT_LEN(pPacket); - return sg; -} - -void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen) -{ - unsigned char *pt; - int x; - - if (RTDebugLevel < RT_DEBUG_TRACE) - return; - - pt = pSrcBufVA; - printk(KERN_DEBUG "%s: %p, len = %d\n", str, pSrcBufVA, SrcBufLen); - for (x = 0; x < SrcBufLen; x++) { - if (x % 16 == 0) - printk(KERN_DEBUG "0x%04x : ", x); - printk(KERN_DEBUG "%02x ", ((unsigned char)pt[x])); - if (x % 16 == 15) - printk(KERN_DEBUG "\n"); - } - printk(KERN_DEBUG "\n"); -} - -/* - ======================================================================== - - Routine Description: - Send log message through wireless event - - Support standard iw_event with IWEVCUSTOM. It is used below. - - iwreq_data.data.flags is used to store event_flag that is defined by user. - iwreq_data.data.length is the length of the event log. - - The format of the event log is composed of the entry's MAC address and - the desired log message (refer to pWirelessEventText). - - ex: 11:22:33:44:55:66 has associated successfully - - p.s. The requirement of Wireless Extension is v15 or newer. - - ======================================================================== -*/ -void RTMPSendWirelessEvent(struct rt_rtmp_adapter *pAd, - u16 Event_flag, - u8 *pAddr, u8 BssIdx, char Rssi) -{ - - /*union iwreq_data wrqu; */ - char *pBuf = NULL, *pBufPtr = NULL; - u16 event, type, BufLen; - u8 event_table_len = 0; - - type = Event_flag & 0xFF00; - event = Event_flag & 0x00FF; - - switch (type) { - case IW_SYS_EVENT_FLAG_START: - event_table_len = IW_SYS_EVENT_TYPE_NUM; - break; - - case IW_SPOOF_EVENT_FLAG_START: - event_table_len = IW_SPOOF_EVENT_TYPE_NUM; - break; - - case IW_FLOOD_EVENT_FLAG_START: - event_table_len = IW_FLOOD_EVENT_TYPE_NUM; - break; - } - - if (event_table_len == 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s : The type(%0x02x) is not valid.\n", __func__, - type)); - return; - } - - if (event >= event_table_len) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s : The event(%0x02x) is not valid.\n", __func__, - event)); - return; - } - /*Allocate memory and copy the msg. */ - pBuf = kmalloc(IW_CUSTOM_MAX_LEN, GFP_ATOMIC); - if (pBuf != NULL) { - /*Prepare the payload */ - memset(pBuf, 0, IW_CUSTOM_MAX_LEN); - - pBufPtr = pBuf; - - if (pAddr) - pBufPtr += - sprintf(pBufPtr, "(RT2860) STA(%pM) ", pAddr); - else if (BssIdx < MAX_MBSSID_NUM) - pBufPtr += - sprintf(pBufPtr, "(RT2860) BSS(wlan%d) ", BssIdx); - else - pBufPtr += sprintf(pBufPtr, "(RT2860) "); - - if (type == IW_SYS_EVENT_FLAG_START) - pBufPtr += - sprintf(pBufPtr, "%s", - pWirelessSysEventText[event]); - else if (type == IW_SPOOF_EVENT_FLAG_START) - pBufPtr += - sprintf(pBufPtr, "%s (RSSI=%d)", - pWirelessSpoofEventText[event], Rssi); - else if (type == IW_FLOOD_EVENT_FLAG_START) - pBufPtr += - sprintf(pBufPtr, "%s", - pWirelessFloodEventText[event]); - else - pBufPtr += sprintf(pBufPtr, "%s", "unknown event"); - - pBufPtr[pBufPtr - pBuf] = '\0'; - BufLen = pBufPtr - pBuf; - - RtmpOSWrielessEventSend(pAd, IWEVCUSTOM, Event_flag, NULL, - (u8 *)pBuf, BufLen); - /*DBGPRINT(RT_DEBUG_TRACE, ("%s : %s\n", __func__, pBuf)); */ - - kfree(pBuf); - } else - DBGPRINT(RT_DEBUG_ERROR, - ("%s : Can't allocate memory for wireless event.\n", - __func__)); -} - -void send_monitor_packets(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk) -{ - struct sk_buff *pOSPkt; - struct rt_wlan_ng_prism2_header *ph; - int rate_index = 0; - u16 header_len = 0; - u8 temp_header[40] = { 0 }; - - u_int32_t ralinkrate[256] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108, 109, 110, 111, 112, 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, 27, 54, 81, 108, 162, 216, 243, 270, /* Last 38 */ - 54, 108, 162, 216, 324, 432, 486, 540, 14, 29, 43, 57, 87, 115, - 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, 30, 60, 90, - 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, - 600, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, - 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, - 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, - 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, - 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, - 72, 73, 74, 75, 76, 77, 78, 79, 80 - }; - - ASSERT(pRxBlk->pRxPacket); - if (pRxBlk->DataSize < 10) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s : Size is too small! (%d)\n", __func__, - pRxBlk->DataSize)); - goto err_free_sk_buff; - } - - if (pRxBlk->DataSize + sizeof(struct rt_wlan_ng_prism2_header) > - RX_BUFFER_AGGRESIZE) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s : Size is too large! (%zu)\n", __func__, - pRxBlk->DataSize + sizeof(struct rt_wlan_ng_prism2_header))); - goto err_free_sk_buff; - } - - pOSPkt = RTPKT_TO_OSPKT(pRxBlk->pRxPacket); - pOSPkt->dev = get_netdev_from_bssid(pAd, BSS0); - if (pRxBlk->pHeader->FC.Type == BTYPE_DATA) { - pRxBlk->DataSize -= LENGTH_802_11; - if ((pRxBlk->pHeader->FC.ToDs == 1) && - (pRxBlk->pHeader->FC.FrDs == 1)) - header_len = LENGTH_802_11_WITH_ADDR4; - else - header_len = LENGTH_802_11; - - /* QOS */ - if (pRxBlk->pHeader->FC.SubType & 0x08) { - header_len += 2; - /* Data skip QOS control field */ - pRxBlk->DataSize -= 2; - } - /* Order bit: A-Ralink or HTC+ */ - if (pRxBlk->pHeader->FC.Order) { - header_len += 4; - /* Data skip HTC control field */ - pRxBlk->DataSize -= 4; - } - /* Copy Header */ - if (header_len <= 40) - NdisMoveMemory(temp_header, pRxBlk->pData, header_len); - - /* skip HW padding */ - if (pRxBlk->RxD.L2PAD) - pRxBlk->pData += (header_len + 2); - else - pRxBlk->pData += header_len; - } /*end if */ - - if (pRxBlk->DataSize < pOSPkt->len) { - skb_trim(pOSPkt, pRxBlk->DataSize); - } else { - skb_put(pOSPkt, (pRxBlk->DataSize - pOSPkt->len)); - } /*end if */ - - if ((pRxBlk->pData - pOSPkt->data) > 0) { - skb_put(pOSPkt, (pRxBlk->pData - pOSPkt->data)); - skb_pull(pOSPkt, (pRxBlk->pData - pOSPkt->data)); - } /*end if */ - - if (skb_headroom(pOSPkt) < (sizeof(struct rt_wlan_ng_prism2_header) + header_len)) { - if (pskb_expand_head - (pOSPkt, (sizeof(struct rt_wlan_ng_prism2_header) + header_len), 0, - GFP_ATOMIC)) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s : Reallocate header size of sk_buff fail!\n", - __func__)); - goto err_free_sk_buff; - } /*end if */ - } /*end if */ - - if (header_len > 0) - NdisMoveMemory(skb_push(pOSPkt, header_len), temp_header, - header_len); - - ph = (struct rt_wlan_ng_prism2_header *)skb_push(pOSPkt, - sizeof(struct rt_wlan_ng_prism2_header)); - NdisZeroMemory(ph, sizeof(struct rt_wlan_ng_prism2_header)); - - ph->msgcode = DIDmsg_lnxind_wlansniffrm; - ph->msglen = sizeof(struct rt_wlan_ng_prism2_header); - strcpy((char *)ph->devname, (char *)pAd->net_dev->name); - - ph->hosttime.did = DIDmsg_lnxind_wlansniffrm_hosttime; - ph->hosttime.status = 0; - ph->hosttime.len = 4; - ph->hosttime.data = jiffies; - - ph->mactime.did = DIDmsg_lnxind_wlansniffrm_mactime; - ph->mactime.status = 0; - ph->mactime.len = 0; - ph->mactime.data = 0; - - ph->istx.did = DIDmsg_lnxind_wlansniffrm_istx; - ph->istx.status = 0; - ph->istx.len = 0; - ph->istx.data = 0; - - ph->channel.did = DIDmsg_lnxind_wlansniffrm_channel; - ph->channel.status = 0; - ph->channel.len = 4; - - ph->channel.data = (u_int32_t) pAd->CommonCfg.Channel; - - ph->rssi.did = DIDmsg_lnxind_wlansniffrm_rssi; - ph->rssi.status = 0; - ph->rssi.len = 4; - ph->rssi.data = - (u_int32_t) RTMPMaxRssi(pAd, - ConvertToRssi(pAd, pRxBlk->pRxWI->RSSI0, - RSSI_0), ConvertToRssi(pAd, - pRxBlk-> - pRxWI-> - RSSI1, - RSSI_1), - ConvertToRssi(pAd, pRxBlk->pRxWI->RSSI2, - RSSI_2)); - - ph->signal.did = DIDmsg_lnxind_wlansniffrm_signal; - ph->signal.status = 0; - ph->signal.len = 4; - ph->signal.data = 0; /*rssi + noise; */ - - ph->noise.did = DIDmsg_lnxind_wlansniffrm_noise; - ph->noise.status = 0; - ph->noise.len = 4; - ph->noise.data = 0; - - if (pRxBlk->pRxWI->PHYMODE >= MODE_HTMIX) { - rate_index = - 16 + ((u8)pRxBlk->pRxWI->BW * 16) + - ((u8)pRxBlk->pRxWI->ShortGI * 32) + - ((u8)pRxBlk->pRxWI->MCS); - } else if (pRxBlk->pRxWI->PHYMODE == MODE_OFDM) - rate_index = (u8)(pRxBlk->pRxWI->MCS) + 4; - else - rate_index = (u8)(pRxBlk->pRxWI->MCS); - if (rate_index < 0) - rate_index = 0; - if (rate_index > 255) - rate_index = 255; - - ph->rate.did = DIDmsg_lnxind_wlansniffrm_rate; - ph->rate.status = 0; - ph->rate.len = 4; - ph->rate.data = ralinkrate[rate_index]; - - ph->frmlen.did = DIDmsg_lnxind_wlansniffrm_frmlen; - ph->frmlen.status = 0; - ph->frmlen.len = 4; - ph->frmlen.data = (u_int32_t) pRxBlk->DataSize; - - pOSPkt->pkt_type = PACKET_OTHERHOST; - pOSPkt->protocol = eth_type_trans(pOSPkt, pOSPkt->dev); - pOSPkt->ip_summed = CHECKSUM_NONE; - netif_rx(pOSPkt); - - return; - -err_free_sk_buff: - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); - return; - -} - -/******************************************************************************* - - Device IRQ related functions. - - *******************************************************************************/ -int RtmpOSIRQRequest(struct net_device *pNetDev) -{ -#ifdef RTMP_PCI_SUPPORT - struct net_device *net_dev = pNetDev; - struct rt_rtmp_adapter *pAd = NULL; - int retval = 0; - - GET_PAD_FROM_NET_DEV(pAd, pNetDev); - - ASSERT(pAd); - - if (pAd->infType == RTMP_DEV_INF_PCI) { - struct os_cookie *_pObj = (struct os_cookie *)(pAd->OS_Cookie); - RTMP_MSI_ENABLE(pAd); - retval = - request_irq(_pObj->pci_dev->irq, rt2860_interrupt, SA_SHIRQ, - (net_dev)->name, (net_dev)); - if (retval != 0) - printk(KERN_ERR "rt2860: request_irq ERROR(%d)\n", retval); - } - - return retval; -#else - return 0; -#endif -} - -int RtmpOSIRQRelease(struct net_device *pNetDev) -{ - struct net_device *net_dev = pNetDev; - struct rt_rtmp_adapter *pAd = NULL; - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - ASSERT(pAd); - -#ifdef RTMP_PCI_SUPPORT - if (pAd->infType == RTMP_DEV_INF_PCI) { - struct os_cookie *pObj = (struct os_cookie *)(pAd->OS_Cookie); - synchronize_irq(pObj->pci_dev->irq); - free_irq(pObj->pci_dev->irq, (net_dev)); - RTMP_MSI_DISABLE(pAd); - } -#endif /* RTMP_PCI_SUPPORT // */ - - return 0; -} - -/******************************************************************************* - - File open/close related functions. - - *******************************************************************************/ -struct file *RtmpOSFileOpen(char *pPath, int flag, int mode) -{ - struct file *filePtr; - - filePtr = filp_open(pPath, flag, 0); - if (IS_ERR(filePtr)) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s(): Error %ld opening %s\n", __func__, - -PTR_ERR(filePtr), pPath)); - } - - return (struct file *)filePtr; -} - -int RtmpOSFileClose(struct file *osfd) -{ - filp_close(osfd, NULL); - return 0; -} - -void RtmpOSFileSeek(struct file *osfd, int offset) -{ - osfd->f_pos = offset; -} - -int RtmpOSFileRead(struct file *osfd, char *pDataPtr, int readLen) -{ - /* The object must have a read method */ - if (osfd->f_op && osfd->f_op->read) { - return osfd->f_op->read(osfd, pDataPtr, readLen, &osfd->f_pos); - } else { - DBGPRINT(RT_DEBUG_ERROR, ("no file read method\n")); - return -1; - } -} - -int RtmpOSFileWrite(struct file *osfd, char *pDataPtr, int writeLen) -{ - return osfd->f_op->write(osfd, pDataPtr, (size_t) writeLen, - &osfd->f_pos); -} - -/******************************************************************************* - - Task create/management/kill related functions. - - *******************************************************************************/ -int RtmpOSTaskKill(struct rt_rtmp_os_task *pTask) -{ - struct rt_rtmp_adapter *pAd; - int ret = NDIS_STATUS_FAILURE; - - pAd = pTask->priv; - -#ifdef KTHREAD_SUPPORT - if (pTask->kthread_task) { - kthread_stop(pTask->kthread_task); - ret = NDIS_STATUS_SUCCESS; - } -#else - CHECK_PID_LEGALITY(pTask->taskPID) { - printk(KERN_INFO "Terminate the task(%s) with pid(%d)!\n", - pTask->taskName, GET_PID_NUMBER(pTask->taskPID)); - mb(); - pTask->task_killed = 1; - mb(); - ret = KILL_THREAD_PID(pTask->taskPID, SIGTERM, 1); - if (ret) { - printk(KERN_WARNING - "kill task(%s) with pid(%d) failed(retVal=%d)!\n", - pTask->taskName, GET_PID_NUMBER(pTask->taskPID), - ret); - } else { - wait_for_completion(&pTask->taskComplete); - pTask->taskPID = THREAD_PID_INIT_VALUE; - pTask->task_killed = 0; - ret = NDIS_STATUS_SUCCESS; - } - } -#endif - - return ret; - -} - -int RtmpOSTaskNotifyToExit(struct rt_rtmp_os_task *pTask) -{ - -#ifndef KTHREAD_SUPPORT - complete_and_exit(&pTask->taskComplete, 0); -#endif - - return 0; -} - -void RtmpOSTaskCustomize(struct rt_rtmp_os_task *pTask) -{ - -#ifndef KTHREAD_SUPPORT - - daemonize((char *)&pTask->taskName[0] /*"%s",pAd->net_dev->name */); - - allow_signal(SIGTERM); - allow_signal(SIGKILL); - current->flags |= PF_NOFREEZE; - - /* signal that we've started the thread */ - complete(&pTask->taskComplete); - -#endif -} - -int RtmpOSTaskAttach(struct rt_rtmp_os_task *pTask, - IN int (*fn) (void *), IN void *arg) -{ - int status = NDIS_STATUS_SUCCESS; - -#ifdef KTHREAD_SUPPORT - pTask->task_killed = 0; - pTask->kthread_task = NULL; - pTask->kthread_task = kthread_run(fn, arg, pTask->taskName); - if (IS_ERR(pTask->kthread_task)) - status = NDIS_STATUS_FAILURE; -#else - pid_number = kernel_thread(fn, arg, RTMP_OS_MGMT_TASK_FLAGS); - if (pid_number < 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("Attach task(%s) failed!\n", pTask->taskName)); - status = NDIS_STATUS_FAILURE; - } else { - pTask->taskPID = GET_PID(pid_number); - - /* Wait for the thread to start */ - wait_for_completion(&pTask->taskComplete); - status = NDIS_STATUS_SUCCESS; - } -#endif - return status; -} - -int RtmpOSTaskInit(struct rt_rtmp_os_task *pTask, - char *pTaskName, void * pPriv) -{ - int len; - - ASSERT(pTask); - -#ifndef KTHREAD_SUPPORT - NdisZeroMemory((u8 *)(pTask), sizeof(struct rt_rtmp_os_task)); -#endif - - len = strlen(pTaskName); - len = - len > - (RTMP_OS_TASK_NAME_LEN - 1) ? (RTMP_OS_TASK_NAME_LEN - 1) : len; - NdisMoveMemory(&pTask->taskName[0], pTaskName, len); - pTask->priv = pPriv; - -#ifndef KTHREAD_SUPPORT - RTMP_SEM_EVENT_INIT_LOCKED(&(pTask->taskSema)); - pTask->taskPID = THREAD_PID_INIT_VALUE; - - init_completion(&pTask->taskComplete); -#endif - - return NDIS_STATUS_SUCCESS; -} - -void RTMP_IndicateMediaState(struct rt_rtmp_adapter *pAd) -{ - if (pAd->CommonCfg.bWirelessEvent) { - if (pAd->IndicateMediaState == NdisMediaStateConnected) { - RTMPSendWirelessEvent(pAd, IW_STA_LINKUP_EVENT_FLAG, - pAd->MacTab.Content[BSSID_WCID]. - Addr, BSS0, 0); - } else { - RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG, - pAd->MacTab.Content[BSSID_WCID]. - Addr, BSS0, 0); - } - } -} - -int RtmpOSWrielessEventSend(struct rt_rtmp_adapter *pAd, - u32 eventType, - int flags, - u8 *pSrcMac, - u8 *pData, u32 dataLen) -{ - union iwreq_data wrqu; - - memset(&wrqu, 0, sizeof(wrqu)); - - if (flags > -1) - wrqu.data.flags = flags; - - if (pSrcMac) - memcpy(wrqu.ap_addr.sa_data, pSrcMac, MAC_ADDR_LEN); - - if ((pData != NULL) && (dataLen > 0)) - wrqu.data.length = dataLen; - - wireless_send_event(pAd->net_dev, eventType, &wrqu, (char *)pData); - return 0; -} - -int RtmpOSNetDevAddrSet(struct net_device *pNetDev, u8 *pMacAddr) -{ - struct net_device *net_dev; - struct rt_rtmp_adapter *pAd; - - net_dev = pNetDev; - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - /* work-around for SuSE, due to them having their own interface name management system. */ - { - NdisZeroMemory(pAd->StaCfg.dev_name, 16); - NdisMoveMemory(pAd->StaCfg.dev_name, net_dev->name, - strlen(net_dev->name)); - } - - NdisMoveMemory(net_dev->dev_addr, pMacAddr, 6); - - return 0; -} - -/* - * Assign the network dev name for created Ralink WiFi interface. - */ -static int RtmpOSNetDevRequestName(struct rt_rtmp_adapter *pAd, - struct net_device *dev, - char *pPrefixStr, int devIdx) -{ - struct net_device *existNetDev; - char suffixName[IFNAMSIZ]; - char desiredName[IFNAMSIZ]; - int ifNameIdx, prefixLen, slotNameLen; - int Status; - - prefixLen = strlen(pPrefixStr); - ASSERT((prefixLen < IFNAMSIZ)); - - for (ifNameIdx = devIdx; ifNameIdx < 32; ifNameIdx++) { - memset(suffixName, 0, IFNAMSIZ); - memset(desiredName, 0, IFNAMSIZ); - strncpy(&desiredName[0], pPrefixStr, prefixLen); - - sprintf(suffixName, "%d", ifNameIdx); - - slotNameLen = strlen(suffixName); - ASSERT(((slotNameLen + prefixLen) < IFNAMSIZ)); - strcat(desiredName, suffixName); - - existNetDev = RtmpOSNetDevGetByName(dev, &desiredName[0]); - if (existNetDev == NULL) - break; - else - RtmpOSNetDeviceRefPut(existNetDev); - } - - if (ifNameIdx < 32) { - strcpy(&dev->name[0], &desiredName[0]); - Status = NDIS_STATUS_SUCCESS; - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("Cannot request DevName with preifx(%s) and in range(0~32) as suffix from OS!\n", - pPrefixStr)); - Status = NDIS_STATUS_FAILURE; - } - - return Status; -} - -void RtmpOSNetDevClose(struct net_device *pNetDev) -{ - dev_close(pNetDev); -} - -void RtmpOSNetDevFree(struct net_device *pNetDev) -{ - ASSERT(pNetDev); - - free_netdev(pNetDev); -} - -int RtmpOSNetDevAlloc(struct net_device **new_dev_p, u32 privDataSize) -{ - /* assign it as null first. */ - *new_dev_p = NULL; - - DBGPRINT(RT_DEBUG_TRACE, - ("Allocate a net device with private data size=%d!\n", - privDataSize)); - *new_dev_p = alloc_etherdev(privDataSize); - if (*new_dev_p) - return NDIS_STATUS_SUCCESS; - else - return NDIS_STATUS_FAILURE; -} - -struct net_device *RtmpOSNetDevGetByName(struct net_device *pNetDev, char *pDevName) -{ - struct net_device *pTargetNetDev = NULL; - - pTargetNetDev = dev_get_by_name(dev_net(pNetDev), pDevName); - - return pTargetNetDev; -} - -void RtmpOSNetDeviceRefPut(struct net_device *pNetDev) -{ - /* - every time dev_get_by_name is called, and it has returned a valid struct - net_device*, dev_put should be called afterwards, because otherwise the - machine hangs when the device is unregistered (since dev->refcnt > 1). - */ - if (pNetDev) - dev_put(pNetDev); -} - -int RtmpOSNetDevDestory(struct rt_rtmp_adapter *pAd, struct net_device *pNetDev) -{ - - /* TODO: Need to fix this */ - printk("WARNING: This function(%s) not implement yet!\n", __func__); - return 0; -} - -void RtmpOSNetDevDetach(struct net_device *pNetDev) -{ - unregister_netdev(pNetDev); -} - -int RtmpOSNetDevAttach(struct net_device *pNetDev, - struct rt_rtmp_os_netdev_op_hook *pDevOpHook) -{ - int ret, rtnl_locked = FALSE; - - DBGPRINT(RT_DEBUG_TRACE, ("RtmpOSNetDevAttach()--->\n")); - /* If we need hook some callback function to the net device structure, now do it. */ - if (pDevOpHook) { - struct rt_rtmp_adapter *pAd = NULL; - - GET_PAD_FROM_NET_DEV(pAd, pNetDev); - - pNetDev->netdev_ops = pDevOpHook->netdev_ops; - - /* OS specific flags, here we used to indicate if we are virtual interface */ - pNetDev->priv_flags = pDevOpHook->priv_flags; - - if (pAd->OpMode == OPMODE_STA) - pNetDev->wireless_handlers = &rt28xx_iw_handler_def; - - /* copy the net device mac address to the net_device structure. */ - NdisMoveMemory(pNetDev->dev_addr, &pDevOpHook->devAddr[0], - MAC_ADDR_LEN); - - rtnl_locked = pDevOpHook->needProtcted; - } - - if (rtnl_locked) - ret = register_netdevice(pNetDev); - else - ret = register_netdev(pNetDev); - - DBGPRINT(RT_DEBUG_TRACE, ("<---RtmpOSNetDevAttach(), ret=%d\n", ret)); - if (ret == 0) - return NDIS_STATUS_SUCCESS; - else - return NDIS_STATUS_FAILURE; -} - -struct net_device *RtmpOSNetDevCreate(struct rt_rtmp_adapter *pAd, - int devType, - int devNum, - int privMemSize, char *pNamePrefix) -{ - struct net_device *pNetDev = NULL; - int status; - - /* allocate a new network device */ - status = RtmpOSNetDevAlloc(&pNetDev, 0 /*privMemSize */); - if (status != NDIS_STATUS_SUCCESS) { - /* allocation fail, exit */ - DBGPRINT(RT_DEBUG_ERROR, - ("Allocate network device fail (%s)...\n", - pNamePrefix)); - return NULL; - } - - /* find an available interface name, max 32 interfaces */ - status = RtmpOSNetDevRequestName(pAd, pNetDev, pNamePrefix, devNum); - if (status != NDIS_STATUS_SUCCESS) { - /* error! no available ra name can be used! */ - DBGPRINT(RT_DEBUG_ERROR, - ("Assign interface name (%s with suffix 0~32) failed...\n", - pNamePrefix)); - RtmpOSNetDevFree(pNetDev); - - return NULL; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("The name of the new %s interface is %s...\n", - pNamePrefix, pNetDev->name)); - } - - return pNetDev; -} diff --git a/trunk/drivers/staging/rt2860/rt_linux.h b/trunk/drivers/staging/rt2860/rt_linux.h deleted file mode 100644 index 3efb88fdffc1..000000000000 --- a/trunk/drivers/staging/rt2860/rt_linux.h +++ /dev/null @@ -1,835 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt_linux.h - - Abstract: - - Revision History: - Who When What - Justin P. Mattock 11/07/2010 Fix typo in a comment - --------- ---------- ---------------------------------------------- -*/ - -#ifndef __RT_LINUX_H__ -#define __RT_LINUX_H__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -/* load firmware */ -#define __KERNEL_SYSCALLS__ -#include -#include -#include -#include /* for get_unaligned() */ - -#define KTHREAD_SUPPORT 1 -/* RT2870 2.1.0.0 has it disabled */ - -#ifdef KTHREAD_SUPPORT -#include -#include -#endif /* KTHREAD_SUPPORT // */ - -/*********************************************************************************** - * Profile related sections - ***********************************************************************************/ - -#ifdef RTMP_MAC_PCI -#define STA_DRIVER_VERSION "2.1.0.0" -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB -#define STA_DRIVER_VERSION "2.1.0.0" -/* RT3070 version: 2.1.1.0 */ -#endif /* RTMP_MAC_USB // */ - -extern const struct iw_handler_def rt28xx_iw_handler_def; - -/*********************************************************************************** - * Compiler related definitions - ***********************************************************************************/ -#undef __inline -#define __inline static inline -#define IN -#define OUT -#define INOUT - -/*********************************************************************************** - * OS Specific definitions and data structures - ***********************************************************************************/ -typedef int (*HARD_START_XMIT_FUNC) (struct sk_buff *skb, - struct net_device *net_dev); - -#ifdef RTMP_MAC_PCI -#ifndef PCI_DEVICE -#define PCI_DEVICE(vend,dev) \ - .vendor = (vend), .device = (dev), \ - .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID -#endif /* PCI_DEVICE // */ -#endif /* RTMP_MAC_PCI // */ - -#define RT_MOD_INC_USE_COUNT() \ - if (!try_module_get(THIS_MODULE)) \ - { \ - DBGPRINT(RT_DEBUG_ERROR, ("%s: cannot reserve module\n", __func__)); \ - return -1; \ - } - -#define RT_MOD_DEC_USE_COUNT() module_put(THIS_MODULE); - -#define RTMP_INC_REF(_A) 0 -#define RTMP_DEC_REF(_A) 0 -#define RTMP_GET_REF(_A) 0 - -/* This function will be called when query /proc */ -struct iw_statistics *rt28xx_get_wireless_stats(IN struct net_device *net_dev); - -/*********************************************************************************** - * Network related constant definitions - ***********************************************************************************/ -#ifndef IFNAMSIZ -#define IFNAMSIZ 16 -#endif - -#define ETH_LENGTH_OF_ADDRESS 6 - -#define NDIS_STATUS_SUCCESS 0x00 -#define NDIS_STATUS_FAILURE 0x01 -#define NDIS_STATUS_INVALID_DATA 0x02 -#define NDIS_STATUS_RESOURCES 0x03 - -#define NDIS_SET_PACKET_STATUS(_p, _status) do{} while(0) -#define NdisWriteErrorLogEntry(_a, _b, _c, _d) do{} while(0) - -/* statistics counter */ -#define STATS_INC_RX_PACKETS(_pAd, _dev) -#define STATS_INC_TX_PACKETS(_pAd, _dev) - -#define STATS_INC_RX_BYTESS(_pAd, _dev, len) -#define STATS_INC_TX_BYTESS(_pAd, _dev, len) - -#define STATS_INC_RX_ERRORS(_pAd, _dev) -#define STATS_INC_TX_ERRORS(_pAd, _dev) - -#define STATS_INC_RX_DROPPED(_pAd, _dev) -#define STATS_INC_TX_DROPPED(_pAd, _dev) - -/*********************************************************************************** - * Ralink Specific network related constant definitions - ***********************************************************************************/ -#define MIN_NET_DEVICE_FOR_AID 0x00 /*0x00~0x3f */ -#define MIN_NET_DEVICE_FOR_MBSSID 0x00 /*0x00,0x10,0x20,0x30 */ -#define MIN_NET_DEVICE_FOR_WDS 0x10 /*0x40,0x50,0x60,0x70 */ -#define MIN_NET_DEVICE_FOR_APCLI 0x20 -#define MIN_NET_DEVICE_FOR_MESH 0x30 -#define MIN_NET_DEVICE_FOR_DLS 0x40 -#define NET_DEVICE_REAL_IDX_MASK 0x0f /* for each operation mode, we maximum support 15 entities. */ - -#define NDIS_PACKET_TYPE_DIRECTED 0 -#define NDIS_PACKET_TYPE_MULTICAST 1 -#define NDIS_PACKET_TYPE_BROADCAST 2 -#define NDIS_PACKET_TYPE_ALL_MULTICAST 3 -#define NDIS_PACKET_TYPE_PROMISCUOUS 4 - -/*********************************************************************************** - * OS signaling related constant definitions - ***********************************************************************************/ - -/*********************************************************************************** - * OS file operation related data structure definitions - ***********************************************************************************/ -struct rt_rtmp_os_fs_info { - int fsuid; - int fsgid; - mm_segment_t fs; -}; - -#define IS_FILE_OPEN_ERR(_fd) IS_ERR((_fd)) - -/*********************************************************************************** - * OS semaphore related data structure and definitions - ***********************************************************************************/ -struct os_lock { - spinlock_t lock; - unsigned long flags; -}; - -/* */ -/* spin_lock enhanced for Nested spin lock */ -/* */ -#define NdisAllocateSpinLock(__lock) \ -{ \ - spin_lock_init((spinlock_t *)(__lock)); \ -} - -#define NdisFreeSpinLock(lock) \ - do{}while(0) - -#define RTMP_SEM_LOCK(__lock) \ -{ \ - spin_lock_bh((spinlock_t *)(__lock)); \ -} - -#define RTMP_SEM_UNLOCK(__lock) \ -{ \ - spin_unlock_bh((spinlock_t *)(__lock)); \ -} - -/* sample, use semaphore lock to replace IRQ lock, 2007/11/15 */ -#define RTMP_IRQ_LOCK(__lock, __irqflags) \ -{ \ - __irqflags = 0; \ - spin_lock_bh((spinlock_t *)(__lock)); \ - pAd->irq_disabled |= 1; \ -} - -#define RTMP_IRQ_UNLOCK(__lock, __irqflag) \ -{ \ - pAd->irq_disabled &= 0; \ - spin_unlock_bh((spinlock_t *)(__lock)); \ -} - -#define RTMP_INT_LOCK(__lock, __irqflags) \ -{ \ - spin_lock_irqsave((spinlock_t *)__lock, __irqflags); \ -} - -#define RTMP_INT_UNLOCK(__lock, __irqflag) \ -{ \ - spin_unlock_irqrestore((spinlock_t *)(__lock), ((unsigned long)__irqflag)); \ -} - -#define NdisAcquireSpinLock RTMP_SEM_LOCK -#define NdisReleaseSpinLock RTMP_SEM_UNLOCK - -#ifndef wait_event_interruptible_timeout -#define __wait_event_interruptible_timeout(wq, condition, ret) \ -do { \ - wait_queue_t __wait; \ - init_waitqueue_entry(&__wait, current); \ - add_wait_queue(&wq, &__wait); \ - for (;;) { \ - set_current_state(TASK_INTERRUPTIBLE); \ - if (condition) \ - break; \ - if (!signal_pending(current)) { \ - ret = schedule_timeout(ret); \ - if (!ret) \ - break; \ - continue; \ - } \ - ret = -ERESTARTSYS; \ - break; \ - } \ - current->state = TASK_RUNNING; \ - remove_wait_queue(&wq, &__wait); \ -} while (0) - -#define wait_event_interruptible_timeout(wq, condition, timeout) \ -({ \ - long __ret = timeout; \ - if (!(condition)) \ - __wait_event_interruptible_timeout(wq, condition, __ret); \ - __ret; \ -}) -#endif - -#define RTMP_SEM_EVENT_INIT_LOCKED(_pSema) sema_init((_pSema), 0) -#define RTMP_SEM_EVENT_INIT(_pSema) sema_init((_pSema), 1) -#define RTMP_SEM_EVENT_WAIT(_pSema, _status) ((_status) = down_interruptible((_pSema))) -#define RTMP_SEM_EVENT_UP(_pSema) up(_pSema) - -#ifdef KTHREAD_SUPPORT -#define RTMP_WAIT_EVENT_INTERRUPTIBLE(_pAd, _pTask) \ -{ \ - wait_event_interruptible(_pTask->kthread_q, \ - _pTask->kthread_running || kthread_should_stop()); \ - _pTask->kthread_running = FALSE; \ - if (kthread_should_stop()) \ - { \ - RTMP_SET_FLAG(_pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); \ - break; \ - } \ -} -#endif - -#ifdef KTHREAD_SUPPORT -#define WAKE_UP(_pTask) \ - do{ \ - if ((_pTask)->kthread_task) \ - { \ - (_pTask)->kthread_running = TRUE; \ - wake_up(&(_pTask)->kthread_q); \ - } \ - }while(0) -#endif - -/*********************************************************************************** - * OS Memory Access related data structure and definitions - ***********************************************************************************/ -#define MEM_ALLOC_FLAG (GFP_ATOMIC) /*(GFP_DMA | GFP_ATOMIC) */ - -#define NdisMoveMemory(Destination, Source, Length) memmove(Destination, Source, Length) -#define NdisCopyMemory(Destination, Source, Length) memcpy(Destination, Source, Length) -#define NdisZeroMemory(Destination, Length) memset(Destination, 0, Length) -#define NdisFillMemory(Destination, Length, Fill) memset(Destination, Fill, Length) -#define NdisCmpMemory(Destination, Source, Length) memcmp(Destination, Source, Length) -#define NdisEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length)) -#define RTMPEqualMemory(Source1, Source2, Length) (!memcmp(Source1, Source2, Length)) - -#define MlmeAllocateMemory(_pAd, _ppVA) os_alloc_mem(_pAd, _ppVA, MGMT_DMA_BUFFER_SIZE) -#define MlmeFreeMemory(_pAd, _pVA) os_free_mem(_pAd, _pVA) - -#define COPY_MAC_ADDR(Addr1, Addr2) memcpy((Addr1), (Addr2), MAC_ADDR_LEN) - -/*********************************************************************************** - * OS task related data structure and definitions - ***********************************************************************************/ -#define RTMP_OS_MGMT_TASK_FLAGS CLONE_VM - -#define THREAD_PID_INIT_VALUE NULL -#define GET_PID(_v) find_get_pid((_v)) -#define GET_PID_NUMBER(_v) pid_nr((_v)) -#define CHECK_PID_LEGALITY(_pid) if (pid_nr((_pid)) > 0) -#define KILL_THREAD_PID(_A, _B, _C) kill_pid((_A), (_B), (_C)) - -/*********************************************************************************** - * Timer related definitions and data structures. - **********************************************************************************/ -#define OS_HZ HZ - -typedef void (*TIMER_FUNCTION) (unsigned long); - -#define OS_WAIT(_time) \ -{ int _i; \ - long _loop = ((_time)/(1000/OS_HZ)) > 0 ? ((_time)/(1000/OS_HZ)) : 1;\ - wait_queue_head_t _wait; \ - init_waitqueue_head(&_wait); \ - for (_i=0; _i<(_loop); _i++) \ - wait_event_interruptible_timeout(_wait, 0, ONE_TICK); } - -#define RTMP_TIME_AFTER(a,b) \ - (typecheck(unsigned long, (unsigned long)a) && \ - typecheck(unsigned long, (unsigned long)b) && \ - ((long)(b) - (long)(a) < 0)) - -#define RTMP_TIME_AFTER_EQ(a,b) \ - (typecheck(unsigned long, (unsigned long)a) && \ - typecheck(unsigned long, (unsigned long)b) && \ - ((long)(a) - (long)(b) >= 0)) -#define RTMP_TIME_BEFORE(a,b) RTMP_TIME_AFTER_EQ(b,a) - -#define ONE_TICK 1 - -static inline void NdisGetSystemUpTime(unsigned long *time) -{ - *time = jiffies; -} - -/*********************************************************************************** - * OS specific cookie data structure binding to struct rt_rtmp_adapter - ***********************************************************************************/ - -struct os_cookie { -#ifdef RTMP_MAC_PCI - struct pci_dev *pci_dev; - struct pci_dev *parent_pci_dev; - u16 DeviceID; - dma_addr_t pAd_pa; -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - struct usb_device *pUsb_Dev; -#endif /* RTMP_MAC_USB // */ - - struct tasklet_struct rx_done_task; - struct tasklet_struct mgmt_dma_done_task; - struct tasklet_struct ac0_dma_done_task; - struct tasklet_struct ac1_dma_done_task; - struct tasklet_struct ac2_dma_done_task; - struct tasklet_struct ac3_dma_done_task; - struct tasklet_struct tbtt_task; -#ifdef RTMP_MAC_PCI - struct tasklet_struct fifo_statistic_full_task; -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - struct tasklet_struct null_frame_complete_task; - struct tasklet_struct rts_frame_complete_task; - struct tasklet_struct pspoll_frame_complete_task; -#endif /* RTMP_MAC_USB // */ - - unsigned long apd_pid; /*802.1x daemon pid */ - int ioctl_if_type; - int ioctl_if; -}; - -/*********************************************************************************** - * OS debugging and printing related definitions and data structure - ***********************************************************************************/ -#ifdef DBG -extern unsigned long RTDebugLevel; - -#define DBGPRINT_RAW(Level, Fmt) \ -do{ \ - if (Level <= RTDebugLevel) \ - { \ - printk Fmt; \ - } \ -}while(0) - -#define DBGPRINT(Level, Fmt) DBGPRINT_RAW(Level, Fmt) - -#define DBGPRINT_ERR(fmt, args...) printk(KERN_ERR fmt, ##args) - -#define DBGPRINT_S(Status, Fmt) \ -{ \ - printk Fmt; \ -} - -#else -#define DBGPRINT(Level, Fmt) -#define DBGPRINT_RAW(Level, Fmt) -#define DBGPRINT_S(Status, Fmt) -#define DBGPRINT_ERR(Fmt) -#endif - -#define ASSERT(x) - -void hex_dump(char *str, unsigned char *pSrcBufVA, unsigned int SrcBufLen); - -/********************************************************************************************************* - The following code are not revised, temporary put it here. - *********************************************************************************************************/ - -/*********************************************************************************** - * Device DMA Access related definitions and data structures. - **********************************************************************************/ -#ifdef RTMP_MAC_PCI -struct rt_rtmp_adapter; -dma_addr_t linux_pci_map_single(struct rt_rtmp_adapter *pAd, void *ptr, - size_t size, int sd_idx, int direction); -void linux_pci_unmap_single(struct rt_rtmp_adapter *pAd, dma_addr_t dma_addr, - size_t size, int direction); - -#define PCI_MAP_SINGLE(_handle, _ptr, _size, _sd_idx, _dir) \ - linux_pci_map_single(_handle, _ptr, _size, _sd_idx, _dir) - -#define PCI_UNMAP_SINGLE(_handle, _ptr, _size, _dir) \ - linux_pci_unmap_single(_handle, _ptr, _size, _dir) - -#define PCI_ALLOC_CONSISTENT(_pci_dev, _size, _ptr) \ - pci_alloc_consistent(_pci_dev, _size, _ptr) - -#define PCI_FREE_CONSISTENT(_pci_dev, _size, _virtual_addr, _physical_addr) \ - pci_free_consistent(_pci_dev, _size, _virtual_addr, _physical_addr) - -#define DEV_ALLOC_SKB(_length) \ - dev_alloc_skb(_length) -#endif /* RTMP_MAC_PCI // */ - -/* - * unsigned long - * RTMP_GetPhysicalAddressLow( - * dma_addr_t PhysicalAddress); - */ -#define RTMP_GetPhysicalAddressLow(PhysicalAddress) (PhysicalAddress) - -/* - * unsigned long - * RTMP_GetPhysicalAddressHigh( - * dma_addr_t PhysicalAddress); - */ -#define RTMP_GetPhysicalAddressHigh(PhysicalAddress) (0) - -/* - * void - * RTMP_SetPhysicalAddressLow( - * dma_addr_t PhysicalAddress, - * unsigned long Value); - */ -#define RTMP_SetPhysicalAddressLow(PhysicalAddress, Value) \ - PhysicalAddress = Value; - -/* - * void - * RTMP_SetPhysicalAddressHigh( - * dma_addr_t PhysicalAddress, - * unsigned long Value); - */ -#define RTMP_SetPhysicalAddressHigh(PhysicalAddress, Value) - -#define NdisMIndicateStatus(_w, _x, _y, _z) - -/*********************************************************************************** - * Device Register I/O Access related definitions and data structures. - **********************************************************************************/ -#ifdef RTMP_MAC_PCI -/*Patch for ASIC turst read/write bug, needs to remove after metel fix */ -#define RTMP_IO_READ32(_A, _R, _pV) \ -{ \ - if ((_A)->bPCIclkOff == FALSE) \ - { \ - (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \ - (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \ - } \ - else \ - *_pV = 0; \ -} - -#define RTMP_IO_FORCE_READ32(_A, _R, _pV) \ -{ \ - (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \ - (*_pV = readl((void *)((_A)->CSRBaseAddress + (_R)))); \ -} - -#define RTMP_IO_READ8(_A, _R, _pV) \ -{ \ - (*_pV = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0))); \ - (*_pV = readb((void *)((_A)->CSRBaseAddress + (_R)))); \ -} -#define RTMP_IO_WRITE32(_A, _R, _V) \ -{ \ - if ((_A)->bPCIclkOff == FALSE) \ - { \ - u32 Val; \ - Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \ - writel((_V), (void *)((_A)->CSRBaseAddress + (_R))); \ - } \ -} - -#define RTMP_IO_FORCE_WRITE32(_A, _R, _V) \ -{ \ - u32 Val; \ - Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \ - writel(_V, (void *)((_A)->CSRBaseAddress + (_R))); \ -} - -#if defined(RALINK_2880) || defined(RALINK_3052) -#define RTMP_IO_WRITE8(_A, _R, _V) \ -{ \ - unsigned long Val; \ - u8 _i; \ - _i = ((_R) & 0x3); \ - Val = readl((void *)((_A)->CSRBaseAddress + ((_R) - _i))); \ - Val = Val & (~(0x000000ff << ((_i)*8))); \ - Val = Val | ((unsigned long)(_V) << ((_i)*8)); \ - writel((Val), (void *)((_A)->CSRBaseAddress + ((_R) - _i))); \ -} -#else -#define RTMP_IO_WRITE8(_A, _R, _V) \ -{ \ - u32 Val; \ - Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \ - writeb((_V), (u8 *)((_A)->CSRBaseAddress + (_R))); \ -} -#endif /* #if defined(BRCM_6358) || defined(RALINK_2880) // */ - -#define RTMP_IO_WRITE16(_A, _R, _V) \ -{ \ - u32 Val; \ - Val = readl((void *)((_A)->CSRBaseAddress + MAC_CSR0)); \ - writew((_V), (u16 *)((_A)->CSRBaseAddress + (_R))); \ -} -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB -/*Patch for ASIC turst read/write bug, needs to remove after metel fix */ -#define RTMP_IO_READ32(_A, _R, _pV) \ - RTUSBReadMACRegister((_A), (_R), (u32 *)(_pV)) - -#define RTMP_IO_READ8(_A, _R, _pV) \ -{ \ -} - -#define RTMP_IO_WRITE32(_A, _R, _V) \ - RTUSBWriteMACRegister((_A), (_R), (u32)(_V)) - -#define RTMP_IO_WRITE8(_A, _R, _V) \ -{ \ - u16 _Val = _V; \ - RTUSBSingleWrite((_A), (_R), (u16)(_Val)); \ -} - -#define RTMP_IO_WRITE16(_A, _R, _V) \ -{ \ - RTUSBSingleWrite((_A), (_R), (u16)(_V)); \ -} -#endif /* RTMP_MAC_USB // */ - -/*********************************************************************************** - * Network Related data structure and marco definitions - ***********************************************************************************/ -#define PKTSRC_NDIS 0x7f -#define PKTSRC_DRIVER 0x0f - -#define RTMP_OS_NETDEV_SET_PRIV(_pNetDev, _pPriv) ((_pNetDev)->ml_priv = (_pPriv)) -#define RTMP_OS_NETDEV_GET_PRIV(_pNetDev) ((_pNetDev)->ml_priv) -#define RTMP_OS_NETDEV_GET_DEVNAME(_pNetDev) ((_pNetDev)->name) -#define RTMP_OS_NETDEV_GET_PHYADDR(_PNETDEV) ((_PNETDEV)->dev_addr) - -#define RTMP_OS_NETDEV_START_QUEUE(_pNetDev) netif_start_queue((_pNetDev)) -#define RTMP_OS_NETDEV_STOP_QUEUE(_pNetDev) netif_stop_queue((_pNetDev)) -#define RTMP_OS_NETDEV_WAKE_QUEUE(_pNetDev) netif_wake_queue((_pNetDev)) -#define RTMP_OS_NETDEV_CARRIER_OFF(_pNetDev) netif_carrier_off((_pNetDev)) - -#define QUEUE_ENTRY_TO_PACKET(pEntry) \ - (void *)(pEntry) - -#define PACKET_TO_QUEUE_ENTRY(pPacket) \ - (struct rt_queue_entry *)(pPacket) - -#define GET_SG_LIST_FROM_PACKET(_p, _sc) \ - rt_get_sg_list_from_packet(_p, _sc) - -#define RELEASE_NDIS_PACKET(_pAd, _pPacket, _Status) \ -{ \ - RTMPFreeNdisPacket(_pAd, _pPacket); \ -} - -/* - * packet helper - * - convert internal rt packet to os packet or - * os packet to rt packet - */ -#define RTPKT_TO_OSPKT(_p) ((struct sk_buff *)(_p)) -#define OSPKT_TO_RTPKT(_p) ((void *)(_p)) - -#define GET_OS_PKT_DATAPTR(_pkt) \ - (RTPKT_TO_OSPKT(_pkt)->data) -#define SET_OS_PKT_DATAPTR(_pkt, _dataPtr) \ - (RTPKT_TO_OSPKT(_pkt)->data) = (_dataPtr) - -#define GET_OS_PKT_LEN(_pkt) \ - (RTPKT_TO_OSPKT(_pkt)->len) -#define SET_OS_PKT_LEN(_pkt, _len) \ - (RTPKT_TO_OSPKT(_pkt)->len) = (_len) - -#define GET_OS_PKT_DATATAIL(_pkt) \ - (skb_tail_pointer(RTPKT_TO_OSPKT(_pkt)) -#define SET_OS_PKT_DATATAIL(_pkt, _start, _len) \ - (skb_set_tail_pointer(RTPKT_TO_OSPKT(_pkt), _len)) - -#define GET_OS_PKT_HEAD(_pkt) \ - (RTPKT_TO_OSPKT(_pkt)->head) - -#define GET_OS_PKT_END(_pkt) \ - (RTPKT_TO_OSPKT(_pkt)->end) - -#define GET_OS_PKT_NETDEV(_pkt) \ - (RTPKT_TO_OSPKT(_pkt)->dev) -#define SET_OS_PKT_NETDEV(_pkt, _pNetDev) \ - (RTPKT_TO_OSPKT(_pkt)->dev) = (_pNetDev) - -#define GET_OS_PKT_TYPE(_pkt) \ - (RTPKT_TO_OSPKT(_pkt)) - -#define GET_OS_PKT_NEXT(_pkt) \ - (RTPKT_TO_OSPKT(_pkt)->next) - -#define OS_PKT_CLONED(_pkt) skb_cloned(RTPKT_TO_OSPKT(_pkt)) - -#define OS_NTOHS(_Val) \ - (ntohs(_Val)) -#define OS_HTONS(_Val) \ - (htons(_Val)) -#define OS_NTOHL(_Val) \ - (ntohl(_Val)) -#define OS_HTONL(_Val) \ - (htonl(_Val)) - -#define CB_OFF 10 - -/* User Priority */ -#define RTMP_SET_PACKET_UP(_p, _prio) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0] = _prio) -#define RTMP_GET_PACKET_UP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+0]) - -/* Fragment # */ -#define RTMP_SET_PACKET_FRAGMENTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1] = _num) -#define RTMP_GET_PACKET_FRAGMENTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+1]) - -/* 0x0 ~0x7f: TX to AP's own BSS which has the specified AID. if AID>127, set bit 7 in RTMP_SET_PACKET_EMACTAB too. */ -/*(this value also as MAC(on-chip WCID) table index) */ -/* 0x80~0xff: TX to a WDS link. b0~6: WDS index */ -#define RTMP_SET_PACKET_WCID(_p, _wdsidx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2] = _wdsidx) -#define RTMP_GET_PACKET_WCID(_p) ((u8)(RTPKT_TO_OSPKT(_p)->cb[CB_OFF+2])) - -/* 0xff: PKTSRC_NDIS, others: local TX buffer index. This value affects how to a packet */ -#define RTMP_SET_PACKET_SOURCE(_p, _pktsrc) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3] = _pktsrc) -#define RTMP_GET_PACKET_SOURCE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+3]) - -/* RTS/CTS-to-self protection method */ -#define RTMP_SET_PACKET_RTS(_p, _num) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4] = _num) -#define RTMP_GET_PACKET_RTS(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+4]) -/* see RTMP_S(G)ET_PACKET_EMACTAB */ - -/* TX rate index */ -#define RTMP_SET_PACKET_TXRATE(_p, _rate) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5] = _rate) -#define RTMP_GET_PACKET_TXRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+5]) - -/* From which Interface */ -#define RTMP_SET_PACKET_IF(_p, _ifdx) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6] = _ifdx) -#define RTMP_GET_PACKET_IF(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+6]) -#define RTMP_SET_PACKET_NET_DEVICE_MBSSID(_p, _bss) RTMP_SET_PACKET_IF((_p), (_bss)) -#define RTMP_SET_PACKET_NET_DEVICE_WDS(_p, _bss) RTMP_SET_PACKET_IF((_p), ((_bss) + MIN_NET_DEVICE_FOR_WDS)) -#define RTMP_SET_PACKET_NET_DEVICE_APCLI(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_APCLI)) -#define RTMP_SET_PACKET_NET_DEVICE_MESH(_p, _idx) RTMP_SET_PACKET_IF((_p), ((_idx) + MIN_NET_DEVICE_FOR_MESH)) -#define RTMP_GET_PACKET_NET_DEVICE_MBSSID(_p) RTMP_GET_PACKET_IF((_p)) -#define RTMP_GET_PACKET_NET_DEVICE(_p) RTMP_GET_PACKET_IF((_p)) - -#define RTMP_SET_PACKET_MOREDATA(_p, _morebit) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7] = _morebit) -#define RTMP_GET_PACKET_MOREDATA(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+7]) - -/* */ -/* Specific Packet Type definition */ -/* */ -#define RTMP_PACKET_SPECIFIC_CB_OFFSET 11 - -#define RTMP_PACKET_SPECIFIC_DHCP 0x01 -#define RTMP_PACKET_SPECIFIC_EAPOL 0x02 -#define RTMP_PACKET_SPECIFIC_IPV4 0x04 -#define RTMP_PACKET_SPECIFIC_WAI 0x08 -#define RTMP_PACKET_SPECIFIC_VLAN 0x10 -#define RTMP_PACKET_SPECIFIC_LLCSNAP 0x20 - -/*Specific */ -#define RTMP_SET_PACKET_SPECIFIC(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] = _flg) - -/*DHCP */ -#define RTMP_SET_PACKET_DHCP(_p, _flg) \ - do{ \ - if (_flg) \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_DHCP); \ - else \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_DHCP); \ - }while(0) -#define RTMP_GET_PACKET_DHCP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_DHCP) - -/*EAPOL */ -#define RTMP_SET_PACKET_EAPOL(_p, _flg) \ - do{ \ - if (_flg) \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_EAPOL); \ - else \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_EAPOL); \ - }while(0) -#define RTMP_GET_PACKET_EAPOL(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_EAPOL) - -/*WAI */ -#define RTMP_SET_PACKET_WAI(_p, _flg) \ - do{ \ - if (_flg) \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_WAI); \ - else \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_WAI); \ - }while(0) -#define RTMP_GET_PACKET_WAI(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_WAI) - -#define RTMP_GET_PACKET_LOWRATE(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & (RTMP_PACKET_SPECIFIC_EAPOL | RTMP_PACKET_SPECIFIC_DHCP | RTMP_PACKET_SPECIFIC_WAI)) - -/*VLAN */ -#define RTMP_SET_PACKET_VLAN(_p, _flg) \ - do{ \ - if (_flg) \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_VLAN); \ - else \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_VLAN); \ - }while(0) -#define RTMP_GET_PACKET_VLAN(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_VLAN) - -/*LLC/SNAP */ -#define RTMP_SET_PACKET_LLCSNAP(_p, _flg) \ - do{ \ - if (_flg) \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_LLCSNAP); \ - else \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_LLCSNAP); \ - }while(0) - -#define RTMP_GET_PACKET_LLCSNAP(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_LLCSNAP) - -/* IP */ -#define RTMP_SET_PACKET_IPV4(_p, _flg) \ - do{ \ - if (_flg) \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) |= (RTMP_PACKET_SPECIFIC_IPV4); \ - else \ - (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11]) &= (!RTMP_PACKET_SPECIFIC_IPV4); \ - }while(0) - -#define RTMP_GET_PACKET_IPV4(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+11] & RTMP_PACKET_SPECIFIC_IPV4) - -/* If this flag is set, it indicates that this EAPoL frame MUST be clear. */ -#define RTMP_SET_PACKET_CLEAR_EAP_FRAME(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12] = _flg) -#define RTMP_GET_PACKET_CLEAR_EAP_FRAME(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+12]) - -/* use bit3 of cb[CB_OFF+16] */ - -#define RTMP_SET_PACKET_5VT(_p, _flg) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22] = _flg) -#define RTMP_GET_PACKET_5VT(_p) (RTPKT_TO_OSPKT(_p)->cb[CB_OFF+22]) - -/* Max skb->cb = 48B = [CB_OFF+38] */ - -/*********************************************************************************** - * Other function prototypes definitions - ***********************************************************************************/ -void RTMP_GetCurrentSystemTime(LARGE_INTEGER *time); -int rt28xx_packet_xmit(struct sk_buff *skb); - -#ifdef RTMP_MAC_PCI -/* function declarations */ -#define IRQ_HANDLE_TYPE irqreturn_t - -IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance); -#endif /* RTMP_MAC_PCI // */ - -int rt28xx_sta_ioctl(struct net_device *net_dev, IN OUT struct ifreq *rq, int cmd); - -extern int ra_mtd_write(int num, loff_t to, size_t len, const u_char *buf); -extern int ra_mtd_read(int num, loff_t from, size_t len, u_char *buf); - -#define GET_PAD_FROM_NET_DEV(_pAd, _net_dev) (_pAd) = (struct rt_rtmp_adapter *)(_net_dev)->ml_priv; - -#endif /* __RT_LINUX_H__ // */ diff --git a/trunk/drivers/staging/rt2860/rt_main_dev.c b/trunk/drivers/staging/rt2860/rt_main_dev.c deleted file mode 100644 index 236dd36d349a..000000000000 --- a/trunk/drivers/staging/rt2860/rt_main_dev.c +++ /dev/null @@ -1,736 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt_main_dev.c - - Abstract: - Create and register network interface. - - Revision History: - Who When What - Justin P. Mattock 11/07/2010 Fix typos in comments - -------- ---------- ---------------------------------------------- -*/ - -#include "rt_config.h" - -/*---------------------------------------------------------------------*/ -/* Private Variables Used */ -/*---------------------------------------------------------------------*/ - -char *mac = ""; /* default 00:00:00:00:00:00 */ -char *hostname = ""; /* default CMPC */ -module_param(mac, charp, 0); -MODULE_PARM_DESC(mac, "rt28xx: wireless mac addr"); - -/*---------------------------------------------------------------------*/ -/* Prototypes of Functions Used */ -/*---------------------------------------------------------------------*/ - -/* public function prototype */ -int rt28xx_close(IN struct net_device *net_dev); -int rt28xx_open(struct net_device *net_dev); - -/* private function prototype */ -static int rt28xx_send_packets(IN struct sk_buff *skb_p, - IN struct net_device *net_dev); - -static struct net_device_stats *RT28xx_get_ether_stats(IN struct net_device - *net_dev); - -/* -======================================================================== -Routine Description: - Close raxx interface. - -Arguments: - *net_dev the raxx interface pointer - -Return Value: - 0 Open OK - otherwise Open Fail - -Note: - 1. if open fail, kernel will not call the close function. - 2. Free memory for - (1) Mlme Memory Handler: MlmeHalt() - (2) TX & RX: RTMPFreeTxRxRingMemory() - (3) BA Reordering: ba_reordering_resource_release() -======================================================================== -*/ -int MainVirtualIF_close(IN struct net_device *net_dev) -{ - struct rt_rtmp_adapter *pAd = NULL; - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - /* Sanity check for pAd */ - if (pAd == NULL) - return 0; /* close ok */ - - netif_carrier_off(pAd->net_dev); - netif_stop_queue(pAd->net_dev); - - { - BOOLEAN Cancelled; - - if (INFRA_ON(pAd) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { - struct rt_mlme_disassoc_req DisReq; - struct rt_mlme_queue_elem *MsgElem = - kmalloc(sizeof(struct rt_mlme_queue_elem), - MEM_ALLOC_FLAG); - - if (MsgElem) { - COPY_MAC_ADDR(DisReq.Addr, - pAd->CommonCfg.Bssid); - DisReq.Reason = REASON_DEAUTH_STA_LEAVING; - - MsgElem->Machine = ASSOC_STATE_MACHINE; - MsgElem->MsgType = MT2_MLME_DISASSOC_REQ; - MsgElem->MsgLen = - sizeof(struct rt_mlme_disassoc_req); - NdisMoveMemory(MsgElem->Msg, &DisReq, - sizeof - (struct rt_mlme_disassoc_req)); - - /* Prevent to connect AP again in STAMlmePeriodicExec */ - pAd->MlmeAux.AutoReconnectSsidLen = 32; - NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, - pAd->MlmeAux. - AutoReconnectSsidLen); - - pAd->Mlme.CntlMachine.CurrState = - CNTL_WAIT_OID_DISASSOC; - MlmeDisassocReqAction(pAd, MsgElem); - kfree(MsgElem); - } - - RTMPusecDelay(1000); - } - - RTMPCancelTimer(&pAd->StaCfg.StaQuickResponeForRateUpTimer, - &Cancelled); - RTMPCancelTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, - &Cancelled); - } - - VIRTUAL_IF_DOWN(pAd); - - RT_MOD_DEC_USE_COUNT(); - - return 0; /* close ok */ -} - -/* -======================================================================== -Routine Description: - Open raxx interface. - -Arguments: - *net_dev the raxx interface pointer - -Return Value: - 0 Open OK - otherwise Open Fail - -Note: - 1. if open fail, kernel will not call the close function. - 2. Free memory for - (1) Mlme Memory Handler: MlmeHalt() - (2) TX & RX: RTMPFreeTxRxRingMemory() - (3) BA Reordering: ba_reordering_resource_release() -======================================================================== -*/ -int MainVirtualIF_open(IN struct net_device *net_dev) -{ - struct rt_rtmp_adapter *pAd = NULL; - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - /* Sanity check for pAd */ - if (pAd == NULL) - return 0; /* close ok */ - - if (VIRTUAL_IF_UP(pAd) != 0) - return -1; - - /* increase MODULE use count */ - RT_MOD_INC_USE_COUNT(); - - netif_start_queue(net_dev); - netif_carrier_on(net_dev); - netif_wake_queue(net_dev); - - return 0; -} - -/* -======================================================================== -Routine Description: - Close raxx interface. - -Arguments: - *net_dev the raxx interface pointer - -Return Value: - 0 Open OK - otherwise Open Fail - -Note: - 1. if open fail, kernel will not call the close function. - 2. Free memory for - (1) Mlme Memory Handler: MlmeHalt() - (2) TX & RX: RTMPFreeTxRxRingMemory() - (3) BA Reordering: ba_reordering_resource_release() -======================================================================== -*/ -int rt28xx_close(struct net_device *dev) -{ - struct net_device *net_dev = (struct net_device *)dev; - struct rt_rtmp_adapter *pAd = NULL; - BOOLEAN Cancelled; - u32 i = 0; - -#ifdef RTMP_MAC_USB - DECLARE_WAIT_QUEUE_HEAD_ONSTACK(unlink_wakeup); - DECLARE_WAITQUEUE(wait, current); -#endif /* RTMP_MAC_USB // */ - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - DBGPRINT(RT_DEBUG_TRACE, ("===> rt28xx_close\n")); - - Cancelled = FALSE; - /* Sanity check for pAd */ - if (pAd == NULL) - return 0; /* close ok */ - - { -#ifdef RTMP_MAC_PCI - RTMPPCIeLinkCtrlValueRestore(pAd, RESTORE_CLOSE); -#endif /* RTMP_MAC_PCI // */ - - /* If driver doesn't wake up firmware here, */ - /* NICLoadFirmware will hang forever when interface is up again. */ - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) { - AsicForceWakeup(pAd, TRUE); - } -#ifdef RTMP_MAC_USB - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_REMOVE_IN_PROGRESS); -#endif /* RTMP_MAC_USB // */ - - MlmeRadioOff(pAd); -#ifdef RTMP_MAC_PCI - pAd->bPCIclkOff = FALSE; -#endif /* RTMP_MAC_PCI // */ - } - - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); - - for (i = 0; i < NUM_OF_TX_RING; i++) { - while (pAd->DeQueueRunning[i] == TRUE) { - DBGPRINT(RT_DEBUG_TRACE, - ("Waiting for TxQueue[%d] done..........\n", - i)); - RTMPusecDelay(1000); - } - } - -#ifdef RTMP_MAC_USB - /* ensure there are no more active urbs. */ - add_wait_queue(&unlink_wakeup, &wait); - pAd->wait = &unlink_wakeup; - - /* maybe wait for deletions to finish. */ - i = 0; - /*while((i < 25) && atomic_read(&pAd->PendingRx) > 0) */ - while (i < 25) { - unsigned long IrqFlags; - - RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); - if (pAd->PendingRx == 0) { - RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); - break; - } - RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); - - msleep(UNLINK_TIMEOUT_MS); /*Time in millisecond */ - i++; - } - pAd->wait = NULL; - remove_wait_queue(&unlink_wakeup, &wait); -#endif /* RTMP_MAC_USB // */ - - /* Stop Mlme state machine */ - MlmeHalt(pAd); - - /* Close net tasklets */ - RtmpNetTaskExit(pAd); - - { - MacTableReset(pAd); - } - - MeasureReqTabExit(pAd); - TpcReqTabExit(pAd); - - /* Close kernel threads */ - RtmpMgmtTaskExit(pAd); - -#ifdef RTMP_MAC_PCI - { - BOOLEAN brc; - /* unsigned long Value; */ - - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE)) { - RTMP_ASIC_INTERRUPT_DISABLE(pAd); - } - /* Receive packets to clear DMA index after disable interrupt. */ - /* RTMPHandleRxDoneInterrupt(pAd); */ - /* put radio off to save power when driver unloads. After radiooff, can't write/read register, so need to finish all. */ - /* register access before Radio off. */ - - brc = RT28xxPciAsicRadioOff(pAd, RTMP_HALT, 0); - -/*In solution 3 of 3090F, the bPCIclkOff will be set to TRUE after calling RT28xxPciAsicRadioOff */ - pAd->bPCIclkOff = FALSE; - - if (brc == FALSE) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s call RT28xxPciAsicRadioOff fail!\n", - __func__)); - } - } - -/* - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE)) - { - RTMP_ASIC_INTERRUPT_DISABLE(pAd); - } - - // Disable Rx, register value supposed will remain after reset - NICIssueReset(pAd); -*/ -#endif /* RTMP_MAC_PCI // */ - - /* Free IRQ */ - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { -#ifdef RTMP_MAC_PCI - /* Deregister interrupt function */ - RtmpOSIRQRelease(net_dev); -#endif /* RTMP_MAC_PCI // */ - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE); - } - /* Free Ring or USB buffers */ - RTMPFreeTxRxRingMemory(pAd); - - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); - - /* Free BA reorder resource */ - ba_reordering_resource_release(pAd); - - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_START_UP); - -/*+++Modify by woody to solve the bulk fail+++*/ - { - } - - DBGPRINT(RT_DEBUG_TRACE, ("<=== rt28xx_close\n")); - return 0; /* close ok */ -} /* End of rt28xx_close */ - -/* -======================================================================== -Routine Description: - Open raxx interface. - -Arguments: - *net_dev the raxx interface pointer - -Return Value: - 0 Open OK - otherwise Open Fail - -Note: -======================================================================== -*/ -int rt28xx_open(struct net_device *dev) -{ - struct net_device *net_dev = (struct net_device *)dev; - struct rt_rtmp_adapter *pAd = NULL; - int retval = 0; - /*struct os_cookie *pObj; */ - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - /* Sanity check for pAd */ - if (pAd == NULL) { - /* if 1st open fail, pAd will be free; - So the net_dev->ml_priv will be NULL in 2rd open */ - return -1; - } - - if (net_dev->priv_flags == INT_MAIN) { - if (pAd->OpMode == OPMODE_STA) - net_dev->wireless_handlers = - (struct iw_handler_def *)&rt28xx_iw_handler_def; - } - /* Request interrupt service routine for PCI device */ - /* register the interrupt routine with the os */ - RtmpOSIRQRequest(net_dev); - - /* Init IRQ parameters stored in pAd */ - RTMP_IRQ_INIT(pAd); - - /* Chip & other init */ - if (rt28xx_init(pAd, mac, hostname) == FALSE) - goto err; - - /* Enable Interrupt */ - RTMP_IRQ_ENABLE(pAd); - - /* Now Enable RxTx */ - RTMPEnableRxTx(pAd); - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_START_UP); - - { - u32 reg = 0; - RTMP_IO_READ32(pAd, 0x1300, ®); /* clear garbage interrupts */ - printk(KERN_DEBUG "0x1300 = %08x\n", reg); - } - - { -/* u32 reg; */ -/* u8 byte; */ -/* u16 tmp; */ - -/* RTMP_IO_READ32(pAd, XIFS_TIME_CFG, ®); */ - -/* tmp = 0x0805; */ -/* reg = (reg & 0xffff0000) | tmp; */ -/* RTMP_IO_WRITE32(pAd, XIFS_TIME_CFG, reg); */ - - } -#ifdef RTMP_MAC_PCI - RTMPInitPCIeLinkCtrlValue(pAd); -#endif /* RTMP_MAC_PCI // */ - - return retval; - -err: -/*+++Add by shiang, move from rt28xx_init() to here. */ - RtmpOSIRQRelease(net_dev); -/*---Add by shiang, move from rt28xx_init() to here. */ - return -1; -} /* End of rt28xx_open */ - -static const struct net_device_ops rt2860_netdev_ops = { - .ndo_open = MainVirtualIF_open, - .ndo_stop = MainVirtualIF_close, - .ndo_do_ioctl = rt28xx_sta_ioctl, - .ndo_get_stats = RT28xx_get_ether_stats, - .ndo_validate_addr = NULL, - .ndo_set_mac_address = eth_mac_addr, - .ndo_change_mtu = eth_change_mtu, - .ndo_start_xmit = rt28xx_send_packets, -}; - -struct net_device *RtmpPhyNetDevInit(struct rt_rtmp_adapter *pAd, - struct rt_rtmp_os_netdev_op_hook *pNetDevHook) -{ - struct net_device *net_dev = NULL; -/* int Status; */ - - net_dev = - RtmpOSNetDevCreate(pAd, INT_MAIN, 0, sizeof(struct rt_rtmp_adapter *), - INF_MAIN_DEV_NAME); - if (net_dev == NULL) { - printk - ("RtmpPhyNetDevInit(): creation failed for main physical net device!\n"); - return NULL; - } - - NdisZeroMemory((unsigned char *)pNetDevHook, - sizeof(struct rt_rtmp_os_netdev_op_hook)); - pNetDevHook->netdev_ops = &rt2860_netdev_ops; - pNetDevHook->priv_flags = INT_MAIN; - pNetDevHook->needProtcted = FALSE; - - net_dev->ml_priv = (void *)pAd; - pAd->net_dev = net_dev; - - return net_dev; - -} - -/* -======================================================================== -Routine Description: - The entry point for Linux kernel sent packet to our driver. - -Arguments: - sk_buff *skb the pointer refer to a sk_buffer. - -Return Value: - 0 - -Note: - This function is the entry point of Tx Path for Os delivery packet to - our driver. You only can put OS-depened & STA/AP common handle procedures - in here. -======================================================================== -*/ -int rt28xx_packet_xmit(struct sk_buff *skb) -{ - struct net_device *net_dev = skb->dev; - struct rt_rtmp_adapter *pAd = NULL; - int status = NETDEV_TX_OK; - void *pPacket = (void *)skb; - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - /* RT2870STA does this in RTMPSendPackets() */ - - { - /* Drop send request since we are in monitor mode */ - if (MONITOR_ON(pAd)) { - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - goto done; - } - } - - /* EapolStart size is 18 */ - if (skb->len < 14) { - /*printk("bad packet size: %d\n", pkt->len); */ - hex_dump("bad packet", skb->data, skb->len); - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - goto done; - } - - RTMP_SET_PACKET_5VT(pPacket, 0); - STASendPackets((void *)pAd, (void **)&pPacket, 1); - - status = NETDEV_TX_OK; -done: - - return status; -} - -/* -======================================================================== -Routine Description: - Send a packet to WLAN. - -Arguments: - skb_p points to our adapter - dev_p which WLAN network interface - -Return Value: - 0: transmit successfully - otherwise: transmit fail - -Note: -======================================================================== -*/ -static int rt28xx_send_packets(IN struct sk_buff *skb_p, - IN struct net_device *net_dev) -{ - struct rt_rtmp_adapter *pAd = NULL; - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - if (!(net_dev->flags & IFF_UP)) { - RELEASE_NDIS_PACKET(pAd, (void *)skb_p, - NDIS_STATUS_FAILURE); - return NETDEV_TX_OK; - } - - NdisZeroMemory((u8 *)&skb_p->cb[CB_OFF], 15); - RTMP_SET_PACKET_NET_DEVICE_MBSSID(skb_p, MAIN_MBSSID); - - return rt28xx_packet_xmit(skb_p); -} - -/* This function will be called when query /proc */ -struct iw_statistics *rt28xx_get_wireless_stats(IN struct net_device *net_dev) -{ - struct rt_rtmp_adapter *pAd = NULL; - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - DBGPRINT(RT_DEBUG_TRACE, ("rt28xx_get_wireless_stats --->\n")); - - pAd->iw_stats.status = 0; /* Status - device dependent for now */ - - /* link quality */ - if (pAd->OpMode == OPMODE_STA) - pAd->iw_stats.qual.qual = - ((pAd->Mlme.ChannelQuality * 12) / 10 + 10); - - if (pAd->iw_stats.qual.qual > 100) - pAd->iw_stats.qual.qual = 100; - - if (pAd->OpMode == OPMODE_STA) { - pAd->iw_stats.qual.level = - RTMPMaxRssi(pAd, pAd->StaCfg.RssiSample.LastRssi0, - pAd->StaCfg.RssiSample.LastRssi1, - pAd->StaCfg.RssiSample.LastRssi2); - } - - pAd->iw_stats.qual.noise = pAd->BbpWriteLatch[66]; /* noise level (dBm) */ - - pAd->iw_stats.qual.noise += 256 - 143; - pAd->iw_stats.qual.updated = 1; /* Flags to know if updated */ -#ifdef IW_QUAL_DBM - pAd->iw_stats.qual.updated |= IW_QUAL_DBM; /* Level + Noise are dBm */ -#endif /* IW_QUAL_DBM // */ - - pAd->iw_stats.discard.nwid = 0; /* Rx : Wrong nwid/essid */ - pAd->iw_stats.miss.beacon = 0; /* Missed beacons/superframe */ - - DBGPRINT(RT_DEBUG_TRACE, ("<--- rt28xx_get_wireless_stats\n")); - return &pAd->iw_stats; -} - -void tbtt_tasklet(unsigned long data) -{ -/*#define MAX_TX_IN_TBTT (16) */ - -} - -/* - ======================================================================== - - Routine Description: - return ethernet statistics counter - - Arguments: - net_dev Pointer to net_device - - Return Value: - net_device_stats* - - Note: - - ======================================================================== -*/ -static struct net_device_stats *RT28xx_get_ether_stats(IN struct net_device - *net_dev) -{ - struct rt_rtmp_adapter *pAd = NULL; - - if (net_dev) - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - if (pAd) { - - pAd->stats.rx_packets = - pAd->WlanCounters.ReceivedFragmentCount.QuadPart; - pAd->stats.tx_packets = - pAd->WlanCounters.TransmittedFragmentCount.QuadPart; - - pAd->stats.rx_bytes = pAd->RalinkCounters.ReceivedByteCount; - pAd->stats.tx_bytes = pAd->RalinkCounters.TransmittedByteCount; - - pAd->stats.rx_errors = pAd->Counters8023.RxErrors; - pAd->stats.tx_errors = pAd->Counters8023.TxErrors; - - pAd->stats.rx_dropped = 0; - pAd->stats.tx_dropped = 0; - - pAd->stats.multicast = pAd->WlanCounters.MulticastReceivedFrameCount.QuadPart; /* multicast packets received */ - pAd->stats.collisions = pAd->Counters8023.OneCollision + pAd->Counters8023.MoreCollisions; /* Collision packets */ - - pAd->stats.rx_length_errors = 0; - pAd->stats.rx_over_errors = pAd->Counters8023.RxNoBuffer; /* receiver ring buff overflow */ - pAd->stats.rx_crc_errors = 0; /*pAd->WlanCounters.FCSErrorCount; // recved pkt with crc error */ - pAd->stats.rx_frame_errors = pAd->Counters8023.RcvAlignmentErrors; /* recv'd frame alignment error */ - pAd->stats.rx_fifo_errors = pAd->Counters8023.RxNoBuffer; /* recv'r fifo overrun */ - pAd->stats.rx_missed_errors = 0; /* receiver missed packet */ - - /* detailed tx_errors */ - pAd->stats.tx_aborted_errors = 0; - pAd->stats.tx_carrier_errors = 0; - pAd->stats.tx_fifo_errors = 0; - pAd->stats.tx_heartbeat_errors = 0; - pAd->stats.tx_window_errors = 0; - - /* for cslip etc */ - pAd->stats.rx_compressed = 0; - pAd->stats.tx_compressed = 0; - - return &pAd->stats; - } else - return NULL; -} - -BOOLEAN RtmpPhyNetDevExit(struct rt_rtmp_adapter *pAd, struct net_device *net_dev) -{ - - /* Unregister network device */ - if (net_dev != NULL) { - printk - ("RtmpOSNetDevDetach(): RtmpOSNetDeviceDetach(), dev->name=%s!\n", - net_dev->name); - RtmpOSNetDevDetach(net_dev); - } - - return TRUE; - -} - -/* -======================================================================== -Routine Description: - Allocate memory for adapter control block. - -Arguments: - pAd Pointer to our adapter - -Return Value: - NDIS_STATUS_SUCCESS - NDIS_STATUS_FAILURE - NDIS_STATUS_RESOURCES - -Note: -======================================================================== -*/ -int AdapterBlockAllocateMemory(void *handle, void ** ppAd) -{ - - *ppAd = vmalloc(sizeof(struct rt_rtmp_adapter)); - /* pci_alloc_consistent(pci_dev, sizeof(struct rt_rtmp_adapter), phy_addr); */ - - if (*ppAd) { - NdisZeroMemory(*ppAd, sizeof(struct rt_rtmp_adapter)); - ((struct rt_rtmp_adapter *)*ppAd)->OS_Cookie = handle; - return NDIS_STATUS_SUCCESS; - } else { - return NDIS_STATUS_FAILURE; - } -} diff --git a/trunk/drivers/staging/rt2860/rt_pci_rbus.c b/trunk/drivers/staging/rt2860/rt_pci_rbus.c deleted file mode 100644 index f80ab4e6a0ac..000000000000 --- a/trunk/drivers/staging/rt2860/rt_pci_rbus.c +++ /dev/null @@ -1,837 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt_pci_rbus.c - - Abstract: - Create and register network interface. - - Revision History: - Who When What - Justin P. Mattock 11/07/2010 Fix a typo - -------- ---------- ---------------------------------------------- -*/ - -#include "rt_config.h" -#include - -IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance); - -static void rx_done_tasklet(unsigned long data); -static void mgmt_dma_done_tasklet(unsigned long data); -static void ac0_dma_done_tasklet(unsigned long data); -static void ac1_dma_done_tasklet(unsigned long data); -static void ac2_dma_done_tasklet(unsigned long data); -static void ac3_dma_done_tasklet(unsigned long data); -static void fifo_statistic_full_tasklet(unsigned long data); - -/*---------------------------------------------------------------------*/ -/* Symbol & Macro Definitions */ -/*---------------------------------------------------------------------*/ -#define RT2860_INT_RX_DLY (1<<0) /* bit 0 */ -#define RT2860_INT_TX_DLY (1<<1) /* bit 1 */ -#define RT2860_INT_RX_DONE (1<<2) /* bit 2 */ -#define RT2860_INT_AC0_DMA_DONE (1<<3) /* bit 3 */ -#define RT2860_INT_AC1_DMA_DONE (1<<4) /* bit 4 */ -#define RT2860_INT_AC2_DMA_DONE (1<<5) /* bit 5 */ -#define RT2860_INT_AC3_DMA_DONE (1<<6) /* bit 6 */ -#define RT2860_INT_HCCA_DMA_DONE (1<<7) /* bit 7 */ -#define RT2860_INT_MGMT_DONE (1<<8) /* bit 8 */ - -#define INT_RX RT2860_INT_RX_DONE - -#define INT_AC0_DLY (RT2860_INT_AC0_DMA_DONE) /*| RT2860_INT_TX_DLY) */ -#define INT_AC1_DLY (RT2860_INT_AC1_DMA_DONE) /*| RT2860_INT_TX_DLY) */ -#define INT_AC2_DLY (RT2860_INT_AC2_DMA_DONE) /*| RT2860_INT_TX_DLY) */ -#define INT_AC3_DLY (RT2860_INT_AC3_DMA_DONE) /*| RT2860_INT_TX_DLY) */ -#define INT_HCCA_DLY (RT2860_INT_HCCA_DMA_DONE) /*| RT2860_INT_TX_DLY) */ -#define INT_MGMT_DLY RT2860_INT_MGMT_DONE - -/*************************************************************************** - * - * Interface-depended memory allocation/Free related procedures. - * Mainly for Hardware TxDesc/RxDesc/MgmtDesc, DMA Memory for TxData/RxData, etc., - * - **************************************************************************/ -/* Function for TxDesc Memory allocation. */ -void RTMP_AllocateTxDescMemory(struct rt_rtmp_adapter *pAd, - u32 Index, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - dma_addr_t *PhysicalAddress) -{ - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - *VirtualAddress = - (void *)pci_alloc_consistent(pObj->pci_dev, sizeof(char) * Length, - PhysicalAddress); - -} - -/* Function for MgmtDesc Memory allocation. */ -void RTMP_AllocateMgmtDescMemory(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - dma_addr_t *PhysicalAddress) -{ - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - *VirtualAddress = - (void *)pci_alloc_consistent(pObj->pci_dev, sizeof(char) * Length, - PhysicalAddress); - -} - -/* Function for RxDesc Memory allocation. */ -void RTMP_AllocateRxDescMemory(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - dma_addr_t *PhysicalAddress) -{ - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - *VirtualAddress = - (void *)pci_alloc_consistent(pObj->pci_dev, sizeof(char) * Length, - PhysicalAddress); - -} - -/* Function for free allocated Desc Memory. */ -void RTMP_FreeDescMemory(struct rt_rtmp_adapter *pAd, - unsigned long Length, - void *VirtualAddress, - dma_addr_t PhysicalAddress) -{ - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - pci_free_consistent(pObj->pci_dev, Length, VirtualAddress, - PhysicalAddress); -} - -/* Function for TxData DMA Memory allocation. */ -void RTMP_AllocateFirstTxBuffer(struct rt_rtmp_adapter *pAd, - u32 Index, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - dma_addr_t *PhysicalAddress) -{ - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - *VirtualAddress = - (void *)pci_alloc_consistent(pObj->pci_dev, sizeof(char) * Length, - PhysicalAddress); -} - -void RTMP_FreeFirstTxBuffer(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void *VirtualAddress, - dma_addr_t PhysicalAddress) -{ - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - pci_free_consistent(pObj->pci_dev, Length, VirtualAddress, - PhysicalAddress); -} - -/* - * FUNCTION: Allocate a common buffer for DMA - * ARGUMENTS: - * AdapterHandle: AdapterHandle - * Length: Number of bytes to allocate - * Cached: Whether or not the memory can be cached - * VirtualAddress: Pointer to memory is returned here - * PhysicalAddress: Physical address corresponding to virtual address - */ -void RTMP_AllocateSharedMemory(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - dma_addr_t *PhysicalAddress) -{ - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - *VirtualAddress = - (void *)pci_alloc_consistent(pObj->pci_dev, sizeof(char) * Length, - PhysicalAddress); -} - -/* - * FUNCTION: Allocate a packet buffer for DMA - * ARGUMENTS: - * AdapterHandle: AdapterHandle - * Length: Number of bytes to allocate - * Cached: Whether or not the memory can be cached - * VirtualAddress: Pointer to memory is returned here - * PhysicalAddress: Physical address corresponding to virtual address - * Notes: - * Cached is ignored: always cached memory - */ -void *RTMP_AllocateRxPacketBuffer(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - OUT dma_addr_t * - PhysicalAddress) -{ - struct sk_buff *pkt; - - pkt = dev_alloc_skb(Length); - - if (pkt == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("can't allocate rx %ld size packet\n", Length)); - } - - if (pkt) { - RTMP_SET_PACKET_SOURCE(OSPKT_TO_RTPKT(pkt), PKTSRC_NDIS); - *VirtualAddress = (void *)pkt->data; - *PhysicalAddress = - PCI_MAP_SINGLE(pAd, *VirtualAddress, Length, -1, - PCI_DMA_FROMDEVICE); - } else { - *VirtualAddress = (void *)NULL; - *PhysicalAddress = (dma_addr_t)NULL; - } - - return (void *)pkt; -} - -void Invalid_Remaining_Packet(struct rt_rtmp_adapter *pAd, unsigned long VirtualAddress) -{ - dma_addr_t PhysicalAddress; - - PhysicalAddress = - PCI_MAP_SINGLE(pAd, (void *)(VirtualAddress + 1600), - RX_BUFFER_NORMSIZE - 1600, -1, PCI_DMA_FROMDEVICE); -} - -int RtmpNetTaskInit(struct rt_rtmp_adapter *pAd) -{ - struct os_cookie *pObj; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - tasklet_init(&pObj->rx_done_task, rx_done_tasklet, (unsigned long)pAd); - tasklet_init(&pObj->mgmt_dma_done_task, mgmt_dma_done_tasklet, - (unsigned long)pAd); - tasklet_init(&pObj->ac0_dma_done_task, ac0_dma_done_tasklet, - (unsigned long)pAd); - tasklet_init(&pObj->ac1_dma_done_task, ac1_dma_done_tasklet, - (unsigned long)pAd); - tasklet_init(&pObj->ac2_dma_done_task, ac2_dma_done_tasklet, - (unsigned long)pAd); - tasklet_init(&pObj->ac3_dma_done_task, ac3_dma_done_tasklet, - (unsigned long)pAd); - tasklet_init(&pObj->tbtt_task, tbtt_tasklet, (unsigned long)pAd); - tasklet_init(&pObj->fifo_statistic_full_task, - fifo_statistic_full_tasklet, (unsigned long)pAd); - - return NDIS_STATUS_SUCCESS; -} - -void RtmpNetTaskExit(struct rt_rtmp_adapter *pAd) -{ - struct os_cookie *pObj; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - tasklet_kill(&pObj->rx_done_task); - tasklet_kill(&pObj->mgmt_dma_done_task); - tasklet_kill(&pObj->ac0_dma_done_task); - tasklet_kill(&pObj->ac1_dma_done_task); - tasklet_kill(&pObj->ac2_dma_done_task); - tasklet_kill(&pObj->ac3_dma_done_task); - tasklet_kill(&pObj->tbtt_task); - tasklet_kill(&pObj->fifo_statistic_full_task); -} - -int RtmpMgmtTaskInit(struct rt_rtmp_adapter *pAd) -{ - - return NDIS_STATUS_SUCCESS; -} - -/* -======================================================================== -Routine Description: - Close kernel threads. - -Arguments: - *pAd the raxx interface data pointer - -Return Value: - NONE - -Note: -======================================================================== -*/ -void RtmpMgmtTaskExit(struct rt_rtmp_adapter *pAd) -{ - - return; -} - -static inline void rt2860_int_enable(struct rt_rtmp_adapter *pAd, unsigned int mode) -{ - u32 regValue; - - pAd->int_disable_mask &= ~(mode); - regValue = pAd->int_enable_reg & ~(pAd->int_disable_mask); - /*if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) */ - { - RTMP_IO_WRITE32(pAd, INT_MASK_CSR, regValue); /* 1:enable */ - } - /*else */ - /* DBGPRINT(RT_DEBUG_TRACE, ("fOP_STATUS_DOZE !\n")); */ - - if (regValue != 0) - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE); -} - -static inline void rt2860_int_disable(struct rt_rtmp_adapter *pAd, unsigned int mode) -{ - u32 regValue; - - pAd->int_disable_mask |= mode; - regValue = pAd->int_enable_reg & ~(pAd->int_disable_mask); - RTMP_IO_WRITE32(pAd, INT_MASK_CSR, regValue); /* 0: disable */ - - if (regValue == 0) { - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_ACTIVE); - } -} - -/*************************************************************************** - * - * tasklet related procedures. - * - **************************************************************************/ -static void mgmt_dma_done_tasklet(unsigned long data) -{ - unsigned long flags; - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data; - INT_SOURCE_CSR_STRUC IntSource; - struct os_cookie *pObj; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - -/* printk("mgmt_dma_done_process\n"); */ - IntSource.word = 0; - IntSource.field.MgmtDmaDone = 1; - pAd->int_pending &= ~INT_MGMT_DLY; - - RTMPHandleMgmtRingDmaDoneInterrupt(pAd); - - /* if you use RTMP_SEM_LOCK, sometimes kernel will hang up, without any */ - /* bug report output */ - RTMP_INT_LOCK(&pAd->irq_lock, flags); - /* - * double check to avoid lose of interrupts - */ - if (pAd->int_pending & INT_MGMT_DLY) { - tasklet_hi_schedule(&pObj->mgmt_dma_done_task); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); - return; - } - - /* enable TxDataInt again */ - rt2860_int_enable(pAd, INT_MGMT_DLY); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); -} - -static void rx_done_tasklet(unsigned long data) -{ - unsigned long flags; - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data; - BOOLEAN bReschedule = 0; - struct os_cookie *pObj; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - pAd->int_pending &= ~(INT_RX); - bReschedule = STARxDoneInterruptHandle(pAd, 0); - - RTMP_INT_LOCK(&pAd->irq_lock, flags); - /* - * double check to avoid rotting packet - */ - if (pAd->int_pending & INT_RX || bReschedule) { - tasklet_hi_schedule(&pObj->rx_done_task); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); - return; - } - - /* enable Rxint again */ - rt2860_int_enable(pAd, INT_RX); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); - -} - -void fifo_statistic_full_tasklet(unsigned long data) -{ - unsigned long flags; - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data; - struct os_cookie *pObj; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - pAd->int_pending &= ~(FifoStaFullInt); - NICUpdateFifoStaCounters(pAd); - - RTMP_INT_LOCK(&pAd->irq_lock, flags); - /* - * double check to avoid rotting packet - */ - if (pAd->int_pending & FifoStaFullInt) { - tasklet_hi_schedule(&pObj->fifo_statistic_full_task); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); - return; - } - - /* enable Rxint again */ - - rt2860_int_enable(pAd, FifoStaFullInt); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); - -} - -static void ac3_dma_done_tasklet(unsigned long data) -{ - unsigned long flags; - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data; - INT_SOURCE_CSR_STRUC IntSource; - struct os_cookie *pObj; - BOOLEAN bReschedule = 0; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - -/* printk("ac0_dma_done_process\n"); */ - IntSource.word = 0; - IntSource.field.Ac3DmaDone = 1; - pAd->int_pending &= ~INT_AC3_DLY; - - bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource); - - RTMP_INT_LOCK(&pAd->irq_lock, flags); - /* - * double check to avoid lose of interrupts - */ - if ((pAd->int_pending & INT_AC3_DLY) || bReschedule) { - tasklet_hi_schedule(&pObj->ac3_dma_done_task); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); - return; - } - - /* enable TxDataInt again */ - rt2860_int_enable(pAd, INT_AC3_DLY); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); -} - -static void ac2_dma_done_tasklet(unsigned long data) -{ - unsigned long flags; - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data; - INT_SOURCE_CSR_STRUC IntSource; - struct os_cookie *pObj; - BOOLEAN bReschedule = 0; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - IntSource.word = 0; - IntSource.field.Ac2DmaDone = 1; - pAd->int_pending &= ~INT_AC2_DLY; - - bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource); - - RTMP_INT_LOCK(&pAd->irq_lock, flags); - - /* - * double check to avoid lose of interrupts - */ - if ((pAd->int_pending & INT_AC2_DLY) || bReschedule) { - tasklet_hi_schedule(&pObj->ac2_dma_done_task); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); - return; - } - - /* enable TxDataInt again */ - rt2860_int_enable(pAd, INT_AC2_DLY); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); -} - -static void ac1_dma_done_tasklet(unsigned long data) -{ - unsigned long flags; - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data; - INT_SOURCE_CSR_STRUC IntSource; - struct os_cookie *pObj; - BOOLEAN bReschedule = 0; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - -/* printk("ac0_dma_done_process\n"); */ - IntSource.word = 0; - IntSource.field.Ac1DmaDone = 1; - pAd->int_pending &= ~INT_AC1_DLY; - - bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource); - - RTMP_INT_LOCK(&pAd->irq_lock, flags); - /* - * double check to avoid lose of interrupts - */ - if ((pAd->int_pending & INT_AC1_DLY) || bReschedule) { - tasklet_hi_schedule(&pObj->ac1_dma_done_task); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); - return; - } - - /* enable TxDataInt again */ - rt2860_int_enable(pAd, INT_AC1_DLY); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); -} - -static void ac0_dma_done_tasklet(unsigned long data) -{ - unsigned long flags; - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)data; - INT_SOURCE_CSR_STRUC IntSource; - struct os_cookie *pObj; - BOOLEAN bReschedule = 0; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - -/* printk("ac0_dma_done_process\n"); */ - IntSource.word = 0; - IntSource.field.Ac0DmaDone = 1; - pAd->int_pending &= ~INT_AC0_DLY; - -/* RTMPHandleMgmtRingDmaDoneInterrupt(pAd); */ - bReschedule = RTMPHandleTxRingDmaDoneInterrupt(pAd, IntSource); - - RTMP_INT_LOCK(&pAd->irq_lock, flags); - /* - * double check to avoid lose of interrupts - */ - if ((pAd->int_pending & INT_AC0_DLY) || bReschedule) { - tasklet_hi_schedule(&pObj->ac0_dma_done_task); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); - return; - } - - /* enable TxDataInt again */ - rt2860_int_enable(pAd, INT_AC0_DLY); - RTMP_INT_UNLOCK(&pAd->irq_lock, flags); -} - -/*************************************************************************** - * - * interrupt handler related procedures. - * - **************************************************************************/ -int print_int_count; - -IRQ_HANDLE_TYPE rt2860_interrupt(int irq, void *dev_instance) -{ - struct net_device *net_dev = (struct net_device *)dev_instance; - struct rt_rtmp_adapter *pAd = NULL; - INT_SOURCE_CSR_STRUC IntSource; - struct os_cookie *pObj; - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - /* Note 03312008: we can not return here before - RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IntSource.word); - RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, IntSource.word); - Or kernel will panic after ifconfig ra0 down sometimes */ - - /* */ - /* Initial the Interrupt source. */ - /* */ - IntSource.word = 0x00000000L; -/* McuIntSource.word = 0x00000000L; */ - - /* */ - /* Get the interrupt sources & saved to local variable */ - /* */ - /*RTMP_IO_READ32(pAd, where, &McuIntSource.word); */ - /*RTMP_IO_WRITE32(pAd, , McuIntSource.word); */ - - /* */ - /* Flag fOP_STATUS_DOZE On, means ASIC put to sleep, elase means ASICK WakeUp */ - /* And at the same time, clock maybe turned off that say there is no DMA service. */ - /* when ASIC get to sleep. */ - /* To prevent system hang on power saving. */ - /* We need to check it before handle the INT_SOURCE_CSR, ASIC must be wake up. */ - /* */ - /* RT2661 => when ASIC is sleeping, MAC register cannot be read and written. */ - /* RT2860 => when ASIC is sleeping, MAC register can be read and written. */ -/* if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) */ - { - RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IntSource.word); - RTMP_IO_WRITE32(pAd, INT_SOURCE_CSR, IntSource.word); /* write 1 to clear */ - } -/* else */ -/* DBGPRINT(RT_DEBUG_TRACE, (">>>fOP_STATUS_DOZE<<<\n")); */ - -/* RTMP_IO_READ32(pAd, INT_SOURCE_CSR, &IsrAfterClear); */ -/* RTMP_IO_READ32(pAd, MCU_INT_SOURCE_CSR, &McuIsrAfterClear); */ -/* DBGPRINT(RT_DEBUG_INFO, ("====> RTMPHandleInterrupt(ISR=%08x,Mcu ISR=%08x, After clear ISR=%08x, MCU ISR=%08x)\n", */ -/* IntSource.word, McuIntSource.word, IsrAfterClear, McuIsrAfterClear)); */ - - /* Do nothing if Reset in progress */ - if (RTMP_TEST_FLAG - (pAd, - (fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS))) { - return IRQ_HANDLED; - } - /* */ - /* Handle interrupt, walk through all bits */ - /* Should start from highest priority interrupt */ - /* The priority can be adjust by altering processing if statement */ - /* */ - -#ifdef DBG - -#endif - - pAd->bPCIclkOff = FALSE; - - /* If required spinlock, each interrupt service routine has to acquire */ - /* and release itself. */ - /* */ - - /* Do nothing if NIC doesn't exist */ - if (IntSource.word == 0xffffffff) { - RTMP_SET_FLAG(pAd, - (fRTMP_ADAPTER_NIC_NOT_EXIST | - fRTMP_ADAPTER_HALT_IN_PROGRESS)); - return IRQ_HANDLED; - } - - if (IntSource.word & TxCoherent) { - DBGPRINT(RT_DEBUG_ERROR, (">>>TxCoherent<<<\n")); - RTMPHandleRxCoherentInterrupt(pAd); - } - - if (IntSource.word & RxCoherent) { - DBGPRINT(RT_DEBUG_ERROR, (">>>RxCoherent<<<\n")); - RTMPHandleRxCoherentInterrupt(pAd); - } - - if (IntSource.word & FifoStaFullInt) { - if ((pAd->int_disable_mask & FifoStaFullInt) == 0) { - /* mask FifoStaFullInt */ - rt2860_int_disable(pAd, FifoStaFullInt); - tasklet_hi_schedule(&pObj->fifo_statistic_full_task); - } - pAd->int_pending |= FifoStaFullInt; - } - - if (IntSource.word & INT_MGMT_DLY) { - if ((pAd->int_disable_mask & INT_MGMT_DLY) == 0) { - rt2860_int_disable(pAd, INT_MGMT_DLY); - tasklet_hi_schedule(&pObj->mgmt_dma_done_task); - } - pAd->int_pending |= INT_MGMT_DLY; - } - - if (IntSource.word & INT_RX) { - if ((pAd->int_disable_mask & INT_RX) == 0) { - - /* mask Rxint */ - rt2860_int_disable(pAd, INT_RX); - tasklet_hi_schedule(&pObj->rx_done_task); - } - pAd->int_pending |= INT_RX; - } - - if (IntSource.word & INT_AC3_DLY) { - - if ((pAd->int_disable_mask & INT_AC3_DLY) == 0) { - /* mask TxDataInt */ - rt2860_int_disable(pAd, INT_AC3_DLY); - tasklet_hi_schedule(&pObj->ac3_dma_done_task); - } - pAd->int_pending |= INT_AC3_DLY; - } - - if (IntSource.word & INT_AC2_DLY) { - - if ((pAd->int_disable_mask & INT_AC2_DLY) == 0) { - /* mask TxDataInt */ - rt2860_int_disable(pAd, INT_AC2_DLY); - tasklet_hi_schedule(&pObj->ac2_dma_done_task); - } - pAd->int_pending |= INT_AC2_DLY; - } - - if (IntSource.word & INT_AC1_DLY) { - - pAd->int_pending |= INT_AC1_DLY; - - if ((pAd->int_disable_mask & INT_AC1_DLY) == 0) { - /* mask TxDataInt */ - rt2860_int_disable(pAd, INT_AC1_DLY); - tasklet_hi_schedule(&pObj->ac1_dma_done_task); - } - - } - - if (IntSource.word & INT_AC0_DLY) { - -/* - if (IntSource.word & 0x2) { - u32 reg; - RTMP_IO_READ32(pAd, DELAY_INT_CFG, ®); - printk("IntSource.word = %08x, DELAY_REG = %08x\n", IntSource.word, reg); - } -*/ - pAd->int_pending |= INT_AC0_DLY; - - if ((pAd->int_disable_mask & INT_AC0_DLY) == 0) { - /* mask TxDataInt */ - rt2860_int_disable(pAd, INT_AC0_DLY); - tasklet_hi_schedule(&pObj->ac0_dma_done_task); - } - - } - - if (IntSource.word & PreTBTTInt) { - RTMPHandlePreTBTTInterrupt(pAd); - } - - if (IntSource.word & TBTTInt) { - RTMPHandleTBTTInterrupt(pAd); - } - - { - if (IntSource.word & AutoWakeupInt) - RTMPHandleTwakeupInterrupt(pAd); - } - - return IRQ_HANDLED; -} - -/* - * invalid or writeback cache - * and convert virtual address to physical address - */ -dma_addr_t linux_pci_map_single(struct rt_rtmp_adapter *pAd, void *ptr, - size_t size, int sd_idx, int direction) -{ - struct os_cookie *pObj; - - /* - ------ Porting Information ------ - > For Tx Alloc: - mgmt packets => sd_idx = 0 - SwIdx: pAd->MgmtRing.TxCpuIdx - pTxD : pAd->MgmtRing.Cell[SwIdx].AllocVa; - - data packets => sd_idx = 1 - TxIdx : pAd->TxRing[pTxBlk->QueIdx].TxCpuIdx - QueIdx: pTxBlk->QueIdx - pTxD : pAd->TxRing[pTxBlk->QueIdx].Cell[TxIdx].AllocVa; - - > For Rx Alloc: - sd_idx = -1 - */ - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - if (sd_idx == 1) { - struct rt_tx_blk *pTxBlk; - pTxBlk = (struct rt_tx_blk *)ptr; - return pci_map_single(pObj->pci_dev, pTxBlk->pSrcBufData, - pTxBlk->SrcBufLen, direction); - } else { - return pci_map_single(pObj->pci_dev, ptr, size, direction); - } - -} - -void linux_pci_unmap_single(struct rt_rtmp_adapter *pAd, dma_addr_t dma_addr, - size_t size, int direction) -{ - struct os_cookie *pObj; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - pci_unmap_single(pObj->pci_dev, dma_addr, size, direction); - -} diff --git a/trunk/drivers/staging/rt2860/rt_usb.c b/trunk/drivers/staging/rt2860/rt_usb.c deleted file mode 100644 index eb037d2e04a2..000000000000 --- a/trunk/drivers/staging/rt2860/rt_usb.c +++ /dev/null @@ -1,794 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtusb_bulk.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs - Justin P. Mattock 11/07/2010 Fix some typos. - -*/ - -#include "rt_config.h" - -void dump_urb(struct urb *purb) -{ - printk(KERN_DEBUG "urb :0x%08lx\n", (unsigned long)purb); - printk(KERN_DEBUG "\tdev :0x%08lx\n", (unsigned long)purb->dev); - printk(KERN_DEBUG "\t\tdev->state :0x%d\n", purb->dev->state); - printk(KERN_DEBUG "\tpipe :0x%08x\n", purb->pipe); - printk(KERN_DEBUG "\tstatus :%d\n", purb->status); - printk(KERN_DEBUG "\ttransfer_flags :0x%08x\n", purb->transfer_flags); - printk(KERN_DEBUG "\ttransfer_buffer :0x%08lx\n", - (unsigned long)purb->transfer_buffer); - printk(KERN_DEBUG "\ttransfer_buffer_length:%d\n", purb->transfer_buffer_length); - printk(KERN_DEBUG "\tactual_length :%d\n", purb->actual_length); - printk(KERN_DEBUG "\tsetup_packet :0x%08lx\n", - (unsigned long)purb->setup_packet); - printk(KERN_DEBUG "\tstart_frame :%d\n", purb->start_frame); - printk(KERN_DEBUG "\tnumber_of_packets :%d\n", purb->number_of_packets); - printk(KERN_DEBUG "\tinterval :%d\n", purb->interval); - printk(KERN_DEBUG "\terror_count :%d\n", purb->error_count); - printk(KERN_DEBUG "\tcontext :0x%08lx\n", - (unsigned long)purb->context); - printk(KERN_DEBUG "\tcomplete :0x%08lx\n\n", - (unsigned long)purb->complete); -} - -/* -======================================================================== -Routine Description: - Create kernel threads & tasklets. - -Arguments: - *net_dev Pointer to wireless net device interface - -Return Value: - NDIS_STATUS_SUCCESS - NDIS_STATUS_FAILURE - -Note: -======================================================================== -*/ -int RtmpMgmtTaskInit(struct rt_rtmp_adapter *pAd) -{ - struct rt_rtmp_os_task *pTask; - int status; - - /* - Creat TimerQ Thread, We need init timerQ related structure before create the timer thread. - */ - RtmpTimerQInit(pAd); - - pTask = &pAd->timerTask; - RtmpOSTaskInit(pTask, "RtmpTimerTask", pAd); - status = RtmpOSTaskAttach(pTask, RtmpTimerQThread, pTask); - if (status == NDIS_STATUS_FAILURE) { - printk(KERN_WARNING "%s: unable to start RtmpTimerQThread\n", - RTMP_OS_NETDEV_GET_DEVNAME(pAd->net_dev)); - return NDIS_STATUS_FAILURE; - } - - /* Creat MLME Thread */ - pTask = &pAd->mlmeTask; - RtmpOSTaskInit(pTask, "RtmpMlmeTask", pAd); - status = RtmpOSTaskAttach(pTask, MlmeThread, pTask); - if (status == NDIS_STATUS_FAILURE) { - printk(KERN_WARNING "%s: unable to start MlmeThread\n", - RTMP_OS_NETDEV_GET_DEVNAME(pAd->net_dev)); - return NDIS_STATUS_FAILURE; - } - - /* Creat Command Thread */ - pTask = &pAd->cmdQTask; - RtmpOSTaskInit(pTask, "RtmpCmdQTask", pAd); - status = RtmpOSTaskAttach(pTask, RTUSBCmdThread, pTask); - if (status == NDIS_STATUS_FAILURE) { - printk(KERN_WARNING "%s: unable to start RTUSBCmdThread\n", - RTMP_OS_NETDEV_GET_DEVNAME(pAd->net_dev)); - return NDIS_STATUS_FAILURE; - } - - return NDIS_STATUS_SUCCESS; -} - -/* -======================================================================== -Routine Description: - Close kernel threads. - -Arguments: - *pAd the raxx interface data pointer - -Return Value: - NONE - -Note: -======================================================================== -*/ -void RtmpMgmtTaskExit(struct rt_rtmp_adapter *pAd) -{ - int ret; - struct rt_rtmp_os_task *pTask; - - /* Sleep 50 milliseconds so pending io might finish normally */ - RTMPusecDelay(50000); - - /* We want to wait until all pending receives and sends to the */ - /* device object. We cancel any */ - /* irps. Wait until sends and receives have stopped. */ - RTUSBCancelPendingIRPs(pAd); - - /* We need clear timerQ related structure before exits of the timer thread. */ - RtmpTimerQExit(pAd); - - /* Terminate Mlme Thread */ - pTask = &pAd->mlmeTask; - ret = RtmpOSTaskKill(pTask); - if (ret == NDIS_STATUS_FAILURE) { - DBGPRINT(RT_DEBUG_ERROR, ("%s: kill task(%s) failed!\n", - RTMP_OS_NETDEV_GET_DEVNAME(pAd-> - net_dev), - pTask->taskName)); - } - - /* Terminate cmdQ thread */ - pTask = &pAd->cmdQTask; -#ifdef KTHREAD_SUPPORT - if (pTask->kthread_task) -#else - CHECK_PID_LEGALITY(pTask->taskPID) -#endif - { - mb(); - NdisAcquireSpinLock(&pAd->CmdQLock); - pAd->CmdQ.CmdQState = RTMP_TASK_STAT_STOPED; - NdisReleaseSpinLock(&pAd->CmdQLock); - mb(); - /*RTUSBCMDUp(pAd); */ - ret = RtmpOSTaskKill(pTask); - if (ret == NDIS_STATUS_FAILURE) { - DBGPRINT(RT_DEBUG_ERROR, ("%s: kill task(%s) failed!\n", - RTMP_OS_NETDEV_GET_DEVNAME - (pAd->net_dev), - pTask->taskName)); - } - pAd->CmdQ.CmdQState = RTMP_TASK_STAT_UNKNOWN; - } - - /* Terminate timer thread */ - pTask = &pAd->timerTask; - ret = RtmpOSTaskKill(pTask); - if (ret == NDIS_STATUS_FAILURE) { - DBGPRINT(RT_DEBUG_ERROR, ("%s: kill task(%s) failed!\n", - RTMP_OS_NETDEV_GET_DEVNAME(pAd-> - net_dev), - pTask->taskName)); - } - -} - -static void rtusb_dataout_complete(unsigned long data) -{ - struct rt_rtmp_adapter *pAd; - struct urb *pUrb; - struct os_cookie *pObj; - struct rt_ht_tx_context *pHTTXContext; - u8 BulkOutPipeId; - int Status; - unsigned long IrqFlags; - - pUrb = (struct urb *)data; - pHTTXContext = (struct rt_ht_tx_context *)pUrb->context; - pAd = pHTTXContext->pAd; - pObj = (struct os_cookie *)pAd->OS_Cookie; - Status = pUrb->status; - - /* Store BulkOut PipeId */ - BulkOutPipeId = pHTTXContext->BulkOutPipeId; - pAd->BulkOutDataOneSecCount++; - - /*DBGPRINT(RT_DEBUG_LOUD, ("Done-B(%d):I=0x%lx, CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", BulkOutPipeId, in_interrupt(), pHTTXContext->CurWritePosition, */ - /* pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad)); */ - - RTMP_IRQ_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - pAd->BulkOutPending[BulkOutPipeId] = FALSE; - pHTTXContext->IRPPending = FALSE; - pAd->watchDogTxPendingCnt[BulkOutPipeId] = 0; - - if (Status == USB_ST_NOERROR) { - pAd->BulkOutComplete++; - - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - - pAd->Counters8023.GoodTransmits++; - /*RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); */ - FREE_HTTX_RING(pAd, BulkOutPipeId, pHTTXContext); - /*RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); */ - - } else { /* STATUS_OTHER */ - u8 *pBuf; - - pAd->BulkOutCompleteOther++; - - pBuf = - &pHTTXContext->TransferBuffer->field. - WirelessPacket[pHTTXContext->NextBulkOutPosition]; - - if (!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST | - fRTMP_ADAPTER_BULKOUT_RESET))) { - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); - pAd->bulkResetPipeid = BulkOutPipeId; - pAd->bulkResetReq[BulkOutPipeId] = pAd->BulkOutReq; - } - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("BulkOutDataPacket failed: ReasonCode=%d!\n", - Status)); - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("\t>>BulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n", - pAd->BulkOutReq, pAd->BulkOutComplete, - pAd->BulkOutCompleteOther)); - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("\t>>BulkOut Header:%x %x %x %x %x %x %x %x\n", - pBuf[0], pBuf[1], pBuf[2], pBuf[3], pBuf[4], - pBuf[5], pBuf[6], pBuf[7])); - /*DBGPRINT_RAW(RT_DEBUG_ERROR, (">>BulkOutCompleteCancel=0x%x, BulkOutCompleteOther=0x%x\n", pAd->BulkOutCompleteCancel, pAd->BulkOutCompleteOther)); */ - - } - - /* */ - /* bInUse = TRUE, means some process are filling TX data, after that must turn on bWaitingBulkOut */ - /* bWaitingBulkOut = TRUE, means the TX data are waiting for bulk out. */ - /* */ - /*RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); */ - if ((pHTTXContext->ENextBulkOutPosition != - pHTTXContext->CurWritePosition) - && (pHTTXContext->ENextBulkOutPosition != - (pHTTXContext->CurWritePosition + 8)) - && !RTUSB_TEST_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_FRAG << - BulkOutPipeId))) { - /* Indicate There is data available */ - RTUSB_SET_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_NORMAL << - BulkOutPipeId)); - } - /*RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); */ - - /* Always call Bulk routine, even reset bulk. */ - /* The protection of rest bulk should be in BulkOut routine */ - RTUSBKickBulkOut(pAd); -} - -static void rtusb_null_frame_done_tasklet(unsigned long data) -{ - struct rt_rtmp_adapter *pAd; - struct rt_tx_context *pNullContext; - struct urb *pUrb; - int Status; - unsigned long irqFlag; - - pUrb = (struct urb *)data; - pNullContext = (struct rt_tx_context *)pUrb->context; - pAd = pNullContext->pAd; - Status = pUrb->status; - - /* Reset Null frame context flags */ - RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], irqFlag); - pNullContext->IRPPending = FALSE; - pNullContext->InUse = FALSE; - pAd->BulkOutPending[0] = FALSE; - pAd->watchDogTxPendingCnt[0] = 0; - - if (Status == USB_ST_NOERROR) { - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); - - RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); - } else { /* STATUS_OTHER */ - if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("Bulk Out Null Frame Failed, ReasonCode=%d!\n", - Status)); - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); - pAd->bulkResetPipeid = - (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG); - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, - NULL, 0); - } else { - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); - } - } - - /* Always call Bulk routine, even reset bulk. */ - /* The protection of rest bulk should be in BulkOut routine */ - RTUSBKickBulkOut(pAd); -} - -static void rtusb_rts_frame_done_tasklet(unsigned long data) -{ - struct rt_rtmp_adapter *pAd; - struct rt_tx_context *pRTSContext; - struct urb *pUrb; - int Status; - unsigned long irqFlag; - - pUrb = (struct urb *)data; - pRTSContext = (struct rt_tx_context *)pUrb->context; - pAd = pRTSContext->pAd; - Status = pUrb->status; - - /* Reset RTS frame context flags */ - RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], irqFlag); - pRTSContext->IRPPending = FALSE; - pRTSContext->InUse = FALSE; - - if (Status == USB_ST_NOERROR) { - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); - RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); - } else { /* STATUS_OTHER */ - if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("Bulk Out RTS Frame Failed\n")); - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); - pAd->bulkResetPipeid = - (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG); - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, - NULL, 0); - } else { - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], irqFlag); - } - } - - RTMP_SEM_LOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]); - pAd->BulkOutPending[pRTSContext->BulkOutPipeId] = FALSE; - RTMP_SEM_UNLOCK(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId]); - - /* Always call Bulk routine, even reset bulk. */ - /* The protection of rest bulk should be in BulkOut routine */ - RTUSBKickBulkOut(pAd); - -} - -static void rtusb_pspoll_frame_done_tasklet(unsigned long data) -{ - struct rt_rtmp_adapter *pAd; - struct rt_tx_context *pPsPollContext; - struct urb *pUrb; - int Status; - - pUrb = (struct urb *)data; - pPsPollContext = (struct rt_tx_context *)pUrb->context; - pAd = pPsPollContext->pAd; - Status = pUrb->status; - - /* Reset PsPoll context flags */ - pPsPollContext->IRPPending = FALSE; - pPsPollContext->InUse = FALSE; - pAd->watchDogTxPendingCnt[0] = 0; - - if (Status == USB_ST_NOERROR) { - RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); - } else { /* STATUS_OTHER */ - if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("Bulk Out PSPoll Failed\n")); - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); - pAd->bulkResetPipeid = - (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG); - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, - NULL, 0); - } - } - - RTMP_SEM_LOCK(&pAd->BulkOutLock[0]); - pAd->BulkOutPending[0] = FALSE; - RTMP_SEM_UNLOCK(&pAd->BulkOutLock[0]); - - /* Always call Bulk routine, even reset bulk. */ - /* The protection of rest bulk should be in BulkOut routine */ - RTUSBKickBulkOut(pAd); - -} - -/* -======================================================================== -Routine Description: - Handle received packets. - -Arguments: - data - URB information pointer - -Return Value: - None - -Note: -======================================================================== -*/ -static void rx_done_tasklet(unsigned long data) -{ - struct urb *pUrb; - struct rt_rx_context *pRxContext; - struct rt_rtmp_adapter *pAd; - int Status; - unsigned int IrqFlags; - - pUrb = (struct urb *)data; - pRxContext = (struct rt_rx_context *)pUrb->context; - pAd = pRxContext->pAd; - Status = pUrb->status; - - RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); - pRxContext->InUse = FALSE; - pRxContext->IRPPending = FALSE; - pRxContext->BulkInOffset += pUrb->actual_length; - /*NdisInterlockedDecrement(&pAd->PendingRx); */ - pAd->PendingRx--; - - if (Status == USB_ST_NOERROR) { - pAd->BulkInComplete++; - pAd->NextRxBulkInPosition = 0; - if (pRxContext->BulkInOffset) { /* As jan's comment, it may bulk-in success but size is zero. */ - pRxContext->Readable = TRUE; - INC_RING_INDEX(pAd->NextRxBulkInIndex, RX_RING_SIZE); - } - RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); - } else { /* STATUS_OTHER */ - pAd->BulkInCompleteFail++; - /* Still read this packet although it may comtain wrong bytes. */ - pRxContext->Readable = FALSE; - RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); - - /* Parsing all packets. because after reset, the index will reset to all zero. */ - if ((!RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_BULKIN_RESET | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST)))) { - - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("Bulk In Failed. Status=%d, BIIdx=0x%x, BIRIdx=0x%x, actual_length= 0x%x\n", - Status, pAd->NextRxBulkInIndex, - pAd->NextRxBulkInReadIndex, - pRxContext->pUrb->actual_length)); - - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET); - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN, - NULL, 0); - } - } - - ASSERT((pRxContext->InUse == pRxContext->IRPPending)); - - RTUSBBulkReceive(pAd); - - return; - -} - -static void rtusb_mgmt_dma_done_tasklet(unsigned long data) -{ - struct rt_rtmp_adapter *pAd; - struct rt_tx_context *pMLMEContext; - int index; - void *pPacket; - struct urb *pUrb; - int Status; - unsigned long IrqFlags; - - pUrb = (struct urb *)data; - pMLMEContext = (struct rt_tx_context *)pUrb->context; - pAd = pMLMEContext->pAd; - Status = pUrb->status; - index = pMLMEContext->SelfIdx; - - ASSERT((pAd->MgmtRing.TxDmaIdx == index)); - - RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags); - - if (Status != USB_ST_NOERROR) { - /*Bulk-Out fail status handle */ - if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("Bulk Out MLME Failed, Status=%d!\n", - Status)); - /* TODO: How to handle about the MLMEBulkOut failed issue. Need to resend the mgmt pkt? */ - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); - pAd->bulkResetPipeid = - (MGMTPIPEIDX | BULKOUT_MGMT_RESET_FLAG); - } - } - - pAd->BulkOutPending[MGMTPIPEIDX] = FALSE; - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags); - - RTMP_IRQ_LOCK(&pAd->MLMEBulkOutLock, IrqFlags); - /* Reset MLME context flags */ - pMLMEContext->IRPPending = FALSE; - pMLMEContext->InUse = FALSE; - pMLMEContext->bWaitingBulkOut = FALSE; - pMLMEContext->BulkOutSize = 0; - - pPacket = pAd->MgmtRing.Cell[index].pNdisPacket; - pAd->MgmtRing.Cell[index].pNdisPacket = NULL; - - /* Increase MgmtRing Index */ - INC_RING_INDEX(pAd->MgmtRing.TxDmaIdx, MGMT_RING_SIZE); - pAd->MgmtRing.TxSwFreeIdx++; - RTMP_IRQ_UNLOCK(&pAd->MLMEBulkOutLock, IrqFlags); - - /* No-matter success or fail, we free the mgmt packet. */ - if (pPacket) - RTMPFreeNdisPacket(pAd, pPacket); - - if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST)))) { - /* do nothing and return directly. */ - } else { - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET) && ((pAd->bulkResetPipeid & BULKOUT_MGMT_RESET_FLAG) == BULKOUT_MGMT_RESET_FLAG)) { /* For Mgmt Bulk-Out failed, ignore it now. */ - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, - NULL, 0); - } else { - - /* Always call Bulk routine, even reset bulk. */ - /* The protection of rest bulk should be in BulkOut routine */ - if (pAd->MgmtRing.TxSwFreeIdx < - MGMT_RING_SIZE - /* pMLMEContext->bWaitingBulkOut == TRUE */) { - RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME); - } - RTUSBKickBulkOut(pAd); - } - } - -} - -static void rtusb_ac3_dma_done_tasklet(unsigned long data) -{ - struct rt_rtmp_adapter *pAd; - struct rt_ht_tx_context *pHTTXContext; - u8 BulkOutPipeId = 3; - struct urb *pUrb; - - pUrb = (struct urb *)data; - pHTTXContext = (struct rt_ht_tx_context *)pUrb->context; - pAd = pHTTXContext->pAd; - - rtusb_dataout_complete((unsigned long)pUrb); - - if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST)))) { - /* do nothing and return directly. */ - } else { - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) { - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, - NULL, 0); - } else { - pHTTXContext = &pAd->TxContext[BulkOutPipeId]; - if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) && - /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */ - (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) && - (pHTTXContext->bCurWriting == FALSE)) { - RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, - MAX_TX_PROCESS); - } - - RTUSB_SET_BULK_FLAG(pAd, - fRTUSB_BULK_OUT_DATA_NORMAL << 3); - RTUSBKickBulkOut(pAd); - } - } - - return; -} - -static void rtusb_ac2_dma_done_tasklet(unsigned long data) -{ - struct rt_rtmp_adapter *pAd; - struct rt_ht_tx_context *pHTTXContext; - u8 BulkOutPipeId = 2; - struct urb *pUrb; - - pUrb = (struct urb *)data; - pHTTXContext = (struct rt_ht_tx_context *)pUrb->context; - pAd = pHTTXContext->pAd; - - rtusb_dataout_complete((unsigned long)pUrb); - - if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST)))) { - /* do nothing and return directly. */ - } else { - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) { - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, - NULL, 0); - } else { - pHTTXContext = &pAd->TxContext[BulkOutPipeId]; - if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) && - /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */ - (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) && - (pHTTXContext->bCurWriting == FALSE)) { - RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, - MAX_TX_PROCESS); - } - - RTUSB_SET_BULK_FLAG(pAd, - fRTUSB_BULK_OUT_DATA_NORMAL << 2); - RTUSBKickBulkOut(pAd); - } - } - - return; -} - -static void rtusb_ac1_dma_done_tasklet(unsigned long data) -{ - struct rt_rtmp_adapter *pAd; - struct rt_ht_tx_context *pHTTXContext; - u8 BulkOutPipeId = 1; - struct urb *pUrb; - - pUrb = (struct urb *)data; - pHTTXContext = (struct rt_ht_tx_context *)pUrb->context; - pAd = pHTTXContext->pAd; - - rtusb_dataout_complete((unsigned long)pUrb); - - if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST)))) { - /* do nothing and return directly. */ - } else { - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) { - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, - NULL, 0); - } else { - pHTTXContext = &pAd->TxContext[BulkOutPipeId]; - if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) && - /*((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */ - (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) && - (pHTTXContext->bCurWriting == FALSE)) { - RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, - MAX_TX_PROCESS); - } - - RTUSB_SET_BULK_FLAG(pAd, - fRTUSB_BULK_OUT_DATA_NORMAL << 1); - RTUSBKickBulkOut(pAd); - } - } - return; - -} - -static void rtusb_ac0_dma_done_tasklet(unsigned long data) -{ - struct rt_rtmp_adapter *pAd; - struct rt_ht_tx_context *pHTTXContext; - u8 BulkOutPipeId = 0; - struct urb *pUrb; - - pUrb = (struct urb *)data; - pHTTXContext = (struct rt_ht_tx_context *)pUrb->context; - pAd = pHTTXContext->pAd; - - rtusb_dataout_complete((unsigned long)pUrb); - - if ((RTMP_TEST_FLAG(pAd, (fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST)))) { - /* do nothing and return directly. */ - } else { - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET)) { - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_OUT, - NULL, 0); - } else { - pHTTXContext = &pAd->TxContext[BulkOutPipeId]; - if ((pAd->TxSwQueue[BulkOutPipeId].Number > 0) && - /* ((pHTTXContext->CurWritePosition > (pHTTXContext->NextBulkOutPosition + 0x6000)) || (pHTTXContext->NextBulkOutPosition > pHTTXContext->CurWritePosition + 0x6000)) && */ - (pAd->DeQueueRunning[BulkOutPipeId] == FALSE) && - (pHTTXContext->bCurWriting == FALSE)) { - RTMPDeQueuePacket(pAd, FALSE, BulkOutPipeId, - MAX_TX_PROCESS); - } - - RTUSB_SET_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL); - RTUSBKickBulkOut(pAd); - } - } - - return; - -} - -int RtmpNetTaskInit(struct rt_rtmp_adapter *pAd) -{ - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - /* Create receive tasklet */ - tasklet_init(&pObj->rx_done_task, rx_done_tasklet, (unsigned long)pAd); - tasklet_init(&pObj->mgmt_dma_done_task, rtusb_mgmt_dma_done_tasklet, - (unsigned long)pAd); - tasklet_init(&pObj->ac0_dma_done_task, rtusb_ac0_dma_done_tasklet, - (unsigned long)pAd); - tasklet_init(&pObj->ac1_dma_done_task, rtusb_ac1_dma_done_tasklet, - (unsigned long)pAd); - tasklet_init(&pObj->ac2_dma_done_task, rtusb_ac2_dma_done_tasklet, - (unsigned long)pAd); - tasklet_init(&pObj->ac3_dma_done_task, rtusb_ac3_dma_done_tasklet, - (unsigned long)pAd); - tasklet_init(&pObj->tbtt_task, tbtt_tasklet, (unsigned long)pAd); - tasklet_init(&pObj->null_frame_complete_task, - rtusb_null_frame_done_tasklet, (unsigned long)pAd); - tasklet_init(&pObj->rts_frame_complete_task, - rtusb_rts_frame_done_tasklet, (unsigned long)pAd); - tasklet_init(&pObj->pspoll_frame_complete_task, - rtusb_pspoll_frame_done_tasklet, (unsigned long)pAd); - - return NDIS_STATUS_SUCCESS; -} - -void RtmpNetTaskExit(struct rt_rtmp_adapter *pAd) -{ - struct os_cookie *pObj; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - tasklet_kill(&pObj->rx_done_task); - tasklet_kill(&pObj->mgmt_dma_done_task); - tasklet_kill(&pObj->ac0_dma_done_task); - tasklet_kill(&pObj->ac1_dma_done_task); - tasklet_kill(&pObj->ac2_dma_done_task); - tasklet_kill(&pObj->ac3_dma_done_task); - tasklet_kill(&pObj->tbtt_task); - tasklet_kill(&pObj->null_frame_complete_task); - tasklet_kill(&pObj->rts_frame_complete_task); - tasklet_kill(&pObj->pspoll_frame_complete_task); -} diff --git a/trunk/drivers/staging/rt2860/rtmp.h b/trunk/drivers/staging/rt2860/rtmp.h deleted file mode 100644 index 3c31340c946a..000000000000 --- a/trunk/drivers/staging/rt2860/rtmp.h +++ /dev/null @@ -1,4332 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp.h - - Abstract: - Miniport generic portion header file - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Paul Lin 2002-08-01 created - James Tan 2002-09-06 modified (Revise NTCRegTable) - John Chang 2004-09-06 modified for RT2600 - Justin P. Mattock 11/07/2010 Fix some typos -*/ -#ifndef __RTMP_H__ -#define __RTMP_H__ - -#include "spectrum_def.h" -#include "rtmp_dot11.h" -#include "rtmp_chip.h" - -struct rt_rtmp_adapter; - -/*#define DBG 1 */ - -/*#define DBG_DIAGNOSE 1 */ - -/*+++Add by shiang for merge MiniportMMRequest() and MiniportDataMMRequest() into one function */ -#define MAX_DATAMM_RETRY 3 -#define MGMT_USE_QUEUE_FLAG 0x80 -/*---Add by shiang for merge MiniportMMRequest() and MiniportDataMMRequest() into one function */ - -#define MAXSEQ (0xFFF) - -extern unsigned char SNAP_AIRONET[]; -extern unsigned char CISCO_OUI[]; -extern u8 BaSizeArray[4]; - -extern u8 BROADCAST_ADDR[MAC_ADDR_LEN]; -extern u8 ZERO_MAC_ADDR[MAC_ADDR_LEN]; -extern unsigned long BIT32[32]; -extern u8 BIT8[8]; -extern char *CipherName[]; -extern char *MCSToMbps[]; -extern u8 RxwiMCSToOfdmRate[12]; -extern u8 SNAP_802_1H[6]; -extern u8 SNAP_BRIDGE_TUNNEL[6]; -extern u8 SNAP_AIRONET[8]; -extern u8 CKIP_LLC_SNAP[8]; -extern u8 EAPOL_LLC_SNAP[8]; -extern u8 EAPOL[2]; -extern u8 IPX[2]; -extern u8 APPLE_TALK[2]; -extern u8 RateIdToPlcpSignal[12]; /* see IEEE802.11a-1999 p.14 */ -extern u8 OfdmRateToRxwiMCS[]; -extern u8 OfdmSignalToRateId[16]; -extern u8 default_cwmin[4]; -extern u8 default_cwmax[4]; -extern u8 default_sta_aifsn[4]; -extern u8 MapUserPriorityToAccessCategory[8]; - -extern u16 RateUpPER[]; -extern u16 RateDownPER[]; -extern u8 Phy11BNextRateDownward[]; -extern u8 Phy11BNextRateUpward[]; -extern u8 Phy11BGNextRateDownward[]; -extern u8 Phy11BGNextRateUpward[]; -extern u8 Phy11ANextRateDownward[]; -extern u8 Phy11ANextRateUpward[]; -extern char RssiSafeLevelForTxRate[]; -extern u8 RateIdToMbps[]; -extern u16 RateIdTo500Kbps[]; - -extern u8 CipherSuiteWpaNoneTkip[]; -extern u8 CipherSuiteWpaNoneTkipLen; - -extern u8 CipherSuiteWpaNoneAes[]; -extern u8 CipherSuiteWpaNoneAesLen; - -extern u8 SsidIe; -extern u8 SupRateIe; -extern u8 ExtRateIe; - -extern u8 HtCapIe; -extern u8 AddHtInfoIe; -extern u8 NewExtChanIe; - -extern u8 ErpIe; -extern u8 DsIe; -extern u8 TimIe; -extern u8 WpaIe; -extern u8 Wpa2Ie; -extern u8 IbssIe; -extern u8 Ccx2Ie; -extern u8 WapiIe; - -extern u8 WPA_OUI[]; -extern u8 RSN_OUI[]; -extern u8 WAPI_OUI[]; -extern u8 WME_INFO_ELEM[]; -extern u8 WME_PARM_ELEM[]; -extern u8 Ccx2QosInfo[]; -extern u8 Ccx2IeInfo[]; -extern u8 RALINK_OUI[]; -extern u8 PowerConstraintIE[]; - -extern u8 RateSwitchTable[]; -extern u8 RateSwitchTable11B[]; -extern u8 RateSwitchTable11G[]; -extern u8 RateSwitchTable11BG[]; - -extern u8 RateSwitchTable11BGN1S[]; -extern u8 RateSwitchTable11BGN2S[]; -extern u8 RateSwitchTable11BGN2SForABand[]; -extern u8 RateSwitchTable11N1S[]; -extern u8 RateSwitchTable11N2S[]; -extern u8 RateSwitchTable11N2SForABand[]; - -extern u8 PRE_N_HT_OUI[]; - -struct rt_rssi_sample { - char LastRssi0; /* last received RSSI */ - char LastRssi1; /* last received RSSI */ - char LastRssi2; /* last received RSSI */ - char AvgRssi0; - char AvgRssi1; - char AvgRssi2; - short AvgRssi0X8; - short AvgRssi1X8; - short AvgRssi2X8; -}; - -/* */ -/* Queue structure and macros */ -/* */ -struct rt_queue_entry; - -struct rt_queue_entry { - struct rt_queue_entry *Next; -}; - -/* Queue structure */ -struct rt_queue_header { - struct rt_queue_entry *Head; - struct rt_queue_entry *Tail; - unsigned long Number; -}; - -#define InitializeQueueHeader(QueueHeader) \ -{ \ - (QueueHeader)->Head = (QueueHeader)->Tail = NULL; \ - (QueueHeader)->Number = 0; \ -} - -#define RemoveHeadQueue(QueueHeader) \ -(QueueHeader)->Head; \ -{ \ - struct rt_queue_entry *pNext; \ - if ((QueueHeader)->Head != NULL) { \ - pNext = (QueueHeader)->Head->Next; \ - (QueueHeader)->Head->Next = NULL; \ - (QueueHeader)->Head = pNext; \ - if (pNext == NULL) \ - (QueueHeader)->Tail = NULL; \ - (QueueHeader)->Number--; \ - } \ -} - -#define InsertHeadQueue(QueueHeader, QueueEntry) \ -{ \ - ((struct rt_queue_entry *)QueueEntry)->Next = (QueueHeader)->Head; \ - (QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry); \ - if ((QueueHeader)->Tail == NULL) \ - (QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry); \ - (QueueHeader)->Number++; \ -} - -#define InsertTailQueue(QueueHeader, QueueEntry) \ -{ \ - ((struct rt_queue_entry *)QueueEntry)->Next = NULL; \ - if ((QueueHeader)->Tail) \ - (QueueHeader)->Tail->Next = (struct rt_queue_entry *)(QueueEntry); \ - else \ - (QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry); \ - (QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry); \ - (QueueHeader)->Number++; \ -} - -#define InsertTailQueueAc(pAd, pEntry, QueueHeader, QueueEntry) \ -{ \ - ((struct rt_queue_entry *)QueueEntry)->Next = NULL; \ - if ((QueueHeader)->Tail) \ - (QueueHeader)->Tail->Next = (struct rt_queue_entry *)(QueueEntry); \ - else \ - (QueueHeader)->Head = (struct rt_queue_entry *)(QueueEntry); \ - (QueueHeader)->Tail = (struct rt_queue_entry *)(QueueEntry); \ - (QueueHeader)->Number++; \ -} - -/* */ -/* Macros for flag and ref count operations */ -/* */ -#define RTMP_SET_FLAG(_M, _F) ((_M)->Flags |= (_F)) -#define RTMP_CLEAR_FLAG(_M, _F) ((_M)->Flags &= ~(_F)) -#define RTMP_CLEAR_FLAGS(_M) ((_M)->Flags = 0) -#define RTMP_TEST_FLAG(_M, _F) (((_M)->Flags & (_F)) != 0) -#define RTMP_TEST_FLAGS(_M, _F) (((_M)->Flags & (_F)) == (_F)) -/* Macro for power save flag. */ -#define RTMP_SET_PSFLAG(_M, _F) ((_M)->PSFlags |= (_F)) -#define RTMP_CLEAR_PSFLAG(_M, _F) ((_M)->PSFlags &= ~(_F)) -#define RTMP_CLEAR_PSFLAGS(_M) ((_M)->PSFlags = 0) -#define RTMP_TEST_PSFLAG(_M, _F) (((_M)->PSFlags & (_F)) != 0) -#define RTMP_TEST_PSFLAGS(_M, _F) (((_M)->PSFlags & (_F)) == (_F)) - -#define OPSTATUS_SET_FLAG(_pAd, _F) ((_pAd)->CommonCfg.OpStatusFlags |= (_F)) -#define OPSTATUS_CLEAR_FLAG(_pAd, _F) ((_pAd)->CommonCfg.OpStatusFlags &= ~(_F)) -#define OPSTATUS_TEST_FLAG(_pAd, _F) (((_pAd)->CommonCfg.OpStatusFlags & (_F)) != 0) - -#define CLIENT_STATUS_SET_FLAG(_pEntry, _F) ((_pEntry)->ClientStatusFlags |= (_F)) -#define CLIENT_STATUS_CLEAR_FLAG(_pEntry, _F) ((_pEntry)->ClientStatusFlags &= ~(_F)) -#define CLIENT_STATUS_TEST_FLAG(_pEntry, _F) (((_pEntry)->ClientStatusFlags & (_F)) != 0) - -#define RX_FILTER_SET_FLAG(_pAd, _F) ((_pAd)->CommonCfg.PacketFilter |= (_F)) -#define RX_FILTER_CLEAR_FLAG(_pAd, _F) ((_pAd)->CommonCfg.PacketFilter &= ~(_F)) -#define RX_FILTER_TEST_FLAG(_pAd, _F) (((_pAd)->CommonCfg.PacketFilter & (_F)) != 0) - -#define STA_NO_SECURITY_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11EncryptionDisabled) -#define STA_WEP_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) -#define STA_TKIP_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) -#define STA_AES_ON(_p) (_p->StaCfg.WepStatus == Ndis802_11Encryption3Enabled) - -#define STA_TGN_WIFI_ON(_p) (_p->StaCfg.bTGnWifiTest == TRUE) - -#define CKIP_KP_ON(_p) ((((_p)->StaCfg.CkipFlag) & 0x10) && ((_p)->StaCfg.bCkipCmicOn == TRUE)) -#define CKIP_CMIC_ON(_p) ((((_p)->StaCfg.CkipFlag) & 0x08) && ((_p)->StaCfg.bCkipCmicOn == TRUE)) - -#define INC_RING_INDEX(_idx, _RingSize) \ -{ \ - (_idx) = (_idx+1) % (_RingSize); \ -} - -/* StaActive.SupportedHtPhy.MCSSet is copied from AP beacon. Don't need to update here. */ -#define COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \ -{ \ - _pAd->StaActive.SupportedHtPhy.ChannelWidth = _pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth; \ - _pAd->StaActive.SupportedHtPhy.MimoPs = _pAd->MlmeAux.HtCapability.HtCapInfo.MimoPs; \ - _pAd->StaActive.SupportedHtPhy.GF = _pAd->MlmeAux.HtCapability.HtCapInfo.GF; \ - _pAd->StaActive.SupportedHtPhy.ShortGIfor20 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor20; \ - _pAd->StaActive.SupportedHtPhy.ShortGIfor40 = _pAd->MlmeAux.HtCapability.HtCapInfo.ShortGIfor40; \ - _pAd->StaActive.SupportedHtPhy.TxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.TxSTBC; \ - _pAd->StaActive.SupportedHtPhy.RxSTBC = _pAd->MlmeAux.HtCapability.HtCapInfo.RxSTBC; \ - _pAd->StaActive.SupportedHtPhy.ExtChanOffset = _pAd->MlmeAux.AddHtInfo.AddHtInfo.ExtChanOffset; \ - _pAd->StaActive.SupportedHtPhy.RecomWidth = _pAd->MlmeAux.AddHtInfo.AddHtInfo.RecomWidth; \ - _pAd->StaActive.SupportedHtPhy.OperaionMode = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.OperaionMode; \ - _pAd->StaActive.SupportedHtPhy.NonGfPresent = _pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent; \ - NdisMoveMemory((_pAd)->MacTab.Content[BSSID_WCID].HTCapability.MCSSet, (_pAd)->StaActive.SupportedPhyInfo.MCSSet, sizeof(u8) * 16);\ -} - -#define COPY_AP_HTSETTINGS_FROM_BEACON(_pAd, _pHtCapability) \ -{ \ - _pAd->MacTab.Content[BSSID_WCID].AMsduSize = (u8)(_pHtCapability->HtCapInfo.AMsduSize); \ - _pAd->MacTab.Content[BSSID_WCID].MmpsMode = (u8)(_pHtCapability->HtCapInfo.MimoPs); \ - _pAd->MacTab.Content[BSSID_WCID].MaxRAmpduFactor = (u8)(_pHtCapability->HtCapParm.MaxRAmpduFactor); \ -} - -/* */ -/* MACRO for 32-bit PCI register read / write */ -/* */ -/* Usage : RTMP_IO_READ32( */ -/* struct rt_rtmp_adapter *pAd, */ -/* unsigned long Register_Offset, */ -/* unsigned long * pValue) */ -/* */ -/* RTMP_IO_WRITE32( */ -/* struct rt_rtmp_adapter *pAd, */ -/* unsigned long Register_Offset, */ -/* unsigned long Value) */ -/* */ - -/* */ -/* Common fragment list structure - Identical to the scatter gather frag list structure */ -/* */ -/*#define struct rt_rtmp_sg_element SCATTER_GATHER_ELEMENT */ -/*#define struct rt_rtmp_sg_element *PSCATTER_GATHER_ELEMENT */ -#define NIC_MAX_PHYS_BUF_COUNT 8 - -struct rt_rtmp_sg_element { - void *Address; - unsigned long Length; - unsigned long *Reserved; -}; - -struct rt_rtmp_sg_list { - unsigned long NumberOfElements; - unsigned long *Reserved; - struct rt_rtmp_sg_element Elements[NIC_MAX_PHYS_BUF_COUNT]; -}; - -/* */ -/* Some utility macros */ -/* */ -#define GET_LNA_GAIN(_pAd) ((_pAd->LatchRfRegs.Channel <= 14) ? (_pAd->BLNAGain) : ((_pAd->LatchRfRegs.Channel <= 64) ? (_pAd->ALNAGain0) : ((_pAd->LatchRfRegs.Channel <= 128) ? (_pAd->ALNAGain1) : (_pAd->ALNAGain2)))) - -#define INC_COUNTER64(Val) (Val.QuadPart++) - -#define INFRA_ON(_p) (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_INFRA_ON)) -#define ADHOC_ON(_p) (OPSTATUS_TEST_FLAG(_p, fOP_STATUS_ADHOC_ON)) -#define MONITOR_ON(_p) (((_p)->StaCfg.BssType) == BSS_MONITOR) -#define IDLE_ON(_p) (!INFRA_ON(_p) && !ADHOC_ON(_p)) - -/* Check LEAP & CCKM flags */ -#define LEAP_ON(_p) (((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) -#define LEAP_CCKM_ON(_p) ((((_p)->StaCfg.LeapAuthMode) == CISCO_AuthModeLEAP) && ((_p)->StaCfg.LeapAuthInfo.CCKM == TRUE)) - -/* if original Ethernet frame contains no LLC/SNAP, then an extra LLC/SNAP encap is required */ -#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(_pBufVA, _pExtraLlcSnapEncap) \ -{ \ - if (((*(_pBufVA + 12) << 8) + *(_pBufVA + 13)) > 1500) { \ - _pExtraLlcSnapEncap = SNAP_802_1H; \ - if (NdisEqualMemory(IPX, _pBufVA + 12, 2) || \ - NdisEqualMemory(APPLE_TALK, _pBufVA + 12, 2)) { \ - _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL; \ - } \ - } \ - else { \ - _pExtraLlcSnapEncap = NULL; \ - } \ -} - -/* New Define for new Tx Path. */ -#define EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(_pBufVA, _pExtraLlcSnapEncap) \ -{ \ - if (((*(_pBufVA) << 8) + *(_pBufVA + 1)) > 1500) { \ - _pExtraLlcSnapEncap = SNAP_802_1H; \ - if (NdisEqualMemory(IPX, _pBufVA, 2) || \ - NdisEqualMemory(APPLE_TALK, _pBufVA, 2)) { \ - _pExtraLlcSnapEncap = SNAP_BRIDGE_TUNNEL; \ - } \ - } \ - else { \ - _pExtraLlcSnapEncap = NULL; \ - } \ -} - -#define MAKE_802_3_HEADER(_p, _pMac1, _pMac2, _pType) \ -{ \ - NdisMoveMemory(_p, _pMac1, MAC_ADDR_LEN); \ - NdisMoveMemory((_p + MAC_ADDR_LEN), _pMac2, MAC_ADDR_LEN); \ - NdisMoveMemory((_p + MAC_ADDR_LEN * 2), _pType, LENGTH_802_3_TYPE); \ -} - -/* if pData has no LLC/SNAP (neither RFC1042 nor Bridge tunnel), keep it that way. */ -/* else if the received frame is LLC/SNAP-encaped IPX or APPLETALK, preserve the LLC/SNAP field */ -/* else remove the LLC/SNAP field from the result Ethernet frame */ -/* Patch for WHQL only, which did not turn on Netbios but use IPX within its payload */ -/* Note: */ -/* _pData & _DataSize may be altered (remove 8-byte LLC/SNAP) by this MACRO */ -/* _pRemovedLLCSNAP: pointer to removed LLC/SNAP; NULL is not removed */ -#define CONVERT_TO_802_3(_p8023hdr, _pDA, _pSA, _pData, _DataSize, _pRemovedLLCSNAP) \ -{ \ - char LLC_Len[2]; \ - \ - _pRemovedLLCSNAP = NULL; \ - if (NdisEqualMemory(SNAP_802_1H, _pData, 6) || \ - NdisEqualMemory(SNAP_BRIDGE_TUNNEL, _pData, 6)) { \ - u8 *pProto = _pData + 6; \ - \ - if ((NdisEqualMemory(IPX, pProto, 2) || NdisEqualMemory(APPLE_TALK, pProto, 2)) && \ - NdisEqualMemory(SNAP_802_1H, _pData, 6)) { \ - LLC_Len[0] = (u8)(_DataSize / 256); \ - LLC_Len[1] = (u8)(_DataSize % 256); \ - MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len); \ - } \ - else { \ - MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, pProto); \ - _pRemovedLLCSNAP = _pData; \ - _DataSize -= LENGTH_802_1_H; \ - _pData += LENGTH_802_1_H; \ - } \ - } \ - else { \ - LLC_Len[0] = (u8)(_DataSize / 256); \ - LLC_Len[1] = (u8)(_DataSize % 256); \ - MAKE_802_3_HEADER(_p8023hdr, _pDA, _pSA, LLC_Len); \ - } \ -} - -/* Enqueue this frame to MLME engine */ -/* We need to enqueue the whole frame because MLME need to pass data type */ -/* information from 802.11 header */ -#ifdef RTMP_MAC_PCI -#define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal) \ -{ \ - u32 High32TSF, Low32TSF; \ - RTMP_IO_READ32(_pAd, TSF_TIMER_DW1, &High32TSF); \ - RTMP_IO_READ32(_pAd, TSF_TIMER_DW0, &Low32TSF); \ - MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (u8)_Rssi0, (u8)_Rssi1, (u8)_Rssi2, _FrameSize, _pFrame, (u8)_PlcpSignal); \ -} -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB -#define REPORT_MGMT_FRAME_TO_MLME(_pAd, Wcid, _pFrame, _FrameSize, _Rssi0, _Rssi1, _Rssi2, _PlcpSignal) \ -{ \ - u32 High32TSF = 0, Low32TSF = 0; \ - MlmeEnqueueForRecv(_pAd, Wcid, High32TSF, Low32TSF, (u8)_Rssi0, (u8)_Rssi1, (u8)_Rssi2, _FrameSize, _pFrame, (u8)_PlcpSignal); \ -} -#endif /* RTMP_MAC_USB // */ - -#define MAC_ADDR_EQUAL(pAddr1, pAddr2) RTMPEqualMemory((void *)(pAddr1), (void *)(pAddr2), MAC_ADDR_LEN) -#define SSID_EQUAL(ssid1, len1, ssid2, len2) ((len1 == len2) && (RTMPEqualMemory(ssid1, ssid2, len1))) - -/* */ -/* Check if it is Japan W53(ch52,56,60,64) channel. */ -/* */ -#define JapanChannelCheck(channel) ((channel == 52) || (channel == 56) || (channel == 60) || (channel == 64)) - -#define STA_EXTRA_SETTING(_pAd) - -#define STA_PORT_SECURED(_pAd) \ -{ \ - BOOLEAN Cancelled; \ - (_pAd)->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; \ - NdisAcquireSpinLock(&((_pAd)->MacTabLock)); \ - (_pAd)->MacTab.Content[BSSID_WCID].PortSecured = (_pAd)->StaCfg.PortSecured; \ - (_pAd)->MacTab.Content[BSSID_WCID].PrivacyFilter = Ndis802_11PrivFilterAcceptAll;\ - NdisReleaseSpinLock(&(_pAd)->MacTabLock); \ - RTMPCancelTimer(&((_pAd)->Mlme.LinkDownTimer), &Cancelled);\ - STA_EXTRA_SETTING(_pAd); \ -} - -/* */ -/* Data buffer for DMA operation, the buffer must be contiguous physical memory */ -/* Both DMA to / from CPU use the same structure. */ -/* */ -struct rt_rtmp_dmabuf { - unsigned long AllocSize; - void *AllocVa; /* TxBuf virtual address */ - dma_addr_t AllocPa; /* TxBuf physical address */ -}; - -/* */ -/* Control block (Descriptor) for all ring descriptor DMA operation, buffer must be */ -/* contiguous physical memory. char stored the binding Rx packet descriptor */ -/* which won't be released, driver has to wait until upper layer return the packet */ -/* before giving up this rx ring descriptor to ASIC. NDIS_BUFFER is associated pair */ -/* to describe the packet buffer. For Tx, char stored the tx packet descriptor */ -/* which driver should ACK upper layer when the tx is physically done or failed. */ -/* */ -struct rt_rtmp_dmacb { - unsigned long AllocSize; /* Control block size */ - void *AllocVa; /* Control block virtual address */ - dma_addr_t AllocPa; /* Control block physical address */ - void *pNdisPacket; - void *pNextNdisPacket; - - struct rt_rtmp_dmabuf DmaBuf; /* Associated DMA buffer structure */ -}; - -struct rt_rtmp_tx_ring { - struct rt_rtmp_dmacb Cell[TX_RING_SIZE]; - u32 TxCpuIdx; - u32 TxDmaIdx; - u32 TxSwFreeIdx; /* software next free tx index */ -}; - -struct rt_rtmp_rx_ring { - struct rt_rtmp_dmacb Cell[RX_RING_SIZE]; - u32 RxCpuIdx; - u32 RxDmaIdx; - int RxSwReadIdx; /* software next read index */ -}; - -struct rt_rtmp_mgmt_ring { - struct rt_rtmp_dmacb Cell[MGMT_RING_SIZE]; - u32 TxCpuIdx; - u32 TxDmaIdx; - u32 TxSwFreeIdx; /* software next free tx index */ -}; - -/* */ -/* Statistic counter structure */ -/* */ -struct rt_counter_802_3 { - /* General Stats */ - unsigned long GoodTransmits; - unsigned long GoodReceives; - unsigned long TxErrors; - unsigned long RxErrors; - unsigned long RxNoBuffer; - - /* Ethernet Stats */ - unsigned long RcvAlignmentErrors; - unsigned long OneCollision; - unsigned long MoreCollisions; - -}; - -struct rt_counter_802_11 { - unsigned long Length; - LARGE_INTEGER LastTransmittedFragmentCount; - LARGE_INTEGER TransmittedFragmentCount; - LARGE_INTEGER MulticastTransmittedFrameCount; - LARGE_INTEGER FailedCount; - LARGE_INTEGER RetryCount; - LARGE_INTEGER MultipleRetryCount; - LARGE_INTEGER RTSSuccessCount; - LARGE_INTEGER RTSFailureCount; - LARGE_INTEGER ACKFailureCount; - LARGE_INTEGER FrameDuplicateCount; - LARGE_INTEGER ReceivedFragmentCount; - LARGE_INTEGER MulticastReceivedFrameCount; - LARGE_INTEGER FCSErrorCount; -}; - -struct rt_counter_ralink { - unsigned long TransmittedByteCount; /* both successful and failure, used to calculate TX throughput */ - unsigned long ReceivedByteCount; /* both CRC okay and CRC error, used to calculate RX throughput */ - unsigned long BeenDisassociatedCount; - unsigned long BadCQIAutoRecoveryCount; - unsigned long PoorCQIRoamingCount; - unsigned long MgmtRingFullCount; - unsigned long RxCountSinceLastNULL; - unsigned long RxCount; - unsigned long RxRingErrCount; - unsigned long KickTxCount; - unsigned long TxRingErrCount; - LARGE_INTEGER RealFcsErrCount; - unsigned long PendingNdisPacketCount; - - unsigned long OneSecOsTxCount[NUM_OF_TX_RING]; - unsigned long OneSecDmaDoneCount[NUM_OF_TX_RING]; - u32 OneSecTxDoneCount; - unsigned long OneSecRxCount; - u32 OneSecTxAggregationCount; - u32 OneSecRxAggregationCount; - u32 OneSecReceivedByteCount; - u32 OneSecFrameDuplicateCount; - - u32 OneSecTransmittedByteCount; /* both successful and failure, used to calculate TX throughput */ - u32 OneSecTxNoRetryOkCount; - u32 OneSecTxRetryOkCount; - u32 OneSecTxFailCount; - u32 OneSecFalseCCACnt; /* CCA error count, for debug purpose, might move to global counter */ - u32 OneSecRxOkCnt; /* RX without error */ - u32 OneSecRxOkDataCnt; /* unicast-to-me DATA frame count */ - u32 OneSecRxFcsErrCnt; /* CRC error */ - u32 OneSecBeaconSentCnt; - u32 LastOneSecTotalTxCount; /* OneSecTxNoRetryOkCount + OneSecTxRetryOkCount + OneSecTxFailCount */ - u32 LastOneSecRxOkDataCnt; /* OneSecRxOkDataCnt */ - unsigned long DuplicateRcv; - unsigned long TxAggCount; - unsigned long TxNonAggCount; - unsigned long TxAgg1MPDUCount; - unsigned long TxAgg2MPDUCount; - unsigned long TxAgg3MPDUCount; - unsigned long TxAgg4MPDUCount; - unsigned long TxAgg5MPDUCount; - unsigned long TxAgg6MPDUCount; - unsigned long TxAgg7MPDUCount; - unsigned long TxAgg8MPDUCount; - unsigned long TxAgg9MPDUCount; - unsigned long TxAgg10MPDUCount; - unsigned long TxAgg11MPDUCount; - unsigned long TxAgg12MPDUCount; - unsigned long TxAgg13MPDUCount; - unsigned long TxAgg14MPDUCount; - unsigned long TxAgg15MPDUCount; - unsigned long TxAgg16MPDUCount; - - LARGE_INTEGER TransmittedOctetsInAMSDU; - LARGE_INTEGER TransmittedAMSDUCount; - LARGE_INTEGER ReceivedOctesInAMSDUCount; - LARGE_INTEGER ReceivedAMSDUCount; - LARGE_INTEGER TransmittedAMPDUCount; - LARGE_INTEGER TransmittedMPDUsInAMPDUCount; - LARGE_INTEGER TransmittedOctetsInAMPDUCount; - LARGE_INTEGER MPDUInReceivedAMPDUCount; -}; - -struct rt_counter_drs { - /* record each TX rate's quality. 0 is best, the bigger the worse. */ - u16 TxQuality[MAX_STEP_OF_TX_RATE_SWITCH]; - u8 PER[MAX_STEP_OF_TX_RATE_SWITCH]; - u8 TxRateUpPenalty; /* extra # of second penalty due to last unstable condition */ - unsigned long CurrTxRateStableTime; /* # of second in current TX rate */ - BOOLEAN fNoisyEnvironment; - BOOLEAN fLastSecAccordingRSSI; - u8 LastSecTxRateChangeAction; /* 0: no change, 1:rate UP, 2:rate down */ - u8 LastTimeTxRateChangeAction; /*Keep last time value of LastSecTxRateChangeAction */ - unsigned long LastTxOkCount; -}; - -/*************************************************************************** - * security key related data structure - **************************************************************************/ -struct rt_cipher_key { - u8 Key[16]; /* right now we implement 4 keys, 128 bits max */ - u8 RxMic[8]; /* make alignment */ - u8 TxMic[8]; - u8 TxTsc[6]; /* 48bit TSC value */ - u8 RxTsc[6]; /* 48bit TSC value */ - u8 CipherAlg; /* 0-none, 1:WEP64, 2:WEP128, 3:TKIP, 4:AES, 5:CKIP64, 6:CKIP128 */ - u8 KeyLen; - u8 BssId[6]; - /* Key length for each key, 0: entry is invalid */ - u8 Type; /* Indicate Pairwise/Group when reporting MIC error */ -}; - -/* structure to define WPA Group Key Rekey Interval */ -struct PACKED rt_802_11_wpa_rekey { - unsigned long ReKeyMethod; /* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */ - unsigned long ReKeyInterval; /* time-based: seconds, packet-based: kilo-packets */ -}; - -#ifdef RTMP_MAC_USB -/*************************************************************************** - * RTUSB I/O related data structure - **************************************************************************/ -struct rt_set_asic_wcid { - unsigned long WCID; /* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */ - unsigned long SetTid; /* time-based: seconds, packet-based: kilo-packets */ - unsigned long DeleteTid; /* time-based: seconds, packet-based: kilo-packets */ - u8 Addr[MAC_ADDR_LEN]; /* avoid in interrupt when write key */ -}; - -struct rt_set_asic_wcid_attri { - unsigned long WCID; /* mechanism for rekeying: 0:disable, 1: time-based, 2: packet-based */ - unsigned long Cipher; /* ASIC Cipher definition */ - u8 Addr[ETH_LENGTH_OF_ADDRESS]; -}; - -/* for USB interface, avoid in interrupt when write key */ -struct rt_add_pairwise_key_entry { - u8 MacAddr[6]; - u16 MacTabMatchWCID; /* ASIC */ - struct rt_cipher_key CipherKey; -}; - -/* Cipher suite type for mixed mode group cipher, P802.11i-2004 */ -typedef enum _RT_802_11_CIPHER_SUITE_TYPE { - Cipher_Type_NONE, - Cipher_Type_WEP40, - Cipher_Type_TKIP, - Cipher_Type_RSVD, - Cipher_Type_CCMP, - Cipher_Type_WEP104 -} RT_802_11_CIPHER_SUITE_TYPE, *PRT_802_11_CIPHER_SUITE_TYPE; -#endif /* RTMP_MAC_USB // */ - -struct rt_rogueap_entry { - u8 Addr[MAC_ADDR_LEN]; - u8 ErrorCode[2]; /*00 01-Invalid authentication type */ - /*00 02-Authentication timeout */ - /*00 03-Challenge from AP failed */ - /*00 04-Challenge to AP failed */ - BOOLEAN Reported; -}; - -struct rt_rogueap_table { - u8 RogueApNr; - struct rt_rogueap_entry RogueApEntry[MAX_LEN_OF_BSS_TABLE]; -}; - -/* */ -/* Cisco IAPP format */ -/* */ -struct rt_cisco_iapp_content { - u16 Length; /*IAPP Length */ - u8 MessageType; /*IAPP type */ - u8 FunctionCode; /*IAPP function type */ - u8 DestinaionMAC[MAC_ADDR_LEN]; - u8 SourceMAC[MAC_ADDR_LEN]; - u16 Tag; /*Tag(element IE) - Adjacent AP report */ - u16 TagLength; /*Length of element not including 4 byte header */ - u8 OUI[4]; /*0x00, 0x40, 0x96, 0x00 */ - u8 PreviousAP[MAC_ADDR_LEN]; /*MAC Address of access point */ - u16 Channel; - u16 SsidLen; - u8 Ssid[MAX_LEN_OF_SSID]; - u16 Seconds; /*Seconds that the client has been disassociated. */ -}; - -/* - * Fragment Frame structure - */ -struct rt_fragment_frame { - void *pFragPacket; - unsigned long RxSize; - u16 Sequence; - u16 LastFrag; - unsigned long Flags; /* Some extra frame information. bit 0: LLC presented */ -}; - -/* */ -/* Packet information for NdisQueryPacket */ -/* */ -struct rt_packet_info { - u32 PhysicalBufferCount; /* Physical breaks of buffer descriptor chained */ - u32 BufferCount; /* Number of Buffer descriptor chained */ - u32 TotalPacketLength; /* Self explained */ - char *pFirstBuffer; /* Pointer to first buffer descriptor */ -}; - -/* */ -/* Arcfour Structure Added by PaulWu */ -/* */ -struct rt_arcfourcontext { - u32 X; - u32 Y; - u8 STATE[256]; -}; - -/* */ -/* Tkip Key structure which RC4 key & MIC calculation */ -/* */ -struct rt_tkip_key_info { - u32 nBytesInM; /* # bytes in M for MICKEY */ - unsigned long IV16; - unsigned long IV32; - unsigned long K0; /* for MICKEY Low */ - unsigned long K1; /* for MICKEY Hig */ - unsigned long L; /* Current state for MICKEY */ - unsigned long R; /* Current state for MICKEY */ - unsigned long M; /* Message accumulator for MICKEY */ - u8 RC4KEY[16]; - u8 MIC[8]; -}; - -/* */ -/* Private / Misc data, counters for driver internal use */ -/* */ -struct rt_private { - u32 SystemResetCnt; /* System reset counter */ - u32 TxRingFullCnt; /* Tx ring full occurrence number */ - u32 PhyRxErrCnt; /* PHY Rx error count, for debug purpose, might move to global counter */ - /* Variables for WEP encryption / decryption in rtmp_wep.c */ - u32 FCSCRC32; - struct rt_arcfourcontext WEPCONTEXT; - /* Tkip stuff */ - struct rt_tkip_key_info Tx; - struct rt_tkip_key_info Rx; -}; - -/*************************************************************************** - * Channel and BBP related data structures - **************************************************************************/ -/* structure to tune BBP R66 (BBP TUNING) */ -struct rt_bbp_r66_tuning { - BOOLEAN bEnable; - u16 FalseCcaLowerThreshold; /* default 100 */ - u16 FalseCcaUpperThreshold; /* default 512 */ - u8 R66Delta; - u8 R66CurrentValue; - BOOLEAN R66LowerUpperSelect; /*Before LinkUp, Used LowerBound or UpperBound as R66 value. */ -}; - -/* structure to store channel TX power */ -struct rt_channel_tx_power { - u16 RemainingTimeForUse; /*unit: sec */ - u8 Channel; - char Power; - char Power2; - u8 MaxTxPwr; - u8 DfsReq; -}; - -/* structure to store 802.11j channel TX power */ -struct rt_channel_11j_tx_power { - u8 Channel; - u8 BW; /* BW_10 or BW_20 */ - char Power; - char Power2; - u16 RemainingTimeForUse; /*unit: sec */ -}; - -struct rt_soft_rx_ant_diversity { - u8 EvaluatePeriod; /* 0:not evalute status, 1: evaluate status, 2: switching status */ - u8 EvaluateStableCnt; - u8 Pair1PrimaryRxAnt; /* 0:Ant-E1, 1:Ant-E2 */ - u8 Pair1SecondaryRxAnt; /* 0:Ant-E1, 1:Ant-E2 */ - u8 Pair2PrimaryRxAnt; /* 0:Ant-E3, 1:Ant-E4 */ - u8 Pair2SecondaryRxAnt; /* 0:Ant-E3, 1:Ant-E4 */ - short Pair1AvgRssi[2]; /* AvgRssi[0]:E1, AvgRssi[1]:E2 */ - short Pair2AvgRssi[2]; /* AvgRssi[0]:E3, AvgRssi[1]:E4 */ - short Pair1LastAvgRssi; /* */ - short Pair2LastAvgRssi; /* */ - unsigned long RcvPktNumWhenEvaluate; - BOOLEAN FirstPktArrivedWhenEvaluate; - struct rt_ralink_timer RxAntDiversityTimer; -}; - -/*************************************************************************** - * structure for radar detection and channel switch - **************************************************************************/ -struct rt_radar_detect { - /*BOOLEAN IEEE80211H; // 0: disable, 1: enable IEEE802.11h */ - u8 CSCount; /*Channel switch counter */ - u8 CSPeriod; /*Channel switch period (beacon count) */ - u8 RDCount; /*Radar detection counter */ - u8 RDMode; /*Radar Detection mode */ - u8 RDDurRegion; /*Radar detection duration region */ - u8 BBPR16; - u8 BBPR17; - u8 BBPR18; - u8 BBPR21; - u8 BBPR22; - u8 BBPR64; - unsigned long InServiceMonitorCount; /* unit: sec */ - u8 DfsSessionTime; - BOOLEAN bFastDfs; - u8 ChMovingTime; - u8 LongPulseRadarTh; -}; - -typedef enum _ABGBAND_STATE_ { - UNKNOWN_BAND, - BG_BAND, - A_BAND, -} ABGBAND_STATE; - -#ifdef RTMP_MAC_PCI -/* Power save method control */ -typedef union _PS_CONTROL { - struct { - unsigned long EnablePSinIdle:1; /* Enable radio off when not connected to AP. radio on only when sitesurvey, */ - unsigned long EnableNewPS:1; /* Enable new Chip power save function . New method can only be applied in chip version after 2872. and PCIe. */ - unsigned long rt30xxPowerMode:2; /* Power Level Mode for rt30xx chip */ - unsigned long rt30xxFollowHostASPM:1; /* Card Follows Host's setting for rt30xx chip. */ - unsigned long rt30xxForceASPMTest:1; /* Force enable L1 for rt30xx chip. This has higher priority than rt30xxFollowHostASPM Mode. */ - unsigned long rsv:26; /* Radio Measurement Enable */ - } field; - unsigned long word; -} PS_CONTROL, *PPS_CONTROL; -#endif /* RTMP_MAC_PCI // */ - -/*************************************************************************** - * structure for MLME state machine - **************************************************************************/ -struct rt_mlme { - /* STA state machines */ - struct rt_state_machine CntlMachine; - struct rt_state_machine AssocMachine; - struct rt_state_machine AuthMachine; - struct rt_state_machine AuthRspMachine; - struct rt_state_machine SyncMachine; - struct rt_state_machine WpaPskMachine; - struct rt_state_machine LeapMachine; - STATE_MACHINE_FUNC AssocFunc[ASSOC_FUNC_SIZE]; - STATE_MACHINE_FUNC AuthFunc[AUTH_FUNC_SIZE]; - STATE_MACHINE_FUNC AuthRspFunc[AUTH_RSP_FUNC_SIZE]; - STATE_MACHINE_FUNC SyncFunc[SYNC_FUNC_SIZE]; - STATE_MACHINE_FUNC ActFunc[ACT_FUNC_SIZE]; - /* Action */ - struct rt_state_machine ActMachine; - - /* common WPA state machine */ - struct rt_state_machine WpaMachine; - STATE_MACHINE_FUNC WpaFunc[WPA_FUNC_SIZE]; - - unsigned long ChannelQuality; /* 0..100, Channel Quality Indication for Roaming */ - unsigned long Now32; /* latch the value of NdisGetSystemUpTime() */ - unsigned long LastSendNULLpsmTime; - - BOOLEAN bRunning; - spinlock_t TaskLock; - struct rt_mlme_queue Queue; - - u32 ShiftReg; - - struct rt_ralink_timer PeriodicTimer; - struct rt_ralink_timer APSDPeriodicTimer; - struct rt_ralink_timer LinkDownTimer; - struct rt_ralink_timer LinkUpTimer; -#ifdef RTMP_MAC_PCI - u8 bPsPollTimerRunning; - struct rt_ralink_timer PsPollTimer; - struct rt_ralink_timer RadioOnOffTimer; -#endif /* RTMP_MAC_PCI // */ - unsigned long PeriodicRound; - unsigned long OneSecPeriodicRound; - - u8 RealRxPath; - BOOLEAN bLowThroughput; - BOOLEAN bEnableAutoAntennaCheck; - struct rt_ralink_timer RxAntEvalTimer; - -#ifdef RT30xx - u8 CaliBW40RfR24; - u8 CaliBW20RfR24; -#endif /* RT30xx // */ - -#ifdef RTMP_MAC_USB - struct rt_ralink_timer AutoWakeupTimer; - BOOLEAN AutoWakeupTimerRunning; -#endif /* RTMP_MAC_USB // */ -}; - -/*************************************************************************** - * 802.11 N related data structures - **************************************************************************/ -struct reordering_mpdu { - struct reordering_mpdu *next; - void *pPacket; /* converted to 802.3 frame */ - int Sequence; /* sequence number of MPDU */ - BOOLEAN bAMSDU; -}; - -struct reordering_list { - struct reordering_mpdu *next; - int qlen; -}; - -struct reordering_mpdu_pool { - void *mem; - spinlock_t lock; - struct reordering_list freelist; -}; - -typedef enum _REC_BLOCKACK_STATUS { - Recipient_NONE = 0, - Recipient_USED, - Recipient_HandleRes, - Recipient_Accept -} REC_BLOCKACK_STATUS, *PREC_BLOCKACK_STATUS; - -typedef enum _ORI_BLOCKACK_STATUS { - Originator_NONE = 0, - Originator_USED, - Originator_WaitRes, - Originator_Done -} ORI_BLOCKACK_STATUS, *PORI_BLOCKACK_STATUS; - -struct rt_ba_ori_entry { - u8 Wcid; - u8 TID; - u8 BAWinSize; - u8 Token; -/* Sequence is to fill every outgoing QoS DATA frame's sequence field in 802.11 header. */ - u16 Sequence; - u16 TimeOutValue; - ORI_BLOCKACK_STATUS ORI_BA_Status; - struct rt_ralink_timer ORIBATimer; - void *pAdapter; -}; - -struct rt_ba_rec_entry { - u8 Wcid; - u8 TID; - u8 BAWinSize; /* 7.3.1.14. each buffer is capable of holding a max AMSDU or MSDU. */ - /*u8 NumOfRxPkt; */ - /*u8 Curindidx; // the head in the RX reordering buffer */ - u16 LastIndSeq; -/* u16 LastIndSeqAtTimer; */ - u16 TimeOutValue; - struct rt_ralink_timer RECBATimer; - unsigned long LastIndSeqAtTimer; - unsigned long nDropPacket; - unsigned long rcvSeq; - REC_BLOCKACK_STATUS REC_BA_Status; -/* u8 RxBufIdxUsed; */ - /* corresponding virtual address for RX reordering packet storage. */ - /*RTMP_REORDERDMABUF MAP_RXBuf[MAX_RX_REORDERBUF]; */ - spinlock_t RxReRingLock; /* Rx Ring spinlock */ -/* struct _BA_REC_ENTRY *pNext; */ - void *pAdapter; - struct reordering_list list; -}; - -struct rt_ba_table { - unsigned long numAsRecipient; /* I am recipient of numAsRecipient clients. These client are in the BARecEntry[] */ - unsigned long numAsOriginator; /* I am originator of numAsOriginator clients. These clients are in the BAOriEntry[] */ - unsigned long numDoneOriginator; /* count Done Originator sessions */ - struct rt_ba_ori_entry BAOriEntry[MAX_LEN_OF_BA_ORI_TABLE]; - struct rt_ba_rec_entry BARecEntry[MAX_LEN_OF_BA_REC_TABLE]; -}; - -/*For QureyBATableOID use; */ -struct PACKED rt_oid_ba_rec_entry { - u8 MACAddr[MAC_ADDR_LEN]; - u8 BaBitmap; /* if (BaBitmap&(1<MaxHTPhyMode.field.MODE >= MODE_HTMIX) - -#define IS_HT_RATE(_pMacEntry) \ - (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX) - -#define PEER_IS_HT_RATE(_pMacEntry) \ - (_pMacEntry->HTPhyMode.field.MODE >= MODE_HTMIX) - -/*This structure is for all 802.11n card InterOptibilityTest action. Reset all Num every n second. (Details see MLMEPeriodic) */ -struct rt_iot { - u8 Threshold[2]; - u8 ReorderTimeOutNum[MAX_LEN_OF_BA_REC_TABLE]; /* compare with threshold[0] */ - u8 RefreshNum[MAX_LEN_OF_BA_REC_TABLE]; /* compare with threshold[1] */ - unsigned long OneSecInWindowCount; - unsigned long OneSecFrameDuplicateCount; - unsigned long OneSecOutWindowCount; - u8 DelOriAct; - u8 DelRecAct; - u8 RTSShortProt; - u8 RTSLongProt; - BOOLEAN bRTSLongProtOn; - BOOLEAN bLastAtheros; - BOOLEAN bCurrentAtheros; - BOOLEAN bNowAtherosBurstOn; - BOOLEAN bNextDisableRxBA; - BOOLEAN bToggle; -}; - -/* This is the registry setting for 802.11n transmit setting. Used in advanced page. */ -typedef union _REG_TRANSMIT_SETTING { - struct { - /*u32 PhyMode:4; */ - /*u32 MCS:7; // MCS */ - u32 rsv0:10; - u32 TxBF:1; - u32 BW:1; /*channel bandwidth 20MHz or 40 MHz */ - u32 ShortGI:1; - u32 STBC:1; /*SPACE */ - u32 TRANSNO:2; - u32 HTMODE:1; - u32 EXTCHA:2; - u32 rsv:13; - } field; - u32 word; -} REG_TRANSMIT_SETTING, *PREG_TRANSMIT_SETTING; - -typedef union _DESIRED_TRANSMIT_SETTING { - struct { - u16 MCS:7; /* MCS */ - u16 PhyMode:4; - u16 FixedTxMode:2; /* If MCS isn't AUTO, fix rate in CCK, OFDM or HT mode. */ - u16 rsv:3; - } field; - u16 word; -} DESIRED_TRANSMIT_SETTING, *PDESIRED_TRANSMIT_SETTING; - -#ifdef RTMP_MAC_USB -/*************************************************************************** - * USB-based chip Beacon related data structures - **************************************************************************/ -#define BEACON_BITMAP_MASK 0xff -struct rt_beacon_sync { - u8 BeaconBuf[HW_BEACON_MAX_COUNT][HW_BEACON_OFFSET]; - u8 BeaconTxWI[HW_BEACON_MAX_COUNT][TXWI_SIZE]; - unsigned long TimIELocationInBeacon[HW_BEACON_MAX_COUNT]; - unsigned long CapabilityInfoLocationInBeacon[HW_BEACON_MAX_COUNT]; - BOOLEAN EnableBeacon; /* trigger to enable beacon transmission. */ - u8 BeaconBitMap; /* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter needs to change. */ - u8 DtimBitOn; /* NOTE: If the MAX_MBSSID_NUM is larger than 8, this parameter needs to change. */ -}; -#endif /* RTMP_MAC_USB // */ - -/*************************************************************************** - * Multiple SSID related data structures - **************************************************************************/ -#define WLAN_MAX_NUM_OF_TIM ((MAX_LEN_OF_MAC_TABLE >> 3) + 1) /* /8 + 1 */ -#define WLAN_CT_TIM_BCMC_OFFSET 0 /* unit: 32B */ - -/* clear bcmc TIM bit */ -#define WLAN_MR_TIM_BCMC_CLEAR(apidx) \ - pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] &= ~BIT8[0]; - -/* set bcmc TIM bit */ -#define WLAN_MR_TIM_BCMC_SET(apidx) \ - pAd->ApCfg.MBSSID[apidx].TimBitmaps[WLAN_CT_TIM_BCMC_OFFSET] |= BIT8[0]; - -/* clear a station PS TIM bit */ -#define WLAN_MR_TIM_BIT_CLEAR(ad_p, apidx, wcid) \ - { u8 tim_offset = wcid >> 3; \ - u8 bit_offset = wcid & 0x7; \ - ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] &= (~BIT8[bit_offset]); } - -/* set a station PS TIM bit */ -#define WLAN_MR_TIM_BIT_SET(ad_p, apidx, wcid) \ - { u8 tim_offset = wcid >> 3; \ - u8 bit_offset = wcid & 0x7; \ - ad_p->ApCfg.MBSSID[apidx].TimBitmaps[tim_offset] |= BIT8[bit_offset]; } - -/* configuration common to OPMODE_AP as well as OPMODE_STA */ -struct rt_common_config { - - BOOLEAN bCountryFlag; - u8 CountryCode[3]; - u8 Geography; - u8 CountryRegion; /* Enum of country region, 0:FCC, 1:IC, 2:ETSI, 3:SPAIN, 4:France, 5:MKK, 6:MKK1, 7:Israel */ - u8 CountryRegionForABand; /* Enum of country region for A band */ - u8 PhyMode; /* PHY_11A, PHY_11B, PHY_11BG_MIXED, PHY_ABG_MIXED */ - u16 Dsifs; /* in units of usec */ - unsigned long PacketFilter; /* Packet filter for receiving */ - u8 RegulatoryClass; - - char Ssid[MAX_LEN_OF_SSID]; /* NOT NULL-terminated */ - u8 SsidLen; /* the actual ssid length in used */ - u8 LastSsidLen; /* the actual ssid length in used */ - char LastSsid[MAX_LEN_OF_SSID]; /* NOT NULL-terminated */ - u8 LastBssid[MAC_ADDR_LEN]; - - u8 Bssid[MAC_ADDR_LEN]; - u16 BeaconPeriod; - u8 Channel; - u8 CentralChannel; /* Central Channel when using 40MHz is indicating. not real channel. */ - - u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 SupRateLen; - u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 ExtRateLen; - u8 DesireRate[MAX_LEN_OF_SUPPORTED_RATES]; /* OID_802_11_DESIRED_RATES */ - u8 MaxDesiredRate; - u8 ExpectedACKRate[MAX_LEN_OF_SUPPORTED_RATES]; - - unsigned long BasicRateBitmap; /* backup basic ratebitmap */ - - BOOLEAN bAPSDCapable; - BOOLEAN bInServicePeriod; - BOOLEAN bAPSDAC_BE; - BOOLEAN bAPSDAC_BK; - BOOLEAN bAPSDAC_VI; - BOOLEAN bAPSDAC_VO; - - /* because TSPEC can modify the APSD flag, we need to keep the APSD flag - requested in association stage from the station; - we need to recover the APSD flag after the TSPEC is deleted. */ - BOOLEAN bACMAPSDBackup[4]; /* for delivery-enabled & trigger-enabled both */ - BOOLEAN bACMAPSDTr[4]; /* no use */ - - BOOLEAN bNeedSendTriggerFrame; - BOOLEAN bAPSDForcePowerSave; /* Force power save mode, should only use in APSD-STAUT */ - unsigned long TriggerTimerCount; - u8 MaxSPLength; - u8 BBPCurrentBW; /* BW_10, BW_20, BW_40 */ - /* move to MULTISSID_STRUCT for MBSS */ - /*HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode;// For transmit phy setting in TXWI. */ - REG_TRANSMIT_SETTING RegTransmitSetting; /*registry transmit setting. this is for reading registry setting only. not useful. */ - /*u8 FixedTxMode; // Fixed Tx Mode (CCK, OFDM), for HT fixed tx mode (GF, MIX) , refer to RegTransmitSetting.field.HTMode */ - u8 TxRate; /* Same value to fill in TXD. TxRate is 6-bit */ - u8 MaxTxRate; /* RATE_1, RATE_2, RATE_5_5, RATE_11 */ - u8 TxRateIndex; /* Tx rate index in RateSwitchTable */ - u8 TxRateTableSize; /* Valid Tx rate table size in RateSwitchTable */ - /*BOOLEAN bAutoTxRateSwitch; */ - u8 MinTxRate; /* RATE_1, RATE_2, RATE_5_5, RATE_11 */ - u8 RtsRate; /* RATE_xxx */ - HTTRANSMIT_SETTING MlmeTransmit; /* MGMT frame PHY rate setting when operation at Ht rate. */ - u8 MlmeRate; /* RATE_xxx, used to send MLME frames */ - u8 BasicMlmeRate; /* Default Rate for sending MLME frames */ - - u16 RtsThreshold; /* in unit of BYTE */ - u16 FragmentThreshold; /* in unit of BYTE */ - - u8 TxPower; /* in unit of mW */ - unsigned long TxPowerPercentage; /* 0~100 % */ - unsigned long TxPowerDefault; /* keep for TxPowerPercentage */ - u8 PwrConstraint; - - BACAP_STRUC BACapability; /* NO USE = 0XFF ; IMMED_BA =1 ; DELAY_BA=0 */ - BACAP_STRUC REGBACapability; /* NO USE = 0XFF ; IMMED_BA =1 ; DELAY_BA=0 */ - - struct rt_iot IOTestParm; /* 802.11n InterOpbility Test Parameter; */ - unsigned long TxPreamble; /* Rt802_11PreambleLong, Rt802_11PreambleShort, Rt802_11PreambleAuto */ - BOOLEAN bUseZeroToDisableFragment; /* Microsoft use 0 as disable */ - unsigned long UseBGProtection; /* 0: auto, 1: always use, 2: always not use */ - BOOLEAN bUseShortSlotTime; /* 0: disable, 1 - use short slot (9us) */ - BOOLEAN bEnableTxBurst; /* 1: enble TX PACKET BURST (when BA is established or AP is not a legacy WMM AP), 0: disable TX PACKET BURST */ - BOOLEAN bAggregationCapable; /* 1: enable TX aggregation when the peer supports it */ - BOOLEAN bPiggyBackCapable; /* 1: enable TX piggy-back according MAC's version */ - BOOLEAN bIEEE80211H; /* 1: enable IEEE802.11h spec. */ - unsigned long DisableOLBCDetect; /* 0: enable OLBC detect; 1 disable OLBC detect */ - - BOOLEAN bRdg; - - BOOLEAN bWmmCapable; /* 0:disable WMM, 1:enable WMM */ - struct rt_qos_capability_parm APQosCapability; /* QOS capability of the current associated AP */ - struct rt_edca_parm APEdcaParm; /* EDCA parameters of the current associated AP */ - struct rt_qbss_load_parm APQbssLoad; /* QBSS load of the current associated AP */ - u8 AckPolicy[4]; /* ACK policy of the specified AC. see ACK_xxx */ - BOOLEAN bDLSCapable; /* 0:disable DLS, 1:enable DLS */ - /* a bitmap of BOOLEAN flags. each bit represent an operation status of a particular */ - /* BOOLEAN control, either ON or OFF. These flags should always be accessed via */ - /* OPSTATUS_TEST_FLAG(), OPSTATUS_SET_FLAG(), OP_STATUS_CLEAR_FLAG() macros. */ - /* see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition */ - unsigned long OpStatusFlags; - - BOOLEAN NdisRadioStateOff; /*For HCT 12.0, set this flag to TRUE instead of called MlmeRadioOff. */ - ABGBAND_STATE BandState; /* For setting BBP used on B/G or A mode. */ - - /* IEEE802.11H--DFS. */ - struct rt_radar_detect RadarDetect; - - /* HT */ - u8 BASize; /* USer desired BAWindowSize. Should not exceed our max capability */ - /*struct rt_ht_capability SupportedHtPhy; */ - struct rt_ht_capability DesiredHtPhy; - struct rt_ht_capability_ie HtCapability; - struct rt_add_ht_info_ie AddHTInfo; /* Useful as AP. */ - /*This IE is used with channel switch announcement element when changing to a new 40MHz. */ - /*This IE is included in channel switch announcement frames 7.4.1.5, beacons, probe Rsp. */ - struct rt_new_ext_chan_ie NewExtChanOffset; /*7.3.2.20A, 1 if extension channel is above the control channel, 3 if below, 0 if not present */ - - BOOLEAN bHTProtect; - BOOLEAN bMIMOPSEnable; - BOOLEAN bBADecline; -/*2008/11/05: KH add to support Antenna power-saving of AP<-- */ - BOOLEAN bGreenAPEnable; -/*2008/11/05: KH add to support Antenna power-saving of AP--> */ - BOOLEAN bDisableReordering; - BOOLEAN bForty_Mhz_Intolerant; - BOOLEAN bExtChannelSwitchAnnouncement; - BOOLEAN bRcvBSSWidthTriggerEvents; - unsigned long LastRcvBSSWidthTriggerEventsTime; - - u8 TxBASize; - - /* Enable wireless event */ - BOOLEAN bWirelessEvent; - BOOLEAN bWiFiTest; /* Enable this parameter for WiFi test */ - - /* Tx & Rx Stream number selection */ - u8 TxStream; - u8 RxStream; - - BOOLEAN bHardwareRadio; /* Hardware controlled Radio enabled */ - -#ifdef RTMP_MAC_USB - BOOLEAN bMultipleIRP; /* Multiple Bulk IN flag */ - u8 NumOfBulkInIRP; /* if bMultipleIRP == TRUE, NumOfBulkInIRP will be 4 otherwise be 1 */ - struct rt_ht_capability SupportedHtPhy; - unsigned long MaxPktOneTxBulk; - u8 TxBulkFactor; - u8 RxBulkFactor; - - BOOLEAN IsUpdateBeacon; - struct rt_beacon_sync *pBeaconSync; - struct rt_ralink_timer BeaconUpdateTimer; - u32 BeaconAdjust; - u32 BeaconFactor; - u32 BeaconRemain; -#endif /* RTMP_MAC_USB // */ - - spinlock_t MeasureReqTabLock; - struct rt_measure_req_tab *pMeasureReqTab; - - spinlock_t TpcReqTabLock; - struct rt_tpc_req_tab *pTpcReqTab; - - BOOLEAN PSPXlink; /* 0: Disable. 1: Enable */ - -#if defined(RT305x) || defined(RT30xx) - /* request by Gary, for High Power issue */ - u8 HighPowerPatchDisabled; -#endif - - BOOLEAN HT_DisallowTKIP; /* Restrict the encryption type in 11n HT mode */ -}; - -/* Modified by Wu Xi-Kun 4/21/2006 */ -/* STA configuration and status */ -struct rt_sta_admin_config { - /* GROUP 1 - */ - /* User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe */ - /* the user intended configuration, but not necessary fully equal to the final */ - /* settings in ACTIVE BSS after negotiation/compromise with the BSS holder (either */ - /* AP or IBSS holder). */ - /* Once initialized, user configuration can only be changed via OID_xxx */ - u8 BssType; /* BSS_INFRA or BSS_ADHOC */ - u16 AtimWin; /* used when starting a new IBSS */ - - /* GROUP 2 - */ - /* User configuration loaded from Registry, E2PROM or OID_xxx. These settings describe */ - /* the user intended configuration, and should be always applied to the final */ - /* settings in ACTIVE BSS without compromising with the BSS holder. */ - /* Once initialized, user configuration can only be changed via OID_xxx */ - u8 RssiTrigger; - u8 RssiTriggerMode; /* RSSI_TRIGGERED_UPON_BELOW_THRESHOLD or RSSI_TRIGGERED_UPON_EXCCEED_THRESHOLD */ - u16 DefaultListenCount; /* default listen count; */ - unsigned long WindowsPowerMode; /* Power mode for AC power */ - unsigned long WindowsBatteryPowerMode; /* Power mode for battery if exists */ - BOOLEAN bWindowsACCAMEnable; /* Enable CAM power mode when AC on */ - BOOLEAN bAutoReconnect; /* Set to TRUE when setting OID_802_11_SSID with no matching BSSID */ - unsigned long WindowsPowerProfile; /* Windows power profile, for NDIS5.1 PnP */ - - /* MIB:ieee802dot11.dot11smt(1).dot11StationConfigTable(1) */ - u16 Psm; /* power management mode (PWR_ACTIVE|PWR_SAVE) */ - u16 DisassocReason; - u8 DisassocSta[MAC_ADDR_LEN]; - u16 DeauthReason; - u8 DeauthSta[MAC_ADDR_LEN]; - u16 AuthFailReason; - u8 AuthFailSta[MAC_ADDR_LEN]; - - NDIS_802_11_PRIVACY_FILTER PrivacyFilter; /* PrivacyFilter enum for 802.1X */ - NDIS_802_11_AUTHENTICATION_MODE AuthMode; /* This should match to whatever microsoft defined */ - NDIS_802_11_WEP_STATUS WepStatus; - NDIS_802_11_WEP_STATUS OrigWepStatus; /* Original wep status set from OID */ - - /* Add to support different cipher suite for WPA2/WPA mode */ - NDIS_802_11_ENCRYPTION_STATUS GroupCipher; /* Multicast cipher suite */ - NDIS_802_11_ENCRYPTION_STATUS PairCipher; /* Unicast cipher suite */ - BOOLEAN bMixCipher; /* Indicate current Pair & Group use different cipher suites */ - u16 RsnCapability; - - NDIS_802_11_WEP_STATUS GroupKeyWepStatus; - - u8 WpaPassPhrase[64]; /* WPA PSK pass phrase */ - u32 WpaPassPhraseLen; /* the length of WPA PSK pass phrase */ - u8 PMK[32]; /* WPA PSK mode PMK */ - u8 PTK[64]; /* WPA PSK mode PTK */ - u8 GTK[32]; /* GTK from authenticator */ - struct rt_bssid_info SavedPMK[PMKID_NO]; - u32 SavedPMKNum; /* Saved PMKID number */ - - u8 DefaultKeyId; - - /* WPA 802.1x port control, WPA_802_1X_PORT_SECURED, WPA_802_1X_PORT_NOT_SECURED */ - u8 PortSecured; - - /* For WPA countermeasures */ - unsigned long LastMicErrorTime; /* record last MIC error time */ - unsigned long MicErrCnt; /* Should be 0, 1, 2, then reset to zero (after disassociation). */ - BOOLEAN bBlockAssoc; /* Block associate attempt for 60 seconds after counter measure occurred. */ - /* For WPA-PSK supplicant state */ - WPA_STATE WpaState; /* Default is SS_NOTUSE and handled by microsoft 802.1x */ - u8 ReplayCounter[8]; - u8 ANonce[32]; /* ANonce for WPA-PSK from auhenticator */ - u8 SNonce[32]; /* SNonce for WPA-PSK */ - - u8 LastSNR0; /* last received BEACON's SNR */ - u8 LastSNR1; /* last received BEACON's SNR for 2nd antenna */ - struct rt_rssi_sample RssiSample; - unsigned long NumOfAvgRssiSample; - - unsigned long LastBeaconRxTime; /* OS's timestamp of the last BEACON RX time */ - unsigned long Last11bBeaconRxTime; /* OS's timestamp of the last 11B BEACON RX time */ - unsigned long Last11gBeaconRxTime; /* OS's timestamp of the last 11G BEACON RX time */ - unsigned long Last20NBeaconRxTime; /* OS's timestamp of the last 20MHz N BEACON RX time */ - - unsigned long LastScanTime; /* Record last scan time for issue BSSID_SCAN_LIST */ - unsigned long ScanCnt; /* Scan counts since most recent SSID, BSSID, SCAN OID request */ - BOOLEAN bSwRadio; /* Software controlled Radio On/Off, TRUE: On */ - BOOLEAN bHwRadio; /* Hardware controlled Radio On/Off, TRUE: On */ - BOOLEAN bRadio; /* Radio state, And of Sw & Hw radio state */ - BOOLEAN bHardwareRadio; /* Hardware controlled Radio enabled */ - BOOLEAN bShowHiddenSSID; /* Show all known SSID in SSID list get operation */ - - /* New for WPA, windows want us to keep association information and */ - /* Fixed IEs from last association response */ - struct rt_ndis_802_11_association_information AssocInfo; - u16 ReqVarIELen; /* Length of next VIE include EID & Length */ - u8 ReqVarIEs[MAX_VIE_LEN]; /* The content saved here should be little-endian format. */ - u16 ResVarIELen; /* Length of next VIE include EID & Length */ - u8 ResVarIEs[MAX_VIE_LEN]; - - u8 RSNIE_Len; - u8 RSN_IE[MAX_LEN_OF_RSNIE]; /* The content saved here should be little-endian format. */ - - unsigned long CLBusyBytes; /* Save the total bytes received during channel load scan time */ - u16 RPIDensity[8]; /* Array for RPI density collection */ - - u8 RMReqCnt; /* Number of measurement request saved. */ - u8 CurrentRMReqIdx; /* Number of measurement request saved. */ - BOOLEAN ParallelReq; /* Parallel measurement, only one request performed, */ - /* It must be the same channel with maximum duration */ - u16 ParallelDuration; /* Maximum duration for parallel measurement */ - u8 ParallelChannel; /* Only one channel with parallel measurement */ - u16 IAPPToken; /* IAPP dialog token */ - /* Hack for channel load and noise histogram parameters */ - u8 NHFactor; /* Parameter for Noise histogram */ - u8 CLFactor; /* Parameter for channel load */ - - struct rt_ralink_timer StaQuickResponeForRateUpTimer; - BOOLEAN StaQuickResponeForRateUpTimerRunning; - - u8 DtimCount; /* 0.. DtimPeriod-1 */ - u8 DtimPeriod; /* default = 3 */ - - /*////////////////////////////////////////////////////////////////////////////////////// */ - /* This is only for WHQL test. */ - BOOLEAN WhqlTest; - /*////////////////////////////////////////////////////////////////////////////////////// */ - - struct rt_ralink_timer WpaDisassocAndBlockAssocTimer; - /* Fast Roaming */ - BOOLEAN bAutoRoaming; /* 0:disable auto roaming by RSSI, 1:enable auto roaming by RSSI */ - char dBmToRoam; /* the condition to roam when receiving Rssi less than this value. It's negative value. */ - - BOOLEAN IEEE8021X; - BOOLEAN IEEE8021x_required_keys; - struct rt_cipher_key DesireSharedKey[4]; /* Record user desired WEP keys */ - u8 DesireSharedKeyId; - - /* 0: driver ignores wpa_supplicant */ - /* 1: wpa_supplicant initiates scanning and AP selection */ - /* 2: driver takes care of scanning, AP selection, and IEEE 802.11 association parameters */ - u8 WpaSupplicantUP; - u8 WpaSupplicantScanCount; - BOOLEAN bRSN_IE_FromWpaSupplicant; - - char dev_name[16]; - u16 OriDevType; - - BOOLEAN bTGnWifiTest; - BOOLEAN bScanReqIsFromWebUI; - - HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode; /* For transmit phy setting in TXWI. */ - DESIRED_TRANSMIT_SETTING DesiredTransmitSetting; - struct rt_ht_phy_info DesiredHtPhyInfo; - BOOLEAN bAutoTxRateSwitch; - -#ifdef RTMP_MAC_PCI - u8 BBPR3; - /* PS Control has 2 meanings for advanced power save function. */ - /* 1. EnablePSinIdle : When no connection, always radio off except need to do site survey. */ - /* 2. EnableNewPS : will save more current in sleep or radio off mode. */ - PS_CONTROL PSControl; -#endif /* RTMP_MAC_PCI // */ - - BOOLEAN bAutoConnectByBssid; - unsigned long BeaconLostTime; /* seconds */ - BOOLEAN bForceTxBurst; /* 1: force enble TX PACKET BURST, 0: disable */ -}; - -/* This data structure keeps the current active BSS/IBSS's configuration that this STA */ -/* had agreed upon joining the network. Which means these parameters are usually decided */ -/* by the BSS/IBSS creator instead of user configuration. Data in this data structure */ -/* is valid only when either ADHOC_ON(pAd) or INFRA_ON(pAd) is TRUE. */ -/* Normally, after SCAN or failed roaming attempts, we need to recover back to */ -/* the current active settings. */ -struct rt_sta_active_config { - u16 Aid; - u16 AtimWin; /* in kusec; IBSS parameter set element */ - u16 CapabilityInfo; - u16 CfpMaxDuration; - u16 CfpPeriod; - - /* Copy supported rate from desired AP's beacon. We are trying to match */ - /* AP's supported and extended rate settings. */ - u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 SupRateLen; - u8 ExtRateLen; - /* Copy supported ht from desired AP's beacon. We are trying to match */ - struct rt_ht_phy_info SupportedPhyInfo; - struct rt_ht_capability SupportedHtPhy; -}; - -struct rt_mac_table_entry; - -struct rt_mac_table_entry { - /*Choose 1 from ValidAsWDS and ValidAsCLI to validize. */ - BOOLEAN ValidAsCLI; /* Sta mode, set this TRUE after Linkup,too. */ - BOOLEAN ValidAsWDS; /* This is WDS Entry. only for AP mode. */ - BOOLEAN ValidAsApCli; /* This is a AP-Client entry, only for AP mode which enable AP-Client functions. */ - BOOLEAN ValidAsMesh; - BOOLEAN ValidAsDls; /* This is DLS Entry. only for STA mode. */ - BOOLEAN isCached; - BOOLEAN bIAmBadAtheros; /* Flag if this is Atheros chip that has IOT problem. We need to turn on RTS/CTS protection. */ - - u8 EnqueueEapolStartTimerRunning; /* Enqueue EAPoL-Start for triggering EAP SM */ - /*jan for wpa */ - /* record which entry revoke MIC Failure, if it leaves the BSS itself, AP won't update aMICFailTime MIB */ - u8 CMTimerRunning; - u8 apidx; /* MBSS number */ - u8 RSNIE_Len; - u8 RSN_IE[MAX_LEN_OF_RSNIE]; - u8 ANonce[LEN_KEY_DESC_NONCE]; - u8 SNonce[LEN_KEY_DESC_NONCE]; - u8 R_Counter[LEN_KEY_DESC_REPLAY]; - u8 PTK[64]; - u8 ReTryCounter; - struct rt_ralink_timer RetryTimer; - struct rt_ralink_timer EnqueueStartForPSKTimer; /* A timer which enqueue EAPoL-Start for triggering PSK SM */ - NDIS_802_11_AUTHENTICATION_MODE AuthMode; /* This should match to whatever microsoft defined */ - NDIS_802_11_WEP_STATUS WepStatus; - NDIS_802_11_WEP_STATUS GroupKeyWepStatus; - AP_WPA_STATE WpaState; - GTK_STATE GTKState; - u16 PortSecured; - NDIS_802_11_PRIVACY_FILTER PrivacyFilter; /* PrivacyFilter enum for 802.1X */ - struct rt_cipher_key PairwiseKey; - void *pAd; - int PMKID_CacheIdx; - u8 PMKID[LEN_PMKID]; - - u8 Addr[MAC_ADDR_LEN]; - u8 PsMode; - SST Sst; - AUTH_STATE AuthState; /* for SHARED KEY authentication state machine used only */ - BOOLEAN IsReassocSta; /* Indicate whether this is a reassociation procedure */ - u16 Aid; - u16 CapabilityInfo; - u8 LastRssi; - unsigned long NoDataIdleCount; - u16 StationKeepAliveCount; /* unit: second */ - unsigned long PsQIdleCount; - struct rt_queue_header PsQueue; - - u32 StaConnectTime; /* the live time of this station since associated with AP */ - - BOOLEAN bSendBAR; - u16 NoBADataCountDown; - - u32 CachedBuf[16]; /* u32 (4 bytes) for alignment */ - u32 TxBFCount; /* 3*3 */ - u32 FIFOCount; - u32 DebugFIFOCount; - u32 DebugTxCount; - BOOLEAN bDlsInit; - -/*==================================================== */ -/*WDS entry needs these */ -/* if ValidAsWDS==TRUE, MatchWDSTabIdx is the index in WdsTab.MacTab */ - u32 MatchWDSTabIdx; - u8 MaxSupportedRate; - u8 CurrTxRate; - u8 CurrTxRateIndex; - /* to record the each TX rate's quality. 0 is best, the bigger the worse. */ - u16 TxQuality[MAX_STEP_OF_TX_RATE_SWITCH]; -/* u16 OneSecTxOkCount; */ - u32 OneSecTxNoRetryOkCount; - u32 OneSecTxRetryOkCount; - u32 OneSecTxFailCount; - u32 ContinueTxFailCnt; - u32 CurrTxRateStableTime; /* # of second in current TX rate */ - u8 TxRateUpPenalty; /* extra # of second penalty due to last unstable condition */ -/*==================================================== */ - - BOOLEAN fNoisyEnvironment; - BOOLEAN fLastSecAccordingRSSI; - u8 LastSecTxRateChangeAction; /* 0: no change, 1:rate UP, 2:rate down */ - char LastTimeTxRateChangeAction; /*Keep last time value of LastSecTxRateChangeAction */ - unsigned long LastTxOkCount; - u8 PER[MAX_STEP_OF_TX_RATE_SWITCH]; - - /* a bitmap of BOOLEAN flags. each bit represent an operation status of a particular */ - /* BOOLEAN control, either ON or OFF. These flags should always be accessed via */ - /* CLIENT_STATUS_TEST_FLAG(), CLIENT_STATUS_SET_FLAG(), CLIENT_STATUS_CLEAR_FLAG() macros. */ - /* see fOP_STATUS_xxx in RTMP_DEF.C for detail bit definition. fCLIENT_STATUS_AMSDU_INUSED */ - unsigned long ClientStatusFlags; - - HTTRANSMIT_SETTING HTPhyMode, MaxHTPhyMode, MinHTPhyMode; /* For transmit phy setting in TXWI. */ - - /* HT EWC MIMO-N used parameters */ - u16 RXBAbitmap; /* fill to on-chip RXWI_BA_BITMASK in 8.1.3RX attribute entry format */ - u16 TXBAbitmap; /* This bitmap as originator, only keep in software used to mark AMPDU bit in TXWI */ - u16 TXAutoBAbitmap; - u16 BADeclineBitmap; - u16 BARecWcidArray[NUM_OF_TID]; /* The mapping wcid of recipient session. if RXBAbitmap bit is masked */ - u16 BAOriWcidArray[NUM_OF_TID]; /* The mapping wcid of originator session. if TXBAbitmap bit is masked */ - u16 BAOriSequence[NUM_OF_TID]; /* The mapping wcid of originator session. if TXBAbitmap bit is masked */ - - /* 802.11n features. */ - u8 MpduDensity; - u8 MaxRAmpduFactor; - u8 AMsduSize; - u8 MmpsMode; /* MIMO power save more. */ - - struct rt_ht_capability_ie HTCapability; - - BOOLEAN bAutoTxRateSwitch; - - u8 RateLen; - struct rt_mac_table_entry *pNext; - u16 TxSeq[NUM_OF_TID]; - u16 NonQosDataSeq; - - struct rt_rssi_sample RssiSample; - - u32 TXMCSExpected[16]; - u32 TXMCSSuccessful[16]; - u32 TXMCSFailed[16]; - u32 TXMCSAutoFallBack[16][16]; - - unsigned long LastBeaconRxTime; - - unsigned long AssocDeadLine; -}; - -struct rt_mac_table { - u16 Size; - struct rt_mac_table_entry *Hash[HASH_TABLE_SIZE]; - struct rt_mac_table_entry Content[MAX_LEN_OF_MAC_TABLE]; - struct rt_queue_header McastPsQueue; - unsigned long PsQIdleCount; - BOOLEAN fAnyStationInPsm; - BOOLEAN fAnyStationBadAtheros; /* Check if any Station is atheros 802.11n Chip. We need to use RTS/CTS with Atheros 802,.11n chip. */ - BOOLEAN fAnyTxOPForceDisable; /* Check if it is necessary to disable BE TxOP */ - BOOLEAN fAllStationAsRalink; /* Check if all stations are ralink-chipset */ - BOOLEAN fAnyStationIsLegacy; /* Check if I use legacy rate to transmit to my BSS Station/ */ - BOOLEAN fAnyStationNonGF; /* Check if any Station can't support GF. */ - BOOLEAN fAnyStation20Only; /* Check if any Station can't support GF. */ - BOOLEAN fAnyStationMIMOPSDynamic; /* Check if any Station is MIMO Dynamic */ - BOOLEAN fAnyBASession; /* Check if there is BA session. Force turn on RTS/CTS */ -/*2008/10/28: KH add to support Antenna power-saving of AP<-- */ -/*2008/10/28: KH add to support Antenna power-saving of AP--> */ -}; - -struct wificonf { - BOOLEAN bShortGI; - BOOLEAN bGreenField; -}; - -struct rt_rtmp_dev_info { - u8 chipName[16]; - RTMP_INF_TYPE infType; -}; - -struct rt_rtmp_chip_op { - /* Calibration access related callback functions */ - int (*eeinit) (struct rt_rtmp_adapter *pAd); /* int (*eeinit)(struct rt_rtmp_adapter *pAd); */ - int (*eeread) (struct rt_rtmp_adapter *pAd, u16 offset, u16 *pValue); /* int (*eeread)(struct rt_rtmp_adapter *pAd, int offset, u16 *pValue); */ - - /* MCU related callback functions */ - int (*loadFirmware) (struct rt_rtmp_adapter *pAd); /* int (*loadFirmware)(struct rt_rtmp_adapter *pAd); */ - int (*eraseFirmware) (struct rt_rtmp_adapter *pAd); /* int (*eraseFirmware)(struct rt_rtmp_adapter *pAd); */ - int (*sendCommandToMcu) (struct rt_rtmp_adapter *pAd, u8 cmd, u8 token, u8 arg0, u8 arg1);; /* int (*sendCommandToMcu)(struct rt_rtmp_adapter *pAd, u8 cmd, u8 token, u8 arg0, u8 arg1); */ - - /* RF access related callback functions */ - struct rt_reg_pair *pRFRegTable; - void (*AsicRfInit) (struct rt_rtmp_adapter *pAd); - void (*AsicRfTurnOn) (struct rt_rtmp_adapter *pAd); - void (*AsicRfTurnOff) (struct rt_rtmp_adapter *pAd); - void (*AsicReverseRfFromSleepMode) (struct rt_rtmp_adapter *pAd); - void (*AsicHaltAction) (struct rt_rtmp_adapter *pAd); -}; - -/* */ -/* The miniport adapter structure */ -/* */ -struct rt_rtmp_adapter { - void *OS_Cookie; /* save specific structure relative to OS */ - struct net_device *net_dev; - unsigned long VirtualIfCnt; - const struct firmware *firmware; - - struct rt_rtmp_chip_op chipOps; - u16 ThisTbttNumToNextWakeUp; - -#ifdef RTMP_MAC_PCI -/*****************************************************************************************/ -/* PCI related parameters */ -/*****************************************************************************************/ - u8 *CSRBaseAddress; /* PCI MMIO Base Address, all access will use */ - unsigned int irq_num; - - u16 LnkCtrlBitMask; - u16 RLnkCtrlConfiguration; - u16 RLnkCtrlOffset; - u16 HostLnkCtrlConfiguration; - u16 HostLnkCtrlOffset; - u16 PCIePowerSaveLevel; - unsigned long Rt3xxHostLinkCtrl; /* USed for 3090F chip */ - unsigned long Rt3xxRalinkLinkCtrl; /* USed for 3090F chip */ - u16 DeviceID; /* Read from PCI config */ - unsigned long AccessBBPFailCount; - BOOLEAN bPCIclkOff; /* flag that indicates if the PICE power status in Configuration Space.. */ - BOOLEAN bPCIclkOffDisableTx; /* */ - - BOOLEAN brt30xxBanMcuCmd; /*when = 0xff means all commands are ok to set . */ - BOOLEAN b3090ESpecialChip; /*3090E special chip that write EEPROM 0x24=0x9280. */ - unsigned long CheckDmaBusyCount; /* Check Interrupt Status Register Count. */ - - u32 int_enable_reg; - u32 int_disable_mask; - u32 int_pending; - - struct rt_rtmp_dmabuf TxBufSpace[NUM_OF_TX_RING]; /* Shared memory of all 1st pre-allocated TxBuf associated with each TXD */ - struct rt_rtmp_dmabuf RxDescRing; /* Shared memory for RX descriptors */ - struct rt_rtmp_dmabuf TxDescRing[NUM_OF_TX_RING]; /* Shared memory for Tx descriptors */ - struct rt_rtmp_tx_ring TxRing[NUM_OF_TX_RING]; /* AC0~4 + HCCA */ -#endif /* RTMP_MAC_PCI // */ - - spinlock_t irq_lock; - u8 irq_disabled; - -#ifdef RTMP_MAC_USB -/*****************************************************************************************/ -/* USB related parameters */ -/*****************************************************************************************/ - struct usb_config_descriptor *config; - u32 BulkInEpAddr; /* bulk-in endpoint address */ - u32 BulkOutEpAddr[6]; /* bulk-out endpoint address */ - - u32 NumberOfPipes; - u16 BulkOutMaxPacketSize; - u16 BulkInMaxPacketSize; - - /*======Control Flags */ - long PendingIoCount; - unsigned long BulkFlags; - BOOLEAN bUsbTxBulkAggre; /* Flags for bulk out data priority */ - - /*======Cmd Thread */ - struct rt_cmdq CmdQ; - spinlock_t CmdQLock; /* CmdQLock spinlock */ - struct rt_rtmp_os_task cmdQTask; - - /*======Semaphores (event) */ - struct semaphore UsbVendorReq_semaphore; - void *UsbVendorReqBuf; - wait_queue_head_t *wait; -#endif /* RTMP_MAC_USB // */ - -/*****************************************************************************************/ -/* RBUS related parameters */ -/*****************************************************************************************/ - -/*****************************************************************************************/ -/* Both PCI/USB related parameters */ -/*****************************************************************************************/ - /*struct rt_rtmp_dev_info chipInfo; */ - RTMP_INF_TYPE infType; - -/*****************************************************************************************/ -/* Driver Mgmt related parameters */ -/*****************************************************************************************/ - struct rt_rtmp_os_task mlmeTask; -#ifdef RTMP_TIMER_TASK_SUPPORT - /* If you want use timer task to handle the timer related jobs, enable this. */ - struct rt_rtmp_timer_task_queue TimerQ; - spinlock_t TimerQLock; - struct rt_rtmp_os_task timerTask; -#endif /* RTMP_TIMER_TASK_SUPPORT // */ - -/*****************************************************************************************/ -/* Tx related parameters */ -/*****************************************************************************************/ - BOOLEAN DeQueueRunning[NUM_OF_TX_RING]; /* for ensuring RTUSBDeQueuePacket get call once */ - spinlock_t DeQueueLock[NUM_OF_TX_RING]; - -#ifdef RTMP_MAC_USB - /* Data related context and AC specified, 4 AC supported */ - spinlock_t BulkOutLock[6]; /* BulkOut spinlock for 4 ACs */ - spinlock_t MLMEBulkOutLock; /* MLME BulkOut lock */ - - struct rt_ht_tx_context TxContext[NUM_OF_TX_RING]; - spinlock_t TxContextQueueLock[NUM_OF_TX_RING]; /* TxContextQueue spinlock */ - - /* 4 sets of Bulk Out index and pending flag */ - u8 NextBulkOutIndex[4]; /* only used for 4 EDCA bulkout pipe */ - - BOOLEAN BulkOutPending[6]; /* used for total 6 bulkout pipe */ - u8 bulkResetPipeid; - BOOLEAN MgmtBulkPending; - unsigned long bulkResetReq[6]; -#endif /* RTMP_MAC_USB // */ - - /* resource for software backlog queues */ - struct rt_queue_header TxSwQueue[NUM_OF_TX_RING]; /* 4 AC + 1 HCCA */ - spinlock_t TxSwQueueLock[NUM_OF_TX_RING]; /* TxSwQueue spinlock */ - - struct rt_rtmp_dmabuf MgmtDescRing; /* Shared memory for MGMT descriptors */ - struct rt_rtmp_mgmt_ring MgmtRing; - spinlock_t MgmtRingLock; /* Prio Ring spinlock */ - -/*****************************************************************************************/ -/* Rx related parameters */ -/*****************************************************************************************/ - -#ifdef RTMP_MAC_PCI - struct rt_rtmp_rx_ring RxRing; - spinlock_t RxRingLock; /* Rx Ring spinlock */ -#ifdef RT3090 - spinlock_t McuCmdLock; /*MCU Command Queue spinlock */ -#endif /* RT3090 // */ -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - struct rt_rx_context RxContext[RX_RING_SIZE]; /* 1 for redundant multiple IRP bulk in. */ - spinlock_t BulkInLock; /* BulkIn spinlock for 4 ACs */ - u8 PendingRx; /* The Maximum pending Rx value should be RX_RING_SIZE. */ - u8 NextRxBulkInIndex; /* Indicate the current RxContext Index which hold by Host controller. */ - u8 NextRxBulkInReadIndex; /* Indicate the current RxContext Index which driver can read & process it. */ - unsigned long NextRxBulkInPosition; /* Want to contatenate 2 URB buffer while 1st is bulkin failed URB. This Position is 1st URB TransferLength. */ - unsigned long TransferBufferLength; /* current length of the packet buffer */ - unsigned long ReadPosition; /* current read position in a packet buffer */ -#endif /* RTMP_MAC_USB // */ - -/*****************************************************************************************/ -/* ASIC related parameters */ -/*****************************************************************************************/ - u32 MACVersion; /* MAC version. Record rt2860C(0x28600100) or rt2860D (0x28600101).. */ - - /* --------------------------- */ - /* E2PROM */ - /* --------------------------- */ - unsigned long EepromVersion; /* byte 0: version, byte 1: revision, byte 2~3: unused */ - unsigned long FirmwareVersion; /* byte 0: Minor version, byte 1: Major version, otherwise unused. */ - u16 EEPROMDefaultValue[NUM_EEPROM_BBP_PARMS]; - u8 EEPROMAddressNum; /* 93c46=6 93c66=8 */ - BOOLEAN EepromAccess; - u8 EFuseTag; - - /* --------------------------- */ - /* BBP Control */ - /* --------------------------- */ - u8 BbpWriteLatch[140]; /* record last BBP register value written via BBP_IO_WRITE/BBP_IO_WRITE_VY_REG_ID */ - char BbpRssiToDbmDelta; /* change from u8 to char for high power */ - struct rt_bbp_r66_tuning BbpTuning; - - /* ---------------------------- */ - /* RFIC control */ - /* ---------------------------- */ - u8 RfIcType; /* RFIC_xxx */ - unsigned long RfFreqOffset; /* Frequency offset for channel switching */ - struct rt_rtmp_rf_regs LatchRfRegs; /* latch the latest RF programming value since RF IC doesn't support READ */ - - EEPROM_ANTENNA_STRUC Antenna; /* Since Antenna definition is different for a & g. We need to save it for future reference. */ - EEPROM_NIC_CONFIG2_STRUC NicConfig2; - - /* This soft Rx Antenna Diversity mechanism is used only when user set */ - /* RX Antenna = DIVERSITY ON */ - struct rt_soft_rx_ant_diversity RxAnt; - - u8 RFProgSeq; - struct rt_channel_tx_power TxPower[MAX_NUM_OF_CHANNELS]; /* Store Tx power value for all channels. */ - struct rt_channel_tx_power ChannelList[MAX_NUM_OF_CHANNELS]; /* list all supported channels for site survey */ - struct rt_channel_11j_tx_power TxPower11J[MAX_NUM_OF_11JCHANNELS]; /* 802.11j channel and bw */ - struct rt_channel_11j_tx_power ChannelList11J[MAX_NUM_OF_11JCHANNELS]; /* list all supported channels for site survey */ - - u8 ChannelListNum; /* number of channel in ChannelList[] */ - u8 Bbp94; - BOOLEAN BbpForCCK; - unsigned long Tx20MPwrCfgABand[5]; - unsigned long Tx20MPwrCfgGBand[5]; - unsigned long Tx40MPwrCfgABand[5]; - unsigned long Tx40MPwrCfgGBand[5]; - - BOOLEAN bAutoTxAgcA; /* Enable driver auto Tx Agc control */ - u8 TssiRefA; /* Store Tssi reference value as 25 temperature. */ - u8 TssiPlusBoundaryA[5]; /* Tssi boundary for increase Tx power to compensate. */ - u8 TssiMinusBoundaryA[5]; /* Tssi boundary for decrease Tx power to compensate. */ - u8 TxAgcStepA; /* Store Tx TSSI delta increment / decrement value */ - char TxAgcCompensateA; /* Store the compensation (TxAgcStep * (idx-1)) */ - - BOOLEAN bAutoTxAgcG; /* Enable driver auto Tx Agc control */ - u8 TssiRefG; /* Store Tssi reference value as 25 temperature. */ - u8 TssiPlusBoundaryG[5]; /* Tssi boundary for increase Tx power to compensate. */ - u8 TssiMinusBoundaryG[5]; /* Tssi boundary for decrease Tx power to compensate. */ - u8 TxAgcStepG; /* Store Tx TSSI delta increment / decrement value */ - char TxAgcCompensateG; /* Store the compensation (TxAgcStep * (idx-1)) */ - - char BGRssiOffset0; /* Store B/G RSSI#0 Offset value on EEPROM 0x46h */ - char BGRssiOffset1; /* Store B/G RSSI#1 Offset value */ - char BGRssiOffset2; /* Store B/G RSSI#2 Offset value */ - - char ARssiOffset0; /* Store A RSSI#0 Offset value on EEPROM 0x4Ah */ - char ARssiOffset1; /* Store A RSSI#1 Offset value */ - char ARssiOffset2; /* Store A RSSI#2 Offset value */ - - char BLNAGain; /* Store B/G external LNA#0 value on EEPROM 0x44h */ - char ALNAGain0; /* Store A external LNA#0 value for ch36~64 */ - char ALNAGain1; /* Store A external LNA#1 value for ch100~128 */ - char ALNAGain2; /* Store A external LNA#2 value for ch132~165 */ -#ifdef RT30xx - /* for 3572 */ - u8 Bbp25; - u8 Bbp26; - - u8 TxMixerGain24G; /* Tx mixer gain value from EEPROM to improve Tx EVM / Tx DAC, 2.4G */ - u8 TxMixerGain5G; -#endif /* RT30xx // */ - /* ---------------------------- */ - /* LED control */ - /* ---------------------------- */ - MCU_LEDCS_STRUC LedCntl; - u16 Led1; /* read from EEPROM 0x3c */ - u16 Led2; /* EEPROM 0x3e */ - u16 Led3; /* EEPROM 0x40 */ - u8 LedIndicatorStrength; - u8 RssiSingalstrengthOffet; - BOOLEAN bLedOnScanning; - u8 LedStatus; - -/*****************************************************************************************/ -/* 802.11 related parameters */ -/*****************************************************************************************/ - /* outgoing BEACON frame buffer and corresponding TXD */ - struct rt_txwi BeaconTxWI; - u8 *BeaconBuf; - u16 BeaconOffset[HW_BEACON_MAX_COUNT]; - - /* pre-build PS-POLL and NULL frame upon link up. for efficiency purpose. */ - struct rt_pspoll_frame PsPollFrame; - struct rt_header_802_11 NullFrame; - -#ifdef RTMP_MAC_USB - struct rt_tx_context BeaconContext[BEACON_RING_SIZE]; - struct rt_tx_context NullContext; - struct rt_tx_context PsPollContext; - struct rt_tx_context RTSContext; -#endif /* RTMP_MAC_USB // */ - -/*=========AP=========== */ - -/*=======STA=========== */ - /* ----------------------------------------------- */ - /* STA specific configuration & operation status */ - /* used only when pAd->OpMode == OPMODE_STA */ - /* ----------------------------------------------- */ - struct rt_sta_admin_config StaCfg; /* user desired settings */ - struct rt_sta_active_config StaActive; /* valid only when ADHOC_ON(pAd) || INFRA_ON(pAd) */ - char nickname[IW_ESSID_MAX_SIZE + 1]; /* nickname, only used in the iwconfig i/f */ - int PreMediaState; - -/*=======Common=========== */ - /* OP mode: either AP or STA */ - u8 OpMode; /* OPMODE_STA, OPMODE_AP */ - - int IndicateMediaState; /* Base on Indication state, default is NdisMediaStateDisConnected */ - - /* MAT related parameters */ - - /* configuration: read from Registry & E2PROM */ - BOOLEAN bLocalAdminMAC; /* Use user changed MAC */ - u8 PermanentAddress[MAC_ADDR_LEN]; /* Factory default MAC address */ - u8 CurrentAddress[MAC_ADDR_LEN]; /* User changed MAC address */ - - /* ------------------------------------------------------ */ - /* common configuration to both OPMODE_STA and OPMODE_AP */ - /* ------------------------------------------------------ */ - struct rt_common_config CommonCfg; - struct rt_mlme Mlme; - - /* AP needs those variables for site survey feature. */ - struct rt_mlme_aux MlmeAux; /* temporary settings used during MLME state machine */ - struct rt_bss_table ScanTab; /* store the latest SCAN result */ - - /*About MacTab, the sta driver will use #0 and #1 for multicast and AP. */ - struct rt_mac_table MacTab; /* ASIC on-chip WCID entry table. At TX, ASIC always use key according to this on-chip table. */ - spinlock_t MacTabLock; - - struct rt_ba_table BATable; - - spinlock_t BATabLock; - struct rt_ralink_timer RECBATimer; - - /* encryption/decryption KEY tables */ - struct rt_cipher_key SharedKey[MAX_MBSSID_NUM][4]; /* STA always use SharedKey[BSS0][0..3] */ - - /* RX re-assembly buffer for fragmentation */ - struct rt_fragment_frame FragFrame; /* Frame storage for fragment frame */ - - /* various Counters */ - struct rt_counter_802_3 Counters8023; /* 802.3 counters */ - struct rt_counter_802_11 WlanCounters; /* 802.11 MIB counters */ - struct rt_counter_ralink RalinkCounters; /* Ralink proprietary counters */ - struct rt_counter_drs DrsCounters; /* counters for Dynamic TX Rate Switching */ - struct rt_private PrivateInfo; /* Private information & counters */ - - /* flags, see fRTMP_ADAPTER_xxx flags */ - unsigned long Flags; /* Represent current device status */ - unsigned long PSFlags; /* Power Save operation flag. */ - - /* current TX sequence # */ - u16 Sequence; - - /* Control disconnect / connect event generation */ - /*+++Not used anymore */ - unsigned long LinkDownTime; - /*--- */ - unsigned long LastRxRate; - unsigned long LastTxRate; - /*+++Used only for Station */ - BOOLEAN bConfigChanged; /* Config Change flag for the same SSID setting */ - /*--- */ - - unsigned long ExtraInfo; /* Extra information for displaying status */ - unsigned long SystemErrorBitmap; /* b0: E2PROM version error */ - - /*+++Not used anymore */ - unsigned long MacIcVersion; /* MAC/BBP serial interface issue solved after ver.D */ - /*--- */ - - /* --------------------------- */ - /* System event log */ - /* --------------------------- */ - struct rt_802_11_event_table EventTab; - - BOOLEAN HTCEnable; - - /*****************************************************************************************/ - /* Statistic related parameters */ - /*****************************************************************************************/ -#ifdef RTMP_MAC_USB - unsigned long BulkOutDataOneSecCount; - unsigned long BulkInDataOneSecCount; - unsigned long BulkLastOneSecCount; /* BulkOutDataOneSecCount + BulkInDataOneSecCount */ - unsigned long watchDogRxCnt; - unsigned long watchDogRxOverFlowCnt; - unsigned long watchDogTxPendingCnt[NUM_OF_TX_RING]; - int TransferedLength[NUM_OF_TX_RING]; -#endif /* RTMP_MAC_USB // */ - - BOOLEAN bUpdateBcnCntDone; - unsigned long watchDogMacDeadlock; /* prevent MAC/BBP into deadlock condition */ - /* ---------------------------- */ - /* DEBUG paramerts */ - /* ---------------------------- */ - /*unsigned long DebugSetting[4]; */ - BOOLEAN bBanAllBaSetup; - BOOLEAN bPromiscuous; - - /* ---------------------------- */ - /* rt2860c emulation-use Parameters */ - /* ---------------------------- */ - /*unsigned long rtsaccu[30]; */ - /*unsigned long ctsaccu[30]; */ - /*unsigned long cfendaccu[30]; */ - /*unsigned long bacontent[16]; */ - /*unsigned long rxint[RX_RING_SIZE+1]; */ - /*u8 rcvba[60]; */ - BOOLEAN bLinkAdapt; - BOOLEAN bForcePrintTX; - BOOLEAN bForcePrintRX; - /*BOOLEAN bDisablescanning; //defined in RT2870 USB */ - BOOLEAN bStaFifoTest; - BOOLEAN bProtectionTest; - BOOLEAN bBroadComHT; - /*+++Following add from RT2870 USB. */ - unsigned long BulkOutReq; - unsigned long BulkOutComplete; - unsigned long BulkOutCompleteOther; - unsigned long BulkOutCompleteCancel; /* seems not used now? */ - unsigned long BulkInReq; - unsigned long BulkInComplete; - unsigned long BulkInCompleteFail; - /*--- */ - - struct wificonf WIFItestbed; - - struct reordering_mpdu_pool mpdu_blk_pool; - - unsigned long OneSecondnonBEpackets; /* record non BE packets per second */ - -#ifdef LINUX - struct iw_statistics iw_stats; - - struct net_device_stats stats; -#endif /* LINUX // */ - - unsigned long TbttTickCount; -#ifdef PCI_MSI_SUPPORT - BOOLEAN HaveMsi; -#endif /* PCI_MSI_SUPPORT // */ - - u8 is_on; - -#define TIME_BASE (1000000/OS_HZ) -#define TIME_ONE_SECOND (1000000/TIME_BASE) - u8 flg_be_adjust; - unsigned long be_adjust_last_time; - - u8 FlgCtsEnabled; - u8 PM_FlgSuspend; - -#ifdef RT30xx -#ifdef RTMP_EFUSE_SUPPORT - BOOLEAN bUseEfuse; - u8 EEPROMImage[1024]; -#endif /* RTMP_EFUSE_SUPPORT // */ -#endif /* RT30xx // */ -}; - -#define DELAYINTMASK 0x0003fffb -#define INTMASK 0x0003fffb -#define IndMask 0x0003fffc -#define RxINT 0x00000005 /* Delayed Rx or indivi rx */ -#define TxDataInt 0x000000fa /* Delayed Tx or indivi tx */ -#define TxMgmtInt 0x00000102 /* Delayed Tx or indivi tx */ -#define TxCoherent 0x00020000 /* tx coherent */ -#define RxCoherent 0x00010000 /* rx coherent */ -#define McuCommand 0x00000200 /* mcu */ -#define PreTBTTInt 0x00001000 /* Pre-TBTT interrupt */ -#define TBTTInt 0x00000800 /* TBTT interrupt */ -#define GPTimeOutInt 0x00008000 /* GPtimeout interrupt */ -#define AutoWakeupInt 0x00004000 /* AutoWakeupInt interrupt */ -#define FifoStaFullInt 0x00002000 /* fifo statistics full interrupt */ - -/*************************************************************************** - * Rx Path software control block related data structures - **************************************************************************/ -struct rt_rx_blk { - RT28XX_RXD_STRUC RxD; - struct rt_rxwi *pRxWI; - struct rt_header_802_11 *pHeader; - void *pRxPacket; - u8 *pData; - u16 DataSize; - u16 Flags; - u8 UserPriority; /* for calculate TKIP MIC using */ -}; - -#define RX_BLK_SET_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags |= _flag) -#define RX_BLK_TEST_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags & _flag) -#define RX_BLK_CLEAR_FLAG(_pRxBlk, _flag) (_pRxBlk->Flags &= ~(_flag)) - -#define fRX_WDS 0x0001 -#define fRX_AMSDU 0x0002 -#define fRX_ARALINK 0x0004 -#define fRX_HTC 0x0008 -#define fRX_PAD 0x0010 -#define fRX_AMPDU 0x0020 -#define fRX_QOS 0x0040 -#define fRX_INFRA 0x0080 -#define fRX_EAP 0x0100 -#define fRX_MESH 0x0200 -#define fRX_APCLI 0x0400 -#define fRX_DLS 0x0800 -#define fRX_WPI 0x1000 - -#define LENGTH_AMSDU_SUBFRAMEHEAD 14 -#define LENGTH_ARALINK_SUBFRAMEHEAD 14 -#define LENGTH_ARALINK_HEADER_FIELD 2 - -/*************************************************************************** - * Tx Path software control block related data structures - **************************************************************************/ -#define TX_UNKOWN_FRAME 0x00 -#define TX_MCAST_FRAME 0x01 -#define TX_LEGACY_FRAME 0x02 -#define TX_AMPDU_FRAME 0x04 -#define TX_AMSDU_FRAME 0x08 -#define TX_RALINK_FRAME 0x10 -#define TX_FRAG_FRAME 0x20 - -/* Currently the sizeof(struct rt_tx_blk) is 148 bytes. */ -struct rt_tx_blk { - u8 QueIdx; - u8 TxFrameType; /* Indicate the Transmission type of the all frames in one batch */ - u8 TotalFrameNum; /* Total frame number that wants to send-out in one batch */ - u16 TotalFragNum; /* Total frame fragments required in one batch */ - u16 TotalFrameLen; /* Total length of all frames that wants to send-out in one batch */ - - struct rt_queue_header TxPacketList; - struct rt_mac_table_entry *pMacEntry; /* NULL: packet with 802.11 RA field is multicast/broadcast address */ - HTTRANSMIT_SETTING *pTransmit; - - /* Following structure used for the characteristics of a specific packet. */ - void *pPacket; - u8 *pSrcBufHeader; /* Reference to the head of sk_buff->data */ - u8 *pSrcBufData; /* Reference to the sk_buff->data, will change depending on the handling progresss */ - u32 SrcBufLen; /* Length of packet payload which not including Layer 2 header */ - u8 *pExtraLlcSnapEncap; /* NULL means no extra LLC/SNAP is required */ - u8 HeaderBuf[128]; /* TempBuffer for TX_INFO + TX_WI + 802.11 Header + padding + AMSDU SubHeader + LLC/SNAP */ - /*RT2870 2.1.0.0 uses only 80 bytes */ - /*RT3070 2.1.1.0 uses only 96 bytes */ - /*RT3090 2.1.0.0 uses only 96 bytes */ - u8 MpduHeaderLen; /* 802.11 header length NOT including the padding */ - u8 HdrPadLen; /* recording Header Padding Length; */ - u8 apidx; /* The interface associated to this packet */ - u8 Wcid; /* The MAC entry associated to this packet */ - u8 UserPriority; /* priority class of packet */ - u8 FrameGap; /* what kind of IFS does this packet use */ - u8 MpduReqNum; /* number of fragments of this frame */ - u8 TxRate; /* TODO: Obsoleted? Should change to MCS? */ - u8 CipherAlg; /* cipher alogrithm */ - struct rt_cipher_key *pKey; - - u16 Flags; /*See following definitions for detail. */ - - /*YOU SHOULD NOT TOUCH IT! Following parameters are used for hardware-depended layer. */ - unsigned long Priv; /* Hardware specific value saved in here. */ -}; - -#define fTX_bRtsRequired 0x0001 /* Indicate if need send RTS frame for protection. Not used in RT2860/RT2870. */ -#define fTX_bAckRequired 0x0002 /* the packet need ack response */ -#define fTX_bPiggyBack 0x0004 /* Legacy device use Piggback or not */ -#define fTX_bHTRate 0x0008 /* allow to use HT rate */ -#define fTX_bForceNonQoS 0x0010 /* force to transmit frame without WMM-QoS in HT mode */ -#define fTX_bAllowFrag 0x0020 /* allow to fragment the packet, A-MPDU, A-MSDU, A-Ralink is not allowed to fragment */ -#define fTX_bMoreData 0x0040 /* there are more data packets in PowerSave Queue */ -#define fTX_bWMM 0x0080 /* QOS Data */ -#define fTX_bClearEAPFrame 0x0100 - -#define TX_BLK_SET_FLAG(_pTxBlk, _flag) (_pTxBlk->Flags |= _flag) -#define TX_BLK_TEST_FLAG(_pTxBlk, _flag) (((_pTxBlk->Flags & _flag) == _flag) ? 1 : 0) -#define TX_BLK_CLEAR_FLAG(_pTxBlk, _flag) (_pTxBlk->Flags &= ~(_flag)) - -/*************************************************************************** - * Other static inline function definitions - **************************************************************************/ -static inline void ConvertMulticastIP2MAC(u8 *pIpAddr, - u8 **ppMacAddr, - u16 ProtoType) -{ - if (pIpAddr == NULL) - return; - - if (ppMacAddr == NULL || *ppMacAddr == NULL) - return; - - switch (ProtoType) { - case ETH_P_IPV6: -/* memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS); */ - *(*ppMacAddr) = 0x33; - *(*ppMacAddr + 1) = 0x33; - *(*ppMacAddr + 2) = pIpAddr[12]; - *(*ppMacAddr + 3) = pIpAddr[13]; - *(*ppMacAddr + 4) = pIpAddr[14]; - *(*ppMacAddr + 5) = pIpAddr[15]; - break; - - case ETH_P_IP: - default: -/* memset(*ppMacAddr, 0, ETH_LENGTH_OF_ADDRESS); */ - *(*ppMacAddr) = 0x01; - *(*ppMacAddr + 1) = 0x00; - *(*ppMacAddr + 2) = 0x5e; - *(*ppMacAddr + 3) = pIpAddr[1] & 0x7f; - *(*ppMacAddr + 4) = pIpAddr[2]; - *(*ppMacAddr + 5) = pIpAddr[3]; - break; - } - - return; -} - -char *GetPhyMode(int Mode); -char *GetBW(int BW); - -/* */ -/* Private routines in rtmp_init.c */ -/* */ -int RTMPAllocAdapterBlock(void *handle, - struct rt_rtmp_adapter **ppAdapter); - -int RTMPAllocTxRxRingMemory(struct rt_rtmp_adapter *pAd); - -void RTMPFreeAdapter(struct rt_rtmp_adapter *pAd); - -int NICReadRegParameters(struct rt_rtmp_adapter *pAd, - void *WrapperConfigurationContext); - -#ifdef RTMP_RF_RW_SUPPORT -void NICInitRFRegisters(struct rt_rtmp_adapter *pAd); - -void RtmpChipOpsRFHook(struct rt_rtmp_adapter *pAd); - -int RT30xxWriteRFRegister(struct rt_rtmp_adapter *pAd, - u8 regID, u8 value); - -int RT30xxReadRFRegister(struct rt_rtmp_adapter *pAd, - u8 regID, u8 *pValue); -#endif /* RTMP_RF_RW_SUPPORT // */ - -void NICReadEEPROMParameters(struct rt_rtmp_adapter *pAd, u8 *mac_addr); - -void NICInitAsicFromEEPROM(struct rt_rtmp_adapter *pAd); - -int NICInitializeAdapter(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset); - -int NICInitializeAsic(struct rt_rtmp_adapter *pAd, IN BOOLEAN bHardReset); - -void NICIssueReset(struct rt_rtmp_adapter *pAd); - -void RTMPRingCleanUp(struct rt_rtmp_adapter *pAd, u8 RingType); - -void UserCfgInit(struct rt_rtmp_adapter *pAd); - -void NICResetFromError(struct rt_rtmp_adapter *pAd); - -int NICLoadFirmware(struct rt_rtmp_adapter *pAd); - -void NICEraseFirmware(struct rt_rtmp_adapter *pAd); - -int NICLoadRateSwitchingParams(struct rt_rtmp_adapter *pAd); - -BOOLEAN NICCheckForHang(struct rt_rtmp_adapter *pAd); - -void NICUpdateFifoStaCounters(struct rt_rtmp_adapter *pAd); - -void NICUpdateRawCounters(struct rt_rtmp_adapter *pAd); - -void RTMPZeroMemory(void *pSrc, unsigned long Length); - -unsigned long RTMPCompareMemory(void *pSrc1, void *pSrc2, unsigned long Length); - -void RTMPMoveMemory(void *pDest, void *pSrc, unsigned long Length); - -void AtoH(char *src, u8 *dest, int destlen); - -void RTMPPatchMacBbpBug(struct rt_rtmp_adapter *pAd); - -void RTMPInitTimer(struct rt_rtmp_adapter *pAd, - struct rt_ralink_timer *pTimer, - void *pTimerFunc, void *pData, IN BOOLEAN Repeat); - -void RTMPSetTimer(struct rt_ralink_timer *pTimer, unsigned long Value); - -void RTMPModTimer(struct rt_ralink_timer *pTimer, unsigned long Value); - -void RTMPCancelTimer(struct rt_ralink_timer *pTimer, OUT BOOLEAN * pCancelled); - -void RTMPSetLED(struct rt_rtmp_adapter *pAd, u8 Status); - -void RTMPSetSignalLED(struct rt_rtmp_adapter *pAd, IN NDIS_802_11_RSSI Dbm); - -void RTMPEnableRxTx(struct rt_rtmp_adapter *pAd); - -/* */ -/* prototype in action.c */ -/* */ -void ActionStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *S, - OUT STATE_MACHINE_FUNC Trans[]); - -void MlmeADDBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void MlmeDELBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void MlmeDLSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void MlmeInvalidAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void MlmeQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerAddBAReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerAddBARspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerDelBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerBAAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void SendPSMPAction(struct rt_rtmp_adapter *pAd, u8 Wcid, u8 Psmp); - -void PeerRMAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerPublicAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerHTAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerQOSAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void RECBATimerTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void ORIBATimerTimeout(struct rt_rtmp_adapter *pAd); - -void SendRefreshBAR(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry); - -void ActHeaderInit(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 *pHdr80211, - u8 *Addr1, u8 *Addr2, u8 *Addr3); - -void BarHeaderInit(struct rt_rtmp_adapter *pAd, - struct rt_frame_bar *pCntlBar, u8 *pDA, u8 *pSA); - -void InsertActField(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, u8 Category, u8 ActCode); - -BOOLEAN CntlEnqueueForRecv(struct rt_rtmp_adapter *pAd, - unsigned long Wcid, - unsigned long MsgLen, struct rt_frame_ba_req *pMsg); - -/* */ -/* Private routines in rtmp_data.c */ -/* */ -BOOLEAN RTMPHandleRxDoneInterrupt(struct rt_rtmp_adapter *pAd); - -BOOLEAN RTMPHandleTxRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd, - INT_SOURCE_CSR_STRUC TxRingBitmap); - -void RTMPHandleMgmtRingDmaDoneInterrupt(struct rt_rtmp_adapter *pAd); - -void RTMPHandleTBTTInterrupt(struct rt_rtmp_adapter *pAd); - -void RTMPHandlePreTBTTInterrupt(struct rt_rtmp_adapter *pAd); - -void RTMPHandleTwakeupInterrupt(struct rt_rtmp_adapter *pAd); - -void RTMPHandleRxCoherentInterrupt(struct rt_rtmp_adapter *pAd); - -BOOLEAN TxFrameIsAggregatible(struct rt_rtmp_adapter *pAd, - u8 *pPrevAddr1, u8 *p8023hdr); - -BOOLEAN PeerIsAggreOn(struct rt_rtmp_adapter *pAd, - unsigned long TxRate, struct rt_mac_table_entry *pMacEntry); - -int Sniff2BytesFromNdisBuffer(char *pFirstBuffer, - u8 DesiredOffset, - u8 *pByte0, u8 *pByte1); - -int STASendPacket(struct rt_rtmp_adapter *pAd, void *pPacket); - -void STASendPackets(void *MiniportAdapterContext, - void **ppPacketArray, u32 NumberOfPackets); - -void RTMPDeQueuePacket(struct rt_rtmp_adapter *pAd, - IN BOOLEAN bIntContext, - u8 QueIdx, u8 Max_Tx_Packets); - -int RTMPHardTransmit(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 QueIdx, unsigned long *pFreeTXDLeft); - -int STAHardTransmit(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, u8 QueIdx); - -void STARxEAPOLFrameIndicate(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID); - -int RTMPFreeTXDRequest(struct rt_rtmp_adapter *pAd, - u8 RingType, - u8 NumberRequired, u8 *FreeNumberIs); - -int MlmeHardTransmit(struct rt_rtmp_adapter *pAd, - u8 QueIdx, void *pPacket); - -int MlmeHardTransmitMgmtRing(struct rt_rtmp_adapter *pAd, - u8 QueIdx, void *pPacket); - -#ifdef RTMP_MAC_PCI -int MlmeHardTransmitTxRing(struct rt_rtmp_adapter *pAd, - u8 QueIdx, void *pPacket); - -int MlmeDataHardTransmit(struct rt_rtmp_adapter *pAd, - u8 QueIdx, void *pPacket); - -void RTMPWriteTxDescriptor(struct rt_rtmp_adapter *pAd, - struct rt_txd *pTxD, IN BOOLEAN bWIV, u8 QSEL); -#endif /* RTMP_MAC_PCI // */ - -u16 RTMPCalcDuration(struct rt_rtmp_adapter *pAd, u8 Rate, unsigned long Size); - -void RTMPWriteTxWI(struct rt_rtmp_adapter *pAd, struct rt_txwi * pTxWI, IN BOOLEAN FRAG, IN BOOLEAN CFACK, IN BOOLEAN InsTimestamp, IN BOOLEAN AMPDU, IN BOOLEAN Ack, IN BOOLEAN NSeq, /* HW new a sequence. */ - u8 BASize, - u8 WCID, - unsigned long Length, - u8 PID, - u8 TID, - u8 TxRate, - u8 Txopmode, - IN BOOLEAN CfAck, IN HTTRANSMIT_SETTING *pTransmit); - -void RTMPWriteTxWI_Data(struct rt_rtmp_adapter *pAd, - struct rt_txwi *pTxWI, struct rt_tx_blk *pTxBlk); - -void RTMPWriteTxWI_Cache(struct rt_rtmp_adapter *pAd, - struct rt_txwi *pTxWI, struct rt_tx_blk *pTxBlk); - -void RTMPSuspendMsduTransmission(struct rt_rtmp_adapter *pAd); - -void RTMPResumeMsduTransmission(struct rt_rtmp_adapter *pAd); - -int MiniportMMRequest(struct rt_rtmp_adapter *pAd, - u8 QueIdx, u8 *pData, u32 Length); - -/*+++mark by shiang, now this function merge to MiniportMMRequest() */ -/*---mark by shiang, now this function merge to MiniportMMRequest() */ - -void RTMPSendNullFrame(struct rt_rtmp_adapter *pAd, - u8 TxRate, IN BOOLEAN bQosNull); - -void RTMPSendDisassociationFrame(struct rt_rtmp_adapter *pAd); - -void RTMPSendRTSFrame(struct rt_rtmp_adapter *pAd, - u8 *pDA, - IN unsigned int NextMpduSize, - u8 TxRate, - u8 RTSRate, - u16 AckDuration, - u8 QueIdx, u8 FrameGap); - -struct rt_queue_header *RTMPCheckTxSwQueue(struct rt_rtmp_adapter *pAd, u8 * QueIdx); - -void RTMPReportMicError(struct rt_rtmp_adapter *pAd, struct rt_cipher_key *pWpaKey); - -void WpaMicFailureReportFrame(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void WpaDisassocApAndBlockAssoc(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, - void *SystemSpecific3); - -void WpaStaPairwiseKeySetting(struct rt_rtmp_adapter *pAd); - -void WpaStaGroupKeySetting(struct rt_rtmp_adapter *pAd); - -int RTMPCloneNdisPacket(struct rt_rtmp_adapter *pAd, - IN BOOLEAN pInsAMSDUHdr, - void *pInPacket, - void **ppOutPacket); - -int RTMPAllocateNdisPacket(struct rt_rtmp_adapter *pAd, - void **pPacket, - u8 *pHeader, - u32 HeaderLen, - u8 *pData, u32 DataLen); - -void RTMPFreeNdisPacket(struct rt_rtmp_adapter *pAd, void *pPacket); - -BOOLEAN RTMPFreeTXDUponTxDmaDone(struct rt_rtmp_adapter *pAd, u8 QueIdx); - -BOOLEAN RTMPCheckDHCPFrame(struct rt_rtmp_adapter *pAd, void *pPacket); - -BOOLEAN RTMPCheckEtherType(struct rt_rtmp_adapter *pAd, void *pPacket); - -/* */ -/* Private routines in rtmp_wep.c */ -/* */ -void RTMPInitWepEngine(struct rt_rtmp_adapter *pAd, - u8 *pKey, - u8 KeyId, u8 KeyLen, u8 *pDest); - -void RTMPEncryptData(struct rt_rtmp_adapter *pAd, - u8 *pSrc, u8 *pDest, u32 Len); - -BOOLEAN RTMPSoftDecryptWEP(struct rt_rtmp_adapter *pAd, - u8 *pData, - unsigned long DataByteCnt, struct rt_cipher_key *pGroupKey); - -void RTMPSetICV(struct rt_rtmp_adapter *pAd, u8 *pDest); - -void ARCFOUR_INIT(struct rt_arcfourcontext *Ctx, u8 *pKey, u32 KeyLen); - -u8 ARCFOUR_BYTE(struct rt_arcfourcontext *Ctx); - -void ARCFOUR_DECRYPT(struct rt_arcfourcontext *Ctx, - u8 *pDest, u8 *pSrc, u32 Len); - -void ARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx, - u8 *pDest, u8 *pSrc, u32 Len); - -void WPAARCFOUR_ENCRYPT(struct rt_arcfourcontext *Ctx, - u8 *pDest, u8 *pSrc, u32 Len); - -u32 RTMP_CALC_FCS32(u32 Fcs, u8 *Cp, int Len); - -/* */ -/* MLME routines */ -/* */ - -/* Asic/RF/BBP related functions */ - -void AsicAdjustTxPower(struct rt_rtmp_adapter *pAd); - -void AsicUpdateProtect(struct rt_rtmp_adapter *pAd, - u16 OperaionMode, - u8 SetMask, - IN BOOLEAN bDisableBGProtect, IN BOOLEAN bNonGFExist); - -void AsicSwitchChannel(struct rt_rtmp_adapter *pAd, - u8 Channel, IN BOOLEAN bScan); - -void AsicLockChannel(struct rt_rtmp_adapter *pAd, u8 Channel); - -void AsicRfTuningExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void AsicResetBBPAgent(struct rt_rtmp_adapter *pAd); - -void AsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd, - u16 TbttNumToNextWakeUp); - -void AsicForceSleep(struct rt_rtmp_adapter *pAd); - -void AsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx); - -void AsicSetBssid(struct rt_rtmp_adapter *pAd, u8 *pBssid); - -void AsicSetMcastWC(struct rt_rtmp_adapter *pAd); - -void AsicDelWcidTab(struct rt_rtmp_adapter *pAd, u8 Wcid); - -void AsicEnableRDG(struct rt_rtmp_adapter *pAd); - -void AsicDisableRDG(struct rt_rtmp_adapter *pAd); - -void AsicDisableSync(struct rt_rtmp_adapter *pAd); - -void AsicEnableBssSync(struct rt_rtmp_adapter *pAd); - -void AsicEnableIbssSync(struct rt_rtmp_adapter *pAd); - -void AsicSetEdcaParm(struct rt_rtmp_adapter *pAd, struct rt_edca_parm *pEdcaParm); - -void AsicSetSlotTime(struct rt_rtmp_adapter *pAd, IN BOOLEAN bUseShortSlotTime); - -void AsicAddSharedKeyEntry(struct rt_rtmp_adapter *pAd, - u8 BssIndex, - u8 KeyIdx, - u8 CipherAlg, - u8 *pKey, u8 *pTxMic, u8 *pRxMic); - -void AsicRemoveSharedKeyEntry(struct rt_rtmp_adapter *pAd, - u8 BssIndex, u8 KeyIdx); - -void AsicUpdateWCIDAttribute(struct rt_rtmp_adapter *pAd, - u16 WCID, - u8 BssIndex, - u8 CipherAlg, - IN BOOLEAN bUsePairewiseKeyTable); - -void AsicUpdateWCIDIVEIV(struct rt_rtmp_adapter *pAd, - u16 WCID, unsigned long uIV, unsigned long uEIV); - -void AsicUpdateRxWCIDTable(struct rt_rtmp_adapter *pAd, - u16 WCID, u8 *pAddr); - -void AsicAddKeyEntry(struct rt_rtmp_adapter *pAd, - u16 WCID, - u8 BssIndex, - u8 KeyIdx, - struct rt_cipher_key *pCipherKey, - IN BOOLEAN bUsePairewiseKeyTable, IN BOOLEAN bTxKey); - -void AsicAddPairwiseKeyEntry(struct rt_rtmp_adapter *pAd, - u8 *pAddr, - u8 WCID, struct rt_cipher_key *pCipherKey); - -void AsicRemovePairwiseKeyEntry(struct rt_rtmp_adapter *pAd, - u8 BssIdx, u8 Wcid); - -BOOLEAN AsicSendCommandToMcu(struct rt_rtmp_adapter *pAd, - u8 Command, - u8 Token, u8 Arg0, u8 Arg1); - -#ifdef RTMP_MAC_PCI -BOOLEAN AsicCheckCommanOk(struct rt_rtmp_adapter *pAd, u8 Command); -#endif /* RTMP_MAC_PCI // */ - -void MacAddrRandomBssid(struct rt_rtmp_adapter *pAd, u8 *pAddr); - -void MgtMacHeaderInit(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 *pHdr80211, - u8 SubType, - u8 ToDs, u8 *pDA, u8 *pBssid); - -void MlmeRadioOff(struct rt_rtmp_adapter *pAd); - -void MlmeRadioOn(struct rt_rtmp_adapter *pAd); - -void BssTableInit(struct rt_bss_table *Tab); - -void BATableInit(struct rt_rtmp_adapter *pAd, struct rt_ba_table *Tab); - -unsigned long BssTableSearch(struct rt_bss_table *Tab, u8 *pBssid, u8 Channel); - -unsigned long BssSsidTableSearch(struct rt_bss_table *Tab, - u8 *pBssid, - u8 *pSsid, u8 SsidLen, u8 Channel); - -unsigned long BssTableSearchWithSSID(struct rt_bss_table *Tab, - u8 *Bssid, - u8 *pSsid, - u8 SsidLen, u8 Channel); - -unsigned long BssSsidTableSearchBySSID(struct rt_bss_table *Tab, - u8 *pSsid, u8 SsidLen); - -void BssTableDeleteEntry(struct rt_bss_table *pTab, - u8 *pBssid, u8 Channel); - -void BATableDeleteORIEntry(struct rt_rtmp_adapter *pAd, - struct rt_ba_ori_entry *pBAORIEntry); - -void BssEntrySet(struct rt_rtmp_adapter *pAd, struct rt_bss_entry *pBss, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * CfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */ - u8 HtCapabilityLen, - u8 AddHtInfoLen, - u8 NewExtChanOffset, - u8 Channel, - char Rssi, - IN LARGE_INTEGER TimeStamp, - u8 CkipFlag, - struct rt_edca_parm *pEdcaParm, - struct rt_qos_capability_parm *pQosCapability, - struct rt_qbss_load_parm *pQbssLoad, - u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE); - -unsigned long BssTableSetEntry(struct rt_rtmp_adapter *pAd, struct rt_bss_table *pTab, u8 *pBssid, char Ssid[], u8 SsidLen, u8 BssType, u16 BeaconPeriod, struct rt_cf_parm * CfParm, u16 AtimWin, u16 CapabilityInfo, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */ - u8 HtCapabilityLen, - u8 AddHtInfoLen, - u8 NewExtChanOffset, - u8 Channel, - char Rssi, - IN LARGE_INTEGER TimeStamp, - u8 CkipFlag, - struct rt_edca_parm *pEdcaParm, - struct rt_qos_capability_parm *pQosCapability, - struct rt_qbss_load_parm *pQbssLoad, - u16 LengthVIE, struct rt_ndis_802_11_variable_ies *pVIE); - -void BATableInsertEntry(struct rt_rtmp_adapter *pAd, - u16 Aid, - u16 TimeOutValue, - u16 StartingSeq, - u8 TID, - u8 BAWinSize, - u8 OriginatorStatus, IN BOOLEAN IsRecipient); - -void BssTableSsidSort(struct rt_rtmp_adapter *pAd, - struct rt_bss_table *OutTab, char Ssid[], u8 SsidLen); - -void BssTableSortByRssi(struct rt_bss_table *OutTab); - -void BssCipherParse(struct rt_bss_entry *pBss); - -int MlmeQueueInit(struct rt_mlme_queue *Queue); - -void MlmeQueueDestroy(struct rt_mlme_queue *Queue); - -BOOLEAN MlmeEnqueue(struct rt_rtmp_adapter *pAd, - unsigned long Machine, - unsigned long MsgType, unsigned long MsgLen, void *Msg); - -BOOLEAN MlmeEnqueueForRecv(struct rt_rtmp_adapter *pAd, - unsigned long Wcid, - unsigned long TimeStampHigh, - unsigned long TimeStampLow, - u8 Rssi0, - u8 Rssi1, - u8 Rssi2, - unsigned long MsgLen, void *Msg, u8 Signal); - -BOOLEAN MlmeDequeue(struct rt_mlme_queue *Queue, struct rt_mlme_queue_elem **Elem); - -void MlmeRestartStateMachine(struct rt_rtmp_adapter *pAd); - -BOOLEAN MlmeQueueEmpty(struct rt_mlme_queue *Queue); - -BOOLEAN MlmeQueueFull(struct rt_mlme_queue *Queue); - -BOOLEAN MsgTypeSubst(struct rt_rtmp_adapter *pAd, - struct rt_frame_802_11 *pFrame, - int *Machine, int *MsgType); - -void StateMachineInit(struct rt_state_machine *Sm, - IN STATE_MACHINE_FUNC Trans[], - unsigned long StNr, - unsigned long MsgNr, - IN STATE_MACHINE_FUNC DefFunc, - unsigned long InitState, unsigned long Base); - -void StateMachineSetAction(struct rt_state_machine *S, - unsigned long St, unsigned long Msg, IN STATE_MACHINE_FUNC F); - -void StateMachinePerformAction(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *S, struct rt_mlme_queue_elem *Elem); - -void Drop(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void AssocStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *Sm, - OUT STATE_MACHINE_FUNC Trans[]); - -void ReassocTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void AssocTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void DisassocTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -/*---------------------------------------------- */ -void MlmeAssocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void MlmeReassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void MlmeDisassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerAssocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerReassocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerDisassocAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void DisassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void AssocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void ReassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void Cls3errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr); - -void InvalidStateWhenAssoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void InvalidStateWhenReassoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void InvalidStateWhenDisassociate(struct rt_rtmp_adapter *pAd, - struct rt_mlme_queue_elem *Elem); - -#ifdef RTMP_MAC_USB -void MlmeCntlConfirm(struct rt_rtmp_adapter *pAd, unsigned long MsgType, u16 Msg); -#endif /* RTMP_MAC_USB // */ - -void ComposePsPoll(struct rt_rtmp_adapter *pAd); - -void ComposeNullFrame(struct rt_rtmp_adapter *pAd); - -void AssocPostProc(struct rt_rtmp_adapter *pAd, - u8 *pAddr2, - u16 CapabilityInfo, - u16 Aid, - u8 SupRate[], - u8 SupRateLen, - u8 ExtRate[], - u8 ExtRateLen, - struct rt_edca_parm *pEdcaParm, - struct rt_ht_capability_ie *pHtCapability, - u8 HtCapabilityLen, struct rt_add_ht_info_ie *pAddHtInfo); - -void AuthStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *sm, OUT STATE_MACHINE_FUNC Trans[]); - -void AuthTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void MlmeAuthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerAuthRspAtSeq2Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerAuthRspAtSeq4Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void AuthTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void Cls2errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr); - -void MlmeDeauthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void InvalidStateWhenAuth(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -/*============================================= */ - -void AuthRspStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *Sm, - IN STATE_MACHINE_FUNC Trans[]); - -void PeerDeauthAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerAuthSimpleRspGenAndSend(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 *pHdr80211, - u16 Alg, - u16 Seq, - u16 Reason, u16 Status); - -/* */ -/* Private routines in dls.c */ -/* */ - -/*======================================== */ - -void SyncStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *Sm, - OUT STATE_MACHINE_FUNC Trans[]); - -void BeaconTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void ScanTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void InvalidStateWhenScan(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void InvalidStateWhenJoin(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void InvalidStateWhenStart(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void EnqueueProbeRequest(struct rt_rtmp_adapter *pAd); - -BOOLEAN ScanRunning(struct rt_rtmp_adapter *pAd); -/*========================================= */ - -void MlmeCntlInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[]); - -void MlmeCntlMachinePerformAction(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *S, - struct rt_mlme_queue_elem *Elem); - -void CntlIdleProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlOidScanProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlOidSsidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlOidRTBssidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlMlmeRoamingProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlWaitDisassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlWaitJoinProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlWaitReassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlWaitStartProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlWaitAuthProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlWaitAuthProc2(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void CntlWaitAssocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType); - -void LinkDown(struct rt_rtmp_adapter *pAd, IN BOOLEAN IsReqFromAP); - -void IterateOnBssTab(struct rt_rtmp_adapter *pAd); - -void IterateOnBssTab2(struct rt_rtmp_adapter *pAd); - -void JoinParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_join_req *JoinReq, unsigned long BssIdx); - -void AssocParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_assoc_req *AssocReq, - u8 *pAddr, - u16 CapabilityInfo, - unsigned long Timeout, u16 ListenIntv); - -void ScanParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_scan_req *ScanReq, - char Ssid[], - u8 SsidLen, u8 BssType, u8 ScanType); - -void DisassocParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_disassoc_req *DisassocReq, - u8 *pAddr, u16 Reason); - -void StartParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_start_req *StartReq, - char Ssid[], u8 SsidLen); - -void AuthParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_auth_req *AuthReq, - u8 *pAddr, u16 Alg); - -void EnqueuePsPoll(struct rt_rtmp_adapter *pAd); - -void EnqueueBeaconFrame(struct rt_rtmp_adapter *pAd); - -void MlmeJoinReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void MlmeScanReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void MlmeStartReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void ScanTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void BeaconTimeoutAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerBeaconAtScanAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerBeaconAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerBeacon(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void PeerProbeReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -void ScanNextChannel(struct rt_rtmp_adapter *pAd); - -unsigned long MakeIbssBeacon(struct rt_rtmp_adapter *pAd); - -BOOLEAN MlmeScanReqSanity(struct rt_rtmp_adapter *pAd, - void *Msg, - unsigned long MsgLen, - u8 *BssType, - char ssid[], - u8 *SsidLen, u8 *ScanType); - -BOOLEAN PeerBeaconAndProbeRspSanity(struct rt_rtmp_adapter *pAd, - void *Msg, - unsigned long MsgLen, - u8 MsgChannel, - u8 *pAddr2, - u8 *pBssid, - char Ssid[], - u8 *pSsidLen, - u8 *pBssType, - u16 *pBeaconPeriod, - u8 *pChannel, - u8 *pNewChannel, - OUT LARGE_INTEGER *pTimestamp, - struct rt_cf_parm *pCfParm, - u16 *pAtimWin, - u16 *pCapabilityInfo, - u8 *pErp, - u8 *pDtimCount, - u8 *pDtimPeriod, - u8 *pBcastFlag, - u8 *pMessageToMe, - u8 SupRate[], - u8 *pSupRateLen, - u8 ExtRate[], - u8 *pExtRateLen, - u8 *pCkipFlag, - u8 *pAironetCellPowerLimit, - struct rt_edca_parm *pEdcaParm, - struct rt_qbss_load_parm *pQbssLoad, - struct rt_qos_capability_parm *pQosCapability, - unsigned long *pRalinkIe, - u8 *pHtCapabilityLen, - u8 *pPreNHtCapabilityLen, - struct rt_ht_capability_ie *pHtCapability, - u8 *AddHtInfoLen, - struct rt_add_ht_info_ie *AddHtInfo, - u8 *NewExtChannel, - u16 *LengthVIE, - struct rt_ndis_802_11_variable_ies *pVIE); - -BOOLEAN PeerAddBAReqActionSanity(struct rt_rtmp_adapter *pAd, - void *pMsg, - unsigned long MsgLen, u8 *pAddr2); - -BOOLEAN PeerAddBARspActionSanity(struct rt_rtmp_adapter *pAd, - void *pMsg, unsigned long MsgLen); - -BOOLEAN PeerDelBAActionSanity(struct rt_rtmp_adapter *pAd, - u8 Wcid, void *pMsg, unsigned long MsgLen); - -BOOLEAN MlmeAssocReqSanity(struct rt_rtmp_adapter *pAd, - void *Msg, - unsigned long MsgLen, - u8 *pApAddr, - u16 *CapabilityInfo, - unsigned long *Timeout, u16 *ListenIntv); - -BOOLEAN MlmeAuthReqSanity(struct rt_rtmp_adapter *pAd, - void *Msg, - unsigned long MsgLen, - u8 *pAddr, - unsigned long *Timeout, u16 *Alg); - -BOOLEAN MlmeStartReqSanity(struct rt_rtmp_adapter *pAd, - void *Msg, - unsigned long MsgLen, - char Ssid[], u8 *Ssidlen); - -BOOLEAN PeerAuthSanity(struct rt_rtmp_adapter *pAd, - void *Msg, - unsigned long MsgLen, - u8 *pAddr, - u16 *Alg, - u16 *Seq, - u16 *Status, char ChlgText[]); - -BOOLEAN PeerAssocRspSanity(struct rt_rtmp_adapter *pAd, void *pMsg, unsigned long MsgLen, u8 *pAddr2, u16 *pCapabilityInfo, u16 *pStatus, u16 *pAid, u8 SupRate[], u8 *pSupRateLen, u8 ExtRate[], u8 *pExtRateLen, struct rt_ht_capability_ie *pHtCapability, struct rt_add_ht_info_ie *pAddHtInfo, /* AP might use this additional ht info IE */ - u8 *pHtCapabilityLen, - u8 *pAddHtInfoLen, - u8 *pNewExtChannelOffset, - struct rt_edca_parm *pEdcaParm, u8 *pCkipFlag); - -BOOLEAN PeerDisassocSanity(struct rt_rtmp_adapter *pAd, - void *Msg, - unsigned long MsgLen, - u8 *pAddr2, u16 *Reason); - -BOOLEAN PeerWpaMessageSanity(struct rt_rtmp_adapter *pAd, - struct rt_eapol_packet *pMsg, - unsigned long MsgLen, - u8 MsgType, struct rt_mac_table_entry *pEntry); - -BOOLEAN PeerDeauthSanity(struct rt_rtmp_adapter *pAd, - void *Msg, - unsigned long MsgLen, - u8 *pAddr2, u16 *Reason); - -BOOLEAN PeerProbeReqSanity(struct rt_rtmp_adapter *pAd, - void *Msg, - unsigned long MsgLen, - u8 *pAddr2, - char Ssid[], u8 *pSsidLen); - -BOOLEAN GetTimBit(char *Ptr, - u16 Aid, - u8 *TimLen, - u8 *BcastFlag, - u8 *DtimCount, - u8 *DtimPeriod, u8 *MessageToMe); - -u8 ChannelSanity(struct rt_rtmp_adapter *pAd, u8 channel); - -NDIS_802_11_NETWORK_TYPE NetworkTypeInUseSanity(struct rt_bss_entry *pBss); - -BOOLEAN MlmeDelBAReqSanity(struct rt_rtmp_adapter *pAd, - void *Msg, unsigned long MsgLen); - -BOOLEAN MlmeAddBAReqSanity(struct rt_rtmp_adapter *pAd, - void *Msg, unsigned long MsgLen, u8 *pAddr2); - -unsigned long MakeOutgoingFrame(u8 *Buffer, unsigned long *Length, ...); - -void LfsrInit(struct rt_rtmp_adapter *pAd, unsigned long Seed); - -u8 RandomByte(struct rt_rtmp_adapter *pAd); - -void AsicUpdateAutoFallBackTable(struct rt_rtmp_adapter *pAd, u8 *pTxRate); - -void MlmePeriodicExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void LinkDownExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void STAMlmePeriodicExec(struct rt_rtmp_adapter *pAd); - -void MlmeAutoScan(struct rt_rtmp_adapter *pAd); - -void MlmeAutoReconnectLastSSID(struct rt_rtmp_adapter *pAd); - -BOOLEAN MlmeValidateSSID(u8 *pSsid, u8 SsidLen); - -void MlmeCheckForRoaming(struct rt_rtmp_adapter *pAd, unsigned long Now32); - -BOOLEAN MlmeCheckForFastRoaming(struct rt_rtmp_adapter *pAd); - -void MlmeDynamicTxRateSwitching(struct rt_rtmp_adapter *pAd); - -void MlmeSetTxRate(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_rtmp_tx_rate_switch * pTxRate); - -void MlmeSelectTxRateTable(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 **ppTable, - u8 *pTableSize, u8 *pInitTxRateIdx); - -void MlmeCalculateChannelQuality(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pMacEntry, unsigned long Now); - -void MlmeCheckPsmChange(struct rt_rtmp_adapter *pAd, unsigned long Now32); - -void MlmeSetPsmBit(struct rt_rtmp_adapter *pAd, u16 psm); - -void MlmeSetTxPreamble(struct rt_rtmp_adapter *pAd, u16 TxPreamble); - -void UpdateBasicRateBitmap(struct rt_rtmp_adapter *pAd); - -void MlmeUpdateTxRates(struct rt_rtmp_adapter *pAd, - IN BOOLEAN bLinkUp, u8 apidx); - -void MlmeUpdateHtTxRates(struct rt_rtmp_adapter *pAd, u8 apidx); - -void RTMPCheckRates(struct rt_rtmp_adapter *pAd, - IN u8 SupRate[], IN u8 *SupRateLen); - -BOOLEAN RTMPCheckChannel(struct rt_rtmp_adapter *pAd, - u8 CentralChannel, u8 Channel); - -BOOLEAN RTMPCheckHt(struct rt_rtmp_adapter *pAd, - u8 Wcid, - struct rt_ht_capability_ie *pHtCapability, - struct rt_add_ht_info_ie *pAddHtInfo); - -void StaQuickResponeForRateUpExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, - void *SystemSpecific3); - -void RTMPUpdateMlmeRate(struct rt_rtmp_adapter *pAd); - -char RTMPMaxRssi(struct rt_rtmp_adapter *pAd, - char Rssi0, char Rssi1, char Rssi2); - -#ifdef RT30xx -void AsicSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant); - -void RTMPFilterCalibration(struct rt_rtmp_adapter *pAd); - -#ifdef RTMP_EFUSE_SUPPORT -/*2008/09/11:KH add to support efuse<-- */ -int set_eFuseGetFreeBlockCount_Proc(struct rt_rtmp_adapter *pAd, char *arg); - -int set_eFusedump_Proc(struct rt_rtmp_adapter *pAd, char *arg); - -void eFusePhysicalReadRegisters(struct rt_rtmp_adapter *pAd, - u16 Offset, - u16 Length, u16 *pData); - -int RtmpEfuseSupportCheck(struct rt_rtmp_adapter *pAd); - -void eFuseGetFreeBlockCount(struct rt_rtmp_adapter *pAd, u32 *EfuseFreeBlock); - -int eFuse_init(struct rt_rtmp_adapter *pAd); -/*2008/09/11:KH add to support efuse--> */ -#endif /* RTMP_EFUSE_SUPPORT // */ - -/* add by johnli, RF power sequence setup */ -void RT30xxLoadRFNormalModeSetup(struct rt_rtmp_adapter *pAd); - -void RT30xxLoadRFSleepModeSetup(struct rt_rtmp_adapter *pAd); - -void RT30xxReverseRFSleepModeSetup(struct rt_rtmp_adapter *pAd); -/* end johnli */ - -#ifdef RT3070 -void NICInitRT3070RFRegisters(struct rt_rtmp_adapter *pAd); -#endif /* RT3070 // */ -#ifdef RT3090 -void NICInitRT3090RFRegisters(struct rt_rtmp_adapter *pAd); -#endif /* RT3090 // */ - -void RT30xxHaltAction(struct rt_rtmp_adapter *pAd); - -void RT30xxSetRxAnt(struct rt_rtmp_adapter *pAd, u8 Ant); -#endif /* RT30xx // */ - -void AsicEvaluateRxAnt(struct rt_rtmp_adapter *pAd); - -void AsicRxAntEvalTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void APSDPeriodicExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -BOOLEAN RTMPCheckEntryEnableAutoRateSwitch(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry); - -u8 RTMPStaFixedTxMode(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry); - -void RTMPUpdateLegacyTxSetting(u8 fixed_tx_mode, struct rt_mac_table_entry *pEntry); - -BOOLEAN RTMPAutoRateSwitchCheck(struct rt_rtmp_adapter *pAd); - -int MlmeInit(struct rt_rtmp_adapter *pAd); - -void MlmeHandler(struct rt_rtmp_adapter *pAd); - -void MlmeHalt(struct rt_rtmp_adapter *pAd); - -void MlmeResetRalinkCounters(struct rt_rtmp_adapter *pAd); - -void BuildChannelList(struct rt_rtmp_adapter *pAd); - -u8 FirstChannel(struct rt_rtmp_adapter *pAd); - -u8 NextChannel(struct rt_rtmp_adapter *pAd, u8 channel); - -void ChangeToCellPowerLimit(struct rt_rtmp_adapter *pAd, - u8 AironetCellPowerLimit); - -/* */ -/* Prototypes of function definition in rtmp_tkip.c */ -/* */ -void RTMPInitTkipEngine(struct rt_rtmp_adapter *pAd, - u8 *pTKey, - u8 KeyId, - u8 *pTA, - u8 *pMICKey, - u8 *pTSC, unsigned long *pIV16, unsigned long *pIV32); - -void RTMPInitMICEngine(struct rt_rtmp_adapter *pAd, - u8 *pKey, - u8 *pDA, - u8 *pSA, u8 UserPriority, u8 *pMICKey); - -BOOLEAN RTMPTkipCompareMICValue(struct rt_rtmp_adapter *pAd, - u8 *pSrc, - u8 *pDA, - u8 *pSA, - u8 *pMICKey, - u8 UserPriority, u32 Len); - -void RTMPCalculateMICValue(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 *pEncap, - struct rt_cipher_key *pKey, u8 apidx); - -void RTMPTkipAppendByte(struct rt_tkip_key_info *pTkip, u8 uChar); - -void RTMPTkipAppend(struct rt_tkip_key_info *pTkip, u8 *pSrc, u32 nBytes); - -void RTMPTkipGetMIC(struct rt_tkip_key_info *pTkip); - -BOOLEAN RTMPSoftDecryptTKIP(struct rt_rtmp_adapter *pAd, - u8 *pData, - unsigned long DataByteCnt, - u8 UserPriority, struct rt_cipher_key *pWpaKey); - -BOOLEAN RTMPSoftDecryptAES(struct rt_rtmp_adapter *pAd, - u8 *pData, - unsigned long DataByteCnt, struct rt_cipher_key *pWpaKey); - -/* */ -/* Prototypes of function definition in cmm_info.c */ -/* */ -int RT_CfgSetCountryRegion(struct rt_rtmp_adapter *pAd, char *arg, int band); - -int RT_CfgSetWirelessMode(struct rt_rtmp_adapter *pAd, char *arg); - -int RT_CfgSetShortSlot(struct rt_rtmp_adapter *pAd, char *arg); - -int RT_CfgSetWepKey(struct rt_rtmp_adapter *pAd, - char *keyString, - struct rt_cipher_key *pSharedKey, int keyIdx); - -int RT_CfgSetWPAPSKKey(struct rt_rtmp_adapter *pAd, - char *keyString, - u8 *pHashStr, - int hashStrLen, u8 *pPMKBuf); - -/* */ -/* Prototypes of function definition in cmm_info.c */ -/* */ -void RTMPWPARemoveAllKeys(struct rt_rtmp_adapter *pAd); - -void RTMPSetPhyMode(struct rt_rtmp_adapter *pAd, unsigned long phymode); - -void RTMPUpdateHTIE(struct rt_ht_capability *pRtHt, - u8 *pMcsSet, - struct rt_ht_capability_ie *pHtCapability, - struct rt_add_ht_info_ie *pAddHtInfo); - -void RTMPAddWcidAttributeEntry(struct rt_rtmp_adapter *pAd, - u8 BssIdx, - u8 KeyIdx, - u8 CipherAlg, struct rt_mac_table_entry *pEntry); - -char *GetEncryptType(char enc); - -char *GetAuthMode(char auth); - -void RTMPSetHT(struct rt_rtmp_adapter *pAd, struct rt_oid_set_ht_phymode *pHTPhyMode); - -void RTMPSetIndividualHT(struct rt_rtmp_adapter *pAd, u8 apidx); - -void RTMPSendWirelessEvent(struct rt_rtmp_adapter *pAd, - u16 Event_flag, - u8 *pAddr, u8 BssIdx, char Rssi); - -char ConvertToRssi(struct rt_rtmp_adapter *pAd, char Rssi, u8 RssiNumber); - -/*=================================== - Function prototype in cmm_wpa.c - =================================== */ -void RTMPToWirelessSta(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 *pHeader802_3, - u32 HdrLen, - u8 *pData, - u32 DataLen, IN BOOLEAN bClearFrame); - -void WpaDerivePTK(struct rt_rtmp_adapter *pAd, - u8 *PMK, - u8 *ANonce, - u8 *AA, - u8 *SNonce, - u8 *SA, u8 *output, u32 len); - -void GenRandom(struct rt_rtmp_adapter *pAd, u8 *macAddr, u8 *random); - -BOOLEAN RTMPCheckWPAframe(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 *pData, - unsigned long DataByteCount, u8 FromWhichBSSID); - -void AES_GTK_KEY_UNWRAP(u8 *key, - u8 *plaintext, - u32 c_len, u8 *ciphertext); - -BOOLEAN RTMPParseEapolKeyData(struct rt_rtmp_adapter *pAd, - u8 *pKeyData, - u8 KeyDataLen, - u8 GroupKeyIndex, - u8 MsgType, - IN BOOLEAN bWPA2, struct rt_mac_table_entry *pEntry); - -void ConstructEapolMsg(struct rt_mac_table_entry *pEntry, - u8 GroupKeyWepStatus, - u8 MsgType, - u8 DefaultKeyIdx, - u8 *KeyNonce, - u8 *TxRSC, - u8 *GTK, - u8 *RSNIE, - u8 RSNIE_Len, struct rt_eapol_packet *pMsg); - -int RTMPSoftDecryptBroadCastData(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, - IN NDIS_802_11_ENCRYPTION_STATUS - GroupCipher, - struct rt_cipher_key *pShard_key); - -void RTMPMakeRSNIE(struct rt_rtmp_adapter *pAd, - u32 AuthMode, u32 WepStatus, u8 apidx); - -/* */ -/* function prototype in ap_wpa.c */ -/* */ -void RTMPGetTxTscFromAsic(struct rt_rtmp_adapter *pAd, - u8 apidx, u8 *pTxTsc); - -void APInstallPairwiseKey(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry); - -u32 APValidateRSNIE(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 *pRsnIe, u8 rsnie_len); - -void HandleCounterMeasure(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry); - -void WPAStart4WayHS(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, unsigned long TimeInterval); - -void WPAStart2WayGroupHS(struct rt_rtmp_adapter *pAd, struct rt_mac_table_entry *pEntry); - -void PeerPairMsg1Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem); - -void PeerPairMsg2Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem); - -void PeerPairMsg3Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem); - -void PeerPairMsg4Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem); - -void PeerGroupMsg1Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_mlme_queue_elem *Elem); - -void PeerGroupMsg2Action(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - void *Msg, u32 MsgLen); - -void WpaDeriveGTK(u8 *PMK, - u8 *GNonce, - u8 *AA, u8 *output, u32 len); - -void AES_GTK_KEY_WRAP(u8 *key, - u8 *plaintext, - u32 p_len, u8 *ciphertext); - -/*typedef void (*TIMER_FUNCTION)(unsigned long); */ - -/* timeout -- ms */ -void RTMP_SetPeriodicTimer(struct timer_list *pTimer, - IN unsigned long timeout); - -void RTMP_OS_Init_Timer(struct rt_rtmp_adapter *pAd, - struct timer_list *pTimer, - IN TIMER_FUNCTION function, void *data); - -void RTMP_OS_Add_Timer(struct timer_list *pTimer, - IN unsigned long timeout); - -void RTMP_OS_Mod_Timer(struct timer_list *pTimer, - IN unsigned long timeout); - -void RTMP_OS_Del_Timer(struct timer_list *pTimer, - OUT BOOLEAN *pCancelled); - -void RTMP_OS_Release_Packet(struct rt_rtmp_adapter *pAd, struct rt_queue_entry *pEntry); - -void RTMPusecDelay(unsigned long usec); - -int os_alloc_mem(struct rt_rtmp_adapter *pAd, - u8 **mem, unsigned long size); - -int os_free_mem(struct rt_rtmp_adapter *pAd, void *mem); - -void RTMP_AllocateSharedMemory(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - dma_addr_t *PhysicalAddress); - -void RTMPFreeTxRxRingMemory(struct rt_rtmp_adapter *pAd); - -int AdapterBlockAllocateMemory(void *handle, void **ppAd); - -void RTMP_AllocateTxDescMemory(struct rt_rtmp_adapter *pAd, - u32 Index, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - dma_addr_t *PhysicalAddress); - -void RTMP_AllocateFirstTxBuffer(struct rt_rtmp_adapter *pAd, - u32 Index, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - dma_addr_t *PhysicalAddress); - -void RTMP_FreeFirstTxBuffer(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void *VirtualAddress, - dma_addr_t PhysicalAddress); - -void RTMP_AllocateMgmtDescMemory(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - dma_addr_t *PhysicalAddress); - -void RTMP_AllocateRxDescMemory(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - dma_addr_t *PhysicalAddress); - -void RTMP_FreeDescMemory(struct rt_rtmp_adapter *pAd, - unsigned long Length, - void *VirtualAddress, - dma_addr_t PhysicalAddress); - -void *RtmpOSNetPktAlloc(struct rt_rtmp_adapter *pAd, IN int size); - -void *RTMP_AllocateRxPacketBuffer(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress, - OUT dma_addr_t *PhysicalAddress); - -void *RTMP_AllocateTxPacketBuffer(struct rt_rtmp_adapter *pAd, - unsigned long Length, - IN BOOLEAN Cached, - void **VirtualAddress); - -void *RTMP_AllocateFragPacketBuffer(struct rt_rtmp_adapter *pAd, - unsigned long Length); - -void RTMP_QueryPacketInfo(void *pPacket, - struct rt_packet_info *pPacketInfo, - u8 **pSrcBufVA, u32 *pSrcBufLen); - -void RTMP_QueryNextPacketInfo(void **ppPacket, - struct rt_packet_info *pPacketInfo, - u8 **pSrcBufVA, u32 *pSrcBufLen); - -BOOLEAN RTMP_FillTxBlkInfo(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk); - -struct rt_rtmp_sg_list *rt_get_sg_list_from_packet(void *pPacket, - struct rt_rtmp_sg_list *sg); - -void announce_802_3_packet(struct rt_rtmp_adapter *pAd, void *pPacket); - -u32 BA_Reorder_AMSDU_Announce(struct rt_rtmp_adapter *pAd, void *pPacket); - -struct net_device *get_netdev_from_bssid(struct rt_rtmp_adapter *pAd, u8 FromWhichBSSID); - -void *duplicate_pkt(struct rt_rtmp_adapter *pAd, - u8 *pHeader802_3, - u32 HdrLen, - u8 *pData, - unsigned long DataSize, u8 FromWhichBSSID); - -void *duplicate_pkt_with_TKIP_MIC(struct rt_rtmp_adapter *pAd, - void *pOldPkt); - -void ba_flush_reordering_timeout_mpdus(struct rt_rtmp_adapter *pAd, - struct rt_ba_rec_entry *pBAEntry, - unsigned long Now32); - -void BAOriSessionSetUp(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 TID, - u16 TimeOut, - unsigned long DelayTime, IN BOOLEAN isForced); - -void BASessionTearDownALL(struct rt_rtmp_adapter *pAd, u8 Wcid); - -BOOLEAN OS_Need_Clone_Packet(void); - -void build_tx_packet(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 *pFrame, unsigned long FrameLen); - -void BAOriSessionTearDown(struct rt_rtmp_adapter *pAd, - u8 Wcid, - u8 TID, - IN BOOLEAN bPassive, IN BOOLEAN bForceSend); - -void BARecSessionTearDown(struct rt_rtmp_adapter *pAd, - u8 Wcid, u8 TID, IN BOOLEAN bPassive); - -BOOLEAN ba_reordering_resource_init(struct rt_rtmp_adapter *pAd, int num); -void ba_reordering_resource_release(struct rt_rtmp_adapter *pAd); - -char *rstrtok(char *s, IN const char *ct); - -/*//////// common ioctl functions ////////// */ -int SetCommonHT(struct rt_rtmp_adapter *pAd); - -int WpaCheckEapCode(struct rt_rtmp_adapter *pAd, - u8 *pFrame, u16 FrameLen, u16 OffSet); - -void WpaSendMicFailureToWpaSupplicant(struct rt_rtmp_adapter *pAd, - IN BOOLEAN bUnicast); - -int wext_notify_event_assoc(struct rt_rtmp_adapter *pAd); - -BOOLEAN STARxDoneInterruptHandle(struct rt_rtmp_adapter *pAd, IN BOOLEAN argc); - -/* AMPDU packet indication */ -void Indicate_AMPDU_Packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID); - -/* AMSDU packet indication */ -void Indicate_AMSDU_Packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID); - -/* Normal legacy Rx packet indication */ -void Indicate_Legacy_Packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID); - -void Indicate_EAPOL_Packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID); - -void update_os_packet_info(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID); - -void wlan_802_11_to_802_3_packet(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, - u8 *pHeader802_3, - u8 FromWhichBSSID); - -/* remove LLC and get 802_3 Header */ -#define RTMP_802_11_REMOVE_LLC_AND_CONVERT_TO_802_3(_pRxBlk, _pHeader802_3) \ -{ \ - u8 *_pRemovedLLCSNAP = NULL, *_pDA, *_pSA; \ - \ - if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_MESH)) { \ - _pDA = _pRxBlk->pHeader->Addr3; \ - _pSA = (u8 *)_pRxBlk->pHeader + sizeof(struct rt_header_802_11); \ - } \ - else {\ - if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_INFRA)) {\ - _pDA = _pRxBlk->pHeader->Addr1; \ - if (RX_BLK_TEST_FLAG(_pRxBlk, fRX_DLS)) \ - _pSA = _pRxBlk->pHeader->Addr2; \ - else \ - _pSA = _pRxBlk->pHeader->Addr3; \ - } \ - else { \ - _pDA = _pRxBlk->pHeader->Addr1; \ - _pSA = _pRxBlk->pHeader->Addr2; \ - } \ - } \ - \ - CONVERT_TO_802_3(_pHeader802_3, _pDA, _pSA, _pRxBlk->pData, \ - _pRxBlk->DataSize, _pRemovedLLCSNAP); \ -} - -void Sta_Announce_or_Forward_802_3_Packet(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 FromWhichBSSID); - -#define ANNOUNCE_OR_FORWARD_802_3_PACKET(_pAd, _pPacket, _FromWhichBSS)\ - Sta_Announce_or_Forward_802_3_Packet(_pAd, _pPacket, _FromWhichBSS); - /*announce_802_3_packet(_pAd, _pPacket); */ - -void *DuplicatePacket(struct rt_rtmp_adapter *pAd, - void *pPacket, u8 FromWhichBSSID); - -void *ClonePacket(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 *pData, unsigned long DataSize); - -/* Normal, AMPDU or AMSDU */ -void CmmRxnonRalinkFrameIndicate(struct rt_rtmp_adapter *pAd, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID); - -void CmmRxRalinkFrameIndicate(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID); - -void Update_Rssi_Sample(struct rt_rtmp_adapter *pAd, - struct rt_rssi_sample *pRssi, struct rt_rxwi * pRxWI); - -void *GetPacketFromRxRing(struct rt_rtmp_adapter *pAd, - OUT PRT28XX_RXD_STRUC pSaveRxD, - OUT BOOLEAN *pbReschedule, - IN u32 *pRxPending); - -void *RTMPDeFragmentDataFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk); - -enum { - DIDmsg_lnxind_wlansniffrm = 0x00000044, - DIDmsg_lnxind_wlansniffrm_hosttime = 0x00010044, - DIDmsg_lnxind_wlansniffrm_mactime = 0x00020044, - DIDmsg_lnxind_wlansniffrm_channel = 0x00030044, - DIDmsg_lnxind_wlansniffrm_rssi = 0x00040044, - DIDmsg_lnxind_wlansniffrm_sq = 0x00050044, - DIDmsg_lnxind_wlansniffrm_signal = 0x00060044, - DIDmsg_lnxind_wlansniffrm_noise = 0x00070044, - DIDmsg_lnxind_wlansniffrm_rate = 0x00080044, - DIDmsg_lnxind_wlansniffrm_istx = 0x00090044, - DIDmsg_lnxind_wlansniffrm_frmlen = 0x000A0044 -}; -enum { - P80211ENUM_msgitem_status_no_value = 0x00 -}; -enum { - P80211ENUM_truth_false = 0x00, - P80211ENUM_truth_true = 0x01 -}; - -/* Definition from madwifi */ -struct rt_p80211item_uint32 { - u32 did; - u16 status; - u16 len; - u32 data; -}; - -struct rt_wlan_ng_prism2_header { - u32 msgcode; - u32 msglen; -#define WLAN_DEVNAMELEN_MAX 16 - u8 devname[WLAN_DEVNAMELEN_MAX]; - struct rt_p80211item_uint32 hosttime; - struct rt_p80211item_uint32 mactime; - struct rt_p80211item_uint32 channel; - struct rt_p80211item_uint32 rssi; - struct rt_p80211item_uint32 sq; - struct rt_p80211item_uint32 signal; - struct rt_p80211item_uint32 noise; - struct rt_p80211item_uint32 rate; - struct rt_p80211item_uint32 istx; - struct rt_p80211item_uint32 frmlen; -}; - -/* The radio capture header precedes the 802.11 header. */ -struct PACKED rt_ieee80211_radiotap_header { - u8 it_version; /* Version 0. Only increases - * for drastic changes, - * introduction of compatible - * new fields does not count. - */ - u8 it_pad; - u16 it_len; /* length of the whole - * header in bytes, including - * it_version, it_pad, - * it_len, and data fields. - */ - u32 it_present; /* A bitmap telling which - * fields are present. Set bit 31 - * (0x80000000) to extend the - * bitmap by another 32 bits. - * Additional extensions are made - * by setting bit 31. - */ -}; - -enum ieee80211_radiotap_type { - IEEE80211_RADIOTAP_TSFT = 0, - IEEE80211_RADIOTAP_FLAGS = 1, - IEEE80211_RADIOTAP_RATE = 2, - IEEE80211_RADIOTAP_CHANNEL = 3, - IEEE80211_RADIOTAP_FHSS = 4, - IEEE80211_RADIOTAP_DBM_ANTSIGNAL = 5, - IEEE80211_RADIOTAP_DBM_ANTNOISE = 6, - IEEE80211_RADIOTAP_LOCK_QUALITY = 7, - IEEE80211_RADIOTAP_TX_ATTENUATION = 8, - IEEE80211_RADIOTAP_DB_TX_ATTENUATION = 9, - IEEE80211_RADIOTAP_DBM_TX_POWER = 10, - IEEE80211_RADIOTAP_ANTENNA = 11, - IEEE80211_RADIOTAP_DB_ANTSIGNAL = 12, - IEEE80211_RADIOTAP_DB_ANTNOISE = 13 -}; - -#define WLAN_RADIOTAP_PRESENT ( \ - (1 << IEEE80211_RADIOTAP_TSFT) | \ - (1 << IEEE80211_RADIOTAP_FLAGS) | \ - (1 << IEEE80211_RADIOTAP_RATE) | \ - 0) - -struct rt_wlan_radiotap_header { - struct rt_ieee80211_radiotap_header wt_ihdr; - long long wt_tsft; - u8 wt_flags; - u8 wt_rate; -}; -/* Definition from madwifi */ - -void send_monitor_packets(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk); - -void RTMPSetDesiredRates(struct rt_rtmp_adapter *pAdapter, long Rates); - -int Set_FixedTxMode_Proc(struct rt_rtmp_adapter *pAd, char *arg); - -BOOLEAN RT28XXChipsetCheck(IN void *_dev_p); - -void RT28XXDMADisable(struct rt_rtmp_adapter *pAd); - -void RT28XXDMAEnable(struct rt_rtmp_adapter *pAd); - -void RT28xx_UpdateBeaconToAsic(struct rt_rtmp_adapter *pAd, - int apidx, - unsigned long BeaconLen, unsigned long UpdatePos); - -int rt28xx_init(struct rt_rtmp_adapter *pAd, - char *pDefaultMac, char *pHostName); - -int RtmpNetTaskInit(struct rt_rtmp_adapter *pAd); - -void RtmpNetTaskExit(struct rt_rtmp_adapter *pAd); - -int RtmpMgmtTaskInit(struct rt_rtmp_adapter *pAd); - -void RtmpMgmtTaskExit(struct rt_rtmp_adapter *pAd); - -void tbtt_tasklet(unsigned long data); - -struct net_device *RtmpPhyNetDevInit(struct rt_rtmp_adapter *pAd, - struct rt_rtmp_os_netdev_op_hook *pNetHook); - -BOOLEAN RtmpPhyNetDevExit(struct rt_rtmp_adapter *pAd, struct net_device *net_dev); - -int RtmpRaDevCtrlInit(struct rt_rtmp_adapter *pAd, IN RTMP_INF_TYPE infType); - -BOOLEAN RtmpRaDevCtrlExit(struct rt_rtmp_adapter *pAd); - -#ifdef RTMP_MAC_PCI -/* */ -/* Function Prototype in cmm_data_pci.c */ -/* */ -u16 RtmpPCI_WriteTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - IN BOOLEAN bIsLast, u16 *FreeNumber); - -u16 RtmpPCI_WriteSingleTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - IN BOOLEAN bIsLast, - u16 *FreeNumber); - -u16 RtmpPCI_WriteMultiTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u8 frameNum, u16 *FreeNumber); - -u16 RtmpPCI_WriteFragTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u8 fragNum, u16 *FreeNumber); - -u16 RtmpPCI_WriteSubTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - IN BOOLEAN bIsLast, u16 *FreeNumber); - -void RtmpPCI_FinalWriteTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u16 totalMPDUSize, - u16 FirstTxIdx); - -void RtmpPCIDataLastTxIdx(struct rt_rtmp_adapter *pAd, - u8 QueIdx, u16 LastTxIdx); - -void RtmpPCIDataKickOut(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, u8 QueIdx); - -int RtmpPCIMgmtKickOut(struct rt_rtmp_adapter *pAd, - u8 QueIdx, - void *pPacket, - u8 *pSrcBufVA, u32 SrcBufLen); - -int RTMPCheckRxError(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 *pHeader, - struct rt_rxwi *pRxWI, IN PRT28XX_RXD_STRUC pRxD); - -BOOLEAN RT28xxPciAsicRadioOff(struct rt_rtmp_adapter *pAd, - u8 Level, u16 TbttNumToNextWakeUp); - -BOOLEAN RT28xxPciAsicRadioOn(struct rt_rtmp_adapter *pAd, u8 Level); - -void RTMPInitPCIeLinkCtrlValue(struct rt_rtmp_adapter *pAd); - -void RTMPFindHostPCIDev(struct rt_rtmp_adapter *pAd); - -void RTMPPCIeLinkCtrlValueRestore(struct rt_rtmp_adapter *pAd, u8 Level); - -void RTMPPCIeLinkCtrlSetting(struct rt_rtmp_adapter *pAd, u16 Max); - -void RTMPrt3xSetPCIePowerLinkCtrl(struct rt_rtmp_adapter *pAd); - -void PsPollWakeExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void RadioOnExec(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3); - -void RT28xxPciStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx); - -void RT28xxPciStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd, - u16 TbttNumToNextWakeUp); - -void RT28xxPciMlmeRadioOn(struct rt_rtmp_adapter *pAd); - -void RT28xxPciMlmeRadioOFF(struct rt_rtmp_adapter *pAd); -#endif /* RTMP_MAC_PCI // */ - -#ifdef RTMP_MAC_USB -/* */ -/* Function Prototype in rtusb_bulk.c */ -/* */ -void RTUSBInitTxDesc(struct rt_rtmp_adapter *pAd, - struct rt_tx_context *pTxContext, - u8 BulkOutPipeId, IN usb_complete_t Func); - -void RTUSBInitHTTxDesc(struct rt_rtmp_adapter *pAd, - struct rt_ht_tx_context *pTxContext, - u8 BulkOutPipeId, - unsigned long BulkOutSize, IN usb_complete_t Func); - -void RTUSBInitRxDesc(struct rt_rtmp_adapter *pAd, struct rt_rx_context *pRxContext); - -void RTUSBCleanUpDataBulkOutQueue(struct rt_rtmp_adapter *pAd); - -void RTUSBCancelPendingBulkOutIRP(struct rt_rtmp_adapter *pAd); - -void RTUSBBulkOutDataPacket(struct rt_rtmp_adapter *pAd, - u8 BulkOutPipeId, u8 Index); - -void RTUSBBulkOutNullFrame(struct rt_rtmp_adapter *pAd); - -void RTUSBBulkOutRTSFrame(struct rt_rtmp_adapter *pAd); - -void RTUSBCancelPendingBulkInIRP(struct rt_rtmp_adapter *pAd); - -void RTUSBCancelPendingIRPs(struct rt_rtmp_adapter *pAd); - -void RTUSBBulkOutMLMEPacket(struct rt_rtmp_adapter *pAd, u8 Index); - -void RTUSBBulkOutPsPoll(struct rt_rtmp_adapter *pAd); - -void RTUSBCleanUpMLMEBulkOutQueue(struct rt_rtmp_adapter *pAd); - -void RTUSBKickBulkOut(struct rt_rtmp_adapter *pAd); - -void RTUSBBulkReceive(struct rt_rtmp_adapter *pAd); - -void DoBulkIn(struct rt_rtmp_adapter *pAd); - -void RTUSBInitRxDesc(struct rt_rtmp_adapter *pAd, struct rt_rx_context *pRxContext); - -void RTUSBBulkRxHandle(IN unsigned long data); - -/* */ -/* Function Prototype in rtusb_io.c */ -/* */ -int RTUSBMultiRead(struct rt_rtmp_adapter *pAd, - u16 Offset, u8 *pData, u16 length); - -int RTUSBMultiWrite(struct rt_rtmp_adapter *pAd, - u16 Offset, const u8 *pData, u16 length); - -int RTUSBMultiWrite_OneByte(struct rt_rtmp_adapter *pAd, - u16 Offset, const u8 *pData); - -int RTUSBReadBBPRegister(struct rt_rtmp_adapter *pAd, - u8 Id, u8 *pValue); - -int RTUSBWriteBBPRegister(struct rt_rtmp_adapter *pAd, - u8 Id, u8 Value); - -int RTUSBWriteRFRegister(struct rt_rtmp_adapter *pAd, u32 Value); - -int RTUSB_VendorRequest(struct rt_rtmp_adapter *pAd, - u32 TransferFlags, - u8 ReservedBits, - u8 Request, - u16 Value, - u16 Index, - void *TransferBuffer, - u32 TransferBufferLength); - -int RTUSBReadEEPROM(struct rt_rtmp_adapter *pAd, - u16 Offset, u8 *pData, u16 length); - -int RTUSBWriteEEPROM(struct rt_rtmp_adapter *pAd, - u16 Offset, u8 *pData, u16 length); - -void RTUSBPutToSleep(struct rt_rtmp_adapter *pAd); - -int RTUSBWakeUp(struct rt_rtmp_adapter *pAd); - -void RTUSBInitializeCmdQ(struct rt_cmdq *cmdq); - -int RTUSBEnqueueCmdFromNdis(struct rt_rtmp_adapter *pAd, - IN NDIS_OID Oid, - IN BOOLEAN SetInformation, - void *pInformationBuffer, - u32 InformationBufferLength); - -int RTUSBEnqueueInternalCmd(struct rt_rtmp_adapter *pAd, - IN NDIS_OID Oid, - void *pInformationBuffer, - u32 InformationBufferLength); - -void RTUSBDequeueCmd(struct rt_cmdq *cmdq, struct rt_cmdqelmt * * pcmdqelmt); - -int RTUSBCmdThread(IN void *Context); - -void RTUSBBssBeaconExit(struct rt_rtmp_adapter *pAd); - -void RTUSBBssBeaconStop(struct rt_rtmp_adapter *pAd); - -void RTUSBBssBeaconStart(struct rt_rtmp_adapter *pAd); - -void RTUSBBssBeaconInit(struct rt_rtmp_adapter *pAd); - -void RTUSBWatchDog(struct rt_rtmp_adapter *pAd); - -int RTUSBWriteMACRegister(struct rt_rtmp_adapter *pAd, - u16 Offset, u32 Value); - -int RTUSBReadMACRegister(struct rt_rtmp_adapter *pAd, - u16 Offset, u32 *pValue); - -int RTUSBSingleWrite(struct rt_rtmp_adapter *pAd, - u16 Offset, u16 Value); - -int RTUSBFirmwareWrite(struct rt_rtmp_adapter *pAd, - const u8 *pFwImage, unsigned long FwLen); - -int RTUSBVenderReset(struct rt_rtmp_adapter *pAd); - -int RTUSBSetHardWareRegister(struct rt_rtmp_adapter *pAdapter, void *pBuf); - -int RTUSBQueryHardWareRegister(struct rt_rtmp_adapter *pAdapter, - void *pBuf); - -void CMDHandler(struct rt_rtmp_adapter *pAd); - -int RTUSBWriteHWMACAddress(struct rt_rtmp_adapter *pAdapter); - -void MacTableInitialize(struct rt_rtmp_adapter *pAd); - -void MlmeSetPsm(struct rt_rtmp_adapter *pAd, u16 psm); - -int RTMPWPAAddKeyProc(struct rt_rtmp_adapter *pAd, void *pBuf); - -void AsicRxAntEvalAction(struct rt_rtmp_adapter *pAd); - -void append_pkt(struct rt_rtmp_adapter *pAd, - u8 *pHeader802_3, - u32 HdrLen, - u8 *pData, - unsigned long DataSize, void **ppPacket); - -u32 deaggregate_AMSDU_announce(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 *pData, unsigned long DataSize); - -int RTMPCheckRxError(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 *pHeader, - struct rt_rxwi *pRxWI, - IN PRT28XX_RXD_STRUC pRxINFO); - -void RTUSBMlmeHardTransmit(struct rt_rtmp_adapter *pAd, struct rt_mgmt *pMgmt); - -int MlmeThread(void *Context); - -/* */ -/* Function Prototype in rtusb_data.c */ -/* */ -int RTUSBFreeDescriptorRequest(struct rt_rtmp_adapter *pAd, - u8 BulkOutPipeId, - u32 NumberRequired); - -BOOLEAN RTUSBNeedQueueBackForAgg(struct rt_rtmp_adapter *pAd, u8 BulkOutPipeId); - -void RTMPWriteTxInfo(struct rt_rtmp_adapter *pAd, - struct rt_txinfo *pTxInfo, - u16 USBDMApktLen, - IN BOOLEAN bWiv, - u8 QueueSel, u8 NextValid, u8 TxBurst); - -/* */ -/* Function Prototype in cmm_data_usb.c */ -/* */ -u16 RtmpUSB_WriteSubTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - IN BOOLEAN bIsLast, u16 *FreeNumber); - -u16 RtmpUSB_WriteSingleTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - IN BOOLEAN bIsLast, - u16 *FreeNumber); - -u16 RtmpUSB_WriteFragTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u8 fragNum, u16 *FreeNumber); - -u16 RtmpUSB_WriteMultiTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u8 frameNum, u16 *FreeNumber); - -void RtmpUSB_FinalWriteTxResource(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, - u16 totalMPDUSize, u16 TxIdx); - -void RtmpUSBDataLastTxIdx(struct rt_rtmp_adapter *pAd, - u8 QueIdx, u16 TxIdx); - -void RtmpUSBDataKickOut(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, u8 QueIdx); - -int RtmpUSBMgmtKickOut(struct rt_rtmp_adapter *pAd, - u8 QueIdx, - void *pPacket, - u8 *pSrcBufVA, u32 SrcBufLen); - -void RtmpUSBNullFrameKickOut(struct rt_rtmp_adapter *pAd, - u8 QueIdx, - u8 *pNullFrame, u32 frameLen); - -void RtmpUsbStaAsicForceWakeupTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, - void *SystemSpecific3); - -void RT28xxUsbStaAsicForceWakeup(struct rt_rtmp_adapter *pAd, IN BOOLEAN bFromTx); - -void RT28xxUsbStaAsicSleepThenAutoWakeup(struct rt_rtmp_adapter *pAd, - u16 TbttNumToNextWakeUp); - -void RT28xxUsbMlmeRadioOn(struct rt_rtmp_adapter *pAd); - -void RT28xxUsbMlmeRadioOFF(struct rt_rtmp_adapter *pAd); -#endif /* RTMP_MAC_USB // */ - -void AsicTurnOffRFClk(struct rt_rtmp_adapter *pAd, u8 Channel); - -void AsicTurnOnRFClk(struct rt_rtmp_adapter *pAd, u8 Channel); - -#ifdef RTMP_TIMER_TASK_SUPPORT -int RtmpTimerQThread(IN void *Context); - -struct rt_rtmp_timer_task_entry *RtmpTimerQInsert(struct rt_rtmp_adapter *pAd, - struct rt_ralink_timer *pTimer); - -BOOLEAN RtmpTimerQRemove(struct rt_rtmp_adapter *pAd, - struct rt_ralink_timer *pTimer); - -void RtmpTimerQExit(struct rt_rtmp_adapter *pAd); - -void RtmpTimerQInit(struct rt_rtmp_adapter *pAd); -#endif /* RTMP_TIMER_TASK_SUPPORT // */ - -void AsicStaBbpTuning(struct rt_rtmp_adapter *pAd); - -BOOLEAN StaAddMacTableEntry(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 MaxSupportedRateIn500Kbps, - struct rt_ht_capability_ie *pHtCapability, - u8 HtCapabilityLen, - struct rt_add_ht_info_ie *pAddHtInfo, - u8 AddHtInfoLen, u16 CapabilityInfo); - -BOOLEAN AUTH_ReqSend(struct rt_rtmp_adapter *pAd, - struct rt_mlme_queue_elem *pElem, - struct rt_ralink_timer *pAuthTimer, - char *pSMName, - u16 SeqNo, - u8 *pNewElement, unsigned long ElementLen); - -void RTMP_IndicateMediaState(struct rt_rtmp_adapter *pAd); - -void ReSyncBeaconTime(struct rt_rtmp_adapter *pAd); - -void RTMPSetAGCInitValue(struct rt_rtmp_adapter *pAd, u8 BandWidth); - -int rt28xx_close(struct net_device *dev); -int rt28xx_open(struct net_device *dev); - -#define VIRTUAL_IF_INC(__pAd) ((__pAd)->VirtualIfCnt++) -#define VIRTUAL_IF_DEC(__pAd) ((__pAd)->VirtualIfCnt--) -#define VIRTUAL_IF_NUM(__pAd) ((__pAd)->VirtualIfCnt) - -#ifdef LINUX -__inline int VIRTUAL_IF_UP(struct rt_rtmp_adapter *pAd) -{ - if (VIRTUAL_IF_NUM(pAd) == 0) { - if (rt28xx_open(pAd->net_dev) != 0) { - DBGPRINT(RT_DEBUG_TRACE, - ("rt28xx_open return fail!\n")); - return -1; - } - } else { - } - VIRTUAL_IF_INC(pAd); - return 0; -} - -__inline void VIRTUAL_IF_DOWN(struct rt_rtmp_adapter *pAd) -{ - VIRTUAL_IF_DEC(pAd); - if (VIRTUAL_IF_NUM(pAd) == 0) - rt28xx_close(pAd->net_dev); - return; -} -#endif /* LINUX // */ - -/* - OS Related funciton prototype definitions. - TODO: Maybe we need to move these function prototypes to other proper place. -*/ -int RtmpOSWrielessEventSend(struct rt_rtmp_adapter *pAd, - u32 eventType, - int flags, - u8 *pSrcMac, - u8 *pData, u32 dataLen); - -int RtmpOSNetDevAddrSet(struct net_device *pNetDev, u8 *pMacAddr); - -int RtmpOSNetDevAttach(struct net_device *pNetDev, - struct rt_rtmp_os_netdev_op_hook *pDevOpHook); - -void RtmpOSNetDevClose(struct net_device *pNetDev); - -void RtmpOSNetDevDetach(struct net_device *pNetDev); - -int RtmpOSNetDevAlloc(struct net_device **pNewNetDev, u32 privDataSize); - -void RtmpOSNetDevFree(struct net_device *pNetDev); - -struct net_device *RtmpOSNetDevGetByName(struct net_device *pNetDev, char *pDevName); - -void RtmpOSNetDeviceRefPut(struct net_device *pNetDev); - -struct net_device *RtmpOSNetDevCreate(struct rt_rtmp_adapter *pAd, - int devType, - int devNum, - int privMemSize, char *pNamePrefix); - -/* - Task operation related function prototypes -*/ -void RtmpOSTaskCustomize(struct rt_rtmp_os_task *pTask); - -int RtmpOSTaskNotifyToExit(struct rt_rtmp_os_task *pTask); - -int RtmpOSTaskKill(struct rt_rtmp_os_task *pTask); - -int RtmpOSTaskInit(struct rt_rtmp_os_task *pTask, - char *pTaskName, void * pPriv); - -int RtmpOSTaskAttach(struct rt_rtmp_os_task *pTask, - IN int (*fn) (void *), IN void *arg); - -/* - File operation related function prototypes -*/ -struct file *RtmpOSFileOpen(IN char *pPath, IN int flag, IN int mode); - -int RtmpOSFileClose(struct file *osfd); - -void RtmpOSFileSeek(struct file *osfd, IN int offset); - -int RtmpOSFileRead(struct file *osfd, IN char *pDataPtr, IN int readLen); - -int RtmpOSFileWrite(struct file *osfd, IN char *pDataPtr, IN int writeLen); - -#endif /* __RTMP_H__ */ diff --git a/trunk/drivers/staging/rt2860/rtmp_chip.h b/trunk/drivers/staging/rt2860/rtmp_chip.h deleted file mode 100644 index 0adf2cd2deb7..000000000000 --- a/trunk/drivers/staging/rt2860/rtmp_chip.h +++ /dev/null @@ -1,258 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_chip.h - - Abstract: - Ralink Wireless Chip related definition & structures - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ - -#ifndef __RTMP_CHIP_H__ -#define __RTMP_CHIP_H__ - -#include "rtmp_type.h" - -#ifdef RT2860 -#include "chip/rt2860.h" -#endif /* RT2860 // */ -#ifdef RT2870 -#include "chip/rt2870.h" -#endif /* RT2870 // */ -#ifdef RT3070 -#include "chip/rt3070.h" -#endif /* RT3070 // */ -#ifdef RT3090 -#include "chip/rt3090.h" -#endif /* RT3090 // */ - -/* We will have a cost down version which mac version is 0x3090xxxx */ -/* */ -/* RT3090A facts */ -/* */ -/* a) 2.4 GHz */ -/* b) Replacement for RT3090 */ -/* c) Internal LNA */ -/* d) Interference over channel #14 */ -/* e) New BBP features (e.g., SIG re-modulation) */ -/* */ -#define IS_RT3090A(_pAd) ((((_pAd)->MACVersion & 0xffff0000) == 0x30900000)) - -/* We will have a cost down version which mac version is 0x3090xxxx */ -#define IS_RT3090(_pAd) ((((_pAd)->MACVersion & 0xffff0000) == 0x30710000) || (IS_RT3090A(_pAd))) - -#define IS_RT3070(_pAd) (((_pAd)->MACVersion & 0xffff0000) == 0x30700000) -#define IS_RT3071(_pAd) (((_pAd)->MACVersion & 0xffff0000) == 0x30710000) -#define IS_RT2070(_pAd) (((_pAd)->RfIcType == RFIC_2020) || ((_pAd)->EFuseTag == 0x27)) - -#define IS_RT30xx(_pAd) (((_pAd)->MACVersion & 0xfff00000) == 0x30700000||IS_RT3090A(_pAd)) -/*#define IS_RT305X(_pAd) ((_pAd)->MACVersion == 0x28720200) */ - -/* RT3572, 3592, 3562, 3062 share the same MAC version */ -#define IS_RT3572(_pAd) (((_pAd)->MACVersion & 0xffff0000) == 0x35720000) -#define IS_VERSION_BEFORE_F(_pAd) (((_pAd)->MACVersion&0xffff) <= 0x0211) -/* F version is 0x0212, E version is 0x0211. 309x can save more power after F version. */ -#define IS_VERSION_AFTER_F(_pAd) ((((_pAd)->MACVersion&0xffff) >= 0x0212) || (((_pAd)->b3090ESpecialChip == TRUE))) -/* */ -/* RT3390 facts */ -/* */ -/* a) Base on RT3090 (RF IC: RT3020) */ -/* b) 2.4 GHz */ -/* c) 1x1 */ -/* d) Single chip */ -/* e) Internal components: PA and LNA */ -/* */ -/*RT3390,RT3370 */ -#define IS_RT3390(_pAd) (((_pAd)->MACVersion & 0xFFFF0000) == 0x33900000) - -/* ------------------------------------------------------ */ -/* PCI registers - base address 0x0000 */ -/* ------------------------------------------------------ */ -#define CHIP_PCI_CFG 0x0000 -#define CHIP_PCI_EECTRL 0x0004 -#define CHIP_PCI_MCUCTRL 0x0008 - -#define OPT_14 0x114 - -#define RETRY_LIMIT 10 - -/* ------------------------------------------------------ */ -/* BBP & RF definition */ -/* ------------------------------------------------------ */ -#define BUSY 1 -#define IDLE 0 - -/*------------------------------------------------------------------------- */ -/* EEPROM definition */ -/*------------------------------------------------------------------------- */ -#define EEDO 0x08 -#define EEDI 0x04 -#define EECS 0x02 -#define EESK 0x01 -#define EERL 0x80 - -#define EEPROM_WRITE_OPCODE 0x05 -#define EEPROM_READ_OPCODE 0x06 -#define EEPROM_EWDS_OPCODE 0x10 -#define EEPROM_EWEN_OPCODE 0x13 - -#define NUM_EEPROM_BBP_PARMS 19 /* Include NIC Config 0, 1, CR, TX ALC step, BBPs */ -#define NUM_EEPROM_TX_G_PARMS 7 -#define EEPROM_NIC1_OFFSET 0x34 /* The address is from NIC config 0, not BBP register ID */ -#define EEPROM_NIC2_OFFSET 0x36 /* The address is from NIC config 0, not BBP register ID */ -#define EEPROM_BBP_BASE_OFFSET 0xf0 /* The address is from NIC config 0, not BBP register ID */ -#define EEPROM_G_TX_PWR_OFFSET 0x52 -#define EEPROM_G_TX2_PWR_OFFSET 0x60 -#define EEPROM_LED1_OFFSET 0x3c -#define EEPROM_LED2_OFFSET 0x3e -#define EEPROM_LED3_OFFSET 0x40 -#define EEPROM_LNA_OFFSET 0x44 -#define EEPROM_RSSI_BG_OFFSET 0x46 -#define EEPROM_TXMIXER_GAIN_2_4G 0x48 -#define EEPROM_RSSI_A_OFFSET 0x4a -#define EEPROM_TXMIXER_GAIN_5G 0x4c -#define EEPROM_DEFINE_MAX_TXPWR 0x4e -#define EEPROM_TXPOWER_BYRATE_20MHZ_2_4G 0xde /* 20MHZ 2.4G tx power. */ -#define EEPROM_TXPOWER_BYRATE_40MHZ_2_4G 0xee /* 40MHZ 2.4G tx power. */ -#define EEPROM_TXPOWER_BYRATE_20MHZ_5G 0xfa /* 20MHZ 5G tx power. */ -#define EEPROM_TXPOWER_BYRATE_40MHZ_5G 0x10a /* 40MHZ 5G tx power. */ -#define EEPROM_A_TX_PWR_OFFSET 0x78 -#define EEPROM_A_TX2_PWR_OFFSET 0xa6 -/*#define EEPROM_Japan_TX_PWR_OFFSET 0x90 // 802.11j */ -/*#define EEPROM_Japan_TX2_PWR_OFFSET 0xbe */ -/*#define EEPROM_TSSI_REF_OFFSET 0x54 */ -/*#define EEPROM_TSSI_DELTA_OFFSET 0x24 */ -/*#define EEPROM_CCK_TX_PWR_OFFSET 0x62 */ -/*#define EEPROM_CALIBRATE_OFFSET 0x7c */ -#define EEPROM_VERSION_OFFSET 0x02 -#define EEPROM_FREQ_OFFSET 0x3a -#define EEPROM_TXPOWER_BYRATE 0xde /* 20MHZ power. */ -#define EEPROM_TXPOWER_DELTA 0x50 /* 20MHZ AND 40 MHZ use different power. This is delta in 40MHZ. */ -#define VALID_EEPROM_VERSION 1 - -/* - * EEPROM operation related marcos - */ -#define RT28xx_EEPROM_READ16(_pAd, _offset, _value) \ - (_pAd)->chipOps.eeread((struct rt_rtmp_adapter *)(_pAd), (u16)(_offset), (u16 *)&(_value)) - -/* ------------------------------------------------------------------- */ -/* E2PROM data layout */ -/* ------------------------------------------------------------------- */ - -/* */ -/* MCU_LEDCS: MCU LED Control Setting. */ -/* */ -typedef union _MCU_LEDCS_STRUC { - struct { - u8 LedMode:7; - u8 Polarity:1; - } field; - u8 word; -} MCU_LEDCS_STRUC, *PMCU_LEDCS_STRUC; - -/* */ -/* EEPROM antenna select format */ -/* */ -typedef union _EEPROM_ANTENNA_STRUC { - struct { - u16 RxPath:4; /* 1: 1R, 2: 2R, 3: 3R */ - u16 TxPath:4; /* 1: 1T, 2: 2T */ - u16 RfIcType:4; /* see E2PROM document */ - u16 Rsv:4; - } field; - u16 word; -} EEPROM_ANTENNA_STRUC, *PEEPROM_ANTENNA_STRUC; - -typedef union _EEPROM_NIC_CINFIG2_STRUC { - struct { - u16 HardwareRadioControl:1; /* 1:enable, 0:disable */ - u16 DynamicTxAgcControl:1; /* */ - u16 ExternalLNAForG:1; /* */ - u16 ExternalLNAForA:1; /* external LNA enable for 2.4G */ - u16 CardbusAcceleration:1; /* ! NOTE: 0 - enable, 1 - disable */ - u16 BW40MSidebandForG:1; - u16 BW40MSidebandForA:1; - u16 EnableWPSPBC:1; /* WPS PBC Control bit */ - u16 BW40MAvailForG:1; /* 0:enable, 1:disable */ - u16 BW40MAvailForA:1; /* 0:enable, 1:disable */ - u16 Rsv1:1; /* must be 0 */ - u16 AntDiversity:1; /* Antenna diversity */ - u16 Rsv2:3; /* must be 0 */ - u16 DACTestBit:1; /* control if driver should patch the DAC issue */ - } field; - u16 word; -} EEPROM_NIC_CONFIG2_STRUC, *PEEPROM_NIC_CONFIG2_STRUC; - -/* */ -/* TX_PWR Value valid range 0xFA(-6) ~ 0x24(36) */ -/* */ -typedef union _EEPROM_TX_PWR_STRUC { - struct { - char Byte0; /* Low Byte */ - char Byte1; /* High Byte */ - } field; - u16 word; -} EEPROM_TX_PWR_STRUC, *PEEPROM_TX_PWR_STRUC; - -typedef union _EEPROM_VERSION_STRUC { - struct { - u8 FaeReleaseNumber; /* Low Byte */ - u8 Version; /* High Byte */ - } field; - u16 word; -} EEPROM_VERSION_STRUC, *PEEPROM_VERSION_STRUC; - -typedef union _EEPROM_LED_STRUC { - struct { - u16 PolarityRDY_G:1; /* Polarity RDY_G setting. */ - u16 PolarityRDY_A:1; /* Polarity RDY_A setting. */ - u16 PolarityACT:1; /* Polarity ACT setting. */ - u16 PolarityGPIO_0:1; /* Polarity GPIO#0 setting. */ - u16 PolarityGPIO_1:1; /* Polarity GPIO#1 setting. */ - u16 PolarityGPIO_2:1; /* Polarity GPIO#2 setting. */ - u16 PolarityGPIO_3:1; /* Polarity GPIO#3 setting. */ - u16 PolarityGPIO_4:1; /* Polarity GPIO#4 setting. */ - u16 LedMode:5; /* Led mode. */ - u16 Rsvd:3; /* Reserved */ - } field; - u16 word; -} EEPROM_LED_STRUC, *PEEPROM_LED_STRUC; - -typedef union _EEPROM_TXPOWER_DELTA_STRUC { - struct { - u8 DeltaValue:6; /* Tx Power dalta value (MAX=4) */ - u8 Type:1; /* 1: plus the delta value, 0: minus the delta value */ - u8 TxPowerEnable:1; /* Enable */ - } field; - u8 value; -} EEPROM_TXPOWER_DELTA_STRUC, *PEEPROM_TXPOWER_DELTA_STRUC; - -#endif /* __RTMP_CHIP_H__ // */ diff --git a/trunk/drivers/staging/rt2860/rtmp_ckipmic.h b/trunk/drivers/staging/rt2860/rtmp_ckipmic.h deleted file mode 100644 index 6ff935dd3dd1..000000000000 --- a/trunk/drivers/staging/rt2860/rtmp_ckipmic.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_ckipmic.h - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs -*/ -#ifndef __RTMP_CKIPMIC_H__ -#define __RTMP_CKIPMIC_H__ - -struct rt_mic_context { - /* --- MMH context */ - u8 CK[16]; /* the key */ - u8 coefficient[16]; /* current aes counter mode coefficients */ - unsigned long long accum; /* accumulated mic, reduced to u32 in final() */ - u32 position; /* current position (byte offset) in message */ - u8 part[4]; /* for conversion of message to u32 for mmh */ -}; - -void xor_128(u8 *a, u8 *b, u8 *out); - -u8 RTMPCkipSbox(u8 a); - -void xor_32(u8 *a, u8 *b, u8 *out); - -void next_key(u8 *key, int round); - -void byte_sub(u8 *in, u8 *out); - -void shift_row(u8 *in, u8 *out); - -void mix_column(u8 *in, u8 *out); - -#endif /*__RTMP_CKIPMIC_H__ */ diff --git a/trunk/drivers/staging/rt2860/rtmp_def.h b/trunk/drivers/staging/rt2860/rtmp_def.h deleted file mode 100644 index 6ac617e7c9bb..000000000000 --- a/trunk/drivers/staging/rt2860/rtmp_def.h +++ /dev/null @@ -1,1427 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_def.h - - Abstract: - Miniport related definition header - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Paul Lin 08-01-2002 created - John Chang 08-05-2003 add definition for 11g & other drafts - Justin P. Mattock 11/07/2010 Fix some typos -*/ -#ifndef __RTMP_DEF_H__ -#define __RTMP_DEF_H__ - -#include "oid.h" - -/* */ -/* Debug information verbosity: lower values indicate higher urgency */ -/* */ -#define RT_DEBUG_OFF 0 -#define RT_DEBUG_ERROR 1 -#define RT_DEBUG_WARN 2 -#define RT_DEBUG_TRACE 3 -#define RT_DEBUG_INFO 4 -#define RT_DEBUG_LOUD 5 - -#define NIC_TAG ((unsigned long)'0682') -#define NIC_DBG_char ("**RT28xx**") - -#ifdef RTMP_MAC_USB -#define TX_RING_SIZE 8 /* 1 */ -#define PRIO_RING_SIZE 8 -#define MGMT_RING_SIZE 32 /* PRIO_RING_SIZE */ -#define RX_RING_SIZE 8 -#define MAX_TX_PROCESS 4 -#define LOCAL_TXBUF_SIZE 2048 -#endif /* RTMP_MAC_USB // */ - -/*#define PACKED */ - -#define RALINK_2883_VERSION ((u32)0x28830300) -#define RALINK_2880E_VERSION ((u32)0x28720200) -#define RALINK_3070_VERSION ((u32)0x30700200) - -#define MAX_RX_PKT_LEN 1520 - -/* */ -/* Entry number for each DMA descriptor ring */ -/* */ - -#ifdef RTMP_MAC_PCI -#define TX_RING_SIZE 64 /*64 */ -#define MGMT_RING_SIZE 128 -#define RX_RING_SIZE 128 /*64 */ -#define MAX_TX_PROCESS TX_RING_SIZE /*8 */ -#define MAX_DMA_DONE_PROCESS TX_RING_SIZE -#define MAX_TX_DONE_PROCESS TX_RING_SIZE /*8 */ -#define LOCAL_TXBUF_SIZE 2 -#endif /* RTMP_MAC_PCI // */ - -#define MAX_RX_PROCESS 128 /*64 //32 */ -#define NUM_OF_LOCAL_TXBUF 2 -#define TXD_SIZE 16 -#define TXWI_SIZE 16 -#define RXD_SIZE 16 -#define RXWI_SIZE 16 -/* TXINFO_SIZE + TXWI_SIZE + 802.11 Header Size + AMSDU sub frame header */ -#define TX_DMA_1ST_BUFFER_SIZE 96 /* only the 1st physical buffer is pre-allocated */ -#define MGMT_DMA_BUFFER_SIZE 1536 /*2048 */ -#define RX_BUFFER_AGGRESIZE 3840 /*3904 //3968 //4096 //2048 //4096 */ -#define RX_BUFFER_NORMSIZE 3840 /*3904 //3968 //4096 //2048 //4096 */ -#define TX_BUFFER_NORMSIZE RX_BUFFER_NORMSIZE -#define MAX_FRAME_SIZE 2346 /* Maximum 802.11 frame size */ -#define MAX_AGGREGATION_SIZE 3840 /*3904 //3968 //4096 */ -#define MAX_NUM_OF_TUPLE_CACHE 2 -#define MAX_MCAST_LIST_SIZE 32 -#define MAX_LEN_OF_VENDOR_DESC 64 -/*#define MAX_SIZE_OF_MCAST_PSQ (NUM_OF_LOCAL_TXBUF >> 2) // AP won't spend more than 1/4 of total buffers on M/BCAST PSQ */ -#define MAX_SIZE_OF_MCAST_PSQ 32 - -#define MAX_RX_PROCESS_CNT (RX_RING_SIZE) - -/* - WMM Note: If memory of your system is not much, please reduce the definition; - or when you do WMM test, the queue for low priority AC will be full, i.e. - TX_RING_SIZE + MAX_PACKETS_IN_QUEUE packets for the AC will be buffered in - WLAN, maybe no packet buffers can get into the Ethernet driver. - - Sometimes no packet buffer can be get into the Ethernet driver, the system will - send flow control packet to the sender to slow down its sending rate. - So no WMM can be seen in the air. -*/ - -/* - Need to use 64 in vxworks for test case WMM A5-T07 - Two dnlink (10Mbps) from a WMM station to a non-WMM station. - If use 256, queue is not enough. - And in rt_main_end.c, clConfig.clNum = RX_RING_SIZE * 3; is changed to - clConfig.clNum = RX_RING_SIZE * 4; -*/ -/* TODO: For VxWorks the size is 256. Shall we change the value as 256 for all OS? */ -#define MAX_PACKETS_IN_QUEUE (512) /*(512) // to pass WMM A5-WPAPSK */ - -#define MAX_PACKETS_IN_MCAST_PS_QUEUE 32 -#define MAX_PACKETS_IN_PS_QUEUE 128 /*32 */ -#define WMM_NUM_OF_AC 4 /* AC0, AC1, AC2, and AC3 */ - -#ifdef RTMP_EFUSE_SUPPORT -/*2008/09/11:KH add to support efuse<-- */ -#define MAX_EEPROM_BIN_FILE_SIZE 1024 -#define EFUSE_BUFFER_PATH "/tmp/RT30xxEEPROM.bin" -/*2008/09/11:KH add to support efuse--> */ -#endif /* RTMP_EFUSE_SUPPORT // */ - -/* RxFilter */ -#define STANORMAL 0x17f97 -#define APNORMAL 0x15f97 -#define PSPXLINK 0x17f93 -/* */ -/* struct rt_rtmp_adapter flags */ -/* */ -#define fRTMP_ADAPTER_MAP_REGISTER 0x00000001 -#define fRTMP_ADAPTER_INTERRUPT_IN_USE 0x00000002 -#define fRTMP_ADAPTER_HARDWARE_ERROR 0x00000004 -#define fRTMP_ADAPTER_SCATTER_GATHER 0x00000008 -#define fRTMP_ADAPTER_SEND_PACKET_ERROR 0x00000010 -#define fRTMP_ADAPTER_MLME_RESET_IN_PROGRESS 0x00000020 -#define fRTMP_ADAPTER_HALT_IN_PROGRESS 0x00000040 -#define fRTMP_ADAPTER_RESET_IN_PROGRESS 0x00000080 -#define fRTMP_ADAPTER_NIC_NOT_EXIST 0x00000100 -#define fRTMP_ADAPTER_TX_RING_ALLOCATED 0x00000200 -#define fRTMP_ADAPTER_REMOVE_IN_PROGRESS 0x00000400 -#define fRTMP_ADAPTER_MIMORATE_INUSED 0x00000800 -#define fRTMP_ADAPTER_RX_RING_ALLOCATED 0x00001000 -#define fRTMP_ADAPTER_INTERRUPT_ACTIVE 0x00002000 -#define fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS 0x00004000 -#define fRTMP_ADAPTER_REASSOC_IN_PROGRESS 0x00008000 -#define fRTMP_ADAPTER_MEDIA_STATE_PENDING 0x00010000 -#define fRTMP_ADAPTER_RADIO_OFF 0x00020000 -#define fRTMP_ADAPTER_BULKOUT_RESET 0x00040000 -#define fRTMP_ADAPTER_BULKIN_RESET 0x00080000 -#define fRTMP_ADAPTER_RDG_ACTIVE 0x00100000 -#define fRTMP_ADAPTER_DYNAMIC_BE_TXOP_ACTIVE 0x00200000 -#define fRTMP_ADAPTER_SCAN_2040 0x04000000 -#define fRTMP_ADAPTER_RADIO_MEASUREMENT 0x08000000 - -#define fRTMP_ADAPTER_START_UP 0x10000000 /*Device already initialized and enabled Tx/Rx. */ -#define fRTMP_ADAPTER_MEDIA_STATE_CHANGE 0x20000000 -#define fRTMP_ADAPTER_IDLE_RADIO_OFF 0x40000000 - -/* */ -/* STA operation status flags */ -/* */ -#define fOP_STATUS_INFRA_ON 0x00000001 -#define fOP_STATUS_ADHOC_ON 0x00000002 -#define fOP_STATUS_BG_PROTECTION_INUSED 0x00000004 -#define fOP_STATUS_SHORT_SLOT_INUSED 0x00000008 -#define fOP_STATUS_SHORT_PREAMBLE_INUSED 0x00000010 -#define fOP_STATUS_RECEIVE_DTIM 0x00000020 -#define fOP_STATUS_MEDIA_STATE_CONNECTED 0x00000080 -#define fOP_STATUS_WMM_INUSED 0x00000100 -#define fOP_STATUS_AGGREGATION_INUSED 0x00000200 -#define fOP_STATUS_DOZE 0x00000400 /* debug purpose */ -#define fOP_STATUS_PIGGYBACK_INUSED 0x00000800 /* piggy-back, and aggregation */ -#define fOP_STATUS_APSD_INUSED 0x00001000 -#define fOP_STATUS_TX_AMSDU_INUSED 0x00002000 -#define fOP_STATUS_MAX_RETRY_ENABLED 0x00004000 -#define fOP_STATUS_WAKEUP_NOW 0x00008000 -#define fOP_STATUS_PCIE_DEVICE 0x00020000 -#define fOP_STATUS_ADVANCE_POWER_SAVE_PCIE_DEVICE fOP_STATUS_PCIE_DEVICE - -/* */ -/* struct rt_rtmp_adapter PSFlags : related to advanced power save. */ -/* */ -/* Indicate whether driver can go to sleep mode from now. This flag is useful AFTER link up */ -#define fRTMP_PS_CAN_GO_SLEEP 0x00000001 -/* Indicate whether driver has issue a LinkControl command to PCIe L1 */ -#define fRTMP_PS_SET_PCI_CLK_OFF_COMMAND 0x00000002 -/* Indicate driver should disable kick off hardware to send packets from now. */ -#define fRTMP_PS_DISABLE_TX 0x00000004 -/* Indicate driver should IMMEDIATELY go to sleep after receiving AP's beacon in which doesn't indicate unicate nor multicast packets for me */ -/* This flag is used ONLY in RTMPHandleRxDoneInterrupt routine. */ -#define fRTMP_PS_GO_TO_SLEEP_NOW 0x00000008 -#define fRTMP_PS_TOGGLE_L1 0x00000010 /* Use Toggle L1 mechanism for rt28xx PCIe */ - -#ifdef RT3090 -#define WAKE_MCU_CMD 0x31 -#define SLEEP_MCU_CMD 0x30 -#define RFOFF_MCU_CMD 0x35 -#endif /* RT3090 // */ - -#define CCKSETPROTECT 0x1 -#define OFDMSETPROTECT 0x2 -#define MM20SETPROTECT 0x4 -#define MM40SETPROTECT 0x8 -#define GF20SETPROTECT 0x10 -#define GR40SETPROTECT 0x20 -#define ALLN_SETPROTECT (GR40SETPROTECT | GF20SETPROTECT | MM40SETPROTECT | MM20SETPROTECT) - -/* */ -/* AP's client table operation status flags */ -/* */ -#define fCLIENT_STATUS_WMM_CAPABLE 0x00000001 /* CLIENT can parse QOS DATA frame */ -#define fCLIENT_STATUS_AGGREGATION_CAPABLE 0x00000002 /* CLIENT can receive Ralink's proprietary TX aggregation frame */ -#define fCLIENT_STATUS_PIGGYBACK_CAPABLE 0x00000004 /* CLIENT support piggy-back */ -#define fCLIENT_STATUS_AMSDU_INUSED 0x00000008 -#define fCLIENT_STATUS_SGI20_CAPABLE 0x00000010 -#define fCLIENT_STATUS_SGI40_CAPABLE 0x00000020 -#define fCLIENT_STATUS_TxSTBC_CAPABLE 0x00000040 -#define fCLIENT_STATUS_RxSTBC_CAPABLE 0x00000080 -#define fCLIENT_STATUS_HTC_CAPABLE 0x00000100 -#define fCLIENT_STATUS_RDG_CAPABLE 0x00000200 -#define fCLIENT_STATUS_MCSFEEDBACK_CAPABLE 0x00000400 -#define fCLIENT_STATUS_APSD_CAPABLE 0x00000800 /* UAPSD STATION */ - -#define fCLIENT_STATUS_RALINK_CHIPSET 0x00100000 -/* */ -/* STA configuration flags */ -/* */ - -/* 802.11n Operating Mode Definition. 0-3 also used in ASICUPdateProtect switch case */ -#define HT_NO_PROTECT 0 -#define HT_LEGACY_PROTECT 1 -#define HT_40_PROTECT 2 -#define HT_2040_PROTECT 3 -#define HT_RTSCTS_6M 7 -/*following is our own definition in order to turn on our ASIC protection register in INFRASTRUCTURE. */ -#define HT_ATHEROS 8 /* rt2860c has problem with atheros chip. we need to turn on RTS/CTS . */ -#define HT_FORCERTSCTS 9 /* Force turn on RTS/CTS first. then go to evaluate if this force RTS is necessary. */ - -/* */ -/* RX Packet Filter control flags. Apply on pAd->PacketFilter */ -/* */ -#define fRX_FILTER_ACCEPT_DIRECT NDIS_PACKET_TYPE_DIRECTED -#define fRX_FILTER_ACCEPT_MULTICAST NDIS_PACKET_TYPE_MULTICAST -#define fRX_FILTER_ACCEPT_BROADCAST NDIS_PACKET_TYPE_BROADCAST -#define fRX_FILTER_ACCEPT_ALL_MULTICAST NDIS_PACKET_TYPE_ALL_MULTICAST -#define fRX_FILTER_ACCEPT_PROMISCUOUS NDIS_PACKET_TYPE_PROMISCUOUS - -/* */ -/* Error code section */ -/* */ -/* NDIS_ERROR_CODE_ADAPTER_NOT_FOUND */ -#define ERRLOG_READ_PCI_SLOT_FAILED 0x00000101L -#define ERRLOG_WRITE_PCI_SLOT_FAILED 0x00000102L -#define ERRLOG_VENDOR_DEVICE_NOMATCH 0x00000103L - -/* NDIS_ERROR_CODE_ADAPTER_DISABLED */ -#define ERRLOG_BUS_MASTER_DISABLED 0x00000201L - -/* NDIS_ERROR_CODE_UNSUPPORTED_CONFIGURATION */ -#define ERRLOG_INVALID_SPEED_DUPLEX 0x00000301L -#define ERRLOG_SET_SECONDARY_FAILED 0x00000302L - -/* NDIS_ERROR_CODE_OUT_OF_RESOURCES */ -#define ERRLOG_OUT_OF_MEMORY 0x00000401L -#define ERRLOG_OUT_OF_SHARED_MEMORY 0x00000402L -#define ERRLOG_OUT_OF_MAP_REGISTERS 0x00000403L -#define ERRLOG_OUT_OF_BUFFER_POOL 0x00000404L -#define ERRLOG_OUT_OF_NDIS_BUFFER 0x00000405L -#define ERRLOG_OUT_OF_PACKET_POOL 0x00000406L -#define ERRLOG_OUT_OF_NDIS_PACKET 0x00000407L -#define ERRLOG_OUT_OF_LOOKASIDE_MEMORY 0x00000408L - -/* NDIS_ERROR_CODE_HARDWARE_FAILURE */ -#define ERRLOG_SELFTEST_FAILED 0x00000501L -#define ERRLOG_INITIALIZE_ADAPTER 0x00000502L -#define ERRLOG_REMOVE_MINIPORT 0x00000503L - -/* NDIS_ERROR_CODE_RESOURCE_CONFLICT */ -#define ERRLOG_MAP_IO_SPACE 0x00000601L -#define ERRLOG_QUERY_ADAPTER_RESOURCES 0x00000602L -#define ERRLOG_NO_IO_RESOURCE 0x00000603L -#define ERRLOG_NO_INTERRUPT_RESOURCE 0x00000604L -#define ERRLOG_NO_MEMORY_RESOURCE 0x00000605L - -/* WDS definition */ -#define MAX_WDS_ENTRY 4 -#define WDS_PAIRWISE_KEY_OFFSET 60 /* WDS links use pairwise key#60 ~ 63 in ASIC pairwise key table */ - -#define WDS_DISABLE_MODE 0 -#define WDS_RESTRICT_MODE 1 -#define WDS_BRIDGE_MODE 2 -#define WDS_REPEATER_MODE 3 -#define WDS_LAZY_MODE 4 - -#define MAX_MESH_NUM 0 - -#define MAX_APCLI_NUM 0 - -#define MAX_MBSSID_NUM 1 -#ifdef MBSS_SUPPORT -#undef MAX_MBSSID_NUM -#define MAX_MBSSID_NUM (8 - MAX_MESH_NUM - MAX_APCLI_NUM) -#endif /* MBSS_SUPPORT // */ - -/* sanity check for apidx */ -#define MBSS_MR_APIDX_SANITY_CHECK(apidx) \ - { if (apidx > MAX_MBSSID_NUM) { \ - DBGPRINT(RT_DEBUG_ERROR, ("%s> Error! apidx = %d > MAX_MBSSID_NUM!\n", __func__, apidx)); \ - apidx = MAIN_MBSSID; } } - -#define VALID_WCID(_wcid) ((_wcid) > 0 && (_wcid) < MAX_LEN_OF_MAC_TABLE ) - -#define MAIN_MBSSID 0 -#define FIRST_MBSSID 1 - -#define MAX_BEACON_SIZE 512 -/* If the MAX_MBSSID_NUM is larger than 6, */ -/* it shall reserve some WCID space(wcid 222~253) for beacon frames. */ -/* - these wcid 238~253 are reserved for beacon#6(ra6). */ -/* - these wcid 222~237 are reserved for beacon#7(ra7). */ -#if defined(MAX_MBSSID_NUM) && (MAX_MBSSID_NUM == 8) -#define HW_RESERVED_WCID 222 -#elif defined(MAX_MBSSID_NUM) && (MAX_MBSSID_NUM == 7) -#define HW_RESERVED_WCID 238 -#else -#define HW_RESERVED_WCID 255 -#endif - -/* Then dedicate wcid of DFS and Carrier-Sense. */ -#define DFS_CTS_WCID (HW_RESERVED_WCID - 1) -#define CS_CTS_WCID (HW_RESERVED_WCID - 2) -#define LAST_SPECIFIC_WCID (HW_RESERVED_WCID - 2) - -/* If MAX_MBSSID_NUM is 8, the maximum available wcid for the associated STA is 211. */ -/* If MAX_MBSSID_NUM is 7, the maximum available wcid for the associated STA is 228. */ -#define MAX_AVAILABLE_CLIENT_WCID (LAST_SPECIFIC_WCID - MAX_MBSSID_NUM - 1) - -/* TX need WCID to find Cipher Key */ -/* these wcid 212 ~ 219 are reserved for bc/mc packets if MAX_MBSSID_NUM is 8. */ -#define GET_GroupKey_WCID(__wcid, __bssidx) \ - { \ - __wcid = LAST_SPECIFIC_WCID - (MAX_MBSSID_NUM) + __bssidx; \ - } - -#define IsGroupKeyWCID(__wcid) (((__wcid) < LAST_SPECIFIC_WCID) && ((__wcid) >= (LAST_SPECIFIC_WCID - (MAX_MBSSID_NUM)))) - -/* definition to support multiple BSSID */ -#define BSS0 0 -#define BSS1 1 -#define BSS2 2 -#define BSS3 3 -#define BSS4 4 -#define BSS5 5 -#define BSS6 6 -#define BSS7 7 - -/*============================================================ */ -/* Length definitions */ -#define PEER_KEY_NO 2 -#define MAC_ADDR_LEN 6 -#define TIMESTAMP_LEN 8 -#define MAX_LEN_OF_SUPPORTED_RATES MAX_LENGTH_OF_SUPPORT_RATES /* 1, 2, 5.5, 11, 6, 9, 12, 18, 24, 36, 48, 54 */ -#define MAX_LEN_OF_KEY 32 /* 32 octets == 256 bits, Redefine for WPA */ -#define MAX_NUM_OF_CHANNELS MAX_NUM_OF_CHS /* 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL termination */ -#define MAX_NUM_OF_11JCHANNELS 20 /* 14 channels @2.4G + 12@UNII + 4 @MMAC + 11 @HiperLAN2 + 7 @Japan + 1 as NULL termination */ -#define MAX_LEN_OF_SSID 32 -#define CIPHER_TEXT_LEN 128 -#define HASH_TABLE_SIZE 256 -#define MAX_VIE_LEN 1024 /* New for WPA cipher suite variable IE sizes. */ -#define MAX_SUPPORT_MCS 32 -#define MAX_NUM_OF_BBP_LATCH 140 - -/*============================================================ */ -/* ASIC WCID Table definition. */ -/*============================================================ */ -#define BSSID_WCID 1 /* in infra mode, always put bssid with this WCID */ -#define MCAST_WCID 0x0 -#define BSS0Mcast_WCID 0x0 -#define BSS1Mcast_WCID 0xf8 -#define BSS2Mcast_WCID 0xf9 -#define BSS3Mcast_WCID 0xfa -#define BSS4Mcast_WCID 0xfb -#define BSS5Mcast_WCID 0xfc -#define BSS6Mcast_WCID 0xfd -#define BSS7Mcast_WCID 0xfe -#define RESERVED_WCID 0xff - -#define MAX_NUM_OF_ACL_LIST MAX_NUMBER_OF_ACL - -#define MAX_LEN_OF_MAC_TABLE MAX_NUMBER_OF_MAC /* if MAX_MBSSID_NUM is 8, this value can't be larger than 211 */ - -#if MAX_LEN_OF_MAC_TABLE>MAX_AVAILABLE_CLIENT_WCID -#error MAX_LEN_OF_MAC_TABLE can not be larger than MAX_AVAILABLE_CLIENT_WCID! -#endif - -#define MAX_NUM_OF_WDS_LINK_PERBSSID 3 -#define MAX_NUM_OF_WDS_LINK (MAX_NUM_OF_WDS_LINK_PERBSSID*MAX_MBSSID_NUM) -#define MAX_NUM_OF_EVENT MAX_NUMBER_OF_EVENT -#define WDS_LINK_START_WCID (MAX_LEN_OF_MAC_TABLE-1) - -#define NUM_OF_TID 8 -#define MAX_AID_BA 4 -#define MAX_LEN_OF_BA_REC_TABLE ((NUM_OF_TID * MAX_LEN_OF_MAC_TABLE)/2) /* (NUM_OF_TID*MAX_AID_BA + 32) //Block ACK recipient */ -#define MAX_LEN_OF_BA_ORI_TABLE ((NUM_OF_TID * MAX_LEN_OF_MAC_TABLE)/2) /* (NUM_OF_TID*MAX_AID_BA + 32) // Block ACK originator */ -#define MAX_LEN_OF_BSS_TABLE 64 -#define MAX_REORDERING_MPDU_NUM 512 - -/* key related definitions */ -#define SHARE_KEY_NUM 4 -#define MAX_LEN_OF_SHARE_KEY 16 /* byte count */ -#define MAX_LEN_OF_PEER_KEY 16 /* byte count */ -#define PAIRWISE_KEY_NUM 64 /* in MAC ASIC pairwise key table */ -#define GROUP_KEY_NUM 4 -#define PMK_LEN 32 -#define WDS_PAIRWISE_KEY_OFFSET 60 /* WDS links uses pairwise key#60 ~ 63 in ASIC pairwise key table */ -#define PMKID_NO 4 /* Number of PMKID saved supported */ -#define MAX_LEN_OF_MLME_BUFFER 2048 - -/* power status related definitions */ -#define PWR_ACTIVE 0 -#define PWR_SAVE 1 -#define PWR_MMPS 2 /*MIMO power save */ - -/* Auth and Assoc mode related definitions */ -#define AUTH_MODE_OPEN 0x00 -#define AUTH_MODE_KEY 0x01 - -/* BSS Type definitions */ -#define BSS_ADHOC 0 /* = Ndis802_11IBSS */ -#define BSS_INFRA 1 /* = Ndis802_11Infrastructure */ -#define BSS_ANY 2 /* = Ndis802_11AutoUnknown */ -#define BSS_MONITOR 3 /* = Ndis802_11Monitor */ - -/* Reason code definitions */ -#define REASON_RESERVED 0 -#define REASON_UNSPECIFY 1 -#define REASON_NO_longER_VALID 2 -#define REASON_DEAUTH_STA_LEAVING 3 -#define REASON_DISASSOC_INACTIVE 4 -#define REASON_DISASSPC_AP_UNABLE 5 -#define REASON_CLS2ERR 6 -#define REASON_CLS3ERR 7 -#define REASON_DISASSOC_STA_LEAVING 8 -#define REASON_STA_REQ_ASSOC_NOT_AUTH 9 -#define REASON_INVALID_IE 13 -#define REASON_MIC_FAILURE 14 -#define REASON_4_WAY_TIMEOUT 15 -#define REASON_GROUP_KEY_HS_TIMEOUT 16 -#define REASON_IE_DIFFERENT 17 -#define REASON_MCIPHER_NOT_VALID 18 -#define REASON_UCIPHER_NOT_VALID 19 -#define REASON_AKMP_NOT_VALID 20 -#define REASON_UNSUPPORT_RSNE_VER 21 -#define REASON_INVALID_RSNE_CAP 22 -#define REASON_8021X_AUTH_FAIL 23 -#define REASON_CIPHER_SUITE_REJECTED 24 -#define REASON_DECLINED 37 - -#define REASON_QOS_UNSPECIFY 32 -#define REASON_QOS_LACK_BANDWIDTH 33 -#define REASON_POOR_CHANNEL_CONDITION 34 -#define REASON_QOS_OUTSIDE_TXOP_LIMITION 35 -#define REASON_QOS_QSTA_LEAVING_QBSS 36 -#define REASON_QOS_UNWANTED_MECHANISM 37 -#define REASON_QOS_MECH_SETUP_REQUIRED 38 -#define REASON_QOS_REQUEST_TIMEOUT 39 -#define REASON_QOS_CIPHER_NOT_SUPPORT 45 - -/* Status code definitions */ -#define MLME_SUCCESS 0 -#define MLME_UNSPECIFY_FAIL 1 -#define MLME_CANNOT_SUPPORT_CAP 10 -#define MLME_REASSOC_DENY_ASSOC_EXIST 11 -#define MLME_ASSOC_DENY_OUT_SCOPE 12 -#define MLME_ALG_NOT_SUPPORT 13 -#define MLME_SEQ_NR_OUT_OF_SEQUENCE 14 -#define MLME_REJ_CHALLENGE_FAILURE 15 -#define MLME_REJ_TIMEOUT 16 -#define MLME_ASSOC_REJ_UNABLE_HANDLE_STA 17 -#define MLME_ASSOC_REJ_DATA_RATE 18 - -#define MLME_ASSOC_REJ_NO_EXT_RATE 22 -#define MLME_ASSOC_REJ_NO_EXT_RATE_PBCC 23 -#define MLME_ASSOC_REJ_NO_CCK_OFDM 24 - -#define MLME_QOS_UNSPECIFY 32 -#define MLME_REQUEST_DECLINED 37 -#define MLME_REQUEST_WITH_INVALID_PARAM 38 -#define MLME_INVALID_GROUP_CIPHER 41 -#define MLME_INVALID_PAIRWISE_CIPHER 42 -#define MLME_INVALID_AKMP 43 -#define MLME_DLS_NOT_ALLOW_IN_QBSS 48 -#define MLME_DEST_STA_NOT_IN_QBSS 49 -#define MLME_DEST_STA_IS_NOT_A_QSTA 50 - -#define MLME_INVALID_FORMAT 0x51 -#define MLME_FAIL_NO_RESOURCE 0x52 -#define MLME_STATE_MACHINE_REJECT 0x53 -#define MLME_MAC_TABLE_FAIL 0x54 - -/* IE code */ -#define IE_SSID 0 -#define IE_SUPP_RATES 1 -#define IE_FH_PARM 2 -#define IE_DS_PARM 3 -#define IE_CF_PARM 4 -#define IE_TIM 5 -#define IE_IBSS_PARM 6 -#define IE_COUNTRY 7 /* 802.11d */ -#define IE_802_11D_REQUEST 10 /* 802.11d */ -#define IE_QBSS_LOAD 11 /* 802.11e d9 */ -#define IE_EDCA_PARAMETER 12 /* 802.11e d9 */ -#define IE_TSPEC 13 /* 802.11e d9 */ -#define IE_TCLAS 14 /* 802.11e d9 */ -#define IE_SCHEDULE 15 /* 802.11e d9 */ -#define IE_CHALLENGE_TEXT 16 -#define IE_POWER_CONSTRAint 32 /* 802.11h d3.3 */ -#define IE_POWER_CAPABILITY 33 /* 802.11h d3.3 */ -#define IE_TPC_REQUEST 34 /* 802.11h d3.3 */ -#define IE_TPC_REPORT 35 /* 802.11h d3.3 */ -#define IE_SUPP_CHANNELS 36 /* 802.11h d3.3 */ -#define IE_CHANNEL_SWITCH_ANNOUNCEMENT 37 /* 802.11h d3.3 */ -#define IE_MEASUREMENT_REQUEST 38 /* 802.11h d3.3 */ -#define IE_MEASUREMENT_REPORT 39 /* 802.11h d3.3 */ -#define IE_QUIET 40 /* 802.11h d3.3 */ -#define IE_IBSS_DFS 41 /* 802.11h d3.3 */ -#define IE_ERP 42 /* 802.11g */ -#define IE_TS_DELAY 43 /* 802.11e d9 */ -#define IE_TCLAS_PROCESSING 44 /* 802.11e d9 */ -#define IE_QOS_CAPABILITY 46 /* 802.11e d6 */ -#define IE_HT_CAP 45 /* 802.11n d1. HT CAPABILITY. ELEMENT ID TBD */ -#define IE_AP_CHANNEL_REPORT 51 /* 802.11k d6 */ -#define IE_HT_CAP2 52 /* 802.11n d1. HT CAPABILITY. ELEMENT ID TBD */ -#define IE_RSN 48 /* 802.11i d3.0 */ -#define IE_WPA2 48 /* WPA2 */ -#define IE_EXT_SUPP_RATES 50 /* 802.11g */ -#define IE_SUPP_REG_CLASS 59 /* 802.11y. Supported regulatory classes. */ -#define IE_EXT_CHANNEL_SWITCH_ANNOUNCEMENT 60 /* 802.11n */ -#define IE_ADD_HT 61 /* 802.11n d1. ADDITIONAL HT CAPABILITY. ELEMENT ID TBD */ -#define IE_ADD_HT2 53 /* 802.11n d1. ADDITIONAL HT CAPABILITY. ELEMENT ID TBD */ - -/* For 802.11n D3.03 */ -/*#define IE_NEW_EXT_CHA_OFFSET 62 // 802.11n d1. New extension channel offset element */ -#define IE_SECONDARY_CH_OFFSET 62 /* 802.11n D3.03 Secondary Channel Offset element */ -#define IE_WAPI 68 /* WAPI information element */ -#define IE_2040_BSS_COEXIST 72 /* 802.11n D3.0.3 */ -#define IE_2040_BSS_INTOLERANT_REPORT 73 /* 802.11n D3.03 */ -#define IE_OVERLAPBSS_SCAN_PARM 74 /* 802.11n D3.03 */ -#define IE_EXT_CAPABILITY 127 /* 802.11n D3.03 */ - -#define IE_WPA 221 /* WPA */ -#define IE_VENDOR_SPECIFIC 221 /* Wifi WMM (WME) */ - -#define OUI_BROADCOM_HT 51 /* */ -#define OUI_BROADCOM_HTADD 52 /* */ -#define OUI_PREN_HT_CAP 51 /* */ -#define OUI_PREN_ADD_HT 52 /* */ - -/* CCX information */ -#define IE_AIRONET_CKIP 133 /* CCX1.0 ID 85H for CKIP */ -#define IE_AP_TX_POWER 150 /* CCX 2.0 for AP transmit power */ -#define IE_MEASUREMENT_CAPABILITY 221 /* CCX 2.0 */ -#define IE_CCX_V2 221 -#define IE_AIRONET_IPADDRESS 149 /* CCX ID 95H for IP Address */ -#define IE_AIRONET_CCKMREASSOC 156 /* CCX ID 9CH for CCKM Reassociation Request element */ -#define CKIP_NEGOTIATION_LENGTH 30 -#define AIRONET_IPADDRESS_LENGTH 10 -#define AIRONET_CCKMREASSOC_LENGTH 24 - -/* ======================================================== */ -/* MLME state machine definition */ -/* ======================================================== */ - -/* STA MLME state mahcines */ -#define ASSOC_STATE_MACHINE 1 -#define AUTH_STATE_MACHINE 2 -#define AUTH_RSP_STATE_MACHINE 3 -#define SYNC_STATE_MACHINE 4 -#define MLME_CNTL_STATE_MACHINE 5 -#define WPA_PSK_STATE_MACHINE 6 -/*#define LEAP_STATE_MACHINE 7 */ -#define AIRONET_STATE_MACHINE 8 -#define ACTION_STATE_MACHINE 9 - -/* AP MLME state machines */ -#define AP_ASSOC_STATE_MACHINE 11 -#define AP_AUTH_STATE_MACHINE 12 -#define AP_SYNC_STATE_MACHINE 14 -#define AP_CNTL_STATE_MACHINE 15 -#define WSC_STATE_MACHINE 17 -#define WSC_UPNP_STATE_MACHINE 18 - -#define WPA_STATE_MACHINE 23 - -/* */ -/* STA's CONTROL/CONNECT state machine: states, events, total function # */ -/* */ -#define CNTL_IDLE 0 -#define CNTL_WAIT_DISASSOC 1 -#define CNTL_WAIT_JOIN 2 -#define CNTL_WAIT_REASSOC 3 -#define CNTL_WAIT_START 4 -#define CNTL_WAIT_AUTH 5 -#define CNTL_WAIT_ASSOC 6 -#define CNTL_WAIT_AUTH2 7 -#define CNTL_WAIT_OID_LIST_SCAN 8 -#define CNTL_WAIT_OID_DISASSOC 9 -#ifdef RTMP_MAC_USB -#define CNTL_WAIT_SCAN_FOR_CONNECT 10 -#endif /* RTMP_MAC_USB // */ - -#define MT2_ASSOC_CONF 34 -#define MT2_AUTH_CONF 35 -#define MT2_DEAUTH_CONF 36 -#define MT2_DISASSOC_CONF 37 -#define MT2_REASSOC_CONF 38 -#define MT2_PWR_MGMT_CONF 39 -#define MT2_JOIN_CONF 40 -#define MT2_SCAN_CONF 41 -#define MT2_START_CONF 42 -#define MT2_GET_CONF 43 -#define MT2_SET_CONF 44 -#define MT2_RESET_CONF 45 -#define MT2_FT_OTD_CONF 46 -#define MT2_MLME_ROAMING_REQ 52 - -#define CNTL_FUNC_SIZE 1 - -/* */ -/* STA's ASSOC state machine: states, events, total function # */ -/* */ -#define ASSOC_IDLE 0 -#define ASSOC_WAIT_RSP 1 -#define REASSOC_WAIT_RSP 2 -#define DISASSOC_WAIT_RSP 3 -#define MAX_ASSOC_STATE 4 - -#define ASSOC_MACHINE_BASE 0 -#define MT2_MLME_ASSOC_REQ 0 -#define MT2_MLME_REASSOC_REQ 1 -#define MT2_MLME_DISASSOC_REQ 2 -#define MT2_PEER_DISASSOC_REQ 3 -#define MT2_PEER_ASSOC_REQ 4 -#define MT2_PEER_ASSOC_RSP 5 -#define MT2_PEER_REASSOC_REQ 6 -#define MT2_PEER_REASSOC_RSP 7 -#define MT2_DISASSOC_TIMEOUT 8 -#define MT2_ASSOC_TIMEOUT 9 -#define MT2_REASSOC_TIMEOUT 10 -#define MAX_ASSOC_MSG 11 - -#define ASSOC_FUNC_SIZE (MAX_ASSOC_STATE * MAX_ASSOC_MSG) - -/* */ -/* ACT state machine: states, events, total function # */ -/* */ -#define ACT_IDLE 0 -#define MAX_ACT_STATE 1 - -#define ACT_MACHINE_BASE 0 - -/*Those PEER_xx_CATE number is based on real Categary value in IEEE spec. Please do not modify it by your self. */ -/*Category */ -#define MT2_PEER_SPECTRUM_CATE 0 -#define MT2_PEER_QOS_CATE 1 -#define MT2_PEER_DLS_CATE 2 -#define MT2_PEER_BA_CATE 3 -#define MT2_PEER_PUBLIC_CATE 4 -#define MT2_PEER_RM_CATE 5 -/* "FT_CATEGORY_BSS_TRANSITION equal to 6" is defined file of "dot11r_ft.h" */ -#define MT2_PEER_HT_CATE 7 /* 7.4.7 */ -#define MAX_PEER_CATE_MSG 7 - -#define MT2_MLME_ADD_BA_CATE 8 -#define MT2_MLME_ORI_DELBA_CATE 9 -#define MT2_MLME_REC_DELBA_CATE 10 -#define MT2_MLME_QOS_CATE 11 -#define MT2_MLME_DLS_CATE 12 -#define MT2_ACT_INVALID 13 -#define MAX_ACT_MSG 14 - -/*Category field */ -#define CATEGORY_SPECTRUM 0 -#define CATEGORY_QOS 1 -#define CATEGORY_DLS 2 -#define CATEGORY_BA 3 -#define CATEGORY_PUBLIC 4 -#define CATEGORY_RM 5 -#define CATEGORY_HT 7 - -/* DLS Action frame definition */ -#define ACTION_DLS_REQUEST 0 -#define ACTION_DLS_RESPONSE 1 -#define ACTION_DLS_TEARDOWN 2 - -/*Spectrum Action field value 802.11h 7.4.1 */ -#define SPEC_MRQ 0 /* Request */ -#define SPEC_MRP 1 /*Report */ -#define SPEC_TPCRQ 2 -#define SPEC_TPCRP 3 -#define SPEC_CHANNEL_SWITCH 4 - -/*BA Action field value */ -#define ADDBA_REQ 0 -#define ADDBA_RESP 1 -#define DELBA 2 - -/*Public's Action field value in Public Category. Some in 802.11y and some in 11n */ -#define ACTION_BSS_2040_COEXIST 0 /* 11n */ -#define ACTION_DSE_ENABLEMENT 1 /* 11y D9.0 */ -#define ACTION_DSE_DEENABLEMENT 2 /* 11y D9.0 */ -#define ACTION_DSE_REG_LOCATION_ANNOUNCE 3 /* 11y D9.0 */ -#define ACTION_EXT_CH_SWITCH_ANNOUNCE 4 /* 11y D9.0 */ -#define ACTION_DSE_MEASUREMENT_REQ 5 /* 11y D9.0 */ -#define ACTION_DSE_MEASUREMENT_REPORT 6 /* 11y D9.0 */ -#define ACTION_MEASUREMENT_PILOT_ACTION 7 /* 11y D9.0 */ -#define ACTION_DSE_POWER_CONSTRAINT 8 /* 11y D9.0 */ - -/*HT Action field value */ -#define NOTIFY_BW_ACTION 0 -#define SMPS_ACTION 1 -#define PSMP_ACTION 2 -#define SETPCO_ACTION 3 -#define MIMO_CHA_MEASURE_ACTION 4 -#define MIMO_N_BEACONFORM 5 -#define MIMO_BEACONFORM 6 -#define ANTENNA_SELECT 7 -#define HT_INFO_EXCHANGE 8 - -#define ACT_FUNC_SIZE (MAX_ACT_STATE * MAX_ACT_MSG) -/* */ -/* STA's AUTHENTICATION state machine: states, events, total function # */ -/* */ -#define AUTH_REQ_IDLE 0 -#define AUTH_WAIT_SEQ2 1 -#define AUTH_WAIT_SEQ4 2 -#define MAX_AUTH_STATE 3 - -#define AUTH_MACHINE_BASE 0 -#define MT2_MLME_AUTH_REQ 0 -#define MT2_PEER_AUTH_EVEN 1 -#define MT2_AUTH_TIMEOUT 2 -#define MAX_AUTH_MSG 3 - -#define AUTH_FUNC_SIZE (MAX_AUTH_STATE * MAX_AUTH_MSG) - -/* */ -/* STA's AUTH_RSP state machine: states, events, total function # */ -/* */ -#define AUTH_RSP_IDLE 0 -#define AUTH_RSP_WAIT_CHAL 1 -#define MAX_AUTH_RSP_STATE 2 - -#define AUTH_RSP_MACHINE_BASE 0 -#define MT2_AUTH_CHALLENGE_TIMEOUT 0 -#define MT2_PEER_AUTH_ODD 1 -#define MT2_PEER_DEAUTH 2 -#define MAX_AUTH_RSP_MSG 3 - -#define AUTH_RSP_FUNC_SIZE (MAX_AUTH_RSP_STATE * MAX_AUTH_RSP_MSG) - -/* */ -/* STA's SYNC state machine: states, events, total function # */ -/* */ -#define SYNC_IDLE 0 /* merge NO_BSS,IBSS_IDLE,IBSS_ACTIVE and BSS in to 1 state */ -#define JOIN_WAIT_BEACON 1 -#define SCAN_LISTEN 2 -#define MAX_SYNC_STATE 3 - -#define SYNC_MACHINE_BASE 0 -#define MT2_MLME_SCAN_REQ 0 -#define MT2_MLME_JOIN_REQ 1 -#define MT2_MLME_START_REQ 2 -#define MT2_PEER_BEACON 3 -#define MT2_PEER_PROBE_RSP 4 -#define MT2_PEER_ATIM 5 -#define MT2_SCAN_TIMEOUT 6 -#define MT2_BEACON_TIMEOUT 7 -#define MT2_ATIM_TIMEOUT 8 -#define MT2_PEER_PROBE_REQ 9 -#define MAX_SYNC_MSG 10 - -#define SYNC_FUNC_SIZE (MAX_SYNC_STATE * MAX_SYNC_MSG) - -/*Messages for the DLS state machine */ -#define DLS_IDLE 0 -#define MAX_DLS_STATE 1 - -#define DLS_MACHINE_BASE 0 -#define MT2_MLME_DLS_REQ 0 -#define MT2_PEER_DLS_REQ 1 -#define MT2_PEER_DLS_RSP 2 -#define MT2_MLME_DLS_TEAR_DOWN 3 -#define MT2_PEER_DLS_TEAR_DOWN 4 -#define MAX_DLS_MSG 5 - -#define DLS_FUNC_SIZE (MAX_DLS_STATE * MAX_DLS_MSG) - -/* */ -/* WSC State machine: states, events, total function # */ -/* */ - -/* */ -/* AP's CONTROL/CONNECT state machine: states, events, total function # */ -/* */ -#define AP_CNTL_FUNC_SIZE 1 - -/* */ -/* AP's ASSOC state machine: states, events, total function # */ -/* */ -#define AP_ASSOC_IDLE 0 -#define AP_MAX_ASSOC_STATE 1 - -#define AP_ASSOC_MACHINE_BASE 0 -#define APMT2_MLME_DISASSOC_REQ 0 -#define APMT2_PEER_DISASSOC_REQ 1 -#define APMT2_PEER_ASSOC_REQ 2 -#define APMT2_PEER_REASSOC_REQ 3 -#define APMT2_CLS3ERR 4 -#define AP_MAX_ASSOC_MSG 5 - -#define AP_ASSOC_FUNC_SIZE (AP_MAX_ASSOC_STATE * AP_MAX_ASSOC_MSG) - -/* */ -/* AP's AUTHENTICATION state machine: states, events, total function # */ -/* */ -#define AP_AUTH_REQ_IDLE 0 -#define AP_MAX_AUTH_STATE 1 - -#define AP_AUTH_MACHINE_BASE 0 -#define APMT2_MLME_DEAUTH_REQ 0 -#define APMT2_CLS2ERR 1 -#define APMT2_PEER_DEAUTH 2 -#define APMT2_PEER_AUTH_REQ 3 -#define APMT2_PEER_AUTH_CONFIRM 4 -#define AP_MAX_AUTH_MSG 5 - -#define AP_AUTH_FUNC_SIZE (AP_MAX_AUTH_STATE * AP_MAX_AUTH_MSG) - -/* */ -/* AP's SYNC state machine: states, events, total function # */ -/* */ -#define AP_SYNC_IDLE 0 -#define AP_SCAN_LISTEN 1 -#define AP_MAX_SYNC_STATE 2 - -#define AP_SYNC_MACHINE_BASE 0 -#define APMT2_PEER_PROBE_REQ 0 -#define APMT2_PEER_BEACON 1 -#define APMT2_MLME_SCAN_REQ 2 -#define APMT2_PEER_PROBE_RSP 3 -#define APMT2_SCAN_TIMEOUT 4 -#define APMT2_MLME_SCAN_CNCL 5 -#define AP_MAX_SYNC_MSG 6 - -#define AP_SYNC_FUNC_SIZE (AP_MAX_SYNC_STATE * AP_MAX_SYNC_MSG) - -/* */ -/* Common WPA state machine: states, events, total function # */ -/* */ -#define WPA_PTK 0 -#define MAX_WPA_PTK_STATE 1 - -#define WPA_MACHINE_BASE 0 -#define MT2_EAPPacket 0 -#define MT2_EAPOLStart 1 -#define MT2_EAPOLLogoff 2 -#define MT2_EAPOLKey 3 -#define MT2_EAPOLASFAlert 4 -#define MAX_WPA_MSG 5 - -#define WPA_FUNC_SIZE (MAX_WPA_PTK_STATE * MAX_WPA_MSG) - -/* ============================================================================= */ - -/* value domain of 802.11 header FC.Tyte, which is b3..b2 of the 1st-byte of MAC header */ -#define BTYPE_MGMT 0 -#define BTYPE_CNTL 1 -#define BTYPE_DATA 2 - -/* value domain of 802.11 MGMT frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header */ -#define SUBTYPE_ASSOC_REQ 0 -#define SUBTYPE_ASSOC_RSP 1 -#define SUBTYPE_REASSOC_REQ 2 -#define SUBTYPE_REASSOC_RSP 3 -#define SUBTYPE_PROBE_REQ 4 -#define SUBTYPE_PROBE_RSP 5 -#define SUBTYPE_BEACON 8 -#define SUBTYPE_ATIM 9 -#define SUBTYPE_DISASSOC 10 -#define SUBTYPE_AUTH 11 -#define SUBTYPE_DEAUTH 12 -#define SUBTYPE_ACTION 13 -#define SUBTYPE_ACTION_NO_ACK 14 - -/* value domain of 802.11 CNTL frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header */ -#define SUBTYPE_WRAPPER 7 -#define SUBTYPE_BLOCK_ACK_REQ 8 -#define SUBTYPE_BLOCK_ACK 9 -#define SUBTYPE_PS_POLL 10 -#define SUBTYPE_RTS 11 -#define SUBTYPE_CTS 12 -#define SUBTYPE_ACK 13 -#define SUBTYPE_CFEND 14 -#define SUBTYPE_CFEND_CFACK 15 - -/* value domain of 802.11 DATA frame's FC.subtype, which is b7..4 of the 1st-byte of MAC header */ -#define SUBTYPE_DATA 0 -#define SUBTYPE_DATA_CFACK 1 -#define SUBTYPE_DATA_CFPOLL 2 -#define SUBTYPE_DATA_CFACK_CFPOLL 3 -#define SUBTYPE_NULL_FUNC 4 -#define SUBTYPE_CFACK 5 -#define SUBTYPE_CFPOLL 6 -#define SUBTYPE_CFACK_CFPOLL 7 -#define SUBTYPE_QDATA 8 -#define SUBTYPE_QDATA_CFACK 9 -#define SUBTYPE_QDATA_CFPOLL 10 -#define SUBTYPE_QDATA_CFACK_CFPOLL 11 -#define SUBTYPE_QOS_NULL 12 -#define SUBTYPE_QOS_CFACK 13 -#define SUBTYPE_QOS_CFPOLL 14 -#define SUBTYPE_QOS_CFACK_CFPOLL 15 - -/* ACK policy of QOS Control field bit 6:5 */ -#define NORMAL_ACK 0x00 /* b6:5 = 00 */ -#define NO_ACK 0x20 /* b6:5 = 01 */ -#define NO_EXPLICIT_ACK 0x40 /* b6:5 = 10 */ -#define BLOCK_ACK 0x60 /* b6:5 = 11 */ - -/* */ -/* rtmp_data.c uses this definition */ -/* */ -#define LENGTH_802_11 24 -#define LENGTH_802_11_AND_H 30 -#define LENGTH_802_11_CRC_H 34 -#define LENGTH_802_11_CRC 28 -#define LENGTH_802_11_WITH_ADDR4 30 -#define LENGTH_802_3 14 -#define LENGTH_802_3_TYPE 2 -#define LENGTH_802_1_H 8 -#define LENGTH_EAPOL_H 4 -#define LENGTH_WMMQOS_H 2 -#define LENGTH_CRC 4 -#define MAX_SEQ_NUMBER 0x0fff -#define LENGTH_802_3_NO_TYPE 12 -#define LENGTH_802_1Q 4 /* VLAN related */ - -/* STA_CSR4.field.TxResult */ -#define TX_RESULT_SUCCESS 0 -#define TX_RESULT_ZERO_LENGTH 1 -#define TX_RESULT_UNDER_RUN 2 -#define TX_RESULT_OHY_ERROR 4 -#define TX_RESULT_RETRY_FAIL 6 - -/* All PHY rate summary in TXD */ -/* Preamble MODE in TxD */ -#define MODE_CCK 0 -#define MODE_OFDM 1 -#define MODE_HTMIX 2 -#define MODE_HTGREENFIELD 3 - -/* MCS for CCK. BW.SGI.STBC are reserved */ -#define MCS_longP_RATE_1 0 /* long preamble CCK 1Mbps */ -#define MCS_longP_RATE_2 1 /* long preamble CCK 1Mbps */ -#define MCS_longP_RATE_5_5 2 -#define MCS_longP_RATE_11 3 -#define MCS_SHORTP_RATE_1 4 /* long preamble CCK 1Mbps. short is forbidden in 1Mbps */ -#define MCS_SHORTP_RATE_2 5 /* short preamble CCK 2Mbps */ -#define MCS_SHORTP_RATE_5_5 6 -#define MCS_SHORTP_RATE_11 7 -/* To send duplicate legacy OFDM. set BW=BW_40. SGI.STBC are reserved */ -#define MCS_RATE_6 0 /* legacy OFDM */ -#define MCS_RATE_9 1 /* OFDM */ -#define MCS_RATE_12 2 /* OFDM */ -#define MCS_RATE_18 3 /* OFDM */ -#define MCS_RATE_24 4 /* OFDM */ -#define MCS_RATE_36 5 /* OFDM */ -#define MCS_RATE_48 6 /* OFDM */ -#define MCS_RATE_54 7 /* OFDM */ -/* HT */ -#define MCS_0 0 /* 1S */ -#define MCS_1 1 -#define MCS_2 2 -#define MCS_3 3 -#define MCS_4 4 -#define MCS_5 5 -#define MCS_6 6 -#define MCS_7 7 -#define MCS_8 8 /* 2S */ -#define MCS_9 9 -#define MCS_10 10 -#define MCS_11 11 -#define MCS_12 12 -#define MCS_13 13 -#define MCS_14 14 -#define MCS_15 15 -#define MCS_16 16 /* 3*3 */ -#define MCS_17 17 -#define MCS_18 18 -#define MCS_19 19 -#define MCS_20 20 -#define MCS_21 21 -#define MCS_22 22 -#define MCS_23 23 -#define MCS_32 32 -#define MCS_AUTO 33 - -/* OID_HTPHYMODE */ -/* MODE */ -#define HTMODE_MM 0 -#define HTMODE_GF 1 - -/* Fixed Tx MODE - HT, CCK or OFDM */ -#define FIXED_TXMODE_HT 0 -#define FIXED_TXMODE_CCK 1 -#define FIXED_TXMODE_OFDM 2 -/* BW */ -#define BW_20 BAND_WIDTH_20 -#define BW_40 BAND_WIDTH_40 -#define BW_BOTH BAND_WIDTH_BOTH -#define BW_10 BAND_WIDTH_10 /* 802.11j has 10MHz. This definition is for internal usage. doesn't fill in the IE or other field. */ - -/* SHORTGI */ -#define GI_400 GAP_INTERVAL_400 /* only support in HT mode */ -#define GI_BOTH GAP_INTERVAL_BOTH -#define GI_800 GAP_INTERVAL_800 -/* STBC */ -#define STBC_NONE 0 -#define STBC_USE 1 /* limited use in rt2860b phy */ -#define RXSTBC_ONE 1 /* rx support of one spatial stream */ -#define RXSTBC_TWO 2 /* rx support of 1 and 2 spatial stream */ -#define RXSTBC_THR 3 /* rx support of 1~3 spatial stream */ -/* MCS FEEDBACK */ -#define MCSFBK_NONE 0 /* not support mcs feedback / */ -#define MCSFBK_RSV 1 /* reserved */ -#define MCSFBK_UNSOLICIT 2 /* only support unsolict mcs feedback */ -#define MCSFBK_MRQ 3 /* response to both MRQ and unsolict mcs feedback */ - -/* MIMO power safe */ -#define MMPS_STATIC 0 -#define MMPS_DYNAMIC 1 -#define MMPS_RSV 2 -#define MMPS_ENABLE 3 - -/* A-MSDU size */ -#define AMSDU_0 0 -#define AMSDU_1 1 - -/* MCS use 7 bits */ -#define TXRATEMIMO 0x80 -#define TXRATEMCS 0x7F -#define TXRATEOFDM 0x7F -#define RATE_1 0 -#define RATE_2 1 -#define RATE_5_5 2 -#define RATE_11 3 -#define RATE_6 4 /* OFDM */ -#define RATE_9 5 /* OFDM */ -#define RATE_12 6 /* OFDM */ -#define RATE_18 7 /* OFDM */ -#define RATE_24 8 /* OFDM */ -#define RATE_36 9 /* OFDM */ -#define RATE_48 10 /* OFDM */ -#define RATE_54 11 /* OFDM */ -#define RATE_FIRST_OFDM_RATE RATE_6 -#define RATE_LAST_OFDM_RATE RATE_54 -#define RATE_6_5 12 /* HT mix */ -#define RATE_13 13 /* HT mix */ -#define RATE_19_5 14 /* HT mix */ -#define RATE_26 15 /* HT mix */ -#define RATE_39 16 /* HT mix */ -#define RATE_52 17 /* HT mix */ -#define RATE_58_5 18 /* HT mix */ -#define RATE_65 19 /* HT mix */ -#define RATE_78 20 /* HT mix */ -#define RATE_104 21 /* HT mix */ -#define RATE_117 22 /* HT mix */ -#define RATE_130 23 /* HT mix */ -/*#define RATE_AUTO_SWITCH 255 // for StaCfg.FixedTxRate only */ -#define HTRATE_0 12 -#define RATE_FIRST_MM_RATE HTRATE_0 -#define RATE_FIRST_HT_RATE HTRATE_0 -#define RATE_LAST_HT_RATE HTRATE_0 - -/* pTxWI->txop */ -#define IFS_HTTXOP 0 /* The txop will be handles by ASIC. */ -#define IFS_PIFS 1 -#define IFS_SIFS 2 -#define IFS_BACKOFF 3 - -/* pTxD->RetryMode */ -#define long_RETRY 1 -#define SHORT_RETRY 0 - -/* Country Region definition */ -#define REGION_MINIMUM_BG_BAND 0 -#define REGION_0_BG_BAND 0 /* 1-11 */ -#define REGION_1_BG_BAND 1 /* 1-13 */ -#define REGION_2_BG_BAND 2 /* 10-11 */ -#define REGION_3_BG_BAND 3 /* 10-13 */ -#define REGION_4_BG_BAND 4 /* 14 */ -#define REGION_5_BG_BAND 5 /* 1-14 */ -#define REGION_6_BG_BAND 6 /* 3-9 */ -#define REGION_7_BG_BAND 7 /* 5-13 */ -#define REGION_31_BG_BAND 31 /* 5-13 */ -#define REGION_MAXIMUM_BG_BAND 7 - -#define REGION_MINIMUM_A_BAND 0 -#define REGION_0_A_BAND 0 /* 36, 40, 44, 48, 52, 56, 60, 64, 149, 153, 157, 161, 165 */ -#define REGION_1_A_BAND 1 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 */ -#define REGION_2_A_BAND 2 /* 36, 40, 44, 48, 52, 56, 60, 64 */ -#define REGION_3_A_BAND 3 /* 52, 56, 60, 64, 149, 153, 157, 161 */ -#define REGION_4_A_BAND 4 /* 149, 153, 157, 161, 165 */ -#define REGION_5_A_BAND 5 /* 149, 153, 157, 161 */ -#define REGION_6_A_BAND 6 /* 36, 40, 44, 48 */ -#define REGION_7_A_BAND 7 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161, 165, 169, 173 */ -#define REGION_8_A_BAND 8 /* 52, 56, 60, 64 */ -#define REGION_9_A_BAND 9 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 132, 136, 140, 149, 153, 157, 161, 165 */ -#define REGION_10_A_BAND 10 /* 36, 40, 44, 48, 149, 153, 157, 161, 165 */ -#define REGION_11_A_BAND 11 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 149, 153, 157, 161 */ -#define REGION_12_A_BAND 12 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140 */ -#define REGION_13_A_BAND 13 /* 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132, 136, 140, 149, 153, 157, 161 */ -#define REGION_14_A_BAND 14 /* 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 136, 140, 149, 153, 157, 161, 165 */ -#define REGION_15_A_BAND 15 /* 149, 153, 157, 161, 165, 169, 173 */ -#define REGION_MAXIMUM_A_BAND 15 - -/* pTxD->CipherAlg */ -#define CIPHER_NONE 0 -#define CIPHER_WEP64 1 -#define CIPHER_WEP128 2 -#define CIPHER_TKIP 3 -#define CIPHER_AES 4 -#define CIPHER_CKIP64 5 -#define CIPHER_CKIP128 6 -#define CIPHER_TKIP_NO_MIC 7 /* MIC appended by driver: not a valid value in hardware key table */ -#define CIPHER_SMS4 8 - -/* LED Status. */ -#define LED_LINK_DOWN 0 -#define LED_LINK_UP 1 -#define LED_RADIO_OFF 2 -#define LED_RADIO_ON 3 -#define LED_HALT 4 -#define LED_WPS 5 -#define LED_ON_SITE_SURVEY 6 -#define LED_POWER_UP 7 - -/* value domain of pAd->LedCntl.LedMode and E2PROM */ -#define LED_MODE_DEFAULT 0 -#define LED_MODE_TWO_LED 1 -/*#define LED_MODE_SIGNAL_STREGTH 8 // EEPROM define =8 */ -#define LED_MODE_SIGNAL_STREGTH 0x40 /* EEPROM define = 64 */ - -/* RC4 init value, used fro WEP & TKIP */ -#define PPPINITFCS32 0xffffffff /* Initial FCS value */ - -/* value domain of pAd->StaCfg.PortSecured. 802.1X controlled port definition */ -#define WPA_802_1X_PORT_SECURED 1 -#define WPA_802_1X_PORT_NOT_SECURED 2 - -#define PAIRWISE_KEY 1 -#define GROUP_KEY 2 - -/*definition of DRS */ -#define MAX_STEP_OF_TX_RATE_SWITCH 32 - -/* pre-allocated free NDIS PACKET/BUFFER poll for internal usage */ -#define MAX_NUM_OF_FREE_NDIS_PACKET 128 - -/*Block ACK */ -#define MAX_TX_REORDERBUF 64 -#define MAX_RX_REORDERBUF 64 -#define DEFAULT_TX_TIMEOUT 30 -#define DEFAULT_RX_TIMEOUT 30 - -/* definition of Recipient or Originator */ -#define I_RECIPIENT TRUE -#define I_ORIGINATOR FALSE - -#define DEFAULT_BBP_TX_POWER 0 -#define DEFAULT_RF_TX_POWER 5 - -#define MAX_INI_BUFFER_SIZE 4096 -#define MAX_PARAM_BUFFER_SIZE (2048) /* enough for ACL (18*64) */ - /*18 : the length of Mac address acceptable format "01:02:03:04:05:06;") */ - /*64 : MAX_NUM_OF_ACL_LIST */ -/* definition of pAd->OpMode */ -#define OPMODE_STA 0 -#define OPMODE_AP 1 -/*#define OPMODE_L3_BRG 2 // as AP and STA at the same time */ - -/* ========================= AP rtmp_def.h =========================== */ -/* value domain for pAd->EventTab.Log[].Event */ -#define EVENT_RESET_ACCESS_POint 0 /* Log = "hh:mm:ss Restart Access Point" */ -#define EVENT_ASSOCIATED 1 /* Log = "hh:mm:ss STA 00:01:02:03:04:05 associated" */ -#define EVENT_DISASSOCIATED 2 /* Log = "hh:mm:ss STA 00:01:02:03:04:05 left this BSS" */ -#define EVENT_AGED_OUT 3 /* Log = "hh:mm:ss STA 00:01:02:03:04:05 was aged-out and removed from this BSS" */ -#define EVENT_COUNTER_M 4 -#define EVENT_INVALID_PSK 5 -#define EVENT_MAX_EVENT_TYPE 6 -/* ==== end of AP rtmp_def.h ============ */ - -/* definition RSSI Number */ -#define RSSI_0 0 -#define RSSI_1 1 -#define RSSI_2 2 - -/* definition of radar detection */ -#define RD_NORMAL_MODE 0 /* Not found radar signal */ -#define RD_SWITCHING_MODE 1 /* Found radar signal, and doing channel switch */ -#define RD_SILENCE_MODE 2 /* After channel switch, need to be silence a while to ensure radar not found */ - -/*Driver defined cid for mapping status and command. */ -#define SLEEPCID 0x11 -#define WAKECID 0x22 -#define QUERYPOWERCID 0x33 -#define OWNERMCU 0x1 -#define OWNERCPU 0x0 - -/* MBSSID definition */ -#define ENTRY_NOT_FOUND 0xFF - -/* After Linux 2.6.9, - * VLAN module use Private (from user) interface flags (netdevice->priv_flags). - * #define IFF_802_1Q_VLAN 0x1 -- 802.1Q VLAN device. in if.h - * ref to ip_sabotage_out() [ out->priv_flags & IFF_802_1Q_VLAN ] in br_netfilter.c - * - * For this reason, we MUST use EVEN value in priv_flags - */ -#define INT_MAIN 0x0100 -#define INT_MBSSID 0x0200 -#define INT_WDS 0x0300 -#define INT_APCLI 0x0400 -#define INT_MESH 0x0500 - -#define INF_MAIN_DEV_NAME "wlan" -#define INF_MBSSID_DEV_NAME "ra" -#define INF_WDS_DEV_NAME "wds" -#define INF_APCLI_DEV_NAME "apcli" -#define INF_MESH_DEV_NAME "mesh" - -/* WEP Key TYPE */ -#define WEP_HEXADECIMAL_TYPE 0 -#define WEP_ASCII_TYPE 1 - -/* WIRELESS EVENTS definition */ -/* Max number of char in custom event, refer to wireless_tools.28/wireless.20.h */ -#define IW_CUSTOM_MAX_LEN 255 /* In bytes */ - -/* For system event - start */ -#define IW_SYS_EVENT_FLAG_START 0x0200 -#define IW_ASSOC_EVENT_FLAG 0x0200 -#define IW_DISASSOC_EVENT_FLAG 0x0201 -#define IW_DEAUTH_EVENT_FLAG 0x0202 -#define IW_AGEOUT_EVENT_FLAG 0x0203 -#define IW_COUNTER_MEASURES_EVENT_FLAG 0x0204 -#define IW_REPLAY_COUNTER_DIFF_EVENT_FLAG 0x0205 -#define IW_RSNIE_DIFF_EVENT_FLAG 0x0206 -#define IW_MIC_DIFF_EVENT_FLAG 0x0207 -#define IW_ICV_ERROR_EVENT_FLAG 0x0208 -#define IW_MIC_ERROR_EVENT_FLAG 0x0209 -#define IW_GROUP_HS_TIMEOUT_EVENT_FLAG 0x020A -#define IW_PAIRWISE_HS_TIMEOUT_EVENT_FLAG 0x020B -#define IW_RSNIE_SANITY_FAIL_EVENT_FLAG 0x020C -#define IW_SET_KEY_DONE_WPA1_EVENT_FLAG 0x020D -#define IW_SET_KEY_DONE_WPA2_EVENT_FLAG 0x020E -#define IW_STA_LINKUP_EVENT_FLAG 0x020F -#define IW_STA_LINKDOWN_EVENT_FLAG 0x0210 -#define IW_SCAN_COMPLETED_EVENT_FLAG 0x0211 -#define IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG 0x0212 -/* if add new system event flag, please update the IW_SYS_EVENT_FLAG_END */ -#define IW_SYS_EVENT_FLAG_END 0x0212 -#define IW_SYS_EVENT_TYPE_NUM (IW_SYS_EVENT_FLAG_END - IW_SYS_EVENT_FLAG_START + 1) -/* For system event - end */ - -/* For spoof attack event - start */ -#define IW_SPOOF_EVENT_FLAG_START 0x0300 -#define IW_CONFLICT_SSID_EVENT_FLAG 0x0300 -#define IW_SPOOF_ASSOC_RESP_EVENT_FLAG 0x0301 -#define IW_SPOOF_REASSOC_RESP_EVENT_FLAG 0x0302 -#define IW_SPOOF_PROBE_RESP_EVENT_FLAG 0x0303 -#define IW_SPOOF_BEACON_EVENT_FLAG 0x0304 -#define IW_SPOOF_DISASSOC_EVENT_FLAG 0x0305 -#define IW_SPOOF_AUTH_EVENT_FLAG 0x0306 -#define IW_SPOOF_DEAUTH_EVENT_FLAG 0x0307 -#define IW_SPOOF_UNKNOWN_MGMT_EVENT_FLAG 0x0308 -#define IW_REPLAY_ATTACK_EVENT_FLAG 0x0309 -/* if add new spoof attack event flag, please update the IW_SPOOF_EVENT_FLAG_END */ -#define IW_SPOOF_EVENT_FLAG_END 0x0309 -#define IW_SPOOF_EVENT_TYPE_NUM (IW_SPOOF_EVENT_FLAG_END - IW_SPOOF_EVENT_FLAG_START + 1) -/* For spoof attack event - end */ - -/* For flooding attack event - start */ -#define IW_FLOOD_EVENT_FLAG_START 0x0400 -#define IW_FLOOD_AUTH_EVENT_FLAG 0x0400 -#define IW_FLOOD_ASSOC_REQ_EVENT_FLAG 0x0401 -#define IW_FLOOD_REASSOC_REQ_EVENT_FLAG 0x0402 -#define IW_FLOOD_PROBE_REQ_EVENT_FLAG 0x0403 -#define IW_FLOOD_DISASSOC_EVENT_FLAG 0x0404 -#define IW_FLOOD_DEAUTH_EVENT_FLAG 0x0405 -#define IW_FLOOD_EAP_REQ_EVENT_FLAG 0x0406 -/* if add new flooding attack event flag, please update the IW_FLOOD_EVENT_FLAG_END */ -#define IW_FLOOD_EVENT_FLAG_END 0x0406 -#define IW_FLOOD_EVENT_TYPE_NUM (IW_FLOOD_EVENT_FLAG_END - IW_FLOOD_EVENT_FLAG_START + 1) -/* For flooding attack - end */ - -/* End - WIRELESS EVENTS definition */ - -/* definition for DLS, kathy */ -#define MAX_NUM_OF_INIT_DLS_ENTRY 1 -#define MAX_NUM_OF_DLS_ENTRY MAX_NUMBER_OF_DLS_ENTRY - -/*Block ACK, kathy */ -#define MAX_TX_REORDERBUF 64 -#define MAX_RX_REORDERBUF 64 -#define DEFAULT_TX_TIMEOUT 30 -#define DEFAULT_RX_TIMEOUT 30 -#define MAX_BARECI_SESSION 8 - -#ifndef IW_ESSID_MAX_SIZE -/* Maximum size of the ESSID and pAd->nickname strings */ -#define IW_ESSID_MAX_SIZE 32 -#endif - -/* For AsicRadioOff/AsicRadioOn function */ -#define DOT11POWERSAVE 0 -#define GUIRADIO_OFF 1 -#define RTMP_HALT 2 -#define GUI_IDLE_POWER_SAVE 3 -/* -- */ - -/* definition for WpaSupport flag */ -#define WPA_SUPPLICANT_DISABLE 0 -#define WPA_SUPPLICANT_ENABLE 1 -#define WPA_SUPPLICANT_ENABLE_WITH_WEB_UI 2 - -/* Endian byte swapping codes */ -#define SWAP16(x) \ - ((u16)( \ - (((u16)(x) & (u16)0x00ffU) << 8) | \ - (((u16)(x) & (u16)0xff00U) >> 8) )) - -#define SWAP32(x) \ - ((u32)( \ - (((u32)(x) & (u32)0x000000ffUL) << 24) | \ - (((u32)(x) & (u32)0x0000ff00UL) << 8) | \ - (((u32)(x) & (u32)0x00ff0000UL) >> 8) | \ - (((u32)(x) & (u32)0xff000000UL) >> 24) )) - -#define SWAP64(x) \ - ((u64)( \ - (u64)(((u64)(x) & (u64)0x00000000000000ffULL) << 56) | \ - (u64)(((u64)(x) & (u64)0x000000000000ff00ULL) << 40) | \ - (u64)(((u64)(x) & (u64)0x0000000000ff0000ULL) << 24) | \ - (u64)(((u64)(x) & (u64)0x00000000ff000000ULL) << 8) | \ - (u64)(((u64)(x) & (u64)0x000000ff00000000ULL) >> 8) | \ - (u64)(((u64)(x) & (u64)0x0000ff0000000000ULL) >> 24) | \ - (u64)(((u64)(x) & (u64)0x00ff000000000000ULL) >> 40) | \ - (u64)(((u64)(x) & (u64)0xff00000000000000ULL) >> 56) )) - -#define cpu2le64(x) ((u64)(x)) -#define le2cpu64(x) ((u64)(x)) -#define cpu2le32(x) ((u32)(x)) -#define le2cpu32(x) ((u32)(x)) -#define cpu2le16(x) ((u16)(x)) -#define le2cpu16(x) ((u16)(x)) -#define cpu2be64(x) SWAP64((x)) -#define be2cpu64(x) SWAP64((x)) -#define cpu2be32(x) SWAP32((x)) -#define be2cpu32(x) SWAP32((x)) -#define cpu2be16(x) SWAP16((x)) -#define be2cpu16(x) SWAP16((x)) - -#define ABS(_x, _y) ((_x) > (_y)) ? ((_x) -(_y)) : ((_y) -(_x)) - -#define A2Dec(_X, _p) \ -{ \ - u8 *p; \ - _X = 0; \ - p = _p; \ - while (((*p >= '0') && (*p <= '9'))) \ - { \ - if ((*p >= '0') && (*p <= '9')) \ - _X = _X * 10 + *p - 48; \ - p++; \ - } \ -} - -#define A2Hex(_X, _p) \ -do{ \ - char *__p; \ - (_X) = 0; \ - __p = (char *)(_p); \ - while (((*__p >= 'a') && (*__p <= 'f')) || ((*__p >= 'A') && (*__p <= 'F')) || ((*__p >= '0') && (*__p <= '9'))) \ - { \ - if ((*__p >= 'a') && (*__p <= 'f')) \ - (_X) = (_X) * 16 + *__p - 87; \ - else if ((*__p >= 'A') && (*__p <= 'F')) \ - (_X) = (_X) * 16 + *__p - 55; \ - else if ((*__p >= '0') && (*__p <= '9')) \ - (_X) = (_X) * 16 + *__p - 48; \ - __p++; \ - } \ -}while(0) - -#endif /* __RTMP_DEF_H__ */ diff --git a/trunk/drivers/staging/rt2860/rtmp_dot11.h b/trunk/drivers/staging/rt2860/rtmp_dot11.h deleted file mode 100644 index 4f8abd77ada5..000000000000 --- a/trunk/drivers/staging/rt2860/rtmp_dot11.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* -*/ - -#ifndef __DOT11_BASE_H__ -#define __DOT11_BASE_H__ - -#include "rtmp_type.h" - -/* 4-byte HTC field. maybe included in any frame except non-QOS data frame. The Order bit must set 1. */ -struct PACKED rt_ht_control { - u32 MA:1; /*management action payload exist in (QoS Null+HTC) */ - u32 TRQ:1; /*sounding request */ - u32 MRQ:1; /*MCS feedback. Request for a MCS feedback */ - u32 MRSorASI:3; /* MRQ Sequence identifier. unchanged during entire procedure. 0x000-0x110. */ - u32 MFS:3; /*SET to the received value of MRS. 0x111 for unsolicited MFB. */ - u32 MFBorASC:7; /*Link adaptation feedback containing recommended MCS. 0x7f for no feedback or not available */ - u32 CalPos:2; /* calibration position */ - u32 CalSeq:2; /*calibration sequence */ - u32 FBKReq:2; /*feedback request */ - u32 CSISTEERING:2; /*CSI/ STEERING */ - u32 ZLFAnnouce:1; /* ZLF announcement */ - u32 rsv:5; /*calibration sequence */ - u32 ACConstraint:1; /*feedback request */ - u32 RDG:1; /*RDG / More PPDU */ -}; - -/* 2-byte QOS CONTROL field */ -struct PACKED rt_qos_control { - u16 TID:4; - u16 EOSP:1; - u16 AckPolicy:2; /*0: normal ACK 1:No ACK 2:scheduled under MTBA/PSMP 3: BA */ - u16 AMsduPresent:1; - u16 Txop_QueueSize:8; -}; - -/* 2-byte Frame control field */ -struct PACKED rt_frame_control { - u16 Ver:2; /* Protocol version */ - u16 Type:2; /* MSDU type */ - u16 SubType:4; /* MSDU subtype */ - u16 ToDs:1; /* To DS indication */ - u16 FrDs:1; /* From DS indication */ - u16 MoreFrag:1; /* More fragment bit */ - u16 Retry:1; /* Retry status bit */ - u16 PwrMgmt:1; /* Power management bit */ - u16 MoreData:1; /* More data bit */ - u16 Wep:1; /* Wep data */ - u16 Order:1; /* Strict order expected */ -}; - -struct PACKED rt_header_802_11 { - struct rt_frame_control FC; - u16 Duration; - u8 Addr1[MAC_ADDR_LEN]; - u8 Addr2[MAC_ADDR_LEN]; - u8 Addr3[MAC_ADDR_LEN]; - u16 Frag:4; - u16 Sequence:12; - u8 Octet[0]; -}; - -struct PACKED rt_pspoll_frame { - struct rt_frame_control FC; - u16 Aid; - u8 Bssid[MAC_ADDR_LEN]; - u8 Ta[MAC_ADDR_LEN]; -}; - -struct PACKED rt_rts_frame { - struct rt_frame_control FC; - u16 Duration; - u8 Addr1[MAC_ADDR_LEN]; - u8 Addr2[MAC_ADDR_LEN]; -}; - -#endif /* __DOT11_BASE_H__ // */ diff --git a/trunk/drivers/staging/rt2860/rtmp_iface.h b/trunk/drivers/staging/rt2860/rtmp_iface.h deleted file mode 100644 index 808c05529848..000000000000 --- a/trunk/drivers/staging/rt2860/rtmp_iface.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rt_iface.h - - Abstract: - - Revision History: - Who When What - --------- ---------- ---------------------------------------------- - */ - -#ifndef __RTMP_IFACE_H__ -#define __RTMP_IFACE_H__ - -#ifdef RTMP_PCI_SUPPORT -#include "iface/rtmp_pci.h" -#endif /* RTMP_PCI_SUPPORT // */ -#ifdef RTMP_USB_SUPPORT -#include "iface/rtmp_usb.h" -#endif /* RTMP_USB_SUPPORT // */ - -struct rt_inf_pci_config { - unsigned long CSRBaseAddress; /* PCI MMIO Base Address, all access will use */ - unsigned int irq_num; -}; - -struct rt_inf_usb_config { - u8 BulkInEpAddr; /* bulk-in endpoint address */ - u8 BulkOutEpAddr[6]; /* bulk-out endpoint address */ -}; - -struct rt_inf_rbus_config { - unsigned long csr_addr; - unsigned int irq; -}; - -typedef enum _RTMP_INF_TYPE_ { - RTMP_DEV_INF_UNKNOWN = 0, - RTMP_DEV_INF_PCI = 1, - RTMP_DEV_INF_USB = 2, - RTMP_DEV_INF_RBUS = 4, -} RTMP_INF_TYPE; - -typedef union _RTMP_INF_CONFIG_ { - struct rt_inf_pci_config pciConfig; - struct rt_inf_usb_config usbConfig; - struct rt_inf_rbus_config rbusConfig; -} RTMP_INF_CONFIG; - -#endif /* __RTMP_IFACE_H__ // */ diff --git a/trunk/drivers/staging/rt2860/rtmp_mcu.h b/trunk/drivers/staging/rt2860/rtmp_mcu.h deleted file mode 100644 index d0987e55cdad..000000000000 --- a/trunk/drivers/staging/rt2860/rtmp_mcu.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_mcu.h - - Abstract: - Miniport header file for mcu related information - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- -*/ - -#ifndef __RTMP_MCU_H__ -#define __RTMP_MCU_H__ - -int RtmpAsicEraseFirmware(struct rt_rtmp_adapter *pAd); - -int RtmpAsicLoadFirmware(struct rt_rtmp_adapter *pAd); - -int RtmpAsicSendCommandToMcu(struct rt_rtmp_adapter *pAd, - u8 Command, - u8 Token, u8 Arg0, u8 Arg1); - -#endif /* __RTMP_MCU_H__ // */ diff --git a/trunk/drivers/staging/rt2860/rtmp_os.h b/trunk/drivers/staging/rt2860/rtmp_os.h deleted file mode 100644 index 94c30c8ca662..000000000000 --- a/trunk/drivers/staging/rt2860/rtmp_os.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_os.h - - Abstract: - - Revision History: - Who When What - --------- ---------- ---------------------------------------------- - */ - -#ifndef __RTMP_OS_H__ -#define __RTMP_OS_H__ - -#ifdef LINUX -#include "rt_linux.h" -#endif /* LINUX // */ - -/* - This data structure mainly strip some callback function defined in - "struct net_device" in kernel source "include/linux/netdevice.h". - - The definition of this data structure may various depends on different - OS. Use it carefully. -*/ -struct rt_rtmp_os_netdev_op_hook { - const struct net_device_ops *netdev_ops; - void *priv; - int priv_flags; - unsigned char devAddr[6]; - unsigned char devName[16]; - unsigned char needProtcted; -}; - -typedef enum _RTMP_TASK_STATUS_ { - RTMP_TASK_STAT_UNKNOWN = 0, - RTMP_TASK_STAT_INITED = 1, - RTMP_TASK_STAT_RUNNING = 2, - RTMP_TASK_STAT_STOPED = 4, -} RTMP_TASK_STATUS; -#define RTMP_TASK_CAN_DO_INSERT (RTMP_TASK_STAT_INITED |RTMP_TASK_STAT_RUNNING) - -#define RTMP_OS_TASK_NAME_LEN 16 -struct rt_rtmp_os_task { - char taskName[RTMP_OS_TASK_NAME_LEN]; - void *priv; - /*unsigned long taskFlags; */ - RTMP_TASK_STATUS taskStatus; -#ifndef KTHREAD_SUPPORT - struct semaphore taskSema; - struct pid *taskPID; - struct completion taskComplete; -#endif - unsigned char task_killed; -#ifdef KTHREAD_SUPPORT - struct task_struct *kthread_task; - wait_queue_head_t kthread_q; - BOOLEAN kthread_running; -#endif -}; - -int RtmpOSIRQRequest(struct net_device *pNetDev); -int RtmpOSIRQRelease(struct net_device *pNetDev); - -#endif /* __RMTP_OS_H__ // */ diff --git a/trunk/drivers/staging/rt2860/rtmp_timer.h b/trunk/drivers/staging/rt2860/rtmp_timer.h deleted file mode 100644 index 15b628743500..000000000000 --- a/trunk/drivers/staging/rt2860/rtmp_timer.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_timer.h - - Abstract: - Ralink Wireless Driver timer related data structures and declarations - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs - Shiang Tu Aug-28-2008 init version - Justin P. Mattock 11/07/2010 Fix a typo - -*/ - -#ifndef __RTMP_TIMER_H__ -#define __RTMP_TIMER_H__ - -#include "rtmp_os.h" - -#define DECLARE_TIMER_FUNCTION(_func) \ - void rtmp_timer_##_func(unsigned long data) - -#define GET_TIMER_FUNCTION(_func) \ - rtmp_timer_##_func - -/* ----------------- Timer Related MARCO ---------------*/ -/* In some os or chipset, we have a lot of timer functions and will read/write register, */ -/* it's not allowed in Linux USB sub-system to do it ( because of sleep issue when */ -/* submit to ctrl pipe). So we need a wrapper function to take care it. */ - -#ifdef RTMP_TIMER_TASK_SUPPORT -typedef void(*RTMP_TIMER_TASK_HANDLE) (void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, - void *SystemSpecific3); -#endif /* RTMP_TIMER_TASK_SUPPORT // */ - -struct rt_ralink_timer { - struct timer_list TimerObj; /* Ndis Timer object */ - BOOLEAN Valid; /* Set to True when call RTMPInitTimer */ - BOOLEAN State; /* True if timer cancelled */ - BOOLEAN PeriodicType; /* True if timer is periodic timer */ - BOOLEAN Repeat; /* True if periodic timer */ - unsigned long TimerValue; /* Timer value in milliseconds */ - unsigned long cookie; /* os specific object */ -#ifdef RTMP_TIMER_TASK_SUPPORT - RTMP_TIMER_TASK_HANDLE handle; - void *pAd; -#endif /* RTMP_TIMER_TASK_SUPPORT // */ -}; - -#ifdef RTMP_TIMER_TASK_SUPPORT -struct rt_rtmp_timer_task_entry { - struct rt_ralink_timer *pRaTimer; - struct rt_rtmp_timer_task_entry *pNext; -}; - -#define TIMER_QUEUE_SIZE_MAX 128 -struct rt_rtmp_timer_task_queue { - unsigned int status; - unsigned char *pTimerQPoll; - struct rt_rtmp_timer_task_entry *pQPollFreeList; - struct rt_rtmp_timer_task_entry *pQHead; - struct rt_rtmp_timer_task_entry *pQTail; -}; - -#define BUILD_TIMER_FUNCTION(_func) \ -void rtmp_timer_##_func(unsigned long data) \ -{ \ - struct rt_ralink_timer *_pTimer = (struct rt_ralink_timer *)data; \ - struct rt_rtmp_timer_task_entry *_pQNode; \ - struct rt_rtmp_adapter *_pAd; \ - \ - _pTimer->handle = _func; \ - _pAd = (struct rt_rtmp_adapter *)_pTimer->pAd; \ - _pQNode = RtmpTimerQInsert(_pAd, _pTimer); \ - if ((_pQNode == NULL) && (_pAd->TimerQ.status & RTMP_TASK_CAN_DO_INSERT)) \ - RTMP_OS_Add_Timer(&_pTimer->TimerObj, OS_HZ); \ -} -#else -#define BUILD_TIMER_FUNCTION(_func) \ -void rtmp_timer_##_func(unsigned long data) \ -{ \ - struct rt_ralink_timer *pTimer = (struct rt_ralink_timer *)data; \ - \ - _func(NULL, (void *)pTimer->cookie, NULL, pTimer); \ - if (pTimer->Repeat) \ - RTMP_OS_Add_Timer(&pTimer->TimerObj, pTimer->TimerValue); \ -} -#endif /* RTMP_TIMER_TASK_SUPPORT // */ - -DECLARE_TIMER_FUNCTION(MlmePeriodicExec); -DECLARE_TIMER_FUNCTION(MlmeRssiReportExec); -DECLARE_TIMER_FUNCTION(AsicRxAntEvalTimeout); -DECLARE_TIMER_FUNCTION(APSDPeriodicExec); -DECLARE_TIMER_FUNCTION(AsicRfTuningExec); -#ifdef RTMP_MAC_USB -DECLARE_TIMER_FUNCTION(BeaconUpdateExec); -#endif /* RTMP_MAC_USB // */ - -DECLARE_TIMER_FUNCTION(BeaconTimeout); -DECLARE_TIMER_FUNCTION(ScanTimeout); -DECLARE_TIMER_FUNCTION(AuthTimeout); -DECLARE_TIMER_FUNCTION(AssocTimeout); -DECLARE_TIMER_FUNCTION(ReassocTimeout); -DECLARE_TIMER_FUNCTION(DisassocTimeout); -DECLARE_TIMER_FUNCTION(LinkDownExec); -DECLARE_TIMER_FUNCTION(StaQuickResponeForRateUpExec); -DECLARE_TIMER_FUNCTION(WpaDisassocApAndBlockAssoc); -DECLARE_TIMER_FUNCTION(PsPollWakeExec); -DECLARE_TIMER_FUNCTION(RadioOnExec); - -#ifdef RTMP_MAC_USB -DECLARE_TIMER_FUNCTION(RtmpUsbStaAsicForceWakeupTimeout); -#endif /* RTMP_MAC_USB // */ - -#if defined(AP_LED) || defined(STA_LED) -DECLARE_TIMER_FUNCTION(LedCtrlMain); -#endif - -#endif /* __RTMP_TIMER_H__ // */ diff --git a/trunk/drivers/staging/rt2860/rtmp_type.h b/trunk/drivers/staging/rt2860/rtmp_type.h deleted file mode 100644 index d9bb2d64c8b8..000000000000 --- a/trunk/drivers/staging/rt2860/rtmp_type.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_type.h - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs - Paul Lin 1-2-2004 -*/ -#ifndef __RTMP_TYPE_H__ -#define __RTMP_TYPE_H__ - -#include - -#define PACKED __attribute__ ((packed)) - -typedef unsigned char BOOLEAN; - -typedef union _LARGE_INTEGER { - struct { - u32 LowPart; - int HighPart; - } u; - long long QuadPart; -} LARGE_INTEGER; - -/* */ -/* Register set pair for initialzation register set definition */ -/* */ -struct rt_rtmp_reg_pair { - unsigned long Register; - unsigned long Value; -}; - -struct rt_reg_pair { - u8 Register; - u8 Value; -}; - -/* */ -/* Register set pair for initialzation register set definition */ -/* */ -struct rt_rtmp_rf_regs { - u8 Channel; - unsigned long R1; - unsigned long R2; - unsigned long R3; - unsigned long R4; -}; - -struct rt_frequency_item { - u8 Channel; - u8 N; - u8 R; - u8 K; -}; - -#define STATUS_SUCCESS 0x00 -#define STATUS_UNSUCCESSFUL 0x01 - -#endif /* __RTMP_TYPE_H__ // */ diff --git a/trunk/drivers/staging/rt2860/rtusb_io.h b/trunk/drivers/staging/rt2860/rtusb_io.h deleted file mode 100644 index 64a2fe435284..000000000000 --- a/trunk/drivers/staging/rt2860/rtusb_io.h +++ /dev/null @@ -1,185 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* -*/ - -#ifndef __RTUSB_IO_H__ -#define __RTUSB_IO_H__ - -#include "rtmp_type.h" - -/* New for MeetingHouse Api support */ -#define CMDTHREAD_VENDOR_RESET 0x0D730101 /* cmd */ -#define CMDTHREAD_VENDOR_UNPLUG 0x0D730102 /* cmd */ -#define CMDTHREAD_VENDOR_SWITCH_FUNCTION 0x0D730103 /* cmd */ -#define CMDTHREAD_MULTI_WRITE_MAC 0x0D730107 /* cmd */ -#define CMDTHREAD_MULTI_READ_MAC 0x0D730108 /* cmd */ -#define CMDTHREAD_VENDOR_EEPROM_WRITE 0x0D73010A /* cmd */ -#define CMDTHREAD_VENDOR_EEPROM_READ 0x0D73010B /* cmd */ -#define CMDTHREAD_VENDOR_ENTER_TESTMODE 0x0D73010C /* cmd */ -#define CMDTHREAD_VENDOR_EXIT_TESTMODE 0x0D73010D /* cmd */ -#define CMDTHREAD_VENDOR_WRITE_BBP 0x0D730119 /* cmd */ -#define CMDTHREAD_VENDOR_READ_BBP 0x0D730118 /* cmd */ -#define CMDTHREAD_VENDOR_WRITE_RF 0x0D73011A /* cmd */ -#define CMDTHREAD_VENDOR_FLIP_IQ 0x0D73011D /* cmd */ -#define CMDTHREAD_RESET_BULK_OUT 0x0D730210 /* cmd */ -#define CMDTHREAD_RESET_BULK_IN 0x0D730211 /* cmd */ -#define CMDTHREAD_SET_PSM_BIT 0x0D730212 /* cmd */ -#define CMDTHREAD_SET_RADIO 0x0D730214 /* cmd */ -#define CMDTHREAD_UPDATE_TX_RATE 0x0D730216 /* cmd */ -#define CMDTHREAD_802_11_ADD_KEY_WEP 0x0D730218 /* cmd */ -#define CMDTHREAD_RESET_FROM_ERROR 0x0D73021A /* cmd */ -#define CMDTHREAD_LINK_DOWN 0x0D73021B /* cmd */ -#define CMDTHREAD_RESET_FROM_NDIS 0x0D73021C /* cmd */ -#define CMDTHREAD_CHECK_GPIO 0x0D730215 /* cmd */ -#define CMDTHREAD_FORCE_WAKE_UP 0x0D730222 /* cmd */ -#define CMDTHREAD_SET_BW 0x0D730225 /* cmd */ -#define CMDTHREAD_SET_ASIC_WCID 0x0D730226 /* cmd */ -#define CMDTHREAD_SET_ASIC_WCID_CIPHER 0x0D730227 /* cmd */ -#define CMDTHREAD_QKERIODIC_EXECUT 0x0D73023D /* cmd */ -#define RT_CMD_SET_KEY_TABLE 0x0D730228 /* cmd */ -#define RT_CMD_SET_RX_WCID_TABLE 0x0D730229 /* cmd */ -#define CMDTHREAD_SET_CLIENT_MAC_ENTRY 0x0D73023E /* cmd */ -#define CMDTHREAD_SET_GROUP_KEY 0x0D73023F /* cmd */ -#define CMDTHREAD_SET_PAIRWISE_KEY 0x0D730240 /* cmd */ - -#define CMDTHREAD_802_11_QUERY_HARDWARE_REGISTER 0x0D710105 /* cmd */ -#define CMDTHREAD_802_11_SET_PHY_MODE 0x0D79010C /* cmd */ -#define CMDTHREAD_802_11_SET_STA_CONFIG 0x0D790111 /* cmd */ -#define CMDTHREAD_802_11_SET_PREAMBLE 0x0D790101 /* cmd */ -#define CMDTHREAD_802_11_COUNTER_MEASURE 0x0D790102 /* cmd */ -/* add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */ -#define CMDTHREAD_UPDATE_PROTECT 0x0D790103 /* cmd */ -/* end johnli */ - -/*CMDTHREAD_MULTI_READ_MAC */ -/*CMDTHREAD_MULTI_WRITE_MAC */ -/*CMDTHREAD_VENDOR_EEPROM_READ */ -/*CMDTHREAD_VENDOR_EEPROM_WRITE */ -struct rt_cmdhandler_tlv { - u16 Offset; - u16 Length; - u8 DataFirst; -}; - -struct rt_cmdqelmt; - -struct rt_cmdqelmt { - u32 command; - void *buffer; - unsigned long bufferlength; - BOOLEAN CmdFromNdis; - BOOLEAN SetOperation; - struct rt_cmdqelmt *next; -}; - -struct rt_cmdq { - u32 size; - struct rt_cmdqelmt *head; - struct rt_cmdqelmt *tail; - u32 CmdQState; -}; - -#define EnqueueCmd(cmdq, cmdqelmt) \ -{ \ - if (cmdq->size == 0) \ - cmdq->head = cmdqelmt; \ - else \ - cmdq->tail->next = cmdqelmt; \ - cmdq->tail = cmdqelmt; \ - cmdqelmt->next = NULL; \ - cmdq->size++; \ -} - -/****************************************************************************** - - USB Cmd to ASIC Related MACRO - -******************************************************************************/ -/* reset MAC of a station entry to 0xFFFFFFFFFFFF */ -#define RTMP_STA_ENTRY_MAC_RESET(pAd, Wcid) \ - { struct rt_set_asic_wcid SetAsicWcid; \ - SetAsicWcid.WCID = Wcid; \ - SetAsicWcid.SetTid = 0xffffffff; \ - SetAsicWcid.DeleteTid = 0xffffffff; \ - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID, \ - &SetAsicWcid, sizeof(struct rt_set_asic_wcid)); } - -/* add this entry into ASIC RX WCID search table */ -#define RTMP_STA_ENTRY_ADD(pAd, pEntry) \ - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_CLIENT_MAC_ENTRY, \ - pEntry, sizeof(struct rt_mac_table_entry)); - -/* add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */ -/* Set MAC register value according operation mode */ -#define RTMP_UPDATE_PROTECT(pAd) \ - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_UPDATE_PROTECT, NULL, 0); -/* end johnli */ - -/* remove Pair-wise key material from ASIC */ -/* yet implement */ -#define RTMP_STA_ENTRY_KEY_DEL(pAd, BssIdx, Wcid) - -/* add Client security information into ASIC WCID table and IVEIV table */ -#define RTMP_STA_SECURITY_INFO_ADD(pAd, apidx, KeyID, pEntry) \ - { RTMP_STA_ENTRY_MAC_RESET(pAd, pEntry->Aid); \ - if (pEntry->Aid >= 1) { \ - struct rt_set_asic_wcid_attri SetAsicWcidAttri; \ - SetAsicWcidAttri.WCID = pEntry->Aid; \ - if ((pEntry->AuthMode <= Ndis802_11AuthModeAutoSwitch) && \ - (pEntry->WepStatus == Ndis802_11Encryption1Enabled)) \ - { \ - SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg; \ - } \ - else if (pEntry->AuthMode == Ndis802_11AuthModeWPANone) \ - { \ - SetAsicWcidAttri.Cipher = pAd->SharedKey[apidx][KeyID].CipherAlg; \ - } \ - else SetAsicWcidAttri.Cipher = 0; \ - DBGPRINT(RT_DEBUG_TRACE, ("aid cipher = %ld\n",SetAsicWcidAttri.Cipher)); \ - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_SET_ASIC_WCID_CIPHER, \ - &SetAsicWcidAttri, sizeof(struct rt_set_asic_wcid_attri)); } } - -/* Insert the BA bitmap to ASIC for the Wcid entry */ -#define RTMP_ADD_BA_SESSION_TO_ASIC(_pAd, _Aid, _TID) \ - do{ \ - struct rt_set_asic_wcid SetAsicWcid; \ - SetAsicWcid.WCID = (_Aid); \ - SetAsicWcid.SetTid = (0x10000<<(_TID)); \ - SetAsicWcid.DeleteTid = 0xffffffff; \ - RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(struct rt_set_asic_wcid)); \ - }while(0) - -/* Remove the BA bitmap from ASIC for the Wcid entry */ -#define RTMP_DEL_BA_SESSION_FROM_ASIC(_pAd, _Wcid, _TID) \ - do{ \ - struct rt_set_asic_wcid SetAsicWcid; \ - SetAsicWcid.WCID = (_Wcid); \ - SetAsicWcid.SetTid = (0xffffffff); \ - SetAsicWcid.DeleteTid = (0x10000<<(_TID) ); \ - RTUSBEnqueueInternalCmd((_pAd), CMDTHREAD_SET_ASIC_WCID, &SetAsicWcid, sizeof(struct rt_set_asic_wcid)); \ - }while(0) - -#endif /* __RTUSB_IO_H__ // */ diff --git a/trunk/drivers/staging/rt2860/spectrum.h b/trunk/drivers/staging/rt2860/spectrum.h deleted file mode 100644 index 4c325ba7ba21..000000000000 --- a/trunk/drivers/staging/rt2860/spectrum.h +++ /dev/null @@ -1,189 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - */ - -#ifndef __SPECTRUM_H__ -#define __SPECTRUM_H__ - -#include "rtmp_type.h" -#include "spectrum_def.h" - -char RTMP_GetTxPwr(struct rt_rtmp_adapter *pAd, IN HTTRANSMIT_SETTING HTTxMode); - -/* - ========================================================================== - Description: - Prepare Measurement request action frame and enqueue it into - management queue waiting for transmission. - - Parametrs: - 1. the destination mac address of the frame. - - Return : None. - ========================================================================== - */ -void MakeMeasurementReqFrame(struct rt_rtmp_adapter *pAd, - u8 *pOutBuffer, - unsigned long *pFrameLen, - u8 TotalLen, - u8 Category, - u8 Action, - u8 MeasureToken, - u8 MeasureReqMode, - u8 MeasureReqType, - u8 NumOfRepetitions); - -/* - ========================================================================== - Description: - Prepare Measurement report action frame and enqueue it into - management queue waiting for transmission. - - Parametrs: - 1. the destination mac address of the frame. - - Return : None. - ========================================================================== - */ -void EnqueueMeasurementRep(struct rt_rtmp_adapter *pAd, - u8 *pDA, - u8 DialogToken, - u8 MeasureToken, - u8 MeasureReqMode, - u8 MeasureReqType, - u8 ReportInfoLen, u8 *pReportInfo); - -/* - ========================================================================== - Description: - Prepare TPC Request action frame and enqueue it into - management queue waiting for transmission. - - Parametrs: - 1. the destination mac address of the frame. - - Return : None. - ========================================================================== - */ -void EnqueueTPCReq(struct rt_rtmp_adapter *pAd, u8 *pDA, u8 DialogToken); - -/* - ========================================================================== - Description: - Prepare TPC Report action frame and enqueue it into - management queue waiting for transmission. - - Parametrs: - 1. the destination mac address of the frame. - - Return : None. - ========================================================================== - */ -void EnqueueTPCRep(struct rt_rtmp_adapter *pAd, - u8 *pDA, - u8 DialogToken, u8 TxPwr, u8 LinkMargin); - -/* - ========================================================================== - Description: - Prepare Channel Switch Announcement action frame and enqueue it into - management queue waiting for transmission. - - Parametrs: - 1. the destination mac address of the frame. - 2. Channel switch announcement mode. - 2. a New selected channel. - - Return : None. - ========================================================================== - */ -void EnqueueChSwAnn(struct rt_rtmp_adapter *pAd, - u8 *pDA, u8 ChSwMode, u8 NewCh); - -/* - ========================================================================== - Description: - Spectrun action frames Handler such as channel switch announcement, - measurement report, measurement request actions frames. - - Parametrs: - Elme - MLME message containing the received frame - - Return : None. - ========================================================================== - */ -void PeerSpectrumAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem); - -/* - ========================================================================== - Description: - - Parametrs: - - Return : None. - ========================================================================== - */ -int Set_MeasureReq_Proc(struct rt_rtmp_adapter *pAd, char *arg); - -int Set_TpcReq_Proc(struct rt_rtmp_adapter *pAd, char *arg); - -int Set_PwrConstraint(struct rt_rtmp_adapter *pAd, char *arg); - -void MeasureReqTabInit(struct rt_rtmp_adapter *pAd); - -void MeasureReqTabExit(struct rt_rtmp_adapter *pAd); - -struct rt_measure_req_entry *MeasureReqLookUp(struct rt_rtmp_adapter *pAd, u8 DialogToken); - -struct rt_measure_req_entry *MeasureReqInsert(struct rt_rtmp_adapter *pAd, u8 DialogToken); - -void MeasureReqDelete(struct rt_rtmp_adapter *pAd, u8 DialogToken); - -void InsertChannelRepIE(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, - char *pCountry, u8 RegulatoryClass); - -void InsertTpcReportIE(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, - u8 TxPwr, u8 LinkMargin); - -void InsertDialogToken(struct rt_rtmp_adapter *pAd, - u8 *pFrameBuf, - unsigned long *pFrameLen, u8 DialogToken); - -void TpcReqTabInit(struct rt_rtmp_adapter *pAd); - -void TpcReqTabExit(struct rt_rtmp_adapter *pAd); - -void NotifyChSwAnnToPeerAPs(struct rt_rtmp_adapter *pAd, - u8 *pRA, - u8 *pTA, u8 ChSwMode, u8 Channel); - -void RguClass_BuildBcnChList(struct rt_rtmp_adapter *pAd, - u8 *pBuf, unsigned long *pBufLen); -#endif /* __SPECTRUM_H__ // */ diff --git a/trunk/drivers/staging/rt2860/spectrum_def.h b/trunk/drivers/staging/rt2860/spectrum_def.h deleted file mode 100644 index 8ffcfb0d04f8..000000000000 --- a/trunk/drivers/staging/rt2860/spectrum_def.h +++ /dev/null @@ -1,202 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - spectrum_def.h - - Abstract: - Handle association related requests either from WSTA or from local MLME - - Revision History: - Who When What - --------- ---------- ---------------------------------------------- - Fonchi Wu 2008 created for 802.11h - */ - -#ifndef __SPECTRUM_DEF_H__ -#define __SPECTRUM_DEF_H__ - -#define MAX_MEASURE_REQ_TAB_SIZE 32 -#define MAX_HASH_MEASURE_REQ_TAB_SIZE MAX_MEASURE_REQ_TAB_SIZE - -#define MAX_TPC_REQ_TAB_SIZE 32 -#define MAX_HASH_TPC_REQ_TAB_SIZE MAX_TPC_REQ_TAB_SIZE - -#define MIN_RCV_PWR 100 /* Negative value ((dBm) */ - -#define TPC_REQ_AGE_OUT 500 /* ms */ -#define MQ_REQ_AGE_OUT 500 /* ms */ - -#define TPC_DIALOGTOKEN_HASH_INDEX(_DialogToken) ((_DialogToken) % MAX_HASH_TPC_REQ_TAB_SIZE) -#define MQ_DIALOGTOKEN_HASH_INDEX(_DialogToken) ((_DialogToken) % MAX_MEASURE_REQ_TAB_SIZE) - -struct rt_measure_req_entry; - -struct rt_measure_req_entry { - struct rt_measure_req_entry *pNext; - unsigned long lastTime; - BOOLEAN Valid; - u8 DialogToken; - u8 MeasureDialogToken[3]; /* 0:basic measure, 1: CCA measure, 2: RPI_Histogram measure. */ -}; - -struct rt_measure_req_tab { - u8 Size; - struct rt_measure_req_entry *Hash[MAX_HASH_MEASURE_REQ_TAB_SIZE]; - struct rt_measure_req_entry Content[MAX_MEASURE_REQ_TAB_SIZE]; -}; - -struct rt_tpc_req_entry; - -struct rt_tpc_req_entry { - struct rt_tpc_req_entry *pNext; - unsigned long lastTime; - BOOLEAN Valid; - u8 DialogToken; -}; - -struct rt_tpc_req_tab { - u8 Size; - struct rt_tpc_req_entry *Hash[MAX_HASH_TPC_REQ_TAB_SIZE]; - struct rt_tpc_req_entry Content[MAX_TPC_REQ_TAB_SIZE]; -}; - -/* The regulatory information */ -struct rt_dot11_channel_set { - u8 NumberOfChannels; - u8 MaxTxPwr; - u8 ChannelList[16]; -}; - -struct rt_dot11_regulatory_information { - u8 RegulatoryClass; - struct rt_dot11_channel_set ChannelSet; -}; - -#define RM_TPC_REQ 0 -#define RM_MEASURE_REQ 1 - -#define RM_BASIC 0 -#define RM_CCA 1 -#define RM_RPI_HISTOGRAM 2 -#define RM_CH_LOAD 3 -#define RM_NOISE_HISTOGRAM 4 - -struct PACKED rt_tpc_report_info { - u8 TxPwr; - u8 LinkMargin; -}; - -struct PACKED rt_ch_sw_ann_info { - u8 ChSwMode; - u8 Channel; - u8 ChSwCnt; -}; - -typedef union PACKED _MEASURE_REQ_MODE { - struct PACKED { - u8 Parallel:1; - u8 Enable:1; - u8 Request:1; - u8 Report:1; - u8 DurationMandatory:1; - u8:3; - } field; - u8 word; -} MEASURE_REQ_MODE, *PMEASURE_REQ_MODE; - -struct PACKED rt_measure_req { - u8 ChNum; - u64 MeasureStartTime; - u16 MeasureDuration; -}; - -struct PACKED rt_measure_req_info { - u8 Token; - MEASURE_REQ_MODE ReqMode; - u8 ReqType; - u8 Oct[0]; -}; - -typedef union PACKED _MEASURE_BASIC_REPORT_MAP { - struct PACKED { - u8 BSS:1; - - u8 OfdmPreamble:1; - u8 UnidentifiedSignal:1; - u8 Radar:1; - u8 Unmeasure:1; - u8 Rev:3; - } field; - u8 word; -} MEASURE_BASIC_REPORT_MAP, *PMEASURE_BASIC_REPORT_MAP; - -struct PACKED rt_measure_basic_report { - u8 ChNum; - u64 MeasureStartTime; - u16 MeasureDuration; - MEASURE_BASIC_REPORT_MAP Map; -}; - -struct PACKED rt_measure_cca_report { - u8 ChNum; - u64 MeasureStartTime; - u16 MeasureDuration; - u8 CCA_Busy_Fraction; -}; - -struct PACKED rt_measure_rpi_report { - u8 ChNum; - u64 MeasureStartTime; - u16 MeasureDuration; - u8 RPI_Density[8]; -}; - -typedef union PACKED _MEASURE_REPORT_MODE { - struct PACKED { - u8 Late:1; - u8 Incapable:1; - u8 Refused:1; - u8 Rev:5; - } field; - u8 word; -} MEASURE_REPORT_MODE, *PMEASURE_REPORT_MODE; - -struct PACKED rt_measure_report_info { - u8 Token; - u8 ReportMode; - u8 ReportType; - u8 Octect[0]; -}; - -struct PACKED rt_quiet_info { - u8 QuietCnt; - u8 QuietPeriod; - u16 QuietDuration; - u16 QuietOffset; -}; - -#endif /* __SPECTRUM_DEF_H__ // */ diff --git a/trunk/drivers/staging/rt2860/sta/assoc.c b/trunk/drivers/staging/rt2860/sta/assoc.c deleted file mode 100644 index 59e931c3190d..000000000000 --- a/trunk/drivers/staging/rt2860/sta/assoc.c +++ /dev/null @@ -1,1602 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - assoc.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - John 2004-9-3 porting from RT2500 - Justin P. Mattock 11/07/2010 Fix typos -*/ -#include "../rt_config.h" - -u8 CipherWpaTemplate[] = { - 0xdd, /* WPA IE */ - 0x16, /* Length */ - 0x00, 0x50, 0xf2, 0x01, /* oui */ - 0x01, 0x00, /* Version */ - 0x00, 0x50, 0xf2, 0x02, /* Multicast */ - 0x01, 0x00, /* Number of unicast */ - 0x00, 0x50, 0xf2, 0x02, /* unicast */ - 0x01, 0x00, /* number of authentication method */ - 0x00, 0x50, 0xf2, 0x01 /* authentication */ -}; - -u8 CipherWpa2Template[] = { - 0x30, /* RSN IE */ - 0x14, /* Length */ - 0x01, 0x00, /* Version */ - 0x00, 0x0f, 0xac, 0x02, /* group cipher, TKIP */ - 0x01, 0x00, /* number of pairwise */ - 0x00, 0x0f, 0xac, 0x02, /* unicast */ - 0x01, 0x00, /* number of authentication method */ - 0x00, 0x0f, 0xac, 0x02, /* authentication */ - 0x00, 0x00, /* RSN capability */ -}; - -u8 Ccx2IeInfo[] = { 0x00, 0x40, 0x96, 0x03, 0x02 }; - -/* - ========================================================================== - Description: - association state machine init, including state transition and timer init - Parameters: - S - pointer to the association state machine - - IRQL = PASSIVE_LEVEL - - ========================================================================== - */ -void AssocStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[]) -{ - StateMachineInit(S, Trans, MAX_ASSOC_STATE, MAX_ASSOC_MSG, - (STATE_MACHINE_FUNC) Drop, ASSOC_IDLE, - ASSOC_MACHINE_BASE); - - /* first column */ - StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_ASSOC_REQ, - (STATE_MACHINE_FUNC) MlmeAssocReqAction); - StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_REASSOC_REQ, - (STATE_MACHINE_FUNC) MlmeReassocReqAction); - StateMachineSetAction(S, ASSOC_IDLE, MT2_MLME_DISASSOC_REQ, - (STATE_MACHINE_FUNC) MlmeDisassocReqAction); - StateMachineSetAction(S, ASSOC_IDLE, MT2_PEER_DISASSOC_REQ, - (STATE_MACHINE_FUNC) PeerDisassocAction); - - /* second column */ - StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenAssoc); - StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenReassoc); - StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, - (STATE_MACHINE_FUNC) - InvalidStateWhenDisassociate); - StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, - (STATE_MACHINE_FUNC) PeerDisassocAction); - StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, - (STATE_MACHINE_FUNC) PeerAssocRspAction); - /* */ - /* Patch 3Com AP MOde:3CRWE454G72 */ - /* We send Assoc request frame to this AP, it always send Reassoc Rsp not Associate Rsp. */ - /* */ - StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, - (STATE_MACHINE_FUNC) PeerAssocRspAction); - StateMachineSetAction(S, ASSOC_WAIT_RSP, MT2_ASSOC_TIMEOUT, - (STATE_MACHINE_FUNC) AssocTimeoutAction); - - /* third column */ - StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenAssoc); - StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenReassoc); - StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, - (STATE_MACHINE_FUNC) - InvalidStateWhenDisassociate); - StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, - (STATE_MACHINE_FUNC) PeerDisassocAction); - StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_REASSOC_RSP, - (STATE_MACHINE_FUNC) PeerReassocRspAction); - /* */ - /* Patch, AP doesn't send Reassociate Rsp frame to Station. */ - /* */ - StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_PEER_ASSOC_RSP, - (STATE_MACHINE_FUNC) PeerReassocRspAction); - StateMachineSetAction(S, REASSOC_WAIT_RSP, MT2_REASSOC_TIMEOUT, - (STATE_MACHINE_FUNC) ReassocTimeoutAction); - - /* fourth column */ - StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_ASSOC_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenAssoc); - StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_REASSOC_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenReassoc); - StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_MLME_DISASSOC_REQ, - (STATE_MACHINE_FUNC) - InvalidStateWhenDisassociate); - StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_PEER_DISASSOC_REQ, - (STATE_MACHINE_FUNC) PeerDisassocAction); - StateMachineSetAction(S, DISASSOC_WAIT_RSP, MT2_DISASSOC_TIMEOUT, - (STATE_MACHINE_FUNC) DisassocTimeoutAction); - - /* initialize the timer */ - RTMPInitTimer(pAd, &pAd->MlmeAux.AssocTimer, - GET_TIMER_FUNCTION(AssocTimeout), pAd, FALSE); - RTMPInitTimer(pAd, &pAd->MlmeAux.ReassocTimer, - GET_TIMER_FUNCTION(ReassocTimeout), pAd, FALSE); - RTMPInitTimer(pAd, &pAd->MlmeAux.DisassocTimer, - GET_TIMER_FUNCTION(DisassocTimeout), pAd, FALSE); -} - -/* - ========================================================================== - Description: - Association timeout procedure. After association timeout, this function - will be called and it will put a message into the MLME queue - Parameters: - Standard timer parameters - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AssocTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_ASSOC_TIMEOUT, 0, NULL); - RTMP_MLME_HANDLER(pAd); -} - -/* - ========================================================================== - Description: - Reassociation timeout procedure. After reassociation timeout, this - function will be called and put a message into the MLME queue - Parameters: - Standard timer parameters - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void ReassocTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_REASSOC_TIMEOUT, 0, NULL); - RTMP_MLME_HANDLER(pAd); -} - -/* - ========================================================================== - Description: - Disassociation timeout procedure. After disassociation timeout, this - function will be called and put a message into the MLME queue - Parameters: - Standard timer parameters - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void DisassocTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_DISASSOC_TIMEOUT, 0, NULL); - RTMP_MLME_HANDLER(pAd); -} - -/* - ========================================================================== - Description: - mlme assoc req handling procedure - Parameters: - Adapter - Adapter pointer - Elem - MLME Queue Element - Pre: - the station has been authenticated and the following information is stored in the config - -# SSID - -# supported rates and their length - -# listen interval (Adapter->StaCfg.default_listen_count) - -# Transmit power (Adapter->StaCfg.tx_power) - Post : - -# An association request frame is generated and sent to the air - -# Association timer starts - -# Association state -> ASSOC_WAIT_RSP - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void MlmeAssocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 ApAddr[6]; - struct rt_header_802_11 AssocHdr; - u8 WmeIe[9] = - { IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, - 0x00 }; - u16 ListenIntv; - unsigned long Timeout; - u16 CapabilityInfo; - BOOLEAN TimerCancelled; - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen = 0; - unsigned long tmp; - u16 VarIesOffset; - u16 Status; - - /* Block all authentication request during WPA block period */ - if (pAd->StaCfg.bBlockAssoc == TRUE) { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - Block Assoc request during WPA block period!\n")); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_STATE_MACHINE_REJECT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, - &Status); - } - /* check sanity first */ - else if (MlmeAssocReqSanity - (pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, - &Timeout, &ListenIntv)) { - RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, &TimerCancelled); - COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr); - - /* Get an unused nonpaged memory */ - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - MlmeAssocReqAction() allocate memory failed \n")); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_FAIL_NO_RESOURCE; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, - MT2_ASSOC_CONF, 2, &Status); - return; - } - /* Add by James 03/06/27 */ - pAd->StaCfg.AssocInfo.Length = - sizeof(struct rt_ndis_802_11_association_information); - /* Association don't need to report MAC address */ - pAd->StaCfg.AssocInfo.AvailableRequestFixedIEs = - NDIS_802_11_AI_REQFI_CAPABILITIES | - NDIS_802_11_AI_REQFI_LISTENINTERVAL; - pAd->StaCfg.AssocInfo.RequestFixedIEs.Capabilities = - CapabilityInfo; - pAd->StaCfg.AssocInfo.RequestFixedIEs.ListenInterval = - ListenIntv; - /* Only reassociate need this */ - /*COPY_MAC_ADDR(pAd->StaCfg.AssocInfo.RequestFixedIEs.CurrentAPAddress, ApAddr); */ - pAd->StaCfg.AssocInfo.OffsetRequestIEs = - sizeof(struct rt_ndis_802_11_association_information); - - NdisZeroMemory(pAd->StaCfg.ReqVarIEs, MAX_VIE_LEN); - /* First add SSID */ - VarIesOffset = 0; - NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SsidIe, - 1); - VarIesOffset += 1; - NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, - &pAd->MlmeAux.SsidLen, 1); - VarIesOffset += 1; - NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, - pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen); - VarIesOffset += pAd->MlmeAux.SsidLen; - - /* Second add Supported rates */ - NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, &SupRateIe, - 1); - VarIesOffset += 1; - NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, - &pAd->MlmeAux.SupRateLen, 1); - VarIesOffset += 1; - NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, - pAd->MlmeAux.SupRate, pAd->MlmeAux.SupRateLen); - VarIesOffset += pAd->MlmeAux.SupRateLen; - /* End Add by James */ - - if ((pAd->CommonCfg.Channel > 14) && - (pAd->CommonCfg.bIEEE80211H == TRUE)) - CapabilityInfo |= 0x0100; - - DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - Send ASSOC request...\n")); - MgtMacHeaderInit(pAd, &AssocHdr, SUBTYPE_ASSOC_REQ, 0, ApAddr, - ApAddr); - - /* Build basic frame first */ - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_header_802_11), &AssocHdr, - 2, &CapabilityInfo, - 2, &ListenIntv, - 1, &SsidIe, - 1, &pAd->MlmeAux.SsidLen, - pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid, - 1, &SupRateIe, - 1, &pAd->MlmeAux.SupRateLen, - pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate, - END_OF_ARGS); - - if (pAd->MlmeAux.ExtRateLen != 0) { - MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp, - 1, &ExtRateIe, - 1, &pAd->MlmeAux.ExtRateLen, - pAd->MlmeAux.ExtRateLen, - pAd->MlmeAux.ExtRate, END_OF_ARGS); - FrameLen += tmp; - } - /* HT */ - if ((pAd->MlmeAux.HtCapabilityLen > 0) - && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) { - unsigned long TmpLen; - u8 HtLen; - u8 BROADCOM[4] = { 0x0, 0x90, 0x4c, 0x33 }; - if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE) { - HtLen = SIZE_HT_CAP_IE + 4; - MakeOutgoingFrame(pOutBuffer + FrameLen, - &TmpLen, 1, &WpaIe, 1, &HtLen, - 4, &BROADCOM[0], - pAd->MlmeAux.HtCapabilityLen, - &pAd->MlmeAux.HtCapability, - END_OF_ARGS); - } else { - MakeOutgoingFrame(pOutBuffer + FrameLen, - &TmpLen, 1, &HtCapIe, 1, - &pAd->MlmeAux.HtCapabilityLen, - pAd->MlmeAux.HtCapabilityLen, - &pAd->MlmeAux.HtCapability, - END_OF_ARGS); - } - FrameLen += TmpLen; - } - /* add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION */ - /* Case I: (Aggregation + Piggy-Back) */ - /* 1. user enable aggregation, AND */ - /* 2. Mac support piggy-back */ - /* 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON */ - /* Case II: (Aggregation) */ - /* 1. user enable aggregation, AND */ - /* 2. AP annouces it's AGGREGATION-capable in BEACON */ - if (pAd->CommonCfg.bAggregationCapable) { - if ((pAd->CommonCfg.bPiggyBackCapable) - && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)) { - unsigned long TmpLen; - u8 RalinkIe[9] = - { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, - 0x03, 0x00, 0x00, 0x00 }; - MakeOutgoingFrame(pOutBuffer + FrameLen, - &TmpLen, 9, RalinkIe, - END_OF_ARGS); - FrameLen += TmpLen; - } else if (pAd->MlmeAux.APRalinkIe & 0x00000001) { - unsigned long TmpLen; - u8 RalinkIe[9] = - { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, - 0x01, 0x00, 0x00, 0x00 }; - MakeOutgoingFrame(pOutBuffer + FrameLen, - &TmpLen, 9, RalinkIe, - END_OF_ARGS); - FrameLen += TmpLen; - } - } else { - unsigned long TmpLen; - u8 RalinkIe[9] = - { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x06, - 0x00, 0x00, 0x00 }; - MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen, 9, - RalinkIe, END_OF_ARGS); - FrameLen += TmpLen; - } - - if (pAd->MlmeAux.APEdcaParm.bValid) { - if (pAd->CommonCfg.bAPSDCapable - && pAd->MlmeAux.APEdcaParm.bAPSDCapable) { - struct rt_qbss_sta_info_parm QosInfo; - - NdisZeroMemory(&QosInfo, - sizeof(struct rt_qbss_sta_info_parm)); - QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE; - QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK; - QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI; - QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO; - QosInfo.MaxSPLength = - pAd->CommonCfg.MaxSPLength; - WmeIe[8] |= *(u8 *)& QosInfo; - } else { - /* The Parameter Set Count is set to ¡§0¡¨ in the association request frames */ - /* WmeIe[8] |= (pAd->MlmeAux.APEdcaParm.EdcaUpdateCount & 0x0f); */ - } - - MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp, - 9, &WmeIe[0], END_OF_ARGS); - FrameLen += tmp; - } - /* */ - /* Let WPA(#221) Element ID on the end of this association frame. */ - /* Otherwise some AP will fail on parsing Element ID and set status fail on Assoc Rsp. */ - /* For example: Put Vendor Specific IE on the front of WPA IE. */ - /* This happens on AP (Model No:Linksys WRK54G) */ - /* */ - if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) - ) - ) { - u8 RSNIe = IE_WPA; - - if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) - || (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA2)) { - RSNIe = IE_WPA2; - } - - if ((pAd->StaCfg.WpaSupplicantUP != - WPA_SUPPLICANT_ENABLE) - && (pAd->StaCfg.bRSN_IE_FromWpaSupplicant == FALSE)) - RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, - pAd->StaCfg.WepStatus, BSS0); - - /* Check for WPA PMK cache list */ - if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) { - int idx; - BOOLEAN FoundPMK = FALSE; - /* Search chched PMKID, append it if existed */ - for (idx = 0; idx < PMKID_NO; idx++) { - if (NdisEqualMemory - (ApAddr, - &pAd->StaCfg.SavedPMK[idx].BSSID, - 6)) { - FoundPMK = TRUE; - break; - } - } - if (FoundPMK) { - /* Set PMK number */ - *(u16 *)& pAd->StaCfg.RSN_IE[pAd-> - StaCfg. - RSNIE_Len] - = 1; - NdisMoveMemory(&pAd->StaCfg. - RSN_IE[pAd->StaCfg. - RSNIE_Len + 2], - &pAd->StaCfg. - SavedPMK[idx].PMKID, 16); - pAd->StaCfg.RSNIE_Len += 18; - } - } - - if ((pAd->StaCfg.WpaSupplicantUP == - WPA_SUPPLICANT_ENABLE) - && (pAd->StaCfg.bRSN_IE_FromWpaSupplicant == - TRUE)) { - MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp, - pAd->StaCfg.RSNIE_Len, - pAd->StaCfg.RSN_IE, - END_OF_ARGS); - } else { - MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp, - 1, &RSNIe, - 1, &pAd->StaCfg.RSNIE_Len, - pAd->StaCfg.RSNIE_Len, - pAd->StaCfg.RSN_IE, - END_OF_ARGS); - } - - FrameLen += tmp; - - if ((pAd->StaCfg.WpaSupplicantUP != - WPA_SUPPLICANT_ENABLE) - || (pAd->StaCfg.bRSN_IE_FromWpaSupplicant == - FALSE)) { - /* Append Variable IE */ - NdisMoveMemory(pAd->StaCfg.ReqVarIEs + - VarIesOffset, &RSNIe, 1); - VarIesOffset += 1; - NdisMoveMemory(pAd->StaCfg.ReqVarIEs + - VarIesOffset, - &pAd->StaCfg.RSNIE_Len, 1); - VarIesOffset += 1; - } - NdisMoveMemory(pAd->StaCfg.ReqVarIEs + VarIesOffset, - pAd->StaCfg.RSN_IE, - pAd->StaCfg.RSNIE_Len); - VarIesOffset += pAd->StaCfg.RSNIE_Len; - - /* Set Variable IEs Length */ - pAd->StaCfg.ReqVarIELen = VarIesOffset; - } - - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - RTMPSetTimer(&pAd->MlmeAux.AssocTimer, Timeout); - pAd->Mlme.AssocMachine.CurrState = ASSOC_WAIT_RSP; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - MlmeAssocReqAction() sanity check failed. BUG!\n")); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_INVALID_FORMAT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, - &Status); - } - -} - -/* - ========================================================================== - Description: - mlme reassoc req handling procedure - Parameters: - Elem - - Pre: - -# SSID (Adapter->StaCfg.ssid[]) - -# BSSID (AP address, Adapter->StaCfg.bssid) - -# Supported rates (Adapter->StaCfg.supported_rates[]) - -# Supported rates length (Adapter->StaCfg.supported_rates_len) - -# Tx power (Adapter->StaCfg.tx_power) - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void MlmeReassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 ApAddr[6]; - struct rt_header_802_11 ReassocHdr; - u8 WmeIe[9] = - { IE_VENDOR_SPECIFIC, 0x07, 0x00, 0x50, 0xf2, 0x02, 0x00, 0x01, - 0x00 }; - u16 CapabilityInfo, ListenIntv; - unsigned long Timeout; - unsigned long FrameLen = 0; - BOOLEAN TimerCancelled; - int NStatus; - unsigned long tmp; - u8 *pOutBuffer = NULL; - u16 Status; - - /* Block all authentication request during WPA block period */ - if (pAd->StaCfg.bBlockAssoc == TRUE) { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - Block ReAssoc request during WPA block period!\n")); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_STATE_MACHINE_REJECT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, - &Status); - } - /* the parameters are the same as the association */ - else if (MlmeAssocReqSanity - (pAd, Elem->Msg, Elem->MsgLen, ApAddr, &CapabilityInfo, - &Timeout, &ListenIntv)) { - RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, &TimerCancelled); - - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - MlmeReassocReqAction() allocate memory failed \n")); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_FAIL_NO_RESOURCE; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, - MT2_REASSOC_CONF, 2, &Status); - return; - } - - COPY_MAC_ADDR(pAd->MlmeAux.Bssid, ApAddr); - - /* make frame, use bssid as the AP address?? */ - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - Send RE-ASSOC request...\n")); - MgtMacHeaderInit(pAd, &ReassocHdr, SUBTYPE_REASSOC_REQ, 0, - ApAddr, ApAddr); - MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11), - &ReassocHdr, 2, &CapabilityInfo, 2, - &ListenIntv, MAC_ADDR_LEN, ApAddr, 1, &SsidIe, - 1, &pAd->MlmeAux.SsidLen, - pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid, 1, - &SupRateIe, 1, &pAd->MlmeAux.SupRateLen, - pAd->MlmeAux.SupRateLen, pAd->MlmeAux.SupRate, - END_OF_ARGS); - - if (pAd->MlmeAux.ExtRateLen != 0) { - MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp, - 1, &ExtRateIe, - 1, &pAd->MlmeAux.ExtRateLen, - pAd->MlmeAux.ExtRateLen, - pAd->MlmeAux.ExtRate, END_OF_ARGS); - FrameLen += tmp; - } - - if (pAd->MlmeAux.APEdcaParm.bValid) { - if (pAd->CommonCfg.bAPSDCapable - && pAd->MlmeAux.APEdcaParm.bAPSDCapable) { - struct rt_qbss_sta_info_parm QosInfo; - - NdisZeroMemory(&QosInfo, - sizeof(struct rt_qbss_sta_info_parm)); - QosInfo.UAPSD_AC_BE = pAd->CommonCfg.bAPSDAC_BE; - QosInfo.UAPSD_AC_BK = pAd->CommonCfg.bAPSDAC_BK; - QosInfo.UAPSD_AC_VI = pAd->CommonCfg.bAPSDAC_VI; - QosInfo.UAPSD_AC_VO = pAd->CommonCfg.bAPSDAC_VO; - QosInfo.MaxSPLength = - pAd->CommonCfg.MaxSPLength; - WmeIe[8] |= *(u8 *)& QosInfo; - } - - MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp, - 9, &WmeIe[0], END_OF_ARGS); - FrameLen += tmp; - } - /* HT */ - if ((pAd->MlmeAux.HtCapabilityLen > 0) - && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) { - unsigned long TmpLen; - u8 HtLen; - u8 BROADCOM[4] = { 0x0, 0x90, 0x4c, 0x33 }; - if (pAd->StaActive.SupportedPhyInfo.bPreNHt == TRUE) { - HtLen = SIZE_HT_CAP_IE + 4; - MakeOutgoingFrame(pOutBuffer + FrameLen, - &TmpLen, 1, &WpaIe, 1, &HtLen, - 4, &BROADCOM[0], - pAd->MlmeAux.HtCapabilityLen, - &pAd->MlmeAux.HtCapability, - END_OF_ARGS); - } else { - MakeOutgoingFrame(pOutBuffer + FrameLen, - &TmpLen, 1, &HtCapIe, 1, - &pAd->MlmeAux.HtCapabilityLen, - pAd->MlmeAux.HtCapabilityLen, - &pAd->MlmeAux.HtCapability, - END_OF_ARGS); - } - FrameLen += TmpLen; - } - /* add Ralink proprietary IE to inform AP this STA is going to use AGGREGATION or PIGGY-BACK+AGGREGATION */ - /* Case I: (Aggregation + Piggy-Back) */ - /* 1. user enable aggregation, AND */ - /* 2. Mac support piggy-back */ - /* 3. AP annouces it's PIGGY-BACK+AGGREGATION-capable in BEACON */ - /* Case II: (Aggregation) */ - /* 1. user enable aggregation, AND */ - /* 2. AP annouces it's AGGREGATION-capable in BEACON */ - if (pAd->CommonCfg.bAggregationCapable) { - if ((pAd->CommonCfg.bPiggyBackCapable) - && ((pAd->MlmeAux.APRalinkIe & 0x00000003) == 3)) { - unsigned long TmpLen; - u8 RalinkIe[9] = - { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, - 0x03, 0x00, 0x00, 0x00 }; - MakeOutgoingFrame(pOutBuffer + FrameLen, - &TmpLen, 9, RalinkIe, - END_OF_ARGS); - FrameLen += TmpLen; - } else if (pAd->MlmeAux.APRalinkIe & 0x00000001) { - unsigned long TmpLen; - u8 RalinkIe[9] = - { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, - 0x01, 0x00, 0x00, 0x00 }; - MakeOutgoingFrame(pOutBuffer + FrameLen, - &TmpLen, 9, RalinkIe, - END_OF_ARGS); - FrameLen += TmpLen; - } - } else { - unsigned long TmpLen; - u8 RalinkIe[9] = - { IE_VENDOR_SPECIFIC, 7, 0x00, 0x0c, 0x43, 0x04, - 0x00, 0x00, 0x00 }; - MakeOutgoingFrame(pOutBuffer + FrameLen, &TmpLen, 9, - RalinkIe, END_OF_ARGS); - FrameLen += TmpLen; - } - - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - RTMPSetTimer(&pAd->MlmeAux.ReassocTimer, Timeout); /* in mSec */ - pAd->Mlme.AssocMachine.CurrState = REASSOC_WAIT_RSP; - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - MlmeReassocReqAction() sanity check failed. BUG!\n")); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_INVALID_FORMAT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, - &Status); - } -} - -/* - ========================================================================== - Description: - Upper layer issues disassoc request - Parameters: - Elem - - - IRQL = PASSIVE_LEVEL - - ========================================================================== - */ -void MlmeDisassocReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_mlme_disassoc_req *pDisassocReq; - struct rt_header_802_11 DisassocHdr; - struct rt_header_802_11 * pDisassocHdr; - u8 *pOutBuffer = NULL; - unsigned long FrameLen = 0; - int NStatus; - BOOLEAN TimerCancelled; - unsigned long Timeout = 500; - u16 Status; - - /* skip sanity check */ - pDisassocReq = (struct rt_mlme_disassoc_req *)(Elem->Msg); - - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - MlmeDisassocReqAction() allocate memory failed\n")); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_FAIL_NO_RESOURCE; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, - &Status); - return; - } - - RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &TimerCancelled); - - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - Send DISASSOC request[BSSID::%pM (Reason=%d)\n", - pDisassocReq->Addr, pDisassocReq->Reason)); - MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pDisassocReq->Addr, pDisassocReq->Addr); /* patch peap ttls switching issue */ - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_header_802_11), &DisassocHdr, - 2, &pDisassocReq->Reason, END_OF_ARGS); - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - - /* To patch Instance and Buffalo(N) AP */ - /* Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine */ - /* Therefore, we send both of them. */ - pDisassocHdr = (struct rt_header_802_11 *) pOutBuffer; - pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH; - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - - MlmeFreeMemory(pAd, pOutBuffer); - - pAd->StaCfg.DisassocReason = REASON_DISASSOC_STA_LEAVING; - COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pDisassocReq->Addr); - - RTMPSetTimer(&pAd->MlmeAux.DisassocTimer, Timeout); /* in mSec */ - pAd->Mlme.AssocMachine.CurrState = DISASSOC_WAIT_RSP; - - RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL, 0); - -} - -/* - ========================================================================== - Description: - peer sends assoc rsp back - Parameters: - Elme - MLME message containing the received frame - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void PeerAssocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 CapabilityInfo, Status, Aid; - u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen; - u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen; - u8 Addr2[MAC_ADDR_LEN]; - BOOLEAN TimerCancelled; - u8 CkipFlag; - struct rt_edca_parm EdcaParm; - struct rt_ht_capability_ie HtCapability; - struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */ - u8 HtCapabilityLen = 0; - u8 AddHtInfoLen; - u8 NewExtChannelOffset = 0xff; - - if (PeerAssocRspSanity - (pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status, - &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen, &HtCapability, - &AddHtInfo, &HtCapabilityLen, &AddHtInfoLen, &NewExtChannelOffset, - &EdcaParm, &CkipFlag)) { - /* The frame is for me ? */ - if (MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid)) { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerAssocRspAction():ASSOC - receive ASSOC_RSP to me (status=%d)\n", - Status)); - DBGPRINT(RT_DEBUG_TRACE, - ("PeerAssocRspAction():MacTable [%d].AMsduSize = %d. ClientStatusFlags = 0x%lx \n", - Elem->Wcid, - pAd->MacTab.Content[BSSID_WCID].AMsduSize, - pAd->MacTab.Content[BSSID_WCID]. - ClientStatusFlags)); - RTMPCancelTimer(&pAd->MlmeAux.AssocTimer, - &TimerCancelled); - - if (Status == MLME_SUCCESS) { - u8 MaxSupportedRateIn500Kbps = 0; - u8 idx; - - /* supported rates array may not be sorted. sort it and find the maximum rate */ - for (idx = 0; idx < SupRateLen; idx++) { - if (MaxSupportedRateIn500Kbps < - (SupRate[idx] & 0x7f)) - MaxSupportedRateIn500Kbps = - SupRate[idx] & 0x7f; - } - - for (idx = 0; idx < ExtRateLen; idx++) { - if (MaxSupportedRateIn500Kbps < - (ExtRate[idx] & 0x7f)) - MaxSupportedRateIn500Kbps = - ExtRate[idx] & 0x7f; - } - /* go to procedure listed on page 376 */ - AssocPostProc(pAd, Addr2, CapabilityInfo, Aid, - SupRate, SupRateLen, ExtRate, - ExtRateLen, &EdcaParm, - &HtCapability, HtCapabilityLen, - &AddHtInfo); - - StaAddMacTableEntry(pAd, - &pAd->MacTab. - Content[BSSID_WCID], - MaxSupportedRateIn500Kbps, - &HtCapability, - HtCapabilityLen, &AddHtInfo, - AddHtInfoLen, - CapabilityInfo); - } - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, - MT2_ASSOC_CONF, 2, &Status); - } - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - PeerAssocRspAction() sanity check fail\n")); - } -} - -/* - ========================================================================== - Description: - peer sends reassoc rsp - Parametrs: - Elem - MLME message cntaining the received frame - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void PeerReassocRspAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 CapabilityInfo; - u16 Status; - u16 Aid; - u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES], SupRateLen; - u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES], ExtRateLen; - u8 Addr2[MAC_ADDR_LEN]; - u8 CkipFlag; - BOOLEAN TimerCancelled; - struct rt_edca_parm EdcaParm; - struct rt_ht_capability_ie HtCapability; - struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */ - u8 HtCapabilityLen; - u8 AddHtInfoLen; - u8 NewExtChannelOffset = 0xff; - - if (PeerAssocRspSanity - (pAd, Elem->Msg, Elem->MsgLen, Addr2, &CapabilityInfo, &Status, - &Aid, SupRate, &SupRateLen, ExtRate, &ExtRateLen, &HtCapability, - &AddHtInfo, &HtCapabilityLen, &AddHtInfoLen, &NewExtChannelOffset, - &EdcaParm, &CkipFlag)) { - if (MAC_ADDR_EQUAL(Addr2, pAd->MlmeAux.Bssid)) /* The frame is for me ? */ - { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - receive REASSOC_RSP to me (status=%d)\n", - Status)); - RTMPCancelTimer(&pAd->MlmeAux.ReassocTimer, - &TimerCancelled); - - if (Status == MLME_SUCCESS) { - /* go to procedure listed on page 376 */ - AssocPostProc(pAd, Addr2, CapabilityInfo, Aid, - SupRate, SupRateLen, ExtRate, - ExtRateLen, &EdcaParm, - &HtCapability, HtCapabilityLen, - &AddHtInfo); - - { - wext_notify_event_assoc(pAd); - RtmpOSWrielessEventSend(pAd, SIOCGIWAP, - -1, - &pAd->MlmeAux. - Bssid[0], NULL, - 0); - } - - } - /* CkipFlag is no use for reassociate */ - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, - MT2_REASSOC_CONF, 2, &Status); - } - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - PeerReassocRspAction() sanity check fail\n")); - } - -} - -/* - ========================================================================== - Description: - procedures on IEEE 802.11/1999 p.376 - Parametrs: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AssocPostProc(struct rt_rtmp_adapter *pAd, u8 *pAddr2, u16 CapabilityInfo, u16 Aid, u8 SupRate[], u8 SupRateLen, u8 ExtRate[], u8 ExtRateLen, struct rt_edca_parm *pEdcaParm, struct rt_ht_capability_ie * pHtCapability, u8 HtCapabilityLen, struct rt_add_ht_info_ie * pAddHtInfo) /* AP might use this additional ht info IE */ -{ - unsigned long Idx; - - pAd->MlmeAux.BssType = BSS_INFRA; - COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pAddr2); - pAd->MlmeAux.Aid = Aid; - pAd->MlmeAux.CapabilityInfo = - CapabilityInfo & SUPPORTED_CAPABILITY_INFO; - - /* Some HT AP might lost WMM IE. We add WMM ourselves. because HT requires QoS on. */ - if ((HtCapabilityLen > 0) && (pEdcaParm->bValid == FALSE)) { - pEdcaParm->bValid = TRUE; - pEdcaParm->Aifsn[0] = 3; - pEdcaParm->Aifsn[1] = 7; - pEdcaParm->Aifsn[2] = 2; - pEdcaParm->Aifsn[3] = 2; - - pEdcaParm->Cwmin[0] = 4; - pEdcaParm->Cwmin[1] = 4; - pEdcaParm->Cwmin[2] = 3; - pEdcaParm->Cwmin[3] = 2; - - pEdcaParm->Cwmax[0] = 10; - pEdcaParm->Cwmax[1] = 10; - pEdcaParm->Cwmax[2] = 4; - pEdcaParm->Cwmax[3] = 3; - - pEdcaParm->Txop[0] = 0; - pEdcaParm->Txop[1] = 0; - pEdcaParm->Txop[2] = 96; - pEdcaParm->Txop[3] = 48; - - } - - NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, pEdcaParm, sizeof(struct rt_edca_parm)); - - /* filter out un-supported rates */ - pAd->MlmeAux.SupRateLen = SupRateLen; - NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, SupRateLen); - RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, &pAd->MlmeAux.SupRateLen); - - /* filter out un-supported rates */ - pAd->MlmeAux.ExtRateLen = ExtRateLen; - NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, ExtRateLen); - RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, &pAd->MlmeAux.ExtRateLen); - - if (HtCapabilityLen > 0) { - RTMPCheckHt(pAd, BSSID_WCID, pHtCapability, pAddHtInfo); - } - DBGPRINT(RT_DEBUG_TRACE, - ("AssocPostProc===> AP.AMsduSize = %d. ClientStatusFlags = 0x%lx \n", - pAd->MacTab.Content[BSSID_WCID].AMsduSize, - pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags)); - - DBGPRINT(RT_DEBUG_TRACE, - ("AssocPostProc===> (Mmps=%d, AmsduSize=%d, )\n", - pAd->MacTab.Content[BSSID_WCID].MmpsMode, - pAd->MacTab.Content[BSSID_WCID].AMsduSize)); - - /* Set New WPA information */ - Idx = BssTableSearch(&pAd->ScanTab, pAddr2, pAd->MlmeAux.Channel); - if (Idx == BSS_NOT_FOUND) { - DBGPRINT_ERR("ASSOC - Can't find BSS after receiving Assoc response\n"); - } else { - /* Init variable */ - pAd->MacTab.Content[BSSID_WCID].RSNIE_Len = 0; - NdisZeroMemory(pAd->MacTab.Content[BSSID_WCID].RSN_IE, - MAX_LEN_OF_RSNIE); - - /* Store appropriate RSN_IE for WPA SM negotiation later */ - if ((pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) - && (pAd->ScanTab.BssEntry[Idx].VarIELen != 0)) { - u8 *pVIE; - u16 len; - struct rt_eid * pEid; - - pVIE = pAd->ScanTab.BssEntry[Idx].VarIEs; - len = pAd->ScanTab.BssEntry[Idx].VarIELen; - /*KH need to check again */ - /* Don't allow to go to sleep mode if authmode is WPA-related. */ - /*This can make Authentication process more smoothly. */ - RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP); - - while (len > 0) { - pEid = (struct rt_eid *) pVIE; - /* For WPA/WPAPSK */ - if ((pEid->Eid == IE_WPA) - && - (NdisEqualMemory(pEid->Octet, WPA_OUI, 4)) - && (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA - || pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPAPSK)) { - NdisMoveMemory(pAd->MacTab. - Content[BSSID_WCID]. - RSN_IE, pVIE, - (pEid->Len + 2)); - pAd->MacTab.Content[BSSID_WCID]. - RSNIE_Len = (pEid->Len + 2); - DBGPRINT(RT_DEBUG_TRACE, - ("AssocPostProc===> Store RSN_IE for WPA SM negotiation \n")); - } - /* For WPA2/WPA2PSK */ - else if ((pEid->Eid == IE_RSN) - && - (NdisEqualMemory - (pEid->Octet + 2, RSN_OUI, 3)) - && (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA2 - || pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA2PSK)) { - NdisMoveMemory(pAd->MacTab. - Content[BSSID_WCID]. - RSN_IE, pVIE, - (pEid->Len + 2)); - pAd->MacTab.Content[BSSID_WCID]. - RSNIE_Len = (pEid->Len + 2); - DBGPRINT(RT_DEBUG_TRACE, - ("AssocPostProc===> Store RSN_IE for WPA2 SM negotiation \n")); - } - - pVIE += (pEid->Len + 2); - len -= (pEid->Len + 2); - } - - } - - if (pAd->MacTab.Content[BSSID_WCID].RSNIE_Len == 0) { - DBGPRINT(RT_DEBUG_TRACE, - ("AssocPostProc===> no RSN_IE \n")); - } else { - hex_dump("RSN_IE", - pAd->MacTab.Content[BSSID_WCID].RSN_IE, - pAd->MacTab.Content[BSSID_WCID].RSNIE_Len); - } - } -} - -/* - ========================================================================== - Description: - left part of IEEE 802.11/1999 p.374 - Parameters: - Elem - MLME message containing the received frame - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void PeerDisassocAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Addr2[MAC_ADDR_LEN]; - u16 Reason; - - DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - PeerDisassocAction()\n")); - if (PeerDisassocSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason)) { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - PeerDisassocAction() Reason = %d\n", - Reason)); - if (INFRA_ON(pAd) - && MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, Addr2)) { - - if (pAd->CommonCfg.bWirelessEvent) { - RTMPSendWirelessEvent(pAd, - IW_DISASSOC_EVENT_FLAG, - pAd->MacTab. - Content[BSSID_WCID].Addr, - BSS0, 0); - } - - LinkDown(pAd, TRUE); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - - RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL, - 0); - } - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - PeerDisassocAction() sanity check fail\n")); - } - -} - -/* - ========================================================================== - Description: - what the state machine will do after assoc timeout - Parameters: - Elme - - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AssocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - AssocTimeoutAction\n")); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_REJ_TIMEOUT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status); -} - -/* - ========================================================================== - Description: - what the state machine will do after reassoc timeout - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void ReassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - ReassocTimeoutAction\n")); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_REJ_TIMEOUT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status); -} - -/* - ========================================================================== - Description: - what the state machine will do after disassoc timeout - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void DisassocTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, ("ASSOC - DisassocTimeoutAction\n")); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_SUCCESS; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, - &Status); -} - -void InvalidStateWhenAssoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - InvalidStateWhenAssoc(state=%ld), reset ASSOC state machine\n", - pAd->Mlme.AssocMachine.CurrState)); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_STATE_MACHINE_REJECT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_ASSOC_CONF, 2, &Status); -} - -void InvalidStateWhenReassoc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - InvalidStateWhenReassoc(state=%ld), reset ASSOC state machine\n", - pAd->Mlme.AssocMachine.CurrState)); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_STATE_MACHINE_REJECT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_REASSOC_CONF, 2, &Status); -} - -void InvalidStateWhenDisassociate(struct rt_rtmp_adapter *pAd, - struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - InvalidStateWhenDisassoc(state=%ld), reset ASSOC state machine\n", - pAd->Mlme.AssocMachine.CurrState)); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - Status = MLME_STATE_MACHINE_REJECT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DISASSOC_CONF, 2, - &Status); -} - -/* - ========================================================================== - Description: - right part of IEEE 802.11/1999 page 374 - Note: - This event should never cause ASSOC state machine perform state - transition, and has no relationship with CNTL machine. So we separate - this routine as a service outside of ASSOC state transition table. - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void Cls3errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr) -{ - struct rt_header_802_11 DisassocHdr; - struct rt_header_802_11 * pDisassocHdr; - u8 *pOutBuffer = NULL; - unsigned long FrameLen = 0; - int NStatus; - u16 Reason = REASON_CLS3ERR; - - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) - return; - - DBGPRINT(RT_DEBUG_TRACE, - ("ASSOC - Class 3 Error, Send DISASSOC frame\n")); - MgtMacHeaderInit(pAd, &DisassocHdr, SUBTYPE_DISASSOC, 0, pAddr, pAd->CommonCfg.Bssid); /* patch peap ttls switching issue */ - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_header_802_11), &DisassocHdr, - 2, &Reason, END_OF_ARGS); - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - - /* To patch Instance and Buffalo(N) AP */ - /* Driver has to send deauth to Instance AP, but Buffalo(N) needs to send disassoc to reset Authenticator's state machine */ - /* Therefore, we send both of them. */ - pDisassocHdr = (struct rt_header_802_11 *) pOutBuffer; - pDisassocHdr->FC.SubType = SUBTYPE_DEAUTH; - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - - MlmeFreeMemory(pAd, pOutBuffer); - - pAd->StaCfg.DisassocReason = REASON_CLS3ERR; - COPY_MAC_ADDR(pAd->StaCfg.DisassocSta, pAddr); -} - -int wext_notify_event_assoc(struct rt_rtmp_adapter *pAd) -{ - char custom[IW_CUSTOM_MAX] = { 0 }; - - if (pAd->StaCfg.ReqVarIELen <= IW_CUSTOM_MAX) { - NdisMoveMemory(custom, pAd->StaCfg.ReqVarIEs, - pAd->StaCfg.ReqVarIELen); - RtmpOSWrielessEventSend(pAd, IWEVASSOCREQIE, -1, NULL, custom, - pAd->StaCfg.ReqVarIELen); - } else - DBGPRINT(RT_DEBUG_TRACE, - ("pAd->StaCfg.ReqVarIELen > MAX_CUSTOM_LEN\n")); - - return 0; - -} - -BOOLEAN StaAddMacTableEntry(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - u8 MaxSupportedRateIn500Kbps, - struct rt_ht_capability_ie * pHtCapability, - u8 HtCapabilityLen, - struct rt_add_ht_info_ie * pAddHtInfo, - u8 AddHtInfoLen, u16 CapabilityInfo) -{ - u8 MaxSupportedRate = RATE_11; - - if (ADHOC_ON(pAd)) - CLIENT_STATUS_CLEAR_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE); - - switch (MaxSupportedRateIn500Kbps) { - case 108: - MaxSupportedRate = RATE_54; - break; - case 96: - MaxSupportedRate = RATE_48; - break; - case 72: - MaxSupportedRate = RATE_36; - break; - case 48: - MaxSupportedRate = RATE_24; - break; - case 36: - MaxSupportedRate = RATE_18; - break; - case 24: - MaxSupportedRate = RATE_12; - break; - case 18: - MaxSupportedRate = RATE_9; - break; - case 12: - MaxSupportedRate = RATE_6; - break; - case 22: - MaxSupportedRate = RATE_11; - break; - case 11: - MaxSupportedRate = RATE_5_5; - break; - case 4: - MaxSupportedRate = RATE_2; - break; - case 2: - MaxSupportedRate = RATE_1; - break; - default: - MaxSupportedRate = RATE_11; - break; - } - - if ((pAd->CommonCfg.PhyMode == PHY_11G) - && (MaxSupportedRate < RATE_FIRST_OFDM_RATE)) - return FALSE; - - /* 11n only */ - if (((pAd->CommonCfg.PhyMode == PHY_11N_2_4G) - || (pAd->CommonCfg.PhyMode == PHY_11N_5G)) - && (HtCapabilityLen == 0)) - return FALSE; - - if (!pEntry) - return FALSE; - - NdisAcquireSpinLock(&pAd->MacTabLock); - if (pEntry) { - pEntry->PortSecured = WPA_802_1X_PORT_SECURED; - if ((MaxSupportedRate < RATE_FIRST_OFDM_RATE) || - (pAd->CommonCfg.PhyMode == PHY_11B)) { - pEntry->RateLen = 4; - if (MaxSupportedRate >= RATE_FIRST_OFDM_RATE) - MaxSupportedRate = RATE_11; - } else - pEntry->RateLen = 12; - - pEntry->MaxHTPhyMode.word = 0; - pEntry->MinHTPhyMode.word = 0; - pEntry->HTPhyMode.word = 0; - pEntry->MaxSupportedRate = MaxSupportedRate; - if (pEntry->MaxSupportedRate < RATE_FIRST_OFDM_RATE) { - pEntry->MaxHTPhyMode.field.MODE = MODE_CCK; - pEntry->MaxHTPhyMode.field.MCS = - pEntry->MaxSupportedRate; - pEntry->MinHTPhyMode.field.MODE = MODE_CCK; - pEntry->MinHTPhyMode.field.MCS = - pEntry->MaxSupportedRate; - pEntry->HTPhyMode.field.MODE = MODE_CCK; - pEntry->HTPhyMode.field.MCS = pEntry->MaxSupportedRate; - } else { - pEntry->MaxHTPhyMode.field.MODE = MODE_OFDM; - pEntry->MaxHTPhyMode.field.MCS = - OfdmRateToRxwiMCS[pEntry->MaxSupportedRate]; - pEntry->MinHTPhyMode.field.MODE = MODE_OFDM; - pEntry->MinHTPhyMode.field.MCS = - OfdmRateToRxwiMCS[pEntry->MaxSupportedRate]; - pEntry->HTPhyMode.field.MODE = MODE_OFDM; - pEntry->HTPhyMode.field.MCS = - OfdmRateToRxwiMCS[pEntry->MaxSupportedRate]; - } - pEntry->CapabilityInfo = CapabilityInfo; - CLIENT_STATUS_CLEAR_FLAG(pEntry, - fCLIENT_STATUS_AGGREGATION_CAPABLE); - CLIENT_STATUS_CLEAR_FLAG(pEntry, - fCLIENT_STATUS_PIGGYBACK_CAPABLE); - } - - NdisZeroMemory(&pEntry->HTCapability, sizeof(pEntry->HTCapability)); - /* If this Entry supports 802.11n, upgrade to HT rate. */ - if ((HtCapabilityLen != 0) - && (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) { - u8 j, bitmask; /*k,bitmask; */ - char i; - - if (ADHOC_ON(pAd)) - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_WMM_CAPABLE); - if ((pHtCapability->HtCapInfo.GF) - && (pAd->CommonCfg.DesiredHtPhy.GF)) { - pEntry->MaxHTPhyMode.field.MODE = MODE_HTGREENFIELD; - } else { - pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX; - pAd->MacTab.fAnyStationNonGF = TRUE; - pAd->CommonCfg.AddHTInfo.AddHtInfo2.NonGfPresent = 1; - } - - if ((pHtCapability->HtCapInfo.ChannelWidth) && - (pAd->CommonCfg.DesiredHtPhy.ChannelWidth) && - ((pAd->StaCfg.BssType == BSS_INFRA) - || ((pAd->StaCfg.BssType == BSS_ADHOC) - && (pAddHtInfo->AddHtInfo.ExtChanOffset == - pAd->CommonCfg.AddHTInfo.AddHtInfo. - ExtChanOffset)))) { - pEntry->MaxHTPhyMode.field.BW = BW_40; - pEntry->MaxHTPhyMode.field.ShortGI = - ((pAd->CommonCfg.DesiredHtPhy. - ShortGIfor40) & (pHtCapability->HtCapInfo. - ShortGIfor40)); - } else { - pEntry->MaxHTPhyMode.field.BW = BW_20; - pEntry->MaxHTPhyMode.field.ShortGI = - ((pAd->CommonCfg.DesiredHtPhy. - ShortGIfor20) & (pHtCapability->HtCapInfo. - ShortGIfor20)); - pAd->MacTab.fAnyStation20Only = TRUE; - } - - /* 3*3 */ - if (pAd->MACVersion >= RALINK_2883_VERSION - && pAd->MACVersion < RALINK_3070_VERSION) - pEntry->MaxHTPhyMode.field.TxBF = - pAd->CommonCfg.RegTransmitSetting.field.TxBF; - - /* find max fixed rate */ - for (i = 23; i >= 0; i--) /* 3*3 */ - { - j = i / 8; - bitmask = (1 << (i - (j * 8))); - if ((pAd->StaCfg.DesiredHtPhyInfo.MCSSet[j] & bitmask) - && (pHtCapability->MCSSet[j] & bitmask)) { - pEntry->MaxHTPhyMode.field.MCS = i; - break; - } - if (i == 0) - break; - } - - if (pAd->StaCfg.DesiredTransmitSetting.field.MCS != MCS_AUTO) { - if (pAd->StaCfg.DesiredTransmitSetting.field.MCS == 32) { - /* Fix MCS as HT Duplicated Mode */ - pEntry->MaxHTPhyMode.field.BW = 1; - pEntry->MaxHTPhyMode.field.MODE = MODE_HTMIX; - pEntry->MaxHTPhyMode.field.STBC = 0; - pEntry->MaxHTPhyMode.field.ShortGI = 0; - pEntry->MaxHTPhyMode.field.MCS = 32; - } else if (pEntry->MaxHTPhyMode.field.MCS > - pAd->StaCfg.HTPhyMode.field.MCS) { - /* STA supports fixed MCS */ - pEntry->MaxHTPhyMode.field.MCS = - pAd->StaCfg.HTPhyMode.field.MCS; - } - } - - pEntry->MaxHTPhyMode.field.STBC = - (pHtCapability->HtCapInfo. - RxSTBC & (pAd->CommonCfg.DesiredHtPhy.TxSTBC)); - pEntry->MpduDensity = pHtCapability->HtCapParm.MpduDensity; - pEntry->MaxRAmpduFactor = - pHtCapability->HtCapParm.MaxRAmpduFactor; - pEntry->MmpsMode = (u8)pHtCapability->HtCapInfo.MimoPs; - pEntry->AMsduSize = (u8)pHtCapability->HtCapInfo.AMsduSize; - pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word; - - if (pAd->CommonCfg.DesiredHtPhy.AmsduEnable - && (pAd->CommonCfg.REGBACapability.field.AutoBA == FALSE)) - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_AMSDU_INUSED); - if (pHtCapability->HtCapInfo.ShortGIfor20) - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_SGI20_CAPABLE); - if (pHtCapability->HtCapInfo.ShortGIfor40) - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_SGI40_CAPABLE); - if (pHtCapability->HtCapInfo.TxSTBC) - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_TxSTBC_CAPABLE); - if (pHtCapability->HtCapInfo.RxSTBC) - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_RxSTBC_CAPABLE); - if (pHtCapability->ExtHtCapInfo.PlusHTC) - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_HTC_CAPABLE); - if (pAd->CommonCfg.bRdg - && pHtCapability->ExtHtCapInfo.RDGSupport) - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_RDG_CAPABLE); - if (pHtCapability->ExtHtCapInfo.MCSFeedback == 0x03) - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_MCSFEEDBACK_CAPABLE); - NdisMoveMemory(&pEntry->HTCapability, pHtCapability, - HtCapabilityLen); - } else { - pAd->MacTab.fAnyStationIsLegacy = TRUE; - } - - pEntry->HTPhyMode.word = pEntry->MaxHTPhyMode.word; - pEntry->CurrTxRate = pEntry->MaxSupportedRate; - - /* Set asic auto fall back */ - if (pAd->StaCfg.bAutoTxRateSwitch == TRUE) { - u8 *pTable; - u8 TableSize = 0; - - MlmeSelectTxRateTable(pAd, pEntry, &pTable, &TableSize, - &pEntry->CurrTxRateIndex); - pEntry->bAutoTxRateSwitch = TRUE; - } else { - pEntry->HTPhyMode.field.MODE = pAd->StaCfg.HTPhyMode.field.MODE; - pEntry->HTPhyMode.field.MCS = pAd->StaCfg.HTPhyMode.field.MCS; - pEntry->bAutoTxRateSwitch = FALSE; - - /* If the legacy mode is set, overwrite the transmit setting of this entry. */ - RTMPUpdateLegacyTxSetting((u8)pAd->StaCfg. - DesiredTransmitSetting.field. - FixedTxMode, pEntry); - } - - pEntry->PortSecured = WPA_802_1X_PORT_SECURED; - pEntry->Sst = SST_ASSOC; - pEntry->AuthState = AS_AUTH_OPEN; - pEntry->AuthMode = pAd->StaCfg.AuthMode; - pEntry->WepStatus = pAd->StaCfg.WepStatus; - - NdisReleaseSpinLock(&pAd->MacTabLock); - - { - union iwreq_data wrqu; - wext_notify_event_assoc(pAd); - - memcpy(wrqu.ap_addr.sa_data, pAd->MlmeAux.Bssid, MAC_ADDR_LEN); - wireless_send_event(pAd->net_dev, SIOCGIWAP, &wrqu, NULL); - - } - return TRUE; -} diff --git a/trunk/drivers/staging/rt2860/sta/auth.c b/trunk/drivers/staging/rt2860/sta/auth.c deleted file mode 100644 index 23ea00b896b0..000000000000 --- a/trunk/drivers/staging/rt2860/sta/auth.c +++ /dev/null @@ -1,517 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - auth.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - John 2004-9-3 porting from RT2500 - Justin P. Mattock 11/07/2010 Fix typos -*/ -#include "../rt_config.h" - -/* - ========================================================================== - Description: - authenticate state machine init, including state transition and timer init - Parameters: - Sm - pointer to the auth state machine - Note: - The state machine looks like this - - AUTH_REQ_IDLE AUTH_WAIT_SEQ2 AUTH_WAIT_SEQ4 - MT2_MLME_AUTH_REQ mlme_auth_req_action invalid_state_when_auth invalid_state_when_auth - MT2_PEER_AUTH_EVEN drop peer_auth_even_at_seq2_action peer_auth_even_at_seq4_action - MT2_AUTH_TIMEOUT Drop auth_timeout_action auth_timeout_action - - IRQL = PASSIVE_LEVEL - - ========================================================================== - */ - -void AuthStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *Sm, OUT STATE_MACHINE_FUNC Trans[]) -{ - StateMachineInit(Sm, Trans, MAX_AUTH_STATE, MAX_AUTH_MSG, - (STATE_MACHINE_FUNC) Drop, AUTH_REQ_IDLE, - AUTH_MACHINE_BASE); - - /* the first column */ - StateMachineSetAction(Sm, AUTH_REQ_IDLE, MT2_MLME_AUTH_REQ, - (STATE_MACHINE_FUNC) MlmeAuthReqAction); - - /* the second column */ - StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_MLME_AUTH_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenAuth); - StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_PEER_AUTH_EVEN, - (STATE_MACHINE_FUNC) PeerAuthRspAtSeq2Action); - StateMachineSetAction(Sm, AUTH_WAIT_SEQ2, MT2_AUTH_TIMEOUT, - (STATE_MACHINE_FUNC) AuthTimeoutAction); - - /* the third column */ - StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_MLME_AUTH_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenAuth); - StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_PEER_AUTH_EVEN, - (STATE_MACHINE_FUNC) PeerAuthRspAtSeq4Action); - StateMachineSetAction(Sm, AUTH_WAIT_SEQ4, MT2_AUTH_TIMEOUT, - (STATE_MACHINE_FUNC) AuthTimeoutAction); - - RTMPInitTimer(pAd, &pAd->MlmeAux.AuthTimer, - GET_TIMER_FUNCTION(AuthTimeout), pAd, FALSE); -} - -/* - ========================================================================== - Description: - function to be executed at timer thread when auth timer expires - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AuthTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - - DBGPRINT(RT_DEBUG_TRACE, ("AUTH - AuthTimeout\n")); - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS | fRTMP_ADAPTER_NIC_NOT_EXIST)) - return; - - /* send a de-auth to reset AP's state machine (Patch AP-Dir635) */ - if (pAd->Mlme.AuthMachine.CurrState == AUTH_WAIT_SEQ2) - Cls2errAction(pAd, pAd->MlmeAux.Bssid); - - MlmeEnqueue(pAd, AUTH_STATE_MACHINE, MT2_AUTH_TIMEOUT, 0, NULL); - RTMP_MLME_HANDLER(pAd); -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void MlmeAuthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - if (AUTH_ReqSend - (pAd, Elem, &pAd->MlmeAux.AuthTimer, "AUTH", 1, NULL, 0)) - pAd->Mlme.AuthMachine.CurrState = AUTH_WAIT_SEQ2; - else { - u16 Status; - - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; - Status = MLME_INVALID_FORMAT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, - &Status); - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void PeerAuthRspAtSeq2Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Addr2[MAC_ADDR_LEN]; - u16 Seq, Status, RemoteStatus, Alg; - u8 ChlgText[CIPHER_TEXT_LEN]; - u8 CyperChlgText[CIPHER_TEXT_LEN + 8 + 8]; - u8 Element[2]; - struct rt_header_802_11 AuthHdr; - BOOLEAN TimerCancelled; - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen = 0; - u16 Status2; - - if (PeerAuthSanity - (pAd, Elem->Msg, Elem->MsgLen, Addr2, &Alg, &Seq, &Status, - (char *)ChlgText)) { - if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Addr2) && Seq == 2) { - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH - Receive AUTH_RSP seq#2 to me (Alg=%d, Status=%d)\n", - Alg, Status)); - RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, - &TimerCancelled); - - if (Status == MLME_SUCCESS) { - /* Authentication Mode "LEAP" has allow for CCX 1.X */ - if (pAd->MlmeAux.Alg == Ndis802_11AuthModeOpen) { - pAd->Mlme.AuthMachine.CurrState = - AUTH_REQ_IDLE; - MlmeEnqueue(pAd, - MLME_CNTL_STATE_MACHINE, - MT2_AUTH_CONF, 2, &Status); - } else { - /* 2. shared key, need to be challenged */ - Seq++; - RemoteStatus = MLME_SUCCESS; - - /* Get an unused nonpaged memory */ - NStatus = - MlmeAllocateMemory(pAd, - &pOutBuffer); - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH - PeerAuthRspAtSeq2Action() allocate memory fail\n")); - pAd->Mlme.AuthMachine. - CurrState = AUTH_REQ_IDLE; - Status2 = MLME_FAIL_NO_RESOURCE; - MlmeEnqueue(pAd, - MLME_CNTL_STATE_MACHINE, - MT2_AUTH_CONF, 2, - &Status2); - return; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH - Send AUTH request seq#3...\n")); - MgtMacHeaderInit(pAd, &AuthHdr, - SUBTYPE_AUTH, 0, Addr2, - pAd->MlmeAux.Bssid); - AuthHdr.FC.Wep = 1; - /* Encrypt challenge text & auth information */ - RTMPInitWepEngine(pAd, - pAd-> - SharedKey[BSS0][pAd-> - StaCfg. - DefaultKeyId]. - Key, - pAd->StaCfg. - DefaultKeyId, - pAd-> - SharedKey[BSS0][pAd-> - StaCfg. - DefaultKeyId]. - KeyLen, - CyperChlgText); - - Alg = cpu2le16(*(u16 *) & Alg); - Seq = cpu2le16(*(u16 *) & Seq); - RemoteStatus = - cpu2le16(*(u16 *) & - RemoteStatus); - - RTMPEncryptData(pAd, (u8 *)& Alg, - CyperChlgText + 4, 2); - RTMPEncryptData(pAd, (u8 *)& Seq, - CyperChlgText + 6, 2); - RTMPEncryptData(pAd, - (u8 *)& RemoteStatus, - CyperChlgText + 8, 2); - Element[0] = 16; - Element[1] = 128; - RTMPEncryptData(pAd, Element, - CyperChlgText + 10, 2); - RTMPEncryptData(pAd, ChlgText, - CyperChlgText + 12, - 128); - RTMPSetICV(pAd, CyperChlgText + 140); - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_header_802_11), - &AuthHdr, - CIPHER_TEXT_LEN + 16, - CyperChlgText, - END_OF_ARGS); - MiniportMMRequest(pAd, 0, pOutBuffer, - FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - RTMPSetTimer(&pAd->MlmeAux.AuthTimer, - AUTH_TIMEOUT); - pAd->Mlme.AuthMachine.CurrState = - AUTH_WAIT_SEQ4; - } - } else { - pAd->StaCfg.AuthFailReason = Status; - COPY_MAC_ADDR(pAd->StaCfg.AuthFailSta, Addr2); - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, - MT2_AUTH_CONF, 2, &Status); - } - } - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH - PeerAuthSanity() sanity check fail\n")); - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void PeerAuthRspAtSeq4Action(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Addr2[MAC_ADDR_LEN]; - u16 Alg, Seq, Status; - char ChlgText[CIPHER_TEXT_LEN]; - BOOLEAN TimerCancelled; - - if (PeerAuthSanity - (pAd, Elem->Msg, Elem->MsgLen, Addr2, &Alg, &Seq, &Status, - ChlgText)) { - if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Addr2) && Seq == 4) { - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH - Receive AUTH_RSP seq#4 to me\n")); - RTMPCancelTimer(&pAd->MlmeAux.AuthTimer, - &TimerCancelled); - - if (Status != MLME_SUCCESS) { - pAd->StaCfg.AuthFailReason = Status; - COPY_MAC_ADDR(pAd->StaCfg.AuthFailSta, Addr2); - } - - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, - 2, &Status); - } - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH - PeerAuthRspAtSeq4Action() sanity check fail\n")); - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void MlmeDeauthReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_mlme_deauth_req *pInfo; - struct rt_header_802_11 DeauthHdr; - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen = 0; - u16 Status; - - pInfo = (struct rt_mlme_deauth_req *)Elem->Msg; - - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH - MlmeDeauthReqAction() allocate memory fail\n")); - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; - Status = MLME_FAIL_NO_RESOURCE; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DEAUTH_CONF, 2, - &Status); - return; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH - Send DE-AUTH request (Reason=%d)...\n", - pInfo->Reason)); - MgtMacHeaderInit(pAd, &DeauthHdr, SUBTYPE_DEAUTH, 0, pInfo->Addr, - pAd->MlmeAux.Bssid); - MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11), - &DeauthHdr, 2, &pInfo->Reason, END_OF_ARGS); - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - pAd->StaCfg.DeauthReason = pInfo->Reason; - COPY_MAC_ADDR(pAd->StaCfg.DeauthSta, pInfo->Addr); - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; - Status = MLME_SUCCESS; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_DEAUTH_CONF, 2, &Status); - - /* send wireless event - for deauthentication */ - if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG, - pAd->MacTab.Content[BSSID_WCID].Addr, - BSS0, 0); -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void AuthTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, ("AUTH - AuthTimeoutAction\n")); - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; - Status = MLME_REJ_TIMEOUT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status); -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void InvalidStateWhenAuth(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH - InvalidStateWhenAuth (state=%ld), reset AUTH state machine\n", - pAd->Mlme.AuthMachine.CurrState)); - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; - Status = MLME_STATE_MACHINE_REJECT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, &Status); -} - -/* - ========================================================================== - Description: - Some STA/AP - Note: - This action should never trigger AUTH state transition, therefore we - separate it from AUTH state machine, and make it as a standalone service - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void Cls2errAction(struct rt_rtmp_adapter *pAd, u8 *pAddr) -{ - struct rt_header_802_11 DeauthHdr; - u8 *pOutBuffer = NULL; - int NStatus; - unsigned long FrameLen = 0; - u16 Reason = REASON_CLS2ERR; - - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) - return; - - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH - Class 2 error, Send DEAUTH frame...\n")); - MgtMacHeaderInit(pAd, &DeauthHdr, SUBTYPE_DEAUTH, 0, pAddr, - pAd->MlmeAux.Bssid); - MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11), - &DeauthHdr, 2, &Reason, END_OF_ARGS); - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - pAd->StaCfg.DeauthReason = Reason; - COPY_MAC_ADDR(pAd->StaCfg.DeauthSta, pAddr); -} - -BOOLEAN AUTH_ReqSend(struct rt_rtmp_adapter *pAd, - struct rt_mlme_queue_elem *pElem, - struct rt_ralink_timer *pAuthTimer, - char *pSMName, - u16 SeqNo, - u8 *pNewElement, unsigned long ElementLen) -{ - u16 Alg, Seq, Status; - u8 Addr[6]; - unsigned long Timeout; - struct rt_header_802_11 AuthHdr; - BOOLEAN TimerCancelled; - int NStatus; - u8 *pOutBuffer = NULL; - unsigned long FrameLen = 0, tmp = 0; - - /* Block all authentication request during WPA block period */ - if (pAd->StaCfg.bBlockAssoc == TRUE) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s - Block Auth request during WPA block period!\n", - pSMName)); - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; - Status = MLME_STATE_MACHINE_REJECT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, 2, - &Status); - } else - if (MlmeAuthReqSanity - (pAd, pElem->Msg, pElem->MsgLen, Addr, &Timeout, &Alg)) { - /* reset timer */ - RTMPCancelTimer(pAuthTimer, &TimerCancelled); - - COPY_MAC_ADDR(pAd->MlmeAux.Bssid, Addr); - pAd->MlmeAux.Alg = Alg; - Seq = SeqNo; - Status = MLME_SUCCESS; - - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, - ("%s - MlmeAuthReqAction(Alg:%d) allocate memory failed\n", - pSMName, Alg)); - pAd->Mlme.AuthMachine.CurrState = AUTH_REQ_IDLE; - Status = MLME_FAIL_NO_RESOURCE; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_AUTH_CONF, - 2, &Status); - return FALSE; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("%s - Send AUTH request seq#1 (Alg=%d)...\n", pSMName, - Alg)); - MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, Addr, - pAd->MlmeAux.Bssid); - MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11), - &AuthHdr, 2, &Alg, 2, &Seq, 2, &Status, - END_OF_ARGS); - - if (pNewElement && ElementLen) { - MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp, - ElementLen, pNewElement, END_OF_ARGS); - FrameLen += tmp; - } - - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - - RTMPSetTimer(pAuthTimer, Timeout); - return TRUE; - } else { - DBGPRINT_ERR("%s - MlmeAuthReqAction() sanity check failed\n", pSMName); - return FALSE; - } - - return TRUE; -} diff --git a/trunk/drivers/staging/rt2860/sta/auth_rsp.c b/trunk/drivers/staging/rt2860/sta/auth_rsp.c deleted file mode 100644 index 5b018b757308..000000000000 --- a/trunk/drivers/staging/rt2860/sta/auth_rsp.c +++ /dev/null @@ -1,142 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - auth_rsp.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - John 2004-10-1 copy from RT2560 -*/ -#include "../rt_config.h" - -/* - ========================================================================== - Description: - authentication state machine init procedure - Parameters: - Sm - the state machine - - IRQL = PASSIVE_LEVEL - - ========================================================================== - */ -void AuthRspStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *Sm, - IN STATE_MACHINE_FUNC Trans[]) -{ - StateMachineInit(Sm, Trans, MAX_AUTH_RSP_STATE, MAX_AUTH_RSP_MSG, - (STATE_MACHINE_FUNC) Drop, AUTH_RSP_IDLE, - AUTH_RSP_MACHINE_BASE); - - /* column 1 */ - StateMachineSetAction(Sm, AUTH_RSP_IDLE, MT2_PEER_DEAUTH, - (STATE_MACHINE_FUNC) PeerDeauthAction); - - /* column 2 */ - StateMachineSetAction(Sm, AUTH_RSP_WAIT_CHAL, MT2_PEER_DEAUTH, - (STATE_MACHINE_FUNC) PeerDeauthAction); - -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void PeerAuthSimpleRspGenAndSend(struct rt_rtmp_adapter *pAd, - struct rt_header_802_11 * pHdr80211, - u16 Alg, - u16 Seq, - u16 Reason, u16 Status) -{ - struct rt_header_802_11 AuthHdr; - unsigned long FrameLen = 0; - u8 *pOutBuffer = NULL; - int NStatus; - - if (Reason != MLME_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, ("Peer AUTH fail...\n")); - return; - } - /*Get an unused nonpaged memory */ - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); - if (NStatus != NDIS_STATUS_SUCCESS) - return; - - DBGPRINT(RT_DEBUG_TRACE, ("Send AUTH response (seq#2)...\n")); - MgtMacHeaderInit(pAd, &AuthHdr, SUBTYPE_AUTH, 0, pHdr80211->Addr2, - pAd->MlmeAux.Bssid); - MakeOutgoingFrame(pOutBuffer, &FrameLen, sizeof(struct rt_header_802_11), - &AuthHdr, 2, &Alg, 2, &Seq, 2, &Reason, END_OF_ARGS); - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void PeerDeauthAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Addr2[MAC_ADDR_LEN]; - u16 Reason; - - if (PeerDeauthSanity(pAd, Elem->Msg, Elem->MsgLen, Addr2, &Reason)) { - if (INFRA_ON(pAd) - && MAC_ADDR_EQUAL(Addr2, pAd->CommonCfg.Bssid) - ) { - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH_RSP - receive DE-AUTH from our AP (Reason=%d)\n", - Reason)); - - RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL, - 0); - - /* send wireless event - for deauthentication */ - if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, IW_DEAUTH_EVENT_FLAG, - pAd->MacTab. - Content[BSSID_WCID].Addr, - BSS0, 0); - - LinkDown(pAd, TRUE); - } - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("AUTH_RSP - PeerDeauthAction() sanity check fail\n")); - } -} diff --git a/trunk/drivers/staging/rt2860/sta/connect.c b/trunk/drivers/staging/rt2860/sta/connect.c deleted file mode 100644 index 4996258f6ecd..000000000000 --- a/trunk/drivers/staging/rt2860/sta/connect.c +++ /dev/null @@ -1,2613 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - connect.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - John 2004-08-08 Major modification from RT2560 - Justin P. Mattock 11/07/2010 Fix typos -*/ -#include "../rt_config.h" - -u8 CipherSuiteWpaNoneTkip[] = { - 0x00, 0x50, 0xf2, 0x01, /* oui */ - 0x01, 0x00, /* Version */ - 0x00, 0x50, 0xf2, 0x02, /* Multicast */ - 0x01, 0x00, /* Number of unicast */ - 0x00, 0x50, 0xf2, 0x02, /* unicast */ - 0x01, 0x00, /* number of authentication method */ - 0x00, 0x50, 0xf2, 0x00 /* authentication */ -}; - -u8 CipherSuiteWpaNoneTkipLen = - (sizeof(CipherSuiteWpaNoneTkip) / sizeof(u8)); - -u8 CipherSuiteWpaNoneAes[] = { - 0x00, 0x50, 0xf2, 0x01, /* oui */ - 0x01, 0x00, /* Version */ - 0x00, 0x50, 0xf2, 0x04, /* Multicast */ - 0x01, 0x00, /* Number of unicast */ - 0x00, 0x50, 0xf2, 0x04, /* unicast */ - 0x01, 0x00, /* number of authentication method */ - 0x00, 0x50, 0xf2, 0x00 /* authentication */ -}; - -u8 CipherSuiteWpaNoneAesLen = - (sizeof(CipherSuiteWpaNoneAes) / sizeof(u8)); - -/* The following MACRO is called after 1. starting an new IBSS, 2. successfully JOIN an IBSS, */ -/* or 3. successfully ASSOCIATE to a BSS, 4. successfully RE_ASSOCIATE to a BSS */ -/* All settings successfuly negotiated firing MLME state machines become final settings */ -/* and are copied to pAd->StaActive */ -#define COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(_pAd) \ -{ \ - NdisZeroMemory((_pAd)->CommonCfg.Ssid, MAX_LEN_OF_SSID); \ - (_pAd)->CommonCfg.SsidLen = (_pAd)->MlmeAux.SsidLen; \ - NdisMoveMemory((_pAd)->CommonCfg.Ssid, (_pAd)->MlmeAux.Ssid, (_pAd)->MlmeAux.SsidLen); \ - COPY_MAC_ADDR((_pAd)->CommonCfg.Bssid, (_pAd)->MlmeAux.Bssid); \ - (_pAd)->CommonCfg.Channel = (_pAd)->MlmeAux.Channel; \ - (_pAd)->CommonCfg.CentralChannel = (_pAd)->MlmeAux.CentralChannel; \ - (_pAd)->StaActive.Aid = (_pAd)->MlmeAux.Aid; \ - (_pAd)->StaActive.AtimWin = (_pAd)->MlmeAux.AtimWin; \ - (_pAd)->StaActive.CapabilityInfo = (_pAd)->MlmeAux.CapabilityInfo; \ - (_pAd)->CommonCfg.BeaconPeriod = (_pAd)->MlmeAux.BeaconPeriod; \ - (_pAd)->StaActive.CfpMaxDuration = (_pAd)->MlmeAux.CfpMaxDuration; \ - (_pAd)->StaActive.CfpPeriod = (_pAd)->MlmeAux.CfpPeriod; \ - (_pAd)->StaActive.SupRateLen = (_pAd)->MlmeAux.SupRateLen; \ - NdisMoveMemory((_pAd)->StaActive.SupRate, (_pAd)->MlmeAux.SupRate, (_pAd)->MlmeAux.SupRateLen);\ - (_pAd)->StaActive.ExtRateLen = (_pAd)->MlmeAux.ExtRateLen; \ - NdisMoveMemory((_pAd)->StaActive.ExtRate, (_pAd)->MlmeAux.ExtRate, (_pAd)->MlmeAux.ExtRateLen);\ - NdisMoveMemory(&(_pAd)->CommonCfg.APEdcaParm, &(_pAd)->MlmeAux.APEdcaParm, sizeof(struct rt_edca_parm));\ - NdisMoveMemory(&(_pAd)->CommonCfg.APQosCapability, &(_pAd)->MlmeAux.APQosCapability, sizeof(struct rt_qos_capability_parm));\ - NdisMoveMemory(&(_pAd)->CommonCfg.APQbssLoad, &(_pAd)->MlmeAux.APQbssLoad, sizeof(struct rt_qbss_load_parm));\ - COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].Addr, (_pAd)->MlmeAux.Bssid); \ - (_pAd)->MacTab.Content[BSSID_WCID].Aid = (_pAd)->MlmeAux.Aid; \ - (_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.CipherAlg = (_pAd)->StaCfg.PairCipher;\ - COPY_MAC_ADDR((_pAd)->MacTab.Content[BSSID_WCID].PairwiseKey.BssId, (_pAd)->MlmeAux.Bssid);\ - (_pAd)->MacTab.Content[BSSID_WCID].RateLen = (_pAd)->StaActive.SupRateLen + (_pAd)->StaActive.ExtRateLen;\ -} - -/* - ========================================================================== - Description: - - IRQL = PASSIVE_LEVEL - - ========================================================================== -*/ -void MlmeCntlInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *S, OUT STATE_MACHINE_FUNC Trans[]) -{ - /* Control state machine differs from other state machines, the interface */ - /* follows the standard interface */ - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void MlmeCntlMachinePerformAction(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *S, - struct rt_mlme_queue_elem *Elem) -{ - switch (pAd->Mlme.CntlMachine.CurrState) { - case CNTL_IDLE: - CntlIdleProc(pAd, Elem); - break; - case CNTL_WAIT_DISASSOC: - CntlWaitDisassocProc(pAd, Elem); - break; - case CNTL_WAIT_JOIN: - CntlWaitJoinProc(pAd, Elem); - break; - - /* CNTL_WAIT_REASSOC is the only state in CNTL machine that does */ - /* not triggered directly or indirectly by "RTMPSetInformation(OID_xxx)". */ - /* Therefore not protected by NDIS's "only one outstanding OID request" */ - /* rule. Which means NDIS may SET OID in the middle of ROAMing attempts. */ - /* Current approach is to block new SET request at RTMPSetInformation() */ - /* when CntlMachine.CurrState is not CNTL_IDLE */ - case CNTL_WAIT_REASSOC: - CntlWaitReassocProc(pAd, Elem); - break; - - case CNTL_WAIT_START: - CntlWaitStartProc(pAd, Elem); - break; - case CNTL_WAIT_AUTH: - CntlWaitAuthProc(pAd, Elem); - break; - case CNTL_WAIT_AUTH2: - CntlWaitAuthProc2(pAd, Elem); - break; - case CNTL_WAIT_ASSOC: - CntlWaitAssocProc(pAd, Elem); - break; - - case CNTL_WAIT_OID_LIST_SCAN: - if (Elem->MsgType == MT2_SCAN_CONF) { - /* Resume TxRing after SCANING complete. We hope the out-of-service time */ - /* won't be too long to let upper layer time-out the waiting frames */ - RTMPResumeMsduTransmission(pAd); - - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - - /* */ - /* Set LED status to previous status. */ - /* */ - if (pAd->bLedOnScanning) { - pAd->bLedOnScanning = FALSE; - RTMPSetLED(pAd, pAd->LedStatus); - } - } - break; - - case CNTL_WAIT_OID_DISASSOC: - if (Elem->MsgType == MT2_DISASSOC_CONF) { - LinkDown(pAd, FALSE); - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - } - break; -#ifdef RTMP_MAC_USB - /* */ - /* This state is for that we want to connect to an AP but */ - /* it didn't find on BSS List table. So we need to scan the air first, */ - /* after that we can try to connect to the desired AP if available. */ - /* */ - case CNTL_WAIT_SCAN_FOR_CONNECT: - if (Elem->MsgType == MT2_SCAN_CONF) { - /* Resume TxRing after SCANING complete. We hope the out-of-service time */ - /* won't be too long to let upper layer time-out the waiting frames */ - RTMPResumeMsduTransmission(pAd); -#ifdef CCX_SUPPORT - if (pAd->StaCfg.CCXReqType != MSRN_TYPE_UNUSED) { - /* Cisco scan request is finished, prepare beacon report */ - MlmeEnqueue(pAd, AIRONET_STATE_MACHINE, - MT2_AIRONET_SCAN_DONE, 0, NULL); - } -#endif /* CCX_SUPPORT // */ - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - - /* */ - /* Check if we can connect to. */ - /* */ - BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, - (char *) pAd->MlmeAux. - AutoReconnectSsid, - pAd->MlmeAux.AutoReconnectSsidLen); - if (pAd->MlmeAux.SsidBssTab.BssNr > 0) { - MlmeAutoReconnectLastSSID(pAd); - } - } - break; -#endif /* RTMP_MAC_USB // */ - default: - DBGPRINT_ERR("ERROR! CNTL - Illegal message type(=%ld)", Elem->MsgType); - break; - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void CntlIdleProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_mlme_disassoc_req DisassocReq; - - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) - return; - - switch (Elem->MsgType) { - case OID_802_11_SSID: - CntlOidSsidProc(pAd, Elem); - break; - - case OID_802_11_BSSID: - CntlOidRTBssidProc(pAd, Elem); - break; - - case OID_802_11_BSSID_LIST_SCAN: - CntlOidScanProc(pAd, Elem); - break; - - case OID_802_11_DISASSOCIATE: - DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, - REASON_DISASSOC_STA_LEAVING); - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, - sizeof(struct rt_mlme_disassoc_req), &DisassocReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC; - - if (pAd->StaCfg.WpaSupplicantUP != - WPA_SUPPLICANT_ENABLE_WITH_WEB_UI) { - /* Set the AutoReconnectSsid to prevent it reconnect to old SSID */ - /* Since calling this indicate user don't want to connect to that SSID anymore. */ - pAd->MlmeAux.AutoReconnectSsidLen = 32; - NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, - pAd->MlmeAux.AutoReconnectSsidLen); - } - break; - - case MT2_MLME_ROAMING_REQ: - CntlMlmeRoamingProc(pAd, Elem); - break; - - case OID_802_11_MIC_FAILURE_REPORT_FRAME: - WpaMicFailureReportFrame(pAd, Elem); - break; - - default: - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - Illegal message in CntlIdleProc(MsgType=%ld)\n", - Elem->MsgType)); - break; - } -} - -void CntlOidScanProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_mlme_scan_req ScanReq; - unsigned long BssIdx = BSS_NOT_FOUND; - struct rt_bss_entry CurrBss; - - /* record current BSS if network is connected. */ - /* 2003-2-13 do not include current IBSS if this is the only STA in this IBSS. */ - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) { - BssIdx = - BssSsidTableSearch(&pAd->ScanTab, pAd->CommonCfg.Bssid, - (u8 *)pAd->CommonCfg.Ssid, - pAd->CommonCfg.SsidLen, - pAd->CommonCfg.Channel); - if (BssIdx != BSS_NOT_FOUND) { - NdisMoveMemory(&CurrBss, &pAd->ScanTab.BssEntry[BssIdx], - sizeof(struct rt_bss_entry)); - } - } - /* clean up previous SCAN result, add current BSS back to table if any */ - BssTableInit(&pAd->ScanTab); - if (BssIdx != BSS_NOT_FOUND) { - /* DDK Note: If the NIC is associated with a particular BSSID and SSID */ - /* that are not contained in the list of BSSIDs generated by this scan, the */ - /* BSSID description of the currently associated BSSID and SSID should be */ - /* appended to the list of BSSIDs in the NIC's database. */ - /* To ensure this, we append this BSS as the first entry in SCAN result */ - NdisMoveMemory(&pAd->ScanTab.BssEntry[0], &CurrBss, - sizeof(struct rt_bss_entry)); - pAd->ScanTab.BssNr = 1; - } - - ScanParmFill(pAd, &ScanReq, (char *)Elem->Msg, Elem->MsgLen, BSS_ANY, - SCAN_ACTIVE); - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, - sizeof(struct rt_mlme_scan_req), &ScanReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN; -} - -/* - ========================================================================== - Description: - Before calling this routine, user desired SSID should already been - recorded in CommonCfg.Ssid[] - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void CntlOidSsidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_ndis_802_11_ssid * pOidSsid = (struct rt_ndis_802_11_ssid *) Elem->Msg; - struct rt_mlme_disassoc_req DisassocReq; - unsigned long Now; - - /* Step 1. record the desired user settings to MlmeAux */ - NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID); - NdisMoveMemory(pAd->MlmeAux.Ssid, pOidSsid->Ssid, pOidSsid->SsidLength); - pAd->MlmeAux.SsidLen = (u8)pOidSsid->SsidLength; - NdisZeroMemory(pAd->MlmeAux.Bssid, MAC_ADDR_LEN); - pAd->MlmeAux.BssType = pAd->StaCfg.BssType; - - pAd->StaCfg.bAutoConnectByBssid = FALSE; - - /* */ - /* Update Reconnect Ssid, that user desired to connect. */ - /* */ - NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID); - NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, pAd->MlmeAux.Ssid, - pAd->MlmeAux.SsidLen); - pAd->MlmeAux.AutoReconnectSsidLen = pAd->MlmeAux.SsidLen; - - /* step 2. find all matching BSS in the lastest SCAN result (inBssTab) */ - /* & log them into MlmeAux.SsidBssTab for later-on iteration. Sort by RSSI order */ - BssTableSsidSort(pAd, &pAd->MlmeAux.SsidBssTab, - (char *)pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen); - - DBGPRINT(RT_DEBUG_TRACE, - ("CntlOidSsidProc():CNTL - %d BSS of %d BSS match the desire (%d)SSID - %s\n", - pAd->MlmeAux.SsidBssTab.BssNr, pAd->ScanTab.BssNr, - pAd->MlmeAux.SsidLen, pAd->MlmeAux.Ssid)); - NdisGetSystemUpTime(&Now); - - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) && - (pAd->CommonCfg.SsidLen == - pAd->MlmeAux.SsidBssTab.BssEntry[0].SsidLen) - && NdisEqualMemory(pAd->CommonCfg.Ssid, - pAd->MlmeAux.SsidBssTab.BssEntry[0].Ssid, - pAd->CommonCfg.SsidLen) - && MAC_ADDR_EQUAL(pAd->CommonCfg.Bssid, - pAd->MlmeAux.SsidBssTab.BssEntry[0].Bssid)) { - /* Case 1. already connected with an AP who has the desired SSID */ - /* with highest RSSI */ - - /* Add checking Mode "LEAP" for CCX 1.0 */ - if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) - ) && - (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)) { - /* case 1.1 For WPA, WPA-PSK, if the 1x port is not secured, we have to redo */ - /* connection process */ - DBGPRINT(RT_DEBUG_TRACE, - ("CntlOidSsidProc():CNTL - disassociate with current AP...\n")); - DisassocParmFill(pAd, &DisassocReq, - pAd->CommonCfg.Bssid, - REASON_DISASSOC_STA_LEAVING); - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, - MT2_MLME_DISASSOC_REQ, - sizeof(struct rt_mlme_disassoc_req), - &DisassocReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC; - } else if (pAd->bConfigChanged == TRUE) { - /* case 1.2 Important Config has changed, we have to reconnect to the same AP */ - DBGPRINT(RT_DEBUG_TRACE, - ("CntlOidSsidProc():CNTL - disassociate with current AP Because config changed...\n")); - DisassocParmFill(pAd, &DisassocReq, - pAd->CommonCfg.Bssid, - REASON_DISASSOC_STA_LEAVING); - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, - MT2_MLME_DISASSOC_REQ, - sizeof(struct rt_mlme_disassoc_req), - &DisassocReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC; - } else { - /* case 1.3. already connected to the SSID with highest RSSI. */ - DBGPRINT(RT_DEBUG_TRACE, - ("CntlOidSsidProc():CNTL - already with this BSSID. ignore this SET_SSID request\n")); - /* */ - /* (HCT 12.1) 1c_wlan_mediaevents required */ - /* media connect events are indicated when associating with the same AP */ - /* */ - if (INFRA_ON(pAd)) { - /* */ - /* Since MediaState already is NdisMediaStateConnected */ - /* We just indicate the connect event again to meet the WHQL required. */ - /* */ - pAd->IndicateMediaState = - NdisMediaStateConnected; - RTMP_IndicateMediaState(pAd); - pAd->ExtraInfo = GENERAL_LINK_UP; /* Update extra information to link is up */ - } - - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, - &pAd->MlmeAux.Bssid[0], NULL, - 0); - } - } else if (INFRA_ON(pAd)) { - /* */ - /* For RT61 */ - /* [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: ) */ - /* RT61 may lost SSID, and not connect to NDTEST_WEP_AP2 and will connect to NDTEST_WEP_AP2 by Autoreconnect */ - /* But media status is connected, so the SSID not report correctly. */ - /* */ - if (!SSID_EQUAL - (pAd->CommonCfg.Ssid, pAd->CommonCfg.SsidLen, - pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen)) { - /* */ - /* Different SSID means not Roaming case, so we let LinkDown() to Indicate a disconnect event. */ - /* */ - pAd->MlmeAux.CurrReqIsFromNdis = TRUE; - } - /* case 2. active INFRA association existent */ - /* roaming is done within miniport driver, nothing to do with configuration */ - /* utility. so upon a new SET(OID_802_11_SSID) is received, we just */ - /* disassociate with the current associated AP, */ - /* then perform a new association with this new SSID, no matter the */ - /* new/old SSID are the same or not. */ - DBGPRINT(RT_DEBUG_TRACE, - ("CntlOidSsidProc():CNTL - disassociate with current AP...\n")); - DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, - REASON_DISASSOC_STA_LEAVING); - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, - sizeof(struct rt_mlme_disassoc_req), &DisassocReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC; - } else { - if (ADHOC_ON(pAd)) { - DBGPRINT(RT_DEBUG_TRACE, - ("CntlOidSsidProc():CNTL - drop current ADHOC\n")); - LinkDown(pAd, FALSE); - OPSTATUS_CLEAR_FLAG(pAd, - fOP_STATUS_MEDIA_STATE_CONNECTED); - pAd->IndicateMediaState = NdisMediaStateDisconnected; - RTMP_IndicateMediaState(pAd); - pAd->ExtraInfo = GENERAL_LINK_DOWN; - DBGPRINT(RT_DEBUG_TRACE, - ("CntlOidSsidProc():NDIS_STATUS_MEDIA_DISCONNECT Event C!\n")); - } - - if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) && - (pAd->StaCfg.bAutoReconnect == TRUE) && - (pAd->MlmeAux.BssType == BSS_INFRA) && - (MlmeValidateSSID(pAd->MlmeAux.Ssid, pAd->MlmeAux.SsidLen) - == TRUE) - ) { - struct rt_mlme_scan_req ScanReq; - - DBGPRINT(RT_DEBUG_TRACE, - ("CntlOidSsidProc():CNTL - No matching BSS, start a new scan\n")); - ScanParmFill(pAd, &ScanReq, (char *)pAd->MlmeAux.Ssid, - pAd->MlmeAux.SsidLen, BSS_ANY, - SCAN_ACTIVE); - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, - sizeof(struct rt_mlme_scan_req), &ScanReq); - pAd->Mlme.CntlMachine.CurrState = - CNTL_WAIT_OID_LIST_SCAN; - /* Reset Missed scan number */ - pAd->StaCfg.LastScanTime = Now; - } else { - pAd->MlmeAux.BssIdx = 0; - IterateOnBssTab(pAd); - } - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void CntlOidRTBssidProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - unsigned long BssIdx; - u8 *pOidBssid = (u8 *)Elem->Msg; - struct rt_mlme_disassoc_req DisassocReq; - struct rt_mlme_join_req JoinReq; - - /* record user desired settings */ - COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pOidBssid); - pAd->MlmeAux.BssType = pAd->StaCfg.BssType; - - /* find the desired BSS in the latest SCAN result table */ - BssIdx = BssTableSearch(&pAd->ScanTab, pOidBssid, pAd->MlmeAux.Channel); - if (BssIdx == BSS_NOT_FOUND) { - struct rt_mlme_scan_req ScanReq; - - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - BSSID not found. reply NDIS_STATUS_NOT_ACCEPTED\n")); - /*pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; */ - - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - BSSID not found. start a new scan\n")); - ScanParmFill(pAd, &ScanReq, (char *)pAd->MlmeAux.Ssid, - pAd->MlmeAux.SsidLen, BSS_ANY, SCAN_ACTIVE); - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_SCAN_REQ, - sizeof(struct rt_mlme_scan_req), &ScanReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_LIST_SCAN; - /* Reset Missed scan number */ - NdisGetSystemUpTime(&pAd->StaCfg.LastScanTime); - return; - } - /* */ - /* Update Reconnect Ssid, that user desired to connect. */ - /* */ - NdisZeroMemory(pAd->MlmeAux.AutoReconnectSsid, MAX_LEN_OF_SSID); - pAd->MlmeAux.AutoReconnectSsidLen = - pAd->ScanTab.BssEntry[BssIdx].SsidLen; - NdisMoveMemory(pAd->MlmeAux.AutoReconnectSsid, - pAd->ScanTab.BssEntry[BssIdx].Ssid, - pAd->ScanTab.BssEntry[BssIdx].SsidLen); - - /* copy the matched BSS entry from ScanTab to MlmeAux.SsidBssTab. Why? */ - /* Because we need this entry to become the JOIN target in later on SYNC state machine */ - pAd->MlmeAux.BssIdx = 0; - pAd->MlmeAux.SsidBssTab.BssNr = 1; - NdisMoveMemory(&pAd->MlmeAux.SsidBssTab.BssEntry[0], - &pAd->ScanTab.BssEntry[BssIdx], sizeof(struct rt_bss_entry)); - - /* Add SSID into MlmeAux for site survey joining hidden SSID */ - pAd->MlmeAux.SsidLen = pAd->ScanTab.BssEntry[BssIdx].SsidLen; - NdisMoveMemory(pAd->MlmeAux.Ssid, pAd->ScanTab.BssEntry[BssIdx].Ssid, - pAd->MlmeAux.SsidLen); - - { - if (INFRA_ON(pAd)) { - /* disassoc from current AP first */ - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - disassociate with current AP ...\n")); - DisassocParmFill(pAd, &DisassocReq, - pAd->CommonCfg.Bssid, - REASON_DISASSOC_STA_LEAVING); - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, - MT2_MLME_DISASSOC_REQ, - sizeof(struct rt_mlme_disassoc_req), - &DisassocReq); - - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC; - } else { - if (ADHOC_ON(pAd)) { - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - drop current ADHOC\n")); - LinkDown(pAd, FALSE); - OPSTATUS_CLEAR_FLAG(pAd, - fOP_STATUS_MEDIA_STATE_CONNECTED); - pAd->IndicateMediaState = - NdisMediaStateDisconnected; - RTMP_IndicateMediaState(pAd); - pAd->ExtraInfo = GENERAL_LINK_DOWN; - DBGPRINT(RT_DEBUG_TRACE, - ("NDIS_STATUS_MEDIA_DISCONNECT Event C!\n")); - } - /* Change the wepstatus to original wepstatus */ - pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus; - pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus; - pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus; - - /* Check cipher suite, AP must have more secured cipher than station setting */ - /* Set the Pairwise and Group cipher to match the intended AP setting */ - /* We can only connect to AP with less secured cipher setting */ - if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) - || (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPAPSK)) { - pAd->StaCfg.GroupCipher = - pAd->ScanTab.BssEntry[BssIdx].WPA. - GroupCipher; - - if (pAd->StaCfg.WepStatus == - pAd->ScanTab.BssEntry[BssIdx].WPA. - PairCipher) - pAd->StaCfg.PairCipher = - pAd->ScanTab.BssEntry[BssIdx].WPA. - PairCipher; - else if (pAd->ScanTab.BssEntry[BssIdx].WPA. - PairCipherAux != Ndis802_11WEPDisabled) - pAd->StaCfg.PairCipher = - pAd->ScanTab.BssEntry[BssIdx].WPA. - PairCipherAux; - else /* There is no PairCipher Aux, downgrade our capability to TKIP */ - pAd->StaCfg.PairCipher = - Ndis802_11Encryption2Enabled; - } else - if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) - || (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA2PSK)) { - pAd->StaCfg.GroupCipher = - pAd->ScanTab.BssEntry[BssIdx].WPA2. - GroupCipher; - - if (pAd->StaCfg.WepStatus == - pAd->ScanTab.BssEntry[BssIdx].WPA2. - PairCipher) - pAd->StaCfg.PairCipher = - pAd->ScanTab.BssEntry[BssIdx].WPA2. - PairCipher; - else if (pAd->ScanTab.BssEntry[BssIdx].WPA2. - PairCipherAux != Ndis802_11WEPDisabled) - pAd->StaCfg.PairCipher = - pAd->ScanTab.BssEntry[BssIdx].WPA2. - PairCipherAux; - else /* There is no PairCipher Aux, downgrade our capability to TKIP */ - pAd->StaCfg.PairCipher = - Ndis802_11Encryption2Enabled; - - /* RSN capability */ - pAd->StaCfg.RsnCapability = - pAd->ScanTab.BssEntry[BssIdx].WPA2. - RsnCapability; - } - /* Set Mix cipher flag */ - pAd->StaCfg.bMixCipher = - (pAd->StaCfg.PairCipher == - pAd->StaCfg.GroupCipher) ? FALSE : TRUE; - /*if (pAd->StaCfg.bMixCipher == TRUE) - { - // If mix cipher, re-build RSNIE - RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0); - } */ - /* No active association, join the BSS immediately */ - DBGPRINT(RT_DEBUG_TRACE, ("CNTL - joining %pM ...\n", - pOidBssid)); - - JoinParmFill(pAd, &JoinReq, pAd->MlmeAux.BssIdx); - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, - sizeof(struct rt_mlme_join_req), &JoinReq); - - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN; - } - } -} - -/* Roaming is the only external request triggering CNTL state machine */ -/* despite of other "SET OID" operation. All "SET OID" related operations */ -/* happen in sequence, because no other SET OID will be sent to this device */ -/* until the the previous SET operation is complete (successful o failed). */ -/* So, how do we quarantee this ROAMING request won't corrupt other "SET OID"? */ -/* or been corrupted by other "SET OID"? */ -/* */ -/* IRQL = DISPATCH_LEVEL */ -void CntlMlmeRoamingProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 BBPValue = 0; - - DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Roaming in MlmeAux.RoamTab...\n")); - - { - /*Let BBP register at 20MHz to do (fast) roaming. */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); - BBPValue &= (~0x18); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); - - NdisMoveMemory(&pAd->MlmeAux.SsidBssTab, &pAd->MlmeAux.RoamTab, - sizeof(pAd->MlmeAux.RoamTab)); - pAd->MlmeAux.SsidBssTab.BssNr = pAd->MlmeAux.RoamTab.BssNr; - - BssTableSortByRssi(&pAd->MlmeAux.SsidBssTab); - pAd->MlmeAux.BssIdx = 0; - IterateOnBssTab(pAd); - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void CntlWaitDisassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - struct rt_mlme_start_req StartReq; - - if (Elem->MsgType == MT2_DISASSOC_CONF) { - DBGPRINT(RT_DEBUG_TRACE, ("CNTL - Dis-associate successful\n")); - - if (pAd->CommonCfg.bWirelessEvent) { - RTMPSendWirelessEvent(pAd, IW_DISASSOC_EVENT_FLAG, - pAd->MacTab.Content[BSSID_WCID]. - Addr, BSS0, 0); - } - - LinkDown(pAd, FALSE); - - /* case 1. no matching BSS, and user wants ADHOC, so we just start a new one */ - if ((pAd->MlmeAux.SsidBssTab.BssNr == 0) - && (pAd->StaCfg.BssType == BSS_ADHOC)) { - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - No matching BSS, start a new ADHOC (Ssid=%s)...\n", - pAd->MlmeAux.Ssid)); - StartParmFill(pAd, &StartReq, (char *)pAd->MlmeAux.Ssid, - pAd->MlmeAux.SsidLen); - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, - sizeof(struct rt_mlme_start_req), &StartReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START; - } - /* case 2. try each matched BSS */ - else { - pAd->MlmeAux.BssIdx = 0; - - IterateOnBssTab(pAd); - } - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void CntlWaitJoinProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Reason; - struct rt_mlme_auth_req AuthReq; - - if (Elem->MsgType == MT2_JOIN_CONF) { - NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16)); - if (Reason == MLME_SUCCESS) { - /* 1. joined an IBSS, we are pretty much done here */ - if (pAd->MlmeAux.BssType == BSS_ADHOC) { - /* */ - /* 5G bands rules of Japan: */ - /* Ad hoc must be disabled in W53(ch52,56,60,64) channels. */ - /* */ - if ((pAd->CommonCfg.bIEEE80211H == 1) && - RadarChannelCheck(pAd, - pAd->CommonCfg.Channel) - ) { - pAd->Mlme.CntlMachine.CurrState = - CNTL_IDLE; - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - Channel=%d, Join adhoc on W53(52,56,60,64) Channels are not accepted\n", - pAd->CommonCfg.Channel)); - return; - } - - LinkUp(pAd, BSS_ADHOC); - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - join the IBSS = %pM ...\n", - pAd->CommonCfg.Bssid)); - - pAd->IndicateMediaState = - NdisMediaStateConnected; - pAd->ExtraInfo = GENERAL_LINK_UP; - } - /* 2. joined a new INFRA network, start from authentication */ - else { - { - /* either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first */ - if ((pAd->StaCfg.AuthMode == - Ndis802_11AuthModeShared) - || (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeAutoSwitch)) { - AuthParmFill(pAd, &AuthReq, - pAd->MlmeAux.Bssid, - AUTH_MODE_KEY); - } else { - AuthParmFill(pAd, &AuthReq, - pAd->MlmeAux.Bssid, - AUTH_MODE_OPEN); - } - MlmeEnqueue(pAd, AUTH_STATE_MACHINE, - MT2_MLME_AUTH_REQ, - sizeof - (struct rt_mlme_auth_req), - &AuthReq); - } - - pAd->Mlme.CntlMachine.CurrState = - CNTL_WAIT_AUTH; - } - } else { - /* 3. failed, try next BSS */ - pAd->MlmeAux.BssIdx++; - IterateOnBssTab(pAd); - } - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void CntlWaitStartProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Result; - - if (Elem->MsgType == MT2_START_CONF) { - NdisMoveMemory(&Result, Elem->Msg, sizeof(u16)); - if (Result == MLME_SUCCESS) { - /* */ - /* 5G bands rules of Japan: */ - /* Ad hoc must be disabled in W53(ch52,56,60,64) channels. */ - /* */ - if ((pAd->CommonCfg.bIEEE80211H == 1) && - RadarChannelCheck(pAd, pAd->CommonCfg.Channel) - ) { - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - Channel=%d, Start adhoc on W53(52,56,60,64) Channels are not accepted\n", - pAd->CommonCfg.Channel)); - return; - } - NdisZeroMemory(&pAd->StaActive.SupportedPhyInfo. - MCSSet[0], 16); - if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) { - N_ChannelCheck(pAd); - SetCommonHT(pAd); - NdisMoveMemory(&pAd->MlmeAux.AddHtInfo, - &pAd->CommonCfg.AddHTInfo, - sizeof(struct rt_add_ht_info_ie)); - RTMPCheckHt(pAd, BSSID_WCID, - &pAd->CommonCfg.HtCapability, - &pAd->CommonCfg.AddHTInfo); - pAd->StaActive.SupportedPhyInfo.bHtEnable = - TRUE; - NdisMoveMemory(&pAd->StaActive.SupportedPhyInfo. - MCSSet[0], - &pAd->CommonCfg.HtCapability. - MCSSet[0], 16); - COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG - (pAd); - - if ((pAd->CommonCfg.HtCapability.HtCapInfo. - ChannelWidth == BW_40) - && (pAd->CommonCfg.AddHTInfo.AddHtInfo. - ExtChanOffset == EXTCHA_ABOVE)) { - pAd->MlmeAux.CentralChannel = - pAd->CommonCfg.Channel + 2; - } else - if ((pAd->CommonCfg.HtCapability.HtCapInfo. - ChannelWidth == BW_40) - && (pAd->CommonCfg.AddHTInfo.AddHtInfo. - ExtChanOffset == EXTCHA_BELOW)) { - pAd->MlmeAux.CentralChannel = - pAd->CommonCfg.Channel - 2; - } - } else { - pAd->StaActive.SupportedPhyInfo.bHtEnable = - FALSE; - } - LinkUp(pAd, BSS_ADHOC); - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - /* Before send beacon, driver need do radar detection */ - if ((pAd->CommonCfg.Channel > 14) - && (pAd->CommonCfg.bIEEE80211H == 1) - && RadarChannelCheck(pAd, pAd->CommonCfg.Channel)) { - pAd->CommonCfg.RadarDetect.RDMode = - RD_SILENCE_MODE; - pAd->CommonCfg.RadarDetect.RDCount = 0; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - start a new IBSS = %pM ...\n", - pAd->CommonCfg.Bssid)); - } else { - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - Start IBSS fail. BUG!\n")); - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - } - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void CntlWaitAuthProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Reason; - struct rt_mlme_assoc_req AssocReq; - struct rt_mlme_auth_req AuthReq; - - if (Elem->MsgType == MT2_AUTH_CONF) { - NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16)); - if (Reason == MLME_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n")); - AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, - pAd->MlmeAux.CapabilityInfo, - ASSOC_TIMEOUT, - pAd->StaCfg.DefaultListenCount); - - { - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, - MT2_MLME_ASSOC_REQ, - sizeof(struct rt_mlme_assoc_req), - &AssocReq); - - pAd->Mlme.CntlMachine.CurrState = - CNTL_WAIT_ASSOC; - } - } else { - /* This fail may because of the AP already keep us in its MAC table without */ - /* ageing-out. The previous authentication attempt must have let it remove us. */ - /* so try Authentication again may help. For D-Link DWL-900AP+ compatibility. */ - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - AUTH FAIL, try again...\n")); - - { - if ((pAd->StaCfg.AuthMode == - Ndis802_11AuthModeShared) - || (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeAutoSwitch)) { - /* either Ndis802_11AuthModeShared or Ndis802_11AuthModeAutoSwitch, try shared key first */ - AuthParmFill(pAd, &AuthReq, - pAd->MlmeAux.Bssid, - AUTH_MODE_KEY); - } else { - AuthParmFill(pAd, &AuthReq, - pAd->MlmeAux.Bssid, - AUTH_MODE_OPEN); - } - MlmeEnqueue(pAd, AUTH_STATE_MACHINE, - MT2_MLME_AUTH_REQ, - sizeof(struct rt_mlme_auth_req), - &AuthReq); - - } - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_AUTH2; - } - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void CntlWaitAuthProc2(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Reason; - struct rt_mlme_assoc_req AssocReq; - struct rt_mlme_auth_req AuthReq; - - if (Elem->MsgType == MT2_AUTH_CONF) { - NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16)); - if (Reason == MLME_SUCCESS) { - DBGPRINT(RT_DEBUG_TRACE, ("CNTL - AUTH OK\n")); - AssocParmFill(pAd, &AssocReq, pAd->MlmeAux.Bssid, - pAd->MlmeAux.CapabilityInfo, - ASSOC_TIMEOUT, - pAd->StaCfg.DefaultListenCount); - { - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, - MT2_MLME_ASSOC_REQ, - sizeof(struct rt_mlme_assoc_req), - &AssocReq); - - pAd->Mlme.CntlMachine.CurrState = - CNTL_WAIT_ASSOC; - } - } else { - if ((pAd->StaCfg.AuthMode == - Ndis802_11AuthModeAutoSwitch) - && (pAd->MlmeAux.Alg == Ndis802_11AuthModeShared)) { - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - AUTH FAIL, try OPEN system...\n")); - AuthParmFill(pAd, &AuthReq, pAd->MlmeAux.Bssid, - Ndis802_11AuthModeOpen); - MlmeEnqueue(pAd, AUTH_STATE_MACHINE, - MT2_MLME_AUTH_REQ, - sizeof(struct rt_mlme_auth_req), - &AuthReq); - - pAd->Mlme.CntlMachine.CurrState = - CNTL_WAIT_AUTH2; - } else { - /* not success, try next BSS */ - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - AUTH FAIL, give up; try next BSS\n")); - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; /*??????? */ - pAd->MlmeAux.BssIdx++; - IterateOnBssTab(pAd); - } - } - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void CntlWaitAssocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Reason; - - if (Elem->MsgType == MT2_ASSOC_CONF) { - NdisMoveMemory(&Reason, Elem->Msg, sizeof(u16)); - if (Reason == MLME_SUCCESS) { - if (pAd->CommonCfg.bWirelessEvent) { - RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, - pAd->MacTab. - Content[BSSID_WCID].Addr, - BSS0, 0); - } - - LinkUp(pAd, BSS_INFRA); - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - Association successful on BSS #%ld\n", - pAd->MlmeAux.BssIdx)); - } else { - /* not success, try next BSS */ - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - Association fails on BSS #%ld\n", - pAd->MlmeAux.BssIdx)); - pAd->MlmeAux.BssIdx++; - IterateOnBssTab(pAd); - } - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void CntlWaitReassocProc(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Result; - - if (Elem->MsgType == MT2_REASSOC_CONF) { - NdisMoveMemory(&Result, Elem->Msg, sizeof(u16)); - if (Result == MLME_SUCCESS) { - /* send wireless event - for association */ - if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, IW_ASSOC_EVENT_FLAG, - pAd->MacTab. - Content[BSSID_WCID].Addr, - BSS0, 0); - - /* */ - /* NDIS requires a new Link UP indication but no Link Down for RE-ASSOC */ - /* */ - LinkUp(pAd, BSS_INFRA); - - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - Re-assocition successful on BSS #%ld\n", - pAd->MlmeAux.RoamIdx)); - } else { - /* reassoc failed, try to pick next BSS in the BSS Table */ - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - Re-assocition fails on BSS #%ld\n", - pAd->MlmeAux.RoamIdx)); - { - pAd->MlmeAux.RoamIdx++; - IterateOnBssTab2(pAd); - } - } - } -} - -void AdhocTurnOnQos(struct rt_rtmp_adapter *pAd) -{ -#define AC0_DEF_TXOP 0 -#define AC1_DEF_TXOP 0 -#define AC2_DEF_TXOP 94 -#define AC3_DEF_TXOP 47 - - /* Turn on QOs if use HT rate. */ - if (pAd->CommonCfg.APEdcaParm.bValid == FALSE) { - pAd->CommonCfg.APEdcaParm.bValid = TRUE; - pAd->CommonCfg.APEdcaParm.Aifsn[0] = 3; - pAd->CommonCfg.APEdcaParm.Aifsn[1] = 7; - pAd->CommonCfg.APEdcaParm.Aifsn[2] = 1; - pAd->CommonCfg.APEdcaParm.Aifsn[3] = 1; - - pAd->CommonCfg.APEdcaParm.Cwmin[0] = 4; - pAd->CommonCfg.APEdcaParm.Cwmin[1] = 4; - pAd->CommonCfg.APEdcaParm.Cwmin[2] = 3; - pAd->CommonCfg.APEdcaParm.Cwmin[3] = 2; - - pAd->CommonCfg.APEdcaParm.Cwmax[0] = 10; - pAd->CommonCfg.APEdcaParm.Cwmax[1] = 6; - pAd->CommonCfg.APEdcaParm.Cwmax[2] = 4; - pAd->CommonCfg.APEdcaParm.Cwmax[3] = 3; - - pAd->CommonCfg.APEdcaParm.Txop[0] = 0; - pAd->CommonCfg.APEdcaParm.Txop[1] = 0; - pAd->CommonCfg.APEdcaParm.Txop[2] = AC2_DEF_TXOP; - pAd->CommonCfg.APEdcaParm.Txop[3] = AC3_DEF_TXOP; - } - AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm); -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void LinkUp(struct rt_rtmp_adapter *pAd, u8 BssType) -{ - unsigned long Now; - u32 Data; - BOOLEAN Cancelled; - u8 Value = 0, idx = 0, HashIdx = 0; - struct rt_mac_table_entry *pEntry = NULL, *pCurrEntry = NULL; - - /* Init ChannelQuality to prevent DEAD_CQI at initial LinkUp */ - pAd->Mlme.ChannelQuality = 50; - - pEntry = MacTableLookup(pAd, pAd->CommonCfg.Bssid); - if (pEntry) { - MacTableDeleteEntry(pAd, pEntry->Aid, pEntry->Addr); - pEntry = NULL; - } - - pEntry = &pAd->MacTab.Content[BSSID_WCID]; - - /* */ - /* ASSOC - DisassocTimeoutAction */ - /* CNTL - Dis-associate successful */ - /* ! LINK DOWN ! */ - /* [88888] OID_802_11_SSID should have returned NDTEST_WEP_AP2(Returned: ) */ - /* */ - /* To prevent DisassocTimeoutAction to call Link down after we link up, */ - /* cancel the DisassocTimer no matter what it start or not. */ - /* */ - RTMPCancelTimer(&pAd->MlmeAux.DisassocTimer, &Cancelled); - - COPY_SETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd); - - COPY_HTSETTINGS_FROM_MLME_AUX_TO_ACTIVE_CFG(pAd); - -#ifdef RTMP_MAC_PCI - /* Before power save before link up function, We will force use 1R. */ - /* So after link up, check Rx antenna # again. */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value); - if (pAd->Antenna.field.RxPath == 3) { - Value |= (0x10); - } else if (pAd->Antenna.field.RxPath == 2) { - Value |= (0x8); - } else if (pAd->Antenna.field.RxPath == 1) { - Value |= (0x0); - } - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value); - pAd->StaCfg.BBPR3 = Value; -#endif /* RTMP_MAC_PCI // */ - - if (BssType == BSS_ADHOC) { - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_ADHOC_ON); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON); - - if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) - AdhocTurnOnQos(pAd); - - DBGPRINT(RT_DEBUG_TRACE, ("Adhoc LINK UP!\n")); - } else { - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_INFRA_ON); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON); - - DBGPRINT(RT_DEBUG_TRACE, ("Infra LINK UP!\n")); - } - - /* 3*3 */ - /* reset Tx beamforming bit */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value); - Value &= (~0x01); - Value |= pAd->CommonCfg.RegTransmitSetting.field.TxBF; - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value); - - /* Change to AP channel */ - if ((pAd->CommonCfg.CentralChannel > pAd->CommonCfg.Channel) - && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == BW_40)) { - /* Must use 40MHz. */ - pAd->CommonCfg.BBPCurrentBW = BW_40; - AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); - - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value); - Value &= (~0x18); - Value |= 0x10; - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value); - - /* RX : control channel at lower */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value); - Value &= (~0x20); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value); -#ifdef RTMP_MAC_PCI - pAd->StaCfg.BBPR3 = Value; -#endif /* RTMP_MAC_PCI // */ - - RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data); - Data &= 0xfffffffe; - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data); - - if (pAd->MACVersion == 0x28600100) { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16); - DBGPRINT(RT_DEBUG_TRACE, ("rt2860C !\n")); - } - - DBGPRINT(RT_DEBUG_TRACE, - ("40MHz Lower LINK UP! Control Channel at Below. Central = %d \n", - pAd->CommonCfg.CentralChannel)); - } else if ((pAd->CommonCfg.CentralChannel < pAd->CommonCfg.Channel) - && (pAd->MlmeAux.HtCapability.HtCapInfo.ChannelWidth == - BW_40)) { - /* Must use 40MHz. */ - pAd->CommonCfg.BBPCurrentBW = BW_40; - AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); - - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value); - Value &= (~0x18); - Value |= 0x10; - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value); - - RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data); - Data |= 0x1; - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data); - - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value); - Value |= (0x20); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value); -#ifdef RTMP_MAC_PCI - pAd->StaCfg.BBPR3 = Value; -#endif /* RTMP_MAC_PCI // */ - - if (pAd->MACVersion == 0x28600100) { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x1A); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x0A); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x16); - DBGPRINT(RT_DEBUG_TRACE, ("rt2860C !\n")); - } - - DBGPRINT(RT_DEBUG_TRACE, - ("40MHz Upper LINK UP! Control Channel at UpperCentral = %d \n", - pAd->CommonCfg.CentralChannel)); - } else { - pAd->CommonCfg.BBPCurrentBW = BW_20; - pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel; - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.Channel); - - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &Value); - Value &= (~0x18); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, Value); - - RTMP_IO_READ32(pAd, TX_BAND_CFG, &Data); - Data &= 0xfffffffe; - RTMP_IO_WRITE32(pAd, TX_BAND_CFG, Data); - - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R3, &Value); - Value &= (~0x20); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R3, Value); -#ifdef RTMP_MAC_PCI - pAd->StaCfg.BBPR3 = Value; -#endif /* RTMP_MAC_PCI // */ - - if (pAd->MACVersion == 0x28600100) { - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R69, 0x16); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R70, 0x08); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R73, 0x11); - DBGPRINT(RT_DEBUG_TRACE, ("rt2860C !\n")); - } - - DBGPRINT(RT_DEBUG_TRACE, ("20MHz LINK UP!\n")); - } - - RTMPSetAGCInitValue(pAd, pAd->CommonCfg.BBPCurrentBW); - - /* */ - /* Save BBP_R66 value, it will be used in RTUSBResumeMsduTransmission */ - /* */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R66, - &pAd->BbpTuning.R66CurrentValue); - - DBGPRINT(RT_DEBUG_TRACE, - ("LINK UP! (BssType=%d, AID=%d, ssid=%s, Channel=%d, CentralChannel = %d)\n", - BssType, pAd->StaActive.Aid, pAd->CommonCfg.Ssid, - pAd->CommonCfg.Channel, pAd->CommonCfg.CentralChannel)); - - DBGPRINT(RT_DEBUG_TRACE, - ("LINK UP! (Density =%d, )\n", - pAd->MacTab.Content[BSSID_WCID].MpduDensity)); - - AsicSetBssid(pAd, pAd->CommonCfg.Bssid); - - AsicSetSlotTime(pAd, TRUE); - AsicSetEdcaParm(pAd, &pAd->CommonCfg.APEdcaParm); - - /* Call this for RTS protection for legacy rate, we will always enable RTS threshold, but normally it will not hit */ - AsicUpdateProtect(pAd, 0, (OFDMSETPROTECT | CCKSETPROTECT), TRUE, - FALSE); - - if ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE)) { - /* Update HT protection for based on AP's operating mode. */ - if (pAd->MlmeAux.AddHtInfo.AddHtInfo2.NonGfPresent == 1) { - AsicUpdateProtect(pAd, - pAd->MlmeAux.AddHtInfo.AddHtInfo2. - OperaionMode, ALLN_SETPROTECT, FALSE, - TRUE); - } else - AsicUpdateProtect(pAd, - pAd->MlmeAux.AddHtInfo.AddHtInfo2. - OperaionMode, ALLN_SETPROTECT, FALSE, - FALSE); - } - - NdisZeroMemory(&pAd->DrsCounters, sizeof(struct rt_counter_drs)); - - NdisGetSystemUpTime(&Now); - pAd->StaCfg.LastBeaconRxTime = Now; /* last RX timestamp */ - - if ((pAd->CommonCfg.TxPreamble != Rt802_11PreambleLong) && - CAP_IS_SHORT_PREAMBLE_ON(pAd->StaActive.CapabilityInfo)) { - MlmeSetTxPreamble(pAd, Rt802_11PreambleShort); - } - - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED); - - if (pAd->CommonCfg.RadarDetect.RDMode == RD_SILENCE_MODE) { - } - pAd->CommonCfg.RadarDetect.RDMode = RD_NORMAL_MODE; - - if (BssType == BSS_ADHOC) { - MakeIbssBeacon(pAd); - if ((pAd->CommonCfg.Channel > 14) - && (pAd->CommonCfg.bIEEE80211H == 1) - && RadarChannelCheck(pAd, pAd->CommonCfg.Channel)) { - ; /*Do nothing */ - } else { - AsicEnableIbssSync(pAd); - } - - /* In ad hoc mode, use MAC table from index 1. */ - /* p.s ASIC use all 0xff as termination of WCID table search.To prevent it's 0xff-ff-ff-ff-ff-ff, Write 0 here. */ - RTMP_IO_WRITE32(pAd, MAC_WCID_BASE, 0x00); - RTMP_IO_WRITE32(pAd, 0x1808, 0x00); - - /* If WEP is enabled, add key material and cipherAlg into Asic */ - /* Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000) */ - - if (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) { - u8 *Key; - u8 CipherAlg; - - for (idx = 0; idx < SHARE_KEY_NUM; idx++) { - CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg; - Key = pAd->SharedKey[BSS0][idx].Key; - - if (pAd->SharedKey[BSS0][idx].KeyLen > 0) { - /* Set key material and cipherAlg to Asic */ - AsicAddSharedKeyEntry(pAd, BSS0, idx, - CipherAlg, Key, - NULL, NULL); - - if (idx == pAd->StaCfg.DefaultKeyId) { - /* Update WCID attribute table and IVEIV table for this group key table */ - RTMPAddWcidAttributeEntry(pAd, - BSS0, - idx, - CipherAlg, - NULL); - } - } - - } - } - /* If WPANone is enabled, add key material and cipherAlg into Asic */ - /* Fill in Shared Key Table(offset: 0x6c00) and Shared Key Mode(offset: 0x7000) */ - else if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) { - pAd->StaCfg.DefaultKeyId = 0; /* always be zero */ - - NdisZeroMemory(&pAd->SharedKey[BSS0][0], - sizeof(struct rt_cipher_key)); - pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK; - NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, - pAd->StaCfg.PMK, LEN_TKIP_EK); - - if (pAd->StaCfg.PairCipher == - Ndis802_11Encryption2Enabled) { - NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, - &pAd->StaCfg.PMK[16], - LEN_TKIP_RXMICK); - NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, - &pAd->StaCfg.PMK[16], - LEN_TKIP_TXMICK); - } - /* Decide its ChiperAlg */ - if (pAd->StaCfg.PairCipher == - Ndis802_11Encryption2Enabled) - pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP; - else if (pAd->StaCfg.PairCipher == - Ndis802_11Encryption3Enabled) - pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES; - else { - DBGPRINT(RT_DEBUG_TRACE, - ("Unknow Cipher (=%d), set Cipher to AES\n", - pAd->StaCfg.PairCipher)); - pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES; - } - - /* Set key material and cipherAlg to Asic */ - AsicAddSharedKeyEntry(pAd, - BSS0, - 0, - pAd->SharedKey[BSS0][0].CipherAlg, - pAd->SharedKey[BSS0][0].Key, - pAd->SharedKey[BSS0][0].TxMic, - pAd->SharedKey[BSS0][0].RxMic); - - /* Update WCID attribute table and IVEIV table for this group key table */ - RTMPAddWcidAttributeEntry(pAd, BSS0, 0, - pAd->SharedKey[BSS0][0]. - CipherAlg, NULL); - - } - - } else /* BSS_INFRA */ - { - /* Check the new SSID with last SSID */ - while (Cancelled == TRUE) { - if (pAd->CommonCfg.LastSsidLen == - pAd->CommonCfg.SsidLen) { - if (RTMPCompareMemory - (pAd->CommonCfg.LastSsid, - pAd->CommonCfg.Ssid, - pAd->CommonCfg.LastSsidLen) == 0) { - /* Link to the old one no linkdown is required. */ - break; - } - } - /* Send link down event before set to link up */ - pAd->IndicateMediaState = NdisMediaStateDisconnected; - RTMP_IndicateMediaState(pAd); - pAd->ExtraInfo = GENERAL_LINK_DOWN; - DBGPRINT(RT_DEBUG_TRACE, - ("NDIS_STATUS_MEDIA_DISCONNECT Event AA!\n")); - break; - } - - /* */ - /* On WPA mode, Remove All Keys if not connect to the last BSSID */ - /* Key will be set after 4-way handshake. */ - /* */ - if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) { - unsigned long IV; - - /* Remove all WPA keys */ - RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP); - RTMPWPARemoveAllKeys(pAd); - pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED; - pAd->StaCfg.PrivacyFilter = - Ndis802_11PrivFilter8021xWEP; - - /* Fixed connection failed with Range Maximizer - 515 AP (Marvell Chip) when security is WPAPSK/TKIP */ - /* If IV related values are too large in GroupMsg2, AP would ignore this message. */ - IV = 1; - IV |= (pAd->StaCfg.DefaultKeyId << 30); - AsicUpdateWCIDIVEIV(pAd, BSSID_WCID, IV, 0); - } - /* NOTE: */ - /* the decision of using "short slot time" or not may change dynamically due to */ - /* new STA association to the AP. so we have to decide that upon parsing BEACON, not here */ - - /* NOTE: */ - /* the decision to use "RTC/CTS" or "CTS-to-self" protection or not may change dynamically */ - /* due to new STA association to the AP. so we have to decide that upon parsing BEACON, not here */ - - ComposePsPoll(pAd); - ComposeNullFrame(pAd); - - AsicEnableBssSync(pAd); - - /* Add BSSID to WCID search table */ - AsicUpdateRxWCIDTable(pAd, BSSID_WCID, pAd->CommonCfg.Bssid); - - /* If WEP is enabled, add pairwise and shared key */ - if (((pAd->StaCfg.WpaSupplicantUP) && - (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) && - (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_SECURED)) || - ((pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_DISABLE) && - (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled))) { - u8 *Key; - u8 CipherAlg; - - for (idx = 0; idx < SHARE_KEY_NUM; idx++) { - CipherAlg = pAd->SharedKey[BSS0][idx].CipherAlg; - Key = pAd->SharedKey[BSS0][idx].Key; - - if (pAd->SharedKey[BSS0][idx].KeyLen > 0) { - /* Set key material and cipherAlg to Asic */ - AsicAddSharedKeyEntry(pAd, BSS0, idx, - CipherAlg, Key, - NULL, NULL); - - if (idx == pAd->StaCfg.DefaultKeyId) { - /* Assign group key info */ - RTMPAddWcidAttributeEntry(pAd, - BSS0, - idx, - CipherAlg, - NULL); - - pEntry->Aid = BSSID_WCID; - /* Assign pairwise key info */ - RTMPAddWcidAttributeEntry(pAd, - BSS0, - idx, - CipherAlg, - pEntry); - } - } - } - } - /* only INFRASTRUCTURE mode need to indicate connectivity immediately; ADHOC mode */ - /* should wait until at least 2 active nodes in this BSSID. */ - OPSTATUS_SET_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED); - - /* For GUI ++ */ - if (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA) { - pAd->IndicateMediaState = NdisMediaStateConnected; - pAd->ExtraInfo = GENERAL_LINK_UP; - RTMP_IndicateMediaState(pAd); - } else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK)) - { - if (pAd->StaCfg.WpaSupplicantUP == - WPA_SUPPLICANT_DISABLE) - RTMPSetTimer(&pAd->Mlme.LinkDownTimer, - LINK_DOWN_TIMEOUT); - } - /* -- */ - - /* Add BSSID in my MAC Table. */ - NdisAcquireSpinLock(&pAd->MacTabLock); - /* add this MAC entry into HASH table */ - if (pEntry) { - HashIdx = MAC_ADDR_HASH_INDEX(pAd->CommonCfg.Bssid); - if (pAd->MacTab.Hash[HashIdx] == NULL) { - pAd->MacTab.Hash[HashIdx] = pEntry; - } else { - pCurrEntry = pAd->MacTab.Hash[HashIdx]; - while (pCurrEntry->pNext != NULL) { - pCurrEntry = pCurrEntry->pNext; - } - pCurrEntry->pNext = pEntry; - } - } - RTMPMoveMemory(pEntry->Addr, pAd->CommonCfg.Bssid, - MAC_ADDR_LEN); - pEntry->Aid = BSSID_WCID; - pEntry->pAd = pAd; - pEntry->ValidAsCLI = TRUE; /*Although this is bssid..still set ValidAsCl */ - pAd->MacTab.Size = 1; /* infra mode always set MACtab size =1. */ - pEntry->Sst = SST_ASSOC; - pEntry->AuthState = SST_ASSOC; - pEntry->AuthMode = pAd->StaCfg.AuthMode; - pEntry->WepStatus = pAd->StaCfg.WepStatus; - if (pEntry->AuthMode < Ndis802_11AuthModeWPA) { - pEntry->WpaState = AS_NOTUSE; - pEntry->PrivacyFilter = Ndis802_11PrivFilterAcceptAll; - } else { - pEntry->WpaState = AS_PTKSTART; - pEntry->PrivacyFilter = Ndis802_11PrivFilter8021xWEP; - } - NdisReleaseSpinLock(&pAd->MacTabLock); - - DBGPRINT(RT_DEBUG_TRACE, - ("LINK UP! ClientStatusFlags=%lx)\n", - pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags)); - - MlmeUpdateTxRates(pAd, TRUE, BSS0); - MlmeUpdateHtTxRates(pAd, BSS0); - DBGPRINT(RT_DEBUG_TRACE, - ("LINK UP! (StaActive.bHtEnable =%d, )\n", - pAd->StaActive.SupportedPhyInfo.bHtEnable)); - - if (pAd->CommonCfg.bAggregationCapable) { - if ((pAd->CommonCfg.bPiggyBackCapable) - && (pAd->MlmeAux.APRalinkIe & 0x00000003) == 3) { - OPSTATUS_SET_FLAG(pAd, - fOP_STATUS_PIGGYBACK_INUSED); - OPSTATUS_SET_FLAG(pAd, - fOP_STATUS_AGGREGATION_INUSED); - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_AGGREGATION_CAPABLE); - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_PIGGYBACK_CAPABLE); - RTMPSetPiggyBack(pAd, TRUE); - DBGPRINT(RT_DEBUG_TRACE, - ("Turn on Piggy-Back\n")); - } else if (pAd->MlmeAux.APRalinkIe & 0x00000001) { - OPSTATUS_SET_FLAG(pAd, - fOP_STATUS_AGGREGATION_INUSED); - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_AGGREGATION_CAPABLE); - DBGPRINT(RT_DEBUG_TRACE, - ("Ralink Aggregation\n")); - } - } - - if (pAd->MlmeAux.APRalinkIe != 0x0) { - if (CLIENT_STATUS_TEST_FLAG - (pEntry, fCLIENT_STATUS_RDG_CAPABLE)) { - AsicEnableRDG(pAd); - } - OPSTATUS_SET_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET); - CLIENT_STATUS_SET_FLAG(pEntry, - fCLIENT_STATUS_RALINK_CHIPSET); - } else { - OPSTATUS_CLEAR_FLAG(pAd, fCLIENT_STATUS_RALINK_CHIPSET); - CLIENT_STATUS_CLEAR_FLAG(pEntry, - fCLIENT_STATUS_RALINK_CHIPSET); - } - } - - DBGPRINT(RT_DEBUG_TRACE, - ("NDIS_STATUS_MEDIA_CONNECT Event B!.BACapability = %x. ClientStatusFlags = %lx\n", - pAd->CommonCfg.BACapability.word, - pAd->MacTab.Content[BSSID_WCID].ClientStatusFlags)); - - /* Set LED */ - RTMPSetLED(pAd, LED_LINK_UP); - - pAd->Mlme.PeriodicRound = 0; - pAd->Mlme.OneSecPeriodicRound = 0; - pAd->bConfigChanged = FALSE; /* Reset config flag */ - pAd->ExtraInfo = GENERAL_LINK_UP; /* Update extra information after link is up */ - - /* Set basic auto fall back */ - { - u8 *pTable; - u8 TableSize = 0; - - MlmeSelectTxRateTable(pAd, &pAd->MacTab.Content[BSSID_WCID], - &pTable, &TableSize, - &pAd->CommonCfg.TxRateIndex); - AsicUpdateAutoFallBackTable(pAd, pTable); - } - - NdisAcquireSpinLock(&pAd->MacTabLock); - pEntry->HTPhyMode.word = pAd->StaCfg.HTPhyMode.word; - pEntry->MaxHTPhyMode.word = pAd->StaCfg.HTPhyMode.word; - if (pAd->StaCfg.bAutoTxRateSwitch == FALSE) { - pEntry->bAutoTxRateSwitch = FALSE; - - if (pEntry->HTPhyMode.field.MCS == 32) - pEntry->HTPhyMode.field.ShortGI = GI_800; - - if ((pEntry->HTPhyMode.field.MCS > MCS_7) - || (pEntry->HTPhyMode.field.MCS == 32)) - pEntry->HTPhyMode.field.STBC = STBC_NONE; - - /* If the legacy mode is set, overwrite the transmit setting of this entry. */ - if (pEntry->HTPhyMode.field.MODE <= MODE_OFDM) - RTMPUpdateLegacyTxSetting((u8)pAd->StaCfg. - DesiredTransmitSetting.field. - FixedTxMode, pEntry); - } else - pEntry->bAutoTxRateSwitch = TRUE; - NdisReleaseSpinLock(&pAd->MacTabLock); - - /* Let Link Status Page display first initial rate. */ - pAd->LastTxRate = (u16)(pEntry->HTPhyMode.word); - /* Select DAC according to HT or Legacy */ - if (pAd->StaActive.SupportedPhyInfo.MCSSet[0] != 0x00) { - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value); - Value &= (~0x18); - if (pAd->Antenna.field.TxPath == 2) { - Value |= 0x10; - } - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value); - } else { - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &Value); - Value &= (~0x18); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, Value); - } - - if (pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) { - } else if (pEntry->MaxRAmpduFactor == 0) { - /* If HT AP doesn't support MaxRAmpduFactor = 1, we need to set max PSDU to 0. */ - /* Because our Init value is 1 at MACRegTable. */ - RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x0fff); - } - /* Patch for Marvel AP to gain high throughput */ - /* Need to set as following, */ - /* 1. Set txop in register-EDCA_AC0_CFG as 0x60 */ - /* 2. Set EnTXWriteBackDDONE in register-WPDMA_GLO_CFG as zero */ - /* 3. PBF_MAX_PCNT as 0x1F3FBF9F */ - /* 4. kick per two packets when dequeue */ - /* */ - /* Txop can only be modified when RDG is off, WMM is disable and TxBurst is enable */ - /* */ - /* if 1. Legacy AP WMM on, or 2. 11n AP, AMPDU disable. Force turn off burst no matter what bEnableTxBurst is. */ - if (!((pAd->CommonCfg.RxStream == 1) && (pAd->CommonCfg.TxStream == 1)) - && (pAd->StaCfg.bForceTxBurst == FALSE) - && - (((pAd->StaActive.SupportedPhyInfo.bHtEnable == FALSE) - && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED)) - || ((pAd->StaActive.SupportedPhyInfo.bHtEnable == TRUE) - && (pAd->CommonCfg.BACapability.field.Policy == BA_NOTUSE)))) { - RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data); - Data &= 0xFFFFFF00; - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data); - - RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F); - DBGPRINT(RT_DEBUG_TRACE, ("Txburst 1\n")); - } else if (pAd->CommonCfg.bEnableTxBurst) { - RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data); - Data &= 0xFFFFFF00; - Data |= 0x60; - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data); - pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = TRUE; - - RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3FBF9F); - DBGPRINT(RT_DEBUG_TRACE, ("Txburst 2\n")); - } else { - RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &Data); - Data &= 0xFFFFFF00; - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, Data); - - RTMP_IO_WRITE32(pAd, PBF_MAX_PCNT, 0x1F3F7F9F); - DBGPRINT(RT_DEBUG_TRACE, ("Txburst 3\n")); - } - - /* Re-check to turn on TX burst or not. */ - if ((pAd->CommonCfg.IOTestParm.bLastAtheros == TRUE) - && ((STA_WEP_ON(pAd)) || (STA_TKIP_ON(pAd)))) { - pAd->CommonCfg.IOTestParm.bNextDisableRxBA = TRUE; - if (pAd->CommonCfg.bEnableTxBurst) { - u32 MACValue = 0; - /* Force disable TXOP value in this case. The same action in MLMEUpdateProtect too. */ - /* I didn't change PBF_MAX_PCNT setting. */ - RTMP_IO_READ32(pAd, EDCA_AC0_CFG, &MACValue); - MACValue &= 0xFFFFFF00; - RTMP_IO_WRITE32(pAd, EDCA_AC0_CFG, MACValue); - pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE; - } - } else { - pAd->CommonCfg.IOTestParm.bNextDisableRxBA = FALSE; - } - - pAd->CommonCfg.IOTestParm.bLastAtheros = FALSE; - COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid); - DBGPRINT(RT_DEBUG_TRACE, - ("pAd->bNextDisableRxBA= %d \n", - pAd->CommonCfg.IOTestParm.bNextDisableRxBA)); - /* BSSID add in one MAC entry too. Because in Tx, ASIC need to check Cipher and IV/EIV, BAbitmap */ - /* Pther information in MACTab.Content[BSSID_WCID] is not necessary for driver. */ - /* Note: As STA, The MACTab.Content[BSSID_WCID]. PairwiseKey and Shared Key for BSS0 are the same. */ - - if (pAd->StaCfg.WepStatus <= Ndis802_11WEPDisabled) { - if (pAd->StaCfg.WpaSupplicantUP && - (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) && - (pAd->StaCfg.IEEE8021X == TRUE)) ; - else { - pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; - pAd->StaCfg.PrivacyFilter = - Ndis802_11PrivFilterAcceptAll; - } - } - - NdisAcquireSpinLock(&pAd->MacTabLock); - pEntry->PortSecured = pAd->StaCfg.PortSecured; - NdisReleaseSpinLock(&pAd->MacTabLock); - - /* */ - /* Patch Atheros AP TX will breakdown issue. */ - /* AP Model: DLink DWL-8200AP */ - /* */ - if (INFRA_ON(pAd) && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) - && STA_TKIP_ON(pAd)) { - RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x01); - } else { - RTMP_IO_WRITE32(pAd, RX_PARSER_CFG, 0x00); - } - - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS); - - RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW); -} - -/* - ========================================================================== - - Routine Description: - Disconnect current BSSID - - Arguments: - pAd - Pointer to our adapter - IsReqFromAP - Request from AP - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - We need more information to know it's this requst from AP. - If yes! we need to do extra handling, for example, remove the WPA key. - Otherwise on 4-way handshaking will fail, since the WPA key didn't get - removed while auto reconnect. - Disconnect request from AP, it means we will start afresh 4-way handshaking - on WPA mode. - - ========================================================================== -*/ -void LinkDown(struct rt_rtmp_adapter *pAd, IN BOOLEAN IsReqFromAP) -{ - u8 i, ByteValue = 0; - - /* Do nothing if monitor mode is on */ - if (MONITOR_ON(pAd)) - return; - - RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_GO_TO_SLEEP_NOW); - /* Comment the codes, because the line 2291 call the same function. */ - /* RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); */ - /* Not allowed go to sleep within the linkdown function. */ - RTMP_CLEAR_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP); - - if (pAd->CommonCfg.bWirelessEvent) { - RTMPSendWirelessEvent(pAd, IW_STA_LINKDOWN_EVENT_FLAG, - pAd->MacTab.Content[BSSID_WCID].Addr, - BSS0, 0); - } - - DBGPRINT(RT_DEBUG_TRACE, ("LINK DOWN!\n")); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED); - -#ifdef RTMP_MAC_PCI - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) { - BOOLEAN Cancelled; - pAd->Mlme.bPsPollTimerRunning = FALSE; - RTMPCancelTimer(&pAd->Mlme.PsPollTimer, &Cancelled); - } - - pAd->bPCIclkOff = FALSE; -#endif /* RTMP_MAC_PCI // */ - - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE) - || RTMP_TEST_PSFLAG(pAd, fRTMP_PS_SET_PCI_CLK_OFF_COMMAND) - || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF)) { - AUTO_WAKEUP_STRUC AutoWakeupCfg; - AsicForceWakeup(pAd, TRUE); - AutoWakeupCfg.word = 0; - RTMP_IO_WRITE32(pAd, AUTO_WAKEUP_CFG, AutoWakeupCfg.word); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_DOZE); - } -#ifdef RTMP_MAC_PCI - pAd->bPCIclkOff = FALSE; -#endif /* RTMP_MAC_PCI // */ - - if (ADHOC_ON(pAd)) /* Adhoc mode link down */ - { - DBGPRINT(RT_DEBUG_TRACE, ("LINK DOWN 1!\n")); - - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_ADHOC_ON); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED); - pAd->IndicateMediaState = NdisMediaStateDisconnected; - RTMP_IndicateMediaState(pAd); - pAd->ExtraInfo = GENERAL_LINK_DOWN; - BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, - pAd->CommonCfg.Channel); - DBGPRINT(RT_DEBUG_TRACE, - (" MacTab.Size=%d !\n", pAd->MacTab.Size)); - } else /* Infra structure mode */ - { - DBGPRINT(RT_DEBUG_TRACE, ("LINK DOWN 2!\n")); - - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_INFRA_ON); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED); - - /* Saved last SSID for linkup comparison */ - pAd->CommonCfg.LastSsidLen = pAd->CommonCfg.SsidLen; - NdisMoveMemory(pAd->CommonCfg.LastSsid, pAd->CommonCfg.Ssid, - pAd->CommonCfg.LastSsidLen); - COPY_MAC_ADDR(pAd->CommonCfg.LastBssid, pAd->CommonCfg.Bssid); - if (pAd->MlmeAux.CurrReqIsFromNdis == TRUE) { - pAd->IndicateMediaState = NdisMediaStateDisconnected; - RTMP_IndicateMediaState(pAd); - pAd->ExtraInfo = GENERAL_LINK_DOWN; - DBGPRINT(RT_DEBUG_TRACE, - ("NDIS_STATUS_MEDIA_DISCONNECT Event A!\n")); - pAd->MlmeAux.CurrReqIsFromNdis = FALSE; - } else { - /* */ - /* If disassociation request is from NDIS, then we don't need to delete BSSID from entry. */ - /* Otherwise lost beacon or receive De-Authentication from AP, */ - /* then we should delete BSSID from BssTable. */ - /* If we don't delete from entry, roaming will fail. */ - /* */ - BssTableDeleteEntry(&pAd->ScanTab, pAd->CommonCfg.Bssid, - pAd->CommonCfg.Channel); - } - - /* restore back to - */ - /* 1. long slot (20 us) or short slot (9 us) time */ - /* 2. turn on/off RTS/CTS and/or CTS-to-self protection */ - /* 3. short preamble */ - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_BG_PROTECTION_INUSED); - - } - - for (i = 1; i < MAX_LEN_OF_MAC_TABLE; i++) { - if (pAd->MacTab.Content[i].ValidAsCLI == TRUE) - MacTableDeleteEntry(pAd, pAd->MacTab.Content[i].Aid, - pAd->MacTab.Content[i].Addr); - } - - AsicSetSlotTime(pAd, TRUE); /*FALSE); */ - AsicSetEdcaParm(pAd, NULL); - - /* Set LED */ - RTMPSetLED(pAd, LED_LINK_DOWN); - pAd->LedIndicatorStrength = 0xF0; - RTMPSetSignalLED(pAd, -100); /* Force signal strength Led to be turned off, firmware has not done it. */ - - AsicDisableSync(pAd); - - pAd->Mlme.PeriodicRound = 0; - pAd->Mlme.OneSecPeriodicRound = 0; - - if (pAd->StaCfg.BssType == BSS_INFRA) { - /* Remove StaCfg Information after link down */ - NdisZeroMemory(pAd->CommonCfg.Bssid, MAC_ADDR_LEN); - NdisZeroMemory(pAd->CommonCfg.Ssid, MAX_LEN_OF_SSID); - pAd->CommonCfg.SsidLen = 0; - } - - NdisZeroMemory(&pAd->MlmeAux.HtCapability, sizeof(struct rt_ht_capability_ie)); - NdisZeroMemory(&pAd->MlmeAux.AddHtInfo, sizeof(struct rt_add_ht_info_ie)); - pAd->MlmeAux.HtCapabilityLen = 0; - pAd->MlmeAux.NewExtChannelOffset = 0xff; - - /* Reset WPA-PSK state. Only reset when supplicant enabled */ - if (pAd->StaCfg.WpaState != SS_NOTUSE) { - pAd->StaCfg.WpaState = SS_START; - /* Clear Replay counter */ - NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8); - - } - /* */ - /* if link down come from AP, we need to remove all WPA keys on WPA mode. */ - /* otherwise will cause 4-way handshaking failed, since the WPA key not empty. */ - /* */ - if ((IsReqFromAP) && (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA)) { - /* Remove all WPA keys */ - RTMPWPARemoveAllKeys(pAd); - } - /* 802.1x port control */ - - /* Prevent clear PortSecured here with static WEP */ - /* NetworkManger set security policy first then set SSID to connect AP. */ - if (pAd->StaCfg.WpaSupplicantUP && - (pAd->StaCfg.WepStatus == Ndis802_11WEPEnabled) && - (pAd->StaCfg.IEEE8021X == FALSE)) { - pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; - } else { - pAd->StaCfg.PortSecured = WPA_802_1X_PORT_NOT_SECURED; - pAd->StaCfg.PrivacyFilter = Ndis802_11PrivFilter8021xWEP; - } - - NdisAcquireSpinLock(&pAd->MacTabLock); - NdisZeroMemory(&pAd->MacTab, sizeof(struct rt_mac_table)); - pAd->MacTab.Content[BSSID_WCID].PortSecured = pAd->StaCfg.PortSecured; - NdisReleaseSpinLock(&pAd->MacTabLock); - - pAd->StaCfg.MicErrCnt = 0; - - pAd->IndicateMediaState = NdisMediaStateDisconnected; - /* Update extra information to link is up */ - pAd->ExtraInfo = GENERAL_LINK_DOWN; - - pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE; - -#ifdef RTMP_MAC_USB - pAd->bUsbTxBulkAggre = FALSE; -#endif /* RTMP_MAC_USB // */ - - /* Clean association information */ - NdisZeroMemory(&pAd->StaCfg.AssocInfo, - sizeof(struct rt_ndis_802_11_association_information)); - pAd->StaCfg.AssocInfo.Length = - sizeof(struct rt_ndis_802_11_association_information); - pAd->StaCfg.ReqVarIELen = 0; - pAd->StaCfg.ResVarIELen = 0; - - /* */ - /* Reset RSSI value after link down */ - /* */ - pAd->StaCfg.RssiSample.AvgRssi0 = 0; - pAd->StaCfg.RssiSample.AvgRssi0X8 = 0; - pAd->StaCfg.RssiSample.AvgRssi1 = 0; - pAd->StaCfg.RssiSample.AvgRssi1X8 = 0; - pAd->StaCfg.RssiSample.AvgRssi2 = 0; - pAd->StaCfg.RssiSample.AvgRssi2X8 = 0; - - /* Restore MlmeRate */ - pAd->CommonCfg.MlmeRate = pAd->CommonCfg.BasicMlmeRate; - pAd->CommonCfg.RtsRate = pAd->CommonCfg.BasicMlmeRate; - - /* */ - /* After Link down, reset piggy-back setting in ASIC. Disable RDG. */ - /* */ - if (pAd->CommonCfg.BBPCurrentBW == BW_40) { - pAd->CommonCfg.BBPCurrentBW = BW_20; - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &ByteValue); - ByteValue &= (~0x18); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, ByteValue); - } - /* Reset DAC */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R1, &ByteValue); - ByteValue &= (~0x18); - if (pAd->Antenna.field.TxPath == 2) { - ByteValue |= 0x10; - } - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R1, ByteValue); - - RTMPSetPiggyBack(pAd, FALSE); - OPSTATUS_CLEAR_FLAG(pAd, fOP_STATUS_PIGGYBACK_INUSED); - - pAd->CommonCfg.BACapability.word = pAd->CommonCfg.REGBACapability.word; - - /* Restore all settings in the following. */ - AsicUpdateProtect(pAd, 0, - (ALLN_SETPROTECT | CCKSETPROTECT | OFDMSETPROTECT), - TRUE, FALSE); - AsicDisableRDG(pAd); - pAd->CommonCfg.IOTestParm.bCurrentAtheros = FALSE; - pAd->CommonCfg.IOTestParm.bNowAtherosBurstOn = FALSE; - - RTMP_IO_WRITE32(pAd, MAX_LEN_CFG, 0x1fff); - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS); - -/* Allow go to sleep after linkdown steps. */ - RTMP_SET_PSFLAG(pAd, fRTMP_PS_CAN_GO_SLEEP); - - RtmpOSWrielessEventSend(pAd, SIOCGIWAP, -1, NULL, NULL, 0); - -#ifdef RT30xx - if ((IS_RT30xx(pAd) || IS_RT3090(pAd) || IS_RT3390(pAd)) - && (pAd->Antenna.field.RxPath > 1 || pAd->Antenna.field.TxPath > 1)) { - RTMP_ASIC_MMPS_DISABLE(pAd); - } -#endif /* RT30xx // */ -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void IterateOnBssTab(struct rt_rtmp_adapter *pAd) -{ - struct rt_mlme_start_req StartReq; - struct rt_mlme_join_req JoinReq; - unsigned long BssIdx; - - /* Change the wepstatus to original wepstatus */ - pAd->StaCfg.WepStatus = pAd->StaCfg.OrigWepStatus; - pAd->StaCfg.PairCipher = pAd->StaCfg.OrigWepStatus; - pAd->StaCfg.GroupCipher = pAd->StaCfg.OrigWepStatus; - - BssIdx = pAd->MlmeAux.BssIdx; - if (BssIdx < pAd->MlmeAux.SsidBssTab.BssNr) { - /* Check cipher suite, AP must have more secured cipher than station setting */ - /* Set the Pairwise and Group cipher to match the intended AP setting */ - /* We can only connect to AP with less secured cipher setting */ - if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) - || (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK)) { - pAd->StaCfg.GroupCipher = - pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA. - GroupCipher; - - if (pAd->StaCfg.WepStatus == - pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA. - PairCipher) - pAd->StaCfg.PairCipher = - pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx]. - WPA.PairCipher; - else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA. - PairCipherAux != Ndis802_11WEPDisabled) - pAd->StaCfg.PairCipher = - pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx]. - WPA.PairCipherAux; - else /* There is no PairCipher Aux, downgrade our capability to TKIP */ - pAd->StaCfg.PairCipher = - Ndis802_11Encryption2Enabled; - } else if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) - || (pAd->StaCfg.AuthMode == - Ndis802_11AuthModeWPA2PSK)) { - pAd->StaCfg.GroupCipher = - pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2. - GroupCipher; - - if (pAd->StaCfg.WepStatus == - pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2. - PairCipher) - pAd->StaCfg.PairCipher = - pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx]. - WPA2.PairCipher; - else if (pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2. - PairCipherAux != Ndis802_11WEPDisabled) - pAd->StaCfg.PairCipher = - pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx]. - WPA2.PairCipherAux; - else /* There is no PairCipher Aux, downgrade our capability to TKIP */ - pAd->StaCfg.PairCipher = - Ndis802_11Encryption2Enabled; - - /* RSN capability */ - pAd->StaCfg.RsnCapability = - pAd->MlmeAux.SsidBssTab.BssEntry[BssIdx].WPA2. - RsnCapability; - } - /* Set Mix cipher flag */ - pAd->StaCfg.bMixCipher = - (pAd->StaCfg.PairCipher == - pAd->StaCfg.GroupCipher) ? FALSE : TRUE; - /*if (pAd->StaCfg.bMixCipher == TRUE) - { - // If mix cipher, re-build RSNIE - RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, 0); - } */ - - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - iterate BSS %ld of %d\n", BssIdx, - pAd->MlmeAux.SsidBssTab.BssNr)); - JoinParmFill(pAd, &JoinReq, BssIdx); - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_JOIN_REQ, - sizeof(struct rt_mlme_join_req), &JoinReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_JOIN; - } else if (pAd->StaCfg.BssType == BSS_ADHOC) { - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - All BSS fail; start a new ADHOC (Ssid=%s)...\n", - pAd->MlmeAux.Ssid)); - StartParmFill(pAd, &StartReq, (char *)pAd->MlmeAux.Ssid, - pAd->MlmeAux.SsidLen); - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_MLME_START_REQ, - sizeof(struct rt_mlme_start_req), &StartReq); - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_START; - } else /* no more BSS */ - { - - { - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.Channel); - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - All roaming failed, restore to channel %d, Total BSS[%02d]\n", - pAd->CommonCfg.Channel, pAd->ScanTab.BssNr)); - } - - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - } -} - -/* for re-association only */ -/* IRQL = DISPATCH_LEVEL */ -void IterateOnBssTab2(struct rt_rtmp_adapter *pAd) -{ - struct rt_mlme_assoc_req ReassocReq; - unsigned long BssIdx; - struct rt_bss_entry *pBss; - - BssIdx = pAd->MlmeAux.RoamIdx; - pBss = &pAd->MlmeAux.RoamTab.BssEntry[BssIdx]; - - if (BssIdx < pAd->MlmeAux.RoamTab.BssNr) { - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - iterate BSS %ld of %d\n", BssIdx, - pAd->MlmeAux.RoamTab.BssNr)); - - AsicSwitchChannel(pAd, pBss->Channel, FALSE); - AsicLockChannel(pAd, pBss->Channel); - - /* reassociate message has the same structure as associate message */ - AssocParmFill(pAd, &ReassocReq, pBss->Bssid, - pBss->CapabilityInfo, ASSOC_TIMEOUT, - pAd->StaCfg.DefaultListenCount); - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_REASSOC_REQ, - sizeof(struct rt_mlme_assoc_req), &ReassocReq); - - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_REASSOC; - } else /* no more BSS */ - { - - { - AsicSwitchChannel(pAd, pAd->CommonCfg.Channel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.Channel); - DBGPRINT(RT_DEBUG_TRACE, - ("CNTL - All roaming failed, restore to channel %d, Total BSS[%02d]\n", - pAd->CommonCfg.Channel, pAd->ScanTab.BssNr)); - } - - pAd->Mlme.CntlMachine.CurrState = CNTL_IDLE; - } -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void JoinParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_join_req *JoinReq, unsigned long BssIdx) -{ - JoinReq->BssIdx = BssIdx; -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void ScanParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_scan_req *ScanReq, - char Ssid[], - u8 SsidLen, u8 BssType, u8 ScanType) -{ - NdisZeroMemory(ScanReq->Ssid, MAX_LEN_OF_SSID); - ScanReq->SsidLen = SsidLen; - NdisMoveMemory(ScanReq->Ssid, Ssid, SsidLen); - ScanReq->BssType = BssType; - ScanReq->ScanType = ScanType; -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void StartParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_start_req *StartReq, - char Ssid[], u8 SsidLen) -{ - ASSERT(SsidLen <= MAX_LEN_OF_SSID); - NdisMoveMemory(StartReq->Ssid, Ssid, SsidLen); - StartReq->SsidLen = SsidLen; -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -void AuthParmFill(struct rt_rtmp_adapter *pAd, - struct rt_mlme_auth_req *AuthReq, - u8 *pAddr, u16 Alg) -{ - COPY_MAC_ADDR(AuthReq->Addr, pAddr); - AuthReq->Alg = Alg; - AuthReq->Timeout = AUTH_TIMEOUT; -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -#ifdef RTMP_MAC_PCI -void ComposePsPoll(struct rt_rtmp_adapter *pAd) -{ - NdisZeroMemory(&pAd->PsPollFrame, sizeof(struct rt_pspoll_frame)); - pAd->PsPollFrame.FC.Type = BTYPE_CNTL; - pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL; - pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000; - COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid); - COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress); -} - -/* IRQL = DISPATCH_LEVEL */ -void ComposeNullFrame(struct rt_rtmp_adapter *pAd) -{ - NdisZeroMemory(&pAd->NullFrame, sizeof(struct rt_header_802_11)); - pAd->NullFrame.FC.Type = BTYPE_DATA; - pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC; - pAd->NullFrame.FC.ToDs = 1; - COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid); - COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress); - COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid); -} -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB -void MlmeCntlConfirm(struct rt_rtmp_adapter *pAd, unsigned long MsgType, u16 Msg) -{ - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MsgType, sizeof(u16), - &Msg); -} - -void ComposePsPoll(struct rt_rtmp_adapter *pAd) -{ - struct rt_txinfo *pTxInfo; - struct rt_txwi * pTxWI; - - DBGPRINT(RT_DEBUG_TRACE, ("ComposePsPoll\n")); - NdisZeroMemory(&pAd->PsPollFrame, sizeof(struct rt_pspoll_frame)); - - pAd->PsPollFrame.FC.PwrMgmt = 0; - pAd->PsPollFrame.FC.Type = BTYPE_CNTL; - pAd->PsPollFrame.FC.SubType = SUBTYPE_PS_POLL; - pAd->PsPollFrame.Aid = pAd->StaActive.Aid | 0xC000; - COPY_MAC_ADDR(pAd->PsPollFrame.Bssid, pAd->CommonCfg.Bssid); - COPY_MAC_ADDR(pAd->PsPollFrame.Ta, pAd->CurrentAddress); - - RTMPZeroMemory(&pAd->PsPollContext.TransferBuffer->field. - WirelessPacket[0], 100); - pTxInfo = - (struct rt_txinfo *)& pAd->PsPollContext.TransferBuffer->field. - WirelessPacket[0]; - RTMPWriteTxInfo(pAd, pTxInfo, - (u16)(sizeof(struct rt_pspoll_frame) + TXWI_SIZE), TRUE, - EpToQueue[MGMTPIPEIDX], FALSE, FALSE); - pTxWI = - (struct rt_txwi *) & pAd->PsPollContext.TransferBuffer->field. - WirelessPacket[TXINFO_SIZE]; - RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, - BSSID_WCID, (sizeof(struct rt_pspoll_frame)), 0, 0, - (u8)pAd->CommonCfg.MlmeTransmit.field.MCS, - IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit); - RTMPMoveMemory(&pAd->PsPollContext.TransferBuffer->field. - WirelessPacket[TXWI_SIZE + TXINFO_SIZE], - &pAd->PsPollFrame, sizeof(struct rt_pspoll_frame)); - /* Append 4 extra zero bytes. */ - pAd->PsPollContext.BulkOutSize = - TXINFO_SIZE + TXWI_SIZE + sizeof(struct rt_pspoll_frame) + 4; -} - -/* IRQL = DISPATCH_LEVEL */ -void ComposeNullFrame(struct rt_rtmp_adapter *pAd) -{ - struct rt_txinfo *pTxInfo; - struct rt_txwi * pTxWI; - - NdisZeroMemory(&pAd->NullFrame, sizeof(struct rt_header_802_11)); - pAd->NullFrame.FC.Type = BTYPE_DATA; - pAd->NullFrame.FC.SubType = SUBTYPE_NULL_FUNC; - pAd->NullFrame.FC.ToDs = 1; - COPY_MAC_ADDR(pAd->NullFrame.Addr1, pAd->CommonCfg.Bssid); - COPY_MAC_ADDR(pAd->NullFrame.Addr2, pAd->CurrentAddress); - COPY_MAC_ADDR(pAd->NullFrame.Addr3, pAd->CommonCfg.Bssid); - RTMPZeroMemory(&pAd->NullContext.TransferBuffer->field. - WirelessPacket[0], 100); - pTxInfo = - (struct rt_txinfo *)& pAd->NullContext.TransferBuffer->field. - WirelessPacket[0]; - RTMPWriteTxInfo(pAd, pTxInfo, - (u16)(sizeof(struct rt_header_802_11) + TXWI_SIZE), TRUE, - EpToQueue[MGMTPIPEIDX], FALSE, FALSE); - pTxWI = - (struct rt_txwi *) & pAd->NullContext.TransferBuffer->field. - WirelessPacket[TXINFO_SIZE]; - RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, 0, - BSSID_WCID, (sizeof(struct rt_header_802_11)), 0, 0, - (u8)pAd->CommonCfg.MlmeTransmit.field.MCS, - IFS_BACKOFF, FALSE, &pAd->CommonCfg.MlmeTransmit); - RTMPMoveMemory(&pAd->NullContext.TransferBuffer->field. - WirelessPacket[TXWI_SIZE + TXINFO_SIZE], &pAd->NullFrame, - sizeof(struct rt_header_802_11)); - pAd->NullContext.BulkOutSize = - TXINFO_SIZE + TXWI_SIZE + sizeof(pAd->NullFrame) + 4; -} -#endif /* RTMP_MAC_USB // */ - -/* - ========================================================================== - Description: - Pre-build a BEACON frame in the shared memory - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ========================================================================== -*/ -unsigned long MakeIbssBeacon(struct rt_rtmp_adapter *pAd) -{ - u8 DsLen = 1, IbssLen = 2; - u8 LocalErpIe[3] = { IE_ERP, 1, 0x04 }; - struct rt_header_802_11 BcnHdr; - u16 CapabilityInfo; - LARGE_INTEGER FakeTimestamp; - unsigned long FrameLen = 0; - struct rt_txwi * pTxWI = &pAd->BeaconTxWI; - u8 *pBeaconFrame = pAd->BeaconBuf; - BOOLEAN Privacy; - u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 SupRateLen = 0; - u8 ExtRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 ExtRateLen = 0; - u8 RSNIe = IE_WPA; - - if ((pAd->CommonCfg.PhyMode == PHY_11B) - && (pAd->CommonCfg.Channel <= 14)) { - SupRate[0] = 0x82; /* 1 mbps */ - SupRate[1] = 0x84; /* 2 mbps */ - SupRate[2] = 0x8b; /* 5.5 mbps */ - SupRate[3] = 0x96; /* 11 mbps */ - SupRateLen = 4; - ExtRateLen = 0; - } else if (pAd->CommonCfg.Channel > 14) { - SupRate[0] = 0x8C; /* 6 mbps, in units of 0.5 Mbps, basic rate */ - SupRate[1] = 0x12; /* 9 mbps, in units of 0.5 Mbps */ - SupRate[2] = 0x98; /* 12 mbps, in units of 0.5 Mbps, basic rate */ - SupRate[3] = 0x24; /* 18 mbps, in units of 0.5 Mbps */ - SupRate[4] = 0xb0; /* 24 mbps, in units of 0.5 Mbps, basic rate */ - SupRate[5] = 0x48; /* 36 mbps, in units of 0.5 Mbps */ - SupRate[6] = 0x60; /* 48 mbps, in units of 0.5 Mbps */ - SupRate[7] = 0x6c; /* 54 mbps, in units of 0.5 Mbps */ - SupRateLen = 8; - ExtRateLen = 0; - - /* */ - /* Also Update MlmeRate & RtsRate for G only & A only */ - /* */ - pAd->CommonCfg.MlmeRate = RATE_6; - pAd->CommonCfg.RtsRate = RATE_6; - pAd->CommonCfg.MlmeTransmit.field.MODE = MODE_OFDM; - pAd->CommonCfg.MlmeTransmit.field.MCS = - OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; - pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MODE = - MODE_OFDM; - pAd->MacTab.Content[BSS0Mcast_WCID].HTPhyMode.field.MCS = - OfdmRateToRxwiMCS[pAd->CommonCfg.MlmeRate]; - } else { - SupRate[0] = 0x82; /* 1 mbps */ - SupRate[1] = 0x84; /* 2 mbps */ - SupRate[2] = 0x8b; /* 5.5 mbps */ - SupRate[3] = 0x96; /* 11 mbps */ - SupRateLen = 4; - - ExtRate[0] = 0x0C; /* 6 mbps, in units of 0.5 Mbps, */ - ExtRate[1] = 0x12; /* 9 mbps, in units of 0.5 Mbps */ - ExtRate[2] = 0x18; /* 12 mbps, in units of 0.5 Mbps, */ - ExtRate[3] = 0x24; /* 18 mbps, in units of 0.5 Mbps */ - ExtRate[4] = 0x30; /* 24 mbps, in units of 0.5 Mbps, */ - ExtRate[5] = 0x48; /* 36 mbps, in units of 0.5 Mbps */ - ExtRate[6] = 0x60; /* 48 mbps, in units of 0.5 Mbps */ - ExtRate[7] = 0x6c; /* 54 mbps, in units of 0.5 Mbps */ - ExtRateLen = 8; - } - - pAd->StaActive.SupRateLen = SupRateLen; - NdisMoveMemory(pAd->StaActive.SupRate, SupRate, SupRateLen); - pAd->StaActive.ExtRateLen = ExtRateLen; - NdisMoveMemory(pAd->StaActive.ExtRate, ExtRate, ExtRateLen); - - /* compose IBSS beacon frame */ - MgtMacHeaderInit(pAd, &BcnHdr, SUBTYPE_BEACON, 0, BROADCAST_ADDR, - pAd->CommonCfg.Bssid); - Privacy = (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) - || (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) - || (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled); - CapabilityInfo = - CAP_GENERATE(0, 1, Privacy, - (pAd->CommonCfg.TxPreamble == Rt802_11PreambleShort), - 0, 0); - - MakeOutgoingFrame(pBeaconFrame, &FrameLen, - sizeof(struct rt_header_802_11), &BcnHdr, - TIMESTAMP_LEN, &FakeTimestamp, - 2, &pAd->CommonCfg.BeaconPeriod, - 2, &CapabilityInfo, - 1, &SsidIe, - 1, &pAd->CommonCfg.SsidLen, - pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid, - 1, &SupRateIe, - 1, &SupRateLen, - SupRateLen, SupRate, - 1, &DsIe, - 1, &DsLen, - 1, &pAd->CommonCfg.Channel, - 1, &IbssIe, - 1, &IbssLen, 2, &pAd->StaActive.AtimWin, END_OF_ARGS); - - /* add ERP_IE and EXT_RAE IE of in 802.11g */ - if (ExtRateLen) { - unsigned long tmp; - - MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp, - 3, LocalErpIe, - 1, &ExtRateIe, - 1, &ExtRateLen, - ExtRateLen, ExtRate, END_OF_ARGS); - FrameLen += tmp; - } - /* If adhoc secruity is set for WPA-None, append the cipher suite IE */ - if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) { - unsigned long tmp; - RTMPMakeRSNIE(pAd, pAd->StaCfg.AuthMode, pAd->StaCfg.WepStatus, - BSS0); - - MakeOutgoingFrame(pBeaconFrame + FrameLen, &tmp, - 1, &RSNIe, - 1, &pAd->StaCfg.RSNIE_Len, - pAd->StaCfg.RSNIE_Len, pAd->StaCfg.RSN_IE, - END_OF_ARGS); - FrameLen += tmp; - } - - if ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED)) { - unsigned long TmpLen; - u8 HtLen, HtLen1; - - /* add HT Capability IE */ - HtLen = sizeof(pAd->CommonCfg.HtCapability); - HtLen1 = sizeof(pAd->CommonCfg.AddHTInfo); - - MakeOutgoingFrame(pBeaconFrame + FrameLen, &TmpLen, - 1, &HtCapIe, - 1, &HtLen, - HtLen, &pAd->CommonCfg.HtCapability, - 1, &AddHtInfoIe, - 1, &HtLen1, - HtLen1, &pAd->CommonCfg.AddHTInfo, - END_OF_ARGS); - - FrameLen += TmpLen; - } - /*beacon use reserved WCID 0xff */ - if (pAd->CommonCfg.Channel > 14) { - RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, - TRUE, 0, 0xff, FrameLen, PID_MGMT, PID_BEACON, - RATE_1, IFS_HTTXOP, FALSE, - &pAd->CommonCfg.MlmeTransmit); - } else { - /* Set to use 1Mbps for Adhoc beacon. */ - HTTRANSMIT_SETTING Transmit; - Transmit.word = 0; - RTMPWriteTxWI(pAd, pTxWI, FALSE, FALSE, TRUE, FALSE, FALSE, - TRUE, 0, 0xff, FrameLen, PID_MGMT, PID_BEACON, - RATE_1, IFS_HTTXOP, FALSE, &Transmit); - } - - DBGPRINT(RT_DEBUG_TRACE, - ("MakeIbssBeacon (len=%ld), SupRateLen=%d, ExtRateLen=%d, Channel=%d, PhyMode=%d\n", - FrameLen, SupRateLen, ExtRateLen, pAd->CommonCfg.Channel, - pAd->CommonCfg.PhyMode)); - return FrameLen; -} diff --git a/trunk/drivers/staging/rt2860/sta/rtmp_data.c b/trunk/drivers/staging/rt2860/sta/rtmp_data.c deleted file mode 100644 index e82c6b669eb2..000000000000 --- a/trunk/drivers/staging/rt2860/sta/rtmp_data.c +++ /dev/null @@ -1,2552 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtmp_data.c - - Abstract: - Data path subroutines - - Revision History: - Who When What - Justin P. Mattock 11/07/2010 Fix typos - -------- ---------- ---------------------------------------------- -*/ -#include "../rt_config.h" -#include - -void STARxEAPOLFrameIndicate(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID) -{ - PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD); - struct rt_rxwi * pRxWI = pRxBlk->pRxWI; - u8 *pTmpBuf; - - if (pAd->StaCfg.WpaSupplicantUP) { - /* All EAPoL frames have to pass to upper layer (ex. WPA_SUPPLICANT daemon) */ - /* TBD : process fragmented EAPol frames */ - { - /* In 802.1x mode, if the received frame is EAP-SUCCESS packet, turn on the PortSecured variable */ - if (pAd->StaCfg.IEEE8021X == TRUE && - (EAP_CODE_SUCCESS == - WpaCheckEapCode(pAd, pRxBlk->pData, - pRxBlk->DataSize, - LENGTH_802_1_H))) { - u8 *Key; - u8 CipherAlg; - int idx = 0; - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("Receive EAP-SUCCESS Packet\n")); - /*pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ - STA_PORT_SECURED(pAd); - - if (pAd->StaCfg.IEEE8021x_required_keys == - FALSE) { - idx = pAd->StaCfg.DesireSharedKeyId; - CipherAlg = - pAd->StaCfg.DesireSharedKey[idx]. - CipherAlg; - Key = - pAd->StaCfg.DesireSharedKey[idx]. - Key; - - if (pAd->StaCfg.DesireSharedKey[idx]. - KeyLen > 0) { -#ifdef RTMP_MAC_PCI - struct rt_mac_table_entry *pEntry = - &pAd->MacTab. - Content[BSSID_WCID]; - - /* Set key material and cipherAlg to Asic */ - AsicAddSharedKeyEntry(pAd, BSS0, - idx, - CipherAlg, - Key, NULL, - NULL); - - /* Assign group key info */ - RTMPAddWcidAttributeEntry(pAd, - BSS0, - idx, - CipherAlg, - NULL); - - /* Assign pairwise key info */ - RTMPAddWcidAttributeEntry(pAd, - BSS0, - idx, - CipherAlg, - pEntry); - - pAd->IndicateMediaState = - NdisMediaStateConnected; - pAd->ExtraInfo = - GENERAL_LINK_UP; -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - union { - char buf[sizeof - (struct rt_ndis_802_11_wep) - + - MAX_LEN_OF_KEY - - 1]; - struct rt_ndis_802_11_wep keyinfo; - } - WepKey; - int len; - - NdisZeroMemory(&WepKey, - sizeof(WepKey)); - len = - pAd->StaCfg. - DesireSharedKey[idx].KeyLen; - - NdisMoveMemory(WepKey.keyinfo. - KeyMaterial, - pAd->StaCfg. - DesireSharedKey - [idx].Key, - pAd->StaCfg. - DesireSharedKey - [idx].KeyLen); - - WepKey.keyinfo.KeyIndex = - 0x80000000 + idx; - WepKey.keyinfo.KeyLength = len; - pAd->SharedKey[BSS0][idx]. - KeyLen = - (u8)(len <= 5 ? 5 : 13); - - pAd->IndicateMediaState = - NdisMediaStateConnected; - pAd->ExtraInfo = - GENERAL_LINK_UP; - /* need to enqueue cmd to thread */ - RTUSBEnqueueCmdFromNdis(pAd, - OID_802_11_ADD_WEP, - TRUE, - &WepKey, - sizeof - (WepKey. - keyinfo) - + len - - 1); -#endif /* RTMP_MAC_USB // */ - /* For Preventing ShardKey Table is cleared by remove key procedure. */ - pAd->SharedKey[BSS0][idx]. - CipherAlg = CipherAlg; - pAd->SharedKey[BSS0][idx]. - KeyLen = - pAd->StaCfg. - DesireSharedKey[idx].KeyLen; - NdisMoveMemory(pAd-> - SharedKey[BSS0] - [idx].Key, - pAd->StaCfg. - DesireSharedKey - [idx].Key, - pAd->StaCfg. - DesireSharedKey - [idx].KeyLen); - } - } - } - - Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID); - return; - } - } else { - /* Special DATA frame that has to pass to MLME */ - /* 1. Cisco Aironet frames for CCX2. We need pass it to MLME for special process */ - /* 2. EAPOL handshaking frames when driver supplicant enabled, pass to MLME for special process */ - { - pTmpBuf = pRxBlk->pData - LENGTH_802_11; - NdisMoveMemory(pTmpBuf, pRxBlk->pHeader, LENGTH_802_11); - REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, - pTmpBuf, - pRxBlk->DataSize + - LENGTH_802_11, pRxWI->RSSI0, - pRxWI->RSSI1, pRxWI->RSSI2, - pRxD->PlcpSignal); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("report EAPOL/AIRONET DATA to MLME (len=%d) !\n", - pRxBlk->DataSize)); - } - } - - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, NDIS_STATUS_FAILURE); - return; - -} - -void STARxDataFrameAnnounce(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, - struct rt_rx_blk *pRxBlk, u8 FromWhichBSSID) -{ - - /* non-EAP frame */ - if (!RTMPCheckWPAframe - (pAd, pEntry, pRxBlk->pData, pRxBlk->DataSize, FromWhichBSSID)) { - - { - /* drop all non-EAP DATA frame before */ - /* this client's Port-Access-Control is secured */ - if (pRxBlk->pHeader->FC.Wep) { - /* unsupported cipher suite */ - if (pAd->StaCfg.WepStatus == - Ndis802_11EncryptionDisabled) { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, - pRxBlk->pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - } else { - /* encryption in-use but receive a non-EAPOL clear text frame, drop it */ - if ((pAd->StaCfg.WepStatus != - Ndis802_11EncryptionDisabled) - && (pAd->StaCfg.PortSecured == - WPA_802_1X_PORT_NOT_SECURED)) { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, - pRxBlk->pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - } - } - RX_BLK_CLEAR_FLAG(pRxBlk, fRX_EAP); - if (!RX_BLK_TEST_FLAG(pRxBlk, fRX_ARALINK)) { - /* Normal legacy, AMPDU or AMSDU */ - CmmRxnonRalinkFrameIndicate(pAd, pRxBlk, - FromWhichBSSID); - - } else { - /* ARALINK */ - CmmRxRalinkFrameIndicate(pAd, pEntry, pRxBlk, - FromWhichBSSID); - } - } else { - RX_BLK_SET_FLAG(pRxBlk, fRX_EAP); - - if (RX_BLK_TEST_FLAG(pRxBlk, fRX_AMPDU) - && (pAd->CommonCfg.bDisableReordering == 0)) { - Indicate_AMPDU_Packet(pAd, pRxBlk, FromWhichBSSID); - } else { - /* Determine the destination of the EAP frame */ - /* to WPA state machine or upper layer */ - STARxEAPOLFrameIndicate(pAd, pEntry, pRxBlk, - FromWhichBSSID); - } - } -} - -/* For TKIP frame, calculate the MIC value */ -BOOLEAN STACheckTkipMICValue(struct rt_rtmp_adapter *pAd, - struct rt_mac_table_entry *pEntry, struct rt_rx_blk *pRxBlk) -{ - struct rt_header_802_11 * pHeader = pRxBlk->pHeader; - u8 *pData = pRxBlk->pData; - u16 DataSize = pRxBlk->DataSize; - u8 UserPriority = pRxBlk->UserPriority; - struct rt_cipher_key *pWpaKey; - u8 *pDA, *pSA; - - pWpaKey = &pAd->SharedKey[BSS0][pRxBlk->pRxWI->KeyIndex]; - - pDA = pHeader->Addr1; - if (RX_BLK_TEST_FLAG(pRxBlk, fRX_INFRA)) { - pSA = pHeader->Addr3; - } else { - pSA = pHeader->Addr2; - } - - if (RTMPTkipCompareMICValue(pAd, - pData, - pDA, - pSA, - pWpaKey->RxMic, - UserPriority, DataSize) == FALSE) { - DBGPRINT_RAW(RT_DEBUG_ERROR, ("Rx MIC Value error 2\n")); - - if (pAd->StaCfg.WpaSupplicantUP) { - WpaSendMicFailureToWpaSupplicant(pAd, - (pWpaKey->Type == - PAIRWISEKEY) ? TRUE : - FALSE); - } else { - RTMPReportMicError(pAd, pWpaKey); - } - - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxBlk->pRxPacket, - NDIS_STATUS_FAILURE); - return FALSE; - } - - return TRUE; -} - -/* */ -/* All Rx routines use struct rt_rx_blk structure to hande rx events */ -/* It is very important to build pRxBlk attributes */ -/* 1. pHeader pointer to 802.11 Header */ -/* 2. pData pointer to payload including LLC (just skip Header) */ -/* 3. set payload size including LLC to DataSize */ -/* 4. set some flags with RX_BLK_SET_FLAG() */ -/* */ -void STAHandleRxDataFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk) -{ - PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD); - struct rt_rxwi * pRxWI = pRxBlk->pRxWI; - struct rt_header_802_11 * pHeader = pRxBlk->pHeader; - void *pRxPacket = pRxBlk->pRxPacket; - BOOLEAN bFragment = FALSE; - struct rt_mac_table_entry *pEntry = NULL; - u8 FromWhichBSSID = BSS0; - u8 UserPriority = 0; - - { - /* before LINK UP, all DATA frames are rejected */ - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - /* Drop not my BSS frames */ - if (pRxD->MyBss == 0) { - { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - } - - pAd->RalinkCounters.RxCountSinceLastNULL++; - if (pAd->CommonCfg.bAPSDCapable - && pAd->CommonCfg.APEdcaParm.bAPSDCapable - && (pHeader->FC.SubType & 0x08)) { - u8 *pData; - DBGPRINT(RT_DEBUG_INFO, ("bAPSDCapable\n")); - - /* Qos bit 4 */ - pData = (u8 *)pHeader + LENGTH_802_11; - if ((*pData >> 4) & 0x01) { - DBGPRINT(RT_DEBUG_INFO, - ("RxDone- Rcv EOSP frame, driver may fall into sleep\n")); - pAd->CommonCfg.bInServicePeriod = FALSE; - - /* Force driver to fall into sleep mode when rcv EOSP frame */ - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) { - u16 TbttNumToNextWakeUp; - u16 NextDtim = - pAd->StaCfg.DtimPeriod; - unsigned long Now; - - NdisGetSystemUpTime(&Now); - NextDtim -= - (u16)(Now - - pAd->StaCfg. - LastBeaconRxTime) / - pAd->CommonCfg.BeaconPeriod; - - TbttNumToNextWakeUp = - pAd->StaCfg.DefaultListenCount; - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_RECEIVE_DTIM) - && (TbttNumToNextWakeUp > NextDtim)) - TbttNumToNextWakeUp = NextDtim; - - RTMP_SET_PSM_BIT(pAd, PWR_SAVE); - /* if WMM-APSD is failed, try to disable following line */ - AsicSleepThenAutoWakeup(pAd, - TbttNumToNextWakeUp); - } - } - - if ((pHeader->FC.MoreData) - && (pAd->CommonCfg.bInServicePeriod)) { - DBGPRINT(RT_DEBUG_TRACE, - ("Sending another trigger frame when More Data bit is set to 1\n")); - } - } - /* Drop NULL, CF-ACK(no data), CF-POLL(no data), and CF-ACK+CF-POLL(no data) data frame */ - if ((pHeader->FC.SubType & 0x04)) /* bit 2 : no DATA */ - { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - /* Drop not my BSS frame (we can not only check the MyBss bit in RxD) */ - - if (INFRA_ON(pAd)) { - /* Infrastructure mode, check address 2 for BSSID */ - if (!RTMPEqualMemory - (&pHeader->Addr2, &pAd->CommonCfg.Bssid, 6)) { - /* Receive frame not my BSSID */ - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - } else /* Ad-Hoc mode or Not associated */ - { - /* Ad-Hoc mode, check address 3 for BSSID */ - if (!RTMPEqualMemory - (&pHeader->Addr3, &pAd->CommonCfg.Bssid, 6)) { - /* Receive frame not my BSSID */ - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - } - - /* */ - /* find pEntry */ - /* */ - if (pRxWI->WirelessCliID < MAX_LEN_OF_MAC_TABLE) { - pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID]; - } else { - /* 1. release packet if infra mode */ - /* 2. new a pEntry if ad-hoc mode */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - - /* infra or ad-hoc */ - if (INFRA_ON(pAd)) { - RX_BLK_SET_FLAG(pRxBlk, fRX_INFRA); - ASSERT(pRxWI->WirelessCliID == BSSID_WCID); - } - /* check Atheros Client */ - if ((pEntry->bIAmBadAtheros == FALSE) && (pRxD->AMPDU == 1) - && (pHeader->FC.Retry)) { - pEntry->bIAmBadAtheros = TRUE; - pAd->CommonCfg.IOTestParm.bCurrentAtheros = TRUE; - pAd->CommonCfg.IOTestParm.bLastAtheros = TRUE; - if (!STA_AES_ON(pAd)) { - AsicUpdateProtect(pAd, 8, ALLN_SETPROTECT, TRUE, - FALSE); - } - } - } - - pRxBlk->pData = (u8 *) pHeader; - - /* */ - /* update RxBlk->pData, DataSize */ - /* 802.11 Header, QOS, HTC, Hw Padding */ - /* */ - - /* 1. skip 802.11 HEADER */ - { - pRxBlk->pData += LENGTH_802_11; - pRxBlk->DataSize -= LENGTH_802_11; - } - - /* 2. QOS */ - if (pHeader->FC.SubType & 0x08) { - RX_BLK_SET_FLAG(pRxBlk, fRX_QOS); - UserPriority = *(pRxBlk->pData) & 0x0f; - /* bit 7 in QoS Control field signals the HT A-MSDU format */ - if ((*pRxBlk->pData) & 0x80) { - RX_BLK_SET_FLAG(pRxBlk, fRX_AMSDU); - } - /* skip QOS contorl field */ - pRxBlk->pData += 2; - pRxBlk->DataSize -= 2; - } - pRxBlk->UserPriority = UserPriority; - - /* check if need to resend PS Poll when received packet with MoreData = 1 */ - if ((pAd->StaCfg.Psm == PWR_SAVE) && (pHeader->FC.MoreData == 1)) { - if ((((UserPriority == 0) || (UserPriority == 3)) && - pAd->CommonCfg.bAPSDAC_BE == 0) || - (((UserPriority == 1) || (UserPriority == 2)) && - pAd->CommonCfg.bAPSDAC_BK == 0) || - (((UserPriority == 4) || (UserPriority == 5)) && - pAd->CommonCfg.bAPSDAC_VI == 0) || - (((UserPriority == 6) || (UserPriority == 7)) && - pAd->CommonCfg.bAPSDAC_VO == 0)) { - /* non-UAPSD delivery-enabled AC */ - RTMP_PS_POLL_ENQUEUE(pAd); - } - } - /* 3. Order bit: A-Ralink or HTC+ */ - if (pHeader->FC.Order) { -#ifdef AGGREGATION_SUPPORT - if ((pRxWI->PHYMODE <= MODE_OFDM) - && (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED))) - { - RX_BLK_SET_FLAG(pRxBlk, fRX_ARALINK); - } else -#endif /* AGGREGATION_SUPPORT // */ - { - RX_BLK_SET_FLAG(pRxBlk, fRX_HTC); - /* skip HTC contorl field */ - pRxBlk->pData += 4; - pRxBlk->DataSize -= 4; - } - } - /* 4. skip HW padding */ - if (pRxD->L2PAD) { - /* just move pData pointer */ - /* because DataSize excluding HW padding */ - RX_BLK_SET_FLAG(pRxBlk, fRX_PAD); - pRxBlk->pData += 2; - } - - if (pRxD->BA) { - RX_BLK_SET_FLAG(pRxBlk, fRX_AMPDU); - } - /* */ - /* Case I Process Broadcast & Multicast data frame */ - /* */ - if (pRxD->Bcast || pRxD->Mcast) { - INC_COUNTER64(pAd->WlanCounters.MulticastReceivedFrameCount); - - /* Drop Mcast/Bcast frame with fragment bit on */ - if (pHeader->FC.MoreFrag) { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - /* Filter out Bcast frame which AP relayed for us */ - if (pHeader->FC.FrDs - && MAC_ADDR_EQUAL(pHeader->Addr3, pAd->CurrentAddress)) { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, - NDIS_STATUS_FAILURE); - return; - } - - Indicate_Legacy_Packet(pAd, pRxBlk, FromWhichBSSID); - return; - } else if (pRxD->U2M) { - pAd->LastRxRate = - (u16)((pRxWI->MCS) + (pRxWI->BW << 7) + - (pRxWI->ShortGI << 8) + (pRxWI->PHYMODE << 14)); - - if (ADHOC_ON(pAd)) { - pEntry = MacTableLookup(pAd, pHeader->Addr2); - if (pEntry) - Update_Rssi_Sample(pAd, &pEntry->RssiSample, - pRxWI); - } - - Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI); - - pAd->StaCfg.LastSNR0 = (u8)(pRxWI->SNR0); - pAd->StaCfg.LastSNR1 = (u8)(pRxWI->SNR1); - - pAd->RalinkCounters.OneSecRxOkDataCnt++; - - if (!((pHeader->Frag == 0) && (pHeader->FC.MoreFrag == 0))) { - /* re-assemble the fragmented packets */ - /* return complete frame (pRxPacket) or NULL */ - bFragment = TRUE; - pRxPacket = RTMPDeFragmentDataFrame(pAd, pRxBlk); - } - - if (pRxPacket) { - pEntry = &pAd->MacTab.Content[pRxWI->WirelessCliID]; - - /* process complete frame */ - if (bFragment && (pRxD->Decrypted) - && (pEntry->WepStatus == - Ndis802_11Encryption2Enabled)) { - /* Minus MIC length */ - pRxBlk->DataSize -= 8; - - /* For TKIP frame, calculate the MIC value */ - if (STACheckTkipMICValue(pAd, pEntry, pRxBlk) == - FALSE) { - return; - } - } - - STARxDataFrameAnnounce(pAd, pEntry, pRxBlk, - FromWhichBSSID); - return; - } else { - /* just return */ - /* because RTMPDeFragmentDataFrame() will release rx packet, */ - /* if packet is fragmented */ - return; - } - } - - ASSERT(0); - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); -} - -void STAHandleRxMgmtFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk) -{ - PRT28XX_RXD_STRUC pRxD = &(pRxBlk->RxD); - struct rt_rxwi * pRxWI = pRxBlk->pRxWI; - struct rt_header_802_11 * pHeader = pRxBlk->pHeader; - void *pRxPacket = pRxBlk->pRxPacket; - - do { - - /* check if need to resend PS Poll when received packet with MoreData = 1 */ - if ((pAd->StaCfg.Psm == PWR_SAVE) - && (pHeader->FC.MoreData == 1)) { - /* for UAPSD, all management frames will be VO priority */ - if (pAd->CommonCfg.bAPSDAC_VO == 0) { - /* non-UAPSD delivery-enabled AC */ - RTMP_PS_POLL_ENQUEUE(pAd); - } - } - - /* TODO: if MoreData == 0, station can go to sleep */ - - /* We should collect RSSI not only U2M data but also my beacon */ - if ((pHeader->FC.SubType == SUBTYPE_BEACON) - && (MAC_ADDR_EQUAL(&pAd->CommonCfg.Bssid, &pHeader->Addr2)) - && (pAd->RxAnt.EvaluatePeriod == 0)) { - Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, pRxWI); - - pAd->StaCfg.LastSNR0 = (u8)(pRxWI->SNR0); - pAd->StaCfg.LastSNR1 = (u8)(pRxWI->SNR1); - } - - /* First check the size, it MUST not exceed the mlme queue size */ - if (pRxWI->MPDUtotalByteCount > MGMT_DMA_BUFFER_SIZE) { - DBGPRINT_ERR("STAHandleRxMgmtFrame: frame too large, size = %d \n", pRxWI->MPDUtotalByteCount); - break; - } - - REPORT_MGMT_FRAME_TO_MLME(pAd, pRxWI->WirelessCliID, pHeader, - pRxWI->MPDUtotalByteCount, - pRxWI->RSSI0, pRxWI->RSSI1, - pRxWI->RSSI2, pRxD->PlcpSignal); - } while (FALSE); - - RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_SUCCESS); -} - -void STAHandleRxControlFrame(struct rt_rtmp_adapter *pAd, struct rt_rx_blk *pRxBlk) -{ - struct rt_rxwi * pRxWI = pRxBlk->pRxWI; - struct rt_header_802_11 * pHeader = pRxBlk->pHeader; - void *pRxPacket = pRxBlk->pRxPacket; - - switch (pHeader->FC.SubType) { - case SUBTYPE_BLOCK_ACK_REQ: - { - CntlEnqueueForRecv(pAd, pRxWI->WirelessCliID, - (pRxWI->MPDUtotalByteCount), - (struct rt_frame_ba_req *) pHeader); - } - break; - case SUBTYPE_BLOCK_ACK: - case SUBTYPE_ACK: - default: - break; - } - - RELEASE_NDIS_PACKET(pAd, pRxPacket, NDIS_STATUS_FAILURE); -} - -/* - ======================================================================== - - Routine Description: - Process RxDone interrupt, running in DPC level - - Arguments: - pAd Pointer to our adapter - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - This routine has to maintain Rx ring read pointer. - Need to consider QOS DATA format when converting to 802.3 - ======================================================================== -*/ -BOOLEAN STARxDoneInterruptHandle(struct rt_rtmp_adapter *pAd, IN BOOLEAN argc) -{ - int Status; - u32 RxProcessed, RxPending; - BOOLEAN bReschedule = FALSE; - PRT28XX_RXD_STRUC pRxD; - u8 *pData; - struct rt_rxwi * pRxWI; - void *pRxPacket; - struct rt_header_802_11 * pHeader; - struct rt_rx_blk RxCell; - - RxProcessed = RxPending = 0; - - /* process whole rx ring */ - while (1) { - - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF | - fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST) || - !RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)) { - break; - } -#ifdef RTMP_MAC_PCI - if (RxProcessed++ > MAX_RX_PROCESS_CNT) { - /* need to reschedule rx handle */ - bReschedule = TRUE; - break; - } -#endif /* RTMP_MAC_PCI // */ - - RxProcessed++; /* test */ - - /* 1. allocate a new data packet into rx ring to replace received packet */ - /* then processing the received packet */ - /* 2. the callee must take charge of release of packet */ - /* 3. As far as driver is concerned , */ - /* the rx packet must */ - /* a. be indicated to upper layer or */ - /* b. be released if it is discarded */ - pRxPacket = - GetPacketFromRxRing(pAd, &(RxCell.RxD), &bReschedule, - &RxPending); - if (pRxPacket == NULL) { - /* no more packet to process */ - break; - } - /* get rx ring descriptor */ - pRxD = &(RxCell.RxD); - /* get rx data buffer */ - pData = GET_OS_PKT_DATAPTR(pRxPacket); - pRxWI = (struct rt_rxwi *) pData; - pHeader = (struct rt_header_802_11 *) (pData + RXWI_SIZE); - - /* build RxCell */ - RxCell.pRxWI = pRxWI; - RxCell.pHeader = pHeader; - RxCell.pRxPacket = pRxPacket; - RxCell.pData = (u8 *) pHeader; - RxCell.DataSize = pRxWI->MPDUtotalByteCount; - RxCell.Flags = 0; - - /* Increase Total receive byte counter after real data received no mater any error or not */ - pAd->RalinkCounters.ReceivedByteCount += - pRxWI->MPDUtotalByteCount; - pAd->RalinkCounters.OneSecReceivedByteCount += - pRxWI->MPDUtotalByteCount; - pAd->RalinkCounters.RxCount++; - - INC_COUNTER64(pAd->WlanCounters.ReceivedFragmentCount); - - if (pRxWI->MPDUtotalByteCount < 14) - Status = NDIS_STATUS_FAILURE; - - if (MONITOR_ON(pAd)) { - send_monitor_packets(pAd, &RxCell); - break; - } - - /* STARxDoneInterruptHandle() is called in rtusb_bulk.c */ - - /* Check for all RxD errors */ - Status = RTMPCheckRxError(pAd, pHeader, pRxWI, pRxD); - - /* Handle the received frame */ - if (Status == NDIS_STATUS_SUCCESS) { - switch (pHeader->FC.Type) { - /* CASE I, receive a DATA frame */ - case BTYPE_DATA: - { - /* process DATA frame */ - STAHandleRxDataFrame(pAd, &RxCell); - } - break; - /* CASE II, receive a MGMT frame */ - case BTYPE_MGMT: - { - STAHandleRxMgmtFrame(pAd, &RxCell); - } - break; - /* CASE III. receive a CNTL frame */ - case BTYPE_CNTL: - { - STAHandleRxControlFrame(pAd, &RxCell); - } - break; - /* discard other type */ - default: - RELEASE_NDIS_PACKET(pAd, pRxPacket, - NDIS_STATUS_FAILURE); - break; - } - } else { - pAd->Counters8023.RxErrors++; - /* discard this frame */ - RELEASE_NDIS_PACKET(pAd, pRxPacket, - NDIS_STATUS_FAILURE); - } - } - - return bReschedule; -} - -/* - ======================================================================== - - Routine Description: - Arguments: - pAd Pointer to our adapter - - IRQL = DISPATCH_LEVEL - - ======================================================================== -*/ -void RTMPHandleTwakeupInterrupt(struct rt_rtmp_adapter *pAd) -{ - AsicForceWakeup(pAd, FALSE); -} - -/* -======================================================================== -Routine Description: - Early checking and OS-depened parsing for Tx packet send to our STA driver. - -Arguments: - void * MiniportAdapterContext Pointer refer to the device handle, i.e., the pAd. - void ** ppPacketArray The packet array need to do transmission. - u32 NumberOfPackets Number of packet in packet array. - -Return Value: - NONE - -Note: - This function does early checking and classification for send-out packet. - You only can put OS-depened & STA related code in here. -======================================================================== -*/ -void STASendPackets(void *MiniportAdapterContext, - void **ppPacketArray, u32 NumberOfPackets) -{ - u32 Index; - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)MiniportAdapterContext; - void *pPacket; - BOOLEAN allowToSend = FALSE; - - for (Index = 0; Index < NumberOfPackets; Index++) { - pPacket = ppPacketArray[Index]; - - do { - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS) - || RTMP_TEST_FLAG(pAd, - fRTMP_ADAPTER_HALT_IN_PROGRESS) - || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RADIO_OFF)) { - /* Drop send request since hardware is in reset state */ - break; - } else if (!INFRA_ON(pAd) && !ADHOC_ON(pAd)) { - /* Drop send request since there are no physical connection yet */ - break; - } else { - /* Record that orignal packet source is from NDIS layer,so that */ - /* later on driver knows how to release this NDIS PACKET */ - RTMP_SET_PACKET_WCID(pPacket, 0); /* this field is useless when in STA mode */ - RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS); - NDIS_SET_PACKET_STATUS(pPacket, - NDIS_STATUS_PENDING); - pAd->RalinkCounters.PendingNdisPacketCount++; - - allowToSend = TRUE; - } - } while (FALSE); - - if (allowToSend == TRUE) - STASendPacket(pAd, pPacket); - else - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - } - - /* Dequeue outgoing frames from TxSwQueue[] and process it */ - RTMPDeQueuePacket(pAd, FALSE, NUM_OF_TX_RING, MAX_TX_PROCESS); - -} - -/* -======================================================================== -Routine Description: - This routine is used to do packet parsing and classification for Tx packet - to STA device, and it will en-queue packets to our TxSwQueue depends on AC - class. - -Arguments: - pAd Pointer to our adapter - pPacket Pointer to send packet - -Return Value: - NDIS_STATUS_SUCCESS If success to queue the packet into TxSwQueue. - NDIS_STATUS_FAILURE If failed to do en-queue. - -Note: - You only can put OS-indepened & STA related code in here. -======================================================================== -*/ -int STASendPacket(struct rt_rtmp_adapter *pAd, void *pPacket) -{ - struct rt_packet_info PacketInfo; - u8 *pSrcBufVA; - u32 SrcBufLen; - u32 AllowFragSize; - u8 NumberOfFrag; - u8 RTSRequired; - u8 QueIdx, UserPriority; - struct rt_mac_table_entry *pEntry = NULL; - unsigned int IrqFlags; - u8 FlgIsIP = 0; - u8 Rate; - - /* Prepare packet information structure for buffer descriptor */ - /* chained within a single NDIS packet. */ - RTMP_QueryPacketInfo(pPacket, &PacketInfo, &pSrcBufVA, &SrcBufLen); - - if (pSrcBufVA == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("STASendPacket --> pSrcBufVA == NULL !SrcBufLen=%x\n", - SrcBufLen)); - /* Resource is low, system did not allocate virtual address */ - /* return NDIS_STATUS_FAILURE directly to upper layer */ - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - return NDIS_STATUS_FAILURE; - } - - if (SrcBufLen < 14) { - DBGPRINT(RT_DEBUG_ERROR, - ("STASendPacket --> Ndis Packet buffer error!\n")); - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - return (NDIS_STATUS_FAILURE); - } - /* In HT rate adhoc mode, A-MPDU is often used. So need to lookup BA Table and MAC Entry. */ - /* Note multicast packets in adhoc also use BSSID_WCID index. */ - { - if (INFRA_ON(pAd)) { - { - pEntry = &pAd->MacTab.Content[BSSID_WCID]; - RTMP_SET_PACKET_WCID(pPacket, BSSID_WCID); - Rate = pAd->CommonCfg.TxRate; - } - } else if (ADHOC_ON(pAd)) { - if (*pSrcBufVA & 0x01) { - RTMP_SET_PACKET_WCID(pPacket, MCAST_WCID); - pEntry = &pAd->MacTab.Content[MCAST_WCID]; - } else { - pEntry = MacTableLookup(pAd, pSrcBufVA); - } - Rate = pAd->CommonCfg.TxRate; - } - } - - if (!pEntry) { - DBGPRINT(RT_DEBUG_ERROR, - ("STASendPacket->Cannot find pEntry(%pM) in MacTab!\n", - pSrcBufVA)); - /* Resource is low, system did not allocate virtual address */ - /* return NDIS_STATUS_FAILURE directly to upper layer */ - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - return NDIS_STATUS_FAILURE; - } - - if (ADHOC_ON(pAd) - ) { - RTMP_SET_PACKET_WCID(pPacket, (u8)pEntry->Aid); - } - /* */ - /* Check the Ethernet Frame type of this packet, and set the RTMP_SET_PACKET_SPECIFIC flags. */ - /* Here we set the PACKET_SPECIFIC flags(LLC, VLAN, DHCP/ARP, EAPOL). */ - RTMPCheckEtherType(pAd, pPacket); - - /* */ - /* WPA 802.1x secured port control - drop all non-802.1x frame before port secured */ - /* */ - if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) - || (pAd->StaCfg.IEEE8021X == TRUE) - ) - && ((pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED) - || (pAd->StaCfg.MicErrCnt >= 2)) - && (RTMP_GET_PACKET_EAPOL(pPacket) == FALSE) - ) { - DBGPRINT(RT_DEBUG_TRACE, - ("STASendPacket --> Drop packet before port secured!\n")); - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - - return (NDIS_STATUS_FAILURE); - } - - /* STEP 1. Decide number of fragments required to deliver this MSDU. */ - /* The estimation here is not very accurate because difficult to */ - /* take encryption overhead into consideration here. The result */ - /* "NumberOfFrag" is then just used to pre-check if enough free */ - /* TXD are available to hold this MSDU. */ - - if (*pSrcBufVA & 0x01) /* fragmentation not allowed on multicast & broadcast */ - NumberOfFrag = 1; - else if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_AGGREGATION_INUSED)) - NumberOfFrag = 1; /* Aggregation overwhelms fragmentation */ - else if (CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_AMSDU_INUSED)) - NumberOfFrag = 1; /* Aggregation overwhelms fragmentation */ - else if ((pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTMIX) - || (pAd->StaCfg.HTPhyMode.field.MODE == MODE_HTGREENFIELD)) - NumberOfFrag = 1; /* MIMO RATE overwhelms fragmentation */ - else { - /* The calculated "NumberOfFrag" is a rough estimation because of various */ - /* encryption/encapsulation overhead not taken into consideration. This number is just */ - /* used to make sure enough free TXD are available before fragmentation takes place. */ - /* In case the actual required number of fragments of an NDIS packet */ - /* excceeds "NumberOfFrag"caculated here and not enough free TXD available, the */ - /* last fragment (i.e. last MPDU) will be dropped in RTMPHardTransmit() due to out of */ - /* resource, and the NDIS packet will be indicated NDIS_STATUS_FAILURE. This should */ - /* rarely happen and the penalty is just like a TX RETRY fail. Affordable. */ - - AllowFragSize = - (pAd->CommonCfg.FragmentThreshold) - LENGTH_802_11 - - LENGTH_CRC; - NumberOfFrag = - ((PacketInfo.TotalPacketLength - LENGTH_802_3 + - LENGTH_802_1_H) / AllowFragSize) + 1; - /* To get accurate number of fragmentation, Minus 1 if the size just match to allowable fragment size */ - if (((PacketInfo.TotalPacketLength - LENGTH_802_3 + - LENGTH_802_1_H) % AllowFragSize) == 0) { - NumberOfFrag--; - } - } - - /* Save fragment number to Ndis packet reserved field */ - RTMP_SET_PACKET_FRAGMENTS(pPacket, NumberOfFrag); - - /* STEP 2. Check the requirement of RTS: */ - /* If multiple fragment required, RTS is required only for the first fragment */ - /* if the fragment size is larger than RTS threshold */ - /* For RT28xx, Let ASIC send RTS/CTS */ - /* RTMP_SET_PACKET_RTS(pPacket, 0); */ - if (NumberOfFrag > 1) - RTSRequired = - (pAd->CommonCfg.FragmentThreshold > - pAd->CommonCfg.RtsThreshold) ? 1 : 0; - else - RTSRequired = - (PacketInfo.TotalPacketLength > - pAd->CommonCfg.RtsThreshold) ? 1 : 0; - - /* Save RTS requirement to Ndis packet reserved field */ - RTMP_SET_PACKET_RTS(pPacket, RTSRequired); - RTMP_SET_PACKET_TXRATE(pPacket, pAd->CommonCfg.TxRate); - - /* */ - /* STEP 3. Traffic classification. outcome = */ - /* */ - UserPriority = 0; - QueIdx = QID_AC_BE; - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_WMM_INUSED) && - CLIENT_STATUS_TEST_FLAG(pEntry, fCLIENT_STATUS_WMM_CAPABLE)) { - u16 Protocol; - u8 LlcSnapLen = 0, Byte0, Byte1; - do { - /* get Ethernet protocol field */ - Protocol = - (u16)((pSrcBufVA[12] << 8) + pSrcBufVA[13]); - if (Protocol <= 1500) { - /* get Ethernet protocol field from LLC/SNAP */ - if (Sniff2BytesFromNdisBuffer - (PacketInfo.pFirstBuffer, LENGTH_802_3 + 6, - &Byte0, &Byte1) != NDIS_STATUS_SUCCESS) - break; - - Protocol = (u16)((Byte0 << 8) + Byte1); - LlcSnapLen = 8; - } - /* always AC_BE for non-IP packet */ - if (Protocol != 0x0800) - break; - - /* get IP header */ - if (Sniff2BytesFromNdisBuffer - (PacketInfo.pFirstBuffer, LENGTH_802_3 + LlcSnapLen, - &Byte0, &Byte1) != NDIS_STATUS_SUCCESS) - break; - - /* return AC_BE if packet is not IPv4 */ - if ((Byte0 & 0xf0) != 0x40) - break; - - FlgIsIP = 1; - UserPriority = (Byte1 & 0xe0) >> 5; - QueIdx = MapUserPriorityToAccessCategory[UserPriority]; - - /* TODO: have to check ACM bit. apply TSPEC if ACM is ON */ - /* TODO: downgrade UP & QueIdx before passing ACM */ - /* - Under WMM ACM control, we dont need to check the bit; - Or when a TSPEC is built for VO but we will change to issue - BA session for BE here, so we will not use BA to send VO packets. - */ - if (pAd->CommonCfg.APEdcaParm.bACM[QueIdx]) { - UserPriority = 0; - QueIdx = QID_AC_BE; - } - } while (FALSE); - } - - RTMP_SET_PACKET_UP(pPacket, UserPriority); - - /* Make sure SendTxWait queue resource won't be used by other threads */ - RTMP_IRQ_LOCK(&pAd->irq_lock, IrqFlags); - if (pAd->TxSwQueue[QueIdx].Number >= MAX_PACKETS_IN_QUEUE) { - RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - - return NDIS_STATUS_FAILURE; - } else { - InsertTailQueueAc(pAd, pEntry, &pAd->TxSwQueue[QueIdx], - PACKET_TO_QUEUE_ENTRY(pPacket)); - } - RTMP_IRQ_UNLOCK(&pAd->irq_lock, IrqFlags); - - if ((pAd->CommonCfg.BACapability.field.AutoBA == TRUE) && - IS_HT_STA(pEntry)) { - /*struct rt_mac_table_entry *pMacEntry = &pAd->MacTab.Content[BSSID_WCID]; */ - if (((pEntry->TXBAbitmap & (1 << UserPriority)) == 0) && - ((pEntry->BADeclineBitmap & (1 << UserPriority)) == 0) && - (pEntry->PortSecured == WPA_802_1X_PORT_SECURED) - /* For IOT compatibility, if */ - /* 1. It is Ralink chip or */ - /* 2. It is OPEN or AES mode, */ - /* then BA session can be bulit. */ - && ((pEntry->ValidAsCLI && pAd->MlmeAux.APRalinkIe != 0x0) - || (pEntry->WepStatus != Ndis802_11WEPEnabled - && pEntry->WepStatus != - Ndis802_11Encryption2Enabled)) - ) { - BAOriSessionSetUp(pAd, pEntry, UserPriority, 0, 10, - FALSE); - } - } - - pAd->RalinkCounters.OneSecOsTxCount[QueIdx]++; /* TODO: for debug only. to be removed */ - return NDIS_STATUS_SUCCESS; -} - -/* - ======================================================================== - - Routine Description: - This subroutine will scan through relative ring descriptor to find - out available free ring descriptor and compare with request size. - - Arguments: - pAd Pointer to our adapter - QueIdx Selected TX Ring - - Return Value: - NDIS_STATUS_FAILURE Not enough free descriptor - NDIS_STATUS_SUCCESS Enough free descriptor - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -#ifdef RTMP_MAC_PCI -int RTMPFreeTXDRequest(struct rt_rtmp_adapter *pAd, - u8 QueIdx, - u8 NumberRequired, u8 *FreeNumberIs) -{ - unsigned long FreeNumber = 0; - int Status = NDIS_STATUS_FAILURE; - - switch (QueIdx) { - case QID_AC_BK: - case QID_AC_BE: - case QID_AC_VI: - case QID_AC_VO: - if (pAd->TxRing[QueIdx].TxSwFreeIdx > - pAd->TxRing[QueIdx].TxCpuIdx) - FreeNumber = - pAd->TxRing[QueIdx].TxSwFreeIdx - - pAd->TxRing[QueIdx].TxCpuIdx - 1; - else - FreeNumber = - pAd->TxRing[QueIdx].TxSwFreeIdx + TX_RING_SIZE - - pAd->TxRing[QueIdx].TxCpuIdx - 1; - - if (FreeNumber >= NumberRequired) - Status = NDIS_STATUS_SUCCESS; - break; - - case QID_MGMT: - if (pAd->MgmtRing.TxSwFreeIdx > pAd->MgmtRing.TxCpuIdx) - FreeNumber = - pAd->MgmtRing.TxSwFreeIdx - pAd->MgmtRing.TxCpuIdx - - 1; - else - FreeNumber = - pAd->MgmtRing.TxSwFreeIdx + MGMT_RING_SIZE - - pAd->MgmtRing.TxCpuIdx - 1; - - if (FreeNumber >= NumberRequired) - Status = NDIS_STATUS_SUCCESS; - break; - - default: - DBGPRINT(RT_DEBUG_ERROR, - ("RTMPFreeTXDRequest::Invalid QueIdx(=%d)\n", QueIdx)); - break; - } - *FreeNumberIs = (u8)FreeNumber; - - return (Status); -} -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB -/* - Actually, this function used to check if the TxHardware Queue still has frame need to send. - If no frame need to send, go to sleep, else, still wake up. -*/ -int RTMPFreeTXDRequest(struct rt_rtmp_adapter *pAd, - u8 QueIdx, - u8 NumberRequired, u8 *FreeNumberIs) -{ - /*unsigned long FreeNumber = 0; */ - int Status = NDIS_STATUS_FAILURE; - unsigned long IrqFlags; - struct rt_ht_tx_context *pHTTXContext; - - switch (QueIdx) { - case QID_AC_BK: - case QID_AC_BE: - case QID_AC_VI: - case QID_AC_VO: - { - pHTTXContext = &pAd->TxContext[QueIdx]; - RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[QueIdx], - IrqFlags); - if ((pHTTXContext->CurWritePosition != - pHTTXContext->ENextBulkOutPosition) - || (pHTTXContext->IRPPending == TRUE)) { - Status = NDIS_STATUS_FAILURE; - } else { - Status = NDIS_STATUS_SUCCESS; - } - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[QueIdx], - IrqFlags); - } - break; - case QID_MGMT: - if (pAd->MgmtRing.TxSwFreeIdx != MGMT_RING_SIZE) - Status = NDIS_STATUS_FAILURE; - else - Status = NDIS_STATUS_SUCCESS; - break; - default: - DBGPRINT(RT_DEBUG_ERROR, - ("RTMPFreeTXDRequest::Invalid QueIdx(=%d)\n", QueIdx)); - break; - } - - return (Status); -} -#endif /* RTMP_MAC_USB // */ - -void RTMPSendDisassociationFrame(struct rt_rtmp_adapter *pAd) -{ -} - -void RTMPSendNullFrame(struct rt_rtmp_adapter *pAd, - u8 TxRate, IN BOOLEAN bQosNull) -{ - u8 NullFrame[48]; - unsigned long Length; - struct rt_header_802_11 * pHeader_802_11; - - /* WPA 802.1x secured port control */ - if (((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPAPSK) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) - || (pAd->StaCfg.IEEE8021X == TRUE) - ) && (pAd->StaCfg.PortSecured == WPA_802_1X_PORT_NOT_SECURED)) { - return; - } - - NdisZeroMemory(NullFrame, 48); - Length = sizeof(struct rt_header_802_11); - - pHeader_802_11 = (struct rt_header_802_11 *) NullFrame; - - pHeader_802_11->FC.Type = BTYPE_DATA; - pHeader_802_11->FC.SubType = SUBTYPE_NULL_FUNC; - pHeader_802_11->FC.ToDs = 1; - COPY_MAC_ADDR(pHeader_802_11->Addr1, pAd->CommonCfg.Bssid); - COPY_MAC_ADDR(pHeader_802_11->Addr2, pAd->CurrentAddress); - COPY_MAC_ADDR(pHeader_802_11->Addr3, pAd->CommonCfg.Bssid); - - if (pAd->CommonCfg.bAPSDForcePowerSave) { - pHeader_802_11->FC.PwrMgmt = PWR_SAVE; - } else { - pHeader_802_11->FC.PwrMgmt = - (pAd->StaCfg.Psm == PWR_SAVE) ? 1 : 0; - } - pHeader_802_11->Duration = - pAd->CommonCfg.Dsifs + RTMPCalcDuration(pAd, TxRate, 14); - - pAd->Sequence++; - pHeader_802_11->Sequence = pAd->Sequence; - - /* Prepare QosNull function frame */ - if (bQosNull) { - pHeader_802_11->FC.SubType = SUBTYPE_QOS_NULL; - - /* copy QOS control bytes */ - NullFrame[Length] = 0; - NullFrame[Length + 1] = 0; - Length += 2; /* if pad with 2 bytes for alignment, APSD will fail */ - } - - HAL_KickOutNullFrameTx(pAd, 0, NullFrame, Length); - -} - -/* IRQL = DISPATCH_LEVEL */ -void RTMPSendRTSFrame(struct rt_rtmp_adapter *pAd, - u8 *pDA, - IN unsigned int NextMpduSize, - u8 TxRate, - u8 RTSRate, - u16 AckDuration, u8 QueIdx, u8 FrameGap) -{ -} - -/* -------------------------------------------------------- */ -/* FIND ENCRYPT KEY AND DECIDE CIPHER ALGORITHM */ -/* Find the WPA key, either Group or Pairwise Key */ -/* LEAP + TKIP also use WPA key. */ -/* -------------------------------------------------------- */ -/* Decide WEP bit and cipher suite to be used. Same cipher suite should be used for whole fragment burst */ -/* In Cisco CCX 2.0 Leap Authentication */ -/* WepStatus is Ndis802_11Encryption1Enabled but the key will use PairwiseKey */ -/* Instead of the SharedKey, SharedKey Length may be Zero. */ -void STAFindCipherAlgorithm(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk) -{ - NDIS_802_11_ENCRYPTION_STATUS Cipher; /* To indicate cipher used for this packet */ - u8 CipherAlg = CIPHER_NONE; /* cipher alogrithm */ - u8 KeyIdx = 0xff; - u8 *pSrcBufVA; - struct rt_cipher_key *pKey = NULL; - - pSrcBufVA = GET_OS_PKT_DATAPTR(pTxBlk->pPacket); - - { - /* Select Cipher */ - if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))) - Cipher = pAd->StaCfg.GroupCipher; /* Cipher for Multicast or Broadcast */ - else - Cipher = pAd->StaCfg.PairCipher; /* Cipher for Unicast */ - - if (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket)) { - ASSERT(pAd->SharedKey[BSS0][0].CipherAlg <= - CIPHER_CKIP128); - - /* 4-way handshaking frame must be clear */ - if (!(TX_BLK_TEST_FLAG(pTxBlk, fTX_bClearEAPFrame)) - && (pAd->SharedKey[BSS0][0].CipherAlg) - && (pAd->SharedKey[BSS0][0].KeyLen)) { - CipherAlg = pAd->SharedKey[BSS0][0].CipherAlg; - KeyIdx = 0; - } - } else if (Cipher == Ndis802_11Encryption1Enabled) { - KeyIdx = pAd->StaCfg.DefaultKeyId; - } else if ((Cipher == Ndis802_11Encryption2Enabled) || - (Cipher == Ndis802_11Encryption3Enabled)) { - if ((*pSrcBufVA & 0x01) && (ADHOC_ON(pAd))) /* multicast */ - KeyIdx = pAd->StaCfg.DefaultKeyId; - else if (pAd->SharedKey[BSS0][0].KeyLen) - KeyIdx = 0; - else - KeyIdx = pAd->StaCfg.DefaultKeyId; - } - - if (KeyIdx == 0xff) - CipherAlg = CIPHER_NONE; - else if ((Cipher == Ndis802_11EncryptionDisabled) - || (pAd->SharedKey[BSS0][KeyIdx].KeyLen == 0)) - CipherAlg = CIPHER_NONE; - else if (pAd->StaCfg.WpaSupplicantUP && - (Cipher == Ndis802_11Encryption1Enabled) && - (pAd->StaCfg.IEEE8021X == TRUE) && - (pAd->StaCfg.PortSecured == - WPA_802_1X_PORT_NOT_SECURED)) - CipherAlg = CIPHER_NONE; - else { - /*Header_802_11.FC.Wep = 1; */ - CipherAlg = pAd->SharedKey[BSS0][KeyIdx].CipherAlg; - pKey = &pAd->SharedKey[BSS0][KeyIdx]; - } - } - - pTxBlk->CipherAlg = CipherAlg; - pTxBlk->pKey = pKey; -} - -void STABuildCommon802_11Header(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk) -{ - struct rt_header_802_11 *pHeader_802_11; - - /* */ - /* MAKE A COMMON 802.11 HEADER */ - /* */ - - /* normal wlan header size : 24 octets */ - pTxBlk->MpduHeaderLen = sizeof(struct rt_header_802_11); - - pHeader_802_11 = - (struct rt_header_802_11 *) & pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; - - NdisZeroMemory(pHeader_802_11, sizeof(struct rt_header_802_11)); - - pHeader_802_11->FC.FrDs = 0; - pHeader_802_11->FC.Type = BTYPE_DATA; - pHeader_802_11->FC.SubType = - ((TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) ? SUBTYPE_QDATA : - SUBTYPE_DATA); - - if (pTxBlk->pMacEntry) { - if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bForceNonQoS)) { - pHeader_802_11->Sequence = - pTxBlk->pMacEntry->NonQosDataSeq; - pTxBlk->pMacEntry->NonQosDataSeq = - (pTxBlk->pMacEntry->NonQosDataSeq + 1) & MAXSEQ; - } else { - { - pHeader_802_11->Sequence = - pTxBlk->pMacEntry->TxSeq[pTxBlk-> - UserPriority]; - pTxBlk->pMacEntry->TxSeq[pTxBlk->UserPriority] = - (pTxBlk->pMacEntry-> - TxSeq[pTxBlk->UserPriority] + 1) & MAXSEQ; - } - } - } else { - pHeader_802_11->Sequence = pAd->Sequence; - pAd->Sequence = (pAd->Sequence + 1) & MAXSEQ; /* next sequence */ - } - - pHeader_802_11->Frag = 0; - - pHeader_802_11->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData); - - { - if (INFRA_ON(pAd)) { - { - COPY_MAC_ADDR(pHeader_802_11->Addr1, - pAd->CommonCfg.Bssid); - COPY_MAC_ADDR(pHeader_802_11->Addr2, - pAd->CurrentAddress); - COPY_MAC_ADDR(pHeader_802_11->Addr3, - pTxBlk->pSrcBufHeader); - pHeader_802_11->FC.ToDs = 1; - } - } else if (ADHOC_ON(pAd)) { - COPY_MAC_ADDR(pHeader_802_11->Addr1, - pTxBlk->pSrcBufHeader); - COPY_MAC_ADDR(pHeader_802_11->Addr2, - pAd->CurrentAddress); - COPY_MAC_ADDR(pHeader_802_11->Addr3, - pAd->CommonCfg.Bssid); - pHeader_802_11->FC.ToDs = 0; - } - } - - if (pTxBlk->CipherAlg != CIPHER_NONE) - pHeader_802_11->FC.Wep = 1; - - /* ----------------------------------------------------------------- */ - /* STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later. */ - /* ----------------------------------------------------------------- */ - if (pAd->CommonCfg.bAPSDForcePowerSave) - pHeader_802_11->FC.PwrMgmt = PWR_SAVE; - else - pHeader_802_11->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE); -} - -void STABuildCache802_11Header(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, u8 * pHeader) -{ - struct rt_mac_table_entry *pMacEntry; - struct rt_header_802_11 * pHeader80211; - - pHeader80211 = (struct rt_header_802_11 *) pHeader; - pMacEntry = pTxBlk->pMacEntry; - - /* */ - /* Update the cached 802.11 HEADER */ - /* */ - - /* normal wlan header size : 24 octets */ - pTxBlk->MpduHeaderLen = sizeof(struct rt_header_802_11); - - /* More Bit */ - pHeader80211->FC.MoreData = TX_BLK_TEST_FLAG(pTxBlk, fTX_bMoreData); - - /* Sequence */ - pHeader80211->Sequence = pMacEntry->TxSeq[pTxBlk->UserPriority]; - pMacEntry->TxSeq[pTxBlk->UserPriority] = - (pMacEntry->TxSeq[pTxBlk->UserPriority] + 1) & MAXSEQ; - - { - /* Check if the frame can be sent through DLS direct link interface */ - /* If packet can be sent through DLS, then force aggregation disable. (Hard to determine peer STA's capability) */ - - /* The addr3 of normal packet send from DS is Dest Mac address. */ - if (ADHOC_ON(pAd)) - COPY_MAC_ADDR(pHeader80211->Addr3, - pAd->CommonCfg.Bssid); - else - COPY_MAC_ADDR(pHeader80211->Addr3, - pTxBlk->pSrcBufHeader); - } - - /* ----------------------------------------------------------------- */ - /* STEP 2. MAKE A COMMON 802.11 HEADER SHARED BY ENTIRE FRAGMENT BURST. Fill sequence later. */ - /* ----------------------------------------------------------------- */ - if (pAd->CommonCfg.bAPSDForcePowerSave) - pHeader80211->FC.PwrMgmt = PWR_SAVE; - else - pHeader80211->FC.PwrMgmt = (pAd->StaCfg.Psm == PWR_SAVE); -} - -static inline u8 *STA_Build_ARalink_Frame_Header(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk) -{ - u8 *pHeaderBufPtr; - struct rt_header_802_11 *pHeader_802_11; - void *pNextPacket; - u32 nextBufLen; - struct rt_queue_entry *pQEntry; - - STAFindCipherAlgorithm(pAd, pTxBlk); - STABuildCommon802_11Header(pAd, pTxBlk); - - pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; - pHeader_802_11 = (struct rt_header_802_11 *) pHeaderBufPtr; - - /* steal "order" bit to mark "aggregation" */ - pHeader_802_11->FC.Order = 1; - - /* skip common header */ - pHeaderBufPtr += pTxBlk->MpduHeaderLen; - - if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) { - /* */ - /* build QOS Control bytes */ - /* */ - *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F); - - *(pHeaderBufPtr + 1) = 0; - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += 2; - } - /* padding at front of LLC header. LLC header should at 4-bytes alignment. */ - pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr; - pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4); - pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen); - - /* For RA Aggregation, */ - /* put the 2nd MSDU length(extra 2-byte field) after struct rt_qos_control in little endian format */ - pQEntry = pTxBlk->TxPacketList.Head; - pNextPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); - nextBufLen = GET_OS_PKT_LEN(pNextPacket); - if (RTMP_GET_PACKET_VLAN(pNextPacket)) - nextBufLen -= LENGTH_802_1Q; - - *pHeaderBufPtr = (u8)nextBufLen & 0xff; - *(pHeaderBufPtr + 1) = (u8)(nextBufLen >> 8); - - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += 2; - - return pHeaderBufPtr; - -} - -static inline u8 *STA_Build_AMSDU_Frame_Header(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk) -{ - u8 *pHeaderBufPtr; /*, pSaveBufPtr; */ - struct rt_header_802_11 *pHeader_802_11; - - STAFindCipherAlgorithm(pAd, pTxBlk); - STABuildCommon802_11Header(pAd, pTxBlk); - - pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; - pHeader_802_11 = (struct rt_header_802_11 *) pHeaderBufPtr; - - /* skip common header */ - pHeaderBufPtr += pTxBlk->MpduHeaderLen; - - /* */ - /* build QOS Control bytes */ - /* */ - *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F); - - /* */ - /* A-MSDU packet */ - /* */ - *pHeaderBufPtr |= 0x80; - - *(pHeaderBufPtr + 1) = 0; - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += 2; - - /*pSaveBufPtr = pHeaderBufPtr; */ - - /* */ - /* padding at front of LLC header */ - /* LLC header should locate at 4-octets aligment */ - /* */ - /* @@@ MpduHeaderLen excluding padding @@@ */ - /* */ - pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr; - pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4); - pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen); - - return pHeaderBufPtr; - -} - -void STA_AMPDU_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk) -{ - struct rt_header_802_11 *pHeader_802_11; - u8 *pHeaderBufPtr; - u16 FreeNumber; - struct rt_mac_table_entry *pMacEntry; - BOOLEAN bVLANPkt; - struct rt_queue_entry *pQEntry; - - ASSERT(pTxBlk); - - while (pTxBlk->TxPacketList.Head) { - pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); - pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); - if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) { - RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, - NDIS_STATUS_FAILURE); - continue; - } - - bVLANPkt = - (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE); - - pMacEntry = pTxBlk->pMacEntry; - if (pMacEntry->isCached) { - /* NOTE: Please make sure the size of pMacEntry->CachedBuf[] is smaller than pTxBlk->HeaderBuf[]! */ - NdisMoveMemory((u8 *)& pTxBlk-> - HeaderBuf[TXINFO_SIZE], - (u8 *)& pMacEntry->CachedBuf[0], - TXWI_SIZE + sizeof(struct rt_header_802_11)); - pHeaderBufPtr = - (u8 *)(&pTxBlk-> - HeaderBuf[TXINFO_SIZE + TXWI_SIZE]); - STABuildCache802_11Header(pAd, pTxBlk, pHeaderBufPtr); - } else { - STAFindCipherAlgorithm(pAd, pTxBlk); - STABuildCommon802_11Header(pAd, pTxBlk); - - pHeaderBufPtr = - &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; - } - - pHeader_802_11 = (struct rt_header_802_11 *) pHeaderBufPtr; - - /* skip common header */ - pHeaderBufPtr += pTxBlk->MpduHeaderLen; - - /* */ - /* build QOS Control bytes */ - /* */ - *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F); - *(pHeaderBufPtr + 1) = 0; - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += 2; - - /* */ - /* build HTC+ */ - /* HTC control filed following QoS field */ - /* */ - if ((pAd->CommonCfg.bRdg == TRUE) - && CLIENT_STATUS_TEST_FLAG(pTxBlk->pMacEntry, - fCLIENT_STATUS_RDG_CAPABLE)) { - if (pMacEntry->isCached == FALSE) { - /* mark HTC bit */ - pHeader_802_11->FC.Order = 1; - - NdisZeroMemory(pHeaderBufPtr, 4); - *(pHeaderBufPtr + 3) |= 0x80; - } - pHeaderBufPtr += 4; - pTxBlk->MpduHeaderLen += 4; - } - /*pTxBlk->MpduHeaderLen = pHeaderBufPtr - pTxBlk->HeaderBuf - TXWI_SIZE - TXINFO_SIZE; */ - ASSERT(pTxBlk->MpduHeaderLen >= 24); - - /* skip 802.3 header */ - pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3; - pTxBlk->SrcBufLen -= LENGTH_802_3; - - /* skip vlan tag */ - if (bVLANPkt) { - pTxBlk->pSrcBufData += LENGTH_802_1Q; - pTxBlk->SrcBufLen -= LENGTH_802_1Q; - } - /* */ - /* padding at front of LLC header */ - /* LLC header should locate at 4-octets aligment */ - /* */ - /* @@@ MpduHeaderLen excluding padding @@@ */ - /* */ - pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr; - pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4); - pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen); - - { - - /* */ - /* Insert LLC-SNAP encapsulation - 8 octets */ - /* */ - EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk-> - pSrcBufData - 2, - pTxBlk-> - pExtraLlcSnapEncap); - if (pTxBlk->pExtraLlcSnapEncap) { - NdisMoveMemory(pHeaderBufPtr, - pTxBlk->pExtraLlcSnapEncap, 6); - pHeaderBufPtr += 6; - /* get 2 octets (TypeofLen) */ - NdisMoveMemory(pHeaderBufPtr, - pTxBlk->pSrcBufData - 2, 2); - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += LENGTH_802_1_H; - } - - } - - if (pMacEntry->isCached) { - RTMPWriteTxWI_Cache(pAd, - (struct rt_txwi *) (&pTxBlk-> - HeaderBuf - [TXINFO_SIZE]), - pTxBlk); - } else { - RTMPWriteTxWI_Data(pAd, - (struct rt_txwi *) (&pTxBlk-> - HeaderBuf - [TXINFO_SIZE]), - pTxBlk); - - NdisZeroMemory((u8 *)(&pMacEntry->CachedBuf[0]), - sizeof(pMacEntry->CachedBuf)); - NdisMoveMemory((u8 *)(&pMacEntry->CachedBuf[0]), - (u8 *)(&pTxBlk-> - HeaderBuf[TXINFO_SIZE]), - (pHeaderBufPtr - - (u8 *)(&pTxBlk-> - HeaderBuf[TXINFO_SIZE]))); - pMacEntry->isCached = TRUE; - } - - /* calculate Transmitted AMPDU count and ByteCount */ - { - pAd->RalinkCounters.TransmittedMPDUsInAMPDUCount.u. - LowPart++; - pAd->RalinkCounters.TransmittedOctetsInAMPDUCount. - QuadPart += pTxBlk->SrcBufLen; - } - - /*FreeNumber = GET_TXRING_FREENO(pAd, QueIdx); */ - - HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber); - - /* */ - /* Kick out Tx */ - /* */ - if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX)) - HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx); - - pAd->RalinkCounters.KickTxCount++; - pAd->RalinkCounters.OneSecTxDoneCount++; - } - -} - -void STA_AMSDU_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk) -{ - u8 *pHeaderBufPtr; - u16 FreeNumber; - u16 subFramePayloadLen = 0; /* AMSDU Subframe length without AMSDU-Header / Padding. */ - u16 totalMPDUSize = 0; - u8 *subFrameHeader; - u8 padding = 0; - u16 FirstTx = 0, LastTxIdx = 0; - BOOLEAN bVLANPkt; - int frameNum = 0; - struct rt_queue_entry *pQEntry; - - ASSERT(pTxBlk); - - ASSERT((pTxBlk->TxPacketList.Number > 1)); - - while (pTxBlk->TxPacketList.Head) { - pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); - pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); - if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) { - RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, - NDIS_STATUS_FAILURE); - continue; - } - - bVLANPkt = - (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE); - - /* skip 802.3 header */ - pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3; - pTxBlk->SrcBufLen -= LENGTH_802_3; - - /* skip vlan tag */ - if (bVLANPkt) { - pTxBlk->pSrcBufData += LENGTH_802_1Q; - pTxBlk->SrcBufLen -= LENGTH_802_1Q; - } - - if (frameNum == 0) { - pHeaderBufPtr = - STA_Build_AMSDU_Frame_Header(pAd, pTxBlk); - - /* NOTE: TxWI->MPDUtotalByteCount will be updated after final frame was handled. */ - RTMPWriteTxWI_Data(pAd, - (struct rt_txwi *) (&pTxBlk-> - HeaderBuf - [TXINFO_SIZE]), - pTxBlk); - } else { - pHeaderBufPtr = &pTxBlk->HeaderBuf[0]; - padding = - ROUND_UP(LENGTH_AMSDU_SUBFRAMEHEAD + - subFramePayloadLen, - 4) - (LENGTH_AMSDU_SUBFRAMEHEAD + - subFramePayloadLen); - NdisZeroMemory(pHeaderBufPtr, - padding + LENGTH_AMSDU_SUBFRAMEHEAD); - pHeaderBufPtr += padding; - pTxBlk->MpduHeaderLen = padding; - } - - /* */ - /* A-MSDU subframe */ - /* DA(6)+SA(6)+Length(2) + LLC/SNAP Encap */ - /* */ - subFrameHeader = pHeaderBufPtr; - subFramePayloadLen = pTxBlk->SrcBufLen; - - NdisMoveMemory(subFrameHeader, pTxBlk->pSrcBufHeader, 12); - - pHeaderBufPtr += LENGTH_AMSDU_SUBFRAMEHEAD; - pTxBlk->MpduHeaderLen += LENGTH_AMSDU_SUBFRAMEHEAD; - - /* */ - /* Insert LLC-SNAP encapsulation - 8 octets */ - /* */ - EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk->pSrcBufData - 2, - pTxBlk->pExtraLlcSnapEncap); - - subFramePayloadLen = pTxBlk->SrcBufLen; - - if (pTxBlk->pExtraLlcSnapEncap) { - NdisMoveMemory(pHeaderBufPtr, - pTxBlk->pExtraLlcSnapEncap, 6); - pHeaderBufPtr += 6; - /* get 2 octets (TypeofLen) */ - NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData - 2, - 2); - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += LENGTH_802_1_H; - subFramePayloadLen += LENGTH_802_1_H; - } - /* update subFrame Length field */ - subFrameHeader[12] = (subFramePayloadLen & 0xFF00) >> 8; - subFrameHeader[13] = subFramePayloadLen & 0xFF; - - totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen; - - if (frameNum == 0) - FirstTx = - HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, - &FreeNumber); - else - LastTxIdx = - HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, - &FreeNumber); - - frameNum++; - - pAd->RalinkCounters.KickTxCount++; - pAd->RalinkCounters.OneSecTxDoneCount++; - - /* calculate Transmitted AMSDU Count and ByteCount */ - { - pAd->RalinkCounters.TransmittedAMSDUCount.u.LowPart++; - pAd->RalinkCounters.TransmittedOctetsInAMSDU.QuadPart += - totalMPDUSize; - } - - } - - HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx); - HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx); - - /* */ - /* Kick out Tx */ - /* */ - if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX)) - HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx); -} - -void STA_Legacy_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk) -{ - struct rt_header_802_11 *pHeader_802_11; - u8 *pHeaderBufPtr; - u16 FreeNumber; - BOOLEAN bVLANPkt; - struct rt_queue_entry *pQEntry; - - ASSERT(pTxBlk); - - pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); - pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); - if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) { - RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE); - return; - } - - if (pTxBlk->TxFrameType == TX_MCAST_FRAME) { - INC_COUNTER64(pAd->WlanCounters.MulticastTransmittedFrameCount); - } - - if (RTMP_GET_PACKET_RTS(pTxBlk->pPacket)) - TX_BLK_SET_FLAG(pTxBlk, fTX_bRtsRequired); - else - TX_BLK_CLEAR_FLAG(pTxBlk, fTX_bRtsRequired); - - bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE); - - if (pTxBlk->TxRate < pAd->CommonCfg.MinTxRate) - pTxBlk->TxRate = pAd->CommonCfg.MinTxRate; - - STAFindCipherAlgorithm(pAd, pTxBlk); - STABuildCommon802_11Header(pAd, pTxBlk); - - /* skip 802.3 header */ - pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3; - pTxBlk->SrcBufLen -= LENGTH_802_3; - - /* skip vlan tag */ - if (bVLANPkt) { - pTxBlk->pSrcBufData += LENGTH_802_1Q; - pTxBlk->SrcBufLen -= LENGTH_802_1Q; - } - - pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; - pHeader_802_11 = (struct rt_header_802_11 *) pHeaderBufPtr; - - /* skip common header */ - pHeaderBufPtr += pTxBlk->MpduHeaderLen; - - if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) { - /* */ - /* build QOS Control bytes */ - /* */ - *(pHeaderBufPtr) = - ((pTxBlk->UserPriority & 0x0F) | (pAd->CommonCfg. - AckPolicy[pTxBlk-> - QueIdx] << 5)); - *(pHeaderBufPtr + 1) = 0; - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += 2; - } - /* The remaining content of MPDU header should locate at 4-octets alignment */ - pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr; - pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4); - pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen); - - { - - /* */ - /* Insert LLC-SNAP encapsulation - 8 octets */ - /* */ - /* */ - /* if original Ethernet frame contains no LLC/SNAP, */ - /* then an extra LLC/SNAP encap is required */ - /* */ - EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, - pTxBlk->pExtraLlcSnapEncap); - if (pTxBlk->pExtraLlcSnapEncap) { - u8 vlan_size; - - NdisMoveMemory(pHeaderBufPtr, - pTxBlk->pExtraLlcSnapEncap, 6); - pHeaderBufPtr += 6; - /* skip vlan tag */ - vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0; - /* get 2 octets (TypeofLen) */ - NdisMoveMemory(pHeaderBufPtr, - pTxBlk->pSrcBufHeader + 12 + vlan_size, - 2); - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += LENGTH_802_1_H; - } - - } - - /* */ - /* prepare for TXWI */ - /* use Wcid as Key Index */ - /* */ - - RTMPWriteTxWI_Data(pAd, (struct rt_txwi *) (&pTxBlk->HeaderBuf[TXINFO_SIZE]), - pTxBlk); - - /*FreeNumber = GET_TXRING_FREENO(pAd, QueIdx); */ - - HAL_WriteTxResource(pAd, pTxBlk, TRUE, &FreeNumber); - - pAd->RalinkCounters.KickTxCount++; - pAd->RalinkCounters.OneSecTxDoneCount++; - - /* */ - /* Kick out Tx */ - /* */ - if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX)) - HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx); -} - -void STA_ARalink_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk) -{ - u8 *pHeaderBufPtr; - u16 FreeNumber; - u16 totalMPDUSize = 0; - u16 FirstTx, LastTxIdx; - int frameNum = 0; - BOOLEAN bVLANPkt; - struct rt_queue_entry *pQEntry; - - ASSERT(pTxBlk); - - ASSERT((pTxBlk->TxPacketList.Number == 2)); - - FirstTx = LastTxIdx = 0; /* Is it ok init they as 0? */ - while (pTxBlk->TxPacketList.Head) { - pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); - pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); - - if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) { - RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, - NDIS_STATUS_FAILURE); - continue; - } - - bVLANPkt = - (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE); - - /* skip 802.3 header */ - pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3; - pTxBlk->SrcBufLen -= LENGTH_802_3; - - /* skip vlan tag */ - if (bVLANPkt) { - pTxBlk->pSrcBufData += LENGTH_802_1Q; - pTxBlk->SrcBufLen -= LENGTH_802_1Q; - } - - if (frameNum == 0) { /* For first frame, we need to create the 802.11 header + padding(optional) + RA-AGG-LEN + SNAP Header */ - - pHeaderBufPtr = - STA_Build_ARalink_Frame_Header(pAd, pTxBlk); - - /* It's ok write the TxWI here, because the TxWI->MPDUtotalByteCount */ - /* will be updated after final frame was handled. */ - RTMPWriteTxWI_Data(pAd, - (struct rt_txwi *) (&pTxBlk-> - HeaderBuf - [TXINFO_SIZE]), - pTxBlk); - - /* */ - /* Insert LLC-SNAP encapsulation - 8 octets */ - /* */ - EXTRA_LLCSNAP_ENCAP_FROM_PKT_OFFSET(pTxBlk-> - pSrcBufData - 2, - pTxBlk-> - pExtraLlcSnapEncap); - - if (pTxBlk->pExtraLlcSnapEncap) { - NdisMoveMemory(pHeaderBufPtr, - pTxBlk->pExtraLlcSnapEncap, 6); - pHeaderBufPtr += 6; - /* get 2 octets (TypeofLen) */ - NdisMoveMemory(pHeaderBufPtr, - pTxBlk->pSrcBufData - 2, 2); - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += LENGTH_802_1_H; - } - } else { /* For second aggregated frame, we need create the 802.3 header to headerBuf, because PCI will copy it to SDPtr0. */ - - pHeaderBufPtr = &pTxBlk->HeaderBuf[0]; - pTxBlk->MpduHeaderLen = 0; - - /* A-Ralink sub-sequent frame header is the same as 802.3 header. */ - /* DA(6)+SA(6)+FrameType(2) */ - NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufHeader, - 12); - pHeaderBufPtr += 12; - /* get 2 octets (TypeofLen) */ - NdisMoveMemory(pHeaderBufPtr, pTxBlk->pSrcBufData - 2, - 2); - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen = LENGTH_ARALINK_SUBFRAMEHEAD; - } - - totalMPDUSize += pTxBlk->MpduHeaderLen + pTxBlk->SrcBufLen; - - /*FreeNumber = GET_TXRING_FREENO(pAd, QueIdx); */ - if (frameNum == 0) - FirstTx = - HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, - &FreeNumber); - else - LastTxIdx = - HAL_WriteMultiTxResource(pAd, pTxBlk, frameNum, - &FreeNumber); - - frameNum++; - - pAd->RalinkCounters.OneSecTxAggregationCount++; - pAd->RalinkCounters.KickTxCount++; - pAd->RalinkCounters.OneSecTxDoneCount++; - - } - - HAL_FinalWriteTxResource(pAd, pTxBlk, totalMPDUSize, FirstTx); - HAL_LastTxIdx(pAd, pTxBlk->QueIdx, LastTxIdx); - - /* */ - /* Kick out Tx */ - /* */ - if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX)) - HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx); - -} - -void STA_Fragment_Frame_Tx(struct rt_rtmp_adapter *pAd, struct rt_tx_blk *pTxBlk) -{ - struct rt_header_802_11 *pHeader_802_11; - u8 *pHeaderBufPtr; - u16 FreeNumber; - u8 fragNum = 0; - struct rt_packet_info PacketInfo; - u16 EncryptionOverhead = 0; - u32 FreeMpduSize, SrcRemainingBytes; - u16 AckDuration; - u32 NextMpduSize; - BOOLEAN bVLANPkt; - struct rt_queue_entry *pQEntry; - HTTRANSMIT_SETTING *pTransmit; - - ASSERT(pTxBlk); - - pQEntry = RemoveHeadQueue(&pTxBlk->TxPacketList); - pTxBlk->pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); - if (RTMP_FillTxBlkInfo(pAd, pTxBlk) != TRUE) { - RELEASE_NDIS_PACKET(pAd, pTxBlk->pPacket, NDIS_STATUS_FAILURE); - return; - } - - ASSERT(TX_BLK_TEST_FLAG(pTxBlk, fTX_bAllowFrag)); - bVLANPkt = (RTMP_GET_PACKET_VLAN(pTxBlk->pPacket) ? TRUE : FALSE); - - STAFindCipherAlgorithm(pAd, pTxBlk); - STABuildCommon802_11Header(pAd, pTxBlk); - - if (pTxBlk->CipherAlg == CIPHER_TKIP) { - pTxBlk->pPacket = - duplicate_pkt_with_TKIP_MIC(pAd, pTxBlk->pPacket); - if (pTxBlk->pPacket == NULL) - return; - RTMP_QueryPacketInfo(pTxBlk->pPacket, &PacketInfo, - &pTxBlk->pSrcBufHeader, - &pTxBlk->SrcBufLen); - } - /* skip 802.3 header */ - pTxBlk->pSrcBufData = pTxBlk->pSrcBufHeader + LENGTH_802_3; - pTxBlk->SrcBufLen -= LENGTH_802_3; - - /* skip vlan tag */ - if (bVLANPkt) { - pTxBlk->pSrcBufData += LENGTH_802_1Q; - pTxBlk->SrcBufLen -= LENGTH_802_1Q; - } - - pHeaderBufPtr = &pTxBlk->HeaderBuf[TXINFO_SIZE + TXWI_SIZE]; - pHeader_802_11 = (struct rt_header_802_11 *) pHeaderBufPtr; - - /* skip common header */ - pHeaderBufPtr += pTxBlk->MpduHeaderLen; - - if (TX_BLK_TEST_FLAG(pTxBlk, fTX_bWMM)) { - /* */ - /* build QOS Control bytes */ - /* */ - *pHeaderBufPtr = (pTxBlk->UserPriority & 0x0F); - - *(pHeaderBufPtr + 1) = 0; - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += 2; - } - /* */ - /* padding at front of LLC header */ - /* LLC header should locate at 4-octets aligment */ - /* */ - pTxBlk->HdrPadLen = (unsigned long)pHeaderBufPtr; - pHeaderBufPtr = (u8 *)ROUND_UP(pHeaderBufPtr, 4); - pTxBlk->HdrPadLen = (unsigned long)(pHeaderBufPtr - pTxBlk->HdrPadLen); - - /* */ - /* Insert LLC-SNAP encapsulation - 8 octets */ - /* */ - /* */ - /* if original Ethernet frame contains no LLC/SNAP, */ - /* then an extra LLC/SNAP encap is required */ - /* */ - EXTRA_LLCSNAP_ENCAP_FROM_PKT_START(pTxBlk->pSrcBufHeader, - pTxBlk->pExtraLlcSnapEncap); - if (pTxBlk->pExtraLlcSnapEncap) { - u8 vlan_size; - - NdisMoveMemory(pHeaderBufPtr, pTxBlk->pExtraLlcSnapEncap, 6); - pHeaderBufPtr += 6; - /* skip vlan tag */ - vlan_size = (bVLANPkt) ? LENGTH_802_1Q : 0; - /* get 2 octets (TypeofLen) */ - NdisMoveMemory(pHeaderBufPtr, - pTxBlk->pSrcBufHeader + 12 + vlan_size, 2); - pHeaderBufPtr += 2; - pTxBlk->MpduHeaderLen += LENGTH_802_1_H; - } - - /* If TKIP is used and fragmentation is required. Driver has to */ - /* append TKIP MIC at tail of the scatter buffer */ - /* MAC ASIC will only perform IV/EIV/ICV insertion but no TKIP MIC */ - if (pTxBlk->CipherAlg == CIPHER_TKIP) { - RTMPCalculateMICValue(pAd, pTxBlk->pPacket, - pTxBlk->pExtraLlcSnapEncap, pTxBlk->pKey, - 0); - - /* NOTE: DON'T refer the skb->len directly after following copy. Because the length is not adjusted */ - /* to correct length, refer to pTxBlk->SrcBufLen for the packet length in following progress. */ - NdisMoveMemory(pTxBlk->pSrcBufData + pTxBlk->SrcBufLen, - &pAd->PrivateInfo.Tx.MIC[0], 8); - /*skb_put((RTPKT_TO_OSPKT(pTxBlk->pPacket))->tail, 8); */ - pTxBlk->SrcBufLen += 8; - pTxBlk->TotalFrameLen += 8; - pTxBlk->CipherAlg = CIPHER_TKIP_NO_MIC; - } - /* */ - /* calculate the overhead bytes that encryption algorithm may add. This */ - /* affects the calculate of "duration" field */ - /* */ - if ((pTxBlk->CipherAlg == CIPHER_WEP64) - || (pTxBlk->CipherAlg == CIPHER_WEP128)) - EncryptionOverhead = 8; /*WEP: IV[4] + ICV[4]; */ - else if (pTxBlk->CipherAlg == CIPHER_TKIP_NO_MIC) - EncryptionOverhead = 12; /*TKIP: IV[4] + EIV[4] + ICV[4], MIC will be added to TotalPacketLength */ - else if (pTxBlk->CipherAlg == CIPHER_TKIP) - EncryptionOverhead = 20; /*TKIP: IV[4] + EIV[4] + ICV[4] + MIC[8] */ - else if (pTxBlk->CipherAlg == CIPHER_AES) - EncryptionOverhead = 16; /* AES: IV[4] + EIV[4] + MIC[8] */ - else - EncryptionOverhead = 0; - - pTransmit = pTxBlk->pTransmit; - /* Decide the TX rate */ - if (pTransmit->field.MODE == MODE_CCK) - pTxBlk->TxRate = pTransmit->field.MCS; - else if (pTransmit->field.MODE == MODE_OFDM) - pTxBlk->TxRate = pTransmit->field.MCS + RATE_FIRST_OFDM_RATE; - else - pTxBlk->TxRate = RATE_6_5; - - /* decide how much time an ACK/CTS frame will consume in the air */ - if (pTxBlk->TxRate <= RATE_LAST_OFDM_RATE) - AckDuration = - RTMPCalcDuration(pAd, - pAd->CommonCfg.ExpectedACKRate[pTxBlk-> - TxRate], - 14); - else - AckDuration = RTMPCalcDuration(pAd, RATE_6_5, 14); - - /* Init the total payload length of this frame. */ - SrcRemainingBytes = pTxBlk->SrcBufLen; - - pTxBlk->TotalFragNum = 0xff; - - do { - - FreeMpduSize = pAd->CommonCfg.FragmentThreshold - LENGTH_CRC; - - FreeMpduSize -= pTxBlk->MpduHeaderLen; - - if (SrcRemainingBytes <= FreeMpduSize) { /* this is the last or only fragment */ - - pTxBlk->SrcBufLen = SrcRemainingBytes; - - pHeader_802_11->FC.MoreFrag = 0; - pHeader_802_11->Duration = - pAd->CommonCfg.Dsifs + AckDuration; - - /* Indicate the lower layer that this's the last fragment. */ - pTxBlk->TotalFragNum = fragNum; - } else { /* more fragment is required */ - - pTxBlk->SrcBufLen = FreeMpduSize; - - NextMpduSize = - min(((u32)SrcRemainingBytes - pTxBlk->SrcBufLen), - ((u32)pAd->CommonCfg.FragmentThreshold)); - pHeader_802_11->FC.MoreFrag = 1; - pHeader_802_11->Duration = - (3 * pAd->CommonCfg.Dsifs) + (2 * AckDuration) + - RTMPCalcDuration(pAd, pTxBlk->TxRate, - NextMpduSize + EncryptionOverhead); - } - - if (fragNum == 0) - pTxBlk->FrameGap = IFS_HTTXOP; - else - pTxBlk->FrameGap = IFS_SIFS; - - RTMPWriteTxWI_Data(pAd, - (struct rt_txwi *) (&pTxBlk-> - HeaderBuf[TXINFO_SIZE]), - pTxBlk); - - HAL_WriteFragTxResource(pAd, pTxBlk, fragNum, &FreeNumber); - - pAd->RalinkCounters.KickTxCount++; - pAd->RalinkCounters.OneSecTxDoneCount++; - - /* Update the frame number, remaining size of the NDIS packet payload. */ - - /* space for 802.11 header. */ - if (fragNum == 0 && pTxBlk->pExtraLlcSnapEncap) - pTxBlk->MpduHeaderLen -= LENGTH_802_1_H; - - fragNum++; - SrcRemainingBytes -= pTxBlk->SrcBufLen; - pTxBlk->pSrcBufData += pTxBlk->SrcBufLen; - - pHeader_802_11->Frag++; /* increase Frag # */ - - } while (SrcRemainingBytes > 0); - - /* */ - /* Kick out Tx */ - /* */ - if (!RTMP_TEST_PSFLAG(pAd, fRTMP_PS_DISABLE_TX)) - HAL_KickOutTx(pAd, pTxBlk, pTxBlk->QueIdx); -} - -#define RELEASE_FRAMES_OF_TXBLK(_pAd, _pTxBlk, _pQEntry, _Status) \ - while(_pTxBlk->TxPacketList.Head) \ - { \ - _pQEntry = RemoveHeadQueue(&_pTxBlk->TxPacketList); \ - RELEASE_NDIS_PACKET(_pAd, QUEUE_ENTRY_TO_PACKET(_pQEntry), _Status); \ - } - -/* - ======================================================================== - - Routine Description: - Copy frame from waiting queue into relative ring buffer and set - appropriate ASIC register to kick hardware encryption before really - sent out to air. - - Arguments: - pAd Pointer to our adapter - void * Pointer to outgoing Ndis frame - NumberOfFrag Number of fragment required - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -int STAHardTransmit(struct rt_rtmp_adapter *pAd, - struct rt_tx_blk *pTxBlk, u8 QueIdx) -{ - char *pPacket; - struct rt_queue_entry *pQEntry; - - /* --------------------------------------------- */ - /* STEP 0. DO SANITY CHECK AND SOME EARLY PREPARATION. */ - /* --------------------------------------------- */ - /* */ - ASSERT(pTxBlk->TxPacketList.Number); - if (pTxBlk->TxPacketList.Head == NULL) { - DBGPRINT(RT_DEBUG_ERROR, - ("pTxBlk->TotalFrameNum == %ld!\n", - pTxBlk->TxPacketList.Number)); - return NDIS_STATUS_FAILURE; - } - - pPacket = QUEUE_ENTRY_TO_PACKET(pTxBlk->TxPacketList.Head); - - /* ------------------------------------------------------------------ */ - /* STEP 1. WAKE UP PHY */ - /* outgoing frame always wakeup PHY to prevent frame lost and */ - /* turn off PSM bit to improve performance */ - /* ------------------------------------------------------------------ */ - /* not to change PSM bit, just send this frame out? */ - if ((pAd->StaCfg.Psm == PWR_SAVE) - && OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_DOZE)) { - DBGPRINT_RAW(RT_DEBUG_INFO, ("AsicForceWakeup At HardTx\n")); -#ifdef RTMP_MAC_PCI - AsicForceWakeup(pAd, TRUE); -#endif /* RTMP_MAC_PCI // */ -#ifdef RTMP_MAC_USB - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_FORCE_WAKE_UP, NULL, 0); -#endif /* RTMP_MAC_USB // */ - } - /* It should not change PSM bit, when APSD turn on. */ - if ((! - (pAd->CommonCfg.bAPSDCapable - && pAd->CommonCfg.APEdcaParm.bAPSDCapable) - && (pAd->CommonCfg.bAPSDForcePowerSave == FALSE)) - || (RTMP_GET_PACKET_EAPOL(pTxBlk->pPacket)) - || (RTMP_GET_PACKET_WAI(pTxBlk->pPacket))) { - if ((pAd->StaCfg.Psm == PWR_SAVE) && - (pAd->StaCfg.WindowsPowerMode == - Ndis802_11PowerModeFast_PSP)) - RTMP_SET_PSM_BIT(pAd, PWR_ACTIVE); - } - - switch (pTxBlk->TxFrameType) { - case TX_AMPDU_FRAME: - STA_AMPDU_Frame_Tx(pAd, pTxBlk); - break; - case TX_AMSDU_FRAME: - STA_AMSDU_Frame_Tx(pAd, pTxBlk); - break; - case TX_LEGACY_FRAME: - STA_Legacy_Frame_Tx(pAd, pTxBlk); - break; - case TX_MCAST_FRAME: - STA_Legacy_Frame_Tx(pAd, pTxBlk); - break; - case TX_RALINK_FRAME: - STA_ARalink_Frame_Tx(pAd, pTxBlk); - break; - case TX_FRAG_FRAME: - STA_Fragment_Frame_Tx(pAd, pTxBlk); - break; - default: - { - /* It should not happened! */ - DBGPRINT(RT_DEBUG_ERROR, - ("Send a packet was not classified! It should not happen!\n")); - while (pTxBlk->TxPacketList.Number) { - pQEntry = - RemoveHeadQueue(&pTxBlk->TxPacketList); - pPacket = QUEUE_ENTRY_TO_PACKET(pQEntry); - if (pPacket) - RELEASE_NDIS_PACKET(pAd, pPacket, - NDIS_STATUS_FAILURE); - } - } - break; - } - - return (NDIS_STATUS_SUCCESS); - -} - -unsigned long HashBytesPolynomial(u8 * value, unsigned int len) -{ - unsigned char *word = value; - unsigned int ret = 0; - unsigned int i; - - for (i = 0; i < len; i++) { - int mod = i % 32; - ret ^= (unsigned int)(word[i]) << mod; - ret ^= (unsigned int)(word[i]) >> (32 - mod); - } - return ret; -} - -void Sta_Announce_or_Forward_802_3_Packet(struct rt_rtmp_adapter *pAd, - void *pPacket, - u8 FromWhichBSSID) -{ - if (TRUE) { - announce_802_3_packet(pAd, pPacket); - } else { - /* release packet */ - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - } -} diff --git a/trunk/drivers/staging/rt2860/sta/sanity.c b/trunk/drivers/staging/rt2860/sta/sanity.c deleted file mode 100644 index 0c32604f2d3f..000000000000 --- a/trunk/drivers/staging/rt2860/sta/sanity.c +++ /dev/null @@ -1,362 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - sanity.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - John Chang 2004-09-01 add WMM support - Justin P. Mattock 11/07/2010 Fix typos -*/ -#include "../rt_config.h" - -extern u8 CISCO_OUI[]; - -extern u8 WPA_OUI[]; -extern u8 RSN_OUI[]; -extern u8 WME_INFO_ELEM[]; -extern u8 WME_PARM_ELEM[]; -extern u8 Ccx2QosInfo[]; -extern u8 RALINK_OUI[]; -extern u8 BROADCOM_OUI[]; - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - ========================================================================== - */ -BOOLEAN MlmeStartReqSanity(struct rt_rtmp_adapter *pAd, - void * Msg, - unsigned long MsgLen, - char Ssid[], u8 * pSsidLen) -{ - struct rt_mlme_start_req *Info; - - Info = (struct rt_mlme_start_req *)(Msg); - - if (Info->SsidLen > MAX_LEN_OF_SSID) { - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeStartReqSanity fail - wrong SSID length\n")); - return FALSE; - } - - *pSsidLen = Info->SsidLen; - NdisMoveMemory(Ssid, Info->Ssid, *pSsidLen); - - return TRUE; -} - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -BOOLEAN PeerAssocRspSanity(struct rt_rtmp_adapter *pAd, void * pMsg, unsigned long MsgLen, u8 *pAddr2, u16 * pCapabilityInfo, u16 * pStatus, u16 * pAid, u8 SupRate[], u8 * pSupRateLen, u8 ExtRate[], u8 * pExtRateLen, struct rt_ht_capability_ie * pHtCapability, struct rt_add_ht_info_ie * pAddHtInfo, /* AP might use this additional ht info IE */ - u8 * pHtCapabilityLen, - u8 * pAddHtInfoLen, - u8 * pNewExtChannelOffset, - struct rt_edca_parm *pEdcaParm, u8 * pCkipFlag) -{ - char IeType, *Ptr; - struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) pMsg; - struct rt_eid * pEid; - unsigned long Length = 0; - - *pNewExtChannelOffset = 0xff; - *pHtCapabilityLen = 0; - *pAddHtInfoLen = 0; - COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); - Ptr = (char *)pFrame->Octet; - Length += LENGTH_802_11; - - NdisMoveMemory(pCapabilityInfo, &pFrame->Octet[0], 2); - Length += 2; - NdisMoveMemory(pStatus, &pFrame->Octet[2], 2); - Length += 2; - *pCkipFlag = 0; - *pExtRateLen = 0; - pEdcaParm->bValid = FALSE; - - if (*pStatus != MLME_SUCCESS) - return TRUE; - - NdisMoveMemory(pAid, &pFrame->Octet[4], 2); - Length += 2; - - /* Aid already swapped byte order in RTMPFrameEndianChange() for big endian platform */ - *pAid = (*pAid) & 0x3fff; /* AID is low 14-bit */ - - /* -- get supported rates from payload and advance the pointer */ - IeType = pFrame->Octet[6]; - *pSupRateLen = pFrame->Octet[7]; - if ((IeType != IE_SUPP_RATES) - || (*pSupRateLen > MAX_LEN_OF_SUPPORTED_RATES)) { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerAssocRspSanity fail - wrong SupportedRates IE\n")); - return FALSE; - } else - NdisMoveMemory(SupRate, &pFrame->Octet[8], *pSupRateLen); - - Length = Length + 2 + *pSupRateLen; - - /* many AP implement proprietary IEs in non-standard order, we'd better */ - /* tolerate mis-ordered IEs to get best compatibility */ - pEid = (struct rt_eid *) & pFrame->Octet[8 + (*pSupRateLen)]; - - /* get variable fields from payload and advance the pointer */ - while ((Length + 2 + pEid->Len) <= MsgLen) { - switch (pEid->Eid) { - case IE_EXT_SUPP_RATES: - if (pEid->Len <= MAX_LEN_OF_SUPPORTED_RATES) { - NdisMoveMemory(ExtRate, pEid->Octet, pEid->Len); - *pExtRateLen = pEid->Len; - } - break; - - case IE_HT_CAP: - case IE_HT_CAP2: - if (pEid->Len >= SIZE_HT_CAP_IE) /*Note: allow extension! */ - { - NdisMoveMemory(pHtCapability, pEid->Octet, - SIZE_HT_CAP_IE); - - *(u16 *) (&pHtCapability->HtCapInfo) = - cpu2le16(*(u16 *) - (&pHtCapability->HtCapInfo)); - *(u16 *) (&pHtCapability->ExtHtCapInfo) = - cpu2le16(*(u16 *) - (&pHtCapability->ExtHtCapInfo)); - - *pHtCapabilityLen = SIZE_HT_CAP_IE; - } else { - DBGPRINT(RT_DEBUG_WARN, - ("PeerAssocRspSanity - wrong IE_HT_CAP. \n")); - } - - break; - case IE_ADD_HT: - case IE_ADD_HT2: - if (pEid->Len >= sizeof(struct rt_add_ht_info_ie)) { - /* This IE allows extension, but we can ignore extra bytes beyond our knowledge , so only */ - /* copy first sizeof(struct rt_add_ht_info_ie) */ - NdisMoveMemory(pAddHtInfo, pEid->Octet, - sizeof(struct rt_add_ht_info_ie)); - - *(u16 *) (&pAddHtInfo->AddHtInfo2) = - cpu2le16(*(u16 *) - (&pAddHtInfo->AddHtInfo2)); - *(u16 *) (&pAddHtInfo->AddHtInfo3) = - cpu2le16(*(u16 *) - (&pAddHtInfo->AddHtInfo3)); - - *pAddHtInfoLen = SIZE_ADD_HT_INFO_IE; - } else { - DBGPRINT(RT_DEBUG_WARN, - ("PeerAssocRspSanity - wrong IE_ADD_HT. \n")); - } - - break; - case IE_SECONDARY_CH_OFFSET: - if (pEid->Len == 1) { - *pNewExtChannelOffset = pEid->Octet[0]; - } else { - DBGPRINT(RT_DEBUG_WARN, - ("PeerAssocRspSanity - wrong IE_SECONDARY_CH_OFFSET. \n")); - } - break; - - case IE_VENDOR_SPECIFIC: - /* handle WME PARAMTER ELEMENT */ - if (NdisEqualMemory(pEid->Octet, WME_PARM_ELEM, 6) - && (pEid->Len == 24)) { - u8 *ptr; - int i; - - /* parsing EDCA parameters */ - pEdcaParm->bValid = TRUE; - pEdcaParm->bQAck = FALSE; /* pEid->Octet[0] & 0x10; */ - pEdcaParm->bQueueRequest = FALSE; /* pEid->Octet[0] & 0x20; */ - pEdcaParm->bTxopRequest = FALSE; /* pEid->Octet[0] & 0x40; */ - /*pEdcaParm->bMoreDataAck = FALSE; // pEid->Octet[0] & 0x80; */ - pEdcaParm->EdcaUpdateCount = - pEid->Octet[6] & 0x0f; - pEdcaParm->bAPSDCapable = - (pEid->Octet[6] & 0x80) ? 1 : 0; - ptr = (u8 *)& pEid->Octet[8]; - for (i = 0; i < 4; i++) { - u8 aci = (*ptr & 0x60) >> 5; /* b5~6 is AC INDEX */ - pEdcaParm->bACM[aci] = (((*ptr) & 0x10) == 0x10); /* b5 is ACM */ - pEdcaParm->Aifsn[aci] = (*ptr) & 0x0f; /* b0~3 is AIFSN */ - pEdcaParm->Cwmin[aci] = *(ptr + 1) & 0x0f; /* b0~4 is Cwmin */ - pEdcaParm->Cwmax[aci] = *(ptr + 1) >> 4; /* b5~8 is Cwmax */ - pEdcaParm->Txop[aci] = *(ptr + 2) + 256 * (*(ptr + 3)); /* in unit of 32-us */ - ptr += 4; /* point to next AC */ - } - } - break; - default: - DBGPRINT(RT_DEBUG_TRACE, - ("PeerAssocRspSanity - ignore unrecognized EID = %d\n", - pEid->Eid)); - break; - } - - Length = Length + 2 + pEid->Len; - pEid = (struct rt_eid *) ((u8 *) pEid + 2 + pEid->Len); - } - - return TRUE; -} - -/* - ========================================================================== - Description: - MLME message sanity check - Return: - TRUE if all parameters are OK, FALSE otherwise - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -BOOLEAN PeerProbeReqSanity(struct rt_rtmp_adapter *pAd, - void * Msg, - unsigned long MsgLen, - u8 *pAddr2, - char Ssid[], u8 * pSsidLen) -{ - u8 Idx; - u8 RateLen; - char IeType; - struct rt_frame_802_11 * pFrame = (struct rt_frame_802_11 *) Msg; - - COPY_MAC_ADDR(pAddr2, pFrame->Hdr.Addr2); - - if ((pFrame->Octet[0] != IE_SSID) - || (pFrame->Octet[1] > MAX_LEN_OF_SSID)) { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerProbeReqSanity fail - wrong SSID IE(Type=%d,Len=%d)\n", - pFrame->Octet[0], pFrame->Octet[1])); - return FALSE; - } - - *pSsidLen = pFrame->Octet[1]; - NdisMoveMemory(Ssid, &pFrame->Octet[2], *pSsidLen); - - Idx = *pSsidLen + 2; - - /* -- get supported rates from payload and advance the pointer */ - IeType = pFrame->Octet[Idx]; - RateLen = pFrame->Octet[Idx + 1]; - if (IeType != IE_SUPP_RATES) { - DBGPRINT(RT_DEBUG_TRACE, - ("PeerProbeReqSanity fail - wrong SupportRates IE(Type=%d,Len=%d)\n", - pFrame->Octet[Idx], pFrame->Octet[Idx + 1])); - return FALSE; - } else { - if ((pAd->CommonCfg.PhyMode == PHY_11G) && (RateLen < 8)) - return (FALSE); - } - - return TRUE; -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -BOOLEAN GetTimBit(char * Ptr, - u16 Aid, - u8 * TimLen, - u8 * BcastFlag, - u8 * DtimCount, - u8 * DtimPeriod, u8 * MessageToMe) -{ - u8 BitCntl, N1, N2, MyByte, MyBit; - char *IdxPtr; - - IdxPtr = Ptr; - - IdxPtr++; - *TimLen = *IdxPtr; - - /* get DTIM Count from TIM element */ - IdxPtr++; - *DtimCount = *IdxPtr; - - /* get DTIM Period from TIM element */ - IdxPtr++; - *DtimPeriod = *IdxPtr; - - /* get Bitmap Control from TIM element */ - IdxPtr++; - BitCntl = *IdxPtr; - - if ((*DtimCount == 0) && (BitCntl & 0x01)) - *BcastFlag = TRUE; - else - *BcastFlag = FALSE; - - /* Parse Partial Virtual Bitmap from TIM element */ - N1 = BitCntl & 0xfe; /* N1 is the first bitmap byte# */ - N2 = *TimLen - 4 + N1; /* N2 is the last bitmap byte# */ - - if ((Aid < (N1 << 3)) || (Aid >= ((N2 + 1) << 3))) - *MessageToMe = FALSE; - else { - MyByte = (Aid >> 3) - N1; /* my byte position in the bitmap byte-stream */ - MyBit = Aid % 16 - ((MyByte & 0x01) ? 8 : 0); - - IdxPtr += (MyByte + 1); - - /*if (*IdxPtr) */ - /* DBGPRINT(RT_DEBUG_WARN, ("TIM bitmap = 0x%02x\n", *IdxPtr)); */ - - if (*IdxPtr & (0x01 << MyBit)) - *MessageToMe = TRUE; - else - *MessageToMe = FALSE; - } - - return TRUE; -} diff --git a/trunk/drivers/staging/rt2860/sta/sync.c b/trunk/drivers/staging/rt2860/sta/sync.c deleted file mode 100644 index 7054ba1323d0..000000000000 --- a/trunk/drivers/staging/rt2860/sta/sync.c +++ /dev/null @@ -1,1968 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - sync.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - John Chang 2004-09-01 modified for rt2561/2661 - Jan Lee 2006-08-01 modified for rt2860 for 802.11n - Justin P. Mattock 11/07/2010 Fix typos -*/ -#include "../rt_config.h" - -#define ADHOC_ENTRY_BEACON_LOST_TIME (2*OS_HZ) /* 2 sec */ - -/* - ========================================================================== - Description: - The sync state machine, - Parameters: - Sm - pointer to the state machine - Note: - the state machine looks like the following - - ========================================================================== - */ -void SyncStateMachineInit(struct rt_rtmp_adapter *pAd, - struct rt_state_machine *Sm, OUT STATE_MACHINE_FUNC Trans[]) -{ - StateMachineInit(Sm, Trans, MAX_SYNC_STATE, MAX_SYNC_MSG, - (STATE_MACHINE_FUNC) Drop, SYNC_IDLE, - SYNC_MACHINE_BASE); - - /* column 1 */ - StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_SCAN_REQ, - (STATE_MACHINE_FUNC) MlmeScanReqAction); - StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_JOIN_REQ, - (STATE_MACHINE_FUNC) MlmeJoinReqAction); - StateMachineSetAction(Sm, SYNC_IDLE, MT2_MLME_START_REQ, - (STATE_MACHINE_FUNC) MlmeStartReqAction); - StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_BEACON, - (STATE_MACHINE_FUNC) PeerBeacon); - StateMachineSetAction(Sm, SYNC_IDLE, MT2_PEER_PROBE_REQ, - (STATE_MACHINE_FUNC) PeerProbeReqAction); - - /*column 2 */ - StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_SCAN_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenScan); - StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_JOIN_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenJoin); - StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_MLME_START_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenStart); - StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_PEER_BEACON, - (STATE_MACHINE_FUNC) PeerBeaconAtJoinAction); - StateMachineSetAction(Sm, JOIN_WAIT_BEACON, MT2_BEACON_TIMEOUT, - (STATE_MACHINE_FUNC) BeaconTimeoutAtJoinAction); - - /* column 3 */ - StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_SCAN_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenScan); - StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_JOIN_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenJoin); - StateMachineSetAction(Sm, SCAN_LISTEN, MT2_MLME_START_REQ, - (STATE_MACHINE_FUNC) InvalidStateWhenStart); - StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_BEACON, - (STATE_MACHINE_FUNC) PeerBeaconAtScanAction); - StateMachineSetAction(Sm, SCAN_LISTEN, MT2_PEER_PROBE_RSP, - (STATE_MACHINE_FUNC) PeerBeaconAtScanAction); - StateMachineSetAction(Sm, SCAN_LISTEN, MT2_SCAN_TIMEOUT, - (STATE_MACHINE_FUNC) ScanTimeoutAction); - - /* timer init */ - RTMPInitTimer(pAd, &pAd->MlmeAux.BeaconTimer, - GET_TIMER_FUNCTION(BeaconTimeout), pAd, FALSE); - RTMPInitTimer(pAd, &pAd->MlmeAux.ScanTimer, - GET_TIMER_FUNCTION(ScanTimeout), pAd, FALSE); -} - -/* - ========================================================================== - Description: - Beacon timeout handler, executed in timer thread - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void BeaconTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - - DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BeaconTimeout\n")); - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) - return; - - if ((pAd->CommonCfg.BBPCurrentBW == BW_40) - ) { - u8 BBPValue = 0; - AsicSwitchChannel(pAd, pAd->CommonCfg.CentralChannel, FALSE); - AsicLockChannel(pAd, pAd->CommonCfg.CentralChannel); - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); - BBPValue &= (~0x18); - BBPValue |= 0x10; - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - End of SCAN, restore to 40MHz channel %d, Total BSS[%02d]\n", - pAd->CommonCfg.CentralChannel, pAd->ScanTab.BssNr)); - } - - MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_BEACON_TIMEOUT, 0, NULL); - RTMP_MLME_HANDLER(pAd); -} - -/* - ========================================================================== - Description: - Scan timeout handler, executed in timer thread - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void ScanTimeout(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - - /* Do nothing if the driver is starting halt state. */ - /* This might happen when timer already been fired before cancel timer with mlmehalt */ - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) - return; - - if (MlmeEnqueue(pAd, SYNC_STATE_MACHINE, MT2_SCAN_TIMEOUT, 0, NULL)) { - RTMP_MLME_HANDLER(pAd); - } else { - /* To prevent SyncMachine.CurrState is SCAN_LISTEN forever. */ - pAd->MlmeAux.Channel = 0; - ScanNextChannel(pAd); - if (pAd->CommonCfg.bWirelessEvent) { - RTMPSendWirelessEvent(pAd, - IW_SCAN_ENQUEUE_FAIL_EVENT_FLAG, - pAd->MacTab.Content[BSSID_WCID]. - Addr, BSS0, 0); - } - } -} - -/* - ========================================================================== - Description: - MLME SCAN req state machine procedure - ========================================================================== - */ -void MlmeScanReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Ssid[MAX_LEN_OF_SSID], SsidLen, ScanType, BssType, BBPValue = 0; - BOOLEAN TimerCancelled; - unsigned long Now; - u16 Status; - struct rt_header_802_11 * pHdr80211; - u8 *pOutBuffer = NULL; - int NStatus; - - /* Check the total scan tries for one single OID command */ - /* If this is the CCX 2.0 Case, skip that! */ - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_START_UP)) { - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - MlmeScanReqAction before Startup\n")); - return; - } - /* Increase the scan retry counters. */ - pAd->StaCfg.ScanCnt++; - -#ifdef RTMP_MAC_PCI - if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) && - (IDLE_ON(pAd)) && - (pAd->StaCfg.bRadio == TRUE) && - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))) { - if (pAd->StaCfg.PSControl.field.EnableNewPS == FALSE) { - AsicSendCommandToMcu(pAd, 0x31, PowerWakeCID, 0x00, - 0x02); - AsicCheckCommanOk(pAd, PowerWakeCID); - RTMP_CLEAR_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF); - DBGPRINT(RT_DEBUG_TRACE, - ("PSM - Issue Wake up command \n")); - } else { - RT28xxPciAsicRadioOn(pAd, GUI_IDLE_POWER_SAVE); - } - } -#endif /* RTMP_MAC_PCI // */ - - /* first check the parameter sanity */ - if (MlmeScanReqSanity(pAd, - Elem->Msg, - Elem->MsgLen, - &BssType, (char *)Ssid, &SsidLen, &ScanType)) { - - /* Check for channel load and noise hist request */ - /* Suspend MSDU only at scan request, not the last two mentioned */ - /* Suspend MSDU transmission here */ - RTMPSuspendMsduTransmission(pAd); - - /* */ - /* To prevent data loss. */ - /* Send a NULL data with turned PSM bit on to current associated AP before SCAN progress. */ - /* And should send a NULL data with turned PSM bit off to AP, when scan progress done */ - /* */ - if (OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) - && (INFRA_ON(pAd))) { - NStatus = MlmeAllocateMemory(pAd, (void *)& pOutBuffer); - if (NStatus == NDIS_STATUS_SUCCESS) { - pHdr80211 = (struct rt_header_802_11 *) pOutBuffer; - MgtMacHeaderInit(pAd, pHdr80211, - SUBTYPE_NULL_FUNC, 1, - pAd->CommonCfg.Bssid, - pAd->CommonCfg.Bssid); - pHdr80211->Duration = 0; - pHdr80211->FC.Type = BTYPE_DATA; - pHdr80211->FC.PwrMgmt = PWR_SAVE; - - /* Send using priority queue */ - MiniportMMRequest(pAd, 0, pOutBuffer, - sizeof(struct rt_header_802_11)); - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeScanReqAction -- Send PSM Data frame for off channel RM\n")); - MlmeFreeMemory(pAd, pOutBuffer); - RTMPusecDelay(5000); - } - } - - NdisGetSystemUpTime(&Now); - pAd->StaCfg.LastScanTime = Now; - /* reset all the timers */ - RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled); - RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled); - - /* record desired BSS parameters */ - pAd->MlmeAux.BssType = BssType; - pAd->MlmeAux.ScanType = ScanType; - pAd->MlmeAux.SsidLen = SsidLen; - NdisZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID); - NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen); - - /* start from the first channel */ - pAd->MlmeAux.Channel = FirstChannel(pAd); - - /* Let BBP register at 20MHz to do scan */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); - BBPValue &= (~0x18); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); - DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n")); - ScanNextChannel(pAd); - } else { - DBGPRINT_ERR("SYNC - MlmeScanReqAction() sanity check fail\n"); - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - Status = MLME_INVALID_FORMAT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, - &Status); - } -} - -/* - ========================================================================== - Description: - MLME JOIN req state machine procedure - ========================================================================== - */ -void MlmeJoinReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 BBPValue = 0; - struct rt_bss_entry *pBss; - BOOLEAN TimerCancelled; - struct rt_header_802_11 Hdr80211; - int NStatus; - unsigned long FrameLen = 0; - u8 *pOutBuffer = NULL; - u8 *pSupRate = NULL; - u8 SupRateLen; - u8 *pExtRate = NULL; - u8 ExtRateLen; - u8 ASupRate[] = { 0x8C, 0x12, 0x98, 0x24, 0xb0, 0x48, 0x60, 0x6C }; - u8 ASupRateLen = sizeof(ASupRate) / sizeof(u8); - struct rt_mlme_join_req *pInfo = (struct rt_mlme_join_req *)(Elem->Msg); - - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - MlmeJoinReqAction(BSS #%ld)\n", pInfo->BssIdx)); - -#ifdef RTMP_MAC_PCI - if ((OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_PCIE_DEVICE)) && - (IDLE_ON(pAd)) && - (pAd->StaCfg.bRadio == TRUE) && - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_IDLE_RADIO_OFF))) { - RT28xxPciAsicRadioOn(pAd, GUI_IDLE_POWER_SAVE); - } -#endif /* RTMP_MAC_PCI // */ - - /* reset all the timers */ - RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled); - RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled); - - pBss = &pAd->MlmeAux.SsidBssTab.BssEntry[pInfo->BssIdx]; - - /* record the desired SSID & BSSID we're waiting for */ - COPY_MAC_ADDR(pAd->MlmeAux.Bssid, pBss->Bssid); - - /* If AP's SSID is not hidden, it is OK for updating ssid to MlmeAux again. */ - if (pBss->Hidden == 0) { - RTMPZeroMemory(pAd->MlmeAux.Ssid, MAX_LEN_OF_SSID); - NdisMoveMemory(pAd->MlmeAux.Ssid, pBss->Ssid, pBss->SsidLen); - pAd->MlmeAux.SsidLen = pBss->SsidLen; - } - - pAd->MlmeAux.BssType = pBss->BssType; - pAd->MlmeAux.Channel = pBss->Channel; - pAd->MlmeAux.CentralChannel = pBss->CentralChannel; - - /* Let BBP register at 20MHz to do scan */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAd, BBP_R4, &BBPValue); - BBPValue &= (~0x18); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAd, BBP_R4, BBPValue); - - DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BBP R4 to 20MHz.l\n")); - - /* switch channel and waiting for beacon timer */ - AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE); - AsicLockChannel(pAd, pAd->MlmeAux.Channel); - RTMPSetTimer(&pAd->MlmeAux.BeaconTimer, JOIN_TIMEOUT); - - do { - if (((pAd->CommonCfg.bIEEE80211H == 1) && - (pAd->MlmeAux.Channel > 14) && - RadarChannelCheck(pAd, pAd->MlmeAux.Channel)) - ) { - /* */ - /* We can't send any Probe request frame to meet 802.11h. */ - /* */ - if (pBss->Hidden == 0) - break; - } - /* */ - /* send probe request */ - /* */ - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); - if (NStatus == NDIS_STATUS_SUCCESS) { - if (pAd->MlmeAux.Channel <= 14) { - pSupRate = pAd->CommonCfg.SupRate; - SupRateLen = pAd->CommonCfg.SupRateLen; - pExtRate = pAd->CommonCfg.ExtRate; - ExtRateLen = pAd->CommonCfg.ExtRateLen; - } else { - /* */ - /* Overwrite Support Rate, CCK rate are not allowed */ - /* */ - pSupRate = ASupRate; - SupRateLen = ASupRateLen; - ExtRateLen = 0; - } - - if (pAd->MlmeAux.BssType == BSS_INFRA) - MgtMacHeaderInit(pAd, &Hdr80211, - SUBTYPE_PROBE_REQ, 0, - pAd->MlmeAux.Bssid, - pAd->MlmeAux.Bssid); - else - MgtMacHeaderInit(pAd, &Hdr80211, - SUBTYPE_PROBE_REQ, 0, - BROADCAST_ADDR, - BROADCAST_ADDR); - - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_header_802_11), &Hdr80211, - 1, &SsidIe, - 1, &pAd->MlmeAux.SsidLen, - pAd->MlmeAux.SsidLen, - pAd->MlmeAux.Ssid, 1, &SupRateIe, 1, - &SupRateLen, SupRateLen, pSupRate, - END_OF_ARGS); - - if (ExtRateLen) { - unsigned long Tmp; - MakeOutgoingFrame(pOutBuffer + FrameLen, &Tmp, - 1, &ExtRateIe, - 1, &ExtRateLen, - ExtRateLen, pExtRate, - END_OF_ARGS); - FrameLen += Tmp; - } - - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - } - } while (FALSE); - - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - Switch to ch %d, Wait BEACON from %pM\n", - pBss->Channel, pBss->Bssid)); - - pAd->Mlme.SyncMachine.CurrState = JOIN_WAIT_BEACON; -} - -/* - ========================================================================== - Description: - MLME START Request state machine procedure, starting an IBSS - ========================================================================== - */ -void MlmeStartReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Ssid[MAX_LEN_OF_SSID], SsidLen; - BOOLEAN TimerCancelled; - - /* New for WPA security suites */ - u8 VarIE[MAX_VIE_LEN]; /* Total VIE length = MAX_VIE_LEN - -5 */ - struct rt_ndis_802_11_variable_ies *pVIE = NULL; - LARGE_INTEGER TimeStamp; - BOOLEAN Privacy; - u16 Status; - - /* Init Variable IE structure */ - pVIE = (struct rt_ndis_802_11_variable_ies *)VarIE; - pVIE->Length = 0; - TimeStamp.u.LowPart = 0; - TimeStamp.u.HighPart = 0; - - if (MlmeStartReqSanity - (pAd, Elem->Msg, Elem->MsgLen, (char *)Ssid, &SsidLen)) { - /* reset all the timers */ - RTMPCancelTimer(&pAd->MlmeAux.ScanTimer, &TimerCancelled); - RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, &TimerCancelled); - - /* */ - /* Start a new IBSS. All IBSS parameters are decided now.... */ - /* */ - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeStartReqAction - Start a new IBSS. All IBSS parameters are decided now.... \n")); - pAd->MlmeAux.BssType = BSS_ADHOC; - NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, SsidLen); - pAd->MlmeAux.SsidLen = SsidLen; - - /* generate a radom number as BSSID */ - MacAddrRandomBssid(pAd, pAd->MlmeAux.Bssid); - DBGPRINT(RT_DEBUG_TRACE, - ("MlmeStartReqAction - generate a radom number as BSSID \n")); - - Privacy = - (pAd->StaCfg.WepStatus == Ndis802_11Encryption1Enabled) - || (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) - || (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled); - pAd->MlmeAux.CapabilityInfo = - CAP_GENERATE(0, 1, Privacy, - (pAd->CommonCfg.TxPreamble == - Rt802_11PreambleShort), 1, 0); - pAd->MlmeAux.BeaconPeriod = pAd->CommonCfg.BeaconPeriod; - pAd->MlmeAux.AtimWin = pAd->StaCfg.AtimWin; - pAd->MlmeAux.Channel = pAd->CommonCfg.Channel; - - pAd->CommonCfg.CentralChannel = pAd->CommonCfg.Channel; - pAd->MlmeAux.CentralChannel = pAd->CommonCfg.CentralChannel; - - pAd->MlmeAux.SupRateLen = pAd->CommonCfg.SupRateLen; - NdisMoveMemory(pAd->MlmeAux.SupRate, pAd->CommonCfg.SupRate, - MAX_LEN_OF_SUPPORTED_RATES); - RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, - &pAd->MlmeAux.SupRateLen); - pAd->MlmeAux.ExtRateLen = pAd->CommonCfg.ExtRateLen; - NdisMoveMemory(pAd->MlmeAux.ExtRate, pAd->CommonCfg.ExtRate, - MAX_LEN_OF_SUPPORTED_RATES); - RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, - &pAd->MlmeAux.ExtRateLen); - - if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) { - RTMPUpdateHTIE(&pAd->CommonCfg.DesiredHtPhy, - &pAd->StaCfg.DesiredHtPhyInfo.MCSSet[0], - &pAd->MlmeAux.HtCapability, - &pAd->MlmeAux.AddHtInfo); - pAd->MlmeAux.HtCapabilityLen = sizeof(struct rt_ht_capability_ie); - /* Not turn pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE here. */ - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC -pAd->StaActive.SupportedHtPhy.bHtEnable = TRUE\n")); - } else { - pAd->MlmeAux.HtCapabilityLen = 0; - pAd->StaActive.SupportedPhyInfo.bHtEnable = FALSE; - NdisZeroMemory(&pAd->StaActive.SupportedPhyInfo. - MCSSet[0], 16); - } - /* temporarily not support QOS in IBSS */ - NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, sizeof(struct rt_edca_parm)); - NdisZeroMemory(&pAd->MlmeAux.APQbssLoad, - sizeof(struct rt_qbss_load_parm)); - NdisZeroMemory(&pAd->MlmeAux.APQosCapability, - sizeof(struct rt_qos_capability_parm)); - - AsicSwitchChannel(pAd, pAd->MlmeAux.Channel, FALSE); - AsicLockChannel(pAd, pAd->MlmeAux.Channel); - - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - MlmeStartReqAction(ch= %d,sup rates= %d, ext rates=%d)\n", - pAd->MlmeAux.Channel, pAd->MlmeAux.SupRateLen, - pAd->MlmeAux.ExtRateLen)); - - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - Status = MLME_SUCCESS; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, - &Status); - } else { - DBGPRINT_ERR("SYNC - MlmeStartReqAction() sanity check fail.\n"); - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - Status = MLME_INVALID_FORMAT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, - &Status); - } -} - -/* - ========================================================================== - Description: - peer sends beacon back when scanning - ========================================================================== - */ -void PeerBeaconAtScanAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN]; - u8 Ssid[MAX_LEN_OF_SSID], BssType, Channel, NewChannel, - SsidLen, DtimCount, DtimPeriod, BcastFlag, MessageToMe; - struct rt_cf_parm CfParm; - u16 BeaconPeriod, AtimWin, CapabilityInfo; - struct rt_frame_802_11 * pFrame; - LARGE_INTEGER TimeStamp; - u8 Erp; - u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES], - ExtRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 SupRateLen, ExtRateLen; - u16 LenVIE; - u8 CkipFlag; - u8 AironetCellPowerLimit; - struct rt_edca_parm EdcaParm; - struct rt_qbss_load_parm QbssLoad; - struct rt_qos_capability_parm QosCapability; - unsigned long RalinkIe; - u8 VarIE[MAX_VIE_LEN]; /* Total VIE length = MAX_VIE_LEN - -5 */ - struct rt_ndis_802_11_variable_ies *pVIE = NULL; - struct rt_ht_capability_ie HtCapability; - struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */ - u8 HtCapabilityLen = 0, PreNHtCapabilityLen = 0; - u8 AddHtInfoLen; - u8 NewExtChannelOffset = 0xff; - - /* NdisFillMemory(Ssid, MAX_LEN_OF_SSID, 0x00); */ - pFrame = (struct rt_frame_802_11 *) Elem->Msg; - /* Init Variable IE structure */ - pVIE = (struct rt_ndis_802_11_variable_ies *)VarIE; - pVIE->Length = 0; - - RTMPZeroMemory(&HtCapability, sizeof(HtCapability)); - RTMPZeroMemory(&AddHtInfo, sizeof(struct rt_add_ht_info_ie)); - - if (PeerBeaconAndProbeRspSanity(pAd, - Elem->Msg, - Elem->MsgLen, - Elem->Channel, - Addr2, - Bssid, - (char *)Ssid, - &SsidLen, - &BssType, - &BeaconPeriod, - &Channel, - &NewChannel, - &TimeStamp, - &CfParm, - &AtimWin, - &CapabilityInfo, - &Erp, - &DtimCount, - &DtimPeriod, - &BcastFlag, - &MessageToMe, - SupRate, - &SupRateLen, - ExtRate, - &ExtRateLen, - &CkipFlag, - &AironetCellPowerLimit, - &EdcaParm, - &QbssLoad, - &QosCapability, - &RalinkIe, - &HtCapabilityLen, - &PreNHtCapabilityLen, - &HtCapability, - &AddHtInfoLen, - &AddHtInfo, - &NewExtChannelOffset, &LenVIE, pVIE)) { - unsigned long Idx; - char Rssi = 0; - - Idx = BssTableSearch(&pAd->ScanTab, Bssid, Channel); - if (Idx != BSS_NOT_FOUND) - Rssi = pAd->ScanTab.BssEntry[Idx].Rssi; - - Rssi = - RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), - ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), - ConvertToRssi(pAd, Elem->Rssi2, RSSI_2)); - - if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0)) - HtCapabilityLen = SIZE_HT_CAP_IE; - - Idx = - BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, (char *)Ssid, - SsidLen, BssType, BeaconPeriod, &CfParm, - AtimWin, CapabilityInfo, SupRate, - SupRateLen, ExtRate, ExtRateLen, - &HtCapability, &AddHtInfo, HtCapabilityLen, - AddHtInfoLen, NewExtChannelOffset, Channel, - Rssi, TimeStamp, CkipFlag, &EdcaParm, - &QosCapability, &QbssLoad, LenVIE, pVIE); - - if (Idx != BSS_NOT_FOUND) { - NdisMoveMemory(pAd->ScanTab.BssEntry[Idx].PTSF, - &Elem->Msg[24], 4); - NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[0], - &Elem->TimeStamp.u.LowPart, 4); - NdisMoveMemory(&pAd->ScanTab.BssEntry[Idx].TTSF[4], - &Elem->TimeStamp.u.LowPart, 4); - } - - } - /* sanity check fail, ignored */ -} - -/* - ========================================================================== - Description: - When waiting joining the (I)BSS, beacon received from external - ========================================================================== - */ -void PeerBeaconAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN]; - u8 Ssid[MAX_LEN_OF_SSID], SsidLen, BssType, Channel, MessageToMe, - DtimCount, DtimPeriod, BcastFlag, NewChannel; - LARGE_INTEGER TimeStamp; - u16 BeaconPeriod, AtimWin, CapabilityInfo; - struct rt_cf_parm Cf; - BOOLEAN TimerCancelled; - u8 Erp; - u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES], - ExtRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 SupRateLen, ExtRateLen; - u8 CkipFlag; - u16 LenVIE; - u8 AironetCellPowerLimit; - struct rt_edca_parm EdcaParm; - struct rt_qbss_load_parm QbssLoad; - struct rt_qos_capability_parm QosCapability; - u16 Status; - u8 VarIE[MAX_VIE_LEN]; /* Total VIE length = MAX_VIE_LEN - -5 */ - struct rt_ndis_802_11_variable_ies *pVIE = NULL; - unsigned long RalinkIe; - unsigned long Idx; - struct rt_ht_capability_ie HtCapability; - struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */ - u8 HtCapabilityLen = 0, PreNHtCapabilityLen = 0; - u8 AddHtInfoLen; - u8 NewExtChannelOffset = 0xff; - u8 CentralChannel; - BOOLEAN bAllowNrate = FALSE; - - /* Init Variable IE structure */ - pVIE = (struct rt_ndis_802_11_variable_ies *)VarIE; - pVIE->Length = 0; - RTMPZeroMemory(&HtCapability, sizeof(HtCapability)); - RTMPZeroMemory(&AddHtInfo, sizeof(struct rt_add_ht_info_ie)); - - if (PeerBeaconAndProbeRspSanity(pAd, - Elem->Msg, - Elem->MsgLen, - Elem->Channel, - Addr2, - Bssid, - (char *)Ssid, - &SsidLen, - &BssType, - &BeaconPeriod, - &Channel, - &NewChannel, - &TimeStamp, - &Cf, - &AtimWin, - &CapabilityInfo, - &Erp, - &DtimCount, - &DtimPeriod, - &BcastFlag, - &MessageToMe, - SupRate, - &SupRateLen, - ExtRate, - &ExtRateLen, - &CkipFlag, - &AironetCellPowerLimit, - &EdcaParm, - &QbssLoad, - &QosCapability, - &RalinkIe, - &HtCapabilityLen, - &PreNHtCapabilityLen, - &HtCapability, - &AddHtInfoLen, - &AddHtInfo, - &NewExtChannelOffset, &LenVIE, pVIE)) { - /* Disqualify 11b only adhoc when we are in 11g only adhoc mode */ - if ((BssType == BSS_ADHOC) - && (pAd->CommonCfg.PhyMode == PHY_11G) - && ((SupRateLen + ExtRateLen) < 12)) - return; - - /* BEACON from desired BSS/IBSS found. We should be able to decide most */ - /* BSS parameters here. */ - /* Q. But what happen if this JOIN doesn't conclude a successful ASSOCIATION? */ - /* Do we need to recover back all parameters belonging to previous BSS? */ - /* A. Should be not. There's no back-door recover to previous AP. It still needs */ - /* a new JOIN-AUTH-ASSOC sequence. */ - if (MAC_ADDR_EQUAL(pAd->MlmeAux.Bssid, Bssid)) { - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - receive desired BEACON at JoinWaitBeacon... Channel = %d\n", - Channel)); - RTMPCancelTimer(&pAd->MlmeAux.BeaconTimer, - &TimerCancelled); - - /* Update RSSI to prevent No signal display when cards first initialized */ - pAd->StaCfg.RssiSample.LastRssi0 = - ConvertToRssi(pAd, Elem->Rssi0, RSSI_0); - pAd->StaCfg.RssiSample.LastRssi1 = - ConvertToRssi(pAd, Elem->Rssi1, RSSI_1); - pAd->StaCfg.RssiSample.LastRssi2 = - ConvertToRssi(pAd, Elem->Rssi2, RSSI_2); - pAd->StaCfg.RssiSample.AvgRssi0 = - pAd->StaCfg.RssiSample.LastRssi0; - pAd->StaCfg.RssiSample.AvgRssi0X8 = - pAd->StaCfg.RssiSample.AvgRssi0 << 3; - pAd->StaCfg.RssiSample.AvgRssi1 = - pAd->StaCfg.RssiSample.LastRssi1; - pAd->StaCfg.RssiSample.AvgRssi1X8 = - pAd->StaCfg.RssiSample.AvgRssi1 << 3; - pAd->StaCfg.RssiSample.AvgRssi2 = - pAd->StaCfg.RssiSample.LastRssi2; - pAd->StaCfg.RssiSample.AvgRssi2X8 = - pAd->StaCfg.RssiSample.AvgRssi2 << 3; - - /* */ - /* We need to check if SSID only set to any, then we can record the current SSID. */ - /* Otherwise will cause hidden SSID association failed. */ - /* */ - if (pAd->MlmeAux.SsidLen == 0) { - NdisMoveMemory(pAd->MlmeAux.Ssid, Ssid, - SsidLen); - pAd->MlmeAux.SsidLen = SsidLen; - } else { - Idx = - BssSsidTableSearch(&pAd->ScanTab, Bssid, - pAd->MlmeAux.Ssid, - pAd->MlmeAux.SsidLen, - Channel); - - if (Idx == BSS_NOT_FOUND) { - char Rssi = 0; - Rssi = - RTMPMaxRssi(pAd, - ConvertToRssi(pAd, - Elem-> - Rssi0, - RSSI_0), - ConvertToRssi(pAd, - Elem-> - Rssi1, - RSSI_1), - ConvertToRssi(pAd, - Elem-> - Rssi2, - RSSI_2)); - Idx = - BssTableSetEntry(pAd, &pAd->ScanTab, - Bssid, - (char *) Ssid, - SsidLen, BssType, - BeaconPeriod, &Cf, - AtimWin, - CapabilityInfo, - SupRate, - SupRateLen, - ExtRate, - ExtRateLen, - &HtCapability, - &AddHtInfo, - HtCapabilityLen, - AddHtInfoLen, - NewExtChannelOffset, - Channel, Rssi, - TimeStamp, - CkipFlag, - &EdcaParm, - &QosCapability, - &QbssLoad, LenVIE, - pVIE); - if (Idx != BSS_NOT_FOUND) { - NdisMoveMemory(pAd->ScanTab. - BssEntry[Idx]. - PTSF, - &Elem->Msg[24], - 4); - NdisMoveMemory(&pAd->ScanTab. - BssEntry[Idx]. - TTSF[0], - &Elem->TimeStamp. - u.LowPart, 4); - NdisMoveMemory(&pAd->ScanTab. - BssEntry[Idx]. - TTSF[4], - &Elem->TimeStamp. - u.LowPart, 4); - CapabilityInfo = - pAd->ScanTab.BssEntry[Idx]. - CapabilityInfo; - } - } else { - /* */ - /* Multiple SSID case, used correct CapabilityInfo */ - /* */ - CapabilityInfo = - pAd->ScanTab.BssEntry[Idx]. - CapabilityInfo; - } - } - NdisMoveMemory(pAd->MlmeAux.Bssid, Bssid, MAC_ADDR_LEN); - pAd->MlmeAux.CapabilityInfo = - CapabilityInfo & SUPPORTED_CAPABILITY_INFO; - pAd->MlmeAux.BssType = BssType; - pAd->MlmeAux.BeaconPeriod = BeaconPeriod; - pAd->MlmeAux.Channel = Channel; - pAd->MlmeAux.AtimWin = AtimWin; - pAd->MlmeAux.CfpPeriod = Cf.CfpPeriod; - pAd->MlmeAux.CfpMaxDuration = Cf.CfpMaxDuration; - pAd->MlmeAux.APRalinkIe = RalinkIe; - - /* Copy AP's supported rate to MlmeAux for creating association request */ - /* Also filter out not supported rate */ - pAd->MlmeAux.SupRateLen = SupRateLen; - NdisMoveMemory(pAd->MlmeAux.SupRate, SupRate, - SupRateLen); - RTMPCheckRates(pAd, pAd->MlmeAux.SupRate, - &pAd->MlmeAux.SupRateLen); - pAd->MlmeAux.ExtRateLen = ExtRateLen; - NdisMoveMemory(pAd->MlmeAux.ExtRate, ExtRate, - ExtRateLen); - RTMPCheckRates(pAd, pAd->MlmeAux.ExtRate, - &pAd->MlmeAux.ExtRateLen); - - NdisZeroMemory(pAd->StaActive.SupportedPhyInfo.MCSSet, - 16); - - if (((pAd->StaCfg.WepStatus != Ndis802_11WEPEnabled) - && (pAd->StaCfg.WepStatus != - Ndis802_11Encryption2Enabled)) - || (pAd->CommonCfg.HT_DisallowTKIP == FALSE)) { - bAllowNrate = TRUE; - } - - pAd->MlmeAux.NewExtChannelOffset = NewExtChannelOffset; - pAd->MlmeAux.HtCapabilityLen = HtCapabilityLen; - - RTMPZeroMemory(&pAd->MlmeAux.HtCapability, - SIZE_HT_CAP_IE); - /* filter out un-supported ht rates */ - if (((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0)) - && ((pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) - && (bAllowNrate))) { - RTMPMoveMemory(&pAd->MlmeAux.AddHtInfo, - &AddHtInfo, SIZE_ADD_HT_INFO_IE); - - /* StaActive.SupportedHtPhy.MCSSet stores Peer AP's 11n Rx capability */ - NdisMoveMemory(pAd->StaActive.SupportedPhyInfo. - MCSSet, HtCapability.MCSSet, 16); - pAd->MlmeAux.NewExtChannelOffset = - NewExtChannelOffset; - pAd->MlmeAux.HtCapabilityLen = SIZE_HT_CAP_IE; - pAd->StaActive.SupportedPhyInfo.bHtEnable = - TRUE; - if (PreNHtCapabilityLen > 0) - pAd->StaActive.SupportedPhyInfo. - bPreNHt = TRUE; - RTMPCheckHt(pAd, BSSID_WCID, &HtCapability, - &AddHtInfo); - /* Copy AP Parameter to StaActive. This is also in LinkUp. */ - DBGPRINT(RT_DEBUG_TRACE, - ("PeerBeaconAtJoinAction! (MpduDensity=%d, MaxRAmpduFactor=%d, BW=%d)\n", - pAd->StaActive.SupportedHtPhy. - MpduDensity, - pAd->StaActive.SupportedHtPhy. - MaxRAmpduFactor, - HtCapability.HtCapInfo.ChannelWidth)); - - if (AddHtInfoLen > 0) { - CentralChannel = AddHtInfo.ControlChan; - /* Check again the Bandwidth capability of this AP. */ - if ((AddHtInfo.ControlChan > 2) - && (AddHtInfo.AddHtInfo. - ExtChanOffset == EXTCHA_BELOW) - && (HtCapability.HtCapInfo. - ChannelWidth == BW_40)) { - CentralChannel = - AddHtInfo.ControlChan - 2; - } else - if ((AddHtInfo.AddHtInfo. - ExtChanOffset == EXTCHA_ABOVE) - && (HtCapability.HtCapInfo. - ChannelWidth == BW_40)) { - CentralChannel = - AddHtInfo.ControlChan + 2; - } - /* Check Error . */ - if (pAd->MlmeAux.CentralChannel != - CentralChannel) - DBGPRINT(RT_DEBUG_ERROR, - ("PeerBeaconAtJoinAction HT===>Beacon Central Channel = %d, Control Channel = %d. Mlmeaux CentralChannel = %d\n", - CentralChannel, - AddHtInfo.ControlChan, - pAd->MlmeAux. - CentralChannel)); - - DBGPRINT(RT_DEBUG_TRACE, - ("PeerBeaconAtJoinAction HT===>Central Channel = %d, Control Channel = %d, .\n", - CentralChannel, - AddHtInfo.ControlChan)); - - } - - } else { - /* To prevent error, let legacy AP must have same CentralChannel and Channel. */ - if ((HtCapabilityLen == 0) - && (PreNHtCapabilityLen == 0)) - pAd->MlmeAux.CentralChannel = - pAd->MlmeAux.Channel; - - pAd->StaActive.SupportedPhyInfo.bHtEnable = - FALSE; - pAd->MlmeAux.NewExtChannelOffset = 0xff; - RTMPZeroMemory(&pAd->MlmeAux.HtCapability, - SIZE_HT_CAP_IE); - pAd->MlmeAux.HtCapabilityLen = 0; - RTMPZeroMemory(&pAd->MlmeAux.AddHtInfo, - SIZE_ADD_HT_INFO_IE); - } - - RTMPUpdateMlmeRate(pAd); - - /* copy QOS related information */ - if ((pAd->CommonCfg.bWmmCapable) - || (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) - ) { - NdisMoveMemory(&pAd->MlmeAux.APEdcaParm, - &EdcaParm, sizeof(struct rt_edca_parm)); - NdisMoveMemory(&pAd->MlmeAux.APQbssLoad, - &QbssLoad, - sizeof(struct rt_qbss_load_parm)); - NdisMoveMemory(&pAd->MlmeAux.APQosCapability, - &QosCapability, - sizeof(struct rt_qos_capability_parm)); - } else { - NdisZeroMemory(&pAd->MlmeAux.APEdcaParm, - sizeof(struct rt_edca_parm)); - NdisZeroMemory(&pAd->MlmeAux.APQbssLoad, - sizeof(struct rt_qbss_load_parm)); - NdisZeroMemory(&pAd->MlmeAux.APQosCapability, - sizeof(struct rt_qos_capability_parm)); - } - - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - after JOIN, SupRateLen=%d, ExtRateLen=%d\n", - pAd->MlmeAux.SupRateLen, - pAd->MlmeAux.ExtRateLen)); - - if (AironetCellPowerLimit != 0xFF) { - /*We need to change our TxPower for CCX 2.0 AP Control of Client Transmit Power */ - ChangeToCellPowerLimit(pAd, - AironetCellPowerLimit); - } else /*Used the default TX Power Percentage. */ - pAd->CommonCfg.TxPowerPercentage = - pAd->CommonCfg.TxPowerDefault; - - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - Status = MLME_SUCCESS; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, - 2, &Status); - } - /* not to me BEACON, ignored */ - } - /* sanity check fail, ignore this frame */ -} - -/* - ========================================================================== - Description: - receive BEACON from peer - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void PeerBeacon(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Bssid[MAC_ADDR_LEN], Addr2[MAC_ADDR_LEN]; - char Ssid[MAX_LEN_OF_SSID]; - struct rt_cf_parm CfParm; - u8 SsidLen, MessageToMe = 0, BssType, Channel, NewChannel, index = 0; - u8 DtimCount = 0, DtimPeriod = 0, BcastFlag = 0; - u16 CapabilityInfo, AtimWin, BeaconPeriod; - LARGE_INTEGER TimeStamp; - u16 TbttNumToNextWakeUp; - u8 Erp; - u8 SupRate[MAX_LEN_OF_SUPPORTED_RATES], - ExtRate[MAX_LEN_OF_SUPPORTED_RATES]; - u8 SupRateLen, ExtRateLen; - u8 CkipFlag; - u16 LenVIE; - u8 AironetCellPowerLimit; - struct rt_edca_parm EdcaParm; - struct rt_qbss_load_parm QbssLoad; - struct rt_qos_capability_parm QosCapability; - unsigned long RalinkIe; - /* New for WPA security suites */ - u8 VarIE[MAX_VIE_LEN]; /* Total VIE length = MAX_VIE_LEN - -5 */ - struct rt_ndis_802_11_variable_ies *pVIE = NULL; - struct rt_ht_capability_ie HtCapability; - struct rt_add_ht_info_ie AddHtInfo; /* AP might use this additional ht info IE */ - u8 HtCapabilityLen, PreNHtCapabilityLen; - u8 AddHtInfoLen; - u8 NewExtChannelOffset = 0xff; - - if (!(INFRA_ON(pAd) || ADHOC_ON(pAd) - )) - return; - - /* Init Variable IE structure */ - pVIE = (struct rt_ndis_802_11_variable_ies *)VarIE; - pVIE->Length = 0; - RTMPZeroMemory(&HtCapability, sizeof(HtCapability)); - RTMPZeroMemory(&AddHtInfo, sizeof(struct rt_add_ht_info_ie)); - - if (PeerBeaconAndProbeRspSanity(pAd, - Elem->Msg, - Elem->MsgLen, - Elem->Channel, - Addr2, - Bssid, - Ssid, - &SsidLen, - &BssType, - &BeaconPeriod, - &Channel, - &NewChannel, - &TimeStamp, - &CfParm, - &AtimWin, - &CapabilityInfo, - &Erp, - &DtimCount, - &DtimPeriod, - &BcastFlag, - &MessageToMe, - SupRate, - &SupRateLen, - ExtRate, - &ExtRateLen, - &CkipFlag, - &AironetCellPowerLimit, - &EdcaParm, - &QbssLoad, - &QosCapability, - &RalinkIe, - &HtCapabilityLen, - &PreNHtCapabilityLen, - &HtCapability, - &AddHtInfoLen, - &AddHtInfo, - &NewExtChannelOffset, &LenVIE, pVIE)) { - BOOLEAN is_my_bssid, is_my_ssid; - unsigned long Bssidx, Now; - struct rt_bss_entry *pBss; - char RealRssi = - RTMPMaxRssi(pAd, ConvertToRssi(pAd, Elem->Rssi0, RSSI_0), - ConvertToRssi(pAd, Elem->Rssi1, RSSI_1), - ConvertToRssi(pAd, Elem->Rssi2, RSSI_2)); - - is_my_bssid = - MAC_ADDR_EQUAL(Bssid, pAd->CommonCfg.Bssid) ? TRUE : FALSE; - is_my_ssid = - SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid, - pAd->CommonCfg.SsidLen) ? TRUE : FALSE; - - /* ignore BEACON not for my SSID */ - if ((!is_my_ssid) && (!is_my_bssid)) - return; - - /* It means STA waits disassoc completely from this AP, ignores this beacon. */ - if (pAd->Mlme.CntlMachine.CurrState == CNTL_WAIT_DISASSOC) - return; - - /* Copy Control channel for this BSSID. */ - if (AddHtInfoLen != 0) - Channel = AddHtInfo.ControlChan; - - if ((HtCapabilityLen > 0) || (PreNHtCapabilityLen > 0)) - HtCapabilityLen = SIZE_HT_CAP_IE; - - /* */ - /* Housekeeping "SsidBssTab" table for later-on ROAMing usage. */ - /* */ - Bssidx = BssTableSearch(&pAd->ScanTab, Bssid, Channel); - if (Bssidx == BSS_NOT_FOUND) { - /* discover new AP of this network, create BSS entry */ - Bssidx = - BssTableSetEntry(pAd, &pAd->ScanTab, Bssid, Ssid, - SsidLen, BssType, BeaconPeriod, - &CfParm, AtimWin, CapabilityInfo, - SupRate, SupRateLen, ExtRate, - ExtRateLen, &HtCapability, - &AddHtInfo, HtCapabilityLen, - AddHtInfoLen, NewExtChannelOffset, - Channel, RealRssi, TimeStamp, - CkipFlag, &EdcaParm, - &QosCapability, &QbssLoad, LenVIE, - pVIE); - if (Bssidx == BSS_NOT_FOUND) /* return if BSS table full */ - return; - - NdisMoveMemory(pAd->ScanTab.BssEntry[Bssidx].PTSF, - &Elem->Msg[24], 4); - NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[0], - &Elem->TimeStamp.u.LowPart, 4); - NdisMoveMemory(&pAd->ScanTab.BssEntry[Bssidx].TTSF[4], - &Elem->TimeStamp.u.LowPart, 4); - - } - - if ((pAd->CommonCfg.bIEEE80211H == 1) && (NewChannel != 0) - && (Channel != NewChannel)) { - /* Switching to channel 1 can prevent from rescanning the current channel immediately (by auto reconnection). */ - /* In addition, clear the MLME queue and the scan table to discard the RX packets and previous scanning results. */ - AsicSwitchChannel(pAd, 1, FALSE); - AsicLockChannel(pAd, 1); - LinkDown(pAd, FALSE); - MlmeQueueInit(&pAd->Mlme.Queue); - BssTableInit(&pAd->ScanTab); - RTMPusecDelay(1000000); /* use delay to prevent STA do reassoc */ - - /* channel sanity check */ - for (index = 0; index < pAd->ChannelListNum; index++) { - if (pAd->ChannelList[index].Channel == - NewChannel) { - pAd->ScanTab.BssEntry[Bssidx].Channel = - NewChannel; - pAd->CommonCfg.Channel = NewChannel; - AsicSwitchChannel(pAd, - pAd->CommonCfg. - Channel, FALSE); - AsicLockChannel(pAd, - pAd->CommonCfg.Channel); - DBGPRINT(RT_DEBUG_TRACE, - ("PeerBeacon - STA receive channel switch announcement IE (New Channel =%d)\n", - NewChannel)); - break; - } - } - - if (index >= pAd->ChannelListNum) { - DBGPRINT_ERR("PeerBeacon(can not find New Channel=%d in ChannelList[%d]\n", pAd->CommonCfg.Channel, pAd->ChannelListNum); - } - } - /* if the ssid matched & bssid unmatched, we should select the bssid with large value. */ - /* This might happened when two STA start at the same time */ - if ((!is_my_bssid) && ADHOC_ON(pAd)) { - int i; - - /* Add the safeguard against the mismatch of adhoc wep status */ - if (pAd->StaCfg.WepStatus != - pAd->ScanTab.BssEntry[Bssidx].WepStatus) { - return; - } - /* collapse into the ADHOC network which has bigger BSSID value. */ - for (i = 0; i < 6; i++) { - if (Bssid[i] > pAd->CommonCfg.Bssid[i]) { - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - merge to the IBSS " - "with bigger BSSID=" - "%pM\n", Bssid)); - AsicDisableSync(pAd); - COPY_MAC_ADDR(pAd->CommonCfg.Bssid, - Bssid); - AsicSetBssid(pAd, pAd->CommonCfg.Bssid); - MakeIbssBeacon(pAd); /* re-build BEACON frame */ - AsicEnableIbssSync(pAd); /* copy BEACON frame to on-chip memory */ - is_my_bssid = TRUE; - break; - } else if (Bssid[i] < pAd->CommonCfg.Bssid[i]) - break; - } - } - - NdisGetSystemUpTime(&Now); - pBss = &pAd->ScanTab.BssEntry[Bssidx]; - pBss->Rssi = RealRssi; /* lastest RSSI */ - pBss->LastBeaconRxTime = Now; /* last RX timestamp */ - - /* */ - /* BEACON from my BSSID - either IBSS or INFRA network */ - /* */ - if (is_my_bssid) { - struct rt_rxwi RxWI; - - pAd->StaCfg.DtimCount = DtimCount; - pAd->StaCfg.DtimPeriod = DtimPeriod; - pAd->StaCfg.LastBeaconRxTime = Now; - - RxWI.RSSI0 = Elem->Rssi0; - RxWI.RSSI1 = Elem->Rssi1; - RxWI.RSSI2 = Elem->Rssi2; - - Update_Rssi_Sample(pAd, &pAd->StaCfg.RssiSample, &RxWI); - if (AironetCellPowerLimit != 0xFF) { - /* */ - /* We get the Cisco (ccx) "TxPower Limit" required */ - /* Changed to appropriate TxPower Limit for Ciso Compatible Extensions */ - /* */ - ChangeToCellPowerLimit(pAd, - AironetCellPowerLimit); - } else { - /* */ - /* AironetCellPowerLimit equal to 0xFF means the Cisco (ccx) "TxPower Limit" not exist. */ - /* Used the default TX Power Percentage, that set from UI. */ - /* */ - pAd->CommonCfg.TxPowerPercentage = - pAd->CommonCfg.TxPowerDefault; - } - - if (ADHOC_ON(pAd) && (CAP_IS_IBSS_ON(CapabilityInfo))) { - u8 MaxSupportedRateIn500Kbps = 0; - u8 idx; - struct rt_mac_table_entry *pEntry; - - /* supported rates array may not be sorted. sort it and find the maximum rate */ - for (idx = 0; idx < SupRateLen; idx++) { - if (MaxSupportedRateIn500Kbps < - (SupRate[idx] & 0x7f)) - MaxSupportedRateIn500Kbps = - SupRate[idx] & 0x7f; - } - - for (idx = 0; idx < ExtRateLen; idx++) { - if (MaxSupportedRateIn500Kbps < - (ExtRate[idx] & 0x7f)) - MaxSupportedRateIn500Kbps = - ExtRate[idx] & 0x7f; - } - - /* look up the existing table */ - pEntry = MacTableLookup(pAd, Addr2); - - /* Ad-hoc mode is using MAC address as BA session. So we need to continuously find newly joined adhoc station by receiving beacon. */ - /* To prevent always check this, we use wcid == RESERVED_WCID to recognize it as newly joined adhoc station. */ - if ((ADHOC_ON(pAd) - && (Elem->Wcid == RESERVED_WCID)) - || (pEntry - && - ((pEntry->LastBeaconRxTime + - ADHOC_ENTRY_BEACON_LOST_TIME) < - Now))) { - if (pEntry == NULL) - /* Another adhoc joining, add to our MAC table. */ - pEntry = - MacTableInsertEntry(pAd, - Addr2, - BSS0, - FALSE); - - if (StaAddMacTableEntry(pAd, - pEntry, - MaxSupportedRateIn500Kbps, - &HtCapability, - HtCapabilityLen, - &AddHtInfo, - AddHtInfoLen, - CapabilityInfo) - == FALSE) { - DBGPRINT(RT_DEBUG_TRACE, - ("ADHOC - Add Entry failed.\n")); - return; - } - - if (pEntry && - (Elem->Wcid == RESERVED_WCID)) { - idx = pAd->StaCfg.DefaultKeyId; - RTMP_STA_SECURITY_INFO_ADD(pAd, - BSS0, - idx, - pEntry); - } - } - - if (pEntry && pEntry->ValidAsCLI) - pEntry->LastBeaconRxTime = Now; - - /* At least another peer in this IBSS, declare MediaState as CONNECTED */ - if (!OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) { - OPSTATUS_SET_FLAG(pAd, - fOP_STATUS_MEDIA_STATE_CONNECTED); - - pAd->IndicateMediaState = - NdisMediaStateConnected; - RTMP_IndicateMediaState(pAd); - pAd->ExtraInfo = GENERAL_LINK_UP; - AsicSetBssid(pAd, pAd->CommonCfg.Bssid); - - /* 2003/03/12 - john */ - /* Make sure this entry in "ScanTab" table, thus complies to Microsoft's policy that */ - /* "site survey" result should always include the current connected network. */ - /* */ - Bssidx = - BssTableSearch(&pAd->ScanTab, Bssid, - Channel); - if (Bssidx == BSS_NOT_FOUND) { - Bssidx = - BssTableSetEntry(pAd, - &pAd-> - ScanTab, - Bssid, - Ssid, - SsidLen, - BssType, - BeaconPeriod, - &CfParm, - AtimWin, - CapabilityInfo, - SupRate, - SupRateLen, - ExtRate, - ExtRateLen, - &HtCapability, - &AddHtInfo, - HtCapabilityLen, - AddHtInfoLen, - NewExtChannelOffset, - Channel, - RealRssi, - TimeStamp, - 0, - &EdcaParm, - &QosCapability, - &QbssLoad, - LenVIE, - pVIE); - } - DBGPRINT(RT_DEBUG_TRACE, - ("ADHOC fOP_STATUS_MEDIA_STATE_CONNECTED.\n")); - } - } - - if (INFRA_ON(pAd)) { - BOOLEAN bUseShortSlot, bUseBGProtection; - - /* decide to use/change to - */ - /* 1. long slot (20 us) or short slot (9 us) time */ - /* 2. turn on/off RTS/CTS and/or CTS-to-self protection */ - /* 3. short preamble */ - - /*bUseShortSlot = pAd->CommonCfg.bUseShortSlotTime && CAP_IS_SHORT_SLOT(CapabilityInfo); */ - bUseShortSlot = - CAP_IS_SHORT_SLOT(CapabilityInfo); - if (bUseShortSlot != - OPSTATUS_TEST_FLAG(pAd, - fOP_STATUS_SHORT_SLOT_INUSED)) - AsicSetSlotTime(pAd, bUseShortSlot); - - bUseBGProtection = (pAd->CommonCfg.UseBGProtection == 1) || /* always use */ - ((pAd->CommonCfg.UseBGProtection == 0) - && ERP_IS_USE_PROTECTION(Erp)); - - if (pAd->CommonCfg.Channel > 14) /* always no BG protection in A-band. falsely happened when switching A/G band to a dual-band AP */ - bUseBGProtection = FALSE; - - if (bUseBGProtection != - OPSTATUS_TEST_FLAG(pAd, - fOP_STATUS_BG_PROTECTION_INUSED)) - { - if (bUseBGProtection) { - OPSTATUS_SET_FLAG(pAd, - fOP_STATUS_BG_PROTECTION_INUSED); - AsicUpdateProtect(pAd, - pAd->MlmeAux. - AddHtInfo. - AddHtInfo2. - OperaionMode, - (OFDMSETPROTECT - | - CCKSETPROTECT - | - ALLN_SETPROTECT), - FALSE, - (pAd->MlmeAux. - AddHtInfo. - AddHtInfo2. - NonGfPresent - == 1)); - } else { - OPSTATUS_CLEAR_FLAG(pAd, - fOP_STATUS_BG_PROTECTION_INUSED); - AsicUpdateProtect(pAd, - pAd->MlmeAux. - AddHtInfo. - AddHtInfo2. - OperaionMode, - (OFDMSETPROTECT - | - CCKSETPROTECT - | - ALLN_SETPROTECT), - TRUE, - (pAd->MlmeAux. - AddHtInfo. - AddHtInfo2. - NonGfPresent - == 1)); - } - - DBGPRINT(RT_DEBUG_WARN, - ("SYNC - AP changed B/G protection to %d\n", - bUseBGProtection)); - } - /* check Ht protection mode. and adhere to the Non-GF device indication by AP. */ - if ((AddHtInfoLen != 0) && - ((AddHtInfo.AddHtInfo2.OperaionMode != - pAd->MlmeAux.AddHtInfo.AddHtInfo2. - OperaionMode) - || (AddHtInfo.AddHtInfo2.NonGfPresent != - pAd->MlmeAux.AddHtInfo.AddHtInfo2. - NonGfPresent))) { - pAd->MlmeAux.AddHtInfo.AddHtInfo2. - NonGfPresent = - AddHtInfo.AddHtInfo2.NonGfPresent; - pAd->MlmeAux.AddHtInfo.AddHtInfo2. - OperaionMode = - AddHtInfo.AddHtInfo2.OperaionMode; - if (pAd->MlmeAux.AddHtInfo.AddHtInfo2. - NonGfPresent == 1) { - AsicUpdateProtect(pAd, - pAd->MlmeAux. - AddHtInfo. - AddHtInfo2. - OperaionMode, - ALLN_SETPROTECT, - FALSE, TRUE); - } else - AsicUpdateProtect(pAd, - pAd->MlmeAux. - AddHtInfo. - AddHtInfo2. - OperaionMode, - ALLN_SETPROTECT, - FALSE, FALSE); - - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - AP changed N OperaionMode to %d\n", - pAd->MlmeAux.AddHtInfo. - AddHtInfo2.OperaionMode)); - } - - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_SHORT_PREAMBLE_INUSED) - && ERP_IS_USE_BARKER_PREAMBLE(Erp)) { - MlmeSetTxPreamble(pAd, - Rt802_11PreambleLong); - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - AP forced to use long preamble\n")); - } - - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_WMM_INUSED) - && (EdcaParm.bValid == TRUE) - && (EdcaParm.EdcaUpdateCount != - pAd->CommonCfg.APEdcaParm. - EdcaUpdateCount)) { - DBGPRINT(RT_DEBUG_TRACE, - ("SYNC - AP change EDCA parameters(from %d to %d)\n", - pAd->CommonCfg.APEdcaParm. - EdcaUpdateCount, - EdcaParm.EdcaUpdateCount)); - AsicSetEdcaParm(pAd, &EdcaParm); - } - /* copy QOS related information */ - NdisMoveMemory(&pAd->CommonCfg.APQbssLoad, - &QbssLoad, - sizeof(struct rt_qbss_load_parm)); - NdisMoveMemory(&pAd->CommonCfg.APQosCapability, - &QosCapability, - sizeof(struct rt_qos_capability_parm)); - } - /* only INFRASTRUCTURE mode support power-saving feature */ - if ((INFRA_ON(pAd) && (pAd->StaCfg.Psm == PWR_SAVE)) - || (pAd->CommonCfg.bAPSDForcePowerSave)) { - u8 FreeNumber; - /* 1. AP has backlogged unicast-to-me frame, stay AWAKE, send PSPOLL */ - /* 2. AP has backlogged broadcast/multicast frame and we want those frames, stay AWAKE */ - /* 3. we have outgoing frames in TxRing or MgmtRing, better stay AWAKE */ - /* 4. Psm change to PWR_SAVE, but AP not been informed yet, we better stay AWAKE */ - /* 5. otherwise, put PHY back to sleep to save battery. */ - if (MessageToMe) { -#ifdef RTMP_MAC_PCI - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_PCIE_DEVICE)) { - /* Restore to correct BBP R3 value */ - if (pAd->Antenna.field.RxPath > - 1) - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R3, - pAd->StaCfg.BBPR3); - /* Turn clk to 80Mhz. */ - } -#endif /* RTMP_MAC_PCI // */ - if (pAd->CommonCfg.bAPSDCapable - && pAd->CommonCfg.APEdcaParm. - bAPSDCapable - && pAd->CommonCfg.bAPSDAC_BE - && pAd->CommonCfg.bAPSDAC_BK - && pAd->CommonCfg.bAPSDAC_VI - && pAd->CommonCfg.bAPSDAC_VO) { - pAd->CommonCfg. - bNeedSendTriggerFrame = - TRUE; - } else - RTMP_PS_POLL_ENQUEUE(pAd); - } else if (BcastFlag && (DtimCount == 0) - && OPSTATUS_TEST_FLAG(pAd, - fOP_STATUS_RECEIVE_DTIM)) - { -#ifdef RTMP_MAC_PCI - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_PCIE_DEVICE)) { - if (pAd->Antenna.field.RxPath > - 1) - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R3, - pAd->StaCfg.BBPR3); - } -#endif /* RTMP_MAC_PCI // */ - } else - if ((pAd->TxSwQueue[QID_AC_BK].Number != 0) - || (pAd->TxSwQueue[QID_AC_BE].Number != - 0) - || (pAd->TxSwQueue[QID_AC_VI].Number != - 0) - || (pAd->TxSwQueue[QID_AC_VO].Number != - 0) - || - (RTMPFreeTXDRequest - (pAd, QID_AC_BK, TX_RING_SIZE - 1, - &FreeNumber) != NDIS_STATUS_SUCCESS) - || - (RTMPFreeTXDRequest - (pAd, QID_AC_BE, TX_RING_SIZE - 1, - &FreeNumber) != NDIS_STATUS_SUCCESS) - || - (RTMPFreeTXDRequest - (pAd, QID_AC_VI, TX_RING_SIZE - 1, - &FreeNumber) != NDIS_STATUS_SUCCESS) - || - (RTMPFreeTXDRequest - (pAd, QID_AC_VO, TX_RING_SIZE - 1, - &FreeNumber) != NDIS_STATUS_SUCCESS) - || - (RTMPFreeTXDRequest - (pAd, QID_MGMT, MGMT_RING_SIZE - 1, - &FreeNumber) != - NDIS_STATUS_SUCCESS)) { - /* TODO: consider scheduled HCCA. might not be proper to use traditional DTIM-based power-saving scheme */ - /* can we cheat here (i.e. just check MGMT & AC_BE) for better performance? */ -#ifdef RTMP_MAC_PCI - if (OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_PCIE_DEVICE)) { - if (pAd->Antenna.field.RxPath > - 1) - RTMP_BBP_IO_WRITE8_BY_REG_ID - (pAd, BBP_R3, - pAd->StaCfg.BBPR3); - } -#endif /* RTMP_MAC_PCI // */ - } else { - if ((pAd->CommonCfg. - bACMAPSDTr[QID_AC_VO]) - || (pAd->CommonCfg. - bACMAPSDTr[QID_AC_VI]) - || (pAd->CommonCfg. - bACMAPSDTr[QID_AC_BK]) - || (pAd->CommonCfg. - bACMAPSDTr[QID_AC_BE])) { - /* - WMM Spec v1.0 3.6.2.4, - The WMM STA shall remain awake until it receives a - QoS Data or Null frame addressed to it, with the - EOSP subfield in QoS Control field set to 1. - - So we can not sleep here or we will suffer a case: - - PS Management Frame --> - Trigger frame --> - Beacon (TIM=0) (Beacon is closer to Trig frame) --> - Station goes to sleep --> - AP delivery queued UAPSD packets --> - Station can NOT receive the reply - - Maybe we need a timeout timer to avoid that we do - NOT receive the EOSP frame. - - We can not use More Data to check if SP is ended - due to MaxSPLength. - */ - } else { - u16 NextDtim = DtimCount; - - if (NextDtim == 0) - NextDtim = DtimPeriod; - - TbttNumToNextWakeUp = - pAd->StaCfg. - DefaultListenCount; - if (OPSTATUS_TEST_FLAG - (pAd, - fOP_STATUS_RECEIVE_DTIM) - && (TbttNumToNextWakeUp > - NextDtim)) - TbttNumToNextWakeUp = - NextDtim; - - if (!OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_DOZE)) { - /* Set a flag to go to sleep . Then after parse this RxDoneInterrupt, will go to sleep mode. */ - pAd-> - ThisTbttNumToNextWakeUp - = - TbttNumToNextWakeUp; - AsicSleepThenAutoWakeup - (pAd, - pAd-> - ThisTbttNumToNextWakeUp); - } - } - } - } - } - /* not my BSSID, ignore it */ - } - /* sanity check fail, ignore this frame */ -} - -/* - ========================================================================== - Description: - Receive PROBE REQ from remote peer when operating in IBSS mode - ========================================================================== - */ -void PeerProbeReqAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 Addr2[MAC_ADDR_LEN]; - char Ssid[MAX_LEN_OF_SSID]; - u8 SsidLen; - u8 HtLen, AddHtLen, NewExtLen; - struct rt_header_802_11 ProbeRspHdr; - int NStatus; - u8 *pOutBuffer = NULL; - unsigned long FrameLen = 0; - LARGE_INTEGER FakeTimestamp; - u8 DsLen = 1, IbssLen = 2; - u8 LocalErpIe[3] = { IE_ERP, 1, 0 }; - BOOLEAN Privacy; - u16 CapabilityInfo; - u8 RSNIe = IE_WPA; - - if (!ADHOC_ON(pAd)) - return; - - if (PeerProbeReqSanity - (pAd, Elem->Msg, Elem->MsgLen, Addr2, Ssid, &SsidLen)) { - if ((SsidLen == 0) - || SSID_EQUAL(Ssid, SsidLen, pAd->CommonCfg.Ssid, - pAd->CommonCfg.SsidLen)) { - /* allocate and send out ProbeRsp frame */ - NStatus = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NStatus != NDIS_STATUS_SUCCESS) - return; - - /*pAd->StaCfg.AtimWin = 0; // ?????? */ - - Privacy = - (pAd->StaCfg.WepStatus == - Ndis802_11Encryption1Enabled) - || (pAd->StaCfg.WepStatus == - Ndis802_11Encryption2Enabled) - || (pAd->StaCfg.WepStatus == - Ndis802_11Encryption3Enabled); - CapabilityInfo = - CAP_GENERATE(0, 1, Privacy, - (pAd->CommonCfg.TxPreamble == - Rt802_11PreambleShort), 0, 0); - - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_header_802_11), &ProbeRspHdr, - TIMESTAMP_LEN, &FakeTimestamp, - 2, &pAd->CommonCfg.BeaconPeriod, - 2, &CapabilityInfo, - 1, &SsidIe, - 1, &pAd->CommonCfg.SsidLen, - pAd->CommonCfg.SsidLen, - pAd->CommonCfg.Ssid, 1, &SupRateIe, 1, - &pAd->StaActive.SupRateLen, - pAd->StaActive.SupRateLen, - pAd->StaActive.SupRate, 1, &DsIe, 1, - &DsLen, 1, &pAd->CommonCfg.Channel, 1, - &IbssIe, 1, &IbssLen, 2, - &pAd->StaActive.AtimWin, END_OF_ARGS); - - if (pAd->StaActive.ExtRateLen) { - unsigned long tmp; - MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp, - 3, LocalErpIe, - 1, &ExtRateIe, - 1, &pAd->StaActive.ExtRateLen, - pAd->StaActive.ExtRateLen, - &pAd->StaActive.ExtRate, - END_OF_ARGS); - FrameLen += tmp; - } - /* If adhoc secruity is set for WPA-None, append the cipher suite IE */ - if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) { - unsigned long tmp; - MakeOutgoingFrame(pOutBuffer + FrameLen, &tmp, - 1, &RSNIe, - 1, &pAd->StaCfg.RSNIE_Len, - pAd->StaCfg.RSNIE_Len, - pAd->StaCfg.RSN_IE, - END_OF_ARGS); - FrameLen += tmp; - } - - if (pAd->CommonCfg.PhyMode >= PHY_11ABGN_MIXED) { - unsigned long TmpLen; - u8 BROADCOM[4] = { 0x0, 0x90, 0x4c, 0x33 }; - HtLen = sizeof(pAd->CommonCfg.HtCapability); - AddHtLen = sizeof(pAd->CommonCfg.AddHTInfo); - NewExtLen = 1; - /*New extension channel offset IE is included in Beacon, Probe Rsp or channel Switch Announcement Frame */ - if (pAd->bBroadComHT == TRUE) { - MakeOutgoingFrame(pOutBuffer + FrameLen, - &TmpLen, 1, &WpaIe, 4, - &BROADCOM[0], - pAd->MlmeAux. - HtCapabilityLen, - &pAd->MlmeAux. - HtCapability, - END_OF_ARGS); - } else { - MakeOutgoingFrame(pOutBuffer + FrameLen, - &TmpLen, 1, &HtCapIe, - 1, &HtLen, - sizeof - (struct rt_ht_capability_ie), - &pAd->CommonCfg. - HtCapability, 1, - &AddHtInfoIe, 1, - &AddHtLen, - sizeof - (struct rt_add_ht_info_ie), - &pAd->CommonCfg. - AddHTInfo, 1, - &NewExtChanIe, 1, - &NewExtLen, - sizeof - (struct rt_new_ext_chan_ie), - &pAd->CommonCfg. - NewExtChanOffset, - END_OF_ARGS); - } - FrameLen += TmpLen; - } - - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - } - } -} - -void BeaconTimeoutAtJoinAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, ("SYNC - BeaconTimeoutAtJoinAction\n")); - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - Status = MLME_REJ_TIMEOUT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status); -} - -/* - ========================================================================== - Description: - Scan timeout procedure. basically add channel index by 1 and rescan - ========================================================================== - */ -void ScanTimeoutAction(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - pAd->MlmeAux.Channel = NextChannel(pAd, pAd->MlmeAux.Channel); - - /* Only one channel scanned for CISCO beacon request */ - if ((pAd->MlmeAux.ScanType == SCAN_CISCO_ACTIVE) || - (pAd->MlmeAux.ScanType == SCAN_CISCO_PASSIVE) || - (pAd->MlmeAux.ScanType == SCAN_CISCO_NOISE) || - (pAd->MlmeAux.ScanType == SCAN_CISCO_CHANNEL_LOAD)) - pAd->MlmeAux.Channel = 0; - - /* this routine will stop if pAd->MlmeAux.Channel == 0 */ - ScanNextChannel(pAd); -} - -/* - ========================================================================== - Description: - ========================================================================== - */ -void InvalidStateWhenScan(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, - ("AYNC - InvalidStateWhenScan(state=%ld). Reset SYNC machine\n", - pAd->Mlme.SyncMachine.CurrState)); - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - Status = MLME_STATE_MACHINE_REJECT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_SCAN_CONF, 2, &Status); -} - -/* - ========================================================================== - Description: - ========================================================================== - */ -void InvalidStateWhenJoin(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, - ("InvalidStateWhenJoin(state=%ld). Reset SYNC machine\n", - pAd->Mlme.SyncMachine.CurrState)); - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - Status = MLME_STATE_MACHINE_REJECT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_JOIN_CONF, 2, &Status); -} - -/* - ========================================================================== - Description: - ========================================================================== - */ -void InvalidStateWhenStart(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u16 Status; - DBGPRINT(RT_DEBUG_TRACE, - ("InvalidStateWhenStart(state=%ld). Reset SYNC machine\n", - pAd->Mlme.SyncMachine.CurrState)); - pAd->Mlme.SyncMachine.CurrState = SYNC_IDLE; - Status = MLME_STATE_MACHINE_REJECT; - MlmeEnqueue(pAd, MLME_CNTL_STATE_MACHINE, MT2_START_CONF, 2, &Status); -} - -/* - ========================================================================== - Description: - - IRQL = DISPATCH_LEVEL - - ========================================================================== - */ -void EnqueuePsPoll(struct rt_rtmp_adapter *pAd) -{ - - if (pAd->StaCfg.WindowsPowerMode == Ndis802_11PowerModeLegacy_PSP) - pAd->PsPollFrame.FC.PwrMgmt = PWR_SAVE; - MiniportMMRequest(pAd, 0, (u8 *)& pAd->PsPollFrame, - sizeof(struct rt_pspoll_frame)); -} - -/* - ========================================================================== - Description: - ========================================================================== - */ -void EnqueueProbeRequest(struct rt_rtmp_adapter *pAd) -{ - int NState; - u8 *pOutBuffer; - unsigned long FrameLen = 0; - struct rt_header_802_11 Hdr80211; - - DBGPRINT(RT_DEBUG_TRACE, ("force out a ProbeRequest ...\n")); - - NState = MlmeAllocateMemory(pAd, &pOutBuffer); /*Get an unused nonpaged memory */ - if (NState == NDIS_STATUS_SUCCESS) { - MgtMacHeaderInit(pAd, &Hdr80211, SUBTYPE_PROBE_REQ, 0, - BROADCAST_ADDR, BROADCAST_ADDR); - - /* this ProbeRequest explicitly specify SSID to reduce unwanted ProbeResponse */ - MakeOutgoingFrame(pOutBuffer, &FrameLen, - sizeof(struct rt_header_802_11), &Hdr80211, - 1, &SsidIe, - 1, &pAd->CommonCfg.SsidLen, - pAd->CommonCfg.SsidLen, pAd->CommonCfg.Ssid, - 1, &SupRateIe, - 1, &pAd->StaActive.SupRateLen, - pAd->StaActive.SupRateLen, - pAd->StaActive.SupRate, END_OF_ARGS); - MiniportMMRequest(pAd, 0, pOutBuffer, FrameLen); - MlmeFreeMemory(pAd, pOutBuffer); - } - -} - -BOOLEAN ScanRunning(struct rt_rtmp_adapter *pAd) -{ - return (pAd->Mlme.SyncMachine.CurrState == SCAN_LISTEN) ? TRUE : FALSE; -} diff --git a/trunk/drivers/staging/rt2860/sta/wpa.c b/trunk/drivers/staging/rt2860/sta/wpa.c deleted file mode 100644 index ff348325028b..000000000000 --- a/trunk/drivers/staging/rt2860/sta/wpa.c +++ /dev/null @@ -1,374 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - wpa.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Jan Lee 03-07-22 Initial - Paul Lin 03-11-28 Modify for supplicant - Justin P. Mattock 11/07/2010 Fix typos -*/ -#include "../rt_config.h" - -void inc_byte_array(u8 * counter, int len); - -/* - ======================================================================== - - Routine Description: - Process MIC error indication and record MIC error timer. - - Arguments: - pAd Pointer to our adapter - pWpaKey Pointer to the WPA key structure - - Return Value: - None - - IRQL = DISPATCH_LEVEL - - Note: - - ======================================================================== -*/ -void RTMPReportMicError(struct rt_rtmp_adapter *pAd, struct rt_cipher_key *pWpaKey) -{ - unsigned long Now; - u8 unicastKey = (pWpaKey->Type == PAIRWISE_KEY ? 1 : 0); - - /* Record Last MIC error time and count */ - NdisGetSystemUpTime(&Now); - if (pAd->StaCfg.MicErrCnt == 0) { - pAd->StaCfg.MicErrCnt++; - pAd->StaCfg.LastMicErrorTime = Now; - NdisZeroMemory(pAd->StaCfg.ReplayCounter, 8); - } else if (pAd->StaCfg.MicErrCnt == 1) { - if ((pAd->StaCfg.LastMicErrorTime + (60 * OS_HZ)) < Now) { - /* Update Last MIC error time, this did not violate two MIC errors within 60 seconds */ - pAd->StaCfg.LastMicErrorTime = Now; - } else { - - if (pAd->CommonCfg.bWirelessEvent) - RTMPSendWirelessEvent(pAd, - IW_COUNTER_MEASURES_EVENT_FLAG, - pAd->MacTab. - Content[BSSID_WCID].Addr, - BSS0, 0); - - pAd->StaCfg.LastMicErrorTime = Now; - /* Violate MIC error counts, MIC countermeasures kicks in */ - pAd->StaCfg.MicErrCnt++; - /* We shall block all reception */ - /* We shall clean all Tx ring and disassociate from AP after next EAPOL frame */ - /* */ - /* No necessary to clean all Tx ring, on RTMPHardTransmit will stop sending non-802.1X EAPOL packets */ - /* if pAd->StaCfg.MicErrCnt greater than 2. */ - /* */ - /* RTMPRingCleanUp(pAd, QID_AC_BK); */ - /* RTMPRingCleanUp(pAd, QID_AC_BE); */ - /* RTMPRingCleanUp(pAd, QID_AC_VI); */ - /* RTMPRingCleanUp(pAd, QID_AC_VO); */ - /* RTMPRingCleanUp(pAd, QID_HCCA); */ - } - } else { - /* MIC error count >= 2 */ - /* This should not happen */ - ; - } - MlmeEnqueue(pAd, - MLME_CNTL_STATE_MACHINE, - OID_802_11_MIC_FAILURE_REPORT_FRAME, 1, &unicastKey); - - if (pAd->StaCfg.MicErrCnt == 2) { - RTMPSetTimer(&pAd->StaCfg.WpaDisassocAndBlockAssocTimer, 100); - } -} - -#define LENGTH_EAP_H 4 -/* If the received frame is EAP-Packet ,find out its EAP-Code (Request(0x01), Response(0x02), Success(0x03), Failure(0x04)). */ -int WpaCheckEapCode(struct rt_rtmp_adapter *pAd, - u8 *pFrame, u16 FrameLen, u16 OffSet) -{ - - u8 *pData; - int result = 0; - - if (FrameLen < OffSet + LENGTH_EAPOL_H + LENGTH_EAP_H) - return result; - - pData = pFrame + OffSet; /* skip offset bytes */ - - if (*(pData + 1) == EAPPacket) /* 802.1x header - Packet Type */ - { - result = *(pData + 4); /* EAP header - Code */ - } - - return result; -} - -void WpaSendMicFailureToWpaSupplicant(struct rt_rtmp_adapter *pAd, IN BOOLEAN bUnicast) -{ - char custom[IW_CUSTOM_MAX] = { 0 }; - - sprintf(custom, "MLME-MICHAELMICFAILURE.indication"); - if (bUnicast) - sprintf(custom, "%s unicast", custom); - - RtmpOSWrielessEventSend(pAd, IWEVCUSTOM, -1, NULL, (u8 *)custom, - strlen(custom)); - - return; -} - -void WpaMicFailureReportFrame(struct rt_rtmp_adapter *pAd, struct rt_mlme_queue_elem *Elem) -{ - u8 *pOutBuffer = NULL; - u8 Header802_3[14]; - unsigned long FrameLen = 0; - struct rt_eapol_packet Packet; - u8 Mic[16]; - BOOLEAN bUnicast; - - DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame ----->\n")); - - bUnicast = (Elem->Msg[0] == 1 ? TRUE : FALSE); - pAd->Sequence = ((pAd->Sequence) + 1) & (MAX_SEQ_NUMBER); - - /* init 802.3 header and Fill Packet */ - MAKE_802_3_HEADER(Header802_3, pAd->CommonCfg.Bssid, - pAd->CurrentAddress, EAPOL); - - NdisZeroMemory(&Packet, sizeof(Packet)); - Packet.ProVer = EAPOL_VER; - Packet.ProType = EAPOLKey; - - Packet.KeyDesc.Type = WPA1_KEY_DESC; - - /* Request field presented */ - Packet.KeyDesc.KeyInfo.Request = 1; - - if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled) { - Packet.KeyDesc.KeyInfo.KeyDescVer = 2; - } else /* TKIP */ - { - Packet.KeyDesc.KeyInfo.KeyDescVer = 1; - } - - Packet.KeyDesc.KeyInfo.KeyType = (bUnicast ? PAIRWISEKEY : GROUPKEY); - - /* KeyMic field presented */ - Packet.KeyDesc.KeyInfo.KeyMic = 1; - - /* Error field presented */ - Packet.KeyDesc.KeyInfo.Error = 1; - - /* Update packet length after decide Key data payload */ - SET_u16_TO_ARRARY(Packet.Body_Len, LEN_EAPOL_KEY_MSG) - /* Key Replay Count */ - NdisMoveMemory(Packet.KeyDesc.ReplayCounter, - pAd->StaCfg.ReplayCounter, LEN_KEY_DESC_REPLAY); - inc_byte_array(pAd->StaCfg.ReplayCounter, 8); - - /* Convert to little-endian format. */ - *((u16 *) & Packet.KeyDesc.KeyInfo) = - cpu2le16(*((u16 *) & Packet.KeyDesc.KeyInfo)); - - MlmeAllocateMemory(pAd, (u8 **) & pOutBuffer); /* allocate memory */ - if (pOutBuffer == NULL) { - return; - } - /* Prepare EAPOL frame for MIC calculation */ - /* Be careful, only EAPOL frame is counted for MIC calculation */ - MakeOutgoingFrame(pOutBuffer, &FrameLen, - CONV_ARRARY_TO_u16(Packet.Body_Len) + 4, &Packet, - END_OF_ARGS); - - /* Prepare and Fill MIC value */ - NdisZeroMemory(Mic, sizeof(Mic)); - if (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled) { /* AES */ - u8 digest[20] = { 0 }; - HMAC_SHA1(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, - digest, SHA1_DIGEST_SIZE); - NdisMoveMemory(Mic, digest, LEN_KEY_DESC_MIC); - } else { /* TKIP */ - HMAC_MD5(pAd->StaCfg.PTK, LEN_EAP_MICK, pOutBuffer, FrameLen, - Mic, MD5_DIGEST_SIZE); - } - NdisMoveMemory(Packet.KeyDesc.KeyMic, Mic, LEN_KEY_DESC_MIC); - - /* copy frame to Tx ring and send MIC failure report frame to authenticator */ - RTMPToWirelessSta(pAd, &pAd->MacTab.Content[BSSID_WCID], - Header802_3, LENGTH_802_3, - (u8 *)& Packet, - CONV_ARRARY_TO_u16(Packet.Body_Len) + 4, FALSE); - - MlmeFreeMemory(pAd, (u8 *)pOutBuffer); - - DBGPRINT(RT_DEBUG_TRACE, ("WpaMicFailureReportFrame <-----\n")); -} - -/** from wpa_supplicant - * inc_byte_array - Increment arbitrary length byte array by one - * @counter: Pointer to byte array - * @len: Length of the counter in bytes - * - * This function increments the last byte of the counter by one and continues - * rolling over to more significant bytes if the byte was incremented from - * 0xff to 0x00. - */ -void inc_byte_array(u8 * counter, int len) -{ - int pos = len - 1; - while (pos >= 0) { - counter[pos]++; - if (counter[pos] != 0) - break; - pos--; - } -} - -void WpaDisassocApAndBlockAssoc(void *SystemSpecific1, - void *FunctionContext, - void *SystemSpecific2, - void *SystemSpecific3) -{ - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)FunctionContext; - struct rt_mlme_disassoc_req DisassocReq; - - /* disassoc from current AP first */ - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPReportMicError - disassociate with current AP after sending second continuous EAPOL frame\n")); - DisassocParmFill(pAd, &DisassocReq, pAd->CommonCfg.Bssid, - REASON_MIC_FAILURE); - MlmeEnqueue(pAd, ASSOC_STATE_MACHINE, MT2_MLME_DISASSOC_REQ, - sizeof(struct rt_mlme_disassoc_req), &DisassocReq); - - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_DISASSOC; - pAd->StaCfg.bBlockAssoc = TRUE; -} - -void WpaStaPairwiseKeySetting(struct rt_rtmp_adapter *pAd) -{ - struct rt_cipher_key *pSharedKey; - struct rt_mac_table_entry *pEntry; - - pEntry = &pAd->MacTab.Content[BSSID_WCID]; - - /* Pairwise key shall use key#0 */ - pSharedKey = &pAd->SharedKey[BSS0][0]; - - NdisMoveMemory(pAd->StaCfg.PTK, pEntry->PTK, LEN_PTK); - - /* Prepare pair-wise key information into shared key table */ - NdisZeroMemory(pSharedKey, sizeof(struct rt_cipher_key)); - pSharedKey->KeyLen = LEN_TKIP_EK; - NdisMoveMemory(pSharedKey->Key, &pAd->StaCfg.PTK[32], LEN_TKIP_EK); - NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.PTK[48], - LEN_TKIP_RXMICK); - NdisMoveMemory(pSharedKey->TxMic, - &pAd->StaCfg.PTK[48 + LEN_TKIP_RXMICK], LEN_TKIP_TXMICK); - - /* Decide its ChiperAlg */ - if (pAd->StaCfg.PairCipher == Ndis802_11Encryption2Enabled) - pSharedKey->CipherAlg = CIPHER_TKIP; - else if (pAd->StaCfg.PairCipher == Ndis802_11Encryption3Enabled) - pSharedKey->CipherAlg = CIPHER_AES; - else - pSharedKey->CipherAlg = CIPHER_NONE; - - /* Update these related information to struct rt_mac_table_entry */ - NdisMoveMemory(pEntry->PairwiseKey.Key, &pAd->StaCfg.PTK[32], - LEN_TKIP_EK); - NdisMoveMemory(pEntry->PairwiseKey.RxMic, &pAd->StaCfg.PTK[48], - LEN_TKIP_RXMICK); - NdisMoveMemory(pEntry->PairwiseKey.TxMic, - &pAd->StaCfg.PTK[48 + LEN_TKIP_RXMICK], LEN_TKIP_TXMICK); - pEntry->PairwiseKey.CipherAlg = pSharedKey->CipherAlg; - - /* Update pairwise key information to ASIC Shared Key Table */ - AsicAddSharedKeyEntry(pAd, - BSS0, - 0, - pSharedKey->CipherAlg, - pSharedKey->Key, - pSharedKey->TxMic, pSharedKey->RxMic); - - /* Update ASIC WCID attribute table and IVEIV table */ - RTMPAddWcidAttributeEntry(pAd, BSS0, 0, pSharedKey->CipherAlg, pEntry); - STA_PORT_SECURED(pAd); - pAd->IndicateMediaState = NdisMediaStateConnected; - - DBGPRINT(RT_DEBUG_TRACE, - ("%s : AID(%d) port secured\n", __func__, pEntry->Aid)); - -} - -void WpaStaGroupKeySetting(struct rt_rtmp_adapter *pAd) -{ - struct rt_cipher_key *pSharedKey; - - pSharedKey = &pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId]; - - /* Prepare pair-wise key information into shared key table */ - NdisZeroMemory(pSharedKey, sizeof(struct rt_cipher_key)); - pSharedKey->KeyLen = LEN_TKIP_EK; - NdisMoveMemory(pSharedKey->Key, pAd->StaCfg.GTK, LEN_TKIP_EK); - NdisMoveMemory(pSharedKey->RxMic, &pAd->StaCfg.GTK[16], - LEN_TKIP_RXMICK); - NdisMoveMemory(pSharedKey->TxMic, &pAd->StaCfg.GTK[24], - LEN_TKIP_TXMICK); - - /* Update Shared Key CipherAlg */ - pSharedKey->CipherAlg = CIPHER_NONE; - if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption2Enabled) - pSharedKey->CipherAlg = CIPHER_TKIP; - else if (pAd->StaCfg.GroupCipher == Ndis802_11Encryption3Enabled) - pSharedKey->CipherAlg = CIPHER_AES; - else if (pAd->StaCfg.GroupCipher == Ndis802_11GroupWEP40Enabled) - pSharedKey->CipherAlg = CIPHER_WEP64; - else if (pAd->StaCfg.GroupCipher == Ndis802_11GroupWEP104Enabled) - pSharedKey->CipherAlg = CIPHER_WEP128; - - /* Update group key information to ASIC Shared Key Table */ - AsicAddSharedKeyEntry(pAd, - BSS0, - pAd->StaCfg.DefaultKeyId, - pSharedKey->CipherAlg, - pSharedKey->Key, - pSharedKey->TxMic, pSharedKey->RxMic); - - /* Update ASIC WCID attribute table and IVEIV table */ - RTMPAddWcidAttributeEntry(pAd, - BSS0, - pAd->StaCfg.DefaultKeyId, - pSharedKey->CipherAlg, NULL); - -} diff --git a/trunk/drivers/staging/rt2860/sta_ioctl.c b/trunk/drivers/staging/rt2860/sta_ioctl.c deleted file mode 100644 index 49b1013e7a03..000000000000 --- a/trunk/drivers/staging/rt2860/sta_ioctl.c +++ /dev/null @@ -1,2912 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - sta_ioctl.c - - Abstract: - IOCTL related subroutines - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Rory Chen 01-03-2003 created - Rory Chen 02-14-2005 modify to support RT61 - Justin P. Mattock 11/07/2010 Fix typos -*/ - -#include "rt_config.h" - -#ifdef DBG -extern unsigned long RTDebugLevel; -#endif - -#define NR_WEP_KEYS 4 -#define WEP_SMALL_KEY_LEN (40/8) -#define WEP_LARGE_KEY_LEN (104/8) - -#define GROUP_KEY_NO 4 - -extern u8 CipherWpa2Template[]; - -struct PACKED rt_version_info { - u8 DriverVersionW; - u8 DriverVersionX; - u8 DriverVersionY; - u8 DriverVersionZ; - u32 DriverBuildYear; - u32 DriverBuildMonth; - u32 DriverBuildDay; -}; - -static __s32 ralinkrate[] = { 2, 4, 11, 22, /* CCK */ - 12, 18, 24, 36, 48, 72, 96, 108, /* OFDM */ - 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, /* 20MHz, 800ns GI, MCS: 0 ~ 15 */ - 39, 78, 117, 156, 234, 312, 351, 390, /* 20MHz, 800ns GI, MCS: 16 ~ 23 */ - 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, /* 40MHz, 800ns GI, MCS: 0 ~ 15 */ - 81, 162, 243, 324, 486, 648, 729, 810, /* 40MHz, 800ns GI, MCS: 16 ~ 23 */ - 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, /* 20MHz, 400ns GI, MCS: 0 ~ 15 */ - 43, 87, 130, 173, 260, 317, 390, 433, /* 20MHz, 400ns GI, MCS: 16 ~ 23 */ - 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, /* 40MHz, 400ns GI, MCS: 0 ~ 15 */ - 90, 180, 270, 360, 540, 720, 810, 900 -}; - -int Set_SSID_Proc(struct rt_rtmp_adapter *pAdapter, char *arg); - -int Set_NetworkType_Proc(struct rt_rtmp_adapter *pAdapter, char *arg); - -void RTMPAddKey(struct rt_rtmp_adapter *pAd, struct rt_ndis_802_11_key *pKey) -{ - unsigned long KeyIdx; - struct rt_mac_table_entry *pEntry; - - DBGPRINT(RT_DEBUG_TRACE, ("RTMPAddKey ------>\n")); - - if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA) { - if (pKey->KeyIndex & 0x80000000) { - if (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPANone) { - NdisZeroMemory(pAd->StaCfg.PMK, 32); - NdisMoveMemory(pAd->StaCfg.PMK, - pKey->KeyMaterial, - pKey->KeyLength); - goto end; - } - /* Update PTK */ - NdisZeroMemory(&pAd->SharedKey[BSS0][0], - sizeof(struct rt_cipher_key)); - pAd->SharedKey[BSS0][0].KeyLen = LEN_TKIP_EK; - NdisMoveMemory(pAd->SharedKey[BSS0][0].Key, - pKey->KeyMaterial, LEN_TKIP_EK); - - if (pAd->StaCfg.PairCipher == - Ndis802_11Encryption2Enabled) { - NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, - pKey->KeyMaterial + LEN_TKIP_EK, - LEN_TKIP_TXMICK); - NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, - pKey->KeyMaterial + LEN_TKIP_EK + - LEN_TKIP_TXMICK, - LEN_TKIP_RXMICK); - } else { - NdisMoveMemory(pAd->SharedKey[BSS0][0].TxMic, - pKey->KeyMaterial + LEN_TKIP_EK, - LEN_TKIP_TXMICK); - NdisMoveMemory(pAd->SharedKey[BSS0][0].RxMic, - pKey->KeyMaterial + LEN_TKIP_EK + - LEN_TKIP_TXMICK, - LEN_TKIP_RXMICK); - } - - /* Decide its ChiperAlg */ - if (pAd->StaCfg.PairCipher == - Ndis802_11Encryption2Enabled) - pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_TKIP; - else if (pAd->StaCfg.PairCipher == - Ndis802_11Encryption3Enabled) - pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_AES; - else - pAd->SharedKey[BSS0][0].CipherAlg = CIPHER_NONE; - - /* Update these related information to struct rt_mac_table_entry */ - pEntry = &pAd->MacTab.Content[BSSID_WCID]; - NdisMoveMemory(pEntry->PairwiseKey.Key, - pAd->SharedKey[BSS0][0].Key, - LEN_TKIP_EK); - NdisMoveMemory(pEntry->PairwiseKey.RxMic, - pAd->SharedKey[BSS0][0].RxMic, - LEN_TKIP_RXMICK); - NdisMoveMemory(pEntry->PairwiseKey.TxMic, - pAd->SharedKey[BSS0][0].TxMic, - LEN_TKIP_TXMICK); - pEntry->PairwiseKey.CipherAlg = - pAd->SharedKey[BSS0][0].CipherAlg; - - /* Update pairwise key information to ASIC Shared Key Table */ - AsicAddSharedKeyEntry(pAd, - BSS0, - 0, - pAd->SharedKey[BSS0][0].CipherAlg, - pAd->SharedKey[BSS0][0].Key, - pAd->SharedKey[BSS0][0].TxMic, - pAd->SharedKey[BSS0][0].RxMic); - - /* Update ASIC WCID attribute table and IVEIV table */ - RTMPAddWcidAttributeEntry(pAd, - BSS0, - 0, - pAd->SharedKey[BSS0][0]. - CipherAlg, pEntry); - - if (pAd->StaCfg.AuthMode >= Ndis802_11AuthModeWPA2) { - /* set 802.1x port control */ - /*pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ - STA_PORT_SECURED(pAd); - - /* Indicate Connected for GUI */ - pAd->IndicateMediaState = - NdisMediaStateConnected; - } - } else { - /* Update GTK */ - pAd->StaCfg.DefaultKeyId = (pKey->KeyIndex & 0xFF); - NdisZeroMemory(&pAd-> - SharedKey[BSS0][pAd->StaCfg. - DefaultKeyId], - sizeof(struct rt_cipher_key)); - pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId].KeyLen = - LEN_TKIP_EK; - NdisMoveMemory(pAd-> - SharedKey[BSS0][pAd->StaCfg. - DefaultKeyId].Key, - pKey->KeyMaterial, LEN_TKIP_EK); - - if (pAd->StaCfg.GroupCipher == - Ndis802_11Encryption2Enabled) { - NdisMoveMemory(pAd-> - SharedKey[BSS0][pAd->StaCfg. - DefaultKeyId]. - RxMic, - pKey->KeyMaterial + LEN_TKIP_EK, - LEN_TKIP_TXMICK); - NdisMoveMemory(pAd-> - SharedKey[BSS0][pAd->StaCfg. - DefaultKeyId]. - TxMic, - pKey->KeyMaterial + LEN_TKIP_EK + - LEN_TKIP_TXMICK, - LEN_TKIP_RXMICK); - } else { - NdisMoveMemory(pAd-> - SharedKey[BSS0][pAd->StaCfg. - DefaultKeyId]. - TxMic, - pKey->KeyMaterial + LEN_TKIP_EK, - LEN_TKIP_TXMICK); - NdisMoveMemory(pAd-> - SharedKey[BSS0][pAd->StaCfg. - DefaultKeyId]. - RxMic, - pKey->KeyMaterial + LEN_TKIP_EK + - LEN_TKIP_TXMICK, - LEN_TKIP_RXMICK); - } - - /* Update Shared Key CipherAlg */ - pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId]. - CipherAlg = CIPHER_NONE; - if (pAd->StaCfg.GroupCipher == - Ndis802_11Encryption2Enabled) - pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId]. - CipherAlg = CIPHER_TKIP; - else if (pAd->StaCfg.GroupCipher == - Ndis802_11Encryption3Enabled) - pAd->SharedKey[BSS0][pAd->StaCfg.DefaultKeyId]. - CipherAlg = CIPHER_AES; - - /* Update group key information to ASIC Shared Key Table */ - AsicAddSharedKeyEntry(pAd, - BSS0, - pAd->StaCfg.DefaultKeyId, - pAd->SharedKey[BSS0][pAd->StaCfg. - DefaultKeyId]. - CipherAlg, - pAd->SharedKey[BSS0][pAd->StaCfg. - DefaultKeyId]. - Key, - pAd->SharedKey[BSS0][pAd->StaCfg. - DefaultKeyId]. - TxMic, - pAd->SharedKey[BSS0][pAd->StaCfg. - DefaultKeyId]. - RxMic); - - /* Update ASIC WCID attribute table and IVEIV table */ - RTMPAddWcidAttributeEntry(pAd, - BSS0, - pAd->StaCfg.DefaultKeyId, - pAd->SharedKey[BSS0][pAd-> - StaCfg. - DefaultKeyId]. - CipherAlg, NULL); - - /* set 802.1x port control */ - /*pAd->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ - STA_PORT_SECURED(pAd); - - /* Indicate Connected for GUI */ - pAd->IndicateMediaState = NdisMediaStateConnected; - } - } else /* dynamic WEP from wpa_supplicant */ - { - u8 CipherAlg; - u8 *Key; - - if (pKey->KeyLength == 32) - goto end; - - KeyIdx = pKey->KeyIndex & 0x0fffffff; - - if (KeyIdx < 4) { - /* it is a default shared key, for Pairwise key setting */ - if (pKey->KeyIndex & 0x80000000) { - pEntry = MacTableLookup(pAd, pKey->BSSID); - - if (pEntry) { - DBGPRINT(RT_DEBUG_TRACE, - ("RTMPAddKey: Set Pair-wise Key\n")); - - /* set key material and key length */ - pEntry->PairwiseKey.KeyLen = - (u8)pKey->KeyLength; - NdisMoveMemory(pEntry->PairwiseKey.Key, - &pKey->KeyMaterial, - pKey->KeyLength); - - /* set Cipher type */ - if (pKey->KeyLength == 5) - pEntry->PairwiseKey.CipherAlg = - CIPHER_WEP64; - else - pEntry->PairwiseKey.CipherAlg = - CIPHER_WEP128; - - /* Add Pair-wise key to Asic */ - AsicAddPairwiseKeyEntry(pAd, - pEntry->Addr, - (u8)pEntry-> - Aid, - &pEntry-> - PairwiseKey); - - /* update WCID attribute table and IVEIV table for this entry */ - RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, /* The value may be not zero */ - pEntry-> - PairwiseKey. - CipherAlg, - pEntry); - - } - } else { - /* Default key for tx (shared key) */ - pAd->StaCfg.DefaultKeyId = (u8)KeyIdx; - - /* set key material and key length */ - pAd->SharedKey[BSS0][KeyIdx].KeyLen = - (u8)pKey->KeyLength; - NdisMoveMemory(pAd->SharedKey[BSS0][KeyIdx].Key, - &pKey->KeyMaterial, - pKey->KeyLength); - - /* Set Ciper type */ - if (pKey->KeyLength == 5) - pAd->SharedKey[BSS0][KeyIdx].CipherAlg = - CIPHER_WEP64; - else - pAd->SharedKey[BSS0][KeyIdx].CipherAlg = - CIPHER_WEP128; - - CipherAlg = - pAd->SharedKey[BSS0][KeyIdx].CipherAlg; - Key = pAd->SharedKey[BSS0][KeyIdx].Key; - - /* Set Group key material to Asic */ - AsicAddSharedKeyEntry(pAd, BSS0, KeyIdx, - CipherAlg, Key, NULL, - NULL); - - /* Update WCID attribute table and IVEIV table for this group key table */ - RTMPAddWcidAttributeEntry(pAd, BSS0, KeyIdx, - CipherAlg, NULL); - - } - } - } -end: - return; -} - -char *rtstrchr(const char *s, int c) -{ - for (; *s != (char)c; ++s) - if (*s == '\0') - return NULL; - return (char *)s; -} - -/* -This is required for LinEX2004/kernel2.6.7 to provide iwlist scanning function -*/ - -int -rt_ioctl_giwname(struct net_device *dev, - struct iw_request_info *info, char *name, char *extra) -{ - strncpy(name, "Ralink STA", IFNAMSIZ); - /* RT2870 2.1.0.0 uses "RT2870 Wireless" */ - /* RT3090 2.1.0.0 uses "RT2860 Wireless" */ - return 0; -} - -int rt_ioctl_siwfreq(struct net_device *dev, - struct iw_request_info *info, - struct iw_freq *freq, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - int chan = -1; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - if (freq->e > 1) - return -EINVAL; - - if ((freq->e == 0) && (freq->m <= 1000)) - chan = freq->m; /* Setting by channel number */ - else - MAP_KHZ_TO_CHANNEL_ID((freq->m / 100), chan); /* Setting by frequency - search the table , like 2.412G, 2.422G, */ - - if (ChannelSanity(pAdapter, chan) == TRUE) { - pAdapter->CommonCfg.Channel = chan; - DBGPRINT(RT_DEBUG_ERROR, - ("==>rt_ioctl_siwfreq::SIOCSIWFREQ[cmd=0x%x] (Channel=%d)\n", - SIOCSIWFREQ, pAdapter->CommonCfg.Channel)); - } else - return -EINVAL; - - return 0; -} - -int rt_ioctl_giwfreq(struct net_device *dev, - struct iw_request_info *info, - struct iw_freq *freq, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - u8 ch; - unsigned long m = 2412000; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - ch = pAdapter->CommonCfg.Channel; - - DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwfreq %d\n", ch)); - - MAP_CHANNEL_ID_TO_KHZ(ch, m); - freq->m = m * 100; - freq->e = 1; - return 0; -} - -int rt_ioctl_siwmode(struct net_device *dev, - struct iw_request_info *info, __u32 * mode, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - switch (*mode) { - case IW_MODE_ADHOC: - Set_NetworkType_Proc(pAdapter, "Adhoc"); - break; - case IW_MODE_INFRA: - Set_NetworkType_Proc(pAdapter, "Infra"); - break; - case IW_MODE_MONITOR: - Set_NetworkType_Proc(pAdapter, "Monitor"); - break; - default: - DBGPRINT(RT_DEBUG_TRACE, - ("===>rt_ioctl_siwmode::SIOCSIWMODE (unknown %d)\n", - *mode)); - return -EINVAL; - } - - /* Reset Ralink supplicant to not use, it will be set to start when UI set PMK key */ - pAdapter->StaCfg.WpaState = SS_NOTUSE; - - return 0; -} - -int rt_ioctl_giwmode(struct net_device *dev, - struct iw_request_info *info, __u32 * mode, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - if (ADHOC_ON(pAdapter)) - *mode = IW_MODE_ADHOC; - else if (INFRA_ON(pAdapter)) - *mode = IW_MODE_INFRA; - else if (MONITOR_ON(pAdapter)) { - *mode = IW_MODE_MONITOR; - } else - *mode = IW_MODE_AUTO; - - DBGPRINT(RT_DEBUG_TRACE, ("==>rt_ioctl_giwmode(mode=%d)\n", *mode)); - return 0; -} - -int rt_ioctl_siwsens(struct net_device *dev, - struct iw_request_info *info, char *name, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - return 0; -} - -int rt_ioctl_giwsens(struct net_device *dev, - struct iw_request_info *info, char *name, char *extra) -{ - return 0; -} - -int rt_ioctl_giwrange(struct net_device *dev, - struct iw_request_info *info, - struct iw_point *data, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - struct iw_range *range = (struct iw_range *)extra; - u16 val; - int i; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - DBGPRINT(RT_DEBUG_TRACE, ("===>rt_ioctl_giwrange\n")); - data->length = sizeof(struct iw_range); - memset(range, 0, sizeof(struct iw_range)); - - range->txpower_capa = IW_TXPOW_DBM; - - if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter)) { - range->min_pmp = 1 * 1024; - range->max_pmp = 65535 * 1024; - range->min_pmt = 1 * 1024; - range->max_pmt = 1000 * 1024; - range->pmp_flags = IW_POWER_PERIOD; - range->pmt_flags = IW_POWER_TIMEOUT; - range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | - IW_POWER_UNICAST_R | IW_POWER_ALL_R; - } - - range->we_version_compiled = WIRELESS_EXT; - range->we_version_source = 14; - - range->retry_capa = IW_RETRY_LIMIT; - range->retry_flags = IW_RETRY_LIMIT; - range->min_retry = 0; - range->max_retry = 255; - - range->num_channels = pAdapter->ChannelListNum; - - val = 0; - for (i = 1; i <= range->num_channels; i++) { - u32 m = 2412000; - range->freq[val].i = pAdapter->ChannelList[i - 1].Channel; - MAP_CHANNEL_ID_TO_KHZ(pAdapter->ChannelList[i - 1].Channel, m); - range->freq[val].m = m * 100; /* OS_HZ */ - - range->freq[val].e = 1; - val++; - if (val == IW_MAX_FREQUENCIES) - break; - } - range->num_frequency = val; - - range->max_qual.qual = 100; /* what is correct max? This was not - * documented exactly. At least - * 69 has been observed. */ - range->max_qual.level = 0; /* dB */ - range->max_qual.noise = 0; /* dB */ - - /* What would be suitable values for "average/typical" qual? */ - range->avg_qual.qual = 20; - range->avg_qual.level = -60; - range->avg_qual.noise = -95; - range->sensitivity = 3; - - range->max_encoding_tokens = NR_WEP_KEYS; - range->num_encoding_sizes = 2; - range->encoding_size[0] = 5; - range->encoding_size[1] = 13; - - range->min_rts = 0; - range->max_rts = 2347; - range->min_frag = 256; - range->max_frag = 2346; - - /* IW_ENC_CAPA_* bit field */ - range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 | - IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP; - - return 0; -} - -int rt_ioctl_siwap(struct net_device *dev, - struct iw_request_info *info, - struct sockaddr *ap_addr, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - NDIS_802_11_MAC_ADDRESS Bssid; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) { - RTMP_MLME_RESET_STATE_MACHINE(pAdapter); - DBGPRINT(RT_DEBUG_TRACE, - ("MLME busy, reset MLME state machine!\n")); - } - /* tell CNTL state machine to call NdisMSetInformationComplete() after completing */ - /* this request, because this request is initiated by NDIS. */ - pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE; - /* Prevent to connect AP again in STAMlmePeriodicExec */ - pAdapter->MlmeAux.AutoReconnectSsidLen = 32; - - memcpy(Bssid, ap_addr->sa_data, MAC_ADDR_LEN); - MlmeEnqueue(pAdapter, - MLME_CNTL_STATE_MACHINE, - OID_802_11_BSSID, - sizeof(NDIS_802_11_MAC_ADDRESS), (void *) & Bssid); - - DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCSIWAP %pM\n", Bssid)); - - return 0; -} - -int rt_ioctl_giwap(struct net_device *dev, - struct iw_request_info *info, - struct sockaddr *ap_addr, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - if (INFRA_ON(pAdapter) || ADHOC_ON(pAdapter)) { - ap_addr->sa_family = ARPHRD_ETHER; - memcpy(ap_addr->sa_data, &pAdapter->CommonCfg.Bssid, ETH_ALEN); - } - /* Add for RT2870 */ - else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) { - ap_addr->sa_family = ARPHRD_ETHER; - memcpy(ap_addr->sa_data, &pAdapter->MlmeAux.Bssid, ETH_ALEN); - } else { - DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIWAP(=EMPTY)\n")); - return -ENOTCONN; - } - - return 0; -} - -/* - * Units are in db above the noise floor. That means the - * rssi values reported in the tx/rx descriptors in the - * driver are the SNR expressed in db. - * - * If you assume that the noise floor is -95, which is an - * excellent assumption 99.5 % of the time, then you can - * derive the absolute signal level (i.e. -95 + rssi). - * There are some other slight factors to take into account - * depending on whether the rssi measurement is from 11b, - * 11g, or 11a. These differences are at most 2db and - * can be documented. - * - * NB: various calculations are based on the orinoco/wavelan - * drivers for compatibility - */ -static void set_quality(struct rt_rtmp_adapter *pAdapter, - struct iw_quality *iq, signed char rssi) -{ - __u8 ChannelQuality; - - /* Normalize Rssi */ - if (rssi >= -50) - ChannelQuality = 100; - else if (rssi >= -80) /* between -50 ~ -80dbm */ - ChannelQuality = (__u8) (24 + ((rssi + 80) * 26) / 10); - else if (rssi >= -90) /* between -80 ~ -90dbm */ - ChannelQuality = (__u8) ((rssi + 90) * 26) / 10; - else - ChannelQuality = 0; - - iq->qual = (__u8) ChannelQuality; - - iq->level = (__u8) (rssi); - iq->noise = (pAdapter->BbpWriteLatch[66] > pAdapter->BbpTuning.FalseCcaUpperThreshold) ? ((__u8) pAdapter->BbpTuning.FalseCcaUpperThreshold) : ((__u8) pAdapter->BbpWriteLatch[66]); /* noise level (dBm) */ - iq->noise += 256 - 143; - iq->updated = pAdapter->iw_stats.qual.updated; -} - -int rt_ioctl_iwaplist(struct net_device *dev, - struct iw_request_info *info, - struct iw_point *data, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - struct sockaddr addr[IW_MAX_AP]; - struct iw_quality qual[IW_MAX_AP]; - int i; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - data->length = 0; - return 0; - /*return -ENETDOWN; */ - } - - for (i = 0; i < IW_MAX_AP; i++) { - if (i >= pAdapter->ScanTab.BssNr) - break; - addr[i].sa_family = ARPHRD_ETHER; - memcpy(addr[i].sa_data, &pAdapter->ScanTab.BssEntry[i].Bssid, - MAC_ADDR_LEN); - set_quality(pAdapter, &qual[i], - pAdapter->ScanTab.BssEntry[i].Rssi); - } - data->length = i; - memcpy(extra, &addr, i * sizeof(addr[0])); - data->flags = 1; /* signal quality present (sort of) */ - memcpy(extra + i * sizeof(addr[0]), &qual, i * sizeof(qual[i])); - - return 0; -} - -int rt_ioctl_siwscan(struct net_device *dev, - struct iw_request_info *info, - struct iw_point *data, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - unsigned long Now; - int Status = NDIS_STATUS_SUCCESS; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - if (MONITOR_ON(pAdapter)) { - DBGPRINT(RT_DEBUG_TRACE, - ("Driver is in Monitor Mode now!\n")); - return -EINVAL; - } - - if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) { - pAdapter->StaCfg.WpaSupplicantScanCount++; - } - - pAdapter->StaCfg.bScanReqIsFromWebUI = TRUE; - if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) - return NDIS_STATUS_SUCCESS; - do { - Now = jiffies; - - if ((pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) - && (pAdapter->StaCfg.WpaSupplicantScanCount > 3)) { - DBGPRINT(RT_DEBUG_TRACE, - ("WpaSupplicantScanCount > 3\n")); - Status = NDIS_STATUS_SUCCESS; - break; - } - - if ((OPSTATUS_TEST_FLAG - (pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) - && ((pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeWPA) - || (pAdapter->StaCfg.AuthMode == - Ndis802_11AuthModeWPAPSK)) - && (pAdapter->StaCfg.PortSecured == - WPA_802_1X_PORT_NOT_SECURED)) { - DBGPRINT(RT_DEBUG_TRACE, - ("Link UP, Port Not Secured! ignore this set::OID_802_11_BSSID_LIST_SCAN\n")); - Status = NDIS_STATUS_SUCCESS; - break; - } - - if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) { - RTMP_MLME_RESET_STATE_MACHINE(pAdapter); - DBGPRINT(RT_DEBUG_TRACE, - ("MLME busy, reset MLME state machine!\n")); - } - /* tell CNTL state machine to call NdisMSetInformationComplete() after completing */ - /* this request, because this request is initiated by NDIS. */ - pAdapter->MlmeAux.CurrReqIsFromNdis = FALSE; - /* Reset allowed scan retries */ - pAdapter->StaCfg.ScanCnt = 0; - pAdapter->StaCfg.LastScanTime = Now; - - MlmeEnqueue(pAdapter, - MLME_CNTL_STATE_MACHINE, - OID_802_11_BSSID_LIST_SCAN, 0, NULL); - - Status = NDIS_STATUS_SUCCESS; - RTMP_MLME_HANDLER(pAdapter); - } while (0); - return NDIS_STATUS_SUCCESS; -} - -int rt_ioctl_giwscan(struct net_device *dev, - struct iw_request_info *info, - struct iw_point *data, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - int i = 0; - char *current_ev = extra, *previous_ev = extra; - char *end_buf; - char *current_val; - char custom[MAX_CUSTOM_LEN] = { 0 }; - struct iw_event iwe; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - if (RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) { - /* - * Still scanning, indicate the caller should try again. - */ - return -EAGAIN; - } - - if (pAdapter->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) { - pAdapter->StaCfg.WpaSupplicantScanCount = 0; - } - - if (pAdapter->ScanTab.BssNr == 0) { - data->length = 0; - return 0; - } - - if (data->length > 0) - end_buf = extra + data->length; - else - end_buf = extra + IW_SCAN_MAX_DATA; - - for (i = 0; i < pAdapter->ScanTab.BssNr; i++) { - if (current_ev >= end_buf) { - return -E2BIG; - } - /*MAC address */ - /*================================ */ - memset(&iwe, 0, sizeof(iwe)); - iwe.cmd = SIOCGIWAP; - iwe.u.ap_addr.sa_family = ARPHRD_ETHER; - memcpy(iwe.u.ap_addr.sa_data, - &pAdapter->ScanTab.BssEntry[i].Bssid, ETH_ALEN); - - previous_ev = current_ev; - current_ev = - iwe_stream_add_event(info, current_ev, end_buf, &iwe, - IW_EV_ADDR_LEN); - if (current_ev == previous_ev) - return -E2BIG; - - /* - Protocol: - it will show scanned AP's WirelessMode. - it might be - 802.11a - 802.11a/n - 802.11g/n - 802.11b/g/n - 802.11g - 802.11b/g - */ - memset(&iwe, 0, sizeof(iwe)); - iwe.cmd = SIOCGIWNAME; - - { - struct rt_bss_entry *pBssEntry = &pAdapter->ScanTab.BssEntry[i]; - BOOLEAN isGonly = FALSE; - int rateCnt = 0; - - if (pBssEntry->Channel > 14) { - if (pBssEntry->HtCapabilityLen != 0) - strcpy(iwe.u.name, "802.11a/n"); - else - strcpy(iwe.u.name, "802.11a"); - } else { - /* - if one of non B mode rate is set supported rate, it means G only. - */ - for (rateCnt = 0; - rateCnt < pBssEntry->SupRateLen; - rateCnt++) { - /* - 6Mbps(140) 9Mbps(146) and >=12Mbps(152) are supported rate, it means G only. - */ - if (pBssEntry->SupRate[rateCnt] == 140 - || pBssEntry->SupRate[rateCnt] == - 146 - || pBssEntry->SupRate[rateCnt] >= - 152) - isGonly = TRUE; - } - - for (rateCnt = 0; - rateCnt < pBssEntry->ExtRateLen; - rateCnt++) { - if (pBssEntry->ExtRate[rateCnt] == 140 - || pBssEntry->ExtRate[rateCnt] == - 146 - || pBssEntry->ExtRate[rateCnt] >= - 152) - isGonly = TRUE; - } - - if (pBssEntry->HtCapabilityLen != 0) { - if (isGonly == TRUE) - strcpy(iwe.u.name, "802.11g/n"); - else - strcpy(iwe.u.name, - "802.11b/g/n"); - } else { - if (isGonly == TRUE) - strcpy(iwe.u.name, "802.11g"); - else { - if (pBssEntry->SupRateLen == 4 - && pBssEntry->ExtRateLen == - 0) - strcpy(iwe.u.name, - "802.11b"); - else - strcpy(iwe.u.name, - "802.11b/g"); - } - } - } - } - - previous_ev = current_ev; - current_ev = - iwe_stream_add_event(info, current_ev, end_buf, &iwe, - IW_EV_ADDR_LEN); - if (current_ev == previous_ev) - return -E2BIG; - - /*ESSID */ - /*================================ */ - memset(&iwe, 0, sizeof(iwe)); - iwe.cmd = SIOCGIWESSID; - iwe.u.data.length = pAdapter->ScanTab.BssEntry[i].SsidLen; - iwe.u.data.flags = 1; - - previous_ev = current_ev; - current_ev = - iwe_stream_add_point(info, current_ev, end_buf, &iwe, - (char *)pAdapter->ScanTab. - BssEntry[i].Ssid); - if (current_ev == previous_ev) - return -E2BIG; - - /*Network Type */ - /*================================ */ - memset(&iwe, 0, sizeof(iwe)); - iwe.cmd = SIOCGIWMODE; - if (pAdapter->ScanTab.BssEntry[i].BssType == Ndis802_11IBSS) { - iwe.u.mode = IW_MODE_ADHOC; - } else if (pAdapter->ScanTab.BssEntry[i].BssType == - Ndis802_11Infrastructure) { - iwe.u.mode = IW_MODE_INFRA; - } else { - iwe.u.mode = IW_MODE_AUTO; - } - iwe.len = IW_EV_UINT_LEN; - - previous_ev = current_ev; - current_ev = - iwe_stream_add_event(info, current_ev, end_buf, &iwe, - IW_EV_UINT_LEN); - if (current_ev == previous_ev) - return -E2BIG; - - /*Channel and Frequency */ - /*================================ */ - memset(&iwe, 0, sizeof(iwe)); - iwe.cmd = SIOCGIWFREQ; - iwe.u.freq.m = pAdapter->ScanTab.BssEntry[i].Channel; - iwe.u.freq.e = 0; - iwe.u.freq.i = 0; - - previous_ev = current_ev; - current_ev = - iwe_stream_add_event(info, current_ev, end_buf, &iwe, - IW_EV_FREQ_LEN); - if (current_ev == previous_ev) - return -E2BIG; - - /*Add quality statistics */ - /*================================ */ - memset(&iwe, 0, sizeof(iwe)); - iwe.cmd = IWEVQUAL; - iwe.u.qual.level = 0; - iwe.u.qual.noise = 0; - set_quality(pAdapter, &iwe.u.qual, - pAdapter->ScanTab.BssEntry[i].Rssi); - current_ev = - iwe_stream_add_event(info, current_ev, end_buf, &iwe, - IW_EV_QUAL_LEN); - if (current_ev == previous_ev) - return -E2BIG; - - /*Encyption key */ - /*================================ */ - memset(&iwe, 0, sizeof(iwe)); - iwe.cmd = SIOCGIWENCODE; - if (CAP_IS_PRIVACY_ON - (pAdapter->ScanTab.BssEntry[i].CapabilityInfo)) - iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY; - else - iwe.u.data.flags = IW_ENCODE_DISABLED; - - previous_ev = current_ev; - current_ev = - iwe_stream_add_point(info, current_ev, end_buf, &iwe, - (char *)pAdapter-> - SharedKey[BSS0][(iwe.u.data. - flags & - IW_ENCODE_INDEX) - - 1].Key); - if (current_ev == previous_ev) - return -E2BIG; - - /*Bit Rate */ - /*================================ */ - if (pAdapter->ScanTab.BssEntry[i].SupRateLen) { - u8 tmpRate = - pAdapter->ScanTab.BssEntry[i].SupRate[pAdapter-> - ScanTab. - BssEntry[i]. - SupRateLen - - 1]; - memset(&iwe, 0, sizeof(iwe)); - iwe.cmd = SIOCGIWRATE; - current_val = current_ev + IW_EV_LCP_LEN; - if (tmpRate == 0x82) - iwe.u.bitrate.value = 1 * 1000000; - else if (tmpRate == 0x84) - iwe.u.bitrate.value = 2 * 1000000; - else if (tmpRate == 0x8B) - iwe.u.bitrate.value = 5.5 * 1000000; - else if (tmpRate == 0x96) - iwe.u.bitrate.value = 11 * 1000000; - else - iwe.u.bitrate.value = (tmpRate / 2) * 1000000; - - if (tmpRate == 0x6c - && pAdapter->ScanTab.BssEntry[i].HtCapabilityLen > - 0) { - int rate_count = ARRAY_SIZE(ralinkrate); - struct rt_ht_cap_info capInfo = - pAdapter->ScanTab.BssEntry[i].HtCapability. - HtCapInfo; - int shortGI = - capInfo.ChannelWidth ? capInfo. - ShortGIfor40 : capInfo.ShortGIfor20; - int maxMCS = - pAdapter->ScanTab.BssEntry[i].HtCapability. - MCSSet[1] ? 15 : 7; - int rate_index = - 12 + ((u8)capInfo.ChannelWidth * 24) + - ((u8)shortGI * 48) + ((u8)maxMCS); - - if (rate_index < 0) - rate_index = 0; - if (rate_index >= rate_count) - rate_index = rate_count - 1; - iwe.u.bitrate.value = - ralinkrate[rate_index] * 500000; - } - - iwe.u.bitrate.disabled = 0; - current_val = iwe_stream_add_value(info, current_ev, - current_val, end_buf, - &iwe, - IW_EV_PARAM_LEN); - - if ((current_val - current_ev) > IW_EV_LCP_LEN) - current_ev = current_val; - else - return -E2BIG; - } - /*WPA IE */ - if (pAdapter->ScanTab.BssEntry[i].WpaIE.IELen > 0) { - memset(&iwe, 0, sizeof(iwe)); - memset(&custom[0], 0, MAX_CUSTOM_LEN); - memcpy(custom, - &(pAdapter->ScanTab.BssEntry[i].WpaIE.IE[0]), - pAdapter->ScanTab.BssEntry[i].WpaIE.IELen); - iwe.cmd = IWEVGENIE; - iwe.u.data.length = - pAdapter->ScanTab.BssEntry[i].WpaIE.IELen; - current_ev = - iwe_stream_add_point(info, current_ev, end_buf, - &iwe, custom); - if (current_ev == previous_ev) - return -E2BIG; - } - /*WPA2 IE */ - if (pAdapter->ScanTab.BssEntry[i].RsnIE.IELen > 0) { - memset(&iwe, 0, sizeof(iwe)); - memset(&custom[0], 0, MAX_CUSTOM_LEN); - memcpy(custom, - &(pAdapter->ScanTab.BssEntry[i].RsnIE.IE[0]), - pAdapter->ScanTab.BssEntry[i].RsnIE.IELen); - iwe.cmd = IWEVGENIE; - iwe.u.data.length = - pAdapter->ScanTab.BssEntry[i].RsnIE.IELen; - current_ev = - iwe_stream_add_point(info, current_ev, end_buf, - &iwe, custom); - if (current_ev == previous_ev) - return -E2BIG; - } - } - - data->length = current_ev - extra; - pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE; - DBGPRINT(RT_DEBUG_ERROR, - ("===>rt_ioctl_giwscan. %d(%d) BSS returned, data->length = %d\n", - i, pAdapter->ScanTab.BssNr, data->length)); - return 0; -} - -int rt_ioctl_siwessid(struct net_device *dev, - struct iw_request_info *info, - struct iw_point *data, char *essid) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - if (data->flags) { - char *pSsidString = NULL; - - /* Includes null character. */ - if (data->length > (IW_ESSID_MAX_SIZE + 1)) - return -E2BIG; - - pSsidString = kmalloc(MAX_LEN_OF_SSID + 1, MEM_ALLOC_FLAG); - if (pSsidString) { - NdisZeroMemory(pSsidString, MAX_LEN_OF_SSID + 1); - NdisMoveMemory(pSsidString, essid, data->length); - if (Set_SSID_Proc(pAdapter, pSsidString) == FALSE) - return -EINVAL; - } else - return -ENOMEM; - } else { - /* ANY ssid */ - if (Set_SSID_Proc(pAdapter, "") == FALSE) - return -EINVAL; - } - return 0; -} - -int rt_ioctl_giwessid(struct net_device *dev, - struct iw_request_info *info, - struct iw_point *data, char *essid) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - data->flags = 1; - if (MONITOR_ON(pAdapter)) { - data->length = 0; - return 0; - } - - if (OPSTATUS_TEST_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED)) { - DBGPRINT(RT_DEBUG_TRACE, ("MediaState is connected\n")); - data->length = pAdapter->CommonCfg.SsidLen; - memcpy(essid, pAdapter->CommonCfg.Ssid, - pAdapter->CommonCfg.SsidLen); - } -#ifdef RTMP_MAC_USB - /* Add for RT2870 */ - else if (pAdapter->StaCfg.WpaSupplicantUP != WPA_SUPPLICANT_DISABLE) { - data->length = pAdapter->CommonCfg.SsidLen; - memcpy(essid, pAdapter->CommonCfg.Ssid, - pAdapter->CommonCfg.SsidLen); - } -#endif /* RTMP_MAC_USB // */ - else { /*the ANY ssid was specified */ - data->length = 0; - DBGPRINT(RT_DEBUG_TRACE, - ("MediaState is not connected, ess\n")); - } - - return 0; - -} - -int rt_ioctl_siwnickn(struct net_device *dev, - struct iw_request_info *info, - struct iw_point *data, char *nickname) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - if (data->length > IW_ESSID_MAX_SIZE) - return -EINVAL; - - memset(pAdapter->nickname, 0, IW_ESSID_MAX_SIZE + 1); - memcpy(pAdapter->nickname, nickname, data->length); - - return 0; -} - -int rt_ioctl_giwnickn(struct net_device *dev, - struct iw_request_info *info, - struct iw_point *data, char *nickname) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - if (data->length > strlen((char *)pAdapter->nickname) + 1) - data->length = strlen((char *)pAdapter->nickname) + 1; - if (data->length > 0) { - memcpy(nickname, pAdapter->nickname, data->length - 1); - nickname[data->length - 1] = '\0'; - } - return 0; -} - -int rt_ioctl_siwrts(struct net_device *dev, - struct iw_request_info *info, - struct iw_param *rts, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - u16 val; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - if (rts->disabled) - val = MAX_RTS_THRESHOLD; - else if (rts->value < 0 || rts->value > MAX_RTS_THRESHOLD) - return -EINVAL; - else if (rts->value == 0) - val = MAX_RTS_THRESHOLD; - else - val = rts->value; - - if (val != pAdapter->CommonCfg.RtsThreshold) - pAdapter->CommonCfg.RtsThreshold = val; - - return 0; -} - -int rt_ioctl_giwrts(struct net_device *dev, - struct iw_request_info *info, - struct iw_param *rts, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - rts->value = pAdapter->CommonCfg.RtsThreshold; - rts->disabled = (rts->value == MAX_RTS_THRESHOLD); - rts->fixed = 1; - - return 0; -} - -int rt_ioctl_siwfrag(struct net_device *dev, - struct iw_request_info *info, - struct iw_param *frag, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - u16 val; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - if (frag->disabled) - val = MAX_FRAG_THRESHOLD; - else if (frag->value >= MIN_FRAG_THRESHOLD - && frag->value <= MAX_FRAG_THRESHOLD) - val = __cpu_to_le16(frag->value & ~0x1); /* even numbers only */ - else if (frag->value == 0) - val = MAX_FRAG_THRESHOLD; - else - return -EINVAL; - - pAdapter->CommonCfg.FragmentThreshold = val; - return 0; -} - -int rt_ioctl_giwfrag(struct net_device *dev, - struct iw_request_info *info, - struct iw_param *frag, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - frag->value = pAdapter->CommonCfg.FragmentThreshold; - frag->disabled = (frag->value == MAX_FRAG_THRESHOLD); - frag->fixed = 1; - - return 0; -} - -#define MAX_WEP_KEY_SIZE 13 -#define MIN_WEP_KEY_SIZE 5 -int rt_ioctl_siwencode(struct net_device *dev, - struct iw_request_info *info, - struct iw_point *erq, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - if ((erq->length == 0) && (erq->flags & IW_ENCODE_DISABLED)) { - pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled; - pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled; - pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled; - pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus; - pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen; - goto done; - } else if (erq->flags & IW_ENCODE_RESTRICTED - || erq->flags & IW_ENCODE_OPEN) { - /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ - STA_PORT_SECURED(pAdapter); - pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled; - pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled; - pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled; - pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus; - if (erq->flags & IW_ENCODE_RESTRICTED) - pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared; - else - pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen; - } - - if (erq->length > 0) { - int keyIdx = (erq->flags & IW_ENCODE_INDEX) - 1; - /* Check the size of the key */ - if (erq->length > MAX_WEP_KEY_SIZE) { - return -EINVAL; - } - /* Check key index */ - if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS)) { - DBGPRINT(RT_DEBUG_TRACE, - ("==>rt_ioctl_siwencode::Wrong keyIdx=%d! Using default key instead (%d)\n", - keyIdx, pAdapter->StaCfg.DefaultKeyId)); - - /*Using default key */ - keyIdx = pAdapter->StaCfg.DefaultKeyId; - } else - pAdapter->StaCfg.DefaultKeyId = keyIdx; - - NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, 16); - - if (erq->length == MAX_WEP_KEY_SIZE) { - pAdapter->SharedKey[BSS0][keyIdx].KeyLen = - MAX_WEP_KEY_SIZE; - pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = - CIPHER_WEP128; - } else if (erq->length == MIN_WEP_KEY_SIZE) { - pAdapter->SharedKey[BSS0][keyIdx].KeyLen = - MIN_WEP_KEY_SIZE; - pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = - CIPHER_WEP64; - } else - /* Disable the key */ - pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0; - - /* Check if the key is not marked as invalid */ - if (!(erq->flags & IW_ENCODE_NOKEY)) { - /* Copy the key in the driver */ - NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, - extra, erq->length); - } - } else { - /* Do we want to just set the transmit key index ? */ - int index = (erq->flags & IW_ENCODE_INDEX) - 1; - if ((index >= 0) && (index < 4)) { - pAdapter->StaCfg.DefaultKeyId = index; - } else - /* Don't complain if the mode is only changed */ - if (!(erq->flags & IW_ENCODE_MODE)) - return -EINVAL; - } - -done: - DBGPRINT(RT_DEBUG_TRACE, - ("==>rt_ioctl_siwencode::erq->flags=%x\n", erq->flags)); - DBGPRINT(RT_DEBUG_TRACE, - ("==>rt_ioctl_siwencode::AuthMode=%x\n", - pAdapter->StaCfg.AuthMode)); - DBGPRINT(RT_DEBUG_TRACE, - ("==>rt_ioctl_siwencode::DefaultKeyId=%x, KeyLen = %d\n", - pAdapter->StaCfg.DefaultKeyId, - pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId]. - KeyLen)); - DBGPRINT(RT_DEBUG_TRACE, - ("==>rt_ioctl_siwencode::WepStatus=%x\n", - pAdapter->StaCfg.WepStatus)); - return 0; -} - -int -rt_ioctl_giwencode(struct net_device *dev, - struct iw_request_info *info, - struct iw_point *erq, char *key) -{ - int kid; - struct rt_rtmp_adapter *pAdapter = NULL; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - kid = erq->flags & IW_ENCODE_INDEX; - DBGPRINT(RT_DEBUG_TRACE, - ("===>rt_ioctl_giwencode %d\n", erq->flags & IW_ENCODE_INDEX)); - - if (pAdapter->StaCfg.WepStatus == Ndis802_11WEPDisabled) { - erq->length = 0; - erq->flags = IW_ENCODE_DISABLED; - } else if ((kid > 0) && (kid <= 4)) { - /* copy wep key */ - erq->flags = kid; /* NB: base 1 */ - if (erq->length > pAdapter->SharedKey[BSS0][kid - 1].KeyLen) - erq->length = pAdapter->SharedKey[BSS0][kid - 1].KeyLen; - memcpy(key, pAdapter->SharedKey[BSS0][kid - 1].Key, - erq->length); - /*if ((kid == pAdapter->PortCfg.DefaultKeyId)) */ - /*erq->flags |= IW_ENCODE_ENABLED; */ /* XXX */ - if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) - erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */ - else - erq->flags |= IW_ENCODE_OPEN; /* XXX */ - - } else if (kid == 0) { - if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) - erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */ - else - erq->flags |= IW_ENCODE_OPEN; /* XXX */ - erq->length = - pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId]. - KeyLen; - memcpy(key, - pAdapter->SharedKey[BSS0][pAdapter->StaCfg.DefaultKeyId]. - Key, erq->length); - /* copy default key ID */ - if (pAdapter->StaCfg.AuthMode == Ndis802_11AuthModeShared) - erq->flags |= IW_ENCODE_RESTRICTED; /* XXX */ - else - erq->flags |= IW_ENCODE_OPEN; /* XXX */ - erq->flags = pAdapter->StaCfg.DefaultKeyId + 1; /* NB: base 1 */ - erq->flags |= IW_ENCODE_ENABLED; /* XXX */ - } - - return 0; - -} - -void getBaInfo(struct rt_rtmp_adapter *pAd, char *pOutBuf) -{ - int i, j; - struct rt_ba_ori_entry *pOriBAEntry; - struct rt_ba_rec_entry *pRecBAEntry; - - for (i = 0; i < MAX_LEN_OF_MAC_TABLE; i++) { - struct rt_mac_table_entry *pEntry = &pAd->MacTab.Content[i]; - if (((pEntry->ValidAsCLI || pEntry->ValidAsApCli) - && (pEntry->Sst == SST_ASSOC)) - || (pEntry->ValidAsWDS) || (pEntry->ValidAsMesh)) { - sprintf(pOutBuf + strlen(pOutBuf), "\n%pM (Aid = %d) " - "(AP) -\n", pEntry->Addr, pEntry->Aid); - - sprintf(pOutBuf, "%s[Recipient]\n", pOutBuf); - for (j = 0; j < NUM_OF_TID; j++) { - if (pEntry->BARecWcidArray[j] != 0) { - pRecBAEntry = - &pAd->BATable.BARecEntry[pEntry-> - BARecWcidArray - [j]]; - sprintf(pOutBuf + strlen(pOutBuf), - "TID=%d, BAWinSize=%d, LastIndSeq=%d, ReorderingPkts=%d\n", - j, pRecBAEntry->BAWinSize, - pRecBAEntry->LastIndSeq, - pRecBAEntry->list.qlen); - } - } - sprintf(pOutBuf, "%s\n", pOutBuf); - - sprintf(pOutBuf, "%s[Originator]\n", pOutBuf); - for (j = 0; j < NUM_OF_TID; j++) { - if (pEntry->BAOriWcidArray[j] != 0) { - pOriBAEntry = - &pAd->BATable.BAOriEntry[pEntry-> - BAOriWcidArray - [j]]; - sprintf(pOutBuf + strlen(pOutBuf), - "TID=%d, BAWinSize=%d, StartSeq=%d, CurTxSeq=%d\n", - j, pOriBAEntry->BAWinSize, - pOriBAEntry->Sequence, - pEntry->TxSeq[j]); - } - } - sprintf(pOutBuf, "%s\n\n", pOutBuf); - } - if (strlen(pOutBuf) > (IW_PRIV_SIZE_MASK - 30)) - break; - } - - return; -} - -int rt_ioctl_siwmlme(struct net_device *dev, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) -{ - struct rt_rtmp_adapter *pAd = NULL; - struct iw_mlme *pMlme = (struct iw_mlme *)wrqu->data.pointer; - struct rt_mlme_queue_elem MsgElem; - struct rt_mlme_disassoc_req DisAssocReq; - struct rt_mlme_deauth_req DeAuthReq; - - GET_PAD_FROM_NET_DEV(pAd, dev); - - DBGPRINT(RT_DEBUG_TRACE, ("====> %s\n", __func__)); - - if (pMlme == NULL) - return -EINVAL; - - switch (pMlme->cmd) { -#ifdef IW_MLME_DEAUTH - case IW_MLME_DEAUTH: - DBGPRINT(RT_DEBUG_TRACE, - ("====> %s - IW_MLME_DEAUTH\n", __func__)); - COPY_MAC_ADDR(DeAuthReq.Addr, pAd->CommonCfg.Bssid); - DeAuthReq.Reason = pMlme->reason_code; - MsgElem.MsgLen = sizeof(struct rt_mlme_deauth_req); - NdisMoveMemory(MsgElem.Msg, &DeAuthReq, - sizeof(struct rt_mlme_deauth_req)); - MlmeDeauthReqAction(pAd, &MsgElem); - if (INFRA_ON(pAd)) { - LinkDown(pAd, FALSE); - pAd->Mlme.AssocMachine.CurrState = ASSOC_IDLE; - } - break; -#endif /* IW_MLME_DEAUTH // */ -#ifdef IW_MLME_DISASSOC - case IW_MLME_DISASSOC: - DBGPRINT(RT_DEBUG_TRACE, - ("====> %s - IW_MLME_DISASSOC\n", __func__)); - COPY_MAC_ADDR(DisAssocReq.Addr, pAd->CommonCfg.Bssid); - DisAssocReq.Reason = pMlme->reason_code; - - MsgElem.Machine = ASSOC_STATE_MACHINE; - MsgElem.MsgType = MT2_MLME_DISASSOC_REQ; - MsgElem.MsgLen = sizeof(struct rt_mlme_disassoc_req); - NdisMoveMemory(MsgElem.Msg, &DisAssocReq, - sizeof(struct rt_mlme_disassoc_req)); - - pAd->Mlme.CntlMachine.CurrState = CNTL_WAIT_OID_DISASSOC; - MlmeDisassocReqAction(pAd, &MsgElem); - break; -#endif /* IW_MLME_DISASSOC // */ - default: - DBGPRINT(RT_DEBUG_TRACE, - ("====> %s - Unknow Command\n", __func__)); - break; - } - - return 0; -} - -int rt_ioctl_siwauth(struct net_device *dev, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - struct iw_param *param = &wrqu->param; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - switch (param->flags & IW_AUTH_INDEX) { - case IW_AUTH_WPA_VERSION: - if (param->value == IW_AUTH_WPA_VERSION_WPA) { - pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPAPSK; - if (pAdapter->StaCfg.BssType == BSS_ADHOC) - pAdapter->StaCfg.AuthMode = - Ndis802_11AuthModeWPANone; - } else if (param->value == IW_AUTH_WPA_VERSION_WPA2) - pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeWPA2PSK; - - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", - __func__, param->value)); - break; - case IW_AUTH_CIPHER_PAIRWISE: - if (param->value == IW_AUTH_CIPHER_NONE) { - pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled; - pAdapter->StaCfg.OrigWepStatus = - pAdapter->StaCfg.WepStatus; - pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled; - } else if (param->value == IW_AUTH_CIPHER_WEP40 || - param->value == IW_AUTH_CIPHER_WEP104) { - pAdapter->StaCfg.WepStatus = Ndis802_11WEPEnabled; - pAdapter->StaCfg.OrigWepStatus = - pAdapter->StaCfg.WepStatus; - pAdapter->StaCfg.PairCipher = Ndis802_11WEPEnabled; - pAdapter->StaCfg.IEEE8021X = FALSE; - } else if (param->value == IW_AUTH_CIPHER_TKIP) { - pAdapter->StaCfg.WepStatus = - Ndis802_11Encryption2Enabled; - pAdapter->StaCfg.OrigWepStatus = - pAdapter->StaCfg.WepStatus; - pAdapter->StaCfg.PairCipher = - Ndis802_11Encryption2Enabled; - } else if (param->value == IW_AUTH_CIPHER_CCMP) { - pAdapter->StaCfg.WepStatus = - Ndis802_11Encryption3Enabled; - pAdapter->StaCfg.OrigWepStatus = - pAdapter->StaCfg.WepStatus; - pAdapter->StaCfg.PairCipher = - Ndis802_11Encryption3Enabled; - } - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_AUTH_CIPHER_PAIRWISE - param->value = %d!\n", - __func__, param->value)); - break; - case IW_AUTH_CIPHER_GROUP: - if (param->value == IW_AUTH_CIPHER_NONE) { - pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled; - } else if (param->value == IW_AUTH_CIPHER_WEP40 || - param->value == IW_AUTH_CIPHER_WEP104) { - pAdapter->StaCfg.GroupCipher = Ndis802_11WEPEnabled; - } else if (param->value == IW_AUTH_CIPHER_TKIP) { - pAdapter->StaCfg.GroupCipher = - Ndis802_11Encryption2Enabled; - } else if (param->value == IW_AUTH_CIPHER_CCMP) { - pAdapter->StaCfg.GroupCipher = - Ndis802_11Encryption3Enabled; - } - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_AUTH_CIPHER_GROUP - param->value = %d!\n", - __func__, param->value)); - break; - case IW_AUTH_KEY_MGMT: - if (param->value == IW_AUTH_KEY_MGMT_802_1X) { - if (pAdapter->StaCfg.AuthMode == - Ndis802_11AuthModeWPAPSK) { - pAdapter->StaCfg.AuthMode = - Ndis802_11AuthModeWPA; - pAdapter->StaCfg.IEEE8021X = FALSE; - } else if (pAdapter->StaCfg.AuthMode == - Ndis802_11AuthModeWPA2PSK) { - pAdapter->StaCfg.AuthMode = - Ndis802_11AuthModeWPA2; - pAdapter->StaCfg.IEEE8021X = FALSE; - } else - /* WEP 1x */ - pAdapter->StaCfg.IEEE8021X = TRUE; - } else if (param->value == 0) { - /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ - STA_PORT_SECURED(pAdapter); - } - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_AUTH_KEY_MGMT - param->value = %d!\n", - __func__, param->value)); - break; - case IW_AUTH_RX_UNENCRYPTED_EAPOL: - break; - case IW_AUTH_PRIVACY_INVOKED: - /*if (param->value == 0) - { - pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen; - pAdapter->StaCfg.WepStatus = Ndis802_11WEPDisabled; - pAdapter->StaCfg.OrigWepStatus = pAdapter->StaCfg.WepStatus; - pAdapter->StaCfg.PairCipher = Ndis802_11WEPDisabled; - pAdapter->StaCfg.GroupCipher = Ndis802_11WEPDisabled; - } */ - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_AUTH_PRIVACY_INVOKED - param->value = %d!\n", - __func__, param->value)); - break; - case IW_AUTH_DROP_UNENCRYPTED: - if (param->value != 0) - pAdapter->StaCfg.PortSecured = - WPA_802_1X_PORT_NOT_SECURED; - else { - /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ - STA_PORT_SECURED(pAdapter); - } - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_AUTH_WPA_VERSION - param->value = %d!\n", - __func__, param->value)); - break; - case IW_AUTH_80211_AUTH_ALG: - if (param->value & IW_AUTH_ALG_SHARED_KEY) { - pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeShared; - } else if (param->value & IW_AUTH_ALG_OPEN_SYSTEM) { - pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen; - } else - return -EINVAL; - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_AUTH_80211_AUTH_ALG - param->value = %d!\n", - __func__, param->value)); - break; - case IW_AUTH_WPA_ENABLED: - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_AUTH_WPA_ENABLED - Driver supports WPA!(param->value = %d)\n", - __func__, param->value)); - break; - default: - return -EOPNOTSUPP; - } - - return 0; -} - -int rt_ioctl_giwauth(struct net_device *dev, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - struct iw_param *param = &wrqu->param; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - switch (param->flags & IW_AUTH_INDEX) { - case IW_AUTH_DROP_UNENCRYPTED: - param->value = - (pAdapter->StaCfg.WepStatus == - Ndis802_11WEPDisabled) ? 0 : 1; - break; - - case IW_AUTH_80211_AUTH_ALG: - param->value = - (pAdapter->StaCfg.AuthMode == - Ndis802_11AuthModeShared) ? IW_AUTH_ALG_SHARED_KEY : - IW_AUTH_ALG_OPEN_SYSTEM; - break; - - case IW_AUTH_WPA_ENABLED: - param->value = - (pAdapter->StaCfg.AuthMode >= - Ndis802_11AuthModeWPA) ? 1 : 0; - break; - - default: - return -EOPNOTSUPP; - } - DBGPRINT(RT_DEBUG_TRACE, - ("rt_ioctl_giwauth::param->value = %d!\n", param->value)); - return 0; -} - -void fnSetCipherKey(struct rt_rtmp_adapter *pAdapter, - int keyIdx, - u8 CipherAlg, - IN BOOLEAN bGTK, IN struct iw_encode_ext *ext) -{ - NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], sizeof(struct rt_cipher_key)); - pAdapter->SharedKey[BSS0][keyIdx].KeyLen = LEN_TKIP_EK; - NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, ext->key, - LEN_TKIP_EK); - NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].TxMic, - ext->key + LEN_TKIP_EK, LEN_TKIP_TXMICK); - NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].RxMic, - ext->key + LEN_TKIP_EK + LEN_TKIP_TXMICK, - LEN_TKIP_RXMICK); - pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CipherAlg; - - /* Update group key information to ASIC Shared Key Table */ - AsicAddSharedKeyEntry(pAdapter, - BSS0, - keyIdx, - pAdapter->SharedKey[BSS0][keyIdx].CipherAlg, - pAdapter->SharedKey[BSS0][keyIdx].Key, - pAdapter->SharedKey[BSS0][keyIdx].TxMic, - pAdapter->SharedKey[BSS0][keyIdx].RxMic); - - if (bGTK) - /* Update ASIC WCID attribute table and IVEIV table */ - RTMPAddWcidAttributeEntry(pAdapter, - BSS0, - keyIdx, - pAdapter->SharedKey[BSS0][keyIdx]. - CipherAlg, NULL); - else - /* Update ASIC WCID attribute table and IVEIV table */ - RTMPAddWcidAttributeEntry(pAdapter, - BSS0, - keyIdx, - pAdapter->SharedKey[BSS0][keyIdx]. - CipherAlg, - &pAdapter->MacTab. - Content[BSSID_WCID]); -} - -int rt_ioctl_siwencodeext(struct net_device *dev, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) -{ - struct rt_rtmp_adapter *pAdapter = NULL; - struct iw_point *encoding = &wrqu->encoding; - struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; - int keyIdx, alg = ext->alg; - - GET_PAD_FROM_NET_DEV(pAdapter, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAdapter, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - if (encoding->flags & IW_ENCODE_DISABLED) { - keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1; - /* set BSSID wcid entry of the Pair-wise Key table as no-security mode */ - AsicRemovePairwiseKeyEntry(pAdapter, BSS0, BSSID_WCID); - pAdapter->SharedKey[BSS0][keyIdx].KeyLen = 0; - pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = CIPHER_NONE; - AsicRemoveSharedKeyEntry(pAdapter, 0, (u8)keyIdx); - NdisZeroMemory(&pAdapter->SharedKey[BSS0][keyIdx], - sizeof(struct rt_cipher_key)); - DBGPRINT(RT_DEBUG_TRACE, - ("%s::Remove all keys!(encoding->flags = %x)\n", - __func__, encoding->flags)); - } else { - /* Get Key Index and convet to our own defined key index */ - keyIdx = (encoding->flags & IW_ENCODE_INDEX) - 1; - if ((keyIdx < 0) || (keyIdx >= NR_WEP_KEYS)) - return -EINVAL; - - if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { - pAdapter->StaCfg.DefaultKeyId = keyIdx; - DBGPRINT(RT_DEBUG_TRACE, - ("%s::DefaultKeyId = %d\n", __func__, - pAdapter->StaCfg.DefaultKeyId)); - } - - switch (alg) { - case IW_ENCODE_ALG_NONE: - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_ENCODE_ALG_NONE\n", __func__)); - break; - case IW_ENCODE_ALG_WEP: - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_ENCODE_ALG_WEP - ext->key_len = %d, keyIdx = %d\n", - __func__, ext->key_len, keyIdx)); - if (ext->key_len == MAX_WEP_KEY_SIZE) { - pAdapter->SharedKey[BSS0][keyIdx].KeyLen = - MAX_WEP_KEY_SIZE; - pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = - CIPHER_WEP128; - } else if (ext->key_len == MIN_WEP_KEY_SIZE) { - pAdapter->SharedKey[BSS0][keyIdx].KeyLen = - MIN_WEP_KEY_SIZE; - pAdapter->SharedKey[BSS0][keyIdx].CipherAlg = - CIPHER_WEP64; - } else - return -EINVAL; - - NdisZeroMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, - 16); - NdisMoveMemory(pAdapter->SharedKey[BSS0][keyIdx].Key, - ext->key, ext->key_len); - if (pAdapter->StaCfg.GroupCipher == - Ndis802_11GroupWEP40Enabled - || pAdapter->StaCfg.GroupCipher == - Ndis802_11GroupWEP104Enabled) { - /* Set Group key material to Asic */ - AsicAddSharedKeyEntry(pAdapter, BSS0, keyIdx, - pAdapter-> - SharedKey[BSS0][keyIdx]. - CipherAlg, - pAdapter-> - SharedKey[BSS0][keyIdx]. - Key, NULL, NULL); - - /* Update WCID attribute table and IVEIV table for this group key table */ - RTMPAddWcidAttributeEntry(pAdapter, BSS0, - keyIdx, - pAdapter-> - SharedKey[BSS0] - [keyIdx].CipherAlg, - NULL); - - STA_PORT_SECURED(pAdapter); - - /* Indicate Connected for GUI */ - pAdapter->IndicateMediaState = - NdisMediaStateConnected; - } - break; - case IW_ENCODE_ALG_TKIP: - DBGPRINT(RT_DEBUG_TRACE, - ("%s::IW_ENCODE_ALG_TKIP - keyIdx = %d, ext->key_len = %d\n", - __func__, keyIdx, ext->key_len)); - if (ext->key_len == 32) { - if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { - fnSetCipherKey(pAdapter, keyIdx, - CIPHER_TKIP, FALSE, ext); - if (pAdapter->StaCfg.AuthMode >= - Ndis802_11AuthModeWPA2) { - /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ - STA_PORT_SECURED(pAdapter); - pAdapter->IndicateMediaState = - NdisMediaStateConnected; - } - } else if (ext-> - ext_flags & IW_ENCODE_EXT_GROUP_KEY) - { - fnSetCipherKey(pAdapter, keyIdx, - CIPHER_TKIP, TRUE, ext); - - /* set 802.1x port control */ - /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ - STA_PORT_SECURED(pAdapter); - pAdapter->IndicateMediaState = - NdisMediaStateConnected; - } - } else - return -EINVAL; - break; - case IW_ENCODE_ALG_CCMP: - if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) { - fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, - FALSE, ext); - if (pAdapter->StaCfg.AuthMode >= - Ndis802_11AuthModeWPA2) - /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ - STA_PORT_SECURED(pAdapter); - pAdapter->IndicateMediaState = - NdisMediaStateConnected; - } else if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) { - fnSetCipherKey(pAdapter, keyIdx, CIPHER_AES, - TRUE, ext); - - /* set 802.1x port control */ - /*pAdapter->StaCfg.PortSecured = WPA_802_1X_PORT_SECURED; */ - STA_PORT_SECURED(pAdapter); - pAdapter->IndicateMediaState = - NdisMediaStateConnected; - } - break; - default: - return -EINVAL; - } - } - - return 0; -} - -int -rt_ioctl_giwencodeext(struct net_device *dev, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) -{ - struct rt_rtmp_adapter *pAd = NULL; - char *pKey = NULL; - struct iw_point *encoding = &wrqu->encoding; - struct iw_encode_ext *ext = (struct iw_encode_ext *)extra; - int idx, max_key_len; - - GET_PAD_FROM_NET_DEV(pAd, dev); - - DBGPRINT(RT_DEBUG_TRACE, ("===> rt_ioctl_giwencodeext\n")); - - max_key_len = encoding->length - sizeof(*ext); - if (max_key_len < 0) - return -EINVAL; - - idx = encoding->flags & IW_ENCODE_INDEX; - if (idx) { - if (idx < 1 || idx > 4) - return -EINVAL; - idx--; - - if ((pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) || - (pAd->StaCfg.WepStatus == Ndis802_11Encryption3Enabled)) { - if (idx != pAd->StaCfg.DefaultKeyId) { - ext->key_len = 0; - return 0; - } - } - } else - idx = pAd->StaCfg.DefaultKeyId; - - encoding->flags = idx + 1; - memset(ext, 0, sizeof(*ext)); - - ext->key_len = 0; - switch (pAd->StaCfg.WepStatus) { - case Ndis802_11WEPDisabled: - ext->alg = IW_ENCODE_ALG_NONE; - encoding->flags |= IW_ENCODE_DISABLED; - break; - case Ndis802_11WEPEnabled: - ext->alg = IW_ENCODE_ALG_WEP; - if (pAd->SharedKey[BSS0][idx].KeyLen > max_key_len) - return -E2BIG; - else { - ext->key_len = pAd->SharedKey[BSS0][idx].KeyLen; - pKey = (char *)& (pAd->SharedKey[BSS0][idx].Key[0]); - } - break; - case Ndis802_11Encryption2Enabled: - case Ndis802_11Encryption3Enabled: - if (pAd->StaCfg.WepStatus == Ndis802_11Encryption2Enabled) - ext->alg = IW_ENCODE_ALG_TKIP; - else - ext->alg = IW_ENCODE_ALG_CCMP; - - if (max_key_len < 32) - return -E2BIG; - else { - ext->key_len = 32; - pKey = (char *)& pAd->StaCfg.PMK[0]; - } - break; - default: - return -EINVAL; - } - - if (ext->key_len && pKey) { - encoding->flags |= IW_ENCODE_ENABLED; - memcpy(ext->key, pKey, ext->key_len); - } - - return 0; -} - -int rt_ioctl_siwgenie(struct net_device *dev, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) -{ - struct rt_rtmp_adapter *pAd = NULL; - - GET_PAD_FROM_NET_DEV(pAd, dev); - - DBGPRINT(RT_DEBUG_TRACE, ("===> rt_ioctl_siwgenie\n")); - pAd->StaCfg.bRSN_IE_FromWpaSupplicant = FALSE; - if (wrqu->data.length > MAX_LEN_OF_RSNIE || - (wrqu->data.length && extra == NULL)) - return -EINVAL; - - if (wrqu->data.length) { - pAd->StaCfg.RSNIE_Len = wrqu->data.length; - NdisMoveMemory(&pAd->StaCfg.RSN_IE[0], extra, - pAd->StaCfg.RSNIE_Len); - pAd->StaCfg.bRSN_IE_FromWpaSupplicant = TRUE; - } else { - pAd->StaCfg.RSNIE_Len = 0; - NdisZeroMemory(&pAd->StaCfg.RSN_IE[0], MAX_LEN_OF_RSNIE); - } - - return 0; -} - -int rt_ioctl_giwgenie(struct net_device *dev, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) -{ - struct rt_rtmp_adapter *pAd = NULL; - - GET_PAD_FROM_NET_DEV(pAd, dev); - - if ((pAd->StaCfg.RSNIE_Len == 0) || - (pAd->StaCfg.AuthMode < Ndis802_11AuthModeWPA)) { - wrqu->data.length = 0; - return 0; - } - - if (pAd->StaCfg.WpaSupplicantUP == WPA_SUPPLICANT_ENABLE) { - if (wrqu->data.length < pAd->StaCfg.RSNIE_Len) - return -E2BIG; - - wrqu->data.length = pAd->StaCfg.RSNIE_Len; - memcpy(extra, &pAd->StaCfg.RSN_IE[0], pAd->StaCfg.RSNIE_Len); - } else { - u8 RSNIe = IE_WPA; - - if (wrqu->data.length < (pAd->StaCfg.RSNIE_Len + 2)) /* ID, Len */ - return -E2BIG; - wrqu->data.length = pAd->StaCfg.RSNIE_Len + 2; - - if ((pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2PSK) || - (pAd->StaCfg.AuthMode == Ndis802_11AuthModeWPA2)) - RSNIe = IE_RSN; - - extra[0] = (char)RSNIe; - extra[1] = pAd->StaCfg.RSNIE_Len; - memcpy(extra + 2, &pAd->StaCfg.RSN_IE[0], - pAd->StaCfg.RSNIE_Len); - } - - return 0; -} - -int rt_ioctl_siwpmksa(struct net_device *dev, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) -{ - struct rt_rtmp_adapter *pAd = NULL; - struct iw_pmksa *pPmksa = (struct iw_pmksa *)wrqu->data.pointer; - int CachedIdx = 0, idx = 0; - - GET_PAD_FROM_NET_DEV(pAd, dev); - - if (pPmksa == NULL) - return -EINVAL; - - DBGPRINT(RT_DEBUG_TRACE, ("===> rt_ioctl_siwpmksa\n")); - switch (pPmksa->cmd) { - case IW_PMKSA_FLUSH: - NdisZeroMemory(pAd->StaCfg.SavedPMK, - sizeof(struct rt_bssid_info) * PMKID_NO); - DBGPRINT(RT_DEBUG_TRACE, - ("rt_ioctl_siwpmksa - IW_PMKSA_FLUSH\n")); - break; - case IW_PMKSA_REMOVE: - for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; - CachedIdx++) { - /* compare the BSSID */ - if (NdisEqualMemory - (pPmksa->bssid.sa_data, - pAd->StaCfg.SavedPMK[CachedIdx].BSSID, - MAC_ADDR_LEN)) { - NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx]. - BSSID, MAC_ADDR_LEN); - NdisZeroMemory(pAd->StaCfg.SavedPMK[CachedIdx]. - PMKID, 16); - for (idx = CachedIdx; - idx < (pAd->StaCfg.SavedPMKNum - 1); - idx++) { - NdisMoveMemory(&pAd->StaCfg. - SavedPMK[idx].BSSID[0], - &pAd->StaCfg. - SavedPMK[idx + - 1].BSSID[0], - MAC_ADDR_LEN); - NdisMoveMemory(&pAd->StaCfg. - SavedPMK[idx].PMKID[0], - &pAd->StaCfg. - SavedPMK[idx + - 1].PMKID[0], - 16); - } - pAd->StaCfg.SavedPMKNum--; - break; - } - } - - DBGPRINT(RT_DEBUG_TRACE, - ("rt_ioctl_siwpmksa - IW_PMKSA_REMOVE\n")); - break; - case IW_PMKSA_ADD: - for (CachedIdx = 0; CachedIdx < pAd->StaCfg.SavedPMKNum; - CachedIdx++) { - /* compare the BSSID */ - if (NdisEqualMemory - (pPmksa->bssid.sa_data, - pAd->StaCfg.SavedPMK[CachedIdx].BSSID, - MAC_ADDR_LEN)) - break; - } - - /* Found, replace it */ - if (CachedIdx < PMKID_NO) { - DBGPRINT(RT_DEBUG_OFF, - ("Update PMKID, idx = %d\n", CachedIdx)); - NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx]. - BSSID[0], pPmksa->bssid.sa_data, - MAC_ADDR_LEN); - NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx]. - PMKID[0], pPmksa->pmkid, 16); - pAd->StaCfg.SavedPMKNum++; - } - /* Not found, replace the last one */ - else { - /* Randomly replace one */ - CachedIdx = (pPmksa->bssid.sa_data[5] % PMKID_NO); - DBGPRINT(RT_DEBUG_OFF, - ("Update PMKID, idx = %d\n", CachedIdx)); - NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx]. - BSSID[0], pPmksa->bssid.sa_data, - MAC_ADDR_LEN); - NdisMoveMemory(&pAd->StaCfg.SavedPMK[CachedIdx]. - PMKID[0], pPmksa->pmkid, 16); - } - - DBGPRINT(RT_DEBUG_TRACE, - ("rt_ioctl_siwpmksa - IW_PMKSA_ADD\n")); - break; - default: - DBGPRINT(RT_DEBUG_TRACE, - ("rt_ioctl_siwpmksa - Unknown Command!\n")); - break; - } - - return 0; -} - -int rt_ioctl_siwrate(struct net_device *dev, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) -{ - struct rt_rtmp_adapter *pAd = NULL; - u32 rate = wrqu->bitrate.value, fixed = wrqu->bitrate.fixed; - - GET_PAD_FROM_NET_DEV(pAd, dev); - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, - ("rt_ioctl_siwrate::Network is down!\n")); - return -ENETDOWN; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("rt_ioctl_siwrate::(rate = %d, fixed = %d)\n", rate, fixed)); - /* rate = -1 => auto rate - rate = X, fixed = 1 => (fixed rate X) - */ - if (rate == -1) { - /*Auto Rate */ - pAd->StaCfg.DesiredTransmitSetting.field.MCS = MCS_AUTO; - pAd->StaCfg.bAutoTxRateSwitch = TRUE; - if ((pAd->CommonCfg.PhyMode <= PHY_11G) || - (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= - MODE_OFDM)) - RTMPSetDesiredRates(pAd, -1); - - SetCommonHT(pAd); - } else { - if (fixed) { - pAd->StaCfg.bAutoTxRateSwitch = FALSE; - if ((pAd->CommonCfg.PhyMode <= PHY_11G) || - (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field. - MODE <= MODE_OFDM)) - RTMPSetDesiredRates(pAd, rate); - else { - pAd->StaCfg.DesiredTransmitSetting.field.MCS = - MCS_AUTO; - SetCommonHT(pAd); - } - DBGPRINT(RT_DEBUG_TRACE, - ("rt_ioctl_siwrate::(HtMcs=%d)\n", - pAd->StaCfg.DesiredTransmitSetting.field. - MCS)); - } else { - /* TODO: rate = X, fixed = 0 => (rates <= X) */ - return -EOPNOTSUPP; - } - } - - return 0; -} - -int rt_ioctl_giwrate(struct net_device *dev, - struct iw_request_info *info, - union iwreq_data *wrqu, char *extra) -{ - struct rt_rtmp_adapter *pAd = NULL; - int rate_index = 0, rate_count = 0; - HTTRANSMIT_SETTING ht_setting; -/* Remove to global variable - __s32 ralinkrate[] = - {2, 4, 11, 22, // CCK - 12, 18, 24, 36, 48, 72, 96, 108, // OFDM - 13, 26, 39, 52, 78, 104, 117, 130, 26, 52, 78, 104, 156, 208, 234, 260, // 20MHz, 800ns GI, MCS: 0 ~ 15 - 39, 78, 117, 156, 234, 312, 351, 390, // 20MHz, 800ns GI, MCS: 16 ~ 23 - 27, 54, 81, 108, 162, 216, 243, 270, 54, 108, 162, 216, 324, 432, 486, 540, // 40MHz, 800ns GI, MCS: 0 ~ 15 - 81, 162, 243, 324, 486, 648, 729, 810, // 40MHz, 800ns GI, MCS: 16 ~ 23 - 14, 29, 43, 57, 87, 115, 130, 144, 29, 59, 87, 115, 173, 230, 260, 288, // 20MHz, 400ns GI, MCS: 0 ~ 15 - 43, 87, 130, 173, 260, 317, 390, 433, // 20MHz, 400ns GI, MCS: 16 ~ 23 - 30, 60, 90, 120, 180, 240, 270, 300, 60, 120, 180, 240, 360, 480, 540, 600, // 40MHz, 400ns GI, MCS: 0 ~ 15 - 90, 180, 270, 360, 540, 720, 810, 900}; // 40MHz, 400ns GI, MCS: 16 ~ 23 -*/ - GET_PAD_FROM_NET_DEV(pAd, dev); - - rate_count = ARRAY_SIZE(ralinkrate); - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - - if ((pAd->StaCfg.bAutoTxRateSwitch == FALSE) && - (INFRA_ON(pAd)) && - ((pAd->CommonCfg.PhyMode <= PHY_11G) - || (pAd->MacTab.Content[BSSID_WCID].HTPhyMode.field.MODE <= - MODE_OFDM))) - ht_setting.word = pAd->StaCfg.HTPhyMode.word; - else - ht_setting.word = - pAd->MacTab.Content[BSSID_WCID].HTPhyMode.word; - - if (ht_setting.field.MODE >= MODE_HTMIX) { -/* rate_index = 12 + ((u8)ht_setting.field.BW *16) + ((u8)ht_setting.field.ShortGI *32) + ((u8)ht_setting.field.MCS); */ - rate_index = - 12 + ((u8)ht_setting.field.BW * 24) + - ((u8)ht_setting.field.ShortGI * 48) + - ((u8)ht_setting.field.MCS); - } else if (ht_setting.field.MODE == MODE_OFDM) - rate_index = (u8)(ht_setting.field.MCS) + 4; - else if (ht_setting.field.MODE == MODE_CCK) - rate_index = (u8)(ht_setting.field.MCS); - - if (rate_index < 0) - rate_index = 0; - - if (rate_index >= rate_count) - rate_index = rate_count - 1; - - wrqu->bitrate.value = ralinkrate[rate_index] * 500000; - wrqu->bitrate.disabled = 0; - - return 0; -} - -static const iw_handler rt_handler[] = { - (iw_handler) NULL, /* SIOCSIWCOMMIT */ - (iw_handler) rt_ioctl_giwname, /* SIOCGIWNAME */ - (iw_handler) NULL, /* SIOCSIWNWID */ - (iw_handler) NULL, /* SIOCGIWNWID */ - (iw_handler) rt_ioctl_siwfreq, /* SIOCSIWFREQ */ - (iw_handler) rt_ioctl_giwfreq, /* SIOCGIWFREQ */ - (iw_handler) rt_ioctl_siwmode, /* SIOCSIWMODE */ - (iw_handler) rt_ioctl_giwmode, /* SIOCGIWMODE */ - (iw_handler) NULL, /* SIOCSIWSENS */ - (iw_handler) NULL, /* SIOCGIWSENS */ - (iw_handler) NULL /* not used */ , /* SIOCSIWRANGE */ - (iw_handler) rt_ioctl_giwrange, /* SIOCGIWRANGE */ - (iw_handler) NULL /* not used */ , /* SIOCSIWPRIV */ - (iw_handler) NULL /* kernel code */ , /* SIOCGIWPRIV */ - (iw_handler) NULL /* not used */ , /* SIOCSIWSTATS */ - (iw_handler) rt28xx_get_wireless_stats /* kernel code */ , /* SIOCGIWSTATS */ - (iw_handler) NULL, /* SIOCSIWSPY */ - (iw_handler) NULL, /* SIOCGIWSPY */ - (iw_handler) NULL, /* SIOCSIWTHRSPY */ - (iw_handler) NULL, /* SIOCGIWTHRSPY */ - (iw_handler) rt_ioctl_siwap, /* SIOCSIWAP */ - (iw_handler) rt_ioctl_giwap, /* SIOCGIWAP */ - (iw_handler) rt_ioctl_siwmlme, /* SIOCSIWMLME */ - (iw_handler) rt_ioctl_iwaplist, /* SIOCGIWAPLIST */ - (iw_handler) rt_ioctl_siwscan, /* SIOCSIWSCAN */ - (iw_handler) rt_ioctl_giwscan, /* SIOCGIWSCAN */ - (iw_handler) rt_ioctl_siwessid, /* SIOCSIWESSID */ - (iw_handler) rt_ioctl_giwessid, /* SIOCGIWESSID */ - (iw_handler) rt_ioctl_siwnickn, /* SIOCSIWNICKN */ - (iw_handler) rt_ioctl_giwnickn, /* SIOCGIWNICKN */ - (iw_handler) NULL, /* -- hole -- */ - (iw_handler) NULL, /* -- hole -- */ - (iw_handler) rt_ioctl_siwrate, /* SIOCSIWRATE */ - (iw_handler) rt_ioctl_giwrate, /* SIOCGIWRATE */ - (iw_handler) rt_ioctl_siwrts, /* SIOCSIWRTS */ - (iw_handler) rt_ioctl_giwrts, /* SIOCGIWRTS */ - (iw_handler) rt_ioctl_siwfrag, /* SIOCSIWFRAG */ - (iw_handler) rt_ioctl_giwfrag, /* SIOCGIWFRAG */ - (iw_handler) NULL, /* SIOCSIWTXPOW */ - (iw_handler) NULL, /* SIOCGIWTXPOW */ - (iw_handler) NULL, /* SIOCSIWRETRY */ - (iw_handler) NULL, /* SIOCGIWRETRY */ - (iw_handler) rt_ioctl_siwencode, /* SIOCSIWENCODE */ - (iw_handler) rt_ioctl_giwencode, /* SIOCGIWENCODE */ - (iw_handler) NULL, /* SIOCSIWPOWER */ - (iw_handler) NULL, /* SIOCGIWPOWER */ - (iw_handler) NULL, /* -- hole -- */ - (iw_handler) NULL, /* -- hole -- */ - (iw_handler) rt_ioctl_siwgenie, /* SIOCSIWGENIE */ - (iw_handler) rt_ioctl_giwgenie, /* SIOCGIWGENIE */ - (iw_handler) rt_ioctl_siwauth, /* SIOCSIWAUTH */ - (iw_handler) rt_ioctl_giwauth, /* SIOCGIWAUTH */ - (iw_handler) rt_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */ - (iw_handler) rt_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */ - (iw_handler) rt_ioctl_siwpmksa, /* SIOCSIWPMKSA */ -}; - -const struct iw_handler_def rt28xx_iw_handler_def = { - .standard = (iw_handler *) rt_handler, - .num_standard = sizeof(rt_handler) / sizeof(iw_handler), -#if IW_HANDLER_VERSION >= 7 - .get_wireless_stats = rt28xx_get_wireless_stats, -#endif -}; - -int rt28xx_sta_ioctl(IN struct net_device *net_dev, - IN OUT struct ifreq *rq, int cmd) -{ - struct os_cookie *pObj; - struct rt_rtmp_adapter *pAd = NULL; - struct iwreq *wrq = (struct iwreq *)rq; - BOOLEAN StateMachineTouched = FALSE; - int Status = NDIS_STATUS_SUCCESS; - - GET_PAD_FROM_NET_DEV(pAd, net_dev); - - pObj = (struct os_cookie *)pAd->OS_Cookie; - - /*check if the interface is down */ - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_INTERRUPT_IN_USE)) { - { - DBGPRINT(RT_DEBUG_TRACE, ("INFO::Network is down!\n")); - return -ENETDOWN; - } - } - - { /* determine this ioctl command is coming from which interface. */ - pObj->ioctl_if_type = INT_MAIN; - pObj->ioctl_if = MAIN_MBSSID; - } - - switch (cmd) { - case SIOCGIFHWADDR: - DBGPRINT(RT_DEBUG_TRACE, ("IOCTL::SIOCGIFHWADDR\n")); - memcpy(wrq->u.name, pAd->CurrentAddress, ETH_ALEN); - break; - case SIOCGIWNAME: - { - char *name = &wrq->u.name[0]; - rt_ioctl_giwname(net_dev, NULL, name, NULL); - break; - } - case SIOCGIWESSID: /*Get ESSID */ - { - struct iw_point *essid = &wrq->u.essid; - rt_ioctl_giwessid(net_dev, NULL, essid, essid->pointer); - break; - } - case SIOCSIWESSID: /*Set ESSID */ - { - struct iw_point *essid = &wrq->u.essid; - rt_ioctl_siwessid(net_dev, NULL, essid, essid->pointer); - break; - } - case SIOCSIWNWID: /* set network id (the cell) */ - case SIOCGIWNWID: /* get network id */ - Status = -EOPNOTSUPP; - break; - case SIOCSIWFREQ: /*set channel/frequency (Hz) */ - { - struct iw_freq *freq = &wrq->u.freq; - rt_ioctl_siwfreq(net_dev, NULL, freq, NULL); - break; - } - case SIOCGIWFREQ: /* get channel/frequency (Hz) */ - { - struct iw_freq *freq = &wrq->u.freq; - rt_ioctl_giwfreq(net_dev, NULL, freq, NULL); - break; - } - case SIOCSIWNICKN: /*set node name/nickname */ - { - /*struct iw_point *data=&wrq->u.data; */ - /*rt_ioctl_siwnickn(net_dev, NULL, data, NULL); */ - break; - } - case SIOCGIWNICKN: /*get node name/nickname */ - { - struct iw_point *erq = NULL; - erq = &wrq->u.data; - erq->length = strlen((char *)pAd->nickname); - Status = - copy_to_user(erq->pointer, pAd->nickname, - erq->length); - if (Status) - Status = -EFAULT; - break; - } - case SIOCGIWRATE: /*get default bit rate (bps) */ - rt_ioctl_giwrate(net_dev, NULL, &wrq->u, NULL); - break; - case SIOCSIWRATE: /*set default bit rate (bps) */ - rt_ioctl_siwrate(net_dev, NULL, &wrq->u, NULL); - break; - case SIOCGIWRTS: /* get RTS/CTS threshold (bytes) */ - { - struct iw_param *rts = &wrq->u.rts; - rt_ioctl_giwrts(net_dev, NULL, rts, NULL); - break; - } - case SIOCSIWRTS: /*set RTS/CTS threshold (bytes) */ - { - struct iw_param *rts = &wrq->u.rts; - rt_ioctl_siwrts(net_dev, NULL, rts, NULL); - break; - } - case SIOCGIWFRAG: /*get fragmentation thr (bytes) */ - { - struct iw_param *frag = &wrq->u.frag; - rt_ioctl_giwfrag(net_dev, NULL, frag, NULL); - break; - } - case SIOCSIWFRAG: /*set fragmentation thr (bytes) */ - { - struct iw_param *frag = &wrq->u.frag; - rt_ioctl_siwfrag(net_dev, NULL, frag, NULL); - break; - } - case SIOCGIWENCODE: /*get encoding token & mode */ - { - struct iw_point *erq = &wrq->u.encoding; - if (erq) - rt_ioctl_giwencode(net_dev, NULL, erq, - erq->pointer); - break; - } - case SIOCSIWENCODE: /*set encoding token & mode */ - { - struct iw_point *erq = &wrq->u.encoding; - if (erq) - rt_ioctl_siwencode(net_dev, NULL, erq, - erq->pointer); - break; - } - case SIOCGIWAP: /*get access point MAC addresses */ - { - struct sockaddr *ap_addr = &wrq->u.ap_addr; - rt_ioctl_giwap(net_dev, NULL, ap_addr, - ap_addr->sa_data); - break; - } - case SIOCSIWAP: /*set access point MAC addresses */ - { - struct sockaddr *ap_addr = &wrq->u.ap_addr; - rt_ioctl_siwap(net_dev, NULL, ap_addr, - ap_addr->sa_data); - break; - } - case SIOCGIWMODE: /*get operation mode */ - { - __u32 *mode = &wrq->u.mode; - rt_ioctl_giwmode(net_dev, NULL, mode, NULL); - break; - } - case SIOCSIWMODE: /*set operation mode */ - { - __u32 *mode = &wrq->u.mode; - rt_ioctl_siwmode(net_dev, NULL, mode, NULL); - break; - } - case SIOCGIWSENS: /*get sensitivity (dBm) */ - case SIOCSIWSENS: /*set sensitivity (dBm) */ - case SIOCGIWPOWER: /*get Power Management settings */ - case SIOCSIWPOWER: /*set Power Management settings */ - case SIOCGIWTXPOW: /*get transmit power (dBm) */ - case SIOCSIWTXPOW: /*set transmit power (dBm) */ - case SIOCGIWRANGE: /*Get range of parameters */ - case SIOCGIWRETRY: /*get retry limits and lifetime */ - case SIOCSIWRETRY: /*set retry limits and lifetime */ - case RT_PRIV_IOCTL: - case RT_PRIV_IOCTL_EXT: - case RTPRIV_IOCTL_SET: - case RTPRIV_IOCTL_GSITESURVEY: - case SIOCGIWPRIV: - Status = -EOPNOTSUPP; - break; - case SIOCETHTOOL: - break; - default: - DBGPRINT(RT_DEBUG_ERROR, - ("IOCTL::unknown IOCTL's cmd = 0x%08x\n", cmd)); - Status = -EOPNOTSUPP; - break; - } - - if (StateMachineTouched) /* Upper layer sent a MLME-related operations */ - RTMP_MLME_HANDLER(pAd); - - return Status; -} - -/* - ========================================================================== - Description: - Set SSID - Return: - TRUE if all parameters are OK, FALSE otherwise - ========================================================================== -*/ -int Set_SSID_Proc(struct rt_rtmp_adapter *pAdapter, char *arg) -{ - struct rt_ndis_802_11_ssid Ssid, *pSsid = NULL; - BOOLEAN StateMachineTouched = FALSE; - int success = TRUE; - - if (strlen(arg) <= MAX_LEN_OF_SSID) { - NdisZeroMemory(&Ssid, sizeof(struct rt_ndis_802_11_ssid)); - if (strlen(arg) != 0) { - NdisMoveMemory(Ssid.Ssid, arg, strlen(arg)); - Ssid.SsidLength = strlen(arg); - } else /*ANY ssid */ - { - Ssid.SsidLength = 0; - memcpy(Ssid.Ssid, "", 0); - pAdapter->StaCfg.BssType = BSS_INFRA; - pAdapter->StaCfg.AuthMode = Ndis802_11AuthModeOpen; - pAdapter->StaCfg.WepStatus = - Ndis802_11EncryptionDisabled; - } - pSsid = &Ssid; - - if (pAdapter->Mlme.CntlMachine.CurrState != CNTL_IDLE) { - RTMP_MLME_RESET_STATE_MACHINE(pAdapter); - DBGPRINT(RT_DEBUG_TRACE, - ("MLME busy, reset MLME state machine!\n")); - } - - if ((pAdapter->StaCfg.WpaPassPhraseLen >= 8) && - (pAdapter->StaCfg.WpaPassPhraseLen <= 64)) { - char passphrase_str[65] = { 0 }; - u8 keyMaterial[40]; - - RTMPMoveMemory(passphrase_str, - pAdapter->StaCfg.WpaPassPhrase, - pAdapter->StaCfg.WpaPassPhraseLen); - RTMPZeroMemory(pAdapter->StaCfg.PMK, 32); - if (pAdapter->StaCfg.WpaPassPhraseLen == 64) { - AtoH((char *)pAdapter->StaCfg.WpaPassPhrase, - pAdapter->StaCfg.PMK, 32); - } else { - PasswordHash((char *)pAdapter->StaCfg. - WpaPassPhrase, Ssid.Ssid, - Ssid.SsidLength, keyMaterial); - NdisMoveMemory(pAdapter->StaCfg.PMK, - keyMaterial, 32); - } - } - - pAdapter->MlmeAux.CurrReqIsFromNdis = TRUE; - pAdapter->StaCfg.bScanReqIsFromWebUI = FALSE; - pAdapter->bConfigChanged = TRUE; - - MlmeEnqueue(pAdapter, - MLME_CNTL_STATE_MACHINE, - OID_802_11_SSID, - sizeof(struct rt_ndis_802_11_ssid), (void *) pSsid); - - StateMachineTouched = TRUE; - DBGPRINT(RT_DEBUG_TRACE, - ("Set_SSID_Proc::(Len=%d,Ssid=%s)\n", Ssid.SsidLength, - Ssid.Ssid)); - } else - success = FALSE; - - if (StateMachineTouched) /* Upper layer sent a MLME-related operations */ - RTMP_MLME_HANDLER(pAdapter); - - return success; -} - -/* - ========================================================================== - Description: - Set Network Type(Infrastructure/Adhoc mode) - Return: - TRUE if all parameters are OK, FALSE otherwise - ========================================================================== -*/ -int Set_NetworkType_Proc(struct rt_rtmp_adapter *pAdapter, char *arg) -{ - u32 Value = 0; - - if (strcmp(arg, "Adhoc") == 0) { - if (pAdapter->StaCfg.BssType != BSS_ADHOC) { - /* Config has changed */ - pAdapter->bConfigChanged = TRUE; - if (MONITOR_ON(pAdapter)) { - RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, - STANORMAL); - RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value); - Value &= (~0x80); - RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value); - OPSTATUS_CLEAR_FLAG(pAdapter, - fOP_STATUS_MEDIA_STATE_CONNECTED); - pAdapter->StaCfg.bAutoReconnect = TRUE; - LinkDown(pAdapter, FALSE); - } - if (INFRA_ON(pAdapter)) { - /*BOOLEAN Cancelled; */ - /* Set the AutoReconnectSsid to prevent it from reconnecting to the old SSID */ - /* Since calling this indicates users don't want to connect to that SSID anymore. */ - pAdapter->MlmeAux.AutoReconnectSsidLen = 32; - NdisZeroMemory(pAdapter->MlmeAux. - AutoReconnectSsid, - pAdapter->MlmeAux. - AutoReconnectSsidLen); - - LinkDown(pAdapter, FALSE); - - DBGPRINT(RT_DEBUG_TRACE, - ("NDIS_STATUS_MEDIA_DISCONNECT Event BB!\n")); - } - } - pAdapter->StaCfg.BssType = BSS_ADHOC; - pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType; - DBGPRINT(RT_DEBUG_TRACE, - ("===>Set_NetworkType_Proc::(AD-HOC)\n")); - } else if (strcmp(arg, "Infra") == 0) { - if (pAdapter->StaCfg.BssType != BSS_INFRA) { - /* Config has changed */ - pAdapter->bConfigChanged = TRUE; - if (MONITOR_ON(pAdapter)) { - RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, - STANORMAL); - RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value); - Value &= (~0x80); - RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value); - OPSTATUS_CLEAR_FLAG(pAdapter, - fOP_STATUS_MEDIA_STATE_CONNECTED); - pAdapter->StaCfg.bAutoReconnect = TRUE; - LinkDown(pAdapter, FALSE); - } - if (ADHOC_ON(pAdapter)) { - /* Set the AutoReconnectSsid to prevent it from reconnecting to the old SSID */ - /* Since calling this indicates users don't want to connect to that SSID anymore. */ - pAdapter->MlmeAux.AutoReconnectSsidLen = 32; - NdisZeroMemory(pAdapter->MlmeAux. - AutoReconnectSsid, - pAdapter->MlmeAux. - AutoReconnectSsidLen); - - LinkDown(pAdapter, FALSE); - } - } - pAdapter->StaCfg.BssType = BSS_INFRA; - pAdapter->net_dev->type = pAdapter->StaCfg.OriDevType; - DBGPRINT(RT_DEBUG_TRACE, - ("===>Set_NetworkType_Proc::(INFRA)\n")); - } else if (strcmp(arg, "Monitor") == 0) { - u8 bbpValue = 0; - BCN_TIME_CFG_STRUC csr; - OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_INFRA_ON); - OPSTATUS_CLEAR_FLAG(pAdapter, fOP_STATUS_ADHOC_ON); - OPSTATUS_SET_FLAG(pAdapter, fOP_STATUS_MEDIA_STATE_CONNECTED); - /* disable all periodic state machine */ - pAdapter->StaCfg.bAutoReconnect = FALSE; - /* reset all mlme state machine */ - RTMP_MLME_RESET_STATE_MACHINE(pAdapter); - DBGPRINT(RT_DEBUG_TRACE, - ("fOP_STATUS_MEDIA_STATE_CONNECTED \n")); - if (pAdapter->CommonCfg.CentralChannel == 0) { - if (pAdapter->CommonCfg.PhyMode == PHY_11AN_MIXED) - pAdapter->CommonCfg.CentralChannel = 36; - else - pAdapter->CommonCfg.CentralChannel = 6; - } else - N_ChannelCheck(pAdapter); - - if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED && - pAdapter->CommonCfg.RegTransmitSetting.field.BW == BW_40 && - pAdapter->CommonCfg.RegTransmitSetting.field.EXTCHA == - EXTCHA_ABOVE) { - /* 40MHz ,control channel at lower */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, - &bbpValue); - bbpValue &= (~0x18); - bbpValue |= 0x10; - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, - bbpValue); - pAdapter->CommonCfg.BBPCurrentBW = BW_40; - /* RX : control channel at lower */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, - &bbpValue); - bbpValue &= (~0x20); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, - bbpValue); - - RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value); - Value &= 0xfffffffe; - RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value); - pAdapter->CommonCfg.CentralChannel = - pAdapter->CommonCfg.Channel + 2; - AsicSwitchChannel(pAdapter, - pAdapter->CommonCfg.CentralChannel, - FALSE); - AsicLockChannel(pAdapter, - pAdapter->CommonCfg.CentralChannel); - DBGPRINT(RT_DEBUG_TRACE, - ("BW_40 ,control_channel(%d), CentralChannel(%d) \n", - pAdapter->CommonCfg.Channel, - pAdapter->CommonCfg.CentralChannel)); - } else if (pAdapter->CommonCfg.PhyMode >= PHY_11ABGN_MIXED - && pAdapter->CommonCfg.RegTransmitSetting.field.BW == - BW_40 - && pAdapter->CommonCfg.RegTransmitSetting.field. - EXTCHA == EXTCHA_BELOW) { - /* 40MHz ,control channel at upper */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, - &bbpValue); - bbpValue &= (~0x18); - bbpValue |= 0x10; - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, - bbpValue); - pAdapter->CommonCfg.BBPCurrentBW = BW_40; - RTMP_IO_READ32(pAdapter, TX_BAND_CFG, &Value); - Value |= 0x1; - RTMP_IO_WRITE32(pAdapter, TX_BAND_CFG, Value); - - RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R3, - &bbpValue); - bbpValue |= (0x20); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R3, - bbpValue); - pAdapter->CommonCfg.CentralChannel = - pAdapter->CommonCfg.Channel - 2; - AsicSwitchChannel(pAdapter, - pAdapter->CommonCfg.CentralChannel, - FALSE); - AsicLockChannel(pAdapter, - pAdapter->CommonCfg.CentralChannel); - DBGPRINT(RT_DEBUG_TRACE, - ("BW_40 ,control_channel(%d), CentralChannel(%d) \n", - pAdapter->CommonCfg.Channel, - pAdapter->CommonCfg.CentralChannel)); - } else { - /* 20MHz */ - RTMP_BBP_IO_READ8_BY_REG_ID(pAdapter, BBP_R4, - &bbpValue); - bbpValue &= (~0x18); - RTMP_BBP_IO_WRITE8_BY_REG_ID(pAdapter, BBP_R4, - bbpValue); - pAdapter->CommonCfg.BBPCurrentBW = BW_20; - AsicSwitchChannel(pAdapter, pAdapter->CommonCfg.Channel, - FALSE); - AsicLockChannel(pAdapter, pAdapter->CommonCfg.Channel); - DBGPRINT(RT_DEBUG_TRACE, - ("BW_20, Channel(%d)\n", - pAdapter->CommonCfg.Channel)); - } - /* Enable Rx with promiscuous reception */ - RTMP_IO_WRITE32(pAdapter, RX_FILTR_CFG, 0x3); - /* ASIC supports sniffer function with replacing RSSI with timestamp. */ - /*RTMP_IO_READ32(pAdapter, MAC_SYS_CTRL, &Value); */ - /*Value |= (0x80); */ - /*RTMP_IO_WRITE32(pAdapter, MAC_SYS_CTRL, Value); */ - /* disable sync */ - RTMP_IO_READ32(pAdapter, BCN_TIME_CFG, &csr.word); - csr.field.bBeaconGen = 0; - csr.field.bTBTTEnable = 0; - csr.field.TsfSyncMode = 0; - RTMP_IO_WRITE32(pAdapter, BCN_TIME_CFG, csr.word); - - pAdapter->StaCfg.BssType = BSS_MONITOR; - pAdapter->net_dev->type = ARPHRD_IEEE80211_PRISM; /*ARPHRD_IEEE80211; // IEEE80211 */ - DBGPRINT(RT_DEBUG_TRACE, - ("===>Set_NetworkType_Proc::(MONITOR)\n")); - } - /* Reset Ralink supplicant to not use, it will be set to start when UI set PMK key */ - pAdapter->StaCfg.WpaState = SS_NOTUSE; - - DBGPRINT(RT_DEBUG_TRACE, - ("Set_NetworkType_Proc::(NetworkType=%d)\n", - pAdapter->StaCfg.BssType)); - - return TRUE; -} diff --git a/trunk/drivers/staging/rt2860/usb_main_dev.c b/trunk/drivers/staging/rt2860/usb_main_dev.c deleted file mode 100644 index 322bf49ee906..000000000000 --- a/trunk/drivers/staging/rt2860/usb_main_dev.c +++ /dev/null @@ -1,927 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - *************************************************************************/ - -#include "rt_config.h" - -/* Following information will be show when you run 'modinfo' */ -/* If you have a solution for the bug in current version of driver, please e-mail me. */ -/* Otherwise post to the forum at ralinktech's web site(www.ralinktech.com) and let all users help you. */ -MODULE_AUTHOR("Paul Lin "); -MODULE_DESCRIPTION("RT2870/RT3070 Wireless Lan Linux Driver"); -MODULE_LICENSE("GPL"); -#ifdef MODULE_VERSION -MODULE_VERSION(STA_DRIVER_VERSION); -#endif - -/* module table */ -struct usb_device_id rtusb_usb_id[] = { -#ifdef RT2870 - {USB_DEVICE(0x148F, 0x2770)}, /* Ralink */ - {USB_DEVICE(0x148F, 0x2870)}, /* Ralink */ - {USB_DEVICE(0x07B8, 0x2870)}, /* AboCom */ - {USB_DEVICE(0x07B8, 0x2770)}, /* AboCom */ - {USB_DEVICE(0x0DF6, 0x0039)}, /* Sitecom 2770 */ - {USB_DEVICE(0x0DF6, 0x003F)}, /* Sitecom 2770 */ - {USB_DEVICE(0x083A, 0x7512)}, /* Arcadyan 2770 */ - {USB_DEVICE(0x0789, 0x0162)}, /* Logitec 2870 */ - {USB_DEVICE(0x0789, 0x0163)}, /* Logitec 2870 */ - {USB_DEVICE(0x0789, 0x0164)}, /* Logitec 2870 */ - {USB_DEVICE(0x177f, 0x0302)}, /* lsusb */ - {USB_DEVICE(0x0B05, 0x1731)}, /* Asus */ - {USB_DEVICE(0x0B05, 0x1732)}, /* Asus */ - {USB_DEVICE(0x0B05, 0x1742)}, /* Asus */ - {USB_DEVICE(0x0DF6, 0x0017)}, /* Sitecom */ - {USB_DEVICE(0x0DF6, 0x002B)}, /* Sitecom */ - {USB_DEVICE(0x0DF6, 0x002C)}, /* Sitecom */ - {USB_DEVICE(0x0DF6, 0x002D)}, /* Sitecom */ - {USB_DEVICE(0x14B2, 0x3C06)}, /* Conceptronic */ - {USB_DEVICE(0x14B2, 0x3C28)}, /* Conceptronic */ - {USB_DEVICE(0x2019, 0xED06)}, /* Planex Communications, Inc. */ - {USB_DEVICE(0x07D1, 0x3C09)}, /* D-Link */ - {USB_DEVICE(0x07D1, 0x3C11)}, /* D-Link */ - {USB_DEVICE(0x14B2, 0x3C07)}, /* AL */ - {USB_DEVICE(0x050D, 0x8053)}, /* Belkin */ - {USB_DEVICE(0x050D, 0x825B)}, /* Belkin */ - {USB_DEVICE(0x050D, 0x935A)}, /* Belkin F6D4050 v1 */ - {USB_DEVICE(0x050D, 0x935B)}, /* Belkin F6D4050 v2 */ - {USB_DEVICE(0x14B2, 0x3C23)}, /* Airlink */ - {USB_DEVICE(0x14B2, 0x3C27)}, /* Airlink */ - {USB_DEVICE(0x07AA, 0x002F)}, /* Corega */ - {USB_DEVICE(0x07AA, 0x003C)}, /* Corega */ - {USB_DEVICE(0x07AA, 0x003F)}, /* Corega */ - {USB_DEVICE(0x1044, 0x800B)}, /* Gigabyte */ - {USB_DEVICE(0x15A9, 0x0006)}, /* Sparklan */ - {USB_DEVICE(0x083A, 0xB522)}, /* SMC */ - {USB_DEVICE(0x083A, 0xA618)}, /* SMC */ - {USB_DEVICE(0x083A, 0x8522)}, /* Arcadyan */ - {USB_DEVICE(0x083A, 0x7522)}, /* Arcadyan */ - {USB_DEVICE(0x0CDE, 0x0022)}, /* ZCOM */ - {USB_DEVICE(0x0586, 0x3416)}, /* Zyxel */ - {USB_DEVICE(0x0586, 0x341a)}, /* Zyxel NWD-270N */ - {USB_DEVICE(0x0CDE, 0x0025)}, /* Zyxel */ - {USB_DEVICE(0x1740, 0x9701)}, /* EnGenius */ - {USB_DEVICE(0x1740, 0x9702)}, /* EnGenius */ - {USB_DEVICE(0x0471, 0x200f)}, /* Philips */ - {USB_DEVICE(0x14B2, 0x3C25)}, /* Draytek */ - {USB_DEVICE(0x13D3, 0x3247)}, /* AzureWave */ - {USB_DEVICE(0x083A, 0x6618)}, /* Accton */ - {USB_DEVICE(0x15c5, 0x0008)}, /* Amit */ - {USB_DEVICE(0x0E66, 0x0001)}, /* Hawking */ - {USB_DEVICE(0x0E66, 0x0003)}, /* Hawking */ - {USB_DEVICE(0x129B, 0x1828)}, /* Siemens */ - {USB_DEVICE(0x157E, 0x300E)}, /* U-Media */ - {USB_DEVICE(0x050d, 0x805c)}, - {USB_DEVICE(0x050d, 0x815c)}, - {USB_DEVICE(0x1482, 0x3C09)}, /* Abocom */ - {USB_DEVICE(0x14B2, 0x3C09)}, /* Alpha */ - {USB_DEVICE(0x04E8, 0x2018)}, /* samsung linkstick2 */ - {USB_DEVICE(0x1690, 0x0740)}, /* Askey */ - {USB_DEVICE(0x5A57, 0x0280)}, /* Zinwell */ - {USB_DEVICE(0x5A57, 0x0282)}, /* Zinwell */ - {USB_DEVICE(0x7392, 0x7718)}, - {USB_DEVICE(0x7392, 0x7717)}, - {USB_DEVICE(0x0411, 0x016f)}, /* MelCo.,Inc. WLI-UC-G301N */ - {USB_DEVICE(0x1737, 0x0070)}, /* Linksys WUSB100 */ - {USB_DEVICE(0x1737, 0x0071)}, /* Linksys WUSB600N */ - {USB_DEVICE(0x1737, 0x0078)}, /* Linksys WUSB100v2 */ - {USB_DEVICE(0x0411, 0x00e8)}, /* Buffalo WLI-UC-G300N */ - {USB_DEVICE(0x050d, 0x815c)}, /* Belkin F5D8053 */ - {USB_DEVICE(0x100D, 0x9031)}, /* Motorola 2770 */ -#endif /* RT2870 // */ -#ifdef RT3070 - {USB_DEVICE(0x148F, 0x3070)}, /* Ralink 3070 */ - {USB_DEVICE(0x148F, 0x3071)}, /* Ralink 3071 */ - {USB_DEVICE(0x148F, 0x3072)}, /* Ralink 3072 */ - {USB_DEVICE(0x0DB0, 0x3820)}, /* Ralink 3070 */ - {USB_DEVICE(0x0DB0, 0x871C)}, /* Ralink 3070 */ - {USB_DEVICE(0x0DB0, 0x822C)}, /* Ralink 3070 */ - {USB_DEVICE(0x0DB0, 0x871B)}, /* Ralink 3070 */ - {USB_DEVICE(0x0DB0, 0x822B)}, /* Ralink 3070 */ - {USB_DEVICE(0x0DF6, 0x003E)}, /* Sitecom 3070 */ - {USB_DEVICE(0x0DF6, 0x0042)}, /* Sitecom 3072 */ - {USB_DEVICE(0x0DF6, 0x0048)}, /* Sitecom 3070 */ - {USB_DEVICE(0x0DF6, 0x0047)}, /* Sitecom 3071 */ - {USB_DEVICE(0x14B2, 0x3C12)}, /* AL 3070 */ - {USB_DEVICE(0x18C5, 0x0012)}, /* Corega 3070 */ - {USB_DEVICE(0x083A, 0x7511)}, /* Arcadyan 3070 */ - {USB_DEVICE(0x083A, 0xA701)}, /* SMC 3070 */ - {USB_DEVICE(0x083A, 0xA702)}, /* SMC 3072 */ - {USB_DEVICE(0x1740, 0x9703)}, /* EnGenius 3070 */ - {USB_DEVICE(0x1740, 0x9705)}, /* EnGenius 3071 */ - {USB_DEVICE(0x1740, 0x9706)}, /* EnGenius 3072 */ - {USB_DEVICE(0x1740, 0x9707)}, /* EnGenius 3070 */ - {USB_DEVICE(0x1740, 0x9708)}, /* EnGenius 3071 */ - {USB_DEVICE(0x1740, 0x9709)}, /* EnGenius 3072 */ - {USB_DEVICE(0x13D3, 0x3273)}, /* AzureWave 3070 */ - {USB_DEVICE(0x13D3, 0x3305)}, /* AzureWave 3070*/ - {USB_DEVICE(0x1044, 0x800D)}, /* Gigabyte GN-WB32L 3070 */ - {USB_DEVICE(0x2019, 0xAB25)}, /* Planex Communications, Inc. RT3070 */ - {USB_DEVICE(0x07B8, 0x3070)}, /* AboCom 3070 */ - {USB_DEVICE(0x07B8, 0x3071)}, /* AboCom 3071 */ - {USB_DEVICE(0x07B8, 0x3072)}, /* Abocom 3072 */ - {USB_DEVICE(0x7392, 0x7711)}, /* Edimax 3070 */ - {USB_DEVICE(0x1A32, 0x0304)}, /* Quanta 3070 */ - {USB_DEVICE(0x1EDA, 0x2310)}, /* AirTies 3070 */ - {USB_DEVICE(0x07D1, 0x3C0A)}, /* D-Link 3072 */ - {USB_DEVICE(0x07D1, 0x3C0D)}, /* D-Link 3070 */ - {USB_DEVICE(0x07D1, 0x3C0E)}, /* D-Link 3070 */ - {USB_DEVICE(0x07D1, 0x3C0F)}, /* D-Link 3070 */ - {USB_DEVICE(0x07D1, 0x3C16)}, /* D-Link 3070 */ - {USB_DEVICE(0x07D1, 0x3C17)}, /* D-Link 8070 */ - {USB_DEVICE(0x1D4D, 0x000C)}, /* Pegatron Corporation 3070 */ - {USB_DEVICE(0x1D4D, 0x000E)}, /* Pegatron Corporation 3070 */ - {USB_DEVICE(0x5A57, 0x5257)}, /* Zinwell 3070 */ - {USB_DEVICE(0x5A57, 0x0283)}, /* Zinwell 3072 */ - {USB_DEVICE(0x04BB, 0x0945)}, /* I-O DATA 3072 */ - {USB_DEVICE(0x04BB, 0x0947)}, /* I-O DATA 3070 */ - {USB_DEVICE(0x04BB, 0x0948)}, /* I-O DATA 3072 */ - {USB_DEVICE(0x203D, 0x1480)}, /* Encore 3070 */ - {USB_DEVICE(0x20B8, 0x8888)}, /* PARA INDUSTRIAL 3070 */ - {USB_DEVICE(0x0B05, 0x1784)}, /* Asus 3072 */ - {USB_DEVICE(0x203D, 0x14A9)}, /* Encore 3070*/ - {USB_DEVICE(0x0DB0, 0x899A)}, /* MSI 3070*/ - {USB_DEVICE(0x0DB0, 0x3870)}, /* MSI 3070*/ - {USB_DEVICE(0x0DB0, 0x870A)}, /* MSI 3070*/ - {USB_DEVICE(0x0DB0, 0x6899)}, /* MSI 3070 */ - {USB_DEVICE(0x0DB0, 0x3822)}, /* MSI 3070 */ - {USB_DEVICE(0x0DB0, 0x3871)}, /* MSI 3070 */ - {USB_DEVICE(0x0DB0, 0x871A)}, /* MSI 3070 */ - {USB_DEVICE(0x0DB0, 0x822A)}, /* MSI 3070 */ - {USB_DEVICE(0x0DB0, 0x3821)}, /* Ralink 3070 */ - {USB_DEVICE(0x0DB0, 0x821A)}, /* Ralink 3070 */ - {USB_DEVICE(0x083A, 0xA703)}, /* IO-MAGIC */ - {USB_DEVICE(0x13D3, 0x3307)}, /* Azurewave */ - {USB_DEVICE(0x13D3, 0x3321)}, /* Azurewave */ - {USB_DEVICE(0x07FA, 0x7712)}, /* Edimax */ - {USB_DEVICE(0x0789, 0x0166)}, /* Edimax */ - {USB_DEVICE(0x148F, 0x2070)}, /* Edimax */ -#endif /* RT3070 // */ - {USB_DEVICE(0x1737, 0x0077)}, /* Linksys WUSB54GC-EU v3 */ - {USB_DEVICE(0x2001, 0x3C09)}, /* D-Link */ - {USB_DEVICE(0x2001, 0x3C0A)}, /* D-Link 3072 */ - {USB_DEVICE(0x2019, 0xED14)}, /* Planex Communications, Inc. */ - {USB_DEVICE(0x0411, 0x015D)}, /* Buffalo Airstation WLI-UC-GN */ - {} /* Terminating entry */ -}; - -int const rtusb_usb_id_len = - sizeof(rtusb_usb_id) / sizeof(struct usb_device_id); - -MODULE_DEVICE_TABLE(usb, rtusb_usb_id); - -static void rt2870_disconnect(struct usb_device *dev, struct rt_rtmp_adapter *pAd); - -static int __devinit rt2870_probe(IN struct usb_interface *intf, - IN struct usb_device *usb_dev, - IN const struct usb_device_id *dev_id, - struct rt_rtmp_adapter **ppAd); - -#ifndef PF_NOFREEZE -#define PF_NOFREEZE 0 -#endif - -extern int rt28xx_close(IN struct net_device *net_dev); -extern int rt28xx_open(struct net_device *net_dev); - -static BOOLEAN USBDevConfigInit(IN struct usb_device *dev, - IN struct usb_interface *intf, - struct rt_rtmp_adapter *pAd); - -/* -======================================================================== -Routine Description: - Check the chipset vendor/product ID. - -Arguments: - _dev_p Point to the PCI or USB device - -Return Value: - TRUE Check ok - FALSE Check fail - -Note: -======================================================================== -*/ -BOOLEAN RT28XXChipsetCheck(IN void *_dev_p) -{ - struct usb_interface *intf = (struct usb_interface *)_dev_p; - struct usb_device *dev_p = interface_to_usbdev(intf); - u32 i; - - for (i = 0; i < rtusb_usb_id_len; i++) { - if (dev_p->descriptor.idVendor == rtusb_usb_id[i].idVendor && - dev_p->descriptor.idProduct == rtusb_usb_id[i].idProduct) { - printk(KERN_INFO "rt2870: idVendor = 0x%x, idProduct = 0x%x\n", - dev_p->descriptor.idVendor, - dev_p->descriptor.idProduct); - break; - } - } - - if (i == rtusb_usb_id_len) { - printk(KERN_ERR "rt2870: Error! Device Descriptor not matching!\n"); - return FALSE; - } - - return TRUE; -} - -/**************************************************************************/ -/**************************************************************************/ -/*tested for kernel 2.6series */ -/**************************************************************************/ -/**************************************************************************/ - -#ifdef CONFIG_PM -static int rt2870_suspend(struct usb_interface *intf, pm_message_t state); -static int rt2870_resume(struct usb_interface *intf); -#endif /* CONFIG_PM // */ - -static BOOLEAN USBDevConfigInit(IN struct usb_device *dev, - IN struct usb_interface *intf, - struct rt_rtmp_adapter *pAd) -{ - struct usb_host_interface *iface_desc; - unsigned long BulkOutIdx; - u32 i; - - /* get the active interface descriptor */ - iface_desc = intf->cur_altsetting; - - /* get # of enpoints */ - pAd->NumberOfPipes = iface_desc->desc.bNumEndpoints; - DBGPRINT(RT_DEBUG_TRACE, - ("NumEndpoints=%d\n", iface_desc->desc.bNumEndpoints)); - - /* Configure Pipes */ - BulkOutIdx = 0; - - for (i = 0; i < pAd->NumberOfPipes; i++) { - if ((iface_desc->endpoint[i].desc.bmAttributes == - USB_ENDPOINT_XFER_BULK) && - ((iface_desc->endpoint[i].desc.bEndpointAddress & - USB_ENDPOINT_DIR_MASK) == USB_DIR_IN)) { - pAd->BulkInEpAddr = - iface_desc->endpoint[i].desc.bEndpointAddress; - pAd->BulkInMaxPacketSize = - le2cpu16(iface_desc->endpoint[i].desc. - wMaxPacketSize); - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("BULK IN MaxPacketSize = %d\n", - pAd->BulkInMaxPacketSize)); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("EP address = 0x%2x\n", - iface_desc->endpoint[i].desc. - bEndpointAddress)); - } else - if ((iface_desc->endpoint[i].desc.bmAttributes == - USB_ENDPOINT_XFER_BULK) - && - ((iface_desc->endpoint[i].desc. - bEndpointAddress & USB_ENDPOINT_DIR_MASK) == - USB_DIR_OUT)) { - /* there are 6 bulk out EP. EP6 highest priority. */ - /* EP1-4 is EDCA. EP5 is HCCA. */ - pAd->BulkOutEpAddr[BulkOutIdx++] = - iface_desc->endpoint[i].desc.bEndpointAddress; - pAd->BulkOutMaxPacketSize = - le2cpu16(iface_desc->endpoint[i].desc. - wMaxPacketSize); - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("BULK OUT MaxPacketSize = %d\n", - pAd->BulkOutMaxPacketSize)); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("EP address = 0x%2x \n", - iface_desc->endpoint[i].desc. - bEndpointAddress)); - } - } - - if (!(pAd->BulkInEpAddr && pAd->BulkOutEpAddr[0])) { - printk - (KERN_ERR "%s: Could not find both bulk-in and bulk-out endpoints\n", - __FUNCTION__); - return FALSE; - } - - pAd->config = &dev->config->desc; - usb_set_intfdata(intf, pAd); - - return TRUE; - -} - -static int __devinit rtusb_probe(struct usb_interface *intf, - const struct usb_device_id *id) -{ - struct rt_rtmp_adapter *pAd; - struct usb_device *dev; - int rv; - - dev = interface_to_usbdev(intf); - dev = usb_get_dev(dev); - - rv = rt2870_probe(intf, dev, id, &pAd); - if (rv != 0) - usb_put_dev(dev); - - return rv; -} - -static void rtusb_disconnect(struct usb_interface *intf) -{ - struct usb_device *dev = interface_to_usbdev(intf); - struct rt_rtmp_adapter *pAd; - - pAd = usb_get_intfdata(intf); - usb_set_intfdata(intf, NULL); - - rt2870_disconnect(dev, pAd); -} - -struct usb_driver rtusb_driver = { - .name = "rt2870", - .probe = rtusb_probe, - .disconnect = rtusb_disconnect, - .id_table = rtusb_usb_id, - -#ifdef CONFIG_PM -suspend:rt2870_suspend, -resume:rt2870_resume, -#endif -}; - -#ifdef CONFIG_PM - -void RT2870RejectPendingPackets(struct rt_rtmp_adapter *pAd) -{ - /* clear PS packets */ - /* clear TxSw packets */ -} - -static int rt2870_suspend(struct usb_interface *intf, pm_message_t state) -{ - struct net_device *net_dev; - struct rt_rtmp_adapter *pAd = usb_get_intfdata(intf); - - DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_suspend()\n")); - net_dev = pAd->net_dev; - netif_device_detach(net_dev); - - pAd->PM_FlgSuspend = 1; - if (netif_running(net_dev)) { - RTUSBCancelPendingBulkInIRP(pAd); - RTUSBCancelPendingBulkOutIRP(pAd); - } - DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_suspend()\n")); - return 0; -} - -static int rt2870_resume(struct usb_interface *intf) -{ - struct net_device *net_dev; - struct rt_rtmp_adapter *pAd = usb_get_intfdata(intf); - - DBGPRINT(RT_DEBUG_TRACE, ("===> rt2870_resume()\n")); - - pAd->PM_FlgSuspend = 0; - net_dev = pAd->net_dev; - netif_device_attach(net_dev); - netif_start_queue(net_dev); - netif_carrier_on(net_dev); - netif_wake_queue(net_dev); - - DBGPRINT(RT_DEBUG_TRACE, ("<=== rt2870_resume()\n")); - return 0; -} -#endif /* CONFIG_PM // */ - -/* Init driver module */ -int __init rtusb_init(void) -{ - printk(KERN_DEBUG "rtusb init --->\n"); - return usb_register(&rtusb_driver); -} - -/* Deinit driver module */ -void __exit rtusb_exit(void) -{ - usb_deregister(&rtusb_driver); - printk(KERN_DEBUG "<--- rtusb exit\n"); -} - -module_init(rtusb_init); -module_exit(rtusb_exit); - -/*--------------------------------------------------------------------- */ -/* function declarations */ -/*--------------------------------------------------------------------- */ - -/* -======================================================================== -Routine Description: - MLME kernel thread. - -Arguments: - *Context the pAd, driver control block pointer - -Return Value: - 0 close the thread - -Note: -======================================================================== -*/ -int MlmeThread(IN void *Context) -{ - struct rt_rtmp_adapter *pAd; - struct rt_rtmp_os_task *pTask; - int status; - status = 0; - - pTask = Context; - pAd = pTask->priv; - - RtmpOSTaskCustomize(pTask); - - while (!pTask->task_killed) { -#ifdef KTHREAD_SUPPORT - RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask); -#else - RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status); - - /* unlock the device pointers */ - if (status != 0) { - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); - break; - } -#endif - - /* lock the device pointers , need to check if required */ - /*down(&(pAd->usbdev_semaphore)); */ - - if (!pAd->PM_FlgSuspend) - MlmeHandler(pAd); - } - - /* notify the exit routine that we're actually exiting now - * - * complete()/wait_for_completion() is similar to up()/down(), - * except that complete() is safe in the case where the structure - * is getting deleted in a parallel mode of execution (i.e. just - * after the down() -- that's necessary for the thread-shutdown - * case. - * - * complete_and_exit() goes even further than this -- it is safe in - * the case that the thread of the caller is going away (not just - * the structure) -- this is necessary for the module-remove case. - * This is important in preemption kernels, which transfer the flow - * of execution immediately upon a complete(). - */ - DBGPRINT(RT_DEBUG_TRACE, ("<---%s\n", __FUNCTION__)); -#ifndef KTHREAD_SUPPORT - pTask->taskPID = THREAD_PID_INIT_VALUE; - complete_and_exit(&pTask->taskComplete, 0); -#endif - return 0; - -} - -/* -======================================================================== -Routine Description: - USB command kernel thread. - -Arguments: - *Context the pAd, driver control block pointer - -Return Value: - 0 close the thread - -Note: -======================================================================== -*/ -int RTUSBCmdThread(IN void *Context) -{ - struct rt_rtmp_adapter *pAd; - struct rt_rtmp_os_task *pTask; - int status; - status = 0; - - pTask = Context; - pAd = pTask->priv; - - RtmpOSTaskCustomize(pTask); - - NdisAcquireSpinLock(&pAd->CmdQLock); - pAd->CmdQ.CmdQState = RTMP_TASK_STAT_RUNNING; - NdisReleaseSpinLock(&pAd->CmdQLock); - - while (pAd && pAd->CmdQ.CmdQState == RTMP_TASK_STAT_RUNNING) { -#ifdef KTHREAD_SUPPORT - RTMP_WAIT_EVENT_INTERRUPTIBLE(pAd, pTask); -#else - /* lock the device pointers */ - RTMP_SEM_EVENT_WAIT(&(pTask->taskSema), status); - - if (status != 0) { - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); - break; - } -#endif - - if (pAd->CmdQ.CmdQState == RTMP_TASK_STAT_STOPED) - break; - - if (!pAd->PM_FlgSuspend) - CMDHandler(pAd); - } - - if (pAd && !pAd->PM_FlgSuspend) { /* Clear the CmdQElements. */ - struct rt_cmdqelmt *pCmdQElmt = NULL; - - NdisAcquireSpinLock(&pAd->CmdQLock); - pAd->CmdQ.CmdQState = RTMP_TASK_STAT_STOPED; - while (pAd->CmdQ.size) { - RTUSBDequeueCmd(&pAd->CmdQ, &pCmdQElmt); - if (pCmdQElmt) { - if (pCmdQElmt->CmdFromNdis == TRUE) { - if (pCmdQElmt->buffer != NULL) - os_free_mem(pAd, - pCmdQElmt->buffer); - os_free_mem(pAd, (u8 *)pCmdQElmt); - } else { - if ((pCmdQElmt->buffer != NULL) - && (pCmdQElmt->bufferlength != 0)) - os_free_mem(pAd, - pCmdQElmt->buffer); - os_free_mem(pAd, (u8 *)pCmdQElmt); - } - } - } - - NdisReleaseSpinLock(&pAd->CmdQLock); - } - /* notify the exit routine that we're actually exiting now - * - * complete()/wait_for_completion() is similar to up()/down(), - * except that complete() is safe in the case where the structure - * is getting deleted in a parallel mode of execution (i.e. just - * after the down() -- that's necessary for the thread-shutdown - * case. - * - * complete_and_exit() goes even further than this -- it is safe in - * the case that the thread of the caller is going away (not just - * the structure) -- this is necessary for the module-remove case. - * This is important in preemption kernels, which transfer the flow - * of execution immediately upon a complete(). - */ - DBGPRINT(RT_DEBUG_TRACE, ("<---RTUSBCmdThread\n")); - -#ifndef KTHREAD_SUPPORT - pTask->taskPID = THREAD_PID_INIT_VALUE; - complete_and_exit(&pTask->taskComplete, 0); -#endif - return 0; - -} - -void RTUSBWatchDog(struct rt_rtmp_adapter *pAd) -{ - struct rt_ht_tx_context *pHTTXContext; - int idx; - unsigned long irqFlags; - PURB pUrb; - BOOLEAN needDumpSeq = FALSE; - u32 MACValue; - u32 TxRxQ_Pcnt; - - idx = 0; - RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue); - if ((MACValue & 0xff) != 0) { - DBGPRINT(RT_DEBUG_TRACE, - ("TX QUEUE 0 Not EMPTY(Value=0x%0x)!\n", - MACValue)); - RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40012); - while ((MACValue & 0xff) != 0 && (idx++ < 10)) { - RTMP_IO_READ32(pAd, TXRXQ_PCNT, &MACValue); - RTMPusecDelay(1); - } - RTMP_IO_WRITE32(pAd, PBF_CFG, 0xf40006); - } - - if (pAd->watchDogRxOverFlowCnt >= 2) { - DBGPRINT(RT_DEBUG_TRACE, - ("Maybe the Rx Bulk-In hanged! Cancel the pending Rx bulks request!\n")); - if ((!RTMP_TEST_FLAG - (pAd, - (fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_BULKIN_RESET | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST)))) { - DBGPRINT(RT_DEBUG_TRACE, - ("Call CMDTHREAD_RESET_BULK_IN to cancel the pending Rx Bulk!\n")); - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKIN_RESET); - RTUSBEnqueueInternalCmd(pAd, CMDTHREAD_RESET_BULK_IN, - NULL, 0); - needDumpSeq = TRUE; - } - pAd->watchDogRxOverFlowCnt = 0; - } - - RTUSBReadMACRegister(pAd, 0x438, &TxRxQ_Pcnt); - - for (idx = 0; idx < NUM_OF_TX_RING; idx++) { - pUrb = NULL; - - RTMP_IRQ_LOCK(&pAd->BulkOutLock[idx], irqFlags); - if ((pAd->BulkOutPending[idx] == TRUE) - && pAd->watchDogTxPendingCnt) { - int actual_length = 0, transfer_buffer_length = 0; - BOOLEAN isDataPacket = FALSE; - pAd->watchDogTxPendingCnt[idx]++; - - if ((pAd->watchDogTxPendingCnt[idx] > 2) && - (!RTMP_TEST_FLAG - (pAd, - (fRTMP_ADAPTER_RESET_IN_PROGRESS | - fRTMP_ADAPTER_HALT_IN_PROGRESS | - fRTMP_ADAPTER_NIC_NOT_EXIST | - fRTMP_ADAPTER_BULKOUT_RESET))) - ) { - /* FIXME: Following code just support single bulk out. If you wanna support multiple bulk out. Modify it! */ - pHTTXContext = - (struct rt_ht_tx_context *)(&pAd->TxContext[idx]); - if (pHTTXContext->IRPPending) { /* Check TxContext. */ - pUrb = pHTTXContext->pUrb; - - actual_length = pUrb->actual_length; - transfer_buffer_length = - pUrb->transfer_buffer_length; - isDataPacket = TRUE; - } else if (idx == MGMTPIPEIDX) { - struct rt_tx_context *pMLMEContext, *pNULLContext, - *pPsPollContext; - - /*Check MgmtContext. */ - pMLMEContext = - (struct rt_tx_context *)(pAd->MgmtRing. - Cell[pAd->MgmtRing. - TxDmaIdx]. - AllocVa); - pPsPollContext = - (struct rt_tx_context *)(&pAd->PsPollContext); - pNULLContext = - (struct rt_tx_context *)(&pAd->NullContext); - - if (pMLMEContext->IRPPending) { - ASSERT(pMLMEContext-> - IRPPending); - pUrb = pMLMEContext->pUrb; - } else if (pNULLContext->IRPPending) { - ASSERT(pNULLContext-> - IRPPending); - pUrb = pNULLContext->pUrb; - } else if (pPsPollContext->IRPPending) { - ASSERT(pPsPollContext-> - IRPPending); - pUrb = pPsPollContext->pUrb; - } - } - - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], - irqFlags); - - printk(KERN_INFO "%d:%lu LTL=%d , TL=%d L:%d\n", - idx, pAd->watchDogTxPendingCnt[idx], - pAd->TransferedLength[idx], - actual_length, transfer_buffer_length); - - if (pUrb) { - if ((isDataPacket - && pAd->TransferedLength[idx] == - actual_length - && pAd->TransferedLength[idx] < - transfer_buffer_length - && actual_length != 0 -/* && TxRxQ_Pcnt==0 */ - && pAd->watchDogTxPendingCnt[idx] > - 3) - || isDataPacket == FALSE - || pAd->watchDogTxPendingCnt[idx] > - 6) { - DBGPRINT(RT_DEBUG_TRACE, - ("Maybe the Tx Bulk-Out hanged! Cancel the pending Tx bulks request of idx(%d)!\n", - idx)); - DBGPRINT(RT_DEBUG_TRACE, - ("Unlink the pending URB!\n")); - /* unlink it now */ - RTUSB_UNLINK_URB(pUrb); - /* Sleep 200 microseconds to give cancellation time to work */ - /*RTMPusecDelay(200); */ - needDumpSeq = TRUE; - } - } else { - DBGPRINT(RT_DEBUG_ERROR, - ("Unknown bulkOut URB maybe hanged!\n")); - } - } else { - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], - irqFlags); - } - - if (isDataPacket == TRUE) - pAd->TransferedLength[idx] = actual_length; - } else { - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[idx], irqFlags); - } - } - - /* For Sigma debug, dump the ba_reordering sequence. */ - if ((needDumpSeq == TRUE) && (pAd->CommonCfg.bDisableReordering == 0)) { - u16 Idx; - struct rt_ba_rec_entry *pBAEntry = NULL; - u8 count = 0; - struct reordering_mpdu *mpdu_blk; - - Idx = pAd->MacTab.Content[BSSID_WCID].BARecWcidArray[0]; - - pBAEntry = &pAd->BATable.BARecEntry[Idx]; - if ((pBAEntry->list.qlen > 0) && (pBAEntry->list.next != NULL)) { - DBGPRINT(RT_DEBUG_TRACE, - ("NICUpdateRawCounters():The Queueing pkt in reordering buffer:\n")); - NdisAcquireSpinLock(&pBAEntry->RxReRingLock); - mpdu_blk = pBAEntry->list.next; - while (mpdu_blk) { - DBGPRINT(RT_DEBUG_TRACE, - ("\t%d:Seq-%d, bAMSDU-%d!\n", count, - mpdu_blk->Sequence, - mpdu_blk->bAMSDU)); - mpdu_blk = mpdu_blk->next; - count++; - } - - DBGPRINT(RT_DEBUG_TRACE, - ("\npBAEntry->LastIndSeq=%d!\n", - pBAEntry->LastIndSeq)); - NdisReleaseSpinLock(&pBAEntry->RxReRingLock); - } - } -} - -/* -======================================================================== -Routine Description: - Release allocated resources. - -Arguments: - *dev Point to the PCI or USB device - pAd driver control block pointer - -Return Value: - None - -Note: -======================================================================== -*/ -static void rt2870_disconnect(struct usb_device *dev, struct rt_rtmp_adapter *pAd) -{ - DBGPRINT(RT_DEBUG_ERROR, - ("rtusb_disconnect: unregister usbnet usb-%s-%s\n", - dev->bus->bus_name, dev->devpath)); - if (!pAd) { - usb_put_dev(dev); - printk(KERN_ERR "rtusb_disconnect: pAd == NULL!\n"); - return; - } - RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST); - - /* for debug, wait to show some messages to /proc system */ - udelay(1); - - RtmpPhyNetDevExit(pAd, pAd->net_dev); - - /* FIXME: Shall we need following delay and flush the schedule?? */ - udelay(1); - flush_scheduled_work(); - udelay(1); - - /* free the root net_device */ - RtmpOSNetDevFree(pAd->net_dev); - - RtmpRaDevCtrlExit(pAd); - - /* release a use of the usb device structure */ - usb_put_dev(dev); - udelay(1); - - DBGPRINT(RT_DEBUG_ERROR, (" RTUSB disconnect successfully\n")); -} - -static int __devinit rt2870_probe(IN struct usb_interface *intf, - IN struct usb_device *usb_dev, - IN const struct usb_device_id *dev_id, - struct rt_rtmp_adapter **ppAd) -{ - struct net_device *net_dev = NULL; - struct rt_rtmp_adapter *pAd = (struct rt_rtmp_adapter *)NULL; - int status, rv; - void *handle; - struct rt_rtmp_os_netdev_op_hook netDevHook; - - DBGPRINT(RT_DEBUG_TRACE, ("===>rt2870_probe()!\n")); - - /* Check chipset vendor/product ID */ - /*if (RT28XXChipsetCheck(_dev_p) == FALSE) */ - /* goto err_out; */ - -/*RtmpDevInit============================================= */ - /* Allocate struct rt_rtmp_adapter adapter structure */ - handle = kmalloc(sizeof(struct os_cookie), GFP_KERNEL); - if (handle == NULL) { - printk - ("rt2870_probe(): Allocate memory for os handle failed!\n"); - return -ENOMEM; - } - ((struct os_cookie *)handle)->pUsb_Dev = usb_dev; - - rv = RTMPAllocAdapterBlock(handle, &pAd); - if (rv != NDIS_STATUS_SUCCESS) { - kfree(handle); - goto err_out; - } -/*USBDevInit============================================== */ - if (USBDevConfigInit(usb_dev, intf, pAd) == FALSE) - goto err_out_free_radev; - - RtmpRaDevCtrlInit(pAd, RTMP_DEV_INF_USB); - -/*NetDevInit============================================== */ - net_dev = RtmpPhyNetDevInit(pAd, &netDevHook); - if (net_dev == NULL) - goto err_out_free_radev; - - /* Here are the net_device structure with usb specific parameters. - * for supporting Network Manager. - * Set the sysfs physical device reference for the network logical device if set prior to registration will - * cause a symlink during initialization. - */ - SET_NETDEV_DEV(net_dev, &(usb_dev->dev)); - - pAd->StaCfg.OriDevType = net_dev->type; - -/*All done, it's time to register the net device to linux kernel. */ - /* Register this device */ - status = RtmpOSNetDevAttach(net_dev, &netDevHook); - if (status != 0) - goto err_out_free_netdev; - -#ifdef KTHREAD_SUPPORT - init_waitqueue_head(&pAd->mlmeTask.kthread_q); - init_waitqueue_head(&pAd->timerTask.kthread_q); - init_waitqueue_head(&pAd->cmdQTask.kthread_q); -#endif - - *ppAd = pAd; - - DBGPRINT(RT_DEBUG_TRACE, ("<===rt2870_probe()!\n")); - - return 0; - - /* --------------------------- ERROR HANDLE --------------------------- */ -err_out_free_netdev: - RtmpOSNetDevFree(net_dev); - -err_out_free_radev: - RTMPFreeAdapter(pAd); - -err_out: - *ppAd = NULL; - - return -1; - -} diff --git a/trunk/drivers/staging/rt2860/wpa.h b/trunk/drivers/staging/rt2860/wpa.h deleted file mode 100644 index a7796d330b71..000000000000 --- a/trunk/drivers/staging/rt2860/wpa.h +++ /dev/null @@ -1,390 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - wpa.h - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs - Justin P. Mattock 11/07/2010 Fix a typo -*/ - -#ifndef __WPA_H__ -#define __WPA_H__ - -/* EAPOL Key descriptor frame format related length */ -#define LEN_KEY_DESC_NONCE 32 -#define LEN_KEY_DESC_IV 16 -#define LEN_KEY_DESC_RSC 8 -#define LEN_KEY_DESC_ID 8 -#define LEN_KEY_DESC_REPLAY 8 -#define LEN_KEY_DESC_MIC 16 - -/* The length is the EAPoL-Key frame except key data field. */ -/* Please refer to 802.11i-2004 ,Figure 43u in p.78 */ -#define LEN_EAPOL_KEY_MSG (sizeof(struct rt_key_descripter) - MAX_LEN_OF_RSNIE) - -/* EAP Code Type. */ -#define EAP_CODE_REQUEST 1 -#define EAP_CODE_RESPONSE 2 -#define EAP_CODE_SUCCESS 3 -#define EAP_CODE_FAILURE 4 - -/* EAPOL frame Protocol Version */ -#define EAPOL_VER 1 -#define EAPOL_VER2 2 - -/* EAPOL-KEY Descriptor Type */ -#define WPA1_KEY_DESC 0xfe -#define WPA2_KEY_DESC 0x02 - -/* Key Descriptor Version of Key Information */ -#define DESC_TYPE_TKIP 1 -#define DESC_TYPE_AES 2 - -#define LEN_MSG1_2WAY 0x7f -#define MAX_LEN_OF_EAP_HS 256 - -#define LEN_MASTER_KEY 32 - -/* EAPOL EK, MK */ -#define LEN_EAP_EK 16 -#define LEN_EAP_MICK 16 -#define LEN_EAP_KEY ((LEN_EAP_EK)+(LEN_EAP_MICK)) -/* TKIP key related */ -#define LEN_PMKID 16 -#define LEN_TKIP_EK 16 -#define LEN_TKIP_RXMICK 8 -#define LEN_TKIP_TXMICK 8 -#define LEN_AES_EK 16 -#define LEN_AES_KEY LEN_AES_EK -#define LEN_TKIP_KEY ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK)) -#define TKIP_AP_TXMICK_OFFSET ((LEN_EAP_KEY)+(LEN_TKIP_EK)) -#define TKIP_AP_RXMICK_OFFSET (TKIP_AP_TXMICK_OFFSET+LEN_TKIP_TXMICK) -#define TKIP_GTK_LENGTH ((LEN_TKIP_EK)+(LEN_TKIP_RXMICK)+(LEN_TKIP_TXMICK)) -#define LEN_PTK ((LEN_EAP_KEY)+(LEN_TKIP_KEY)) -#define MIN_LEN_OF_GTK 5 -#define LEN_PMK 32 -#define LEN_PMK_NAME 16 -#define LEN_NONCE 32 - -/* RSN IE Length definition */ -#define MAX_LEN_OF_RSNIE 255 -#define MIN_LEN_OF_RSNIE 8 - -#define KEY_LIFETIME 3600 - -/*EAP Packet Type */ -#define EAPPacket 0 -#define EAPOLStart 1 -#define EAPOLLogoff 2 -#define EAPOLKey 3 -#define EAPOLASFAlert 4 -#define EAPTtypeMax 5 - -#define EAPOL_MSG_INVALID 0 -#define EAPOL_PAIR_MSG_1 1 -#define EAPOL_PAIR_MSG_2 2 -#define EAPOL_PAIR_MSG_3 3 -#define EAPOL_PAIR_MSG_4 4 -#define EAPOL_GROUP_MSG_1 5 -#define EAPOL_GROUP_MSG_2 6 - -#define PAIRWISEKEY 1 -#define GROUPKEY 0 - -/* Retry timer counter initial value */ -#define PEER_MSG1_RETRY_TIMER_CTR 0 -#define PEER_MSG3_RETRY_TIMER_CTR 10 -#define GROUP_MSG1_RETRY_TIMER_CTR 20 - -/*#ifdef CONFIG_AP_SUPPORT */ -/* WPA mechanism retry timer interval */ -#define PEER_MSG1_RETRY_EXEC_INTV 1000 /* 1 sec */ -#define PEER_MSG3_RETRY_EXEC_INTV 3000 /* 3 sec */ -#define GROUP_KEY_UPDATE_EXEC_INTV 1000 /* 1 sec */ -#define PEER_GROUP_KEY_UPDATE_INIV 2000 /* 2 sec */ - -#define ENQUEUE_EAPOL_START_TIMER 200 /* 200 ms */ - -/* group rekey interval */ -#define TIME_REKEY 0 -#define PKT_REKEY 1 -#define DISABLE_REKEY 2 -#define MAX_REKEY 2 - -#define MAX_REKEY_INTER 0x3ffffff -/*#endif // CONFIG_AP_SUPPORT // */ - -#define GROUP_SUITE 0 -#define PAIRWISE_SUITE 1 -#define AKM_SUITE 2 -#define PMKID_LIST 3 - -#define EAPOL_START_DISABLE 0 -#define EAPOL_START_PSK 1 -#define EAPOL_START_1X 2 - -#define MIX_CIPHER_WPA_TKIP_ON(x) (((x) & 0x08) != 0) -#define MIX_CIPHER_WPA_AES_ON(x) (((x) & 0x04) != 0) -#define MIX_CIPHER_WPA2_TKIP_ON(x) (((x) & 0x02) != 0) -#define MIX_CIPHER_WPA2_AES_ON(x) (((x) & 0x01) != 0) - -#ifndef ROUND_UP -#define ROUND_UP(__x, __y) \ - (((unsigned long)((__x)+((__y)-1))) & ((unsigned long)~((__y)-1))) -#endif - -#define SET_u16_TO_ARRARY(_V, _LEN) \ -{ \ - _V[0] = (_LEN & 0xFF00) >> 8; \ - _V[1] = (_LEN & 0xFF); \ -} - -#define INC_u16_TO_ARRARY(_V, _LEN) \ -{ \ - u16 var_len; \ - \ - var_len = (_V[0]<<8) | (_V[1]); \ - var_len += _LEN; \ - \ - _V[0] = (var_len & 0xFF00) >> 8; \ - _V[1] = (var_len & 0xFF); \ -} - -#define CONV_ARRARY_TO_u16(_V) ((_V[0]<<8) | (_V[1])) - -#define ADD_ONE_To_64BIT_VAR(_V) \ -{ \ - u8 cnt = LEN_KEY_DESC_REPLAY; \ - do \ - { \ - cnt--; \ - _V[cnt]++; \ - if (cnt == 0) \ - break; \ - }while (_V[cnt] == 0); \ -} - -#define IS_WPA_CAPABILITY(a) (((a) >= Ndis802_11AuthModeWPA) && ((a) <= Ndis802_11AuthModeWPA1PSKWPA2PSK)) - -/* EAPOL Key Information definition within Key descriptor format */ -struct PACKED rt_key_info { - u8 KeyMic:1; - u8 Secure:1; - u8 Error:1; - u8 Request:1; - u8 EKD_DL:1; /* EKD for AP; DL for STA */ - u8 Rsvd:3; - u8 KeyDescVer:3; - u8 KeyType:1; - u8 KeyIndex:2; - u8 Install:1; - u8 KeyAck:1; -}; - -/* EAPOL Key descriptor format */ -struct PACKED rt_key_descripter { - u8 Type; - struct rt_key_info KeyInfo; - u8 KeyLength[2]; - u8 ReplayCounter[LEN_KEY_DESC_REPLAY]; - u8 KeyNonce[LEN_KEY_DESC_NONCE]; - u8 KeyIv[LEN_KEY_DESC_IV]; - u8 KeyRsc[LEN_KEY_DESC_RSC]; - u8 KeyId[LEN_KEY_DESC_ID]; - u8 KeyMic[LEN_KEY_DESC_MIC]; - u8 KeyDataLen[2]; - u8 KeyData[MAX_LEN_OF_RSNIE]; -}; - -struct PACKED rt_eapol_packet { - u8 ProVer; - u8 ProType; - u8 Body_Len[2]; - struct rt_key_descripter KeyDesc; -}; - -/*802.11i D10 page 83 */ -struct PACKED rt_gtk_encap { - u8 Kid:2; - u8 tx:1; - u8 rsv:5; - u8 rsv1; - u8 GTK[TKIP_GTK_LENGTH]; -}; - -struct PACKED rt_kde_encap { - u8 Type; - u8 Len; - u8 OUI[3]; - u8 DataType; - struct rt_gtk_encap GTKEncap; -}; - -/* For WPA1 */ -struct PACKED rt_rsnie { - u8 oui[4]; - u16 version; - u8 mcast[4]; - u16 ucount; - struct PACKED { - u8 oui[4]; - } ucast[1]; -}; - -/* For WPA2 */ -struct PACKED rt_rsnie2 { - u16 version; - u8 mcast[4]; - u16 ucount; - struct PACKED { - u8 oui[4]; - } ucast[1]; -}; - -/* AKM Suite */ -struct PACKED rt_rsnie_auth { - u16 acount; - struct PACKED { - u8 oui[4]; - } auth[1]; -}; - -typedef union PACKED _RSN_CAPABILITIES { - struct PACKED { - u16 PreAuth:1; - u16 No_Pairwise:1; - u16 PTKSA_R_Counter:2; - u16 GTKSA_R_Counter:2; - u16 Rsvd:10; - } field; - u16 word; -} RSN_CAPABILITIES, *PRSN_CAPABILITIES; - -struct PACKED rt_eap_hdr { - u8 ProVer; - u8 ProType; - u8 Body_Len[2]; - u8 code; - u8 identifier; - u8 length[2]; /* including code and identifier, followed by length-2 octets of data */ -}; - -/* For supplicant state machine states. 802.11i Draft 4.1, p. 97 */ -/* We simplified it */ -typedef enum _WpaState { - SS_NOTUSE, /* 0 */ - SS_START, /* 1 */ - SS_WAIT_MSG_3, /* 2 */ - SS_WAIT_GROUP, /* 3 */ - SS_FINISH, /* 4 */ - SS_KEYUPDATE, /* 5 */ -} WPA_STATE; - -/* */ -/* The definition of the cipher combination */ -/* */ -/* bit3 bit2 bit1 bit0 */ -/* +------------+------------+ */ -/* | WPA | WPA2 | */ -/* +------+-----+------+-----+ */ -/* | TKIP | AES | TKIP | AES | */ -/* | 0 | 1 | 1 | 0 | -> 0x06 */ -/* | 0 | 1 | 1 | 1 | -> 0x07 */ -/* | 1 | 0 | 0 | 1 | -> 0x09 */ -/* | 1 | 0 | 1 | 1 | -> 0x0B */ -/* | 1 | 1 | 0 | 1 | -> 0x0D */ -/* | 1 | 1 | 1 | 0 | -> 0x0E */ -/* | 1 | 1 | 1 | 1 | -> 0x0F */ -/* +------+-----+------+-----+ */ -/* */ -typedef enum _WpaMixPairCipher { - MIX_CIPHER_NOTUSE = 0x00, - WPA_NONE_WPA2_TKIPAES = 0x03, /* WPA2-TKIPAES */ - WPA_AES_WPA2_TKIP = 0x06, - WPA_AES_WPA2_TKIPAES = 0x07, - WPA_TKIP_WPA2_AES = 0x09, - WPA_TKIP_WPA2_TKIPAES = 0x0B, - WPA_TKIPAES_WPA2_NONE = 0x0C, /* WPA-TKIPAES */ - WPA_TKIPAES_WPA2_AES = 0x0D, - WPA_TKIPAES_WPA2_TKIP = 0x0E, - WPA_TKIPAES_WPA2_TKIPAES = 0x0F, -} WPA_MIX_PAIR_CIPHER; - -struct PACKED rt_rsn_ie_header { - u8 Eid; - u8 Length; - u16 Version; /* Little endian format */ -}; - -/* Cipher suite selector types */ -struct PACKED rt_cipher_suite_struct { - u8 Oui[3]; - u8 Type; -}; - -/* Authentication and Key Management suite selector */ -struct PACKED rt_akm_suite { - u8 Oui[3]; - u8 Type; -}; - -/* RSN capability */ -struct PACKED rt_rsn_capability { - u16 Rsv:10; - u16 GTKSAReplayCnt:2; - u16 PTKSAReplayCnt:2; - u16 NoPairwise:1; - u16 PreAuth:1; -}; - -/*======================================== - The prototype is defined in cmm_wpa.c - ========================================*/ -BOOLEAN WpaMsgTypeSubst(u8 EAPType, int *MsgType); - -void PRF(u8 *key, int key_len, u8 *prefix, int prefix_len, - u8 *data, int data_len, u8 *output, int len); - -int PasswordHash(char *password, - unsigned char *ssid, int ssidlength, unsigned char *output); - -u8 *GetSuiteFromRSNIE(u8 *rsnie, u32 rsnie_len, u8 type, u8 *count); - -void WpaShowAllsuite(u8 *rsnie, u32 rsnie_len); - -void RTMPInsertRSNIE(u8 *pFrameBuf, - unsigned long *pFrameLen, - u8 *rsnie_ptr, - u8 rsnie_len, - u8 *pmkid_ptr, u8 pmkid_len); - -#endif diff --git a/trunk/drivers/staging/rt2870/Kconfig b/trunk/drivers/staging/rt2870/Kconfig deleted file mode 100644 index e988680b5be4..000000000000 --- a/trunk/drivers/staging/rt2870/Kconfig +++ /dev/null @@ -1,9 +0,0 @@ -config RT2870 - tristate "Ralink 2870/3070 wireless support" - depends on USB && (X86 || ARM) && WLAN - select WIRELESS_EXT - select WEXT_PRIV - select CRC_CCITT - select FW_LOADER - ---help--- - This is an experimental driver for the Ralink xx70 wireless chips. diff --git a/trunk/drivers/staging/rt2870/Makefile b/trunk/drivers/staging/rt2870/Makefile deleted file mode 100644 index b499910ed738..000000000000 --- a/trunk/drivers/staging/rt2870/Makefile +++ /dev/null @@ -1,55 +0,0 @@ -# -obj-$(CONFIG_RT2870) += rt2870sta.o - -# TODO: all of these should be removed -ccflags-y := -DLINUX -DAGGREGATION_SUPPORT -DPIGGYBACK_SUPPORT -DWMM_SUPPORT -ccflags-y += -DRTMP_MAC_USB -DRTMP_USB_SUPPORT -DRT2870 -DRTMP_TIMER_TASK_SUPPORT -ccflags-y += -DRTMP_RF_RW_SUPPORT -DRTMP_EFUSE_SUPPORT -DRT30xx -DRT3070 -ccflags-y += -DDBG - -rt2870sta-y := \ - common/crypt_md5.o \ - common/crypt_sha2.o \ - common/crypt_hmac.o \ - common/mlme.o \ - common/cmm_wep.o \ - common/action.o \ - common/cmm_data.o \ - common/rtmp_init.o \ - common/cmm_tkip.o \ - common/cmm_aes.o \ - common/cmm_sync.o \ - common/eeprom.o \ - common/cmm_sanity.o \ - common/cmm_info.o \ - common/cmm_cfg.o \ - common/cmm_wpa.o \ - common/dfs.o \ - common/spectrum.o \ - common/rtmp_timer.o \ - common/rt_channel.o \ - common/cmm_asic.o \ - sta/assoc.o \ - sta/auth.o \ - sta/auth_rsp.o \ - sta/sync.o \ - sta/sanity.o \ - sta/rtmp_data.o \ - sta/connect.o \ - sta/wpa.o \ - rt_linux.o \ - rt_main_dev.o \ - sta_ioctl.o \ - common/ba_action.o \ - usb_main_dev.o \ - rt_usb.o \ - common/cmm_mac_usb.o \ - common/rtusb_io.o \ - common/rtusb_bulk.o \ - common/rtusb_data.o \ - common/cmm_data_usb.o \ - common/rtmp_mcu.o \ - common/ee_efuse.o \ - chips/rt30xx.o \ - common/rt_rf.o \ - chips/rt3070.o diff --git a/trunk/drivers/staging/rt2870/TODO b/trunk/drivers/staging/rt2870/TODO deleted file mode 100644 index 2df1bfed9a58..000000000000 --- a/trunk/drivers/staging/rt2870/TODO +++ /dev/null @@ -1,17 +0,0 @@ -I'm hesitant to add a TODO file here, as the wireless developers would -really have people help them out on the "clean" rt2870 driver that can -be found at the http://rt2x00.serialmonkey.com/ site. - -But, if you wish to clean up this driver instead, here's a short list of -things that need to be done to get it into a more mergable shape: - -TODO: - - checkpatch.pl clean - - sparse clean - - port to in-kernel 80211 stack and common rt2x00 infrastructure - - remove reading from /etc/ config files - - review by the wireless developer community - -Please send any patches or complaints about this driver to Greg -Kroah-Hartman and don't bother the upstream wireless -kernel developers about it, they want nothing to do with it. diff --git a/trunk/drivers/staging/rt2870/aironet.h b/trunk/drivers/staging/rt2870/aironet.h deleted file mode 100644 index ae6259710a4f..000000000000 --- a/trunk/drivers/staging/rt2870/aironet.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/aironet.h" diff --git a/trunk/drivers/staging/rt2870/ap.h b/trunk/drivers/staging/rt2870/ap.h deleted file mode 100644 index fe04b5f45f20..000000000000 --- a/trunk/drivers/staging/rt2870/ap.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/ap.h" diff --git a/trunk/drivers/staging/rt2870/chips/rt3070.c b/trunk/drivers/staging/rt2870/chips/rt3070.c deleted file mode 100644 index 3a6db5ea89ab..000000000000 --- a/trunk/drivers/staging/rt2870/chips/rt3070.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/chips/rt3070.c" diff --git a/trunk/drivers/staging/rt2870/chips/rt30xx.c b/trunk/drivers/staging/rt2870/chips/rt30xx.c deleted file mode 100644 index 6c56b84c75d9..000000000000 --- a/trunk/drivers/staging/rt2870/chips/rt30xx.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/chips/rt30xx.c" diff --git a/trunk/drivers/staging/rt2870/chlist.h b/trunk/drivers/staging/rt2870/chlist.h deleted file mode 100644 index 31999583b379..000000000000 --- a/trunk/drivers/staging/rt2870/chlist.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/chlist.h" diff --git a/trunk/drivers/staging/rt2870/common/acction.c b/trunk/drivers/staging/rt2870/common/acction.c deleted file mode 100644 index fd806c3871aa..000000000000 --- a/trunk/drivers/staging/rt2870/common/acction.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/action.c" diff --git a/trunk/drivers/staging/rt2870/common/action.c b/trunk/drivers/staging/rt2870/common/action.c deleted file mode 100644 index fd806c3871aa..000000000000 --- a/trunk/drivers/staging/rt2870/common/action.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/action.c" diff --git a/trunk/drivers/staging/rt2870/common/action.h b/trunk/drivers/staging/rt2870/common/action.h deleted file mode 100644 index 9a1895525f30..000000000000 --- a/trunk/drivers/staging/rt2870/common/action.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/action.h" diff --git a/trunk/drivers/staging/rt2870/common/ba_action.c b/trunk/drivers/staging/rt2870/common/ba_action.c deleted file mode 100644 index a9e6a09d994f..000000000000 --- a/trunk/drivers/staging/rt2870/common/ba_action.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/ba_action.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_aes.c b/trunk/drivers/staging/rt2870/common/cmm_aes.c deleted file mode 100644 index 15d6a14d2d9c..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_aes.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_aes.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_asic.c b/trunk/drivers/staging/rt2870/common/cmm_asic.c deleted file mode 100644 index 38de817991ff..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_asic.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_asic.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_cfg.c b/trunk/drivers/staging/rt2870/common/cmm_cfg.c deleted file mode 100644 index 6b2bdd7d44ec..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_cfg.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_cfg.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_data.c b/trunk/drivers/staging/rt2870/common/cmm_data.c deleted file mode 100644 index df775c3cf691..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_data.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_data.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_data_usb.c b/trunk/drivers/staging/rt2870/common/cmm_data_usb.c deleted file mode 100644 index 704675fccb7d..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_data_usb.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_data_usb.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_info.c b/trunk/drivers/staging/rt2870/common/cmm_info.c deleted file mode 100644 index 226187ee5561..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_info.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_info.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_mac_usb.c b/trunk/drivers/staging/rt2870/common/cmm_mac_usb.c deleted file mode 100644 index b26af4af890b..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_mac_usb.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_mac_usb.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_profile.c b/trunk/drivers/staging/rt2870/common/cmm_profile.c deleted file mode 100644 index 9926e45aba3c..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_profile.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_profile.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_sanity.c b/trunk/drivers/staging/rt2870/common/cmm_sanity.c deleted file mode 100644 index cb3352118c57..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_sanity.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_sanity.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_sync.c b/trunk/drivers/staging/rt2870/common/cmm_sync.c deleted file mode 100644 index 5e7221d7cb27..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_sync.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_sync.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_tkip.c b/trunk/drivers/staging/rt2870/common/cmm_tkip.c deleted file mode 100644 index f73c71bafe86..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_tkip.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_tkip.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_wep.c b/trunk/drivers/staging/rt2870/common/cmm_wep.c deleted file mode 100644 index 5f681078387f..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_wep.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_wep.c" diff --git a/trunk/drivers/staging/rt2870/common/cmm_wpa.c b/trunk/drivers/staging/rt2870/common/cmm_wpa.c deleted file mode 100644 index 04a54bb21853..000000000000 --- a/trunk/drivers/staging/rt2870/common/cmm_wpa.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/cmm_wpa.c" diff --git a/trunk/drivers/staging/rt2870/common/crypt_hmac.c b/trunk/drivers/staging/rt2870/common/crypt_hmac.c deleted file mode 100644 index 24d84e7724fb..000000000000 --- a/trunk/drivers/staging/rt2870/common/crypt_hmac.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/crypt_hmac.c" diff --git a/trunk/drivers/staging/rt2870/common/crypt_md5.c b/trunk/drivers/staging/rt2870/common/crypt_md5.c deleted file mode 100644 index 457a2caca1e3..000000000000 --- a/trunk/drivers/staging/rt2870/common/crypt_md5.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/crypt_md5.c" diff --git a/trunk/drivers/staging/rt2870/common/crypt_sha2.c b/trunk/drivers/staging/rt2870/common/crypt_sha2.c deleted file mode 100644 index 07ffb300c193..000000000000 --- a/trunk/drivers/staging/rt2870/common/crypt_sha2.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/crypt_sha2.c" diff --git a/trunk/drivers/staging/rt2870/common/dfs.c b/trunk/drivers/staging/rt2870/common/dfs.c deleted file mode 100644 index ac2da4c0e2ca..000000000000 --- a/trunk/drivers/staging/rt2870/common/dfs.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/dfs.c" diff --git a/trunk/drivers/staging/rt2870/common/ee_efuse.c b/trunk/drivers/staging/rt2870/common/ee_efuse.c deleted file mode 100644 index 0e34e65e5f28..000000000000 --- a/trunk/drivers/staging/rt2870/common/ee_efuse.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/ee_efuse.c" diff --git a/trunk/drivers/staging/rt2870/common/eeprom.c b/trunk/drivers/staging/rt2870/common/eeprom.c deleted file mode 100644 index def09658fd81..000000000000 --- a/trunk/drivers/staging/rt2870/common/eeprom.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/eeprom.c" diff --git a/trunk/drivers/staging/rt2870/common/md5.c b/trunk/drivers/staging/rt2870/common/md5.c deleted file mode 100644 index 195645c0e1a8..000000000000 --- a/trunk/drivers/staging/rt2870/common/md5.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/md5.c" diff --git a/trunk/drivers/staging/rt2870/common/mlme.c b/trunk/drivers/staging/rt2870/common/mlme.c deleted file mode 100644 index f88040abd26b..000000000000 --- a/trunk/drivers/staging/rt2870/common/mlme.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/mlme.c" diff --git a/trunk/drivers/staging/rt2870/common/rt_channel.c b/trunk/drivers/staging/rt2870/common/rt_channel.c deleted file mode 100644 index c8ceb4c177d9..000000000000 --- a/trunk/drivers/staging/rt2870/common/rt_channel.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/rt_channel.c" diff --git a/trunk/drivers/staging/rt2870/common/rt_rf.c b/trunk/drivers/staging/rt2870/common/rt_rf.c deleted file mode 100644 index b81cff34969b..000000000000 --- a/trunk/drivers/staging/rt2870/common/rt_rf.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/rt_rf.c" diff --git a/trunk/drivers/staging/rt2870/common/rtmp_init.c b/trunk/drivers/staging/rt2870/common/rtmp_init.c deleted file mode 100644 index eef10efda196..000000000000 --- a/trunk/drivers/staging/rt2870/common/rtmp_init.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/rtmp_init.c" diff --git a/trunk/drivers/staging/rt2870/common/rtmp_mcu.c b/trunk/drivers/staging/rt2870/common/rtmp_mcu.c deleted file mode 100644 index 20b7f13d60f8..000000000000 --- a/trunk/drivers/staging/rt2870/common/rtmp_mcu.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/rtmp_mcu.c" diff --git a/trunk/drivers/staging/rt2870/common/rtmp_timer.c b/trunk/drivers/staging/rt2870/common/rtmp_timer.c deleted file mode 100644 index fd4aedcd5e8b..000000000000 --- a/trunk/drivers/staging/rt2870/common/rtmp_timer.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/rtmp_timer.c" diff --git a/trunk/drivers/staging/rt2870/common/rtmp_tkip.c b/trunk/drivers/staging/rt2870/common/rtmp_tkip.c deleted file mode 100644 index 240bf67f521f..000000000000 --- a/trunk/drivers/staging/rt2870/common/rtmp_tkip.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/rtmp_tkip.c" diff --git a/trunk/drivers/staging/rt2870/common/rtmp_wep.c b/trunk/drivers/staging/rt2870/common/rtmp_wep.c deleted file mode 100644 index ae255adc9f7f..000000000000 --- a/trunk/drivers/staging/rt2870/common/rtmp_wep.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/rtmp_wep.c" diff --git a/trunk/drivers/staging/rt2870/common/rtusb_bulk.c b/trunk/drivers/staging/rt2870/common/rtusb_bulk.c deleted file mode 100644 index 679b802d2169..000000000000 --- a/trunk/drivers/staging/rt2870/common/rtusb_bulk.c +++ /dev/null @@ -1,1232 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtusb_bulk.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs - Paul Lin 06-25-2004 created - -*/ - -#ifdef RTMP_MAC_USB - -#include "../rt_config.h" -/* Match total 6 bulkout endpoint to corresponding queue. */ -u8 EpToQueue[6] = - { FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_EDCA, FIFO_MGMT }; - -/*static BOOLEAN SingleBulkOut = FALSE; */ - -void RTUSB_FILL_BULK_URB(struct urb *pUrb, - struct usb_device *pUsb_Dev, - unsigned int bulkpipe, - void *pTransferBuf, - int BufSize, usb_complete_t Complete, void *pContext) -{ - - usb_fill_bulk_urb(pUrb, pUsb_Dev, bulkpipe, pTransferBuf, BufSize, - (usb_complete_t) Complete, pContext); - -} - -void RTUSBInitTxDesc(struct rt_rtmp_adapter *pAd, - struct rt_tx_context *pTxContext, - u8 BulkOutPipeId, IN usb_complete_t Func) -{ - PURB pUrb; - u8 *pSrc = NULL; - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - pUrb = pTxContext->pUrb; - ASSERT(pUrb); - - /* Store BulkOut PipeId */ - pTxContext->BulkOutPipeId = BulkOutPipeId; - - if (pTxContext->bAggregatible) { - pSrc = &pTxContext->TransferBuffer->Aggregation[2]; - } else { - pSrc = - (u8 *)pTxContext->TransferBuffer->field.WirelessPacket; - } - - /*Initialize a tx bulk urb */ - RTUSB_FILL_BULK_URB(pUrb, - pObj->pUsb_Dev, - usb_sndbulkpipe(pObj->pUsb_Dev, - pAd->BulkOutEpAddr[BulkOutPipeId]), - pSrc, pTxContext->BulkOutSize, Func, pTxContext); - - if (pTxContext->bAggregatible) - pUrb->transfer_dma = - (pTxContext->data_dma + TX_BUFFER_NORMSIZE + 2); - else - pUrb->transfer_dma = pTxContext->data_dma; - - pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - -} - -void RTUSBInitHTTxDesc(struct rt_rtmp_adapter *pAd, - struct rt_ht_tx_context *pTxContext, - u8 BulkOutPipeId, - unsigned long BulkOutSize, IN usb_complete_t Func) -{ - PURB pUrb; - u8 *pSrc = NULL; - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - pUrb = pTxContext->pUrb; - ASSERT(pUrb); - - /* Store BulkOut PipeId */ - pTxContext->BulkOutPipeId = BulkOutPipeId; - - pSrc = - &pTxContext->TransferBuffer->field.WirelessPacket[pTxContext-> - NextBulkOutPosition]; - - /*Initialize a tx bulk urb */ - RTUSB_FILL_BULK_URB(pUrb, - pObj->pUsb_Dev, - usb_sndbulkpipe(pObj->pUsb_Dev, - pAd->BulkOutEpAddr[BulkOutPipeId]), - pSrc, BulkOutSize, Func, pTxContext); - - pUrb->transfer_dma = - (pTxContext->data_dma + pTxContext->NextBulkOutPosition); - pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - -} - -void RTUSBInitRxDesc(struct rt_rtmp_adapter *pAd, struct rt_rx_context *pRxContext) -{ - PURB pUrb; - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - unsigned long RX_bulk_size; - - pUrb = pRxContext->pUrb; - ASSERT(pUrb); - - if (pAd->BulkInMaxPacketSize == 64) - RX_bulk_size = 4096; - else - RX_bulk_size = MAX_RXBULK_SIZE; - - /*Initialize a rx bulk urb */ - RTUSB_FILL_BULK_URB(pUrb, - pObj->pUsb_Dev, - usb_rcvbulkpipe(pObj->pUsb_Dev, pAd->BulkInEpAddr), - &(pRxContext-> - TransferBuffer[pAd->NextRxBulkInPosition]), - RX_bulk_size - (pAd->NextRxBulkInPosition), - (usb_complete_t) RTUSBBulkRxComplete, - (void *)pRxContext); - - pUrb->transfer_dma = pRxContext->data_dma + pAd->NextRxBulkInPosition; - pUrb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; - -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: - - ======================================================================== -*/ - -#define BULK_OUT_LOCK(pLock, IrqFlags) \ - if (1 /*!(in_interrupt() & 0xffff0000)*/) \ - RTMP_IRQ_LOCK((pLock), IrqFlags); - -#define BULK_OUT_UNLOCK(pLock, IrqFlags) \ - if (1 /*!(in_interrupt() & 0xffff0000)*/) \ - RTMP_IRQ_UNLOCK((pLock), IrqFlags); - -void RTUSBBulkOutDataPacket(struct rt_rtmp_adapter *pAd, - u8 BulkOutPipeId, u8 Index) -{ - - struct rt_ht_tx_context *pHTTXContext; - PURB pUrb; - int ret = 0; - struct rt_txinfo *pTxInfo, *pLastTxInfo = NULL; - struct rt_txwi *pTxWI; - unsigned long TmpBulkEndPos, ThisBulkSize; - unsigned long IrqFlags = 0, IrqFlags2 = 0; - u8 *pWirelessPkt, *pAppendant; - BOOLEAN bTxQLastRound = FALSE; - u8 allzero[4] = { 0x0, 0x0, 0x0, 0x0 }; - - BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - if ((pAd->BulkOutPending[BulkOutPipeId] == TRUE) - || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX)) { - BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - return; - } - pAd->BulkOutPending[BulkOutPipeId] = TRUE; - - if (!OPSTATUS_TEST_FLAG(pAd, fOP_STATUS_MEDIA_STATE_CONNECTED) - ) { - pAd->BulkOutPending[BulkOutPipeId] = FALSE; - BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - return; - } - BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - - pHTTXContext = &(pAd->TxContext[BulkOutPipeId]); - - BULK_OUT_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2); - if ((pHTTXContext->ENextBulkOutPosition == - pHTTXContext->CurWritePosition) - || ((pHTTXContext->ENextBulkOutPosition - 8) == - pHTTXContext->CurWritePosition)) { - BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], - IrqFlags2); - - BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - pAd->BulkOutPending[BulkOutPipeId] = FALSE; - - /* Clear Data flag */ - RTUSB_CLEAR_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_FRAG << - BulkOutPipeId)); - RTUSB_CLEAR_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_NORMAL << - BulkOutPipeId)); - - BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - return; - } - /* Clear Data flag */ - RTUSB_CLEAR_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_FRAG << BulkOutPipeId)); - RTUSB_CLEAR_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_NORMAL << BulkOutPipeId)); - - /*DBGPRINT(RT_DEBUG_TRACE,("BulkOut-B:I=0x%lx, CWPos=%ld, CWRPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", in_interrupt(), */ - /* pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->NextBulkOutPosition, */ - /* pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad)); */ - pHTTXContext->NextBulkOutPosition = pHTTXContext->ENextBulkOutPosition; - ThisBulkSize = 0; - TmpBulkEndPos = pHTTXContext->NextBulkOutPosition; - pWirelessPkt = &pHTTXContext->TransferBuffer->field.WirelessPacket[0]; - - if ((pHTTXContext->bCopySavePad == TRUE)) { - if (RTMPEqualMemory(pHTTXContext->SavedPad, allzero, 4)) { - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("e1, allzero : %x %x %x %x %x %x %x %x \n", - pHTTXContext->SavedPad[0], - pHTTXContext->SavedPad[1], - pHTTXContext->SavedPad[2], - pHTTXContext->SavedPad[3] - , pHTTXContext->SavedPad[4], - pHTTXContext->SavedPad[5], - pHTTXContext->SavedPad[6], - pHTTXContext->SavedPad[7])); - } - NdisMoveMemory(&pWirelessPkt[TmpBulkEndPos], - pHTTXContext->SavedPad, 8); - pHTTXContext->bCopySavePad = FALSE; - if (pAd->bForcePrintTX == TRUE) - DBGPRINT(RT_DEBUG_TRACE, - ("RTUSBBulkOutDataPacket --> COPY PAD. CurWrite = %ld, NextBulk = %ld. ENextBulk = %ld.\n", - pHTTXContext->CurWritePosition, - pHTTXContext->NextBulkOutPosition, - pHTTXContext->ENextBulkOutPosition)); - } - - do { - pTxInfo = (struct rt_txinfo *)&pWirelessPkt[TmpBulkEndPos]; - pTxWI = - (struct rt_txwi *)&pWirelessPkt[TmpBulkEndPos + TXINFO_SIZE]; - - if (pAd->bForcePrintTX == TRUE) - DBGPRINT(RT_DEBUG_TRACE, - ("RTUSBBulkOutDataPacket AMPDU = %d.\n", - pTxWI->AMPDU)); - - /* add by Iverson, limit BulkOut size to 4k to pass WMM b mode 2T1R test items */ - /*if ((ThisBulkSize != 0) && (pTxWI->AMPDU == 0)) */ - if ((ThisBulkSize != 0) && (pTxWI->PHYMODE == MODE_CCK)) { - if (((ThisBulkSize & 0xffff8000) != 0) - || ((ThisBulkSize & 0x1000) == 0x1000)) { - /* Limit BulkOut size to about 4k bytes. */ - pHTTXContext->ENextBulkOutPosition = - TmpBulkEndPos; - break; - } else - if (((pAd->BulkOutMaxPacketSize < 512) - && ((ThisBulkSize & 0xfffff800) != - 0)) - /*|| ( (ThisBulkSize != 0) && (pTxWI->AMPDU == 0)) */ - ) { - /* For USB 1.1 or peer which didn't support AMPDU, limit the BulkOut size. */ - /* For performance in b/g mode, now just check for USB 1.1 and didn't care about the APMDU or not! 2008/06/04. */ - pHTTXContext->ENextBulkOutPosition = - TmpBulkEndPos; - break; - } - } - /* end Iverson */ - else { - if (((ThisBulkSize & 0xffff8000) != 0) || ((ThisBulkSize & 0x6000) == 0x6000)) { /* Limit BulkOut size to about 24k bytes. */ - pHTTXContext->ENextBulkOutPosition = - TmpBulkEndPos; - break; - } else if (((pAd->BulkOutMaxPacketSize < 512) && ((ThisBulkSize & 0xfffff800) != 0)) /*|| ( (ThisBulkSize != 0) && (pTxWI->AMPDU == 0)) */) { /* For USB 1.1 or peer which didn't support AMPDU, limit the BulkOut size. */ - /* For performance in b/g mode, now just check for USB 1.1 and didn't care about the APMDU or not! 2008/06/04. */ - pHTTXContext->ENextBulkOutPosition = - TmpBulkEndPos; - break; - } - } - - if (TmpBulkEndPos == pHTTXContext->CurWritePosition) { - pHTTXContext->ENextBulkOutPosition = TmpBulkEndPos; - break; - } - - if (pTxInfo->QSEL != FIFO_EDCA) { - DBGPRINT(RT_DEBUG_ERROR, - ("%s(): ====> pTxInfo->QueueSel(%d)!= FIFO_EDCA!!!!\n", - __func__, pTxInfo->QSEL)); - DBGPRINT(RT_DEBUG_ERROR, - ("\tCWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", - pHTTXContext->CurWritePosition, - pHTTXContext->NextBulkOutPosition, - pHTTXContext->ENextBulkOutPosition, - pHTTXContext->bCopySavePad)); - hex_dump("Wrong QSel Pkt:", - (u8 *)&pWirelessPkt[TmpBulkEndPos], - (pHTTXContext->CurWritePosition - - pHTTXContext->NextBulkOutPosition)); - } - - if (pTxInfo->USBDMATxPktLen <= 8) { - BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], - IrqFlags2); - DBGPRINT(RT_DEBUG_ERROR /*RT_DEBUG_TRACE */ , - ("e2, USBDMATxPktLen==0, Size=%ld, bCSPad=%d, CWPos=%ld, NBPos=%ld, CWRPos=%ld!\n", - pHTTXContext->BulkOutSize, - pHTTXContext->bCopySavePad, - pHTTXContext->CurWritePosition, - pHTTXContext->NextBulkOutPosition, - pHTTXContext->CurWriteRealPos)); - { - DBGPRINT_RAW(RT_DEBUG_ERROR /*RT_DEBUG_TRACE */ - , - ("%x %x %x %x %x %x %x %x \n", - pHTTXContext->SavedPad[0], - pHTTXContext->SavedPad[1], - pHTTXContext->SavedPad[2], - pHTTXContext->SavedPad[3] - , pHTTXContext->SavedPad[4], - pHTTXContext->SavedPad[5], - pHTTXContext->SavedPad[6], - pHTTXContext->SavedPad[7])); - } - pAd->bForcePrintTX = TRUE; - BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], - IrqFlags); - pAd->BulkOutPending[BulkOutPipeId] = FALSE; - BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], - IrqFlags); - /*DBGPRINT(RT_DEBUG_LOUD,("Out:pTxInfo->USBDMATxPktLen=%d!\n", pTxInfo->USBDMATxPktLen)); */ - return; - } - /* Increase Total transmit byte counter */ - pAd->RalinkCounters.OneSecTransmittedByteCount += - pTxWI->MPDUtotalByteCount; - pAd->RalinkCounters.TransmittedByteCount += - pTxWI->MPDUtotalByteCount; - - pLastTxInfo = pTxInfo; - - /* Make sure we use EDCA QUEUE. */ - pTxInfo->QSEL = FIFO_EDCA; - ThisBulkSize += (pTxInfo->USBDMATxPktLen + 4); - TmpBulkEndPos += (pTxInfo->USBDMATxPktLen + 4); - - if (TmpBulkEndPos != pHTTXContext->CurWritePosition) - pTxInfo->USBDMANextVLD = 1; - - if (pTxInfo->SwUseLastRound == 1) { - if (pHTTXContext->CurWritePosition == 8) - pTxInfo->USBDMANextVLD = 0; - pTxInfo->SwUseLastRound = 0; - - bTxQLastRound = TRUE; - pHTTXContext->ENextBulkOutPosition = 8; - - break; - } - - } while (TRUE); - - /* adjust the pTxInfo->USBDMANextVLD value of last pTxInfo. */ - if (pLastTxInfo) - pLastTxInfo->USBDMANextVLD = 0; - - /* - We need to copy SavedPad when following condition matched! - 1. Not the last round of the TxQueue and - 2. any match of following cases: - (1). The End Position of this bulk out is reach to the Currenct Write position and - the TxInfo and related header already write to the CurWritePosition. - =>(ENextBulkOutPosition == CurWritePosition) && (CurWriteRealPos > CurWritePosition) - - (2). The EndPosition of the bulk out is not reach to the Current Write Position. - =>(ENextBulkOutPosition != CurWritePosition) - */ - if ((bTxQLastRound == FALSE) && - (((pHTTXContext->ENextBulkOutPosition == - pHTTXContext->CurWritePosition) - && (pHTTXContext->CurWriteRealPos > - pHTTXContext->CurWritePosition)) - || (pHTTXContext->ENextBulkOutPosition != - pHTTXContext->CurWritePosition)) - ) { - NdisMoveMemory(pHTTXContext->SavedPad, - &pWirelessPkt[pHTTXContext-> - ENextBulkOutPosition], 8); - pHTTXContext->bCopySavePad = TRUE; - if (RTMPEqualMemory(pHTTXContext->SavedPad, allzero, 4)) { - u8 *pBuf = &pHTTXContext->SavedPad[0]; - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("WARNING-Zero-3:%02x%02x%02x%02x%02x%02x%02x%02x,CWPos=%ld, CWRPos=%ld, bCW=%d, NBPos=%ld, TBPos=%ld, TBSize=%ld\n", - pBuf[0], pBuf[1], pBuf[2], pBuf[3], - pBuf[4], pBuf[5], pBuf[6], pBuf[7], - pHTTXContext->CurWritePosition, - pHTTXContext->CurWriteRealPos, - pHTTXContext->bCurWriting, - pHTTXContext->NextBulkOutPosition, - TmpBulkEndPos, ThisBulkSize)); - - pBuf = &pWirelessPkt[pHTTXContext->CurWritePosition]; - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("\tCWPos=%02x%02x%02x%02x%02x%02x%02x%02x\n", - pBuf[0], pBuf[1], pBuf[2], pBuf[3], - pBuf[4], pBuf[5], pBuf[6], pBuf[7])); - } - /*DBGPRINT(RT_DEBUG_LOUD,("ENPos==CWPos=%ld, CWRPos=%ld, bCSPad=%d!\n", pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->bCopySavePad)); */ - } - - if (pAd->bForcePrintTX == TRUE) - DBGPRINT(RT_DEBUG_TRACE, - ("BulkOut-A:Size=%ld, CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d!\n", - ThisBulkSize, pHTTXContext->CurWritePosition, - pHTTXContext->NextBulkOutPosition, - pHTTXContext->ENextBulkOutPosition, - pHTTXContext->bCopySavePad)); - /*DBGPRINT(RT_DEBUG_LOUD,("BulkOut-A:Size=%ld, CWPos=%ld, CWRPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, bLRound=%d!\n", ThisBulkSize, pHTTXContext->CurWritePosition, pHTTXContext->CurWriteRealPos, pHTTXContext->NextBulkOutPosition, pHTTXContext->ENextBulkOutPosition, pHTTXContext->bCopySavePad, bTxQLastRound)); */ - - /* USB DMA engine requires to pad extra 4 bytes. This pad doesn't count into real bulkoutsize. */ - pAppendant = &pWirelessPkt[TmpBulkEndPos]; - NdisZeroMemory(pAppendant, 8); - ThisBulkSize += 4; - pHTTXContext->LastOne = TRUE; - if ((ThisBulkSize % pAd->BulkOutMaxPacketSize) == 0) - ThisBulkSize += 4; - pHTTXContext->BulkOutSize = ThisBulkSize; - - pAd->watchDogTxPendingCnt[BulkOutPipeId] = 1; - BULK_OUT_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags2); - - /* Init Tx context descriptor */ - RTUSBInitHTTxDesc(pAd, pHTTXContext, BulkOutPipeId, ThisBulkSize, - (usb_complete_t) RTUSBBulkOutDataPacketComplete); - - pUrb = pHTTXContext->pUrb; - ret = RTUSB_SUBMIT_URB(pUrb); - if (ret != 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("RTUSBBulkOutDataPacket: Submit Tx URB failed %d\n", - ret)); - - BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - pAd->BulkOutPending[BulkOutPipeId] = FALSE; - pAd->watchDogTxPendingCnt[BulkOutPipeId] = 0; - BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - - return; - } - - BULK_OUT_LOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - pHTTXContext->IRPPending = TRUE; - BULK_OUT_UNLOCK(&pAd->BulkOutLock[BulkOutPipeId], IrqFlags); - pAd->BulkOutReq++; - -} - -void RTUSBBulkOutDataPacketComplete(struct urb *pUrb, struct pt_regs * pt_regs) -{ - struct rt_ht_tx_context *pHTTXContext; - struct rt_rtmp_adapter *pAd; - struct os_cookie *pObj; - u8 BulkOutPipeId; - - pHTTXContext = (struct rt_ht_tx_context *)pUrb->context; - pAd = pHTTXContext->pAd; - pObj = (struct os_cookie *)pAd->OS_Cookie; - - /* Store BulkOut PipeId */ - BulkOutPipeId = pHTTXContext->BulkOutPipeId; - pAd->BulkOutDataOneSecCount++; - - switch (BulkOutPipeId) { - case 0: - pObj->ac0_dma_done_task.data = (unsigned long)pUrb; - tasklet_hi_schedule(&pObj->ac0_dma_done_task); - break; - case 1: - pObj->ac1_dma_done_task.data = (unsigned long)pUrb; - tasklet_hi_schedule(&pObj->ac1_dma_done_task); - break; - case 2: - pObj->ac2_dma_done_task.data = (unsigned long)pUrb; - tasklet_hi_schedule(&pObj->ac2_dma_done_task); - break; - case 3: - pObj->ac3_dma_done_task.data = (unsigned long)pUrb; - tasklet_hi_schedule(&pObj->ac3_dma_done_task); - break; - } - -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: NULL frame use BulkOutPipeId = 0 - - ======================================================================== -*/ -void RTUSBBulkOutNullFrame(struct rt_rtmp_adapter *pAd) -{ - struct rt_tx_context *pNullContext = &(pAd->NullContext); - PURB pUrb; - int ret = 0; - unsigned long IrqFlags; - - RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags); - if ((pAd->BulkOutPending[0] == TRUE) - || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX)) { - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags); - return; - } - pAd->BulkOutPending[0] = TRUE; - pAd->watchDogTxPendingCnt[0] = 1; - pNullContext->IRPPending = TRUE; - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags); - - /* Increase Total transmit byte counter */ - pAd->RalinkCounters.TransmittedByteCount += pNullContext->BulkOutSize; - - /* Clear Null frame bulk flag */ - RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL); - - /* Init Tx context descriptor */ - RTUSBInitTxDesc(pAd, pNullContext, 0, - (usb_complete_t) RTUSBBulkOutNullFrameComplete); - - pUrb = pNullContext->pUrb; - ret = RTUSB_SUBMIT_URB(pUrb); - if (ret != 0) { - RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags); - pAd->BulkOutPending[0] = FALSE; - pAd->watchDogTxPendingCnt[0] = 0; - pNullContext->IRPPending = FALSE; - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags); - - DBGPRINT(RT_DEBUG_ERROR, - ("RTUSBBulkOutNullFrame: Submit Tx URB failed %d\n", - ret)); - return; - } - -} - -/* NULL frame use BulkOutPipeId = 0 */ -void RTUSBBulkOutNullFrameComplete(struct urb *pUrb, struct pt_regs * pt_regs) -{ - struct rt_rtmp_adapter *pAd; - struct rt_tx_context *pNullContext; - int Status; - struct os_cookie *pObj; - - pNullContext = (struct rt_tx_context *)pUrb->context; - pAd = pNullContext->pAd; - Status = pUrb->status; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - pObj->null_frame_complete_task.data = (unsigned long)pUrb; - tasklet_hi_schedule(&pObj->null_frame_complete_task); -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: MLME use BulkOutPipeId = 0 - - ======================================================================== -*/ -void RTUSBBulkOutMLMEPacket(struct rt_rtmp_adapter *pAd, u8 Index) -{ - struct rt_tx_context *pMLMEContext; - PURB pUrb; - int ret = 0; - unsigned long IrqFlags; - - pMLMEContext = - (struct rt_tx_context *)pAd->MgmtRing.Cell[pAd->MgmtRing.TxDmaIdx].AllocVa; - pUrb = pMLMEContext->pUrb; - - if ((pAd->MgmtRing.TxSwFreeIdx >= MGMT_RING_SIZE) || - (pMLMEContext->InUse == FALSE) || - (pMLMEContext->bWaitingBulkOut == FALSE)) { - - /* Clear MLME bulk flag */ - RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME); - - return; - } - - RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags); - if ((pAd->BulkOutPending[MGMTPIPEIDX] == TRUE) - || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX)) { - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags); - return; - } - - pAd->BulkOutPending[MGMTPIPEIDX] = TRUE; - pAd->watchDogTxPendingCnt[MGMTPIPEIDX] = 1; - pMLMEContext->IRPPending = TRUE; - pMLMEContext->bWaitingBulkOut = FALSE; - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags); - - /* Increase Total transmit byte counter */ - pAd->RalinkCounters.TransmittedByteCount += pMLMEContext->BulkOutSize; - - /* Clear MLME bulk flag */ - RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME); - - /* Init Tx context descriptor */ - RTUSBInitTxDesc(pAd, pMLMEContext, MGMTPIPEIDX, - (usb_complete_t) RTUSBBulkOutMLMEPacketComplete); - - /*For mgmt urb buffer, because we use sk_buff, so we need to notify the USB controller do dma mapping. */ - pUrb->transfer_dma = 0; - pUrb->transfer_flags &= (~URB_NO_TRANSFER_DMA_MAP); - - pUrb = pMLMEContext->pUrb; - ret = RTUSB_SUBMIT_URB(pUrb); - if (ret != 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("RTUSBBulkOutMLMEPacket: Submit MLME URB failed %d\n", - ret)); - RTMP_IRQ_LOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags); - pAd->BulkOutPending[MGMTPIPEIDX] = FALSE; - pAd->watchDogTxPendingCnt[MGMTPIPEIDX] = 0; - pMLMEContext->IRPPending = FALSE; - pMLMEContext->bWaitingBulkOut = TRUE; - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[MGMTPIPEIDX], IrqFlags); - - return; - } - /*DBGPRINT_RAW(RT_DEBUG_INFO, ("<---RTUSBBulkOutMLMEPacket \n")); */ -/* printk("<---RTUSBBulkOutMLMEPacket,Cpu=%d!, Dma=%d, SwIdx=%d!\n", pAd->MgmtRing.TxCpuIdx, pAd->MgmtRing.TxDmaIdx, pAd->MgmtRing.TxSwFreeIdx); */ -} - -void RTUSBBulkOutMLMEPacketComplete(struct urb *pUrb, struct pt_regs * pt_regs) -{ - struct rt_tx_context *pMLMEContext; - struct rt_rtmp_adapter *pAd; - int Status; - struct os_cookie *pObj; - int index; - - /*DBGPRINT_RAW(RT_DEBUG_INFO, ("--->RTUSBBulkOutMLMEPacketComplete\n")); */ - pMLMEContext = (struct rt_tx_context *)pUrb->context; - pAd = pMLMEContext->pAd; - pObj = (struct os_cookie *)pAd->OS_Cookie; - Status = pUrb->status; - index = pMLMEContext->SelfIdx; - - pObj->mgmt_dma_done_task.data = (unsigned long)pUrb; - tasklet_hi_schedule(&pObj->mgmt_dma_done_task); -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: PsPoll use BulkOutPipeId = 0 - - ======================================================================== -*/ -void RTUSBBulkOutPsPoll(struct rt_rtmp_adapter *pAd) -{ - struct rt_tx_context *pPsPollContext = &(pAd->PsPollContext); - PURB pUrb; - int ret = 0; - unsigned long IrqFlags; - - RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags); - if ((pAd->BulkOutPending[0] == TRUE) - || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX)) { - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags); - return; - } - pAd->BulkOutPending[0] = TRUE; - pAd->watchDogTxPendingCnt[0] = 1; - pPsPollContext->IRPPending = TRUE; - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags); - - /* Clear PS-Poll bulk flag */ - RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL); - - /* Init Tx context descriptor */ - RTUSBInitTxDesc(pAd, pPsPollContext, MGMTPIPEIDX, - (usb_complete_t) RTUSBBulkOutPsPollComplete); - - pUrb = pPsPollContext->pUrb; - ret = RTUSB_SUBMIT_URB(pUrb); - if (ret != 0) { - RTMP_IRQ_LOCK(&pAd->BulkOutLock[0], IrqFlags); - pAd->BulkOutPending[0] = FALSE; - pAd->watchDogTxPendingCnt[0] = 0; - pPsPollContext->IRPPending = FALSE; - RTMP_IRQ_UNLOCK(&pAd->BulkOutLock[0], IrqFlags); - - DBGPRINT(RT_DEBUG_ERROR, - ("RTUSBBulkOutPsPoll: Submit Tx URB failed %d\n", - ret)); - return; - } - -} - -/* PS-Poll frame use BulkOutPipeId = 0 */ -void RTUSBBulkOutPsPollComplete(struct urb *pUrb, struct pt_regs * pt_regs) -{ - struct rt_rtmp_adapter *pAd; - struct rt_tx_context *pPsPollContext; - int Status; - struct os_cookie *pObj; - - pPsPollContext = (struct rt_tx_context *)pUrb->context; - pAd = pPsPollContext->pAd; - Status = pUrb->status; - - pObj = (struct os_cookie *)pAd->OS_Cookie; - pObj->pspoll_frame_complete_task.data = (unsigned long)pUrb; - tasklet_hi_schedule(&pObj->pspoll_frame_complete_task); -} - -void DoBulkIn(struct rt_rtmp_adapter *pAd) -{ - struct rt_rx_context *pRxContext; - PURB pUrb; - int ret = 0; - unsigned long IrqFlags; - - RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); - pRxContext = &(pAd->RxContext[pAd->NextRxBulkInIndex]); - if ((pAd->PendingRx > 0) || (pRxContext->Readable == TRUE) - || (pRxContext->InUse == TRUE)) { - RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); - return; - } - pRxContext->InUse = TRUE; - pRxContext->IRPPending = TRUE; - pAd->PendingRx++; - pAd->BulkInReq++; - RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); - - /* Init Rx context descriptor */ - NdisZeroMemory(pRxContext->TransferBuffer, pRxContext->BulkInOffset); - RTUSBInitRxDesc(pAd, pRxContext); - - pUrb = pRxContext->pUrb; - ret = RTUSB_SUBMIT_URB(pUrb); - if (ret != 0) { /* fail */ - - RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); - pRxContext->InUse = FALSE; - pRxContext->IRPPending = FALSE; - pAd->PendingRx--; - pAd->BulkInReq--; - RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); - DBGPRINT(RT_DEBUG_ERROR, - ("RTUSBBulkReceive: Submit Rx URB failed %d\n", ret)); - } else { /* success */ - ASSERT((pRxContext->InUse == pRxContext->IRPPending)); - /*printk("BIDone, Pend=%d,BIIdx=%d,BIRIdx=%d!\n", pAd->PendingRx, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex); */ - } -} - -/* - ======================================================================== - - Routine Description: - USB_RxPacket initializes a URB and uses the Rx IRP to submit it - to USB. It checks if an Rx Descriptor is available and passes the - the coresponding buffer to be filled. If no descriptor is available - fails the request. When setting the completion routine we pass our - Adapter Object as Context. - - Arguments: - - Return Value: - TRUE found matched tuple cache - FALSE no matched found - - Note: - - ======================================================================== -*/ -#define fRTMP_ADAPTER_NEED_STOP_RX \ - (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \ - fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_RESET_IN_PROGRESS | \ - fRTMP_ADAPTER_REMOVE_IN_PROGRESS | fRTMP_ADAPTER_BULKIN_RESET) - -#define fRTMP_ADAPTER_NEED_STOP_HANDLE_RX \ - (fRTMP_ADAPTER_NIC_NOT_EXIST | fRTMP_ADAPTER_HALT_IN_PROGRESS | \ - fRTMP_ADAPTER_RADIO_OFF | fRTMP_ADAPTER_RESET_IN_PROGRESS | \ - fRTMP_ADAPTER_REMOVE_IN_PROGRESS) - -void RTUSBBulkReceive(struct rt_rtmp_adapter *pAd) -{ - struct rt_rx_context *pRxContext; - unsigned long IrqFlags; - - /* sanity check */ - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_HANDLE_RX)) - return; - - while (1) { - - RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); - pRxContext = &(pAd->RxContext[pAd->NextRxBulkInReadIndex]); - if (((pRxContext->InUse == FALSE) - && (pRxContext->Readable == TRUE)) - && (pRxContext->bRxHandling == FALSE)) { - pRxContext->bRxHandling = TRUE; - RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); - - /* read RxContext, Since not */ - STARxDoneInterruptHandle(pAd, TRUE); - - /* Finish to handle this bulkIn buffer. */ - RTMP_IRQ_LOCK(&pAd->BulkInLock, IrqFlags); - pRxContext->BulkInOffset = 0; - pRxContext->Readable = FALSE; - pRxContext->bRxHandling = FALSE; - pAd->ReadPosition = 0; - pAd->TransferBufferLength = 0; - INC_RING_INDEX(pAd->NextRxBulkInReadIndex, - RX_RING_SIZE); - RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); - - } else { - RTMP_IRQ_UNLOCK(&pAd->BulkInLock, IrqFlags); - break; - } - } - - if (!(RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_RX))) - DoBulkIn(pAd); - -} - -/* - ======================================================================== - - Routine Description: - This routine process Rx Irp and call rx complete function. - - Arguments: - DeviceObject Pointer to the device object for next lower - device. DeviceObject passed in here belongs to - the next lower driver in the stack because we - were invoked via IoCallDriver in USB_RxPacket - AND it is not OUR device object - Irp Ptr to completed IRP - Context Ptr to our Adapter object (context specified - in IoSetCompletionRoutine - - Return Value: - Always returns STATUS_MORE_PROCESSING_REQUIRED - - Note: - Always returns STATUS_MORE_PROCESSING_REQUIRED - ======================================================================== -*/ -void RTUSBBulkRxComplete(struct urb *pUrb, struct pt_regs *pt_regs) -{ - /* use a receive tasklet to handle received packets; */ - /* or sometimes hardware IRQ will be disabled here, so we can not */ - /* use spin_lock_bh()/spin_unlock_bh() after IRQ is disabled. :< */ - struct rt_rx_context *pRxContext; - struct rt_rtmp_adapter *pAd; - struct os_cookie *pObj; - - pRxContext = (struct rt_rx_context *)pUrb->context; - pAd = pRxContext->pAd; - pObj = (struct os_cookie *)pAd->OS_Cookie; - - pObj->rx_done_task.data = (unsigned long)pUrb; - tasklet_hi_schedule(&pObj->rx_done_task); - -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: - - ======================================================================== -*/ -void RTUSBKickBulkOut(struct rt_rtmp_adapter *pAd) -{ - /* BulkIn Reset will reset whole USB PHY. So we need to make sure fRTMP_ADAPTER_BULKIN_RESET not flaged. */ - if (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NEED_STOP_TX) - ) { - /* 2. PS-Poll frame is next */ - if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL)) - RTUSBBulkOutPsPoll(pAd); - /* 5. Mlme frame is next */ - else if ((RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_MLME)) || - (pAd->MgmtRing.TxSwFreeIdx < MGMT_RING_SIZE)) { - RTUSBBulkOutMLMEPacket(pAd, pAd->MgmtRing.TxDmaIdx); - } - /* 6. Data frame normal is next */ - if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL)) { - if (((!RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) - || - (!OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) - )) { - RTUSBBulkOutDataPacket(pAd, 0, - pAd-> - NextBulkOutIndex[0]); - } - } - if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_2)) { - if (((!RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) - || - (!OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) - )) { - RTUSBBulkOutDataPacket(pAd, 1, - pAd-> - NextBulkOutIndex[1]); - } - } - if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_3)) { - if (((!RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) - || - (!OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) - )) { - RTUSBBulkOutDataPacket(pAd, 2, - pAd-> - NextBulkOutIndex[2]); - } - } - if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NORMAL_4)) { - if (((!RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) - || - (!OPSTATUS_TEST_FLAG - (pAd, fOP_STATUS_MEDIA_STATE_CONNECTED)) - )) { - RTUSBBulkOutDataPacket(pAd, 3, - pAd-> - NextBulkOutIndex[3]); - } - } - /* 7. Null frame is the last */ - else if (RTUSB_TEST_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL)) { - if (!RTMP_TEST_FLAG - (pAd, fRTMP_ADAPTER_BSS_SCAN_IN_PROGRESS)) { - RTUSBBulkOutNullFrame(pAd); - } - } - /* 8. No data available */ - else - ; - } -} - -/* - ======================================================================== - - Routine Description: - Call from Reset action after BulkOut failed. - Arguments: - - Return Value: - - Note: - - ======================================================================== -*/ -void RTUSBCleanUpDataBulkOutQueue(struct rt_rtmp_adapter *pAd) -{ - u8 Idx; - struct rt_ht_tx_context *pTxContext; - - DBGPRINT(RT_DEBUG_TRACE, ("--->CleanUpDataBulkOutQueue\n")); - - for (Idx = 0; Idx < 4; Idx++) { - pTxContext = &pAd->TxContext[Idx]; - - pTxContext->CurWritePosition = pTxContext->NextBulkOutPosition; - pTxContext->LastOne = FALSE; - NdisAcquireSpinLock(&pAd->BulkOutLock[Idx]); - pAd->BulkOutPending[Idx] = FALSE; - NdisReleaseSpinLock(&pAd->BulkOutLock[Idx]); - } - - DBGPRINT(RT_DEBUG_TRACE, ("<---CleanUpDataBulkOutQueue\n")); -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: - - ======================================================================== -*/ -void RTUSBCleanUpMLMEBulkOutQueue(struct rt_rtmp_adapter *pAd) -{ - DBGPRINT(RT_DEBUG_TRACE, ("--->CleanUpMLMEBulkOutQueue\n")); - DBGPRINT(RT_DEBUG_TRACE, ("<---CleanUpMLMEBulkOutQueue\n")); -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: - - ======================================================================== -*/ -void RTUSBCancelPendingIRPs(struct rt_rtmp_adapter *pAd) -{ - RTUSBCancelPendingBulkInIRP(pAd); - RTUSBCancelPendingBulkOutIRP(pAd); -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: - - ======================================================================== -*/ -void RTUSBCancelPendingBulkInIRP(struct rt_rtmp_adapter *pAd) -{ - struct rt_rx_context *pRxContext; - u32 i; - - DBGPRINT_RAW(RT_DEBUG_TRACE, ("--->RTUSBCancelPendingBulkInIRP\n")); - for (i = 0; i < (RX_RING_SIZE); i++) { - pRxContext = &(pAd->RxContext[i]); - if (pRxContext->IRPPending == TRUE) { - RTUSB_UNLINK_URB(pRxContext->pUrb); - pRxContext->IRPPending = FALSE; - pRxContext->InUse = FALSE; - /*NdisInterlockedDecrement(&pAd->PendingRx); */ - /*pAd->PendingRx--; */ - } - } - DBGPRINT_RAW(RT_DEBUG_TRACE, ("<---RTUSBCancelPendingBulkInIRP\n")); -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - Note: - - ======================================================================== -*/ -void RTUSBCancelPendingBulkOutIRP(struct rt_rtmp_adapter *pAd) -{ - struct rt_ht_tx_context *pHTTXContext; - struct rt_tx_context *pMLMEContext; - struct rt_tx_context *pBeaconContext; - struct rt_tx_context *pNullContext; - struct rt_tx_context *pPsPollContext; - struct rt_tx_context *pRTSContext; - u32 i, Idx; -/* unsigned int IrqFlags; */ -/* spinlock_t *pLock; */ -/* BOOLEAN *pPending; */ - -/* pLock = &pAd->BulkOutLock[MGMTPIPEIDX]; */ -/* pPending = &pAd->BulkOutPending[MGMTPIPEIDX]; */ - - for (Idx = 0; Idx < 4; Idx++) { - pHTTXContext = &(pAd->TxContext[Idx]); - - if (pHTTXContext->IRPPending == TRUE) { - - /* Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself */ - /* remove it from the HeadPendingSendList and NULL out HeadPendingSendList */ - /* when the last IRP on the list has been cancelled; that's how we exit this loop */ - /* */ - - RTUSB_UNLINK_URB(pHTTXContext->pUrb); - - /* Sleep 200 microseconds to give cancellation time to work */ - RTMPusecDelay(200); - } - - pAd->BulkOutPending[Idx] = FALSE; - } - - /*RTMP_IRQ_LOCK(pLock, IrqFlags); */ - for (i = 0; i < MGMT_RING_SIZE; i++) { - pMLMEContext = (struct rt_tx_context *)pAd->MgmtRing.Cell[i].AllocVa; - if (pMLMEContext && (pMLMEContext->IRPPending == TRUE)) { - - /* Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself */ - /* remove it from the HeadPendingSendList and NULL out HeadPendingSendList */ - /* when the last IRP on the list has been cancelled; that's how we exit this loop */ - /* */ - - RTUSB_UNLINK_URB(pMLMEContext->pUrb); - pMLMEContext->IRPPending = FALSE; - - /* Sleep 200 microsecs to give cancellation time to work */ - RTMPusecDelay(200); - } - } - pAd->BulkOutPending[MGMTPIPEIDX] = FALSE; - /*RTMP_IRQ_UNLOCK(pLock, IrqFlags); */ - - for (i = 0; i < BEACON_RING_SIZE; i++) { - pBeaconContext = &(pAd->BeaconContext[i]); - - if (pBeaconContext->IRPPending == TRUE) { - - /* Get the USB_CONTEXT and cancel it's IRP; the completion routine will itself */ - /* remove it from the HeadPendingSendList and NULL out HeadPendingSendList */ - /* when the last IRP on the list has been cancelled; that's how we exit this loop */ - /* */ - - RTUSB_UNLINK_URB(pBeaconContext->pUrb); - - /* Sleep 200 microsecs to give cancellation time to work */ - RTMPusecDelay(200); - } - } - - pNullContext = &(pAd->NullContext); - if (pNullContext->IRPPending == TRUE) - RTUSB_UNLINK_URB(pNullContext->pUrb); - - pRTSContext = &(pAd->RTSContext); - if (pRTSContext->IRPPending == TRUE) - RTUSB_UNLINK_URB(pRTSContext->pUrb); - - pPsPollContext = &(pAd->PsPollContext); - if (pPsPollContext->IRPPending == TRUE) - RTUSB_UNLINK_URB(pPsPollContext->pUrb); - - for (Idx = 0; Idx < 4; Idx++) { - NdisAcquireSpinLock(&pAd->BulkOutLock[Idx]); - pAd->BulkOutPending[Idx] = FALSE; - NdisReleaseSpinLock(&pAd->BulkOutLock[Idx]); - } -} - -#endif /* RTMP_MAC_USB // */ diff --git a/trunk/drivers/staging/rt2870/common/rtusb_data.c b/trunk/drivers/staging/rt2870/common/rtusb_data.c deleted file mode 100644 index 5b72bcdaa78f..000000000000 --- a/trunk/drivers/staging/rt2870/common/rtusb_data.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtusb_data.c - - Abstract: - Ralink USB driver Tx/Rx functions. - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Jan 03-25-2006 created - -*/ - -#ifdef RTMP_MAC_USB - -#include "../rt_config.h" - -extern u8 Phy11BGNextRateUpward[]; /* defined in mlme.c */ -extern u8 EpToQueue[]; - -void REPORT_AMSDU_FRAMES_TO_LLC(struct rt_rtmp_adapter *pAd, - u8 *pData, unsigned long DataSize) -{ - void *pPacket; - u32 nMSDU; - struct sk_buff *pSkb; - - nMSDU = 0; - /* allocate a rx packet */ - pSkb = dev_alloc_skb(RX_BUFFER_AGGRESIZE); - pPacket = (void *)OSPKT_TO_RTPKT(pSkb); - if (pSkb) { - - /* convert 802.11 to 802.3 packet */ - pSkb->dev = get_netdev_from_bssid(pAd, BSS0); - RTMP_SET_PACKET_SOURCE(pPacket, PKTSRC_NDIS); - deaggregate_AMSDU_announce(pAd, pPacket, pData, DataSize); - } else { - DBGPRINT(RT_DEBUG_ERROR, ("Can't allocate skb\n")); - } -} - -/* - ======================================================================== - - Routine Description: - This subroutine will scan through releative ring descriptor to find - out available free ring descriptor and compare with request size. - - Arguments: - pAd Pointer to our adapter - RingType Selected Ring - - Return Value: - NDIS_STATUS_FAILURE Not enough free descriptor - NDIS_STATUS_SUCCESS Enough free descriptor - - Note: - - ======================================================================== -*/ -int RTUSBFreeDescriptorRequest(struct rt_rtmp_adapter *pAd, - u8 BulkOutPipeId, - u32 NumberRequired) -{ -/* u8 FreeNumber = 0; */ -/* u32 Index; */ - int Status = NDIS_STATUS_FAILURE; - unsigned long IrqFlags; - struct rt_ht_tx_context *pHTTXContext; - - pHTTXContext = &pAd->TxContext[BulkOutPipeId]; - RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); - if ((pHTTXContext->CurWritePosition < pHTTXContext->NextBulkOutPosition) - && - ((pHTTXContext->CurWritePosition + NumberRequired + - LOCAL_TXBUF_SIZE) > pHTTXContext->NextBulkOutPosition)) { - - RTUSB_SET_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_NORMAL << - BulkOutPipeId)); - } else if ((pHTTXContext->CurWritePosition == 8) - && (pHTTXContext->NextBulkOutPosition < - (NumberRequired + LOCAL_TXBUF_SIZE))) { - RTUSB_SET_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_NORMAL << - BulkOutPipeId)); - } else if (pHTTXContext->bCurWriting == TRUE) { - DBGPRINT(RT_DEBUG_TRACE, - ("RTUSBFreeD c3 --> QueIdx=%d, CWPos=%ld, NBOutPos=%ld!\n", - BulkOutPipeId, pHTTXContext->CurWritePosition, - pHTTXContext->NextBulkOutPosition)); - RTUSB_SET_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_NORMAL << - BulkOutPipeId)); - } else { - Status = NDIS_STATUS_SUCCESS; - } - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); - - return Status; -} - -int RTUSBFreeDescriptorRelease(struct rt_rtmp_adapter *pAd, - u8 BulkOutPipeId) -{ - unsigned long IrqFlags; - struct rt_ht_tx_context *pHTTXContext; - - pHTTXContext = &pAd->TxContext[BulkOutPipeId]; - RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); - pHTTXContext->bCurWriting = FALSE; - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); - - return NDIS_STATUS_SUCCESS; -} - -BOOLEAN RTUSBNeedQueueBackForAgg(struct rt_rtmp_adapter *pAd, u8 BulkOutPipeId) -{ - unsigned long IrqFlags; - struct rt_ht_tx_context *pHTTXContext; - BOOLEAN needQueBack = FALSE; - - pHTTXContext = &pAd->TxContext[BulkOutPipeId]; - - RTMP_IRQ_LOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); - if ((pHTTXContext->IRPPending == - TRUE) /*&& (pAd->TxSwQueue[BulkOutPipeId].Number == 0) */) { - if ((pHTTXContext->CurWritePosition < - pHTTXContext->ENextBulkOutPosition) - && - (((pHTTXContext->ENextBulkOutPosition + - MAX_AGGREGATION_SIZE) < MAX_TXBULK_LIMIT) - || (pHTTXContext->CurWritePosition > - MAX_AGGREGATION_SIZE))) { - needQueBack = TRUE; - } else - if ((pHTTXContext->CurWritePosition > - pHTTXContext->ENextBulkOutPosition) - && - ((pHTTXContext->ENextBulkOutPosition + - MAX_AGGREGATION_SIZE) < - pHTTXContext->CurWritePosition)) { - needQueBack = TRUE; - } - } - RTMP_IRQ_UNLOCK(&pAd->TxContextQueueLock[BulkOutPipeId], IrqFlags); - - return needQueBack; - -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -void RTUSBRejectPendingPackets(struct rt_rtmp_adapter *pAd) -{ - u8 Index; - struct rt_queue_entry *pEntry; - void *pPacket; - struct rt_queue_header *pQueue; - - for (Index = 0; Index < 4; Index++) { - NdisAcquireSpinLock(&pAd->TxSwQueueLock[Index]); - while (pAd->TxSwQueue[Index].Head != NULL) { - pQueue = (struct rt_queue_header *)&(pAd->TxSwQueue[Index]); - pEntry = RemoveHeadQueue(pQueue); - pPacket = QUEUE_ENTRY_TO_PACKET(pEntry); - RELEASE_NDIS_PACKET(pAd, pPacket, NDIS_STATUS_FAILURE); - } - NdisReleaseSpinLock(&pAd->TxSwQueueLock[Index]); - - } - -} - -/* - ======================================================================== - - Routine Description: - Calculates the duration which is required to transmit out frames - with given size and specified rate. - - Arguments: - pTxD Pointer to transmit descriptor - Ack Setting for Ack requirement bit - Fragment Setting for Fragment bit - RetryMode Setting for retry mode - Ifs Setting for IFS gap - Rate Setting for transmit rate - Service Setting for service - Length Frame length - TxPreamble Short or Long preamble when using CCK rates - QueIdx - 0-3, according to 802.11e/d4.4 June/2003 - - Return Value: - None - - IRQL = PASSIVE_LEVEL - IRQL = DISPATCH_LEVEL - - ======================================================================== -*/ - -void RTMPWriteTxInfo(struct rt_rtmp_adapter *pAd, - struct rt_txinfo *pTxInfo, - u16 USBDMApktLen, - IN BOOLEAN bWiv, - u8 QueueSel, u8 NextValid, u8 TxBurst) -{ - pTxInfo->USBDMATxPktLen = USBDMApktLen; - pTxInfo->QSEL = QueueSel; - if (QueueSel != FIFO_EDCA) - DBGPRINT(RT_DEBUG_TRACE, - ("====> QueueSel != FIFO_EDCA<============\n")); - pTxInfo->USBDMANextVLD = FALSE; /*NextValid; // Need to check with Jan about this. */ - pTxInfo->USBDMATxburst = TxBurst; - pTxInfo->WIV = bWiv; - pTxInfo->SwUseLastRound = 0; - pTxInfo->rsv = 0; - pTxInfo->rsv2 = 0; -} - -#endif /* RTMP_MAC_USB // */ diff --git a/trunk/drivers/staging/rt2870/common/rtusb_io.c b/trunk/drivers/staging/rt2870/common/rtusb_io.c deleted file mode 100644 index 7d2f7e05814d..000000000000 --- a/trunk/drivers/staging/rt2870/common/rtusb_io.c +++ /dev/null @@ -1,2104 +0,0 @@ -/* - ************************************************************************* - * Ralink Tech Inc. - * 5F., No.36, Taiyuan St., Jhubei City, - * Hsinchu County 302, - * Taiwan, R.O.C. - * - * (c) Copyright 2002-2007, Ralink Technology, Inc. - * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - * * - ************************************************************************* - - Module Name: - rtusb_io.c - - Abstract: - - Revision History: - Who When What - -------- ---------- ---------------------------------------------- - Name Date Modification logs - Paul Lin 06-25-2004 created -*/ - -#ifdef RTMP_MAC_USB - -#include "../rt_config.h" - -/* - ======================================================================== - - Routine Description: NIC initialization complete - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ - -static int RTUSBFirmwareRun(struct rt_rtmp_adapter *pAd) -{ - int Status; - - Status = RTUSB_VendorRequest(pAd, - USBD_TRANSFER_DIRECTION_OUT, - DEVICE_VENDOR_REQUEST_OUT, - 0x01, 0x8, 0, NULL, 0); - - return Status; -} - -/* - ======================================================================== - - Routine Description: Write Firmware to NIC. - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBFirmwareWrite(struct rt_rtmp_adapter *pAd, - const u8 *pFwImage, unsigned long FwLen) -{ - u32 MacReg; - int Status; -/* unsigned long i; */ - u16 writeLen; - - Status = RTUSBReadMACRegister(pAd, MAC_CSR0, &MacReg); - - writeLen = FwLen; - RTUSBMultiWrite(pAd, FIRMWARE_IMAGE_BASE, pFwImage, writeLen); - - Status = RTUSBWriteMACRegister(pAd, 0x7014, 0xffffffff); - Status = RTUSBWriteMACRegister(pAd, 0x701c, 0xffffffff); - Status = RTUSBFirmwareRun(pAd); - - /*2008/11/28:KH add to fix the dead rf frequency offset bug<-- */ - RTMPusecDelay(10000); - RTUSBWriteMACRegister(pAd, H2M_MAILBOX_CSR, 0); - AsicSendCommandToMcu(pAd, 0x72, 0x00, 0x00, 0x00); /*reset rf by MCU supported by new firmware */ - /*2008/11/28:KH add to fix the dead rf frequency offset bug--> */ - - return Status; -} - -int RTUSBVenderReset(struct rt_rtmp_adapter *pAd) -{ - int Status; - DBGPRINT_RAW(RT_DEBUG_ERROR, ("-->RTUSBVenderReset\n")); - Status = RTUSB_VendorRequest(pAd, - USBD_TRANSFER_DIRECTION_OUT, - DEVICE_VENDOR_REQUEST_OUT, - 0x01, 0x1, 0, NULL, 0); - - DBGPRINT_RAW(RT_DEBUG_ERROR, ("<--RTUSBVenderReset\n")); - return Status; -} - -/* - ======================================================================== - - Routine Description: Read various length data from RT2573 - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBMultiRead(struct rt_rtmp_adapter *pAd, - u16 Offset, u8 *pData, u16 length) -{ - int Status; - - Status = RTUSB_VendorRequest(pAd, - (USBD_TRANSFER_DIRECTION_IN | - USBD_SHORT_TRANSFER_OK), - DEVICE_VENDOR_REQUEST_IN, 0x7, 0, Offset, - pData, length); - - return Status; -} - -/* - ======================================================================== - - Routine Description: Write various length data to RT2573 - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBMultiWrite_OneByte(struct rt_rtmp_adapter *pAd, - u16 Offset, const u8 *pData) -{ - int Status; - - /* TODO: In 2870, use this funciton carefully cause it's not stable. */ - Status = RTUSB_VendorRequest(pAd, - USBD_TRANSFER_DIRECTION_OUT, - DEVICE_VENDOR_REQUEST_OUT, - 0x6, 0, Offset, (u8 *)pData, 1); - - return Status; -} - -int RTUSBMultiWrite(struct rt_rtmp_adapter *pAd, - u16 Offset, const u8 *pData, u16 length) -{ - int Status; - - u16 index = 0, Value; - const u8 *pSrc = pData; - u16 resude = 0; - - resude = length % 2; - length += resude; - do { - Value = (u16)(*pSrc | (*(pSrc + 1) << 8)); - Status = RTUSBSingleWrite(pAd, Offset + index, Value); - index += 2; - length -= 2; - pSrc = pSrc + 2; - } while (length > 0); - - return Status; -} - -int RTUSBSingleWrite(struct rt_rtmp_adapter *pAd, - u16 Offset, u16 Value) -{ - int Status; - - Status = RTUSB_VendorRequest(pAd, - USBD_TRANSFER_DIRECTION_OUT, - DEVICE_VENDOR_REQUEST_OUT, - 0x2, Value, Offset, NULL, 0); - - return Status; - -} - -/* - ======================================================================== - - Routine Description: Read 32-bit MAC register - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBReadMACRegister(struct rt_rtmp_adapter *pAd, - u16 Offset, u32 *pValue) -{ - int Status = 0; - u32 localVal; - - Status = RTUSB_VendorRequest(pAd, - (USBD_TRANSFER_DIRECTION_IN | - USBD_SHORT_TRANSFER_OK), - DEVICE_VENDOR_REQUEST_IN, 0x7, 0, Offset, - &localVal, 4); - - *pValue = le2cpu32(localVal); - - if (Status < 0) - *pValue = 0xffffffff; - - return Status; -} - -/* - ======================================================================== - - Routine Description: Write 32-bit MAC register - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBWriteMACRegister(struct rt_rtmp_adapter *pAd, - u16 Offset, u32 Value) -{ - int Status; - u32 localVal; - - localVal = Value; - - Status = RTUSBSingleWrite(pAd, Offset, (u16)(localVal & 0xffff)); - Status = - RTUSBSingleWrite(pAd, Offset + 2, - (u16)((localVal & 0xffff0000) >> 16)); - - return Status; -} - -/* - ======================================================================== - - Routine Description: Read 8-bit BBP register - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBReadBBPRegister(struct rt_rtmp_adapter *pAd, - u8 Id, u8 *pValue) -{ - BBP_CSR_CFG_STRUC BbpCsr; - u32 i = 0; - int status; - - /* Verify the busy condition */ - do { - status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word); - if (status >= 0) { - if (!(BbpCsr.field.Busy == BUSY)) - break; - } - DBGPRINT(RT_DEBUG_TRACE, - ("RTUSBReadBBPRegister(BBP_CSR_CFG_1):retry count=%d!\n", - i)); - i++; - } while ((i < RETRY_LIMIT) - && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))); - - if ((i == RETRY_LIMIT) - || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { - /* */ - /* Read failed then Return Default value. */ - /* */ - *pValue = pAd->BbpWriteLatch[Id]; - - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("Retry count exhausted or device removed!!!\n")); - return STATUS_UNSUCCESSFUL; - } - /* Prepare for write material */ - BbpCsr.word = 0; - BbpCsr.field.fRead = 1; - BbpCsr.field.Busy = 1; - BbpCsr.field.RegNum = Id; - RTUSBWriteMACRegister(pAd, BBP_CSR_CFG, BbpCsr.word); - - i = 0; - /* Verify the busy condition */ - do { - status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word); - if (status >= 0) { - if (!(BbpCsr.field.Busy == BUSY)) { - *pValue = (u8)BbpCsr.field.Value; - break; - } - } - DBGPRINT(RT_DEBUG_TRACE, - ("RTUSBReadBBPRegister(BBP_CSR_CFG_2):retry count=%d!\n", - i)); - i++; - } while ((i < RETRY_LIMIT) - && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))); - - if ((i == RETRY_LIMIT) - || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { - /* */ - /* Read failed then Return Default value. */ - /* */ - *pValue = pAd->BbpWriteLatch[Id]; - - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("Retry count exhausted or device removed!!!\n")); - return STATUS_UNSUCCESSFUL; - } - - return STATUS_SUCCESS; -} - -/* - ======================================================================== - - Routine Description: Write 8-bit BBP register - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBWriteBBPRegister(struct rt_rtmp_adapter *pAd, - u8 Id, u8 Value) -{ - BBP_CSR_CFG_STRUC BbpCsr; - u32 i = 0; - int status; - /* Verify the busy condition */ - do { - status = RTUSBReadMACRegister(pAd, BBP_CSR_CFG, &BbpCsr.word); - if (status >= 0) { - if (!(BbpCsr.field.Busy == BUSY)) - break; - } - DBGPRINT(RT_DEBUG_TRACE, - ("RTUSBWriteBBPRegister(BBP_CSR_CFG):retry count=%d!\n", - i)); - i++; - } while ((i < RETRY_LIMIT) - && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))); - - if ((i == RETRY_LIMIT) - || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("Retry count exhausted or device removed!!!\n")); - return STATUS_UNSUCCESSFUL; - } - /* Prepare for write material */ - BbpCsr.word = 0; - BbpCsr.field.fRead = 0; - BbpCsr.field.Value = Value; - BbpCsr.field.Busy = 1; - BbpCsr.field.RegNum = Id; - RTUSBWriteMACRegister(pAd, BBP_CSR_CFG, BbpCsr.word); - - pAd->BbpWriteLatch[Id] = Value; - - return STATUS_SUCCESS; -} - -/* - ======================================================================== - - Routine Description: Write RF register through MAC - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBWriteRFRegister(struct rt_rtmp_adapter *pAd, u32 Value) -{ - PHY_CSR4_STRUC PhyCsr4; - u32 i = 0; - int status; - - NdisZeroMemory(&PhyCsr4, sizeof(PHY_CSR4_STRUC)); - do { - status = RTUSBReadMACRegister(pAd, RF_CSR_CFG0, &PhyCsr4.word); - if (status >= 0) { - if (!(PhyCsr4.field.Busy)) - break; - } - DBGPRINT(RT_DEBUG_TRACE, - ("RTUSBWriteRFRegister(RF_CSR_CFG0):retry count=%d!\n", - i)); - i++; - } while ((i < RETRY_LIMIT) - && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))); - - if ((i == RETRY_LIMIT) - || (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) { - DBGPRINT_RAW(RT_DEBUG_ERROR, - ("Retry count exhausted or device removed!!!\n")); - return STATUS_UNSUCCESSFUL; - } - - RTUSBWriteMACRegister(pAd, RF_CSR_CFG0, Value); - - return STATUS_SUCCESS; -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBReadEEPROM(struct rt_rtmp_adapter *pAd, - u16 Offset, u8 *pData, u16 length) -{ - int Status = STATUS_SUCCESS; - - Status = RTUSB_VendorRequest(pAd, - (USBD_TRANSFER_DIRECTION_IN | - USBD_SHORT_TRANSFER_OK), - DEVICE_VENDOR_REQUEST_IN, 0x9, 0, Offset, - pData, length); - - return Status; -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBWriteEEPROM(struct rt_rtmp_adapter *pAd, - u16 Offset, u8 *pData, u16 length) -{ - int Status = STATUS_SUCCESS; - - Status = RTUSB_VendorRequest(pAd, - USBD_TRANSFER_DIRECTION_OUT, - DEVICE_VENDOR_REQUEST_OUT, - 0x8, 0, Offset, pData, length); - - return Status; -} - -int RTUSBReadEEPROM16(struct rt_rtmp_adapter *pAd, - u16 offset, u16 *pData) -{ - int status; - u16 localData; - - status = RTUSBReadEEPROM(pAd, offset, (u8 *)(&localData), 2); - if (status == STATUS_SUCCESS) - *pData = le2cpu16(localData); - - return status; - -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -void RTUSBPutToSleep(struct rt_rtmp_adapter *pAd) -{ - u32 value; - - /* Timeout 0x40 x 50us */ - value = (SLEEPCID << 16) + (OWNERMCU << 24) + (0x40 << 8) + 1; - RTUSBWriteMACRegister(pAd, 0x7010, value); - RTUSBWriteMACRegister(pAd, 0x404, 0x30); - /*RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS); */ - DBGPRINT_RAW(RT_DEBUG_ERROR, ("Sleep Mailbox testvalue %x\n", value)); - -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBWakeUp(struct rt_rtmp_adapter *pAd) -{ - int Status; - - Status = RTUSB_VendorRequest(pAd, - USBD_TRANSFER_DIRECTION_OUT, - DEVICE_VENDOR_REQUEST_OUT, - 0x01, 0x09, 0, NULL, 0); - - return Status; -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -void RTUSBInitializeCmdQ(struct rt_cmdq *cmdq) -{ - cmdq->head = NULL; - cmdq->tail = NULL; - cmdq->size = 0; - cmdq->CmdQState = RTMP_TASK_STAT_INITED; -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBEnqueueCmdFromNdis(struct rt_rtmp_adapter *pAd, - IN NDIS_OID Oid, - IN BOOLEAN SetInformation, - void *pInformationBuffer, - u32 InformationBufferLength) -{ - int status; - struct rt_cmdqelmt *cmdqelmt = NULL; - struct rt_rtmp_os_task *pTask = &pAd->cmdQTask; - -#ifdef KTHREAD_SUPPORT - if (pTask->kthread_task == NULL) -#else - CHECK_PID_LEGALITY(pTask->taskPID) { - } - else -#endif - return NDIS_STATUS_RESOURCES; - - status = os_alloc_mem(pAd, (u8 **) (&cmdqelmt), sizeof(struct rt_cmdqelmt)); - if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt == NULL)) - return NDIS_STATUS_RESOURCES; - - cmdqelmt->buffer = NULL; - if (pInformationBuffer != NULL) { - status = - os_alloc_mem(pAd, (u8 **) & cmdqelmt->buffer, - InformationBufferLength); - if ((status != NDIS_STATUS_SUCCESS) - || (cmdqelmt->buffer == NULL)) { - kfree(cmdqelmt); - return NDIS_STATUS_RESOURCES; - } else { - NdisMoveMemory(cmdqelmt->buffer, pInformationBuffer, - InformationBufferLength); - cmdqelmt->bufferlength = InformationBufferLength; - } - } else - cmdqelmt->bufferlength = 0; - - cmdqelmt->command = Oid; - cmdqelmt->CmdFromNdis = TRUE; - if (SetInformation == TRUE) - cmdqelmt->SetOperation = TRUE; - else - cmdqelmt->SetOperation = FALSE; - - NdisAcquireSpinLock(&pAd->CmdQLock); - if (pAd->CmdQ.CmdQState & RTMP_TASK_CAN_DO_INSERT) { - EnqueueCmd((&pAd->CmdQ), cmdqelmt); - status = NDIS_STATUS_SUCCESS; - } else { - status = NDIS_STATUS_FAILURE; - } - NdisReleaseSpinLock(&pAd->CmdQLock); - - if (status == NDIS_STATUS_FAILURE) { - if (cmdqelmt->buffer) - os_free_mem(pAd, cmdqelmt->buffer); - os_free_mem(pAd, cmdqelmt); - } else - RTUSBCMDUp(pAd); - - return NDIS_STATUS_SUCCESS; -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -int RTUSBEnqueueInternalCmd(struct rt_rtmp_adapter *pAd, - IN NDIS_OID Oid, - void *pInformationBuffer, - u32 InformationBufferLength) -{ - int status; - struct rt_cmdqelmt *cmdqelmt = NULL; - - status = os_alloc_mem(pAd, (u8 **) & cmdqelmt, sizeof(struct rt_cmdqelmt)); - if ((status != NDIS_STATUS_SUCCESS) || (cmdqelmt == NULL)) - return NDIS_STATUS_RESOURCES; - NdisZeroMemory(cmdqelmt, sizeof(struct rt_cmdqelmt)); - - if (InformationBufferLength > 0) { - status = - os_alloc_mem(pAd, (u8 **) & cmdqelmt->buffer, - InformationBufferLength); - if ((status != NDIS_STATUS_SUCCESS) - || (cmdqelmt->buffer == NULL)) { - os_free_mem(pAd, cmdqelmt); - return NDIS_STATUS_RESOURCES; - } else { - NdisMoveMemory(cmdqelmt->buffer, pInformationBuffer, - InformationBufferLength); - cmdqelmt->bufferlength = InformationBufferLength; - } - } else { - cmdqelmt->buffer = NULL; - cmdqelmt->bufferlength = 0; - } - - cmdqelmt->command = Oid; - cmdqelmt->CmdFromNdis = FALSE; - - if (cmdqelmt != NULL) { - NdisAcquireSpinLock(&pAd->CmdQLock); - if (pAd->CmdQ.CmdQState & RTMP_TASK_CAN_DO_INSERT) { - EnqueueCmd((&pAd->CmdQ), cmdqelmt); - status = NDIS_STATUS_SUCCESS; - } else { - status = NDIS_STATUS_FAILURE; - } - NdisReleaseSpinLock(&pAd->CmdQLock); - - if (status == NDIS_STATUS_FAILURE) { - if (cmdqelmt->buffer) - os_free_mem(pAd, cmdqelmt->buffer); - os_free_mem(pAd, cmdqelmt); - } else - RTUSBCMDUp(pAd); - } - return NDIS_STATUS_SUCCESS; -} - -/* - ======================================================================== - - Routine Description: - - Arguments: - - Return Value: - - IRQL = - - Note: - - ======================================================================== -*/ -void RTUSBDequeueCmd(struct rt_cmdq *cmdq, struct rt_cmdqelmt * * pcmdqelmt) -{ - *pcmdqelmt = cmdq->head; - - if (*pcmdqelmt != NULL) { - cmdq->head = cmdq->head->next; - cmdq->size--; - if (cmdq->size == 0) - cmdq->tail = NULL; - } -} - -/* - ======================================================================== - usb_control_msg - Builds a control urb, sends it off and waits for completion - @dev: pointer to the usb device to send the message to - @pipe: endpoint "pipe" to send the message to - @request: USB message request value - @requesttype: USB message request type value - @value: USB message value - @index: USB message index value - @data: pointer to the data to send - @size: length in bytes of the data to send - @timeout: time in jiffies to wait for the message to complete before - timing out (if 0 the wait is forever) - Context: !in_interrupt () - - This function sends a simple control message to a specified endpoint - and waits for the message to complete, or timeout. - If successful, it returns the number of bytes transferred, otherwise a negative error number. - - Don't use this function from within an interrupt context, like a - bottom half handler. If you need an asynchronous message, or need to send - a message from within interrupt context, use usb_submit_urb() - If a thread in your driver uses this call, make sure your disconnect() - method can wait for it to complete. Since you don't have a handle on - the URB used, you can't cancel the request. - - Routine Description: - - Arguments: - - Return Value: - - Note: - - ======================================================================== -*/ -int RTUSB_VendorRequest(struct rt_rtmp_adapter *pAd, - u32 TransferFlags, - u8 RequestType, - u8 Request, - u16 Value, - u16 Index, - void *TransferBuffer, - u32 TransferBufferLength) -{ - int ret = 0; - struct os_cookie *pObj = (struct os_cookie *)pAd->OS_Cookie; - - if (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) { - DBGPRINT(RT_DEBUG_ERROR, ("device disconnected\n")); - return -1; - } else if (in_interrupt()) { - DBGPRINT(RT_DEBUG_ERROR, - ("in_interrupt, RTUSB_VendorRequest Request%02x Value%04x Offset%04x\n", - Request, Value, Index)); - - return -1; - } else { -#define MAX_RETRY_COUNT 10 - - int retryCount = 0; - void *tmpBuf = TransferBuffer; - - ret = down_interruptible(&(pAd->UsbVendorReq_semaphore)); - if (pAd->UsbVendorReqBuf) { - ASSERT(TransferBufferLength < MAX_PARAM_BUFFER_SIZE); - - tmpBuf = (void *)pAd->UsbVendorReqBuf; - NdisZeroMemory(pAd->UsbVendorReqBuf, - TransferBufferLength); - - if (RequestType == DEVICE_VENDOR_REQUEST_OUT) - NdisMoveMemory(tmpBuf, TransferBuffer, - TransferBufferLength); - } - - do { - if (RequestType == DEVICE_VENDOR_REQUEST_OUT) - ret = - usb_control_msg(pObj->pUsb_Dev, - usb_sndctrlpipe(pObj-> - pUsb_Dev, - 0), Request, - RequestType, Value, Index, - tmpBuf, - TransferBufferLength, - CONTROL_TIMEOUT_JIFFIES); - else if (RequestType == DEVICE_VENDOR_REQUEST_IN) - ret = - usb_control_msg(pObj->pUsb_Dev, - usb_rcvctrlpipe(pObj-> - pUsb_Dev, - 0), Request, - RequestType, Value, Index, - tmpBuf, - TransferBufferLength, - CONTROL_TIMEOUT_JIFFIES); - else { - DBGPRINT(RT_DEBUG_ERROR, - ("vendor request direction is failed\n")); - ret = -1; - } - - retryCount++; - if (ret < 0) { - DBGPRINT(RT_DEBUG_OFF, ("#\n")); - RTMPusecDelay(5000); - } - } while ((ret < 0) && (retryCount < MAX_RETRY_COUNT)); - - if ((pAd->UsbVendorReqBuf) - && (RequestType == DEVICE_VENDOR_REQUEST_IN)) - NdisMoveMemory(TransferBuffer, tmpBuf, - TransferBufferLength); - up(&(pAd->UsbVendorReq_semaphore)); - - if (ret < 0) { - DBGPRINT(RT_DEBUG_ERROR, - ("RTUSB_VendorRequest failed(%d),TxFlags=0x%x, ReqType=%s, Req=0x%x, Index=0x%x\n", - ret, TransferFlags, - (RequestType == - DEVICE_VENDOR_REQUEST_OUT ? "OUT" : "IN"), - Request, Index)); - if (Request == 0x2) - DBGPRINT(RT_DEBUG_ERROR, - ("\tRequest Value=0x%04x!\n", Value)); - - if ((TransferBuffer != NULL) - && (TransferBufferLength > 0)) - hex_dump("Failed TransferBuffer value", - TransferBuffer, TransferBufferLength); - } - - } - - if (ret != -1) - return STATUS_SUCCESS; - else - return STATUS_UNSUCCESSFUL; -} - -/* - ======================================================================== - - Routine Description: - Creates an IRP to submite an IOCTL_INTERNAL_USB_RESET_PORT - synchronously. Callers of this function must be running at - PASSIVE LEVEL. - - Arguments: - - Return Value: - - Note: - - ======================================================================== -*/ -int RTUSB_ResetDevice(struct rt_rtmp_adapter *pAd) -{ - int Status = TRUE; - - DBGPRINT_RAW(RT_DEBUG_TRACE, ("--->USB_ResetDevice\n")); - /*RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS); */ - return Status; -} - -void CMDHandler(struct rt_rtmp_adapter *pAd) -{ - struct rt_cmdqelmt *cmdqelmt; - u8 *pData; - int NdisStatus = NDIS_STATUS_SUCCESS; -/* unsigned long Now = 0; */ - int ntStatus; -/* unsigned long IrqFlags; */ - - while (pAd && pAd->CmdQ.size > 0) { - NdisStatus = NDIS_STATUS_SUCCESS; - - NdisAcquireSpinLock(&pAd->CmdQLock); - RTUSBDequeueCmd(&pAd->CmdQ, &cmdqelmt); - NdisReleaseSpinLock(&pAd->CmdQLock); - - if (cmdqelmt == NULL) - break; - - pData = cmdqelmt->buffer; - - if (! - (RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST) - || RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) { - switch (cmdqelmt->command) { - case CMDTHREAD_CHECK_GPIO: - { - u32 data; - - { - /* Read GPIO pin2 as Hardware controlled radio state */ - - RTUSBReadMACRegister(pAd, - GPIO_CTRL_CFG, - &data); - - if (data & 0x04) { - pAd->StaCfg.bHwRadio = - TRUE; - } else { - pAd->StaCfg.bHwRadio = - FALSE; - } - - if (pAd->StaCfg.bRadio != - (pAd->StaCfg.bHwRadio - && pAd->StaCfg.bSwRadio)) { - pAd->StaCfg.bRadio = - (pAd->StaCfg. - bHwRadio - && pAd->StaCfg. - bSwRadio); - if (pAd->StaCfg. - bRadio == TRUE) { - DBGPRINT_RAW - (RT_DEBUG_ERROR, - ("!!! Radio On !!!\n")); - - MlmeRadioOn - (pAd); - /* Update extra information */ - pAd->ExtraInfo = - EXTRA_INFO_CLEAR; - } else { - DBGPRINT_RAW - (RT_DEBUG_ERROR, - ("!!! Radio Off !!!\n")); - - MlmeRadioOff - (pAd); - /* Update extra information */ - pAd->ExtraInfo = - HW_RADIO_OFF; - } - } - } - } - break; - - case CMDTHREAD_QKERIODIC_EXECUT: - { - StaQuickResponeForRateUpExec(NULL, pAd, - NULL, - NULL); - } - break; - - case CMDTHREAD_RESET_BULK_OUT: - { - u32 MACValue; - u8 Index; - int ret = 0; - struct rt_ht_tx_context *pHTTXContext; -/* struct rt_rtmp_tx_ring *pTxRing; */ - unsigned long IrqFlags; - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("CmdThread : CMDTHREAD_RESET_BULK_OUT(ResetPipeid=0x%0x)===>\n", - pAd->bulkResetPipeid)); - /* All transfers must be aborted or cancelled before attempting to reset the pipe. */ - /*RTUSBCancelPendingBulkOutIRP(pAd); */ - /* Wait 10ms to let previous packet that are already in HW FIFO to clear. by MAXLEE 12-25-2007 */ - Index = 0; - do { - RTUSBReadMACRegister(pAd, - TXRXQ_PCNT, - &MACValue); - if ((MACValue & 0xf00000 - /*0x800000 */) == 0) - break; - Index++; - RTMPusecDelay(10000); - } while (Index < 100); - MACValue = 0; - RTUSBReadMACRegister(pAd, USB_DMA_CFG, - &MACValue); - /* To prevent Read Register error, we 2nd check the validity. */ - if ((MACValue & 0xc00000) == 0) - RTUSBReadMACRegister(pAd, - USB_DMA_CFG, - &MACValue); - /* To prevent Read Register error, we 3rd check the validity. */ - if ((MACValue & 0xc00000) == 0) - RTUSBReadMACRegister(pAd, - USB_DMA_CFG, - &MACValue); - MACValue |= 0x80000; - RTUSBWriteMACRegister(pAd, USB_DMA_CFG, - MACValue); - - /* Wait 1ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007 */ - RTMPusecDelay(1000); - - MACValue &= (~0x80000); - RTUSBWriteMACRegister(pAd, USB_DMA_CFG, - MACValue); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("\tSet 0x2a0 bit19. Clear USB DMA TX path\n")); - - /* Wait 5ms to prevent next URB to bulkout before HW reset. by MAXLEE 12-25-2007 */ - /*RTMPusecDelay(5000); */ - - if ((pAd-> - bulkResetPipeid & - BULKOUT_MGMT_RESET_FLAG) == - BULKOUT_MGMT_RESET_FLAG) { - RTMP_CLEAR_FLAG(pAd, - fRTMP_ADAPTER_BULKOUT_RESET); - if (pAd->MgmtRing.TxSwFreeIdx < - MGMT_RING_SIZE - /* pMLMEContext->bWaitingBulkOut == TRUE */ - ) { - RTUSB_SET_BULK_FLAG(pAd, - fRTUSB_BULK_OUT_MLME); - } - RTUSBKickBulkOut(pAd); - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("\tTX MGMT RECOVER Done!\n")); - } else { - pHTTXContext = - &(pAd-> - TxContext[pAd-> - bulkResetPipeid]); - /*NdisAcquireSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); */ - RTMP_INT_LOCK(&pAd-> - BulkOutLock[pAd-> - bulkResetPipeid], - IrqFlags); - if (pAd-> - BulkOutPending[pAd-> - bulkResetPipeid] - == FALSE) { - pAd-> - BulkOutPending[pAd-> - bulkResetPipeid] - = TRUE; - pHTTXContext-> - IRPPending = TRUE; - pAd-> - watchDogTxPendingCnt - [pAd-> - bulkResetPipeid] = - 1; - - /* no matter what, clean the flag */ - RTMP_CLEAR_FLAG(pAd, - fRTMP_ADAPTER_BULKOUT_RESET); - - /*NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); */ - RTMP_INT_UNLOCK(&pAd-> - BulkOutLock - [pAd-> - bulkResetPipeid], - IrqFlags); - { - RTUSBInitHTTxDesc - (pAd, - pHTTXContext, - pAd-> - bulkResetPipeid, - pHTTXContext-> - BulkOutSize, - (usb_complete_t) - RTUSBBulkOutDataPacketComplete); - - ret = RTUSB_SUBMIT_URB - (pHTTXContext-> - pUrb); - if (ret != 0) { - RTMP_INT_LOCK - (&pAd-> - BulkOutLock - [pAd-> - bulkResetPipeid], - IrqFlags); - pAd-> - BulkOutPending - [pAd-> - bulkResetPipeid] - = - FALSE; - pHTTXContext-> - IRPPending - = - FALSE; - pAd-> - watchDogTxPendingCnt - [pAd-> - bulkResetPipeid] - = 0; - RTMP_INT_UNLOCK - (&pAd-> - BulkOutLock - [pAd-> - bulkResetPipeid], - IrqFlags); - - DBGPRINT - (RT_DEBUG_ERROR, - ("CmdThread : CMDTHREAD_RESET_BULK_OUT: Submit Tx URB failed %d\n", - ret)); - } else { - RTMP_IRQ_LOCK - (&pAd-> - BulkOutLock - [pAd-> - bulkResetPipeid], - IrqFlags); - DBGPRINT_RAW - (RT_DEBUG_TRACE, - ("\tCMDTHREAD_RESET_BULK_OUT: TxContext[%d]:CWPos=%ld, NBPos=%ld, ENBPos=%ld, bCopy=%d, pending=%d!\n", - pAd-> - bulkResetPipeid, - pHTTXContext-> - CurWritePosition, - pHTTXContext-> - NextBulkOutPosition, - pHTTXContext-> - ENextBulkOutPosition, - pHTTXContext-> - bCopySavePad, - pAd-> - BulkOutPending - [pAd-> - bulkResetPipeid])); - DBGPRINT_RAW - (RT_DEBUG_TRACE, - ("\t\tBulkOut Req=0x%lx, Complete=0x%lx, Other=0x%lx\n", - pAd-> - BulkOutReq, - pAd-> - BulkOutComplete, - pAd-> - BulkOutCompleteOther)); - RTMP_IRQ_UNLOCK - (&pAd-> - BulkOutLock - [pAd-> - bulkResetPipeid], - IrqFlags); - DBGPRINT_RAW - (RT_DEBUG_TRACE, - ("\tCMDTHREAD_RESET_BULK_OUT: Submit Tx DATA URB for failed BulkReq(0x%lx) Done, status=%d!\n", - pAd-> - bulkResetReq - [pAd-> - bulkResetPipeid], - pHTTXContext-> - pUrb-> - status)); - - } - } - } else { - /*NdisReleaseSpinLock(&pAd->BulkOutLock[pAd->bulkResetPipeid]); */ - /*RTMP_INT_UNLOCK(&pAd->BulkOutLock[pAd->bulkResetPipeid], IrqFlags); */ - - DBGPRINT_RAW - (RT_DEBUG_ERROR, - ("CmdThread : TX DATA RECOVER FAIL for BulkReq(0x%lx) because BulkOutPending[%d] is TRUE!\n", - pAd-> - bulkResetReq[pAd-> - bulkResetPipeid], - pAd-> - bulkResetPipeid)); - if (pAd-> - bulkResetPipeid == - 0) { - u8 - pendingContext - = 0; - struct rt_ht_tx_context * - pHTTXContext - = - (struct rt_ht_tx_context *) - (&pAd-> - TxContext - [pAd-> - bulkResetPipeid]); - struct rt_tx_context * - pMLMEContext - = - (struct rt_tx_context *) - (pAd-> - MgmtRing. - Cell[pAd-> - MgmtRing. - TxDmaIdx]. - AllocVa); - struct rt_tx_context * - pNULLContext - = - (struct rt_tx_context *) - (&pAd-> - PsPollContext); - struct rt_tx_context * - pPsPollContext - = - (struct rt_tx_context *) - (&pAd-> - NullContext); - - if (pHTTXContext->IRPPending) - pendingContext - |= - 1; - else if - (pMLMEContext-> - IRPPending) - pendingContext - |= - 2; - else if - (pNULLContext-> - IRPPending) - pendingContext - |= - 4; - else if - (pPsPollContext-> - IRPPending) - pendingContext - |= - 8; - else - pendingContext - = 0; - - DBGPRINT_RAW - (RT_DEBUG_ERROR, - ("\tTX Occupied by %d!\n", - pendingContext)); - } - /* no matter what, clean the flag */ - RTMP_CLEAR_FLAG(pAd, - fRTMP_ADAPTER_BULKOUT_RESET); - - RTMP_INT_UNLOCK(&pAd-> - BulkOutLock - [pAd-> - bulkResetPipeid], - IrqFlags); - - RTUSB_SET_BULK_FLAG(pAd, - (fRTUSB_BULK_OUT_DATA_NORMAL - << - pAd-> - bulkResetPipeid)); - } - - RTMPDeQueuePacket(pAd, FALSE, - NUM_OF_TX_RING, - MAX_TX_PROCESS); - /*RTUSBKickBulkOut(pAd); */ - } - - } - /* - // Don't cancel BULKIN. - while ((atomic_read(&pAd->PendingRx) > 0) && - (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) - { - if (atomic_read(&pAd->PendingRx) > 0) - { - DBGPRINT_RAW(RT_DEBUG_ERROR, ("BulkIn IRP Pending!!cancel it!\n")); - RTUSBCancelPendingBulkInIRP(pAd); - } - RTMPusecDelay(100000); - } - - if ((atomic_read(&pAd->PendingRx) == 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS))) - { - u8 i; - RTUSBRxPacket(pAd); - pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index - pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer - for (i = 0; i < (RX_RING_SIZE); i++) - { - struct rt_rx_context *pRxContext = &(pAd->RxContext[i]); - - pRxContext->pAd = pAd; - pRxContext->InUse = FALSE; - pRxContext->IRPPending = FALSE; - pRxContext->Readable = FALSE; - pRxContext->ReorderInUse = FALSE; - - } - RTUSBBulkReceive(pAd); - DBGPRINT_RAW(RT_DEBUG_ERROR, ("RTUSBBulkReceive\n")); - } */ - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("CmdThread : CMDTHREAD_RESET_BULK_OUT<===\n")); - break; - - case CMDTHREAD_RESET_BULK_IN: - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("CmdThread : CMDTHREAD_RESET_BULK_IN === >\n")); - - /* All transfers must be aborted or cancelled before attempting to reset the pipe. */ - { - u32 MACValue; - { - /*while ((atomic_read(&pAd->PendingRx) > 0) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST))) */ - if ((pAd->PendingRx > 0) - && - (!RTMP_TEST_FLAG - (pAd, - fRTMP_ADAPTER_NIC_NOT_EXIST))) { - DBGPRINT_RAW - (RT_DEBUG_ERROR, - ("BulkIn IRP Pending!!!\n")); - RTUSBCancelPendingBulkInIRP - (pAd); - RTMPusecDelay(100000); - pAd->PendingRx = 0; - } - } - /* Wait 10ms before reading register. */ - RTMPusecDelay(10000); - ntStatus = - RTUSBReadMACRegister(pAd, MAC_CSR0, - &MACValue); - - if ((NT_SUCCESS(ntStatus) == TRUE) && - (!(RTMP_TEST_FLAG - (pAd, - (fRTMP_ADAPTER_RESET_IN_PROGRESS - | fRTMP_ADAPTER_RADIO_OFF | - fRTMP_ADAPTER_HALT_IN_PROGRESS - | - fRTMP_ADAPTER_NIC_NOT_EXIST))))) - { - u8 i; - - if (RTMP_TEST_FLAG - (pAd, - (fRTMP_ADAPTER_RESET_IN_PROGRESS - | fRTMP_ADAPTER_RADIO_OFF - | - fRTMP_ADAPTER_HALT_IN_PROGRESS - | - fRTMP_ADAPTER_NIC_NOT_EXIST))) - break; - pAd->NextRxBulkInPosition = - pAd->RxContext[pAd-> - NextRxBulkInIndex]. - BulkInOffset; - DBGPRINT(RT_DEBUG_TRACE, - ("BULK_IN_RESET: NBIIdx=0x%x,NBIRIdx=0x%x, BIRPos=0x%lx. BIReq=x%lx, BIComplete=0x%lx, BICFail0x%lx\n", - pAd-> - NextRxBulkInIndex, - pAd-> - NextRxBulkInReadIndex, - pAd-> - NextRxBulkInPosition, - pAd->BulkInReq, - pAd->BulkInComplete, - pAd-> - BulkInCompleteFail)); - for (i = 0; i < RX_RING_SIZE; - i++) { - DBGPRINT(RT_DEBUG_TRACE, - ("\tRxContext[%d]: IRPPending=%d, InUse=%d, Readable=%d!\n", - i, - pAd-> - RxContext[i]. - IRPPending, - pAd-> - RxContext[i]. - InUse, - pAd-> - RxContext[i]. - Readable)); - } - /* - - DBGPRINT_RAW(RT_DEBUG_ERROR, ("==========================================\n")); - - pAd->NextRxBulkInReadIndex = 0; // Next Rx Read index - pAd->NextRxBulkInIndex = 0; // Rx Bulk pointer - for (i = 0; i < (RX_RING_SIZE); i++) - { - struct rt_rx_context *pRxContext = &(pAd->RxContext[i]); - - pRxContext->pAd = pAd; - pRxContext->InUse = FALSE; - pRxContext->IRPPending = FALSE; - pRxContext->Readable = FALSE; - pRxContext->ReorderInUse = FALSE; - - } */ - RTMP_CLEAR_FLAG(pAd, - fRTMP_ADAPTER_BULKIN_RESET); - for (i = 0; - i < - pAd->CommonCfg. - NumOfBulkInIRP; i++) { - /*RTUSBBulkReceive(pAd); */ - struct rt_rx_context *pRxContext; - PURB pUrb; - int ret = 0; - unsigned long IrqFlags; - - RTMP_IRQ_LOCK(&pAd-> - BulkInLock, - IrqFlags); - pRxContext = - &(pAd-> - RxContext[pAd-> - NextRxBulkInIndex]); - if ((pAd->PendingRx > 0) - || (pRxContext-> - Readable == - TRUE) - || (pRxContext-> - InUse == - TRUE)) { - RTMP_IRQ_UNLOCK - (&pAd-> - BulkInLock, - IrqFlags); - break; - } - pRxContext->InUse = - TRUE; - pRxContext->IRPPending = - TRUE; - pAd->PendingRx++; - pAd->BulkInReq++; - RTMP_IRQ_UNLOCK(&pAd-> - BulkInLock, - IrqFlags); - - /* Init Rx context descriptor */ - RTUSBInitRxDesc(pAd, - pRxContext); - pUrb = pRxContext->pUrb; - ret = RTUSB_SUBMIT_URB(pUrb); - if (ret != 0) { /* fail */ - - RTMP_IRQ_LOCK - (&pAd-> - BulkInLock, - IrqFlags); - pRxContext-> - InUse = - FALSE; - pRxContext-> - IRPPending = - FALSE; - pAd-> - PendingRx--; - pAd-> - BulkInReq--; - RTMP_IRQ_UNLOCK - (&pAd-> - BulkInLock, - IrqFlags); - DBGPRINT - (RT_DEBUG_ERROR, - ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB failed(%d), status=%d\n", - ret, - pUrb-> - status)); - } else { /* success */ - /*DBGPRINT(RT_DEBUG_TRACE, ("BIDone, Pend=%d,BIIdx=%d,BIRIdx=%d!\n", */ - /* pAd->PendingRx, pAd->NextRxBulkInIndex, pAd->NextRxBulkInReadIndex)); */ - DBGPRINT_RAW - (RT_DEBUG_TRACE, - ("CMDTHREAD_RESET_BULK_IN: Submit Rx URB Done, status=%d!\n", - pUrb-> - status)); - ASSERT((pRxContext->InUse == pRxContext->IRPPending)); - } - } - - } else { - /* Card must be removed */ - if (NT_SUCCESS(ntStatus) != - TRUE) { - RTMP_SET_FLAG(pAd, - fRTMP_ADAPTER_NIC_NOT_EXIST); - DBGPRINT_RAW - (RT_DEBUG_ERROR, - ("CMDTHREAD_RESET_BULK_IN: Read Register Failed!Card must be removed!!\n\n")); - } else { - DBGPRINT_RAW - (RT_DEBUG_ERROR, - ("CMDTHREAD_RESET_BULK_IN: Cannot do bulk in because flags(0x%lx) on !\n", - pAd->Flags)); - } - } - } - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("CmdThread : CMDTHREAD_RESET_BULK_IN <===\n")); - break; - - case CMDTHREAD_SET_ASIC_WCID: - { - struct rt_set_asic_wcid SetAsicWcid; - u16 offset; - u32 MACValue, MACRValue = 0; - SetAsicWcid = - *((struct rt_set_asic_wcid *)(pData)); - - if (SetAsicWcid.WCID >= - MAX_LEN_OF_MAC_TABLE) - return; - - offset = - MAC_WCID_BASE + - ((u8)SetAsicWcid.WCID) * - HW_WCID_ENTRY_SIZE; - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("CmdThread : CMDTHREAD_SET_ASIC_WCID : WCID = %ld, SetTid = %lx, DeleteTid = %lx.\n", - SetAsicWcid.WCID, - SetAsicWcid.SetTid, - SetAsicWcid.DeleteTid)); - MACValue = - (pAd->MacTab. - Content[SetAsicWcid.WCID]. - Addr[3] << 24) + - (pAd->MacTab. - Content[SetAsicWcid.WCID]. - Addr[2] << 16) + - (pAd->MacTab. - Content[SetAsicWcid.WCID]. - Addr[1] << 8) + - (pAd->MacTab. - Content[SetAsicWcid.WCID].Addr[0]); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("1-MACValue= %x,\n", - MACValue)); - RTUSBWriteMACRegister(pAd, offset, - MACValue); - /* Read bitmask */ - RTUSBReadMACRegister(pAd, offset + 4, - &MACRValue); - if (SetAsicWcid.DeleteTid != 0xffffffff) - MACRValue &= - (~SetAsicWcid.DeleteTid); - if (SetAsicWcid.SetTid != 0xffffffff) - MACRValue |= - (SetAsicWcid.SetTid); - MACRValue &= 0xffff0000; - - MACValue = - (pAd->MacTab. - Content[SetAsicWcid.WCID]. - Addr[5] << 8) + - pAd->MacTab.Content[SetAsicWcid. - WCID].Addr[4]; - MACValue |= MACRValue; - RTUSBWriteMACRegister(pAd, offset + 4, - MACValue); - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("2-MACValue= %x,\n", - MACValue)); - } - break; - - case CMDTHREAD_SET_ASIC_WCID_CIPHER: - { - struct rt_set_asic_wcid_attri SetAsicWcidAttri; - u16 offset; - u32 MACRValue = 0; - SHAREDKEY_MODE_STRUC csr1; - SetAsicWcidAttri = - *((struct rt_set_asic_wcid_attri *) - (pData)); - - if (SetAsicWcidAttri.WCID >= - MAX_LEN_OF_MAC_TABLE) - return; - - offset = - MAC_WCID_ATTRIBUTE_BASE + - ((u8)SetAsicWcidAttri.WCID) * - HW_WCID_ATTRI_SIZE; - - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("Cmd : CMDTHREAD_SET_ASIC_WCID_CIPHER : WCID = %ld, Cipher = %lx.\n", - SetAsicWcidAttri.WCID, - SetAsicWcidAttri.Cipher)); - /* Read bitmask */ - RTUSBReadMACRegister(pAd, offset, - &MACRValue); - MACRValue = 0; - MACRValue |= - (((u8)SetAsicWcidAttri. - Cipher) << 1); - - RTUSBWriteMACRegister(pAd, offset, - MACRValue); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("2-offset = %x , MACValue= %x,\n", - offset, MACRValue)); - - offset = - PAIRWISE_IVEIV_TABLE_BASE + - ((u8)SetAsicWcidAttri.WCID) * - HW_IVEIV_ENTRY_SIZE; - MACRValue = 0; - if ((SetAsicWcidAttri.Cipher <= - CIPHER_WEP128)) - MACRValue |= - (pAd->StaCfg. - DefaultKeyId << 30); - else - MACRValue |= (0x20000000); - RTUSBWriteMACRegister(pAd, offset, - MACRValue); - DBGPRINT_RAW(RT_DEBUG_TRACE, - ("2-offset = %x , MACValue= %x,\n", - offset, MACRValue)); - - /* */ - /* Update cipher algorithm. WSTA always use BSS0 */ - /* */ - /* for adhoc mode only ,because wep status slow than add key, when use zero config */ - if (pAd->StaCfg.BssType == BSS_ADHOC) { - offset = - MAC_WCID_ATTRIBUTE_BASE; - - RTUSBReadMACRegister(pAd, - offset, - &MACRValue); - MACRValue &= (~0xe); - MACRValue |= - (((u8)SetAsicWcidAttri. - Cipher) << 1); - - RTUSBWriteMACRegister(pAd, - offset, - MACRValue); - - /*Update group key cipher,,because wep status slow than add key, when use zero config */ - RTUSBReadMACRegister(pAd, - SHARED_KEY_MODE_BASE - + - 4 * (0 / - 2), - &csr1. - word); - - csr1.field.Bss0Key0CipherAlg = - SetAsicWcidAttri.Cipher; - csr1.field.Bss0Key1CipherAlg = - SetAsicWcidAttri.Cipher; - - RTUSBWriteMACRegister(pAd, - SHARED_KEY_MODE_BASE - + - 4 * (0 / - 2), - csr1. - word); - } - } - break; - -/*Benson modified for USB interface, avoid in interrupt when write key, 20080724 --> */ - case RT_CMD_SET_KEY_TABLE: /*General call for AsicAddPairwiseKeyEntry() */ - { - struct rt_add_pairwise_key_entry KeyInfo; - KeyInfo = - *((struct rt_add_pairwise_key_entry *) - (pData)); - AsicAddPairwiseKeyEntry(pAd, - KeyInfo.MacAddr, - (u8)KeyInfo. - MacTabMatchWCID, - &KeyInfo. - CipherKey); - } - break; - - case RT_CMD_SET_RX_WCID_TABLE: /*General call for RTMPAddWcidAttributeEntry() */ - { - struct rt_mac_table_entry *pEntry; - u8 KeyIdx = 0; - u8 CipherAlg = CIPHER_NONE; - u8 ApIdx = BSS0; - - pEntry = (struct rt_mac_table_entry *)(pData); - - RTMPAddWcidAttributeEntry(pAd, - ApIdx, - KeyIdx, - CipherAlg, - pEntry); - } - break; -/*Benson modified for USB interface, avoid in interrupt when write key, 20080724 <-- */ - - case CMDTHREAD_SET_CLIENT_MAC_ENTRY: - { - struct rt_mac_table_entry *pEntry; - pEntry = (struct rt_mac_table_entry *)pData; - - { - AsicRemovePairwiseKeyEntry(pAd, - pEntry-> - apidx, - (u8) - pEntry-> - Aid); - if ((pEntry->AuthMode <= - Ndis802_11AuthModeAutoSwitch) - && (pEntry->WepStatus == - Ndis802_11Encryption1Enabled)) - { - u32 uIV = 1; - u8 *ptr; - - ptr = (u8 *)& uIV; - *(ptr + 3) = - (pAd->StaCfg. - DefaultKeyId << 6); - AsicUpdateWCIDIVEIV(pAd, - pEntry-> - Aid, - uIV, - 0); - AsicUpdateWCIDAttribute - (pAd, pEntry->Aid, - BSS0, - pAd-> - SharedKey[BSS0] - [pAd->StaCfg. - DefaultKeyId]. - CipherAlg, FALSE); - } else if (pEntry->AuthMode == - Ndis802_11AuthModeWPANone) - { - u32 uIV = 1; - u8 *ptr; - - ptr = (u8 *)& uIV; - *(ptr + 3) = - (pAd->StaCfg. - DefaultKeyId << 6); - AsicUpdateWCIDIVEIV(pAd, - pEntry-> - Aid, - uIV, - 0); - AsicUpdateWCIDAttribute - (pAd, pEntry->Aid, - BSS0, - pAd-> - SharedKey[BSS0] - [pAd->StaCfg. - DefaultKeyId]. - CipherAlg, FALSE); - } else { - /* */ - /* Other case, disable engine. */ - /* Don't worry WPA key, we will add WPA Key after 4-Way handshaking. */ - /* */ - u16 offset; - offset = - MAC_WCID_ATTRIBUTE_BASE - + - (pEntry->Aid * - HW_WCID_ATTRI_SIZE); - /* RX_PKEY_MODE:0 for no security; RX_KEY_TAB:0 for shared key table; BSS_IDX:0 */ - RTUSBWriteMACRegister - (pAd, offset, 0); - } - } - - AsicUpdateRxWCIDTable(pAd, pEntry->Aid, - pEntry->Addr); - DBGPRINT(RT_DEBUG_TRACE, - ("UpdateRxWCIDTable(): Aid=%d, " - "Addr=%pM!\n", - pEntry->Aid, - pEntry->Addr)); - } - break; - -/* add by johnli, fix "in_interrupt" error when call "MacTableDeleteEntry" in Rx tasklet */ - case CMDTHREAD_UPDATE_PROTECT: - { - AsicUpdateProtect(pAd, 0, - (ALLN_SETPROTECT), - TRUE, 0); - } - break; -/* end johnli */ - - case OID_802_11_ADD_WEP: - { - u32 i; - u32 KeyIdx; - struct rt_ndis_802_11_wep *pWepKey; - - DBGPRINT(RT_DEBUG_TRACE, - ("CmdThread::OID_802_11_ADD_WEP \n")); - - pWepKey = (struct rt_ndis_802_11_wep *)pData; - KeyIdx = pWepKey->KeyIndex & 0x0fffffff; - - /* it is a shared key */ - if ((KeyIdx >= 4) - || ((pWepKey->KeyLength != 5) - && (pWepKey->KeyLength != - 13))) { - NdisStatus = - NDIS_STATUS_INVALID_DATA; - DBGPRINT(RT_DEBUG_ERROR, - ("CmdThread::OID_802_11_ADD_WEP, INVALID_DATA!!\n")); - } else { - u8 CipherAlg; - pAd->SharedKey[BSS0][KeyIdx]. - KeyLen = - (u8)pWepKey->KeyLength; - NdisMoveMemory(pAd-> - SharedKey[BSS0] - [KeyIdx].Key, - &pWepKey-> - KeyMaterial, - pWepKey-> - KeyLength); - CipherAlg = - (pAd-> - SharedKey[BSS0][KeyIdx]. - KeyLen == - 5) ? CIPHER_WEP64 : - CIPHER_WEP128; - - /* */ - /* Change the WEP cipher to CKIP cipher if CKIP KP on. */ - /* Funk UI or Meetinghouse UI will add ckip key from this path. */ - /* */ - - if (pAd->OpMode == OPMODE_STA) { - pAd->MacTab. - Content[BSSID_WCID]. - PairwiseKey. - CipherAlg = - pAd-> - SharedKey[BSS0] - [KeyIdx].CipherAlg; - pAd->MacTab. - Content[BSSID_WCID]. - PairwiseKey.KeyLen = - pAd-> - SharedKey[BSS0] - [KeyIdx].KeyLen; - } - pAd->SharedKey[BSS0][KeyIdx]. - CipherAlg = CipherAlg; - if (pWepKey-> - KeyIndex & 0x80000000) { - /* Default key for tx (shared key) */ - u8 IVEIV[8]; - u32 WCIDAttri, Value; - u16 offset, offset2; - NdisZeroMemory(IVEIV, - 8); - pAd->StaCfg. - DefaultKeyId = - (u8)KeyIdx; - /* Add BSSID to WCTable. because this is Tx wep key. */ - /* WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:1=PAIRWISE KEY, BSSIdx is 0 */ - WCIDAttri = - (CipherAlg << 1) | - SHAREDKEYTABLE; - - offset = - MAC_WCID_ATTRIBUTE_BASE - + - (BSSID_WCID * - HW_WCID_ATTRI_SIZE); - RTUSBWriteMACRegister - (pAd, offset, - WCIDAttri); - /* 1. IV/EIV */ - /* Specify key index to find shared key. */ - IVEIV[3] = (u8)(KeyIdx << 6); /*WEP Eiv bit off. groupkey index is not 0 */ - offset = - PAIRWISE_IVEIV_TABLE_BASE - + - (BSS0Mcast_WCID * - HW_IVEIV_ENTRY_SIZE); - offset2 = - PAIRWISE_IVEIV_TABLE_BASE - + - (BSSID_WCID * - HW_IVEIV_ENTRY_SIZE); - for (i = 0; i < 8;) { - Value = - IVEIV[i]; - Value += - (IVEIV - [i + - 1] << 8); - Value += - (IVEIV - [i + - 2] << 16); - Value += - (IVEIV - [i + - 3] << 24); - RTUSBWriteMACRegister - (pAd, - offset + i, - Value); - RTUSBWriteMACRegister - (pAd, - offset2 + - i, Value); - i += 4; - } - - /* 2. WCID Attribute UDF:3, BSSIdx:3, Alg:3, Keytable:use share key, BSSIdx is 0 */ - WCIDAttri = - (pAd-> - SharedKey[BSS0] - [KeyIdx]. - CipherAlg << 1) | - SHAREDKEYTABLE; - offset = - MAC_WCID_ATTRIBUTE_BASE - + - (BSS0Mcast_WCID * - HW_WCID_ATTRI_SIZE); - DBGPRINT(RT_DEBUG_TRACE, - ("BSS0Mcast_WCID : offset = %x, WCIDAttri = %x\n", - offset, - WCIDAttri)); - RTUSBWriteMACRegister - (pAd, offset, - WCIDAttri); - - } - AsicAddSharedKeyEntry(pAd, BSS0, - (u8) - KeyIdx, - CipherAlg, - pWepKey-> - KeyMaterial, - NULL, - NULL); - DBGPRINT(RT_DEBUG_TRACE, - ("CmdThread::OID_802_11_ADD_WEP (KeyIdx=%d, Len=%d-byte)\n", - KeyIdx, - pWepKey->KeyLength)); - } - } - break; - - case CMDTHREAD_802_11_COUNTER_MEASURE: - break; - - case CMDTHREAD_SET_GROUP_KEY: - WpaStaGroupKeySetting(pAd); - break; - - case CMDTHREAD_SET_PAIRWISE_KEY: - WpaStaPairwiseKeySetting(pAd); - break; - - case CMDTHREAD_SET_PSM_BIT: - { - u16 *pPsm = (u16 *) pData; - MlmeSetPsmBit(pAd, *pPsm); - } - break; - case CMDTHREAD_FORCE_WAKE_UP: - AsicForceWakeup(pAd, TRUE); - break; - - default: - DBGPRINT(RT_DEBUG_ERROR, - ("--> Control Thread !! ERROR !! Unknown(cmdqelmt->command=0x%x) !! \n", - cmdqelmt->command)); - break; - } - } - - if (cmdqelmt->CmdFromNdis == TRUE) { - if (cmdqelmt->buffer != NULL) - os_free_mem(pAd, cmdqelmt->buffer); - os_free_mem(pAd, cmdqelmt); - } else { - if ((cmdqelmt->buffer != NULL) - && (cmdqelmt->bufferlength != 0)) - os_free_mem(pAd, cmdqelmt->buffer); - os_free_mem(pAd, cmdqelmt); - } - } /* end of while */ -} - -#endif /* RTMP_MAC_USB // */ diff --git a/trunk/drivers/staging/rt2870/common/spectrum.c b/trunk/drivers/staging/rt2870/common/spectrum.c deleted file mode 100644 index 1cf2c263f452..000000000000 --- a/trunk/drivers/staging/rt2870/common/spectrum.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/common/spectrum.c" diff --git a/trunk/drivers/staging/rt2870/dfs.h b/trunk/drivers/staging/rt2870/dfs.h deleted file mode 100644 index 1fdbd7bc5de5..000000000000 --- a/trunk/drivers/staging/rt2870/dfs.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/dfs.h" diff --git a/trunk/drivers/staging/rt2870/md5.h b/trunk/drivers/staging/rt2870/md5.h deleted file mode 100644 index d60cd05b54f7..000000000000 --- a/trunk/drivers/staging/rt2870/md5.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/md5.h" diff --git a/trunk/drivers/staging/rt2870/mlme.h b/trunk/drivers/staging/rt2870/mlme.h deleted file mode 100644 index 58753ac441de..000000000000 --- a/trunk/drivers/staging/rt2870/mlme.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/mlme.h" diff --git a/trunk/drivers/staging/rt2870/oid.h b/trunk/drivers/staging/rt2870/oid.h deleted file mode 100644 index 1223d81bfc62..000000000000 --- a/trunk/drivers/staging/rt2870/oid.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/oid.h" diff --git a/trunk/drivers/staging/rt2870/rt28xx.h b/trunk/drivers/staging/rt2870/rt28xx.h deleted file mode 100644 index 29bad957de48..000000000000 --- a/trunk/drivers/staging/rt2870/rt28xx.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rt28xx.h" diff --git a/trunk/drivers/staging/rt2870/rt_config.h b/trunk/drivers/staging/rt2870/rt_config.h deleted file mode 100644 index 1f6d6ed5630c..000000000000 --- a/trunk/drivers/staging/rt2870/rt_config.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rt_config.h" diff --git a/trunk/drivers/staging/rt2870/rt_linux.c b/trunk/drivers/staging/rt2870/rt_linux.c deleted file mode 100644 index 88c697bf90eb..000000000000 --- a/trunk/drivers/staging/rt2870/rt_linux.c +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rt_linux.c" diff --git a/trunk/drivers/staging/rt2870/rt_linux.h b/trunk/drivers/staging/rt2870/rt_linux.h deleted file mode 100644 index b2aeafbd5189..000000000000 --- a/trunk/drivers/staging/rt2870/rt_linux.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rt_linux.h" diff --git a/trunk/drivers/staging/rt2870/rt_main_dev.c b/trunk/drivers/staging/rt2870/rt_main_dev.c deleted file mode 100644 index 121e1636017a..000000000000 --- a/trunk/drivers/staging/rt2870/rt_main_dev.c +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rt_main_dev.c" diff --git a/trunk/drivers/staging/rt2870/rt_profile.c b/trunk/drivers/staging/rt2870/rt_profile.c deleted file mode 100644 index 15988c5d9df7..000000000000 --- a/trunk/drivers/staging/rt2870/rt_profile.c +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rt_profile.c" diff --git a/trunk/drivers/staging/rt2870/rt_usb.c b/trunk/drivers/staging/rt2870/rt_usb.c deleted file mode 100644 index 5e02d4c88d73..000000000000 --- a/trunk/drivers/staging/rt2870/rt_usb.c +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rt_usb.c" diff --git a/trunk/drivers/staging/rt2870/rtmp.h b/trunk/drivers/staging/rt2870/rtmp.h deleted file mode 100644 index e5ef89f8bef1..000000000000 --- a/trunk/drivers/staging/rt2870/rtmp.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rtmp.h" diff --git a/trunk/drivers/staging/rt2870/rtmp_ckipmic.h b/trunk/drivers/staging/rt2870/rtmp_ckipmic.h deleted file mode 100644 index 0e7f1dfd4547..000000000000 --- a/trunk/drivers/staging/rt2870/rtmp_ckipmic.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rtmp_ckipmic.h" diff --git a/trunk/drivers/staging/rt2870/rtmp_def.h b/trunk/drivers/staging/rt2870/rtmp_def.h deleted file mode 100644 index 839d791b4f62..000000000000 --- a/trunk/drivers/staging/rt2870/rtmp_def.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rtmp_def.h" diff --git a/trunk/drivers/staging/rt2870/rtmp_type.h b/trunk/drivers/staging/rt2870/rtmp_type.h deleted file mode 100644 index fbf97d0fa5d3..000000000000 --- a/trunk/drivers/staging/rt2870/rtmp_type.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/rtmp_type.h" diff --git a/trunk/drivers/staging/rt2870/spectrum.h b/trunk/drivers/staging/rt2870/spectrum.h deleted file mode 100644 index 8aa23a1833b1..000000000000 --- a/trunk/drivers/staging/rt2870/spectrum.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/spectrum.h" diff --git a/trunk/drivers/staging/rt2870/spectrum_def.h b/trunk/drivers/staging/rt2870/spectrum_def.h deleted file mode 100644 index a65f551e3918..000000000000 --- a/trunk/drivers/staging/rt2870/spectrum_def.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/spectrum_def.h" diff --git a/trunk/drivers/staging/rt2870/sta/aironet.c b/trunk/drivers/staging/rt2870/sta/aironet.c deleted file mode 100644 index 72b7f2e6bf7f..000000000000 --- a/trunk/drivers/staging/rt2870/sta/aironet.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/sta/aironet.c" diff --git a/trunk/drivers/staging/rt2870/sta/assoc.c b/trunk/drivers/staging/rt2870/sta/assoc.c deleted file mode 100644 index 46564d7a01a9..000000000000 --- a/trunk/drivers/staging/rt2870/sta/assoc.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/sta/assoc.c" diff --git a/trunk/drivers/staging/rt2870/sta/auth.c b/trunk/drivers/staging/rt2870/sta/auth.c deleted file mode 100644 index 57632f9ec784..000000000000 --- a/trunk/drivers/staging/rt2870/sta/auth.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/sta/auth.c" diff --git a/trunk/drivers/staging/rt2870/sta/auth_rsp.c b/trunk/drivers/staging/rt2870/sta/auth_rsp.c deleted file mode 100644 index 783e266d3e8f..000000000000 --- a/trunk/drivers/staging/rt2870/sta/auth_rsp.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/sta/auth_rsp.c" diff --git a/trunk/drivers/staging/rt2870/sta/connect.c b/trunk/drivers/staging/rt2870/sta/connect.c deleted file mode 100644 index f6c7bbf542dc..000000000000 --- a/trunk/drivers/staging/rt2870/sta/connect.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/sta/connect.c" diff --git a/trunk/drivers/staging/rt2870/sta/rtmp_data.c b/trunk/drivers/staging/rt2870/sta/rtmp_data.c deleted file mode 100644 index b67e06952bcf..000000000000 --- a/trunk/drivers/staging/rt2870/sta/rtmp_data.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/sta/rtmp_data.c" diff --git a/trunk/drivers/staging/rt2870/sta/sanity.c b/trunk/drivers/staging/rt2870/sta/sanity.c deleted file mode 100644 index f1f2333bb993..000000000000 --- a/trunk/drivers/staging/rt2870/sta/sanity.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/sta/sanity.c" diff --git a/trunk/drivers/staging/rt2870/sta/sync.c b/trunk/drivers/staging/rt2870/sta/sync.c deleted file mode 100644 index 66c8772ad346..000000000000 --- a/trunk/drivers/staging/rt2870/sta/sync.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/sta/sync.c" diff --git a/trunk/drivers/staging/rt2870/sta/wpa.c b/trunk/drivers/staging/rt2870/sta/wpa.c deleted file mode 100644 index 57a2eb2d0896..000000000000 --- a/trunk/drivers/staging/rt2870/sta/wpa.c +++ /dev/null @@ -1 +0,0 @@ -#include "../../rt2860/sta/wpa.c" diff --git a/trunk/drivers/staging/rt2870/sta_ioctl.c b/trunk/drivers/staging/rt2870/sta_ioctl.c deleted file mode 100644 index 3553a6c898b9..000000000000 --- a/trunk/drivers/staging/rt2870/sta_ioctl.c +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/sta_ioctl.c" diff --git a/trunk/drivers/staging/rt2870/usb_main_dev.c b/trunk/drivers/staging/rt2870/usb_main_dev.c deleted file mode 100644 index 6e63bc50047a..000000000000 --- a/trunk/drivers/staging/rt2870/usb_main_dev.c +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/usb_main_dev.c" diff --git a/trunk/drivers/staging/rt2870/wpa.h b/trunk/drivers/staging/rt2870/wpa.h deleted file mode 100644 index 712507224146..000000000000 --- a/trunk/drivers/staging/rt2870/wpa.h +++ /dev/null @@ -1 +0,0 @@ -#include "../rt2860/wpa.h" diff --git a/trunk/drivers/staging/rtl8712/ieee80211.h b/trunk/drivers/staging/rtl8712/ieee80211.h index 1f4d147c4b68..432cf8a7605f 100644 --- a/trunk/drivers/staging/rtl8712/ieee80211.h +++ b/trunk/drivers/staging/rtl8712/ieee80211.h @@ -76,7 +76,7 @@ struct ieee_param { u8 reserved[32]; u8 data[0]; } wpa_ie; - struct { + struct{ int command; int reason_code; } mlme; @@ -149,11 +149,11 @@ struct ieee80211_hdr_qos { struct ieee80211_hdr_3addr_qos { u16 frame_ctl; u16 duration_id; - u8 addr1[ETH_ALEN]; - u8 addr2[ETH_ALEN]; - u8 addr3[ETH_ALEN]; + u8 addr1[ETH_ALEN]; + u8 addr2[ETH_ALEN]; + u8 addr3[ETH_ALEN]; u16 seq_ctl; - u16 qc; + u16 qc; } __attribute__ ((packed)); struct eapol { @@ -461,7 +461,7 @@ struct ieee80211_stats { uint rx_message_in_bad_msg_fragments; }; -struct ieee80211_softmac_stats { +struct ieee80211_softmac_stats{ uint rx_ass_ok; uint rx_ass_err; uint rx_probe_rq; @@ -754,17 +754,15 @@ struct registry_priv; u8 *r8712_set_ie(u8 *pbuf, sint index, uint len, u8 *source, uint *frlen); u8 *r8712_get_ie(u8*pbuf, sint index, sint *len, sint limit); unsigned char *r8712_get_wpa_ie(unsigned char *pie, int *rsn_ie_len, int limit); -unsigned char *r8712_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, - int limit); +unsigned char *r8712_get_wpa2_ie(unsigned char *pie, int *rsn_ie_len, int limit); int r8712_parse_wpa_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, - int *pairwise_cipher); + int *pairwise_cipher); int r8712_parse_wpa2_ie(u8 *wpa_ie, int wpa_ie_len, int *group_cipher, - int *pairwise_cipher); -int r8712_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, - u8 *wpa_ie, u16 *wpa_len); + int *pairwise_cipher); +int r8712_get_sec_ie(u8 *in_ie, uint in_len, u8 *rsn_ie, u16 *rsn_len, u8 *wpa_ie, + u16 *wpa_len); int r8712_get_wps_ie(u8 *in_ie, uint in_len, u8 *wps_ie, uint *wps_ielen); -int r8712_generate_ie(struct registry_priv *pregistrypriv, - struct _adapter *padapter); +int r8712_generate_ie(struct registry_priv *pregistrypriv, struct _adapter *padapter); uint r8712_is_cckrates_included(u8 *rate); uint r8712_is_cckratesonly_included(u8 *rate); diff --git a/trunk/drivers/staging/rtl8712/if_ether.h b/trunk/drivers/staging/rtl8712/if_ether.h index 0e9753b9ed37..36a2ba5c86f1 100644 --- a/trunk/drivers/staging/rtl8712/if_ether.h +++ b/trunk/drivers/staging/rtl8712/if_ether.h @@ -99,8 +99,8 @@ struct ethhdr { }; struct _vlan { - unsigned short h_vlan_TCI; /* Encapsulates priority and VLAN ID*/ - unsigned short h_vlan_encapsulated_proto; + unsigned short h_vlan_TCI; /* Encapsulates priority and VLAN ID*/ + unsigned short h_vlan_encapsulated_proto; }; diff --git a/trunk/drivers/staging/rtl8712/ip.h b/trunk/drivers/staging/rtl8712/ip.h index f37b0f8d14d4..4785a591486c 100644 --- a/trunk/drivers/staging/rtl8712/ip.h +++ b/trunk/drivers/staging/rtl8712/ip.h @@ -90,23 +90,23 @@ #define IPOPT_TS_PRESPEC 3 /* specified modules only */ struct ip_options { - __u32 faddr; /* Saved first hop address */ - unsigned char optlen; - unsigned char srr; - unsigned char rr; - unsigned char ts; - unsigned char is_setbyuser:1, /* Set by setsockopt? */ - is_data:1, /* Options in __data, rather than skb */ - is_strictroute:1, /* Strict source route */ - srr_is_hit:1, /* Packet destination addr was our one*/ - is_changed:1, /* IP checksum more not valid */ - rr_needaddr:1, /* Need to record addr of outgoing dev*/ - ts_needtime:1, /* Need to record timestamp */ - ts_needaddr:1; /* Need to record addr of outgoing dev*/ - unsigned char router_alert; - unsigned char __pad1; - unsigned char __pad2; - unsigned char __data[0]; + __u32 faddr; /* Saved first hop address */ + unsigned char optlen; + unsigned char srr; + unsigned char rr; + unsigned char ts; + unsigned char is_setbyuser:1, /* Set by setsockopt? */ + is_data:1, /* Options in __data, rather than skb */ + is_strictroute:1, /* Strict source route */ + srr_is_hit:1, /* Packet destination addr was our one */ + is_changed:1, /* IP checksum more not valid */ + rr_needaddr:1, /* Need to record addr of outgoing dev */ + ts_needtime:1, /* Need to record timestamp */ + ts_needaddr:1; /* Need to record addr of outgoing dev */ + unsigned char router_alert; + unsigned char __pad1; + unsigned char __pad2; + unsigned char __data[0]; }; #define optlength(opt) (sizeof(struct ip_options) + opt->optlen) diff --git a/trunk/drivers/staging/rtl8712/mlme_osdep.h b/trunk/drivers/staging/rtl8712/mlme_osdep.h index 968e78765a3b..7013a4980802 100644 --- a/trunk/drivers/staging/rtl8712/mlme_osdep.h +++ b/trunk/drivers/staging/rtl8712/mlme_osdep.h @@ -9,8 +9,8 @@ void r8712_os_indicate_disconnect(struct _adapter *adapter); void r8712_os_indicate_connect(struct _adapter *adapter); void r8712_report_sec_ie(struct _adapter *adapter, u8 authmode, u8 *sec_ie); int r8712_recv_indicatepkts_in_order(struct _adapter *adapter, - struct recv_reorder_ctrl *precvreorder_ctrl, - int bforced); + struct recv_reorder_ctrl *precvreorder_ctrl, + int bforced); void r8712_indicate_wx_assoc_event(struct _adapter *padapter); void r8712_indicate_wx_disassoc_event(struct _adapter *padapter); diff --git a/trunk/drivers/staging/rtl8712/osdep_service.h b/trunk/drivers/staging/rtl8712/osdep_service.h index 3d3f73c5cd5b..36eeb5a1b5a5 100644 --- a/trunk/drivers/staging/rtl8712/osdep_service.h +++ b/trunk/drivers/staging/rtl8712/osdep_service.h @@ -145,8 +145,7 @@ static inline u32 is_list_empty(struct list_head *phead) return false; } -static inline void list_insert_tail(struct list_head *plist, - struct list_head *phead) +static inline void list_insert_tail(struct list_head *plist, struct list_head *phead) { list_add_tail(plist, phead); } diff --git a/trunk/drivers/staging/rtl8712/recv_osdep.h b/trunk/drivers/staging/rtl8712/recv_osdep.h index 60a54dd90ff1..b23dd6b159f4 100644 --- a/trunk/drivers/staging/rtl8712/recv_osdep.h +++ b/trunk/drivers/staging/rtl8712/recv_osdep.h @@ -12,8 +12,7 @@ s32 r8712_recv_entry(union recv_frame *precv_frame); void r8712_recv_indicatepkt(struct _adapter *adapter, union recv_frame *precv_frame); void r8712_handle_tkip_mic_err(struct _adapter *padapter, u8 bgroup); -int r8712_init_recv_priv(struct recv_priv *precvpriv, - struct _adapter *padapter); +int r8712_init_recv_priv(struct recv_priv *precvpriv, struct _adapter *padapter); void r8712_free_recv_priv(struct recv_priv *precvpriv); int r8712_os_recv_resource_alloc(struct _adapter *padapter, union recv_frame *precvframe); @@ -25,3 +24,4 @@ void r8712_os_read_port(struct _adapter *padapter, struct recv_buf *precvbuf); void r8712_init_recv_timer(struct recv_reorder_ctrl *preorder_ctrl); #endif + diff --git a/trunk/drivers/staging/rtl8712/rtl8712_event.h b/trunk/drivers/staging/rtl8712/rtl8712_event.h index 27316934b1a3..48408f72546c 100644 --- a/trunk/drivers/staging/rtl8712/rtl8712_event.h +++ b/trunk/drivers/staging/rtl8712/rtl8712_event.h @@ -5,33 +5,33 @@ void r8712_event_handle(struct _adapter *padapter, uint *peventbuf); void r8712_got_addbareq_event_callback(struct _adapter *adapter , u8 *pbuf); enum rtl8712_c2h_event { - GEN_EVT_CODE(_Read_MACREG) = 0, /*0*/ + GEN_EVT_CODE(_Read_MACREG) = 0, /*0*/ GEN_EVT_CODE(_Read_BBREG), GEN_EVT_CODE(_Read_RFREG), GEN_EVT_CODE(_Read_EEPROM), GEN_EVT_CODE(_Read_EFUSE), - GEN_EVT_CODE(_Read_CAM), /*5*/ + GEN_EVT_CODE(_Read_CAM), /*5*/ GEN_EVT_CODE(_Get_BasicRate), GEN_EVT_CODE(_Get_DataRate), - GEN_EVT_CODE(_Survey), /*8*/ - GEN_EVT_CODE(_SurveyDone), /*9*/ + GEN_EVT_CODE(_Survey), /*8*/ + GEN_EVT_CODE(_SurveyDone), /*9*/ - GEN_EVT_CODE(_JoinBss), /*10*/ + GEN_EVT_CODE(_JoinBss) , /*10*/ GEN_EVT_CODE(_AddSTA), GEN_EVT_CODE(_DelSTA), - GEN_EVT_CODE(_AtimDone), + GEN_EVT_CODE(_AtimDone) , GEN_EVT_CODE(_TX_Report), - GEN_EVT_CODE(_CCX_Report), /*15*/ + GEN_EVT_CODE(_CCX_Report), /*15*/ GEN_EVT_CODE(_DTM_Report), GEN_EVT_CODE(_TX_Rate_Statistics), GEN_EVT_CODE(_C2HLBK), GEN_EVT_CODE(_FWDBG), - GEN_EVT_CODE(_C2HFEEDBACK), /*20*/ + GEN_EVT_CODE(_C2HFEEDBACK), /*20*/ GEN_EVT_CODE(_ADDBA), GEN_EVT_CODE(_C2HBCN), GEN_EVT_CODE(_ReportPwrState), /*filen: only for PCIE, USB*/ GEN_EVT_CODE(_WPS_PBC), /*24*/ - GEN_EVT_CODE(_ADDBAReq_Report), /*25*/ + GEN_EVT_CODE(_ADDBAReq_Report), /*25*/ MAX_C2HEVT }; @@ -48,8 +48,7 @@ static struct fwevent wlanevents[] = { {0, NULL}, {0, NULL}, {0, &r8712_survey_event_callback}, /*8*/ - {sizeof(struct surveydone_event), - &r8712_surveydone_event_callback}, /*9*/ + {sizeof(struct surveydone_event), &r8712_surveydone_event_callback},/*9*/ {0, &r8712_joinbss_event_callback}, /*10*/ {sizeof(struct stassoc_event), &r8712_stassoc_event_callback}, @@ -60,8 +59,8 @@ static struct fwevent wlanevents[] = { {0, NULL}, {0, NULL}, {0, NULL}, - {0, NULL}, /*fwdbg_event_callback},*/ - {0, NULL}, /*20*/ + {0, NULL}, /*fwdbg_event_callback},*/ + {0, NULL}, /*20*/ {0, NULL}, {0, NULL}, {0, &r8712_cpwm_event_callback}, diff --git a/trunk/drivers/staging/rtl8712/rtl8712_hal.h b/trunk/drivers/staging/rtl8712/rtl8712_hal.h index 66baa87cd4b0..13df2001e9ad 100644 --- a/trunk/drivers/staging/rtl8712/rtl8712_hal.h +++ b/trunk/drivers/staging/rtl8712/rtl8712_hal.h @@ -21,13 +21,13 @@ enum RTL871X_HCI_TYPE { RTL8712_USB, }; -enum RTL8712_RF_CONFIG { +enum RTL8712_RF_CONFIG{ RTL8712_RF_1T1R, RTL8712_RF_1T2R, RTL8712_RF_2T2R }; -enum _RTL8712_HCI_TYPE_ { +enum _RTL8712_HCI_TYPE_{ RTL8712_HCI_TYPE_PCIE = 0x01, RTL8712_HCI_TYPE_AP_PCIE = 0x81, RTL8712_HCI_TYPE_USB = 0x02, @@ -40,62 +40,62 @@ enum _RTL8712_HCI_TYPE_ { struct fw_priv { /*8-bytes alignment required*/ /*--- long word 0 ----*/ - unsigned char signature_0; /*0x12: CE product, 0x92: IT product*/ - unsigned char signature_1; /*0x87: CE product, 0x81: IT product*/ - unsigned char hci_sel; /*0x81: PCI-AP, 01:PCIe, 02: 92S-U, 0x82: USB-AP, + unsigned char signature_0; /*0x12: CE product, 0x92: IT product*/ + unsigned char signature_1; /*0x87: CE product, 0x81: IT product*/ + unsigned char hci_sel; /*0x81: PCI-AP, 01:PCIe, 02: 92S-U, 0x82: USB-AP, * 0x12: 72S-U, 03:SDIO*/ - unsigned char chip_version; /*the same value as register value*/ - unsigned char customer_ID_0; /*customer ID low byte*/ - unsigned char customer_ID_1; /*customer ID high byte*/ - unsigned char rf_config; /*0x11: 1T1R, 0x12: 1T2R, 0x92: 1T2R turbo, + unsigned char chip_version; /*the same value as register value*/ + unsigned char customer_ID_0; /*customer ID low byte*/ + unsigned char customer_ID_1; /*customer ID high byte*/ + unsigned char rf_config; /*0x11: 1T1R, 0x12: 1T2R, 0x92: 1T2R turbo, * 0x22: 2T2R*/ - unsigned char usb_ep_num; /* 4: 4EP, 6: 6EP, 11: 11EP*/ + unsigned char usb_ep_num; /* 4: 4EP, 6: 6EP, 11: 11EP*/ /*--- long word 1 ----*/ - unsigned char regulatory_class_0; /*regulatory class bit map 0*/ - unsigned char regulatory_class_1; /*regulatory class bit map 1*/ - unsigned char regulatory_class_2; /*regulatory class bit map 2*/ - unsigned char regulatory_class_3; /*regulatory class bit map 3*/ - unsigned char rfintfs; /* 0:SWSI, 1:HWSI, 2:HWPI*/ - unsigned char def_nettype; - unsigned char turboMode; - unsigned char lowPowerMode;/* 0: noral mode, 1: low power mode*/ + unsigned char regulatory_class_0; /*regulatory class bit map 0*/ + unsigned char regulatory_class_1; /*regulatory class bit map 1*/ + unsigned char regulatory_class_2; /*regulatory class bit map 2*/ + unsigned char regulatory_class_3; /*regulatory class bit map 3*/ + unsigned char rfintfs; /* 0:SWSI, 1:HWSI, 2:HWPI*/ + unsigned char def_nettype; + unsigned char turboMode; + unsigned char lowPowerMode;/* 0: noral mode, 1: low power mode*/ /*--- long word 2 ----*/ - unsigned char lbk_mode; /*0x00: normal, 0x03: MACLBK, 0x01: PHYLBK*/ - unsigned char mp_mode; /* 1: for MP use, 0: for normal driver */ - unsigned char vcsType; /* 0:off 1:on 2:auto */ - unsigned char vcsMode; /* 1:RTS/CTS 2:CTS to self */ - unsigned char rsvd022; - unsigned char rsvd023; - unsigned char rsvd024; - unsigned char rsvd025; + unsigned char lbk_mode; /*0x00: normal, 0x03: MACLBK, 0x01: PHYLBK*/ + unsigned char mp_mode; /* 1: for MP use, 0: for normal driver */ + unsigned char vcsType; /* 0:off 1:on 2:auto */ + unsigned char vcsMode; /* 1:RTS/CTS 2:CTS to self */ + unsigned char rsvd022; + unsigned char rsvd023; + unsigned char rsvd024; + unsigned char rsvd025; /*--- long word 3 ----*/ - unsigned char qos_en; /*1: QoS enable*/ - unsigned char bw_40MHz_en; /*1: 40MHz BW enable*/ - unsigned char AMSDU2AMPDU_en; /*1: 4181 convert AMSDU to AMPDU, + unsigned char qos_en; /*1: QoS enable*/ + unsigned char bw_40MHz_en; /*1: 40MHz BW enable*/ + unsigned char AMSDU2AMPDU_en; /*1: 4181 convert AMSDU to AMPDU, * 0: disable*/ - unsigned char AMPDU_en; /*1: 11n AMPDU enable*/ - unsigned char rate_control_offload; /*1: FW offloads,0: driver handles*/ - unsigned char aggregation_offload; /*1: FW offloads,0: driver handles*/ - unsigned char rsvd030; - unsigned char rsvd031; + unsigned char AMPDU_en; /*1: 11n AMPDU enable*/ + unsigned char rate_control_offload; /*1: FW offloads, 0: driver handles*/ + unsigned char aggregation_offload; /*1: FW offloads, 0: driver handles*/ + unsigned char rsvd030; + unsigned char rsvd031; /*--- long word 4 ----*/ - unsigned char beacon_offload; /* 1. FW offloads, 0: driver handles*/ - unsigned char MLME_offload; /* 2. FW offloads, 0: driver handles*/ - unsigned char hwpc_offload; /* 3. FW offloads, 0: driver handles*/ - unsigned char tcp_checksum_offload; /*4. FW offloads,0: driver handles*/ - unsigned char tcp_offload; /* 5. FW offloads, 0: driver handles*/ - unsigned char ps_control_offload; /* 6. FW offloads, 0: driver handles*/ - unsigned char WWLAN_offload; /* 7. FW offloads, 0: driver handles*/ - unsigned char rsvd040; + unsigned char beacon_offload; /* 1. FW offloads, 0: driver handles*/ + unsigned char MLME_offload; /* 2. FW offloads, 0: driver handles*/ + unsigned char hwpc_offload; /* 3. FW offloads, 0: driver handles*/ + unsigned char tcp_checksum_offload; /* 4. FW offloads, 0: driver handles*/ + unsigned char tcp_offload; /* 5. FW offloads, 0: driver handles*/ + unsigned char ps_control_offload; /* 6. FW offloads, 0: driver handles*/ + unsigned char WWLAN_offload; /* 7. FW offloads, 0: driver handles*/ + unsigned char rsvd040; /*--- long word 5 ----*/ - unsigned char tcp_tx_frame_len_L; /*tcp tx packet length low byte*/ - unsigned char tcp_tx_frame_len_H; /*tcp tx packet length high byte*/ - unsigned char tcp_rx_frame_len_L; /*tcp rx packet length low byte*/ - unsigned char tcp_rx_frame_len_H; /*tcp rx packet length high byte*/ - unsigned char rsvd050; - unsigned char rsvd051; - unsigned char rsvd052; - unsigned char rsvd053; + unsigned char tcp_tx_frame_len_L; /*tcp tx packet length low byte*/ + unsigned char tcp_tx_frame_len_H; /*tcp tx packet length high byte*/ + unsigned char tcp_rx_frame_len_L; /*tcp rx packet length low byte*/ + unsigned char tcp_rx_frame_len_H; /*tcp rx packet length high byte*/ + unsigned char rsvd050; + unsigned char rsvd051; + unsigned char rsvd052; + unsigned char rsvd053; }; struct fw_hdr {/*8-byte alinment required*/ diff --git a/trunk/drivers/staging/rtl8712/rtl8712_led.c b/trunk/drivers/staging/rtl8712/rtl8712_led.c index cb1751e95f06..5024ee42b04b 100644 --- a/trunk/drivers/staging/rtl8712/rtl8712_led.c +++ b/trunk/drivers/staging/rtl8712/rtl8712_led.c @@ -49,7 +49,7 @@ * LED object. *=========================================================================== */ -enum _LED_STATE_871x { +enum _LED_STATE_871x{ LED_UNKNOWN = 0, LED_ON = 1, LED_OFF = 2, diff --git a/trunk/drivers/staging/rtl8712/rtl8712_recv.h b/trunk/drivers/staging/rtl8712/rtl8712_recv.h index c48757f97da4..4ba52b9c1697 100644 --- a/trunk/drivers/staging/rtl8712/rtl8712_recv.h +++ b/trunk/drivers/staging/rtl8712/rtl8712_recv.h @@ -93,7 +93,7 @@ struct recv_buf { end -----> len = (unsigned int )(tail - data); */ -struct recv_frame_hdr { +struct recv_frame_hdr{ struct list_head list; _pkt *pkt; _pkt *pkt_newalloc; diff --git a/trunk/drivers/staging/rtl8712/rtl8712_xmit.h b/trunk/drivers/staging/rtl8712/rtl8712_xmit.h index 12a080f545ab..5d77c5107242 100644 --- a/trunk/drivers/staging/rtl8712/rtl8712_xmit.h +++ b/trunk/drivers/staging/rtl8712/rtl8712_xmit.h @@ -59,16 +59,25 @@ /*OFFSET 20*/ #define DISFB BIT(15) -struct tx_desc { +struct tx_desc{ + /*DWORD 0*/ unsigned int txdw0; + unsigned int txdw1; + unsigned int txdw2; + unsigned int txdw3; + unsigned int txdw4; + unsigned int txdw5; + unsigned int txdw6; + unsigned int txdw7; + }; diff --git a/trunk/drivers/staging/rtl8712/rtl871x_cmd.c b/trunk/drivers/staging/rtl8712/rtl871x_cmd.c index ba92762dbb1c..fbb2e4eaae51 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_cmd.c +++ b/trunk/drivers/staging/rtl8712/rtl871x_cmd.c @@ -431,7 +431,8 @@ u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork) } psecnetwork = (struct ndis_wlan_bssid_ex *)&psecuritypriv->sec_bss; if (psecnetwork == NULL) { - kfree(pcmd); + if (pcmd != NULL) + kfree((unsigned char *)pcmd); return _FAIL; } memset(psecnetwork, 0, t_len); @@ -477,8 +478,8 @@ u8 r8712_joinbss_cmd(struct _adapter *padapter, struct wlan_network *pnetwork) * to avoid some IOT issues, especially for Realtek 8192u * SoftAP. */ - if ((padapter->securitypriv.PrivacyAlgrthm != _WEP40_) && - (padapter->securitypriv.PrivacyAlgrthm != _WEP104_)) { + if ((padapter->securitypriv.PrivacyAlgrthm != _WEP40_ ) && + (padapter->securitypriv.PrivacyAlgrthm != _WEP104_ )) { /* restructure_ht_ie */ r8712_restructure_ht_ie(padapter, &pnetwork->network.IEs[0], diff --git a/trunk/drivers/staging/rtl8712/rtl871x_cmd.h b/trunk/drivers/staging/rtl8712/rtl871x_cmd.h index dcf256d44d1c..2dc78476b7d3 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_cmd.h +++ b/trunk/drivers/staging/rtl8712/rtl871x_cmd.h @@ -562,54 +562,54 @@ struct getratable_rsp { }; /*to get TX,RX retry count*/ -struct gettxretrycnt_parm { +struct gettxretrycnt_parm{ unsigned int rsvd; }; -struct gettxretrycnt_rsp { +struct gettxretrycnt_rsp{ unsigned long tx_retrycnt; }; -struct getrxretrycnt_parm { +struct getrxretrycnt_parm{ unsigned int rsvd; }; -struct getrxretrycnt_rsp { +struct getrxretrycnt_rsp{ unsigned long rx_retrycnt; }; /*to get BCNOK,BCNERR count*/ -struct getbcnokcnt_parm { +struct getbcnokcnt_parm{ unsigned int rsvd; }; -struct getbcnokcnt_rsp { - unsigned long bcnokcnt; +struct getbcnokcnt_rsp{ + unsigned long bcnokcnt; }; -struct getbcnerrcnt_parm { +struct getbcnerrcnt_parm{ unsigned int rsvd; }; -struct getbcnerrcnt_rsp { +struct getbcnerrcnt_rsp{ unsigned long bcnerrcnt; }; /* to get current TX power level*/ -struct getcurtxpwrlevel_parm { +struct getcurtxpwrlevel_parm{ unsigned int rsvd; }; -struct getcurtxpwrlevel_rsp { +struct getcurtxpwrlevel_rsp{ unsigned short tx_power; }; /*dynamic on/off DIG*/ -struct setdig_parm { +struct setdig_parm{ unsigned char dig_on; /* 1:on , 0:off */ }; /*dynamic on/off RA*/ -struct setra_parm { +struct setra_parm{ unsigned char ra_on; /* 1:on , 0:off */ }; diff --git a/trunk/drivers/staging/rtl8712/rtl871x_event.h b/trunk/drivers/staging/rtl8712/rtl871x_event.h index 6ce06767130d..d45229356bf6 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_event.h +++ b/trunk/drivers/staging/rtl8712/rtl871x_event.h @@ -45,8 +45,8 @@ struct stassoc_event { }; struct stadel_event { - unsigned char macaddr[6]; - unsigned char rsvd[2]; + unsigned char macaddr[6]; + unsigned char rsvd[2]; }; struct addba_event { @@ -61,7 +61,7 @@ struct fwevent { }; #define C2HEVENT_SZ 32 -struct event_node { +struct event_node{ unsigned char *node; unsigned char evt_code; unsigned short evt_sz; @@ -85,9 +85,9 @@ struct network_queue { }; struct ADDBA_Req_Report_parm { - unsigned char MacAddress[ETH_ALEN]; - unsigned short StartSeqNum; - unsigned char tid; + unsigned char MacAddress[ETH_ALEN]; + unsigned short StartSeqNum; + unsigned char tid; }; #include "rtl8712_event.h" diff --git a/trunk/drivers/staging/rtl8712/rtl871x_io.c b/trunk/drivers/staging/rtl8712/rtl871x_io.c index ca84ee02eacc..e6e3c3752a97 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_io.c +++ b/trunk/drivers/staging/rtl8712/rtl871x_io.c @@ -73,7 +73,8 @@ static uint _init_intf_hdl(struct _adapter *padapter, goto _init_intf_hdl_fail; return _SUCCESS; _init_intf_hdl_fail: - kfree(pintf_priv); + if (pintf_priv) + kfree((u8 *)pintf_priv); return _FAIL; } @@ -83,7 +84,8 @@ static void _unload_intf_hdl(struct intf_priv *pintfpriv) unload_intf_priv = &r8712_usb_unload_intf_priv; unload_intf_priv(pintfpriv); - kfree(pintfpriv); + if (pintfpriv) + kfree((u8 *)pintfpriv); } static uint register_intf_hdl(u8 *dev, struct intf_hdl *pintfhdl) diff --git a/trunk/drivers/staging/rtl8712/rtl871x_ioctl_linux.c b/trunk/drivers/staging/rtl8712/rtl871x_ioctl_linux.c index 40e6b5cc412d..bd315c77610a 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_ioctl_linux.c +++ b/trunk/drivers/staging/rtl8712/rtl871x_ioctl_linux.c @@ -291,8 +291,7 @@ static inline char *translate_scan(struct _adapter *padapter, memset(buf, 0, MAX_WPA_IE_LEN); n = sprintf(buf, "wpa_ie="); for (i = 0; i < wpa_len; i++) { - n += snprintf(buf + n, MAX_WPA_IE_LEN - n, - "%02x", wpa_ie[i]); + n += snprintf(buf + n, MAX_WPA_IE_LEN - n, "%02x", wpa_ie[i]); if (n >= MAX_WPA_IE_LEN) break; } @@ -311,8 +310,7 @@ static inline char *translate_scan(struct _adapter *padapter, memset(buf, 0, MAX_WPA_IE_LEN); n = sprintf(buf, "rsn_ie="); for (i = 0; i < rsn_len; i++) { - n += snprintf(buf + n, MAX_WPA_IE_LEN - n, - "%02x", rsn_ie[i]); + n += snprintf(buf + n, MAX_WPA_IE_LEN - n, "%02x", rsn_ie[i]); if (n >= MAX_WPA_IE_LEN) break; } @@ -1734,7 +1732,8 @@ static int r871x_wx_set_enc_ext(struct net_device *dev, memcpy(param + 1, pext + 1, pext->key_len); } ret = wpa_set_encryption(dev, param, param_len); - kfree(param); + if (param) + kfree((u8 *)param); return ret; } diff --git a/trunk/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c b/trunk/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c index 9a33eaee879b..7adbe82cd085 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c +++ b/trunk/drivers/staging/rtl8712/rtl871x_ioctl_rtl.c @@ -493,7 +493,7 @@ uint oid_rt_pro_rf_read_registry_hdl(struct oid_par_priv *poid_par_priv) return status; } -enum _CONNECT_STATE_ { +enum _CONNECT_STATE_{ CHECKINGSTATUS, ASSOCIATED, ADHOCMODE, diff --git a/trunk/drivers/staging/rtl8712/rtl871x_ioctl_set.h b/trunk/drivers/staging/rtl8712/rtl871x_ioctl_set.h index 8dff2b196ff2..283afbfc1d02 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_ioctl_set.h +++ b/trunk/drivers/staging/rtl8712/rtl871x_ioctl_set.h @@ -6,27 +6,19 @@ typedef u8 NDIS_802_11_PMKID_VALUE[16]; struct BSSIDInfo { - unsigned char BSSID[6]; - NDIS_802_11_PMKID_VALUE PMKID; + unsigned char BSSID[6]; + NDIS_802_11_PMKID_VALUE PMKID; }; u8 r8712_set_802_11_authentication_mode(struct _adapter *pdapter, enum NDIS_802_11_AUTHENTICATION_MODE authmode); - u8 r8712_set_802_11_bssid(struct _adapter *padapter, u8 *bssid); - -u8 r8712_set_802_11_add_wep(struct _adapter *padapter, - struct NDIS_802_11_WEP *wep); - +u8 r8712_set_802_11_add_wep(struct _adapter *padapter, struct NDIS_802_11_WEP *wep); u8 r8712_set_802_11_disassociate(struct _adapter *padapter); - u8 r8712_set_802_11_bssid_list_scan(struct _adapter *padapter); - u8 r8712_set_802_11_infrastructure_mode(struct _adapter *padapter, enum NDIS_802_11_NETWORK_INFRASTRUCTURE networktype); - -void r8712_set_802_11_ssid(struct _adapter *padapter, - struct ndis_802_11_ssid *ssid); +void r8712_set_802_11_ssid(struct _adapter *padapter, struct ndis_802_11_ssid *ssid); #endif diff --git a/trunk/drivers/staging/rtl8712/rtl871x_mp.c b/trunk/drivers/staging/rtl8712/rtl871x_mp.c index 41e00a2c862d..427467cb10bd 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_mp.c +++ b/trunk/drivers/staging/rtl8712/rtl871x_mp.c @@ -217,10 +217,7 @@ static u32 get_bb_reg(struct _adapter *pAdapter, u16 offset, u32 bitmask) return new_value; } -static u8 set_bb_reg(struct _adapter *pAdapter, - u16 offset, - u32 bitmask, - u32 value) +static u8 set_bb_reg(struct _adapter *pAdapter, u16 offset, u32 bitmask, u32 value) { u32 org_value, bit_shift, new_value; @@ -277,7 +274,8 @@ void r8712_SetChannel(struct _adapter *pAdapter) pparm = (struct SetChannel_parm *)_malloc(sizeof(struct SetChannel_parm)); if (pparm == NULL) { - kfree(pcmd); + if (pcmd != NULL) + kfree((u8 *)pcmd); return; } pparm->curr_ch = pAdapter->mppriv.curr_ch; diff --git a/trunk/drivers/staging/rtl8712/rtl871x_mp_ioctl.h b/trunk/drivers/staging/rtl8712/rtl871x_mp_ioctl.h index 67759c31b1da..fdd2278936d8 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_mp_ioctl.h +++ b/trunk/drivers/staging/rtl8712/rtl871x_mp_ioctl.h @@ -281,23 +281,23 @@ enum MP_MODE { MP_ERR_MODE }; -struct rwreg_param { +struct rwreg_param{ unsigned int offset; unsigned int width; unsigned int value; }; -struct bbreg_param { +struct bbreg_param{ unsigned int offset; unsigned int phymask; unsigned int value; }; -struct txpower_param { +struct txpower_param{ unsigned int pwr_index; }; -struct datarate_param { +struct datarate_param{ unsigned int rate_index; }; @@ -321,7 +321,7 @@ struct mp_ioctl_handler { unsigned int oid; }; -struct mp_ioctl_param { +struct mp_ioctl_param{ unsigned int subcode; unsigned int len; unsigned char data[0]; diff --git a/trunk/drivers/staging/rtl8712/rtl871x_recv.c b/trunk/drivers/staging/rtl8712/rtl871x_recv.c index aec83dd8a01f..a3165e67f857 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_recv.c +++ b/trunk/drivers/staging/rtl8712/rtl871x_recv.c @@ -307,9 +307,9 @@ static sint recv_decache(union recv_frame *precv_frame, u8 bretry, return _SUCCESS; } -static sint sta2sta_data_frame(struct _adapter *adapter, - union recv_frame *precv_frame, - struct sta_info **psta) +static sint sta2sta_data_frame(struct _adapter *adapter, union recv_frame *precv_frame, + struct sta_info **psta +) { u8 *ptr = precv_frame->u.hdr.rx_data; sint ret = _SUCCESS; @@ -373,9 +373,8 @@ static sint sta2sta_data_frame(struct _adapter *adapter, return ret; } -static sint ap2sta_data_frame(struct _adapter *adapter, - union recv_frame *precv_frame, - struct sta_info **psta) +static sint ap2sta_data_frame(struct _adapter *adapter, union recv_frame *precv_frame, + struct sta_info **psta) { u8 *ptr = precv_frame->u.hdr.rx_data; struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; @@ -432,9 +431,8 @@ static sint ap2sta_data_frame(struct _adapter *adapter, return _SUCCESS; } -static sint sta2ap_data_frame(struct _adapter *adapter, - union recv_frame *precv_frame, - struct sta_info **psta) +static sint sta2ap_data_frame(struct _adapter *adapter, union recv_frame *precv_frame, + struct sta_info **psta) { struct rx_pkt_attrib *pattrib = &precv_frame->u.hdr.attrib; struct sta_priv *pstapriv = &adapter->stapriv; diff --git a/trunk/drivers/staging/rtl8712/rtl871x_recv.h b/trunk/drivers/staging/rtl8712/rtl871x_recv.h index cc7a72fee1c2..bf8115dbcb61 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_recv.h +++ b/trunk/drivers/staging/rtl8712/rtl871x_recv.h @@ -19,9 +19,9 @@ /* for Rx reordering buffer control */ struct recv_reorder_ctrl { struct _adapter *padapter; - u16 indicate_seq; /* =wstart_b, init_value=0xffff */ + u16 indicate_seq;/* =wstart_b, init_value=0xffff */ u16 wend_b; - u8 wsize_b; + u8 wsize_b; struct __queue pending_recvframe_queue; struct timer_list reordering_ctrl_timer; }; diff --git a/trunk/drivers/staging/rtl8712/rtl871x_rf.h b/trunk/drivers/staging/rtl8712/rtl871x_rf.h index 6c54966f13f7..c709d8cadf0c 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_rf.h +++ b/trunk/drivers/staging/rtl8712/rtl871x_rf.h @@ -22,7 +22,7 @@ struct regulatory_class { u8 modem; }; -enum _REG_PREAMBLE_MODE { +enum _REG_PREAMBLE_MODE{ PREAMBLE_LONG = 1, PREAMBLE_AUTO = 2, PREAMBLE_SHORT = 3, diff --git a/trunk/drivers/staging/rtl8712/rtl871x_security.h b/trunk/drivers/staging/rtl8712/rtl871x_security.h index bff71d2aae98..782b70a352fb 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_security.h +++ b/trunk/drivers/staging/rtl8712/rtl871x_security.h @@ -21,31 +21,30 @@ #ifndef Ndis802_11AuthModeWPA2PSK #define Ndis802_11AuthModeWPA2PSK (Ndis802_11AuthModeWPANone + 2) #endif - union pn48 { u64 val; #if defined(__BIG_ENDIAN) - struct { - u8 TSC7; - u8 TSC6; - u8 TSC5; - u8 TSC4; - u8 TSC3; - u8 TSC2; - u8 TSC1; - u8 TSC0; - } _byte_; +struct { + u8 TSC7; + u8 TSC6; + u8 TSC5; + u8 TSC4; + u8 TSC3; + u8 TSC2; + u8 TSC1; + u8 TSC0; +} _byte_; #else - struct { - u8 TSC0; - u8 TSC1; - u8 TSC2; - u8 TSC3; - u8 TSC4; - u8 TSC5; - u8 TSC6; - u8 TSC7; - } _byte_; +struct { + u8 TSC0; + u8 TSC1; + u8 TSC2; + u8 TSC3; + u8 TSC4; + u8 TSC5; + u8 TSC6; + u8 TSC7; +} _byte_; #endif }; @@ -175,11 +174,11 @@ struct mic_data { }; void seccalctkipmic( - u8 *key, - u8 *header, - u8 *data, - u32 data_len, - u8 *Miccode, + u8 *key, + u8 *header, + u8 *data, + u32 data_len, + u8 *Miccode, u8 priority); void r8712_secmicsetkey(struct mic_data *pmicdata, u8 * key); diff --git a/trunk/drivers/staging/rtl8712/rtl871x_xmit.c b/trunk/drivers/staging/rtl8712/rtl871x_xmit.c index ccf08911f58b..75f1a6bba2f6 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_xmit.c +++ b/trunk/drivers/staging/rtl8712/rtl871x_xmit.c @@ -996,7 +996,8 @@ static void free_hwxmits(struct _adapter *padapter) { struct xmit_priv *pxmitpriv = &padapter->xmitpriv; - kfree(pxmitpriv->hwxmits); + if (pxmitpriv->hwxmits) + kfree((u8 *)pxmitpriv->hwxmits); } static void init_hwxmits(struct hw_xmit *phwxmit, sint entry) diff --git a/trunk/drivers/staging/rtl8712/rtl871x_xmit.h b/trunk/drivers/staging/rtl8712/rtl871x_xmit.h index df13e67b3eb8..d518ce85585d 100644 --- a/trunk/drivers/staging/rtl8712/rtl871x_xmit.h +++ b/trunk/drivers/staging/rtl8712/rtl871x_xmit.h @@ -244,8 +244,7 @@ sint r8712_update_attrib(struct _adapter *padapter, _pkt *pkt, struct pkt_attrib *pattrib); int r8712_txframes_sta_ac_pending(struct _adapter *padapter, struct pkt_attrib *pattrib); -sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv, - struct _adapter *padapter); +sint _r8712_init_xmit_priv(struct xmit_priv *pxmitpriv, struct _adapter *padapter); void _free_xmit_priv(struct xmit_priv *pxmitpriv); void r8712_free_xmitframe_ex(struct xmit_priv *pxmitpriv, struct xmit_frame *pxmitframe); diff --git a/trunk/drivers/staging/rtl8712/wifi.h b/trunk/drivers/staging/rtl8712/wifi.h index 6032cdc65394..86d4b98e2439 100644 --- a/trunk/drivers/staging/rtl8712/wifi.h +++ b/trunk/drivers/staging/rtl8712/wifi.h @@ -39,35 +39,38 @@ enum WIFI_FRAME_TYPE { }; enum WIFI_FRAME_SUBTYPE { - /* below is for mgt frame */ - WIFI_ASSOCREQ = (0 | WIFI_MGT_TYPE), - WIFI_ASSOCRSP = (BIT(4) | WIFI_MGT_TYPE), - WIFI_REASSOCREQ = (BIT(5) | WIFI_MGT_TYPE), - WIFI_REASSOCRSP = (BIT(5) | BIT(4) | WIFI_MGT_TYPE), - WIFI_PROBEREQ = (BIT(6) | WIFI_MGT_TYPE), - WIFI_PROBERSP = (BIT(6) | BIT(4) | WIFI_MGT_TYPE), - WIFI_BEACON = (BIT(7) | WIFI_MGT_TYPE), - WIFI_ATIM = (BIT(7) | BIT(4) | WIFI_MGT_TYPE), - WIFI_DISASSOC = (BIT(7) | BIT(5) | WIFI_MGT_TYPE), - WIFI_AUTH = (BIT(7) | BIT(5) | BIT(4) | WIFI_MGT_TYPE), - WIFI_DEAUTH = (BIT(7) | BIT(6) | WIFI_MGT_TYPE), - WIFI_ACTION = (BIT(7) | BIT(6) | BIT(4) | WIFI_MGT_TYPE), - /* below is for control frame */ - WIFI_PSPOLL = (BIT(7) | BIT(5) | WIFI_CTRL_TYPE), - WIFI_RTS = (BIT(7) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE), - WIFI_CTS = (BIT(7) | BIT(6) | WIFI_CTRL_TYPE), - WIFI_ACK = (BIT(7) | BIT(6) | BIT(4) | WIFI_CTRL_TYPE), - WIFI_CFEND = (BIT(7) | BIT(6) | BIT(5) | WIFI_CTRL_TYPE), - WIFI_CFEND_CFACK = (BIT(7) | BIT(6) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE), - /* below is for data frame */ - WIFI_DATA = (0 | WIFI_DATA_TYPE), - WIFI_DATA_CFACK = (BIT(4) | WIFI_DATA_TYPE), - WIFI_DATA_CFPOLL = (BIT(5) | WIFI_DATA_TYPE), - WIFI_DATA_CFACKPOLL = (BIT(5) | BIT(4) | WIFI_DATA_TYPE), - WIFI_DATA_NULL = (BIT(6) | WIFI_DATA_TYPE), - WIFI_CF_ACK = (BIT(6) | BIT(4) | WIFI_DATA_TYPE), - WIFI_CF_POLL = (BIT(6) | BIT(5) | WIFI_DATA_TYPE), - WIFI_CF_ACKPOLL = (BIT(6) | BIT(5) | BIT(4) | WIFI_DATA_TYPE), + + /* below is for mgt frame */ + WIFI_ASSOCREQ = (0 | WIFI_MGT_TYPE), + WIFI_ASSOCRSP = (BIT(4) | WIFI_MGT_TYPE), + WIFI_REASSOCREQ = (BIT(5) | WIFI_MGT_TYPE), + WIFI_REASSOCRSP = (BIT(5) | BIT(4) | WIFI_MGT_TYPE), + WIFI_PROBEREQ = (BIT(6) | WIFI_MGT_TYPE), + WIFI_PROBERSP = (BIT(6) | BIT(4) | WIFI_MGT_TYPE), + WIFI_BEACON = (BIT(7) | WIFI_MGT_TYPE), + WIFI_ATIM = (BIT(7) | BIT(4) | WIFI_MGT_TYPE), + WIFI_DISASSOC = (BIT(7) | BIT(5) | WIFI_MGT_TYPE), + WIFI_AUTH = (BIT(7) | BIT(5) | BIT(4) | WIFI_MGT_TYPE), + WIFI_DEAUTH = (BIT(7) | BIT(6) | WIFI_MGT_TYPE), + WIFI_ACTION = (BIT(7) | BIT(6) | BIT(4) | WIFI_MGT_TYPE), + + /* below is for control frame */ + WIFI_PSPOLL = (BIT(7) | BIT(5) | WIFI_CTRL_TYPE), + WIFI_RTS = (BIT(7) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE), + WIFI_CTS = (BIT(7) | BIT(6) | WIFI_CTRL_TYPE), + WIFI_ACK = (BIT(7) | BIT(6) | BIT(4) | WIFI_CTRL_TYPE), + WIFI_CFEND = (BIT(7) | BIT(6) | BIT(5) | WIFI_CTRL_TYPE), + WIFI_CFEND_CFACK = (BIT(7) | BIT(6) | BIT(5) | BIT(4) | WIFI_CTRL_TYPE), + + /* below is for data frame */ + WIFI_DATA = (0 | WIFI_DATA_TYPE), + WIFI_DATA_CFACK = (BIT(4) | WIFI_DATA_TYPE), + WIFI_DATA_CFPOLL = (BIT(5) | WIFI_DATA_TYPE), + WIFI_DATA_CFACKPOLL = (BIT(5) | BIT(4) | WIFI_DATA_TYPE), + WIFI_DATA_NULL = (BIT(6) | WIFI_DATA_TYPE), + WIFI_CF_ACK = (BIT(6) | BIT(4) | WIFI_DATA_TYPE), + WIFI_CF_POLL = (BIT(6) | BIT(5) | WIFI_DATA_TYPE), + WIFI_CF_ACKPOLL = (BIT(6) | BIT(5) | BIT(4) | WIFI_DATA_TYPE), }; enum WIFI_REASON_CODE { @@ -81,6 +84,7 @@ enum WIFI_REASON_CODE { _RSON_CLS3_ = 7, _RSON_DISAOC_STA_LEAVING_ = 8, _RSON_ASOC_NOT_AUTH_ = 9, + /* WPA reason */ _RSON_INVALID_IE_ = 13, _RSON_MIC_FAILURE_ = 14, @@ -93,6 +97,7 @@ enum WIFI_REASON_CODE { _RSON_UNSUPPORT_RSNE_VER_ = 21, _RSON_INVALID_RSNE_CAP_ = 22, _RSON_IEEE_802DOT1X_AUTH_FAIL_ = 23, + /* below are Realtek definitions */ _RSON_PMK_NOT_AVAILABLE_ = 24, }; diff --git a/trunk/drivers/staging/rtl8712/wlan_bssdef.h b/trunk/drivers/staging/rtl8712/wlan_bssdef.h index 0d90e1f5b29a..6d9295270f83 100644 --- a/trunk/drivers/staging/rtl8712/wlan_bssdef.h +++ b/trunk/drivers/staging/rtl8712/wlan_bssdef.h @@ -13,23 +13,23 @@ typedef unsigned char NDIS_802_11_RATES[NDIS_802_11_LENGTH_RATES]; typedef unsigned char NDIS_802_11_RATES_EX[NDIS_802_11_LENGTH_RATES_EX]; struct ndis_802_11_ssid { - u32 SsidLength; - u8 Ssid[32]; + u32 SsidLength; + u8 Ssid[32]; }; enum NDIS_802_11_NETWORK_TYPE { - Ndis802_11FH, - Ndis802_11DS, - Ndis802_11OFDM5, - Ndis802_11OFDM24, - Ndis802_11NetworkTypeMax /* not a real type, defined as an upper bound*/ + Ndis802_11FH, + Ndis802_11DS, + Ndis802_11OFDM5, + Ndis802_11OFDM24, + Ndis802_11NetworkTypeMax /* not a real type, defined as an upper bound */ }; struct NDIS_802_11_CONFIGURATION_FH { - u32 Length; /* Length of structure */ - u32 HopPattern; /* As defined by 802.11, MSB set */ - u32 HopSet; /* to one if non-802.11 */ - u32 DwellTime; /* units are Kusec */ + u32 Length; /* Length of structure */ + u32 HopPattern; /* As defined by 802.11, MSB set */ + u32 HopSet; /* to one if non-802.11 */ + u32 DwellTime; /* units are Kusec */ }; /* @@ -37,25 +37,25 @@ struct NDIS_802_11_CONFIGURATION_FH { ODI Handler will convert the channel number to freq. number. */ struct NDIS_802_11_CONFIGURATION { - u32 Length; /* Length of structure */ - u32 BeaconPeriod; /* units are Kusec */ - u32 ATIMWindow; /* units are Kusec */ - u32 DSConfig; /* Frequency, units are kHz */ - struct NDIS_802_11_CONFIGURATION_FH FHConfig; + u32 Length; /* Length of structure */ + u32 BeaconPeriod; /* units are Kusec */ + u32 ATIMWindow; /* units are Kusec */ + u32 DSConfig; /* Frequency, units are kHz */ + struct NDIS_802_11_CONFIGURATION_FH FHConfig; }; enum NDIS_802_11_NETWORK_INFRASTRUCTURE { - Ndis802_11IBSS, - Ndis802_11Infrastructure, - Ndis802_11AutoUnknown, - Ndis802_11InfrastructureMax, /*Not a real value,defined as upper bound*/ - Ndis802_11APMode + Ndis802_11IBSS, + Ndis802_11Infrastructure, + Ndis802_11AutoUnknown, + Ndis802_11InfrastructureMax, /* Not a real value, defined as upper bound */ + Ndis802_11APMode }; struct NDIS_802_11_FIXED_IEs { - u8 Timestamp[8]; - u16 BeaconInterval; - u16 Capabilities; + u8 Timestamp[8]; + u16 BeaconInterval; + u16 Capabilities; }; /* @@ -70,44 +70,44 @@ struct NDIS_802_11_FIXED_IEs { */ struct ndis_wlan_bssid_ex { - u32 Length; - unsigned char MacAddress[6]; - u8 Reserved[2]; - struct ndis_802_11_ssid Ssid; - u32 Privacy; - s32 Rssi; - enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse; - struct NDIS_802_11_CONFIGURATION Configuration; - enum NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode; - NDIS_802_11_RATES_EX SupportedRates; - u32 IELength; - /*(timestamp, beacon interval, and capability information) */ - u8 IEs[MAX_IE_SZ]; + u32 Length; + unsigned char MacAddress[6]; + u8 Reserved[2]; + struct ndis_802_11_ssid Ssid; + u32 Privacy; + s32 Rssi; + enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse; + struct NDIS_802_11_CONFIGURATION Configuration; + enum NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode; + NDIS_802_11_RATES_EX SupportedRates; + u32 IELength; +/*(timestamp, beacon interval, and capability information) */ + u8 IEs[MAX_IE_SZ]; }; enum NDIS_802_11_AUTHENTICATION_MODE { - Ndis802_11AuthModeOpen, - Ndis802_11AuthModeShared, - Ndis802_11AuthModeAutoSwitch, - Ndis802_11AuthModeWPA, - Ndis802_11AuthModeWPAPSK, - Ndis802_11AuthModeWPANone, - Ndis802_11AuthModeMax /* Not a real mode, defined as upper bound */ + Ndis802_11AuthModeOpen, + Ndis802_11AuthModeShared, + Ndis802_11AuthModeAutoSwitch, + Ndis802_11AuthModeWPA, + Ndis802_11AuthModeWPAPSK, + Ndis802_11AuthModeWPANone, + Ndis802_11AuthModeMax /* Not a real mode, defined as upper bound */ }; enum { - Ndis802_11WEPEnabled, - Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled, - Ndis802_11WEPDisabled, - Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled, - Ndis802_11WEPKeyAbsent, - Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent, - Ndis802_11WEPNotSupported, - Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported, - Ndis802_11Encryption2Enabled, - Ndis802_11Encryption2KeyAbsent, - Ndis802_11Encryption3Enabled, - Ndis802_11Encryption3KeyAbsent + Ndis802_11WEPEnabled, + Ndis802_11Encryption1Enabled = Ndis802_11WEPEnabled, + Ndis802_11WEPDisabled, + Ndis802_11EncryptionDisabled = Ndis802_11WEPDisabled, + Ndis802_11WEPKeyAbsent, + Ndis802_11Encryption1KeyAbsent = Ndis802_11WEPKeyAbsent, + Ndis802_11WEPNotSupported, + Ndis802_11EncryptionNotSupported = Ndis802_11WEPNotSupported, + Ndis802_11Encryption2Enabled, + Ndis802_11Encryption2KeyAbsent, + Ndis802_11Encryption3Enabled, + Ndis802_11Encryption3KeyAbsent }; #define NDIS_802_11_AI_REQFI_CAPABILITIES 1 @@ -119,51 +119,51 @@ enum { #define NDIS_802_11_AI_RESFI_ASSOCIATIONID 4 struct NDIS_802_11_AI_REQFI { - u16 Capabilities; - u16 ListenInterval; - unsigned char CurrentAPAddress[6]; + u16 Capabilities; + u16 ListenInterval; + unsigned char CurrentAPAddress[6]; }; struct NDIS_802_11_AI_RESFI { - u16 Capabilities; - u16 StatusCode; - u16 AssociationId; + u16 Capabilities; + u16 StatusCode; + u16 AssociationId; }; struct NDIS_802_11_ASSOCIATION_INFORMATION { - u32 Length; - u16 AvailableRequestFixedIEs; - struct NDIS_802_11_AI_REQFI RequestFixedIEs; - u32 RequestIELength; - u32 OffsetRequestIEs; - u16 AvailableResponseFixedIEs; - struct NDIS_802_11_AI_RESFI ResponseFixedIEs; - u32 ResponseIELength; - u32 OffsetResponseIEs; + u32 Length; + u16 AvailableRequestFixedIEs; + struct NDIS_802_11_AI_REQFI RequestFixedIEs; + u32 RequestIELength; + u32 OffsetRequestIEs; + u16 AvailableResponseFixedIEs; + struct NDIS_802_11_AI_RESFI ResponseFixedIEs; + u32 ResponseIELength; + u32 OffsetResponseIEs; }; /* Key mapping keys require a BSSID*/ struct NDIS_802_11_KEY { - u32 Length; /* Length of this structure */ - u32 KeyIndex; - u32 KeyLength; /* length of key in bytes */ - unsigned char BSSID[6]; - unsigned long long KeyRSC; - u8 KeyMaterial[32]; /* variable length */ + u32 Length; /* Length of this structure */ + u32 KeyIndex; + u32 KeyLength; /* length of key in bytes */ + unsigned char BSSID[6]; + unsigned long long KeyRSC; + u8 KeyMaterial[32]; /* variable length */ }; struct NDIS_802_11_REMOVE_KEY { - u32 Length; /* Length of this structure */ - u32 KeyIndex; - unsigned char BSSID[6]; + u32 Length; /* Length of this structure */ + u32 KeyIndex; + unsigned char BSSID[6]; }; struct NDIS_802_11_WEP { - u32 Length; /* Length of this structure */ - u32 KeyIndex; /* 0 is the per-client key, - * 1-N are the global keys */ - u32 KeyLength; /* length of key in bytes */ - u8 KeyMaterial[16]; /* variable length depending on above field */ + u32 Length; /* Length of this structure */ + u32 KeyIndex; /* 0 is the per-client key, + * 1-N are the global keys */ + u32 KeyLength; /* length of key in bytes */ + u8 KeyMaterial[16];/* variable length depending on above field */ }; /* mask for authentication/integrity fields */ @@ -192,15 +192,15 @@ struct wlan_network { }; enum VRTL_CARRIER_SENSE { - DISABLE_VCS, - ENABLE_VCS, - AUTO_VCS + DISABLE_VCS, + ENABLE_VCS, + AUTO_VCS }; enum VCS_TYPE { - NONE_VCS, - RTS_CTS, - CTS_TO_SELF + NONE_VCS, + RTS_CTS, + CTS_TO_SELF }; #define PWR_CAM 0 @@ -211,9 +211,9 @@ enum VCS_TYPE { enum UAPSD_MAX_SP { NO_LIMIT, - TWO_MSDU, - FOUR_MSDU, - SIX_MSDU + TWO_MSDU, + FOUR_MSDU, + SIX_MSDU }; #define NUM_PRE_AUTH_KEY 16 @@ -223,18 +223,18 @@ enum UAPSD_MAX_SP { * WPA2 */ struct wlan_bssid_ex { - u32 Length; - unsigned char MacAddress[6]; - u8 Reserved[2]; - struct ndis_802_11_ssid Ssid; - u32 Privacy; - s32 Rssi; - enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse; - struct NDIS_802_11_CONFIGURATION Configuration; - enum NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode; - NDIS_802_11_RATES_EX SupportedRates; - u32 IELength; - u8 IEs[MAX_IE_SZ]; /* (timestamp, beacon interval, and capability + u32 Length; + unsigned char MacAddress[6]; + u8 Reserved[2]; + struct ndis_802_11_ssid Ssid; + u32 Privacy; + s32 Rssi; + enum NDIS_802_11_NETWORK_TYPE NetworkTypeInUse; + struct NDIS_802_11_CONFIGURATION Configuration; + enum NDIS_802_11_NETWORK_INFRASTRUCTURE InfrastructureMode; + NDIS_802_11_RATES_EX SupportedRates; + u32 IELength; + u8 IEs[MAX_IE_SZ]; /* (timestamp, beacon interval, and capability * information) */ }; diff --git a/trunk/drivers/staging/rts_pstor/ms.c b/trunk/drivers/staging/rts_pstor/ms.c index 2fd2932432f5..810e170894f5 100644 --- a/trunk/drivers/staging/rts_pstor/ms.c +++ b/trunk/drivers/staging/rts_pstor/ms.c @@ -863,7 +863,7 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) TRACE_RET(chip, STATUS_FAIL); } - buf = kmalloc(64 * 512, GFP_KERNEL); + buf = (u8 *)rtsx_alloc_dma_buf(chip, 64 * 512, GFP_KERNEL); if (buf == NULL) { TRACE_RET(chip, STATUS_ERROR); } @@ -875,11 +875,11 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) } retval = rtsx_read_register(chip, MS_TRANS_CFG, &val); if (retval != STATUS_SUCCESS) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } if (!(val & MS_INT_BREQ)) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } retval = ms_transfer_data(chip, MS_TM_AUTO_READ, PRO_READ_LONG_DATA, @@ -891,7 +891,7 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) } } if (retval != STATUS_SUCCESS) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -899,7 +899,7 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) do { retval = rtsx_read_register(chip, MS_TRANS_CFG, &val); if (retval != STATUS_SUCCESS) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -908,7 +908,7 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) retval = ms_transfer_tpc(chip, MS_TM_NORMAL_READ, PRO_READ_LONG_DATA, 0, WAIT_INT); if (retval != STATUS_SUCCESS) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -916,18 +916,18 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) } while (i < 1024); if (retval != STATUS_SUCCESS) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } if ((buf[0] != 0xa5) && (buf[1] != 0xc3)) { /* Signature code is wrong */ - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } if ((buf[4] < 1) || (buf[4] > 12)) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -949,15 +949,15 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) RTSX_DEBUGP("sys_info_addr = 0x%x, sys_info_size = 0x%x\n", sys_info_addr, sys_info_size); if (sys_info_size != 96) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } if (sys_info_addr < 0x1A0) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } if ((sys_info_size + sys_info_addr) > 0x8000) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -983,15 +983,15 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) RTSX_DEBUGP("model_name_addr = 0x%x, model_name_size = 0x%x\n", model_name_addr, model_name_size); if (model_name_size != 48) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } if (model_name_addr < 0x1A0) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } if ((model_name_size + model_name_addr) > 0x8000) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -1004,7 +1004,7 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) } if (i == buf[4]) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -1041,7 +1041,7 @@ static int ms_read_attribute_info(struct rtsx_chip *chip) memcpy(ms_card->raw_model_name, buf + model_name_addr, 48); #endif - kfree(buf); + rtsx_free_dma_buf(chip, buf); #ifdef SUPPORT_MSXC if (CHK_MSXC(ms_card)) { @@ -3783,7 +3783,7 @@ int mg_get_local_EKB(struct scsi_cmnd *srb, struct rtsx_chip *chip) TRACE_RET(chip, STATUS_FAIL); } - buf = kmalloc(1540, GFP_KERNEL); + buf = (u8 *)rtsx_alloc_dma_buf(chip, 1540, GFP_KERNEL); if (!buf) { TRACE_RET(chip, STATUS_ERROR); } @@ -3816,7 +3816,9 @@ int mg_get_local_EKB(struct scsi_cmnd *srb, struct rtsx_chip *chip) rtsx_stor_set_xfer_buf(buf, bufflen, srb); GetEKBFinish: - kfree(buf); + if (buf) { + rtsx_free_dma_buf(chip, buf); + } return retval; } @@ -4019,7 +4021,7 @@ int mg_get_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) TRACE_RET(chip, STATUS_FAIL); } - buf = kmalloc(1028, GFP_KERNEL); + buf = (u8 *)rtsx_alloc_dma_buf(chip, 1028, GFP_KERNEL); if (!buf) { TRACE_RET(chip, STATUS_ERROR); } @@ -4052,7 +4054,9 @@ int mg_get_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) rtsx_stor_set_xfer_buf(buf, bufflen, srb); GetICVFinish: - kfree(buf); + if (buf) { + rtsx_free_dma_buf(chip, buf); + } return retval; } @@ -4076,7 +4080,7 @@ int mg_set_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) TRACE_RET(chip, STATUS_FAIL); } - buf = kmalloc(1028, GFP_KERNEL); + buf = (u8 *)rtsx_alloc_dma_buf(chip, 1028, GFP_KERNEL); if (!buf) { TRACE_RET(chip, STATUS_ERROR); } @@ -4151,7 +4155,9 @@ int mg_set_ICV(struct scsi_cmnd *srb, struct rtsx_chip *chip) #endif SetICVFinish: - kfree(buf); + if (buf) { + rtsx_free_dma_buf(chip, buf); + } return retval; } diff --git a/trunk/drivers/staging/rts_pstor/rtsx.h b/trunk/drivers/staging/rts_pstor/rtsx.h index 6afb6358e775..4d5ddf6fbb5e 100644 --- a/trunk/drivers/staging/rts_pstor/rtsx.h +++ b/trunk/drivers/staging/rts_pstor/rtsx.h @@ -98,6 +98,9 @@ do { \ #define SCSI_LUN(srb) ((srb)->device->lun) +#define rtsx_alloc_dma_buf(chip, size, flag) kmalloc((size), (flag)) +#define rtsx_free_dma_buf(chip, ptr) kfree((ptr)) + typedef unsigned long DELAY_PARA_T; struct rtsx_chip; diff --git a/trunk/drivers/staging/rts_pstor/spi.c b/trunk/drivers/staging/rts_pstor/spi.c index c803ba635509..8a8689b327ae 100644 --- a/trunk/drivers/staging/rts_pstor/spi.c +++ b/trunk/drivers/staging/rts_pstor/spi.c @@ -505,7 +505,7 @@ int spi_read_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) TRACE_RET(chip, STATUS_FAIL); } - buf = kmalloc(SF_PAGE_LEN, GFP_KERNEL); + buf = (u8 *)rtsx_alloc_dma_buf(chip, SF_PAGE_LEN, GFP_KERNEL); if (buf == NULL) TRACE_RET(chip, STATUS_ERROR); @@ -543,7 +543,7 @@ int spi_read_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = rtsx_transfer_data(chip, 0, buf, pagelen, 0, DMA_FROM_DEVICE, 10000); if (retval < 0) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); TRACE_RET(chip, STATUS_FAIL); @@ -556,7 +556,7 @@ int spi_read_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) } scsi_set_resid(srb, 0); - kfree(buf); + rtsx_free_dma_buf(chip, buf); return STATUS_SUCCESS; } @@ -584,14 +584,14 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) } if (program_mode == BYTE_PROGRAM) { - buf = kmalloc(4, GFP_KERNEL); + buf = rtsx_alloc_dma_buf(chip, 4, GFP_KERNEL); if (!buf) TRACE_RET(chip, STATUS_ERROR); while (len) { retval = sf_enable_write(chip, SPI_WREN); if (retval != STATUS_SUCCESS) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -605,7 +605,7 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = rtsx_send_cmd(chip, 0, 100); if (retval < 0) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); TRACE_RET(chip, STATUS_FAIL); @@ -613,7 +613,7 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = sf_polling_status(chip, 100); if (retval != STATUS_SUCCESS) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -621,7 +621,7 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) len--; } - kfree(buf); + rtsx_free_dma_buf(chip, buf); } else if (program_mode == AAI_PROGRAM) { int first_byte = 1; @@ -630,7 +630,7 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) TRACE_RET(chip, STATUS_FAIL); - buf = kmalloc(4, GFP_KERNEL); + buf = rtsx_alloc_dma_buf(chip, 4, GFP_KERNEL); if (!buf) TRACE_RET(chip, STATUS_ERROR); @@ -650,7 +650,7 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = rtsx_send_cmd(chip, 0, 100); if (retval < 0) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); TRACE_RET(chip, STATUS_FAIL); @@ -658,14 +658,14 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = sf_polling_status(chip, 100); if (retval != STATUS_SUCCESS) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } len--; } - kfree(buf); + rtsx_free_dma_buf(chip, buf); retval = sf_disable_write(chip, SPI_WRDI); if (retval != STATUS_SUCCESS) @@ -675,7 +675,7 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) if (retval != STATUS_SUCCESS) TRACE_RET(chip, STATUS_FAIL); } else if (program_mode == PAGE_PROGRAM) { - buf = kmalloc(SF_PAGE_LEN, GFP_KERNEL); + buf = rtsx_alloc_dma_buf(chip, SF_PAGE_LEN, GFP_KERNEL); if (!buf) TRACE_RET(chip, STATUS_NOMEM); @@ -687,7 +687,7 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = sf_enable_write(chip, SPI_WREN); if (retval != STATUS_SUCCESS) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -702,7 +702,7 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = rtsx_transfer_data(chip, 0, buf, pagelen, 0, DMA_TO_DEVICE, 100); if (retval < 0) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); rtsx_clear_spi_error(chip); spi_set_err_code(chip, SPI_HW_ERR); TRACE_RET(chip, STATUS_FAIL); @@ -710,7 +710,7 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) retval = sf_polling_status(chip, 100); if (retval != STATUS_SUCCESS) { - kfree(buf); + rtsx_free_dma_buf(chip, buf); TRACE_RET(chip, STATUS_FAIL); } @@ -718,7 +718,7 @@ int spi_write_flash(struct scsi_cmnd *srb, struct rtsx_chip *chip) len -= pagelen; } - kfree(buf); + rtsx_free_dma_buf(chip, buf); } else { spi_set_err_code(chip, SPI_INVALID_COMMAND); TRACE_RET(chip, STATUS_FAIL); diff --git a/trunk/drivers/staging/rts_pstor/xd.c b/trunk/drivers/staging/rts_pstor/xd.c index a58a689fe9b5..7bcd468b8f2c 100644 --- a/trunk/drivers/staging/rts_pstor/xd.c +++ b/trunk/drivers/staging/rts_pstor/xd.c @@ -379,7 +379,7 @@ static void xd_clear_dma_buffer(struct rtsx_chip *chip) RTSX_DEBUGP("xD ECC error, dummy write!\n"); - buf = kmalloc(512, GFP_KERNEL); + buf = (u8 *)rtsx_alloc_dma_buf(chip, 512, GFP_KERNEL); if (!buf) return; @@ -426,7 +426,7 @@ static void xd_clear_dma_buffer(struct rtsx_chip *chip) rtsx_write_register(chip, CARD_STOP, SD_STOP | SD_CLR_ERR, SD_STOP | SD_CLR_ERR); } - kfree(buf); + rtsx_free_dma_buf(chip, buf); if (chip->asic_code) { rtsx_write_register(chip, CARD_PULL_CTL2, 0xFF, 0x55); diff --git a/trunk/drivers/staging/samsung-laptop/Kconfig b/trunk/drivers/staging/samsung-laptop/Kconfig new file mode 100644 index 000000000000..f27c60864c26 --- /dev/null +++ b/trunk/drivers/staging/samsung-laptop/Kconfig @@ -0,0 +1,10 @@ +config SAMSUNG_LAPTOP + tristate "Samsung Laptop driver" + default n + depends on RFKILL && BACKLIGHT_CLASS_DEVICE && X86 + help + This module implements a driver for the N128 Samsung Laptop + providing control over the Wireless LED and the LCD backlight + + To compile this driver as a module, choose + M here: the module will be called samsung-laptop. diff --git a/trunk/drivers/staging/samsung-laptop/Makefile b/trunk/drivers/staging/samsung-laptop/Makefile new file mode 100644 index 000000000000..3c6f42045211 --- /dev/null +++ b/trunk/drivers/staging/samsung-laptop/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_SAMSUNG_LAPTOP) += samsung-laptop.o diff --git a/trunk/drivers/staging/samsung-laptop/TODO b/trunk/drivers/staging/samsung-laptop/TODO new file mode 100644 index 000000000000..f7a6d589916e --- /dev/null +++ b/trunk/drivers/staging/samsung-laptop/TODO @@ -0,0 +1,5 @@ +TODO: + - review from other developers + - figure out ACPI video issues + +Please send patches to Greg Kroah-Hartman diff --git a/trunk/drivers/staging/samsung-laptop/samsung-laptop.c b/trunk/drivers/staging/samsung-laptop/samsung-laptop.c new file mode 100644 index 000000000000..25294462b8b6 --- /dev/null +++ b/trunk/drivers/staging/samsung-laptop/samsung-laptop.c @@ -0,0 +1,843 @@ +/* + * Samsung Laptop driver + * + * Copyright (C) 2009,2011 Greg Kroah-Hartman (gregkh@suse.de) + * Copyright (C) 2009,2011 Novell Inc. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + * + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * This driver is needed because a number of Samsung laptops do not hook + * their control settings through ACPI. So we have to poke around in the + * BIOS to do things like brightness values, and "special" key controls. + */ + +/* + * We have 0 - 8 as valid brightness levels. The specs say that level 0 should + * be reserved by the BIOS (which really doesn't make much sense), we tell + * userspace that the value is 0 - 7 and then just tell the hardware 1 - 8 + */ +#define MAX_BRIGHT 0x07 + + +#define SABI_IFACE_MAIN 0x00 +#define SABI_IFACE_SUB 0x02 +#define SABI_IFACE_COMPLETE 0x04 +#define SABI_IFACE_DATA 0x05 + +/* Structure to get data back to the calling function */ +struct sabi_retval { + u8 retval[20]; +}; + +struct sabi_header_offsets { + u8 port; + u8 re_mem; + u8 iface_func; + u8 en_mem; + u8 data_offset; + u8 data_segment; +}; + +struct sabi_commands { + /* + * Brightness is 0 - 8, as described above. + * Value 0 is for the BIOS to use + */ + u8 get_brightness; + u8 set_brightness; + + /* + * first byte: + * 0x00 - wireless is off + * 0x01 - wireless is on + * second byte: + * 0x02 - 3G is off + * 0x03 - 3G is on + * TODO, verify 3G is correct, that doesn't seem right... + */ + u8 get_wireless_button; + u8 set_wireless_button; + + /* 0 is off, 1 is on */ + u8 get_backlight; + u8 set_backlight; + + /* + * 0x80 or 0x00 - no action + * 0x81 - recovery key pressed + */ + u8 get_recovery_mode; + u8 set_recovery_mode; + + /* + * on seclinux: 0 is low, 1 is high, + * on swsmi: 0 is normal, 1 is silent, 2 is turbo + */ + u8 get_performance_level; + u8 set_performance_level; + + /* + * Tell the BIOS that Linux is running on this machine. + * 81 is on, 80 is off + */ + u8 set_linux; +}; + +struct sabi_performance_level { + const char *name; + u8 value; +}; + +struct sabi_config { + const char *test_string; + u16 main_function; + const struct sabi_header_offsets header_offsets; + const struct sabi_commands commands; + const struct sabi_performance_level performance_levels[4]; + u8 min_brightness; + u8 max_brightness; +}; + +static const struct sabi_config sabi_configs[] = { + { + .test_string = "SECLINUX", + + .main_function = 0x4c49, + + .header_offsets = { + .port = 0x00, + .re_mem = 0x02, + .iface_func = 0x03, + .en_mem = 0x04, + .data_offset = 0x05, + .data_segment = 0x07, + }, + + .commands = { + .get_brightness = 0x00, + .set_brightness = 0x01, + + .get_wireless_button = 0x02, + .set_wireless_button = 0x03, + + .get_backlight = 0x04, + .set_backlight = 0x05, + + .get_recovery_mode = 0x06, + .set_recovery_mode = 0x07, + + .get_performance_level = 0x08, + .set_performance_level = 0x09, + + .set_linux = 0x0a, + }, + + .performance_levels = { + { + .name = "silent", + .value = 0, + }, + { + .name = "normal", + .value = 1, + }, + { }, + }, + .min_brightness = 1, + .max_brightness = 8, + }, + { + .test_string = "SwSmi@", + + .main_function = 0x5843, + + .header_offsets = { + .port = 0x00, + .re_mem = 0x04, + .iface_func = 0x02, + .en_mem = 0x03, + .data_offset = 0x05, + .data_segment = 0x07, + }, + + .commands = { + .get_brightness = 0x10, + .set_brightness = 0x11, + + .get_wireless_button = 0x12, + .set_wireless_button = 0x13, + + .get_backlight = 0x2d, + .set_backlight = 0x2e, + + .get_recovery_mode = 0xff, + .set_recovery_mode = 0xff, + + .get_performance_level = 0x31, + .set_performance_level = 0x32, + + .set_linux = 0xff, + }, + + .performance_levels = { + { + .name = "normal", + .value = 0, + }, + { + .name = "silent", + .value = 1, + }, + { + .name = "overclock", + .value = 2, + }, + { }, + }, + .min_brightness = 0, + .max_brightness = 8, + }, + { }, +}; + +static const struct sabi_config *sabi_config; + +static void __iomem *sabi; +static void __iomem *sabi_iface; +static void __iomem *f0000_segment; +static struct backlight_device *backlight_device; +static struct mutex sabi_mutex; +static struct platform_device *sdev; +static struct rfkill *rfk; + +static int force; +module_param(force, bool, 0); +MODULE_PARM_DESC(force, + "Disable the DMI check and forces the driver to be loaded"); + +static int debug; +module_param(debug, bool, S_IRUGO | S_IWUSR); +MODULE_PARM_DESC(debug, "Debug enabled or not"); + +static int sabi_get_command(u8 command, struct sabi_retval *sretval) +{ + int retval = 0; + u16 port = readw(sabi + sabi_config->header_offsets.port); + u8 complete, iface_data; + + mutex_lock(&sabi_mutex); + + /* enable memory to be able to write to it */ + outb(readb(sabi + sabi_config->header_offsets.en_mem), port); + + /* write out the command */ + writew(sabi_config->main_function, sabi_iface + SABI_IFACE_MAIN); + writew(command, sabi_iface + SABI_IFACE_SUB); + writeb(0, sabi_iface + SABI_IFACE_COMPLETE); + outb(readb(sabi + sabi_config->header_offsets.iface_func), port); + + /* write protect memory to make it safe */ + outb(readb(sabi + sabi_config->header_offsets.re_mem), port); + + /* see if the command actually succeeded */ + complete = readb(sabi_iface + SABI_IFACE_COMPLETE); + iface_data = readb(sabi_iface + SABI_IFACE_DATA); + if (complete != 0xaa || iface_data == 0xff) { + pr_warn("SABI get command 0x%02x failed with completion flag 0x%02x and data 0x%02x\n", + command, complete, iface_data); + retval = -EINVAL; + goto exit; + } + /* + * Save off the data into a structure so the caller use it. + * Right now we only want the first 4 bytes, + * There are commands that need more, but not for the ones we + * currently care about. + */ + sretval->retval[0] = readb(sabi_iface + SABI_IFACE_DATA); + sretval->retval[1] = readb(sabi_iface + SABI_IFACE_DATA + 1); + sretval->retval[2] = readb(sabi_iface + SABI_IFACE_DATA + 2); + sretval->retval[3] = readb(sabi_iface + SABI_IFACE_DATA + 3); + +exit: + mutex_unlock(&sabi_mutex); + return retval; + +} + +static int sabi_set_command(u8 command, u8 data) +{ + int retval = 0; + u16 port = readw(sabi + sabi_config->header_offsets.port); + u8 complete, iface_data; + + mutex_lock(&sabi_mutex); + + /* enable memory to be able to write to it */ + outb(readb(sabi + sabi_config->header_offsets.en_mem), port); + + /* write out the command */ + writew(sabi_config->main_function, sabi_iface + SABI_IFACE_MAIN); + writew(command, sabi_iface + SABI_IFACE_SUB); + writeb(0, sabi_iface + SABI_IFACE_COMPLETE); + writeb(data, sabi_iface + SABI_IFACE_DATA); + outb(readb(sabi + sabi_config->header_offsets.iface_func), port); + + /* write protect memory to make it safe */ + outb(readb(sabi + sabi_config->header_offsets.re_mem), port); + + /* see if the command actually succeeded */ + complete = readb(sabi_iface + SABI_IFACE_COMPLETE); + iface_data = readb(sabi_iface + SABI_IFACE_DATA); + if (complete != 0xaa || iface_data == 0xff) { + pr_warn("SABI set command 0x%02x failed with completion flag 0x%02x and data 0x%02x\n", + command, complete, iface_data); + retval = -EINVAL; + } + + mutex_unlock(&sabi_mutex); + return retval; +} + +static void test_backlight(void) +{ + struct sabi_retval sretval; + + sabi_get_command(sabi_config->commands.get_backlight, &sretval); + printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]); + + sabi_set_command(sabi_config->commands.set_backlight, 0); + printk(KERN_DEBUG "backlight should be off\n"); + + sabi_get_command(sabi_config->commands.get_backlight, &sretval); + printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]); + + msleep(1000); + + sabi_set_command(sabi_config->commands.set_backlight, 1); + printk(KERN_DEBUG "backlight should be on\n"); + + sabi_get_command(sabi_config->commands.get_backlight, &sretval); + printk(KERN_DEBUG "backlight = 0x%02x\n", sretval.retval[0]); +} + +static void test_wireless(void) +{ + struct sabi_retval sretval; + + sabi_get_command(sabi_config->commands.get_wireless_button, &sretval); + printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]); + + sabi_set_command(sabi_config->commands.set_wireless_button, 0); + printk(KERN_DEBUG "wireless led should be off\n"); + + sabi_get_command(sabi_config->commands.get_wireless_button, &sretval); + printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]); + + msleep(1000); + + sabi_set_command(sabi_config->commands.set_wireless_button, 1); + printk(KERN_DEBUG "wireless led should be on\n"); + + sabi_get_command(sabi_config->commands.get_wireless_button, &sretval); + printk(KERN_DEBUG "wireless led = 0x%02x\n", sretval.retval[0]); +} + +static u8 read_brightness(void) +{ + struct sabi_retval sretval; + int user_brightness = 0; + int retval; + + retval = sabi_get_command(sabi_config->commands.get_brightness, + &sretval); + if (!retval) { + user_brightness = sretval.retval[0]; + if (user_brightness != 0) + user_brightness -= sabi_config->min_brightness; + } + return user_brightness; +} + +static void set_brightness(u8 user_brightness) +{ + u8 user_level = user_brightness - sabi_config->min_brightness; + + sabi_set_command(sabi_config->commands.set_brightness, user_level); +} + +static int get_brightness(struct backlight_device *bd) +{ + return (int)read_brightness(); +} + +static int update_status(struct backlight_device *bd) +{ + set_brightness(bd->props.brightness); + + if (bd->props.power == FB_BLANK_UNBLANK) + sabi_set_command(sabi_config->commands.set_backlight, 1); + else + sabi_set_command(sabi_config->commands.set_backlight, 0); + return 0; +} + +static const struct backlight_ops backlight_ops = { + .get_brightness = get_brightness, + .update_status = update_status, +}; + +static int rfkill_set(void *data, bool blocked) +{ + /* Do something with blocked...*/ + /* + * blocked == false is on + * blocked == true is off + */ + if (blocked) + sabi_set_command(sabi_config->commands.set_wireless_button, 0); + else + sabi_set_command(sabi_config->commands.set_wireless_button, 1); + + return 0; +} + +static struct rfkill_ops rfkill_ops = { + .set_block = rfkill_set, +}; + +static int init_wireless(struct platform_device *sdev) +{ + int retval; + + rfk = rfkill_alloc("samsung-wifi", &sdev->dev, RFKILL_TYPE_WLAN, + &rfkill_ops, NULL); + if (!rfk) + return -ENOMEM; + + retval = rfkill_register(rfk); + if (retval) { + rfkill_destroy(rfk); + return -ENODEV; + } + + return 0; +} + +static void destroy_wireless(void) +{ + rfkill_unregister(rfk); + rfkill_destroy(rfk); +} + +static ssize_t get_performance_level(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct sabi_retval sretval; + int retval; + int i; + + /* Read the state */ + retval = sabi_get_command(sabi_config->commands.get_performance_level, + &sretval); + if (retval) + return retval; + + /* The logic is backwards, yeah, lots of fun... */ + for (i = 0; sabi_config->performance_levels[i].name; ++i) { + if (sretval.retval[0] == sabi_config->performance_levels[i].value) + return sprintf(buf, "%s\n", sabi_config->performance_levels[i].name); + } + return sprintf(buf, "%s\n", "unknown"); +} + +static ssize_t set_performance_level(struct device *dev, + struct device_attribute *attr, const char *buf, + size_t count) +{ + if (count >= 1) { + int i; + for (i = 0; sabi_config->performance_levels[i].name; ++i) { + const struct sabi_performance_level *level = + &sabi_config->performance_levels[i]; + if (!strncasecmp(level->name, buf, strlen(level->name))) { + sabi_set_command(sabi_config->commands.set_performance_level, + level->value); + break; + } + } + if (!sabi_config->performance_levels[i].name) + return -EINVAL; + } + return count; +} +static DEVICE_ATTR(performance_level, S_IWUSR | S_IRUGO, + get_performance_level, set_performance_level); + + +static int __init dmi_check_cb(const struct dmi_system_id *id) +{ + pr_info("found laptop model '%s'\n", + id->ident); + return 0; +} + +static struct dmi_system_id __initdata samsung_dmi_table[] = { + { + .ident = "N128", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "N128"), + DMI_MATCH(DMI_BOARD_NAME, "N128"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "N130", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "N130"), + DMI_MATCH(DMI_BOARD_NAME, "N130"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "X125", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "X125"), + DMI_MATCH(DMI_BOARD_NAME, "X125"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "X120/X170", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "X120/X170"), + DMI_MATCH(DMI_BOARD_NAME, "X120/X170"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "NC10", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "NC10"), + DMI_MATCH(DMI_BOARD_NAME, "NC10"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "NP-Q45", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"), + DMI_MATCH(DMI_BOARD_NAME, "SQ45S70S"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "X360", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "X360"), + DMI_MATCH(DMI_BOARD_NAME, "X360"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "R410 Plus", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "R410P"), + DMI_MATCH(DMI_BOARD_NAME, "R460"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "R518", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "R518"), + DMI_MATCH(DMI_BOARD_NAME, "R518"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "R519/R719", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "R519/R719"), + DMI_MATCH(DMI_BOARD_NAME, "R519/R719"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "N150/N210/N220/N230", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "N150/N210/N220/N230"), + DMI_MATCH(DMI_BOARD_NAME, "N150/N210/N220/N230"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "N150P/N210P/N220P", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "N150P/N210P/N220P"), + DMI_MATCH(DMI_BOARD_NAME, "N150P/N210P/N220P"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "R530/R730", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "R530/R730"), + DMI_MATCH(DMI_BOARD_NAME, "R530/R730"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "NF110/NF210/NF310", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "NF110/NF210/NF310"), + DMI_MATCH(DMI_BOARD_NAME, "NF110/NF210/NF310"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "N145P/N250P/N260P", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "N145P/N250P/N260P"), + DMI_MATCH(DMI_BOARD_NAME, "N145P/N250P/N260P"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "R70/R71", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, + "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "R70/R71"), + DMI_MATCH(DMI_BOARD_NAME, "R70/R71"), + }, + .callback = dmi_check_cb, + }, + { + .ident = "P460", + .matches = { + DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."), + DMI_MATCH(DMI_PRODUCT_NAME, "P460"), + DMI_MATCH(DMI_BOARD_NAME, "P460"), + }, + .callback = dmi_check_cb, + }, + { }, +}; +MODULE_DEVICE_TABLE(dmi, samsung_dmi_table); + +static int find_signature(void __iomem *memcheck, const char *testStr) +{ + int i = 0; + int loca; + + for (loca = 0; loca < 0xffff; loca++) { + char temp = readb(memcheck + loca); + + if (temp == testStr[i]) { + if (i == strlen(testStr)-1) + break; + ++i; + } else { + i = 0; + } + } + return loca; +} + +static int __init samsung_init(void) +{ + struct backlight_properties props; + struct sabi_retval sretval; + unsigned int ifaceP; + int i; + int loca; + int retval; + + mutex_init(&sabi_mutex); + + if (!force && !dmi_check_system(samsung_dmi_table)) + return -ENODEV; + + f0000_segment = ioremap_nocache(0xf0000, 0xffff); + if (!f0000_segment) { + pr_err("Can't map the segment at 0xf0000\n"); + return -EINVAL; + } + + /* Try to find one of the signatures in memory to find the header */ + for (i = 0; sabi_configs[i].test_string != 0; ++i) { + sabi_config = &sabi_configs[i]; + loca = find_signature(f0000_segment, sabi_config->test_string); + if (loca != 0xffff) + break; + } + + if (loca == 0xffff) { + pr_err("This computer does not support SABI\n"); + goto error_no_signature; + } + + /* point to the SMI port Number */ + loca += 1; + sabi = (f0000_segment + loca); + + if (debug) { + printk(KERN_DEBUG "This computer supports SABI==%x\n", + loca + 0xf0000 - 6); + printk(KERN_DEBUG "SABI header:\n"); + printk(KERN_DEBUG " SMI Port Number = 0x%04x\n", + readw(sabi + sabi_config->header_offsets.port)); + printk(KERN_DEBUG " SMI Interface Function = 0x%02x\n", + readb(sabi + sabi_config->header_offsets.iface_func)); + printk(KERN_DEBUG " SMI enable memory buffer = 0x%02x\n", + readb(sabi + sabi_config->header_offsets.en_mem)); + printk(KERN_DEBUG " SMI restore memory buffer = 0x%02x\n", + readb(sabi + sabi_config->header_offsets.re_mem)); + printk(KERN_DEBUG " SABI data offset = 0x%04x\n", + readw(sabi + sabi_config->header_offsets.data_offset)); + printk(KERN_DEBUG " SABI data segment = 0x%04x\n", + readw(sabi + sabi_config->header_offsets.data_segment)); + } + + /* Get a pointer to the SABI Interface */ + ifaceP = (readw(sabi + sabi_config->header_offsets.data_segment) & 0x0ffff) << 4; + ifaceP += readw(sabi + sabi_config->header_offsets.data_offset) & 0x0ffff; + sabi_iface = ioremap_nocache(ifaceP, 16); + if (!sabi_iface) { + pr_err("Can't remap %x\n", ifaceP); + goto exit; + } + if (debug) { + printk(KERN_DEBUG "ifaceP = 0x%08x\n", ifaceP); + printk(KERN_DEBUG "sabi_iface = %p\n", sabi_iface); + + test_backlight(); + test_wireless(); + + retval = sabi_get_command(sabi_config->commands.get_brightness, + &sretval); + printk(KERN_DEBUG "brightness = 0x%02x\n", sretval.retval[0]); + } + + /* Turn on "Linux" mode in the BIOS */ + if (sabi_config->commands.set_linux != 0xff) { + retval = sabi_set_command(sabi_config->commands.set_linux, + 0x81); + if (retval) { + pr_warn("Linux mode was not set!\n"); + goto error_no_platform; + } + } + + /* knock up a platform device to hang stuff off of */ + sdev = platform_device_register_simple("samsung", -1, NULL, 0); + if (IS_ERR(sdev)) + goto error_no_platform; + + /* create a backlight device to talk to this one */ + memset(&props, 0, sizeof(struct backlight_properties)); + props.type = BACKLIGHT_PLATFORM; + props.max_brightness = sabi_config->max_brightness; + backlight_device = backlight_device_register("samsung", &sdev->dev, + NULL, &backlight_ops, + &props); + if (IS_ERR(backlight_device)) + goto error_no_backlight; + + backlight_device->props.brightness = read_brightness(); + backlight_device->props.power = FB_BLANK_UNBLANK; + backlight_update_status(backlight_device); + + retval = init_wireless(sdev); + if (retval) + goto error_no_rfk; + + retval = device_create_file(&sdev->dev, &dev_attr_performance_level); + if (retval) + goto error_file_create; + +exit: + return 0; + +error_file_create: + destroy_wireless(); + +error_no_rfk: + backlight_device_unregister(backlight_device); + +error_no_backlight: + platform_device_unregister(sdev); + +error_no_platform: + iounmap(sabi_iface); + +error_no_signature: + iounmap(f0000_segment); + return -EINVAL; +} + +static void __exit samsung_exit(void) +{ + /* Turn off "Linux" mode in the BIOS */ + if (sabi_config->commands.set_linux != 0xff) + sabi_set_command(sabi_config->commands.set_linux, 0x80); + + device_remove_file(&sdev->dev, &dev_attr_performance_level); + backlight_device_unregister(backlight_device); + destroy_wireless(); + iounmap(sabi_iface); + iounmap(f0000_segment); + platform_device_unregister(sdev); +} + +module_init(samsung_init); +module_exit(samsung_exit); + +MODULE_AUTHOR("Greg Kroah-Hartman "); +MODULE_DESCRIPTION("Samsung Backlight driver"); +MODULE_LICENSE("GPL"); diff --git a/trunk/drivers/staging/sbe-2t3e3/dc.c b/trunk/drivers/staging/sbe-2t3e3/dc.c index 9dc4ec2109eb..126a9720c6b8 100644 --- a/trunk/drivers/staging/sbe-2t3e3/dc.c +++ b/trunk/drivers/staging/sbe-2t3e3/dc.c @@ -341,6 +341,10 @@ u32 dc_init_descriptor_list(struct channel *sc) sc->ether.tx_ring = kzalloc(SBE_2T3E3_TX_DESC_RING_SIZE * sizeof(t3e3_tx_desc_t), GFP_KERNEL); if (sc->ether.tx_ring == NULL) { +#ifdef T3E3_USE_CONTIGMALLOC + t3e3_contigmemory_size = SBE_2T3E3_RX_DESC_RING_SIZE * + sizeof(t3e3_rx_desc_t); +#endif kfree(sc->ether.rx_ring); sc->ether.rx_ring = NULL; dev_err(&sc->pdev->dev, "SBE 2T3E3: no buffer space for RX ring\n"); @@ -362,8 +366,16 @@ u32 dc_init_descriptor_list(struct channel *sc) dev_kfree_skb_any(sc->ether.rx_data[j]); sc->ether.rx_data[j] = NULL; } +#ifdef T3E3_USE_CONTIGMALLOC + t3e3_contigmemory_size = SBE_2T3E3_RX_DESC_RING_SIZE * + sizeof(t3e3_rx_desc_t); +#endif kfree(sc->ether.rx_ring); sc->ether.rx_ring = NULL; +#ifdef T3E3_USE_CONTIGMALLOC + t3e3_contigmemory_size = SBE_2T3E3_TX_DESC_RING_SIZE * + sizeof(t3e3_tx_desc_t); +#endif kfree(sc->ether.tx_ring); sc->ether.tx_ring = NULL; dev_err(&sc->pdev->dev, "SBE 2T3E3: token_alloc err:" @@ -442,10 +454,23 @@ void dc_drop_descriptor_list(struct channel *sc) } } - kfree(sc->ether.rx_ring); - sc->ether.rx_ring = NULL; - kfree(sc->ether.tx_ring); - sc->ether.tx_ring = NULL; + if (sc->ether.rx_ring != NULL) { +#ifdef T3E3_USE_CONTIGMALLOC + t3e3_contigmemory_size = SBE_2T3E3_RX_DESC_RING_SIZE * + sizeof(t3e3_rx_desc_t); +#endif + kfree(sc->ether.rx_ring); + sc->ether.rx_ring = NULL; + } + + if (sc->ether.tx_ring != NULL) { +#ifdef T3E3_USE_CONTIGMALLOC + t3e3_contigmemory_size = SBE_2T3E3_TX_DESC_RING_SIZE * + sizeof(t3e3_tx_desc_t); +#endif + kfree(sc->ether.tx_ring); + sc->ether.tx_ring = NULL; + } } diff --git a/trunk/drivers/staging/tty/istallion.c b/trunk/drivers/staging/tty/istallion.c index ca18cbf4e3c9..0b266272cccd 100644 --- a/trunk/drivers/staging/tty/istallion.c +++ b/trunk/drivers/staging/tty/istallion.c @@ -186,6 +186,7 @@ static struct ktermios stli_deftermios = { * re-used for each stats call. */ static comstats_t stli_comstats; +static combrd_t stli_brdstats; static struct asystats stli_cdkstats; /*****************************************************************************/ @@ -4004,7 +4005,6 @@ static int stli_getbrdstats(combrd_t __user *bp) { struct stlibrd *brdp; unsigned int i; - combrd_t stli_brdstats; if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t))) return -EFAULT; diff --git a/trunk/drivers/staging/winbond/mto.c b/trunk/drivers/staging/winbond/mto.c index 5250217156a7..c03e5010ca34 100644 --- a/trunk/drivers/staging/winbond/mto.c +++ b/trunk/drivers/staging/winbond/mto.c @@ -40,9 +40,14 @@ static u8 MTO_Data_Rate_Tbl[MTO_MAX_DATA_RATE_LEVELS] = { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 }; +static int TotalTxPkt; +static int TotalTxPktRetry; /* this record the retry rate at different data rate */ static int retryrate_rec[MTO_MAX_DATA_RATE_LEVELS]; +static int PeriodTotalTxPkt; +static int PeriodTotalTxPktRetry; + static u8 boSparseTxTraffic; void MTO_Init(struct wbsoft_priv *adapter); @@ -169,4 +174,9 @@ void MTO_SetTxCount(struct wbsoft_priv *adapter, u8 tx_rate, u8 index) MTO_HAL()->dto_tx_retry_count += index; MTO_HAL()->dto_tx_frag_count += (index + 1); } + TotalTxPkt++; + TotalTxPktRetry += (index + 1); + + PeriodTotalTxPkt++; + PeriodTotalTxPktRetry += (index + 1); } diff --git a/trunk/drivers/staging/winbond/phy_calibration.c b/trunk/drivers/staging/winbond/phy_calibration.c index 79e53e46ecca..09844db64fe9 100644 --- a/trunk/drivers/staging/winbond/phy_calibration.c +++ b/trunk/drivers/staging/winbond/phy_calibration.c @@ -27,10 +27,10 @@ #define DEG2RAD(X) 0.017453 * (X) static const s32 Angles[] = { - FIXED(DEG2RAD(45.0)), FIXED(DEG2RAD(26.565)), FIXED(DEG2RAD(14.0362)), - FIXED(DEG2RAD(7.12502)), FIXED(DEG2RAD(3.57633)), FIXED(DEG2RAD(1.78991)), - FIXED(DEG2RAD(0.895174)), FIXED(DEG2RAD(0.447614)), FIXED(DEG2RAD(0.223811)), - FIXED(DEG2RAD(0.111906)), FIXED(DEG2RAD(0.055953)), FIXED(DEG2RAD(0.027977)) + FIXED(DEG2RAD(45.0)), FIXED(DEG2RAD(26.565)), FIXED(DEG2RAD(14.0362)), + FIXED(DEG2RAD(7.12502)), FIXED(DEG2RAD(3.57633)), FIXED(DEG2RAD(1.78991)), + FIXED(DEG2RAD(0.895174)), FIXED(DEG2RAD(0.447614)), FIXED(DEG2RAD(0.223811)), + FIXED(DEG2RAD(0.111906)), FIXED(DEG2RAD(0.055953)), FIXED(DEG2RAD(0.027977)) }; /****************** LOCAL FUNCTION DECLARATION SECTION **********************/ diff --git a/trunk/drivers/staging/winbond/wb35tx.c b/trunk/drivers/staging/winbond/wb35tx.c index 5df39d46cda4..44fc3fe79b79 100644 --- a/trunk/drivers/staging/winbond/wb35tx.c +++ b/trunk/drivers/staging/winbond/wb35tx.c @@ -291,6 +291,7 @@ void Wb35Tx_EP2VM_start(struct wbsoft_priv *adapter) if (atomic_inc_return(&pWb35Tx->TxResultCount) == 1) { pWb35Tx->EP2vm_state = VM_RUNNING; Wb35Tx_EP2VM(adapter); - } else + } + else atomic_dec(&pWb35Tx->TxResultCount); } diff --git a/trunk/drivers/usb/Kconfig b/trunk/drivers/usb/Kconfig index 006489d82dc3..41b6e51188e4 100644 --- a/trunk/drivers/usb/Kconfig +++ b/trunk/drivers/usb/Kconfig @@ -66,7 +66,6 @@ config USB_ARCH_HAS_EHCI default y if ARCH_VT8500 default y if PLAT_SPEAR default y if ARCH_MSM - default y if MICROBLAZE default PCI # ARM SA1111 chips have a non-PCI based "OHCI-compatible" USB host interface. diff --git a/trunk/drivers/usb/core/devices.c b/trunk/drivers/usb/core/devices.c index 96fdfb815f89..a3d2e2399655 100644 --- a/trunk/drivers/usb/core/devices.c +++ b/trunk/drivers/usb/core/devices.c @@ -221,7 +221,7 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end, break; case USB_ENDPOINT_XFER_INT: type = "Int."; - if (speed == USB_SPEED_HIGH || speed == USB_SPEED_SUPER) + if (speed == USB_SPEED_HIGH) interval = 1 << (desc->bInterval - 1); else interval = desc->bInterval; @@ -229,8 +229,7 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end, default: /* "can't happen" */ return start; } - interval *= (speed == USB_SPEED_HIGH || - speed == USB_SPEED_SUPER) ? 125 : 1000; + interval *= (speed == USB_SPEED_HIGH) ? 125 : 1000; if (interval % 1000) unit = 'u'; else { @@ -543,9 +542,8 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes, if (level == 0) { int max; - /* super/high speed reserves 80%, full/low reserves 90% */ - if (usbdev->speed == USB_SPEED_HIGH || - usbdev->speed == USB_SPEED_SUPER) + /* high speed reserves 80%, full/low reserves 90% */ + if (usbdev->speed == USB_SPEED_HIGH) max = 800; else max = FRAME_TIME_MAX_USECS_ALLOC; diff --git a/trunk/drivers/usb/core/hcd.c b/trunk/drivers/usb/core/hcd.c index 77a7faec8d78..8eed05d23838 100644 --- a/trunk/drivers/usb/core/hcd.c +++ b/trunk/drivers/usb/core/hcd.c @@ -1908,7 +1908,7 @@ void usb_free_streams(struct usb_interface *interface, /* Streams only apply to bulk endpoints. */ for (i = 0; i < num_eps; i++) - if (!eps[i] || !usb_endpoint_xfer_bulk(&eps[i]->desc)) + if (!usb_endpoint_xfer_bulk(&eps[i]->desc)) return; hcd->driver->free_streams(hcd, dev, eps, num_eps, mem_flags); diff --git a/trunk/drivers/usb/core/hub.c b/trunk/drivers/usb/core/hub.c index 93720bdc9efd..8fb754916c67 100644 --- a/trunk/drivers/usb/core/hub.c +++ b/trunk/drivers/usb/core/hub.c @@ -2285,17 +2285,7 @@ int usb_port_suspend(struct usb_device *udev, pm_message_t msg) } /* see 7.1.7.6 */ - /* Clear PORT_POWER if it's a USB3.0 device connected to USB 3.0 - * external hub. - * FIXME: this is a temporary workaround to make the system able - * to suspend/resume. - */ - if ((hub->hdev->parent != NULL) && hub_is_superspeed(hub->hdev)) - status = clear_port_feature(hub->hdev, port1, - USB_PORT_FEAT_POWER); - else - status = set_port_feature(hub->hdev, port1, - USB_PORT_FEAT_SUSPEND); + status = set_port_feature(hub->hdev, port1, USB_PORT_FEAT_SUSPEND); if (status) { dev_dbg(hub->intfdev, "can't suspend port %d, status %d\n", port1, status); diff --git a/trunk/drivers/usb/gadget/f_audio.c b/trunk/drivers/usb/gadget/f_audio.c index 0111f8a9cf7f..9abecfddb27d 100644 --- a/trunk/drivers/usb/gadget/f_audio.c +++ b/trunk/drivers/usb/gadget/f_audio.c @@ -706,7 +706,6 @@ f_audio_unbind(struct usb_configuration *c, struct usb_function *f) struct f_audio *audio = func_to_audio(f); usb_free_descriptors(f->descriptors); - usb_free_descriptors(f->hs_descriptors); kfree(audio); } diff --git a/trunk/drivers/usb/gadget/f_eem.c b/trunk/drivers/usb/gadget/f_eem.c index b3c304290150..95dd4662d6a8 100644 --- a/trunk/drivers/usb/gadget/f_eem.c +++ b/trunk/drivers/usb/gadget/f_eem.c @@ -314,9 +314,6 @@ eem_unbind(struct usb_configuration *c, struct usb_function *f) static void eem_cmd_complete(struct usb_ep *ep, struct usb_request *req) { - struct sk_buff *skb = (struct sk_buff *)req->context; - - dev_kfree_skb_any(skb); } /* @@ -431,11 +428,10 @@ static int eem_unwrap(struct gether *port, skb_trim(skb2, len); put_unaligned_le16(BIT(15) | BIT(11) | len, skb_push(skb2, 2)); - skb_copy_bits(skb2, 0, req->buf, skb2->len); - req->length = skb2->len; + skb_copy_bits(skb, 0, req->buf, skb->len); + req->length = skb->len; req->complete = eem_cmd_complete; req->zero = 1; - req->context = skb2; if (usb_ep_queue(port->in_ep, req, GFP_ATOMIC)) DBG(cdev, "echo response queue fail\n"); break; diff --git a/trunk/drivers/usb/gadget/fsl_qe_udc.c b/trunk/drivers/usb/gadget/fsl_qe_udc.c index 36613b37c504..aee7e3c53c38 100644 --- a/trunk/drivers/usb/gadget/fsl_qe_udc.c +++ b/trunk/drivers/usb/gadget/fsl_qe_udc.c @@ -1148,12 +1148,6 @@ static int qe_ep_tx(struct qe_ep *ep, struct qe_frame *frame) static int txcomplete(struct qe_ep *ep, unsigned char restart) { if (ep->tx_req != NULL) { - struct qe_req *req = ep->tx_req; - unsigned zlp = 0, last_len = 0; - - last_len = min_t(unsigned, req->req.length - ep->sent, - ep->ep.maxpacket); - if (!restart) { int asent = ep->last; ep->sent += asent; @@ -1162,18 +1156,9 @@ static int txcomplete(struct qe_ep *ep, unsigned char restart) ep->last = 0; } - /* zlp needed when req->re.zero is set */ - if (req->req.zero) { - if (last_len == 0 || - (req->req.length % ep->ep.maxpacket) != 0) - zlp = 0; - else - zlp = 1; - } else - zlp = 0; - /* a request already were transmitted completely */ - if (((ep->tx_req->req.length - ep->sent) <= 0) && !zlp) { + if ((ep->tx_req->req.length - ep->sent) <= 0) { + ep->tx_req->req.actual = (unsigned int)ep->sent; done(ep, ep->tx_req, 0); ep->tx_req = NULL; ep->last = 0; @@ -1206,7 +1191,6 @@ static int qe_usb_senddata(struct qe_ep *ep, struct qe_frame *frame) buf = (u8 *)ep->tx_req->req.buf + ep->sent; if (buf && size) { ep->last = size; - ep->tx_req->req.actual += size; frame_set_data(frame, buf); frame_set_length(frame, size); frame_set_status(frame, FRAME_OK); diff --git a/trunk/drivers/usb/gadget/inode.c b/trunk/drivers/usb/gadget/inode.c index a01383f71f38..3ed73f49cf18 100644 --- a/trunk/drivers/usb/gadget/inode.c +++ b/trunk/drivers/usb/gadget/inode.c @@ -386,10 +386,8 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr) /* halt any endpoint by doing a "wrong direction" i/o call */ if (usb_endpoint_dir_in(&data->desc)) { - if (usb_endpoint_xfer_isoc(&data->desc)) { - mutex_unlock(&data->lock); + if (usb_endpoint_xfer_isoc(&data->desc)) return -EINVAL; - } DBG (data->dev, "%s halt\n", data->name); spin_lock_irq (&data->dev->lock); if (likely (data->ep != NULL)) diff --git a/trunk/drivers/usb/gadget/pch_udc.c b/trunk/drivers/usb/gadget/pch_udc.c index 68dbcc3e4cc2..3e4b35e50c24 100644 --- a/trunk/drivers/usb/gadget/pch_udc.c +++ b/trunk/drivers/usb/gadget/pch_udc.c @@ -1608,7 +1608,7 @@ static int pch_udc_pcd_queue(struct usb_ep *usbep, struct usb_request *usbreq, return -EINVAL; if (!dev->driver || (dev->gadget.speed == USB_SPEED_UNKNOWN)) return -ESHUTDOWN; - spin_lock_irqsave(&dev->lock, iflags); + spin_lock_irqsave(&ep->dev->lock, iflags); /* map the buffer for dma */ if (usbreq->length && ((usbreq->dma == DMA_ADDR_INVALID) || !usbreq->dma)) { @@ -1625,10 +1625,8 @@ static int pch_udc_pcd_queue(struct usb_ep *usbep, struct usb_request *usbreq, DMA_FROM_DEVICE); } else { req->buf = kzalloc(usbreq->length, GFP_ATOMIC); - if (!req->buf) { - retval = -ENOMEM; - goto probe_end; - } + if (!req->buf) + return -ENOMEM; if (ep->in) { memcpy(req->buf, usbreq->buf, usbreq->length); req->dma = dma_map_single(&dev->pdev->dev, diff --git a/trunk/drivers/usb/gadget/r8a66597-udc.c b/trunk/drivers/usb/gadget/r8a66597-udc.c index 6dcc1f68fa60..015118535f77 100644 --- a/trunk/drivers/usb/gadget/r8a66597-udc.c +++ b/trunk/drivers/usb/gadget/r8a66597-udc.c @@ -1083,9 +1083,7 @@ static void irq_device_state(struct r8a66597 *r8a66597) if (dvsq == DS_DFLT) { /* bus reset */ - spin_unlock(&r8a66597->lock); r8a66597->driver->disconnect(&r8a66597->gadget); - spin_lock(&r8a66597->lock); r8a66597_update_usb_speed(r8a66597); } if (r8a66597->old_dvsq == DS_CNFG && dvsq != DS_CNFG) diff --git a/trunk/drivers/usb/host/ehci-q.c b/trunk/drivers/usb/host/ehci-q.c index 42abd0f603bf..98ded66e8d3f 100644 --- a/trunk/drivers/usb/host/ehci-q.c +++ b/trunk/drivers/usb/host/ehci-q.c @@ -1247,27 +1247,24 @@ static void start_unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh) static void scan_async (struct ehci_hcd *ehci) { - bool stopped; struct ehci_qh *qh; enum ehci_timer_action action = TIMER_IO_WATCHDOG; ehci->stamp = ehci_readl(ehci, &ehci->regs->frame_index); timer_action_done (ehci, TIMER_ASYNC_SHRINK); rescan: - stopped = !HC_IS_RUNNING(ehci_to_hcd(ehci)->state); qh = ehci->async->qh_next.qh; if (likely (qh != NULL)) { do { /* clean any finished work for this qh */ - if (!list_empty(&qh->qtd_list) && (stopped || - qh->stamp != ehci->stamp)) { + if (!list_empty (&qh->qtd_list) + && qh->stamp != ehci->stamp) { int temp; /* unlinks could happen here; completion * reporting drops the lock. rescan using * the latest schedule, but don't rescan - * qhs we already finished (no looping) - * unless the controller is stopped. + * qhs we already finished (no looping). */ qh = qh_get (qh); qh->stamp = ehci->stamp; @@ -1288,9 +1285,9 @@ static void scan_async (struct ehci_hcd *ehci) */ if (list_empty(&qh->qtd_list) && qh->qh_state == QH_STATE_LINKED) { - if (!ehci->reclaim && (stopped || - ((ehci->stamp - qh->stamp) & 0x1fff) - >= EHCI_SHRINK_FRAMES * 8)) + if (!ehci->reclaim + && ((ehci->stamp - qh->stamp) & 0x1fff) + >= (EHCI_SHRINK_FRAMES * 8)) start_unlink_async(ehci, qh); else action = TIMER_ASYNC_SHRINK; diff --git a/trunk/drivers/usb/host/isp1760-hcd.c b/trunk/drivers/usb/host/isp1760-hcd.c index 795345ad45e6..f50e84ac570a 100644 --- a/trunk/drivers/usb/host/isp1760-hcd.c +++ b/trunk/drivers/usb/host/isp1760-hcd.c @@ -295,7 +295,7 @@ static void alloc_mem(struct usb_hcd *hcd, struct isp1760_qtd *qtd) } dev_err(hcd->self.controller, - "%s: Cannot allocate %zu bytes of memory\n" + "%s: Can not allocate %lu bytes of memory\n" "Current memory map:\n", __func__, qtd->length); for (i = 0; i < BLOCKS; i++) { diff --git a/trunk/drivers/usb/host/ohci-au1xxx.c b/trunk/drivers/usb/host/ohci-au1xxx.c index 958d985f2951..17a6043c1fa0 100644 --- a/trunk/drivers/usb/host/ohci-au1xxx.c +++ b/trunk/drivers/usb/host/ohci-au1xxx.c @@ -33,7 +33,7 @@ #ifdef __LITTLE_ENDIAN #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C) -#elif defined(__BIG_ENDIAN) +#elif __BIG_ENDIAN #define USBH_ENABLE_INIT (USBH_ENABLE_CE | USBH_ENABLE_E | USBH_ENABLE_C | \ USBH_ENABLE_BE) #else diff --git a/trunk/drivers/usb/host/pci-quirks.c b/trunk/drivers/usb/host/pci-quirks.c index 9b166d70ae91..1d586d4f7b56 100644 --- a/trunk/drivers/usb/host/pci-quirks.c +++ b/trunk/drivers/usb/host/pci-quirks.c @@ -84,92 +84,65 @@ int usb_amd_find_chipset_info(void) { u8 rev = 0; unsigned long flags; - struct amd_chipset_info info; - int ret; spin_lock_irqsave(&amd_lock, flags); + amd_chipset.probe_count++; /* probe only once */ - if (amd_chipset.probe_count > 0) { - amd_chipset.probe_count++; + if (amd_chipset.probe_count > 1) { spin_unlock_irqrestore(&amd_lock, flags); return amd_chipset.probe_result; } - memset(&info, 0, sizeof(info)); - spin_unlock_irqrestore(&amd_lock, flags); - info.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL); - if (info.smbus_dev) { - rev = info.smbus_dev->revision; + amd_chipset.smbus_dev = pci_get_device(PCI_VENDOR_ID_ATI, 0x4385, NULL); + if (amd_chipset.smbus_dev) { + rev = amd_chipset.smbus_dev->revision; if (rev >= 0x40) - info.sb_type = 1; + amd_chipset.sb_type = 1; else if (rev >= 0x30 && rev <= 0x3b) - info.sb_type = 3; + amd_chipset.sb_type = 3; } else { - info.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, - 0x780b, NULL); - if (!info.smbus_dev) { - ret = 0; - goto commit; + amd_chipset.smbus_dev = pci_get_device(PCI_VENDOR_ID_AMD, + 0x780b, NULL); + if (!amd_chipset.smbus_dev) { + spin_unlock_irqrestore(&amd_lock, flags); + return 0; } - - rev = info.smbus_dev->revision; + rev = amd_chipset.smbus_dev->revision; if (rev >= 0x11 && rev <= 0x18) - info.sb_type = 2; + amd_chipset.sb_type = 2; } - if (info.sb_type == 0) { - if (info.smbus_dev) { - pci_dev_put(info.smbus_dev); - info.smbus_dev = NULL; + if (amd_chipset.sb_type == 0) { + if (amd_chipset.smbus_dev) { + pci_dev_put(amd_chipset.smbus_dev); + amd_chipset.smbus_dev = NULL; } - ret = 0; - goto commit; + spin_unlock_irqrestore(&amd_lock, flags); + return 0; } - info.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9601, NULL); - if (info.nb_dev) { - info.nb_type = 1; + amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x9601, NULL); + if (amd_chipset.nb_dev) { + amd_chipset.nb_type = 1; } else { - info.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, 0x1510, NULL); - if (info.nb_dev) { - info.nb_type = 2; - } else { - info.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, - 0x9600, NULL); - if (info.nb_dev) - info.nb_type = 3; + amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, + 0x1510, NULL); + if (amd_chipset.nb_dev) { + amd_chipset.nb_type = 2; + } else { + amd_chipset.nb_dev = pci_get_device(PCI_VENDOR_ID_AMD, + 0x9600, NULL); + if (amd_chipset.nb_dev) + amd_chipset.nb_type = 3; } } - ret = info.probe_result = 1; + amd_chipset.probe_result = 1; printk(KERN_DEBUG "QUIRK: Enable AMD PLL fix\n"); -commit: - - spin_lock_irqsave(&amd_lock, flags); - if (amd_chipset.probe_count > 0) { - /* race - someone else was faster - drop devices */ - - /* Mark that we where here */ - amd_chipset.probe_count++; - ret = amd_chipset.probe_result; - - spin_unlock_irqrestore(&amd_lock, flags); - - if (info.nb_dev) - pci_dev_put(info.nb_dev); - if (info.smbus_dev) - pci_dev_put(info.smbus_dev); - - } else { - /* no race - commit the result */ - info.probe_count++; - amd_chipset = info; - spin_unlock_irqrestore(&amd_lock, flags); - } - - return ret; + spin_unlock_irqrestore(&amd_lock, flags); + return amd_chipset.probe_result; } EXPORT_SYMBOL_GPL(usb_amd_find_chipset_info); @@ -311,7 +284,6 @@ EXPORT_SYMBOL_GPL(usb_amd_quirk_pll_enable); void usb_amd_dev_put(void) { - struct pci_dev *nb, *smbus; unsigned long flags; spin_lock_irqsave(&amd_lock, flags); @@ -322,23 +294,20 @@ void usb_amd_dev_put(void) return; } - /* save them to pci_dev_put outside of spinlock */ - nb = amd_chipset.nb_dev; - smbus = amd_chipset.smbus_dev; - - amd_chipset.nb_dev = NULL; - amd_chipset.smbus_dev = NULL; + if (amd_chipset.nb_dev) { + pci_dev_put(amd_chipset.nb_dev); + amd_chipset.nb_dev = NULL; + } + if (amd_chipset.smbus_dev) { + pci_dev_put(amd_chipset.smbus_dev); + amd_chipset.smbus_dev = NULL; + } amd_chipset.nb_type = 0; amd_chipset.sb_type = 0; amd_chipset.isoc_reqs = 0; amd_chipset.probe_result = 0; spin_unlock_irqrestore(&amd_lock, flags); - - if (nb) - pci_dev_put(nb); - if (smbus) - pci_dev_put(smbus); } EXPORT_SYMBOL_GPL(usb_amd_dev_put); diff --git a/trunk/drivers/usb/host/xhci-mem.c b/trunk/drivers/usb/host/xhci-mem.c index 627f3438028c..a003e79aacdc 100644 --- a/trunk/drivers/usb/host/xhci-mem.c +++ b/trunk/drivers/usb/host/xhci-mem.c @@ -846,7 +846,7 @@ static u32 xhci_find_real_port_number(struct xhci_hcd *xhci, * Skip ports that don't have known speeds, or have duplicate * Extended Capabilities port speed entries. */ - if (port_speed == 0 || port_speed == DUPLICATE_ENTRY) + if (port_speed == 0 || port_speed == -1) continue; /* @@ -974,47 +974,6 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud return 0; } -/* - * Convert interval expressed as 2^(bInterval - 1) == interval into - * straight exponent value 2^n == interval. - * - */ -static unsigned int xhci_parse_exponent_interval(struct usb_device *udev, - struct usb_host_endpoint *ep) -{ - unsigned int interval; - - interval = clamp_val(ep->desc.bInterval, 1, 16) - 1; - if (interval != ep->desc.bInterval - 1) - dev_warn(&udev->dev, - "ep %#x - rounding interval to %d microframes\n", - ep->desc.bEndpointAddress, - 1 << interval); - - return interval; -} - -/* - * Convert bInterval expressed in frames (in 1-255 range) to exponent of - * microframes, rounded down to nearest power of 2. - */ -static unsigned int xhci_parse_frame_interval(struct usb_device *udev, - struct usb_host_endpoint *ep) -{ - unsigned int interval; - - interval = fls(8 * ep->desc.bInterval) - 1; - interval = clamp_val(interval, 3, 10); - if ((1 << interval) != 8 * ep->desc.bInterval) - dev_warn(&udev->dev, - "ep %#x - rounding interval to %d microframes, ep desc says %d microframes\n", - ep->desc.bEndpointAddress, - 1 << interval, - 8 * ep->desc.bInterval); - - return interval; -} - /* Return the polling or NAK interval. * * The polling interval is expressed in "microframes". If xHCI's Interval field @@ -1023,7 +982,7 @@ static unsigned int xhci_parse_frame_interval(struct usb_device *udev, * The NAK interval is one NAK per 1 to 255 microframes, or no NAKs if interval * is set to 0. */ -static unsigned int xhci_get_endpoint_interval(struct usb_device *udev, +static inline unsigned int xhci_get_endpoint_interval(struct usb_device *udev, struct usb_host_endpoint *ep) { unsigned int interval = 0; @@ -1032,38 +991,45 @@ static unsigned int xhci_get_endpoint_interval(struct usb_device *udev, case USB_SPEED_HIGH: /* Max NAK rate */ if (usb_endpoint_xfer_control(&ep->desc) || - usb_endpoint_xfer_bulk(&ep->desc)) { + usb_endpoint_xfer_bulk(&ep->desc)) interval = ep->desc.bInterval; - break; - } /* Fall through - SS and HS isoc/int have same decoding */ - case USB_SPEED_SUPER: if (usb_endpoint_xfer_int(&ep->desc) || - usb_endpoint_xfer_isoc(&ep->desc)) { - interval = xhci_parse_exponent_interval(udev, ep); + usb_endpoint_xfer_isoc(&ep->desc)) { + if (ep->desc.bInterval == 0) + interval = 0; + else + interval = ep->desc.bInterval - 1; + if (interval > 15) + interval = 15; + if (interval != ep->desc.bInterval + 1) + dev_warn(&udev->dev, "ep %#x - rounding interval to %d microframes\n", + ep->desc.bEndpointAddress, 1 << interval); } break; - + /* Convert bInterval (in 1-255 frames) to microframes and round down to + * nearest power of 2. + */ case USB_SPEED_FULL: - if (usb_endpoint_xfer_int(&ep->desc)) { - interval = xhci_parse_exponent_interval(udev, ep); - break; - } - /* - * Fall through for isochronous endpoint interval decoding - * since it uses the same rules as low speed interrupt - * endpoints. - */ - case USB_SPEED_LOW: if (usb_endpoint_xfer_int(&ep->desc) || - usb_endpoint_xfer_isoc(&ep->desc)) { - - interval = xhci_parse_frame_interval(udev, ep); + usb_endpoint_xfer_isoc(&ep->desc)) { + interval = fls(8*ep->desc.bInterval) - 1; + if (interval > 10) + interval = 10; + if (interval < 3) + interval = 3; + if ((1 << interval) != 8*ep->desc.bInterval) + dev_warn(&udev->dev, + "ep %#x - rounding interval" + " to %d microframes, " + "ep desc says %d microframes\n", + ep->desc.bEndpointAddress, + 1 << interval, + 8*ep->desc.bInterval); } break; - default: BUG(); } @@ -1075,7 +1041,7 @@ static unsigned int xhci_get_endpoint_interval(struct usb_device *udev, * transaction opportunities per microframe", but that goes in the Max Burst * endpoint context field. */ -static u32 xhci_get_endpoint_mult(struct usb_device *udev, +static inline u32 xhci_get_endpoint_mult(struct usb_device *udev, struct usb_host_endpoint *ep) { if (udev->speed != USB_SPEED_SUPER || @@ -1084,7 +1050,7 @@ static u32 xhci_get_endpoint_mult(struct usb_device *udev, return ep->ss_ep_comp.bmAttributes; } -static u32 xhci_get_endpoint_type(struct usb_device *udev, +static inline u32 xhci_get_endpoint_type(struct usb_device *udev, struct usb_host_endpoint *ep) { int in; @@ -1118,7 +1084,7 @@ static u32 xhci_get_endpoint_type(struct usb_device *udev, * Basically, this is the maxpacket size, multiplied by the burst size * and mult size. */ -static u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci, +static inline u32 xhci_get_max_esit_payload(struct xhci_hcd *xhci, struct usb_device *udev, struct usb_host_endpoint *ep) { @@ -1761,12 +1727,12 @@ static void xhci_add_in_port(struct xhci_hcd *xhci, unsigned int num_ports, * found a similar duplicate. */ if (xhci->port_array[i] != major_revision && - xhci->port_array[i] != DUPLICATE_ENTRY) { + xhci->port_array[i] != (u8) -1) { if (xhci->port_array[i] == 0x03) xhci->num_usb3_ports--; else xhci->num_usb2_ports--; - xhci->port_array[i] = DUPLICATE_ENTRY; + xhci->port_array[i] = (u8) -1; } /* FIXME: Should we disable the port? */ continue; @@ -1865,7 +1831,7 @@ static int xhci_setup_port_arrays(struct xhci_hcd *xhci, gfp_t flags) for (i = 0; i < num_ports; i++) { if (xhci->port_array[i] == 0x03 || xhci->port_array[i] == 0 || - xhci->port_array[i] == DUPLICATE_ENTRY) + xhci->port_array[i] == -1) continue; xhci->usb2_ports[port_index] = diff --git a/trunk/drivers/usb/host/xhci-pci.c b/trunk/drivers/usb/host/xhci-pci.c index a10494c2f3c7..ceea9f33491c 100644 --- a/trunk/drivers/usb/host/xhci-pci.c +++ b/trunk/drivers/usb/host/xhci-pci.c @@ -114,10 +114,6 @@ static int xhci_pci_setup(struct usb_hcd *hcd) if (pdev->vendor == PCI_VENDOR_ID_NEC) xhci->quirks |= XHCI_NEC_HOST; - /* AMD PLL quirk */ - if (pdev->vendor == PCI_VENDOR_ID_AMD && usb_amd_find_chipset_info()) - xhci->quirks |= XHCI_AMD_PLL_FIX; - /* Make sure the HC is halted. */ retval = xhci_halt(xhci); if (retval) diff --git a/trunk/drivers/usb/host/xhci-ring.c b/trunk/drivers/usb/host/xhci-ring.c index 7437386a9a50..cfc1ad92473f 100644 --- a/trunk/drivers/usb/host/xhci-ring.c +++ b/trunk/drivers/usb/host/xhci-ring.c @@ -93,7 +93,7 @@ dma_addr_t xhci_trb_virt_to_dma(struct xhci_segment *seg, /* Does this link TRB point to the first segment in a ring, * or was the previous TRB the last TRB on the last segment in the ERST? */ -static bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring *ring, +static inline bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring *ring, struct xhci_segment *seg, union xhci_trb *trb) { if (ring == xhci->event_ring) @@ -107,7 +107,7 @@ static bool last_trb_on_last_seg(struct xhci_hcd *xhci, struct xhci_ring *ring, * segment? I.e. would the updated event TRB pointer step off the end of the * event seg? */ -static int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, +static inline int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, struct xhci_segment *seg, union xhci_trb *trb) { if (ring == xhci->event_ring) @@ -116,7 +116,7 @@ static int last_trb(struct xhci_hcd *xhci, struct xhci_ring *ring, return (trb->link.control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK); } -static int enqueue_is_link_trb(struct xhci_ring *ring) +static inline int enqueue_is_link_trb(struct xhci_ring *ring) { struct xhci_link_trb *link = &ring->enqueue->link; return ((link->control & TRB_TYPE_BITMASK) == TRB_TYPE(TRB_LINK)); @@ -592,7 +592,7 @@ void xhci_queue_new_dequeue_state(struct xhci_hcd *xhci, ep->ep_state |= SET_DEQ_PENDING; } -static void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, +static inline void xhci_stop_watchdog_timer_in_irq(struct xhci_hcd *xhci, struct xhci_virt_ep *ep) { ep->ep_state &= ~EP_HALT_PENDING; @@ -619,13 +619,6 @@ static void xhci_giveback_urb_in_irq(struct xhci_hcd *xhci, /* Only giveback urb when this is the last td in urb */ if (urb_priv->td_cnt == urb_priv->length) { - if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { - xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--; - if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { - if (xhci->quirks & XHCI_AMD_PLL_FIX) - usb_amd_quirk_pll_enable(); - } - } usb_hcd_unlink_urb_from_ep(hcd, urb); xhci_dbg(xhci, "Giveback %s URB %p\n", adjective, urb); @@ -1216,7 +1209,7 @@ static unsigned int find_faked_portnum_from_hw_portnum(struct usb_hcd *hcd, * Skip ports that don't have known speeds, or have duplicate * Extended Capabilities port speed entries. */ - if (port_speed == 0 || port_speed == DUPLICATE_ENTRY) + if (port_speed == 0 || port_speed == -1) continue; /* @@ -1242,7 +1235,6 @@ static void handle_port_status(struct xhci_hcd *xhci, u8 major_revision; struct xhci_bus_state *bus_state; u32 __iomem **port_array; - bool bogus_port_status = false; /* Port status change events always have a successful completion code */ if (GET_COMP_CODE(event->generic.field[2]) != COMP_SUCCESS) { @@ -1255,7 +1247,6 @@ static void handle_port_status(struct xhci_hcd *xhci, max_ports = HCS_MAX_PORTS(xhci->hcs_params1); if ((port_id <= 0) || (port_id > max_ports)) { xhci_warn(xhci, "Invalid port id %d\n", port_id); - bogus_port_status = true; goto cleanup; } @@ -1267,14 +1258,12 @@ static void handle_port_status(struct xhci_hcd *xhci, xhci_warn(xhci, "Event for port %u not in " "Extended Capabilities, ignoring.\n", port_id); - bogus_port_status = true; goto cleanup; } - if (major_revision == DUPLICATE_ENTRY) { + if (major_revision == (u8) -1) { xhci_warn(xhci, "Event for port %u duplicated in" "Extended Capabilities, ignoring.\n", port_id); - bogus_port_status = true; goto cleanup; } @@ -1346,13 +1335,6 @@ static void handle_port_status(struct xhci_hcd *xhci, /* Update event ring dequeue pointer before dropping the lock */ inc_deq(xhci, xhci->event_ring, true); - /* Don't make the USB core poll the roothub if we got a bad port status - * change event. Besides, at that point we can't tell which roothub - * (USB 2.0 or USB 3.0) to kick. - */ - if (bogus_port_status) - return; - spin_unlock(&xhci->lock); /* Pass this up to the core */ usb_hcd_poll_rh_status(hcd); @@ -1572,17 +1554,8 @@ static int finish_td(struct xhci_hcd *xhci, struct xhci_td *td, urb_priv->td_cnt++; /* Giveback the urb when all the tds are completed */ - if (urb_priv->td_cnt == urb_priv->length) { + if (urb_priv->td_cnt == urb_priv->length) ret = 1; - if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { - xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs--; - if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs - == 0) { - if (xhci->quirks & XHCI_AMD_PLL_FIX) - usb_amd_quirk_pll_enable(); - } - } - } } return ret; @@ -1702,52 +1675,71 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, struct urb_priv *urb_priv; int idx; int len = 0; + int skip_td = 0; union xhci_trb *cur_trb; struct xhci_segment *cur_seg; - struct usb_iso_packet_descriptor *frame; u32 trb_comp_code; - bool skip_td = false; ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); trb_comp_code = GET_COMP_CODE(event->transfer_len); urb_priv = td->urb->hcpriv; idx = urb_priv->td_cnt; - frame = &td->urb->iso_frame_desc[idx]; - /* handle completion code */ - switch (trb_comp_code) { - case COMP_SUCCESS: - frame->status = 0; - xhci_dbg(xhci, "Successful isoc transfer!\n"); - break; - case COMP_SHORT_TX: - frame->status = td->urb->transfer_flags & URB_SHORT_NOT_OK ? - -EREMOTEIO : 0; - break; - case COMP_BW_OVER: - frame->status = -ECOMM; - skip_td = true; - break; - case COMP_BUFF_OVER: - case COMP_BABBLE: - frame->status = -EOVERFLOW; - skip_td = true; - break; - case COMP_STALL: - frame->status = -EPROTO; - skip_td = true; - break; - case COMP_STOP: - case COMP_STOP_INVAL: - break; - default: - frame->status = -1; - break; + if (ep->skip) { + /* The transfer is partly done */ + *status = -EXDEV; + td->urb->iso_frame_desc[idx].status = -EXDEV; + } else { + /* handle completion code */ + switch (trb_comp_code) { + case COMP_SUCCESS: + td->urb->iso_frame_desc[idx].status = 0; + xhci_dbg(xhci, "Successful isoc transfer!\n"); + break; + case COMP_SHORT_TX: + if (td->urb->transfer_flags & URB_SHORT_NOT_OK) + td->urb->iso_frame_desc[idx].status = + -EREMOTEIO; + else + td->urb->iso_frame_desc[idx].status = 0; + break; + case COMP_BW_OVER: + td->urb->iso_frame_desc[idx].status = -ECOMM; + skip_td = 1; + break; + case COMP_BUFF_OVER: + case COMP_BABBLE: + td->urb->iso_frame_desc[idx].status = -EOVERFLOW; + skip_td = 1; + break; + case COMP_STALL: + td->urb->iso_frame_desc[idx].status = -EPROTO; + skip_td = 1; + break; + case COMP_STOP: + case COMP_STOP_INVAL: + break; + default: + td->urb->iso_frame_desc[idx].status = -1; + break; + } + } + + /* calc actual length */ + if (ep->skip) { + td->urb->iso_frame_desc[idx].actual_length = 0; + /* Update ring dequeue pointer */ + while (ep_ring->dequeue != td->last_trb) + inc_deq(xhci, ep_ring, false); + inc_deq(xhci, ep_ring, false); + return finish_td(xhci, td, event_trb, event, ep, status, true); } - if (trb_comp_code == COMP_SUCCESS || skip_td) { - frame->actual_length = frame->length; - td->urb->actual_length += frame->length; + if (trb_comp_code == COMP_SUCCESS || skip_td == 1) { + td->urb->iso_frame_desc[idx].actual_length = + td->urb->iso_frame_desc[idx].length; + td->urb->actual_length += + td->urb->iso_frame_desc[idx].length; } else { for (cur_trb = ep_ring->dequeue, cur_seg = ep_ring->deq_seg; cur_trb != event_trb; @@ -1763,7 +1755,7 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, TRB_LEN(event->transfer_len); if (trb_comp_code != COMP_STOP_INVAL) { - frame->actual_length = len; + td->urb->iso_frame_desc[idx].actual_length = len; td->urb->actual_length += len; } } @@ -1774,35 +1766,6 @@ static int process_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, return finish_td(xhci, td, event_trb, event, ep, status, false); } -static int skip_isoc_td(struct xhci_hcd *xhci, struct xhci_td *td, - struct xhci_transfer_event *event, - struct xhci_virt_ep *ep, int *status) -{ - struct xhci_ring *ep_ring; - struct urb_priv *urb_priv; - struct usb_iso_packet_descriptor *frame; - int idx; - - ep_ring = xhci_dma_to_transfer_ring(ep, event->buffer); - urb_priv = td->urb->hcpriv; - idx = urb_priv->td_cnt; - frame = &td->urb->iso_frame_desc[idx]; - - /* The transfer is partly done */ - *status = -EXDEV; - frame->status = -EXDEV; - - /* calc actual length */ - frame->actual_length = 0; - - /* Update ring dequeue pointer */ - while (ep_ring->dequeue != td->last_trb) - inc_deq(xhci, ep_ring, false); - inc_deq(xhci, ep_ring, false); - - return finish_td(xhci, td, NULL, event, ep, status, true); -} - /* * Process bulk and interrupt tds, update urb status and actual_length. */ @@ -2061,42 +2024,36 @@ static int handle_tx_event(struct xhci_hcd *xhci, } td = list_entry(ep_ring->td_list.next, struct xhci_td, td_list); - /* Is this a TRB in the currently executing TD? */ event_seg = trb_in_td(ep_ring->deq_seg, ep_ring->dequeue, td->last_trb, event_dma); - if (!event_seg) { - if (!ep->skip || - !usb_endpoint_xfer_isoc(&td->urb->ep->desc)) { - /* HC is busted, give up! */ - xhci_err(xhci, - "ERROR Transfer event TRB DMA ptr not " - "part of current TD\n"); - return -ESHUTDOWN; - } - - ret = skip_isoc_td(xhci, td, event, ep, &status); - goto cleanup; - } - - if (ep->skip) { + if (event_seg && ep->skip) { xhci_dbg(xhci, "Found td. Clear skip flag.\n"); ep->skip = false; } + if (!event_seg && + (!ep->skip || !usb_endpoint_xfer_isoc(&td->urb->ep->desc))) { + /* HC is busted, give up! */ + xhci_err(xhci, "ERROR Transfer event TRB DMA ptr not " + "part of current TD\n"); + return -ESHUTDOWN; + } - event_trb = &event_seg->trbs[(event_dma - event_seg->dma) / - sizeof(*event_trb)]; - /* - * No-op TRB should not trigger interrupts. - * If event_trb is a no-op TRB, it means the - * corresponding TD has been cancelled. Just ignore - * the TD. - */ - if ((event_trb->generic.field[3] & TRB_TYPE_BITMASK) - == TRB_TYPE(TRB_TR_NOOP)) { - xhci_dbg(xhci, - "event_trb is a no-op TRB. Skip it\n"); - goto cleanup; + if (event_seg) { + event_trb = &event_seg->trbs[(event_dma - + event_seg->dma) / sizeof(*event_trb)]; + /* + * No-op TRB should not trigger interrupts. + * If event_trb is a no-op TRB, it means the + * corresponding TD has been cancelled. Just ignore + * the TD. + */ + if ((event_trb->generic.field[3] & TRB_TYPE_BITMASK) + == TRB_TYPE(TRB_TR_NOOP)) { + xhci_dbg(xhci, "event_trb is a no-op TRB. " + "Skip it\n"); + goto cleanup; + } } /* Now update the urb's actual_length and give back to @@ -3169,12 +3126,6 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags, } } - if (xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs == 0) { - if (xhci->quirks & XHCI_AMD_PLL_FIX) - usb_amd_quirk_pll_disable(); - } - xhci_to_hcd(xhci)->self.bandwidth_isoc_reqs++; - giveback_first_trb(xhci, slot_id, ep_index, urb->stream_id, start_cycle, start_trb); return 0; diff --git a/trunk/drivers/usb/host/xhci.c b/trunk/drivers/usb/host/xhci.c index 81b976e45880..196e0181b2ed 100644 --- a/trunk/drivers/usb/host/xhci.c +++ b/trunk/drivers/usb/host/xhci.c @@ -550,9 +550,6 @@ void xhci_stop(struct usb_hcd *hcd) del_timer_sync(&xhci->event_ring_timer); #endif - if (xhci->quirks & XHCI_AMD_PLL_FIX) - usb_amd_dev_put(); - xhci_dbg(xhci, "// Disabling event ring interrupts\n"); temp = xhci_readl(xhci, &xhci->op_regs->status); xhci_writel(xhci, temp & ~STS_EINT, &xhci->op_regs->status); @@ -774,9 +771,7 @@ int xhci_resume(struct xhci_hcd *xhci, bool hibernated) /* If restore operation fails, re-initialize the HC during resume */ if ((temp & STS_SRE) || hibernated) { - /* Let the USB core know _both_ roothubs lost power. */ - usb_root_hub_lost_power(xhci->main_hcd->self.root_hub); - usb_root_hub_lost_power(xhci->shared_hcd->self.root_hub); + usb_root_hub_lost_power(hcd->self.root_hub); xhci_dbg(xhci, "Stop HCD\n"); xhci_halt(xhci); @@ -2391,18 +2386,10 @@ int xhci_discover_or_reset_device(struct usb_hcd *hcd, struct usb_device *udev) /* Everything but endpoint 0 is disabled, so free or cache the rings. */ last_freed_endpoint = 1; for (i = 1; i < 31; ++i) { - struct xhci_virt_ep *ep = &virt_dev->eps[i]; - - if (ep->ep_state & EP_HAS_STREAMS) { - xhci_free_stream_info(xhci, ep->stream_info); - ep->stream_info = NULL; - ep->ep_state &= ~EP_HAS_STREAMS; - } - - if (ep->ring) { - xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i); - last_freed_endpoint = i; - } + if (!virt_dev->eps[i].ring) + continue; + xhci_free_or_cache_endpoint_ring(xhci, virt_dev, i); + last_freed_endpoint = i; } xhci_dbg(xhci, "Output context after successful reset device cmd:\n"); xhci_dbg_ctx(xhci, virt_dev->out_ctx, last_freed_endpoint); diff --git a/trunk/drivers/usb/host/xhci.h b/trunk/drivers/usb/host/xhci.h index ba1be6b7cc6d..07e263063e37 100644 --- a/trunk/drivers/usb/host/xhci.h +++ b/trunk/drivers/usb/host/xhci.h @@ -30,7 +30,6 @@ /* Code sharing between pci-quirks and xhci hcd */ #include "xhci-ext-caps.h" -#include "pci-quirks.h" /* xHCI PCI Configuration Registers */ #define XHCI_SBRN_OFFSET (0x60) @@ -233,7 +232,7 @@ struct xhci_op_regs { * notification type that matches a bit set in this bit field. */ #define DEV_NOTE_MASK (0xffff) -#define ENABLE_DEV_NOTE(x) (1 << (x)) +#define ENABLE_DEV_NOTE(x) (1 << x) /* Most of the device notification types should only be used for debug. * SW does need to pay attention to function wake notifications. */ @@ -349,9 +348,6 @@ struct xhci_op_regs { /* Initiate a warm port reset - complete when PORT_WRC is '1' */ #define PORT_WR (1 << 31) -/* We mark duplicate entries with -1 */ -#define DUPLICATE_ENTRY ((u8)(-1)) - /* Port Power Management Status and Control - port_power_base bitmasks */ /* Inactivity timer value for transitions into U1, in microseconds. * Timeout can be up to 127us. 0xFF means an infinite timeout. @@ -605,11 +601,11 @@ struct xhci_ep_ctx { #define EP_STATE_STOPPED 3 #define EP_STATE_ERROR 4 /* Mult - Max number of burtst within an interval, in EP companion desc. */ -#define EP_MULT(p) (((p) & 0x3) << 8) +#define EP_MULT(p) ((p & 0x3) << 8) /* bits 10:14 are Max Primary Streams */ /* bit 15 is Linear Stream Array */ /* Interval - period between requests to an endpoint - 125u increments. */ -#define EP_INTERVAL(p) (((p) & 0xff) << 16) +#define EP_INTERVAL(p) ((p & 0xff) << 16) #define EP_INTERVAL_TO_UFRAMES(p) (1 << (((p) >> 16) & 0xff)) #define EP_MAXPSTREAMS_MASK (0x1f << 10) #define EP_MAXPSTREAMS(p) (((p) << 10) & EP_MAXPSTREAMS_MASK) @@ -1280,7 +1276,6 @@ struct xhci_hcd { #define XHCI_LINK_TRB_QUIRK (1 << 0) #define XHCI_RESET_EP_QUIRK (1 << 1) #define XHCI_NEC_HOST (1 << 2) -#define XHCI_AMD_PLL_FIX (1 << 3) /* There are two roothubs to keep track of bus suspend info for */ struct xhci_bus_state bus_state[2]; /* Is each xHCI roothub port a USB 3.0, USB 2.0, or USB 1.1 port? */ diff --git a/trunk/drivers/usb/musb/Kconfig b/trunk/drivers/usb/musb/Kconfig index 74073b363c30..4cbb7e4b368d 100644 --- a/trunk/drivers/usb/musb/Kconfig +++ b/trunk/drivers/usb/musb/Kconfig @@ -14,7 +14,7 @@ config USB_MUSB_HDRC select TWL4030_USB if MACH_OMAP_3430SDP select TWL6030_USB if MACH_OMAP_4430SDP || MACH_OMAP4_PANDA select USB_OTG_UTILS - bool 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' + tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)' help Say Y here if your system has a dual role high speed USB controller based on the Mentor Graphics silicon IP. Then @@ -30,8 +30,8 @@ config USB_MUSB_HDRC If you do not know what this is, please say N. -# To compile this driver as a module, choose M here; the -# module will be called "musb-hdrc". + To compile this driver as a module, choose M here; the + module will be called "musb-hdrc". choice prompt "Platform Glue Layer" diff --git a/trunk/drivers/usb/musb/blackfin.c b/trunk/drivers/usb/musb/blackfin.c index 8e2a1ff8a35a..52312e8af213 100644 --- a/trunk/drivers/usb/musb/blackfin.c +++ b/trunk/drivers/usb/musb/blackfin.c @@ -21,7 +21,6 @@ #include #include "musb_core.h" -#include "musbhsdma.h" #include "blackfin.h" struct bfin_glue { @@ -333,27 +332,6 @@ static int bfin_musb_set_mode(struct musb *musb, u8 musb_mode) return -EIO; } -static int bfin_musb_adjust_channel_params(struct dma_channel *channel, - u16 packet_sz, u8 *mode, - dma_addr_t *dma_addr, u32 *len) -{ - struct musb_dma_channel *musb_channel = channel->private_data; - - /* - * Anomaly 05000450 might cause data corruption when using DMA - * MODE 1 transmits with short packet. So to work around this, - * we truncate all MODE 1 transfers down to a multiple of the - * max packet size, and then do the last short packet transfer - * (if there is any) using MODE 0. - */ - if (ANOMALY_05000450) { - if (musb_channel->transmit && *mode == 1) - *len = *len - (*len % packet_sz); - } - - return 0; -} - static void bfin_musb_reg_init(struct musb *musb) { if (ANOMALY_05000346) { @@ -452,8 +430,6 @@ static const struct musb_platform_ops bfin_ops = { .vbus_status = bfin_musb_vbus_status, .set_vbus = bfin_musb_set_vbus, - - .adjust_channel_params = bfin_musb_adjust_channel_params, }; static u64 bfin_dmamask = DMA_BIT_MASK(32); diff --git a/trunk/drivers/usb/musb/cppi_dma.c b/trunk/drivers/usb/musb/cppi_dma.c index ab434fbd8c35..de55a3c3259a 100644 --- a/trunk/drivers/usb/musb/cppi_dma.c +++ b/trunk/drivers/usb/musb/cppi_dma.c @@ -597,12 +597,12 @@ cppi_next_tx_segment(struct musb *musb, struct cppi_channel *tx) length = min(n_bds * maxpacket, length); } - DBG(4, "TX DMA%d, pktSz %d %s bds %d dma 0x%llx len %u\n", + DBG(4, "TX DMA%d, pktSz %d %s bds %d dma 0x%x len %u\n", tx->index, maxpacket, rndis ? "rndis" : "transparent", n_bds, - (unsigned long long)addr, length); + addr, length); cppi_rndis_update(tx, 0, musb->ctrl_base, rndis); @@ -820,7 +820,7 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket) length = min(n_bds * maxpacket, length); DBG(4, "RX DMA%d seg, maxp %d %s bds %d (cnt %d) " - "dma 0x%llx len %u %u/%u\n", + "dma 0x%x len %u %u/%u\n", rx->index, maxpacket, onepacket ? (is_rndis ? "rndis" : "onepacket") @@ -829,8 +829,7 @@ cppi_next_rx_segment(struct musb *musb, struct cppi_channel *rx, int onepacket) musb_readl(tibase, DAVINCI_RXCPPI_BUFCNT0_REG + (rx->index * 4)) & 0xffff, - (unsigned long long)addr, length, - rx->channel.actual_len, rx->buf_len); + addr, length, rx->channel.actual_len, rx->buf_len); /* only queue one segment at a time, since the hardware prevents * correct queue shutdown after unexpected short packets @@ -1040,9 +1039,9 @@ static bool cppi_rx_scan(struct cppi *cppi, unsigned ch) if (!completed && (bd->hw_options & CPPI_OWN_SET)) break; - DBG(5, "C/RXBD %llx: nxt %08x buf %08x " + DBG(5, "C/RXBD %08x: nxt %08x buf %08x " "off.len %08x opt.len %08x (%d)\n", - (unsigned long long)bd->dma, bd->hw_next, bd->hw_bufp, + bd->dma, bd->hw_next, bd->hw_bufp, bd->hw_off_len, bd->hw_options, rx->channel.actual_len); @@ -1112,12 +1111,11 @@ static bool cppi_rx_scan(struct cppi *cppi, unsigned ch) musb_ep_select(cppi->mregs, rx->index + 1); csr = musb_readw(regs, MUSB_RXCSR); if (csr & MUSB_RXCSR_DMAENAB) { - DBG(4, "list%d %p/%p, last %llx%s, csr %04x\n", + DBG(4, "list%d %p/%p, last %08x%s, csr %04x\n", rx->index, rx->head, rx->tail, rx->last_processed - ? (unsigned long long) - rx->last_processed->dma + ? rx->last_processed->dma : 0, completed ? ", completed" : "", csr); @@ -1169,11 +1167,8 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id) tx = musb_readl(tibase, DAVINCI_TXCPPI_MASKED_REG); rx = musb_readl(tibase, DAVINCI_RXCPPI_MASKED_REG); - if (!tx && !rx) { - if (cppi->irq) - spin_unlock_irqrestore(&musb->lock, flags); + if (!tx && !rx) return IRQ_NONE; - } DBG(4, "CPPI IRQ Tx%x Rx%x\n", tx, rx); @@ -1204,7 +1199,7 @@ irqreturn_t cppi_interrupt(int irq, void *dev_id) */ if (NULL == bd) { DBG(1, "null BD\n"); - musb_writel(&tx_ram->tx_complete, 0, 0); + tx_ram->tx_complete = 0; continue; } @@ -1457,7 +1452,7 @@ static int cppi_channel_abort(struct dma_channel *channel) * compare mode by writing 1 to the tx_complete register. */ cppi_reset_tx(tx_ram, 1); - cppi_ch->head = NULL; + cppi_ch->head = 0; musb_writel(&tx_ram->tx_complete, 0, 1); cppi_dump_tx(5, cppi_ch, " (done teardown)"); diff --git a/trunk/drivers/usb/musb/musb_core.c b/trunk/drivers/usb/musb/musb_core.c index f10ff00ca09e..630ae7f3cd4c 100644 --- a/trunk/drivers/usb/musb/musb_core.c +++ b/trunk/drivers/usb/musb/musb_core.c @@ -1030,7 +1030,6 @@ static void musb_shutdown(struct platform_device *pdev) struct musb *musb = dev_to_musb(&pdev->dev); unsigned long flags; - pm_runtime_get_sync(musb->controller); spin_lock_irqsave(&musb->lock, flags); musb_platform_disable(musb); musb_generic_disable(musb); @@ -1041,7 +1040,6 @@ static void musb_shutdown(struct platform_device *pdev) musb_writeb(musb->mregs, MUSB_DEVCTL, 0); musb_platform_exit(musb); - pm_runtime_put(musb->controller); /* FIXME power down */ } diff --git a/trunk/drivers/usb/musb/musb_core.h b/trunk/drivers/usb/musb/musb_core.h index 0e053b587960..4bd9e2145ee4 100644 --- a/trunk/drivers/usb/musb/musb_core.h +++ b/trunk/drivers/usb/musb/musb_core.h @@ -261,7 +261,6 @@ enum musb_g_ep0_state { * @try_ilde: tries to idle the IP * @vbus_status: returns vbus status if possible * @set_vbus: forces vbus status - * @channel_program: pre check for standard dma channel_program func */ struct musb_platform_ops { int (*init)(struct musb *musb); @@ -275,10 +274,6 @@ struct musb_platform_ops { int (*vbus_status)(struct musb *musb); void (*set_vbus)(struct musb *musb, int on); - - int (*adjust_channel_params)(struct dma_channel *channel, - u16 packet_sz, u8 *mode, - dma_addr_t *dma_addr, u32 *len); }; /* diff --git a/trunk/drivers/usb/musb/musb_gadget.c b/trunk/drivers/usb/musb/musb_gadget.c index 6dfbf9ffd7a6..98519c5d8b5c 100644 --- a/trunk/drivers/usb/musb/musb_gadget.c +++ b/trunk/drivers/usb/musb/musb_gadget.c @@ -535,7 +535,7 @@ void musb_g_tx(struct musb *musb, u8 epnum) is_dma = 1; csr |= MUSB_TXCSR_P_WZC_BITS; csr &= ~(MUSB_TXCSR_DMAENAB | MUSB_TXCSR_P_UNDERRUN | - MUSB_TXCSR_TXPKTRDY | MUSB_TXCSR_AUTOSET); + MUSB_TXCSR_TXPKTRDY); musb_writew(epio, MUSB_TXCSR, csr); /* Ensure writebuffer is empty. */ csr = musb_readw(epio, MUSB_TXCSR); @@ -1296,7 +1296,7 @@ static int musb_gadget_dequeue(struct usb_ep *ep, struct usb_request *request) } /* if the hardware doesn't have the request, easy ... */ - if (musb_ep->req_list.next != &req->list || musb_ep->busy) + if (musb_ep->req_list.next != &request->list || musb_ep->busy) musb_g_giveback(musb_ep, request, -ECONNRESET); /* ... else abort the dma transfer ... */ diff --git a/trunk/drivers/usb/musb/musbhsdma.c b/trunk/drivers/usb/musb/musbhsdma.c index d281792db05c..0144a2d481fd 100644 --- a/trunk/drivers/usb/musb/musbhsdma.c +++ b/trunk/drivers/usb/musb/musbhsdma.c @@ -169,14 +169,6 @@ static int dma_channel_program(struct dma_channel *channel, BUG_ON(channel->status == MUSB_DMA_STATUS_UNKNOWN || channel->status == MUSB_DMA_STATUS_BUSY); - /* Let targets check/tweak the arguments */ - if (musb->ops->adjust_channel_params) { - int ret = musb->ops->adjust_channel_params(channel, - packet_sz, &mode, &dma_addr, &len); - if (ret) - return ret; - } - /* * The DMA engine in RTL1.8 and above cannot handle * DMA addresses that are not aligned to a 4 byte boundary. diff --git a/trunk/drivers/usb/musb/omap2430.c b/trunk/drivers/usb/musb/omap2430.c index 57a27fa954b4..25cb8b0003b1 100644 --- a/trunk/drivers/usb/musb/omap2430.c +++ b/trunk/drivers/usb/musb/omap2430.c @@ -259,10 +259,9 @@ static int musb_otg_notifications(struct notifier_block *nb, case USB_EVENT_VBUS: DBG(4, "VBUS Connect\n"); -#ifdef CONFIG_USB_GADGET_MUSB_HDRC if (musb->gadget_driver) pm_runtime_get_sync(musb->controller); -#endif + otg_init(musb->xceiv); break; diff --git a/trunk/drivers/usb/musb/ux500.c b/trunk/drivers/usb/musb/ux500.c index f7e04bf34a13..d6384e4aeef9 100644 --- a/trunk/drivers/usb/musb/ux500.c +++ b/trunk/drivers/usb/musb/ux500.c @@ -93,8 +93,6 @@ static int __init ux500_probe(struct platform_device *pdev) } musb->dev.parent = &pdev->dev; - musb->dev.dma_mask = pdev->dev.dma_mask; - musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask; glue->dev = &pdev->dev; glue->musb = musb; diff --git a/trunk/drivers/usb/serial/ftdi_sio.c b/trunk/drivers/usb/serial/ftdi_sio.c index 4de6ef0ae52a..a973c7a29d6e 100644 --- a/trunk/drivers/usb/serial/ftdi_sio.c +++ b/trunk/drivers/usb/serial/ftdi_sio.c @@ -151,8 +151,6 @@ static struct ftdi_sio_quirk ftdi_stmclite_quirk = { * /sys/bus/usb/ftdi_sio/new_id, then send patch/report! */ static struct usb_device_id id_table_combined [] = { - { USB_DEVICE(FTDI_VID, FTDI_CTI_MINI_PID) }, - { USB_DEVICE(FTDI_VID, FTDI_CTI_NANO_PID) }, { USB_DEVICE(FTDI_VID, FTDI_AMC232_PID) }, { USB_DEVICE(FTDI_VID, FTDI_CANUSB_PID) }, { USB_DEVICE(FTDI_VID, FTDI_CANDAPTER_PID) }, @@ -527,7 +525,6 @@ static struct usb_device_id id_table_combined [] = { { USB_DEVICE(SEALEVEL_VID, SEALEVEL_2803_8_PID) }, { USB_DEVICE(IDTECH_VID, IDTECH_IDT1221U_PID) }, { USB_DEVICE(OCT_VID, OCT_US101_PID) }, - { USB_DEVICE(OCT_VID, OCT_DK201_PID) }, { USB_DEVICE(FTDI_VID, FTDI_HE_TIRA1_PID), .driver_info = (kernel_ulong_t)&ftdi_HE_TIRA1_quirk }, { USB_DEVICE(FTDI_VID, FTDI_USB_UIRT_PID), @@ -790,8 +787,6 @@ static struct usb_device_id id_table_combined [] = { { USB_DEVICE(FTDI_VID, MARVELL_OPENRD_PID), .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, { USB_DEVICE(FTDI_VID, HAMEG_HO820_PID) }, - { USB_DEVICE(FTDI_VID, HAMEG_HO720_PID) }, - { USB_DEVICE(FTDI_VID, HAMEG_HO730_PID) }, { USB_DEVICE(FTDI_VID, HAMEG_HO870_PID) }, { USB_DEVICE(FTDI_VID, MJSG_GENERIC_PID) }, { USB_DEVICE(FTDI_VID, MJSG_SR_RADIO_PID) }, diff --git a/trunk/drivers/usb/serial/ftdi_sio_ids.h b/trunk/drivers/usb/serial/ftdi_sio_ids.h index efffc23723bd..c543e55bafba 100644 --- a/trunk/drivers/usb/serial/ftdi_sio_ids.h +++ b/trunk/drivers/usb/serial/ftdi_sio_ids.h @@ -300,8 +300,6 @@ * Hameg HO820 and HO870 interface (using VID 0x0403) */ #define HAMEG_HO820_PID 0xed74 -#define HAMEG_HO730_PID 0xed73 -#define HAMEG_HO720_PID 0xed72 #define HAMEG_HO870_PID 0xed71 /* @@ -574,7 +572,6 @@ /* Note: OCT US101 is also rebadged as Dick Smith Electronics (NZ) XH6381 */ /* Also rebadged as Dick Smith Electronics (Aus) XH6451 */ /* Also rebadged as SIIG Inc. model US2308 hardware version 1 */ -#define OCT_DK201_PID 0x0103 /* OCT DK201 USB docking station */ #define OCT_US101_PID 0x0421 /* OCT US101 USB to RS-232 */ /* @@ -1144,12 +1141,3 @@ #define QIHARDWARE_VID 0x20B7 #define MILKYMISTONE_JTAGSERIAL_PID 0x0713 -/* - * CTI GmbH RS485 Converter http://www.cti-lean.com/ - */ -/* USB-485-Mini*/ -#define FTDI_CTI_MINI_PID 0xF608 -/* USB-Nano-485*/ -#define FTDI_CTI_NANO_PID 0xF60B - - diff --git a/trunk/drivers/usb/serial/option.c b/trunk/drivers/usb/serial/option.c index d77ff0435896..75c7f456eed5 100644 --- a/trunk/drivers/usb/serial/option.c +++ b/trunk/drivers/usb/serial/option.c @@ -407,10 +407,6 @@ static void option_instat_callback(struct urb *urb); /* ONDA MT825UP HSDPA 14.2 modem */ #define ONDA_MT825UP 0x000b -/* Samsung products */ -#define SAMSUNG_VENDOR_ID 0x04e8 -#define SAMSUNG_PRODUCT_GT_B3730 0x6889 - /* some devices interfaces need special handling due to a number of reasons */ enum option_blacklist_reason { OPTION_BLACKLIST_NONE = 0, @@ -972,7 +968,6 @@ static const struct usb_device_id option_ids[] = { { USB_DEVICE(OLIVETTI_VENDOR_ID, OLIVETTI_PRODUCT_OLICARD100) }, { USB_DEVICE(CELOT_VENDOR_ID, CELOT_PRODUCT_CT680M) }, /* CT-650 CDMA 450 1xEVDO modem */ { USB_DEVICE(ONDA_VENDOR_ID, ONDA_MT825UP) }, /* ONDA MT825UP modem */ - { USB_DEVICE_AND_INTERFACE_INFO(SAMSUNG_VENDOR_ID, SAMSUNG_PRODUCT_GT_B3730, USB_CLASS_CDC_DATA, 0x00, 0x00) }, /* Samsung GT-B3730/GT-B3710 LTE USB modem.*/ { } /* Terminating entry */ }; MODULE_DEVICE_TABLE(usb, option_ids); diff --git a/trunk/drivers/usb/serial/qcserial.c b/trunk/drivers/usb/serial/qcserial.c index 54a9dab1f33b..8858201eb1d3 100644 --- a/trunk/drivers/usb/serial/qcserial.c +++ b/trunk/drivers/usb/serial/qcserial.c @@ -111,7 +111,7 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) ifnum = intf->desc.bInterfaceNumber; dbg("This Interface = %d", ifnum); - data = kzalloc(sizeof(struct usb_wwan_intf_private), + data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL); if (!data) return -ENOMEM; @@ -134,10 +134,8 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) { dbg("QDL port found"); - if (serial->interface->num_altsetting == 1) { - retval = 0; /* Success */ - break; - } + if (serial->interface->num_altsetting == 1) + return 0; retval = usb_set_interface(serial->dev, ifnum, 1); if (retval < 0) { @@ -147,6 +145,7 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) retval = -ENODEV; kfree(data); } + return retval; } break; @@ -167,7 +166,6 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) "Could not set interface, error %d\n", retval); retval = -ENODEV; - kfree(data); } } else if (ifnum == 2) { dbg("Modem port found"); @@ -179,6 +177,7 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) retval = -ENODEV; kfree(data); } + return retval; } else if (ifnum==3) { /* * NMEA (serial line 9600 8N1) @@ -192,7 +191,6 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) "Could not set interface, error %d\n", retval); retval = -ENODEV; - kfree(data); } } break; @@ -201,27 +199,12 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) dev_err(&serial->dev->dev, "unknown number of interfaces: %d\n", nintf); kfree(data); - retval = -ENODEV; + return -ENODEV; } - /* Set serial->private if not returning -ENODEV */ - if (retval != -ENODEV) - usb_set_serial_data(serial, data); return retval; } -static void qc_release(struct usb_serial *serial) -{ - struct usb_wwan_intf_private *priv = usb_get_serial_data(serial); - - dbg("%s", __func__); - - /* Call usb_wwan release & free the private data allocated in qcprobe */ - usb_wwan_release(serial); - usb_set_serial_data(serial, NULL); - kfree(priv); -} - static struct usb_serial_driver qcdevice = { .driver = { .owner = THIS_MODULE, @@ -239,7 +222,7 @@ static struct usb_serial_driver qcdevice = { .chars_in_buffer = usb_wwan_chars_in_buffer, .attach = usb_wwan_startup, .disconnect = usb_wwan_disconnect, - .release = qc_release, + .release = usb_wwan_release, #ifdef CONFIG_PM .suspend = usb_wwan_suspend, .resume = usb_wwan_resume, diff --git a/trunk/drivers/video/pxafb.c b/trunk/drivers/video/pxafb.c index 0f4e8c942f9e..a2e5b5100ab4 100644 --- a/trunk/drivers/video/pxafb.c +++ b/trunk/drivers/video/pxafb.c @@ -1648,9 +1648,7 @@ pxafb_freq_transition(struct notifier_block *nb, unsigned long val, void *data) switch (val) { case CPUFREQ_PRECHANGE: -#ifdef CONFIG_FB_PXA_OVERLAY - if (!(fbi->overlay[0].usage || fbi->overlay[1].usage)) -#endif + if (!fbi->overlay[0].usage && !fbi->overlay[1].usage) set_ctrlr_state(fbi, C_DISABLE_CLKCHANGE); break; diff --git a/trunk/drivers/xen/events.c b/trunk/drivers/xen/events.c index 33167b43ac7e..42d6c930cc87 100644 --- a/trunk/drivers/xen/events.c +++ b/trunk/drivers/xen/events.c @@ -912,7 +912,8 @@ int bind_evtchn_to_irqhandler(unsigned int evtchn, unsigned long irqflags, const char *devname, void *dev_id) { - int irq, retval; + unsigned int irq; + int retval; irq = bind_evtchn_to_irq(evtchn); if (irq < 0) @@ -954,7 +955,8 @@ int bind_virq_to_irqhandler(unsigned int virq, unsigned int cpu, irq_handler_t handler, unsigned long irqflags, const char *devname, void *dev_id) { - int irq, retval; + unsigned int irq; + int retval; irq = bind_virq_to_irq(virq, cpu); if (irq < 0) diff --git a/trunk/drivers/xen/manage.c b/trunk/drivers/xen/manage.c index 1ac94125bf93..95143dd6904d 100644 --- a/trunk/drivers/xen/manage.c +++ b/trunk/drivers/xen/manage.c @@ -61,7 +61,7 @@ static void xen_post_suspend(int cancelled) xen_mm_unpin_all(); } -#ifdef CONFIG_HIBERNATE_CALLBACKS +#ifdef CONFIG_HIBERNATION static int xen_suspend(void *data) { struct suspend_info *si = data; @@ -173,7 +173,7 @@ static void do_suspend(void) #endif shutting_down = SHUTDOWN_INVALID; } -#endif /* CONFIG_HIBERNATE_CALLBACKS */ +#endif /* CONFIG_HIBERNATION */ struct shutdown_handler { const char *command; @@ -202,7 +202,7 @@ static void shutdown_handler(struct xenbus_watch *watch, { "poweroff", do_poweroff }, { "halt", do_poweroff }, { "reboot", do_reboot }, -#ifdef CONFIG_HIBERNATE_CALLBACKS +#ifdef CONFIG_HIBERNATION { "suspend", do_suspend }, #endif {NULL, NULL}, diff --git a/trunk/fs/9p/fid.c b/trunk/fs/9p/fid.c index 85b67ffa2a43..0ee594569dcc 100644 --- a/trunk/fs/9p/fid.c +++ b/trunk/fs/9p/fid.c @@ -286,9 +286,11 @@ static struct p9_fid *v9fs_fid_clone_with_uid(struct dentry *dentry, uid_t uid) struct p9_fid *v9fs_writeback_fid(struct dentry *dentry) { - int err; + int err, flags; struct p9_fid *fid; + struct v9fs_session_info *v9ses; + v9ses = v9fs_dentry2v9ses(dentry); fid = v9fs_fid_clone_with_uid(dentry, 0); if (IS_ERR(fid)) goto error_out; @@ -297,8 +299,17 @@ struct p9_fid *v9fs_writeback_fid(struct dentry *dentry) * dirty pages. We always request for the open fid in read-write * mode so that a partial page write which result in page * read can work. + * + * we don't have a tsyncfs operation for older version + * of protocol. So make sure the write back fid is + * opened in O_SYNC mode. */ - err = p9_client_open(fid, O_RDWR); + if (!v9fs_proto_dotl(v9ses)) + flags = O_RDWR | O_SYNC; + else + flags = O_RDWR; + + err = p9_client_open(fid, flags); if (err < 0) { p9_client_clunk(fid); fid = ERR_PTR(err); diff --git a/trunk/fs/9p/v9fs.h b/trunk/fs/9p/v9fs.h index e5ebedfc5ed8..9665c2b840e6 100644 --- a/trunk/fs/9p/v9fs.h +++ b/trunk/fs/9p/v9fs.h @@ -116,6 +116,7 @@ struct v9fs_session_info { struct list_head slist; /* list of sessions registered with v9fs */ struct backing_dev_info bdi; struct rw_semaphore rename_sem; + struct p9_fid *root_fid; /* Used for file system sync */ }; /* cache_validity flags */ diff --git a/trunk/fs/9p/vfs_dentry.c b/trunk/fs/9p/vfs_dentry.c index e022890c6f40..b6a3b9f7fe4d 100644 --- a/trunk/fs/9p/vfs_dentry.c +++ b/trunk/fs/9p/vfs_dentry.c @@ -126,9 +126,7 @@ static int v9fs_lookup_revalidate(struct dentry *dentry, struct nameidata *nd) retval = v9fs_refresh_inode_dotl(fid, inode); else retval = v9fs_refresh_inode(fid, inode); - if (retval == -ENOENT) - return 0; - if (retval < 0) + if (retval <= 0) return retval; } out_valid: diff --git a/trunk/fs/9p/vfs_inode_dotl.c b/trunk/fs/9p/vfs_inode_dotl.c index 82a7c38ddad0..ffbb113d5f33 100644 --- a/trunk/fs/9p/vfs_inode_dotl.c +++ b/trunk/fs/9p/vfs_inode_dotl.c @@ -811,7 +811,7 @@ v9fs_vfs_follow_link_dotl(struct dentry *dentry, struct nameidata *nd) fid = v9fs_fid_lookup(dentry); if (IS_ERR(fid)) { __putname(link); - link = ERR_CAST(fid); + link = ERR_PTR(PTR_ERR(fid)); goto ndset; } retval = p9_client_readlink(fid, &target); diff --git a/trunk/fs/9p/vfs_super.c b/trunk/fs/9p/vfs_super.c index feef6cdc1fd2..f3eed3383e4f 100644 --- a/trunk/fs/9p/vfs_super.c +++ b/trunk/fs/9p/vfs_super.c @@ -154,7 +154,6 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags, retval = PTR_ERR(inode); goto release_sb; } - root = d_alloc_root(inode); if (!root) { iput(inode); @@ -186,10 +185,21 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags, p9stat_free(st); kfree(st); } + v9fs_fid_add(root, fid); retval = v9fs_get_acl(inode, fid); if (retval) goto release_sb; - v9fs_fid_add(root, fid); + /* + * Add the root fid to session info. This is used + * for file system sync. We want a cloned fid here + * so that we can do a sync_filesystem after a + * shrink_dcache_for_umount + */ + v9ses->root_fid = v9fs_fid_clone(root); + if (IS_ERR(v9ses->root_fid)) { + retval = PTR_ERR(v9ses->root_fid); + goto release_sb; + } P9_DPRINTK(P9_DEBUG_VFS, " simple set mount, return 0\n"); return dget(sb->s_root); @@ -200,15 +210,11 @@ static struct dentry *v9fs_mount(struct file_system_type *fs_type, int flags, v9fs_session_close(v9ses); kfree(v9ses); return ERR_PTR(retval); - release_sb: /* - * we will do the session_close and root dentry release - * in the below call. But we need to clunk fid, because we haven't - * attached the fid to dentry so it won't get clunked - * automatically. + * we will do the session_close and root dentry + * release in the below call. */ - p9_client_clunk(fid); deactivate_locked_super(sb); return ERR_PTR(retval); } @@ -226,7 +232,7 @@ static void v9fs_kill_super(struct super_block *s) P9_DPRINTK(P9_DEBUG_VFS, " %p\n", s); kill_anon_super(s); - + p9_client_clunk(v9ses->root_fid); v9fs_session_cancel(v9ses); v9fs_session_close(v9ses); kfree(v9ses); @@ -279,6 +285,14 @@ static int v9fs_statfs(struct dentry *dentry, struct kstatfs *buf) return res; } +static int v9fs_sync_fs(struct super_block *sb, int wait) +{ + struct v9fs_session_info *v9ses = sb->s_fs_info; + + P9_DPRINTK(P9_DEBUG_VFS, "v9fs_sync_fs: super_block %p\n", sb); + return p9_client_sync_fs(v9ses->root_fid); +} + static int v9fs_drop_inode(struct inode *inode) { struct v9fs_session_info *v9ses; @@ -293,51 +307,6 @@ static int v9fs_drop_inode(struct inode *inode) return 1; } -static int v9fs_write_inode(struct inode *inode, - struct writeback_control *wbc) -{ - int ret; - struct p9_wstat wstat; - struct v9fs_inode *v9inode; - /* - * send an fsync request to server irrespective of - * wbc->sync_mode. - */ - P9_DPRINTK(P9_DEBUG_VFS, "%s: inode %p\n", __func__, inode); - v9inode = V9FS_I(inode); - if (!v9inode->writeback_fid) - return 0; - v9fs_blank_wstat(&wstat); - - ret = p9_client_wstat(v9inode->writeback_fid, &wstat); - if (ret < 0) { - __mark_inode_dirty(inode, I_DIRTY_DATASYNC); - return ret; - } - return 0; -} - -static int v9fs_write_inode_dotl(struct inode *inode, - struct writeback_control *wbc) -{ - int ret; - struct v9fs_inode *v9inode; - /* - * send an fsync request to server irrespective of - * wbc->sync_mode. - */ - P9_DPRINTK(P9_DEBUG_VFS, "%s: inode %p\n", __func__, inode); - v9inode = V9FS_I(inode); - if (!v9inode->writeback_fid) - return 0; - ret = p9_client_fsync(v9inode->writeback_fid, 0); - if (ret < 0) { - __mark_inode_dirty(inode, I_DIRTY_DATASYNC); - return ret; - } - return 0; -} - static const struct super_operations v9fs_super_ops = { .alloc_inode = v9fs_alloc_inode, .destroy_inode = v9fs_destroy_inode, @@ -345,18 +314,17 @@ static const struct super_operations v9fs_super_ops = { .evict_inode = v9fs_evict_inode, .show_options = generic_show_options, .umount_begin = v9fs_umount_begin, - .write_inode = v9fs_write_inode, }; static const struct super_operations v9fs_super_ops_dotl = { .alloc_inode = v9fs_alloc_inode, .destroy_inode = v9fs_destroy_inode, + .sync_fs = v9fs_sync_fs, .statfs = v9fs_statfs, .drop_inode = v9fs_drop_inode, .evict_inode = v9fs_evict_inode, .show_options = generic_show_options, .umount_begin = v9fs_umount_begin, - .write_inode = v9fs_write_inode_dotl, }; struct file_system_type v9fs_fs_type = { diff --git a/trunk/fs/binfmt_elf.c b/trunk/fs/binfmt_elf.c index 303983fabfd6..f34078d702d3 100644 --- a/trunk/fs/binfmt_elf.c +++ b/trunk/fs/binfmt_elf.c @@ -941,13 +941,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs) current->mm->start_stack = bprm->p; #ifdef arch_randomize_brk - if ((current->flags & PF_RANDOMIZE) && (randomize_va_space > 1)) { + if ((current->flags & PF_RANDOMIZE) && (randomize_va_space > 1)) current->mm->brk = current->mm->start_brk = arch_randomize_brk(current->mm); -#ifdef CONFIG_COMPAT_BRK - current->brk_randomized = 1; -#endif - } #endif if (current->personality & MMAP_PAGE_ZERO) { diff --git a/trunk/fs/btrfs/acl.c b/trunk/fs/btrfs/acl.c index 5d505aaa72fb..de34bfad9ec3 100644 --- a/trunk/fs/btrfs/acl.c +++ b/trunk/fs/btrfs/acl.c @@ -178,17 +178,16 @@ static int btrfs_xattr_acl_set(struct dentry *dentry, const char *name, if (value) { acl = posix_acl_from_xattr(value, size); - if (acl) { - ret = posix_acl_valid(acl); - if (ret) - goto out; + if (acl == NULL) { + value = NULL; + size = 0; } else if (IS_ERR(acl)) { return PTR_ERR(acl); } } ret = btrfs_set_acl(NULL, dentry->d_inode, acl, type); -out: + posix_acl_release(acl); return ret; diff --git a/trunk/fs/btrfs/ctree.h b/trunk/fs/btrfs/ctree.h index 2e61fe1b6b8c..3458b5725540 100644 --- a/trunk/fs/btrfs/ctree.h +++ b/trunk/fs/btrfs/ctree.h @@ -740,10 +740,8 @@ struct btrfs_space_info { */ unsigned long reservation_progress; - int full:1; /* indicates that we cannot allocate any more + int full; /* indicates that we cannot allocate any more chunks for this space */ - int chunk_alloc:1; /* set if we are allocating a chunk */ - int force_alloc; /* set if we need to force a chunk alloc for this space */ @@ -2578,11 +2576,6 @@ int btrfs_drop_extents(struct btrfs_trans_handle *trans, struct inode *inode, int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, struct inode *inode, u64 start, u64 end); int btrfs_release_file(struct inode *inode, struct file *file); -void btrfs_drop_pages(struct page **pages, size_t num_pages); -int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode, - struct page **pages, size_t num_pages, - loff_t pos, size_t write_bytes, - struct extent_state **cached); /* tree-defrag.c */ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, diff --git a/trunk/fs/btrfs/disk-io.c b/trunk/fs/btrfs/disk-io.c index 68c84c8c24bd..8f1d44ba332f 100644 --- a/trunk/fs/btrfs/disk-io.c +++ b/trunk/fs/btrfs/disk-io.c @@ -3057,7 +3057,7 @@ static int btrfs_cleanup_transaction(struct btrfs_root *root) btrfs_destroy_pinned_extent(root, root->fs_info->pinned_extents); - atomic_set(&t->use_count, 0); + t->use_count = 0; list_del_init(&t->list); memset(t, 0, sizeof(*t)); kmem_cache_free(btrfs_transaction_cachep, t); diff --git a/trunk/fs/btrfs/extent-tree.c b/trunk/fs/btrfs/extent-tree.c index 31f33ba56fe8..f619c3cb13b7 100644 --- a/trunk/fs/btrfs/extent-tree.c +++ b/trunk/fs/btrfs/extent-tree.c @@ -33,25 +33,6 @@ #include "locking.h" #include "free-space-cache.h" -/* control flags for do_chunk_alloc's force field - * CHUNK_ALLOC_NO_FORCE means to only allocate a chunk - * if we really need one. - * - * CHUNK_ALLOC_FORCE means it must try to allocate one - * - * CHUNK_ALLOC_LIMITED means to only try and allocate one - * if we have very few chunks already allocated. This is - * used as part of the clustering code to help make sure - * we have a good pool of storage to cluster in, without - * filling the FS with empty chunks - * - */ -enum { - CHUNK_ALLOC_NO_FORCE = 0, - CHUNK_ALLOC_FORCE = 1, - CHUNK_ALLOC_LIMITED = 2, -}; - static int update_block_group(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 bytenr, u64 num_bytes, int alloc); @@ -3038,8 +3019,7 @@ static int update_space_info(struct btrfs_fs_info *info, u64 flags, found->bytes_readonly = 0; found->bytes_may_use = 0; found->full = 0; - found->force_alloc = CHUNK_ALLOC_NO_FORCE; - found->chunk_alloc = 0; + found->force_alloc = 0; *space_info = found; list_add_rcu(&found->list, &info->space_info); atomic_set(&found->caching_threads, 0); @@ -3170,7 +3150,7 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes) if (!data_sinfo->full && alloc_chunk) { u64 alloc_target; - data_sinfo->force_alloc = CHUNK_ALLOC_FORCE; + data_sinfo->force_alloc = 1; spin_unlock(&data_sinfo->lock); alloc: alloc_target = btrfs_get_alloc_profile(root, 1); @@ -3180,8 +3160,7 @@ int btrfs_check_data_free_space(struct inode *inode, u64 bytes) ret = do_chunk_alloc(trans, root->fs_info->extent_root, bytes + 2 * 1024 * 1024, - alloc_target, - CHUNK_ALLOC_NO_FORCE); + alloc_target, 0); btrfs_end_transaction(trans, root); if (ret < 0) { if (ret != -ENOSPC) @@ -3260,56 +3239,31 @@ static void force_metadata_allocation(struct btrfs_fs_info *info) rcu_read_lock(); list_for_each_entry_rcu(found, head, list) { if (found->flags & BTRFS_BLOCK_GROUP_METADATA) - found->force_alloc = CHUNK_ALLOC_FORCE; + found->force_alloc = 1; } rcu_read_unlock(); } static int should_alloc_chunk(struct btrfs_root *root, - struct btrfs_space_info *sinfo, u64 alloc_bytes, - int force) + struct btrfs_space_info *sinfo, u64 alloc_bytes) { u64 num_bytes = sinfo->total_bytes - sinfo->bytes_readonly; - u64 num_allocated = sinfo->bytes_used + sinfo->bytes_reserved; u64 thresh; - if (force == CHUNK_ALLOC_FORCE) - return 1; - - /* - * in limited mode, we want to have some free space up to - * about 1% of the FS size. - */ - if (force == CHUNK_ALLOC_LIMITED) { - thresh = btrfs_super_total_bytes(&root->fs_info->super_copy); - thresh = max_t(u64, 64 * 1024 * 1024, - div_factor_fine(thresh, 1)); - - if (num_bytes - num_allocated < thresh) - return 1; - } - - /* - * we have two similar checks here, one based on percentage - * and once based on a hard number of 256MB. The idea - * is that if we have a good amount of free - * room, don't allocate a chunk. A good mount is - * less than 80% utilized of the chunks we have allocated, - * or more than 256MB free - */ - if (num_allocated + alloc_bytes + 256 * 1024 * 1024 < num_bytes) + if (sinfo->bytes_used + sinfo->bytes_reserved + + alloc_bytes + 256 * 1024 * 1024 < num_bytes) return 0; - if (num_allocated + alloc_bytes < div_factor(num_bytes, 8)) + if (sinfo->bytes_used + sinfo->bytes_reserved + + alloc_bytes < div_factor(num_bytes, 8)) return 0; thresh = btrfs_super_total_bytes(&root->fs_info->super_copy); - - /* 256MB or 5% of the FS */ thresh = max_t(u64, 256 * 1024 * 1024, div_factor_fine(thresh, 5)); if (num_bytes > thresh && sinfo->bytes_used < div_factor(num_bytes, 3)) return 0; + return 1; } @@ -3319,9 +3273,10 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, { struct btrfs_space_info *space_info; struct btrfs_fs_info *fs_info = extent_root->fs_info; - int wait_for_alloc = 0; int ret = 0; + mutex_lock(&fs_info->chunk_mutex); + flags = btrfs_reduce_alloc_profile(extent_root, flags); space_info = __find_space_info(extent_root->fs_info, flags); @@ -3332,40 +3287,21 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, } BUG_ON(!space_info); -again: spin_lock(&space_info->lock); if (space_info->force_alloc) - force = space_info->force_alloc; + force = 1; if (space_info->full) { spin_unlock(&space_info->lock); - return 0; + goto out; } - if (!should_alloc_chunk(extent_root, space_info, alloc_bytes, force)) { + if (!force && !should_alloc_chunk(extent_root, space_info, + alloc_bytes)) { spin_unlock(&space_info->lock); - return 0; - } else if (space_info->chunk_alloc) { - wait_for_alloc = 1; - } else { - space_info->chunk_alloc = 1; + goto out; } - spin_unlock(&space_info->lock); - mutex_lock(&fs_info->chunk_mutex); - - /* - * The chunk_mutex is held throughout the entirety of a chunk - * allocation, so once we've acquired the chunk_mutex we know that the - * other guy is done and we need to recheck and see if we should - * allocate. - */ - if (wait_for_alloc) { - mutex_unlock(&fs_info->chunk_mutex); - wait_for_alloc = 0; - goto again; - } - /* * If we have mixed data/metadata chunks we want to make sure we keep * allocating mixed chunks instead of individual chunks. @@ -3391,10 +3327,9 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans, space_info->full = 1; else ret = 1; - - space_info->force_alloc = CHUNK_ALLOC_NO_FORCE; - space_info->chunk_alloc = 0; + space_info->force_alloc = 0; spin_unlock(&space_info->lock); +out: mutex_unlock(&extent_root->fs_info->chunk_mutex); return ret; } @@ -5368,13 +5303,11 @@ static noinline int find_free_extent(struct btrfs_trans_handle *trans, if (allowed_chunk_alloc) { ret = do_chunk_alloc(trans, root, num_bytes + - 2 * 1024 * 1024, data, - CHUNK_ALLOC_LIMITED); + 2 * 1024 * 1024, data, 1); allowed_chunk_alloc = 0; done_chunk_alloc = 1; - } else if (!done_chunk_alloc && - space_info->force_alloc == CHUNK_ALLOC_NO_FORCE) { - space_info->force_alloc = CHUNK_ALLOC_LIMITED; + } else if (!done_chunk_alloc) { + space_info->force_alloc = 1; } if (loop < LOOP_NO_EMPTY_SIZE) { @@ -5460,8 +5393,7 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, */ if (empty_size || root->ref_cows) ret = do_chunk_alloc(trans, root->fs_info->extent_root, - num_bytes + 2 * 1024 * 1024, data, - CHUNK_ALLOC_NO_FORCE); + num_bytes + 2 * 1024 * 1024, data, 0); WARN_ON(num_bytes < root->sectorsize); ret = find_free_extent(trans, root, num_bytes, empty_size, @@ -5473,7 +5405,7 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, num_bytes = num_bytes & ~(root->sectorsize - 1); num_bytes = max(num_bytes, min_alloc_size); do_chunk_alloc(trans, root->fs_info->extent_root, - num_bytes, data, CHUNK_ALLOC_FORCE); + num_bytes, data, 1); goto again; } if (ret == -ENOSPC && btrfs_test_opt(root, ENOSPC_DEBUG)) { @@ -8177,15 +8109,13 @@ int btrfs_set_block_group_ro(struct btrfs_root *root, alloc_flags = update_block_group_flags(root, cache->flags); if (alloc_flags != cache->flags) - do_chunk_alloc(trans, root, 2 * 1024 * 1024, alloc_flags, - CHUNK_ALLOC_FORCE); + do_chunk_alloc(trans, root, 2 * 1024 * 1024, alloc_flags, 1); ret = set_block_group_ro(cache); if (!ret) goto out; alloc_flags = get_alloc_profile(root, cache->space_info->flags); - ret = do_chunk_alloc(trans, root, 2 * 1024 * 1024, alloc_flags, - CHUNK_ALLOC_FORCE); + ret = do_chunk_alloc(trans, root, 2 * 1024 * 1024, alloc_flags, 1); if (ret < 0) goto out; ret = set_block_group_ro(cache); @@ -8198,8 +8128,7 @@ int btrfs_force_chunk_alloc(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 type) { u64 alloc_flags = get_alloc_profile(root, type); - return do_chunk_alloc(trans, root, 2 * 1024 * 1024, alloc_flags, - CHUNK_ALLOC_FORCE); + return do_chunk_alloc(trans, root, 2 * 1024 * 1024, alloc_flags, 1); } /* diff --git a/trunk/fs/btrfs/extent_io.c b/trunk/fs/btrfs/extent_io.c index 315138605088..20ddb28602a8 100644 --- a/trunk/fs/btrfs/extent_io.c +++ b/trunk/fs/btrfs/extent_io.c @@ -690,15 +690,6 @@ static void cache_state(struct extent_state *state, } } -static void uncache_state(struct extent_state **cached_ptr) -{ - if (cached_ptr && (*cached_ptr)) { - struct extent_state *state = *cached_ptr; - *cached_ptr = NULL; - free_extent_state(state); - } -} - /* * set some bits on a range in the tree. This may require allocations or * sleeping, so the gfp mask is used to indicate what is allowed. @@ -949,10 +940,10 @@ static int clear_extent_new(struct extent_io_tree *tree, u64 start, u64 end, } int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, - struct extent_state **cached_state, gfp_t mask) + gfp_t mask) { - return set_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, - NULL, cached_state, mask); + return set_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, NULL, + NULL, mask); } static int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, @@ -1021,7 +1012,8 @@ int unlock_extent_cached(struct extent_io_tree *tree, u64 start, u64 end, mask); } -int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask) +int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, + gfp_t mask) { return clear_extent_bit(tree, start, end, EXTENT_LOCKED, 1, 0, NULL, mask); @@ -1743,9 +1735,6 @@ static void end_bio_extent_readpage(struct bio *bio, int err) do { struct page *page = bvec->bv_page; - struct extent_state *cached = NULL; - struct extent_state *state; - tree = &BTRFS_I(page->mapping->host)->io_tree; start = ((u64)page->index << PAGE_CACHE_SHIFT) + @@ -1760,20 +1749,9 @@ static void end_bio_extent_readpage(struct bio *bio, int err) if (++bvec <= bvec_end) prefetchw(&bvec->bv_page->flags); - spin_lock(&tree->lock); - state = find_first_extent_bit_state(tree, start, EXTENT_LOCKED); - if (state && state->start == start) { - /* - * take a reference on the state, unlock will drop - * the ref - */ - cache_state(state, &cached); - } - spin_unlock(&tree->lock); - if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { ret = tree->ops->readpage_end_io_hook(page, start, end, - state); + NULL); if (ret) uptodate = 0; } @@ -1786,16 +1764,15 @@ static void end_bio_extent_readpage(struct bio *bio, int err) test_bit(BIO_UPTODATE, &bio->bi_flags); if (err) uptodate = 0; - uncache_state(&cached); continue; } } if (uptodate) { - set_extent_uptodate(tree, start, end, &cached, + set_extent_uptodate(tree, start, end, GFP_ATOMIC); } - unlock_extent_cached(tree, start, end, &cached, GFP_ATOMIC); + unlock_extent(tree, start, end, GFP_ATOMIC); if (whole_page) { if (uptodate) { @@ -1834,7 +1811,6 @@ static void end_bio_extent_preparewrite(struct bio *bio, int err) do { struct page *page = bvec->bv_page; - struct extent_state *cached = NULL; tree = &BTRFS_I(page->mapping->host)->io_tree; start = ((u64)page->index << PAGE_CACHE_SHIFT) + @@ -1845,14 +1821,13 @@ static void end_bio_extent_preparewrite(struct bio *bio, int err) prefetchw(&bvec->bv_page->flags); if (uptodate) { - set_extent_uptodate(tree, start, end, &cached, - GFP_ATOMIC); + set_extent_uptodate(tree, start, end, GFP_ATOMIC); } else { ClearPageUptodate(page); SetPageError(page); } - unlock_extent_cached(tree, start, end, &cached, GFP_ATOMIC); + unlock_extent(tree, start, end, GFP_ATOMIC); } while (bvec >= bio->bi_io_vec); @@ -2041,17 +2016,14 @@ static int __extent_read_full_page(struct extent_io_tree *tree, while (cur <= end) { if (cur >= last_byte) { char *userpage; - struct extent_state *cached = NULL; - iosize = PAGE_CACHE_SIZE - page_offset; userpage = kmap_atomic(page, KM_USER0); memset(userpage + page_offset, 0, iosize); flush_dcache_page(page); kunmap_atomic(userpage, KM_USER0); set_extent_uptodate(tree, cur, cur + iosize - 1, - &cached, GFP_NOFS); - unlock_extent_cached(tree, cur, cur + iosize - 1, - &cached, GFP_NOFS); + GFP_NOFS); + unlock_extent(tree, cur, cur + iosize - 1, GFP_NOFS); break; } em = get_extent(inode, page, page_offset, cur, @@ -2091,17 +2063,14 @@ static int __extent_read_full_page(struct extent_io_tree *tree, /* we've found a hole, just zero and go on */ if (block_start == EXTENT_MAP_HOLE) { char *userpage; - struct extent_state *cached = NULL; - userpage = kmap_atomic(page, KM_USER0); memset(userpage + page_offset, 0, iosize); flush_dcache_page(page); kunmap_atomic(userpage, KM_USER0); set_extent_uptodate(tree, cur, cur + iosize - 1, - &cached, GFP_NOFS); - unlock_extent_cached(tree, cur, cur + iosize - 1, - &cached, GFP_NOFS); + GFP_NOFS); + unlock_extent(tree, cur, cur + iosize - 1, GFP_NOFS); cur = cur + iosize; page_offset += iosize; continue; @@ -2820,12 +2789,9 @@ int extent_prepare_write(struct extent_io_tree *tree, iocount++; block_start = block_start + iosize; } else { - struct extent_state *cached = NULL; - - set_extent_uptodate(tree, block_start, cur_end, &cached, + set_extent_uptodate(tree, block_start, cur_end, GFP_NOFS); - unlock_extent_cached(tree, block_start, cur_end, - &cached, GFP_NOFS); + unlock_extent(tree, block_start, cur_end, GFP_NOFS); block_start = cur_end + 1; } page_offset = block_start & (PAGE_CACHE_SIZE - 1); @@ -3491,7 +3457,7 @@ int set_extent_buffer_uptodate(struct extent_io_tree *tree, num_pages = num_extent_pages(eb->start, eb->len); set_extent_uptodate(tree, eb->start, eb->start + eb->len - 1, - NULL, GFP_NOFS); + GFP_NOFS); for (i = 0; i < num_pages; i++) { page = extent_buffer_page(eb, i); if ((i == 0 && (eb->start & (PAGE_CACHE_SIZE - 1))) || @@ -3919,12 +3885,6 @@ static void move_pages(struct page *dst_page, struct page *src_page, kunmap_atomic(dst_kaddr, KM_USER0); } -static inline bool areas_overlap(unsigned long src, unsigned long dst, unsigned long len) -{ - unsigned long distance = (src > dst) ? src - dst : dst - src; - return distance < len; -} - static void copy_pages(struct page *dst_page, struct page *src_page, unsigned long dst_off, unsigned long src_off, unsigned long len) @@ -3932,12 +3892,10 @@ static void copy_pages(struct page *dst_page, struct page *src_page, char *dst_kaddr = kmap_atomic(dst_page, KM_USER0); char *src_kaddr; - if (dst_page != src_page) { + if (dst_page != src_page) src_kaddr = kmap_atomic(src_page, KM_USER1); - } else { + else src_kaddr = dst_kaddr; - BUG_ON(areas_overlap(src_off, dst_off, len)); - } memcpy(dst_kaddr + dst_off, src_kaddr + src_off, len); kunmap_atomic(dst_kaddr, KM_USER0); @@ -4012,7 +3970,7 @@ void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset, "len %lu len %lu\n", dst_offset, len, dst->len); BUG_ON(1); } - if (!areas_overlap(src_offset, dst_offset, len)) { + if (dst_offset < src_offset) { memcpy_extent_buffer(dst, dst_offset, src_offset, len); return; } diff --git a/trunk/fs/btrfs/extent_io.h b/trunk/fs/btrfs/extent_io.h index af2d7179c372..f62c5442835d 100644 --- a/trunk/fs/btrfs/extent_io.h +++ b/trunk/fs/btrfs/extent_io.h @@ -208,7 +208,7 @@ int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits, int exclusive_bits, u64 *failed_start, struct extent_state **cached_state, gfp_t mask); int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, - struct extent_state **cached_state, gfp_t mask); + gfp_t mask); int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, diff --git a/trunk/fs/btrfs/file.c b/trunk/fs/btrfs/file.c index 75899a01dded..e621ea54a3fd 100644 --- a/trunk/fs/btrfs/file.c +++ b/trunk/fs/btrfs/file.c @@ -104,7 +104,7 @@ static noinline int btrfs_copy_from_user(loff_t pos, int num_pages, /* * unlocks pages after btrfs_file_write is done with them */ -void btrfs_drop_pages(struct page **pages, size_t num_pages) +static noinline void btrfs_drop_pages(struct page **pages, size_t num_pages) { size_t i; for (i = 0; i < num_pages; i++) { @@ -127,13 +127,16 @@ void btrfs_drop_pages(struct page **pages, size_t num_pages) * this also makes the decision about creating an inline extent vs * doing real data extents, marking pages dirty and delalloc as required. */ -int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode, - struct page **pages, size_t num_pages, - loff_t pos, size_t write_bytes, - struct extent_state **cached) +static noinline int dirty_and_release_pages(struct btrfs_root *root, + struct file *file, + struct page **pages, + size_t num_pages, + loff_t pos, + size_t write_bytes) { int err = 0; int i; + struct inode *inode = fdentry(file)->d_inode; u64 num_bytes; u64 start_pos; u64 end_of_last_block; @@ -146,7 +149,7 @@ int btrfs_dirty_pages(struct btrfs_root *root, struct inode *inode, end_of_last_block = start_pos + num_bytes - 1; err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block, - cached); + NULL); if (err) return err; @@ -989,9 +992,9 @@ static noinline ssize_t __btrfs_buffered_write(struct file *file, } if (copied > 0) { - ret = btrfs_dirty_pages(root, inode, pages, - dirty_pages, pos, copied, - NULL); + ret = dirty_and_release_pages(root, file, pages, + dirty_pages, pos, + copied); if (ret) { btrfs_delalloc_release_space(inode, dirty_pages << PAGE_CACHE_SHIFT); diff --git a/trunk/fs/btrfs/free-space-cache.c b/trunk/fs/btrfs/free-space-cache.c index 11d2e9cea09e..f561c953205b 100644 --- a/trunk/fs/btrfs/free-space-cache.c +++ b/trunk/fs/btrfs/free-space-cache.c @@ -508,7 +508,6 @@ int btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode; struct rb_node *node; struct list_head *pos, *n; - struct page **pages; struct page *page; struct extent_state *cached_state = NULL; struct btrfs_free_cluster *cluster = NULL; @@ -518,13 +517,13 @@ int btrfs_write_out_cache(struct btrfs_root *root, u64 start, end, len; u64 bytes = 0; u32 *crc, *checksums; + pgoff_t index = 0, last_index = 0; unsigned long first_page_offset; - int index = 0, num_pages = 0; + int num_checksums; int entries = 0; int bitmaps = 0; int ret = 0; bool next_page = false; - bool out_of_space = false; root = root->fs_info->tree_root; @@ -552,31 +551,24 @@ int btrfs_write_out_cache(struct btrfs_root *root, return 0; } - num_pages = (i_size_read(inode) + PAGE_CACHE_SIZE - 1) >> - PAGE_CACHE_SHIFT; + last_index = (i_size_read(inode) - 1) >> PAGE_CACHE_SHIFT; filemap_write_and_wait(inode->i_mapping); btrfs_wait_ordered_range(inode, inode->i_size & ~(root->sectorsize - 1), (u64)-1); /* We need a checksum per page. */ - crc = checksums = kzalloc(sizeof(u32) * num_pages, GFP_NOFS); + num_checksums = i_size_read(inode) / PAGE_CACHE_SIZE; + crc = checksums = kzalloc(sizeof(u32) * num_checksums, GFP_NOFS); if (!crc) { iput(inode); return 0; } - pages = kzalloc(sizeof(struct page *) * num_pages, GFP_NOFS); - if (!pages) { - kfree(crc); - iput(inode); - return 0; - } - /* Since the first page has all of our checksums and our generation we * need to calculate the offset into the page that we can start writing * our entries. */ - first_page_offset = (sizeof(u32) * num_pages) + sizeof(u64); + first_page_offset = (sizeof(u32) * num_checksums) + sizeof(u64); /* Get the cluster for this block_group if it exists */ if (!list_empty(&block_group->cluster_list)) @@ -598,18 +590,20 @@ int btrfs_write_out_cache(struct btrfs_root *root, * after find_get_page at this point. Just putting this here so people * know and don't freak out. */ - while (index < num_pages) { + while (index <= last_index) { page = grab_cache_page(inode->i_mapping, index); if (!page) { - int i; + pgoff_t i = 0; - for (i = 0; i < num_pages; i++) { - unlock_page(pages[i]); - page_cache_release(pages[i]); + while (i < index) { + page = find_get_page(inode->i_mapping, i); + unlock_page(page); + page_cache_release(page); + page_cache_release(page); + i++; } goto out_free; } - pages[index] = page; index++; } @@ -637,12 +631,7 @@ int btrfs_write_out_cache(struct btrfs_root *root, offset = start_offset; } - if (index >= num_pages) { - out_of_space = true; - break; - } - - page = pages[index]; + page = find_get_page(inode->i_mapping, index); addr = kmap(page); entry = addr + start_offset; @@ -719,6 +708,23 @@ int btrfs_write_out_cache(struct btrfs_root *root, bytes += PAGE_CACHE_SIZE; + ClearPageChecked(page); + set_page_extent_mapped(page); + SetPageUptodate(page); + set_page_dirty(page); + + /* + * We need to release our reference we got for grab_cache_page, + * except for the first page which will hold our checksums, we + * do that below. + */ + if (index != 0) { + unlock_page(page); + page_cache_release(page); + } + + page_cache_release(page); + index++; } while (node || next_page); @@ -728,11 +734,7 @@ int btrfs_write_out_cache(struct btrfs_root *root, struct btrfs_free_space *entry = list_entry(pos, struct btrfs_free_space, list); - if (index >= num_pages) { - out_of_space = true; - break; - } - page = pages[index]; + page = find_get_page(inode->i_mapping, index); addr = kmap(page); memcpy(addr, entry->bitmap, PAGE_CACHE_SIZE); @@ -743,58 +745,64 @@ int btrfs_write_out_cache(struct btrfs_root *root, crc++; bytes += PAGE_CACHE_SIZE; + ClearPageChecked(page); + set_page_extent_mapped(page); + SetPageUptodate(page); + set_page_dirty(page); + unlock_page(page); + page_cache_release(page); + page_cache_release(page); list_del_init(&entry->list); index++; } - if (out_of_space) { - btrfs_drop_pages(pages, num_pages); - unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, - i_size_read(inode) - 1, &cached_state, - GFP_NOFS); - ret = 0; - goto out_free; - } - /* Zero out the rest of the pages just to make sure */ - while (index < num_pages) { + while (index <= last_index) { void *addr; - page = pages[index]; + page = find_get_page(inode->i_mapping, index); + addr = kmap(page); memset(addr, 0, PAGE_CACHE_SIZE); kunmap(page); + ClearPageChecked(page); + set_page_extent_mapped(page); + SetPageUptodate(page); + set_page_dirty(page); + unlock_page(page); + page_cache_release(page); + page_cache_release(page); bytes += PAGE_CACHE_SIZE; index++; } + btrfs_set_extent_delalloc(inode, 0, bytes - 1, &cached_state); + /* Write the checksums and trans id to the first page */ { void *addr; u64 *gen; - page = pages[0]; + page = find_get_page(inode->i_mapping, 0); addr = kmap(page); - memcpy(addr, checksums, sizeof(u32) * num_pages); - gen = addr + (sizeof(u32) * num_pages); + memcpy(addr, checksums, sizeof(u32) * num_checksums); + gen = addr + (sizeof(u32) * num_checksums); *gen = trans->transid; kunmap(page); + ClearPageChecked(page); + set_page_extent_mapped(page); + SetPageUptodate(page); + set_page_dirty(page); + unlock_page(page); + page_cache_release(page); + page_cache_release(page); } + BTRFS_I(inode)->generation = trans->transid; - ret = btrfs_dirty_pages(root, inode, pages, num_pages, 0, - bytes, &cached_state); - btrfs_drop_pages(pages, num_pages); unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, i_size_read(inode) - 1, &cached_state, GFP_NOFS); - if (ret) { - ret = 0; - goto out_free; - } - - BTRFS_I(inode)->generation = trans->transid; - filemap_write_and_wait(inode->i_mapping); key.objectid = BTRFS_FREE_SPACE_OBJECTID; @@ -845,7 +853,6 @@ int btrfs_write_out_cache(struct btrfs_root *root, BTRFS_I(inode)->generation = 0; } kfree(checksums); - kfree(pages); btrfs_update_inode(trans, root, inode); iput(inode); return ret; diff --git a/trunk/fs/btrfs/inode.c b/trunk/fs/btrfs/inode.c index fcd66b6a8086..5cc64ab9c485 100644 --- a/trunk/fs/btrfs/inode.c +++ b/trunk/fs/btrfs/inode.c @@ -1770,12 +1770,9 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) add_pending_csums(trans, inode, ordered_extent->file_offset, &ordered_extent->list); - ret = btrfs_ordered_update_i_size(inode, 0, ordered_extent); - if (!ret) { - ret = btrfs_update_inode(trans, root, inode); - BUG_ON(ret); - } - ret = 0; + btrfs_ordered_update_i_size(inode, 0, ordered_extent); + ret = btrfs_update_inode(trans, root, inode); + BUG_ON(ret); out: if (nolock) { if (trans) @@ -2593,13 +2590,6 @@ static void fill_inode_item(struct btrfs_trans_handle *trans, struct btrfs_inode_item *item, struct inode *inode) { - if (!leaf->map_token) - map_private_extent_buffer(leaf, (unsigned long)item, - sizeof(struct btrfs_inode_item), - &leaf->map_token, &leaf->kaddr, - &leaf->map_start, &leaf->map_len, - KM_USER1); - btrfs_set_inode_uid(leaf, item, inode->i_uid); btrfs_set_inode_gid(leaf, item, inode->i_gid); btrfs_set_inode_size(leaf, item, BTRFS_I(inode)->disk_i_size); @@ -2628,11 +2618,6 @@ static void fill_inode_item(struct btrfs_trans_handle *trans, btrfs_set_inode_rdev(leaf, item, inode->i_rdev); btrfs_set_inode_flags(leaf, item, BTRFS_I(inode)->flags); btrfs_set_inode_block_group(leaf, item, BTRFS_I(inode)->block_group); - - if (leaf->map_token) { - unmap_extent_buffer(leaf, leaf->map_token, KM_USER1); - leaf->map_token = NULL; - } } /* @@ -4222,8 +4207,10 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, struct btrfs_key found_key; struct btrfs_path *path; int ret; + u32 nritems; struct extent_buffer *leaf; int slot; + int advance; unsigned char d_type; int over = 0; u32 di_cur; @@ -4266,19 +4253,27 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) goto err; + advance = 0; while (1) { leaf = path->nodes[0]; + nritems = btrfs_header_nritems(leaf); slot = path->slots[0]; - if (slot >= btrfs_header_nritems(leaf)) { - ret = btrfs_next_leaf(root, path); - if (ret < 0) - goto err; - else if (ret > 0) - break; - continue; + if (advance || slot >= nritems) { + if (slot >= nritems - 1) { + ret = btrfs_next_leaf(root, path); + if (ret) + break; + leaf = path->nodes[0]; + nritems = btrfs_header_nritems(leaf); + slot = path->slots[0]; + } else { + slot++; + path->slots[0]++; + } } + advance = 1; item = btrfs_item_nr(leaf, slot); btrfs_item_key_to_cpu(leaf, &found_key, slot); @@ -4287,7 +4282,7 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, if (btrfs_key_type(&found_key) != key_type) break; if (found_key.offset < filp->f_pos) - goto next; + continue; filp->f_pos = found_key.offset; @@ -4340,8 +4335,6 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, di_cur += di_len; di = (struct btrfs_dir_item *)((char *)di + di_len); } -next: - path->slots[0]++; } /* Reached end of directory/root. Bump pos past the last item. */ @@ -4534,17 +4527,14 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans, BUG_ON(!path); inode = new_inode(root->fs_info->sb); - if (!inode) { - btrfs_free_path(path); + if (!inode) return ERR_PTR(-ENOMEM); - } if (dir) { trace_btrfs_inode_request(dir); ret = btrfs_set_inode_index(dir, index); if (ret) { - btrfs_free_path(path); iput(inode); return ERR_PTR(ret); } @@ -4844,6 +4834,9 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, if (inode->i_nlink == ~0U) return -EMLINK; + btrfs_inc_nlink(inode); + inode->i_ctime = CURRENT_TIME; + err = btrfs_set_inode_index(dir, &index); if (err) goto fail; @@ -4859,9 +4852,6 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, goto fail; } - btrfs_inc_nlink(inode); - inode->i_ctime = CURRENT_TIME; - btrfs_set_trans_block_group(trans, dir); ihold(inode); @@ -5231,7 +5221,7 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, btrfs_mark_buffer_dirty(leaf); } set_extent_uptodate(io_tree, em->start, - extent_map_end(em) - 1, NULL, GFP_NOFS); + extent_map_end(em) - 1, GFP_NOFS); goto insert; } else { printk(KERN_ERR "btrfs unknown found_type %d\n", found_type); @@ -5438,30 +5428,17 @@ struct extent_map *btrfs_get_extent_fiemap(struct inode *inode, struct page *pag } static struct extent_map *btrfs_new_extent_direct(struct inode *inode, - struct extent_map *em, u64 start, u64 len) { struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_trans_handle *trans; + struct extent_map *em; struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; struct btrfs_key ins; u64 alloc_hint; int ret; - bool insert = false; - /* - * Ok if the extent map we looked up is a hole and is for the exact - * range we want, there is no reason to allocate a new one, however if - * it is not right then we need to free this one and drop the cache for - * our range. - */ - if (em->block_start != EXTENT_MAP_HOLE || em->start != start || - em->len != len) { - free_extent_map(em); - em = NULL; - insert = true; - btrfs_drop_extent_cache(inode, start, start + len - 1, 0); - } + btrfs_drop_extent_cache(inode, start, start + len - 1, 0); trans = btrfs_join_transaction(root, 0); if (IS_ERR(trans)) @@ -5477,12 +5454,10 @@ static struct extent_map *btrfs_new_extent_direct(struct inode *inode, goto out; } + em = alloc_extent_map(GFP_NOFS); if (!em) { - em = alloc_extent_map(GFP_NOFS); - if (!em) { - em = ERR_PTR(-ENOMEM); - goto out; - } + em = ERR_PTR(-ENOMEM); + goto out; } em->start = start; @@ -5492,15 +5467,9 @@ static struct extent_map *btrfs_new_extent_direct(struct inode *inode, em->block_start = ins.objectid; em->block_len = ins.offset; em->bdev = root->fs_info->fs_devices->latest_bdev; - - /* - * We need to do this because if we're using the original em we searched - * for, we could have EXTENT_FLAG_VACANCY set, and we don't want that. - */ - em->flags = 0; set_bit(EXTENT_FLAG_PINNED, &em->flags); - while (insert) { + while (1) { write_lock(&em_tree->lock); ret = add_extent_mapping(em_tree, em); write_unlock(&em_tree->lock); @@ -5718,7 +5687,8 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock, * it above */ len = bh_result->b_size; - em = btrfs_new_extent_direct(inode, em, start, len); + free_extent_map(em); + em = btrfs_new_extent_direct(inode, start, len); if (IS_ERR(em)) return PTR_ERR(em); len = min(len, em->len - (start - em->start)); @@ -5881,10 +5851,8 @@ static void btrfs_endio_direct_write(struct bio *bio, int err) } add_pending_csums(trans, inode, ordered->file_offset, &ordered->list); - ret = btrfs_ordered_update_i_size(inode, 0, ordered); - if (!ret) - btrfs_update_inode(trans, root, inode); - ret = 0; + btrfs_ordered_update_i_size(inode, 0, ordered); + btrfs_update_inode(trans, root, inode); out_unlock: unlock_extent_cached(&BTRFS_I(inode)->io_tree, ordered->file_offset, ordered->file_offset + ordered->len - 1, @@ -5970,7 +5938,7 @@ static struct bio *btrfs_dio_bio_alloc(struct block_device *bdev, static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode, int rw, u64 file_offset, int skip_sum, - u32 *csums, int async_submit) + u32 *csums) { int write = rw & REQ_WRITE; struct btrfs_root *root = BTRFS_I(inode)->root; @@ -5981,24 +5949,13 @@ static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode, if (ret) goto err; - if (skip_sum) - goto map; - - if (write && async_submit) { + if (write && !skip_sum) { ret = btrfs_wq_submit_bio(root->fs_info, inode, rw, bio, 0, 0, file_offset, __btrfs_submit_bio_start_direct_io, __btrfs_submit_bio_done); goto err; - } else if (write) { - /* - * If we aren't doing async submit, calculate the csum of the - * bio now. - */ - ret = btrfs_csum_one_bio(root, inode, bio, file_offset, 1); - if (ret) - goto err; } else if (!skip_sum) { ret = btrfs_lookup_bio_sums_dio(root, inode, bio, file_offset, csums); @@ -6006,8 +5963,7 @@ static inline int __btrfs_submit_dio_bio(struct bio *bio, struct inode *inode, goto err; } -map: - ret = btrfs_map_bio(root, rw, bio, 0, async_submit); + ret = btrfs_map_bio(root, rw, bio, 0, 1); err: bio_put(bio); return ret; @@ -6029,9 +5985,15 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip, int nr_pages = 0; u32 *csums = dip->csums; int ret = 0; - int async_submit = 0; int write = rw & REQ_WRITE; + bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, start_sector, GFP_NOFS); + if (!bio) + return -ENOMEM; + bio->bi_private = dip; + bio->bi_end_io = btrfs_end_dio_bio; + atomic_inc(&dip->pending_bios); + map_length = orig_bio->bi_size; ret = btrfs_map_block(map_tree, READ, start_sector << 9, &map_length, NULL, 0); @@ -6040,19 +6002,6 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip, return -EIO; } - if (map_length >= orig_bio->bi_size) { - bio = orig_bio; - goto submit; - } - - async_submit = 1; - bio = btrfs_dio_bio_alloc(orig_bio->bi_bdev, start_sector, GFP_NOFS); - if (!bio) - return -ENOMEM; - bio->bi_private = dip; - bio->bi_end_io = btrfs_end_dio_bio; - atomic_inc(&dip->pending_bios); - while (bvec <= (orig_bio->bi_io_vec + orig_bio->bi_vcnt - 1)) { if (unlikely(map_length < submit_len + bvec->bv_len || bio_add_page(bio, bvec->bv_page, bvec->bv_len, @@ -6066,7 +6015,7 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip, atomic_inc(&dip->pending_bios); ret = __btrfs_submit_dio_bio(bio, inode, rw, file_offset, skip_sum, - csums, async_submit); + csums); if (ret) { bio_put(bio); atomic_dec(&dip->pending_bios); @@ -6103,9 +6052,8 @@ static int btrfs_submit_direct_hook(int rw, struct btrfs_dio_private *dip, } } -submit: ret = __btrfs_submit_dio_bio(bio, inode, rw, file_offset, skip_sum, - csums, async_submit); + csums); if (!ret) return 0; @@ -6200,7 +6148,6 @@ static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *io unsigned long nr_segs) { int seg; - int i; size_t size; unsigned long addr; unsigned blocksize_mask = root->sectorsize - 1; @@ -6215,22 +6162,8 @@ static ssize_t check_direct_IO(struct btrfs_root *root, int rw, struct kiocb *io addr = (unsigned long)iov[seg].iov_base; size = iov[seg].iov_len; end += size; - if ((addr & blocksize_mask) || (size & blocksize_mask)) + if ((addr & blocksize_mask) || (size & blocksize_mask)) goto out; - - /* If this is a write we don't need to check anymore */ - if (rw & WRITE) - continue; - - /* - * Check to make sure we don't have duplicate iov_base's in this - * iovec, if so return EINVAL, otherwise we'll get csum errors - * when reading back. - */ - for (i = seg + 1; i < nr_segs; i++) { - if (iov[seg].iov_base == iov[i].iov_base) - goto out; - } } retval = 0; out: diff --git a/trunk/fs/btrfs/ioctl.c b/trunk/fs/btrfs/ioctl.c index ffb48d6c5433..cfc264fefdb0 100644 --- a/trunk/fs/btrfs/ioctl.c +++ b/trunk/fs/btrfs/ioctl.c @@ -2287,7 +2287,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg) struct btrfs_ioctl_space_info space; struct btrfs_ioctl_space_info *dest; struct btrfs_ioctl_space_info *dest_orig; - struct btrfs_ioctl_space_info __user *user_dest; + struct btrfs_ioctl_space_info *user_dest; struct btrfs_space_info *info; u64 types[] = {BTRFS_BLOCK_GROUP_DATA, BTRFS_BLOCK_GROUP_SYSTEM, diff --git a/trunk/fs/btrfs/super.c b/trunk/fs/btrfs/super.c index 0ac712efcdf2..58e7de9cc90c 100644 --- a/trunk/fs/btrfs/super.c +++ b/trunk/fs/btrfs/super.c @@ -159,7 +159,7 @@ enum { Opt_compress_type, Opt_compress_force, Opt_compress_force_type, Opt_notreelog, Opt_ratio, Opt_flushoncommit, Opt_discard, Opt_space_cache, Opt_clear_cache, Opt_user_subvol_rm_allowed, - Opt_enospc_debug, Opt_subvolrootid, Opt_err, + Opt_enospc_debug, Opt_err, }; static match_table_t tokens = { @@ -189,7 +189,6 @@ static match_table_t tokens = { {Opt_clear_cache, "clear_cache"}, {Opt_user_subvol_rm_allowed, "user_subvol_rm_allowed"}, {Opt_enospc_debug, "enospc_debug"}, - {Opt_subvolrootid, "subvolrootid=%d"}, {Opt_err, NULL}, }; @@ -233,7 +232,6 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) break; case Opt_subvol: case Opt_subvolid: - case Opt_subvolrootid: case Opt_device: /* * These are parsed by btrfs_parse_early_options @@ -390,7 +388,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) */ static int btrfs_parse_early_options(const char *options, fmode_t flags, void *holder, char **subvol_name, u64 *subvol_objectid, - u64 *subvol_rootid, struct btrfs_fs_devices **fs_devices) + struct btrfs_fs_devices **fs_devices) { substring_t args[MAX_OPT_ARGS]; char *opts, *orig, *p; @@ -431,18 +429,6 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, *subvol_objectid = intarg; } break; - case Opt_subvolrootid: - intarg = 0; - error = match_int(&args[0], &intarg); - if (!error) { - /* we want the original fs_tree */ - if (!intarg) - *subvol_rootid = - BTRFS_FS_TREE_OBJECTID; - else - *subvol_rootid = intarg; - } - break; case Opt_device: error = btrfs_scan_one_device(match_strdup(&args[0]), flags, holder, fs_devices); @@ -750,7 +736,6 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, fmode_t mode = FMODE_READ; char *subvol_name = NULL; u64 subvol_objectid = 0; - u64 subvol_rootid = 0; int error = 0; if (!(flags & MS_RDONLY)) @@ -758,7 +743,7 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, error = btrfs_parse_early_options(data, mode, fs_type, &subvol_name, &subvol_objectid, - &subvol_rootid, &fs_devices); + &fs_devices); if (error) return ERR_PTR(error); @@ -822,17 +807,15 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, s->s_flags |= MS_ACTIVE; } + root = get_default_root(s, subvol_objectid); + if (IS_ERR(root)) { + error = PTR_ERR(root); + deactivate_locked_super(s); + goto error_free_subvol_name; + } /* if they gave us a subvolume name bind mount into that */ if (strcmp(subvol_name, ".")) { struct dentry *new_root; - - root = get_default_root(s, subvol_rootid); - if (IS_ERR(root)) { - error = PTR_ERR(root); - deactivate_locked_super(s); - goto error_free_subvol_name; - } - mutex_lock(&root->d_inode->i_mutex); new_root = lookup_one_len(subvol_name, root, strlen(subvol_name)); @@ -853,13 +836,6 @@ static struct dentry *btrfs_mount(struct file_system_type *fs_type, int flags, } dput(root); root = new_root; - } else { - root = get_default_root(s, subvol_objectid); - if (IS_ERR(root)) { - error = PTR_ERR(root); - deactivate_locked_super(s); - goto error_free_subvol_name; - } } kfree(subvol_name); diff --git a/trunk/fs/btrfs/transaction.c b/trunk/fs/btrfs/transaction.c index c571734d5e5a..5b158da7e0bb 100644 --- a/trunk/fs/btrfs/transaction.c +++ b/trunk/fs/btrfs/transaction.c @@ -32,8 +32,10 @@ static noinline void put_transaction(struct btrfs_transaction *transaction) { - WARN_ON(atomic_read(&transaction->use_count) == 0); - if (atomic_dec_and_test(&transaction->use_count)) { + WARN_ON(transaction->use_count == 0); + transaction->use_count--; + if (transaction->use_count == 0) { + list_del_init(&transaction->list); memset(transaction, 0, sizeof(*transaction)); kmem_cache_free(btrfs_transaction_cachep, transaction); } @@ -58,14 +60,14 @@ static noinline int join_transaction(struct btrfs_root *root) if (!cur_trans) return -ENOMEM; root->fs_info->generation++; - atomic_set(&cur_trans->num_writers, 1); + cur_trans->num_writers = 1; cur_trans->num_joined = 0; cur_trans->transid = root->fs_info->generation; init_waitqueue_head(&cur_trans->writer_wait); init_waitqueue_head(&cur_trans->commit_wait); cur_trans->in_commit = 0; cur_trans->blocked = 0; - atomic_set(&cur_trans->use_count, 1); + cur_trans->use_count = 1; cur_trans->commit_done = 0; cur_trans->start_time = get_seconds(); @@ -86,7 +88,7 @@ static noinline int join_transaction(struct btrfs_root *root) root->fs_info->running_transaction = cur_trans; spin_unlock(&root->fs_info->new_trans_lock); } else { - atomic_inc(&cur_trans->num_writers); + cur_trans->num_writers++; cur_trans->num_joined++; } @@ -143,7 +145,7 @@ static void wait_current_trans(struct btrfs_root *root) cur_trans = root->fs_info->running_transaction; if (cur_trans && cur_trans->blocked) { DEFINE_WAIT(wait); - atomic_inc(&cur_trans->use_count); + cur_trans->use_count++; while (1) { prepare_to_wait(&root->fs_info->transaction_wait, &wait, TASK_UNINTERRUPTIBLE); @@ -179,7 +181,6 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, { struct btrfs_trans_handle *h; struct btrfs_transaction *cur_trans; - int retries = 0; int ret; if (root->fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) @@ -203,7 +204,7 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, } cur_trans = root->fs_info->running_transaction; - atomic_inc(&cur_trans->use_count); + cur_trans->use_count++; if (type != TRANS_JOIN_NOLOCK) mutex_unlock(&root->fs_info->trans_mutex); @@ -223,18 +224,10 @@ static struct btrfs_trans_handle *start_transaction(struct btrfs_root *root, if (num_items > 0) { ret = btrfs_trans_reserve_metadata(h, root, num_items); - if (ret == -EAGAIN && !retries) { - retries++; + if (ret == -EAGAIN) { btrfs_commit_transaction(h, root); goto again; - } else if (ret == -EAGAIN) { - /* - * We have already retried and got EAGAIN, so really we - * don't have space, so set ret to -ENOSPC. - */ - ret = -ENOSPC; } - if (ret < 0) { btrfs_end_transaction(h, root); return ERR_PTR(ret); @@ -334,7 +327,7 @@ int btrfs_wait_for_commit(struct btrfs_root *root, u64 transid) goto out_unlock; /* nothing committing|committed */ } - atomic_inc(&cur_trans->use_count); + cur_trans->use_count++; mutex_unlock(&root->fs_info->trans_mutex); wait_for_commit(root, cur_trans); @@ -464,14 +457,18 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, wake_up_process(info->transaction_kthread); } + if (lock) + mutex_lock(&info->trans_mutex); WARN_ON(cur_trans != info->running_transaction); - WARN_ON(atomic_read(&cur_trans->num_writers) < 1); - atomic_dec(&cur_trans->num_writers); + WARN_ON(cur_trans->num_writers < 1); + cur_trans->num_writers--; smp_mb(); if (waitqueue_active(&cur_trans->writer_wait)) wake_up(&cur_trans->writer_wait); put_transaction(cur_trans); + if (lock) + mutex_unlock(&info->trans_mutex); if (current->journal_info == trans) current->journal_info = NULL; @@ -1181,7 +1178,7 @@ int btrfs_commit_transaction_async(struct btrfs_trans_handle *trans, /* take transaction reference */ mutex_lock(&root->fs_info->trans_mutex); cur_trans = trans->transaction; - atomic_inc(&cur_trans->use_count); + cur_trans->use_count++; mutex_unlock(&root->fs_info->trans_mutex); btrfs_end_transaction(trans, root); @@ -1240,7 +1237,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, mutex_lock(&root->fs_info->trans_mutex); if (cur_trans->in_commit) { - atomic_inc(&cur_trans->use_count); + cur_trans->use_count++; mutex_unlock(&root->fs_info->trans_mutex); btrfs_end_transaction(trans, root); @@ -1262,7 +1259,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, prev_trans = list_entry(cur_trans->list.prev, struct btrfs_transaction, list); if (!prev_trans->commit_done) { - atomic_inc(&prev_trans->use_count); + prev_trans->use_count++; mutex_unlock(&root->fs_info->trans_mutex); wait_for_commit(root, prev_trans); @@ -1303,14 +1300,14 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, TASK_UNINTERRUPTIBLE); smp_mb(); - if (atomic_read(&cur_trans->num_writers) > 1) + if (cur_trans->num_writers > 1) schedule_timeout(MAX_SCHEDULE_TIMEOUT); else if (should_grow) schedule_timeout(1); mutex_lock(&root->fs_info->trans_mutex); finish_wait(&cur_trans->writer_wait, &wait); - } while (atomic_read(&cur_trans->num_writers) > 1 || + } while (cur_trans->num_writers > 1 || (should_grow && cur_trans->num_joined != joined)); ret = create_pending_snapshots(trans, root->fs_info); @@ -1397,7 +1394,6 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, wake_up(&cur_trans->commit_wait); - list_del_init(&cur_trans->list); put_transaction(cur_trans); put_transaction(cur_trans); diff --git a/trunk/fs/btrfs/transaction.h b/trunk/fs/btrfs/transaction.h index e441acc6c584..229a594cacd5 100644 --- a/trunk/fs/btrfs/transaction.h +++ b/trunk/fs/btrfs/transaction.h @@ -27,11 +27,11 @@ struct btrfs_transaction { * total writers in this transaction, it must be zero before the * transaction can end */ - atomic_t num_writers; + unsigned long num_writers; unsigned long num_joined; int in_commit; - atomic_t use_count; + int use_count; int commit_done; int blocked; struct list_head list; diff --git a/trunk/fs/btrfs/xattr.c b/trunk/fs/btrfs/xattr.c index cfd660550ded..a5303b871b13 100644 --- a/trunk/fs/btrfs/xattr.c +++ b/trunk/fs/btrfs/xattr.c @@ -180,10 +180,11 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size) struct btrfs_path *path; struct extent_buffer *leaf; struct btrfs_dir_item *di; - int ret = 0, slot; + int ret = 0, slot, advance; size_t total_size = 0, size_left = size; unsigned long name_ptr; size_t name_len; + u32 nritems; /* * ok we want all objects associated with this id. @@ -203,24 +204,34 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size) ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) goto err; - + advance = 0; while (1) { leaf = path->nodes[0]; + nritems = btrfs_header_nritems(leaf); slot = path->slots[0]; /* this is where we start walking through the path */ - if (slot >= btrfs_header_nritems(leaf)) { + if (advance || slot >= nritems) { /* * if we've reached the last slot in this leaf we need * to go to the next leaf and reset everything */ - ret = btrfs_next_leaf(root, path); - if (ret < 0) - goto err; - else if (ret > 0) - break; - continue; + if (slot >= nritems-1) { + ret = btrfs_next_leaf(root, path); + if (ret) + break; + leaf = path->nodes[0]; + nritems = btrfs_header_nritems(leaf); + slot = path->slots[0]; + } else { + /* + * just walking through the slots on this leaf + */ + slot++; + path->slots[0]++; + } } + advance = 1; btrfs_item_key_to_cpu(leaf, &found_key, slot); @@ -239,7 +250,7 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size) /* we are just looking for how big our buffer needs to be */ if (!size) - goto next; + continue; if (!buffer || (name_len + 1) > size_left) { ret = -ERANGE; @@ -252,8 +263,6 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size) size_left -= name_len + 1; buffer += name_len + 1; -next: - path->slots[0]++; } ret = total_size; diff --git a/trunk/fs/cifs/README b/trunk/fs/cifs/README index 74ab165fc646..fe1683590828 100644 --- a/trunk/fs/cifs/README +++ b/trunk/fs/cifs/README @@ -685,6 +685,22 @@ LinuxExtensionsEnabled If set to one then the client will attempt to support and want to map the uid and gid fields to values supplied at mount (rather than the actual values, then set this to zero. (default 1) +Experimental When set to 1 used to enable certain experimental + features (currently enables multipage writes + when signing is enabled, the multipage write + performance enhancement was disabled when + signing turned on in case buffer was modified + just before it was sent, also this flag will + be used to use the new experimental directory change + notification code). When set to 2 enables + an additional experimental feature, "raw ntlmssp" + session establishment support (which allows + specifying "sec=ntlmssp" on mount). The Linux cifs + module will use ntlmv2 authentication encapsulated + in "raw ntlmssp" (not using SPNEGO) when + "sec=ntlmssp" is specified on mount. + This support also requires building cifs with + the CONFIG_CIFS_EXPERIMENTAL configuration flag. These experimental features and tracing can be enabled by changing flags in /proc/fs/cifs (after the cifs module has been installed or built into the diff --git a/trunk/fs/cifs/cache.c b/trunk/fs/cifs/cache.c index 53d57a3fe427..e654dfd092c3 100644 --- a/trunk/fs/cifs/cache.c +++ b/trunk/fs/cifs/cache.c @@ -50,7 +50,7 @@ void cifs_fscache_unregister(void) */ struct cifs_server_key { uint16_t family; /* address family */ - __be16 port; /* IP port */ + uint16_t port; /* IP port */ union { struct in_addr ipv4_addr; struct in6_addr ipv6_addr; diff --git a/trunk/fs/cifs/cifs_debug.c b/trunk/fs/cifs/cifs_debug.c index 30d01bc90855..65829d32128c 100644 --- a/trunk/fs/cifs/cifs_debug.c +++ b/trunk/fs/cifs/cifs_debug.c @@ -423,6 +423,7 @@ static const struct file_operations cifs_lookup_cache_proc_fops; static const struct file_operations traceSMB_proc_fops; static const struct file_operations cifs_multiuser_mount_proc_fops; static const struct file_operations cifs_security_flags_proc_fops; +static const struct file_operations cifs_experimental_proc_fops; static const struct file_operations cifs_linux_ext_proc_fops; void @@ -440,6 +441,8 @@ cifs_proc_init(void) proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops); proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops); proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops); + proc_create("Experimental", 0, proc_fs_cifs, + &cifs_experimental_proc_fops); proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs, &cifs_linux_ext_proc_fops); proc_create("MultiuserMount", 0, proc_fs_cifs, @@ -466,6 +469,7 @@ cifs_proc_clean(void) remove_proc_entry("OplockEnabled", proc_fs_cifs); remove_proc_entry("SecurityFlags", proc_fs_cifs); remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs); + remove_proc_entry("Experimental", proc_fs_cifs); remove_proc_entry("LookupCacheEnabled", proc_fs_cifs); remove_proc_entry("fs/cifs", NULL); } @@ -546,6 +550,45 @@ static const struct file_operations cifs_oplock_proc_fops = { .write = cifs_oplock_proc_write, }; +static int cifs_experimental_proc_show(struct seq_file *m, void *v) +{ + seq_printf(m, "%d\n", experimEnabled); + return 0; +} + +static int cifs_experimental_proc_open(struct inode *inode, struct file *file) +{ + return single_open(file, cifs_experimental_proc_show, NULL); +} + +static ssize_t cifs_experimental_proc_write(struct file *file, + const char __user *buffer, size_t count, loff_t *ppos) +{ + char c; + int rc; + + rc = get_user(c, buffer); + if (rc) + return rc; + if (c == '0' || c == 'n' || c == 'N') + experimEnabled = 0; + else if (c == '1' || c == 'y' || c == 'Y') + experimEnabled = 1; + else if (c == '2') + experimEnabled = 2; + + return count; +} + +static const struct file_operations cifs_experimental_proc_fops = { + .owner = THIS_MODULE, + .open = cifs_experimental_proc_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, + .write = cifs_experimental_proc_write, +}; + static int cifs_linux_ext_proc_show(struct seq_file *m, void *v) { seq_printf(m, "%d\n", linuxExtEnabled); diff --git a/trunk/fs/cifs/cifs_spnego.c b/trunk/fs/cifs/cifs_spnego.c index 33d221394aca..4dfba8283165 100644 --- a/trunk/fs/cifs/cifs_spnego.c +++ b/trunk/fs/cifs/cifs_spnego.c @@ -113,7 +113,7 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo) MAX_MECH_STR_LEN + UID_KEY_LEN + (sizeof(uid_t) * 2) + CREDUID_KEY_LEN + (sizeof(uid_t) * 2) + - USER_KEY_LEN + strlen(sesInfo->user_name) + + USER_KEY_LEN + strlen(sesInfo->userName) + PID_KEY_LEN + (sizeof(pid_t) * 2) + 1; spnego_key = ERR_PTR(-ENOMEM); @@ -153,7 +153,7 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo) sprintf(dp, ";creduid=0x%x", sesInfo->cred_uid); dp = description + strlen(description); - sprintf(dp, ";user=%s", sesInfo->user_name); + sprintf(dp, ";user=%s", sesInfo->userName); dp = description + strlen(description); sprintf(dp, ";pid=0x%x", current->pid); diff --git a/trunk/fs/cifs/cifs_unicode.c b/trunk/fs/cifs/cifs_unicode.c index 23d43cde4306..fc0fd4fde306 100644 --- a/trunk/fs/cifs/cifs_unicode.c +++ b/trunk/fs/cifs/cifs_unicode.c @@ -90,7 +90,7 @@ cifs_mapchar(char *target, const __u16 src_char, const struct nls_table *cp, case UNI_COLON: *target = ':'; break; - case UNI_ASTERISK: + case UNI_ASTERIK: *target = '*'; break; case UNI_QUESTION: @@ -264,40 +264,40 @@ cifs_strndup_from_ucs(const char *src, const int maxlen, const bool is_unicode, * names are little endian 16 bit Unicode on the wire */ int -cifsConvertToUCS(__le16 *target, const char *source, int srclen, +cifsConvertToUCS(__le16 *target, const char *source, int maxlen, const struct nls_table *cp, int mapChars) { int i, j, charlen; + int len_remaining = maxlen; char src_char; - __le16 dst_char; - wchar_t tmp; + __u16 temp; if (!mapChars) return cifs_strtoUCS(target, source, PATH_MAX, cp); - for (i = 0, j = 0; i < srclen; j++) { + for (i = 0, j = 0; i < maxlen; j++) { src_char = source[i]; switch (src_char) { case 0: - put_unaligned(0, &target[j]); + put_unaligned_le16(0, &target[j]); goto ctoUCS_out; case ':': - dst_char = cpu_to_le16(UNI_COLON); + temp = UNI_COLON; break; case '*': - dst_char = cpu_to_le16(UNI_ASTERISK); + temp = UNI_ASTERIK; break; case '?': - dst_char = cpu_to_le16(UNI_QUESTION); + temp = UNI_QUESTION; break; case '<': - dst_char = cpu_to_le16(UNI_LESSTHAN); + temp = UNI_LESSTHAN; break; case '>': - dst_char = cpu_to_le16(UNI_GRTRTHAN); + temp = UNI_GRTRTHAN; break; case '|': - dst_char = cpu_to_le16(UNI_PIPE); + temp = UNI_PIPE; break; /* * FIXME: We can not handle remapping backslash (UNI_SLASH) @@ -305,17 +305,17 @@ cifsConvertToUCS(__le16 *target, const char *source, int srclen, * as they use backslash as separator. */ default: - charlen = cp->char2uni(source + i, srclen - i, &tmp); - dst_char = cpu_to_le16(tmp); - + charlen = cp->char2uni(source+i, len_remaining, + &temp); /* * if no match, use question mark, which at least in * some cases serves as wild card */ if (charlen < 1) { - dst_char = cpu_to_le16(0x003f); + temp = 0x003f; charlen = 1; } + len_remaining -= charlen; /* * character may take more than one byte in the source * string, but will take exactly two bytes in the @@ -324,8 +324,9 @@ cifsConvertToUCS(__le16 *target, const char *source, int srclen, i += charlen; continue; } - put_unaligned(dst_char, &target[j]); + put_unaligned_le16(temp, &target[j]); i++; /* move to next char in source string */ + len_remaining--; } ctoUCS_out: diff --git a/trunk/fs/cifs/cifs_unicode.h b/trunk/fs/cifs/cifs_unicode.h index 644dd882a560..7fe6b52df507 100644 --- a/trunk/fs/cifs/cifs_unicode.h +++ b/trunk/fs/cifs/cifs_unicode.h @@ -44,7 +44,7 @@ * reserved symbols (along with \ and /), otherwise illegal to store * in filenames in NTFS */ -#define UNI_ASTERISK (__u16) ('*' + 0xF000) +#define UNI_ASTERIK (__u16) ('*' + 0xF000) #define UNI_QUESTION (__u16) ('?' + 0xF000) #define UNI_COLON (__u16) (':' + 0xF000) #define UNI_GRTRTHAN (__u16) ('>' + 0xF000) diff --git a/trunk/fs/cifs/cifsencrypt.c b/trunk/fs/cifs/cifsencrypt.c index d1a016be73ba..a51585f9852b 100644 --- a/trunk/fs/cifs/cifsencrypt.c +++ b/trunk/fs/cifs/cifsencrypt.c @@ -30,13 +30,12 @@ #include #include -/* - * Calculate and return the CIFS signature based on the mac key and SMB PDU. - * The 16 byte signature must be allocated by the caller. Note we only use the - * 1st eight bytes and that the smb header signature field on input contains - * the sequence number before this function is called. Also, this function - * should be called with the server->srv_mutex held. - */ +/* Calculate and return the CIFS signature based on the mac key and SMB PDU */ +/* the 16 byte signature must be allocated by the caller */ +/* Note we only use the 1st eight bytes */ +/* Note that the smb header signature field on input contains the + sequence number before this function is called */ + static int cifs_calculate_signature(const struct smb_hdr *cifs_pdu, struct TCP_Server_Info *server, char *signature) { @@ -210,10 +209,8 @@ int cifs_verify_signature(struct smb_hdr *cifs_pdu, cpu_to_le32(expected_sequence_number); cifs_pdu->Signature.Sequence.Reserved = 0; - mutex_lock(&server->srv_mutex); rc = cifs_calculate_signature(cifs_pdu, server, what_we_think_sig_should_be); - mutex_unlock(&server->srv_mutex); if (rc) return rc; @@ -472,15 +469,15 @@ static int calc_ntlmv2_hash(struct cifsSesInfo *ses, char *ntlmv2_hash, return rc; } - /* convert ses->user_name to unicode and uppercase */ - len = strlen(ses->user_name); + /* convert ses->userName to unicode and uppercase */ + len = strlen(ses->userName); user = kmalloc(2 + (len * 2), GFP_KERNEL); if (user == NULL) { cERROR(1, "calc_ntlmv2_hash: user mem alloc failure\n"); rc = -ENOMEM; goto calc_exit_2; } - len = cifs_strtoUCS((__le16 *)user, ses->user_name, len, nls_cp); + len = cifs_strtoUCS((__le16 *)user, ses->userName, len, nls_cp); UniStrupr(user); crypto_shash_update(&ses->server->secmech.sdeschmacmd5->shash, diff --git a/trunk/fs/cifs/cifsfs.c b/trunk/fs/cifs/cifsfs.c index 5c412b33cd7c..f2970136d17d 100644 --- a/trunk/fs/cifs/cifsfs.c +++ b/trunk/fs/cifs/cifsfs.c @@ -53,6 +53,7 @@ int cifsFYI = 0; int cifsERROR = 1; int traceSMB = 0; unsigned int oplockEnabled = 1; +unsigned int experimEnabled = 0; unsigned int linuxExtEnabled = 1; unsigned int lookupCacheEnabled = 1; unsigned int multiuser_mount = 0; @@ -126,7 +127,6 @@ cifs_read_super(struct super_block *sb, void *data, kfree(cifs_sb); return rc; } - cifs_sb->bdi.ra_pages = default_backing_dev_info.ra_pages; #ifdef CONFIG_CIFS_DFS_UPCALL /* copy mount params to sb for use in submounts */ @@ -409,8 +409,8 @@ cifs_show_options(struct seq_file *s, struct vfsmount *m) if (cifs_sb->mnt_cifs_flags & CIFS_MOUNT_MULTIUSER) seq_printf(s, ",multiuser"); - else if (tcon->ses->user_name) - seq_printf(s, ",username=%s", tcon->ses->user_name); + else if (tcon->ses->userName) + seq_printf(s, ",username=%s", tcon->ses->userName); if (tcon->ses->domainName) seq_printf(s, ",domain=%s", tcon->ses->domainName); diff --git a/trunk/fs/cifs/cifsglob.h b/trunk/fs/cifs/cifsglob.h index a5d1106fcbde..17afb0fbcaed 100644 --- a/trunk/fs/cifs/cifsglob.h +++ b/trunk/fs/cifs/cifsglob.h @@ -37,9 +37,10 @@ #define MAX_TREE_SIZE (2 + MAX_SERVER_SIZE + 1 + MAX_SHARE_SIZE + 1) #define MAX_SERVER_SIZE 15 -#define MAX_SHARE_SIZE 80 -#define MAX_USERNAME_SIZE 256 /* reasonable maximum for current servers */ -#define MAX_PASSWORD_SIZE 512 /* max for windows seems to be 256 wide chars */ +#define MAX_SHARE_SIZE 64 /* used to be 20, this should still be enough */ +#define MAX_USERNAME_SIZE 32 /* 32 is to allow for 15 char names + null + termination then *2 for unicode versions */ +#define MAX_PASSWORD_SIZE 512 /* max for windows seems to be 256 wide chars */ #define CIFS_MIN_RCV_POOL 4 @@ -91,8 +92,7 @@ enum statusEnum { CifsNew = 0, CifsGood, CifsExiting, - CifsNeedReconnect, - CifsNeedNegotiate + CifsNeedReconnect }; enum securityEnum { @@ -274,7 +274,7 @@ struct cifsSesInfo { int capabilities; char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for TCP names - will ipv6 and sctp addresses fit? */ - char *user_name; + char userName[MAX_USERNAME_SIZE + 1]; char *domainName; char *password; struct session_key auth_key; @@ -817,6 +817,7 @@ GLOBAL_EXTERN unsigned int multiuser_mount; /* if enabled allows new sessions have the uid/password or Kerberos credential or equivalent for current user */ GLOBAL_EXTERN unsigned int oplockEnabled; +GLOBAL_EXTERN unsigned int experimEnabled; GLOBAL_EXTERN unsigned int lookupCacheEnabled; GLOBAL_EXTERN unsigned int global_secflags; /* if on, session setup sent with more secure ntlmssp2 challenge/resp */ diff --git a/trunk/fs/cifs/cifssmb.c b/trunk/fs/cifs/cifssmb.c index df959bae6728..2644a5d6cc67 100644 --- a/trunk/fs/cifs/cifssmb.c +++ b/trunk/fs/cifs/cifssmb.c @@ -142,9 +142,9 @@ cifs_reconnect_tcon(struct cifsTconInfo *tcon, int smb_command) */ while (server->tcpStatus == CifsNeedReconnect) { wait_event_interruptible_timeout(server->response_q, - (server->tcpStatus != CifsNeedReconnect), 10 * HZ); + (server->tcpStatus == CifsGood), 10 * HZ); - /* are we still trying to reconnect? */ + /* is TCP session is reestablished now ?*/ if (server->tcpStatus != CifsNeedReconnect) break; @@ -729,7 +729,7 @@ CIFSSMBEcho(struct TCP_Server_Info *server) return rc; /* set up echo request */ - smb->hdr.Tid = 0xffff; + smb->hdr.Tid = cpu_to_le16(0xffff); smb->hdr.WordCount = 1; put_unaligned_le16(1, &smb->EchoCount); put_bcc_le(1, &smb->hdr); @@ -1884,10 +1884,10 @@ CIFSSMBPosixLock(const int xid, struct cifsTconInfo *tcon, __constant_cpu_to_le16(CIFS_WRLCK)) pLockData->fl_type = F_WRLCK; - pLockData->fl_start = le64_to_cpu(parm_data->start); - pLockData->fl_end = pLockData->fl_start + - le64_to_cpu(parm_data->length) - 1; - pLockData->fl_pid = le32_to_cpu(parm_data->pid); + pLockData->fl_start = parm_data->start; + pLockData->fl_end = parm_data->start + + parm_data->length - 1; + pLockData->fl_pid = parm_data->pid; } } diff --git a/trunk/fs/cifs/connect.c b/trunk/fs/cifs/connect.c index db9d55b507d0..6e2b2addfc78 100644 --- a/trunk/fs/cifs/connect.c +++ b/trunk/fs/cifs/connect.c @@ -199,7 +199,8 @@ cifs_reconnect(struct TCP_Server_Info *server) } spin_unlock(&GlobalMid_Lock); - while (server->tcpStatus == CifsNeedReconnect) { + while ((server->tcpStatus != CifsExiting) && + (server->tcpStatus != CifsGood)) { try_to_freeze(); /* we should try only the port we connected to before */ @@ -211,7 +212,7 @@ cifs_reconnect(struct TCP_Server_Info *server) atomic_inc(&tcpSesReconnectCount); spin_lock(&GlobalMid_Lock); if (server->tcpStatus != CifsExiting) - server->tcpStatus = CifsNeedNegotiate; + server->tcpStatus = CifsGood; spin_unlock(&GlobalMid_Lock); } } @@ -247,24 +248,24 @@ static int check2ndT2(struct smb_hdr *pSMB, unsigned int maxBufSize) total_data_size = get_unaligned_le16(&pSMBt->t2_rsp.TotalDataCount); data_in_this_rsp = get_unaligned_le16(&pSMBt->t2_rsp.DataCount); - if (total_data_size == data_in_this_rsp) + remaining = total_data_size - data_in_this_rsp; + + if (remaining == 0) return 0; - else if (total_data_size < data_in_this_rsp) { + else if (remaining < 0) { cFYI(1, "total data %d smaller than data in frame %d", total_data_size, data_in_this_rsp); return -EINVAL; + } else { + cFYI(1, "missing %d bytes from transact2, check next response", + remaining); + if (total_data_size > maxBufSize) { + cERROR(1, "TotalDataSize %d is over maximum buffer %d", + total_data_size, maxBufSize); + return -EINVAL; + } + return remaining; } - - remaining = total_data_size - data_in_this_rsp; - - cFYI(1, "missing %d bytes from transact2, check next response", - remaining); - if (total_data_size > maxBufSize) { - cERROR(1, "TotalDataSize %d is over maximum buffer %d", - total_data_size, maxBufSize); - return -EINVAL; - } - return remaining; } static int coalesce_t2(struct smb_hdr *psecond, struct smb_hdr *pTargetSMB) @@ -420,7 +421,7 @@ cifs_demultiplex_thread(struct TCP_Server_Info *server) pdu_length = 4; /* enough to get RFC1001 header */ incomplete_rcv: - if (echo_retries > 0 && server->tcpStatus == CifsGood && + if (echo_retries > 0 && time_after(jiffies, server->lstrp + (echo_retries * SMB_ECHO_INTERVAL))) { cERROR(1, "Server %s has not responded in %d seconds. " @@ -880,8 +881,7 @@ cifs_parse_mount_options(char *options, const char *devname, /* null user, ie anonymous, authentication */ vol->nullauth = 1; } - if (strnlen(value, MAX_USERNAME_SIZE) < - MAX_USERNAME_SIZE) { + if (strnlen(value, 200) < 200) { vol->username = value; } else { printk(KERN_WARNING "CIFS: username too long\n"); @@ -1472,7 +1472,7 @@ srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs) static bool match_port(struct TCP_Server_Info *server, struct sockaddr *addr) { - __be16 port, *sport; + unsigned short int port, *sport; switch (addr->sa_family) { case AF_INET: @@ -1765,7 +1765,6 @@ cifs_get_tcp_session(struct smb_vol *volume_info) module_put(THIS_MODULE); goto out_err_crypto_release; } - tcp_ses->tcpStatus = CifsNeedNegotiate; /* thread spawned, put it on the list */ spin_lock(&cifs_tcp_ses_lock); @@ -1809,9 +1808,7 @@ cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol) break; default: /* anything else takes username/password */ - if (ses->user_name == NULL) - continue; - if (strncmp(ses->user_name, vol->username, + if (strncmp(ses->userName, vol->username, MAX_USERNAME_SIZE)) continue; if (strlen(vol->username) != 0 && @@ -1854,8 +1851,6 @@ cifs_put_smb_ses(struct cifsSesInfo *ses) cifs_put_tcp_session(server); } -static bool warned_on_ntlm; /* globals init to false automatically */ - static struct cifsSesInfo * cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info) { @@ -1911,11 +1906,9 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info) else sprintf(ses->serverName, "%pI4", &addr->sin_addr); - if (volume_info->username) { - ses->user_name = kstrdup(volume_info->username, GFP_KERNEL); - if (!ses->user_name) - goto get_ses_fail; - } + if (volume_info->username) + strncpy(ses->userName, volume_info->username, + MAX_USERNAME_SIZE); /* volume_info->password freed at unmount */ if (volume_info->password) { @@ -1930,15 +1923,6 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info) } ses->cred_uid = volume_info->cred_uid; ses->linux_uid = volume_info->linux_uid; - - /* ntlmv2 is much stronger than ntlm security, and has been broadly - supported for many years, time to update default security mechanism */ - if ((volume_info->secFlg == 0) && warned_on_ntlm == false) { - warned_on_ntlm = true; - cERROR(1, "default security mechanism requested. The default " - "security mechanism will be upgraded from ntlm to " - "ntlmv2 in kernel release 2.6.41"); - } ses->overrideSecFlg = volume_info->secFlg; mutex_lock(&ses->session_mutex); @@ -2292,7 +2276,7 @@ static int generic_ip_connect(struct TCP_Server_Info *server) { int rc = 0; - __be16 sport; + unsigned short int sport; int slen, sfamily; struct socket *socket = server->ssocket; struct sockaddr *saddr; @@ -2377,7 +2361,7 @@ generic_ip_connect(struct TCP_Server_Info *server) static int ip_connect(struct TCP_Server_Info *server) { - __be16 *sport; + unsigned short int *sport; struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&server->dstaddr; struct sockaddr_in *addr = (struct sockaddr_in *)&server->dstaddr; @@ -2842,7 +2826,7 @@ cifs_mount(struct super_block *sb, struct cifs_sb_info *cifs_sb, remote_path_check: /* check if a whole path (including prepath) is not remote */ - if (!rc && tcon) { + if (!rc && cifs_sb->prepathlen && tcon) { /* build_path_to_root works only when we have a valid tcon */ full_path = cifs_build_path_to_root(cifs_sb, tcon); if (full_path == NULL) { diff --git a/trunk/fs/cifs/file.c b/trunk/fs/cifs/file.c index faf59529e847..c27d236738fc 100644 --- a/trunk/fs/cifs/file.c +++ b/trunk/fs/cifs/file.c @@ -575,10 +575,8 @@ static int cifs_reopen_file(struct cifsFileInfo *pCifsFile, bool can_flush) int cifs_close(struct inode *inode, struct file *file) { - if (file->private_data != NULL) { - cifsFileInfo_put(file->private_data); - file->private_data = NULL; - } + cifsFileInfo_put(file->private_data); + file->private_data = NULL; /* return code from the ->release op is always ignored */ return 0; @@ -972,9 +970,6 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, total_written += bytes_written) { rc = -EAGAIN; while (rc == -EAGAIN) { - struct kvec iov[2]; - unsigned int len; - if (open_file->invalidHandle) { /* we could deadlock if we called filemap_fdatawait from here so tell @@ -984,14 +979,31 @@ static ssize_t cifs_write(struct cifsFileInfo *open_file, if (rc != 0) break; } - - len = min((size_t)cifs_sb->wsize, - write_size - total_written); - /* iov[0] is reserved for smb header */ - iov[1].iov_base = (char *)write_data + total_written; - iov[1].iov_len = len; - rc = CIFSSMBWrite2(xid, pTcon, open_file->netfid, len, - *poffset, &bytes_written, iov, 1, 0); + if (experimEnabled || (pTcon->ses->server && + ((pTcon->ses->server->secMode & + (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) + == 0))) { + struct kvec iov[2]; + unsigned int len; + + len = min((size_t)cifs_sb->wsize, + write_size - total_written); + /* iov[0] is reserved for smb header */ + iov[1].iov_base = (char *)write_data + + total_written; + iov[1].iov_len = len; + rc = CIFSSMBWrite2(xid, pTcon, + open_file->netfid, len, + *poffset, &bytes_written, + iov, 1, 0); + } else + rc = CIFSSMBWrite(xid, pTcon, + open_file->netfid, + min_t(const int, cifs_sb->wsize, + write_size - total_written), + *poffset, &bytes_written, + write_data + total_written, + NULL, 0); } if (rc || (bytes_written == 0)) { if (total_written) @@ -1228,6 +1240,12 @@ static int cifs_writepages(struct address_space *mapping, } tcon = tlink_tcon(open_file->tlink); + if (!experimEnabled && tcon->ses->server->secMode & + (SECMODE_SIGN_REQUIRED | SECMODE_SIGN_ENABLED)) { + cifsFileInfo_put(open_file); + kfree(iov); + return generic_writepages(mapping, wbc); + } cifsFileInfo_put(open_file); xid = GetXid(); @@ -1962,24 +1980,6 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size, return total_read; } -/* - * If the page is mmap'ed into a process' page tables, then we need to make - * sure that it doesn't change while being written back. - */ -static int -cifs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) -{ - struct page *page = vmf->page; - - lock_page(page); - return VM_FAULT_LOCKED; -} - -static struct vm_operations_struct cifs_file_vm_ops = { - .fault = filemap_fault, - .page_mkwrite = cifs_page_mkwrite, -}; - int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) { int rc, xid; @@ -1991,8 +1991,6 @@ int cifs_file_strict_mmap(struct file *file, struct vm_area_struct *vma) cifs_invalidate_mapping(inode); rc = generic_file_mmap(file, vma); - if (rc == 0) - vma->vm_ops = &cifs_file_vm_ops; FreeXid(xid); return rc; } @@ -2009,8 +2007,6 @@ int cifs_file_mmap(struct file *file, struct vm_area_struct *vma) return rc; } rc = generic_file_mmap(file, vma); - if (rc == 0) - vma->vm_ops = &cifs_file_vm_ops; FreeXid(xid); return rc; } diff --git a/trunk/fs/cifs/link.c b/trunk/fs/cifs/link.c index ce417a9764a3..e8804d373404 100644 --- a/trunk/fs/cifs/link.c +++ b/trunk/fs/cifs/link.c @@ -239,7 +239,7 @@ CIFSQueryMFSymLink(const int xid, struct cifsTconInfo *tcon, if (rc != 0) return rc; - if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) { + if (file_info.EndOfFile != CIFS_MF_SYMLINK_FILE_SIZE) { CIFSSMBClose(xid, tcon, netfid); /* it's not a symlink */ return -EINVAL; @@ -316,7 +316,7 @@ CIFSCheckMFSymlink(struct cifs_fattr *fattr, if (rc != 0) goto out; - if (file_info.EndOfFile != cpu_to_le64(CIFS_MF_SYMLINK_FILE_SIZE)) { + if (file_info.EndOfFile != CIFS_MF_SYMLINK_FILE_SIZE) { CIFSSMBClose(xid, pTcon, netfid); /* it's not a symlink */ goto out; diff --git a/trunk/fs/cifs/misc.c b/trunk/fs/cifs/misc.c index 0c684ae4c071..2a930a752a78 100644 --- a/trunk/fs/cifs/misc.c +++ b/trunk/fs/cifs/misc.c @@ -100,7 +100,6 @@ sesInfoFree(struct cifsSesInfo *buf_to_free) memset(buf_to_free->password, 0, strlen(buf_to_free->password)); kfree(buf_to_free->password); } - kfree(buf_to_free->user_name); kfree(buf_to_free->domainName); kfree(buf_to_free); } @@ -521,7 +520,7 @@ is_valid_oplock_break(struct smb_hdr *buf, struct TCP_Server_Info *srv) (struct smb_com_transaction_change_notify_rsp *)buf; struct file_notify_information *pnotify; __u32 data_offset = 0; - if (get_bcc_le(buf) > sizeof(struct file_notify_information)) { + if (pSMBr->ByteCount > sizeof(struct file_notify_information)) { data_offset = le32_to_cpu(pSMBr->DataOffset); pnotify = (struct file_notify_information *) diff --git a/trunk/fs/cifs/sess.c b/trunk/fs/cifs/sess.c index f6728eb6f4b9..16765703131b 100644 --- a/trunk/fs/cifs/sess.c +++ b/trunk/fs/cifs/sess.c @@ -219,12 +219,12 @@ static void unicode_ssetup_strings(char **pbcc_area, struct cifsSesInfo *ses, bcc_ptr++; } */ /* copy user */ - if (ses->user_name == NULL) { + if (ses->userName == NULL) { /* null user mount */ *bcc_ptr = 0; *(bcc_ptr+1) = 0; } else { - bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, ses->user_name, + bytes_ret = cifs_strtoUCS((__le16 *) bcc_ptr, ses->userName, MAX_USERNAME_SIZE, nls_cp); } bcc_ptr += 2 * bytes_ret; @@ -244,11 +244,12 @@ static void ascii_ssetup_strings(char **pbcc_area, struct cifsSesInfo *ses, /* copy user */ /* BB what about null user mounts - check that we do this BB */ /* copy user */ - if (ses->user_name != NULL) - strncpy(bcc_ptr, ses->user_name, MAX_USERNAME_SIZE); - /* else null user mount */ - - bcc_ptr += strnlen(ses->user_name, MAX_USERNAME_SIZE); + if (ses->userName == NULL) { + /* BB what about null user mounts - check that we do this BB */ + } else { + strncpy(bcc_ptr, ses->userName, MAX_USERNAME_SIZE); + } + bcc_ptr += strnlen(ses->userName, MAX_USERNAME_SIZE); *bcc_ptr = 0; bcc_ptr++; /* account for null termination */ @@ -404,8 +405,8 @@ static int decode_ntlmssp_challenge(char *bcc_ptr, int blob_len, /* BB spec says that if AvId field of MsvAvTimestamp is populated then we must set the MIC field of the AUTHENTICATE_MESSAGE */ ses->ntlmssp->server_flags = le32_to_cpu(pblob->NegotiateFlags); - tioffset = le32_to_cpu(pblob->TargetInfoArray.BufferOffset); - tilen = le16_to_cpu(pblob->TargetInfoArray.Length); + tioffset = cpu_to_le16(pblob->TargetInfoArray.BufferOffset); + tilen = cpu_to_le16(pblob->TargetInfoArray.Length); if (tilen) { ses->auth_key.response = kmalloc(tilen, GFP_KERNEL); if (!ses->auth_key.response) { @@ -522,14 +523,14 @@ static int build_ntlmssp_auth_blob(unsigned char *pbuffer, tmp += len; } - if (ses->user_name == NULL) { + if (ses->userName == NULL) { sec_blob->UserName.BufferOffset = cpu_to_le32(tmp - pbuffer); sec_blob->UserName.Length = 0; sec_blob->UserName.MaximumLength = 0; tmp += 2; } else { int len; - len = cifs_strtoUCS((__le16 *)tmp, ses->user_name, + len = cifs_strtoUCS((__le16 *)tmp, ses->userName, MAX_USERNAME_SIZE, nls_cp); len *= 2; /* unicode is 2 bytes each */ sec_blob->UserName.BufferOffset = cpu_to_le32(tmp - pbuffer); diff --git a/trunk/fs/dcache.c b/trunk/fs/dcache.c index 129a35730994..ad25c4cec7d5 100644 --- a/trunk/fs/dcache.c +++ b/trunk/fs/dcache.c @@ -2131,7 +2131,7 @@ EXPORT_SYMBOL(d_rehash); */ void dentry_update_name_case(struct dentry *dentry, struct qstr *name) { - BUG_ON(!mutex_is_locked(&dentry->d_parent->d_inode->i_mutex)); + BUG_ON(!mutex_is_locked(&dentry->d_inode->i_mutex)); BUG_ON(dentry->d_name.len != name->len); /* d_lookup gives this */ spin_lock(&dentry->d_lock); diff --git a/trunk/fs/ext3/inode.c b/trunk/fs/ext3/inode.c index 68b2e43d7c35..b5c2f3c97d71 100644 --- a/trunk/fs/ext3/inode.c +++ b/trunk/fs/ext3/inode.c @@ -3291,7 +3291,7 @@ static int ext3_writepage_trans_blocks(struct inode *inode) if (ext3_should_journal_data(inode)) ret = 3 * (bpp + indirects) + 2; else - ret = 2 * (bpp + indirects) + indirects + 2; + ret = 2 * (bpp + indirects) + 2; #ifdef CONFIG_QUOTA /* We know that structure was already allocated during dquot_initialize so diff --git a/trunk/fs/ext4/ext4_jbd2.h b/trunk/fs/ext4/ext4_jbd2.h index d0f53538a57f..e25e99bf7ee1 100644 --- a/trunk/fs/ext4/ext4_jbd2.h +++ b/trunk/fs/ext4/ext4_jbd2.h @@ -86,8 +86,8 @@ #ifdef CONFIG_QUOTA /* Amount of blocks needed for quota update - we know that the structure was - * allocated so we need to update only data block */ -#define EXT4_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 1 : 0) + * allocated so we need to update only inode+data */ +#define EXT4_QUOTA_TRANS_BLOCKS(sb) (test_opt(sb, QUOTA) ? 2 : 0) /* Amount of blocks needed for quota insert/delete - we do some block writes * but inode, sb and group updates are done only once */ #define EXT4_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\ diff --git a/trunk/fs/ext4/fsync.c b/trunk/fs/ext4/fsync.c index e9473cbe80df..4673bc05274f 100644 --- a/trunk/fs/ext4/fsync.c +++ b/trunk/fs/ext4/fsync.c @@ -125,11 +125,9 @@ extern int ext4_flush_completed_IO(struct inode *inode) * the parent directory's parent as well, and so on recursively, if * they are also freshly created. */ -static int ext4_sync_parent(struct inode *inode) +static void ext4_sync_parent(struct inode *inode) { - struct writeback_control wbc; struct dentry *dentry = NULL; - int ret = 0; while (inode && ext4_test_inode_state(inode, EXT4_STATE_NEWENTRY)) { ext4_clear_inode_state(inode, EXT4_STATE_NEWENTRY); @@ -138,17 +136,8 @@ static int ext4_sync_parent(struct inode *inode) if (!dentry || !dentry->d_parent || !dentry->d_parent->d_inode) break; inode = dentry->d_parent->d_inode; - ret = sync_mapping_buffers(inode->i_mapping); - if (ret) - break; - memset(&wbc, 0, sizeof(wbc)); - wbc.sync_mode = WB_SYNC_ALL; - wbc.nr_to_write = 0; /* only write out the inode */ - ret = sync_inode(inode, &wbc); - if (ret) - break; + sync_mapping_buffers(inode->i_mapping); } - return ret; } /* @@ -187,7 +176,7 @@ int ext4_sync_file(struct file *file, int datasync) if (!journal) { ret = generic_file_fsync(file, datasync); if (!ret && !list_empty(&inode->i_dentry)) - ret = ext4_sync_parent(inode); + ext4_sync_parent(inode); goto out; } diff --git a/trunk/fs/ext4/inode.c b/trunk/fs/ext4/inode.c index f2fa5e8a582c..ad8e303c0d29 100644 --- a/trunk/fs/ext4/inode.c +++ b/trunk/fs/ext4/inode.c @@ -2502,7 +2502,6 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, * for partial write. */ set_buffer_new(bh); - set_buffer_mapped(bh); } return 0; } @@ -4430,8 +4429,8 @@ void ext4_truncate(struct inode *inode) Indirect chain[4]; Indirect *partial; __le32 nr = 0; - int n = 0; - ext4_lblk_t last_block, max_block; + int n; + ext4_lblk_t last_block; unsigned blocksize = inode->i_sb->s_blocksize; trace_ext4_truncate_enter(inode); @@ -4456,18 +4455,14 @@ void ext4_truncate(struct inode *inode) last_block = (inode->i_size + blocksize-1) >> EXT4_BLOCK_SIZE_BITS(inode->i_sb); - max_block = (EXT4_SB(inode->i_sb)->s_bitmap_maxbytes + blocksize-1) - >> EXT4_BLOCK_SIZE_BITS(inode->i_sb); if (inode->i_size & (blocksize - 1)) if (ext4_block_truncate_page(handle, mapping, inode->i_size)) goto out_stop; - if (last_block != max_block) { - n = ext4_block_to_path(inode, last_block, offsets, NULL); - if (n == 0) - goto out_stop; /* error */ - } + n = ext4_block_to_path(inode, last_block, offsets, NULL); + if (n == 0) + goto out_stop; /* error */ /* * OK. This truncate is going to happen. We add the inode to the @@ -4498,13 +4493,7 @@ void ext4_truncate(struct inode *inode) */ ei->i_disksize = inode->i_size; - if (last_block == max_block) { - /* - * It is unnecessary to free any data blocks if last_block is - * equal to the indirect block limit. - */ - goto out_unlock; - } else if (n == 1) { /* direct blocks */ + if (n == 1) { /* direct blocks */ ext4_free_data(handle, inode, NULL, i_data+offsets[0], i_data + EXT4_NDIR_BLOCKS); goto do_indirects; @@ -4564,7 +4553,6 @@ void ext4_truncate(struct inode *inode) ; } -out_unlock: up_write(&ei->i_data_sem); inode->i_mtime = inode->i_ctime = ext4_current_time(inode); ext4_mark_inode_dirty(handle, inode); @@ -5410,12 +5398,13 @@ static int ext4_indirect_trans_blocks(struct inode *inode, int nrblocks, /* if nrblocks are contiguous */ if (chunk) { /* - * With N contiguous data blocks, we need at most - * N/EXT4_ADDR_PER_BLOCK(inode->i_sb) + 1 indirect blocks, - * 2 dindirect blocks, and 1 tindirect block + * With N contiguous data blocks, it need at most + * N/EXT4_ADDR_PER_BLOCK(inode->i_sb) indirect blocks + * 2 dindirect blocks + * 1 tindirect block */ - return DIV_ROUND_UP(nrblocks, - EXT4_ADDR_PER_BLOCK(inode->i_sb)) + 4; + indirects = nrblocks / EXT4_ADDR_PER_BLOCK(inode->i_sb); + return indirects + 3; } /* * if nrblocks are not contiguous, worse case, each block touch diff --git a/trunk/fs/ext4/super.c b/trunk/fs/ext4/super.c index 8553dfb310af..056474b7b8e0 100644 --- a/trunk/fs/ext4/super.c +++ b/trunk/fs/ext4/super.c @@ -242,44 +242,27 @@ static void ext4_put_nojournal(handle_t *handle) * journal_end calls result in the superblock being marked dirty, so * that sync() will call the filesystem's write_super callback if * appropriate. - * - * To avoid j_barrier hold in userspace when a user calls freeze(), - * ext4 prevents a new handle from being started by s_frozen, which - * is in an upper layer. */ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks) { journal_t *journal; - handle_t *handle; if (sb->s_flags & MS_RDONLY) return ERR_PTR(-EROFS); - journal = EXT4_SB(sb)->s_journal; - handle = ext4_journal_current_handle(); - - /* - * If a handle has been started, it should be allowed to - * finish, otherwise deadlock could happen between freeze - * and others(e.g. truncate) due to the restart of the - * journal handle if the filesystem is forzen and active - * handles are not stopped. - */ - if (!handle) - vfs_check_frozen(sb, SB_FREEZE_TRANS); - - if (!journal) - return ext4_get_nojournal(); - /* - * Special case here: if the journal has aborted behind our + vfs_check_frozen(sb, SB_FREEZE_TRANS); + /* Special case here: if the journal has aborted behind our * backs (eg. EIO in the commit thread), then we still need to - * take the FS itself readonly cleanly. - */ - if (is_journal_aborted(journal)) { - ext4_abort(sb, "Detected aborted journal"); - return ERR_PTR(-EROFS); + * take the FS itself readonly cleanly. */ + journal = EXT4_SB(sb)->s_journal; + if (journal) { + if (is_journal_aborted(journal)) { + ext4_abort(sb, "Detected aborted journal"); + return ERR_PTR(-EROFS); + } + return jbd2_journal_start(journal, nblocks); } - return jbd2_journal_start(journal, nblocks); + return ext4_get_nojournal(); } /* @@ -2992,12 +2975,6 @@ static int ext4_register_li_request(struct super_block *sb, mutex_unlock(&ext4_li_info->li_list_mtx); sbi->s_li_request = elr; - /* - * set elr to NULL here since it has been inserted to - * the request_list and the removal and free of it is - * handled by ext4_clear_request_list from now on. - */ - elr = NULL; if (!(ext4_li_info->li_state & EXT4_LAZYINIT_RUNNING)) { ret = ext4_run_lazyinit_thread(); @@ -3408,10 +3385,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) get_random_bytes(&sbi->s_next_generation, sizeof(u32)); spin_lock_init(&sbi->s_next_gen_lock); - init_timer(&sbi->s_err_report); - sbi->s_err_report.function = print_daily_error_info; - sbi->s_err_report.data = (unsigned long) sb; - err = percpu_counter_init(&sbi->s_freeblocks_counter, ext4_count_free_blocks(sb)); if (!err) { @@ -3673,6 +3646,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) "Opts: %s%s%s", descr, sbi->s_es->s_mount_opts, *sbi->s_es->s_mount_opts ? "; " : "", orig_data); + init_timer(&sbi->s_err_report); + sbi->s_err_report.function = print_daily_error_info; + sbi->s_err_report.data = (unsigned long) sb; if (es->s_error_count) mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */ @@ -3696,7 +3672,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_journal = NULL; } failed_mount3: - del_timer(&sbi->s_err_report); if (sbi->s_flex_groups) { if (is_vmalloc_addr(sbi->s_flex_groups)) vfree(sbi->s_flex_groups); @@ -4163,11 +4138,6 @@ static int ext4_sync_fs(struct super_block *sb, int wait) /* * LVM calls this function before a (read-only) snapshot is created. This * gives us a chance to flush the journal completely and mark the fs clean. - * - * Note that only this function cannot bring a filesystem to be in a clean - * state independently, because ext4 prevents a new handle from being started - * by @sb->s_frozen, which stays in an upper layer. It thus needs help from - * the upper layer. */ static int ext4_freeze(struct super_block *sb) { @@ -4644,24 +4614,11 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id, static int ext4_quota_off(struct super_block *sb, int type) { - struct inode *inode = sb_dqopt(sb)->files[type]; - handle_t *handle; - /* Force all delayed allocation blocks to be allocated. * Caller already holds s_umount sem */ if (test_opt(sb, DELALLOC)) sync_filesystem(sb); - /* Update modification times of quota files when userspace can - * start looking at them */ - handle = ext4_journal_start(inode, 1); - if (IS_ERR(handle)) - goto out; - inode->i_mtime = inode->i_ctime = CURRENT_TIME; - ext4_mark_inode_dirty(handle, inode); - ext4_journal_stop(handle); - -out: return dquot_quota_off(sb, type); } @@ -4757,8 +4714,9 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, if (inode->i_size < off + len) { i_size_write(inode, off + len); EXT4_I(inode)->i_disksize = inode->i_size; - ext4_mark_inode_dirty(handle, inode); } + inode->i_mtime = inode->i_ctime = CURRENT_TIME; + ext4_mark_inode_dirty(handle, inode); mutex_unlock(&inode->i_mutex); return len; } diff --git a/trunk/fs/fhandle.c b/trunk/fs/fhandle.c index 6b088641f5bf..bf93ad2bee07 100644 --- a/trunk/fs/fhandle.c +++ b/trunk/fs/fhandle.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include "internal.h" diff --git a/trunk/fs/filesystems.c b/trunk/fs/filesystems.c index 0845f84f2a5f..751d6b255a12 100644 --- a/trunk/fs/filesystems.c +++ b/trunk/fs/filesystems.c @@ -110,13 +110,14 @@ int unregister_filesystem(struct file_system_type * fs) *tmp = fs->next; fs->next = NULL; write_unlock(&file_systems_lock); - synchronize_rcu(); return 0; } tmp = &(*tmp)->next; } write_unlock(&file_systems_lock); + synchronize_rcu(); + return -EINVAL; } diff --git a/trunk/fs/jbd2/commit.c b/trunk/fs/jbd2/commit.c index 6e28000a4b21..20af62f4304b 100644 --- a/trunk/fs/jbd2/commit.c +++ b/trunk/fs/jbd2/commit.c @@ -105,8 +105,6 @@ static int journal_submit_commit_record(journal_t *journal, int ret; struct timespec now = current_kernel_time(); - *cbh = NULL; - if (is_journal_aborted(journal)) return 0; @@ -808,7 +806,7 @@ void jbd2_journal_commit_transaction(journal_t *journal) if (err) __jbd2_journal_abort_hard(journal); } - if (cbh) + if (!err && !is_journal_aborted(journal)) err = journal_wait_on_commit_record(journal, cbh); if (JBD2_HAS_INCOMPAT_FEATURE(journal, JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT) && diff --git a/trunk/fs/jbd2/journal.c b/trunk/fs/jbd2/journal.c index e0ec3db1c395..aba8ebaec25c 100644 --- a/trunk/fs/jbd2/journal.c +++ b/trunk/fs/jbd2/journal.c @@ -2413,12 +2413,10 @@ const char *jbd2_dev_to_name(dev_t device) new_dev = kmalloc(sizeof(struct devname_cache), GFP_KERNEL); if (!new_dev) return "NODEV-ALLOCFAILURE"; /* Something non-NULL */ - bd = bdget(device); spin_lock(&devname_cache_lock); if (devcache[i]) { if (devcache[i]->device == device) { kfree(new_dev); - bdput(bd); ret = devcache[i]->devname; spin_unlock(&devname_cache_lock); return ret; @@ -2427,6 +2425,7 @@ const char *jbd2_dev_to_name(dev_t device) } devcache[i] = new_dev; devcache[i]->device = device; + bd = bdget(device); if (bd) { bdevname(bd, devcache[i]->devname); bdput(bd); diff --git a/trunk/fs/namei.c b/trunk/fs/namei.c index 54fc993e3027..e6cd6113872c 100644 --- a/trunk/fs/namei.c +++ b/trunk/fs/namei.c @@ -697,7 +697,6 @@ static __always_inline void set_root_rcu(struct nameidata *nd) do { seq = read_seqcount_begin(&fs->seq); nd->root = fs->root; - nd->seq = __read_seqcount_begin(&nd->root.dentry->d_seq); } while (read_seqcount_retry(&fs->seq, seq)); } } diff --git a/trunk/fs/namespace.c b/trunk/fs/namespace.c index d99bcf59e4c2..7dba2ed03429 100644 --- a/trunk/fs/namespace.c +++ b/trunk/fs/namespace.c @@ -1030,6 +1030,18 @@ const struct seq_operations mounts_op = { .show = show_vfsmnt }; +static int uuid_is_nil(u8 *uuid) +{ + int i; + u8 *cp = (u8 *)uuid; + + for (i = 0; i < 16; i++) { + if (*cp++) + return 0; + } + return 1; +} + static int show_mountinfo(struct seq_file *m, void *v) { struct proc_mounts *p = m->private; @@ -1073,6 +1085,10 @@ static int show_mountinfo(struct seq_file *m, void *v) if (IS_MNT_UNBINDABLE(mnt)) seq_puts(m, " unbindable"); + if (!uuid_is_nil(mnt->mnt_sb->s_uuid)) + /* print the uuid */ + seq_printf(m, " uuid:%pU", mnt->mnt_sb->s_uuid); + /* Filesystem specific data */ seq_puts(m, " - "); show_type(m, sb); diff --git a/trunk/fs/nfs/namespace.c b/trunk/fs/nfs/namespace.c index 89fc160fd5b0..9166fcb66da2 100644 --- a/trunk/fs/nfs/namespace.c +++ b/trunk/fs/nfs/namespace.c @@ -148,64 +148,67 @@ static rpc_authflavor_t nfs_find_best_sec(struct nfs4_secinfo_flavors *flavors, return pseudoflavor; } -static int nfs_negotiate_security(const struct dentry *parent, - const struct dentry *dentry, - rpc_authflavor_t *flavor) +static rpc_authflavor_t nfs_negotiate_security(const struct dentry *parent, const struct dentry *dentry) { + int status = 0; struct page *page; struct nfs4_secinfo_flavors *flavors; int (*secinfo)(struct inode *, const struct qstr *, struct nfs4_secinfo_flavors *); - int ret = -EPERM; + rpc_authflavor_t flavor = RPC_AUTH_UNIX; secinfo = NFS_PROTO(parent->d_inode)->secinfo; if (secinfo != NULL) { page = alloc_page(GFP_KERNEL); if (!page) { - ret = -ENOMEM; + status = -ENOMEM; goto out; } flavors = page_address(page); - ret = secinfo(parent->d_inode, &dentry->d_name, flavors); - *flavor = nfs_find_best_sec(flavors, dentry->d_inode); + status = secinfo(parent->d_inode, &dentry->d_name, flavors); + flavor = nfs_find_best_sec(flavors, dentry->d_inode); put_page(page); } + return flavor; + out: - return ret; + status = -ENOMEM; + return status; } -static int nfs_lookup_with_sec(struct nfs_server *server, struct dentry *parent, - struct dentry *dentry, struct path *path, - struct nfs_fh *fh, struct nfs_fattr *fattr, - rpc_authflavor_t *flavor) +static rpc_authflavor_t nfs_lookup_with_sec(struct nfs_server *server, struct dentry *parent, + struct dentry *dentry, struct path *path, + struct nfs_fh *fh, struct nfs_fattr *fattr) { + rpc_authflavor_t flavor; struct rpc_clnt *clone; struct rpc_auth *auth; int err; - err = nfs_negotiate_security(parent, path->dentry, flavor); - if (err < 0) + flavor = nfs_negotiate_security(parent, path->dentry); + if (flavor < 0) goto out; clone = rpc_clone_client(server->client); - auth = rpcauth_create(*flavor, clone); + auth = rpcauth_create(flavor, clone); if (!auth) { - err = -EIO; + flavor = -EIO; goto out_shutdown; } err = server->nfs_client->rpc_ops->lookup(clone, parent->d_inode, &path->dentry->d_name, fh, fattr); + if (err < 0) + flavor = err; out_shutdown: rpc_shutdown_client(clone); out: - return err; + return flavor; } #else /* CONFIG_NFS_V4 */ -static inline int nfs_lookup_with_sec(struct nfs_server *server, - struct dentry *parent, struct dentry *dentry, - struct path *path, struct nfs_fh *fh, - struct nfs_fattr *fattr, - rpc_authflavor_t *flavor) +static inline rpc_authflavor_t nfs_lookup_with_sec(struct nfs_server *server, + struct dentry *parent, struct dentry *dentry, + struct path *path, struct nfs_fh *fh, + struct nfs_fattr *fattr) { return -EPERM; } @@ -231,7 +234,7 @@ struct vfsmount *nfs_d_automount(struct path *path) struct nfs_fh *fh = NULL; struct nfs_fattr *fattr = NULL; int err; - rpc_authflavor_t flavor = RPC_AUTH_UNIX; + rpc_authflavor_t flavor = 1; dprintk("--> nfs_d_automount()\n"); @@ -252,8 +255,13 @@ struct vfsmount *nfs_d_automount(struct path *path) err = server->nfs_client->rpc_ops->lookup(server->client, parent->d_inode, &path->dentry->d_name, fh, fattr); - if (err == -EPERM && NFS_PROTO(parent->d_inode)->secinfo != NULL) - err = nfs_lookup_with_sec(server, parent, path->dentry, path, fh, fattr, &flavor); + if (err == -EPERM) { + flavor = nfs_lookup_with_sec(server, parent, path->dentry, path, fh, fattr); + if (flavor < 0) + err = flavor; + else + err = 0; + } dput(parent); if (err != 0) { mnt = ERR_PTR(err); diff --git a/trunk/fs/nfs/nfs4proc.c b/trunk/fs/nfs/nfs4proc.c index 9bf41eab3e46..dfd1e6d7e6c3 100644 --- a/trunk/fs/nfs/nfs4proc.c +++ b/trunk/fs/nfs/nfs4proc.c @@ -2204,6 +2204,8 @@ static int nfs4_lookup_root_sec(struct nfs_server *server, struct nfs_fh *fhandl goto out; } ret = nfs4_lookup_root(server, fhandle, info); + if (ret < 0) + ret = -EAGAIN; out: return ret; } @@ -2224,7 +2226,7 @@ static int nfs4_proc_get_root(struct nfs_server *server, struct nfs_fh *fhandle, for (i = 0; i < len; i++) { status = nfs4_lookup_root_sec(server, fhandle, info, flav_array[i]); - if (status != -EPERM) + if (status == 0) break; } if (status == 0) diff --git a/trunk/fs/nfs/write.c b/trunk/fs/nfs/write.c index e4cbc11a74ab..af0c6279a4a7 100644 --- a/trunk/fs/nfs/write.c +++ b/trunk/fs/nfs/write.c @@ -542,15 +542,11 @@ nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, u if (!nfs_need_commit(nfsi)) return 0; - spin_lock(&inode->i_lock); ret = nfs_scan_list(nfsi, dst, idx_start, npages, NFS_PAGE_TAG_COMMIT); if (ret > 0) nfsi->ncommit -= ret; - spin_unlock(&inode->i_lock); - if (nfs_need_commit(NFS_I(inode))) __mark_inode_dirty(inode, I_DIRTY_DATASYNC); - return ret; } #else @@ -1487,7 +1483,9 @@ int nfs_commit_inode(struct inode *inode, int how) res = nfs_commit_set_lock(NFS_I(inode), may_wait); if (res <= 0) goto out_mark_dirty; + spin_lock(&inode->i_lock); res = nfs_scan_commit(inode, &head, 0, 0); + spin_unlock(&inode->i_lock); if (res) { int error; diff --git a/trunk/fs/nfsd/lockd.c b/trunk/fs/nfsd/lockd.c index 7c831a2731fa..0c6d81670137 100644 --- a/trunk/fs/nfsd/lockd.c +++ b/trunk/fs/nfsd/lockd.c @@ -38,6 +38,7 @@ nlm_fopen(struct svc_rqst *rqstp, struct nfs_fh *f, struct file **filp) exp_readlock(); nfserr = nfsd_open(rqstp, &fh, S_IFREG, NFSD_MAY_LOCK, filp); fh_put(&fh); + rqstp->rq_client = NULL; exp_readunlock(); /* We return nlm error codes as nlm doesn't know * about nfsd, but nfsd does know about nlm.. diff --git a/trunk/fs/nfsd/nfs4state.c b/trunk/fs/nfsd/nfs4state.c index aa309aa93fe8..4b36ec3eb8ea 100644 --- a/trunk/fs/nfsd/nfs4state.c +++ b/trunk/fs/nfsd/nfs4state.c @@ -397,13 +397,10 @@ static void unhash_generic_stateid(struct nfs4_stateid *stp) static void free_generic_stateid(struct nfs4_stateid *stp) { - int oflag; + int oflag = nfs4_access_bmap_to_omode(stp); - if (stp->st_access_bmap) { - oflag = nfs4_access_bmap_to_omode(stp); - nfs4_file_put_access(stp->st_file, oflag); - put_nfs4_file(stp->st_file); - } + nfs4_file_put_access(stp->st_file, oflag); + put_nfs4_file(stp->st_file); kmem_cache_free(stateid_slab, stp); } diff --git a/trunk/fs/partitions/ldm.c b/trunk/fs/partitions/ldm.c index ce4f62440425..b10e3540d5b7 100644 --- a/trunk/fs/partitions/ldm.c +++ b/trunk/fs/partitions/ldm.c @@ -1299,11 +1299,6 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) BUG_ON (!data || !frags); - if (size < 2 * VBLK_SIZE_HEAD) { - ldm_error("Value of size is to small."); - return false; - } - group = get_unaligned_be32(data + 0x08); rec = get_unaligned_be16(data + 0x0C); num = get_unaligned_be16(data + 0x0E); @@ -1311,10 +1306,6 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) ldm_error ("A VBLK claims to have %d parts.", num); return false; } - if (rec >= num) { - ldm_error("REC value (%d) exceeds NUM value (%d)", rec, num); - return false; - } list_for_each (item, frags) { f = list_entry (item, struct frag, list); @@ -1343,9 +1334,10 @@ static bool ldm_frag_add (const u8 *data, int size, struct list_head *frags) f->map |= (1 << rec); - data += VBLK_SIZE_HEAD; - size -= VBLK_SIZE_HEAD; - + if (num > 0) { + data += VBLK_SIZE_HEAD; + size -= VBLK_SIZE_HEAD; + } memcpy (f->data+rec*(size-VBLK_SIZE_HEAD)+VBLK_SIZE_HEAD, data, size); return true; diff --git a/trunk/fs/proc/base.c b/trunk/fs/proc/base.c index dfa532730e55..dd6628d3ba42 100644 --- a/trunk/fs/proc/base.c +++ b/trunk/fs/proc/base.c @@ -3124,16 +3124,11 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi /* for the /proc/ directory itself, after non-process stuff has been done */ int proc_pid_readdir(struct file * filp, void * dirent, filldir_t filldir) { - unsigned int nr; - struct task_struct *reaper; + unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY; + struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode); struct tgid_iter iter; struct pid_namespace *ns; - if (filp->f_pos >= PID_MAX_LIMIT + TGID_OFFSET) - goto out_no_task; - nr = filp->f_pos - FIRST_PROCESS_ENTRY; - - reaper = get_proc_task(filp->f_path.dentry->d_inode); if (!reaper) goto out_no_task; diff --git a/trunk/fs/quota/dquot.c b/trunk/fs/quota/dquot.c index d3c032f5fa0a..a925bf205497 100644 --- a/trunk/fs/quota/dquot.c +++ b/trunk/fs/quota/dquot.c @@ -442,7 +442,7 @@ EXPORT_SYMBOL(dquot_acquire); */ int dquot_commit(struct dquot *dquot) { - int ret = 0; + int ret = 0, ret2 = 0; struct quota_info *dqopt = sb_dqopt(dquot->dq_sb); mutex_lock(&dqopt->dqio_mutex); @@ -454,10 +454,15 @@ int dquot_commit(struct dquot *dquot) spin_unlock(&dq_list_lock); /* Inactive dquot can be only if there was error during read/init * => we have better not writing it */ - if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) + if (test_bit(DQ_ACTIVE_B, &dquot->dq_flags)) { ret = dqopt->ops[dquot->dq_type]->commit_dqblk(dquot); - else - ret = -EIO; + if (info_dirty(&dqopt->info[dquot->dq_type])) { + ret2 = dqopt->ops[dquot->dq_type]->write_file_info( + dquot->dq_sb, dquot->dq_type); + } + if (ret >= 0) + ret = ret2; + } out_sem: mutex_unlock(&dqopt->dqio_mutex); return ret; diff --git a/trunk/fs/ramfs/file-nommu.c b/trunk/fs/ramfs/file-nommu.c index fbb0b478a346..9eead2c796b7 100644 --- a/trunk/fs/ramfs/file-nommu.c +++ b/trunk/fs/ramfs/file-nommu.c @@ -112,7 +112,6 @@ int ramfs_nommu_expand_for_mapping(struct inode *inode, size_t newsize) SetPageDirty(page); unlock_page(page); - put_page(page); } return 0; diff --git a/trunk/fs/ubifs/debug.h b/trunk/fs/ubifs/debug.h index e6493cac193d..919f0de29d8f 100644 --- a/trunk/fs/ubifs/debug.h +++ b/trunk/fs/ubifs/debug.h @@ -23,12 +23,6 @@ #ifndef __UBIFS_DEBUG_H__ #define __UBIFS_DEBUG_H__ -/* Checking helper functions */ -typedef int (*dbg_leaf_callback)(struct ubifs_info *c, - struct ubifs_zbranch *zbr, void *priv); -typedef int (*dbg_znode_callback)(struct ubifs_info *c, - struct ubifs_znode *znode, void *priv); - #ifdef CONFIG_UBIFS_FS_DEBUG /** @@ -276,6 +270,11 @@ void dbg_dump_tnc(struct ubifs_info *c); void dbg_dump_index(struct ubifs_info *c); void dbg_dump_lpt_lebs(const struct ubifs_info *c); +/* Checking helper functions */ +typedef int (*dbg_leaf_callback)(struct ubifs_info *c, + struct ubifs_zbranch *zbr, void *priv); +typedef int (*dbg_znode_callback)(struct ubifs_info *c, + struct ubifs_znode *znode, void *priv); int dbg_walk_index(struct ubifs_info *c, dbg_leaf_callback leaf_cb, dbg_znode_callback znode_cb, void *priv); @@ -296,6 +295,7 @@ int dbg_check_idx_size(struct ubifs_info *c, long long idx_size); int dbg_check_filesystem(struct ubifs_info *c); void dbg_check_heap(struct ubifs_info *c, struct ubifs_lpt_heap *heap, int cat, int add_pos); +int dbg_check_lprops(struct ubifs_info *c); int dbg_check_lpt_nodes(struct ubifs_info *c, struct ubifs_cnode *cnode, int row, int col); int dbg_check_inode_size(struct ubifs_info *c, const struct inode *inode, @@ -401,94 +401,58 @@ void dbg_debugfs_exit_fs(struct ubifs_info *c); #define DBGKEY(key) ((char *)(key)) #define DBGKEY1(key) ((char *)(key)) -static inline int ubifs_debugging_init(struct ubifs_info *c) { return 0; } -static inline void ubifs_debugging_exit(struct ubifs_info *c) { return; } -static inline const char *dbg_ntype(int type) { return ""; } -static inline const char *dbg_cstate(int cmt_state) { return ""; } -static inline const char *dbg_jhead(int jhead) { return ""; } -static inline const char * -dbg_get_key_dump(const struct ubifs_info *c, - const union ubifs_key *key) { return ""; } -static inline void dbg_dump_inode(const struct ubifs_info *c, - const struct inode *inode) { return; } -static inline void dbg_dump_node(const struct ubifs_info *c, - const void *node) { return; } -static inline void dbg_dump_lpt_node(const struct ubifs_info *c, - void *node, int lnum, - int offs) { return; } -static inline void -dbg_dump_budget_req(const struct ubifs_budget_req *req) { return; } -static inline void -dbg_dump_lstats(const struct ubifs_lp_stats *lst) { return; } -static inline void dbg_dump_budg(struct ubifs_info *c) { return; } -static inline void dbg_dump_lprop(const struct ubifs_info *c, - const struct ubifs_lprops *lp) { return; } -static inline void dbg_dump_lprops(struct ubifs_info *c) { return; } -static inline void dbg_dump_lpt_info(struct ubifs_info *c) { return; } -static inline void dbg_dump_leb(const struct ubifs_info *c, - int lnum) { return; } -static inline void -dbg_dump_znode(const struct ubifs_info *c, - const struct ubifs_znode *znode) { return; } -static inline void dbg_dump_heap(struct ubifs_info *c, - struct ubifs_lpt_heap *heap, - int cat) { return; } -static inline void dbg_dump_pnode(struct ubifs_info *c, - struct ubifs_pnode *pnode, - struct ubifs_nnode *parent, - int iip) { return; } -static inline void dbg_dump_tnc(struct ubifs_info *c) { return; } -static inline void dbg_dump_index(struct ubifs_info *c) { return; } -static inline void dbg_dump_lpt_lebs(const struct ubifs_info *c) { return; } - -static inline int dbg_walk_index(struct ubifs_info *c, - dbg_leaf_callback leaf_cb, - dbg_znode_callback znode_cb, - void *priv) { return 0; } -static inline void dbg_save_space_info(struct ubifs_info *c) { return; } -static inline int dbg_check_space_info(struct ubifs_info *c) { return 0; } -static inline int dbg_check_lprops(struct ubifs_info *c) { return 0; } -static inline int -dbg_old_index_check_init(struct ubifs_info *c, - struct ubifs_zbranch *zroot) { return 0; } -static inline int -dbg_check_old_index(struct ubifs_info *c, - struct ubifs_zbranch *zroot) { return 0; } -static inline int dbg_check_cats(struct ubifs_info *c) { return 0; } -static inline int dbg_check_ltab(struct ubifs_info *c) { return 0; } -static inline int dbg_chk_lpt_free_spc(struct ubifs_info *c) { return 0; } -static inline int dbg_chk_lpt_sz(struct ubifs_info *c, - int action, int len) { return 0; } -static inline int dbg_check_synced_i_size(struct inode *inode) { return 0; } -static inline int dbg_check_dir_size(struct ubifs_info *c, - const struct inode *dir) { return 0; } -static inline int dbg_check_tnc(struct ubifs_info *c, int extra) { return 0; } -static inline int dbg_check_idx_size(struct ubifs_info *c, - long long idx_size) { return 0; } -static inline int dbg_check_filesystem(struct ubifs_info *c) { return 0; } -static inline void dbg_check_heap(struct ubifs_info *c, - struct ubifs_lpt_heap *heap, - int cat, int add_pos) { return; } -static inline int dbg_check_lpt_nodes(struct ubifs_info *c, - struct ubifs_cnode *cnode, int row, int col) { return 0; } -static inline int dbg_check_inode_size(struct ubifs_info *c, - const struct inode *inode, - loff_t size) { return 0; } -static inline int -dbg_check_data_nodes_order(struct ubifs_info *c, - struct list_head *head) { return 0; } -static inline int -dbg_check_nondata_nodes_order(struct ubifs_info *c, - struct list_head *head) { return 0; } - -static inline int dbg_force_in_the_gaps(void) { return 0; } -#define dbg_force_in_the_gaps_enabled 0 -#define dbg_failure_mode 0 - -static inline int dbg_debugfs_init(void) { return 0; } -static inline void dbg_debugfs_exit(void) { return; } -static inline int dbg_debugfs_init_fs(struct ubifs_info *c) { return 0; } -static inline int dbg_debugfs_exit_fs(struct ubifs_info *c) { return 0; } +#define ubifs_debugging_init(c) 0 +#define ubifs_debugging_exit(c) ({}) + +#define dbg_ntype(type) "" +#define dbg_cstate(cmt_state) "" +#define dbg_jhead(jhead) "" +#define dbg_get_key_dump(c, key) ({}) +#define dbg_dump_inode(c, inode) ({}) +#define dbg_dump_node(c, node) ({}) +#define dbg_dump_lpt_node(c, node, lnum, offs) ({}) +#define dbg_dump_budget_req(req) ({}) +#define dbg_dump_lstats(lst) ({}) +#define dbg_dump_budg(c) ({}) +#define dbg_dump_lprop(c, lp) ({}) +#define dbg_dump_lprops(c) ({}) +#define dbg_dump_lpt_info(c) ({}) +#define dbg_dump_leb(c, lnum) ({}) +#define dbg_dump_znode(c, znode) ({}) +#define dbg_dump_heap(c, heap, cat) ({}) +#define dbg_dump_pnode(c, pnode, parent, iip) ({}) +#define dbg_dump_tnc(c) ({}) +#define dbg_dump_index(c) ({}) +#define dbg_dump_lpt_lebs(c) ({}) + +#define dbg_walk_index(c, leaf_cb, znode_cb, priv) 0 +#define dbg_old_index_check_init(c, zroot) 0 +#define dbg_save_space_info(c) ({}) +#define dbg_check_space_info(c) 0 +#define dbg_check_old_index(c, zroot) 0 +#define dbg_check_cats(c) 0 +#define dbg_check_ltab(c) 0 +#define dbg_chk_lpt_free_spc(c) 0 +#define dbg_chk_lpt_sz(c, action, len) 0 +#define dbg_check_synced_i_size(inode) 0 +#define dbg_check_dir_size(c, dir) 0 +#define dbg_check_tnc(c, x) 0 +#define dbg_check_idx_size(c, idx_size) 0 +#define dbg_check_filesystem(c) 0 +#define dbg_check_heap(c, heap, cat, add_pos) ({}) +#define dbg_check_lprops(c) 0 +#define dbg_check_lpt_nodes(c, cnode, row, col) 0 +#define dbg_check_inode_size(c, inode, size) 0 +#define dbg_check_data_nodes_order(c, head) 0 +#define dbg_check_nondata_nodes_order(c, head) 0 +#define dbg_force_in_the_gaps_enabled 0 +#define dbg_force_in_the_gaps() 0 +#define dbg_failure_mode 0 + +#define dbg_debugfs_init() 0 +#define dbg_debugfs_exit() +#define dbg_debugfs_init_fs(c) 0 +#define dbg_debugfs_exit_fs(c) 0 #endif /* !CONFIG_UBIFS_FS_DEBUG */ #endif /* !__UBIFS_DEBUG_H__ */ diff --git a/trunk/fs/ubifs/file.c b/trunk/fs/ubifs/file.c index b286db79c686..28be1e6a65e8 100644 --- a/trunk/fs/ubifs/file.c +++ b/trunk/fs/ubifs/file.c @@ -1312,9 +1312,6 @@ int ubifs_fsync(struct file *file, int datasync) dbg_gen("syncing inode %lu", inode->i_ino); - if (inode->i_sb->s_flags & MS_RDONLY) - return 0; - /* * VFS has already synchronized dirty pages for this inode. Synchronize * the inode unless this is a 'datasync()' call. diff --git a/trunk/fs/xfs/linux-2.6/xfs_buf.c b/trunk/fs/xfs/linux-2.6/xfs_buf.c index 9ef9ed2cfe2e..5ea402023ebd 100644 --- a/trunk/fs/xfs/linux-2.6/xfs_buf.c +++ b/trunk/fs/xfs/linux-2.6/xfs_buf.c @@ -293,6 +293,7 @@ xfs_buf_allocate_memory( size_t nbytes, offset; gfp_t gfp_mask = xb_to_gfp(flags); unsigned short page_count, i; + pgoff_t first; xfs_off_t end; int error; @@ -332,6 +333,7 @@ xfs_buf_allocate_memory( return error; offset = bp->b_offset; + first = bp->b_file_offset >> PAGE_SHIFT; bp->b_flags |= _XBF_PAGES; for (i = 0; i < bp->b_page_count; i++) { @@ -655,6 +657,8 @@ xfs_buf_readahead( xfs_off_t ioff, size_t isize) { + struct backing_dev_info *bdi; + if (bdi_read_congested(target->bt_bdi)) return; @@ -915,6 +919,8 @@ xfs_buf_lock( if (atomic_read(&bp->b_pin_count) && (bp->b_flags & XBF_STALE)) xfs_log_force(bp->b_target->bt_mount, 0); + if (atomic_read(&bp->b_io_remaining)) + blk_flush_plug(current); down(&bp->b_sema); XB_SET_OWNER(bp); @@ -1303,6 +1309,8 @@ xfs_buf_iowait( { trace_xfs_buf_iowait(bp, _RET_IP_); + if (atomic_read(&bp->b_io_remaining)) + blk_flush_plug(current); wait_for_completion(&bp->b_iowait); trace_xfs_buf_iowait_done(bp, _RET_IP_); @@ -1739,8 +1747,8 @@ xfsbufd( do { long age = xfs_buf_age_centisecs * msecs_to_jiffies(10); long tout = xfs_buf_timer_centisecs * msecs_to_jiffies(10); + int count = 0; struct list_head tmp; - struct blk_plug plug; if (unlikely(freezing(current))) { set_bit(XBT_FORCE_SLEEP, &target->bt_flags); @@ -1756,15 +1764,16 @@ xfsbufd( xfs_buf_delwri_split(target, &tmp, age); list_sort(NULL, &tmp, xfs_buf_cmp); - - blk_start_plug(&plug); while (!list_empty(&tmp)) { struct xfs_buf *bp; bp = list_first_entry(&tmp, struct xfs_buf, b_list); list_del_init(&bp->b_list); xfs_bdstrat_cb(bp); + count++; } - blk_finish_plug(&plug); + if (count) + blk_flush_plug(current); + } while (!kthread_should_stop()); return 0; @@ -1784,7 +1793,6 @@ xfs_flush_buftarg( int pincount = 0; LIST_HEAD(tmp_list); LIST_HEAD(wait_list); - struct blk_plug plug; xfs_buf_runall_queues(xfsconvertd_workqueue); xfs_buf_runall_queues(xfsdatad_workqueue); @@ -1799,8 +1807,6 @@ xfs_flush_buftarg( * we do that after issuing all the IO. */ list_sort(NULL, &tmp_list, xfs_buf_cmp); - - blk_start_plug(&plug); while (!list_empty(&tmp_list)) { bp = list_first_entry(&tmp_list, struct xfs_buf, b_list); ASSERT(target == bp->b_target); @@ -1811,10 +1817,10 @@ xfs_flush_buftarg( } xfs_bdstrat_cb(bp); } - blk_finish_plug(&plug); if (wait) { - /* Wait for IO to complete. */ + /* Expedite and wait for IO to complete. */ + blk_flush_plug(current); while (!list_empty(&wait_list)) { bp = list_first_entry(&wait_list, struct xfs_buf, b_list); diff --git a/trunk/fs/xfs/linux-2.6/xfs_message.c b/trunk/fs/xfs/linux-2.6/xfs_message.c index 3ca795609113..508e06fd7d1e 100644 --- a/trunk/fs/xfs/linux-2.6/xfs_message.c +++ b/trunk/fs/xfs/linux-2.6/xfs_message.c @@ -28,47 +28,53 @@ /* * XFS logging functions */ -static void +static int __xfs_printk( const char *level, const struct xfs_mount *mp, struct va_format *vaf) { if (mp && mp->m_fsname) - printk("%sXFS (%s): %pV\n", level, mp->m_fsname, vaf); - printk("%sXFS: %pV\n", level, vaf); + return printk("%sXFS (%s): %pV\n", level, mp->m_fsname, vaf); + return printk("%sXFS: %pV\n", level, vaf); } -void xfs_printk( +int xfs_printk( const char *level, const struct xfs_mount *mp, const char *fmt, ...) { struct va_format vaf; va_list args; + int r; va_start(args, fmt); vaf.fmt = fmt; vaf.va = &args; - __xfs_printk(level, mp, &vaf); + r = __xfs_printk(level, mp, &vaf); va_end(args); + + return r; } #define define_xfs_printk_level(func, kern_level) \ -void func(const struct xfs_mount *mp, const char *fmt, ...) \ +int func(const struct xfs_mount *mp, const char *fmt, ...) \ { \ struct va_format vaf; \ va_list args; \ + int r; \ \ va_start(args, fmt); \ \ vaf.fmt = fmt; \ vaf.va = &args; \ \ - __xfs_printk(kern_level, mp, &vaf); \ + r = __xfs_printk(kern_level, mp, &vaf); \ va_end(args); \ + \ + return r; \ } \ define_xfs_printk_level(xfs_emerg, KERN_EMERG); @@ -82,7 +88,7 @@ define_xfs_printk_level(xfs_info, KERN_INFO); define_xfs_printk_level(xfs_debug, KERN_DEBUG); #endif -void +int xfs_alert_tag( const struct xfs_mount *mp, int panic_tag, @@ -91,6 +97,7 @@ xfs_alert_tag( struct va_format vaf; va_list args; int do_panic = 0; + int r; if (xfs_panic_mask && (xfs_panic_mask & panic_tag)) { xfs_printk(KERN_ALERT, mp, @@ -103,10 +110,12 @@ xfs_alert_tag( vaf.fmt = fmt; vaf.va = &args; - __xfs_printk(KERN_ALERT, mp, &vaf); + r = __xfs_printk(KERN_ALERT, mp, &vaf); va_end(args); BUG_ON(do_panic); + + return r; } void diff --git a/trunk/fs/xfs/linux-2.6/xfs_message.h b/trunk/fs/xfs/linux-2.6/xfs_message.h index f1b3fc1b6c4e..e77ffa16745b 100644 --- a/trunk/fs/xfs/linux-2.6/xfs_message.h +++ b/trunk/fs/xfs/linux-2.6/xfs_message.h @@ -3,34 +3,32 @@ struct xfs_mount; -extern void xfs_printk(const char *level, const struct xfs_mount *mp, +extern int xfs_printk(const char *level, const struct xfs_mount *mp, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); -extern void xfs_emerg(const struct xfs_mount *mp, const char *fmt, ...) +extern int xfs_emerg(const struct xfs_mount *mp, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); -extern void xfs_alert(const struct xfs_mount *mp, const char *fmt, ...) +extern int xfs_alert(const struct xfs_mount *mp, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); -extern void xfs_alert_tag(const struct xfs_mount *mp, int tag, +extern int xfs_alert_tag(const struct xfs_mount *mp, int tag, const char *fmt, ...) __attribute__ ((format (printf, 3, 4))); -extern void xfs_crit(const struct xfs_mount *mp, const char *fmt, ...) +extern int xfs_crit(const struct xfs_mount *mp, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); -extern void xfs_err(const struct xfs_mount *mp, const char *fmt, ...) +extern int xfs_err(const struct xfs_mount *mp, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); -extern void xfs_warn(const struct xfs_mount *mp, const char *fmt, ...) +extern int xfs_warn(const struct xfs_mount *mp, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); -extern void xfs_notice(const struct xfs_mount *mp, const char *fmt, ...) +extern int xfs_notice(const struct xfs_mount *mp, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); -extern void xfs_info(const struct xfs_mount *mp, const char *fmt, ...) +extern int xfs_info(const struct xfs_mount *mp, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); #ifdef DEBUG -extern void xfs_debug(const struct xfs_mount *mp, const char *fmt, ...) +extern int xfs_debug(const struct xfs_mount *mp, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); #else -static inline void xfs_debug(const struct xfs_mount *mp, const char *fmt, ...) -{ -} +#define xfs_debug(mp, fmt, ...) (0) #endif extern void assfail(char *expr, char *f, int l); diff --git a/trunk/fs/xfs/linux-2.6/xfs_super.c b/trunk/fs/xfs/linux-2.6/xfs_super.c index b38e58d02299..1ba5c451da36 100644 --- a/trunk/fs/xfs/linux-2.6/xfs_super.c +++ b/trunk/fs/xfs/linux-2.6/xfs_super.c @@ -816,6 +816,75 @@ xfs_setup_devices( return 0; } +/* + * XFS AIL push thread support + */ +void +xfsaild_wakeup( + struct xfs_ail *ailp, + xfs_lsn_t threshold_lsn) +{ + /* only ever move the target forwards */ + if (XFS_LSN_CMP(threshold_lsn, ailp->xa_target) > 0) { + ailp->xa_target = threshold_lsn; + wake_up_process(ailp->xa_task); + } +} + +STATIC int +xfsaild( + void *data) +{ + struct xfs_ail *ailp = data; + xfs_lsn_t last_pushed_lsn = 0; + long tout = 0; /* milliseconds */ + + while (!kthread_should_stop()) { + /* + * for short sleeps indicating congestion, don't allow us to + * get woken early. Otherwise all we do is bang on the AIL lock + * without making progress. + */ + if (tout && tout <= 20) + __set_current_state(TASK_KILLABLE); + else + __set_current_state(TASK_INTERRUPTIBLE); + schedule_timeout(tout ? + msecs_to_jiffies(tout) : MAX_SCHEDULE_TIMEOUT); + + /* swsusp */ + try_to_freeze(); + + ASSERT(ailp->xa_mount->m_log); + if (XFS_FORCED_SHUTDOWN(ailp->xa_mount)) + continue; + + tout = xfsaild_push(ailp, &last_pushed_lsn); + } + + return 0; +} /* xfsaild */ + +int +xfsaild_start( + struct xfs_ail *ailp) +{ + ailp->xa_target = 0; + ailp->xa_task = kthread_run(xfsaild, ailp, "xfsaild/%s", + ailp->xa_mount->m_fsname); + if (IS_ERR(ailp->xa_task)) + return -PTR_ERR(ailp->xa_task); + return 0; +} + +void +xfsaild_stop( + struct xfs_ail *ailp) +{ + kthread_stop(ailp->xa_task); +} + + /* Catch misguided souls that try to use this interface on XFS */ STATIC struct inode * xfs_fs_alloc_inode( @@ -1122,12 +1191,22 @@ xfs_fs_sync_fs( return -error; if (laptop_mode) { + int prev_sync_seq = mp->m_sync_seq; + /* * The disk must be active because we're syncing. * We schedule xfssyncd now (now that the disk is * active) instead of later (when it might not be). */ - flush_delayed_work_sync(&mp->m_sync_work); + wake_up_process(mp->m_sync_task); + /* + * We have to wait for the sync iteration to complete. + * If we don't, the disk activity caused by the sync + * will come after the sync is completed, and that + * triggers another sync from laptop mode. + */ + wait_event(mp->m_wait_single_sync_task, + mp->m_sync_seq != prev_sync_seq); } return 0; @@ -1411,6 +1490,9 @@ xfs_fs_fill_super( spin_lock_init(&mp->m_sb_lock); mutex_init(&mp->m_growlock); atomic_set(&mp->m_active_trans, 0); + INIT_LIST_HEAD(&mp->m_sync_list); + spin_lock_init(&mp->m_sync_lock); + init_waitqueue_head(&mp->m_wait_single_sync_task); mp->m_super = sb; sb->s_fs_info = mp; @@ -1716,38 +1798,6 @@ xfs_destroy_zones(void) } -STATIC int __init -xfs_init_workqueues(void) -{ - /* - * max_active is set to 8 to give enough concurency to allow - * multiple work operations on each CPU to run. This allows multiple - * filesystems to be running sync work concurrently, and scales with - * the number of CPUs in the system. - */ - xfs_syncd_wq = alloc_workqueue("xfssyncd", WQ_CPU_INTENSIVE, 8); - if (!xfs_syncd_wq) - goto out; - - xfs_ail_wq = alloc_workqueue("xfsail", WQ_CPU_INTENSIVE, 8); - if (!xfs_ail_wq) - goto out_destroy_syncd; - - return 0; - -out_destroy_syncd: - destroy_workqueue(xfs_syncd_wq); -out: - return -ENOMEM; -} - -STATIC void -xfs_destroy_workqueues(void) -{ - destroy_workqueue(xfs_ail_wq); - destroy_workqueue(xfs_syncd_wq); -} - STATIC int __init init_xfs_fs(void) { @@ -1763,13 +1813,9 @@ init_xfs_fs(void) if (error) goto out; - error = xfs_init_workqueues(); - if (error) - goto out_destroy_zones; - error = xfs_mru_cache_init(); if (error) - goto out_destroy_wq; + goto out_destroy_zones; error = xfs_filestream_init(); if (error) @@ -1787,10 +1833,6 @@ init_xfs_fs(void) if (error) goto out_cleanup_procfs; - error = xfs_init_workqueues(); - if (error) - goto out_sysctl_unregister; - vfs_initquota(); error = register_filesystem(&xfs_fs_type); @@ -1808,8 +1850,6 @@ init_xfs_fs(void) xfs_filestream_uninit(); out_mru_cache_uninit: xfs_mru_cache_uninit(); - out_destroy_wq: - xfs_destroy_workqueues(); out_destroy_zones: xfs_destroy_zones(); out: @@ -1826,7 +1866,6 @@ exit_xfs_fs(void) xfs_buf_terminate(); xfs_filestream_uninit(); xfs_mru_cache_uninit(); - xfs_destroy_workqueues(); xfs_destroy_zones(); } diff --git a/trunk/fs/xfs/linux-2.6/xfs_sync.c b/trunk/fs/xfs/linux-2.6/xfs_sync.c index e4f9c1b0836c..9cf35a688f53 100644 --- a/trunk/fs/xfs/linux-2.6/xfs_sync.c +++ b/trunk/fs/xfs/linux-2.6/xfs_sync.c @@ -22,7 +22,6 @@ #include "xfs_log.h" #include "xfs_inum.h" #include "xfs_trans.h" -#include "xfs_trans_priv.h" #include "xfs_sb.h" #include "xfs_ag.h" #include "xfs_mount.h" @@ -40,8 +39,6 @@ #include #include -struct workqueue_struct *xfs_syncd_wq; /* sync workqueue */ - /* * The inode lookup is done in batches to keep the amount of lock traffic and * radix tree lookups to a minimum. The batch size is a trade off between @@ -434,12 +431,62 @@ xfs_quiesce_attr( xfs_unmountfs_writesb(mp); } -static void -xfs_syncd_queue_sync( - struct xfs_mount *mp) +/* + * Enqueue a work item to be picked up by the vfs xfssyncd thread. + * Doing this has two advantages: + * - It saves on stack space, which is tight in certain situations + * - It can be used (with care) as a mechanism to avoid deadlocks. + * Flushing while allocating in a full filesystem requires both. + */ +STATIC void +xfs_syncd_queue_work( + struct xfs_mount *mp, + void *data, + void (*syncer)(struct xfs_mount *, void *), + struct completion *completion) +{ + struct xfs_sync_work *work; + + work = kmem_alloc(sizeof(struct xfs_sync_work), KM_SLEEP); + INIT_LIST_HEAD(&work->w_list); + work->w_syncer = syncer; + work->w_data = data; + work->w_mount = mp; + work->w_completion = completion; + spin_lock(&mp->m_sync_lock); + list_add_tail(&work->w_list, &mp->m_sync_list); + spin_unlock(&mp->m_sync_lock); + wake_up_process(mp->m_sync_task); +} + +/* + * Flush delayed allocate data, attempting to free up reserved space + * from existing allocations. At this point a new allocation attempt + * has failed with ENOSPC and we are in the process of scratching our + * heads, looking about for more room... + */ +STATIC void +xfs_flush_inodes_work( + struct xfs_mount *mp, + void *arg) +{ + struct inode *inode = arg; + xfs_sync_data(mp, SYNC_TRYLOCK); + xfs_sync_data(mp, SYNC_TRYLOCK | SYNC_WAIT); + iput(inode); +} + +void +xfs_flush_inodes( + xfs_inode_t *ip) { - queue_delayed_work(xfs_syncd_wq, &mp->m_sync_work, - msecs_to_jiffies(xfs_syncd_centisecs * 10)); + struct inode *inode = VFS_I(ip); + DECLARE_COMPLETION_ONSTACK(completion); + + igrab(inode); + xfs_syncd_queue_work(ip->i_mount, inode, xfs_flush_inodes_work, &completion); + wait_for_completion(&completion); + xfs_log_force(ip->i_mount, XFS_LOG_SYNC); } /* @@ -449,10 +496,9 @@ xfs_syncd_queue_sync( */ STATIC void xfs_sync_worker( - struct work_struct *work) + struct xfs_mount *mp, + void *unused) { - struct xfs_mount *mp = container_of(to_delayed_work(work), - struct xfs_mount, m_sync_work); int error; if (!(mp->m_flags & XFS_MOUNT_RDONLY)) { @@ -462,106 +508,73 @@ xfs_sync_worker( error = xfs_fs_log_dummy(mp); else xfs_log_force(mp, 0); + xfs_reclaim_inodes(mp, 0); error = xfs_qm_sync(mp, SYNC_TRYLOCK); - - /* start pushing all the metadata that is currently dirty */ - xfs_ail_push_all(mp->m_ail); } - - /* queue us up again */ - xfs_syncd_queue_sync(mp); + mp->m_sync_seq++; + wake_up(&mp->m_wait_single_sync_task); } -/* - * Queue a new inode reclaim pass if there are reclaimable inodes and there - * isn't a reclaim pass already in progress. By default it runs every 5s based - * on the xfs syncd work default of 30s. Perhaps this should have it's own - * tunable, but that can be done if this method proves to be ineffective or too - * aggressive. - */ -static void -xfs_syncd_queue_reclaim( - struct xfs_mount *mp) +STATIC int +xfssyncd( + void *arg) { + struct xfs_mount *mp = arg; + long timeleft; + xfs_sync_work_t *work, *n; + LIST_HEAD (tmp); + + set_freezable(); + timeleft = xfs_syncd_centisecs * msecs_to_jiffies(10); + for (;;) { + if (list_empty(&mp->m_sync_list)) + timeleft = schedule_timeout_interruptible(timeleft); + /* swsusp */ + try_to_freeze(); + if (kthread_should_stop() && list_empty(&mp->m_sync_list)) + break; - /* - * We can have inodes enter reclaim after we've shut down the syncd - * workqueue during unmount, so don't allow reclaim work to be queued - * during unmount. - */ - if (!(mp->m_super->s_flags & MS_ACTIVE)) - return; + spin_lock(&mp->m_sync_lock); + /* + * We can get woken by laptop mode, to do a sync - + * that's the (only!) case where the list would be + * empty with time remaining. + */ + if (!timeleft || list_empty(&mp->m_sync_list)) { + if (!timeleft) + timeleft = xfs_syncd_centisecs * + msecs_to_jiffies(10); + INIT_LIST_HEAD(&mp->m_sync_work.w_list); + list_add_tail(&mp->m_sync_work.w_list, + &mp->m_sync_list); + } + list_splice_init(&mp->m_sync_list, &tmp); + spin_unlock(&mp->m_sync_lock); - rcu_read_lock(); - if (radix_tree_tagged(&mp->m_perag_tree, XFS_ICI_RECLAIM_TAG)) { - queue_delayed_work(xfs_syncd_wq, &mp->m_reclaim_work, - msecs_to_jiffies(xfs_syncd_centisecs / 6 * 10)); + list_for_each_entry_safe(work, n, &tmp, w_list) { + (*work->w_syncer)(mp, work->w_data); + list_del(&work->w_list); + if (work == &mp->m_sync_work) + continue; + if (work->w_completion) + complete(work->w_completion); + kmem_free(work); + } } - rcu_read_unlock(); -} - -/* - * This is a fast pass over the inode cache to try to get reclaim moving on as - * many inodes as possible in a short period of time. It kicks itself every few - * seconds, as well as being kicked by the inode cache shrinker when memory - * goes low. It scans as quickly as possible avoiding locked inodes or those - * already being flushed, and once done schedules a future pass. - */ -STATIC void -xfs_reclaim_worker( - struct work_struct *work) -{ - struct xfs_mount *mp = container_of(to_delayed_work(work), - struct xfs_mount, m_reclaim_work); - - xfs_reclaim_inodes(mp, SYNC_TRYLOCK); - xfs_syncd_queue_reclaim(mp); -} - -/* - * Flush delayed allocate data, attempting to free up reserved space - * from existing allocations. At this point a new allocation attempt - * has failed with ENOSPC and we are in the process of scratching our - * heads, looking about for more room. - * - * Queue a new data flush if there isn't one already in progress and - * wait for completion of the flush. This means that we only ever have one - * inode flush in progress no matter how many ENOSPC events are occurring and - * so will prevent the system from bogging down due to every concurrent - * ENOSPC event scanning all the active inodes in the system for writeback. - */ -void -xfs_flush_inodes( - struct xfs_inode *ip) -{ - struct xfs_mount *mp = ip->i_mount; - - queue_work(xfs_syncd_wq, &mp->m_flush_work); - flush_work_sync(&mp->m_flush_work); -} -STATIC void -xfs_flush_worker( - struct work_struct *work) -{ - struct xfs_mount *mp = container_of(work, - struct xfs_mount, m_flush_work); - - xfs_sync_data(mp, SYNC_TRYLOCK); - xfs_sync_data(mp, SYNC_TRYLOCK | SYNC_WAIT); + return 0; } int xfs_syncd_init( struct xfs_mount *mp) { - INIT_WORK(&mp->m_flush_work, xfs_flush_worker); - INIT_DELAYED_WORK(&mp->m_sync_work, xfs_sync_worker); - INIT_DELAYED_WORK(&mp->m_reclaim_work, xfs_reclaim_worker); - - xfs_syncd_queue_sync(mp); - xfs_syncd_queue_reclaim(mp); - + mp->m_sync_work.w_syncer = xfs_sync_worker; + mp->m_sync_work.w_mount = mp; + mp->m_sync_work.w_completion = NULL; + mp->m_sync_task = kthread_run(xfssyncd, mp, "xfssyncd/%s", mp->m_fsname); + if (IS_ERR(mp->m_sync_task)) + return -PTR_ERR(mp->m_sync_task); return 0; } @@ -569,9 +582,7 @@ void xfs_syncd_stop( struct xfs_mount *mp) { - cancel_delayed_work_sync(&mp->m_sync_work); - cancel_delayed_work_sync(&mp->m_reclaim_work); - cancel_work_sync(&mp->m_flush_work); + kthread_stop(mp->m_sync_task); } void @@ -590,10 +601,6 @@ __xfs_inode_set_reclaim_tag( XFS_INO_TO_AGNO(ip->i_mount, ip->i_ino), XFS_ICI_RECLAIM_TAG); spin_unlock(&ip->i_mount->m_perag_lock); - - /* schedule periodic background inode reclaim */ - xfs_syncd_queue_reclaim(ip->i_mount); - trace_xfs_perag_set_reclaim(ip->i_mount, pag->pag_agno, -1, _RET_IP_); } @@ -1010,13 +1017,7 @@ xfs_reclaim_inodes( } /* - * Inode cache shrinker. - * - * When called we make sure that there is a background (fast) inode reclaim in - * progress, while we will throttle the speed of reclaim via doiing synchronous - * reclaim of inodes. That means if we come across dirty inodes, we wait for - * them to be cleaned, which we hope will not be very long due to the - * background walker having already kicked the IO off on those dirty inodes. + * Shrinker infrastructure. */ static int xfs_reclaim_inode_shrink( @@ -1031,15 +1032,10 @@ xfs_reclaim_inode_shrink( mp = container_of(shrink, struct xfs_mount, m_inode_shrink); if (nr_to_scan) { - /* kick background reclaimer and push the AIL */ - xfs_syncd_queue_reclaim(mp); - xfs_ail_push_all(mp->m_ail); - if (!(gfp_mask & __GFP_FS)) return -1; - xfs_reclaim_inodes_ag(mp, SYNC_TRYLOCK | SYNC_WAIT, - &nr_to_scan); + xfs_reclaim_inodes_ag(mp, SYNC_TRYLOCK, &nr_to_scan); /* terminate if we don't exhaust the scan */ if (nr_to_scan > 0) return -1; diff --git a/trunk/fs/xfs/linux-2.6/xfs_sync.h b/trunk/fs/xfs/linux-2.6/xfs_sync.h index e3a6ad27415f..32ba6628290c 100644 --- a/trunk/fs/xfs/linux-2.6/xfs_sync.h +++ b/trunk/fs/xfs/linux-2.6/xfs_sync.h @@ -32,8 +32,6 @@ typedef struct xfs_sync_work { #define SYNC_WAIT 0x0001 /* wait for i/o to complete */ #define SYNC_TRYLOCK 0x0002 /* only try to lock inodes */ -extern struct workqueue_struct *xfs_syncd_wq; /* sync workqueue */ - int xfs_syncd_init(struct xfs_mount *mp); void xfs_syncd_stop(struct xfs_mount *mp); diff --git a/trunk/fs/xfs/quota/xfs_qm.c b/trunk/fs/xfs/quota/xfs_qm.c index 69228aa8605a..254ee062bd7d 100644 --- a/trunk/fs/xfs/quota/xfs_qm.c +++ b/trunk/fs/xfs/quota/xfs_qm.c @@ -461,10 +461,12 @@ xfs_qm_dqflush_all( struct xfs_quotainfo *q = mp->m_quotainfo; int recl; struct xfs_dquot *dqp; + int niters; int error; if (!q) return 0; + niters = 0; again: mutex_lock(&q->qi_dqlist_lock); list_for_each_entry(dqp, &q->qi_dqlist, q_mplist) { @@ -1312,9 +1314,14 @@ xfs_qm_dqiter_bufs( { xfs_buf_t *bp; int error; + int notcommitted; + int incr; int type; ASSERT(blkcnt > 0); + notcommitted = 0; + incr = (blkcnt > XFS_QM_MAX_DQCLUSTER_LOGSZ) ? + XFS_QM_MAX_DQCLUSTER_LOGSZ : blkcnt; type = flags & XFS_QMOPT_UQUOTA ? XFS_DQ_USER : (flags & XFS_QMOPT_PQUOTA ? XFS_DQ_PROJ : XFS_DQ_GROUP); error = 0; diff --git a/trunk/fs/xfs/quota/xfs_qm.h b/trunk/fs/xfs/quota/xfs_qm.h index 567b29b9f1b3..c9446f1c726d 100644 --- a/trunk/fs/xfs/quota/xfs_qm.h +++ b/trunk/fs/xfs/quota/xfs_qm.h @@ -65,6 +65,11 @@ extern kmem_zone_t *qm_dqtrxzone; * block in the dquot/xqm code. */ #define XFS_DQUOT_CLUSTER_SIZE_FSB (xfs_filblks_t)1 +/* + * When doing a quotacheck, we log dquot clusters of this many FSBs at most + * in a single transaction. We don't want to ask for too huge a log reservation. + */ +#define XFS_QM_MAX_DQCLUSTER_LOGSZ 3 typedef xfs_dqhash_t xfs_dqlist_t; diff --git a/trunk/fs/xfs/quota/xfs_qm_syscalls.c b/trunk/fs/xfs/quota/xfs_qm_syscalls.c index 2dadb15d5ca9..0d62a07b7fd8 100644 --- a/trunk/fs/xfs/quota/xfs_qm_syscalls.c +++ b/trunk/fs/xfs/quota/xfs_qm_syscalls.c @@ -313,12 +313,14 @@ xfs_qm_scall_quotaon( { int error; uint qf; + uint accflags; __int64_t sbflags; flags &= (XFS_ALL_QUOTA_ACCT | XFS_ALL_QUOTA_ENFD); /* * Switching on quota accounting must be done at mount time. */ + accflags = flags & XFS_ALL_QUOTA_ACCT; flags &= ~(XFS_ALL_QUOTA_ACCT); sbflags = 0; diff --git a/trunk/fs/xfs/xfs_alloc.c b/trunk/fs/xfs/xfs_alloc.c index 27d64d752eab..4bc3c649aee4 100644 --- a/trunk/fs/xfs/xfs_alloc.c +++ b/trunk/fs/xfs/xfs_alloc.c @@ -2395,33 +2395,17 @@ xfs_free_extent( memset(&args, 0, sizeof(xfs_alloc_arg_t)); args.tp = tp; args.mp = tp->t_mountp; - - /* - * validate that the block number is legal - the enables us to detect - * and handle a silent filesystem corruption rather than crashing. - */ args.agno = XFS_FSB_TO_AGNO(args.mp, bno); - if (args.agno >= args.mp->m_sb.sb_agcount) - return EFSCORRUPTED; - + ASSERT(args.agno < args.mp->m_sb.sb_agcount); args.agbno = XFS_FSB_TO_AGBNO(args.mp, bno); - if (args.agbno >= args.mp->m_sb.sb_agblocks) - return EFSCORRUPTED; - args.pag = xfs_perag_get(args.mp, args.agno); - ASSERT(args.pag); - - error = xfs_alloc_fix_freelist(&args, XFS_ALLOC_FLAG_FREEING); - if (error) - goto error0; - - /* validate the extent size is legal now we have the agf locked */ - if (args.agbno + len > - be32_to_cpu(XFS_BUF_TO_AGF(args.agbp)->agf_length)) { - error = EFSCORRUPTED; + if ((error = xfs_alloc_fix_freelist(&args, XFS_ALLOC_FLAG_FREEING))) goto error0; - } - +#ifdef DEBUG + ASSERT(args.agbp != NULL); + ASSERT((args.agbno + len) <= + be32_to_cpu(XFS_BUF_TO_AGF(args.agbp)->agf_length)); +#endif error = xfs_free_ag_extent(tp, args.agbp, args.agno, args.agbno, len, 0); error0: xfs_perag_put(args.pag); diff --git a/trunk/fs/xfs/xfs_inode_item.c b/trunk/fs/xfs/xfs_inode_item.c index 576fdfe81d60..46cc40131d4a 100644 --- a/trunk/fs/xfs/xfs_inode_item.c +++ b/trunk/fs/xfs/xfs_inode_item.c @@ -197,41 +197,6 @@ xfs_inode_item_size( return nvecs; } -/* - * xfs_inode_item_format_extents - convert in-core extents to on-disk form - * - * For either the data or attr fork in extent format, we need to endian convert - * the in-core extent as we place them into the on-disk inode. In this case, we - * need to do this conversion before we write the extents into the log. Because - * we don't have the disk inode to write into here, we allocate a buffer and - * format the extents into it via xfs_iextents_copy(). We free the buffer in - * the unlock routine after the copy for the log has been made. - * - * In the case of the data fork, the in-core and on-disk fork sizes can be - * different due to delayed allocation extents. We only log on-disk extents - * here, so always use the physical fork size to determine the size of the - * buffer we need to allocate. - */ -STATIC void -xfs_inode_item_format_extents( - struct xfs_inode *ip, - struct xfs_log_iovec *vecp, - int whichfork, - int type) -{ - xfs_bmbt_rec_t *ext_buffer; - - ext_buffer = kmem_alloc(XFS_IFORK_SIZE(ip, whichfork), KM_SLEEP); - if (whichfork == XFS_DATA_FORK) - ip->i_itemp->ili_extents_buf = ext_buffer; - else - ip->i_itemp->ili_aextents_buf = ext_buffer; - - vecp->i_addr = ext_buffer; - vecp->i_len = xfs_iextents_copy(ip, ext_buffer, whichfork); - vecp->i_type = type; -} - /* * This is called to fill in the vector of log iovecs for the * given inode log item. It fills the first item with an inode @@ -248,6 +213,7 @@ xfs_inode_item_format( struct xfs_inode *ip = iip->ili_inode; uint nvecs; size_t data_bytes; + xfs_bmbt_rec_t *ext_buffer; xfs_mount_t *mp; vecp->i_addr = &iip->ili_format; @@ -354,8 +320,22 @@ xfs_inode_item_format( } else #endif { - xfs_inode_item_format_extents(ip, vecp, - XFS_DATA_FORK, XLOG_REG_TYPE_IEXT); + /* + * There are delayed allocation extents + * in the inode, or we need to convert + * the extents to on disk format. + * Use xfs_iextents_copy() + * to copy only the real extents into + * a separate buffer. We'll free the + * buffer in the unlock routine. + */ + ext_buffer = kmem_alloc(ip->i_df.if_bytes, + KM_SLEEP); + iip->ili_extents_buf = ext_buffer; + vecp->i_addr = ext_buffer; + vecp->i_len = xfs_iextents_copy(ip, ext_buffer, + XFS_DATA_FORK); + vecp->i_type = XLOG_REG_TYPE_IEXT; } ASSERT(vecp->i_len <= ip->i_df.if_bytes); iip->ili_format.ilf_dsize = vecp->i_len; @@ -465,12 +445,19 @@ xfs_inode_item_format( */ vecp->i_addr = ip->i_afp->if_u1.if_extents; vecp->i_len = ip->i_afp->if_bytes; - vecp->i_type = XLOG_REG_TYPE_IATTR_EXT; #else ASSERT(iip->ili_aextents_buf == NULL); - xfs_inode_item_format_extents(ip, vecp, - XFS_ATTR_FORK, XLOG_REG_TYPE_IATTR_EXT); + /* + * Need to endian flip before logging + */ + ext_buffer = kmem_alloc(ip->i_afp->if_bytes, + KM_SLEEP); + iip->ili_aextents_buf = ext_buffer; + vecp->i_addr = ext_buffer; + vecp->i_len = xfs_iextents_copy(ip, ext_buffer, + XFS_ATTR_FORK); #endif + vecp->i_type = XLOG_REG_TYPE_IATTR_EXT; iip->ili_format.ilf_asize = vecp->i_len; vecp++; nvecs++; diff --git a/trunk/fs/xfs/xfs_itable.c b/trunk/fs/xfs/xfs_itable.c index 751e94fe1f77..dc1882adaf54 100644 --- a/trunk/fs/xfs/xfs_itable.c +++ b/trunk/fs/xfs/xfs_itable.c @@ -204,6 +204,7 @@ xfs_bulkstat( xfs_agi_t *agi; /* agi header data */ xfs_agino_t agino; /* inode # in allocation group */ xfs_agnumber_t agno; /* allocation group number */ + xfs_daddr_t bno; /* inode cluster start daddr */ int chunkidx; /* current index into inode chunk */ int clustidx; /* current index into inode cluster */ xfs_btree_cur_t *cur; /* btree cursor for ialloc btree */ @@ -462,6 +463,7 @@ xfs_bulkstat( mp->m_sb.sb_inopblog); } ino = XFS_AGINO_TO_INO(mp, agno, agino); + bno = XFS_AGB_TO_DADDR(mp, agno, agbno); /* * Skip if this inode is free. */ diff --git a/trunk/fs/xfs/xfs_log.c b/trunk/fs/xfs/xfs_log.c index b612ce4520ae..25efa9b8a602 100644 --- a/trunk/fs/xfs/xfs_log.c +++ b/trunk/fs/xfs/xfs_log.c @@ -761,7 +761,7 @@ xfs_log_need_covered(xfs_mount_t *mp) break; case XLOG_STATE_COVER_NEED: case XLOG_STATE_COVER_NEED2: - if (!xfs_ail_min_lsn(log->l_ailp) && + if (!xfs_trans_ail_tail(log->l_ailp) && xlog_iclogs_empty(log)) { if (log->l_covered_state == XLOG_STATE_COVER_NEED) log->l_covered_state = XLOG_STATE_COVER_DONE; @@ -801,7 +801,7 @@ xlog_assign_tail_lsn( xfs_lsn_t tail_lsn; struct log *log = mp->m_log; - tail_lsn = xfs_ail_min_lsn(mp->m_ail); + tail_lsn = xfs_trans_ail_tail(mp->m_ail); if (!tail_lsn) tail_lsn = atomic64_read(&log->l_last_sync_lsn); @@ -1239,7 +1239,7 @@ xlog_grant_push_ail( * the filesystem is shutting down. */ if (!XLOG_FORCED_SHUTDOWN(log)) - xfs_ail_push(log->l_ailp, threshold_lsn); + xfs_trans_ail_push(log->l_ailp, threshold_lsn); } /* @@ -3407,17 +3407,6 @@ xlog_verify_dest_ptr( xfs_emerg(log->l_mp, "%s: invalid ptr", __func__); } -/* - * Check to make sure the grant write head didn't just over lap the tail. If - * the cycles are the same, we can't be overlapping. Otherwise, make sure that - * the cycles differ by exactly one and check the byte count. - * - * This check is run unlocked, so can give false positives. Rather than assert - * on failures, use a warn-once flag and a panic tag to allow the admin to - * determine if they want to panic the machine when such an error occurs. For - * debug kernels this will have the same effect as using an assert but, unlinke - * an assert, it can be turned off at runtime. - */ STATIC void xlog_verify_grant_tail( struct log *log) @@ -3425,22 +3414,17 @@ xlog_verify_grant_tail( int tail_cycle, tail_blocks; int cycle, space; + /* + * Check to make sure the grant write head didn't just over lap the + * tail. If the cycles are the same, we can't be overlapping. + * Otherwise, make sure that the cycles differ by exactly one and + * check the byte count. + */ xlog_crack_grant_head(&log->l_grant_write_head, &cycle, &space); xlog_crack_atomic_lsn(&log->l_tail_lsn, &tail_cycle, &tail_blocks); if (tail_cycle != cycle) { - if (cycle - 1 != tail_cycle && - !(log->l_flags & XLOG_TAIL_WARN)) { - xfs_alert_tag(log->l_mp, XFS_PTAG_LOGRES, - "%s: cycle - 1 != tail_cycle", __func__); - log->l_flags |= XLOG_TAIL_WARN; - } - - if (space > BBTOB(tail_blocks) && - !(log->l_flags & XLOG_TAIL_WARN)) { - xfs_alert_tag(log->l_mp, XFS_PTAG_LOGRES, - "%s: space > BBTOB(tail_blocks)", __func__); - log->l_flags |= XLOG_TAIL_WARN; - } + ASSERT(cycle - 1 == tail_cycle); + ASSERT(space <= BBTOB(tail_blocks)); } } diff --git a/trunk/fs/xfs/xfs_log_priv.h b/trunk/fs/xfs/xfs_log_priv.h index 5864850e9e34..ffae692c9832 100644 --- a/trunk/fs/xfs/xfs_log_priv.h +++ b/trunk/fs/xfs/xfs_log_priv.h @@ -144,7 +144,6 @@ static inline uint xlog_get_client_id(__be32 i) #define XLOG_RECOVERY_NEEDED 0x4 /* log was recovered */ #define XLOG_IO_ERROR 0x8 /* log hit an I/O error, and being shutdown */ -#define XLOG_TAIL_WARN 0x10 /* log tail verify warning issued */ #ifdef __KERNEL__ /* diff --git a/trunk/fs/xfs/xfs_mount.h b/trunk/fs/xfs/xfs_mount.h index 19af0ab0d0c6..a62e8971539d 100644 --- a/trunk/fs/xfs/xfs_mount.h +++ b/trunk/fs/xfs/xfs_mount.h @@ -203,9 +203,12 @@ typedef struct xfs_mount { struct mutex m_icsb_mutex; /* balancer sync lock */ #endif struct xfs_mru_cache *m_filestream; /* per-mount filestream data */ - struct delayed_work m_sync_work; /* background sync work */ - struct delayed_work m_reclaim_work; /* background inode reclaim */ - struct work_struct m_flush_work; /* background inode flush */ + struct task_struct *m_sync_task; /* generalised sync thread */ + xfs_sync_work_t m_sync_work; /* work item for VFS_SYNC */ + struct list_head m_sync_list; /* sync thread work item list */ + spinlock_t m_sync_lock; /* work item list lock */ + int m_sync_seq; /* sync thread generation no. */ + wait_queue_head_t m_wait_single_sync_task; __int64_t m_update_flags; /* sb flags we need to update on the next remount,rw */ struct shrinker m_inode_shrink; /* inode reclaim shrinker */ diff --git a/trunk/fs/xfs/xfs_trans_ail.c b/trunk/fs/xfs/xfs_trans_ail.c index acdb92f14d51..12aff9584e29 100644 --- a/trunk/fs/xfs/xfs_trans_ail.c +++ b/trunk/fs/xfs/xfs_trans_ail.c @@ -28,138 +28,74 @@ #include "xfs_trans_priv.h" #include "xfs_error.h" -struct workqueue_struct *xfs_ail_wq; /* AIL workqueue */ +STATIC void xfs_ail_splice(struct xfs_ail *, struct list_head *, xfs_lsn_t); +STATIC void xfs_ail_delete(struct xfs_ail *, xfs_log_item_t *); +STATIC xfs_log_item_t * xfs_ail_min(struct xfs_ail *); +STATIC xfs_log_item_t * xfs_ail_next(struct xfs_ail *, xfs_log_item_t *); #ifdef DEBUG -/* - * Check that the list is sorted as it should be. - */ -STATIC void -xfs_ail_check( - struct xfs_ail *ailp, - xfs_log_item_t *lip) -{ - xfs_log_item_t *prev_lip; - - if (list_empty(&ailp->xa_ail)) - return; - - /* - * Check the next and previous entries are valid. - */ - ASSERT((lip->li_flags & XFS_LI_IN_AIL) != 0); - prev_lip = list_entry(lip->li_ail.prev, xfs_log_item_t, li_ail); - if (&prev_lip->li_ail != &ailp->xa_ail) - ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) <= 0); - - prev_lip = list_entry(lip->li_ail.next, xfs_log_item_t, li_ail); - if (&prev_lip->li_ail != &ailp->xa_ail) - ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) >= 0); - - -#ifdef XFS_TRANS_DEBUG - /* - * Walk the list checking lsn ordering, and that every entry has the - * XFS_LI_IN_AIL flag set. This is really expensive, so only do it - * when specifically debugging the transaction subsystem. - */ - prev_lip = list_entry(&ailp->xa_ail, xfs_log_item_t, li_ail); - list_for_each_entry(lip, &ailp->xa_ail, li_ail) { - if (&prev_lip->li_ail != &ailp->xa_ail) - ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) <= 0); - ASSERT((lip->li_flags & XFS_LI_IN_AIL) != 0); - prev_lip = lip; - } -#endif /* XFS_TRANS_DEBUG */ -} -#else /* !DEBUG */ +STATIC void xfs_ail_check(struct xfs_ail *, xfs_log_item_t *); +#else #define xfs_ail_check(a,l) #endif /* DEBUG */ -/* - * Return a pointer to the first item in the AIL. If the AIL is empty, then - * return NULL. - */ -static xfs_log_item_t * -xfs_ail_min( - struct xfs_ail *ailp) -{ - if (list_empty(&ailp->xa_ail)) - return NULL; - - return list_first_entry(&ailp->xa_ail, xfs_log_item_t, li_ail); -} - - /* - * Return a pointer to the last item in the AIL. If the AIL is empty, then - * return NULL. - */ -static xfs_log_item_t * -xfs_ail_max( - struct xfs_ail *ailp) -{ - if (list_empty(&ailp->xa_ail)) - return NULL; - - return list_entry(ailp->xa_ail.prev, xfs_log_item_t, li_ail); -} - -/* - * Return a pointer to the item which follows the given item in the AIL. If - * the given item is the last item in the list, then return NULL. - */ -static xfs_log_item_t * -xfs_ail_next( - struct xfs_ail *ailp, - xfs_log_item_t *lip) -{ - if (lip->li_ail.next == &ailp->xa_ail) - return NULL; - - return list_first_entry(&lip->li_ail, xfs_log_item_t, li_ail); -} /* - * This is called by the log manager code to determine the LSN of the tail of - * the log. This is exactly the LSN of the first item in the AIL. If the AIL - * is empty, then this function returns 0. + * This is called by the log manager code to determine the LSN + * of the tail of the log. This is exactly the LSN of the first + * item in the AIL. If the AIL is empty, then this function + * returns 0. * - * We need the AIL lock in order to get a coherent read of the lsn of the last - * item in the AIL. + * We need the AIL lock in order to get a coherent read of the + * lsn of the last item in the AIL. */ xfs_lsn_t -xfs_ail_min_lsn( +xfs_trans_ail_tail( struct xfs_ail *ailp) { - xfs_lsn_t lsn = 0; + xfs_lsn_t lsn; xfs_log_item_t *lip; spin_lock(&ailp->xa_lock); lip = xfs_ail_min(ailp); - if (lip) + if (lip == NULL) { + lsn = (xfs_lsn_t)0; + } else { lsn = lip->li_lsn; + } spin_unlock(&ailp->xa_lock); return lsn; } /* - * Return the maximum lsn held in the AIL, or zero if the AIL is empty. + * xfs_trans_push_ail + * + * This routine is called to move the tail of the AIL forward. It does this by + * trying to flush items in the AIL whose lsns are below the given + * threshold_lsn. + * + * the push is run asynchronously in a separate thread, so we return the tail + * of the log right now instead of the tail after the push. This means we will + * either continue right away, or we will sleep waiting on the async thread to + * do its work. + * + * We do this unlocked - we only need to know whether there is anything in the + * AIL at the time we are called. We don't need to access the contents of + * any of the objects, so the lock is not needed. */ -static xfs_lsn_t -xfs_ail_max_lsn( - struct xfs_ail *ailp) +void +xfs_trans_ail_push( + struct xfs_ail *ailp, + xfs_lsn_t threshold_lsn) { - xfs_lsn_t lsn = 0; - xfs_log_item_t *lip; - - spin_lock(&ailp->xa_lock); - lip = xfs_ail_max(ailp); - if (lip) - lsn = lip->li_lsn; - spin_unlock(&ailp->xa_lock); + xfs_log_item_t *lip; - return lsn; + lip = xfs_ail_min(ailp); + if (lip && !XFS_FORCED_SHUTDOWN(ailp->xa_mount)) { + if (XFS_LSN_CMP(threshold_lsn, ailp->xa_target) > 0) + xfsaild_wakeup(ailp, threshold_lsn); + } } /* @@ -300,57 +236,16 @@ xfs_trans_ail_cursor_first( } /* - * splice the log item list into the AIL at the given LSN. + * xfsaild_push does the work of pushing on the AIL. Returning a timeout of + * zero indicates that the caller should sleep until woken. */ -static void -xfs_ail_splice( - struct xfs_ail *ailp, - struct list_head *list, - xfs_lsn_t lsn) -{ - xfs_log_item_t *next_lip; - - /* If the list is empty, just insert the item. */ - if (list_empty(&ailp->xa_ail)) { - list_splice(list, &ailp->xa_ail); - return; - } - - list_for_each_entry_reverse(next_lip, &ailp->xa_ail, li_ail) { - if (XFS_LSN_CMP(next_lip->li_lsn, lsn) <= 0) - break; - } - - ASSERT(&next_lip->li_ail == &ailp->xa_ail || - XFS_LSN_CMP(next_lip->li_lsn, lsn) <= 0); - - list_splice_init(list, &next_lip->li_ail); -} - -/* - * Delete the given item from the AIL. Return a pointer to the item. - */ -static void -xfs_ail_delete( - struct xfs_ail *ailp, - xfs_log_item_t *lip) -{ - xfs_ail_check(ailp, lip); - list_del(&lip->li_ail); - xfs_trans_ail_cursor_clear(ailp, lip); -} - -/* - * xfs_ail_worker does the work of pushing on the AIL. It will requeue itself - * to run at a later time if there is more work to do to complete the push. - */ -STATIC void -xfs_ail_worker( - struct work_struct *work) +long +xfsaild_push( + struct xfs_ail *ailp, + xfs_lsn_t *last_lsn) { - struct xfs_ail *ailp = container_of(to_delayed_work(work), - struct xfs_ail, xa_work); - long tout; + long tout = 0; + xfs_lsn_t last_pushed_lsn = *last_lsn; xfs_lsn_t target = ailp->xa_target; xfs_lsn_t lsn; xfs_log_item_t *lip; @@ -361,15 +256,15 @@ xfs_ail_worker( spin_lock(&ailp->xa_lock); xfs_trans_ail_cursor_init(ailp, cur); - lip = xfs_trans_ail_cursor_first(ailp, cur, ailp->xa_last_pushed_lsn); + lip = xfs_trans_ail_cursor_first(ailp, cur, *last_lsn); if (!lip || XFS_FORCED_SHUTDOWN(mp)) { /* * AIL is empty or our push has reached the end. */ xfs_trans_ail_cursor_done(ailp, cur); spin_unlock(&ailp->xa_lock); - ailp->xa_last_pushed_lsn = 0; - return; + *last_lsn = 0; + return tout; } XFS_STATS_INC(xs_push_ail); @@ -406,13 +301,13 @@ xfs_ail_worker( case XFS_ITEM_SUCCESS: XFS_STATS_INC(xs_push_ail_success); IOP_PUSH(lip); - ailp->xa_last_pushed_lsn = lsn; + last_pushed_lsn = lsn; break; case XFS_ITEM_PUSHBUF: XFS_STATS_INC(xs_push_ail_pushbuf); IOP_PUSHBUF(lip); - ailp->xa_last_pushed_lsn = lsn; + last_pushed_lsn = lsn; push_xfsbufd = 1; break; @@ -424,7 +319,7 @@ xfs_ail_worker( case XFS_ITEM_LOCKED: XFS_STATS_INC(xs_push_ail_locked); - ailp->xa_last_pushed_lsn = lsn; + last_pushed_lsn = lsn; stuck++; break; @@ -479,23 +374,9 @@ xfs_ail_worker( wake_up_process(mp->m_ddev_targp->bt_task); } - /* assume we have more work to do in a short while */ - tout = 10; if (!count) { /* We're past our target or empty, so idle */ - ailp->xa_last_pushed_lsn = 0; - - /* - * Check for an updated push target before clearing the - * XFS_AIL_PUSHING_BIT. If the target changed, we've got more - * work to do. Wait a bit longer before starting that work. - */ - smp_rmb(); - if (ailp->xa_target == target) { - clear_bit(XFS_AIL_PUSHING_BIT, &ailp->xa_flags); - return; - } - tout = 50; + last_pushed_lsn = 0; } else if (XFS_LSN_CMP(lsn, target) >= 0) { /* * We reached the target so wait a bit longer for I/O to @@ -503,7 +384,7 @@ xfs_ail_worker( * start the next scan from the start of the AIL. */ tout = 50; - ailp->xa_last_pushed_lsn = 0; + last_pushed_lsn = 0; } else if ((stuck * 100) / count > 90) { /* * Either there is a lot of contention on the AIL or we @@ -515,61 +396,14 @@ xfs_ail_worker( * continuing from where we were. */ tout = 20; + } else { + /* more to do, but wait a short while before continuing */ + tout = 10; } - - /* There is more to do, requeue us. */ - queue_delayed_work(xfs_syncd_wq, &ailp->xa_work, - msecs_to_jiffies(tout)); -} - -/* - * This routine is called to move the tail of the AIL forward. It does this by - * trying to flush items in the AIL whose lsns are below the given - * threshold_lsn. - * - * The push is run asynchronously in a workqueue, which means the caller needs - * to handle waiting on the async flush for space to become available. - * We don't want to interrupt any push that is in progress, hence we only queue - * work if we set the pushing bit approriately. - * - * We do this unlocked - we only need to know whether there is anything in the - * AIL at the time we are called. We don't need to access the contents of - * any of the objects, so the lock is not needed. - */ -void -xfs_ail_push( - struct xfs_ail *ailp, - xfs_lsn_t threshold_lsn) -{ - xfs_log_item_t *lip; - - lip = xfs_ail_min(ailp); - if (!lip || XFS_FORCED_SHUTDOWN(ailp->xa_mount) || - XFS_LSN_CMP(threshold_lsn, ailp->xa_target) <= 0) - return; - - /* - * Ensure that the new target is noticed in push code before it clears - * the XFS_AIL_PUSHING_BIT. - */ - smp_wmb(); - ailp->xa_target = threshold_lsn; - if (!test_and_set_bit(XFS_AIL_PUSHING_BIT, &ailp->xa_flags)) - queue_delayed_work(xfs_syncd_wq, &ailp->xa_work, 0); + *last_lsn = last_pushed_lsn; + return tout; } -/* - * Push out all items in the AIL immediately - */ -void -xfs_ail_push_all( - struct xfs_ail *ailp) -{ - xfs_lsn_t threshold_lsn = xfs_ail_max_lsn(ailp); - - if (threshold_lsn) - xfs_ail_push(ailp, threshold_lsn); -} /* * This is to be called when an item is unlocked that may have @@ -781,6 +615,7 @@ xfs_trans_ail_init( xfs_mount_t *mp) { struct xfs_ail *ailp; + int error; ailp = kmem_zalloc(sizeof(struct xfs_ail), KM_MAYFAIL); if (!ailp) @@ -789,9 +624,15 @@ xfs_trans_ail_init( ailp->xa_mount = mp; INIT_LIST_HEAD(&ailp->xa_ail); spin_lock_init(&ailp->xa_lock); - INIT_DELAYED_WORK(&ailp->xa_work, xfs_ail_worker); + error = xfsaild_start(ailp); + if (error) + goto out_free_ailp; mp->m_ail = ailp; return 0; + +out_free_ailp: + kmem_free(ailp); + return error; } void @@ -800,6 +641,124 @@ xfs_trans_ail_destroy( { struct xfs_ail *ailp = mp->m_ail; - cancel_delayed_work_sync(&ailp->xa_work); + xfsaild_stop(ailp); kmem_free(ailp); } + +/* + * splice the log item list into the AIL at the given LSN. + */ +STATIC void +xfs_ail_splice( + struct xfs_ail *ailp, + struct list_head *list, + xfs_lsn_t lsn) +{ + xfs_log_item_t *next_lip; + + /* + * If the list is empty, just insert the item. + */ + if (list_empty(&ailp->xa_ail)) { + list_splice(list, &ailp->xa_ail); + return; + } + + list_for_each_entry_reverse(next_lip, &ailp->xa_ail, li_ail) { + if (XFS_LSN_CMP(next_lip->li_lsn, lsn) <= 0) + break; + } + + ASSERT((&next_lip->li_ail == &ailp->xa_ail) || + (XFS_LSN_CMP(next_lip->li_lsn, lsn) <= 0)); + + list_splice_init(list, &next_lip->li_ail); + return; +} + +/* + * Delete the given item from the AIL. Return a pointer to the item. + */ +STATIC void +xfs_ail_delete( + struct xfs_ail *ailp, + xfs_log_item_t *lip) +{ + xfs_ail_check(ailp, lip); + list_del(&lip->li_ail); + xfs_trans_ail_cursor_clear(ailp, lip); +} + +/* + * Return a pointer to the first item in the AIL. + * If the AIL is empty, then return NULL. + */ +STATIC xfs_log_item_t * +xfs_ail_min( + struct xfs_ail *ailp) +{ + if (list_empty(&ailp->xa_ail)) + return NULL; + + return list_first_entry(&ailp->xa_ail, xfs_log_item_t, li_ail); +} + +/* + * Return a pointer to the item which follows + * the given item in the AIL. If the given item + * is the last item in the list, then return NULL. + */ +STATIC xfs_log_item_t * +xfs_ail_next( + struct xfs_ail *ailp, + xfs_log_item_t *lip) +{ + if (lip->li_ail.next == &ailp->xa_ail) + return NULL; + + return list_first_entry(&lip->li_ail, xfs_log_item_t, li_ail); +} + +#ifdef DEBUG +/* + * Check that the list is sorted as it should be. + */ +STATIC void +xfs_ail_check( + struct xfs_ail *ailp, + xfs_log_item_t *lip) +{ + xfs_log_item_t *prev_lip; + + if (list_empty(&ailp->xa_ail)) + return; + + /* + * Check the next and previous entries are valid. + */ + ASSERT((lip->li_flags & XFS_LI_IN_AIL) != 0); + prev_lip = list_entry(lip->li_ail.prev, xfs_log_item_t, li_ail); + if (&prev_lip->li_ail != &ailp->xa_ail) + ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) <= 0); + + prev_lip = list_entry(lip->li_ail.next, xfs_log_item_t, li_ail); + if (&prev_lip->li_ail != &ailp->xa_ail) + ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) >= 0); + + +#ifdef XFS_TRANS_DEBUG + /* + * Walk the list checking lsn ordering, and that every entry has the + * XFS_LI_IN_AIL flag set. This is really expensive, so only do it + * when specifically debugging the transaction subsystem. + */ + prev_lip = list_entry(&ailp->xa_ail, xfs_log_item_t, li_ail); + list_for_each_entry(lip, &ailp->xa_ail, li_ail) { + if (&prev_lip->li_ail != &ailp->xa_ail) + ASSERT(XFS_LSN_CMP(prev_lip->li_lsn, lip->li_lsn) <= 0); + ASSERT((lip->li_flags & XFS_LI_IN_AIL) != 0); + prev_lip = lip; + } +#endif /* XFS_TRANS_DEBUG */ +} +#endif /* DEBUG */ diff --git a/trunk/fs/xfs/xfs_trans_priv.h b/trunk/fs/xfs/xfs_trans_priv.h index 6b164e9e9a1f..35162c238fa3 100644 --- a/trunk/fs/xfs/xfs_trans_priv.h +++ b/trunk/fs/xfs/xfs_trans_priv.h @@ -65,22 +65,16 @@ struct xfs_ail_cursor { struct xfs_ail { struct xfs_mount *xa_mount; struct list_head xa_ail; + uint xa_gen; + struct task_struct *xa_task; xfs_lsn_t xa_target; struct xfs_ail_cursor xa_cursors; spinlock_t xa_lock; - struct delayed_work xa_work; - xfs_lsn_t xa_last_pushed_lsn; - unsigned long xa_flags; }; -#define XFS_AIL_PUSHING_BIT 0 - /* * From xfs_trans_ail.c */ - -extern struct workqueue_struct *xfs_ail_wq; /* AIL workqueue */ - void xfs_trans_ail_update_bulk(struct xfs_ail *ailp, struct xfs_log_item **log_items, int nr_items, xfs_lsn_t lsn) __releases(ailp->xa_lock); @@ -104,13 +98,12 @@ xfs_trans_ail_delete( xfs_trans_ail_delete_bulk(ailp, &lip, 1); } -void xfs_ail_push(struct xfs_ail *, xfs_lsn_t); -void xfs_ail_push_all(struct xfs_ail *); -xfs_lsn_t xfs_ail_min_lsn(struct xfs_ail *ailp); - +void xfs_trans_ail_push(struct xfs_ail *, xfs_lsn_t); void xfs_trans_unlocked_item(struct xfs_ail *, xfs_log_item_t *); +xfs_lsn_t xfs_trans_ail_tail(struct xfs_ail *ailp); + struct xfs_log_item *xfs_trans_ail_cursor_first(struct xfs_ail *ailp, struct xfs_ail_cursor *cur, xfs_lsn_t lsn); @@ -119,6 +112,11 @@ struct xfs_log_item *xfs_trans_ail_cursor_next(struct xfs_ail *ailp, void xfs_trans_ail_cursor_done(struct xfs_ail *ailp, struct xfs_ail_cursor *cur); +long xfsaild_push(struct xfs_ail *, xfs_lsn_t *); +void xfsaild_wakeup(struct xfs_ail *, xfs_lsn_t); +int xfsaild_start(struct xfs_ail *); +void xfsaild_stop(struct xfs_ail *); + #if BITS_PER_LONG != 64 static inline void xfs_trans_ail_copy_lsn( diff --git a/trunk/include/linux/blkdev.h b/trunk/include/linux/blkdev.h index cbbfd98ad4a3..32176cc8e715 100644 --- a/trunk/include/linux/blkdev.h +++ b/trunk/include/linux/blkdev.h @@ -697,7 +697,7 @@ extern void blk_start_queue(struct request_queue *q); extern void blk_stop_queue(struct request_queue *q); extern void blk_sync_queue(struct request_queue *q); extern void __blk_stop_queue(struct request_queue *q); -extern void __blk_run_queue(struct request_queue *q); +extern void __blk_run_queue(struct request_queue *q, bool force_kblockd); extern void blk_run_queue(struct request_queue *); extern int blk_rq_map_user(struct request_queue *, struct request *, struct rq_map_data *, void __user *, unsigned long, @@ -857,39 +857,26 @@ extern void blk_put_queue(struct request_queue *); struct blk_plug { unsigned long magic; struct list_head list; - struct list_head cb_list; unsigned int should_sort; }; -struct blk_plug_cb { - struct list_head list; - void (*callback)(struct blk_plug_cb *); -}; extern void blk_start_plug(struct blk_plug *); extern void blk_finish_plug(struct blk_plug *); -extern void blk_flush_plug_list(struct blk_plug *, bool); +extern void __blk_flush_plug(struct task_struct *, struct blk_plug *); static inline void blk_flush_plug(struct task_struct *tsk) { struct blk_plug *plug = tsk->plug; - if (plug) - blk_flush_plug_list(plug, false); -} - -static inline void blk_schedule_flush_plug(struct task_struct *tsk) -{ - struct blk_plug *plug = tsk->plug; - - if (plug) - blk_flush_plug_list(plug, true); + if (unlikely(plug)) + __blk_flush_plug(tsk, plug); } static inline bool blk_needs_flush_plug(struct task_struct *tsk) { struct blk_plug *plug = tsk->plug; - return plug && (!list_empty(&plug->list) || !list_empty(&plug->cb_list)); + return plug && !list_empty(&plug->list); } /* @@ -1327,11 +1314,6 @@ static inline void blk_flush_plug(struct task_struct *task) { } -static inline void blk_schedule_flush_plug(struct task_struct *task) -{ -} - - static inline bool blk_needs_flush_plug(struct task_struct *tsk) { return false; diff --git a/trunk/include/linux/can/platform/mcp251x.h b/trunk/include/linux/can/platform/mcp251x.h index 089fe43211a4..8e20540043f5 100644 --- a/trunk/include/linux/can/platform/mcp251x.h +++ b/trunk/include/linux/can/platform/mcp251x.h @@ -12,7 +12,6 @@ /** * struct mcp251x_platform_data - MCP251X SPI CAN controller platform data * @oscillator_frequency: - oscillator frequency in Hz - * @irq_flags: - IRQF configuration flags * @board_specific_setup: - called before probing the chip (power,reset) * @transceiver_enable: - called to power on/off the transceiver * @power_enable: - called to power on/off the mcp *and* the @@ -25,7 +24,6 @@ struct mcp251x_platform_data { unsigned long oscillator_frequency; - unsigned long irq_flags; int (*board_specific_setup)(struct spi_device *spi); int (*transceiver_enable)(int enable); int (*power_enable) (int enable); diff --git a/trunk/include/linux/device-mapper.h b/trunk/include/linux/device-mapper.h index 32a4423710f5..e2768834f397 100644 --- a/trunk/include/linux/device-mapper.h +++ b/trunk/include/linux/device-mapper.h @@ -197,6 +197,7 @@ struct dm_target { struct dm_target_callbacks { struct list_head list; int (*congested_fn) (struct dm_target_callbacks *, int); + void (*unplug_fn)(struct dm_target_callbacks *); }; int dm_register_target(struct target_type *t); diff --git a/trunk/include/linux/input.h b/trunk/include/linux/input.h index 771d6d85667d..f3a7794a18c4 100644 --- a/trunk/include/linux/input.h +++ b/trunk/include/linux/input.h @@ -167,7 +167,6 @@ struct input_keymap_entry { #define SYN_REPORT 0 #define SYN_CONFIG 1 #define SYN_MT_REPORT 2 -#define SYN_DROPPED 3 /* * Keys and buttons @@ -554,8 +553,8 @@ struct input_keymap_entry { #define KEY_DVD 0x185 /* Media Select DVD */ #define KEY_AUX 0x186 #define KEY_MP3 0x187 -#define KEY_AUDIO 0x188 /* AL Audio Browser */ -#define KEY_VIDEO 0x189 /* AL Movie Browser */ +#define KEY_AUDIO 0x188 +#define KEY_VIDEO 0x189 #define KEY_DIRECTORY 0x18a #define KEY_LIST 0x18b #define KEY_MEMO 0x18c /* Media Select Messages */ @@ -604,9 +603,8 @@ struct input_keymap_entry { #define KEY_FRAMEFORWARD 0x1b5 #define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */ #define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */ -#define KEY_10CHANNELSUP 0x1b8 /* 10 channels up (10+) */ -#define KEY_10CHANNELSDOWN 0x1b9 /* 10 channels down (10-) */ -#define KEY_IMAGES 0x1ba /* AL Image Browser */ +#define KEY_10CHANNELSUP 0x1b8 /* 10 channels up (10+) */ +#define KEY_10CHANNELSDOWN 0x1b9 /* 10 channels down (10-) */ #define KEY_DEL_EOL 0x1c0 #define KEY_DEL_EOS 0x1c1 diff --git a/trunk/include/linux/input/mt.h b/trunk/include/linux/input/mt.h index 318bb82325a6..b3ac06a4435d 100644 --- a/trunk/include/linux/input/mt.h +++ b/trunk/include/linux/input/mt.h @@ -48,12 +48,6 @@ static inline void input_mt_slot(struct input_dev *dev, int slot) input_event(dev, EV_ABS, ABS_MT_SLOT, slot); } -static inline bool input_is_mt_axis(int axis) -{ - return axis == ABS_MT_SLOT || - (axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST); -} - void input_mt_report_slot_state(struct input_dev *dev, unsigned int tool_type, bool active); diff --git a/trunk/include/linux/memcontrol.h b/trunk/include/linux/memcontrol.h index 5e9840f50980..5a5ce7055839 100644 --- a/trunk/include/linux/memcontrol.h +++ b/trunk/include/linux/memcontrol.h @@ -216,7 +216,7 @@ static inline void mem_cgroup_del_lru_list(struct page *page, int lru) return ; } -static inline void mem_cgroup_rotate_reclaimable_page(struct page *page) +static inline inline void mem_cgroup_rotate_reclaimable_page(struct page *page) { return ; } diff --git a/trunk/include/linux/mfd/core.h b/trunk/include/linux/mfd/core.h index aef23309a742..ad1b19aa6508 100644 --- a/trunk/include/linux/mfd/core.h +++ b/trunk/include/linux/mfd/core.h @@ -86,25 +86,16 @@ extern int mfd_clone_cell(const char *cell, const char **clones, */ static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev) { - return pdev->mfd_cell; + return pdev->dev.platform_data; } /* * Given a platform device that's been created by mfd_add_devices(), fetch * the .mfd_data entry from the mfd_cell that created it. - * Otherwise just return the platform_data pointer. - * This maintains compatibility with platform drivers whose devices aren't - * created by the mfd layer, and expect platform_data to contain what would've - * otherwise been in mfd_data. */ static inline void *mfd_get_data(struct platform_device *pdev) { - const struct mfd_cell *cell = mfd_get_cell(pdev); - - if (cell) - return cell->mfd_data; - else - return pdev->dev.platform_data; + return mfd_get_cell(pdev)->mfd_data; } extern int mfd_add_devices(struct device *parent, int id, diff --git a/trunk/include/linux/netfilter.h b/trunk/include/linux/netfilter.h index 7fa95df60146..eeec00abb664 100644 --- a/trunk/include/linux/netfilter.h +++ b/trunk/include/linux/netfilter.h @@ -270,8 +270,7 @@ struct nf_afinfo { unsigned int dataoff, unsigned int len, u_int8_t protocol); - int (*route)(struct net *net, struct dst_entry **dst, - struct flowi *fl, bool strict); + int (*route)(struct dst_entry **dst, struct flowi *fl); void (*saveroute)(const struct sk_buff *skb, struct nf_queue_entry *entry); int (*reroute)(struct sk_buff *skb, diff --git a/trunk/include/linux/netfilter/ipset/ip_set.h b/trunk/include/linux/netfilter/ipset/ip_set.h index 5a262e3ae715..ec333d83f3b4 100644 --- a/trunk/include/linux/netfilter/ipset/ip_set.h +++ b/trunk/include/linux/netfilter/ipset/ip_set.h @@ -293,7 +293,7 @@ struct ip_set { /* Lock protecting the set data */ rwlock_t lock; /* References to the set */ - u32 ref; + atomic_t ref; /* The core set type */ struct ip_set_type *type; /* The type variant doing the real job */ diff --git a/trunk/include/linux/netfilter/ipset/ip_set_ahash.h b/trunk/include/linux/netfilter/ipset/ip_set_ahash.h index a0196ac79051..ec9d9bea1e37 100644 --- a/trunk/include/linux/netfilter/ipset/ip_set_ahash.h +++ b/trunk/include/linux/netfilter/ipset/ip_set_ahash.h @@ -515,7 +515,8 @@ type_pf_head(struct ip_set *set, struct sk_buff *skb) if (h->netmask != HOST_MASK) NLA_PUT_U8(skb, IPSET_ATTR_NETMASK, h->netmask); #endif - NLA_PUT_NET32(skb, IPSET_ATTR_REFERENCES, htonl(set->ref - 1)); + NLA_PUT_NET32(skb, IPSET_ATTR_REFERENCES, + htonl(atomic_read(&set->ref) - 1)); NLA_PUT_NET32(skb, IPSET_ATTR_MEMSIZE, htonl(memsize)); if (with_timeout(h->timeout)) NLA_PUT_NET32(skb, IPSET_ATTR_TIMEOUT, htonl(h->timeout)); diff --git a/trunk/include/linux/pid.h b/trunk/include/linux/pid.h index cdced84261d7..31afb7ecbe1f 100644 --- a/trunk/include/linux/pid.h +++ b/trunk/include/linux/pid.h @@ -117,7 +117,7 @@ extern struct pid *find_vpid(int nr); */ extern struct pid *find_get_pid(int nr); extern struct pid *find_ge_pid(int nr, struct pid_namespace *); -int next_pidmap(struct pid_namespace *pid_ns, unsigned int last); +int next_pidmap(struct pid_namespace *pid_ns, int last); extern struct pid *alloc_pid(struct pid_namespace *ns); extern void free_pid(struct pid *pid); diff --git a/trunk/include/linux/platform_device.h b/trunk/include/linux/platform_device.h index 744942c95fec..d96db9825708 100644 --- a/trunk/include/linux/platform_device.h +++ b/trunk/include/linux/platform_device.h @@ -14,8 +14,6 @@ #include #include -struct mfd_cell; - struct platform_device { const char * name; int id; @@ -25,9 +23,6 @@ struct platform_device { const struct platform_device_id *id_entry; - /* MFD cell pointer */ - struct mfd_cell *mfd_cell; - /* arch specific additions */ struct pdev_archdata archdata; }; diff --git a/trunk/include/linux/rio.h b/trunk/include/linux/rio.h index 4d50611112ba..4e37a7cfa726 100644 --- a/trunk/include/linux/rio.h +++ b/trunk/include/linux/rio.h @@ -396,7 +396,7 @@ union rio_pw_msg { }; /* Architecture and hardware-specific functions */ -extern int rio_register_mport(struct rio_mport *); +extern void rio_register_mport(struct rio_mport *); extern int rio_open_inb_mbox(struct rio_mport *, void *, int, int); extern void rio_close_inb_mbox(struct rio_mport *, int); extern int rio_open_outb_mbox(struct rio_mport *, void *, int, int); diff --git a/trunk/include/linux/rio_ids.h b/trunk/include/linux/rio_ids.h index 0cee0152aca9..7410d3365e2a 100644 --- a/trunk/include/linux/rio_ids.h +++ b/trunk/include/linux/rio_ids.h @@ -35,7 +35,6 @@ #define RIO_DID_IDTCPS6Q 0x035f #define RIO_DID_IDTCPS10Q 0x035e #define RIO_DID_IDTCPS1848 0x0374 -#define RIO_DID_IDTCPS1432 0x0375 #define RIO_DID_IDTCPS1616 0x0379 #define RIO_DID_IDTVPS1616 0x0377 #define RIO_DID_IDTSPS1616 0x0378 diff --git a/trunk/include/linux/rtc.h b/trunk/include/linux/rtc.h index 877ece45426f..2ca7e8a78060 100644 --- a/trunk/include/linux/rtc.h +++ b/trunk/include/linux/rtc.h @@ -228,8 +228,6 @@ extern int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alrm); extern int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alrm); -extern int rtc_initialize_alarm(struct rtc_device *rtc, - struct rtc_wkalrm *alrm); extern void rtc_update_irq(struct rtc_device *rtc, unsigned long num, unsigned long events); diff --git a/trunk/include/linux/sched.h b/trunk/include/linux/sched.h index 18d63cea2848..4ec2c027e92c 100644 --- a/trunk/include/linux/sched.h +++ b/trunk/include/linux/sched.h @@ -1254,9 +1254,6 @@ struct task_struct { #endif struct mm_struct *mm, *active_mm; -#ifdef CONFIG_COMPAT_BRK - unsigned brk_randomized:1; -#endif #if defined(SPLIT_RSS_COUNTING) struct task_rss_stat rss_stat; #endif diff --git a/trunk/include/linux/suspend.h b/trunk/include/linux/suspend.h index 083ffea7ba18..5a89e3612875 100644 --- a/trunk/include/linux/suspend.h +++ b/trunk/include/linux/suspend.h @@ -249,8 +249,6 @@ extern void hibernation_set_ops(const struct platform_hibernation_ops *ops); extern int hibernate(void); extern bool system_entering_hibernation(void); #else /* CONFIG_HIBERNATION */ -static inline void register_nosave_region(unsigned long b, unsigned long e) {} -static inline void register_nosave_region_late(unsigned long b, unsigned long e) {} static inline int swsusp_page_is_forbidden(struct page *p) { return 0; } static inline void swsusp_set_page_free(struct page *p) {} static inline void swsusp_unset_page_free(struct page *p) {} @@ -299,7 +297,14 @@ static inline bool pm_wakeup_pending(void) { return false; } extern struct mutex pm_mutex; -#ifndef CONFIG_HIBERNATE_CALLBACKS +#ifndef CONFIG_HIBERNATION +static inline void register_nosave_region(unsigned long b, unsigned long e) +{ +} +static inline void register_nosave_region_late(unsigned long b, unsigned long e) +{ +} + static inline void lock_system_sleep(void) {} static inline void unlock_system_sleep(void) {} diff --git a/trunk/include/linux/vmstat.h b/trunk/include/linux/vmstat.h index 2b3831b58aa4..461c0119664f 100644 --- a/trunk/include/linux/vmstat.h +++ b/trunk/include/linux/vmstat.h @@ -58,13 +58,6 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, UNEVICTABLE_PGCLEARED, /* on COW, page truncate */ UNEVICTABLE_PGSTRANDED, /* unable to isolate on unlock */ UNEVICTABLE_MLOCKFREED, -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - THP_FAULT_ALLOC, - THP_FAULT_FALLBACK, - THP_COLLAPSE_ALLOC, - THP_COLLAPSE_ALLOC_FAILED, - THP_SPLIT, -#endif NR_VM_EVENT_ITEMS }; diff --git a/trunk/include/net/9p/9p.h b/trunk/include/net/9p/9p.h index d2df55b0c213..cdf2e8ac4309 100644 --- a/trunk/include/net/9p/9p.h +++ b/trunk/include/net/9p/9p.h @@ -139,6 +139,8 @@ do { \ */ enum p9_msg_t { + P9_TSYNCFS = 0, + P9_RSYNCFS, P9_TLERROR = 6, P9_RLERROR, P9_TSTATFS = 8, diff --git a/trunk/include/net/9p/client.h b/trunk/include/net/9p/client.h index 051a99f79769..85c1413f054d 100644 --- a/trunk/include/net/9p/client.h +++ b/trunk/include/net/9p/client.h @@ -218,8 +218,8 @@ void p9_client_disconnect(struct p9_client *clnt); void p9_client_begin_disconnect(struct p9_client *clnt); struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, char *uname, u32 n_uname, char *aname); -struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname, - char **wnames, int clone); +struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames, + int clone); int p9_client_open(struct p9_fid *fid, int mode); int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode, char *extension); @@ -230,6 +230,7 @@ int p9_client_create_dotl(struct p9_fid *ofid, char *name, u32 flags, u32 mode, gid_t gid, struct p9_qid *qid); int p9_client_clunk(struct p9_fid *fid); int p9_client_fsync(struct p9_fid *fid, int datasync); +int p9_client_sync_fs(struct p9_fid *fid); int p9_client_remove(struct p9_fid *fid); int p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset, u32 count); diff --git a/trunk/include/net/ip_vs.h b/trunk/include/net/ip_vs.h index d516f00c8e0f..814b434db749 100644 --- a/trunk/include/net/ip_vs.h +++ b/trunk/include/net/ip_vs.h @@ -52,7 +52,7 @@ static inline struct net *skb_net(const struct sk_buff *skb) */ if (likely(skb->dev && skb->dev->nd_net)) return dev_net(skb->dev); - if (skb_dst(skb) && skb_dst(skb)->dev) + if (skb_dst(skb)->dev) return dev_net(skb_dst(skb)->dev); WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n", __func__, __LINE__); diff --git a/trunk/include/net/mac80211.h b/trunk/include/net/mac80211.h index 025d4cc7bbf8..cb13239fe8e3 100644 --- a/trunk/include/net/mac80211.h +++ b/trunk/include/net/mac80211.h @@ -1753,19 +1753,8 @@ enum ieee80211_ampdu_mlme_action { * that TX/RX_STOP can pass NULL for this parameter. * The @buf_size parameter is only valid when the action is set to * %IEEE80211_AMPDU_TX_OPERATIONAL and indicates the peer's reorder - * buffer size (number of subframes) for this session -- the driver - * may neither send aggregates containing more subframes than this - * nor send aggregates in a way that lost frames would exceed the - * buffer size. If just limiting the aggregate size, this would be - * possible with a buf_size of 8: - * - TX: 1.....7 - * - RX: 2....7 (lost frame #1) - * - TX: 8..1... - * which is invalid since #1 was now re-transmitted well past the - * buffer size of 8. Correct ways to retransmit #1 would be: - * - TX: 1 or 18 or 81 - * Even "189" would be wrong since 1 could be lost again. - * + * buffer size (number of subframes) for this session -- aggregates + * containing more subframes than this may not be transmitted to the peer. * Returns a negative error code on failure. * The callback can sleep. * diff --git a/trunk/include/net/route.h b/trunk/include/net/route.h index 8fce0621cad1..f88429cad52a 100644 --- a/trunk/include/net/route.h +++ b/trunk/include/net/route.h @@ -64,7 +64,6 @@ struct rtable { __be32 rt_dst; /* Path destination */ __be32 rt_src; /* Path source */ - int rt_route_iif; int rt_iif; int rt_oif; __u32 rt_mark; @@ -81,12 +80,12 @@ struct rtable { static inline bool rt_is_input_route(struct rtable *rt) { - return rt->rt_route_iif != 0; + return rt->rt_iif != 0; } static inline bool rt_is_output_route(struct rtable *rt) { - return rt->rt_route_iif == 0; + return rt->rt_iif == 0; } struct ip_rt_acct { diff --git a/trunk/include/trace/events/block.h b/trunk/include/trace/events/block.h index bf366547da25..78f18adb49c8 100644 --- a/trunk/include/trace/events/block.h +++ b/trunk/include/trace/events/block.h @@ -401,9 +401,9 @@ TRACE_EVENT(block_plug, DECLARE_EVENT_CLASS(block_unplug, - TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit), + TP_PROTO(struct request_queue *q), - TP_ARGS(q, depth, explicit), + TP_ARGS(q), TP_STRUCT__entry( __field( int, nr_rq ) @@ -411,7 +411,7 @@ DECLARE_EVENT_CLASS(block_unplug, ), TP_fast_assign( - __entry->nr_rq = depth; + __entry->nr_rq = q->rq.count[READ] + q->rq.count[WRITE]; memcpy(__entry->comm, current->comm, TASK_COMM_LEN); ), @@ -419,19 +419,31 @@ DECLARE_EVENT_CLASS(block_unplug, ); /** - * block_unplug - release of operations requests in request queue + * block_unplug_timer - timed release of operations requests in queue to device driver + * @q: request queue to unplug + * + * Unplug the request queue @q because a timer expired and allow block + * operation requests to be sent to the device driver. + */ +DEFINE_EVENT(block_unplug, block_unplug_timer, + + TP_PROTO(struct request_queue *q), + + TP_ARGS(q) +); + +/** + * block_unplug_io - release of operations requests in request queue * @q: request queue to unplug - * @depth: number of requests just added to the queue - * @explicit: whether this was an explicit unplug, or one from schedule() * * Unplug request queue @q because device driver is scheduled to work * on elements in the request queue. */ -DEFINE_EVENT(block_unplug, block_unplug, +DEFINE_EVENT(block_unplug, block_unplug_io, - TP_PROTO(struct request_queue *q, unsigned int depth, bool explicit), + TP_PROTO(struct request_queue *q), - TP_ARGS(q, depth, explicit) + TP_ARGS(q) ); /** diff --git a/trunk/kernel/futex.c b/trunk/kernel/futex.c index fe28dc282eae..dfb924ffe65b 100644 --- a/trunk/kernel/futex.c +++ b/trunk/kernel/futex.c @@ -1886,7 +1886,7 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val, restart->futex.val = val; restart->futex.time = abs_time->tv64; restart->futex.bitset = bitset; - restart->futex.flags = flags | FLAGS_HAS_TIMEOUT; + restart->futex.flags = flags; ret = -ERESTART_RESTARTBLOCK; diff --git a/trunk/kernel/module.c b/trunk/kernel/module.c index 4d5c16aae745..d5938a5c19c4 100644 --- a/trunk/kernel/module.c +++ b/trunk/kernel/module.c @@ -2790,7 +2790,7 @@ static struct module *load_module(void __user *umod, } /* This has to be done once we're sure module name is unique. */ - if (!mod->taints || mod->taints == (1U<taints) dynamic_debug_setup(info.debug, info.num_debug); /* Find duplicate symbols */ @@ -2827,7 +2827,7 @@ static struct module *load_module(void __user *umod, module_bug_cleanup(mod); ddebug: - if (!mod->taints || mod->taints == (1U<taints) dynamic_debug_remove(info.debug); unlock: mutex_unlock(&module_mutex); diff --git a/trunk/kernel/perf_event.c b/trunk/kernel/perf_event.c index 8e81a9860a0d..27960f114efd 100644 --- a/trunk/kernel/perf_event.c +++ b/trunk/kernel/perf_event.c @@ -364,7 +364,6 @@ void perf_cgroup_switch(struct task_struct *task, int mode) } if (mode & PERF_CGROUP_SWIN) { - WARN_ON_ONCE(cpuctx->cgrp); /* set cgrp before ctxsw in to * allow event_filter_match() to not * have to pass task around @@ -2424,14 +2423,6 @@ static void perf_event_enable_on_exec(struct perf_event_context *ctx) if (!ctx || !ctx->nr_events) goto out; - /* - * We must ctxsw out cgroup events to avoid conflict - * when invoking perf_task_event_sched_in() later on - * in this function. Otherwise we end up trying to - * ctxswin cgroup events which are already scheduled - * in. - */ - perf_cgroup_sched_out(current); task_ctx_sched_out(ctx, EVENT_ALL); raw_spin_lock(&ctx->lock); @@ -2456,9 +2447,6 @@ static void perf_event_enable_on_exec(struct perf_event_context *ctx) raw_spin_unlock(&ctx->lock); - /* - * Also calls ctxswin for cgroup events, if any: - */ perf_event_context_sched_in(ctx, ctx->task); out: local_irq_restore(flags); diff --git a/trunk/kernel/pid.c b/trunk/kernel/pid.c index 57a8346a270e..02f221274265 100644 --- a/trunk/kernel/pid.c +++ b/trunk/kernel/pid.c @@ -217,14 +217,11 @@ static int alloc_pidmap(struct pid_namespace *pid_ns) return -1; } -int next_pidmap(struct pid_namespace *pid_ns, unsigned int last) +int next_pidmap(struct pid_namespace *pid_ns, int last) { int offset; struct pidmap *map, *end; - if (last >= PID_MAX_LIMIT) - return -1; - offset = (last + 1) & BITS_PER_PAGE_MASK; map = &pid_ns->pidmap[(last + 1)/BITS_PER_PAGE]; end = &pid_ns->pidmap[PIDMAP_ENTRIES]; diff --git a/trunk/kernel/power/Kconfig b/trunk/kernel/power/Kconfig index 6de9a8fc3417..4603f08dc47b 100644 --- a/trunk/kernel/power/Kconfig +++ b/trunk/kernel/power/Kconfig @@ -18,13 +18,9 @@ config SUSPEND_FREEZER Turning OFF this setting is NOT recommended! If in doubt, say Y. -config HIBERNATE_CALLBACKS - bool - config HIBERNATION bool "Hibernation (aka 'suspend to disk')" depends on SWAP && ARCH_HIBERNATION_POSSIBLE - select HIBERNATE_CALLBACKS select LZO_COMPRESS select LZO_DECOMPRESS ---help--- @@ -89,7 +85,7 @@ config PM_STD_PARTITION config PM_SLEEP def_bool y - depends on SUSPEND || HIBERNATE_CALLBACKS + depends on SUSPEND || HIBERNATION || XEN_SAVE_RESTORE config PM_SLEEP_SMP def_bool y diff --git a/trunk/kernel/sched.c b/trunk/kernel/sched.c index 312f8b95c2d4..48013633d792 100644 --- a/trunk/kernel/sched.c +++ b/trunk/kernel/sched.c @@ -4111,20 +4111,20 @@ asmlinkage void __sched schedule(void) try_to_wake_up_local(to_wakeup); } deactivate_task(rq, prev, DEQUEUE_SLEEP); - - /* - * If we are going to sleep and we have plugged IO queued, make - * sure to submit it to avoid deadlocks. - */ - if (blk_needs_flush_plug(prev)) { - raw_spin_unlock(&rq->lock); - blk_schedule_flush_plug(prev); - raw_spin_lock(&rq->lock); - } } switch_count = &prev->nvcsw; } + /* + * If we are going to sleep and we have plugged IO queued, make + * sure to submit it to avoid deadlocks. + */ + if (prev->state != TASK_RUNNING && blk_needs_flush_plug(prev)) { + raw_spin_unlock(&rq->lock); + blk_flush_plug(prev); + raw_spin_lock(&rq->lock); + } + pre_schedule(rq, prev); if (unlikely(!rq->nr_running)) diff --git a/trunk/kernel/sched_fair.c b/trunk/kernel/sched_fair.c index 6fa833ab2cb8..7f00772e57c9 100644 --- a/trunk/kernel/sched_fair.c +++ b/trunk/kernel/sched_fair.c @@ -2104,20 +2104,21 @@ balance_tasks(struct rq *this_rq, int this_cpu, struct rq *busiest, enum cpu_idle_type idle, int *all_pinned, int *this_best_prio, struct cfs_rq *busiest_cfs_rq) { - int loops = 0, pulled = 0; + int loops = 0, pulled = 0, pinned = 0; long rem_load_move = max_load_move; struct task_struct *p, *n; if (max_load_move == 0) goto out; + pinned = 1; + list_for_each_entry_safe(p, n, &busiest_cfs_rq->tasks, se.group_node) { if (loops++ > sysctl_sched_nr_migrate) break; if ((p->se.load.weight >> 1) > rem_load_move || - !can_migrate_task(p, busiest, this_cpu, sd, idle, - all_pinned)) + !can_migrate_task(p, busiest, this_cpu, sd, idle, &pinned)) continue; pull_task(busiest, p, this_rq, this_cpu); @@ -2152,6 +2153,9 @@ balance_tasks(struct rq *this_rq, int this_cpu, struct rq *busiest, */ schedstat_add(sd, lb_gained[idle], pulled); + if (all_pinned) + *all_pinned = pinned; + return max_load_move - rem_load_move; } @@ -3123,8 +3127,6 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, if (!sds.busiest || sds.busiest_nr_running == 0) goto out_balanced; - sds.avg_load = (SCHED_LOAD_SCALE * sds.total_load) / sds.total_pwr; - /* * If the busiest group is imbalanced the below checks don't * work because they assumes all things are equal, which typically @@ -3149,6 +3151,7 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, * Don't pull any tasks if this group is already above the domain * average load. */ + sds.avg_load = (SCHED_LOAD_SCALE * sds.total_load) / sds.total_pwr; if (sds.this_load >= sds.avg_load) goto out_balanced; @@ -3337,7 +3340,6 @@ static int load_balance(int this_cpu, struct rq *this_rq, * still unbalanced. ld_moved simply stays zero, so it is * correctly treated as an imbalance. */ - all_pinned = 1; local_irq_save(flags); double_rq_lock(this_rq, busiest); ld_moved = move_tasks(this_rq, this_cpu, busiest, diff --git a/trunk/kernel/signal.c b/trunk/kernel/signal.c index 7165af5f1b11..29e233fd7a0f 100644 --- a/trunk/kernel/signal.c +++ b/trunk/kernel/signal.c @@ -2711,8 +2711,8 @@ SYSCALL_DEFINE3(sigprocmask, int, how, old_sigset_t __user *, set, /** * sys_rt_sigaction - alter an action taken by a process * @sig: signal to be sent - * @act: new sigaction - * @oact: used to save the previous sigaction + * @act: the thread group ID of the thread + * @oact: the PID of the thread * @sigsetsize: size of sigset_t type */ SYSCALL_DEFINE4(rt_sigaction, int, sig, diff --git a/trunk/kernel/trace/blktrace.c b/trunk/kernel/trace/blktrace.c index 6957aa298dfa..7aa40f8e182d 100644 --- a/trunk/kernel/trace/blktrace.c +++ b/trunk/kernel/trace/blktrace.c @@ -850,21 +850,29 @@ static void blk_add_trace_plug(void *ignore, struct request_queue *q) __blk_add_trace(bt, 0, 0, 0, BLK_TA_PLUG, 0, 0, NULL); } -static void blk_add_trace_unplug(void *ignore, struct request_queue *q, - unsigned int depth, bool explicit) +static void blk_add_trace_unplug_io(void *ignore, struct request_queue *q) { struct blk_trace *bt = q->blk_trace; if (bt) { - __be64 rpdu = cpu_to_be64(depth); - u32 what; + unsigned int pdu = q->rq.count[READ] + q->rq.count[WRITE]; + __be64 rpdu = cpu_to_be64(pdu); - if (explicit) - what = BLK_TA_UNPLUG_IO; - else - what = BLK_TA_UNPLUG_TIMER; + __blk_add_trace(bt, 0, 0, 0, BLK_TA_UNPLUG_IO, 0, + sizeof(rpdu), &rpdu); + } +} - __blk_add_trace(bt, 0, 0, 0, what, 0, sizeof(rpdu), &rpdu); +static void blk_add_trace_unplug_timer(void *ignore, struct request_queue *q) +{ + struct blk_trace *bt = q->blk_trace; + + if (bt) { + unsigned int pdu = q->rq.count[READ] + q->rq.count[WRITE]; + __be64 rpdu = cpu_to_be64(pdu); + + __blk_add_trace(bt, 0, 0, 0, BLK_TA_UNPLUG_TIMER, 0, + sizeof(rpdu), &rpdu); } } @@ -1007,7 +1015,9 @@ static void blk_register_tracepoints(void) WARN_ON(ret); ret = register_trace_block_plug(blk_add_trace_plug, NULL); WARN_ON(ret); - ret = register_trace_block_unplug(blk_add_trace_unplug, NULL); + ret = register_trace_block_unplug_timer(blk_add_trace_unplug_timer, NULL); + WARN_ON(ret); + ret = register_trace_block_unplug_io(blk_add_trace_unplug_io, NULL); WARN_ON(ret); ret = register_trace_block_split(blk_add_trace_split, NULL); WARN_ON(ret); @@ -1022,7 +1032,8 @@ static void blk_unregister_tracepoints(void) unregister_trace_block_rq_remap(blk_add_trace_rq_remap, NULL); unregister_trace_block_bio_remap(blk_add_trace_bio_remap, NULL); unregister_trace_block_split(blk_add_trace_split, NULL); - unregister_trace_block_unplug(blk_add_trace_unplug, NULL); + unregister_trace_block_unplug_io(blk_add_trace_unplug_io, NULL); + unregister_trace_block_unplug_timer(blk_add_trace_unplug_timer, NULL); unregister_trace_block_plug(blk_add_trace_plug, NULL); unregister_trace_block_sleeprq(blk_add_trace_sleeprq, NULL); unregister_trace_block_getrq(blk_add_trace_getrq, NULL); diff --git a/trunk/lib/kstrtox.c b/trunk/lib/kstrtox.c index a235f3cc471c..05672e819f8c 100644 --- a/trunk/lib/kstrtox.c +++ b/trunk/lib/kstrtox.c @@ -49,9 +49,12 @@ static int _kstrtoull(const char *s, unsigned int base, unsigned long long *res) val = *s - '0'; else if ('a' <= _tolower(*s) && _tolower(*s) <= 'f') val = _tolower(*s) - 'a' + 10; - else if (*s == '\n' && *(s + 1) == '\0') - break; - else + else if (*s == '\n') { + if (*(s + 1) == '\0') + break; + else + return -EINVAL; + } else return -EINVAL; if (val >= base) diff --git a/trunk/lib/test-kstrtox.c b/trunk/lib/test-kstrtox.c index d55769d63cb8..325c2f9ecebd 100644 --- a/trunk/lib/test-kstrtox.c +++ b/trunk/lib/test-kstrtox.c @@ -315,12 +315,12 @@ static void __init test_kstrtou64_ok(void) {"65537", 10, 65537}, {"2147483646", 10, 2147483646}, {"2147483647", 10, 2147483647}, - {"2147483648", 10, 2147483648ULL}, - {"2147483649", 10, 2147483649ULL}, - {"4294967294", 10, 4294967294ULL}, - {"4294967295", 10, 4294967295ULL}, - {"4294967296", 10, 4294967296ULL}, - {"4294967297", 10, 4294967297ULL}, + {"2147483648", 10, 2147483648}, + {"2147483649", 10, 2147483649}, + {"4294967294", 10, 4294967294}, + {"4294967295", 10, 4294967295}, + {"4294967296", 10, 4294967296}, + {"4294967297", 10, 4294967297}, {"9223372036854775806", 10, 9223372036854775806ULL}, {"9223372036854775807", 10, 9223372036854775807ULL}, {"9223372036854775808", 10, 9223372036854775808ULL}, @@ -369,12 +369,12 @@ static void __init test_kstrtos64_ok(void) {"65537", 10, 65537}, {"2147483646", 10, 2147483646}, {"2147483647", 10, 2147483647}, - {"2147483648", 10, 2147483648LL}, - {"2147483649", 10, 2147483649LL}, - {"4294967294", 10, 4294967294LL}, - {"4294967295", 10, 4294967295LL}, - {"4294967296", 10, 4294967296LL}, - {"4294967297", 10, 4294967297LL}, + {"2147483648", 10, 2147483648}, + {"2147483649", 10, 2147483649}, + {"4294967294", 10, 4294967294}, + {"4294967295", 10, 4294967295}, + {"4294967296", 10, 4294967296}, + {"4294967297", 10, 4294967297}, {"9223372036854775806", 10, 9223372036854775806LL}, {"9223372036854775807", 10, 9223372036854775807LL}, }; @@ -418,10 +418,10 @@ static void __init test_kstrtou32_ok(void) {"65537", 10, 65537}, {"2147483646", 10, 2147483646}, {"2147483647", 10, 2147483647}, - {"2147483648", 10, 2147483648U}, - {"2147483649", 10, 2147483649U}, - {"4294967294", 10, 4294967294U}, - {"4294967295", 10, 4294967295U}, + {"2147483648", 10, 2147483648}, + {"2147483649", 10, 2147483649}, + {"4294967294", 10, 4294967294}, + {"4294967295", 10, 4294967295}, }; TEST_OK(kstrtou32, u32, "%u", test_u32_ok); } diff --git a/trunk/mm/huge_memory.c b/trunk/mm/huge_memory.c index 470dcda10add..0a619e0e2e0b 100644 --- a/trunk/mm/huge_memory.c +++ b/trunk/mm/huge_memory.c @@ -244,28 +244,24 @@ static ssize_t single_flag_show(struct kobject *kobj, struct kobj_attribute *attr, char *buf, enum transparent_hugepage_flag flag) { - return sprintf(buf, "%d\n", - !!test_bit(flag, &transparent_hugepage_flags)); + if (test_bit(flag, &transparent_hugepage_flags)) + return sprintf(buf, "[yes] no\n"); + else + return sprintf(buf, "yes [no]\n"); } - static ssize_t single_flag_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count, enum transparent_hugepage_flag flag) { - unsigned long value; - int ret; - - ret = kstrtoul(buf, 10, &value); - if (ret < 0) - return ret; - if (value > 1) - return -EINVAL; - - if (value) + if (!memcmp("yes", buf, + min(sizeof("yes")-1, count))) { set_bit(flag, &transparent_hugepage_flags); - else + } else if (!memcmp("no", buf, + min(sizeof("no")-1, count))) { clear_bit(flag, &transparent_hugepage_flags); + } else + return -EINVAL; return count; } @@ -684,11 +680,8 @@ int do_huge_pmd_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma, return VM_FAULT_OOM; page = alloc_hugepage_vma(transparent_hugepage_defrag(vma), vma, haddr, numa_node_id(), 0); - if (unlikely(!page)) { - count_vm_event(THP_FAULT_FALLBACK); + if (unlikely(!page)) goto out; - } - count_vm_event(THP_FAULT_ALLOC); if (unlikely(mem_cgroup_newpage_charge(page, mm, GFP_KERNEL))) { put_page(page); goto out; @@ -916,13 +909,11 @@ int do_huge_pmd_wp_page(struct mm_struct *mm, struct vm_area_struct *vma, new_page = NULL; if (unlikely(!new_page)) { - count_vm_event(THP_FAULT_FALLBACK); ret = do_huge_pmd_wp_page_fallback(mm, vma, address, pmd, orig_pmd, page, haddr); put_page(page); goto out; } - count_vm_event(THP_FAULT_ALLOC); if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL))) { put_page(new_page); @@ -1399,7 +1390,6 @@ int split_huge_page(struct page *page) BUG_ON(!PageSwapBacked(page)); __split_huge_page(page, anon_vma); - count_vm_event(THP_SPLIT); BUG_ON(PageCompound(page)); out_unlock: @@ -1794,11 +1784,9 @@ static void collapse_huge_page(struct mm_struct *mm, node, __GFP_OTHER_NODE); if (unlikely(!new_page)) { up_read(&mm->mmap_sem); - count_vm_event(THP_COLLAPSE_ALLOC_FAILED); *hpage = ERR_PTR(-ENOMEM); return; } - count_vm_event(THP_COLLAPSE_ALLOC); if (unlikely(mem_cgroup_newpage_charge(new_page, mm, GFP_KERNEL))) { up_read(&mm->mmap_sem); put_page(new_page); @@ -2163,11 +2151,8 @@ static void khugepaged_do_scan(struct page **hpage) #ifndef CONFIG_NUMA if (!*hpage) { *hpage = alloc_hugepage(khugepaged_defrag()); - if (unlikely(!*hpage)) { - count_vm_event(THP_COLLAPSE_ALLOC_FAILED); + if (unlikely(!*hpage)) break; - } - count_vm_event(THP_COLLAPSE_ALLOC); } #else if (IS_ERR(*hpage)) @@ -2207,11 +2192,8 @@ static struct page *khugepaged_alloc_hugepage(void) do { hpage = alloc_hugepage(khugepaged_defrag()); - if (!hpage) { - count_vm_event(THP_COLLAPSE_ALLOC_FAILED); + if (!hpage) khugepaged_alloc_sleep(); - } else - count_vm_event(THP_COLLAPSE_ALLOC); } while (unlikely(!hpage) && likely(khugepaged_enabled())); return hpage; @@ -2228,11 +2210,8 @@ static void khugepaged_loop(void) while (likely(khugepaged_enabled())) { #ifndef CONFIG_NUMA hpage = khugepaged_alloc_hugepage(); - if (unlikely(!hpage)) { - count_vm_event(THP_COLLAPSE_ALLOC_FAILED); + if (unlikely(!hpage)) break; - } - count_vm_event(THP_COLLAPSE_ALLOC); #else if (IS_ERR(hpage)) { khugepaged_alloc_sleep(); diff --git a/trunk/mm/memory.c b/trunk/mm/memory.c index ce22a250926f..9da8cab1b1b0 100644 --- a/trunk/mm/memory.c +++ b/trunk/mm/memory.c @@ -1410,13 +1410,6 @@ struct page *follow_page(struct vm_area_struct *vma, unsigned long address, return page; } -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr) -{ - return (vma->vm_flags & VM_GROWSDOWN) && - (vma->vm_start == addr) && - !vma_stack_continue(vma->vm_prev, addr); -} - /** * __get_user_pages() - pin user pages in memory * @tsk: task_struct of target task @@ -1495,6 +1488,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, vma = find_extend_vma(mm, start); if (!vma && in_gate_area(mm, start)) { unsigned long pg = start & PAGE_MASK; + struct vm_area_struct *gate_vma = get_gate_vma(mm); pgd_t *pgd; pud_t *pud; pmd_t *pmd; @@ -1519,11 +1513,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, pte_unmap(pte); return i ? : -EFAULT; } - vma = get_gate_vma(mm); if (pages) { struct page *page; - page = vm_normal_page(vma, start, *pte); + page = vm_normal_page(gate_vma, start, *pte); if (!page) { if (!(gup_flags & FOLL_DUMP) && is_zero_pfn(pte_pfn(*pte))) @@ -1537,7 +1530,12 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, get_page(page); } pte_unmap(pte); - goto next_page; + if (vmas) + vmas[i] = gate_vma; + i++; + start += PAGE_SIZE; + nr_pages--; + continue; } if (!vma || @@ -1551,13 +1549,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, continue; } - /* - * If we don't actually want the page itself, - * and it's the stack guard page, just skip it. - */ - if (!pages && stack_guard_page(vma, start)) - goto next_page; - do { struct page *page; unsigned int foll_flags = gup_flags; @@ -1640,7 +1631,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm, flush_anon_page(vma, page, start); flush_dcache_page(page); } -next_page: if (vmas) vmas[i] = vma; i++; @@ -3688,7 +3678,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm, */ #ifdef CONFIG_HAVE_IOREMAP_PROT vma = find_vma(mm, addr); - if (!vma || vma->vm_start > addr) + if (!vma) break; if (vma->vm_ops && vma->vm_ops->access) ret = vma->vm_ops->access(vma, addr, buf, diff --git a/trunk/mm/memory_hotplug.c b/trunk/mm/memory_hotplug.c index 9ca1d604f7cd..a2acaf820fe5 100644 --- a/trunk/mm/memory_hotplug.c +++ b/trunk/mm/memory_hotplug.c @@ -375,7 +375,7 @@ void online_page(struct page *page) #endif #ifdef CONFIG_FLATMEM - max_mapnr = max(pfn, max_mapnr); + max_mapnr = max(page_to_pfn(page), max_mapnr); #endif ClearPageReserved(page); diff --git a/trunk/mm/mlock.c b/trunk/mm/mlock.c index 6b55e3efe0df..2689a08c79af 100644 --- a/trunk/mm/mlock.c +++ b/trunk/mm/mlock.c @@ -135,6 +135,13 @@ void munlock_vma_page(struct page *page) } } +static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr) +{ + return (vma->vm_flags & VM_GROWSDOWN) && + (vma->vm_start == addr) && + !vma_stack_continue(vma->vm_prev, addr); +} + /** * __mlock_vma_pages_range() - mlock a range of pages in the vma. * @vma: target vma @@ -181,6 +188,12 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma, if (vma->vm_flags & VM_LOCKED) gup_flags |= FOLL_MLOCK; + /* We don't try to access the guard page of a stack vma */ + if (stack_guard_page(vma, start)) { + addr += PAGE_SIZE; + nr_pages--; + } + return __get_user_pages(current, mm, addr, nr_pages, gup_flags, NULL, NULL, nonblocking); } diff --git a/trunk/mm/mmap.c b/trunk/mm/mmap.c index e27e0cf0de03..2ec8eb5a9cdd 100644 --- a/trunk/mm/mmap.c +++ b/trunk/mm/mmap.c @@ -259,7 +259,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk) * randomize_va_space to 2, which will still cause mm->start_brk * to be arbitrarily shifted */ - if (current->brk_randomized) + if (mm->start_brk > PAGE_ALIGN(mm->end_data)) min_brk = mm->start_brk; else min_brk = mm->end_data; @@ -1814,14 +1814,11 @@ static int expand_downwards(struct vm_area_struct *vma, size = vma->vm_end - address; grow = (vma->vm_start - address) >> PAGE_SHIFT; - error = -ENOMEM; - if (grow <= vma->vm_pgoff) { - error = acct_stack_growth(vma, size, grow); - if (!error) { - vma->vm_start = address; - vma->vm_pgoff -= grow; - perf_event_mmap(vma); - } + error = acct_stack_growth(vma, size, grow); + if (!error) { + vma->vm_start = address; + vma->vm_pgoff -= grow; + perf_event_mmap(vma); } } vma_unlock_anon_vma(vma); diff --git a/trunk/mm/oom_kill.c b/trunk/mm/oom_kill.c index 83fb72c108b7..6a819d1b2c7d 100644 --- a/trunk/mm/oom_kill.c +++ b/trunk/mm/oom_kill.c @@ -83,6 +83,24 @@ static bool has_intersects_mems_allowed(struct task_struct *tsk, } #endif /* CONFIG_NUMA */ +/* + * If this is a system OOM (not a memcg OOM) and the task selected to be + * killed is not already running at high (RT) priorities, speed up the + * recovery by boosting the dying task to the lowest FIFO priority. + * That helps with the recovery and avoids interfering with RT tasks. + */ +static void boost_dying_task_prio(struct task_struct *p, + struct mem_cgroup *mem) +{ + struct sched_param param = { .sched_priority = 1 }; + + if (mem) + return; + + if (!rt_task(p)) + sched_setscheduler_nocheck(p, SCHED_FIFO, ¶m); +} + /* * The process p may have detached its own ->mm while exiting or through * use_mm(), but one or more of its subthreads may still have a valid @@ -434,6 +452,13 @@ static int oom_kill_task(struct task_struct *p, struct mem_cgroup *mem) set_tsk_thread_flag(p, TIF_MEMDIE); force_sig(SIGKILL, p); + /* + * We give our sacrificial lamb high priority and access to + * all the memory it needs. That way it should be able to + * exit() and clear out its resources quickly... + */ + boost_dying_task_prio(p, mem); + return 0; } #undef K @@ -457,6 +482,7 @@ static int oom_kill_process(struct task_struct *p, gfp_t gfp_mask, int order, */ if (p->flags & PF_EXITING) { set_tsk_thread_flag(p, TIF_MEMDIE); + boost_dying_task_prio(p, mem); return 0; } @@ -530,6 +556,7 @@ void mem_cgroup_out_of_memory(struct mem_cgroup *mem, gfp_t gfp_mask) */ if (fatal_signal_pending(current)) { set_thread_flag(TIF_MEMDIE); + boost_dying_task_prio(current, NULL); return; } @@ -685,6 +712,7 @@ void out_of_memory(struct zonelist *zonelist, gfp_t gfp_mask, */ if (fatal_signal_pending(current)) { set_thread_flag(TIF_MEMDIE); + boost_dying_task_prio(current, NULL); return; } diff --git a/trunk/mm/page_alloc.c b/trunk/mm/page_alloc.c index 9f8a97b9a350..2747f5e5abc1 100644 --- a/trunk/mm/page_alloc.c +++ b/trunk/mm/page_alloc.c @@ -3176,7 +3176,7 @@ static __init_refok int __build_all_zonelists(void *data) * Called with zonelists_mutex held always * unless system_state == SYSTEM_BOOTING. */ -void __ref build_all_zonelists(void *data) +void build_all_zonelists(void *data) { set_zonelist_order(); diff --git a/trunk/mm/shmem.c b/trunk/mm/shmem.c index 8fa27e4e582a..58da7c150ba6 100644 --- a/trunk/mm/shmem.c +++ b/trunk/mm/shmem.c @@ -421,8 +421,7 @@ static swp_entry_t *shmem_swp_alloc(struct shmem_inode_info *info, unsigned long * a waste to allocate index if we cannot allocate data. */ if (sbinfo->max_blocks) { - if (percpu_counter_compare(&sbinfo->used_blocks, - sbinfo->max_blocks - 1) >= 0) + if (percpu_counter_compare(&sbinfo->used_blocks, (sbinfo->max_blocks - 1)) > 0) return ERR_PTR(-ENOSPC); percpu_counter_inc(&sbinfo->used_blocks); spin_lock(&inode->i_lock); @@ -1398,8 +1397,7 @@ static int shmem_getpage(struct inode *inode, unsigned long idx, shmem_swp_unmap(entry); sbinfo = SHMEM_SB(inode->i_sb); if (sbinfo->max_blocks) { - if (percpu_counter_compare(&sbinfo->used_blocks, - sbinfo->max_blocks) >= 0 || + if ((percpu_counter_compare(&sbinfo->used_blocks, sbinfo->max_blocks) > 0) || shmem_acct_block(info->flags)) { spin_unlock(&info->lock); error = -ENOSPC; diff --git a/trunk/mm/vmscan.c b/trunk/mm/vmscan.c index f6b435c80079..c7f5a6d4b75b 100644 --- a/trunk/mm/vmscan.c +++ b/trunk/mm/vmscan.c @@ -41,7 +41,6 @@ #include #include #include -#include #include #include @@ -1989,12 +1988,17 @@ static bool zone_reclaimable(struct zone *zone) return zone->pages_scanned < zone_reclaimable_pages(zone) * 6; } -/* All zones in zonelist are unreclaimable? */ +/* + * As hibernation is going on, kswapd is freezed so that it can't mark + * the zone into all_unreclaimable. It can't handle OOM during hibernation. + * So let's check zone's unreclaimable in direct reclaim as well as kswapd. + */ static bool all_unreclaimable(struct zonelist *zonelist, struct scan_control *sc) { struct zoneref *z; struct zone *zone; + bool all_unreclaimable = true; for_each_zone_zonelist_nodemask(zone, z, zonelist, gfp_zone(sc->gfp_mask), sc->nodemask) { @@ -2002,11 +2006,13 @@ static bool all_unreclaimable(struct zonelist *zonelist, continue; if (!cpuset_zone_allowed_hardwall(zone, GFP_KERNEL)) continue; - if (!zone->all_unreclaimable) - return false; + if (zone_reclaimable(zone)) { + all_unreclaimable = false; + break; + } } - return true; + return all_unreclaimable; } /* @@ -2102,14 +2108,6 @@ static unsigned long do_try_to_free_pages(struct zonelist *zonelist, if (sc->nr_reclaimed) return sc->nr_reclaimed; - /* - * As hibernation is going on, kswapd is freezed so that it can't mark - * the zone into all_unreclaimable. Thus bypassing all_unreclaimable - * check. - */ - if (oom_killer_disabled) - return 0; - /* top priority shrink_zones still had more to do? don't OOM, then */ if (scanning_global_lru(sc) && !all_unreclaimable(zonelist, sc)) return 1; diff --git a/trunk/mm/vmstat.c b/trunk/mm/vmstat.c index 897ea9e88238..772b39b87d95 100644 --- a/trunk/mm/vmstat.c +++ b/trunk/mm/vmstat.c @@ -321,12 +321,9 @@ static inline void mod_state(struct zone *zone, /* * The fetching of the stat_threshold is racy. We may apply * a counter threshold to the wrong the cpu if we get - * rescheduled while executing here. However, the next - * counter update will apply the threshold again and - * therefore bring the counter under the threshold again. - * - * Most of the time the thresholds are the same anyways - * for all cpus in a zone. + * rescheduled while executing here. However, the following + * will apply the threshold again and therefore bring the + * counter under the threshold. */ t = this_cpu_read(pcp->stat_threshold); @@ -948,16 +945,7 @@ static const char * const vmstat_text[] = { "unevictable_pgs_cleared", "unevictable_pgs_stranded", "unevictable_pgs_mlockfreed", - -#ifdef CONFIG_TRANSPARENT_HUGEPAGE - "thp_fault_alloc", - "thp_fault_fallback", - "thp_collapse_alloc", - "thp_collapse_alloc_failed", - "thp_split", #endif - -#endif /* CONFIG_VM_EVENTS_COUNTERS */ }; static void zoneinfo_show_print(struct seq_file *m, pg_data_t *pgdat, diff --git a/trunk/net/9p/client.c b/trunk/net/9p/client.c index 77367745be9b..48b8e084e710 100644 --- a/trunk/net/9p/client.c +++ b/trunk/net/9p/client.c @@ -929,15 +929,15 @@ struct p9_fid *p9_client_attach(struct p9_client *clnt, struct p9_fid *afid, } EXPORT_SYMBOL(p9_client_attach); -struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname, - char **wnames, int clone) +struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames, + int clone) { int err; struct p9_client *clnt; struct p9_fid *fid; struct p9_qid *wqids; struct p9_req_t *req; - uint16_t nwqids, count; + int16_t nwqids, count; err = 0; wqids = NULL; @@ -955,7 +955,7 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, uint16_t nwname, fid = oldfid; - P9_DPRINTK(P9_DEBUG_9P, ">>> TWALK fids %d,%d nwname %ud wname[0] %s\n", + P9_DPRINTK(P9_DEBUG_9P, ">>> TWALK fids %d,%d nwname %d wname[0] %s\n", oldfid->fid, fid->fid, nwname, wnames ? wnames[0] : NULL); req = p9_client_rpc(clnt, P9_TWALK, "ddT", oldfid->fid, fid->fid, @@ -1220,6 +1220,27 @@ int p9_client_fsync(struct p9_fid *fid, int datasync) } EXPORT_SYMBOL(p9_client_fsync); +int p9_client_sync_fs(struct p9_fid *fid) +{ + int err = 0; + struct p9_req_t *req; + struct p9_client *clnt; + + P9_DPRINTK(P9_DEBUG_9P, ">>> TSYNC_FS fid %d\n", fid->fid); + + clnt = fid->clnt; + req = p9_client_rpc(clnt, P9_TSYNCFS, "d", fid->fid); + if (IS_ERR(req)) { + err = PTR_ERR(req); + goto error; + } + P9_DPRINTK(P9_DEBUG_9P, "<<< RSYNCFS fid %d\n", fid->fid); + p9_free_req(clnt, req); +error: + return err; +} +EXPORT_SYMBOL(p9_client_sync_fs); + int p9_client_clunk(struct p9_fid *fid) { int err; diff --git a/trunk/net/9p/protocol.c b/trunk/net/9p/protocol.c index b58a501cf3d1..8a4084fa8b5a 100644 --- a/trunk/net/9p/protocol.c +++ b/trunk/net/9p/protocol.c @@ -265,7 +265,7 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt, } break; case 'T':{ - uint16_t *nwname = va_arg(ap, uint16_t *); + int16_t *nwname = va_arg(ap, int16_t *); char ***wnames = va_arg(ap, char ***); errcode = p9pdu_readf(pdu, proto_version, @@ -468,8 +468,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt, case 'E':{ int32_t cnt = va_arg(ap, int32_t); const char *k = va_arg(ap, const void *); - const char __user *u = va_arg(ap, - const void __user *); + const char *u = va_arg(ap, const void *); errcode = p9pdu_writef(pdu, proto_version, "d", cnt); if (!errcode && pdu_write_urw(pdu, k, u, cnt)) @@ -496,7 +495,7 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt, } break; case 'T':{ - uint16_t nwname = va_arg(ap, int); + int16_t nwname = va_arg(ap, int); const char **wnames = va_arg(ap, const char **); errcode = p9pdu_writef(pdu, proto_version, "w", diff --git a/trunk/net/9p/trans_common.c b/trunk/net/9p/trans_common.c index e883172f9aa2..d47880e971dd 100644 --- a/trunk/net/9p/trans_common.c +++ b/trunk/net/9p/trans_common.c @@ -66,7 +66,7 @@ p9_payload_gup(struct p9_req_t *req, size_t *pdata_off, int *pdata_len, uint32_t pdata_mapped_pages; struct trans_rpage_info *rpinfo; - *pdata_off = (__force size_t)req->tc->pubuf & (PAGE_SIZE-1); + *pdata_off = (size_t)req->tc->pubuf & (PAGE_SIZE-1); if (*pdata_off) first_page_bytes = min(((size_t)PAGE_SIZE - *pdata_off), diff --git a/trunk/net/9p/trans_virtio.c b/trunk/net/9p/trans_virtio.c index 244e70742183..e8f046b07182 100644 --- a/trunk/net/9p/trans_virtio.c +++ b/trunk/net/9p/trans_virtio.c @@ -326,11 +326,8 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req) outp = pack_sg_list_p(chan->sg, out, VIRTQUEUE_NUM, pdata_off, rpinfo->rp_data, pdata_len); } else { - char *pbuf; - if (req->tc->pubuf) - pbuf = (__force char *) req->tc->pubuf; - else - pbuf = req->tc->pkbuf; + char *pbuf = req->tc->pubuf ? req->tc->pubuf : + req->tc->pkbuf; outp = pack_sg_list(chan->sg, out, VIRTQUEUE_NUM, pbuf, req->tc->pbuf_size); } @@ -355,12 +352,8 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req) in = pack_sg_list_p(chan->sg, out+inp, VIRTQUEUE_NUM, pdata_off, rpinfo->rp_data, pdata_len); } else { - char *pbuf; - if (req->tc->pubuf) - pbuf = (__force char *) req->tc->pubuf; - else - pbuf = req->tc->pkbuf; - + char *pbuf = req->tc->pubuf ? req->tc->pubuf : + req->tc->pkbuf; in = pack_sg_list(chan->sg, out+inp, VIRTQUEUE_NUM, pbuf, req->tc->pbuf_size); } diff --git a/trunk/net/ceph/osd_client.c b/trunk/net/ceph/osd_client.c index 5a80f41c0cba..50af02737a3d 100644 --- a/trunk/net/ceph/osd_client.c +++ b/trunk/net/ceph/osd_client.c @@ -579,15 +579,9 @@ static void __kick_osd_requests(struct ceph_osd_client *osdc, list_for_each_entry_safe(req, nreq, &osd->o_linger_requests, r_linger_osd) { - /* - * reregister request prior to unregistering linger so - * that r_osd is preserved. - */ - BUG_ON(!list_empty(&req->r_req_lru_item)); - __register_request(osdc, req); - list_add(&req->r_req_lru_item, &osdc->req_unsent); - list_add(&req->r_osd_item, &req->r_osd->o_requests); __unregister_linger_request(osdc, req); + __register_request(osdc, req); + list_move(&req->r_req_lru_item, &osdc->req_unsent); dout("requeued lingering %p tid %llu osd%d\n", req, req->r_tid, osd->o_osd); } @@ -804,7 +798,7 @@ static void __register_request(struct ceph_osd_client *osdc, req->r_request->hdr.tid = cpu_to_le64(req->r_tid); INIT_LIST_HEAD(&req->r_req_lru_item); - dout("__register_request %p tid %lld\n", req, req->r_tid); + dout("register_request %p tid %lld\n", req, req->r_tid); __insert_request(osdc, req); ceph_osdc_get_request(req); osdc->num_requests++; diff --git a/trunk/net/dsa/mv88e6131.c b/trunk/net/dsa/mv88e6131.c index 3da418894efc..d951f93644bf 100644 --- a/trunk/net/dsa/mv88e6131.c +++ b/trunk/net/dsa/mv88e6131.c @@ -14,13 +14,6 @@ #include "dsa_priv.h" #include "mv88e6xxx.h" -/* - * Switch product IDs - */ -#define ID_6085 0x04a0 -#define ID_6095 0x0950 -#define ID_6131 0x1060 - static char *mv88e6131_probe(struct mii_bus *bus, int sw_addr) { int ret; @@ -28,11 +21,9 @@ static char *mv88e6131_probe(struct mii_bus *bus, int sw_addr) ret = __mv88e6xxx_reg_read(bus, sw_addr, REG_PORT(0), 0x03); if (ret >= 0) { ret &= 0xfff0; - if (ret == ID_6085) - return "Marvell 88E6085"; - if (ret == ID_6095) + if (ret == 0x0950) return "Marvell 88E6095/88E6095F"; - if (ret == ID_6131) + if (ret == 0x1060) return "Marvell 88E6131"; } @@ -173,7 +164,6 @@ static int mv88e6131_setup_global(struct dsa_switch *ds) static int mv88e6131_setup_port(struct dsa_switch *ds, int p) { - struct mv88e6xxx_priv_state *ps = (void *)(ds + 1); int addr = REG_PORT(p); u16 val; @@ -181,13 +171,10 @@ static int mv88e6131_setup_port(struct dsa_switch *ds, int p) * MAC Forcing register: don't force link, speed, duplex * or flow control state to any particular values on physical * ports, but force the CPU port and all DSA ports to 1000 Mb/s - * (100 Mb/s on 6085) full duplex. + * full duplex. */ if (dsa_is_cpu_port(ds, p) || ds->dsa_port_mask & (1 << p)) - if (ps->id == ID_6085) - REG_WRITE(addr, 0x01, 0x003d); /* 100 Mb/s */ - else - REG_WRITE(addr, 0x01, 0x003e); /* 1000 Mb/s */ + REG_WRITE(addr, 0x01, 0x003e); else REG_WRITE(addr, 0x01, 0x0003); @@ -299,8 +286,6 @@ static int mv88e6131_setup(struct dsa_switch *ds) mv88e6xxx_ppu_state_init(ds); mutex_init(&ps->stats_mutex); - ps->id = REG_READ(REG_PORT(0), 0x03) & 0xfff0; - ret = mv88e6131_switch_reset(ds); if (ret < 0) return ret; diff --git a/trunk/net/dsa/mv88e6xxx.h b/trunk/net/dsa/mv88e6xxx.h index 61156ca26a0d..eb0e0aaa9f1b 100644 --- a/trunk/net/dsa/mv88e6xxx.h +++ b/trunk/net/dsa/mv88e6xxx.h @@ -39,8 +39,6 @@ struct mv88e6xxx_priv_state { * Hold this mutex over snapshot + dump sequences. */ struct mutex stats_mutex; - - int id; /* switch product id */ }; struct mv88e6xxx_hw_stat { diff --git a/trunk/net/ipv4/netfilter.c b/trunk/net/ipv4/netfilter.c index 4614babdc45f..f3c0b549b8e1 100644 --- a/trunk/net/ipv4/netfilter.c +++ b/trunk/net/ipv4/netfilter.c @@ -221,10 +221,9 @@ static __sum16 nf_ip_checksum_partial(struct sk_buff *skb, unsigned int hook, return csum; } -static int nf_ip_route(struct net *net, struct dst_entry **dst, - struct flowi *fl, bool strict __always_unused) +static int nf_ip_route(struct dst_entry **dst, struct flowi *fl) { - struct rtable *rt = ip_route_output_key(net, &fl->u.ip4); + struct rtable *rt = ip_route_output_key(&init_net, &fl->u.ip4); if (IS_ERR(rt)) return PTR_ERR(rt); *dst = &rt->dst; diff --git a/trunk/net/ipv4/route.c b/trunk/net/ipv4/route.c index c1acf69858fd..ea107515c53e 100644 --- a/trunk/net/ipv4/route.c +++ b/trunk/net/ipv4/route.c @@ -1891,7 +1891,6 @@ static int ip_route_input_mc(struct sk_buff *skb, __be32 daddr, __be32 saddr, #ifdef CONFIG_IP_ROUTE_CLASSID rth->dst.tclassid = itag; #endif - rth->rt_route_iif = dev->ifindex; rth->rt_iif = dev->ifindex; rth->dst.dev = init_net.loopback_dev; dev_hold(rth->dst.dev); @@ -2027,7 +2026,6 @@ static int __mkroute_input(struct sk_buff *skb, rth->rt_key_src = saddr; rth->rt_src = saddr; rth->rt_gateway = daddr; - rth->rt_route_iif = in_dev->dev->ifindex; rth->rt_iif = in_dev->dev->ifindex; rth->dst.dev = (out_dev)->dev; dev_hold(rth->dst.dev); @@ -2204,7 +2202,6 @@ out: return err; #ifdef CONFIG_IP_ROUTE_CLASSID rth->dst.tclassid = itag; #endif - rth->rt_route_iif = dev->ifindex; rth->rt_iif = dev->ifindex; rth->dst.dev = net->loopback_dev; dev_hold(rth->dst.dev); @@ -2404,8 +2401,7 @@ static struct rtable *__mkroute_output(const struct fib_result *res, rth->rt_mark = oldflp4->flowi4_mark; rth->rt_dst = fl4->daddr; rth->rt_src = fl4->saddr; - rth->rt_route_iif = 0; - rth->rt_iif = oldflp4->flowi4_oif ? : dev_out->ifindex; + rth->rt_iif = 0; /* get references to the devices that are to be hold by the routing cache entry */ rth->dst.dev = dev_out; @@ -2720,7 +2716,6 @@ struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_or rt->rt_key_dst = ort->rt_key_dst; rt->rt_key_src = ort->rt_key_src; rt->rt_tos = ort->rt_tos; - rt->rt_route_iif = ort->rt_route_iif; rt->rt_iif = ort->rt_iif; rt->rt_oif = ort->rt_oif; rt->rt_mark = ort->rt_mark; @@ -2730,6 +2725,7 @@ struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_or rt->rt_type = ort->rt_type; rt->rt_dst = ort->rt_dst; rt->rt_src = ort->rt_src; + rt->rt_iif = ort->rt_iif; rt->rt_gateway = ort->rt_gateway; rt->rt_spec_dst = ort->rt_spec_dst; rt->peer = ort->peer; diff --git a/trunk/net/ipv4/xfrm4_policy.c b/trunk/net/ipv4/xfrm4_policy.c index d20a05e970d8..13e0e7f659ff 100644 --- a/trunk/net/ipv4/xfrm4_policy.c +++ b/trunk/net/ipv4/xfrm4_policy.c @@ -74,7 +74,6 @@ static int xfrm4_fill_dst(struct xfrm_dst *xdst, struct net_device *dev, rt->rt_key_dst = fl4->daddr; rt->rt_key_src = fl4->saddr; rt->rt_tos = fl4->flowi4_tos; - rt->rt_route_iif = fl4->flowi4_iif; rt->rt_iif = fl4->flowi4_iif; rt->rt_oif = fl4->flowi4_oif; rt->rt_mark = fl4->flowi4_mark; diff --git a/trunk/net/ipv6/netfilter.c b/trunk/net/ipv6/netfilter.c index 28bc1f644b7b..39aaca2b4fd2 100644 --- a/trunk/net/ipv6/netfilter.c +++ b/trunk/net/ipv6/netfilter.c @@ -90,18 +90,9 @@ static int nf_ip6_reroute(struct sk_buff *skb, return 0; } -static int nf_ip6_route(struct net *net, struct dst_entry **dst, - struct flowi *fl, bool strict) +static int nf_ip6_route(struct dst_entry **dst, struct flowi *fl) { - static const struct ipv6_pinfo fake_pinfo; - static const struct inet_sock fake_sk = { - /* makes ip6_route_output set RT6_LOOKUP_F_IFACE: */ - .sk.sk_bound_dev_if = 1, - .pinet6 = (struct ipv6_pinfo *) &fake_pinfo, - }; - const void *sk = strict ? &fake_sk : NULL; - - *dst = ip6_route_output(net, sk, &fl->u.ip6); + *dst = ip6_route_output(&init_net, NULL, &fl->u.ip6); return (*dst)->error; } diff --git a/trunk/net/ipv6/tcp_ipv6.c b/trunk/net/ipv6/tcp_ipv6.c index 4f49e5dd41bb..56fa12538d45 100644 --- a/trunk/net/ipv6/tcp_ipv6.c +++ b/trunk/net/ipv6/tcp_ipv6.c @@ -1622,7 +1622,6 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) opt_skb = skb_clone(skb, GFP_ATOMIC); if (sk->sk_state == TCP_ESTABLISHED) { /* Fast path */ - sock_rps_save_rxhash(sk, skb->rxhash); if (tcp_rcv_established(sk, skb, tcp_hdr(skb), skb->len)) goto reset; if (opt_skb) @@ -1650,8 +1649,7 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb) __kfree_skb(opt_skb); return 0; } - } else - sock_rps_save_rxhash(sk, skb->rxhash); + } if (tcp_rcv_state_process(sk, skb, tcp_hdr(skb), skb->len)) goto reset; diff --git a/trunk/net/ipv6/udp.c b/trunk/net/ipv6/udp.c index 15c37746845e..d7037c006e13 100644 --- a/trunk/net/ipv6/udp.c +++ b/trunk/net/ipv6/udp.c @@ -505,9 +505,6 @@ int udpv6_queue_rcv_skb(struct sock * sk, struct sk_buff *skb) int rc; int is_udplite = IS_UDPLITE(sk); - if (!ipv6_addr_any(&inet6_sk(sk)->daddr)) - sock_rps_save_rxhash(sk, skb->rxhash); - if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) goto drop; diff --git a/trunk/net/mac80211/rx.c b/trunk/net/mac80211/rx.c index c5d4530d8284..9d192d665ff5 100644 --- a/trunk/net/mac80211/rx.c +++ b/trunk/net/mac80211/rx.c @@ -2541,6 +2541,7 @@ static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx) * same TID from the same station */ rx->skb = skb; + rx->flags = 0; CALL_RXH(ieee80211_rx_h_decrypt) CALL_RXH(ieee80211_rx_h_check_more_data) @@ -2611,7 +2612,6 @@ void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid) .sdata = sta->sdata, .local = sta->local, .queue = tid, - .flags = 0, }; struct tid_ampdu_rx *tid_agg_rx; diff --git a/trunk/net/netfilter/Kconfig b/trunk/net/netfilter/Kconfig index 32bff6d86cb2..c3f988aa1152 100644 --- a/trunk/net/netfilter/Kconfig +++ b/trunk/net/netfilter/Kconfig @@ -652,6 +652,7 @@ comment "Xtables matches" config NETFILTER_XT_MATCH_ADDRTYPE tristate '"addrtype" address type match support' depends on NETFILTER_ADVANCED + depends on (IPV6 || IPV6=n) ---help--- This option allows you to match what routing thinks of an address, eg. UNICAST, LOCAL, BROADCAST, ... diff --git a/trunk/net/netfilter/ipset/ip_set_bitmap_ip.c b/trunk/net/netfilter/ipset/ip_set_bitmap_ip.c index a113ff066928..bca96990218d 100644 --- a/trunk/net/netfilter/ipset/ip_set_bitmap_ip.c +++ b/trunk/net/netfilter/ipset/ip_set_bitmap_ip.c @@ -338,7 +338,8 @@ bitmap_ip_head(struct ip_set *set, struct sk_buff *skb) NLA_PUT_IPADDR4(skb, IPSET_ATTR_IP_TO, htonl(map->last_ip)); if (map->netmask != 32) NLA_PUT_U8(skb, IPSET_ATTR_NETMASK, map->netmask); - NLA_PUT_NET32(skb, IPSET_ATTR_REFERENCES, htonl(set->ref - 1)); + NLA_PUT_NET32(skb, IPSET_ATTR_REFERENCES, + htonl(atomic_read(&set->ref) - 1)); NLA_PUT_NET32(skb, IPSET_ATTR_MEMSIZE, htonl(sizeof(*map) + map->memsize)); if (with_timeout(map->timeout)) diff --git a/trunk/net/netfilter/ipset/ip_set_bitmap_ipmac.c b/trunk/net/netfilter/ipset/ip_set_bitmap_ipmac.c index 00a33242e90c..5e790172deff 100644 --- a/trunk/net/netfilter/ipset/ip_set_bitmap_ipmac.c +++ b/trunk/net/netfilter/ipset/ip_set_bitmap_ipmac.c @@ -434,7 +434,8 @@ bitmap_ipmac_head(struct ip_set *set, struct sk_buff *skb) goto nla_put_failure; NLA_PUT_IPADDR4(skb, IPSET_ATTR_IP, htonl(map->first_ip)); NLA_PUT_IPADDR4(skb, IPSET_ATTR_IP_TO, htonl(map->last_ip)); - NLA_PUT_NET32(skb, IPSET_ATTR_REFERENCES, htonl(set->ref - 1)); + NLA_PUT_NET32(skb, IPSET_ATTR_REFERENCES, + htonl(atomic_read(&set->ref) - 1)); NLA_PUT_NET32(skb, IPSET_ATTR_MEMSIZE, htonl(sizeof(*map) + (map->last_ip - map->first_ip + 1) * map->dsize)); diff --git a/trunk/net/netfilter/ipset/ip_set_bitmap_port.c b/trunk/net/netfilter/ipset/ip_set_bitmap_port.c index 6b38eb8f6ed8..165f09b1a9cb 100644 --- a/trunk/net/netfilter/ipset/ip_set_bitmap_port.c +++ b/trunk/net/netfilter/ipset/ip_set_bitmap_port.c @@ -320,7 +320,8 @@ bitmap_port_head(struct ip_set *set, struct sk_buff *skb) goto nla_put_failure; NLA_PUT_NET16(skb, IPSET_ATTR_PORT, htons(map->first_port)); NLA_PUT_NET16(skb, IPSET_ATTR_PORT_TO, htons(map->last_port)); - NLA_PUT_NET32(skb, IPSET_ATTR_REFERENCES, htonl(set->ref - 1)); + NLA_PUT_NET32(skb, IPSET_ATTR_REFERENCES, + htonl(atomic_read(&set->ref) - 1)); NLA_PUT_NET32(skb, IPSET_ATTR_MEMSIZE, htonl(sizeof(*map) + map->memsize)); if (with_timeout(map->timeout)) diff --git a/trunk/net/netfilter/ipset/ip_set_core.c b/trunk/net/netfilter/ipset/ip_set_core.c index 9152e69a162d..253326e8d990 100644 --- a/trunk/net/netfilter/ipset/ip_set_core.c +++ b/trunk/net/netfilter/ipset/ip_set_core.c @@ -26,7 +26,6 @@ static LIST_HEAD(ip_set_type_list); /* all registered set types */ static DEFINE_MUTEX(ip_set_type_mutex); /* protects ip_set_type_list */ -static DEFINE_RWLOCK(ip_set_ref_lock); /* protects the set refs */ static struct ip_set **ip_set_list; /* all individual sets */ static ip_set_id_t ip_set_max = CONFIG_IP_SET_MAX; /* max number of sets */ @@ -302,18 +301,13 @@ EXPORT_SYMBOL_GPL(ip_set_get_ipaddr6); static inline void __ip_set_get(ip_set_id_t index) { - write_lock_bh(&ip_set_ref_lock); - ip_set_list[index]->ref++; - write_unlock_bh(&ip_set_ref_lock); + atomic_inc(&ip_set_list[index]->ref); } static inline void __ip_set_put(ip_set_id_t index) { - write_lock_bh(&ip_set_ref_lock); - BUG_ON(ip_set_list[index]->ref == 0); - ip_set_list[index]->ref--; - write_unlock_bh(&ip_set_ref_lock); + atomic_dec(&ip_set_list[index]->ref); } /* @@ -330,7 +324,7 @@ ip_set_test(ip_set_id_t index, const struct sk_buff *skb, struct ip_set *set = ip_set_list[index]; int ret = 0; - BUG_ON(set == NULL); + BUG_ON(set == NULL || atomic_read(&set->ref) == 0); pr_debug("set %s, index %u\n", set->name, index); if (dim < set->type->dimension || @@ -362,7 +356,7 @@ ip_set_add(ip_set_id_t index, const struct sk_buff *skb, struct ip_set *set = ip_set_list[index]; int ret; - BUG_ON(set == NULL); + BUG_ON(set == NULL || atomic_read(&set->ref) == 0); pr_debug("set %s, index %u\n", set->name, index); if (dim < set->type->dimension || @@ -384,7 +378,7 @@ ip_set_del(ip_set_id_t index, const struct sk_buff *skb, struct ip_set *set = ip_set_list[index]; int ret = 0; - BUG_ON(set == NULL); + BUG_ON(set == NULL || atomic_read(&set->ref) == 0); pr_debug("set %s, index %u\n", set->name, index); if (dim < set->type->dimension || @@ -403,6 +397,7 @@ EXPORT_SYMBOL_GPL(ip_set_del); * Find set by name, reference it once. The reference makes sure the * thing pointed to, does not go away under our feet. * + * The nfnl mutex must already be activated. */ ip_set_id_t ip_set_get_byname(const char *name, struct ip_set **set) @@ -428,12 +423,15 @@ EXPORT_SYMBOL_GPL(ip_set_get_byname); * reference count by 1. The caller shall not assume the index * to be valid, after calling this function. * + * The nfnl mutex must already be activated. */ void ip_set_put_byindex(ip_set_id_t index) { - if (ip_set_list[index] != NULL) + if (ip_set_list[index] != NULL) { + BUG_ON(atomic_read(&ip_set_list[index]->ref) == 0); __ip_set_put(index); + } } EXPORT_SYMBOL_GPL(ip_set_put_byindex); @@ -443,6 +441,7 @@ EXPORT_SYMBOL_GPL(ip_set_put_byindex); * can't be destroyed. The set cannot be renamed due to * the referencing either. * + * The nfnl mutex must already be activated. */ const char * ip_set_name_byindex(ip_set_id_t index) @@ -450,7 +449,7 @@ ip_set_name_byindex(ip_set_id_t index) const struct ip_set *set = ip_set_list[index]; BUG_ON(set == NULL); - BUG_ON(set->ref == 0); + BUG_ON(atomic_read(&set->ref) == 0); /* Referenced, so it's safe */ return set->name; @@ -516,7 +515,10 @@ void ip_set_nfnl_put(ip_set_id_t index) { nfnl_lock(); - ip_set_put_byindex(index); + if (ip_set_list[index] != NULL) { + BUG_ON(atomic_read(&ip_set_list[index]->ref) == 0); + __ip_set_put(index); + } nfnl_unlock(); } EXPORT_SYMBOL_GPL(ip_set_nfnl_put); @@ -524,7 +526,7 @@ EXPORT_SYMBOL_GPL(ip_set_nfnl_put); /* * Communication protocol with userspace over netlink. * - * The commands are serialized by the nfnl mutex. + * We already locked by nfnl_lock. */ static inline bool @@ -655,6 +657,7 @@ ip_set_create(struct sock *ctnl, struct sk_buff *skb, return -ENOMEM; rwlock_init(&set->lock); strlcpy(set->name, name, IPSET_MAXNAMELEN); + atomic_set(&set->ref, 0); set->family = family; /* @@ -687,8 +690,8 @@ ip_set_create(struct sock *ctnl, struct sk_buff *skb, /* * Here, we have a valid, constructed set and we are protected - * by the nfnl mutex. Find the first free index in ip_set_list - * and check clashing. + * by nfnl_lock. Find the first free index in ip_set_list and + * check clashing. */ if ((ret = find_free_id(set->name, &index, &clash)) != 0) { /* If this is the same set and requested, ignore error */ @@ -748,51 +751,31 @@ ip_set_destroy(struct sock *ctnl, struct sk_buff *skb, const struct nlattr * const attr[]) { ip_set_id_t i; - int ret = 0; if (unlikely(protocol_failed(attr))) return -IPSET_ERR_PROTOCOL; - /* Commands are serialized and references are - * protected by the ip_set_ref_lock. - * External systems (i.e. xt_set) must call - * ip_set_put|get_nfnl_* functions, that way we - * can safely check references here. - * - * list:set timer can only decrement the reference - * counter, so if it's already zero, we can proceed - * without holding the lock. - */ - read_lock_bh(&ip_set_ref_lock); + /* References are protected by the nfnl mutex */ if (!attr[IPSET_ATTR_SETNAME]) { for (i = 0; i < ip_set_max; i++) { - if (ip_set_list[i] != NULL && ip_set_list[i]->ref) { - ret = IPSET_ERR_BUSY; - goto out; - } + if (ip_set_list[i] != NULL && + (atomic_read(&ip_set_list[i]->ref))) + return -IPSET_ERR_BUSY; } - read_unlock_bh(&ip_set_ref_lock); for (i = 0; i < ip_set_max; i++) { if (ip_set_list[i] != NULL) ip_set_destroy_set(i); } } else { i = find_set_id(nla_data(attr[IPSET_ATTR_SETNAME])); - if (i == IPSET_INVALID_ID) { - ret = -ENOENT; - goto out; - } else if (ip_set_list[i]->ref) { - ret = -IPSET_ERR_BUSY; - goto out; - } - read_unlock_bh(&ip_set_ref_lock); + if (i == IPSET_INVALID_ID) + return -ENOENT; + else if (atomic_read(&ip_set_list[i]->ref)) + return -IPSET_ERR_BUSY; ip_set_destroy_set(i); } return 0; -out: - read_unlock_bh(&ip_set_ref_lock); - return ret; } /* Flush sets */ @@ -851,7 +834,6 @@ ip_set_rename(struct sock *ctnl, struct sk_buff *skb, struct ip_set *set; const char *name2; ip_set_id_t i; - int ret = 0; if (unlikely(protocol_failed(attr) || attr[IPSET_ATTR_SETNAME] == NULL || @@ -861,33 +843,25 @@ ip_set_rename(struct sock *ctnl, struct sk_buff *skb, set = find_set(nla_data(attr[IPSET_ATTR_SETNAME])); if (set == NULL) return -ENOENT; - - read_lock_bh(&ip_set_ref_lock); - if (set->ref != 0) { - ret = -IPSET_ERR_REFERENCED; - goto out; - } + if (atomic_read(&set->ref) != 0) + return -IPSET_ERR_REFERENCED; name2 = nla_data(attr[IPSET_ATTR_SETNAME2]); for (i = 0; i < ip_set_max; i++) { if (ip_set_list[i] != NULL && - STREQ(ip_set_list[i]->name, name2)) { - ret = -IPSET_ERR_EXIST_SETNAME2; - goto out; - } + STREQ(ip_set_list[i]->name, name2)) + return -IPSET_ERR_EXIST_SETNAME2; } strncpy(set->name, name2, IPSET_MAXNAMELEN); -out: - read_unlock_bh(&ip_set_ref_lock); - return ret; + return 0; } /* Swap two sets so that name/index points to the other. * References and set names are also swapped. * - * The commands are serialized by the nfnl mutex and references are - * protected by the ip_set_ref_lock. The kernel interfaces + * We are protected by the nfnl mutex and references are + * manipulated only by holding the mutex. The kernel interfaces * do not hold the mutex but the pointer settings are atomic * so the ip_set_list always contains valid pointers to the sets. */ @@ -900,6 +874,7 @@ ip_set_swap(struct sock *ctnl, struct sk_buff *skb, struct ip_set *from, *to; ip_set_id_t from_id, to_id; char from_name[IPSET_MAXNAMELEN]; + u32 from_ref; if (unlikely(protocol_failed(attr) || attr[IPSET_ATTR_SETNAME] == NULL || @@ -924,15 +899,17 @@ ip_set_swap(struct sock *ctnl, struct sk_buff *skb, from->type->family == to->type->family)) return -IPSET_ERR_TYPE_MISMATCH; + /* No magic here: ref munging protected by the nfnl_lock */ strncpy(from_name, from->name, IPSET_MAXNAMELEN); + from_ref = atomic_read(&from->ref); + strncpy(from->name, to->name, IPSET_MAXNAMELEN); + atomic_set(&from->ref, atomic_read(&to->ref)); strncpy(to->name, from_name, IPSET_MAXNAMELEN); + atomic_set(&to->ref, from_ref); - write_lock_bh(&ip_set_ref_lock); - swap(from->ref, to->ref); ip_set_list[from_id] = to; ip_set_list[to_id] = from; - write_unlock_bh(&ip_set_ref_lock); return 0; } @@ -949,7 +926,7 @@ ip_set_dump_done(struct netlink_callback *cb) { if (cb->args[2]) { pr_debug("release set %s\n", ip_set_list[cb->args[1]]->name); - ip_set_put_byindex((ip_set_id_t) cb->args[1]); + __ip_set_put((ip_set_id_t) cb->args[1]); } return 0; } @@ -1091,7 +1068,7 @@ ip_set_dump_start(struct sk_buff *skb, struct netlink_callback *cb) /* If there was an error or set is done, release set */ if (ret || !cb->args[2]) { pr_debug("release set %s\n", ip_set_list[index]->name); - ip_set_put_byindex(index); + __ip_set_put(index); } /* If we dump all sets, continue with dumping last ones */ diff --git a/trunk/net/netfilter/ipset/ip_set_list_set.c b/trunk/net/netfilter/ipset/ip_set_list_set.c index e9159e99fc4b..a47c32982f06 100644 --- a/trunk/net/netfilter/ipset/ip_set_list_set.c +++ b/trunk/net/netfilter/ipset/ip_set_list_set.c @@ -43,19 +43,14 @@ struct list_set { static inline struct set_elem * list_set_elem(const struct list_set *map, u32 id) { - return (struct set_elem *)((void *)map->members + id * map->dsize); -} - -static inline struct set_telem * -list_set_telem(const struct list_set *map, u32 id) -{ - return (struct set_telem *)((void *)map->members + id * map->dsize); + return (struct set_elem *)((char *)map->members + id * map->dsize); } static inline bool list_set_timeout(const struct list_set *map, u32 id) { - const struct set_telem *elem = list_set_telem(map, id); + const struct set_telem *elem = + (const struct set_telem *) list_set_elem(map, id); return ip_set_timeout_test(elem->timeout); } @@ -63,11 +58,19 @@ list_set_timeout(const struct list_set *map, u32 id) static inline bool list_set_expired(const struct list_set *map, u32 id) { - const struct set_telem *elem = list_set_telem(map, id); + const struct set_telem *elem = + (const struct set_telem *) list_set_elem(map, id); return ip_set_timeout_expired(elem->timeout); } +static inline int +list_set_exist(const struct set_telem *elem) +{ + return elem->id != IPSET_INVALID_ID && + !ip_set_timeout_expired(elem->timeout); +} + /* Set list without and with timeout */ static int @@ -143,11 +146,11 @@ list_elem_tadd(struct list_set *map, u32 i, ip_set_id_t id, struct set_telem *e; for (; i < map->size; i++) { - e = list_set_telem(map, i); + e = (struct set_telem *)list_set_elem(map, i); swap(e->id, id); - swap(e->timeout, timeout); if (e->id == IPSET_INVALID_ID) break; + swap(e->timeout, timeout); } } @@ -161,7 +164,7 @@ list_set_add(struct list_set *map, u32 i, ip_set_id_t id, /* Last element replaced: e.g. add new,before,last */ ip_set_put_byindex(e->id); if (with_timeout(map->timeout)) - list_elem_tadd(map, i, id, ip_set_timeout_set(timeout)); + list_elem_tadd(map, i, id, timeout); else list_elem_add(map, i, id); @@ -169,11 +172,11 @@ list_set_add(struct list_set *map, u32 i, ip_set_id_t id, } static int -list_set_del(struct list_set *map, u32 i) +list_set_del(struct list_set *map, ip_set_id_t id, u32 i) { struct set_elem *a = list_set_elem(map, i), *b; - ip_set_put_byindex(a->id); + ip_set_put_byindex(id); for (; i < map->size - 1; i++) { b = list_set_elem(map, i + 1); @@ -305,11 +308,11 @@ list_set_uadt(struct ip_set *set, struct nlattr *tb[], (before == 0 || (before > 0 && next_id_eq(map, i, refid)))) - ret = list_set_del(map, i); + ret = list_set_del(map, id, i); else if (before < 0 && elem->id == refid && next_id_eq(map, i, id)) - ret = list_set_del(map, i + 1); + ret = list_set_del(map, id, i + 1); } break; default: @@ -366,7 +369,8 @@ list_set_head(struct ip_set *set, struct sk_buff *skb) NLA_PUT_NET32(skb, IPSET_ATTR_SIZE, htonl(map->size)); if (with_timeout(map->timeout)) NLA_PUT_NET32(skb, IPSET_ATTR_TIMEOUT, htonl(map->timeout)); - NLA_PUT_NET32(skb, IPSET_ATTR_REFERENCES, htonl(set->ref - 1)); + NLA_PUT_NET32(skb, IPSET_ATTR_REFERENCES, + htonl(atomic_read(&set->ref) - 1)); NLA_PUT_NET32(skb, IPSET_ATTR_MEMSIZE, htonl(sizeof(*map) + map->size * map->dsize)); ipset_nest_end(skb, nested); @@ -457,13 +461,16 @@ list_set_gc(unsigned long ul_set) struct set_telem *e; u32 i; - write_lock_bh(&set->lock); - for (i = 0; i < map->size; i++) { - e = list_set_telem(map, i); - if (e->id != IPSET_INVALID_ID && list_set_expired(map, i)) - list_set_del(map, i); + /* We run parallel with other readers (test element) + * but adding/deleting new entries is locked out */ + read_lock_bh(&set->lock); + for (i = map->size - 1; i >= 0; i--) { + e = (struct set_telem *) list_set_elem(map, i); + if (e->id != IPSET_INVALID_ID && + list_set_expired(map, i)) + list_set_del(map, e->id, i); } - write_unlock_bh(&set->lock); + read_unlock_bh(&set->lock); map->gc.expires = jiffies + IPSET_GC_PERIOD(map->timeout) * HZ; add_timer(&map->gc); diff --git a/trunk/net/netfilter/ipvs/ip_vs_ctl.c b/trunk/net/netfilter/ipvs/ip_vs_ctl.c index ae47090bf45f..33733c8872e7 100644 --- a/trunk/net/netfilter/ipvs/ip_vs_ctl.c +++ b/trunk/net/netfilter/ipvs/ip_vs_ctl.c @@ -3120,7 +3120,7 @@ static int ip_vs_genl_dump_daemon(struct sk_buff *skb, __be32 state, static int ip_vs_genl_dump_daemons(struct sk_buff *skb, struct netlink_callback *cb) { - struct net *net = skb_sknet(skb); + struct net *net = skb_net(skb); struct netns_ipvs *ipvs = net_ipvs(net); mutex_lock(&__ip_vs_mutex); diff --git a/trunk/net/netfilter/nf_conntrack_h323_asn1.c b/trunk/net/netfilter/nf_conntrack_h323_asn1.c index bcd5ed6b7130..867882313e49 100644 --- a/trunk/net/netfilter/nf_conntrack_h323_asn1.c +++ b/trunk/net/netfilter/nf_conntrack_h323_asn1.c @@ -631,7 +631,7 @@ static int decode_seqof(bitstr_t *bs, const struct field_t *f, CHECK_BOUND(bs, 2); count = *bs->cur++; count <<= 8; - count += *bs->cur++; + count = *bs->cur++; break; case SEMI: BYTE_ALIGN(bs); diff --git a/trunk/net/netfilter/nf_conntrack_h323_main.c b/trunk/net/netfilter/nf_conntrack_h323_main.c index 18b2ce5c8ced..533a183e6661 100644 --- a/trunk/net/netfilter/nf_conntrack_h323_main.c +++ b/trunk/net/netfilter/nf_conntrack_h323_main.c @@ -731,10 +731,10 @@ static int callforward_do_filter(const union nf_inet_addr *src, memset(&fl2, 0, sizeof(fl2)); fl2.daddr = dst->ip; - if (!afinfo->route(&init_net, (struct dst_entry **)&rt1, - flowi4_to_flowi(&fl1), false)) { - if (!afinfo->route(&init_net, (struct dst_entry **)&rt2, - flowi4_to_flowi(&fl2), false)) { + if (!afinfo->route((struct dst_entry **)&rt1, + flowi4_to_flowi(&fl1))) { + if (!afinfo->route((struct dst_entry **)&rt2, + flowi4_to_flowi(&fl2))) { if (rt1->rt_gateway == rt2->rt_gateway && rt1->dst.dev == rt2->dst.dev) ret = 1; @@ -755,10 +755,10 @@ static int callforward_do_filter(const union nf_inet_addr *src, memset(&fl2, 0, sizeof(fl2)); ipv6_addr_copy(&fl2.daddr, &dst->in6); - if (!afinfo->route(&init_net, (struct dst_entry **)&rt1, - flowi6_to_flowi(&fl1), false)) { - if (!afinfo->route(&init_net, (struct dst_entry **)&rt2, - flowi6_to_flowi(&fl2), false)) { + if (!afinfo->route((struct dst_entry **)&rt1, + flowi6_to_flowi(&fl1))) { + if (!afinfo->route((struct dst_entry **)&rt2, + flowi6_to_flowi(&fl2))) { if (!memcmp(&rt1->rt6i_gateway, &rt2->rt6i_gateway, sizeof(rt1->rt6i_gateway)) && rt1->dst.dev == rt2->dst.dev) diff --git a/trunk/net/netfilter/xt_TCPMSS.c b/trunk/net/netfilter/xt_TCPMSS.c index 9e63b43faeed..6e6b46cb1db9 100644 --- a/trunk/net/netfilter/xt_TCPMSS.c +++ b/trunk/net/netfilter/xt_TCPMSS.c @@ -166,7 +166,7 @@ static u_int32_t tcpmss_reverse_mtu(const struct sk_buff *skb, rcu_read_lock(); ai = nf_get_afinfo(family); if (ai != NULL) - ai->route(&init_net, (struct dst_entry **)&rt, &fl, false); + ai->route((struct dst_entry **)&rt, &fl); rcu_read_unlock(); if (rt != NULL) { diff --git a/trunk/net/netfilter/xt_addrtype.c b/trunk/net/netfilter/xt_addrtype.c index b77d383cec78..2220b85e9519 100644 --- a/trunk/net/netfilter/xt_addrtype.c +++ b/trunk/net/netfilter/xt_addrtype.c @@ -32,32 +32,11 @@ MODULE_ALIAS("ipt_addrtype"); MODULE_ALIAS("ip6t_addrtype"); #if defined(CONFIG_IP6_NF_IPTABLES) || defined(CONFIG_IP6_NF_IPTABLES_MODULE) -static u32 match_lookup_rt6(struct net *net, const struct net_device *dev, - const struct in6_addr *addr) +static u32 xt_addrtype_rt6_to_type(const struct rt6_info *rt) { - const struct nf_afinfo *afinfo; - struct flowi6 flow; - struct rt6_info *rt; u32 ret; - int route_err; - memset(&flow, 0, sizeof(flow)); - ipv6_addr_copy(&flow.daddr, addr); - if (dev) - flow.flowi6_oif = dev->ifindex; - - rcu_read_lock(); - - afinfo = nf_get_afinfo(NFPROTO_IPV6); - if (afinfo != NULL) - route_err = afinfo->route(net, (struct dst_entry **)&rt, - flowi6_to_flowi(&flow), !!dev); - else - route_err = 1; - - rcu_read_unlock(); - - if (route_err) + if (!rt) return XT_ADDRTYPE_UNREACHABLE; if (rt->rt6i_flags & RTF_REJECT) @@ -69,9 +48,6 @@ static u32 match_lookup_rt6(struct net *net, const struct net_device *dev, ret |= XT_ADDRTYPE_LOCAL; if (rt->rt6i_flags & RTF_ANYCAST) ret |= XT_ADDRTYPE_ANYCAST; - - - dst_release(&rt->dst); return ret; } @@ -89,8 +65,18 @@ static bool match_type6(struct net *net, const struct net_device *dev, return false; if ((XT_ADDRTYPE_LOCAL | XT_ADDRTYPE_ANYCAST | - XT_ADDRTYPE_UNREACHABLE) & mask) - return !!(mask & match_lookup_rt6(net, dev, addr)); + XT_ADDRTYPE_UNREACHABLE) & mask) { + struct rt6_info *rt; + u32 type; + int ifindex = dev ? dev->ifindex : 0; + + rt = rt6_lookup(net, addr, NULL, ifindex, !!dev); + + type = xt_addrtype_rt6_to_type(rt); + + dst_release(&rt->dst); + return !!(mask & type); + } return true; } diff --git a/trunk/net/netfilter/xt_conntrack.c b/trunk/net/netfilter/xt_conntrack.c index 481a86fdc409..2c0086a4751e 100644 --- a/trunk/net/netfilter/xt_conntrack.c +++ b/trunk/net/netfilter/xt_conntrack.c @@ -195,7 +195,7 @@ conntrack_mt(const struct sk_buff *skb, struct xt_action_param *par, return info->match_flags & XT_CONNTRACK_STATE; if ((info->match_flags & XT_CONNTRACK_DIRECTION) && (CTINFO2DIR(ctinfo) == IP_CT_DIR_ORIGINAL) ^ - !(info->invert_flags & XT_CONNTRACK_DIRECTION)) + !!(info->invert_flags & XT_CONNTRACK_DIRECTION)) return false; if (info->match_flags & XT_CONNTRACK_ORIGSRC) diff --git a/trunk/net/sunrpc/auth_gss/gss_krb5_mech.c b/trunk/net/sunrpc/auth_gss/gss_krb5_mech.c index 0a9a2ec2e469..9022f0a6503e 100644 --- a/trunk/net/sunrpc/auth_gss/gss_krb5_mech.c +++ b/trunk/net/sunrpc/auth_gss/gss_krb5_mech.c @@ -427,7 +427,7 @@ static int context_derive_keys_rc4(struct krb5_ctx *ctx) { struct crypto_hash *hmac; - char sigkeyconstant[] = "signaturekey"; + static const char sigkeyconstant[] = "signaturekey"; int slen = strlen(sigkeyconstant) + 1; /* include null terminator */ struct hash_desc desc; struct scatterlist sg[1]; diff --git a/trunk/sound/arm/pxa2xx-pcm-lib.c b/trunk/sound/arm/pxa2xx-pcm-lib.c index 76e0d5695075..8808b82311b1 100644 --- a/trunk/sound/arm/pxa2xx-pcm-lib.c +++ b/trunk/sound/arm/pxa2xx-pcm-lib.c @@ -140,9 +140,6 @@ int __pxa2xx_pcm_prepare(struct snd_pcm_substream *substream) if (!prtd || !prtd->params) return 0; - if (prtd->dma_ch == -1) - return -EINVAL; - DCSR(prtd->dma_ch) &= ~DCSR_RUN; DCSR(prtd->dma_ch) = 0; DCMD(prtd->dma_ch) = 0; diff --git a/trunk/sound/pci/hda/patch_conexant.c b/trunk/sound/pci/hda/patch_conexant.c index ad97d937d3a8..69e33869a53e 100644 --- a/trunk/sound/pci/hda/patch_conexant.c +++ b/trunk/sound/pci/hda/patch_conexant.c @@ -3035,7 +3035,6 @@ static struct snd_pci_quirk cxt5066_cfg_tbl[] = { SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), - SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS), SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */ {} diff --git a/trunk/sound/pci/hda/patch_hdmi.c b/trunk/sound/pci/hda/patch_hdmi.c index 715615a88a8d..251773e45f61 100644 --- a/trunk/sound/pci/hda/patch_hdmi.c +++ b/trunk/sound/pci/hda/patch_hdmi.c @@ -1280,39 +1280,6 @@ static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo, stream_tag, format, substream); } -static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec, - int channels) -{ - unsigned int chanmask; - int chan = channels ? (channels - 1) : 1; - - switch (channels) { - default: - case 0: - case 2: - chanmask = 0x00; - break; - case 4: - chanmask = 0x08; - break; - case 6: - chanmask = 0x0b; - break; - case 8: - chanmask = 0x13; - break; - } - - /* Set the audio infoframe channel allocation and checksum fields. The - * channel count is computed implicitly by the hardware. */ - snd_hda_codec_write(codec, 0x1, 0, - Nv_VERB_SET_Channel_Allocation, chanmask); - - snd_hda_codec_write(codec, 0x1, 0, - Nv_VERB_SET_Info_Frame_Checksum, - (0x71 - chan - chanmask)); -} - static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo, struct hda_codec *codec, struct snd_pcm_substream *substream) @@ -1331,10 +1298,6 @@ static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo, AC_VERB_SET_STREAM_FORMAT, 0); } - /* The audio hardware sends a channel count of 0x7 (8ch) when all the - * streams are disabled. */ - nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8); - return snd_hda_multi_out_dig_close(codec, &spec->multiout); } @@ -1345,16 +1308,37 @@ static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo, struct snd_pcm_substream *substream) { int chs; - unsigned int dataDCC1, dataDCC2, channel_id; + unsigned int dataDCC1, dataDCC2, chan, chanmask, channel_id; int i; mutex_lock(&codec->spdif_mutex); chs = substream->runtime->channels; + chan = chs ? (chs - 1) : 1; + switch (chs) { + default: + case 0: + case 2: + chanmask = 0x00; + break; + case 4: + chanmask = 0x08; + break; + case 6: + chanmask = 0x0b; + break; + case 8: + chanmask = 0x13; + break; + } dataDCC1 = AC_DIG1_ENABLE | AC_DIG1_COPYRIGHT; dataDCC2 = 0x2; + /* set the Audio InforFrame Channel Allocation */ + snd_hda_codec_write(codec, 0x1, 0, + Nv_VERB_SET_Channel_Allocation, chanmask); + /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */ if (codec->spdif_status_reset && (codec->spdif_ctls & AC_DIG1_ENABLE)) snd_hda_codec_write(codec, @@ -1429,7 +1413,10 @@ static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo, } } - nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs); + /* set the Audio Info Frame Checksum */ + snd_hda_codec_write(codec, 0x1, 0, + Nv_VERB_SET_Info_Frame_Checksum, + (0x71 - chan - chanmask)); mutex_unlock(&codec->spdif_mutex); return 0; @@ -1525,11 +1512,6 @@ static int patch_nvhdmi_8ch_7x(struct hda_codec *codec) spec->multiout.max_channels = 8; spec->pcm_playback = &nvhdmi_pcm_playback_8ch_7x; codec->patch_ops = nvhdmi_patch_ops_8ch_7x; - - /* Initialize the audio infoframe channel mask and checksum to something - * valid */ - nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8); - return 0; } diff --git a/trunk/sound/pci/hda/patch_realtek.c b/trunk/sound/pci/hda/patch_realtek.c index 52928d9a72da..7e28a64884f6 100644 --- a/trunk/sound/pci/hda/patch_realtek.c +++ b/trunk/sound/pci/hda/patch_realtek.c @@ -14124,7 +14124,7 @@ static hda_nid_t alc269vb_capsrc_nids[1] = { }; static hda_nid_t alc269_adc_candidates[] = { - 0x08, 0x09, 0x07, 0x11, + 0x08, 0x09, 0x07, }; #define alc269_modes alc260_modes diff --git a/trunk/sound/pci/hda/patch_sigmatel.c b/trunk/sound/pci/hda/patch_sigmatel.c index 94d19c03a7f4..1395991c39f2 100644 --- a/trunk/sound/pci/hda/patch_sigmatel.c +++ b/trunk/sound/pci/hda/patch_sigmatel.c @@ -3408,9 +3408,6 @@ static int get_connection_index(struct hda_codec *codec, hda_nid_t mux, hda_nid_t conn[HDA_MAX_NUM_INPUTS]; int i, nums; - if (!(get_wcaps(codec, mux) & AC_WCAP_CONN_LIST)) - return -1; - nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn)); for (i = 0; i < nums; i++) if (conn[i] == nid) diff --git a/trunk/sound/soc/pxa/pxa2xx-pcm.c b/trunk/sound/soc/pxa/pxa2xx-pcm.c index 2ce0b2d891d5..02fb66416ddc 100644 --- a/trunk/sound/soc/pxa/pxa2xx-pcm.c +++ b/trunk/sound/soc/pxa/pxa2xx-pcm.c @@ -65,7 +65,6 @@ static int pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream) if (prtd->dma_ch >= 0) { pxa_free_dma(prtd->dma_ch); prtd->dma_ch = -1; - prtd->params = NULL; } return 0; diff --git a/trunk/sound/soc/pxa/zylonite.c b/trunk/sound/soc/pxa/zylonite.c index b6445757fc54..ac577263b3e3 100644 --- a/trunk/sound/soc/pxa/zylonite.c +++ b/trunk/sound/soc/pxa/zylonite.c @@ -167,7 +167,7 @@ static struct snd_soc_dai_link zylonite_dai[] = { .codec_name = "wm9713-codec", .platform_name = "pxa-pcm-audio", .cpu_dai_name = "pxa2xx-ac97", - .codec_dai_name = "wm9713-hifi", + .codec_name = "wm9713-hifi", .init = zylonite_wm9713_init, }, { @@ -176,7 +176,7 @@ static struct snd_soc_dai_link zylonite_dai[] = { .codec_name = "wm9713-codec", .platform_name = "pxa-pcm-audio", .cpu_dai_name = "pxa2xx-ac97-aux", - .codec_dai_name = "wm9713-aux", + .codec_name = "wm9713-aux", }, { .name = "WM9713 Voice", @@ -184,7 +184,7 @@ static struct snd_soc_dai_link zylonite_dai[] = { .codec_name = "wm9713-codec", .platform_name = "pxa-pcm-audio", .cpu_dai_name = "pxa-ssp-dai.2", - .codec_dai_name = "wm9713-voice", + .codec_name = "wm9713-voice", .ops = &zylonite_voice_ops, }, }; diff --git a/trunk/sound/soc/soc-core.c b/trunk/sound/soc/soc-core.c index b76b74db0968..4dda58926bc5 100644 --- a/trunk/sound/soc/soc-core.c +++ b/trunk/sound/soc/soc-core.c @@ -92,8 +92,8 @@ static int min_bytes_needed(unsigned long val) static int format_register_str(struct snd_soc_codec *codec, unsigned int reg, char *buf, size_t len) { - int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; - int regsize = codec->driver->reg_word_size * 2; + int wordsize = codec->driver->reg_word_size * 2; + int regsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; int ret; char tmpbuf[len + 1]; char regbuf[regsize + 1]; @@ -132,8 +132,8 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf, size_t total = 0; loff_t p = 0; - wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; - regsize = codec->driver->reg_word_size * 2; + wordsize = codec->driver->reg_word_size * 2; + regsize = min_bytes_needed(codec->driver->reg_cache_size) * 2; len = wordsize + regsize + 2 + 1; diff --git a/trunk/sound/usb/midi.c b/trunk/sound/usb/midi.c index f9289102886a..b4b39c0b6c9e 100644 --- a/trunk/sound/usb/midi.c +++ b/trunk/sound/usb/midi.c @@ -1301,7 +1301,6 @@ static int snd_usbmidi_out_endpoint_create(struct snd_usb_midi* umidi, case USB_ID(0x15ca, 0x0101): /* Textech USB Midi Cable */ case USB_ID(0x15ca, 0x1806): /* Textech USB Midi Cable */ case USB_ID(0x1a86, 0x752d): /* QinHeng CH345 "USB2.0-MIDI" */ - case USB_ID(0xfc08, 0x0101): /* Unknown vendor Cable */ ep->max_transfer = 4; break; /* diff --git a/trunk/tools/perf/util/cgroup.c b/trunk/tools/perf/util/cgroup.c index 96bee5c46008..9fea75535221 100644 --- a/trunk/tools/perf/util/cgroup.c +++ b/trunk/tools/perf/util/cgroup.c @@ -13,7 +13,7 @@ cgroupfs_find_mountpoint(char *buf, size_t maxlen) { FILE *fp; char mountpoint[MAX_PATH+1], tokens[MAX_PATH+1], type[MAX_PATH+1]; - char *token, *saved_ptr = NULL; + char *token, *saved_ptr; int found = 0; fp = fopen("/proc/mounts", "r");