1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright 2014 Cisco Systems, Inc. All rights reserved.
4 #include <linux/string.h>
5 #include <linux/errno.h>
7 #include <linux/interrupt.h>
10 #include "vnic_intr.h"
11 #include "vnic_stats.h"
17 * snic_isr_msix_wq : MSIx ISR for work queue.
21 snic_isr_msix_wq(int irq
, void *data
)
23 struct snic
*snic
= data
;
24 unsigned long wq_work_done
= 0;
26 snic
->s_stats
.misc
.last_isr_time
= jiffies
;
27 atomic64_inc(&snic
->s_stats
.misc
.ack_isr_cnt
);
29 wq_work_done
= snic_wq_cmpl_handler(snic
, -1);
30 svnic_intr_return_credits(&snic
->intr
[SNIC_MSIX_WQ
],
33 1 /* reset intr timer */);
36 } /* end of snic_isr_msix_wq */
39 snic_isr_msix_io_cmpl(int irq
, void *data
)
41 struct snic
*snic
= data
;
42 unsigned long iocmpl_work_done
= 0;
44 snic
->s_stats
.misc
.last_isr_time
= jiffies
;
45 atomic64_inc(&snic
->s_stats
.misc
.cmpl_isr_cnt
);
47 iocmpl_work_done
= snic_fwcq_cmpl_handler(snic
, -1);
48 svnic_intr_return_credits(&snic
->intr
[SNIC_MSIX_IO_CMPL
],
51 1 /* reset intr timer */);
54 } /* end of snic_isr_msix_io_cmpl */
57 snic_isr_msix_err_notify(int irq
, void *data
)
59 struct snic
*snic
= data
;
61 snic
->s_stats
.misc
.last_isr_time
= jiffies
;
62 atomic64_inc(&snic
->s_stats
.misc
.errnotify_isr_cnt
);
64 svnic_intr_return_all_credits(&snic
->intr
[SNIC_MSIX_ERR_NOTIFY
]);
65 snic_log_q_error(snic
);
67 /*Handling link events */
68 snic_handle_link_event(snic
);
71 } /* end of snic_isr_msix_err_notify */
75 snic_free_intr(struct snic
*snic
)
79 /* ONLY interrupt mode MSIX is supported */
80 for (i
= 0; i
< ARRAY_SIZE(snic
->msix
); i
++) {
81 if (snic
->msix
[i
].requested
) {
82 free_irq(pci_irq_vector(snic
->pdev
, i
),
86 } /* end of snic_free_intr */
89 snic_request_intr(struct snic
*snic
)
92 enum vnic_dev_intr_mode intr_mode
;
94 intr_mode
= svnic_dev_get_intr_mode(snic
->vdev
);
95 SNIC_BUG_ON(intr_mode
!= VNIC_DEV_INTR_MODE_MSIX
);
98 * Currently HW supports single WQ and CQ. So passing devid as snic.
99 * When hardware supports multiple WQs and CQs, one idea is
100 * to pass devid as corresponding WQ or CQ ptr and retrieve snic
102 * Except for err_notify, which is always one.
104 sprintf(snic
->msix
[SNIC_MSIX_WQ
].devname
,
107 snic
->msix
[SNIC_MSIX_WQ
].isr
= snic_isr_msix_wq
;
108 snic
->msix
[SNIC_MSIX_WQ
].devid
= snic
;
110 sprintf(snic
->msix
[SNIC_MSIX_IO_CMPL
].devname
,
113 snic
->msix
[SNIC_MSIX_IO_CMPL
].isr
= snic_isr_msix_io_cmpl
;
114 snic
->msix
[SNIC_MSIX_IO_CMPL
].devid
= snic
;
116 sprintf(snic
->msix
[SNIC_MSIX_ERR_NOTIFY
].devname
,
119 snic
->msix
[SNIC_MSIX_ERR_NOTIFY
].isr
= snic_isr_msix_err_notify
;
120 snic
->msix
[SNIC_MSIX_ERR_NOTIFY
].devid
= snic
;
122 for (i
= 0; i
< ARRAY_SIZE(snic
->msix
); i
++) {
123 ret
= request_irq(pci_irq_vector(snic
->pdev
, i
),
126 snic
->msix
[i
].devname
,
127 snic
->msix
[i
].devid
);
129 SNIC_HOST_ERR(snic
->shost
,
130 "MSI-X: request_irq(%d) failed %d\n",
133 snic_free_intr(snic
);
136 snic
->msix
[i
].requested
= 1;
140 } /* end of snic_request_intr */
143 snic_set_intr_mode(struct snic
*snic
)
145 unsigned int n
= ARRAY_SIZE(snic
->wq
);
146 unsigned int m
= SNIC_CQ_IO_CMPL_MAX
;
147 unsigned int vecs
= n
+ m
+ 1;
150 * We need n WQs, m CQs, and n+m+1 INTRs
151 * (last INTR is used for WQ/CQ errors and notification area
153 BUILD_BUG_ON((ARRAY_SIZE(snic
->wq
) + SNIC_CQ_IO_CMPL_MAX
) >
154 ARRAY_SIZE(snic
->intr
));
156 if (snic
->wq_count
< n
|| snic
->cq_count
< n
+ m
)
159 if (pci_alloc_irq_vectors(snic
->pdev
, vecs
, vecs
, PCI_IRQ_MSIX
) < 0)
163 snic
->cq_count
= n
+ m
;
164 snic
->intr_count
= vecs
;
165 snic
->err_intr_offset
= SNIC_MSIX_ERR_NOTIFY
;
167 SNIC_ISR_DBG(snic
->shost
, "Using MSI-X Interrupts\n");
168 svnic_dev_set_intr_mode(snic
->vdev
, VNIC_DEV_INTR_MODE_MSIX
);
171 svnic_dev_set_intr_mode(snic
->vdev
, VNIC_DEV_INTR_MODE_UNKNOWN
);
173 } /* end of snic_set_intr_mode */
176 snic_clear_intr_mode(struct snic
*snic
)
178 pci_free_irq_vectors(snic
->pdev
);
179 svnic_dev_set_intr_mode(snic
->vdev
, VNIC_DEV_INTR_MODE_INTX
);