spectrum_switchdev.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625
  1. /*
  2. * drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c
  3. * Copyright (c) 2015 Mellanox Technologies. All rights reserved.
  4. * Copyright (c) 2015 Jiri Pirko <jiri@mellanox.com>
  5. * Copyright (c) 2015 Ido Schimmel <idosch@mellanox.com>
  6. * Copyright (c) 2015 Elad Raz <eladr@mellanox.com>
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the names of the copyright holders nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * Alternatively, this software may be distributed under the terms of the
  21. * GNU General Public License ("GPL") version 2 as published by the Free
  22. * Software Foundation.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  34. * POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include <linux/kernel.h>
  37. #include <linux/types.h>
  38. #include <linux/netdevice.h>
  39. #include <linux/etherdevice.h>
  40. #include <linux/slab.h>
  41. #include <linux/device.h>
  42. #include <linux/skbuff.h>
  43. #include <linux/if_vlan.h>
  44. #include <linux/if_bridge.h>
  45. #include <linux/workqueue.h>
  46. #include <linux/jiffies.h>
  47. #include <linux/rtnetlink.h>
  48. #include <net/switchdev.h>
  49. #include "spectrum.h"
  50. #include "core.h"
  51. #include "reg.h"
  52. static u16 mlxsw_sp_port_vid_to_fid_get(struct mlxsw_sp_port *mlxsw_sp_port,
  53. u16 vid)
  54. {
  55. struct mlxsw_sp_fid *f = mlxsw_sp_vport_fid_get(mlxsw_sp_port);
  56. u16 fid = vid;
  57. fid = f ? f->fid : fid;
  58. if (!fid)
  59. fid = mlxsw_sp_port->pvid;
  60. return fid;
  61. }
  62. static struct mlxsw_sp_port *
  63. mlxsw_sp_port_orig_get(struct net_device *dev,
  64. struct mlxsw_sp_port *mlxsw_sp_port)
  65. {
  66. struct mlxsw_sp_port *mlxsw_sp_vport;
  67. u16 vid;
  68. if (!is_vlan_dev(dev))
  69. return mlxsw_sp_port;
  70. vid = vlan_dev_vlan_id(dev);
  71. mlxsw_sp_vport = mlxsw_sp_port_vport_find(mlxsw_sp_port, vid);
  72. WARN_ON(!mlxsw_sp_vport);
  73. return mlxsw_sp_vport;
  74. }
  75. static int mlxsw_sp_port_attr_get(struct net_device *dev,
  76. struct switchdev_attr *attr)
  77. {
  78. struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
  79. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  80. mlxsw_sp_port = mlxsw_sp_port_orig_get(attr->orig_dev, mlxsw_sp_port);
  81. if (!mlxsw_sp_port)
  82. return -EINVAL;
  83. switch (attr->id) {
  84. case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
  85. attr->u.ppid.id_len = sizeof(mlxsw_sp->base_mac);
  86. memcpy(&attr->u.ppid.id, &mlxsw_sp->base_mac,
  87. attr->u.ppid.id_len);
  88. break;
  89. case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
  90. attr->u.brport_flags =
  91. (mlxsw_sp_port->learning ? BR_LEARNING : 0) |
  92. (mlxsw_sp_port->learning_sync ? BR_LEARNING_SYNC : 0) |
  93. (mlxsw_sp_port->uc_flood ? BR_FLOOD : 0);
  94. break;
  95. default:
  96. return -EOPNOTSUPP;
  97. }
  98. return 0;
  99. }
  100. static int mlxsw_sp_port_stp_state_set(struct mlxsw_sp_port *mlxsw_sp_port,
  101. u8 state)
  102. {
  103. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  104. enum mlxsw_reg_spms_state spms_state;
  105. char *spms_pl;
  106. u16 vid;
  107. int err;
  108. switch (state) {
  109. case BR_STATE_FORWARDING:
  110. spms_state = MLXSW_REG_SPMS_STATE_FORWARDING;
  111. break;
  112. case BR_STATE_LEARNING:
  113. spms_state = MLXSW_REG_SPMS_STATE_LEARNING;
  114. break;
  115. case BR_STATE_LISTENING: /* fall-through */
  116. case BR_STATE_DISABLED: /* fall-through */
  117. case BR_STATE_BLOCKING:
  118. spms_state = MLXSW_REG_SPMS_STATE_DISCARDING;
  119. break;
  120. default:
  121. BUG();
  122. }
  123. spms_pl = kmalloc(MLXSW_REG_SPMS_LEN, GFP_KERNEL);
  124. if (!spms_pl)
  125. return -ENOMEM;
  126. mlxsw_reg_spms_pack(spms_pl, mlxsw_sp_port->local_port);
  127. if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
  128. vid = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
  129. mlxsw_reg_spms_vid_pack(spms_pl, vid, spms_state);
  130. } else {
  131. for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID)
  132. mlxsw_reg_spms_vid_pack(spms_pl, vid, spms_state);
  133. }
  134. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spms), spms_pl);
  135. kfree(spms_pl);
  136. return err;
  137. }
  138. static int mlxsw_sp_port_attr_stp_state_set(struct mlxsw_sp_port *mlxsw_sp_port,
  139. struct switchdev_trans *trans,
  140. u8 state)
  141. {
  142. if (switchdev_trans_ph_prepare(trans))
  143. return 0;
  144. mlxsw_sp_port->stp_state = state;
  145. return mlxsw_sp_port_stp_state_set(mlxsw_sp_port, state);
  146. }
  147. static int __mlxsw_sp_port_flood_set(struct mlxsw_sp_port *mlxsw_sp_port,
  148. u16 idx_begin, u16 idx_end, bool uc_set,
  149. bool bm_set)
  150. {
  151. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  152. u16 local_port = mlxsw_sp_port->local_port;
  153. enum mlxsw_flood_table_type table_type;
  154. u16 range = idx_end - idx_begin + 1;
  155. char *sftr_pl;
  156. int err;
  157. if (mlxsw_sp_port_is_vport(mlxsw_sp_port))
  158. table_type = MLXSW_REG_SFGC_TABLE_TYPE_FID;
  159. else
  160. table_type = MLXSW_REG_SFGC_TABLE_TYPE_FID_OFFEST;
  161. sftr_pl = kmalloc(MLXSW_REG_SFTR_LEN, GFP_KERNEL);
  162. if (!sftr_pl)
  163. return -ENOMEM;
  164. mlxsw_reg_sftr_pack(sftr_pl, MLXSW_SP_FLOOD_TABLE_UC, idx_begin,
  165. table_type, range, local_port, uc_set);
  166. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sftr), sftr_pl);
  167. if (err)
  168. goto buffer_out;
  169. mlxsw_reg_sftr_pack(sftr_pl, MLXSW_SP_FLOOD_TABLE_BM, idx_begin,
  170. table_type, range, local_port, bm_set);
  171. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sftr), sftr_pl);
  172. if (err)
  173. goto err_flood_bm_set;
  174. goto buffer_out;
  175. err_flood_bm_set:
  176. mlxsw_reg_sftr_pack(sftr_pl, MLXSW_SP_FLOOD_TABLE_UC, idx_begin,
  177. table_type, range, local_port, !uc_set);
  178. mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sftr), sftr_pl);
  179. buffer_out:
  180. kfree(sftr_pl);
  181. return err;
  182. }
  183. static int mlxsw_sp_port_uc_flood_set(struct mlxsw_sp_port *mlxsw_sp_port,
  184. bool set)
  185. {
  186. struct net_device *dev = mlxsw_sp_port->dev;
  187. u16 vid, last_visited_vid;
  188. int err;
  189. if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
  190. u16 fid = mlxsw_sp_vport_fid_get(mlxsw_sp_port)->fid;
  191. u16 vfid = mlxsw_sp_fid_to_vfid(fid);
  192. return __mlxsw_sp_port_flood_set(mlxsw_sp_port, vfid, vfid,
  193. set, true);
  194. }
  195. for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID) {
  196. err = __mlxsw_sp_port_flood_set(mlxsw_sp_port, vid, vid, set,
  197. true);
  198. if (err) {
  199. last_visited_vid = vid;
  200. goto err_port_flood_set;
  201. }
  202. }
  203. return 0;
  204. err_port_flood_set:
  205. for_each_set_bit(vid, mlxsw_sp_port->active_vlans, last_visited_vid)
  206. __mlxsw_sp_port_flood_set(mlxsw_sp_port, vid, vid, !set, true);
  207. netdev_err(dev, "Failed to configure unicast flooding\n");
  208. return err;
  209. }
  210. int mlxsw_sp_vport_flood_set(struct mlxsw_sp_port *mlxsw_sp_vport, u16 fid,
  211. bool set)
  212. {
  213. u16 vfid;
  214. /* In case of vFIDs, index into the flooding table is relative to
  215. * the start of the vFIDs range.
  216. */
  217. vfid = mlxsw_sp_fid_to_vfid(fid);
  218. return __mlxsw_sp_port_flood_set(mlxsw_sp_vport, vfid, vfid, set, set);
  219. }
  220. static int mlxsw_sp_port_learning_set(struct mlxsw_sp_port *mlxsw_sp_port,
  221. bool set)
  222. {
  223. u16 vid;
  224. int err;
  225. if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
  226. vid = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
  227. return __mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid, vid,
  228. set);
  229. }
  230. for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID) {
  231. err = __mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid, vid,
  232. set);
  233. if (err)
  234. goto err_port_vid_learning_set;
  235. }
  236. return 0;
  237. err_port_vid_learning_set:
  238. for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID)
  239. __mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid, vid, !set);
  240. return err;
  241. }
  242. static int mlxsw_sp_port_attr_br_flags_set(struct mlxsw_sp_port *mlxsw_sp_port,
  243. struct switchdev_trans *trans,
  244. unsigned long brport_flags)
  245. {
  246. unsigned long learning = mlxsw_sp_port->learning ? BR_LEARNING : 0;
  247. unsigned long uc_flood = mlxsw_sp_port->uc_flood ? BR_FLOOD : 0;
  248. int err;
  249. if (!mlxsw_sp_port->bridged)
  250. return -EINVAL;
  251. if (switchdev_trans_ph_prepare(trans))
  252. return 0;
  253. if ((uc_flood ^ brport_flags) & BR_FLOOD) {
  254. err = mlxsw_sp_port_uc_flood_set(mlxsw_sp_port,
  255. !mlxsw_sp_port->uc_flood);
  256. if (err)
  257. return err;
  258. }
  259. if ((learning ^ brport_flags) & BR_LEARNING) {
  260. err = mlxsw_sp_port_learning_set(mlxsw_sp_port,
  261. !mlxsw_sp_port->learning);
  262. if (err)
  263. goto err_port_learning_set;
  264. }
  265. mlxsw_sp_port->uc_flood = brport_flags & BR_FLOOD ? 1 : 0;
  266. mlxsw_sp_port->learning = brport_flags & BR_LEARNING ? 1 : 0;
  267. mlxsw_sp_port->learning_sync = brport_flags & BR_LEARNING_SYNC ? 1 : 0;
  268. return 0;
  269. err_port_learning_set:
  270. if ((uc_flood ^ brport_flags) & BR_FLOOD)
  271. mlxsw_sp_port_uc_flood_set(mlxsw_sp_port,
  272. mlxsw_sp_port->uc_flood);
  273. return err;
  274. }
  275. static int mlxsw_sp_ageing_set(struct mlxsw_sp *mlxsw_sp, u32 ageing_time)
  276. {
  277. char sfdat_pl[MLXSW_REG_SFDAT_LEN];
  278. int err;
  279. mlxsw_reg_sfdat_pack(sfdat_pl, ageing_time);
  280. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfdat), sfdat_pl);
  281. if (err)
  282. return err;
  283. mlxsw_sp->ageing_time = ageing_time;
  284. return 0;
  285. }
  286. static int mlxsw_sp_port_attr_br_ageing_set(struct mlxsw_sp_port *mlxsw_sp_port,
  287. struct switchdev_trans *trans,
  288. unsigned long ageing_clock_t)
  289. {
  290. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  291. unsigned long ageing_jiffies = clock_t_to_jiffies(ageing_clock_t);
  292. u32 ageing_time = jiffies_to_msecs(ageing_jiffies) / 1000;
  293. if (switchdev_trans_ph_prepare(trans)) {
  294. if (ageing_time < MLXSW_SP_MIN_AGEING_TIME ||
  295. ageing_time > MLXSW_SP_MAX_AGEING_TIME)
  296. return -ERANGE;
  297. else
  298. return 0;
  299. }
  300. return mlxsw_sp_ageing_set(mlxsw_sp, ageing_time);
  301. }
  302. static int mlxsw_sp_port_attr_br_vlan_set(struct mlxsw_sp_port *mlxsw_sp_port,
  303. struct switchdev_trans *trans,
  304. struct net_device *orig_dev,
  305. bool vlan_enabled)
  306. {
  307. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  308. /* SWITCHDEV_TRANS_PREPARE phase */
  309. if ((!vlan_enabled) && (mlxsw_sp->master_bridge.dev == orig_dev)) {
  310. netdev_err(mlxsw_sp_port->dev, "Bridge must be vlan-aware\n");
  311. return -EINVAL;
  312. }
  313. return 0;
  314. }
  315. static int mlxsw_sp_port_attr_set(struct net_device *dev,
  316. const struct switchdev_attr *attr,
  317. struct switchdev_trans *trans)
  318. {
  319. struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
  320. int err = 0;
  321. mlxsw_sp_port = mlxsw_sp_port_orig_get(attr->orig_dev, mlxsw_sp_port);
  322. if (!mlxsw_sp_port)
  323. return -EINVAL;
  324. switch (attr->id) {
  325. case SWITCHDEV_ATTR_ID_PORT_STP_STATE:
  326. err = mlxsw_sp_port_attr_stp_state_set(mlxsw_sp_port, trans,
  327. attr->u.stp_state);
  328. break;
  329. case SWITCHDEV_ATTR_ID_PORT_BRIDGE_FLAGS:
  330. err = mlxsw_sp_port_attr_br_flags_set(mlxsw_sp_port, trans,
  331. attr->u.brport_flags);
  332. break;
  333. case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME:
  334. err = mlxsw_sp_port_attr_br_ageing_set(mlxsw_sp_port, trans,
  335. attr->u.ageing_time);
  336. break;
  337. case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING:
  338. err = mlxsw_sp_port_attr_br_vlan_set(mlxsw_sp_port, trans,
  339. attr->orig_dev,
  340. attr->u.vlan_filtering);
  341. break;
  342. default:
  343. err = -EOPNOTSUPP;
  344. break;
  345. }
  346. return err;
  347. }
  348. static int mlxsw_sp_fid_op(struct mlxsw_sp *mlxsw_sp, u16 fid, bool create)
  349. {
  350. char sfmr_pl[MLXSW_REG_SFMR_LEN];
  351. mlxsw_reg_sfmr_pack(sfmr_pl, !create, fid, fid);
  352. return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfmr), sfmr_pl);
  353. }
  354. static int mlxsw_sp_fid_map(struct mlxsw_sp *mlxsw_sp, u16 fid, bool valid)
  355. {
  356. enum mlxsw_reg_svfa_mt mt = MLXSW_REG_SVFA_MT_VID_TO_FID;
  357. char svfa_pl[MLXSW_REG_SVFA_LEN];
  358. mlxsw_reg_svfa_pack(svfa_pl, 0, mt, valid, fid, fid);
  359. return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(svfa), svfa_pl);
  360. }
  361. static struct mlxsw_sp_fid *mlxsw_sp_fid_alloc(u16 fid)
  362. {
  363. struct mlxsw_sp_fid *f;
  364. f = kzalloc(sizeof(*f), GFP_KERNEL);
  365. if (!f)
  366. return NULL;
  367. f->fid = fid;
  368. return f;
  369. }
  370. struct mlxsw_sp_fid *mlxsw_sp_fid_create(struct mlxsw_sp *mlxsw_sp, u16 fid)
  371. {
  372. struct mlxsw_sp_fid *f;
  373. int err;
  374. err = mlxsw_sp_fid_op(mlxsw_sp, fid, true);
  375. if (err)
  376. return ERR_PTR(err);
  377. /* Although all the ports member in the FID might be using a
  378. * {Port, VID} to FID mapping, we create a global VID-to-FID
  379. * mapping. This allows a port to transition to VLAN mode,
  380. * knowing the global mapping exists.
  381. */
  382. err = mlxsw_sp_fid_map(mlxsw_sp, fid, true);
  383. if (err)
  384. goto err_fid_map;
  385. f = mlxsw_sp_fid_alloc(fid);
  386. if (!f) {
  387. err = -ENOMEM;
  388. goto err_allocate_fid;
  389. }
  390. list_add(&f->list, &mlxsw_sp->fids);
  391. return f;
  392. err_allocate_fid:
  393. mlxsw_sp_fid_map(mlxsw_sp, fid, false);
  394. err_fid_map:
  395. mlxsw_sp_fid_op(mlxsw_sp, fid, false);
  396. return ERR_PTR(err);
  397. }
  398. void mlxsw_sp_fid_destroy(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_fid *f)
  399. {
  400. u16 fid = f->fid;
  401. list_del(&f->list);
  402. if (f->r)
  403. mlxsw_sp_rif_bridge_destroy(mlxsw_sp, f->r);
  404. kfree(f);
  405. mlxsw_sp_fid_map(mlxsw_sp, fid, false);
  406. mlxsw_sp_fid_op(mlxsw_sp, fid, false);
  407. }
  408. static int __mlxsw_sp_port_fid_join(struct mlxsw_sp_port *mlxsw_sp_port,
  409. u16 fid)
  410. {
  411. struct mlxsw_sp_fid *f;
  412. if (test_bit(fid, mlxsw_sp_port->active_vlans))
  413. return 0;
  414. f = mlxsw_sp_fid_find(mlxsw_sp_port->mlxsw_sp, fid);
  415. if (!f) {
  416. f = mlxsw_sp_fid_create(mlxsw_sp_port->mlxsw_sp, fid);
  417. if (IS_ERR(f))
  418. return PTR_ERR(f);
  419. }
  420. f->ref_count++;
  421. netdev_dbg(mlxsw_sp_port->dev, "Joined FID=%d\n", fid);
  422. return 0;
  423. }
  424. static void __mlxsw_sp_port_fid_leave(struct mlxsw_sp_port *mlxsw_sp_port,
  425. u16 fid)
  426. {
  427. struct mlxsw_sp_fid *f;
  428. f = mlxsw_sp_fid_find(mlxsw_sp_port->mlxsw_sp, fid);
  429. if (WARN_ON(!f))
  430. return;
  431. netdev_dbg(mlxsw_sp_port->dev, "Left FID=%d\n", fid);
  432. mlxsw_sp_port_fdb_flush(mlxsw_sp_port, fid);
  433. if (--f->ref_count == 0)
  434. mlxsw_sp_fid_destroy(mlxsw_sp_port->mlxsw_sp, f);
  435. }
  436. static int mlxsw_sp_port_fid_map(struct mlxsw_sp_port *mlxsw_sp_port, u16 fid,
  437. bool valid)
  438. {
  439. enum mlxsw_reg_svfa_mt mt = MLXSW_REG_SVFA_MT_PORT_VID_TO_FID;
  440. /* If port doesn't have vPorts, then it can use the global
  441. * VID-to-FID mapping.
  442. */
  443. if (list_empty(&mlxsw_sp_port->vports_list))
  444. return 0;
  445. return mlxsw_sp_port_vid_to_fid_set(mlxsw_sp_port, mt, valid, fid, fid);
  446. }
  447. static int mlxsw_sp_port_fid_join(struct mlxsw_sp_port *mlxsw_sp_port,
  448. u16 fid_begin, u16 fid_end)
  449. {
  450. int fid, err;
  451. for (fid = fid_begin; fid <= fid_end; fid++) {
  452. err = __mlxsw_sp_port_fid_join(mlxsw_sp_port, fid);
  453. if (err)
  454. goto err_port_fid_join;
  455. }
  456. err = __mlxsw_sp_port_flood_set(mlxsw_sp_port, fid_begin, fid_end,
  457. mlxsw_sp_port->uc_flood, true);
  458. if (err)
  459. goto err_port_flood_set;
  460. for (fid = fid_begin; fid <= fid_end; fid++) {
  461. err = mlxsw_sp_port_fid_map(mlxsw_sp_port, fid, true);
  462. if (err)
  463. goto err_port_fid_map;
  464. }
  465. return 0;
  466. err_port_fid_map:
  467. for (fid--; fid >= fid_begin; fid--)
  468. mlxsw_sp_port_fid_map(mlxsw_sp_port, fid, false);
  469. __mlxsw_sp_port_flood_set(mlxsw_sp_port, fid_begin, fid_end, false,
  470. false);
  471. err_port_flood_set:
  472. fid = fid_end;
  473. err_port_fid_join:
  474. for (fid--; fid >= fid_begin; fid--)
  475. __mlxsw_sp_port_fid_leave(mlxsw_sp_port, fid);
  476. return err;
  477. }
  478. static void mlxsw_sp_port_fid_leave(struct mlxsw_sp_port *mlxsw_sp_port,
  479. u16 fid_begin, u16 fid_end)
  480. {
  481. int fid;
  482. for (fid = fid_begin; fid <= fid_end; fid++)
  483. mlxsw_sp_port_fid_map(mlxsw_sp_port, fid, false);
  484. __mlxsw_sp_port_flood_set(mlxsw_sp_port, fid_begin, fid_end, false,
  485. false);
  486. for (fid = fid_begin; fid <= fid_end; fid++)
  487. __mlxsw_sp_port_fid_leave(mlxsw_sp_port, fid);
  488. }
  489. static int __mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port,
  490. u16 vid)
  491. {
  492. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  493. char spvid_pl[MLXSW_REG_SPVID_LEN];
  494. mlxsw_reg_spvid_pack(spvid_pl, mlxsw_sp_port->local_port, vid);
  495. return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spvid), spvid_pl);
  496. }
  497. static int mlxsw_sp_port_allow_untagged_set(struct mlxsw_sp_port *mlxsw_sp_port,
  498. bool allow)
  499. {
  500. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  501. char spaft_pl[MLXSW_REG_SPAFT_LEN];
  502. mlxsw_reg_spaft_pack(spaft_pl, mlxsw_sp_port->local_port, allow);
  503. return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(spaft), spaft_pl);
  504. }
  505. int mlxsw_sp_port_pvid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 vid)
  506. {
  507. struct net_device *dev = mlxsw_sp_port->dev;
  508. int err;
  509. if (!vid) {
  510. err = mlxsw_sp_port_allow_untagged_set(mlxsw_sp_port, false);
  511. if (err) {
  512. netdev_err(dev, "Failed to disallow untagged traffic\n");
  513. return err;
  514. }
  515. } else {
  516. err = __mlxsw_sp_port_pvid_set(mlxsw_sp_port, vid);
  517. if (err) {
  518. netdev_err(dev, "Failed to set PVID\n");
  519. return err;
  520. }
  521. /* Only allow if not already allowed. */
  522. if (!mlxsw_sp_port->pvid) {
  523. err = mlxsw_sp_port_allow_untagged_set(mlxsw_sp_port,
  524. true);
  525. if (err) {
  526. netdev_err(dev, "Failed to allow untagged traffic\n");
  527. goto err_port_allow_untagged_set;
  528. }
  529. }
  530. }
  531. mlxsw_sp_port->pvid = vid;
  532. return 0;
  533. err_port_allow_untagged_set:
  534. __mlxsw_sp_port_pvid_set(mlxsw_sp_port, mlxsw_sp_port->pvid);
  535. return err;
  536. }
  537. static int __mlxsw_sp_port_vlans_set(struct mlxsw_sp_port *mlxsw_sp_port,
  538. u16 vid_begin, u16 vid_end, bool is_member,
  539. bool untagged)
  540. {
  541. u16 vid, vid_e;
  542. int err;
  543. for (vid = vid_begin; vid <= vid_end;
  544. vid += MLXSW_REG_SPVM_REC_MAX_COUNT) {
  545. vid_e = min((u16) (vid + MLXSW_REG_SPVM_REC_MAX_COUNT - 1),
  546. vid_end);
  547. err = mlxsw_sp_port_vlan_set(mlxsw_sp_port, vid, vid_e,
  548. is_member, untagged);
  549. if (err)
  550. return err;
  551. }
  552. return 0;
  553. }
  554. static int mlxsw_sp_port_vid_learning_set(struct mlxsw_sp_port *mlxsw_sp_port,
  555. u16 vid_begin, u16 vid_end,
  556. bool learn_enable)
  557. {
  558. u16 vid, vid_e;
  559. int err;
  560. for (vid = vid_begin; vid <= vid_end;
  561. vid += MLXSW_REG_SPVMLR_REC_MAX_COUNT) {
  562. vid_e = min((u16) (vid + MLXSW_REG_SPVMLR_REC_MAX_COUNT - 1),
  563. vid_end);
  564. err = __mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid,
  565. vid_e, learn_enable);
  566. if (err)
  567. return err;
  568. }
  569. return 0;
  570. }
  571. static int __mlxsw_sp_port_vlans_add(struct mlxsw_sp_port *mlxsw_sp_port,
  572. u16 vid_begin, u16 vid_end,
  573. bool flag_untagged, bool flag_pvid)
  574. {
  575. struct net_device *dev = mlxsw_sp_port->dev;
  576. u16 vid, old_pvid;
  577. int err;
  578. if (!mlxsw_sp_port->bridged)
  579. return -EINVAL;
  580. err = mlxsw_sp_port_fid_join(mlxsw_sp_port, vid_begin, vid_end);
  581. if (err) {
  582. netdev_err(dev, "Failed to join FIDs\n");
  583. return err;
  584. }
  585. err = __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end,
  586. true, flag_untagged);
  587. if (err) {
  588. netdev_err(dev, "Unable to add VIDs %d-%d\n", vid_begin,
  589. vid_end);
  590. goto err_port_vlans_set;
  591. }
  592. old_pvid = mlxsw_sp_port->pvid;
  593. if (flag_pvid && old_pvid != vid_begin) {
  594. err = mlxsw_sp_port_pvid_set(mlxsw_sp_port, vid_begin);
  595. if (err) {
  596. netdev_err(dev, "Unable to add PVID %d\n", vid_begin);
  597. goto err_port_pvid_set;
  598. }
  599. } else if (!flag_pvid && old_pvid >= vid_begin && old_pvid <= vid_end) {
  600. err = mlxsw_sp_port_pvid_set(mlxsw_sp_port, 0);
  601. if (err) {
  602. netdev_err(dev, "Unable to del PVID\n");
  603. goto err_port_pvid_set;
  604. }
  605. }
  606. err = mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid_begin, vid_end,
  607. mlxsw_sp_port->learning);
  608. if (err) {
  609. netdev_err(dev, "Failed to set learning for VIDs %d-%d\n",
  610. vid_begin, vid_end);
  611. goto err_port_vid_learning_set;
  612. }
  613. /* Changing activity bits only if HW operation succeded */
  614. for (vid = vid_begin; vid <= vid_end; vid++) {
  615. set_bit(vid, mlxsw_sp_port->active_vlans);
  616. if (flag_untagged)
  617. set_bit(vid, mlxsw_sp_port->untagged_vlans);
  618. else
  619. clear_bit(vid, mlxsw_sp_port->untagged_vlans);
  620. }
  621. /* STP state change must be done after we set active VLANs */
  622. err = mlxsw_sp_port_stp_state_set(mlxsw_sp_port,
  623. mlxsw_sp_port->stp_state);
  624. if (err) {
  625. netdev_err(dev, "Failed to set STP state\n");
  626. goto err_port_stp_state_set;
  627. }
  628. return 0;
  629. err_port_stp_state_set:
  630. for (vid = vid_begin; vid <= vid_end; vid++)
  631. clear_bit(vid, mlxsw_sp_port->active_vlans);
  632. mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid_begin, vid_end,
  633. false);
  634. err_port_vid_learning_set:
  635. if (old_pvid != mlxsw_sp_port->pvid)
  636. mlxsw_sp_port_pvid_set(mlxsw_sp_port, old_pvid);
  637. err_port_pvid_set:
  638. __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end, false,
  639. false);
  640. err_port_vlans_set:
  641. mlxsw_sp_port_fid_leave(mlxsw_sp_port, vid_begin, vid_end);
  642. return err;
  643. }
  644. static int mlxsw_sp_port_vlans_add(struct mlxsw_sp_port *mlxsw_sp_port,
  645. const struct switchdev_obj_port_vlan *vlan,
  646. struct switchdev_trans *trans)
  647. {
  648. bool flag_untagged = vlan->flags & BRIDGE_VLAN_INFO_UNTAGGED;
  649. bool flag_pvid = vlan->flags & BRIDGE_VLAN_INFO_PVID;
  650. if (switchdev_trans_ph_prepare(trans))
  651. return 0;
  652. return __mlxsw_sp_port_vlans_add(mlxsw_sp_port,
  653. vlan->vid_begin, vlan->vid_end,
  654. flag_untagged, flag_pvid);
  655. }
  656. static enum mlxsw_reg_sfd_rec_policy mlxsw_sp_sfd_rec_policy(bool dynamic)
  657. {
  658. return dynamic ? MLXSW_REG_SFD_REC_POLICY_DYNAMIC_ENTRY_INGRESS :
  659. MLXSW_REG_SFD_REC_POLICY_STATIC_ENTRY;
  660. }
  661. static enum mlxsw_reg_sfd_op mlxsw_sp_sfd_op(bool adding)
  662. {
  663. return adding ? MLXSW_REG_SFD_OP_WRITE_EDIT :
  664. MLXSW_REG_SFD_OP_WRITE_REMOVE;
  665. }
  666. static int __mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
  667. const char *mac, u16 fid, bool adding,
  668. enum mlxsw_reg_sfd_rec_action action,
  669. bool dynamic)
  670. {
  671. char *sfd_pl;
  672. u8 num_rec;
  673. int err;
  674. sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
  675. if (!sfd_pl)
  676. return -ENOMEM;
  677. mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
  678. mlxsw_reg_sfd_uc_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
  679. mac, fid, action, local_port);
  680. num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
  681. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
  682. if (err)
  683. goto out;
  684. if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
  685. err = -EBUSY;
  686. out:
  687. kfree(sfd_pl);
  688. return err;
  689. }
  690. static int mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
  691. const char *mac, u16 fid, bool adding,
  692. bool dynamic)
  693. {
  694. return __mlxsw_sp_port_fdb_uc_op(mlxsw_sp, local_port, mac, fid, adding,
  695. MLXSW_REG_SFD_REC_ACTION_NOP, dynamic);
  696. }
  697. int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
  698. bool adding)
  699. {
  700. return __mlxsw_sp_port_fdb_uc_op(mlxsw_sp, 0, mac, fid, adding,
  701. MLXSW_REG_SFD_REC_ACTION_FORWARD_IP_ROUTER,
  702. false);
  703. }
  704. static int mlxsw_sp_port_fdb_uc_lag_op(struct mlxsw_sp *mlxsw_sp, u16 lag_id,
  705. const char *mac, u16 fid, u16 lag_vid,
  706. bool adding, bool dynamic)
  707. {
  708. char *sfd_pl;
  709. u8 num_rec;
  710. int err;
  711. sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
  712. if (!sfd_pl)
  713. return -ENOMEM;
  714. mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
  715. mlxsw_reg_sfd_uc_lag_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
  716. mac, fid, MLXSW_REG_SFD_REC_ACTION_NOP,
  717. lag_vid, lag_id);
  718. num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
  719. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
  720. if (err)
  721. goto out;
  722. if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
  723. err = -EBUSY;
  724. out:
  725. kfree(sfd_pl);
  726. return err;
  727. }
  728. static int
  729. mlxsw_sp_port_fdb_static_add(struct mlxsw_sp_port *mlxsw_sp_port,
  730. const struct switchdev_obj_port_fdb *fdb,
  731. struct switchdev_trans *trans)
  732. {
  733. u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, fdb->vid);
  734. u16 lag_vid = 0;
  735. if (switchdev_trans_ph_prepare(trans))
  736. return 0;
  737. if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
  738. lag_vid = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
  739. }
  740. if (!mlxsw_sp_port->lagged)
  741. return mlxsw_sp_port_fdb_uc_op(mlxsw_sp_port->mlxsw_sp,
  742. mlxsw_sp_port->local_port,
  743. fdb->addr, fid, true, false);
  744. else
  745. return mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp_port->mlxsw_sp,
  746. mlxsw_sp_port->lag_id,
  747. fdb->addr, fid, lag_vid,
  748. true, false);
  749. }
  750. static int mlxsw_sp_port_mdb_op(struct mlxsw_sp *mlxsw_sp, const char *addr,
  751. u16 fid, u16 mid, bool adding)
  752. {
  753. char *sfd_pl;
  754. u8 num_rec;
  755. int err;
  756. sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
  757. if (!sfd_pl)
  758. return -ENOMEM;
  759. mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
  760. mlxsw_reg_sfd_mc_pack(sfd_pl, 0, addr, fid,
  761. MLXSW_REG_SFD_REC_ACTION_NOP, mid);
  762. num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
  763. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
  764. if (err)
  765. goto out;
  766. if (num_rec != mlxsw_reg_sfd_num_rec_get(sfd_pl))
  767. err = -EBUSY;
  768. out:
  769. kfree(sfd_pl);
  770. return err;
  771. }
  772. static int mlxsw_sp_port_smid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 mid,
  773. bool add, bool clear_all_ports)
  774. {
  775. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  776. char *smid_pl;
  777. int err, i;
  778. smid_pl = kmalloc(MLXSW_REG_SMID_LEN, GFP_KERNEL);
  779. if (!smid_pl)
  780. return -ENOMEM;
  781. mlxsw_reg_smid_pack(smid_pl, mid, mlxsw_sp_port->local_port, add);
  782. if (clear_all_ports) {
  783. for (i = 1; i < MLXSW_PORT_MAX_PORTS; i++)
  784. if (mlxsw_sp->ports[i])
  785. mlxsw_reg_smid_port_mask_set(smid_pl, i, 1);
  786. }
  787. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(smid), smid_pl);
  788. kfree(smid_pl);
  789. return err;
  790. }
  791. static struct mlxsw_sp_mid *__mlxsw_sp_mc_get(struct mlxsw_sp *mlxsw_sp,
  792. const unsigned char *addr,
  793. u16 fid)
  794. {
  795. struct mlxsw_sp_mid *mid;
  796. list_for_each_entry(mid, &mlxsw_sp->br_mids.list, list) {
  797. if (ether_addr_equal(mid->addr, addr) && mid->fid == fid)
  798. return mid;
  799. }
  800. return NULL;
  801. }
  802. static struct mlxsw_sp_mid *__mlxsw_sp_mc_alloc(struct mlxsw_sp *mlxsw_sp,
  803. const unsigned char *addr,
  804. u16 fid)
  805. {
  806. struct mlxsw_sp_mid *mid;
  807. u16 mid_idx;
  808. mid_idx = find_first_zero_bit(mlxsw_sp->br_mids.mapped,
  809. MLXSW_SP_MID_MAX);
  810. if (mid_idx == MLXSW_SP_MID_MAX)
  811. return NULL;
  812. mid = kzalloc(sizeof(*mid), GFP_KERNEL);
  813. if (!mid)
  814. return NULL;
  815. set_bit(mid_idx, mlxsw_sp->br_mids.mapped);
  816. ether_addr_copy(mid->addr, addr);
  817. mid->fid = fid;
  818. mid->mid = mid_idx;
  819. mid->ref_count = 0;
  820. list_add_tail(&mid->list, &mlxsw_sp->br_mids.list);
  821. return mid;
  822. }
  823. static int __mlxsw_sp_mc_dec_ref(struct mlxsw_sp *mlxsw_sp,
  824. struct mlxsw_sp_mid *mid)
  825. {
  826. if (--mid->ref_count == 0) {
  827. list_del(&mid->list);
  828. clear_bit(mid->mid, mlxsw_sp->br_mids.mapped);
  829. kfree(mid);
  830. return 1;
  831. }
  832. return 0;
  833. }
  834. static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,
  835. const struct switchdev_obj_port_mdb *mdb,
  836. struct switchdev_trans *trans)
  837. {
  838. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  839. struct net_device *dev = mlxsw_sp_port->dev;
  840. struct mlxsw_sp_mid *mid;
  841. u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, mdb->vid);
  842. int err = 0;
  843. if (switchdev_trans_ph_prepare(trans))
  844. return 0;
  845. mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, fid);
  846. if (!mid) {
  847. mid = __mlxsw_sp_mc_alloc(mlxsw_sp, mdb->addr, fid);
  848. if (!mid) {
  849. netdev_err(dev, "Unable to allocate MC group\n");
  850. return -ENOMEM;
  851. }
  852. }
  853. mid->ref_count++;
  854. err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, true,
  855. mid->ref_count == 1);
  856. if (err) {
  857. netdev_err(dev, "Unable to set SMID\n");
  858. goto err_out;
  859. }
  860. if (mid->ref_count == 1) {
  861. err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid, mid->mid,
  862. true);
  863. if (err) {
  864. netdev_err(dev, "Unable to set MC SFD\n");
  865. goto err_out;
  866. }
  867. }
  868. return 0;
  869. err_out:
  870. __mlxsw_sp_mc_dec_ref(mlxsw_sp, mid);
  871. return err;
  872. }
  873. static int mlxsw_sp_port_obj_add(struct net_device *dev,
  874. const struct switchdev_obj *obj,
  875. struct switchdev_trans *trans)
  876. {
  877. struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
  878. int err = 0;
  879. mlxsw_sp_port = mlxsw_sp_port_orig_get(obj->orig_dev, mlxsw_sp_port);
  880. if (!mlxsw_sp_port)
  881. return -EINVAL;
  882. switch (obj->id) {
  883. case SWITCHDEV_OBJ_ID_PORT_VLAN:
  884. if (mlxsw_sp_port_is_vport(mlxsw_sp_port))
  885. return 0;
  886. err = mlxsw_sp_port_vlans_add(mlxsw_sp_port,
  887. SWITCHDEV_OBJ_PORT_VLAN(obj),
  888. trans);
  889. break;
  890. case SWITCHDEV_OBJ_ID_PORT_FDB:
  891. err = mlxsw_sp_port_fdb_static_add(mlxsw_sp_port,
  892. SWITCHDEV_OBJ_PORT_FDB(obj),
  893. trans);
  894. break;
  895. case SWITCHDEV_OBJ_ID_PORT_MDB:
  896. err = mlxsw_sp_port_mdb_add(mlxsw_sp_port,
  897. SWITCHDEV_OBJ_PORT_MDB(obj),
  898. trans);
  899. break;
  900. default:
  901. err = -EOPNOTSUPP;
  902. break;
  903. }
  904. return err;
  905. }
  906. static int __mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
  907. u16 vid_begin, u16 vid_end)
  908. {
  909. u16 vid, pvid;
  910. if (!mlxsw_sp_port->bridged)
  911. return -EINVAL;
  912. mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid_begin, vid_end,
  913. false);
  914. pvid = mlxsw_sp_port->pvid;
  915. if (pvid >= vid_begin && pvid <= vid_end)
  916. mlxsw_sp_port_pvid_set(mlxsw_sp_port, 0);
  917. __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end, false,
  918. false);
  919. mlxsw_sp_port_fid_leave(mlxsw_sp_port, vid_begin, vid_end);
  920. /* Changing activity bits only if HW operation succeded */
  921. for (vid = vid_begin; vid <= vid_end; vid++)
  922. clear_bit(vid, mlxsw_sp_port->active_vlans);
  923. return 0;
  924. }
  925. static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
  926. const struct switchdev_obj_port_vlan *vlan)
  927. {
  928. return __mlxsw_sp_port_vlans_del(mlxsw_sp_port, vlan->vid_begin,
  929. vlan->vid_end);
  930. }
  931. void mlxsw_sp_port_active_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port)
  932. {
  933. u16 vid;
  934. for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID)
  935. __mlxsw_sp_port_vlans_del(mlxsw_sp_port, vid, vid);
  936. }
  937. static int
  938. mlxsw_sp_port_fdb_static_del(struct mlxsw_sp_port *mlxsw_sp_port,
  939. const struct switchdev_obj_port_fdb *fdb)
  940. {
  941. u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, fdb->vid);
  942. u16 lag_vid = 0;
  943. if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
  944. lag_vid = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
  945. }
  946. if (!mlxsw_sp_port->lagged)
  947. return mlxsw_sp_port_fdb_uc_op(mlxsw_sp_port->mlxsw_sp,
  948. mlxsw_sp_port->local_port,
  949. fdb->addr, fid,
  950. false, false);
  951. else
  952. return mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp_port->mlxsw_sp,
  953. mlxsw_sp_port->lag_id,
  954. fdb->addr, fid, lag_vid,
  955. false, false);
  956. }
  957. static int mlxsw_sp_port_mdb_del(struct mlxsw_sp_port *mlxsw_sp_port,
  958. const struct switchdev_obj_port_mdb *mdb)
  959. {
  960. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  961. struct net_device *dev = mlxsw_sp_port->dev;
  962. struct mlxsw_sp_mid *mid;
  963. u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, mdb->vid);
  964. u16 mid_idx;
  965. int err = 0;
  966. mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, fid);
  967. if (!mid) {
  968. netdev_err(dev, "Unable to remove port from MC DB\n");
  969. return -EINVAL;
  970. }
  971. err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, false, false);
  972. if (err)
  973. netdev_err(dev, "Unable to remove port from SMID\n");
  974. mid_idx = mid->mid;
  975. if (__mlxsw_sp_mc_dec_ref(mlxsw_sp, mid)) {
  976. err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid, mid_idx,
  977. false);
  978. if (err)
  979. netdev_err(dev, "Unable to remove MC SFD\n");
  980. }
  981. return err;
  982. }
  983. static int mlxsw_sp_port_obj_del(struct net_device *dev,
  984. const struct switchdev_obj *obj)
  985. {
  986. struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
  987. int err = 0;
  988. mlxsw_sp_port = mlxsw_sp_port_orig_get(obj->orig_dev, mlxsw_sp_port);
  989. if (!mlxsw_sp_port)
  990. return -EINVAL;
  991. switch (obj->id) {
  992. case SWITCHDEV_OBJ_ID_PORT_VLAN:
  993. if (mlxsw_sp_port_is_vport(mlxsw_sp_port))
  994. return 0;
  995. err = mlxsw_sp_port_vlans_del(mlxsw_sp_port,
  996. SWITCHDEV_OBJ_PORT_VLAN(obj));
  997. break;
  998. case SWITCHDEV_OBJ_ID_PORT_FDB:
  999. err = mlxsw_sp_port_fdb_static_del(mlxsw_sp_port,
  1000. SWITCHDEV_OBJ_PORT_FDB(obj));
  1001. break;
  1002. case SWITCHDEV_OBJ_ID_PORT_MDB:
  1003. err = mlxsw_sp_port_mdb_del(mlxsw_sp_port,
  1004. SWITCHDEV_OBJ_PORT_MDB(obj));
  1005. break;
  1006. default:
  1007. err = -EOPNOTSUPP;
  1008. break;
  1009. }
  1010. return err;
  1011. }
  1012. static struct mlxsw_sp_port *mlxsw_sp_lag_rep_port(struct mlxsw_sp *mlxsw_sp,
  1013. u16 lag_id)
  1014. {
  1015. struct mlxsw_sp_port *mlxsw_sp_port;
  1016. struct mlxsw_resources *resources;
  1017. int i;
  1018. resources = mlxsw_core_resources_get(mlxsw_sp->core);
  1019. for (i = 0; i < resources->max_ports_in_lag; i++) {
  1020. mlxsw_sp_port = mlxsw_sp_port_lagged_get(mlxsw_sp, lag_id, i);
  1021. if (mlxsw_sp_port)
  1022. return mlxsw_sp_port;
  1023. }
  1024. return NULL;
  1025. }
  1026. static int mlxsw_sp_port_fdb_dump(struct mlxsw_sp_port *mlxsw_sp_port,
  1027. struct switchdev_obj_port_fdb *fdb,
  1028. switchdev_obj_dump_cb_t *cb,
  1029. struct net_device *orig_dev)
  1030. {
  1031. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  1032. struct mlxsw_sp_port *tmp;
  1033. struct mlxsw_sp_fid *f;
  1034. u16 vport_fid;
  1035. char *sfd_pl;
  1036. char mac[ETH_ALEN];
  1037. u16 fid;
  1038. u8 local_port;
  1039. u16 lag_id;
  1040. u8 num_rec;
  1041. int stored_err = 0;
  1042. int i;
  1043. int err;
  1044. sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
  1045. if (!sfd_pl)
  1046. return -ENOMEM;
  1047. f = mlxsw_sp_vport_fid_get(mlxsw_sp_port);
  1048. vport_fid = f ? f->fid : 0;
  1049. mlxsw_reg_sfd_pack(sfd_pl, MLXSW_REG_SFD_OP_QUERY_DUMP, 0);
  1050. do {
  1051. mlxsw_reg_sfd_num_rec_set(sfd_pl, MLXSW_REG_SFD_REC_MAX_COUNT);
  1052. err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
  1053. if (err)
  1054. goto out;
  1055. num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
  1056. /* Even in case of error, we have to run the dump to the end
  1057. * so the session in firmware is finished.
  1058. */
  1059. if (stored_err)
  1060. continue;
  1061. for (i = 0; i < num_rec; i++) {
  1062. switch (mlxsw_reg_sfd_rec_type_get(sfd_pl, i)) {
  1063. case MLXSW_REG_SFD_REC_TYPE_UNICAST:
  1064. mlxsw_reg_sfd_uc_unpack(sfd_pl, i, mac, &fid,
  1065. &local_port);
  1066. if (local_port == mlxsw_sp_port->local_port) {
  1067. if (vport_fid && vport_fid == fid)
  1068. fdb->vid = 0;
  1069. else if (!vport_fid &&
  1070. !mlxsw_sp_fid_is_vfid(fid))
  1071. fdb->vid = fid;
  1072. else
  1073. continue;
  1074. ether_addr_copy(fdb->addr, mac);
  1075. fdb->ndm_state = NUD_REACHABLE;
  1076. err = cb(&fdb->obj);
  1077. if (err)
  1078. stored_err = err;
  1079. }
  1080. break;
  1081. case MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG:
  1082. mlxsw_reg_sfd_uc_lag_unpack(sfd_pl, i,
  1083. mac, &fid, &lag_id);
  1084. tmp = mlxsw_sp_lag_rep_port(mlxsw_sp, lag_id);
  1085. if (tmp && tmp->local_port ==
  1086. mlxsw_sp_port->local_port) {
  1087. /* LAG records can only point to LAG
  1088. * devices or VLAN devices on top.
  1089. */
  1090. if (!netif_is_lag_master(orig_dev) &&
  1091. !is_vlan_dev(orig_dev))
  1092. continue;
  1093. if (vport_fid && vport_fid == fid)
  1094. fdb->vid = 0;
  1095. else if (!vport_fid &&
  1096. !mlxsw_sp_fid_is_vfid(fid))
  1097. fdb->vid = fid;
  1098. else
  1099. continue;
  1100. ether_addr_copy(fdb->addr, mac);
  1101. fdb->ndm_state = NUD_REACHABLE;
  1102. err = cb(&fdb->obj);
  1103. if (err)
  1104. stored_err = err;
  1105. }
  1106. break;
  1107. }
  1108. }
  1109. } while (num_rec == MLXSW_REG_SFD_REC_MAX_COUNT);
  1110. out:
  1111. kfree(sfd_pl);
  1112. return stored_err ? stored_err : err;
  1113. }
  1114. static int mlxsw_sp_port_vlan_dump(struct mlxsw_sp_port *mlxsw_sp_port,
  1115. struct switchdev_obj_port_vlan *vlan,
  1116. switchdev_obj_dump_cb_t *cb)
  1117. {
  1118. u16 vid;
  1119. int err = 0;
  1120. if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
  1121. vlan->flags = 0;
  1122. vlan->vid_begin = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
  1123. vlan->vid_end = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
  1124. return cb(&vlan->obj);
  1125. }
  1126. for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID) {
  1127. vlan->flags = 0;
  1128. if (vid == mlxsw_sp_port->pvid)
  1129. vlan->flags |= BRIDGE_VLAN_INFO_PVID;
  1130. if (test_bit(vid, mlxsw_sp_port->untagged_vlans))
  1131. vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
  1132. vlan->vid_begin = vid;
  1133. vlan->vid_end = vid;
  1134. err = cb(&vlan->obj);
  1135. if (err)
  1136. break;
  1137. }
  1138. return err;
  1139. }
  1140. static int mlxsw_sp_port_obj_dump(struct net_device *dev,
  1141. struct switchdev_obj *obj,
  1142. switchdev_obj_dump_cb_t *cb)
  1143. {
  1144. struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
  1145. int err = 0;
  1146. mlxsw_sp_port = mlxsw_sp_port_orig_get(obj->orig_dev, mlxsw_sp_port);
  1147. if (!mlxsw_sp_port)
  1148. return -EINVAL;
  1149. switch (obj->id) {
  1150. case SWITCHDEV_OBJ_ID_PORT_VLAN:
  1151. err = mlxsw_sp_port_vlan_dump(mlxsw_sp_port,
  1152. SWITCHDEV_OBJ_PORT_VLAN(obj), cb);
  1153. break;
  1154. case SWITCHDEV_OBJ_ID_PORT_FDB:
  1155. err = mlxsw_sp_port_fdb_dump(mlxsw_sp_port,
  1156. SWITCHDEV_OBJ_PORT_FDB(obj), cb,
  1157. obj->orig_dev);
  1158. break;
  1159. default:
  1160. err = -EOPNOTSUPP;
  1161. break;
  1162. }
  1163. return err;
  1164. }
  1165. static const struct switchdev_ops mlxsw_sp_port_switchdev_ops = {
  1166. .switchdev_port_attr_get = mlxsw_sp_port_attr_get,
  1167. .switchdev_port_attr_set = mlxsw_sp_port_attr_set,
  1168. .switchdev_port_obj_add = mlxsw_sp_port_obj_add,
  1169. .switchdev_port_obj_del = mlxsw_sp_port_obj_del,
  1170. .switchdev_port_obj_dump = mlxsw_sp_port_obj_dump,
  1171. };
  1172. static void mlxsw_sp_fdb_call_notifiers(bool learning_sync, bool adding,
  1173. char *mac, u16 vid,
  1174. struct net_device *dev)
  1175. {
  1176. struct switchdev_notifier_fdb_info info;
  1177. unsigned long notifier_type;
  1178. if (learning_sync) {
  1179. info.addr = mac;
  1180. info.vid = vid;
  1181. notifier_type = adding ? SWITCHDEV_FDB_ADD : SWITCHDEV_FDB_DEL;
  1182. call_switchdev_notifiers(notifier_type, dev, &info.info);
  1183. }
  1184. }
  1185. static void mlxsw_sp_fdb_notify_mac_process(struct mlxsw_sp *mlxsw_sp,
  1186. char *sfn_pl, int rec_index,
  1187. bool adding)
  1188. {
  1189. struct mlxsw_sp_port *mlxsw_sp_port;
  1190. char mac[ETH_ALEN];
  1191. u8 local_port;
  1192. u16 vid, fid;
  1193. bool do_notification = true;
  1194. int err;
  1195. mlxsw_reg_sfn_mac_unpack(sfn_pl, rec_index, mac, &fid, &local_port);
  1196. mlxsw_sp_port = mlxsw_sp->ports[local_port];
  1197. if (!mlxsw_sp_port) {
  1198. dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Incorrect local port in FDB notification\n");
  1199. goto just_remove;
  1200. }
  1201. if (mlxsw_sp_fid_is_vfid(fid)) {
  1202. struct mlxsw_sp_port *mlxsw_sp_vport;
  1203. mlxsw_sp_vport = mlxsw_sp_port_vport_find_by_fid(mlxsw_sp_port,
  1204. fid);
  1205. if (!mlxsw_sp_vport) {
  1206. netdev_err(mlxsw_sp_port->dev, "Failed to find a matching vPort following FDB notification\n");
  1207. goto just_remove;
  1208. }
  1209. vid = 0;
  1210. /* Override the physical port with the vPort. */
  1211. mlxsw_sp_port = mlxsw_sp_vport;
  1212. } else {
  1213. vid = fid;
  1214. }
  1215. do_fdb_op:
  1216. err = mlxsw_sp_port_fdb_uc_op(mlxsw_sp, local_port, mac, fid,
  1217. adding, true);
  1218. if (err) {
  1219. dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to set FDB entry\n");
  1220. return;
  1221. }
  1222. if (!do_notification)
  1223. return;
  1224. mlxsw_sp_fdb_call_notifiers(mlxsw_sp_port->learning_sync,
  1225. adding, mac, vid, mlxsw_sp_port->dev);
  1226. return;
  1227. just_remove:
  1228. adding = false;
  1229. do_notification = false;
  1230. goto do_fdb_op;
  1231. }
  1232. static void mlxsw_sp_fdb_notify_mac_lag_process(struct mlxsw_sp *mlxsw_sp,
  1233. char *sfn_pl, int rec_index,
  1234. bool adding)
  1235. {
  1236. struct mlxsw_sp_port *mlxsw_sp_port;
  1237. struct net_device *dev;
  1238. char mac[ETH_ALEN];
  1239. u16 lag_vid = 0;
  1240. u16 lag_id;
  1241. u16 vid, fid;
  1242. bool do_notification = true;
  1243. int err;
  1244. mlxsw_reg_sfn_mac_lag_unpack(sfn_pl, rec_index, mac, &fid, &lag_id);
  1245. mlxsw_sp_port = mlxsw_sp_lag_rep_port(mlxsw_sp, lag_id);
  1246. if (!mlxsw_sp_port) {
  1247. dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Cannot find port representor for LAG\n");
  1248. goto just_remove;
  1249. }
  1250. if (mlxsw_sp_fid_is_vfid(fid)) {
  1251. struct mlxsw_sp_port *mlxsw_sp_vport;
  1252. mlxsw_sp_vport = mlxsw_sp_port_vport_find_by_fid(mlxsw_sp_port,
  1253. fid);
  1254. if (!mlxsw_sp_vport) {
  1255. netdev_err(mlxsw_sp_port->dev, "Failed to find a matching vPort following FDB notification\n");
  1256. goto just_remove;
  1257. }
  1258. lag_vid = mlxsw_sp_vport_vid_get(mlxsw_sp_vport);
  1259. dev = mlxsw_sp_vport->dev;
  1260. vid = 0;
  1261. /* Override the physical port with the vPort. */
  1262. mlxsw_sp_port = mlxsw_sp_vport;
  1263. } else {
  1264. dev = mlxsw_sp_lag_get(mlxsw_sp, lag_id)->dev;
  1265. vid = fid;
  1266. }
  1267. do_fdb_op:
  1268. err = mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp, lag_id, mac, fid, lag_vid,
  1269. adding, true);
  1270. if (err) {
  1271. dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to set FDB entry\n");
  1272. return;
  1273. }
  1274. if (!do_notification)
  1275. return;
  1276. mlxsw_sp_fdb_call_notifiers(mlxsw_sp_port->learning_sync, adding, mac,
  1277. vid, dev);
  1278. return;
  1279. just_remove:
  1280. adding = false;
  1281. do_notification = false;
  1282. goto do_fdb_op;
  1283. }
  1284. static void mlxsw_sp_fdb_notify_rec_process(struct mlxsw_sp *mlxsw_sp,
  1285. char *sfn_pl, int rec_index)
  1286. {
  1287. switch (mlxsw_reg_sfn_rec_type_get(sfn_pl, rec_index)) {
  1288. case MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC:
  1289. mlxsw_sp_fdb_notify_mac_process(mlxsw_sp, sfn_pl,
  1290. rec_index, true);
  1291. break;
  1292. case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC:
  1293. mlxsw_sp_fdb_notify_mac_process(mlxsw_sp, sfn_pl,
  1294. rec_index, false);
  1295. break;
  1296. case MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC_LAG:
  1297. mlxsw_sp_fdb_notify_mac_lag_process(mlxsw_sp, sfn_pl,
  1298. rec_index, true);
  1299. break;
  1300. case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC_LAG:
  1301. mlxsw_sp_fdb_notify_mac_lag_process(mlxsw_sp, sfn_pl,
  1302. rec_index, false);
  1303. break;
  1304. }
  1305. }
  1306. static void mlxsw_sp_fdb_notify_work_schedule(struct mlxsw_sp *mlxsw_sp)
  1307. {
  1308. mlxsw_core_schedule_dw(&mlxsw_sp->fdb_notify.dw,
  1309. msecs_to_jiffies(mlxsw_sp->fdb_notify.interval));
  1310. }
  1311. static void mlxsw_sp_fdb_notify_work(struct work_struct *work)
  1312. {
  1313. struct mlxsw_sp *mlxsw_sp;
  1314. char *sfn_pl;
  1315. u8 num_rec;
  1316. int i;
  1317. int err;
  1318. sfn_pl = kmalloc(MLXSW_REG_SFN_LEN, GFP_KERNEL);
  1319. if (!sfn_pl)
  1320. return;
  1321. mlxsw_sp = container_of(work, struct mlxsw_sp, fdb_notify.dw.work);
  1322. rtnl_lock();
  1323. mlxsw_reg_sfn_pack(sfn_pl);
  1324. err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(sfn), sfn_pl);
  1325. if (err) {
  1326. dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to get FDB notifications\n");
  1327. goto out;
  1328. }
  1329. num_rec = mlxsw_reg_sfn_num_rec_get(sfn_pl);
  1330. for (i = 0; i < num_rec; i++)
  1331. mlxsw_sp_fdb_notify_rec_process(mlxsw_sp, sfn_pl, i);
  1332. out:
  1333. rtnl_unlock();
  1334. kfree(sfn_pl);
  1335. mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp);
  1336. }
  1337. static int mlxsw_sp_fdb_init(struct mlxsw_sp *mlxsw_sp)
  1338. {
  1339. int err;
  1340. err = mlxsw_sp_ageing_set(mlxsw_sp, MLXSW_SP_DEFAULT_AGEING_TIME);
  1341. if (err) {
  1342. dev_err(mlxsw_sp->bus_info->dev, "Failed to set default ageing time\n");
  1343. return err;
  1344. }
  1345. INIT_DELAYED_WORK(&mlxsw_sp->fdb_notify.dw, mlxsw_sp_fdb_notify_work);
  1346. mlxsw_sp->fdb_notify.interval = MLXSW_SP_DEFAULT_LEARNING_INTERVAL;
  1347. mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp);
  1348. return 0;
  1349. }
  1350. static void mlxsw_sp_fdb_fini(struct mlxsw_sp *mlxsw_sp)
  1351. {
  1352. cancel_delayed_work_sync(&mlxsw_sp->fdb_notify.dw);
  1353. }
  1354. int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp)
  1355. {
  1356. return mlxsw_sp_fdb_init(mlxsw_sp);
  1357. }
  1358. void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp)
  1359. {
  1360. mlxsw_sp_fdb_fini(mlxsw_sp);
  1361. }
  1362. void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port)
  1363. {
  1364. mlxsw_sp_port->dev->switchdev_ops = &mlxsw_sp_port_switchdev_ops;
  1365. }
  1366. void mlxsw_sp_port_switchdev_fini(struct mlxsw_sp_port *mlxsw_sp_port)
  1367. {
  1368. }