Skip to content

Commit 4ed2d8f

Browse files
manabiandavem330
authored andcommitted
stmmac: clean up platform/of_match data retrieval
Refactor code to clearly separate probing non-dt versus dt. In the non-dt case platform data must be supplied to probe successfully. For dt the platform data structure is created and match data is copied into it. Note that support for supplying platform data in dt from AUXDATA is dropped as no users in mainline does this. This change will allow dt dwmac-* drivers to call the config_dt() function from probe to create the needed platform data struct and retrieve common dt properties. Signed-off-by: Joachim Eastwood <manabian@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0dacf3f commit 4ed2d8f

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,20 @@ static int dwmac1000_validate_ucast_entries(int ucast_entries)
105105
* set some private fields that will be used by the main at runtime.
106106
*/
107107
static int stmmac_probe_config_dt(struct platform_device *pdev,
108-
struct plat_stmmacenet_data *plat,
108+
struct plat_stmmacenet_data **plat_dat,
109109
const char **mac)
110110
{
111111
struct device_node *np = pdev->dev.of_node;
112+
struct plat_stmmacenet_data *plat;
112113
const struct stmmac_of_data *data;
113114
struct stmmac_dma_cfg *dma_cfg;
114115

116+
plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
117+
if (!plat)
118+
return -ENOMEM;
119+
120+
*plat_dat = plat;
121+
115122
data = of_device_get_match_data(&pdev->dev);
116123
if (data) {
117124
plat->has_gmac = data->has_gmac;
@@ -180,6 +187,12 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
180187
*/
181188
plat->maxmtu = JUMBO_LEN;
182189

190+
/* Set default value for multicast hash bins */
191+
plat->multicast_filter_bins = HASH_TABLE_SIZE;
192+
193+
/* Set default value for unicast filter entries */
194+
plat->unicast_filter_entries = 1;
195+
183196
/*
184197
* Currently only the properties needed on SPEAr600
185198
* are provided. All other properties should be added
@@ -242,7 +255,7 @@ static int stmmac_probe_config_dt(struct platform_device *pdev,
242255
}
243256
#else
244257
static int stmmac_probe_config_dt(struct platform_device *pdev,
245-
struct plat_stmmacenet_data *plat,
258+
struct plat_stmmacenet_data **plat,
246259
const char **mac)
247260
{
248261
return -ENOSYS;
@@ -301,29 +314,24 @@ int stmmac_pltfr_probe(struct platform_device *pdev)
301314
if (IS_ERR(stmmac_res.addr))
302315
return PTR_ERR(stmmac_res.addr);
303316

304-
plat_dat = dev_get_platdata(&pdev->dev);
305-
306-
if (!plat_dat)
307-
plat_dat = devm_kzalloc(&pdev->dev,
308-
sizeof(struct plat_stmmacenet_data),
309-
GFP_KERNEL);
310-
if (!plat_dat) {
311-
pr_err("%s: ERROR: no memory", __func__);
312-
return -ENOMEM;
313-
}
314-
315-
/* Set default value for multicast hash bins */
316-
plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
317-
318-
/* Set default value for unicast filter entries */
319-
plat_dat->unicast_filter_entries = 1;
320-
321317
if (pdev->dev.of_node) {
322-
ret = stmmac_probe_config_dt(pdev, plat_dat, &stmmac_res.mac);
318+
ret = stmmac_probe_config_dt(pdev, &plat_dat, &stmmac_res.mac);
323319
if (ret) {
324-
pr_err("%s: main dt probe failed", __func__);
320+
dev_err(&pdev->dev, "dt configuration failed\n");
325321
return ret;
326322
}
323+
} else {
324+
plat_dat = dev_get_platdata(&pdev->dev);
325+
if (!plat_dat) {
326+
dev_err(&pdev->dev, "no platform data provided\n");
327+
return -EINVAL;
328+
}
329+
330+
/* Set default value for multicast hash bins */
331+
plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
332+
333+
/* Set default value for unicast filter entries */
334+
plat_dat->unicast_filter_entries = 1;
327335
}
328336

329337
/* Custom setup (if needed) */

0 commit comments

Comments
 (0)