Skip to content

Commit 833716e

Browse files
committed
Merge branch 'stmmac-GMAC4.x'
Alexandre TORGUE says: ==================== Enhance stmmac driver to support GMAC4.x IP This is a subset of patch to enhance current stmmac driver to support new GMAC4.x chips. New set of callbacks is defined to support this new family: descriptors, dma, core. One of main changes of GMAC 4.xx IP is descriptors management. -descriptors are only used in ring mode. -A descriptor is composed of 4 32bits registers (no more extended descriptors) -descriptor mechanism (Tx for example, but it is exactly the same for RX): -useful registers: -DMA_CH#_TxDesc_Ring_Len: length of transmit descriptor ring -DMA_CH#_TxDesc_List_Address: start address of the ring -DMA_CH#_TxDesc_Tail_Pointer: address of the last descriptor to send + 1. -DMA_CH#_TxDesc_Current_App_TxDesc: address of the current descriptor -The descriptor Tail Pointer register contains the pointer to the descriptor address (N). The base address and the current descriptor decide the address of the current descriptor that the DMA can process. The descriptors up to one location less than the one indicated by the descriptor tail pointer (N-1) are owned by the DMA. The DMA continues to process the descriptors until the following condition occurs: "current descriptor pointer == Descriptor Tail pointer" Then the DMA goes into suspend mode. The application must perform a write to descriptor tail pointer register and update the tail pointer to have the following condition and to start a new transfer: "current descriptor pointer < Descriptor tail pointer" The DMA automatically wraps around the base address when the end of ring is reached. New features are available on IP: -TSO (TCP Segmentation Offload) for TX only -Split header: to have header and payload in 2 different buffers (not yet implemented) Below some throughput figures obtained on some boxes: iperf (mbps) -------------------------------------- tcp udp tx rx tx rx ----------------- GMAC4.x 935 930 750 800 Note: There is a change in 4.10a databook on bitfield mapping of DMA_CHANx_INTR_ENA register. This requires to have é diffrent set of callbacks between IP 4.00a and 4.10a. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 5ada37b + 91979b9 commit 833716e

File tree

24 files changed

+2821
-369
lines changed

24 files changed

+2821
-369
lines changed

Documentation/devicetree/bindings/net/stmmac.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Optional properties:
5959
- snps,fb: fixed-burst
6060
- snps,mb: mixed-burst
6161
- snps,rb: rebuild INCRx Burst
62+
- snps,tso: this enables the TSO feature otherwise it will be managed by
63+
MAC HW capability register.
6264
- mdio: with compatible = "snps,dwmac-mdio", create and register mdio bus.
6365

6466
Examples:

Documentation/networking/stmmac.txt

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
STMicroelectronics 10/100/1000 Synopsys Ethernet driver
22

3-
Copyright (C) 2007-2014 STMicroelectronics Ltd
3+
Copyright (C) 2007-2015 STMicroelectronics Ltd
44
Author: Giuseppe Cavallaro <[email protected]>
55

66
This is the driver for the MAC 10/100/1000 on-chip Ethernet controllers
@@ -138,6 +138,8 @@ struct plat_stmmacenet_data {
138138
int (*init)(struct platform_device *pdev, void *priv);
139139
void (*exit)(struct platform_device *pdev, void *priv);
140140
void *bsp_priv;
141+
int has_gmac4;
142+
bool tso_en;
141143
};
142144

143145
Where:
@@ -181,6 +183,8 @@ Where:
181183
registers. init/exit callbacks should not use or modify
182184
platform data.
183185
o bsp_priv: another private pointer.
186+
o has_gmac4: uses GMAC4 core.
187+
o tso_en: Enables TSO (TCP Segmentation Offload) feature.
184188

185189
For MDIO bus The we have:
186190

