Lines Matching +full:int +full:- +full:map +full:- +full:mask

1 // SPDX-License-Identifier: GPL-2.0
54 /* ksz_supported_apptrust[] - Supported apptrust selectors and Priority Order
55 * of Internal Priority Map (IPM) sources.
58 * the index within the array indicates the priority of the selector - lower
65 * non-configurable precedence where certain types of priority information
68 * 1. Tail Tag - Highest priority, overrides ACL, VLAN PCP, and DSCP priorities.
69 * 2. ACL - Overrides VLAN PCP and DSCP priorities.
70 * 3. VLAN PCP - Overrides DSCP priority.
71 * 4. DSCP - Lowest priority, does not override any other priority source.
77 * DCB_APP_SEL_PCP - Priority Code Point selector
78 * IEEE_8021QAZ_APP_SEL_DSCP - Differentiated Services Code Point selector
89 static void ksz_get_default_port_prio_reg(struct ksz_device *dev, int *reg, in ksz_get_default_port_prio_reg()
90 u8 *mask, int *shift) in ksz_get_default_port_prio_reg() argument
94 *mask = KSZ8_PORT_BASED_PRIO_M; in ksz_get_default_port_prio_reg()
98 *mask = KSZ9477_PORT_BASED_PRIO_M; in ksz_get_default_port_prio_reg()
104 * ksz_get_dscp_prio_reg - Retrieves the DSCP-to-priority-mapping register
108 * @mask: Pointer to the mask to be set
111 * DSCP values per register, and the mask to be set.
113 static void ksz_get_dscp_prio_reg(struct ksz_device *dev, int *reg, in ksz_get_dscp_prio_reg()
114 int *per_reg, u8 *mask) in ksz_get_dscp_prio_reg() argument
119 *mask = GENMASK(1, 0); in ksz_get_dscp_prio_reg()
123 *mask = GENMASK(1, 0); in ksz_get_dscp_prio_reg()
127 *mask = GENMASK(2, 0); in ksz_get_dscp_prio_reg()
132 * ksz_get_apptrust_map_and_reg - Retrieves the apptrust map and register
134 * @map: Pointer to the apptrust map to be set
136 * @mask: Pointer to the mask to be set
138 * This function retrieves the apptrust map and register address for the
142 const struct ksz_apptrust_map **map, in ksz_get_apptrust_map_and_reg() argument
143 int *reg, u8 *mask) in ksz_get_apptrust_map_and_reg() argument
146 *map = ksz8_apptrust_map_to_bit; in ksz_get_apptrust_map_and_reg()
148 *mask = KSZ8_PORT_DIFFSERV_ENABLE | KSZ8_PORT_802_1P_ENABLE; in ksz_get_apptrust_map_and_reg()
150 *map = ksz9477_apptrust_map_to_bit; in ksz_get_apptrust_map_and_reg()
152 *mask = KSZ9477_PORT_802_1P_PRIO_ENABLE | in ksz_get_apptrust_map_and_reg()
158 * ksz_port_get_default_prio - Retrieves the default priority for a port on a
169 int ksz_port_get_default_prio(struct dsa_switch *ds, int port) in ksz_port_get_default_prio()
171 struct ksz_device *dev = ds->priv; in ksz_port_get_default_prio()
172 int ret, reg, shift; in ksz_port_get_default_prio()
173 u8 data, mask; in ksz_port_get_default_prio() local
175 ksz_get_default_port_prio_reg(dev, &reg, &mask, &shift); in ksz_port_get_default_prio()
181 return (data & mask) >> shift; in ksz_port_get_default_prio()
185 * ksz88x3_port_set_default_prio_quirks - Quirks for default priority
200 static int ksz88x3_port_set_default_prio_quirks(struct ksz_device *dev, int port, in ksz88x3_port_set_default_prio_quirks()
207 dev_err(dev->dev, "Port priority configuration is not working on Port 2\n"); in ksz88x3_port_set_default_prio_quirks()
208 return -EINVAL; in ksz88x3_port_set_default_prio_quirks()
211 int ret; in ksz88x3_port_set_default_prio_quirks()
219 …dev_err(dev->dev, "Not possible to configure port priority on Port 1 if PCP apptrust on Port 2 is … in ksz88x3_port_set_default_prio_quirks()
220 return -EINVAL; in ksz88x3_port_set_default_prio_quirks()
228 * ksz_port_set_default_prio - Sets the default priority for a port on a KSZ
239 int ksz_port_set_default_prio(struct dsa_switch *ds, int port, u8 prio) in ksz_port_set_default_prio()
241 struct ksz_device *dev = ds->priv; in ksz_port_set_default_prio()
242 int reg, shift, ret; in ksz_port_set_default_prio()
243 u8 mask; in ksz_port_set_default_prio() local
245 if (prio >= dev->info->num_ipms) in ksz_port_set_default_prio()
246 return -EINVAL; in ksz_port_set_default_prio()
254 ksz_get_default_port_prio_reg(dev, &reg, &mask, &shift); in ksz_port_set_default_prio()
256 return ksz_prmw8(dev, port, reg, mask, (prio << shift) & mask); in ksz_port_set_default_prio()
260 * ksz_port_get_dscp_prio - Retrieves the priority for a DSCP value on a KSZ
266 * This function fetches the priority value from switch global DSCP-to-priorty
272 int ksz_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) in ksz_port_get_dscp_prio()
274 struct ksz_device *dev = ds->priv; in ksz_port_get_dscp_prio()
275 int reg, per_reg, ret, shift; in ksz_port_get_dscp_prio()
276 u8 data, mask; in ksz_port_get_dscp_prio() local
278 ksz_get_dscp_prio_reg(dev, &reg, &per_reg, &mask); in ksz_port_get_dscp_prio()
280 /* If DSCP remapping is disabled, DSCP bits 3-5 are used as Internal in ksz_port_get_dscp_prio()
281 * Priority Map (IPM) in ksz_port_get_dscp_prio()
288 /* If DSCP remapping is disabled, DSCP bits 3-5 are used as in ksz_port_get_dscp_prio()
289 * Internal Priority Map (IPM) in ksz_port_get_dscp_prio()
306 return (data >> shift) & mask; in ksz_port_get_dscp_prio()
310 * ksz_set_global_dscp_entry - Sets the global DSCP-to-priority mapping entry
315 * This function sets the global DSCP-to-priority mapping entry for the
320 static int ksz_set_global_dscp_entry(struct ksz_device *dev, u8 dscp, u8 ipm) in ksz_set_global_dscp_entry()
322 int reg, per_reg, shift; in ksz_set_global_dscp_entry()
323 u8 mask; in ksz_set_global_dscp_entry() local
325 ksz_get_dscp_prio_reg(dev, &reg, &per_reg, &mask); in ksz_set_global_dscp_entry()
329 return ksz_rmw8(dev, reg + (dscp / per_reg), mask << shift, in ksz_set_global_dscp_entry()
334 * ksz_init_global_dscp_map - Initializes the global DSCP-to-priority mapping
337 * This function initializes the global DSCP-to-priority mapping table for the
342 static int ksz_init_global_dscp_map(struct ksz_device *dev) in ksz_init_global_dscp_map()
344 int ret, dscp; in ksz_init_global_dscp_map()
359 int ipm, tt; in ksz_init_global_dscp_map()
361 /* Map DSCP to Traffic Type, which is corresponding to the in ksz_init_global_dscp_map()
362 * Internal Priority Map (IPM) in the switch. in ksz_init_global_dscp_map()
375 ipm = ieee8021q_tt_to_tc(tt, dev->info->num_tx_queues); in ksz_init_global_dscp_map()
388 * ksz_port_add_dscp_prio - Adds a DSCP-to-priority mapping entry for a port on
391 * @port: Port number for which to add the DSCP-to-priority mapping entry
397 int ksz_port_add_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio) in ksz_port_add_dscp_prio()
399 struct ksz_device *dev = ds->priv; in ksz_port_add_dscp_prio()
401 if (prio >= dev->info->num_ipms) in ksz_port_add_dscp_prio()
402 return -ERANGE; in ksz_port_add_dscp_prio()
408 * ksz_port_del_dscp_prio - Deletes a DSCP-to-priority mapping entry for a port
411 * @port: Port number for which to delete the DSCP-to-priority mapping entry
417 int ksz_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, u8 prio) in ksz_port_del_dscp_prio()
419 struct ksz_device *dev = ds->priv; in ksz_port_del_dscp_prio()
420 int ipm; in ksz_port_del_dscp_prio()
427 dev->info->num_tx_queues); in ksz_port_del_dscp_prio()
438 * ksz_apptrust_error - Prints an error message for an invalid apptrust selector
447 int i; in ksz_apptrust_error()
459 dev_err(dev->dev, "Invalid apptrust selector or priority order. Supported: %s\n", in ksz_apptrust_error()
464 * ksz_port_set_apptrust_validate - Validates the apptrust selectors
476 * 1. DCB_APP_SEL_PCP - Priority Code Point selector (highest priority)
477 * 2. IEEE_8021QAZ_APP_SEL_DSCP - Differentiated Services Code Point selector
482 static int ksz_port_set_apptrust_validate(struct ksz_device *dev, int port, in ksz_port_set_apptrust_validate()
483 const u8 *sel, int nsel) in ksz_port_set_apptrust_validate()
485 int i, j, found; in ksz_port_set_apptrust_validate()
486 int j_prev = 0; in ksz_port_set_apptrust_validate()
518 return -EINVAL; in ksz_port_set_apptrust_validate()
522 * ksz88x3_port1_apptrust_quirk - Quirk for apptrust configuration on Port 1
537 static int ksz88x3_port1_apptrust_quirk(struct ksz_device *dev, int port, in ksz88x3_port1_apptrust_quirk()
538 int reg, u8 port1_data) in ksz88x3_port1_apptrust_quirk()
541 int ret; in ksz88x3_port1_apptrust_quirk()
568 …dev_err(dev->dev, "Not possible to enable any apptrust on Port 1 if PCP apptrust on Port 2 is disa… in ksz88x3_port1_apptrust_quirk()
569 return -EINVAL; in ksz88x3_port1_apptrust_quirk()
576 * ksz88x3_port2_apptrust_quirk - Quirk for apptrust configuration on Port 2
590 static int ksz88x3_port2_apptrust_quirk(struct ksz_device *dev, int port, in ksz88x3_port2_apptrust_quirk()
591 int reg, u8 port2_data) in ksz88x3_port2_apptrust_quirk()
593 struct dsa_switch *ds = dev->ds; in ksz88x3_port2_apptrust_quirk()
595 int ret; in ksz88x3_port2_apptrust_quirk()
601 dev_err(dev->dev, "DSCP apptrust is not working on Port 2\n"); in ksz88x3_port2_apptrust_quirk()
602 return -EINVAL; in ksz88x3_port2_apptrust_quirk()
609 return ksz8_all_queues_split(dev, dev->info->num_tx_queues); in ksz88x3_port2_apptrust_quirk()
623 dev_err(dev->dev, "Not possible to disable PCP on Port 2 if any apptrust is enabled on Port 1\n"); in ksz88x3_port2_apptrust_quirk()
624 return -EINVAL; in ksz88x3_port2_apptrust_quirk()
634 …dev_err(dev->dev, "Not possible to disable PCP on Port 2 if non zero default priority is set on Po… in ksz88x3_port2_apptrust_quirk()
635 return -EINVAL; in ksz88x3_port2_apptrust_quirk()
646 * ksz88x3_port_apptrust_quirk - Quirk for apptrust configuration on KSZ88x3
659 static int ksz88x3_port_apptrust_quirk(struct ksz_device *dev, int port, in ksz88x3_port_apptrust_quirk()
660 int reg, u8 data) in ksz88x3_port_apptrust_quirk()
671 * ksz_port_set_apptrust - Sets the apptrust selectors for a port on a KSZ
683 int ksz_port_set_apptrust(struct dsa_switch *ds, int port, in ksz_port_set_apptrust()
684 const u8 *sel, int nsel) in ksz_port_set_apptrust()
686 const struct ksz_apptrust_map *map; in ksz_port_set_apptrust() local
687 struct ksz_device *dev = ds->priv; in ksz_port_set_apptrust()
688 int reg, i, ret; in ksz_port_set_apptrust()
690 u8 mask; in ksz_port_set_apptrust() local
696 ksz_get_apptrust_map_and_reg(dev, &map, &reg, &mask); in ksz_port_set_apptrust()
699 int j; in ksz_port_set_apptrust()
705 data |= map[j].bit; in ksz_port_set_apptrust()
716 return ksz_prmw8(dev, port, reg, mask, data); in ksz_port_set_apptrust()
720 * ksz_port_get_apptrust - Retrieves the apptrust selectors for a port on a KSZ
732 int ksz_port_get_apptrust(struct dsa_switch *ds, int port, u8 *sel, int *nsel) in ksz_port_get_apptrust()
734 const struct ksz_apptrust_map *map; in ksz_port_get_apptrust() local
735 struct ksz_device *dev = ds->priv; in ksz_port_get_apptrust()
736 int reg, i, ret; in ksz_port_get_apptrust()
738 u8 mask; in ksz_port_get_apptrust() local
740 ksz_get_apptrust_map_and_reg(dev, &map, &reg, &mask); in ksz_port_get_apptrust()
748 if (data & map[i].bit) in ksz_port_get_apptrust()
756 * ksz_dcb_init_port - Initializes the DCB configuration for a port on a KSZ
768 int ksz_dcb_init_port(struct ksz_device *dev, int port) in ksz_dcb_init_port()
771 int ret, ipm; in ksz_dcb_init_port()
775 dev->info->num_tx_queues); in ksz_dcb_init_port()
783 ret = ksz_port_set_default_prio(dev->ds, port, ipm); in ksz_dcb_init_port()
787 return ksz_port_set_apptrust(dev->ds, port, ksz_default_apptrust, in ksz_dcb_init_port()
792 * ksz_dcb_init - Initializes the DCB configuration for a KSZ switch
796 * DSCP-to-priority mapping table is initialized.
800 int ksz_dcb_init(struct ksz_device *dev) in ksz_dcb_init()
802 int ret; in ksz_dcb_init()