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