Skip to content

Commit 4c9668d

Browse files
committed
Merge branch 'thunderx-cleanups'
Sunil Goutham says: ==================== net: thunderx: Miscellaneous cleanups This patch series contains contains couple of cleanup patches. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 6487428 + 668dda0 commit 4c9668d

File tree

2 files changed

+51
-148
lines changed

2 files changed

+51
-148
lines changed

drivers/net/ethernet/cavium/thunder/nicvf_queues.c

Lines changed: 49 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818
#include "q_struct.h"
1919
#include "nicvf_queues.h"
2020

21-
struct rbuf_info {
22-
struct page *page;
23-
void *data;
24-
u64 offset;
25-
};
26-
27-
#define GET_RBUF_INFO(x) ((struct rbuf_info *)(x - NICVF_RCV_BUF_ALIGN_BYTES))
28-
2921
/* Poll a register for a specific value */
3022
static int nicvf_poll_reg(struct nicvf *nic, int qidx,
3123
u64 reg, int bit_pos, int bits, int val)
@@ -86,8 +78,6 @@ static void nicvf_free_q_desc_mem(struct nicvf *nic, struct q_desc_mem *dmem)
8678
static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, gfp_t gfp,
8779
u32 buf_len, u64 **rbuf)
8880
{
89-
u64 data;
90-
struct rbuf_info *rinfo;
9181
int order = get_order(buf_len);
9282

9383
/* Check if request can be accomodated in previous allocated page */
@@ -113,46 +103,28 @@ static inline int nicvf_alloc_rcv_buffer(struct nicvf *nic, gfp_t gfp,
113103
nic->rb_page_offset = 0;
114104
}
115105

116-
data = (u64)page_address(nic->rb_page) + nic->rb_page_offset;
117-
118-
/* Align buffer addr to cache line i.e 128 bytes */
119-
rinfo = (struct rbuf_info *)(data + NICVF_RCV_BUF_ALIGN_LEN(data));
120-
/* Save page address for reference updation */
121-
rinfo->page = nic->rb_page;
122-
/* Store start address for later retrieval */
123-
rinfo->data = (void *)data;
124-
/* Store alignment offset */
125-
rinfo->offset = NICVF_RCV_BUF_ALIGN_LEN(data);
106+
*rbuf = (u64 *)((u64)page_address(nic->rb_page) + nic->rb_page_offset);
126107

127-
data += rinfo->offset;
128-
129-
/* Give next aligned address to hw for DMA */
130-
*rbuf = (u64 *)(data + NICVF_RCV_BUF_ALIGN_BYTES);
131108
return 0;
132109
}
133110

134-
/* Retrieve actual buffer start address and build skb for received packet */
111+
/* Build skb around receive buffer */
135112
static struct sk_buff *nicvf_rb_ptr_to_skb(struct nicvf *nic,
136113
u64 rb_ptr, int len)
137114
{
115+
void *data;
138116
struct sk_buff *skb;
139-
struct rbuf_info *rinfo;
140117

141-
rb_ptr = (u64)phys_to_virt(rb_ptr);
142-
/* Get buffer start address and alignment offset */
143-
rinfo = GET_RBUF_INFO(rb_ptr);
118+
data = phys_to_virt(rb_ptr);
144119

145120
/* Now build an skb to give to stack */
146-
skb = build_skb(rinfo->data, RCV_FRAG_LEN);
121+
skb = build_skb(data, RCV_FRAG_LEN);
147122
if (!skb) {
148-
put_page(rinfo->page);
123+
put_page(virt_to_page(data));
149124
return NULL;
150125
}
151126

152-
/* Set correct skb->data */
153-
skb_reserve(skb, rinfo->offset + NICVF_RCV_BUF_ALIGN_BYTES);
154-
155-
prefetch((void *)rb_ptr);
127+
prefetch(skb->data);
156128
return skb;
157129
}
158130

@@ -196,7 +168,6 @@ static void nicvf_free_rbdr(struct nicvf *nic, struct rbdr *rbdr)
196168
int head, tail;
197169
u64 buf_addr;
198170
struct rbdr_entry_t *desc;
199-
struct rbuf_info *rinfo;
200171

