Lines Matching refs:ethsw
33 static struct dpaa2_switch_fdb *dpaa2_switch_fdb_get_unused(struct ethsw_core *ethsw)
37 for (i = 0; i < ethsw->sw_attr.num_ifs; i++)
38 if (!ethsw->fdbs[i].in_use)
39 return ðsw->fdbs[i];
44 dpaa2_switch_filter_block_get_unused(struct ethsw_core *ethsw)
48 for (i = 0; i < ethsw->sw_attr.num_ifs; i++)
49 if (!ethsw->filter_blocks[i].in_use)
50 return ðsw->filter_blocks[i];
124 static void dpaa2_switch_fdb_get_flood_cfg(struct ethsw_core *ethsw, u16 fdb_id,
135 for (j = 0; j < ethsw->sw_attr.num_ifs; j++) {
136 if (!ethsw->ports[j])
138 if (ethsw->ports[j]->fdb->fdb_id != fdb_id)
141 if (type == DPSW_BROADCAST && ethsw->ports[j]->bcast_flood)
142 cfg->if_id[i++] = ethsw->ports[j]->idx;
143 else if (type == DPSW_FLOODING && ethsw->ports[j]->ucast_flood)
144 cfg->if_id[i++] = ethsw->ports[j]->idx;
148 cfg->if_id[i++] = ethsw->sw_attr.num_ifs;
155 static int dpaa2_switch_fdb_set_egress_flood(struct ethsw_core *ethsw, u16 fdb_id)
161 dpaa2_switch_fdb_get_flood_cfg(ethsw, fdb_id, DPSW_BROADCAST, &flood_cfg);
162 err = dpsw_set_egress_flood(ethsw->mc_io, 0, ethsw->dpsw_handle,
165 dev_err(ethsw->dev, "dpsw_set_egress_flood() = %d\n", err);
170 dpaa2_switch_fdb_get_flood_cfg(ethsw, fdb_id, DPSW_FLOODING, &flood_cfg);
171 err = dpsw_set_egress_flood(ethsw->mc_io, 0, ethsw->dpsw_handle,
174 dev_err(ethsw->dev, "dpsw_set_egress_flood() = %d\n", err);
193 struct ethsw_core *ethsw = port_priv->ethsw_data;
198 err = dpsw_vlan_add(ethsw->mc_io, 0,
199 ethsw->dpsw_handle, vid, &vcfg);
201 dev_err(ethsw->dev, "dpsw_vlan_add err %d\n", err);
204 ethsw->vlans[vid] = ETHSW_VLAN_MEMBER;
230 struct ethsw_core *ethsw = port_priv->ethsw_data;
236 err = dpsw_if_get_tci(ethsw->mc_io, 0, ethsw->dpsw_handle,
248 err = dpsw_if_disable(ethsw->mc_io, 0,
249 ethsw->dpsw_handle,
257 err = dpsw_if_set_tci(ethsw->mc_io, 0, ethsw->dpsw_handle,
271 ret = dpsw_if_enable(ethsw->mc_io, 0,
272 ethsw->dpsw_handle,
286 struct ethsw_core *ethsw = port_priv->ethsw_data;
303 err = dpsw_vlan_add_if(ethsw->mc_io, 0, ethsw->dpsw_handle, vid, &vcfg);
312 err = dpsw_vlan_add_if_untagged(ethsw->mc_io, 0,
313 ethsw->dpsw_handle,
379 static int dpaa2_switch_dellink(struct ethsw_core *ethsw, u16 vid)
384 if (!ethsw->vlans[vid])
387 err = dpsw_vlan_remove(ethsw->mc_io, 0, ethsw->dpsw_handle, vid);
389 dev_err(ethsw->dev, "dpsw_vlan_remove err %d\n", err);
392 ethsw->vlans[vid] = 0;
394 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
395 ppriv_local = ethsw->ports[i];
649 static void dpaa2_switch_enable_ctrl_if_napi(struct ethsw_core *ethsw)
653 /* Access to the ethsw->napi_users relies on the RTNL lock */
657 ethsw->napi_users++;
660 if (ethsw->napi_users > 1)
664 napi_enable(ðsw->fq[i].napi);
667 static void dpaa2_switch_disable_ctrl_if_napi(struct ethsw_core *ethsw)
671 /* Access to the ethsw->napi_users relies on the RTNL lock */
675 ethsw->napi_users--;
676 if (ethsw->napi_users)
680 napi_disable(ðsw->fq[i].napi);
686 struct ethsw_core *ethsw = port_priv->ethsw_data;
709 dpaa2_switch_enable_ctrl_if_napi(ethsw);
722 struct ethsw_core *ethsw = port_priv->ethsw_data;
744 dpaa2_switch_disable_ctrl_if_napi(ethsw);
838 struct ethsw_core *ethsw = port_priv->ethsw_data;
849 fdb_dump_size = ethsw->sw_attr.max_fdb_entries * sizeof(fdb_entry);
863 err = dpsw_fdb_dump(ethsw->mc_io, 0, ethsw->dpsw_handle, fdb_id,
976 struct ethsw_core *ethsw = port_priv->ethsw_data;
982 if (!(ethsw->features & ETHSW_FEATURE_MAC_ADDR))
986 err = dpsw_if_get_port_mac_addr(ethsw->mc_io, 0, ethsw->dpsw_handle,
1014 static void dpaa2_switch_free_fd(const struct ethsw_core *ethsw,
1017 struct device *dev = ethsw->dev;
1023 skbh = dpaa2_iova_to_virt(ethsw->iommu_domain, fd_addr);
1036 static int dpaa2_switch_build_single_fd(struct ethsw_core *ethsw,
1040 struct device *dev = ethsw->dev;
1085 struct ethsw_core *ethsw = port_priv->ethsw_data;
1119 err = dpaa2_switch_build_single_fd(ethsw, skb, &fd);
1133 dpaa2_switch_free_fd(ethsw, &fd);
1193 struct ethsw_core *ethsw = port_priv->ethsw_data;
1203 err = dpsw_acl_add_if(ethsw->mc_io, 0, ethsw->dpsw_handle,
1220 struct ethsw_core *ethsw = port_priv->ethsw_data;
1230 err = dpsw_acl_remove_if(ethsw->mc_io, 0, ethsw->dpsw_handle,
1278 struct ethsw_core *ethsw = port_priv->ethsw_data;
1302 new_block = dpaa2_switch_filter_block_get_unused(ethsw);
1311 struct ethsw_core *ethsw = port_priv->ethsw_data;
1319 ethsw);
1329 ethsw, filter_block, NULL);
1361 struct ethsw_core *ethsw = port_priv->ethsw_data;
1368 ethsw);
1510 struct ethsw_core *ethsw = dev_get_drvdata(dev);
1516 err = dpsw_get_irq_status(ethsw->mc_io, 0, ethsw->dpsw_handle,
1524 port_priv = ethsw->ports[if_id];
1544 err = dpsw_clear_irq_status(ethsw->mc_io, 0, ethsw->dpsw_handle,
1555 struct ethsw_core *ethsw = dev_get_drvdata(dev);
1571 err = dpsw_set_irq_enable(ethsw->mc_io, 0, ethsw->dpsw_handle,
1589 err = dpsw_set_irq_mask(ethsw->mc_io, 0, ethsw->dpsw_handle,
1596 err = dpsw_set_irq_enable(ethsw->mc_io, 0, ethsw->dpsw_handle,
1615 struct ethsw_core *ethsw = dev_get_drvdata(dev);
1618 err = dpsw_set_irq_enable(ethsw->mc_io, 0, ethsw->dpsw_handle,
1628 struct ethsw_core *ethsw = port_priv->ethsw_data;
1637 err = dpsw_if_set_learning_mode(ethsw->mc_io, 0, ethsw->dpsw_handle,
1677 struct ethsw_core *ethsw = port_priv->ethsw_data;
1685 return dpaa2_switch_fdb_set_egress_flood(ethsw, port_priv->fdb->fdb_id);
1771 struct ethsw_core *ethsw = port_priv->ethsw_data;
1772 struct dpsw_attr *attr = ðsw->sw_attr;
1782 err = dpsw_get_attributes(ethsw->mc_io, 0, ethsw->dpsw_handle,
1783 ðsw->sw_attr);
1792 err = dpsw_get_attributes(ethsw->mc_io, 0, ethsw->dpsw_handle,
1793 ðsw->sw_attr);
1877 struct ethsw_core *ethsw = port_priv->ethsw_data;
1898 err = dpsw_vlan_remove_if_untagged(ethsw->mc_io, 0,
1899 ethsw->dpsw_handle,
1910 err = dpsw_vlan_remove_if(ethsw->mc_io, 0, ethsw->dpsw_handle,
1922 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
1923 if (ethsw->ports[i] &&
1924 ethsw->ports[i]->vlans[vid] & ETHSW_VLAN_MEMBER)
1928 ethsw->vlans[vid] &= ~ETHSW_VLAN_GLOBAL;
1930 err = dpaa2_switch_dellink(ethsw, vid);
2006 struct ethsw_core *ethsw = port_priv->ethsw_data;
2038 err = dpaa2_switch_fdb_set_egress_flood(ethsw, port_priv->fdb->fdb_id);
2084 struct ethsw_core *ethsw = port_priv->ethsw_data;
2116 err = dpaa2_switch_fdb_set_egress_flood(ethsw, port_priv->fdb->fdb_id);
2121 err = dpaa2_switch_fdb_set_egress_flood(ethsw, old_fdb->fdb_id);
2280 struct ethsw_core *ethsw = port_priv->ethsw_data;
2316 queue_work(ethsw->workqueue, &switchdev_work->work);
2364 static struct sk_buff *dpaa2_switch_build_linear_skb(struct ethsw_core *ethsw,
2370 struct device *dev = ethsw->dev;
2374 fd_vaddr = dpaa2_iova_to_virt(ethsw->iommu_domain, addr);
2388 ethsw->buf_count--;
2396 dpaa2_switch_free_fd(fq->ethsw, fd);
2402 struct ethsw_core *ethsw = fq->ethsw;
2413 if (if_id >= ethsw->sw_attr.num_ifs) {
2414 dev_err(ethsw->dev, "Frame received from unknown interface!\n");
2417 port_priv = ethsw->ports[if_id];
2428 skb = dpaa2_switch_build_linear_skb(ethsw, fd);
2445 dev_info(ethsw->dev, "__skb_vlan_pop() returned %d", err);
2461 dpaa2_switch_free_fd(ethsw, fd);
2464 static void dpaa2_switch_detect_features(struct ethsw_core *ethsw)
2466 ethsw->features = 0;
2468 if (ethsw->major > 8 || (ethsw->major == 8 && ethsw->minor >= 6))
2469 ethsw->features |= ETHSW_FEATURE_MAC_ADDR;
2472 static int dpaa2_switch_setup_fqs(struct ethsw_core *ethsw)
2475 struct device *dev = ethsw->dev;
2479 err = dpsw_ctrl_if_get_attributes(ethsw->mc_io, 0, ethsw->dpsw_handle,
2486 ethsw->fq[i].fqid = ctrl_if_attr.rx_fqid;
2487 ethsw->fq[i].ethsw = ethsw;
2488 ethsw->fq[i++].type = DPSW_QUEUE_RX;
2490 ethsw->fq[i].fqid = ctrl_if_attr.tx_err_conf_fqid;
2491 ethsw->fq[i].ethsw = ethsw;
2492 ethsw->fq[i++].type = DPSW_QUEUE_TX_ERR_CONF;
2500 static void dpaa2_switch_free_bufs(struct ethsw_core *ethsw, u64 *buf_array, int count)
2502 struct device *dev = ethsw->dev;
2507 vaddr = dpaa2_iova_to_virt(ethsw->iommu_domain, buf_array[i]);
2517 static int dpaa2_switch_add_bufs(struct ethsw_core *ethsw, u16 bpid)
2519 struct device *dev = ethsw->dev;
2561 dpaa2_switch_free_bufs(ethsw, buf_array, i);
2579 static int dpaa2_switch_refill_bp(struct ethsw_core *ethsw)
2581 int *count = ðsw->buf_count;
2587 new_count = dpaa2_switch_add_bufs(ethsw, ethsw->bpid);
2604 static int dpaa2_switch_seed_bp(struct ethsw_core *ethsw)
2609 count = ðsw->buf_count;
2610 *count += dpaa2_switch_add_bufs(ethsw, ethsw->bpid);
2619 static void dpaa2_switch_drain_bp(struct ethsw_core *ethsw)
2625 ret = dpaa2_io_service_acquire(NULL, ethsw->bpid,
2628 dev_err(ethsw->dev,
2632 dpaa2_switch_free_bufs(ethsw, buf_array, ret);
2637 static int dpaa2_switch_setup_dpbp(struct ethsw_core *ethsw)
2640 struct device *dev = ethsw->dev;
2654 ethsw->dpbp_dev = dpbp_dev;
2656 err = dpbp_open(ethsw->mc_io, 0, dpbp_dev->obj_desc.id,
2663 err = dpbp_reset(ethsw->mc_io, 0, dpbp_dev->mc_handle);
2669 err = dpbp_enable(ethsw->mc_io, 0, dpbp_dev->mc_handle);
2675 err = dpbp_get_attributes(ethsw->mc_io, 0, dpbp_dev->mc_handle,
2687 err = dpsw_ctrl_if_set_pools(ethsw->mc_io, 0, ethsw->dpsw_handle,
2693 ethsw->bpid = dpbp_attrs.id;
2698 dpbp_disable(ethsw->mc_io, 0, dpbp_dev->mc_handle);
2701 dpbp_close(ethsw->mc_io, 0, dpbp_dev->mc_handle);
2707 static void dpaa2_switch_free_dpbp(struct ethsw_core *ethsw)
2709 dpbp_disable(ethsw->mc_io, 0, ethsw->dpbp_dev->mc_handle);
2710 dpbp_close(ethsw->mc_io, 0, ethsw->dpbp_dev->mc_handle);
2711 fsl_mc_object_free(ethsw->dpbp_dev);
2714 static int dpaa2_switch_alloc_rings(struct ethsw_core *ethsw)
2719 ethsw->fq[i].store =
2721 ethsw->dev);
2722 if (!ethsw->fq[i].store) {
2723 dev_err(ethsw->dev, "dpaa2_io_store_create failed\n");
2725 dpaa2_io_store_destroy(ethsw->fq[i].store);
2733 static void dpaa2_switch_destroy_rings(struct ethsw_core *ethsw)
2738 dpaa2_io_store_destroy(ethsw->fq[i].store);
2754 dev_err(fq->ethsw->dev, "dpaa2_io_service_pull err %d", err);
2762 struct ethsw_core *ethsw = fq->ethsw;
2772 dev_err_once(ethsw->dev,
2805 dpaa2_switch_refill_bp(fq->ethsw);
2841 static int dpaa2_switch_setup_dpio(struct ethsw_core *ethsw)
2848 nctx = ðsw->fq[i].nctx;
2855 nctx->id = ethsw->fq[i].fqid;
2858 err = dpaa2_io_service_register(NULL, nctx, ethsw->dev);
2871 err = dpsw_ctrl_if_set_queue(ethsw->mc_io, 0,
2872 ethsw->dpsw_handle,
2873 ethsw->fq[i].type,
2882 dpaa2_io_service_deregister(NULL, nctx, ethsw->dev);
2885 dpaa2_io_service_deregister(NULL, ðsw->fq[j].nctx,
2886 ethsw->dev);
2891 static void dpaa2_switch_free_dpio(struct ethsw_core *ethsw)
2896 dpaa2_io_service_deregister(NULL, ðsw->fq[i].nctx,
2897 ethsw->dev);
2900 static int dpaa2_switch_ctrl_if_setup(struct ethsw_core *ethsw)
2905 err = dpaa2_switch_setup_fqs(ethsw);
2910 err = dpaa2_switch_setup_dpbp(ethsw);
2914 err = dpaa2_switch_alloc_rings(ethsw);
2918 err = dpaa2_switch_setup_dpio(ethsw);
2922 err = dpaa2_switch_seed_bp(ethsw);
2926 err = dpsw_ctrl_if_enable(ethsw->mc_io, 0, ethsw->dpsw_handle);
2928 dev_err(ethsw->dev, "dpsw_ctrl_if_enable err %d\n", err);
2935 dpaa2_switch_drain_bp(ethsw);
2937 dpaa2_switch_free_dpio(ethsw);
2939 dpaa2_switch_destroy_rings(ethsw);
2941 dpaa2_switch_free_dpbp(ethsw);
2946 static void dpaa2_switch_remove_port(struct ethsw_core *ethsw,
2949 struct ethsw_port_priv *port_priv = ethsw->ports[port_idx];
2953 ethsw->ports[port_idx] = NULL;
2959 struct ethsw_core *ethsw = dev_get_drvdata(dev);
2966 ethsw->dev_id = sw_dev->obj_desc.id;
2968 err = dpsw_open(ethsw->mc_io, 0, ethsw->dev_id, ðsw->dpsw_handle);
2974 err = dpsw_get_attributes(ethsw->mc_io, 0, ethsw->dpsw_handle,
2975 ðsw->sw_attr);
2981 err = dpsw_get_api_version(ethsw->mc_io, 0,
2982 ðsw->major,
2983 ðsw->minor);
2990 if (ethsw->major < DPSW_MIN_VER_MAJOR ||
2991 (ethsw->major == DPSW_MIN_VER_MAJOR &&
2992 ethsw->minor < DPSW_MIN_VER_MINOR)) {
2994 ethsw->major, ethsw->minor);
2999 if (!dpaa2_switch_supports_cpu_traffic(ethsw)) {
3004 dpaa2_switch_detect_features(ethsw);
3006 err = dpsw_reset(ethsw->mc_io, 0, ethsw->dpsw_handle);
3015 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
3016 err = dpsw_if_disable(ethsw->mc_io, 0, ethsw->dpsw_handle, i);
3022 err = dpsw_if_set_stp(ethsw->mc_io, 0, ethsw->dpsw_handle, i,
3035 err = dpsw_vlan_remove_if_untagged(ethsw->mc_io, 0, ethsw->dpsw_handle,
3044 err = dpsw_if_set_tci(ethsw->mc_io, 0, ethsw->dpsw_handle, i, &tci_cfg);
3050 err = dpsw_vlan_remove_if(ethsw->mc_io, 0, ethsw->dpsw_handle,
3058 err = dpsw_vlan_remove(ethsw->mc_io, 0, ethsw->dpsw_handle, DEFAULT_VLAN_ID);
3064 ethsw->workqueue = alloc_ordered_workqueue("%s_%d_ordered",
3065 WQ_MEM_RECLAIM, "ethsw",
3066 ethsw->sw_attr.id);
3067 if (!ethsw->workqueue) {
3072 err = dpsw_fdb_remove(ethsw->mc_io, 0, ethsw->dpsw_handle, 0);
3076 err = dpaa2_switch_ctrl_if_setup(ethsw);
3083 destroy_workqueue(ethsw->workqueue);
3086 dpsw_close(ethsw->mc_io, 0, ethsw->dpsw_handle);
3118 struct ethsw_core *ethsw = port_priv->ethsw_data;
3128 err = dpsw_if_get_attributes(ethsw->mc_io, 0, ethsw->dpsw_handle,
3137 fdb_cfg.num_fdb_entries = ethsw->sw_attr.max_fdb_entries / ethsw->sw_attr.num_ifs;
3138 err = dpsw_fdb_add(ethsw->mc_io, 0, ethsw->dpsw_handle,
3146 fdb = dpaa2_switch_fdb_get_unused(ethsw);
3161 err = dpaa2_switch_fdb_set_egress_flood(ethsw, port_priv->fdb->fdb_id);
3167 err = dpsw_acl_add(ethsw->mc_io, 0, ethsw->dpsw_handle,
3174 filter_block = dpaa2_switch_filter_block_get_unused(ethsw);
3175 filter_block->ethsw = ethsw;
3193 static void dpaa2_switch_ctrl_if_teardown(struct ethsw_core *ethsw)
3195 dpsw_ctrl_if_disable(ethsw->mc_io, 0, ethsw->dpsw_handle);
3196 dpaa2_switch_free_dpio(ethsw);
3197 dpaa2_switch_destroy_rings(ethsw);
3198 dpaa2_switch_drain_bp(ethsw);
3199 dpaa2_switch_free_dpbp(ethsw);
3205 struct ethsw_core *ethsw = dev_get_drvdata(dev);
3208 dpaa2_switch_ctrl_if_teardown(ethsw);
3210 destroy_workqueue(ethsw->workqueue);
3212 err = dpsw_close(ethsw->mc_io, 0, ethsw->dpsw_handle);
3220 struct ethsw_core *ethsw;
3225 ethsw = dev_get_drvdata(dev);
3229 dpsw_disable(ethsw->mc_io, 0, ethsw->dpsw_handle);
3231 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
3232 port_priv = ethsw->ports[i];
3234 dpaa2_switch_remove_port(ethsw, i);
3237 kfree(ethsw->fdbs);
3238 kfree(ethsw->filter_blocks);
3239 kfree(ethsw->ports);
3243 fsl_mc_portal_free(ethsw->mc_io);
3245 kfree(ethsw);
3250 static int dpaa2_switch_probe_port(struct ethsw_core *ethsw,
3254 struct device *dev = ethsw->dev;
3266 port_priv->ethsw_data = ethsw;
3289 ethsw->ports[port_idx] = port_priv;
3319 ethsw->ports[port_idx] = NULL;
3327 struct ethsw_core *ethsw;
3331 ethsw = kzalloc(sizeof(*ethsw), GFP_KERNEL);
3333 if (!ethsw)
3336 ethsw->dev = dev;
3337 ethsw->iommu_domain = iommu_get_domain_for_dev(dev);
3338 dev_set_drvdata(dev, ethsw);
3341 ðsw->mc_io);
3354 ethsw->ports = kcalloc(ethsw->sw_attr.num_ifs, sizeof(*ethsw->ports),
3356 if (!(ethsw->ports)) {
3361 ethsw->fdbs = kcalloc(ethsw->sw_attr.num_ifs, sizeof(*ethsw->fdbs),
3363 if (!ethsw->fdbs) {
3368 ethsw->filter_blocks = kcalloc(ethsw->sw_attr.num_ifs,
3369 sizeof(*ethsw->filter_blocks),
3371 if (!ethsw->filter_blocks) {
3376 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
3377 err = dpaa2_switch_probe_port(ethsw, i);
3387 netif_napi_add(ethsw->ports[0]->netdev, ðsw->fq[i].napi,
3398 ethsw->mirror_port = ethsw->sw_attr.num_ifs;
3403 for (i = 0; i < ethsw->sw_attr.num_ifs; i++) {
3404 err = register_netdev(ethsw->ports[i]->netdev);
3415 unregister_netdev(ethsw->ports[i]->netdev);
3418 dpsw_disable(ethsw->mc_io, 0, ethsw->dpsw_handle);
3421 dpaa2_switch_remove_port(ethsw, i);
3422 kfree(ethsw->filter_blocks);
3424 kfree(ethsw->fdbs);
3426 kfree(ethsw->ports);
3432 fsl_mc_portal_free(ethsw->mc_io);
3435 kfree(ethsw);