5656#include <asm/netlogic/xlp-hal/bridge.h>
5757
5858#define XLP_MSIVEC_PER_LINK 32
59- #define XLP_MSIXVEC_TOTAL 32
60- #define XLP_MSIXVEC_PER_LINK 8
59+ #define XLP_MSIXVEC_TOTAL (cpu_is_xlp9xx() ? 128 : 32)
60+ #define XLP_MSIXVEC_PER_LINK (cpu_is_xlp9xx() ? 32 : 8)
6161
6262/* 128 MSI irqs per node, mapped starting at NLM_MSI_VEC_BASE */
6363static inline int nlm_link_msiirq (int link , int msivec )
6464{
6565 return NLM_MSI_VEC_BASE + link * XLP_MSIVEC_PER_LINK + msivec ;
6666}
6767
68+ /* get the link MSI vector from irq number */
6869static inline int nlm_irq_msivec (int irq )
6970{
70- return irq % XLP_MSIVEC_PER_LINK ;
71+ return ( irq - NLM_MSI_VEC_BASE ) % XLP_MSIVEC_PER_LINK ;
7172}
7273
74+ /* get the link from the irq number */
7375static inline int nlm_irq_msilink (int irq )
7476{
75- return (irq % (XLP_MSIVEC_PER_LINK * PCIE_NLINKS )) /
76- XLP_MSIVEC_PER_LINK ;
77+ int total_msivec = XLP_MSIVEC_PER_LINK * PCIE_NLINKS ;
78+
79+ return ((irq - NLM_MSI_VEC_BASE ) % total_msivec ) /
80+ XLP_MSIVEC_PER_LINK ;
7781}
7882
7983/*
80- * Only 32 MSI-X vectors are possible because there are only 32 PIC
81- * interrupts for MSI. We split them statically and use 8 MSI-X vectors
82- * per link - this keeps the allocation and lookup simple.
84+ * For XLP 8xx/4xx/3xx/2xx, only 32 MSI-X vectors are possible because
85+ * there are only 32 PIC interrupts for MSI. We split them statically
86+ * and use 8 MSI-X vectors per link - this keeps the allocation and
87+ * lookup simple.
88+ * On XLP 9xx, there are 32 vectors per link, and the interrupts are
89+ * not routed thru PIC, so we can use all 128 MSI-X vectors.
8390 */
8491static inline int nlm_link_msixirq (int link , int bit )
8592{
8693 return NLM_MSIX_VEC_BASE + link * XLP_MSIXVEC_PER_LINK + bit ;
8794}
8895
96+ /* get the link MSI vector from irq number */
8997static inline int nlm_irq_msixvec (int irq )
9098{
91- return irq % XLP_MSIXVEC_TOTAL ; /* works when given xirq */
99+ return ( irq - NLM_MSIX_VEC_BASE ) % XLP_MSIXVEC_TOTAL ;
92100}
93101
94- static inline int nlm_irq_msixlink (int irq )
102+ /* get the link from MSIX vec */
103+ static inline int nlm_irq_msixlink (int msixvec )
95104{
96- return nlm_irq_msixvec ( irq ) / XLP_MSIXVEC_PER_LINK ;
105+ return msixvec / XLP_MSIXVEC_PER_LINK ;
97106}
98107
99108/*
@@ -129,7 +138,11 @@ static void xlp_msi_enable(struct irq_data *d)
129138 vec = nlm_irq_msivec (d -> irq );
130139 spin_lock_irqsave (& md -> msi_lock , flags );
131140 md -> msi_enabled_mask |= 1u << vec ;
132- nlm_write_reg (md -> lnkbase , PCIE_MSI_EN , md -> msi_enabled_mask );
141+ if (cpu_is_xlp9xx ())
142+ nlm_write_reg (md -> lnkbase , PCIE_9XX_MSI_EN ,
143+ md -> msi_enabled_mask );
144+ else
145+ nlm_write_reg (md -> lnkbase , PCIE_MSI_EN , md -> msi_enabled_mask );
133146 spin_unlock_irqrestore (& md -> msi_lock , flags );
134147}
135148
@@ -142,7 +155,11 @@ static void xlp_msi_disable(struct irq_data *d)
142155 vec = nlm_irq_msivec (d -> irq );
143156 spin_lock_irqsave (& md -> msi_lock , flags );
144157 md -> msi_enabled_mask &= ~(1u << vec );
145- nlm_write_reg (md -> lnkbase , PCIE_MSI_EN , md -> msi_enabled_mask );
158+ if (cpu_is_xlp9xx ())
159+ nlm_write_reg (md -> lnkbase , PCIE_9XX_MSI_EN ,
160+ md -> msi_enabled_mask );
161+ else
162+ nlm_write_reg (md -> lnkbase , PCIE_MSI_EN , md -> msi_enabled_mask );
146163 spin_unlock_irqrestore (& md -> msi_lock , flags );
147164}
148165
@@ -156,11 +173,18 @@ static void xlp_msi_mask_ack(struct irq_data *d)
156173 xlp_msi_disable (d );
157174
158175 /* Ack MSI on bridge */
159- nlm_write_reg (md -> lnkbase , PCIE_MSI_STATUS , 1u << vec );
176+ if (cpu_is_xlp9xx ())
177+ nlm_write_reg (md -> lnkbase , PCIE_9XX_MSI_STATUS , 1u << vec );
178+ else
179+ nlm_write_reg (md -> lnkbase , PCIE_MSI_STATUS , 1u << vec );
160180
161181 /* Ack at eirr and PIC */
162182 ack_c0_eirr (PIC_PCIE_LINK_MSI_IRQ (link ));
163- nlm_pic_ack (md -> node -> picbase , PIC_IRT_PCIE_LINK_INDEX (link ));
183+ if (cpu_is_xlp9xx ())
184+ nlm_pic_ack (md -> node -> picbase ,
185+ PIC_9XX_IRT_PCIE_LINK_INDEX (link ));
186+ else
187+ nlm_pic_ack (md -> node -> picbase , PIC_IRT_PCIE_LINK_INDEX (link ));
164188}
165189
166190static struct irq_chip xlp_msi_chip = {
@@ -172,30 +196,45 @@ static struct irq_chip xlp_msi_chip = {
172196};
173197
174198/*
175- * The MSI-X interrupt handling is different from MSI, there are 32
176- * MSI-X interrupts generated by the PIC and each of these correspond
177- * to a MSI-X vector (0-31) that can be assigned.
199+ * XLP8XX/4XX/3XX/2XX:
200+ * The MSI-X interrupt handling is different from MSI, there are 32 MSI-X
201+ * interrupts generated by the PIC and each of these correspond to a MSI-X
202+ * vector (0-31) that can be assigned.
178203 *
179- * We divide the MSI-X vectors to 8 per link and do a per-link
180- * allocation
204+ * We divide the MSI-X vectors to 8 per link and do a per-link allocation
205+ *
206+ * XLP9XX:
207+ * 32 MSI-X vectors are available per link, and the interrupts are not routed
208+ * thru the PIC. PIC ack not needed.
181209 *
182210 * Enable and disable done using standard MSI functions.
183211 */
184212static void xlp_msix_mask_ack (struct irq_data * d )
185213{
186- struct xlp_msi_data * md = irq_data_get_irq_handler_data ( d ) ;
214+ struct xlp_msi_data * md ;
187215 int link , msixvec ;
216+ uint32_t status_reg , bit ;
188217
189218 msixvec = nlm_irq_msixvec (d -> irq );
190- link = nlm_irq_msixlink (d -> irq );
219+ link = nlm_irq_msixlink (msixvec );
191220 mask_msi_irq (d );
221+ md = irq_data_get_irq_handler_data (d );
192222
193223 /* Ack MSI on bridge */
194- nlm_write_reg (md -> lnkbase , PCIE_MSIX_STATUS , 1u << msixvec );
224+ if (cpu_is_xlp9xx ()) {
225+ status_reg = PCIE_9XX_MSIX_STATUSX (link );
226+ bit = msixvec % XLP_MSIXVEC_PER_LINK ;
227+ } else {
228+ status_reg = PCIE_MSIX_STATUS ;
229+ bit = msixvec ;
230+ }
231+ nlm_write_reg (md -> lnkbase , status_reg , 1u << bit );
195232
196233 /* Ack at eirr and PIC */
197234 ack_c0_eirr (PIC_PCIE_MSIX_IRQ (link ));
198- nlm_pic_ack (md -> node -> picbase , PIC_IRT_PCIE_MSIX_INDEX (msixvec ));
235+ if (!cpu_is_xlp9xx ())
236+ nlm_pic_ack (md -> node -> picbase ,
237+ PIC_IRT_PCIE_MSIX_INDEX (msixvec ));
199238}
200239
201240static struct irq_chip xlp_msix_chip = {
@@ -225,10 +264,18 @@ static void xlp_config_link_msi(uint64_t lnkbase, int lirq, uint64_t msiaddr)
225264{
226265 u32 val ;
227266
228- val = nlm_read_reg (lnkbase , PCIE_INT_EN0 );
229- if ((val & 0x200 ) == 0 ) {
230- val |= 0x200 ; /* MSI Interrupt enable */
231- nlm_write_reg (lnkbase , PCIE_INT_EN0 , val );
267+ if (cpu_is_xlp9xx ()) {
268+ val = nlm_read_reg (lnkbase , PCIE_9XX_INT_EN0 );
269+ if ((val & 0x200 ) == 0 ) {
270+ val |= 0x200 ; /* MSI Interrupt enable */
271+ nlm_write_reg (lnkbase , PCIE_9XX_INT_EN0 , val );
272+ }
273+ } else {
274+ val = nlm_read_reg (lnkbase , PCIE_INT_EN0 );
275+ if ((val & 0x200 ) == 0 ) {
276+ val |= 0x200 ;
277+ nlm_write_reg (lnkbase , PCIE_INT_EN0 , val );
278+ }
232279 }
233280
234281 val = nlm_read_reg (lnkbase , 0x1 ); /* CMD */
@@ -275,9 +322,12 @@ static int xlp_setup_msi(uint64_t lnkbase, int node, int link,
275322
276323 spin_lock_irqsave (& md -> msi_lock , flags );
277324 if (md -> msi_alloc_mask == 0 ) {
278- /* switch the link IRQ to MSI range */
279325 xlp_config_link_msi (lnkbase , lirq , msiaddr );
280- irt = PIC_IRT_PCIE_LINK_INDEX (link );
326+ /* switch the link IRQ to MSI range */
327+ if (cpu_is_xlp9xx ())
328+ irt = PIC_9XX_IRT_PCIE_LINK_INDEX (link );
329+ else
330+ irt = PIC_IRT_PCIE_LINK_INDEX (link );
281331 nlm_setup_pic_irq (node , lirq , lirq , irt );
282332 nlm_pic_init_irt (nlm_get_node (node )-> picbase , irt , lirq ,
283333 node * nlm_threads_per_node (), 1 /*en */ );
@@ -319,10 +369,19 @@ static void xlp_config_link_msix(uint64_t lnkbase, int lirq, uint64_t msixaddr)
319369 val |= 0x80000000U ;
320370 nlm_write_reg (lnkbase , 0x2C , val );
321371 }
322- val = nlm_read_reg (lnkbase , PCIE_INT_EN0 );
323- if ((val & 0x200 ) == 0 ) {
324- val |= 0x200 ; /* MSI Interrupt enable */
325- nlm_write_reg (lnkbase , PCIE_INT_EN0 , val );
372+
373+ if (cpu_is_xlp9xx ()) {
374+ val = nlm_read_reg (lnkbase , PCIE_9XX_INT_EN0 );
375+ if ((val & 0x200 ) == 0 ) {
376+ val |= 0x200 ; /* MSI Interrupt enable */
377+ nlm_write_reg (lnkbase , PCIE_9XX_INT_EN0 , val );
378+ }
379+ } else {
380+ val = nlm_read_reg (lnkbase , PCIE_INT_EN0 );
381+ if ((val & 0x200 ) == 0 ) {
382+ val |= 0x200 ; /* MSI Interrupt enable */
383+ nlm_write_reg (lnkbase , PCIE_INT_EN0 , val );
384+ }
326385 }
327386
328387 val = nlm_read_reg (lnkbase , 0x1 ); /* CMD */
@@ -337,10 +396,19 @@ static void xlp_config_link_msix(uint64_t lnkbase, int lirq, uint64_t msixaddr)
337396 val |= (1 << 8 ) | lirq ;
338397 nlm_write_pci_reg (lnkbase , 0xf , val );
339398
340- /* MSI-X addresses */
341- nlm_write_reg (lnkbase , PCIE_BRIDGE_MSIX_ADDR_BASE , msixaddr >> 8 );
342- nlm_write_reg (lnkbase , PCIE_BRIDGE_MSIX_ADDR_LIMIT ,
343- (msixaddr + MSI_ADDR_SZ ) >> 8 );
399+ if (cpu_is_xlp9xx ()) {
400+ /* MSI-X addresses */
401+ nlm_write_reg (lnkbase , PCIE_9XX_BRIDGE_MSIX_ADDR_BASE ,
402+ msixaddr >> 8 );
403+ nlm_write_reg (lnkbase , PCIE_9XX_BRIDGE_MSIX_ADDR_LIMIT ,
404+ (msixaddr + MSI_ADDR_SZ ) >> 8 );
405+ } else {
406+ /* MSI-X addresses */
407+ nlm_write_reg (lnkbase , PCIE_BRIDGE_MSIX_ADDR_BASE ,
408+ msixaddr >> 8 );
409+ nlm_write_reg (lnkbase , PCIE_BRIDGE_MSIX_ADDR_LIMIT ,
410+ (msixaddr + MSI_ADDR_SZ ) >> 8 );
411+ }
344412}
345413
346414/*
@@ -377,6 +445,7 @@ static int xlp_setup_msix(uint64_t lnkbase, int node, int link,
377445
378446 xirq += t ;
379447 msixvec = nlm_irq_msixvec (xirq );
448+
380449 msg .address_hi = msixaddr >> 32 ;
381450 msg .address_lo = msixaddr & 0xffffffff ;
382451 msg .data = 0xc00 | msixvec ;
@@ -417,7 +486,7 @@ void __init xlp_init_node_msi_irqs(int node, int link)
417486{
418487 struct nlm_soc_info * nodep ;
419488 struct xlp_msi_data * md ;
420- int irq , i , irt , msixvec ;
489+ int irq , i , irt , msixvec , val ;
421490
422491 pr_info ("[%d %d] Init node PCI IRT\n" , node , link );
423492 nodep = nlm_get_node (node );
@@ -438,19 +507,28 @@ void __init xlp_init_node_msi_irqs(int node, int link)
438507 irq_set_handler_data (i , md );
439508 }
440509
441- for (i = 0 ; i < XLP_MSIXVEC_PER_LINK ; i ++ ) {
442- /* Initialize MSI-X irts to generate one interrupt per link */
443- msixvec = link * XLP_MSIXVEC_PER_LINK + i ;
444- irt = PIC_IRT_PCIE_MSIX_INDEX (msixvec );
445- nlm_pic_init_irt (nodep -> picbase , irt , PIC_PCIE_MSIX_IRQ (link ),
446- node * nlm_threads_per_node (), 1 /* enable */ );
510+ for (i = 0 ; i < XLP_MSIXVEC_PER_LINK ; i ++ ) {
511+ if (cpu_is_xlp9xx ()) {
512+ val = ((node * nlm_threads_per_node ()) << 7 |
513+ PIC_PCIE_MSIX_IRQ (link ) << 1 | 0 << 0 );
514+ nlm_write_pcie_reg (md -> lnkbase , PCIE_9XX_MSIX_VECX (i +
515+ (link * XLP_MSIXVEC_PER_LINK )), val );
516+ } else {
517+ /* Initialize MSI-X irts to generate one interrupt
518+ * per link
519+ */
520+ msixvec = link * XLP_MSIXVEC_PER_LINK + i ;
521+ irt = PIC_IRT_PCIE_MSIX_INDEX (msixvec );
522+ nlm_pic_init_irt (nodep -> picbase , irt ,
523+ PIC_PCIE_MSIX_IRQ (link ),
524+ node * nlm_threads_per_node (), 1 );
525+ }
447526
448527 /* Initialize MSI-X extended irq space for the link */
449528 irq = nlm_irq_to_xirq (node , nlm_link_msixirq (link , i ));
450529 irq_set_chip_and_handler (irq , & xlp_msix_chip , handle_level_irq );
451530 irq_set_handler_data (irq , md );
452531 }
453-
454532}
455533
456534void nlm_dispatch_msi (int node , int lirq )
@@ -462,7 +540,11 @@ void nlm_dispatch_msi(int node, int lirq)
462540 link = lirq - PIC_PCIE_LINK_MSI_IRQ_BASE ;
463541 irqbase = nlm_irq_to_xirq (node , nlm_link_msiirq (link , 0 ));
464542 md = irq_get_handler_data (irqbase );
465- status = nlm_read_reg (md -> lnkbase , PCIE_MSI_STATUS ) &
543+ if (cpu_is_xlp9xx ())
544+ status = nlm_read_reg (md -> lnkbase , PCIE_9XX_MSI_STATUS ) &
545+ md -> msi_enabled_mask ;
546+ else
547+ status = nlm_read_reg (md -> lnkbase , PCIE_MSI_STATUS ) &
466548 md -> msi_enabled_mask ;
467549 while (status ) {
468550 i = __ffs (status );
@@ -480,10 +562,14 @@ void nlm_dispatch_msix(int node, int lirq)
480562 link = lirq - PIC_PCIE_MSIX_IRQ_BASE ;
481563 irqbase = nlm_irq_to_xirq (node , nlm_link_msixirq (link , 0 ));
482564 md = irq_get_handler_data (irqbase );
483- status = nlm_read_reg (md -> lnkbase , PCIE_MSIX_STATUS );
565+ if (cpu_is_xlp9xx ())
566+ status = nlm_read_reg (md -> lnkbase , PCIE_9XX_MSIX_STATUSX (link ));
567+ else
568+ status = nlm_read_reg (md -> lnkbase , PCIE_MSIX_STATUS );
484569
485570 /* narrow it down to the MSI-x vectors for our link */
486- status = (status >> (link * XLP_MSIXVEC_PER_LINK )) &
571+ if (!cpu_is_xlp9xx ())
572+ status = (status >> (link * XLP_MSIXVEC_PER_LINK )) &
487573 ((1 << XLP_MSIXVEC_PER_LINK ) - 1 );
488574
489575 while (status ) {
0 commit comments