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