boards.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2007 Solarflare Communications Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 as published
  7. * by the Free Software Foundation, incorporated herein by reference.
  8. */
  9. #include "net_driver.h"
  10. #include "phy.h"
  11. #include "boards.h"
  12. #include "efx.h"
  13. /* Macros for unpacking the board revision */
  14. /* The revision info is in host byte order. */
  15. #define BOARD_TYPE(_rev) (_rev >> 8)
  16. #define BOARD_MAJOR(_rev) ((_rev >> 4) & 0xf)
  17. #define BOARD_MINOR(_rev) (_rev & 0xf)
  18. /* Blink support. If the PHY has no auto-blink mode so we hang it off a timer */
  19. #define BLINK_INTERVAL (HZ/2)
  20. static void blink_led_timer(unsigned long context)
  21. {
  22. struct efx_nic *efx = (struct efx_nic *)context;
  23. struct efx_blinker *bl = &efx->board_info.blinker;
  24. efx->board_info.set_fault_led(efx, bl->state);
  25. bl->state = !bl->state;
  26. if (bl->resubmit) {
  27. bl->timer.expires = jiffies + BLINK_INTERVAL;
  28. add_timer(&bl->timer);
  29. }
  30. }
  31. static void board_blink(struct efx_nic *efx, int blink)
  32. {
  33. struct efx_blinker *blinker = &efx->board_info.blinker;
  34. /* The rtnl mutex serialises all ethtool ioctls, so
  35. * nothing special needs doing here. */
  36. if (blink) {
  37. blinker->resubmit = 1;
  38. blinker->state = 0;
  39. setup_timer(&blinker->timer, blink_led_timer,
  40. (unsigned long)efx);
  41. blinker->timer.expires = jiffies + BLINK_INTERVAL;
  42. add_timer(&blinker->timer);
  43. } else {
  44. blinker->resubmit = 0;
  45. if (blinker->timer.function)
  46. del_timer_sync(&blinker->timer);
  47. efx->board_info.set_fault_led(efx, 0);
  48. }
  49. }
  50. /*****************************************************************************
  51. * Support for the SFE4002
  52. *
  53. */
  54. /****************************************************************************/
  55. /* LED allocations. Note that on rev A0 boards the schematic and the reality
  56. * differ: red and green are swapped. Below is the fixed (A1) layout (there
  57. * are only 3 A0 boards in existence, so no real reason to make this
  58. * conditional).
  59. */
  60. #define SFE4002_FAULT_LED (2) /* Red */
  61. #define SFE4002_RX_LED (0) /* Green */
  62. #define SFE4002_TX_LED (1) /* Amber */
  63. static int sfe4002_init_leds(struct efx_nic *efx)
  64. {
  65. /* Set the TX and RX LEDs to reflect status and activity, and the
  66. * fault LED off */
  67. xfp_set_led(efx, SFE4002_TX_LED,
  68. QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
  69. xfp_set_led(efx, SFE4002_RX_LED,
  70. QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
  71. xfp_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
  72. efx->board_info.blinker.led_num = SFE4002_FAULT_LED;
  73. return 0;
  74. }
  75. static void sfe4002_fault_led(struct efx_nic *efx, int state)
  76. {
  77. xfp_set_led(efx, SFE4002_FAULT_LED, state ? QUAKE_LED_ON :
  78. QUAKE_LED_OFF);
  79. }
  80. static int sfe4002_init(struct efx_nic *efx)
  81. {
  82. efx->board_info.init_leds = sfe4002_init_leds;
  83. efx->board_info.set_fault_led = sfe4002_fault_led;
  84. efx->board_info.blink = board_blink;
  85. return 0;
  86. }
  87. /* This will get expanded as board-specific details get moved out of the
  88. * PHY drivers. */
  89. struct efx_board_data {
  90. const char *ref_model;
  91. const char *gen_type;
  92. int (*init) (struct efx_nic *nic);
  93. };
  94. static int dummy_init(struct efx_nic *nic)
  95. {
  96. return 0;
  97. }
  98. static struct efx_board_data board_data[] = {
  99. [EFX_BOARD_INVALID] =
  100. {NULL, NULL, dummy_init},
  101. [EFX_BOARD_SFE4001] =
  102. {"SFE4001", "10GBASE-T adapter", sfe4001_poweron},
  103. [EFX_BOARD_SFE4002] =
  104. {"SFE4002", "XFP adapter", sfe4002_init},
  105. };
  106. int efx_set_board_info(struct efx_nic *efx, u16 revision_info)
  107. {
  108. int rc = 0;
  109. struct efx_board_data *data;
  110. if (BOARD_TYPE(revision_info) >= EFX_BOARD_MAX) {
  111. EFX_ERR(efx, "squashing unknown board type %d\n",
  112. BOARD_TYPE(revision_info));
  113. revision_info = 0;
  114. }
  115. if (BOARD_TYPE(revision_info) == 0) {
  116. efx->board_info.major = 0;
  117. efx->board_info.minor = 0;
  118. /* For early boards that don't have revision info. there is
  119. * only 1 board for each PHY type, so we can work it out, with
  120. * the exception of the PHY-less boards. */
  121. switch (efx->phy_type) {
  122. case PHY_TYPE_10XPRESS:
  123. efx->board_info.type = EFX_BOARD_SFE4001;
  124. break;
  125. case PHY_TYPE_XFP:
  126. efx->board_info.type = EFX_BOARD_SFE4002;
  127. break;
  128. default:
  129. efx->board_info.type = 0;
  130. break;
  131. }
  132. } else {
  133. efx->board_info.type = BOARD_TYPE(revision_info);
  134. efx->board_info.major = BOARD_MAJOR(revision_info);
  135. efx->board_info.minor = BOARD_MINOR(revision_info);
  136. }
  137. data = &board_data[efx->board_info.type];
  138. /* Report the board model number or generic type for recognisable
  139. * boards. */
  140. if (efx->board_info.type != 0)
  141. EFX_INFO(efx, "board is %s rev %c%d\n",
  142. (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
  143. ? data->ref_model : data->gen_type,
  144. 'A' + efx->board_info.major, efx->board_info.minor);
  145. efx->board_info.init = data->init;
  146. return rc;
  147. }