dcbnl.c 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836
  1. /*
  2. * Copyright (c) 2008-2011, 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])
  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. if (netdev->dcbnl_ops->getapp) {
  502. up = netdev->dcbnl_ops->getapp(netdev, idtype, id);
  503. } else {
  504. struct dcb_app app = {
  505. .selector = idtype,
  506. .protocol = id,
  507. };
  508. up = dcb_getapp(netdev, &app);
  509. }
  510. /* send this back */
  511. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  512. if (!dcbnl_skb)
  513. goto out;
  514. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  515. dcb = NLMSG_DATA(nlh);
  516. dcb->dcb_family = AF_UNSPEC;
  517. dcb->cmd = DCB_CMD_GAPP;
  518. app_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_APP);
  519. if (!app_nest)
  520. goto out_cancel;
  521. ret = nla_put_u8(dcbnl_skb, DCB_APP_ATTR_IDTYPE, idtype);
  522. if (ret)
  523. goto out_cancel;
  524. ret = nla_put_u16(dcbnl_skb, DCB_APP_ATTR_ID, id);
  525. if (ret)
  526. goto out_cancel;
  527. ret = nla_put_u8(dcbnl_skb, DCB_APP_ATTR_PRIORITY, up);
  528. if (ret)
  529. goto out_cancel;
  530. nla_nest_end(dcbnl_skb, app_nest);
  531. nlmsg_end(dcbnl_skb, nlh);
  532. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  533. if (ret)
  534. goto nlmsg_failure;
  535. goto out;
  536. out_cancel:
  537. nla_nest_cancel(dcbnl_skb, app_nest);
  538. nlmsg_failure:
  539. kfree_skb(dcbnl_skb);
  540. out:
  541. return ret;
  542. }
  543. static int dcbnl_setapp(struct net_device *netdev, struct nlattr **tb,
  544. u32 pid, u32 seq, u16 flags)
  545. {
  546. int err, ret = -EINVAL;
  547. u16 id;
  548. u8 up, idtype;
  549. struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
  550. if (!tb[DCB_ATTR_APP])
  551. goto out;
  552. ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
  553. dcbnl_app_nest);
  554. if (ret)
  555. goto out;
  556. ret = -EINVAL;
  557. /* all must be non-null */
  558. if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
  559. (!app_tb[DCB_APP_ATTR_ID]) ||
  560. (!app_tb[DCB_APP_ATTR_PRIORITY]))
  561. goto out;
  562. /* either by eth type or by socket number */
  563. idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
  564. if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
  565. (idtype != DCB_APP_IDTYPE_PORTNUM))
  566. goto out;
  567. id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
  568. up = nla_get_u8(app_tb[DCB_APP_ATTR_PRIORITY]);
  569. if (netdev->dcbnl_ops->setapp) {
  570. err = netdev->dcbnl_ops->setapp(netdev, idtype, id, up);
  571. } else {
  572. struct dcb_app app;
  573. app.selector = idtype;
  574. app.protocol = id;
  575. app.priority = up;
  576. err = dcb_setapp(netdev, &app);
  577. }
  578. ret = dcbnl_reply(err, RTM_SETDCB, DCB_CMD_SAPP, DCB_ATTR_APP,
  579. pid, seq, flags);
  580. out:
  581. return ret;
  582. }
  583. static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb,
  584. u32 pid, u32 seq, u16 flags, int dir)
  585. {
  586. struct sk_buff *dcbnl_skb;
  587. struct nlmsghdr *nlh;
  588. struct dcbmsg *dcb;
  589. struct nlattr *pg_nest, *param_nest, *data;
  590. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  591. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  592. u8 prio, pgid, tc_pct, up_map;
  593. int ret = -EINVAL;
  594. int getall = 0;
  595. int i;
  596. if (!tb[DCB_ATTR_PG_CFG] ||
  597. !netdev->dcbnl_ops->getpgtccfgtx ||
  598. !netdev->dcbnl_ops->getpgtccfgrx ||
  599. !netdev->dcbnl_ops->getpgbwgcfgtx ||
  600. !netdev->dcbnl_ops->getpgbwgcfgrx)
  601. return ret;
  602. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  603. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  604. if (ret)
  605. goto err_out;
  606. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  607. if (!dcbnl_skb)
  608. goto err_out;
  609. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  610. dcb = NLMSG_DATA(nlh);
  611. dcb->dcb_family = AF_UNSPEC;
  612. dcb->cmd = (dir) ? DCB_CMD_PGRX_GCFG : DCB_CMD_PGTX_GCFG;
  613. pg_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PG_CFG);
  614. if (!pg_nest)
  615. goto err;
  616. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  617. getall = 1;
  618. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  619. if (!getall && !pg_tb[i])
  620. continue;
  621. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  622. data = pg_tb[DCB_PG_ATTR_TC_ALL];
  623. else
  624. data = pg_tb[i];
  625. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  626. data, dcbnl_tc_param_nest);
  627. if (ret)
  628. goto err_pg;
  629. param_nest = nla_nest_start(dcbnl_skb, i);
  630. if (!param_nest)
  631. goto err_pg;
  632. pgid = DCB_ATTR_VALUE_UNDEFINED;
  633. prio = DCB_ATTR_VALUE_UNDEFINED;
  634. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  635. up_map = DCB_ATTR_VALUE_UNDEFINED;
  636. if (dir) {
  637. /* Rx */
  638. netdev->dcbnl_ops->getpgtccfgrx(netdev,
  639. i - DCB_PG_ATTR_TC_0, &prio,
  640. &pgid, &tc_pct, &up_map);
  641. } else {
  642. /* Tx */
  643. netdev->dcbnl_ops->getpgtccfgtx(netdev,
  644. i - DCB_PG_ATTR_TC_0, &prio,
  645. &pgid, &tc_pct, &up_map);
  646. }
  647. if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
  648. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  649. ret = nla_put_u8(dcbnl_skb,
  650. DCB_TC_ATTR_PARAM_PGID, pgid);
  651. if (ret)
  652. goto err_param;
  653. }
  654. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
  655. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  656. ret = nla_put_u8(dcbnl_skb,
  657. DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
  658. if (ret)
  659. goto err_param;
  660. }
  661. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
  662. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  663. ret = nla_put_u8(dcbnl_skb,
  664. DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
  665. if (ret)
  666. goto err_param;
  667. }
  668. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
  669. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  670. ret = nla_put_u8(dcbnl_skb, DCB_TC_ATTR_PARAM_BW_PCT,
  671. tc_pct);
  672. if (ret)
  673. goto err_param;
  674. }
  675. nla_nest_end(dcbnl_skb, param_nest);
  676. }
  677. if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
  678. getall = 1;
  679. else
  680. getall = 0;
  681. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  682. if (!getall && !pg_tb[i])
  683. continue;
  684. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  685. if (dir) {
  686. /* Rx */
  687. netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
  688. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  689. } else {
  690. /* Tx */
  691. netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
  692. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  693. }
  694. ret = nla_put_u8(dcbnl_skb, i, tc_pct);
  695. if (ret)
  696. goto err_pg;
  697. }
  698. nla_nest_end(dcbnl_skb, pg_nest);
  699. nlmsg_end(dcbnl_skb, nlh);
  700. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  701. if (ret)
  702. goto err_out;
  703. return 0;
  704. err_param:
  705. nla_nest_cancel(dcbnl_skb, param_nest);
  706. err_pg:
  707. nla_nest_cancel(dcbnl_skb, pg_nest);
  708. nlmsg_failure:
  709. err:
  710. kfree_skb(dcbnl_skb);
  711. err_out:
  712. ret = -EINVAL;
  713. return ret;
  714. }
  715. static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlattr **tb,
  716. u32 pid, u32 seq, u16 flags)
  717. {
  718. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 0);
  719. }
  720. static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlattr **tb,
  721. u32 pid, u32 seq, u16 flags)
  722. {
  723. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 1);
  724. }
  725. static int dcbnl_setstate(struct net_device *netdev, struct nlattr **tb,
  726. u32 pid, u32 seq, u16 flags)
  727. {
  728. int ret = -EINVAL;
  729. u8 value;
  730. if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->setstate)
  731. return ret;
  732. value = nla_get_u8(tb[DCB_ATTR_STATE]);
  733. ret = dcbnl_reply(netdev->dcbnl_ops->setstate(netdev, value),
  734. RTM_SETDCB, DCB_CMD_SSTATE, DCB_ATTR_STATE,
  735. pid, seq, flags);
  736. return ret;
  737. }
  738. static int dcbnl_setpfccfg(struct net_device *netdev, struct nlattr **tb,
  739. u32 pid, u32 seq, u16 flags)
  740. {
  741. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
  742. int i;
  743. int ret = -EINVAL;
  744. u8 value;
  745. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->setpfccfg)
  746. return ret;
  747. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  748. tb[DCB_ATTR_PFC_CFG],
  749. dcbnl_pfc_up_nest);
  750. if (ret)
  751. goto err;
  752. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  753. if (data[i] == NULL)
  754. continue;
  755. value = nla_get_u8(data[i]);
  756. netdev->dcbnl_ops->setpfccfg(netdev,
  757. data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
  758. }
  759. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SCFG, DCB_ATTR_PFC_CFG,
  760. pid, seq, flags);
  761. err:
  762. return ret;
  763. }
  764. static int dcbnl_setall(struct net_device *netdev, struct nlattr **tb,
  765. u32 pid, u32 seq, u16 flags)
  766. {
  767. int ret = -EINVAL;
  768. if (!tb[DCB_ATTR_SET_ALL] || !netdev->dcbnl_ops->setall)
  769. return ret;
  770. ret = dcbnl_reply(netdev->dcbnl_ops->setall(netdev), RTM_SETDCB,
  771. DCB_CMD_SET_ALL, DCB_ATTR_SET_ALL, pid, seq, flags);
  772. return ret;
  773. }
  774. static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlattr **tb,
  775. u32 pid, u32 seq, u16 flags, int dir)
  776. {
  777. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  778. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  779. int ret = -EINVAL;
  780. int i;
  781. u8 pgid;
  782. u8 up_map;
  783. u8 prio;
  784. u8 tc_pct;
  785. if (!tb[DCB_ATTR_PG_CFG] ||
  786. !netdev->dcbnl_ops->setpgtccfgtx ||
  787. !netdev->dcbnl_ops->setpgtccfgrx ||
  788. !netdev->dcbnl_ops->setpgbwgcfgtx ||
  789. !netdev->dcbnl_ops->setpgbwgcfgrx)
  790. return ret;
  791. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  792. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  793. if (ret)
  794. goto err;
  795. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  796. if (!pg_tb[i])
  797. continue;
  798. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  799. pg_tb[i], dcbnl_tc_param_nest);
  800. if (ret)
  801. goto err;
  802. pgid = DCB_ATTR_VALUE_UNDEFINED;
  803. prio = DCB_ATTR_VALUE_UNDEFINED;
  804. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  805. up_map = DCB_ATTR_VALUE_UNDEFINED;
  806. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
  807. prio =
  808. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
  809. if (param_tb[DCB_TC_ATTR_PARAM_PGID])
  810. pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
  811. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
  812. tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
  813. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
  814. up_map =
  815. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
  816. /* dir: Tx = 0, Rx = 1 */
  817. if (dir) {
  818. /* Rx */
  819. netdev->dcbnl_ops->setpgtccfgrx(netdev,
  820. i - DCB_PG_ATTR_TC_0,
  821. prio, pgid, tc_pct, up_map);
  822. } else {
  823. /* Tx */
  824. netdev->dcbnl_ops->setpgtccfgtx(netdev,
  825. i - DCB_PG_ATTR_TC_0,
  826. prio, pgid, tc_pct, up_map);
  827. }
  828. }
  829. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  830. if (!pg_tb[i])
  831. continue;
  832. tc_pct = nla_get_u8(pg_tb[i]);
  833. /* dir: Tx = 0, Rx = 1 */
  834. if (dir) {
  835. /* Rx */
  836. netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
  837. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  838. } else {
  839. /* Tx */
  840. netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
  841. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  842. }
  843. }
  844. ret = dcbnl_reply(0, RTM_SETDCB,
  845. (dir ? DCB_CMD_PGRX_SCFG : DCB_CMD_PGTX_SCFG),
  846. DCB_ATTR_PG_CFG, pid, seq, flags);
  847. err:
  848. return ret;
  849. }
  850. static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlattr **tb,
  851. u32 pid, u32 seq, u16 flags)
  852. {
  853. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 0);
  854. }
  855. static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlattr **tb,
  856. u32 pid, u32 seq, u16 flags)
  857. {
  858. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 1);
  859. }
  860. static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlattr **tb,
  861. u32 pid, u32 seq, u16 flags)
  862. {
  863. struct sk_buff *dcbnl_skb;
  864. struct nlmsghdr *nlh;
  865. struct dcbmsg *dcb;
  866. struct nlattr *bcn_nest;
  867. struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
  868. u8 value_byte;
  869. u32 value_integer;
  870. int ret = -EINVAL;
  871. bool getall = false;
  872. int i;
  873. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->getbcnrp ||
  874. !netdev->dcbnl_ops->getbcncfg)
  875. return ret;
  876. ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX,
  877. tb[DCB_ATTR_BCN], dcbnl_bcn_nest);
  878. if (ret)
  879. goto err_out;
  880. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  881. if (!dcbnl_skb)
  882. goto err_out;
  883. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  884. dcb = NLMSG_DATA(nlh);
  885. dcb->dcb_family = AF_UNSPEC;
  886. dcb->cmd = DCB_CMD_BCN_GCFG;
  887. bcn_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_BCN);
  888. if (!bcn_nest)
  889. goto err;
  890. if (bcn_tb[DCB_BCN_ATTR_ALL])
  891. getall = true;
  892. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  893. if (!getall && !bcn_tb[i])
  894. continue;
  895. netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
  896. &value_byte);
  897. ret = nla_put_u8(dcbnl_skb, i, value_byte);
  898. if (ret)
  899. goto err_bcn;
  900. }
  901. for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
  902. if (!getall && !bcn_tb[i])
  903. continue;
  904. netdev->dcbnl_ops->getbcncfg(netdev, i,
  905. &value_integer);
  906. ret = nla_put_u32(dcbnl_skb, i, value_integer);
  907. if (ret)
  908. goto err_bcn;
  909. }
  910. nla_nest_end(dcbnl_skb, bcn_nest);
  911. nlmsg_end(dcbnl_skb, nlh);
  912. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  913. if (ret)
  914. goto err_out;
  915. return 0;
  916. err_bcn:
  917. nla_nest_cancel(dcbnl_skb, bcn_nest);
  918. nlmsg_failure:
  919. err:
  920. kfree_skb(dcbnl_skb);
  921. err_out:
  922. ret = -EINVAL;
  923. return ret;
  924. }
  925. static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlattr **tb,
  926. u32 pid, u32 seq, u16 flags)
  927. {
  928. struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
  929. int i;
  930. int ret = -EINVAL;
  931. u8 value_byte;
  932. u32 value_int;
  933. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg ||
  934. !netdev->dcbnl_ops->setbcnrp)
  935. return ret;
  936. ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX,
  937. tb[DCB_ATTR_BCN],
  938. dcbnl_pfc_up_nest);
  939. if (ret)
  940. goto err;
  941. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  942. if (data[i] == NULL)
  943. continue;
  944. value_byte = nla_get_u8(data[i]);
  945. netdev->dcbnl_ops->setbcnrp(netdev,
  946. data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
  947. }
  948. for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
  949. if (data[i] == NULL)
  950. continue;
  951. value_int = nla_get_u32(data[i]);
  952. netdev->dcbnl_ops->setbcncfg(netdev,
  953. i, value_int);
  954. }
  955. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_BCN_SCFG, DCB_ATTR_BCN,
  956. pid, seq, flags);
  957. err:
  958. return ret;
  959. }
  960. /* Handle IEEE 802.1Qaz SET commands. If any requested operation can not
  961. * be completed the entire msg is aborted and error value is returned.
  962. * No attempt is made to reconcile the case where only part of the
  963. * cmd can be completed.
  964. */
  965. static int dcbnl_ieee_set(struct net_device *netdev, struct nlattr **tb,
  966. u32 pid, u32 seq, u16 flags)
  967. {
  968. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  969. struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
  970. int err = -EOPNOTSUPP;
  971. if (!ops)
  972. goto err;
  973. err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX,
  974. tb[DCB_ATTR_IEEE], dcbnl_ieee_policy);
  975. if (err)
  976. goto err;
  977. if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) {
  978. struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]);
  979. err = ops->ieee_setets(netdev, ets);
  980. if (err)
  981. goto err;
  982. }
  983. if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setpfc) {
  984. struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]);
  985. err = ops->ieee_setpfc(netdev, pfc);
  986. if (err)
  987. goto err;
  988. }
  989. if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
  990. struct nlattr *attr;
  991. int rem;
  992. nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
  993. struct dcb_app *app_data;
  994. if (nla_type(attr) != DCB_ATTR_IEEE_APP)
  995. continue;
  996. app_data = nla_data(attr);
  997. if (ops->ieee_setapp)
  998. err = ops->ieee_setapp(netdev, app_data);
  999. else
  1000. err = dcb_setapp(netdev, app_data);
  1001. if (err)
  1002. goto err;
  1003. }
  1004. }
  1005. err:
  1006. dcbnl_reply(err, RTM_SETDCB, DCB_CMD_IEEE_SET, DCB_ATTR_IEEE,
  1007. pid, seq, flags);
  1008. return err;
  1009. }
  1010. static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
  1011. int app_nested_type, int app_info_type,
  1012. int app_entry_type)
  1013. {
  1014. struct dcb_peer_app_info info;
  1015. struct dcb_app *table = NULL;
  1016. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1017. u16 app_count;
  1018. int err;
  1019. /**
  1020. * retrieve the peer app configuration form the driver. If the driver
  1021. * handlers fail exit without doing anything
  1022. */
  1023. err = ops->peer_getappinfo(netdev, &info, &app_count);
  1024. if (!err && app_count) {
  1025. table = kmalloc(sizeof(struct dcb_app) * app_count, GFP_KERNEL);
  1026. if (!table)
  1027. return -ENOMEM;
  1028. err = ops->peer_getapptable(netdev, table);
  1029. }
  1030. if (!err) {
  1031. u16 i;
  1032. struct nlattr *app;
  1033. /**
  1034. * build the message, from here on the only possible failure
  1035. * is due to the skb size
  1036. */
  1037. err = -EMSGSIZE;
  1038. app = nla_nest_start(skb, app_nested_type);
  1039. if (!app)
  1040. goto nla_put_failure;
  1041. if (app_info_type)
  1042. NLA_PUT(skb, app_info_type, sizeof(info), &info);
  1043. for (i = 0; i < app_count; i++)
  1044. NLA_PUT(skb, app_entry_type, sizeof(struct dcb_app),
  1045. &table[i]);
  1046. nla_nest_end(skb, app);
  1047. }
  1048. err = 0;
  1049. nla_put_failure:
  1050. kfree(table);
  1051. return err;
  1052. }
  1053. /* Handle IEEE 802.1Qaz GET commands. */
  1054. static int dcbnl_ieee_get(struct net_device *netdev, struct nlattr **tb,
  1055. u32 pid, u32 seq, u16 flags)
  1056. {
  1057. struct sk_buff *skb;
  1058. struct nlmsghdr *nlh;
  1059. struct dcbmsg *dcb;
  1060. struct nlattr *ieee, *app;
  1061. struct dcb_app_type *itr;
  1062. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1063. int err;
  1064. if (!ops)
  1065. return -EOPNOTSUPP;
  1066. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1067. if (!skb)
  1068. return -ENOBUFS;
  1069. nlh = NLMSG_NEW(skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1070. dcb = NLMSG_DATA(nlh);
  1071. dcb->dcb_family = AF_UNSPEC;
  1072. dcb->cmd = DCB_CMD_IEEE_GET;
  1073. NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name);
  1074. ieee = nla_nest_start(skb, DCB_ATTR_IEEE);
  1075. if (!ieee)
  1076. goto nla_put_failure;
  1077. if (ops->ieee_getets) {
  1078. struct ieee_ets ets;
  1079. err = ops->ieee_getets(netdev, &ets);
  1080. if (!err)
  1081. NLA_PUT(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets);
  1082. }
  1083. if (ops->ieee_getpfc) {
  1084. struct ieee_pfc pfc;
  1085. err = ops->ieee_getpfc(netdev, &pfc);
  1086. if (!err)
  1087. NLA_PUT(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc);
  1088. }
  1089. app = nla_nest_start(skb, DCB_ATTR_IEEE_APP_TABLE);
  1090. if (!app)
  1091. goto nla_put_failure;
  1092. spin_lock(&dcb_lock);
  1093. list_for_each_entry(itr, &dcb_app_list, list) {
  1094. if (strncmp(itr->name, netdev->name, IFNAMSIZ) == 0) {
  1095. err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app),
  1096. &itr->app);
  1097. if (err) {
  1098. spin_unlock(&dcb_lock);
  1099. goto nla_put_failure;
  1100. }
  1101. }
  1102. }
  1103. spin_unlock(&dcb_lock);
  1104. nla_nest_end(skb, app);
  1105. /* get peer info if available */
  1106. if (ops->ieee_peer_getets) {
  1107. struct ieee_ets ets;
  1108. err = ops->ieee_peer_getets(netdev, &ets);
  1109. if (!err)
  1110. NLA_PUT(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets);
  1111. }
  1112. if (ops->ieee_peer_getpfc) {
  1113. struct ieee_pfc pfc;
  1114. err = ops->ieee_peer_getpfc(netdev, &pfc);
  1115. if (!err)
  1116. NLA_PUT(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc);
  1117. }
  1118. if (ops->peer_getappinfo && ops->peer_getapptable) {
  1119. err = dcbnl_build_peer_app(netdev, skb,
  1120. DCB_ATTR_IEEE_PEER_APP,
  1121. DCB_ATTR_IEEE_APP_UNSPEC,
  1122. DCB_ATTR_IEEE_APP);
  1123. if (err)
  1124. goto nla_put_failure;
  1125. }
  1126. nla_nest_end(skb, ieee);
  1127. nlmsg_end(skb, nlh);
  1128. return rtnl_unicast(skb, &init_net, pid);
  1129. nla_put_failure:
  1130. nlmsg_cancel(skb, nlh);
  1131. nlmsg_failure:
  1132. kfree_skb(skb);
  1133. return -1;
  1134. }
  1135. /* DCBX configuration */
  1136. static int dcbnl_getdcbx(struct net_device *netdev, struct nlattr **tb,
  1137. u32 pid, u32 seq, u16 flags)
  1138. {
  1139. int ret;
  1140. if (!netdev->dcbnl_ops->getdcbx)
  1141. return -EOPNOTSUPP;
  1142. ret = dcbnl_reply(netdev->dcbnl_ops->getdcbx(netdev), RTM_GETDCB,
  1143. DCB_CMD_GDCBX, DCB_ATTR_DCBX, pid, seq, flags);
  1144. return ret;
  1145. }
  1146. static int dcbnl_setdcbx(struct net_device *netdev, struct nlattr **tb,
  1147. u32 pid, u32 seq, u16 flags)
  1148. {
  1149. int ret;
  1150. u8 value;
  1151. if (!netdev->dcbnl_ops->setdcbx)
  1152. return -EOPNOTSUPP;
  1153. if (!tb[DCB_ATTR_DCBX])
  1154. return -EINVAL;
  1155. value = nla_get_u8(tb[DCB_ATTR_DCBX]);
  1156. ret = dcbnl_reply(netdev->dcbnl_ops->setdcbx(netdev, value),
  1157. RTM_SETDCB, DCB_CMD_SDCBX, DCB_ATTR_DCBX,
  1158. pid, seq, flags);
  1159. return ret;
  1160. }
  1161. static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlattr **tb,
  1162. u32 pid, u32 seq, u16 flags)
  1163. {
  1164. struct sk_buff *dcbnl_skb;
  1165. struct nlmsghdr *nlh;
  1166. struct dcbmsg *dcb;
  1167. struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest;
  1168. u8 value;
  1169. int ret, i;
  1170. int getall = 0;
  1171. if (!netdev->dcbnl_ops->getfeatcfg)
  1172. return -EOPNOTSUPP;
  1173. if (!tb[DCB_ATTR_FEATCFG])
  1174. return -EINVAL;
  1175. ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
  1176. dcbnl_featcfg_nest);
  1177. if (ret)
  1178. goto err_out;
  1179. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1180. if (!dcbnl_skb) {
  1181. ret = -ENOBUFS;
  1182. goto err_out;
  1183. }
  1184. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1185. dcb = NLMSG_DATA(nlh);
  1186. dcb->dcb_family = AF_UNSPEC;
  1187. dcb->cmd = DCB_CMD_GFEATCFG;
  1188. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_FEATCFG);
  1189. if (!nest) {
  1190. ret = -EMSGSIZE;
  1191. goto nla_put_failure;
  1192. }
  1193. if (data[DCB_FEATCFG_ATTR_ALL])
  1194. getall = 1;
  1195. for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
  1196. if (!getall && !data[i])
  1197. continue;
  1198. ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value);
  1199. if (!ret)
  1200. ret = nla_put_u8(dcbnl_skb, i, value);
  1201. if (ret) {
  1202. nla_nest_cancel(dcbnl_skb, nest);
  1203. goto nla_put_failure;
  1204. }
  1205. }
  1206. nla_nest_end(dcbnl_skb, nest);
  1207. nlmsg_end(dcbnl_skb, nlh);
  1208. return rtnl_unicast(dcbnl_skb, &init_net, pid);
  1209. nla_put_failure:
  1210. nlmsg_cancel(dcbnl_skb, nlh);
  1211. nlmsg_failure:
  1212. kfree_skb(dcbnl_skb);
  1213. err_out:
  1214. return ret;
  1215. }
  1216. static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlattr **tb,
  1217. u32 pid, u32 seq, u16 flags)
  1218. {
  1219. struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1];
  1220. int ret, i;
  1221. u8 value;
  1222. if (!netdev->dcbnl_ops->setfeatcfg)
  1223. return -ENOTSUPP;
  1224. if (!tb[DCB_ATTR_FEATCFG])
  1225. return -EINVAL;
  1226. ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
  1227. dcbnl_featcfg_nest);
  1228. if (ret)
  1229. goto err;
  1230. for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
  1231. if (data[i] == NULL)
  1232. continue;
  1233. value = nla_get_u8(data[i]);
  1234. ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value);
  1235. if (ret)
  1236. goto err;
  1237. }
  1238. err:
  1239. dcbnl_reply(ret, RTM_SETDCB, DCB_CMD_SFEATCFG, DCB_ATTR_FEATCFG,
  1240. pid, seq, flags);
  1241. return ret;
  1242. }
  1243. /* Handle CEE DCBX GET commands. */
  1244. static int dcbnl_cee_get(struct net_device *netdev, struct nlattr **tb,
  1245. u32 pid, u32 seq, u16 flags)
  1246. {
  1247. struct sk_buff *skb;
  1248. struct nlmsghdr *nlh;
  1249. struct dcbmsg *dcb;
  1250. struct nlattr *cee;
  1251. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1252. int err;
  1253. if (!ops)
  1254. return -EOPNOTSUPP;
  1255. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1256. if (!skb)
  1257. return -ENOBUFS;
  1258. nlh = NLMSG_NEW(skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1259. dcb = NLMSG_DATA(nlh);
  1260. dcb->dcb_family = AF_UNSPEC;
  1261. dcb->cmd = DCB_CMD_CEE_GET;
  1262. NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name);
  1263. cee = nla_nest_start(skb, DCB_ATTR_CEE);
  1264. if (!cee)
  1265. goto nla_put_failure;
  1266. /* get peer info if available */
  1267. if (ops->cee_peer_getpg) {
  1268. struct cee_pg pg;
  1269. err = ops->cee_peer_getpg(netdev, &pg);
  1270. if (!err)
  1271. NLA_PUT(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg);
  1272. }
  1273. if (ops->cee_peer_getpfc) {
  1274. struct cee_pfc pfc;
  1275. err = ops->cee_peer_getpfc(netdev, &pfc);
  1276. if (!err)
  1277. NLA_PUT(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc);
  1278. }
  1279. if (ops->peer_getappinfo && ops->peer_getapptable) {
  1280. err = dcbnl_build_peer_app(netdev, skb,
  1281. DCB_ATTR_CEE_PEER_APP_TABLE,
  1282. DCB_ATTR_CEE_PEER_APP_INFO,
  1283. DCB_ATTR_CEE_PEER_APP);
  1284. if (err)
  1285. goto nla_put_failure;
  1286. }
  1287. nla_nest_end(skb, cee);
  1288. nlmsg_end(skb, nlh);
  1289. return rtnl_unicast(skb, &init_net, pid);
  1290. nla_put_failure:
  1291. nlmsg_cancel(skb, nlh);
  1292. nlmsg_failure:
  1293. kfree_skb(skb);
  1294. return -1;
  1295. }
  1296. static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
  1297. {
  1298. struct net *net = sock_net(skb->sk);
  1299. struct net_device *netdev;
  1300. struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
  1301. struct nlattr *tb[DCB_ATTR_MAX + 1];
  1302. u32 pid = skb ? NETLINK_CB(skb).pid : 0;
  1303. int ret = -EINVAL;
  1304. if (!net_eq(net, &init_net))
  1305. return -EINVAL;
  1306. ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
  1307. dcbnl_rtnl_policy);
  1308. if (ret < 0)
  1309. return ret;
  1310. if (!tb[DCB_ATTR_IFNAME])
  1311. return -EINVAL;
  1312. netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
  1313. if (!netdev)
  1314. return -EINVAL;
  1315. if (!netdev->dcbnl_ops)
  1316. goto errout;
  1317. switch (dcb->cmd) {
  1318. case DCB_CMD_GSTATE:
  1319. ret = dcbnl_getstate(netdev, tb, pid, nlh->nlmsg_seq,
  1320. nlh->nlmsg_flags);
  1321. goto out;
  1322. case DCB_CMD_PFC_GCFG:
  1323. ret = dcbnl_getpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  1324. nlh->nlmsg_flags);
  1325. goto out;
  1326. case DCB_CMD_GPERM_HWADDR:
  1327. ret = dcbnl_getperm_hwaddr(netdev, tb, pid, nlh->nlmsg_seq,
  1328. nlh->nlmsg_flags);
  1329. goto out;
  1330. case DCB_CMD_PGTX_GCFG:
  1331. ret = dcbnl_pgtx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1332. nlh->nlmsg_flags);
  1333. goto out;
  1334. case DCB_CMD_PGRX_GCFG:
  1335. ret = dcbnl_pgrx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1336. nlh->nlmsg_flags);
  1337. goto out;
  1338. case DCB_CMD_BCN_GCFG:
  1339. ret = dcbnl_bcn_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1340. nlh->nlmsg_flags);
  1341. goto out;
  1342. case DCB_CMD_SSTATE:
  1343. ret = dcbnl_setstate(netdev, tb, pid, nlh->nlmsg_seq,
  1344. nlh->nlmsg_flags);
  1345. goto out;
  1346. case DCB_CMD_PFC_SCFG:
  1347. ret = dcbnl_setpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  1348. nlh->nlmsg_flags);
  1349. goto out;
  1350. case DCB_CMD_SET_ALL:
  1351. ret = dcbnl_setall(netdev, tb, pid, nlh->nlmsg_seq,
  1352. nlh->nlmsg_flags);
  1353. goto out;
  1354. case DCB_CMD_PGTX_SCFG:
  1355. ret = dcbnl_pgtx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1356. nlh->nlmsg_flags);
  1357. goto out;
  1358. case DCB_CMD_PGRX_SCFG:
  1359. ret = dcbnl_pgrx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1360. nlh->nlmsg_flags);
  1361. goto out;
  1362. case DCB_CMD_GCAP:
  1363. ret = dcbnl_getcap(netdev, tb, pid, nlh->nlmsg_seq,
  1364. nlh->nlmsg_flags);
  1365. goto out;
  1366. case DCB_CMD_GNUMTCS:
  1367. ret = dcbnl_getnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  1368. nlh->nlmsg_flags);
  1369. goto out;
  1370. case DCB_CMD_SNUMTCS:
  1371. ret = dcbnl_setnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  1372. nlh->nlmsg_flags);
  1373. goto out;
  1374. case DCB_CMD_PFC_GSTATE:
  1375. ret = dcbnl_getpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  1376. nlh->nlmsg_flags);
  1377. goto out;
  1378. case DCB_CMD_PFC_SSTATE:
  1379. ret = dcbnl_setpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  1380. nlh->nlmsg_flags);
  1381. goto out;
  1382. case DCB_CMD_BCN_SCFG:
  1383. ret = dcbnl_bcn_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1384. nlh->nlmsg_flags);
  1385. goto out;
  1386. case DCB_CMD_GAPP:
  1387. ret = dcbnl_getapp(netdev, tb, pid, nlh->nlmsg_seq,
  1388. nlh->nlmsg_flags);
  1389. goto out;
  1390. case DCB_CMD_SAPP:
  1391. ret = dcbnl_setapp(netdev, tb, pid, nlh->nlmsg_seq,
  1392. nlh->nlmsg_flags);
  1393. goto out;
  1394. case DCB_CMD_IEEE_SET:
  1395. ret = dcbnl_ieee_set(netdev, tb, pid, nlh->nlmsg_seq,
  1396. nlh->nlmsg_flags);
  1397. goto out;
  1398. case DCB_CMD_IEEE_GET:
  1399. ret = dcbnl_ieee_get(netdev, tb, pid, nlh->nlmsg_seq,
  1400. nlh->nlmsg_flags);
  1401. goto out;
  1402. case DCB_CMD_GDCBX:
  1403. ret = dcbnl_getdcbx(netdev, tb, pid, nlh->nlmsg_seq,
  1404. nlh->nlmsg_flags);
  1405. goto out;
  1406. case DCB_CMD_SDCBX:
  1407. ret = dcbnl_setdcbx(netdev, tb, pid, nlh->nlmsg_seq,
  1408. nlh->nlmsg_flags);
  1409. goto out;
  1410. case DCB_CMD_GFEATCFG:
  1411. ret = dcbnl_getfeatcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1412. nlh->nlmsg_flags);
  1413. goto out;
  1414. case DCB_CMD_SFEATCFG:
  1415. ret = dcbnl_setfeatcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1416. nlh->nlmsg_flags);
  1417. goto out;
  1418. case DCB_CMD_CEE_GET:
  1419. ret = dcbnl_cee_get(netdev, tb, pid, nlh->nlmsg_seq,
  1420. nlh->nlmsg_flags);
  1421. goto out;
  1422. default:
  1423. goto errout;
  1424. }
  1425. errout:
  1426. ret = -EINVAL;
  1427. out:
  1428. dev_put(netdev);
  1429. return ret;
  1430. }
  1431. /**
  1432. * dcb_getapp - retrieve the DCBX application user priority
  1433. *
  1434. * On success returns a non-zero 802.1p user priority bitmap
  1435. * otherwise returns 0 as the invalid user priority bitmap to
  1436. * indicate an error.
  1437. */
  1438. u8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
  1439. {
  1440. struct dcb_app_type *itr;
  1441. u8 prio = 0;
  1442. spin_lock(&dcb_lock);
  1443. list_for_each_entry(itr, &dcb_app_list, list) {
  1444. if (itr->app.selector == app->selector &&
  1445. itr->app.protocol == app->protocol &&
  1446. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1447. prio = itr->app.priority;
  1448. break;
  1449. }
  1450. }
  1451. spin_unlock(&dcb_lock);
  1452. return prio;
  1453. }
  1454. EXPORT_SYMBOL(dcb_getapp);
  1455. /**
  1456. * ixgbe_dcbnl_setapp - add dcb application data to app list
  1457. *
  1458. * Priority 0 is the default priority this removes applications
  1459. * from the app list if the priority is set to zero.
  1460. */
  1461. u8 dcb_setapp(struct net_device *dev, struct dcb_app *new)
  1462. {
  1463. struct dcb_app_type *itr;
  1464. struct dcb_app_type event;
  1465. memcpy(&event.name, dev->name, sizeof(event.name));
  1466. memcpy(&event.app, new, sizeof(event.app));
  1467. spin_lock(&dcb_lock);
  1468. /* Search for existing match and replace */
  1469. list_for_each_entry(itr, &dcb_app_list, list) {
  1470. if (itr->app.selector == new->selector &&
  1471. itr->app.protocol == new->protocol &&
  1472. (strncmp(itr->name, dev->name, IFNAMSIZ) == 0)) {
  1473. if (new->priority)
  1474. itr->app.priority = new->priority;
  1475. else {
  1476. list_del(&itr->list);
  1477. kfree(itr);
  1478. }
  1479. goto out;
  1480. }
  1481. }
  1482. /* App type does not exist add new application type */
  1483. if (new->priority) {
  1484. struct dcb_app_type *entry;
  1485. entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
  1486. if (!entry) {
  1487. spin_unlock(&dcb_lock);
  1488. return -ENOMEM;
  1489. }
  1490. memcpy(&entry->app, new, sizeof(*new));
  1491. strncpy(entry->name, dev->name, IFNAMSIZ);
  1492. list_add(&entry->list, &dcb_app_list);
  1493. }
  1494. out:
  1495. spin_unlock(&dcb_lock);
  1496. call_dcbevent_notifiers(DCB_APP_EVENT, &event);
  1497. return 0;
  1498. }
  1499. EXPORT_SYMBOL(dcb_setapp);
  1500. static void dcb_flushapp(void)
  1501. {
  1502. struct dcb_app_type *app;
  1503. struct dcb_app_type *tmp;
  1504. spin_lock(&dcb_lock);
  1505. list_for_each_entry_safe(app, tmp, &dcb_app_list, list) {
  1506. list_del(&app->list);
  1507. kfree(app);
  1508. }
  1509. spin_unlock(&dcb_lock);
  1510. }
  1511. static int __init dcbnl_init(void)
  1512. {
  1513. INIT_LIST_HEAD(&dcb_app_list);
  1514. rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL);
  1515. rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL);
  1516. return 0;
  1517. }
  1518. module_init(dcbnl_init);
  1519. static void __exit dcbnl_exit(void)
  1520. {
  1521. rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
  1522. rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
  1523. dcb_flushapp();
  1524. }
  1525. module_exit(dcbnl_exit);