net: stmmac: Support devicetree configs for mcast and ucast filter entries
[cascardo/linux.git] / drivers / net / ethernet / stmicro / stmmac / stmmac_platform.c
index ea7a65b..bb524a9 100644 (file)
@@ -52,6 +52,59 @@ static const struct of_device_id stmmac_dt_ids[] = {
 MODULE_DEVICE_TABLE(of, stmmac_dt_ids);
 
 #ifdef CONFIG_OF
+
+/* This function validates the number of Multicast filtering bins specified
+ * by the configuration through the device tree. The Synopsys GMAC supports
+ * 64 bins, 128 bins, or 256 bins. "bins" refer to the division of CRC
+ * number space. 64 bins correspond to 6 bits of the CRC, 128 corresponds
+ * to 7 bits, and 256 refers to 8 bits of the CRC. Any other setting is
+ * invalid and will cause the filtering algorithm to use Multicast
+ * promiscuous mode.
+ */
+static int dwmac1000_validate_mcast_bins(int mcast_bins)
+{
+       int x = mcast_bins;
+
+       switch (x) {
+       case HASH_TABLE_SIZE:
+       case 128:
+       case 256:
+               break;
+       default:
+               x = 0;
+               pr_info("Hash table entries set to unexpected value %d",
+                       mcast_bins);
+               break;
+       }
+       return x;
+}
+
+/* This function validates the number of Unicast address entries supported
+ * by a particular Synopsys 10/100/1000 controller. The Synopsys controller
+ * supports 1, 32, 64, or 128 Unicast filter entries for it's Unicast filter
+ * logic. This function validates a valid, supported configuration is
+ * selected, and defaults to 1 Unicast address if an unsupported
+ * configuration is selected.
+ */
+static int dwmac1000_validate_ucast_entries(int ucast_entries)
+{
+       int x = ucast_entries;
+
+       switch (x) {
+       case 1:
+       case 32:
+       case 64:
+       case 128:
+               break;
+       default:
+               x = 1;
+               pr_info("Unicast table entries set to unexpected value %d\n",
+                       ucast_entries);
+               break;
+       }
+       return x;
+}
+
 static int stmmac_probe_config_dt(struct platform_device *pdev,
                                  struct plat_stmmacenet_data *plat,
                                  const char **mac)
@@ -115,6 +168,12 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
         */
        plat->maxmtu = JUMBO_LEN;
 
+       /* Set default value for multicast hash bins */
+       plat->multicast_filter_bins = HASH_TABLE_SIZE;
+
+       /* Set default value for unicast filter entries */
+       plat->unicast_filter_entries = 1;
+
        /*
         * Currently only the properties needed on SPEAr600
         * are provided. All other properties should be added
@@ -131,6 +190,14 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
                 * are clearly MTUs
                 */
                of_property_read_u32(np, "max-frame-size", &plat->maxmtu);
+               of_property_read_u32(np, "snps,multicast-filter-bins",
+                                    &plat->multicast_filter_bins);
+               of_property_read_u32(np, "snps,perfect-filter-entries",
+                                    &plat->unicast_filter_entries);
+               plat->unicast_filter_entries = dwmac1000_validate_ucast_entries(
+                                              plat->unicast_filter_entries);
+               plat->multicast_filter_bins = dwmac1000_validate_mcast_bins(
+                                             plat->multicast_filter_bins);
                plat->has_gmac = 1;
                plat->pmt = 1;
        }