blob: d954ec1eac173752e23e57653ccd4d2cae2de944 [file] [log] [blame]
Roland Dreier225c7b12007-05-08 18:00:38 -07001/*
Jack Morgenstein51a379d2008-07-25 10:32:52 -07002 * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
Roland Dreier225c7b12007-05-08 18:00:38 -07003 * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
4 *
5 * This software is available to you under a choice of one of two
6 * licenses. You may choose to be licensed under the terms of the GNU
7 * General Public License (GPL) Version 2, available from the file
8 * COPYING in the main directory of this source tree, or the
9 * OpenIB.org BSD license below:
10 *
11 * Redistribution and use in source and binary forms, with or
12 * without modification, are permitted provided that the following
13 * conditions are met:
14 *
15 * - Redistributions of source code must retain the above
16 * copyright notice, this list of conditions and the following
17 * disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials
22 * provided with the distribution.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
28 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
29 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
30 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
32 */
33
Roland Dreier225c7b12007-05-08 18:00:38 -070034#include <linux/interrupt.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090035#include <linux/slab.h>
Paul Gortmakeree40fa02011-05-27 16:14:23 -040036#include <linux/export.h>
Andrea Righi27ac7922008-07-23 21:28:13 -070037#include <linux/mm.h>
Al Viro9cbe05c2007-05-15 20:36:30 +010038#include <linux/dma-mapping.h>
Roland Dreier225c7b12007-05-08 18:00:38 -070039
40#include <linux/mlx4/cmd.h>
Amir Vadaid9236c32012-07-18 22:33:51 +000041#include <linux/cpu_rmap.h>
Roland Dreier225c7b12007-05-08 18:00:38 -070042
43#include "mlx4.h"
44#include "fw.h"
45
46enum {
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +000047 MLX4_IRQNAME_SIZE = 32
Arputham Benjaminf5f59512009-09-05 20:24:50 -070048};
49
50enum {
Roland Dreier225c7b12007-05-08 18:00:38 -070051 MLX4_NUM_ASYNC_EQE = 0x100,
52 MLX4_NUM_SPARE_EQE = 0x80,
53 MLX4_EQ_ENTRY_SIZE = 0x20
54};
55
Yuval Atias2eacc232014-05-14 12:15:10 +030056struct mlx4_irq_notify {
57 void *arg;
58 struct irq_affinity_notify notify;
59};
60
Roland Dreier225c7b12007-05-08 18:00:38 -070061#define MLX4_EQ_STATUS_OK ( 0 << 28)
62#define MLX4_EQ_STATUS_WRITE_FAIL (10 << 28)
63#define MLX4_EQ_OWNER_SW ( 0 << 24)
64#define MLX4_EQ_OWNER_HW ( 1 << 24)
65#define MLX4_EQ_FLAG_EC ( 1 << 18)
66#define MLX4_EQ_FLAG_OI ( 1 << 17)
67#define MLX4_EQ_STATE_ARMED ( 9 << 8)
68#define MLX4_EQ_STATE_FIRED (10 << 8)
69#define MLX4_EQ_STATE_ALWAYS_ARMED (11 << 8)
70
71#define MLX4_ASYNC_EVENT_MASK ((1ull << MLX4_EVENT_TYPE_PATH_MIG) | \
72 (1ull << MLX4_EVENT_TYPE_COMM_EST) | \
73 (1ull << MLX4_EVENT_TYPE_SQ_DRAINED) | \
74 (1ull << MLX4_EVENT_TYPE_CQ_ERROR) | \
75 (1ull << MLX4_EVENT_TYPE_WQ_CATAS_ERROR) | \
76 (1ull << MLX4_EVENT_TYPE_EEC_CATAS_ERROR) | \
77 (1ull << MLX4_EVENT_TYPE_PATH_MIG_FAILED) | \
78 (1ull << MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR) | \
79 (1ull << MLX4_EVENT_TYPE_WQ_ACCESS_ERROR) | \
Roland Dreier225c7b12007-05-08 18:00:38 -070080 (1ull << MLX4_EVENT_TYPE_PORT_CHANGE) | \
81 (1ull << MLX4_EVENT_TYPE_ECC_DETECT) | \
82 (1ull << MLX4_EVENT_TYPE_SRQ_CATAS_ERROR) | \
83 (1ull << MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE) | \
84 (1ull << MLX4_EVENT_TYPE_SRQ_LIMIT) | \
Jack Morgensteinacba2422011-12-13 04:13:58 +000085 (1ull << MLX4_EVENT_TYPE_CMD) | \
Yevgeny Petrilinfe6f7002013-07-28 18:54:21 +030086 (1ull << MLX4_EVENT_TYPE_OP_REQUIRED) | \
Jack Morgensteinacba2422011-12-13 04:13:58 +000087 (1ull << MLX4_EVENT_TYPE_COMM_CHANNEL) | \
Jack Morgenstein5984be92012-03-06 15:50:49 +020088 (1ull << MLX4_EVENT_TYPE_FLR_EVENT) | \
89 (1ull << MLX4_EVENT_TYPE_FATAL_WARNING))
Roland Dreier225c7b12007-05-08 18:00:38 -070090
Jack Morgenstein00f5ce92012-06-19 11:21:40 +030091static u64 get_async_ev_mask(struct mlx4_dev *dev)
92{
93 u64 async_ev_mask = MLX4_ASYNC_EVENT_MASK;
94 if (dev->caps.flags & MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV)
95 async_ev_mask |= (1ull << MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT);
96
97 return async_ev_mask;
98}
99
Roland Dreier225c7b12007-05-08 18:00:38 -0700100static void eq_set_ci(struct mlx4_eq *eq, int req_not)
101{
102 __raw_writel((__force u32) cpu_to_be32((eq->cons_index & 0xffffff) |
103 req_not << 31),
104 eq->doorbell);
105 /* We still want ordering, just not swabbing, so add a barrier */
106 mb();
107}
108
Or Gerlitz08ff3232012-10-21 14:59:24 +0000109static struct mlx4_eqe *get_eqe(struct mlx4_eq *eq, u32 entry, u8 eqe_factor)
Roland Dreier225c7b12007-05-08 18:00:38 -0700110{
Or Gerlitz08ff3232012-10-21 14:59:24 +0000111 /* (entry & (eq->nent - 1)) gives us a cyclic array */
112 unsigned long offset = (entry & (eq->nent - 1)) * (MLX4_EQ_ENTRY_SIZE << eqe_factor);
113 /* CX3 is capable of extending the EQE from 32 to 64 bytes.
114 * When this feature is enabled, the first (in the lower addresses)
115 * 32 bytes in the 64 byte EQE are reserved and the next 32 bytes
116 * contain the legacy EQE information.
117 */
118 return eq->page_list[offset / PAGE_SIZE].buf + (offset + (eqe_factor ? MLX4_EQ_ENTRY_SIZE : 0)) % PAGE_SIZE;
Roland Dreier225c7b12007-05-08 18:00:38 -0700119}
120
Or Gerlitz08ff3232012-10-21 14:59:24 +0000121static struct mlx4_eqe *next_eqe_sw(struct mlx4_eq *eq, u8 eqe_factor)
Roland Dreier225c7b12007-05-08 18:00:38 -0700122{
Or Gerlitz08ff3232012-10-21 14:59:24 +0000123 struct mlx4_eqe *eqe = get_eqe(eq, eq->cons_index, eqe_factor);
Roland Dreier225c7b12007-05-08 18:00:38 -0700124 return !!(eqe->owner & 0x80) ^ !!(eq->cons_index & eq->nent) ? NULL : eqe;
125}
126
Jack Morgensteinacba2422011-12-13 04:13:58 +0000127static struct mlx4_eqe *next_slave_event_eqe(struct mlx4_slave_event_eq *slave_eq)
128{
129 struct mlx4_eqe *eqe =
130 &slave_eq->event_eqe[slave_eq->cons & (SLAVE_EVENT_EQ_SIZE - 1)];
131 return (!!(eqe->owner & 0x80) ^
132 !!(slave_eq->cons & SLAVE_EVENT_EQ_SIZE)) ?
133 eqe : NULL;
134}
135
Jack Morgensteinacba2422011-12-13 04:13:58 +0000136void mlx4_gen_slave_eqe(struct work_struct *work)
137{
138 struct mlx4_mfunc_master_ctx *master =
139 container_of(work, struct mlx4_mfunc_master_ctx,
140 slave_event_work);
141 struct mlx4_mfunc *mfunc =
142 container_of(master, struct mlx4_mfunc, master);
143 struct mlx4_priv *priv = container_of(mfunc, struct mlx4_priv, mfunc);
144 struct mlx4_dev *dev = &priv->dev;
145 struct mlx4_slave_event_eq *slave_eq = &mfunc->master.slave_eq;
146 struct mlx4_eqe *eqe;
147 u8 slave;
148 int i;
149
150 for (eqe = next_slave_event_eqe(slave_eq); eqe;
151 eqe = next_slave_event_eqe(slave_eq)) {
152 slave = eqe->slave_id;
153
154 /* All active slaves need to receive the event */
155 if (slave == ALL_SLAVES) {
156 for (i = 0; i < dev->num_slaves; i++) {
157 if (i != dev->caps.function &&
158 master->slave_state[i].active)
159 if (mlx4_GEN_EQE(dev, i, eqe))
Joe Perches1a91de22014-05-07 12:52:57 -0700160 mlx4_warn(dev, "Failed to generate event for slave %d\n",
161 i);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000162 }
163 } else {
164 if (mlx4_GEN_EQE(dev, slave, eqe))
Joe Perches1a91de22014-05-07 12:52:57 -0700165 mlx4_warn(dev, "Failed to generate event for slave %d\n",
166 slave);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000167 }
168 ++slave_eq->cons;
169 }
170}
171
172
173static void slave_event(struct mlx4_dev *dev, u8 slave, struct mlx4_eqe *eqe)
174{
175 struct mlx4_priv *priv = mlx4_priv(dev);
176 struct mlx4_slave_event_eq *slave_eq = &priv->mfunc.master.slave_eq;
Jack Morgenstein992e8e6e2012-08-03 08:40:54 +0000177 struct mlx4_eqe *s_eqe;
178 unsigned long flags;
Jack Morgensteinacba2422011-12-13 04:13:58 +0000179
Jack Morgenstein992e8e6e2012-08-03 08:40:54 +0000180 spin_lock_irqsave(&slave_eq->event_lock, flags);
181 s_eqe = &slave_eq->event_eqe[slave_eq->prod & (SLAVE_EVENT_EQ_SIZE - 1)];
Jack Morgensteinacba2422011-12-13 04:13:58 +0000182 if ((!!(s_eqe->owner & 0x80)) ^
183 (!!(slave_eq->prod & SLAVE_EVENT_EQ_SIZE))) {
Joe Perches1a91de22014-05-07 12:52:57 -0700184 mlx4_warn(dev, "Master failed to generate an EQE for slave: %d. No free EQE on slave events queue\n",
185 slave);
Jack Morgenstein992e8e6e2012-08-03 08:40:54 +0000186 spin_unlock_irqrestore(&slave_eq->event_lock, flags);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000187 return;
188 }
189
Or Gerlitz08ff3232012-10-21 14:59:24 +0000190 memcpy(s_eqe, eqe, dev->caps.eqe_size - 1);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000191 s_eqe->slave_id = slave;
192 /* ensure all information is written before setting the ownersip bit */
193 wmb();
194 s_eqe->owner = !!(slave_eq->prod & SLAVE_EVENT_EQ_SIZE) ? 0x0 : 0x80;
195 ++slave_eq->prod;
196
197 queue_work(priv->mfunc.master.comm_wq,
198 &priv->mfunc.master.slave_event_work);
Jack Morgenstein992e8e6e2012-08-03 08:40:54 +0000199 spin_unlock_irqrestore(&slave_eq->event_lock, flags);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000200}
201
202static void mlx4_slave_event(struct mlx4_dev *dev, int slave,
203 struct mlx4_eqe *eqe)
204{
205 struct mlx4_priv *priv = mlx4_priv(dev);
206 struct mlx4_slave_state *s_slave =
207 &priv->mfunc.master.slave_state[slave];
208
209 if (!s_slave->active) {
210 /*mlx4_warn(dev, "Trying to pass event to inactive slave\n");*/
211 return;
212 }
213
214 slave_event(dev, slave, eqe);
215}
216
Jack Morgenstein993c4012012-08-03 08:40:48 +0000217int mlx4_gen_pkey_eqe(struct mlx4_dev *dev, int slave, u8 port)
218{
219 struct mlx4_eqe eqe;
220
221 struct mlx4_priv *priv = mlx4_priv(dev);
222 struct mlx4_slave_state *s_slave = &priv->mfunc.master.slave_state[slave];
223
224 if (!s_slave->active)
225 return 0;
226
227 memset(&eqe, 0, sizeof eqe);
228
229 eqe.type = MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT;
230 eqe.subtype = MLX4_DEV_PMC_SUBTYPE_PKEY_TABLE;
231 eqe.event.port_mgmt_change.port = port;
232
233 return mlx4_GEN_EQE(dev, slave, &eqe);
234}
235EXPORT_SYMBOL(mlx4_gen_pkey_eqe);
236
237int mlx4_gen_guid_change_eqe(struct mlx4_dev *dev, int slave, u8 port)
238{
239 struct mlx4_eqe eqe;
240
241 /*don't send if we don't have the that slave */
242 if (dev->num_vfs < slave)
243 return 0;
244 memset(&eqe, 0, sizeof eqe);
245
246 eqe.type = MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT;
247 eqe.subtype = MLX4_DEV_PMC_SUBTYPE_GUID_INFO;
248 eqe.event.port_mgmt_change.port = port;
249
250 return mlx4_GEN_EQE(dev, slave, &eqe);
251}
252EXPORT_SYMBOL(mlx4_gen_guid_change_eqe);
253
254int mlx4_gen_port_state_change_eqe(struct mlx4_dev *dev, int slave, u8 port,
255 u8 port_subtype_change)
256{
257 struct mlx4_eqe eqe;
258
259 /*don't send if we don't have the that slave */
260 if (dev->num_vfs < slave)
261 return 0;
262 memset(&eqe, 0, sizeof eqe);
263
264 eqe.type = MLX4_EVENT_TYPE_PORT_CHANGE;
265 eqe.subtype = port_subtype_change;
266 eqe.event.port_change.port = cpu_to_be32(port << 28);
267
268 mlx4_dbg(dev, "%s: sending: %d to slave: %d on port: %d\n", __func__,
269 port_subtype_change, slave, port);
270 return mlx4_GEN_EQE(dev, slave, &eqe);
271}
272EXPORT_SYMBOL(mlx4_gen_port_state_change_eqe);
273
274enum slave_port_state mlx4_get_slave_port_state(struct mlx4_dev *dev, int slave, u8 port)
275{
276 struct mlx4_priv *priv = mlx4_priv(dev);
277 struct mlx4_slave_state *s_state = priv->mfunc.master.slave_state;
Matan Barak449fc482014-03-19 18:11:52 +0200278 struct mlx4_active_ports actv_ports = mlx4_get_active_ports(dev, slave);
279
280 if (slave >= dev->num_slaves || port > dev->caps.num_ports ||
281 port <= 0 || !test_bit(port - 1, actv_ports.ports)) {
Jack Morgenstein993c4012012-08-03 08:40:48 +0000282 pr_err("%s: Error: asking for slave:%d, port:%d\n",
283 __func__, slave, port);
284 return SLAVE_PORT_DOWN;
285 }
286 return s_state[slave].port_state[port];
287}
288EXPORT_SYMBOL(mlx4_get_slave_port_state);
289
290static int mlx4_set_slave_port_state(struct mlx4_dev *dev, int slave, u8 port,
291 enum slave_port_state state)
292{
293 struct mlx4_priv *priv = mlx4_priv(dev);
294 struct mlx4_slave_state *s_state = priv->mfunc.master.slave_state;
Matan Barak449fc482014-03-19 18:11:52 +0200295 struct mlx4_active_ports actv_ports = mlx4_get_active_ports(dev, slave);
Jack Morgenstein993c4012012-08-03 08:40:48 +0000296
Matan Barak449fc482014-03-19 18:11:52 +0200297 if (slave >= dev->num_slaves || port > dev->caps.num_ports ||
298 port <= 0 || !test_bit(port - 1, actv_ports.ports)) {
Jack Morgenstein993c4012012-08-03 08:40:48 +0000299 pr_err("%s: Error: asking for slave:%d, port:%d\n",
300 __func__, slave, port);
301 return -1;
302 }
303 s_state[slave].port_state[port] = state;
304
305 return 0;
306}
307
308static void set_all_slave_state(struct mlx4_dev *dev, u8 port, int event)
309{
310 int i;
311 enum slave_port_gen_event gen_event;
Matan Barak449fc482014-03-19 18:11:52 +0200312 struct mlx4_slaves_pport slaves_pport = mlx4_phys_to_slaves_pport(dev,
313 port);
Jack Morgenstein993c4012012-08-03 08:40:48 +0000314
Matan Barak449fc482014-03-19 18:11:52 +0200315 for (i = 0; i < dev->num_vfs + 1; i++)
316 if (test_bit(i, slaves_pport.slaves))
317 set_and_calc_slave_port_state(dev, i, port,
318 event, &gen_event);
Jack Morgenstein993c4012012-08-03 08:40:48 +0000319}
320/**************************************************************************
321 The function get as input the new event to that port,
322 and according to the prev state change the slave's port state.
323 The events are:
324 MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN,
325 MLX4_PORT_STATE_DEV_EVENT_PORT_UP
326 MLX4_PORT_STATE_IB_EVENT_GID_VALID
327 MLX4_PORT_STATE_IB_EVENT_GID_INVALID
328***************************************************************************/
329int set_and_calc_slave_port_state(struct mlx4_dev *dev, int slave,
330 u8 port, int event,
331 enum slave_port_gen_event *gen_event)
332{
333 struct mlx4_priv *priv = mlx4_priv(dev);
334 struct mlx4_slave_state *ctx = NULL;
335 unsigned long flags;
336 int ret = -1;
Matan Barak449fc482014-03-19 18:11:52 +0200337 struct mlx4_active_ports actv_ports = mlx4_get_active_ports(dev, slave);
Jack Morgenstein993c4012012-08-03 08:40:48 +0000338 enum slave_port_state cur_state =
339 mlx4_get_slave_port_state(dev, slave, port);
340
341 *gen_event = SLAVE_PORT_GEN_EVENT_NONE;
342
Matan Barak449fc482014-03-19 18:11:52 +0200343 if (slave >= dev->num_slaves || port > dev->caps.num_ports ||
344 port <= 0 || !test_bit(port - 1, actv_ports.ports)) {
Jack Morgenstein993c4012012-08-03 08:40:48 +0000345 pr_err("%s: Error: asking for slave:%d, port:%d\n",
346 __func__, slave, port);
347 return ret;
348 }
349
350 ctx = &priv->mfunc.master.slave_state[slave];
351 spin_lock_irqsave(&ctx->lock, flags);
352
Jack Morgenstein993c4012012-08-03 08:40:48 +0000353 switch (cur_state) {
354 case SLAVE_PORT_DOWN:
355 if (MLX4_PORT_STATE_DEV_EVENT_PORT_UP == event)
356 mlx4_set_slave_port_state(dev, slave, port,
357 SLAVE_PENDING_UP);
358 break;
359 case SLAVE_PENDING_UP:
360 if (MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN == event)
361 mlx4_set_slave_port_state(dev, slave, port,
362 SLAVE_PORT_DOWN);
363 else if (MLX4_PORT_STATE_IB_PORT_STATE_EVENT_GID_VALID == event) {
364 mlx4_set_slave_port_state(dev, slave, port,
365 SLAVE_PORT_UP);
366 *gen_event = SLAVE_PORT_GEN_EVENT_UP;
367 }
368 break;
369 case SLAVE_PORT_UP:
370 if (MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN == event) {
371 mlx4_set_slave_port_state(dev, slave, port,
372 SLAVE_PORT_DOWN);
373 *gen_event = SLAVE_PORT_GEN_EVENT_DOWN;
374 } else if (MLX4_PORT_STATE_IB_EVENT_GID_INVALID ==
375 event) {
376 mlx4_set_slave_port_state(dev, slave, port,
377 SLAVE_PENDING_UP);
378 *gen_event = SLAVE_PORT_GEN_EVENT_DOWN;
379 }
380 break;
381 default:
Joe Perches1a91de22014-05-07 12:52:57 -0700382 pr_err("%s: BUG!!! UNKNOWN state: slave:%d, port:%d\n",
383 __func__, slave, port);
384 goto out;
Jack Morgenstein993c4012012-08-03 08:40:48 +0000385 }
386 ret = mlx4_get_slave_port_state(dev, slave, port);
Jack Morgenstein993c4012012-08-03 08:40:48 +0000387
388out:
389 spin_unlock_irqrestore(&ctx->lock, flags);
390 return ret;
391}
392
393EXPORT_SYMBOL(set_and_calc_slave_port_state);
394
395int mlx4_gen_slaves_port_mgt_ev(struct mlx4_dev *dev, u8 port, int attr)
396{
397 struct mlx4_eqe eqe;
398
399 memset(&eqe, 0, sizeof eqe);
400
401 eqe.type = MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT;
402 eqe.subtype = MLX4_DEV_PMC_SUBTYPE_PORT_INFO;
403 eqe.event.port_mgmt_change.port = port;
404 eqe.event.port_mgmt_change.params.port_info.changed_attr =
405 cpu_to_be32((u32) attr);
406
407 slave_event(dev, ALL_SLAVES, &eqe);
408 return 0;
409}
410EXPORT_SYMBOL(mlx4_gen_slaves_port_mgt_ev);
411
Jack Morgensteinacba2422011-12-13 04:13:58 +0000412void mlx4_master_handle_slave_flr(struct work_struct *work)
413{
414 struct mlx4_mfunc_master_ctx *master =
415 container_of(work, struct mlx4_mfunc_master_ctx,
416 slave_flr_event_work);
417 struct mlx4_mfunc *mfunc =
418 container_of(master, struct mlx4_mfunc, master);
419 struct mlx4_priv *priv =
420 container_of(mfunc, struct mlx4_priv, mfunc);
421 struct mlx4_dev *dev = &priv->dev;
422 struct mlx4_slave_state *slave_state = priv->mfunc.master.slave_state;
423 int i;
424 int err;
Jack Morgenstein311f8132012-11-27 16:24:30 +0000425 unsigned long flags;
Jack Morgensteinacba2422011-12-13 04:13:58 +0000426
427 mlx4_dbg(dev, "mlx4_handle_slave_flr\n");
428
429 for (i = 0 ; i < dev->num_slaves; i++) {
430
431 if (MLX4_COMM_CMD_FLR == slave_state[i].last_cmd) {
Joe Perches1a91de22014-05-07 12:52:57 -0700432 mlx4_dbg(dev, "mlx4_handle_slave_flr: clean slave: %d\n",
433 i);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000434
435 mlx4_delete_all_resources_for_slave(dev, i);
436 /*return the slave to running mode*/
Jack Morgenstein311f8132012-11-27 16:24:30 +0000437 spin_lock_irqsave(&priv->mfunc.master.slave_state_lock, flags);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000438 slave_state[i].last_cmd = MLX4_COMM_CMD_RESET;
439 slave_state[i].is_slave_going_down = 0;
Jack Morgenstein311f8132012-11-27 16:24:30 +0000440 spin_unlock_irqrestore(&priv->mfunc.master.slave_state_lock, flags);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000441 /*notify the FW:*/
442 err = mlx4_cmd(dev, 0, i, 0, MLX4_CMD_INFORM_FLR_DONE,
443 MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
444 if (err)
Joe Perches1a91de22014-05-07 12:52:57 -0700445 mlx4_warn(dev, "Failed to notify FW on FLR done (slave:%d)\n",
446 i);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000447 }
448 }
449}
450
Roland Dreier225c7b12007-05-08 18:00:38 -0700451static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
452{
Jack Morgensteinacba2422011-12-13 04:13:58 +0000453 struct mlx4_priv *priv = mlx4_priv(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -0700454 struct mlx4_eqe *eqe;
455 int cqn;
456 int eqes_found = 0;
457 int set_ci = 0;
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700458 int port;
Jack Morgensteinacba2422011-12-13 04:13:58 +0000459 int slave = 0;
460 int ret;
461 u32 flr_slave;
462 u8 update_slave_state;
463 int i;
Jack Morgenstein993c4012012-08-03 08:40:48 +0000464 enum slave_port_gen_event gen_event;
Jack Morgenstein311f8132012-11-27 16:24:30 +0000465 unsigned long flags;
Rony Efraim948e3062013-06-13 13:19:11 +0300466 struct mlx4_vport_state *s_info;
Roland Dreier225c7b12007-05-08 18:00:38 -0700467
Or Gerlitz08ff3232012-10-21 14:59:24 +0000468 while ((eqe = next_eqe_sw(eq, dev->caps.eqe_factor))) {
Roland Dreier225c7b12007-05-08 18:00:38 -0700469 /*
470 * Make sure we read EQ entry contents after we've
471 * checked the ownership bit.
472 */
473 rmb();
474
475 switch (eqe->type) {
476 case MLX4_EVENT_TYPE_COMP:
477 cqn = be32_to_cpu(eqe->event.comp.cqn) & 0xffffff;
478 mlx4_cq_completion(dev, cqn);
479 break;
480
481 case MLX4_EVENT_TYPE_PATH_MIG:
482 case MLX4_EVENT_TYPE_COMM_EST:
483 case MLX4_EVENT_TYPE_SQ_DRAINED:
484 case MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE:
485 case MLX4_EVENT_TYPE_WQ_CATAS_ERROR:
486 case MLX4_EVENT_TYPE_PATH_MIG_FAILED:
487 case MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
488 case MLX4_EVENT_TYPE_WQ_ACCESS_ERROR:
Jack Morgensteinacba2422011-12-13 04:13:58 +0000489 mlx4_dbg(dev, "event %d arrived\n", eqe->type);
490 if (mlx4_is_master(dev)) {
491 /* forward only to slave owning the QP */
492 ret = mlx4_get_slave_from_resource_id(dev,
493 RES_QP,
494 be32_to_cpu(eqe->event.qp.qpn)
495 & 0xffffff, &slave);
496 if (ret && ret != -ENOENT) {
Joe Perches1a91de22014-05-07 12:52:57 -0700497 mlx4_dbg(dev, "QP event %02x(%02x) on EQ %d at index %u: could not get slave id (%d)\n",
Jack Morgensteinacba2422011-12-13 04:13:58 +0000498 eqe->type, eqe->subtype,
499 eq->eqn, eq->cons_index, ret);
500 break;
501 }
502
503 if (!ret && slave != dev->caps.function) {
504 mlx4_slave_event(dev, slave, eqe);
505 break;
506 }
507
508 }
509 mlx4_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) &
510 0xffffff, eqe->type);
Roland Dreier225c7b12007-05-08 18:00:38 -0700511 break;
512
513 case MLX4_EVENT_TYPE_SRQ_LIMIT:
Jack Morgensteine0debf92013-04-21 15:09:59 +0000514 mlx4_dbg(dev, "%s: MLX4_EVENT_TYPE_SRQ_LIMIT\n",
515 __func__);
Roland Dreier225c7b12007-05-08 18:00:38 -0700516 case MLX4_EVENT_TYPE_SRQ_CATAS_ERROR:
Jack Morgensteinacba2422011-12-13 04:13:58 +0000517 if (mlx4_is_master(dev)) {
518 /* forward only to slave owning the SRQ */
519 ret = mlx4_get_slave_from_resource_id(dev,
520 RES_SRQ,
521 be32_to_cpu(eqe->event.srq.srqn)
522 & 0xffffff,
523 &slave);
524 if (ret && ret != -ENOENT) {
Joe Perches1a91de22014-05-07 12:52:57 -0700525 mlx4_warn(dev, "SRQ event %02x(%02x) on EQ %d at index %u: could not get slave id (%d)\n",
Jack Morgensteinacba2422011-12-13 04:13:58 +0000526 eqe->type, eqe->subtype,
527 eq->eqn, eq->cons_index, ret);
528 break;
529 }
Joe Perches1a91de22014-05-07 12:52:57 -0700530 mlx4_warn(dev, "%s: slave:%d, srq_no:0x%x, event: %02x(%02x)\n",
531 __func__, slave,
Jack Morgensteinacba2422011-12-13 04:13:58 +0000532 be32_to_cpu(eqe->event.srq.srqn),
533 eqe->type, eqe->subtype);
534
535 if (!ret && slave != dev->caps.function) {
Joe Perches1a91de22014-05-07 12:52:57 -0700536 mlx4_warn(dev, "%s: sending event %02x(%02x) to slave:%d\n",
537 __func__, eqe->type,
Jack Morgensteinacba2422011-12-13 04:13:58 +0000538 eqe->subtype, slave);
539 mlx4_slave_event(dev, slave, eqe);
540 break;
541 }
542 }
543 mlx4_srq_event(dev, be32_to_cpu(eqe->event.srq.srqn) &
544 0xffffff, eqe->type);
Roland Dreier225c7b12007-05-08 18:00:38 -0700545 break;
546
547 case MLX4_EVENT_TYPE_CMD:
548 mlx4_cmd_event(dev,
549 be16_to_cpu(eqe->event.cmd.token),
550 eqe->event.cmd.status,
551 be64_to_cpu(eqe->event.cmd.out_param));
552 break;
553
Matan Barak449fc482014-03-19 18:11:52 +0200554 case MLX4_EVENT_TYPE_PORT_CHANGE: {
555 struct mlx4_slaves_pport slaves_port;
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700556 port = be32_to_cpu(eqe->event.port_change.port) >> 28;
Matan Barak449fc482014-03-19 18:11:52 +0200557 slaves_port = mlx4_phys_to_slaves_pport(dev, port);
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700558 if (eqe->subtype == MLX4_PORT_CHANGE_SUBTYPE_DOWN) {
Jack Morgenstein993c4012012-08-03 08:40:48 +0000559 mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_DOWN,
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700560 port);
561 mlx4_priv(dev)->sense.do_sense_port[port] = 1;
Jack Morgenstein993c4012012-08-03 08:40:48 +0000562 if (!mlx4_is_master(dev))
563 break;
Matan Barak449fc482014-03-19 18:11:52 +0200564 for (i = 0; i < dev->num_vfs + 1; i++) {
565 if (!test_bit(i, slaves_port.slaves))
566 continue;
Jack Morgenstein993c4012012-08-03 08:40:48 +0000567 if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) {
568 if (i == mlx4_master_func_num(dev))
569 continue;
Joe Perches1a91de22014-05-07 12:52:57 -0700570 mlx4_dbg(dev, "%s: Sending MLX4_PORT_CHANGE_SUBTYPE_DOWN to slave: %d, port:%d\n",
Jack Morgensteinacba2422011-12-13 04:13:58 +0000571 __func__, i, port);
Rony Efraim948e3062013-06-13 13:19:11 +0300572 s_info = &priv->mfunc.master.vf_oper[slave].vport[port].state;
Matan Barak449fc482014-03-19 18:11:52 +0200573 if (IFLA_VF_LINK_STATE_AUTO == s_info->link_state) {
574 eqe->event.port_change.port =
575 cpu_to_be32(
576 (be32_to_cpu(eqe->event.port_change.port) & 0xFFFFFFF)
577 | (mlx4_phys_to_slave_port(dev, i, port) << 28));
Rony Efraim948e3062013-06-13 13:19:11 +0300578 mlx4_slave_event(dev, i, eqe);
Matan Barak449fc482014-03-19 18:11:52 +0200579 }
Jack Morgenstein993c4012012-08-03 08:40:48 +0000580 } else { /* IB port */
581 set_and_calc_slave_port_state(dev, i, port,
582 MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN,
583 &gen_event);
584 /*we can be in pending state, then do not send port_down event*/
585 if (SLAVE_PORT_GEN_EVENT_DOWN == gen_event) {
586 if (i == mlx4_master_func_num(dev))
587 continue;
588 mlx4_slave_event(dev, i, eqe);
589 }
Jack Morgensteinacba2422011-12-13 04:13:58 +0000590 }
591 }
Jack Morgenstein993c4012012-08-03 08:40:48 +0000592 } else {
593 mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_UP, port);
594
595 mlx4_priv(dev)->sense.do_sense_port[port] = 0;
596
597 if (!mlx4_is_master(dev))
598 break;
599 if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH)
Matan Barak449fc482014-03-19 18:11:52 +0200600 for (i = 0; i < dev->num_vfs + 1; i++) {
601 if (!test_bit(i, slaves_port.slaves))
602 continue;
Jack Morgenstein993c4012012-08-03 08:40:48 +0000603 if (i == mlx4_master_func_num(dev))
604 continue;
Rony Efraim948e3062013-06-13 13:19:11 +0300605 s_info = &priv->mfunc.master.vf_oper[slave].vport[port].state;
Matan Barak449fc482014-03-19 18:11:52 +0200606 if (IFLA_VF_LINK_STATE_AUTO == s_info->link_state) {
607 eqe->event.port_change.port =
608 cpu_to_be32(
609 (be32_to_cpu(eqe->event.port_change.port) & 0xFFFFFFF)
610 | (mlx4_phys_to_slave_port(dev, i, port) << 28));
Rony Efraim948e3062013-06-13 13:19:11 +0300611 mlx4_slave_event(dev, i, eqe);
Matan Barak449fc482014-03-19 18:11:52 +0200612 }
Jack Morgenstein993c4012012-08-03 08:40:48 +0000613 }
614 else /* IB port */
615 /* port-up event will be sent to a slave when the
616 * slave's alias-guid is set. This is done in alias_GUID.c
617 */
618 set_all_slave_state(dev, port, MLX4_DEV_EVENT_PORT_UP);
Yevgeny Petrilin27bf91d2009-03-18 19:45:11 -0700619 }
Roland Dreier225c7b12007-05-08 18:00:38 -0700620 break;
Matan Barak449fc482014-03-19 18:11:52 +0200621 }
Roland Dreier225c7b12007-05-08 18:00:38 -0700622
623 case MLX4_EVENT_TYPE_CQ_ERROR:
624 mlx4_warn(dev, "CQ %s on CQN %06x\n",
625 eqe->event.cq_err.syndrome == 1 ?
626 "overrun" : "access violation",
627 be32_to_cpu(eqe->event.cq_err.cqn) & 0xffffff);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000628 if (mlx4_is_master(dev)) {
629 ret = mlx4_get_slave_from_resource_id(dev,
630 RES_CQ,
631 be32_to_cpu(eqe->event.cq_err.cqn)
632 & 0xffffff, &slave);
633 if (ret && ret != -ENOENT) {
Joe Perches1a91de22014-05-07 12:52:57 -0700634 mlx4_dbg(dev, "CQ event %02x(%02x) on EQ %d at index %u: could not get slave id (%d)\n",
635 eqe->type, eqe->subtype,
636 eq->eqn, eq->cons_index, ret);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000637 break;
638 }
639
640 if (!ret && slave != dev->caps.function) {
641 mlx4_slave_event(dev, slave, eqe);
642 break;
643 }
644 }
645 mlx4_cq_event(dev,
646 be32_to_cpu(eqe->event.cq_err.cqn)
647 & 0xffffff,
Roland Dreier225c7b12007-05-08 18:00:38 -0700648 eqe->type);
649 break;
650
651 case MLX4_EVENT_TYPE_EQ_OVERFLOW:
652 mlx4_warn(dev, "EQ overrun on EQN %d\n", eq->eqn);
653 break;
654
Yevgeny Petrilinfe6f7002013-07-28 18:54:21 +0300655 case MLX4_EVENT_TYPE_OP_REQUIRED:
656 atomic_inc(&priv->opreq_count);
657 /* FW commands can't be executed from interrupt context
658 * working in deferred task
659 */
660 queue_work(mlx4_wq, &priv->opreq_task);
661 break;
662
Jack Morgensteinacba2422011-12-13 04:13:58 +0000663 case MLX4_EVENT_TYPE_COMM_CHANNEL:
664 if (!mlx4_is_master(dev)) {
Joe Perches1a91de22014-05-07 12:52:57 -0700665 mlx4_warn(dev, "Received comm channel event for non master device\n");
Jack Morgensteinacba2422011-12-13 04:13:58 +0000666 break;
667 }
668 memcpy(&priv->mfunc.master.comm_arm_bit_vector,
669 eqe->event.comm_channel_arm.bit_vec,
670 sizeof eqe->event.comm_channel_arm.bit_vec);
671 queue_work(priv->mfunc.master.comm_wq,
672 &priv->mfunc.master.comm_work);
673 break;
674
675 case MLX4_EVENT_TYPE_FLR_EVENT:
676 flr_slave = be32_to_cpu(eqe->event.flr_event.slave_id);
677 if (!mlx4_is_master(dev)) {
Joe Perches1a91de22014-05-07 12:52:57 -0700678 mlx4_warn(dev, "Non-master function received FLR event\n");
Jack Morgensteinacba2422011-12-13 04:13:58 +0000679 break;
680 }
681
682 mlx4_dbg(dev, "FLR event for slave: %d\n", flr_slave);
683
Jack Morgenstein30f7c732012-05-30 09:14:50 +0000684 if (flr_slave >= dev->num_slaves) {
Jack Morgensteinacba2422011-12-13 04:13:58 +0000685 mlx4_warn(dev,
686 "Got FLR for unknown function: %d\n",
687 flr_slave);
688 update_slave_state = 0;
689 } else
690 update_slave_state = 1;
691
Jack Morgenstein311f8132012-11-27 16:24:30 +0000692 spin_lock_irqsave(&priv->mfunc.master.slave_state_lock, flags);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000693 if (update_slave_state) {
694 priv->mfunc.master.slave_state[flr_slave].active = false;
695 priv->mfunc.master.slave_state[flr_slave].last_cmd = MLX4_COMM_CMD_FLR;
696 priv->mfunc.master.slave_state[flr_slave].is_slave_going_down = 1;
697 }
Jack Morgenstein311f8132012-11-27 16:24:30 +0000698 spin_unlock_irqrestore(&priv->mfunc.master.slave_state_lock, flags);
Jack Morgensteinacba2422011-12-13 04:13:58 +0000699 queue_work(priv->mfunc.master.comm_wq,
700 &priv->mfunc.master.slave_flr_event_work);
701 break;
Jack Morgenstein5984be92012-03-06 15:50:49 +0200702
703 case MLX4_EVENT_TYPE_FATAL_WARNING:
704 if (eqe->subtype == MLX4_FATAL_WARNING_SUBTYPE_WARMING) {
705 if (mlx4_is_master(dev))
706 for (i = 0; i < dev->num_slaves; i++) {
Joe Perches1a91de22014-05-07 12:52:57 -0700707 mlx4_dbg(dev, "%s: Sending MLX4_FATAL_WARNING_SUBTYPE_WARMING to slave: %d\n",
708 __func__, i);
Jack Morgenstein5984be92012-03-06 15:50:49 +0200709 if (i == dev->caps.function)
710 continue;
711 mlx4_slave_event(dev, i, eqe);
712 }
Joe Perches1a91de22014-05-07 12:52:57 -0700713 mlx4_err(dev, "Temperature Threshold was reached! Threshold: %d celsius degrees; Current Temperature: %d\n",
714 be16_to_cpu(eqe->event.warming.warning_threshold),
715 be16_to_cpu(eqe->event.warming.current_temperature));
Jack Morgenstein5984be92012-03-06 15:50:49 +0200716 } else
Joe Perches1a91de22014-05-07 12:52:57 -0700717 mlx4_warn(dev, "Unhandled event FATAL WARNING (%02x), subtype %02x on EQ %d at index %u. owner=%x, nent=0x%x, slave=%x, ownership=%s\n",
Jack Morgenstein5984be92012-03-06 15:50:49 +0200718 eqe->type, eqe->subtype, eq->eqn,
719 eq->cons_index, eqe->owner, eq->nent,
720 eqe->slave_id,
721 !!(eqe->owner & 0x80) ^
722 !!(eq->cons_index & eq->nent) ? "HW" : "SW");
723
724 break;
725
Jack Morgenstein00f5ce92012-06-19 11:21:40 +0300726 case MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT:
727 mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_MGMT_CHANGE,
728 (unsigned long) eqe);
729 break;
730
Roland Dreier225c7b12007-05-08 18:00:38 -0700731 case MLX4_EVENT_TYPE_EEC_CATAS_ERROR:
732 case MLX4_EVENT_TYPE_ECC_DETECT:
733 default:
Joe Perches1a91de22014-05-07 12:52:57 -0700734 mlx4_warn(dev, "Unhandled event %02x(%02x) on EQ %d at index %u. owner=%x, nent=0x%x, slave=%x, ownership=%s\n",
Jack Morgensteinacba2422011-12-13 04:13:58 +0000735 eqe->type, eqe->subtype, eq->eqn,
736 eq->cons_index, eqe->owner, eq->nent,
737 eqe->slave_id,
738 !!(eqe->owner & 0x80) ^
739 !!(eq->cons_index & eq->nent) ? "HW" : "SW");
Roland Dreier225c7b12007-05-08 18:00:38 -0700740 break;
Jack Morgensteinacba2422011-12-13 04:13:58 +0000741 };
Roland Dreier225c7b12007-05-08 18:00:38 -0700742
743 ++eq->cons_index;
744 eqes_found = 1;
745 ++set_ci;
746
747 /*
748 * The HCA will think the queue has overflowed if we
749 * don't tell it we've been processing events. We
750 * create our EQs with MLX4_NUM_SPARE_EQE extra
751 * entries, so we must update our consumer index at
752 * least that often.
753 */
754 if (unlikely(set_ci >= MLX4_NUM_SPARE_EQE)) {
Roland Dreier225c7b12007-05-08 18:00:38 -0700755 eq_set_ci(eq, 0);
756 set_ci = 0;
757 }
758 }
759
760 eq_set_ci(eq, 1);
761
762 return eqes_found;
763}
764
765static irqreturn_t mlx4_interrupt(int irq, void *dev_ptr)
766{
767 struct mlx4_dev *dev = dev_ptr;
768 struct mlx4_priv *priv = mlx4_priv(dev);
769 int work = 0;
770 int i;
771
772 writel(priv->eq_table.clr_mask, priv->eq_table.clr_int);
773
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800774 for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
Roland Dreier225c7b12007-05-08 18:00:38 -0700775 work |= mlx4_eq_int(dev, &priv->eq_table.eq[i]);
776
777 return IRQ_RETVAL(work);
778}
779
780static irqreturn_t mlx4_msi_x_interrupt(int irq, void *eq_ptr)
781{
782 struct mlx4_eq *eq = eq_ptr;
783 struct mlx4_dev *dev = eq->dev;
784
785 mlx4_eq_int(dev, eq);
786
787 /* MSI-X vectors always belong to us */
788 return IRQ_HANDLED;
789}
790
Jack Morgensteinacba2422011-12-13 04:13:58 +0000791int mlx4_MAP_EQ_wrapper(struct mlx4_dev *dev, int slave,
792 struct mlx4_vhcr *vhcr,
793 struct mlx4_cmd_mailbox *inbox,
794 struct mlx4_cmd_mailbox *outbox,
795 struct mlx4_cmd_info *cmd)
796{
797 struct mlx4_priv *priv = mlx4_priv(dev);
798 struct mlx4_slave_event_eq_info *event_eq =
Marcel Apfelbaum803143f2012-01-19 09:45:46 +0000799 priv->mfunc.master.slave_state[slave].event_eq;
Jack Morgensteinacba2422011-12-13 04:13:58 +0000800 u32 in_modifier = vhcr->in_modifier;
Moshe Lazerc101c812013-03-21 05:55:51 +0000801 u32 eqn = in_modifier & 0x3FF;
Jack Morgensteinacba2422011-12-13 04:13:58 +0000802 u64 in_param = vhcr->in_param;
803 int err = 0;
Marcel Apfelbaum803143f2012-01-19 09:45:46 +0000804 int i;
Jack Morgensteinacba2422011-12-13 04:13:58 +0000805
806 if (slave == dev->caps.function)
807 err = mlx4_cmd(dev, in_param, (in_modifier & 0x80000000) | eqn,
808 0, MLX4_CMD_MAP_EQ, MLX4_CMD_TIME_CLASS_B,
809 MLX4_CMD_NATIVE);
Marcel Apfelbaum803143f2012-01-19 09:45:46 +0000810 if (!err)
811 for (i = 0; i < MLX4_EVENT_TYPES_NUM; ++i)
812 if (in_param & (1LL << i))
813 event_eq[i].eqn = in_modifier >> 31 ? -1 : eqn;
814
Jack Morgensteinacba2422011-12-13 04:13:58 +0000815 return err;
816}
817
Roland Dreier225c7b12007-05-08 18:00:38 -0700818static int mlx4_MAP_EQ(struct mlx4_dev *dev, u64 event_mask, int unmap,
819 int eq_num)
820{
821 return mlx4_cmd(dev, event_mask, (unmap << 31) | eq_num,
Jack Morgensteinf9baff52011-12-13 04:10:51 +0000822 0, MLX4_CMD_MAP_EQ, MLX4_CMD_TIME_CLASS_B,
823 MLX4_CMD_WRAPPED);
Roland Dreier225c7b12007-05-08 18:00:38 -0700824}
825
826static int mlx4_SW2HW_EQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
827 int eq_num)
828{
Marcel Apfelbaumeb410492012-01-19 09:45:19 +0000829 return mlx4_cmd(dev, mailbox->dma, eq_num, 0,
Jack Morgensteinacba2422011-12-13 04:13:58 +0000830 MLX4_CMD_SW2HW_EQ, MLX4_CMD_TIME_CLASS_A,
Jack Morgensteinf9baff52011-12-13 04:10:51 +0000831 MLX4_CMD_WRAPPED);
Roland Dreier225c7b12007-05-08 18:00:38 -0700832}
833
834static int mlx4_HW2SW_EQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
835 int eq_num)
836{
Marcel Apfelbaumeb410492012-01-19 09:45:19 +0000837 return mlx4_cmd_box(dev, 0, mailbox->dma, eq_num,
Jack Morgensteinacba2422011-12-13 04:13:58 +0000838 0, MLX4_CMD_HW2SW_EQ, MLX4_CMD_TIME_CLASS_A,
Jack Morgensteinf9baff52011-12-13 04:10:51 +0000839 MLX4_CMD_WRAPPED);
Roland Dreier225c7b12007-05-08 18:00:38 -0700840}
841
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800842static int mlx4_num_eq_uar(struct mlx4_dev *dev)
843{
844 /*
845 * Each UAR holds 4 EQ doorbells. To figure out how many UARs
846 * we need to map, take the difference of highest index and
847 * the lowest index we'll use and add 1.
848 */
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +0000849 return (dev->caps.num_comp_vectors + 1 + dev->caps.reserved_eqs +
850 dev->caps.comp_pool)/4 - dev->caps.reserved_eqs/4 + 1;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -0800851}
852
Roland Dreier3d73c282007-10-10 15:43:54 -0700853static void __iomem *mlx4_get_eq_uar(struct mlx4_dev *dev, struct mlx4_eq *eq)
Roland Dreier225c7b12007-05-08 18:00:38 -0700854{
855 struct mlx4_priv *priv = mlx4_priv(dev);
856 int index;
857
858 index = eq->eqn / 4 - dev->caps.reserved_eqs / 4;
859
860 if (!priv->eq_table.uar_map[index]) {
861 priv->eq_table.uar_map[index] =
862 ioremap(pci_resource_start(dev->pdev, 2) +
863 ((eq->eqn / 4) << PAGE_SHIFT),
864 PAGE_SIZE);
865 if (!priv->eq_table.uar_map[index]) {
866 mlx4_err(dev, "Couldn't map EQ doorbell for EQN 0x%06x\n",
867 eq->eqn);
868 return NULL;
869 }
870 }
871
872 return priv->eq_table.uar_map[index] + 0x800 + 8 * (eq->eqn % 4);
873}
874
Dotan Barakbfc0d8c2012-10-25 01:12:49 +0000875static void mlx4_unmap_uar(struct mlx4_dev *dev)
876{
877 struct mlx4_priv *priv = mlx4_priv(dev);
878 int i;
879
880 for (i = 0; i < mlx4_num_eq_uar(dev); ++i)
881 if (priv->eq_table.uar_map[i]) {
882 iounmap(priv->eq_table.uar_map[i]);
883 priv->eq_table.uar_map[i] = NULL;
884 }
885}
886
Roland Dreier3d73c282007-10-10 15:43:54 -0700887static int mlx4_create_eq(struct mlx4_dev *dev, int nent,
888 u8 intr, struct mlx4_eq *eq)
Roland Dreier225c7b12007-05-08 18:00:38 -0700889{
890 struct mlx4_priv *priv = mlx4_priv(dev);
891 struct mlx4_cmd_mailbox *mailbox;
892 struct mlx4_eq_context *eq_context;
893 int npages;
894 u64 *dma_list = NULL;
895 dma_addr_t t;
896 u64 mtt_addr;
897 int err = -ENOMEM;
898 int i;
899
900 eq->dev = dev;
901 eq->nent = roundup_pow_of_two(max(nent, 2));
Or Gerlitz08ff3232012-10-21 14:59:24 +0000902 /* CX3 is capable of extending the CQE/EQE from 32 to 64 bytes */
903 npages = PAGE_ALIGN(eq->nent * (MLX4_EQ_ENTRY_SIZE << dev->caps.eqe_factor)) / PAGE_SIZE;
Roland Dreier225c7b12007-05-08 18:00:38 -0700904
905 eq->page_list = kmalloc(npages * sizeof *eq->page_list,
906 GFP_KERNEL);
907 if (!eq->page_list)
908 goto err_out;
909
910 for (i = 0; i < npages; ++i)
911 eq->page_list[i].buf = NULL;
912
913 dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
914 if (!dma_list)
915 goto err_out_free;
916
917 mailbox = mlx4_alloc_cmd_mailbox(dev);
918 if (IS_ERR(mailbox))
919 goto err_out_free;
920 eq_context = mailbox->buf;
921
922 for (i = 0; i < npages; ++i) {
923 eq->page_list[i].buf = dma_alloc_coherent(&dev->pdev->dev,
924 PAGE_SIZE, &t, GFP_KERNEL);
925 if (!eq->page_list[i].buf)
926 goto err_out_free_pages;
927
928 dma_list[i] = t;
929 eq->page_list[i].map = t;
930
931 memset(eq->page_list[i].buf, 0, PAGE_SIZE);
932 }
933
934 eq->eqn = mlx4_bitmap_alloc(&priv->eq_table.bitmap);
935 if (eq->eqn == -1)
936 goto err_out_free_pages;
937
938 eq->doorbell = mlx4_get_eq_uar(dev, eq);
939 if (!eq->doorbell) {
940 err = -ENOMEM;
941 goto err_out_free_eq;
942 }
943
944 err = mlx4_mtt_init(dev, npages, PAGE_SHIFT, &eq->mtt);
945 if (err)
946 goto err_out_free_eq;
947
948 err = mlx4_write_mtt(dev, &eq->mtt, 0, npages, dma_list);
949 if (err)
950 goto err_out_free_mtt;
951
Roland Dreier225c7b12007-05-08 18:00:38 -0700952 eq_context->flags = cpu_to_be32(MLX4_EQ_STATUS_OK |
953 MLX4_EQ_STATE_ARMED);
954 eq_context->log_eq_size = ilog2(eq->nent);
955 eq_context->intr = intr;
956 eq_context->log_page_size = PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT;
957
958 mtt_addr = mlx4_mtt_addr(dev, &eq->mtt);
959 eq_context->mtt_base_addr_h = mtt_addr >> 32;
960 eq_context->mtt_base_addr_l = cpu_to_be32(mtt_addr & 0xffffffff);
961
962 err = mlx4_SW2HW_EQ(dev, mailbox, eq->eqn);
963 if (err) {
964 mlx4_warn(dev, "SW2HW_EQ failed (%d)\n", err);
965 goto err_out_free_mtt;
966 }
967
968 kfree(dma_list);
969 mlx4_free_cmd_mailbox(dev, mailbox);
970
971 eq->cons_index = 0;
972
973 return err;
974
975err_out_free_mtt:
976 mlx4_mtt_cleanup(dev, &eq->mtt);
977
978err_out_free_eq:
Jack Morgenstein7c6d74d2013-12-08 16:50:17 +0200979 mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn, MLX4_USE_RR);
Roland Dreier225c7b12007-05-08 18:00:38 -0700980
981err_out_free_pages:
982 for (i = 0; i < npages; ++i)
983 if (eq->page_list[i].buf)
984 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
985 eq->page_list[i].buf,
986 eq->page_list[i].map);
987
988 mlx4_free_cmd_mailbox(dev, mailbox);
989
990err_out_free:
991 kfree(eq->page_list);
992 kfree(dma_list);
993
994err_out:
995 return err;
996}
997
998static void mlx4_free_eq(struct mlx4_dev *dev,
999 struct mlx4_eq *eq)
1000{
1001 struct mlx4_priv *priv = mlx4_priv(dev);
1002 struct mlx4_cmd_mailbox *mailbox;
1003 int err;
Roland Dreier225c7b12007-05-08 18:00:38 -07001004 int i;
Or Gerlitz08ff3232012-10-21 14:59:24 +00001005 /* CX3 is capable of extending the CQE/EQE from 32 to 64 bytes */
1006 int npages = PAGE_ALIGN((MLX4_EQ_ENTRY_SIZE << dev->caps.eqe_factor) * eq->nent) / PAGE_SIZE;
Roland Dreier225c7b12007-05-08 18:00:38 -07001007
1008 mailbox = mlx4_alloc_cmd_mailbox(dev);
1009 if (IS_ERR(mailbox))
1010 return;
1011
1012 err = mlx4_HW2SW_EQ(dev, mailbox, eq->eqn);
1013 if (err)
1014 mlx4_warn(dev, "HW2SW_EQ failed (%d)\n", err);
1015
1016 if (0) {
1017 mlx4_dbg(dev, "Dumping EQ context %02x:\n", eq->eqn);
1018 for (i = 0; i < sizeof (struct mlx4_eq_context) / 4; ++i) {
1019 if (i % 4 == 0)
Joe Perches0a645e82010-07-10 07:22:46 +00001020 pr_cont("[%02x] ", i * 4);
1021 pr_cont(" %08x", be32_to_cpup(mailbox->buf + i * 4));
Roland Dreier225c7b12007-05-08 18:00:38 -07001022 if ((i + 1) % 4 == 0)
Joe Perches0a645e82010-07-10 07:22:46 +00001023 pr_cont("\n");
Roland Dreier225c7b12007-05-08 18:00:38 -07001024 }
1025 }
1026
1027 mlx4_mtt_cleanup(dev, &eq->mtt);
1028 for (i = 0; i < npages; ++i)
Dotan Baraka8dc0df2011-10-06 09:33:12 -07001029 dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
Roland Dreier225c7b12007-05-08 18:00:38 -07001030 eq->page_list[i].buf,
1031 eq->page_list[i].map);
1032
1033 kfree(eq->page_list);
Jack Morgenstein7c6d74d2013-12-08 16:50:17 +02001034 mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn, MLX4_USE_RR);
Roland Dreier225c7b12007-05-08 18:00:38 -07001035 mlx4_free_cmd_mailbox(dev, mailbox);
1036}
1037
1038static void mlx4_free_irqs(struct mlx4_dev *dev)
1039{
1040 struct mlx4_eq_table *eq_table = &mlx4_priv(dev)->eq_table;
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001041 struct mlx4_priv *priv = mlx4_priv(dev);
1042 int i, vec;
Roland Dreier225c7b12007-05-08 18:00:38 -07001043
1044 if (eq_table->have_irq)
1045 free_irq(dev->pdev->irq, dev);
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001046
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001047 for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
Roland Dreierd1fdf242009-06-14 13:30:45 -07001048 if (eq_table->eq[i].have_irq) {
Roland Dreier225c7b12007-05-08 18:00:38 -07001049 free_irq(eq_table->eq[i].irq, eq_table->eq + i);
Roland Dreierd1fdf242009-06-14 13:30:45 -07001050 eq_table->eq[i].have_irq = 0;
1051 }
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001052
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001053 for (i = 0; i < dev->caps.comp_pool; i++) {
1054 /*
1055 * Freeing the assigned irq's
1056 * all bits should be 0, but we need to validate
1057 */
1058 if (priv->msix_ctl.pool_bm & 1ULL << i) {
1059 /* NO need protecting*/
1060 vec = dev->caps.num_comp_vectors + 1 + i;
1061 free_irq(priv->eq_table.eq[vec].irq,
1062 &priv->eq_table.eq[vec]);
1063 }
1064 }
1065
1066
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001067 kfree(eq_table->irq_names);
Roland Dreier225c7b12007-05-08 18:00:38 -07001068}
1069
Roland Dreier3d73c282007-10-10 15:43:54 -07001070static int mlx4_map_clr_int(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -07001071{
1072 struct mlx4_priv *priv = mlx4_priv(dev);
1073
1074 priv->clr_base = ioremap(pci_resource_start(dev->pdev, priv->fw.clr_int_bar) +
1075 priv->fw.clr_int_base, MLX4_CLR_INT_SIZE);
1076 if (!priv->clr_base) {
Joe Perches1a91de22014-05-07 12:52:57 -07001077 mlx4_err(dev, "Couldn't map interrupt clear register, aborting\n");
Roland Dreier225c7b12007-05-08 18:00:38 -07001078 return -ENOMEM;
1079 }
1080
1081 return 0;
1082}
1083
1084static void mlx4_unmap_clr_int(struct mlx4_dev *dev)
1085{
1086 struct mlx4_priv *priv = mlx4_priv(dev);
1087
1088 iounmap(priv->clr_base);
1089}
1090
Yuval Atias2eacc232014-05-14 12:15:10 +03001091static void mlx4_irq_notifier_notify(struct irq_affinity_notify *notify,
1092 const cpumask_t *mask)
1093{
1094 struct mlx4_irq_notify *n = container_of(notify,
1095 struct mlx4_irq_notify,
1096 notify);
1097 struct mlx4_priv *priv = (struct mlx4_priv *)n->arg;
1098 struct radix_tree_iter iter;
1099 void **slot;
1100
1101 radix_tree_for_each_slot(slot, &priv->cq_table.tree, &iter, 0) {
1102 struct mlx4_cq *cq = (struct mlx4_cq *)(*slot);
1103
1104 if (cq->irq == notify->irq)
1105 cq->irq_affinity_change = true;
1106 }
1107}
1108
1109static void mlx4_release_irq_notifier(struct kref *ref)
1110{
1111 struct mlx4_irq_notify *n = container_of(ref, struct mlx4_irq_notify,
1112 notify.kref);
1113 kfree(n);
1114}
1115
1116static void mlx4_assign_irq_notifier(struct mlx4_priv *priv,
1117 struct mlx4_dev *dev, int irq)
1118{
1119 struct mlx4_irq_notify *irq_notifier = NULL;
1120 int err = 0;
1121
1122 irq_notifier = kzalloc(sizeof(*irq_notifier), GFP_KERNEL);
1123 if (!irq_notifier) {
1124 mlx4_warn(dev, "Failed to allocate irq notifier. irq %d\n",
1125 irq);
1126 return;
1127 }
1128
1129 irq_notifier->notify.irq = irq;
1130 irq_notifier->notify.notify = mlx4_irq_notifier_notify;
1131 irq_notifier->notify.release = mlx4_release_irq_notifier;
1132 irq_notifier->arg = priv;
1133 err = irq_set_affinity_notifier(irq, &irq_notifier->notify);
1134 if (err) {
1135 kfree(irq_notifier);
1136 irq_notifier = NULL;
1137 mlx4_warn(dev, "Failed to set irq notifier. irq %d\n", irq);
1138 }
1139}
1140
1141
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001142int mlx4_alloc_eq_table(struct mlx4_dev *dev)
1143{
1144 struct mlx4_priv *priv = mlx4_priv(dev);
1145
1146 priv->eq_table.eq = kcalloc(dev->caps.num_eqs - dev->caps.reserved_eqs,
1147 sizeof *priv->eq_table.eq, GFP_KERNEL);
1148 if (!priv->eq_table.eq)
1149 return -ENOMEM;
1150
1151 return 0;
1152}
1153
1154void mlx4_free_eq_table(struct mlx4_dev *dev)
1155{
1156 kfree(mlx4_priv(dev)->eq_table.eq);
1157}
1158
Roland Dreier3d73c282007-10-10 15:43:54 -07001159int mlx4_init_eq_table(struct mlx4_dev *dev)
Roland Dreier225c7b12007-05-08 18:00:38 -07001160{
1161 struct mlx4_priv *priv = mlx4_priv(dev);
1162 int err;
1163 int i;
1164
Axel Lin758ff232012-02-12 15:14:39 +00001165 priv->eq_table.uar_map = kcalloc(mlx4_num_eq_uar(dev),
1166 sizeof *priv->eq_table.uar_map,
1167 GFP_KERNEL);
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001168 if (!priv->eq_table.uar_map) {
1169 err = -ENOMEM;
1170 goto err_out_free;
1171 }
1172
Roland Dreier225c7b12007-05-08 18:00:38 -07001173 err = mlx4_bitmap_init(&priv->eq_table.bitmap, dev->caps.num_eqs,
Yevgeny Petrilin93fc9e12008-10-22 10:25:29 -07001174 dev->caps.num_eqs - 1, dev->caps.reserved_eqs, 0);
Roland Dreier225c7b12007-05-08 18:00:38 -07001175 if (err)
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001176 goto err_out_free;
Roland Dreier225c7b12007-05-08 18:00:38 -07001177
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001178 for (i = 0; i < mlx4_num_eq_uar(dev); ++i)
Roland Dreier225c7b12007-05-08 18:00:38 -07001179 priv->eq_table.uar_map[i] = NULL;
1180
Jack Morgensteinacba2422011-12-13 04:13:58 +00001181 if (!mlx4_is_slave(dev)) {
1182 err = mlx4_map_clr_int(dev);
1183 if (err)
1184 goto err_out_bitmap;
Roland Dreier225c7b12007-05-08 18:00:38 -07001185
Jack Morgensteinacba2422011-12-13 04:13:58 +00001186 priv->eq_table.clr_mask =
1187 swab32(1 << (priv->eq_table.inta_pin & 31));
1188 priv->eq_table.clr_int = priv->clr_base +
1189 (priv->eq_table.inta_pin < 32 ? 4 : 0);
1190 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001191
Arputham Benjaminf5f59512009-09-05 20:24:50 -07001192 priv->eq_table.irq_names =
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001193 kmalloc(MLX4_IRQNAME_SIZE * (dev->caps.num_comp_vectors + 1 +
1194 dev->caps.comp_pool),
Arputham Benjaminf5f59512009-09-05 20:24:50 -07001195 GFP_KERNEL);
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001196 if (!priv->eq_table.irq_names) {
1197 err = -ENOMEM;
1198 goto err_out_bitmap;
1199 }
1200
1201 for (i = 0; i < dev->caps.num_comp_vectors; ++i) {
Yevgeny Petrilinc3794742011-03-30 23:30:17 +00001202 err = mlx4_create_eq(dev, dev->caps.num_cqs -
1203 dev->caps.reserved_cqs +
1204 MLX4_NUM_SPARE_EQE,
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001205 (dev->flags & MLX4_FLAG_MSI_X) ? i : 0,
1206 &priv->eq_table.eq[i]);
Yevgeny Petrilina5b19b62009-06-08 00:39:58 -07001207 if (err) {
1208 --i;
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001209 goto err_out_unmap;
Yevgeny Petrilina5b19b62009-06-08 00:39:58 -07001210 }
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001211 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001212
1213 err = mlx4_create_eq(dev, MLX4_NUM_ASYNC_EQE + MLX4_NUM_SPARE_EQE,
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001214 (dev->flags & MLX4_FLAG_MSI_X) ? dev->caps.num_comp_vectors : 0,
1215 &priv->eq_table.eq[dev->caps.num_comp_vectors]);
Roland Dreier225c7b12007-05-08 18:00:38 -07001216 if (err)
1217 goto err_out_comp;
1218
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001219 /*if additional completion vectors poolsize is 0 this loop will not run*/
1220 for (i = dev->caps.num_comp_vectors + 1;
1221 i < dev->caps.num_comp_vectors + dev->caps.comp_pool + 1; ++i) {
1222
1223 err = mlx4_create_eq(dev, dev->caps.num_cqs -
1224 dev->caps.reserved_cqs +
1225 MLX4_NUM_SPARE_EQE,
1226 (dev->flags & MLX4_FLAG_MSI_X) ? i : 0,
1227 &priv->eq_table.eq[i]);
1228 if (err) {
1229 --i;
1230 goto err_out_unmap;
1231 }
1232 }
1233
1234
Roland Dreier225c7b12007-05-08 18:00:38 -07001235 if (dev->flags & MLX4_FLAG_MSI_X) {
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001236 const char *eq_name;
Roland Dreier225c7b12007-05-08 18:00:38 -07001237
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001238 for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i) {
1239 if (i < dev->caps.num_comp_vectors) {
Arputham Benjaminf5f59512009-09-05 20:24:50 -07001240 snprintf(priv->eq_table.irq_names +
1241 i * MLX4_IRQNAME_SIZE,
1242 MLX4_IRQNAME_SIZE,
1243 "mlx4-comp-%d@pci:%s", i,
1244 pci_name(dev->pdev));
1245 } else {
1246 snprintf(priv->eq_table.irq_names +
1247 i * MLX4_IRQNAME_SIZE,
1248 MLX4_IRQNAME_SIZE,
1249 "mlx4-async@pci:%s",
1250 pci_name(dev->pdev));
1251 }
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001252
Arputham Benjaminf5f59512009-09-05 20:24:50 -07001253 eq_name = priv->eq_table.irq_names +
1254 i * MLX4_IRQNAME_SIZE;
Roland Dreier225c7b12007-05-08 18:00:38 -07001255 err = request_irq(priv->eq_table.eq[i].irq,
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001256 mlx4_msi_x_interrupt, 0, eq_name,
1257 priv->eq_table.eq + i);
Roland Dreier225c7b12007-05-08 18:00:38 -07001258 if (err)
Jack Morgensteinee49bd92007-07-12 17:50:45 +03001259 goto err_out_async;
Roland Dreier225c7b12007-05-08 18:00:38 -07001260
1261 priv->eq_table.eq[i].have_irq = 1;
1262 }
Roland Dreier225c7b12007-05-08 18:00:38 -07001263 } else {
Arputham Benjaminf5f59512009-09-05 20:24:50 -07001264 snprintf(priv->eq_table.irq_names,
1265 MLX4_IRQNAME_SIZE,
1266 DRV_NAME "@pci:%s",
1267 pci_name(dev->pdev));
Roland Dreier225c7b12007-05-08 18:00:38 -07001268 err = request_irq(dev->pdev->irq, mlx4_interrupt,
Arputham Benjaminf5f59512009-09-05 20:24:50 -07001269 IRQF_SHARED, priv->eq_table.irq_names, dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07001270 if (err)
1271 goto err_out_async;
1272
1273 priv->eq_table.have_irq = 1;
1274 }
1275
Jack Morgenstein00f5ce92012-06-19 11:21:40 +03001276 err = mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001277 priv->eq_table.eq[dev->caps.num_comp_vectors].eqn);
Roland Dreier225c7b12007-05-08 18:00:38 -07001278 if (err)
1279 mlx4_warn(dev, "MAP_EQ for async EQ %d failed (%d)\n",
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001280 priv->eq_table.eq[dev->caps.num_comp_vectors].eqn, err);
Roland Dreier225c7b12007-05-08 18:00:38 -07001281
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001282 for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
Roland Dreier225c7b12007-05-08 18:00:38 -07001283 eq_set_ci(&priv->eq_table.eq[i], 1);
1284
Roland Dreier225c7b12007-05-08 18:00:38 -07001285 return 0;
1286
Roland Dreier225c7b12007-05-08 18:00:38 -07001287err_out_async:
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001288 mlx4_free_eq(dev, &priv->eq_table.eq[dev->caps.num_comp_vectors]);
Roland Dreier225c7b12007-05-08 18:00:38 -07001289
1290err_out_comp:
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001291 i = dev->caps.num_comp_vectors - 1;
Roland Dreier225c7b12007-05-08 18:00:38 -07001292
1293err_out_unmap:
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001294 while (i >= 0) {
1295 mlx4_free_eq(dev, &priv->eq_table.eq[i]);
1296 --i;
1297 }
Jack Morgensteinacba2422011-12-13 04:13:58 +00001298 if (!mlx4_is_slave(dev))
1299 mlx4_unmap_clr_int(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07001300 mlx4_free_irqs(dev);
1301
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001302err_out_bitmap:
Dotan Barakbfc0d8c2012-10-25 01:12:49 +00001303 mlx4_unmap_uar(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07001304 mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001305
1306err_out_free:
1307 kfree(priv->eq_table.uar_map);
1308
Roland Dreier225c7b12007-05-08 18:00:38 -07001309 return err;
1310}
1311
1312void mlx4_cleanup_eq_table(struct mlx4_dev *dev)
1313{
1314 struct mlx4_priv *priv = mlx4_priv(dev);
1315 int i;
1316
Jack Morgenstein00f5ce92012-06-19 11:21:40 +03001317 mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 1,
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001318 priv->eq_table.eq[dev->caps.num_comp_vectors].eqn);
Roland Dreier225c7b12007-05-08 18:00:38 -07001319
1320 mlx4_free_irqs(dev);
1321
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001322 for (i = 0; i < dev->caps.num_comp_vectors + dev->caps.comp_pool + 1; ++i)
Roland Dreier225c7b12007-05-08 18:00:38 -07001323 mlx4_free_eq(dev, &priv->eq_table.eq[i]);
Roland Dreier225c7b12007-05-08 18:00:38 -07001324
Jack Morgensteinacba2422011-12-13 04:13:58 +00001325 if (!mlx4_is_slave(dev))
1326 mlx4_unmap_clr_int(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07001327
Dotan Barakbfc0d8c2012-10-25 01:12:49 +00001328 mlx4_unmap_uar(dev);
Roland Dreier225c7b12007-05-08 18:00:38 -07001329 mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
Yevgeny Petrilinb8dd7862008-12-22 07:15:03 -08001330
1331 kfree(priv->eq_table.uar_map);
Roland Dreier225c7b12007-05-08 18:00:38 -07001332}
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +00001333
1334/* A test that verifies that we can accept interrupts on all
1335 * the irq vectors of the device.
1336 * Interrupts are checked using the NOP command.
1337 */
1338int mlx4_test_interrupts(struct mlx4_dev *dev)
1339{
1340 struct mlx4_priv *priv = mlx4_priv(dev);
1341 int i;
1342 int err;
1343
1344 err = mlx4_NOP(dev);
1345 /* When not in MSI_X, there is only one irq to check */
Jack Morgensteinacba2422011-12-13 04:13:58 +00001346 if (!(dev->flags & MLX4_FLAG_MSI_X) || mlx4_is_slave(dev))
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +00001347 return err;
1348
1349 /* A loop over all completion vectors, for each vector we will check
1350 * whether it works by mapping command completions to that vector
1351 * and performing a NOP command
1352 */
1353 for(i = 0; !err && (i < dev->caps.num_comp_vectors); ++i) {
1354 /* Temporary use polling for command completions */
1355 mlx4_cmd_use_polling(dev);
1356
Adam Buchbinderb3834be2012-09-19 21:48:02 -04001357 /* Map the new eq to handle all asynchronous events */
Jack Morgenstein00f5ce92012-06-19 11:21:40 +03001358 err = mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +00001359 priv->eq_table.eq[i].eqn);
1360 if (err) {
1361 mlx4_warn(dev, "Failed mapping eq for interrupt test\n");
1362 mlx4_cmd_use_events(dev);
1363 break;
1364 }
1365
1366 /* Go back to using events */
1367 mlx4_cmd_use_events(dev);
1368 err = mlx4_NOP(dev);
1369 }
1370
1371 /* Return to default */
Jack Morgenstein00f5ce92012-06-19 11:21:40 +03001372 mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
Yevgeny Petriline7c1c2c42010-08-24 03:46:18 +00001373 priv->eq_table.eq[dev->caps.num_comp_vectors].eqn);
1374 return err;
1375}
1376EXPORT_SYMBOL(mlx4_test_interrupts);
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001377
Amir Vadaid9236c32012-07-18 22:33:51 +00001378int mlx4_assign_eq(struct mlx4_dev *dev, char *name, struct cpu_rmap *rmap,
David S. Miller96b2e732014-06-02 00:18:48 -07001379 int *vector)
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001380{
1381
1382 struct mlx4_priv *priv = mlx4_priv(dev);
1383 int vec = 0, err = 0, i;
1384
Yevgeny Petrilin730c41d2012-02-21 03:39:32 +00001385 mutex_lock(&priv->msix_ctl.pool_lock);
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001386 for (i = 0; !vec && i < dev->caps.comp_pool; i++) {
1387 if (~priv->msix_ctl.pool_bm & 1ULL << i) {
1388 priv->msix_ctl.pool_bm |= 1ULL << i;
1389 vec = dev->caps.num_comp_vectors + 1 + i;
1390 snprintf(priv->eq_table.irq_names +
1391 vec * MLX4_IRQNAME_SIZE,
1392 MLX4_IRQNAME_SIZE, "%s", name);
Amir Vadaid9236c32012-07-18 22:33:51 +00001393#ifdef CONFIG_RFS_ACCEL
1394 if (rmap) {
1395 err = irq_cpu_rmap_add(rmap,
1396 priv->eq_table.eq[vec].irq);
1397 if (err)
1398 mlx4_warn(dev, "Failed adding irq rmap\n");
1399 }
1400#endif
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001401 err = request_irq(priv->eq_table.eq[vec].irq,
1402 mlx4_msi_x_interrupt, 0,
1403 &priv->eq_table.irq_names[vec<<5],
1404 priv->eq_table.eq + vec);
1405 if (err) {
1406 /*zero out bit by fliping it*/
1407 priv->msix_ctl.pool_bm ^= 1 << i;
1408 vec = 0;
1409 continue;
1410 /*we dont want to break here*/
1411 }
Yuval Atias2eacc232014-05-14 12:15:10 +03001412 mlx4_assign_irq_notifier(priv, dev,
1413 priv->eq_table.eq[vec].irq);
1414
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001415 eq_set_ci(&priv->eq_table.eq[vec], 1);
1416 }
1417 }
Yevgeny Petrilin730c41d2012-02-21 03:39:32 +00001418 mutex_unlock(&priv->msix_ctl.pool_lock);
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001419
1420 if (vec) {
1421 *vector = vec;
1422 } else {
1423 *vector = 0;
1424 err = (i == dev->caps.comp_pool) ? -ENOSPC : err;
1425 }
1426 return err;
1427}
1428EXPORT_SYMBOL(mlx4_assign_eq);
1429
1430void mlx4_release_eq(struct mlx4_dev *dev, int vec)
1431{
1432 struct mlx4_priv *priv = mlx4_priv(dev);
1433 /*bm index*/
1434 int i = vec - dev->caps.num_comp_vectors - 1;
1435
1436 if (likely(i >= 0)) {
1437 /*sanity check , making sure were not trying to free irq's
1438 Belonging to a legacy EQ*/
Yevgeny Petrilin730c41d2012-02-21 03:39:32 +00001439 mutex_lock(&priv->msix_ctl.pool_lock);
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001440 if (priv->msix_ctl.pool_bm & 1ULL << i) {
Yuval Atias2eacc232014-05-14 12:15:10 +03001441 irq_set_affinity_notifier(
1442 priv->eq_table.eq[vec].irq,
1443 NULL);
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001444 free_irq(priv->eq_table.eq[vec].irq,
1445 &priv->eq_table.eq[vec]);
1446 priv->msix_ctl.pool_bm &= ~(1ULL << i);
1447 }
Yevgeny Petrilin730c41d2012-02-21 03:39:32 +00001448 mutex_unlock(&priv->msix_ctl.pool_lock);
Yevgeny Petrilin0b7ca5a2011-03-22 22:37:47 +00001449 }
1450
1451}
1452EXPORT_SYMBOL(mlx4_release_eq);
1453