dcbnl.c 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259
  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 <linux/module.h>
  28. #include <net/sock.h>
  29. /**
  30. * Data Center Bridging (DCB) is a collection of Ethernet enhancements
  31. * intended to allow network traffic with differing requirements
  32. * (highly reliable, no drops vs. best effort vs. low latency) to operate
  33. * and co-exist on Ethernet. Current DCB features are:
  34. *
  35. * Enhanced Transmission Selection (aka Priority Grouping [PG]) - provides a
  36. * framework for assigning bandwidth guarantees to traffic classes.
  37. *
  38. * Priority-based Flow Control (PFC) - provides a flow control mechanism which
  39. * can work independently for each 802.1p priority.
  40. *
  41. * Congestion Notification - provides a mechanism for end-to-end congestion
  42. * control for protocols which do not have built-in congestion management.
  43. *
  44. * More information about the emerging standards for these Ethernet features
  45. * can be found at: http://www.ieee802.org/1/pages/dcbridges.html
  46. *
  47. * This file implements an rtnetlink interface to allow configuration of DCB
  48. * features for capable devices.
  49. */
  50. MODULE_AUTHOR("Lucy Liu, <lucy.liu@intel.com>");
  51. MODULE_DESCRIPTION("Data Center Bridging netlink interface");
  52. MODULE_LICENSE("GPL");
  53. /**************** DCB attribute policies *************************************/
  54. /* DCB netlink attributes policy */
  55. static const struct nla_policy dcbnl_rtnl_policy[DCB_ATTR_MAX + 1] = {
  56. [DCB_ATTR_IFNAME] = {.type = NLA_NUL_STRING, .len = IFNAMSIZ - 1},
  57. [DCB_ATTR_STATE] = {.type = NLA_U8},
  58. [DCB_ATTR_PFC_CFG] = {.type = NLA_NESTED},
  59. [DCB_ATTR_PG_CFG] = {.type = NLA_NESTED},
  60. [DCB_ATTR_SET_ALL] = {.type = NLA_U8},
  61. [DCB_ATTR_PERM_HWADDR] = {.type = NLA_FLAG},
  62. [DCB_ATTR_CAP] = {.type = NLA_NESTED},
  63. [DCB_ATTR_PFC_STATE] = {.type = NLA_U8},
  64. [DCB_ATTR_BCN] = {.type = NLA_NESTED},
  65. [DCB_ATTR_APP] = {.type = NLA_NESTED},
  66. [DCB_ATTR_IEEE] = {.type = NLA_NESTED},
  67. [DCB_ATTR_DCBX] = {.type = NLA_U8},
  68. [DCB_ATTR_FEATCFG] = {.type = NLA_NESTED},
  69. };
  70. /* DCB priority flow control to User Priority nested attributes */
  71. static const struct nla_policy dcbnl_pfc_up_nest[DCB_PFC_UP_ATTR_MAX + 1] = {
  72. [DCB_PFC_UP_ATTR_0] = {.type = NLA_U8},
  73. [DCB_PFC_UP_ATTR_1] = {.type = NLA_U8},
  74. [DCB_PFC_UP_ATTR_2] = {.type = NLA_U8},
  75. [DCB_PFC_UP_ATTR_3] = {.type = NLA_U8},
  76. [DCB_PFC_UP_ATTR_4] = {.type = NLA_U8},
  77. [DCB_PFC_UP_ATTR_5] = {.type = NLA_U8},
  78. [DCB_PFC_UP_ATTR_6] = {.type = NLA_U8},
  79. [DCB_PFC_UP_ATTR_7] = {.type = NLA_U8},
  80. [DCB_PFC_UP_ATTR_ALL] = {.type = NLA_FLAG},
  81. };
  82. /* DCB priority grouping nested attributes */
  83. static const struct nla_policy dcbnl_pg_nest[DCB_PG_ATTR_MAX + 1] = {
  84. [DCB_PG_ATTR_TC_0] = {.type = NLA_NESTED},
  85. [DCB_PG_ATTR_TC_1] = {.type = NLA_NESTED},
  86. [DCB_PG_ATTR_TC_2] = {.type = NLA_NESTED},
  87. [DCB_PG_ATTR_TC_3] = {.type = NLA_NESTED},
  88. [DCB_PG_ATTR_TC_4] = {.type = NLA_NESTED},
  89. [DCB_PG_ATTR_TC_5] = {.type = NLA_NESTED},
  90. [DCB_PG_ATTR_TC_6] = {.type = NLA_NESTED},
  91. [DCB_PG_ATTR_TC_7] = {.type = NLA_NESTED},
  92. [DCB_PG_ATTR_TC_ALL] = {.type = NLA_NESTED},
  93. [DCB_PG_ATTR_BW_ID_0] = {.type = NLA_U8},
  94. [DCB_PG_ATTR_BW_ID_1] = {.type = NLA_U8},
  95. [DCB_PG_ATTR_BW_ID_2] = {.type = NLA_U8},
  96. [DCB_PG_ATTR_BW_ID_3] = {.type = NLA_U8},
  97. [DCB_PG_ATTR_BW_ID_4] = {.type = NLA_U8},
  98. [DCB_PG_ATTR_BW_ID_5] = {.type = NLA_U8},
  99. [DCB_PG_ATTR_BW_ID_6] = {.type = NLA_U8},
  100. [DCB_PG_ATTR_BW_ID_7] = {.type = NLA_U8},
  101. [DCB_PG_ATTR_BW_ID_ALL] = {.type = NLA_FLAG},
  102. };
  103. /* DCB traffic class nested attributes. */
  104. static const struct nla_policy dcbnl_tc_param_nest[DCB_TC_ATTR_PARAM_MAX + 1] = {
  105. [DCB_TC_ATTR_PARAM_PGID] = {.type = NLA_U8},
  106. [DCB_TC_ATTR_PARAM_UP_MAPPING] = {.type = NLA_U8},
  107. [DCB_TC_ATTR_PARAM_STRICT_PRIO] = {.type = NLA_U8},
  108. [DCB_TC_ATTR_PARAM_BW_PCT] = {.type = NLA_U8},
  109. [DCB_TC_ATTR_PARAM_ALL] = {.type = NLA_FLAG},
  110. };
  111. /* DCB capabilities nested attributes. */
  112. static const struct nla_policy dcbnl_cap_nest[DCB_CAP_ATTR_MAX + 1] = {
  113. [DCB_CAP_ATTR_ALL] = {.type = NLA_FLAG},
  114. [DCB_CAP_ATTR_PG] = {.type = NLA_U8},
  115. [DCB_CAP_ATTR_PFC] = {.type = NLA_U8},
  116. [DCB_CAP_ATTR_UP2TC] = {.type = NLA_U8},
  117. [DCB_CAP_ATTR_PG_TCS] = {.type = NLA_U8},
  118. [DCB_CAP_ATTR_PFC_TCS] = {.type = NLA_U8},
  119. [DCB_CAP_ATTR_GSP] = {.type = NLA_U8},
  120. [DCB_CAP_ATTR_BCN] = {.type = NLA_U8},
  121. [DCB_CAP_ATTR_DCBX] = {.type = NLA_U8},
  122. };
  123. /* DCB capabilities nested attributes. */
  124. static const struct nla_policy dcbnl_numtcs_nest[DCB_NUMTCS_ATTR_MAX + 1] = {
  125. [DCB_NUMTCS_ATTR_ALL] = {.type = NLA_FLAG},
  126. [DCB_NUMTCS_ATTR_PG] = {.type = NLA_U8},
  127. [DCB_NUMTCS_ATTR_PFC] = {.type = NLA_U8},
  128. };
  129. /* DCB BCN nested attributes. */
  130. static const struct nla_policy dcbnl_bcn_nest[DCB_BCN_ATTR_MAX + 1] = {
  131. [DCB_BCN_ATTR_RP_0] = {.type = NLA_U8},
  132. [DCB_BCN_ATTR_RP_1] = {.type = NLA_U8},
  133. [DCB_BCN_ATTR_RP_2] = {.type = NLA_U8},
  134. [DCB_BCN_ATTR_RP_3] = {.type = NLA_U8},
  135. [DCB_BCN_ATTR_RP_4] = {.type = NLA_U8},
  136. [DCB_BCN_ATTR_RP_5] = {.type = NLA_U8},
  137. [DCB_BCN_ATTR_RP_6] = {.type = NLA_U8},
  138. [DCB_BCN_ATTR_RP_7] = {.type = NLA_U8},
  139. [DCB_BCN_ATTR_RP_ALL] = {.type = NLA_FLAG},
  140. [DCB_BCN_ATTR_BCNA_0] = {.type = NLA_U32},
  141. [DCB_BCN_ATTR_BCNA_1] = {.type = NLA_U32},
  142. [DCB_BCN_ATTR_ALPHA] = {.type = NLA_U32},
  143. [DCB_BCN_ATTR_BETA] = {.type = NLA_U32},
  144. [DCB_BCN_ATTR_GD] = {.type = NLA_U32},
  145. [DCB_BCN_ATTR_GI] = {.type = NLA_U32},
  146. [DCB_BCN_ATTR_TMAX] = {.type = NLA_U32},
  147. [DCB_BCN_ATTR_TD] = {.type = NLA_U32},
  148. [DCB_BCN_ATTR_RMIN] = {.type = NLA_U32},
  149. [DCB_BCN_ATTR_W] = {.type = NLA_U32},
  150. [DCB_BCN_ATTR_RD] = {.type = NLA_U32},
  151. [DCB_BCN_ATTR_RU] = {.type = NLA_U32},
  152. [DCB_BCN_ATTR_WRTT] = {.type = NLA_U32},
  153. [DCB_BCN_ATTR_RI] = {.type = NLA_U32},
  154. [DCB_BCN_ATTR_C] = {.type = NLA_U32},
  155. [DCB_BCN_ATTR_ALL] = {.type = NLA_FLAG},
  156. };
  157. /* DCB APP nested attributes. */
  158. static const struct nla_policy dcbnl_app_nest[DCB_APP_ATTR_MAX + 1] = {
  159. [DCB_APP_ATTR_IDTYPE] = {.type = NLA_U8},
  160. [DCB_APP_ATTR_ID] = {.type = NLA_U16},
  161. [DCB_APP_ATTR_PRIORITY] = {.type = NLA_U8},
  162. };
  163. /* IEEE 802.1Qaz nested attributes. */
  164. static const struct nla_policy dcbnl_ieee_policy[DCB_ATTR_IEEE_MAX + 1] = {
  165. [DCB_ATTR_IEEE_ETS] = {.len = sizeof(struct ieee_ets)},
  166. [DCB_ATTR_IEEE_PFC] = {.len = sizeof(struct ieee_pfc)},
  167. [DCB_ATTR_IEEE_APP_TABLE] = {.type = NLA_NESTED},
  168. };
  169. static const struct nla_policy dcbnl_ieee_app[DCB_ATTR_IEEE_APP_MAX + 1] = {
  170. [DCB_ATTR_IEEE_APP] = {.len = sizeof(struct dcb_app)},
  171. };
  172. /* DCB number of traffic classes nested attributes. */
  173. static const struct nla_policy dcbnl_featcfg_nest[DCB_FEATCFG_ATTR_MAX + 1] = {
  174. [DCB_FEATCFG_ATTR_ALL] = {.type = NLA_FLAG},
  175. [DCB_FEATCFG_ATTR_PG] = {.type = NLA_U8},
  176. [DCB_FEATCFG_ATTR_PFC] = {.type = NLA_U8},
  177. [DCB_FEATCFG_ATTR_APP] = {.type = NLA_U8},
  178. };
  179. static LIST_HEAD(dcb_app_list);
  180. static DEFINE_SPINLOCK(dcb_lock);
  181. /* standard netlink reply call */
  182. static int dcbnl_reply(u8 value, u8 event, u8 cmd, u8 attr, u32 pid,
  183. u32 seq, u16 flags)
  184. {
  185. struct sk_buff *dcbnl_skb;
  186. struct dcbmsg *dcb;
  187. struct nlmsghdr *nlh;
  188. int ret = -EINVAL;
  189. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  190. if (!dcbnl_skb)
  191. return ret;
  192. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, event, sizeof(*dcb), flags);
  193. dcb = NLMSG_DATA(nlh);
  194. dcb->dcb_family = AF_UNSPEC;
  195. dcb->cmd = cmd;
  196. dcb->dcb_pad = 0;
  197. ret = nla_put_u8(dcbnl_skb, attr, value);
  198. if (ret)
  199. goto err;
  200. /* end the message, assign the nlmsg_len. */
  201. nlmsg_end(dcbnl_skb, nlh);
  202. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  203. if (ret)
  204. return -EINVAL;
  205. return 0;
  206. nlmsg_failure:
  207. err:
  208. kfree_skb(dcbnl_skb);
  209. return ret;
  210. }
  211. static int dcbnl_getstate(struct net_device *netdev, struct nlattr **tb,
  212. u32 pid, u32 seq, u16 flags)
  213. {
  214. int ret = -EINVAL;
  215. /* if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->getstate) */
  216. if (!netdev->dcbnl_ops->getstate)
  217. return ret;
  218. ret = dcbnl_reply(netdev->dcbnl_ops->getstate(netdev), RTM_GETDCB,
  219. DCB_CMD_GSTATE, DCB_ATTR_STATE, pid, seq, flags);
  220. return ret;
  221. }
  222. static int dcbnl_getpfccfg(struct net_device *netdev, struct nlattr **tb,
  223. u32 pid, u32 seq, u16 flags)
  224. {
  225. struct sk_buff *dcbnl_skb;
  226. struct nlmsghdr *nlh;
  227. struct dcbmsg *dcb;
  228. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1], *nest;
  229. u8 value;
  230. int ret = -EINVAL;
  231. int i;
  232. int getall = 0;
  233. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->getpfccfg)
  234. return ret;
  235. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  236. tb[DCB_ATTR_PFC_CFG],
  237. dcbnl_pfc_up_nest);
  238. if (ret)
  239. goto err_out;
  240. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  241. if (!dcbnl_skb)
  242. goto err_out;
  243. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  244. dcb = NLMSG_DATA(nlh);
  245. dcb->dcb_family = AF_UNSPEC;
  246. dcb->cmd = DCB_CMD_PFC_GCFG;
  247. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PFC_CFG);
  248. if (!nest)
  249. goto err;
  250. if (data[DCB_PFC_UP_ATTR_ALL])
  251. getall = 1;
  252. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  253. if (!getall && !data[i])
  254. continue;
  255. netdev->dcbnl_ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0,
  256. &value);
  257. ret = nla_put_u8(dcbnl_skb, i, value);
  258. if (ret) {
  259. nla_nest_cancel(dcbnl_skb, nest);
  260. goto err;
  261. }
  262. }
  263. nla_nest_end(dcbnl_skb, nest);
  264. nlmsg_end(dcbnl_skb, nlh);
  265. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  266. if (ret)
  267. goto err_out;
  268. return 0;
  269. nlmsg_failure:
  270. err:
  271. kfree_skb(dcbnl_skb);
  272. err_out:
  273. return -EINVAL;
  274. }
  275. static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlattr **tb,
  276. u32 pid, u32 seq, u16 flags)
  277. {
  278. struct sk_buff *dcbnl_skb;
  279. struct nlmsghdr *nlh;
  280. struct dcbmsg *dcb;
  281. u8 perm_addr[MAX_ADDR_LEN];
  282. int ret = -EINVAL;
  283. if (!netdev->dcbnl_ops->getpermhwaddr)
  284. return ret;
  285. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  286. if (!dcbnl_skb)
  287. goto err_out;
  288. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  289. dcb = NLMSG_DATA(nlh);
  290. dcb->dcb_family = AF_UNSPEC;
  291. dcb->cmd = DCB_CMD_GPERM_HWADDR;
  292. netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
  293. ret = nla_put(dcbnl_skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr),
  294. perm_addr);
  295. nlmsg_end(dcbnl_skb, nlh);
  296. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  297. if (ret)
  298. goto err_out;
  299. return 0;
  300. nlmsg_failure:
  301. kfree_skb(dcbnl_skb);
  302. err_out:
  303. return -EINVAL;
  304. }
  305. static int dcbnl_getcap(struct net_device *netdev, struct nlattr **tb,
  306. u32 pid, u32 seq, u16 flags)
  307. {
  308. struct sk_buff *dcbnl_skb;
  309. struct nlmsghdr *nlh;
  310. struct dcbmsg *dcb;
  311. struct nlattr *data[DCB_CAP_ATTR_MAX + 1], *nest;
  312. u8 value;
  313. int ret = -EINVAL;
  314. int i;
  315. int getall = 0;
  316. if (!tb[DCB_ATTR_CAP] || !netdev->dcbnl_ops->getcap)
  317. return ret;
  318. ret = nla_parse_nested(data, DCB_CAP_ATTR_MAX, tb[DCB_ATTR_CAP],
  319. dcbnl_cap_nest);
  320. if (ret)
  321. goto err_out;
  322. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  323. if (!dcbnl_skb)
  324. goto err_out;
  325. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  326. dcb = NLMSG_DATA(nlh);
  327. dcb->dcb_family = AF_UNSPEC;
  328. dcb->cmd = DCB_CMD_GCAP;
  329. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_CAP);
  330. if (!nest)
  331. goto err;
  332. if (data[DCB_CAP_ATTR_ALL])
  333. getall = 1;
  334. for (i = DCB_CAP_ATTR_ALL+1; i <= DCB_CAP_ATTR_MAX; i++) {
  335. if (!getall && !data[i])
  336. continue;
  337. if (!netdev->dcbnl_ops->getcap(netdev, i, &value)) {
  338. ret = nla_put_u8(dcbnl_skb, i, value);
  339. if (ret) {
  340. nla_nest_cancel(dcbnl_skb, nest);
  341. goto err;
  342. }
  343. }
  344. }
  345. nla_nest_end(dcbnl_skb, nest);
  346. nlmsg_end(dcbnl_skb, nlh);
  347. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  348. if (ret)
  349. goto err_out;
  350. return 0;
  351. nlmsg_failure:
  352. err:
  353. kfree_skb(dcbnl_skb);
  354. err_out:
  355. return -EINVAL;
  356. }
  357. static int dcbnl_getnumtcs(struct net_device *netdev, struct nlattr **tb,
  358. u32 pid, u32 seq, u16 flags)
  359. {
  360. struct sk_buff *dcbnl_skb;
  361. struct nlmsghdr *nlh;
  362. struct dcbmsg *dcb;
  363. struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1], *nest;
  364. u8 value;
  365. int ret = -EINVAL;
  366. int i;
  367. int getall = 0;
  368. if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->getnumtcs)
  369. return ret;
  370. ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
  371. dcbnl_numtcs_nest);
  372. if (ret) {
  373. ret = -EINVAL;
  374. goto err_out;
  375. }
  376. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  377. if (!dcbnl_skb) {
  378. ret = -EINVAL;
  379. goto err_out;
  380. }
  381. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  382. dcb = NLMSG_DATA(nlh);
  383. dcb->dcb_family = AF_UNSPEC;
  384. dcb->cmd = DCB_CMD_GNUMTCS;
  385. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_NUMTCS);
  386. if (!nest) {
  387. ret = -EINVAL;
  388. goto err;
  389. }
  390. if (data[DCB_NUMTCS_ATTR_ALL])
  391. getall = 1;
  392. for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
  393. if (!getall && !data[i])
  394. continue;
  395. ret = netdev->dcbnl_ops->getnumtcs(netdev, i, &value);
  396. if (!ret) {
  397. ret = nla_put_u8(dcbnl_skb, i, value);
  398. if (ret) {
  399. nla_nest_cancel(dcbnl_skb, nest);
  400. ret = -EINVAL;
  401. goto err;
  402. }
  403. } else {
  404. goto err;
  405. }
  406. }
  407. nla_nest_end(dcbnl_skb, nest);
  408. nlmsg_end(dcbnl_skb, nlh);
  409. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  410. if (ret) {
  411. ret = -EINVAL;
  412. goto err_out;
  413. }
  414. return 0;
  415. nlmsg_failure:
  416. err:
  417. kfree_skb(dcbnl_skb);
  418. err_out:
  419. return ret;
  420. }
  421. static int dcbnl_setnumtcs(struct net_device *netdev, struct nlattr **tb,
  422. u32 pid, u32 seq, u16 flags)
  423. {
  424. struct nlattr *data[DCB_NUMTCS_ATTR_MAX + 1];
  425. int ret = -EINVAL;
  426. u8 value;
  427. int i;
  428. if (!tb[DCB_ATTR_NUMTCS] || !netdev->dcbnl_ops->setnumtcs)
  429. return ret;
  430. ret = nla_parse_nested(data, DCB_NUMTCS_ATTR_MAX, tb[DCB_ATTR_NUMTCS],
  431. dcbnl_numtcs_nest);
  432. if (ret) {
  433. ret = -EINVAL;
  434. goto err;
  435. }
  436. for (i = DCB_NUMTCS_ATTR_ALL+1; i <= DCB_NUMTCS_ATTR_MAX; i++) {
  437. if (data[i] == NULL)
  438. continue;
  439. value = nla_get_u8(data[i]);
  440. ret = netdev->dcbnl_ops->setnumtcs(netdev, i, value);
  441. if (ret)
  442. goto operr;
  443. }
  444. operr:
  445. ret = dcbnl_reply(!!ret, RTM_SETDCB, DCB_CMD_SNUMTCS,
  446. DCB_ATTR_NUMTCS, pid, seq, flags);
  447. err:
  448. return ret;
  449. }
  450. static int dcbnl_getpfcstate(struct net_device *netdev, struct nlattr **tb,
  451. u32 pid, u32 seq, u16 flags)
  452. {
  453. int ret = -EINVAL;
  454. if (!netdev->dcbnl_ops->getpfcstate)
  455. return ret;
  456. ret = dcbnl_reply(netdev->dcbnl_ops->getpfcstate(netdev), RTM_GETDCB,
  457. DCB_CMD_PFC_GSTATE, DCB_ATTR_PFC_STATE,
  458. pid, seq, flags);
  459. return ret;
  460. }
  461. static int dcbnl_setpfcstate(struct net_device *netdev, struct nlattr **tb,
  462. u32 pid, u32 seq, u16 flags)
  463. {
  464. int ret = -EINVAL;
  465. u8 value;
  466. if (!tb[DCB_ATTR_PFC_STATE] || !netdev->dcbnl_ops->setpfcstate)
  467. return ret;
  468. value = nla_get_u8(tb[DCB_ATTR_PFC_STATE]);
  469. netdev->dcbnl_ops->setpfcstate(netdev, value);
  470. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SSTATE, DCB_ATTR_PFC_STATE,
  471. pid, seq, flags);
  472. return ret;
  473. }
  474. static int dcbnl_getapp(struct net_device *netdev, struct nlattr **tb,
  475. u32 pid, u32 seq, u16 flags)
  476. {
  477. struct sk_buff *dcbnl_skb;
  478. struct nlmsghdr *nlh;
  479. struct dcbmsg *dcb;
  480. struct nlattr *app_nest;
  481. struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
  482. u16 id;
  483. u8 up, idtype;
  484. int ret = -EINVAL;
  485. if (!tb[DCB_ATTR_APP])
  486. goto out;
  487. ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
  488. dcbnl_app_nest);
  489. if (ret)
  490. goto out;
  491. ret = -EINVAL;
  492. /* all must be non-null */
  493. if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
  494. (!app_tb[DCB_APP_ATTR_ID]))
  495. goto out;
  496. /* either by eth type or by socket number */
  497. idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
  498. if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
  499. (idtype != DCB_APP_IDTYPE_PORTNUM))
  500. goto out;
  501. id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
  502. if (netdev->dcbnl_ops->getapp) {
  503. up = netdev->dcbnl_ops->getapp(netdev, idtype, id);
  504. } else {
  505. struct dcb_app app = {
  506. .selector = idtype,
  507. .protocol = id,
  508. };
  509. up = dcb_getapp(netdev, &app);
  510. }
  511. /* send this back */
  512. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  513. if (!dcbnl_skb)
  514. goto out;
  515. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  516. dcb = NLMSG_DATA(nlh);
  517. dcb->dcb_family = AF_UNSPEC;
  518. dcb->cmd = DCB_CMD_GAPP;
  519. app_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_APP);
  520. if (!app_nest)
  521. goto out_cancel;
  522. ret = nla_put_u8(dcbnl_skb, DCB_APP_ATTR_IDTYPE, idtype);
  523. if (ret)
  524. goto out_cancel;
  525. ret = nla_put_u16(dcbnl_skb, DCB_APP_ATTR_ID, id);
  526. if (ret)
  527. goto out_cancel;
  528. ret = nla_put_u8(dcbnl_skb, DCB_APP_ATTR_PRIORITY, up);
  529. if (ret)
  530. goto out_cancel;
  531. nla_nest_end(dcbnl_skb, app_nest);
  532. nlmsg_end(dcbnl_skb, nlh);
  533. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  534. if (ret)
  535. goto nlmsg_failure;
  536. goto out;
  537. out_cancel:
  538. nla_nest_cancel(dcbnl_skb, app_nest);
  539. nlmsg_failure:
  540. kfree_skb(dcbnl_skb);
  541. out:
  542. return ret;
  543. }
  544. static int dcbnl_setapp(struct net_device *netdev, struct nlattr **tb,
  545. u32 pid, u32 seq, u16 flags)
  546. {
  547. int err, ret = -EINVAL;
  548. u16 id;
  549. u8 up, idtype;
  550. struct nlattr *app_tb[DCB_APP_ATTR_MAX + 1];
  551. if (!tb[DCB_ATTR_APP])
  552. goto out;
  553. ret = nla_parse_nested(app_tb, DCB_APP_ATTR_MAX, tb[DCB_ATTR_APP],
  554. dcbnl_app_nest);
  555. if (ret)
  556. goto out;
  557. ret = -EINVAL;
  558. /* all must be non-null */
  559. if ((!app_tb[DCB_APP_ATTR_IDTYPE]) ||
  560. (!app_tb[DCB_APP_ATTR_ID]) ||
  561. (!app_tb[DCB_APP_ATTR_PRIORITY]))
  562. goto out;
  563. /* either by eth type or by socket number */
  564. idtype = nla_get_u8(app_tb[DCB_APP_ATTR_IDTYPE]);
  565. if ((idtype != DCB_APP_IDTYPE_ETHTYPE) &&
  566. (idtype != DCB_APP_IDTYPE_PORTNUM))
  567. goto out;
  568. id = nla_get_u16(app_tb[DCB_APP_ATTR_ID]);
  569. up = nla_get_u8(app_tb[DCB_APP_ATTR_PRIORITY]);
  570. if (netdev->dcbnl_ops->setapp) {
  571. err = netdev->dcbnl_ops->setapp(netdev, idtype, id, up);
  572. } else {
  573. struct dcb_app app;
  574. app.selector = idtype;
  575. app.protocol = id;
  576. app.priority = up;
  577. err = dcb_setapp(netdev, &app);
  578. }
  579. ret = dcbnl_reply(err, RTM_SETDCB, DCB_CMD_SAPP, DCB_ATTR_APP,
  580. pid, seq, flags);
  581. out:
  582. return ret;
  583. }
  584. static int __dcbnl_pg_getcfg(struct net_device *netdev, struct nlattr **tb,
  585. u32 pid, u32 seq, u16 flags, int dir)
  586. {
  587. struct sk_buff *dcbnl_skb;
  588. struct nlmsghdr *nlh;
  589. struct dcbmsg *dcb;
  590. struct nlattr *pg_nest, *param_nest, *data;
  591. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  592. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  593. u8 prio, pgid, tc_pct, up_map;
  594. int ret = -EINVAL;
  595. int getall = 0;
  596. int i;
  597. if (!tb[DCB_ATTR_PG_CFG] ||
  598. !netdev->dcbnl_ops->getpgtccfgtx ||
  599. !netdev->dcbnl_ops->getpgtccfgrx ||
  600. !netdev->dcbnl_ops->getpgbwgcfgtx ||
  601. !netdev->dcbnl_ops->getpgbwgcfgrx)
  602. return ret;
  603. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  604. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  605. if (ret)
  606. goto err_out;
  607. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  608. if (!dcbnl_skb)
  609. goto err_out;
  610. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  611. dcb = NLMSG_DATA(nlh);
  612. dcb->dcb_family = AF_UNSPEC;
  613. dcb->cmd = (dir) ? DCB_CMD_PGRX_GCFG : DCB_CMD_PGTX_GCFG;
  614. pg_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_PG_CFG);
  615. if (!pg_nest)
  616. goto err;
  617. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  618. getall = 1;
  619. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  620. if (!getall && !pg_tb[i])
  621. continue;
  622. if (pg_tb[DCB_PG_ATTR_TC_ALL])
  623. data = pg_tb[DCB_PG_ATTR_TC_ALL];
  624. else
  625. data = pg_tb[i];
  626. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  627. data, dcbnl_tc_param_nest);
  628. if (ret)
  629. goto err_pg;
  630. param_nest = nla_nest_start(dcbnl_skb, i);
  631. if (!param_nest)
  632. goto err_pg;
  633. pgid = DCB_ATTR_VALUE_UNDEFINED;
  634. prio = DCB_ATTR_VALUE_UNDEFINED;
  635. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  636. up_map = DCB_ATTR_VALUE_UNDEFINED;
  637. if (dir) {
  638. /* Rx */
  639. netdev->dcbnl_ops->getpgtccfgrx(netdev,
  640. i - DCB_PG_ATTR_TC_0, &prio,
  641. &pgid, &tc_pct, &up_map);
  642. } else {
  643. /* Tx */
  644. netdev->dcbnl_ops->getpgtccfgtx(netdev,
  645. i - DCB_PG_ATTR_TC_0, &prio,
  646. &pgid, &tc_pct, &up_map);
  647. }
  648. if (param_tb[DCB_TC_ATTR_PARAM_PGID] ||
  649. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  650. ret = nla_put_u8(dcbnl_skb,
  651. DCB_TC_ATTR_PARAM_PGID, pgid);
  652. if (ret)
  653. goto err_param;
  654. }
  655. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING] ||
  656. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  657. ret = nla_put_u8(dcbnl_skb,
  658. DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
  659. if (ret)
  660. goto err_param;
  661. }
  662. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO] ||
  663. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  664. ret = nla_put_u8(dcbnl_skb,
  665. DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
  666. if (ret)
  667. goto err_param;
  668. }
  669. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT] ||
  670. param_tb[DCB_TC_ATTR_PARAM_ALL]) {
  671. ret = nla_put_u8(dcbnl_skb, DCB_TC_ATTR_PARAM_BW_PCT,
  672. tc_pct);
  673. if (ret)
  674. goto err_param;
  675. }
  676. nla_nest_end(dcbnl_skb, param_nest);
  677. }
  678. if (pg_tb[DCB_PG_ATTR_BW_ID_ALL])
  679. getall = 1;
  680. else
  681. getall = 0;
  682. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  683. if (!getall && !pg_tb[i])
  684. continue;
  685. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  686. if (dir) {
  687. /* Rx */
  688. netdev->dcbnl_ops->getpgbwgcfgrx(netdev,
  689. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  690. } else {
  691. /* Tx */
  692. netdev->dcbnl_ops->getpgbwgcfgtx(netdev,
  693. i - DCB_PG_ATTR_BW_ID_0, &tc_pct);
  694. }
  695. ret = nla_put_u8(dcbnl_skb, i, tc_pct);
  696. if (ret)
  697. goto err_pg;
  698. }
  699. nla_nest_end(dcbnl_skb, pg_nest);
  700. nlmsg_end(dcbnl_skb, nlh);
  701. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  702. if (ret)
  703. goto err_out;
  704. return 0;
  705. err_param:
  706. nla_nest_cancel(dcbnl_skb, param_nest);
  707. err_pg:
  708. nla_nest_cancel(dcbnl_skb, pg_nest);
  709. nlmsg_failure:
  710. err:
  711. kfree_skb(dcbnl_skb);
  712. err_out:
  713. ret = -EINVAL;
  714. return ret;
  715. }
  716. static int dcbnl_pgtx_getcfg(struct net_device *netdev, struct nlattr **tb,
  717. u32 pid, u32 seq, u16 flags)
  718. {
  719. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 0);
  720. }
  721. static int dcbnl_pgrx_getcfg(struct net_device *netdev, struct nlattr **tb,
  722. u32 pid, u32 seq, u16 flags)
  723. {
  724. return __dcbnl_pg_getcfg(netdev, tb, pid, seq, flags, 1);
  725. }
  726. static int dcbnl_setstate(struct net_device *netdev, struct nlattr **tb,
  727. u32 pid, u32 seq, u16 flags)
  728. {
  729. int ret = -EINVAL;
  730. u8 value;
  731. if (!tb[DCB_ATTR_STATE] || !netdev->dcbnl_ops->setstate)
  732. return ret;
  733. value = nla_get_u8(tb[DCB_ATTR_STATE]);
  734. ret = dcbnl_reply(netdev->dcbnl_ops->setstate(netdev, value),
  735. RTM_SETDCB, DCB_CMD_SSTATE, DCB_ATTR_STATE,
  736. pid, seq, flags);
  737. return ret;
  738. }
  739. static int dcbnl_setpfccfg(struct net_device *netdev, struct nlattr **tb,
  740. u32 pid, u32 seq, u16 flags)
  741. {
  742. struct nlattr *data[DCB_PFC_UP_ATTR_MAX + 1];
  743. int i;
  744. int ret = -EINVAL;
  745. u8 value;
  746. if (!tb[DCB_ATTR_PFC_CFG] || !netdev->dcbnl_ops->setpfccfg)
  747. return ret;
  748. ret = nla_parse_nested(data, DCB_PFC_UP_ATTR_MAX,
  749. tb[DCB_ATTR_PFC_CFG],
  750. dcbnl_pfc_up_nest);
  751. if (ret)
  752. goto err;
  753. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  754. if (data[i] == NULL)
  755. continue;
  756. value = nla_get_u8(data[i]);
  757. netdev->dcbnl_ops->setpfccfg(netdev,
  758. data[i]->nla_type - DCB_PFC_UP_ATTR_0, value);
  759. }
  760. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_PFC_SCFG, DCB_ATTR_PFC_CFG,
  761. pid, seq, flags);
  762. err:
  763. return ret;
  764. }
  765. static int dcbnl_setall(struct net_device *netdev, struct nlattr **tb,
  766. u32 pid, u32 seq, u16 flags)
  767. {
  768. int ret = -EINVAL;
  769. if (!tb[DCB_ATTR_SET_ALL] || !netdev->dcbnl_ops->setall)
  770. return ret;
  771. ret = dcbnl_reply(netdev->dcbnl_ops->setall(netdev), RTM_SETDCB,
  772. DCB_CMD_SET_ALL, DCB_ATTR_SET_ALL, pid, seq, flags);
  773. return ret;
  774. }
  775. static int __dcbnl_pg_setcfg(struct net_device *netdev, struct nlattr **tb,
  776. u32 pid, u32 seq, u16 flags, int dir)
  777. {
  778. struct nlattr *pg_tb[DCB_PG_ATTR_MAX + 1];
  779. struct nlattr *param_tb[DCB_TC_ATTR_PARAM_MAX + 1];
  780. int ret = -EINVAL;
  781. int i;
  782. u8 pgid;
  783. u8 up_map;
  784. u8 prio;
  785. u8 tc_pct;
  786. if (!tb[DCB_ATTR_PG_CFG] ||
  787. !netdev->dcbnl_ops->setpgtccfgtx ||
  788. !netdev->dcbnl_ops->setpgtccfgrx ||
  789. !netdev->dcbnl_ops->setpgbwgcfgtx ||
  790. !netdev->dcbnl_ops->setpgbwgcfgrx)
  791. return ret;
  792. ret = nla_parse_nested(pg_tb, DCB_PG_ATTR_MAX,
  793. tb[DCB_ATTR_PG_CFG], dcbnl_pg_nest);
  794. if (ret)
  795. goto err;
  796. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  797. if (!pg_tb[i])
  798. continue;
  799. ret = nla_parse_nested(param_tb, DCB_TC_ATTR_PARAM_MAX,
  800. pg_tb[i], dcbnl_tc_param_nest);
  801. if (ret)
  802. goto err;
  803. pgid = DCB_ATTR_VALUE_UNDEFINED;
  804. prio = DCB_ATTR_VALUE_UNDEFINED;
  805. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  806. up_map = DCB_ATTR_VALUE_UNDEFINED;
  807. if (param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO])
  808. prio =
  809. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_STRICT_PRIO]);
  810. if (param_tb[DCB_TC_ATTR_PARAM_PGID])
  811. pgid = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_PGID]);
  812. if (param_tb[DCB_TC_ATTR_PARAM_BW_PCT])
  813. tc_pct = nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_BW_PCT]);
  814. if (param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING])
  815. up_map =
  816. nla_get_u8(param_tb[DCB_TC_ATTR_PARAM_UP_MAPPING]);
  817. /* dir: Tx = 0, Rx = 1 */
  818. if (dir) {
  819. /* Rx */
  820. netdev->dcbnl_ops->setpgtccfgrx(netdev,
  821. i - DCB_PG_ATTR_TC_0,
  822. prio, pgid, tc_pct, up_map);
  823. } else {
  824. /* Tx */
  825. netdev->dcbnl_ops->setpgtccfgtx(netdev,
  826. i - DCB_PG_ATTR_TC_0,
  827. prio, pgid, tc_pct, up_map);
  828. }
  829. }
  830. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  831. if (!pg_tb[i])
  832. continue;
  833. tc_pct = nla_get_u8(pg_tb[i]);
  834. /* dir: Tx = 0, Rx = 1 */
  835. if (dir) {
  836. /* Rx */
  837. netdev->dcbnl_ops->setpgbwgcfgrx(netdev,
  838. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  839. } else {
  840. /* Tx */
  841. netdev->dcbnl_ops->setpgbwgcfgtx(netdev,
  842. i - DCB_PG_ATTR_BW_ID_0, tc_pct);
  843. }
  844. }
  845. ret = dcbnl_reply(0, RTM_SETDCB,
  846. (dir ? DCB_CMD_PGRX_SCFG : DCB_CMD_PGTX_SCFG),
  847. DCB_ATTR_PG_CFG, pid, seq, flags);
  848. err:
  849. return ret;
  850. }
  851. static int dcbnl_pgtx_setcfg(struct net_device *netdev, struct nlattr **tb,
  852. u32 pid, u32 seq, u16 flags)
  853. {
  854. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 0);
  855. }
  856. static int dcbnl_pgrx_setcfg(struct net_device *netdev, struct nlattr **tb,
  857. u32 pid, u32 seq, u16 flags)
  858. {
  859. return __dcbnl_pg_setcfg(netdev, tb, pid, seq, flags, 1);
  860. }
  861. static int dcbnl_bcn_getcfg(struct net_device *netdev, struct nlattr **tb,
  862. u32 pid, u32 seq, u16 flags)
  863. {
  864. struct sk_buff *dcbnl_skb;
  865. struct nlmsghdr *nlh;
  866. struct dcbmsg *dcb;
  867. struct nlattr *bcn_nest;
  868. struct nlattr *bcn_tb[DCB_BCN_ATTR_MAX + 1];
  869. u8 value_byte;
  870. u32 value_integer;
  871. int ret = -EINVAL;
  872. bool getall = false;
  873. int i;
  874. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->getbcnrp ||
  875. !netdev->dcbnl_ops->getbcncfg)
  876. return ret;
  877. ret = nla_parse_nested(bcn_tb, DCB_BCN_ATTR_MAX,
  878. tb[DCB_ATTR_BCN], dcbnl_bcn_nest);
  879. if (ret)
  880. goto err_out;
  881. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  882. if (!dcbnl_skb)
  883. goto err_out;
  884. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  885. dcb = NLMSG_DATA(nlh);
  886. dcb->dcb_family = AF_UNSPEC;
  887. dcb->cmd = DCB_CMD_BCN_GCFG;
  888. bcn_nest = nla_nest_start(dcbnl_skb, DCB_ATTR_BCN);
  889. if (!bcn_nest)
  890. goto err;
  891. if (bcn_tb[DCB_BCN_ATTR_ALL])
  892. getall = true;
  893. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  894. if (!getall && !bcn_tb[i])
  895. continue;
  896. netdev->dcbnl_ops->getbcnrp(netdev, i - DCB_BCN_ATTR_RP_0,
  897. &value_byte);
  898. ret = nla_put_u8(dcbnl_skb, i, value_byte);
  899. if (ret)
  900. goto err_bcn;
  901. }
  902. for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
  903. if (!getall && !bcn_tb[i])
  904. continue;
  905. netdev->dcbnl_ops->getbcncfg(netdev, i,
  906. &value_integer);
  907. ret = nla_put_u32(dcbnl_skb, i, value_integer);
  908. if (ret)
  909. goto err_bcn;
  910. }
  911. nla_nest_end(dcbnl_skb, bcn_nest);
  912. nlmsg_end(dcbnl_skb, nlh);
  913. ret = rtnl_unicast(dcbnl_skb, &init_net, pid);
  914. if (ret)
  915. goto err_out;
  916. return 0;
  917. err_bcn:
  918. nla_nest_cancel(dcbnl_skb, bcn_nest);
  919. nlmsg_failure:
  920. err:
  921. kfree_skb(dcbnl_skb);
  922. err_out:
  923. ret = -EINVAL;
  924. return ret;
  925. }
  926. static int dcbnl_bcn_setcfg(struct net_device *netdev, struct nlattr **tb,
  927. u32 pid, u32 seq, u16 flags)
  928. {
  929. struct nlattr *data[DCB_BCN_ATTR_MAX + 1];
  930. int i;
  931. int ret = -EINVAL;
  932. u8 value_byte;
  933. u32 value_int;
  934. if (!tb[DCB_ATTR_BCN] || !netdev->dcbnl_ops->setbcncfg ||
  935. !netdev->dcbnl_ops->setbcnrp)
  936. return ret;
  937. ret = nla_parse_nested(data, DCB_BCN_ATTR_MAX,
  938. tb[DCB_ATTR_BCN],
  939. dcbnl_pfc_up_nest);
  940. if (ret)
  941. goto err;
  942. for (i = DCB_BCN_ATTR_RP_0; i <= DCB_BCN_ATTR_RP_7; i++) {
  943. if (data[i] == NULL)
  944. continue;
  945. value_byte = nla_get_u8(data[i]);
  946. netdev->dcbnl_ops->setbcnrp(netdev,
  947. data[i]->nla_type - DCB_BCN_ATTR_RP_0, value_byte);
  948. }
  949. for (i = DCB_BCN_ATTR_BCNA_0; i <= DCB_BCN_ATTR_RI; i++) {
  950. if (data[i] == NULL)
  951. continue;
  952. value_int = nla_get_u32(data[i]);
  953. netdev->dcbnl_ops->setbcncfg(netdev,
  954. i, value_int);
  955. }
  956. ret = dcbnl_reply(0, RTM_SETDCB, DCB_CMD_BCN_SCFG, DCB_ATTR_BCN,
  957. pid, seq, flags);
  958. err:
  959. return ret;
  960. }
  961. static int dcbnl_build_peer_app(struct net_device *netdev, struct sk_buff* skb,
  962. int app_nested_type, int app_info_type,
  963. int app_entry_type)
  964. {
  965. struct dcb_peer_app_info info;
  966. struct dcb_app *table = NULL;
  967. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  968. u16 app_count;
  969. int err;
  970. /**
  971. * retrieve the peer app configuration form the driver. If the driver
  972. * handlers fail exit without doing anything
  973. */
  974. err = ops->peer_getappinfo(netdev, &info, &app_count);
  975. if (!err && app_count) {
  976. table = kmalloc(sizeof(struct dcb_app) * app_count, GFP_KERNEL);
  977. if (!table)
  978. return -ENOMEM;
  979. err = ops->peer_getapptable(netdev, table);
  980. }
  981. if (!err) {
  982. u16 i;
  983. struct nlattr *app;
  984. /**
  985. * build the message, from here on the only possible failure
  986. * is due to the skb size
  987. */
  988. err = -EMSGSIZE;
  989. app = nla_nest_start(skb, app_nested_type);
  990. if (!app)
  991. goto nla_put_failure;
  992. if (app_info_type)
  993. NLA_PUT(skb, app_info_type, sizeof(info), &info);
  994. for (i = 0; i < app_count; i++)
  995. NLA_PUT(skb, app_entry_type, sizeof(struct dcb_app),
  996. &table[i]);
  997. nla_nest_end(skb, app);
  998. }
  999. err = 0;
  1000. nla_put_failure:
  1001. kfree(table);
  1002. return err;
  1003. }
  1004. /* Handle IEEE 802.1Qaz GET commands. */
  1005. static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
  1006. {
  1007. struct nlattr *ieee, *app;
  1008. struct dcb_app_type *itr;
  1009. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1010. int dcbx;
  1011. int err = -EMSGSIZE;
  1012. NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name);
  1013. ieee = nla_nest_start(skb, DCB_ATTR_IEEE);
  1014. if (!ieee)
  1015. goto nla_put_failure;
  1016. if (ops->ieee_getets) {
  1017. struct ieee_ets ets;
  1018. err = ops->ieee_getets(netdev, &ets);
  1019. if (!err)
  1020. NLA_PUT(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets);
  1021. }
  1022. if (ops->ieee_getpfc) {
  1023. struct ieee_pfc pfc;
  1024. err = ops->ieee_getpfc(netdev, &pfc);
  1025. if (!err)
  1026. NLA_PUT(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc);
  1027. }
  1028. app = nla_nest_start(skb, DCB_ATTR_IEEE_APP_TABLE);
  1029. if (!app)
  1030. goto nla_put_failure;
  1031. spin_lock(&dcb_lock);
  1032. list_for_each_entry(itr, &dcb_app_list, list) {
  1033. if (itr->ifindex == netdev->ifindex) {
  1034. err = nla_put(skb, DCB_ATTR_IEEE_APP, sizeof(itr->app),
  1035. &itr->app);
  1036. if (err) {
  1037. spin_unlock(&dcb_lock);
  1038. goto nla_put_failure;
  1039. }
  1040. }
  1041. }
  1042. if (netdev->dcbnl_ops->getdcbx)
  1043. dcbx = netdev->dcbnl_ops->getdcbx(netdev);
  1044. else
  1045. dcbx = -EOPNOTSUPP;
  1046. spin_unlock(&dcb_lock);
  1047. nla_nest_end(skb, app);
  1048. /* get peer info if available */
  1049. if (ops->ieee_peer_getets) {
  1050. struct ieee_ets ets;
  1051. err = ops->ieee_peer_getets(netdev, &ets);
  1052. if (!err)
  1053. NLA_PUT(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets);
  1054. }
  1055. if (ops->ieee_peer_getpfc) {
  1056. struct ieee_pfc pfc;
  1057. err = ops->ieee_peer_getpfc(netdev, &pfc);
  1058. if (!err)
  1059. NLA_PUT(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc);
  1060. }
  1061. if (ops->peer_getappinfo && ops->peer_getapptable) {
  1062. err = dcbnl_build_peer_app(netdev, skb,
  1063. DCB_ATTR_IEEE_PEER_APP,
  1064. DCB_ATTR_IEEE_APP_UNSPEC,
  1065. DCB_ATTR_IEEE_APP);
  1066. if (err)
  1067. goto nla_put_failure;
  1068. }
  1069. nla_nest_end(skb, ieee);
  1070. if (dcbx >= 0) {
  1071. err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
  1072. if (err)
  1073. goto nla_put_failure;
  1074. }
  1075. return 0;
  1076. nla_put_failure:
  1077. return err;
  1078. }
  1079. static int dcbnl_cee_pg_fill(struct sk_buff *skb, struct net_device *dev,
  1080. int dir)
  1081. {
  1082. u8 pgid, up_map, prio, tc_pct;
  1083. const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
  1084. int i = dir ? DCB_ATTR_CEE_TX_PG : DCB_ATTR_CEE_RX_PG;
  1085. struct nlattr *pg = nla_nest_start(skb, i);
  1086. if (!pg)
  1087. goto nla_put_failure;
  1088. for (i = DCB_PG_ATTR_TC_0; i <= DCB_PG_ATTR_TC_7; i++) {
  1089. struct nlattr *tc_nest = nla_nest_start(skb, i);
  1090. if (!tc_nest)
  1091. goto nla_put_failure;
  1092. pgid = DCB_ATTR_VALUE_UNDEFINED;
  1093. prio = DCB_ATTR_VALUE_UNDEFINED;
  1094. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  1095. up_map = DCB_ATTR_VALUE_UNDEFINED;
  1096. if (!dir)
  1097. ops->getpgtccfgrx(dev, i - DCB_PG_ATTR_TC_0,
  1098. &prio, &pgid, &tc_pct, &up_map);
  1099. else
  1100. ops->getpgtccfgtx(dev, i - DCB_PG_ATTR_TC_0,
  1101. &prio, &pgid, &tc_pct, &up_map);
  1102. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_PGID, pgid);
  1103. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_UP_MAPPING, up_map);
  1104. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_STRICT_PRIO, prio);
  1105. NLA_PUT_U8(skb, DCB_TC_ATTR_PARAM_BW_PCT, tc_pct);
  1106. nla_nest_end(skb, tc_nest);
  1107. }
  1108. for (i = DCB_PG_ATTR_BW_ID_0; i <= DCB_PG_ATTR_BW_ID_7; i++) {
  1109. tc_pct = DCB_ATTR_VALUE_UNDEFINED;
  1110. if (!dir)
  1111. ops->getpgbwgcfgrx(dev, i - DCB_PG_ATTR_BW_ID_0,
  1112. &tc_pct);
  1113. else
  1114. ops->getpgbwgcfgtx(dev, i - DCB_PG_ATTR_BW_ID_0,
  1115. &tc_pct);
  1116. NLA_PUT_U8(skb, i, tc_pct);
  1117. }
  1118. nla_nest_end(skb, pg);
  1119. return 0;
  1120. nla_put_failure:
  1121. return -EMSGSIZE;
  1122. }
  1123. static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
  1124. {
  1125. struct nlattr *cee, *app;
  1126. struct dcb_app_type *itr;
  1127. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1128. int dcbx, i, err = -EMSGSIZE;
  1129. u8 value;
  1130. NLA_PUT_STRING(skb, DCB_ATTR_IFNAME, netdev->name);
  1131. cee = nla_nest_start(skb, DCB_ATTR_CEE);
  1132. if (!cee)
  1133. goto nla_put_failure;
  1134. /* local pg */
  1135. if (ops->getpgtccfgtx && ops->getpgbwgcfgtx) {
  1136. err = dcbnl_cee_pg_fill(skb, netdev, 1);
  1137. if (err)
  1138. goto nla_put_failure;
  1139. }
  1140. if (ops->getpgtccfgrx && ops->getpgbwgcfgrx) {
  1141. err = dcbnl_cee_pg_fill(skb, netdev, 0);
  1142. if (err)
  1143. goto nla_put_failure;
  1144. }
  1145. /* local pfc */
  1146. if (ops->getpfccfg) {
  1147. struct nlattr *pfc_nest = nla_nest_start(skb, DCB_ATTR_CEE_PFC);
  1148. if (!pfc_nest)
  1149. goto nla_put_failure;
  1150. for (i = DCB_PFC_UP_ATTR_0; i <= DCB_PFC_UP_ATTR_7; i++) {
  1151. ops->getpfccfg(netdev, i - DCB_PFC_UP_ATTR_0, &value);
  1152. NLA_PUT_U8(skb, i, value);
  1153. }
  1154. nla_nest_end(skb, pfc_nest);
  1155. }
  1156. /* local app */
  1157. spin_lock(&dcb_lock);
  1158. app = nla_nest_start(skb, DCB_ATTR_CEE_APP_TABLE);
  1159. if (!app)
  1160. goto dcb_unlock;
  1161. list_for_each_entry(itr, &dcb_app_list, list) {
  1162. if (itr->ifindex == netdev->ifindex) {
  1163. struct nlattr *app_nest = nla_nest_start(skb,
  1164. DCB_ATTR_APP);
  1165. if (!app_nest)
  1166. goto dcb_unlock;
  1167. err = nla_put_u8(skb, DCB_APP_ATTR_IDTYPE,
  1168. itr->app.selector);
  1169. if (err)
  1170. goto dcb_unlock;
  1171. err = nla_put_u16(skb, DCB_APP_ATTR_ID,
  1172. itr->app.protocol);
  1173. if (err)
  1174. goto dcb_unlock;
  1175. err = nla_put_u8(skb, DCB_APP_ATTR_PRIORITY,
  1176. itr->app.priority);
  1177. if (err)
  1178. goto dcb_unlock;
  1179. nla_nest_end(skb, app_nest);
  1180. }
  1181. }
  1182. nla_nest_end(skb, app);
  1183. if (netdev->dcbnl_ops->getdcbx)
  1184. dcbx = netdev->dcbnl_ops->getdcbx(netdev);
  1185. else
  1186. dcbx = -EOPNOTSUPP;
  1187. spin_unlock(&dcb_lock);
  1188. /* features flags */
  1189. if (ops->getfeatcfg) {
  1190. struct nlattr *feat = nla_nest_start(skb, DCB_ATTR_CEE_FEAT);
  1191. if (!feat)
  1192. goto nla_put_failure;
  1193. for (i = DCB_FEATCFG_ATTR_ALL + 1; i <= DCB_FEATCFG_ATTR_MAX;
  1194. i++)
  1195. if (!ops->getfeatcfg(netdev, i, &value))
  1196. NLA_PUT_U8(skb, i, value);
  1197. nla_nest_end(skb, feat);
  1198. }
  1199. /* peer info if available */
  1200. if (ops->cee_peer_getpg) {
  1201. struct cee_pg pg;
  1202. err = ops->cee_peer_getpg(netdev, &pg);
  1203. if (!err)
  1204. NLA_PUT(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg);
  1205. }
  1206. if (ops->cee_peer_getpfc) {
  1207. struct cee_pfc pfc;
  1208. err = ops->cee_peer_getpfc(netdev, &pfc);
  1209. if (!err)
  1210. NLA_PUT(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc);
  1211. }
  1212. if (ops->peer_getappinfo && ops->peer_getapptable) {
  1213. err = dcbnl_build_peer_app(netdev, skb,
  1214. DCB_ATTR_CEE_PEER_APP_TABLE,
  1215. DCB_ATTR_CEE_PEER_APP_INFO,
  1216. DCB_ATTR_CEE_PEER_APP);
  1217. if (err)
  1218. goto nla_put_failure;
  1219. }
  1220. nla_nest_end(skb, cee);
  1221. /* DCBX state */
  1222. if (dcbx >= 0) {
  1223. err = nla_put_u8(skb, DCB_ATTR_DCBX, dcbx);
  1224. if (err)
  1225. goto nla_put_failure;
  1226. }
  1227. return 0;
  1228. dcb_unlock:
  1229. spin_unlock(&dcb_lock);
  1230. nla_put_failure:
  1231. return err;
  1232. }
  1233. static int dcbnl_notify(struct net_device *dev, int event, int cmd,
  1234. u32 seq, u32 pid, int dcbx_ver)
  1235. {
  1236. struct net *net = dev_net(dev);
  1237. struct sk_buff *skb;
  1238. struct nlmsghdr *nlh;
  1239. struct dcbmsg *dcb;
  1240. const struct dcbnl_rtnl_ops *ops = dev->dcbnl_ops;
  1241. int err;
  1242. if (!ops)
  1243. return -EOPNOTSUPP;
  1244. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1245. if (!skb)
  1246. return -ENOBUFS;
  1247. nlh = nlmsg_put(skb, pid, 0, event, sizeof(*dcb), 0);
  1248. if (nlh == NULL) {
  1249. nlmsg_free(skb);
  1250. return -EMSGSIZE;
  1251. }
  1252. dcb = NLMSG_DATA(nlh);
  1253. dcb->dcb_family = AF_UNSPEC;
  1254. dcb->cmd = cmd;
  1255. if (dcbx_ver == DCB_CAP_DCBX_VER_IEEE)
  1256. err = dcbnl_ieee_fill(skb, dev);
  1257. else
  1258. err = dcbnl_cee_fill(skb, dev);
  1259. if (err < 0) {
  1260. /* Report error to broadcast listeners */
  1261. nlmsg_cancel(skb, nlh);
  1262. kfree_skb(skb);
  1263. rtnl_set_sk_err(net, RTNLGRP_DCB, err);
  1264. } else {
  1265. /* End nlmsg and notify broadcast listeners */
  1266. nlmsg_end(skb, nlh);
  1267. rtnl_notify(skb, net, 0, RTNLGRP_DCB, NULL, GFP_KERNEL);
  1268. }
  1269. return err;
  1270. }
  1271. int dcbnl_ieee_notify(struct net_device *dev, int event, int cmd,
  1272. u32 seq, u32 pid)
  1273. {
  1274. return dcbnl_notify(dev, event, cmd, seq, pid, DCB_CAP_DCBX_VER_IEEE);
  1275. }
  1276. EXPORT_SYMBOL(dcbnl_ieee_notify);
  1277. int dcbnl_cee_notify(struct net_device *dev, int event, int cmd,
  1278. u32 seq, u32 pid)
  1279. {
  1280. return dcbnl_notify(dev, event, cmd, seq, pid, DCB_CAP_DCBX_VER_CEE);
  1281. }
  1282. EXPORT_SYMBOL(dcbnl_cee_notify);
  1283. /* Handle IEEE 802.1Qaz SET commands. If any requested operation can not
  1284. * be completed the entire msg is aborted and error value is returned.
  1285. * No attempt is made to reconcile the case where only part of the
  1286. * cmd can be completed.
  1287. */
  1288. static int dcbnl_ieee_set(struct net_device *netdev, struct nlattr **tb,
  1289. u32 pid, u32 seq, u16 flags)
  1290. {
  1291. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1292. struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
  1293. int err = -EOPNOTSUPP;
  1294. if (!ops)
  1295. return err;
  1296. if (!tb[DCB_ATTR_IEEE])
  1297. return -EINVAL;
  1298. err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX,
  1299. tb[DCB_ATTR_IEEE], dcbnl_ieee_policy);
  1300. if (err)
  1301. return err;
  1302. if (ieee[DCB_ATTR_IEEE_ETS] && ops->ieee_setets) {
  1303. struct ieee_ets *ets = nla_data(ieee[DCB_ATTR_IEEE_ETS]);
  1304. err = ops->ieee_setets(netdev, ets);
  1305. if (err)
  1306. goto err;
  1307. }
  1308. if (ieee[DCB_ATTR_IEEE_PFC] && ops->ieee_setpfc) {
  1309. struct ieee_pfc *pfc = nla_data(ieee[DCB_ATTR_IEEE_PFC]);
  1310. err = ops->ieee_setpfc(netdev, pfc);
  1311. if (err)
  1312. goto err;
  1313. }
  1314. if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
  1315. struct nlattr *attr;
  1316. int rem;
  1317. nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
  1318. struct dcb_app *app_data;
  1319. if (nla_type(attr) != DCB_ATTR_IEEE_APP)
  1320. continue;
  1321. app_data = nla_data(attr);
  1322. if (ops->ieee_setapp)
  1323. err = ops->ieee_setapp(netdev, app_data);
  1324. else
  1325. err = dcb_ieee_setapp(netdev, app_data);
  1326. if (err)
  1327. goto err;
  1328. }
  1329. }
  1330. err:
  1331. dcbnl_reply(err, RTM_SETDCB, DCB_CMD_IEEE_SET, DCB_ATTR_IEEE,
  1332. pid, seq, flags);
  1333. dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_SET, seq, 0);
  1334. return err;
  1335. }
  1336. static int dcbnl_ieee_get(struct net_device *netdev, struct nlattr **tb,
  1337. u32 pid, u32 seq, u16 flags)
  1338. {
  1339. struct net *net = dev_net(netdev);
  1340. struct sk_buff *skb;
  1341. struct nlmsghdr *nlh;
  1342. struct dcbmsg *dcb;
  1343. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1344. int err;
  1345. if (!ops)
  1346. return -EOPNOTSUPP;
  1347. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1348. if (!skb)
  1349. return -ENOBUFS;
  1350. nlh = nlmsg_put(skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1351. if (nlh == NULL) {
  1352. nlmsg_free(skb);
  1353. return -EMSGSIZE;
  1354. }
  1355. dcb = NLMSG_DATA(nlh);
  1356. dcb->dcb_family = AF_UNSPEC;
  1357. dcb->cmd = DCB_CMD_IEEE_GET;
  1358. err = dcbnl_ieee_fill(skb, netdev);
  1359. if (err < 0) {
  1360. nlmsg_cancel(skb, nlh);
  1361. kfree_skb(skb);
  1362. } else {
  1363. nlmsg_end(skb, nlh);
  1364. err = rtnl_unicast(skb, net, pid);
  1365. }
  1366. return err;
  1367. }
  1368. static int dcbnl_ieee_del(struct net_device *netdev, struct nlattr **tb,
  1369. u32 pid, u32 seq, u16 flags)
  1370. {
  1371. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1372. struct nlattr *ieee[DCB_ATTR_IEEE_MAX + 1];
  1373. int err = -EOPNOTSUPP;
  1374. if (!ops)
  1375. return -EOPNOTSUPP;
  1376. if (!tb[DCB_ATTR_IEEE])
  1377. return -EINVAL;
  1378. err = nla_parse_nested(ieee, DCB_ATTR_IEEE_MAX,
  1379. tb[DCB_ATTR_IEEE], dcbnl_ieee_policy);
  1380. if (err)
  1381. return err;
  1382. if (ieee[DCB_ATTR_IEEE_APP_TABLE]) {
  1383. struct nlattr *attr;
  1384. int rem;
  1385. nla_for_each_nested(attr, ieee[DCB_ATTR_IEEE_APP_TABLE], rem) {
  1386. struct dcb_app *app_data;
  1387. if (nla_type(attr) != DCB_ATTR_IEEE_APP)
  1388. continue;
  1389. app_data = nla_data(attr);
  1390. if (ops->ieee_delapp)
  1391. err = ops->ieee_delapp(netdev, app_data);
  1392. else
  1393. err = dcb_ieee_delapp(netdev, app_data);
  1394. if (err)
  1395. goto err;
  1396. }
  1397. }
  1398. err:
  1399. dcbnl_reply(err, RTM_SETDCB, DCB_CMD_IEEE_DEL, DCB_ATTR_IEEE,
  1400. pid, seq, flags);
  1401. dcbnl_ieee_notify(netdev, RTM_SETDCB, DCB_CMD_IEEE_DEL, seq, 0);
  1402. return err;
  1403. }
  1404. /* DCBX configuration */
  1405. static int dcbnl_getdcbx(struct net_device *netdev, struct nlattr **tb,
  1406. u32 pid, u32 seq, u16 flags)
  1407. {
  1408. int ret;
  1409. if (!netdev->dcbnl_ops->getdcbx)
  1410. return -EOPNOTSUPP;
  1411. ret = dcbnl_reply(netdev->dcbnl_ops->getdcbx(netdev), RTM_GETDCB,
  1412. DCB_CMD_GDCBX, DCB_ATTR_DCBX, pid, seq, flags);
  1413. return ret;
  1414. }
  1415. static int dcbnl_setdcbx(struct net_device *netdev, struct nlattr **tb,
  1416. u32 pid, u32 seq, u16 flags)
  1417. {
  1418. int ret;
  1419. u8 value;
  1420. if (!netdev->dcbnl_ops->setdcbx)
  1421. return -EOPNOTSUPP;
  1422. if (!tb[DCB_ATTR_DCBX])
  1423. return -EINVAL;
  1424. value = nla_get_u8(tb[DCB_ATTR_DCBX]);
  1425. ret = dcbnl_reply(netdev->dcbnl_ops->setdcbx(netdev, value),
  1426. RTM_SETDCB, DCB_CMD_SDCBX, DCB_ATTR_DCBX,
  1427. pid, seq, flags);
  1428. return ret;
  1429. }
  1430. static int dcbnl_getfeatcfg(struct net_device *netdev, struct nlattr **tb,
  1431. u32 pid, u32 seq, u16 flags)
  1432. {
  1433. struct sk_buff *dcbnl_skb;
  1434. struct nlmsghdr *nlh;
  1435. struct dcbmsg *dcb;
  1436. struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1], *nest;
  1437. u8 value;
  1438. int ret, i;
  1439. int getall = 0;
  1440. if (!netdev->dcbnl_ops->getfeatcfg)
  1441. return -EOPNOTSUPP;
  1442. if (!tb[DCB_ATTR_FEATCFG])
  1443. return -EINVAL;
  1444. ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
  1445. dcbnl_featcfg_nest);
  1446. if (ret)
  1447. goto err_out;
  1448. dcbnl_skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1449. if (!dcbnl_skb) {
  1450. ret = -ENOBUFS;
  1451. goto err_out;
  1452. }
  1453. nlh = NLMSG_NEW(dcbnl_skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1454. dcb = NLMSG_DATA(nlh);
  1455. dcb->dcb_family = AF_UNSPEC;
  1456. dcb->cmd = DCB_CMD_GFEATCFG;
  1457. nest = nla_nest_start(dcbnl_skb, DCB_ATTR_FEATCFG);
  1458. if (!nest) {
  1459. ret = -EMSGSIZE;
  1460. goto nla_put_failure;
  1461. }
  1462. if (data[DCB_FEATCFG_ATTR_ALL])
  1463. getall = 1;
  1464. for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
  1465. if (!getall && !data[i])
  1466. continue;
  1467. ret = netdev->dcbnl_ops->getfeatcfg(netdev, i, &value);
  1468. if (!ret)
  1469. ret = nla_put_u8(dcbnl_skb, i, value);
  1470. if (ret) {
  1471. nla_nest_cancel(dcbnl_skb, nest);
  1472. goto nla_put_failure;
  1473. }
  1474. }
  1475. nla_nest_end(dcbnl_skb, nest);
  1476. nlmsg_end(dcbnl_skb, nlh);
  1477. return rtnl_unicast(dcbnl_skb, &init_net, pid);
  1478. nla_put_failure:
  1479. nlmsg_cancel(dcbnl_skb, nlh);
  1480. nlmsg_failure:
  1481. kfree_skb(dcbnl_skb);
  1482. err_out:
  1483. return ret;
  1484. }
  1485. static int dcbnl_setfeatcfg(struct net_device *netdev, struct nlattr **tb,
  1486. u32 pid, u32 seq, u16 flags)
  1487. {
  1488. struct nlattr *data[DCB_FEATCFG_ATTR_MAX + 1];
  1489. int ret, i;
  1490. u8 value;
  1491. if (!netdev->dcbnl_ops->setfeatcfg)
  1492. return -ENOTSUPP;
  1493. if (!tb[DCB_ATTR_FEATCFG])
  1494. return -EINVAL;
  1495. ret = nla_parse_nested(data, DCB_FEATCFG_ATTR_MAX, tb[DCB_ATTR_FEATCFG],
  1496. dcbnl_featcfg_nest);
  1497. if (ret)
  1498. goto err;
  1499. for (i = DCB_FEATCFG_ATTR_ALL+1; i <= DCB_FEATCFG_ATTR_MAX; i++) {
  1500. if (data[i] == NULL)
  1501. continue;
  1502. value = nla_get_u8(data[i]);
  1503. ret = netdev->dcbnl_ops->setfeatcfg(netdev, i, value);
  1504. if (ret)
  1505. goto err;
  1506. }
  1507. err:
  1508. dcbnl_reply(ret, RTM_SETDCB, DCB_CMD_SFEATCFG, DCB_ATTR_FEATCFG,
  1509. pid, seq, flags);
  1510. return ret;
  1511. }
  1512. /* Handle CEE DCBX GET commands. */
  1513. static int dcbnl_cee_get(struct net_device *netdev, struct nlattr **tb,
  1514. u32 pid, u32 seq, u16 flags)
  1515. {
  1516. struct net *net = dev_net(netdev);
  1517. struct sk_buff *skb;
  1518. struct nlmsghdr *nlh;
  1519. struct dcbmsg *dcb;
  1520. const struct dcbnl_rtnl_ops *ops = netdev->dcbnl_ops;
  1521. int err;
  1522. if (!ops)
  1523. return -EOPNOTSUPP;
  1524. skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
  1525. if (!skb)
  1526. return -ENOBUFS;
  1527. nlh = nlmsg_put(skb, pid, seq, RTM_GETDCB, sizeof(*dcb), flags);
  1528. if (nlh == NULL) {
  1529. nlmsg_free(skb);
  1530. return -EMSGSIZE;
  1531. }
  1532. dcb = NLMSG_DATA(nlh);
  1533. dcb->dcb_family = AF_UNSPEC;
  1534. dcb->cmd = DCB_CMD_CEE_GET;
  1535. err = dcbnl_cee_fill(skb, netdev);
  1536. if (err < 0) {
  1537. nlmsg_cancel(skb, nlh);
  1538. nlmsg_free(skb);
  1539. } else {
  1540. nlmsg_end(skb, nlh);
  1541. err = rtnl_unicast(skb, net, pid);
  1542. }
  1543. return err;
  1544. }
  1545. static int dcb_doit(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
  1546. {
  1547. struct net *net = sock_net(skb->sk);
  1548. struct net_device *netdev;
  1549. struct dcbmsg *dcb = (struct dcbmsg *)NLMSG_DATA(nlh);
  1550. struct nlattr *tb[DCB_ATTR_MAX + 1];
  1551. u32 pid = skb ? NETLINK_CB(skb).pid : 0;
  1552. int ret = -EINVAL;
  1553. if (!net_eq(net, &init_net))
  1554. return -EINVAL;
  1555. ret = nlmsg_parse(nlh, sizeof(*dcb), tb, DCB_ATTR_MAX,
  1556. dcbnl_rtnl_policy);
  1557. if (ret < 0)
  1558. return ret;
  1559. if (!tb[DCB_ATTR_IFNAME])
  1560. return -EINVAL;
  1561. netdev = dev_get_by_name(&init_net, nla_data(tb[DCB_ATTR_IFNAME]));
  1562. if (!netdev)
  1563. return -EINVAL;
  1564. if (!netdev->dcbnl_ops)
  1565. goto errout;
  1566. switch (dcb->cmd) {
  1567. case DCB_CMD_GSTATE:
  1568. ret = dcbnl_getstate(netdev, tb, pid, nlh->nlmsg_seq,
  1569. nlh->nlmsg_flags);
  1570. goto out;
  1571. case DCB_CMD_PFC_GCFG:
  1572. ret = dcbnl_getpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  1573. nlh->nlmsg_flags);
  1574. goto out;
  1575. case DCB_CMD_GPERM_HWADDR:
  1576. ret = dcbnl_getperm_hwaddr(netdev, tb, pid, nlh->nlmsg_seq,
  1577. nlh->nlmsg_flags);
  1578. goto out;
  1579. case DCB_CMD_PGTX_GCFG:
  1580. ret = dcbnl_pgtx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1581. nlh->nlmsg_flags);
  1582. goto out;
  1583. case DCB_CMD_PGRX_GCFG:
  1584. ret = dcbnl_pgrx_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1585. nlh->nlmsg_flags);
  1586. goto out;
  1587. case DCB_CMD_BCN_GCFG:
  1588. ret = dcbnl_bcn_getcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1589. nlh->nlmsg_flags);
  1590. goto out;
  1591. case DCB_CMD_SSTATE:
  1592. ret = dcbnl_setstate(netdev, tb, pid, nlh->nlmsg_seq,
  1593. nlh->nlmsg_flags);
  1594. goto out;
  1595. case DCB_CMD_PFC_SCFG:
  1596. ret = dcbnl_setpfccfg(netdev, tb, pid, nlh->nlmsg_seq,
  1597. nlh->nlmsg_flags);
  1598. goto out;
  1599. case DCB_CMD_SET_ALL:
  1600. ret = dcbnl_setall(netdev, tb, pid, nlh->nlmsg_seq,
  1601. nlh->nlmsg_flags);
  1602. goto out;
  1603. case DCB_CMD_PGTX_SCFG:
  1604. ret = dcbnl_pgtx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1605. nlh->nlmsg_flags);
  1606. goto out;
  1607. case DCB_CMD_PGRX_SCFG:
  1608. ret = dcbnl_pgrx_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1609. nlh->nlmsg_flags);
  1610. goto out;
  1611. case DCB_CMD_GCAP:
  1612. ret = dcbnl_getcap(netdev, tb, pid, nlh->nlmsg_seq,
  1613. nlh->nlmsg_flags);
  1614. goto out;
  1615. case DCB_CMD_GNUMTCS:
  1616. ret = dcbnl_getnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  1617. nlh->nlmsg_flags);
  1618. goto out;
  1619. case DCB_CMD_SNUMTCS:
  1620. ret = dcbnl_setnumtcs(netdev, tb, pid, nlh->nlmsg_seq,
  1621. nlh->nlmsg_flags);
  1622. goto out;
  1623. case DCB_CMD_PFC_GSTATE:
  1624. ret = dcbnl_getpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  1625. nlh->nlmsg_flags);
  1626. goto out;
  1627. case DCB_CMD_PFC_SSTATE:
  1628. ret = dcbnl_setpfcstate(netdev, tb, pid, nlh->nlmsg_seq,
  1629. nlh->nlmsg_flags);
  1630. goto out;
  1631. case DCB_CMD_BCN_SCFG:
  1632. ret = dcbnl_bcn_setcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1633. nlh->nlmsg_flags);
  1634. goto out;
  1635. case DCB_CMD_GAPP:
  1636. ret = dcbnl_getapp(netdev, tb, pid, nlh->nlmsg_seq,
  1637. nlh->nlmsg_flags);
  1638. goto out;
  1639. case DCB_CMD_SAPP:
  1640. ret = dcbnl_setapp(netdev, tb, pid, nlh->nlmsg_seq,
  1641. nlh->nlmsg_flags);
  1642. goto out;
  1643. case DCB_CMD_IEEE_SET:
  1644. ret = dcbnl_ieee_set(netdev, tb, pid, nlh->nlmsg_seq,
  1645. nlh->nlmsg_flags);
  1646. goto out;
  1647. case DCB_CMD_IEEE_GET:
  1648. ret = dcbnl_ieee_get(netdev, tb, pid, nlh->nlmsg_seq,
  1649. nlh->nlmsg_flags);
  1650. goto out;
  1651. case DCB_CMD_IEEE_DEL:
  1652. ret = dcbnl_ieee_del(netdev, tb, pid, nlh->nlmsg_seq,
  1653. nlh->nlmsg_flags);
  1654. goto out;
  1655. case DCB_CMD_GDCBX:
  1656. ret = dcbnl_getdcbx(netdev, tb, pid, nlh->nlmsg_seq,
  1657. nlh->nlmsg_flags);
  1658. goto out;
  1659. case DCB_CMD_SDCBX:
  1660. ret = dcbnl_setdcbx(netdev, tb, pid, nlh->nlmsg_seq,
  1661. nlh->nlmsg_flags);
  1662. goto out;
  1663. case DCB_CMD_GFEATCFG:
  1664. ret = dcbnl_getfeatcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1665. nlh->nlmsg_flags);
  1666. goto out;
  1667. case DCB_CMD_SFEATCFG:
  1668. ret = dcbnl_setfeatcfg(netdev, tb, pid, nlh->nlmsg_seq,
  1669. nlh->nlmsg_flags);
  1670. goto out;
  1671. case DCB_CMD_CEE_GET:
  1672. ret = dcbnl_cee_get(netdev, tb, pid, nlh->nlmsg_seq,
  1673. nlh->nlmsg_flags);
  1674. goto out;
  1675. default:
  1676. goto errout;
  1677. }
  1678. errout:
  1679. ret = -EINVAL;
  1680. out:
  1681. dev_put(netdev);
  1682. return ret;
  1683. }
  1684. /**
  1685. * dcb_getapp - retrieve the DCBX application user priority
  1686. *
  1687. * On success returns a non-zero 802.1p user priority bitmap
  1688. * otherwise returns 0 as the invalid user priority bitmap to
  1689. * indicate an error.
  1690. */
  1691. u8 dcb_getapp(struct net_device *dev, struct dcb_app *app)
  1692. {
  1693. struct dcb_app_type *itr;
  1694. u8 prio = 0;
  1695. spin_lock(&dcb_lock);
  1696. list_for_each_entry(itr, &dcb_app_list, list) {
  1697. if (itr->app.selector == app->selector &&
  1698. itr->app.protocol == app->protocol &&
  1699. itr->ifindex == dev->ifindex) {
  1700. prio = itr->app.priority;
  1701. break;
  1702. }
  1703. }
  1704. spin_unlock(&dcb_lock);
  1705. return prio;
  1706. }
  1707. EXPORT_SYMBOL(dcb_getapp);
  1708. /**
  1709. * dcb_setapp - add CEE dcb application data to app list
  1710. *
  1711. * Priority 0 is an invalid priority in CEE spec. This routine
  1712. * removes applications from the app list if the priority is
  1713. * set to zero.
  1714. */
  1715. int dcb_setapp(struct net_device *dev, struct dcb_app *new)
  1716. {
  1717. struct dcb_app_type *itr;
  1718. struct dcb_app_type event;
  1719. event.ifindex = dev->ifindex;
  1720. memcpy(&event.app, new, sizeof(event.app));
  1721. if (dev->dcbnl_ops->getdcbx)
  1722. event.dcbx = dev->dcbnl_ops->getdcbx(dev);
  1723. spin_lock(&dcb_lock);
  1724. /* Search for existing match and replace */
  1725. list_for_each_entry(itr, &dcb_app_list, list) {
  1726. if (itr->app.selector == new->selector &&
  1727. itr->app.protocol == new->protocol &&
  1728. itr->ifindex == dev->ifindex) {
  1729. if (new->priority)
  1730. itr->app.priority = new->priority;
  1731. else {
  1732. list_del(&itr->list);
  1733. kfree(itr);
  1734. }
  1735. goto out;
  1736. }
  1737. }
  1738. /* App type does not exist add new application type */
  1739. if (new->priority) {
  1740. struct dcb_app_type *entry;
  1741. entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
  1742. if (!entry) {
  1743. spin_unlock(&dcb_lock);
  1744. return -ENOMEM;
  1745. }
  1746. memcpy(&entry->app, new, sizeof(*new));
  1747. entry->ifindex = dev->ifindex;
  1748. list_add(&entry->list, &dcb_app_list);
  1749. }
  1750. out:
  1751. spin_unlock(&dcb_lock);
  1752. call_dcbevent_notifiers(DCB_APP_EVENT, &event);
  1753. return 0;
  1754. }
  1755. EXPORT_SYMBOL(dcb_setapp);
  1756. /**
  1757. * dcb_ieee_getapp_mask - retrieve the IEEE DCB application priority
  1758. *
  1759. * Helper routine which on success returns a non-zero 802.1Qaz user
  1760. * priority bitmap otherwise returns 0 to indicate the dcb_app was
  1761. * not found in APP list.
  1762. */
  1763. u8 dcb_ieee_getapp_mask(struct net_device *dev, struct dcb_app *app)
  1764. {
  1765. struct dcb_app_type *itr;
  1766. u8 prio = 0;
  1767. spin_lock(&dcb_lock);
  1768. list_for_each_entry(itr, &dcb_app_list, list) {
  1769. if (itr->app.selector == app->selector &&
  1770. itr->app.protocol == app->protocol &&
  1771. itr->ifindex == dev->ifindex) {
  1772. prio |= 1 << itr->app.priority;
  1773. }
  1774. }
  1775. spin_unlock(&dcb_lock);
  1776. return prio;
  1777. }
  1778. EXPORT_SYMBOL(dcb_ieee_getapp_mask);
  1779. /**
  1780. * dcb_ieee_setapp - add IEEE dcb application data to app list
  1781. *
  1782. * This adds Application data to the list. Multiple application
  1783. * entries may exists for the same selector and protocol as long
  1784. * as the priorities are different.
  1785. */
  1786. int dcb_ieee_setapp(struct net_device *dev, struct dcb_app *new)
  1787. {
  1788. struct dcb_app_type *itr, *entry;
  1789. struct dcb_app_type event;
  1790. int err = 0;
  1791. event.ifindex = dev->ifindex;
  1792. memcpy(&event.app, new, sizeof(event.app));
  1793. if (dev->dcbnl_ops->getdcbx)
  1794. event.dcbx = dev->dcbnl_ops->getdcbx(dev);
  1795. spin_lock(&dcb_lock);
  1796. /* Search for existing match and abort if found */
  1797. list_for_each_entry(itr, &dcb_app_list, list) {
  1798. if (itr->app.selector == new->selector &&
  1799. itr->app.protocol == new->protocol &&
  1800. itr->app.priority == new->priority &&
  1801. itr->ifindex == dev->ifindex) {
  1802. err = -EEXIST;
  1803. goto out;
  1804. }
  1805. }
  1806. /* App entry does not exist add new entry */
  1807. entry = kmalloc(sizeof(struct dcb_app_type), GFP_ATOMIC);
  1808. if (!entry) {
  1809. err = -ENOMEM;
  1810. goto out;
  1811. }
  1812. memcpy(&entry->app, new, sizeof(*new));
  1813. entry->ifindex = dev->ifindex;
  1814. list_add(&entry->list, &dcb_app_list);
  1815. out:
  1816. spin_unlock(&dcb_lock);
  1817. if (!err)
  1818. call_dcbevent_notifiers(DCB_APP_EVENT, &event);
  1819. return err;
  1820. }
  1821. EXPORT_SYMBOL(dcb_ieee_setapp);
  1822. /**
  1823. * dcb_ieee_delapp - delete IEEE dcb application data from list
  1824. *
  1825. * This removes a matching APP data from the APP list
  1826. */
  1827. int dcb_ieee_delapp(struct net_device *dev, struct dcb_app *del)
  1828. {
  1829. struct dcb_app_type *itr;
  1830. struct dcb_app_type event;
  1831. int err = -ENOENT;
  1832. event.ifindex = dev->ifindex;
  1833. memcpy(&event.app, del, sizeof(event.app));
  1834. if (dev->dcbnl_ops->getdcbx)
  1835. event.dcbx = dev->dcbnl_ops->getdcbx(dev);
  1836. spin_lock(&dcb_lock);
  1837. /* Search for existing match and remove it. */
  1838. list_for_each_entry(itr, &dcb_app_list, list) {
  1839. if (itr->app.selector == del->selector &&
  1840. itr->app.protocol == del->protocol &&
  1841. itr->app.priority == del->priority &&
  1842. itr->ifindex == dev->ifindex) {
  1843. list_del(&itr->list);
  1844. kfree(itr);
  1845. err = 0;
  1846. goto out;
  1847. }
  1848. }
  1849. out:
  1850. spin_unlock(&dcb_lock);
  1851. if (!err)
  1852. call_dcbevent_notifiers(DCB_APP_EVENT, &event);
  1853. return err;
  1854. }
  1855. EXPORT_SYMBOL(dcb_ieee_delapp);
  1856. static void dcb_flushapp(void)
  1857. {
  1858. struct dcb_app_type *app;
  1859. struct dcb_app_type *tmp;
  1860. spin_lock(&dcb_lock);
  1861. list_for_each_entry_safe(app, tmp, &dcb_app_list, list) {
  1862. list_del(&app->list);
  1863. kfree(app);
  1864. }
  1865. spin_unlock(&dcb_lock);
  1866. }
  1867. static int __init dcbnl_init(void)
  1868. {
  1869. INIT_LIST_HEAD(&dcb_app_list);
  1870. rtnl_register(PF_UNSPEC, RTM_GETDCB, dcb_doit, NULL, NULL);
  1871. rtnl_register(PF_UNSPEC, RTM_SETDCB, dcb_doit, NULL, NULL);
  1872. return 0;
  1873. }
  1874. module_init(dcbnl_init);
  1875. static void __exit dcbnl_exit(void)
  1876. {
  1877. rtnl_unregister(PF_UNSPEC, RTM_GETDCB);
  1878. rtnl_unregister(PF_UNSPEC, RTM_SETDCB);
  1879. dcb_flushapp();
  1880. }
  1881. module_exit(dcbnl_exit);