dcbnl.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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 <net/netlink.h>
  22. #include <net/rtnetlink.h>
  23. #include <linux/dcbnl.h>
  24. #include <linux/rtnetlink.h>
  25. #include <net/sock.h>
  26. /**
  27. * Data Center Bridging (DCB) is a collection of Ethernet enhancements
  28. * intended to allow network traffic with differing requirements
  29. * (highly reliable, no drops vs. best effort vs. low latency) to operate
  30. * and co-exist on Ethernet. Current DCB features are:
  31. *
  32. * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
  33. * framework for assigning bandwidth guarantees to traffic classes.
  34. *
  35. * Priority-based Flow Control (PFC) - provides a flow control mechanism which
  36. * can work independently for each 802.1p priority.
  37. *
  38. * Congestion Notification - provides a mechanism for end-to-end congestion
  39. * control for protocols which do not have built-in congestion management.
  40. *
  41. * More information about the emerging standards for these Ethernet features
  42. * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
  43. *
  44. * This file implements an rtnetlink interface to allow configuration of DCB
  45. * features for capable devices.
  46. */
  47. MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
  48. MODULE_DESCRIPTION("Data Center Bridging netlink interface");
  49. MODULE_LICENSE("GPL");
  50. /**************** DCB attribute policies *************************************/
  51. /* DCB netlink attributes policy */
  52. static struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
  53. [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
  54. [DCB_ATTR_STATE] = {.type = NLA_U8},
  55. [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED},
  56. [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED},
  57. [DCB_ATTR_SET_ALL] = {.type = NLA_U8},
  58. [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
  59. [DCB_ATTR_CAP] = {.type = NLA_NESTED},
  60. [DCB_ATTR_PFC_STATE] = {.type = NLA_U8},
  61. [DCB_ATTR_BCN] = {.type = NLA_NESTED},
  62. };
  63. /* DCB priority flow control to User Priority nested attributes */
  64. static struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
  65. [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
  66. [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
  67. [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
  68. [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8},
  69. [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8},
  70. [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8},
  71. [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8},
  72. [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8},
  73. [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
  74. };
  75. /* DCB priority grouping nested attributes */
  76. static struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
  77. [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
  78. [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
  79. [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
  80. [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED},
  81. [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED},
  82. [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED},
  83. [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED},
  84. [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED},
  85. [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED},
  86. [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8},
  87. [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8},
  88. [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8},
  89. [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8},
  90. [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8},
  91. [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8},
  92. [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8},
  93. [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8},
  94. [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
  95. };
  96. /* DCB traffic class nested attributes. */
  97. static struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
  98. [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
  99. [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
  100. [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
  101. [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8},
  102. [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG},
  103. };
  104. /* DCB capabilities nested attributes. */
  105. static struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
  106. [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
  107. [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
  108. [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
  109. [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8},
  110. [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8},
  111. [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
  112. [DCB_CAP_ATTR_GSP] = {.type = NLA_U8},
  113. [DCB_CAP_ATTR_BCN] = {.type = NLA_U8},
  114. };
  115. /* DCB capabilities nested attributes. */
  116. static struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
  117. [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
  118. [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
  119. [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
  120. };
  121. /* DCB BCN nested attributes. */
  122. static struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
  123. [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8},
  124. [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8},
  125. [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8},
  126. [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8},
  127. [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8},
  128. [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8},
  129. [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8},
  130. [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8},
  131. [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG},
  132. [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32},
  133. [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32},
  134. [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32},
  135. [DCB_BCN_ATTR_BETA] = {.type = NLA_U32},
  136. [DCB_BCN_ATTR_GD] = {.type = NLA_U32},
  137. [DCB_BCN_ATTR_GI] = {.type = NLA_U32},
  138. [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32},
  139. [DCB_BCN_ATTR_TD] = {.type = NLA_U32},
  140. [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32},
  141. [DCB_BCN_ATTR_W] = {.type = NLA_U32},
  142. [DCB_BCN_ATTR_RD] = {.type = NLA_U32},
  143. [DCB_BCN_ATTR_RU] = {.type = NLA_U32},
  144. [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32},
  145. [DCB_BCN_ATTR_RI] = {.type = NLA_U32},
  146. [DCB_BCN_ATTR_C] = {.type = NLA_U32},
  147. [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG},
  148. };
  149. /* standard netlink reply call */
  150. static int dcbnl_reply(u8 value, u8 event, u8 cmd, u8 attr, u32 pid,
  151. u32 seq, u16 flags)
  152. {
  153. struct sk_buff *dcbnl_skb;
  154. struct dcbmsg *dcb;
  155. struct nlmsghdr *nlh;
  156. int ret = -EINVAL;
  157. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  158. if (!dcbnl_skb)
  159. return ret;
  160. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, event, sizeof(*dcb), flags);
  161. dcb = NLMSG_DATA(nlh);
  162. dcb->dcb_family = AF_UNSPEC;
  163. dcb->cmd = cmd;
  164. dcb->dcb_pad = 0;
  165. ret = nla_put_u8(dcbnl_skb, attr, value);
  166. if (ret)
  167. goto err;
  168. /* end the message, assign the nlmsg_len. */
  169. nlmsg_end(dcbnl_skb, nlh);
  170. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  171. if (ret)
  172. goto err;
  173. return 0;
  174. nlmsg_failure:
  175. err:
  176. kfree_skb(dcbnl_skb);
  177. return ret;
  178. }
  179. static int dcbnl_getstate(struct net_device *netdev, struct nlattr **tb,
  180. u32 pid, u32 seq, u16 flags)
  181. {
  182. int ret = -EINVAL;
  183. /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
  184. if (!netdev->dcbnl_ops->getstate)
  185. return ret;
  186. ret = dcbnl_reply(netdev->dcbnl_ops->getstate(netdev), RTM_GETDCB,
  187. DCB_CMD_GSTATE, DCB_ATTR_STATE, pid, seq, flags);
  188. return ret;
  189. }
  190. static int dcbnl_getpfccfg(struct net_device *netdev, struct nlattr **tb,
  191. u32 pid, u32 seq, u16 flags)
  192. {
  193. struct sk_buff *dcbnl_skb;
  194. struct nlmsghdr *nlh;
  195. struct dcbmsg *dcb;
  196. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
  197. u8 value;
  198. int ret = -EINVAL;
  199. int i;
  200. int getall = 0;
  201. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->getpfccfg)
  202. return ret;
  203. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  204. tb[DCB_ATTR_PFC_CFG],
  205. dcbnl_pfc_up_nest);
  206. if (ret)
  207. goto err_out;
  208. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  209. if (!dcbnl_skb)
  210. goto err_out;
  211. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  212. dcb = NLMSG_DATA(nlh);
  213. dcb->dcb_family = AF_UNSPEC;
  214. dcb->cmd = DCB_CMD_PFC_GCFG;
  215. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PFC_CFG);
  216. if (!nest)
  217. goto err;
  218. if (data[DCB_PFC_UP_ATTR_ALL])
  219. getall = 1;
  220. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  221. if (!getall && !data[i])
  222. continue;
  223. netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
  224. &value);
  225. ret = nla_put_u8(dcbnl_skb, i, value);
  226. if (ret) {
  227. nla_nest_cancel(dcbnl_skb, nest);
  228. goto err;
  229. }
  230. }
  231. nla_nest_end(dcbnl_skb, nest);
  232. nlmsg_end(dcbnl_skb, nlh);
  233. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  234. if (ret)
  235. goto err;
  236. return 0;
  237. nlmsg_failure:
  238. err:
  239. kfree_skb(dcbnl_skb);
  240. err_out:
  241. return -EINVAL;
  242. }
  243. static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlattr **tb,
  244. u32 pid, u32 seq, u16 flags)
  245. {
  246. struct sk_buff *dcbnl_skb;
  247. struct nlmsghdr *nlh;
  248. struct dcbmsg *dcb;
  249. u8 perm_addr[MAX_ADDR_LEN];
  250. int ret = -EINVAL;
  251. if (!netdev->dcbnl_ops->getpermhwaddr)
  252. return ret;
  253. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  254. if (!dcbnl_skb)
  255. goto err_out;
  256. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  257. dcb = NLMSG_DATA(nlh);
  258. dcb->dcb_family = AF_UNSPEC;
  259. dcb->cmd = DCB_CMD_GPERM_HWADDR;
  260. netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
  261. ret = nla_put(dcbnl_skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr),
  262. perm_addr);
  263. nlmsg_end(dcbnl_skb, nlh);
  264. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  265. if (ret)
  266. goto err;
  267. return 0;
  268. nlmsg_failure:
  269. err:
  270. kfree_skb(dcbnl_skb);
  271. err_out:
  272. return -EINVAL;
  273. }
  274. static int dcbnl_getcap(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. struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
  281. u8 value;
  282. int ret = -EINVAL;
  283. int i;
  284. int getall = 0;
  285. if (!tb[DCB_ATTR_CAP] || !netdev->dcbnl_ops->getcap)
  286. return ret;
  287. ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP],
  288. dcbnl_cap_nest);
  289. if (ret)
  290. goto err_out;
  291. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  292. if (!dcbnl_skb)
  293. goto err_out;
  294. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  295. dcb = NLMSG_DATA(nlh);
  296. dcb->dcb_family = AF_UNSPEC;
  297. dcb->cmd = DCB_CMD_GCAP;
  298. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_CAP);
  299. if (!nest)
  300. goto err;
  301. if (data[DCB_CAP_ATTR_ALL])
  302. getall = 1;
  303. for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
  304. if (!getall && !data[i])
  305. continue;
  306. if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
  307. ret = nla_put_u8(dcbnl_skb, i, value);
  308. if (ret) {
  309. nla_nest_cancel(dcbnl_skb, nest);
  310. goto err;
  311. }
  312. }
  313. }
  314. nla_nest_end(dcbnl_skb, nest);
  315. nlmsg_end(dcbnl_skb, nlh);
  316. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  317. if (ret)
  318. goto err;
  319. return 0;
  320. nlmsg_failure:
  321. err:
  322. kfree_skb(dcbnl_skb);
  323. err_out:
  324. return -EINVAL;
  325. }
  326. static int dcbnl_getnumtcs(struct net_device *netdev, struct nlattr **tb,
  327. u32 pid, u32 seq, u16 flags)
  328. {
  329. struct sk_buff *dcbnl_skb;
  330. struct nlmsghdr *nlh;
  331. struct dcbmsg *dcb;
  332. struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
  333. u8 value;
  334. int ret = -EINVAL;
  335. int i;
  336. int getall = 0;
  337. if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->getnumtcs)
  338. return ret;
  339. ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
  340. dcbnl_numtcs_nest);
  341. if (ret) {
  342. ret = -EINVAL;
  343. goto err_out;
  344. }
  345. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  346. if (!dcbnl_skb) {
  347. ret = -EINVAL;
  348. goto err_out;
  349. }
  350. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  351. dcb = NLMSG_DATA(nlh);
  352. dcb->dcb_family = AF_UNSPEC;
  353. dcb->cmd = DCB_CMD_GNUMTCS;
  354. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_NUMTCS);
  355. if (!nest) {
  356. ret = -EINVAL;
  357. goto err;
  358. }
  359. if (data[DCB_NUMTCS_ATTR_ALL])
  360. getall = 1;
  361. for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
  362. if (!getall && !data[i])
  363. continue;
  364. ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
  365. if (!ret) {
  366. ret = nla_put_u8(dcbnl_skb, i, value);
  367. if (ret) {
  368. nla_nest_cancel(dcbnl_skb, nest);
  369. ret = -EINVAL;
  370. goto err;
  371. }
  372. } else {
  373. goto err;
  374. }
  375. }
  376. nla_nest_end(dcbnl_skb, nest);
  377. nlmsg_end(dcbnl_skb, nlh);
  378. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  379. if (ret) {
  380. ret = -EINVAL;
  381. goto err;
  382. }
  383. return 0;
  384. nlmsg_failure:
  385. err:
  386. kfree_skb(dcbnl_skb);
  387. err_out:
  388. return ret;
  389. }
  390. static int dcbnl_setnumtcs(struct net_device *netdev, struct nlattr **tb,
  391. u32 pid, u32 seq, u16 flags)
  392. {
  393. struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
  394. int ret = -EINVAL;
  395. u8 value;
  396. int i;
  397. if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->setnumtcs)
  398. return ret;
  399. ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
  400. dcbnl_numtcs_nest);
  401. if (ret) {
  402. ret = -EINVAL;
  403. goto err;
  404. }
  405. for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
  406. if (data[i] == NULL)
  407. continue;
  408. value = nla_get_u8(data[i]);
  409. ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
  410. if (ret)
  411. goto operr;
  412. }
  413. operr:
  414. ret = dcbnl_reply(!!ret, RTM_SETDCB, DCB_CMD_SNUMTCS,
  415. DCB_ATTR_NUMTCS, pid, seq, flags);
  416. err:
  417. return ret;
  418. }
  419. static int dcbnl_getpfcstate(struct net_device *netdev, struct nlattr **tb,
  420. u32 pid, u32 seq, u16 flags)
  421. {
  422. int ret = -EINVAL;
  423. if (!netdev->dcbnl_ops->getpfcstate)
  424. return ret;
  425. ret = dcbnl_reply(netdev->dcbnl_ops->getpfcstate(netdev), RTM_GETDCB,
  426. DCB_CMD_PFC_GSTATE, DCB_ATTR_PFC_STATE,
  427. pid, seq, flags);
  428. return ret;
  429. }
  430. static int dcbnl_setpfcstate(struct net_device *netdev, struct nlattr **tb,
  431. u32 pid, u32 seq, u16 flags)
  432. {
  433. int ret = -EINVAL;
  434. u8 value;
  435. if (!tb[DCB_ATTR_PFC_STATE] || !netdev->dcbnl_ops->setpfcstate)
  436. return ret;
  437. value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]);
  438. netdev->dcbnl_ops->setpfcstate(netdev, value);
  439. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SSTATE, DCB_ATTR_PFC_STATE,
  440. pid, seq, flags);
  441. return ret;
  442. }
  443. static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb,
  444. u32 pid, u32 seq, u16 flags, int dir)
  445. {
  446. struct sk_buff *dcbnl_skb;
  447. struct nlmsghdr *nlh;
  448. struct dcbmsg *dcb;
  449. struct nlattr *pg_nest, *param_nest, *data;
  450. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  451. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  452. u8 prio, pgid, tc_pct, up_map;
  453. int ret = -EINVAL;
  454. int getall = 0;
  455. int i;
  456. if (!tb[DCB_ATTR_PG_CFG] ||
  457. !netdev->dcbnl_ops->getpgtccfgtx ||
  458. !netdev->dcbnl_ops->getpgtccfgrx ||
  459. !netdev->dcbnl_ops->getpgbwgcfgtx ||
  460. !netdev->dcbnl_ops->getpgbwgcfgrx)
  461. return ret;
  462. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  463. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  464. if (ret)
  465. goto err_out;
  466. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  467. if (!dcbnl_skb)
  468. goto err_out;
  469. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  470. dcb = NLMSG_DATA(nlh);
  471. dcb->dcb_family = AF_UNSPEC;
  472. dcb->cmd = (dir) ? DCB_CMD_PGRX_GCFG : DCB_CMD_PGTX_GCFG;
  473. pg_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PG_CFG);
  474. if (!pg_nest)
  475. goto err;
  476. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  477. getall = 1;
  478. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  479. if (!getall && !pg_tb[i])
  480. continue;
  481. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  482. data = pg_tb[DCB_PG_ATTR_TC_ALL];
  483. else
  484. data = pg_tb[i];
  485. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  486. data, dcbnl_tc_param_nest);
  487. if (ret)
  488. goto err_pg;
  489. param_nest = nla_nest_start(dcbnl_skb, i);
  490. if (!param_nest)
  491. goto err_pg;
  492. pgid = DCB_ATTR_VALUE_UNDEFINED;
  493. prio = DCB_ATTR_VALUE_UNDEFINED;
  494. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  495. up_map = DCB_ATTR_VALUE_UNDEFINED;
  496. if (dir) {
  497. /* Rx */
  498. netdev->dcbnl_ops->getpgtccfgrx(netdev,
  499. i - DCB_PG_ATTR_TC_0, &prio,
  500. &pgid, &tc_pct, &up_map);
  501. } else {
  502. /* Tx */
  503. netdev->dcbnl_ops->getpgtccfgtx(netdev,
  504. i - DCB_PG_ATTR_TC_0, &prio,
  505. &pgid, &tc_pct, &up_map);
  506. }
  507. if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
  508. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  509. ret = nla_put_u8(dcbnl_skb,
  510. DCB_TC_ATTR_PARAM_PGID, pgid);
  511. if (ret)
  512. goto err_param;
  513. }
  514. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
  515. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  516. ret = nla_put_u8(dcbnl_skb,
  517. DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
  518. if (ret)
  519. goto err_param;
  520. }
  521. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
  522. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  523. ret = nla_put_u8(dcbnl_skb,
  524. DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
  525. if (ret)
  526. goto err_param;
  527. }
  528. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
  529. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  530. ret = nla_put_u8(dcbnl_skb, DCB_TC_ATTR_PARAM_BW_PCT,
  531. tc_pct);
  532. if (ret)
  533. goto err_param;
  534. }
  535. nla_nest_end(dcbnl_skb, param_nest);
  536. }
  537. if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
  538. getall = 1;
  539. else
  540. getall = 0;
  541. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  542. if (!getall && !pg_tb[i])
  543. continue;
  544. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  545. if (dir) {
  546. /* Rx */
  547. netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
  548. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  549. } else {
  550. /* Tx */
  551. netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
  552. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  553. }
  554. ret = nla_put_u8(dcbnl_skb, i, tc_pct);
  555. if (ret)
  556. goto err_pg;
  557. }
  558. nla_nest_end(dcbnl_skb, pg_nest);
  559. nlmsg_end(dcbnl_skb, nlh);
  560. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  561. if (ret)
  562. goto err;
  563. return 0;
  564. err_param:
  565. nla_nest_cancel(dcbnl_skb, param_nest);
  566. err_pg:
  567. nla_nest_cancel(dcbnl_skb, pg_nest);
  568. nlmsg_failure:
  569. err:
  570. kfree_skb(dcbnl_skb);
  571. err_out:
  572. ret = -EINVAL;
  573. return ret;
  574. }
  575. static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlattr **tb,
  576. u32 pid, u32 seq, u16 flags)
  577. {
  578. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 0);
  579. }
  580. static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlattr **tb,
  581. u32 pid, u32 seq, u16 flags)
  582. {
  583. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 1);
  584. }
  585. static int dcbnl_setstate(struct net_device *netdev, struct nlattr **tb,
  586. u32 pid, u32 seq, u16 flags)
  587. {
  588. int ret = -EINVAL;
  589. u8 value;
  590. if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->setstate)
  591. return ret;
  592. value = nla_get_u8(tb[DCB_ATTR_STATE]);
  593. ret = dcbnl_reply(netdev->dcbnl_ops->setstate(netdev, value),
  594. RTM_SETDCB, DCB_CMD_SSTATE, DCB_ATTR_STATE,
  595. pid, seq, flags);
  596. return ret;
  597. }
  598. static int dcbnl_setpfccfg(struct net_device *netdev, struct nlattr **tb,
  599. u32 pid, u32 seq, u16 flags)
  600. {
  601. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
  602. int i;
  603. int ret = -EINVAL;
  604. u8 value;
  605. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->setpfccfg)
  606. return ret;
  607. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  608. tb[DCB_ATTR_PFC_CFG],
  609. dcbnl_pfc_up_nest);
  610. if (ret)
  611. goto err;
  612. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  613. if (data[i] == NULL)
  614. continue;
  615. value = nla_get_u8(data[i]);
  616. netdev->dcbnl_ops->setpfccfg(netdev,
  617. data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
  618. }
  619. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SCFG, DCB_ATTR_PFC_CFG,
  620. pid, seq, flags);
  621. err:
  622. return ret;
  623. }
  624. static int dcbnl_setall(struct net_device *netdev, struct nlattr **tb,
  625. u32 pid, u32 seq, u16 flags)
  626. {
  627. int ret = -EINVAL;
  628. if (!tb[DCB_ATTR_SET_ALL] || !netdev->dcbnl_ops->setall)
  629. return ret;
  630. ret = dcbnl_reply(netdev->dcbnl_ops->setall(netdev), RTM_SETDCB,
  631. DCB_CMD_SET_ALL, DCB_ATTR_SET_ALL, pid, seq, flags);
  632. return ret;
  633. }
  634. static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlattr **tb,
  635. u32 pid, u32 seq, u16 flags, int dir)
  636. {
  637. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  638. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  639. int ret = -EINVAL;
  640. int i;
  641. u8 pgid;
  642. u8 up_map;
  643. u8 prio;
  644. u8 tc_pct;
  645. if (!tb[DCB_ATTR_PG_CFG] ||
  646. !netdev->dcbnl_ops->setpgtccfgtx ||
  647. !netdev->dcbnl_ops->setpgtccfgrx ||
  648. !netdev->dcbnl_ops->setpgbwgcfgtx ||
  649. !netdev->dcbnl_ops->setpgbwgcfgrx)
  650. return ret;
  651. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  652. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  653. if (ret)
  654. goto err;
  655. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  656. if (!pg_tb[i])
  657. continue;
  658. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  659. pg_tb[i], dcbnl_tc_param_nest);
  660. if (ret)
  661. goto err;
  662. pgid = DCB_ATTR_VALUE_UNDEFINED;
  663. prio = DCB_ATTR_VALUE_UNDEFINED;
  664. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  665. up_map = DCB_ATTR_VALUE_UNDEFINED;
  666. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
  667. prio =
  668. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
  669. if (param_tb[DCB_TC_ATTR_PARAM_PGID])
  670. pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
  671. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
  672. tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
  673. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
  674. up_map =
  675. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
  676. /* dir: Tx = 0, Rx = 1 */
  677. if (dir) {
  678. /* Rx */
  679. netdev->dcbnl_ops->setpgtccfgrx(netdev,
  680. i - DCB_PG_ATTR_TC_0,
  681. prio, pgid, tc_pct, up_map);
  682. } else {
  683. /* Tx */
  684. netdev->dcbnl_ops->setpgtccfgtx(netdev,
  685. i - DCB_PG_ATTR_TC_0,
  686. prio, pgid, tc_pct, up_map);
  687. }
  688. }
  689. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  690. if (!pg_tb[i])
  691. continue;
  692. tc_pct = nla_get_u8(pg_tb[i]);
  693. /* dir: Tx = 0, Rx = 1 */
  694. if (dir) {
  695. /* Rx */
  696. netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
  697. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  698. } else {
  699. /* Tx */
  700. netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
  701. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  702. }
  703. }
  704. ret = dcbnl_reply(0, RTM_SETDCB,
  705. (dir ? DCB_CMD_PGRX_SCFG : DCB_CMD_PGTX_SCFG),
  706. DCB_ATTR_PG_CFG, pid, seq, flags);
  707. err:
  708. return ret;
  709. }
  710. static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlattr **tb,
  711. u32 pid, u32 seq, u16 flags)
  712. {
  713. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 0);
  714. }
  715. static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlattr **tb,
  716. u32 pid, u32 seq, u16 flags)
  717. {
  718. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 1);
  719. }
  720. static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlattr **tb,
  721. u32 pid, u32 seq, u16 flags)
  722. {
  723. struct sk_buff *dcbnl_skb;
  724. struct nlmsghdr *nlh;
  725. struct dcbmsg *dcb;
  726. struct nlattr *bcn_nest;
  727. struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
  728. u8 value_byte;
  729. u32 value_integer;
  730. int ret = -EINVAL;
  731. bool getall = false;
  732. int i;
  733. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->getbcnrp ||
  734. !netdev->dcbnl_ops->getbcncfg)
  735. return ret;
  736. ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX,
  737. tb[DCB_ATTR_BCN], dcbnl_bcn_nest);
  738. if (ret)
  739. goto err_out;
  740. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  741. if (!dcbnl_skb)
  742. goto err_out;
  743. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  744. dcb = NLMSG_DATA(nlh);
  745. dcb->dcb_family = AF_UNSPEC;
  746. dcb->cmd = DCB_CMD_BCN_GCFG;
  747. bcn_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_BCN);
  748. if (!bcn_nest)
  749. goto err;
  750. if (bcn_tb[DCB_BCN_ATTR_ALL])
  751. getall = true;
  752. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  753. if (!getall && !bcn_tb[i])
  754. continue;
  755. netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
  756. &value_byte);
  757. ret = nla_put_u8(dcbnl_skb, i, value_byte);
  758. if (ret)
  759. goto err_bcn;
  760. }
  761. for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
  762. if (!getall && !bcn_tb[i])
  763. continue;
  764. netdev->dcbnl_ops->getbcncfg(netdev, i,
  765. &value_integer);
  766. ret = nla_put_u32(dcbnl_skb, i, value_integer);
  767. if (ret)
  768. goto err_bcn;
  769. }
  770. nla_nest_end(dcbnl_skb, bcn_nest);
  771. nlmsg_end(dcbnl_skb, nlh);
  772. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  773. if (ret)
  774. goto err;
  775. return 0;
  776. err_bcn:
  777. nla_nest_cancel(dcbnl_skb, bcn_nest);
  778. nlmsg_failure:
  779. err:
  780. kfree_skb(dcbnl_skb);
  781. err_out:
  782. ret = -EINVAL;
  783. return ret;
  784. }
  785. static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlattr **tb,
  786. u32 pid, u32 seq, u16 flags)
  787. {
  788. struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
  789. int i;
  790. int ret = -EINVAL;
  791. u8 value_byte;
  792. u32 value_int;
  793. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg
  794. || !netdev->dcbnl_ops->setbcnrp)
  795. return ret;
  796. ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX,
  797. tb[DCB_ATTR_BCN],
  798. dcbnl_pfc_up_nest);
  799. if (ret)
  800. goto err;
  801. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  802. if (data[i] == NULL)
  803. continue;
  804. value_byte = nla_get_u8(data[i]);
  805. netdev->dcbnl_ops->setbcnrp(netdev,
  806. data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
  807. }
  808. for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
  809. if (data[i] == NULL)
  810. continue;
  811. value_int = nla_get_u32(data[i]);
  812. netdev->dcbnl_ops->setbcncfg(netdev,
  813. i, value_int);
  814. }
  815. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_BCN_SCFG, DCB_ATTR_BCN,
  816. pid, seq, flags);
  817. err:
  818. return ret;
  819. }
  820. static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
  821. {
  822. struct net *net = sock_net(skb->sk);
  823. struct net_device *netdev;
  824. struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
  825. struct nlattr *tb[DCB_ATTR_MAX + 1];
  826. u32 pid = skb ? NETLINK_CB(skb).pid : 0;
  827. int ret = -EINVAL;
  828. if (net != &init_net)
  829. return -EINVAL;
  830. ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
  831. dcbnl_rtnl_policy);
  832. if (ret < 0)
  833. return ret;
  834. if (!tb[DCB_ATTR_IFNAME])
  835. return -EINVAL;
  836. netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
  837. if (!netdev)
  838. return -EINVAL;
  839. if (!netdev->dcbnl_ops)
  840. goto errout;
  841. switch (dcb->cmd) {
  842. case DCB_CMD_GSTATE:
  843. ret = dcbnl_getstate(netdev, tb, pid, nlh->nlmsg_seq,
  844. nlh->nlmsg_flags);
  845. goto out;
  846. case DCB_CMD_PFC_GCFG:
  847. ret = dcbnl_getpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  848. nlh->nlmsg_flags);
  849. goto out;
  850. case DCB_CMD_GPERM_HWADDR:
  851. ret = dcbnl_getperm_hwaddr(netdev, tb, pid, nlh->nlmsg_seq,
  852. nlh->nlmsg_flags);
  853. goto out;
  854. case DCB_CMD_PGTX_GCFG:
  855. ret = dcbnl_pgtx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  856. nlh->nlmsg_flags);
  857. goto out;
  858. case DCB_CMD_PGRX_GCFG:
  859. ret = dcbnl_pgrx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  860. nlh->nlmsg_flags);
  861. goto out;
  862. case DCB_CMD_BCN_GCFG:
  863. ret = dcbnl_bcn_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  864. nlh->nlmsg_flags);
  865. goto out;
  866. case DCB_CMD_SSTATE:
  867. ret = dcbnl_setstate(netdev, tb, pid, nlh->nlmsg_seq,
  868. nlh->nlmsg_flags);
  869. goto out;
  870. case DCB_CMD_PFC_SCFG:
  871. ret = dcbnl_setpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  872. nlh->nlmsg_flags);
  873. goto out;
  874. case DCB_CMD_SET_ALL:
  875. ret = dcbnl_setall(netdev, tb, pid, nlh->nlmsg_seq,
  876. nlh->nlmsg_flags);
  877. goto out;
  878. case DCB_CMD_PGTX_SCFG:
  879. ret = dcbnl_pgtx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  880. nlh->nlmsg_flags);
  881. goto out;
  882. case DCB_CMD_PGRX_SCFG:
  883. ret = dcbnl_pgrx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  884. nlh->nlmsg_flags);
  885. goto out;
  886. case DCB_CMD_GCAP:
  887. ret = dcbnl_getcap(netdev, tb, pid, nlh->nlmsg_seq,
  888. nlh->nlmsg_flags);
  889. goto out;
  890. case DCB_CMD_GNUMTCS:
  891. ret = dcbnl_getnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  892. nlh->nlmsg_flags);
  893. goto out;
  894. case DCB_CMD_SNUMTCS:
  895. ret = dcbnl_setnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  896. nlh->nlmsg_flags);
  897. goto out;
  898. case DCB_CMD_PFC_GSTATE:
  899. ret = dcbnl_getpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  900. nlh->nlmsg_flags);
  901. goto out;
  902. case DCB_CMD_PFC_SSTATE:
  903. ret = dcbnl_setpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  904. nlh->nlmsg_flags);
  905. goto out;
  906. case DCB_CMD_BCN_SCFG:
  907. ret = dcbnl_bcn_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  908. nlh->nlmsg_flags);
  909. goto out;
  910. default:
  911. goto errout;
  912. }
  913. errout:
  914. ret = -EINVAL;
  915. out:
  916. dev_put(netdev);
  917. return ret;
  918. }
  919. static int __init dcbnl_init(void)
  920. {
  921. rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL);
  922. rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL);
  923. return 0;
  924. }
  925. module_init(dcbnl_init);
  926. static void __exit dcbnl_exit(void)
  927. {
  928. rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
  929. rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
  930. }
  931. module_exit(dcbnl_exit);