Lines Matching refs:mlxsw_sp

52 u32 mlxsw_sp_cells_bytes(const struct mlxsw_sp *mlxsw_sp, u32 cells)  in mlxsw_sp_cells_bytes()  argument
54 return mlxsw_sp->sb->cell_size * cells; in mlxsw_sp_cells_bytes()
57 u32 mlxsw_sp_bytes_cells(const struct mlxsw_sp *mlxsw_sp, u32 bytes) in mlxsw_sp_bytes_cells() argument
59 return DIV_ROUND_UP(bytes, mlxsw_sp->sb->cell_size); in mlxsw_sp_bytes_cells()
62 static struct mlxsw_sp_sb_pr *mlxsw_sp_sb_pr_get(struct mlxsw_sp *mlxsw_sp, in mlxsw_sp_sb_pr_get() argument
66 return &mlxsw_sp->sb->prs[dir][pool]; in mlxsw_sp_sb_pr_get()
69 static struct mlxsw_sp_sb_cm *mlxsw_sp_sb_cm_get(struct mlxsw_sp *mlxsw_sp, in mlxsw_sp_sb_cm_get() argument
73 return &mlxsw_sp->sb->ports[local_port].cms[dir][pg_buff]; in mlxsw_sp_sb_cm_get()
76 static struct mlxsw_sp_sb_pm *mlxsw_sp_sb_pm_get(struct mlxsw_sp *mlxsw_sp, in mlxsw_sp_sb_pm_get() argument
80 return &mlxsw_sp->sb->ports[local_port].pms[dir][pool]; in mlxsw_sp_sb_pm_get()
83 static int mlxsw_sp_sb_pr_write(struct mlxsw_sp *mlxsw_sp, u8 pool, in mlxsw_sp_sb_pr_write() argument
92 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbpr), sbpr_pl); in mlxsw_sp_sb_pr_write()
96 pr = mlxsw_sp_sb_pr_get(mlxsw_sp, pool, dir); in mlxsw_sp_sb_pr_write()
102 static int mlxsw_sp_sb_cm_write(struct mlxsw_sp *mlxsw_sp, u8 local_port, in mlxsw_sp_sb_cm_write() argument
111 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbcm), sbcm_pl); in mlxsw_sp_sb_cm_write()
117 cm = mlxsw_sp_sb_cm_get(mlxsw_sp, local_port, pg_buff, dir); in mlxsw_sp_sb_cm_write()
125 static int mlxsw_sp_sb_pm_write(struct mlxsw_sp *mlxsw_sp, u8 local_port, in mlxsw_sp_sb_pm_write() argument
135 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbpm), sbpm_pl); in mlxsw_sp_sb_pm_write()
139 pm = mlxsw_sp_sb_pm_get(mlxsw_sp, local_port, pool, dir); in mlxsw_sp_sb_pm_write()
145 static int mlxsw_sp_sb_pm_occ_clear(struct mlxsw_sp *mlxsw_sp, u8 local_port, in mlxsw_sp_sb_pm_occ_clear() argument
152 return mlxsw_reg_trans_query(mlxsw_sp->core, MLXSW_REG(sbpm), sbpm_pl, in mlxsw_sp_sb_pm_occ_clear()
165 static int mlxsw_sp_sb_pm_occ_query(struct mlxsw_sp *mlxsw_sp, u8 local_port, in mlxsw_sp_sb_pm_occ_query() argument
172 pm = mlxsw_sp_sb_pm_get(mlxsw_sp, local_port, pool, dir); in mlxsw_sp_sb_pm_occ_query()
174 return mlxsw_reg_trans_query(mlxsw_sp->core, MLXSW_REG(sbpm), sbpm_pl, in mlxsw_sp_sb_pm_occ_query()
190 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; in mlxsw_sp_port_pb_init() local
197 u16 size = mlxsw_sp_bytes_cells(mlxsw_sp, mlxsw_sp_pbs[i]); in mlxsw_sp_port_pb_init()
205 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pbmc), pbmc_pl); in mlxsw_sp_port_pb_init()
216 return mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, MLXSW_REG(pptb), in mlxsw_sp_port_pb_prio_init()
230 static int mlxsw_sp_sb_ports_init(struct mlxsw_sp *mlxsw_sp) in mlxsw_sp_sb_ports_init() argument
232 unsigned int max_ports = mlxsw_core_max_ports(mlxsw_sp->core); in mlxsw_sp_sb_ports_init()
234 mlxsw_sp->sb->ports = kcalloc(max_ports, in mlxsw_sp_sb_ports_init()
237 if (!mlxsw_sp->sb->ports) in mlxsw_sp_sb_ports_init()
242 static void mlxsw_sp_sb_ports_fini(struct mlxsw_sp *mlxsw_sp) in mlxsw_sp_sb_ports_fini() argument
244 kfree(mlxsw_sp->sb->ports); in mlxsw_sp_sb_ports_fini()
277 static int __mlxsw_sp_sb_prs_init(struct mlxsw_sp *mlxsw_sp, in __mlxsw_sp_sb_prs_init() argument
286 u32 size = mlxsw_sp_bytes_cells(mlxsw_sp, prs[i].size); in __mlxsw_sp_sb_prs_init()
288 err = mlxsw_sp_sb_pr_write(mlxsw_sp, i, dir, prs[i].mode, size); in __mlxsw_sp_sb_prs_init()
295 static int mlxsw_sp_sb_prs_init(struct mlxsw_sp *mlxsw_sp) in mlxsw_sp_sb_prs_init() argument
299 err = __mlxsw_sp_sb_prs_init(mlxsw_sp, MLXSW_REG_SBXX_DIR_INGRESS, in mlxsw_sp_sb_prs_init()
304 return __mlxsw_sp_sb_prs_init(mlxsw_sp, MLXSW_REG_SBXX_DIR_EGRESS, in mlxsw_sp_sb_prs_init()
393 static int __mlxsw_sp_sb_cms_init(struct mlxsw_sp *mlxsw_sp, u8 local_port, in __mlxsw_sp_sb_cms_init() argument
411 min_buff = mlxsw_sp_bytes_cells(mlxsw_sp, cm->min_buff); in __mlxsw_sp_sb_cms_init()
412 err = mlxsw_sp_sb_cm_write(mlxsw_sp, local_port, i, dir, in __mlxsw_sp_sb_cms_init()
424 err = __mlxsw_sp_sb_cms_init(mlxsw_sp_port->mlxsw_sp, in mlxsw_sp_port_sb_cms_init()
431 return __mlxsw_sp_sb_cms_init(mlxsw_sp_port->mlxsw_sp, in mlxsw_sp_port_sb_cms_init()
438 static int mlxsw_sp_cpu_port_sb_cms_init(struct mlxsw_sp *mlxsw_sp) in mlxsw_sp_cpu_port_sb_cms_init() argument
440 return __mlxsw_sp_sb_cms_init(mlxsw_sp, 0, MLXSW_REG_SBXX_DIR_EGRESS, in mlxsw_sp_cpu_port_sb_cms_init()
469 static int __mlxsw_sp_port_sb_pms_init(struct mlxsw_sp *mlxsw_sp, u8 local_port, in __mlxsw_sp_port_sb_pms_init() argument
481 err = mlxsw_sp_sb_pm_write(mlxsw_sp, local_port, i, dir, in __mlxsw_sp_port_sb_pms_init()
493 err = __mlxsw_sp_port_sb_pms_init(mlxsw_sp_port->mlxsw_sp, in mlxsw_sp_port_sb_pms_init()
500 return __mlxsw_sp_port_sb_pms_init(mlxsw_sp_port->mlxsw_sp, in mlxsw_sp_port_sb_pms_init()
540 static int mlxsw_sp_sb_mms_init(struct mlxsw_sp *mlxsw_sp) in mlxsw_sp_sb_mms_init() argument
554 min_buff = mlxsw_sp_bytes_cells(mlxsw_sp, mc->min_buff); in mlxsw_sp_sb_mms_init()
557 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(sbmm), sbmm_pl); in mlxsw_sp_sb_mms_init()
564 int mlxsw_sp_buffers_init(struct mlxsw_sp *mlxsw_sp) in mlxsw_sp_buffers_init() argument
569 if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, CELL_SIZE)) in mlxsw_sp_buffers_init()
572 if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, MAX_BUFFER_SIZE)) in mlxsw_sp_buffers_init()
574 sb_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_BUFFER_SIZE); in mlxsw_sp_buffers_init()
576 mlxsw_sp->sb = kzalloc(sizeof(*mlxsw_sp->sb), GFP_KERNEL); in mlxsw_sp_buffers_init()
577 if (!mlxsw_sp->sb) in mlxsw_sp_buffers_init()
579 mlxsw_sp->sb->cell_size = MLXSW_CORE_RES_GET(mlxsw_sp->core, CELL_SIZE); in mlxsw_sp_buffers_init()
581 err = mlxsw_sp_sb_ports_init(mlxsw_sp); in mlxsw_sp_buffers_init()
584 err = mlxsw_sp_sb_prs_init(mlxsw_sp); in mlxsw_sp_buffers_init()
587 err = mlxsw_sp_cpu_port_sb_cms_init(mlxsw_sp); in mlxsw_sp_buffers_init()
590 err = mlxsw_sp_sb_mms_init(mlxsw_sp); in mlxsw_sp_buffers_init()
593 err = devlink_sb_register(priv_to_devlink(mlxsw_sp->core), 0, sb_size, in mlxsw_sp_buffers_init()
607 mlxsw_sp_sb_ports_fini(mlxsw_sp); in mlxsw_sp_buffers_init()
609 kfree(mlxsw_sp->sb); in mlxsw_sp_buffers_init()
613 void mlxsw_sp_buffers_fini(struct mlxsw_sp *mlxsw_sp) in mlxsw_sp_buffers_fini() argument
615 devlink_sb_unregister(priv_to_devlink(mlxsw_sp->core), 0); in mlxsw_sp_buffers_fini()
616 mlxsw_sp_sb_ports_fini(mlxsw_sp); in mlxsw_sp_buffers_fini()
617 kfree(mlxsw_sp->sb); in mlxsw_sp_buffers_fini()
660 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); in mlxsw_sp_sb_pool_get() local
663 struct mlxsw_sp_sb_pr *pr = mlxsw_sp_sb_pr_get(mlxsw_sp, pool, dir); in mlxsw_sp_sb_pool_get()
666 pool_info->size = mlxsw_sp_cells_bytes(mlxsw_sp, pr->size); in mlxsw_sp_sb_pool_get()
675 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); in mlxsw_sp_sb_pool_set() local
676 u32 pool_size = mlxsw_sp_bytes_cells(mlxsw_sp, size); in mlxsw_sp_sb_pool_set()
681 if (size > MLXSW_CORE_RES_GET(mlxsw_sp->core, MAX_BUFFER_SIZE)) in mlxsw_sp_sb_pool_set()
685 return mlxsw_sp_sb_pr_write(mlxsw_sp, pool, dir, mode, pool_size); in mlxsw_sp_sb_pool_set()
690 static u32 mlxsw_sp_sb_threshold_out(struct mlxsw_sp *mlxsw_sp, u8 pool, in mlxsw_sp_sb_threshold_out() argument
693 struct mlxsw_sp_sb_pr *pr = mlxsw_sp_sb_pr_get(mlxsw_sp, pool, dir); in mlxsw_sp_sb_threshold_out()
697 return mlxsw_sp_cells_bytes(mlxsw_sp, max_buff); in mlxsw_sp_sb_threshold_out()
700 static int mlxsw_sp_sb_threshold_in(struct mlxsw_sp *mlxsw_sp, u8 pool, in mlxsw_sp_sb_threshold_in() argument
704 struct mlxsw_sp_sb_pr *pr = mlxsw_sp_sb_pr_get(mlxsw_sp, pool, dir); in mlxsw_sp_sb_threshold_in()
715 *p_max_buff = mlxsw_sp_bytes_cells(mlxsw_sp, threshold); in mlxsw_sp_sb_threshold_in()
726 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; in mlxsw_sp_sb_port_pool_get() local
730 struct mlxsw_sp_sb_pm *pm = mlxsw_sp_sb_pm_get(mlxsw_sp, local_port, in mlxsw_sp_sb_port_pool_get()
733 *p_threshold = mlxsw_sp_sb_threshold_out(mlxsw_sp, pool, dir, in mlxsw_sp_sb_port_pool_get()
744 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; in mlxsw_sp_sb_port_pool_set() local
751 err = mlxsw_sp_sb_threshold_in(mlxsw_sp, pool, dir, in mlxsw_sp_sb_port_pool_set()
756 return mlxsw_sp_sb_pm_write(mlxsw_sp, local_port, pool, dir, in mlxsw_sp_sb_port_pool_set()
767 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; in mlxsw_sp_sb_tc_pool_bind_get() local
771 struct mlxsw_sp_sb_cm *cm = mlxsw_sp_sb_cm_get(mlxsw_sp, local_port, in mlxsw_sp_sb_tc_pool_bind_get()
774 *p_threshold = mlxsw_sp_sb_threshold_out(mlxsw_sp, cm->pool, dir, in mlxsw_sp_sb_tc_pool_bind_get()
787 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; in mlxsw_sp_sb_tc_pool_bind_set() local
798 err = mlxsw_sp_sb_threshold_in(mlxsw_sp, pool, dir, in mlxsw_sp_sb_tc_pool_bind_set()
803 return mlxsw_sp_sb_cm_write(mlxsw_sp, local_port, pg_buff, dir, in mlxsw_sp_sb_tc_pool_bind_set()
819 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); in mlxsw_sp_sb_sr_occ_query_cb() local
832 if (!mlxsw_sp->ports[local_port]) in mlxsw_sp_sb_sr_occ_query_cb()
835 cm = mlxsw_sp_sb_cm_get(mlxsw_sp, local_port, i, in mlxsw_sp_sb_sr_occ_query_cb()
846 if (!mlxsw_sp->ports[local_port]) in mlxsw_sp_sb_sr_occ_query_cb()
849 cm = mlxsw_sp_sb_cm_get(mlxsw_sp, local_port, i, in mlxsw_sp_sb_sr_occ_query_cb()
862 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); in mlxsw_sp_sb_occ_snapshot() local
888 if (!mlxsw_sp->ports[local_port]) in mlxsw_sp_sb_occ_snapshot()
893 err = mlxsw_sp_sb_pm_occ_query(mlxsw_sp, local_port, i, in mlxsw_sp_sb_occ_snapshot()
898 err = mlxsw_sp_sb_pm_occ_query(mlxsw_sp, local_port, i, in mlxsw_sp_sb_occ_snapshot()
931 struct mlxsw_sp *mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core); in mlxsw_sp_sb_occ_max_clear() local
953 if (!mlxsw_sp->ports[local_port]) in mlxsw_sp_sb_occ_max_clear()
958 err = mlxsw_sp_sb_pm_occ_clear(mlxsw_sp, local_port, i, in mlxsw_sp_sb_occ_max_clear()
963 err = mlxsw_sp_sb_pm_occ_clear(mlxsw_sp, local_port, i, in mlxsw_sp_sb_occ_max_clear()
995 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; in mlxsw_sp_sb_occ_port_pool_get() local
999 struct mlxsw_sp_sb_pm *pm = mlxsw_sp_sb_pm_get(mlxsw_sp, local_port, in mlxsw_sp_sb_occ_port_pool_get()
1002 *p_cur = mlxsw_sp_cells_bytes(mlxsw_sp, pm->occ.cur); in mlxsw_sp_sb_occ_port_pool_get()
1003 *p_max = mlxsw_sp_cells_bytes(mlxsw_sp, pm->occ.max); in mlxsw_sp_sb_occ_port_pool_get()
1014 struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; in mlxsw_sp_sb_occ_tc_port_bind_get() local
1018 struct mlxsw_sp_sb_cm *cm = mlxsw_sp_sb_cm_get(mlxsw_sp, local_port, in mlxsw_sp_sb_occ_tc_port_bind_get()
1021 *p_cur = mlxsw_sp_cells_bytes(mlxsw_sp, cm->occ.cur); in mlxsw_sp_sb_occ_tc_port_bind_get()
1022 *p_max = mlxsw_sp_cells_bytes(mlxsw_sp, cm->occ.max); in mlxsw_sp_sb_occ_tc_port_bind_get()