dcbnl.c 56 KB

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