boards.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. mod_timer(&bl->timer, jiffies + BLINK_INTERVAL);
  28. }
  29. static void board_blink(struct efx_nic *efx, int blink)
  30. {
  31. struct efx_blinker *blinker = &efx->board_info.blinker;
  32. /* The rtnl mutex serialises all ethtool ioctls, so
  33. * nothing special needs doing here. */
  34. if (blink) {
  35. blinker->resubmit = 1;
  36. blinker->state = 0;
  37. setup_timer(&blinker->timer, blink_led_timer,
  38. (unsigned long)efx);
  39. mod_timer(&blinker->timer, jiffies + BLINK_INTERVAL);
  40. } else {
  41. blinker->resubmit = 0;
  42. if (blinker->timer.function)
  43. del_timer_sync(&blinker->timer);
  44. efx->board_info.set_fault_led(efx, 0);
  45. }
  46. }
  47. /*****************************************************************************
  48. * Support for the SFE4002
  49. *
  50. */
  51. /****************************************************************************/
  52. /* LED allocations. Note that on rev A0 boards the schematic and the reality
  53. * differ: red and green are swapped. Below is the fixed (A1) layout (there
  54. * are only 3 A0 boards in existence, so no real reason to make this
  55. * conditional).
  56. */
  57. #define SFE4002_FAULT_LED (2) /* Red */
  58. #define SFE4002_RX_LED (0) /* Green */
  59. #define SFE4002_TX_LED (1) /* Amber */
  60. static int sfe4002_init_leds(struct efx_nic *efx)
  61. {
  62. /* Set the TX and RX LEDs to reflect status and activity, and the
  63. * fault LED off */
  64. xfp_set_led(efx, SFE4002_TX_LED,
  65. QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
  66. xfp_set_led(efx, SFE4002_RX_LED,
  67. QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
  68. xfp_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
  69. efx->board_info.blinker.led_num = SFE4002_FAULT_LED;
  70. return 0;
  71. }
  72. static void sfe4002_fault_led(struct efx_nic *efx, int state)
  73. {
  74. xfp_set_led(efx, SFE4002_FAULT_LED, state ? QUAKE_LED_ON :
  75. QUAKE_LED_OFF);
  76. }
  77. static int sfe4002_init(struct efx_nic *efx)
  78. {
  79. efx->board_info.init_leds = sfe4002_init_leds;
  80. efx->board_info.set_fault_led = sfe4002_fault_led;
  81. efx->board_info.blink = board_blink;
  82. return 0;
  83. }
  84. /* This will get expanded as board-specific details get moved out of the
  85. * PHY drivers. */
  86. struct efx_board_data {
  87. const char *ref_model;
  88. const char *gen_type;
  89. int (*init) (struct efx_nic *nic);
  90. };
  91. static int dummy_init(struct efx_nic *nic)
  92. {
  93. return 0;
  94. }
  95. static struct efx_board_data board_data[] = {
  96. [EFX_BOARD_INVALID] =
  97. {NULL, NULL, dummy_init},
  98. [EFX_BOARD_SFE4001] =
  99. {"SFE4001", "10GBASE-T adapter", sfe4001_poweron},
  100. [EFX_BOARD_SFE4002] =
  101. {"SFE4002", "XFP adapter", sfe4002_init},
  102. };
  103. int efx_set_board_info(struct efx_nic *efx, u16 revision_info)
  104. {
  105. int rc = 0;
  106. struct efx_board_data *data;
  107. if (BOARD_TYPE(revision_info) >= EFX_BOARD_MAX) {
  108. EFX_ERR(efx, "squashing unknown board type %d\n",
  109. BOARD_TYPE(revision_info));
  110. revision_info = 0;
  111. }
  112. if (BOARD_TYPE(revision_info) == 0) {
  113. efx->board_info.major = 0;
  114. efx->board_info.minor = 0;
  115. /* For early boards that don't have revision info. there is
  116. * only 1 board for each PHY type, so we can work it out, with
  117. * the exception of the PHY-less boards. */
  118. switch (efx->phy_type) {
  119. case PHY_TYPE_10XPRESS:
  120. efx->board_info.type = EFX_BOARD_SFE4001;
  121. break;
  122. case PHY_TYPE_XFP:
  123. efx->board_info.type = EFX_BOARD_SFE4002;
  124. break;
  125. default:
  126. efx->board_info.type = 0;
  127. break;
  128. }
  129. } else {
  130. efx->board_info.type = BOARD_TYPE(revision_info);
  131. efx->board_info.major = BOARD_MAJOR(revision_info);
  132. efx->board_info.minor = BOARD_MINOR(revision_info);
  133. }
  134. data = &board_data[efx->board_info.type];
  135. /* Report the board model number or generic type for recognisable
  136. * boards. */
  137. if (efx->board_info.type != 0)
  138. EFX_INFO(efx, "board is %s rev %c%d\n",
  139. (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
  140. ? data->ref_model : data->gen_type,
  141. 'A' + efx->board_info.major, efx->board_info.minor);
  142. efx->board_info.init = data->init;
  143. return rc;
  144. }