Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * net/dsa/dsa_priv.h - Hardware switch handling |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 3 | * Copyright (c) 2008-2009 Marvell Semiconductor |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | */ |
| 10 | |
| 11 | #ifndef __DSA_PRIV_H |
| 12 | #define __DSA_PRIV_H |
| 13 | |
| 14 | #include <linux/list.h> |
| 15 | #include <linux/phy.h> |
| 16 | #include <linux/timer.h> |
| 17 | #include <linux/workqueue.h> |
| 18 | #include <net/dsa.h> |
| 19 | |
| 20 | struct dsa_switch { |
| 21 | /* |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 22 | * Parent switch tree, and switch index. |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 23 | */ |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 24 | struct dsa_switch_tree *dst; |
| 25 | int index; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 26 | |
| 27 | /* |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 28 | * Configuration data for this switch. |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 29 | */ |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 30 | struct dsa_chip_data *pd; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 31 | |
| 32 | /* |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 33 | * The used switch driver. |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 34 | */ |
| 35 | struct dsa_switch_driver *drv; |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 36 | |
| 37 | /* |
| 38 | * Reference to mii bus to use. |
| 39 | */ |
| 40 | struct mii_bus *master_mii_bus; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * Slave mii_bus and devices for the individual ports. |
| 44 | */ |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 45 | u32 dsa_port_mask; |
| 46 | u32 phys_port_mask; |
| 47 | struct mii_bus *slave_mii_bus; |
| 48 | struct net_device *ports[DSA_MAX_PORTS]; |
| 49 | }; |
| 50 | |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 51 | static inline bool dsa_is_cpu_port(struct dsa_switch *ds, int p) |
| 52 | { |
| 53 | return !!(ds->index == ds->dst->cpu_switch && p == ds->dst->cpu_port); |
| 54 | } |
| 55 | |
| 56 | static inline u8 dsa_upstream_port(struct dsa_switch *ds) |
| 57 | { |
| 58 | struct dsa_switch_tree *dst = ds->dst; |
| 59 | |
| 60 | /* |
| 61 | * If this is the root switch (i.e. the switch that connects |
| 62 | * to the CPU), return the cpu port number on this switch. |
| 63 | * Else return the (DSA) port number that connects to the |
| 64 | * switch that is one hop closer to the cpu. |
| 65 | */ |
| 66 | if (dst->cpu_switch == ds->index) |
| 67 | return dst->cpu_port; |
| 68 | else |
| 69 | return ds->pd->rtable[dst->cpu_switch]; |
| 70 | } |
| 71 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 72 | struct dsa_slave_priv { |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 73 | /* |
| 74 | * The linux network interface corresponding to this |
| 75 | * switch port. |
| 76 | */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 77 | struct net_device *dev; |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Which switch this port is a part of, and the port index |
| 81 | * for this port. |
| 82 | */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 83 | struct dsa_switch *parent; |
Lennert Buytenhek | e84665c | 2009-03-20 09:52:09 +0000 | [diff] [blame] | 84 | u8 port; |
| 85 | |
| 86 | /* |
| 87 | * The phylib phy_device pointer for the PHY connected |
| 88 | * to this port. |
| 89 | */ |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 90 | struct phy_device *phy; |
| 91 | }; |
| 92 | |
| 93 | struct dsa_switch_driver { |
| 94 | struct list_head list; |
| 95 | |
| 96 | __be16 tag_protocol; |
| 97 | int priv_size; |
| 98 | |
| 99 | /* |
| 100 | * Probing and setup. |
| 101 | */ |
| 102 | char *(*probe)(struct mii_bus *bus, int sw_addr); |
| 103 | int (*setup)(struct dsa_switch *ds); |
| 104 | int (*set_addr)(struct dsa_switch *ds, u8 *addr); |
| 105 | |
| 106 | /* |
| 107 | * Access to the switch's PHY registers. |
| 108 | */ |
| 109 | int (*phy_read)(struct dsa_switch *ds, int port, int regnum); |
| 110 | int (*phy_write)(struct dsa_switch *ds, int port, |
| 111 | int regnum, u16 val); |
| 112 | |
| 113 | /* |
| 114 | * Link state polling and IRQ handling. |
| 115 | */ |
| 116 | void (*poll_link)(struct dsa_switch *ds); |
| 117 | |
| 118 | /* |
| 119 | * ethtool hardware statistics. |
| 120 | */ |
| 121 | void (*get_strings)(struct dsa_switch *ds, int port, uint8_t *data); |
| 122 | void (*get_ethtool_stats)(struct dsa_switch *ds, |
| 123 | int port, uint64_t *data); |
| 124 | int (*get_sset_count)(struct dsa_switch *ds); |
| 125 | }; |
| 126 | |
| 127 | /* dsa.c */ |
| 128 | extern char dsa_driver_version[]; |
| 129 | void register_switch_driver(struct dsa_switch_driver *type); |
| 130 | void unregister_switch_driver(struct dsa_switch_driver *type); |
| 131 | |
| 132 | /* slave.c */ |
| 133 | void dsa_slave_mii_bus_init(struct dsa_switch *ds); |
| 134 | struct net_device *dsa_slave_create(struct dsa_switch *ds, |
| 135 | struct device *parent, |
| 136 | int port, char *name); |
| 137 | |
Lennert Buytenhek | cf85d08 | 2008-10-07 13:45:02 +0000 | [diff] [blame] | 138 | /* tag_dsa.c */ |
Stephen Hemminger | 6fef4c0 | 2009-08-31 19:50:41 +0000 | [diff] [blame] | 139 | netdev_tx_t dsa_xmit(struct sk_buff *skb, struct net_device *dev); |
Ben Hutchings | 7df899c | 2011-11-25 14:35:02 +0000 | [diff] [blame^] | 140 | extern struct packet_type dsa_packet_type; |
Lennert Buytenhek | cf85d08 | 2008-10-07 13:45:02 +0000 | [diff] [blame] | 141 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 142 | /* tag_edsa.c */ |
Stephen Hemminger | 6fef4c0 | 2009-08-31 19:50:41 +0000 | [diff] [blame] | 143 | netdev_tx_t edsa_xmit(struct sk_buff *skb, struct net_device *dev); |
Ben Hutchings | 7df899c | 2011-11-25 14:35:02 +0000 | [diff] [blame^] | 144 | extern struct packet_type edsa_packet_type; |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 145 | |
Lennert Buytenhek | 396138f | 2008-10-07 13:46:07 +0000 | [diff] [blame] | 146 | /* tag_trailer.c */ |
Stephen Hemminger | 6fef4c0 | 2009-08-31 19:50:41 +0000 | [diff] [blame] | 147 | netdev_tx_t trailer_xmit(struct sk_buff *skb, struct net_device *dev); |
Ben Hutchings | 7df899c | 2011-11-25 14:35:02 +0000 | [diff] [blame^] | 148 | extern struct packet_type trailer_packet_type; |
Lennert Buytenhek | 396138f | 2008-10-07 13:46:07 +0000 | [diff] [blame] | 149 | |
Lennert Buytenhek | 91da11f | 2008-10-07 13:44:02 +0000 | [diff] [blame] | 150 | |
| 151 | #endif |