dcbnl.c 42 KB

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