dpsw.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright 2014-2016 Freescale Semiconductor Inc.
  4. * Copyright 2017-2021 NXP
  5. *
  6. */
  7. #include <linux/fsl/mc.h>
  8. #include "dpsw.h"
  9. #include "dpsw-cmd.h"
  10. static void build_if_id_bitmap(__le64 *bmap, const u16 *id, const u16 num_ifs)
  11. {
  12. int i;
  13. for (i = 0; (i < num_ifs) && (i < DPSW_MAX_IF); i++) {
  14. if (id[i] < DPSW_MAX_IF)
  15. bmap[id[i] / 64] |= cpu_to_le64(BIT_MASK(id[i] % 64));
  16. }
  17. }
  18. /**
  19. * dpsw_open() - Open a control session for the specified object
  20. * @mc_io: Pointer to MC portal's I/O object
  21. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  22. * @dpsw_id: DPSW unique ID
  23. * @token: Returned token; use in subsequent API calls
  24. *
  25. * This function can be used to open a control session for an
  26. * already created object; an object may have been declared in
  27. * the DPL or by calling the dpsw_create() function.
  28. * This function returns a unique authentication token,
  29. * associated with the specific object ID and the specific MC
  30. * portal; this token must be used in all subsequent commands for
  31. * this specific object
  32. *
  33. * Return: '0' on Success; Error code otherwise.
  34. */
  35. int dpsw_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpsw_id, u16 *token)
  36. {
  37. struct fsl_mc_command cmd = { 0 };
  38. struct dpsw_cmd_open *cmd_params;
  39. int err;
  40. /* prepare command */
  41. cmd.header = mc_encode_cmd_header(DPSW_CMDID_OPEN,
  42. cmd_flags,
  43. 0);
  44. cmd_params = (struct dpsw_cmd_open *)cmd.params;
  45. cmd_params->dpsw_id = cpu_to_le32(dpsw_id);
  46. /* send command to mc*/
  47. err = mc_send_command(mc_io, &cmd);
  48. if (err)
  49. return err;
  50. /* retrieve response parameters */
  51. *token = mc_cmd_hdr_read_token(&cmd);
  52. return 0;
  53. }
  54. /**
  55. * dpsw_close() - Close the control session of the object
  56. * @mc_io: Pointer to MC portal's I/O object
  57. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  58. * @token: Token of DPSW object
  59. *
  60. * After this function is called, no further operations are
  61. * allowed on the object without opening a new control session.
  62. *
  63. * Return: '0' on Success; Error code otherwise.
  64. */
  65. int dpsw_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
  66. {
  67. struct fsl_mc_command cmd = { 0 };
  68. /* prepare command */
  69. cmd.header = mc_encode_cmd_header(DPSW_CMDID_CLOSE,
  70. cmd_flags,
  71. token);
  72. /* send command to mc*/
  73. return mc_send_command(mc_io, &cmd);
  74. }
  75. /**
  76. * dpsw_enable() - Enable DPSW functionality
  77. * @mc_io: Pointer to MC portal's I/O object
  78. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  79. * @token: Token of DPSW object
  80. *
  81. * Return: Completion status. '0' on Success; Error code otherwise.
  82. */
  83. int dpsw_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
  84. {
  85. struct fsl_mc_command cmd = { 0 };
  86. /* prepare command */
  87. cmd.header = mc_encode_cmd_header(DPSW_CMDID_ENABLE,
  88. cmd_flags,
  89. token);
  90. /* send command to mc*/
  91. return mc_send_command(mc_io, &cmd);
  92. }
  93. /**
  94. * dpsw_disable() - Disable DPSW functionality
  95. * @mc_io: Pointer to MC portal's I/O object
  96. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  97. * @token: Token of DPSW object
  98. *
  99. * Return: Completion status. '0' on Success; Error code otherwise.
  100. */
  101. int dpsw_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
  102. {
  103. struct fsl_mc_command cmd = { 0 };
  104. /* prepare command */
  105. cmd.header = mc_encode_cmd_header(DPSW_CMDID_DISABLE,
  106. cmd_flags,
  107. token);
  108. /* send command to mc*/
  109. return mc_send_command(mc_io, &cmd);
  110. }
  111. /**
  112. * dpsw_reset() - Reset the DPSW, returns the object to initial state.
  113. * @mc_io: Pointer to MC portal's I/O object
  114. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  115. * @token: Token of DPSW object
  116. *
  117. * Return: '0' on Success; Error code otherwise.
  118. */
  119. int dpsw_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
  120. {
  121. struct fsl_mc_command cmd = { 0 };
  122. /* prepare command */
  123. cmd.header = mc_encode_cmd_header(DPSW_CMDID_RESET,
  124. cmd_flags,
  125. token);
  126. /* send command to mc*/
  127. return mc_send_command(mc_io, &cmd);
  128. }
  129. /**
  130. * dpsw_set_irq_enable() - Set overall interrupt state.
  131. * @mc_io: Pointer to MC portal's I/O object
  132. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  133. * @token: Token of DPCI object
  134. * @irq_index: The interrupt index to configure
  135. * @en: Interrupt state - enable = 1, disable = 0
  136. *
  137. * Allows GPP software to control when interrupts are generated.
  138. * Each interrupt can have up to 32 causes. The enable/disable control's the
  139. * overall interrupt state. if the interrupt is disabled no causes will cause
  140. * an interrupt
  141. *
  142. * Return: '0' on Success; Error code otherwise.
  143. */
  144. int dpsw_set_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  145. u8 irq_index, u8 en)
  146. {
  147. struct fsl_mc_command cmd = { 0 };
  148. struct dpsw_cmd_set_irq_enable *cmd_params;
  149. /* prepare command */
  150. cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_IRQ_ENABLE,
  151. cmd_flags,
  152. token);
  153. cmd_params = (struct dpsw_cmd_set_irq_enable *)cmd.params;
  154. dpsw_set_field(cmd_params->enable_state, ENABLE, en);
  155. cmd_params->irq_index = irq_index;
  156. /* send command to mc*/
  157. return mc_send_command(mc_io, &cmd);
  158. }
  159. /**
  160. * dpsw_set_irq_mask() - Set interrupt mask.
  161. * @mc_io: Pointer to MC portal's I/O object
  162. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  163. * @token: Token of DPCI object
  164. * @irq_index: The interrupt index to configure
  165. * @mask: Event mask to trigger interrupt;
  166. * each bit:
  167. * 0 = ignore event
  168. * 1 = consider event for asserting IRQ
  169. *
  170. * Every interrupt can have up to 32 causes and the interrupt model supports
  171. * masking/unmasking each cause independently
  172. *
  173. * Return: '0' on Success; Error code otherwise.
  174. */
  175. int dpsw_set_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  176. u8 irq_index, u32 mask)
  177. {
  178. struct fsl_mc_command cmd = { 0 };
  179. struct dpsw_cmd_set_irq_mask *cmd_params;
  180. /* prepare command */
  181. cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_IRQ_MASK,
  182. cmd_flags,
  183. token);
  184. cmd_params = (struct dpsw_cmd_set_irq_mask *)cmd.params;
  185. cmd_params->mask = cpu_to_le32(mask);
  186. cmd_params->irq_index = irq_index;
  187. /* send command to mc*/
  188. return mc_send_command(mc_io, &cmd);
  189. }
  190. /**
  191. * dpsw_get_irq_status() - Get the current status of any pending interrupts
  192. * @mc_io: Pointer to MC portal's I/O object
  193. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  194. * @token: Token of DPSW object
  195. * @irq_index: The interrupt index to configure
  196. * @status: Returned interrupts status - one bit per cause:
  197. * 0 = no interrupt pending
  198. * 1 = interrupt pending
  199. *
  200. * Return: '0' on Success; Error code otherwise.
  201. */
  202. int dpsw_get_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  203. u8 irq_index, u32 *status)
  204. {
  205. struct fsl_mc_command cmd = { 0 };
  206. struct dpsw_cmd_get_irq_status *cmd_params;
  207. struct dpsw_rsp_get_irq_status *rsp_params;
  208. int err;
  209. /* prepare command */
  210. cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_IRQ_STATUS,
  211. cmd_flags,
  212. token);
  213. cmd_params = (struct dpsw_cmd_get_irq_status *)cmd.params;
  214. cmd_params->status = cpu_to_le32(*status);
  215. cmd_params->irq_index = irq_index;
  216. /* send command to mc*/
  217. err = mc_send_command(mc_io, &cmd);
  218. if (err)
  219. return err;
  220. /* retrieve response parameters */
  221. rsp_params = (struct dpsw_rsp_get_irq_status *)cmd.params;
  222. *status = le32_to_cpu(rsp_params->status);
  223. return 0;
  224. }
  225. /**
  226. * dpsw_clear_irq_status() - Clear a pending interrupt's status
  227. * @mc_io: Pointer to MC portal's I/O object
  228. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  229. * @token: Token of DPCI object
  230. * @irq_index: The interrupt index to configure
  231. * @status: bits to clear (W1C) - one bit per cause:
  232. * 0 = don't change
  233. * 1 = clear status bit
  234. *
  235. * Return: '0' on Success; Error code otherwise.
  236. */
  237. int dpsw_clear_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  238. u8 irq_index, u32 status)
  239. {
  240. struct fsl_mc_command cmd = { 0 };
  241. struct dpsw_cmd_clear_irq_status *cmd_params;
  242. /* prepare command */
  243. cmd.header = mc_encode_cmd_header(DPSW_CMDID_CLEAR_IRQ_STATUS,
  244. cmd_flags,
  245. token);
  246. cmd_params = (struct dpsw_cmd_clear_irq_status *)cmd.params;
  247. cmd_params->status = cpu_to_le32(status);
  248. cmd_params->irq_index = irq_index;
  249. /* send command to mc*/
  250. return mc_send_command(mc_io, &cmd);
  251. }
  252. /**
  253. * dpsw_get_attributes() - Retrieve DPSW attributes
  254. * @mc_io: Pointer to MC portal's I/O object
  255. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  256. * @token: Token of DPSW object
  257. * @attr: Returned DPSW attributes
  258. *
  259. * Return: Completion status. '0' on Success; Error code otherwise.
  260. */
  261. int dpsw_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  262. struct dpsw_attr *attr)
  263. {
  264. struct fsl_mc_command cmd = { 0 };
  265. struct dpsw_rsp_get_attr *rsp_params;
  266. int err;
  267. /* prepare command */
  268. cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_ATTR,
  269. cmd_flags,
  270. token);
  271. /* send command to mc*/
  272. err = mc_send_command(mc_io, &cmd);
  273. if (err)
  274. return err;
  275. /* retrieve response parameters */
  276. rsp_params = (struct dpsw_rsp_get_attr *)cmd.params;
  277. attr->num_ifs = le16_to_cpu(rsp_params->num_ifs);
  278. attr->max_fdbs = rsp_params->max_fdbs;
  279. attr->num_fdbs = rsp_params->num_fdbs;
  280. attr->max_vlans = le16_to_cpu(rsp_params->max_vlans);
  281. attr->num_vlans = le16_to_cpu(rsp_params->num_vlans);
  282. attr->max_fdb_entries = le16_to_cpu(rsp_params->max_fdb_entries);
  283. attr->fdb_aging_time = le16_to_cpu(rsp_params->fdb_aging_time);
  284. attr->id = le32_to_cpu(rsp_params->dpsw_id);
  285. attr->mem_size = le16_to_cpu(rsp_params->mem_size);
  286. attr->max_fdb_mc_groups = le16_to_cpu(rsp_params->max_fdb_mc_groups);
  287. attr->max_meters_per_if = rsp_params->max_meters_per_if;
  288. attr->options = le64_to_cpu(rsp_params->options);
  289. attr->component_type = dpsw_get_field(rsp_params->component_type, COMPONENT_TYPE);
  290. attr->flooding_cfg = dpsw_get_field(rsp_params->repl_cfg, FLOODING_CFG);
  291. attr->broadcast_cfg = dpsw_get_field(rsp_params->repl_cfg, BROADCAST_CFG);
  292. return 0;
  293. }
  294. /**
  295. * dpsw_if_set_link_cfg() - Set the link configuration.
  296. * @mc_io: Pointer to MC portal's I/O object
  297. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  298. * @token: Token of DPSW object
  299. * @if_id: Interface id
  300. * @cfg: Link configuration
  301. *
  302. * Return: '0' on Success; Error code otherwise.
  303. */
  304. int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
  305. struct dpsw_link_cfg *cfg)
  306. {
  307. struct fsl_mc_command cmd = { 0 };
  308. struct dpsw_cmd_if_set_link_cfg *cmd_params;
  309. /* prepare command */
  310. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_LINK_CFG,
  311. cmd_flags,
  312. token);
  313. cmd_params = (struct dpsw_cmd_if_set_link_cfg *)cmd.params;
  314. cmd_params->if_id = cpu_to_le16(if_id);
  315. cmd_params->rate = cpu_to_le32(cfg->rate);
  316. cmd_params->options = cpu_to_le64(cfg->options);
  317. /* send command to mc*/
  318. return mc_send_command(mc_io, &cmd);
  319. }
  320. /**
  321. * dpsw_if_get_link_state - Return the link state
  322. * @mc_io: Pointer to MC portal's I/O object
  323. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  324. * @token: Token of DPSW object
  325. * @if_id: Interface id
  326. * @state: Link state 1 - linkup, 0 - link down or disconnected
  327. *
  328. * Return: '0' on Success; Error code otherwise.
  329. */
  330. int dpsw_if_get_link_state(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  331. u16 if_id, struct dpsw_link_state *state)
  332. {
  333. struct fsl_mc_command cmd = { 0 };
  334. struct dpsw_cmd_if_get_link_state *cmd_params;
  335. struct dpsw_rsp_if_get_link_state *rsp_params;
  336. int err;
  337. /* prepare command */
  338. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_LINK_STATE,
  339. cmd_flags,
  340. token);
  341. cmd_params = (struct dpsw_cmd_if_get_link_state *)cmd.params;
  342. cmd_params->if_id = cpu_to_le16(if_id);
  343. /* send command to mc*/
  344. err = mc_send_command(mc_io, &cmd);
  345. if (err)
  346. return err;
  347. /* retrieve response parameters */
  348. rsp_params = (struct dpsw_rsp_if_get_link_state *)cmd.params;
  349. state->rate = le32_to_cpu(rsp_params->rate);
  350. state->options = le64_to_cpu(rsp_params->options);
  351. state->up = dpsw_get_field(rsp_params->up, UP);
  352. return 0;
  353. }
  354. /**
  355. * dpsw_if_set_tci() - Set default VLAN Tag Control Information (TCI)
  356. * @mc_io: Pointer to MC portal's I/O object
  357. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  358. * @token: Token of DPSW object
  359. * @if_id: Interface Identifier
  360. * @cfg: Tag Control Information Configuration
  361. *
  362. * Return: Completion status. '0' on Success; Error code otherwise.
  363. */
  364. int dpsw_if_set_tci(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
  365. const struct dpsw_tci_cfg *cfg)
  366. {
  367. struct fsl_mc_command cmd = { 0 };
  368. struct dpsw_cmd_if_set_tci *cmd_params;
  369. u16 tmp_conf = 0;
  370. /* prepare command */
  371. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_TCI,
  372. cmd_flags,
  373. token);
  374. cmd_params = (struct dpsw_cmd_if_set_tci *)cmd.params;
  375. cmd_params->if_id = cpu_to_le16(if_id);
  376. dpsw_set_field(tmp_conf, VLAN_ID, cfg->vlan_id);
  377. dpsw_set_field(tmp_conf, DEI, cfg->dei);
  378. dpsw_set_field(tmp_conf, PCP, cfg->pcp);
  379. cmd_params->conf = cpu_to_le16(tmp_conf);
  380. /* send command to mc*/
  381. return mc_send_command(mc_io, &cmd);
  382. }
  383. /**
  384. * dpsw_if_get_tci() - Get default VLAN Tag Control Information (TCI)
  385. * @mc_io: Pointer to MC portal's I/O object
  386. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  387. * @token: Token of DPSW object
  388. * @if_id: Interface Identifier
  389. * @cfg: Tag Control Information Configuration
  390. *
  391. * Return: Completion status. '0' on Success; Error code otherwise.
  392. */
  393. int dpsw_if_get_tci(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
  394. struct dpsw_tci_cfg *cfg)
  395. {
  396. struct fsl_mc_command cmd = { 0 };
  397. struct dpsw_cmd_if_get_tci *cmd_params;
  398. struct dpsw_rsp_if_get_tci *rsp_params;
  399. int err;
  400. /* prepare command */
  401. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_TCI,
  402. cmd_flags,
  403. token);
  404. cmd_params = (struct dpsw_cmd_if_get_tci *)cmd.params;
  405. cmd_params->if_id = cpu_to_le16(if_id);
  406. /* send command to mc*/
  407. err = mc_send_command(mc_io, &cmd);
  408. if (err)
  409. return err;
  410. /* retrieve response parameters */
  411. rsp_params = (struct dpsw_rsp_if_get_tci *)cmd.params;
  412. cfg->pcp = rsp_params->pcp;
  413. cfg->dei = rsp_params->dei;
  414. cfg->vlan_id = le16_to_cpu(rsp_params->vlan_id);
  415. return 0;
  416. }
  417. /**
  418. * dpsw_if_set_stp() - Function sets Spanning Tree Protocol (STP) state.
  419. * @mc_io: Pointer to MC portal's I/O object
  420. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  421. * @token: Token of DPSW object
  422. * @if_id: Interface Identifier
  423. * @cfg: STP State configuration parameters
  424. *
  425. * The following STP states are supported -
  426. * blocking, listening, learning, forwarding and disabled.
  427. *
  428. * Return: Completion status. '0' on Success; Error code otherwise.
  429. */
  430. int dpsw_if_set_stp(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
  431. const struct dpsw_stp_cfg *cfg)
  432. {
  433. struct fsl_mc_command cmd = { 0 };
  434. struct dpsw_cmd_if_set_stp *cmd_params;
  435. /* prepare command */
  436. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_STP,
  437. cmd_flags,
  438. token);
  439. cmd_params = (struct dpsw_cmd_if_set_stp *)cmd.params;
  440. cmd_params->if_id = cpu_to_le16(if_id);
  441. cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
  442. dpsw_set_field(cmd_params->state, STATE, cfg->state);
  443. /* send command to mc*/
  444. return mc_send_command(mc_io, &cmd);
  445. }
  446. /**
  447. * dpsw_if_get_counter() - Get specific counter of particular interface
  448. * @mc_io: Pointer to MC portal's I/O object
  449. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  450. * @token: Token of DPSW object
  451. * @if_id: Interface Identifier
  452. * @type: Counter type
  453. * @counter: return value
  454. *
  455. * Return: Completion status. '0' on Success; Error code otherwise.
  456. */
  457. int dpsw_if_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  458. u16 if_id, enum dpsw_counter type, u64 *counter)
  459. {
  460. struct fsl_mc_command cmd = { 0 };
  461. struct dpsw_cmd_if_get_counter *cmd_params;
  462. struct dpsw_rsp_if_get_counter *rsp_params;
  463. int err;
  464. /* prepare command */
  465. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_COUNTER,
  466. cmd_flags,
  467. token);
  468. cmd_params = (struct dpsw_cmd_if_get_counter *)cmd.params;
  469. cmd_params->if_id = cpu_to_le16(if_id);
  470. dpsw_set_field(cmd_params->type, COUNTER_TYPE, type);
  471. /* send command to mc*/
  472. err = mc_send_command(mc_io, &cmd);
  473. if (err)
  474. return err;
  475. /* retrieve response parameters */
  476. rsp_params = (struct dpsw_rsp_if_get_counter *)cmd.params;
  477. *counter = le64_to_cpu(rsp_params->counter);
  478. return 0;
  479. }
  480. /**
  481. * dpsw_if_enable() - Enable Interface
  482. * @mc_io: Pointer to MC portal's I/O object
  483. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  484. * @token: Token of DPSW object
  485. * @if_id: Interface Identifier
  486. *
  487. * Return: Completion status. '0' on Success; Error code otherwise.
  488. */
  489. int dpsw_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id)
  490. {
  491. struct fsl_mc_command cmd = { 0 };
  492. struct dpsw_cmd_if *cmd_params;
  493. /* prepare command */
  494. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_ENABLE,
  495. cmd_flags,
  496. token);
  497. cmd_params = (struct dpsw_cmd_if *)cmd.params;
  498. cmd_params->if_id = cpu_to_le16(if_id);
  499. /* send command to mc*/
  500. return mc_send_command(mc_io, &cmd);
  501. }
  502. /**
  503. * dpsw_if_disable() - Disable Interface
  504. * @mc_io: Pointer to MC portal's I/O object
  505. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  506. * @token: Token of DPSW object
  507. * @if_id: Interface Identifier
  508. *
  509. * Return: Completion status. '0' on Success; Error code otherwise.
  510. */
  511. int dpsw_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id)
  512. {
  513. struct fsl_mc_command cmd = { 0 };
  514. struct dpsw_cmd_if *cmd_params;
  515. /* prepare command */
  516. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_DISABLE,
  517. cmd_flags,
  518. token);
  519. cmd_params = (struct dpsw_cmd_if *)cmd.params;
  520. cmd_params->if_id = cpu_to_le16(if_id);
  521. /* send command to mc*/
  522. return mc_send_command(mc_io, &cmd);
  523. }
  524. /**
  525. * dpsw_if_get_attributes() - Function obtains attributes of interface
  526. * @mc_io: Pointer to MC portal's I/O object
  527. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  528. * @token: Token of DPSW object
  529. * @if_id: Interface Identifier
  530. * @attr: Returned interface attributes
  531. *
  532. * Return: Completion status. '0' on Success; Error code otherwise.
  533. */
  534. int dpsw_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  535. u16 if_id, struct dpsw_if_attr *attr)
  536. {
  537. struct dpsw_rsp_if_get_attr *rsp_params;
  538. struct fsl_mc_command cmd = { 0 };
  539. struct dpsw_cmd_if *cmd_params;
  540. int err;
  541. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_ATTR, cmd_flags,
  542. token);
  543. cmd_params = (struct dpsw_cmd_if *)cmd.params;
  544. cmd_params->if_id = cpu_to_le16(if_id);
  545. err = mc_send_command(mc_io, &cmd);
  546. if (err)
  547. return err;
  548. rsp_params = (struct dpsw_rsp_if_get_attr *)cmd.params;
  549. attr->num_tcs = rsp_params->num_tcs;
  550. attr->rate = le32_to_cpu(rsp_params->rate);
  551. attr->options = le32_to_cpu(rsp_params->options);
  552. attr->qdid = le16_to_cpu(rsp_params->qdid);
  553. attr->enabled = dpsw_get_field(rsp_params->conf, ENABLED);
  554. attr->accept_all_vlan = dpsw_get_field(rsp_params->conf,
  555. ACCEPT_ALL_VLAN);
  556. attr->admit_untagged = dpsw_get_field(rsp_params->conf,
  557. ADMIT_UNTAGGED);
  558. return 0;
  559. }
  560. /**
  561. * dpsw_if_set_max_frame_length() - Set Maximum Receive frame length.
  562. * @mc_io: Pointer to MC portal's I/O object
  563. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  564. * @token: Token of DPSW object
  565. * @if_id: Interface Identifier
  566. * @frame_length: Maximum Frame Length
  567. *
  568. * Return: Completion status. '0' on Success; Error code otherwise.
  569. */
  570. int dpsw_if_set_max_frame_length(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  571. u16 if_id, u16 frame_length)
  572. {
  573. struct fsl_mc_command cmd = { 0 };
  574. struct dpsw_cmd_if_set_max_frame_length *cmd_params;
  575. /* prepare command */
  576. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_MAX_FRAME_LENGTH,
  577. cmd_flags,
  578. token);
  579. cmd_params = (struct dpsw_cmd_if_set_max_frame_length *)cmd.params;
  580. cmd_params->if_id = cpu_to_le16(if_id);
  581. cmd_params->frame_length = cpu_to_le16(frame_length);
  582. /* send command to mc*/
  583. return mc_send_command(mc_io, &cmd);
  584. }
  585. /**
  586. * dpsw_vlan_add() - Adding new VLAN to DPSW.
  587. * @mc_io: Pointer to MC portal's I/O object
  588. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  589. * @token: Token of DPSW object
  590. * @vlan_id: VLAN Identifier
  591. * @cfg: VLAN configuration
  592. *
  593. * Only VLAN ID and FDB ID are required parameters here.
  594. * 12 bit VLAN ID is defined in IEEE802.1Q.
  595. * Adding a duplicate VLAN ID is not allowed.
  596. * FDB ID can be shared across multiple VLANs. Shared learning
  597. * is obtained by calling dpsw_vlan_add for multiple VLAN IDs
  598. * with same fdb_id
  599. *
  600. * Return: Completion status. '0' on Success; Error code otherwise.
  601. */
  602. int dpsw_vlan_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  603. u16 vlan_id, const struct dpsw_vlan_cfg *cfg)
  604. {
  605. struct fsl_mc_command cmd = { 0 };
  606. struct dpsw_vlan_add *cmd_params;
  607. /* prepare command */
  608. cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD,
  609. cmd_flags,
  610. token);
  611. cmd_params = (struct dpsw_vlan_add *)cmd.params;
  612. cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
  613. cmd_params->vlan_id = cpu_to_le16(vlan_id);
  614. /* send command to mc*/
  615. return mc_send_command(mc_io, &cmd);
  616. }
  617. /**
  618. * dpsw_vlan_add_if() - Adding a set of interfaces to an existing VLAN.
  619. * @mc_io: Pointer to MC portal's I/O object
  620. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  621. * @token: Token of DPSW object
  622. * @vlan_id: VLAN Identifier
  623. * @cfg: Set of interfaces to add
  624. *
  625. * It adds only interfaces not belonging to this VLAN yet,
  626. * otherwise an error is generated and an entire command is
  627. * ignored. This function can be called numerous times always
  628. * providing required interfaces delta.
  629. *
  630. * Return: Completion status. '0' on Success; Error code otherwise.
  631. */
  632. int dpsw_vlan_add_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  633. u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
  634. {
  635. struct dpsw_cmd_vlan_add_if *cmd_params;
  636. struct fsl_mc_command cmd = { 0 };
  637. /* prepare command */
  638. cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD_IF,
  639. cmd_flags,
  640. token);
  641. cmd_params = (struct dpsw_cmd_vlan_add_if *)cmd.params;
  642. cmd_params->vlan_id = cpu_to_le16(vlan_id);
  643. cmd_params->options = cpu_to_le16(cfg->options);
  644. cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
  645. build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
  646. /* send command to mc*/
  647. return mc_send_command(mc_io, &cmd);
  648. }
  649. /**
  650. * dpsw_vlan_add_if_untagged() - Defining a set of interfaces that should be
  651. * transmitted as untagged.
  652. * @mc_io: Pointer to MC portal's I/O object
  653. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  654. * @token: Token of DPSW object
  655. * @vlan_id: VLAN Identifier
  656. * @cfg: Set of interfaces that should be transmitted as untagged
  657. *
  658. * These interfaces should already belong to this VLAN.
  659. * By default all interfaces are transmitted as tagged.
  660. * Providing un-existing interface or untagged interface that is
  661. * configured untagged already generates an error and the entire
  662. * command is ignored.
  663. *
  664. * Return: Completion status. '0' on Success; Error code otherwise.
  665. */
  666. int dpsw_vlan_add_if_untagged(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  667. u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
  668. {
  669. struct fsl_mc_command cmd = { 0 };
  670. struct dpsw_cmd_vlan_manage_if *cmd_params;
  671. /* prepare command */
  672. cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD_IF_UNTAGGED,
  673. cmd_flags,
  674. token);
  675. cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
  676. cmd_params->vlan_id = cpu_to_le16(vlan_id);
  677. build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
  678. /* send command to mc*/
  679. return mc_send_command(mc_io, &cmd);
  680. }
  681. /**
  682. * dpsw_vlan_remove_if() - Remove interfaces from an existing VLAN.
  683. * @mc_io: Pointer to MC portal's I/O object
  684. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  685. * @token: Token of DPSW object
  686. * @vlan_id: VLAN Identifier
  687. * @cfg: Set of interfaces that should be removed
  688. *
  689. * Interfaces must belong to this VLAN, otherwise an error
  690. * is returned and an the command is ignored
  691. *
  692. * Return: Completion status. '0' on Success; Error code otherwise.
  693. */
  694. int dpsw_vlan_remove_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  695. u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
  696. {
  697. struct fsl_mc_command cmd = { 0 };
  698. struct dpsw_cmd_vlan_manage_if *cmd_params;
  699. /* prepare command */
  700. cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE_IF,
  701. cmd_flags,
  702. token);
  703. cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
  704. cmd_params->vlan_id = cpu_to_le16(vlan_id);
  705. build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
  706. /* send command to mc*/
  707. return mc_send_command(mc_io, &cmd);
  708. }
  709. /**
  710. * dpsw_vlan_remove_if_untagged() - Define a set of interfaces that should be
  711. * converted from transmitted as untagged to transmit as tagged.
  712. * @mc_io: Pointer to MC portal's I/O object
  713. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  714. * @token: Token of DPSW object
  715. * @vlan_id: VLAN Identifier
  716. * @cfg: Set of interfaces that should be removed
  717. *
  718. * Interfaces provided by API have to belong to this VLAN and
  719. * configured untagged, otherwise an error is returned and the
  720. * command is ignored
  721. *
  722. * Return: Completion status. '0' on Success; Error code otherwise.
  723. */
  724. int dpsw_vlan_remove_if_untagged(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  725. u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
  726. {
  727. struct fsl_mc_command cmd = { 0 };
  728. struct dpsw_cmd_vlan_manage_if *cmd_params;
  729. /* prepare command */
  730. cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE_IF_UNTAGGED,
  731. cmd_flags,
  732. token);
  733. cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
  734. cmd_params->vlan_id = cpu_to_le16(vlan_id);
  735. build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
  736. /* send command to mc*/
  737. return mc_send_command(mc_io, &cmd);
  738. }
  739. /**
  740. * dpsw_vlan_remove() - Remove an entire VLAN
  741. * @mc_io: Pointer to MC portal's I/O object
  742. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  743. * @token: Token of DPSW object
  744. * @vlan_id: VLAN Identifier
  745. *
  746. * Return: Completion status. '0' on Success; Error code otherwise.
  747. */
  748. int dpsw_vlan_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  749. u16 vlan_id)
  750. {
  751. struct fsl_mc_command cmd = { 0 };
  752. struct dpsw_cmd_vlan_remove *cmd_params;
  753. /* prepare command */
  754. cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE,
  755. cmd_flags,
  756. token);
  757. cmd_params = (struct dpsw_cmd_vlan_remove *)cmd.params;
  758. cmd_params->vlan_id = cpu_to_le16(vlan_id);
  759. /* send command to mc*/
  760. return mc_send_command(mc_io, &cmd);
  761. }
  762. /**
  763. * dpsw_fdb_add() - Add FDB to switch and Returns handle to FDB table for
  764. * the reference
  765. * @mc_io: Pointer to MC portal's I/O object
  766. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  767. * @token: Token of DPSW object
  768. * @fdb_id: Returned Forwarding Database Identifier
  769. * @cfg: FDB Configuration
  770. *
  771. * Return: Completion status. '0' on Success; Error code otherwise.
  772. */
  773. int dpsw_fdb_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *fdb_id,
  774. const struct dpsw_fdb_cfg *cfg)
  775. {
  776. struct dpsw_cmd_fdb_add *cmd_params;
  777. struct dpsw_rsp_fdb_add *rsp_params;
  778. struct fsl_mc_command cmd = { 0 };
  779. int err;
  780. cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD,
  781. cmd_flags,
  782. token);
  783. cmd_params = (struct dpsw_cmd_fdb_add *)cmd.params;
  784. cmd_params->fdb_ageing_time = cpu_to_le16(cfg->fdb_ageing_time);
  785. cmd_params->num_fdb_entries = cpu_to_le16(cfg->num_fdb_entries);
  786. err = mc_send_command(mc_io, &cmd);
  787. if (err)
  788. return err;
  789. rsp_params = (struct dpsw_rsp_fdb_add *)cmd.params;
  790. *fdb_id = le16_to_cpu(rsp_params->fdb_id);
  791. return 0;
  792. }
  793. /**
  794. * dpsw_fdb_remove() - Remove FDB from switch
  795. * @mc_io: Pointer to MC portal's I/O object
  796. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  797. * @token: Token of DPSW object
  798. * @fdb_id: Forwarding Database Identifier
  799. *
  800. * Return: Completion status. '0' on Success; Error code otherwise.
  801. */
  802. int dpsw_fdb_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id)
  803. {
  804. struct dpsw_cmd_fdb_remove *cmd_params;
  805. struct fsl_mc_command cmd = { 0 };
  806. /* prepare command */
  807. cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE,
  808. cmd_flags,
  809. token);
  810. cmd_params = (struct dpsw_cmd_fdb_remove *)cmd.params;
  811. cmd_params->fdb_id = cpu_to_le16(fdb_id);
  812. return mc_send_command(mc_io, &cmd);
  813. }
  814. /**
  815. * dpsw_fdb_add_unicast() - Function adds an unicast entry into MAC lookup table
  816. * @mc_io: Pointer to MC portal's I/O object
  817. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  818. * @token: Token of DPSW object
  819. * @fdb_id: Forwarding Database Identifier
  820. * @cfg: Unicast entry configuration
  821. *
  822. * Return: Completion status. '0' on Success; Error code otherwise.
  823. */
  824. int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  825. u16 fdb_id, const struct dpsw_fdb_unicast_cfg *cfg)
  826. {
  827. struct fsl_mc_command cmd = { 0 };
  828. struct dpsw_cmd_fdb_unicast_op *cmd_params;
  829. int i;
  830. /* prepare command */
  831. cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD_UNICAST,
  832. cmd_flags,
  833. token);
  834. cmd_params = (struct dpsw_cmd_fdb_unicast_op *)cmd.params;
  835. cmd_params->fdb_id = cpu_to_le16(fdb_id);
  836. cmd_params->if_egress = cpu_to_le16(cfg->if_egress);
  837. for (i = 0; i < 6; i++)
  838. cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
  839. dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
  840. /* send command to mc*/
  841. return mc_send_command(mc_io, &cmd);
  842. }
  843. /**
  844. * dpsw_fdb_dump() - Dump the content of FDB table into memory.
  845. * @mc_io: Pointer to MC portal's I/O object
  846. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  847. * @token: Token of DPSW object
  848. * @fdb_id: Forwarding Database Identifier
  849. * @iova_addr: Data will be stored here as an array of struct fdb_dump_entry
  850. * @iova_size: Memory size allocated at iova_addr
  851. * @num_entries:Number of entries written at iova_addr
  852. *
  853. * Return: Completion status. '0' on Success; Error code otherwise.
  854. *
  855. * The memory allocated at iova_addr must be initialized with zero before
  856. * command execution. If the FDB table does not fit into memory MC will stop
  857. * after the memory is filled up.
  858. * The struct fdb_dump_entry array must be parsed until the end of memory
  859. * area or until an entry with mac_addr set to zero is found.
  860. */
  861. int dpsw_fdb_dump(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id,
  862. u64 iova_addr, u32 iova_size, u16 *num_entries)
  863. {
  864. struct dpsw_cmd_fdb_dump *cmd_params;
  865. struct dpsw_rsp_fdb_dump *rsp_params;
  866. struct fsl_mc_command cmd = { 0 };
  867. int err;
  868. /* prepare command */
  869. cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_DUMP,
  870. cmd_flags,
  871. token);
  872. cmd_params = (struct dpsw_cmd_fdb_dump *)cmd.params;
  873. cmd_params->fdb_id = cpu_to_le16(fdb_id);
  874. cmd_params->iova_addr = cpu_to_le64(iova_addr);
  875. cmd_params->iova_size = cpu_to_le32(iova_size);
  876. /* send command to mc */
  877. err = mc_send_command(mc_io, &cmd);
  878. if (err)
  879. return err;
  880. rsp_params = (struct dpsw_rsp_fdb_dump *)cmd.params;
  881. *num_entries = le16_to_cpu(rsp_params->num_entries);
  882. return 0;
  883. }
  884. /**
  885. * dpsw_fdb_remove_unicast() - removes an entry from MAC lookup table
  886. * @mc_io: Pointer to MC portal's I/O object
  887. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  888. * @token: Token of DPSW object
  889. * @fdb_id: Forwarding Database Identifier
  890. * @cfg: Unicast entry configuration
  891. *
  892. * Return: Completion status. '0' on Success; Error code otherwise.
  893. */
  894. int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  895. u16 fdb_id, const struct dpsw_fdb_unicast_cfg *cfg)
  896. {
  897. struct fsl_mc_command cmd = { 0 };
  898. struct dpsw_cmd_fdb_unicast_op *cmd_params;
  899. int i;
  900. /* prepare command */
  901. cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE_UNICAST,
  902. cmd_flags,
  903. token);
  904. cmd_params = (struct dpsw_cmd_fdb_unicast_op *)cmd.params;
  905. cmd_params->fdb_id = cpu_to_le16(fdb_id);
  906. for (i = 0; i < 6; i++)
  907. cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
  908. cmd_params->if_egress = cpu_to_le16(cfg->if_egress);
  909. dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
  910. /* send command to mc*/
  911. return mc_send_command(mc_io, &cmd);
  912. }
  913. /**
  914. * dpsw_fdb_add_multicast() - Add a set of egress interfaces to multi-cast group
  915. * @mc_io: Pointer to MC portal's I/O object
  916. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  917. * @token: Token of DPSW object
  918. * @fdb_id: Forwarding Database Identifier
  919. * @cfg: Multicast entry configuration
  920. *
  921. * If group doesn't exist, it will be created.
  922. * It adds only interfaces not belonging to this multicast group
  923. * yet, otherwise error will be generated and the command is
  924. * ignored.
  925. * This function may be called numerous times always providing
  926. * required interfaces delta.
  927. *
  928. * Return: Completion status. '0' on Success; Error code otherwise.
  929. */
  930. int dpsw_fdb_add_multicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  931. u16 fdb_id, const struct dpsw_fdb_multicast_cfg *cfg)
  932. {
  933. struct fsl_mc_command cmd = { 0 };
  934. struct dpsw_cmd_fdb_multicast_op *cmd_params;
  935. int i;
  936. /* prepare command */
  937. cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD_MULTICAST,
  938. cmd_flags,
  939. token);
  940. cmd_params = (struct dpsw_cmd_fdb_multicast_op *)cmd.params;
  941. cmd_params->fdb_id = cpu_to_le16(fdb_id);
  942. cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
  943. dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
  944. build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
  945. for (i = 0; i < 6; i++)
  946. cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
  947. /* send command to mc*/
  948. return mc_send_command(mc_io, &cmd);
  949. }
  950. /**
  951. * dpsw_fdb_remove_multicast() - Removing interfaces from an existing multicast
  952. * group.
  953. * @mc_io: Pointer to MC portal's I/O object
  954. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  955. * @token: Token of DPSW object
  956. * @fdb_id: Forwarding Database Identifier
  957. * @cfg: Multicast entry configuration
  958. *
  959. * Interfaces provided by this API have to exist in the group,
  960. * otherwise an error will be returned and an entire command
  961. * ignored. If there is no interface left in the group,
  962. * an entire group is deleted
  963. *
  964. * Return: Completion status. '0' on Success; Error code otherwise.
  965. */
  966. int dpsw_fdb_remove_multicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  967. u16 fdb_id, const struct dpsw_fdb_multicast_cfg *cfg)
  968. {
  969. struct fsl_mc_command cmd = { 0 };
  970. struct dpsw_cmd_fdb_multicast_op *cmd_params;
  971. int i;
  972. /* prepare command */
  973. cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE_MULTICAST,
  974. cmd_flags,
  975. token);
  976. cmd_params = (struct dpsw_cmd_fdb_multicast_op *)cmd.params;
  977. cmd_params->fdb_id = cpu_to_le16(fdb_id);
  978. cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
  979. dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
  980. build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
  981. for (i = 0; i < 6; i++)
  982. cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
  983. /* send command to mc*/
  984. return mc_send_command(mc_io, &cmd);
  985. }
  986. /**
  987. * dpsw_ctrl_if_get_attributes() - Obtain control interface attributes
  988. * @mc_io: Pointer to MC portal's I/O object
  989. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  990. * @token: Token of DPSW object
  991. * @attr: Returned control interface attributes
  992. *
  993. * Return: '0' on Success; Error code otherwise.
  994. */
  995. int dpsw_ctrl_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags,
  996. u16 token, struct dpsw_ctrl_if_attr *attr)
  997. {
  998. struct dpsw_rsp_ctrl_if_get_attr *rsp_params;
  999. struct fsl_mc_command cmd = { 0 };
  1000. int err;
  1001. cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_GET_ATTR,
  1002. cmd_flags, token);
  1003. err = mc_send_command(mc_io, &cmd);
  1004. if (err)
  1005. return err;
  1006. rsp_params = (struct dpsw_rsp_ctrl_if_get_attr *)cmd.params;
  1007. attr->rx_fqid = le32_to_cpu(rsp_params->rx_fqid);
  1008. attr->rx_err_fqid = le32_to_cpu(rsp_params->rx_err_fqid);
  1009. attr->tx_err_conf_fqid = le32_to_cpu(rsp_params->tx_err_conf_fqid);
  1010. return 0;
  1011. }
  1012. /**
  1013. * dpsw_ctrl_if_set_pools() - Set control interface buffer pools
  1014. * @mc_io: Pointer to MC portal's I/O object
  1015. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1016. * @token: Token of DPSW object
  1017. * @cfg: Buffer pools configuration
  1018. *
  1019. * Return: '0' on Success; Error code otherwise.
  1020. */
  1021. int dpsw_ctrl_if_set_pools(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1022. const struct dpsw_ctrl_if_pools_cfg *cfg)
  1023. {
  1024. struct dpsw_cmd_ctrl_if_set_pools *cmd_params;
  1025. struct fsl_mc_command cmd = { 0 };
  1026. int i;
  1027. cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_SET_POOLS,
  1028. cmd_flags, token);
  1029. cmd_params = (struct dpsw_cmd_ctrl_if_set_pools *)cmd.params;
  1030. cmd_params->num_dpbp = cfg->num_dpbp;
  1031. for (i = 0; i < DPSW_MAX_DPBP; i++) {
  1032. cmd_params->dpbp_id[i] = cpu_to_le32(cfg->pools[i].dpbp_id);
  1033. cmd_params->buffer_size[i] =
  1034. cpu_to_le16(cfg->pools[i].buffer_size);
  1035. cmd_params->backup_pool_mask |=
  1036. DPSW_BACKUP_POOL(cfg->pools[i].backup_pool, i);
  1037. }
  1038. return mc_send_command(mc_io, &cmd);
  1039. }
  1040. /**
  1041. * dpsw_ctrl_if_set_queue() - Set Rx queue configuration
  1042. * @mc_io: Pointer to MC portal's I/O object
  1043. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1044. * @token: Token of dpsw object
  1045. * @qtype: dpsw_queue_type of the targeted queue
  1046. * @cfg: Rx queue configuration
  1047. *
  1048. * Return: '0' on Success; Error code otherwise.
  1049. */
  1050. int dpsw_ctrl_if_set_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1051. enum dpsw_queue_type qtype,
  1052. const struct dpsw_ctrl_if_queue_cfg *cfg)
  1053. {
  1054. struct dpsw_cmd_ctrl_if_set_queue *cmd_params;
  1055. struct fsl_mc_command cmd = { 0 };
  1056. cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_SET_QUEUE,
  1057. cmd_flags,
  1058. token);
  1059. cmd_params = (struct dpsw_cmd_ctrl_if_set_queue *)cmd.params;
  1060. cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
  1061. cmd_params->dest_priority = cfg->dest_cfg.priority;
  1062. cmd_params->qtype = qtype;
  1063. cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
  1064. cmd_params->options = cpu_to_le32(cfg->options);
  1065. dpsw_set_field(cmd_params->dest_type,
  1066. DEST_TYPE,
  1067. cfg->dest_cfg.dest_type);
  1068. return mc_send_command(mc_io, &cmd);
  1069. }
  1070. /**
  1071. * dpsw_get_api_version() - Get Data Path Switch API version
  1072. * @mc_io: Pointer to MC portal's I/O object
  1073. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1074. * @major_ver: Major version of data path switch API
  1075. * @minor_ver: Minor version of data path switch API
  1076. *
  1077. * Return: '0' on Success; Error code otherwise.
  1078. */
  1079. int dpsw_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
  1080. u16 *major_ver, u16 *minor_ver)
  1081. {
  1082. struct fsl_mc_command cmd = { 0 };
  1083. struct dpsw_rsp_get_api_version *rsp_params;
  1084. int err;
  1085. cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_API_VERSION,
  1086. cmd_flags,
  1087. 0);
  1088. err = mc_send_command(mc_io, &cmd);
  1089. if (err)
  1090. return err;
  1091. rsp_params = (struct dpsw_rsp_get_api_version *)cmd.params;
  1092. *major_ver = le16_to_cpu(rsp_params->version_major);
  1093. *minor_ver = le16_to_cpu(rsp_params->version_minor);
  1094. return 0;
  1095. }
  1096. /**
  1097. * dpsw_if_get_port_mac_addr() - Retrieve MAC address associated to the physical port
  1098. * @mc_io: Pointer to MC portal's I/O object
  1099. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1100. * @token: Token of DPSW object
  1101. * @if_id: Interface Identifier
  1102. * @mac_addr: MAC address of the physical port, if any, otherwise 0
  1103. *
  1104. * Return: Completion status. '0' on Success; Error code otherwise.
  1105. */
  1106. int dpsw_if_get_port_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1107. u16 if_id, u8 mac_addr[6])
  1108. {
  1109. struct dpsw_rsp_if_get_mac_addr *rsp_params;
  1110. struct fsl_mc_command cmd = { 0 };
  1111. struct dpsw_cmd_if *cmd_params;
  1112. int err, i;
  1113. /* prepare command */
  1114. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_PORT_MAC_ADDR,
  1115. cmd_flags,
  1116. token);
  1117. cmd_params = (struct dpsw_cmd_if *)cmd.params;
  1118. cmd_params->if_id = cpu_to_le16(if_id);
  1119. /* send command to mc*/
  1120. err = mc_send_command(mc_io, &cmd);
  1121. if (err)
  1122. return err;
  1123. /* retrieve response parameters */
  1124. rsp_params = (struct dpsw_rsp_if_get_mac_addr *)cmd.params;
  1125. for (i = 0; i < 6; i++)
  1126. mac_addr[5 - i] = rsp_params->mac_addr[i];
  1127. return 0;
  1128. }
  1129. /**
  1130. * dpsw_ctrl_if_enable() - Enable control interface
  1131. * @mc_io: Pointer to MC portal's I/O object
  1132. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1133. * @token: Token of DPSW object
  1134. *
  1135. * Return: '0' on Success; Error code otherwise.
  1136. */
  1137. int dpsw_ctrl_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
  1138. {
  1139. struct fsl_mc_command cmd = { 0 };
  1140. cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_ENABLE, cmd_flags,
  1141. token);
  1142. return mc_send_command(mc_io, &cmd);
  1143. }
  1144. /**
  1145. * dpsw_ctrl_if_disable() - Function disables control interface
  1146. * @mc_io: Pointer to MC portal's I/O object
  1147. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1148. * @token: Token of DPSW object
  1149. *
  1150. * Return: '0' on Success; Error code otherwise.
  1151. */
  1152. int dpsw_ctrl_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
  1153. {
  1154. struct fsl_mc_command cmd = { 0 };
  1155. cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_DISABLE,
  1156. cmd_flags,
  1157. token);
  1158. return mc_send_command(mc_io, &cmd);
  1159. }
  1160. /**
  1161. * dpsw_set_egress_flood() - Set egress parameters associated with an FDB ID
  1162. * @mc_io: Pointer to MC portal's I/O object
  1163. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1164. * @token: Token of DPSW object
  1165. * @cfg: Egress flooding configuration
  1166. *
  1167. * Return: '0' on Success; Error code otherwise.
  1168. */
  1169. int dpsw_set_egress_flood(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1170. const struct dpsw_egress_flood_cfg *cfg)
  1171. {
  1172. struct dpsw_cmd_set_egress_flood *cmd_params;
  1173. struct fsl_mc_command cmd = { 0 };
  1174. cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_EGRESS_FLOOD, cmd_flags, token);
  1175. cmd_params = (struct dpsw_cmd_set_egress_flood *)cmd.params;
  1176. cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
  1177. cmd_params->flood_type = cfg->flood_type;
  1178. build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
  1179. return mc_send_command(mc_io, &cmd);
  1180. }
  1181. /**
  1182. * dpsw_if_set_learning_mode() - Configure the learning mode on an interface.
  1183. * If this API is used, it will take precedence over the FDB configuration.
  1184. * @mc_io: Pointer to MC portal's I/O object
  1185. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1186. * @token: Token of DPSW object
  1187. * @if_id: InterfaceID
  1188. * @mode: Learning mode
  1189. *
  1190. * Return: Completion status. '0' on Success; Error code otherwise.
  1191. */
  1192. int dpsw_if_set_learning_mode(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1193. u16 if_id, enum dpsw_learning_mode mode)
  1194. {
  1195. struct dpsw_cmd_if_set_learning_mode *cmd_params;
  1196. struct fsl_mc_command cmd = { 0 };
  1197. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_LEARNING_MODE,
  1198. cmd_flags,
  1199. token);
  1200. cmd_params = (struct dpsw_cmd_if_set_learning_mode *)cmd.params;
  1201. cmd_params->if_id = cpu_to_le16(if_id);
  1202. dpsw_set_field(cmd_params->mode, LEARNING_MODE, mode);
  1203. return mc_send_command(mc_io, &cmd);
  1204. }
  1205. /**
  1206. * dpsw_acl_add() - Create an ACL table
  1207. * @mc_io: Pointer to MC portal's I/O object
  1208. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1209. * @token: Token of DPSW object
  1210. * @acl_id: Returned ACL ID, for future references
  1211. * @cfg: ACL configuration
  1212. *
  1213. * Create Access Control List table. Multiple ACLs can be created and
  1214. * co-exist in L2 switch
  1215. *
  1216. * Return: '0' on Success; Error code otherwise.
  1217. */
  1218. int dpsw_acl_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *acl_id,
  1219. const struct dpsw_acl_cfg *cfg)
  1220. {
  1221. struct dpsw_cmd_acl_add *cmd_params;
  1222. struct dpsw_rsp_acl_add *rsp_params;
  1223. struct fsl_mc_command cmd = { 0 };
  1224. int err;
  1225. cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD, cmd_flags, token);
  1226. cmd_params = (struct dpsw_cmd_acl_add *)cmd.params;
  1227. cmd_params->max_entries = cpu_to_le16(cfg->max_entries);
  1228. err = mc_send_command(mc_io, &cmd);
  1229. if (err)
  1230. return err;
  1231. rsp_params = (struct dpsw_rsp_acl_add *)cmd.params;
  1232. *acl_id = le16_to_cpu(rsp_params->acl_id);
  1233. return 0;
  1234. }
  1235. /**
  1236. * dpsw_acl_remove() - Remove an ACL table from L2 switch.
  1237. * @mc_io: Pointer to MC portal's I/O object
  1238. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1239. * @token: Token of DPSW object
  1240. * @acl_id: ACL ID
  1241. *
  1242. * Return: '0' on Success; Error code otherwise.
  1243. */
  1244. int dpsw_acl_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1245. u16 acl_id)
  1246. {
  1247. struct dpsw_cmd_acl_remove *cmd_params;
  1248. struct fsl_mc_command cmd = { 0 };
  1249. cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE, cmd_flags,
  1250. token);
  1251. cmd_params = (struct dpsw_cmd_acl_remove *)cmd.params;
  1252. cmd_params->acl_id = cpu_to_le16(acl_id);
  1253. return mc_send_command(mc_io, &cmd);
  1254. }
  1255. /**
  1256. * dpsw_acl_add_if() - Associate interface/interfaces with an ACL table.
  1257. * @mc_io: Pointer to MC portal's I/O object
  1258. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1259. * @token: Token of DPSW object
  1260. * @acl_id: ACL ID
  1261. * @cfg: Interfaces list
  1262. *
  1263. * Return: '0' on Success; Error code otherwise.
  1264. */
  1265. int dpsw_acl_add_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1266. u16 acl_id, const struct dpsw_acl_if_cfg *cfg)
  1267. {
  1268. struct dpsw_cmd_acl_if *cmd_params;
  1269. struct fsl_mc_command cmd = { 0 };
  1270. cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD_IF, cmd_flags,
  1271. token);
  1272. cmd_params = (struct dpsw_cmd_acl_if *)cmd.params;
  1273. cmd_params->acl_id = cpu_to_le16(acl_id);
  1274. cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
  1275. build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
  1276. return mc_send_command(mc_io, &cmd);
  1277. }
  1278. /**
  1279. * dpsw_acl_remove_if() - De-associate interface/interfaces from an ACL table
  1280. * @mc_io: Pointer to MC portal's I/O object
  1281. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1282. * @token: Token of DPSW object
  1283. * @acl_id: ACL ID
  1284. * @cfg: Interfaces list
  1285. *
  1286. * Return: '0' on Success; Error code otherwise.
  1287. */
  1288. int dpsw_acl_remove_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1289. u16 acl_id, const struct dpsw_acl_if_cfg *cfg)
  1290. {
  1291. struct dpsw_cmd_acl_if *cmd_params;
  1292. struct fsl_mc_command cmd = { 0 };
  1293. /* prepare command */
  1294. cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE_IF, cmd_flags,
  1295. token);
  1296. cmd_params = (struct dpsw_cmd_acl_if *)cmd.params;
  1297. cmd_params->acl_id = cpu_to_le16(acl_id);
  1298. cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
  1299. build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
  1300. /* send command to mc*/
  1301. return mc_send_command(mc_io, &cmd);
  1302. }
  1303. /**
  1304. * dpsw_acl_prepare_entry_cfg() - Setup an ACL entry
  1305. * @key: Key
  1306. * @entry_cfg_buf: Zeroed 256 bytes of memory before mapping it to DMA
  1307. *
  1308. * This function has to be called before adding or removing acl_entry
  1309. *
  1310. */
  1311. void dpsw_acl_prepare_entry_cfg(const struct dpsw_acl_key *key,
  1312. u8 *entry_cfg_buf)
  1313. {
  1314. struct dpsw_prep_acl_entry *ext_params;
  1315. int i;
  1316. ext_params = (struct dpsw_prep_acl_entry *)entry_cfg_buf;
  1317. for (i = 0; i < 6; i++) {
  1318. ext_params->match_l2_dest_mac[i] = key->match.l2_dest_mac[5 - i];
  1319. ext_params->match_l2_source_mac[i] = key->match.l2_source_mac[5 - i];
  1320. ext_params->mask_l2_dest_mac[i] = key->mask.l2_dest_mac[5 - i];
  1321. ext_params->mask_l2_source_mac[i] = key->mask.l2_source_mac[5 - i];
  1322. }
  1323. ext_params->match_l2_tpid = cpu_to_le16(key->match.l2_tpid);
  1324. ext_params->match_l2_vlan_id = cpu_to_le16(key->match.l2_vlan_id);
  1325. ext_params->match_l3_dest_ip = cpu_to_le32(key->match.l3_dest_ip);
  1326. ext_params->match_l3_source_ip = cpu_to_le32(key->match.l3_source_ip);
  1327. ext_params->match_l4_dest_port = cpu_to_le16(key->match.l4_dest_port);
  1328. ext_params->match_l4_source_port = cpu_to_le16(key->match.l4_source_port);
  1329. ext_params->match_l2_ether_type = cpu_to_le16(key->match.l2_ether_type);
  1330. ext_params->match_l2_pcp_dei = key->match.l2_pcp_dei;
  1331. ext_params->match_l3_dscp = key->match.l3_dscp;
  1332. ext_params->mask_l2_tpid = cpu_to_le16(key->mask.l2_tpid);
  1333. ext_params->mask_l2_vlan_id = cpu_to_le16(key->mask.l2_vlan_id);
  1334. ext_params->mask_l3_dest_ip = cpu_to_le32(key->mask.l3_dest_ip);
  1335. ext_params->mask_l3_source_ip = cpu_to_le32(key->mask.l3_source_ip);
  1336. ext_params->mask_l4_dest_port = cpu_to_le16(key->mask.l4_dest_port);
  1337. ext_params->mask_l4_source_port = cpu_to_le16(key->mask.l4_source_port);
  1338. ext_params->mask_l2_ether_type = cpu_to_le16(key->mask.l2_ether_type);
  1339. ext_params->mask_l2_pcp_dei = key->mask.l2_pcp_dei;
  1340. ext_params->mask_l3_dscp = key->mask.l3_dscp;
  1341. ext_params->match_l3_protocol = key->match.l3_protocol;
  1342. ext_params->mask_l3_protocol = key->mask.l3_protocol;
  1343. }
  1344. /**
  1345. * dpsw_acl_add_entry() - Add a rule to the ACL table.
  1346. * @mc_io: Pointer to MC portal's I/O object
  1347. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1348. * @token: Token of DPSW object
  1349. * @acl_id: ACL ID
  1350. * @cfg: Entry configuration
  1351. *
  1352. * warning: This function has to be called after dpsw_acl_prepare_entry_cfg()
  1353. *
  1354. * Return: '0' on Success; Error code otherwise.
  1355. */
  1356. int dpsw_acl_add_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1357. u16 acl_id, const struct dpsw_acl_entry_cfg *cfg)
  1358. {
  1359. struct dpsw_cmd_acl_entry *cmd_params;
  1360. struct fsl_mc_command cmd = { 0 };
  1361. cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD_ENTRY, cmd_flags,
  1362. token);
  1363. cmd_params = (struct dpsw_cmd_acl_entry *)cmd.params;
  1364. cmd_params->acl_id = cpu_to_le16(acl_id);
  1365. cmd_params->result_if_id = cpu_to_le16(cfg->result.if_id);
  1366. cmd_params->precedence = cpu_to_le32(cfg->precedence);
  1367. cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
  1368. dpsw_set_field(cmd_params->result_action,
  1369. RESULT_ACTION,
  1370. cfg->result.action);
  1371. return mc_send_command(mc_io, &cmd);
  1372. }
  1373. /**
  1374. * dpsw_acl_remove_entry() - Removes an entry from ACL.
  1375. * @mc_io: Pointer to MC portal's I/O object
  1376. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1377. * @token: Token of DPSW object
  1378. * @acl_id: ACL ID
  1379. * @cfg: Entry configuration
  1380. *
  1381. * warning: This function has to be called after dpsw_acl_set_entry_cfg()
  1382. *
  1383. * Return: '0' on Success; Error code otherwise.
  1384. */
  1385. int dpsw_acl_remove_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1386. u16 acl_id, const struct dpsw_acl_entry_cfg *cfg)
  1387. {
  1388. struct dpsw_cmd_acl_entry *cmd_params;
  1389. struct fsl_mc_command cmd = { 0 };
  1390. /* prepare command */
  1391. cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE_ENTRY,
  1392. cmd_flags,
  1393. token);
  1394. cmd_params = (struct dpsw_cmd_acl_entry *)cmd.params;
  1395. cmd_params->acl_id = cpu_to_le16(acl_id);
  1396. cmd_params->result_if_id = cpu_to_le16(cfg->result.if_id);
  1397. cmd_params->precedence = cpu_to_le32(cfg->precedence);
  1398. cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
  1399. dpsw_set_field(cmd_params->result_action,
  1400. RESULT_ACTION,
  1401. cfg->result.action);
  1402. /* send command to mc*/
  1403. return mc_send_command(mc_io, &cmd);
  1404. }
  1405. /**
  1406. * dpsw_set_reflection_if() - Set target interface for traffic mirrored
  1407. * @mc_io: Pointer to MC portal's I/O object
  1408. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1409. * @token: Token of DPSW object
  1410. * @if_id: Interface Id
  1411. *
  1412. * Only one mirroring destination is allowed per switch
  1413. *
  1414. * Return: Completion status. '0' on Success; Error code otherwise.
  1415. */
  1416. int dpsw_set_reflection_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1417. u16 if_id)
  1418. {
  1419. struct dpsw_cmd_set_reflection_if *cmd_params;
  1420. struct fsl_mc_command cmd = { 0 };
  1421. cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_REFLECTION_IF,
  1422. cmd_flags,
  1423. token);
  1424. cmd_params = (struct dpsw_cmd_set_reflection_if *)cmd.params;
  1425. cmd_params->if_id = cpu_to_le16(if_id);
  1426. return mc_send_command(mc_io, &cmd);
  1427. }
  1428. /**
  1429. * dpsw_if_add_reflection() - Setup mirroring rule
  1430. * @mc_io: Pointer to MC portal's I/O object
  1431. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1432. * @token: Token of DPSW object
  1433. * @if_id: Interface Identifier
  1434. * @cfg: Reflection configuration
  1435. *
  1436. * Return: Completion status. '0' on Success; Error code otherwise.
  1437. */
  1438. int dpsw_if_add_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1439. u16 if_id, const struct dpsw_reflection_cfg *cfg)
  1440. {
  1441. struct dpsw_cmd_if_reflection *cmd_params;
  1442. struct fsl_mc_command cmd = { 0 };
  1443. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_ADD_REFLECTION,
  1444. cmd_flags,
  1445. token);
  1446. cmd_params = (struct dpsw_cmd_if_reflection *)cmd.params;
  1447. cmd_params->if_id = cpu_to_le16(if_id);
  1448. cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
  1449. dpsw_set_field(cmd_params->filter, FILTER, cfg->filter);
  1450. return mc_send_command(mc_io, &cmd);
  1451. }
  1452. /**
  1453. * dpsw_if_remove_reflection() - Remove mirroring rule
  1454. * @mc_io: Pointer to MC portal's I/O object
  1455. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  1456. * @token: Token of DPSW object
  1457. * @if_id: Interface Identifier
  1458. * @cfg: Reflection configuration
  1459. *
  1460. * Return: Completion status. '0' on Success; Error code otherwise.
  1461. */
  1462. int dpsw_if_remove_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
  1463. u16 if_id, const struct dpsw_reflection_cfg *cfg)
  1464. {
  1465. struct dpsw_cmd_if_reflection *cmd_params;
  1466. struct fsl_mc_command cmd = { 0 };
  1467. cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_REMOVE_REFLECTION,
  1468. cmd_flags,
  1469. token);
  1470. cmd_params = (struct dpsw_cmd_if_reflection *)cmd.params;
  1471. cmd_params->if_id = cpu_to_le16(if_id);
  1472. cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
  1473. dpsw_set_field(cmd_params->filter, FILTER, cfg->filter);
  1474. return mc_send_command(mc_io, &cmd);
  1475. }