Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db98a0b0 authored by Giuseppe CAVALLARO's avatar Giuseppe CAVALLARO Committed by David S. Miller
Browse files

stmmac: reorganise class operations.



This patch reorganises the internal stmmac ops structure.
The stmmac_ops has been splitted into other three structures named:
 stmmac_ops
 stmmac_dma_ops
 stmmac_desc_ops

This makes the code more clear and also helps the next work to
make the driver more generic.

Signed-off-by: default avatarGiuseppe Cavallaro <peppe.cavallaro@st.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 65818fa7
Loading
Loading
Loading
Loading
+34 −30
Original line number Diff line number Diff line
@@ -239,25 +239,11 @@ static inline void stmmac_get_mac_addr(unsigned long ioaddr,
	return;
}

struct stmmac_ops {
	/* MAC core initialization */
	void (*core_init) (unsigned long ioaddr) ____cacheline_aligned;
	/* DMA core initialization */
	int (*dma_init) (unsigned long ioaddr, int pbl, u32 dma_tx, u32 dma_rx);
	/* Dump MAC registers */
	void (*dump_mac_regs) (unsigned long ioaddr);
	/* Dump DMA registers */
	void (*dump_dma_regs) (unsigned long ioaddr);
	/* Set tx/rx threshold in the csr6 register
	 * An invalid value enables the store-and-forward mode */
	void (*dma_mode) (unsigned long ioaddr, int txmode, int rxmode);
	/* To track extra statistic (if supported) */
	void (*dma_diagnostic_fr) (void *data, struct stmmac_extra_stats *x,
				   unsigned long ioaddr);
	/* RX descriptor ring initialization */
struct stmmac_desc_ops {
	/* DMA RX descriptor ring initialization */
	void (*init_rx_desc) (struct dma_desc *p, unsigned int ring_size,
			      int disable_rx_ic);
	/* TX descriptor ring initialization */
	/* DMA TX descriptor ring initialization */
	void (*init_tx_desc) (struct dma_desc *p, unsigned int ring_size);

