en_dcb_nl.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. /*
  2. * Copyright (c) 2011 Mellanox Technologies. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #include <linux/dcbnl.h>
  34. #include <linux/math64.h>
  35. #include "mlx4_en.h"
  36. #include "fw_qos.h"
  37. enum {
  38. MLX4_CEE_STATE_DOWN = 0,
  39. MLX4_CEE_STATE_UP = 1,
  40. };
  41. /* Definitions for QCN
  42. */
  43. struct mlx4_congestion_control_mb_prio_802_1_qau_params {
  44. __be32 modify_enable_high;
  45. __be32 modify_enable_low;
  46. __be32 reserved1;
  47. __be32 extended_enable;
  48. __be32 rppp_max_rps;
  49. __be32 rpg_time_reset;
  50. __be32 rpg_byte_reset;
  51. __be32 rpg_threshold;
  52. __be32 rpg_max_rate;
  53. __be32 rpg_ai_rate;
  54. __be32 rpg_hai_rate;
  55. __be32 rpg_gd;
  56. __be32 rpg_min_dec_fac;
  57. __be32 rpg_min_rate;
  58. __be32 max_time_rise;
  59. __be32 max_byte_rise;
  60. __be32 max_qdelta;
  61. __be32 min_qoffset;
  62. __be32 gd_coefficient;
  63. __be32 reserved2[5];
  64. __be32 cp_sample_base;
  65. __be32 reserved3[39];
  66. };
  67. struct mlx4_congestion_control_mb_prio_802_1_qau_statistics {
  68. __be64 rppp_rp_centiseconds;
  69. __be32 reserved1;
  70. __be32 ignored_cnm;
  71. __be32 rppp_created_rps;
  72. __be32 estimated_total_rate;
  73. __be32 max_active_rate_limiter_index;
  74. __be32 dropped_cnms_busy_fw;
  75. __be32 reserved2;
  76. __be32 cnms_handled_successfully;
  77. __be32 min_total_limiters_rate;
  78. __be32 max_total_limiters_rate;
  79. __be32 reserved3[4];
  80. };
  81. static u8 mlx4_en_dcbnl_getcap(struct net_device *dev, int capid, u8 *cap)
  82. {
  83. struct mlx4_en_priv *priv = netdev_priv(dev);
  84. switch (capid) {
  85. case DCB_CAP_ATTR_PFC:
  86. *cap = true;
  87. break;
  88. case DCB_CAP_ATTR_DCBX:
  89. *cap = priv->dcbx_cap;
  90. break;
  91. case DCB_CAP_ATTR_PFC_TCS:
  92. *cap = 1 << mlx4_max_tc(priv->mdev->dev);
  93. break;
  94. default:
  95. *cap = false;
  96. break;
  97. }
  98. return 0;
  99. }
  100. static u8 mlx4_en_dcbnl_getpfcstate(struct net_device *netdev)
  101. {
  102. struct mlx4_en_priv *priv = netdev_priv(netdev);
  103. return priv->cee_config.pfc_state;
  104. }
  105. static void mlx4_en_dcbnl_setpfcstate(struct net_device *netdev, u8 state)
  106. {
  107. struct mlx4_en_priv *priv = netdev_priv(netdev);
  108. priv->cee_config.pfc_state = state;
  109. }
  110. static void mlx4_en_dcbnl_get_pfc_cfg(struct net_device *netdev, int priority,
  111. u8 *setting)
  112. {
  113. struct mlx4_en_priv *priv = netdev_priv(netdev);
  114. *setting = priv->cee_config.dcb_pfc[priority];
  115. }
  116. static void mlx4_en_dcbnl_set_pfc_cfg(struct net_device *netdev, int priority,
  117. u8 setting)
  118. {
  119. struct mlx4_en_priv *priv = netdev_priv(netdev);
  120. priv->cee_config.dcb_pfc[priority] = setting;
  121. priv->cee_config.pfc_state = true;
  122. }
  123. static int mlx4_en_dcbnl_getnumtcs(struct net_device *netdev, int tcid, u8 *num)
  124. {
  125. struct mlx4_en_priv *priv = netdev_priv(netdev);
  126. if (!(priv->flags & MLX4_EN_FLAG_DCB_ENABLED))
  127. return -EINVAL;
  128. if (tcid == DCB_NUMTCS_ATTR_PFC)
  129. *num = mlx4_max_tc(priv->mdev->dev);
  130. else
  131. *num = 0;
  132. return 0;
  133. }
  134. static u8 mlx4_en_dcbnl_set_all(struct net_device *netdev)
  135. {
  136. struct mlx4_en_priv *priv = netdev_priv(netdev);
  137. struct mlx4_en_dev *mdev = priv->mdev;
  138. if (!(priv->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
  139. return 1;
  140. if (priv->cee_config.pfc_state) {
  141. int tc;
  142. priv->prof->rx_pause = 0;
  143. priv->prof->tx_pause = 0;
  144. for (tc = 0; tc < CEE_DCBX_MAX_PRIO; tc++) {
  145. u8 tc_mask = 1 << tc;
  146. switch (priv->cee_config.dcb_pfc[tc]) {
  147. case pfc_disabled:
  148. priv->prof->tx_ppp &= ~tc_mask;
  149. priv->prof->rx_ppp &= ~tc_mask;
  150. break;
  151. case pfc_enabled_full:
  152. priv->prof->tx_ppp |= tc_mask;
  153. priv->prof->rx_ppp |= tc_mask;
  154. break;
  155. case pfc_enabled_tx:
  156. priv->prof->tx_ppp |= tc_mask;
  157. priv->prof->rx_ppp &= ~tc_mask;
  158. break;
  159. case pfc_enabled_rx:
  160. priv->prof->tx_ppp &= ~tc_mask;
  161. priv->prof->rx_ppp |= tc_mask;
  162. break;
  163. default:
  164. break;
  165. }
  166. }
  167. en_dbg(DRV, priv, "Set pfc on\n");
  168. } else {
  169. priv->prof->rx_pause = 1;
  170. priv->prof->tx_pause = 1;
  171. en_dbg(DRV, priv, "Set pfc off\n");
  172. }
  173. if (mlx4_SET_PORT_general(mdev->dev, priv->port,
  174. priv->rx_skb_size + ETH_FCS_LEN,
  175. priv->prof->tx_pause,
  176. priv->prof->tx_ppp,
  177. priv->prof->rx_pause,
  178. priv->prof->rx_ppp)) {
  179. en_err(priv, "Failed setting pause params\n");
  180. return 1;
  181. }
  182. return 0;
  183. }
  184. static u8 mlx4_en_dcbnl_get_state(struct net_device *dev)
  185. {
  186. struct mlx4_en_priv *priv = netdev_priv(dev);
  187. if (priv->flags & MLX4_EN_FLAG_DCB_ENABLED)
  188. return MLX4_CEE_STATE_UP;
  189. return MLX4_CEE_STATE_DOWN;
  190. }
  191. static u8 mlx4_en_dcbnl_set_state(struct net_device *dev, u8 state)
  192. {
  193. struct mlx4_en_priv *priv = netdev_priv(dev);
  194. int num_tcs = 0;
  195. if (!(priv->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
  196. return 1;
  197. if (!!(state) == !!(priv->flags & MLX4_EN_FLAG_DCB_ENABLED))
  198. return 0;
  199. if (state) {
  200. priv->flags |= MLX4_EN_FLAG_DCB_ENABLED;
  201. num_tcs = IEEE_8021QAZ_MAX_TCS;
  202. } else {
  203. priv->flags &= ~MLX4_EN_FLAG_DCB_ENABLED;
  204. }
  205. if (mlx4_en_setup_tc(dev, num_tcs))
  206. return 1;
  207. return 0;
  208. }
  209. /* On success returns a non-zero 802.1p user priority bitmap
  210. * otherwise returns 0 as the invalid user priority bitmap to
  211. * indicate an error.
  212. */
  213. static int mlx4_en_dcbnl_getapp(struct net_device *netdev, u8 idtype, u16 id)
  214. {
  215. struct mlx4_en_priv *priv = netdev_priv(netdev);
  216. struct dcb_app app = {
  217. .selector = idtype,
  218. .protocol = id,
  219. };
  220. if (!(priv->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
  221. return 0;
  222. return dcb_getapp(netdev, &app);
  223. }
  224. static int mlx4_en_dcbnl_setapp(struct net_device *netdev, u8 idtype,
  225. u16 id, u8 up)
  226. {
  227. struct mlx4_en_priv *priv = netdev_priv(netdev);
  228. struct dcb_app app;
  229. if (!(priv->dcbx_cap & DCB_CAP_DCBX_VER_CEE))
  230. return -EINVAL;
  231. memset(&app, 0, sizeof(struct dcb_app));
  232. app.selector = idtype;
  233. app.protocol = id;
  234. app.priority = up;
  235. return dcb_setapp(netdev, &app);
  236. }
  237. static int mlx4_en_dcbnl_ieee_getets(struct net_device *dev,
  238. struct ieee_ets *ets)
  239. {
  240. struct mlx4_en_priv *priv = netdev_priv(dev);
  241. struct ieee_ets *my_ets = &priv->ets;
  242. if (!my_ets)
  243. return -EINVAL;
  244. ets->ets_cap = IEEE_8021QAZ_MAX_TCS;
  245. ets->cbs = my_ets->cbs;
  246. memcpy(ets->tc_tx_bw, my_ets->tc_tx_bw, sizeof(ets->tc_tx_bw));
  247. memcpy(ets->tc_tsa, my_ets->tc_tsa, sizeof(ets->tc_tsa));
  248. memcpy(ets->prio_tc, my_ets->prio_tc, sizeof(ets->prio_tc));
  249. return 0;
  250. }
  251. static int mlx4_en_ets_validate(struct mlx4_en_priv *priv, struct ieee_ets *ets)
  252. {
  253. int i;
  254. int total_ets_bw = 0;
  255. int has_ets_tc = 0;
  256. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  257. if (ets->prio_tc[i] >= MLX4_EN_NUM_UP) {
  258. en_err(priv, "Bad priority in UP <=> TC mapping. TC: %d, UP: %d\n",
  259. i, ets->prio_tc[i]);
  260. return -EINVAL;
  261. }
  262. switch (ets->tc_tsa[i]) {
  263. case IEEE_8021QAZ_TSA_STRICT:
  264. break;
  265. case IEEE_8021QAZ_TSA_ETS:
  266. has_ets_tc = 1;
  267. total_ets_bw += ets->tc_tx_bw[i];
  268. break;
  269. default:
  270. en_err(priv, "TC[%d]: Not supported TSA: %d\n",
  271. i, ets->tc_tsa[i]);
  272. return -EOPNOTSUPP;
  273. }
  274. }
  275. if (has_ets_tc && total_ets_bw != MLX4_EN_BW_MAX) {
  276. en_err(priv, "Bad ETS BW sum: %d. Should be exactly 100%%\n",
  277. total_ets_bw);
  278. return -EINVAL;
  279. }
  280. return 0;
  281. }
  282. static int mlx4_en_config_port_scheduler(struct mlx4_en_priv *priv,
  283. struct ieee_ets *ets, u16 *ratelimit)
  284. {
  285. struct mlx4_en_dev *mdev = priv->mdev;
  286. int num_strict = 0;
  287. int i;
  288. __u8 tc_tx_bw[IEEE_8021QAZ_MAX_TCS] = { 0 };
  289. __u8 pg[IEEE_8021QAZ_MAX_TCS] = { 0 };
  290. ets = ets ?: &priv->ets;
  291. ratelimit = ratelimit ?: priv->maxrate;
  292. /* higher TC means higher priority => lower pg */
  293. for (i = IEEE_8021QAZ_MAX_TCS - 1; i >= 0; i--) {
  294. switch (ets->tc_tsa[i]) {
  295. case IEEE_8021QAZ_TSA_STRICT:
  296. pg[i] = num_strict++;
  297. tc_tx_bw[i] = MLX4_EN_BW_MAX;
  298. break;
  299. case IEEE_8021QAZ_TSA_ETS:
  300. pg[i] = MLX4_EN_TC_ETS;
  301. tc_tx_bw[i] = ets->tc_tx_bw[i] ?: MLX4_EN_BW_MIN;
  302. break;
  303. }
  304. }
  305. return mlx4_SET_PORT_SCHEDULER(mdev->dev, priv->port, tc_tx_bw, pg,
  306. ratelimit);
  307. }
  308. static int
  309. mlx4_en_dcbnl_ieee_setets(struct net_device *dev, struct ieee_ets *ets)
  310. {
  311. struct mlx4_en_priv *priv = netdev_priv(dev);
  312. struct mlx4_en_dev *mdev = priv->mdev;
  313. int err;
  314. err = mlx4_en_ets_validate(priv, ets);
  315. if (err)
  316. return err;
  317. err = mlx4_SET_PORT_PRIO2TC(mdev->dev, priv->port, ets->prio_tc);
  318. if (err)
  319. return err;
  320. err = mlx4_en_config_port_scheduler(priv, ets, NULL);
  321. if (err)
  322. return err;
  323. memcpy(&priv->ets, ets, sizeof(priv->ets));
  324. return 0;
  325. }
  326. static int mlx4_en_dcbnl_ieee_getpfc(struct net_device *dev,
  327. struct ieee_pfc *pfc)
  328. {
  329. struct mlx4_en_priv *priv = netdev_priv(dev);
  330. pfc->pfc_cap = IEEE_8021QAZ_MAX_TCS;
  331. pfc->pfc_en = priv->prof->tx_ppp;
  332. return 0;
  333. }
  334. static int mlx4_en_dcbnl_ieee_setpfc(struct net_device *dev,
  335. struct ieee_pfc *pfc)
  336. {
  337. struct mlx4_en_priv *priv = netdev_priv(dev);
  338. struct mlx4_en_port_profile *prof = priv->prof;
  339. struct mlx4_en_dev *mdev = priv->mdev;
  340. int err;
  341. en_dbg(DRV, priv, "cap: 0x%x en: 0x%x mbc: 0x%x delay: %d\n",
  342. pfc->pfc_cap,
  343. pfc->pfc_en,
  344. pfc->mbc,
  345. pfc->delay);
  346. prof->rx_pause = !pfc->pfc_en;
  347. prof->tx_pause = !pfc->pfc_en;
  348. prof->rx_ppp = pfc->pfc_en;
  349. prof->tx_ppp = pfc->pfc_en;
  350. err = mlx4_SET_PORT_general(mdev->dev, priv->port,
  351. priv->rx_skb_size + ETH_FCS_LEN,
  352. prof->tx_pause,
  353. prof->tx_ppp,
  354. prof->rx_pause,
  355. prof->rx_ppp);
  356. if (err)
  357. en_err(priv, "Failed setting pause params\n");
  358. else
  359. mlx4_en_update_pfc_stats_bitmap(mdev->dev, &priv->stats_bitmap,
  360. prof->rx_ppp, prof->rx_pause,
  361. prof->tx_ppp, prof->tx_pause);
  362. return err;
  363. }
  364. static u8 mlx4_en_dcbnl_getdcbx(struct net_device *dev)
  365. {
  366. struct mlx4_en_priv *priv = netdev_priv(dev);
  367. return priv->dcbx_cap;
  368. }
  369. static u8 mlx4_en_dcbnl_setdcbx(struct net_device *dev, u8 mode)
  370. {
  371. struct mlx4_en_priv *priv = netdev_priv(dev);
  372. struct ieee_ets ets = {0};
  373. struct ieee_pfc pfc = {0};
  374. if (mode == priv->dcbx_cap)
  375. return 0;
  376. if ((mode & DCB_CAP_DCBX_LLD_MANAGED) ||
  377. ((mode & DCB_CAP_DCBX_VER_IEEE) &&
  378. (mode & DCB_CAP_DCBX_VER_CEE)) ||
  379. !(mode & DCB_CAP_DCBX_HOST))
  380. goto err;
  381. priv->dcbx_cap = mode;
  382. ets.ets_cap = IEEE_8021QAZ_MAX_TCS;
  383. pfc.pfc_cap = IEEE_8021QAZ_MAX_TCS;
  384. if (mode & DCB_CAP_DCBX_VER_IEEE) {
  385. if (mlx4_en_dcbnl_ieee_setets(dev, &ets))
  386. goto err;
  387. if (mlx4_en_dcbnl_ieee_setpfc(dev, &pfc))
  388. goto err;
  389. } else if (mode & DCB_CAP_DCBX_VER_CEE) {
  390. if (mlx4_en_dcbnl_set_all(dev))
  391. goto err;
  392. } else {
  393. if (mlx4_en_dcbnl_ieee_setets(dev, &ets))
  394. goto err;
  395. if (mlx4_en_dcbnl_ieee_setpfc(dev, &pfc))
  396. goto err;
  397. if (mlx4_en_setup_tc(dev, 0))
  398. goto err;
  399. }
  400. return 0;
  401. err:
  402. return 1;
  403. }
  404. #define MLX4_RATELIMIT_UNITS_IN_KB 100000 /* rate-limit HW unit in Kbps */
  405. static int mlx4_en_dcbnl_ieee_getmaxrate(struct net_device *dev,
  406. struct ieee_maxrate *maxrate)
  407. {
  408. struct mlx4_en_priv *priv = netdev_priv(dev);
  409. int i;
  410. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++)
  411. maxrate->tc_maxrate[i] =
  412. priv->maxrate[i] * MLX4_RATELIMIT_UNITS_IN_KB;
  413. return 0;
  414. }
  415. static int mlx4_en_dcbnl_ieee_setmaxrate(struct net_device *dev,
  416. struct ieee_maxrate *maxrate)
  417. {
  418. struct mlx4_en_priv *priv = netdev_priv(dev);
  419. u16 tmp[IEEE_8021QAZ_MAX_TCS];
  420. int i, err;
  421. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  422. /* Convert from Kbps into HW units, rounding result up.
  423. * Setting to 0, means unlimited BW.
  424. */
  425. tmp[i] = div_u64(maxrate->tc_maxrate[i] +
  426. MLX4_RATELIMIT_UNITS_IN_KB - 1,
  427. MLX4_RATELIMIT_UNITS_IN_KB);
  428. }
  429. err = mlx4_en_config_port_scheduler(priv, NULL, tmp);
  430. if (err)
  431. return err;
  432. memcpy(priv->maxrate, tmp, sizeof(priv->maxrate));
  433. return 0;
  434. }
  435. #define RPG_ENABLE_BIT 31
  436. #define CN_TAG_BIT 30
  437. static int mlx4_en_dcbnl_ieee_getqcn(struct net_device *dev,
  438. struct ieee_qcn *qcn)
  439. {
  440. struct mlx4_en_priv *priv = netdev_priv(dev);
  441. struct mlx4_congestion_control_mb_prio_802_1_qau_params *hw_qcn;
  442. struct mlx4_cmd_mailbox *mailbox_out = NULL;
  443. u64 mailbox_in_dma = 0;
  444. u32 inmod = 0;
  445. int i, err;
  446. if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_QCN))
  447. return -EOPNOTSUPP;
  448. mailbox_out = mlx4_alloc_cmd_mailbox(priv->mdev->dev);
  449. if (IS_ERR(mailbox_out))
  450. return -ENOMEM;
  451. hw_qcn =
  452. (struct mlx4_congestion_control_mb_prio_802_1_qau_params *)
  453. mailbox_out->buf;
  454. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  455. inmod = priv->port | ((1 << i) << 8) |
  456. (MLX4_CTRL_ALGO_802_1_QAU_REACTION_POINT << 16);
  457. err = mlx4_cmd_box(priv->mdev->dev, mailbox_in_dma,
  458. mailbox_out->dma,
  459. inmod, MLX4_CONGESTION_CONTROL_GET_PARAMS,
  460. MLX4_CMD_CONGESTION_CTRL_OPCODE,
  461. MLX4_CMD_TIME_CLASS_C,
  462. MLX4_CMD_NATIVE);
  463. if (err) {
  464. mlx4_free_cmd_mailbox(priv->mdev->dev, mailbox_out);
  465. return err;
  466. }
  467. qcn->rpg_enable[i] =
  468. be32_to_cpu(hw_qcn->extended_enable) >> RPG_ENABLE_BIT;
  469. qcn->rppp_max_rps[i] =
  470. be32_to_cpu(hw_qcn->rppp_max_rps);
  471. qcn->rpg_time_reset[i] =
  472. be32_to_cpu(hw_qcn->rpg_time_reset);
  473. qcn->rpg_byte_reset[i] =
  474. be32_to_cpu(hw_qcn->rpg_byte_reset);
  475. qcn->rpg_threshold[i] =
  476. be32_to_cpu(hw_qcn->rpg_threshold);
  477. qcn->rpg_max_rate[i] =
  478. be32_to_cpu(hw_qcn->rpg_max_rate);
  479. qcn->rpg_ai_rate[i] =
  480. be32_to_cpu(hw_qcn->rpg_ai_rate);
  481. qcn->rpg_hai_rate[i] =
  482. be32_to_cpu(hw_qcn->rpg_hai_rate);
  483. qcn->rpg_gd[i] =
  484. be32_to_cpu(hw_qcn->rpg_gd);
  485. qcn->rpg_min_dec_fac[i] =
  486. be32_to_cpu(hw_qcn->rpg_min_dec_fac);
  487. qcn->rpg_min_rate[i] =
  488. be32_to_cpu(hw_qcn->rpg_min_rate);
  489. qcn->cndd_state_machine[i] =
  490. priv->cndd_state[i];
  491. }
  492. mlx4_free_cmd_mailbox(priv->mdev->dev, mailbox_out);
  493. return 0;
  494. }
  495. static int mlx4_en_dcbnl_ieee_setqcn(struct net_device *dev,
  496. struct ieee_qcn *qcn)
  497. {
  498. struct mlx4_en_priv *priv = netdev_priv(dev);
  499. struct mlx4_congestion_control_mb_prio_802_1_qau_params *hw_qcn;
  500. struct mlx4_cmd_mailbox *mailbox_in = NULL;
  501. u64 mailbox_in_dma = 0;
  502. u32 inmod = 0;
  503. int i, err;
  504. #define MODIFY_ENABLE_HIGH_MASK 0xc0000000
  505. #define MODIFY_ENABLE_LOW_MASK 0xffc00000
  506. if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_QCN))
  507. return -EOPNOTSUPP;
  508. mailbox_in = mlx4_alloc_cmd_mailbox(priv->mdev->dev);
  509. if (IS_ERR(mailbox_in))
  510. return -ENOMEM;
  511. mailbox_in_dma = mailbox_in->dma;
  512. hw_qcn =
  513. (struct mlx4_congestion_control_mb_prio_802_1_qau_params *)mailbox_in->buf;
  514. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  515. inmod = priv->port | ((1 << i) << 8) |
  516. (MLX4_CTRL_ALGO_802_1_QAU_REACTION_POINT << 16);
  517. /* Before updating QCN parameter,
  518. * need to set it's modify enable bit to 1
  519. */
  520. hw_qcn->modify_enable_high = cpu_to_be32(
  521. MODIFY_ENABLE_HIGH_MASK);
  522. hw_qcn->modify_enable_low = cpu_to_be32(MODIFY_ENABLE_LOW_MASK);
  523. hw_qcn->extended_enable = cpu_to_be32(qcn->rpg_enable[i] << RPG_ENABLE_BIT);
  524. hw_qcn->rppp_max_rps = cpu_to_be32(qcn->rppp_max_rps[i]);
  525. hw_qcn->rpg_time_reset = cpu_to_be32(qcn->rpg_time_reset[i]);
  526. hw_qcn->rpg_byte_reset = cpu_to_be32(qcn->rpg_byte_reset[i]);
  527. hw_qcn->rpg_threshold = cpu_to_be32(qcn->rpg_threshold[i]);
  528. hw_qcn->rpg_max_rate = cpu_to_be32(qcn->rpg_max_rate[i]);
  529. hw_qcn->rpg_ai_rate = cpu_to_be32(qcn->rpg_ai_rate[i]);
  530. hw_qcn->rpg_hai_rate = cpu_to_be32(qcn->rpg_hai_rate[i]);
  531. hw_qcn->rpg_gd = cpu_to_be32(qcn->rpg_gd[i]);
  532. hw_qcn->rpg_min_dec_fac = cpu_to_be32(qcn->rpg_min_dec_fac[i]);
  533. hw_qcn->rpg_min_rate = cpu_to_be32(qcn->rpg_min_rate[i]);
  534. priv->cndd_state[i] = qcn->cndd_state_machine[i];
  535. if (qcn->cndd_state_machine[i] == DCB_CNDD_INTERIOR_READY)
  536. hw_qcn->extended_enable |= cpu_to_be32(1 << CN_TAG_BIT);
  537. err = mlx4_cmd(priv->mdev->dev, mailbox_in_dma, inmod,
  538. MLX4_CONGESTION_CONTROL_SET_PARAMS,
  539. MLX4_CMD_CONGESTION_CTRL_OPCODE,
  540. MLX4_CMD_TIME_CLASS_C,
  541. MLX4_CMD_NATIVE);
  542. if (err) {
  543. mlx4_free_cmd_mailbox(priv->mdev->dev, mailbox_in);
  544. return err;
  545. }
  546. }
  547. mlx4_free_cmd_mailbox(priv->mdev->dev, mailbox_in);
  548. return 0;
  549. }
  550. static int mlx4_en_dcbnl_ieee_getqcnstats(struct net_device *dev,
  551. struct ieee_qcn_stats *qcn_stats)
  552. {
  553. struct mlx4_en_priv *priv = netdev_priv(dev);
  554. struct mlx4_congestion_control_mb_prio_802_1_qau_statistics *hw_qcn_stats;
  555. struct mlx4_cmd_mailbox *mailbox_out = NULL;
  556. u64 mailbox_in_dma = 0;
  557. u32 inmod = 0;
  558. int i, err;
  559. if (!(priv->mdev->dev->caps.flags2 & MLX4_DEV_CAP_FLAG2_QCN))
  560. return -EOPNOTSUPP;
  561. mailbox_out = mlx4_alloc_cmd_mailbox(priv->mdev->dev);
  562. if (IS_ERR(mailbox_out))
  563. return -ENOMEM;
  564. hw_qcn_stats =
  565. (struct mlx4_congestion_control_mb_prio_802_1_qau_statistics *)
  566. mailbox_out->buf;
  567. for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
  568. inmod = priv->port | ((1 << i) << 8) |
  569. (MLX4_CTRL_ALGO_802_1_QAU_REACTION_POINT << 16);
  570. err = mlx4_cmd_box(priv->mdev->dev, mailbox_in_dma,
  571. mailbox_out->dma, inmod,
  572. MLX4_CONGESTION_CONTROL_GET_STATISTICS,
  573. MLX4_CMD_CONGESTION_CTRL_OPCODE,
  574. MLX4_CMD_TIME_CLASS_C,
  575. MLX4_CMD_NATIVE);
  576. if (err) {
  577. mlx4_free_cmd_mailbox(priv->mdev->dev, mailbox_out);
  578. return err;
  579. }
  580. qcn_stats->rppp_rp_centiseconds[i] =
  581. be64_to_cpu(hw_qcn_stats->rppp_rp_centiseconds);
  582. qcn_stats->rppp_created_rps[i] =
  583. be32_to_cpu(hw_qcn_stats->rppp_created_rps);
  584. }
  585. mlx4_free_cmd_mailbox(priv->mdev->dev, mailbox_out);
  586. return 0;
  587. }
  588. const struct dcbnl_rtnl_ops mlx4_en_dcbnl_ops = {
  589. .ieee_getets = mlx4_en_dcbnl_ieee_getets,
  590. .ieee_setets = mlx4_en_dcbnl_ieee_setets,
  591. .ieee_getmaxrate = mlx4_en_dcbnl_ieee_getmaxrate,
  592. .ieee_setmaxrate = mlx4_en_dcbnl_ieee_setmaxrate,
  593. .ieee_getqcn = mlx4_en_dcbnl_ieee_getqcn,
  594. .ieee_setqcn = mlx4_en_dcbnl_ieee_setqcn,
  595. .ieee_getqcnstats = mlx4_en_dcbnl_ieee_getqcnstats,
  596. .ieee_getpfc = mlx4_en_dcbnl_ieee_getpfc,
  597. .ieee_setpfc = mlx4_en_dcbnl_ieee_setpfc,
  598. .getstate = mlx4_en_dcbnl_get_state,
  599. .setstate = mlx4_en_dcbnl_set_state,
  600. .getpfccfg = mlx4_en_dcbnl_get_pfc_cfg,
  601. .setpfccfg = mlx4_en_dcbnl_set_pfc_cfg,
  602. .setall = mlx4_en_dcbnl_set_all,
  603. .getcap = mlx4_en_dcbnl_getcap,
  604. .getnumtcs = mlx4_en_dcbnl_getnumtcs,
  605. .getpfcstate = mlx4_en_dcbnl_getpfcstate,
  606. .setpfcstate = mlx4_en_dcbnl_setpfcstate,
  607. .getapp = mlx4_en_dcbnl_getapp,
  608. .setapp = mlx4_en_dcbnl_setapp,
  609. .getdcbx = mlx4_en_dcbnl_getdcbx,
  610. .setdcbx = mlx4_en_dcbnl_setdcbx,
  611. };
  612. const struct dcbnl_rtnl_ops mlx4_en_dcbnl_pfc_ops = {
  613. .ieee_getpfc = mlx4_en_dcbnl_ieee_getpfc,
  614. .ieee_setpfc = mlx4_en_dcbnl_ieee_setpfc,
  615. .setstate = mlx4_en_dcbnl_set_state,
  616. .getpfccfg = mlx4_en_dcbnl_get_pfc_cfg,
  617. .setpfccfg = mlx4_en_dcbnl_set_pfc_cfg,
  618. .setall = mlx4_en_dcbnl_set_all,
  619. .getnumtcs = mlx4_en_dcbnl_getnumtcs,
  620. .getpfcstate = mlx4_en_dcbnl_getpfcstate,
  621. .setpfcstate = mlx4_en_dcbnl_setpfcstate,
  622. .getapp = mlx4_en_dcbnl_getapp,
  623. .setapp = mlx4_en_dcbnl_setapp,
  624. .getdcbx = mlx4_en_dcbnl_getdcbx,
  625. .setdcbx = mlx4_en_dcbnl_setdcbx,
  626. };