Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[RAPIDIO] Add RapidIO multi mport support

The original RapidIO driver suppose there is only one mpc85xx RIO controller
in system. So, some data structures are defined as mpc85xx_rio global, such
as 'regs_win', 'dbell_ring', 'msg_tx_ring'. Now, I changed them to mport's
private members. And you can define multi RIO OF-nodes in dts file for multi
RapidIO controller in one processor, such as PCI/PCI-Ex host controllers in
Freescale's silicon. And the mport operation function declaration should be
changed to know which RapidIO controller is target.

Signed-off-by: Zhang Wei <wei.zhang@freescale.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

Zhang Wei and committed by
Paul Mackerras
ad1e9380 5a7b60ed

+237 -184
+221 -172
arch/powerpc/sysdev/fsl_rio.c
··· 1 1 /* 2 2 * Freescale MPC85xx/MPC86xx RapidIO support 3 3 * 4 + * Copyright (C) 2007, 2008 Freescale Semiconductor, Inc. 5 + * Zhang Wei <wei.zhang@freescale.com> 6 + * 4 7 * Copyright 2005 MontaVista Software, Inc. 5 8 * Matt Porter <mporter@kernel.crashing.org> 6 9 * ··· 22 19 #include <linux/rio_drv.h> 23 20 24 21 #include <asm/io.h> 22 + 23 + /* RapidIO definition irq, which read from OF-tree */ 24 + #define IRQ_RIO_BELL(m) (((struct rio_priv *)(m->priv))->bellirq) 25 + #define IRQ_RIO_TX(m) (((struct rio_priv *)(m->priv))->txirq) 26 + #define IRQ_RIO_RX(m) (((struct rio_priv *)(m->priv))->rxirq) 25 27 26 28 #define RIO_REGS_BASE (CCSRBAR + 0xc0000) 27 29 #define RIO_ATMU_REGS_OFFSET 0x10c00 ··· 120 112 u32 res4; 121 113 }; 122 114 123 - static u32 regs_win; 124 - static struct rio_atmu_regs *atmu_regs; 125 - static struct rio_atmu_regs *maint_atmu_regs; 126 - static struct rio_atmu_regs *dbell_atmu_regs; 127 - static u32 dbell_win; 128 - static u32 maint_win; 129 - static struct rio_msg_regs *msg_regs; 130 - 131 - static struct rio_dbell_ring { 115 + struct rio_dbell_ring { 132 116 void *virt; 133 117 dma_addr_t phys; 134 - } dbell_ring; 118 + }; 135 119 136 - static struct rio_msg_tx_ring { 120 + struct rio_msg_tx_ring { 137 121 void *virt; 138 122 dma_addr_t phys; 139 123 void *virt_buffer[RIO_MAX_TX_RING_SIZE]; ··· 133 133 int tx_slot; 134 134 int size; 135 135 void *dev_id; 136 - } msg_tx_ring; 136 + }; 137 137 138 - static struct rio_msg_rx_ring { 138 + struct rio_msg_rx_ring { 139 139 void *virt; 140 140 dma_addr_t phys; 141 141 void *virt_buffer[RIO_MAX_RX_RING_SIZE]; 142 142 int rx_slot; 143 143 int size; 144 144 void *dev_id; 145 - } msg_rx_ring; 145 + }; 146 + 147 + struct rio_priv { 148 + void __iomem *regs_win; 149 + struct rio_atmu_regs __iomem *atmu_regs; 150 + struct rio_atmu_regs __iomem *maint_atmu_regs; 151 + struct rio_atmu_regs __iomem *dbell_atmu_regs; 152 + void __iomem *dbell_win; 153 + void __iomem *maint_win; 154 + struct rio_msg_regs __iomem *msg_regs; 155 + struct rio_dbell_ring dbell_ring; 156 + struct rio_msg_tx_ring msg_tx_ring; 157 + struct rio_msg_rx_ring msg_rx_ring; 158 + int bellirq; 159 + int txirq; 160 + int rxirq; 161 + }; 146 162 147 163 /** 148 164 * fsl_rio_doorbell_send - Send a MPC85xx doorbell message ··· 169 153 * Sends a MPC85xx doorbell message. Returns %0 on success or 170 154 * %-EINVAL on failure. 171 155 */ 172 - static int fsl_rio_doorbell_send(int index, u16 destid, u16 data) 156 + static int fsl_rio_doorbell_send(struct rio_mport *mport, 157 + int index, u16 destid, u16 data) 173 158 { 159 + struct rio_priv *priv = mport->priv; 174 160 pr_debug("fsl_doorbell_send: index %d destid %4.4x data %4.4x\n", 175 161 index, destid, data); 176 - out_be32((void *)&dbell_atmu_regs->rowtar, destid << 22); 177 - out_be16((void *)(dbell_win), data); 162 + out_be32(&priv->dbell_atmu_regs->rowtar, destid << 22); 163 + out_be16(priv->dbell_win, data); 178 164 179 165 return 0; 180 166 } ··· 191 173 * Generates a MPC85xx local configuration space read. Returns %0 on 192 174 * success or %-EINVAL on failure. 193 175 */ 194 - static int fsl_local_config_read(int index, u32 offset, int len, u32 *data) 176 + static int fsl_local_config_read(struct rio_mport *mport, 177 + int index, u32 offset, int len, u32 *data) 195 178 { 179 + struct rio_priv *priv = mport->priv; 196 180 pr_debug("fsl_local_config_read: index %d offset %8.8x\n", index, 197 181 offset); 198 - *data = in_be32((void *)(regs_win + offset)); 182 + *data = in_be32(priv->regs_win + offset); 199 183 200 184 return 0; 201 185 } ··· 212 192 * Generates a MPC85xx local configuration space write. Returns %0 on 213 193 * success or %-EINVAL on failure. 214 194 */ 215 - static int fsl_local_config_write(int index, u32 offset, int len, u32 data) 195 + static int fsl_local_config_write(struct rio_mport *mport, 196 + int index, u32 offset, int len, u32 data) 216 197 { 198 + struct rio_priv *priv = mport->priv; 217 199 pr_debug 218 200 ("fsl_local_config_write: index %d offset %8.8x data %8.8x\n", 219 201 index, offset, data); 220 - out_be32((void *)(regs_win + offset), data); 202 + out_be32(priv->regs_win + offset, data); 221 203 222 204 return 0; 223 205 } ··· 237 215 * success or %-EINVAL on failure. 238 216 */ 239 217 static int 240 - fsl_rio_config_read(int index, u16 destid, u8 hopcount, u32 offset, int len, 241 - u32 * val) 218 + fsl_rio_config_read(struct rio_mport *mport, int index, u16 destid, 219 + u8 hopcount, u32 offset, int len, u32 *val) 242 220 { 221 + struct rio_priv *priv = mport->priv; 243 222 u8 *data; 244 223 245 224 pr_debug 246 225 ("fsl_rio_config_read: index %d destid %d hopcount %d offset %8.8x len %d\n", 247 226 index, destid, hopcount, offset, len); 248 - out_be32((void *)&maint_atmu_regs->rowtar, 227 + out_be32(&priv->maint_atmu_regs->rowtar, 249 228 (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9)); 250 229 251 - data = (u8 *) maint_win + offset; 230 + data = (u8 *) priv->maint_win + offset; 252 231 switch (len) { 253 232 case 1: 254 233 *val = in_8((u8 *) data); ··· 278 255 * success or %-EINVAL on failure. 279 256 */ 280 257 static int 281 - fsl_rio_config_write(int index, u16 destid, u8 hopcount, u32 offset, 282 - int len, u32 val) 258 + fsl_rio_config_write(struct rio_mport *mport, int index, u16 destid, 259 + u8 hopcount, u32 offset, int len, u32 val) 283 260 { 261 + struct rio_priv *priv = mport->priv; 284 262 u8 *data; 285 263 pr_debug 286 264 ("fsl_rio_config_write: index %d destid %d hopcount %d offset %8.8x len %d val %8.8x\n", 287 265 index, destid, hopcount, offset, len, val); 288 - out_be32((void *)&maint_atmu_regs->rowtar, 266 + out_be32(&priv->maint_atmu_regs->rowtar, 289 267 (destid << 22) | (hopcount << 12) | ((offset & ~0x3) >> 9)); 290 268 291 - data = (u8 *) maint_win + offset; 269 + data = (u8 *) priv->maint_win + offset; 292 270 switch (len) { 293 271 case 1: 294 272 out_8((u8 *) data, val); ··· 320 296 rio_hw_add_outb_message(struct rio_mport *mport, struct rio_dev *rdev, int mbox, 321 297 void *buffer, size_t len) 322 298 { 299 + struct rio_priv *priv = mport->priv; 323 300 u32 omr; 324 - struct rio_tx_desc *desc = 325 - (struct rio_tx_desc *)msg_tx_ring.virt + msg_tx_ring.tx_slot; 301 + struct rio_tx_desc *desc = (struct rio_tx_desc *)priv->msg_tx_ring.virt 302 + + priv->msg_tx_ring.tx_slot; 326 303 int ret = 0; 327 304 328 305 pr_debug ··· 336 311 } 337 312 338 313 /* Copy and clear rest of buffer */ 339 - memcpy(msg_tx_ring.virt_buffer[msg_tx_ring.tx_slot], buffer, len); 314 + memcpy(priv->msg_tx_ring.virt_buffer[priv->msg_tx_ring.tx_slot], buffer, 315 + len); 340 316 if (len < (RIO_MAX_MSG_SIZE - 4)) 341 - memset((void *)((u32) msg_tx_ring. 342 - virt_buffer[msg_tx_ring.tx_slot] + len), 0, 343 - RIO_MAX_MSG_SIZE - len); 317 + memset(priv->msg_tx_ring.virt_buffer[priv->msg_tx_ring.tx_slot] 318 + + len, 0, RIO_MAX_MSG_SIZE - len); 344 319 345 320 /* Set mbox field for message */ 346 321 desc->dport = mbox & 0x3; ··· 352 327 desc->dwcnt = is_power_of_2(len) ? len : 1 << get_bitmask_order(len); 353 328 354 329 /* Set snooping and source buffer address */ 355 - desc->saddr = 0x00000004 | msg_tx_ring.phys_buffer[msg_tx_ring.tx_slot]; 330 + desc->saddr = 0x00000004 331 + | priv->msg_tx_ring.phys_buffer[priv->msg_tx_ring.tx_slot]; 356 332 357 333 /* Increment enqueue pointer */ 358 - omr = in_be32((void *)&msg_regs->omr); 359 - out_be32((void *)&msg_regs->omr, omr | RIO_MSG_OMR_MUI); 334 + omr = in_be32(&priv->msg_regs->omr); 335 + out_be32(&priv->msg_regs->omr, omr | RIO_MSG_OMR_MUI); 360 336 361 337 /* Go to next descriptor */ 362 - if (++msg_tx_ring.tx_slot == msg_tx_ring.size) 363 - msg_tx_ring.tx_slot = 0; 338 + if (++priv->msg_tx_ring.tx_slot == priv->msg_tx_ring.size) 339 + priv->msg_tx_ring.tx_slot = 0; 364 340 365 341 out: 366 342 return ret; ··· 382 356 { 383 357 int osr; 384 358 struct rio_mport *port = (struct rio_mport *)dev_instance; 359 + struct rio_priv *priv = port->priv; 385 360 386 - osr = in_be32((void *)&msg_regs->osr); 361 + osr = in_be32(&priv->msg_regs->osr); 387 362 388 363 if (osr & RIO_MSG_OSR_TE) { 389 364 pr_info("RIO: outbound message transmission error\n"); 390 - out_be32((void *)&msg_regs->osr, RIO_MSG_OSR_TE); 365 + out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_TE); 391 366 goto out; 392 367 } 393 368 394 369 if (osr & RIO_MSG_OSR_QOI) { 395 370 pr_info("RIO: outbound message queue overflow\n"); 396 - out_be32((void *)&msg_regs->osr, RIO_MSG_OSR_QOI); 371 + out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_QOI); 397 372 goto out; 398 373 } 399 374 400 375 if (osr & RIO_MSG_OSR_EOMI) { 401 - u32 dqp = in_be32((void *)&msg_regs->odqdpar); 402 - int slot = (dqp - msg_tx_ring.phys) >> 5; 403 - port->outb_msg[0].mcback(port, msg_tx_ring.dev_id, -1, slot); 376 + u32 dqp = in_be32(&priv->msg_regs->odqdpar); 377 + int slot = (dqp - priv->msg_tx_ring.phys) >> 5; 378 + port->outb_msg[0].mcback(port, priv->msg_tx_ring.dev_id, -1, 379 + slot); 404 380 405 381 /* Ack the end-of-message interrupt */ 406 - out_be32((void *)&msg_regs->osr, RIO_MSG_OSR_EOMI); 382 + out_be32(&priv->msg_regs->osr, RIO_MSG_OSR_EOMI); 407 383 } 408 384 409 385 out: ··· 426 398 int rio_open_outb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries) 427 399 { 428 400 int i, j, rc = 0; 401 + struct rio_priv *priv = mport->priv; 429 402 430 403 if ((entries < RIO_MIN_TX_RING_SIZE) || 431 404 (entries > RIO_MAX_TX_RING_SIZE) || (!is_power_of_2(entries))) { ··· 435 406 } 436 407 437 408 /* Initialize shadow copy ring */ 438 - msg_tx_ring.dev_id = dev_id; 439 - msg_tx_ring.size = entries; 409 + priv->msg_tx_ring.dev_id = dev_id; 410 + priv->msg_tx_ring.size = entries; 440 411 441 - for (i = 0; i < msg_tx_ring.size; i++) { 442 - if (! 443 - (msg_tx_ring.virt_buffer[i] = 444 - dma_alloc_coherent(NULL, RIO_MSG_BUFFER_SIZE, 445 - &msg_tx_ring.phys_buffer[i], 446 - GFP_KERNEL))) { 412 + for (i = 0; i < priv->msg_tx_ring.size; i++) { 413 + priv->msg_tx_ring.virt_buffer[i] = 414 + dma_alloc_coherent(NULL, RIO_MSG_BUFFER_SIZE, 415 + &priv->msg_tx_ring.phys_buffer[i], GFP_KERNEL); 416 + if (!priv->msg_tx_ring.virt_buffer[i]) { 447 417 rc = -ENOMEM; 448 - for (j = 0; j < msg_tx_ring.size; j++) 449 - if (msg_tx_ring.virt_buffer[j]) 418 + for (j = 0; j < priv->msg_tx_ring.size; j++) 419 + if (priv->msg_tx_ring.virt_buffer[j]) 450 420 dma_free_coherent(NULL, 451 - RIO_MSG_BUFFER_SIZE, 452 - msg_tx_ring. 453 - virt_buffer[j], 454 - msg_tx_ring. 455 - phys_buffer[j]); 421 + RIO_MSG_BUFFER_SIZE, 422 + priv->msg_tx_ring. 423 + virt_buffer[j], 424 + priv->msg_tx_ring. 425 + phys_buffer[j]); 456 426 goto out; 457 427 } 458 428 } 459 429 460 430 /* Initialize outbound message descriptor ring */ 461 - if (!(msg_tx_ring.virt = dma_alloc_coherent(NULL, 462 - msg_tx_ring.size * 463 - RIO_MSG_DESC_SIZE, 464 - &msg_tx_ring.phys, 465 - GFP_KERNEL))) { 431 + priv->msg_tx_ring.virt = dma_alloc_coherent(NULL, 432 + priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE, 433 + &priv->msg_tx_ring.phys, GFP_KERNEL); 434 + if (!priv->msg_tx_ring.virt) { 466 435 rc = -ENOMEM; 467 436 goto out_dma; 468 437 } 469 - memset(msg_tx_ring.virt, 0, msg_tx_ring.size * RIO_MSG_DESC_SIZE); 470 - msg_tx_ring.tx_slot = 0; 438 + memset(priv->msg_tx_ring.virt, 0, 439 + priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE); 440 + priv->msg_tx_ring.tx_slot = 0; 471 441 472 442 /* Point dequeue/enqueue pointers at first entry in ring */ 473 - out_be32((void *)&msg_regs->odqdpar, msg_tx_ring.phys); 474 - out_be32((void *)&msg_regs->odqepar, msg_tx_ring.phys); 443 + out_be32(&priv->msg_regs->odqdpar, priv->msg_tx_ring.phys); 444 + out_be32(&priv->msg_regs->odqepar, priv->msg_tx_ring.phys); 475 445 476 446 /* Configure for snooping */ 477 - out_be32((void *)&msg_regs->osar, 0x00000004); 447 + out_be32(&priv->msg_regs->osar, 0x00000004); 478 448 479 449 /* Clear interrupt status */ 480 - out_be32((void *)&msg_regs->osr, 0x000000b3); 450 + out_be32(&priv->msg_regs->osr, 0x000000b3); 481 451 482 452 /* Hook up outbound message handler */ 483 - if ((rc = 484 - request_irq(MPC85xx_IRQ_RIO_TX, fsl_rio_tx_handler, 0, 485 - "msg_tx", (void *)mport)) < 0) 453 + rc = request_irq(IRQ_RIO_TX(mport), fsl_rio_tx_handler, 0, 454 + "msg_tx", (void *)mport); 455 + if (rc < 0) 486 456 goto out_irq; 487 457 488 458 /* ··· 491 463 * Chaining mode 492 464 * Disable 493 465 */ 494 - out_be32((void *)&msg_regs->omr, 0x00100220); 466 + out_be32(&priv->msg_regs->omr, 0x00100220); 495 467 496 468 /* Set number of entries */ 497 - out_be32((void *)&msg_regs->omr, 498 - in_be32((void *)&msg_regs->omr) | 469 + out_be32(&priv->msg_regs->omr, 470 + in_be32(&priv->msg_regs->omr) | 499 471 ((get_bitmask_order(entries) - 2) << 12)); 500 472 501 473 /* Now enable the unit */ 502 - out_be32((void *)&msg_regs->omr, in_be32((void *)&msg_regs->omr) | 0x1); 474 + out_be32(&priv->msg_regs->omr, in_be32(&priv->msg_regs->omr) | 0x1); 503 475 504 476 out: 505 477 return rc; 506 478 507 479 out_irq: 508 - dma_free_coherent(NULL, msg_tx_ring.size * RIO_MSG_DESC_SIZE, 509 - msg_tx_ring.virt, msg_tx_ring.phys); 480 + dma_free_coherent(NULL, priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE, 481 + priv->msg_tx_ring.virt, priv->msg_tx_ring.phys); 510 482 511 483 out_dma: 512 - for (i = 0; i < msg_tx_ring.size; i++) 484 + for (i = 0; i < priv->msg_tx_ring.size; i++) 513 485 dma_free_coherent(NULL, RIO_MSG_BUFFER_SIZE, 514 - msg_tx_ring.virt_buffer[i], 515 - msg_tx_ring.phys_buffer[i]); 486 + priv->msg_tx_ring.virt_buffer[i], 487 + priv->msg_tx_ring.phys_buffer[i]); 516 488 517 489 return rc; 518 490 } ··· 527 499 */ 528 500 void rio_close_outb_mbox(struct rio_mport *mport, int mbox) 529 501 { 502 + struct rio_priv *priv = mport->priv; 530 503 /* Disable inbound message unit */ 531 - out_be32((void *)&msg_regs->omr, 0); 504 + out_be32(&priv->msg_regs->omr, 0); 532 505 533 506 /* Free ring */ 534 - dma_free_coherent(NULL, msg_tx_ring.size * RIO_MSG_DESC_SIZE, 535 - msg_tx_ring.virt, msg_tx_ring.phys); 507 + dma_free_coherent(NULL, priv->msg_tx_ring.size * RIO_MSG_DESC_SIZE, 508 + priv->msg_tx_ring.virt, priv->msg_tx_ring.phys); 536 509 537 510 /* Free interrupt */ 538 - free_irq(MPC85xx_IRQ_RIO_TX, (void *)mport); 511 + free_irq(IRQ_RIO_TX(mport), (void *)mport); 539 512 } 540 513 541 514 /** ··· 552 523 { 553 524 int isr; 554 525 struct rio_mport *port = (struct rio_mport *)dev_instance; 526 + struct rio_priv *priv = port->priv; 555 527 556 - isr = in_be32((void *)&msg_regs->isr); 528 + isr = in_be32(&priv->msg_regs->isr); 557 529 558 530 if (isr & RIO_MSG_ISR_TE) { 559 531 pr_info("RIO: inbound message reception error\n"); 560 - out_be32((void *)&msg_regs->isr, RIO_MSG_ISR_TE); 532 + out_be32((void *)&priv->msg_regs->isr, RIO_MSG_ISR_TE); 561 533 goto out; 562 534 } 563 535 ··· 570 540 * make the callback with an unknown/invalid mailbox number 571 541 * argument. 572 542 */ 573 - port->inb_msg[0].mcback(port, msg_rx_ring.dev_id, -1, -1); 543 + port->inb_msg[0].mcback(port, priv->msg_rx_ring.dev_id, -1, -1); 574 544 575 545 /* Ack the queueing interrupt */ 576 - out_be32((void *)&msg_regs->isr, RIO_MSG_ISR_DIQI); 546 + out_be32(&priv->msg_regs->isr, RIO_MSG_ISR_DIQI); 577 547 } 578 548 579 549 out: ··· 594 564 int rio_open_inb_mbox(struct rio_mport *mport, void *dev_id, int mbox, int entries) 595 565 { 596 566 int i, rc = 0; 567 + struct rio_priv *priv = mport->priv; 597 568 598 569 if ((entries < RIO_MIN_RX_RING_SIZE) || 599 570 (entries > RIO_MAX_RX_RING_SIZE) || (!is_power_of_2(entries))) { ··· 603 572 } 604 573 605 574 /* Initialize client buffer ring */ 606 - msg_rx_ring.dev_id = dev_id; 607 - msg_rx_ring.size = entries; 608 - msg_rx_ring.rx_slot = 0; 609 - for (i = 0; i < msg_rx_ring.size; i++) 610 - msg_rx_ring.virt_buffer[i] = NULL; 575 + priv->msg_rx_ring.dev_id = dev_id; 576 + priv->msg_rx_ring.size = entries; 577 + priv->msg_rx_ring.rx_slot = 0; 578 + for (i = 0; i < priv->msg_rx_ring.size; i++) 579 + priv->msg_rx_ring.virt_buffer[i] = NULL; 611 580 612 581 /* Initialize inbound message ring */ 613 - if (!(msg_rx_ring.virt = dma_alloc_coherent(NULL, 614 - msg_rx_ring.size * 615 - RIO_MAX_MSG_SIZE, 616 - &msg_rx_ring.phys, 617 - GFP_KERNEL))) { 582 + priv->msg_rx_ring.virt = dma_alloc_coherent(NULL, 583 + priv->msg_rx_ring.size * RIO_MAX_MSG_SIZE, 584 + &priv->msg_rx_ring.phys, GFP_KERNEL); 585 + if (!priv->msg_rx_ring.virt) { 618 586 rc = -ENOMEM; 619 587 goto out; 620 588 } 621 589 622 590 /* Point dequeue/enqueue pointers at first entry in ring */ 623 - out_be32((void *)&msg_regs->ifqdpar, (u32) msg_rx_ring.phys); 624 - out_be32((void *)&msg_regs->ifqepar, (u32) msg_rx_ring.phys); 591 + out_be32(&priv->msg_regs->ifqdpar, (u32) priv->msg_rx_ring.phys); 592 + out_be32(&priv->msg_regs->ifqepar, (u32) priv->msg_rx_ring.phys); 625 593 626 594 /* Clear interrupt status */ 627 - out_be32((void *)&msg_regs->isr, 0x00000091); 595 + out_be32(&priv->msg_regs->isr, 0x00000091); 628 596 629 597 /* Hook up inbound message handler */ 630 - if ((rc = 631 - request_irq(MPC85xx_IRQ_RIO_RX, fsl_rio_rx_handler, 0, 632 - "msg_rx", (void *)mport)) < 0) { 598 + rc = request_irq(IRQ_RIO_RX(mport), fsl_rio_rx_handler, 0, 599 + "msg_rx", (void *)mport); 600 + if (rc < 0) { 633 601 dma_free_coherent(NULL, RIO_MSG_BUFFER_SIZE, 634 - msg_tx_ring.virt_buffer[i], 635 - msg_tx_ring.phys_buffer[i]); 602 + priv->msg_tx_ring.virt_buffer[i], 603 + priv->msg_tx_ring.phys_buffer[i]); 636 604 goto out; 637 605 } 638 606 ··· 642 612 * Unmask all interrupt sources 643 613 * Disable 644 614 */ 645 - out_be32((void *)&msg_regs->imr, 0x001b0060); 615 + out_be32(&priv->msg_regs->imr, 0x001b0060); 646 616 647 617 /* Set number of queue entries */ 648 - out_be32((void *)&msg_regs->imr, 649 - in_be32((void *)&msg_regs->imr) | 650 - ((get_bitmask_order(entries) - 2) << 12)); 618 + setbits32(&priv->msg_regs->imr, (get_bitmask_order(entries) - 2) << 12); 651 619 652 620 /* Now enable the unit */ 653 - out_be32((void *)&msg_regs->imr, in_be32((void *)&msg_regs->imr) | 0x1); 621 + setbits32(&priv->msg_regs->imr, 0x1); 654 622 655 623 out: 656 624 return rc; ··· 664 636 */ 665 637 void rio_close_inb_mbox(struct rio_mport *mport, int mbox) 666 638 { 639 + struct rio_priv *priv = mport->priv; 667 640 /* Disable inbound message unit */ 668 - out_be32((void *)&msg_regs->imr, 0); 641 + out_be32(&priv->msg_regs->imr, 0); 669 642 670 643 /* Free ring */ 671 - dma_free_coherent(NULL, msg_rx_ring.size * RIO_MAX_MSG_SIZE, 672 - msg_rx_ring.virt, msg_rx_ring.phys); 644 + dma_free_coherent(NULL, priv->msg_rx_ring.size * RIO_MAX_MSG_SIZE, 645 + priv->msg_rx_ring.virt, priv->msg_rx_ring.phys); 673 646 674 647 /* Free interrupt */ 675 - free_irq(MPC85xx_IRQ_RIO_RX, (void *)mport); 648 + free_irq(IRQ_RIO_RX(mport), (void *)mport); 676 649 } 677 650 678 651 /** ··· 688 659 int rio_hw_add_inb_buffer(struct rio_mport *mport, int mbox, void *buf) 689 660 { 690 661 int rc = 0; 662 + struct rio_priv *priv = mport->priv; 691 663 692 664 pr_debug("RIO: rio_hw_add_inb_buffer(), msg_rx_ring.rx_slot %d\n", 693 - msg_rx_ring.rx_slot); 665 + priv->msg_rx_ring.rx_slot); 694 666 695 - if (msg_rx_ring.virt_buffer[msg_rx_ring.rx_slot]) { 667 + if (priv->msg_rx_ring.virt_buffer[priv->msg_rx_ring.rx_slot]) { 696 668 printk(KERN_ERR 697 669 "RIO: error adding inbound buffer %d, buffer exists\n", 698 - msg_rx_ring.rx_slot); 670 + priv->msg_rx_ring.rx_slot); 699 671 rc = -EINVAL; 700 672 goto out; 701 673 } 702 674 703 - msg_rx_ring.virt_buffer[msg_rx_ring.rx_slot] = buf; 704 - if (++msg_rx_ring.rx_slot == msg_rx_ring.size) 705 - msg_rx_ring.rx_slot = 0; 675 + priv->msg_rx_ring.virt_buffer[priv->msg_rx_ring.rx_slot] = buf; 676 + if (++priv->msg_rx_ring.rx_slot == priv->msg_rx_ring.size) 677 + priv->msg_rx_ring.rx_slot = 0; 706 678 707 679 out: 708 680 return rc; ··· 721 691 */ 722 692 void *rio_hw_get_inb_message(struct rio_mport *mport, int mbox) 723 693 { 724 - u32 imr; 694 + struct rio_priv *priv = mport->priv; 725 695 u32 phys_buf, virt_buf; 726 696 void *buf = NULL; 727 697 int buf_idx; 728 698 729 - phys_buf = in_be32((void *)&msg_regs->ifqdpar); 699 + phys_buf = in_be32(&priv->msg_regs->ifqdpar); 730 700 731 701 /* If no more messages, then bail out */ 732 - if (phys_buf == in_be32((void *)&msg_regs->ifqepar)) 702 + if (phys_buf == in_be32(&priv->msg_regs->ifqepar)) 733 703 goto out2; 734 704 735 - virt_buf = (u32) msg_rx_ring.virt + (phys_buf - msg_rx_ring.phys); 736 - buf_idx = (phys_buf - msg_rx_ring.phys) / RIO_MAX_MSG_SIZE; 737 - buf = msg_rx_ring.virt_buffer[buf_idx]; 705 + virt_buf = (u32) priv->msg_rx_ring.virt + (phys_buf 706 + - priv->msg_rx_ring.phys); 707 + buf_idx = (phys_buf - priv->msg_rx_ring.phys) / RIO_MAX_MSG_SIZE; 708 + buf = priv->msg_rx_ring.virt_buffer[buf_idx]; 738 709 739 710 if (!buf) { 740 711 printk(KERN_ERR ··· 747 716 memcpy(buf, (void *)virt_buf, RIO_MAX_MSG_SIZE); 748 717 749 718 /* Clear the available buffer */ 750 - msg_rx_ring.virt_buffer[buf_idx] = NULL; 719 + priv->msg_rx_ring.virt_buffer[buf_idx] = NULL; 751 720 752 721 out1: 753 - imr = in_be32((void *)&msg_regs->imr); 754 - out_be32((void *)&msg_regs->imr, imr | RIO_MSG_IMR_MI); 722 + setbits32(&priv->msg_regs->imr, RIO_MSG_IMR_MI); 755 723 756 724 out2: 757 725 return buf; ··· 771 741 { 772 742 int dsr; 773 743 struct rio_mport *port = (struct rio_mport *)dev_instance; 744 + struct rio_priv *priv = port->priv; 774 745 775 - dsr = in_be32((void *)&msg_regs->dsr); 746 + dsr = in_be32(&priv->msg_regs->dsr); 776 747 777 748 if (dsr & DOORBELL_DSR_TE) { 778 749 pr_info("RIO: doorbell reception error\n"); 779 - out_be32((void *)&msg_regs->dsr, DOORBELL_DSR_TE); 750 + out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_TE); 780 751 goto out; 781 752 } 782 753 783 754 if (dsr & DOORBELL_DSR_QFI) { 784 755 pr_info("RIO: doorbell queue full\n"); 785 - out_be32((void *)&msg_regs->dsr, DOORBELL_DSR_QFI); 756 + out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_QFI); 786 757 goto out; 787 758 } 788 759 789 760 /* XXX Need to check/dispatch until queue empty */ 790 761 if (dsr & DOORBELL_DSR_DIQI) { 791 762 u32 dmsg = 792 - (u32) dbell_ring.virt + 793 - (in_be32((void *)&msg_regs->dqdpar) & 0xfff); 794 - u32 dmr; 763 + (u32) priv->dbell_ring.virt + 764 + (in_be32(&priv->msg_regs->dqdpar) & 0xfff); 795 765 struct rio_dbell *dbell; 796 766 int found = 0; 797 767 ··· 814 784 ("RIO: spurious doorbell, sid %2.2x tid %2.2x info %4.4x\n", 815 785 DBELL_SID(dmsg), DBELL_TID(dmsg), DBELL_INF(dmsg)); 816 786 } 817 - dmr = in_be32((void *)&msg_regs->dmr); 818 - out_be32((void *)&msg_regs->dmr, dmr | DOORBELL_DMR_DI); 819 - out_be32((void *)&msg_regs->dsr, DOORBELL_DSR_DIQI); 787 + setbits32(&priv->msg_regs->dmr, DOORBELL_DMR_DI); 788 + out_be32(&priv->msg_regs->dsr, DOORBELL_DSR_DIQI); 820 789 } 821 790 822 791 out: ··· 832 803 */ 833 804 static int fsl_rio_doorbell_init(struct rio_mport *mport) 834 805 { 806 + struct rio_priv *priv = mport->priv; 835 807 int rc = 0; 836 808 837 809 /* Map outbound doorbell window immediately after maintenance window */ 838 - if (!(dbell_win = 839 - (u32) ioremap(mport->iores.start + RIO_MAINT_WIN_SIZE, 840 - RIO_DBELL_WIN_SIZE))) { 810 + priv->dbell_win = ioremap(mport->iores.start + RIO_MAINT_WIN_SIZE, 811 + RIO_DBELL_WIN_SIZE); 812 + if (!priv->dbell_win) { 841 813 printk(KERN_ERR 842 814 "RIO: unable to map outbound doorbell window\n"); 843 815 rc = -ENOMEM; ··· 846 816 } 847 817 848 818 /* Initialize inbound doorbells */ 849 - if (!(dbell_ring.virt = dma_alloc_coherent(NULL, 850 - 512 * DOORBELL_MESSAGE_SIZE, 851 - &dbell_ring.phys, 852 - GFP_KERNEL))) { 819 + priv->dbell_ring.virt = dma_alloc_coherent(NULL, 512 * 820 + DOORBELL_MESSAGE_SIZE, &priv->dbell_ring.phys, GFP_KERNEL); 821 + if (!priv->dbell_ring.virt) { 853 822 printk(KERN_ERR "RIO: unable allocate inbound doorbell ring\n"); 854 823 rc = -ENOMEM; 855 - iounmap((void *)dbell_win); 824 + iounmap(priv->dbell_win); 856 825 goto out; 857 826 } 858 827 859 828 /* Point dequeue/enqueue pointers at first entry in ring */ 860 - out_be32((void *)&msg_regs->dqdpar, (u32) dbell_ring.phys); 861 - out_be32((void *)&msg_regs->dqepar, (u32) dbell_ring.phys); 829 + out_be32(&priv->msg_regs->dqdpar, (u32) priv->dbell_ring.phys); 830 + out_be32(&priv->msg_regs->dqepar, (u32) priv->dbell_ring.phys); 862 831 863 832 /* Clear interrupt status */ 864 - out_be32((void *)&msg_regs->dsr, 0x00000091); 833 + out_be32(&priv->msg_regs->dsr, 0x00000091); 865 834 866 835 /* Hook up doorbell handler */ 867 - if ((rc = 868 - request_irq(MPC85xx_IRQ_RIO_BELL, fsl_rio_dbell_handler, 0, 869 - "dbell_rx", (void *)mport) < 0)) { 870 - iounmap((void *)dbell_win); 836 + rc = request_irq(IRQ_RIO_BELL(mport), fsl_rio_dbell_handler, 0, 837 + "dbell_rx", (void *)mport); 838 + if (rc < 0) { 839 + iounmap(priv->dbell_win); 871 840 dma_free_coherent(NULL, 512 * DOORBELL_MESSAGE_SIZE, 872 - dbell_ring.virt, dbell_ring.phys); 841 + priv->dbell_ring.virt, priv->dbell_ring.phys); 873 842 printk(KERN_ERR 874 843 "MPC85xx RIO: unable to request inbound doorbell irq"); 875 844 goto out; 876 845 } 877 846 878 847 /* Configure doorbells for snooping, 512 entries, and enable */ 879 - out_be32((void *)&msg_regs->dmr, 0x00108161); 848 + out_be32(&priv->msg_regs->dmr, 0x00108161); 880 849 881 850 out: 882 851 return rc; ··· 916 887 { 917 888 struct rio_ops *ops; 918 889 struct rio_mport *port; 890 + struct rio_priv *priv = NULL; 891 + int rc; 919 892 920 893 ops = kmalloc(sizeof(struct rio_ops), GFP_KERNEL); 921 894 ops->lcread = fsl_local_config_read; ··· 926 895 ops->cwrite = fsl_rio_config_write; 927 896 ops->dsend = fsl_rio_doorbell_send; 928 897 929 - port = kmalloc(sizeof(struct rio_mport), GFP_KERNEL); 898 + port = kzalloc(sizeof(struct rio_mport), GFP_KERNEL); 930 899 port->id = 0; 931 900 port->index = 0; 901 + 902 + priv = kzalloc(sizeof(struct rio_priv), GFP_KERNEL); 903 + if (!priv) { 904 + printk(KERN_ERR "Can't alloc memory for 'priv'\n"); 905 + rc = -ENOMEM; 906 + goto err; 907 + } 908 + 932 909 INIT_LIST_HEAD(&port->dbells); 933 910 port->iores.start = law_start; 934 911 port->iores.end = law_start + law_size; ··· 950 911 port->ops = ops; 951 912 port->host_deviceid = fsl_rio_get_hdid(port->id); 952 913 914 + port->priv = priv; 953 915 rio_register_mport(port); 954 916 955 - regs_win = (u32) ioremap(RIO_REGS_BASE, 0x20000); 956 - atmu_regs = (struct rio_atmu_regs *)(regs_win + RIO_ATMU_REGS_OFFSET); 957 - maint_atmu_regs = atmu_regs + 1; 958 - dbell_atmu_regs = atmu_regs + 2; 959 - msg_regs = (struct rio_msg_regs *)(regs_win + RIO_MSG_REGS_OFFSET); 917 + priv->regs_win = ioremap(RIO_REGS_BASE, 0x20000); 918 + priv->atmu_regs = (struct rio_atmu_regs *)(priv->regs_win 919 + + RIO_ATMU_REGS_OFFSET); 920 + priv->maint_atmu_regs = priv->atmu_regs + 1; 921 + priv->dbell_atmu_regs = priv->atmu_regs + 2; 922 + priv->msg_regs = (struct rio_msg_regs *)(priv->regs_win 923 + + RIO_MSG_REGS_OFFSET); 960 924 961 925 /* Configure maintenance transaction window */ 962 - out_be32((void *)&maint_atmu_regs->rowbar, 0x000c0000); 963 - out_be32((void *)&maint_atmu_regs->rowar, 0x80077015); 926 + out_be32(&priv->maint_atmu_regs->rowbar, 0x000c0000); 927 + out_be32(&priv->maint_atmu_regs->rowar, 0x80077015); 964 928 965 - maint_win = (u32) ioremap(law_start, RIO_MAINT_WIN_SIZE); 929 + priv->maint_win = ioremap(law_start, RIO_MAINT_WIN_SIZE); 966 930 967 931 /* Configure outbound doorbell window */ 968 - out_be32((void *)&dbell_atmu_regs->rowbar, 0x000c0400); 969 - out_be32((void *)&dbell_atmu_regs->rowar, 0x8004200b); 932 + out_be32(&priv->dbell_atmu_regs->rowbar, 0x000c0400); 933 + out_be32(&priv->dbell_atmu_regs->rowar, 0x8004200b); 970 934 fsl_rio_doorbell_init(port); 935 + 936 + return; 937 + err: 938 + if (priv) 939 + iounmap(priv->regs_win); 940 + kfree(priv); 941 + kfree(port); 971 942 }
+5 -5
drivers/rapidio/rio-access.c
··· 48 48 u32 data = 0; \ 49 49 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \ 50 50 spin_lock_irqsave(&rio_config_lock, flags); \ 51 - res = mport->ops->lcread(mport->id, offset, len, &data); \ 51 + res = mport->ops->lcread(mport, mport->id, offset, len, &data); \ 52 52 *value = (type)data; \ 53 53 spin_unlock_irqrestore(&rio_config_lock, flags); \ 54 54 return res; \ ··· 71 71 unsigned long flags; \ 72 72 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \ 73 73 spin_lock_irqsave(&rio_config_lock, flags); \ 74 - res = mport->ops->lcwrite(mport->id, offset, len, value); \ 74 + res = mport->ops->lcwrite(mport, mport->id, offset, len, value);\ 75 75 spin_unlock_irqrestore(&rio_config_lock, flags); \ 76 76 return res; \ 77 77 } ··· 108 108 u32 data = 0; \ 109 109 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \ 110 110 spin_lock_irqsave(&rio_config_lock, flags); \ 111 - res = mport->ops->cread(mport->id, destid, hopcount, offset, len, &data); \ 111 + res = mport->ops->cread(mport, mport->id, destid, hopcount, offset, len, &data); \ 112 112 *value = (type)data; \ 113 113 spin_unlock_irqrestore(&rio_config_lock, flags); \ 114 114 return res; \ ··· 131 131 unsigned long flags; \ 132 132 if (RIO_##size##_BAD) return RIO_BAD_SIZE; \ 133 133 spin_lock_irqsave(&rio_config_lock, flags); \ 134 - res = mport->ops->cwrite(mport->id, destid, hopcount, offset, len, value); \ 134 + res = mport->ops->cwrite(mport, mport->id, destid, hopcount, offset, len, value); \ 135 135 spin_unlock_irqrestore(&rio_config_lock, flags); \ 136 136 return res; \ 137 137 } ··· 166 166 unsigned long flags; 167 167 168 168 spin_lock_irqsave(&rio_doorbell_lock, flags); 169 - res = mport->ops->dsend(mport->id, destid, data); 169 + res = mport->ops->dsend(mport, mport->id, destid, data); 170 170 spin_unlock_irqrestore(&rio_doorbell_lock, flags); 171 171 172 172 return res;
+11 -7
include/linux/rio.h
··· 163 163 * @id: Port ID, unique among all ports 164 164 * @index: Port index, unique among all port interfaces of the same type 165 165 * @name: Port name string 166 + * @priv: Master port private data 166 167 */ 167 168 struct rio_mport { 168 169 struct list_head dbells; /* list of doorbell events */ ··· 179 178 unsigned char index; /* port index, unique among all port 180 179 interfaces of the same type */ 181 180 unsigned char name[40]; 181 + void *priv; /* Master port private data */ 182 182 }; 183 183 184 184 /** ··· 231 229 * @dsend: Callback to send a doorbell message. 232 230 */ 233 231 struct rio_ops { 234 - int (*lcread) (int index, u32 offset, int len, u32 * data); 235 - int (*lcwrite) (int index, u32 offset, int len, u32 data); 236 - int (*cread) (int index, u16 destid, u8 hopcount, u32 offset, int len, 237 - u32 * data); 238 - int (*cwrite) (int index, u16 destid, u8 hopcount, u32 offset, int len, 239 - u32 data); 240 - int (*dsend) (int index, u16 destid, u16 data); 232 + int (*lcread) (struct rio_mport *mport, int index, u32 offset, int len, 233 + u32 *data); 234 + int (*lcwrite) (struct rio_mport *mport, int index, u32 offset, int len, 235 + u32 data); 236 + int (*cread) (struct rio_mport *mport, int index, u16 destid, 237 + u8 hopcount, u32 offset, int len, u32 *data); 238 + int (*cwrite) (struct rio_mport *mport, int index, u16 destid, 239 + u8 hopcount, u32 offset, int len, u32 data); 240 + int (*dsend) (struct rio_mport *mport, int index, u16 destid, u16 data); 241 241 }; 242 242 243 243 #define RIO_RESOURCE_MEM 0x00000100