spectrum_switchdev.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610
  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. int err;
  673. sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
  674. if (!sfd_pl)
  675. return -ENOMEM;
  676. mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
  677. mlxsw_reg_sfd_uc_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
  678. mac, fid, action, local_port);
  679. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
  680. kfree(sfd_pl);
  681. return err;
  682. }
  683. static int mlxsw_sp_port_fdb_uc_op(struct mlxsw_sp *mlxsw_sp, u8 local_port,
  684. const char *mac, u16 fid, bool adding,
  685. bool dynamic)
  686. {
  687. return __mlxsw_sp_port_fdb_uc_op(mlxsw_sp, local_port, mac, fid, adding,
  688. MLXSW_REG_SFD_REC_ACTION_NOP, dynamic);
  689. }
  690. int mlxsw_sp_rif_fdb_op(struct mlxsw_sp *mlxsw_sp, const char *mac, u16 fid,
  691. bool adding)
  692. {
  693. return __mlxsw_sp_port_fdb_uc_op(mlxsw_sp, 0, mac, fid, adding,
  694. MLXSW_REG_SFD_REC_ACTION_FORWARD_IP_ROUTER,
  695. false);
  696. }
  697. static int mlxsw_sp_port_fdb_uc_lag_op(struct mlxsw_sp *mlxsw_sp, u16 lag_id,
  698. const char *mac, u16 fid, u16 lag_vid,
  699. bool adding, bool dynamic)
  700. {
  701. char *sfd_pl;
  702. int err;
  703. sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
  704. if (!sfd_pl)
  705. return -ENOMEM;
  706. mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
  707. mlxsw_reg_sfd_uc_lag_pack(sfd_pl, 0, mlxsw_sp_sfd_rec_policy(dynamic),
  708. mac, fid, MLXSW_REG_SFD_REC_ACTION_NOP,
  709. lag_vid, lag_id);
  710. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
  711. kfree(sfd_pl);
  712. return err;
  713. }
  714. static int
  715. mlxsw_sp_port_fdb_static_add(struct mlxsw_sp_port *mlxsw_sp_port,
  716. const struct switchdev_obj_port_fdb *fdb,
  717. struct switchdev_trans *trans)
  718. {
  719. u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, fdb->vid);
  720. u16 lag_vid = 0;
  721. if (switchdev_trans_ph_prepare(trans))
  722. return 0;
  723. if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
  724. lag_vid = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
  725. }
  726. if (!mlxsw_sp_port->lagged)
  727. return mlxsw_sp_port_fdb_uc_op(mlxsw_sp_port->mlxsw_sp,
  728. mlxsw_sp_port->local_port,
  729. fdb->addr, fid, true, false);
  730. else
  731. return mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp_port->mlxsw_sp,
  732. mlxsw_sp_port->lag_id,
  733. fdb->addr, fid, lag_vid,
  734. true, false);
  735. }
  736. static int mlxsw_sp_port_mdb_op(struct mlxsw_sp *mlxsw_sp, const char *addr,
  737. u16 fid, u16 mid, bool adding)
  738. {
  739. char *sfd_pl;
  740. int err;
  741. sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
  742. if (!sfd_pl)
  743. return -ENOMEM;
  744. mlxsw_reg_sfd_pack(sfd_pl, mlxsw_sp_sfd_op(adding), 0);
  745. mlxsw_reg_sfd_mc_pack(sfd_pl, 0, addr, fid,
  746. MLXSW_REG_SFD_REC_ACTION_NOP, mid);
  747. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
  748. kfree(sfd_pl);
  749. return err;
  750. }
  751. static int mlxsw_sp_port_smid_set(struct mlxsw_sp_port *mlxsw_sp_port, u16 mid,
  752. bool add, bool clear_all_ports)
  753. {
  754. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  755. char *smid_pl;
  756. int err, i;
  757. smid_pl = kmalloc(MLXSW_REG_SMID_LEN, GFP_KERNEL);
  758. if (!smid_pl)
  759. return -ENOMEM;
  760. mlxsw_reg_smid_pack(smid_pl, mid, mlxsw_sp_port->local_port, add);
  761. if (clear_all_ports) {
  762. for (i = 1; i < MLXSW_PORT_MAX_PORTS; i++)
  763. if (mlxsw_sp->ports[i])
  764. mlxsw_reg_smid_port_mask_set(smid_pl, i, 1);
  765. }
  766. err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(smid), smid_pl);
  767. kfree(smid_pl);
  768. return err;
  769. }
  770. static struct mlxsw_sp_mid *__mlxsw_sp_mc_get(struct mlxsw_sp *mlxsw_sp,
  771. const unsigned char *addr,
  772. u16 vid)
  773. {
  774. struct mlxsw_sp_mid *mid;
  775. list_for_each_entry(mid, &mlxsw_sp->br_mids.list, list) {
  776. if (ether_addr_equal(mid->addr, addr) && mid->vid == vid)
  777. return mid;
  778. }
  779. return NULL;
  780. }
  781. static struct mlxsw_sp_mid *__mlxsw_sp_mc_alloc(struct mlxsw_sp *mlxsw_sp,
  782. const unsigned char *addr,
  783. u16 vid)
  784. {
  785. struct mlxsw_sp_mid *mid;
  786. u16 mid_idx;
  787. mid_idx = find_first_zero_bit(mlxsw_sp->br_mids.mapped,
  788. MLXSW_SP_MID_MAX);
  789. if (mid_idx == MLXSW_SP_MID_MAX)
  790. return NULL;
  791. mid = kzalloc(sizeof(*mid), GFP_KERNEL);
  792. if (!mid)
  793. return NULL;
  794. set_bit(mid_idx, mlxsw_sp->br_mids.mapped);
  795. ether_addr_copy(mid->addr, addr);
  796. mid->vid = vid;
  797. mid->mid = mid_idx;
  798. mid->ref_count = 0;
  799. list_add_tail(&mid->list, &mlxsw_sp->br_mids.list);
  800. return mid;
  801. }
  802. static int __mlxsw_sp_mc_dec_ref(struct mlxsw_sp *mlxsw_sp,
  803. struct mlxsw_sp_mid *mid)
  804. {
  805. if (--mid->ref_count == 0) {
  806. list_del(&mid->list);
  807. clear_bit(mid->mid, mlxsw_sp->br_mids.mapped);
  808. kfree(mid);
  809. return 1;
  810. }
  811. return 0;
  812. }
  813. static int mlxsw_sp_port_mdb_add(struct mlxsw_sp_port *mlxsw_sp_port,
  814. const struct switchdev_obj_port_mdb *mdb,
  815. struct switchdev_trans *trans)
  816. {
  817. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  818. struct net_device *dev = mlxsw_sp_port->dev;
  819. struct mlxsw_sp_mid *mid;
  820. u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, mdb->vid);
  821. int err = 0;
  822. if (switchdev_trans_ph_prepare(trans))
  823. return 0;
  824. mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, mdb->vid);
  825. if (!mid) {
  826. mid = __mlxsw_sp_mc_alloc(mlxsw_sp, mdb->addr, mdb->vid);
  827. if (!mid) {
  828. netdev_err(dev, "Unable to allocate MC group\n");
  829. return -ENOMEM;
  830. }
  831. }
  832. mid->ref_count++;
  833. err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, true,
  834. mid->ref_count == 1);
  835. if (err) {
  836. netdev_err(dev, "Unable to set SMID\n");
  837. goto err_out;
  838. }
  839. if (mid->ref_count == 1) {
  840. err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid, mid->mid,
  841. true);
  842. if (err) {
  843. netdev_err(dev, "Unable to set MC SFD\n");
  844. goto err_out;
  845. }
  846. }
  847. return 0;
  848. err_out:
  849. __mlxsw_sp_mc_dec_ref(mlxsw_sp, mid);
  850. return err;
  851. }
  852. static int mlxsw_sp_port_obj_add(struct net_device *dev,
  853. const struct switchdev_obj *obj,
  854. struct switchdev_trans *trans)
  855. {
  856. struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
  857. int err = 0;
  858. mlxsw_sp_port = mlxsw_sp_port_orig_get(obj->orig_dev, mlxsw_sp_port);
  859. if (!mlxsw_sp_port)
  860. return -EINVAL;
  861. switch (obj->id) {
  862. case SWITCHDEV_OBJ_ID_PORT_VLAN:
  863. if (mlxsw_sp_port_is_vport(mlxsw_sp_port))
  864. return 0;
  865. err = mlxsw_sp_port_vlans_add(mlxsw_sp_port,
  866. SWITCHDEV_OBJ_PORT_VLAN(obj),
  867. trans);
  868. break;
  869. case SWITCHDEV_OBJ_ID_IPV4_FIB:
  870. err = mlxsw_sp_router_fib4_add(mlxsw_sp_port,
  871. SWITCHDEV_OBJ_IPV4_FIB(obj),
  872. trans);
  873. break;
  874. case SWITCHDEV_OBJ_ID_PORT_FDB:
  875. err = mlxsw_sp_port_fdb_static_add(mlxsw_sp_port,
  876. SWITCHDEV_OBJ_PORT_FDB(obj),
  877. trans);
  878. break;
  879. case SWITCHDEV_OBJ_ID_PORT_MDB:
  880. err = mlxsw_sp_port_mdb_add(mlxsw_sp_port,
  881. SWITCHDEV_OBJ_PORT_MDB(obj),
  882. trans);
  883. break;
  884. default:
  885. err = -EOPNOTSUPP;
  886. break;
  887. }
  888. return err;
  889. }
  890. static int __mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
  891. u16 vid_begin, u16 vid_end)
  892. {
  893. u16 vid, pvid;
  894. if (!mlxsw_sp_port->bridged)
  895. return -EINVAL;
  896. mlxsw_sp_port_vid_learning_set(mlxsw_sp_port, vid_begin, vid_end,
  897. false);
  898. pvid = mlxsw_sp_port->pvid;
  899. if (pvid >= vid_begin && pvid <= vid_end)
  900. mlxsw_sp_port_pvid_set(mlxsw_sp_port, 0);
  901. __mlxsw_sp_port_vlans_set(mlxsw_sp_port, vid_begin, vid_end, false,
  902. false);
  903. mlxsw_sp_port_fid_leave(mlxsw_sp_port, vid_begin, vid_end);
  904. /* Changing activity bits only if HW operation succeded */
  905. for (vid = vid_begin; vid <= vid_end; vid++)
  906. clear_bit(vid, mlxsw_sp_port->active_vlans);
  907. return 0;
  908. }
  909. static int mlxsw_sp_port_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port,
  910. const struct switchdev_obj_port_vlan *vlan)
  911. {
  912. return __mlxsw_sp_port_vlans_del(mlxsw_sp_port, vlan->vid_begin,
  913. vlan->vid_end);
  914. }
  915. void mlxsw_sp_port_active_vlans_del(struct mlxsw_sp_port *mlxsw_sp_port)
  916. {
  917. u16 vid;
  918. for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID)
  919. __mlxsw_sp_port_vlans_del(mlxsw_sp_port, vid, vid);
  920. }
  921. static int
  922. mlxsw_sp_port_fdb_static_del(struct mlxsw_sp_port *mlxsw_sp_port,
  923. const struct switchdev_obj_port_fdb *fdb)
  924. {
  925. u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, fdb->vid);
  926. u16 lag_vid = 0;
  927. if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
  928. lag_vid = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
  929. }
  930. if (!mlxsw_sp_port->lagged)
  931. return mlxsw_sp_port_fdb_uc_op(mlxsw_sp_port->mlxsw_sp,
  932. mlxsw_sp_port->local_port,
  933. fdb->addr, fid,
  934. false, false);
  935. else
  936. return mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp_port->mlxsw_sp,
  937. mlxsw_sp_port->lag_id,
  938. fdb->addr, fid, lag_vid,
  939. false, false);
  940. }
  941. static int mlxsw_sp_port_mdb_del(struct mlxsw_sp_port *mlxsw_sp_port,
  942. const struct switchdev_obj_port_mdb *mdb)
  943. {
  944. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  945. struct net_device *dev = mlxsw_sp_port->dev;
  946. struct mlxsw_sp_mid *mid;
  947. u16 fid = mlxsw_sp_port_vid_to_fid_get(mlxsw_sp_port, mdb->vid);
  948. u16 mid_idx;
  949. int err = 0;
  950. mid = __mlxsw_sp_mc_get(mlxsw_sp, mdb->addr, mdb->vid);
  951. if (!mid) {
  952. netdev_err(dev, "Unable to remove port from MC DB\n");
  953. return -EINVAL;
  954. }
  955. err = mlxsw_sp_port_smid_set(mlxsw_sp_port, mid->mid, false, false);
  956. if (err)
  957. netdev_err(dev, "Unable to remove port from SMID\n");
  958. mid_idx = mid->mid;
  959. if (__mlxsw_sp_mc_dec_ref(mlxsw_sp, mid)) {
  960. err = mlxsw_sp_port_mdb_op(mlxsw_sp, mdb->addr, fid, mid_idx,
  961. false);
  962. if (err)
  963. netdev_err(dev, "Unable to remove MC SFD\n");
  964. }
  965. return err;
  966. }
  967. static int mlxsw_sp_port_obj_del(struct net_device *dev,
  968. const struct switchdev_obj *obj)
  969. {
  970. struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
  971. int err = 0;
  972. mlxsw_sp_port = mlxsw_sp_port_orig_get(obj->orig_dev, mlxsw_sp_port);
  973. if (!mlxsw_sp_port)
  974. return -EINVAL;
  975. switch (obj->id) {
  976. case SWITCHDEV_OBJ_ID_PORT_VLAN:
  977. if (mlxsw_sp_port_is_vport(mlxsw_sp_port))
  978. return 0;
  979. err = mlxsw_sp_port_vlans_del(mlxsw_sp_port,
  980. SWITCHDEV_OBJ_PORT_VLAN(obj));
  981. break;
  982. case SWITCHDEV_OBJ_ID_IPV4_FIB:
  983. err = mlxsw_sp_router_fib4_del(mlxsw_sp_port,
  984. SWITCHDEV_OBJ_IPV4_FIB(obj));
  985. break;
  986. case SWITCHDEV_OBJ_ID_PORT_FDB:
  987. err = mlxsw_sp_port_fdb_static_del(mlxsw_sp_port,
  988. SWITCHDEV_OBJ_PORT_FDB(obj));
  989. break;
  990. case SWITCHDEV_OBJ_ID_PORT_MDB:
  991. err = mlxsw_sp_port_mdb_del(mlxsw_sp_port,
  992. SWITCHDEV_OBJ_PORT_MDB(obj));
  993. break;
  994. default:
  995. err = -EOPNOTSUPP;
  996. break;
  997. }
  998. return err;
  999. }
  1000. static struct mlxsw_sp_port *mlxsw_sp_lag_rep_port(struct mlxsw_sp *mlxsw_sp,
  1001. u16 lag_id)
  1002. {
  1003. struct mlxsw_sp_port *mlxsw_sp_port;
  1004. struct mlxsw_resources *resources;
  1005. int i;
  1006. resources = mlxsw_core_resources_get(mlxsw_sp->core);
  1007. for (i = 0; i < resources->max_ports_in_lag; i++) {
  1008. mlxsw_sp_port = mlxsw_sp_port_lagged_get(mlxsw_sp, lag_id, i);
  1009. if (mlxsw_sp_port)
  1010. return mlxsw_sp_port;
  1011. }
  1012. return NULL;
  1013. }
  1014. static int mlxsw_sp_port_fdb_dump(struct mlxsw_sp_port *mlxsw_sp_port,
  1015. struct switchdev_obj_port_fdb *fdb,
  1016. switchdev_obj_dump_cb_t *cb,
  1017. struct net_device *orig_dev)
  1018. {
  1019. struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp;
  1020. struct mlxsw_sp_port *tmp;
  1021. struct mlxsw_sp_fid *f;
  1022. u16 vport_fid;
  1023. char *sfd_pl;
  1024. char mac[ETH_ALEN];
  1025. u16 fid;
  1026. u8 local_port;
  1027. u16 lag_id;
  1028. u8 num_rec;
  1029. int stored_err = 0;
  1030. int i;
  1031. int err;
  1032. sfd_pl = kmalloc(MLXSW_REG_SFD_LEN, GFP_KERNEL);
  1033. if (!sfd_pl)
  1034. return -ENOMEM;
  1035. f = mlxsw_sp_vport_fid_get(mlxsw_sp_port);
  1036. vport_fid = f ? f->fid : 0;
  1037. mlxsw_reg_sfd_pack(sfd_pl, MLXSW_REG_SFD_OP_QUERY_DUMP, 0);
  1038. do {
  1039. mlxsw_reg_sfd_num_rec_set(sfd_pl, MLXSW_REG_SFD_REC_MAX_COUNT);
  1040. err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(sfd), sfd_pl);
  1041. if (err)
  1042. goto out;
  1043. num_rec = mlxsw_reg_sfd_num_rec_get(sfd_pl);
  1044. /* Even in case of error, we have to run the dump to the end
  1045. * so the session in firmware is finished.
  1046. */
  1047. if (stored_err)
  1048. continue;
  1049. for (i = 0; i < num_rec; i++) {
  1050. switch (mlxsw_reg_sfd_rec_type_get(sfd_pl, i)) {
  1051. case MLXSW_REG_SFD_REC_TYPE_UNICAST:
  1052. mlxsw_reg_sfd_uc_unpack(sfd_pl, i, mac, &fid,
  1053. &local_port);
  1054. if (local_port == mlxsw_sp_port->local_port) {
  1055. if (vport_fid && vport_fid == fid)
  1056. fdb->vid = 0;
  1057. else if (!vport_fid &&
  1058. !mlxsw_sp_fid_is_vfid(fid))
  1059. fdb->vid = fid;
  1060. else
  1061. continue;
  1062. ether_addr_copy(fdb->addr, mac);
  1063. fdb->ndm_state = NUD_REACHABLE;
  1064. err = cb(&fdb->obj);
  1065. if (err)
  1066. stored_err = err;
  1067. }
  1068. break;
  1069. case MLXSW_REG_SFD_REC_TYPE_UNICAST_LAG:
  1070. mlxsw_reg_sfd_uc_lag_unpack(sfd_pl, i,
  1071. mac, &fid, &lag_id);
  1072. tmp = mlxsw_sp_lag_rep_port(mlxsw_sp, lag_id);
  1073. if (tmp && tmp->local_port ==
  1074. mlxsw_sp_port->local_port) {
  1075. /* LAG records can only point to LAG
  1076. * devices or VLAN devices on top.
  1077. */
  1078. if (!netif_is_lag_master(orig_dev) &&
  1079. !is_vlan_dev(orig_dev))
  1080. continue;
  1081. if (vport_fid && vport_fid == fid)
  1082. fdb->vid = 0;
  1083. else if (!vport_fid &&
  1084. !mlxsw_sp_fid_is_vfid(fid))
  1085. fdb->vid = fid;
  1086. else
  1087. continue;
  1088. ether_addr_copy(fdb->addr, mac);
  1089. fdb->ndm_state = NUD_REACHABLE;
  1090. err = cb(&fdb->obj);
  1091. if (err)
  1092. stored_err = err;
  1093. }
  1094. break;
  1095. }
  1096. }
  1097. } while (num_rec == MLXSW_REG_SFD_REC_MAX_COUNT);
  1098. out:
  1099. kfree(sfd_pl);
  1100. return stored_err ? stored_err : err;
  1101. }
  1102. static int mlxsw_sp_port_vlan_dump(struct mlxsw_sp_port *mlxsw_sp_port,
  1103. struct switchdev_obj_port_vlan *vlan,
  1104. switchdev_obj_dump_cb_t *cb)
  1105. {
  1106. u16 vid;
  1107. int err = 0;
  1108. if (mlxsw_sp_port_is_vport(mlxsw_sp_port)) {
  1109. vlan->flags = 0;
  1110. vlan->vid_begin = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
  1111. vlan->vid_end = mlxsw_sp_vport_vid_get(mlxsw_sp_port);
  1112. return cb(&vlan->obj);
  1113. }
  1114. for_each_set_bit(vid, mlxsw_sp_port->active_vlans, VLAN_N_VID) {
  1115. vlan->flags = 0;
  1116. if (vid == mlxsw_sp_port->pvid)
  1117. vlan->flags |= BRIDGE_VLAN_INFO_PVID;
  1118. if (test_bit(vid, mlxsw_sp_port->untagged_vlans))
  1119. vlan->flags |= BRIDGE_VLAN_INFO_UNTAGGED;
  1120. vlan->vid_begin = vid;
  1121. vlan->vid_end = vid;
  1122. err = cb(&vlan->obj);
  1123. if (err)
  1124. break;
  1125. }
  1126. return err;
  1127. }
  1128. static int mlxsw_sp_port_obj_dump(struct net_device *dev,
  1129. struct switchdev_obj *obj,
  1130. switchdev_obj_dump_cb_t *cb)
  1131. {
  1132. struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
  1133. int err = 0;
  1134. mlxsw_sp_port = mlxsw_sp_port_orig_get(obj->orig_dev, mlxsw_sp_port);
  1135. if (!mlxsw_sp_port)
  1136. return -EINVAL;
  1137. switch (obj->id) {
  1138. case SWITCHDEV_OBJ_ID_PORT_VLAN:
  1139. err = mlxsw_sp_port_vlan_dump(mlxsw_sp_port,
  1140. SWITCHDEV_OBJ_PORT_VLAN(obj), cb);
  1141. break;
  1142. case SWITCHDEV_OBJ_ID_PORT_FDB:
  1143. err = mlxsw_sp_port_fdb_dump(mlxsw_sp_port,
  1144. SWITCHDEV_OBJ_PORT_FDB(obj), cb,
  1145. obj->orig_dev);
  1146. break;
  1147. default:
  1148. err = -EOPNOTSUPP;
  1149. break;
  1150. }
  1151. return err;
  1152. }
  1153. static const struct switchdev_ops mlxsw_sp_port_switchdev_ops = {
  1154. .switchdev_port_attr_get = mlxsw_sp_port_attr_get,
  1155. .switchdev_port_attr_set = mlxsw_sp_port_attr_set,
  1156. .switchdev_port_obj_add = mlxsw_sp_port_obj_add,
  1157. .switchdev_port_obj_del = mlxsw_sp_port_obj_del,
  1158. .switchdev_port_obj_dump = mlxsw_sp_port_obj_dump,
  1159. };
  1160. static void mlxsw_sp_fdb_call_notifiers(bool learning_sync, bool adding,
  1161. char *mac, u16 vid,
  1162. struct net_device *dev)
  1163. {
  1164. struct switchdev_notifier_fdb_info info;
  1165. unsigned long notifier_type;
  1166. if (learning_sync) {
  1167. info.addr = mac;
  1168. info.vid = vid;
  1169. notifier_type = adding ? SWITCHDEV_FDB_ADD : SWITCHDEV_FDB_DEL;
  1170. call_switchdev_notifiers(notifier_type, dev, &info.info);
  1171. }
  1172. }
  1173. static void mlxsw_sp_fdb_notify_mac_process(struct mlxsw_sp *mlxsw_sp,
  1174. char *sfn_pl, int rec_index,
  1175. bool adding)
  1176. {
  1177. struct mlxsw_sp_port *mlxsw_sp_port;
  1178. char mac[ETH_ALEN];
  1179. u8 local_port;
  1180. u16 vid, fid;
  1181. bool do_notification = true;
  1182. int err;
  1183. mlxsw_reg_sfn_mac_unpack(sfn_pl, rec_index, mac, &fid, &local_port);
  1184. mlxsw_sp_port = mlxsw_sp->ports[local_port];
  1185. if (!mlxsw_sp_port) {
  1186. dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Incorrect local port in FDB notification\n");
  1187. goto just_remove;
  1188. }
  1189. if (mlxsw_sp_fid_is_vfid(fid)) {
  1190. struct mlxsw_sp_port *mlxsw_sp_vport;
  1191. mlxsw_sp_vport = mlxsw_sp_port_vport_find_by_fid(mlxsw_sp_port,
  1192. fid);
  1193. if (!mlxsw_sp_vport) {
  1194. netdev_err(mlxsw_sp_port->dev, "Failed to find a matching vPort following FDB notification\n");
  1195. goto just_remove;
  1196. }
  1197. vid = 0;
  1198. /* Override the physical port with the vPort. */
  1199. mlxsw_sp_port = mlxsw_sp_vport;
  1200. } else {
  1201. vid = fid;
  1202. }
  1203. do_fdb_op:
  1204. err = mlxsw_sp_port_fdb_uc_op(mlxsw_sp, local_port, mac, fid,
  1205. adding, true);
  1206. if (err) {
  1207. if (net_ratelimit())
  1208. netdev_err(mlxsw_sp_port->dev, "Failed to set FDB entry\n");
  1209. return;
  1210. }
  1211. if (!do_notification)
  1212. return;
  1213. mlxsw_sp_fdb_call_notifiers(mlxsw_sp_port->learning_sync,
  1214. adding, mac, vid, mlxsw_sp_port->dev);
  1215. return;
  1216. just_remove:
  1217. adding = false;
  1218. do_notification = false;
  1219. goto do_fdb_op;
  1220. }
  1221. static void mlxsw_sp_fdb_notify_mac_lag_process(struct mlxsw_sp *mlxsw_sp,
  1222. char *sfn_pl, int rec_index,
  1223. bool adding)
  1224. {
  1225. struct mlxsw_sp_port *mlxsw_sp_port;
  1226. struct net_device *dev;
  1227. char mac[ETH_ALEN];
  1228. u16 lag_vid = 0;
  1229. u16 lag_id;
  1230. u16 vid, fid;
  1231. bool do_notification = true;
  1232. int err;
  1233. mlxsw_reg_sfn_mac_lag_unpack(sfn_pl, rec_index, mac, &fid, &lag_id);
  1234. mlxsw_sp_port = mlxsw_sp_lag_rep_port(mlxsw_sp, lag_id);
  1235. if (!mlxsw_sp_port) {
  1236. dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Cannot find port representor for LAG\n");
  1237. goto just_remove;
  1238. }
  1239. if (mlxsw_sp_fid_is_vfid(fid)) {
  1240. struct mlxsw_sp_port *mlxsw_sp_vport;
  1241. mlxsw_sp_vport = mlxsw_sp_port_vport_find_by_fid(mlxsw_sp_port,
  1242. fid);
  1243. if (!mlxsw_sp_vport) {
  1244. netdev_err(mlxsw_sp_port->dev, "Failed to find a matching vPort following FDB notification\n");
  1245. goto just_remove;
  1246. }
  1247. lag_vid = mlxsw_sp_vport_vid_get(mlxsw_sp_vport);
  1248. dev = mlxsw_sp_vport->dev;
  1249. vid = 0;
  1250. /* Override the physical port with the vPort. */
  1251. mlxsw_sp_port = mlxsw_sp_vport;
  1252. } else {
  1253. dev = mlxsw_sp_lag_get(mlxsw_sp, lag_id)->dev;
  1254. vid = fid;
  1255. }
  1256. do_fdb_op:
  1257. err = mlxsw_sp_port_fdb_uc_lag_op(mlxsw_sp, lag_id, mac, fid, lag_vid,
  1258. adding, true);
  1259. if (err) {
  1260. if (net_ratelimit())
  1261. netdev_err(mlxsw_sp_port->dev, "Failed to set FDB entry\n");
  1262. return;
  1263. }
  1264. if (!do_notification)
  1265. return;
  1266. mlxsw_sp_fdb_call_notifiers(mlxsw_sp_port->learning_sync, adding, mac,
  1267. vid, dev);
  1268. return;
  1269. just_remove:
  1270. adding = false;
  1271. do_notification = false;
  1272. goto do_fdb_op;
  1273. }
  1274. static void mlxsw_sp_fdb_notify_rec_process(struct mlxsw_sp *mlxsw_sp,
  1275. char *sfn_pl, int rec_index)
  1276. {
  1277. switch (mlxsw_reg_sfn_rec_type_get(sfn_pl, rec_index)) {
  1278. case MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC:
  1279. mlxsw_sp_fdb_notify_mac_process(mlxsw_sp, sfn_pl,
  1280. rec_index, true);
  1281. break;
  1282. case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC:
  1283. mlxsw_sp_fdb_notify_mac_process(mlxsw_sp, sfn_pl,
  1284. rec_index, false);
  1285. break;
  1286. case MLXSW_REG_SFN_REC_TYPE_LEARNED_MAC_LAG:
  1287. mlxsw_sp_fdb_notify_mac_lag_process(mlxsw_sp, sfn_pl,
  1288. rec_index, true);
  1289. break;
  1290. case MLXSW_REG_SFN_REC_TYPE_AGED_OUT_MAC_LAG:
  1291. mlxsw_sp_fdb_notify_mac_lag_process(mlxsw_sp, sfn_pl,
  1292. rec_index, false);
  1293. break;
  1294. }
  1295. }
  1296. static void mlxsw_sp_fdb_notify_work_schedule(struct mlxsw_sp *mlxsw_sp)
  1297. {
  1298. mlxsw_core_schedule_dw(&mlxsw_sp->fdb_notify.dw,
  1299. msecs_to_jiffies(mlxsw_sp->fdb_notify.interval));
  1300. }
  1301. static void mlxsw_sp_fdb_notify_work(struct work_struct *work)
  1302. {
  1303. struct mlxsw_sp *mlxsw_sp;
  1304. char *sfn_pl;
  1305. u8 num_rec;
  1306. int i;
  1307. int err;
  1308. sfn_pl = kmalloc(MLXSW_REG_SFN_LEN, GFP_KERNEL);
  1309. if (!sfn_pl)
  1310. return;
  1311. mlxsw_sp = container_of(work, struct mlxsw_sp, fdb_notify.dw.work);
  1312. rtnl_lock();
  1313. mlxsw_reg_sfn_pack(sfn_pl);
  1314. err = mlxsw_reg_query(mlxsw_sp->core, MLXSW_REG(sfn), sfn_pl);
  1315. if (err) {
  1316. dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to get FDB notifications\n");
  1317. goto out;
  1318. }
  1319. num_rec = mlxsw_reg_sfn_num_rec_get(sfn_pl);
  1320. for (i = 0; i < num_rec; i++)
  1321. mlxsw_sp_fdb_notify_rec_process(mlxsw_sp, sfn_pl, i);
  1322. out:
  1323. rtnl_unlock();
  1324. kfree(sfn_pl);
  1325. mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp);
  1326. }
  1327. static int mlxsw_sp_fdb_init(struct mlxsw_sp *mlxsw_sp)
  1328. {
  1329. int err;
  1330. err = mlxsw_sp_ageing_set(mlxsw_sp, MLXSW_SP_DEFAULT_AGEING_TIME);
  1331. if (err) {
  1332. dev_err(mlxsw_sp->bus_info->dev, "Failed to set default ageing time\n");
  1333. return err;
  1334. }
  1335. INIT_DELAYED_WORK(&mlxsw_sp->fdb_notify.dw, mlxsw_sp_fdb_notify_work);
  1336. mlxsw_sp->fdb_notify.interval = MLXSW_SP_DEFAULT_LEARNING_INTERVAL;
  1337. mlxsw_sp_fdb_notify_work_schedule(mlxsw_sp);
  1338. return 0;
  1339. }
  1340. static void mlxsw_sp_fdb_fini(struct mlxsw_sp *mlxsw_sp)
  1341. {
  1342. cancel_delayed_work_sync(&mlxsw_sp->fdb_notify.dw);
  1343. }
  1344. int mlxsw_sp_switchdev_init(struct mlxsw_sp *mlxsw_sp)
  1345. {
  1346. return mlxsw_sp_fdb_init(mlxsw_sp);
  1347. }
  1348. void mlxsw_sp_switchdev_fini(struct mlxsw_sp *mlxsw_sp)
  1349. {
  1350. mlxsw_sp_fdb_fini(mlxsw_sp);
  1351. }
  1352. void mlxsw_sp_port_switchdev_init(struct mlxsw_sp_port *mlxsw_sp_port)
  1353. {
  1354. mlxsw_sp_port->dev->switchdev_ops = &mlxsw_sp_port_switchdev_ops;
  1355. }
  1356. void mlxsw_sp_port_switchdev_fini(struct mlxsw_sp_port *mlxsw_sp_port)
  1357. {
  1358. }