201172
if (!rbdr)
202173
return;
@@ -212,16 +183,14 @@ static void nicvf_free_rbdr(struct nicvf *nic, struct rbdr *rbdr)
212183
while (head != tail) {
213184
desc = GET_RBDR_DESC(rbdr, head);
214185
buf_addr = desc->buf_addr << NICVF_RCV_BUF_ALIGN;
215-
rinfo = GET_RBUF_INFO((u64)phys_to_virt(buf_addr));
216-
put_page(rinfo->page);
186+
put_page(virt_to_page(phys_to_virt(buf_addr)));
217187
head++;
218188
head &= (rbdr->dmem.q_len - 1);
219189
}
220190
/* Free SKB of tail desc */
221191
desc = GET_RBDR_DESC(rbdr, tail);
222192
buf_addr = desc->buf_addr << NICVF_RCV_BUF_ALIGN;
223-
rinfo = GET_RBUF_INFO((u64)phys_to_virt(buf_addr));
224-
put_page(rinfo->page);
193+
put_page(virt_to_page(phys_to_virt(buf_addr)));
225194

226195
/* Free RBDR ring */
227196
nicvf_free_q_desc_mem(nic, &rbdr->dmem);
@@ -1234,153 +1203,93 @@ struct sk_buff *nicvf_get_rcv_skb(struct nicvf *nic, struct cqe_rx_t *cqe_rx)
12341203
return skb;
12351204
}
12361205

1237-
/* Enable interrupt */
1238-
void nicvf_enable_intr(struct nicvf *nic, int int_type, int q_idx)
1206+
static u64 nicvf_int_type_to_mask(int int_type, int q_idx)
12391207
{
12401208
u64 reg_val;
12411209

1242-
reg_val = nicvf_reg_read(nic, NIC_VF_ENA_W1S);
1243-
12441210
switch (int_type) {
12451211
case NICVF_INTR_CQ:
1246-
reg_val |= ((1ULL << q_idx) << NICVF_INTR_CQ_SHIFT);
1212+
reg_val = ((1ULL << q_idx) << NICVF_INTR_CQ_SHIFT);
12471213
break;
12481214
case NICVF_INTR_SQ:
1249-
reg_val |= ((1ULL << q_idx) << NICVF_INTR_SQ_SHIFT);
1215+
reg_val = ((1ULL << q_idx) << NICVF_INTR_SQ_SHIFT);
12501216
break;
12511217
case NICVF_INTR_RBDR:
1252-
reg_val |= ((1ULL << q_idx) << NICVF_INTR_RBDR_SHIFT);
1218+
reg_val = ((1ULL << q_idx) << NICVF_INTR_RBDR_SHIFT);
12531219
break;
12541220
case NICVF_INTR_PKT_DROP:
1255-
reg_val |= (1ULL << NICVF_INTR_PKT_DROP_SHIFT);
1221+
reg_val = (1ULL << NICVF_INTR_PKT_DROP_SHIFT);
12561222
break;
12571223
case NICVF_INTR_TCP_TIMER:
1258-
reg_val |= (1ULL << NICVF_INTR_TCP_TIMER_SHIFT);
1224+
reg_val = (1ULL << NICVF_INTR_TCP_TIMER_SHIFT);
12591225
break;
12601226
case NICVF_INTR_MBOX:
1261-
reg_val |= (1ULL << NICVF_INTR_MBOX_SHIFT);
1227+
reg_val = (1ULL << NICVF_INTR_MBOX_SHIFT);
12621228
break;
12631229
case NICVF_INTR_QS_ERR:
1264-
reg_val |= (1ULL << NICVF_INTR_QS_ERR_SHIFT);
1230+
reg_val = (1ULL << NICVF_INTR_QS_ERR_SHIFT);
12651231
break;
12661232
default:
1267-
netdev_err(nic->netdev,
1268-
"Failed to enable interrupt: unknown type\n");
1269-
break;
1233+
reg_val = 0;
12701234
}
12711235

1272-
nicvf_reg_write(nic, NIC_VF_ENA_W1S, reg_val);
1236+
return reg_val;
1237+
}
1238+
1239+
/* Enable interrupt */
1240+
void nicvf_enable_intr(struct nicvf *nic, int int_type, int q_idx)
1241+
{
1242+
u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
1243+
1244+
if (!mask) {
1245+
netdev_dbg(nic->netdev,
1246+
"Failed to enable interrupt: unknown type\n");
1247+
return;
1248+
}
1249+
nicvf_reg_write(nic, NIC_VF_ENA_W1S,
1250+
nicvf_reg_read(nic, NIC_VF_ENA_W1S) | mask);
12731251
}
12741252

