David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 1 | /********************************************************************** |
| 2 | * Author: Cavium Networks |
| 3 | * |
| 4 | * Contact: support@caviumnetworks.com |
| 5 | * This file is part of the OCTEON SDK |
| 6 | * |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 7 | * Copyright (c) 2003-2010 Cavium Networks |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 8 | * |
| 9 | * This file is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License, Version 2, as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This file is distributed in the hope that it will be useful, but |
| 14 | * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty |
| 15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or |
| 16 | * NONINFRINGEMENT. See the GNU General Public License for more |
| 17 | * details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this file; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 22 | * or visit http://www.gnu.org/licenses/. |
| 23 | * |
| 24 | * This file may also be available under a different license from Cavium. |
| 25 | * Contact Cavium Networks for more information |
| 26 | **********************************************************************/ |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/cache.h> |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 30 | #include <linux/cpumask.h> |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 31 | #include <linux/netdevice.h> |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 32 | #include <linux/etherdevice.h> |
| 33 | #include <linux/ip.h> |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/prefetch.h> |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 36 | #include <linux/ratelimit.h> |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 37 | #include <linux/smp.h> |
Imre Kaloz | dc890df | 2012-04-19 12:27:27 +0200 | [diff] [blame] | 38 | #include <linux/interrupt.h> |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 39 | #include <net/dst.h> |
| 40 | #ifdef CONFIG_XFRM |
| 41 | #include <linux/xfrm.h> |
| 42 | #include <net/xfrm.h> |
| 43 | #endif /* CONFIG_XFRM */ |
| 44 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 45 | #include <linux/atomic.h> |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 46 | |
| 47 | #include <asm/octeon/octeon.h> |
| 48 | |
| 49 | #include "ethernet-defines.h" |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 50 | #include "ethernet-mem.h" |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 51 | #include "ethernet-rx.h" |
| 52 | #include "octeon-ethernet.h" |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 53 | #include "ethernet-util.h" |
| 54 | |
David Daney | af86649 | 2011-11-22 14:47:00 +0000 | [diff] [blame] | 55 | #include <asm/octeon/cvmx-helper.h> |
| 56 | #include <asm/octeon/cvmx-wqe.h> |
| 57 | #include <asm/octeon/cvmx-fau.h> |
| 58 | #include <asm/octeon/cvmx-pow.h> |
| 59 | #include <asm/octeon/cvmx-pip.h> |
| 60 | #include <asm/octeon/cvmx-scratch.h> |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 61 | |
David Daney | af86649 | 2011-11-22 14:47:00 +0000 | [diff] [blame] | 62 | #include <asm/octeon/cvmx-gmxx-defs.h> |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 63 | |
Aaro Koskinen | 030739f | 2014-11-07 22:44:58 +0200 | [diff] [blame^] | 64 | static struct napi_struct cvm_oct_napi; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 65 | |
| 66 | /** |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 67 | * cvm_oct_do_interrupt - interrupt handler. |
| 68 | * |
| 69 | * The interrupt occurs whenever the POW has packets in our group. |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 70 | * |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 71 | */ |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 72 | static irqreturn_t cvm_oct_do_interrupt(int cpl, void *dev_id) |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 73 | { |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 74 | /* Disable the IRQ and start napi_poll. */ |
| 75 | disable_irq_nosync(OCTEON_IRQ_WORKQ0 + pow_receive_group); |
Aaro Koskinen | 030739f | 2014-11-07 22:44:58 +0200 | [diff] [blame^] | 76 | napi_schedule(&cvm_oct_napi); |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 77 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 78 | return IRQ_HANDLED; |
| 79 | } |
| 80 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 81 | /** |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 82 | * cvm_oct_check_rcv_error - process receive errors |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 83 | * @work: Work queue entry pointing to the packet. |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 84 | * |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 85 | * Returns Non-zero if the packet can be dropped, zero otherwise. |
| 86 | */ |
| 87 | static inline int cvm_oct_check_rcv_error(cvmx_wqe_t *work) |
| 88 | { |
| 89 | if ((work->word2.snoip.err_code == 10) && (work->len <= 64)) { |
| 90 | /* |
| 91 | * Ignore length errors on min size packets. Some |
| 92 | * equipment incorrectly pads packets to 64+4FCS |
| 93 | * instead of 60+4FCS. Note these packets still get |
| 94 | * counted as frame errors. |
| 95 | */ |
| 96 | } else |
| 97 | if (USE_10MBPS_PREAMBLE_WORKAROUND |
| 98 | && ((work->word2.snoip.err_code == 5) |
| 99 | || (work->word2.snoip.err_code == 7))) { |
| 100 | |
| 101 | /* |
| 102 | * We received a packet with either an alignment error |
| 103 | * or a FCS error. This may be signalling that we are |
Justin P. Mattock | 215c47c | 2012-03-26 21:34:18 -0700 | [diff] [blame] | 104 | * running 10Mbps with GMXX_RXX_FRM_CTL[PRE_CHK] |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 105 | * off. If this is the case we need to parse the |
| 106 | * packet to determine if we can remove a non spec |
| 107 | * preamble and generate a correct packet. |
| 108 | */ |
| 109 | int interface = cvmx_helper_get_interface_num(work->ipprt); |
| 110 | int index = cvmx_helper_get_interface_index_num(work->ipprt); |
| 111 | union cvmx_gmxx_rxx_frm_ctl gmxx_rxx_frm_ctl; |
| 112 | gmxx_rxx_frm_ctl.u64 = |
| 113 | cvmx_read_csr(CVMX_GMXX_RXX_FRM_CTL(index, interface)); |
| 114 | if (gmxx_rxx_frm_ctl.s.pre_chk == 0) { |
| 115 | |
| 116 | uint8_t *ptr = |
| 117 | cvmx_phys_to_ptr(work->packet_ptr.s.addr); |
| 118 | int i = 0; |
| 119 | |
| 120 | while (i < work->len - 1) { |
| 121 | if (*ptr != 0x55) |
| 122 | break; |
| 123 | ptr++; |
| 124 | i++; |
| 125 | } |
| 126 | |
| 127 | if (*ptr == 0xd5) { |
| 128 | /* |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 129 | printk_ratelimited("Port %d received 0xd5 preamble\n", work->ipprt); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 130 | */ |
| 131 | work->packet_ptr.s.addr += i + 1; |
| 132 | work->len -= i + 5; |
| 133 | } else if ((*ptr & 0xf) == 0xd) { |
| 134 | /* |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 135 | printk_ratelimited("Port %d received 0x?d preamble\n", work->ipprt); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 136 | */ |
| 137 | work->packet_ptr.s.addr += i; |
| 138 | work->len -= i + 4; |
| 139 | for (i = 0; i < work->len; i++) { |
| 140 | *ptr = |
| 141 | ((*ptr & 0xf0) >> 4) | |
| 142 | ((*(ptr + 1) & 0xf) << 4); |
| 143 | ptr++; |
| 144 | } |
| 145 | } else { |
Gulsah Kose | 61e15f0 | 2014-09-30 22:12:23 +0300 | [diff] [blame] | 146 | printk_ratelimited("Port %d unknown preamble, packet dropped\n", |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 147 | work->ipprt); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 148 | /* |
| 149 | cvmx_helper_dump_packet(work); |
| 150 | */ |
| 151 | cvm_oct_free_work(work); |
| 152 | return 1; |
| 153 | } |
| 154 | } |
| 155 | } else { |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 156 | printk_ratelimited("Port %d receive error code %d, packet dropped\n", |
| 157 | work->ipprt, work->word2.snoip.err_code); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 158 | cvm_oct_free_work(work); |
| 159 | return 1; |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | /** |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 166 | * cvm_oct_napi_poll - the NAPI poll function. |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 167 | * @napi: The NAPI instance, or null if called from cvm_oct_poll_controller |
| 168 | * @budget: Maximum number of packets to receive. |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 169 | * |
| 170 | * Returns the number of packets processed. |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 171 | */ |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 172 | static int cvm_oct_napi_poll(struct napi_struct *napi, int budget) |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 173 | { |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 174 | const int coreid = cvmx_get_core_num(); |
| 175 | uint64_t old_group_mask; |
| 176 | uint64_t old_scratch; |
| 177 | int rx_count = 0; |
| 178 | int did_work_request = 0; |
| 179 | int packet_not_copied; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 180 | |
| 181 | /* Prefetch cvm_oct_device since we know we need it soon */ |
| 182 | prefetch(cvm_oct_device); |
| 183 | |
| 184 | if (USE_ASYNC_IOBDMA) { |
| 185 | /* Save scratch in case userspace is using it */ |
| 186 | CVMX_SYNCIOBDMA; |
| 187 | old_scratch = cvmx_scratch_read64(CVMX_SCR_SCRATCH); |
| 188 | } |
| 189 | |
| 190 | /* Only allow work for our group (and preserve priorities) */ |
| 191 | old_group_mask = cvmx_read_csr(CVMX_POW_PP_GRP_MSKX(coreid)); |
| 192 | cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid), |
| 193 | (old_group_mask & ~0xFFFFull) | 1 << pow_receive_group); |
| 194 | |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 195 | if (USE_ASYNC_IOBDMA) { |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 196 | cvmx_pow_work_request_async(CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT); |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 197 | did_work_request = 1; |
| 198 | } |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 199 | |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 200 | while (rx_count < budget) { |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 201 | struct sk_buff *skb = NULL; |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 202 | struct sk_buff **pskb = NULL; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 203 | int skb_in_hw; |
| 204 | cvmx_wqe_t *work; |
| 205 | |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 206 | if (USE_ASYNC_IOBDMA && did_work_request) |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 207 | work = cvmx_pow_work_response_async(CVMX_SCR_SCRATCH); |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 208 | else |
| 209 | work = cvmx_pow_work_request_sync(CVMX_POW_NO_WAIT); |
| 210 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 211 | prefetch(work); |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 212 | did_work_request = 0; |
| 213 | if (work == NULL) { |
| 214 | union cvmx_pow_wq_int wq_int; |
| 215 | wq_int.u64 = 0; |
| 216 | wq_int.s.iq_dis = 1 << pow_receive_group; |
| 217 | wq_int.s.wq_int = 1 << pow_receive_group; |
| 218 | cvmx_write_csr(CVMX_POW_WQ_INT, wq_int.u64); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 219 | break; |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 220 | } |
| 221 | pskb = (struct sk_buff **)(cvm_oct_get_buffer_ptr(work->packet_ptr) - sizeof(void *)); |
| 222 | prefetch(pskb); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 223 | |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 224 | if (USE_ASYNC_IOBDMA && rx_count < (budget - 1)) { |
| 225 | cvmx_pow_work_request_async_nocheck(CVMX_SCR_SCRATCH, CVMX_POW_NO_WAIT); |
| 226 | did_work_request = 1; |
| 227 | } |
Aaro Koskinen | da029d0 | 2013-09-05 21:43:59 +0300 | [diff] [blame] | 228 | rx_count++; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 229 | |
| 230 | skb_in_hw = USE_SKBUFFS_IN_HW && work->word2.s.bufs == 1; |
| 231 | if (likely(skb_in_hw)) { |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 232 | skb = *pskb; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 233 | prefetch(&skb->head); |
| 234 | prefetch(&skb->len); |
| 235 | } |
| 236 | prefetch(cvm_oct_device[work->ipprt]); |
| 237 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 238 | /* Immediately throw away all packets with receive errors */ |
| 239 | if (unlikely(work->word2.snoip.rcv_error)) { |
| 240 | if (cvm_oct_check_rcv_error(work)) |
| 241 | continue; |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * We can only use the zero copy path if skbuffs are |
| 246 | * in the FPA pool and the packet fits in a single |
| 247 | * buffer. |
| 248 | */ |
| 249 | if (likely(skb_in_hw)) { |
David Daney | 6568a23 | 2010-01-07 11:05:01 -0800 | [diff] [blame] | 250 | skb->data = skb->head + work->packet_ptr.s.addr - cvmx_ptr_to_phys(skb->head); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 251 | prefetch(skb->data); |
| 252 | skb->len = work->len; |
| 253 | skb_set_tail_pointer(skb, skb->len); |
| 254 | packet_not_copied = 1; |
| 255 | } else { |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 256 | /* |
| 257 | * We have to copy the packet. First allocate |
| 258 | * an skbuff for it. |
| 259 | */ |
| 260 | skb = dev_alloc_skb(work->len); |
| 261 | if (!skb) { |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 262 | cvm_oct_free_work(work); |
| 263 | continue; |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * Check if we've received a packet that was |
David Daney | 6568a23 | 2010-01-07 11:05:01 -0800 | [diff] [blame] | 268 | * entirely stored in the work entry. |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 269 | */ |
| 270 | if (unlikely(work->word2.s.bufs == 0)) { |
| 271 | uint8_t *ptr = work->packet_data; |
| 272 | |
| 273 | if (likely(!work->word2.s.not_IP)) { |
| 274 | /* |
| 275 | * The beginning of the packet |
| 276 | * moves for IP packets. |
| 277 | */ |
| 278 | if (work->word2.s.is_v6) |
| 279 | ptr += 2; |
| 280 | else |
| 281 | ptr += 6; |
| 282 | } |
| 283 | memcpy(skb_put(skb, work->len), ptr, work->len); |
| 284 | /* No packet buffers to free */ |
| 285 | } else { |
| 286 | int segments = work->word2.s.bufs; |
David Daney | 6568a23 | 2010-01-07 11:05:01 -0800 | [diff] [blame] | 287 | union cvmx_buf_ptr segment_ptr = work->packet_ptr; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 288 | int len = work->len; |
| 289 | |
| 290 | while (segments--) { |
| 291 | union cvmx_buf_ptr next_ptr = |
David Daney | 6568a23 | 2010-01-07 11:05:01 -0800 | [diff] [blame] | 292 | *(union cvmx_buf_ptr *)cvmx_phys_to_ptr(segment_ptr.s.addr - 8); |
| 293 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 294 | /* |
| 295 | * Octeon Errata PKI-100: The segment size is |
| 296 | * wrong. Until it is fixed, calculate the |
| 297 | * segment size based on the packet pool |
| 298 | * buffer size. When it is fixed, the |
| 299 | * following line should be replaced with this |
| 300 | * one: int segment_size = |
| 301 | * segment_ptr.s.size; |
| 302 | */ |
David Daney | 6568a23 | 2010-01-07 11:05:01 -0800 | [diff] [blame] | 303 | int segment_size = CVMX_FPA_PACKET_POOL_SIZE - |
| 304 | (segment_ptr.s.addr - (((segment_ptr.s.addr >> 7) - segment_ptr.s.back) << 7)); |
| 305 | /* |
| 306 | * Don't copy more than what |
| 307 | * is left in the packet. |
| 308 | */ |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 309 | if (segment_size > len) |
| 310 | segment_size = len; |
| 311 | /* Copy the data into the packet */ |
| 312 | memcpy(skb_put(skb, segment_size), |
David Daney | 6568a23 | 2010-01-07 11:05:01 -0800 | [diff] [blame] | 313 | cvmx_phys_to_ptr(segment_ptr.s.addr), |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 314 | segment_size); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 315 | len -= segment_size; |
| 316 | segment_ptr = next_ptr; |
| 317 | } |
| 318 | } |
| 319 | packet_not_copied = 0; |
| 320 | } |
| 321 | |
| 322 | if (likely((work->ipprt < TOTAL_NUMBER_OF_PORTS) && |
| 323 | cvm_oct_device[work->ipprt])) { |
| 324 | struct net_device *dev = cvm_oct_device[work->ipprt]; |
| 325 | struct octeon_ethernet *priv = netdev_priv(dev); |
| 326 | |
David Daney | 6568a23 | 2010-01-07 11:05:01 -0800 | [diff] [blame] | 327 | /* |
| 328 | * Only accept packets for devices that are |
| 329 | * currently up. |
| 330 | */ |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 331 | if (likely(dev->flags & IFF_UP)) { |
| 332 | skb->protocol = eth_type_trans(skb, dev); |
| 333 | skb->dev = dev; |
| 334 | |
Roy.Li | a4be637 | 2011-09-26 09:08:00 +0800 | [diff] [blame] | 335 | if (unlikely(work->word2.s.not_IP || work->word2.s.IP_exc || |
| 336 | work->word2.s.L4_error || !work->word2.s.tcp_or_udp)) |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 337 | skb->ip_summed = CHECKSUM_NONE; |
| 338 | else |
| 339 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 340 | |
| 341 | /* Increment RX stats for virtual ports */ |
| 342 | if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) { |
| 343 | #ifdef CONFIG_64BIT |
| 344 | atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets); |
| 345 | atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes); |
| 346 | #else |
| 347 | atomic_add(1, (atomic_t *)&priv->stats.rx_packets); |
| 348 | atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes); |
| 349 | #endif |
| 350 | } |
| 351 | netif_receive_skb(skb); |
| 352 | } else { |
David Daney | 6568a23 | 2010-01-07 11:05:01 -0800 | [diff] [blame] | 353 | /* Drop any packet received for a device that isn't up */ |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 354 | /* |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 355 | printk_ratelimited("%s: Device not up, packet dropped\n", |
David Daney | 6568a23 | 2010-01-07 11:05:01 -0800 | [diff] [blame] | 356 | dev->name); |
| 357 | */ |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 358 | #ifdef CONFIG_64BIT |
| 359 | atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped); |
| 360 | #else |
| 361 | atomic_add(1, (atomic_t *)&priv->stats.rx_dropped); |
| 362 | #endif |
| 363 | dev_kfree_skb_irq(skb); |
| 364 | } |
| 365 | } else { |
| 366 | /* |
| 367 | * Drop any packet received for a device that |
| 368 | * doesn't exist. |
| 369 | */ |
Christian Dietrich | 7a2eaf9 | 2011-06-04 17:35:58 +0200 | [diff] [blame] | 370 | printk_ratelimited("Port %d not controlled by Linux, packet dropped\n", |
David Daney | 6568a23 | 2010-01-07 11:05:01 -0800 | [diff] [blame] | 371 | work->ipprt); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 372 | dev_kfree_skb_irq(skb); |
| 373 | } |
| 374 | /* |
| 375 | * Check to see if the skbuff and work share the same |
| 376 | * packet buffer. |
| 377 | */ |
| 378 | if (USE_SKBUFFS_IN_HW && likely(packet_not_copied)) { |
| 379 | /* |
| 380 | * This buffer needs to be replaced, increment |
| 381 | * the number of buffers we need to free by |
| 382 | * one. |
| 383 | */ |
| 384 | cvmx_fau_atomic_add32(FAU_NUM_PACKET_BUFFERS_TO_FREE, |
| 385 | 1); |
| 386 | |
| 387 | cvmx_fpa_free(work, CVMX_FPA_WQE_POOL, |
| 388 | DONT_WRITEBACK(1)); |
| 389 | } else { |
| 390 | cvm_oct_free_work(work); |
| 391 | } |
| 392 | } |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 393 | /* Restore the original POW group mask */ |
| 394 | cvmx_write_csr(CVMX_POW_PP_GRP_MSKX(coreid), old_group_mask); |
| 395 | if (USE_ASYNC_IOBDMA) { |
| 396 | /* Restore the scratch area */ |
| 397 | cvmx_scratch_write64(CVMX_SCR_SCRATCH, old_scratch); |
| 398 | } |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 399 | cvm_oct_rx_refill_pool(0); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 400 | |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 401 | if (rx_count < budget && napi != NULL) { |
| 402 | /* No more work */ |
| 403 | napi_complete(napi); |
Aaro Koskinen | 030739f | 2014-11-07 22:44:58 +0200 | [diff] [blame^] | 404 | enable_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 405 | } |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 406 | return rx_count; |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 407 | } |
| 408 | |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 409 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 410 | /** |
David Daney | ec977c5 | 2010-02-16 17:25:32 -0800 | [diff] [blame] | 411 | * cvm_oct_poll_controller - poll for receive packets |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 412 | * device. |
| 413 | * |
| 414 | * @dev: Device to poll. Unused |
| 415 | */ |
| 416 | void cvm_oct_poll_controller(struct net_device *dev) |
| 417 | { |
| 418 | cvm_oct_napi_poll(NULL, 16); |
| 419 | } |
| 420 | #endif |
| 421 | |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 422 | void cvm_oct_rx_initialize(void) |
| 423 | { |
| 424 | int i; |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 425 | struct net_device *dev_for_napi = NULL; |
| 426 | union cvmx_pow_wq_int_thrx int_thr; |
| 427 | union cvmx_pow_wq_int_pc int_pc; |
| 428 | |
| 429 | for (i = 0; i < TOTAL_NUMBER_OF_PORTS; i++) { |
| 430 | if (cvm_oct_device[i]) { |
| 431 | dev_for_napi = cvm_oct_device[i]; |
| 432 | break; |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | if (NULL == dev_for_napi) |
| 437 | panic("No net_devices were allocated."); |
| 438 | |
Aaro Koskinen | 030739f | 2014-11-07 22:44:58 +0200 | [diff] [blame^] | 439 | netif_napi_add(dev_for_napi, &cvm_oct_napi, cvm_oct_napi_poll, |
| 440 | rx_napi_weight); |
| 441 | napi_enable(&cvm_oct_napi); |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 442 | |
Masanari Iida | 811a751 | 2013-09-16 11:44:08 +0900 | [diff] [blame] | 443 | /* Register an IRQ handler to receive POW interrupts */ |
David Daney | 3368c78 | 2010-01-07 11:05:04 -0800 | [diff] [blame] | 444 | i = request_irq(OCTEON_IRQ_WORKQ0 + pow_receive_group, |
| 445 | cvm_oct_do_interrupt, 0, "Ethernet", cvm_oct_device); |
| 446 | |
| 447 | if (i) |
| 448 | panic("Could not acquire Ethernet IRQ %d\n", |
| 449 | OCTEON_IRQ_WORKQ0 + pow_receive_group); |
| 450 | |
| 451 | disable_irq_nosync(OCTEON_IRQ_WORKQ0 + pow_receive_group); |
| 452 | |
| 453 | int_thr.u64 = 0; |
| 454 | int_thr.s.tc_en = 1; |
| 455 | int_thr.s.tc_thr = 1; |
| 456 | /* Enable POW interrupt when our port has at least one packet */ |
| 457 | cvmx_write_csr(CVMX_POW_WQ_INT_THRX(pow_receive_group), int_thr.u64); |
| 458 | |
| 459 | int_pc.u64 = 0; |
| 460 | int_pc.s.pc_thr = 5; |
| 461 | cvmx_write_csr(CVMX_POW_WQ_INT_PC, int_pc.u64); |
| 462 | |
Aaro Koskinen | 030739f | 2014-11-07 22:44:58 +0200 | [diff] [blame^] | 463 | /* Schedule NAPI now. This will indirectly enable the interrupt. */ |
| 464 | napi_schedule(&cvm_oct_napi); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | void cvm_oct_rx_shutdown(void) |
| 468 | { |
Aaro Koskinen | 030739f | 2014-11-07 22:44:58 +0200 | [diff] [blame^] | 469 | netif_napi_del(&cvm_oct_napi); |
David Daney | 80ff0fd | 2009-05-05 17:35:21 -0700 | [diff] [blame] | 470 | } |