dcbnl.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674
  1. /*
  2. * Copyright (c) 2008, Intel Corporation.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms and conditions of the GNU General Public License,
  6. * version 2, as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along with
  14. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  15. * Place - Suite 330, Boston, MA 02111-1307 USA.
  16. *
  17. * Author: Lucy Liu <lucy.liu@intel.com>
  18. */
  19. #include <linux/netdevice.h>
  20. #include <linux/netlink.h>
  21. #include <linux/slab.h>
  22. #include <net/netlink.h>
  23. #include <net/rtnetlink.h>
  24. #include <linux/dcbnl.h>
  25. #include <net/dcbevent.h>
  26. #include <linux/rtnetlink.h>
  27. #include <net/sock.h>
  28. /**
  29. * Data Center Bridging (DCB) is a collection of Ethernet enhancements
  30. * intended to allow network traffic with differing requirements
  31. * (highly reliable, no drops vs. best effort vs. low latency) to operate
  32. * and co-exist on Ethernet. Current DCB features are:
  33. *
  34. * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
  35. * framework for assigning bandwidth guarantees to traffic classes.
  36. *
  37. * Priority-based Flow Control (PFC) - provides a flow control mechanism which
  38. * can work independently for each 802.1p priority.
  39. *
  40. * Congestion Notification - provides a mechanism for end-to-end congestion
  41. * control for protocols which do not have built-in congestion management.
  42. *
  43. * More information about the emerging standards for these Ethernet features
  44. * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
  45. *
  46. * This file implements an rtnetlink interface to allow configuration of DCB
  47. * features for capable devices.
  48. */
  49. MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
  50. MODULE_DESCRIPTION("Data Center Bridging netlink interface");
  51. MODULE_LICENSE("GPL");
  52. /**************** DCB attribute policies *************************************/
  53. /* DCB netlink attributes policy */
  54. static const struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
  55. [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
  56. [DCB_ATTR_STATE] = {.type = NLA_U8},
  57. [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED},
  58. [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED},
  59. [DCB_ATTR_SET_ALL] = {.type = NLA_U8},
  60. [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
  61. [DCB_ATTR_CAP] = {.type = NLA_NESTED},
  62. [DCB_ATTR_PFC_STATE] = {.type = NLA_U8},
  63. [DCB_ATTR_BCN] = {.type = NLA_NESTED},
  64. [DCB_ATTR_APP] = {.type = NLA_NESTED},
  65. [DCB_ATTR_IEEE] = {.type = NLA_NESTED},
  66. [DCB_ATTR_DCBX] = {.type = NLA_U8},
  67. [DCB_ATTR_FEATCFG] = {.type = NLA_NESTED},
  68. };
  69. /* DCB priority flow control to User Priority nested attributes */
  70. static const struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
  71. [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
  72. [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
  73. [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
  74. [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8},
  75. [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8},
  76. [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8},
  77. [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8},
  78. [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8},
  79. [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
  80. };
  81. /* DCB priority grouping nested attributes */
  82. static const struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
  83. [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
  84. [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
  85. [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
  86. [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED},
  87. [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED},
  88. [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED},
  89. [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED},
  90. [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED},
  91. [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED},
  92. [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8},
  93. [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8},
  94. [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8},
  95. [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8},
  96. [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8},
  97. [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8},
  98. [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8},
  99. [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8},
  100. [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
  101. };
  102. /* DCB traffic class nested attributes. */
  103. static const struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
  104. [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
  105. [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
  106. [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
  107. [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8},
  108. [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG},
  109. };
  110. /* DCB capabilities nested attributes. */
  111. static const struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
  112. [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
  113. [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
  114. [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
  115. [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8},
  116. [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8},
  117. [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
  118. [DCB_CAP_ATTR_GSP] = {.type = NLA_U8},
  119. [DCB_CAP_ATTR_BCN] = {.type = NLA_U8},
  120. [DCB_CAP_ATTR_DCBX] = {.type = NLA_U8},
  121. };
  122. /* DCB capabilities nested attributes. */
  123. static const struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
  124. [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
  125. [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
  126. [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
  127. };
  128. /* DCB BCN nested attributes. */
  129. static const struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
  130. [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8},
  131. [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8},
  132. [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8},
  133. [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8},
  134. [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8},
  135. [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8},
  136. [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8},
  137. [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8},
  138. [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG},
  139. [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32},
  140. [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32},
  141. [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32},
  142. [DCB_BCN_ATTR_BETA] = {.type = NLA_U32},
  143. [DCB_BCN_ATTR_GD] = {.type = NLA_U32},
  144. [DCB_BCN_ATTR_GI] = {.type = NLA_U32},
  145. [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32},
  146. [DCB_BCN_ATTR_TD] = {.type = NLA_U32},
  147. [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32},
  148. [DCB_BCN_ATTR_W] = {.type = NLA_U32},
  149. [DCB_BCN_ATTR_RD] = {.type = NLA_U32},
  150. [DCB_BCN_ATTR_RU] = {.type = NLA_U32},
  151. [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32},
  152. [DCB_BCN_ATTR_RI] = {.type = NLA_U32},
  153. [DCB_BCN_ATTR_C] = {.type = NLA_U32},
  154. [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG},
  155. };
  156. /* DCB APP nested attributes. */
  157. static const struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = {
  158. [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8},
  159. [DCB_APP_ATTR_ID] = {.type = NLA_U16},
  160. [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8},
  161. };
  162. /* IEEE 802.1Qaz nested attributes. */
  163. static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = {
  164. [DCB_ATTR_IEEE_ETS] = {.len = sizeof(struct ieee_ets)},
  165. [DCB_ATTR_IEEE_PFC] = {.len = sizeof(struct ieee_pfc)},
  166. [DCB_ATTR_IEEE_APP_TABLE] = {.type = NLA_NESTED},
  167. };
  168. static const struct nla_policy dcbnl_ieee_app[DCB_ATTR_IEEE_APP_MAX + 1] = {
  169. [DCB_ATTR_IEEE_APP] = {.len = sizeof(struct dcb_app)},
  170. };
  171. /* DCB number of traffic classes nested attributes. */
  172. static const struct nla_policy dcbnl_featcfg_nest[DCB_FEATCFG_ATTR_MAX + 1] = {
  173. [DCB_FEATCFG_ATTR_ALL] = {.type = NLA_FLAG},
  174. [DCB_FEATCFG_ATTR_PG] = {.type = NLA_U8},
  175. [DCB_FEATCFG_ATTR_PFC] = {.type = NLA_U8},
  176. [DCB_FEATCFG_ATTR_APP] = {.type = NLA_U8},
  177. };
  178. static LIST_HEAD(dcb_app_list);
  179. static DEFINE_SPINLOCK(dcb_lock);
  180. /* standard netlink reply call */
  181. static int dcbnl_reply(u8 value, u8 event, u8 cmd, u8 attr, u32 pid,
  182. u32 seq, u16 flags)
  183. {
  184. struct sk_buff *dcbnl_skb;
  185. struct dcbmsg *dcb;
  186. struct nlmsghdr *nlh;
  187. int ret = -EINVAL;
  188. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  189. if (!dcbnl_skb)
  190. return ret;
  191. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, event, sizeof(*dcb), flags);
  192. dcb = NLMSG_DATA(nlh);
  193. dcb->dcb_family = AF_UNSPEC;
  194. dcb->cmd = cmd;
  195. dcb->dcb_pad = 0;
  196. ret = nla_put_u8(dcbnl_skb, attr, value);
  197. if (ret)
  198. goto err;
  199. /* end the message, assign the nlmsg_len. */
  200. nlmsg_end(dcbnl_skb, nlh);
  201. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  202. if (ret)
  203. return -EINVAL;
  204. return 0;
  205. nlmsg_failure:
  206. err:
  207. kfree_skb(dcbnl_skb);
  208. return ret;
  209. }
  210. static int dcbnl_getstate(struct net_device *netdev, struct nlattr **tb,
  211. u32 pid, u32 seq, u16 flags)
  212. {
  213. int ret = -EINVAL;
  214. /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
  215. if (!netdev->dcbnl_ops->getstate)
  216. return ret;
  217. ret = dcbnl_reply(netdev->dcbnl_ops->getstate(netdev), RTM_GETDCB,
  218. DCB_CMD_GSTATE, DCB_ATTR_STATE, pid, seq, flags);
  219. return ret;
  220. }
  221. static int dcbnl_getpfccfg(struct net_device *netdev, struct nlattr **tb,
  222. u32 pid, u32 seq, u16 flags)
  223. {
  224. struct sk_buff *dcbnl_skb;
  225. struct nlmsghdr *nlh;
  226. struct dcbmsg *dcb;
  227. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
  228. u8 value;
  229. int ret = -EINVAL;
  230. int i;
  231. int getall = 0;
  232. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->getpfccfg)
  233. return ret;
  234. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  235. tb[DCB_ATTR_PFC_CFG],
  236. dcbnl_pfc_up_nest);
  237. if (ret)
  238. goto err_out;
  239. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  240. if (!dcbnl_skb)
  241. goto err_out;
  242. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  243. dcb = NLMSG_DATA(nlh);
  244. dcb->dcb_family = AF_UNSPEC;
  245. dcb->cmd = DCB_CMD_PFC_GCFG;
  246. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PFC_CFG);
  247. if (!nest)
  248. goto err;
  249. if (data[DCB_PFC_UP_ATTR_ALL])
  250. getall = 1;
  251. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  252. if (!getall && !data[i])
  253. continue;
  254. netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
  255. &value);
  256. ret = nla_put_u8(dcbnl_skb, i, value);
  257. if (ret) {
  258. nla_nest_cancel(dcbnl_skb, nest);
  259. goto err;
  260. }
  261. }
  262. nla_nest_end(dcbnl_skb, nest);
  263. nlmsg_end(dcbnl_skb, nlh);
  264. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  265. if (ret)
  266. goto err_out;
  267. return 0;
  268. nlmsg_failure:
  269. err:
  270. kfree_skb(dcbnl_skb);
  271. err_out:
  272. return -EINVAL;
  273. }
  274. static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlattr **tb,
  275. u32 pid, u32 seq, u16 flags)
  276. {
  277. struct sk_buff *dcbnl_skb;
  278. struct nlmsghdr *nlh;
  279. struct dcbmsg *dcb;
  280. u8 perm_addr[MAX_ADDR_LEN];
  281. int ret = -EINVAL;
  282. if (!netdev->dcbnl_ops->getpermhwaddr)
  283. return ret;
  284. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  285. if (!dcbnl_skb)
  286. goto err_out;
  287. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  288. dcb = NLMSG_DATA(nlh);
  289. dcb->dcb_family = AF_UNSPEC;
  290. dcb->cmd = DCB_CMD_GPERM_HWADDR;
  291. netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
  292. ret = nla_put(dcbnl_skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr),
  293. perm_addr);
  294. nlmsg_end(dcbnl_skb, nlh);
  295. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  296. if (ret)
  297. goto err_out;
  298. return 0;
  299. nlmsg_failure:
  300. kfree_skb(dcbnl_skb);
  301. err_out:
  302. return -EINVAL;
  303. }
  304. static int dcbnl_getcap(struct net_device *netdev, struct nlattr **tb,
  305. u32 pid, u32 seq, u16 flags)
  306. {
  307. struct sk_buff *dcbnl_skb;
  308. struct nlmsghdr *nlh;
  309. struct dcbmsg *dcb;
  310. struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
  311. u8 value;
  312. int ret = -EINVAL;
  313. int i;
  314. int getall = 0;
  315. if (!tb[DCB_ATTR_CAP] || !netdev->dcbnl_ops->getcap)
  316. return ret;
  317. ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP],
  318. dcbnl_cap_nest);
  319. if (ret)
  320. goto err_out;
  321. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  322. if (!dcbnl_skb)
  323. goto err_out;
  324. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  325. dcb = NLMSG_DATA(nlh);
  326. dcb->dcb_family = AF_UNSPEC;
  327. dcb->cmd = DCB_CMD_GCAP;
  328. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_CAP);
  329. if (!nest)
  330. goto err;
  331. if (data[DCB_CAP_ATTR_ALL])
  332. getall = 1;
  333. for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
  334. if (!getall && !data[i])
  335. continue;
  336. if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
  337. ret = nla_put_u8(dcbnl_skb, i, value);
  338. if (ret) {
  339. nla_nest_cancel(dcbnl_skb, nest);
  340. goto err;
  341. }
  342. }
  343. }
  344. nla_nest_end(dcbnl_skb, nest);
  345. nlmsg_end(dcbnl_skb, nlh);
  346. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  347. if (ret)
  348. goto err_out;
  349. return 0;
  350. nlmsg_failure:
  351. err:
  352. kfree_skb(dcbnl_skb);
  353. err_out:
  354. return -EINVAL;
  355. }
  356. static int dcbnl_getnumtcs(struct net_device *netdev, struct nlattr **tb,
  357. u32 pid, u32 seq, u16 flags)
  358. {
  359. struct sk_buff *dcbnl_skb;
  360. struct nlmsghdr *nlh;
  361. struct dcbmsg *dcb;
  362. struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
  363. u8 value;
  364. int ret = -EINVAL;
  365. int i;
  366. int getall = 0;
  367. if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->getnumtcs)
  368. return ret;
  369. ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
  370. dcbnl_numtcs_nest);
  371. if (ret) {
  372. ret = -EINVAL;
  373. goto err_out;
  374. }
  375. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  376. if (!dcbnl_skb) {
  377. ret = -EINVAL;
  378. goto err_out;
  379. }
  380. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  381. dcb = NLMSG_DATA(nlh);
  382. dcb->dcb_family = AF_UNSPEC;
  383. dcb->cmd = DCB_CMD_GNUMTCS;
  384. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_NUMTCS);
  385. if (!nest) {
  386. ret = -EINVAL;
  387. goto err;
  388. }
  389. if (data[DCB_NUMTCS_ATTR_ALL])
  390. getall = 1;
  391. for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
  392. if (!getall && !data[i])
  393. continue;
  394. ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
  395. if (!ret) {
  396. ret = nla_put_u8(dcbnl_skb, i, value);
  397. if (ret) {
  398. nla_nest_cancel(dcbnl_skb, nest);
  399. ret = -EINVAL;
  400. goto err;
  401. }
  402. } else {
  403. goto err;
  404. }
  405. }
  406. nla_nest_end(dcbnl_skb, nest);
  407. nlmsg_end(dcbnl_skb, nlh);
  408. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  409. if (ret) {
  410. ret = -EINVAL;
  411. goto err_out;
  412. }
  413. return 0;
  414. nlmsg_failure:
  415. err:
  416. kfree_skb(dcbnl_skb);
  417. err_out:
  418. return ret;
  419. }
  420. static int dcbnl_setnumtcs(struct net_device *netdev, struct nlattr **tb,
  421. u32 pid, u32 seq, u16 flags)
  422. {
  423. struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
  424. int ret = -EINVAL;
  425. u8 value;
  426. int i;
  427. if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->setnumtcs)
  428. return ret;
  429. ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
  430. dcbnl_numtcs_nest);
  431. if (ret) {
  432. ret = -EINVAL;
  433. goto err;
  434. }
  435. for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
  436. if (data[i] == NULL)
  437. continue;
  438. value = nla_get_u8(data[i]);
  439. ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
  440. if (ret)
  441. goto operr;
  442. }
  443. operr:
  444. ret = dcbnl_reply(!!ret, RTM_SETDCB, DCB_CMD_SNUMTCS,
  445. DCB_ATTR_NUMTCS, pid, seq, flags);
  446. err:
  447. return ret;
  448. }
  449. static int dcbnl_getpfcstate(struct net_device *netdev, struct nlattr **tb,
  450. u32 pid, u32 seq, u16 flags)
  451. {
  452. int ret = -EINVAL;
  453. if (!netdev->dcbnl_ops->getpfcstate)
  454. return ret;
  455. ret = dcbnl_reply(netdev->dcbnl_ops->getpfcstate(netdev), RTM_GETDCB,
  456. DCB_CMD_PFC_GSTATE, DCB_ATTR_PFC_STATE,
  457. pid, seq, flags);
  458. return ret;
  459. }
  460. static int dcbnl_setpfcstate(struct net_device *netdev, struct nlattr **tb,
  461. u32 pid, u32 seq, u16 flags)
  462. {
  463. int ret = -EINVAL;
  464. u8 value;
  465. if (!tb[DCB_ATTR_PFC_STATE] || !netdev->dcbnl_ops->setpfcstate)
  466. return ret;
  467. value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]);
  468. netdev->dcbnl_ops->setpfcstate(netdev, value);
  469. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SSTATE, DCB_ATTR_PFC_STATE,
  470. pid, seq, flags);
  471. return ret;
  472. }
  473. static int dcbnl_getapp(struct net_device *netdev, struct nlattr **tb,
  474. u32 pid, u32 seq, u16 flags)
  475. {
  476. struct sk_buff *dcbnl_skb;
  477. struct nlmsghdr *nlh;
  478. struct dcbmsg *dcb;
  479. struct nlattr *app_nest;
  480. struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
  481. u16 id;
  482. u8 up, idtype;
  483. int ret = -EINVAL;
  484. if (!tb[DCB_ATTR_APP] || !netdev->dcbnl_ops->getapp)
  485. goto out;
  486. ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
  487. dcbnl_app_nest);
  488. if (ret)
  489. goto out;
  490. ret = -EINVAL;
  491. /* all must be non-null */
  492. if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
  493. (!app_tb[DCB_APP_ATTR_ID]))
  494. goto out;
  495. /* either by eth type or by socket number */
  496. idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
  497. if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
  498. (idtype != DCB_APP_IDTYPE_PORTNUM))
  499. goto out;
  500. id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
  501. up = netdev->dcbnl_ops->getapp(netdev, idtype, id);
  502. /* send this back */
  503. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  504. if (!dcbnl_skb)
  505. goto out;
  506. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  507. dcb = NLMSG_DATA(nlh);
  508. dcb->dcb_family = AF_UNSPEC;
  509. dcb->cmd = DCB_CMD_GAPP;
  510. app_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_APP);
  511. ret = nla_put_u8(dcbnl_skb, DCB_APP_ATTR_IDTYPE, idtype);
  512. if (ret)
  513. goto out_cancel;
  514. ret = nla_put_u16(dcbnl_skb, DCB_APP_ATTR_ID, id);
  515. if (ret)
  516. goto out_cancel;
  517. ret = nla_put_u8(dcbnl_skb, DCB_APP_ATTR_PRIORITY, up);
  518. if (ret)
  519. goto out_cancel;
  520. nla_nest_end(dcbnl_skb, app_nest);
  521. nlmsg_end(dcbnl_skb, nlh);
  522. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  523. if (ret)
  524. goto nlmsg_failure;
  525. goto out;
  526. out_cancel:
  527. nla_nest_cancel(dcbnl_skb, app_nest);
  528. nlmsg_failure:
  529. kfree_skb(dcbnl_skb);
  530. out:
  531. return ret;
  532. }
  533. static int dcbnl_setapp(struct net_device *netdev, struct nlattr **tb,
  534. u32 pid, u32 seq, u16 flags)
  535. {
  536. int err, ret = -EINVAL;
  537. u16 id;
  538. u8 up, idtype;
  539. struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
  540. if (!tb[DCB_ATTR_APP])
  541. goto out;
  542. ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
  543. dcbnl_app_nest);
  544. if (ret)
  545. goto out;
  546. ret = -EINVAL;
  547. /* all must be non-null */
  548. if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
  549. (!app_tb[DCB_APP_ATTR_ID]) ||
  550. (!app_tb[DCB_APP_ATTR_PRIORITY]))
  551. goto out;
  552. /* either by eth type or by socket number */
  553. idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
  554. if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
  555. (idtype != DCB_APP_IDTYPE_PORTNUM))
  556. goto out;
  557. id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
  558. up = nla_get_u8(app_tb[DCB_APP_ATTR_PRIORITY]);
  559. if (netdev->dcbnl_ops->setapp) {
  560. err = netdev->dcbnl_ops->setapp(netdev, idtype, id, up);
  561. } else {
  562. struct dcb_app app;
  563. app.selector = idtype;
  564. app.protocol = id;
  565. app.priority = up;
  566. err = dcb_setapp(netdev, &app);
  567. }
  568. ret = dcbnl_reply(err, RTM_SETDCB, DCB_CMD_SAPP, DCB_ATTR_APP,
  569. pid, seq, flags);
  570. out:
  571. return ret;
  572. }
  573. static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb,
  574. u32 pid, u32 seq, u16 flags, int dir)
  575. {
  576. struct sk_buff *dcbnl_skb;
  577. struct nlmsghdr *nlh;
  578. struct dcbmsg *dcb;
  579. struct nlattr *pg_nest, *param_nest, *data;
  580. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  581. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  582. u8 prio, pgid, tc_pct, up_map;
  583. int ret = -EINVAL;
  584. int getall = 0;
  585. int i;
  586. if (!tb[DCB_ATTR_PG_CFG] ||
  587. !netdev->dcbnl_ops->getpgtccfgtx ||
  588. !netdev->dcbnl_ops->getpgtccfgrx ||
  589. !netdev->dcbnl_ops->getpgbwgcfgtx ||
  590. !netdev->dcbnl_ops->getpgbwgcfgrx)
  591. return ret;
  592. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  593. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  594. if (ret)
  595. goto err_out;
  596. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  597. if (!dcbnl_skb)
  598. goto err_out;
  599. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  600. dcb = NLMSG_DATA(nlh);
  601. dcb->dcb_family = AF_UNSPEC;
  602. dcb->cmd = (dir) ? DCB_CMD_PGRX_GCFG : DCB_CMD_PGTX_GCFG;
  603. pg_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PG_CFG);
  604. if (!pg_nest)
  605. goto err;
  606. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  607. getall = 1;
  608. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  609. if (!getall && !pg_tb[i])
  610. continue;
  611. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  612. data = pg_tb[DCB_PG_ATTR_TC_ALL];
  613. else
  614. data = pg_tb[i];
  615. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  616. data, dcbnl_tc_param_nest);
  617. if (ret)
  618. goto err_pg;
  619. param_nest = nla_nest_start(dcbnl_skb, i);
  620. if (!param_nest)
  621. goto err_pg;
  622. pgid = DCB_ATTR_VALUE_UNDEFINED;
  623. prio = DCB_ATTR_VALUE_UNDEFINED;
  624. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  625. up_map = DCB_ATTR_VALUE_UNDEFINED;
  626. if (dir) {
  627. /* Rx */
  628. netdev->dcbnl_ops->getpgtccfgrx(netdev,
  629. i - DCB_PG_ATTR_TC_0, &prio,
  630. &pgid, &tc_pct, &up_map);
  631. } else {
  632. /* Tx */
  633. netdev->dcbnl_ops->getpgtccfgtx(netdev,
  634. i - DCB_PG_ATTR_TC_0, &prio,
  635. &pgid, &tc_pct, &up_map);
  636. }
  637. if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
  638. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  639. ret = nla_put_u8(dcbnl_skb,
  640. DCB_TC_ATTR_PARAM_PGID, pgid);
  641. if (ret)
  642. goto err_param;
  643. }
  644. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
  645. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  646. ret = nla_put_u8(dcbnl_skb,
  647. DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
  648. if (ret)
  649. goto err_param;
  650. }
  651. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
  652. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  653. ret = nla_put_u8(dcbnl_skb,
  654. DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
  655. if (ret)
  656. goto err_param;
  657. }
  658. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
  659. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  660. ret = nla_put_u8(dcbnl_skb, DCB_TC_ATTR_PARAM_BW_PCT,
  661. tc_pct);
  662. if (ret)
  663. goto err_param;
  664. }
  665. nla_nest_end(dcbnl_skb, param_nest);
  666. }
  667. if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
  668. getall = 1;
  669. else
  670. getall = 0;
  671. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  672. if (!getall && !pg_tb[i])
  673. continue;
  674. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  675. if (dir) {
  676. /* Rx */
  677. netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
  678. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  679. } else {
  680. /* Tx */
  681. netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
  682. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  683. }
  684. ret = nla_put_u8(dcbnl_skb, i, tc_pct);
  685. if (ret)
  686. goto err_pg;
  687. }
  688. nla_nest_end(dcbnl_skb, pg_nest);
  689. nlmsg_end(dcbnl_skb, nlh);
  690. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  691. if (ret)
  692. goto err_out;
  693. return 0;
  694. err_param:
  695. nla_nest_cancel(dcbnl_skb, param_nest);
  696. err_pg:
  697. nla_nest_cancel(dcbnl_skb, pg_nest);
  698. nlmsg_failure:
  699. err:
  700. kfree_skb(dcbnl_skb);
  701. err_out:
  702. ret = -EINVAL;
  703. return ret;
  704. }
  705. static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlattr **tb,
  706. u32 pid, u32 seq, u16 flags)
  707. {
  708. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 0);
  709. }
  710. static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlattr **tb,
  711. u32 pid, u32 seq, u16 flags)
  712. {
  713. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 1);
  714. }
  715. static int dcbnl_setstate(struct net_device *netdev, struct nlattr **tb,
  716. u32 pid, u32 seq, u16 flags)
  717. {
  718. int ret = -EINVAL;
  719. u8 value;
  720. if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->setstate)
  721. return ret;
  722. value = nla_get_u8(tb[DCB_ATTR_STATE]);
  723. ret = dcbnl_reply(netdev->dcbnl_ops->setstate(netdev, value),
  724. RTM_SETDCB, DCB_CMD_SSTATE, DCB_ATTR_STATE,
  725. pid, seq, flags);
  726. return ret;
  727. }
  728. static int dcbnl_setpfccfg(struct net_device *netdev, struct nlattr **tb,
  729. u32 pid, u32 seq, u16 flags)
  730. {
  731. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
  732. int i;
  733. int ret = -EINVAL;
  734. u8 value;
  735. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->setpfccfg)
  736. return ret;
  737. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  738. tb[DCB_ATTR_PFC_CFG],
  739. dcbnl_pfc_up_nest);
  740. if (ret)
  741. goto err;
  742. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  743. if (data[i] == NULL)
  744. continue;
  745. value = nla_get_u8(data[i]);
  746. netdev->dcbnl_ops->setpfccfg(netdev,
  747. data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
  748. }
  749. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SCFG, DCB_ATTR_PFC_CFG,
  750. pid, seq, flags);
  751. err:
  752. return ret;
  753. }
  754. static int dcbnl_setall(struct net_device *netdev, struct nlattr **tb,
  755. u32 pid, u32 seq, u16 flags)
  756. {
  757. int ret = -EINVAL;
  758. if (!tb[DCB_ATTR_SET_ALL] || !netdev->dcbnl_ops->setall)
  759. return ret;
  760. ret = dcbnl_reply(netdev->dcbnl_ops->setall(netdev), RTM_SETDCB,
  761. DCB_CMD_SET_ALL, DCB_ATTR_SET_ALL, pid, seq, flags);
  762. return ret;
  763. }
  764. static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlattr **tb,
  765. u32 pid, u32 seq, u16 flags, int dir)
  766. {
  767. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  768. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  769. int ret = -EINVAL;
  770. int i;
  771. u8 pgid;
  772. u8 up_map;
  773. u8 prio;
  774. u8 tc_pct;
  775. if (!tb[DCB_ATTR_PG_CFG] ||
  776. !netdev->dcbnl_ops->setpgtccfgtx ||
  777. !netdev->dcbnl_ops->setpgtccfgrx ||
  778. !netdev->dcbnl_ops->setpgbwgcfgtx ||
  779. !netdev->dcbnl_ops->setpgbwgcfgrx)
  780. return ret;
  781. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  782. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  783. if (ret)
  784. goto err;
  785. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  786. if (!pg_tb[i])
  787. continue;
  788. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  789. pg_tb[i], dcbnl_tc_param_nest);
  790. if (ret)
  791. goto err;
  792. pgid = DCB_ATTR_VALUE_UNDEFINED;
  793. prio = DCB_ATTR_VALUE_UNDEFINED;
  794. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  795. up_map = DCB_ATTR_VALUE_UNDEFINED;
  796. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
  797. prio =
  798. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
  799. if (param_tb[DCB_TC_ATTR_PARAM_PGID])
  800. pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
  801. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
  802. tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
  803. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
  804. up_map =
  805. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
  806. /* dir: Tx = 0, Rx = 1 */
  807. if (dir) {
  808. /* Rx */
  809. netdev->dcbnl_ops->setpgtccfgrx(netdev,
  810. i - DCB_PG_ATTR_TC_0,
  811. prio, pgid, tc_pct, up_map);
  812. } else {
  813. /* Tx */
  814. netdev->dcbnl_ops->setpgtccfgtx(netdev,
  815. i - DCB_PG_ATTR_TC_0,
  816. prio, pgid, tc_pct, up_map);
  817. }
  818. }
  819. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  820. if (!pg_tb[i])
  821. continue;
  822. tc_pct = nla_get_u8(pg_tb[i]);
  823. /* dir: Tx = 0, Rx = 1 */
  824. if (dir) {
  825. /* Rx */
  826. netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
  827. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  828. } else {
  829. /* Tx */
  830. netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
  831. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  832. }
  833. }
  834. ret = dcbnl_reply(0, RTM_SETDCB,
  835. (dir ? DCB_CMD_PGRX_SCFG : DCB_CMD_PGTX_SCFG),
  836. DCB_ATTR_PG_CFG, pid, seq, flags);
  837. err:
  838. return ret;
  839. }
  840. static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlattr **tb,
  841. u32 pid, u32 seq, u16 flags)
  842. {
  843. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 0);
  844. }
  845. static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlattr **tb,
  846. u32 pid, u32 seq, u16 flags)
  847. {
  848. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 1);
  849. }
  850. static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlattr **tb,
  851. u32 pid, u32 seq, u16 flags)
  852. {
  853. struct sk_buff *dcbnl_skb;
  854. struct nlmsghdr *nlh;
  855. struct dcbmsg *dcb;
  856. struct nlattr *bcn_nest;
  857. struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
  858. u8 value_byte;
  859. u32 value_integer;
  860. int ret = -EINVAL;
  861. bool getall = false;
  862. int i;
  863. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->getbcnrp ||
  864. !netdev->dcbnl_ops->getbcncfg)
  865. return ret;
  866. ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX,
  867. tb[DCB_ATTR_BCN], dcbnl_bcn_nest);
  868. if (ret)
  869. goto err_out;
  870. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  871. if (!dcbnl_skb)
  872. goto err_out;
  873. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  874. dcb = NLMSG_DATA(nlh);
  875. dcb->dcb_family = AF_UNSPEC;
  876. dcb->cmd = DCB_CMD_BCN_GCFG;
  877. bcn_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_BCN);
  878. if (!bcn_nest)
  879. goto err;
  880. if (bcn_tb[DCB_BCN_ATTR_ALL])
  881. getall = true;
  882. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  883. if (!getall && !bcn_tb[i])
  884. continue;
  885. netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
  886. &value_byte);
  887. ret = nla_put_u8(dcbnl_skb, i, value_byte);
  888. if (ret)
  889. goto err_bcn;
  890. }
  891. for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
  892. if (!getall && !bcn_tb[i])
  893. continue;
  894. netdev->dcbnl_ops->getbcncfg(netdev, i,
  895. &value_integer);
  896. ret = nla_put_u32(dcbnl_skb, i, value_integer);
  897. if (ret)
  898. goto err_bcn;
  899. }
  900. nla_nest_end(dcbnl_skb, bcn_nest);
  901. nlmsg_end(dcbnl_skb, nlh);
  902. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  903. if (ret)
  904. goto err_out;
  905. return 0;
  906. err_bcn:
  907. nla_nest_cancel(dcbnl_skb, bcn_nest);
  908. nlmsg_failure:
  909. err:
  910. kfree_skb(dcbnl_skb);
  911. err_out:
  912. ret = -EINVAL;
  913. return ret;
  914. }
  915. static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlattr **tb,
  916. u32 pid, u32 seq, u16 flags)
  917. {
  918. struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
  919. int i;
  920. int ret = -EINVAL;
  921. u8 value_byte;
  922. u32 value_int;
  923. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg ||
  924. !netdev->dcbnl_ops->setbcnrp)
  925. return ret;
  926. ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX,
  927. tb[DCB_ATTR_BCN],
  928. dcbnl_pfc_up_nest);
  929. if (ret)
  930. goto err;
  931. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  932. if (data[i] == NULL)
  933. continue;
  934. value_byte = nla_get_u8(data[i]);
  935. netdev->dcbnl_ops->setbcnrp(netdev,
  936. data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
  937. }
  938. for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
  939. if (data[i] == NULL)
  940. continue;
  941. value_int = nla_get_u32(data[i]);
  942. netdev->dcbnl_ops->setbcncfg(netdev,
  943. i, value_int);
  944. }
  945. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_BCN_SCFG, DCB_ATTR_BCN,
  946. pid, seq, flags);
  947. err:
  948. return ret;
  949. }
  950. /* Handle IEEE 802.1Qaz SET commands. If any requested operation can not
  951. * be completed the entire msg is aborted and error value is returned.
  952. * No attempt is made to reconcile the case where only part of the
  953. * cmd can be completed.
  954. */
  955. static int dcbnl_ieee_set(struct net_device *netdev, struct nlattr **tb,
  956. u32 pid, u32 seq, u16 flags)
  957. {
  958. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  959. struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
  960. int err = -EOPNOTSUPP;
  961. if (!ops)
  962. goto err;
  963. err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX,
  964. tb[DCB_ATTR_IEEE], dcbnl_ieee_policy);
  965. if (err)
  966. goto err;
  967. if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) {
  968. struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]);
  969. err = ops->ieee_setets(netdev, ets);
  970. if (err)
  971. goto err;
  972. }
  973. if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setets) {
  974. struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]);
  975. err = ops->ieee_setpfc(netdev, pfc);
  976. if (err)
  977. goto err;
  978. }
  979. if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
  980. struct nlattr *attr;
  981. int rem;
  982. nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
  983. struct dcb_app *app_data;
  984. if (nla_type(attr) != DCB_ATTR_IEEE_APP)
  985. continue;
  986. app_data = nla_data(attr);
  987. if (ops->ieee_setapp)
  988. err = ops->ieee_setapp(netdev, app_data);
  989. else
  990. err = dcb_setapp(netdev, app_data);
  991. if (err)
  992. goto err;
  993. }
  994. }
  995. err:
  996. dcbnl_reply(err, RTM_SETDCB, DCB_CMD_IEEE_SET, DCB_ATTR_IEEE,
  997. pid, seq, flags);
  998. return err;
  999. }
  1000. /* Handle IEEE 802.1Qaz GET commands. */
  1001. static int dcbnl_ieee_get(struct net_device *netdev, struct nlattr **tb,
  1002. u32 pid, u32 seq, u16 flags)
  1003. {
  1004. struct sk_buff *skb;
  1005. struct nlmsghdr *nlh;
  1006. struct dcbmsg *dcb;
  1007. struct nlattr *ieee, *app;
  1008. struct dcb_app_type *itr;
  1009. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1010. int err;
  1011. if (!ops)
  1012. return -EOPNOTSUPP;
  1013. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1014. if (!skb)
  1015. return -ENOBUFS;
  1016. nlh = NLMSG_NEW(skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1017. dcb = NLMSG_DATA(nlh);
  1018. dcb->dcb_family = AF_UNSPEC;
  1019. dcb->cmd = DCB_CMD_IEEE_GET;
  1020. NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name);
  1021. ieee = nla_nest_start(skb, DCB_ATTR_IEEE);
  1022. if (!ieee)
  1023. goto nla_put_failure;
  1024. if (ops->ieee_getets) {
  1025. struct ieee_ets ets;
  1026. err = ops->ieee_getets(netdev, &ets);
  1027. if (!err)
  1028. NLA_PUT(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets);
  1029. }
  1030. if (ops->ieee_getpfc) {
  1031. struct ieee_pfc pfc;
  1032. err = ops->ieee_getpfc(netdev, &pfc);
  1033. if (!err)
  1034. NLA_PUT(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc);
  1035. }
  1036. app = nla_nest_start(skb, DCB_ATTR_IEEE_APP_TABLE);
  1037. if (!app)
  1038. goto nla_put_failure;
  1039. spin_lock(&dcb_lock);
  1040. list_for_each_entry(itr, &dcb_app_list, list) {
  1041. if (strncmp(itr->name, netdev->name, IFNAMSIZ) == 0)
  1042. NLA_PUT(skb, DCB_ATTR_IEEE_APP,
  1043. sizeof(itr->app), &itr->app);
  1044. }
  1045. spin_unlock(&dcb_lock);
  1046. nla_nest_end(skb, app);
  1047. nla_nest_end(skb, ieee);
  1048. nlmsg_end(skb, nlh);
  1049. return rtnl_unicast(skb, &init_net, pid);
  1050. nla_put_failure:
  1051. nlmsg_cancel(skb, nlh);
  1052. nlmsg_failure:
  1053. kfree_skb(skb);
  1054. return -1;
  1055. }
  1056. /* DCBX configuration */
  1057. static int dcbnl_getdcbx(struct net_device *netdev, struct nlattr **tb,
  1058. u32 pid, u32 seq, u16 flags)
  1059. {
  1060. int ret = -EINVAL;
  1061. if (!netdev->dcbnl_ops->getdcbx)
  1062. return ret;
  1063. ret = dcbnl_reply(netdev->dcbnl_ops->getdcbx(netdev), RTM_GETDCB,
  1064. DCB_CMD_GDCBX, DCB_ATTR_DCBX, pid, seq, flags);
  1065. return ret;
  1066. }
  1067. static int dcbnl_setdcbx(struct net_device *netdev, struct nlattr **tb,
  1068. u32 pid, u32 seq, u16 flags)
  1069. {
  1070. int ret = -EINVAL;
  1071. u8 value;
  1072. if (!tb[DCB_ATTR_DCBX] || !netdev->dcbnl_ops->setdcbx)
  1073. return ret;
  1074. value = nla_get_u8(tb[DCB_ATTR_DCBX]);
  1075. ret = dcbnl_reply(netdev->dcbnl_ops->setdcbx(netdev, value),
  1076. RTM_SETDCB, DCB_CMD_SDCBX, DCB_ATTR_DCBX,
  1077. pid, seq, flags);
  1078. return ret;
  1079. }
  1080. static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlattr **tb,
  1081. u32 pid, u32 seq, u16 flags)
  1082. {
  1083. struct sk_buff *dcbnl_skb;
  1084. struct nlmsghdr *nlh;
  1085. struct dcbmsg *dcb;
  1086. struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest;
  1087. u8 value;
  1088. int ret = -EINVAL;
  1089. int i;
  1090. int getall = 0;
  1091. if (!tb[DCB_ATTR_FEATCFG] || !netdev->dcbnl_ops->getfeatcfg)
  1092. return ret;
  1093. ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
  1094. dcbnl_featcfg_nest);
  1095. if (ret) {
  1096. ret = -EINVAL;
  1097. goto err_out;
  1098. }
  1099. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1100. if (!dcbnl_skb) {
  1101. ret = -EINVAL;
  1102. goto err_out;
  1103. }
  1104. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1105. dcb = NLMSG_DATA(nlh);
  1106. dcb->dcb_family = AF_UNSPEC;
  1107. dcb->cmd = DCB_CMD_GFEATCFG;
  1108. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_FEATCFG);
  1109. if (!nest) {
  1110. ret = -EINVAL;
  1111. goto err;
  1112. }
  1113. if (data[DCB_FEATCFG_ATTR_ALL])
  1114. getall = 1;
  1115. for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
  1116. if (!getall && !data[i])
  1117. continue;
  1118. ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value);
  1119. if (!ret) {
  1120. ret = nla_put_u8(dcbnl_skb, i, value);
  1121. if (ret) {
  1122. nla_nest_cancel(dcbnl_skb, nest);
  1123. ret = -EINVAL;
  1124. goto err;
  1125. }
  1126. } else
  1127. goto err;
  1128. }
  1129. nla_nest_end(dcbnl_skb, nest);
  1130. nlmsg_end(dcbnl_skb, nlh);
  1131. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  1132. if (ret) {
  1133. ret = -EINVAL;
  1134. goto err_out;
  1135. }
  1136. return 0;
  1137. nlmsg_failure:
  1138. err:
  1139. kfree_skb(dcbnl_skb);
  1140. err_out:
  1141. return ret;
  1142. }
  1143. static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlattr **tb,
  1144. u32 pid, u32 seq, u16 flags)
  1145. {
  1146. struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1];
  1147. int ret = -EINVAL;
  1148. u8 value;
  1149. int i;
  1150. if (!tb[DCB_ATTR_FEATCFG] || !netdev->dcbnl_ops->setfeatcfg)
  1151. return ret;
  1152. ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
  1153. dcbnl_featcfg_nest);
  1154. if (ret) {
  1155. ret = -EINVAL;
  1156. goto err;
  1157. }
  1158. for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
  1159. if (data[i] == NULL)
  1160. continue;
  1161. value = nla_get_u8(data[i]);
  1162. ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value);
  1163. if (ret)
  1164. goto operr;
  1165. }
  1166. operr:
  1167. ret = dcbnl_reply(!!ret, RTM_SETDCB, DCB_CMD_SFEATCFG,
  1168. DCB_ATTR_FEATCFG, pid, seq, flags);
  1169. err:
  1170. return ret;
  1171. }
  1172. static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
  1173. {
  1174. struct net *net = sock_net(skb->sk);
  1175. struct net_device *netdev;
  1176. struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
  1177. struct nlattr *tb[DCB_ATTR_MAX + 1];
  1178. u32 pid = skb ? NETLINK_CB(skb).pid : 0;
  1179. int ret = -EINVAL;
  1180. if (!net_eq(net, &init_net))
  1181. return -EINVAL;
  1182. ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
  1183. dcbnl_rtnl_policy);
  1184. if (ret < 0)
  1185. return ret;
  1186. if (!tb[DCB_ATTR_IFNAME])
  1187. return -EINVAL;
  1188. netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
  1189. if (!netdev)
  1190. return -EINVAL;
  1191. if (!netdev->dcbnl_ops)
  1192. goto errout;
  1193. switch (dcb->cmd) {
  1194. case DCB_CMD_GSTATE:
  1195. ret = dcbnl_getstate(netdev, tb, pid, nlh->nlmsg_seq,
  1196. nlh->nlmsg_flags);
  1197. goto out;
  1198. case DCB_CMD_PFC_GCFG:
  1199. ret = dcbnl_getpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  1200. nlh->nlmsg_flags);
  1201. goto out;
  1202. case DCB_CMD_GPERM_HWADDR:
  1203. ret = dcbnl_getperm_hwaddr(netdev, tb, pid, nlh->nlmsg_seq,
  1204. nlh->nlmsg_flags);
  1205. goto out;
  1206. case DCB_CMD_PGTX_GCFG:
  1207. ret = dcbnl_pgtx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1208. nlh->nlmsg_flags);
  1209. goto out;
  1210. case DCB_CMD_PGRX_GCFG:
  1211. ret = dcbnl_pgrx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1212. nlh->nlmsg_flags);
  1213. goto out;
  1214. case DCB_CMD_BCN_GCFG:
  1215. ret = dcbnl_bcn_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1216. nlh->nlmsg_flags);
  1217. goto out;
  1218. case DCB_CMD_SSTATE:
  1219. ret = dcbnl_setstate(netdev, tb, pid, nlh->nlmsg_seq,
  1220. nlh->nlmsg_flags);
  1221. goto out;
  1222. case DCB_CMD_PFC_SCFG:
  1223. ret = dcbnl_setpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  1224. nlh->nlmsg_flags);
  1225. goto out;
  1226. case DCB_CMD_SET_ALL:
  1227. ret = dcbnl_setall(netdev, tb, pid, nlh->nlmsg_seq,
  1228. nlh->nlmsg_flags);
  1229. goto out;
  1230. case DCB_CMD_PGTX_SCFG:
  1231. ret = dcbnl_pgtx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1232. nlh->nlmsg_flags);
  1233. goto out;
  1234. case DCB_CMD_PGRX_SCFG:
  1235. ret = dcbnl_pgrx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1236. nlh->nlmsg_flags);
  1237. goto out;
  1238. case DCB_CMD_GCAP:
  1239. ret = dcbnl_getcap(netdev, tb, pid, nlh->nlmsg_seq,
  1240. nlh->nlmsg_flags);
  1241. goto out;
  1242. case DCB_CMD_GNUMTCS:
  1243. ret = dcbnl_getnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  1244. nlh->nlmsg_flags);
  1245. goto out;
  1246. case DCB_CMD_SNUMTCS:
  1247. ret = dcbnl_setnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  1248. nlh->nlmsg_flags);
  1249. goto out;
  1250. case DCB_CMD_PFC_GSTATE:
  1251. ret = dcbnl_getpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  1252. nlh->nlmsg_flags);
  1253. goto out;
  1254. case DCB_CMD_PFC_SSTATE:
  1255. ret = dcbnl_setpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  1256. nlh->nlmsg_flags);
  1257. goto out;
  1258. case DCB_CMD_BCN_SCFG:
  1259. ret = dcbnl_bcn_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1260. nlh->nlmsg_flags);
  1261. goto out;
  1262. case DCB_CMD_GAPP:
  1263. ret = dcbnl_getapp(netdev, tb, pid, nlh->nlmsg_seq,
  1264. nlh->nlmsg_flags);
  1265. goto out;
  1266. case DCB_CMD_SAPP:
  1267. ret = dcbnl_setapp(netdev, tb, pid, nlh->nlmsg_seq,
  1268. nlh->nlmsg_flags);
  1269. goto out;
  1270. case DCB_CMD_IEEE_SET:
  1271. ret = dcbnl_ieee_set(netdev, tb, pid, nlh->nlmsg_seq,
  1272. nlh->nlmsg_flags);
  1273. goto out;
  1274. case DCB_CMD_IEEE_GET:
  1275. ret = dcbnl_ieee_get(netdev, tb, pid, nlh->nlmsg_seq,
  1276. nlh->nlmsg_flags);
  1277. goto out;
  1278. case DCB_CMD_GDCBX:
  1279. ret = dcbnl_getdcbx(netdev, tb, pid, nlh->nlmsg_seq,
  1280. nlh->nlmsg_flags);
  1281. goto out;
  1282. case DCB_CMD_SDCBX:
  1283. ret = dcbnl_setdcbx(netdev, tb, pid, nlh->nlmsg_seq,
  1284. nlh->nlmsg_flags);
  1285. goto out;
  1286. case DCB_CMD_GFEATCFG:
  1287. ret = dcbnl_getfeatcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1288. nlh->nlmsg_flags);
  1289. goto out;
  1290. case DCB_CMD_SFEATCFG:
  1291. ret = dcbnl_setfeatcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1292. nlh->nlmsg_flags);
  1293. goto out;
  1294. default:
  1295. goto errout;
  1296. }
  1297. errout:
  1298. ret = -EINVAL;
  1299. out:
  1300. dev_put(netdev);
  1301. return ret;
  1302. }
  1303. /**
  1304. * dcb_getapp - retrieve the DCBX application user priority
  1305. *
  1306. * On success returns a non-zero 802.1p user priority bitmap
  1307. * otherwise returns 0 as the invalid user priority bitmap to
  1308. * indicate an error.
  1309. */
  1310. u8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
  1311. {
  1312. struct dcb_app_type *itr;
  1313. u8 prio = 0;
  1314. spin_lock(&dcb_lock);
  1315. list_for_each_entry(itr, &dcb_app_list, list) {
  1316. if (itr->app.selector == app->selector &&
  1317. itr->app.protocol == app->protocol &&
  1318. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1319. prio = itr->app.priority;
  1320. break;
  1321. }
  1322. }
  1323. spin_unlock(&dcb_lock);
  1324. return prio;
  1325. }
  1326. EXPORT_SYMBOL(dcb_getapp);
  1327. /**
  1328. * ixgbe_dcbnl_setapp - add dcb application data to app list
  1329. *
  1330. * Priority 0 is the default priority this removes applications
  1331. * from the app list if the priority is set to zero.
  1332. */
  1333. u8 dcb_setapp(struct net_device *dev, struct dcb_app *new)
  1334. {
  1335. struct dcb_app_type *itr;
  1336. spin_lock(&dcb_lock);
  1337. /* Search for existing match and replace */
  1338. list_for_each_entry(itr, &dcb_app_list, list) {
  1339. if (itr->app.selector == new->selector &&
  1340. itr->app.protocol == new->protocol &&
  1341. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1342. if (new->priority)
  1343. itr->app.priority = new->priority;
  1344. else {
  1345. list_del(&itr->list);
  1346. kfree(itr);
  1347. }
  1348. goto out;
  1349. }
  1350. }
  1351. /* App type does not exist add new application type */
  1352. if (new->priority) {
  1353. struct dcb_app_type *entry;
  1354. entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
  1355. if (!entry) {
  1356. spin_unlock(&dcb_lock);
  1357. return -ENOMEM;
  1358. }
  1359. memcpy(&entry->app, new, sizeof(*new));
  1360. strncpy(entry->name, dev->name, IFNAMSIZ);
  1361. list_add(&entry->list, &dcb_app_list);
  1362. }
  1363. out:
  1364. spin_unlock(&dcb_lock);
  1365. call_dcbevent_notifiers(DCB_APP_EVENT, new);
  1366. return 0;
  1367. }
  1368. EXPORT_SYMBOL(dcb_setapp);
  1369. static void dcb_flushapp(void)
  1370. {
  1371. struct dcb_app_type *app;
  1372. spin_lock(&dcb_lock);
  1373. list_for_each_entry(app, &dcb_app_list, list) {
  1374. list_del(&app->list);
  1375. kfree(app);
  1376. }
  1377. spin_unlock(&dcb_lock);
  1378. }
  1379. static int __init dcbnl_init(void)
  1380. {
  1381. INIT_LIST_HEAD(&dcb_app_list);
  1382. rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL);
  1383. rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL);
  1384. return 0;
  1385. }
  1386. module_init(dcbnl_init);
  1387. static void __exit dcbnl_exit(void)
  1388. {
  1389. rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
  1390. rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
  1391. dcb_flushapp();
  1392. }
  1393. module_exit(dcbnl_exit);