boards.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. /****************************************************************************
  2. * Driver for Solarflare Solarstorm network controllers and boards
  3. * Copyright 2007-2008 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. #include "workarounds.h"
  14. /* Macros for unpacking the board revision */
  15. /* The revision info is in host byte order. */
  16. #define BOARD_TYPE(_rev) (_rev >> 8)
  17. #define BOARD_MAJOR(_rev) ((_rev >> 4) & 0xf)
  18. #define BOARD_MINOR(_rev) (_rev & 0xf)
  19. /* Blink support. If the PHY has no auto-blink mode so we hang it off a timer */
  20. #define BLINK_INTERVAL (HZ/2)
  21. static void blink_led_timer(unsigned long context)
  22. {
  23. struct efx_nic *efx = (struct efx_nic *)context;
  24. struct efx_blinker *bl = &efx->board_info.blinker;
  25. efx->board_info.set_id_led(efx, bl->state);
  26. bl->state = !bl->state;
  27. if (bl->resubmit)
  28. mod_timer(&bl->timer, jiffies + BLINK_INTERVAL);
  29. }
  30. static void board_blink(struct efx_nic *efx, bool blink)
  31. {
  32. struct efx_blinker *blinker = &efx->board_info.blinker;
  33. /* The rtnl mutex serialises all ethtool ioctls, so
  34. * nothing special needs doing here. */
  35. if (blink) {
  36. blinker->resubmit = true;
  37. blinker->state = false;
  38. setup_timer(&blinker->timer, blink_led_timer,
  39. (unsigned long)efx);
  40. mod_timer(&blinker->timer, jiffies + BLINK_INTERVAL);
  41. } else {
  42. blinker->resubmit = false;
  43. if (blinker->timer.function)
  44. del_timer_sync(&blinker->timer);
  45. efx->board_info.init_leds(efx);
  46. }
  47. }
  48. /*****************************************************************************
  49. * Support for LM87 sensor chip used on several boards
  50. */
  51. #define LM87_REG_ALARMS1 0x41
  52. #define LM87_REG_ALARMS2 0x42
  53. #define LM87_IN_LIMITS(nr, _min, _max) \
  54. 0x2B + (nr) * 2, _max, 0x2C + (nr) * 2, _min
  55. #define LM87_AIN_LIMITS(nr, _min, _max) \
  56. 0x3B + (nr), _max, 0x1A + (nr), _min
  57. #define LM87_TEMP_INT_LIMITS(_min, _max) \
  58. 0x39, _max, 0x3A, _min
  59. #define LM87_TEMP_EXT1_LIMITS(_min, _max) \
  60. 0x37, _max, 0x38, _min
  61. #define LM87_ALARM_TEMP_INT 0x10
  62. #define LM87_ALARM_TEMP_EXT1 0x20
  63. #if defined(CONFIG_SENSORS_LM87) || defined(CONFIG_SENSORS_LM87_MODULE)
  64. static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
  65. const u8 *reg_values)
  66. {
  67. struct i2c_client *client = i2c_new_device(&efx->i2c_adap, info);
  68. int rc;
  69. if (!client)
  70. return -EIO;
  71. while (*reg_values) {
  72. u8 reg = *reg_values++;
  73. u8 value = *reg_values++;
  74. rc = i2c_smbus_write_byte_data(client, reg, value);
  75. if (rc)
  76. goto err;
  77. }
  78. efx->board_info.hwmon_client = client;
  79. return 0;
  80. err:
  81. i2c_unregister_device(client);
  82. return rc;
  83. }
  84. static void efx_fini_lm87(struct efx_nic *efx)
  85. {
  86. i2c_unregister_device(efx->board_info.hwmon_client);
  87. }
  88. static int efx_check_lm87(struct efx_nic *efx, unsigned mask)
  89. {
  90. struct i2c_client *client = efx->board_info.hwmon_client;
  91. s32 alarms1, alarms2;
  92. /* If link is up then do not monitor temperature */
  93. if (EFX_WORKAROUND_7884(efx) && efx->link_up)
  94. return 0;
  95. alarms1 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1);
  96. alarms2 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2);
  97. if (alarms1 < 0)
  98. return alarms1;
  99. if (alarms2 < 0)
  100. return alarms2;
  101. alarms1 &= mask;
  102. alarms2 &= mask >> 8;
  103. if (alarms1 || alarms2) {
  104. EFX_ERR(efx,
  105. "LM87 detected a hardware failure (status %02x:%02x)"
  106. "%s%s\n",
  107. alarms1, alarms2,
  108. (alarms1 & LM87_ALARM_TEMP_INT) ? " INTERNAL" : "",
  109. (alarms1 & LM87_ALARM_TEMP_EXT1) ? " EXTERNAL" : "");
  110. return -ERANGE;
  111. }
  112. return 0;
  113. }
  114. #else /* !CONFIG_SENSORS_LM87 */
  115. static inline int
  116. efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
  117. const u8 *reg_values)
  118. {
  119. return 0;
  120. }
  121. static inline void efx_fini_lm87(struct efx_nic *efx)
  122. {
  123. }
  124. static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask)
  125. {
  126. return 0;
  127. }
  128. #endif /* CONFIG_SENSORS_LM87 */
  129. /*****************************************************************************
  130. * Support for the SFE4002
  131. *
  132. */
  133. static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */
  134. static const u8 sfe4002_lm87_regs[] = {
  135. LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
  136. LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
  137. LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
  138. LM87_IN_LIMITS(3, 0xb0, 0xc9), /* 5V: 4.6-5.2V */
  139. LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
  140. LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
  141. LM87_AIN_LIMITS(0, 0xa0, 0xb2), /* AIN1: 1.66V +/- 5% */
  142. LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
  143. LM87_TEMP_INT_LIMITS(10, 60), /* board */
  144. LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
  145. 0
  146. };
  147. static struct i2c_board_info sfe4002_hwmon_info = {
  148. I2C_BOARD_INFO("lm87", 0x2e),
  149. .platform_data = &sfe4002_lm87_channel,
  150. };
  151. /****************************************************************************/
  152. /* LED allocations. Note that on rev A0 boards the schematic and the reality
  153. * differ: red and green are swapped. Below is the fixed (A1) layout (there
  154. * are only 3 A0 boards in existence, so no real reason to make this
  155. * conditional).
  156. */
  157. #define SFE4002_FAULT_LED (2) /* Red */
  158. #define SFE4002_RX_LED (0) /* Green */
  159. #define SFE4002_TX_LED (1) /* Amber */
  160. static void sfe4002_init_leds(struct efx_nic *efx)
  161. {
  162. /* Set the TX and RX LEDs to reflect status and activity, and the
  163. * fault LED off */
  164. xfp_set_led(efx, SFE4002_TX_LED,
  165. QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
  166. xfp_set_led(efx, SFE4002_RX_LED,
  167. QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
  168. xfp_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
  169. }
  170. static void sfe4002_set_id_led(struct efx_nic *efx, bool state)
  171. {
  172. xfp_set_led(efx, SFE4002_FAULT_LED, state ? QUAKE_LED_ON :
  173. QUAKE_LED_OFF);
  174. }
  175. static int sfe4002_check_hw(struct efx_nic *efx)
  176. {
  177. /* A0 board rev. 4002s report a temperature fault the whole time
  178. * (bad sensor) so we mask it out. */
  179. unsigned alarm_mask =
  180. (efx->board_info.major == 0 && efx->board_info.minor == 0) ?
  181. ~LM87_ALARM_TEMP_EXT1 : ~0;
  182. return efx_check_lm87(efx, alarm_mask);
  183. }
  184. static int sfe4002_init(struct efx_nic *efx)
  185. {
  186. int rc = efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs);
  187. if (rc)
  188. return rc;
  189. efx->board_info.monitor = sfe4002_check_hw;
  190. efx->board_info.init_leds = sfe4002_init_leds;
  191. efx->board_info.set_id_led = sfe4002_set_id_led;
  192. efx->board_info.blink = board_blink;
  193. efx->board_info.fini = efx_fini_lm87;
  194. return 0;
  195. }
  196. /*****************************************************************************
  197. * Support for the SFN4112F
  198. *
  199. */
  200. static u8 sfn4112f_lm87_channel = 0x03; /* use AIN not FAN inputs */
  201. static const u8 sfn4112f_lm87_regs[] = {
  202. LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
  203. LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
  204. LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
  205. LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
  206. LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
  207. LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
  208. LM87_TEMP_INT_LIMITS(10, 60), /* board */
  209. LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
  210. 0
  211. };
  212. static struct i2c_board_info sfn4112f_hwmon_info = {
  213. I2C_BOARD_INFO("lm87", 0x2e),
  214. .platform_data = &sfn4112f_lm87_channel,
  215. };
  216. #define SFN4112F_ACT_LED 0
  217. #define SFN4112F_LINK_LED 1
  218. static void sfn4112f_init_leds(struct efx_nic *efx)
  219. {
  220. xfp_set_led(efx, SFN4112F_ACT_LED,
  221. QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACT);
  222. xfp_set_led(efx, SFN4112F_LINK_LED,
  223. QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT);
  224. }
  225. static void sfn4112f_set_id_led(struct efx_nic *efx, bool state)
  226. {
  227. xfp_set_led(efx, SFN4112F_LINK_LED,
  228. state ? QUAKE_LED_ON : QUAKE_LED_OFF);
  229. }
  230. static int sfn4112f_check_hw(struct efx_nic *efx)
  231. {
  232. /* Mask out unused sensors */
  233. return efx_check_lm87(efx, ~0x48);
  234. }
  235. static int sfn4112f_init(struct efx_nic *efx)
  236. {
  237. int rc = efx_init_lm87(efx, &sfn4112f_hwmon_info, sfn4112f_lm87_regs);
  238. if (rc)
  239. return rc;
  240. efx->board_info.monitor = sfn4112f_check_hw;
  241. efx->board_info.init_leds = sfn4112f_init_leds;
  242. efx->board_info.set_id_led = sfn4112f_set_id_led;
  243. efx->board_info.blink = board_blink;
  244. efx->board_info.fini = efx_fini_lm87;
  245. return 0;
  246. }
  247. /* This will get expanded as board-specific details get moved out of the
  248. * PHY drivers. */
  249. struct efx_board_data {
  250. enum efx_board_type type;
  251. const char *ref_model;
  252. const char *gen_type;
  253. int (*init) (struct efx_nic *nic);
  254. };
  255. static struct efx_board_data board_data[] = {
  256. { EFX_BOARD_SFE4001, "SFE4001", "10GBASE-T adapter", sfe4001_init },
  257. { EFX_BOARD_SFE4002, "SFE4002", "XFP adapter", sfe4002_init },
  258. { EFX_BOARD_SFN4111T, "SFN4111T", "100/1000/10GBASE-T adapter",
  259. sfn4111t_init },
  260. { EFX_BOARD_SFN4112F, "SFN4112F", "SFP+ adapter",
  261. sfn4112f_init },
  262. };
  263. void efx_set_board_info(struct efx_nic *efx, u16 revision_info)
  264. {
  265. struct efx_board_data *data = NULL;
  266. int i;
  267. efx->board_info.type = BOARD_TYPE(revision_info);
  268. efx->board_info.major = BOARD_MAJOR(revision_info);
  269. efx->board_info.minor = BOARD_MINOR(revision_info);
  270. for (i = 0; i < ARRAY_SIZE(board_data); i++)
  271. if (board_data[i].type == efx->board_info.type)
  272. data = &board_data[i];
  273. if (data) {
  274. EFX_INFO(efx, "board is %s rev %c%d\n",
  275. (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
  276. ? data->ref_model : data->gen_type,
  277. 'A' + efx->board_info.major, efx->board_info.minor);
  278. efx->board_info.init = data->init;
  279. } else {
  280. EFX_ERR(efx, "unknown board type %d\n", efx->board_info.type);
  281. }
  282. }