cpsw_ale.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. * Texas Instruments 3-Port Ethernet Switch Address Lookup Engine
  3. *
  4. * Copyright (C) 2012 Texas Instruments
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation version 2.
  9. *
  10. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  11. * kind, whether express or implied; without even the implied warranty
  12. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/slab.h>
  19. #include <linux/err.h>
  20. #include <linux/io.h>
  21. #include <linux/stat.h>
  22. #include <linux/sysfs.h>
  23. #include "cpsw_ale.h"
  24. #define BITMASK(bits) (BIT(bits) - 1)
  25. #define ALE_ENTRY_BITS 68
  26. #define ALE_ENTRY_WORDS DIV_ROUND_UP(ALE_ENTRY_BITS, 32)
  27. #define ALE_VERSION_MAJOR(rev) ((rev >> 8) & 0xff)
  28. #define ALE_VERSION_MINOR(rev) (rev & 0xff)
  29. /* ALE Registers */
  30. #define ALE_IDVER 0x00
  31. #define ALE_CONTROL 0x08
  32. #define ALE_PRESCALE 0x10
  33. #define ALE_UNKNOWNVLAN 0x18
  34. #define ALE_TABLE_CONTROL 0x20
  35. #define ALE_TABLE 0x34
  36. #define ALE_PORTCTL 0x40
  37. #define ALE_TABLE_WRITE BIT(31)
  38. #define ALE_TYPE_FREE 0
  39. #define ALE_TYPE_ADDR 1
  40. #define ALE_TYPE_VLAN 2
  41. #define ALE_TYPE_VLAN_ADDR 3
  42. #define ALE_UCAST_PERSISTANT 0
  43. #define ALE_UCAST_UNTOUCHED 1
  44. #define ALE_UCAST_OUI 2
  45. #define ALE_UCAST_TOUCHED 3
  46. static inline int cpsw_ale_get_field(u32 *ale_entry, u32 start, u32 bits)
  47. {
  48. int idx;
  49. idx = start / 32;
  50. start -= idx * 32;
  51. idx = 2 - idx; /* flip */
  52. return (ale_entry[idx] >> start) & BITMASK(bits);
  53. }
  54. static inline void cpsw_ale_set_field(u32 *ale_entry, u32 start, u32 bits,
  55. u32 value)
  56. {
  57. int idx;
  58. value &= BITMASK(bits);
  59. idx = start / 32;
  60. start -= idx * 32;
  61. idx = 2 - idx; /* flip */
  62. ale_entry[idx] &= ~(BITMASK(bits) << start);
  63. ale_entry[idx] |= (value << start);
  64. }
  65. #define DEFINE_ALE_FIELD(name, start, bits) \
  66. static inline int cpsw_ale_get_##name(u32 *ale_entry) \
  67. { \
  68. return cpsw_ale_get_field(ale_entry, start, bits); \
  69. } \
  70. static inline void cpsw_ale_set_##name(u32 *ale_entry, u32 value) \
  71. { \
  72. cpsw_ale_set_field(ale_entry, start, bits, value); \
  73. }
  74. DEFINE_ALE_FIELD(entry_type, 60, 2)
  75. DEFINE_ALE_FIELD(vlan_id, 48, 12)
  76. DEFINE_ALE_FIELD(mcast_state, 62, 2)
  77. DEFINE_ALE_FIELD(port_mask, 66, 3)
  78. DEFINE_ALE_FIELD(super, 65, 1)
  79. DEFINE_ALE_FIELD(ucast_type, 62, 2)
  80. DEFINE_ALE_FIELD(port_num, 66, 2)
  81. DEFINE_ALE_FIELD(blocked, 65, 1)
  82. DEFINE_ALE_FIELD(secure, 64, 1)
  83. DEFINE_ALE_FIELD(vlan_untag_force, 24, 3)
  84. DEFINE_ALE_FIELD(vlan_reg_mcast, 16, 3)
  85. DEFINE_ALE_FIELD(vlan_unreg_mcast, 8, 3)
  86. DEFINE_ALE_FIELD(vlan_member_list, 0, 3)
  87. DEFINE_ALE_FIELD(mcast, 40, 1)
  88. /* The MAC address field in the ALE entry cannot be macroized as above */
  89. static inline void cpsw_ale_get_addr(u32 *ale_entry, u8 *addr)
  90. {
  91. int i;
  92. for (i = 0; i < 6; i++)
  93. addr[i] = cpsw_ale_get_field(ale_entry, 40 - 8*i, 8);
  94. }
  95. static inline void cpsw_ale_set_addr(u32 *ale_entry, u8 *addr)
  96. {
  97. int i;
  98. for (i = 0; i < 6; i++)
  99. cpsw_ale_set_field(ale_entry, 40 - 8*i, 8, addr[i]);
  100. }
  101. static int cpsw_ale_read(struct cpsw_ale *ale, int idx, u32 *ale_entry)
  102. {
  103. int i;
  104. WARN_ON(idx > ale->params.ale_entries);
  105. __raw_writel(idx, ale->params.ale_regs + ALE_TABLE_CONTROL);
  106. for (i = 0; i < ALE_ENTRY_WORDS; i++)
  107. ale_entry[i] = __raw_readl(ale->params.ale_regs +
  108. ALE_TABLE + 4 * i);
  109. return idx;
  110. }
  111. static int cpsw_ale_write(struct cpsw_ale *ale, int idx, u32 *ale_entry)
  112. {
  113. int i;
  114. WARN_ON(idx > ale->params.ale_entries);
  115. for (i = 0; i < ALE_ENTRY_WORDS; i++)
  116. __raw_writel(ale_entry[i], ale->params.ale_regs +
  117. ALE_TABLE + 4 * i);
  118. __raw_writel(idx | ALE_TABLE_WRITE, ale->params.ale_regs +
  119. ALE_TABLE_CONTROL);
  120. return idx;
  121. }
  122. static int cpsw_ale_match_addr(struct cpsw_ale *ale, u8 *addr)
  123. {
  124. u32 ale_entry[ALE_ENTRY_WORDS];
  125. int type, idx;
  126. for (idx = 0; idx < ale->params.ale_entries; idx++) {
  127. u8 entry_addr[6];
  128. cpsw_ale_read(ale, idx, ale_entry);
  129. type = cpsw_ale_get_entry_type(ale_entry);
  130. if (type != ALE_TYPE_ADDR && type != ALE_TYPE_VLAN_ADDR)
  131. continue;
  132. cpsw_ale_get_addr(ale_entry, entry_addr);
  133. if (memcmp(entry_addr, addr, 6) == 0)
  134. return idx;
  135. }
  136. return -ENOENT;
  137. }
  138. static int cpsw_ale_match_free(struct cpsw_ale *ale)
  139. {
  140. u32 ale_entry[ALE_ENTRY_WORDS];
  141. int type, idx;
  142. for (idx = 0; idx < ale->params.ale_entries; idx++) {
  143. cpsw_ale_read(ale, idx, ale_entry);
  144. type = cpsw_ale_get_entry_type(ale_entry);
  145. if (type == ALE_TYPE_FREE)
  146. return idx;
  147. }
  148. return -ENOENT;
  149. }
  150. static int cpsw_ale_find_ageable(struct cpsw_ale *ale)
  151. {
  152. u32 ale_entry[ALE_ENTRY_WORDS];
  153. int type, idx;
  154. for (idx = 0; idx < ale->params.ale_entries; idx++) {
  155. cpsw_ale_read(ale, idx, ale_entry);
  156. type = cpsw_ale_get_entry_type(ale_entry);
  157. if (type != ALE_TYPE_ADDR && type != ALE_TYPE_VLAN_ADDR)
  158. continue;
  159. if (cpsw_ale_get_mcast(ale_entry))
  160. continue;
  161. type = cpsw_ale_get_ucast_type(ale_entry);
  162. if (type != ALE_UCAST_PERSISTANT &&
  163. type != ALE_UCAST_OUI)
  164. return idx;
  165. }
  166. return -ENOENT;
  167. }
  168. static void cpsw_ale_flush_mcast(struct cpsw_ale *ale, u32 *ale_entry,
  169. int port_mask)
  170. {
  171. int mask;
  172. mask = cpsw_ale_get_port_mask(ale_entry);
  173. if ((mask & port_mask) == 0)
  174. return; /* ports dont intersect, not interested */
  175. mask &= ~port_mask;
  176. /* free if only remaining port is host port */
  177. if (mask == BIT(ale->params.ale_ports))
  178. cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
  179. else
  180. cpsw_ale_set_port_mask(ale_entry, mask);
  181. }
  182. static void cpsw_ale_flush_ucast(struct cpsw_ale *ale, u32 *ale_entry,
  183. int port_mask)
  184. {
  185. int port;
  186. port = cpsw_ale_get_port_num(ale_entry);
  187. if ((BIT(port) & port_mask) == 0)
  188. return; /* ports dont intersect, not interested */
  189. cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
  190. }
  191. int cpsw_ale_flush(struct cpsw_ale *ale, int port_mask)
  192. {
  193. u32 ale_entry[ALE_ENTRY_WORDS];
  194. int ret, idx;
  195. for (idx = 0; idx < ale->params.ale_entries; idx++) {
  196. cpsw_ale_read(ale, idx, ale_entry);
  197. ret = cpsw_ale_get_entry_type(ale_entry);
  198. if (ret != ALE_TYPE_ADDR && ret != ALE_TYPE_VLAN_ADDR)
  199. continue;
  200. if (cpsw_ale_get_mcast(ale_entry))
  201. cpsw_ale_flush_mcast(ale, ale_entry, port_mask);
  202. else
  203. cpsw_ale_flush_ucast(ale, ale_entry, port_mask);
  204. cpsw_ale_write(ale, idx, ale_entry);
  205. }
  206. return 0;
  207. }
  208. int cpsw_ale_add_ucast(struct cpsw_ale *ale, u8 *addr, int port, int flags)
  209. {
  210. u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
  211. int idx;
  212. cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_ADDR);
  213. cpsw_ale_set_addr(ale_entry, addr);
  214. cpsw_ale_set_ucast_type(ale_entry, ALE_UCAST_PERSISTANT);
  215. cpsw_ale_set_secure(ale_entry, (flags & ALE_SECURE) ? 1 : 0);
  216. cpsw_ale_set_blocked(ale_entry, (flags & ALE_BLOCKED) ? 1 : 0);
  217. cpsw_ale_set_port_num(ale_entry, port);
  218. idx = cpsw_ale_match_addr(ale, addr);
  219. if (idx < 0)
  220. idx = cpsw_ale_match_free(ale);
  221. if (idx < 0)
  222. idx = cpsw_ale_find_ageable(ale);
  223. if (idx < 0)
  224. return -ENOMEM;
  225. cpsw_ale_write(ale, idx, ale_entry);
  226. return 0;
  227. }
  228. int cpsw_ale_del_ucast(struct cpsw_ale *ale, u8 *addr, int port)
  229. {
  230. u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
  231. int idx;
  232. idx = cpsw_ale_match_addr(ale, addr);
  233. if (idx < 0)
  234. return -ENOENT;
  235. cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
  236. cpsw_ale_write(ale, idx, ale_entry);
  237. return 0;
  238. }
  239. int cpsw_ale_add_mcast(struct cpsw_ale *ale, u8 *addr, int port_mask,
  240. int super, int mcast_state)
  241. {
  242. u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
  243. int idx, mask;
  244. idx = cpsw_ale_match_addr(ale, addr);
  245. if (idx >= 0)
  246. cpsw_ale_read(ale, idx, ale_entry);
  247. cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_ADDR);
  248. cpsw_ale_set_addr(ale_entry, addr);
  249. cpsw_ale_set_super(ale_entry, super);
  250. cpsw_ale_set_mcast_state(ale_entry, mcast_state);
  251. mask = cpsw_ale_get_port_mask(ale_entry);
  252. port_mask |= mask;
  253. cpsw_ale_set_port_mask(ale_entry, port_mask);
  254. if (idx < 0)
  255. idx = cpsw_ale_match_free(ale);
  256. if (idx < 0)
  257. idx = cpsw_ale_find_ageable(ale);
  258. if (idx < 0)
  259. return -ENOMEM;
  260. cpsw_ale_write(ale, idx, ale_entry);
  261. return 0;
  262. }
  263. int cpsw_ale_del_mcast(struct cpsw_ale *ale, u8 *addr, int port_mask)
  264. {
  265. u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
  266. int idx;
  267. idx = cpsw_ale_match_addr(ale, addr);
  268. if (idx < 0)
  269. return -EINVAL;
  270. cpsw_ale_read(ale, idx, ale_entry);
  271. if (port_mask)
  272. cpsw_ale_set_port_mask(ale_entry, port_mask);
  273. else
  274. cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
  275. cpsw_ale_write(ale, idx, ale_entry);
  276. return 0;
  277. }
  278. struct ale_control_info {
  279. const char *name;
  280. int offset, port_offset;
  281. int shift, port_shift;
  282. int bits;
  283. };
  284. static const struct ale_control_info ale_controls[ALE_NUM_CONTROLS] = {
  285. [ALE_ENABLE] = {
  286. .name = "enable",
  287. .offset = ALE_CONTROL,
  288. .port_offset = 0,
  289. .shift = 31,
  290. .port_shift = 0,
  291. .bits = 1,
  292. },
  293. [ALE_CLEAR] = {
  294. .name = "clear",
  295. .offset = ALE_CONTROL,
  296. .port_offset = 0,
  297. .shift = 30,
  298. .port_shift = 0,
  299. .bits = 1,
  300. },
  301. [ALE_AGEOUT] = {
  302. .name = "ageout",
  303. .offset = ALE_CONTROL,
  304. .port_offset = 0,
  305. .shift = 29,
  306. .port_shift = 0,
  307. .bits = 1,
  308. },
  309. [ALE_VLAN_NOLEARN] = {
  310. .name = "vlan_nolearn",
  311. .offset = ALE_CONTROL,
  312. .port_offset = 0,
  313. .shift = 7,
  314. .port_shift = 0,
  315. .bits = 1,
  316. },
  317. [ALE_NO_PORT_VLAN] = {
  318. .name = "no_port_vlan",
  319. .offset = ALE_CONTROL,
  320. .port_offset = 0,
  321. .shift = 6,
  322. .port_shift = 0,
  323. .bits = 1,
  324. },
  325. [ALE_OUI_DENY] = {
  326. .name = "oui_deny",
  327. .offset = ALE_CONTROL,
  328. .port_offset = 0,
  329. .shift = 5,
  330. .port_shift = 0,
  331. .bits = 1,
  332. },
  333. [ALE_BYPASS] = {
  334. .name = "bypass",
  335. .offset = ALE_CONTROL,
  336. .port_offset = 0,
  337. .shift = 4,
  338. .port_shift = 0,
  339. .bits = 1,
  340. },
  341. [ALE_RATE_LIMIT_TX] = {
  342. .name = "rate_limit_tx",
  343. .offset = ALE_CONTROL,
  344. .port_offset = 0,
  345. .shift = 3,
  346. .port_shift = 0,
  347. .bits = 1,
  348. },
  349. [ALE_VLAN_AWARE] = {
  350. .name = "vlan_aware",
  351. .offset = ALE_CONTROL,
  352. .port_offset = 0,
  353. .shift = 2,
  354. .port_shift = 0,
  355. .bits = 1,
  356. },
  357. [ALE_AUTH_ENABLE] = {
  358. .name = "auth_enable",
  359. .offset = ALE_CONTROL,
  360. .port_offset = 0,
  361. .shift = 1,
  362. .port_shift = 0,
  363. .bits = 1,
  364. },
  365. [ALE_RATE_LIMIT] = {
  366. .name = "rate_limit",
  367. .offset = ALE_CONTROL,
  368. .port_offset = 0,
  369. .shift = 0,
  370. .port_shift = 0,
  371. .bits = 1,
  372. },
  373. [ALE_PORT_STATE] = {
  374. .name = "port_state",
  375. .offset = ALE_PORTCTL,
  376. .port_offset = 4,
  377. .shift = 0,
  378. .port_shift = 0,
  379. .bits = 2,
  380. },
  381. [ALE_PORT_DROP_UNTAGGED] = {
  382. .name = "drop_untagged",
  383. .offset = ALE_PORTCTL,
  384. .port_offset = 4,
  385. .shift = 2,
  386. .port_shift = 0,
  387. .bits = 1,
  388. },
  389. [ALE_PORT_DROP_UNKNOWN_VLAN] = {
  390. .name = "drop_unknown",
  391. .offset = ALE_PORTCTL,
  392. .port_offset = 4,
  393. .shift = 3,
  394. .port_shift = 0,
  395. .bits = 1,
  396. },
  397. [ALE_PORT_NOLEARN] = {
  398. .name = "nolearn",
  399. .offset = ALE_PORTCTL,
  400. .port_offset = 4,
  401. .shift = 4,
  402. .port_shift = 0,
  403. .bits = 1,
  404. },
  405. [ALE_PORT_MCAST_LIMIT] = {
  406. .name = "mcast_limit",
  407. .offset = ALE_PORTCTL,
  408. .port_offset = 4,
  409. .shift = 16,
  410. .port_shift = 0,
  411. .bits = 8,
  412. },
  413. [ALE_PORT_BCAST_LIMIT] = {
  414. .name = "bcast_limit",
  415. .offset = ALE_PORTCTL,
  416. .port_offset = 4,
  417. .shift = 24,
  418. .port_shift = 0,
  419. .bits = 8,
  420. },
  421. [ALE_PORT_UNKNOWN_VLAN_MEMBER] = {
  422. .name = "unknown_vlan_member",
  423. .offset = ALE_UNKNOWNVLAN,
  424. .port_offset = 0,
  425. .shift = 0,
  426. .port_shift = 0,
  427. .bits = 6,
  428. },
  429. [ALE_PORT_UNKNOWN_MCAST_FLOOD] = {
  430. .name = "unknown_mcast_flood",
  431. .offset = ALE_UNKNOWNVLAN,
  432. .port_offset = 0,
  433. .shift = 8,
  434. .port_shift = 0,
  435. .bits = 6,
  436. },
  437. [ALE_PORT_UNKNOWN_REG_MCAST_FLOOD] = {
  438. .name = "unknown_reg_flood",
  439. .offset = ALE_UNKNOWNVLAN,
  440. .port_offset = 0,
  441. .shift = 16,
  442. .port_shift = 0,
  443. .bits = 6,
  444. },
  445. [ALE_PORT_UNTAGGED_EGRESS] = {
  446. .name = "untagged_egress",
  447. .offset = ALE_UNKNOWNVLAN,
  448. .port_offset = 0,
  449. .shift = 24,
  450. .port_shift = 0,
  451. .bits = 6,
  452. },
  453. };
  454. int cpsw_ale_control_set(struct cpsw_ale *ale, int port, int control,
  455. int value)
  456. {
  457. const struct ale_control_info *info;
  458. int offset, shift;
  459. u32 tmp, mask;
  460. if (control < 0 || control >= ARRAY_SIZE(ale_controls))
  461. return -EINVAL;
  462. info = &ale_controls[control];
  463. if (info->port_offset == 0 && info->port_shift == 0)
  464. port = 0; /* global, port is a dont care */
  465. if (port < 0 || port > ale->params.ale_ports)
  466. return -EINVAL;
  467. mask = BITMASK(info->bits);
  468. if (value & ~mask)
  469. return -EINVAL;
  470. offset = info->offset + (port * info->port_offset);
  471. shift = info->shift + (port * info->port_shift);
  472. tmp = __raw_readl(ale->params.ale_regs + offset);
  473. tmp = (tmp & ~(mask << shift)) | (value << shift);
  474. __raw_writel(tmp, ale->params.ale_regs + offset);
  475. return 0;
  476. }
  477. int cpsw_ale_control_get(struct cpsw_ale *ale, int port, int control)
  478. {
  479. const struct ale_control_info *info;
  480. int offset, shift;
  481. u32 tmp;
  482. if (control < 0 || control >= ARRAY_SIZE(ale_controls))
  483. return -EINVAL;
  484. info = &ale_controls[control];
  485. if (info->port_offset == 0 && info->port_shift == 0)
  486. port = 0; /* global, port is a dont care */
  487. if (port < 0 || port > ale->params.ale_ports)
  488. return -EINVAL;
  489. offset = info->offset + (port * info->port_offset);
  490. shift = info->shift + (port * info->port_shift);
  491. tmp = __raw_readl(ale->params.ale_regs + offset) >> shift;
  492. return tmp & BITMASK(info->bits);
  493. }
  494. static void cpsw_ale_timer(unsigned long arg)
  495. {
  496. struct cpsw_ale *ale = (struct cpsw_ale *)arg;
  497. cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
  498. if (ale->ageout) {
  499. ale->timer.expires = jiffies + ale->ageout;
  500. add_timer(&ale->timer);
  501. }
  502. }
  503. int cpsw_ale_set_ageout(struct cpsw_ale *ale, int ageout)
  504. {
  505. del_timer_sync(&ale->timer);
  506. ale->ageout = ageout * HZ;
  507. if (ale->ageout) {
  508. ale->timer.expires = jiffies + ale->ageout;
  509. add_timer(&ale->timer);
  510. }
  511. return 0;
  512. }
  513. void cpsw_ale_start(struct cpsw_ale *ale)
  514. {
  515. u32 rev;
  516. rev = __raw_readl(ale->params.ale_regs + ALE_IDVER);
  517. dev_dbg(ale->params.dev, "initialized cpsw ale revision %d.%d\n",
  518. ALE_VERSION_MAJOR(rev), ALE_VERSION_MINOR(rev));
  519. cpsw_ale_control_set(ale, 0, ALE_ENABLE, 1);
  520. cpsw_ale_control_set(ale, 0, ALE_CLEAR, 1);
  521. init_timer(&ale->timer);
  522. ale->timer.data = (unsigned long)ale;
  523. ale->timer.function = cpsw_ale_timer;
  524. if (ale->ageout) {
  525. ale->timer.expires = jiffies + ale->ageout;
  526. add_timer(&ale->timer);
  527. }
  528. }
  529. void cpsw_ale_stop(struct cpsw_ale *ale)
  530. {
  531. del_timer_sync(&ale->timer);
  532. }
  533. struct cpsw_ale *cpsw_ale_create(struct cpsw_ale_params *params)
  534. {
  535. struct cpsw_ale *ale;
  536. ale = kzalloc(sizeof(*ale), GFP_KERNEL);
  537. if (!ale)
  538. return NULL;
  539. ale->params = *params;
  540. ale->ageout = ale->params.ale_ageout * HZ;
  541. return ale;
  542. }
  543. int cpsw_ale_destroy(struct cpsw_ale *ale)
  544. {
  545. if (!ale)
  546. return -EINVAL;
  547. cpsw_ale_stop(ale);
  548. cpsw_ale_control_set(ale, 0, ALE_ENABLE, 0);
  549. kfree(ale);
  550. return 0;
  551. }