Lines Matching refs:ale

215 static int cpsw_ale_entry_get_fld(struct cpsw_ale *ale,  in cpsw_ale_entry_get_fld()  argument
223 if (!ale || !ale_entry) in cpsw_ale_entry_get_fld()
228 dev_err(ale->params.dev, "get: wrong ale fld id %d\n", fld_id); in cpsw_ale_entry_get_fld()
234 bits = ale->port_mask_bits; in cpsw_ale_entry_get_fld()
239 static void cpsw_ale_entry_set_fld(struct cpsw_ale *ale, in cpsw_ale_entry_set_fld() argument
248 if (!ale || !ale_entry) in cpsw_ale_entry_set_fld()
253 dev_err(ale->params.dev, "set: wrong ale fld id %d\n", fld_id); in cpsw_ale_entry_set_fld()
259 bits = ale->port_mask_bits; in cpsw_ale_entry_set_fld()
264 static int cpsw_ale_vlan_get_fld(struct cpsw_ale *ale, in cpsw_ale_vlan_get_fld() argument
268 return cpsw_ale_entry_get_fld(ale, ale_entry, in cpsw_ale_vlan_get_fld()
269 ale->vlan_entry_tbl, fld_id); in cpsw_ale_vlan_get_fld()
272 static void cpsw_ale_vlan_set_fld(struct cpsw_ale *ale, in cpsw_ale_vlan_set_fld() argument
277 cpsw_ale_entry_set_fld(ale, ale_entry, in cpsw_ale_vlan_set_fld()
278 ale->vlan_entry_tbl, fld_id, value); in cpsw_ale_vlan_set_fld()
298 static int cpsw_ale_read(struct cpsw_ale *ale, int idx, u32 *ale_entry) in cpsw_ale_read() argument
302 WARN_ON(idx > ale->params.ale_entries); in cpsw_ale_read()
304 writel_relaxed(idx, ale->params.ale_regs + ALE_TABLE_CONTROL); in cpsw_ale_read()
307 ale_entry[i] = readl_relaxed(ale->params.ale_regs + in cpsw_ale_read()
313 static int cpsw_ale_write(struct cpsw_ale *ale, int idx, u32 *ale_entry) in cpsw_ale_write() argument
317 WARN_ON(idx > ale->params.ale_entries); in cpsw_ale_write()
320 writel_relaxed(ale_entry[i], ale->params.ale_regs + in cpsw_ale_write()
323 writel_relaxed(idx | ALE_TABLE_WRITE, ale->params.ale_regs + in cpsw_ale_write()
329 static int cpsw_ale_match_addr(struct cpsw_ale *ale, const u8 *addr, u16 vid) in cpsw_ale_match_addr() argument
334 for (idx = 0; idx < ale->params.ale_entries; idx++) { in cpsw_ale_match_addr()
337 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_match_addr()
350 static int cpsw_ale_match_vlan(struct cpsw_ale *ale, u16 vid) in cpsw_ale_match_vlan() argument
355 for (idx = 0; idx < ale->params.ale_entries; idx++) { in cpsw_ale_match_vlan()
356 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_match_vlan()
366 static int cpsw_ale_match_free(struct cpsw_ale *ale) in cpsw_ale_match_free() argument
371 for (idx = 0; idx < ale->params.ale_entries; idx++) { in cpsw_ale_match_free()
372 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_match_free()
380 static int cpsw_ale_find_ageable(struct cpsw_ale *ale) in cpsw_ale_find_ageable() argument
385 for (idx = 0; idx < ale->params.ale_entries; idx++) { in cpsw_ale_find_ageable()
386 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_find_ageable()
400 static void cpsw_ale_flush_mcast(struct cpsw_ale *ale, u32 *ale_entry, in cpsw_ale_flush_mcast() argument
406 ale->port_mask_bits); in cpsw_ale_flush_mcast()
414 ale->port_mask_bits); in cpsw_ale_flush_mcast()
419 int cpsw_ale_flush_multicast(struct cpsw_ale *ale, int port_mask, int vid) in cpsw_ale_flush_multicast() argument
424 for (idx = 0; idx < ale->params.ale_entries; idx++) { in cpsw_ale_flush_multicast()
425 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_flush_multicast()
446 cpsw_ale_flush_mcast(ale, ale_entry, port_mask); in cpsw_ale_flush_multicast()
449 cpsw_ale_write(ale, idx, ale_entry); in cpsw_ale_flush_multicast()
465 int cpsw_ale_add_ucast(struct cpsw_ale *ale, const u8 *addr, int port, in cpsw_ale_add_ucast() argument
477 cpsw_ale_set_port_num(ale_entry, port, ale->port_num_bits); in cpsw_ale_add_ucast()
479 idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0); in cpsw_ale_add_ucast()
481 idx = cpsw_ale_match_free(ale); in cpsw_ale_add_ucast()
483 idx = cpsw_ale_find_ageable(ale); in cpsw_ale_add_ucast()
487 cpsw_ale_write(ale, idx, ale_entry); in cpsw_ale_add_ucast()
491 int cpsw_ale_del_ucast(struct cpsw_ale *ale, const u8 *addr, int port, in cpsw_ale_del_ucast() argument
497 idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0); in cpsw_ale_del_ucast()
502 cpsw_ale_write(ale, idx, ale_entry); in cpsw_ale_del_ucast()
506 int cpsw_ale_add_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask, in cpsw_ale_add_mcast() argument
512 idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0); in cpsw_ale_add_mcast()
514 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_add_mcast()
523 ale->port_mask_bits); in cpsw_ale_add_mcast()
526 ale->port_mask_bits); in cpsw_ale_add_mcast()
529 idx = cpsw_ale_match_free(ale); in cpsw_ale_add_mcast()
531 idx = cpsw_ale_find_ageable(ale); in cpsw_ale_add_mcast()
535 cpsw_ale_write(ale, idx, ale_entry); in cpsw_ale_add_mcast()
539 int cpsw_ale_del_mcast(struct cpsw_ale *ale, const u8 *addr, int port_mask, in cpsw_ale_del_mcast() argument
546 idx = cpsw_ale_match_addr(ale, addr, (flags & ALE_VLAN) ? vid : 0); in cpsw_ale_del_mcast()
550 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_del_mcast()
554 ale->port_mask_bits); in cpsw_ale_del_mcast()
560 ale->port_mask_bits); in cpsw_ale_del_mcast()
564 cpsw_ale_write(ale, idx, ale_entry); in cpsw_ale_del_mcast()
569 static void cpsw_ale_set_vlan_mcast(struct cpsw_ale *ale, u32 *ale_entry, in cpsw_ale_set_vlan_mcast() argument
575 idx = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_set_vlan_mcast()
577 writel(reg_mcast, ale->params.ale_regs + ALE_VLAN_MASK_MUX(idx)); in cpsw_ale_set_vlan_mcast()
580 idx = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_set_vlan_mcast()
582 writel(unreg_mcast, ale->params.ale_regs + ALE_VLAN_MASK_MUX(idx)); in cpsw_ale_set_vlan_mcast()
585 static void cpsw_ale_set_vlan_untag(struct cpsw_ale *ale, u32 *ale_entry, in cpsw_ale_set_vlan_untag() argument
588 cpsw_ale_vlan_set_fld(ale, ale_entry, in cpsw_ale_set_vlan_untag()
592 bitmap_set(ale->p0_untag_vid_mask, vid, 1); in cpsw_ale_set_vlan_untag()
594 bitmap_clear(ale->p0_untag_vid_mask, vid, 1); in cpsw_ale_set_vlan_untag()
597 int cpsw_ale_add_vlan(struct cpsw_ale *ale, u16 vid, int port_mask, int untag, in cpsw_ale_add_vlan() argument
603 idx = cpsw_ale_match_vlan(ale, vid); in cpsw_ale_add_vlan()
605 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_add_vlan()
609 cpsw_ale_set_vlan_untag(ale, ale_entry, vid, untag); in cpsw_ale_add_vlan()
611 if (!ale->params.nu_switch_ale) { in cpsw_ale_add_vlan()
612 cpsw_ale_vlan_set_fld(ale, ale_entry, in cpsw_ale_add_vlan()
614 cpsw_ale_vlan_set_fld(ale, ale_entry, in cpsw_ale_add_vlan()
617 cpsw_ale_vlan_set_fld(ale, ale_entry, in cpsw_ale_add_vlan()
620 cpsw_ale_set_vlan_mcast(ale, ale_entry, reg_mcast, unreg_mcast); in cpsw_ale_add_vlan()
623 cpsw_ale_vlan_set_fld(ale, ale_entry, in cpsw_ale_add_vlan()
627 idx = cpsw_ale_match_free(ale); in cpsw_ale_add_vlan()
629 idx = cpsw_ale_find_ageable(ale); in cpsw_ale_add_vlan()
633 cpsw_ale_write(ale, idx, ale_entry); in cpsw_ale_add_vlan()
637 static void cpsw_ale_vlan_del_modify_int(struct cpsw_ale *ale, u32 *ale_entry, in cpsw_ale_vlan_del_modify_int() argument
643 members = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_vlan_del_modify_int()
647 cpsw_ale_set_vlan_untag(ale, ale_entry, vid, 0); in cpsw_ale_vlan_del_modify_int()
652 untag = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_vlan_del_modify_int()
654 reg_mcast = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_vlan_del_modify_int()
656 unreg_mcast = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_vlan_del_modify_int()
662 cpsw_ale_set_vlan_untag(ale, ale_entry, vid, untag); in cpsw_ale_vlan_del_modify_int()
664 if (!ale->params.nu_switch_ale) { in cpsw_ale_vlan_del_modify_int()
665 cpsw_ale_vlan_set_fld(ale, ale_entry, in cpsw_ale_vlan_del_modify_int()
667 cpsw_ale_vlan_set_fld(ale, ale_entry, in cpsw_ale_vlan_del_modify_int()
670 cpsw_ale_set_vlan_mcast(ale, ale_entry, reg_mcast, in cpsw_ale_vlan_del_modify_int()
673 cpsw_ale_vlan_set_fld(ale, ale_entry, in cpsw_ale_vlan_del_modify_int()
677 int cpsw_ale_vlan_del_modify(struct cpsw_ale *ale, u16 vid, int port_mask) in cpsw_ale_vlan_del_modify() argument
682 idx = cpsw_ale_match_vlan(ale, vid); in cpsw_ale_vlan_del_modify()
686 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_vlan_del_modify()
688 cpsw_ale_vlan_del_modify_int(ale, ale_entry, vid, port_mask); in cpsw_ale_vlan_del_modify()
689 cpsw_ale_write(ale, idx, ale_entry); in cpsw_ale_vlan_del_modify()
694 int cpsw_ale_del_vlan(struct cpsw_ale *ale, u16 vid, int port_mask) in cpsw_ale_del_vlan() argument
699 idx = cpsw_ale_match_vlan(ale, vid); in cpsw_ale_del_vlan()
703 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_del_vlan()
711 members = cpsw_ale_vlan_get_fld(ale, ale_entry, ALE_ENT_VID_MEMBER_LIST); in cpsw_ale_del_vlan()
716 cpsw_ale_set_vlan_untag(ale, ale_entry, vid, 0); in cpsw_ale_del_vlan()
720 cpsw_ale_vlan_del_modify_int(ale, ale_entry, vid, port_mask); in cpsw_ale_del_vlan()
723 cpsw_ale_write(ale, idx, ale_entry); in cpsw_ale_del_vlan()
728 int cpsw_ale_vlan_add_modify(struct cpsw_ale *ale, u16 vid, int port_mask, in cpsw_ale_vlan_add_modify() argument
736 idx = cpsw_ale_match_vlan(ale, vid); in cpsw_ale_vlan_add_modify()
738 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_vlan_add_modify()
740 vlan_members = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_vlan_add_modify()
742 reg_mcast_members = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_vlan_add_modify()
745 cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_vlan_add_modify()
747 untag_members = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_vlan_add_modify()
755 ret = cpsw_ale_add_vlan(ale, vid, vlan_members, untag_members, in cpsw_ale_vlan_add_modify()
758 dev_err(ale->params.dev, "Unable to add vlan\n"); in cpsw_ale_vlan_add_modify()
761 dev_dbg(ale->params.dev, "port mask 0x%x untag 0x%x\n", vlan_members, in cpsw_ale_vlan_add_modify()
767 void cpsw_ale_set_unreg_mcast(struct cpsw_ale *ale, int unreg_mcast_mask, in cpsw_ale_set_unreg_mcast() argument
774 for (idx = 0; idx < ale->params.ale_entries; idx++) { in cpsw_ale_set_unreg_mcast()
775 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_set_unreg_mcast()
781 cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_set_unreg_mcast()
787 cpsw_ale_vlan_set_fld(ale, ale_entry, in cpsw_ale_set_unreg_mcast()
790 cpsw_ale_write(ale, idx, ale_entry); in cpsw_ale_set_unreg_mcast()
794 static void cpsw_ale_vlan_set_unreg_mcast(struct cpsw_ale *ale, u32 *ale_entry, in cpsw_ale_vlan_set_unreg_mcast() argument
799 unreg_mcast = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_vlan_set_unreg_mcast()
806 cpsw_ale_vlan_set_fld(ale, ale_entry, in cpsw_ale_vlan_set_unreg_mcast()
811 cpsw_ale_vlan_set_unreg_mcast_idx(struct cpsw_ale *ale, u32 *ale_entry, in cpsw_ale_vlan_set_unreg_mcast_idx() argument
817 idx = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_vlan_set_unreg_mcast_idx()
820 unreg_mcast = readl(ale->params.ale_regs + ALE_VLAN_MASK_MUX(idx)); in cpsw_ale_vlan_set_unreg_mcast_idx()
827 writel(unreg_mcast, ale->params.ale_regs + ALE_VLAN_MASK_MUX(idx)); in cpsw_ale_vlan_set_unreg_mcast_idx()
830 void cpsw_ale_set_allmulti(struct cpsw_ale *ale, int allmulti, int port) in cpsw_ale_set_allmulti() argument
835 for (idx = 0; idx < ale->params.ale_entries; idx++) { in cpsw_ale_set_allmulti()
838 cpsw_ale_read(ale, idx, ale_entry); in cpsw_ale_set_allmulti()
843 vlan_members = cpsw_ale_vlan_get_fld(ale, ale_entry, in cpsw_ale_set_allmulti()
849 if (!ale->params.nu_switch_ale) in cpsw_ale_set_allmulti()
850 cpsw_ale_vlan_set_unreg_mcast(ale, ale_entry, allmulti); in cpsw_ale_set_allmulti()
852 cpsw_ale_vlan_set_unreg_mcast_idx(ale, ale_entry, in cpsw_ale_set_allmulti()
855 cpsw_ale_write(ale, idx, ale_entry); in cpsw_ale_set_allmulti()
1085 int cpsw_ale_control_set(struct cpsw_ale *ale, int port, int control, in cpsw_ale_control_set() argument
1099 if (port < 0 || port >= ale->params.ale_ports) in cpsw_ale_control_set()
1109 tmp = readl_relaxed(ale->params.ale_regs + offset); in cpsw_ale_control_set()
1111 writel_relaxed(tmp, ale->params.ale_regs + offset); in cpsw_ale_control_set()
1116 int cpsw_ale_control_get(struct cpsw_ale *ale, int port, int control) in cpsw_ale_control_get() argument
1129 if (port < 0 || port >= ale->params.ale_ports) in cpsw_ale_control_get()
1135 tmp = readl_relaxed(ale->params.ale_regs + offset) >> shift; in cpsw_ale_control_get()
1141 struct cpsw_ale *ale = from_timer(ale, t, timer); in cpsw_ale_timer() local
1143 cpsw_ale_control_set(ale, 0, ALE_AGEOUT, 1); in cpsw_ale_timer()
1145 if (ale->ageout) { in cpsw_ale_timer()
1146 ale->timer.expires = jiffies + ale->ageout; in cpsw_ale_timer()
1147 add_timer(&ale->timer); in cpsw_ale_timer()
1151 static void cpsw_ale_hw_aging_timer_start(struct cpsw_ale *ale) in cpsw_ale_hw_aging_timer_start() argument
1155 aging_timer = ale->params.bus_freq / 1000000; in cpsw_ale_hw_aging_timer_start()
1156 aging_timer *= ale->params.ale_ageout; in cpsw_ale_hw_aging_timer_start()
1160 dev_warn(ale->params.dev, in cpsw_ale_hw_aging_timer_start()
1164 writel(aging_timer, ale->params.ale_regs + ALE_AGING_TIMER); in cpsw_ale_hw_aging_timer_start()
1167 static void cpsw_ale_hw_aging_timer_stop(struct cpsw_ale *ale) in cpsw_ale_hw_aging_timer_stop() argument
1169 writel(0, ale->params.ale_regs + ALE_AGING_TIMER); in cpsw_ale_hw_aging_timer_stop()
1172 static void cpsw_ale_aging_start(struct cpsw_ale *ale) in cpsw_ale_aging_start() argument
1174 if (!ale->params.ale_ageout) in cpsw_ale_aging_start()
1177 if (ale->features & CPSW_ALE_F_HW_AUTOAGING) { in cpsw_ale_aging_start()
1178 cpsw_ale_hw_aging_timer_start(ale); in cpsw_ale_aging_start()
1182 timer_setup(&ale->timer, cpsw_ale_timer, 0); in cpsw_ale_aging_start()
1183 ale->timer.expires = jiffies + ale->ageout; in cpsw_ale_aging_start()
1184 add_timer(&ale->timer); in cpsw_ale_aging_start()
1187 static void cpsw_ale_aging_stop(struct cpsw_ale *ale) in cpsw_ale_aging_stop() argument
1189 if (!ale->params.ale_ageout) in cpsw_ale_aging_stop()
1192 if (ale->features & CPSW_ALE_F_HW_AUTOAGING) { in cpsw_ale_aging_stop()
1193 cpsw_ale_hw_aging_timer_stop(ale); in cpsw_ale_aging_stop()
1197 del_timer_sync(&ale->timer); in cpsw_ale_aging_stop()
1200 void cpsw_ale_start(struct cpsw_ale *ale) in cpsw_ale_start() argument
1202 cpsw_ale_control_set(ale, 0, ALE_ENABLE, 1); in cpsw_ale_start()
1203 cpsw_ale_control_set(ale, 0, ALE_CLEAR, 1); in cpsw_ale_start()
1205 cpsw_ale_aging_start(ale); in cpsw_ale_start()
1208 void cpsw_ale_stop(struct cpsw_ale *ale) in cpsw_ale_stop() argument
1210 cpsw_ale_aging_stop(ale); in cpsw_ale_stop()
1211 cpsw_ale_control_set(ale, 0, ALE_CLEAR, 1); in cpsw_ale_stop()
1212 cpsw_ale_control_set(ale, 0, ALE_ENABLE, 0); in cpsw_ale_stop()
1287 struct cpsw_ale *ale; in cpsw_ale_create() local
1298 ale = devm_kzalloc(params->dev, sizeof(*ale), GFP_KERNEL); in cpsw_ale_create()
1299 if (!ale) in cpsw_ale_create()
1302 ale->p0_untag_vid_mask = devm_bitmap_zalloc(params->dev, VLAN_N_VID, in cpsw_ale_create()
1304 if (!ale->p0_untag_vid_mask) in cpsw_ale_create()
1307 ale->params = *params; in cpsw_ale_create()
1308 ale->ageout = ale->params.ale_ageout * HZ; in cpsw_ale_create()
1309 ale->features = ale_dev_id->features; in cpsw_ale_create()
1310 ale->vlan_entry_tbl = ale_dev_id->vlan_entry_tbl; in cpsw_ale_create()
1312 rev = readl_relaxed(ale->params.ale_regs + ALE_IDVER); in cpsw_ale_create()
1313 ale->version = in cpsw_ale_create()
1314 (ALE_VERSION_MAJOR(rev, ale->params.major_ver_mask) << 8) | in cpsw_ale_create()
1316 dev_info(ale->params.dev, "initialized cpsw ale version %d.%d\n", in cpsw_ale_create()
1317 ALE_VERSION_MAJOR(rev, ale->params.major_ver_mask), in cpsw_ale_create()
1320 if (ale->features & CPSW_ALE_F_STATUS_REG && in cpsw_ale_create()
1321 !ale->params.ale_entries) { in cpsw_ale_create()
1323 readl_relaxed(ale->params.ale_regs + ALE_STATUS) & in cpsw_ale_create()
1336 ale->params.ale_entries = ale_entries; in cpsw_ale_create()
1338 dev_info(ale->params.dev, in cpsw_ale_create()
1339 "ALE Table size %ld\n", ale->params.ale_entries); in cpsw_ale_create()
1342 ale->port_mask_bits = ale->params.ale_ports; in cpsw_ale_create()
1343 ale->port_num_bits = order_base_2(ale->params.ale_ports); in cpsw_ale_create()
1344 ale->vlan_field_bits = ale->params.ale_ports; in cpsw_ale_create()
1349 if (ale->params.nu_switch_ale) { in cpsw_ale_create()
1355 ale->params.ale_ports; in cpsw_ale_create()
1359 ale->params.ale_ports; in cpsw_ale_create()
1364 ale->params.ale_ports; in cpsw_ale_create()
1369 ale->params.ale_ports; in cpsw_ale_create()
1375 cpsw_ale_control_set(ale, 0, ALE_CLEAR, 1); in cpsw_ale_create()
1376 return ale; in cpsw_ale_create()
1379 void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data) in cpsw_ale_dump() argument
1383 for (i = 0; i < ale->params.ale_entries; i++) { in cpsw_ale_dump()
1384 cpsw_ale_read(ale, i, data); in cpsw_ale_dump()
1389 u32 cpsw_ale_get_num_entries(struct cpsw_ale *ale) in cpsw_ale_get_num_entries() argument
1391 return ale ? ale->params.ale_entries : 0; in cpsw_ale_get_num_entries()