2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2004, 2005 Topspin Communications. All rights reserved.
|
2005-08-11 06:03:10 +00:00
|
|
|
* Copyright (c) 2005 Mellanox Technologies. All rights reserved.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
* This software is available to you under a choice of one of two
|
|
|
|
* licenses. You may choose to be licensed under the terms of the GNU
|
|
|
|
* General Public License (GPL) Version 2, available from the file
|
|
|
|
* COPYING in the main directory of this source tree, or the
|
|
|
|
* OpenIB.org BSD license below:
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or
|
|
|
|
* without modification, are permitted provided that the following
|
|
|
|
* conditions are met:
|
|
|
|
*
|
|
|
|
* - Redistributions of source code must retain the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer.
|
|
|
|
*
|
|
|
|
* - Redistributions in binary form must reproduce the above
|
|
|
|
* copyright notice, this list of conditions and the following
|
|
|
|
* disclaimer in the documentation and/or other materials
|
|
|
|
* provided with the distribution.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/pci.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#include "mthca_dev.h"
|
|
|
|
#include "mthca_cmd.h"
|
|
|
|
#include "mthca_config_reg.h"
|
|
|
|
|
|
|
|
enum {
|
|
|
|
MTHCA_NUM_ASYNC_EQE = 0x80,
|
|
|
|
MTHCA_NUM_CMD_EQE = 0x80,
|
2006-01-09 22:04:40 +00:00
|
|
|
MTHCA_NUM_SPARE_EQE = 0x80,
|
2005-04-16 22:20:36 +00:00
|
|
|
MTHCA_EQ_ENTRY_SIZE = 0x20
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must be packed because start is 64 bits but only aligned to 32 bits.
|
|
|
|
*/
|
|
|
|
struct mthca_eq_context {
|
2005-08-14 04:05:57 +00:00
|
|
|
__be32 flags;
|
|
|
|
__be64 start;
|
|
|
|
__be32 logsize_usrpage;
|
|
|
|
__be32 tavor_pd; /* reserved for Arbel */
|
|
|
|
u8 reserved1[3];
|
|
|
|
u8 intr;
|
|
|
|
__be32 arbel_pd; /* lost_count for Tavor */
|
|
|
|
__be32 lkey;
|
|
|
|
u32 reserved2[2];
|
|
|
|
__be32 consumer_index;
|
|
|
|
__be32 producer_index;
|
|
|
|
u32 reserved3[4];
|
2019-02-25 06:52:30 +00:00
|
|
|
} __packed;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define MTHCA_EQ_STATUS_OK ( 0 << 28)
|
|
|
|
#define MTHCA_EQ_STATUS_OVERFLOW ( 9 << 28)
|
|
|
|
#define MTHCA_EQ_STATUS_WRITE_FAIL (10 << 28)
|
|
|
|
#define MTHCA_EQ_OWNER_SW ( 0 << 24)
|
|
|
|
#define MTHCA_EQ_OWNER_HW ( 1 << 24)
|
|
|
|
#define MTHCA_EQ_FLAG_TR ( 1 << 18)
|
|
|
|
#define MTHCA_EQ_FLAG_OI ( 1 << 17)
|
|
|
|
#define MTHCA_EQ_STATE_ARMED ( 1 << 8)
|
|
|
|
#define MTHCA_EQ_STATE_FIRED ( 2 << 8)
|
|
|
|
#define MTHCA_EQ_STATE_ALWAYS_ARMED ( 3 << 8)
|
|
|
|
#define MTHCA_EQ_STATE_ARBEL ( 8 << 8)
|
|
|
|
|
|
|
|
enum {
|
|
|
|
MTHCA_EVENT_TYPE_COMP = 0x00,
|
|
|
|
MTHCA_EVENT_TYPE_PATH_MIG = 0x01,
|
|
|
|
MTHCA_EVENT_TYPE_COMM_EST = 0x02,
|
|
|
|
MTHCA_EVENT_TYPE_SQ_DRAINED = 0x03,
|
2005-10-06 20:15:56 +00:00
|
|
|
MTHCA_EVENT_TYPE_SRQ_QP_LAST_WQE = 0x13,
|
|
|
|
MTHCA_EVENT_TYPE_SRQ_LIMIT = 0x14,
|
2005-04-16 22:20:36 +00:00
|
|
|
MTHCA_EVENT_TYPE_CQ_ERROR = 0x04,
|
|
|
|
MTHCA_EVENT_TYPE_WQ_CATAS_ERROR = 0x05,
|
|
|
|
MTHCA_EVENT_TYPE_EEC_CATAS_ERROR = 0x06,
|
|
|
|
MTHCA_EVENT_TYPE_PATH_MIG_FAILED = 0x07,
|
|
|
|
MTHCA_EVENT_TYPE_WQ_INVAL_REQ_ERROR = 0x10,
|
|
|
|
MTHCA_EVENT_TYPE_WQ_ACCESS_ERROR = 0x11,
|
|
|
|
MTHCA_EVENT_TYPE_SRQ_CATAS_ERROR = 0x12,
|
|
|
|
MTHCA_EVENT_TYPE_LOCAL_CATAS_ERROR = 0x08,
|
|
|
|
MTHCA_EVENT_TYPE_PORT_CHANGE = 0x09,
|
|
|
|
MTHCA_EVENT_TYPE_EQ_OVERFLOW = 0x0f,
|
|
|
|
MTHCA_EVENT_TYPE_ECC_DETECT = 0x0e,
|
|
|
|
MTHCA_EVENT_TYPE_CMD = 0x0a
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MTHCA_ASYNC_EVENT_MASK ((1ULL << MTHCA_EVENT_TYPE_PATH_MIG) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_COMM_EST) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_SQ_DRAINED) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_CQ_ERROR) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_WQ_CATAS_ERROR) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_EEC_CATAS_ERROR) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_PATH_MIG_FAILED) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_WQ_INVAL_REQ_ERROR) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_WQ_ACCESS_ERROR) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_LOCAL_CATAS_ERROR) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_PORT_CHANGE) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_ECC_DETECT))
|
2005-10-06 20:15:56 +00:00
|
|
|
#define MTHCA_SRQ_EVENT_MASK ((1ULL << MTHCA_EVENT_TYPE_SRQ_CATAS_ERROR) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_SRQ_QP_LAST_WQE) | \
|
|
|
|
(1ULL << MTHCA_EVENT_TYPE_SRQ_LIMIT))
|
2005-04-16 22:20:36 +00:00
|
|
|
#define MTHCA_CMD_EVENT_MASK (1ULL << MTHCA_EVENT_TYPE_CMD)
|
|
|
|
|
|
|
|
#define MTHCA_EQ_DB_INC_CI (1 << 24)
|
|
|
|
#define MTHCA_EQ_DB_REQ_NOT (2 << 24)
|
|
|
|
#define MTHCA_EQ_DB_DISARM_CQ (3 << 24)
|
|
|
|
#define MTHCA_EQ_DB_SET_CI (4 << 24)
|
|
|
|
#define MTHCA_EQ_DB_ALWAYS_ARM (5 << 24)
|
|
|
|
|
|
|
|
struct mthca_eqe {
|
|
|
|
u8 reserved1;
|
|
|
|
u8 type;
|
|
|
|
u8 reserved2;
|
|
|
|
u8 subtype;
|
|
|
|
union {
|
|
|
|
u32 raw[6];
|
|
|
|
struct {
|
2005-08-14 04:05:57 +00:00
|
|
|
__be32 cqn;
|
2019-02-25 06:52:30 +00:00
|
|
|
} __packed comp;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct {
|
2005-08-14 04:05:57 +00:00
|
|
|
u16 reserved1;
|
|
|
|
__be16 token;
|
|
|
|
u32 reserved2;
|
|
|
|
u8 reserved3[3];
|
|
|
|
u8 status;
|
|
|
|
__be64 out_param;
|
2019-02-25 06:52:30 +00:00
|
|
|
} __packed cmd;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct {
|
2005-08-14 04:05:57 +00:00
|
|
|
__be32 qpn;
|
2019-02-25 06:52:30 +00:00
|
|
|
} __packed qp;
|
2005-10-06 20:15:56 +00:00
|
|
|
struct {
|
|
|
|
__be32 srqn;
|
2019-02-25 06:52:30 +00:00
|
|
|
} __packed srq;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct {
|
2005-08-14 04:05:57 +00:00
|
|
|
__be32 cqn;
|
|
|
|
u32 reserved1;
|
|
|
|
u8 reserved2[3];
|
|
|
|
u8 syndrome;
|
2019-02-25 06:52:30 +00:00
|
|
|
} __packed cq_err;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct {
|
2005-08-14 04:05:57 +00:00
|
|
|
u32 reserved1[2];
|
|
|
|
__be32 port;
|
2019-02-25 06:52:30 +00:00
|
|
|
} __packed port_change;
|
2005-04-16 22:20:36 +00:00
|
|
|
} event;
|
|
|
|
u8 reserved3[3];
|
|
|
|
u8 owner;
|
2019-02-25 06:52:30 +00:00
|
|
|
} __packed;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#define MTHCA_EQ_ENTRY_OWNER_SW (0 << 7)
|
|
|
|
#define MTHCA_EQ_ENTRY_OWNER_HW (1 << 7)
|
|
|
|
|
|
|
|
static inline u64 async_mask(struct mthca_dev *dev)
|
|
|
|
{
|
|
|
|
return dev->mthca_flags & MTHCA_FLAG_SRQ ?
|
|
|
|
MTHCA_ASYNC_EVENT_MASK | MTHCA_SRQ_EVENT_MASK :
|
|
|
|
MTHCA_ASYNC_EVENT_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tavor_set_eq_ci(struct mthca_dev *dev, struct mthca_eq *eq, u32 ci)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This barrier makes sure that all updates to ownership bits
|
|
|
|
* done by set_eqe_hw() hit memory before the consumer index
|
|
|
|
* is updated. set_eq_ci() allows the HCA to possibly write
|
|
|
|
* more EQ entries, and we want to avoid the exceedingly
|
|
|
|
* unlikely possibility of the HCA writing an entry and then
|
|
|
|
* having set_eqe_hw() overwrite the owner field.
|
|
|
|
*/
|
|
|
|
wmb();
|
2007-10-15 03:40:27 +00:00
|
|
|
mthca_write64(MTHCA_EQ_DB_SET_CI | eq->eqn, ci & (eq->nent - 1),
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->kar + MTHCA_EQ_DOORBELL,
|
|
|
|
MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void arbel_set_eq_ci(struct mthca_dev *dev, struct mthca_eq *eq, u32 ci)
|
|
|
|
{
|
|
|
|
/* See comment in tavor_set_eq_ci() above. */
|
|
|
|
wmb();
|
2005-08-14 04:05:57 +00:00
|
|
|
__raw_writel((__force u32) cpu_to_be32(ci),
|
|
|
|
dev->eq_regs.arbel.eq_set_ci_base + eq->eqn * 8);
|
2005-04-16 22:20:36 +00:00
|
|
|
/* We still want ordering, just not swabbing, so add a barrier */
|
|
|
|
mb();
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void set_eq_ci(struct mthca_dev *dev, struct mthca_eq *eq, u32 ci)
|
|
|
|
{
|
2005-04-16 22:26:32 +00:00
|
|
|
if (mthca_is_memfree(dev))
|
2005-04-16 22:20:36 +00:00
|
|
|
arbel_set_eq_ci(dev, eq, ci);
|
|
|
|
else
|
|
|
|
tavor_set_eq_ci(dev, eq, ci);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void tavor_eq_req_not(struct mthca_dev *dev, int eqn)
|
|
|
|
{
|
2007-10-15 03:40:27 +00:00
|
|
|
mthca_write64(MTHCA_EQ_DB_REQ_NOT | eqn, 0,
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->kar + MTHCA_EQ_DOORBELL,
|
|
|
|
MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void arbel_eq_req_not(struct mthca_dev *dev, u32 eqn_mask)
|
|
|
|
{
|
|
|
|
writel(eqn_mask, dev->eq_regs.arbel.eq_arm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void disarm_cq(struct mthca_dev *dev, int eqn, int cqn)
|
|
|
|
{
|
2005-04-16 22:26:32 +00:00
|
|
|
if (!mthca_is_memfree(dev)) {
|
2007-10-15 03:40:27 +00:00
|
|
|
mthca_write64(MTHCA_EQ_DB_DISARM_CQ | eqn, cqn,
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->kar + MTHCA_EQ_DOORBELL,
|
|
|
|
MTHCA_GET_DOORBELL_LOCK(&dev->doorbell_lock));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct mthca_eqe *get_eqe(struct mthca_eq *eq, u32 entry)
|
|
|
|
{
|
|
|
|
unsigned long off = (entry & (eq->nent - 1)) * MTHCA_EQ_ENTRY_SIZE;
|
|
|
|
return eq->page_list[off / PAGE_SIZE].buf + off % PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
2008-04-17 04:01:03 +00:00
|
|
|
static inline struct mthca_eqe *next_eqe_sw(struct mthca_eq *eq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-04-17 04:01:03 +00:00
|
|
|
struct mthca_eqe *eqe;
|
2005-04-16 22:20:36 +00:00
|
|
|
eqe = get_eqe(eq, eq->cons_index);
|
|
|
|
return (MTHCA_EQ_ENTRY_OWNER_HW & eqe->owner) ? NULL : eqe;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void set_eqe_hw(struct mthca_eqe *eqe)
|
|
|
|
{
|
|
|
|
eqe->owner = MTHCA_EQ_ENTRY_OWNER_HW;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void port_change(struct mthca_dev *dev, int port, int active)
|
|
|
|
{
|
|
|
|
struct ib_event record;
|
|
|
|
|
|
|
|
mthca_dbg(dev, "Port change to %s for port %d\n",
|
|
|
|
active ? "active" : "down", port);
|
|
|
|
|
|
|
|
record.device = &dev->ib_dev;
|
|
|
|
record.event = active ? IB_EVENT_PORT_ACTIVE : IB_EVENT_PORT_ERR;
|
|
|
|
record.element.port_num = port;
|
|
|
|
|
|
|
|
ib_dispatch_event(&record);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mthca_eq_int(struct mthca_dev *dev, struct mthca_eq *eq)
|
|
|
|
{
|
|
|
|
struct mthca_eqe *eqe;
|
|
|
|
int disarm_cqn;
|
2006-01-09 22:04:40 +00:00
|
|
|
int eqes_found = 0;
|
|
|
|
int set_ci = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
while ((eqe = next_eqe_sw(eq))) {
|
|
|
|
/*
|
|
|
|
* Make sure we read EQ entry contents after we've
|
|
|
|
* checked the ownership bit.
|
|
|
|
*/
|
|
|
|
rmb();
|
|
|
|
|
|
|
|
switch (eqe->type) {
|
|
|
|
case MTHCA_EVENT_TYPE_COMP:
|
|
|
|
disarm_cqn = be32_to_cpu(eqe->event.comp.cqn) & 0xffffff;
|
|
|
|
disarm_cq(dev, eq->eqn, disarm_cqn);
|
2005-10-29 14:39:42 +00:00
|
|
|
mthca_cq_completion(dev, disarm_cqn);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_PATH_MIG:
|
|
|
|
mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
|
|
|
|
IB_EVENT_PATH_MIG);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_COMM_EST:
|
|
|
|
mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
|
|
|
|
IB_EVENT_COMM_EST);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_SQ_DRAINED:
|
|
|
|
mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
|
|
|
|
IB_EVENT_SQ_DRAINED);
|
|
|
|
break;
|
|
|
|
|
2005-10-06 20:15:56 +00:00
|
|
|
case MTHCA_EVENT_TYPE_SRQ_QP_LAST_WQE:
|
|
|
|
mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
|
|
|
|
IB_EVENT_QP_LAST_WQE_REACHED);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_SRQ_LIMIT:
|
|
|
|
mthca_srq_event(dev, be32_to_cpu(eqe->event.srq.srqn) & 0xffffff,
|
|
|
|
IB_EVENT_SRQ_LIMIT_REACHED);
|
|
|
|
break;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
case MTHCA_EVENT_TYPE_WQ_CATAS_ERROR:
|
|
|
|
mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
|
|
|
|
IB_EVENT_QP_FATAL);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_PATH_MIG_FAILED:
|
|
|
|
mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
|
|
|
|
IB_EVENT_PATH_MIG_ERR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
|
|
|
|
mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
|
|
|
|
IB_EVENT_QP_REQ_ERR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_WQ_ACCESS_ERROR:
|
|
|
|
mthca_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
|
|
|
|
IB_EVENT_QP_ACCESS_ERR);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_CMD:
|
|
|
|
mthca_cmd_event(dev,
|
|
|
|
be16_to_cpu(eqe->event.cmd.token),
|
|
|
|
eqe->event.cmd.status,
|
|
|
|
be64_to_cpu(eqe->event.cmd.out_param));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_PORT_CHANGE:
|
|
|
|
port_change(dev,
|
|
|
|
(be32_to_cpu(eqe->event.port_change.port) >> 28) & 3,
|
|
|
|
eqe->subtype == 0x4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_CQ_ERROR:
|
2005-04-16 22:26:22 +00:00
|
|
|
mthca_warn(dev, "CQ %s on CQN %06x\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
eqe->event.cq_err.syndrome == 1 ?
|
|
|
|
"overrun" : "access violation",
|
2005-04-16 22:26:22 +00:00
|
|
|
be32_to_cpu(eqe->event.cq_err.cqn) & 0xffffff);
|
2005-10-29 14:39:42 +00:00
|
|
|
mthca_cq_event(dev, be32_to_cpu(eqe->event.cq_err.cqn),
|
|
|
|
IB_EVENT_CQ_ERR);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_EQ_OVERFLOW:
|
|
|
|
mthca_warn(dev, "EQ overrun on EQN %d\n", eq->eqn);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MTHCA_EVENT_TYPE_EEC_CATAS_ERROR:
|
|
|
|
case MTHCA_EVENT_TYPE_SRQ_CATAS_ERROR:
|
|
|
|
case MTHCA_EVENT_TYPE_LOCAL_CATAS_ERROR:
|
|
|
|
case MTHCA_EVENT_TYPE_ECC_DETECT:
|
|
|
|
default:
|
|
|
|
mthca_warn(dev, "Unhandled event %02x(%02x) on EQ %d\n",
|
|
|
|
eqe->type, eqe->subtype, eq->eqn);
|
|
|
|
break;
|
2013-10-08 23:07:22 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
set_eqe_hw(eqe);
|
|
|
|
++eq->cons_index;
|
|
|
|
eqes_found = 1;
|
2006-01-09 22:04:40 +00:00
|
|
|
++set_ci;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-01-09 22:04:40 +00:00
|
|
|
/*
|
|
|
|
* The HCA will think the queue has overflowed if we
|
|
|
|
* don't tell it we've been processing events. We
|
|
|
|
* create our EQs with MTHCA_NUM_SPARE_EQE extra
|
|
|
|
* entries, so we must update our consumer index at
|
|
|
|
* least that often.
|
|
|
|
*/
|
|
|
|
if (unlikely(set_ci >= MTHCA_NUM_SPARE_EQE)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Conditional on hca_type is OK here because
|
|
|
|
* this is a rare case, not the fast path.
|
|
|
|
*/
|
|
|
|
set_eq_ci(dev, eq, eq->cons_index);
|
|
|
|
set_ci = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Rely on caller to set consumer index so that we don't have
|
|
|
|
* to test hca_type in our interrupt handling fast path.
|
|
|
|
*/
|
|
|
|
return eqes_found;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t mthca_tavor_interrupt(int irq, void *dev_ptr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct mthca_dev *dev = dev_ptr;
|
|
|
|
u32 ecr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (dev->eq_table.clr_mask)
|
|
|
|
writel(dev->eq_table.clr_mask, dev->eq_table.clr_int);
|
|
|
|
|
|
|
|
ecr = readl(dev->eq_regs.tavor.ecr_base + 4);
|
2005-10-22 16:43:29 +00:00
|
|
|
if (!ecr)
|
|
|
|
return IRQ_NONE;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-22 16:43:29 +00:00
|
|
|
writel(ecr, dev->eq_regs.tavor.ecr_base +
|
|
|
|
MTHCA_ECR_CLR_BASE - MTHCA_ECR_BASE + 4);
|
|
|
|
|
|
|
|
for (i = 0; i < MTHCA_NUM_EQ; ++i)
|
|
|
|
if (ecr & dev->eq_table.eq[i].eqn_mask) {
|
|
|
|
if (mthca_eq_int(dev, &dev->eq_table.eq[i]))
|
2005-04-16 22:20:36 +00:00
|
|
|
tavor_set_eq_ci(dev, &dev->eq_table.eq[i],
|
|
|
|
dev->eq_table.eq[i].cons_index);
|
2005-10-22 16:43:29 +00:00
|
|
|
tavor_eq_req_not(dev, dev->eq_table.eq[i].eqn);
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-10-22 16:43:29 +00:00
|
|
|
return IRQ_HANDLED;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t mthca_tavor_msi_x_interrupt(int irq, void *eq_ptr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct mthca_eq *eq = eq_ptr;
|
|
|
|
struct mthca_dev *dev = eq->dev;
|
|
|
|
|
|
|
|
mthca_eq_int(dev, eq);
|
|
|
|
tavor_set_eq_ci(dev, eq, eq->cons_index);
|
|
|
|
tavor_eq_req_not(dev, eq->eqn);
|
|
|
|
|
|
|
|
/* MSI-X vectors always belong to us */
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t mthca_arbel_interrupt(int irq, void *dev_ptr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct mthca_dev *dev = dev_ptr;
|
|
|
|
int work = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (dev->eq_table.clr_mask)
|
|
|
|
writel(dev->eq_table.clr_mask, dev->eq_table.clr_int);
|
|
|
|
|
|
|
|
for (i = 0; i < MTHCA_NUM_EQ; ++i)
|
|
|
|
if (mthca_eq_int(dev, &dev->eq_table.eq[i])) {
|
|
|
|
work = 1;
|
|
|
|
arbel_set_eq_ci(dev, &dev->eq_table.eq[i],
|
|
|
|
dev->eq_table.eq[i].cons_index);
|
|
|
|
}
|
|
|
|
|
|
|
|
arbel_eq_req_not(dev, dev->eq_table.arm_mask);
|
|
|
|
|
|
|
|
return IRQ_RETVAL(work);
|
|
|
|
}
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t mthca_arbel_msi_x_interrupt(int irq, void *eq_ptr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct mthca_eq *eq = eq_ptr;
|
|
|
|
struct mthca_dev *dev = eq->dev;
|
|
|
|
|
|
|
|
mthca_eq_int(dev, eq);
|
|
|
|
arbel_set_eq_ci(dev, eq, eq->cons_index);
|
|
|
|
arbel_eq_req_not(dev, eq->eqn_mask);
|
|
|
|
|
|
|
|
/* MSI-X vectors always belong to us */
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2006-11-29 23:33:06 +00:00
|
|
|
static int mthca_create_eq(struct mthca_dev *dev,
|
|
|
|
int nent,
|
|
|
|
u8 intr,
|
|
|
|
struct mthca_eq *eq)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-01-06 00:17:38 +00:00
|
|
|
int npages;
|
2005-04-16 22:20:36 +00:00
|
|
|
u64 *dma_list = NULL;
|
|
|
|
dma_addr_t t;
|
2005-06-27 21:36:45 +00:00
|
|
|
struct mthca_mailbox *mailbox;
|
2005-04-16 22:20:36 +00:00
|
|
|
struct mthca_eq_context *eq_context;
|
|
|
|
int err = -ENOMEM;
|
|
|
|
int i;
|
|
|
|
|
2005-09-18 20:52:06 +00:00
|
|
|
eq->dev = dev;
|
|
|
|
eq->nent = roundup_pow_of_two(max(nent, 2));
|
2006-02-01 21:38:24 +00:00
|
|
|
npages = ALIGN(eq->nent * MTHCA_EQ_ENTRY_SIZE, PAGE_SIZE) / PAGE_SIZE;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 20:55:00 +00:00
|
|
|
eq->page_list = kmalloc_array(npages, sizeof(*eq->page_list),
|
|
|
|
GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!eq->page_list)
|
|
|
|
goto err_out;
|
|
|
|
|
|
|
|
for (i = 0; i < npages; ++i)
|
|
|
|
eq->page_list[i].buf = NULL;
|
|
|
|
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 20:55:00 +00:00
|
|
|
dma_list = kmalloc_array(npages, sizeof(*dma_list), GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!dma_list)
|
|
|
|
goto err_out_free;
|
|
|
|
|
2005-06-27 21:36:45 +00:00
|
|
|
mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
|
|
|
|
if (IS_ERR(mailbox))
|
2005-04-16 22:20:36 +00:00
|
|
|
goto err_out_free;
|
2005-06-27 21:36:45 +00:00
|
|
|
eq_context = mailbox->buf;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < npages; ++i) {
|
2005-06-27 21:36:40 +00:00
|
|
|
eq->page_list[i].buf = dma_alloc_coherent(&dev->pdev->dev,
|
|
|
|
PAGE_SIZE, &t, GFP_KERNEL);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!eq->page_list[i].buf)
|
2005-06-27 21:36:45 +00:00
|
|
|
goto err_out_free_pages;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
dma_list[i] = t;
|
2010-04-02 04:29:39 +00:00
|
|
|
dma_unmap_addr_set(&eq->page_list[i], mapping, t);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-06-18 03:16:41 +00:00
|
|
|
clear_page(eq->page_list[i].buf);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-09-18 20:52:06 +00:00
|
|
|
for (i = 0; i < eq->nent; ++i)
|
2005-04-16 22:20:36 +00:00
|
|
|
set_eqe_hw(get_eqe(eq, i));
|
|
|
|
|
|
|
|
eq->eqn = mthca_alloc(&dev->eq_table.alloc);
|
|
|
|
if (eq->eqn == -1)
|
2005-06-27 21:36:45 +00:00
|
|
|
goto err_out_free_pages;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
err = mthca_mr_alloc_phys(dev, dev->driver_pd.pd_num,
|
|
|
|
dma_list, PAGE_SHIFT, npages,
|
|
|
|
0, npages * PAGE_SIZE,
|
|
|
|
MTHCA_MPT_FLAG_LOCAL_WRITE |
|
|
|
|
MTHCA_MPT_FLAG_LOCAL_READ,
|
|
|
|
&eq->mr);
|
|
|
|
if (err)
|
|
|
|
goto err_out_free_eq;
|
|
|
|
|
|
|
|
memset(eq_context, 0, sizeof *eq_context);
|
|
|
|
eq_context->flags = cpu_to_be32(MTHCA_EQ_STATUS_OK |
|
|
|
|
MTHCA_EQ_OWNER_HW |
|
|
|
|
MTHCA_EQ_STATE_ARMED |
|
|
|
|
MTHCA_EQ_FLAG_TR);
|
2005-04-16 22:26:32 +00:00
|
|
|
if (mthca_is_memfree(dev))
|
2005-04-16 22:20:36 +00:00
|
|
|
eq_context->flags |= cpu_to_be32(MTHCA_EQ_STATE_ARBEL);
|
|
|
|
|
2005-09-18 20:52:06 +00:00
|
|
|
eq_context->logsize_usrpage = cpu_to_be32((ffs(eq->nent) - 1) << 24);
|
2005-04-16 22:26:32 +00:00
|
|
|
if (mthca_is_memfree(dev)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
eq_context->arbel_pd = cpu_to_be32(dev->driver_pd.pd_num);
|
|
|
|
} else {
|
|
|
|
eq_context->logsize_usrpage |= cpu_to_be32(dev->driver_uar.index);
|
|
|
|
eq_context->tavor_pd = cpu_to_be32(dev->driver_pd.pd_num);
|
|
|
|
}
|
|
|
|
eq_context->intr = intr;
|
|
|
|
eq_context->lkey = cpu_to_be32(eq->mr.ibmr.lkey);
|
|
|
|
|
2011-07-07 17:20:40 +00:00
|
|
|
err = mthca_SW2HW_EQ(dev, mailbox, eq->eqn);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err) {
|
2011-07-07 17:20:40 +00:00
|
|
|
mthca_warn(dev, "SW2HW_EQ returned %d\n", err);
|
2005-04-16 22:20:36 +00:00
|
|
|
goto err_out_free_mr;
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(dma_list);
|
2005-06-27 21:36:45 +00:00
|
|
|
mthca_free_mailbox(dev, mailbox);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
eq->eqn_mask = swab32(1 << eq->eqn);
|
|
|
|
eq->cons_index = 0;
|
|
|
|
|
|
|
|
dev->eq_table.arm_mask |= eq->eqn_mask;
|
|
|
|
|
|
|
|
mthca_dbg(dev, "Allocated EQ %d with %d entries\n",
|
2005-09-18 20:52:06 +00:00
|
|
|
eq->eqn, eq->nent);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err_out_free_mr:
|
|
|
|
mthca_free_mr(dev, &eq->mr);
|
|
|
|
|
|
|
|
err_out_free_eq:
|
|
|
|
mthca_free(&dev->eq_table.alloc, eq->eqn);
|
|
|
|
|
2005-06-27 21:36:45 +00:00
|
|
|
err_out_free_pages:
|
2005-04-16 22:20:36 +00:00
|
|
|
for (i = 0; i < npages; ++i)
|
|
|
|
if (eq->page_list[i].buf)
|
2005-06-27 21:36:40 +00:00
|
|
|
dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
|
|
|
|
eq->page_list[i].buf,
|
2010-04-02 04:29:39 +00:00
|
|
|
dma_unmap_addr(&eq->page_list[i],
|
2005-06-27 21:36:40 +00:00
|
|
|
mapping));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-06-27 21:36:45 +00:00
|
|
|
mthca_free_mailbox(dev, mailbox);
|
|
|
|
|
|
|
|
err_out_free:
|
2005-04-16 22:20:36 +00:00
|
|
|
kfree(eq->page_list);
|
|
|
|
kfree(dma_list);
|
|
|
|
|
|
|
|
err_out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mthca_free_eq(struct mthca_dev *dev,
|
|
|
|
struct mthca_eq *eq)
|
|
|
|
{
|
2005-06-27 21:36:45 +00:00
|
|
|
struct mthca_mailbox *mailbox;
|
2005-04-16 22:20:36 +00:00
|
|
|
int err;
|
|
|
|
int npages = (eq->nent * MTHCA_EQ_ENTRY_SIZE + PAGE_SIZE - 1) /
|
|
|
|
PAGE_SIZE;
|
|
|
|
int i;
|
|
|
|
|
2005-06-27 21:36:45 +00:00
|
|
|
mailbox = mthca_alloc_mailbox(dev, GFP_KERNEL);
|
|
|
|
if (IS_ERR(mailbox))
|
2005-04-16 22:20:36 +00:00
|
|
|
return;
|
|
|
|
|
2011-07-07 17:20:40 +00:00
|
|
|
err = mthca_HW2SW_EQ(dev, mailbox, eq->eqn);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
2011-07-07 17:20:40 +00:00
|
|
|
mthca_warn(dev, "HW2SW_EQ returned %d\n", err);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
dev->eq_table.arm_mask &= ~eq->eqn_mask;
|
|
|
|
|
|
|
|
if (0) {
|
|
|
|
mthca_dbg(dev, "Dumping EQ context %02x:\n", eq->eqn);
|
|
|
|
for (i = 0; i < sizeof (struct mthca_eq_context) / 4; ++i) {
|
|
|
|
if (i % 4 == 0)
|
|
|
|
printk("[%02x] ", i * 4);
|
2005-06-27 21:36:45 +00:00
|
|
|
printk(" %08x", be32_to_cpup(mailbox->buf + i * 4));
|
2005-04-16 22:20:36 +00:00
|
|
|
if ((i + 1) % 4 == 0)
|
|
|
|
printk("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mthca_free_mr(dev, &eq->mr);
|
|
|
|
for (i = 0; i < npages; ++i)
|
|
|
|
pci_free_consistent(dev->pdev, PAGE_SIZE,
|
|
|
|
eq->page_list[i].buf,
|
2010-04-02 04:29:39 +00:00
|
|
|
dma_unmap_addr(&eq->page_list[i], mapping));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
kfree(eq->page_list);
|
2005-06-27 21:36:45 +00:00
|
|
|
mthca_free_mailbox(dev, mailbox);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void mthca_free_irqs(struct mthca_dev *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (dev->eq_table.have_irq)
|
|
|
|
free_irq(dev->pdev->irq, dev);
|
|
|
|
for (i = 0; i < MTHCA_NUM_EQ; ++i)
|
2009-06-13 22:14:09 +00:00
|
|
|
if (dev->eq_table.eq[i].have_irq) {
|
2005-04-16 22:20:36 +00:00
|
|
|
free_irq(dev->eq_table.eq[i].msi_x_vector,
|
|
|
|
dev->eq_table.eq + i);
|
2009-06-13 22:14:09 +00:00
|
|
|
dev->eq_table.eq[i].have_irq = 0;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-11-29 23:33:06 +00:00
|
|
|
static int mthca_map_reg(struct mthca_dev *dev,
|
|
|
|
unsigned long offset, unsigned long size,
|
|
|
|
void __iomem **map)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-01-12 04:39:46 +00:00
|
|
|
phys_addr_t base = pci_resource_start(dev->pdev, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
*map = ioremap(base + offset, size);
|
2008-09-30 04:37:33 +00:00
|
|
|
if (!*map)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-11-29 23:33:06 +00:00
|
|
|
static int mthca_map_eq_regs(struct mthca_dev *dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-04-16 22:26:32 +00:00
|
|
|
if (mthca_is_memfree(dev)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* We assume that the EQ arm and EQ set CI registers
|
|
|
|
* fall within the first BAR. We can't trust the
|
|
|
|
* values firmware gives us, since those addresses are
|
|
|
|
* valid on the HCA's side of the PCI bus but not
|
|
|
|
* necessarily the host side.
|
|
|
|
*/
|
|
|
|
if (mthca_map_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) &
|
|
|
|
dev->fw.arbel.clr_int_base, MTHCA_CLR_INT_SIZE,
|
|
|
|
&dev->clr_base)) {
|
|
|
|
mthca_err(dev, "Couldn't map interrupt clear register, "
|
|
|
|
"aborting.\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add 4 because we limit ourselves to EQs 0 ... 31,
|
|
|
|
* so we only need the low word of the register.
|
|
|
|
*/
|
|
|
|
if (mthca_map_reg(dev, ((pci_resource_len(dev->pdev, 0) - 1) &
|
|
|
|
dev->fw.arbel.eq_arm_base) + 4, 4,
|
|
|
|
&dev->eq_regs.arbel.eq_arm)) {
|
2005-06-27 21:36:39 +00:00
|
|
|
mthca_err(dev, "Couldn't map EQ arm register, aborting.\n");
|
2008-09-30 04:37:33 +00:00
|
|
|
iounmap(dev->clr_base);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mthca_map_reg(dev, (pci_resource_len(dev->pdev, 0) - 1) &
|
|
|
|
dev->fw.arbel.eq_set_ci_base,
|
|
|
|
MTHCA_EQ_SET_CI_SIZE,
|
|
|
|
&dev->eq_regs.arbel.eq_set_ci_base)) {
|
2005-06-27 21:36:39 +00:00
|
|
|
mthca_err(dev, "Couldn't map EQ CI register, aborting.\n");
|
2008-09-30 04:37:33 +00:00
|
|
|
iounmap(dev->eq_regs.arbel.eq_arm);
|
|
|
|
iounmap(dev->clr_base);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (mthca_map_reg(dev, MTHCA_CLR_INT_BASE, MTHCA_CLR_INT_SIZE,
|
|
|
|
&dev->clr_base)) {
|
|
|
|
mthca_err(dev, "Couldn't map interrupt clear register, "
|
|
|
|
"aborting.\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mthca_map_reg(dev, MTHCA_ECR_BASE,
|
|
|
|
MTHCA_ECR_SIZE + MTHCA_ECR_CLR_SIZE,
|
|
|
|
&dev->eq_regs.tavor.ecr_base)) {
|
|
|
|
mthca_err(dev, "Couldn't map ecr register, "
|
|
|
|
"aborting.\n");
|
2008-09-30 04:37:33 +00:00
|
|
|
iounmap(dev->clr_base);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-03-29 17:36:46 +00:00
|
|
|
static void mthca_unmap_eq_regs(struct mthca_dev *dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-04-16 22:26:32 +00:00
|
|
|
if (mthca_is_memfree(dev)) {
|
2008-09-30 04:37:33 +00:00
|
|
|
iounmap(dev->eq_regs.arbel.eq_set_ci_base);
|
|
|
|
iounmap(dev->eq_regs.arbel.eq_arm);
|
|
|
|
iounmap(dev->clr_base);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
2008-09-30 04:37:33 +00:00
|
|
|
iounmap(dev->eq_regs.tavor.ecr_base);
|
|
|
|
iounmap(dev->clr_base);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-11-29 23:33:06 +00:00
|
|
|
int mthca_map_eq_icm(struct mthca_dev *dev, u64 icm_virt)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We assume that mapping one page is enough for the whole EQ
|
|
|
|
* context table. This is fine with all current HCAs, because
|
|
|
|
* we only use 32 EQs and each EQ uses 32 bytes of context
|
|
|
|
* memory, or 1 KB total.
|
|
|
|
*/
|
|
|
|
dev->eq_table.icm_virt = icm_virt;
|
|
|
|
dev->eq_table.icm_page = alloc_page(GFP_HIGHUSER);
|
|
|
|
if (!dev->eq_table.icm_page)
|
|
|
|
return -ENOMEM;
|
|
|
|
dev->eq_table.icm_dma = pci_map_page(dev->pdev, dev->eq_table.icm_page, 0,
|
|
|
|
PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
|
2008-07-26 02:44:49 +00:00
|
|
|
if (pci_dma_mapping_error(dev->pdev, dev->eq_table.icm_dma)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
__free_page(dev->eq_table.icm_page);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
2011-07-07 17:20:40 +00:00
|
|
|
ret = mthca_MAP_ICM_page(dev, dev->eq_table.icm_dma, icm_virt);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (ret) {
|
|
|
|
pci_unmap_page(dev->pdev, dev->eq_table.icm_dma, PAGE_SIZE,
|
|
|
|
PCI_DMA_BIDIRECTIONAL);
|
|
|
|
__free_page(dev->eq_table.icm_page);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-03-29 17:36:46 +00:00
|
|
|
void mthca_unmap_eq_icm(struct mthca_dev *dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2011-07-07 17:20:40 +00:00
|
|
|
mthca_UNMAP_ICM(dev, dev->eq_table.icm_virt, 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
pci_unmap_page(dev->pdev, dev->eq_table.icm_dma, PAGE_SIZE,
|
|
|
|
PCI_DMA_BIDIRECTIONAL);
|
|
|
|
__free_page(dev->eq_table.icm_page);
|
|
|
|
}
|
|
|
|
|
2006-11-29 23:33:06 +00:00
|
|
|
int mthca_init_eq_table(struct mthca_dev *dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
u8 intr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
err = mthca_alloc_init(&dev->eq_table.alloc,
|
|
|
|
dev->limits.num_eqs,
|
|
|
|
dev->limits.num_eqs - 1,
|
|
|
|
dev->limits.reserved_eqs);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
err = mthca_map_eq_regs(dev);
|
|
|
|
if (err)
|
|
|
|
goto err_out_free;
|
|
|
|
|
2008-01-01 13:47:10 +00:00
|
|
|
if (dev->mthca_flags & MTHCA_FLAG_MSI_X) {
|
2005-04-16 22:20:36 +00:00
|
|
|
dev->eq_table.clr_mask = 0;
|
|
|
|
} else {
|
|
|
|
dev->eq_table.clr_mask =
|
|
|
|
swab32(1 << (dev->eq_table.inta_pin & 31));
|
|
|
|
dev->eq_table.clr_int = dev->clr_base +
|
2005-09-26 16:29:33 +00:00
|
|
|
(dev->eq_table.inta_pin < 32 ? 4 : 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dev->eq_table.arm_mask = 0;
|
|
|
|
|
2008-01-01 13:47:10 +00:00
|
|
|
intr = dev->eq_table.inta_pin;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-01-09 22:04:40 +00:00
|
|
|
err = mthca_create_eq(dev, dev->limits.num_cqs + MTHCA_NUM_SPARE_EQE,
|
2005-04-16 22:20:36 +00:00
|
|
|
(dev->mthca_flags & MTHCA_FLAG_MSI_X) ? 128 : intr,
|
|
|
|
&dev->eq_table.eq[MTHCA_EQ_COMP]);
|
|
|
|
if (err)
|
|
|
|
goto err_out_unmap;
|
|
|
|
|
2006-01-09 22:04:40 +00:00
|
|
|
err = mthca_create_eq(dev, MTHCA_NUM_ASYNC_EQE + MTHCA_NUM_SPARE_EQE,
|
2005-04-16 22:20:36 +00:00
|
|
|
(dev->mthca_flags & MTHCA_FLAG_MSI_X) ? 129 : intr,
|
|
|
|
&dev->eq_table.eq[MTHCA_EQ_ASYNC]);
|
|
|
|
if (err)
|
|
|
|
goto err_out_comp;
|
|
|
|
|
2006-01-09 22:04:40 +00:00
|
|
|
err = mthca_create_eq(dev, MTHCA_NUM_CMD_EQE + MTHCA_NUM_SPARE_EQE,
|
2005-04-16 22:20:36 +00:00
|
|
|
(dev->mthca_flags & MTHCA_FLAG_MSI_X) ? 130 : intr,
|
|
|
|
&dev->eq_table.eq[MTHCA_EQ_CMD]);
|
|
|
|
if (err)
|
|
|
|
goto err_out_async;
|
|
|
|
|
|
|
|
if (dev->mthca_flags & MTHCA_FLAG_MSI_X) {
|
|
|
|
static const char *eq_name[] = {
|
2009-09-06 03:36:15 +00:00
|
|
|
[MTHCA_EQ_COMP] = DRV_NAME "-comp",
|
|
|
|
[MTHCA_EQ_ASYNC] = DRV_NAME "-async",
|
|
|
|
[MTHCA_EQ_CMD] = DRV_NAME "-cmd"
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (i = 0; i < MTHCA_NUM_EQ; ++i) {
|
2009-09-06 03:36:15 +00:00
|
|
|
snprintf(dev->eq_table.eq[i].irq_name,
|
|
|
|
IB_DEVICE_NAME_MAX,
|
|
|
|
"%s@pci:%s", eq_name[i],
|
|
|
|
pci_name(dev->pdev));
|
2005-04-16 22:20:36 +00:00
|
|
|
err = request_irq(dev->eq_table.eq[i].msi_x_vector,
|
2005-04-16 22:26:32 +00:00
|
|
|
mthca_is_memfree(dev) ?
|
2005-04-16 22:20:36 +00:00
|
|
|
mthca_arbel_msi_x_interrupt :
|
|
|
|
mthca_tavor_msi_x_interrupt,
|
2009-09-06 03:36:15 +00:00
|
|
|
0, dev->eq_table.eq[i].irq_name,
|
|
|
|
dev->eq_table.eq + i);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
|
|
|
goto err_out_cmd;
|
|
|
|
dev->eq_table.eq[i].have_irq = 1;
|
|
|
|
}
|
|
|
|
} else {
|
2009-09-06 03:36:15 +00:00
|
|
|
snprintf(dev->eq_table.eq[0].irq_name, IB_DEVICE_NAME_MAX,
|
|
|
|
DRV_NAME "@pci:%s", pci_name(dev->pdev));
|
2005-04-16 22:20:36 +00:00
|
|
|
err = request_irq(dev->pdev->irq,
|
2005-04-16 22:26:32 +00:00
|
|
|
mthca_is_memfree(dev) ?
|
2005-04-16 22:20:36 +00:00
|
|
|
mthca_arbel_interrupt :
|
|
|
|
mthca_tavor_interrupt,
|
2009-09-06 03:36:15 +00:00
|
|
|
IRQF_SHARED, dev->eq_table.eq[0].irq_name, dev);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
|
|
|
goto err_out_cmd;
|
|
|
|
dev->eq_table.have_irq = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = mthca_MAP_EQ(dev, async_mask(dev),
|
2011-07-07 17:20:40 +00:00
|
|
|
0, dev->eq_table.eq[MTHCA_EQ_ASYNC].eqn);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
|
|
|
mthca_warn(dev, "MAP_EQ for async EQ %d failed (%d)\n",
|
|
|
|
dev->eq_table.eq[MTHCA_EQ_ASYNC].eqn, err);
|
|
|
|
|
|
|
|
err = mthca_MAP_EQ(dev, MTHCA_CMD_EVENT_MASK,
|
2011-07-07 17:20:40 +00:00
|
|
|
0, dev->eq_table.eq[MTHCA_EQ_CMD].eqn);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (err)
|
|
|
|
mthca_warn(dev, "MAP_EQ for cmd EQ %d failed (%d)\n",
|
|
|
|
dev->eq_table.eq[MTHCA_EQ_CMD].eqn, err);
|
|
|
|
|
2006-03-20 18:08:25 +00:00
|
|
|
for (i = 0; i < MTHCA_NUM_EQ; ++i)
|
2005-04-16 22:26:32 +00:00
|
|
|
if (mthca_is_memfree(dev))
|
2005-04-16 22:20:36 +00:00
|
|
|
arbel_eq_req_not(dev, dev->eq_table.eq[i].eqn_mask);
|
|
|
|
else
|
|
|
|
tavor_eq_req_not(dev, dev->eq_table.eq[i].eqn);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_out_cmd:
|
|
|
|
mthca_free_irqs(dev);
|
|
|
|
mthca_free_eq(dev, &dev->eq_table.eq[MTHCA_EQ_CMD]);
|
|
|
|
|
|
|
|
err_out_async:
|
|
|
|
mthca_free_eq(dev, &dev->eq_table.eq[MTHCA_EQ_ASYNC]);
|
|
|
|
|
|
|
|
err_out_comp:
|
|
|
|
mthca_free_eq(dev, &dev->eq_table.eq[MTHCA_EQ_COMP]);
|
|
|
|
|
|
|
|
err_out_unmap:
|
|
|
|
mthca_unmap_eq_regs(dev);
|
|
|
|
|
|
|
|
err_out_free:
|
|
|
|
mthca_alloc_cleanup(&dev->eq_table.alloc);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2006-03-29 17:36:46 +00:00
|
|
|
void mthca_cleanup_eq_table(struct mthca_dev *dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mthca_free_irqs(dev);
|
|
|
|
|
|
|
|
mthca_MAP_EQ(dev, async_mask(dev),
|
2011-07-07 17:20:40 +00:00
|
|
|
1, dev->eq_table.eq[MTHCA_EQ_ASYNC].eqn);
|
2005-04-16 22:20:36 +00:00
|
|
|
mthca_MAP_EQ(dev, MTHCA_CMD_EVENT_MASK,
|
2011-07-07 17:20:40 +00:00
|
|
|
1, dev->eq_table.eq[MTHCA_EQ_CMD].eqn);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < MTHCA_NUM_EQ; ++i)
|
|
|
|
mthca_free_eq(dev, &dev->eq_table.eq[i]);
|
|
|
|
|
|
|
|
mthca_unmap_eq_regs(dev);
|
|
|
|
|
|
|
|
mthca_alloc_cleanup(&dev->eq_table.alloc);
|
|
|
|
}
|