eq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  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/mm.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/mlx4/cmd.h>
  37. #include "mlx4.h"
  38. #include "fw.h"
  39. enum {
  40. MLX4_IRQNAME_SIZE = 64
  41. };
  42. enum {
  43. MLX4_NUM_ASYNC_EQE = 0x100,
  44. MLX4_NUM_SPARE_EQE = 0x80,
  45. MLX4_EQ_ENTRY_SIZE = 0x20
  46. };
  47. /*
  48. * Must be packed because start is 64 bits but only aligned to 32 bits.
  49. */
  50. struct mlx4_eq_context {
  51. __be32 flags;
  52. u16 reserved1[3];
  53. __be16 page_offset;
  54. u8 log_eq_size;
  55. u8 reserved2[4];
  56. u8 eq_period;
  57. u8 reserved3;
  58. u8 eq_max_count;
  59. u8 reserved4[3];
  60. u8 intr;
  61. u8 log_page_size;
  62. u8 reserved5[2];
  63. u8 mtt_base_addr_h;
  64. __be32 mtt_base_addr_l;
  65. u32 reserved6[2];
  66. __be32 consumer_index;
  67. __be32 producer_index;
  68. u32 reserved7[4];
  69. };
  70. #define MLX4_EQ_STATUS_OK ( 0 << 28)
  71. #define MLX4_EQ_STATUS_WRITE_FAIL (10 << 28)
  72. #define MLX4_EQ_OWNER_SW ( 0 << 24)
  73. #define MLX4_EQ_OWNER_HW ( 1 << 24)
  74. #define MLX4_EQ_FLAG_EC ( 1 << 18)
  75. #define MLX4_EQ_FLAG_OI ( 1 << 17)
  76. #define MLX4_EQ_STATE_ARMED ( 9 << 8)
  77. #define MLX4_EQ_STATE_FIRED (10 << 8)
  78. #define MLX4_EQ_STATE_ALWAYS_ARMED (11 << 8)
  79. #define MLX4_ASYNC_EVENT_MASK ((1ull << MLX4_EVENT_TYPE_PATH_MIG) | \
  80. (1ull << MLX4_EVENT_TYPE_COMM_EST) | \
  81. (1ull << MLX4_EVENT_TYPE_SQ_DRAINED) | \
  82. (1ull << MLX4_EVENT_TYPE_CQ_ERROR) | \
  83. (1ull << MLX4_EVENT_TYPE_WQ_CATAS_ERROR) | \
  84. (1ull << MLX4_EVENT_TYPE_EEC_CATAS_ERROR) | \
  85. (1ull << MLX4_EVENT_TYPE_PATH_MIG_FAILED) | \
  86. (1ull << MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR) | \
  87. (1ull << MLX4_EVENT_TYPE_WQ_ACCESS_ERROR) | \
  88. (1ull << MLX4_EVENT_TYPE_PORT_CHANGE) | \
  89. (1ull << MLX4_EVENT_TYPE_ECC_DETECT) | \
  90. (1ull << MLX4_EVENT_TYPE_SRQ_CATAS_ERROR) | \
  91. (1ull << MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE) | \
  92. (1ull << MLX4_EVENT_TYPE_SRQ_LIMIT) | \
  93. (1ull << MLX4_EVENT_TYPE_CMD))
  94. struct mlx4_eqe {
  95. u8 reserved1;
  96. u8 type;
  97. u8 reserved2;
  98. u8 subtype;
  99. union {
  100. u32 raw[6];
  101. struct {
  102. __be32 cqn;
  103. } __attribute__((packed)) comp;
  104. struct {
  105. u16 reserved1;
  106. __be16 token;
  107. u32 reserved2;
  108. u8 reserved3[3];
  109. u8 status;
  110. __be64 out_param;
  111. } __attribute__((packed)) cmd;
  112. struct {
  113. __be32 qpn;
  114. } __attribute__((packed)) qp;
  115. struct {
  116. __be32 srqn;
  117. } __attribute__((packed)) srq;
  118. struct {
  119. __be32 cqn;
  120. u32 reserved1;
  121. u8 reserved2[3];
  122. u8 syndrome;
  123. } __attribute__((packed)) cq_err;
  124. struct {
  125. u32 reserved1[2];
  126. __be32 port;
  127. } __attribute__((packed)) port_change;
  128. } event;
  129. u8 reserved3[3];
  130. u8 owner;
  131. } __attribute__((packed));
  132. static void eq_set_ci(struct mlx4_eq *eq, int req_not)
  133. {
  134. __raw_writel((__force u32) cpu_to_be32((eq->cons_index & 0xffffff) |
  135. req_not << 31),
  136. eq->doorbell);
  137. /* We still want ordering, just not swabbing, so add a barrier */
  138. mb();
  139. }
  140. static struct mlx4_eqe *get_eqe(struct mlx4_eq *eq, u32 entry)
  141. {
  142. unsigned long off = (entry & (eq->nent - 1)) * MLX4_EQ_ENTRY_SIZE;
  143. return eq->page_list[off / PAGE_SIZE].buf + off % PAGE_SIZE;
  144. }
  145. static struct mlx4_eqe *next_eqe_sw(struct mlx4_eq *eq)
  146. {
  147. struct mlx4_eqe *eqe = get_eqe(eq, eq->cons_index);
  148. return !!(eqe->owner & 0x80) ^ !!(eq->cons_index & eq->nent) ? NULL : eqe;
  149. }
  150. static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
  151. {
  152. struct mlx4_eqe *eqe;
  153. int cqn;
  154. int eqes_found = 0;
  155. int set_ci = 0;
  156. int port;
  157. while ((eqe = next_eqe_sw(eq))) {
  158. /*
  159. * Make sure we read EQ entry contents after we've
  160. * checked the ownership bit.
  161. */
  162. rmb();
  163. switch (eqe->type) {
  164. case MLX4_EVENT_TYPE_COMP:
  165. cqn = be32_to_cpu(eqe->event.comp.cqn) & 0xffffff;
  166. mlx4_cq_completion(dev, cqn);
  167. break;
  168. case MLX4_EVENT_TYPE_PATH_MIG:
  169. case MLX4_EVENT_TYPE_COMM_EST:
  170. case MLX4_EVENT_TYPE_SQ_DRAINED:
  171. case MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE:
  172. case MLX4_EVENT_TYPE_WQ_CATAS_ERROR:
  173. case MLX4_EVENT_TYPE_PATH_MIG_FAILED:
  174. case MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
  175. case MLX4_EVENT_TYPE_WQ_ACCESS_ERROR:
  176. mlx4_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
  177. eqe->type);
  178. break;
  179. case MLX4_EVENT_TYPE_SRQ_LIMIT:
  180. case MLX4_EVENT_TYPE_SRQ_CATAS_ERROR:
  181. mlx4_srq_event(dev, be32_to_cpu(eqe->event.srq.srqn) & 0xffffff,
  182. eqe->type);
  183. break;
  184. case MLX4_EVENT_TYPE_CMD:
  185. mlx4_cmd_event(dev,
  186. be16_to_cpu(eqe->event.cmd.token),
  187. eqe->event.cmd.status,
  188. be64_to_cpu(eqe->event.cmd.out_param));
  189. break;
  190. case MLX4_EVENT_TYPE_PORT_CHANGE:
  191. port = be32_to_cpu(eqe->event.port_change.port) >> 28;
  192. if (eqe->subtype == MLX4_PORT_CHANGE_SUBTYPE_DOWN) {
  193. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_DOWN,
  194. port);
  195. mlx4_priv(dev)->sense.do_sense_port[port] = 1;
  196. } else {
  197. mlx4_dispatch_event(dev, MLX4_DEV_EVENT_PORT_UP,
  198. port);
  199. mlx4_priv(dev)->sense.do_sense_port[port] = 0;
  200. }
  201. break;
  202. case MLX4_EVENT_TYPE_CQ_ERROR:
  203. mlx4_warn(dev, "CQ %s on CQN %06x\n",
  204. eqe->event.cq_err.syndrome == 1 ?
  205. "overrun" : "access violation",
  206. be32_to_cpu(eqe->event.cq_err.cqn) & 0xffffff);
  207. mlx4_cq_event(dev, be32_to_cpu(eqe->event.cq_err.cqn),
  208. eqe->type);
  209. break;
  210. case MLX4_EVENT_TYPE_EQ_OVERFLOW:
  211. mlx4_warn(dev, "EQ overrun on EQN %d\n", eq->eqn);
  212. break;
  213. case MLX4_EVENT_TYPE_EEC_CATAS_ERROR:
  214. case MLX4_EVENT_TYPE_ECC_DETECT:
  215. default:
  216. mlx4_warn(dev, "Unhandled event %02x(%02x) on EQ %d at index %u\n",
  217. eqe->type, eqe->subtype, eq->eqn, eq->cons_index);
  218. break;
  219. };
  220. ++eq->cons_index;
  221. eqes_found = 1;
  222. ++set_ci;
  223. /*
  224. * The HCA will think the queue has overflowed if we
  225. * don't tell it we've been processing events. We
  226. * create our EQs with MLX4_NUM_SPARE_EQE extra
  227. * entries, so we must update our consumer index at
  228. * least that often.
  229. */
  230. if (unlikely(set_ci >= MLX4_NUM_SPARE_EQE)) {
  231. eq_set_ci(eq, 0);
  232. set_ci = 0;
  233. }
  234. }
  235. eq_set_ci(eq, 1);
  236. return eqes_found;
  237. }
  238. static irqreturn_t mlx4_interrupt(int irq, void *dev_ptr)
  239. {
  240. struct mlx4_dev *dev = dev_ptr;
  241. struct mlx4_priv *priv = mlx4_priv(dev);
  242. int work = 0;
  243. int i;
  244. writel(priv->eq_table.clr_mask, priv->eq_table.clr_int);
  245. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  246. work |= mlx4_eq_int(dev, &priv->eq_table.eq[i]);
  247. return IRQ_RETVAL(work);
  248. }
  249. static irqreturn_t mlx4_msi_x_interrupt(int irq, void *eq_ptr)
  250. {
  251. struct mlx4_eq *eq = eq_ptr;
  252. struct mlx4_dev *dev = eq->dev;
  253. mlx4_eq_int(dev, eq);
  254. /* MSI-X vectors always belong to us */
  255. return IRQ_HANDLED;
  256. }
  257. static int mlx4_MAP_EQ(struct mlx4_dev *dev, u64 event_mask, int unmap,
  258. int eq_num)
  259. {
  260. return mlx4_cmd(dev, event_mask, (unmap << 31) | eq_num,
  261. 0, MLX4_CMD_MAP_EQ, MLX4_CMD_TIME_CLASS_B);
  262. }
  263. static int mlx4_SW2HW_EQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
  264. int eq_num)
  265. {
  266. return mlx4_cmd(dev, mailbox->dma, eq_num, 0, MLX4_CMD_SW2HW_EQ,
  267. MLX4_CMD_TIME_CLASS_A);
  268. }
  269. static int mlx4_HW2SW_EQ(struct mlx4_dev *dev, struct mlx4_cmd_mailbox *mailbox,
  270. int eq_num)
  271. {
  272. return mlx4_cmd_box(dev, 0, mailbox->dma, eq_num, 0, MLX4_CMD_HW2SW_EQ,
  273. MLX4_CMD_TIME_CLASS_A);
  274. }
  275. static int mlx4_num_eq_uar(struct mlx4_dev *dev)
  276. {
  277. /*
  278. * Each UAR holds 4 EQ doorbells. To figure out how many UARs
  279. * we need to map, take the difference of highest index and
  280. * the lowest index we'll use and add 1.
  281. */
  282. return (dev->caps.num_comp_vectors + 1 + dev->caps.reserved_eqs) / 4 -
  283. dev->caps.reserved_eqs / 4 + 1;
  284. }
  285. static void __iomem *mlx4_get_eq_uar(struct mlx4_dev *dev, struct mlx4_eq *eq)
  286. {
  287. struct mlx4_priv *priv = mlx4_priv(dev);
  288. int index;
  289. index = eq->eqn / 4 - dev->caps.reserved_eqs / 4;
  290. if (!priv->eq_table.uar_map[index]) {
  291. priv->eq_table.uar_map[index] =
  292. ioremap(pci_resource_start(dev->pdev, 2) +
  293. ((eq->eqn / 4) << PAGE_SHIFT),
  294. PAGE_SIZE);
  295. if (!priv->eq_table.uar_map[index]) {
  296. mlx4_err(dev, "Couldn't map EQ doorbell for EQN 0x%06x\n",
  297. eq->eqn);
  298. return NULL;
  299. }
  300. }
  301. return priv->eq_table.uar_map[index] + 0x800 + 8 * (eq->eqn % 4);
  302. }
  303. static int mlx4_create_eq(struct mlx4_dev *dev, int nent,
  304. u8 intr, struct mlx4_eq *eq)
  305. {
  306. struct mlx4_priv *priv = mlx4_priv(dev);
  307. struct mlx4_cmd_mailbox *mailbox;
  308. struct mlx4_eq_context *eq_context;
  309. int npages;
  310. u64 *dma_list = NULL;
  311. dma_addr_t t;
  312. u64 mtt_addr;
  313. int err = -ENOMEM;
  314. int i;
  315. eq->dev = dev;
  316. eq->nent = roundup_pow_of_two(max(nent, 2));
  317. npages = PAGE_ALIGN(eq->nent * MLX4_EQ_ENTRY_SIZE) / PAGE_SIZE;
  318. eq->page_list = kmalloc(npages * sizeof *eq->page_list,
  319. GFP_KERNEL);
  320. if (!eq->page_list)
  321. goto err_out;
  322. for (i = 0; i < npages; ++i)
  323. eq->page_list[i].buf = NULL;
  324. dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
  325. if (!dma_list)
  326. goto err_out_free;
  327. mailbox = mlx4_alloc_cmd_mailbox(dev);
  328. if (IS_ERR(mailbox))
  329. goto err_out_free;
  330. eq_context = mailbox->buf;
  331. for (i = 0; i < npages; ++i) {
  332. eq->page_list[i].buf = dma_alloc_coherent(&dev->pdev->dev,
  333. PAGE_SIZE, &t, GFP_KERNEL);
  334. if (!eq->page_list[i].buf)
  335. goto err_out_free_pages;
  336. dma_list[i] = t;
  337. eq->page_list[i].map = t;
  338. memset(eq->page_list[i].buf, 0, PAGE_SIZE);
  339. }
  340. eq->eqn = mlx4_bitmap_alloc(&priv->eq_table.bitmap);
  341. if (eq->eqn == -1)
  342. goto err_out_free_pages;
  343. eq->doorbell = mlx4_get_eq_uar(dev, eq);
  344. if (!eq->doorbell) {
  345. err = -ENOMEM;
  346. goto err_out_free_eq;
  347. }
  348. err = mlx4_mtt_init(dev, npages, PAGE_SHIFT, &eq->mtt);
  349. if (err)
  350. goto err_out_free_eq;
  351. err = mlx4_write_mtt(dev, &eq->mtt, 0, npages, dma_list);
  352. if (err)
  353. goto err_out_free_mtt;
  354. memset(eq_context, 0, sizeof *eq_context);
  355. eq_context->flags = cpu_to_be32(MLX4_EQ_STATUS_OK |
  356. MLX4_EQ_STATE_ARMED);
  357. eq_context->log_eq_size = ilog2(eq->nent);
  358. eq_context->intr = intr;
  359. eq_context->log_page_size = PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT;
  360. mtt_addr = mlx4_mtt_addr(dev, &eq->mtt);
  361. eq_context->mtt_base_addr_h = mtt_addr >> 32;
  362. eq_context->mtt_base_addr_l = cpu_to_be32(mtt_addr & 0xffffffff);
  363. err = mlx4_SW2HW_EQ(dev, mailbox, eq->eqn);
  364. if (err) {
  365. mlx4_warn(dev, "SW2HW_EQ failed (%d)\n", err);
  366. goto err_out_free_mtt;
  367. }
  368. kfree(dma_list);
  369. mlx4_free_cmd_mailbox(dev, mailbox);
  370. eq->cons_index = 0;
  371. return err;
  372. err_out_free_mtt:
  373. mlx4_mtt_cleanup(dev, &eq->mtt);
  374. err_out_free_eq:
  375. mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn);
  376. err_out_free_pages:
  377. for (i = 0; i < npages; ++i)
  378. if (eq->page_list[i].buf)
  379. dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
  380. eq->page_list[i].buf,
  381. eq->page_list[i].map);
  382. mlx4_free_cmd_mailbox(dev, mailbox);
  383. err_out_free:
  384. kfree(eq->page_list);
  385. kfree(dma_list);
  386. err_out:
  387. return err;
  388. }
  389. static void mlx4_free_eq(struct mlx4_dev *dev,
  390. struct mlx4_eq *eq)
  391. {
  392. struct mlx4_priv *priv = mlx4_priv(dev);
  393. struct mlx4_cmd_mailbox *mailbox;
  394. int err;
  395. int npages = PAGE_ALIGN(MLX4_EQ_ENTRY_SIZE * eq->nent) / PAGE_SIZE;
  396. int i;
  397. mailbox = mlx4_alloc_cmd_mailbox(dev);
  398. if (IS_ERR(mailbox))
  399. return;
  400. err = mlx4_HW2SW_EQ(dev, mailbox, eq->eqn);
  401. if (err)
  402. mlx4_warn(dev, "HW2SW_EQ failed (%d)\n", err);
  403. if (0) {
  404. mlx4_dbg(dev, "Dumping EQ context %02x:\n", eq->eqn);
  405. for (i = 0; i < sizeof (struct mlx4_eq_context) / 4; ++i) {
  406. if (i % 4 == 0)
  407. printk("[%02x] ", i * 4);
  408. printk(" %08x", be32_to_cpup(mailbox->buf + i * 4));
  409. if ((i + 1) % 4 == 0)
  410. printk("\n");
  411. }
  412. }
  413. mlx4_mtt_cleanup(dev, &eq->mtt);
  414. for (i = 0; i < npages; ++i)
  415. pci_free_consistent(dev->pdev, PAGE_SIZE,
  416. eq->page_list[i].buf,
  417. eq->page_list[i].map);
  418. kfree(eq->page_list);
  419. mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn);
  420. mlx4_free_cmd_mailbox(dev, mailbox);
  421. }
  422. static void mlx4_free_irqs(struct mlx4_dev *dev)
  423. {
  424. struct mlx4_eq_table *eq_table = &mlx4_priv(dev)->eq_table;
  425. int i;
  426. if (eq_table->have_irq)
  427. free_irq(dev->pdev->irq, dev);
  428. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  429. if (eq_table->eq[i].have_irq) {
  430. free_irq(eq_table->eq[i].irq, eq_table->eq + i);
  431. eq_table->eq[i].have_irq = 0;
  432. }
  433. kfree(eq_table->irq_names);
  434. }
  435. static int mlx4_map_clr_int(struct mlx4_dev *dev)
  436. {
  437. struct mlx4_priv *priv = mlx4_priv(dev);
  438. priv->clr_base = ioremap(pci_resource_start(dev->pdev, priv->fw.clr_int_bar) +
  439. priv->fw.clr_int_base, MLX4_CLR_INT_SIZE);
  440. if (!priv->clr_base) {
  441. mlx4_err(dev, "Couldn't map interrupt clear register, aborting.\n");
  442. return -ENOMEM;
  443. }
  444. return 0;
  445. }
  446. static void mlx4_unmap_clr_int(struct mlx4_dev *dev)
  447. {
  448. struct mlx4_priv *priv = mlx4_priv(dev);
  449. iounmap(priv->clr_base);
  450. }
  451. int mlx4_alloc_eq_table(struct mlx4_dev *dev)
  452. {
  453. struct mlx4_priv *priv = mlx4_priv(dev);
  454. priv->eq_table.eq = kcalloc(dev->caps.num_eqs - dev->caps.reserved_eqs,
  455. sizeof *priv->eq_table.eq, GFP_KERNEL);
  456. if (!priv->eq_table.eq)
  457. return -ENOMEM;
  458. return 0;
  459. }
  460. void mlx4_free_eq_table(struct mlx4_dev *dev)
  461. {
  462. kfree(mlx4_priv(dev)->eq_table.eq);
  463. }
  464. int mlx4_init_eq_table(struct mlx4_dev *dev)
  465. {
  466. struct mlx4_priv *priv = mlx4_priv(dev);
  467. int err;
  468. int i;
  469. priv->eq_table.uar_map = kcalloc(sizeof *priv->eq_table.uar_map,
  470. mlx4_num_eq_uar(dev), GFP_KERNEL);
  471. if (!priv->eq_table.uar_map) {
  472. err = -ENOMEM;
  473. goto err_out_free;
  474. }
  475. err = mlx4_bitmap_init(&priv->eq_table.bitmap, dev->caps.num_eqs,
  476. dev->caps.num_eqs - 1, dev->caps.reserved_eqs, 0);
  477. if (err)
  478. goto err_out_free;
  479. for (i = 0; i < mlx4_num_eq_uar(dev); ++i)
  480. priv->eq_table.uar_map[i] = NULL;
  481. err = mlx4_map_clr_int(dev);
  482. if (err)
  483. goto err_out_bitmap;
  484. priv->eq_table.clr_mask =
  485. swab32(1 << (priv->eq_table.inta_pin & 31));
  486. priv->eq_table.clr_int = priv->clr_base +
  487. (priv->eq_table.inta_pin < 32 ? 4 : 0);
  488. priv->eq_table.irq_names =
  489. kmalloc(MLX4_IRQNAME_SIZE * (dev->caps.num_comp_vectors + 1),
  490. GFP_KERNEL);
  491. if (!priv->eq_table.irq_names) {
  492. err = -ENOMEM;
  493. goto err_out_bitmap;
  494. }
  495. for (i = 0; i < dev->caps.num_comp_vectors; ++i) {
  496. err = mlx4_create_eq(dev, dev->caps.num_cqs + MLX4_NUM_SPARE_EQE,
  497. (dev->flags & MLX4_FLAG_MSI_X) ? i : 0,
  498. &priv->eq_table.eq[i]);
  499. if (err) {
  500. --i;
  501. goto err_out_unmap;
  502. }
  503. }
  504. err = mlx4_create_eq(dev, MLX4_NUM_ASYNC_EQE + MLX4_NUM_SPARE_EQE,
  505. (dev->flags & MLX4_FLAG_MSI_X) ? dev->caps.num_comp_vectors : 0,
  506. &priv->eq_table.eq[dev->caps.num_comp_vectors]);
  507. if (err)
  508. goto err_out_comp;
  509. if (dev->flags & MLX4_FLAG_MSI_X) {
  510. const char *eq_name;
  511. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i) {
  512. if (i < dev->caps.num_comp_vectors) {
  513. snprintf(priv->eq_table.irq_names +
  514. i * MLX4_IRQNAME_SIZE,
  515. MLX4_IRQNAME_SIZE,
  516. "mlx4-comp-%d@pci:%s", i,
  517. pci_name(dev->pdev));
  518. } else {
  519. snprintf(priv->eq_table.irq_names +
  520. i * MLX4_IRQNAME_SIZE,
  521. MLX4_IRQNAME_SIZE,
  522. "mlx4-async@pci:%s",
  523. pci_name(dev->pdev));
  524. }
  525. eq_name = priv->eq_table.irq_names +
  526. i * MLX4_IRQNAME_SIZE;
  527. err = request_irq(priv->eq_table.eq[i].irq,
  528. mlx4_msi_x_interrupt, 0, eq_name,
  529. priv->eq_table.eq + i);
  530. if (err)
  531. goto err_out_async;
  532. priv->eq_table.eq[i].have_irq = 1;
  533. }
  534. } else {
  535. snprintf(priv->eq_table.irq_names,
  536. MLX4_IRQNAME_SIZE,
  537. DRV_NAME "@pci:%s",
  538. pci_name(dev->pdev));
  539. err = request_irq(dev->pdev->irq, mlx4_interrupt,
  540. IRQF_SHARED, priv->eq_table.irq_names, dev);
  541. if (err)
  542. goto err_out_async;
  543. priv->eq_table.have_irq = 1;
  544. }
  545. err = mlx4_MAP_EQ(dev, MLX4_ASYNC_EVENT_MASK, 0,
  546. priv->eq_table.eq[dev->caps.num_comp_vectors].eqn);
  547. if (err)
  548. mlx4_warn(dev, "MAP_EQ for async EQ %d failed (%d)\n",
  549. priv->eq_table.eq[dev->caps.num_comp_vectors].eqn, err);
  550. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  551. eq_set_ci(&priv->eq_table.eq[i], 1);
  552. return 0;
  553. err_out_async:
  554. mlx4_free_eq(dev, &priv->eq_table.eq[dev->caps.num_comp_vectors]);
  555. err_out_comp:
  556. i = dev->caps.num_comp_vectors - 1;
  557. err_out_unmap:
  558. while (i >= 0) {
  559. mlx4_free_eq(dev, &priv->eq_table.eq[i]);
  560. --i;
  561. }
  562. mlx4_unmap_clr_int(dev);
  563. mlx4_free_irqs(dev);
  564. err_out_bitmap:
  565. mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
  566. err_out_free:
  567. kfree(priv->eq_table.uar_map);
  568. return err;
  569. }
  570. void mlx4_cleanup_eq_table(struct mlx4_dev *dev)
  571. {
  572. struct mlx4_priv *priv = mlx4_priv(dev);
  573. int i;
  574. mlx4_MAP_EQ(dev, MLX4_ASYNC_EVENT_MASK, 1,
  575. priv->eq_table.eq[dev->caps.num_comp_vectors].eqn);
  576. mlx4_free_irqs(dev);
  577. for (i = 0; i < dev->caps.num_comp_vectors + 1; ++i)
  578. mlx4_free_eq(dev, &priv->eq_table.eq[i]);
  579. mlx4_unmap_clr_int(dev);
  580. for (i = 0; i < mlx4_num_eq_uar(dev); ++i)
  581. if (priv->eq_table.uar_map[i])
  582. iounmap(priv->eq_table.uar_map[i]);
  583. mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
  584. kfree(priv->eq_table.uar_map);
  585. }