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

Merge branch 'sparc64-LDC-changes-for-porting-VCC-driver-into-upstream-kernel'

Jag Raman says:

====================
sparc64: LDC changes for porting VCC driver into upstream kernel

This series of patches is part of an effort to add VCC (Virtual Console
Concentrator) support to Linux.

VCC enables the virtualization of serial console on SPARC processors. VCC
provides access to the guest domain's serial console.

VCC depends on some core functionalities in the linux kernel for SPARC. The
functionalities include LDC (Logical Domain Channels), MDESC (Machine
Descriptor) and VIO (Virtual IO protocol). In order for VCC to be enabled,
it requires that these core functionalities support them.

This series of patches adds LDC support to enable VCC on Linux. It
is the first batch of changes to enable VCC.

This version 4 of the series addresses the following changes
suggested by Dave Miller
Patch 1/5: Modifies ldc_print/__ldc_print to print caller name. Fixes
indentation of wrapped lines.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+106 -43
+8
arch/sparc/include/asm/ldc.h
··· 48 48 #define LDC_STATE_READY 0x03 49 49 #define LDC_STATE_CONNECTED 0x04 50 50 51 + #define LDC_PACKET_SIZE 64 52 + 51 53 struct ldc_channel; 52 54 53 55 /* Allocate state for a channel. */ ··· 74 72 int ldc_disconnect(struct ldc_channel *lp); 75 73 76 74 int ldc_state(struct ldc_channel *lp); 75 + void ldc_set_state(struct ldc_channel *lp, u8 state); 76 + int ldc_mode(struct ldc_channel *lp); 77 + void __ldc_print(struct ldc_channel *lp, const char *caller); 78 + int ldc_rx_reset(struct ldc_channel *lp); 79 + 80 + #define ldc_print(chan) __ldc_print(chan, __func__) 77 81 78 82 /* Read and write operations. Only valid when the link is up. */ 79 83 int ldc_write(struct ldc_channel *lp, const void *buf,
+98 -43
arch/sparc/kernel/ldc.c
··· 34 34 35 35 static char version[] = 36 36 DRV_MODULE_NAME ".c:v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n"; 37 - #define LDC_PACKET_SIZE 64 38 37 39 38 /* Packet header layout for unreliable and reliable mode frames. 40 39 * When in RAW mode, packets are simply straight 64-byte payloads ··· 177 178 printk(KERN_INFO PFX "ID[%lu] " f, lp->id, ## a); \ 178 179 } while (0) 179 180 181 + #define LDC_ABORT(lp) ldc_abort((lp), __func__) 182 + 180 183 static const char *state_to_str(u8 state) 181 184 { 182 185 switch (state) { ··· 195 194 default: 196 195 return "<UNKNOWN>"; 197 196 } 198 - } 199 - 200 - static void ldc_set_state(struct ldc_channel *lp, u8 state) 201 - { 202 - ldcdbg(STATE, "STATE (%s) --> (%s)\n", 203 - state_to_str(lp->state), 204 - state_to_str(state)); 205 - 206 - lp->state = state; 207 197 } 208 198 209 199 static unsigned long __advance(unsigned long off, unsigned long num_entries) ··· 508 516 return err; 509 517 } 510 518 511 - static int ldc_abort(struct ldc_channel *lp) 519 + static int ldc_abort(struct ldc_channel *lp, const char *msg) 512 520 { 513 521 unsigned long hv_err; 514 522 515 - ldcdbg(STATE, "ABORT\n"); 523 + ldcdbg(STATE, "ABORT[%s]\n", msg); 524 + ldc_print(lp); 516 525 517 526 /* We report but do not act upon the hypervisor errors because 518 527 * there really isn't much we can do if they fail at this point. ··· 598 605 } 599 606 } 600 607 if (err) 601 - return ldc_abort(lp); 608 + return LDC_ABORT(lp); 602 609 603 610 return 0; 604 611 } ··· 611 618 if (lp->hs_state == LDC_HS_GOTVERS) { 612 619 if (lp->ver.major != vp->major || 613 620 lp->ver.minor != vp->minor) 614 - return ldc_abort(lp); 621 + return LDC_ABORT(lp); 615 622 } else { 616 623 lp->ver = *vp; 617 624 lp->hs_state = LDC_HS_GOTVERS; 618 625 } 619 626 if (send_rts(lp)) 620 - return ldc_abort(lp); 627 + return LDC_ABORT(lp); 621 628 return 0; 622 629 } 623 630 ··· 628 635 unsigned long new_tail; 629 636 630 637 if (vp->major == 0 && vp->minor == 0) 631 - return ldc_abort(lp); 638 + return LDC_ABORT(lp); 632 639 633 640 vap = find_by_major(vp->major); 634 641 if (!vap) 635 - return ldc_abort(lp); 642 + return LDC_ABORT(lp); 636 643 637 644 p = handshake_compose_ctrl(lp, LDC_INFO, LDC_VERS, 638 645 vap, sizeof(*vap), 639 646 &new_tail); 640 647 if (!p) 641 - return ldc_abort(lp); 648 + return LDC_ABORT(lp); 642 649 643 650 return send_tx_packet(lp, p, new_tail); 644 651 } ··· 661 668 return process_ver_nack(lp, vp); 662 669 663 670 default: 664 - return ldc_abort(lp); 671 + return LDC_ABORT(lp); 665 672 } 666 673 } 667 674 ··· 674 681 if (p->stype != LDC_INFO || 675 682 lp->hs_state != LDC_HS_GOTVERS || 676 683 p->env != lp->cfg.mode) 677 - return ldc_abort(lp); 684 + return LDC_ABORT(lp); 678 685 679 686 lp->snd_nxt = p->seqid; 680 687 lp->rcv_nxt = p->seqid; 681 688 lp->hs_state = LDC_HS_SENTRTR; 682 689 if (send_rtr(lp)) 683 - return ldc_abort(lp); 690 + return LDC_ABORT(lp); 684 691 685 692 return 0; 686 693 } ··· 693 700 694 701 if (p->stype != LDC_INFO || 695 702 p->env != lp->cfg.mode) 696 - return ldc_abort(lp); 703 + return LDC_ABORT(lp); 697 704 698 705 lp->snd_nxt = p->seqid; 699 706 lp->hs_state = LDC_HS_COMPLETE; ··· 716 723 717 724 if (p->stype != LDC_INFO || 718 725 !(rx_seq_ok(lp, p->seqid))) 719 - return ldc_abort(lp); 726 + return LDC_ABORT(lp); 720 727 721 728 lp->rcv_nxt = p->seqid; 722 729 ··· 743 750 return process_rdx(lp, p); 744 751 745 752 default: 746 - return ldc_abort(lp); 753 + return LDC_ABORT(lp); 747 754 } 748 755 } 749 756 750 757 static int process_error_frame(struct ldc_channel *lp, 751 758 struct ldc_packet *p) 752 759 { 753 - return ldc_abort(lp); 760 + return LDC_ABORT(lp); 754 761 } 755 762 756 763 static int process_data_ack(struct ldc_channel *lp, ··· 769 776 return 0; 770 777 } 771 778 if (head == lp->tx_tail) 772 - return ldc_abort(lp); 779 + return LDC_ABORT(lp); 773 780 } 774 781 775 782 return 0; ··· 813 820 lp->hs_state = LDC_HS_COMPLETE; 814 821 ldc_set_state(lp, LDC_STATE_CONNECTED); 815 822 816 - event_mask |= LDC_EVENT_UP; 817 - 818 - orig_state = lp->chan_state; 823 + /* 824 + * Generate an LDC_EVENT_UP event if the channel 825 + * was not already up. 826 + */ 827 + if (orig_state != LDC_CHANNEL_UP) { 828 + event_mask |= LDC_EVENT_UP; 829 + orig_state = lp->chan_state; 830 + } 819 831 } 820 832 821 833 /* If we are in reset state, flush the RX queue and ignore 822 834 * everything. 823 835 */ 824 836 if (lp->flags & LDC_FLAG_RESET) { 825 - (void) __set_rx_head(lp, lp->rx_tail); 837 + (void) ldc_rx_reset(lp); 826 838 goto out; 827 839 } 828 840 ··· 878 880 break; 879 881 880 882 default: 881 - err = ldc_abort(lp); 883 + err = LDC_ABORT(lp); 882 884 break; 883 885 } 884 886 ··· 893 895 894 896 err = __set_rx_head(lp, new); 895 897 if (err < 0) { 896 - (void) ldc_abort(lp); 898 + (void) LDC_ABORT(lp); 897 899 break; 898 900 } 899 901 if (lp->hs_state == LDC_HS_COMPLETE) ··· 934 936 lp->hs_state = LDC_HS_COMPLETE; 935 937 ldc_set_state(lp, LDC_STATE_CONNECTED); 936 938 937 - event_mask |= LDC_EVENT_UP; 939 + /* 940 + * Generate an LDC_EVENT_UP event if the channel 941 + * was not already up. 942 + */ 943 + if (orig_state != LDC_CHANNEL_UP) { 944 + event_mask |= LDC_EVENT_UP; 945 + orig_state = lp->chan_state; 946 + } 938 947 } 939 948 940 949 spin_unlock_irqrestore(&lp->lock, flags); ··· 1452 1447 } 1453 1448 EXPORT_SYMBOL(ldc_state); 1454 1449 1450 + void ldc_set_state(struct ldc_channel *lp, u8 state) 1451 + { 1452 + ldcdbg(STATE, "STATE (%s) --> (%s)\n", 1453 + state_to_str(lp->state), 1454 + state_to_str(state)); 1455 + 1456 + lp->state = state; 1457 + } 1458 + 1459 + int ldc_mode(struct ldc_channel *lp) 1460 + { 1461 + return lp->cfg.mode; 1462 + } 1463 + 1464 + int ldc_rx_reset(struct ldc_channel *lp) 1465 + { 1466 + return __set_rx_head(lp, lp->rx_tail); 1467 + } 1468 + 1469 + void __ldc_print(struct ldc_channel *lp, const char *caller) 1470 + { 1471 + pr_info("%s: id=0x%lx flags=0x%x state=%s cstate=0x%lx hsstate=0x%x\n" 1472 + "\trx_h=0x%lx rx_t=0x%lx rx_n=%ld\n" 1473 + "\ttx_h=0x%lx tx_t=0x%lx tx_n=%ld\n" 1474 + "\trcv_nxt=%u snd_nxt=%u\n", 1475 + caller, lp->id, lp->flags, state_to_str(lp->state), 1476 + lp->chan_state, lp->hs_state, 1477 + lp->rx_head, lp->rx_tail, lp->rx_num_entries, 1478 + lp->tx_head, lp->tx_tail, lp->tx_num_entries, 1479 + lp->rcv_nxt, lp->snd_nxt); 1480 + } 1481 + 1455 1482 static int write_raw(struct ldc_channel *lp, const void *buf, unsigned int size) 1456 1483 { 1457 1484 struct ldc_packet *p; 1458 - unsigned long new_tail; 1485 + unsigned long new_tail, hv_err; 1459 1486 int err; 1487 + 1488 + hv_err = sun4v_ldc_tx_get_state(lp->id, &lp->tx_head, &lp->tx_tail, 1489 + &lp->chan_state); 1490 + if (unlikely(hv_err)) 1491 + return -EBUSY; 1492 + 1493 + if (unlikely(lp->chan_state != LDC_CHANNEL_UP)) 1494 + return LDC_ABORT(lp); 1460 1495 1461 1496 if (size > LDC_PACKET_SIZE) 1462 1497 return -EMSGSIZE; ··· 1528 1483 &lp->rx_tail, 1529 1484 &lp->chan_state); 1530 1485 if (hv_err) 1531 - return ldc_abort(lp); 1486 + return LDC_ABORT(lp); 1532 1487 1533 1488 if (lp->chan_state == LDC_CHANNEL_DOWN || 1534 1489 lp->chan_state == LDC_CHANNEL_RESETTING) ··· 1571 1526 return -EBUSY; 1572 1527 1573 1528 if (unlikely(lp->chan_state != LDC_CHANNEL_UP)) 1574 - return ldc_abort(lp); 1529 + return LDC_ABORT(lp); 1575 1530 1576 1531 if (!tx_has_space_for(lp, size)) 1577 1532 return -EAGAIN; ··· 1637 1592 if (err) 1638 1593 return err; 1639 1594 1640 - err = __set_rx_head(lp, lp->rx_tail); 1595 + err = ldc_rx_reset(lp); 1641 1596 if (err < 0) 1642 - return ldc_abort(lp); 1597 + return LDC_ABORT(lp); 1643 1598 1644 1599 return 0; 1645 1600 } ··· 1652 1607 return err; 1653 1608 } 1654 1609 if (p->stype & LDC_NACK) 1655 - return ldc_abort(lp); 1610 + return LDC_ABORT(lp); 1656 1611 1657 1612 return 0; 1658 1613 } ··· 1672 1627 &lp->rx_tail, 1673 1628 &lp->chan_state); 1674 1629 if (hv_err) 1675 - return ldc_abort(lp); 1630 + return LDC_ABORT(lp); 1676 1631 1677 1632 if (lp->chan_state == LDC_CHANNEL_DOWN || 1678 1633 lp->chan_state == LDC_CHANNEL_RESETTING) ··· 1695 1650 int err = __set_rx_head(lp, head); 1696 1651 1697 1652 if (err < 0) 1698 - return ldc_abort(lp); 1653 + return LDC_ABORT(lp); 1699 1654 1700 1655 lp->rx_head = head; 1701 1656 return 0; ··· 1734 1689 &lp->rx_tail, 1735 1690 &lp->chan_state); 1736 1691 if (hv_err) 1737 - return ldc_abort(lp); 1692 + return LDC_ABORT(lp); 1738 1693 1739 1694 if (lp->chan_state == LDC_CHANNEL_DOWN || 1740 1695 lp->chan_state == LDC_CHANNEL_RESETTING) ··· 1778 1733 1779 1734 lp->rcv_nxt = p->seqid; 1780 1735 1736 + /* 1737 + * If this is a control-only packet, there is nothing 1738 + * else to do but advance the rx queue since the packet 1739 + * was already processed above. 1740 + */ 1781 1741 if (!(p->type & LDC_DATA)) { 1782 1742 new = rx_advance(lp, new); 1783 - goto no_data; 1743 + break; 1784 1744 } 1785 1745 if (p->stype & (LDC_ACK | LDC_NACK)) { 1786 1746 err = data_ack_nack(lp, p); ··· 1950 1900 unsigned long flags; 1951 1901 int err; 1952 1902 1903 + ldcdbg(RX, "%s: entered size=%d\n", __func__, size); 1904 + 1953 1905 if (!buf) 1954 1906 return -EINVAL; 1955 1907 ··· 1966 1914 err = lp->mops->read(lp, buf, size); 1967 1915 1968 1916 spin_unlock_irqrestore(&lp->lock, flags); 1917 + 1918 + ldcdbg(RX, "%s: mode=%d, head=%lu, tail=%lu rv=%d\n", __func__, 1919 + lp->cfg.mode, lp->rx_head, lp->rx_tail, err); 1969 1920 1970 1921 return err; 1971 1922 }