Merge branch 'Felix-DSA-probing-cleanup'
Vladimir Oltean says: ==================== Probing cleanup for the Felix DSA driver This is a follow-up to Russell King's request for code consolidation among felix_vsc9959, seville_vsc9953 and ocelot_ext, stated here: https://lore.kernel.org/all/Zh1GvcOTXqb7CpQt@shell.armlinux.org.uk/ Details are in individual patches. Testing was done on NXP LS1028A (felix_vsc9959). ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
@@ -1597,6 +1597,15 @@ static int felix_setup(struct dsa_switch *ds)
|
||||
felix_port_qos_map_init(ocelot, dp->index);
|
||||
}
|
||||
|
||||
if (felix->info->request_irq) {
|
||||
err = felix->info->request_irq(ocelot);
|
||||
if (err) {
|
||||
dev_err(ocelot->dev, "Failed to request IRQ: %pe\n",
|
||||
ERR_PTR(err));
|
||||
goto out_deinit_ports;
|
||||
}
|
||||
}
|
||||
|
||||
err = ocelot_devlink_sb_register(ocelot);
|
||||
if (err)
|
||||
goto out_deinit_ports;
|
||||
@@ -2097,15 +2106,14 @@ static void felix_get_mm_stats(struct dsa_switch *ds, int port,
|
||||
ocelot_port_get_mm_stats(ocelot, port, stats);
|
||||
}
|
||||
|
||||
const struct phylink_mac_ops felix_phylink_mac_ops = {
|
||||
static const struct phylink_mac_ops felix_phylink_mac_ops = {
|
||||
.mac_select_pcs = felix_phylink_mac_select_pcs,
|
||||
.mac_config = felix_phylink_mac_config,
|
||||
.mac_link_down = felix_phylink_mac_link_down,
|
||||
.mac_link_up = felix_phylink_mac_link_up,
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(felix_phylink_mac_ops);
|
||||
|
||||
const struct dsa_switch_ops felix_switch_ops = {
|
||||
static const struct dsa_switch_ops felix_switch_ops = {
|
||||
.get_tag_protocol = felix_get_tag_protocol,
|
||||
.change_tag_protocol = felix_change_tag_protocol,
|
||||
.connect_tag_protocol = felix_connect_tag_protocol,
|
||||
@@ -2184,7 +2192,53 @@ const struct dsa_switch_ops felix_switch_ops = {
|
||||
.port_set_host_flood = felix_port_set_host_flood,
|
||||
.port_change_conduit = felix_port_change_conduit,
|
||||
};
|
||||
EXPORT_SYMBOL_GPL(felix_switch_ops);
|
||||
|
||||
int felix_register_switch(struct device *dev, resource_size_t switch_base,
|
||||
int num_flooding_pgids, bool ptp,
|
||||
bool mm_supported,
|
||||
enum dsa_tag_protocol init_tag_proto,
|
||||
const struct felix_info *info)
|
||||
{
|
||||
struct dsa_switch *ds;
|
||||
struct ocelot *ocelot;
|
||||
struct felix *felix;
|
||||
int err;
|
||||
|
||||
felix = devm_kzalloc(dev, sizeof(*felix), GFP_KERNEL);
|
||||
if (!felix)
|
||||
return -ENOMEM;
|
||||
|
||||
ds = devm_kzalloc(dev, sizeof(*ds), GFP_KERNEL);
|
||||
if (!ds)
|
||||
return -ENOMEM;
|
||||
|
||||
dev_set_drvdata(dev, felix);
|
||||
|
||||
ocelot = &felix->ocelot;
|
||||
ocelot->dev = dev;
|
||||
ocelot->num_flooding_pgids = num_flooding_pgids;
|
||||
ocelot->ptp = ptp;
|
||||
ocelot->mm_supported = mm_supported;
|
||||
|
||||
felix->info = info;
|
||||
felix->switch_base = switch_base;
|
||||
felix->ds = ds;
|
||||
felix->tag_proto = init_tag_proto;
|
||||
|
||||
ds->dev = dev;
|
||||
ds->num_ports = info->num_ports;
|
||||
ds->num_tx_queues = OCELOT_NUM_TC;
|
||||
ds->ops = &felix_switch_ops;
|
||||
ds->phylink_mac_ops = &felix_phylink_mac_ops;
|
||||
ds->priv = ocelot;
|
||||
|
||||
err = dsa_register_switch(ds);
|
||||
if (err)
|
||||
dev_err_probe(dev, err, "Failed to register DSA switch\n");
|
||||
|
||||
return err;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(felix_register_switch);
|
||||
|
||||
struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,6 @@ struct felix_info {
|
||||
const u32 *port_modes;
|
||||
int num_mact_rows;
|
||||
int num_ports;
|
||||
int num_tx_queues;
|
||||
struct vcap_props *vcap;
|
||||
u16 vcap_pol_base;
|
||||
u16 vcap_pol_max;
|
||||
@@ -64,6 +63,7 @@ struct felix_info {
|
||||
const struct phylink_link_state *state);
|
||||
int (*configure_serdes)(struct ocelot *ocelot, int port,
|
||||
struct device_node *portnp);
|
||||
int (*request_irq)(struct ocelot *ocelot);
|
||||
};
|
||||
|
||||
/* Methods for initializing the hardware resources specific to a tagging
|
||||
@@ -82,9 +82,6 @@ struct felix_tag_proto_ops {
|
||||
struct netlink_ext_ack *extack);
|
||||
};
|
||||
|
||||
extern const struct phylink_mac_ops felix_phylink_mac_ops;
|
||||
extern const struct dsa_switch_ops felix_switch_ops;
|
||||
|
||||
/* DSA glue / front-end for struct ocelot */
|
||||
struct felix {
|
||||
struct dsa_switch *ds;
|
||||
@@ -100,6 +97,11 @@ struct felix {
|
||||
unsigned long host_flood_mc_mask;
|
||||
};
|
||||
|
||||
int felix_register_switch(struct device *dev, resource_size_t switch_base,
|
||||
int num_flooding_pgids, bool ptp,
|
||||
bool mm_supported,
|
||||
enum dsa_tag_protocol init_tag_proto,
|
||||
const struct felix_info *info);
|
||||
struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port);
|
||||
int felix_netdev_to_port(struct net_device *dev);
|
||||
|
||||
|
||||
@@ -2605,6 +2605,28 @@ set:
|
||||
}
|
||||
}
|
||||
|
||||
/* The INTB interrupt is shared between for PTP TX timestamp availability
|
||||
* notification and MAC Merge status change on each port.
|
||||
*/
|
||||
static irqreturn_t vsc9959_irq_handler(int irq, void *data)
|
||||
{
|
||||
struct ocelot *ocelot = data;
|
||||
|
||||
ocelot_get_txtstamp(ocelot);
|
||||
ocelot_mm_irq(ocelot);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int vsc9959_request_irq(struct ocelot *ocelot)
|
||||
{
|
||||
struct pci_dev *pdev = to_pci_dev(ocelot->dev);
|
||||
|
||||
return devm_request_threaded_irq(ocelot->dev, pdev->irq, NULL,
|
||||
&vsc9959_irq_handler, IRQF_ONESHOT,
|
||||
"felix-intb", ocelot);
|
||||
}
|
||||
|
||||
static const struct ocelot_ops vsc9959_ops = {
|
||||
.reset = vsc9959_reset,
|
||||
.wm_enc = vsc9959_wm_enc,
|
||||
@@ -2636,7 +2658,6 @@ static const struct felix_info felix_info_vsc9959 = {
|
||||
.vcap_pol_max2 = 0,
|
||||
.num_mact_rows = 2048,
|
||||
.num_ports = VSC9959_NUM_PORTS,
|
||||
.num_tx_queues = OCELOT_NUM_TC,
|
||||
.quirks = FELIX_MAC_QUIRKS,
|
||||
.quirk_no_xtr_irq = true,
|
||||
.ptp_caps = &vsc9959_ptp_caps,
|
||||
@@ -2645,99 +2666,36 @@ static const struct felix_info felix_info_vsc9959 = {
|
||||
.port_modes = vsc9959_port_modes,
|
||||
.port_setup_tc = vsc9959_port_setup_tc,
|
||||
.port_sched_speed_set = vsc9959_sched_speed_set,
|
||||
.request_irq = vsc9959_request_irq,
|
||||
};
|
||||
|
||||
/* The INTB interrupt is shared between for PTP TX timestamp availability
|
||||
* notification and MAC Merge status change on each port.
|
||||
*/
|
||||
static irqreturn_t felix_irq_handler(int irq, void *data)
|
||||
{
|
||||
struct ocelot *ocelot = (struct ocelot *)data;
|
||||
|
||||
ocelot_get_txtstamp(ocelot);
|
||||
ocelot_mm_irq(ocelot);
|
||||
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
static int felix_pci_probe(struct pci_dev *pdev,
|
||||
const struct pci_device_id *id)
|
||||
{
|
||||
struct dsa_switch *ds;
|
||||
struct ocelot *ocelot;
|
||||
struct felix *felix;
|
||||
struct device *dev = &pdev->dev;
|
||||
resource_size_t switch_base;
|
||||
int err;
|
||||
|
||||
if (pdev->dev.of_node && !of_device_is_available(pdev->dev.of_node)) {
|
||||
dev_info(&pdev->dev, "device is disabled, skipping\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
err = pci_enable_device(pdev);
|
||||
if (err) {
|
||||
dev_err(&pdev->dev, "device enable failed\n");
|
||||
goto err_pci_enable;
|
||||
dev_err(dev, "device enable failed: %pe\n", ERR_PTR(err));
|
||||
return err;
|
||||
}
|
||||
|
||||
felix = kzalloc(sizeof(struct felix), GFP_KERNEL);
|
||||
if (!felix) {
|
||||
err = -ENOMEM;
|
||||
dev_err(&pdev->dev, "Failed to allocate driver memory\n");
|
||||
goto err_alloc_felix;
|
||||
}
|
||||
|
||||
pci_set_drvdata(pdev, felix);
|
||||
ocelot = &felix->ocelot;
|
||||
ocelot->dev = &pdev->dev;
|
||||
ocelot->num_flooding_pgids = OCELOT_NUM_TC;
|
||||
felix->info = &felix_info_vsc9959;
|
||||
felix->switch_base = pci_resource_start(pdev, VSC9959_SWITCH_PCI_BAR);
|
||||
|
||||
pci_set_master(pdev);
|
||||
|
||||
err = devm_request_threaded_irq(&pdev->dev, pdev->irq, NULL,
|
||||
&felix_irq_handler, IRQF_ONESHOT,
|
||||
"felix-intb", ocelot);
|
||||
if (err) {
|
||||
dev_err(&pdev->dev, "Failed to request irq\n");
|
||||
goto err_alloc_irq;
|
||||
}
|
||||
switch_base = pci_resource_start(pdev, VSC9959_SWITCH_PCI_BAR);
|
||||
|
||||
ocelot->ptp = 1;
|
||||
ocelot->mm_supported = true;
|
||||
|
||||
ds = kzalloc(sizeof(struct dsa_switch), GFP_KERNEL);
|
||||
if (!ds) {
|
||||
err = -ENOMEM;
|
||||
dev_err(&pdev->dev, "Failed to allocate DSA switch\n");
|
||||
goto err_alloc_ds;
|
||||
}
|
||||
|
||||
ds->dev = &pdev->dev;
|
||||
ds->num_ports = felix->info->num_ports;
|
||||
ds->num_tx_queues = felix->info->num_tx_queues;
|
||||
ds->ops = &felix_switch_ops;
|
||||
ds->phylink_mac_ops = &felix_phylink_mac_ops;
|
||||
ds->priv = ocelot;
|
||||
felix->ds = ds;
|
||||
felix->tag_proto = DSA_TAG_PROTO_OCELOT;
|
||||
|
||||
err = dsa_register_switch(ds);
|
||||
if (err) {
|
||||
dev_err_probe(&pdev->dev, err, "Failed to register DSA switch\n");
|
||||
goto err_register_ds;
|
||||
}
|
||||
err = felix_register_switch(dev, switch_base, OCELOT_NUM_TC,
|
||||
true, true, DSA_TAG_PROTO_OCELOT,
|
||||
&felix_info_vsc9959);
|
||||
if (err)
|
||||
goto out_disable;
|
||||
|
||||
return 0;
|
||||
|
||||
err_register_ds:
|
||||
kfree(ds);
|
||||
err_alloc_ds:
|
||||
err_alloc_irq:
|
||||
kfree(felix);
|
||||
err_alloc_felix:
|
||||
out_disable:
|
||||
pci_disable_device(pdev);
|
||||
err_pci_enable:
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -2750,9 +2708,6 @@ static void felix_pci_remove(struct pci_dev *pdev)
|
||||
|
||||
dsa_unregister_switch(felix->ds);
|
||||
|
||||
kfree(felix->ds);
|
||||
kfree(felix);
|
||||
|
||||
pci_disable_device(pdev);
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,6 @@ static const struct felix_info vsc7512_info = {
|
||||
.vcap = vsc7514_vcap_props,
|
||||
.num_mact_rows = 1024,
|
||||
.num_ports = VSC7514_NUM_PORTS,
|
||||
.num_tx_queues = OCELOT_NUM_TC,
|
||||
.port_modes = vsc7512_port_modes,
|
||||
.phylink_mac_config = ocelot_phylink_mac_config,
|
||||
.configure_serdes = ocelot_port_configure_serdes,
|
||||
@@ -65,55 +64,8 @@ static const struct felix_info vsc7512_info = {
|
||||
|
||||
static int ocelot_ext_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct device *dev = &pdev->dev;
|
||||
struct dsa_switch *ds;
|
||||
struct ocelot *ocelot;
|
||||
struct felix *felix;
|
||||
int err;
|
||||
|
||||
felix = kzalloc(sizeof(*felix), GFP_KERNEL);
|
||||
if (!felix)
|
||||
return -ENOMEM;
|
||||
|
||||
dev_set_drvdata(dev, felix);
|
||||
|
||||
ocelot = &felix->ocelot;
|
||||
ocelot->dev = dev;
|
||||
|
||||
ocelot->num_flooding_pgids = 1;
|
||||
|
||||
felix->info = &vsc7512_info;
|
||||
|
||||
ds = kzalloc(sizeof(*ds), GFP_KERNEL);
|
||||
if (!ds) {
|
||||
err = -ENOMEM;
|
||||
dev_err_probe(dev, err, "Failed to allocate DSA switch\n");
|
||||
goto err_free_felix;
|
||||
}
|
||||
|
||||
ds->dev = dev;
|
||||
ds->num_ports = felix->info->num_ports;
|
||||
ds->num_tx_queues = felix->info->num_tx_queues;
|
||||
|
||||
ds->ops = &felix_switch_ops;
|
||||
ds->phylink_mac_ops = &felix_phylink_mac_ops;
|
||||
ds->priv = ocelot;
|
||||
felix->ds = ds;
|
||||
felix->tag_proto = DSA_TAG_PROTO_OCELOT;
|
||||
|
||||
err = dsa_register_switch(ds);
|
||||
if (err) {
|
||||
dev_err_probe(dev, err, "Failed to register DSA switch\n");
|
||||
goto err_free_ds;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err_free_ds:
|
||||
kfree(ds);
|
||||
err_free_felix:
|
||||
kfree(felix);
|
||||
return err;
|
||||
return felix_register_switch(&pdev->dev, 0, 1, false, false,
|
||||
DSA_TAG_PROTO_OCELOT, &vsc7512_info);
|
||||
}
|
||||
|
||||
static void ocelot_ext_remove(struct platform_device *pdev)
|
||||
@@ -124,9 +76,6 @@ static void ocelot_ext_remove(struct platform_device *pdev)
|
||||
return;
|
||||
|
||||
dsa_unregister_switch(felix->ds);
|
||||
|
||||
kfree(felix->ds);
|
||||
kfree(felix);
|
||||
}
|
||||
|
||||
static void ocelot_ext_shutdown(struct platform_device *pdev)
|
||||
|
||||
@@ -963,7 +963,6 @@ static const struct felix_info seville_info_vsc9953 = {
|
||||
.quirks = FELIX_MAC_QUIRKS,
|
||||
.num_mact_rows = 2048,
|
||||
.num_ports = VSC9953_NUM_PORTS,
|
||||
.num_tx_queues = OCELOT_NUM_TC,
|
||||
.mdio_bus_alloc = vsc9953_mdio_bus_alloc,
|
||||
.mdio_bus_free = vsc9953_mdio_bus_free,
|
||||
.port_modes = vsc9953_port_modes,
|
||||
@@ -971,63 +970,18 @@ static const struct felix_info seville_info_vsc9953 = {
|
||||
|
||||
static int seville_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct dsa_switch *ds;
|
||||
struct ocelot *ocelot;
|
||||
struct device *dev = &pdev->dev;
|
||||
struct resource *res;
|
||||
struct felix *felix;
|
||||
int err;
|
||||
|
||||
felix = kzalloc(sizeof(struct felix), GFP_KERNEL);
|
||||
if (!felix) {
|
||||
err = -ENOMEM;
|
||||
dev_err(&pdev->dev, "Failed to allocate driver memory\n");
|
||||
goto err_alloc_felix;
|
||||
}
|
||||
|
||||
platform_set_drvdata(pdev, felix);
|
||||
|
||||
ocelot = &felix->ocelot;
|
||||
ocelot->dev = &pdev->dev;
|
||||
ocelot->num_flooding_pgids = 1;
|
||||
felix->info = &seville_info_vsc9953;
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
||||
if (!res) {
|
||||
err = -EINVAL;
|
||||
dev_err(&pdev->dev, "Invalid resource\n");
|
||||
goto err_alloc_felix;
|
||||
}
|
||||
felix->switch_base = res->start;
|
||||
|
||||
ds = kzalloc(sizeof(struct dsa_switch), GFP_KERNEL);
|
||||
if (!ds) {
|
||||
err = -ENOMEM;
|
||||
dev_err(&pdev->dev, "Failed to allocate DSA switch\n");
|
||||
goto err_alloc_ds;
|
||||
dev_err(dev, "Invalid resource\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ds->dev = &pdev->dev;
|
||||
ds->num_ports = felix->info->num_ports;
|
||||
ds->ops = &felix_switch_ops;
|
||||
ds->phylink_mac_ops = &felix_phylink_mac_ops;
|
||||
ds->priv = ocelot;
|
||||
felix->ds = ds;
|
||||
felix->tag_proto = DSA_TAG_PROTO_SEVILLE;
|
||||
|
||||
err = dsa_register_switch(ds);
|
||||
if (err) {
|
||||
dev_err(&pdev->dev, "Failed to register DSA switch: %d\n", err);
|
||||
goto err_register_ds;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err_register_ds:
|
||||
kfree(ds);
|
||||
err_alloc_ds:
|
||||
err_alloc_felix:
|
||||
kfree(felix);
|
||||
return err;
|
||||
return felix_register_switch(dev, res->start, 1, false, false,
|
||||
DSA_TAG_PROTO_SEVILLE,
|
||||
&seville_info_vsc9953);
|
||||
}
|
||||
|
||||
static void seville_remove(struct platform_device *pdev)
|
||||
@@ -1038,9 +992,6 @@ static void seville_remove(struct platform_device *pdev)
|
||||
return;
|
||||
|
||||
dsa_unregister_switch(felix->ds);
|
||||
|
||||
kfree(felix->ds);
|
||||
kfree(felix);
|
||||
}
|
||||
|
||||
static void seville_shutdown(struct platform_device *pdev)
|
||||
|
||||
Reference in New Issue
Block a user