8 #include <linux/kernel.h>
25 static u64 msi_free_irq_bitmask[4];
33 static u64 msi_multiple_irq_bitmask[4];
45 static int msi_irq_size;
63 int configured_private_bits;
64 int request_private_bits;
85 if (configured_private_bits == 0) {
94 request_private_bits = configured_private_bits;
101 if (request_private_bits > 5)
102 request_private_bits = 0;
109 irq_step = 1 << request_private_bits;
112 search_mask = (1 << irq_step) - 1;
119 spin_lock(&msi_free_irq_bitmask_lock);
120 for (index = 0; index < msi_irq_size/64; index++) {
121 for (irq = 0; irq < 64; irq += irq_step) {
122 if ((msi_free_irq_bitmask[index] & (search_mask << irq)) == 0) {
123 msi_free_irq_bitmask[
index] |= search_mask << irq;
124 msi_multiple_irq_bitmask[
index] |= (search_mask >> 1) << irq;
125 goto msi_irq_allocated;
130 spin_unlock(&msi_free_irq_bitmask_lock);
134 if (request_private_bits) {
135 pr_err(
"arch_setup_msi_irq: Unable to find %d free interrupts, trying just one",
136 1 << request_private_bits);
137 request_private_bits = 0;
140 panic(
"arch_setup_msi_irq: Unable to find a free MSI interrupt");
145 irq += OCTEON_IRQ_MSI_BIT0;
152 msg.
address_hi = ((128ul << 20) + CVMX_PCI_MSI_RCV) >> 32;
165 panic(
"arch_setup_msi_irq: Invalid octeon_dma_bar_type");
167 msg.
data = irq - OCTEON_IRQ_MSI_BIT0;
171 control |= request_private_bits << 4;
222 if ((irq < OCTEON_IRQ_MSI_BIT0)
223 || (irq > msi_irq_size + OCTEON_IRQ_MSI_BIT0))
224 panic(
"arch_teardown_msi_irq: Attempted to teardown illegal "
225 "MSI interrupt (%d)", irq);
227 irq -= OCTEON_IRQ_MSI_BIT0;
237 while ((irq0 + number_irqs < 64) &&
238 (msi_multiple_irq_bitmask[index]
239 & (1ull << (irq0 + number_irqs))))
243 bitmask = (1 << number_irqs) - 1;
246 if ((msi_free_irq_bitmask[index] & bitmask) !=
bitmask)
247 panic(
"arch_teardown_msi_irq: Attempted to teardown MSI "
248 "interrupt (%d) not in use", irq);
251 spin_lock(&msi_free_irq_bitmask_lock);
252 msi_free_irq_bitmask[
index] &= ~bitmask;
253 msi_multiple_irq_bitmask[
index] &= ~bitmask;
254 spin_unlock(&msi_free_irq_bitmask_lock);
259 static u64 msi_rcv_reg[4];
260 static u64 mis_ena_reg[4];
262 static void octeon_irq_msi_enable_pcie(
struct irq_data *
data)
266 int msi_number = data->
irq - OCTEON_IRQ_MSI_BIT0;
267 int irq_index = msi_number >> 6;
268 int irq_bit = msi_number & 0x3f;
271 en = cvmx_read_csr(mis_ena_reg[irq_index]);
272 en |= 1ull << irq_bit;
273 cvmx_write_csr(mis_ena_reg[irq_index], en);
274 cvmx_read_csr(mis_ena_reg[irq_index]);
278 static void octeon_irq_msi_disable_pcie(
struct irq_data *
data)
282 int msi_number = data->
irq - OCTEON_IRQ_MSI_BIT0;
283 int irq_index = msi_number >> 6;
284 int irq_bit = msi_number & 0x3f;
287 en = cvmx_read_csr(mis_ena_reg[irq_index]);
288 en &= ~(1ull << irq_bit);
289 cvmx_write_csr(mis_ena_reg[irq_index], en);
290 cvmx_read_csr(mis_ena_reg[irq_index]);
294 static struct irq_chip octeon_irq_chip_msi_pcie = {
296 .irq_enable = octeon_irq_msi_enable_pcie,
297 .irq_disable = octeon_irq_msi_disable_pcie,
300 static void octeon_irq_msi_enable_pci(
struct irq_data *
data)
311 static void octeon_irq_msi_disable_pci(
struct irq_data *
data)
316 static struct irq_chip octeon_irq_chip_msi_pci = {
318 .irq_enable = octeon_irq_msi_enable_pci,
319 .irq_disable = octeon_irq_msi_disable_pci,
331 bit = fls64(msi_bits);
335 cvmx_write_csr(msi_rcv_reg[index], 1ull << bit);
337 irq = bit + OCTEON_IRQ_MSI_BIT0 + 64 *
index;
344 #define OCTEON_MSI_INT_HANDLER_X(x) \
345 static irqreturn_t octeon_msi_interrupt##x(int cpl, void *dev_id) \
347 u64 msi_bits = cvmx_read_csr(msi_rcv_reg[(x)]); \
348 return __octeon_msi_do_interrupt((x), msi_bits); \
376 msi = &octeon_irq_chip_msi_pcie;
379 #define INVALID_GENERATE_ADE 0x8700000000000000ULL;
387 msi = &octeon_irq_chip_msi_pci;
390 for (irq = OCTEON_IRQ_MSI_BIT0; irq <= OCTEON_IRQ_MSI_LAST; irq++)
395 0,
"MSI[0:63]", octeon_msi_interrupt0))
396 panic(
"request_irq(OCTEON_IRQ_PCI_MSI0) failed");
399 0,
"MSI[64:127]", octeon_msi_interrupt1))
400 panic(
"request_irq(OCTEON_IRQ_PCI_MSI1) failed");
403 0,
"MSI[127:191]", octeon_msi_interrupt2))
404 panic(
"request_irq(OCTEON_IRQ_PCI_MSI2) failed");
407 0,
"MSI[192:255]", octeon_msi_interrupt3))
408 panic(
"request_irq(OCTEON_IRQ_PCI_MSI3) failed");
413 0,
"MSI[0:15]", octeon_msi_interrupt0))
414 panic(
"request_irq(OCTEON_IRQ_PCI_MSI0) failed");
417 0,
"MSI[16:31]", octeon_msi_interrupt0))
418 panic(
"request_irq(OCTEON_IRQ_PCI_MSI1) failed");
421 0,
"MSI[32:47]", octeon_msi_interrupt0))
422 panic(
"request_irq(OCTEON_IRQ_PCI_MSI2) failed");
425 0,
"MSI[48:63]", octeon_msi_interrupt0))
426 panic(
"request_irq(OCTEON_IRQ_PCI_MSI3) failed");