From: <Tristram.Ha@microchip.com>
To: <andrew@lunn.ch>, <muvarov@gmail.com>, <pavel@ucw.cz>,
<nathan.leigh.conrad@gmail.com>,
<vivien.didelot@savoirfairelinux.com>, <f.fainelli@gmail.com>,
<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<Woojung.Huh@microchip.com>
Subject: [PATCH RFC 4/6] The common header ksz_priv.h does not contain chip specific data
Date: Thu, 7 Sep 2017 21:09:17 +0000 [thread overview]
Message-ID: <93AF473E2DA327428DE3D46B72B1E9FD41121A14@CHN-SV-EXMX02.mchp-main.com> (raw)
In-Reply-To: <93AF473E2DA327428DE3D46B72B1E9FD411218E7@CHN-SV-EXMX02.mchp-main.com>
From: Tristram Ha <Tristram.Ha@microchip.com>
The header ksz_priv.h is used by all KSZ switch drivers so chip specific data are removed and commonly used variables are added.
Signed-off-by: Tristram Ha <Tristram.Ha@microchip.com>
---
diff --git a/drivers/net/dsa/microchip/ksz_priv.h b/drivers/net/dsa/microchip/ksz_priv.h
index 2a98dbd..343b509 100644
--- a/drivers/net/dsa/microchip/ksz_priv.h
+++ b/drivers/net/dsa/microchip/ksz_priv.h
@@ -25,14 +25,56 @@
#include <linux/etherdevice.h>
#include <net/dsa.h>
-#include "ksz_9477_reg.h"
-
struct ksz_io_ops;
struct vlan_table {
u32 table[3];
};
+enum {
+ PHY_NO_FLOW_CTRL,
+ PHY_FLOW_CTRL,
+ PHY_TX_ONLY,
+ PHY_RX_ONLY
+};
+
+struct ksz_port_mib {
+ u8 cnt_ptr;
+ u8 ctrl;
+ unsigned long time;
+
+ struct ksz_port_mib_info {
+ u64 counter;
+ u8 read_cnt;
+ u8 read_max;
+ } *info;
+};
+
+struct ksz_port {
+ u16 member;
+ u16 vid_member;
+ int stp_state;
+ u16 speed;
+ u8 duplex;
+ u8 advertised;
+ u8 flow_ctrl;
+ u8 link;
+ u8 partner;
+
+ u32 on:1; /* port is not disabled by hardware */
+ u32 fiber:1; /* port is fiber */
+ u32 sgmii:1; /* port is SGMII */
+ u32 force:1;
+ u32 link_down:1; /* link just goes down */
+ u32 link_up:1; /* link is up */
+
+ struct ksz_port_mib mib;
+};
+
+#define USE_FEWER_PORTS BIT(18)
+
+#define PTP_TAG BIT(29)
+
struct ksz_device {
struct dsa_switch *ds;
struct ksz_platform_data *pdata;
@@ -43,6 +85,7 @@ struct ksz_device {
struct mutex alu_mutex; /* ALU access */
struct mutex vlan_mutex; /* vlan access */
const struct ksz_io_ops *ops;
+ const struct ksz_dev_ops *dev_ops;
struct device *dev;
@@ -56,10 +99,32 @@ struct ksz_device {
int cpu_port; /* port connected to CPU */
int cpu_ports; /* port bitmap can be cpu port */
int port_cnt;
+ int mib_cnt;
+ int mib_port_cnt;
+ int last_port; /* ports after that not used */
+ int interface;
struct vlan_table *vlan_cache;
- u64 mib_value[TOTAL_SWITCH_COUNTER_NUM];
+ u8 *txbuf;
+
+ struct ksz_port *ports;
+ struct timer_list mib_read_timer;
+ struct work_struct mib_read;
+ spinlock_t mib_read_lock; /* use to update read_cnt */
+ unsigned long MIB_READ_INTERVAL;
+ u32 features;
+ u32 overrides;
+ u16 br_member;
+ u16 member;
+ u16 live_ports;
+ u16 on_ports; /* ports enabled by DSA */
+ u16 rx_ports;
+ u16 tx_ports;
+ u16 mirror_rx;
+ u16 mirror_tx;
+ u16 HOST_MASK;
+ u16 PORT_MASK;
};
struct ksz_io_ops {
@@ -75,12 +140,30 @@ struct ksz_io_ops {
u16 *value);
int (*phy_write16)(struct ksz_device *dev, int addr, int reg,
u16 value);
+ unsigned int (*get)(struct ksz_device *dev, u32 reg, void *data,
+ unsigned int len);
+ unsigned int (*set)(struct ksz_device *dev, u32 reg, void *data,
+ unsigned int len);
+};
+
+struct ksz_dev_ops {
+ u32 (*get_port_addr)(int port, int offset);
+ int (*reset)(struct ksz_device *dev);
+ int (*get_rx_len)(struct ksz_device *dev);
+ int (*get_tx_len)(struct ksz_device *dev);
+ void (*add_tail_tag)(struct ksz_device *dev, struct sk_buff *skb,
+ int port);
+ int (*get_tail_tag)(struct ksz_device *dev, struct sk_buff *skb,
+ int *port);
+ int (*detect)(struct ksz_device *dev);
+ int (*init)(struct ksz_device *dev);
+ void (*exit)(struct ksz_device *dev);
};
struct ksz_device *ksz_switch_alloc(struct device *base,
const struct ksz_io_ops *ops, void *priv); -int ksz_switch_detect(struct ksz_device *dev); -int ksz_switch_register(struct ksz_device *dev);
+int ksz_switch_register(struct ksz_device *dev,
+ const struct ksz_dev_ops *ops);
void ksz_switch_remove(struct ksz_device *dev);
static inline int ksz_read8(struct ksz_device *dev, u32 reg, u8 *val) @@ -174,37 +257,37 @@ static inline int ksz_write32(struct ksz_device *dev, u32 reg, u32 value) static inline void ksz_pread8(struct ksz_device *dev, int port, int offset,
u8 *data)
{
- ksz_read8(dev, PORT_CTRL_ADDR(port, offset), data);
+ ksz_read8(dev, dev->dev_ops->get_port_addr(port, offset), data);
}
static inline void ksz_pread16(struct ksz_device *dev, int port, int offset,
u16 *data)
{
- ksz_read16(dev, PORT_CTRL_ADDR(port, offset), data);
+ ksz_read16(dev, dev->dev_ops->get_port_addr(port, offset), data);
}
static inline void ksz_pread32(struct ksz_device *dev, int port, int offset,
u32 *data)
{
- ksz_read32(dev, PORT_CTRL_ADDR(port, offset), data);
+ ksz_read32(dev, dev->dev_ops->get_port_addr(port, offset), data);
}
static inline void ksz_pwrite8(struct ksz_device *dev, int port, int offset,
u8 data)
{
- ksz_write8(dev, PORT_CTRL_ADDR(port, offset), data);
+ ksz_write8(dev, dev->dev_ops->get_port_addr(port, offset), data);
}
static inline void ksz_pwrite16(struct ksz_device *dev, int port, int offset,
u16 data)
{
- ksz_write16(dev, PORT_CTRL_ADDR(port, offset), data);
+ ksz_write16(dev, dev->dev_ops->get_port_addr(port, offset), data);
}
static inline void ksz_pwrite32(struct ksz_device *dev, int port, int offset,
u32 data)
{
- ksz_write32(dev, PORT_CTRL_ADDR(port, offset), data);
+ ksz_write32(dev, dev->dev_ops->get_port_addr(port, offset), data);
}
#endif
parent reply other threads:[~2017-09-07 21:10 UTC|newest]
Thread overview: expand[flat|nested] mbox.gz Atom feed
[parent not found: <93AF473E2DA327428DE3D46B72B1E9FD411218E7@CHN-SV-EXMX02.mchp-main.com>]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=93AF473E2DA327428DE3D46B72B1E9FD41121A14@CHN-SV-EXMX02.mchp-main.com \
--to=tristram.ha@microchip.com \
--cc=Woojung.Huh@microchip.com \
--cc=andrew@lunn.ch \
--cc=f.fainelli@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=muvarov@gmail.com \
--cc=nathan.leigh.conrad@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=vivien.didelot@savoirfairelinux.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).