@@ -278,6 +282,13 @@ Please see the following document:
278282
o stmmac_ethtool.c: to implement the ethtool support;
279283
o stmmac.h: private driver structure;
280284
o common.h: common definitions and VFTs;
285+
o mmc_core.c/mmc.h: Management MAC Counters;
286+
o stmmac_hwtstamp.c: HW timestamp support for PTP;
287+
o stmmac_ptp.c: PTP 1588 clock;
288+
o dwmac-<XXX>.c: these are for the platform glue-logic file; e.g. dwmac-sti.c
289+
for STMicroelectronics SoCs.
290+
291+
- GMAC 3.x
281292
o descs.h: descriptor structure definitions;
282293
o dwmac1000_core.c: dwmac GiGa core functions;
283294
o dwmac1000_dma.c: dma functions for the GMAC chip;
@@ -289,11 +300,32 @@ Please see the following document:
289300
o enh_desc.c: functions for handling enhanced descriptors;
290301
o norm_desc.c: functions for handling normal descriptors;
291302
o chain_mode.c/ring_mode.c:: functions to manage RING/CHAINED modes;
292-
o mmc_core.c/mmc.h: Management MAC Counters;
293-
o stmmac_hwtstamp.c: HW timestamp support for PTP;
294-
o stmmac_ptp.c: PTP 1588 clock;
295-
o dwmac-<XXX>.c: these are for the platform glue-logic file; e.g. dwmac-sti.c
296-
for STMicroelectronics SoCs.
303+
304+
- GMAC4.x generation
305+
o dwmac4_core.c: dwmac GMAC4.x core functions;
306+
o dwmac4_desc.c: functions for handling GMAC4.x descriptors;
307+
o dwmac4_descs.h: descriptor definitions;
308+
o dwmac4_dma.c: dma functions for the GMAC4.x chip;
309+
o dwmac4_dma.h: dma definitions for the GMAC4.x chip;
310+
o dwmac4.h: core definitions for the GMAC4.x chip;
311+
o dwmac4_lib.c: generic GMAC4.x functions;
312+
313+
4.12) TSO support (GMAC4.x)
314+
315+
TSO (Tcp Segmentation Offload) feature is supported by GMAC 4.x chip family.
316+
When a packet is sent through TCP protocol, the TCP stack ensures that
317+
the SKB provided to the low level driver (stmmac in our case) matches with
318+
the maximum frame len (IP header + TCP header + payload <= 1500 bytes (for
319+
MTU set to 1500)). It means that if an application using TCP want to send a
320+
packet which will have a length (after adding headers) > 1514 the packet
321+
will be split in several TCP packets: The data payload is split and headers
322+
(TCP/IP ..) are added. It is done by software.
323+
324+
When TSO is enabled, the TCP stack doesn't care about the maximum frame
325+
length and provide SKB packet to stmmac as it is. The GMAC IP will have to
326+
perform the segmentation by it self to match with maximum frame length.
327+
328+
This feature can be enabled in device tree through "snps,tso" entry.
297329

298330
5) Debug Information
299331

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,6 +3348,7 @@ F: Documentation/powerpc/cxlflash.txt
33483348

33493349
STMMAC ETHERNET DRIVER
33503350
M: Giuseppe Cavallaro <[email protected]>
3351+
M: Alexandre Torgue <[email protected]>
33513352
33523353
W: http://www.stlinux.com
33533354
S: Supported

drivers/net/ethernet/stmicro/stmmac/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ obj-$(CONFIG_STMMAC_ETH) += stmmac.o
22
stmmac-objs:= stmmac_main.o stmmac_ethtool.o stmmac_mdio.o ring_mode.o \
33
chain_mode.o dwmac_lib.o dwmac1000_core.o dwmac1000_dma.o \
44
dwmac100_core.o dwmac100_dma.o enh_desc.o norm_desc.o \
5-
mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o $(stmmac-y)
5+
mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o dwmac4_descs.o \
6+
dwmac4_dma.o dwmac4_lib.o dwmac4_core.o $(stmmac-y)
67

78
# Ordering matters. Generic driver must be last.
89
obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o

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

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
/* Synopsys Core versions */
4242
#define DWMAC_CORE_3_40 0x34
4343
#define DWMAC_CORE_3_50 0x35
44+
#define DWMAC_CORE_4_00 0x40
45+
#define STMMAC_CHAN0 0 /* Always supported and default for all chips */
4446

