net: dsa: sja1105: Add support for the AVB Parameters Table
authorVladimir Oltean <olteanv@gmail.com>
Sat, 8 Jun 2019 12:04:37 +0000 (15:04 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sat, 8 Jun 2019 22:20:40 +0000 (15:20 -0700)
This table is used to program the switch to emit "meta" follow-up
Ethernet frames (which contain partial RX timestamps) after each
link-local frame that was trapped to the CPU port through MAC filtering.
This includes PTP frames.

Signed-off-by: Vladimir Oltean <olteanv@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/sja1105/sja1105_dynamic_config.c
drivers/net/dsa/sja1105/sja1105_main.c
drivers/net/dsa/sja1105/sja1105_static_config.c
drivers/net/dsa/sja1105/sja1105_static_config.h

index 352bb6e89297b90c8f7bd2cc6b61c3e2d33e71a5..56c83b9d52e40d700744ec3e405c713dc7ff3f5d 100644 (file)
@@ -378,6 +378,7 @@ struct sja1105_dynamic_table_ops sja1105et_dyn_ops[BLK_IDX_MAX_DYN] = {
                .addr = 0x38,
        },
        [BLK_IDX_L2_FORWARDING_PARAMS] = {0},
+       [BLK_IDX_AVB_PARAMS] = {0},
        [BLK_IDX_GENERAL_PARAMS] = {
                .entry_packing = sja1105et_general_params_entry_packing,
                .cmd_packing = sja1105et_general_params_cmd_packing,
@@ -441,6 +442,7 @@ struct sja1105_dynamic_table_ops sja1105pqrs_dyn_ops[BLK_IDX_MAX_DYN] = {
                .addr = 0x38,
        },
        [BLK_IDX_L2_FORWARDING_PARAMS] = {0},
+       [BLK_IDX_AVB_PARAMS] = {0},
        [BLK_IDX_GENERAL_PARAMS] = {
                .entry_packing = sja1105et_general_params_entry_packing,
                .cmd_packing = sja1105et_general_params_cmd_packing,
index 121ceccd8107b991d5bdf461fb7b8f4dbca6329a..d129997174bb28f07afb35ef8883542433aa3817 100644 (file)
@@ -508,6 +508,39 @@ static int sja1105_init_l2_policing(struct sja1105_private *priv)
        return 0;
 }
 
+static int sja1105_init_avb_params(struct sja1105_private *priv,
+                                  bool on)
+{
+       struct sja1105_avb_params_entry *avb;
+       struct sja1105_table *table;
+
+       table = &priv->static_config.tables[BLK_IDX_AVB_PARAMS];
+
+       /* Discard previous AVB Parameters Table */
+       if (table->entry_count) {
+               kfree(table->entries);
+               table->entry_count = 0;
+       }
+
+       /* Configure the reception of meta frames only if requested */
+       if (!on)
+               return 0;
+
+       table->entries = kcalloc(SJA1105_MAX_AVB_PARAMS_COUNT,
+                                table->ops->unpacked_entry_size, GFP_KERNEL);
+       if (!table->entries)
+               return -ENOMEM;
+
+       table->entry_count = SJA1105_MAX_AVB_PARAMS_COUNT;
+
+       avb = table->entries;
+
+       avb->destmeta = SJA1105_META_DMAC;
+       avb->srcmeta  = SJA1105_META_SMAC;
+
+       return 0;
+}
+
 static int sja1105_static_config_load(struct sja1105_private *priv,
                                      struct sja1105_dt_port *ports)
 {
@@ -546,6 +579,9 @@ static int sja1105_static_config_load(struct sja1105_private *priv,
        if (rc < 0)
                return rc;
        rc = sja1105_init_general_params(priv);
+       if (rc < 0)
+               return rc;
+       rc = sja1105_init_avb_params(priv, false);
        if (rc < 0)
                return rc;
 
index e2f86b332b09fb7bb42d04cbdc4ecb66e5daf46d..58f273eaf1ea575f4727a0db67570d7dcdc14673 100644 (file)
@@ -94,6 +94,28 @@ u32 sja1105_crc32(const void *buf, size_t len)
        return ~crc;
 }
 
+static size_t sja1105et_avb_params_entry_packing(void *buf, void *entry_ptr,
+                                                enum packing_op op)
+{
+       const size_t size = SJA1105ET_SIZE_AVB_PARAMS_ENTRY;
+       struct sja1105_avb_params_entry *entry = entry_ptr;
+
+       sja1105_packing(buf, &entry->destmeta, 95, 48, size, op);
+       sja1105_packing(buf, &entry->srcmeta,  47,  0, size, op);
+       return size;
+}
+
+static size_t sja1105pqrs_avb_params_entry_packing(void *buf, void *entry_ptr,
+                                                  enum packing_op op)
+{
+       const size_t size = SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY;
+       struct sja1105_avb_params_entry *entry = entry_ptr;
+
+       sja1105_packing(buf, &entry->destmeta,   125,  78, size, op);
+       sja1105_packing(buf, &entry->srcmeta,     77,  30, size, op);
+       return size;
+}
+
 static size_t sja1105et_general_params_entry_packing(void *buf, void *entry_ptr,
                                                     enum packing_op op)
 {
@@ -426,6 +448,7 @@ static u64 blk_id_map[BLK_IDX_MAX] = {
        [BLK_IDX_MAC_CONFIG] = BLKID_MAC_CONFIG,
        [BLK_IDX_L2_LOOKUP_PARAMS] = BLKID_L2_LOOKUP_PARAMS,
        [BLK_IDX_L2_FORWARDING_PARAMS] = BLKID_L2_FORWARDING_PARAMS,
+       [BLK_IDX_AVB_PARAMS] = BLKID_AVB_PARAMS,
        [BLK_IDX_GENERAL_PARAMS] = BLKID_GENERAL_PARAMS,
        [BLK_IDX_XMII_PARAMS] = BLKID_XMII_PARAMS,
 };
@@ -627,6 +650,12 @@ struct sja1105_table_ops sja1105e_table_ops[BLK_IDX_MAX] = {
                .packed_entry_size = SJA1105_SIZE_L2_FORWARDING_PARAMS_ENTRY,
                .max_entry_count = SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT,
        },
+       [BLK_IDX_AVB_PARAMS] = {
+               .packing = sja1105et_avb_params_entry_packing,
+               .unpacked_entry_size = sizeof(struct sja1105_avb_params_entry),
+               .packed_entry_size = SJA1105ET_SIZE_AVB_PARAMS_ENTRY,
+               .max_entry_count = SJA1105_MAX_AVB_PARAMS_COUNT,
+       },
        [BLK_IDX_GENERAL_PARAMS] = {
                .packing = sja1105et_general_params_entry_packing,
                .unpacked_entry_size = sizeof(struct sja1105_general_params_entry),
@@ -685,6 +714,12 @@ struct sja1105_table_ops sja1105t_table_ops[BLK_IDX_MAX] = {
                .packed_entry_size = SJA1105_SIZE_L2_FORWARDING_PARAMS_ENTRY,
                .max_entry_count = SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT,
        },
+       [BLK_IDX_AVB_PARAMS] = {
+               .packing = sja1105et_avb_params_entry_packing,
+               .unpacked_entry_size = sizeof(struct sja1105_avb_params_entry),
+               .packed_entry_size = SJA1105ET_SIZE_AVB_PARAMS_ENTRY,
+               .max_entry_count = SJA1105_MAX_AVB_PARAMS_COUNT,
+       },
        [BLK_IDX_GENERAL_PARAMS] = {
                .packing = sja1105et_general_params_entry_packing,
                .unpacked_entry_size = sizeof(struct sja1105_general_params_entry),
@@ -743,6 +778,12 @@ struct sja1105_table_ops sja1105p_table_ops[BLK_IDX_MAX] = {
                .packed_entry_size = SJA1105_SIZE_L2_FORWARDING_PARAMS_ENTRY,
                .max_entry_count = SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT,
        },
+       [BLK_IDX_AVB_PARAMS] = {
+               .packing = sja1105pqrs_avb_params_entry_packing,
+               .unpacked_entry_size = sizeof(struct sja1105_avb_params_entry),
+               .packed_entry_size = SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY,
+               .max_entry_count = SJA1105_MAX_AVB_PARAMS_COUNT,
+       },
        [BLK_IDX_GENERAL_PARAMS] = {
                .packing = sja1105pqrs_general_params_entry_packing,
                .unpacked_entry_size = sizeof(struct sja1105_general_params_entry),
@@ -801,6 +842,12 @@ struct sja1105_table_ops sja1105q_table_ops[BLK_IDX_MAX] = {
                .packed_entry_size = SJA1105_SIZE_L2_FORWARDING_PARAMS_ENTRY,
                .max_entry_count = SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT,
        },
+       [BLK_IDX_AVB_PARAMS] = {
+               .packing = sja1105pqrs_avb_params_entry_packing,
+               .unpacked_entry_size = sizeof(struct sja1105_avb_params_entry),
+               .packed_entry_size = SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY,
+               .max_entry_count = SJA1105_MAX_AVB_PARAMS_COUNT,
+       },
        [BLK_IDX_GENERAL_PARAMS] = {
                .packing = sja1105pqrs_general_params_entry_packing,
                .unpacked_entry_size = sizeof(struct sja1105_general_params_entry),
@@ -859,6 +906,12 @@ struct sja1105_table_ops sja1105r_table_ops[BLK_IDX_MAX] = {
                .packed_entry_size = SJA1105_SIZE_L2_FORWARDING_PARAMS_ENTRY,
                .max_entry_count = SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT,
        },
+       [BLK_IDX_AVB_PARAMS] = {
+               .packing = sja1105pqrs_avb_params_entry_packing,
+               .unpacked_entry_size = sizeof(struct sja1105_avb_params_entry),
+               .packed_entry_size = SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY,
+               .max_entry_count = SJA1105_MAX_AVB_PARAMS_COUNT,
+       },
        [BLK_IDX_GENERAL_PARAMS] = {
                .packing = sja1105pqrs_general_params_entry_packing,
                .unpacked_entry_size = sizeof(struct sja1105_general_params_entry),
@@ -917,6 +970,12 @@ struct sja1105_table_ops sja1105s_table_ops[BLK_IDX_MAX] = {
                .packed_entry_size = SJA1105_SIZE_L2_FORWARDING_PARAMS_ENTRY,
                .max_entry_count = SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT,
        },
+       [BLK_IDX_AVB_PARAMS] = {
+               .packing = sja1105pqrs_avb_params_entry_packing,
+               .unpacked_entry_size = sizeof(struct sja1105_avb_params_entry),
+               .packed_entry_size = SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY,
+               .max_entry_count = SJA1105_MAX_AVB_PARAMS_COUNT,
+       },
        [BLK_IDX_GENERAL_PARAMS] = {
                .packing = sja1105pqrs_general_params_entry_packing,
                .unpacked_entry_size = sizeof(struct sja1105_general_params_entry),
index d513b1c91b9850341d62c8c0ffc8f78d52c2253a..a9586d0b4b3bef4e469d052fefbfc897dd61b598 100644 (file)
 #define SJA1105ET_SIZE_MAC_CONFIG_ENTRY                        28
 #define SJA1105ET_SIZE_L2_LOOKUP_PARAMS_ENTRY          4
 #define SJA1105ET_SIZE_GENERAL_PARAMS_ENTRY            40
+#define SJA1105ET_SIZE_AVB_PARAMS_ENTRY                        12
 #define SJA1105PQRS_SIZE_L2_LOOKUP_ENTRY               20
 #define SJA1105PQRS_SIZE_MAC_CONFIG_ENTRY              32
 #define SJA1105PQRS_SIZE_L2_LOOKUP_PARAMS_ENTRY                16
 #define SJA1105PQRS_SIZE_GENERAL_PARAMS_ENTRY          44
+#define SJA1105PQRS_SIZE_AVB_PARAMS_ENTRY              16
 
 /* UM10944.pdf Page 11, Table 2. Configuration Blocks */
 enum {
@@ -34,6 +36,7 @@ enum {
        BLKID_MAC_CONFIG                                = 0x09,
        BLKID_L2_LOOKUP_PARAMS                          = 0x0D,
        BLKID_L2_FORWARDING_PARAMS                      = 0x0E,
+       BLKID_AVB_PARAMS                                = 0x10,
        BLKID_GENERAL_PARAMS                            = 0x11,
        BLKID_XMII_PARAMS                               = 0x4E,
 };
@@ -46,6 +49,7 @@ enum sja1105_blk_idx {
        BLK_IDX_MAC_CONFIG,
        BLK_IDX_L2_LOOKUP_PARAMS,
        BLK_IDX_L2_FORWARDING_PARAMS,
+       BLK_IDX_AVB_PARAMS,
        BLK_IDX_GENERAL_PARAMS,
        BLK_IDX_XMII_PARAMS,
        BLK_IDX_MAX,
@@ -64,6 +68,7 @@ enum sja1105_blk_idx {
 #define SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT         1
 #define SJA1105_MAX_GENERAL_PARAMS_COUNT               1
 #define SJA1105_MAX_XMII_PARAMS_COUNT                  1
+#define SJA1105_MAX_AVB_PARAMS_COUNT                   1
 
 #define SJA1105_MAX_FRAME_MEMORY                       929
 
@@ -179,6 +184,11 @@ struct sja1105_l2_policing_entry {
        u64 partition;
 };
 
+struct sja1105_avb_params_entry {
+       u64 destmeta;
+       u64 srcmeta;
+};
+
 struct sja1105_mac_config_entry {
        u64 top[8];
        u64 base[8];