lan743x_ethtool.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /* Copyright (C) 2018 Microchip Technology Inc. */
  3. #include <linux/netdevice.h>
  4. #include "lan743x_main.h"
  5. #include "lan743x_ethtool.h"
  6. #include <linux/net_tstamp.h>
  7. #include <linux/pci.h>
  8. #include <linux/phy.h>
  9. /* eeprom */
  10. #define LAN743X_EEPROM_MAGIC (0x74A5)
  11. #define LAN743X_OTP_MAGIC (0x74F3)
  12. #define EEPROM_INDICATOR_1 (0xA5)
  13. #define EEPROM_INDICATOR_2 (0xAA)
  14. #define EEPROM_MAC_OFFSET (0x01)
  15. #define MAX_EEPROM_SIZE 512
  16. #define OTP_INDICATOR_1 (0xF3)
  17. #define OTP_INDICATOR_2 (0xF7)
  18. static int lan743x_otp_write(struct lan743x_adapter *adapter, u32 offset,
  19. u32 length, u8 *data)
  20. {
  21. unsigned long timeout;
  22. u32 buf;
  23. int i;
  24. buf = lan743x_csr_read(adapter, OTP_PWR_DN);
  25. if (buf & OTP_PWR_DN_PWRDN_N_) {
  26. /* clear it and wait to be cleared */
  27. lan743x_csr_write(adapter, OTP_PWR_DN, 0);
  28. timeout = jiffies + HZ;
  29. do {
  30. udelay(1);
  31. buf = lan743x_csr_read(adapter, OTP_PWR_DN);
  32. if (time_after(jiffies, timeout)) {
  33. netif_warn(adapter, drv, adapter->netdev,
  34. "timeout on OTP_PWR_DN completion\n");
  35. return -EIO;
  36. }
  37. } while (buf & OTP_PWR_DN_PWRDN_N_);
  38. }
  39. /* set to BYTE program mode */
  40. lan743x_csr_write(adapter, OTP_PRGM_MODE, OTP_PRGM_MODE_BYTE_);
  41. for (i = 0; i < length; i++) {
  42. lan743x_csr_write(adapter, OTP_ADDR1,
  43. ((offset + i) >> 8) &
  44. OTP_ADDR1_15_11_MASK_);
  45. lan743x_csr_write(adapter, OTP_ADDR2,
  46. ((offset + i) &
  47. OTP_ADDR2_10_3_MASK_));
  48. lan743x_csr_write(adapter, OTP_PRGM_DATA, data[i]);
  49. lan743x_csr_write(adapter, OTP_TST_CMD, OTP_TST_CMD_PRGVRFY_);
  50. lan743x_csr_write(adapter, OTP_CMD_GO, OTP_CMD_GO_GO_);
  51. timeout = jiffies + HZ;
  52. do {
  53. udelay(1);
  54. buf = lan743x_csr_read(adapter, OTP_STATUS);
  55. if (time_after(jiffies, timeout)) {
  56. netif_warn(adapter, drv, adapter->netdev,
  57. "Timeout on OTP_STATUS completion\n");
  58. return -EIO;
  59. }
  60. } while (buf & OTP_STATUS_BUSY_);
  61. }
  62. return 0;
  63. }
  64. static int lan743x_eeprom_wait(struct lan743x_adapter *adapter)
  65. {
  66. unsigned long start_time = jiffies;
  67. u32 val;
  68. do {
  69. val = lan743x_csr_read(adapter, E2P_CMD);
  70. if (!(val & E2P_CMD_EPC_BUSY_) ||
  71. (val & E2P_CMD_EPC_TIMEOUT_))
  72. break;
  73. usleep_range(40, 100);
  74. } while (!time_after(jiffies, start_time + HZ));
  75. if (val & (E2P_CMD_EPC_TIMEOUT_ | E2P_CMD_EPC_BUSY_)) {
  76. netif_warn(adapter, drv, adapter->netdev,
  77. "EEPROM read operation timeout\n");
  78. return -EIO;
  79. }
  80. return 0;
  81. }
  82. static int lan743x_eeprom_confirm_not_busy(struct lan743x_adapter *adapter)
  83. {
  84. unsigned long start_time = jiffies;
  85. u32 val;
  86. do {
  87. val = lan743x_csr_read(adapter, E2P_CMD);
  88. if (!(val & E2P_CMD_EPC_BUSY_))
  89. return 0;
  90. usleep_range(40, 100);
  91. } while (!time_after(jiffies, start_time + HZ));
  92. netif_warn(adapter, drv, adapter->netdev, "EEPROM is busy\n");
  93. return -EIO;
  94. }
  95. static int lan743x_eeprom_read(struct lan743x_adapter *adapter,
  96. u32 offset, u32 length, u8 *data)
  97. {
  98. int retval;
  99. u32 val;
  100. int i;
  101. retval = lan743x_eeprom_confirm_not_busy(adapter);
  102. if (retval)
  103. return retval;
  104. for (i = 0; i < length; i++) {
  105. val = E2P_CMD_EPC_BUSY_ | E2P_CMD_EPC_CMD_READ_;
  106. val |= (offset & E2P_CMD_EPC_ADDR_MASK_);
  107. lan743x_csr_write(adapter, E2P_CMD, val);
  108. retval = lan743x_eeprom_wait(adapter);
  109. if (retval < 0)
  110. return retval;
  111. val = lan743x_csr_read(adapter, E2P_DATA);
  112. data[i] = val & 0xFF;
  113. offset++;
  114. }
  115. return 0;
  116. }
  117. static int lan743x_eeprom_write(struct lan743x_adapter *adapter,
  118. u32 offset, u32 length, u8 *data)
  119. {
  120. int retval;
  121. u32 val;
  122. int i;
  123. retval = lan743x_eeprom_confirm_not_busy(adapter);
  124. if (retval)
  125. return retval;
  126. /* Issue write/erase enable command */
  127. val = E2P_CMD_EPC_BUSY_ | E2P_CMD_EPC_CMD_EWEN_;
  128. lan743x_csr_write(adapter, E2P_CMD, val);
  129. retval = lan743x_eeprom_wait(adapter);
  130. if (retval < 0)
  131. return retval;
  132. for (i = 0; i < length; i++) {
  133. /* Fill data register */
  134. val = data[i];
  135. lan743x_csr_write(adapter, E2P_DATA, val);
  136. /* Send "write" command */
  137. val = E2P_CMD_EPC_BUSY_ | E2P_CMD_EPC_CMD_WRITE_;
  138. val |= (offset & E2P_CMD_EPC_ADDR_MASK_);
  139. lan743x_csr_write(adapter, E2P_CMD, val);
  140. retval = lan743x_eeprom_wait(adapter);
  141. if (retval < 0)
  142. return retval;
  143. offset++;
  144. }
  145. return 0;
  146. }
  147. static void lan743x_ethtool_get_drvinfo(struct net_device *netdev,
  148. struct ethtool_drvinfo *info)
  149. {
  150. struct lan743x_adapter *adapter = netdev_priv(netdev);
  151. strlcpy(info->driver, DRIVER_NAME, sizeof(info->driver));
  152. strlcpy(info->bus_info,
  153. pci_name(adapter->pdev), sizeof(info->bus_info));
  154. }
  155. static u32 lan743x_ethtool_get_msglevel(struct net_device *netdev)
  156. {
  157. struct lan743x_adapter *adapter = netdev_priv(netdev);
  158. return adapter->msg_enable;
  159. }
  160. static void lan743x_ethtool_set_msglevel(struct net_device *netdev,
  161. u32 msglevel)
  162. {
  163. struct lan743x_adapter *adapter = netdev_priv(netdev);
  164. adapter->msg_enable = msglevel;
  165. }
  166. static int lan743x_ethtool_get_eeprom_len(struct net_device *netdev)
  167. {
  168. return MAX_EEPROM_SIZE;
  169. }
  170. static int lan743x_ethtool_get_eeprom(struct net_device *netdev,
  171. struct ethtool_eeprom *ee, u8 *data)
  172. {
  173. struct lan743x_adapter *adapter = netdev_priv(netdev);
  174. return lan743x_eeprom_read(adapter, ee->offset, ee->len, data);
  175. }
  176. static int lan743x_ethtool_set_eeprom(struct net_device *netdev,
  177. struct ethtool_eeprom *ee, u8 *data)
  178. {
  179. struct lan743x_adapter *adapter = netdev_priv(netdev);
  180. int ret = -EINVAL;
  181. if (ee->magic == LAN743X_EEPROM_MAGIC)
  182. ret = lan743x_eeprom_write(adapter, ee->offset, ee->len,
  183. data);
  184. /* Beware! OTP is One Time Programming ONLY!
  185. * So do some strict condition check before messing up
  186. */
  187. else if ((ee->magic == LAN743X_OTP_MAGIC) &&
  188. (ee->offset == 0) &&
  189. (ee->len == MAX_EEPROM_SIZE) &&
  190. (data[0] == OTP_INDICATOR_1))
  191. ret = lan743x_otp_write(adapter, ee->offset, ee->len, data);
  192. return ret;
  193. }
  194. static const char lan743x_set0_hw_cnt_strings[][ETH_GSTRING_LEN] = {
  195. "RX FCS Errors",
  196. "RX Alignment Errors",
  197. "Rx Fragment Errors",
  198. "RX Jabber Errors",
  199. "RX Undersize Frame Errors",
  200. "RX Oversize Frame Errors",
  201. "RX Dropped Frames",
  202. "RX Unicast Byte Count",
  203. "RX Broadcast Byte Count",
  204. "RX Multicast Byte Count",
  205. "RX Unicast Frames",
  206. "RX Broadcast Frames",
  207. "RX Multicast Frames",
  208. "RX Pause Frames",
  209. "RX 64 Byte Frames",
  210. "RX 65 - 127 Byte Frames",
  211. "RX 128 - 255 Byte Frames",
  212. "RX 256 - 511 Bytes Frames",
  213. "RX 512 - 1023 Byte Frames",
  214. "RX 1024 - 1518 Byte Frames",
  215. "RX Greater 1518 Byte Frames",
  216. };
  217. static const char lan743x_set1_sw_cnt_strings[][ETH_GSTRING_LEN] = {
  218. "RX Queue 0 Frames",
  219. "RX Queue 1 Frames",
  220. "RX Queue 2 Frames",
  221. "RX Queue 3 Frames",
  222. };
  223. static const char lan743x_set2_hw_cnt_strings[][ETH_GSTRING_LEN] = {
  224. "RX Total Frames",
  225. "EEE RX LPI Transitions",
  226. "EEE RX LPI Time",
  227. "RX Counter Rollover Status",
  228. "TX FCS Errors",
  229. "TX Excess Deferral Errors",
  230. "TX Carrier Errors",
  231. "TX Bad Byte Count",
  232. "TX Single Collisions",
  233. "TX Multiple Collisions",
  234. "TX Excessive Collision",
  235. "TX Late Collisions",
  236. "TX Unicast Byte Count",
  237. "TX Broadcast Byte Count",
  238. "TX Multicast Byte Count",
  239. "TX Unicast Frames",
  240. "TX Broadcast Frames",
  241. "TX Multicast Frames",
  242. "TX Pause Frames",
  243. "TX 64 Byte Frames",
  244. "TX 65 - 127 Byte Frames",
  245. "TX 128 - 255 Byte Frames",
  246. "TX 256 - 511 Bytes Frames",
  247. "TX 512 - 1023 Byte Frames",
  248. "TX 1024 - 1518 Byte Frames",
  249. "TX Greater 1518 Byte Frames",
  250. "TX Total Frames",
  251. "EEE TX LPI Transitions",
  252. "EEE TX LPI Time",
  253. "TX Counter Rollover Status",
  254. };
  255. static const u32 lan743x_set0_hw_cnt_addr[] = {
  256. STAT_RX_FCS_ERRORS,
  257. STAT_RX_ALIGNMENT_ERRORS,
  258. STAT_RX_FRAGMENT_ERRORS,
  259. STAT_RX_JABBER_ERRORS,
  260. STAT_RX_UNDERSIZE_FRAME_ERRORS,
  261. STAT_RX_OVERSIZE_FRAME_ERRORS,
  262. STAT_RX_DROPPED_FRAMES,
  263. STAT_RX_UNICAST_BYTE_COUNT,
  264. STAT_RX_BROADCAST_BYTE_COUNT,
  265. STAT_RX_MULTICAST_BYTE_COUNT,
  266. STAT_RX_UNICAST_FRAMES,
  267. STAT_RX_BROADCAST_FRAMES,
  268. STAT_RX_MULTICAST_FRAMES,
  269. STAT_RX_PAUSE_FRAMES,
  270. STAT_RX_64_BYTE_FRAMES,
  271. STAT_RX_65_127_BYTE_FRAMES,
  272. STAT_RX_128_255_BYTE_FRAMES,
  273. STAT_RX_256_511_BYTES_FRAMES,
  274. STAT_RX_512_1023_BYTE_FRAMES,
  275. STAT_RX_1024_1518_BYTE_FRAMES,
  276. STAT_RX_GREATER_1518_BYTE_FRAMES,
  277. };
  278. static const u32 lan743x_set2_hw_cnt_addr[] = {
  279. STAT_RX_TOTAL_FRAMES,
  280. STAT_EEE_RX_LPI_TRANSITIONS,
  281. STAT_EEE_RX_LPI_TIME,
  282. STAT_RX_COUNTER_ROLLOVER_STATUS,
  283. STAT_TX_FCS_ERRORS,
  284. STAT_TX_EXCESS_DEFERRAL_ERRORS,
  285. STAT_TX_CARRIER_ERRORS,
  286. STAT_TX_BAD_BYTE_COUNT,
  287. STAT_TX_SINGLE_COLLISIONS,
  288. STAT_TX_MULTIPLE_COLLISIONS,
  289. STAT_TX_EXCESSIVE_COLLISION,
  290. STAT_TX_LATE_COLLISIONS,
  291. STAT_TX_UNICAST_BYTE_COUNT,
  292. STAT_TX_BROADCAST_BYTE_COUNT,
  293. STAT_TX_MULTICAST_BYTE_COUNT,
  294. STAT_TX_UNICAST_FRAMES,
  295. STAT_TX_BROADCAST_FRAMES,
  296. STAT_TX_MULTICAST_FRAMES,
  297. STAT_TX_PAUSE_FRAMES,
  298. STAT_TX_64_BYTE_FRAMES,
  299. STAT_TX_65_127_BYTE_FRAMES,
  300. STAT_TX_128_255_BYTE_FRAMES,
  301. STAT_TX_256_511_BYTES_FRAMES,
  302. STAT_TX_512_1023_BYTE_FRAMES,
  303. STAT_TX_1024_1518_BYTE_FRAMES,
  304. STAT_TX_GREATER_1518_BYTE_FRAMES,
  305. STAT_TX_TOTAL_FRAMES,
  306. STAT_EEE_TX_LPI_TRANSITIONS,
  307. STAT_EEE_TX_LPI_TIME,
  308. STAT_TX_COUNTER_ROLLOVER_STATUS
  309. };
  310. static void lan743x_ethtool_get_strings(struct net_device *netdev,
  311. u32 stringset, u8 *data)
  312. {
  313. switch (stringset) {
  314. case ETH_SS_STATS:
  315. memcpy(data, lan743x_set0_hw_cnt_strings,
  316. sizeof(lan743x_set0_hw_cnt_strings));
  317. memcpy(&data[sizeof(lan743x_set0_hw_cnt_strings)],
  318. lan743x_set1_sw_cnt_strings,
  319. sizeof(lan743x_set1_sw_cnt_strings));
  320. memcpy(&data[sizeof(lan743x_set0_hw_cnt_strings) +
  321. sizeof(lan743x_set1_sw_cnt_strings)],
  322. lan743x_set2_hw_cnt_strings,
  323. sizeof(lan743x_set2_hw_cnt_strings));
  324. break;
  325. }
  326. }
  327. static void lan743x_ethtool_get_ethtool_stats(struct net_device *netdev,
  328. struct ethtool_stats *stats,
  329. u64 *data)
  330. {
  331. struct lan743x_adapter *adapter = netdev_priv(netdev);
  332. int data_index = 0;
  333. u32 buf;
  334. int i;
  335. for (i = 0; i < ARRAY_SIZE(lan743x_set0_hw_cnt_addr); i++) {
  336. buf = lan743x_csr_read(adapter, lan743x_set0_hw_cnt_addr[i]);
  337. data[data_index++] = (u64)buf;
  338. }
  339. for (i = 0; i < ARRAY_SIZE(adapter->rx); i++)
  340. data[data_index++] = (u64)(adapter->rx[i].frame_count);
  341. for (i = 0; i < ARRAY_SIZE(lan743x_set2_hw_cnt_addr); i++) {
  342. buf = lan743x_csr_read(adapter, lan743x_set2_hw_cnt_addr[i]);
  343. data[data_index++] = (u64)buf;
  344. }
  345. }
  346. static int lan743x_ethtool_get_sset_count(struct net_device *netdev, int sset)
  347. {
  348. switch (sset) {
  349. case ETH_SS_STATS:
  350. {
  351. int ret;
  352. ret = ARRAY_SIZE(lan743x_set0_hw_cnt_strings);
  353. ret += ARRAY_SIZE(lan743x_set1_sw_cnt_strings);
  354. ret += ARRAY_SIZE(lan743x_set2_hw_cnt_strings);
  355. return ret;
  356. }
  357. default:
  358. return -EOPNOTSUPP;
  359. }
  360. }
  361. static int lan743x_ethtool_get_rxnfc(struct net_device *netdev,
  362. struct ethtool_rxnfc *rxnfc,
  363. u32 *rule_locs)
  364. {
  365. switch (rxnfc->cmd) {
  366. case ETHTOOL_GRXFH:
  367. rxnfc->data = 0;
  368. switch (rxnfc->flow_type) {
  369. case TCP_V4_FLOW:case UDP_V4_FLOW:
  370. case TCP_V6_FLOW:case UDP_V6_FLOW:
  371. rxnfc->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
  372. /* fall through */
  373. case IPV4_FLOW: case IPV6_FLOW:
  374. rxnfc->data |= RXH_IP_SRC | RXH_IP_DST;
  375. return 0;
  376. }
  377. break;
  378. case ETHTOOL_GRXRINGS:
  379. rxnfc->data = LAN743X_USED_RX_CHANNELS;
  380. return 0;
  381. }
  382. return -EOPNOTSUPP;
  383. }
  384. static u32 lan743x_ethtool_get_rxfh_key_size(struct net_device *netdev)
  385. {
  386. return 40;
  387. }
  388. static u32 lan743x_ethtool_get_rxfh_indir_size(struct net_device *netdev)
  389. {
  390. return 128;
  391. }
  392. static int lan743x_ethtool_get_rxfh(struct net_device *netdev,
  393. u32 *indir, u8 *key, u8 *hfunc)
  394. {
  395. struct lan743x_adapter *adapter = netdev_priv(netdev);
  396. if (indir) {
  397. int dw_index;
  398. int byte_index = 0;
  399. for (dw_index = 0; dw_index < 32; dw_index++) {
  400. u32 four_entries =
  401. lan743x_csr_read(adapter, RFE_INDX(dw_index));
  402. byte_index = dw_index << 2;
  403. indir[byte_index + 0] =
  404. ((four_entries >> 0) & 0x000000FF);
  405. indir[byte_index + 1] =
  406. ((four_entries >> 8) & 0x000000FF);
  407. indir[byte_index + 2] =
  408. ((four_entries >> 16) & 0x000000FF);
  409. indir[byte_index + 3] =
  410. ((four_entries >> 24) & 0x000000FF);
  411. }
  412. }
  413. if (key) {
  414. int dword_index;
  415. int byte_index = 0;
  416. for (dword_index = 0; dword_index < 10; dword_index++) {
  417. u32 four_entries =
  418. lan743x_csr_read(adapter,
  419. RFE_HASH_KEY(dword_index));
  420. byte_index = dword_index << 2;
  421. key[byte_index + 0] =
  422. ((four_entries >> 0) & 0x000000FF);
  423. key[byte_index + 1] =
  424. ((four_entries >> 8) & 0x000000FF);
  425. key[byte_index + 2] =
  426. ((four_entries >> 16) & 0x000000FF);
  427. key[byte_index + 3] =
  428. ((four_entries >> 24) & 0x000000FF);
  429. }
  430. }
  431. if (hfunc)
  432. (*hfunc) = ETH_RSS_HASH_TOP;
  433. return 0;
  434. }
  435. static int lan743x_ethtool_set_rxfh(struct net_device *netdev,
  436. const u32 *indir, const u8 *key,
  437. const u8 hfunc)
  438. {
  439. struct lan743x_adapter *adapter = netdev_priv(netdev);
  440. if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
  441. return -EOPNOTSUPP;
  442. if (indir) {
  443. u32 indir_value = 0;
  444. int dword_index = 0;
  445. int byte_index = 0;
  446. for (dword_index = 0; dword_index < 32; dword_index++) {
  447. byte_index = dword_index << 2;
  448. indir_value =
  449. (((indir[byte_index + 0] & 0x000000FF) << 0) |
  450. ((indir[byte_index + 1] & 0x000000FF) << 8) |
  451. ((indir[byte_index + 2] & 0x000000FF) << 16) |
  452. ((indir[byte_index + 3] & 0x000000FF) << 24));
  453. lan743x_csr_write(adapter, RFE_INDX(dword_index),
  454. indir_value);
  455. }
  456. }
  457. if (key) {
  458. int dword_index = 0;
  459. int byte_index = 0;
  460. u32 key_value = 0;
  461. for (dword_index = 0; dword_index < 10; dword_index++) {
  462. byte_index = dword_index << 2;
  463. key_value =
  464. ((((u32)(key[byte_index + 0])) << 0) |
  465. (((u32)(key[byte_index + 1])) << 8) |
  466. (((u32)(key[byte_index + 2])) << 16) |
  467. (((u32)(key[byte_index + 3])) << 24));
  468. lan743x_csr_write(adapter, RFE_HASH_KEY(dword_index),
  469. key_value);
  470. }
  471. }
  472. return 0;
  473. }
  474. static int lan743x_ethtool_get_ts_info(struct net_device *netdev,
  475. struct ethtool_ts_info *ts_info)
  476. {
  477. struct lan743x_adapter *adapter = netdev_priv(netdev);
  478. ts_info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
  479. SOF_TIMESTAMPING_RX_SOFTWARE |
  480. SOF_TIMESTAMPING_SOFTWARE |
  481. SOF_TIMESTAMPING_TX_HARDWARE |
  482. SOF_TIMESTAMPING_RX_HARDWARE |
  483. SOF_TIMESTAMPING_RAW_HARDWARE;
  484. if (adapter->ptp.ptp_clock)
  485. ts_info->phc_index = ptp_clock_index(adapter->ptp.ptp_clock);
  486. else
  487. ts_info->phc_index = -1;
  488. ts_info->tx_types = BIT(HWTSTAMP_TX_OFF) |
  489. BIT(HWTSTAMP_TX_ON) |
  490. BIT(HWTSTAMP_TX_ONESTEP_SYNC);
  491. ts_info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
  492. BIT(HWTSTAMP_FILTER_ALL);
  493. return 0;
  494. }
  495. static int lan743x_ethtool_get_eee(struct net_device *netdev,
  496. struct ethtool_eee *eee)
  497. {
  498. struct lan743x_adapter *adapter = netdev_priv(netdev);
  499. struct phy_device *phydev = netdev->phydev;
  500. u32 buf;
  501. int ret;
  502. if (!phydev)
  503. return -EIO;
  504. if (!phydev->drv) {
  505. netif_err(adapter, drv, adapter->netdev,
  506. "Missing PHY Driver\n");
  507. return -EIO;
  508. }
  509. ret = phy_ethtool_get_eee(phydev, eee);
  510. if (ret < 0)
  511. return ret;
  512. buf = lan743x_csr_read(adapter, MAC_CR);
  513. if (buf & MAC_CR_EEE_EN_) {
  514. eee->eee_enabled = true;
  515. eee->eee_active = !!(eee->advertised & eee->lp_advertised);
  516. eee->tx_lpi_enabled = true;
  517. /* EEE_TX_LPI_REQ_DLY & tx_lpi_timer are same uSec unit */
  518. buf = lan743x_csr_read(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT);
  519. eee->tx_lpi_timer = buf;
  520. } else {
  521. eee->eee_enabled = false;
  522. eee->eee_active = false;
  523. eee->tx_lpi_enabled = false;
  524. eee->tx_lpi_timer = 0;
  525. }
  526. return 0;
  527. }
  528. static int lan743x_ethtool_set_eee(struct net_device *netdev,
  529. struct ethtool_eee *eee)
  530. {
  531. struct lan743x_adapter *adapter = netdev_priv(netdev);
  532. struct phy_device *phydev = NULL;
  533. u32 buf = 0;
  534. int ret = 0;
  535. if (!netdev)
  536. return -EINVAL;
  537. adapter = netdev_priv(netdev);
  538. if (!adapter)
  539. return -EINVAL;
  540. phydev = netdev->phydev;
  541. if (!phydev)
  542. return -EIO;
  543. if (!phydev->drv) {
  544. netif_err(adapter, drv, adapter->netdev,
  545. "Missing PHY Driver\n");
  546. return -EIO;
  547. }
  548. if (eee->eee_enabled) {
  549. ret = phy_init_eee(phydev, 0);
  550. if (ret) {
  551. netif_err(adapter, drv, adapter->netdev,
  552. "EEE initialization failed\n");
  553. return ret;
  554. }
  555. buf = (u32)eee->tx_lpi_timer;
  556. lan743x_csr_write(adapter, MAC_EEE_TX_LPI_REQ_DLY_CNT, buf);
  557. buf = lan743x_csr_read(adapter, MAC_CR);
  558. buf |= MAC_CR_EEE_EN_;
  559. lan743x_csr_write(adapter, MAC_CR, buf);
  560. } else {
  561. buf = lan743x_csr_read(adapter, MAC_CR);
  562. buf &= ~MAC_CR_EEE_EN_;
  563. lan743x_csr_write(adapter, MAC_CR, buf);
  564. }
  565. return phy_ethtool_set_eee(phydev, eee);
  566. }
  567. #ifdef CONFIG_PM
  568. static void lan743x_ethtool_get_wol(struct net_device *netdev,
  569. struct ethtool_wolinfo *wol)
  570. {
  571. struct lan743x_adapter *adapter = netdev_priv(netdev);
  572. wol->supported = 0;
  573. wol->wolopts = 0;
  574. phy_ethtool_get_wol(netdev->phydev, wol);
  575. wol->supported |= WAKE_BCAST | WAKE_UCAST | WAKE_MCAST |
  576. WAKE_MAGIC | WAKE_PHY | WAKE_ARP;
  577. wol->wolopts |= adapter->wolopts;
  578. }
  579. static int lan743x_ethtool_set_wol(struct net_device *netdev,
  580. struct ethtool_wolinfo *wol)
  581. {
  582. struct lan743x_adapter *adapter = netdev_priv(netdev);
  583. adapter->wolopts = 0;
  584. if (wol->wolopts & WAKE_UCAST)
  585. adapter->wolopts |= WAKE_UCAST;
  586. if (wol->wolopts & WAKE_MCAST)
  587. adapter->wolopts |= WAKE_MCAST;
  588. if (wol->wolopts & WAKE_BCAST)
  589. adapter->wolopts |= WAKE_BCAST;
  590. if (wol->wolopts & WAKE_MAGIC)
  591. adapter->wolopts |= WAKE_MAGIC;
  592. if (wol->wolopts & WAKE_PHY)
  593. adapter->wolopts |= WAKE_PHY;
  594. if (wol->wolopts & WAKE_ARP)
  595. adapter->wolopts |= WAKE_ARP;
  596. device_set_wakeup_enable(&adapter->pdev->dev, (bool)wol->wolopts);
  597. phy_ethtool_set_wol(netdev->phydev, wol);
  598. return 0;
  599. }
  600. #endif /* CONFIG_PM */
  601. const struct ethtool_ops lan743x_ethtool_ops = {
  602. .get_drvinfo = lan743x_ethtool_get_drvinfo,
  603. .get_msglevel = lan743x_ethtool_get_msglevel,
  604. .set_msglevel = lan743x_ethtool_set_msglevel,
  605. .get_link = ethtool_op_get_link,
  606. .get_eeprom_len = lan743x_ethtool_get_eeprom_len,
  607. .get_eeprom = lan743x_ethtool_get_eeprom,
  608. .set_eeprom = lan743x_ethtool_set_eeprom,
  609. .get_strings = lan743x_ethtool_get_strings,
  610. .get_ethtool_stats = lan743x_ethtool_get_ethtool_stats,
  611. .get_sset_count = lan743x_ethtool_get_sset_count,
  612. .get_rxnfc = lan743x_ethtool_get_rxnfc,
  613. .get_rxfh_key_size = lan743x_ethtool_get_rxfh_key_size,
  614. .get_rxfh_indir_size = lan743x_ethtool_get_rxfh_indir_size,
  615. .get_rxfh = lan743x_ethtool_get_rxfh,
  616. .set_rxfh = lan743x_ethtool_set_rxfh,
  617. .get_ts_info = lan743x_ethtool_get_ts_info,
  618. .get_eee = lan743x_ethtool_get_eee,
  619. .set_eee = lan743x_ethtool_set_eee,
  620. .get_link_ksettings = phy_ethtool_get_link_ksettings,
  621. .set_link_ksettings = phy_ethtool_set_link_ksettings,
  622. #ifdef CONFIG_PM
  623. .get_wol = lan743x_ethtool_get_wol,
  624. .set_wol = lan743x_ethtool_set_wol,
  625. #endif
  626. };