18c2ecf20Sopenharmony_ci/******************************************************************************
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
48c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * GPL LICENSE SUMMARY
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
118c2ecf20Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as
128c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but
158c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
168c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
178c2ecf20Sopenharmony_ci * General Public License for more details.
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License
208c2ecf20Sopenharmony_ci * along with this program; if not, write to the Free Software
218c2ecf20Sopenharmony_ci * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
228c2ecf20Sopenharmony_ci * USA
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci * The full GNU General Public License is included in this distribution
258c2ecf20Sopenharmony_ci * in the file called LICENSE.GPL.
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * Contact Information:
288c2ecf20Sopenharmony_ci *  Intel Linux Wireless <ilw@linux.intel.com>
298c2ecf20Sopenharmony_ci * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci * BSD LICENSE
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci * Copyright(c) 2005 - 2011 Intel Corporation. All rights reserved.
348c2ecf20Sopenharmony_ci * All rights reserved.
358c2ecf20Sopenharmony_ci *
368c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
378c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
388c2ecf20Sopenharmony_ci * are met:
398c2ecf20Sopenharmony_ci *
408c2ecf20Sopenharmony_ci *  * Redistributions of source code must retain the above copyright
418c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
428c2ecf20Sopenharmony_ci *  * Redistributions in binary form must reproduce the above copyright
438c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
448c2ecf20Sopenharmony_ci *    the documentation and/or other materials provided with the
458c2ecf20Sopenharmony_ci *    distribution.
468c2ecf20Sopenharmony_ci *  * Neither the name Intel Corporation nor the names of its
478c2ecf20Sopenharmony_ci *    contributors may be used to endorse or promote products derived
488c2ecf20Sopenharmony_ci *    from this software without specific prior written permission.
498c2ecf20Sopenharmony_ci *
508c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
518c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
528c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
538c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
548c2ecf20Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
558c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
568c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
578c2ecf20Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
588c2ecf20Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
598c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
608c2ecf20Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
618c2ecf20Sopenharmony_ci *****************************************************************************/
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#ifndef	__il_prph_h__
648c2ecf20Sopenharmony_ci#define __il_prph_h__
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/*
678c2ecf20Sopenharmony_ci * Registers in this file are internal, not PCI bus memory mapped.
688c2ecf20Sopenharmony_ci * Driver accesses these via HBUS_TARG_PRPH_* registers.
698c2ecf20Sopenharmony_ci */
708c2ecf20Sopenharmony_ci#define PRPH_BASE	(0x00000)
718c2ecf20Sopenharmony_ci#define PRPH_END	(0xFFFFF)
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci/* APMG (power management) constants */
748c2ecf20Sopenharmony_ci#define APMG_BASE			(PRPH_BASE + 0x3000)
758c2ecf20Sopenharmony_ci#define APMG_CLK_CTRL_REG		(APMG_BASE + 0x0000)
768c2ecf20Sopenharmony_ci#define APMG_CLK_EN_REG			(APMG_BASE + 0x0004)
778c2ecf20Sopenharmony_ci#define APMG_CLK_DIS_REG		(APMG_BASE + 0x0008)
788c2ecf20Sopenharmony_ci#define APMG_PS_CTRL_REG		(APMG_BASE + 0x000c)
798c2ecf20Sopenharmony_ci#define APMG_PCIDEV_STT_REG		(APMG_BASE + 0x0010)
808c2ecf20Sopenharmony_ci#define APMG_RFKILL_REG			(APMG_BASE + 0x0014)
818c2ecf20Sopenharmony_ci#define APMG_RTC_INT_STT_REG		(APMG_BASE + 0x001c)
828c2ecf20Sopenharmony_ci#define APMG_RTC_INT_MSK_REG		(APMG_BASE + 0x0020)
838c2ecf20Sopenharmony_ci#define APMG_DIGITAL_SVR_REG		(APMG_BASE + 0x0058)
848c2ecf20Sopenharmony_ci#define APMG_ANALOG_SVR_REG		(APMG_BASE + 0x006C)
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#define APMS_CLK_VAL_MRB_FUNC_MODE	(0x00000001)
878c2ecf20Sopenharmony_ci#define APMG_CLK_VAL_DMA_CLK_RQT	(0x00000200)
888c2ecf20Sopenharmony_ci#define APMG_CLK_VAL_BSM_CLK_RQT	(0x00000800)
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS	(0x00400000)
918c2ecf20Sopenharmony_ci#define APMG_PS_CTRL_VAL_RESET_REQ		(0x04000000)
928c2ecf20Sopenharmony_ci#define APMG_PS_CTRL_MSK_PWR_SRC		(0x03000000)
938c2ecf20Sopenharmony_ci#define APMG_PS_CTRL_VAL_PWR_SRC_VMAIN		(0x00000000)
948c2ecf20Sopenharmony_ci#define APMG_PS_CTRL_VAL_PWR_SRC_MAX		(0x01000000)	/* 3945 only */
958c2ecf20Sopenharmony_ci#define APMG_PS_CTRL_VAL_PWR_SRC_VAUX		(0x02000000)
968c2ecf20Sopenharmony_ci#define APMG_SVR_VOLTAGE_CONFIG_BIT_MSK	(0x000001E0)	/* bit 8:5 */
978c2ecf20Sopenharmony_ci#define APMG_SVR_DIGITAL_VOLTAGE_1_32		(0x00000060)
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define APMG_PCIDEV_STT_VAL_L1_ACT_DIS		(0x00000800)
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/**
1028c2ecf20Sopenharmony_ci * BSM (Bootstrap State Machine)
1038c2ecf20Sopenharmony_ci *
1048c2ecf20Sopenharmony_ci * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
1058c2ecf20Sopenharmony_ci * in special SRAM that does not power down when the embedded control
1068c2ecf20Sopenharmony_ci * processor is sleeping (e.g. for periodic power-saving shutdowns of radio).
1078c2ecf20Sopenharmony_ci *
1088c2ecf20Sopenharmony_ci * When powering back up after sleeps (or during initial uCode load), the BSM
1098c2ecf20Sopenharmony_ci * internally loads the short bootstrap program from the special SRAM into the
1108c2ecf20Sopenharmony_ci * embedded processor's instruction SRAM, and starts the processor so it runs
1118c2ecf20Sopenharmony_ci * the bootstrap program.
1128c2ecf20Sopenharmony_ci *
1138c2ecf20Sopenharmony_ci * This bootstrap program loads (via PCI busmaster DMA) instructions and data
1148c2ecf20Sopenharmony_ci * images for a uCode program from host DRAM locations.  The host driver
1158c2ecf20Sopenharmony_ci * indicates DRAM locations and sizes for instruction and data images via the
1168c2ecf20Sopenharmony_ci * four BSM_DRAM_* registers.  Once the bootstrap program loads the new program,
1178c2ecf20Sopenharmony_ci * the new program starts automatically.
1188c2ecf20Sopenharmony_ci *
1198c2ecf20Sopenharmony_ci * The uCode used for open-source drivers includes two programs:
1208c2ecf20Sopenharmony_ci *
1218c2ecf20Sopenharmony_ci * 1)  Initialization -- performs hardware calibration and sets up some
1228c2ecf20Sopenharmony_ci *     internal data, then notifies host via "initialize alive" notification
1238c2ecf20Sopenharmony_ci *     (struct il_init_alive_resp) that it has completed all of its work.
1248c2ecf20Sopenharmony_ci *     After signal from host, it then loads and starts the runtime program.
1258c2ecf20Sopenharmony_ci *     The initialization program must be used when initially setting up the
1268c2ecf20Sopenharmony_ci *     NIC after loading the driver.
1278c2ecf20Sopenharmony_ci *
1288c2ecf20Sopenharmony_ci * 2)  Runtime/Protocol -- performs all normal runtime operations.  This
1298c2ecf20Sopenharmony_ci *     notifies host via "alive" notification (struct il_alive_resp) that it
1308c2ecf20Sopenharmony_ci *     is ready to be used.
1318c2ecf20Sopenharmony_ci *
1328c2ecf20Sopenharmony_ci * When initializing the NIC, the host driver does the following procedure:
1338c2ecf20Sopenharmony_ci *
1348c2ecf20Sopenharmony_ci * 1)  Load bootstrap program (instructions only, no data image for bootstrap)
1358c2ecf20Sopenharmony_ci *     into bootstrap memory.  Use dword writes starting at BSM_SRAM_LOWER_BOUND
1368c2ecf20Sopenharmony_ci *
1378c2ecf20Sopenharmony_ci * 2)  Point (via BSM_DRAM_*) to the "initialize" uCode data and instruction
1388c2ecf20Sopenharmony_ci *     images in host DRAM.
1398c2ecf20Sopenharmony_ci *
1408c2ecf20Sopenharmony_ci * 3)  Set up BSM to copy from BSM SRAM into uCode instruction SRAM when asked:
1418c2ecf20Sopenharmony_ci *     BSM_WR_MEM_SRC_REG = 0
1428c2ecf20Sopenharmony_ci *     BSM_WR_MEM_DST_REG = RTC_INST_LOWER_BOUND
1438c2ecf20Sopenharmony_ci *     BSM_WR_MEM_DWCOUNT_REG = # dwords in bootstrap instruction image
1448c2ecf20Sopenharmony_ci *
1458c2ecf20Sopenharmony_ci * 4)  Load bootstrap into instruction SRAM:
1468c2ecf20Sopenharmony_ci *     BSM_WR_CTRL_REG = BSM_WR_CTRL_REG_BIT_START
1478c2ecf20Sopenharmony_ci *
1488c2ecf20Sopenharmony_ci * 5)  Wait for load completion:
1498c2ecf20Sopenharmony_ci *     Poll BSM_WR_CTRL_REG for BSM_WR_CTRL_REG_BIT_START = 0
1508c2ecf20Sopenharmony_ci *
1518c2ecf20Sopenharmony_ci * 6)  Enable future boot loads whenever NIC's power management triggers it:
1528c2ecf20Sopenharmony_ci *     BSM_WR_CTRL_REG = BSM_WR_CTRL_REG_BIT_START_EN
1538c2ecf20Sopenharmony_ci *
1548c2ecf20Sopenharmony_ci * 7)  Start the NIC by removing all reset bits:
1558c2ecf20Sopenharmony_ci *     CSR_RESET = 0
1568c2ecf20Sopenharmony_ci *
1578c2ecf20Sopenharmony_ci *     The bootstrap uCode (already in instruction SRAM) loads initialization
1588c2ecf20Sopenharmony_ci *     uCode.  Initialization uCode performs data initialization, sends
1598c2ecf20Sopenharmony_ci *     "initialize alive" notification to host, and waits for a signal from
1608c2ecf20Sopenharmony_ci *     host to load runtime code.
1618c2ecf20Sopenharmony_ci *
1628c2ecf20Sopenharmony_ci * 4)  Point (via BSM_DRAM_*) to the "runtime" uCode data and instruction
1638c2ecf20Sopenharmony_ci *     images in host DRAM.  The last register loaded must be the instruction
1648c2ecf20Sopenharmony_ci *     byte count register ("1" in MSbit tells initialization uCode to load
1658c2ecf20Sopenharmony_ci *     the runtime uCode):
1668c2ecf20Sopenharmony_ci *     BSM_DRAM_INST_BYTECOUNT_REG = byte count | BSM_DRAM_INST_LOAD
1678c2ecf20Sopenharmony_ci *
1688c2ecf20Sopenharmony_ci * 5)  Wait for "alive" notification, then issue normal runtime commands.
1698c2ecf20Sopenharmony_ci *
1708c2ecf20Sopenharmony_ci * Data caching during power-downs:
1718c2ecf20Sopenharmony_ci *
1728c2ecf20Sopenharmony_ci * Just before the embedded controller powers down (e.g for automatic
1738c2ecf20Sopenharmony_ci * power-saving modes, or for RFKILL), uCode stores (via PCI busmaster DMA)
1748c2ecf20Sopenharmony_ci * a current snapshot of the embedded processor's data SRAM into host DRAM.
1758c2ecf20Sopenharmony_ci * This caches the data while the embedded processor's memory is powered down.
1768c2ecf20Sopenharmony_ci * Location and size are controlled by BSM_DRAM_DATA_* registers.
1778c2ecf20Sopenharmony_ci *
1788c2ecf20Sopenharmony_ci * NOTE:  Instruction SRAM does not need to be saved, since that doesn't
1798c2ecf20Sopenharmony_ci *        change during operation; the original image (from uCode distribution
1808c2ecf20Sopenharmony_ci *        file) can be used for reload.
1818c2ecf20Sopenharmony_ci *
1828c2ecf20Sopenharmony_ci * When powering back up, the BSM loads the bootstrap program.  Bootstrap looks
1838c2ecf20Sopenharmony_ci * at the BSM_DRAM_* registers, which now point to the runtime instruction
1848c2ecf20Sopenharmony_ci * image and the cached (modified) runtime data (*not* the initialization
1858c2ecf20Sopenharmony_ci * uCode).  Bootstrap reloads these runtime images into SRAM, and restarts the
1868c2ecf20Sopenharmony_ci * uCode from where it left off before the power-down.
1878c2ecf20Sopenharmony_ci *
1888c2ecf20Sopenharmony_ci * NOTE:  Initialization uCode does *not* run as part of the save/restore
1898c2ecf20Sopenharmony_ci *        procedure.
1908c2ecf20Sopenharmony_ci *
1918c2ecf20Sopenharmony_ci * This save/restore method is mostly for autonomous power management during
1928c2ecf20Sopenharmony_ci * normal operation (result of C_POWER_TBL).  Platform suspend/resume and
1938c2ecf20Sopenharmony_ci * RFKILL should use complete restarts (with total re-initialization) of uCode,
1948c2ecf20Sopenharmony_ci * allowing total shutdown (including BSM memory).
1958c2ecf20Sopenharmony_ci *
1968c2ecf20Sopenharmony_ci * Note that, during normal operation, the host DRAM that held the initial
1978c2ecf20Sopenharmony_ci * startup data for the runtime code is now being used as a backup data cache
1988c2ecf20Sopenharmony_ci * for modified data!  If you need to completely re-initialize the NIC, make
1998c2ecf20Sopenharmony_ci * sure that you use the runtime data image from the uCode distribution file,
2008c2ecf20Sopenharmony_ci * not the modified/saved runtime data.  You may want to store a separate
2018c2ecf20Sopenharmony_ci * "clean" runtime data image in DRAM to avoid disk reads of distribution file.
2028c2ecf20Sopenharmony_ci */
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci/* BSM bit fields */
2058c2ecf20Sopenharmony_ci#define BSM_WR_CTRL_REG_BIT_START     (0x80000000)	/* start boot load now */
2068c2ecf20Sopenharmony_ci#define BSM_WR_CTRL_REG_BIT_START_EN  (0x40000000)	/* enable boot after pwrup */
2078c2ecf20Sopenharmony_ci#define BSM_DRAM_INST_LOAD            (0x80000000)	/* start program load now */
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci/* BSM addresses */
2108c2ecf20Sopenharmony_ci#define BSM_BASE                     (PRPH_BASE + 0x3400)
2118c2ecf20Sopenharmony_ci#define BSM_END                      (PRPH_BASE + 0x3800)
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci#define BSM_WR_CTRL_REG              (BSM_BASE + 0x000)	/* ctl and status */
2148c2ecf20Sopenharmony_ci#define BSM_WR_MEM_SRC_REG           (BSM_BASE + 0x004)	/* source in BSM mem */
2158c2ecf20Sopenharmony_ci#define BSM_WR_MEM_DST_REG           (BSM_BASE + 0x008)	/* dest in SRAM mem */
2168c2ecf20Sopenharmony_ci#define BSM_WR_DWCOUNT_REG           (BSM_BASE + 0x00C)	/* bytes */
2178c2ecf20Sopenharmony_ci#define BSM_WR_STATUS_REG            (BSM_BASE + 0x010)	/* bit 0:  1 == done */
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci/*
2208c2ecf20Sopenharmony_ci * Pointers and size regs for bootstrap load and data SRAM save/restore.
2218c2ecf20Sopenharmony_ci * NOTE:  3945 pointers use bits 31:0 of DRAM address.
2228c2ecf20Sopenharmony_ci *        4965 pointers use bits 35:4 of DRAM address.
2238c2ecf20Sopenharmony_ci */
2248c2ecf20Sopenharmony_ci#define BSM_DRAM_INST_PTR_REG        (BSM_BASE + 0x090)
2258c2ecf20Sopenharmony_ci#define BSM_DRAM_INST_BYTECOUNT_REG  (BSM_BASE + 0x094)
2268c2ecf20Sopenharmony_ci#define BSM_DRAM_DATA_PTR_REG        (BSM_BASE + 0x098)
2278c2ecf20Sopenharmony_ci#define BSM_DRAM_DATA_BYTECOUNT_REG  (BSM_BASE + 0x09C)
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci/*
2308c2ecf20Sopenharmony_ci * BSM special memory, stays powered on during power-save sleeps.
2318c2ecf20Sopenharmony_ci * Read/write, address range from LOWER_BOUND to (LOWER_BOUND + SIZE -1)
2328c2ecf20Sopenharmony_ci */
2338c2ecf20Sopenharmony_ci#define BSM_SRAM_LOWER_BOUND         (PRPH_BASE + 0x3800)
2348c2ecf20Sopenharmony_ci#define BSM_SRAM_SIZE			(1024)	/* bytes */
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci/* 3945 Tx scheduler registers */
2378c2ecf20Sopenharmony_ci#define ALM_SCD_BASE                        (PRPH_BASE + 0x2E00)
2388c2ecf20Sopenharmony_ci#define ALM_SCD_MODE_REG                    (ALM_SCD_BASE + 0x000)
2398c2ecf20Sopenharmony_ci#define ALM_SCD_ARASTAT_REG                 (ALM_SCD_BASE + 0x004)
2408c2ecf20Sopenharmony_ci#define ALM_SCD_TXFACT_REG                  (ALM_SCD_BASE + 0x010)
2418c2ecf20Sopenharmony_ci#define ALM_SCD_TXF4MF_REG                  (ALM_SCD_BASE + 0x014)
2428c2ecf20Sopenharmony_ci#define ALM_SCD_TXF5MF_REG                  (ALM_SCD_BASE + 0x020)
2438c2ecf20Sopenharmony_ci#define ALM_SCD_SBYP_MODE_1_REG             (ALM_SCD_BASE + 0x02C)
2448c2ecf20Sopenharmony_ci#define ALM_SCD_SBYP_MODE_2_REG             (ALM_SCD_BASE + 0x030)
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_ci/**
2478c2ecf20Sopenharmony_ci * Tx Scheduler
2488c2ecf20Sopenharmony_ci *
2498c2ecf20Sopenharmony_ci * The Tx Scheduler selects the next frame to be transmitted, choosing TFDs
2508c2ecf20Sopenharmony_ci * (Transmit Frame Descriptors) from up to 16 circular Tx queues resident in
2518c2ecf20Sopenharmony_ci * host DRAM.  It steers each frame's Tx command (which contains the frame
2528c2ecf20Sopenharmony_ci * data) into one of up to 7 prioritized Tx DMA FIFO channels within the
2538c2ecf20Sopenharmony_ci * device.  A queue maps to only one (selectable by driver) Tx DMA channel,
2548c2ecf20Sopenharmony_ci * but one DMA channel may take input from several queues.
2558c2ecf20Sopenharmony_ci *
2568c2ecf20Sopenharmony_ci * Tx DMA FIFOs have dedicated purposes.  For 4965, they are used as follows
2578c2ecf20Sopenharmony_ci * (cf. default_queue_to_tx_fifo in 4965.c):
2588c2ecf20Sopenharmony_ci *
2598c2ecf20Sopenharmony_ci * 0 -- EDCA BK (background) frames, lowest priority
2608c2ecf20Sopenharmony_ci * 1 -- EDCA BE (best effort) frames, normal priority
2618c2ecf20Sopenharmony_ci * 2 -- EDCA VI (video) frames, higher priority
2628c2ecf20Sopenharmony_ci * 3 -- EDCA VO (voice) and management frames, highest priority
2638c2ecf20Sopenharmony_ci * 4 -- Commands (e.g. RXON, etc.)
2648c2ecf20Sopenharmony_ci * 5 -- unused (HCCA)
2658c2ecf20Sopenharmony_ci * 6 -- unused (HCCA)
2668c2ecf20Sopenharmony_ci * 7 -- not used by driver (device-internal only)
2678c2ecf20Sopenharmony_ci *
2688c2ecf20Sopenharmony_ci *
2698c2ecf20Sopenharmony_ci * Driver should normally map queues 0-6 to Tx DMA/FIFO channels 0-6.
2708c2ecf20Sopenharmony_ci * In addition, driver can map the remaining queues to Tx DMA/FIFO
2718c2ecf20Sopenharmony_ci * channels 0-3 to support 11n aggregation via EDCA DMA channels.
2728c2ecf20Sopenharmony_ci *
2738c2ecf20Sopenharmony_ci * The driver sets up each queue to work in one of two modes:
2748c2ecf20Sopenharmony_ci *
2758c2ecf20Sopenharmony_ci * 1)  Scheduler-Ack, in which the scheduler automatically supports a
2768c2ecf20Sopenharmony_ci *     block-ack (BA) win of up to 64 TFDs.  In this mode, each queue
2778c2ecf20Sopenharmony_ci *     contains TFDs for a unique combination of Recipient Address (RA)
2788c2ecf20Sopenharmony_ci *     and Traffic Identifier (TID), that is, traffic of a given
2798c2ecf20Sopenharmony_ci *     Quality-Of-Service (QOS) priority, destined for a single station.
2808c2ecf20Sopenharmony_ci *
2818c2ecf20Sopenharmony_ci *     In scheduler-ack mode, the scheduler keeps track of the Tx status of
2828c2ecf20Sopenharmony_ci *     each frame within the BA win, including whether it's been transmitted,
2838c2ecf20Sopenharmony_ci *     and whether it's been acknowledged by the receiving station.  The device
2848c2ecf20Sopenharmony_ci *     automatically processes block-acks received from the receiving STA,
2858c2ecf20Sopenharmony_ci *     and reschedules un-acked frames to be retransmitted (successful
2868c2ecf20Sopenharmony_ci *     Tx completion may end up being out-of-order).
2878c2ecf20Sopenharmony_ci *
2888c2ecf20Sopenharmony_ci *     The driver must maintain the queue's Byte Count table in host DRAM
2898c2ecf20Sopenharmony_ci *     (struct il4965_sched_queue_byte_cnt_tbl) for this mode.
2908c2ecf20Sopenharmony_ci *     This mode does not support fragmentation.
2918c2ecf20Sopenharmony_ci *
2928c2ecf20Sopenharmony_ci * 2)  FIFO (a.k.a. non-Scheduler-ACK), in which each TFD is processed in order.
2938c2ecf20Sopenharmony_ci *     The device may automatically retry Tx, but will retry only one frame
2948c2ecf20Sopenharmony_ci *     at a time, until receiving ACK from receiving station, or reaching
2958c2ecf20Sopenharmony_ci *     retry limit and giving up.
2968c2ecf20Sopenharmony_ci *
2978c2ecf20Sopenharmony_ci *     The command queue (#4/#9) must use this mode!
2988c2ecf20Sopenharmony_ci *     This mode does not require use of the Byte Count table in host DRAM.
2998c2ecf20Sopenharmony_ci *
3008c2ecf20Sopenharmony_ci * Driver controls scheduler operation via 3 means:
3018c2ecf20Sopenharmony_ci * 1)  Scheduler registers
3028c2ecf20Sopenharmony_ci * 2)  Shared scheduler data base in internal 4956 SRAM
3038c2ecf20Sopenharmony_ci * 3)  Shared data in host DRAM
3048c2ecf20Sopenharmony_ci *
3058c2ecf20Sopenharmony_ci * Initialization:
3068c2ecf20Sopenharmony_ci *
3078c2ecf20Sopenharmony_ci * When loading, driver should allocate memory for:
3088c2ecf20Sopenharmony_ci * 1)  16 TFD circular buffers, each with space for (typically) 256 TFDs.
3098c2ecf20Sopenharmony_ci * 2)  16 Byte Count circular buffers in 16 KBytes contiguous memory
3108c2ecf20Sopenharmony_ci *     (1024 bytes for each queue).
3118c2ecf20Sopenharmony_ci *
3128c2ecf20Sopenharmony_ci * After receiving "Alive" response from uCode, driver must initialize
3138c2ecf20Sopenharmony_ci * the scheduler (especially for queue #4/#9, the command queue, otherwise
3148c2ecf20Sopenharmony_ci * the driver can't issue commands!):
3158c2ecf20Sopenharmony_ci */
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci/**
3188c2ecf20Sopenharmony_ci * Max Tx win size is the max number of contiguous TFDs that the scheduler
3198c2ecf20Sopenharmony_ci * can keep track of at one time when creating block-ack chains of frames.
3208c2ecf20Sopenharmony_ci * Note that "64" matches the number of ack bits in a block-ack packet.
3218c2ecf20Sopenharmony_ci * Driver should use SCD_WIN_SIZE and SCD_FRAME_LIMIT values to initialize
3228c2ecf20Sopenharmony_ci * IL49_SCD_CONTEXT_QUEUE_OFFSET(x) values.
3238c2ecf20Sopenharmony_ci */
3248c2ecf20Sopenharmony_ci#define SCD_WIN_SIZE				64
3258c2ecf20Sopenharmony_ci#define SCD_FRAME_LIMIT				64
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci/* SCD registers are internal, must be accessed via HBUS_TARG_PRPH regs */
3288c2ecf20Sopenharmony_ci#define IL49_SCD_START_OFFSET		0xa02c00
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci/*
3318c2ecf20Sopenharmony_ci * 4965 tells driver SRAM address for internal scheduler structs via this reg.
3328c2ecf20Sopenharmony_ci * Value is valid only after "Alive" response from uCode.
3338c2ecf20Sopenharmony_ci */
3348c2ecf20Sopenharmony_ci#define IL49_SCD_SRAM_BASE_ADDR           (IL49_SCD_START_OFFSET + 0x0)
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci/*
3378c2ecf20Sopenharmony_ci * Driver may need to update queue-empty bits after changing queue's
3388c2ecf20Sopenharmony_ci * write and read pointers (idxes) during (re-)initialization (i.e. when
3398c2ecf20Sopenharmony_ci * scheduler is not tracking what's happening).
3408c2ecf20Sopenharmony_ci * Bit fields:
3418c2ecf20Sopenharmony_ci * 31-16:  Write mask -- 1: update empty bit, 0: don't change empty bit
3428c2ecf20Sopenharmony_ci * 15-00:  Empty state, one for each queue -- 1: empty, 0: non-empty
3438c2ecf20Sopenharmony_ci * NOTE:  This register is not used by Linux driver.
3448c2ecf20Sopenharmony_ci */
3458c2ecf20Sopenharmony_ci#define IL49_SCD_EMPTY_BITS               (IL49_SCD_START_OFFSET + 0x4)
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci/*
3488c2ecf20Sopenharmony_ci * Physical base address of array of byte count (BC) circular buffers (CBs).
3498c2ecf20Sopenharmony_ci * Each Tx queue has a BC CB in host DRAM to support Scheduler-ACK mode.
3508c2ecf20Sopenharmony_ci * This register points to BC CB for queue 0, must be on 1024-byte boundary.
3518c2ecf20Sopenharmony_ci * Others are spaced by 1024 bytes.
3528c2ecf20Sopenharmony_ci * Each BC CB is 2 bytes * (256 + 64) = 740 bytes, followed by 384 bytes pad.
3538c2ecf20Sopenharmony_ci * (Index into a queue's BC CB) = (idx into queue's TFD CB) = (SSN & 0xff).
3548c2ecf20Sopenharmony_ci * Bit fields:
3558c2ecf20Sopenharmony_ci * 25-00:  Byte Count CB physical address [35:10], must be 1024-byte aligned.
3568c2ecf20Sopenharmony_ci */
3578c2ecf20Sopenharmony_ci#define IL49_SCD_DRAM_BASE_ADDR           (IL49_SCD_START_OFFSET + 0x10)
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci/*
3608c2ecf20Sopenharmony_ci * Enables any/all Tx DMA/FIFO channels.
3618c2ecf20Sopenharmony_ci * Scheduler generates requests for only the active channels.
3628c2ecf20Sopenharmony_ci * Set this to 0xff to enable all 8 channels (normal usage).
3638c2ecf20Sopenharmony_ci * Bit fields:
3648c2ecf20Sopenharmony_ci *  7- 0:  Enable (1), disable (0), one bit for each channel 0-7
3658c2ecf20Sopenharmony_ci */
3668c2ecf20Sopenharmony_ci#define IL49_SCD_TXFACT                   (IL49_SCD_START_OFFSET + 0x1c)
3678c2ecf20Sopenharmony_ci/*
3688c2ecf20Sopenharmony_ci * Queue (x) Write Pointers (idxes, really!), one for each Tx queue.
3698c2ecf20Sopenharmony_ci * Initialized and updated by driver as new TFDs are added to queue.
3708c2ecf20Sopenharmony_ci * NOTE:  If using Block Ack, idx must correspond to frame's
3718c2ecf20Sopenharmony_ci *        Start Sequence Number; idx = (SSN & 0xff)
3728c2ecf20Sopenharmony_ci * NOTE:  Alternative to HBUS_TARG_WRPTR, which is what Linux driver uses?
3738c2ecf20Sopenharmony_ci */
3748c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_WRPTR(x)  (IL49_SCD_START_OFFSET + 0x24 + (x) * 4)
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci/*
3778c2ecf20Sopenharmony_ci * Queue (x) Read Pointers (idxes, really!), one for each Tx queue.
3788c2ecf20Sopenharmony_ci * For FIFO mode, idx indicates next frame to transmit.
3798c2ecf20Sopenharmony_ci * For Scheduler-ACK mode, idx indicates first frame in Tx win.
3808c2ecf20Sopenharmony_ci * Initialized by driver, updated by scheduler.
3818c2ecf20Sopenharmony_ci */
3828c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_RDPTR(x)  (IL49_SCD_START_OFFSET + 0x64 + (x) * 4)
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ci/*
3858c2ecf20Sopenharmony_ci * Select which queues work in chain mode (1) vs. not (0).
3868c2ecf20Sopenharmony_ci * Use chain mode to build chains of aggregated frames.
3878c2ecf20Sopenharmony_ci * Bit fields:
3888c2ecf20Sopenharmony_ci * 31-16:  Reserved
3898c2ecf20Sopenharmony_ci * 15-00:  Mode, one bit for each queue -- 1: Chain mode, 0: one-at-a-time
3908c2ecf20Sopenharmony_ci * NOTE:  If driver sets up queue for chain mode, it should be also set up
3918c2ecf20Sopenharmony_ci *        Scheduler-ACK mode as well, via SCD_QUEUE_STATUS_BITS(x).
3928c2ecf20Sopenharmony_ci */
3938c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUECHAIN_SEL  (IL49_SCD_START_OFFSET + 0xd0)
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_ci/*
3968c2ecf20Sopenharmony_ci * Select which queues interrupt driver when scheduler increments
3978c2ecf20Sopenharmony_ci * a queue's read pointer (idx).
3988c2ecf20Sopenharmony_ci * Bit fields:
3998c2ecf20Sopenharmony_ci * 31-16:  Reserved
4008c2ecf20Sopenharmony_ci * 15-00:  Interrupt enable, one bit for each queue -- 1: enabled, 0: disabled
4018c2ecf20Sopenharmony_ci * NOTE:  This functionality is apparently a no-op; driver relies on interrupts
4028c2ecf20Sopenharmony_ci *        from Rx queue to read Tx command responses and update Tx queues.
4038c2ecf20Sopenharmony_ci */
4048c2ecf20Sopenharmony_ci#define IL49_SCD_INTERRUPT_MASK  (IL49_SCD_START_OFFSET + 0xe4)
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci/*
4078c2ecf20Sopenharmony_ci * Queue search status registers.  One for each queue.
4088c2ecf20Sopenharmony_ci * Sets up queue mode and assigns queue to Tx DMA channel.
4098c2ecf20Sopenharmony_ci * Bit fields:
4108c2ecf20Sopenharmony_ci * 19-10: Write mask/enable bits for bits 0-9
4118c2ecf20Sopenharmony_ci *     9: Driver should init to "0"
4128c2ecf20Sopenharmony_ci *     8: Scheduler-ACK mode (1), non-Scheduler-ACK (i.e. FIFO) mode (0).
4138c2ecf20Sopenharmony_ci *        Driver should init to "1" for aggregation mode, or "0" otherwise.
4148c2ecf20Sopenharmony_ci *   7-6: Driver should init to "0"
4158c2ecf20Sopenharmony_ci *     5: Window Size Left; indicates whether scheduler can request
4168c2ecf20Sopenharmony_ci *        another TFD, based on win size, etc.  Driver should init
4178c2ecf20Sopenharmony_ci *        this bit to "1" for aggregation mode, or "0" for non-agg.
4188c2ecf20Sopenharmony_ci *   4-1: Tx FIFO to use (range 0-7).
4198c2ecf20Sopenharmony_ci *     0: Queue is active (1), not active (0).
4208c2ecf20Sopenharmony_ci * Other bits should be written as "0"
4218c2ecf20Sopenharmony_ci *
4228c2ecf20Sopenharmony_ci * NOTE:  If enabling Scheduler-ACK mode, chain mode should also be enabled
4238c2ecf20Sopenharmony_ci *        via SCD_QUEUECHAIN_SEL.
4248c2ecf20Sopenharmony_ci */
4258c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_STATUS_BITS(x)\
4268c2ecf20Sopenharmony_ci	(IL49_SCD_START_OFFSET + 0x104 + (x) * 4)
4278c2ecf20Sopenharmony_ci
4288c2ecf20Sopenharmony_ci/* Bit field positions */
4298c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_STTS_REG_POS_ACTIVE	(0)
4308c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_STTS_REG_POS_TXF	(1)
4318c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_STTS_REG_POS_WSL	(5)
4328c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK	(8)
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_ci/* Write masks */
4358c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN	(10)
4368c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_STTS_REG_MSK		(0x0007FC00)
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci/**
4398c2ecf20Sopenharmony_ci * 4965 internal SRAM structures for scheduler, shared with driver ...
4408c2ecf20Sopenharmony_ci *
4418c2ecf20Sopenharmony_ci * Driver should clear and initialize the following areas after receiving
4428c2ecf20Sopenharmony_ci * "Alive" response from 4965 uCode, i.e. after initial
4438c2ecf20Sopenharmony_ci * uCode load, or after a uCode load done for error recovery:
4448c2ecf20Sopenharmony_ci *
4458c2ecf20Sopenharmony_ci * SCD_CONTEXT_DATA_OFFSET (size 128 bytes)
4468c2ecf20Sopenharmony_ci * SCD_TX_STTS_BITMAP_OFFSET (size 256 bytes)
4478c2ecf20Sopenharmony_ci * SCD_TRANSLATE_TBL_OFFSET (size 32 bytes)
4488c2ecf20Sopenharmony_ci *
4498c2ecf20Sopenharmony_ci * Driver accesses SRAM via HBUS_TARG_MEM_* registers.
4508c2ecf20Sopenharmony_ci * Driver reads base address of this scheduler area from SCD_SRAM_BASE_ADDR.
4518c2ecf20Sopenharmony_ci * All OFFSET values must be added to this base address.
4528c2ecf20Sopenharmony_ci */
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci/*
4558c2ecf20Sopenharmony_ci * Queue context.  One 8-byte entry for each of 16 queues.
4568c2ecf20Sopenharmony_ci *
4578c2ecf20Sopenharmony_ci * Driver should clear this entire area (size 0x80) to 0 after receiving
4588c2ecf20Sopenharmony_ci * "Alive" notification from uCode.  Additionally, driver should init
4598c2ecf20Sopenharmony_ci * each queue's entry as follows:
4608c2ecf20Sopenharmony_ci *
4618c2ecf20Sopenharmony_ci * LS Dword bit fields:
4628c2ecf20Sopenharmony_ci *  0-06:  Max Tx win size for Scheduler-ACK.  Driver should init to 64.
4638c2ecf20Sopenharmony_ci *
4648c2ecf20Sopenharmony_ci * MS Dword bit fields:
4658c2ecf20Sopenharmony_ci * 16-22:  Frame limit.  Driver should init to 10 (0xa).
4668c2ecf20Sopenharmony_ci *
4678c2ecf20Sopenharmony_ci * Driver should init all other bits to 0.
4688c2ecf20Sopenharmony_ci *
4698c2ecf20Sopenharmony_ci * Init must be done after driver receives "Alive" response from 4965 uCode,
4708c2ecf20Sopenharmony_ci * and when setting up queue for aggregation.
4718c2ecf20Sopenharmony_ci */
4728c2ecf20Sopenharmony_ci#define IL49_SCD_CONTEXT_DATA_OFFSET			0x380
4738c2ecf20Sopenharmony_ci#define IL49_SCD_CONTEXT_QUEUE_OFFSET(x) \
4748c2ecf20Sopenharmony_ci			(IL49_SCD_CONTEXT_DATA_OFFSET + ((x) * 8))
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS		(0)
4778c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK		(0x0000007F)
4788c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS	(16)
4798c2ecf20Sopenharmony_ci#define IL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK	(0x007F0000)
4808c2ecf20Sopenharmony_ci
4818c2ecf20Sopenharmony_ci/*
4828c2ecf20Sopenharmony_ci * Tx Status Bitmap
4838c2ecf20Sopenharmony_ci *
4848c2ecf20Sopenharmony_ci * Driver should clear this entire area (size 0x100) to 0 after receiving
4858c2ecf20Sopenharmony_ci * "Alive" notification from uCode.  Area is used only by device itself;
4868c2ecf20Sopenharmony_ci * no other support (besides clearing) is required from driver.
4878c2ecf20Sopenharmony_ci */
4888c2ecf20Sopenharmony_ci#define IL49_SCD_TX_STTS_BITMAP_OFFSET		0x400
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_ci/*
4918c2ecf20Sopenharmony_ci * RAxTID to queue translation mapping.
4928c2ecf20Sopenharmony_ci *
4938c2ecf20Sopenharmony_ci * When queue is in Scheduler-ACK mode, frames placed in a that queue must be
4948c2ecf20Sopenharmony_ci * for only one combination of receiver address (RA) and traffic ID (TID), i.e.
4958c2ecf20Sopenharmony_ci * one QOS priority level destined for one station (for this wireless link,
4968c2ecf20Sopenharmony_ci * not final destination).  The SCD_TRANSLATE_TBL area provides 16 16-bit
4978c2ecf20Sopenharmony_ci * mappings, one for each of the 16 queues.  If queue is not in Scheduler-ACK
4988c2ecf20Sopenharmony_ci * mode, the device ignores the mapping value.
4998c2ecf20Sopenharmony_ci *
5008c2ecf20Sopenharmony_ci * Bit fields, for each 16-bit map:
5018c2ecf20Sopenharmony_ci * 15-9:  Reserved, set to 0
5028c2ecf20Sopenharmony_ci *  8-4:  Index into device's station table for recipient station
5038c2ecf20Sopenharmony_ci *  3-0:  Traffic ID (tid), range 0-15
5048c2ecf20Sopenharmony_ci *
5058c2ecf20Sopenharmony_ci * Driver should clear this entire area (size 32 bytes) to 0 after receiving
5068c2ecf20Sopenharmony_ci * "Alive" notification from uCode.  To update a 16-bit map value, driver
5078c2ecf20Sopenharmony_ci * must read a dword-aligned value from device SRAM, replace the 16-bit map
5088c2ecf20Sopenharmony_ci * value of interest, and write the dword value back into device SRAM.
5098c2ecf20Sopenharmony_ci */
5108c2ecf20Sopenharmony_ci#define IL49_SCD_TRANSLATE_TBL_OFFSET		0x500
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ci/* Find translation table dword to read/write for given queue */
5138c2ecf20Sopenharmony_ci#define IL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \
5148c2ecf20Sopenharmony_ci	((IL49_SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffffffc)
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ci#define IL_SCD_TXFIFO_POS_TID			(0)
5178c2ecf20Sopenharmony_ci#define IL_SCD_TXFIFO_POS_RA			(4)
5188c2ecf20Sopenharmony_ci#define IL_SCD_QUEUE_RA_TID_MAP_RATID_MSK	(0x01FF)
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_ci/*********************** END TX SCHEDULER *************************************/
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci#endif /* __il_prph_h__ */
523