Skip to content

Commit 5da8baa

Browse files
committed
Merge branch 'net-stmmac-Stop-using-hard-coded-callbacks'
Jose Abreu says: ==================== net: stmmac: Stop using hard-coded callbacks This a starting point for a cleanup and re-organization of stmmac. In this series we stop using hard-coded callbacks along the code and use instead helpers which are defined in a single place ("hwif.h"). This brings several advantages: 1) Less typing :) 2) Guaranteed function pointer check 3) More flexibility By 2) we stop using the repeated pattern of: if (priv->hw->mac->some_func) priv->hw->mac->some_func(...) I didn't check but I expect the final .ko will be bigger with this series because *all* of function pointers are checked. Anyway, I hope this can make the code more readable and more flexible now. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 309c446 + 2c520b1 commit 5da8baa

File tree

13 files changed

+726
-577
lines changed

13 files changed

+726
-577
lines changed

drivers/net/ethernet/stmicro/stmmac/chain_mode.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "stmmac.h"
2626

27-
static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
27+
static int jumbo_frm(void *p, struct sk_buff *skb, int csum)
2828
{
2929
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)p;
3030
unsigned int nopaged_len = skb_headlen(skb);
@@ -51,8 +51,8 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
5151
tx_q->tx_skbuff_dma[entry].buf = des2;
5252
tx_q->tx_skbuff_dma[entry].len = bmax;
5353
/* do not close the descriptor and do not set own bit */
54-
priv->hw->desc->prepare_tx_desc(desc, 1, bmax, csum, STMMAC_CHAIN_MODE,
55-
0, false, skb->len);
54+
stmmac_prepare_tx_desc(priv, desc, 1, bmax, csum, STMMAC_CHAIN_MODE,
55+
0, false, skb->len);
5656

5757
while (len != 0) {
5858
tx_q->tx_skbuff[entry] = NULL;
@@ -68,9 +68,8 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
6868
return -1;
6969
tx_q->tx_skbuff_dma[entry].buf = des2;
7070
tx_q->tx_skbuff_dma[entry].len = bmax;
71-
priv->hw->desc->prepare_tx_desc(desc, 0, bmax, csum,
72-
STMMAC_CHAIN_MODE, 1,
73-
false, skb->len);
71+
stmmac_prepare_tx_desc(priv, desc, 0, bmax, csum,
72+
STMMAC_CHAIN_MODE, 1, false, skb->len);
7473
len -= bmax;
7574
i++;
7675
} else {
@@ -83,9 +82,8 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
8382
tx_q->tx_skbuff_dma[entry].buf = des2;
8483
tx_q->tx_skbuff_dma[entry].len = len;
8584
/* last descriptor can be set now */
86-
priv->hw->desc->prepare_tx_desc(desc, 0, len, csum,
87-
STMMAC_CHAIN_MODE, 1,
88-
true, skb->len);
85+
stmmac_prepare_tx_desc(priv, desc, 0, len, csum,
86+
STMMAC_CHAIN_MODE, 1, true, skb->len);
8987
len = 0;
9088
}
9189
}
@@ -95,7 +93,7 @@ static int stmmac_jumbo_frm(void *p, struct sk_buff *skb, int csum)
9593
return entry;
9694
}
9795

98-
static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
96+
static unsigned int is_jumbo_frm(int len, int enh_desc)
9997
{
10098
unsigned int ret = 0;
10199

@@ -107,7 +105,7 @@ static unsigned int stmmac_is_jumbo_frm(int len, int enh_desc)
107105
return ret;
108106
}
109107

