eq.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561
  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/interrupt.h>
  34. #include <linux/slab.h>
  35. #include <linux/export.h>
  36. #include <linux/mm.h>
  37. #include <linux/dma-mapping.h>
  38. #include <linux/mlx4/cmd.h>
  39. #include <linux/cpu_rmap.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_OP_REQUIRED) | \
  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. if (dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_RECOVERABLE_ERROR_EVENT)
  84. async_ev_mask |= (1ull << MLX4_EVENT_TYPE_RECOVERABLE_ERROR_EVENT);
  85. return async_ev_mask;
  86. }
  87. static void eq_set_ci(struct mlx4_eq *eq, int req_not)
  88. {
  89. __raw_writel((__force u32) cpu_to_be32((eq->cons_index & 0xffffff) |
  90. req_not << 31),
  91. eq->doorbell);
  92. /* We still want ordering, just not swabbing, so add a barrier */
  93. mb();
  94. }
  95. static struct mlx4_eqe *get_eqe(struct mlx4_eq *eq, u32 entry, u8 eqe_factor,
  96. u8 eqe_size)
  97. {
  98. /* (entry & (eq->nent - 1)) gives us a cyclic array */
  99. unsigned long offset = (entry & (eq->nent - 1)) * eqe_size;
  100. /* CX3 is capable of extending the EQE from 32 to 64 bytes with
  101. * strides of 64B,128B and 256B.
  102. * When 64B EQE is used, the first (in the lower addresses)
  103. * 32 bytes in the 64 byte EQE are reserved and the next 32 bytes
  104. * contain the legacy EQE information.
  105. * In all other cases, the first 32B contains the legacy EQE info.
  106. */
  107. return eq->page_list[offset / PAGE_SIZE].buf + (offset + (eqe_factor ? MLX4_EQ_ENTRY_SIZE : 0)) % PAGE_SIZE;
  108. }
  109. static struct mlx4_eqe *next_eqe_sw(struct mlx4_eq *eq, u8 eqe_factor, u8 size)
  110. {
  111. struct mlx4_eqe *eqe = get_eqe(eq, eq->cons_index, eqe_factor, size);
  112. return !!(eqe->owner & 0x80) ^ !!(eq->cons_index & eq->nent) ? NULL : eqe;
  113. }
  114. static struct mlx4_eqe *next_slave_event_eqe(struct mlx4_slave_event_eq *slave_eq)
  115. {
  116. struct mlx4_eqe *eqe =
  117. &slave_eq->event_eqe[slave_eq->cons & (SLAVE_EVENT_EQ_SIZE - 1)];
  118. return (!!(eqe->owner & 0x80) ^
  119. !!(slave_eq->cons & SLAVE_EVENT_EQ_SIZE)) ?
  120. eqe : NULL;
  121. }
  122. void mlx4_gen_slave_eqe(struct work_struct *work)
  123. {
  124. struct mlx4_mfunc_master_ctx *master =
  125. container_of(work, struct mlx4_mfunc_master_ctx,
  126. slave_event_work);
  127. struct mlx4_mfunc *mfunc =
  128. container_of(master, struct mlx4_mfunc, master);
  129. struct mlx4_priv *priv = container_of(mfunc, struct mlx4_priv, mfunc);
  130. struct mlx4_dev *dev = &priv->dev;
  131. struct mlx4_slave_event_eq *slave_eq = &mfunc->master.slave_eq;
  132. struct mlx4_eqe *eqe;
  133. u8 slave;
  134. int i, phys_port, slave_port;
  135. for (eqe = next_slave_event_eqe(slave_eq); eqe;
  136. eqe = next_slave_event_eqe(slave_eq)) {
  137. slave = eqe->slave_id;
  138. /* All active slaves need to receive the event */
  139. if (slave == ALL_SLAVES) {
  140. for (i = 0; i <= dev->persist->num_vfs; i++) {
  141. phys_port = 0;
  142. if (eqe->type == MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT &&
  143. eqe->subtype == MLX4_DEV_PMC_SUBTYPE_PORT_INFO) {
  144. phys_port = eqe->event.port_mgmt_change.port;
  145. slave_port = mlx4_phys_to_slave_port(dev, i, phys_port);
  146. if (slave_port < 0) /* VF doesn't have this port */
  147. continue;
  148. eqe->event.port_mgmt_change.port = slave_port;
  149. }
  150. if (mlx4_GEN_EQE(dev, i, eqe))
  151. mlx4_warn(dev, "Failed to generate event for slave %d\n",
  152. i);
  153. if (phys_port)
  154. eqe->event.port_mgmt_change.port = phys_port;
  155. }
  156. } else {
  157. if (mlx4_GEN_EQE(dev, slave, eqe))
  158. mlx4_warn(dev, "Failed to generate event for slave %d\n",
  159. slave);
  160. }
  161. ++slave_eq->cons;
  162. }
  163. }
  164. static void slave_event(struct mlx4_dev *dev, u8 slave, struct mlx4_eqe *eqe)
  165. {
  166. struct mlx4_priv *priv = mlx4_priv(dev);
  167. struct mlx4_slave_event_eq *slave_eq = &priv->mfunc.master.slave_eq;
  168. struct mlx4_eqe *s_eqe;
  169. unsigned long flags;
  170. spin_lock_irqsave(&slave_eq->event_lock, flags);
  171. s_eqe = &slave_eq->event_eqe[slave_eq->prod & (SLAVE_EVENT_EQ_SIZE - 1)];
  172. if ((!!(s_eqe->owner & 0x80)) ^
  173. (!!(slave_eq->prod & SLAVE_EVENT_EQ_SIZE))) {
  174. mlx4_warn(dev, "Master failed to generate an EQE for slave: %d. No free EQE on slave events queue\n",
  175. slave);
  176. spin_unlock_irqrestore(&slave_eq->event_lock, flags);
  177. return;
  178. }
  179. memcpy(s_eqe, eqe, sizeof(struct mlx4_eqe) - 1);
  180. s_eqe->slave_id = slave;
  181. /* ensure all information is written before setting the ownersip bit */
  182. dma_wmb();
  183. s_eqe->owner = !!(slave_eq->prod & SLAVE_EVENT_EQ_SIZE) ? 0x0 : 0x80;
  184. ++slave_eq->prod;
  185. queue_work(priv->mfunc.master.comm_wq,
  186. &priv->mfunc.master.slave_event_work);
  187. spin_unlock_irqrestore(&slave_eq->event_lock, flags);
  188. }
  189. static void mlx4_slave_event(struct mlx4_dev *dev, int slave,
  190. struct mlx4_eqe *eqe)
  191. {
  192. struct mlx4_priv *priv = mlx4_priv(dev);
  193. if (slave < 0 || slave > dev->persist->num_vfs ||
  194. slave == dev->caps.function ||
  195. !priv->mfunc.master.slave_state[slave].active)
  196. return;
  197. slave_event(dev, slave, eqe);
  198. }
  199. #if defined(CONFIG_SMP)
  200. static void mlx4_set_eq_affinity_hint(struct mlx4_priv *priv, int vec)
  201. {
  202. int hint_err;
  203. struct mlx4_dev *dev = &priv->dev;
  204. struct mlx4_eq *eq = &priv->eq_table.eq[vec];
  205. if (!cpumask_available(eq->affinity_mask) ||
  206. cpumask_empty(eq->affinity_mask))
  207. return;
  208. hint_err = irq_set_affinity_hint(eq->irq, eq->affinity_mask);
  209. if (hint_err)
  210. mlx4_warn(dev, "irq_set_affinity_hint failed, err %d\n", hint_err);
  211. }
  212. #endif
  213. int mlx4_gen_pkey_eqe(struct mlx4_dev *dev, int slave, u8 port)
  214. {
  215. struct mlx4_eqe eqe;
  216. struct mlx4_priv *priv = mlx4_priv(dev);
  217. struct mlx4_slave_state *s_slave = &priv->mfunc.master.slave_state[slave];
  218. if (!s_slave->active)
  219. return 0;
  220. memset(&eqe, 0, sizeof eqe);
  221. eqe.type = MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT;
  222. eqe.subtype = MLX4_DEV_PMC_SUBTYPE_PKEY_TABLE;
  223. eqe.event.port_mgmt_change.port = mlx4_phys_to_slave_port(dev, slave, port);
  224. return mlx4_GEN_EQE(dev, slave, &eqe);
  225. }
  226. EXPORT_SYMBOL(mlx4_gen_pkey_eqe);
  227. int mlx4_gen_guid_change_eqe(struct mlx4_dev *dev, int slave, u8 port)
  228. {
  229. struct mlx4_eqe eqe;
  230. /*don't send if we don't have the that slave */
  231. if (dev->persist->num_vfs < slave)
  232. return 0;
  233. memset(&eqe, 0, sizeof eqe);
  234. eqe.type = MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT;
  235. eqe.subtype = MLX4_DEV_PMC_SUBTYPE_GUID_INFO;
  236. eqe.event.port_mgmt_change.port = mlx4_phys_to_slave_port(dev, slave, port);
  237. return mlx4_GEN_EQE(dev, slave, &eqe);
  238. }
  239. EXPORT_SYMBOL(mlx4_gen_guid_change_eqe);
  240. int mlx4_gen_port_state_change_eqe(struct mlx4_dev *dev, int slave, u8 port,
  241. u8 port_subtype_change)
  242. {
  243. struct mlx4_eqe eqe;
  244. u8 slave_port = mlx4_phys_to_slave_port(dev, slave, port);
  245. /*don't send if we don't have the that slave */
  246. if (dev->persist->num_vfs < slave)
  247. return 0;
  248. memset(&eqe, 0, sizeof eqe);
  249. eqe.type = MLX4_EVENT_TYPE_PORT_CHANGE;
  250. eqe.subtype = port_subtype_change;
  251. eqe.event.port_change.port = cpu_to_be32(slave_port << 28);
  252. mlx4_dbg(dev, "%s: sending: %d to slave: %d on port: %d\n", __func__,
  253. port_subtype_change, slave, port);
  254. return mlx4_GEN_EQE(dev, slave, &eqe);
  255. }
  256. EXPORT_SYMBOL(mlx4_gen_port_state_change_eqe);
  257. enum slave_port_state mlx4_get_slave_port_state(struct mlx4_dev *dev, int slave, u8 port)
  258. {
  259. struct mlx4_priv *priv = mlx4_priv(dev);
  260. struct mlx4_slave_state *s_state = priv->mfunc.master.slave_state;
  261. struct mlx4_active_ports actv_ports = mlx4_get_active_ports(dev, slave);
  262. if (slave >= dev->num_slaves || port > dev->caps.num_ports ||
  263. port <= 0 || !test_bit(port - 1, actv_ports.ports)) {
  264. pr_err("%s: Error: asking for slave:%d, port:%d\n",
  265. __func__, slave, port);
  266. return SLAVE_PORT_DOWN;
  267. }
  268. return s_state[slave].port_state[port];
  269. }
  270. EXPORT_SYMBOL(mlx4_get_slave_port_state);
  271. static int mlx4_set_slave_port_state(struct mlx4_dev *dev, int slave, u8 port,
  272. enum slave_port_state state)
  273. {
  274. struct mlx4_priv *priv = mlx4_priv(dev);
  275. struct mlx4_slave_state *s_state = priv->mfunc.master.slave_state;
  276. struct mlx4_active_ports actv_ports = mlx4_get_active_ports(dev, slave);
  277. if (slave >= dev->num_slaves || port > dev->caps.num_ports ||
  278. port <= 0 || !test_bit(port - 1, actv_ports.ports)) {
  279. pr_err("%s: Error: asking for slave:%d, port:%d\n",
  280. __func__, slave, port);
  281. return -1;
  282. }
  283. s_state[slave].port_state[port] = state;
  284. return 0;
  285. }
  286. static void set_all_slave_state(struct mlx4_dev *dev, u8 port, int event)
  287. {
  288. int i;
  289. enum slave_port_gen_event gen_event;
  290. struct mlx4_slaves_pport slaves_pport = mlx4_phys_to_slaves_pport(dev,
  291. port);
  292. for (i = 0; i < dev->persist->num_vfs + 1; i++)
  293. if (test_bit(i, slaves_pport.slaves))
  294. set_and_calc_slave_port_state(dev, i, port,
  295. event, &gen_event);
  296. }
  297. /**************************************************************************
  298. The function get as input the new event to that port,
  299. and according to the prev state change the slave's port state.
  300. The events are:
  301. MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN,
  302. MLX4_PORT_STATE_DEV_EVENT_PORT_UP
  303. MLX4_PORT_STATE_IB_EVENT_GID_VALID
  304. MLX4_PORT_STATE_IB_EVENT_GID_INVALID
  305. ***************************************************************************/
  306. int set_and_calc_slave_port_state(struct mlx4_dev *dev, int slave,
  307. u8 port, int event,
  308. enum slave_port_gen_event *gen_event)
  309. {
  310. struct mlx4_priv *priv = mlx4_priv(dev);
  311. struct mlx4_slave_state *ctx = NULL;
  312. unsigned long flags;
  313. int ret = -1;
  314. struct mlx4_active_ports actv_ports = mlx4_get_active_ports(dev, slave);
  315. enum slave_port_state cur_state =
  316. mlx4_get_slave_port_state(dev, slave, port);
  317. *gen_event = SLAVE_PORT_GEN_EVENT_NONE;
  318. if (slave >= dev->num_slaves || port > dev->caps.num_ports ||
  319. port <= 0 || !test_bit(port - 1, actv_ports.ports)) {
  320. pr_err("%s: Error: asking for slave:%d, port:%d\n",
  321. __func__, slave, port);
  322. return ret;
  323. }
  324. ctx = &priv->mfunc.master.slave_state[slave];
  325. spin_lock_irqsave(&ctx->lock, flags);
  326. switch (cur_state) {
  327. case SLAVE_PORT_DOWN:
  328. if (MLX4_PORT_STATE_DEV_EVENT_PORT_UP == event)
  329. mlx4_set_slave_port_state(dev, slave, port,
  330. SLAVE_PENDING_UP);
  331. break;
  332. case SLAVE_PENDING_UP:
  333. if (MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN == event)
  334. mlx4_set_slave_port_state(dev, slave, port,
  335. SLAVE_PORT_DOWN);
  336. else if (MLX4_PORT_STATE_IB_PORT_STATE_EVENT_GID_VALID == event) {
  337. mlx4_set_slave_port_state(dev, slave, port,
  338. SLAVE_PORT_UP);
  339. *gen_event = SLAVE_PORT_GEN_EVENT_UP;
  340. }
  341. break;
  342. case SLAVE_PORT_UP:
  343. if (MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN == event) {
  344. mlx4_set_slave_port_state(dev, slave, port,
  345. SLAVE_PORT_DOWN);
  346. *gen_event = SLAVE_PORT_GEN_EVENT_DOWN;
  347. } else if (MLX4_PORT_STATE_IB_EVENT_GID_INVALID ==
  348. event) {
  349. mlx4_set_slave_port_state(dev, slave, port,
  350. SLAVE_PENDING_UP);
  351. *gen_event = SLAVE_PORT_GEN_EVENT_DOWN;
  352. }
  353. break;
  354. default:
  355. pr_err("%s: BUG!!! UNKNOWN state: slave:%d, port:%d\n",
  356. __func__, slave, port);
  357. goto out;
  358. }
  359. ret = mlx4_get_slave_port_state(dev, slave, port);
  360. out:
  361. spin_unlock_irqrestore(&ctx->lock, flags);
  362. return ret;
  363. }
  364. EXPORT_SYMBOL(set_and_calc_slave_port_state);
  365. int mlx4_gen_slaves_port_mgt_ev(struct mlx4_dev *dev, u8 port, int attr)
  366. {
  367. struct mlx4_eqe eqe;
  368. memset(&eqe, 0, sizeof eqe);
  369. eqe.type = MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT;
  370. eqe.subtype = MLX4_DEV_PMC_SUBTYPE_PORT_INFO;
  371. eqe.event.port_mgmt_change.port = port;
  372. eqe.event.port_mgmt_change.params.port_info.changed_attr =
  373. cpu_to_be32((u32) attr);
  374. slave_event(dev, ALL_SLAVES, &eqe);
  375. return 0;
  376. }
  377. EXPORT_SYMBOL(mlx4_gen_slaves_port_mgt_ev);
  378. void mlx4_master_handle_slave_flr(struct work_struct *work)
  379. {
  380. struct mlx4_mfunc_master_ctx *master =
  381. container_of(work, struct mlx4_mfunc_master_ctx,
  382. slave_flr_event_work);
  383. struct mlx4_mfunc *mfunc =
  384. container_of(master, struct mlx4_mfunc, master);
  385. struct mlx4_priv *priv =
  386. container_of(mfunc, struct mlx4_priv, mfunc);
  387. struct mlx4_dev *dev = &priv->dev;
  388. struct mlx4_slave_state *slave_state = priv->mfunc.master.slave_state;
  389. int i;
  390. int err;
  391. unsigned long flags;
  392. mlx4_dbg(dev, "mlx4_handle_slave_flr\n");
  393. for (i = 0 ; i < dev->num_slaves; i++) {
  394. if (MLX4_COMM_CMD_FLR == slave_state[i].last_cmd) {
  395. mlx4_dbg(dev, "mlx4_handle_slave_flr: clean slave: %d\n",
  396. i);
  397. /* In case of 'Reset flow' FLR can be generated for
  398. * a slave before mlx4_load_one is done.
  399. * make sure interface is up before trying to delete
  400. * slave resources which weren't allocated yet.
  401. */
  402. if (dev->persist->interface_state &
  403. MLX4_INTERFACE_STATE_UP)
  404. mlx4_delete_all_resources_for_slave(dev, i);
  405. /*return the slave to running mode*/
  406. spin_lock_irqsave(&priv->mfunc.master.slave_state_lock, flags);
  407. slave_state[i].last_cmd = MLX4_COMM_CMD_RESET;
  408. slave_state[i].is_slave_going_down = 0;
  409. spin_unlock_irqrestore(&priv->mfunc.master.slave_state_lock, flags);
  410. /*notify the FW:*/
  411. err = mlx4_cmd(dev, 0, i, 0, MLX4_CMD_INFORM_FLR_DONE,
  412. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  413. if (err)
  414. mlx4_warn(dev, "Failed to notify FW on FLR done (slave:%d)\n",
  415. i);
  416. }
  417. }
  418. }
  419. static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
  420. {
  421. struct mlx4_priv *priv = mlx4_priv(dev);
  422. struct mlx4_eqe *eqe;
  423. int cqn = -1;
  424. int eqes_found = 0;
  425. int set_ci = 0;
  426. int port;
  427. int slave = 0;
  428. int ret;
  429. u32 flr_slave;
  430. u8 update_slave_state;
  431. int i;
  432. enum slave_port_gen_event gen_event;
  433. unsigned long flags;
  434. struct mlx4_vport_state *s_info;
  435. int eqe_size = dev->caps.eqe_size;
  436. while ((eqe = next_eqe_sw(eq, dev->caps.eqe_factor, eqe_size))) {
  437. /*
  438. * Make sure we read EQ entry contents after we've
  439. * checked the ownership bit.
  440. */
  441. dma_rmb();
  442. switch (eqe->type) {
  443. case MLX4_EVENT_TYPE_COMP:
  444. cqn = be32_to_cpu(eqe->event.comp.cqn) & 0xffffff;
  445. mlx4_cq_completion(dev, cqn);
  446. break;
  447. case MLX4_EVENT_TYPE_PATH_MIG:
  448. case MLX4_EVENT_TYPE_COMM_EST:
  449. case MLX4_EVENT_TYPE_SQ_DRAINED:
  450. case MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE:
  451. case MLX4_EVENT_TYPE_WQ_CATAS_ERROR:
  452. case MLX4_EVENT_TYPE_PATH_MIG_FAILED:
  453. case MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
  454. case MLX4_EVENT_TYPE_WQ_ACCESS_ERROR:
  455. mlx4_dbg(dev, "event %d arrived\n", eqe->type);
  456. if (mlx4_is_master(dev)) {
  457. /* forward only to slave owning the QP */
  458. ret = mlx4_get_slave_from_resource_id(dev,
  459. RES_QP,
  460. be32_to_cpu(eqe->event.qp.qpn)
  461. & 0xffffff, &slave);
  462. if (ret && ret != -ENOENT) {
  463. mlx4_dbg(dev, "QP event %02x(%02x) on EQ %d at index %u: could not get slave id (%d)\n",
  464. eqe->type, eqe->subtype,
  465. eq->eqn, eq->cons_index, ret);
  466. break;
  467. }
  468. if (!ret && slave != dev->caps.function) {
  469. mlx4_slave_event(dev, slave, eqe);
  470. break;
  471. }
  472. }
  473. mlx4_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) &
  474. 0xffffff, eqe->type);
  475. break;
  476. case MLX4_EVENT_TYPE_SRQ_LIMIT:
  477. mlx4_dbg(dev, "%s: MLX4_EVENT_TYPE_SRQ_LIMIT. srq_no=0x%x, eq 0x%x\n",
  478. __func__, be32_to_cpu(eqe->event.srq.srqn),
  479. eq->eqn);
  480. case MLX4_EVENT_TYPE_SRQ_CATAS_ERROR:
  481. if (mlx4_is_master(dev)) {
  482. /* forward only to slave owning the SRQ */
  483. ret = mlx4_get_slave_from_resource_id(dev,
  484. RES_SRQ,
  485. be32_to_cpu(eqe->event.srq.srqn)
  486. & 0xffffff,
  487. &slave);
  488. if (ret && ret != -ENOENT) {
  489. mlx4_warn(dev, "SRQ event %02x(%02x) on EQ %d at index %u: could not get slave id (%d)\n",
  490. eqe->type, eqe->subtype,
  491. eq->eqn, eq->cons_index, ret);
  492. break;
  493. }
  494. if (eqe->type ==
  495. MLX4_EVENT_TYPE_SRQ_CATAS_ERROR)
  496. mlx4_warn(dev, "%s: slave:%d, srq_no:0x%x, event: %02x(%02x)\n",
  497. __func__, slave,
  498. be32_to_cpu(eqe->event.srq.srqn),
  499. eqe->type, eqe->subtype);
  500. if (!ret && slave != dev->caps.function) {
  501. if (eqe->type ==
  502. MLX4_EVENT_TYPE_SRQ_CATAS_ERROR)
  503. mlx4_warn(dev, "%s: sending event %02x(%02x) to slave:%d\n",
  504. __func__, eqe->type,
  505. eqe->subtype, slave);
  506. mlx4_slave_event(dev, slave, eqe);
  507. break;
  508. }
  509. }
  510. mlx4_srq_event(dev, be32_to_cpu(eqe->event.srq.srqn) &
  511. 0xffffff, eqe->type);
  512. break;
  513. case MLX4_EVENT_TYPE_CMD:
  514. mlx4_cmd_event(dev,
  515. be16_to_cpu(eqe->event.cmd.token),
  516. eqe->event.cmd.status,
  517. be64_to_cpu(eqe->event.cmd.out_param));
  518. break;
  519. case MLX4_EVENT_TYPE_PORT_CHANGE: {
  520. struct mlx4_slaves_pport slaves_port;
  521. port = be32_to_cpu(eqe->event.port_change.port) >> 28;
  522. slaves_port = mlx4_phys_to_slaves_pport(dev, port);
  523. if (eqe->subtype == MLX4_PORT_CHANGE_SUBTYPE_DOWN) {
  524. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_DOWN,
  525. port);
  526. mlx4_priv(dev)->sense.do_sense_port[port] = 1;
  527. if (!mlx4_is_master(dev))
  528. break;
  529. for (i = 0; i < dev->persist->num_vfs + 1;
  530. i++) {
  531. if (!test_bit(i, slaves_port.slaves))
  532. continue;
  533. if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) {
  534. if (i == mlx4_master_func_num(dev))
  535. continue;
  536. mlx4_dbg(dev, "%s: Sending MLX4_PORT_CHANGE_SUBTYPE_DOWN to slave: %d, port:%d\n",
  537. __func__, i, port);
  538. s_info = &priv->mfunc.master.vf_oper[i].vport[port].state;
  539. if (IFLA_VF_LINK_STATE_AUTO == s_info->link_state) {
  540. eqe->event.port_change.port =
  541. cpu_to_be32(
  542. (be32_to_cpu(eqe->event.port_change.port) & 0xFFFFFFF)
  543. | (mlx4_phys_to_slave_port(dev, i, port) << 28));
  544. mlx4_slave_event(dev, i, eqe);
  545. }
  546. } else { /* IB port */
  547. set_and_calc_slave_port_state(dev, i, port,
  548. MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN,
  549. &gen_event);
  550. /*we can be in pending state, then do not send port_down event*/
  551. if (SLAVE_PORT_GEN_EVENT_DOWN == gen_event) {
  552. if (i == mlx4_master_func_num(dev))
  553. continue;
  554. eqe->event.port_change.port =
  555. cpu_to_be32(
  556. (be32_to_cpu(eqe->event.port_change.port) & 0xFFFFFFF)
  557. | (mlx4_phys_to_slave_port(dev, i, port) << 28));
  558. mlx4_slave_event(dev, i, eqe);
  559. }
  560. }
  561. }
  562. } else {
  563. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_UP, port);
  564. mlx4_priv(dev)->sense.do_sense_port[port] = 0;
  565. if (!mlx4_is_master(dev))
  566. break;
  567. if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH)
  568. for (i = 0;
  569. i < dev->persist->num_vfs + 1;
  570. i++) {
  571. if (!test_bit(i, slaves_port.slaves))
  572. continue;
  573. if (i == mlx4_master_func_num(dev))
  574. continue;
  575. s_info = &priv->mfunc.master.vf_oper[i].vport[port].state;
  576. if (IFLA_VF_LINK_STATE_AUTO == s_info->link_state) {
  577. eqe->event.port_change.port =
  578. cpu_to_be32(
  579. (be32_to_cpu(eqe->event.port_change.port) & 0xFFFFFFF)
  580. | (mlx4_phys_to_slave_port(dev, i, port) << 28));
  581. mlx4_slave_event(dev, i, eqe);
  582. }
  583. }
  584. else /* IB port */
  585. /* port-up event will be sent to a slave when the
  586. * slave's alias-guid is set. This is done in alias_GUID.c
  587. */
  588. set_all_slave_state(dev, port, MLX4_DEV_EVENT_PORT_UP);
  589. }
  590. break;
  591. }
  592. case MLX4_EVENT_TYPE_CQ_ERROR:
  593. mlx4_warn(dev, "CQ %s on CQN %06x\n",
  594. eqe->event.cq_err.syndrome == 1 ?
  595. "overrun" : "access violation",
  596. be32_to_cpu(eqe->event.cq_err.cqn) & 0xffffff);
  597. if (mlx4_is_master(dev)) {
  598. ret = mlx4_get_slave_from_resource_id(dev,
  599. RES_CQ,
  600. be32_to_cpu(eqe->event.cq_err.cqn)
  601. & 0xffffff, &slave);
  602. if (ret && ret != -ENOENT) {
  603. mlx4_dbg(dev, "CQ event %02x(%02x) on EQ %d at index %u: could not get slave id (%d)\n",
  604. eqe->type, eqe->subtype,
  605. eq->eqn, eq->cons_index, ret);
  606. break;
  607. }
  608. if (!ret && slave != dev->caps.function) {
  609. mlx4_slave_event(dev, slave, eqe);
  610. break;
  611. }
  612. }
  613. mlx4_cq_event(dev,
  614. be32_to_cpu(eqe->event.cq_err.cqn)
  615. & 0xffffff,
  616. eqe->type);
  617. break;
  618. case MLX4_EVENT_TYPE_EQ_OVERFLOW:
  619. mlx4_warn(dev, "EQ overrun on EQN %d\n", eq->eqn);
  620. break;
  621. case MLX4_EVENT_TYPE_OP_REQUIRED:
  622. atomic_inc(&priv->opreq_count);
  623. /* FW commands can't be executed from interrupt context
  624. * working in deferred task
  625. */
  626. queue_work(mlx4_wq, &priv->opreq_task);
  627. break;
  628. case MLX4_EVENT_TYPE_COMM_CHANNEL:
  629. if (!mlx4_is_master(dev)) {
  630. mlx4_warn(dev, "Received comm channel event for non master device\n");
  631. break;
  632. }
  633. memcpy(&priv->mfunc.master.comm_arm_bit_vector,
  634. eqe->event.comm_channel_arm.bit_vec,
  635. sizeof eqe->event.comm_channel_arm.bit_vec);
  636. queue_work(priv->mfunc.master.comm_wq,
  637. &priv->mfunc.master.comm_work);
  638. break;
  639. case MLX4_EVENT_TYPE_FLR_EVENT:
  640. flr_slave = be32_to_cpu(eqe->event.flr_event.slave_id);
  641. if (!mlx4_is_master(dev)) {
  642. mlx4_warn(dev, "Non-master function received FLR event\n");
  643. break;
  644. }
  645. mlx4_dbg(dev, "FLR event for slave: %d\n", flr_slave);
  646. if (flr_slave >= dev->num_slaves) {
  647. mlx4_warn(dev,
  648. "Got FLR for unknown function: %d\n",
  649. flr_slave);
  650. update_slave_state = 0;
  651. } else
  652. update_slave_state = 1;
  653. spin_lock_irqsave(&priv->mfunc.master.slave_state_lock, flags);
  654. if (update_slave_state) {
  655. priv->mfunc.master.slave_state[flr_slave].active = false;
  656. priv->mfunc.master.slave_state[flr_slave].last_cmd = MLX4_COMM_CMD_FLR;
  657. priv->mfunc.master.slave_state[flr_slave].is_slave_going_down = 1;
  658. }
  659. spin_unlock_irqrestore(&priv->mfunc.master.slave_state_lock, flags);
  660. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_SLAVE_SHUTDOWN,
  661. flr_slave);
  662. queue_work(priv->mfunc.master.comm_wq,
  663. &priv->mfunc.master.slave_flr_event_work);
  664. break;
  665. case MLX4_EVENT_TYPE_FATAL_WARNING:
  666. if (eqe->subtype == MLX4_FATAL_WARNING_SUBTYPE_WARMING) {
  667. if (mlx4_is_master(dev))
  668. for (i = 0; i < dev->num_slaves; i++) {
  669. mlx4_dbg(dev, "%s: Sending MLX4_FATAL_WARNING_SUBTYPE_WARMING to slave: %d\n",
  670. __func__, i);
  671. if (i == dev->caps.function)
  672. continue;
  673. mlx4_slave_event(dev, i, eqe);
  674. }
  675. mlx4_err(dev, "Temperature Threshold was reached! Threshold: %d celsius degrees; Current Temperature: %d\n",
  676. be16_to_cpu(eqe->event.warming.warning_threshold),
  677. be16_to_cpu(eqe->event.warming.current_temperature));
  678. } else
  679. 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",
  680. eqe->type, eqe->subtype, eq->eqn,
  681. eq->cons_index, eqe->owner, eq->nent,
  682. eqe->slave_id,
  683. !!(eqe->owner & 0x80) ^
  684. !!(eq->cons_index & eq->nent) ? "HW" : "SW");
  685. break;
  686. case MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT:
  687. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_MGMT_CHANGE,
  688. (unsigned long) eqe);
  689. break;
  690. case MLX4_EVENT_TYPE_RECOVERABLE_ERROR_EVENT:
  691. switch (eqe->subtype) {
  692. case MLX4_RECOVERABLE_ERROR_EVENT_SUBTYPE_BAD_CABLE:
  693. mlx4_warn(dev, "Bad cable detected on port %u\n",
  694. eqe->event.bad_cable.port);
  695. break;
  696. case MLX4_RECOVERABLE_ERROR_EVENT_SUBTYPE_UNSUPPORTED_CABLE:
  697. mlx4_warn(dev, "Unsupported cable detected\n");
  698. break;
  699. default:
  700. mlx4_dbg(dev,
  701. "Unhandled recoverable error event detected: %02x(%02x) on EQ %d at index %u. owner=%x, nent=0x%x, ownership=%s\n",
  702. eqe->type, eqe->subtype, eq->eqn,
  703. eq->cons_index, eqe->owner, eq->nent,
  704. !!(eqe->owner & 0x80) ^
  705. !!(eq->cons_index & eq->nent) ? "HW" : "SW");
  706. break;
  707. }
  708. break;
  709. case MLX4_EVENT_TYPE_EEC_CATAS_ERROR:
  710. case MLX4_EVENT_TYPE_ECC_DETECT:
  711. default:
  712. mlx4_warn(dev, "Unhandled event %02x(%02x) on EQ %d at index %u. owner=%x, nent=0x%x, slave=%x, ownership=%s\n",
  713. eqe->type, eqe->subtype, eq->eqn,
  714. eq->cons_index, eqe->owner, eq->nent,
  715. eqe->slave_id,
  716. !!(eqe->owner & 0x80) ^
  717. !!(eq->cons_index & eq->nent) ? "HW" : "SW");
  718. break;
  719. };
  720. ++eq->cons_index;
  721. eqes_found = 1;
  722. ++set_ci;
  723. /*
  724. * The HCA will think the queue has overflowed if we
  725. * don't tell it we've been processing events. We
  726. * create our EQs with MLX4_NUM_SPARE_EQE extra
  727. * entries, so we must update our consumer index at
  728. * least that often.
  729. */
  730. if (unlikely(set_ci >= MLX4_NUM_SPARE_EQE)) {
  731. eq_set_ci(eq, 0);
  732. set_ci = 0;
  733. }
  734. }
  735. eq_set_ci(eq, 1);
  736. /* cqn is 24bit wide but is initialized such that its higher bits
  737. * are ones too. Thus, if we got any event, cqn's high bits should be off
  738. * and we need to schedule the tasklet.
  739. */
  740. if (!(cqn & ~0xffffff))
  741. tasklet_schedule(&eq->tasklet_ctx.task);
  742. return eqes_found;
  743. }
  744. static irqreturn_t mlx4_interrupt(int irq, void *dev_ptr)
  745. {
  746. struct mlx4_dev *dev = dev_ptr;
  747. struct mlx4_priv *priv = mlx4_priv(dev);
  748. int work = 0;
  749. int i;
  750. writel(priv->eq_table.clr_mask, priv->eq_table.clr_int);
  751. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  752. work |= mlx4_eq_int(dev, &priv->eq_table.eq[i]);
  753. return IRQ_RETVAL(work);
  754. }
  755. static irqreturn_t mlx4_msi_x_interrupt(int irq, void *eq_ptr)
  756. {
  757. struct mlx4_eq *eq = eq_ptr;
  758. struct mlx4_dev *dev = eq->dev;
  759. mlx4_eq_int(dev, eq);
  760. /* MSI-X vectors always belong to us */
  761. return IRQ_HANDLED;
  762. }
  763. int mlx4_MAP_EQ_wrapper(struct mlx4_dev *dev, int slave,
  764. struct mlx4_vhcr *vhcr,
  765. struct mlx4_cmd_mailbox *inbox,
  766. struct mlx4_cmd_mailbox *outbox,
  767. struct mlx4_cmd_info *cmd)
  768. {
  769. struct mlx4_priv *priv = mlx4_priv(dev);
  770. struct mlx4_slave_event_eq_info *event_eq =
  771. priv->mfunc.master.slave_state[slave].event_eq;
  772. u32 in_modifier = vhcr->in_modifier;
  773. u32 eqn = in_modifier & 0x3FF;
  774. u64 in_param = vhcr->in_param;
  775. int err = 0;
  776. int i;
  777. if (slave == dev->caps.function)
  778. err = mlx4_cmd(dev, in_param, (in_modifier & 0x80000000) | eqn,
  779. 0, MLX4_CMD_MAP_EQ, MLX4_CMD_TIME_CLASS_B,
  780. MLX4_CMD_NATIVE);
  781. if (!err)
  782. for (i = 0; i < MLX4_EVENT_TYPES_NUM; ++i)
  783. if (in_param & (1LL << i))
  784. event_eq[i].eqn = in_modifier >> 31 ? -1 : eqn;
  785. return err;
  786. }
  787. static int mlx4_MAP_EQ(struct mlx4_dev *dev, u64 event_mask, int unmap,
  788. int eq_num)
  789. {
  790. return mlx4_cmd(dev, event_mask, (unmap << 31) | eq_num,
  791. 0, MLX4_CMD_MAP_EQ, MLX4_CMD_TIME_CLASS_B,
  792. MLX4_CMD_WRAPPED);
  793. }
  794. static int mlx4_SW2HW_EQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
  795. int eq_num)
  796. {
  797. return mlx4_cmd(dev, mailbox->dma, eq_num, 0,
  798. MLX4_CMD_SW2HW_EQ, MLX4_CMD_TIME_CLASS_A,
  799. MLX4_CMD_WRAPPED);
  800. }
  801. static int mlx4_HW2SW_EQ(struct mlx4_dev *dev, int eq_num)
  802. {
  803. return mlx4_cmd(dev, 0, eq_num, 1, MLX4_CMD_HW2SW_EQ,
  804. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  805. }
  806. static int mlx4_num_eq_uar(struct mlx4_dev *dev)
  807. {
  808. /*
  809. * Each UAR holds 4 EQ doorbells. To figure out how many UARs
  810. * we need to map, take the difference of highest index and
  811. * the lowest index we'll use and add 1.
  812. */
  813. return (dev->caps.num_comp_vectors + 1 + dev->caps.reserved_eqs) / 4 -
  814. dev->caps.reserved_eqs / 4 + 1;
  815. }
  816. static void __iomem *mlx4_get_eq_uar(struct mlx4_dev *dev, struct mlx4_eq *eq)
  817. {
  818. struct mlx4_priv *priv = mlx4_priv(dev);
  819. int index;
  820. index = eq->eqn / 4 - dev->caps.reserved_eqs / 4;
  821. if (!priv->eq_table.uar_map[index]) {
  822. priv->eq_table.uar_map[index] =
  823. ioremap(pci_resource_start(dev->persist->pdev, 2) +
  824. ((eq->eqn / 4) << PAGE_SHIFT),
  825. PAGE_SIZE);
  826. if (!priv->eq_table.uar_map[index]) {
  827. mlx4_err(dev, "Couldn't map EQ doorbell for EQN 0x%06x\n",
  828. eq->eqn);
  829. return NULL;
  830. }
  831. }
  832. return priv->eq_table.uar_map[index] + 0x800 + 8 * (eq->eqn % 4);
  833. }
  834. static void mlx4_unmap_uar(struct mlx4_dev *dev)
  835. {
  836. struct mlx4_priv *priv = mlx4_priv(dev);
  837. int i;
  838. for (i = 0; i < mlx4_num_eq_uar(dev); ++i)
  839. if (priv->eq_table.uar_map[i]) {
  840. iounmap(priv->eq_table.uar_map[i]);
  841. priv->eq_table.uar_map[i] = NULL;
  842. }
  843. }
  844. static int mlx4_create_eq(struct mlx4_dev *dev, int nent,
  845. u8 intr, struct mlx4_eq *eq)
  846. {
  847. struct mlx4_priv *priv = mlx4_priv(dev);
  848. struct mlx4_cmd_mailbox *mailbox;
  849. struct mlx4_eq_context *eq_context;
  850. int npages;
  851. u64 *dma_list = NULL;
  852. dma_addr_t t;
  853. u64 mtt_addr;
  854. int err = -ENOMEM;
  855. int i;
  856. eq->dev = dev;
  857. eq->nent = roundup_pow_of_two(max(nent, 2));
  858. /* CX3 is capable of extending the CQE/EQE from 32 to 64 bytes, with
  859. * strides of 64B,128B and 256B.
  860. */
  861. npages = PAGE_ALIGN(eq->nent * dev->caps.eqe_size) / PAGE_SIZE;
  862. eq->page_list = kmalloc(npages * sizeof *eq->page_list,
  863. GFP_KERNEL);
  864. if (!eq->page_list)
  865. goto err_out;
  866. for (i = 0; i < npages; ++i)
  867. eq->page_list[i].buf = NULL;
  868. dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
  869. if (!dma_list)
  870. goto err_out_free;
  871. mailbox = mlx4_alloc_cmd_mailbox(dev);
  872. if (IS_ERR(mailbox))
  873. goto err_out_free;
  874. eq_context = mailbox->buf;
  875. for (i = 0; i < npages; ++i) {
  876. eq->page_list[i].buf = dma_alloc_coherent(&dev->persist->
  877. pdev->dev,
  878. PAGE_SIZE, &t,
  879. GFP_KERNEL);
  880. if (!eq->page_list[i].buf)
  881. goto err_out_free_pages;
  882. dma_list[i] = t;
  883. eq->page_list[i].map = t;
  884. memset(eq->page_list[i].buf, 0, PAGE_SIZE);
  885. }
  886. eq->eqn = mlx4_bitmap_alloc(&priv->eq_table.bitmap);
  887. if (eq->eqn == -1)
  888. goto err_out_free_pages;
  889. eq->doorbell = mlx4_get_eq_uar(dev, eq);
  890. if (!eq->doorbell) {
  891. err = -ENOMEM;
  892. goto err_out_free_eq;
  893. }
  894. err = mlx4_mtt_init(dev, npages, PAGE_SHIFT, &eq->mtt);
  895. if (err)
  896. goto err_out_free_eq;
  897. err = mlx4_write_mtt(dev, &eq->mtt, 0, npages, dma_list);
  898. if (err)
  899. goto err_out_free_mtt;
  900. eq_context->flags = cpu_to_be32(MLX4_EQ_STATUS_OK |
  901. MLX4_EQ_STATE_ARMED);
  902. eq_context->log_eq_size = ilog2(eq->nent);
  903. eq_context->intr = intr;
  904. eq_context->log_page_size = PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT;
  905. mtt_addr = mlx4_mtt_addr(dev, &eq->mtt);
  906. eq_context->mtt_base_addr_h = mtt_addr >> 32;
  907. eq_context->mtt_base_addr_l = cpu_to_be32(mtt_addr & 0xffffffff);
  908. err = mlx4_SW2HW_EQ(dev, mailbox, eq->eqn);
  909. if (err) {
  910. mlx4_warn(dev, "SW2HW_EQ failed (%d)\n", err);
  911. goto err_out_free_mtt;
  912. }
  913. kfree(dma_list);
  914. mlx4_free_cmd_mailbox(dev, mailbox);
  915. eq->cons_index = 0;
  916. INIT_LIST_HEAD(&eq->tasklet_ctx.list);
  917. INIT_LIST_HEAD(&eq->tasklet_ctx.process_list);
  918. spin_lock_init(&eq->tasklet_ctx.lock);
  919. tasklet_init(&eq->tasklet_ctx.task, mlx4_cq_tasklet_cb,
  920. (unsigned long)&eq->tasklet_ctx);
  921. return err;
  922. err_out_free_mtt:
  923. mlx4_mtt_cleanup(dev, &eq->mtt);
  924. err_out_free_eq:
  925. mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn, MLX4_USE_RR);
  926. err_out_free_pages:
  927. for (i = 0; i < npages; ++i)
  928. if (eq->page_list[i].buf)
  929. dma_free_coherent(&dev->persist->pdev->dev, PAGE_SIZE,
  930. eq->page_list[i].buf,
  931. eq->page_list[i].map);
  932. mlx4_free_cmd_mailbox(dev, mailbox);
  933. err_out_free:
  934. kfree(eq->page_list);
  935. kfree(dma_list);
  936. err_out:
  937. return err;
  938. }
  939. static void mlx4_free_eq(struct mlx4_dev *dev,
  940. struct mlx4_eq *eq)
  941. {
  942. struct mlx4_priv *priv = mlx4_priv(dev);
  943. int err;
  944. int i;
  945. /* CX3 is capable of extending the CQE/EQE from 32 to 64 bytes, with
  946. * strides of 64B,128B and 256B
  947. */
  948. int npages = PAGE_ALIGN(dev->caps.eqe_size * eq->nent) / PAGE_SIZE;
  949. err = mlx4_HW2SW_EQ(dev, eq->eqn);
  950. if (err)
  951. mlx4_warn(dev, "HW2SW_EQ failed (%d)\n", err);
  952. synchronize_irq(eq->irq);
  953. tasklet_disable(&eq->tasklet_ctx.task);
  954. mlx4_mtt_cleanup(dev, &eq->mtt);
  955. for (i = 0; i < npages; ++i)
  956. dma_free_coherent(&dev->persist->pdev->dev, PAGE_SIZE,
  957. eq->page_list[i].buf,
  958. eq->page_list[i].map);
  959. kfree(eq->page_list);
  960. mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn, MLX4_USE_RR);
  961. }
  962. static void mlx4_free_irqs(struct mlx4_dev *dev)
  963. {
  964. struct mlx4_eq_table *eq_table = &mlx4_priv(dev)->eq_table;
  965. int i;
  966. if (eq_table->have_irq)
  967. free_irq(dev->persist->pdev->irq, dev);
  968. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  969. if (eq_table->eq[i].have_irq) {
  970. free_cpumask_var(eq_table->eq[i].affinity_mask);
  971. #if defined(CONFIG_SMP)
  972. irq_set_affinity_hint(eq_table->eq[i].irq, NULL);
  973. #endif
  974. free_irq(eq_table->eq[i].irq, eq_table->eq + i);
  975. eq_table->eq[i].have_irq = 0;
  976. }
  977. kfree(eq_table->irq_names);
  978. }
  979. static int mlx4_map_clr_int(struct mlx4_dev *dev)
  980. {
  981. struct mlx4_priv *priv = mlx4_priv(dev);
  982. priv->clr_base = ioremap(pci_resource_start(dev->persist->pdev,
  983. priv->fw.clr_int_bar) +
  984. priv->fw.clr_int_base, MLX4_CLR_INT_SIZE);
  985. if (!priv->clr_base) {
  986. mlx4_err(dev, "Couldn't map interrupt clear register, aborting\n");
  987. return -ENOMEM;
  988. }
  989. return 0;
  990. }
  991. static void mlx4_unmap_clr_int(struct mlx4_dev *dev)
  992. {
  993. struct mlx4_priv *priv = mlx4_priv(dev);
  994. iounmap(priv->clr_base);
  995. }
  996. int mlx4_alloc_eq_table(struct mlx4_dev *dev)
  997. {
  998. struct mlx4_priv *priv = mlx4_priv(dev);
  999. priv->eq_table.eq = kcalloc(dev->caps.num_eqs - dev->caps.reserved_eqs,
  1000. sizeof *priv->eq_table.eq, GFP_KERNEL);
  1001. if (!priv->eq_table.eq)
  1002. return -ENOMEM;
  1003. return 0;
  1004. }
  1005. void mlx4_free_eq_table(struct mlx4_dev *dev)
  1006. {
  1007. kfree(mlx4_priv(dev)->eq_table.eq);
  1008. }
  1009. int mlx4_init_eq_table(struct mlx4_dev *dev)
  1010. {
  1011. struct mlx4_priv *priv = mlx4_priv(dev);
  1012. int err;
  1013. int i;
  1014. priv->eq_table.uar_map = kcalloc(mlx4_num_eq_uar(dev),
  1015. sizeof *priv->eq_table.uar_map,
  1016. GFP_KERNEL);
  1017. if (!priv->eq_table.uar_map) {
  1018. err = -ENOMEM;
  1019. goto err_out_free;
  1020. }
  1021. err = mlx4_bitmap_init(&priv->eq_table.bitmap,
  1022. roundup_pow_of_two(dev->caps.num_eqs),
  1023. dev->caps.num_eqs - 1,
  1024. dev->caps.reserved_eqs,
  1025. roundup_pow_of_two(dev->caps.num_eqs) -
  1026. dev->caps.num_eqs);
  1027. if (err)
  1028. goto err_out_free;
  1029. for (i = 0; i < mlx4_num_eq_uar(dev); ++i)
  1030. priv->eq_table.uar_map[i] = NULL;
  1031. if (!mlx4_is_slave(dev)) {
  1032. err = mlx4_map_clr_int(dev);
  1033. if (err)
  1034. goto err_out_bitmap;
  1035. priv->eq_table.clr_mask =
  1036. swab32(1 << (priv->eq_table.inta_pin & 31));
  1037. priv->eq_table.clr_int = priv->clr_base +
  1038. (priv->eq_table.inta_pin < 32 ? 4 : 0);
  1039. }
  1040. priv->eq_table.irq_names =
  1041. kmalloc(MLX4_IRQNAME_SIZE * (dev->caps.num_comp_vectors + 1),
  1042. GFP_KERNEL);
  1043. if (!priv->eq_table.irq_names) {
  1044. err = -ENOMEM;
  1045. goto err_out_clr_int;
  1046. }
  1047. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i) {
  1048. if (i == MLX4_EQ_ASYNC) {
  1049. err = mlx4_create_eq(dev,
  1050. MLX4_NUM_ASYNC_EQE + MLX4_NUM_SPARE_EQE,
  1051. 0, &priv->eq_table.eq[MLX4_EQ_ASYNC]);
  1052. } else {
  1053. struct mlx4_eq *eq = &priv->eq_table.eq[i];
  1054. #ifdef CONFIG_RFS_ACCEL
  1055. int port = find_first_bit(eq->actv_ports.ports,
  1056. dev->caps.num_ports) + 1;
  1057. if (port <= dev->caps.num_ports) {
  1058. struct mlx4_port_info *info =
  1059. &mlx4_priv(dev)->port[port];
  1060. if (!info->rmap) {
  1061. info->rmap = alloc_irq_cpu_rmap(
  1062. mlx4_get_eqs_per_port(dev, port));
  1063. if (!info->rmap) {
  1064. mlx4_warn(dev, "Failed to allocate cpu rmap\n");
  1065. err = -ENOMEM;
  1066. goto err_out_unmap;
  1067. }
  1068. }
  1069. err = irq_cpu_rmap_add(
  1070. info->rmap, eq->irq);
  1071. if (err)
  1072. mlx4_warn(dev, "Failed adding irq rmap\n");
  1073. }
  1074. #endif
  1075. err = mlx4_create_eq(dev, dev->caps.num_cqs -
  1076. dev->caps.reserved_cqs +
  1077. MLX4_NUM_SPARE_EQE,
  1078. (dev->flags & MLX4_FLAG_MSI_X) ?
  1079. i + 1 - !!(i > MLX4_EQ_ASYNC) : 0,
  1080. eq);
  1081. }
  1082. if (err)
  1083. goto err_out_unmap;
  1084. }
  1085. if (dev->flags & MLX4_FLAG_MSI_X) {
  1086. const char *eq_name;
  1087. snprintf(priv->eq_table.irq_names +
  1088. MLX4_EQ_ASYNC * MLX4_IRQNAME_SIZE,
  1089. MLX4_IRQNAME_SIZE,
  1090. "mlx4-async@pci:%s",
  1091. pci_name(dev->persist->pdev));
  1092. eq_name = priv->eq_table.irq_names +
  1093. MLX4_EQ_ASYNC * MLX4_IRQNAME_SIZE;
  1094. err = request_irq(priv->eq_table.eq[MLX4_EQ_ASYNC].irq,
  1095. mlx4_msi_x_interrupt, 0, eq_name,
  1096. priv->eq_table.eq + MLX4_EQ_ASYNC);
  1097. if (err)
  1098. goto err_out_unmap;
  1099. priv->eq_table.eq[MLX4_EQ_ASYNC].have_irq = 1;
  1100. } else {
  1101. snprintf(priv->eq_table.irq_names,
  1102. MLX4_IRQNAME_SIZE,
  1103. DRV_NAME "@pci:%s",
  1104. pci_name(dev->persist->pdev));
  1105. err = request_irq(dev->persist->pdev->irq, mlx4_interrupt,
  1106. IRQF_SHARED, priv->eq_table.irq_names, dev);
  1107. if (err)
  1108. goto err_out_unmap;
  1109. priv->eq_table.have_irq = 1;
  1110. }
  1111. err = mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
  1112. priv->eq_table.eq[MLX4_EQ_ASYNC].eqn);
  1113. if (err)
  1114. mlx4_warn(dev, "MAP_EQ for async EQ %d failed (%d)\n",
  1115. priv->eq_table.eq[MLX4_EQ_ASYNC].eqn, err);
  1116. /* arm ASYNC eq */
  1117. eq_set_ci(&priv->eq_table.eq[MLX4_EQ_ASYNC], 1);
  1118. return 0;
  1119. err_out_unmap:
  1120. while (i >= 0)
  1121. mlx4_free_eq(dev, &priv->eq_table.eq[i--]);
  1122. #ifdef CONFIG_RFS_ACCEL
  1123. for (i = 1; i <= dev->caps.num_ports; i++) {
  1124. if (mlx4_priv(dev)->port[i].rmap) {
  1125. free_irq_cpu_rmap(mlx4_priv(dev)->port[i].rmap);
  1126. mlx4_priv(dev)->port[i].rmap = NULL;
  1127. }
  1128. }
  1129. #endif
  1130. mlx4_free_irqs(dev);
  1131. err_out_clr_int:
  1132. if (!mlx4_is_slave(dev))
  1133. mlx4_unmap_clr_int(dev);
  1134. err_out_bitmap:
  1135. mlx4_unmap_uar(dev);
  1136. mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
  1137. err_out_free:
  1138. kfree(priv->eq_table.uar_map);
  1139. return err;
  1140. }
  1141. void mlx4_cleanup_eq_table(struct mlx4_dev *dev)
  1142. {
  1143. struct mlx4_priv *priv = mlx4_priv(dev);
  1144. int i;
  1145. mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 1,
  1146. priv->eq_table.eq[MLX4_EQ_ASYNC].eqn);
  1147. #ifdef CONFIG_RFS_ACCEL
  1148. for (i = 1; i <= dev->caps.num_ports; i++) {
  1149. if (mlx4_priv(dev)->port[i].rmap) {
  1150. free_irq_cpu_rmap(mlx4_priv(dev)->port[i].rmap);
  1151. mlx4_priv(dev)->port[i].rmap = NULL;
  1152. }
  1153. }
  1154. #endif
  1155. mlx4_free_irqs(dev);
  1156. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  1157. mlx4_free_eq(dev, &priv->eq_table.eq[i]);
  1158. if (!mlx4_is_slave(dev))
  1159. mlx4_unmap_clr_int(dev);
  1160. mlx4_unmap_uar(dev);
  1161. mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
  1162. kfree(priv->eq_table.uar_map);
  1163. }
  1164. /* A test that verifies that we can accept interrupts on all
  1165. * the irq vectors of the device.
  1166. * Interrupts are checked using the NOP command.
  1167. */
  1168. int mlx4_test_interrupts(struct mlx4_dev *dev)
  1169. {
  1170. struct mlx4_priv *priv = mlx4_priv(dev);
  1171. int i;
  1172. int err;
  1173. err = mlx4_NOP(dev);
  1174. /* When not in MSI_X, there is only one irq to check */
  1175. if (!(dev->flags & MLX4_FLAG_MSI_X) || mlx4_is_slave(dev))
  1176. return err;
  1177. /* A loop over all completion vectors, for each vector we will check
  1178. * whether it works by mapping command completions to that vector
  1179. * and performing a NOP command
  1180. */
  1181. for(i = 0; !err && (i < dev->caps.num_comp_vectors); ++i) {
  1182. /* Make sure request_irq was called */
  1183. if (!priv->eq_table.eq[i].have_irq)
  1184. continue;
  1185. /* Temporary use polling for command completions */
  1186. mlx4_cmd_use_polling(dev);
  1187. /* Map the new eq to handle all asynchronous events */
  1188. err = mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
  1189. priv->eq_table.eq[i].eqn);
  1190. if (err) {
  1191. mlx4_warn(dev, "Failed mapping eq for interrupt test\n");
  1192. mlx4_cmd_use_events(dev);
  1193. break;
  1194. }
  1195. /* Go back to using events */
  1196. mlx4_cmd_use_events(dev);
  1197. err = mlx4_NOP(dev);
  1198. }
  1199. /* Return to default */
  1200. mlx4_MAP_EQ(dev, get_async_ev_mask(dev), 0,
  1201. priv->eq_table.eq[MLX4_EQ_ASYNC].eqn);
  1202. return err;
  1203. }
  1204. EXPORT_SYMBOL(mlx4_test_interrupts);
  1205. bool mlx4_is_eq_vector_valid(struct mlx4_dev *dev, u8 port, int vector)
  1206. {
  1207. struct mlx4_priv *priv = mlx4_priv(dev);
  1208. vector = MLX4_CQ_TO_EQ_VECTOR(vector);
  1209. if (vector < 0 || (vector >= dev->caps.num_comp_vectors + 1) ||
  1210. (vector == MLX4_EQ_ASYNC))
  1211. return false;
  1212. return test_bit(port - 1, priv->eq_table.eq[vector].actv_ports.ports);
  1213. }
  1214. EXPORT_SYMBOL(mlx4_is_eq_vector_valid);
  1215. u32 mlx4_get_eqs_per_port(struct mlx4_dev *dev, u8 port)
  1216. {
  1217. struct mlx4_priv *priv = mlx4_priv(dev);
  1218. unsigned int i;
  1219. unsigned int sum = 0;
  1220. for (i = 0; i < dev->caps.num_comp_vectors + 1; i++)
  1221. sum += !!test_bit(port - 1,
  1222. priv->eq_table.eq[i].actv_ports.ports);
  1223. return sum;
  1224. }
  1225. EXPORT_SYMBOL(mlx4_get_eqs_per_port);
  1226. int mlx4_is_eq_shared(struct mlx4_dev *dev, int vector)
  1227. {
  1228. struct mlx4_priv *priv = mlx4_priv(dev);
  1229. vector = MLX4_CQ_TO_EQ_VECTOR(vector);
  1230. if (vector <= 0 || (vector >= dev->caps.num_comp_vectors + 1))
  1231. return -EINVAL;
  1232. return !!(bitmap_weight(priv->eq_table.eq[vector].actv_ports.ports,
  1233. dev->caps.num_ports) > 1);
  1234. }
  1235. EXPORT_SYMBOL(mlx4_is_eq_shared);
  1236. struct cpu_rmap *mlx4_get_cpu_rmap(struct mlx4_dev *dev, int port)
  1237. {
  1238. return mlx4_priv(dev)->port[port].rmap;
  1239. }
  1240. EXPORT_SYMBOL(mlx4_get_cpu_rmap);
  1241. int mlx4_assign_eq(struct mlx4_dev *dev, u8 port, int *vector)
  1242. {
  1243. struct mlx4_priv *priv = mlx4_priv(dev);
  1244. int err = 0, i = 0;
  1245. u32 min_ref_count_val = (u32)-1;
  1246. int requested_vector = MLX4_CQ_TO_EQ_VECTOR(*vector);
  1247. int *prequested_vector = NULL;
  1248. mutex_lock(&priv->msix_ctl.pool_lock);
  1249. if (requested_vector < (dev->caps.num_comp_vectors + 1) &&
  1250. (requested_vector >= 0) &&
  1251. (requested_vector != MLX4_EQ_ASYNC)) {
  1252. if (test_bit(port - 1,
  1253. priv->eq_table.eq[requested_vector].actv_ports.ports)) {
  1254. prequested_vector = &requested_vector;
  1255. } else {
  1256. struct mlx4_eq *eq;
  1257. for (i = 1; i < port;
  1258. requested_vector += mlx4_get_eqs_per_port(dev, i++))
  1259. ;
  1260. eq = &priv->eq_table.eq[requested_vector];
  1261. if (requested_vector < dev->caps.num_comp_vectors + 1 &&
  1262. test_bit(port - 1, eq->actv_ports.ports)) {
  1263. prequested_vector = &requested_vector;
  1264. }
  1265. }
  1266. }
  1267. if (!prequested_vector) {
  1268. requested_vector = -1;
  1269. for (i = 0; min_ref_count_val && i < dev->caps.num_comp_vectors + 1;
  1270. i++) {
  1271. struct mlx4_eq *eq = &priv->eq_table.eq[i];
  1272. if (min_ref_count_val > eq->ref_count &&
  1273. test_bit(port - 1, eq->actv_ports.ports)) {
  1274. min_ref_count_val = eq->ref_count;
  1275. requested_vector = i;
  1276. }
  1277. }
  1278. if (requested_vector < 0) {
  1279. err = -ENOSPC;
  1280. goto err_unlock;
  1281. }
  1282. prequested_vector = &requested_vector;
  1283. }
  1284. if (!test_bit(*prequested_vector, priv->msix_ctl.pool_bm) &&
  1285. dev->flags & MLX4_FLAG_MSI_X) {
  1286. set_bit(*prequested_vector, priv->msix_ctl.pool_bm);
  1287. snprintf(priv->eq_table.irq_names +
  1288. *prequested_vector * MLX4_IRQNAME_SIZE,
  1289. MLX4_IRQNAME_SIZE, "mlx4-%d@%s",
  1290. *prequested_vector, dev_name(&dev->persist->pdev->dev));
  1291. err = request_irq(priv->eq_table.eq[*prequested_vector].irq,
  1292. mlx4_msi_x_interrupt, 0,
  1293. &priv->eq_table.irq_names[*prequested_vector << 5],
  1294. priv->eq_table.eq + *prequested_vector);
  1295. if (err) {
  1296. clear_bit(*prequested_vector, priv->msix_ctl.pool_bm);
  1297. *prequested_vector = -1;
  1298. } else {
  1299. #if defined(CONFIG_SMP)
  1300. mlx4_set_eq_affinity_hint(priv, *prequested_vector);
  1301. #endif
  1302. eq_set_ci(&priv->eq_table.eq[*prequested_vector], 1);
  1303. priv->eq_table.eq[*prequested_vector].have_irq = 1;
  1304. }
  1305. }
  1306. if (!err && *prequested_vector >= 0)
  1307. priv->eq_table.eq[*prequested_vector].ref_count++;
  1308. err_unlock:
  1309. mutex_unlock(&priv->msix_ctl.pool_lock);
  1310. if (!err && *prequested_vector >= 0)
  1311. *vector = MLX4_EQ_TO_CQ_VECTOR(*prequested_vector);
  1312. else
  1313. *vector = 0;
  1314. return err;
  1315. }
  1316. EXPORT_SYMBOL(mlx4_assign_eq);
  1317. int mlx4_eq_get_irq(struct mlx4_dev *dev, int cq_vec)
  1318. {
  1319. struct mlx4_priv *priv = mlx4_priv(dev);
  1320. return priv->eq_table.eq[MLX4_CQ_TO_EQ_VECTOR(cq_vec)].irq;
  1321. }
  1322. EXPORT_SYMBOL(mlx4_eq_get_irq);
  1323. void mlx4_release_eq(struct mlx4_dev *dev, int vec)
  1324. {
  1325. struct mlx4_priv *priv = mlx4_priv(dev);
  1326. int eq_vec = MLX4_CQ_TO_EQ_VECTOR(vec);
  1327. mutex_lock(&priv->msix_ctl.pool_lock);
  1328. priv->eq_table.eq[eq_vec].ref_count--;
  1329. /* once we allocated EQ, we don't release it because it might be binded
  1330. * to cpu_rmap.
  1331. */
  1332. mutex_unlock(&priv->msix_ctl.pool_lock);
  1333. }
  1334. EXPORT_SYMBOL(mlx4_release_eq);