mm.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2022-2025 NXP
  4. * Copyright 2024 Furong Xu <0x1207@gmail.com>
  5. */
  6. #include "common.h"
  7. #include "netlink.h"
  8. struct mm_req_info {
  9. struct ethnl_req_info base;
  10. };
  11. struct mm_reply_data {
  12. struct ethnl_reply_data base;
  13. struct ethtool_mm_state state;
  14. struct ethtool_mm_stats stats;
  15. };
  16. #define MM_REPDATA(__reply_base) \
  17. container_of(__reply_base, struct mm_reply_data, base)
  18. #define ETHTOOL_MM_STAT_CNT \
  19. (__ETHTOOL_A_MM_STAT_CNT - (ETHTOOL_A_MM_STAT_PAD + 1))
  20. const struct nla_policy ethnl_mm_get_policy[ETHTOOL_A_MM_HEADER + 1] = {
  21. [ETHTOOL_A_MM_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy_stats),
  22. };
  23. static int mm_prepare_data(const struct ethnl_req_info *req_base,
  24. struct ethnl_reply_data *reply_base,
  25. const struct genl_info *info)
  26. {
  27. struct mm_reply_data *data = MM_REPDATA(reply_base);
  28. struct net_device *dev = reply_base->dev;
  29. const struct ethtool_ops *ops;
  30. int ret;
  31. ops = dev->ethtool_ops;
  32. if (!ops->get_mm)
  33. return -EOPNOTSUPP;
  34. ethtool_stats_init((u64 *)&data->stats,
  35. sizeof(data->stats) / sizeof(u64));
  36. ret = ethnl_ops_begin(dev);
  37. if (ret < 0)
  38. return ret;
  39. ret = ops->get_mm(dev, &data->state);
  40. if (ret)
  41. goto out_complete;
  42. if (ops->get_mm_stats && (req_base->flags & ETHTOOL_FLAG_STATS))
  43. ops->get_mm_stats(dev, &data->stats);
  44. out_complete:
  45. ethnl_ops_complete(dev);
  46. return ret;
  47. }
  48. static int mm_reply_size(const struct ethnl_req_info *req_base,
  49. const struct ethnl_reply_data *reply_base)
  50. {
  51. int len = 0;
  52. len += nla_total_size(sizeof(u8)); /* _MM_PMAC_ENABLED */
  53. len += nla_total_size(sizeof(u8)); /* _MM_TX_ENABLED */
  54. len += nla_total_size(sizeof(u8)); /* _MM_TX_ACTIVE */
  55. len += nla_total_size(sizeof(u8)); /* _MM_VERIFY_ENABLED */
  56. len += nla_total_size(sizeof(u8)); /* _MM_VERIFY_STATUS */
  57. len += nla_total_size(sizeof(u32)); /* _MM_VERIFY_TIME */
  58. len += nla_total_size(sizeof(u32)); /* _MM_MAX_VERIFY_TIME */
  59. len += nla_total_size(sizeof(u32)); /* _MM_TX_MIN_FRAG_SIZE */
  60. len += nla_total_size(sizeof(u32)); /* _MM_RX_MIN_FRAG_SIZE */
  61. if (req_base->flags & ETHTOOL_FLAG_STATS)
  62. len += nla_total_size(0) + /* _MM_STATS */
  63. nla_total_size_64bit(sizeof(u64)) * ETHTOOL_MM_STAT_CNT;
  64. return len;
  65. }
  66. static int mm_put_stat(struct sk_buff *skb, u64 val, u16 attrtype)
  67. {
  68. if (val == ETHTOOL_STAT_NOT_SET)
  69. return 0;
  70. if (nla_put_u64_64bit(skb, attrtype, val, ETHTOOL_A_MM_STAT_PAD))
  71. return -EMSGSIZE;
  72. return 0;
  73. }
  74. static int mm_put_stats(struct sk_buff *skb,
  75. const struct ethtool_mm_stats *stats)
  76. {
  77. struct nlattr *nest;
  78. nest = nla_nest_start(skb, ETHTOOL_A_MM_STATS);
  79. if (!nest)
  80. return -EMSGSIZE;
  81. if (mm_put_stat(skb, stats->MACMergeFrameAssErrorCount,
  82. ETHTOOL_A_MM_STAT_REASSEMBLY_ERRORS) ||
  83. mm_put_stat(skb, stats->MACMergeFrameSmdErrorCount,
  84. ETHTOOL_A_MM_STAT_SMD_ERRORS) ||
  85. mm_put_stat(skb, stats->MACMergeFrameAssOkCount,
  86. ETHTOOL_A_MM_STAT_REASSEMBLY_OK) ||
  87. mm_put_stat(skb, stats->MACMergeFragCountRx,
  88. ETHTOOL_A_MM_STAT_RX_FRAG_COUNT) ||
  89. mm_put_stat(skb, stats->MACMergeFragCountTx,
  90. ETHTOOL_A_MM_STAT_TX_FRAG_COUNT) ||
  91. mm_put_stat(skb, stats->MACMergeHoldCount,
  92. ETHTOOL_A_MM_STAT_HOLD_COUNT))
  93. goto err_cancel;
  94. nla_nest_end(skb, nest);
  95. return 0;
  96. err_cancel:
  97. nla_nest_cancel(skb, nest);
  98. return -EMSGSIZE;
  99. }
  100. static int mm_fill_reply(struct sk_buff *skb,
  101. const struct ethnl_req_info *req_base,
  102. const struct ethnl_reply_data *reply_base)
  103. {
  104. const struct mm_reply_data *data = MM_REPDATA(reply_base);
  105. const struct ethtool_mm_state *state = &data->state;
  106. if (nla_put_u8(skb, ETHTOOL_A_MM_TX_ENABLED, state->tx_enabled) ||
  107. nla_put_u8(skb, ETHTOOL_A_MM_TX_ACTIVE, state->tx_active) ||
  108. nla_put_u8(skb, ETHTOOL_A_MM_PMAC_ENABLED, state->pmac_enabled) ||
  109. nla_put_u8(skb, ETHTOOL_A_MM_VERIFY_ENABLED, state->verify_enabled) ||
  110. nla_put_u8(skb, ETHTOOL_A_MM_VERIFY_STATUS, state->verify_status) ||
  111. nla_put_u32(skb, ETHTOOL_A_MM_VERIFY_TIME, state->verify_time) ||
  112. nla_put_u32(skb, ETHTOOL_A_MM_MAX_VERIFY_TIME, state->max_verify_time) ||
  113. nla_put_u32(skb, ETHTOOL_A_MM_TX_MIN_FRAG_SIZE, state->tx_min_frag_size) ||
  114. nla_put_u32(skb, ETHTOOL_A_MM_RX_MIN_FRAG_SIZE, state->rx_min_frag_size))
  115. return -EMSGSIZE;
  116. if (req_base->flags & ETHTOOL_FLAG_STATS &&
  117. mm_put_stats(skb, &data->stats))
  118. return -EMSGSIZE;
  119. return 0;
  120. }
  121. const struct nla_policy ethnl_mm_set_policy[ETHTOOL_A_MM_MAX + 1] = {
  122. [ETHTOOL_A_MM_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
  123. [ETHTOOL_A_MM_VERIFY_ENABLED] = NLA_POLICY_MAX(NLA_U8, 1),
  124. [ETHTOOL_A_MM_VERIFY_TIME] = NLA_POLICY_RANGE(NLA_U32, 1, 128),
  125. [ETHTOOL_A_MM_TX_ENABLED] = NLA_POLICY_MAX(NLA_U8, 1),
  126. [ETHTOOL_A_MM_PMAC_ENABLED] = NLA_POLICY_MAX(NLA_U8, 1),
  127. [ETHTOOL_A_MM_TX_MIN_FRAG_SIZE] = NLA_POLICY_RANGE(NLA_U32, 60, 252),
  128. };
  129. static void mm_state_to_cfg(const struct ethtool_mm_state *state,
  130. struct ethtool_mm_cfg *cfg)
  131. {
  132. /* We could also compare state->verify_status against
  133. * ETHTOOL_MM_VERIFY_STATUS_DISABLED, but state->verify_enabled
  134. * is more like an administrative state which should be seen in
  135. * ETHTOOL_MSG_MM_GET replies. For example, a port with verification
  136. * disabled might be in the ETHTOOL_MM_VERIFY_STATUS_INITIAL
  137. * if it's down.
  138. */
  139. cfg->verify_enabled = state->verify_enabled;
  140. cfg->verify_time = state->verify_time;
  141. cfg->tx_enabled = state->tx_enabled;
  142. cfg->pmac_enabled = state->pmac_enabled;
  143. cfg->tx_min_frag_size = state->tx_min_frag_size;
  144. }
  145. static int
  146. ethnl_set_mm_validate(struct ethnl_req_info *req_info, struct genl_info *info)
  147. {
  148. const struct ethtool_ops *ops = req_info->dev->ethtool_ops;
  149. return ops->get_mm && ops->set_mm ? 1 : -EOPNOTSUPP;
  150. }
  151. static int ethnl_set_mm(struct ethnl_req_info *req_info, struct genl_info *info)
  152. {
  153. struct netlink_ext_ack *extack = info->extack;
  154. struct net_device *dev = req_info->dev;
  155. struct ethtool_mm_state state = {};
  156. struct nlattr **tb = info->attrs;
  157. struct ethtool_mm_cfg cfg = {};
  158. bool mod = false;
  159. int ret;
  160. ret = dev->ethtool_ops->get_mm(dev, &state);
  161. if (ret)
  162. return ret;
  163. mm_state_to_cfg(&state, &cfg);
  164. ethnl_update_bool(&cfg.verify_enabled, tb[ETHTOOL_A_MM_VERIFY_ENABLED],
  165. &mod);
  166. ethnl_update_u32(&cfg.verify_time, tb[ETHTOOL_A_MM_VERIFY_TIME], &mod);
  167. ethnl_update_bool(&cfg.tx_enabled, tb[ETHTOOL_A_MM_TX_ENABLED], &mod);
  168. ethnl_update_bool(&cfg.pmac_enabled, tb[ETHTOOL_A_MM_PMAC_ENABLED],
  169. &mod);
  170. ethnl_update_u32(&cfg.tx_min_frag_size,
  171. tb[ETHTOOL_A_MM_TX_MIN_FRAG_SIZE], &mod);
  172. if (!mod)
  173. return 0;
  174. if (cfg.verify_time > state.max_verify_time) {
  175. NL_SET_ERR_MSG_ATTR(extack, tb[ETHTOOL_A_MM_VERIFY_TIME],
  176. "verifyTime exceeds device maximum");
  177. return -ERANGE;
  178. }
  179. if (cfg.verify_enabled && !cfg.tx_enabled) {
  180. NL_SET_ERR_MSG(extack, "Verification requires TX enabled");
  181. return -EINVAL;
  182. }
  183. if (cfg.tx_enabled && !cfg.pmac_enabled) {
  184. NL_SET_ERR_MSG(extack, "TX enabled requires pMAC enabled");
  185. return -EINVAL;
  186. }
  187. ret = dev->ethtool_ops->set_mm(dev, &cfg, extack);
  188. return ret < 0 ? ret : 1;
  189. }
  190. const struct ethnl_request_ops ethnl_mm_request_ops = {
  191. .request_cmd = ETHTOOL_MSG_MM_GET,
  192. .reply_cmd = ETHTOOL_MSG_MM_GET_REPLY,
  193. .hdr_attr = ETHTOOL_A_MM_HEADER,
  194. .req_info_size = sizeof(struct mm_req_info),
  195. .reply_data_size = sizeof(struct mm_reply_data),
  196. .prepare_data = mm_prepare_data,
  197. .reply_size = mm_reply_size,
  198. .fill_reply = mm_fill_reply,
  199. .set_validate = ethnl_set_mm_validate,
  200. .set = ethnl_set_mm,
  201. .set_ntf_cmd = ETHTOOL_MSG_MM_NTF,
  202. };
  203. /* Returns whether a given device supports the MAC merge layer
  204. * (has an eMAC and a pMAC). Must be called under rtnl_lock() and
  205. * ethnl_ops_begin().
  206. */
  207. bool __ethtool_dev_mm_supported(struct net_device *dev)
  208. {
  209. const struct ethtool_ops *ops = dev->ethtool_ops;
  210. struct ethtool_mm_state state = {};
  211. int ret = -EOPNOTSUPP;
  212. if (ops && ops->get_mm)
  213. ret = ops->get_mm(dev, &state);
  214. return !ret;
  215. }
  216. bool ethtool_dev_mm_supported(struct net_device *dev)
  217. {
  218. const struct ethtool_ops *ops = dev->ethtool_ops;
  219. bool supported;
  220. int ret;
  221. ASSERT_RTNL();
  222. if (!ops)
  223. return false;
  224. ret = ethnl_ops_begin(dev);
  225. if (ret < 0)
  226. return false;
  227. supported = __ethtool_dev_mm_supported(dev);
  228. ethnl_ops_complete(dev);
  229. return supported;
  230. }
  231. EXPORT_SYMBOL_GPL(ethtool_dev_mm_supported);
  232. static void ethtool_mmsv_configure_tx(struct ethtool_mmsv *mmsv,
  233. bool tx_active)
  234. {
  235. if (mmsv->ops->configure_tx)
  236. mmsv->ops->configure_tx(mmsv, tx_active);
  237. }
  238. static void ethtool_mmsv_configure_pmac(struct ethtool_mmsv *mmsv,
  239. bool pmac_enabled)
  240. {
  241. if (mmsv->ops->configure_pmac)
  242. mmsv->ops->configure_pmac(mmsv, pmac_enabled);
  243. }
  244. static void ethtool_mmsv_send_mpacket(struct ethtool_mmsv *mmsv,
  245. enum ethtool_mpacket mpacket)
  246. {
  247. if (mmsv->ops->send_mpacket)
  248. mmsv->ops->send_mpacket(mmsv, mpacket);
  249. }
  250. /**
  251. * ethtool_mmsv_verify_timer - Timer for MAC Merge verification
  252. * @t: timer_list struct containing private info
  253. *
  254. * Verify the MAC Merge capability in the local TX direction, by
  255. * transmitting Verify mPackets up to 3 times. Wait until link
  256. * partner responds with a Response mPacket, otherwise fail.
  257. */
  258. static void ethtool_mmsv_verify_timer(struct timer_list *t)
  259. {
  260. struct ethtool_mmsv *mmsv = timer_container_of(mmsv, t, verify_timer);
  261. unsigned long flags;
  262. bool rearm = false;
  263. spin_lock_irqsave(&mmsv->lock, flags);
  264. switch (mmsv->status) {
  265. case ETHTOOL_MM_VERIFY_STATUS_INITIAL:
  266. case ETHTOOL_MM_VERIFY_STATUS_VERIFYING:
  267. if (mmsv->verify_retries != 0) {
  268. ethtool_mmsv_send_mpacket(mmsv, ETHTOOL_MPACKET_VERIFY);
  269. rearm = true;
  270. } else {
  271. mmsv->status = ETHTOOL_MM_VERIFY_STATUS_FAILED;
  272. }
  273. mmsv->verify_retries--;
  274. break;
  275. case ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED:
  276. ethtool_mmsv_configure_tx(mmsv, true);
  277. break;
  278. default:
  279. break;
  280. }
  281. if (rearm) {
  282. mod_timer(&mmsv->verify_timer,
  283. jiffies + msecs_to_jiffies(mmsv->verify_time));
  284. }
  285. spin_unlock_irqrestore(&mmsv->lock, flags);
  286. }
  287. static void ethtool_mmsv_verify_timer_arm(struct ethtool_mmsv *mmsv)
  288. {
  289. if (mmsv->pmac_enabled && mmsv->tx_enabled && mmsv->verify_enabled &&
  290. mmsv->status != ETHTOOL_MM_VERIFY_STATUS_FAILED &&
  291. mmsv->status != ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED) {
  292. timer_setup(&mmsv->verify_timer, ethtool_mmsv_verify_timer, 0);
  293. mod_timer(&mmsv->verify_timer, jiffies);
  294. }
  295. }
  296. static void ethtool_mmsv_apply(struct ethtool_mmsv *mmsv)
  297. {
  298. /* If verification is disabled, configure FPE right away.
  299. * Otherwise let the timer code do it.
  300. */
  301. if (!mmsv->verify_enabled) {
  302. ethtool_mmsv_configure_pmac(mmsv, mmsv->pmac_enabled);
  303. ethtool_mmsv_configure_tx(mmsv, mmsv->tx_enabled);
  304. } else {
  305. mmsv->status = ETHTOOL_MM_VERIFY_STATUS_INITIAL;
  306. mmsv->verify_retries = ETHTOOL_MM_MAX_VERIFY_RETRIES;
  307. if (netif_running(mmsv->dev))
  308. ethtool_mmsv_verify_timer_arm(mmsv);
  309. }
  310. }
  311. /**
  312. * ethtool_mmsv_stop() - Stop MAC Merge Software Verification
  313. * @mmsv: MAC Merge Software Verification state
  314. *
  315. * Drivers should call this method in a state where the hardware is
  316. * about to lose state, like ndo_stop() or suspend(), and turning off
  317. * MAC Merge features would be superfluous. Otherwise, prefer
  318. * ethtool_mmsv_link_state_handle() with up=false.
  319. */
  320. void ethtool_mmsv_stop(struct ethtool_mmsv *mmsv)
  321. {
  322. timer_shutdown_sync(&mmsv->verify_timer);
  323. }
  324. EXPORT_SYMBOL_GPL(ethtool_mmsv_stop);
  325. /**
  326. * ethtool_mmsv_link_state_handle() - Inform MAC Merge Software Verification
  327. * of link state changes
  328. * @mmsv: MAC Merge Software Verification state
  329. * @up: True if device carrier is up and able to pass verification packets
  330. *
  331. * Calling context is expected to be from a task, interrupts enabled.
  332. */
  333. void ethtool_mmsv_link_state_handle(struct ethtool_mmsv *mmsv, bool up)
  334. {
  335. unsigned long flags;
  336. ethtool_mmsv_stop(mmsv);
  337. spin_lock_irqsave(&mmsv->lock, flags);
  338. if (up && mmsv->pmac_enabled) {
  339. /* VERIFY process requires pMAC enabled when NIC comes up */
  340. ethtool_mmsv_configure_pmac(mmsv, true);
  341. /* New link => maybe new partner => new verification process */
  342. ethtool_mmsv_apply(mmsv);
  343. } else {
  344. /* Reset the reported verification state while the link is down */
  345. if (mmsv->verify_enabled)
  346. mmsv->status = ETHTOOL_MM_VERIFY_STATUS_INITIAL;
  347. /* No link or pMAC not enabled */
  348. ethtool_mmsv_configure_pmac(mmsv, false);
  349. ethtool_mmsv_configure_tx(mmsv, false);
  350. }
  351. spin_unlock_irqrestore(&mmsv->lock, flags);
  352. }
  353. EXPORT_SYMBOL_GPL(ethtool_mmsv_link_state_handle);
  354. /**
  355. * ethtool_mmsv_event_handle() - Inform MAC Merge Software Verification
  356. * of interrupt-based events
  357. * @mmsv: MAC Merge Software Verification state
  358. * @event: Event which took place (packet transmission or reception)
  359. *
  360. * Calling context expects to have interrupts disabled.
  361. */
  362. void ethtool_mmsv_event_handle(struct ethtool_mmsv *mmsv,
  363. enum ethtool_mmsv_event event)
  364. {
  365. /* This is interrupt context, just spin_lock() */
  366. spin_lock(&mmsv->lock);
  367. if (!mmsv->pmac_enabled)
  368. goto unlock;
  369. switch (event) {
  370. case ETHTOOL_MMSV_LP_SENT_VERIFY_MPACKET:
  371. /* Link partner has sent verify mPacket */
  372. ethtool_mmsv_send_mpacket(mmsv, ETHTOOL_MPACKET_RESPONSE);
  373. break;
  374. case ETHTOOL_MMSV_LD_SENT_VERIFY_MPACKET:
  375. /* Local device has sent verify mPacket */
  376. if (mmsv->status != ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED)
  377. mmsv->status = ETHTOOL_MM_VERIFY_STATUS_VERIFYING;
  378. break;
  379. case ETHTOOL_MMSV_LP_SENT_RESPONSE_MPACKET:
  380. /* Link partner has sent response mPacket */
  381. if (mmsv->status == ETHTOOL_MM_VERIFY_STATUS_VERIFYING)
  382. mmsv->status = ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED;
  383. break;
  384. }
  385. unlock:
  386. spin_unlock(&mmsv->lock);
  387. }
  388. EXPORT_SYMBOL_GPL(ethtool_mmsv_event_handle);
  389. static bool ethtool_mmsv_is_tx_active(struct ethtool_mmsv *mmsv)
  390. {
  391. /* TX is active if administratively enabled, and verification either
  392. * succeeded, or was administratively disabled.
  393. */
  394. return mmsv->tx_enabled &&
  395. (mmsv->status == ETHTOOL_MM_VERIFY_STATUS_SUCCEEDED ||
  396. mmsv->status == ETHTOOL_MM_VERIFY_STATUS_DISABLED);
  397. }
  398. /**
  399. * ethtool_mmsv_get_mm() - get_mm() hook for MAC Merge Software Verification
  400. * @mmsv: MAC Merge Software Verification state
  401. * @state: see struct ethtool_mm_state
  402. *
  403. * Drivers are expected to call this from their ethtool_ops :: get_mm()
  404. * method.
  405. */
  406. void ethtool_mmsv_get_mm(struct ethtool_mmsv *mmsv,
  407. struct ethtool_mm_state *state)
  408. {
  409. unsigned long flags;
  410. spin_lock_irqsave(&mmsv->lock, flags);
  411. state->max_verify_time = ETHTOOL_MM_MAX_VERIFY_TIME_MS;
  412. state->verify_enabled = mmsv->verify_enabled;
  413. state->pmac_enabled = mmsv->pmac_enabled;
  414. state->verify_time = mmsv->verify_time;
  415. state->tx_enabled = mmsv->tx_enabled;
  416. state->verify_status = mmsv->status;
  417. state->tx_active = ethtool_mmsv_is_tx_active(mmsv);
  418. spin_unlock_irqrestore(&mmsv->lock, flags);
  419. }
  420. EXPORT_SYMBOL_GPL(ethtool_mmsv_get_mm);
  421. /**
  422. * ethtool_mmsv_set_mm() - set_mm() hook for MAC Merge Software Verification
  423. * @mmsv: MAC Merge Software Verification state
  424. * @cfg: see struct ethtool_mm_cfg
  425. *
  426. * Drivers are expected to call this from their ethtool_ops :: set_mm()
  427. * method.
  428. */
  429. void ethtool_mmsv_set_mm(struct ethtool_mmsv *mmsv, struct ethtool_mm_cfg *cfg)
  430. {
  431. unsigned long flags;
  432. /* Wait for the verification that's currently in progress to finish */
  433. ethtool_mmsv_stop(mmsv);
  434. spin_lock_irqsave(&mmsv->lock, flags);
  435. mmsv->verify_enabled = cfg->verify_enabled;
  436. mmsv->pmac_enabled = cfg->pmac_enabled;
  437. mmsv->verify_time = cfg->verify_time;
  438. mmsv->tx_enabled = cfg->tx_enabled;
  439. if (!cfg->verify_enabled)
  440. mmsv->status = ETHTOOL_MM_VERIFY_STATUS_DISABLED;
  441. ethtool_mmsv_apply(mmsv);
  442. spin_unlock_irqrestore(&mmsv->lock, flags);
  443. }
  444. EXPORT_SYMBOL_GPL(ethtool_mmsv_set_mm);
  445. /**
  446. * ethtool_mmsv_init() - Initialize MAC Merge Software Verification state
  447. * @mmsv: MAC Merge Software Verification state
  448. * @dev: Pointer to network interface
  449. * @ops: Methods for implementing the generic functionality
  450. *
  451. * The MAC Merge Software Verification is a timer- and event-based state
  452. * machine intended for network interfaces which lack a hardware-based
  453. * TX verification process (as per IEEE 802.3 clause 99.4.3). The timer
  454. * is managed by the core code, whereas events are supplied by the
  455. * driver explicitly calling one of the other API functions.
  456. */
  457. void ethtool_mmsv_init(struct ethtool_mmsv *mmsv, struct net_device *dev,
  458. const struct ethtool_mmsv_ops *ops)
  459. {
  460. mmsv->ops = ops;
  461. mmsv->dev = dev;
  462. mmsv->verify_retries = ETHTOOL_MM_MAX_VERIFY_RETRIES;
  463. mmsv->verify_time = ETHTOOL_MM_MAX_VERIFY_TIME_MS;
  464. mmsv->status = ETHTOOL_MM_VERIFY_STATUS_DISABLED;
  465. timer_setup(&mmsv->verify_timer, ethtool_mmsv_verify_timer, 0);
  466. spin_lock_init(&mmsv->lock);
  467. }
  468. EXPORT_SYMBOL_GPL(ethtool_mmsv_init);