|
7 | 7 | #define SJA1105_TAS_CLKSRC_STANDALONE 1 |
8 | 8 | #define SJA1105_TAS_CLKSRC_AS6802 2 |
9 | 9 | #define SJA1105_TAS_CLKSRC_PTP 3 |
10 | | -#define SJA1105_TAS_MAX_DELTA BIT(19) |
11 | 10 | #define SJA1105_GATE_MASK GENMASK_ULL(SJA1105_NUM_TC - 1, 0) |
12 | 11 |
|
13 | 12 | #define work_to_sja1105_tas(d) \ |
14 | 13 | container_of((d), struct sja1105_tas_data, tas_work) |
15 | 14 | #define tas_to_sja1105(d) \ |
16 | 15 | container_of((d), struct sja1105_private, tas_data) |
17 | 16 |
|
18 | | -/* This is not a preprocessor macro because the "ns" argument may or may not be |
19 | | - * s64 at caller side. This ensures it is properly type-cast before div_s64. |
20 | | - */ |
21 | | -static s64 ns_to_sja1105_delta(s64 ns) |
22 | | -{ |
23 | | - return div_s64(ns, 200); |
24 | | -} |
25 | | - |
26 | | -static s64 sja1105_delta_to_ns(s64 delta) |
27 | | -{ |
28 | | - return delta * 200; |
29 | | -} |
30 | | - |
31 | 17 | static int sja1105_tas_set_runtime_params(struct sja1105_private *priv) |
32 | 18 | { |
33 | 19 | struct sja1105_tas_data *tas_data = &priv->tas_data; |
| 20 | + struct sja1105_gating_config *gating_cfg = &tas_data->gating_cfg; |
34 | 21 | struct dsa_switch *ds = priv->ds; |
35 | 22 | s64 earliest_base_time = S64_MAX; |
36 | 23 | s64 latest_base_time = 0; |
@@ -59,6 +46,19 @@ static int sja1105_tas_set_runtime_params(struct sja1105_private *priv) |
59 | 46 | } |
60 | 47 | } |
61 | 48 |
|
| 49 | + if (!list_empty(&gating_cfg->entries)) { |
| 50 | + tas_data->enabled = true; |
| 51 | + |
| 52 | + if (max_cycle_time < gating_cfg->cycle_time) |
| 53 | + max_cycle_time = gating_cfg->cycle_time; |
| 54 | + if (latest_base_time < gating_cfg->base_time) |
| 55 | + latest_base_time = gating_cfg->base_time; |
| 56 | + if (earliest_base_time > gating_cfg->base_time) { |
| 57 | + earliest_base_time = gating_cfg->base_time; |
| 58 | + its_cycle_time = gating_cfg->cycle_time; |
| 59 | + } |
| 60 | + } |
| 61 | + |
62 | 62 | if (!tas_data->enabled) |
63 | 63 | return 0; |
64 | 64 |
|
@@ -155,13 +155,14 @@ static int sja1105_tas_set_runtime_params(struct sja1105_private *priv) |
155 | 155 | * their "subschedule end index" (subscheind) equal to the last valid |
156 | 156 | * subschedule's end index (in this case 5). |
157 | 157 | */ |
158 | | -static int sja1105_init_scheduling(struct sja1105_private *priv) |
| 158 | +int sja1105_init_scheduling(struct sja1105_private *priv) |
159 | 159 | { |
160 | 160 | struct sja1105_schedule_entry_points_entry *schedule_entry_points; |
161 | 161 | struct sja1105_schedule_entry_points_params_entry |
162 | 162 | *schedule_entry_points_params; |
163 | 163 | struct sja1105_schedule_params_entry *schedule_params; |
164 | 164 | struct sja1105_tas_data *tas_data = &priv->tas_data; |
| 165 | + struct sja1105_gating_config *gating_cfg = &tas_data->gating_cfg; |
165 | 166 | struct sja1105_schedule_entry *schedule; |
166 | 167 | struct sja1105_table *table; |
167 | 168 | int schedule_start_idx; |
@@ -213,6 +214,11 @@ static int sja1105_init_scheduling(struct sja1105_private *priv) |
213 | 214 | } |
214 | 215 | } |
215 | 216 |
|
| 217 | + if (!list_empty(&gating_cfg->entries)) { |
| 218 | + num_entries += gating_cfg->num_entries; |
| 219 | + num_cycles++; |
| 220 | + } |
| 221 | + |
216 | 222 | /* Nothing to do */ |
217 | 223 | if (!num_cycles) |
218 | 224 | return 0; |
@@ -312,6 +318,42 @@ static int sja1105_init_scheduling(struct sja1105_private *priv) |
312 | 318 | cycle++; |
313 | 319 | } |
314 | 320 |
|
| 321 | + if (!list_empty(&gating_cfg->entries)) { |
| 322 | + struct sja1105_gate_entry *e; |
| 323 | + |
| 324 | + /* Relative base time */ |
| 325 | + s64 rbt; |
| 326 | + |
| 327 | + schedule_start_idx = k; |
| 328 | + schedule_end_idx = k + gating_cfg->num_entries - 1; |
| 329 | + rbt = future_base_time(gating_cfg->base_time, |
| 330 | + gating_cfg->cycle_time, |
| 331 | + tas_data->earliest_base_time); |
| 332 | + rbt -= tas_data->earliest_base_time; |
| 333 | + entry_point_delta = ns_to_sja1105_delta(rbt) + 1; |
| 334 | + |
| 335 | + schedule_entry_points[cycle].subschindx = cycle; |
| 336 | + schedule_entry_points[cycle].delta = entry_point_delta; |
| 337 | + schedule_entry_points[cycle].address = schedule_start_idx; |
| 338 | + |
| 339 | + for (i = cycle; i < 8; i++) |
| 340 | + schedule_params->subscheind[i] = schedule_end_idx; |
| 341 | + |
| 342 | + list_for_each_entry(e, &gating_cfg->entries, list) { |
| 343 | + schedule[k].delta = ns_to_sja1105_delta(e->interval); |
| 344 | + schedule[k].destports = e->rule->vl.destports; |
| 345 | + schedule[k].setvalid = true; |
| 346 | + schedule[k].txen = true; |
| 347 | + schedule[k].vlindex = e->rule->vl.sharindx; |
| 348 | + schedule[k].winstindex = e->rule->vl.sharindx; |
| 349 | + if (e->gate_state) /* Gate open */ |
| 350 | + schedule[k].winst = true; |
| 351 | + else /* Gate closed */ |
| 352 | + schedule[k].winend = true; |
| 353 | + k++; |
| 354 | + } |
| 355 | + } |
| 356 | + |
315 | 357 | return 0; |
316 | 358 | } |
317 | 359 |
|
@@ -415,6 +457,54 @@ sja1105_tas_check_conflicts(struct sja1105_private *priv, int port, |
415 | 457 | return false; |
416 | 458 | } |
417 | 459 |
|
| 460 | +/* Check the tc-taprio configuration on @port for conflicts with the tc-gate |
| 461 | + * global subschedule. If @port is -1, check it against all ports. |
| 462 | + * To reuse the sja1105_tas_check_conflicts logic without refactoring it, |
| 463 | + * convert the gating configuration to a dummy tc-taprio offload structure. |
| 464 | + */ |
| 465 | +bool sja1105_gating_check_conflicts(struct sja1105_private *priv, int port, |
| 466 | + struct netlink_ext_ack *extack) |
| 467 | +{ |
| 468 | + struct sja1105_gating_config *gating_cfg = &priv->tas_data.gating_cfg; |
| 469 | + size_t num_entries = gating_cfg->num_entries; |
| 470 | + struct tc_taprio_qopt_offload *dummy; |
| 471 | + struct sja1105_gate_entry *e; |
| 472 | + bool conflict; |
| 473 | + int i = 0; |
| 474 | + |
| 475 | + if (list_empty(&gating_cfg->entries)) |
| 476 | + return false; |
| 477 | + |
| 478 | + dummy = kzalloc(sizeof(struct tc_taprio_sched_entry) * num_entries + |
| 479 | + sizeof(struct tc_taprio_qopt_offload), GFP_KERNEL); |
| 480 | + if (!dummy) { |
| 481 | + NL_SET_ERR_MSG_MOD(extack, "Failed to allocate memory"); |
| 482 | + return true; |
| 483 | + } |
| 484 | + |
| 485 | + dummy->num_entries = num_entries; |
| 486 | + dummy->base_time = gating_cfg->base_time; |
| 487 | + dummy->cycle_time = gating_cfg->cycle_time; |
| 488 | + |
| 489 | + list_for_each_entry(e, &gating_cfg->entries, list) |
| 490 | + dummy->entries[i++].interval = e->interval; |
| 491 | + |
| 492 | + if (port != -1) { |
| 493 | + conflict = sja1105_tas_check_conflicts(priv, port, dummy); |
| 494 | + } else { |
| 495 | + for (port = 0; port < SJA1105_NUM_PORTS; port++) { |
| 496 | + conflict = sja1105_tas_check_conflicts(priv, port, |
| 497 | + dummy); |
| 498 | + if (conflict) |
| 499 | + break; |
| 500 | + } |
| 501 | + } |
| 502 | + |
| 503 | + kfree(dummy); |
| 504 | + |
| 505 | + return conflict; |
| 506 | +} |
| 507 | + |
418 | 508 | int sja1105_setup_tc_taprio(struct dsa_switch *ds, int port, |
419 | 509 | struct tc_taprio_qopt_offload *admin) |
420 | 510 | { |
@@ -473,6 +563,11 @@ int sja1105_setup_tc_taprio(struct dsa_switch *ds, int port, |
473 | 563 | return -ERANGE; |
474 | 564 | } |
475 | 565 |
|
| 566 | + if (sja1105_gating_check_conflicts(priv, port, NULL)) { |
| 567 | + dev_err(ds->dev, "Conflict with tc-gate schedule\n"); |
| 568 | + return -ERANGE; |
| 569 | + } |
| 570 | + |
476 | 571 | tas_data->offload[port] = taprio_offload_get(admin); |
477 | 572 |
|
478 | 573 | rc = sja1105_init_scheduling(priv); |
@@ -779,6 +874,8 @@ void sja1105_tas_setup(struct dsa_switch *ds) |
779 | 874 | INIT_WORK(&tas_data->tas_work, sja1105_tas_state_machine); |
780 | 875 | tas_data->state = SJA1105_TAS_STATE_DISABLED; |
781 | 876 | tas_data->last_op = SJA1105_PTP_NONE; |
| 877 | + |
| 878 | + INIT_LIST_HEAD(&tas_data->gating_cfg.entries); |
782 | 879 | } |
783 | 880 |
|
784 | 881 | void sja1105_tas_teardown(struct dsa_switch *ds) |
|
0 commit comments