n2rng.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* n2rng.h: Niagara2 RNG defines.
  2. *
  3. * Copyright (C) 2008 David S. Miller <davem@davemloft.net>
  4. */
  5. #ifndef _N2RNG_H
  6. #define _N2RNG_H
  7. #define RNG_CTL_WAIT 0x0000000001fffe00ULL /* Minimum wait time */
  8. #define RNG_CTL_WAIT_SHIFT 9
  9. #define RNG_CTL_BYPASS 0x0000000000000100ULL /* VCO voltage source */
  10. #define RNG_CTL_VCO 0x00000000000000c0ULL /* VCO rate control */
  11. #define RNG_CTL_VCO_SHIFT 6
  12. #define RNG_CTL_ASEL 0x0000000000000030ULL /* Analog MUX select */
  13. #define RNG_CTL_ASEL_SHIFT 4
  14. #define RNG_CTL_LFSR 0x0000000000000008ULL /* Use LFSR or plain shift */
  15. #define RNG_CTL_ES3 0x0000000000000004ULL /* Enable entropy source 3 */
  16. #define RNG_CTL_ES2 0x0000000000000002ULL /* Enable entropy source 2 */
  17. #define RNG_CTL_ES1 0x0000000000000001ULL /* Enable entropy source 1 */
  18. #define HV_FAST_RNG_GET_DIAG_CTL 0x130
  19. #define HV_FAST_RNG_CTL_READ 0x131
  20. #define HV_FAST_RNG_CTL_WRITE 0x132
  21. #define HV_FAST_RNG_DATA_READ_DIAG 0x133
  22. #define HV_FAST_RNG_DATA_READ 0x134
  23. #define HV_RNG_STATE_UNCONFIGURED 0
  24. #define HV_RNG_STATE_CONFIGURED 1
  25. #define HV_RNG_STATE_HEALTHCHECK 2
  26. #define HV_RNG_STATE_ERROR 3
  27. #define HV_RNG_NUM_CONTROL 4
  28. #ifndef __ASSEMBLY__
  29. extern unsigned long sun4v_rng_get_diag_ctl(void);
  30. extern unsigned long sun4v_rng_ctl_read_v1(unsigned long ctl_regs_ra,
  31. unsigned long *state,
  32. unsigned long *tick_delta);
  33. extern unsigned long sun4v_rng_ctl_read_v2(unsigned long ctl_regs_ra,
  34. unsigned long unit,
  35. unsigned long *state,
  36. unsigned long *tick_delta,
  37. unsigned long *watchdog,
  38. unsigned long *write_status);
  39. extern unsigned long sun4v_rng_ctl_write_v1(unsigned long ctl_regs_ra,
  40. unsigned long state,
  41. unsigned long write_timeout,
  42. unsigned long *tick_delta);
  43. extern unsigned long sun4v_rng_ctl_write_v2(unsigned long ctl_regs_ra,
  44. unsigned long state,
  45. unsigned long write_timeout,
  46. unsigned long unit);
  47. extern unsigned long sun4v_rng_data_read_diag_v1(unsigned long data_ra,
  48. unsigned long len,
  49. unsigned long *tick_delta);
  50. extern unsigned long sun4v_rng_data_read_diag_v2(unsigned long data_ra,
  51. unsigned long len,
  52. unsigned long unit,
  53. unsigned long *tick_delta);
  54. extern unsigned long sun4v_rng_data_read(unsigned long data_ra,
  55. unsigned long *tick_delta);
  56. struct n2rng_unit {
  57. u64 control[HV_RNG_NUM_CONTROL];
  58. };
  59. struct n2rng {
  60. struct platform_device *op;
  61. unsigned long flags;
  62. #define N2RNG_FLAG_MULTI 0x00000001 /* Multi-unit capable RNG */
  63. #define N2RNG_FLAG_CONTROL 0x00000002 /* Operating in control domain */
  64. #define N2RNG_FLAG_READY 0x00000008 /* Ready for hw-rng layer */
  65. #define N2RNG_FLAG_SHUTDOWN 0x00000010 /* Driver unregistering */
  66. #define N2RNG_FLAG_BUFFER_VALID 0x00000020 /* u32 buffer holds valid data */
  67. int num_units;
  68. struct n2rng_unit *units;
  69. struct hwrng hwrng;
  70. u32 buffer;
  71. /* Registered hypervisor group API major and minor version. */
  72. unsigned long hvapi_major;
  73. unsigned long hvapi_minor;
  74. struct delayed_work work;
  75. unsigned long hv_state; /* HV_RNG_STATE_foo */
  76. unsigned long health_check_sec;
  77. unsigned long accum_cycles;
  78. unsigned long wd_timeo;
  79. #define N2RNG_HEALTH_CHECK_SEC_DEFAULT 0
  80. #define N2RNG_ACCUM_CYCLES_DEFAULT 2048
  81. #define N2RNG_WD_TIMEO_DEFAULT 0
  82. u64 scratch_control[HV_RNG_NUM_CONTROL];
  83. #define SELFTEST_TICKS 38859
  84. #define SELFTEST_VAL ((u64)0xB8820C7BD387E32C)
  85. #define SELFTEST_POLY ((u64)0x231DCEE91262B8A3)
  86. #define SELFTEST_MATCH_GOAL 6
  87. #define SELFTEST_LOOPS_MAX 40000
  88. #define SELFTEST_BUFFER_WORDS 8
  89. u64 test_data;
  90. u64 test_control[HV_RNG_NUM_CONTROL];
  91. u64 test_buffer[SELFTEST_BUFFER_WORDS];
  92. };
  93. #define N2RNG_BLOCK_LIMIT 60000
  94. #define N2RNG_BUSY_LIMIT 100
  95. #define N2RNG_HCHECK_LIMIT 100
  96. #endif /* !(__ASSEMBLY__) */
  97. #endif /* _N2RNG_H */