4547
#define DMA_TX_SIZE 512
4648
#define DMA_RX_SIZE 512
@@ -167,6 +169,9 @@ struct stmmac_extra_stats {
167169
unsigned long mtl_rx_fifo_ctrl_active;
168170
unsigned long mac_rx_frame_ctrl_fifo;
169171
unsigned long mac_gmii_rx_proto_engine;
172+
/* TSO */
173+
unsigned long tx_tso_frames;
174+
unsigned long tx_tso_nfrags;
170175
};
171176

172177
/* CSR Frequency Access Defines*/
@@ -243,6 +248,7 @@ enum rx_frame_status {
243248
csum_none = 0x2,
244249
llc_snap = 0x4,
245250
dma_own = 0x8,
251+
rx_not_ls = 0x10,
246252
};
247253

248254
/* Tx status */
@@ -269,6 +275,7 @@ enum dma_irq_status {
269275
#define CORE_PCS_ANE_COMPLETE (1 << 5)
270276
#define CORE_PCS_LINK_STATUS (1 << 6)
271277
#define CORE_RGMII_IRQ (1 << 7)
278+
#define CORE_IRQ_MTL_RX_OVERFLOW BIT(8)
272279

273280
/* Physical Coding Sublayer */
274281
struct rgmii_adv {
@@ -300,8 +307,10 @@ struct dma_features {
300307
/* 802.3az - Energy-Efficient Ethernet (EEE) */
301308
unsigned int eee;
302309
unsigned int av;
310+
unsigned int tsoen;
303311
/* TX and RX csum */
304312
unsigned int tx_coe;
313+
unsigned int rx_coe;
305314
unsigned int rx_coe_type1;
306315
unsigned int rx_coe_type2;
307316
unsigned int rxfifo_over_2048;
@@ -348,6 +357,10 @@ struct stmmac_desc_ops {
348357
void (*prepare_tx_desc) (struct dma_desc *p, int is_fs, int len,
349358
bool csum_flag, int mode, bool tx_own,
350359
bool ls);
360+
void (*prepare_tso_tx_desc)(struct dma_desc *p, int is_fs, int len1,
361+
int len2, bool tx_own, bool ls,
362+
unsigned int tcphdrlen,
363+
unsigned int tcppayloadlen);
351364
/* Set/get the owner of the descriptor */
352365
void (*set_tx_owner) (struct dma_desc *p);
353366
int (*get_tx_owner) (struct dma_desc *p);
@@ -380,6 +393,10 @@ struct stmmac_desc_ops {
380393
u64(*get_timestamp) (void *desc, u32 ats);
381394
/* get rx timestamp status */
382395
int (*get_rx_timestamp_status) (void *desc, u32 ats);
396+
/* Display ring */
397+
void (*display_ring)(void *head, unsigned int size, bool rx);
398+
/* set MSS via context descriptor */
399+
void (*set_mss)(struct dma_desc *p, unsigned int mss);
383400
};
384401

385402
extern const struct stmmac_desc_ops enh_desc_ops;
@@ -412,9 +429,15 @@ struct stmmac_dma_ops {
412429
int (*dma_interrupt) (void __iomem *ioaddr,
413430
struct stmmac_extra_stats *x);
414431
/* If supported then get the optional core features */
415-
unsigned int (*get_hw_feature) (void __iomem *ioaddr);
432+
void (*get_hw_feature)(void __iomem *ioaddr,
433+
struct dma_features *dma_cap);
416434
/* Program the HW RX Watchdog */
417435
void (*rx_watchdog) (void __iomem *ioaddr, u32 riwt);
436+
void (*set_tx_ring_len)(void __iomem *ioaddr, u32 len);
437+
void (*set_rx_ring_len)(void __iomem *ioaddr, u32 len);
438+
void (*set_rx_tail_ptr)(void __iomem *ioaddr, u32 tail_ptr, u32 chan);
439+
void (*set_tx_tail_ptr)(void __iomem *ioaddr, u32 tail_ptr, u32 chan);
440+
void (*enable_tso)(void __iomem *ioaddr, bool en, u32 chan);
418441
};
419442

420443
struct mac_device_info;
@@ -463,6 +486,7 @@ struct stmmac_hwtimestamp {
463486
};
464487

465488
extern const struct stmmac_hwtimestamp stmmac_ptp;
489+
extern const struct stmmac_mode_ops dwmac4_ring_mode_ops;
466490

467491
struct mac_link {
468492
int port;
@@ -495,7 +519,6 @@ struct mac_device_info {
495519
const struct stmmac_hwtimestamp *ptp;
496520
struct mii_regs mii; /* MII register Addresses */
497521
struct mac_link link;
498-
unsigned int synopsys_uid;
499522
void __iomem *pcsr; /* vpointer to device CSRs */
500523
int multicast_filter_bins;
501524
int unicast_filter_entries;
@@ -504,18 +527,47 @@ struct mac_device_info {
504527
};
505528

506529
struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
507-
int perfect_uc_entries);
508-
struct mac_device_info *dwmac100_setup(void __iomem *ioaddr);
530+
int perfect_uc_entries,
531+
int *synopsys_id);
532+
struct mac_device_info *dwmac100_setup(void __iomem *ioaddr, int *synopsys_id);
533+
struct mac_device_info *dwmac4_setup(void __iomem *ioaddr, int mcbins,
534+
int perfect_uc_entries, int *synopsys_id);
509535

510536
void stmmac_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
511537
unsigned int high, unsigned int low);
512538
void stmmac_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
513539
unsigned int high, unsigned int low);
514-
515540
void stmmac_set_mac(void __iomem *ioaddr, bool enable);
516541

542+
void stmmac_dwmac4_set_mac_addr(void __iomem *ioaddr, u8 addr[6],
543+
unsigned int high, unsigned int low);
544+
void stmmac_dwmac4_get_mac_addr(void __iomem *ioaddr, unsigned char *addr,
545+
unsigned int high, unsigned int low);
546+
void stmmac_dwmac4_set_mac(void __iomem *ioaddr, bool enable);
547+
517548
void dwmac_dma_flush_tx_fifo(void __iomem *ioaddr);
518549
extern const struct stmmac_mode_ops ring_mode_ops;
519550
extern const struct stmmac_mode_ops chain_mode_ops;
520-
551+
extern const struct stmmac_desc_ops dwmac4_desc_ops;
552+
553+
/**
554+
* stmmac_get_synopsys_id - return the SYINID.
555+
* @priv: driver private structure
556+
* Description: this simple function is to decode and return the SYINID
557+
* starting from the HW core register.
558+
*/
559+
static inline u32 stmmac_get_synopsys_id(u32 hwid)
560+
{
561+
/* Check Synopsys Id (not available on old chips) */
562+
if (likely(hwid)) {
563+
u32 uid = ((hwid & 0x0000ff00) >> 8);
564+
u32 synid = (hwid & 0x000000ff);
565+
566+
pr_info("stmmac - user ID: 0x%x, Synopsys ID: 0x%x\n",
567+
uid, synid);
568+
569+
return synid;
570+
}
571+
return 0;
572+
}
521573
#endif /* __COMMON_H__ */

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ static const struct stmmac_ops dwmac1000_ops = {
491491
};
492492

493493
struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
494-
int perfect_uc_entries)
494+
int perfect_uc_entries,
495+
int *synopsys_id)
495496
{
496497
struct mac_device_info *mac;
497498
u32 hwid = readl(ioaddr + GMAC_VERSION);
@@ -516,7 +517,9 @@ struct mac_device_info *dwmac1000_setup(void __iomem *ioaddr, int mcbins,
516517
mac->link.speed = GMAC_CONTROL_FES;
517518
mac->mii.addr = GMAC_MII_ADDR;
518519
mac->mii.data = GMAC_MII_DATA;
519-
mac->synopsys_uid = hwid;
520+
521+
/* Get and dump the chip ID */
522+
*synopsys_id = stmmac_get_synopsys_id(hwid);
520523

521524
return mac;
522525
}

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,40 @@ static void dwmac1000_dump_dma_regs(void __iomem *ioaddr)
215215
}
216216
}
217217

