Skip to content

Commit 2079667

Browse files
Danielmachonkuba-moo
authored andcommitted
net: sparx5: add feature support
Lan969x supports a number of different features, depending on the target. Add new field sparx5->features and initialize the features based on the target. Also add the function sparx5_has_feature() and use it throughout. For now, we only need to handle features: PSFP and PTP - more will come in the future. [1] https://www.microchip.com/en-us/product/lan9698 Reviewed-by: Steen Hegelund <[email protected]> Signed-off-by: Daniel Machon <[email protected]> Link: https://patch.msgid.link/20241024-sparx5-lan969x-switch-driver-2-v2-15-a0b5fae88a0f@microchip.com Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 98a0111 commit 2079667

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

drivers/net/ethernet/microchip/sparx5/sparx5_main.c

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,40 @@ bool is_sparx5(struct sparx5 *sparx5)
229229
}
230230
}
231231

232+
static void sparx5_init_features(struct sparx5 *sparx5)
233+
{
234+
switch (sparx5->target_ct) {
235+
case SPX5_TARGET_CT_7546:
236+
case SPX5_TARGET_CT_7549:
237+
case SPX5_TARGET_CT_7552:
238+
case SPX5_TARGET_CT_7556:
239+
case SPX5_TARGET_CT_7558:
240+
case SPX5_TARGET_CT_7546TSN:
241+
case SPX5_TARGET_CT_7549TSN:
242+
case SPX5_TARGET_CT_7552TSN:
243+
case SPX5_TARGET_CT_7556TSN:
244+
case SPX5_TARGET_CT_7558TSN:
245+
case SPX5_TARGET_CT_LAN9691VAO:
246+
case SPX5_TARGET_CT_LAN9694TSN:
247+
case SPX5_TARGET_CT_LAN9694RED:
248+
case SPX5_TARGET_CT_LAN9692VAO:
249+
case SPX5_TARGET_CT_LAN9696TSN:
250+
case SPX5_TARGET_CT_LAN9696RED:
251+
case SPX5_TARGET_CT_LAN9693VAO:
252+
case SPX5_TARGET_CT_LAN9698TSN:
253+
case SPX5_TARGET_CT_LAN9698RED:
254+
sparx5->features = (SPX5_FEATURE_PSFP | SPX5_FEATURE_PTP);
255+
break;
256+
default:
257+
break;
258+
}
259+
}
260+
261+
bool sparx5_has_feature(struct sparx5 *sparx5, enum sparx5_feature feature)
262+
{
263+
return sparx5->features & feature;
264+
}
265+
232266
static int sparx5_create_targets(struct sparx5 *sparx5)
233267
{
234268
const struct sparx5_main_io_resource *iomap = sparx5->data->iomap;
@@ -771,7 +805,8 @@ static int sparx5_start(struct sparx5 *sparx5)
771805
sparx5->xtr_irq = -ENXIO;
772806
}
773807

774-
if (sparx5->ptp_irq >= 0) {
808+
if (sparx5->ptp_irq >= 0 &&
809+
sparx5_has_feature(sparx5, SPX5_FEATURE_PTP)) {
775810
err = devm_request_threaded_irq(sparx5->dev, sparx5->ptp_irq,
776811
NULL, ops->ptp_irq_handler,
777812
IRQF_ONESHOT, "sparx5-ptp",
@@ -915,6 +950,9 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
915950
sparx5->target_ct = (enum spx5_target_chiptype)
916951
GCB_CHIP_ID_PART_ID_GET(sparx5->chip_id);
917952

953+
/* Initialize the features based on the target */
954+
sparx5_init_features(sparx5);
955+
918956
/* Initialize Switchcore and internal RAMs */
919957
err = sparx5_init_switchcore(sparx5);
920958
if (err) {

drivers/net/ethernet/microchip/sparx5/sparx5_main.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ enum sparx5_cal_bw {
7575
SPX5_CAL_SPEED_12G5 = 7
7676
};
7777

78+
enum sparx5_feature {
79+
SPX5_FEATURE_PSFP = BIT(0),
80+
SPX5_FEATURE_PTP = BIT(1),
81+
};
82+
7883
#define SPX5_PORTS 65
7984
#define SPX5_PORTS_ALL 70 /* Total number of ports */
8085

@@ -337,6 +342,7 @@ struct sparx5 {
337342
struct device *dev;
338343
u32 chip_id;
339344
enum spx5_target_chiptype target_ct;
345+
u32 features;
340346
void __iomem *regs[NUM_TARGETS];
341347
int port_count;
342348
struct mutex lock; /* MAC reg lock */
@@ -404,6 +410,7 @@ struct sparx5 {
404410

405411
/* sparx5_main.c */
406412
bool is_sparx5(struct sparx5 *sparx5);
413+
bool sparx5_has_feature(struct sparx5 *sparx5, enum sparx5_feature feature);
407414

408415
/* sparx5_switchdev.c */
409416
int sparx5_register_notifier_blocks(struct sparx5 *sparx5);

drivers/net/ethernet/microchip/sparx5/sparx5_tc_flower.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,11 @@ static int sparx5_tc_flower_replace(struct net_device *ndev,
12841284

12851285
/* Setup PSFP */
12861286
if (tc_sg_idx >= 0 || tc_pol_idx >= 0) {
1287+
if (!sparx5_has_feature(sparx5, SPX5_FEATURE_PSFP)) {
1288+
err = -EOPNOTSUPP;
1289+
goto out;
1290+
}
1291+
12871292
err = sparx5_tc_flower_psfp_setup(sparx5, vrule, tc_sg_idx,
12881293
tc_pol_idx, &sg, &fm, &sf);
12891294
if (err)

0 commit comments

Comments
 (0)