falcon_boards.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  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 <linux/rtnetlink.h>
  10. #include "net_driver.h"
  11. #include "phy.h"
  12. #include "efx.h"
  13. #include "falcon.h"
  14. #include "regs.h"
  15. #include "io.h"
  16. #include "workarounds.h"
  17. /* Macros for unpacking the board revision */
  18. /* The revision info is in host byte order. */
  19. #define FALCON_BOARD_TYPE(_rev) (_rev >> 8)
  20. #define FALCON_BOARD_MAJOR(_rev) ((_rev >> 4) & 0xf)
  21. #define FALCON_BOARD_MINOR(_rev) (_rev & 0xf)
  22. /* Board types */
  23. #define FALCON_BOARD_SFE4001 0x01
  24. #define FALCON_BOARD_SFE4002 0x02
  25. #define FALCON_BOARD_SFN4111T 0x51
  26. #define FALCON_BOARD_SFN4112F 0x52
  27. /* Blink support. If the PHY has no auto-blink mode so we hang it off a timer */
  28. #define BLINK_INTERVAL (HZ/2)
  29. static void blink_led_timer(unsigned long context)
  30. {
  31. struct efx_nic *efx = (struct efx_nic *)context;
  32. struct efx_board *board = &efx->board_info;
  33. board->set_id_led(efx, board->blink_state);
  34. board->blink_state = !board->blink_state;
  35. if (board->blink_resubmit)
  36. mod_timer(&board->blink_timer, jiffies + BLINK_INTERVAL);
  37. }
  38. static void board_blink(struct efx_nic *efx, bool blink)
  39. {
  40. struct efx_board *board = &efx->board_info;
  41. /* The rtnl mutex serialises all ethtool ioctls, so
  42. * nothing special needs doing here. */
  43. if (blink) {
  44. board->blink_resubmit = true;
  45. board->blink_state = false;
  46. setup_timer(&board->blink_timer, blink_led_timer,
  47. (unsigned long)efx);
  48. mod_timer(&board->blink_timer, jiffies + BLINK_INTERVAL);
  49. } else {
  50. board->blink_resubmit = false;
  51. if (board->blink_timer.function)
  52. del_timer_sync(&board->blink_timer);
  53. board->init_leds(efx);
  54. }
  55. }
  56. /*****************************************************************************
  57. * Support for LM87 sensor chip used on several boards
  58. */
  59. #define LM87_REG_ALARMS1 0x41
  60. #define LM87_REG_ALARMS2 0x42
  61. #define LM87_IN_LIMITS(nr, _min, _max) \
  62. 0x2B + (nr) * 2, _max, 0x2C + (nr) * 2, _min
  63. #define LM87_AIN_LIMITS(nr, _min, _max) \
  64. 0x3B + (nr), _max, 0x1A + (nr), _min
  65. #define LM87_TEMP_INT_LIMITS(_min, _max) \
  66. 0x39, _max, 0x3A, _min
  67. #define LM87_TEMP_EXT1_LIMITS(_min, _max) \
  68. 0x37, _max, 0x38, _min
  69. #define LM87_ALARM_TEMP_INT 0x10
  70. #define LM87_ALARM_TEMP_EXT1 0x20
  71. #if defined(CONFIG_SENSORS_LM87) || defined(CONFIG_SENSORS_LM87_MODULE)
  72. static int efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
  73. const u8 *reg_values)
  74. {
  75. struct i2c_client *client = i2c_new_device(&efx->i2c_adap, info);
  76. int rc;
  77. if (!client)
  78. return -EIO;
  79. while (*reg_values) {
  80. u8 reg = *reg_values++;
  81. u8 value = *reg_values++;
  82. rc = i2c_smbus_write_byte_data(client, reg, value);
  83. if (rc)
  84. goto err;
  85. }
  86. efx->board_info.hwmon_client = client;
  87. return 0;
  88. err:
  89. i2c_unregister_device(client);
  90. return rc;
  91. }
  92. static void efx_fini_lm87(struct efx_nic *efx)
  93. {
  94. i2c_unregister_device(efx->board_info.hwmon_client);
  95. }
  96. static int efx_check_lm87(struct efx_nic *efx, unsigned mask)
  97. {
  98. struct i2c_client *client = efx->board_info.hwmon_client;
  99. s32 alarms1, alarms2;
  100. /* If link is up then do not monitor temperature */
  101. if (EFX_WORKAROUND_7884(efx) && efx->link_up)
  102. return 0;
  103. alarms1 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS1);
  104. alarms2 = i2c_smbus_read_byte_data(client, LM87_REG_ALARMS2);
  105. if (alarms1 < 0)
  106. return alarms1;
  107. if (alarms2 < 0)
  108. return alarms2;
  109. alarms1 &= mask;
  110. alarms2 &= mask >> 8;
  111. if (alarms1 || alarms2) {
  112. EFX_ERR(efx,
  113. "LM87 detected a hardware failure (status %02x:%02x)"
  114. "%s%s\n",
  115. alarms1, alarms2,
  116. (alarms1 & LM87_ALARM_TEMP_INT) ? " INTERNAL" : "",
  117. (alarms1 & LM87_ALARM_TEMP_EXT1) ? " EXTERNAL" : "");
  118. return -ERANGE;
  119. }
  120. return 0;
  121. }
  122. #else /* !CONFIG_SENSORS_LM87 */
  123. static inline int
  124. efx_init_lm87(struct efx_nic *efx, struct i2c_board_info *info,
  125. const u8 *reg_values)
  126. {
  127. return 0;
  128. }
  129. static inline void efx_fini_lm87(struct efx_nic *efx)
  130. {
  131. }
  132. static inline int efx_check_lm87(struct efx_nic *efx, unsigned mask)
  133. {
  134. return 0;
  135. }
  136. #endif /* CONFIG_SENSORS_LM87 */
  137. /*****************************************************************************
  138. * Support for the SFE4001 and SFN4111T NICs.
  139. *
  140. * The SFE4001 does not power-up fully at reset due to its high power
  141. * consumption. We control its power via a PCA9539 I/O expander.
  142. * Both boards have a MAX6647 temperature monitor which we expose to
  143. * the lm90 driver.
  144. *
  145. * This also provides minimal support for reflashing the PHY, which is
  146. * initiated by resetting it with the FLASH_CFG_1 pin pulled down.
  147. * On SFE4001 rev A2 and later this is connected to the 3V3X output of
  148. * the IO-expander; on the SFN4111T it is connected to Falcon's GPIO3.
  149. * We represent reflash mode as PHY_MODE_SPECIAL and make it mutually
  150. * exclusive with the network device being open.
  151. */
  152. /**************************************************************************
  153. * Support for I2C IO Expander device on SFE40001
  154. */
  155. #define PCA9539 0x74
  156. #define P0_IN 0x00
  157. #define P0_OUT 0x02
  158. #define P0_INVERT 0x04
  159. #define P0_CONFIG 0x06
  160. #define P0_EN_1V0X_LBN 0
  161. #define P0_EN_1V0X_WIDTH 1
  162. #define P0_EN_1V2_LBN 1
  163. #define P0_EN_1V2_WIDTH 1
  164. #define P0_EN_2V5_LBN 2
  165. #define P0_EN_2V5_WIDTH 1
  166. #define P0_EN_3V3X_LBN 3
  167. #define P0_EN_3V3X_WIDTH 1
  168. #define P0_EN_5V_LBN 4
  169. #define P0_EN_5V_WIDTH 1
  170. #define P0_SHORTEN_JTAG_LBN 5
  171. #define P0_SHORTEN_JTAG_WIDTH 1
  172. #define P0_X_TRST_LBN 6
  173. #define P0_X_TRST_WIDTH 1
  174. #define P0_DSP_RESET_LBN 7
  175. #define P0_DSP_RESET_WIDTH 1
  176. #define P1_IN 0x01
  177. #define P1_OUT 0x03
  178. #define P1_INVERT 0x05
  179. #define P1_CONFIG 0x07
  180. #define P1_AFE_PWD_LBN 0
  181. #define P1_AFE_PWD_WIDTH 1
  182. #define P1_DSP_PWD25_LBN 1
  183. #define P1_DSP_PWD25_WIDTH 1
  184. #define P1_RESERVED_LBN 2
  185. #define P1_RESERVED_WIDTH 2
  186. #define P1_SPARE_LBN 4
  187. #define P1_SPARE_WIDTH 4
  188. /* Temperature Sensor */
  189. #define MAX664X_REG_RSL 0x02
  190. #define MAX664X_REG_WLHO 0x0B
  191. static void sfe4001_poweroff(struct efx_nic *efx)
  192. {
  193. struct i2c_client *ioexp_client = efx->board_info.ioexp_client;
  194. struct i2c_client *hwmon_client = efx->board_info.hwmon_client;
  195. /* Turn off all power rails and disable outputs */
  196. i2c_smbus_write_byte_data(ioexp_client, P0_OUT, 0xff);
  197. i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG, 0xff);
  198. i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0xff);
  199. /* Clear any over-temperature alert */
  200. i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
  201. }
  202. static int sfe4001_poweron(struct efx_nic *efx)
  203. {
  204. struct i2c_client *hwmon_client = efx->board_info.hwmon_client;
  205. struct i2c_client *ioexp_client = efx->board_info.ioexp_client;
  206. unsigned int i, j;
  207. int rc;
  208. u8 out;
  209. /* Clear any previous over-temperature alert */
  210. rc = i2c_smbus_read_byte_data(hwmon_client, MAX664X_REG_RSL);
  211. if (rc < 0)
  212. return rc;
  213. /* Enable port 0 and port 1 outputs on IO expander */
  214. rc = i2c_smbus_write_byte_data(ioexp_client, P0_CONFIG, 0x00);
  215. if (rc)
  216. return rc;
  217. rc = i2c_smbus_write_byte_data(ioexp_client, P1_CONFIG,
  218. 0xff & ~(1 << P1_SPARE_LBN));
  219. if (rc)
  220. goto fail_on;
  221. /* If PHY power is on, turn it all off and wait 1 second to
  222. * ensure a full reset.
  223. */
  224. rc = i2c_smbus_read_byte_data(ioexp_client, P0_OUT);
  225. if (rc < 0)
  226. goto fail_on;
  227. out = 0xff & ~((0 << P0_EN_1V2_LBN) | (0 << P0_EN_2V5_LBN) |
  228. (0 << P0_EN_3V3X_LBN) | (0 << P0_EN_5V_LBN) |
  229. (0 << P0_EN_1V0X_LBN));
  230. if (rc != out) {
  231. EFX_INFO(efx, "power-cycling PHY\n");
  232. rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
  233. if (rc)
  234. goto fail_on;
  235. schedule_timeout_uninterruptible(HZ);
  236. }
  237. for (i = 0; i < 20; ++i) {
  238. /* Turn on 1.2V, 2.5V, 3.3V and 5V power rails */
  239. out = 0xff & ~((1 << P0_EN_1V2_LBN) | (1 << P0_EN_2V5_LBN) |
  240. (1 << P0_EN_3V3X_LBN) | (1 << P0_EN_5V_LBN) |
  241. (1 << P0_X_TRST_LBN));
  242. if (efx->phy_mode & PHY_MODE_SPECIAL)
  243. out |= 1 << P0_EN_3V3X_LBN;
  244. rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
  245. if (rc)
  246. goto fail_on;
  247. msleep(10);
  248. /* Turn on 1V power rail */
  249. out &= ~(1 << P0_EN_1V0X_LBN);
  250. rc = i2c_smbus_write_byte_data(ioexp_client, P0_OUT, out);
  251. if (rc)
  252. goto fail_on;
  253. EFX_INFO(efx, "waiting for DSP boot (attempt %d)...\n", i);
  254. /* In flash config mode, DSP does not turn on AFE, so
  255. * just wait 1 second.
  256. */
  257. if (efx->phy_mode & PHY_MODE_SPECIAL) {
  258. schedule_timeout_uninterruptible(HZ);
  259. return 0;
  260. }
  261. for (j = 0; j < 10; ++j) {
  262. msleep(100);
  263. /* Check DSP has asserted AFE power line */
  264. rc = i2c_smbus_read_byte_data(ioexp_client, P1_IN);
  265. if (rc < 0)
  266. goto fail_on;
  267. if (rc & (1 << P1_AFE_PWD_LBN))
  268. return 0;
  269. }
  270. }
  271. EFX_INFO(efx, "timed out waiting for DSP boot\n");
  272. rc = -ETIMEDOUT;
  273. fail_on:
  274. sfe4001_poweroff(efx);
  275. return rc;
  276. }
  277. static int sfn4111t_reset(struct efx_nic *efx)
  278. {
  279. efx_oword_t reg;
  280. /* GPIO 3 and the GPIO register are shared with I2C, so block that */
  281. mutex_lock(&efx->i2c_adap.bus_lock);
  282. /* Pull RST_N (GPIO 2) low then let it up again, setting the
  283. * FLASH_CFG_1 strap (GPIO 3) appropriately. Only change the
  284. * output enables; the output levels should always be 0 (low)
  285. * and we rely on external pull-ups. */
  286. efx_reado(efx, &reg, FR_AB_GPIO_CTL);
  287. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, true);
  288. efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
  289. msleep(1000);
  290. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO2_OEN, false);
  291. EFX_SET_OWORD_FIELD(reg, FRF_AB_GPIO3_OEN,
  292. !!(efx->phy_mode & PHY_MODE_SPECIAL));
  293. efx_writeo(efx, &reg, FR_AB_GPIO_CTL);
  294. msleep(1);
  295. mutex_unlock(&efx->i2c_adap.bus_lock);
  296. ssleep(1);
  297. return 0;
  298. }
  299. static ssize_t show_phy_flash_cfg(struct device *dev,
  300. struct device_attribute *attr, char *buf)
  301. {
  302. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  303. return sprintf(buf, "%d\n", !!(efx->phy_mode & PHY_MODE_SPECIAL));
  304. }
  305. static ssize_t set_phy_flash_cfg(struct device *dev,
  306. struct device_attribute *attr,
  307. const char *buf, size_t count)
  308. {
  309. struct efx_nic *efx = pci_get_drvdata(to_pci_dev(dev));
  310. enum efx_phy_mode old_mode, new_mode;
  311. int err;
  312. rtnl_lock();
  313. old_mode = efx->phy_mode;
  314. if (count == 0 || *buf == '0')
  315. new_mode = old_mode & ~PHY_MODE_SPECIAL;
  316. else
  317. new_mode = PHY_MODE_SPECIAL;
  318. if (old_mode == new_mode) {
  319. err = 0;
  320. } else if (efx->state != STATE_RUNNING || netif_running(efx->net_dev)) {
  321. err = -EBUSY;
  322. } else {
  323. /* Reset the PHY, reconfigure the MAC and enable/disable
  324. * MAC stats accordingly. */
  325. efx->phy_mode = new_mode;
  326. if (new_mode & PHY_MODE_SPECIAL)
  327. efx_stats_disable(efx);
  328. if (efx->board_info.type == FALCON_BOARD_SFE4001)
  329. err = sfe4001_poweron(efx);
  330. else
  331. err = sfn4111t_reset(efx);
  332. efx_reconfigure_port(efx);
  333. if (!(new_mode & PHY_MODE_SPECIAL))
  334. efx_stats_enable(efx);
  335. }
  336. rtnl_unlock();
  337. return err ? err : count;
  338. }
  339. static DEVICE_ATTR(phy_flash_cfg, 0644, show_phy_flash_cfg, set_phy_flash_cfg);
  340. static void sfe4001_fini(struct efx_nic *efx)
  341. {
  342. EFX_INFO(efx, "%s\n", __func__);
  343. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
  344. sfe4001_poweroff(efx);
  345. i2c_unregister_device(efx->board_info.ioexp_client);
  346. i2c_unregister_device(efx->board_info.hwmon_client);
  347. }
  348. static int sfe4001_check_hw(struct efx_nic *efx)
  349. {
  350. s32 status;
  351. /* If XAUI link is up then do not monitor */
  352. if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
  353. return 0;
  354. /* Check the powered status of the PHY. Lack of power implies that
  355. * the MAX6647 has shut down power to it, probably due to a temp.
  356. * alarm. Reading the power status rather than the MAX6647 status
  357. * directly because the later is read-to-clear and would thus
  358. * start to power up the PHY again when polled, causing us to blip
  359. * the power undesirably.
  360. * We know we can read from the IO expander because we did
  361. * it during power-on. Assume failure now is bad news. */
  362. status = i2c_smbus_read_byte_data(efx->board_info.ioexp_client, P1_IN);
  363. if (status >= 0 &&
  364. (status & ((1 << P1_AFE_PWD_LBN) | (1 << P1_DSP_PWD25_LBN))) != 0)
  365. return 0;
  366. /* Use board power control, not PHY power control */
  367. sfe4001_poweroff(efx);
  368. efx->phy_mode = PHY_MODE_OFF;
  369. return (status < 0) ? -EIO : -ERANGE;
  370. }
  371. static struct i2c_board_info sfe4001_hwmon_info = {
  372. I2C_BOARD_INFO("max6647", 0x4e),
  373. };
  374. /* This board uses an I2C expander to provider power to the PHY, which needs to
  375. * be turned on before the PHY can be used.
  376. * Context: Process context, rtnl lock held
  377. */
  378. static int sfe4001_init(struct efx_nic *efx)
  379. {
  380. int rc;
  381. #if defined(CONFIG_SENSORS_LM90) || defined(CONFIG_SENSORS_LM90_MODULE)
  382. efx->board_info.hwmon_client =
  383. i2c_new_device(&efx->i2c_adap, &sfe4001_hwmon_info);
  384. #else
  385. efx->board_info.hwmon_client =
  386. i2c_new_dummy(&efx->i2c_adap, sfe4001_hwmon_info.addr);
  387. #endif
  388. if (!efx->board_info.hwmon_client)
  389. return -EIO;
  390. /* Raise board/PHY high limit from 85 to 90 degrees Celsius */
  391. rc = i2c_smbus_write_byte_data(efx->board_info.hwmon_client,
  392. MAX664X_REG_WLHO, 90);
  393. if (rc)
  394. goto fail_hwmon;
  395. efx->board_info.ioexp_client = i2c_new_dummy(&efx->i2c_adap, PCA9539);
  396. if (!efx->board_info.ioexp_client) {
  397. rc = -EIO;
  398. goto fail_hwmon;
  399. }
  400. /* 10Xpress has fixed-function LED pins, so there is no board-specific
  401. * blink code. */
  402. efx->board_info.blink = tenxpress_phy_blink;
  403. efx->board_info.monitor = sfe4001_check_hw;
  404. efx->board_info.fini = sfe4001_fini;
  405. if (efx->phy_mode & PHY_MODE_SPECIAL) {
  406. /* PHY won't generate a 156.25 MHz clock and MAC stats fetch
  407. * will fail. */
  408. efx_stats_disable(efx);
  409. }
  410. rc = sfe4001_poweron(efx);
  411. if (rc)
  412. goto fail_ioexp;
  413. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
  414. if (rc)
  415. goto fail_on;
  416. EFX_INFO(efx, "PHY is powered on\n");
  417. return 0;
  418. fail_on:
  419. sfe4001_poweroff(efx);
  420. fail_ioexp:
  421. i2c_unregister_device(efx->board_info.ioexp_client);
  422. fail_hwmon:
  423. i2c_unregister_device(efx->board_info.hwmon_client);
  424. return rc;
  425. }
  426. static int sfn4111t_check_hw(struct efx_nic *efx)
  427. {
  428. s32 status;
  429. /* If XAUI link is up then do not monitor */
  430. if (EFX_WORKAROUND_7884(efx) && efx->mac_up)
  431. return 0;
  432. /* Test LHIGH, RHIGH, FAULT, EOT and IOT alarms */
  433. status = i2c_smbus_read_byte_data(efx->board_info.hwmon_client,
  434. MAX664X_REG_RSL);
  435. if (status < 0)
  436. return -EIO;
  437. if (status & 0x57)
  438. return -ERANGE;
  439. return 0;
  440. }
  441. static void sfn4111t_fini(struct efx_nic *efx)
  442. {
  443. EFX_INFO(efx, "%s\n", __func__);
  444. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
  445. i2c_unregister_device(efx->board_info.hwmon_client);
  446. }
  447. static struct i2c_board_info sfn4111t_a0_hwmon_info = {
  448. I2C_BOARD_INFO("max6647", 0x4e),
  449. };
  450. static struct i2c_board_info sfn4111t_r5_hwmon_info = {
  451. I2C_BOARD_INFO("max6646", 0x4d),
  452. };
  453. static int sfn4111t_init(struct efx_nic *efx)
  454. {
  455. int i = 0;
  456. int rc;
  457. efx->board_info.hwmon_client =
  458. i2c_new_device(&efx->i2c_adap,
  459. (efx->board_info.minor < 5) ?
  460. &sfn4111t_a0_hwmon_info :
  461. &sfn4111t_r5_hwmon_info);
  462. if (!efx->board_info.hwmon_client)
  463. return -EIO;
  464. efx->board_info.blink = tenxpress_phy_blink;
  465. efx->board_info.monitor = sfn4111t_check_hw;
  466. efx->board_info.fini = sfn4111t_fini;
  467. rc = device_create_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
  468. if (rc)
  469. goto fail_hwmon;
  470. do {
  471. if (efx->phy_mode & PHY_MODE_SPECIAL) {
  472. /* PHY may not generate a 156.25 MHz clock and MAC
  473. * stats fetch will fail. */
  474. efx_stats_disable(efx);
  475. sfn4111t_reset(efx);
  476. }
  477. rc = sft9001_wait_boot(efx);
  478. if (rc == 0)
  479. return 0;
  480. efx->phy_mode = PHY_MODE_SPECIAL;
  481. } while (rc == -EINVAL && ++i < 2);
  482. device_remove_file(&efx->pci_dev->dev, &dev_attr_phy_flash_cfg);
  483. fail_hwmon:
  484. i2c_unregister_device(efx->board_info.hwmon_client);
  485. return rc;
  486. }
  487. /*****************************************************************************
  488. * Support for the SFE4002
  489. *
  490. */
  491. static u8 sfe4002_lm87_channel = 0x03; /* use AIN not FAN inputs */
  492. static const u8 sfe4002_lm87_regs[] = {
  493. LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
  494. LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
  495. LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
  496. LM87_IN_LIMITS(3, 0xb0, 0xc9), /* 5V: 4.6-5.2V */
  497. LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
  498. LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
  499. LM87_AIN_LIMITS(0, 0xa0, 0xb2), /* AIN1: 1.66V +/- 5% */
  500. LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
  501. LM87_TEMP_INT_LIMITS(10, 60), /* board */
  502. LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
  503. 0
  504. };
  505. static struct i2c_board_info sfe4002_hwmon_info = {
  506. I2C_BOARD_INFO("lm87", 0x2e),
  507. .platform_data = &sfe4002_lm87_channel,
  508. };
  509. /****************************************************************************/
  510. /* LED allocations. Note that on rev A0 boards the schematic and the reality
  511. * differ: red and green are swapped. Below is the fixed (A1) layout (there
  512. * are only 3 A0 boards in existence, so no real reason to make this
  513. * conditional).
  514. */
  515. #define SFE4002_FAULT_LED (2) /* Red */
  516. #define SFE4002_RX_LED (0) /* Green */
  517. #define SFE4002_TX_LED (1) /* Amber */
  518. static void sfe4002_init_leds(struct efx_nic *efx)
  519. {
  520. /* Set the TX and RX LEDs to reflect status and activity, and the
  521. * fault LED off */
  522. falcon_qt202x_set_led(efx, SFE4002_TX_LED,
  523. QUAKE_LED_TXLINK | QUAKE_LED_LINK_ACTSTAT);
  524. falcon_qt202x_set_led(efx, SFE4002_RX_LED,
  525. QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACTSTAT);
  526. falcon_qt202x_set_led(efx, SFE4002_FAULT_LED, QUAKE_LED_OFF);
  527. }
  528. static void sfe4002_set_id_led(struct efx_nic *efx, bool state)
  529. {
  530. falcon_qt202x_set_led(efx, SFE4002_FAULT_LED, state ? QUAKE_LED_ON :
  531. QUAKE_LED_OFF);
  532. }
  533. static int sfe4002_check_hw(struct efx_nic *efx)
  534. {
  535. /* A0 board rev. 4002s report a temperature fault the whole time
  536. * (bad sensor) so we mask it out. */
  537. unsigned alarm_mask =
  538. (efx->board_info.major == 0 && efx->board_info.minor == 0) ?
  539. ~LM87_ALARM_TEMP_EXT1 : ~0;
  540. return efx_check_lm87(efx, alarm_mask);
  541. }
  542. static int sfe4002_init(struct efx_nic *efx)
  543. {
  544. int rc = efx_init_lm87(efx, &sfe4002_hwmon_info, sfe4002_lm87_regs);
  545. if (rc)
  546. return rc;
  547. efx->board_info.monitor = sfe4002_check_hw;
  548. efx->board_info.init_leds = sfe4002_init_leds;
  549. efx->board_info.set_id_led = sfe4002_set_id_led;
  550. efx->board_info.blink = board_blink;
  551. efx->board_info.fini = efx_fini_lm87;
  552. return 0;
  553. }
  554. /*****************************************************************************
  555. * Support for the SFN4112F
  556. *
  557. */
  558. static u8 sfn4112f_lm87_channel = 0x03; /* use AIN not FAN inputs */
  559. static const u8 sfn4112f_lm87_regs[] = {
  560. LM87_IN_LIMITS(0, 0x83, 0x91), /* 2.5V: 1.8V +/- 5% */
  561. LM87_IN_LIMITS(1, 0x51, 0x5a), /* Vccp1: 1.2V +/- 5% */
  562. LM87_IN_LIMITS(2, 0xb6, 0xca), /* 3.3V: 3.3V +/- 5% */
  563. LM87_IN_LIMITS(4, 0xb0, 0xe0), /* 12V: 11-14V */
  564. LM87_IN_LIMITS(5, 0x44, 0x4b), /* Vccp2: 1.0V +/- 5% */
  565. LM87_AIN_LIMITS(1, 0x91, 0xa1), /* AIN2: 1.5V +/- 5% */
  566. LM87_TEMP_INT_LIMITS(10, 60), /* board */
  567. LM87_TEMP_EXT1_LIMITS(10, 70), /* Falcon */
  568. 0
  569. };
  570. static struct i2c_board_info sfn4112f_hwmon_info = {
  571. I2C_BOARD_INFO("lm87", 0x2e),
  572. .platform_data = &sfn4112f_lm87_channel,
  573. };
  574. #define SFN4112F_ACT_LED 0
  575. #define SFN4112F_LINK_LED 1
  576. static void sfn4112f_init_leds(struct efx_nic *efx)
  577. {
  578. falcon_qt202x_set_led(efx, SFN4112F_ACT_LED,
  579. QUAKE_LED_RXLINK | QUAKE_LED_LINK_ACT);
  580. falcon_qt202x_set_led(efx, SFN4112F_LINK_LED,
  581. QUAKE_LED_RXLINK | QUAKE_LED_LINK_STAT);
  582. }
  583. static void sfn4112f_set_id_led(struct efx_nic *efx, bool state)
  584. {
  585. falcon_qt202x_set_led(efx, SFN4112F_LINK_LED,
  586. state ? QUAKE_LED_ON : QUAKE_LED_OFF);
  587. }
  588. static int sfn4112f_check_hw(struct efx_nic *efx)
  589. {
  590. /* Mask out unused sensors */
  591. return efx_check_lm87(efx, ~0x48);
  592. }
  593. static int sfn4112f_init(struct efx_nic *efx)
  594. {
  595. int rc = efx_init_lm87(efx, &sfn4112f_hwmon_info, sfn4112f_lm87_regs);
  596. if (rc)
  597. return rc;
  598. efx->board_info.monitor = sfn4112f_check_hw;
  599. efx->board_info.init_leds = sfn4112f_init_leds;
  600. efx->board_info.set_id_led = sfn4112f_set_id_led;
  601. efx->board_info.blink = board_blink;
  602. efx->board_info.fini = efx_fini_lm87;
  603. return 0;
  604. }
  605. /* This will get expanded as board-specific details get moved out of the
  606. * PHY drivers. */
  607. struct falcon_board_data {
  608. u8 type;
  609. const char *ref_model;
  610. const char *gen_type;
  611. int (*init) (struct efx_nic *nic);
  612. };
  613. static struct falcon_board_data board_data[] = {
  614. { FALCON_BOARD_SFE4001, "SFE4001", "10GBASE-T adapter", sfe4001_init },
  615. { FALCON_BOARD_SFE4002, "SFE4002", "XFP adapter", sfe4002_init },
  616. { FALCON_BOARD_SFN4111T, "SFN4111T", "100/1000/10GBASE-T adapter",
  617. sfn4111t_init },
  618. { FALCON_BOARD_SFN4112F, "SFN4112F", "SFP+ adapter",
  619. sfn4112f_init },
  620. };
  621. void falcon_probe_board(struct efx_nic *efx, u16 revision_info)
  622. {
  623. struct falcon_board_data *data = NULL;
  624. int i;
  625. efx->board_info.type = FALCON_BOARD_TYPE(revision_info);
  626. efx->board_info.major = FALCON_BOARD_MAJOR(revision_info);
  627. efx->board_info.minor = FALCON_BOARD_MINOR(revision_info);
  628. for (i = 0; i < ARRAY_SIZE(board_data); i++)
  629. if (board_data[i].type == efx->board_info.type)
  630. data = &board_data[i];
  631. if (data) {
  632. EFX_INFO(efx, "board is %s rev %c%d\n",
  633. (efx->pci_dev->subsystem_vendor == EFX_VENDID_SFC)
  634. ? data->ref_model : data->gen_type,
  635. 'A' + efx->board_info.major, efx->board_info.minor);
  636. efx->board_info.init = data->init;
  637. } else {
  638. EFX_ERR(efx, "unknown board type %d\n", efx->board_info.type);
  639. }
  640. }