Skip to content

Commit 201c78e

Browse files
committed
Merge branch 'macb-rx-packet-filtering'
Rafal Ozieblo says: ==================== Receive packets filtering for macb driver This patch series adds support for receive packets filtering for Cadence GEM driver. Packets can be redirect to different hardware queues based on source IP, destination IP, source port or destination port. To enable filtering, support for RX queueing was added as well. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 7475908 + ae8223d commit 201c78e

File tree

2 files changed

+699
-146
lines changed

2 files changed

+699
-146
lines changed

drivers/net/ethernet/cadence/macb.h

Lines changed: 155 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,38 @@
164164
#define GEM_DCFG5 0x0290 /* Design Config 5 */
165165
#define GEM_DCFG6 0x0294 /* Design Config 6 */
166166
#define GEM_DCFG7 0x0298 /* Design Config 7 */
167+
#define GEM_DCFG8 0x029C /* Design Config 8 */
167168

168169
#define GEM_TXBDCTRL 0x04cc /* TX Buffer Descriptor control register */
169170
#define GEM_RXBDCTRL 0x04d0 /* RX Buffer Descriptor control register */
170171

172+
/* Screener Type 2 match registers */
173+
#define GEM_SCRT2 0x540
174+
175+
/* EtherType registers */
176+
#define GEM_ETHT 0x06E0
177+
178+
/* Type 2 compare registers */
179+
#define GEM_T2CMPW0 0x0700
180+
#define GEM_T2CMPW1 0x0704
181+
#define T2CMP_OFST(t2idx) (t2idx * 2)
182+
183+
/* type 2 compare registers
184+
* each location requires 3 compare regs
185+
*/
186+
#define GEM_IP4SRC_CMP(idx) (idx * 3)
187+
#define GEM_IP4DST_CMP(idx) (idx * 3 + 1)
188+
#define GEM_PORT_CMP(idx) (idx * 3 + 2)
189+
190+
/* Which screening type 2 EtherType register will be used (0 - 7) */
191+
#define SCRT2_ETHT 0
192+
171193
#define GEM_ISR(hw_q) (0x0400 + ((hw_q) << 2))
172194
#define GEM_TBQP(hw_q) (0x0440 + ((hw_q) << 2))
173195
#define GEM_TBQPH(hw_q) (0x04C8)
174196
#define GEM_RBQP(hw_q) (0x0480 + ((hw_q) << 2))
197+
#define GEM_RBQS(hw_q) (0x04A0 + ((hw_q) << 2))
198+
#define GEM_RBQPH(hw_q) (0x04D4)
175199
#define GEM_IER(hw_q) (0x0600 + ((hw_q) << 2))
176200
#define GEM_IDR(hw_q) (0x0620 + ((hw_q) << 2))
177201
#define GEM_IMR(hw_q) (0x0640 + ((hw_q) << 2))
@@ -455,6 +479,16 @@
455479
#define GEM_DAW64_OFFSET 23
456480
#define GEM_DAW64_SIZE 1
457481

482+
/* Bitfields in DCFG8. */
483+
#define GEM_T1SCR_OFFSET 24
484+
#define GEM_T1SCR_SIZE 8
485+
#define GEM_T2SCR_OFFSET 16
486+
#define GEM_T2SCR_SIZE 8
487+
#define GEM_SCR2ETH_OFFSET 8
488+
#define GEM_SCR2ETH_SIZE 8
489+
#define GEM_SCR2CMP_OFFSET 0
490+
#define GEM_SCR2CMP_SIZE 8
491+
458492
/* Bitfields in TISUBN */
459493
#define GEM_SUBNSINCR_OFFSET 0
460494
#define GEM_SUBNSINCR_SIZE 16
@@ -483,6 +517,66 @@
483517
#define GEM_RXTSMODE_OFFSET 4 /* RX Descriptor Timestamp Insertion mode */
484518
#define GEM_RXTSMODE_SIZE 2
485519