110-
static void stmmac_init_dma_chain(void *des, dma_addr_t phy_addr,
108+
static void init_dma_chain(void *des, dma_addr_t phy_addr,
111109
unsigned int size, unsigned int extend_desc)
112110
{
113111
/*
@@ -137,7 +135,7 @@ static void stmmac_init_dma_chain(void *des, dma_addr_t phy_addr,
137135
}
138136
}
139137

140-
static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
138+
static void refill_desc3(void *priv_ptr, struct dma_desc *p)
141139
{
142140
struct stmmac_rx_queue *rx_q = (struct stmmac_rx_queue *)priv_ptr;
143141
struct stmmac_priv *priv = rx_q->priv_data;
@@ -153,7 +151,7 @@ static void stmmac_refill_desc3(void *priv_ptr, struct dma_desc *p)
153151
sizeof(struct dma_desc)));
154152
}
155153

156-
static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
154+
static void clean_desc3(void *priv_ptr, struct dma_desc *p)
157155
{
158156
struct stmmac_tx_queue *tx_q = (struct stmmac_tx_queue *)priv_ptr;
159157
struct stmmac_priv *priv = tx_q->priv_data;
@@ -171,9 +169,9 @@ static void stmmac_clean_desc3(void *priv_ptr, struct dma_desc *p)
171169
}
172170

173171
const struct stmmac_mode_ops chain_mode_ops = {
174-
.init = stmmac_init_dma_chain,
175-
.is_jumbo_frm = stmmac_is_jumbo_frm,
176-
.jumbo_frm = stmmac_jumbo_frm,
177-
.refill_desc3 = stmmac_refill_desc3,
178-
.clean_desc3 = stmmac_clean_desc3,
172+
.init = init_dma_chain,
173+
.is_jumbo_frm = is_jumbo_frm,
174+
.jumbo_frm = jumbo_frm,
175+
.refill_desc3 = refill_desc3,
176+
.clean_desc3 = clean_desc3,
179177
};

drivers/net/ethernet/stmicro/stmmac/common.h

Lines changed: 1 addition & 198 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#endif
3333

3434
#include "descs.h"
35+
#include "hwif.h"
3536
#include "mmc.h"
3637

3738
/* Synopsys Core versions */
@@ -377,197 +378,11 @@ struct dma_features {
377378

378379
#define JUMBO_LEN 9000
379380

380-
/* Descriptors helpers */
381-
struct stmmac_desc_ops {
382-
/* DMA RX descriptor ring initialization */
383-
void (*init_rx_desc) (struct dma_desc *p, int disable_rx_ic, int mode,
384-
int end);
385-
/* DMA TX descriptor ring initialization */
386-
void (*init_tx_desc) (struct dma_desc *p, int mode, int end);
387-
388-
/* Invoked by the xmit function to prepare the tx descriptor */
389-
void (*prepare_tx_desc) (struct dma_desc *p, int is_fs, int len,
390-
bool csum_flag, int mode, bool tx_own,
391-
bool ls, unsigned int tot_pkt_len);
392-
void (*prepare_tso_tx_desc)(struct dma_desc *p, int is_fs, int len1,
393-
int len2, bool tx_own, bool ls,
394-
unsigned int tcphdrlen,
395-
unsigned int tcppayloadlen);
396-
/* Set/get the owner of the descriptor */
397-
void (*set_tx_owner) (struct dma_desc *p);
398-
int (*get_tx_owner) (struct dma_desc *p);
399-
/* Clean the tx descriptor as soon as the tx irq is received */
400-
void (*release_tx_desc) (struct dma_desc *p, int mode);
401-
/* Clear interrupt on tx frame completion. When this bit is
402-
* set an interrupt happens as soon as the frame is transmitted */
403-
void (*set_tx_ic)(struct dma_desc *p);
404-
/* Last tx segment reports the transmit status */
405-
int (*get_tx_ls) (struct dma_desc *p);
406-
/* Return the transmit status looking at the TDES1 */
407-
int (*tx_status) (void *data, struct stmmac_extra_stats *x,
408-
struct dma_desc *p, void __iomem *ioaddr);
409-
/* Get the buffer size from the descriptor */
410-
int (*get_tx_len) (struct dma_desc *p);
411-
/* Handle extra events on specific interrupts hw dependent */
412-
void (*set_rx_owner) (struct dma_desc *p);
413-
/* Get the receive frame size */
414-
int (*get_rx_frame_len) (struct dma_desc *p, int rx_coe_type);
415-
/* Return the reception status looking at the RDES1 */
416-
int (*rx_status) (void *data, struct stmmac_extra_stats *x,
417-
struct dma_desc *p);
418-
void (*rx_extended_status) (void *data, struct stmmac_extra_stats *x,
419-
struct dma_extended_desc *p);
420-
/* Set tx timestamp enable bit */
421-
void (*enable_tx_timestamp) (struct dma_desc *p);
422-
/* get tx timestamp status */
423-
int (*get_tx_timestamp_status) (struct dma_desc *p);
424-
/* get timestamp value */
425-
u64(*get_timestamp) (void *desc, u32 ats);
426-
/* get rx timestamp status */
427-
int (*get_rx_timestamp_status)(void *desc, void *next_desc, u32 ats);
428-
/* Display ring */
429-
void (*display_ring)(void *head, unsigned int size, bool rx);
430-
/* set MSS via context descriptor */
431-
void (*set_mss)(struct dma_desc *p, unsigned int mss);
432-
};
433-
434381
extern const struct stmmac_desc_ops enh_desc_ops;
435382
extern const struct stmmac_desc_ops ndesc_ops;
436383

437-
/* Specific DMA helpers */
438-
struct stmmac_dma_ops {
439-
/* DMA core initialization */
440-
int (*reset)(void __iomem *ioaddr);
441-
void (*init)(void __iomem *ioaddr, struct stmmac_dma_cfg *dma_cfg,
442-
u32 dma_tx, u32 dma_rx, int atds);
443-
void (*init_chan)(void __iomem *ioaddr,
444-
struct stmmac_dma_cfg *dma_cfg, u32 chan);
445-
void (*init_rx_chan)(void __iomem *ioaddr,
446-
struct stmmac_dma_cfg *dma_cfg,
447-
u32 dma_rx_phy, u32 chan);
448-
void (*init_tx_chan)(void __iomem *ioaddr,
449-
struct stmmac_dma_cfg *dma_cfg,
450-
u32 dma_tx_phy, u32 chan);
451-
/* Configure the AXI Bus Mode Register */
452-
void (*axi)(void __iomem *ioaddr, struct stmmac_axi *axi);
453-
/* Dump DMA registers */
454-
void (*dump_regs)(void __iomem *ioaddr, u32 *reg_space);
455-
/* Set tx/rx threshold in the csr6 register
456-
* An invalid value enables the store-and-forward mode */
457-
void (*dma_mode)(void __iomem *ioaddr, int txmode, int rxmode,
458-
int rxfifosz);
459-
void (*dma_rx_mode)(void __iomem *ioaddr, int mode, u32 channel,
460-
int fifosz, u8 qmode);
461-
void (*dma_tx_mode)(void __iomem *ioaddr, int mode, u32 channel,
462-
int fifosz, u8 qmode);
463-
/* To track extra statistic (if supported) */
464-
void (*dma_diagnostic_fr) (void *data, struct stmmac_extra_stats *x,
465-
void __iomem *ioaddr);
466-
void (*enable_dma_transmission) (void __iomem *ioaddr);
467-
void (*enable_dma_irq)(void __iomem *ioaddr, u32 chan);
468-
void (*disable_dma_irq)(void __iomem *ioaddr, u32 chan);
469-
void (*start_tx)(void __iomem *ioaddr, u32 chan);
470-
void (*stop_tx)(void __iomem *ioaddr, u32 chan);
471-
void (*start_rx)(void __iomem *ioaddr, u32 chan);
472-
void (*stop_rx)(void __iomem *ioaddr, u32 chan);
473-
int (*dma_interrupt) (void __iomem *ioaddr,
474-
struct stmmac_extra_stats *x, u32 chan);
475-
/* If supported then get the optional core features */
476-
void (*get_hw_feature)(void __iomem *ioaddr,
477-
struct dma_features *dma_cap);
478-
/* Program the HW RX Watchdog */
479-
void (*rx_watchdog)(void __iomem *ioaddr, u32 riwt, u32 number_chan);
480-
void (*set_tx_ring_len)(void __iomem *ioaddr, u32 len, u32 chan);
481-
void (*set_rx_ring_len)(void __iomem *ioaddr, u32 len, u32 chan);
482-
void (*set_rx_tail_ptr)(void __iomem *ioaddr, u32 tail_ptr, u32 chan);
483-
void (*set_tx_tail_ptr)(void __iomem *ioaddr, u32 tail_ptr, u32 chan);
484-
void (*enable_tso)(void __iomem *ioaddr, bool en, u32 chan);
485-
};
486-
487384
struct mac_device_info;
488385

489-
/* Helpers to program the MAC core */
490-
struct stmmac_ops {
491-
/* MAC core initialization */
492-
void (*core_init)(struct mac_device_info *hw, struct net_device *dev);
493-
/* Enable the MAC RX/TX */
494-
void (*set_mac)(void __iomem *ioaddr, bool enable);
495-
/* Enable and verify that the IPC module is supported */
496-
int (*rx_ipc)(struct mac_device_info *hw);
497-
/* Enable RX Queues */
498-
void (*rx_queue_enable)(struct mac_device_info *hw, u8 mode, u32 queue);
499-
/* RX Queues Priority */
500-
void (*rx_queue_prio)(struct mac_device_info *hw, u32 prio, u32 queue);
501-
/* TX Queues Priority */
502-
void (*tx_queue_prio)(struct mac_device_info *hw, u32 prio, u32 queue);
503-
/* RX Queues Routing */
504-
void (*rx_queue_routing)(struct mac_device_info *hw, u8 packet,
505-
u32 queue);
506-
/* Program RX Algorithms */
507-
void (*prog_mtl_rx_algorithms)(struct mac_device_info *hw, u32 rx_alg);
508-
/* Program TX Algorithms */
509-
void (*prog_mtl_tx_algorithms)(struct mac_device_info *hw, u32 tx_alg);
510-
/* Set MTL TX queues weight */
511-
void (*set_mtl_tx_queue_weight)(struct mac_device_info *hw,
512-
u32 weight, u32 queue);
513-
/* RX MTL queue to RX dma mapping */
514-
void (*map_mtl_to_dma)(struct mac_device_info *hw, u32 queue, u32 chan);
515-
/* Configure AV Algorithm */
516-
void (*config_cbs)(struct mac_device_info *hw, u32 send_slope,
517-
u32 idle_slope, u32 high_credit, u32 low_credit,
518-
u32 queue);
519-
/* Dump MAC registers */
520-
void (*dump_regs)(struct mac_device_info *hw, u32 *reg_space);
521-
/* Handle extra events on specific interrupts hw dependent */
522-
int (*host_irq_status)(struct mac_device_info *hw,
523-
struct stmmac_extra_stats *x);
524-
/* Handle MTL interrupts */
525-
int (*host_mtl_irq_status)(struct mac_device_info *hw, u32 chan);
526-
/* Multicast filter setting */
527-
void (*set_filter)(struct mac_device_info *hw, struct net_device *dev);
528-
/* Flow control setting */
529-
void (*flow_ctrl)(struct mac_device_info *hw, unsigned int duplex,
530-
unsigned int fc, unsigned int pause_time, u32 tx_cnt);
531-
/* Set power management mode (e.g. magic frame) */
532-
void (*pmt)(struct mac_device_info *hw, unsigned long mode);
533-
/* Set/Get Unicast MAC addresses */
534-
void (*set_umac_addr)(struct mac_device_info *hw, unsigned char *addr,
535-
unsigned int reg_n);
536-
void (*get_umac_addr)(struct mac_device_info *hw, unsigned char *addr,
537-
unsigned int reg_n);
538-
void (*set_eee_mode)(struct mac_device_info *hw,
539-
bool en_tx_lpi_clockgating);
540-
void (*reset_eee_mode)(struct mac_device_info *hw);
541-
void (*set_eee_timer)(struct mac_device_info *hw, int ls, int tw);
542-
void (*set_eee_pls)(struct mac_device_info *hw, int link);
543-
void (*debug)(void __iomem *ioaddr, struct stmmac_extra_stats *x,
544-
u32 rx_queues, u32 tx_queues);
545-
/* PCS calls */
546-
void (*pcs_ctrl_ane)(void __iomem *ioaddr, bool ane, bool srgmi_ral,
547-
bool loopback);
548-
void (*pcs_rane)(void __iomem *ioaddr, bool restart);
549-
void (*pcs_get_adv_lp)(void __iomem *ioaddr, struct rgmii_adv *adv);
550-
/* Safety Features */
551-
int (*safety_feat_config)(void __iomem *ioaddr, unsigned int asp);
552-
bool (*safety_feat_irq_status)(struct net_device *ndev,
553-
void __iomem *ioaddr, unsigned int asp,
554-
struct stmmac_safety_stats *stats);
555-
const char *(*safety_feat_dump)(struct stmmac_safety_stats *stats,
556-
int index, unsigned long *count);
557-
};
558-
559-
/* PTP and HW Timer helpers */
560-
struct stmmac_hwtimestamp {
561-
void (*config_hw_tstamping) (void __iomem *ioaddr, u32 data);
562-
u32 (*config_sub_second_increment)(void __iomem *ioaddr, u32 ptp_clock,
563-
int gmac4);
564-
int (*init_systime) (void __iomem *ioaddr, u32 sec, u32 nsec);
565-
int (*config_addend) (void __iomem *ioaddr, u32 addend);
566-
int (*adjust_systime) (void __iomem *ioaddr, u32 sec, u32 nsec,
567-
int add_sub, int gmac4);
568-
u64(*get_systime) (void __iomem *ioaddr);
569-
};
570-
571386
extern const struct stmmac_hwtimestamp stmmac_ptp;
572387
extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;
573388

@@ -590,18 +405,6 @@ struct mii_regs {
590405
unsigned int clk_csr_mask;
591406
};
592407

593-
/* Helpers to manage the descriptors for chain and ring modes */
594-
struct stmmac_mode_ops {
595-
void (*init) (void *des, dma_addr_t phy_addr, unsigned int size,
596-
unsigned int extend_desc);
597-
unsigned int (*is_jumbo_frm) (int len, int ehn_desc);
598-
int (*jumbo_frm)(void *priv, struct sk_buff *skb, int csum);
599-
int (*set_16kib_bfsize)(int mtu);
600-
void (*init_desc3)(struct dma_desc *p);
601-
void (*refill_desc3) (void *priv, struct dma_desc *p);
602-
void (*clean_desc3) (void *priv, struct dma_desc *p);
603-
};
604-
605408
struct mac_device_info {
606409
const struct stmmac_ops *mac;
607410
const struct stmmac_desc_ops *desc;

drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int dwmac4_wrback_get_tx_timestamp_status(struct dma_desc *p)
223223
return 0;
224224
}
225225

226-
static inline u64 dwmac4_get_timestamp(void *desc, u32 ats)
226+
static inline void dwmac4_get_timestamp(void *desc, u32 ats, u64 *ts)
227227
{
228228
struct dma_desc *p = (struct dma_desc *)desc;
229229
u64 ns;
@@ -232,7 +232,7 @@ static inline u64 dwmac4_get_timestamp(void *desc, u32 ats)
232232
/* convert high/sec time stamp value to nanosecond */
233233
ns += le32_to_cpu(p->des1) * 1000000000ULL;
234234

235-
return ns;
235+
*ts = ns;
236236
}
237237

238238
static int dwmac4_rx_check_timestamp(void *desc)

drivers/net/ethernet/stmicro/stmmac/dwmac5.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,16 @@ int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp)
237237
return 0;
238238
}
239239

240-
bool dwmac5_safety_feat_irq_status(struct net_device *ndev,
240+
int dwmac5_safety_feat_irq_status(struct net_device *ndev,
241241
void __iomem *ioaddr, unsigned int asp,
242242
struct stmmac_safety_stats *stats)
243243
{
244-
bool ret = false, err, corr;
244+
bool err, corr;
245245
u32 mtl, dma;
246+
int ret = 0;
246247

247248
if (!asp)
248-
return false;
249+
return -EINVAL;
249250

250251
mtl = readl(ioaddr + MTL_SAFETY_INT_STATUS);
251252
dma = readl(ioaddr + DMA_SAFETY_INT_STATUS);
@@ -282,17 +283,19 @@ static const struct dwmac5_error {
282283
{ dwmac5_dma_errors },
283284
};
284285

285-
const char *dwmac5_safety_feat_dump(struct stmmac_safety_stats *stats,
286-
int index, unsigned long *count)
286+
int dwmac5_safety_feat_dump(struct stmmac_safety_stats *stats,
287+
int index, unsigned long *count, const char **desc)
287288
{
288289
int module = index / 32, offset = index % 32;
289290
unsigned long *ptr = (unsigned long *)stats;
290291

291292
if (module >= ARRAY_SIZE(dwmac5_all_errors))
292-
return NULL;
293+
return -EINVAL;
293294
if (!dwmac5_all_errors[module].desc[offset].valid)
294-
return NULL;
295+
return -EINVAL;
295296
if (count)
296297
*count = *(ptr + index);
297-
return dwmac5_all_errors[module].desc[offset].desc;
298+
if (desc)
299+
*desc = dwmac5_all_errors[module].desc[offset].desc;
300+
return 0;
298301
}

drivers/net/ethernet/stmicro/stmmac/dwmac5.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
#define DMA_ECC_INT_STATUS 0x00001088
4444

4545
int dwmac5_safety_feat_config(void __iomem *ioaddr, unsigned int asp);
46-
bool dwmac5_safety_feat_irq_status(struct net_device *ndev,
46+
int dwmac5_safety_feat_irq_status(struct net_device *ndev,
4747
void __iomem *ioaddr, unsigned int asp,
4848
struct stmmac_safety_stats *stats);
49-
const char *dwmac5_safety_feat_dump(struct stmmac_safety_stats *stats,
50-
int index, unsigned long *count);
49+
int dwmac5_safety_feat_dump(struct stmmac_safety_stats *stats,
50+
int index, unsigned long *count, const char **desc);
5151

5252
#endif /* __DWMAC5_H__ */

0 commit comments

Comments
 (0)