68
68
/* basic switch operations **************************************************/
69
69
static struct dsa_switch *
70
dsa_switch_setup(struct device *parent, struct dsa_platform_data *pd,
71
struct mii_bus *bus, struct net_device *dev)
70
dsa_switch_setup(struct dsa_switch_tree *dst, int index,
71
struct device *parent, struct mii_bus *bus)
73
struct dsa_chip_data *pd = dst->pd->chip + index;
74
struct dsa_switch_driver *drv;
73
75
struct dsa_switch *ds;
75
struct dsa_switch_driver *drv;
82
83
drv = dsa_switch_probe(bus, pd->sw_addr, &name);
84
printk(KERN_ERR "%s: could not detect attached switch\n",
85
printk(KERN_ERR "%s[%d]: could not detect attached switch\n",
86
dst->master_netdev->name, index);
86
87
return ERR_PTR(-EINVAL);
88
printk(KERN_INFO "%s: detected a %s switch\n", dev->name, name);
89
printk(KERN_INFO "%s[%d]: detected a %s switch\n",
90
dst->master_netdev->name, index, name);
117
117
if (!strcmp(name, "cpu")) {
118
if (ds->cpu_port != -1) {
118
if (dst->cpu_switch != -1) {
119
119
printk(KERN_ERR "multiple cpu ports?!\n");
123
dst->cpu_switch = index;
125
} else if (!strcmp(name, "dsa")) {
126
ds->dsa_port_mask |= 1 << i;
125
ds->valid_port_mask |= 1 << i;
128
ds->phys_port_mask |= 1 << i;
129
if (ds->cpu_port == -1) {
130
printk(KERN_ERR "no cpu port?!\n");
137
* If we use a tagging format that doesn't have an ethertype
138
* field, make sure that all packets from this point on get
139
* sent to the tag format's receive function. (Which will
140
* discard received packets until we set ds->ports[] below.)
134
* If the CPU connects to this switch, set the switch tree
135
* tagging protocol to the preferred tagging format of this
143
dev->dsa_ptr = (void *)ds;
138
if (ds->dst->cpu_switch == index)
139
ds->dst->tag_protocol = drv->tag_protocol;
170
166
* Create network devices for physical switch ports.
173
168
for (i = 0; i < DSA_MAX_PORTS; i++) {
174
169
struct net_device *slave_dev;
176
if (!(ds->valid_port_mask & (1 << i)))
171
if (!(ds->phys_port_mask & (1 << i)))
179
174
slave_dev = dsa_slave_create(ds, parent, i, pd->port_names[i]);
180
175
if (slave_dev == NULL) {
181
printk(KERN_ERR "%s: can't create dsa slave "
182
"device for port %d(%s)\n",
183
dev->name, i, pd->port_names[i]);
176
printk(KERN_ERR "%s[%d]: can't create dsa "
177
"slave device for port %d(%s)\n",
178
dst->master_netdev->name,
179
index, i, pd->port_names[i]);
213
208
bool dsa_uses_dsa_tags(void *dsa_ptr)
215
struct dsa_switch *ds = dsa_ptr;
210
struct dsa_switch_tree *dst = dsa_ptr;
217
return !!(ds->tag_protocol == htons(ETH_P_DSA));
212
return !!(dst->tag_protocol == htons(ETH_P_DSA));
220
215
bool dsa_uses_trailer_tags(void *dsa_ptr)
222
struct dsa_switch *ds = dsa_ptr;
217
struct dsa_switch_tree *dst = dsa_ptr;
224
return !!(ds->tag_protocol == htons(ETH_P_TRAILER));
219
return !!(dst->tag_protocol == htons(ETH_P_TRAILER));
228
223
/* link polling *************************************************************/
229
224
static void dsa_link_poll_work(struct work_struct *ugly)
231
struct dsa_switch *ds;
233
ds = container_of(ugly, struct dsa_switch, link_poll_work);
235
ds->drv->poll_link(ds);
236
mod_timer(&ds->link_poll_timer, round_jiffies(jiffies + HZ));
226
struct dsa_switch_tree *dst;
229
dst = container_of(ugly, struct dsa_switch_tree, link_poll_work);
231
for (i = 0; i < dst->pd->nr_chips; i++) {
232
struct dsa_switch *ds = dst->ds[i];
234
if (ds != NULL && ds->drv->poll_link != NULL)
235
ds->drv->poll_link(ds);
238
mod_timer(&dst->link_poll_timer, round_jiffies(jiffies + HZ));
239
static void dsa_link_poll_timer(unsigned long _ds)
241
static void dsa_link_poll_timer(unsigned long _dst)
241
struct dsa_switch *ds = (void *)_ds;
243
struct dsa_switch_tree *dst = (void *)_dst;
243
schedule_work(&ds->link_poll_work);
245
schedule_work(&dst->link_poll_work);
303
305
static int dsa_version_printed;
304
306
struct dsa_platform_data *pd = pdev->dev.platform_data;
305
307
struct net_device *dev;
307
struct dsa_switch *ds;
308
struct dsa_switch_tree *dst;
309
311
if (!dsa_version_printed++)
310
312
printk(KERN_NOTICE "Distributed Switch Architecture "
311
313
"driver version %s\n", dsa_driver_version);
313
if (pd == NULL || pd->mii_bus == NULL || pd->netdev == NULL)
316
bus = dev_to_mii_bus(pd->mii_bus);
315
if (pd == NULL || pd->netdev == NULL)
320
318
dev = dev_to_net_device(pd->netdev);
329
ds = dsa_switch_setup(&pdev->dev, pd, bus, dev);
327
dst = kzalloc(sizeof(*dst), GFP_KERNEL);
335
if (ds->drv->poll_link != NULL) {
336
INIT_WORK(&ds->link_poll_work, dsa_link_poll_work);
337
init_timer(&ds->link_poll_timer);
338
ds->link_poll_timer.data = (unsigned long)ds;
339
ds->link_poll_timer.function = dsa_link_poll_timer;
340
ds->link_poll_timer.expires = round_jiffies(jiffies + HZ);
341
add_timer(&ds->link_poll_timer);
344
platform_set_drvdata(pdev, ds);
333
platform_set_drvdata(pdev, dst);
336
dst->master_netdev = dev;
337
dst->cpu_switch = -1;
340
for (i = 0; i < pd->nr_chips; i++) {
342
struct dsa_switch *ds;
344
bus = dev_to_mii_bus(pd->chip[i].mii_bus);
346
printk(KERN_ERR "%s[%d]: no mii bus found for "
347
"dsa switch\n", dev->name, i);
351
ds = dsa_switch_setup(dst, i, &pdev->dev, bus);
353
printk(KERN_ERR "%s[%d]: couldn't create dsa switch "
354
"instance (error %ld)\n", dev->name, i,
360
if (ds->drv->poll_link != NULL)
361
dst->link_poll_needed = 1;
365
* If we use a tagging format that doesn't have an ethertype
366
* field, make sure that all packets from this point on get
367
* sent to the tag format's receive function.
370
dev->dsa_ptr = (void *)dst;
372
if (dst->link_poll_needed) {
373
INIT_WORK(&dst->link_poll_work, dsa_link_poll_work);
374
init_timer(&dst->link_poll_timer);
375
dst->link_poll_timer.data = (unsigned long)dst;
376
dst->link_poll_timer.function = dsa_link_poll_timer;
377
dst->link_poll_timer.expires = round_jiffies(jiffies + HZ);
378
add_timer(&dst->link_poll_timer);
349
384
static int dsa_remove(struct platform_device *pdev)
351
struct dsa_switch *ds = platform_get_drvdata(pdev);
386
struct dsa_switch_tree *dst = platform_get_drvdata(pdev);
353
if (ds->drv->poll_link != NULL)
354
del_timer_sync(&ds->link_poll_timer);
389
if (dst->link_poll_needed)
390
del_timer_sync(&dst->link_poll_timer);
356
392
flush_scheduled_work();
358
dsa_switch_destroy(ds);
394
for (i = 0; i < dst->pd->nr_chips; i++) {
395
struct dsa_switch *ds = dst->ds[i];
398
dsa_switch_destroy(ds);