520+
/* Bitfields in SCRT2 */
521+
#define GEM_QUEUE_OFFSET 0 /* Queue Number */
522+
#define GEM_QUEUE_SIZE 4
523+
#define GEM_VLANPR_OFFSET 4 /* VLAN Priority */
524+
#define GEM_VLANPR_SIZE 3
525+
#define GEM_VLANEN_OFFSET 8 /* VLAN Enable */
526+
#define GEM_VLANEN_SIZE 1
527+
#define GEM_ETHT2IDX_OFFSET 9 /* Index to screener type 2 EtherType register */
528+
#define GEM_ETHT2IDX_SIZE 3
529+
#define GEM_ETHTEN_OFFSET 12 /* EtherType Enable */
530+
#define GEM_ETHTEN_SIZE 1
531+
#define GEM_CMPA_OFFSET 13 /* Compare A - Index to screener type 2 Compare register */
532+
#define GEM_CMPA_SIZE 5
533+
#define GEM_CMPAEN_OFFSET 18 /* Compare A Enable */
534+
#define GEM_CMPAEN_SIZE 1
535+
#define GEM_CMPB_OFFSET 19 /* Compare B - Index to screener type 2 Compare register */
536+
#define GEM_CMPB_SIZE 5
537+
#define GEM_CMPBEN_OFFSET 24 /* Compare B Enable */
538+
#define GEM_CMPBEN_SIZE 1
539+
#define GEM_CMPC_OFFSET 25 /* Compare C - Index to screener type 2 Compare register */
540+
#define GEM_CMPC_SIZE 5
541+
#define GEM_CMPCEN_OFFSET 30 /* Compare C Enable */
542+
#define GEM_CMPCEN_SIZE 1
543+
544+
/* Bitfields in ETHT */
545+
#define GEM_ETHTCMP_OFFSET 0 /* EtherType compare value */
546+
#define GEM_ETHTCMP_SIZE 16
547+
548+
/* Bitfields in T2CMPW0 */
549+
#define GEM_T2CMP_OFFSET 16 /* 0xFFFF0000 compare value */
550+
#define GEM_T2CMP_SIZE 16
551+
#define GEM_T2MASK_OFFSET 0 /* 0x0000FFFF compare value or mask */
552+
#define GEM_T2MASK_SIZE 16
553+
554+
/* Bitfields in T2CMPW1 */
555+
#define GEM_T2DISMSK_OFFSET 9 /* disable mask */
556+
#define GEM_T2DISMSK_SIZE 1
557+
#define GEM_T2CMPOFST_OFFSET 7 /* compare offset */
558+
#define GEM_T2CMPOFST_SIZE 2
559+
#define GEM_T2OFST_OFFSET 0 /* offset value */
560+
#define GEM_T2OFST_SIZE 7
561+
562+
/* Offset for screener type 2 compare values (T2CMPOFST).
563+
* Note the offset is applied after the specified point,
564+
* e.g. GEM_T2COMPOFST_ETYPE denotes the EtherType field, so an offset
565+
* of 12 bytes from this would be the source IP address in an IP header
566+
*/
567+
#define GEM_T2COMPOFST_SOF 0
568+
#define GEM_T2COMPOFST_ETYPE 1
569+
#define GEM_T2COMPOFST_IPHDR 2
570+
#define GEM_T2COMPOFST_TCPUDP 3
571+
572+
/* offset from EtherType to IP address */
573+
#define ETYPE_SRCIP_OFFSET 12
574+
#define ETYPE_DSTIP_OFFSET 16
575+
576+
/* offset from IP header to port */
577+
#define IPHDR_SRCPORT_OFFSET 0
578+
#define IPHDR_DSTPORT_OFFSET 2
579+
486580
/* Transmit DMA buffer descriptor Word 1 */
487581
#define GEM_DMA_TXVALID_OFFSET 23 /* timestamp has been captured in the Buffer Descriptor */
488582
#define GEM_DMA_TXVALID_SIZE 1
@@ -583,6 +677,8 @@
583677
#define gem_writel(port, reg, value) (port)->macb_reg_writel((port), GEM_##reg, (value))
584678
#define queue_readl(queue, reg) (queue)->bp->macb_reg_readl((queue)->bp, (queue)->reg)
585679
#define queue_writel(queue, reg, value) (queue)->bp->macb_reg_writel((queue)->bp, (queue)->reg, (value))
680+
#define gem_readl_n(port, reg, idx) (port)->macb_reg_readl((port), GEM_##reg + idx * 4)
681+
#define gem_writel_n(port, reg, idx, value) (port)->macb_reg_writel((port), GEM_##reg + idx * 4, (value))
586682

587683
#define PTP_TS_BUFFER_SIZE 128 /* must be power of 2 */
588684

@@ -920,13 +1016,42 @@ static const struct gem_statistic gem_statistics[] = {
9201016

9211017
#define GEM_STATS_LEN ARRAY_SIZE(gem_statistics)
9221018

1019+
#define QUEUE_STAT_TITLE(title) { \
1020+
.stat_string = title, \
1021+
}
1022+
1023+
/* per queue statistics, each should be unsigned long type */
1024+
struct queue_stats {
1025+
union {
1026+
unsigned long first;
1027+
unsigned long rx_packets;
1028+
};
1029+
unsigned long rx_bytes;
1030+
unsigned long rx_dropped;
1031+
unsigned long tx_packets;
1032+
unsigned long tx_bytes;
1033+
unsigned long tx_dropped;
1034+
};
1035+
1036+
static const struct gem_statistic queue_statistics[] = {
1037+
QUEUE_STAT_TITLE("rx_packets"),
1038+
QUEUE_STAT_TITLE("rx_bytes"),
1039+
QUEUE_STAT_TITLE("rx_dropped"),
1040+
QUEUE_STAT_TITLE("tx_packets"),
1041+
QUEUE_STAT_TITLE("tx_bytes"),
1042+
QUEUE_STAT_TITLE("tx_dropped"),
1043+
};
1044+
1045+
#define QUEUE_STATS_LEN ARRAY_SIZE(queue_statistics)
1046+
9231047
struct macb;
1048+
struct macb_queue;
9241049

