for (port = 0; port < ds->num_ports; port++) { conststruct tc_taprio_qopt_offload *offload;
offload = tas_data->offload[port]; if (!offload) continue;
tas_data->enabled = true;
if (max_cycle_time < offload->cycle_time)
max_cycle_time = offload->cycle_time; if (latest_base_time < offload->base_time)
latest_base_time = offload->base_time; if (earliest_base_time > offload->base_time) {
earliest_base_time = offload->base_time;
its_cycle_time = offload->cycle_time;
}
}
if (!list_empty(&gating_cfg->entries)) {
tas_data->enabled = true;
if (max_cycle_time < gating_cfg->cycle_time)
max_cycle_time = gating_cfg->cycle_time; if (latest_base_time < gating_cfg->base_time)
latest_base_time = gating_cfg->base_time; if (earliest_base_time > gating_cfg->base_time) {
earliest_base_time = gating_cfg->base_time;
its_cycle_time = gating_cfg->cycle_time;
}
}
if (!tas_data->enabled) return0;
/* Roll the earliest base time over until it is in a comparable *timebasewiththelatest,thencomparetheirdeltas. *Wewanttoenforcethatallports'basetimesarewithin *SJA1105_TAS_MAX_DELTA200nscyclesofoneanother.
*/
earliest_base_time = future_base_time(earliest_base_time,
its_cycle_time,
latest_base_time); while (earliest_base_time > latest_base_time)
earliest_base_time -= its_cycle_time; if (latest_base_time - earliest_base_time >
sja1105_delta_to_ns(SJA1105_TAS_MAX_DELTA)) {
dev_err(ds->dev, "Base times too far apart: min %llu max %llu\n",
earliest_base_time, latest_base_time); return -ERANGE;
}
dev_dbg(ds->dev, "earliest base time %lld ns\n", earliest_base_time);
dev_dbg(ds->dev, "latest base time %lld ns\n", latest_base_time);
dev_dbg(ds->dev, "longest cycle time %lld ns\n", max_cycle_time);
return0;
}
/* Lo and behold: the egress scheduler from hell. * *Atthehardwarelevel,theTime-AwareShaperholdsagloballineararrrayof *allscheduleentriesforallports.ThesearetheGateControlList(GCL) *entries,let'scallthem"timeslots"forshort.Thislineararrayof *timeslotsisheldinBLK_IDX_SCHEDULE. * *Thenthereareamaximumof8"executionthreads"insidetheswitch,which *iteratecyclicallythroughthe"schedule".Each"cycle"hasanentrypoint *andanexitpoint,bothbeingtimeslotindicesinthescheduletable.The *hardwarecallseachcyclea"subschedule". * *Subschedule(cycle)istartswhen *ptpclkval>=ptpschtm+BLK_IDX_SCHEDULE_ENTRY_POINTS[i].delta. * *ThehardwarescheduleriteratesBLK_IDX_SCHEDULEwithakrangingfrom *k=BLK_IDX_SCHEDULE_ENTRY_POINTS[i].addressto *k=BLK_IDX_SCHEDULE_PARAMS.subscheind[i] * *Foreachscheduleentry(timeslot)k,theengineexecutesthegatecontrol *listentryforthedurationofBLK_IDX_SCHEDULE[k].delta. * *+---------+ *||BLK_IDX_SCHEDULE_ENTRY_POINTS_PARAMS *+---------+ *| *+-----------------+ *|.actsubsch *BLK_IDX_SCHEDULE_ENTRY_POINTSv *+-------+-------+ *|cycle0|cycle1| *+-------+-------+ *|||| *+----------------+||+-------------------------------------+ *|.subschindx||.subschindx| *||+---------------+| *|.address|.address|| *|||| *|||| *|BLK_IDX_SCHEDULEvv| *|+-------+-------+-------+-------+-------+------+| *||entry0|entry1|entry2|entry3|entry4|entry5|| *|+-------+-------+-------+-------+-------+------+| *|^^^^| *|||||| *|+-------------------------+|||| *||+-------------------------------+||| *|||+-------------------+|| *|||||| *|+---------------------------------------------------------------+| *||subscheind[0]<=subscheind[1]<=subscheind[2]<=...<=subscheind[7]|| *|+---------------------------------------------------------------+| *|^^BLK_IDX_SCHEDULE_PARAMS| *|||| *+--------++-------------------------------------------+ * *Intheabovepicturetherearetwosubschedules(cycles): * *-cycle0:iteratesthescheduletablefrom0to2(andback) *-cycle1:iteratesthescheduletablefrom3to5(andback) * *Allotherpossibleexecutionthreadsmustbemarkedasunusedbymaking *their"subscheduleendindex"(subscheind)equaltothelastvalid *subschedule'sendindex(inthiscase5).
*/ int sja1105_init_scheduling(struct sja1105_private *priv)
{ struct sja1105_schedule_entry_points_entry *schedule_entry_points; struct sja1105_schedule_entry_points_params_entry
*schedule_entry_points_params; struct sja1105_schedule_params_entry *schedule_params; struct sja1105_tas_data *tas_data = &priv->tas_data; struct sja1105_gating_config *gating_cfg = &tas_data->gating_cfg; struct sja1105_schedule_entry *schedule; struct dsa_switch *ds = priv->ds; struct sja1105_table *table; int schedule_start_idx;
s64 entry_point_delta; int schedule_end_idx; int num_entries = 0; int num_cycles = 0; int cycle = 0; int i, k = 0; int port, rc;
rc = sja1105_tas_set_runtime_params(priv); if (rc < 0) return rc;
/* Figure out the dimensioning of the problem */ for (port = 0; port < ds->num_ports; port++) { if (tas_data->offload[port]) {
num_entries += tas_data->offload[port]->num_entries;
num_cycles++;
}
}
if (!list_empty(&gating_cfg->entries)) {
num_entries += gating_cfg->num_entries;
num_cycles++;
}
/* Nothing to do */ if (!num_cycles) return0;
/* Pre-allocate space in the static config tables */
for (port = 0; port < ds->num_ports; port++) { conststruct tc_taprio_qopt_offload *offload; /* Relative base time */
s64 rbt;
offload = tas_data->offload[port]; if (!offload) continue;
schedule_start_idx = k;
schedule_end_idx = k + offload->num_entries - 1; /* This is the base time expressed as a number of TAS ticks *relativetoPTPSCHTM,whichwe'll(perhapsimproperly)call *theoperationalbasetime.
*/
rbt = future_base_time(offload->base_time,
offload->cycle_time,
tas_data->earliest_base_time);
rbt -= tas_data->earliest_base_time; /* UM10944.pdf 4.2.2. Schedule Entry Points table says that *deltacannotbezero,whichisshitty.Advanceallrelative *basetimesby1TASdelta,sothateventheearliestbase *timebecomes1inrelativeterms.Thenstarttheoperational *basetime(PTPSCHTM)oneTASdeltaearlierthanplanned.
*/
entry_point_delta = ns_to_sja1105_delta(rbt) + 1;
/* Be there 2 port subschedules, each executing an arbitrary number of gate *open/closeeventscyclically. *Noneofthosegateeventsmusteveroccurattheexactsametime,otherwise *theswitchisknowntoactinexoticallystrangeways. *Howeverthehardwaredoesn'tbotherperformingtheseintegritychecks. *Soherewearewiththetaskofvalidatingwhetherthenew@adminoffload *hasanyconflictwiththealreadyestablishedTASconfigurationin *tas_data->offload.Wealreadyknowtheotherportsareinharmonywithone *another,otherwisewewouldn'thavesavedthem. *Eachgateeventexecutesperiodically,withaperiodof@cycle_timeanda *phasegivenbyitscycle's@base_timeplusitsoffsetwithinthecycle *(whichinturnisgivenbythelengthoftheeventspriortoit). *Therearetwoaspectstopossiblecollisions: *-Collisionswithinonecycle's(actuallythelongestcycle's)timeframe. *Forthat,weneedtocomparethecartesianproductofeachpossible *occurrenceofeacheventwithinonecycletime. *-Collisionsinthefuture.Eventsmaynotcollidewithinonecycletime, *butiftwoportschedulesdon'thavethesameperiodicity(akathecycle *timesaren'tmultiplesofoneanother),theysurelywillsometimeinthe *future(actuallytheywillcollideaninfiniteamountoftimes).
*/ staticbool
sja1105_tas_check_conflicts(struct sja1105_private *priv, int port, conststruct tc_taprio_qopt_offload *admin)
{ struct sja1105_tas_data *tas_data = &priv->tas_data; conststruct tc_taprio_qopt_offload *offload;
s64 max_cycle_time, min_cycle_time;
s64 delta1, delta2;
s64 rbt1, rbt2;
s64 stop_time;
s64 t1, t2; int i, j;
s32 rem;
offload = tas_data->offload[port]; if (!offload) returnfalse;
/* Check if the two cycle times are multiples of one another. *Iftheyaren't,thentheywillsurelycollide.
*/
max_cycle_time = max(offload->cycle_time, admin->cycle_time);
min_cycle_time = min(offload->cycle_time, admin->cycle_time);
div_s64_rem(max_cycle_time, min_cycle_time, &rem); if (rem) returntrue;
/* Calculate the "reduced" base time of each of the two cycles *(transposedbackascloseto0aspossible)bydividingto *thecycletime.
*/
div_s64_rem(offload->base_time, offload->cycle_time, &rem);
rbt1 = rem;
/* delta1 is the relative base time of each GCL entry within *theestablishedports'TASconfig.
*/ for (i = 0, delta1 = 0;
i < offload->num_entries;
delta1 += offload->entries[i].interval, i++) { /* delta2 is the relative base time of each GCL entry *withinthenewlyaddedTASconfig.
*/ for (j = 0, delta2 = 0;
j < admin->num_entries;
delta2 += admin->entries[j].interval, j++) { /* t1 follows all possible occurrences of the *establishedports'GCLentryiwithinthe *firstcycletime.
*/ for (t1 = rbt1 + delta1;
t1 <= stop_time;
t1 += offload->cycle_time) { /* t2 follows all possible occurrences *ofthenewlyaddedGCLentryj *withinthefirstcycletime.
*/ for (t2 = rbt2 + delta2;
t2 <= stop_time;
t2 += admin->cycle_time) { if (t1 == t2) {
dev_warn(priv->ds->dev, "GCL entry %d collides with entry %d of port %d\n",
j, i, port); returntrue;
}
}
}
}
}
returnfalse;
}
/* Check the tc-taprio configuration on @port for conflicts with the tc-gate *globalsubschedule.If@portis-1,checkitagainstallports. *Toreusethesja1105_tas_check_conflictslogicwithoutrefactoringit, *convertthegatingconfigurationtoadummytc-tapriooffloadstructure.
*/ bool sja1105_gating_check_conflicts(struct sja1105_private *priv, int port, struct netlink_ext_ack *extack)
{ struct sja1105_gating_config *gating_cfg = &priv->tas_data.gating_cfg;
size_t num_entries = gating_cfg->num_entries; struct tc_taprio_qopt_offload *dummy; struct dsa_switch *ds = priv->ds; struct sja1105_gate_entry *e; bool conflict; int i = 0;
if (list_empty(&gating_cfg->entries)) returnfalse;
dummy = kzalloc(struct_size(dummy, entries, num_entries), GFP_KERNEL); if (!dummy) {
NL_SET_ERR_MSG_MOD(extack, "Failed to allocate memory"); returntrue;
}
/* The cycle time extension is the amount of time the last cycle from *theoldOPERneedstobeextendedinordertophase-alignwiththe *basetimeoftheADMINwhenthatbecomesthenewOPER. *Butofcourseourswitchneedstoberesettoswitch-overbetween *theADMINandtheOPERconfigs-somuchforaseamlesstransition. *Sodon'taddinsultoverinjuryandjustsaywedon'tsupportcycle *timeextension.
*/ if (admin->cycle_time_extension) return -ENOTSUPP;
for (i = 0; i < admin->num_entries; i++) {
s64 delta_ns = admin->entries[i].interval;
s64 delta_cycles = ns_to_sja1105_delta(delta_ns); bool too_long, too_short;
switch (tas_data->state) { case SJA1105_TAS_STATE_DISABLED: /* Can't do anything at all if clock is still being stepped */ if (tas_data->last_op != SJA1105_PTP_ADJUSTFREQ) break;
rc = sja1105_tas_adjust_drift(priv, tas_data->max_cycle_time); if (rc < 0) break;
rc = __sja1105_ptp_gettimex(ds, &now, NULL); if (rc < 0) break;
/* Plan to start the earliest schedule first. The others *willbestartedinhardware,bywayoftheirrespective *entrypointsdelta. *Tryourbesttoavoidfringecases(raceconditionbetween *ptpschtmandptpstrtsch)bypushingtheoper_base_timeat *leastonesecondinthefuturefromnow.Thisisnotideal, *butthisonlyneedstobuyustimeuntilthe *sja1105_tas_startcommandbelowgetsexecuted.
*/
base_time = future_base_time(tas_data->earliest_base_time,
tas_data->max_cycle_time,
now + 1ull * NSEC_PER_SEC);
base_time -= sja1105_delta_to_ns(1);
rc = sja1105_tas_set_base_time(priv, base_time); if (rc < 0) break;
dev_dbg(ds->dev, "OPER base time %lld.%09ld (now %lld.%09ld)\n",
base_time_ts.tv_sec, base_time_ts.tv_nsec,
now_ts.tv_sec, now_ts.tv_nsec);
break;
case SJA1105_TAS_STATE_ENABLED_NOT_RUNNING: if (tas_data->last_op != SJA1105_PTP_ADJUSTFREQ) { /* Clock was stepped.. bad news for TAS */
sja1105_tas_stop(priv); break;
}
/* Check if TAS has actually started, by comparing the *scheduledstarttimewiththeSJA1105PTPclock
*/
rc = __sja1105_ptp_gettimex(ds, &now, NULL); if (rc < 0) break;
if (now < tas_data->oper_base_time) { /* TAS has not started yet */
diff = ns_to_timespec64(tas_data->oper_base_time - now);
dev_dbg(ds->dev, "time to start: [%lld.%09ld]",
diff.tv_sec, diff.tv_nsec); break;
}
/* Time elapsed, what happened? */
rc = sja1105_tas_check_running(priv); if (rc < 0) break;
if (tas_data->state != SJA1105_TAS_STATE_RUNNING) /* TAS has started */
dev_err(ds->dev, "TAS not started despite time elapsed\n");
break;
case SJA1105_TAS_STATE_RUNNING: /* Clock was stepped.. bad news for TAS */ if (tas_data->last_op != SJA1105_PTP_ADJUSTFREQ) {
sja1105_tas_stop(priv); break;
}
rc = sja1105_tas_check_running(priv); if (rc < 0) break;
if (tas_data->state != SJA1105_TAS_STATE_RUNNING)
dev_err(ds->dev, "TAS surprisingly stopped\n");
break;
default: if (net_ratelimit())
dev_err(ds->dev, "TAS in an invalid state (incorrect use of API)!\n");
}
if (rc && net_ratelimit())
dev_err(ds->dev, "An operation returned %d\n", rc);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.