i40e_dcb_nl.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  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. /* MFP mode but not an iSCSI PF so return */
  160. if ((pf->flags & I40E_FLAG_MFP_ENABLED) && !(pf->hw.func_caps.iscsi))
  161. return;
  162. dcbxcfg = &hw->local_dcbx_config;
  163. /* Set up all the App TLVs if DCBx is negotiated */
  164. for (i = 0; i < dcbxcfg->numapps; i++) {
  165. prio = dcbxcfg->app[i].priority;
  166. tc_map = BIT(dcbxcfg->etscfg.prioritytable[prio]);
  167. /* Add APP only if the TC is enabled for this VSI */
  168. if (tc_map & vsi->tc_config.enabled_tc) {
  169. sapp.selector = dcbxcfg->app[i].selector;
  170. sapp.protocol = dcbxcfg->app[i].protocolid;
  171. sapp.priority = prio;
  172. dcb_ieee_setapp(dev, &sapp);
  173. }
  174. }
  175. /* Notify user-space of the changes */
  176. dcbnl_ieee_notify(dev, RTM_SETDCB, DCB_CMD_IEEE_SET, 0, 0);
  177. }
  178. /**
  179. * i40e_dcbnl_vsi_del_app - Delete APP for given VSI
  180. * @vsi: the corresponding vsi
  181. * @app: APP to delete
  182. *
  183. * Delete given APP from the DCBNL APP table for given
  184. * VSI
  185. **/
  186. static int i40e_dcbnl_vsi_del_app(struct i40e_vsi *vsi,
  187. struct i40e_dcb_app_priority_table *app)
  188. {
  189. struct net_device *dev = vsi->netdev;
  190. struct dcb_app sapp;
  191. if (!dev)
  192. return -EINVAL;
  193. sapp.selector = app->selector;
  194. sapp.protocol = app->protocolid;
  195. sapp.priority = app->priority;
  196. return dcb_ieee_delapp(dev, &sapp);
  197. }
  198. /**
  199. * i40e_dcbnl_del_app - Delete APP on all VSIs
  200. * @pf: the corresponding PF
  201. * @app: APP to delete
  202. *
  203. * Delete given APP from all the VSIs for given PF
  204. **/
  205. static void i40e_dcbnl_del_app(struct i40e_pf *pf,
  206. struct i40e_dcb_app_priority_table *app)
  207. {
  208. int v, err;
  209. for (v = 0; v < pf->num_alloc_vsi; v++) {
  210. if (pf->vsi[v] && pf->vsi[v]->netdev) {
  211. err = i40e_dcbnl_vsi_del_app(pf->vsi[v], app);
  212. dev_dbg(&pf->pdev->dev, "Deleting app for VSI seid=%d err=%d sel=%d proto=0x%x prio=%d\n",
  213. pf->vsi[v]->seid, err, app->selector,
  214. app->protocolid, app->priority);
  215. }
  216. }
  217. }
  218. /**
  219. * i40e_dcbnl_find_app - Search APP in given DCB config
  220. * @cfg: DCBX configuration data
  221. * @app: APP to search for
  222. *
  223. * Find given APP in the DCB configuration
  224. **/
  225. static bool i40e_dcbnl_find_app(struct i40e_dcbx_config *cfg,
  226. struct i40e_dcb_app_priority_table *app)
  227. {
  228. int i;
  229. for (i = 0; i < cfg->numapps; i++) {
  230. if (app->selector == cfg->app[i].selector &&
  231. app->protocolid == cfg->app[i].protocolid &&
  232. app->priority == cfg->app[i].priority)
  233. return true;
  234. }
  235. return false;
  236. }
  237. /**
  238. * i40e_dcbnl_flush_apps - Delete all removed APPs
  239. * @pf: the corresponding PF
  240. * @old_cfg: old DCBX configuration data
  241. * @new_cfg: new DCBX configuration data
  242. *
  243. * Find and delete all APPs that are not present in the passed
  244. * DCB configuration
  245. **/
  246. void i40e_dcbnl_flush_apps(struct i40e_pf *pf,
  247. struct i40e_dcbx_config *old_cfg,
  248. struct i40e_dcbx_config *new_cfg)
  249. {
  250. struct i40e_dcb_app_priority_table app;
  251. int i;
  252. /* MFP mode but not an iSCSI PF so return */
  253. if ((pf->flags & I40E_FLAG_MFP_ENABLED) && !(pf->hw.func_caps.iscsi))
  254. return;
  255. for (i = 0; i < old_cfg->numapps; i++) {
  256. app = old_cfg->app[i];
  257. /* The APP is not available anymore delete it */
  258. if (!i40e_dcbnl_find_app(new_cfg, &app))
  259. i40e_dcbnl_del_app(pf, &app);
  260. }
  261. }
  262. /**
  263. * i40e_dcbnl_setup - DCBNL setup
  264. * @vsi: the corresponding vsi
  265. *
  266. * Set up DCBNL ops and initial APP TLVs
  267. **/
  268. void i40e_dcbnl_setup(struct i40e_vsi *vsi)
  269. {
  270. struct net_device *dev = vsi->netdev;
  271. struct i40e_pf *pf = i40e_netdev_to_pf(dev);
  272. /* Not DCB capable */
  273. if (!(pf->flags & I40E_FLAG_DCB_CAPABLE))
  274. return;
  275. dev->dcbnl_ops = &dcbnl_ops;
  276. /* Set initial IEEE DCB settings */
  277. i40e_dcbnl_set_all(vsi);
  278. }
  279. #endif /* CONFIG_I40E_DCB */