eq.c 45 KB

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