12751253
/* Disable interrupt */
12761254
void nicvf_disable_intr(struct nicvf *nic, int int_type, int q_idx)
12771255
{
1278-
u64 reg_val = 0;
1256+
u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
12791257

1280-
switch (int_type) {
1281-
case NICVF_INTR_CQ:
1282-
reg_val |= ((1ULL << q_idx) << NICVF_INTR_CQ_SHIFT);
1283-
break;
1284-
case NICVF_INTR_SQ:
1285-
reg_val |= ((1ULL << q_idx) << NICVF_INTR_SQ_SHIFT);
1286-
break;
1287-
case NICVF_INTR_RBDR:
1288-
reg_val |= ((1ULL << q_idx) << NICVF_INTR_RBDR_SHIFT);
1289-
break;
1290-
case NICVF_INTR_PKT_DROP:
1291-
reg_val |= (1ULL << NICVF_INTR_PKT_DROP_SHIFT);
1292-
break;
1293-
case NICVF_INTR_TCP_TIMER:
1294-
reg_val |= (1ULL << NICVF_INTR_TCP_TIMER_SHIFT);
1295-
break;
1296-
case NICVF_INTR_MBOX:
1297-
reg_val |= (1ULL << NICVF_INTR_MBOX_SHIFT);
1298-
break;
1299-
case NICVF_INTR_QS_ERR:
1300-
reg_val |= (1ULL << NICVF_INTR_QS_ERR_SHIFT);
1301-
break;
1302-
default:
1303-
netdev_err(nic->netdev,
1258+
if (!mask) {
1259+
netdev_dbg(nic->netdev,
13041260
"Failed to disable interrupt: unknown type\n");
1305-
break;
1261+
return;
13061262
}
13071263

1308-
nicvf_reg_write(nic, NIC_VF_ENA_W1C, reg_val);
1264+
nicvf_reg_write(nic, NIC_VF_ENA_W1C, mask);
13091265
}
13101266

13111267
/* Clear interrupt */
13121268
void nicvf_clear_intr(struct nicvf *nic, int int_type, int q_idx)
13131269
{
1314-
u64 reg_val = 0;
1270+
u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
13151271

1316-
switch (int_type) {
1317-
case NICVF_INTR_CQ:
1318-
reg_val = ((1ULL << q_idx) << NICVF_INTR_CQ_SHIFT);
1319-
break;
1320-
case NICVF_INTR_SQ:
1321-
reg_val = ((1ULL << q_idx) << NICVF_INTR_SQ_SHIFT);
1322-
break;
1323-
case NICVF_INTR_RBDR:
1324-
reg_val = ((1ULL << q_idx) << NICVF_INTR_RBDR_SHIFT);
1325-
break;
1326-
case NICVF_INTR_PKT_DROP:
1327-
reg_val = (1ULL << NICVF_INTR_PKT_DROP_SHIFT);
1328-
break;
1329-
case NICVF_INTR_TCP_TIMER:
1330-
reg_val = (1ULL << NICVF_INTR_TCP_TIMER_SHIFT);
1331-
break;
1332-
case NICVF_INTR_MBOX:
1333-
reg_val = (1ULL << NICVF_INTR_MBOX_SHIFT);
1334-
break;
1335-
case NICVF_INTR_QS_ERR:
1336-
reg_val |= (1ULL << NICVF_INTR_QS_ERR_SHIFT);
1337-
break;
1338-
default:
1339-
netdev_err(nic->netdev,
1272+
if (!mask) {
1273+
netdev_dbg(nic->netdev,
13401274
"Failed to clear interrupt: unknown type\n");
1341-
break;
1275+
return;
13421276
}
13431277

1344-
nicvf_reg_write(nic, NIC_VF_INT, reg_val);
1278+
nicvf_reg_write(nic, NIC_VF_INT, mask);
13451279
}
13461280

13471281
/* Check if interrupt is enabled */
13481282
int nicvf_is_intr_enabled(struct nicvf *nic, int int_type, int q_idx)
13491283
{
1350-
u64 reg_val;
1351-
u64 mask = 0xff;
1352-
1353-
reg_val = nicvf_reg_read(nic, NIC_VF_ENA_W1S);
1354-
1355-
switch (int_type) {
1356-
case NICVF_INTR_CQ:
1357-
mask = ((1ULL << q_idx) << NICVF_INTR_CQ_SHIFT);
1358-
break;
1359-
case NICVF_INTR_SQ:
1360-
mask = ((1ULL << q_idx) << NICVF_INTR_SQ_SHIFT);
1361-
break;
1362-
case NICVF_INTR_RBDR:
1363-
mask = ((1ULL << q_idx) << NICVF_INTR_RBDR_SHIFT);
1364-
break;
1365-
case NICVF_INTR_PKT_DROP:
1366-
mask = NICVF_INTR_PKT_DROP_MASK;
1367-
break;
1368-
case NICVF_INTR_TCP_TIMER:
1369-
mask = NICVF_INTR_TCP_TIMER_MASK;
1370-
break;
1371-
case NICVF_INTR_MBOX:
1372-
mask = NICVF_INTR_MBOX_MASK;
1373-
break;
1374-
case NICVF_INTR_QS_ERR:
1375-
mask = NICVF_INTR_QS_ERR_MASK;
1376-
break;
1377-
default:
1378-
netdev_err(nic->netdev,
1284+
u64 mask = nicvf_int_type_to_mask(int_type, q_idx);
1285+
/* If interrupt type is unknown, we treat it disabled. */
1286+
if (!mask) {
1287+
netdev_dbg(nic->netdev,
13791288
"Failed to check interrupt enable: unknown type\n");
1380-
break;
1289+
return 0;
13811290
}
13821291

1383-
return (reg_val & mask);
1292+
return mask & nicvf_reg_read(nic, NIC_VF_ENA_W1S);
13841293
}
13851294

13861295
void nicvf_update_rq_stats(struct nicvf *nic, int rq_idx)

drivers/net/ethernet/cavium/thunder/nicvf_queues.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,8 @@
8383
#define MAX_RCV_BUF_COUNT (1ULL << (RBDR_SIZE6 + 13))
8484
#define RBDR_THRESH (RCV_BUF_COUNT / 2)
8585
#define DMA_BUFFER_LEN 2048 /* In multiples of 128bytes */
86-
#define RCV_FRAG_LEN (SKB_DATA_ALIGN(DMA_BUFFER_LEN + NET_SKB_PAD) + \
87-
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + \
88-
(NICVF_RCV_BUF_ALIGN_BYTES * 2))
89-
#define RCV_DATA_OFFSET NICVF_RCV_BUF_ALIGN_BYTES
86+
#define RCV_FRAG_LEN (SKB_DATA_ALIGN(DMA_BUFFER_LEN + NET_SKB_PAD) + \
87+
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))
9088

9189
#define MAX_CQES_FOR_TX ((SND_QUEUE_LEN / MIN_SQ_DESC_PER_PKT_XMIT) * \
9290
MAX_CQE_PER_PKT_XMIT)
@@ -108,10 +106,6 @@
108106
#define NICVF_SQ_BASE_ALIGN_BYTES 128 /* 7 bits */
109107

110108
#define NICVF_ALIGNED_ADDR(ADDR, ALIGN_BYTES) ALIGN(ADDR, ALIGN_BYTES)
111-
#define NICVF_ADDR_ALIGN_LEN(ADDR, BYTES)\
112-
(NICVF_ALIGNED_ADDR(ADDR, BYTES) - BYTES)
113-
#define NICVF_RCV_BUF_ALIGN_LEN(X)\
114-
(NICVF_ALIGNED_ADDR(X, NICVF_RCV_BUF_ALIGN_BYTES) - X)
115109

116110
/* Queue enable/disable */
117111
#define NICVF_SQ_EN BIT_ULL(19)

0 commit comments

Comments
 (0)