2 * Texas Instruments N-Port Ethernet Switch Address Lookup Engine
4 * Copyright (C) 2012 Texas Instruments
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.
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.
15 #include <linux/kernel.h>
16 #include <linux/module.h>
17 #include <linux/platform_device.h>
18 #include <linux/seq_file.h>
19 #include <linux/slab.h>
20 #include <linux/err.h>
22 #include <linux/stat.h>
23 #include <linux/sysfs.h>
24 #include <linux/etherdevice.h>
28 #define BITMASK(bits) (BIT(bits) - 1)
30 #define ALE_VERSION_MAJOR(rev, mask) (((rev) >> 8) & (mask))
31 #define ALE_VERSION_MINOR(rev) (rev & 0xff)
32 #define ALE_VERSION_1R3 0x0103
33 #define ALE_VERSION_1R4 0x0104
36 #define ALE_IDVER 0x00
37 #define ALE_STATUS 0x04
38 #define ALE_CONTROL 0x08
39 #define ALE_PRESCALE 0x10
40 #define ALE_UNKNOWNVLAN 0x18
41 #define ALE_TABLE_CONTROL 0x20
42 #define ALE_TABLE 0x34
43 #define ALE_PORTCTL 0x40
45 /* ALE NetCP NU switch specific Registers */
46 #define ALE_UNKNOWNVLAN_MEMBER 0x90
47 #define ALE_UNKNOWNVLAN_UNREG_MCAST_FLOOD 0x94
48 #define ALE_UNKNOWNVLAN_REG_MCAST_FLOOD 0x98
49 #define ALE_UNKNOWNVLAN_FORCE_UNTAG_EGRESS 0x9C
50 #define ALE_VLAN_MASK_MUX(reg) (0xc0 + (0x4 * (reg)))
52 #define ALE_TABLE_WRITE BIT(31)
54 #define ALE_TYPE_FREE 0
55 #define ALE_TYPE_ADDR 1
56 #define ALE_TYPE_VLAN 2
57 #define ALE_TYPE_VLAN_ADDR 3
59 #define ALE_UCAST_PERSISTANT 0
60 #define ALE_UCAST_UNTOUCHED 1
61 #define ALE_UCAST_OUI 2
62 #define ALE_UCAST_TOUCHED 3
64 #define ALE_TABLE_SIZE_MULTIPLIER 1024
65 #define ALE_STATUS_SIZE_MASK 0x1f
66 #define ALE_TABLE_SIZE_DEFAULT 64
68 static inline int cpsw_ale_get_field(u32 *ale_entry, u32 start, u32 bits)
74 idx2 = (start + bits - 1) / 32;
75 /* Check if bits to be fetched exceed a word */
77 idx2 = 2 - idx2; /* flip */
78 hi_val = ale_entry[idx2] << ((idx2 * 32) - start);
81 idx = 2 - idx; /* flip */
82 return (hi_val + (ale_entry[idx] >> start)) & BITMASK(bits);
85 static inline void cpsw_ale_set_field(u32 *ale_entry, u32 start, u32 bits,
90 value &= BITMASK(bits);
92 idx2 = (start + bits - 1) / 32;
93 /* Check if bits to be set exceed a word */
95 idx2 = 2 - idx2; /* flip */
96 ale_entry[idx2] &= ~(BITMASK(bits + start - (idx2 * 32)));
97 ale_entry[idx2] |= (value >> ((idx2 * 32) - start));
100 idx = 2 - idx; /* flip */
101 ale_entry[idx] &= ~(BITMASK(bits) << start);
102 ale_entry[idx] |= (value << start);
105 #define DEFINE_ALE_FIELD(name, start, bits) \
106 static inline int cpsw_ale_get_##name(u32 *ale_entry) \
108 return cpsw_ale_get_field(ale_entry, start, bits); \
110 static inline void cpsw_ale_set_##name(u32 *ale_entry, u32 value) \
112 cpsw_ale_set_field(ale_entry, start, bits, value); \
115 #define DEFINE_ALE_FIELD1(name, start) \
116 static inline int cpsw_ale_get_##name(u32 *ale_entry, u32 bits) \
118 return cpsw_ale_get_field(ale_entry, start, bits); \
120 static inline void cpsw_ale_set_##name(u32 *ale_entry, u32 value, \
123 cpsw_ale_set_field(ale_entry, start, bits, value); \
126 DEFINE_ALE_FIELD(entry_type, 60, 2)
127 DEFINE_ALE_FIELD(vlan_id, 48, 12)
128 DEFINE_ALE_FIELD(mcast_state, 62, 2)
129 DEFINE_ALE_FIELD1(port_mask, 66)
130 DEFINE_ALE_FIELD(super, 65, 1)
131 DEFINE_ALE_FIELD(ucast_type, 62, 2)
132 DEFINE_ALE_FIELD1(port_num, 66)
133 DEFINE_ALE_FIELD(blocked, 65, 1)
134 DEFINE_ALE_FIELD(secure, 64, 1)
135 DEFINE_ALE_FIELD1(vlan_untag_force, 24)
136 DEFINE_ALE_FIELD1(vlan_reg_mcast, 16)
137 DEFINE_ALE_FIELD1(vlan_unreg_mcast, 8)
138 DEFINE_ALE_FIELD1(vlan_member_list, 0)
139 DEFINE_ALE_FIELD(mcast, 40, 1)
140 /* ALE NetCP nu switch specific */
141 DEFINE_ALE_FIELD(vlan_unreg_mcast_idx, 20, 3)
142 DEFINE_ALE_FIELD(vlan_reg_mcast_idx, 44, 3)
144 /* The MAC address field in the ALE entry cannot be macroized as above */
145 static inline void cpsw_ale_get_addr(u32 *ale_entry, u8 *addr)
149 for (i = 0; i < 6; i++)
150 addr[i] = cpsw_ale_get_field(ale_entry, 40 - 8*i, 8);
153 static inline void cpsw_ale_set_addr(u32 *ale_entry, u8 *addr)
157 for (i = 0; i < 6; i++)
158 cpsw_ale_set_field(ale_entry, 40 - 8*i, 8, addr[i]);
161 static int cpsw_ale_read(struct cpsw_ale *ale, int idx, u32 *ale_entry)
165 WARN_ON(idx > ale->params.ale_entries);
167 __raw_writel(idx, ale->params.ale_regs + ALE_TABLE_CONTROL);
169 for (i = 0; i < ALE_ENTRY_WORDS; i++)
170 ale_entry[i] = __raw_readl(ale->params.ale_regs +
176 static int cpsw_ale_write(struct cpsw_ale *ale, int idx, u32 *ale_entry)
180 WARN_ON(idx > ale->params.ale_entries);
182 for (i = 0; i < ALE_ENTRY_WORDS; i++)
183 __raw_writel(ale_entry[i], ale->params.ale_regs +
186 __raw_writel(idx | ALE_TABLE_WRITE, ale->params.ale_regs +
192 static int cpsw_ale_match_addr(struct cpsw_ale *ale, u8 *addr, u16 vid)
194 u32 ale_entry[ALE_ENTRY_WORDS];
197 for (idx = 0; idx < ale->params.ale_entries; idx++) {
200 cpsw_ale_read(ale, idx, ale_entry);
201 type = cpsw_ale_get_entry_type(ale_entry);
202 if (type != ALE_TYPE_ADDR && type != ALE_TYPE_VLAN_ADDR)
204 if (cpsw_ale_get_vlan_id(ale_entry) != vid)
206 cpsw_ale_get_addr(ale_entry, entry_addr);
207 if (ether_addr_equal(entry_addr, addr))
213 static int cpsw_ale_match_vlan(struct cpsw_ale *ale, u16 vid)
215 u32 ale_entry[ALE_ENTRY_WORDS];
218 for (idx = 0; idx < ale->params.ale_entries; idx++) {
219 cpsw_ale_read(ale, idx, ale_entry);
220 type = cpsw_ale_get_entry_type(ale_entry);
221 if (type != ALE_TYPE_VLAN)
223 if (cpsw_ale_get_vlan_id(ale_entry) == vid)
229 static int cpsw_ale_match_free(struct cpsw_ale *ale)
231 u32 ale_entry[ALE_ENTRY_WORDS];
234 for (idx = 0; idx < ale->params.ale_entries; idx++) {
235 cpsw_ale_read(ale, idx, ale_entry);
236 type = cpsw_ale_get_entry_type(ale_entry);
237 if (type == ALE_TYPE_FREE)
243 static int cpsw_ale_find_ageable(struct cpsw_ale *ale)
245 u32 ale_entry[ALE_ENTRY_WORDS];
248 for (idx = 0; idx < ale->params.ale_entries; idx++) {
249 cpsw_ale_read(ale, idx, ale_entry);
250 type = cpsw_ale_get_entry_type(ale_entry);
251 if (type != ALE_TYPE_ADDR && type != ALE_TYPE_VLAN_ADDR)
253 if (cpsw_ale_get_mcast(ale_entry))
255 type = cpsw_ale_get_ucast_type(ale_entry);
256 if (type != ALE_UCAST_PERSISTANT &&
257 type != ALE_UCAST_OUI)
263 static void cpsw_ale_flush_mcast(struct cpsw_ale *ale, u32 *ale_entry,
268 mask = cpsw_ale_get_port_mask(ale_entry,
269 ale->port_mask_bits);
270 if ((mask & port_mask) == 0)
271 return; /* ports dont intersect, not interested */
274 /* free if only remaining port is host port */
276 cpsw_ale_set_port_mask(ale_entry, mask,
277 ale->port_mask_bits);
279 cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
282 int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid)
284 u32 ale_entry[ALE_ENTRY_WORDS];
287 for (idx = 0; idx < ale->params.ale_entries; idx++) {
288 cpsw_ale_read(ale, idx, ale_entry);
289 ret = cpsw_ale_get_entry_type(ale_entry);
290 if (ret != ALE_TYPE_ADDR && ret != ALE_TYPE_VLAN_ADDR)
293 /* if vid passed is -1 then remove all multicast entry from
294 * the table irrespective of vlan id, if a valid vlan id is
295 * passed then remove only multicast added to that vlan id.
296 * if vlan id doesn't match then move on to next entry.
298 if (vid != -1 && cpsw_ale_get_vlan_id(ale_entry) != vid)
301 if (cpsw_ale_get_mcast(ale_entry)) {
304 cpsw_ale_get_addr(ale_entry, addr);
305 if (!is_broadcast_ether_addr(addr))
306 cpsw_ale_flush_mcast(ale, ale_entry, port_mask);
309 cpsw_ale_write(ale, idx, ale_entry);
313 EXPORT_SYMBOL_GPL(cpsw_ale_flush_multicast);
315 static inline void cpsw_ale_set_vlan_entry_type(u32 *ale_entry,
318 if (flags & ALE_VLAN) {
319 cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_VLAN_ADDR);
320 cpsw_ale_set_vlan_id(ale_entry, vid);
322 cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_ADDR);
326 int cpsw_ale_add_ucast(struct cpsw_ale *ale, u8 *addr, int port,
329 u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
332 cpsw_ale_set_vlan_entry_type(ale_entry, flags, vid);
334 cpsw_ale_set_addr(ale_entry, addr);
335 cpsw_ale_set_ucast_type(ale_entry, ALE_UCAST_PERSISTANT);
336 cpsw_ale_set_secure(ale_entry, (flags & ALE_SECURE) ? 1 : 0);
337 cpsw_ale_set_blocked(ale_entry, (flags & ALE_BLOCKED) ? 1 : 0);
338 cpsw_ale_set_port_num(ale_entry, port, ale->port_num_bits);
340 idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
342 idx = cpsw_ale_match_free(ale);
344 idx = cpsw_ale_find_ageable(ale);
348 cpsw_ale_write(ale, idx, ale_entry);
351 EXPORT_SYMBOL_GPL(cpsw_ale_add_ucast);
353 int cpsw_ale_del_ucast(struct cpsw_ale *ale, u8 *addr, int port,
356 u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
359 idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
363 cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
364 cpsw_ale_write(ale, idx, ale_entry);
367 EXPORT_SYMBOL_GPL(cpsw_ale_del_ucast);
369 int cpsw_ale_add_mcast(struct cpsw_ale *ale, u8 *addr, int port_mask,
370 int flags, u16 vid, int mcast_state)
372 u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
375 idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
377 cpsw_ale_read(ale, idx, ale_entry);
379 cpsw_ale_set_vlan_entry_type(ale_entry, flags, vid);
381 cpsw_ale_set_addr(ale_entry, addr);
382 cpsw_ale_set_super(ale_entry, (flags & ALE_BLOCKED) ? 1 : 0);
383 cpsw_ale_set_mcast_state(ale_entry, mcast_state);
385 mask = cpsw_ale_get_port_mask(ale_entry,
386 ale->port_mask_bits);
388 cpsw_ale_set_port_mask(ale_entry, port_mask,
389 ale->port_mask_bits);
392 idx = cpsw_ale_match_free(ale);
394 idx = cpsw_ale_find_ageable(ale);
398 cpsw_ale_write(ale, idx, ale_entry);
401 EXPORT_SYMBOL_GPL(cpsw_ale_add_mcast);
403 int cpsw_ale_del_mcast(struct cpsw_ale *ale, u8 *addr, int port_mask,
406 u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
409 idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0);
413 cpsw_ale_read(ale, idx, ale_entry);
416 cpsw_ale_set_port_mask(ale_entry, port_mask,
417 ale->port_mask_bits);
419 cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
421 cpsw_ale_write(ale, idx, ale_entry);
424 EXPORT_SYMBOL_GPL(cpsw_ale_del_mcast);
426 /* ALE NetCP NU switch specific vlan functions */
427 static void cpsw_ale_set_vlan_mcast(struct cpsw_ale *ale, u32 *ale_entry,
428 int reg_mcast, int unreg_mcast)
432 /* Set VLAN registered multicast flood mask */
433 idx = cpsw_ale_get_vlan_reg_mcast_idx(ale_entry);
434 writel(reg_mcast, ale->params.ale_regs + ALE_VLAN_MASK_MUX(idx));
436 /* Set VLAN unregistered multicast flood mask */
437 idx = cpsw_ale_get_vlan_unreg_mcast_idx(ale_entry);
438 writel(unreg_mcast, ale->params.ale_regs + ALE_VLAN_MASK_MUX(idx));
441 int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port, int untag,
442 int reg_mcast, int unreg_mcast)
444 u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
447 idx = cpsw_ale_match_vlan(ale, vid);
449 cpsw_ale_read(ale, idx, ale_entry);
451 cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_VLAN);
452 cpsw_ale_set_vlan_id(ale_entry, vid);
454 cpsw_ale_set_vlan_untag_force(ale_entry, untag, ale->vlan_field_bits);
455 if (!ale->params.nu_switch_ale) {
456 cpsw_ale_set_vlan_reg_mcast(ale_entry, reg_mcast,
457 ale->vlan_field_bits);
458 cpsw_ale_set_vlan_unreg_mcast(ale_entry, unreg_mcast,
459 ale->vlan_field_bits);
461 cpsw_ale_set_vlan_mcast(ale, ale_entry, reg_mcast, unreg_mcast);
463 cpsw_ale_set_vlan_member_list(ale_entry, port, ale->vlan_field_bits);
466 idx = cpsw_ale_match_free(ale);
468 idx = cpsw_ale_find_ageable(ale);
472 cpsw_ale_write(ale, idx, ale_entry);
475 EXPORT_SYMBOL_GPL(cpsw_ale_add_vlan);
477 int cpsw_ale_del_vlan(struct cpsw_ale *ale, u16 vid, int port_mask)
479 u32 ale_entry[ALE_ENTRY_WORDS] = {0, 0, 0};
482 idx = cpsw_ale_match_vlan(ale, vid);
486 cpsw_ale_read(ale, idx, ale_entry);
489 cpsw_ale_set_vlan_member_list(ale_entry, port_mask,
490 ale->vlan_field_bits);
492 cpsw_ale_set_entry_type(ale_entry, ALE_TYPE_FREE);
494 cpsw_ale_write(ale, idx, ale_entry);
497 EXPORT_SYMBOL_GPL(cpsw_ale_del_vlan);
499 void cpsw_ale_set_allmulti(struct cpsw_ale *ale, int allmulti)
501 u32 ale_entry[ALE_ENTRY_WORDS];
505 /* Only bother doing the work if the setting is actually changing */
506 if (ale->allmulti == allmulti)
509 /* Remember the new setting to check against next time */
510 ale->allmulti = allmulti;
512 for (idx = 0; idx < ale->params.ale_entries; idx++) {
513 cpsw_ale_read(ale, idx, ale_entry);
514 type = cpsw_ale_get_entry_type(ale_entry);
515 if (type != ALE_TYPE_VLAN)
519 cpsw_ale_get_vlan_unreg_mcast(ale_entry,
520 ale->vlan_field_bits);
525 cpsw_ale_set_vlan_unreg_mcast(ale_entry, unreg_mcast,
526 ale->vlan_field_bits);
527 cpsw_ale_write(ale, idx, ale_entry);
530 EXPORT_SYMBOL_GPL(cpsw_ale_set_allmulti);
532 struct ale_control_info {
534 int offset, port_offset;
535 int shift, port_shift;
539 static struct ale_control_info ale_controls[ALE_NUM_CONTROLS] = {
542 .offset = ALE_CONTROL,
550 .offset = ALE_CONTROL,
558 .offset = ALE_CONTROL,
564 [ALE_P0_UNI_FLOOD] = {
565 .name = "port0_unicast_flood",
566 .offset = ALE_CONTROL,
572 [ALE_VLAN_NOLEARN] = {
573 .name = "vlan_nolearn",
574 .offset = ALE_CONTROL,
580 [ALE_NO_PORT_VLAN] = {
581 .name = "no_port_vlan",
582 .offset = ALE_CONTROL,
590 .offset = ALE_CONTROL,
598 .offset = ALE_CONTROL,
604 [ALE_RATE_LIMIT_TX] = {
605 .name = "rate_limit_tx",
606 .offset = ALE_CONTROL,
613 .name = "vlan_aware",
614 .offset = ALE_CONTROL,
620 [ALE_AUTH_ENABLE] = {
621 .name = "auth_enable",
622 .offset = ALE_CONTROL,
629 .name = "rate_limit",
630 .offset = ALE_CONTROL,
637 .name = "port_state",
638 .offset = ALE_PORTCTL,
644 [ALE_PORT_DROP_UNTAGGED] = {
645 .name = "drop_untagged",
646 .offset = ALE_PORTCTL,
652 [ALE_PORT_DROP_UNKNOWN_VLAN] = {
653 .name = "drop_unknown",
654 .offset = ALE_PORTCTL,
660 [ALE_PORT_NOLEARN] = {
662 .offset = ALE_PORTCTL,
668 [ALE_PORT_NO_SA_UPDATE] = {
669 .name = "no_source_update",
670 .offset = ALE_PORTCTL,
676 [ALE_PORT_MCAST_LIMIT] = {
677 .name = "mcast_limit",
678 .offset = ALE_PORTCTL,
684 [ALE_PORT_BCAST_LIMIT] = {
685 .name = "bcast_limit",
686 .offset = ALE_PORTCTL,
692 [ALE_PORT_UNKNOWN_VLAN_MEMBER] = {
693 .name = "unknown_vlan_member",
694 .offset = ALE_UNKNOWNVLAN,
700 [ALE_PORT_UNKNOWN_MCAST_FLOOD] = {
701 .name = "unknown_mcast_flood",
702 .offset = ALE_UNKNOWNVLAN,
708 [ALE_PORT_UNKNOWN_REG_MCAST_FLOOD] = {
709 .name = "unknown_reg_flood",
710 .offset = ALE_UNKNOWNVLAN,
716 [ALE_PORT_UNTAGGED_EGRESS] = {
717 .name = "untagged_egress",
718 .offset = ALE_UNKNOWNVLAN,
726 int cpsw_ale_control_set(struct cpsw_ale *ale, int port, int control,
729 const struct ale_control_info *info;
733 if (control < 0 || control >= ARRAY_SIZE(ale_controls))
736 info = &ale_controls[control];
737 if (info->port_offset == 0 && info->port_shift == 0)
738 port = 0; /* global, port is a dont care */
740 if (port < 0 || port > ale->params.ale_ports)
743 mask = BITMASK(info->bits);
747 offset = info->offset + (port * info->port_offset);
748 shift = info->shift + (port * info->port_shift);
750 tmp = __raw_readl(ale->params.ale_regs + offset);
751 tmp = (tmp & ~(mask << shift)) | (value << shift);
752 __raw_writel(tmp, ale->params.ale_regs + offset);
756 EXPORT_SYMBOL_GPL(cpsw_ale_control_set);
758 int cpsw_ale_control_get(struct cpsw_ale *ale, int port, int control)
760 const struct ale_control_info *info;
764 if (control < 0 || control >= ARRAY_SIZE(ale_controls))
767 info = &ale_controls[control];
768 if (info->port_offset == 0 && info->port_shift == 0)
769 port = 0; /* global, port is a dont care */
771 if (port < 0 || port > ale->params.ale_ports)
774 offset = info->offset + (port * info->port_offset);
775 shift = info->shift + (port * info->port_shift);
777 tmp = __raw_readl(ale->params.ale_regs + offset) >> shift;
778 return tmp & BITMASK(info->bits);
780 EXPORT_SYMBOL_GPL(cpsw_ale_control_get);
782 static void cpsw_ale_timer(unsigned long arg)
784 struct cpsw_ale *ale = (struct cpsw_ale *)arg;
786 cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1);
789 ale->timer.expires = jiffies + ale->ageout;
790 add_timer(&ale->timer);
794 void cpsw_ale_start(struct cpsw_ale *ale)
796 u32 rev, ale_entries;
798 rev = __raw_readl(ale->params.ale_regs + ALE_IDVER);
799 if (!ale->params.major_ver_mask)
800 ale->params.major_ver_mask = 0xff;
802 (ALE_VERSION_MAJOR(rev, ale->params.major_ver_mask) << 8) |
803 ALE_VERSION_MINOR(rev);
804 dev_info(ale->params.dev, "initialized cpsw ale version %d.%d\n",
805 ALE_VERSION_MAJOR(rev, ale->params.major_ver_mask),
806 ALE_VERSION_MINOR(rev));
808 if (!ale->params.ale_entries) {
810 __raw_readl(ale->params.ale_regs + ALE_STATUS) &
811 ALE_STATUS_SIZE_MASK;
812 /* ALE available on newer NetCP switches has introduced
813 * a register, ALE_STATUS, to indicate the size of ALE
814 * table which shows the size as a multiple of 1024 entries.
815 * For these, params.ale_entries will be set to zero. So
816 * read the register and update the value of ale_entries.
817 * ALE table on NetCP lite, is much smaller and is indicated
818 * by a value of zero in ALE_STATUS. So use a default value
819 * of ALE_TABLE_SIZE_DEFAULT for this. Caller is expected
820 * to set the value of ale_entries for all other versions
824 ale_entries = ALE_TABLE_SIZE_DEFAULT;
826 ale_entries *= ALE_TABLE_SIZE_MULTIPLIER;
827 ale->params.ale_entries = ale_entries;
829 dev_info(ale->params.dev,
830 "ALE Table size %ld\n", ale->params.ale_entries);
832 /* set default bits for existing h/w */
833 ale->port_mask_bits = 3;
834 ale->port_num_bits = 2;
835 ale->vlan_field_bits = 3;
837 /* Set defaults override for ALE on NetCP NU switch and for version
840 if (ale->params.nu_switch_ale) {
841 /* Separate registers for unknown vlan configuration.
842 * Also there are N bits, where N is number of ale
843 * ports and shift value should be 0
845 ale_controls[ALE_PORT_UNKNOWN_VLAN_MEMBER].bits =
846 ale->params.ale_ports;
847 ale_controls[ALE_PORT_UNKNOWN_VLAN_MEMBER].offset =
848 ALE_UNKNOWNVLAN_MEMBER;
849 ale_controls[ALE_PORT_UNKNOWN_MCAST_FLOOD].bits =
850 ale->params.ale_ports;
851 ale_controls[ALE_PORT_UNKNOWN_MCAST_FLOOD].shift = 0;
852 ale_controls[ALE_PORT_UNKNOWN_MCAST_FLOOD].offset =
853 ALE_UNKNOWNVLAN_UNREG_MCAST_FLOOD;
854 ale_controls[ALE_PORT_UNKNOWN_REG_MCAST_FLOOD].bits =
855 ale->params.ale_ports;
856 ale_controls[ALE_PORT_UNKNOWN_REG_MCAST_FLOOD].shift = 0;
857 ale_controls[ALE_PORT_UNKNOWN_REG_MCAST_FLOOD].offset =
858 ALE_UNKNOWNVLAN_REG_MCAST_FLOOD;
859 ale_controls[ALE_PORT_UNTAGGED_EGRESS].bits =
860 ale->params.ale_ports;
861 ale_controls[ALE_PORT_UNTAGGED_EGRESS].shift = 0;
862 ale_controls[ALE_PORT_UNTAGGED_EGRESS].offset =
863 ALE_UNKNOWNVLAN_FORCE_UNTAG_EGRESS;
864 ale->port_mask_bits = ale->params.ale_ports;
865 ale->port_num_bits = ale->params.ale_ports - 1;
866 ale->vlan_field_bits = ale->params.ale_ports;
867 } else if (ale->version == ALE_VERSION_1R3) {
868 ale->port_mask_bits = ale->params.ale_ports;
869 ale->port_num_bits = 3;
870 ale->vlan_field_bits = ale->params.ale_ports;
873 cpsw_ale_control_set(ale, 0, ALE_ENABLE, 1);
874 cpsw_ale_control_set(ale, 0, ALE_CLEAR, 1);
876 init_timer(&ale->timer);
877 ale->timer.data = (unsigned long)ale;
878 ale->timer.function = cpsw_ale_timer;
880 ale->timer.expires = jiffies + ale->ageout;
881 add_timer(&ale->timer);
884 EXPORT_SYMBOL_GPL(cpsw_ale_start);
886 void cpsw_ale_stop(struct cpsw_ale *ale)
888 del_timer_sync(&ale->timer);
890 EXPORT_SYMBOL_GPL(cpsw_ale_stop);
892 struct cpsw_ale *cpsw_ale_create(struct cpsw_ale_params *params)
894 struct cpsw_ale *ale;
896 ale = kzalloc(sizeof(*ale), GFP_KERNEL);
900 ale->params = *params;
901 ale->ageout = ale->params.ale_ageout * HZ;
905 EXPORT_SYMBOL_GPL(cpsw_ale_create);
907 int cpsw_ale_destroy(struct cpsw_ale *ale)
911 cpsw_ale_control_set(ale, 0, ALE_ENABLE, 0);
915 EXPORT_SYMBOL_GPL(cpsw_ale_destroy);
917 void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data)
921 for (i = 0; i < ale->params.ale_entries; i++) {
922 cpsw_ale_read(ale, i, data);
923 data += ALE_ENTRY_WORDS;
926 EXPORT_SYMBOL_GPL(cpsw_ale_dump);
928 MODULE_LICENSE("GPL v2");
929 MODULE_DESCRIPTION("TI CPSW ALE driver");
930 MODULE_AUTHOR("Texas Instruments");