eq.c 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568
  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. 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. case MLX4_EVENT_TYPE_SRQ_CATAS_ERROR:
  491. if (mlx4_is_master(dev)) {
  492. /* forward only to slave owning the SRQ */
  493. ret = mlx4_get_slave_from_resource_id(dev,
  494. RES_SRQ,
  495. be32_to_cpu(eqe->event.srq.srqn)
  496. & 0xffffff,
  497. &slave);
  498. if (ret && ret != -ENOENT) {
  499. mlx4_warn(dev, "SRQ event %02x(%02x) on EQ %d at index %u: could not get slave id (%d)\n",
  500. eqe->type, eqe->subtype,
  501. eq->eqn, eq->cons_index, ret);
  502. break;
  503. }
  504. if (eqe->type ==
  505. MLX4_EVENT_TYPE_SRQ_CATAS_ERROR)
  506. mlx4_warn(dev, "%s: slave:%d, srq_no:0x%x, event: %02x(%02x)\n",
  507. __func__, slave,
  508. be32_to_cpu(eqe->event.srq.srqn),
  509. eqe->type, eqe->subtype);
  510. if (!ret && slave != dev->caps.function) {
  511. if (eqe->type ==
  512. MLX4_EVENT_TYPE_SRQ_CATAS_ERROR)
  513. mlx4_warn(dev, "%s: sending event %02x(%02x) to slave:%d\n",
  514. __func__, eqe->type,
  515. eqe->subtype, slave);
  516. mlx4_slave_event(dev, slave, eqe);
  517. break;
  518. }
  519. }
  520. mlx4_srq_event(dev, be32_to_cpu(eqe->event.srq.srqn) &
  521. 0xffffff, eqe->type);
  522. break;
  523. case MLX4_EVENT_TYPE_CMD:
  524. mlx4_cmd_event(dev,
  525. be16_to_cpu(eqe->event.cmd.token),
  526. eqe->event.cmd.status,
  527. be64_to_cpu(eqe->event.cmd.out_param));
  528. break;
  529. case MLX4_EVENT_TYPE_PORT_CHANGE: {
  530. struct mlx4_slaves_pport slaves_port;
  531. port = be32_to_cpu(eqe->event.port_change.port) >> 28;
  532. slaves_port = mlx4_phys_to_slaves_pport(dev, port);
  533. if (eqe->subtype == MLX4_PORT_CHANGE_SUBTYPE_DOWN) {
  534. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_DOWN,
  535. port);
  536. mlx4_priv(dev)->sense.do_sense_port[port] = 1;
  537. if (!mlx4_is_master(dev))
  538. break;
  539. for (i = 0; i < dev->persist->num_vfs + 1;
  540. i++) {
  541. int reported_port = mlx4_is_bonded(dev) ? 1 : mlx4_phys_to_slave_port(dev, i, port);
  542. if (!test_bit(i, slaves_port.slaves) && !mlx4_is_bonded(dev))
  543. continue;
  544. if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH) {
  545. if (i == mlx4_master_func_num(dev))
  546. continue;
  547. mlx4_dbg(dev, "%s: Sending MLX4_PORT_CHANGE_SUBTYPE_DOWN to slave: %d, port:%d\n",
  548. __func__, i, port);
  549. s_info = &priv->mfunc.master.vf_oper[i].vport[port].state;
  550. if (IFLA_VF_LINK_STATE_AUTO == s_info->link_state) {
  551. eqe->event.port_change.port =
  552. cpu_to_be32(
  553. (be32_to_cpu(eqe->event.port_change.port) & 0xFFFFFFF)
  554. | (reported_port << 28));
  555. mlx4_slave_event(dev, i, eqe);
  556. }
  557. } else { /* IB port */
  558. set_and_calc_slave_port_state(dev, i, port,
  559. MLX4_PORT_STATE_DEV_EVENT_PORT_DOWN,
  560. &gen_event);
  561. /*we can be in pending state, then do not send port_down event*/
  562. if (SLAVE_PORT_GEN_EVENT_DOWN == gen_event) {
  563. if (i == mlx4_master_func_num(dev))
  564. continue;
  565. eqe->event.port_change.port =
  566. cpu_to_be32(
  567. (be32_to_cpu(eqe->event.port_change.port) & 0xFFFFFFF)
  568. | (mlx4_phys_to_slave_port(dev, i, port) << 28));
  569. mlx4_slave_event(dev, i, eqe);
  570. }
  571. }
  572. }
  573. } else {
  574. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_UP, port);
  575. mlx4_priv(dev)->sense.do_sense_port[port] = 0;
  576. if (!mlx4_is_master(dev))
  577. break;
  578. if (dev->caps.port_type[port] == MLX4_PORT_TYPE_ETH)
  579. for (i = 0;
  580. i < dev->persist->num_vfs + 1;
  581. i++) {
  582. int reported_port = mlx4_is_bonded(dev) ? 1 : mlx4_phys_to_slave_port(dev, i, port);
  583. if (!test_bit(i, slaves_port.slaves) && !mlx4_is_bonded(dev))
  584. continue;
  585. if (i == mlx4_master_func_num(dev))
  586. continue;
  587. s_info = &priv->mfunc.master.vf_oper[i].vport[port].state;
  588. if (IFLA_VF_LINK_STATE_AUTO == s_info->link_state) {
  589. eqe->event.port_change.port =
  590. cpu_to_be32(
  591. (be32_to_cpu(eqe->event.port_change.port) & 0xFFFFFFF)
  592. | (reported_port << 28));
  593. mlx4_slave_event(dev, i, eqe);
  594. }
  595. }
  596. else /* IB port */
  597. /* port-up event will be sent to a slave when the
  598. * slave's alias-guid is set. This is done in alias_GUID.c
  599. */
  600. set_all_slave_state(dev, port, MLX4_DEV_EVENT_PORT_UP);
  601. }
  602. break;
  603. }
  604. case MLX4_EVENT_TYPE_CQ_ERROR:
  605. mlx4_warn(dev, "CQ %s on CQN %06x\n",
  606. eqe->event.cq_err.syndrome == 1 ?
  607. "overrun" : "access violation",
  608. be32_to_cpu(eqe->event.cq_err.cqn) & 0xffffff);
  609. if (mlx4_is_master(dev)) {
  610. ret = mlx4_get_slave_from_resource_id(dev,
  611. RES_CQ,
  612. be32_to_cpu(eqe->event.cq_err.cqn)
  613. & 0xffffff, &slave);
  614. if (ret && ret != -ENOENT) {
  615. mlx4_dbg(dev, "CQ event %02x(%02x) on EQ %d at index %u: could not get slave id (%d)\n",
  616. eqe->type, eqe->subtype,
  617. eq->eqn, eq->cons_index, ret);
  618. break;
  619. }
  620. if (!ret && slave != dev->caps.function) {
  621. mlx4_slave_event(dev, slave, eqe);
  622. break;
  623. }
  624. }
  625. mlx4_cq_event(dev,
  626. be32_to_cpu(eqe->event.cq_err.cqn)
  627. & 0xffffff,
  628. eqe->type);
  629. break;
  630. case MLX4_EVENT_TYPE_EQ_OVERFLOW:
  631. mlx4_warn(dev, "EQ overrun on EQN %d\n", eq->eqn);
  632. break;
  633. case MLX4_EVENT_TYPE_OP_REQUIRED:
  634. atomic_inc(&priv->opreq_count);
  635. /* FW commands can't be executed from interrupt context
  636. * working in deferred task
  637. */
  638. queue_work(mlx4_wq, &priv->opreq_task);
  639. break;
  640. case MLX4_EVENT_TYPE_COMM_CHANNEL:
  641. if (!mlx4_is_master(dev)) {
  642. mlx4_warn(dev, "Received comm channel event for non master device\n");
  643. break;
  644. }
  645. memcpy(&priv->mfunc.master.comm_arm_bit_vector,
  646. eqe->event.comm_channel_arm.bit_vec,
  647. sizeof(eqe->event.comm_channel_arm.bit_vec));
  648. queue_work(priv->mfunc.master.comm_wq,
  649. &priv->mfunc.master.comm_work);
  650. break;
  651. case MLX4_EVENT_TYPE_FLR_EVENT:
  652. flr_slave = be32_to_cpu(eqe->event.flr_event.slave_id);
  653. if (!mlx4_is_master(dev)) {
  654. mlx4_warn(dev, "Non-master function received FLR event\n");
  655. break;
  656. }
  657. mlx4_dbg(dev, "FLR event for slave: %d\n", flr_slave);
  658. if (flr_slave >= dev->num_slaves) {
  659. mlx4_warn(dev,
  660. "Got FLR for unknown function: %d\n",
  661. flr_slave);
  662. update_slave_state = 0;
  663. } else
  664. update_slave_state = 1;
  665. spin_lock_irqsave(&priv->mfunc.master.slave_state_lock, flags);
  666. if (update_slave_state) {
  667. priv->mfunc.master.slave_state[flr_slave].active = false;
  668. priv->mfunc.master.slave_state[flr_slave].last_cmd = MLX4_COMM_CMD_FLR;
  669. priv->mfunc.master.slave_state[flr_slave].is_slave_going_down = 1;
  670. }
  671. spin_unlock_irqrestore(&priv->mfunc.master.slave_state_lock, flags);
  672. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_SLAVE_SHUTDOWN,
  673. flr_slave);
  674. queue_work(priv->mfunc.master.comm_wq,
  675. &priv->mfunc.master.slave_flr_event_work);
  676. break;
  677. case MLX4_EVENT_TYPE_FATAL_WARNING:
  678. if (eqe->subtype == MLX4_FATAL_WARNING_SUBTYPE_WARMING) {
  679. if (mlx4_is_master(dev))
  680. for (i = 0; i < dev->num_slaves; i++) {
  681. mlx4_dbg(dev, "%s: Sending MLX4_FATAL_WARNING_SUBTYPE_WARMING to slave: %d\n",
  682. __func__, i);
  683. if (i == dev->caps.function)
  684. continue;
  685. mlx4_slave_event(dev, i, eqe);
  686. }
  687. mlx4_err(dev, "Temperature Threshold was reached! Threshold: %d celsius degrees; Current Temperature: %d\n",
  688. be16_to_cpu(eqe->event.warming.warning_threshold),
  689. be16_to_cpu(eqe->event.warming.current_temperature));
  690. } else
  691. 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",
  692. eqe->type, eqe->subtype, eq->eqn,
  693. eq->cons_index, eqe->owner, eq->nent,
  694. eqe->slave_id,
  695. !!(eqe->owner & 0x80) ^
  696. !!(eq->cons_index & eq->nent) ? "HW" : "SW");
  697. break;
  698. case MLX4_EVENT_TYPE_PORT_MNG_CHG_EVENT:
  699. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_MGMT_CHANGE,
  700. (unsigned long) eqe);
  701. break;
  702. case MLX4_EVENT_TYPE_RECOVERABLE_ERROR_EVENT:
  703. switch (eqe->subtype) {
  704. case MLX4_RECOVERABLE_ERROR_EVENT_SUBTYPE_BAD_CABLE:
  705. mlx4_warn(dev, "Bad cable detected on port %u\n",
  706. eqe->event.bad_cable.port);
  707. break;
  708. case MLX4_RECOVERABLE_ERROR_EVENT_SUBTYPE_UNSUPPORTED_CABLE:
  709. mlx4_warn(dev, "Unsupported cable detected\n");
  710. break;
  711. default:
  712. mlx4_dbg(dev,
  713. "Unhandled recoverable error event detected: %02x(%02x) on EQ %d at index %u. owner=%x, nent=0x%x, ownership=%s\n",
  714. eqe->type, eqe->subtype, eq->eqn,
  715. eq->cons_index, eqe->owner, eq->nent,
  716. !!(eqe->owner & 0x80) ^
  717. !!(eq->cons_index & eq->nent) ? "HW" : "SW");
  718. break;
  719. }
  720. break;
  721. case MLX4_EVENT_TYPE_EEC_CATAS_ERROR:
  722. case MLX4_EVENT_TYPE_ECC_DETECT:
  723. default:
  724. mlx4_warn(dev, "Unhandled event %02x(%02x) on EQ %d at index %u. owner=%x, nent=0x%x, slave=%x, ownership=%s\n",
  725. eqe->type, eqe->subtype, eq->eqn,
  726. eq->cons_index, eqe->owner, eq->nent,
  727. eqe->slave_id,
  728. !!(eqe->owner & 0x80) ^
  729. !!(eq->cons_index & eq->nent) ? "HW" : "SW");
  730. break;
  731. };
  732. ++eq->cons_index;
  733. eqes_found = 1;
  734. ++set_ci;
  735. /*
  736. * The HCA will think the queue has overflowed if we
  737. * don't tell it we've been processing events. We
  738. * create our EQs with MLX4_NUM_SPARE_EQE extra
  739. * entries, so we must update our consumer index at
  740. * least that often.
  741. */
  742. if (unlikely(set_ci >= MLX4_NUM_SPARE_EQE)) {
  743. eq_set_ci(eq, 0);
  744. set_ci = 0;
  745. }
  746. }
  747. eq_set_ci(eq, 1);
  748. return eqes_found;
  749. }
  750. static irqreturn_t mlx4_interrupt(int irq, void *dev_ptr)
  751. {
  752. struct mlx4_dev *dev = dev_ptr;
  753. struct mlx4_priv *priv = mlx4_priv(dev);
  754. int work = 0;
  755. int i;
  756. writel(priv->eq_table.clr_mask, priv->eq_table.clr_int);
  757. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  758. work |= mlx4_eq_int(dev, &priv->eq_table.eq[i]);
  759. return IRQ_RETVAL(work);
  760. }
  761. static irqreturn_t mlx4_msi_x_interrupt(int irq, void *eq_ptr)
  762. {
  763. struct mlx4_eq *eq = eq_ptr;
  764. struct mlx4_dev *dev = eq->dev;
  765. mlx4_eq_int(dev, eq);
  766. /* MSI-X vectors always belong to us */
  767. return IRQ_HANDLED;
  768. }
  769. int mlx4_MAP_EQ_wrapper(struct mlx4_dev *dev, int slave,
  770. struct mlx4_vhcr *vhcr,
  771. struct mlx4_cmd_mailbox *inbox,
  772. struct mlx4_cmd_mailbox *outbox,
  773. struct mlx4_cmd_info *cmd)
  774. {
  775. struct mlx4_priv *priv = mlx4_priv(dev);
  776. struct mlx4_slave_event_eq_info *event_eq =
  777. priv->mfunc.master.slave_state[slave].event_eq;
  778. u32 in_modifier = vhcr->in_modifier;
  779. u32 eqn = in_modifier & 0x3FF;
  780. u64 in_param = vhcr->in_param;
  781. int err = 0;
  782. int i;
  783. if (slave == dev->caps.function)
  784. err = mlx4_cmd(dev, in_param, (in_modifier & 0x80000000) | eqn,
  785. 0, MLX4_CMD_MAP_EQ, MLX4_CMD_TIME_CLASS_B,
  786. MLX4_CMD_NATIVE);
  787. if (!err)
  788. for (i = 0; i < MLX4_EVENT_TYPES_NUM; ++i)
  789. if (in_param & (1LL << i))
  790. event_eq[i].eqn = in_modifier >> 31 ? -1 : eqn;
  791. return err;
  792. }
  793. static int mlx4_MAP_EQ(struct mlx4_dev *dev, u64 event_mask, int unmap,
  794. int eq_num)
  795. {
  796. return mlx4_cmd(dev, event_mask, (unmap << 31) | eq_num,
  797. 0, MLX4_CMD_MAP_EQ, MLX4_CMD_TIME_CLASS_B,
  798. MLX4_CMD_WRAPPED);
  799. }
  800. static int mlx4_SW2HW_EQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
  801. int eq_num)
  802. {
  803. return mlx4_cmd(dev, mailbox->dma, eq_num, 0,
  804. MLX4_CMD_SW2HW_EQ, MLX4_CMD_TIME_CLASS_A,
  805. MLX4_CMD_WRAPPED);
  806. }
  807. static int mlx4_HW2SW_EQ(struct mlx4_dev *dev, int eq_num)
  808. {
  809. return mlx4_cmd(dev, 0, eq_num, 1, MLX4_CMD_HW2SW_EQ,
  810. MLX4_CMD_TIME_CLASS_A, MLX4_CMD_WRAPPED);
  811. }
  812. static int mlx4_num_eq_uar(struct mlx4_dev *dev)
  813. {
  814. /*
  815. * Each UAR holds 4 EQ doorbells. To figure out how many UARs
  816. * we need to map, take the difference of highest index and
  817. * the lowest index we'll use and add 1.
  818. */
  819. return (dev->caps.num_comp_vectors + 1 + dev->caps.reserved_eqs) / 4 -
  820. dev->caps.reserved_eqs / 4 + 1;
  821. }
  822. static void __iomem *mlx4_get_eq_uar(struct mlx4_dev *dev, struct mlx4_eq *eq)
  823. {
  824. struct mlx4_priv *priv = mlx4_priv(dev);
  825. int index;
  826. index = eq->eqn / 4 - dev->caps.reserved_eqs / 4;
  827. if (!priv->eq_table.uar_map[index]) {
  828. priv->eq_table.uar_map[index] =
  829. ioremap(
  830. pci_resource_start(dev->persist->pdev, 2) +
  831. ((eq->eqn / 4) << (dev->uar_page_shift)),
  832. (1 << (dev->uar_page_shift)));
  833. if (!priv->eq_table.uar_map[index]) {
  834. mlx4_err(dev, "Couldn't map EQ doorbell for EQN 0x%06x\n",
  835. eq->eqn);
  836. return NULL;
  837. }
  838. }
  839. return priv->eq_table.uar_map[index] + 0x800 + 8 * (eq->eqn % 4);
  840. }
  841. static void mlx4_unmap_uar(struct mlx4_dev *dev)
  842. {
  843. struct mlx4_priv *priv = mlx4_priv(dev);
  844. int i;
  845. for (i = 0; i < mlx4_num_eq_uar(dev); ++i)
  846. if (priv->eq_table.uar_map[i]) {
  847. iounmap(priv->eq_table.uar_map[i]);
  848. priv->eq_table.uar_map[i] = NULL;
  849. }
  850. }
  851. static int mlx4_create_eq(struct mlx4_dev *dev, int nent,
  852. u8 intr, struct mlx4_eq *eq)
  853. {
  854. struct mlx4_priv *priv = mlx4_priv(dev);
  855. struct mlx4_cmd_mailbox *mailbox;
  856. struct mlx4_eq_context *eq_context;
  857. int npages;
  858. u64 *dma_list = NULL;
  859. dma_addr_t t;
  860. u64 mtt_addr;
  861. int err = -ENOMEM;
  862. int i;
  863. eq->dev = dev;
  864. eq->nent = roundup_pow_of_two(max(nent, 2));
  865. /* CX3 is capable of extending the CQE/EQE from 32 to 64 bytes, with
  866. * strides of 64B,128B and 256B.
  867. */
  868. npages = PAGE_ALIGN(eq->nent * dev->caps.eqe_size) / PAGE_SIZE;
  869. eq->page_list = kmalloc_array(npages, sizeof(*eq->page_list),
  870. GFP_KERNEL);
  871. if (!eq->page_list)
  872. goto err_out;
  873. for (i = 0; i < npages; ++i)
  874. eq->page_list[i].buf = NULL;
  875. dma_list = kmalloc_array(npages, sizeof(*dma_list), GFP_KERNEL);
  876. if (!dma_list)
  877. goto err_out_free;
  878. mailbox = mlx4_alloc_cmd_mailbox(dev);
  879. if (IS_ERR(mailbox))
  880. goto err_out_free;
  881. eq_context = mailbox->buf;
  882. for (i = 0; i < npages; ++i) {
  883. eq->page_list[i].buf = dma_alloc_coherent(&dev->persist->
  884. pdev->dev,
  885. PAGE_SIZE, &t,
  886. GFP_KERNEL);
  887. if (!eq->page_list[i].buf)
  888. goto err_out_free_pages;
  889. dma_list[i] = t;
  890. eq->page_list[i].map = t;
  891. memset(eq->page_list[i].buf, 0, PAGE_SIZE);
  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);