aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rapidio/rio.c
diff options
context:
space:
mode:
authorAlexandre Bounine <alexandre.bounine@idt.com>2010-05-26 17:43:59 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-05-27 12:12:50 -0400
commite5cabeb3d60f9cd3e3950aff071319ae0e2d08d8 (patch)
treee866f1a9076608630a40f21f0a50c073dedb0e57 /drivers/rapidio/rio.c
parent818a04a0bb93643d57dd8935815de2ff307b58a3 (diff)
rapidio: add Port-Write handling for EM
Add RapidIO Port-Write message handling in the context of Error Management Extensions Specification Rev.1.3. Signed-off-by: Alexandre Bounine <alexandre.bounine@idt.com> Tested-by: Thomas Moll <thomas.moll@sysgo.com> Cc: Matt Porter <mporter@kernel.crashing.org> Cc: Li Yang <leoli@freescale.com> Cc: Kumar Gala <galak@kernel.crashing.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rapidio/rio.c')
-rw-r--r--drivers/rapidio/rio.c328
1 files changed, 328 insertions, 0 deletions
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
index 67a379216959..8fa732e46bf6 100644
--- a/drivers/rapidio/rio.c
+++ b/drivers/rapidio/rio.c
@@ -5,6 +5,10 @@
5 * Copyright 2005 MontaVista Software, Inc. 5 * Copyright 2005 MontaVista Software, Inc.
6 * Matt Porter <mporter@kernel.crashing.org> 6 * Matt Porter <mporter@kernel.crashing.org>
7 * 7 *
8 * Copyright 2009 Integrated Device Technology, Inc.
9 * Alex Bounine <alexandre.bounine@idt.com>
10 * - Added Port-Write/Error Management initialization and handling
11 *
8 * This program is free software; you can redistribute it and/or modify it 12 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the 13 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your 14 * Free Software Foundation; either version 2 of the License, or (at your
@@ -333,6 +337,329 @@ int rio_release_outb_dbell(struct rio_dev *rdev, struct resource *res)
333} 337}
334 338
335/** 339/**
340 * rio_request_inb_pwrite - request inbound port-write message service
341 * @mport: RIO device to which register inbound port-write callback routine
342 * @pwcback: Callback routine to execute when port-write is received
343 *
344 * Binds a port-write callback function to the RapidIO device.
345 * Returns 0 if the request has been satisfied.
346 */
347int rio_request_inb_pwrite(struct rio_dev *rdev,
348 int (*pwcback)(struct rio_dev *rdev, union rio_pw_msg *msg, int step))
349{
350 int rc = 0;
351
352 spin_lock(&rio_global_list_lock);
353 if (rdev->pwcback != NULL)
354 rc = -ENOMEM;
355 else
356 rdev->pwcback = pwcback;
357
358 spin_unlock(&rio_global_list_lock);
359 return rc;
360}
361EXPORT_SYMBOL_GPL(rio_request_inb_pwrite);
362
363/**
364 * rio_release_inb_pwrite - release inbound port-write message service
365 * @rdev: RIO device which registered for inbound port-write callback
366 *
367 * Removes callback from the rio_dev structure. Returns 0 if the request
368 * has been satisfied.
369 */
370int rio_release_inb_pwrite(struct rio_dev *rdev)
371{
372 int rc = -ENOMEM;
373
374 spin_lock(&rio_global_list_lock);
375 if (rdev->pwcback) {
376 rdev->pwcback = NULL;
377 rc = 0;
378 }
379
380 spin_unlock(&rio_global_list_lock);
381 return rc;
382}
383EXPORT_SYMBOL_GPL(rio_release_inb_pwrite);
384
385/**
386 * rio_mport_get_physefb - Helper function that returns register offset
387 * for Physical Layer Extended Features Block.
388 * @rdev: RIO device
389 */
390u32
391rio_mport_get_physefb(struct rio_mport *port, int local,
392 u16 destid, u8 hopcount)
393{
394 u32 ext_ftr_ptr;
395 u32 ftr_header;
396
397 ext_ftr_ptr = rio_mport_get_efb(port, local, destid, hopcount, 0);
398
399 while (ext_ftr_ptr) {
400 if (local)
401 rio_local_read_config_32(port, ext_ftr_ptr,
402 &ftr_header);
403 else
404 rio_mport_read_config_32(port, destid, hopcount,
405 ext_ftr_ptr, &ftr_header);
406
407 ftr_header = RIO_GET_BLOCK_ID(ftr_header);
408 switch (ftr_header) {
409
410 case RIO_EFB_SER_EP_ID_V13P:
411 case RIO_EFB_SER_EP_REC_ID_V13P:
412 case RIO_EFB_SER_EP_FREE_ID_V13P:
413 case RIO_EFB_SER_EP_ID:
414 case RIO_EFB_SER_EP_REC_ID:
415 case RIO_EFB_SER_EP_FREE_ID:
416 case RIO_EFB_SER_EP_FREC_ID:
417
418 return ext_ftr_ptr;
419
420 default:
421 break;
422 }
423
424 ext_ftr_ptr = rio_mport_get_efb(port, local, destid,
425 hopcount, ext_ftr_ptr);
426 }
427
428 return ext_ftr_ptr;
429}
430
431/**
432 * rio_get_comptag - Begin or continue searching for a RIO device by component tag
433 * @comp_tag: RIO component tad to match
434 * @from: Previous RIO device found in search, or %NULL for new search
435 *
436 * Iterates through the list of known RIO devices. If a RIO device is
437 * found with a matching @comp_tag, a pointer to its device
438 * structure is returned. Otherwise, %NULL is returned. A new search
439 * is initiated by passing %NULL to the @from argument. Otherwise, if
440 * @from is not %NULL, searches continue from next device on the global
441 * list.
442 */
443static struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from)
444{
445 struct list_head *n;
446 struct rio_dev *rdev;
447
448 WARN_ON(in_interrupt());
449 spin_lock(&rio_global_list_lock);
450 n = from ? from->global_list.next : rio_devices.next;
451
452 while (n && (n != &rio_devices)) {
453 rdev = rio_dev_g(n);
454 if (rdev->comp_tag == comp_tag)
455 goto exit;
456 n = n->next;
457 }
458 rdev = NULL;
459exit:
460 spin_unlock(&rio_global_list_lock);
461 return rdev;
462}
463
464/**
465 * rio_set_port_lockout - Sets/clears LOCKOUT bit (RIO EM 1.3) for a switch port.
466 * @rdev: Pointer to RIO device control structure
467 * @pnum: Switch port number to set LOCKOUT bit
468 * @lock: Operation : set (=1) or clear (=0)
469 */
470int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
471{
472 u8 hopcount = 0xff;
473 u16 destid = rdev->destid;
474 u32 regval;
475
476 if (rdev->rswitch) {
477 destid = rdev->rswitch->destid;
478 hopcount = rdev->rswitch->hopcount;
479 }
480
481 rio_mport_read_config_32(rdev->net->hport, destid, hopcount,
482 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
483 &regval);
484 if (lock)
485 regval |= RIO_PORT_N_CTL_LOCKOUT;
486 else
487 regval &= ~RIO_PORT_N_CTL_LOCKOUT;
488
489 rio_mport_write_config_32(rdev->net->hport, destid, hopcount,
490 rdev->phys_efptr + RIO_PORT_N_CTL_CSR(pnum),
491 regval);
492 return 0;
493}
494
495/**
496 * rio_inb_pwrite_handler - process inbound port-write message
497 * @pw_msg: pointer to inbound port-write message
498 *
499 * Processes an inbound port-write message. Returns 0 if the request
500 * has been satisfied.
501 */
502int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
503{
504 struct rio_dev *rdev;
505 struct rio_mport *mport;
506 u8 hopcount;
507 u16 destid;
508 u32 err_status;
509 int rc, portnum;
510
511 rdev = rio_get_comptag(pw_msg->em.comptag, NULL);
512 if (rdev == NULL) {
513 /* Someting bad here (probably enumeration error) */
514 pr_err("RIO: %s No matching device for CTag 0x%08x\n",
515 __func__, pw_msg->em.comptag);
516 return -EIO;
517 }
518
519 pr_debug("RIO: Port-Write message from %s\n", rio_name(rdev));
520
521#ifdef DEBUG_PW
522 {
523 u32 i;
524 for (i = 0; i < RIO_PW_MSG_SIZE/sizeof(u32);) {
525 pr_debug("0x%02x: %08x %08x %08x %08x",
526 i*4, pw_msg->raw[i], pw_msg->raw[i + 1],
527 pw_msg->raw[i + 2], pw_msg->raw[i + 3]);
528 i += 4;
529 }
530 pr_debug("\n");
531 }
532#endif
533
534 /* Call an external service function (if such is registered
535 * for this device). This may be the service for endpoints that send
536 * device-specific port-write messages. End-point messages expected
537 * to be handled completely by EP specific device driver.
538 * For switches rc==0 signals that no standard processing required.
539 */
540 if (rdev->pwcback != NULL) {
541 rc = rdev->pwcback(rdev, pw_msg, 0);
542 if (rc == 0)
543 return 0;
544 }
545
546 /* For End-point devices processing stops here */
547 if (!(rdev->pef & RIO_PEF_SWITCH))
548 return 0;
549
550 if (rdev->phys_efptr == 0) {
551 pr_err("RIO_PW: Bad switch initialization for %s\n",
552 rio_name(rdev));
553 return 0;
554 }
555
556 mport = rdev->net->hport;
557 destid = rdev->rswitch->destid;
558 hopcount = rdev->rswitch->hopcount;
559
560 /*
561 * Process the port-write notification from switch
562 */
563
564 portnum = pw_msg->em.is_port & 0xFF;
565
566 if (rdev->rswitch->em_handle)
567 rdev->rswitch->em_handle(rdev, portnum);
568
569 rio_mport_read_config_32(mport, destid, hopcount,
570 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
571 &err_status);
572 pr_debug("RIO_PW: SP%d_ERR_STS_CSR=0x%08x\n", portnum, err_status);
573
574 if (pw_msg->em.errdetect) {
575 pr_debug("RIO_PW: RIO_EM_P%d_ERR_DETECT=0x%08x\n",
576 portnum, pw_msg->em.errdetect);
577 /* Clear EM Port N Error Detect CSR */
578 rio_mport_write_config_32(mport, destid, hopcount,
579 rdev->em_efptr + RIO_EM_PN_ERR_DETECT(portnum), 0);
580 }
581
582 if (pw_msg->em.ltlerrdet) {
583 pr_debug("RIO_PW: RIO_EM_LTL_ERR_DETECT=0x%08x\n",
584 pw_msg->em.ltlerrdet);
585 /* Clear EM L/T Layer Error Detect CSR */
586 rio_mport_write_config_32(mport, destid, hopcount,
587 rdev->em_efptr + RIO_EM_LTL_ERR_DETECT, 0);
588 }
589
590 /* Clear Port Errors */
591 rio_mport_write_config_32(mport, destid, hopcount,
592 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
593 err_status & RIO_PORT_N_ERR_STS_CLR_MASK);
594
595 if (rdev->rswitch->port_ok & (1 << portnum)) {
596 if (err_status & RIO_PORT_N_ERR_STS_PORT_UNINIT) {
597 rdev->rswitch->port_ok &= ~(1 << portnum);
598 rio_set_port_lockout(rdev, portnum, 1);
599
600 rio_mport_write_config_32(mport, destid, hopcount,
601 rdev->phys_efptr +
602 RIO_PORT_N_ACK_STS_CSR(portnum),
603 RIO_PORT_N_ACK_CLEAR);
604
605 /* Schedule Extraction Service */
606 pr_debug("RIO_PW: Device Extraction on [%s]-P%d\n",
607 rio_name(rdev), portnum);
608 }
609 } else {
610 if (err_status & RIO_PORT_N_ERR_STS_PORT_OK) {
611 rdev->rswitch->port_ok |= (1 << portnum);
612 rio_set_port_lockout(rdev, portnum, 0);
613
614 /* Schedule Insertion Service */
615 pr_debug("RIO_PW: Device Insertion on [%s]-P%d\n",
616 rio_name(rdev), portnum);
617 }
618 }
619
620 /* Clear Port-Write Pending bit */
621 rio_mport_write_config_32(mport, destid, hopcount,
622 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
623 RIO_PORT_N_ERR_STS_PW_PEND);
624
625 return 0;
626}
627EXPORT_SYMBOL_GPL(rio_inb_pwrite_handler);
628
629/**
630 * rio_mport_get_efb - get pointer to next extended features block
631 * @port: Master port to issue transaction
632 * @local: Indicate a local master port or remote device access
633 * @destid: Destination ID of the device
634 * @hopcount: Number of switch hops to the device
635 * @from: Offset of current Extended Feature block header (if 0 starts
636 * from ExtFeaturePtr)
637 */
638u32
639rio_mport_get_efb(struct rio_mport *port, int local, u16 destid,
640 u8 hopcount, u32 from)
641{
642 u32 reg_val;
643
644 if (from == 0) {
645 if (local)
646 rio_local_read_config_32(port, RIO_ASM_INFO_CAR,
647 &reg_val);
648 else
649 rio_mport_read_config_32(port, destid, hopcount,
650 RIO_ASM_INFO_CAR, &reg_val);
651 return reg_val & RIO_EXT_FTR_PTR_MASK;
652 } else {
653 if (local)
654 rio_local_read_config_32(port, from, &reg_val);
655 else
656 rio_mport_read_config_32(port, destid, hopcount,
657 from, &reg_val);
658 return RIO_GET_BLOCK_ID(reg_val);
659 }
660}
661
662/**
336 * rio_mport_get_feature - query for devices' extended features 663 * rio_mport_get_feature - query for devices' extended features
337 * @port: Master port to issue transaction 664 * @port: Master port to issue transaction
338 * @local: Indicate a local master port or remote device access 665 * @local: Indicate a local master port or remote device access
@@ -472,6 +799,7 @@ int rio_std_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
472 RIO_STD_RTE_CONF_PORT_SEL_CSR, 799 RIO_STD_RTE_CONF_PORT_SEL_CSR,
473 (u32)route_port); 800 (u32)route_port);
474 } 801 }
802
475 udelay(10); 803 udelay(10);
476 return 0; 804 return 0;
477} 805}