eq.c 31 KB

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