9251050
struct macb_or_gem_ops {
9261051
int (*mog_alloc_rx_buffers)(struct macb *bp);
9271052
void (*mog_free_rx_buffers)(struct macb *bp);
9281053
void (*mog_init_rings)(struct macb *bp);
929-
int (*mog_rx)(struct macb *bp, int budget);
1054+
int (*mog_rx)(struct macb_queue *queue, int budget);
9301055
};
9311056

9321057
/* MACB-PTP interface: adapt to platform needs. */
@@ -968,20 +1093,43 @@ struct macb_queue {
9681093
unsigned int IMR;
9691094
unsigned int TBQP;
9701095
unsigned int TBQPH;
1096+
unsigned int RBQS;
1097+
unsigned int RBQP;
1098+
unsigned int RBQPH;
9711099

9721100
unsigned int tx_head, tx_tail;
9731101
struct macb_dma_desc *tx_ring;
9741102
struct macb_tx_skb *tx_skb;
9751103
dma_addr_t tx_ring_dma;
9761104
struct work_struct tx_error_task;
9771105

1106+
dma_addr_t rx_ring_dma;
1107+
dma_addr_t rx_buffers_dma;
1108+
unsigned int rx_tail;
1109+
unsigned int rx_prepared_head;
1110+
struct macb_dma_desc *rx_ring;
1111+
struct sk_buff **rx_skbuff;
1112+
void *rx_buffers;
1113+
struct napi_struct napi;
1114+
struct queue_stats stats;
1115+
9781116
#ifdef CONFIG_MACB_USE_HWSTAMP
9791117
struct work_struct tx_ts_task;
9801118
unsigned int tx_ts_head, tx_ts_tail;
9811119
struct gem_tx_ts tx_timestamps[PTP_TS_BUFFER_SIZE];
9821120
#endif
9831121
};
9841122

1123+
struct ethtool_rx_fs_item {
1124+
struct ethtool_rx_flow_spec fs;
1125+
struct list_head list;
1126+
};
1127+
1128+
struct ethtool_rx_fs_list {
1129+
struct list_head list;
1130+
unsigned int count;
1131+
};
1132+
9851133
struct macb {
9861134
void __iomem *regs;
9871135
bool native_io;
@@ -990,11 +1138,6 @@ struct macb {
9901138
u32 (*macb_reg_readl)(struct macb *bp, int offset);
9911139
void (*macb_reg_writel)(struct macb *bp, int offset, u32 value);
9921140

993-
unsigned int rx_tail;
994-
unsigned int rx_prepared_head;
995-
struct macb_dma_desc *rx_ring;
996-
struct sk_buff **rx_skbuff;
997-
void *rx_buffers;
9981141
size_t rx_buffer_size;
9991142

10001143
unsigned int rx_ring_size;
@@ -1011,15 +1154,11 @@ struct macb {
10111154
struct clk *tx_clk;
10121155
struct clk *rx_clk;
10131156
struct net_device *dev;
1014-
struct napi_struct napi;
10151157
union {
10161158
struct macb_stats macb;
10171159
struct gem_stats gem;
10181160
} hw_stats;
10191161

1020-
dma_addr_t rx_ring_dma;
1021-
dma_addr_t rx_buffers_dma;
1022-
10231162
struct macb_or_gem_ops macbgem_ops;
10241163

10251164
struct mii_bus *mii_bus;
@@ -1040,7 +1179,7 @@ struct macb {
10401179
int skb_length; /* saved skb length for pci_unmap_single */
10411180
unsigned int max_tx_length;
10421181

1043-
u64 ethtool_stats[GEM_STATS_LEN];
1182+
u64 ethtool_stats[GEM_STATS_LEN + QUEUE_STATS_LEN * MACB_MAX_QUEUES];
10441183

10451184
unsigned int rx_frm_len_mask;
10461185
unsigned int jumbo_max_len;
@@ -1057,6 +1196,11 @@ struct macb {
10571196
struct ptp_clock_info ptp_clock_info;
10581197
struct tsu_incr tsu_incr;
10591198
struct hwtstamp_config tstamp_config;
1199+
1200+
/* RX queue filer rule set*/
1201+
struct ethtool_rx_fs_list rx_fs_list;
1202+
spinlock_t rx_fs_lock;
1203+
unsigned int max_tuples;
10601204
};
10611205

10621206
#ifdef CONFIG_MACB_USE_HWSTAMP

0 commit comments

Comments
 (0)