	/* Invoked by the xmit function to prepare the tx descriptor */
@@ -281,7 +267,6 @@ struct stmmac_ops {
	/* Get the buffer size from the descriptor */
	int (*get_tx_len) (struct dma_desc *p);
	/* Handle extra events on specific interrupts hw dependent */
	void (*host_irq_status) (unsigned long ioaddr);
	int (*get_rx_owner) (struct dma_desc *p);
	void (*set_rx_owner) (struct dma_desc *p);
	/* Get the receive frame size */
@@ -289,6 +274,28 @@ struct stmmac_ops {
	/* Return the reception status looking at the RDES1 */
	int (*rx_status) (void *data, struct stmmac_extra_stats *x,
			  struct dma_desc *p);
};

struct stmmac_dma_ops {
	/* DMA core initialization */
	int (*init) (unsigned long ioaddr, int pbl, u32 dma_tx, u32 dma_rx);
	/* Dump DMA registers */
	void (*dump_regs) (unsigned long ioaddr);
	/* Set tx/rx threshold in the csr6 register
	 * An invalid value enables the store-and-forward mode */
	void (*dma_mode) (unsigned long ioaddr, int txmode, int rxmode);
	/* To track extra statistic (if supported) */
	void (*dma_diagnostic_fr) (void *data, struct stmmac_extra_stats *x,
				   unsigned long ioaddr);
};

struct stmmac_ops {
	/* MAC core initialization */
	void (*core_init) (unsigned long ioaddr) ____cacheline_aligned;
	/* Dump MAC registers */
	void (*dump_regs) (unsigned long ioaddr);
	/* Handle extra events on specific interrupts hw dependent */
	void (*host_irq_status) (unsigned long ioaddr);
	/* Multicast filter setting */
	void (*set_filter) (struct net_device *dev);
	/* Flow control setting */
@@ -314,16 +321,13 @@ struct mii_regs {
	unsigned int data;	/* MII Data */
};

struct hw_cap {
	unsigned int version;	/* Core Version register (GMAC) */
	unsigned int pmt;	/* Power-Down mode (GMAC) */
	struct mac_link link;
	struct mii_regs mii;
};

struct mac_device_info {
	struct hw_cap hw;
	struct stmmac_ops *ops;
	struct stmmac_ops	*mac;
	struct stmmac_desc_ops	*desc;
	struct stmmac_dma_ops	*dma;
	unsigned int pmt;	/* support Power-Down */
	struct mii_regs mii;	/* MII register Addresses */
	struct mac_link link;
};

struct mac_device_info *gmac_setup(unsigned long addr);
+26 −17
Original line number Diff line number Diff line
@@ -630,19 +630,28 @@ static int gmac_get_rx_frame_len(struct dma_desc *p)
	return p->des01.erx.frame_length;
}

struct stmmac_ops gmac_driver = {
struct stmmac_ops gmac_ops = {
	.core_init = gmac_core_init,
	.dump_mac_regs = gmac_dump_regs,
	.dma_init = gmac_dma_init,
	.dump_dma_regs = gmac_dump_dma_regs,
	.dump_regs = gmac_dump_regs,
	.host_irq_status = gmac_irq_status,
	.set_filter = gmac_set_filter,
	.flow_ctrl = gmac_flow_ctrl,
	.pmt = gmac_pmt,
	.set_umac_addr = gmac_set_umac_addr,
	.get_umac_addr = gmac_get_umac_addr,
};

struct stmmac_dma_ops gmac_dma_ops = {
	.init = gmac_dma_init,
	.dump_regs = gmac_dump_dma_regs,
	.dma_mode = gmac_dma_operation_mode,
	.dma_diagnostic_fr = gmac_dma_diagnostic_fr,
};

struct stmmac_desc_ops gmac_desc_ops = {
	.tx_status = gmac_get_tx_frame_status,
	.rx_status = gmac_get_rx_frame_status,
	.get_tx_len = gmac_get_tx_len,
	.set_filter = gmac_set_filter,
	.flow_ctrl = gmac_flow_ctrl,
	.pmt = gmac_pmt,
	.init_rx_desc = gmac_init_rx_desc,
	.init_tx_desc = gmac_init_tx_desc,
	.get_tx_owner = gmac_get_tx_owner,
@@ -655,9 +664,6 @@ struct stmmac_ops gmac_driver = {
	.set_tx_owner = gmac_set_tx_owner,
	.set_rx_owner = gmac_set_rx_owner,
	.get_rx_frame_len = gmac_get_rx_frame_len,
	.host_irq_status = gmac_irq_status,
	.set_umac_addr = gmac_set_umac_addr,
	.get_umac_addr = gmac_get_umac_addr,
};

struct mac_device_info *gmac_setup(unsigned long ioaddr)
@@ -670,13 +676,16 @@ struct mac_device_info *gmac_setup(unsigned long ioaddr)

	mac = kzalloc(sizeof(const struct mac_device_info), GFP_KERNEL);

	mac->ops = &gmac_driver;
	mac->hw.pmt = PMT_SUPPORTED;
	mac->hw.link.port = GMAC_CONTROL_PS;
	mac->hw.link.duplex = GMAC_CONTROL_DM;
	mac->hw.link.speed = GMAC_CONTROL_FES;
	mac->hw.mii.addr = GMAC_MII_ADDR;
	mac->hw.mii.data = GMAC_MII_DATA;
	mac->mac = &gmac_ops;
	mac->desc = &gmac_desc_ops;
	mac->dma = &gmac_dma_ops;

	mac->pmt = PMT_SUPPORTED;
	mac->link.port = GMAC_CONTROL_PS;
	mac->link.duplex = GMAC_CONTROL_DM;
	mac->link.speed = GMAC_CONTROL_FES;
	mac->mii.addr = GMAC_MII_ADDR;
	mac->mii.data = GMAC_MII_DATA;

	return mac;
}
+26 −17
Original line number Diff line number Diff line
@@ -467,19 +467,28 @@ static int mac100_get_rx_frame_len(struct dma_desc *p)
	return p->des01.rx.frame_length;
}

struct stmmac_ops mac100_driver = {
struct stmmac_ops mac100_ops = {
	.core_init = mac100_core_init,
	.dump_mac_regs = mac100_dump_mac_regs,
	.dma_init = mac100_dma_init,
	.dump_dma_regs = mac100_dump_dma_regs,
	.dump_regs = mac100_dump_mac_regs,
	.host_irq_status = mac100_irq_status,
	.set_filter = mac100_set_filter,
	.flow_ctrl = mac100_flow_ctrl,
	.pmt = mac100_pmt,
	.set_umac_addr = mac100_set_umac_addr,
	.get_umac_addr = mac100_get_umac_addr,
};

struct stmmac_dma_ops mac100_dma_ops = {
	.init = mac100_dma_init,
	.dump_regs = mac100_dump_dma_regs,
	.dma_mode = mac100_dma_operation_mode,
	.dma_diagnostic_fr = mac100_dma_diagnostic_fr,
};

struct stmmac_desc_ops mac100_desc_ops = {
	.tx_status = mac100_get_tx_frame_status,
	.rx_status = mac100_get_rx_frame_status,
	.get_tx_len = mac100_get_tx_len,
	.set_filter = mac100_set_filter,
	.flow_ctrl = mac100_flow_ctrl,
	.pmt = mac100_pmt,
	.init_rx_desc = mac100_init_rx_desc,
	.init_tx_desc = mac100_init_tx_desc,
	.get_tx_owner = mac100_get_tx_owner,
@@ -492,9 +501,6 @@ struct stmmac_ops mac100_driver = {
	.set_tx_owner = mac100_set_tx_owner,
	.set_rx_owner = mac100_set_rx_owner,
	.get_rx_frame_len = mac100_get_rx_frame_len,
	.host_irq_status = mac100_irq_status,
	.set_umac_addr = mac100_set_umac_addr,
	.get_umac_addr = mac100_get_umac_addr,
};

struct mac_device_info *mac100_setup(unsigned long ioaddr)
@@ -505,13 +511,16 @@ struct mac_device_info *mac100_setup(unsigned long ioaddr)

	pr_info("\tMAC 10/100\n");

	mac->ops = &mac100_driver;
	mac->hw.pmt = PMT_NOT_SUPPORTED;
	mac->hw.link.port = MAC_CONTROL_PS;
	mac->hw.link.duplex = MAC_CONTROL_F;
	mac->hw.link.speed = 0;
	mac->hw.mii.addr = MAC_MII_ADDR;
	mac->hw.mii.data = MAC_MII_DATA;
	mac->mac = &mac100_ops;
	mac->desc = &mac100_desc_ops;
	mac->dma = &mac100_dma_ops;

	mac->pmt = PMT_NOT_SUPPORTED;
	mac->link.port = MAC_CONTROL_PS;
	mac->link.duplex = MAC_CONTROL_F;
	mac->link.speed = 0;
	mac->mii.addr = MAC_MII_ADDR;
	mac->mii.data = MAC_MII_DATA;

	return mac;
}
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ struct stmmac_priv {
	int rx_csum;
	unsigned int dma_buf_sz;
	struct device *device;
	struct mac_device_info *mac_type;
	struct mac_device_info *hw;

	struct stmmac_extra_stats xstats;
	struct napi_struct napi;
+4 −4
Original line number Diff line number Diff line
@@ -268,7 +268,7 @@ stmmac_set_pauseparam(struct net_device *netdev,
		}
	} else {
		unsigned long ioaddr = netdev->base_addr;
		priv->mac_type->ops->flow_ctrl(ioaddr, phy->duplex,
		priv->hw->mac->flow_ctrl(ioaddr, phy->duplex,
					 priv->flow_ctrl, priv->pause);
	}
	spin_unlock(&priv->lock);
@@ -283,7 +283,7 @@ static void stmmac_get_ethtool_stats(struct net_device *dev,
	int i;

	/* Update HW stats if supported */
	priv->mac_type->ops->dma_diagnostic_fr(&dev->stats, &priv->xstats,
	priv->hw->dma->dma_diagnostic_fr(&dev->stats, (void *) &priv->xstats,
					 ioaddr);

	for (i = 0; i < STMMAC_STATS_LEN; i++) {
Loading