2018-01-11 10:08:44 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2015-04-04 19:51:21 +00:00
|
|
|
/*
|
|
|
|
* This file is based on code from OCTEON SDK by Cavium Networks.
|
2009-05-06 00:35:21 +00:00
|
|
|
*
|
2010-01-07 19:05:04 +00:00
|
|
|
* Copyright (c) 2003-2010 Cavium Networks
|
2015-04-04 19:51:21 +00:00
|
|
|
*/
|
|
|
|
|
2009-05-06 00:35:21 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/cache.h>
|
2010-01-07 19:05:04 +00:00
|
|
|
#include <linux/cpumask.h>
|
2009-05-06 00:35:21 +00:00
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/etherdevice.h>
|
|
|
|
#include <linux/ip.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/prefetch.h>
|
2011-06-04 15:35:58 +00:00
|
|
|
#include <linux/ratelimit.h>
|
2010-01-07 19:05:04 +00:00
|
|
|
#include <linux/smp.h>
|
2012-04-19 10:27:27 +00:00
|
|
|
#include <linux/interrupt.h>
|
2009-05-06 00:35:21 +00:00
|
|
|
#include <net/dst.h>
|
|
|
|
#ifdef CONFIG_XFRM
|
|
|
|
#include <linux/xfrm.h>
|
|
|
|
#include <net/xfrm.h>
|
|
|
|
#endif /* CONFIG_XFRM */
|
|
|
|
|
|
|
|
#include <asm/octeon/octeon.h>
|
|
|
|
|
|
|
|
#include "ethernet-defines.h"
|
|
|
|
#include "ethernet-mem.h"
|
2010-01-07 19:05:04 +00:00
|
|
|
#include "ethernet-rx.h"
|
|
|
|
#include "octeon-ethernet.h"
|
2009-05-06 00:35:21 +00:00
|
|
|
#include "ethernet-util.h"
|
|
|
|
|
2011-11-22 14:47:00 +00:00
|
|
|
#include <asm/octeon/cvmx-helper.h>
|
|
|
|
#include <asm/octeon/cvmx-wqe.h>
|
|
|
|
#include <asm/octeon/cvmx-fau.h>
|
|
|
|
#include <asm/octeon/cvmx-pow.h>
|
|
|
|
#include <asm/octeon/cvmx-pip.h>
|
|
|
|
#include <asm/octeon/cvmx-scratch.h>
|
2009-05-06 00:35:21 +00:00
|
|
|
|
2011-11-22 14:47:00 +00:00
|
|
|
#include <asm/octeon/cvmx-gmxx-defs.h>
|
2009-05-06 00:35:21 +00:00
|
|
|
|
2016-08-31 20:57:46 +00:00
|
|
|
static atomic_t oct_rx_ready = ATOMIC_INIT(0);
|
|
|
|
|
2016-08-31 20:57:40 +00:00
|
|
|
static struct oct_rx_group {
|
2016-08-31 20:57:41 +00:00
|
|
|
int irq;
|
2016-08-31 20:57:42 +00:00
|
|
|
int group;
|
2016-08-31 20:57:40 +00:00
|
|
|
struct napi_struct napi;
|
2016-08-31 20:57:43 +00:00
|
|
|
} oct_rx_group[16];
|
2009-05-06 00:35:21 +00:00
|
|
|
|
|
|
|
/**
|
2010-02-17 01:25:32 +00:00
|
|
|
* cvm_oct_do_interrupt - interrupt handler.
|
2016-08-31 20:57:37 +00:00
|
|
|
* @irq: Interrupt number.
|
2016-08-31 20:57:38 +00:00
|
|
|
* @napi_id: Cookie to identify the NAPI instance.
|
2010-02-17 01:25:32 +00:00
|
|
|
*
|
|
|
|
* The interrupt occurs whenever the POW has packets in our group.
|
2009-05-06 00:35:21 +00:00
|
|
|
*
|
|
|
|
*/
|
2016-08-31 20:57:38 +00:00
|
|
|
static irqreturn_t cvm_oct_do_interrupt(int irq, void *napi_id)
|
2009-05-06 00:35:21 +00:00
|
|
|
{
|
2010-01-07 19:05:04 +00:00
|
|
|
/* Disable the IRQ and start napi_poll. */
|
2016-08-31 20:57:37 +00:00
|
|
|
disable_irq_nosync(irq);
|
2016-08-31 20:57:38 +00:00
|
|
|
napi_schedule(napi_id);
|
2010-01-07 19:05:04 +00:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
2009-05-06 00:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-02-17 01:25:32 +00:00
|
|
|
* cvm_oct_check_rcv_error - process receive errors
|
2009-05-06 00:35:21 +00:00
|
|
|
* @work: Work queue entry pointing to the packet.
|
2010-02-17 01:25:32 +00:00
|
|
|
*
|
2009-05-06 00:35:21 +00:00
|
|
|
* Returns Non-zero if the packet can be dropped, zero otherwise.
|
|
|
|
*/
|
|
|
|
static inline int cvm_oct_check_rcv_error(cvmx_wqe_t *work)
|
|
|
|
{
|
2015-08-13 13:21:42 +00:00
|
|
|
int port;
|
|
|
|
|
|
|
|
if (octeon_has_feature(OCTEON_FEATURE_PKND))
|
|
|
|
port = work->word0.pip.cn68xx.pknd;
|
|
|
|
else
|
|
|
|
port = work->word1.cn38xx.ipprt;
|
|
|
|
|
|
|
|
if ((work->word2.snoip.err_code == 10) && (work->word1.len <= 64)) {
|
2009-05-06 00:35:21 +00:00
|
|
|
/*
|
|
|
|
* Ignore length errors on min size packets. Some
|
|
|
|
* equipment incorrectly pads packets to 64+4FCS
|
|
|
|
* instead of 60+4FCS. Note these packets still get
|
|
|
|
* counted as frame errors.
|
|
|
|
*/
|
2015-04-04 19:51:15 +00:00
|
|
|
} else if (work->word2.snoip.err_code == 5 ||
|
|
|
|
work->word2.snoip.err_code == 7) {
|
2009-05-06 00:35:21 +00:00
|
|
|
/*
|
|
|
|
* We received a packet with either an alignment error
|
|
|
|
* or a FCS error. This may be signalling that we are
|
2012-03-27 04:34:18 +00:00
|
|
|
* running 10Mbps with GMXX_RXX_FRM_CTL[PRE_CHK]
|
2009-05-06 00:35:21 +00:00
|
|
|
* off. If this is the case we need to parse the
|
|
|
|
* packet to determine if we can remove a non spec
|
|
|
|
* preamble and generate a correct packet.
|
|
|
|
*/
|
2015-08-13 13:21:42 +00:00
|
|
|
int interface = cvmx_helper_get_interface_num(port);
|
|
|
|
int index = cvmx_helper_get_interface_index_num(port);
|
2009-05-06 00:35:21 +00:00
|
|
|
union cvmx_gmxx_rxx_frm_ctl gmxx_rxx_frm_ctl;
|
2014-12-04 13:02:23 +00:00
|
|
|
|
2009-05-06 00:35:21 +00:00
|
|
|
gmxx_rxx_frm_ctl.u64 =
|
|
|
|
cvmx_read_csr(CVMX_GMXX_RXX_FRM_CTL(index, interface));
|
|
|
|
if (gmxx_rxx_frm_ctl.s.pre_chk == 0) {
|
2015-10-01 13:42:16 +00:00
|
|
|
u8 *ptr =
|
2009-05-06 00:35:21 +00:00
|
|
|
cvmx_phys_to_ptr(work->packet_ptr.s.addr);
|
|
|
|
int i = 0;
|
|
|
|
|
2015-08-13 13:21:42 +00:00
|
|
|
while (i < work->word1.len - 1) {
|
2009-05-06 00:35:21 +00:00
|
|
|
if (*ptr != 0x55)
|
|
|
|
break;
|
|
|
|
ptr++;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*ptr == 0xd5) {
|
2016-02-27 23:43:52 +00:00
|
|
|
/* Port received 0xd5 preamble */
|
2009-05-06 00:35:21 +00:00
|
|
|
work->packet_ptr.s.addr += i + 1;
|
2015-08-13 13:21:42 +00:00
|
|
|
work->word1.len -= i + 5;
|
2009-05-06 00:35:21 +00:00
|
|
|
} else if ((*ptr & 0xf) == 0xd) {
|
2016-02-27 23:43:52 +00:00
|
|
|
/* Port received 0xd preamble */
|
2009-05-06 00:35:21 +00:00
|
|
|
work->packet_ptr.s.addr += i;
|
2015-08-13 13:21:42 +00:00
|
|
|
work->word1.len -= i + 4;
|
|
|
|
for (i = 0; i < work->word1.len; i++) {
|
2009-05-06 00:35:21 +00:00
|
|
|
*ptr =
|
|
|
|
((*ptr & 0xf0) >> 4) |
|
|
|
|
((*(ptr + 1) & 0xf) << 4);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
} else {
|
2014-09-30 19:12:23 +00:00
|
|
|
printk_ratelimited("Port %d unknown preamble, packet dropped\n",
|
2015-08-13 13:21:42 +00:00
|
|
|
port);
|
2009-05-06 00:35:21 +00:00
|
|
|
cvm_oct_free_work(work);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2011-06-04 15:35:58 +00:00
|
|
|
printk_ratelimited("Port %d receive error code %d, packet dropped\n",
|
2015-08-13 13:21:42 +00:00
|
|
|
port, work->word2.snoip.err_code);
|
2009-05-06 00:35:21 +00:00
|
|
|
cvm_oct_free_work(work);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-08-01 07:51:12 +00:00
|
|
|
static void copy_segments_to_skb(cvmx_wqe_t *work, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
int segments = work->word2.s.bufs;
|
|
|
|
union cvmx_buf_ptr segment_ptr = work->packet_ptr;
|
|
|
|
int len = work->word1.len;
|
|
|
|
int segment_size;
|
|
|
|
|
|
|
|
while (segments--) {
|
|
|
|
union cvmx_buf_ptr next_ptr;
|
|
|
|
|
|
|
|
next_ptr = *(union cvmx_buf_ptr *)
|
|
|
|
cvmx_phys_to_ptr(segment_ptr.s.addr - 8);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Octeon Errata PKI-100: The segment size is wrong.
|
|
|
|
*
|
|
|
|
* Until it is fixed, calculate the segment size based on
|
|
|
|
* the packet pool buffer size.
|
|
|
|
* When it is fixed, the following line should be replaced
|
|
|
|
* with this one:
|
|
|
|
* int segment_size = segment_ptr.s.size;
|
|
|
|
*/
|
|
|
|
segment_size =
|
|
|
|
CVMX_FPA_PACKET_POOL_SIZE -
|
|
|
|
(segment_ptr.s.addr -
|
|
|
|
(((segment_ptr.s.addr >> 7) -
|
|
|
|
segment_ptr.s.back) << 7));
|
|
|
|
|
|
|
|
/* Don't copy more than what is left in the packet */
|
|
|
|
if (segment_size > len)
|
|
|
|
segment_size = len;
|
|
|
|
|
|
|
|
/* Copy the data into the packet */
|
|
|
|
skb_put_data(skb, cvmx_phys_to_ptr(segment_ptr.s.addr),
|
|
|
|
segment_size);
|
|
|
|
len -= segment_size;
|
|
|
|
segment_ptr = next_ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 20:57:42 +00:00
|
|
|
static int cvm_oct_poll(struct oct_rx_group *rx_group, int budget)
|
2009-05-06 00:35:21 +00:00
|
|
|
{
|
2010-01-07 19:05:04 +00:00
|
|
|
const int coreid = cvmx_get_core_num();
|
2015-10-01 13:42:16 +00:00
|
|
|
u64 old_group_mask;
|
|
|
|
u64 old_scratch;
|
2010-01-07 19:05:04 +00:00
|
|
|
int rx_count = 0;
|
|
|
|
int did_work_request = 0;
|
|
|
|
int packet_not_copied;
|
2009-05-06 00:35:21 +00:00
|
|
|
|
|
|
|
/* Prefetch cvm_oct_device since we know we need it soon */
|
|
|
|
prefetch(cvm_oct_device);
|
|
|
|
|
|
|
|
if (USE_ASYNC_IOBDMA) {
|
|
|
|
/* Save scratch in case userspace is using it */
|
|
|
|
CVMX_SYNCIOBDMA;
|
|
|
|
old_scratch = cvmx_scratch_read64(CVMX_SCR_SCRATCH);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only allow work for our group (and preserve priorities) */
|
2015-08-13 13:21:40 +00:00
|
|
|
if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
|
|
|
|
old_group_mask = cvmx_read_csr(CVMX_SSO_PPX_GRP_MSK(coreid));
|
|
|
|
cvmx_write_csr(CVMX_SSO_PPX_GRP_MSK(coreid),
|
2016-08-31 20:57:42 +00:00
|
|
|
BIT(rx_group->group));
|
2015-08-13 13:21:40 +00:00
|
|
|
cvmx_read_csr(CVMX_SSO_PPX_GRP_MSK(coreid)); /* Flush */
|
|
|
|
} else {
|
|
|
|
old_group_mask = cvmx_read_csr(CVMX_POW_PP_GRP_MSKX(coreid));
|
|
|
|
cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid),
|
2016-03-12 15:35:30 +00:00
|
|
|
(old_group_mask & ~0xFFFFull) |
|
2016-08-31 20:57:42 +00:00
|
|
|
BIT(rx_group->group));
|
2015-08-13 13:21:40 +00:00
|
|
|
}
|
2009-05-06 00:35:21 +00:00
|
|
|
|
2010-01-07 19:05:04 +00:00
|
|
|
if (USE_ASYNC_IOBDMA) {
|
2009-05-06 00:35:21 +00:00
|
|
|
cvmx_pow_work_request_async(CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT);
|
2010-01-07 19:05:04 +00:00
|
|
|
did_work_request = 1;
|
|
|
|
}
|
2009-05-06 00:35:21 +00:00
|
|
|
|
2010-01-07 19:05:04 +00:00
|
|
|
while (rx_count < budget) {
|
2009-05-06 00:35:21 +00:00
|
|
|
struct sk_buff *skb = NULL;
|
2010-01-07 19:05:04 +00:00
|
|
|
struct sk_buff **pskb = NULL;
|
2009-05-06 00:35:21 +00:00
|
|
|
int skb_in_hw;
|
|
|
|
cvmx_wqe_t *work;
|
2015-08-13 13:21:42 +00:00
|
|
|
int port;
|
2009-05-06 00:35:21 +00:00
|
|
|
|
2010-01-07 19:05:04 +00:00
|
|
|
if (USE_ASYNC_IOBDMA && did_work_request)
|
2009-05-06 00:35:21 +00:00
|
|
|
work = cvmx_pow_work_response_async(CVMX_SCR_SCRATCH);
|
2010-01-07 19:05:04 +00:00
|
|
|
else
|
|
|
|
work = cvmx_pow_work_request_sync(CVMX_POW_NO_WAIT);
|
|
|
|
|
2009-05-06 00:35:21 +00:00
|
|
|
prefetch(work);
|
2010-01-07 19:05:04 +00:00
|
|
|
did_work_request = 0;
|
2016-02-27 23:43:12 +00:00
|
|
|
if (!work) {
|
2015-08-13 13:21:39 +00:00
|
|
|
if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
|
|
|
|
cvmx_write_csr(CVMX_SSO_WQ_IQ_DIS,
|
2016-08-31 20:57:42 +00:00
|
|
|
BIT(rx_group->group));
|
2015-08-13 13:21:39 +00:00
|
|
|
cvmx_write_csr(CVMX_SSO_WQ_INT,
|
2016-08-31 20:57:42 +00:00
|
|
|
BIT(rx_group->group));
|
2015-08-13 13:21:39 +00:00
|
|
|
} else {
|
|
|
|
union cvmx_pow_wq_int wq_int;
|
2014-12-04 13:02:23 +00:00
|
|
|
|
2015-08-13 13:21:39 +00:00
|
|
|
wq_int.u64 = 0;
|
2016-08-31 20:57:42 +00:00
|
|
|
wq_int.s.iq_dis = BIT(rx_group->group);
|
|
|
|
wq_int.s.wq_int = BIT(rx_group->group);
|
2015-08-13 13:21:39 +00:00
|
|
|
cvmx_write_csr(CVMX_POW_WQ_INT, wq_int.u64);
|
|
|
|
}
|
2009-05-06 00:35:21 +00:00
|
|
|
break;
|
2010-01-07 19:05:04 +00:00
|
|
|
}
|
2016-02-27 23:45:13 +00:00
|
|
|
pskb = (struct sk_buff **)
|
|
|
|
(cvm_oct_get_buffer_ptr(work->packet_ptr) -
|
2014-11-28 13:34:29 +00:00
|
|
|
sizeof(void *));
|
2010-01-07 19:05:04 +00:00
|
|
|
prefetch(pskb);
|
2009-05-06 00:35:21 +00:00
|
|
|
|
2010-01-07 19:05:04 +00:00
|
|
|
if (USE_ASYNC_IOBDMA && rx_count < (budget - 1)) {
|
2014-11-28 13:34:29 +00:00
|
|
|
cvmx_pow_work_request_async_nocheck(CVMX_SCR_SCRATCH,
|
|
|
|
CVMX_POW_NO_WAIT);
|
2010-01-07 19:05:04 +00:00
|
|
|
did_work_request = 1;
|
|
|
|
}
|
2013-09-05 18:43:59 +00:00
|
|
|
rx_count++;
|
2009-05-06 00:35:21 +00:00
|
|
|
|
2015-04-04 19:51:17 +00:00
|
|
|
skb_in_hw = work->word2.s.bufs == 1;
|
2009-05-06 00:35:21 +00:00
|
|
|
if (likely(skb_in_hw)) {
|
2010-01-07 19:05:04 +00:00
|
|
|
skb = *pskb;
|
2009-05-06 00:35:21 +00:00
|
|
|
prefetch(&skb->head);
|
|
|
|
prefetch(&skb->len);
|
|
|
|
}
|
2015-08-13 13:21:42 +00:00
|
|
|
|
|
|
|
if (octeon_has_feature(OCTEON_FEATURE_PKND))
|
|
|
|
port = work->word0.pip.cn68xx.pknd;
|
|
|
|
else
|
|
|
|
port = work->word1.cn38xx.ipprt;
|
|
|
|
|
|
|
|
prefetch(cvm_oct_device[port]);
|
2009-05-06 00:35:21 +00:00
|
|
|
|
|
|
|
/* Immediately throw away all packets with receive errors */
|
|
|
|
if (unlikely(work->word2.snoip.rcv_error)) {
|
|
|
|
if (cvm_oct_check_rcv_error(work))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can only use the zero copy path if skbuffs are
|
|
|
|
* in the FPA pool and the packet fits in a single
|
|
|
|
* buffer.
|
|
|
|
*/
|
|
|
|
if (likely(skb_in_hw)) {
|
2014-11-28 13:34:29 +00:00
|
|
|
skb->data = skb->head + work->packet_ptr.s.addr -
|
|
|
|
cvmx_ptr_to_phys(skb->head);
|
2009-05-06 00:35:21 +00:00
|
|
|
prefetch(skb->data);
|
2015-08-13 13:21:42 +00:00
|
|
|
skb->len = work->word1.len;
|
2009-05-06 00:35:21 +00:00
|
|
|
skb_set_tail_pointer(skb, skb->len);
|
|
|
|
packet_not_copied = 1;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We have to copy the packet. First allocate
|
|
|
|
* an skbuff for it.
|
|
|
|
*/
|
2015-08-13 13:21:42 +00:00
|
|
|
skb = dev_alloc_skb(work->word1.len);
|
2009-05-06 00:35:21 +00:00
|
|
|
if (!skb) {
|
|
|
|
cvm_oct_free_work(work);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if we've received a packet that was
|
2010-01-07 19:05:01 +00:00
|
|
|
* entirely stored in the work entry.
|
2009-05-06 00:35:21 +00:00
|
|
|
*/
|
|
|
|
if (unlikely(work->word2.s.bufs == 0)) {
|
2015-10-01 13:42:16 +00:00
|
|
|
u8 *ptr = work->packet_data;
|
2009-05-06 00:35:21 +00:00
|
|
|
|
|
|
|
if (likely(!work->word2.s.not_IP)) {
|
|
|
|
/*
|
|
|
|
* The beginning of the packet
|
|
|
|
* moves for IP packets.
|
|
|
|
*/
|
|
|
|
if (work->word2.s.is_v6)
|
|
|
|
ptr += 2;
|
|
|
|
else
|
|
|
|
ptr += 6;
|
|
|
|
}
|
networking: introduce and use skb_put_data()
A common pattern with skb_put() is to just want to memcpy()
some data into the new space, introduce skb_put_data() for
this.
An spatch similar to the one for skb_put_zero() converts many
of the places using it:
@@
identifier p, p2;
expression len, skb, data;
type t, t2;
@@
(
-p = skb_put(skb, len);
+p = skb_put_data(skb, data, len);
|
-p = (t)skb_put(skb, len);
+p = skb_put_data(skb, data, len);
)
(
p2 = (t2)p;
-memcpy(p2, data, len);
|
-memcpy(p, data, len);
)
@@
type t, t2;
identifier p, p2;
expression skb, data;
@@
t *p;
...
(
-p = skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
|
-p = (t *)skb_put(skb, sizeof(t));
+p = skb_put_data(skb, data, sizeof(t));
)
(
p2 = (t2)p;
-memcpy(p2, data, sizeof(*p));
|
-memcpy(p, data, sizeof(*p));
)
@@
expression skb, len, data;
@@
-memcpy(skb_put(skb, len), data, len);
+skb_put_data(skb, data, len);
(again, manually post-processed to retain some comments)
Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2017-06-16 12:29:20 +00:00
|
|
|
skb_put_data(skb, ptr, work->word1.len);
|
2009-05-06 00:35:21 +00:00
|
|
|
/* No packet buffers to free */
|
|
|
|
} else {
|
2017-08-01 07:51:12 +00:00
|
|
|
copy_segments_to_skb(work, skb);
|
2009-05-06 00:35:21 +00:00
|
|
|
}
|
|
|
|
packet_not_copied = 0;
|
|
|
|
}
|
2015-08-13 13:21:42 +00:00
|
|
|
if (likely((port < TOTAL_NUMBER_OF_PORTS) &&
|
|
|
|
cvm_oct_device[port])) {
|
|
|
|
struct net_device *dev = cvm_oct_device[port];
|
2009-05-06 00:35:21 +00:00
|
|
|
|
2010-01-07 19:05:01 +00:00
|
|
|
/*
|
|
|
|
* Only accept packets for devices that are
|
|
|
|
* currently up.
|
|
|
|
*/
|
2009-05-06 00:35:21 +00:00
|
|
|
if (likely(dev->flags & IFF_UP)) {
|
|
|
|
skb->protocol = eth_type_trans(skb, dev);
|
|
|
|
skb->dev = dev;
|
|
|
|
|
2014-11-28 13:34:29 +00:00
|
|
|
if (unlikely(work->word2.s.not_IP ||
|
|
|
|
work->word2.s.IP_exc ||
|
|
|
|
work->word2.s.L4_error ||
|
|
|
|
!work->word2.s.tcp_or_udp))
|
2009-05-06 00:35:21 +00:00
|
|
|
skb->ip_summed = CHECKSUM_NONE;
|
|
|
|
else
|
|
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
|
|
|
|
|
|
|
/* Increment RX stats for virtual ports */
|
2015-08-13 13:21:42 +00:00
|
|
|
if (port >= CVMX_PIP_NUM_INPUT_PORTS) {
|
2017-02-15 12:51:10 +00:00
|
|
|
dev->stats.rx_packets++;
|
|
|
|
dev->stats.rx_bytes += skb->len;
|
2009-05-06 00:35:21 +00:00
|
|
|
}
|
|
|
|
netif_receive_skb(skb);
|
|
|
|
} else {
|
|
|
|
/*
|
2016-02-27 23:43:52 +00:00
|
|
|
* Drop any packet received for a device that
|
|
|
|
* isn't up.
|
|
|
|
*/
|
2017-02-15 12:51:10 +00:00
|
|
|
dev->stats.rx_dropped++;
|
2009-05-06 00:35:21 +00:00
|
|
|
dev_kfree_skb_irq(skb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Drop any packet received for a device that
|
|
|
|
* doesn't exist.
|
|
|
|
*/
|
2011-06-04 15:35:58 +00:00
|
|
|
printk_ratelimited("Port %d not controlled by Linux, packet dropped\n",
|
2016-03-12 15:35:30 +00:00
|
|
|
port);
|
2009-05-06 00:35:21 +00:00
|
|
|
dev_kfree_skb_irq(skb);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Check to see if the skbuff and work share the same
|
|
|
|
* packet buffer.
|
|
|
|
*/
|
2015-04-04 19:51:17 +00:00
|
|
|
if (likely(packet_not_copied)) {
|
2009-05-06 00:35:21 +00:00
|
|
|
/*
|
|
|
|
* This buffer needs to be replaced, increment
|
|
|
|
* the number of buffers we need to free by
|
|
|
|
* one.
|
|
|
|
*/
|
|
|
|
cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE,
|
|
|
|
1);
|
|
|
|
|
2015-04-04 19:51:19 +00:00
|
|
|
cvmx_fpa_free(work, CVMX_FPA_WQE_POOL, 1);
|
2009-05-06 00:35:21 +00:00
|
|
|
} else {
|
|
|
|
cvm_oct_free_work(work);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Restore the original POW group mask */
|
2015-08-13 13:21:40 +00:00
|
|
|
if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
|
|
|
|
cvmx_write_csr(CVMX_SSO_PPX_GRP_MSK(coreid), old_group_mask);
|
|
|
|
cvmx_read_csr(CVMX_SSO_PPX_GRP_MSK(coreid)); /* Flush */
|
|
|
|
} else {
|
|
|
|
cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid), old_group_mask);
|
|
|
|
}
|
|
|
|
|
2009-05-06 00:35:21 +00:00
|
|
|
if (USE_ASYNC_IOBDMA) {
|
|
|
|
/* Restore the scratch area */
|
|
|
|
cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch);
|
|
|
|
}
|
2010-01-07 19:05:04 +00:00
|
|
|
cvm_oct_rx_refill_pool(0);
|
2009-05-06 00:35:21 +00:00
|
|
|
|
2016-08-31 20:57:39 +00:00
|
|
|
return rx_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cvm_oct_napi_poll - the NAPI poll function.
|
|
|
|
* @napi: The NAPI instance.
|
|
|
|
* @budget: Maximum number of packets to receive.
|
|
|
|
*
|
|
|
|
* Returns the number of packets processed.
|
|
|
|
*/
|
|
|
|
static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
|
|
|
|
{
|
2016-08-31 20:57:41 +00:00
|
|
|
struct oct_rx_group *rx_group = container_of(napi, struct oct_rx_group,
|
|
|
|
napi);
|
2016-08-31 20:57:39 +00:00
|
|
|
int rx_count;
|
|
|
|
|
2016-08-31 20:57:42 +00:00
|
|
|
rx_count = cvm_oct_poll(rx_group, budget);
|
2016-08-31 20:57:39 +00:00
|
|
|
|
|
|
|
if (rx_count < budget) {
|
2010-01-07 19:05:04 +00:00
|
|
|
/* No more work */
|
2017-01-30 16:22:01 +00:00
|
|
|
napi_complete_done(napi, rx_count);
|
2016-08-31 20:57:41 +00:00
|
|
|
enable_irq(rx_group->irq);
|
2009-05-06 00:35:21 +00:00
|
|
|
}
|
2010-01-07 19:05:04 +00:00
|
|
|
return rx_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
|
|
/**
|
2010-02-17 01:25:32 +00:00
|
|
|
* cvm_oct_poll_controller - poll for receive packets
|
2010-01-07 19:05:04 +00:00
|
|
|
* device.
|
|
|
|
*
|
|
|
|
* @dev: Device to poll. Unused
|
|
|
|
*/
|
|
|
|
void cvm_oct_poll_controller(struct net_device *dev)
|
|
|
|
{
|
2016-08-31 20:57:43 +00:00
|
|
|
int i;
|
|
|
|
|
2016-08-31 20:57:46 +00:00
|
|
|
if (!atomic_read(&oct_rx_ready))
|
|
|
|
return;
|
|
|
|
|
2016-08-31 20:57:43 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(oct_rx_group); i++) {
|
|
|
|
if (!(pow_receive_groups & BIT(i)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
cvm_oct_poll(&oct_rx_group[i], 16);
|
|
|
|
}
|
2009-05-06 00:35:21 +00:00
|
|
|
}
|
2010-01-07 19:05:04 +00:00
|
|
|
#endif
|
2009-05-06 00:35:21 +00:00
|
|
|
|
|
|
|
void cvm_oct_rx_initialize(void)
|
|
|
|
{
|
|
|
|
int i;
|
2010-01-07 19:05:04 +00:00
|
|
|
struct net_device *dev_for_napi = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < TOTAL_NUMBER_OF_PORTS; i++) {
|
|
|
|
if (cvm_oct_device[i]) {
|
|
|
|
dev_for_napi = cvm_oct_device[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-27 23:43:12 +00:00
|
|
|
if (!dev_for_napi)
|
2010-01-07 19:05:04 +00:00
|
|
|
panic("No net_devices were allocated.");
|
|
|
|
|
2016-08-31 20:57:43 +00:00
|
|
|
for (i = 0; i < ARRAY_SIZE(oct_rx_group); i++) {
|
|
|
|
int ret;
|
2014-11-07 20:44:58 +00:00
|
|
|
|
2016-08-31 20:57:43 +00:00
|
|
|
if (!(pow_receive_groups & BIT(i)))
|
|
|
|
continue;
|
2016-08-31 20:57:41 +00:00
|
|
|
|
2016-08-31 20:57:43 +00:00
|
|
|
netif_napi_add(dev_for_napi, &oct_rx_group[i].napi,
|
|
|
|
cvm_oct_napi_poll, rx_napi_weight);
|
|
|
|
napi_enable(&oct_rx_group[i].napi);
|
2010-01-07 19:05:04 +00:00
|
|
|
|
2016-08-31 20:57:43 +00:00
|
|
|
oct_rx_group[i].irq = OCTEON_IRQ_WORKQ0 + i;
|
|
|
|
oct_rx_group[i].group = i;
|
2010-01-07 19:05:04 +00:00
|
|
|
|
2016-08-31 20:57:43 +00:00
|
|
|
/* Register an IRQ handler to receive POW interrupts */
|
|
|
|
ret = request_irq(oct_rx_group[i].irq, cvm_oct_do_interrupt, 0,
|
|
|
|
"Ethernet", &oct_rx_group[i].napi);
|
|
|
|
if (ret)
|
|
|
|
panic("Could not acquire Ethernet IRQ %d\n",
|
|
|
|
oct_rx_group[i].irq);
|
2010-01-07 19:05:04 +00:00
|
|
|
|
2016-08-31 20:57:43 +00:00
|
|
|
disable_irq_nosync(oct_rx_group[i].irq);
|
|
|
|
|
|
|
|
/* Enable POW interrupt when our port has at least one packet */
|
|
|
|
if (OCTEON_IS_MODEL(OCTEON_CN68XX)) {
|
|
|
|
union cvmx_sso_wq_int_thrx int_thr;
|
|
|
|
union cvmx_pow_wq_int_pc int_pc;
|
|
|
|
|
|
|
|
int_thr.u64 = 0;
|
|
|
|
int_thr.s.tc_en = 1;
|
|
|
|
int_thr.s.tc_thr = 1;
|
|
|
|
cvmx_write_csr(CVMX_SSO_WQ_INT_THRX(i), int_thr.u64);
|
|
|
|
|
|
|
|
int_pc.u64 = 0;
|
|
|
|
int_pc.s.pc_thr = 5;
|
|
|
|
cvmx_write_csr(CVMX_SSO_WQ_INT_PC, int_pc.u64);
|
|
|
|
} else {
|
|
|
|
union cvmx_pow_wq_int_thrx int_thr;
|
|
|
|
union cvmx_pow_wq_int_pc int_pc;
|
2010-01-07 19:05:04 +00:00
|
|
|
|
2016-08-31 20:57:43 +00:00
|
|
|
int_thr.u64 = 0;
|
|
|
|
int_thr.s.tc_en = 1;
|
|
|
|
int_thr.s.tc_thr = 1;
|
|
|
|
cvmx_write_csr(CVMX_POW_WQ_INT_THRX(i), int_thr.u64);
|
|
|
|
|
|
|
|
int_pc.u64 = 0;
|
|
|
|
int_pc.s.pc_thr = 5;
|
|
|
|
cvmx_write_csr(CVMX_POW_WQ_INT_PC, int_pc.u64);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Schedule NAPI now. This will indirectly enable the
|
|
|
|
* interrupt.
|
|
|
|
*/
|
|
|
|
napi_schedule(&oct_rx_group[i].napi);
|
|
|
|
}
|
2016-08-31 20:57:46 +00:00
|
|
|
atomic_inc(&oct_rx_ready);
|
2009-05-06 00:35:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cvm_oct_rx_shutdown(void)
|
|
|
|
{
|
2016-08-31 20:57:43 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(oct_rx_group); i++) {
|
|
|
|
if (!(pow_receive_groups & BIT(i)))
|
|
|
|
continue;
|
2016-08-31 20:57:36 +00:00
|
|
|
|
2016-08-31 20:57:43 +00:00
|
|
|
/* Disable POW interrupt */
|
|
|
|
if (OCTEON_IS_MODEL(OCTEON_CN68XX))
|
|
|
|
cvmx_write_csr(CVMX_SSO_WQ_INT_THRX(i), 0);
|
|
|
|
else
|
|
|
|
cvmx_write_csr(CVMX_POW_WQ_INT_THRX(i), 0);
|
|
|
|
|
|
|
|
/* Free the interrupt handler */
|
|
|
|
free_irq(oct_rx_group[i].irq, cvm_oct_device);
|
2016-08-31 20:57:36 +00:00
|
|
|
|
2016-08-31 20:57:43 +00:00
|
|
|
netif_napi_del(&oct_rx_group[i].napi);
|
|
|
|
}
|
2009-05-06 00:35:21 +00:00
|
|
|
}
|