iwk.c revision e29eff43297ff00f74f3111c6d2b040e444d7aea
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Copyright (c) 2007, Intel Corporation
* All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
*/
#include <sys/byteorder.h>
#include <sys/ethernet.h>
#include <sys/mac_wifi.h>
#include <sys/net80211.h>
#include <sys/net80211_proto.h>
#include "iwk_hw.h"
#include "iwk_eeprom.h"
#include "iwk_var.h"
#include <inet/wifi_ioctl.h>
#ifdef DEBUG
#define IWK_DEBUG_80211 (1 << 0)
uint32_t iwk_dbg_flags = 0;
#define IWK_DBG(x) \
iwk_dbg x
#else
#define IWK_DBG(x)
#endif
static void *iwk_soft_state_p = NULL;
static uint8_t iwk_fw_bin [] = {
#include "fw-iw/iw4965.ucode.hex"
};
/* DMA attributes for a shared page */
static ddi_dma_attr_t sh_dma_attr = {
DMA_ATTR_V0, /* version of this structure */
0, /* lowest usable address */
0xffffffffU, /* highest usable address */
0xffffffffU, /* maximum DMAable byte count */
0x1000, /* alignment in bytes */
0x1000, /* burst sizes (any?) */
1, /* minimum transfer */
0xffffffffU, /* maximum transfer */
0xffffffffU, /* maximum segment length */
1, /* maximum number of segments */
1, /* granularity */
0, /* flags (reserved) */
};
/* DMA attributes for a keep warm DRAM descriptor */
static ddi_dma_attr_t kw_dma_attr = {
DMA_ATTR_V0, /* version of this structure */
0, /* lowest usable address */
0xffffffffU, /* highest usable address */
0xffffffffU, /* maximum DMAable byte count */
0x1000, /* alignment in bytes */
0x1000, /* burst sizes (any?) */
1, /* minimum transfer */
0xffffffffU, /* maximum transfer */
0xffffffffU, /* maximum segment length */
1, /* maximum number of segments */
1, /* granularity */
0, /* flags (reserved) */
};
/* DMA attributes for a ring descriptor */
static ddi_dma_attr_t ring_desc_dma_attr = {
DMA_ATTR_V0, /* version of this structure */
0, /* lowest usable address */
0xffffffffU, /* highest usable address */
0xffffffffU, /* maximum DMAable byte count */
0x100, /* alignment in bytes */
0x100, /* burst sizes (any?) */
1, /* minimum transfer */
0xffffffffU, /* maximum transfer */
0xffffffffU, /* maximum segment length */
1, /* maximum number of segments */
1, /* granularity */
0, /* flags (reserved) */
};
/* DMA attributes for a cmd */
static ddi_dma_attr_t cmd_dma_attr = {
DMA_ATTR_V0, /* version of this structure */
0, /* lowest usable address */
0xffffffffU, /* highest usable address */
0xffffffffU, /* maximum DMAable byte count */
4, /* alignment in bytes */
0x100, /* burst sizes (any?) */
1, /* minimum transfer */
0xffffffffU, /* maximum transfer */
0xffffffffU, /* maximum segment length */
1, /* maximum number of segments */
1, /* granularity */
0, /* flags (reserved) */
};
/* DMA attributes for a rx buffer */
static ddi_dma_attr_t rx_buffer_dma_attr = {
DMA_ATTR_V0, /* version of this structure */
0, /* lowest usable address */
0xffffffffU, /* highest usable address */
0xffffffffU, /* maximum DMAable byte count */
0x100, /* alignment in bytes */
0x100, /* burst sizes (any?) */
1, /* minimum transfer */
0xffffffffU, /* maximum transfer */
0xffffffffU, /* maximum segment length */
1, /* maximum number of segments */
1, /* granularity */
0, /* flags (reserved) */
};
/*
* DMA attributes for a tx buffer.
* the maximum number of segments is 4 for the hardware.
* now all the wifi drivers put the whole frame in a single
* descriptor, so we define the maximum number of segments 1,
* just the same as the rx_buffer. we consider leverage the HW
* ability in the future, that is why we don't define rx and tx
* buffer_dma_attr as the same.
*/
static ddi_dma_attr_t tx_buffer_dma_attr = {
DMA_ATTR_V0, /* version of this structure */
0, /* lowest usable address */
0xffffffffU, /* highest usable address */
0xffffffffU, /* maximum DMAable byte count */
4, /* alignment in bytes */
0x100, /* burst sizes (any?) */
1, /* minimum transfer */
0xffffffffU, /* maximum transfer */
0xffffffffU, /* maximum segment length */
1, /* maximum number of segments */
1, /* granularity */
0, /* flags (reserved) */
};
/* DMA attributes for text and data part in the firmware */
static ddi_dma_attr_t fw_dma_attr = {
DMA_ATTR_V0, /* version of this structure */
0, /* lowest usable address */
0xffffffffU, /* highest usable address */
0x7fffffff, /* maximum DMAable byte count */
0x10, /* alignment in bytes */
0x100, /* burst sizes (any?) */
1, /* minimum transfer */
0xffffffffU, /* maximum transfer */
0xffffffffU, /* maximum segment length */
1, /* maximum number of segments */
1, /* granularity */
0, /* flags (reserved) */
};
/* regs access attributes */
static ddi_device_acc_attr_t iwk_reg_accattr = {
};
/* DMA access attributes */
static ddi_device_acc_attr_t iwk_dma_accattr = {
};
static int iwk_ring_init(iwk_sc_t *);
static void iwk_ring_free(iwk_sc_t *);
static int iwk_alloc_shared(iwk_sc_t *);
static void iwk_free_shared(iwk_sc_t *);
static int iwk_alloc_kw(iwk_sc_t *);
static void iwk_free_kw(iwk_sc_t *);
static int iwk_alloc_fw_dma(iwk_sc_t *);
static void iwk_free_fw_dma(iwk_sc_t *);
static int iwk_alloc_rx_ring(iwk_sc_t *);
static void iwk_reset_rx_ring(iwk_sc_t *);
static void iwk_free_rx_ring(iwk_sc_t *);
int, int);
static void iwk_mac_access_enter(iwk_sc_t *);
static void iwk_mac_access_exit(iwk_sc_t *);
uint32_t *, int);
static int iwk_load_firmware(iwk_sc_t *);
iwk_rx_data_t *);
iwk_rx_data_t *);
static uint8_t iwk_rate_to_plcp(int);
static int iwk_hw_set_before_auth(iwk_sc_t *);
static int iwk_config(iwk_sc_t *);
static void iwk_stop_master(iwk_sc_t *);
static int iwk_power_up(iwk_sc_t *);
static int iwk_preinit(iwk_sc_t *);
/*
* GLD specific operations
*/
static int iwk_m_start(void *arg);
static void iwk_m_stop(void *arg);
/*
* Supported rates for 802.11b/g modes (in 500Kbps unit).
* 11a and 11n support will be added later.
*/
static const struct ieee80211_rateset iwk_rateset_11b =
{ 4, { 2, 4, 11, 22 } };
static const struct ieee80211_rateset iwk_rateset_11g =
{ 12, { 2, 4, 11, 22, 12, 18, 24, 36, 48, 72, 96, 108 } };
/*
* For mfthread only
*/
extern pri_t minclsyspri;
#define DRV_NAME_4965 "iwk"
/*
* Module Loading Data & Entry Points
*/
static struct modldrv iwk_modldrv = {
"Intel(R) 4965AGN driver(N)",
};
static struct modlinkage iwk_modlinkage = {
};
int
_init(void)
{
int status;
sizeof (iwk_sc_t), 1);
if (status != DDI_SUCCESS)
return (status);
if (status != DDI_SUCCESS) {
}
return (status);
}
int
_fini(void)
{
int status;
if (status == DDI_SUCCESS) {
}
return (status);
}
int
{
}
/*
* Mac Call Back entries
*/
NULL,
};
#ifdef DEBUG
void
{
if (flags & iwk_dbg_flags) {
}
}
#endif
/*
* device operations
*/
int
{
char strbuf[32];
wifi_data_t wd = { 0 };
if (cmd != DDI_ATTACH) {
err = DDI_FAILURE;
goto attach_fail1;
}
if (err != DDI_SUCCESS) {
"iwk_attach(): failed to allocate soft state\n");
goto attach_fail1;
}
if (err != DDI_SUCCESS) {
"iwk_attach(): failed to map config spaces regs\n");
goto attach_fail2;
}
/*
* Map operating registers
*/
if (err != DDI_SUCCESS) {
"iwk_attach(): failed to map device regs\n");
goto attach_fail2a;
}
/*
* Initialize mutexs and condvars
*/
if (err != DDI_SUCCESS) {
"iwk_attach(): failed to do ddi_get_iblock_cookie()\n");
goto attach_fail2b;
}
/*
* initialize the mfthread
*/
sc->sc_mf_thread_switch = 0;
/*
* Allocate shared page.
*/
if (err != DDI_SUCCESS) {
goto attach_fail3;
}
/*
* Allocate keep warm page.
*/
if (err != DDI_SUCCESS) {
goto attach_fail3a;
}
/*
* Do some necessary hardware initializations.
*/
if (err != DDI_SUCCESS) {
goto attach_fail4;
}
/* initialize EEPROM */
if (err != 0) {
goto attach_fail4;
}
goto attach_fail4;
}
if (err != DDI_SUCCESS) {
"failed to allocate and initialize ring\n");
goto attach_fail4;
}
if (err != DDI_SUCCESS) {
"failed to allocate firmware dma\n");
goto attach_fail5;
}
/*
* Initialize the wifi part, which will be used by
* generic layer
*/
/*
* use software WEP and TKIP, hardware CCMP;
*/
/*
*/
/* set supported .11b and .11g rates */
/* set supported .11b and .11g channels (1 through 14) */
for (i = 1; i <= 14; i++) {
}
/*
* init Wifi layer
*/
/*
* different instance has different WPA door
*/
/*
* Override 80211 default routines
*/
/*
* initialize default tx key
*/
ic->ic_def_txkey = 0;
if (err != DDI_SUCCESS) {
"iwk_attach(): failed to do ddi_add_softintr()\n");
goto attach_fail7;
}
/*
* Add the interrupt handler
*/
if (err != DDI_SUCCESS) {
"iwk_attach(): failed to do ddi_add_intr()\n");
goto attach_fail8;
}
/*
* Initialize pointer to device specific functions
*/
if (err != DDI_SUCCESS) {
"iwk_attach(): failed to do mac_alloc()\n");
goto attach_fail9;
}
/*
* Register the macp to mac
*/
if (err != DDI_SUCCESS) {
"iwk_attach(): failed to do mac_register()\n");
goto attach_fail9;
}
/*
* Create minor node of type DDI_NT_NET_WIFI
*/
if (err != DDI_SUCCESS)
"iwk_attach(): failed to do ddi_create_minor_node()\n");
/*
* Notify link is down now
*/
/*
* create the mf thread to handle the link status,
* recovery fatal error, etc.
*/
return (DDI_SUCCESS);
return (err);
}
int
{
int err;
if (cmd != DDI_DETACH)
return (DDI_FAILURE);
return (DDI_FAILURE);
/*
* Destroy the mf_thread
*/
sc->sc_mf_thread_switch = 0;
break;
}
DELAY(500000);
/*
* Unregiste from the MAC layer subsystem
*/
if (err != DDI_SUCCESS)
return (err);
/*
* detach ieee80211
*/
return (DDI_SUCCESS);
}
static void
{
}
/*
* Allocate an area of memory and a DMA handle for accessing it
*/
static int
{
int err;
/*
* Allocate handle
*/
if (err != DDI_SUCCESS) {
return (DDI_FAILURE);
}
/*
* Allocate memory
*/
if (err != DDI_SUCCESS) {
return (DDI_FAILURE);
}
/*
* Bind the two together
*/
if (err != DDI_DMA_MAPPED) {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/*
* Free one allocated area of DMAable memory
*/
static void
{
}
}
}
}
/*
*
*/
static int
{
int err = DDI_SUCCESS;
char *t;
/*
* firmware image layout:
* |HDR|<-TEXT->|<-DATA->|<-INIT_TEXT->|<-INIT_DATA->|<-BOOT->|
*/
&sc->sc_dma_fw_text);
if (err != DDI_SUCCESS) {
" text dma memory");
goto fail;
}
&sc->sc_dma_fw_data);
if (err != DDI_SUCCESS) {
" data dma memory");
goto fail;
}
&sc->sc_dma_fw_data_bak);
"size:%lx]\n",
if (err != DDI_SUCCESS) {
" data bakeup dma memory");
goto fail;
}
"size:%lx]\n",
if (err != DDI_SUCCESS) {
"init text dma memory");
goto fail;
}
"size:%lx]\n",
if (err != DDI_SUCCESS) {
"init data dma memory");
goto fail;
}
fail:
return (err);
}
static void
{
}
/*
* Allocate a shared page between host and NIC.
*/
static int
{
int err = DDI_SUCCESS;
/* must be aligned on a 4K-page boundary */
if (err != DDI_SUCCESS)
goto fail;
return (err);
fail:
return (err);
}
static void
{
}
/*
* Allocate a keep warm page.
*/
static int
{
int err = DDI_SUCCESS;
/* must be aligned on a 4K-page boundary */
if (err != DDI_SUCCESS)
goto fail;
return (err);
fail:
return (err);
}
static void
{
}
static int
{
int i, err = DDI_SUCCESS;
if (err != DDI_SUCCESS) {
"failed\n"));
goto fail;
}
/*
* Allocate Rx buffers.
*/
for (i = 0; i < RX_QUEUE_SIZE; i++) {
if (err != DDI_SUCCESS) {
"buf[%d] failed\n", i));
goto fail;
}
/*
* the physical address bit [8-36] are used,
* instead of bit [0-31] in 3945.
*/
}
"size:%lx]\n",
return (err);
fail:
return (err);
}
static void
{
int n;
for (n = 0; n < 2000; n++) {
break;
DELAY(1000);
}
#ifdef DEBUG
if (n == 2000)
#endif
}
static void
{
int i;
for (i = 0; i < RX_QUEUE_SIZE; i++) {
}
}
static int
{
int i, err = DDI_SUCCESS;
TFD_QUEUE_SIZE_MAX * sizeof (iwk_tx_desc_t),
if (err != DDI_SUCCESS) {
" failed\n", qid));
goto fail;
}
TFD_QUEUE_SIZE_MAX * sizeof (iwk_cmd_t),
if (err != DDI_SUCCESS) {
" failed\n", qid));
goto fail;
}
/*
* Allocate Tx buffers.
*/
"tx data slots\n"));
goto fail;
}
for (i = 0; i < TFD_QUEUE_SIZE_MAX; i++) {
if (err != DDI_SUCCESS) {
"ring buf[%d] failed\n", i));
goto fail;
}
/* ((i % slots) * sizeof (iwk_cmd_t)); */
}
"size:%lx]\n",
return (err);
fail:
sizeof (iwk_tx_data_t) * TFD_QUEUE_SIZE_MAX);
return (err);
}
static void
{
int i, n;
for (n = 0; n < 200; n++) {
break;
DELAY(10);
}
#ifdef DEBUG
if (n == 200 && iwk_dbg_flags > 0) {
}
#endif
}
}
/*ARGSUSED*/
static void
{
int i;
}
}
}
static int
{
int i, err = DDI_SUCCESS;
for (i = 0; i < IWK_NUM_QUEUES; i++) {
if (i == IWK_CMD_QUEUE_NUM)
continue;
i);
if (err != DDI_SUCCESS)
goto fail;
}
if (err != DDI_SUCCESS)
goto fail;
if (err != DDI_SUCCESS)
goto fail;
return (err);
fail:
return (err);
}
static void
{
int i = IWK_NUM_QUEUES;
while (--i >= 0) {
}
}
/*ARGSUSED*/
static int
{
int i, err = IWK_SUCCESS;
switch (nstate) {
case IEEE80211_S_SCAN:
if (ostate == IEEE80211_S_INIT) {
/* let LED blink when scanning */
"could not initiate scan\n"));
return (err);
}
}
return (IWK_SUCCESS);
case IEEE80211_S_AUTH:
/* reset state to handle reassociations correctly */
/*
* before sending authentication and association request frame,
* we need do something in the hardware, such as setting the
* channel same to the target AP...
*/
"could not send authentication request\n"));
return (err);
}
break;
case IEEE80211_S_RUN:
/* let LED blink when monitoring */
break;
}
(void) iwk_hw_set_before_auth(sc);
/* need setup beacon here */
}
/* update adapter's configuration */
" filter_flags %x\n",
sizeof (iwk_rxon_cmd_t), 1);
if (err != IWK_SUCCESS) {
"could not update configuration\n"));
return (err);
}
/*
* set Tx power for 2.4GHz channels
* (need further investigation. fix tx power at present)
* This cmd should be issued each time the reply_rxon cmd is
* invoked.
*/
for (i = 0; i < POWER_TABLE_NUM_HT_OFDM_ENTRIES; i++) {
0x3f3f;
110 | (110 << 8);
}
.s.ramon_tx_gain = 0x3f3f;
sizeof (txpower), 1);
if (err != IWK_SUCCESS) {
"set txpower\n");
return (err);
}
/* set LED on after associated */
break;
case IEEE80211_S_INIT:
/* set LED off after init */
break;
case IEEE80211_S_ASSOC:
break;
}
}
/*ARGSUSED*/
{
int err;
case IEEE80211_CIPHER_WEP:
case IEEE80211_CIPHER_TKIP:
return (1); /* sofeware do it. */
case IEEE80211_CIPHER_AES_CCM:
break;
default:
return (0);
}
if (IEEE80211_IS_MULTICAST(mac)) {
} else {
}
if (k->wk_flags & IEEE80211_KEY_XMIT) {
} else {
}
if (err != IWK_SUCCESS) {
"failed to update ap node\n");
return (0);
}
return (1);
}
/*
* exclusive access to mac begin.
*/
static void
{
int n;
/* wait until we succeed */
for (n = 0; n < 1000; n++) {
break;
DELAY(10);
}
if (n == 1000)
}
/*
* exclusive access to mac end.
*/
static void
{
}
/*
* this function defined here for future use.
* static uint32_t
* iwk_mem_read(iwk_sc_t *sc, uint32_t addr)
* {
* IWK_WRITE(sc, HBUS_TARG_MEM_RADDR, addr);
* return (IWK_READ(sc, HBUS_TARG_MEM_RDAT));
* }
*/
static void
{
}
static uint32_t
{
}
static void
{
}
static void
{
}
/*
* ucode load/initialization steps:
* 1) load Bootstrap State Machine (BSM) with "bootstrap" uCode image.
* BSM contains a small memory that *always* stays powered up, so it can
* retain the bootstrap program even when the card is in a power-saving
* power-down state. The BSM loads the small program into ARC processor's
* instruction memory when triggered by power-up.
* 2) load Initialize image via bootstrap program.
* The Initialize image sets up regulatory and calibration data for the
* The 4965 reply contains calibration data for temperature, voltage and tx gain
* correction.
*/
static int
{
int n, err = IWK_SUCCESS;
/*
* The physical address bit [4-35] of the initialize uCode.
* In the initialize alive notify interrupt the physical address of
* the runtime ucode will be set for loading.
*/
/* load bootstrap code into BSM memory */
/*
* prepare to load initialize uCode
*/
/* wait while the adapter is busy loading the firmware */
for (n = 0; n < 1000; n++) {
break;
DELAY(10);
}
if (n == 1000) {
"timeout transferring firmware\n"));
return (err);
}
/* for future power-save mode use */
return (err);
}
/*ARGSUSED*/
static void
{
struct ieee80211_frame *wh;
int16_t t;
struct iwk_rx_non_cfg_phy *phyinfo;
/* assuming not 11n here. cope with 11n in phase-II */
return;
}
mrssi = 0;
for (i = 0; i < 3; i++) {
if (ants & (1 << i))
}
/*
* convert dBm to percentage ???
*/
/ (75 * 75);
if (rssi > 100)
rssi = 100;
if (rssi < 1)
rssi = 1;
"rate=%x chan=%d tstamp=%x non_cfg_phy_count=%x "
return;
}
/*
* discard Rx frames with bad CRC
*/
return;
}
wh = (struct ieee80211_frame *)
sc->sc_assoc_id));
}
#ifdef DEBUG
if (iwk_dbg_flags & IWK_DEBUG_RX)
#endif
if (mp) {
/* send the frame to the 802.11 layer */
} else {
sc->sc_rx_nobuf++;
"iwk_rx_intr(): alloc rx buf failed\n"));
}
/* release node reference */
}
/*ARGSUSED*/
static void
{
" retries=%d frame_count=%x nkill=%d "
"rate=%x duration=%d status=%x\n",
sc->sc_tx_retries++;
sc->sc_tx_retries));
}
sc->sc_tx_timer = 0;
sc->sc_need_reschedule = 0;
}
}
static void
{
return;
}
"qid=%x idx=%d flags=%x type=0x%x\n",
}
static void
{
struct iwk_alive_resp *ar =
/* the microcontroller is ready */
"microcode alive notification minor: %x major: %x type:"
" %x subtype: %x\n",
"microcontroller initialization failed\n"));
}
"initialization alive received.\n"));
sizeof (struct iwk_init_alive_resp));
/* XXX get temperature */
} else {
sizeof (struct iwk_alive_resp));
/*
* Init SCD related registers to make Tx work. XXX
*/
/* read sram address of data base */
/* clear and init SCD_CONTEXT_DATA_OFFSET area. 128 bytes */
i < 128; i += 4)
/* clear and init SCD_TX_STTS_BITMAP_OFFSET area. 256 bytes */
i < 256; i += 4)
/* clear and init SCD_TRANSLATE_TBL_OFFSET area. 32 bytes */
/* initiate the tx queues */
for (i = 0; i < IWK_NUM_QUEUES; i++) {
(SCD_WIN_SIZE & 0x7f));
SCD_CONTEXT_QUEUE_OFFSET(i) + sizeof (uint32_t),
}
/* interrupt enable on each queue0-7 */
/* enable each channel 0-7 */
SCD_TXFACT_REG_TXFIFO_MASK(0, 7));
/*
* queue 0-7 maps to FIFO 0-7 and
* all queues work under FIFO mode (none-scheduler-ack)
*/
for (i = 0; i < 7; i++) {
(1 << SCD_QUEUE_STTS_REG_POS_ACTIVE)|
(i << SCD_QUEUE_STTS_REG_POS_TXF)|
}
}
}
static uint_t
{
return (DDI_INTR_UNCLAIMED);
}
/* disable interrupts */
/*
* firmware has moved the index of the rx queue, driver get it,
* and deal with it.
*/
" cur = %d qid=%x idx=%d flags=%x type=%x len=%d\n",
/* a command other than a tx need to be replied */
case REPLY_4965_RX:
break;
case REPLY_TX:
break;
case REPLY_ALIVE:
break;
case CARD_STATE_NOTIFICATION:
{
/* the radio button has to be pushed */
"iwk: Radio transmitter is off\n");
}
break;
}
case SCAN_START_NOTIFICATION:
{
"scanning channel %d status %x\n",
break;
}
break;
}
}
/*
* driver dealt with what reveived in rx queue and tell the information
* to the firmware.
*/
/* re-enable interrupts */
sc->sc_rx_softint_pending = 0;
return (DDI_INTR_CLAIMED);
}
static uint_t
{
if (r == 0 || r == 0xffffffff) {
return (DDI_INTR_UNCLAIMED);
}
/* disable interrupts */
/* ack interrupts */
return (DDI_INTR_CLAIMED);
}
if (r & (BIT_INT_SWERROR | BIT_INT_ERR)) {
return (DDI_INTR_CLAIMED);
}
if (r & BIT_INT_RF_KILL) {
}
if ((r & (BIT_INT_FH_RX | BIT_INT_SW_RX)) ||
(rfh & FH_INT_RX_MASK)) {
}
if (r & BIT_INT_ALIVE) {
}
/* re-enable interrupts */
return (DDI_INTR_CLAIMED);
}
static uint8_t
iwk_rate_to_plcp(int rate)
{
switch (rate) {
/* CCK rates */
case 2:
ret = 0xa;
break;
case 4:
ret = 0x14;
break;
case 11:
ret = 0x37;
break;
case 22:
ret = 0x6e;
break;
/* OFDM rates */
case 12:
ret = 0xd;
break;
case 18:
ret = 0xf;
break;
case 24:
ret = 0x5;
break;
case 36:
ret = 0x7;
break;
case 48:
ret = 0x9;
break;
case 72:
ret = 0xb;
break;
case 96:
ret = 0x1;
break;
case 108:
ret = 0x3;
break;
default:
ret = 0;
break;
}
return (ret);
}
static mblk_t *
{
return (NULL);
}
break;
}
}
return (mp);
}
/* ARGSUSED */
static int
{
struct ieee80211_frame *wh;
struct ieee80211_key *k = NULL;
if ((type & IEEE80211_FC0_TYPE_MASK) !=
}
sc->sc_tx_nobuf++;
goto exit;
}
hdrlen = sizeof (struct ieee80211_frame);
if (m == NULL) { /* can not alloc buf, drop this package */
"iwk_send(): failed to allocate msgbuf\n");
err = IWK_SUCCESS;
goto exit;
}
}
freemsg(m);
err = IWK_SUCCESS;
goto exit;
}
} else {
}
k = ieee80211_crypto_encap(ic, m);
if (k == NULL) {
freemsg(m);
err = IWK_SUCCESS;
goto exit;
}
}
/* packet header may have moved, reset our local pointer */
}
#ifdef DEBUG
if (iwk_dbg_flags & IWK_DEBUG_TX)
#endif
/* pickup a rate */
/* mgmt frames are sent at 1M */
} else {
/*
* do it later: rate scaling in hardware.
* maybe like the following, for management frame:
* tx->initial_rate_index = LINK_QUAL_MAX_RETRY_NUM - 1;
* for data frame:
* tx->tx_flags |= (LE_32(TX_CMD_FLG_STA_RATE_MSK));
* rate = in->in_rates.ir_rates[in->in_txrate];
* tx->initial_rate_index = 1;
*
* now the txrate is determined in tx cmd flags, set to the
* max value 54M for 11g and 11M for 11b.
*/
} else {
}
}
/* retrieve destination node's id */
} else {
}
/* tell h/w to set timestamp in probe responses */
else
} else
tx->dram_lsb_ptr =
tx->dram_msb_ptr = 0;
tx->driver_txop = 0;
tx->next_frame_len = 0;
/*
* first segment includes the tx cmd plus the 802.11 header,
* the second includes the remaining of the 802.11 frame.
*/
"len1 = 0x%x, len2 = 0x%x val1 = 0x%x val2 = 0x%x",
/* kick ring */
= 8 + len;
}
freemsg(m);
/* release node reference */
if (sc->sc_tx_timer == 0)
exit:
return (err);
}
static void
{
int err;
(void) ieee80211_new_state(ic,
IEEE80211_S_SCAN, -1);
}
}
/*ARGSUSED*/
static int
{
switch (stat) {
case MAC_STAT_IFSPEED:
break;
case MAC_STAT_NOXMTBUF:
break;
case MAC_STAT_NORCVBUF:
break;
case MAC_STAT_IERRORS:
break;
case MAC_STAT_RBYTES:
break;
case MAC_STAT_IPACKETS:
break;
case MAC_STAT_OBYTES:
break;
case MAC_STAT_OPACKETS:
break;
case MAC_STAT_OERRORS:
case WIFI_STAT_TX_FAILED:
break;
case WIFI_STAT_TX_RETRANS:
break;
case WIFI_STAT_FCS_ERRORS:
case WIFI_STAT_WEP_ERRORS:
case WIFI_STAT_TX_FRAGS:
case WIFI_STAT_MCAST_TX:
case WIFI_STAT_RTS_SUCCESS:
case WIFI_STAT_RTS_FAILURE:
case WIFI_STAT_ACK_FAILURE:
case WIFI_STAT_RX_FRAGS:
case WIFI_STAT_MCAST_RX:
case WIFI_STAT_RX_DUPS:
default:
return (ENOTSUP);
}
return (IWK_SUCCESS);
}
static int
iwk_m_start(void *arg)
{
int err;
if (err != IWK_SUCCESS) {
return (err);
}
return (err);
}
static void
iwk_m_stop(void *arg)
{
}
/*ARGSUSED*/
static int
{
int err;
if (err != IWK_SUCCESS) {
"iwk_m_unicst(): "
"failed to configure device\n");
goto fail;
}
}
return (IWK_SUCCESS);
fail:
return (err);
}
/*ARGSUSED*/
static int
{
return (IWK_SUCCESS);
}
/*ARGSUSED*/
static int
{
return (IWK_SUCCESS);
}
static void
{
while (sc->sc_mf_thread_switch) {
/*
* recovery fatal error
*/
"iwk_thread(): "
"try to recover fatal hw error: %d\n", times++));
if (err != IWK_SUCCESS) {
n++;
if (n < 20)
continue;
}
n = 0;
}
if (sc->sc_tx_timer) {
timeout++;
if (timeout == 10) {
sc->sc_tx_timer--;
if (sc->sc_tx_timer == 0) {
"iwk_thread(): try to recover from"
" 'send fail\n"));
}
timeout = 0;
}
}
}
}
/*
* Send a command to the firmware.
*/
static int
{
/* kick cmd ring XXX */
}
if (async)
return (IWK_SUCCESS);
else {
< 0)
break;
}
return (IWK_SUCCESS);
else
return (IWK_FAIL);
}
}
static void
{
}
static int
{
struct ieee80211_rateset rs;
int i, err;
/* update adapter's configuration according the info of target AP */
} else { /* assume 802.11b/g */
}
else
else
"filter_flags %x cck %x ofdm %x"
" bssid:%02x:%02x:%02x:%02x:%02x:%2x\n",
sizeof (iwk_rxon_cmd_t), 1);
if (err != IWK_SUCCESS) {
" failed to config chan%d\n",
return (err);
}
/*
* set Tx power for 2.4GHz channels
* (need further investigation. fix tx power at present)
*/
for (i = 0; i < POWER_TABLE_NUM_HT_OFDM_ENTRIES; i++) {
.ramon_tx_gain = 0x3f3f;
}
s.ramon_tx_gain = 0x3f3f;
sizeof (txpower), 1);
if (err != IWK_SUCCESS) {
" failed to set txpower\n");
return (err);
}
/* add default AP node */
if (err != IWK_SUCCESS) {
" failed to add BSS node\n");
return (err);
}
/* TX_LINK_QUALITY cmd ? */
for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
else
rate = 2;
masks &= ~RATE_MCS_ANT_A_MSK;
link_quality.rate_n_flags[i] =
}
sizeof (link_quality), 1);
if (err != IWK_SUCCESS) {
"failed to config link quality table\n");
return (err);
}
return (IWK_SUCCESS);
}
/*
* Send a scan request(assembly scan cmd) to the firmware.
*/
static int
{
struct ieee80211_frame *wh;
struct ieee80211_rateset *rs;
enum ieee80211_phymode mode;
(0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
(0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
if (ic->ic_des_esslen)
ic->ic_des_esslen);
else
/*
* a probe request frame is required after the REPLY_SCAN_CMD
*/
/* essid IE */
*frm++ = IEEE80211_ELEMID_SSID;
/* supported rates IE */
*frm++ = IEEE80211_ELEMID_RATES;
if (nrates > IEEE80211_RATE_SIZE)
/* supported xrates IE */
*frm++ = IEEE80211_ELEMID_XRATES;
}
/* optionnal IE (usually for wpa) */
}
/* setup length of probe request */
/*
* the attribute of the scan channels are required after the probe
* request frame.
*/
frm += sizeof (iwk_scan_chan_t);
}
/*
* maybe for cmd, filling the byte cnt table is not necessary.
* anyway, we fill it here.
*/
}
#if 0
#endif
/* kick cmd ring */
return (IWK_SUCCESS);
}
static int
{
int i, err;
/*
* set power mode. Disable power management at present, do it later
*/
sizeof (powertable), 0);
if (err != IWK_SUCCESS) {
return (err);
}
/* configure bt coexistence */
sizeof (bt), 0);
if (err != IWK_SUCCESS) {
"iwk_config(): "
"failed to configurate bt coexistence\n");
return (err);
}
/* configure rxon */
case IEEE80211_M_STA:
break;
case IEEE80211_M_IBSS:
case IEEE80211_M_AHDEMO:
break;
case IEEE80211_M_HOSTAP:
break;
case IEEE80211_M_MONITOR:
break;
}
/* set antenna */
(0x6 << RXON_RX_CHAIN_FORCE_SEL_POS) |
(0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS));
sizeof (iwk_rxon_cmd_t), 0);
if (err != IWK_SUCCESS) {
"failed to set configure command\n");
return (err);
}
/*
* set Tx power for 2.4GHz channels
* (need further investigation. fix tx power at present)
*/
for (i = 0; i < POWER_TABLE_NUM_HT_OFDM_ENTRIES; i++) {
.s.ramon_tx_gain = 0x3f3f;
}
.s.ramon_tx_gain = 0x3f3f;
sizeof (txpower), 0);
if (err != IWK_SUCCESS) {
return (err);
}
/* add broadcast node so that we can send broadcast frame */
if (err != IWK_SUCCESS) {
"failed to add broadcast node\n");
return (err);
}
/* TX_LINK_QUALITY cmd ? */
for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
masks &= ~RATE_MCS_ANT_A_MSK;
}
sizeof (link_quality), 0);
if (err != IWK_SUCCESS) {
"failed to config link quality table\n");
return (err);
}
return (IWK_SUCCESS);
}
static void
{
int n;
if ((tmp & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE) ==
return;
for (n = 0; n < 2000; n++) {
break;
DELAY(1000);
}
if (n == 2000)
"timeout waiting for master stop\n"));
}
static int
{
DELAY(5000);
return (IWK_SUCCESS);
}
static int
{
int n;
/* clear any pending interrupts */
/* wait for clock ready */
for (n = 0; n < 1000; n++) {
break;
DELAY(10);
}
if (n == 1000) {
return (ETIMEDOUT);
}
DELAY(20);
(void) iwk_power_up(sc);
}
vlink & ~2);
/* make sure power supply on each part of the hardware */
DELAY(5);
return (IWK_SUCCESS);
}
/*
* set up semphore flag to own EEPROM
*/
{
return (IWK_SUCCESS);
DELAY(10000);
}
}
return (IWK_FAIL);
}
/*
* reset semphore flag to release EEPROM
*/
{
tmp & (~CSR_HW_IF_CONFIG_REG_EEP_SEM));
}
/*
* This function load all infomation in eeprom into iwk_eep
* structure in iwk_sc_t structure
*/
{
int i, rr;
/* read eeprom gp register in CSR */
if ((eep_gp & CSR_EEPROM_GP_VALID_MSK) ==
return (IWK_FAIL);
}
if (rr != 0) {
return (IWK_FAIL);
}
for (i = 0; i < 10; i++) {
if (rv & 1)
break;
DELAY(10);
}
if (!(rv & 1)) {
"time out when read eeprome\n"));
return (IWK_FAIL);
}
}
return (IWK_SUCCESS);
}
/*
* init mac address in ieee80211com_t struct
*/
{
}
static int
{
(void) iwk_preinit(sc);
/* init Rx ring */
/* init Tx rings */
/* keep warn page */
}
/* clear "radio off" and "disable command" bits */
/* clear any pending interrupts */
/* enable interrupts */
/*
* backup ucode data part for future use.
*/
for (n = 0; n < 2; n++) {
/* load firmware init segment into NIC */
if (err != IWK_SUCCESS) {
"failed to setup boot firmware\n");
continue;
}
/* now press "execute" start running */
break;
}
if (n == 2) {
goto fail1;
}
/* ..and wait at most one second for adapter to initialize */
break;
}
"iwk_init(): timeout waiting for firmware init\n");
goto fail1;
}
/*
* at this point, the firmware is loaded OK, then config the hardware
* with the ucode API, including rxon, txpower, etc.
*/
if (err) {
goto fail1;
}
/* at this point, hardware may receive beacons :) */
return (IWK_SUCCESS);
return (err);
}
static void
{
int i;
/* disable interrupts */
/* reset all Tx rings */
for (i = 0; i < IWK_NUM_QUEUES; i++)
/* reset Rx ring */
DELAY(5);
sc->sc_tx_timer = 0;
}