eq.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. /*
  2. * Copyright (c) 2005, 2006, 2007, 2008 Mellanox Technologies. All rights reserved.
  3. * 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. #include <linux/init.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/slab.h>
  36. #include <linux/export.h>
  37. #include <linux/mm.h>
  38. #include <linux/dma-mapping.h>
  39. #include <linux/mlx4/cmd.h>
  40. #include <linux/cpu_rmap.h>
  41. #include "mlx4.h"
  42. #include "fw.h"
  43. enum {
  44. MLX4_IRQNAME_SIZE = 32
  45. };
  46. enum {
  47. MLX4_NUM_ASYNC_EQE = 0x100,
  48. MLX4_NUM_SPARE_EQE = 0x80,
  49. MLX4_EQ_ENTRY_SIZE = 0x20
  50. };
  51. #define MLX4_EQ_STATUS_OK ( 0 << 28)
  52. #define MLX4_EQ_STATUS_WRITE_FAIL (10 << 28)
  53. #define MLX4_EQ_OWNER_SW ( 0 << 24)
  54. #define MLX4_EQ_OWNER_HW ( 1 << 24)
  55. #define MLX4_EQ_FLAG_EC ( 1 << 18)
  56. #define MLX4_EQ_FLAG_OI ( 1 << 17)
  57. #define MLX4_EQ_STATE_ARMED ( 9 << 8)
  58. #define MLX4_EQ_STATE_FIRED (10 << 8)
  59. #define MLX4_EQ_STATE_ALWAYS_ARMED (11 << 8)
  60. #define MLX4_ASYNC_EVENT_MASK ((1ull << MLX4_EVENT_TYPE_PATH_MIG) | \
  61. (1ull << MLX4_EVENT_TYPE_COMM_EST) | \
  62. (1ull << MLX4_EVENT_TYPE_SQ_DRAINED) | \
  63. (1ull << MLX4_EVENT_TYPE_CQ_ERROR) | \
  64. (1ull << MLX4_EVENT_TYPE_WQ_CATAS_ERROR) | \
  65. (1ull << MLX4_EVENT_TYPE_EEC_CATAS_ERROR) | \
  66. (1ull << MLX4_EVENT_TYPE_PATH_MIG_FAILED) | \
  67. (1ull << MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR) | \
  68. (1ull << MLX4_EVENT_TYPE_WQ_ACCESS_ERROR) | \
  69. (1ull << MLX4_EVENT_TYPE_PORT_CHANGE) | \
  70. (1ull << MLX4_EVENT_TYPE_ECC_DETECT) | \
  71. (1ull << MLX4_EVENT_TYPE_SRQ_CATAS_ERROR) | \
  72. (1ull << MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE) | \
  73. (1ull << MLX4_EVENT_TYPE_SRQ_LIMIT) | \
  74. (1ull << MLX4_EVENT_TYPE_CMD) | \
  75. (1ull << MLX4_EVENT_TYPE_COMM_CHANNEL) | \
  76. (1ull << MLX4_EVENT_TYPE_FLR_EVENT) | \
  77. (1ull << MLX4_EVENT_TYPE_FATAL_WARNING))
  78. static u64 get_async_ev_mask(struct mlx4_dev *dev)
  79. {
  80. u64 async_ev_mask = MLX4_ASYNC_EVENT_MASK;
  81. if (dev->caps.flags & MLX4_DEV_CAP_FLAG_PORT_MNG_CHG_EV)
  82. async_ev_mask |= (1ull << MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT);
  83. return async_ev_mask;
  84. }
  85. static void eq_set_ci(struct mlx4_eq *eq, int req_not)
  86. {
  87. __raw_writel((__force u32) cpu_to_be32((eq->cons_index & 0xffffff) |
  88. req_not << 31),
  89. eq->doorbell);
  90. /* We still want ordering, just not swabbing, so add a barrier */
  91. mb();
  92. }
  93. static struct mlx4_eqe *get_eqe(struct mlx4_eq *eq, u32 entry)
  94. {
  95. unsigned long off = (entry & (eq->nent - 1)) * MLX4_EQ_ENTRY_SIZE;
  96. return eq->page_list[off / PAGE_SIZE].buf + off % PAGE_SIZE;
  97. }
  98. static struct mlx4_eqe *next_eqe_sw(struct mlx4_eq *eq)
  99. {
  100. struct mlx4_eqe *eqe = get_eqe(eq, eq->cons_index);
  101. return !!(eqe->owner & 0x80) ^ !!(eq->cons_index & eq->nent) ? NULL : eqe;
  102. }
  103. static struct mlx4_eqe *next_slave_event_eqe(struct mlx4_slave_event_eq *slave_eq)
  104. {
  105. struct mlx4_eqe *eqe =
  106. &slave_eq->event_eqe[slave_eq->cons & (SLAVE_EVENT_EQ_SIZE - 1)];
  107. return (!!(eqe->owner & 0x80) ^
  108. !!(slave_eq->cons & SLAVE_EVENT_EQ_SIZE)) ?
  109. eqe : NULL;
  110. }
  111. void mlx4_gen_slave_eqe(struct work_struct *work)
  112. {
  113. struct mlx4_mfunc_master_ctx *master =
  114. container_of(work, struct mlx4_mfunc_master_ctx,
  115. slave_event_work);
  116. struct mlx4_mfunc *mfunc =
  117. container_of(master, struct mlx4_mfunc, master);
  118. struct mlx4_priv *priv = container_of(mfunc, struct mlx4_priv, mfunc);
  119. struct mlx4_dev *dev = &priv->dev;
  120. struct mlx4_slave_event_eq *slave_eq = &mfunc->master.slave_eq;
  121. struct mlx4_eqe *eqe;
  122. u8 slave;
  123. int i;
  124. for (eqe = next_slave_event_eqe(slave_eq); eqe;
  125. eqe = next_slave_event_eqe(slave_eq)) {
  126. slave = eqe->slave_id;
  127. /* All active slaves need to receive the event */
  128. if (slave == ALL_SLAVES) {
  129. for (i = 0; i < dev->num_slaves; i++) {
  130. if (i != dev->caps.function &&
  131. master->slave_state[i].active)
  132. if (mlx4_GEN_EQE(dev, i, eqe))
  133. mlx4_warn(dev, "Failed to "
  134. " generate event "
  135. "for slave %d\n", i);
  136. }
  137. } else {
  138. if (mlx4_GEN_EQE(dev, slave, eqe))
  139. mlx4_warn(dev, "Failed to generate event "
  140. "for slave %d\n", slave);
  141. }
  142. ++slave_eq->cons;
  143. }
  144. }
  145. static void slave_event(struct mlx4_dev *dev, u8 slave, struct mlx4_eqe *eqe)
  146. {
  147. struct mlx4_priv *priv = mlx4_priv(dev);
  148. struct mlx4_slave_event_eq *slave_eq = &priv->mfunc.master.slave_eq;
  149. struct mlx4_eqe *s_eqe =
  150. &slave_eq->event_eqe[slave_eq->prod & (SLAVE_EVENT_EQ_SIZE - 1)];
  151. if ((!!(s_eqe->owner & 0x80)) ^
  152. (!!(slave_eq->prod & SLAVE_EVENT_EQ_SIZE))) {
  153. mlx4_warn(dev, "Master failed to generate an EQE for slave: %d. "
  154. "No free EQE on slave events queue\n", slave);
  155. return;
  156. }
  157. memcpy(s_eqe, eqe, sizeof(struct mlx4_eqe) - 1);
  158. s_eqe->slave_id = slave;
  159. /* ensure all information is written before setting the ownersip bit */
  160. wmb();
  161. s_eqe->owner = !!(slave_eq->prod & SLAVE_EVENT_EQ_SIZE) ? 0x0 : 0x80;
  162. ++slave_eq->prod;
  163. queue_work(priv->mfunc.master.comm_wq,
  164. &priv->mfunc.master.slave_event_work);
  165. }
  166. static void mlx4_slave_event(struct mlx4_dev *dev, int slave,
  167. struct mlx4_eqe *eqe)
  168. {
  169. struct mlx4_priv *priv = mlx4_priv(dev);
  170. struct mlx4_slave_state *s_slave =
  171. &priv->mfunc.master.slave_state[slave];
  172. if (!s_slave->active) {
  173. /*mlx4_warn(dev, "Trying to pass event to inactive slave\n");*/
  174. return;
  175. }
  176. slave_event(dev, slave, eqe);
  177. }
  178. void mlx4_master_handle_slave_flr(struct work_struct *work)
  179. {
  180. struct mlx4_mfunc_master_ctx *master =
  181. container_of(work, struct mlx4_mfunc_master_ctx,
  182. slave_flr_event_work);
  183. struct mlx4_mfunc *mfunc =
  184. container_of(master, struct mlx4_mfunc, master);
  185. struct mlx4_priv *priv =
  186. container_of(mfunc, struct mlx4_priv, mfunc);
  187. struct mlx4_dev *dev = &priv->dev;
  188. struct mlx4_slave_state *slave_state = priv->mfunc.master.slave_state;
  189. int i;
  190. int err;
  191. mlx4_dbg(dev, "mlx4_handle_slave_flr\n");
  192. for (i = 0 ; i < dev->num_slaves; i++) {
  193. if (MLX4_COMM_CMD_FLR == slave_state[i].last_cmd) {
  194. mlx4_dbg(dev, "mlx4_handle_slave_flr: "
  195. "clean slave: %d\n", i);
  196. mlx4_delete_all_resources_for_slave(dev, i);
  197. /*return the slave to running mode*/
  198. spin_lock(&priv->mfunc.master.slave_state_lock);
  199. slave_state[i].last_cmd = MLX4_COMM_CMD_RESET;
  200. slave_state[i].is_slave_going_down = 0;
  201. spin_unlock(&priv->mfunc.master.slave_state_lock);
  202. /*notify the FW:*/
  203. err = mlx4_cmd(dev, 0, i, 0, MLX4_CMD_INFORM_FLR_DONE,
  204. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  205. if (err)
  206. mlx4_warn(dev, "Failed to notify FW on "
  207. "FLR done (slave:%d)\n", i);
  208. }
  209. }
  210. }
  211. static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
  212. {
  213. struct mlx4_priv *priv = mlx4_priv(dev);
  214. struct mlx4_eqe *eqe;
  215. int cqn;
  216. int eqes_found = 0;
  217. int set_ci = 0;
  218. int port;
  219. int slave = 0;
  220. int ret;
  221. u32 flr_slave;
  222. u8 update_slave_state;
  223. int i;
  224. while ((eqe = next_eqe_sw(eq))) {
  225. /*
  226. * Make sure we read EQ entry contents after we've
  227. * checked the ownership bit.
  228. */
  229. rmb();
  230. switch (eqe->type) {
  231. case MLX4_EVENT_TYPE_COMP:
  232. cqn = be32_to_cpu(eqe->event.comp.cqn) & 0xffffff;
  233. mlx4_cq_completion(dev, cqn);
  234. break;
  235. case MLX4_EVENT_TYPE_PATH_MIG:
  236. case MLX4_EVENT_TYPE_COMM_EST:
  237. case MLX4_EVENT_TYPE_SQ_DRAINED:
  238. case MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE:
  239. case MLX4_EVENT_TYPE_WQ_CATAS_ERROR:
  240. case MLX4_EVENT_TYPE_PATH_MIG_FAILED:
  241. case MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
  242. case MLX4_EVENT_TYPE_WQ_ACCESS_ERROR:
  243. mlx4_dbg(dev, "event %d arrived\n", eqe->type);
  244. if (mlx4_is_master(dev)) {
  245. /* forward only to slave owning the QP */
  246. ret = mlx4_get_slave_from_resource_id(dev,
  247. RES_QP,
  248. be32_to_cpu(eqe->event.qp.qpn)
  249. & 0xffffff, &slave);
  250. if (ret && ret != -ENOENT) {
  251. mlx4_dbg(dev, "QP event %02x(%02x) on "
  252. "EQ %d at index %u: could "
  253. "not get slave id (%d)\n",
  254. eqe->type, eqe->subtype,
  255. eq->eqn, eq->cons_index, ret);
  256. break;
  257. }
  258. if (!ret && slave != dev->caps.function) {
  259. mlx4_slave_event(dev, slave, eqe);
  260. break;
  261. }
  262. }
  263. mlx4_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) &
  264. 0xffffff, eqe->type);
  265. break;
  266. case MLX4_EVENT_TYPE_SRQ_LIMIT:
  267. mlx4_warn(dev, "%s: MLX4_EVENT_TYPE_SRQ_LIMIT\n",
  268. __func__);
  269. case MLX4_EVENT_TYPE_SRQ_CATAS_ERROR:
  270. if (mlx4_is_master(dev)) {
  271. /* forward only to slave owning the SRQ */
  272. ret = mlx4_get_slave_from_resource_id(dev,
  273. RES_SRQ,
  274. be32_to_cpu(eqe->event.srq.srqn)
  275. & 0xffffff,
  276. &slave);
  277. if (ret && ret != -ENOENT) {
  278. mlx4_warn(dev, "SRQ event %02x(%02x) "
  279. "on EQ %d at index %u: could"
  280. " not get slave id (%d)\n",
  281. eqe->type, eqe->subtype,
  282. eq->eqn, eq->cons_index, ret);
  283. break;
  284. }
  285. mlx4_warn(dev, "%s: slave:%d, srq_no:0x%x,"
  286. " event: %02x(%02x)\n", __func__,
  287. slave,
  288. be32_to_cpu(eqe->event.srq.srqn),
  289. eqe->type, eqe->subtype);
  290. if (!ret && slave != dev->caps.function) {
  291. mlx4_warn(dev, "%s: sending event "
  292. "%02x(%02x) to slave:%d\n",
  293. __func__, eqe->type,
  294. eqe->subtype, slave);
  295. mlx4_slave_event(dev, slave, eqe);
  296. break;
  297. }
  298. }
  299. mlx4_srq_event(dev, be32_to_cpu(eqe->event.srq.srqn) &
  300. 0xffffff, eqe->type);
  301. break;
  302. case MLX4_EVENT_TYPE_CMD:
  303. mlx4_cmd_event(dev,
  304. be16_to_cpu(eqe->event.cmd.token),
  305. eqe->event.cmd.status,
  306. be64_to_cpu(eqe->event.cmd.out_param));
  307. break;
  308. case MLX4_EVENT_TYPE_PORT_CHANGE:
  309. port = be32_to_cpu(eqe->event.port_change.port) >> 28;
  310. if (eqe->subtype == MLX4_PORT_CHANGE_SUBTYPE_DOWN) {
  311. mlx4_dispatch_event(dev,
  312. MLX4_DEV_EVENT_PORT_DOWN,
  313. port);
  314. mlx4_priv(dev)->sense.do_sense_port[port] = 1;
  315. if (mlx4_is_master(dev))
  316. /*change the state of all slave's port
  317. * to down:*/
  318. for (i = 0; i < dev->num_slaves; i++) {
  319. mlx4_dbg(dev, "%s: Sending "
  320. "MLX4_PORT_CHANGE_SUBTYPE_DOWN"
  321. " to slave: %d, port:%d\n",
  322. __func__, i, port);
  323. if (i == dev->caps.function)
  324. continue;
  325. mlx4_slave_event(dev, i, eqe);
  326. }
  327. } else {
  328. mlx4_dispatch_event(dev,
  329. MLX4_DEV_EVENT_PORT_UP,
  330. port);
  331. mlx4_priv(dev)->sense.do_sense_port[port] = 0;
  332. if (mlx4_is_master(dev)) {
  333. for (i = 0; i < dev->num_slaves; i++) {
  334. if (i == dev->caps.function)
  335. continue;
  336. mlx4_slave_event(dev, i, eqe);
  337. }
  338. }
  339. }
  340. break;
  341. case MLX4_EVENT_TYPE_CQ_ERROR:
  342. mlx4_warn(dev, "CQ %s on CQN %06x\n",
  343. eqe->event.cq_err.syndrome == 1 ?
  344. "overrun" : "access violation",
  345. be32_to_cpu(eqe->event.cq_err.cqn) & 0xffffff);
  346. if (mlx4_is_master(dev)) {
  347. ret = mlx4_get_slave_from_resource_id(dev,
  348. RES_CQ,
  349. be32_to_cpu(eqe->event.cq_err.cqn)
  350. & 0xffffff, &slave);
  351. if (ret && ret != -ENOENT) {
  352. mlx4_dbg(dev, "CQ event %02x(%02x) on "
  353. "EQ %d at index %u: could "
  354. "not get slave id (%d)\n",
  355. eqe->type, eqe->subtype,
  356. eq->eqn, eq->cons_index, ret);
  357. break;
  358. }
  359. if (!ret && slave != dev->caps.function) {
  360. mlx4_slave_event(dev, slave, eqe);
  361. break;
  362. }
  363. }
  364. mlx4_cq_event(dev,
  365. be32_to_cpu(eqe->event.cq_err.cqn)
  366. & 0xffffff,
  367. eqe->type);
  368. break;
  369. case MLX4_EVENT_TYPE_EQ_OVERFLOW:
  370. mlx4_warn(dev, "EQ overrun on EQN %d\n", eq->eqn);
  371. break;
  372. case MLX4_EVENT_TYPE_COMM_CHANNEL:
  373. if (!mlx4_is_master(dev)) {
  374. mlx4_warn(dev, "Received comm channel event "
  375. "for non master device\n");
  376. break;
  377. }
  378. memcpy(&priv->mfunc.master.comm_arm_bit_vector,
  379. eqe->event.comm_channel_arm.bit_vec,
  380. sizeof eqe->event.comm_channel_arm.bit_vec);
  381. queue_work(priv->mfunc.master.comm_wq,
  382. &priv->mfunc.master.comm_work);
  383. break;
  384. case MLX4_EVENT_TYPE_FLR_EVENT:
  385. flr_slave = be32_to_cpu(eqe->event.flr_event.slave_id);
  386. if (!mlx4_is_master(dev)) {
  387. mlx4_warn(dev, "Non-master function received"
  388. "FLR event\n");
  389. break;
  390. }
  391. mlx4_dbg(dev, "FLR event for slave: %d\n", flr_slave);
  392. if (flr_slave >= dev->num_slaves) {
  393. mlx4_warn(dev,
  394. "Got FLR for unknown function: %d\n",
  395. flr_slave);
  396. update_slave_state = 0;
  397. } else
  398. update_slave_state = 1;
  399. spin_lock(&priv->mfunc.master.slave_state_lock);
  400. if (update_slave_state) {
  401. priv->mfunc.master.slave_state[flr_slave].active = false;
  402. priv->mfunc.master.slave_state[flr_slave].last_cmd = MLX4_COMM_CMD_FLR;
  403. priv->mfunc.master.slave_state[flr_slave].is_slave_going_down = 1;
  404. }
  405. spin_unlock(&priv->mfunc.master.slave_state_lock);
  406. queue_work(priv->mfunc.master.comm_wq,
  407. &priv->mfunc.master.slave_flr_event_work);
  408. break;
  409. case MLX4_EVENT_TYPE_FATAL_WARNING:
  410. if (eqe->subtype == MLX4_FATAL_WARNING_SUBTYPE_WARMING) {
  411. if (mlx4_is_master(dev))
  412. for (i = 0; i < dev->num_slaves; i++) {
  413. mlx4_dbg(dev, "%s: Sending "
  414. "MLX4_FATAL_WARNING_SUBTYPE_WARMING"
  415. " to slave: %d\n", __func__, i);
  416. if (i == dev->caps.function)
  417. continue;
  418. mlx4_slave_event(dev, i, eqe);
  419. }
  420. mlx4_err(dev, "Temperature Threshold was reached! "
  421. "Threshold: %d celsius degrees; "
  422. "Current Temperature: %d\n",
  423. be16_to_cpu(eqe->event.warming.warning_threshold),
  424. be16_to_cpu(eqe->event.warming.current_temperature));
  425. } else
  426. mlx4_warn(dev, "Unhandled event FATAL WARNING (%02x), "
  427. "subtype %02x on EQ %d at index %u. owner=%x, "
  428. "nent=0x%x, slave=%x, ownership=%s\n",
  429. eqe->type, eqe->subtype, eq->eqn,
  430. eq->cons_index, eqe->owner, eq->nent,
  431. eqe->slave_id,
  432. !!(eqe->owner & 0x80) ^
  433. !!(eq->cons_index & eq->nent) ? "HW" : "SW");
  434. break;
  435. case MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT:
  436. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_MGMT_CHANGE,
  437. (unsigned long) eqe);
  438. break;
  439. case MLX4_EVENT_TYPE_EEC_CATAS_ERROR:
  440. case MLX4_EVENT_TYPE_ECC_DETECT:
  441. default:
  442. mlx4_warn(dev, "Unhandled event %02x(%02x) on EQ %d at "
  443. "index %u. owner=%x, nent=0x%x, slave=%x, "
  444. "ownership=%s\n",
  445. eqe->type, eqe->subtype, eq->eqn,
  446. eq->cons_index, eqe->owner, eq->nent,
  447. eqe->slave_id,
  448. !!(eqe->owner & 0x80) ^
  449. !!(eq->cons_index & eq->nent) ? "HW" : "SW");
  450. break;
  451. };
  452. ++eq->cons_index;
  453. eqes_found = 1;
  454. ++set_ci;
  455. /*
  456. * The HCA will think the queue has overflowed if we
  457. * don't tell it we've been processing events. We
  458. * create our EQs with MLX4_NUM_SPARE_EQE extra
  459. * entries, so we must update our consumer index at
  460. * least that often.
  461. */
  462. if (unlikely(set_ci >= MLX4_NUM_SPARE_EQE)) {
  463. eq_set_ci(eq, 0);
  464. set_ci = 0;
  465. }
  466. }
  467. eq_set_ci(eq, 1);
  468. return eqes_found;
  469. }
  470. static irqreturn_t mlx4_interrupt(int irq, void *dev_ptr)
  471. {
  472. struct mlx4_dev *dev = dev_ptr;
  473. struct mlx4_priv *priv = mlx4_priv(dev);
  474. int work = 0;
  475. int i;
  476. writel(priv->eq_table.clr_mask, priv->eq_table.clr_int);
  477. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  478. work |= mlx4_eq_int(dev, &priv->eq_table.eq[i]);
  479. return IRQ_RETVAL(work);
  480. }
  481. static irqreturn_t mlx4_msi_x_interrupt(int irq, void *eq_ptr)
  482. {
  483. struct mlx4_eq *eq = eq_ptr;
  484. struct mlx4_dev *dev = eq->dev;
  485. mlx4_eq_int(dev, eq);
  486. /* MSI-X vectors always belong to us */
  487. return IRQ_HANDLED;
  488. }
  489. int mlx4_MAP_EQ_wrapper(struct mlx4_dev *dev, int slave,
  490. struct mlx4_vhcr *vhcr,
  491. struct mlx4_cmd_mailbox *inbox,
  492. struct mlx4_cmd_mailbox *outbox,
  493. struct mlx4_cmd_info *cmd)
  494. {
  495. struct mlx4_priv *priv = mlx4_priv(dev);
  496. struct mlx4_slave_event_eq_info *event_eq =
  497. priv->mfunc.master.slave_state[slave].event_eq;
  498. u32 in_modifier = vhcr->in_modifier;
  499. u32 eqn = in_modifier & 0x1FF;
  500. u64 in_param = vhcr->in_param;
  501. int err = 0;
  502. int i;
  503. if (slave == dev->caps.function)
  504. err = mlx4_cmd(dev, in_param, (in_modifier & 0x80000000) | eqn,
  505. 0, MLX4_CMD_MAP_EQ, MLX4_CMD_TIME_CLASS_B,
  506. MLX4_CMD_NATIVE);
  507. if (!err)
  508. for (i = 0; i < MLX4_EVENT_TYPES_NUM; ++i)
  509. if (in_param & (1LL << i))
  510. event_eq[i].eqn = in_modifier >> 31 ? -1 : eqn;
  511. return err;
  512. }
  513. static int mlx4_MAP_EQ(struct mlx4_dev *dev, u64 event_mask, int unmap,
  514. int eq_num)
  515. {
  516. return mlx4_cmd(dev, event_mask, (unmap << 31) | eq_num,
  517. 0, MLX4_CMD_MAP_EQ, MLX4_CMD_TIME_CLASS_B,
  518. MLX4_CMD_WRAPPED);
  519. }
  520. static int mlx4_SW2HW_EQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
  521. int eq_num)
  522. {
  523. return mlx4_cmd(dev, mailbox->dma, eq_num, 0,
  524. MLX4_CMD_SW2HW_EQ, MLX4_CMD_TIME_CLASS_A,
  525. MLX4_CMD_WRAPPED);
  526. }
  527. static int mlx4_HW2SW_EQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
  528. int eq_num)
  529. {
  530. return mlx4_cmd_box(dev, 0, mailbox->dma, eq_num,
  531. 0, MLX4_CMD_HW2SW_EQ, MLX4_CMD_TIME_CLASS_A,
  532. MLX4_CMD_WRAPPED);
  533. }
  534. static int mlx4_num_eq_uar(struct mlx4_dev *dev)
  535. {
  536. /*
  537. * Each UAR holds 4 EQ doorbells. To figure out how many UARs
  538. * we need to map, take the difference of highest index and
  539. * the lowest index we'll use and add 1.
  540. */
  541. return (dev->caps.num_comp_vectors + 1 + dev->caps.reserved_eqs +
  542. dev->caps.comp_pool)/4 - dev->caps.reserved_eqs/4 + 1;
  543. }
  544. static void __iomem *mlx4_get_eq_uar(struct mlx4_dev *dev, struct mlx4_eq *eq)
  545. {
  546. struct mlx4_priv *priv = mlx4_priv(dev);
  547. int index;
  548. index = eq->eqn / 4 - dev->caps.reserved_eqs / 4;
  549. if (!priv->eq_table.uar_map[index]) {
  550. priv->eq_table.uar_map[index] =
  551. ioremap(pci_resource_start(dev->pdev, 2) +
  552. ((eq->eqn / 4) << PAGE_SHIFT),
  553. PAGE_SIZE);
  554. if (!priv->eq_table.uar_map[index]) {
  555. mlx4_err(dev, "Couldn't map EQ doorbell for EQN 0x%06x\n",
  556. eq->eqn);
  557. return NULL;
  558. }
  559. }
  560. return priv->eq_table.uar_map[index] + 0x800 + 8 * (eq->eqn % 4);
  561. }
  562. static int mlx4_create_eq(struct mlx4_dev *dev, int nent,
  563. u8 intr, struct mlx4_eq *eq)
  564. {
  565. struct mlx4_priv *priv = mlx4_priv(dev);
  566. struct mlx4_cmd_mailbox *mailbox;
  567. struct mlx4_eq_context *eq_context;
  568. int npages;
  569. u64 *dma_list = NULL;
  570. dma_addr_t t;
  571. u64 mtt_addr;
  572. int err = -ENOMEM;
  573. int i;
  574. eq->dev = dev;
  575. eq->nent = roundup_pow_of_two(max(nent, 2));
  576. npages = PAGE_ALIGN(eq->nent * MLX4_EQ_ENTRY_SIZE) / PAGE_SIZE;
  577. eq->page_list = kmalloc(npages * sizeof *eq->page_list,
  578. GFP_KERNEL);
  579. if (!eq->page_list)
  580. goto err_out;
  581. for (i = 0; i < npages; ++i)
  582. eq->page_list[i].buf = NULL;
  583. dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
  584. if (!dma_list)
  585. goto err_out_free;
  586. mailbox = mlx4_alloc_cmd_mailbox(dev);
  587. if (IS_ERR(mailbox))
  588. goto err_out_free;
  589. eq_context = mailbox->buf;
  590. for (i = 0; i < npages; ++i) {
  591. eq->page_list[i].buf = dma_alloc_coherent(&dev->pdev->dev,
  592. PAGE_SIZE, &t, GFP_KERNEL);
  593. if (!eq->page_list[i].buf)
  594. goto err_out_free_pages;
  595. dma_list[i] = t;
  596. eq->page_list[i].map = t;
  597. memset(eq->page_list[i].buf, 0, PAGE_SIZE);
  598. }
  599. eq->eqn = mlx4_bitmap_alloc(&priv->eq_table.bitmap);
  600. if (eq->eqn == -1)
  601. goto err_out_free_pages;
  602. eq->doorbell = mlx4_get_eq_uar(dev, eq);
  603. if (!eq->doorbell) {
  604. err = -ENOMEM;
  605. goto err_out_free_eq;
  606. }
  607. err = mlx4_mtt_init(dev, npages, PAGE_SHIFT, &eq->mtt);
  608. if (err)
  609. goto err_out_free_eq;
  610. err = mlx4_write_mtt(dev, &eq->mtt, 0, npages, dma_list);
  611. if (err)
  612. goto err_out_free_mtt;
  613. memset(eq_context, 0, sizeof *eq_context);
  614. eq_context->flags = cpu_to_be32(MLX4_EQ_STATUS_OK |
  615. MLX4_EQ_STATE_ARMED);
  616. eq_context->log_eq_size = ilog2(eq->nent);
  617. eq_context->intr = intr;
  618. eq_context->log_page_size = PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT;
  619. mtt_addr = mlx4_mtt_addr(dev, &eq->mtt);
  620. eq_context->mtt_base_addr_h = mtt_addr >> 32;
  621. eq_context->mtt_base_addr_l = cpu_to_be32(mtt_addr & 0xffffffff);
  622. err = mlx4_SW2HW_EQ(dev, mailbox, eq->eqn);
  623. if (err) {
  624. mlx4_warn(dev, "SW2HW_EQ failed (%d)\n", err);
  625. goto err_out_free_mtt;
  626. }
  627. kfree(dma_list);
  628. mlx4_free_cmd_mailbox(dev, mailbox);
  629. eq->cons_index = 0;
  630. return err;
  631. err_out_free_mtt:
  632. mlx4_mtt_cleanup(dev, &eq->mtt);
  633. err_out_free_eq:
  634. mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn);
  635. err_out_free_pages:
  636. for (i = 0; i < npages; ++i)
  637. if (eq->page_list[i].buf)
  638. dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
  639. eq->page_list[i].buf,
  640. eq->page_list[i].map);
  641. mlx4_free_cmd_mailbox(dev, mailbox);
  642. err_out_free:
  643. kfree(eq->page_list);
  644. kfree(dma_list);
  645. err_out:
  646. return err;
  647. }
  648. static void mlx4_free_eq(struct mlx4_dev *dev,
  649. struct mlx4_eq *eq)
  650. {
  651. struct mlx4_priv *priv = mlx4_priv(dev);
  652. struct mlx4_cmd_mailbox *mailbox;
  653. int err;
  654. int npages = PAGE_ALIGN(MLX4_EQ_ENTRY_SIZE * eq->nent) / PAGE_SIZE;
  655. int i;
  656. mailbox = mlx4_alloc_cmd_mailbox(dev);
  657. if (IS_ERR(mailbox))
  658. return;
  659. err = mlx4_HW2SW_EQ(dev, mailbox, eq->eqn);
  660. if (err)
  661. mlx4_warn(dev, "HW2SW_EQ failed (%d)\n", err);
  662. if (0) {
  663. mlx4_dbg(dev, "Dumping EQ context %02x:\n", eq->eqn);
  664. for (i = 0; i < sizeof (struct mlx4_eq_context) / 4; ++i) {
  665. if (i % 4 == 0)
  666. pr_cont("[%02x] ", i * 4);
  667. pr_cont(" %08x", be32_to_cpup(mailbox->buf + i * 4));
  668. if ((i + 1) % 4 == 0)
  669. pr_cont("\n");
  670. }
  671. }
  672. mlx4_mtt_cleanup(dev, &eq->mtt);
  673. for (i = 0; i < npages; ++i)
  674. dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
  675. eq->page_list[i].buf,
  676. eq->page_list[i].map);
  677. kfree(eq->page_list);
  678. mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn);
  679. mlx4_free_cmd_mailbox(dev, mailbox);
  680. }
  681. static void mlx4_free_irqs(struct mlx4_dev *dev)
  682. {
  683. struct mlx4_eq_table *eq_table = &mlx4_priv(dev)->eq_table;
  684. struct mlx4_priv *priv = mlx4_priv(dev);
  685. int i, vec;
  686. if (eq_table->have_irq)
  687. free_irq(dev->pdev->irq, dev);
  688. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  689. if (eq_table->eq[i].have_irq) {
  690. free_irq(eq_table->eq[i].irq, eq_table->eq + i);
  691. eq_table->eq[i].have_irq = 0;
  692. }
  693. for (i = 0; i < dev->caps.comp_pool; i++) {
  694. /*
  695. * Freeing the assigned irq's
  696. * all bits should be 0, but we need to validate
  697. */
  698. if (priv->msix_ctl.pool_bm & 1ULL << i) {
  699. /* NO need protecting*/
  700. vec = dev->caps.num_comp_vectors + 1 + i;
  701. free_irq(priv->eq_table.eq[vec].irq,
  702. &priv->eq_table.eq[vec]);
  703. }
  704. }
  705. kfree(eq_table->irq_names);
  706. }
  707. static int mlx4_map_clr_int(struct mlx4_dev *dev)
  708. {
  709. struct mlx4_priv *priv = mlx4_priv(dev);
  710. priv->clr_base = ioremap(pci_resource_start(dev->pdev, priv->fw.clr_int_bar) +
  711. priv->fw.clr_int_base, MLX4_CLR_INT_SIZE);
  712. if (!priv->clr_base) {
  713. mlx4_err(dev, "Couldn't map interrupt clear register, aborting.\n");
  714. return -ENOMEM;
  715. }
  716. return 0;
  717. }
  718. static void mlx4_unmap_clr_int(struct mlx4_dev *dev)
  719. {
  720. struct mlx4_priv *priv = mlx4_priv(dev);
  721. iounmap(priv->clr_base);
  722. }
  723. int mlx4_alloc_eq_table(struct mlx4_dev *dev)
  724. {
  725. struct mlx4_priv *priv = mlx4_priv(dev);
  726. priv->eq_table.eq = kcalloc(dev->caps.num_eqs - dev->caps.reserved_eqs,
  727. sizeof *priv->eq_table.eq, GFP_KERNEL);
  728. if (!priv->eq_table.eq)
  729. return -ENOMEM;
  730. return 0;
  731. }
  732. void mlx4_free_eq_table(struct mlx4_dev *dev)
  733. {
  734. kfree(mlx4_priv(dev)->eq_table.eq);
  735. }
  736. int mlx4_init_eq_table(struct mlx4_dev *dev)
  737. {
  738. struct mlx4_priv *priv = mlx4_priv(dev);
  739. int err;
  740. int i;
  741. priv->eq_table.uar_map = kcalloc(mlx4_num_eq_uar(dev),
  742. sizeof *priv->eq_table.uar_map,
  743. GFP_KERNEL);
  744. if (!priv->eq_table.uar_map) {
  745. err = -ENOMEM;
  746. goto err_out_free;
  747. }
  748. err = mlx4_bitmap_init(&priv->eq_table.bitmap, dev->caps.num_eqs,
  749. dev->caps.num_eqs - 1, dev->caps.reserved_eqs, 0);
  750. if (err)
  751. goto err_out_free;
  752. for (i = 0; i < mlx4_num_eq_uar(dev); ++i)
  753. priv->eq_table.uar_map[i] = NULL;
  754. if (!mlx4_is_slave(dev)) {
  755. err = mlx4_map_clr_int(dev);
  756. if (err)
  757. goto err_out_bitmap;
  758. priv->eq_table.clr_mask =
  759. swab32(1 << (priv->eq_table.inta_pin & 31));
  760. priv->eq_table.clr_int = priv->clr_base +
  761. (priv->eq_table.inta_pin < 32 ? 4 : 0);
  762. }
  763. priv->eq_table.irq_names =
  764. kmalloc(MLX4_IRQNAME_SIZE * (dev->caps.num_comp_vectors + 1 +
  765. dev->caps.comp_pool),
  766. GFP_KERNEL);
  767. if (!priv->eq_table.irq_names) {
  768. err = -ENOMEM;
  769. goto err_out_bitmap;
  770. }
  771. for (i = 0; i < dev->caps.num_comp_vectors; ++i) {
  772. err = mlx4_create_eq(dev, dev->caps.num_cqs -
  773. dev->caps.reserved_cqs +
  774. MLX4_NUM_SPARE_EQE,
  775. (dev->flags & MLX4_FLAG_MSI_X) ? i : 0,
  776. &priv->eq_table.eq[i]);
  777. if (err) {
  778. --i;
  779. goto err_out_unmap;
  780. }
  781. }
  782. err = mlx4_create_eq(dev, MLX4_NUM_ASYNC_EQE + MLX4_NUM_SPARE_EQE,
  783. (dev->flags & MLX4_FLAG_MSI_X) ? dev->caps.num_comp_vectors : 0,
  784. &priv->eq_table.eq[dev->caps.num_comp_vectors]);
  785. if (err)
  786. goto err_out_comp;
  787. /*if additional completion vectors poolsize is 0 this loop will not run*/
  788. for (i = dev->caps.num_comp_vectors + 1;
  789. i < dev->caps.num_comp_vectors + dev->caps.comp_pool + 1; ++i) {
  790. err = mlx4_create_eq(dev, dev->caps.num_cqs -
  791. dev->caps.reserved_cqs +
  792. MLX4_NUM_SPARE_EQE,
  793. (dev->flags & MLX4_FLAG_MSI_X) ? i : 0,
  794. &priv->eq_table.eq[i]);
  795. if (err) {
  796. --i;
  797. goto err_out_unmap;
  798. }
  799. }
  800. if (dev->flags & MLX4_FLAG_MSI_X) {
  801. const char *eq_name;
  802. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i) {
  803. if (i < dev->caps.num_comp_vectors) {
  804. snprintf(priv->eq_table.irq_names +
  805. i * MLX4_IRQNAME_SIZE,
  806. MLX4_IRQNAME_SIZE,
  807. "mlx4-comp-%d@pci:%s", i,
  808. pci_name(dev->pdev));
  809. } else {
  810. snprintf(priv->eq_table.irq_names +
  811. i * MLX4_IRQNAME_SIZE,
  812. MLX4_IRQNAME_SIZE,
  813. "mlx4-async@pci:%s",
  814. pci_name(dev->pdev));
  815. }
  816. eq_name = priv->eq_table.irq_names +
  817. i * MLX4_IRQNAME_SIZE;
  818. err = request_irq(priv->eq_table.eq[i].irq,
  819. mlx4_msi_x_interrupt, 0, eq_name,
  820. priv->eq_table.eq + i);
  821. if (err)
  822. goto err_out_async;
  823. priv->eq_table.eq[i].have_irq = 1;
  824. }
  825. } else {
  826. snprintf(priv->eq_table.irq_names,
  827. MLX4_IRQNAME_SIZE,
  828. DRV_NAME "@pci:%s",
  829. pci_name(dev->pdev));
  830. err = request_irq(dev->pdev->irq, mlx4_interrupt,
  831. IRQF_SHARED, priv->eq_table.irq_names, dev);
  832. if (err)
  833. goto err_out_async;
  834. priv->eq_table.have_irq = 1;
  835. }
  836. err = mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
  837. priv->eq_table.eq[dev->caps.num_comp_vectors].eqn);
  838. if (err)
  839. mlx4_warn(dev, "MAP_EQ for async EQ %d failed (%d)\n",
  840. priv->eq_table.eq[dev->caps.num_comp_vectors].eqn, err);
  841. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  842. eq_set_ci(&priv->eq_table.eq[i], 1);
  843. return 0;
  844. err_out_async:
  845. mlx4_free_eq(dev, &priv->eq_table.eq[dev->caps.num_comp_vectors]);
  846. err_out_comp:
  847. i = dev->caps.num_comp_vectors - 1;
  848. err_out_unmap:
  849. while (i >= 0) {
  850. mlx4_free_eq(dev, &priv->eq_table.eq[i]);
  851. --i;
  852. }
  853. if (!mlx4_is_slave(dev))
  854. mlx4_unmap_clr_int(dev);
  855. mlx4_free_irqs(dev);
  856. err_out_bitmap:
  857. mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
  858. err_out_free:
  859. kfree(priv->eq_table.uar_map);
  860. return err;
  861. }
  862. void mlx4_cleanup_eq_table(struct mlx4_dev *dev)
  863. {
  864. struct mlx4_priv *priv = mlx4_priv(dev);
  865. int i;
  866. mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 1,
  867. priv->eq_table.eq[dev->caps.num_comp_vectors].eqn);
  868. mlx4_free_irqs(dev);
  869. for (i = 0; i < dev->caps.num_comp_vectors + dev->caps.comp_pool + 1; ++i)
  870. mlx4_free_eq(dev, &priv->eq_table.eq[i]);
  871. if (!mlx4_is_slave(dev))
  872. mlx4_unmap_clr_int(dev);
  873. for (i = 0; i < mlx4_num_eq_uar(dev); ++i)
  874. if (priv->eq_table.uar_map[i])
  875. iounmap(priv->eq_table.uar_map[i]);
  876. mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
  877. kfree(priv->eq_table.uar_map);
  878. }
  879. /* A test that verifies that we can accept interrupts on all
  880. * the irq vectors of the device.
  881. * Interrupts are checked using the NOP command.
  882. */
  883. int mlx4_test_interrupts(struct mlx4_dev *dev)
  884. {
  885. struct mlx4_priv *priv = mlx4_priv(dev);
  886. int i;
  887. int err;
  888. err = mlx4_NOP(dev);
  889. /* When not in MSI_X, there is only one irq to check */
  890. if (!(dev->flags & MLX4_FLAG_MSI_X) || mlx4_is_slave(dev))
  891. return err;
  892. /* A loop over all completion vectors, for each vector we will check
  893. * whether it works by mapping command completions to that vector
  894. * and performing a NOP command
  895. */
  896. for(i = 0; !err && (i < dev->caps.num_comp_vectors); ++i) {
  897. /* Temporary use polling for command completions */
  898. mlx4_cmd_use_polling(dev);
  899. /* Map the new eq to handle all asyncronous events */
  900. err = mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
  901. priv->eq_table.eq[i].eqn);
  902. if (err) {
  903. mlx4_warn(dev, "Failed mapping eq for interrupt test\n");
  904. mlx4_cmd_use_events(dev);
  905. break;
  906. }
  907. /* Go back to using events */
  908. mlx4_cmd_use_events(dev);
  909. err = mlx4_NOP(dev);
  910. }
  911. /* Return to default */
  912. mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
  913. priv->eq_table.eq[dev->caps.num_comp_vectors].eqn);
  914. return err;
  915. }
  916. EXPORT_SYMBOL(mlx4_test_interrupts);
  917. int mlx4_assign_eq(struct mlx4_dev *dev, char *name, struct cpu_rmap *rmap,
  918. int *vector)
  919. {
  920. struct mlx4_priv *priv = mlx4_priv(dev);
  921. int vec = 0, err = 0, i;
  922. mutex_lock(&priv->msix_ctl.pool_lock);
  923. for (i = 0; !vec && i < dev->caps.comp_pool; i++) {
  924. if (~priv->msix_ctl.pool_bm & 1ULL << i) {
  925. priv->msix_ctl.pool_bm |= 1ULL << i;
  926. vec = dev->caps.num_comp_vectors + 1 + i;
  927. snprintf(priv->eq_table.irq_names +
  928. vec * MLX4_IRQNAME_SIZE,
  929. MLX4_IRQNAME_SIZE, "%s", name);
  930. #ifdef CONFIG_RFS_ACCEL
  931. if (rmap) {
  932. err = irq_cpu_rmap_add(rmap,
  933. priv->eq_table.eq[vec].irq);
  934. if (err)
  935. mlx4_warn(dev, "Failed adding irq rmap\n");
  936. }
  937. #endif
  938. err = request_irq(priv->eq_table.eq[vec].irq,
  939. mlx4_msi_x_interrupt, 0,
  940. &priv->eq_table.irq_names[vec<<5],
  941. priv->eq_table.eq + vec);
  942. if (err) {
  943. /*zero out bit by fliping it*/
  944. priv->msix_ctl.pool_bm ^= 1 << i;
  945. vec = 0;
  946. continue;
  947. /*we dont want to break here*/
  948. }
  949. eq_set_ci(&priv->eq_table.eq[vec], 1);
  950. }
  951. }
  952. mutex_unlock(&priv->msix_ctl.pool_lock);
  953. if (vec) {
  954. *vector = vec;
  955. } else {
  956. *vector = 0;
  957. err = (i == dev->caps.comp_pool) ? -ENOSPC : err;
  958. }
  959. return err;
  960. }
  961. EXPORT_SYMBOL(mlx4_assign_eq);
  962. void mlx4_release_eq(struct mlx4_dev *dev, int vec)
  963. {
  964. struct mlx4_priv *priv = mlx4_priv(dev);
  965. /*bm index*/
  966. int i = vec - dev->caps.num_comp_vectors - 1;
  967. if (likely(i >= 0)) {
  968. /*sanity check , making sure were not trying to free irq's
  969. Belonging to a legacy EQ*/
  970. mutex_lock(&priv->msix_ctl.pool_lock);
  971. if (priv->msix_ctl.pool_bm & 1ULL << i) {
  972. free_irq(priv->eq_table.eq[vec].irq,
  973. &priv->eq_table.eq[vec]);
  974. priv->msix_ctl.pool_bm &= ~(1ULL << i);
  975. }
  976. mutex_unlock(&priv->msix_ctl.pool_lock);
  977. }
  978. }
  979. EXPORT_SYMBOL(mlx4_release_eq);