1010#include "ksz_dcb.h"
1111#include "ksz8.h"
1212
13- #define KSZ8_REG_PORT_1_CTRL_0 0x10
13+ /* Port X Control 0 register.
14+ * The datasheet specifies: Port 1 - 0x10, Port 2 - 0x20, Port 3 - 0x30.
15+ * However, the driver uses get_port_addr(), which maps Port 1 to offset 0.
16+ * Therefore, we define the base offset as 0x00 here to align with that logic.
17+ */
18+ #define KSZ8_REG_PORT_1_CTRL_0 0x00
1419#define KSZ8_PORT_DIFFSERV_ENABLE BIT(6)
1520#define KSZ8_PORT_802_1P_ENABLE BIT(5)
1621#define KSZ8_PORT_BASED_PRIO_M GENMASK(4, 3)
@@ -181,49 +186,6 @@ int ksz_port_get_default_prio(struct dsa_switch *ds, int port)
181186 return (data & mask ) >> shift ;
182187}
183188
184- /**
185- * ksz88x3_port_set_default_prio_quirks - Quirks for default priority
186- * @dev: Pointer to the KSZ switch device structure
187- * @port: Port number for which to set the default priority
188- * @prio: Priority value to set
189- *
190- * This function implements quirks for setting the default priority on KSZ88x3
191- * devices. On Port 2, no other priority providers are working
192- * except of PCP. So, configuring default priority on Port 2 is not possible.
193- * On Port 1, it is not possible to configure port priority if PCP
194- * apptrust on Port 2 is disabled. Since we disable multiple queues on the
195- * switch to disable PCP on Port 2, we need to ensure that the default priority
196- * configuration on Port 1 is in agreement with the configuration on Port 2.
197- *
198- * Return: 0 on success, or a negative error code on failure
199- */
200- static int ksz88x3_port_set_default_prio_quirks (struct ksz_device * dev , int port ,
201- u8 prio )
202- {
203- if (!prio )
204- return 0 ;
205-
206- if (port == KSZ_PORT_2 ) {
207- dev_err (dev -> dev , "Port priority configuration is not working on Port 2\n" );
208- return - EINVAL ;
209- } else if (port == KSZ_PORT_1 ) {
210- u8 port2_data ;
211- int ret ;
212-
213- ret = ksz_pread8 (dev , KSZ_PORT_2 , KSZ8_REG_PORT_1_CTRL_0 ,
214- & port2_data );
215- if (ret )
216- return ret ;
217-
218- if (!(port2_data & KSZ8_PORT_802_1P_ENABLE )) {
219- dev_err (dev -> dev , "Not possible to configure port priority on Port 1 if PCP apptrust on Port 2 is disabled\n" );
220- return - EINVAL ;
221- }
222- }
223-
224- return 0 ;
225- }
226-
227189/**
228190 * ksz_port_set_default_prio - Sets the default priority for a port on a KSZ
229191 * switch
@@ -239,18 +201,12 @@ static int ksz88x3_port_set_default_prio_quirks(struct ksz_device *dev, int port
239201int ksz_port_set_default_prio (struct dsa_switch * ds , int port , u8 prio )
240202{
241203 struct ksz_device * dev = ds -> priv ;
242- int reg , shift , ret ;
204+ int reg , shift ;
243205 u8 mask ;
244206
245207 if (prio >= dev -> info -> num_ipms )
246208 return - EINVAL ;
247209
248- if (ksz_is_ksz88x3 (dev )) {
249- ret = ksz88x3_port_set_default_prio_quirks (dev , port , prio );
250- if (ret )
251- return ret ;
252- }
253-
254210 ksz_get_default_port_prio_reg (dev , & reg , & mask , & shift );
255211
256212 return ksz_prmw8 (dev , port , reg , mask , (prio << shift ) & mask );
@@ -518,155 +474,6 @@ static int ksz_port_set_apptrust_validate(struct ksz_device *dev, int port,
518474 return - EINVAL ;
519475}
520476
521- /**
522- * ksz88x3_port1_apptrust_quirk - Quirk for apptrust configuration on Port 1
523- * of KSZ88x3 devices
524- * @dev: Pointer to the KSZ switch device structure
525- * @port: Port number for which to set the apptrust selectors
526- * @reg: Register address for the apptrust configuration
527- * @port1_data: Data to set for the apptrust configuration
528- *
529- * This function implements a quirk for apptrust configuration on Port 1 of
530- * KSZ88x3 devices. It ensures that apptrust configuration on Port 1 is not
531- * possible if PCP apptrust on Port 2 is disabled. This is because the Port 2
532- * seems to be permanently hardwired to PCP classification, so we need to
533- * do Port 1 configuration always in agreement with Port 2 configuration.
534- *
535- * Return: 0 on success, or a negative error code on failure
536- */
537- static int ksz88x3_port1_apptrust_quirk (struct ksz_device * dev , int port ,
538- int reg , u8 port1_data )
539- {
540- u8 port2_data ;
541- int ret ;
542-
543- /* If no apptrust is requested for Port 1, no need to care about Port 2
544- * configuration.
545- */
546- if (!(port1_data & (KSZ8_PORT_802_1P_ENABLE | KSZ8_PORT_DIFFSERV_ENABLE )))
547- return 0 ;
548-
549- /* We got request to enable any apptrust on Port 1. To make it possible,
550- * we need to enable multiple queues on the switch. If we enable
551- * multiqueue support, PCP classification on Port 2 will be
552- * automatically activated by HW.
553- */
554- ret = ksz_pread8 (dev , KSZ_PORT_2 , reg , & port2_data );
555- if (ret )
556- return ret ;
557-
558- /* If KSZ8_PORT_802_1P_ENABLE bit is set on Port 2, the driver showed
559- * the interest in PCP classification on Port 2. In this case,
560- * multiqueue support is enabled and we can enable any apptrust on
561- * Port 1.
562- * If KSZ8_PORT_802_1P_ENABLE bit is not set on Port 2, the PCP
563- * classification on Port 2 is still active, but the driver disabled
564- * multiqueue support and made frame prioritization inactive for
565- * all ports. In this case, we can't enable any apptrust on Port 1.
566- */
567- if (!(port2_data & KSZ8_PORT_802_1P_ENABLE )) {
568- dev_err (dev -> dev , "Not possible to enable any apptrust on Port 1 if PCP apptrust on Port 2 is disabled\n" );
569- return - EINVAL ;
570- }
571-
572- return 0 ;
573- }
574-
575- /**
576- * ksz88x3_port2_apptrust_quirk - Quirk for apptrust configuration on Port 2
577- * of KSZ88x3 devices
578- * @dev: Pointer to the KSZ switch device structure
579- * @port: Port number for which to set the apptrust selectors
580- * @reg: Register address for the apptrust configuration
581- * @port2_data: Data to set for the apptrust configuration
582- *
583- * This function implements a quirk for apptrust configuration on Port 2 of
584- * KSZ88x3 devices. It ensures that DSCP apptrust is not working on Port 2 and
585- * that it is not possible to disable PCP on Port 2. The only way to disable PCP
586- * on Port 2 is to disable multiple queues on the switch.
587- *
588- * Return: 0 on success, or a negative error code on failure
589- */
590- static int ksz88x3_port2_apptrust_quirk (struct ksz_device * dev , int port ,
591- int reg , u8 port2_data )
592- {
593- struct dsa_switch * ds = dev -> ds ;
594- u8 port1_data ;
595- int ret ;
596-
597- /* First validate Port 2 configuration. DiffServ/DSCP is not working
598- * on this port.
599- */
600- if (port2_data & KSZ8_PORT_DIFFSERV_ENABLE ) {
601- dev_err (dev -> dev , "DSCP apptrust is not working on Port 2\n" );
602- return - EINVAL ;
603- }
604-
605- /* If PCP support is requested, we need to enable all queues on the
606- * switch to make PCP priority working on Port 2.
607- */
608- if (port2_data & KSZ8_PORT_802_1P_ENABLE )
609- return ksz8_all_queues_split (dev , dev -> info -> num_tx_queues );
610-
611- /* We got request to disable PCP priority on Port 2.
612- * Now, we need to compare Port 2 configuration with Port 1
613- * configuration.
614- */
615- ret = ksz_pread8 (dev , KSZ_PORT_1 , reg , & port1_data );
616- if (ret )
617- return ret ;
618-
619- /* If Port 1 has any apptrust enabled, we can't disable multiple queues
620- * on the switch, so we can't disable PCP on Port 2.
621- */
622- if (port1_data & (KSZ8_PORT_802_1P_ENABLE | KSZ8_PORT_DIFFSERV_ENABLE )) {
623- dev_err (dev -> dev , "Not possible to disable PCP on Port 2 if any apptrust is enabled on Port 1\n" );
624- return - EINVAL ;
625- }
626-
627- /* Now we need to ensure that default priority on Port 1 is set to 0
628- * otherwise we can't disable multiqueue support on the switch.
629- */
630- ret = ksz_port_get_default_prio (ds , KSZ_PORT_1 );
631- if (ret < 0 ) {
632- return ret ;
633- } else if (ret ) {
634- dev_err (dev -> dev , "Not possible to disable PCP on Port 2 if non zero default priority is set on Port 1\n" );
635- return - EINVAL ;
636- }
637-
638- /* Port 1 has no apptrust or default priority set and we got request to
639- * disable PCP on Port 2. We can disable multiqueue support to disable
640- * PCP on Port 2.
641- */
642- return ksz8_all_queues_split (dev , 1 );
643- }
644-
645- /**
646- * ksz88x3_port_apptrust_quirk - Quirk for apptrust configuration on KSZ88x3
647- * devices
648- * @dev: Pointer to the KSZ switch device structure
649- * @port: Port number for which to set the apptrust selectors
650- * @reg: Register address for the apptrust configuration
651- * @data: Data to set for the apptrust configuration
652- *
653- * This function implements a quirk for apptrust configuration on KSZ88x3
654- * devices. It ensures that apptrust configuration on Port 1 and
655- * Port 2 is done in agreement with each other.
656- *
657- * Return: 0 on success, or a negative error code on failure
658- */
659- static int ksz88x3_port_apptrust_quirk (struct ksz_device * dev , int port ,
660- int reg , u8 data )
661- {
662- if (port == KSZ_PORT_1 )
663- return ksz88x3_port1_apptrust_quirk (dev , port , reg , data );
664- else if (port == KSZ_PORT_2 )
665- return ksz88x3_port2_apptrust_quirk (dev , port , reg , data );
666-
667- return 0 ;
668- }
669-
670477/**
671478 * ksz_port_set_apptrust - Sets the apptrust selectors for a port on a KSZ
672479 * switch
@@ -707,12 +514,6 @@ int ksz_port_set_apptrust(struct dsa_switch *ds, int port,
707514 }
708515 }
709516
710- if (ksz_is_ksz88x3 (dev )) {
711- ret = ksz88x3_port_apptrust_quirk (dev , port , reg , data );
712- if (ret )
713- return ret ;
714- }
715-
716517 return ksz_prmw8 (dev , port , reg , mask , data );
717518}
718519
@@ -799,21 +600,5 @@ int ksz_dcb_init_port(struct ksz_device *dev, int port)
799600 */
800601int ksz_dcb_init (struct ksz_device * dev )
801602{
802- int ret ;
803-
804- ret = ksz_init_global_dscp_map (dev );
805- if (ret )
806- return ret ;
807-
808- /* Enable 802.1p priority control on Port 2 during switch initialization.
809- * This setup is critical for the apptrust functionality on Port 1, which
810- * relies on the priority settings of Port 2. Note: Port 1 is naturally
811- * configured before Port 2, necessitating this configuration order.
812- */
813- if (ksz_is_ksz88x3 (dev ))
814- return ksz_prmw8 (dev , KSZ_PORT_2 , KSZ8_REG_PORT_1_CTRL_0 ,
815- KSZ8_PORT_802_1P_ENABLE ,
816- KSZ8_PORT_802_1P_ENABLE );
817-
818- return 0 ;
603+ return ksz_init_global_dscp_map (dev );
819604}
0 commit comments