218-
static unsigned int dwmac1000_get_hw_feature(void __iomem *ioaddr)
218+
static void dwmac1000_get_hw_feature(void __iomem *ioaddr,
219+
struct dma_features *dma_cap)
219220
{
220-
return readl(ioaddr + DMA_HW_FEATURE);
221+
u32 hw_cap = readl(ioaddr + DMA_HW_FEATURE);
222+
223+
dma_cap->mbps_10_100 = (hw_cap & DMA_HW_FEAT_MIISEL);
224+
dma_cap->mbps_1000 = (hw_cap & DMA_HW_FEAT_GMIISEL) >> 1;
225+
dma_cap->half_duplex = (hw_cap & DMA_HW_FEAT_HDSEL) >> 2;
226+
dma_cap->hash_filter = (hw_cap & DMA_HW_FEAT_HASHSEL) >> 4;
227+
dma_cap->multi_addr = (hw_cap & DMA_HW_FEAT_ADDMAC) >> 5;
228+
dma_cap->pcs = (hw_cap & DMA_HW_FEAT_PCSSEL) >> 6;
229+
dma_cap->sma_mdio = (hw_cap & DMA_HW_FEAT_SMASEL) >> 8;
230+
dma_cap->pmt_remote_wake_up = (hw_cap & DMA_HW_FEAT_RWKSEL) >> 9;
231+
dma_cap->pmt_magic_frame = (hw_cap & DMA_HW_FEAT_MGKSEL) >> 10;
232+
/* MMC */
233+
dma_cap->rmon = (hw_cap & DMA_HW_FEAT_MMCSEL) >> 11;
234+
/* IEEE 1588-2002 */
235+
dma_cap->time_stamp =
236+
(hw_cap & DMA_HW_FEAT_TSVER1SEL) >> 12;
237+
/* IEEE 1588-2008 */
238+
dma_cap->atime_stamp = (hw_cap & DMA_HW_FEAT_TSVER2SEL) >> 13;
239+
/* 802.3az - Energy-Efficient Ethernet (EEE) */
240+
dma_cap->eee = (hw_cap & DMA_HW_FEAT_EEESEL) >> 14;
241+
dma_cap->av = (hw_cap & DMA_HW_FEAT_AVSEL) >> 15;
242+
/* TX and RX csum */
243+
dma_cap->tx_coe = (hw_cap & DMA_HW_FEAT_TXCOESEL) >> 16;
244+
dma_cap->rx_coe_type1 = (hw_cap & DMA_HW_FEAT_RXTYP1COE) >> 17;
245+
dma_cap->rx_coe_type2 = (hw_cap & DMA_HW_FEAT_RXTYP2COE) >> 18;
246+
dma_cap->rxfifo_over_2048 = (hw_cap & DMA_HW_FEAT_RXFIFOSIZE) >> 19;
247+
/* TX and RX number of channels */
248+
dma_cap->number_rx_channel = (hw_cap & DMA_HW_FEAT_RXCHCNT) >> 20;
249+
dma_cap->number_tx_channel = (hw_cap & DMA_HW_FEAT_TXCHCNT) >> 22;
250+
/* Alternate (enhanced) DESC mode */
251+
dma_cap->enh_desc = (hw_cap & DMA_HW_FEAT_ENHDESSEL) >> 24;
221252
}
222253

223254
static void dwmac1000_rx_watchdog(void __iomem *ioaddr, u32 riwt)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ static const struct stmmac_ops dwmac100_ops = {
173173
.get_umac_addr = dwmac100_get_umac_addr,
174174
};
175175

176-
struct mac_device_info *dwmac100_setup(void __iomem *ioaddr)
176+
struct mac_device_info *dwmac100_setup(void __iomem *ioaddr, int *synopsys_id)
177177
{
178178
struct mac_device_info *mac;
179179

@@ -192,7 +192,8 @@ struct mac_device_info *dwmac100_setup(void __iomem *ioaddr)
192192
mac->link.speed = 0;
193193
mac->mii.addr = MAC_MII_ADDR;
194194
mac->mii.data = MAC_MII_DATA;
195-
mac->synopsys_uid = 0;
195+
/* Synopsys Id is not available on old chips */
196+
*synopsys_id = 0;
196197

197198
return mac;
198199
}

0 commit comments

Comments
 (0)