2011-02-22 02:27:26 +07:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* Portions of this file are derived from the ipw3945 project, as well
|
|
|
|
* as portions of the ieee80211 subsystem header files.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
|
|
|
*
|
|
|
|
* The full GNU General Public License is included in this distribution in the
|
|
|
|
* file called LICENSE.
|
|
|
|
*
|
|
|
|
* Contact Information:
|
|
|
|
* Intel Linux Wireless <ilw@linux.intel.com>
|
|
|
|
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <net/mac80211.h>
|
|
|
|
#include "iwl-eeprom.h"
|
|
|
|
#include "iwl-dev.h"
|
|
|
|
#include "iwl-core.h"
|
|
|
|
#include "iwl-sta.h"
|
|
|
|
#include "iwl-io.h"
|
|
|
|
#include "iwl-helpers.h"
|
|
|
|
|
|
|
|
/**
|
2011-11-15 18:30:17 +07:00
|
|
|
* il_txq_update_write_ptr - Send new write idx to hardware
|
2011-02-22 02:27:26 +07:00
|
|
|
*/
|
|
|
|
void
|
2011-10-24 21:49:25 +07:00
|
|
|
il_txq_update_write_ptr(struct il_priv *il, struct il_tx_queue *txq)
|
2011-02-22 02:27:26 +07:00
|
|
|
{
|
|
|
|
u32 reg = 0;
|
|
|
|
int txq_id = txq->q.id;
|
|
|
|
|
|
|
|
if (txq->need_update == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* if we're trying to save power */
|
2011-10-24 21:49:25 +07:00
|
|
|
if (test_bit(STATUS_POWER_PMI, &il->status)) {
|
2011-02-22 02:27:26 +07:00
|
|
|
/* wake up nic if it's powered down ...
|
|
|
|
* uCode will wake up, and interrupt us again, so next
|
|
|
|
* time we'll skip this part. */
|
2011-08-24 20:14:03 +07:00
|
|
|
reg = _il_rd(il, CSR_UCODE_DRV_GP1);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
if (reg & CSR_UCODE_DRV_GP1_BIT_MAC_SLEEP) {
|
2011-11-15 17:21:01 +07:00
|
|
|
D_INFO(
|
2011-02-22 02:27:26 +07:00
|
|
|
"Tx queue %d requesting wakeup,"
|
|
|
|
" GP1 = 0x%x\n", txq_id, reg);
|
2011-10-24 21:49:25 +07:00
|
|
|
il_set_bit(il, CSR_GP_CNTRL,
|
2011-02-22 02:27:26 +07:00
|
|
|
CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-24 22:37:16 +07:00
|
|
|
il_wr(il, HBUS_TARG_WRPTR,
|
2011-02-22 02:27:26 +07:00
|
|
|
txq->q.write_ptr | (txq_id << 8));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* else not in power-save mode,
|
|
|
|
* uCode will never sleep when we're
|
|
|
|
* trying to tx (during RFKILL, we're not trying to tx).
|
|
|
|
*/
|
|
|
|
} else
|
2011-08-24 20:14:03 +07:00
|
|
|
_il_wr(il, HBUS_TARG_WRPTR,
|
2011-02-22 02:27:26 +07:00
|
|
|
txq->q.write_ptr | (txq_id << 8));
|
|
|
|
txq->need_update = 0;
|
|
|
|
}
|
2011-10-24 20:41:30 +07:00
|
|
|
EXPORT_SYMBOL(il_txq_update_write_ptr);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-02-28 20:33:14 +07:00
|
|
|
/**
|
2011-10-24 20:41:30 +07:00
|
|
|
* il_tx_queue_unmap - Unmap any remaining DMA mappings and free skb's
|
2011-02-28 20:33:14 +07:00
|
|
|
*/
|
2011-10-24 21:49:25 +07:00
|
|
|
void il_tx_queue_unmap(struct il_priv *il, int txq_id)
|
2011-02-28 20:33:14 +07:00
|
|
|
{
|
2011-10-24 21:49:25 +07:00
|
|
|
struct il_tx_queue *txq = &il->txq[txq_id];
|
2011-10-24 20:41:30 +07:00
|
|
|
struct il_queue *q = &txq->q;
|
2011-02-28 20:33:14 +07:00
|
|
|
|
|
|
|
if (q->n_bd == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (q->write_ptr != q->read_ptr) {
|
2011-10-24 21:49:25 +07:00
|
|
|
il->cfg->ops->lib->txq_free_tfd(il, txq);
|
2011-10-24 20:41:30 +07:00
|
|
|
q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd);
|
2011-02-28 20:33:14 +07:00
|
|
|
}
|
|
|
|
}
|
2011-10-24 20:41:30 +07:00
|
|
|
EXPORT_SYMBOL(il_tx_queue_unmap);
|
2011-02-28 20:33:14 +07:00
|
|
|
|
2011-02-22 02:27:26 +07:00
|
|
|
/**
|
2011-10-24 20:41:30 +07:00
|
|
|
* il_tx_queue_free - Deallocate DMA queue.
|
2011-02-22 02:27:26 +07:00
|
|
|
* @txq: Transmit queue to deallocate.
|
|
|
|
*
|
|
|
|
* Empty queue by removing and destroying all BD's.
|
|
|
|
* Free all buffers.
|
|
|
|
* 0-fill, but do not free "txq" descriptor structure.
|
|
|
|
*/
|
2011-10-24 21:49:25 +07:00
|
|
|
void il_tx_queue_free(struct il_priv *il, int txq_id)
|
2011-02-22 02:27:26 +07:00
|
|
|
{
|
2011-10-24 21:49:25 +07:00
|
|
|
struct il_tx_queue *txq = &il->txq[txq_id];
|
|
|
|
struct device *dev = &il->pci_dev->dev;
|
2011-02-22 02:27:26 +07:00
|
|
|
int i;
|
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
il_tx_queue_unmap(il, txq_id);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
/* De-alloc array of command/tx buffers */
|
|
|
|
for (i = 0; i < TFD_TX_CMD_SLOTS; i++)
|
|
|
|
kfree(txq->cmd[i]);
|
|
|
|
|
|
|
|
/* De-alloc circular buffer of TFDs */
|
|
|
|
if (txq->q.n_bd)
|
2011-10-24 21:49:25 +07:00
|
|
|
dma_free_coherent(dev, il->hw_params.tfd_size *
|
2011-02-22 02:27:26 +07:00
|
|
|
txq->q.n_bd, txq->tfds, txq->q.dma_addr);
|
|
|
|
|
|
|
|
/* De-alloc array of per-TFD driver data */
|
|
|
|
kfree(txq->txb);
|
|
|
|
txq->txb = NULL;
|
|
|
|
|
|
|
|
/* deallocate arrays */
|
|
|
|
kfree(txq->cmd);
|
|
|
|
kfree(txq->meta);
|
|
|
|
txq->cmd = NULL;
|
|
|
|
txq->meta = NULL;
|
|
|
|
|
|
|
|
/* 0-fill queue descriptor structure */
|
|
|
|
memset(txq, 0, sizeof(*txq));
|
|
|
|
}
|
2011-10-24 20:41:30 +07:00
|
|
|
EXPORT_SYMBOL(il_tx_queue_free);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
/**
|
2011-10-24 20:41:30 +07:00
|
|
|
* il_cmd_queue_unmap - Unmap any remaining DMA mappings from command queue
|
2011-02-22 02:27:26 +07:00
|
|
|
*/
|
2011-10-24 21:49:25 +07:00
|
|
|
void il_cmd_queue_unmap(struct il_priv *il)
|
2011-02-22 02:27:26 +07:00
|
|
|
{
|
2011-10-24 21:49:25 +07:00
|
|
|
struct il_tx_queue *txq = &il->txq[il->cmd_queue];
|
2011-10-24 20:41:30 +07:00
|
|
|
struct il_queue *q = &txq->q;
|
2011-02-28 20:33:14 +07:00
|
|
|
int i;
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
if (q->n_bd == 0)
|
|
|
|
return;
|
|
|
|
|
2011-02-28 20:33:14 +07:00
|
|
|
while (q->read_ptr != q->write_ptr) {
|
2011-11-15 18:30:17 +07:00
|
|
|
i = il_get_cmd_idx(q, q->read_ptr, 0);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-04-28 16:51:31 +07:00
|
|
|
if (txq->meta[i].flags & CMD_MAPPED) {
|
2011-10-24 21:49:25 +07:00
|
|
|
pci_unmap_single(il->pci_dev,
|
2011-02-28 20:33:14 +07:00
|
|
|
dma_unmap_addr(&txq->meta[i], mapping),
|
|
|
|
dma_unmap_len(&txq->meta[i], len),
|
|
|
|
PCI_DMA_BIDIRECTIONAL);
|
2011-04-28 16:51:31 +07:00
|
|
|
txq->meta[i].flags = 0;
|
|
|
|
}
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-10-24 20:41:30 +07:00
|
|
|
q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd);
|
2011-02-22 02:27:26 +07:00
|
|
|
}
|
2011-02-28 20:33:14 +07:00
|
|
|
|
2011-08-26 20:49:28 +07:00
|
|
|
i = q->n_win;
|
2011-04-28 16:51:31 +07:00
|
|
|
if (txq->meta[i].flags & CMD_MAPPED) {
|
2011-10-24 21:49:25 +07:00
|
|
|
pci_unmap_single(il->pci_dev,
|
2011-02-22 02:27:26 +07:00
|
|
|
dma_unmap_addr(&txq->meta[i], mapping),
|
|
|
|
dma_unmap_len(&txq->meta[i], len),
|
|
|
|
PCI_DMA_BIDIRECTIONAL);
|
2011-04-28 16:51:31 +07:00
|
|
|
txq->meta[i].flags = 0;
|
2011-02-22 02:27:26 +07:00
|
|
|
}
|
2011-02-28 20:33:14 +07:00
|
|
|
}
|
2011-10-24 20:41:30 +07:00
|
|
|
EXPORT_SYMBOL(il_cmd_queue_unmap);
|
2011-02-28 20:33:14 +07:00
|
|
|
|
|
|
|
/**
|
2011-10-24 20:41:30 +07:00
|
|
|
* il_cmd_queue_free - Deallocate DMA queue.
|
2011-02-28 20:33:14 +07:00
|
|
|
* @txq: Transmit queue to deallocate.
|
|
|
|
*
|
|
|
|
* Empty queue by removing and destroying all BD's.
|
|
|
|
* Free all buffers.
|
|
|
|
* 0-fill, but do not free "txq" descriptor structure.
|
|
|
|
*/
|
2011-10-24 21:49:25 +07:00
|
|
|
void il_cmd_queue_free(struct il_priv *il)
|
2011-02-28 20:33:14 +07:00
|
|
|
{
|
2011-10-24 21:49:25 +07:00
|
|
|
struct il_tx_queue *txq = &il->txq[il->cmd_queue];
|
|
|
|
struct device *dev = &il->pci_dev->dev;
|
2011-02-28 20:33:14 +07:00
|
|
|
int i;
|
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
il_cmd_queue_unmap(il);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
/* De-alloc array of command/tx buffers */
|
|
|
|
for (i = 0; i <= TFD_CMD_SLOTS; i++)
|
|
|
|
kfree(txq->cmd[i]);
|
|
|
|
|
|
|
|
/* De-alloc circular buffer of TFDs */
|
|
|
|
if (txq->q.n_bd)
|
2011-10-24 21:49:25 +07:00
|
|
|
dma_free_coherent(dev, il->hw_params.tfd_size * txq->q.n_bd,
|
2011-02-22 02:27:26 +07:00
|
|
|
txq->tfds, txq->q.dma_addr);
|
|
|
|
|
|
|
|
/* deallocate arrays */
|
|
|
|
kfree(txq->cmd);
|
|
|
|
kfree(txq->meta);
|
|
|
|
txq->cmd = NULL;
|
|
|
|
txq->meta = NULL;
|
|
|
|
|
|
|
|
/* 0-fill queue descriptor structure */
|
|
|
|
memset(txq, 0, sizeof(*txq));
|
|
|
|
}
|
2011-10-24 20:41:30 +07:00
|
|
|
EXPORT_SYMBOL(il_cmd_queue_free);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
/*************** DMA-QUEUE-GENERAL-FUNCTIONS *****
|
|
|
|
* DMA services
|
|
|
|
*
|
|
|
|
* Theory of operation
|
|
|
|
*
|
|
|
|
* A Tx or Rx queue resides in host DRAM, and is comprised of a circular buffer
|
|
|
|
* of buffer descriptors, each of which points to one or more data buffers for
|
|
|
|
* the device to read from or fill. Driver and device exchange status of each
|
|
|
|
* queue via "read" and "write" pointers. Driver keeps minimum of 2 empty
|
|
|
|
* entries in each circular buffer, to protect against confusing empty and full
|
|
|
|
* queue states.
|
|
|
|
*
|
|
|
|
* The device reads or writes the data in the queues via the device's several
|
|
|
|
* DMA/FIFO channels. Each queue is mapped to a single DMA channel.
|
|
|
|
*
|
|
|
|
* For Tx queue, there are low mark and high mark limits. If, after queuing
|
|
|
|
* the packet for Tx, free space become < low mark, Tx queue stopped. When
|
|
|
|
* reclaiming packets (on 'tx done IRQ), if free space become > high mark,
|
|
|
|
* Tx queue resumed.
|
|
|
|
*
|
|
|
|
* See more detailed info in iwl-4965-hw.h.
|
|
|
|
***************************************************/
|
|
|
|
|
2011-10-24 20:41:30 +07:00
|
|
|
int il_queue_space(const struct il_queue *q)
|
2011-02-22 02:27:26 +07:00
|
|
|
{
|
|
|
|
int s = q->read_ptr - q->write_ptr;
|
|
|
|
|
|
|
|
if (q->read_ptr > q->write_ptr)
|
|
|
|
s -= q->n_bd;
|
|
|
|
|
|
|
|
if (s <= 0)
|
2011-08-26 20:49:28 +07:00
|
|
|
s += q->n_win;
|
2011-02-22 02:27:26 +07:00
|
|
|
/* keep some reserve to not confuse empty and full situations */
|
|
|
|
s -= 2;
|
|
|
|
if (s < 0)
|
|
|
|
s = 0;
|
|
|
|
return s;
|
|
|
|
}
|
2011-10-24 20:41:30 +07:00
|
|
|
EXPORT_SYMBOL(il_queue_space);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2011-11-15 18:30:17 +07:00
|
|
|
* il_queue_init - Initialize queue's high/low-water and read/write idxes
|
2011-02-22 02:27:26 +07:00
|
|
|
*/
|
2011-10-24 21:49:25 +07:00
|
|
|
static int il_queue_init(struct il_priv *il, struct il_queue *q,
|
2011-02-22 02:27:26 +07:00
|
|
|
int count, int slots_num, u32 id)
|
|
|
|
{
|
|
|
|
q->n_bd = count;
|
2011-08-26 20:49:28 +07:00
|
|
|
q->n_win = slots_num;
|
2011-02-22 02:27:26 +07:00
|
|
|
q->id = id;
|
|
|
|
|
2011-10-24 20:41:30 +07:00
|
|
|
/* count must be power-of-two size, otherwise il_queue_inc_wrap
|
|
|
|
* and il_queue_dec_wrap are broken. */
|
2011-02-22 02:27:26 +07:00
|
|
|
BUG_ON(!is_power_of_2(count));
|
|
|
|
|
|
|
|
/* slots_num must be power-of-two size, otherwise
|
2011-11-15 18:30:17 +07:00
|
|
|
* il_get_cmd_idx is broken. */
|
2011-02-22 02:27:26 +07:00
|
|
|
BUG_ON(!is_power_of_2(slots_num));
|
|
|
|
|
2011-08-26 20:49:28 +07:00
|
|
|
q->low_mark = q->n_win / 4;
|
2011-02-22 02:27:26 +07:00
|
|
|
if (q->low_mark < 4)
|
|
|
|
q->low_mark = 4;
|
|
|
|
|
2011-08-26 20:49:28 +07:00
|
|
|
q->high_mark = q->n_win / 8;
|
2011-02-22 02:27:26 +07:00
|
|
|
if (q->high_mark < 2)
|
|
|
|
q->high_mark = 2;
|
|
|
|
|
|
|
|
q->write_ptr = q->read_ptr = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-24 20:41:30 +07:00
|
|
|
* il_tx_queue_alloc - Alloc driver data and TFD CB for one Tx/cmd queue
|
2011-02-22 02:27:26 +07:00
|
|
|
*/
|
2011-10-24 21:49:25 +07:00
|
|
|
static int il_tx_queue_alloc(struct il_priv *il,
|
2011-10-24 20:41:30 +07:00
|
|
|
struct il_tx_queue *txq, u32 id)
|
2011-02-22 02:27:26 +07:00
|
|
|
{
|
2011-10-24 21:49:25 +07:00
|
|
|
struct device *dev = &il->pci_dev->dev;
|
|
|
|
size_t tfd_sz = il->hw_params.tfd_size * TFD_QUEUE_SIZE_MAX;
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
/* Driver ilate data, only for Tx (not command) queues,
|
2011-02-22 02:27:26 +07:00
|
|
|
* not shared with device. */
|
2011-10-24 21:49:25 +07:00
|
|
|
if (id != il->cmd_queue) {
|
2011-02-22 02:27:26 +07:00
|
|
|
txq->txb = kzalloc(sizeof(txq->txb[0]) *
|
|
|
|
TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
|
|
|
|
if (!txq->txb) {
|
2011-08-19 03:07:57 +07:00
|
|
|
IL_ERR("kmalloc for auxiliary BD "
|
2011-02-22 02:27:26 +07:00
|
|
|
"structures failed\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
txq->txb = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Circular buffer of transmit frame descriptors (TFDs),
|
|
|
|
* shared with device */
|
|
|
|
txq->tfds = dma_alloc_coherent(dev, tfd_sz, &txq->q.dma_addr,
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!txq->tfds) {
|
2011-08-19 03:07:57 +07:00
|
|
|
IL_ERR("pci_alloc_consistent(%zd) failed\n", tfd_sz);
|
2011-02-22 02:27:26 +07:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
txq->q.id = id;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
error:
|
|
|
|
kfree(txq->txb);
|
|
|
|
txq->txb = NULL;
|
|
|
|
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-24 20:41:30 +07:00
|
|
|
* il_tx_queue_init - Allocate and initialize one tx/cmd queue
|
2011-02-22 02:27:26 +07:00
|
|
|
*/
|
2011-10-24 21:49:25 +07:00
|
|
|
int il_tx_queue_init(struct il_priv *il, struct il_tx_queue *txq,
|
2011-02-22 02:27:26 +07:00
|
|
|
int slots_num, u32 txq_id)
|
|
|
|
{
|
|
|
|
int i, len;
|
|
|
|
int ret;
|
|
|
|
int actual_slots = slots_num;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Alloc buffer array for commands (Tx or other types of commands).
|
|
|
|
* For the command queue (#4/#9), allocate command space + one big
|
|
|
|
* command for scan, since scan command is very huge; the system will
|
|
|
|
* not have two scans at the same time, so only one is needed.
|
|
|
|
* For normal Tx queues (all other queues), no super-size command
|
|
|
|
* space is needed.
|
|
|
|
*/
|
2011-10-24 21:49:25 +07:00
|
|
|
if (txq_id == il->cmd_queue)
|
2011-02-22 02:27:26 +07:00
|
|
|
actual_slots++;
|
|
|
|
|
2011-10-24 20:41:30 +07:00
|
|
|
txq->meta = kzalloc(sizeof(struct il_cmd_meta) * actual_slots,
|
2011-02-22 02:27:26 +07:00
|
|
|
GFP_KERNEL);
|
2011-10-24 20:41:30 +07:00
|
|
|
txq->cmd = kzalloc(sizeof(struct il_device_cmd *) * actual_slots,
|
2011-02-22 02:27:26 +07:00
|
|
|
GFP_KERNEL);
|
|
|
|
|
|
|
|
if (!txq->meta || !txq->cmd)
|
|
|
|
goto out_free_arrays;
|
|
|
|
|
2011-10-24 20:41:30 +07:00
|
|
|
len = sizeof(struct il_device_cmd);
|
2011-02-22 02:27:26 +07:00
|
|
|
for (i = 0; i < actual_slots; i++) {
|
|
|
|
/* only happens for cmd queue */
|
|
|
|
if (i == slots_num)
|
2011-10-24 20:41:30 +07:00
|
|
|
len = IL_MAX_CMD_SIZE;
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
txq->cmd[i] = kmalloc(len, GFP_KERNEL);
|
|
|
|
if (!txq->cmd[i])
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Alloc driver data array and TFD circular buffer */
|
2011-10-24 21:49:25 +07:00
|
|
|
ret = il_tx_queue_alloc(il, txq, txq_id);
|
2011-02-22 02:27:26 +07:00
|
|
|
if (ret)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
txq->need_update = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For the default queues 0-3, set up the swq_id
|
|
|
|
* already -- all others need to get one later
|
|
|
|
* (if they need one at all).
|
|
|
|
*/
|
|
|
|
if (txq_id < 4)
|
2011-10-24 20:41:30 +07:00
|
|
|
il_set_swq_id(txq, txq_id, txq_id);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
/* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
|
2011-10-24 20:41:30 +07:00
|
|
|
* il_queue_inc_wrap and il_queue_dec_wrap are broken. */
|
2011-02-22 02:27:26 +07:00
|
|
|
BUILD_BUG_ON(TFD_QUEUE_SIZE_MAX & (TFD_QUEUE_SIZE_MAX - 1));
|
|
|
|
|
2011-11-15 18:30:17 +07:00
|
|
|
/* Initialize queue's high/low-water marks, and head/tail idxes */
|
2011-10-24 21:49:25 +07:00
|
|
|
il_queue_init(il, &txq->q,
|
2011-02-22 02:27:26 +07:00
|
|
|
TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
|
|
|
|
|
|
|
|
/* Tell device where to find queue */
|
2011-10-24 21:49:25 +07:00
|
|
|
il->cfg->ops->lib->txq_init(il, txq);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
for (i = 0; i < actual_slots; i++)
|
|
|
|
kfree(txq->cmd[i]);
|
|
|
|
out_free_arrays:
|
|
|
|
kfree(txq->meta);
|
|
|
|
kfree(txq->cmd);
|
|
|
|
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2011-10-24 20:41:30 +07:00
|
|
|
EXPORT_SYMBOL(il_tx_queue_init);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
void il_tx_queue_reset(struct il_priv *il, struct il_tx_queue *txq,
|
2011-02-22 02:27:26 +07:00
|
|
|
int slots_num, u32 txq_id)
|
|
|
|
{
|
|
|
|
int actual_slots = slots_num;
|
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
if (txq_id == il->cmd_queue)
|
2011-02-22 02:27:26 +07:00
|
|
|
actual_slots++;
|
|
|
|
|
2011-10-24 20:41:30 +07:00
|
|
|
memset(txq->meta, 0, sizeof(struct il_cmd_meta) * actual_slots);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
txq->need_update = 0;
|
|
|
|
|
2011-11-15 18:30:17 +07:00
|
|
|
/* Initialize queue's high/low-water marks, and head/tail idxes */
|
2011-10-24 21:49:25 +07:00
|
|
|
il_queue_init(il, &txq->q,
|
2011-02-22 02:27:26 +07:00
|
|
|
TFD_QUEUE_SIZE_MAX, slots_num, txq_id);
|
|
|
|
|
|
|
|
/* Tell device where to find queue */
|
2011-10-24 21:49:25 +07:00
|
|
|
il->cfg->ops->lib->txq_init(il, txq);
|
2011-02-22 02:27:26 +07:00
|
|
|
}
|
2011-10-24 20:41:30 +07:00
|
|
|
EXPORT_SYMBOL(il_tx_queue_reset);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
/*************** HOST COMMAND QUEUE FUNCTIONS *****/
|
|
|
|
|
|
|
|
/**
|
2011-10-24 20:41:30 +07:00
|
|
|
* il_enqueue_hcmd - enqueue a uCode command
|
2011-10-24 21:49:25 +07:00
|
|
|
* @il: device ilate data point
|
2011-02-22 02:27:26 +07:00
|
|
|
* @cmd: a point to the ucode command structure
|
|
|
|
*
|
|
|
|
* The function returns < 0 values to indicate the operation is
|
2011-11-15 18:30:17 +07:00
|
|
|
* failed. On success, it turns the idx (> 0) of command in the
|
2011-02-22 02:27:26 +07:00
|
|
|
* command queue.
|
|
|
|
*/
|
2011-10-24 21:49:25 +07:00
|
|
|
int il_enqueue_hcmd(struct il_priv *il, struct il_host_cmd *cmd)
|
2011-02-22 02:27:26 +07:00
|
|
|
{
|
2011-10-24 21:49:25 +07:00
|
|
|
struct il_tx_queue *txq = &il->txq[il->cmd_queue];
|
2011-10-24 20:41:30 +07:00
|
|
|
struct il_queue *q = &txq->q;
|
|
|
|
struct il_device_cmd *out_cmd;
|
|
|
|
struct il_cmd_meta *out_meta;
|
2011-02-22 02:27:26 +07:00
|
|
|
dma_addr_t phys_addr;
|
|
|
|
unsigned long flags;
|
|
|
|
int len;
|
|
|
|
u32 idx;
|
|
|
|
u16 fix_size;
|
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
cmd->len = il->cfg->ops->utils->get_hcmd_size(cmd->id, cmd->len);
|
2011-02-22 02:27:26 +07:00
|
|
|
fix_size = (u16)(cmd->len + sizeof(out_cmd->hdr));
|
|
|
|
|
|
|
|
/* If any of the command structures end up being larger than
|
|
|
|
* the TFD_MAX_PAYLOAD_SIZE, and it sent as a 'small' command then
|
|
|
|
* we will need to increase the size of the TFD entries
|
|
|
|
* Also, check to see if command buffer should not exceed the size
|
|
|
|
* of device_cmd and max_cmd_size. */
|
|
|
|
BUG_ON((fix_size > TFD_MAX_PAYLOAD_SIZE) &&
|
|
|
|
!(cmd->flags & CMD_SIZE_HUGE));
|
2011-10-24 20:41:30 +07:00
|
|
|
BUG_ON(fix_size > IL_MAX_CMD_SIZE);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
if (il_is_rfkill(il) || il_is_ctkill(il)) {
|
2011-08-19 03:07:57 +07:00
|
|
|
IL_WARN("Not sending command - %s KILL\n",
|
2011-10-24 21:49:25 +07:00
|
|
|
il_is_rfkill(il) ? "RF" : "CT");
|
2011-02-22 02:27:26 +07:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
spin_lock_irqsave(&il->hcmd_lock, flags);
|
2011-04-28 16:51:31 +07:00
|
|
|
|
2011-10-24 20:41:30 +07:00
|
|
|
if (il_queue_space(q) < ((cmd->flags & CMD_ASYNC) ? 2 : 1)) {
|
2011-10-24 21:49:25 +07:00
|
|
|
spin_unlock_irqrestore(&il->hcmd_lock, flags);
|
2011-04-28 16:51:31 +07:00
|
|
|
|
2011-08-19 03:07:57 +07:00
|
|
|
IL_ERR("Restarting adapter due to command queue full\n");
|
2011-10-24 21:49:25 +07:00
|
|
|
queue_work(il->workqueue, &il->restart);
|
2011-02-22 02:27:26 +07:00
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
2011-11-15 18:30:17 +07:00
|
|
|
idx = il_get_cmd_idx(q, q->write_ptr, cmd->flags & CMD_SIZE_HUGE);
|
2011-02-22 02:27:26 +07:00
|
|
|
out_cmd = txq->cmd[idx];
|
|
|
|
out_meta = &txq->meta[idx];
|
|
|
|
|
2011-04-28 16:51:31 +07:00
|
|
|
if (WARN_ON(out_meta->flags & CMD_MAPPED)) {
|
2011-10-24 21:49:25 +07:00
|
|
|
spin_unlock_irqrestore(&il->hcmd_lock, flags);
|
2011-04-28 16:51:31 +07:00
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
2011-02-22 02:27:26 +07:00
|
|
|
memset(out_meta, 0, sizeof(*out_meta)); /* re-initialize to NULL */
|
2011-04-28 16:51:31 +07:00
|
|
|
out_meta->flags = cmd->flags | CMD_MAPPED;
|
2011-02-22 02:27:26 +07:00
|
|
|
if (cmd->flags & CMD_WANT_SKB)
|
|
|
|
out_meta->source = cmd;
|
|
|
|
if (cmd->flags & CMD_ASYNC)
|
|
|
|
out_meta->callback = cmd->callback;
|
|
|
|
|
|
|
|
out_cmd->hdr.cmd = cmd->id;
|
|
|
|
memcpy(&out_cmd->cmd.payload, cmd->data, cmd->len);
|
|
|
|
|
|
|
|
/* At this point, the out_cmd now has all of the incoming cmd
|
|
|
|
* information */
|
|
|
|
|
|
|
|
out_cmd->hdr.flags = 0;
|
2011-10-24 21:49:25 +07:00
|
|
|
out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(il->cmd_queue) |
|
2011-08-26 21:10:40 +07:00
|
|
|
IDX_TO_SEQ(q->write_ptr));
|
2011-02-22 02:27:26 +07:00
|
|
|
if (cmd->flags & CMD_SIZE_HUGE)
|
|
|
|
out_cmd->hdr.sequence |= SEQ_HUGE_FRAME;
|
2011-10-24 20:41:30 +07:00
|
|
|
len = sizeof(struct il_device_cmd);
|
2011-02-22 02:27:26 +07:00
|
|
|
if (idx == TFD_CMD_SLOTS)
|
2011-10-24 20:41:30 +07:00
|
|
|
len = IL_MAX_CMD_SIZE;
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-11-15 17:25:42 +07:00
|
|
|
#ifdef CONFIG_IWLEGACY_DEBUG
|
2011-02-22 02:27:26 +07:00
|
|
|
switch (out_cmd->hdr.cmd) {
|
|
|
|
case REPLY_TX_LINK_QUALITY_CMD:
|
|
|
|
case SENSITIVITY_CMD:
|
2011-11-15 17:21:01 +07:00
|
|
|
D_HC_DUMP(
|
2011-02-22 02:27:26 +07:00
|
|
|
"Sending command %s (#%x), seq: 0x%04X, "
|
|
|
|
"%d bytes at %d[%d]:%d\n",
|
2011-10-24 20:41:30 +07:00
|
|
|
il_get_cmd_string(out_cmd->hdr.cmd),
|
2011-02-22 02:27:26 +07:00
|
|
|
out_cmd->hdr.cmd,
|
|
|
|
le16_to_cpu(out_cmd->hdr.sequence), fix_size,
|
2011-10-24 21:49:25 +07:00
|
|
|
q->write_ptr, idx, il->cmd_queue);
|
2011-02-22 02:27:26 +07:00
|
|
|
break;
|
|
|
|
default:
|
2011-11-15 17:21:01 +07:00
|
|
|
D_HC("Sending command %s (#%x), seq: 0x%04X, "
|
2011-02-22 02:27:26 +07:00
|
|
|
"%d bytes at %d[%d]:%d\n",
|
2011-10-24 20:41:30 +07:00
|
|
|
il_get_cmd_string(out_cmd->hdr.cmd),
|
2011-02-22 02:27:26 +07:00
|
|
|
out_cmd->hdr.cmd,
|
|
|
|
le16_to_cpu(out_cmd->hdr.sequence), fix_size,
|
2011-10-24 21:49:25 +07:00
|
|
|
q->write_ptr, idx, il->cmd_queue);
|
2011-02-22 02:27:26 +07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
txq->need_update = 1;
|
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
if (il->cfg->ops->lib->txq_update_byte_cnt_tbl)
|
2011-02-22 02:27:26 +07:00
|
|
|
/* Set up entry in queue's byte count circular buffer */
|
2011-10-24 21:49:25 +07:00
|
|
|
il->cfg->ops->lib->txq_update_byte_cnt_tbl(il, txq, 0);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
phys_addr = pci_map_single(il->pci_dev, &out_cmd->hdr,
|
2011-02-22 02:27:26 +07:00
|
|
|
fix_size, PCI_DMA_BIDIRECTIONAL);
|
|
|
|
dma_unmap_addr_set(out_meta, mapping, phys_addr);
|
|
|
|
dma_unmap_len_set(out_meta, len, fix_size);
|
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
il->cfg->ops->lib->txq_attach_buf_to_tfd(il, txq,
|
2011-02-22 02:27:26 +07:00
|
|
|
phys_addr, fix_size, 1,
|
|
|
|
U32_PAD(cmd->len));
|
|
|
|
|
2011-11-15 18:30:17 +07:00
|
|
|
/* Increment and update queue's write idx */
|
2011-10-24 20:41:30 +07:00
|
|
|
q->write_ptr = il_queue_inc_wrap(q->write_ptr, q->n_bd);
|
2011-10-24 21:49:25 +07:00
|
|
|
il_txq_update_write_ptr(il, txq);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
spin_unlock_irqrestore(&il->hcmd_lock, flags);
|
2011-02-22 02:27:26 +07:00
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-24 20:41:30 +07:00
|
|
|
* il_hcmd_queue_reclaim - Reclaim TX command queue entries already Tx'd
|
2011-02-22 02:27:26 +07:00
|
|
|
*
|
2011-11-15 18:30:17 +07:00
|
|
|
* When FW advances 'R' idx, all entries between old and new 'R' idx
|
2011-02-22 02:27:26 +07:00
|
|
|
* need to be reclaimed. As result, some free space forms. If there is
|
|
|
|
* enough free space (> low mark), wake the stack that feeds us.
|
|
|
|
*/
|
2011-10-24 21:49:25 +07:00
|
|
|
static void il_hcmd_queue_reclaim(struct il_priv *il, int txq_id,
|
2011-02-22 02:27:26 +07:00
|
|
|
int idx, int cmd_idx)
|
|
|
|
{
|
2011-10-24 21:49:25 +07:00
|
|
|
struct il_tx_queue *txq = &il->txq[txq_id];
|
2011-10-24 20:41:30 +07:00
|
|
|
struct il_queue *q = &txq->q;
|
2011-02-22 02:27:26 +07:00
|
|
|
int nfreed = 0;
|
|
|
|
|
2011-08-26 15:45:16 +07:00
|
|
|
if (idx >= q->n_bd || il_queue_used(q, idx) == 0) {
|
2011-11-15 18:30:17 +07:00
|
|
|
IL_ERR("Read idx for DMA queue txq id (%d), idx %d, "
|
2011-02-22 02:27:26 +07:00
|
|
|
"is out of range [0-%d] %d %d.\n", txq_id,
|
|
|
|
idx, q->n_bd, q->write_ptr, q->read_ptr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-10-24 20:41:30 +07:00
|
|
|
for (idx = il_queue_inc_wrap(idx, q->n_bd); q->read_ptr != idx;
|
|
|
|
q->read_ptr = il_queue_inc_wrap(q->read_ptr, q->n_bd)) {
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
if (nfreed++ > 0) {
|
2011-11-15 18:30:17 +07:00
|
|
|
IL_ERR("HCMD skipped: idx (%d) %d %d\n", idx,
|
2011-02-22 02:27:26 +07:00
|
|
|
q->write_ptr, q->read_ptr);
|
2011-10-24 21:49:25 +07:00
|
|
|
queue_work(il->workqueue, &il->restart);
|
2011-02-22 02:27:26 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-10-24 20:41:30 +07:00
|
|
|
* il_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
|
2011-02-22 02:27:26 +07:00
|
|
|
* @rxb: Rx buffer to reclaim
|
|
|
|
*
|
|
|
|
* If an Rx buffer has an async callback associated with it the callback
|
|
|
|
* will be executed. The attached skb (if present) will only be freed
|
|
|
|
* if the callback returns 1
|
|
|
|
*/
|
|
|
|
void
|
2011-08-26 19:37:54 +07:00
|
|
|
il_tx_cmd_complete(struct il_priv *il, struct il_rx_buf *rxb)
|
2011-02-22 02:27:26 +07:00
|
|
|
{
|
2011-08-26 19:36:21 +07:00
|
|
|
struct il_rx_pkt *pkt = rxb_addr(rxb);
|
2011-02-22 02:27:26 +07:00
|
|
|
u16 sequence = le16_to_cpu(pkt->hdr.sequence);
|
|
|
|
int txq_id = SEQ_TO_QUEUE(sequence);
|
2011-11-15 18:30:17 +07:00
|
|
|
int idx = SEQ_TO_IDX(sequence);
|
|
|
|
int cmd_idx;
|
2011-02-22 02:27:26 +07:00
|
|
|
bool huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
|
2011-10-24 20:41:30 +07:00
|
|
|
struct il_device_cmd *cmd;
|
|
|
|
struct il_cmd_meta *meta;
|
2011-10-24 21:49:25 +07:00
|
|
|
struct il_tx_queue *txq = &il->txq[il->cmd_queue];
|
2011-04-28 16:51:31 +07:00
|
|
|
unsigned long flags;
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
/* If a Tx command is being handled and it isn't in the actual
|
|
|
|
* command queue then there a command routing bug has been introduced
|
|
|
|
* in the queue management code. */
|
2011-10-24 21:49:25 +07:00
|
|
|
if (WARN(txq_id != il->cmd_queue,
|
2011-02-22 02:27:26 +07:00
|
|
|
"wrong command queue %d (should be %d), sequence 0x%X readp=%d writep=%d\n",
|
2011-10-24 21:49:25 +07:00
|
|
|
txq_id, il->cmd_queue, sequence,
|
|
|
|
il->txq[il->cmd_queue].q.read_ptr,
|
|
|
|
il->txq[il->cmd_queue].q.write_ptr)) {
|
|
|
|
il_print_hex_error(il, pkt, 32);
|
2011-02-22 02:27:26 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-15 18:30:17 +07:00
|
|
|
cmd_idx = il_get_cmd_idx(&txq->q, idx, huge);
|
|
|
|
cmd = txq->cmd[cmd_idx];
|
|
|
|
meta = &txq->meta[cmd_idx];
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-09-20 21:46:36 +07:00
|
|
|
txq->time_stamp = jiffies;
|
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
pci_unmap_single(il->pci_dev,
|
2011-02-22 02:27:26 +07:00
|
|
|
dma_unmap_addr(meta, mapping),
|
|
|
|
dma_unmap_len(meta, len),
|
|
|
|
PCI_DMA_BIDIRECTIONAL);
|
|
|
|
|
|
|
|
/* Input error checking is done when commands are added to queue. */
|
|
|
|
if (meta->flags & CMD_WANT_SKB) {
|
|
|
|
meta->source->reply_page = (unsigned long)rxb_addr(rxb);
|
|
|
|
rxb->page = NULL;
|
|
|
|
} else if (meta->callback)
|
2011-10-24 21:49:25 +07:00
|
|
|
meta->callback(il, cmd, pkt);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
spin_lock_irqsave(&il->hcmd_lock, flags);
|
2011-04-28 16:51:31 +07:00
|
|
|
|
2011-11-15 18:30:17 +07:00
|
|
|
il_hcmd_queue_reclaim(il, txq_id, idx, cmd_idx);
|
2011-02-22 02:27:26 +07:00
|
|
|
|
|
|
|
if (!(meta->flags & CMD_ASYNC)) {
|
2011-10-24 21:49:25 +07:00
|
|
|
clear_bit(STATUS_HCMD_ACTIVE, &il->status);
|
2011-11-15 17:21:01 +07:00
|
|
|
D_INFO("Clearing HCMD_ACTIVE for command %s\n",
|
2011-10-24 20:41:30 +07:00
|
|
|
il_get_cmd_string(cmd->hdr.cmd));
|
2011-10-24 21:49:25 +07:00
|
|
|
wake_up(&il->wait_command_queue);
|
2011-02-22 02:27:26 +07:00
|
|
|
}
|
2011-04-28 16:51:31 +07:00
|
|
|
|
|
|
|
/* Mark as unmapped */
|
2011-02-22 02:27:26 +07:00
|
|
|
meta->flags = 0;
|
2011-04-28 16:51:31 +07:00
|
|
|
|
2011-10-24 21:49:25 +07:00
|
|
|
spin_unlock_irqrestore(&il->hcmd_lock, flags);
|
2011-02-22 02:27:26 +07:00
|
|
|
}
|
2011-10-24 20:41:30 +07:00
|
|
|
EXPORT_SYMBOL(il_tx_cmd_complete);
|