eq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. /*
  2. * Copyright (c) 2005 Mellanox Technologies. All rights reserved.
  3. * Copyright (c) 2005, 2006, 2007 Cisco Systems, Inc. All rights reserved.
  4. *
  5. * This software is available to you under a choice of one of two
  6. * licenses. You may choose to be licensed under the terms of the GNU
  7. * General Public License (GPL) Version 2, available from the file
  8. * COPYING in the main directory of this source tree, or the
  9. * OpenIB.org BSD license below:
  10. *
  11. * Redistribution and use in source and binary forms, with or
  12. * without modification, are permitted provided that the following
  13. * conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above
  16. * copyright notice, this list of conditions and the following
  17. * disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  25. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  27. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  28. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  29. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  30. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  31. * SOFTWARE.
  32. */
  33. #include <linux/init.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/dma-mapping.h>
  36. #include <linux/mlx4/cmd.h>
  37. #include "mlx4.h"
  38. #include "fw.h"
  39. enum {
  40. MLX4_NUM_ASYNC_EQE = 0x100,
  41. MLX4_NUM_SPARE_EQE = 0x80,
  42. MLX4_EQ_ENTRY_SIZE = 0x20
  43. };
  44. /*
  45. * Must be packed because start is 64 bits but only aligned to 32 bits.
  46. */
  47. struct mlx4_eq_context {
  48. __be32 flags;
  49. u16 reserved1[3];
  50. __be16 page_offset;
  51. u8 log_eq_size;
  52. u8 reserved2[4];
  53. u8 eq_period;
  54. u8 reserved3;
  55. u8 eq_max_count;
  56. u8 reserved4[3];
  57. u8 intr;
  58. u8 log_page_size;
  59. u8 reserved5[2];
  60. u8 mtt_base_addr_h;
  61. __be32 mtt_base_addr_l;
  62. u32 reserved6[2];
  63. __be32 consumer_index;
  64. __be32 producer_index;
  65. u32 reserved7[4];
  66. };
  67. #define MLX4_EQ_STATUS_OK ( 0 << 28)
  68. #define MLX4_EQ_STATUS_WRITE_FAIL (10 << 28)
  69. #define MLX4_EQ_OWNER_SW ( 0 << 24)
  70. #define MLX4_EQ_OWNER_HW ( 1 << 24)
  71. #define MLX4_EQ_FLAG_EC ( 1 << 18)
  72. #define MLX4_EQ_FLAG_OI ( 1 << 17)
  73. #define MLX4_EQ_STATE_ARMED ( 9 << 8)
  74. #define MLX4_EQ_STATE_FIRED (10 << 8)
  75. #define MLX4_EQ_STATE_ALWAYS_ARMED (11 << 8)
  76. #define MLX4_ASYNC_EVENT_MASK ((1ull << MLX4_EVENT_TYPE_PATH_MIG) | \
  77. (1ull << MLX4_EVENT_TYPE_COMM_EST) | \
  78. (1ull << MLX4_EVENT_TYPE_SQ_DRAINED) | \
  79. (1ull << MLX4_EVENT_TYPE_CQ_ERROR) | \
  80. (1ull << MLX4_EVENT_TYPE_WQ_CATAS_ERROR) | \
  81. (1ull << MLX4_EVENT_TYPE_EEC_CATAS_ERROR) | \
  82. (1ull << MLX4_EVENT_TYPE_PATH_MIG_FAILED) | \
  83. (1ull << MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR) | \
  84. (1ull << MLX4_EVENT_TYPE_WQ_ACCESS_ERROR) | \
  85. (1ull << MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR) | \
  86. (1ull << MLX4_EVENT_TYPE_PORT_CHANGE) | \
  87. (1ull << MLX4_EVENT_TYPE_ECC_DETECT) | \
  88. (1ull << MLX4_EVENT_TYPE_SRQ_CATAS_ERROR) | \
  89. (1ull << MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE) | \
  90. (1ull << MLX4_EVENT_TYPE_SRQ_LIMIT) | \
  91. (1ull << MLX4_EVENT_TYPE_CMD))
  92. #define MLX4_CATAS_EVENT_MASK (1ull << MLX4_EVENT_TYPE_LOCAL_CATAS_ERROR)
  93. struct mlx4_eqe {
  94. u8 reserved1;
  95. u8 type;
  96. u8 reserved2;
  97. u8 subtype;
  98. union {
  99. u32 raw[6];
  100. struct {
  101. __be32 cqn;
  102. } __attribute__((packed)) comp;
  103. struct {
  104. u16 reserved1;
  105. __be16 token;
  106. u32 reserved2;
  107. u8 reserved3[3];
  108. u8 status;
  109. __be64 out_param;
  110. } __attribute__((packed)) cmd;
  111. struct {
  112. __be32 qpn;
  113. } __attribute__((packed)) qp;
  114. struct {
  115. __be32 srqn;
  116. } __attribute__((packed)) srq;
  117. struct {
  118. __be32 cqn;
  119. u32 reserved1;
  120. u8 reserved2[3];
  121. u8 syndrome;
  122. } __attribute__((packed)) cq_err;
  123. struct {
  124. u32 reserved1[2];
  125. __be32 port;
  126. } __attribute__((packed)) port_change;
  127. } event;
  128. u8 reserved3[3];
  129. u8 owner;
  130. } __attribute__((packed));
  131. static void eq_set_ci(struct mlx4_eq *eq, int req_not)
  132. {
  133. __raw_writel((__force u32) cpu_to_be32((eq->cons_index & 0xffffff) |
  134. req_not << 31),
  135. eq->doorbell);
  136. /* We still want ordering, just not swabbing, so add a barrier */
  137. mb();
  138. }
  139. static struct mlx4_eqe *get_eqe(struct mlx4_eq *eq, u32 entry)
  140. {
  141. unsigned long off = (entry & (eq->nent - 1)) * MLX4_EQ_ENTRY_SIZE;
  142. return eq->page_list[off / PAGE_SIZE].buf + off % PAGE_SIZE;
  143. }
  144. static struct mlx4_eqe *next_eqe_sw(struct mlx4_eq *eq)
  145. {
  146. struct mlx4_eqe *eqe = get_eqe(eq, eq->cons_index);
  147. return !!(eqe->owner & 0x80) ^ !!(eq->cons_index & eq->nent) ? NULL : eqe;
  148. }
  149. static int mlx4_eq_int(struct mlx4_dev *dev, struct mlx4_eq *eq)
  150. {
  151. struct mlx4_eqe *eqe;
  152. int cqn;
  153. int eqes_found = 0;
  154. int set_ci = 0;
  155. while ((eqe = next_eqe_sw(eq))) {
  156. /*
  157. * Make sure we read EQ entry contents after we've
  158. * checked the ownership bit.
  159. */
  160. rmb();
  161. switch (eqe->type) {
  162. case MLX4_EVENT_TYPE_COMP:
  163. cqn = be32_to_cpu(eqe->event.comp.cqn) & 0xffffff;
  164. mlx4_cq_completion(dev, cqn);
  165. break;
  166. case MLX4_EVENT_TYPE_PATH_MIG:
  167. case MLX4_EVENT_TYPE_COMM_EST:
  168. case MLX4_EVENT_TYPE_SQ_DRAINED:
  169. case MLX4_EVENT_TYPE_SRQ_QP_LAST_WQE:
  170. case MLX4_EVENT_TYPE_WQ_CATAS_ERROR:
  171. case MLX4_EVENT_TYPE_PATH_MIG_FAILED:
  172. case MLX4_EVENT_TYPE_WQ_INVAL_REQ_ERROR:
  173. case MLX4_EVENT_TYPE_WQ_ACCESS_ERROR:
  174. mlx4_qp_event(dev, be32_to_cpu(eqe->event.qp.qpn) & 0xffffff,
  175. eqe->type);
  176. break;
  177. case MLX4_EVENT_TYPE_SRQ_LIMIT:
  178. case MLX4_EVENT_TYPE_SRQ_CATAS_ERROR:
  179. mlx4_srq_event(dev, be32_to_cpu(eqe->event.srq.srqn) & 0xffffff,
  180. eqe->type);
  181. break;
  182. case MLX4_EVENT_TYPE_CMD:
  183. mlx4_cmd_event(dev,
  184. be16_to_cpu(eqe->event.cmd.token),
  185. eqe->event.cmd.status,
  186. be64_to_cpu(eqe->event.cmd.out_param));
  187. break;
  188. case MLX4_EVENT_TYPE_PORT_CHANGE:
  189. mlx4_dispatch_event(dev, eqe->type, eqe->subtype,
  190. be32_to_cpu(eqe->event.port_change.port) >> 28);
  191. break;
  192. case MLX4_EVENT_TYPE_CQ_ERROR:
  193. mlx4_warn(dev, "CQ %s on CQN %06x\n",
  194. eqe->event.cq_err.syndrome == 1 ?
  195. "overrun" : "access violation",
  196. be32_to_cpu(eqe->event.cq_err.cqn) & 0xffffff);
  197. mlx4_cq_event(dev, be32_to_cpu(eqe->event.cq_err.cqn),
  198. eqe->type);
  199. break;
  200. case MLX4_EVENT_TYPE_EQ_OVERFLOW:
  201. mlx4_warn(dev, "EQ overrun on EQN %d\n", eq->eqn);
  202. break;
  203. case MLX4_EVENT_TYPE_EEC_CATAS_ERROR:
  204. case MLX4_EVENT_TYPE_ECC_DETECT:
  205. default:
  206. mlx4_warn(dev, "Unhandled event %02x(%02x) on EQ %d at index %u\n",
  207. eqe->type, eqe->subtype, eq->eqn, eq->cons_index);
  208. break;
  209. };
  210. ++eq->cons_index;
  211. eqes_found = 1;
  212. ++set_ci;
  213. /*
  214. * The HCA will think the queue has overflowed if we
  215. * don't tell it we've been processing events. We
  216. * create our EQs with MLX4_NUM_SPARE_EQE extra
  217. * entries, so we must update our consumer index at
  218. * least that often.
  219. */
  220. if (unlikely(set_ci >= MLX4_NUM_SPARE_EQE)) {
  221. /*
  222. * Conditional on hca_type is OK here because
  223. * this is a rare case, not the fast path.
  224. */
  225. eq_set_ci(eq, 0);
  226. set_ci = 0;
  227. }
  228. }
  229. eq_set_ci(eq, 1);
  230. return eqes_found;
  231. }
  232. static irqreturn_t mlx4_interrupt(int irq, void *dev_ptr)
  233. {
  234. struct mlx4_dev *dev = dev_ptr;
  235. struct mlx4_priv *priv = mlx4_priv(dev);
  236. int work = 0;
  237. int i;
  238. writel(priv->eq_table.clr_mask, priv->eq_table.clr_int);
  239. for (i = 0; i < MLX4_EQ_CATAS; ++i)
  240. work |= mlx4_eq_int(dev, &priv->eq_table.eq[i]);
  241. return IRQ_RETVAL(work);
  242. }
  243. static irqreturn_t mlx4_msi_x_interrupt(int irq, void *eq_ptr)
  244. {
  245. struct mlx4_eq *eq = eq_ptr;
  246. struct mlx4_dev *dev = eq->dev;
  247. mlx4_eq_int(dev, eq);
  248. /* MSI-X vectors always belong to us */
  249. return IRQ_HANDLED;
  250. }
  251. static irqreturn_t mlx4_catas_interrupt(int irq, void *dev_ptr)
  252. {
  253. mlx4_handle_catas_err(dev_ptr);
  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 void __devinit __iomem *mlx4_get_eq_uar(struct mlx4_dev *dev,
  276. struct mlx4_eq *eq)
  277. {
  278. struct mlx4_priv *priv = mlx4_priv(dev);
  279. int index;
  280. index = eq->eqn / 4 - dev->caps.reserved_eqs / 4;
  281. if (!priv->eq_table.uar_map[index]) {
  282. priv->eq_table.uar_map[index] =
  283. ioremap(pci_resource_start(dev->pdev, 2) +
  284. ((eq->eqn / 4) << PAGE_SHIFT),
  285. PAGE_SIZE);
  286. if (!priv->eq_table.uar_map[index]) {
  287. mlx4_err(dev, "Couldn't map EQ doorbell for EQN 0x%06x\n",
  288. eq->eqn);
  289. return NULL;
  290. }
  291. }
  292. return priv->eq_table.uar_map[index] + 0x800 + 8 * (eq->eqn % 4);
  293. }
  294. static int __devinit mlx4_create_eq(struct mlx4_dev *dev, int nent,
  295. u8 intr, struct mlx4_eq *eq)
  296. {
  297. struct mlx4_priv *priv = mlx4_priv(dev);
  298. struct mlx4_cmd_mailbox *mailbox;
  299. struct mlx4_eq_context *eq_context;
  300. int npages;
  301. u64 *dma_list = NULL;
  302. dma_addr_t t;
  303. u64 mtt_addr;
  304. int err = -ENOMEM;
  305. int i;
  306. eq->dev = dev;
  307. eq->nent = roundup_pow_of_two(max(nent, 2));
  308. npages = PAGE_ALIGN(eq->nent * MLX4_EQ_ENTRY_SIZE) / PAGE_SIZE;
  309. eq->page_list = kmalloc(npages * sizeof *eq->page_list,
  310. GFP_KERNEL);
  311. if (!eq->page_list)
  312. goto err_out;
  313. for (i = 0; i < npages; ++i)
  314. eq->page_list[i].buf = NULL;
  315. dma_list = kmalloc(npages * sizeof *dma_list, GFP_KERNEL);
  316. if (!dma_list)
  317. goto err_out_free;
  318. mailbox = mlx4_alloc_cmd_mailbox(dev);
  319. if (IS_ERR(mailbox))
  320. goto err_out_free;
  321. eq_context = mailbox->buf;
  322. for (i = 0; i < npages; ++i) {
  323. eq->page_list[i].buf = dma_alloc_coherent(&dev->pdev->dev,
  324. PAGE_SIZE, &t, GFP_KERNEL);
  325. if (!eq->page_list[i].buf)
  326. goto err_out_free_pages;
  327. dma_list[i] = t;
  328. eq->page_list[i].map = t;
  329. memset(eq->page_list[i].buf, 0, PAGE_SIZE);
  330. }
  331. eq->eqn = mlx4_bitmap_alloc(&priv->eq_table.bitmap);
  332. if (eq->eqn == -1)
  333. goto err_out_free_pages;
  334. eq->doorbell = mlx4_get_eq_uar(dev, eq);
  335. if (!eq->doorbell) {
  336. err = -ENOMEM;
  337. goto err_out_free_eq;
  338. }
  339. err = mlx4_mtt_init(dev, npages, PAGE_SHIFT, &eq->mtt);
  340. if (err)
  341. goto err_out_free_eq;
  342. err = mlx4_write_mtt(dev, &eq->mtt, 0, npages, dma_list);
  343. if (err)
  344. goto err_out_free_mtt;
  345. memset(eq_context, 0, sizeof *eq_context);
  346. eq_context->flags = cpu_to_be32(MLX4_EQ_STATUS_OK |
  347. MLX4_EQ_STATE_ARMED);
  348. eq_context->log_eq_size = ilog2(eq->nent);
  349. eq_context->intr = intr;
  350. eq_context->log_page_size = PAGE_SHIFT - MLX4_ICM_PAGE_SHIFT;
  351. mtt_addr = mlx4_mtt_addr(dev, &eq->mtt);
  352. eq_context->mtt_base_addr_h = mtt_addr >> 32;
  353. eq_context->mtt_base_addr_l = cpu_to_be32(mtt_addr & 0xffffffff);
  354. err = mlx4_SW2HW_EQ(dev, mailbox, eq->eqn);
  355. if (err) {
  356. mlx4_warn(dev, "SW2HW_EQ failed (%d)\n", err);
  357. goto err_out_free_mtt;
  358. }
  359. kfree(dma_list);
  360. mlx4_free_cmd_mailbox(dev, mailbox);
  361. eq->cons_index = 0;
  362. return err;
  363. err_out_free_mtt:
  364. mlx4_mtt_cleanup(dev, &eq->mtt);
  365. err_out_free_eq:
  366. mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn);
  367. err_out_free_pages:
  368. for (i = 0; i < npages; ++i)
  369. if (eq->page_list[i].buf)
  370. dma_free_coherent(&dev->pdev->dev, PAGE_SIZE,
  371. eq->page_list[i].buf,
  372. eq->page_list[i].map);
  373. mlx4_free_cmd_mailbox(dev, mailbox);
  374. err_out_free:
  375. kfree(eq->page_list);
  376. kfree(dma_list);
  377. err_out:
  378. return err;
  379. }
  380. static void mlx4_free_eq(struct mlx4_dev *dev,
  381. struct mlx4_eq *eq)
  382. {
  383. struct mlx4_priv *priv = mlx4_priv(dev);
  384. struct mlx4_cmd_mailbox *mailbox;
  385. int err;
  386. int npages = PAGE_ALIGN(MLX4_EQ_ENTRY_SIZE * eq->nent) / PAGE_SIZE;
  387. int i;
  388. mailbox = mlx4_alloc_cmd_mailbox(dev);
  389. if (IS_ERR(mailbox))
  390. return;
  391. err = mlx4_HW2SW_EQ(dev, mailbox, eq->eqn);
  392. if (err)
  393. mlx4_warn(dev, "HW2SW_EQ failed (%d)\n", err);
  394. if (0) {
  395. mlx4_dbg(dev, "Dumping EQ context %02x:\n", eq->eqn);
  396. for (i = 0; i < sizeof (struct mlx4_eq_context) / 4; ++i) {
  397. if (i % 4 == 0)
  398. printk("[%02x] ", i * 4);
  399. printk(" %08x", be32_to_cpup(mailbox->buf + i * 4));
  400. if ((i + 1) % 4 == 0)
  401. printk("\n");
  402. }
  403. }
  404. mlx4_mtt_cleanup(dev, &eq->mtt);
  405. for (i = 0; i < npages; ++i)
  406. pci_free_consistent(dev->pdev, PAGE_SIZE,
  407. eq->page_list[i].buf,
  408. eq->page_list[i].map);
  409. kfree(eq->page_list);
  410. mlx4_bitmap_free(&priv->eq_table.bitmap, eq->eqn);
  411. mlx4_free_cmd_mailbox(dev, mailbox);
  412. }
  413. static void mlx4_free_irqs(struct mlx4_dev *dev)
  414. {
  415. struct mlx4_eq_table *eq_table = &mlx4_priv(dev)->eq_table;
  416. int i;
  417. if (eq_table->have_irq)
  418. free_irq(dev->pdev->irq, dev);
  419. for (i = 0; i < MLX4_NUM_EQ; ++i)
  420. if (eq_table->eq[i].have_irq)
  421. free_irq(eq_table->eq[i].irq, eq_table->eq + i);
  422. }
  423. static int __devinit mlx4_map_clr_int(struct mlx4_dev *dev)
  424. {
  425. struct mlx4_priv *priv = mlx4_priv(dev);
  426. priv->clr_base = ioremap(pci_resource_start(dev->pdev, priv->fw.clr_int_bar) +
  427. priv->fw.clr_int_base, MLX4_CLR_INT_SIZE);
  428. if (!priv->clr_base) {
  429. mlx4_err(dev, "Couldn't map interrupt clear register, aborting.\n");
  430. return -ENOMEM;
  431. }
  432. return 0;
  433. }
  434. static void mlx4_unmap_clr_int(struct mlx4_dev *dev)
  435. {
  436. struct mlx4_priv *priv = mlx4_priv(dev);
  437. iounmap(priv->clr_base);
  438. }
  439. int __devinit mlx4_map_eq_icm(struct mlx4_dev *dev, u64 icm_virt)
  440. {
  441. struct mlx4_priv *priv = mlx4_priv(dev);
  442. int ret;
  443. /*
  444. * We assume that mapping one page is enough for the whole EQ
  445. * context table. This is fine with all current HCAs, because
  446. * we only use 32 EQs and each EQ uses 64 bytes of context
  447. * memory, or 1 KB total.
  448. */
  449. priv->eq_table.icm_virt = icm_virt;
  450. priv->eq_table.icm_page = alloc_page(GFP_HIGHUSER);
  451. if (!priv->eq_table.icm_page)
  452. return -ENOMEM;
  453. priv->eq_table.icm_dma = pci_map_page(dev->pdev, priv->eq_table.icm_page, 0,
  454. PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
  455. if (pci_dma_mapping_error(priv->eq_table.icm_dma)) {
  456. __free_page(priv->eq_table.icm_page);
  457. return -ENOMEM;
  458. }
  459. ret = mlx4_MAP_ICM_page(dev, priv->eq_table.icm_dma, icm_virt);
  460. if (ret) {
  461. pci_unmap_page(dev->pdev, priv->eq_table.icm_dma, PAGE_SIZE,
  462. PCI_DMA_BIDIRECTIONAL);
  463. __free_page(priv->eq_table.icm_page);
  464. }
  465. return ret;
  466. }
  467. void mlx4_unmap_eq_icm(struct mlx4_dev *dev)
  468. {
  469. struct mlx4_priv *priv = mlx4_priv(dev);
  470. mlx4_UNMAP_ICM(dev, priv->eq_table.icm_virt, 1);
  471. pci_unmap_page(dev->pdev, priv->eq_table.icm_dma, PAGE_SIZE,
  472. PCI_DMA_BIDIRECTIONAL);
  473. __free_page(priv->eq_table.icm_page);
  474. }
  475. int __devinit mlx4_init_eq_table(struct mlx4_dev *dev)
  476. {
  477. struct mlx4_priv *priv = mlx4_priv(dev);
  478. int err;
  479. int i;
  480. err = mlx4_bitmap_init(&priv->eq_table.bitmap, dev->caps.num_eqs,
  481. dev->caps.num_eqs - 1, dev->caps.reserved_eqs);
  482. if (err)
  483. return err;
  484. for (i = 0; i < ARRAY_SIZE(priv->eq_table.uar_map); ++i)
  485. priv->eq_table.uar_map[i] = NULL;
  486. err = mlx4_map_clr_int(dev);
  487. if (err)
  488. goto err_out_free;
  489. priv->eq_table.clr_mask =
  490. swab32(1 << (priv->eq_table.inta_pin & 31));
  491. priv->eq_table.clr_int = priv->clr_base +
  492. (priv->eq_table.inta_pin < 32 ? 4 : 0);
  493. err = mlx4_create_eq(dev, dev->caps.num_cqs + MLX4_NUM_SPARE_EQE,
  494. (dev->flags & MLX4_FLAG_MSI_X) ? MLX4_EQ_COMP : 0,
  495. &priv->eq_table.eq[MLX4_EQ_COMP]);
  496. if (err)
  497. goto err_out_unmap;
  498. err = mlx4_create_eq(dev, MLX4_NUM_ASYNC_EQE + MLX4_NUM_SPARE_EQE,
  499. (dev->flags & MLX4_FLAG_MSI_X) ? MLX4_EQ_ASYNC : 0,
  500. &priv->eq_table.eq[MLX4_EQ_ASYNC]);
  501. if (err)
  502. goto err_out_comp;
  503. if (dev->flags & MLX4_FLAG_MSI_X) {
  504. static const char *eq_name[] = {
  505. [MLX4_EQ_COMP] = DRV_NAME " (comp)",
  506. [MLX4_EQ_ASYNC] = DRV_NAME " (async)",
  507. [MLX4_EQ_CATAS] = DRV_NAME " (catas)"
  508. };
  509. err = mlx4_create_eq(dev, 1, MLX4_EQ_CATAS,
  510. &priv->eq_table.eq[MLX4_EQ_CATAS]);
  511. if (err)
  512. goto err_out_async;
  513. for (i = 0; i < MLX4_EQ_CATAS; ++i) {
  514. err = request_irq(priv->eq_table.eq[i].irq,
  515. mlx4_msi_x_interrupt,
  516. 0, eq_name[i], priv->eq_table.eq + i);
  517. if (err)
  518. goto err_out_catas;
  519. priv->eq_table.eq[i].have_irq = 1;
  520. }
  521. err = request_irq(priv->eq_table.eq[MLX4_EQ_CATAS].irq,
  522. mlx4_catas_interrupt, 0,
  523. eq_name[MLX4_EQ_CATAS], dev);
  524. if (err)
  525. goto err_out_catas;
  526. priv->eq_table.eq[MLX4_EQ_CATAS].have_irq = 1;
  527. } else {
  528. err = request_irq(dev->pdev->irq, mlx4_interrupt,
  529. IRQF_SHARED, DRV_NAME, dev);
  530. if (err)
  531. goto err_out_async;
  532. priv->eq_table.have_irq = 1;
  533. }
  534. err = mlx4_MAP_EQ(dev, MLX4_ASYNC_EVENT_MASK, 0,
  535. priv->eq_table.eq[MLX4_EQ_ASYNC].eqn);
  536. if (err)
  537. mlx4_warn(dev, "MAP_EQ for async EQ %d failed (%d)\n",
  538. priv->eq_table.eq[MLX4_EQ_ASYNC].eqn, err);
  539. for (i = 0; i < MLX4_EQ_CATAS; ++i)
  540. eq_set_ci(&priv->eq_table.eq[i], 1);
  541. if (dev->flags & MLX4_FLAG_MSI_X) {
  542. err = mlx4_MAP_EQ(dev, MLX4_CATAS_EVENT_MASK, 0,
  543. priv->eq_table.eq[MLX4_EQ_CATAS].eqn);
  544. if (err)
  545. mlx4_warn(dev, "MAP_EQ for catas EQ %d failed (%d)\n",
  546. priv->eq_table.eq[MLX4_EQ_CATAS].eqn, err);
  547. }
  548. return 0;
  549. err_out_catas:
  550. mlx4_free_eq(dev, &priv->eq_table.eq[MLX4_EQ_CATAS]);
  551. err_out_async:
  552. mlx4_free_eq(dev, &priv->eq_table.eq[MLX4_EQ_ASYNC]);
  553. err_out_comp:
  554. mlx4_free_eq(dev, &priv->eq_table.eq[MLX4_EQ_COMP]);
  555. err_out_unmap:
  556. mlx4_unmap_clr_int(dev);
  557. mlx4_free_irqs(dev);
  558. err_out_free:
  559. mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
  560. return err;
  561. }
  562. void mlx4_cleanup_eq_table(struct mlx4_dev *dev)
  563. {
  564. struct mlx4_priv *priv = mlx4_priv(dev);
  565. int i;
  566. if (dev->flags & MLX4_FLAG_MSI_X)
  567. mlx4_MAP_EQ(dev, MLX4_CATAS_EVENT_MASK, 1,
  568. priv->eq_table.eq[MLX4_EQ_CATAS].eqn);
  569. mlx4_MAP_EQ(dev, MLX4_ASYNC_EVENT_MASK, 1,
  570. priv->eq_table.eq[MLX4_EQ_ASYNC].eqn);
  571. mlx4_free_irqs(dev);
  572. for (i = 0; i < MLX4_EQ_CATAS; ++i)
  573. mlx4_free_eq(dev, &priv->eq_table.eq[i]);
  574. if (dev->flags & MLX4_FLAG_MSI_X)
  575. mlx4_free_eq(dev, &priv->eq_table.eq[MLX4_EQ_CATAS]);
  576. mlx4_unmap_clr_int(dev);
  577. for (i = 0; i < ARRAY_SIZE(priv->eq_table.uar_map); ++i)
  578. if (priv->eq_table.uar_map[i])
  579. iounmap(priv->eq_table.uar_map[i]);
  580. mlx4_bitmap_cleanup(&priv->eq_table.bitmap);
  581. }