i40e_dcb_nl.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*******************************************************************************
  2. *
  3. * Intel Ethernet Controller XL710 Family Linux Driver
  4. * Copyright(c) 2013 - 2014 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. * Contact Information:
  22. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. ******************************************************************************/
  26. #ifdef CONFIG_I40E_DCB
  27. #include "i40e.h"
  28. #include <net/dcbnl.h>
  29. /**
  30. * i40e_get_pfc_delay - retrieve PFC Link Delay
  31. * @hw: pointer to hardware struct
  32. * @delay: holds the PFC Link delay value
  33. *
  34. * Returns PFC Link Delay from the PRTDCB_GENC.PFCLDA
  35. **/
  36. static void i40e_get_pfc_delay(struct i40e_hw *hw, u16 *delay)
  37. {
  38. u32 val;
  39. val = rd32(hw, I40E_PRTDCB_GENC);
  40. *delay = (u16)(val & I40E_PRTDCB_GENC_PFCLDA_MASK >>
  41. I40E_PRTDCB_GENC_PFCLDA_SHIFT);
  42. }
  43. /**
  44. * i40e_dcbnl_ieee_getets - retrieve local IEEE ETS configuration
  45. * @netdev: the corresponding netdev
  46. * @ets: structure to hold the ETS information
  47. *
  48. * Returns local IEEE ETS configuration
  49. **/
  50. static int i40e_dcbnl_ieee_getets(struct net_device *dev,
  51. struct ieee_ets *ets)
  52. {
  53. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  54. struct i40e_dcbx_config *dcbxcfg;
  55. struct i40e_hw *hw = &pf->hw;
  56. if (!(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
  57. return -EINVAL;
  58. dcbxcfg = &hw->local_dcbx_config;
  59. ets->willing = dcbxcfg->etscfg.willing;
  60. ets->ets_cap = dcbxcfg->etscfg.maxtcs;
  61. ets->cbs = dcbxcfg->etscfg.cbs;
  62. memcpy(ets->tc_tx_bw, dcbxcfg->etscfg.tcbwtable,
  63. sizeof(ets->tc_tx_bw));
  64. memcpy(ets->tc_rx_bw, dcbxcfg->etscfg.tcbwtable,
  65. sizeof(ets->tc_rx_bw));
  66. memcpy(ets->tc_tsa, dcbxcfg->etscfg.tsatable,
  67. sizeof(ets->tc_tsa));
  68. memcpy(ets->prio_tc, dcbxcfg->etscfg.prioritytable,
  69. sizeof(ets->prio_tc));
  70. memcpy(ets->tc_reco_bw, dcbxcfg->etsrec.tcbwtable,
  71. sizeof(ets->tc_reco_bw));
  72. memcpy(ets->tc_reco_tsa, dcbxcfg->etsrec.tsatable,
  73. sizeof(ets->tc_reco_tsa));
  74. memcpy(ets->reco_prio_tc, dcbxcfg->etscfg.prioritytable,
  75. sizeof(ets->reco_prio_tc));
  76. return 0;
  77. }
  78. /**
  79. * i40e_dcbnl_ieee_getpfc - retrieve local IEEE PFC configuration
  80. * @netdev: the corresponding netdev
  81. * @ets: structure to hold the PFC information
  82. *
  83. * Returns local IEEE PFC configuration
  84. **/
  85. static int i40e_dcbnl_ieee_getpfc(struct net_device *dev,
  86. struct ieee_pfc *pfc)
  87. {
  88. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  89. struct i40e_dcbx_config *dcbxcfg;
  90. struct i40e_hw *hw = &pf->hw;
  91. int i;
  92. if (!(pf->dcbx_cap & DCB_CAP_DCBX_VER_IEEE))
  93. return -EINVAL;
  94. dcbxcfg = &hw->local_dcbx_config;
  95. pfc->pfc_cap = dcbxcfg->pfc.pfccap;
  96. pfc->pfc_en = dcbxcfg->pfc.pfcenable;
  97. pfc->mbc = dcbxcfg->pfc.mbc;
  98. i40e_get_pfc_delay(hw, &pfc->delay);
  99. /* Get Requests/Indicatiosn */
  100. for (i = 0; i < I40E_MAX_TRAFFIC_CLASS; i++) {
  101. pfc->requests[i] = pf->stats.priority_xoff_tx[i];
  102. pfc->indications[i] = pf->stats.priority_xoff_rx[i];
  103. }
  104. return 0;
  105. }
  106. /**
  107. * i40e_dcbnl_getdcbx - retrieve current DCBx capability
  108. * @netdev: the corresponding netdev
  109. *
  110. * Returns DCBx capability features
  111. **/
  112. static u8 i40e_dcbnl_getdcbx(struct net_device *dev)
  113. {
  114. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  115. return pf->dcbx_cap;
  116. }
  117. /**
  118. * i40e_dcbnl_get_perm_hw_addr - MAC address used by DCBx
  119. * @netdev: the corresponding netdev
  120. *
  121. * Returns the SAN MAC address used for LLDP exchange
  122. **/
  123. static void i40e_dcbnl_get_perm_hw_addr(struct net_device *dev,
  124. u8 *perm_addr)
  125. {
  126. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  127. int i, j;
  128. memset(perm_addr, 0xff, MAX_ADDR_LEN);
  129. for (i = 0; i < dev->addr_len; i++)
  130. perm_addr[i] = pf->hw.mac.perm_addr[i];
  131. for (j = 0; j < dev->addr_len; j++, i++)
  132. perm_addr[i] = pf->hw.mac.san_addr[j];
  133. }
  134. static const struct dcbnl_rtnl_ops dcbnl_ops = {
  135. .ieee_getets = i40e_dcbnl_ieee_getets,
  136. .ieee_getpfc = i40e_dcbnl_ieee_getpfc,
  137. .getdcbx = i40e_dcbnl_getdcbx,
  138. .getpermhwaddr = i40e_dcbnl_get_perm_hw_addr,
  139. };
  140. /**
  141. * i40e_dcbnl_set_all - set all the apps and ieee data from DCBx config
  142. * @vsi: the corresponding vsi
  143. *
  144. * Set up all the IEEE APPs in the DCBNL App Table and generate event for
  145. * other settings
  146. **/
  147. void i40e_dcbnl_set_all(struct i40e_vsi *vsi)
  148. {
  149. struct net_device *dev = vsi->netdev;
  150. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  151. struct i40e_dcbx_config *dcbxcfg;
  152. struct i40e_hw *hw = &pf->hw;
  153. struct dcb_app sapp;
  154. u8 prio, tc_map;
  155. int i;
  156. /* DCB not enabled */
  157. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  158. return;
  159. dcbxcfg = &hw->local_dcbx_config;
  160. /* Set up all the App TLVs if DCBx is negotiated */
  161. for (i = 0; i < dcbxcfg->numapps; i++) {
  162. prio = dcbxcfg->app[i].priority;
  163. tc_map = (1 << dcbxcfg->etscfg.prioritytable[prio]);
  164. /* Add APP only if the TC is enabled for this VSI */
  165. if (tc_map & vsi->tc_config.enabled_tc) {
  166. sapp.selector = dcbxcfg->app[i].selector;
  167. sapp.protocol = dcbxcfg->app[i].protocolid;
  168. sapp.priority = prio;
  169. dcb_ieee_setapp(dev, &sapp);
  170. }
  171. }
  172. /* Notify user-space of the changes */
  173. dcbnl_ieee_notify(dev, RTM_SETDCB, DCB_CMD_IEEE_SET, 0, 0);
  174. }
  175. /**
  176. * i40e_dcbnl_vsi_del_app - Delete APP for given VSI
  177. * @vsi: the corresponding vsi
  178. * @app: APP to delete
  179. *
  180. * Delete given APP from the DCBNL APP table for given
  181. * VSI
  182. **/
  183. static int i40e_dcbnl_vsi_del_app(struct i40e_vsi *vsi,
  184. struct i40e_ieee_app_priority_table *app)
  185. {
  186. struct net_device *dev = vsi->netdev;
  187. struct dcb_app sapp;
  188. if (!dev)
  189. return -EINVAL;
  190. sapp.selector = app->selector;
  191. sapp.protocol = app->protocolid;
  192. sapp.priority = app->priority;
  193. return dcb_ieee_delapp(dev, &sapp);
  194. }
  195. /**
  196. * i40e_dcbnl_del_app - Delete APP on all VSIs
  197. * @pf: the corresponding pf
  198. * @app: APP to delete
  199. *
  200. * Delete given APP from all the VSIs for given PF
  201. **/
  202. static void i40e_dcbnl_del_app(struct i40e_pf *pf,
  203. struct i40e_ieee_app_priority_table *app)
  204. {
  205. int v, err;
  206. for (v = 0; v < pf->hw.func_caps.num_vsis; v++) {
  207. if (pf->vsi[v] && pf->vsi[v]->netdev) {
  208. err = i40e_dcbnl_vsi_del_app(pf->vsi[v], app);
  209. if (err)
  210. dev_info(&pf->pdev->dev, "%s: Failed deleting app for VSI seid=%d err=%d sel=%d proto=0x%x prio=%d\n",
  211. __func__, pf->vsi[v]->seid,
  212. err, app->selector,
  213. app->protocolid, app->priority);
  214. }
  215. }
  216. }
  217. /**
  218. * i40e_dcbnl_find_app - Search APP in given DCB config
  219. * @cfg: DCBX configuration data
  220. * @app: APP to search for
  221. *
  222. * Find given APP in the DCB configuration
  223. **/
  224. static bool i40e_dcbnl_find_app(struct i40e_dcbx_config *cfg,
  225. struct i40e_ieee_app_priority_table *app)
  226. {
  227. int i;
  228. for (i = 0; i < cfg->numapps; i++) {
  229. if (app->selector == cfg->app[i].selector &&
  230. app->protocolid == cfg->app[i].protocolid &&
  231. app->priority == cfg->app[i].priority)
  232. return true;
  233. }
  234. return false;
  235. }
  236. /**
  237. * i40e_dcbnl_flush_apps - Delete all removed APPs
  238. * @pf: the corresponding pf
  239. * @new_cfg: new DCBX configuration data
  240. *
  241. * Find and delete all APPs that are not present in the passed
  242. * DCB configuration
  243. **/
  244. void i40e_dcbnl_flush_apps(struct i40e_pf *pf,
  245. struct i40e_dcbx_config *new_cfg)
  246. {
  247. struct i40e_ieee_app_priority_table app;
  248. struct i40e_dcbx_config *dcbxcfg;
  249. struct i40e_hw *hw = &pf->hw;
  250. int i;
  251. dcbxcfg = &hw->local_dcbx_config;
  252. for (i = 0; i < dcbxcfg->numapps; i++) {
  253. app = dcbxcfg->app[i];
  254. /* The APP is not available anymore delete it */
  255. if (!i40e_dcbnl_find_app(new_cfg, &app))
  256. i40e_dcbnl_del_app(pf, &app);
  257. }
  258. }
  259. /**
  260. * i40e_dcbnl_setup - DCBNL setup
  261. * @vsi: the corresponding vsi
  262. *
  263. * Set up DCBNL ops and initial APP TLVs
  264. **/
  265. void i40e_dcbnl_setup(struct i40e_vsi *vsi)
  266. {
  267. struct net_device *dev = vsi->netdev;
  268. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  269. /* DCB not enabled */
  270. if (!(pf->flags & I40E_FLAG_DCB_ENABLED))
  271. return;
  272. /* Do not setup DCB NL ops for MFP mode */
  273. if (!(pf->flags & I40E_FLAG_MFP_ENABLED))
  274. dev->dcbnl_ops = &dcbnl_ops;
  275. /* Set initial IEEE DCB settings */
  276. i40e_dcbnl_set_all(vsi);
  277. }
  278. #endif /* CONFIG_I40E_DCB */