i40e_dcb_nl.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright(c) 2013 - 2018 Intel Corporation. */
  3. #ifdef CONFIG_I40E_DCB
  4. #include "i40e.h"
  5. #include <net/dcbnl.h>
  6. /**
  7. * i40e_get_pfc_delay - retrieve PFC Link Delay
  8. * @hw: pointer to hardware struct
  9. * @delay: holds the PFC Link delay value
  10. *
  11. * Returns PFC Link Delay from the PRTDCB_GENC.PFCLDA
  12. **/
  13. static void i40e_get_pfc_delay(struct i40e_hw *hw, u16 *delay)
  14. {
  15. u32 val;
  16. val = rd32(hw, I40E_PRTDCB_GENC);
  17. *delay = (u16)((val & I40E_PRTDCB_GENC_PFCLDA_MASK) >>
  18. I40E_PRTDCB_GENC_PFCLDA_SHIFT);
  19. }
  20. /**
  21. * i40e_dcbnl_ieee_getets - retrieve local IEEE ETS configuration
  22. * @dev: the corresponding netdev
  23. * @ets: structure to hold the ETS information
  24. *
  25. * Returns local IEEE ETS configuration
  26. **/
  27. static int i40e_dcbnl_ieee_getets(struct net_device *dev,
  28. struct ieee_ets *ets)
  29. {
  30. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  31. struct i40e_dcbx_config *dcbxcfg;
  32. struct i40e_hw *hw = &pf->hw;
  33. if (!(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
  34. return -EINVAL;
  35. dcbxcfg = &hw->local_dcbx_config;
  36. ets->willing = dcbxcfg->etscfg.willing;
  37. ets->ets_cap = dcbxcfg->etscfg.maxtcs;
  38. ets->cbs = dcbxcfg->etscfg.cbs;
  39. memcpy(ets->tc_tx_bw, dcbxcfg->etscfg.tcbwtable,
  40. sizeof(ets->tc_tx_bw));
  41. memcpy(ets->tc_rx_bw, dcbxcfg->etscfg.tcbwtable,
  42. sizeof(ets->tc_rx_bw));
  43. memcpy(ets->tc_tsa, dcbxcfg->etscfg.tsatable,
  44. sizeof(ets->tc_tsa));
  45. memcpy(ets->prio_tc, dcbxcfg->etscfg.prioritytable,
  46. sizeof(ets->prio_tc));
  47. memcpy(ets->tc_reco_bw, dcbxcfg->etsrec.tcbwtable,
  48. sizeof(ets->tc_reco_bw));
  49. memcpy(ets->tc_reco_tsa, dcbxcfg->etsrec.tsatable,
  50. sizeof(ets->tc_reco_tsa));
  51. memcpy(ets->reco_prio_tc, dcbxcfg->etscfg.prioritytable,
  52. sizeof(ets->reco_prio_tc));
  53. return 0;
  54. }
  55. /**
  56. * i40e_dcbnl_ieee_getpfc - retrieve local IEEE PFC configuration
  57. * @dev: the corresponding netdev
  58. * @pfc: structure to hold the PFC information
  59. *
  60. * Returns local IEEE PFC configuration
  61. **/
  62. static int i40e_dcbnl_ieee_getpfc(struct net_device *dev,
  63. struct ieee_pfc *pfc)
  64. {
  65. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  66. struct i40e_dcbx_config *dcbxcfg;
  67. struct i40e_hw *hw = &pf->hw;
  68. int i;
  69. if (!(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
  70. return -EINVAL;
  71. dcbxcfg = &hw->local_dcbx_config;
  72. pfc->pfc_cap = dcbxcfg->pfc.pfccap;
  73. pfc->pfc_en = dcbxcfg->pfc.pfcenable;
  74. pfc->mbc = dcbxcfg->pfc.mbc;
  75. i40e_get_pfc_delay(hw, &pfc->delay);
  76. /* Get Requests/Indicatiosn */
  77. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  78. pfc->requests[i] = pf->stats.priority_xoff_tx[i];
  79. pfc->indications[i] = pf->stats.priority_xoff_rx[i];
  80. }
  81. return 0;
  82. }
  83. /**
  84. * i40e_dcbnl_getdcbx - retrieve current DCBx capability
  85. * @dev: the corresponding netdev
  86. *
  87. * Returns DCBx capability features
  88. **/
  89. static u8 i40e_dcbnl_getdcbx(struct net_device *dev)
  90. {
  91. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  92. return pf->dcbx_cap;
  93. }
  94. /**
  95. * i40e_dcbnl_get_perm_hw_addr - MAC address used by DCBx
  96. * @dev: the corresponding netdev
  97. * @perm_addr: buffer to store the MAC address
  98. *
  99. * Returns the SAN MAC address used for LLDP exchange
  100. **/
  101. static void i40e_dcbnl_get_perm_hw_addr(struct net_device *dev,
  102. u8 *perm_addr)
  103. {
  104. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  105. int i, j;
  106. memset(perm_addr, 0xff, MAX_ADDR_LEN);
  107. for (i = 0; i < dev->addr_len; i++)
  108. perm_addr[i] = pf->hw.mac.perm_addr[i];
  109. for (j = 0; j < dev->addr_len; j++, i++)
  110. perm_addr[i] = pf->hw.mac.san_addr[j];
  111. }
  112. static const struct dcbnl_rtnl_ops dcbnl_ops = {
  113. .ieee_getets = i40e_dcbnl_ieee_getets,
  114. .ieee_getpfc = i40e_dcbnl_ieee_getpfc,
  115. .getdcbx = i40e_dcbnl_getdcbx,
  116. .getpermhwaddr = i40e_dcbnl_get_perm_hw_addr,
  117. };
  118. /**
  119. * i40e_dcbnl_set_all - set all the apps and ieee data from DCBx config
  120. * @vsi: the corresponding vsi
  121. *
  122. * Set up all the IEEE APPs in the DCBNL App Table and generate event for
  123. * other settings
  124. **/
  125. void i40e_dcbnl_set_all(struct i40e_vsi *vsi)
  126. {
  127. struct net_device *dev = vsi->netdev;
  128. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  129. struct i40e_dcbx_config *dcbxcfg;
  130. struct i40e_hw *hw = &pf->hw;
  131. struct dcb_app sapp;
  132. u8 prio, tc_map;
  133. int i;
  134. /* DCB not enabled */
  135. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  136. return;
  137. /* MFP mode but not an iSCSI PF so return */
  138. if ((pf->flags & I40E_FLAG_MFP_ENABLED) && !(pf->hw.func_caps.iscsi))
  139. return;
  140. dcbxcfg = &hw->local_dcbx_config;
  141. /* Set up all the App TLVs if DCBx is negotiated */
  142. for (i = 0; i < dcbxcfg->numapps; i++) {
  143. prio = dcbxcfg->app[i].priority;
  144. tc_map = BIT(dcbxcfg->etscfg.prioritytable[prio]);
  145. /* Add APP only if the TC is enabled for this VSI */
  146. if (tc_map & vsi->tc_config.enabled_tc) {
  147. sapp.selector = dcbxcfg->app[i].selector;
  148. sapp.protocol = dcbxcfg->app[i].protocolid;
  149. sapp.priority = prio;
  150. dcb_ieee_setapp(dev, &sapp);
  151. }
  152. }
  153. /* Notify user-space of the changes */
  154. dcbnl_ieee_notify(dev, RTM_SETDCB, DCB_CMD_IEEE_SET, 0, 0);
  155. }
  156. /**
  157. * i40e_dcbnl_vsi_del_app - Delete APP for given VSI
  158. * @vsi: the corresponding vsi
  159. * @app: APP to delete
  160. *
  161. * Delete given APP from the DCBNL APP table for given
  162. * VSI
  163. **/
  164. static int i40e_dcbnl_vsi_del_app(struct i40e_vsi *vsi,
  165. struct i40e_dcb_app_priority_table *app)
  166. {
  167. struct net_device *dev = vsi->netdev;
  168. struct dcb_app sapp;
  169. if (!dev)
  170. return -EINVAL;
  171. sapp.selector = app->selector;
  172. sapp.protocol = app->protocolid;
  173. sapp.priority = app->priority;
  174. return dcb_ieee_delapp(dev, &sapp);
  175. }
  176. /**
  177. * i40e_dcbnl_del_app - Delete APP on all VSIs
  178. * @pf: the corresponding PF
  179. * @app: APP to delete
  180. *
  181. * Delete given APP from all the VSIs for given PF
  182. **/
  183. static void i40e_dcbnl_del_app(struct i40e_pf *pf,
  184. struct i40e_dcb_app_priority_table *app)
  185. {
  186. int v, err;
  187. for (v = 0; v < pf->num_alloc_vsi; v++) {
  188. if (pf->vsi[v] && pf->vsi[v]->netdev) {
  189. err = i40e_dcbnl_vsi_del_app(pf->vsi[v], app);
  190. dev_dbg(&pf->pdev->dev, "Deleting app for VSI seid=%d err=%d sel=%d proto=0x%x prio=%d\n",
  191. pf->vsi[v]->seid, err, app->selector,
  192. app->protocolid, app->priority);
  193. }
  194. }
  195. }
  196. /**
  197. * i40e_dcbnl_find_app - Search APP in given DCB config
  198. * @cfg: DCBX configuration data
  199. * @app: APP to search for
  200. *
  201. * Find given APP in the DCB configuration
  202. **/
  203. static bool i40e_dcbnl_find_app(struct i40e_dcbx_config *cfg,
  204. struct i40e_dcb_app_priority_table *app)
  205. {
  206. int i;
  207. for (i = 0; i < cfg->numapps; i++) {
  208. if (app->selector == cfg->app[i].selector &&
  209. app->protocolid == cfg->app[i].protocolid &&
  210. app->priority == cfg->app[i].priority)
  211. return true;
  212. }
  213. return false;
  214. }
  215. /**
  216. * i40e_dcbnl_flush_apps - Delete all removed APPs
  217. * @pf: the corresponding PF
  218. * @old_cfg: old DCBX configuration data
  219. * @new_cfg: new DCBX configuration data
  220. *
  221. * Find and delete all APPs that are not present in the passed
  222. * DCB configuration
  223. **/
  224. void i40e_dcbnl_flush_apps(struct i40e_pf *pf,
  225. struct i40e_dcbx_config *old_cfg,
  226. struct i40e_dcbx_config *new_cfg)
  227. {
  228. struct i40e_dcb_app_priority_table app;
  229. int i;
  230. /* MFP mode but not an iSCSI PF so return */
  231. if ((pf->flags & I40E_FLAG_MFP_ENABLED) && !(pf->hw.func_caps.iscsi))
  232. return;
  233. for (i = 0; i < old_cfg->numapps; i++) {
  234. app = old_cfg->app[i];
  235. /* The APP is not available anymore delete it */
  236. if (!i40e_dcbnl_find_app(new_cfg, &app))
  237. i40e_dcbnl_del_app(pf, &app);
  238. }
  239. }
  240. /**
  241. * i40e_dcbnl_setup - DCBNL setup
  242. * @vsi: the corresponding vsi
  243. *
  244. * Set up DCBNL ops and initial APP TLVs
  245. **/
  246. void i40e_dcbnl_setup(struct i40e_vsi *vsi)
  247. {
  248. struct net_device *dev = vsi->netdev;
  249. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  250. /* Not DCB capable */
  251. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  252. return;
  253. dev->dcbnl_ops = &dcbnl_ops;
  254. /* Set initial IEEE DCB settings */
  255. i40e_dcbnl_set_all(vsi);
  256. }
  257. #endif /* CONFIG_I40E_DCB */