| 1 |
// SPDX-License-Identifier: GPL-2.0 |
| 2 |
/* Copyright(c) 1999 - 2024 Intel Corporation. */ |
| 3 |
|
| 4 |
/****************************************************************************** |
| 5 |
Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code |
| 6 |
******************************************************************************/ |
| 7 |
|
| 8 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 9 |
|
| 10 |
#include <linux/types.h> |
| 11 |
#include <linux/bitops.h> |
| 12 |
#include <linux/module.h> |
| 13 |
#include <linux/pci.h> |
| 14 |
#include <linux/netdevice.h> |
| 15 |
#include <linux/vmalloc.h> |
| 16 |
#include <linux/string.h> |
| 17 |
#include <linux/in.h> |
| 18 |
#include <linux/ip.h> |
| 19 |
#include <linux/tcp.h> |
| 20 |
#include <linux/sctp.h> |
| 21 |
#include <linux/ipv6.h> |
| 22 |
#include <linux/slab.h> |
| 23 |
#include <net/checksum.h> |
| 24 |
#include <net/ip6_checksum.h> |
| 25 |
#include <linux/ethtool.h> |
| 26 |
#include <linux/if.h> |
| 27 |
#include <linux/if_vlan.h> |
| 28 |
#include <linux/prefetch.h> |
| 29 |
#include <net/mpls.h> |
| 30 |
#include <linux/bpf.h> |
| 31 |
#include <linux/bpf_trace.h> |
| 32 |
#include <linux/atomic.h> |
| 33 |
#include <net/xfrm.h> |
| 34 |
|
| 35 |
#include "ixgbevf.h" |
| 36 |
|
| 37 |
const char ixgbevf_driver_name[] = "ixgbevf"; |
| 38 |
static const char ixgbevf_driver_string[] = |
| 39 |
"Intel(R) 10 Gigabit PCI Express Virtual Function Network Driver"; |
| 40 |
|
| 41 |
static char ixgbevf_copyright[] = |
| 42 |
"Copyright (c) 2009 - 2024 Intel Corporation."; |
| 43 |
|
| 44 |
static const struct ixgbevf_info *ixgbevf_info_tbl[] = { |
| 45 |
[board_82599_vf] = &ixgbevf_82599_vf_info, |
| 46 |
[board_82599_vf_hv] = &ixgbevf_82599_vf_hv_info, |
| 47 |
[board_X540_vf] = &ixgbevf_X540_vf_info, |
| 48 |
[board_X540_vf_hv] = &ixgbevf_X540_vf_hv_info, |
| 49 |
[board_X550_vf] = &ixgbevf_X550_vf_info, |
| 50 |
[board_X550_vf_hv] = &ixgbevf_X550_vf_hv_info, |
| 51 |
[board_X550EM_x_vf] = &ixgbevf_X550EM_x_vf_info, |
| 52 |
[board_X550EM_x_vf_hv] = &ixgbevf_X550EM_x_vf_hv_info, |
| 53 |
[board_x550em_a_vf] = &ixgbevf_x550em_a_vf_info, |
| 54 |
[board_e610_vf] = &ixgbevf_e610_vf_info, |
| 55 |
[board_e610_vf_hv] = &ixgbevf_e610_vf_hv_info, |
| 56 |
}; |
| 57 |
|
| 58 |
/* ixgbevf_pci_tbl - PCI Device ID Table |
| 59 |
* |
| 60 |
* Wildcard entries (PCI_ANY_ID) should come last |
| 61 |
* Last entry must be all 0s |
| 62 |
* |
| 63 |
* { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 64 |
* Class, Class Mask, private data (not used) } |
| 65 |
*/ |
| 66 |
static const struct pci_device_id ixgbevf_pci_tbl[] = { |
| 67 |
{PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF), board_82599_vf }, |
| 68 |
{PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF_HV), board_82599_vf_hv }, |
| 69 |
{PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF), board_X540_vf }, |
| 70 |
{PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF_HV), board_X540_vf_hv }, |
| 71 |
{PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF), board_X550_vf }, |
| 72 |
{PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550_VF_HV), board_X550_vf_hv }, |
| 73 |
{PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF), board_X550EM_x_vf }, |
| 74 |
{PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_X_VF_HV), board_X550EM_x_vf_hv}, |
| 75 |
{PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X550EM_A_VF), board_x550em_a_vf }, |
| 76 |
{PCI_VDEVICE_SUB(INTEL, IXGBE_DEV_ID_E610_VF, PCI_ANY_ID, |
| 77 |
IXGBE_SUBDEV_ID_E610_VF_HV), board_e610_vf_hv}, |
| 78 |
{PCI_VDEVICE(INTEL, IXGBE_DEV_ID_E610_VF), board_e610_vf}, |
| 79 |
/* required last entry */ |
| 80 |
{0, } |
| 81 |
}; |
| 82 |
MODULE_DEVICE_TABLE(pci, ixgbevf_pci_tbl); |
| 83 |
|
| 84 |
MODULE_DESCRIPTION("Intel(R) 10 Gigabit Virtual Function Network Driver"); |
| 85 |
MODULE_LICENSE("GPL v2"); |
| 86 |
|
| 87 |
#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 88 |
static int debug = -1; |
| 89 |
module_param(debug, int, 0); |
| 90 |
MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
| 91 |
|
| 92 |
static struct workqueue_struct *ixgbevf_wq; |
| 93 |
|
| 94 |
static void ixgbevf_service_event_schedule(struct ixgbevf_adapter *adapter) |
| 95 |
{ |
| 96 |
if (!test_bit(__IXGBEVF_DOWN, &adapter->state) && |
| 97 |
!test_bit(__IXGBEVF_REMOVING, &adapter->state) && |
| 98 |
!test_and_set_bit(__IXGBEVF_SERVICE_SCHED, &adapter->state)) |
| 99 |
queue_work(ixgbevf_wq, &adapter->service_task); |
| 100 |
} |
| 101 |
|
| 102 |
static void ixgbevf_service_event_complete(struct ixgbevf_adapter *adapter) |
| 103 |
{ |
| 104 |
BUG_ON(!test_bit(__IXGBEVF_SERVICE_SCHED, &adapter->state)); |
| 105 |
|
| 106 |
/* flush memory to make sure state is correct before next watchdog */ |
| 107 |
smp_mb__before_atomic(); |
| 108 |
clear_bit(__IXGBEVF_SERVICE_SCHED, &adapter->state); |
| 109 |
} |
| 110 |
|
| 111 |
/* forward decls */ |
| 112 |
static void ixgbevf_queue_reset_subtask(struct ixgbevf_adapter *adapter); |
| 113 |
static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector); |
| 114 |
static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter *adapter); |
| 115 |
static bool ixgbevf_can_reuse_rx_page(struct ixgbevf_rx_buffer *rx_buffer); |
| 116 |
static void ixgbevf_reuse_rx_page(struct ixgbevf_ring *rx_ring, |
| 117 |
struct ixgbevf_rx_buffer *old_buff); |
| 118 |
|
| 119 |
static void ixgbevf_remove_adapter(struct ixgbe_hw *hw) |
| 120 |
{ |
| 121 |
struct ixgbevf_adapter *adapter = hw->back; |
| 122 |
|
| 123 |
if (!hw->hw_addr) |
| 124 |
return; |
| 125 |
hw->hw_addr = NULL; |
| 126 |
dev_err(&adapter->pdev->dev, "Adapter removed\n"); |
| 127 |
if (test_bit(__IXGBEVF_SERVICE_INITED, &adapter->state)) |
| 128 |
ixgbevf_service_event_schedule(adapter); |
| 129 |
} |
| 130 |
|
| 131 |
static void ixgbevf_check_remove(struct ixgbe_hw *hw, u32 reg) |
| 132 |
{ |
| 133 |
u32 value; |
| 134 |
|
| 135 |
/* The following check not only optimizes a bit by not |
| 136 |
* performing a read on the status register when the |
| 137 |
* register just read was a status register read that |
| 138 |
* returned IXGBE_FAILED_READ_REG. It also blocks any |
| 139 |
* potential recursion. |
| 140 |
*/ |
| 141 |
if (reg == IXGBE_VFSTATUS) { |
| 142 |
ixgbevf_remove_adapter(hw); |
| 143 |
return; |
| 144 |
} |
| 145 |
value = ixgbevf_read_reg(hw, IXGBE_VFSTATUS); |
| 146 |
if (value == IXGBE_FAILED_READ_REG) |
| 147 |
ixgbevf_remove_adapter(hw); |
| 148 |
} |
| 149 |
|
| 150 |
u32 ixgbevf_read_reg(struct ixgbe_hw *hw, u32 reg) |
| 151 |
{ |
| 152 |
u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr); |
| 153 |
u32 value; |
| 154 |
|
| 155 |
if (IXGBE_REMOVED(reg_addr)) |
| 156 |
return IXGBE_FAILED_READ_REG; |
| 157 |
value = readl(reg_addr + reg); |
| 158 |
if (unlikely(value == IXGBE_FAILED_READ_REG)) |
| 159 |
ixgbevf_check_remove(hw, reg); |
| 160 |
return value; |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* ixgbevf_set_ivar - set IVAR registers - maps interrupt causes to vectors |
| 165 |
* @adapter: pointer to adapter struct |
| 166 |
* @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 167 |
* @queue: queue to map the corresponding interrupt to |
| 168 |
* @msix_vector: the vector to map to the corresponding queue |
| 169 |
**/ |
| 170 |
static void ixgbevf_set_ivar(struct ixgbevf_adapter *adapter, s8 direction, |
| 171 |
u8 queue, u8 msix_vector) |
| 172 |
{ |
| 173 |
u32 ivar, index; |
| 174 |
struct ixgbe_hw *hw = &adapter->hw; |
| 175 |
|
| 176 |
if (direction == -1) { |
| 177 |
/* other causes */ |
| 178 |
msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 179 |
ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC); |
| 180 |
ivar &= ~0xFF; |
| 181 |
ivar |= msix_vector; |
| 182 |
IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, ivar); |
| 183 |
} else { |
| 184 |
/* Tx or Rx causes */ |
| 185 |
msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 186 |
index = ((16 * (queue & 1)) + (8 * direction)); |
| 187 |
ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1)); |
| 188 |
ivar &= ~(0xFF << index); |
| 189 |
ivar |= (msix_vector << index); |
| 190 |
IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), ivar); |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
static u64 ixgbevf_get_tx_completed(struct ixgbevf_ring *ring) |
| 195 |
{ |
| 196 |
return ring->stats.packets; |
| 197 |
} |
| 198 |
|
| 199 |
static u32 ixgbevf_get_tx_pending(struct ixgbevf_ring *ring) |
| 200 |
{ |
| 201 |
struct ixgbevf_adapter *adapter = netdev_priv(ring->netdev); |
| 202 |
struct ixgbe_hw *hw = &adapter->hw; |
| 203 |
|
| 204 |
u32 head = IXGBE_READ_REG(hw, IXGBE_VFTDH(ring->reg_idx)); |
| 205 |
u32 tail = IXGBE_READ_REG(hw, IXGBE_VFTDT(ring->reg_idx)); |
| 206 |
|
| 207 |
if (head != tail) |
| 208 |
return (head < tail) ? |
| 209 |
tail - head : (tail + ring->count - head); |
| 210 |
|
| 211 |
return 0; |
| 212 |
} |
| 213 |
|
| 214 |
static inline bool ixgbevf_check_tx_hang(struct ixgbevf_ring *tx_ring) |
| 215 |
{ |
| 216 |
u32 tx_done = ixgbevf_get_tx_completed(tx_ring); |
| 217 |
u32 tx_done_old = tx_ring->tx_stats.tx_done_old; |
| 218 |
u32 tx_pending = ixgbevf_get_tx_pending(tx_ring); |
| 219 |
|
| 220 |
clear_check_for_tx_hang(tx_ring); |
| 221 |
|
| 222 |
/* Check for a hung queue, but be thorough. This verifies |
| 223 |
* that a transmit has been completed since the previous |
| 224 |
* check AND there is at least one packet pending. The |
| 225 |
* ARMED bit is set to indicate a potential hang. |
| 226 |
*/ |
| 227 |
if ((tx_done_old == tx_done) && tx_pending) { |
| 228 |
/* make sure it is true for two checks in a row */ |
| 229 |
return test_and_set_bit(__IXGBEVF_HANG_CHECK_ARMED, |
| 230 |
&tx_ring->state); |
| 231 |
} |
| 232 |
/* reset the countdown */ |
| 233 |
clear_bit(__IXGBEVF_HANG_CHECK_ARMED, &tx_ring->state); |
| 234 |
|
| 235 |
/* update completed stats and continue */ |
| 236 |
tx_ring->tx_stats.tx_done_old = tx_done; |
| 237 |
|
| 238 |
return false; |
| 239 |
} |
| 240 |
|
| 241 |
static void ixgbevf_tx_timeout_reset(struct ixgbevf_adapter *adapter) |
| 242 |
{ |
| 243 |
/* Do the reset outside of interrupt context */ |
| 244 |
if (!test_bit(__IXGBEVF_DOWN, &adapter->state)) { |
| 245 |
set_bit(__IXGBEVF_RESET_REQUESTED, &adapter->state); |
| 246 |
ixgbevf_service_event_schedule(adapter); |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
/** |
| 251 |
* ixgbevf_tx_timeout - Respond to a Tx Hang |
| 252 |
* @netdev: network interface device structure |
| 253 |
* @txqueue: transmit queue hanging (unused) |
| 254 |
**/ |
| 255 |
static void ixgbevf_tx_timeout(struct net_device *netdev, unsigned int __always_unused txqueue) |
| 256 |
{ |
| 257 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 258 |
|
| 259 |
ixgbevf_tx_timeout_reset(adapter); |
| 260 |
} |
| 261 |
|
| 262 |
/** |
| 263 |
* ixgbevf_clean_tx_irq - Reclaim resources after transmit completes |
| 264 |
* @q_vector: board private structure |
| 265 |
* @tx_ring: tx ring to clean |
| 266 |
* @napi_budget: Used to determine if we are in netpoll |
| 267 |
**/ |
| 268 |
static bool ixgbevf_clean_tx_irq(struct ixgbevf_q_vector *q_vector, |
| 269 |
struct ixgbevf_ring *tx_ring, int napi_budget) |
| 270 |
{ |
| 271 |
struct ixgbevf_adapter *adapter = q_vector->adapter; |
| 272 |
struct ixgbevf_tx_buffer *tx_buffer; |
| 273 |
union ixgbe_adv_tx_desc *tx_desc; |
| 274 |
unsigned int total_bytes = 0, total_packets = 0, total_ipsec = 0; |
| 275 |
unsigned int budget = tx_ring->count / 2; |
| 276 |
unsigned int i = tx_ring->next_to_clean; |
| 277 |
|
| 278 |
if (test_bit(__IXGBEVF_DOWN, &adapter->state)) |
| 279 |
return true; |
| 280 |
|
| 281 |
tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 282 |
tx_desc = IXGBEVF_TX_DESC(tx_ring, i); |
| 283 |
i -= tx_ring->count; |
| 284 |
|
| 285 |
do { |
| 286 |
union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch; |
| 287 |
|
| 288 |
/* if next_to_watch is not set then there is no work pending */ |
| 289 |
if (!eop_desc) |
| 290 |
break; |
| 291 |
|
| 292 |
/* prevent any other reads prior to eop_desc */ |
| 293 |
smp_rmb(); |
| 294 |
|
| 295 |
/* if DD is not set pending work has not been completed */ |
| 296 |
if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD))) |
| 297 |
break; |
| 298 |
|
| 299 |
/* clear next_to_watch to prevent false hangs */ |
| 300 |
tx_buffer->next_to_watch = NULL; |
| 301 |
|
| 302 |
/* update the statistics for this packet */ |
| 303 |
total_bytes += tx_buffer->bytecount; |
| 304 |
total_packets += tx_buffer->gso_segs; |
| 305 |
if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_IPSEC) |
| 306 |
total_ipsec++; |
| 307 |
|
| 308 |
/* free the skb */ |
| 309 |
if (ring_is_xdp(tx_ring)) |
| 310 |
page_frag_free(tx_buffer->data); |
| 311 |
else |
| 312 |
napi_consume_skb(tx_buffer->skb, napi_budget); |
| 313 |
|
| 314 |
/* unmap skb header data */ |
| 315 |
dma_unmap_single(tx_ring->dev, |
| 316 |
dma_unmap_addr(tx_buffer, dma), |
| 317 |
dma_unmap_len(tx_buffer, len), |
| 318 |
DMA_TO_DEVICE); |
| 319 |
|
| 320 |
/* clear tx_buffer data */ |
| 321 |
dma_unmap_len_set(tx_buffer, len, 0); |
| 322 |
|
| 323 |
/* unmap remaining buffers */ |
| 324 |
while (tx_desc != eop_desc) { |
| 325 |
tx_buffer++; |
| 326 |
tx_desc++; |
| 327 |
i++; |
| 328 |
if (unlikely(!i)) { |
| 329 |
i -= tx_ring->count; |
| 330 |
tx_buffer = tx_ring->tx_buffer_info; |
| 331 |
tx_desc = IXGBEVF_TX_DESC(tx_ring, 0); |
| 332 |
} |
| 333 |
|
| 334 |
/* unmap any remaining paged data */ |
| 335 |
if (dma_unmap_len(tx_buffer, len)) { |
| 336 |
dma_unmap_page(tx_ring->dev, |
| 337 |
dma_unmap_addr(tx_buffer, dma), |
| 338 |
dma_unmap_len(tx_buffer, len), |
| 339 |
DMA_TO_DEVICE); |
| 340 |
dma_unmap_len_set(tx_buffer, len, 0); |
| 341 |
} |
| 342 |
} |
| 343 |
|
| 344 |
/* move us one more past the eop_desc for start of next pkt */ |
| 345 |
tx_buffer++; |
| 346 |
tx_desc++; |
| 347 |
i++; |
| 348 |
if (unlikely(!i)) { |
| 349 |
i -= tx_ring->count; |
| 350 |
tx_buffer = tx_ring->tx_buffer_info; |
| 351 |
tx_desc = IXGBEVF_TX_DESC(tx_ring, 0); |
| 352 |
} |
| 353 |
|
| 354 |
/* issue prefetch for next Tx descriptor */ |
| 355 |
prefetch(tx_desc); |
| 356 |
|
| 357 |
/* update budget accounting */ |
| 358 |
budget--; |
| 359 |
} while (likely(budget)); |
| 360 |
|
| 361 |
i += tx_ring->count; |
| 362 |
tx_ring->next_to_clean = i; |
| 363 |
u64_stats_update_begin(&tx_ring->syncp); |
| 364 |
tx_ring->stats.bytes += total_bytes; |
| 365 |
tx_ring->stats.packets += total_packets; |
| 366 |
u64_stats_update_end(&tx_ring->syncp); |
| 367 |
q_vector->tx.total_bytes += total_bytes; |
| 368 |
q_vector->tx.total_packets += total_packets; |
| 369 |
adapter->tx_ipsec += total_ipsec; |
| 370 |
|
| 371 |
if (check_for_tx_hang(tx_ring) && ixgbevf_check_tx_hang(tx_ring)) { |
| 372 |
struct ixgbe_hw *hw = &adapter->hw; |
| 373 |
union ixgbe_adv_tx_desc *eop_desc; |
| 374 |
|
| 375 |
eop_desc = tx_ring->tx_buffer_info[i].next_to_watch; |
| 376 |
|
| 377 |
pr_err("Detected Tx Unit Hang%s\n" |
| 378 |
" Tx Queue <%d>\n" |
| 379 |
" TDH, TDT <%x>, <%x>\n" |
| 380 |
" next_to_use <%x>\n" |
| 381 |
" next_to_clean <%x>\n" |
| 382 |
"tx_buffer_info[next_to_clean]\n" |
| 383 |
" next_to_watch <%p>\n" |
| 384 |
" eop_desc->wb.status <%x>\n" |
| 385 |
" time_stamp <%lx>\n" |
| 386 |
" jiffies <%lx>\n", |
| 387 |
ring_is_xdp(tx_ring) ? " XDP" : "", |
| 388 |
tx_ring->queue_index, |
| 389 |
IXGBE_READ_REG(hw, IXGBE_VFTDH(tx_ring->reg_idx)), |
| 390 |
IXGBE_READ_REG(hw, IXGBE_VFTDT(tx_ring->reg_idx)), |
| 391 |
tx_ring->next_to_use, i, |
| 392 |
eop_desc, (eop_desc ? eop_desc->wb.status : 0), |
| 393 |
tx_ring->tx_buffer_info[i].time_stamp, jiffies); |
| 394 |
|
| 395 |
if (!ring_is_xdp(tx_ring)) |
| 396 |
netif_stop_subqueue(tx_ring->netdev, |
| 397 |
tx_ring->queue_index); |
| 398 |
|
| 399 |
/* schedule immediate reset if we believe we hung */ |
| 400 |
ixgbevf_tx_timeout_reset(adapter); |
| 401 |
|
| 402 |
return true; |
| 403 |
} |
| 404 |
|
| 405 |
if (ring_is_xdp(tx_ring)) |
| 406 |
return !!budget; |
| 407 |
|
| 408 |
#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
| 409 |
if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) && |
| 410 |
(ixgbevf_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) { |
| 411 |
/* Make sure that anybody stopping the queue after this |
| 412 |
* sees the new next_to_clean. |
| 413 |
*/ |
| 414 |
smp_mb(); |
| 415 |
|
| 416 |
if (__netif_subqueue_stopped(tx_ring->netdev, |
| 417 |
tx_ring->queue_index) && |
| 418 |
!test_bit(__IXGBEVF_DOWN, &adapter->state)) { |
| 419 |
netif_wake_subqueue(tx_ring->netdev, |
| 420 |
tx_ring->queue_index); |
| 421 |
++tx_ring->tx_stats.restart_queue; |
| 422 |
} |
| 423 |
} |
| 424 |
|
| 425 |
return !!budget; |
| 426 |
} |
| 427 |
|
| 428 |
/** |
| 429 |
* ixgbevf_rx_skb - Helper function to determine proper Rx method |
| 430 |
* @q_vector: structure containing interrupt and ring information |
| 431 |
* @skb: packet to send up |
| 432 |
**/ |
| 433 |
static void ixgbevf_rx_skb(struct ixgbevf_q_vector *q_vector, |
| 434 |
struct sk_buff *skb) |
| 435 |
{ |
| 436 |
napi_gro_receive(&q_vector->napi, skb); |
| 437 |
} |
| 438 |
|
| 439 |
#define IXGBE_RSS_L4_TYPES_MASK \ |
| 440 |
((1ul << IXGBE_RXDADV_RSSTYPE_IPV4_TCP) | \ |
| 441 |
(1ul << IXGBE_RXDADV_RSSTYPE_IPV4_UDP) | \ |
| 442 |
(1ul << IXGBE_RXDADV_RSSTYPE_IPV6_TCP) | \ |
| 443 |
(1ul << IXGBE_RXDADV_RSSTYPE_IPV6_UDP)) |
| 444 |
|
| 445 |
static inline void ixgbevf_rx_hash(struct ixgbevf_ring *ring, |
| 446 |
union ixgbe_adv_rx_desc *rx_desc, |
| 447 |
struct sk_buff *skb) |
| 448 |
{ |
| 449 |
u16 rss_type; |
| 450 |
|
| 451 |
if (!(ring->netdev->features & NETIF_F_RXHASH)) |
| 452 |
return; |
| 453 |
|
| 454 |
rss_type = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.pkt_info) & |
| 455 |
IXGBE_RXDADV_RSSTYPE_MASK; |
| 456 |
|
| 457 |
if (!rss_type) |
| 458 |
return; |
| 459 |
|
| 460 |
skb_set_hash(skb, le32_to_cpu(rx_desc->wb.lower.hi_dword.rss), |
| 461 |
(IXGBE_RSS_L4_TYPES_MASK & (1ul << rss_type)) ? |
| 462 |
PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3); |
| 463 |
} |
| 464 |
|
| 465 |
/** |
| 466 |
* ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum |
| 467 |
* @ring: structure containig ring specific data |
| 468 |
* @rx_desc: current Rx descriptor being processed |
| 469 |
* @skb: skb currently being received and modified |
| 470 |
**/ |
| 471 |
static inline void ixgbevf_rx_checksum(struct ixgbevf_ring *ring, |
| 472 |
union ixgbe_adv_rx_desc *rx_desc, |
| 473 |
struct sk_buff *skb) |
| 474 |
{ |
| 475 |
skb_checksum_none_assert(skb); |
| 476 |
|
| 477 |
/* Rx csum disabled */ |
| 478 |
if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
| 479 |
return; |
| 480 |
|
| 481 |
/* if IP and error */ |
| 482 |
if (ixgbevf_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) && |
| 483 |
ixgbevf_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) { |
| 484 |
ring->rx_stats.csum_err++; |
| 485 |
return; |
| 486 |
} |
| 487 |
|
| 488 |
if (!ixgbevf_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS)) |
| 489 |
return; |
| 490 |
|
| 491 |
if (ixgbevf_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) { |
| 492 |
ring->rx_stats.csum_err++; |
| 493 |
return; |
| 494 |
} |
| 495 |
|
| 496 |
/* It must be a TCP or UDP packet with a valid checksum */ |
| 497 |
skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 498 |
} |
| 499 |
|
| 500 |
/** |
| 501 |
* ixgbevf_process_skb_fields - Populate skb header fields from Rx descriptor |
| 502 |
* @rx_ring: rx descriptor ring packet is being transacted on |
| 503 |
* @rx_desc: pointer to the EOP Rx descriptor |
| 504 |
* @skb: pointer to current skb being populated |
| 505 |
* |
| 506 |
* This function checks the ring, descriptor, and packet information in |
| 507 |
* order to populate the checksum, VLAN, protocol, and other fields within |
| 508 |
* the skb. |
| 509 |
**/ |
| 510 |
static void ixgbevf_process_skb_fields(struct ixgbevf_ring *rx_ring, |
| 511 |
union ixgbe_adv_rx_desc *rx_desc, |
| 512 |
struct sk_buff *skb) |
| 513 |
{ |
| 514 |
ixgbevf_rx_hash(rx_ring, rx_desc, skb); |
| 515 |
ixgbevf_rx_checksum(rx_ring, rx_desc, skb); |
| 516 |
|
| 517 |
if (ixgbevf_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) { |
| 518 |
u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan); |
| 519 |
unsigned long *active_vlans = netdev_priv(rx_ring->netdev); |
| 520 |
|
| 521 |
if (test_bit(vid & VLAN_VID_MASK, active_vlans)) |
| 522 |
__vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
| 523 |
} |
| 524 |
|
| 525 |
if (ixgbevf_test_staterr(rx_desc, IXGBE_RXDADV_STAT_SECP)) |
| 526 |
ixgbevf_ipsec_rx(rx_ring, rx_desc, skb); |
| 527 |
|
| 528 |
skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
| 529 |
} |
| 530 |
|
| 531 |
static |
| 532 |
struct ixgbevf_rx_buffer *ixgbevf_get_rx_buffer(struct ixgbevf_ring *rx_ring, |
| 533 |
const unsigned int size) |
| 534 |
{ |
| 535 |
struct ixgbevf_rx_buffer *rx_buffer; |
| 536 |
|
| 537 |
rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean]; |
| 538 |
prefetchw(rx_buffer->page); |
| 539 |
|
| 540 |
/* we are reusing so sync this buffer for CPU use */ |
| 541 |
dma_sync_single_range_for_cpu(rx_ring->dev, |
| 542 |
rx_buffer->dma, |
| 543 |
rx_buffer->page_offset, |
| 544 |
size, |
| 545 |
DMA_FROM_DEVICE); |
| 546 |
|
| 547 |
rx_buffer->pagecnt_bias--; |
| 548 |
|
| 549 |
return rx_buffer; |
| 550 |
} |
| 551 |
|
| 552 |
static void ixgbevf_put_rx_buffer(struct ixgbevf_ring *rx_ring, |
| 553 |
struct ixgbevf_rx_buffer *rx_buffer, |
| 554 |
struct sk_buff *skb) |
| 555 |
{ |
| 556 |
if (ixgbevf_can_reuse_rx_page(rx_buffer)) { |
| 557 |
/* hand second half of page back to the ring */ |
| 558 |
ixgbevf_reuse_rx_page(rx_ring, rx_buffer); |
| 559 |
} else { |
| 560 |
if (IS_ERR(skb)) |
| 561 |
/* We are not reusing the buffer so unmap it and free |
| 562 |
* any references we are holding to it |
| 563 |
*/ |
| 564 |
dma_unmap_page_attrs(rx_ring->dev, rx_buffer->dma, |
| 565 |
ixgbevf_rx_pg_size(rx_ring), |
| 566 |
DMA_FROM_DEVICE, |
| 567 |
IXGBEVF_RX_DMA_ATTR); |
| 568 |
__page_frag_cache_drain(rx_buffer->page, |
| 569 |
rx_buffer->pagecnt_bias); |
| 570 |
} |
| 571 |
|
| 572 |
/* clear contents of rx_buffer */ |
| 573 |
rx_buffer->page = NULL; |
| 574 |
} |
| 575 |
|
| 576 |
/** |
| 577 |
* ixgbevf_is_non_eop - process handling of non-EOP buffers |
| 578 |
* @rx_ring: Rx ring being processed |
| 579 |
* @rx_desc: Rx descriptor for current buffer |
| 580 |
* |
| 581 |
* This function updates next to clean. If the buffer is an EOP buffer |
| 582 |
* this function exits returning false, otherwise it will place the |
| 583 |
* sk_buff in the next buffer to be chained and return true indicating |
| 584 |
* that this is in fact a non-EOP buffer. |
| 585 |
**/ |
| 586 |
static bool ixgbevf_is_non_eop(struct ixgbevf_ring *rx_ring, |
| 587 |
union ixgbe_adv_rx_desc *rx_desc) |
| 588 |
{ |
| 589 |
u32 ntc = rx_ring->next_to_clean + 1; |
| 590 |
|
| 591 |
/* fetch, update, and store next to clean */ |
| 592 |
ntc = (ntc < rx_ring->count) ? ntc : 0; |
| 593 |
rx_ring->next_to_clean = ntc; |
| 594 |
|
| 595 |
prefetch(IXGBEVF_RX_DESC(rx_ring, ntc)); |
| 596 |
|
| 597 |
if (likely(ixgbevf_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) |
| 598 |
return false; |
| 599 |
|
| 600 |
return true; |
| 601 |
} |
| 602 |
|
| 603 |
static inline unsigned int ixgbevf_rx_offset(struct ixgbevf_ring *rx_ring) |
| 604 |
{ |
| 605 |
return ring_uses_build_skb(rx_ring) ? IXGBEVF_SKB_PAD : 0; |
| 606 |
} |
| 607 |
|
| 608 |
static bool ixgbevf_alloc_mapped_page(struct ixgbevf_ring *rx_ring, |
| 609 |
struct ixgbevf_rx_buffer *bi) |
| 610 |
{ |
| 611 |
struct page *page = bi->page; |
| 612 |
dma_addr_t dma; |
| 613 |
|
| 614 |
/* since we are recycling buffers we should seldom need to alloc */ |
| 615 |
if (likely(page)) |
| 616 |
return true; |
| 617 |
|
| 618 |
/* alloc new page for storage */ |
| 619 |
page = dev_alloc_pages(ixgbevf_rx_pg_order(rx_ring)); |
| 620 |
if (unlikely(!page)) { |
| 621 |
rx_ring->rx_stats.alloc_rx_page_failed++; |
| 622 |
return false; |
| 623 |
} |
| 624 |
|
| 625 |
/* map page for use */ |
| 626 |
dma = dma_map_page_attrs(rx_ring->dev, page, 0, |
| 627 |
ixgbevf_rx_pg_size(rx_ring), |
| 628 |
DMA_FROM_DEVICE, IXGBEVF_RX_DMA_ATTR); |
| 629 |
|
| 630 |
/* if mapping failed free memory back to system since |
| 631 |
* there isn't much point in holding memory we can't use |
| 632 |
*/ |
| 633 |
if (dma_mapping_error(rx_ring->dev, dma)) { |
| 634 |
__free_pages(page, ixgbevf_rx_pg_order(rx_ring)); |
| 635 |
|
| 636 |
rx_ring->rx_stats.alloc_rx_page_failed++; |
| 637 |
return false; |
| 638 |
} |
| 639 |
|
| 640 |
bi->dma = dma; |
| 641 |
bi->page = page; |
| 642 |
bi->page_offset = ixgbevf_rx_offset(rx_ring); |
| 643 |
bi->pagecnt_bias = 1; |
| 644 |
rx_ring->rx_stats.alloc_rx_page++; |
| 645 |
|
| 646 |
return true; |
| 647 |
} |
| 648 |
|
| 649 |
/** |
| 650 |
* ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split |
| 651 |
* @rx_ring: rx descriptor ring (for a specific queue) to setup buffers on |
| 652 |
* @cleaned_count: number of buffers to replace |
| 653 |
**/ |
| 654 |
static void ixgbevf_alloc_rx_buffers(struct ixgbevf_ring *rx_ring, |
| 655 |
u16 cleaned_count) |
| 656 |
{ |
| 657 |
union ixgbe_adv_rx_desc *rx_desc; |
| 658 |
struct ixgbevf_rx_buffer *bi; |
| 659 |
unsigned int i = rx_ring->next_to_use; |
| 660 |
|
| 661 |
/* nothing to do or no valid netdev defined */ |
| 662 |
if (!cleaned_count || !rx_ring->netdev) |
| 663 |
return; |
| 664 |
|
| 665 |
rx_desc = IXGBEVF_RX_DESC(rx_ring, i); |
| 666 |
bi = &rx_ring->rx_buffer_info[i]; |
| 667 |
i -= rx_ring->count; |
| 668 |
|
| 669 |
do { |
| 670 |
if (!ixgbevf_alloc_mapped_page(rx_ring, bi)) |
| 671 |
break; |
| 672 |
|
| 673 |
/* sync the buffer for use by the device */ |
| 674 |
dma_sync_single_range_for_device(rx_ring->dev, bi->dma, |
| 675 |
bi->page_offset, |
| 676 |
ixgbevf_rx_bufsz(rx_ring), |
| 677 |
DMA_FROM_DEVICE); |
| 678 |
|
| 679 |
/* Refresh the desc even if pkt_addr didn't change |
| 680 |
* because each write-back erases this info. |
| 681 |
*/ |
| 682 |
rx_desc->read.pkt_addr = cpu_to_le64(bi->dma + bi->page_offset); |
| 683 |
|
| 684 |
rx_desc++; |
| 685 |
bi++; |
| 686 |
i++; |
| 687 |
if (unlikely(!i)) { |
| 688 |
rx_desc = IXGBEVF_RX_DESC(rx_ring, 0); |
| 689 |
bi = rx_ring->rx_buffer_info; |
| 690 |
i -= rx_ring->count; |
| 691 |
} |
| 692 |
|
| 693 |
/* clear the length for the next_to_use descriptor */ |
| 694 |
rx_desc->wb.upper.length = 0; |
| 695 |
|
| 696 |
cleaned_count--; |
| 697 |
} while (cleaned_count); |
| 698 |
|
| 699 |
i += rx_ring->count; |
| 700 |
|
| 701 |
if (rx_ring->next_to_use != i) { |
| 702 |
/* record the next descriptor to use */ |
| 703 |
rx_ring->next_to_use = i; |
| 704 |
|
| 705 |
/* update next to alloc since we have filled the ring */ |
| 706 |
rx_ring->next_to_alloc = i; |
| 707 |
|
| 708 |
/* Force memory writes to complete before letting h/w |
| 709 |
* know there are new descriptors to fetch. (Only |
| 710 |
* applicable for weak-ordered memory model archs, |
| 711 |
* such as IA-64). |
| 712 |
*/ |
| 713 |
wmb(); |
| 714 |
ixgbevf_write_tail(rx_ring, i); |
| 715 |
} |
| 716 |
} |
| 717 |
|
| 718 |
/** |
| 719 |
* ixgbevf_cleanup_headers - Correct corrupted or empty headers |
| 720 |
* @rx_ring: rx descriptor ring packet is being transacted on |
| 721 |
* @rx_desc: pointer to the EOP Rx descriptor |
| 722 |
* @skb: pointer to current skb being fixed |
| 723 |
* |
| 724 |
* Check for corrupted packet headers caused by senders on the local L2 |
| 725 |
* embedded NIC switch not setting up their Tx Descriptors right. These |
| 726 |
* should be very rare. |
| 727 |
* |
| 728 |
* Also address the case where we are pulling data in on pages only |
| 729 |
* and as such no data is present in the skb header. |
| 730 |
* |
| 731 |
* In addition if skb is not at least 60 bytes we need to pad it so that |
| 732 |
* it is large enough to qualify as a valid Ethernet frame. |
| 733 |
* |
| 734 |
* Returns true if an error was encountered and skb was freed. |
| 735 |
**/ |
| 736 |
static bool ixgbevf_cleanup_headers(struct ixgbevf_ring *rx_ring, |
| 737 |
union ixgbe_adv_rx_desc *rx_desc, |
| 738 |
struct sk_buff *skb) |
| 739 |
{ |
| 740 |
/* verify that the packet does not have any known errors */ |
| 741 |
if (unlikely(ixgbevf_test_staterr(rx_desc, |
| 742 |
IXGBE_RXDADV_ERR_FRAME_ERR_MASK))) { |
| 743 |
struct net_device *netdev = rx_ring->netdev; |
| 744 |
|
| 745 |
if (!(netdev->features & NETIF_F_RXALL)) { |
| 746 |
dev_kfree_skb_any(skb); |
| 747 |
return true; |
| 748 |
} |
| 749 |
} |
| 750 |
|
| 751 |
/* if eth_skb_pad returns an error the skb was freed */ |
| 752 |
if (eth_skb_pad(skb)) |
| 753 |
return true; |
| 754 |
|
| 755 |
return false; |
| 756 |
} |
| 757 |
|
| 758 |
/** |
| 759 |
* ixgbevf_reuse_rx_page - page flip buffer and store it back on the ring |
| 760 |
* @rx_ring: rx descriptor ring to store buffers on |
| 761 |
* @old_buff: donor buffer to have page reused |
| 762 |
* |
| 763 |
* Synchronizes page for reuse by the adapter |
| 764 |
**/ |
| 765 |
static void ixgbevf_reuse_rx_page(struct ixgbevf_ring *rx_ring, |
| 766 |
struct ixgbevf_rx_buffer *old_buff) |
| 767 |
{ |
| 768 |
struct ixgbevf_rx_buffer *new_buff; |
| 769 |
u16 nta = rx_ring->next_to_alloc; |
| 770 |
|
| 771 |
new_buff = &rx_ring->rx_buffer_info[nta]; |
| 772 |
|
| 773 |
/* update, and store next to alloc */ |
| 774 |
nta++; |
| 775 |
rx_ring->next_to_alloc = (nta < rx_ring->count) ? nta : 0; |
| 776 |
|
| 777 |
/* transfer page from old buffer to new buffer */ |
| 778 |
new_buff->page = old_buff->page; |
| 779 |
new_buff->dma = old_buff->dma; |
| 780 |
new_buff->page_offset = old_buff->page_offset; |
| 781 |
new_buff->pagecnt_bias = old_buff->pagecnt_bias; |
| 782 |
} |
| 783 |
|
| 784 |
static bool ixgbevf_can_reuse_rx_page(struct ixgbevf_rx_buffer *rx_buffer) |
| 785 |
{ |
| 786 |
unsigned int pagecnt_bias = rx_buffer->pagecnt_bias; |
| 787 |
struct page *page = rx_buffer->page; |
| 788 |
|
| 789 |
/* avoid re-using remote and pfmemalloc pages */ |
| 790 |
if (!dev_page_is_reusable(page)) |
| 791 |
return false; |
| 792 |
|
| 793 |
#if (PAGE_SIZE < 8192) |
| 794 |
/* if we are only owner of page we can reuse it */ |
| 795 |
if (unlikely((page_ref_count(page) - pagecnt_bias) > 1)) |
| 796 |
return false; |
| 797 |
#else |
| 798 |
#define IXGBEVF_LAST_OFFSET \ |
| 799 |
(SKB_WITH_OVERHEAD(PAGE_SIZE) - IXGBEVF_RXBUFFER_2048) |
| 800 |
|
| 801 |
if (rx_buffer->page_offset > IXGBEVF_LAST_OFFSET) |
| 802 |
return false; |
| 803 |
|
| 804 |
#endif |
| 805 |
|
| 806 |
/* If we have drained the page fragment pool we need to update |
| 807 |
* the pagecnt_bias and page count so that we fully restock the |
| 808 |
* number of references the driver holds. |
| 809 |
*/ |
| 810 |
if (unlikely(!pagecnt_bias)) { |
| 811 |
page_ref_add(page, USHRT_MAX); |
| 812 |
rx_buffer->pagecnt_bias = USHRT_MAX; |
| 813 |
} |
| 814 |
|
| 815 |
return true; |
| 816 |
} |
| 817 |
|
| 818 |
/** |
| 819 |
* ixgbevf_add_rx_frag - Add contents of Rx buffer to sk_buff |
| 820 |
* @rx_ring: rx descriptor ring to transact packets on |
| 821 |
* @rx_buffer: buffer containing page to add |
| 822 |
* @skb: sk_buff to place the data into |
| 823 |
* @size: size of buffer to be added |
| 824 |
* |
| 825 |
* This function will add the data contained in rx_buffer->page to the skb. |
| 826 |
**/ |
| 827 |
static void ixgbevf_add_rx_frag(struct ixgbevf_ring *rx_ring, |
| 828 |
struct ixgbevf_rx_buffer *rx_buffer, |
| 829 |
struct sk_buff *skb, |
| 830 |
unsigned int size) |
| 831 |
{ |
| 832 |
#if (PAGE_SIZE < 8192) |
| 833 |
unsigned int truesize = ixgbevf_rx_pg_size(rx_ring) / 2; |
| 834 |
#else |
| 835 |
unsigned int truesize = ring_uses_build_skb(rx_ring) ? |
| 836 |
SKB_DATA_ALIGN(IXGBEVF_SKB_PAD + size) : |
| 837 |
SKB_DATA_ALIGN(size); |
| 838 |
#endif |
| 839 |
skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, rx_buffer->page, |
| 840 |
rx_buffer->page_offset, size, truesize); |
| 841 |
#if (PAGE_SIZE < 8192) |
| 842 |
rx_buffer->page_offset ^= truesize; |
| 843 |
#else |
| 844 |
rx_buffer->page_offset += truesize; |
| 845 |
#endif |
| 846 |
} |
| 847 |
|
| 848 |
static |
| 849 |
struct sk_buff *ixgbevf_construct_skb(struct ixgbevf_ring *rx_ring, |
| 850 |
struct ixgbevf_rx_buffer *rx_buffer, |
| 851 |
struct xdp_buff *xdp, |
| 852 |
union ixgbe_adv_rx_desc *rx_desc) |
| 853 |
{ |
| 854 |
unsigned int size = xdp->data_end - xdp->data; |
| 855 |
#if (PAGE_SIZE < 8192) |
| 856 |
unsigned int truesize = ixgbevf_rx_pg_size(rx_ring) / 2; |
| 857 |
#else |
| 858 |
unsigned int truesize = SKB_DATA_ALIGN(xdp->data_end - |
| 859 |
xdp->data_hard_start); |
| 860 |
#endif |
| 861 |
unsigned int headlen; |
| 862 |
struct sk_buff *skb; |
| 863 |
|
| 864 |
/* prefetch first cache line of first page */ |
| 865 |
net_prefetch(xdp->data); |
| 866 |
|
| 867 |
/* Note, we get here by enabling legacy-rx via: |
| 868 |
* |
| 869 |
* ethtool --set-priv-flags <dev> legacy-rx on |
| 870 |
* |
| 871 |
* In this mode, we currently get 0 extra XDP headroom as |
| 872 |
* opposed to having legacy-rx off, where we process XDP |
| 873 |
* packets going to stack via ixgbevf_build_skb(). |
| 874 |
* |
| 875 |
* For ixgbevf_construct_skb() mode it means that the |
| 876 |
* xdp->data_meta will always point to xdp->data, since |
| 877 |
* the helper cannot expand the head. Should this ever |
| 878 |
* changed in future for legacy-rx mode on, then lets also |
| 879 |
* add xdp->data_meta handling here. |
| 880 |
*/ |
| 881 |
|
| 882 |
/* allocate a skb to store the frags */ |
| 883 |
skb = napi_alloc_skb(&rx_ring->q_vector->napi, IXGBEVF_RX_HDR_SIZE); |
| 884 |
if (unlikely(!skb)) |
| 885 |
return NULL; |
| 886 |
|
| 887 |
/* Determine available headroom for copy */ |
| 888 |
headlen = size; |
| 889 |
if (headlen > IXGBEVF_RX_HDR_SIZE) |
| 890 |
headlen = eth_get_headlen(skb->dev, xdp->data, |
| 891 |
IXGBEVF_RX_HDR_SIZE); |
| 892 |
|
| 893 |
/* align pull length to size of long to optimize memcpy performance */ |
| 894 |
memcpy(__skb_put(skb, headlen), xdp->data, |
| 895 |
ALIGN(headlen, sizeof(long))); |
| 896 |
|
| 897 |
/* update all of the pointers */ |
| 898 |
size -= headlen; |
| 899 |
if (size) { |
| 900 |
skb_add_rx_frag(skb, 0, rx_buffer->page, |
| 901 |
(xdp->data + headlen) - |
| 902 |
page_address(rx_buffer->page), |
| 903 |
size, truesize); |
| 904 |
#if (PAGE_SIZE < 8192) |
| 905 |
rx_buffer->page_offset ^= truesize; |
| 906 |
#else |
| 907 |
rx_buffer->page_offset += truesize; |
| 908 |
#endif |
| 909 |
} else { |
| 910 |
rx_buffer->pagecnt_bias++; |
| 911 |
} |
| 912 |
|
| 913 |
return skb; |
| 914 |
} |
| 915 |
|
| 916 |
static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter *adapter, |
| 917 |
u32 qmask) |
| 918 |
{ |
| 919 |
struct ixgbe_hw *hw = &adapter->hw; |
| 920 |
|
| 921 |
IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, qmask); |
| 922 |
} |
| 923 |
|
| 924 |
static struct sk_buff *ixgbevf_build_skb(struct ixgbevf_ring *rx_ring, |
| 925 |
struct ixgbevf_rx_buffer *rx_buffer, |
| 926 |
struct xdp_buff *xdp, |
| 927 |
union ixgbe_adv_rx_desc *rx_desc) |
| 928 |
{ |
| 929 |
unsigned int metasize = xdp->data - xdp->data_meta; |
| 930 |
#if (PAGE_SIZE < 8192) |
| 931 |
unsigned int truesize = ixgbevf_rx_pg_size(rx_ring) / 2; |
| 932 |
#else |
| 933 |
unsigned int truesize = SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) + |
| 934 |
SKB_DATA_ALIGN(xdp->data_end - |
| 935 |
xdp->data_hard_start); |
| 936 |
#endif |
| 937 |
struct sk_buff *skb; |
| 938 |
|
| 939 |
/* Prefetch first cache line of first page. If xdp->data_meta |
| 940 |
* is unused, this points to xdp->data, otherwise, we likely |
| 941 |
* have a consumer accessing first few bytes of meta data, |
| 942 |
* and then actual data. |
| 943 |
*/ |
| 944 |
net_prefetch(xdp->data_meta); |
| 945 |
|
| 946 |
/* build an skb around the page buffer */ |
| 947 |
skb = napi_build_skb(xdp->data_hard_start, truesize); |
| 948 |
if (unlikely(!skb)) |
| 949 |
return NULL; |
| 950 |
|
| 951 |
/* update pointers within the skb to store the data */ |
| 952 |
skb_reserve(skb, xdp->data - xdp->data_hard_start); |
| 953 |
__skb_put(skb, xdp->data_end - xdp->data); |
| 954 |
if (metasize) |
| 955 |
skb_metadata_set(skb, metasize); |
| 956 |
|
| 957 |
/* update buffer offset */ |
| 958 |
#if (PAGE_SIZE < 8192) |
| 959 |
rx_buffer->page_offset ^= truesize; |
| 960 |
#else |
| 961 |
rx_buffer->page_offset += truesize; |
| 962 |
#endif |
| 963 |
|
| 964 |
return skb; |
| 965 |
} |
| 966 |
|
| 967 |
#define IXGBEVF_XDP_PASS 0 |
| 968 |
#define IXGBEVF_XDP_CONSUMED 1 |
| 969 |
#define IXGBEVF_XDP_TX 2 |
| 970 |
|
| 971 |
static int ixgbevf_xmit_xdp_ring(struct ixgbevf_ring *ring, |
| 972 |
struct xdp_buff *xdp) |
| 973 |
{ |
| 974 |
struct ixgbevf_tx_buffer *tx_buffer; |
| 975 |
union ixgbe_adv_tx_desc *tx_desc; |
| 976 |
u32 len, cmd_type; |
| 977 |
dma_addr_t dma; |
| 978 |
u16 i; |
| 979 |
|
| 980 |
len = xdp->data_end - xdp->data; |
| 981 |
|
| 982 |
if (unlikely(!ixgbevf_desc_unused(ring))) |
| 983 |
return IXGBEVF_XDP_CONSUMED; |
| 984 |
|
| 985 |
dma = dma_map_single(ring->dev, xdp->data, len, DMA_TO_DEVICE); |
| 986 |
if (dma_mapping_error(ring->dev, dma)) |
| 987 |
return IXGBEVF_XDP_CONSUMED; |
| 988 |
|
| 989 |
/* record the location of the first descriptor for this packet */ |
| 990 |
i = ring->next_to_use; |
| 991 |
tx_buffer = &ring->tx_buffer_info[i]; |
| 992 |
|
| 993 |
dma_unmap_len_set(tx_buffer, len, len); |
| 994 |
dma_unmap_addr_set(tx_buffer, dma, dma); |
| 995 |
tx_buffer->data = xdp->data; |
| 996 |
tx_buffer->bytecount = len; |
| 997 |
tx_buffer->gso_segs = 1; |
| 998 |
tx_buffer->protocol = 0; |
| 999 |
|
| 1000 |
/* Populate minimal context descriptor that will provide for the |
| 1001 |
* fact that we are expected to process Ethernet frames. |
| 1002 |
*/ |
| 1003 |
if (!test_bit(__IXGBEVF_TX_XDP_RING_PRIMED, &ring->state)) { |
| 1004 |
struct ixgbe_adv_tx_context_desc *context_desc; |
| 1005 |
|
| 1006 |
set_bit(__IXGBEVF_TX_XDP_RING_PRIMED, &ring->state); |
| 1007 |
|
| 1008 |
context_desc = IXGBEVF_TX_CTXTDESC(ring, 0); |
| 1009 |
context_desc->vlan_macip_lens = |
| 1010 |
cpu_to_le32(ETH_HLEN << IXGBE_ADVTXD_MACLEN_SHIFT); |
| 1011 |
context_desc->fceof_saidx = 0; |
| 1012 |
context_desc->type_tucmd_mlhl = |
| 1013 |
cpu_to_le32(IXGBE_TXD_CMD_DEXT | |
| 1014 |
IXGBE_ADVTXD_DTYP_CTXT); |
| 1015 |
context_desc->mss_l4len_idx = 0; |
| 1016 |
|
| 1017 |
i = 1; |
| 1018 |
} |
| 1019 |
|
| 1020 |
/* put descriptor type bits */ |
| 1021 |
cmd_type = IXGBE_ADVTXD_DTYP_DATA | |
| 1022 |
IXGBE_ADVTXD_DCMD_DEXT | |
| 1023 |
IXGBE_ADVTXD_DCMD_IFCS; |
| 1024 |
cmd_type |= len | IXGBE_TXD_CMD; |
| 1025 |
|
| 1026 |
tx_desc = IXGBEVF_TX_DESC(ring, i); |
| 1027 |
tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 1028 |
|
| 1029 |
tx_desc->read.cmd_type_len = cpu_to_le32(cmd_type); |
| 1030 |
tx_desc->read.olinfo_status = |
| 1031 |
cpu_to_le32((len << IXGBE_ADVTXD_PAYLEN_SHIFT) | |
| 1032 |
IXGBE_ADVTXD_CC); |
| 1033 |
|
| 1034 |
/* Avoid any potential race with cleanup */ |
| 1035 |
smp_wmb(); |
| 1036 |
|
| 1037 |
/* set next_to_watch value indicating a packet is present */ |
| 1038 |
i++; |
| 1039 |
if (i == ring->count) |
| 1040 |
i = 0; |
| 1041 |
|
| 1042 |
tx_buffer->next_to_watch = tx_desc; |
| 1043 |
ring->next_to_use = i; |
| 1044 |
|
| 1045 |
return IXGBEVF_XDP_TX; |
| 1046 |
} |
| 1047 |
|
| 1048 |
static int ixgbevf_run_xdp(struct ixgbevf_adapter *adapter, |
| 1049 |
struct ixgbevf_ring *rx_ring, |
| 1050 |
struct xdp_buff *xdp) |
| 1051 |
{ |
| 1052 |
int result = IXGBEVF_XDP_PASS; |
| 1053 |
struct ixgbevf_ring *xdp_ring; |
| 1054 |
struct bpf_prog *xdp_prog; |
| 1055 |
u32 act; |
| 1056 |
|
| 1057 |
xdp_prog = READ_ONCE(rx_ring->xdp_prog); |
| 1058 |
|
| 1059 |
if (!xdp_prog) |
| 1060 |
goto xdp_out; |
| 1061 |
|
| 1062 |
act = bpf_prog_run_xdp(xdp_prog, xdp); |
| 1063 |
switch (act) { |
| 1064 |
case XDP_PASS: |
| 1065 |
break; |
| 1066 |
case XDP_TX: |
| 1067 |
xdp_ring = adapter->xdp_ring[rx_ring->queue_index]; |
| 1068 |
result = ixgbevf_xmit_xdp_ring(xdp_ring, xdp); |
| 1069 |
if (result == IXGBEVF_XDP_CONSUMED) |
| 1070 |
goto out_failure; |
| 1071 |
break; |
| 1072 |
default: |
| 1073 |
bpf_warn_invalid_xdp_action(rx_ring->netdev, xdp_prog, act); |
| 1074 |
fallthrough; |
| 1075 |
case XDP_ABORTED: |
| 1076 |
out_failure: |
| 1077 |
trace_xdp_exception(rx_ring->netdev, xdp_prog, act); |
| 1078 |
fallthrough; /* handle aborts by dropping packet */ |
| 1079 |
case XDP_DROP: |
| 1080 |
result = IXGBEVF_XDP_CONSUMED; |
| 1081 |
break; |
| 1082 |
} |
| 1083 |
xdp_out: |
| 1084 |
return result; |
| 1085 |
} |
| 1086 |
|
| 1087 |
static unsigned int ixgbevf_rx_frame_truesize(struct ixgbevf_ring *rx_ring, |
| 1088 |
unsigned int size) |
| 1089 |
{ |
| 1090 |
unsigned int truesize; |
| 1091 |
|
| 1092 |
#if (PAGE_SIZE < 8192) |
| 1093 |
truesize = ixgbevf_rx_pg_size(rx_ring) / 2; /* Must be power-of-2 */ |
| 1094 |
#else |
| 1095 |
truesize = ring_uses_build_skb(rx_ring) ? |
| 1096 |
SKB_DATA_ALIGN(IXGBEVF_SKB_PAD + size) + |
| 1097 |
SKB_DATA_ALIGN(sizeof(struct skb_shared_info)) : |
| 1098 |
SKB_DATA_ALIGN(size); |
| 1099 |
#endif |
| 1100 |
return truesize; |
| 1101 |
} |
| 1102 |
|
| 1103 |
static void ixgbevf_rx_buffer_flip(struct ixgbevf_ring *rx_ring, |
| 1104 |
struct ixgbevf_rx_buffer *rx_buffer, |
| 1105 |
unsigned int size) |
| 1106 |
{ |
| 1107 |
unsigned int truesize = ixgbevf_rx_frame_truesize(rx_ring, size); |
| 1108 |
|
| 1109 |
#if (PAGE_SIZE < 8192) |
| 1110 |
rx_buffer->page_offset ^= truesize; |
| 1111 |
#else |
| 1112 |
rx_buffer->page_offset += truesize; |
| 1113 |
#endif |
| 1114 |
} |
| 1115 |
|
| 1116 |
static int ixgbevf_clean_rx_irq(struct ixgbevf_q_vector *q_vector, |
| 1117 |
struct ixgbevf_ring *rx_ring, |
| 1118 |
int budget) |
| 1119 |
{ |
| 1120 |
unsigned int total_rx_bytes = 0, total_rx_packets = 0, frame_sz = 0; |
| 1121 |
struct ixgbevf_adapter *adapter = q_vector->adapter; |
| 1122 |
u16 cleaned_count = ixgbevf_desc_unused(rx_ring); |
| 1123 |
struct sk_buff *skb = rx_ring->skb; |
| 1124 |
bool xdp_xmit = false; |
| 1125 |
struct xdp_buff xdp; |
| 1126 |
int xdp_res = 0; |
| 1127 |
|
| 1128 |
/* Frame size depend on rx_ring setup when PAGE_SIZE=4K */ |
| 1129 |
#if (PAGE_SIZE < 8192) |
| 1130 |
frame_sz = ixgbevf_rx_frame_truesize(rx_ring, 0); |
| 1131 |
#endif |
| 1132 |
xdp_init_buff(&xdp, frame_sz, &rx_ring->xdp_rxq); |
| 1133 |
|
| 1134 |
while (likely(total_rx_packets < budget)) { |
| 1135 |
struct ixgbevf_rx_buffer *rx_buffer; |
| 1136 |
union ixgbe_adv_rx_desc *rx_desc; |
| 1137 |
unsigned int size; |
| 1138 |
|
| 1139 |
/* return some buffers to hardware, one at a time is too slow */ |
| 1140 |
if (cleaned_count >= IXGBEVF_RX_BUFFER_WRITE) { |
| 1141 |
ixgbevf_alloc_rx_buffers(rx_ring, cleaned_count); |
| 1142 |
cleaned_count = 0; |
| 1143 |
} |
| 1144 |
|
| 1145 |
rx_desc = IXGBEVF_RX_DESC(rx_ring, rx_ring->next_to_clean); |
| 1146 |
size = le16_to_cpu(rx_desc->wb.upper.length); |
| 1147 |
if (!size) |
| 1148 |
break; |
| 1149 |
|
| 1150 |
/* This memory barrier is needed to keep us from reading |
| 1151 |
* any other fields out of the rx_desc until we know the |
| 1152 |
* RXD_STAT_DD bit is set |
| 1153 |
*/ |
| 1154 |
rmb(); |
| 1155 |
|
| 1156 |
rx_buffer = ixgbevf_get_rx_buffer(rx_ring, size); |
| 1157 |
|
| 1158 |
/* retrieve a buffer from the ring */ |
| 1159 |
if (!skb) { |
| 1160 |
unsigned int offset = ixgbevf_rx_offset(rx_ring); |
| 1161 |
unsigned char *hard_start; |
| 1162 |
|
| 1163 |
hard_start = page_address(rx_buffer->page) + |
| 1164 |
rx_buffer->page_offset - offset; |
| 1165 |
xdp_prepare_buff(&xdp, hard_start, offset, size, true); |
| 1166 |
#if (PAGE_SIZE > 4096) |
| 1167 |
/* At larger PAGE_SIZE, frame_sz depend on len size */ |
| 1168 |
xdp.frame_sz = ixgbevf_rx_frame_truesize(rx_ring, size); |
| 1169 |
#endif |
| 1170 |
xdp_res = ixgbevf_run_xdp(adapter, rx_ring, &xdp); |
| 1171 |
} |
| 1172 |
|
| 1173 |
if (xdp_res) { |
| 1174 |
if (xdp_res == IXGBEVF_XDP_TX) { |
| 1175 |
xdp_xmit = true; |
| 1176 |
ixgbevf_rx_buffer_flip(rx_ring, rx_buffer, |
| 1177 |
size); |
| 1178 |
} else { |
| 1179 |
rx_buffer->pagecnt_bias++; |
| 1180 |
} |
| 1181 |
total_rx_packets++; |
| 1182 |
total_rx_bytes += size; |
| 1183 |
} else if (skb) { |
| 1184 |
ixgbevf_add_rx_frag(rx_ring, rx_buffer, skb, size); |
| 1185 |
} else if (ring_uses_build_skb(rx_ring)) { |
| 1186 |
skb = ixgbevf_build_skb(rx_ring, rx_buffer, |
| 1187 |
&xdp, rx_desc); |
| 1188 |
} else { |
| 1189 |
skb = ixgbevf_construct_skb(rx_ring, rx_buffer, |
| 1190 |
&xdp, rx_desc); |
| 1191 |
} |
| 1192 |
|
| 1193 |
/* exit if we failed to retrieve a buffer */ |
| 1194 |
if (!xdp_res && !skb) { |
| 1195 |
rx_ring->rx_stats.alloc_rx_buff_failed++; |
| 1196 |
rx_buffer->pagecnt_bias++; |
| 1197 |
break; |
| 1198 |
} |
| 1199 |
|
| 1200 |
ixgbevf_put_rx_buffer(rx_ring, rx_buffer, skb); |
| 1201 |
cleaned_count++; |
| 1202 |
|
| 1203 |
/* fetch next buffer in frame if non-eop */ |
| 1204 |
if (ixgbevf_is_non_eop(rx_ring, rx_desc)) |
| 1205 |
continue; |
| 1206 |
|
| 1207 |
/* verify the packet layout is correct */ |
| 1208 |
if (xdp_res || ixgbevf_cleanup_headers(rx_ring, rx_desc, skb)) { |
| 1209 |
skb = NULL; |
| 1210 |
continue; |
| 1211 |
} |
| 1212 |
|
| 1213 |
/* probably a little skewed due to removing CRC */ |
| 1214 |
total_rx_bytes += skb->len; |
| 1215 |
|
| 1216 |
/* Workaround hardware that can't do proper VEPA multicast |
| 1217 |
* source pruning. |
| 1218 |
*/ |
| 1219 |
if ((skb->pkt_type == PACKET_BROADCAST || |
| 1220 |
skb->pkt_type == PACKET_MULTICAST) && |
| 1221 |
ether_addr_equal(rx_ring->netdev->dev_addr, |
| 1222 |
eth_hdr(skb)->h_source)) { |
| 1223 |
dev_kfree_skb_irq(skb); |
| 1224 |
skb = NULL; |
| 1225 |
continue; |
| 1226 |
} |
| 1227 |
|
| 1228 |
/* populate checksum, VLAN, and protocol */ |
| 1229 |
ixgbevf_process_skb_fields(rx_ring, rx_desc, skb); |
| 1230 |
|
| 1231 |
ixgbevf_rx_skb(q_vector, skb); |
| 1232 |
|
| 1233 |
/* reset skb pointer */ |
| 1234 |
skb = NULL; |
| 1235 |
|
| 1236 |
/* update budget accounting */ |
| 1237 |
total_rx_packets++; |
| 1238 |
} |
| 1239 |
|
| 1240 |
/* place incomplete frames back on ring for completion */ |
| 1241 |
rx_ring->skb = skb; |
| 1242 |
|
| 1243 |
if (xdp_xmit) { |
| 1244 |
struct ixgbevf_ring *xdp_ring = |
| 1245 |
adapter->xdp_ring[rx_ring->queue_index]; |
| 1246 |
|
| 1247 |
/* Force memory writes to complete before letting h/w |
| 1248 |
* know there are new descriptors to fetch. |
| 1249 |
*/ |
| 1250 |
wmb(); |
| 1251 |
ixgbevf_write_tail(xdp_ring, xdp_ring->next_to_use); |
| 1252 |
} |
| 1253 |
|
| 1254 |
u64_stats_update_begin(&rx_ring->syncp); |
| 1255 |
rx_ring->stats.packets += total_rx_packets; |
| 1256 |
rx_ring->stats.bytes += total_rx_bytes; |
| 1257 |
u64_stats_update_end(&rx_ring->syncp); |
| 1258 |
q_vector->rx.total_packets += total_rx_packets; |
| 1259 |
q_vector->rx.total_bytes += total_rx_bytes; |
| 1260 |
|
| 1261 |
return total_rx_packets; |
| 1262 |
} |
| 1263 |
|
| 1264 |
/** |
| 1265 |
* ixgbevf_poll - NAPI polling calback |
| 1266 |
* @napi: napi struct with our devices info in it |
| 1267 |
* @budget: amount of work driver is allowed to do this pass, in packets |
| 1268 |
* |
| 1269 |
* This function will clean more than one or more rings associated with a |
| 1270 |
* q_vector. |
| 1271 |
**/ |
| 1272 |
static int ixgbevf_poll(struct napi_struct *napi, int budget) |
| 1273 |
{ |
| 1274 |
struct ixgbevf_q_vector *q_vector = |
| 1275 |
container_of(napi, struct ixgbevf_q_vector, napi); |
| 1276 |
struct ixgbevf_adapter *adapter = q_vector->adapter; |
| 1277 |
struct ixgbevf_ring *ring; |
| 1278 |
int per_ring_budget, work_done = 0; |
| 1279 |
bool clean_complete = true; |
| 1280 |
|
| 1281 |
ixgbevf_for_each_ring(ring, q_vector->tx) { |
| 1282 |
if (!ixgbevf_clean_tx_irq(q_vector, ring, budget)) |
| 1283 |
clean_complete = false; |
| 1284 |
} |
| 1285 |
|
| 1286 |
if (budget <= 0) |
| 1287 |
return budget; |
| 1288 |
|
| 1289 |
/* attempt to distribute budget to each queue fairly, but don't allow |
| 1290 |
* the budget to go below 1 because we'll exit polling |
| 1291 |
*/ |
| 1292 |
if (q_vector->rx.count > 1) |
| 1293 |
per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 1294 |
else |
| 1295 |
per_ring_budget = budget; |
| 1296 |
|
| 1297 |
ixgbevf_for_each_ring(ring, q_vector->rx) { |
| 1298 |
int cleaned = ixgbevf_clean_rx_irq(q_vector, ring, |
| 1299 |
per_ring_budget); |
| 1300 |
work_done += cleaned; |
| 1301 |
if (cleaned >= per_ring_budget) |
| 1302 |
clean_complete = false; |
| 1303 |
} |
| 1304 |
|
| 1305 |
/* If all work not completed, return budget and keep polling */ |
| 1306 |
if (!clean_complete) |
| 1307 |
return budget; |
| 1308 |
|
| 1309 |
/* Exit the polling mode, but don't re-enable interrupts if stack might |
| 1310 |
* poll us due to busy-polling |
| 1311 |
*/ |
| 1312 |
if (likely(napi_complete_done(napi, work_done))) { |
| 1313 |
if (adapter->rx_itr_setting == 1) |
| 1314 |
ixgbevf_set_itr(q_vector); |
| 1315 |
if (!test_bit(__IXGBEVF_DOWN, &adapter->state) && |
| 1316 |
!test_bit(__IXGBEVF_REMOVING, &adapter->state)) |
| 1317 |
ixgbevf_irq_enable_queues(adapter, |
| 1318 |
BIT(q_vector->v_idx)); |
| 1319 |
} |
| 1320 |
|
| 1321 |
return min(work_done, budget - 1); |
| 1322 |
} |
| 1323 |
|
| 1324 |
/** |
| 1325 |
* ixgbevf_write_eitr - write VTEITR register in hardware specific way |
| 1326 |
* @q_vector: structure containing interrupt and ring information |
| 1327 |
**/ |
| 1328 |
void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector) |
| 1329 |
{ |
| 1330 |
struct ixgbevf_adapter *adapter = q_vector->adapter; |
| 1331 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1332 |
int v_idx = q_vector->v_idx; |
| 1333 |
u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
| 1334 |
|
| 1335 |
/* set the WDIS bit to not clear the timer bits and cause an |
| 1336 |
* immediate assertion of the interrupt |
| 1337 |
*/ |
| 1338 |
itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 1339 |
|
| 1340 |
IXGBE_WRITE_REG(hw, IXGBE_VTEITR(v_idx), itr_reg); |
| 1341 |
} |
| 1342 |
|
| 1343 |
/** |
| 1344 |
* ixgbevf_configure_msix - Configure MSI-X hardware |
| 1345 |
* @adapter: board private structure |
| 1346 |
* |
| 1347 |
* ixgbevf_configure_msix sets up the hardware to properly generate MSI-X |
| 1348 |
* interrupts. |
| 1349 |
**/ |
| 1350 |
static void ixgbevf_configure_msix(struct ixgbevf_adapter *adapter) |
| 1351 |
{ |
| 1352 |
struct ixgbevf_q_vector *q_vector; |
| 1353 |
int q_vectors, v_idx; |
| 1354 |
|
| 1355 |
q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1356 |
adapter->eims_enable_mask = 0; |
| 1357 |
|
| 1358 |
/* Populate the IVAR table and set the ITR values to the |
| 1359 |
* corresponding register. |
| 1360 |
*/ |
| 1361 |
for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
| 1362 |
struct ixgbevf_ring *ring; |
| 1363 |
|
| 1364 |
q_vector = adapter->q_vector[v_idx]; |
| 1365 |
|
| 1366 |
ixgbevf_for_each_ring(ring, q_vector->rx) |
| 1367 |
ixgbevf_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
| 1368 |
|
| 1369 |
ixgbevf_for_each_ring(ring, q_vector->tx) |
| 1370 |
ixgbevf_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
| 1371 |
|
| 1372 |
if (q_vector->tx.ring && !q_vector->rx.ring) { |
| 1373 |
/* Tx only vector */ |
| 1374 |
if (adapter->tx_itr_setting == 1) |
| 1375 |
q_vector->itr = IXGBE_12K_ITR; |
| 1376 |
else |
| 1377 |
q_vector->itr = adapter->tx_itr_setting; |
| 1378 |
} else { |
| 1379 |
/* Rx or Rx/Tx vector */ |
| 1380 |
if (adapter->rx_itr_setting == 1) |
| 1381 |
q_vector->itr = IXGBE_20K_ITR; |
| 1382 |
else |
| 1383 |
q_vector->itr = adapter->rx_itr_setting; |
| 1384 |
} |
| 1385 |
|
| 1386 |
/* add q_vector eims value to global eims_enable_mask */ |
| 1387 |
adapter->eims_enable_mask |= BIT(v_idx); |
| 1388 |
|
| 1389 |
ixgbevf_write_eitr(q_vector); |
| 1390 |
} |
| 1391 |
|
| 1392 |
ixgbevf_set_ivar(adapter, -1, 1, v_idx); |
| 1393 |
/* setup eims_other and add value to global eims_enable_mask */ |
| 1394 |
adapter->eims_other = BIT(v_idx); |
| 1395 |
adapter->eims_enable_mask |= adapter->eims_other; |
| 1396 |
} |
| 1397 |
|
| 1398 |
enum latency_range { |
| 1399 |
lowest_latency = 0, |
| 1400 |
low_latency = 1, |
| 1401 |
bulk_latency = 2, |
| 1402 |
latency_invalid = 255 |
| 1403 |
}; |
| 1404 |
|
| 1405 |
/** |
| 1406 |
* ixgbevf_update_itr - update the dynamic ITR value based on statistics |
| 1407 |
* @q_vector: structure containing interrupt and ring information |
| 1408 |
* @ring_container: structure containing ring performance data |
| 1409 |
* |
| 1410 |
* Stores a new ITR value based on packets and byte |
| 1411 |
* counts during the last interrupt. The advantage of per interrupt |
| 1412 |
* computation is faster updates and more accurate ITR for the current |
| 1413 |
* traffic pattern. Constants in this function were computed |
| 1414 |
* based on theoretical maximum wire speed and thresholds were set based |
| 1415 |
* on testing data as well as attempting to minimize response time |
| 1416 |
* while increasing bulk throughput. |
| 1417 |
**/ |
| 1418 |
static void ixgbevf_update_itr(struct ixgbevf_q_vector *q_vector, |
| 1419 |
struct ixgbevf_ring_container *ring_container) |
| 1420 |
{ |
| 1421 |
int bytes = ring_container->total_bytes; |
| 1422 |
int packets = ring_container->total_packets; |
| 1423 |
u32 timepassed_us; |
| 1424 |
u64 bytes_perint; |
| 1425 |
u8 itr_setting = ring_container->itr; |
| 1426 |
|
| 1427 |
if (packets == 0) |
| 1428 |
return; |
| 1429 |
|
| 1430 |
/* simple throttle rate management |
| 1431 |
* 0-20MB/s lowest (100000 ints/s) |
| 1432 |
* 20-100MB/s low (20000 ints/s) |
| 1433 |
* 100-1249MB/s bulk (12000 ints/s) |
| 1434 |
*/ |
| 1435 |
/* what was last interrupt timeslice? */ |
| 1436 |
timepassed_us = q_vector->itr >> 2; |
| 1437 |
if (timepassed_us == 0) |
| 1438 |
return; |
| 1439 |
|
| 1440 |
bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1441 |
|
| 1442 |
switch (itr_setting) { |
| 1443 |
case lowest_latency: |
| 1444 |
if (bytes_perint > 10) |
| 1445 |
itr_setting = low_latency; |
| 1446 |
break; |
| 1447 |
case low_latency: |
| 1448 |
if (bytes_perint > 20) |
| 1449 |
itr_setting = bulk_latency; |
| 1450 |
else if (bytes_perint <= 10) |
| 1451 |
itr_setting = lowest_latency; |
| 1452 |
break; |
| 1453 |
case bulk_latency: |
| 1454 |
if (bytes_perint <= 20) |
| 1455 |
itr_setting = low_latency; |
| 1456 |
break; |
| 1457 |
} |
| 1458 |
|
| 1459 |
/* clear work counters since we have the values we need */ |
| 1460 |
ring_container->total_bytes = 0; |
| 1461 |
ring_container->total_packets = 0; |
| 1462 |
|
| 1463 |
/* write updated itr to ring container */ |
| 1464 |
ring_container->itr = itr_setting; |
| 1465 |
} |
| 1466 |
|
| 1467 |
static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector) |
| 1468 |
{ |
| 1469 |
u32 new_itr = q_vector->itr; |
| 1470 |
u8 current_itr; |
| 1471 |
|
| 1472 |
ixgbevf_update_itr(q_vector, &q_vector->tx); |
| 1473 |
ixgbevf_update_itr(q_vector, &q_vector->rx); |
| 1474 |
|
| 1475 |
current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
| 1476 |
|
| 1477 |
switch (current_itr) { |
| 1478 |
/* counts and packets in update_itr are dependent on these numbers */ |
| 1479 |
case lowest_latency: |
| 1480 |
new_itr = IXGBE_100K_ITR; |
| 1481 |
break; |
| 1482 |
case low_latency: |
| 1483 |
new_itr = IXGBE_20K_ITR; |
| 1484 |
break; |
| 1485 |
case bulk_latency: |
| 1486 |
new_itr = IXGBE_12K_ITR; |
| 1487 |
break; |
| 1488 |
default: |
| 1489 |
break; |
| 1490 |
} |
| 1491 |
|
| 1492 |
if (new_itr != q_vector->itr) { |
| 1493 |
/* do an exponential smoothing */ |
| 1494 |
new_itr = (10 * new_itr * q_vector->itr) / |
| 1495 |
((9 * new_itr) + q_vector->itr); |
| 1496 |
|
| 1497 |
/* save the algorithm value here */ |
| 1498 |
q_vector->itr = new_itr; |
| 1499 |
|
| 1500 |
ixgbevf_write_eitr(q_vector); |
| 1501 |
} |
| 1502 |
} |
| 1503 |
|
| 1504 |
static irqreturn_t ixgbevf_msix_other(int irq, void *data) |
| 1505 |
{ |
| 1506 |
struct ixgbevf_adapter *adapter = data; |
| 1507 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1508 |
|
| 1509 |
hw->mac.get_link_status = 1; |
| 1510 |
|
| 1511 |
ixgbevf_service_event_schedule(adapter); |
| 1512 |
|
| 1513 |
IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, adapter->eims_other); |
| 1514 |
|
| 1515 |
return IRQ_HANDLED; |
| 1516 |
} |
| 1517 |
|
| 1518 |
/** |
| 1519 |
* ixgbevf_msix_clean_rings - single unshared vector rx clean (all queues) |
| 1520 |
* @irq: unused |
| 1521 |
* @data: pointer to our q_vector struct for this interrupt vector |
| 1522 |
**/ |
| 1523 |
static irqreturn_t ixgbevf_msix_clean_rings(int irq, void *data) |
| 1524 |
{ |
| 1525 |
struct ixgbevf_q_vector *q_vector = data; |
| 1526 |
|
| 1527 |
/* EIAM disabled interrupts (on this vector) for us */ |
| 1528 |
if (q_vector->rx.ring || q_vector->tx.ring) |
| 1529 |
napi_schedule_irqoff(&q_vector->napi); |
| 1530 |
|
| 1531 |
return IRQ_HANDLED; |
| 1532 |
} |
| 1533 |
|
| 1534 |
/** |
| 1535 |
* ixgbevf_request_msix_irqs - Initialize MSI-X interrupts |
| 1536 |
* @adapter: board private structure |
| 1537 |
* |
| 1538 |
* ixgbevf_request_msix_irqs allocates MSI-X vectors and requests |
| 1539 |
* interrupts from the kernel. |
| 1540 |
**/ |
| 1541 |
static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter *adapter) |
| 1542 |
{ |
| 1543 |
struct net_device *netdev = adapter->netdev; |
| 1544 |
int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1545 |
unsigned int ri = 0, ti = 0; |
| 1546 |
int vector, err; |
| 1547 |
|
| 1548 |
for (vector = 0; vector < q_vectors; vector++) { |
| 1549 |
struct ixgbevf_q_vector *q_vector = adapter->q_vector[vector]; |
| 1550 |
struct msix_entry *entry = &adapter->msix_entries[vector]; |
| 1551 |
|
| 1552 |
if (q_vector->tx.ring && q_vector->rx.ring) { |
| 1553 |
snprintf(q_vector->name, sizeof(q_vector->name), |
| 1554 |
"%s-TxRx-%u", netdev->name, ri++); |
| 1555 |
ti++; |
| 1556 |
} else if (q_vector->rx.ring) { |
| 1557 |
snprintf(q_vector->name, sizeof(q_vector->name), |
| 1558 |
"%s-rx-%u", netdev->name, ri++); |
| 1559 |
} else if (q_vector->tx.ring) { |
| 1560 |
snprintf(q_vector->name, sizeof(q_vector->name), |
| 1561 |
"%s-tx-%u", netdev->name, ti++); |
| 1562 |
} else { |
| 1563 |
/* skip this unused q_vector */ |
| 1564 |
continue; |
| 1565 |
} |
| 1566 |
err = request_irq(entry->vector, &ixgbevf_msix_clean_rings, 0, |
| 1567 |
q_vector->name, q_vector); |
| 1568 |
if (err) { |
| 1569 |
hw_dbg(&adapter->hw, |
| 1570 |
"request_irq failed for MSIX interrupt Error: %d\n", |
| 1571 |
err); |
| 1572 |
goto free_queue_irqs; |
| 1573 |
} |
| 1574 |
} |
| 1575 |
|
| 1576 |
err = request_irq(adapter->msix_entries[vector].vector, |
| 1577 |
&ixgbevf_msix_other, 0, netdev->name, adapter); |
| 1578 |
if (err) { |
| 1579 |
hw_dbg(&adapter->hw, "request_irq for msix_other failed: %d\n", |
| 1580 |
err); |
| 1581 |
goto free_queue_irqs; |
| 1582 |
} |
| 1583 |
|
| 1584 |
return 0; |
| 1585 |
|
| 1586 |
free_queue_irqs: |
| 1587 |
while (vector) { |
| 1588 |
vector--; |
| 1589 |
free_irq(adapter->msix_entries[vector].vector, |
| 1590 |
adapter->q_vector[vector]); |
| 1591 |
} |
| 1592 |
/* This failure is non-recoverable - it indicates the system is |
| 1593 |
* out of MSIX vector resources and the VF driver cannot run |
| 1594 |
* without them. Set the number of msix vectors to zero |
| 1595 |
* indicating that not enough can be allocated. The error |
| 1596 |
* will be returned to the user indicating device open failed. |
| 1597 |
* Any further attempts to force the driver to open will also |
| 1598 |
* fail. The only way to recover is to unload the driver and |
| 1599 |
* reload it again. If the system has recovered some MSIX |
| 1600 |
* vectors then it may succeed. |
| 1601 |
*/ |
| 1602 |
adapter->num_msix_vectors = 0; |
| 1603 |
return err; |
| 1604 |
} |
| 1605 |
|
| 1606 |
/** |
| 1607 |
* ixgbevf_request_irq - initialize interrupts |
| 1608 |
* @adapter: board private structure |
| 1609 |
* |
| 1610 |
* Attempts to configure interrupts using the best available |
| 1611 |
* capabilities of the hardware and kernel. |
| 1612 |
**/ |
| 1613 |
static int ixgbevf_request_irq(struct ixgbevf_adapter *adapter) |
| 1614 |
{ |
| 1615 |
int err = ixgbevf_request_msix_irqs(adapter); |
| 1616 |
|
| 1617 |
if (err) |
| 1618 |
hw_dbg(&adapter->hw, "request_irq failed, Error %d\n", err); |
| 1619 |
|
| 1620 |
return err; |
| 1621 |
} |
| 1622 |
|
| 1623 |
static void ixgbevf_free_irq(struct ixgbevf_adapter *adapter) |
| 1624 |
{ |
| 1625 |
int i, q_vectors; |
| 1626 |
|
| 1627 |
if (!adapter->msix_entries) |
| 1628 |
return; |
| 1629 |
|
| 1630 |
q_vectors = adapter->num_msix_vectors; |
| 1631 |
i = q_vectors - 1; |
| 1632 |
|
| 1633 |
free_irq(adapter->msix_entries[i].vector, adapter); |
| 1634 |
i--; |
| 1635 |
|
| 1636 |
for (; i >= 0; i--) { |
| 1637 |
/* free only the irqs that were actually requested */ |
| 1638 |
if (!adapter->q_vector[i]->rx.ring && |
| 1639 |
!adapter->q_vector[i]->tx.ring) |
| 1640 |
continue; |
| 1641 |
|
| 1642 |
free_irq(adapter->msix_entries[i].vector, |
| 1643 |
adapter->q_vector[i]); |
| 1644 |
} |
| 1645 |
} |
| 1646 |
|
| 1647 |
/** |
| 1648 |
* ixgbevf_irq_disable - Mask off interrupt generation on the NIC |
| 1649 |
* @adapter: board private structure |
| 1650 |
**/ |
| 1651 |
static inline void ixgbevf_irq_disable(struct ixgbevf_adapter *adapter) |
| 1652 |
{ |
| 1653 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1654 |
int i; |
| 1655 |
|
| 1656 |
IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, 0); |
| 1657 |
IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, ~0); |
| 1658 |
IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, 0); |
| 1659 |
|
| 1660 |
IXGBE_WRITE_FLUSH(hw); |
| 1661 |
|
| 1662 |
for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1663 |
synchronize_irq(adapter->msix_entries[i].vector); |
| 1664 |
} |
| 1665 |
|
| 1666 |
/** |
| 1667 |
* ixgbevf_irq_enable - Enable default interrupt generation settings |
| 1668 |
* @adapter: board private structure |
| 1669 |
**/ |
| 1670 |
static inline void ixgbevf_irq_enable(struct ixgbevf_adapter *adapter) |
| 1671 |
{ |
| 1672 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1673 |
|
| 1674 |
IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, adapter->eims_enable_mask); |
| 1675 |
IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, adapter->eims_enable_mask); |
| 1676 |
IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, adapter->eims_enable_mask); |
| 1677 |
} |
| 1678 |
|
| 1679 |
/** |
| 1680 |
* ixgbevf_configure_tx_ring - Configure 82599 VF Tx ring after Reset |
| 1681 |
* @adapter: board private structure |
| 1682 |
* @ring: structure containing ring specific data |
| 1683 |
* |
| 1684 |
* Configure the Tx descriptor ring after a reset. |
| 1685 |
**/ |
| 1686 |
static void ixgbevf_configure_tx_ring(struct ixgbevf_adapter *adapter, |
| 1687 |
struct ixgbevf_ring *ring) |
| 1688 |
{ |
| 1689 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1690 |
u64 tdba = ring->dma; |
| 1691 |
int wait_loop = 10; |
| 1692 |
u32 txdctl = IXGBE_TXDCTL_ENABLE; |
| 1693 |
u8 reg_idx = ring->reg_idx; |
| 1694 |
|
| 1695 |
/* disable queue to avoid issues while updating state */ |
| 1696 |
IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH); |
| 1697 |
IXGBE_WRITE_FLUSH(hw); |
| 1698 |
|
| 1699 |
IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(reg_idx), tdba & DMA_BIT_MASK(32)); |
| 1700 |
IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(reg_idx), tdba >> 32); |
| 1701 |
IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(reg_idx), |
| 1702 |
ring->count * sizeof(union ixgbe_adv_tx_desc)); |
| 1703 |
|
| 1704 |
/* disable head writeback */ |
| 1705 |
IXGBE_WRITE_REG(hw, IXGBE_VFTDWBAH(reg_idx), 0); |
| 1706 |
IXGBE_WRITE_REG(hw, IXGBE_VFTDWBAL(reg_idx), 0); |
| 1707 |
|
| 1708 |
/* enable relaxed ordering */ |
| 1709 |
IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(reg_idx), |
| 1710 |
(IXGBE_DCA_TXCTRL_DESC_RRO_EN | |
| 1711 |
IXGBE_DCA_TXCTRL_DATA_RRO_EN)); |
| 1712 |
|
| 1713 |
/* reset head and tail pointers */ |
| 1714 |
IXGBE_WRITE_REG(hw, IXGBE_VFTDH(reg_idx), 0); |
| 1715 |
IXGBE_WRITE_REG(hw, IXGBE_VFTDT(reg_idx), 0); |
| 1716 |
ring->tail = adapter->io_addr + IXGBE_VFTDT(reg_idx); |
| 1717 |
|
| 1718 |
/* reset ntu and ntc to place SW in sync with hardwdare */ |
| 1719 |
ring->next_to_clean = 0; |
| 1720 |
ring->next_to_use = 0; |
| 1721 |
|
| 1722 |
/* In order to avoid issues WTHRESH + PTHRESH should always be equal |
| 1723 |
* to or less than the number of on chip descriptors, which is |
| 1724 |
* currently 40. |
| 1725 |
*/ |
| 1726 |
txdctl |= (8 << 16); /* WTHRESH = 8 */ |
| 1727 |
|
| 1728 |
/* Setting PTHRESH to 32 both improves performance */ |
| 1729 |
txdctl |= (1u << 8) | /* HTHRESH = 1 */ |
| 1730 |
32; /* PTHRESH = 32 */ |
| 1731 |
|
| 1732 |
/* reinitialize tx_buffer_info */ |
| 1733 |
memset(ring->tx_buffer_info, 0, |
| 1734 |
sizeof(struct ixgbevf_tx_buffer) * ring->count); |
| 1735 |
|
| 1736 |
clear_bit(__IXGBEVF_HANG_CHECK_ARMED, &ring->state); |
| 1737 |
clear_bit(__IXGBEVF_TX_XDP_RING_PRIMED, &ring->state); |
| 1738 |
|
| 1739 |
IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(reg_idx), txdctl); |
| 1740 |
|
| 1741 |
/* poll to verify queue is enabled */ |
| 1742 |
do { |
| 1743 |
usleep_range(1000, 2000); |
| 1744 |
txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(reg_idx)); |
| 1745 |
} while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 1746 |
if (!wait_loop) |
| 1747 |
hw_dbg(hw, "Could not enable Tx Queue %d\n", reg_idx); |
| 1748 |
} |
| 1749 |
|
| 1750 |
/** |
| 1751 |
* ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset |
| 1752 |
* @adapter: board private structure |
| 1753 |
* |
| 1754 |
* Configure the Tx unit of the MAC after a reset. |
| 1755 |
**/ |
| 1756 |
static void ixgbevf_configure_tx(struct ixgbevf_adapter *adapter) |
| 1757 |
{ |
| 1758 |
u32 i; |
| 1759 |
|
| 1760 |
/* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1761 |
for (i = 0; i < adapter->num_tx_queues; i++) |
| 1762 |
ixgbevf_configure_tx_ring(adapter, adapter->tx_ring[i]); |
| 1763 |
for (i = 0; i < adapter->num_xdp_queues; i++) |
| 1764 |
ixgbevf_configure_tx_ring(adapter, adapter->xdp_ring[i]); |
| 1765 |
} |
| 1766 |
|
| 1767 |
#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
| 1768 |
|
| 1769 |
static void ixgbevf_configure_srrctl(struct ixgbevf_adapter *adapter, |
| 1770 |
struct ixgbevf_ring *ring, int index) |
| 1771 |
{ |
| 1772 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1773 |
u32 srrctl; |
| 1774 |
|
| 1775 |
srrctl = IXGBE_SRRCTL_DROP_EN; |
| 1776 |
|
| 1777 |
srrctl |= IXGBEVF_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT; |
| 1778 |
if (ring_uses_large_buffer(ring)) |
| 1779 |
srrctl |= IXGBEVF_RXBUFFER_3072 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1780 |
else |
| 1781 |
srrctl |= IXGBEVF_RXBUFFER_2048 >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1782 |
srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
| 1783 |
|
| 1784 |
IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(index), srrctl); |
| 1785 |
} |
| 1786 |
|
| 1787 |
static void ixgbevf_setup_psrtype(struct ixgbevf_adapter *adapter) |
| 1788 |
{ |
| 1789 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1790 |
|
| 1791 |
/* PSRTYPE must be initialized in 82599 */ |
| 1792 |
u32 psrtype = IXGBE_PSRTYPE_TCPHDR | IXGBE_PSRTYPE_UDPHDR | |
| 1793 |
IXGBE_PSRTYPE_IPV4HDR | IXGBE_PSRTYPE_IPV6HDR | |
| 1794 |
IXGBE_PSRTYPE_L2HDR; |
| 1795 |
|
| 1796 |
if (adapter->num_rx_queues > 1) |
| 1797 |
psrtype |= BIT(29); |
| 1798 |
|
| 1799 |
IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, psrtype); |
| 1800 |
} |
| 1801 |
|
| 1802 |
#define IXGBEVF_MAX_RX_DESC_POLL 10 |
| 1803 |
static void ixgbevf_disable_rx_queue(struct ixgbevf_adapter *adapter, |
| 1804 |
struct ixgbevf_ring *ring) |
| 1805 |
{ |
| 1806 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1807 |
int wait_loop = IXGBEVF_MAX_RX_DESC_POLL; |
| 1808 |
u32 rxdctl; |
| 1809 |
u8 reg_idx = ring->reg_idx; |
| 1810 |
|
| 1811 |
if (IXGBE_REMOVED(hw->hw_addr)) |
| 1812 |
return; |
| 1813 |
rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(reg_idx)); |
| 1814 |
rxdctl &= ~IXGBE_RXDCTL_ENABLE; |
| 1815 |
|
| 1816 |
/* write value back with RXDCTL.ENABLE bit cleared */ |
| 1817 |
IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(reg_idx), rxdctl); |
| 1818 |
|
| 1819 |
/* the hardware may take up to 100us to really disable the Rx queue */ |
| 1820 |
do { |
| 1821 |
udelay(10); |
| 1822 |
rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(reg_idx)); |
| 1823 |
} while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 1824 |
|
| 1825 |
if (!wait_loop) |
| 1826 |
pr_err("RXDCTL.ENABLE queue %d not cleared while polling\n", |
| 1827 |
reg_idx); |
| 1828 |
} |
| 1829 |
|
| 1830 |
static void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter *adapter, |
| 1831 |
struct ixgbevf_ring *ring) |
| 1832 |
{ |
| 1833 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1834 |
int wait_loop = IXGBEVF_MAX_RX_DESC_POLL; |
| 1835 |
u32 rxdctl; |
| 1836 |
u8 reg_idx = ring->reg_idx; |
| 1837 |
|
| 1838 |
if (IXGBE_REMOVED(hw->hw_addr)) |
| 1839 |
return; |
| 1840 |
do { |
| 1841 |
usleep_range(1000, 2000); |
| 1842 |
rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(reg_idx)); |
| 1843 |
} while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE)); |
| 1844 |
|
| 1845 |
if (!wait_loop) |
| 1846 |
pr_err("RXDCTL.ENABLE queue %d not set while polling\n", |
| 1847 |
reg_idx); |
| 1848 |
} |
| 1849 |
|
| 1850 |
/** |
| 1851 |
* ixgbevf_init_rss_key - Initialize adapter RSS key |
| 1852 |
* @adapter: device handle |
| 1853 |
* |
| 1854 |
* Allocates and initializes the RSS key if it is not allocated. |
| 1855 |
**/ |
| 1856 |
static inline int ixgbevf_init_rss_key(struct ixgbevf_adapter *adapter) |
| 1857 |
{ |
| 1858 |
u32 *rss_key; |
| 1859 |
|
| 1860 |
if (!adapter->rss_key) { |
| 1861 |
rss_key = kzalloc(IXGBEVF_RSS_HASH_KEY_SIZE, GFP_KERNEL); |
| 1862 |
if (unlikely(!rss_key)) |
| 1863 |
return -ENOMEM; |
| 1864 |
|
| 1865 |
netdev_rss_key_fill(rss_key, IXGBEVF_RSS_HASH_KEY_SIZE); |
| 1866 |
adapter->rss_key = rss_key; |
| 1867 |
} |
| 1868 |
|
| 1869 |
return 0; |
| 1870 |
} |
| 1871 |
|
| 1872 |
static void ixgbevf_setup_vfmrqc(struct ixgbevf_adapter *adapter) |
| 1873 |
{ |
| 1874 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1875 |
u32 vfmrqc = 0, vfreta = 0; |
| 1876 |
u16 rss_i = adapter->num_rx_queues; |
| 1877 |
u8 i, j; |
| 1878 |
|
| 1879 |
/* Fill out hash function seeds */ |
| 1880 |
for (i = 0; i < IXGBEVF_VFRSSRK_REGS; i++) |
| 1881 |
IXGBE_WRITE_REG(hw, IXGBE_VFRSSRK(i), *(adapter->rss_key + i)); |
| 1882 |
|
| 1883 |
for (i = 0, j = 0; i < IXGBEVF_X550_VFRETA_SIZE; i++, j++) { |
| 1884 |
if (j == rss_i) |
| 1885 |
j = 0; |
| 1886 |
|
| 1887 |
adapter->rss_indir_tbl[i] = j; |
| 1888 |
|
| 1889 |
vfreta |= j << (i & 0x3) * 8; |
| 1890 |
if ((i & 3) == 3) { |
| 1891 |
IXGBE_WRITE_REG(hw, IXGBE_VFRETA(i >> 2), vfreta); |
| 1892 |
vfreta = 0; |
| 1893 |
} |
| 1894 |
} |
| 1895 |
|
| 1896 |
/* Perform hash on these packet types */ |
| 1897 |
vfmrqc |= IXGBE_VFMRQC_RSS_FIELD_IPV4 | |
| 1898 |
IXGBE_VFMRQC_RSS_FIELD_IPV4_TCP | |
| 1899 |
IXGBE_VFMRQC_RSS_FIELD_IPV6 | |
| 1900 |
IXGBE_VFMRQC_RSS_FIELD_IPV6_TCP; |
| 1901 |
|
| 1902 |
vfmrqc |= IXGBE_VFMRQC_RSSEN; |
| 1903 |
|
| 1904 |
IXGBE_WRITE_REG(hw, IXGBE_VFMRQC, vfmrqc); |
| 1905 |
} |
| 1906 |
|
| 1907 |
static void ixgbevf_configure_rx_ring(struct ixgbevf_adapter *adapter, |
| 1908 |
struct ixgbevf_ring *ring) |
| 1909 |
{ |
| 1910 |
struct ixgbe_hw *hw = &adapter->hw; |
| 1911 |
union ixgbe_adv_rx_desc *rx_desc; |
| 1912 |
u64 rdba = ring->dma; |
| 1913 |
u32 rxdctl; |
| 1914 |
u8 reg_idx = ring->reg_idx; |
| 1915 |
|
| 1916 |
/* disable queue to avoid issues while updating state */ |
| 1917 |
rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(reg_idx)); |
| 1918 |
ixgbevf_disable_rx_queue(adapter, ring); |
| 1919 |
|
| 1920 |
IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(reg_idx), rdba & DMA_BIT_MASK(32)); |
| 1921 |
IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(reg_idx), rdba >> 32); |
| 1922 |
IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(reg_idx), |
| 1923 |
ring->count * sizeof(union ixgbe_adv_rx_desc)); |
| 1924 |
|
| 1925 |
#ifndef CONFIG_SPARC |
| 1926 |
/* enable relaxed ordering */ |
| 1927 |
IXGBE_WRITE_REG(hw, IXGBE_VFDCA_RXCTRL(reg_idx), |
| 1928 |
IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 1929 |
#else |
| 1930 |
IXGBE_WRITE_REG(hw, IXGBE_VFDCA_RXCTRL(reg_idx), |
| 1931 |
IXGBE_DCA_RXCTRL_DESC_RRO_EN | |
| 1932 |
IXGBE_DCA_RXCTRL_DATA_WRO_EN); |
| 1933 |
#endif |
| 1934 |
|
| 1935 |
/* reset head and tail pointers */ |
| 1936 |
IXGBE_WRITE_REG(hw, IXGBE_VFRDH(reg_idx), 0); |
| 1937 |
IXGBE_WRITE_REG(hw, IXGBE_VFRDT(reg_idx), 0); |
| 1938 |
ring->tail = adapter->io_addr + IXGBE_VFRDT(reg_idx); |
| 1939 |
|
| 1940 |
/* initialize rx_buffer_info */ |
| 1941 |
memset(ring->rx_buffer_info, 0, |
| 1942 |
sizeof(struct ixgbevf_rx_buffer) * ring->count); |
| 1943 |
|
| 1944 |
/* initialize Rx descriptor 0 */ |
| 1945 |
rx_desc = IXGBEVF_RX_DESC(ring, 0); |
| 1946 |
rx_desc->wb.upper.length = 0; |
| 1947 |
|
| 1948 |
/* reset ntu and ntc to place SW in sync with hardwdare */ |
| 1949 |
ring->next_to_clean = 0; |
| 1950 |
ring->next_to_use = 0; |
| 1951 |
ring->next_to_alloc = 0; |
| 1952 |
|
| 1953 |
ixgbevf_configure_srrctl(adapter, ring, reg_idx); |
| 1954 |
|
| 1955 |
/* RXDCTL.RLPML does not work on 82599 */ |
| 1956 |
if (adapter->hw.mac.type != ixgbe_mac_82599_vf) { |
| 1957 |
rxdctl &= ~(IXGBE_RXDCTL_RLPMLMASK | |
| 1958 |
IXGBE_RXDCTL_RLPML_EN); |
| 1959 |
|
| 1960 |
#if (PAGE_SIZE < 8192) |
| 1961 |
/* Limit the maximum frame size so we don't overrun the skb */ |
| 1962 |
if (ring_uses_build_skb(ring) && |
| 1963 |
!ring_uses_large_buffer(ring)) |
| 1964 |
rxdctl |= IXGBEVF_MAX_FRAME_BUILD_SKB | |
| 1965 |
IXGBE_RXDCTL_RLPML_EN; |
| 1966 |
#endif |
| 1967 |
} |
| 1968 |
|
| 1969 |
rxdctl |= IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME; |
| 1970 |
IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(reg_idx), rxdctl); |
| 1971 |
|
| 1972 |
ixgbevf_rx_desc_queue_enable(adapter, ring); |
| 1973 |
ixgbevf_alloc_rx_buffers(ring, ixgbevf_desc_unused(ring)); |
| 1974 |
} |
| 1975 |
|
| 1976 |
static void ixgbevf_set_rx_buffer_len(struct ixgbevf_adapter *adapter, |
| 1977 |
struct ixgbevf_ring *rx_ring) |
| 1978 |
{ |
| 1979 |
struct net_device *netdev = adapter->netdev; |
| 1980 |
unsigned int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 1981 |
|
| 1982 |
/* set build_skb and buffer size flags */ |
| 1983 |
clear_ring_build_skb_enabled(rx_ring); |
| 1984 |
clear_ring_uses_large_buffer(rx_ring); |
| 1985 |
|
| 1986 |
if (adapter->flags & IXGBEVF_FLAGS_LEGACY_RX) |
| 1987 |
return; |
| 1988 |
|
| 1989 |
if (PAGE_SIZE < 8192) |
| 1990 |
if (max_frame > IXGBEVF_MAX_FRAME_BUILD_SKB) |
| 1991 |
set_ring_uses_large_buffer(rx_ring); |
| 1992 |
|
| 1993 |
/* 82599 can't rely on RXDCTL.RLPML to restrict the size of the frame */ |
| 1994 |
if (adapter->hw.mac.type == ixgbe_mac_82599_vf && !ring_uses_large_buffer(rx_ring)) |
| 1995 |
return; |
| 1996 |
|
| 1997 |
set_ring_build_skb_enabled(rx_ring); |
| 1998 |
} |
| 1999 |
|
| 2000 |
/** |
| 2001 |
* ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset |
| 2002 |
* @adapter: board private structure |
| 2003 |
* |
| 2004 |
* Configure the Rx unit of the MAC after a reset. |
| 2005 |
**/ |
| 2006 |
static void ixgbevf_configure_rx(struct ixgbevf_adapter *adapter) |
| 2007 |
{ |
| 2008 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2009 |
struct net_device *netdev = adapter->netdev; |
| 2010 |
int i, ret; |
| 2011 |
|
| 2012 |
ixgbevf_setup_psrtype(adapter); |
| 2013 |
if (hw->mac.type >= ixgbe_mac_X550_vf) |
| 2014 |
ixgbevf_setup_vfmrqc(adapter); |
| 2015 |
|
| 2016 |
spin_lock_bh(&adapter->mbx_lock); |
| 2017 |
/* notify the PF of our intent to use this size of frame */ |
| 2018 |
ret = hw->mac.ops.set_rlpml(hw, netdev->mtu + ETH_HLEN + ETH_FCS_LEN); |
| 2019 |
spin_unlock_bh(&adapter->mbx_lock); |
| 2020 |
if (ret) |
| 2021 |
dev_err(&adapter->pdev->dev, |
| 2022 |
"Failed to set MTU at %d\n", netdev->mtu); |
| 2023 |
|
| 2024 |
/* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2025 |
* the Base and Length of the Rx Descriptor Ring |
| 2026 |
*/ |
| 2027 |
for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2028 |
struct ixgbevf_ring *rx_ring = adapter->rx_ring[i]; |
| 2029 |
|
| 2030 |
ixgbevf_set_rx_buffer_len(adapter, rx_ring); |
| 2031 |
ixgbevf_configure_rx_ring(adapter, rx_ring); |
| 2032 |
} |
| 2033 |
} |
| 2034 |
|
| 2035 |
static int ixgbevf_vlan_rx_add_vid(struct net_device *netdev, |
| 2036 |
__be16 proto, u16 vid) |
| 2037 |
{ |
| 2038 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 2039 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2040 |
int err; |
| 2041 |
|
| 2042 |
spin_lock_bh(&adapter->mbx_lock); |
| 2043 |
|
| 2044 |
/* add VID to filter table */ |
| 2045 |
err = hw->mac.ops.set_vfta(hw, vid, 0, true); |
| 2046 |
|
| 2047 |
spin_unlock_bh(&adapter->mbx_lock); |
| 2048 |
|
| 2049 |
if (err) { |
| 2050 |
netdev_err(netdev, "VF could not set VLAN %d\n", vid); |
| 2051 |
|
| 2052 |
/* translate error return types so error makes sense */ |
| 2053 |
if (err == IXGBE_ERR_MBX) |
| 2054 |
return -EIO; |
| 2055 |
|
| 2056 |
if (err == IXGBE_ERR_INVALID_ARGUMENT) |
| 2057 |
return -EACCES; |
| 2058 |
} |
| 2059 |
|
| 2060 |
set_bit(vid, adapter->active_vlans); |
| 2061 |
|
| 2062 |
return err; |
| 2063 |
} |
| 2064 |
|
| 2065 |
static int ixgbevf_vlan_rx_kill_vid(struct net_device *netdev, |
| 2066 |
__be16 proto, u16 vid) |
| 2067 |
{ |
| 2068 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 2069 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2070 |
int err; |
| 2071 |
|
| 2072 |
spin_lock_bh(&adapter->mbx_lock); |
| 2073 |
|
| 2074 |
/* remove VID from filter table */ |
| 2075 |
err = hw->mac.ops.set_vfta(hw, vid, 0, false); |
| 2076 |
|
| 2077 |
spin_unlock_bh(&adapter->mbx_lock); |
| 2078 |
|
| 2079 |
if (err) |
| 2080 |
netdev_err(netdev, "Could not remove VLAN %d\n", vid); |
| 2081 |
|
| 2082 |
clear_bit(vid, adapter->active_vlans); |
| 2083 |
|
| 2084 |
return err; |
| 2085 |
} |
| 2086 |
|
| 2087 |
static void ixgbevf_restore_vlan(struct ixgbevf_adapter *adapter) |
| 2088 |
{ |
| 2089 |
u16 vid; |
| 2090 |
|
| 2091 |
for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 2092 |
ixgbevf_vlan_rx_add_vid(adapter->netdev, |
| 2093 |
htons(ETH_P_8021Q), vid); |
| 2094 |
} |
| 2095 |
|
| 2096 |
static int ixgbevf_write_uc_addr_list(struct net_device *netdev) |
| 2097 |
{ |
| 2098 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 2099 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2100 |
int count = 0; |
| 2101 |
|
| 2102 |
if (!netdev_uc_empty(netdev)) { |
| 2103 |
struct netdev_hw_addr *ha; |
| 2104 |
|
| 2105 |
netdev_for_each_uc_addr(ha, netdev) { |
| 2106 |
hw->mac.ops.set_uc_addr(hw, ++count, ha->addr); |
| 2107 |
udelay(200); |
| 2108 |
} |
| 2109 |
} else { |
| 2110 |
/* If the list is empty then send message to PF driver to |
| 2111 |
* clear all MAC VLANs on this VF. |
| 2112 |
*/ |
| 2113 |
hw->mac.ops.set_uc_addr(hw, 0, NULL); |
| 2114 |
} |
| 2115 |
|
| 2116 |
return count; |
| 2117 |
} |
| 2118 |
|
| 2119 |
/** |
| 2120 |
* ixgbevf_set_rx_mode - Multicast and unicast set |
| 2121 |
* @netdev: network interface device structure |
| 2122 |
* |
| 2123 |
* The set_rx_method entry point is called whenever the multicast address |
| 2124 |
* list, unicast address list or the network interface flags are updated. |
| 2125 |
* This routine is responsible for configuring the hardware for proper |
| 2126 |
* multicast mode and configuring requested unicast filters. |
| 2127 |
**/ |
| 2128 |
static void ixgbevf_set_rx_mode(struct net_device *netdev) |
| 2129 |
{ |
| 2130 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 2131 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2132 |
unsigned int flags = netdev->flags; |
| 2133 |
int xcast_mode; |
| 2134 |
|
| 2135 |
/* request the most inclusive mode we need */ |
| 2136 |
if (flags & IFF_PROMISC) |
| 2137 |
xcast_mode = IXGBEVF_XCAST_MODE_PROMISC; |
| 2138 |
else if (flags & IFF_ALLMULTI) |
| 2139 |
xcast_mode = IXGBEVF_XCAST_MODE_ALLMULTI; |
| 2140 |
else if (flags & (IFF_BROADCAST | IFF_MULTICAST)) |
| 2141 |
xcast_mode = IXGBEVF_XCAST_MODE_MULTI; |
| 2142 |
else |
| 2143 |
xcast_mode = IXGBEVF_XCAST_MODE_NONE; |
| 2144 |
|
| 2145 |
spin_lock_bh(&adapter->mbx_lock); |
| 2146 |
|
| 2147 |
hw->mac.ops.update_xcast_mode(hw, xcast_mode); |
| 2148 |
|
| 2149 |
/* reprogram multicast list */ |
| 2150 |
hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 2151 |
|
| 2152 |
ixgbevf_write_uc_addr_list(netdev); |
| 2153 |
|
| 2154 |
spin_unlock_bh(&adapter->mbx_lock); |
| 2155 |
} |
| 2156 |
|
| 2157 |
static void ixgbevf_napi_enable_all(struct ixgbevf_adapter *adapter) |
| 2158 |
{ |
| 2159 |
int q_idx; |
| 2160 |
struct ixgbevf_q_vector *q_vector; |
| 2161 |
int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2162 |
|
| 2163 |
for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 2164 |
q_vector = adapter->q_vector[q_idx]; |
| 2165 |
napi_enable(&q_vector->napi); |
| 2166 |
} |
| 2167 |
} |
| 2168 |
|
| 2169 |
static void ixgbevf_napi_disable_all(struct ixgbevf_adapter *adapter) |
| 2170 |
{ |
| 2171 |
int q_idx; |
| 2172 |
struct ixgbevf_q_vector *q_vector; |
| 2173 |
int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2174 |
|
| 2175 |
for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 2176 |
q_vector = adapter->q_vector[q_idx]; |
| 2177 |
napi_disable(&q_vector->napi); |
| 2178 |
} |
| 2179 |
} |
| 2180 |
|
| 2181 |
static int ixgbevf_configure_dcb(struct ixgbevf_adapter *adapter) |
| 2182 |
{ |
| 2183 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2184 |
unsigned int def_q = 0; |
| 2185 |
unsigned int num_tcs = 0; |
| 2186 |
unsigned int num_rx_queues = adapter->num_rx_queues; |
| 2187 |
unsigned int num_tx_queues = adapter->num_tx_queues; |
| 2188 |
int err; |
| 2189 |
|
| 2190 |
spin_lock_bh(&adapter->mbx_lock); |
| 2191 |
|
| 2192 |
/* fetch queue configuration from the PF */ |
| 2193 |
err = ixgbevf_get_queues(hw, &num_tcs, &def_q); |
| 2194 |
|
| 2195 |
spin_unlock_bh(&adapter->mbx_lock); |
| 2196 |
|
| 2197 |
if (err) |
| 2198 |
return err; |
| 2199 |
|
| 2200 |
if (num_tcs > 1) { |
| 2201 |
/* we need only one Tx queue */ |
| 2202 |
num_tx_queues = 1; |
| 2203 |
|
| 2204 |
/* update default Tx ring register index */ |
| 2205 |
adapter->tx_ring[0]->reg_idx = def_q; |
| 2206 |
|
| 2207 |
/* we need as many queues as traffic classes */ |
| 2208 |
num_rx_queues = num_tcs; |
| 2209 |
} |
| 2210 |
|
| 2211 |
/* if we have a bad config abort request queue reset */ |
| 2212 |
if ((adapter->num_rx_queues != num_rx_queues) || |
| 2213 |
(adapter->num_tx_queues != num_tx_queues)) { |
| 2214 |
/* force mailbox timeout to prevent further messages */ |
| 2215 |
hw->mbx.timeout = 0; |
| 2216 |
|
| 2217 |
/* wait for watchdog to come around and bail us out */ |
| 2218 |
set_bit(__IXGBEVF_QUEUE_RESET_REQUESTED, &adapter->state); |
| 2219 |
} |
| 2220 |
|
| 2221 |
return 0; |
| 2222 |
} |
| 2223 |
|
| 2224 |
static void ixgbevf_configure(struct ixgbevf_adapter *adapter) |
| 2225 |
{ |
| 2226 |
ixgbevf_configure_dcb(adapter); |
| 2227 |
|
| 2228 |
ixgbevf_set_rx_mode(adapter->netdev); |
| 2229 |
|
| 2230 |
ixgbevf_restore_vlan(adapter); |
| 2231 |
ixgbevf_ipsec_restore(adapter); |
| 2232 |
|
| 2233 |
ixgbevf_configure_tx(adapter); |
| 2234 |
ixgbevf_configure_rx(adapter); |
| 2235 |
} |
| 2236 |
|
| 2237 |
static void ixgbevf_save_reset_stats(struct ixgbevf_adapter *adapter) |
| 2238 |
{ |
| 2239 |
/* Only save pre-reset stats if there are some */ |
| 2240 |
if (adapter->stats.vfgprc || adapter->stats.vfgptc) { |
| 2241 |
adapter->stats.saved_reset_vfgprc += adapter->stats.vfgprc - |
| 2242 |
adapter->stats.base_vfgprc; |
| 2243 |
adapter->stats.saved_reset_vfgptc += adapter->stats.vfgptc - |
| 2244 |
adapter->stats.base_vfgptc; |
| 2245 |
adapter->stats.saved_reset_vfgorc += adapter->stats.vfgorc - |
| 2246 |
adapter->stats.base_vfgorc; |
| 2247 |
adapter->stats.saved_reset_vfgotc += adapter->stats.vfgotc - |
| 2248 |
adapter->stats.base_vfgotc; |
| 2249 |
adapter->stats.saved_reset_vfmprc += adapter->stats.vfmprc - |
| 2250 |
adapter->stats.base_vfmprc; |
| 2251 |
} |
| 2252 |
} |
| 2253 |
|
| 2254 |
static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter *adapter) |
| 2255 |
{ |
| 2256 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2257 |
|
| 2258 |
adapter->stats.last_vfgprc = IXGBE_READ_REG(hw, IXGBE_VFGPRC); |
| 2259 |
adapter->stats.last_vfgorc = IXGBE_READ_REG(hw, IXGBE_VFGORC_LSB); |
| 2260 |
adapter->stats.last_vfgorc |= |
| 2261 |
(((u64)(IXGBE_READ_REG(hw, IXGBE_VFGORC_MSB))) << 32); |
| 2262 |
adapter->stats.last_vfgptc = IXGBE_READ_REG(hw, IXGBE_VFGPTC); |
| 2263 |
adapter->stats.last_vfgotc = IXGBE_READ_REG(hw, IXGBE_VFGOTC_LSB); |
| 2264 |
adapter->stats.last_vfgotc |= |
| 2265 |
(((u64)(IXGBE_READ_REG(hw, IXGBE_VFGOTC_MSB))) << 32); |
| 2266 |
adapter->stats.last_vfmprc = IXGBE_READ_REG(hw, IXGBE_VFMPRC); |
| 2267 |
|
| 2268 |
adapter->stats.base_vfgprc = adapter->stats.last_vfgprc; |
| 2269 |
adapter->stats.base_vfgorc = adapter->stats.last_vfgorc; |
| 2270 |
adapter->stats.base_vfgptc = adapter->stats.last_vfgptc; |
| 2271 |
adapter->stats.base_vfgotc = adapter->stats.last_vfgotc; |
| 2272 |
adapter->stats.base_vfmprc = adapter->stats.last_vfmprc; |
| 2273 |
} |
| 2274 |
|
| 2275 |
/** |
| 2276 |
* ixgbevf_set_features - Set features supported by PF |
| 2277 |
* @adapter: pointer to the adapter struct |
| 2278 |
* |
| 2279 |
* Negotiate with PF supported features and then set pf_features accordingly. |
| 2280 |
*/ |
| 2281 |
static void ixgbevf_set_features(struct ixgbevf_adapter *adapter) |
| 2282 |
{ |
| 2283 |
u32 *pf_features = &adapter->pf_features; |
| 2284 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2285 |
int err; |
| 2286 |
|
| 2287 |
err = hw->mac.ops.negotiate_features(hw, pf_features); |
| 2288 |
if (err && err != -EOPNOTSUPP) |
| 2289 |
netdev_dbg(adapter->netdev, |
| 2290 |
"PF feature negotiation failed.\n"); |
| 2291 |
|
| 2292 |
/* Address also pre API 1.7 cases */ |
| 2293 |
if (hw->api_version == ixgbe_mbox_api_14) |
| 2294 |
*pf_features |= IXGBEVF_PF_SUP_IPSEC; |
| 2295 |
else if (hw->api_version == ixgbe_mbox_api_15) |
| 2296 |
*pf_features |= IXGBEVF_PF_SUP_ESX_MBX; |
| 2297 |
} |
| 2298 |
|
| 2299 |
static void ixgbevf_negotiate_api(struct ixgbevf_adapter *adapter) |
| 2300 |
{ |
| 2301 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2302 |
static const int api[] = { |
| 2303 |
ixgbe_mbox_api_17, |
| 2304 |
ixgbe_mbox_api_16, |
| 2305 |
ixgbe_mbox_api_15, |
| 2306 |
ixgbe_mbox_api_14, |
| 2307 |
ixgbe_mbox_api_13, |
| 2308 |
ixgbe_mbox_api_12, |
| 2309 |
ixgbe_mbox_api_11, |
| 2310 |
ixgbe_mbox_api_10, |
| 2311 |
ixgbe_mbox_api_unknown |
| 2312 |
}; |
| 2313 |
int err, idx = 0; |
| 2314 |
|
| 2315 |
spin_lock_bh(&adapter->mbx_lock); |
| 2316 |
|
| 2317 |
while (api[idx] != ixgbe_mbox_api_unknown) { |
| 2318 |
err = hw->mac.ops.negotiate_api_version(hw, api[idx]); |
| 2319 |
if (!err) |
| 2320 |
break; |
| 2321 |
idx++; |
| 2322 |
} |
| 2323 |
|
| 2324 |
ixgbevf_set_features(adapter); |
| 2325 |
|
| 2326 |
if (adapter->pf_features & IXGBEVF_PF_SUP_ESX_MBX) { |
| 2327 |
hw->mbx.ops.init_params(hw); |
| 2328 |
memcpy(&hw->mbx.ops, &ixgbevf_mbx_ops, |
| 2329 |
sizeof(struct ixgbe_mbx_operations)); |
| 2330 |
} |
| 2331 |
|
| 2332 |
spin_unlock_bh(&adapter->mbx_lock); |
| 2333 |
} |
| 2334 |
|
| 2335 |
static void ixgbevf_up_complete(struct ixgbevf_adapter *adapter) |
| 2336 |
{ |
| 2337 |
struct net_device *netdev = adapter->netdev; |
| 2338 |
struct pci_dev *pdev = adapter->pdev; |
| 2339 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2340 |
bool state; |
| 2341 |
|
| 2342 |
ixgbevf_configure_msix(adapter); |
| 2343 |
|
| 2344 |
spin_lock_bh(&adapter->mbx_lock); |
| 2345 |
|
| 2346 |
if (is_valid_ether_addr(hw->mac.addr)) |
| 2347 |
hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0); |
| 2348 |
else |
| 2349 |
hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0); |
| 2350 |
|
| 2351 |
spin_unlock_bh(&adapter->mbx_lock); |
| 2352 |
|
| 2353 |
state = adapter->link_state; |
| 2354 |
hw->mac.ops.get_link_state(hw, &adapter->link_state); |
| 2355 |
if (state && state != adapter->link_state) |
| 2356 |
dev_info(&pdev->dev, "VF is administratively disabled\n"); |
| 2357 |
|
| 2358 |
smp_mb__before_atomic(); |
| 2359 |
clear_bit(__IXGBEVF_DOWN, &adapter->state); |
| 2360 |
ixgbevf_napi_enable_all(adapter); |
| 2361 |
|
| 2362 |
/* clear any pending interrupts, may auto mask */ |
| 2363 |
IXGBE_READ_REG(hw, IXGBE_VTEICR); |
| 2364 |
ixgbevf_irq_enable(adapter); |
| 2365 |
|
| 2366 |
/* enable transmits */ |
| 2367 |
netif_tx_start_all_queues(netdev); |
| 2368 |
|
| 2369 |
ixgbevf_save_reset_stats(adapter); |
| 2370 |
ixgbevf_init_last_counter_stats(adapter); |
| 2371 |
|
| 2372 |
hw->mac.get_link_status = 1; |
| 2373 |
mod_timer(&adapter->service_timer, jiffies); |
| 2374 |
} |
| 2375 |
|
| 2376 |
void ixgbevf_up(struct ixgbevf_adapter *adapter) |
| 2377 |
{ |
| 2378 |
ixgbevf_configure(adapter); |
| 2379 |
|
| 2380 |
ixgbevf_up_complete(adapter); |
| 2381 |
} |
| 2382 |
|
| 2383 |
/** |
| 2384 |
* ixgbevf_clean_rx_ring - Free Rx Buffers per Queue |
| 2385 |
* @rx_ring: ring to free buffers from |
| 2386 |
**/ |
| 2387 |
static void ixgbevf_clean_rx_ring(struct ixgbevf_ring *rx_ring) |
| 2388 |
{ |
| 2389 |
u16 i = rx_ring->next_to_clean; |
| 2390 |
|
| 2391 |
/* Free Rx ring sk_buff */ |
| 2392 |
if (rx_ring->skb) { |
| 2393 |
dev_kfree_skb(rx_ring->skb); |
| 2394 |
rx_ring->skb = NULL; |
| 2395 |
} |
| 2396 |
|
| 2397 |
/* Free all the Rx ring pages */ |
| 2398 |
while (i != rx_ring->next_to_alloc) { |
| 2399 |
struct ixgbevf_rx_buffer *rx_buffer; |
| 2400 |
|
| 2401 |
rx_buffer = &rx_ring->rx_buffer_info[i]; |
| 2402 |
|
| 2403 |
/* Invalidate cache lines that may have been written to by |
| 2404 |
* device so that we avoid corrupting memory. |
| 2405 |
*/ |
| 2406 |
dma_sync_single_range_for_cpu(rx_ring->dev, |
| 2407 |
rx_buffer->dma, |
| 2408 |
rx_buffer->page_offset, |
| 2409 |
ixgbevf_rx_bufsz(rx_ring), |
| 2410 |
DMA_FROM_DEVICE); |
| 2411 |
|
| 2412 |
/* free resources associated with mapping */ |
| 2413 |
dma_unmap_page_attrs(rx_ring->dev, |
| 2414 |
rx_buffer->dma, |
| 2415 |
ixgbevf_rx_pg_size(rx_ring), |
| 2416 |
DMA_FROM_DEVICE, |
| 2417 |
IXGBEVF_RX_DMA_ATTR); |
| 2418 |
|
| 2419 |
__page_frag_cache_drain(rx_buffer->page, |
| 2420 |
rx_buffer->pagecnt_bias); |
| 2421 |
|
| 2422 |
i++; |
| 2423 |
if (i == rx_ring->count) |
| 2424 |
i = 0; |
| 2425 |
} |
| 2426 |
|
| 2427 |
rx_ring->next_to_alloc = 0; |
| 2428 |
rx_ring->next_to_clean = 0; |
| 2429 |
rx_ring->next_to_use = 0; |
| 2430 |
} |
| 2431 |
|
| 2432 |
/** |
| 2433 |
* ixgbevf_clean_tx_ring - Free Tx Buffers |
| 2434 |
* @tx_ring: ring to be cleaned |
| 2435 |
**/ |
| 2436 |
static void ixgbevf_clean_tx_ring(struct ixgbevf_ring *tx_ring) |
| 2437 |
{ |
| 2438 |
u16 i = tx_ring->next_to_clean; |
| 2439 |
struct ixgbevf_tx_buffer *tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 2440 |
|
| 2441 |
while (i != tx_ring->next_to_use) { |
| 2442 |
union ixgbe_adv_tx_desc *eop_desc, *tx_desc; |
| 2443 |
|
| 2444 |
/* Free all the Tx ring sk_buffs */ |
| 2445 |
if (ring_is_xdp(tx_ring)) |
| 2446 |
page_frag_free(tx_buffer->data); |
| 2447 |
else |
| 2448 |
dev_kfree_skb_any(tx_buffer->skb); |
| 2449 |
|
| 2450 |
/* unmap skb header data */ |
| 2451 |
dma_unmap_single(tx_ring->dev, |
| 2452 |
dma_unmap_addr(tx_buffer, dma), |
| 2453 |
dma_unmap_len(tx_buffer, len), |
| 2454 |
DMA_TO_DEVICE); |
| 2455 |
|
| 2456 |
/* check for eop_desc to determine the end of the packet */ |
| 2457 |
eop_desc = tx_buffer->next_to_watch; |
| 2458 |
tx_desc = IXGBEVF_TX_DESC(tx_ring, i); |
| 2459 |
|
| 2460 |
/* unmap remaining buffers */ |
| 2461 |
while (tx_desc != eop_desc) { |
| 2462 |
tx_buffer++; |
| 2463 |
tx_desc++; |
| 2464 |
i++; |
| 2465 |
if (unlikely(i == tx_ring->count)) { |
| 2466 |
i = 0; |
| 2467 |
tx_buffer = tx_ring->tx_buffer_info; |
| 2468 |
tx_desc = IXGBEVF_TX_DESC(tx_ring, 0); |
| 2469 |
} |
| 2470 |
|
| 2471 |
/* unmap any remaining paged data */ |
| 2472 |
if (dma_unmap_len(tx_buffer, len)) |
| 2473 |
dma_unmap_page(tx_ring->dev, |
| 2474 |
dma_unmap_addr(tx_buffer, dma), |
| 2475 |
dma_unmap_len(tx_buffer, len), |
| 2476 |
DMA_TO_DEVICE); |
| 2477 |
} |
| 2478 |
|
| 2479 |
/* move us one more past the eop_desc for start of next pkt */ |
| 2480 |
tx_buffer++; |
| 2481 |
i++; |
| 2482 |
if (unlikely(i == tx_ring->count)) { |
| 2483 |
i = 0; |
| 2484 |
tx_buffer = tx_ring->tx_buffer_info; |
| 2485 |
} |
| 2486 |
} |
| 2487 |
|
| 2488 |
/* reset next_to_use and next_to_clean */ |
| 2489 |
tx_ring->next_to_use = 0; |
| 2490 |
tx_ring->next_to_clean = 0; |
| 2491 |
|
| 2492 |
} |
| 2493 |
|
| 2494 |
/** |
| 2495 |
* ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2496 |
* @adapter: board private structure |
| 2497 |
**/ |
| 2498 |
static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter *adapter) |
| 2499 |
{ |
| 2500 |
int i; |
| 2501 |
|
| 2502 |
for (i = 0; i < adapter->num_rx_queues; i++) |
| 2503 |
ixgbevf_clean_rx_ring(adapter->rx_ring[i]); |
| 2504 |
} |
| 2505 |
|
| 2506 |
/** |
| 2507 |
* ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2508 |
* @adapter: board private structure |
| 2509 |
**/ |
| 2510 |
static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter *adapter) |
| 2511 |
{ |
| 2512 |
int i; |
| 2513 |
|
| 2514 |
for (i = 0; i < adapter->num_tx_queues; i++) |
| 2515 |
ixgbevf_clean_tx_ring(adapter->tx_ring[i]); |
| 2516 |
for (i = 0; i < adapter->num_xdp_queues; i++) |
| 2517 |
ixgbevf_clean_tx_ring(adapter->xdp_ring[i]); |
| 2518 |
} |
| 2519 |
|
| 2520 |
void ixgbevf_down(struct ixgbevf_adapter *adapter) |
| 2521 |
{ |
| 2522 |
struct net_device *netdev = adapter->netdev; |
| 2523 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2524 |
int i; |
| 2525 |
|
| 2526 |
/* signal that we are down to the interrupt handler */ |
| 2527 |
if (test_and_set_bit(__IXGBEVF_DOWN, &adapter->state)) |
| 2528 |
return; /* do nothing if already down */ |
| 2529 |
|
| 2530 |
/* disable all enabled Rx queues */ |
| 2531 |
for (i = 0; i < adapter->num_rx_queues; i++) |
| 2532 |
ixgbevf_disable_rx_queue(adapter, adapter->rx_ring[i]); |
| 2533 |
|
| 2534 |
usleep_range(10000, 20000); |
| 2535 |
|
| 2536 |
netif_tx_stop_all_queues(netdev); |
| 2537 |
|
| 2538 |
/* call carrier off first to avoid false dev_watchdog timeouts */ |
| 2539 |
netif_carrier_off(netdev); |
| 2540 |
netif_tx_disable(netdev); |
| 2541 |
|
| 2542 |
ixgbevf_irq_disable(adapter); |
| 2543 |
|
| 2544 |
ixgbevf_napi_disable_all(adapter); |
| 2545 |
|
| 2546 |
timer_delete_sync(&adapter->service_timer); |
| 2547 |
|
| 2548 |
/* disable transmits in the hardware now that interrupts are off */ |
| 2549 |
for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2550 |
u8 reg_idx = adapter->tx_ring[i]->reg_idx; |
| 2551 |
|
| 2552 |
IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(reg_idx), |
| 2553 |
IXGBE_TXDCTL_SWFLSH); |
| 2554 |
} |
| 2555 |
|
| 2556 |
for (i = 0; i < adapter->num_xdp_queues; i++) { |
| 2557 |
u8 reg_idx = adapter->xdp_ring[i]->reg_idx; |
| 2558 |
|
| 2559 |
IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(reg_idx), |
| 2560 |
IXGBE_TXDCTL_SWFLSH); |
| 2561 |
} |
| 2562 |
|
| 2563 |
if (!pci_channel_offline(adapter->pdev)) |
| 2564 |
ixgbevf_reset(adapter); |
| 2565 |
|
| 2566 |
ixgbevf_clean_all_tx_rings(adapter); |
| 2567 |
ixgbevf_clean_all_rx_rings(adapter); |
| 2568 |
} |
| 2569 |
|
| 2570 |
void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter) |
| 2571 |
{ |
| 2572 |
while (test_and_set_bit(__IXGBEVF_RESETTING, &adapter->state)) |
| 2573 |
msleep(1); |
| 2574 |
|
| 2575 |
ixgbevf_down(adapter); |
| 2576 |
pci_set_master(adapter->pdev); |
| 2577 |
ixgbevf_up(adapter); |
| 2578 |
|
| 2579 |
clear_bit(__IXGBEVF_RESETTING, &adapter->state); |
| 2580 |
} |
| 2581 |
|
| 2582 |
void ixgbevf_reset(struct ixgbevf_adapter *adapter) |
| 2583 |
{ |
| 2584 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2585 |
struct net_device *netdev = adapter->netdev; |
| 2586 |
|
| 2587 |
if (hw->mac.ops.reset_hw(hw)) { |
| 2588 |
hw_dbg(hw, "PF still resetting\n"); |
| 2589 |
} else { |
| 2590 |
hw->mac.ops.init_hw(hw); |
| 2591 |
ixgbevf_negotiate_api(adapter); |
| 2592 |
} |
| 2593 |
|
| 2594 |
if (is_valid_ether_addr(adapter->hw.mac.addr)) { |
| 2595 |
eth_hw_addr_set(netdev, adapter->hw.mac.addr); |
| 2596 |
ether_addr_copy(netdev->perm_addr, adapter->hw.mac.addr); |
| 2597 |
} |
| 2598 |
|
| 2599 |
adapter->last_reset = jiffies; |
| 2600 |
} |
| 2601 |
|
| 2602 |
static int ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter *adapter, |
| 2603 |
int vectors) |
| 2604 |
{ |
| 2605 |
int vector_threshold; |
| 2606 |
|
| 2607 |
/* We'll want at least 2 (vector_threshold): |
| 2608 |
* 1) TxQ[0] + RxQ[0] handler |
| 2609 |
* 2) Other (Link Status Change, etc.) |
| 2610 |
*/ |
| 2611 |
vector_threshold = MIN_MSIX_COUNT; |
| 2612 |
|
| 2613 |
/* The more we get, the more we will assign to Tx/Rx Cleanup |
| 2614 |
* for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 2615 |
* Right now, we simply care about how many we'll get; we'll |
| 2616 |
* set them up later while requesting irq's. |
| 2617 |
*/ |
| 2618 |
vectors = pci_enable_msix_range(adapter->pdev, adapter->msix_entries, |
| 2619 |
vector_threshold, vectors); |
| 2620 |
|
| 2621 |
if (vectors < 0) { |
| 2622 |
dev_err(&adapter->pdev->dev, |
| 2623 |
"Unable to allocate MSI-X interrupts\n"); |
| 2624 |
kfree(adapter->msix_entries); |
| 2625 |
adapter->msix_entries = NULL; |
| 2626 |
return vectors; |
| 2627 |
} |
| 2628 |
|
| 2629 |
/* Adjust for only the vectors we'll use, which is minimum |
| 2630 |
* of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 2631 |
* vectors we were allocated. |
| 2632 |
*/ |
| 2633 |
adapter->num_msix_vectors = vectors; |
| 2634 |
|
| 2635 |
return 0; |
| 2636 |
} |
| 2637 |
|
| 2638 |
/** |
| 2639 |
* ixgbevf_set_num_queues - Allocate queues for device, feature dependent |
| 2640 |
* @adapter: board private structure to initialize |
| 2641 |
* |
| 2642 |
* This is the top level queue allocation routine. The order here is very |
| 2643 |
* important, starting with the "most" number of features turned on at once, |
| 2644 |
* and ending with the smallest set of features. This way large combinations |
| 2645 |
* can be allocated if they're turned on, and smaller combinations are the |
| 2646 |
* fall through conditions. |
| 2647 |
* |
| 2648 |
**/ |
| 2649 |
static void ixgbevf_set_num_queues(struct ixgbevf_adapter *adapter) |
| 2650 |
{ |
| 2651 |
struct ixgbe_hw *hw = &adapter->hw; |
| 2652 |
unsigned int def_q = 0; |
| 2653 |
unsigned int num_tcs = 0; |
| 2654 |
int err; |
| 2655 |
|
| 2656 |
/* Start with base case */ |
| 2657 |
adapter->num_rx_queues = 1; |
| 2658 |
adapter->num_tx_queues = 1; |
| 2659 |
adapter->num_xdp_queues = 0; |
| 2660 |
|
| 2661 |
spin_lock_bh(&adapter->mbx_lock); |
| 2662 |
|
| 2663 |
/* fetch queue configuration from the PF */ |
| 2664 |
err = ixgbevf_get_queues(hw, &num_tcs, &def_q); |
| 2665 |
|
| 2666 |
spin_unlock_bh(&adapter->mbx_lock); |
| 2667 |
|
| 2668 |
if (err) |
| 2669 |
return; |
| 2670 |
|
| 2671 |
/* we need as many queues as traffic classes */ |
| 2672 |
if (num_tcs > 1) { |
| 2673 |
adapter->num_rx_queues = num_tcs; |
| 2674 |
} else { |
| 2675 |
u16 rss = min_t(u16, num_online_cpus(), IXGBEVF_MAX_RSS_QUEUES); |
| 2676 |
|
| 2677 |
switch (hw->api_version) { |
| 2678 |
case ixgbe_mbox_api_11: |
| 2679 |
case ixgbe_mbox_api_12: |
| 2680 |
case ixgbe_mbox_api_13: |
| 2681 |
case ixgbe_mbox_api_14: |
| 2682 |
case ixgbe_mbox_api_15: |
| 2683 |
case ixgbe_mbox_api_16: |
| 2684 |
case ixgbe_mbox_api_17: |
| 2685 |
if (adapter->xdp_prog && |
| 2686 |
hw->mac.max_tx_queues == rss) |
| 2687 |
rss = rss > 3 ? 2 : 1; |
| 2688 |
|
| 2689 |
adapter->num_rx_queues = rss; |
| 2690 |
adapter->num_tx_queues = rss; |
| 2691 |
adapter->num_xdp_queues = adapter->xdp_prog ? rss : 0; |
| 2692 |
break; |
| 2693 |
default: |
| 2694 |
break; |
| 2695 |
} |
| 2696 |
} |
| 2697 |
} |
| 2698 |
|
| 2699 |
/** |
| 2700 |
* ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported |
| 2701 |
* @adapter: board private structure to initialize |
| 2702 |
* |
| 2703 |
* Attempt to configure the interrupts using the best available |
| 2704 |
* capabilities of the hardware and the kernel. |
| 2705 |
**/ |
| 2706 |
static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter *adapter) |
| 2707 |
{ |
| 2708 |
int vector, v_budget; |
| 2709 |
|
| 2710 |
/* It's easy to be greedy for MSI-X vectors, but it really |
| 2711 |
* doesn't do us much good if we have a lot more vectors |
| 2712 |
* than CPU's. So let's be conservative and only ask for |
| 2713 |
* (roughly) the same number of vectors as there are CPU's. |
| 2714 |
* The default is to use pairs of vectors. |
| 2715 |
*/ |
| 2716 |
v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues); |
| 2717 |
v_budget = min_t(int, v_budget, num_online_cpus()); |
| 2718 |
v_budget += NON_Q_VECTORS; |
| 2719 |
|
| 2720 |
adapter->msix_entries = kzalloc_objs(struct msix_entry, v_budget); |
| 2721 |
if (!adapter->msix_entries) |
| 2722 |
return -ENOMEM; |
| 2723 |
|
| 2724 |
for (vector = 0; vector < v_budget; vector++) |
| 2725 |
adapter->msix_entries[vector].entry = vector; |
| 2726 |
|
| 2727 |
/* A failure in MSI-X entry allocation isn't fatal, but the VF driver |
| 2728 |
* does not support any other modes, so we will simply fail here. Note |
| 2729 |
* that we clean up the msix_entries pointer else-where. |
| 2730 |
*/ |
| 2731 |
return ixgbevf_acquire_msix_vectors(adapter, v_budget); |
| 2732 |
} |
| 2733 |
|
| 2734 |
static void ixgbevf_add_ring(struct ixgbevf_ring *ring, |
| 2735 |
struct ixgbevf_ring_container *head) |
| 2736 |
{ |
| 2737 |
ring->next = head->ring; |
| 2738 |
head->ring = ring; |
| 2739 |
head->count++; |
| 2740 |
} |
| 2741 |
|
| 2742 |
/** |
| 2743 |
* ixgbevf_alloc_q_vector - Allocate memory for a single interrupt vector |
| 2744 |
* @adapter: board private structure to initialize |
| 2745 |
* @v_idx: index of vector in adapter struct |
| 2746 |
* @txr_count: number of Tx rings for q vector |
| 2747 |
* @txr_idx: index of first Tx ring to assign |
| 2748 |
* @xdp_count: total number of XDP rings to allocate |
| 2749 |
* @xdp_idx: index of first XDP ring to allocate |
| 2750 |
* @rxr_count: number of Rx rings for q vector |
| 2751 |
* @rxr_idx: index of first Rx ring to assign |
| 2752 |
* |
| 2753 |
* We allocate one q_vector. If allocation fails we return -ENOMEM. |
| 2754 |
**/ |
| 2755 |
static int ixgbevf_alloc_q_vector(struct ixgbevf_adapter *adapter, int v_idx, |
| 2756 |
int txr_count, int txr_idx, |
| 2757 |
int xdp_count, int xdp_idx, |
| 2758 |
int rxr_count, int rxr_idx) |
| 2759 |
{ |
| 2760 |
struct ixgbevf_q_vector *q_vector; |
| 2761 |
int reg_idx = txr_idx + xdp_idx; |
| 2762 |
struct ixgbevf_ring *ring; |
| 2763 |
int ring_count, size; |
| 2764 |
|
| 2765 |
ring_count = txr_count + xdp_count + rxr_count; |
| 2766 |
size = sizeof(*q_vector) + (sizeof(*ring) * ring_count); |
| 2767 |
|
| 2768 |
/* allocate q_vector and rings */ |
| 2769 |
q_vector = kzalloc(size, GFP_KERNEL); |
| 2770 |
if (!q_vector) |
| 2771 |
return -ENOMEM; |
| 2772 |
|
| 2773 |
/* initialize NAPI */ |
| 2774 |
netif_napi_add(adapter->netdev, &q_vector->napi, ixgbevf_poll); |
| 2775 |
|
| 2776 |
/* tie q_vector and adapter together */ |
| 2777 |
adapter->q_vector[v_idx] = q_vector; |
| 2778 |
q_vector->adapter = adapter; |
| 2779 |
q_vector->v_idx = v_idx; |
| 2780 |
|
| 2781 |
/* initialize pointer to rings */ |
| 2782 |
ring = q_vector->ring; |
| 2783 |
|
| 2784 |
while (txr_count) { |
| 2785 |
/* assign generic ring traits */ |
| 2786 |
ring->dev = &adapter->pdev->dev; |
| 2787 |
ring->netdev = adapter->netdev; |
| 2788 |
|
| 2789 |
/* configure backlink on ring */ |
| 2790 |
ring->q_vector = q_vector; |
| 2791 |
|
| 2792 |
/* update q_vector Tx values */ |
| 2793 |
ixgbevf_add_ring(ring, &q_vector->tx); |
| 2794 |
|
| 2795 |
/* apply Tx specific ring traits */ |
| 2796 |
ring->count = adapter->tx_ring_count; |
| 2797 |
ring->queue_index = txr_idx; |
| 2798 |
ring->reg_idx = reg_idx; |
| 2799 |
|
| 2800 |
/* assign ring to adapter */ |
| 2801 |
adapter->tx_ring[txr_idx] = ring; |
| 2802 |
|
| 2803 |
/* update count and index */ |
| 2804 |
txr_count--; |
| 2805 |
txr_idx++; |
| 2806 |
reg_idx++; |
| 2807 |
|
| 2808 |
/* push pointer to next ring */ |
| 2809 |
ring++; |
| 2810 |
} |
| 2811 |
|
| 2812 |
while (xdp_count) { |
| 2813 |
/* assign generic ring traits */ |
| 2814 |
ring->dev = &adapter->pdev->dev; |
| 2815 |
ring->netdev = adapter->netdev; |
| 2816 |
|
| 2817 |
/* configure backlink on ring */ |
| 2818 |
ring->q_vector = q_vector; |
| 2819 |
|
| 2820 |
/* update q_vector Tx values */ |
| 2821 |
ixgbevf_add_ring(ring, &q_vector->tx); |
| 2822 |
|
| 2823 |
/* apply Tx specific ring traits */ |
| 2824 |
ring->count = adapter->tx_ring_count; |
| 2825 |
ring->queue_index = xdp_idx; |
| 2826 |
ring->reg_idx = reg_idx; |
| 2827 |
set_ring_xdp(ring); |
| 2828 |
|
| 2829 |
/* assign ring to adapter */ |
| 2830 |
adapter->xdp_ring[xdp_idx] = ring; |
| 2831 |
|
| 2832 |
/* update count and index */ |
| 2833 |
xdp_count--; |
| 2834 |
xdp_idx++; |
| 2835 |
reg_idx++; |
| 2836 |
|
| 2837 |
/* push pointer to next ring */ |
| 2838 |
ring++; |
| 2839 |
} |
| 2840 |
|
| 2841 |
while (rxr_count) { |
| 2842 |
/* assign generic ring traits */ |
| 2843 |
ring->dev = &adapter->pdev->dev; |
| 2844 |
ring->netdev = adapter->netdev; |
| 2845 |
|
| 2846 |
/* configure backlink on ring */ |
| 2847 |
ring->q_vector = q_vector; |
| 2848 |
|
| 2849 |
/* update q_vector Rx values */ |
| 2850 |
ixgbevf_add_ring(ring, &q_vector->rx); |
| 2851 |
|
| 2852 |
/* apply Rx specific ring traits */ |
| 2853 |
ring->count = adapter->rx_ring_count; |
| 2854 |
ring->queue_index = rxr_idx; |
| 2855 |
ring->reg_idx = rxr_idx; |
| 2856 |
|
| 2857 |
/* assign ring to adapter */ |
| 2858 |
adapter->rx_ring[rxr_idx] = ring; |
| 2859 |
|
| 2860 |
/* update count and index */ |
| 2861 |
rxr_count--; |
| 2862 |
rxr_idx++; |
| 2863 |
|
| 2864 |
/* push pointer to next ring */ |
| 2865 |
ring++; |
| 2866 |
} |
| 2867 |
|
| 2868 |
return 0; |
| 2869 |
} |
| 2870 |
|
| 2871 |
/** |
| 2872 |
* ixgbevf_free_q_vector - Free memory allocated for specific interrupt vector |
| 2873 |
* @adapter: board private structure to initialize |
| 2874 |
* @v_idx: index of vector in adapter struct |
| 2875 |
* |
| 2876 |
* This function frees the memory allocated to the q_vector. In addition if |
| 2877 |
* NAPI is enabled it will delete any references to the NAPI struct prior |
| 2878 |
* to freeing the q_vector. |
| 2879 |
**/ |
| 2880 |
static void ixgbevf_free_q_vector(struct ixgbevf_adapter *adapter, int v_idx) |
| 2881 |
{ |
| 2882 |
struct ixgbevf_q_vector *q_vector = adapter->q_vector[v_idx]; |
| 2883 |
struct ixgbevf_ring *ring; |
| 2884 |
|
| 2885 |
ixgbevf_for_each_ring(ring, q_vector->tx) { |
| 2886 |
if (ring_is_xdp(ring)) |
| 2887 |
adapter->xdp_ring[ring->queue_index] = NULL; |
| 2888 |
else |
| 2889 |
adapter->tx_ring[ring->queue_index] = NULL; |
| 2890 |
} |
| 2891 |
|
| 2892 |
ixgbevf_for_each_ring(ring, q_vector->rx) |
| 2893 |
adapter->rx_ring[ring->queue_index] = NULL; |
| 2894 |
|
| 2895 |
adapter->q_vector[v_idx] = NULL; |
| 2896 |
netif_napi_del(&q_vector->napi); |
| 2897 |
|
| 2898 |
/* ixgbevf_get_stats() might access the rings on this vector, |
| 2899 |
* we must wait a grace period before freeing it. |
| 2900 |
*/ |
| 2901 |
kfree_rcu(q_vector, rcu); |
| 2902 |
} |
| 2903 |
|
| 2904 |
/** |
| 2905 |
* ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors |
| 2906 |
* @adapter: board private structure to initialize |
| 2907 |
* |
| 2908 |
* We allocate one q_vector per queue interrupt. If allocation fails we |
| 2909 |
* return -ENOMEM. |
| 2910 |
**/ |
| 2911 |
static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter *adapter) |
| 2912 |
{ |
| 2913 |
int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2914 |
int rxr_remaining = adapter->num_rx_queues; |
| 2915 |
int txr_remaining = adapter->num_tx_queues; |
| 2916 |
int xdp_remaining = adapter->num_xdp_queues; |
| 2917 |
int rxr_idx = 0, txr_idx = 0, xdp_idx = 0, v_idx = 0; |
| 2918 |
int err; |
| 2919 |
|
| 2920 |
if (q_vectors >= (rxr_remaining + txr_remaining + xdp_remaining)) { |
| 2921 |
for (; rxr_remaining; v_idx++, q_vectors--) { |
| 2922 |
int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors); |
| 2923 |
|
| 2924 |
err = ixgbevf_alloc_q_vector(adapter, v_idx, |
| 2925 |
0, 0, 0, 0, rqpv, rxr_idx); |
| 2926 |
if (err) |
| 2927 |
goto err_out; |
| 2928 |
|
| 2929 |
/* update counts and index */ |
| 2930 |
rxr_remaining -= rqpv; |
| 2931 |
rxr_idx += rqpv; |
| 2932 |
} |
| 2933 |
} |
| 2934 |
|
| 2935 |
for (; q_vectors; v_idx++, q_vectors--) { |
| 2936 |
int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors); |
| 2937 |
int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors); |
| 2938 |
int xqpv = DIV_ROUND_UP(xdp_remaining, q_vectors); |
| 2939 |
|
| 2940 |
err = ixgbevf_alloc_q_vector(adapter, v_idx, |
| 2941 |
tqpv, txr_idx, |
| 2942 |
xqpv, xdp_idx, |
| 2943 |
rqpv, rxr_idx); |
| 2944 |
|
| 2945 |
if (err) |
| 2946 |
goto err_out; |
| 2947 |
|
| 2948 |
/* update counts and index */ |
| 2949 |
rxr_remaining -= rqpv; |
| 2950 |
rxr_idx += rqpv; |
| 2951 |
txr_remaining -= tqpv; |
| 2952 |
txr_idx += tqpv; |
| 2953 |
xdp_remaining -= xqpv; |
| 2954 |
xdp_idx += xqpv; |
| 2955 |
} |
| 2956 |
|
| 2957 |
return 0; |
| 2958 |
|
| 2959 |
err_out: |
| 2960 |
while (v_idx) { |
| 2961 |
v_idx--; |
| 2962 |
ixgbevf_free_q_vector(adapter, v_idx); |
| 2963 |
} |
| 2964 |
|
| 2965 |
return -ENOMEM; |
| 2966 |
} |
| 2967 |
|
| 2968 |
/** |
| 2969 |
* ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors |
| 2970 |
* @adapter: board private structure to initialize |
| 2971 |
* |
| 2972 |
* This function frees the memory allocated to the q_vectors. In addition if |
| 2973 |
* NAPI is enabled it will delete any references to the NAPI struct prior |
| 2974 |
* to freeing the q_vector. |
| 2975 |
**/ |
| 2976 |
static void ixgbevf_free_q_vectors(struct ixgbevf_adapter *adapter) |
| 2977 |
{ |
| 2978 |
int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2979 |
|
| 2980 |
while (q_vectors) { |
| 2981 |
q_vectors--; |
| 2982 |
ixgbevf_free_q_vector(adapter, q_vectors); |
| 2983 |
} |
| 2984 |
} |
| 2985 |
|
| 2986 |
/** |
| 2987 |
* ixgbevf_reset_interrupt_capability - Reset MSIX setup |
| 2988 |
* @adapter: board private structure |
| 2989 |
* |
| 2990 |
**/ |
| 2991 |
static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter *adapter) |
| 2992 |
{ |
| 2993 |
if (!adapter->msix_entries) |
| 2994 |
return; |
| 2995 |
|
| 2996 |
pci_disable_msix(adapter->pdev); |
| 2997 |
kfree(adapter->msix_entries); |
| 2998 |
adapter->msix_entries = NULL; |
| 2999 |
} |
| 3000 |
|
| 3001 |
/** |
| 3002 |
* ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init |
| 3003 |
* @adapter: board private structure to initialize |
| 3004 |
* |
| 3005 |
**/ |
| 3006 |
static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter *adapter) |
| 3007 |
{ |
| 3008 |
int err; |
| 3009 |
|
| 3010 |
/* Number of supported queues */ |
| 3011 |
ixgbevf_set_num_queues(adapter); |
| 3012 |
|
| 3013 |
err = ixgbevf_set_interrupt_capability(adapter); |
| 3014 |
if (err) { |
| 3015 |
hw_dbg(&adapter->hw, |
| 3016 |
"Unable to setup interrupt capabilities\n"); |
| 3017 |
goto err_set_interrupt; |
| 3018 |
} |
| 3019 |
|
| 3020 |
err = ixgbevf_alloc_q_vectors(adapter); |
| 3021 |
if (err) { |
| 3022 |
hw_dbg(&adapter->hw, "Unable to allocate memory for queue vectors\n"); |
| 3023 |
goto err_alloc_q_vectors; |
| 3024 |
} |
| 3025 |
|
| 3026 |
hw_dbg(&adapter->hw, "Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u XDP Queue count %u\n", |
| 3027 |
(adapter->num_rx_queues > 1) ? "Enabled" : "Disabled", |
| 3028 |
adapter->num_rx_queues, adapter->num_tx_queues, |
| 3029 |
adapter->num_xdp_queues); |
| 3030 |
|
| 3031 |
set_bit(__IXGBEVF_DOWN, &adapter->state); |
| 3032 |
|
| 3033 |
return 0; |
| 3034 |
err_alloc_q_vectors: |
| 3035 |
ixgbevf_reset_interrupt_capability(adapter); |
| 3036 |
err_set_interrupt: |
| 3037 |
return err; |
| 3038 |
} |
| 3039 |
|
| 3040 |
/** |
| 3041 |
* ixgbevf_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3042 |
* @adapter: board private structure to clear interrupt scheme on |
| 3043 |
* |
| 3044 |
* We go through and clear interrupt specific resources and reset the structure |
| 3045 |
* to pre-load conditions |
| 3046 |
**/ |
| 3047 |
static void ixgbevf_clear_interrupt_scheme(struct ixgbevf_adapter *adapter) |
| 3048 |
{ |
| 3049 |
adapter->num_tx_queues = 0; |
| 3050 |
adapter->num_xdp_queues = 0; |
| 3051 |
adapter->num_rx_queues = 0; |
| 3052 |
|
| 3053 |
ixgbevf_free_q_vectors(adapter); |
| 3054 |
ixgbevf_reset_interrupt_capability(adapter); |
| 3055 |
} |
| 3056 |
|
| 3057 |
/** |
| 3058 |
* ixgbevf_sw_init - Initialize general software structures |
| 3059 |
* @adapter: board private structure to initialize |
| 3060 |
* |
| 3061 |
* ixgbevf_sw_init initializes the Adapter private data structure. |
| 3062 |
* Fields are initialized based on PCI device information and |
| 3063 |
* OS network device settings (MTU size). |
| 3064 |
**/ |
| 3065 |
static int ixgbevf_sw_init(struct ixgbevf_adapter *adapter) |
| 3066 |
{ |
| 3067 |
struct ixgbe_hw *hw = &adapter->hw; |
| 3068 |
struct pci_dev *pdev = adapter->pdev; |
| 3069 |
struct net_device *netdev = adapter->netdev; |
| 3070 |
int err; |
| 3071 |
|
| 3072 |
/* PCI config space info */ |
| 3073 |
hw->vendor_id = pdev->vendor; |
| 3074 |
hw->device_id = pdev->device; |
| 3075 |
hw->revision_id = pdev->revision; |
| 3076 |
hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 3077 |
hw->subsystem_device_id = pdev->subsystem_device; |
| 3078 |
|
| 3079 |
hw->mbx.ops.init_params(hw); |
| 3080 |
|
| 3081 |
if (hw->mac.type >= ixgbe_mac_X550_vf) { |
| 3082 |
err = ixgbevf_init_rss_key(adapter); |
| 3083 |
if (err) |
| 3084 |
goto out; |
| 3085 |
} |
| 3086 |
|
| 3087 |
/* assume legacy case in which PF would only give VF 2 queues */ |
| 3088 |
hw->mac.max_tx_queues = 2; |
| 3089 |
hw->mac.max_rx_queues = 2; |
| 3090 |
|
| 3091 |
/* lock to protect mailbox accesses */ |
| 3092 |
spin_lock_init(&adapter->mbx_lock); |
| 3093 |
|
| 3094 |
err = hw->mac.ops.reset_hw(hw); |
| 3095 |
if (err) { |
| 3096 |
dev_info(&pdev->dev, |
| 3097 |
"PF still in reset state. Is the PF interface up?\n"); |
| 3098 |
} else { |
| 3099 |
err = hw->mac.ops.init_hw(hw); |
| 3100 |
if (err) { |
| 3101 |
pr_err("init_shared_code failed: %d\n", err); |
| 3102 |
goto out; |
| 3103 |
} |
| 3104 |
ixgbevf_negotiate_api(adapter); |
| 3105 |
err = hw->mac.ops.get_mac_addr(hw, hw->mac.addr); |
| 3106 |
if (err) |
| 3107 |
dev_info(&pdev->dev, "Error reading MAC address\n"); |
| 3108 |
else if (is_zero_ether_addr(adapter->hw.mac.addr)) |
| 3109 |
dev_info(&pdev->dev, |
| 3110 |
"MAC address not assigned by administrator.\n"); |
| 3111 |
eth_hw_addr_set(netdev, hw->mac.addr); |
| 3112 |
} |
| 3113 |
|
| 3114 |
if (!is_valid_ether_addr(netdev->dev_addr)) { |
| 3115 |
dev_info(&pdev->dev, "Assigning random MAC address\n"); |
| 3116 |
eth_hw_addr_random(netdev); |
| 3117 |
ether_addr_copy(hw->mac.addr, netdev->dev_addr); |
| 3118 |
ether_addr_copy(hw->mac.perm_addr, netdev->dev_addr); |
| 3119 |
} |
| 3120 |
|
| 3121 |
/* Enable dynamic interrupt throttling rates */ |
| 3122 |
adapter->rx_itr_setting = 1; |
| 3123 |
adapter->tx_itr_setting = 1; |
| 3124 |
|
| 3125 |
/* set default ring sizes */ |
| 3126 |
adapter->tx_ring_count = IXGBEVF_DEFAULT_TXD; |
| 3127 |
adapter->rx_ring_count = IXGBEVF_DEFAULT_RXD; |
| 3128 |
|
| 3129 |
adapter->link_state = true; |
| 3130 |
|
| 3131 |
set_bit(__IXGBEVF_DOWN, &adapter->state); |
| 3132 |
return 0; |
| 3133 |
|
| 3134 |
out: |
| 3135 |
return err; |
| 3136 |
} |
| 3137 |
|
| 3138 |
#define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \ |
| 3139 |
{ \ |
| 3140 |
u32 current_counter = IXGBE_READ_REG(hw, reg); \ |
| 3141 |
if (current_counter < last_counter) \ |
| 3142 |
counter += 0x100000000LL; \ |
| 3143 |
last_counter = current_counter; \ |
| 3144 |
counter &= 0xFFFFFFFF00000000LL; \ |
| 3145 |
counter |= current_counter; \ |
| 3146 |
} |
| 3147 |
|
| 3148 |
#define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \ |
| 3149 |
{ \ |
| 3150 |
u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \ |
| 3151 |
u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \ |
| 3152 |
u64 current_counter = (current_counter_msb << 32) | \ |
| 3153 |
current_counter_lsb; \ |
| 3154 |
if (current_counter < last_counter) \ |
| 3155 |
counter += 0x1000000000LL; \ |
| 3156 |
last_counter = current_counter; \ |
| 3157 |
counter &= 0xFFFFFFF000000000LL; \ |
| 3158 |
counter |= current_counter; \ |
| 3159 |
} |
| 3160 |
/** |
| 3161 |
* ixgbevf_update_stats - Update the board statistics counters. |
| 3162 |
* @adapter: board private structure |
| 3163 |
**/ |
| 3164 |
void ixgbevf_update_stats(struct ixgbevf_adapter *adapter) |
| 3165 |
{ |
| 3166 |
struct ixgbe_hw *hw = &adapter->hw; |
| 3167 |
u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0; |
| 3168 |
u64 alloc_rx_page = 0, hw_csum_rx_error = 0; |
| 3169 |
int i; |
| 3170 |
|
| 3171 |
if (test_bit(__IXGBEVF_DOWN, &adapter->state) || |
| 3172 |
test_bit(__IXGBEVF_RESETTING, &adapter->state)) |
| 3173 |
return; |
| 3174 |
|
| 3175 |
UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC, adapter->stats.last_vfgprc, |
| 3176 |
adapter->stats.vfgprc); |
| 3177 |
UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC, adapter->stats.last_vfgptc, |
| 3178 |
adapter->stats.vfgptc); |
| 3179 |
UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB, |
| 3180 |
adapter->stats.last_vfgorc, |
| 3181 |
adapter->stats.vfgorc); |
| 3182 |
UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB, |
| 3183 |
adapter->stats.last_vfgotc, |
| 3184 |
adapter->stats.vfgotc); |
| 3185 |
UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC, adapter->stats.last_vfmprc, |
| 3186 |
adapter->stats.vfmprc); |
| 3187 |
|
| 3188 |
for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3189 |
struct ixgbevf_ring *rx_ring = adapter->rx_ring[i]; |
| 3190 |
|
| 3191 |
hw_csum_rx_error += rx_ring->rx_stats.csum_err; |
| 3192 |
alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed; |
| 3193 |
alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed; |
| 3194 |
alloc_rx_page += rx_ring->rx_stats.alloc_rx_page; |
| 3195 |
} |
| 3196 |
|
| 3197 |
adapter->hw_csum_rx_error = hw_csum_rx_error; |
| 3198 |
adapter->alloc_rx_page_failed = alloc_rx_page_failed; |
| 3199 |
adapter->alloc_rx_buff_failed = alloc_rx_buff_failed; |
| 3200 |
adapter->alloc_rx_page = alloc_rx_page; |
| 3201 |
} |
| 3202 |
|
| 3203 |
/** |
| 3204 |
* ixgbevf_service_timer - Timer Call-back |
| 3205 |
* @t: pointer to timer_list struct |
| 3206 |
**/ |
| 3207 |
static void ixgbevf_service_timer(struct timer_list *t) |
| 3208 |
{ |
| 3209 |
struct ixgbevf_adapter *adapter = timer_container_of(adapter, t, |
| 3210 |
service_timer); |
| 3211 |
|
| 3212 |
/* Reset the timer */ |
| 3213 |
mod_timer(&adapter->service_timer, (HZ * 2) + jiffies); |
| 3214 |
|
| 3215 |
ixgbevf_service_event_schedule(adapter); |
| 3216 |
} |
| 3217 |
|
| 3218 |
static void ixgbevf_reset_subtask(struct ixgbevf_adapter *adapter) |
| 3219 |
{ |
| 3220 |
if (!test_and_clear_bit(__IXGBEVF_RESET_REQUESTED, &adapter->state)) |
| 3221 |
return; |
| 3222 |
|
| 3223 |
rtnl_lock(); |
| 3224 |
/* If we're already down or resetting, just bail */ |
| 3225 |
if (test_bit(__IXGBEVF_DOWN, &adapter->state) || |
| 3226 |
test_bit(__IXGBEVF_REMOVING, &adapter->state) || |
| 3227 |
test_bit(__IXGBEVF_RESETTING, &adapter->state)) { |
| 3228 |
rtnl_unlock(); |
| 3229 |
return; |
| 3230 |
} |
| 3231 |
|
| 3232 |
adapter->tx_timeout_count++; |
| 3233 |
|
| 3234 |
ixgbevf_reinit_locked(adapter); |
| 3235 |
rtnl_unlock(); |
| 3236 |
} |
| 3237 |
|
| 3238 |
/** |
| 3239 |
* ixgbevf_check_hang_subtask - check for hung queues and dropped interrupts |
| 3240 |
* @adapter: pointer to the device adapter structure |
| 3241 |
* |
| 3242 |
* This function serves two purposes. First it strobes the interrupt lines |
| 3243 |
* in order to make certain interrupts are occurring. Secondly it sets the |
| 3244 |
* bits needed to check for TX hangs. As a result we should immediately |
| 3245 |
* determine if a hang has occurred. |
| 3246 |
**/ |
| 3247 |
static void ixgbevf_check_hang_subtask(struct ixgbevf_adapter *adapter) |
| 3248 |
{ |
| 3249 |
struct ixgbe_hw *hw = &adapter->hw; |
| 3250 |
u32 eics = 0; |
| 3251 |
int i; |
| 3252 |
|
| 3253 |
/* If we're down or resetting, just bail */ |
| 3254 |
if (test_bit(__IXGBEVF_DOWN, &adapter->state) || |
| 3255 |
test_bit(__IXGBEVF_RESETTING, &adapter->state)) |
| 3256 |
return; |
| 3257 |
|
| 3258 |
/* Force detection of hung controller */ |
| 3259 |
if (netif_carrier_ok(adapter->netdev)) { |
| 3260 |
for (i = 0; i < adapter->num_tx_queues; i++) |
| 3261 |
set_check_for_tx_hang(adapter->tx_ring[i]); |
| 3262 |
for (i = 0; i < adapter->num_xdp_queues; i++) |
| 3263 |
set_check_for_tx_hang(adapter->xdp_ring[i]); |
| 3264 |
} |
| 3265 |
|
| 3266 |
/* get one bit for every active Tx/Rx interrupt vector */ |
| 3267 |
for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 3268 |
struct ixgbevf_q_vector *qv = adapter->q_vector[i]; |
| 3269 |
|
| 3270 |
if (qv->rx.ring || qv->tx.ring) |
| 3271 |
eics |= BIT(i); |
| 3272 |
} |
| 3273 |
|
| 3274 |
/* Cause software interrupt to ensure rings are cleaned */ |
| 3275 |
IXGBE_WRITE_REG(hw, IXGBE_VTEICS, eics); |
| 3276 |
} |
| 3277 |
|
| 3278 |
/** |
| 3279 |
* ixgbevf_watchdog_update_link - update the link status |
| 3280 |
* @adapter: pointer to the device adapter structure |
| 3281 |
**/ |
| 3282 |
static void ixgbevf_watchdog_update_link(struct ixgbevf_adapter *adapter) |
| 3283 |
{ |
| 3284 |
struct ixgbe_hw *hw = &adapter->hw; |
| 3285 |
u32 link_speed = adapter->link_speed; |
| 3286 |
bool link_up = adapter->link_up; |
| 3287 |
s32 err; |
| 3288 |
|
| 3289 |
spin_lock_bh(&adapter->mbx_lock); |
| 3290 |
|
| 3291 |
err = hw->mac.ops.check_link(hw, &link_speed, &link_up, false); |
| 3292 |
|
| 3293 |
spin_unlock_bh(&adapter->mbx_lock); |
| 3294 |
|
| 3295 |
/* if check for link returns error we will need to reset */ |
| 3296 |
if (err && time_after(jiffies, adapter->last_reset + (10 * HZ))) { |
| 3297 |
set_bit(__IXGBEVF_RESET_REQUESTED, &adapter->state); |
| 3298 |
link_up = false; |
| 3299 |
} |
| 3300 |
|
| 3301 |
adapter->link_up = link_up; |
| 3302 |
adapter->link_speed = link_speed; |
| 3303 |
} |
| 3304 |
|
| 3305 |
/** |
| 3306 |
* ixgbevf_watchdog_link_is_up - update netif_carrier status and |
| 3307 |
* print link up message |
| 3308 |
* @adapter: pointer to the device adapter structure |
| 3309 |
**/ |
| 3310 |
static void ixgbevf_watchdog_link_is_up(struct ixgbevf_adapter *adapter) |
| 3311 |
{ |
| 3312 |
struct net_device *netdev = adapter->netdev; |
| 3313 |
|
| 3314 |
/* only continue if link was previously down */ |
| 3315 |
if (netif_carrier_ok(netdev)) |
| 3316 |
return; |
| 3317 |
|
| 3318 |
dev_info(&adapter->pdev->dev, "NIC Link is Up %s\n", |
| 3319 |
(adapter->link_speed == IXGBE_LINK_SPEED_10GB_FULL) ? |
| 3320 |
"10 Gbps" : |
| 3321 |
(adapter->link_speed == IXGBE_LINK_SPEED_1GB_FULL) ? |
| 3322 |
"1 Gbps" : |
| 3323 |
(adapter->link_speed == IXGBE_LINK_SPEED_100_FULL) ? |
| 3324 |
"100 Mbps" : |
| 3325 |
"unknown speed"); |
| 3326 |
|
| 3327 |
netif_carrier_on(netdev); |
| 3328 |
} |
| 3329 |
|
| 3330 |
/** |
| 3331 |
* ixgbevf_watchdog_link_is_down - update netif_carrier status and |
| 3332 |
* print link down message |
| 3333 |
* @adapter: pointer to the adapter structure |
| 3334 |
**/ |
| 3335 |
static void ixgbevf_watchdog_link_is_down(struct ixgbevf_adapter *adapter) |
| 3336 |
{ |
| 3337 |
struct net_device *netdev = adapter->netdev; |
| 3338 |
|
| 3339 |
adapter->link_speed = 0; |
| 3340 |
|
| 3341 |
/* only continue if link was up previously */ |
| 3342 |
if (!netif_carrier_ok(netdev)) |
| 3343 |
return; |
| 3344 |
|
| 3345 |
dev_info(&adapter->pdev->dev, "NIC Link is Down\n"); |
| 3346 |
|
| 3347 |
netif_carrier_off(netdev); |
| 3348 |
} |
| 3349 |
|
| 3350 |
/** |
| 3351 |
* ixgbevf_watchdog_subtask - worker thread to bring link up |
| 3352 |
* @adapter: board private structure |
| 3353 |
**/ |
| 3354 |
static void ixgbevf_watchdog_subtask(struct ixgbevf_adapter *adapter) |
| 3355 |
{ |
| 3356 |
/* if interface is down do nothing */ |
| 3357 |
if (test_bit(__IXGBEVF_DOWN, &adapter->state) || |
| 3358 |
test_bit(__IXGBEVF_RESETTING, &adapter->state)) |
| 3359 |
return; |
| 3360 |
|
| 3361 |
ixgbevf_watchdog_update_link(adapter); |
| 3362 |
|
| 3363 |
if (adapter->link_up && adapter->link_state) |
| 3364 |
ixgbevf_watchdog_link_is_up(adapter); |
| 3365 |
else |
| 3366 |
ixgbevf_watchdog_link_is_down(adapter); |
| 3367 |
|
| 3368 |
ixgbevf_update_stats(adapter); |
| 3369 |
} |
| 3370 |
|
| 3371 |
/** |
| 3372 |
* ixgbevf_service_task - manages and runs subtasks |
| 3373 |
* @work: pointer to work_struct containing our data |
| 3374 |
**/ |
| 3375 |
static void ixgbevf_service_task(struct work_struct *work) |
| 3376 |
{ |
| 3377 |
struct ixgbevf_adapter *adapter = container_of(work, |
| 3378 |
struct ixgbevf_adapter, |
| 3379 |
service_task); |
| 3380 |
struct ixgbe_hw *hw = &adapter->hw; |
| 3381 |
|
| 3382 |
if (IXGBE_REMOVED(hw->hw_addr)) { |
| 3383 |
if (!test_bit(__IXGBEVF_DOWN, &adapter->state)) { |
| 3384 |
rtnl_lock(); |
| 3385 |
ixgbevf_down(adapter); |
| 3386 |
rtnl_unlock(); |
| 3387 |
} |
| 3388 |
return; |
| 3389 |
} |
| 3390 |
|
| 3391 |
ixgbevf_queue_reset_subtask(adapter); |
| 3392 |
ixgbevf_reset_subtask(adapter); |
| 3393 |
ixgbevf_watchdog_subtask(adapter); |
| 3394 |
ixgbevf_check_hang_subtask(adapter); |
| 3395 |
|
| 3396 |
ixgbevf_service_event_complete(adapter); |
| 3397 |
} |
| 3398 |
|
| 3399 |
/** |
| 3400 |
* ixgbevf_free_tx_resources - Free Tx Resources per Queue |
| 3401 |
* @tx_ring: Tx descriptor ring for a specific queue |
| 3402 |
* |
| 3403 |
* Free all transmit software resources |
| 3404 |
**/ |
| 3405 |
void ixgbevf_free_tx_resources(struct ixgbevf_ring *tx_ring) |
| 3406 |
{ |
| 3407 |
ixgbevf_clean_tx_ring(tx_ring); |
| 3408 |
|
| 3409 |
vfree(tx_ring->tx_buffer_info); |
| 3410 |
tx_ring->tx_buffer_info = NULL; |
| 3411 |
|
| 3412 |
/* if not set, then don't free */ |
| 3413 |
if (!tx_ring->desc) |
| 3414 |
return; |
| 3415 |
|
| 3416 |
dma_free_coherent(tx_ring->dev, tx_ring->size, tx_ring->desc, |
| 3417 |
tx_ring->dma); |
| 3418 |
|
| 3419 |
tx_ring->desc = NULL; |
| 3420 |
} |
| 3421 |
|
| 3422 |
/** |
| 3423 |
* ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues |
| 3424 |
* @adapter: board private structure |
| 3425 |
* |
| 3426 |
* Free all transmit software resources |
| 3427 |
**/ |
| 3428 |
static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter *adapter) |
| 3429 |
{ |
| 3430 |
int i; |
| 3431 |
|
| 3432 |
for (i = 0; i < adapter->num_tx_queues; i++) |
| 3433 |
if (adapter->tx_ring[i]->desc) |
| 3434 |
ixgbevf_free_tx_resources(adapter->tx_ring[i]); |
| 3435 |
for (i = 0; i < adapter->num_xdp_queues; i++) |
| 3436 |
if (adapter->xdp_ring[i]->desc) |
| 3437 |
ixgbevf_free_tx_resources(adapter->xdp_ring[i]); |
| 3438 |
} |
| 3439 |
|
| 3440 |
/** |
| 3441 |
* ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors) |
| 3442 |
* @tx_ring: Tx descriptor ring (for a specific queue) to setup |
| 3443 |
* |
| 3444 |
* Return 0 on success, negative on failure |
| 3445 |
**/ |
| 3446 |
int ixgbevf_setup_tx_resources(struct ixgbevf_ring *tx_ring) |
| 3447 |
{ |
| 3448 |
struct ixgbevf_adapter *adapter = netdev_priv(tx_ring->netdev); |
| 3449 |
int size; |
| 3450 |
|
| 3451 |
size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count; |
| 3452 |
tx_ring->tx_buffer_info = vmalloc(size); |
| 3453 |
if (!tx_ring->tx_buffer_info) |
| 3454 |
goto err; |
| 3455 |
|
| 3456 |
u64_stats_init(&tx_ring->syncp); |
| 3457 |
|
| 3458 |
/* round up to nearest 4K */ |
| 3459 |
tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
| 3460 |
tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 3461 |
|
| 3462 |
tx_ring->desc = dma_alloc_coherent(tx_ring->dev, tx_ring->size, |
| 3463 |
&tx_ring->dma, GFP_KERNEL); |
| 3464 |
if (!tx_ring->desc) |
| 3465 |
goto err; |
| 3466 |
|
| 3467 |
return 0; |
| 3468 |
|
| 3469 |
err: |
| 3470 |
vfree(tx_ring->tx_buffer_info); |
| 3471 |
tx_ring->tx_buffer_info = NULL; |
| 3472 |
hw_dbg(&adapter->hw, "Unable to allocate memory for the transmit descriptor ring\n"); |
| 3473 |
return -ENOMEM; |
| 3474 |
} |
| 3475 |
|
| 3476 |
/** |
| 3477 |
* ixgbevf_setup_all_tx_resources - allocate all queues Tx resources |
| 3478 |
* @adapter: board private structure |
| 3479 |
* |
| 3480 |
* If this function returns with an error, then it's possible one or |
| 3481 |
* more of the rings is populated (while the rest are not). It is the |
| 3482 |
* callers duty to clean those orphaned rings. |
| 3483 |
* |
| 3484 |
* Return 0 on success, negative on failure |
| 3485 |
**/ |
| 3486 |
static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter *adapter) |
| 3487 |
{ |
| 3488 |
int i, j = 0, err = 0; |
| 3489 |
|
| 3490 |
for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3491 |
err = ixgbevf_setup_tx_resources(adapter->tx_ring[i]); |
| 3492 |
if (!err) |
| 3493 |
continue; |
| 3494 |
hw_dbg(&adapter->hw, "Allocation for Tx Queue %u failed\n", i); |
| 3495 |
goto err_setup_tx; |
| 3496 |
} |
| 3497 |
|
| 3498 |
for (j = 0; j < adapter->num_xdp_queues; j++) { |
| 3499 |
err = ixgbevf_setup_tx_resources(adapter->xdp_ring[j]); |
| 3500 |
if (!err) |
| 3501 |
continue; |
| 3502 |
hw_dbg(&adapter->hw, "Allocation for XDP Queue %u failed\n", j); |
| 3503 |
goto err_setup_tx; |
| 3504 |
} |
| 3505 |
|
| 3506 |
return 0; |
| 3507 |
err_setup_tx: |
| 3508 |
/* rewind the index freeing the rings as we go */ |
| 3509 |
while (j--) |
| 3510 |
ixgbevf_free_tx_resources(adapter->xdp_ring[j]); |
| 3511 |
while (i--) |
| 3512 |
ixgbevf_free_tx_resources(adapter->tx_ring[i]); |
| 3513 |
|
| 3514 |
return err; |
| 3515 |
} |
| 3516 |
|
| 3517 |
/** |
| 3518 |
* ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors) |
| 3519 |
* @adapter: board private structure |
| 3520 |
* @rx_ring: Rx descriptor ring (for a specific queue) to setup |
| 3521 |
* |
| 3522 |
* Returns 0 on success, negative on failure |
| 3523 |
**/ |
| 3524 |
int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *adapter, |
| 3525 |
struct ixgbevf_ring *rx_ring) |
| 3526 |
{ |
| 3527 |
int size; |
| 3528 |
|
| 3529 |
size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count; |
| 3530 |
rx_ring->rx_buffer_info = vmalloc(size); |
| 3531 |
if (!rx_ring->rx_buffer_info) |
| 3532 |
goto err; |
| 3533 |
|
| 3534 |
u64_stats_init(&rx_ring->syncp); |
| 3535 |
|
| 3536 |
/* Round up to nearest 4K */ |
| 3537 |
rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 3538 |
rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 3539 |
|
| 3540 |
rx_ring->desc = dma_alloc_coherent(rx_ring->dev, rx_ring->size, |
| 3541 |
&rx_ring->dma, GFP_KERNEL); |
| 3542 |
|
| 3543 |
if (!rx_ring->desc) |
| 3544 |
goto err; |
| 3545 |
|
| 3546 |
/* XDP RX-queue info */ |
| 3547 |
if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev, |
| 3548 |
rx_ring->queue_index, 0) < 0) |
| 3549 |
goto err; |
| 3550 |
|
| 3551 |
rx_ring->xdp_prog = adapter->xdp_prog; |
| 3552 |
|
| 3553 |
return 0; |
| 3554 |
err: |
| 3555 |
vfree(rx_ring->rx_buffer_info); |
| 3556 |
rx_ring->rx_buffer_info = NULL; |
| 3557 |
dev_err(rx_ring->dev, "Unable to allocate memory for the Rx descriptor ring\n"); |
| 3558 |
return -ENOMEM; |
| 3559 |
} |
| 3560 |
|
| 3561 |
/** |
| 3562 |
* ixgbevf_setup_all_rx_resources - allocate all queues Rx resources |
| 3563 |
* @adapter: board private structure |
| 3564 |
* |
| 3565 |
* If this function returns with an error, then it's possible one or |
| 3566 |
* more of the rings is populated (while the rest are not). It is the |
| 3567 |
* callers duty to clean those orphaned rings. |
| 3568 |
* |
| 3569 |
* Return 0 on success, negative on failure |
| 3570 |
**/ |
| 3571 |
static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter *adapter) |
| 3572 |
{ |
| 3573 |
int i, err = 0; |
| 3574 |
|
| 3575 |
for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3576 |
err = ixgbevf_setup_rx_resources(adapter, adapter->rx_ring[i]); |
| 3577 |
if (!err) |
| 3578 |
continue; |
| 3579 |
hw_dbg(&adapter->hw, "Allocation for Rx Queue %u failed\n", i); |
| 3580 |
goto err_setup_rx; |
| 3581 |
} |
| 3582 |
|
| 3583 |
return 0; |
| 3584 |
err_setup_rx: |
| 3585 |
/* rewind the index freeing the rings as we go */ |
| 3586 |
while (i--) |
| 3587 |
ixgbevf_free_rx_resources(adapter->rx_ring[i]); |
| 3588 |
return err; |
| 3589 |
} |
| 3590 |
|
| 3591 |
/** |
| 3592 |
* ixgbevf_free_rx_resources - Free Rx Resources |
| 3593 |
* @rx_ring: ring to clean the resources from |
| 3594 |
* |
| 3595 |
* Free all receive software resources |
| 3596 |
**/ |
| 3597 |
void ixgbevf_free_rx_resources(struct ixgbevf_ring *rx_ring) |
| 3598 |
{ |
| 3599 |
ixgbevf_clean_rx_ring(rx_ring); |
| 3600 |
|
| 3601 |
rx_ring->xdp_prog = NULL; |
| 3602 |
xdp_rxq_info_unreg(&rx_ring->xdp_rxq); |
| 3603 |
vfree(rx_ring->rx_buffer_info); |
| 3604 |
rx_ring->rx_buffer_info = NULL; |
| 3605 |
|
| 3606 |
dma_free_coherent(rx_ring->dev, rx_ring->size, rx_ring->desc, |
| 3607 |
rx_ring->dma); |
| 3608 |
|
| 3609 |
rx_ring->desc = NULL; |
| 3610 |
} |
| 3611 |
|
| 3612 |
/** |
| 3613 |
* ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues |
| 3614 |
* @adapter: board private structure |
| 3615 |
* |
| 3616 |
* Free all receive software resources |
| 3617 |
**/ |
| 3618 |
static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter *adapter) |
| 3619 |
{ |
| 3620 |
int i; |
| 3621 |
|
| 3622 |
for (i = 0; i < adapter->num_rx_queues; i++) |
| 3623 |
if (adapter->rx_ring[i]->desc) |
| 3624 |
ixgbevf_free_rx_resources(adapter->rx_ring[i]); |
| 3625 |
} |
| 3626 |
|
| 3627 |
/** |
| 3628 |
* ixgbevf_open - Called when a network interface is made active |
| 3629 |
* @netdev: network interface device structure |
| 3630 |
* |
| 3631 |
* Returns 0 on success, negative value on failure |
| 3632 |
* |
| 3633 |
* The open entry point is called when a network interface is made |
| 3634 |
* active by the system (IFF_UP). At this point all resources needed |
| 3635 |
* for transmit and receive operations are allocated, the interrupt |
| 3636 |
* handler is registered with the OS, the watchdog timer is started, |
| 3637 |
* and the stack is notified that the interface is ready. |
| 3638 |
**/ |
| 3639 |
int ixgbevf_open(struct net_device *netdev) |
| 3640 |
{ |
| 3641 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 3642 |
struct ixgbe_hw *hw = &adapter->hw; |
| 3643 |
int err; |
| 3644 |
|
| 3645 |
/* A previous failure to open the device because of a lack of |
| 3646 |
* available MSIX vector resources may have reset the number |
| 3647 |
* of msix vectors variable to zero. The only way to recover |
| 3648 |
* is to unload/reload the driver and hope that the system has |
| 3649 |
* been able to recover some MSIX vector resources. |
| 3650 |
*/ |
| 3651 |
if (!adapter->num_msix_vectors) |
| 3652 |
return -ENOMEM; |
| 3653 |
|
| 3654 |
if (hw->adapter_stopped) { |
| 3655 |
ixgbevf_reset(adapter); |
| 3656 |
/* if adapter is still stopped then PF isn't up and |
| 3657 |
* the VF can't start. |
| 3658 |
*/ |
| 3659 |
if (hw->adapter_stopped) { |
| 3660 |
err = IXGBE_ERR_MBX; |
| 3661 |
pr_err("Unable to start - perhaps the PF Driver isn't up yet\n"); |
| 3662 |
goto err_setup_reset; |
| 3663 |
} |
| 3664 |
} |
| 3665 |
|
| 3666 |
/* disallow open during test */ |
| 3667 |
if (test_bit(__IXGBEVF_TESTING, &adapter->state)) |
| 3668 |
return -EBUSY; |
| 3669 |
|
| 3670 |
netif_carrier_off(netdev); |
| 3671 |
|
| 3672 |
/* allocate transmit descriptors */ |
| 3673 |
err = ixgbevf_setup_all_tx_resources(adapter); |
| 3674 |
if (err) |
| 3675 |
goto err_setup_tx; |
| 3676 |
|
| 3677 |
/* allocate receive descriptors */ |
| 3678 |
err = ixgbevf_setup_all_rx_resources(adapter); |
| 3679 |
if (err) |
| 3680 |
goto err_setup_rx; |
| 3681 |
|
| 3682 |
ixgbevf_configure(adapter); |
| 3683 |
|
| 3684 |
err = ixgbevf_request_irq(adapter); |
| 3685 |
if (err) |
| 3686 |
goto err_req_irq; |
| 3687 |
|
| 3688 |
/* Notify the stack of the actual queue counts. */ |
| 3689 |
err = netif_set_real_num_tx_queues(netdev, adapter->num_tx_queues); |
| 3690 |
if (err) |
| 3691 |
goto err_set_queues; |
| 3692 |
|
| 3693 |
err = netif_set_real_num_rx_queues(netdev, adapter->num_rx_queues); |
| 3694 |
if (err) |
| 3695 |
goto err_set_queues; |
| 3696 |
|
| 3697 |
ixgbevf_up_complete(adapter); |
| 3698 |
|
| 3699 |
return 0; |
| 3700 |
|
| 3701 |
err_set_queues: |
| 3702 |
ixgbevf_free_irq(adapter); |
| 3703 |
err_req_irq: |
| 3704 |
ixgbevf_free_all_rx_resources(adapter); |
| 3705 |
err_setup_rx: |
| 3706 |
ixgbevf_free_all_tx_resources(adapter); |
| 3707 |
err_setup_tx: |
| 3708 |
ixgbevf_reset(adapter); |
| 3709 |
err_setup_reset: |
| 3710 |
|
| 3711 |
return err; |
| 3712 |
} |
| 3713 |
|
| 3714 |
/** |
| 3715 |
* ixgbevf_close_suspend - actions necessary to both suspend and close flows |
| 3716 |
* @adapter: the private adapter struct |
| 3717 |
* |
| 3718 |
* This function should contain the necessary work common to both suspending |
| 3719 |
* and closing of the device. |
| 3720 |
*/ |
| 3721 |
static void ixgbevf_close_suspend(struct ixgbevf_adapter *adapter) |
| 3722 |
{ |
| 3723 |
ixgbevf_down(adapter); |
| 3724 |
ixgbevf_free_irq(adapter); |
| 3725 |
ixgbevf_free_all_tx_resources(adapter); |
| 3726 |
ixgbevf_free_all_rx_resources(adapter); |
| 3727 |
} |
| 3728 |
|
| 3729 |
/** |
| 3730 |
* ixgbevf_close - Disables a network interface |
| 3731 |
* @netdev: network interface device structure |
| 3732 |
* |
| 3733 |
* Returns 0, this is not allowed to fail |
| 3734 |
* |
| 3735 |
* The close entry point is called when an interface is de-activated |
| 3736 |
* by the OS. The hardware is still under the drivers control, but |
| 3737 |
* needs to be disabled. A global MAC reset is issued to stop the |
| 3738 |
* hardware, and all transmit and receive resources are freed. |
| 3739 |
**/ |
| 3740 |
int ixgbevf_close(struct net_device *netdev) |
| 3741 |
{ |
| 3742 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 3743 |
|
| 3744 |
if (netif_device_present(netdev)) |
| 3745 |
ixgbevf_close_suspend(adapter); |
| 3746 |
|
| 3747 |
return 0; |
| 3748 |
} |
| 3749 |
|
| 3750 |
static void ixgbevf_queue_reset_subtask(struct ixgbevf_adapter *adapter) |
| 3751 |
{ |
| 3752 |
struct net_device *dev = adapter->netdev; |
| 3753 |
|
| 3754 |
if (!test_and_clear_bit(__IXGBEVF_QUEUE_RESET_REQUESTED, |
| 3755 |
&adapter->state)) |
| 3756 |
return; |
| 3757 |
|
| 3758 |
/* if interface is down do nothing */ |
| 3759 |
if (test_bit(__IXGBEVF_DOWN, &adapter->state) || |
| 3760 |
test_bit(__IXGBEVF_RESETTING, &adapter->state)) |
| 3761 |
return; |
| 3762 |
|
| 3763 |
/* Hardware has to reinitialize queues and interrupts to |
| 3764 |
* match packet buffer alignment. Unfortunately, the |
| 3765 |
* hardware is not flexible enough to do this dynamically. |
| 3766 |
*/ |
| 3767 |
rtnl_lock(); |
| 3768 |
|
| 3769 |
if (netif_running(dev)) |
| 3770 |
ixgbevf_close(dev); |
| 3771 |
|
| 3772 |
ixgbevf_clear_interrupt_scheme(adapter); |
| 3773 |
ixgbevf_init_interrupt_scheme(adapter); |
| 3774 |
|
| 3775 |
if (netif_running(dev)) |
| 3776 |
ixgbevf_open(dev); |
| 3777 |
|
| 3778 |
rtnl_unlock(); |
| 3779 |
} |
| 3780 |
|
| 3781 |
static void ixgbevf_tx_ctxtdesc(struct ixgbevf_ring *tx_ring, |
| 3782 |
u32 vlan_macip_lens, u32 fceof_saidx, |
| 3783 |
u32 type_tucmd, u32 mss_l4len_idx) |
| 3784 |
{ |
| 3785 |
struct ixgbe_adv_tx_context_desc *context_desc; |
| 3786 |
u16 i = tx_ring->next_to_use; |
| 3787 |
|
| 3788 |
context_desc = IXGBEVF_TX_CTXTDESC(tx_ring, i); |
| 3789 |
|
| 3790 |
i++; |
| 3791 |
tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 3792 |
|
| 3793 |
/* set bits to identify this as an advanced context descriptor */ |
| 3794 |
type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; |
| 3795 |
|
| 3796 |
context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 3797 |
context_desc->fceof_saidx = cpu_to_le32(fceof_saidx); |
| 3798 |
context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); |
| 3799 |
context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 3800 |
} |
| 3801 |
|
| 3802 |
static int ixgbevf_tso(struct ixgbevf_ring *tx_ring, |
| 3803 |
struct ixgbevf_tx_buffer *first, |
| 3804 |
u8 *hdr_len, |
| 3805 |
struct ixgbevf_ipsec_tx_data *itd) |
| 3806 |
{ |
| 3807 |
u32 vlan_macip_lens, type_tucmd, mss_l4len_idx; |
| 3808 |
struct sk_buff *skb = first->skb; |
| 3809 |
union { |
| 3810 |
struct iphdr *v4; |
| 3811 |
struct ipv6hdr *v6; |
| 3812 |
unsigned char *hdr; |
| 3813 |
} ip; |
| 3814 |
union { |
| 3815 |
struct tcphdr *tcp; |
| 3816 |
unsigned char *hdr; |
| 3817 |
} l4; |
| 3818 |
u32 paylen, l4_offset; |
| 3819 |
u32 fceof_saidx = 0; |
| 3820 |
int err; |
| 3821 |
|
| 3822 |
if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 3823 |
return 0; |
| 3824 |
|
| 3825 |
if (!skb_is_gso(skb)) |
| 3826 |
return 0; |
| 3827 |
|
| 3828 |
err = skb_cow_head(skb, 0); |
| 3829 |
if (err < 0) |
| 3830 |
return err; |
| 3831 |
|
| 3832 |
if (eth_p_mpls(first->protocol)) |
| 3833 |
ip.hdr = skb_inner_network_header(skb); |
| 3834 |
else |
| 3835 |
ip.hdr = skb_network_header(skb); |
| 3836 |
l4.hdr = skb_checksum_start(skb); |
| 3837 |
|
| 3838 |
/* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 3839 |
type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 3840 |
|
| 3841 |
/* initialize outer IP header fields */ |
| 3842 |
if (ip.v4->version == 4) { |
| 3843 |
unsigned char *csum_start = skb_checksum_start(skb); |
| 3844 |
unsigned char *trans_start = ip.hdr + (ip.v4->ihl * 4); |
| 3845 |
int len = csum_start - trans_start; |
| 3846 |
|
| 3847 |
/* IP header will have to cancel out any data that |
| 3848 |
* is not a part of the outer IP header, so set to |
| 3849 |
* a reverse csum if needed, else init check to 0. |
| 3850 |
*/ |
| 3851 |
ip.v4->check = (skb_shinfo(skb)->gso_type & SKB_GSO_PARTIAL) ? |
| 3852 |
csum_fold(csum_partial(trans_start, |
| 3853 |
len, 0)) : 0; |
| 3854 |
type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 3855 |
|
| 3856 |
ip.v4->tot_len = 0; |
| 3857 |
first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 3858 |
IXGBE_TX_FLAGS_CSUM | |
| 3859 |
IXGBE_TX_FLAGS_IPV4; |
| 3860 |
} else { |
| 3861 |
ip.v6->payload_len = 0; |
| 3862 |
first->tx_flags |= IXGBE_TX_FLAGS_TSO | |
| 3863 |
IXGBE_TX_FLAGS_CSUM; |
| 3864 |
} |
| 3865 |
|
| 3866 |
/* determine offset of inner transport header */ |
| 3867 |
l4_offset = l4.hdr - skb->data; |
| 3868 |
|
| 3869 |
/* compute length of segmentation header */ |
| 3870 |
*hdr_len = (l4.tcp->doff * 4) + l4_offset; |
| 3871 |
|
| 3872 |
/* remove payload length from inner checksum */ |
| 3873 |
paylen = skb->len - l4_offset; |
| 3874 |
csum_replace_by_diff(&l4.tcp->check, (__force __wsum)htonl(paylen)); |
| 3875 |
|
| 3876 |
/* update gso size and bytecount with header size */ |
| 3877 |
first->gso_segs = skb_shinfo(skb)->gso_segs; |
| 3878 |
first->bytecount += (first->gso_segs - 1) * *hdr_len; |
| 3879 |
|
| 3880 |
/* mss_l4len_id: use 1 as index for TSO */ |
| 3881 |
mss_l4len_idx = (*hdr_len - l4_offset) << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 3882 |
mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
| 3883 |
mss_l4len_idx |= (1u << IXGBE_ADVTXD_IDX_SHIFT); |
| 3884 |
|
| 3885 |
fceof_saidx |= itd->pfsa; |
| 3886 |
type_tucmd |= itd->flags | itd->trailer_len; |
| 3887 |
|
| 3888 |
/* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 3889 |
vlan_macip_lens = l4.hdr - ip.hdr; |
| 3890 |
vlan_macip_lens |= (ip.hdr - skb->data) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 3891 |
vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 3892 |
|
| 3893 |
ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens, fceof_saidx, type_tucmd, |
| 3894 |
mss_l4len_idx); |
| 3895 |
|
| 3896 |
return 1; |
| 3897 |
} |
| 3898 |
|
| 3899 |
static void ixgbevf_tx_csum(struct ixgbevf_ring *tx_ring, |
| 3900 |
struct ixgbevf_tx_buffer *first, |
| 3901 |
struct ixgbevf_ipsec_tx_data *itd) |
| 3902 |
{ |
| 3903 |
struct sk_buff *skb = first->skb; |
| 3904 |
u32 vlan_macip_lens = 0; |
| 3905 |
u32 fceof_saidx = 0; |
| 3906 |
u32 type_tucmd = 0; |
| 3907 |
|
| 3908 |
if (skb->ip_summed != CHECKSUM_PARTIAL) |
| 3909 |
goto no_csum; |
| 3910 |
|
| 3911 |
switch (skb->csum_offset) { |
| 3912 |
case offsetof(struct tcphdr, check): |
| 3913 |
type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 3914 |
fallthrough; |
| 3915 |
case offsetof(struct udphdr, check): |
| 3916 |
break; |
| 3917 |
case offsetof(struct sctphdr, checksum): |
| 3918 |
/* validate that this is actually an SCTP request */ |
| 3919 |
if (skb_csum_is_sctp(skb)) { |
| 3920 |
type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 3921 |
break; |
| 3922 |
} |
| 3923 |
fallthrough; |
| 3924 |
default: |
| 3925 |
skb_checksum_help(skb); |
| 3926 |
goto no_csum; |
| 3927 |
} |
| 3928 |
|
| 3929 |
if (first->protocol == htons(ETH_P_IP)) |
| 3930 |
type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 3931 |
|
| 3932 |
/* update TX checksum flag */ |
| 3933 |
first->tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 3934 |
vlan_macip_lens = skb_checksum_start_offset(skb) - |
| 3935 |
skb_network_offset(skb); |
| 3936 |
no_csum: |
| 3937 |
/* vlan_macip_lens: MACLEN, VLAN tag */ |
| 3938 |
vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 3939 |
vlan_macip_lens |= first->tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 3940 |
|
| 3941 |
fceof_saidx |= itd->pfsa; |
| 3942 |
type_tucmd |= itd->flags | itd->trailer_len; |
| 3943 |
|
| 3944 |
ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens, |
| 3945 |
fceof_saidx, type_tucmd, 0); |
| 3946 |
} |
| 3947 |
|
| 3948 |
static __le32 ixgbevf_tx_cmd_type(u32 tx_flags) |
| 3949 |
{ |
| 3950 |
/* set type for advanced descriptor with frame checksum insertion */ |
| 3951 |
__le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA | |
| 3952 |
IXGBE_ADVTXD_DCMD_IFCS | |
| 3953 |
IXGBE_ADVTXD_DCMD_DEXT); |
| 3954 |
|
| 3955 |
/* set HW VLAN bit if VLAN is present */ |
| 3956 |
if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 3957 |
cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE); |
| 3958 |
|
| 3959 |
/* set segmentation enable bits for TSO/FSO */ |
| 3960 |
if (tx_flags & IXGBE_TX_FLAGS_TSO) |
| 3961 |
cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE); |
| 3962 |
|
| 3963 |
return cmd_type; |
| 3964 |
} |
| 3965 |
|
| 3966 |
static void ixgbevf_tx_olinfo_status(union ixgbe_adv_tx_desc *tx_desc, |
| 3967 |
u32 tx_flags, unsigned int paylen) |
| 3968 |
{ |
| 3969 |
__le32 olinfo_status = cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 3970 |
|
| 3971 |
/* enable L4 checksum for TSO and TX checksum offload */ |
| 3972 |
if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 3973 |
olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM); |
| 3974 |
|
| 3975 |
/* enble IPv4 checksum for TSO */ |
| 3976 |
if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 3977 |
olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM); |
| 3978 |
|
| 3979 |
/* enable IPsec */ |
| 3980 |
if (tx_flags & IXGBE_TX_FLAGS_IPSEC) |
| 3981 |
olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IPSEC); |
| 3982 |
|
| 3983 |
/* use index 1 context for TSO/FSO/FCOE/IPSEC */ |
| 3984 |
if (tx_flags & (IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_IPSEC)) |
| 3985 |
olinfo_status |= cpu_to_le32(1u << IXGBE_ADVTXD_IDX_SHIFT); |
| 3986 |
|
| 3987 |
/* Check Context must be set if Tx switch is enabled, which it |
| 3988 |
* always is for case where virtual functions are running |
| 3989 |
*/ |
| 3990 |
olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC); |
| 3991 |
|
| 3992 |
tx_desc->read.olinfo_status = olinfo_status; |
| 3993 |
} |
| 3994 |
|
| 3995 |
static void ixgbevf_tx_map(struct ixgbevf_ring *tx_ring, |
| 3996 |
struct ixgbevf_tx_buffer *first, |
| 3997 |
const u8 hdr_len) |
| 3998 |
{ |
| 3999 |
struct sk_buff *skb = first->skb; |
| 4000 |
struct ixgbevf_tx_buffer *tx_buffer; |
| 4001 |
union ixgbe_adv_tx_desc *tx_desc; |
| 4002 |
skb_frag_t *frag; |
| 4003 |
dma_addr_t dma; |
| 4004 |
unsigned int data_len, size; |
| 4005 |
u32 tx_flags = first->tx_flags; |
| 4006 |
__le32 cmd_type = ixgbevf_tx_cmd_type(tx_flags); |
| 4007 |
u16 i = tx_ring->next_to_use; |
| 4008 |
|
| 4009 |
tx_desc = IXGBEVF_TX_DESC(tx_ring, i); |
| 4010 |
|
| 4011 |
ixgbevf_tx_olinfo_status(tx_desc, tx_flags, skb->len - hdr_len); |
| 4012 |
|
| 4013 |
size = skb_headlen(skb); |
| 4014 |
data_len = skb->data_len; |
| 4015 |
|
| 4016 |
dma = dma_map_single(tx_ring->dev, skb->data, size, DMA_TO_DEVICE); |
| 4017 |
|
| 4018 |
tx_buffer = first; |
| 4019 |
|
| 4020 |
for (frag = &skb_shinfo(skb)->frags[0];; frag++) { |
| 4021 |
if (dma_mapping_error(tx_ring->dev, dma)) |
| 4022 |
goto dma_error; |
| 4023 |
|
| 4024 |
/* record length, and DMA address */ |
| 4025 |
dma_unmap_len_set(tx_buffer, len, size); |
| 4026 |
dma_unmap_addr_set(tx_buffer, dma, dma); |
| 4027 |
|
| 4028 |
tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 4029 |
|
| 4030 |
while (unlikely(size > IXGBE_MAX_DATA_PER_TXD)) { |
| 4031 |
tx_desc->read.cmd_type_len = |
| 4032 |
cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD); |
| 4033 |
|
| 4034 |
i++; |
| 4035 |
tx_desc++; |
| 4036 |
if (i == tx_ring->count) { |
| 4037 |
tx_desc = IXGBEVF_TX_DESC(tx_ring, 0); |
| 4038 |
i = 0; |
| 4039 |
} |
| 4040 |
tx_desc->read.olinfo_status = 0; |
| 4041 |
|
| 4042 |
dma += IXGBE_MAX_DATA_PER_TXD; |
| 4043 |
size -= IXGBE_MAX_DATA_PER_TXD; |
| 4044 |
|
| 4045 |
tx_desc->read.buffer_addr = cpu_to_le64(dma); |
| 4046 |
} |
| 4047 |
|
| 4048 |
if (likely(!data_len)) |
| 4049 |
break; |
| 4050 |
|
| 4051 |
tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size); |
| 4052 |
|
| 4053 |
i++; |
| 4054 |
tx_desc++; |
| 4055 |
if (i == tx_ring->count) { |
| 4056 |
tx_desc = IXGBEVF_TX_DESC(tx_ring, 0); |
| 4057 |
i = 0; |
| 4058 |
} |
| 4059 |
tx_desc->read.olinfo_status = 0; |
| 4060 |
|
| 4061 |
size = skb_frag_size(frag); |
| 4062 |
data_len -= size; |
| 4063 |
|
| 4064 |
dma = skb_frag_dma_map(tx_ring->dev, frag, 0, size, |
| 4065 |
DMA_TO_DEVICE); |
| 4066 |
|
| 4067 |
tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 4068 |
} |
| 4069 |
|
| 4070 |
/* write last descriptor with RS and EOP bits */ |
| 4071 |
cmd_type |= cpu_to_le32(size) | cpu_to_le32(IXGBE_TXD_CMD); |
| 4072 |
tx_desc->read.cmd_type_len = cmd_type; |
| 4073 |
|
| 4074 |
/* set the timestamp */ |
| 4075 |
first->time_stamp = jiffies; |
| 4076 |
|
| 4077 |
skb_tx_timestamp(skb); |
| 4078 |
|
| 4079 |
/* Force memory writes to complete before letting h/w know there |
| 4080 |
* are new descriptors to fetch. (Only applicable for weak-ordered |
| 4081 |
* memory model archs, such as IA-64). |
| 4082 |
* |
| 4083 |
* We also need this memory barrier (wmb) to make certain all of the |
| 4084 |
* status bits have been updated before next_to_watch is written. |
| 4085 |
*/ |
| 4086 |
wmb(); |
| 4087 |
|
| 4088 |
/* set next_to_watch value indicating a packet is present */ |
| 4089 |
first->next_to_watch = tx_desc; |
| 4090 |
|
| 4091 |
i++; |
| 4092 |
if (i == tx_ring->count) |
| 4093 |
i = 0; |
| 4094 |
|
| 4095 |
tx_ring->next_to_use = i; |
| 4096 |
|
| 4097 |
/* notify HW of packet */ |
| 4098 |
ixgbevf_write_tail(tx_ring, i); |
| 4099 |
|
| 4100 |
return; |
| 4101 |
dma_error: |
| 4102 |
dev_err(tx_ring->dev, "TX DMA map failed\n"); |
| 4103 |
tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 4104 |
|
| 4105 |
/* clear dma mappings for failed tx_buffer_info map */ |
| 4106 |
while (tx_buffer != first) { |
| 4107 |
if (dma_unmap_len(tx_buffer, len)) |
| 4108 |
dma_unmap_page(tx_ring->dev, |
| 4109 |
dma_unmap_addr(tx_buffer, dma), |
| 4110 |
dma_unmap_len(tx_buffer, len), |
| 4111 |
DMA_TO_DEVICE); |
| 4112 |
dma_unmap_len_set(tx_buffer, len, 0); |
| 4113 |
|
| 4114 |
if (i-- == 0) |
| 4115 |
i += tx_ring->count; |
| 4116 |
tx_buffer = &tx_ring->tx_buffer_info[i]; |
| 4117 |
} |
| 4118 |
|
| 4119 |
if (dma_unmap_len(tx_buffer, len)) |
| 4120 |
dma_unmap_single(tx_ring->dev, |
| 4121 |
dma_unmap_addr(tx_buffer, dma), |
| 4122 |
dma_unmap_len(tx_buffer, len), |
| 4123 |
DMA_TO_DEVICE); |
| 4124 |
dma_unmap_len_set(tx_buffer, len, 0); |
| 4125 |
|
| 4126 |
dev_kfree_skb_any(tx_buffer->skb); |
| 4127 |
tx_buffer->skb = NULL; |
| 4128 |
|
| 4129 |
tx_ring->next_to_use = i; |
| 4130 |
} |
| 4131 |
|
| 4132 |
static int __ixgbevf_maybe_stop_tx(struct ixgbevf_ring *tx_ring, int size) |
| 4133 |
{ |
| 4134 |
netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 4135 |
/* Herbert's original patch had: |
| 4136 |
* smp_mb__after_netif_stop_queue(); |
| 4137 |
* but since that doesn't exist yet, just open code it. |
| 4138 |
*/ |
| 4139 |
smp_mb(); |
| 4140 |
|
| 4141 |
/* We need to check again in a case another CPU has just |
| 4142 |
* made room available. |
| 4143 |
*/ |
| 4144 |
if (likely(ixgbevf_desc_unused(tx_ring) < size)) |
| 4145 |
return -EBUSY; |
| 4146 |
|
| 4147 |
/* A reprieve! - use start_queue because it doesn't call schedule */ |
| 4148 |
netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
| 4149 |
++tx_ring->tx_stats.restart_queue; |
| 4150 |
|
| 4151 |
return 0; |
| 4152 |
} |
| 4153 |
|
| 4154 |
static int ixgbevf_maybe_stop_tx(struct ixgbevf_ring *tx_ring, int size) |
| 4155 |
{ |
| 4156 |
if (likely(ixgbevf_desc_unused(tx_ring) >= size)) |
| 4157 |
return 0; |
| 4158 |
return __ixgbevf_maybe_stop_tx(tx_ring, size); |
| 4159 |
} |
| 4160 |
|
| 4161 |
static int ixgbevf_xmit_frame_ring(struct sk_buff *skb, |
| 4162 |
struct ixgbevf_ring *tx_ring) |
| 4163 |
{ |
| 4164 |
struct ixgbevf_tx_buffer *first; |
| 4165 |
int tso; |
| 4166 |
u32 tx_flags = 0; |
| 4167 |
u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
| 4168 |
struct ixgbevf_ipsec_tx_data ipsec_tx = { 0 }; |
| 4169 |
#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 4170 |
unsigned short f; |
| 4171 |
#endif |
| 4172 |
u8 hdr_len = 0; |
| 4173 |
u8 *dst_mac = skb_header_pointer(skb, 0, 0, NULL); |
| 4174 |
|
| 4175 |
if (!dst_mac || is_link_local_ether_addr(dst_mac)) { |
| 4176 |
dev_kfree_skb_any(skb); |
| 4177 |
return NETDEV_TX_OK; |
| 4178 |
} |
| 4179 |
|
| 4180 |
/* need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
| 4181 |
* + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
| 4182 |
* + 2 desc gap to keep tail from touching head, |
| 4183 |
* + 1 desc for context descriptor, |
| 4184 |
* otherwise try next time |
| 4185 |
*/ |
| 4186 |
#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 4187 |
for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) { |
| 4188 |
skb_frag_t *frag = &skb_shinfo(skb)->frags[f]; |
| 4189 |
|
| 4190 |
count += TXD_USE_COUNT(skb_frag_size(frag)); |
| 4191 |
} |
| 4192 |
#else |
| 4193 |
count += skb_shinfo(skb)->nr_frags; |
| 4194 |
#endif |
| 4195 |
if (ixgbevf_maybe_stop_tx(tx_ring, count + 3)) { |
| 4196 |
tx_ring->tx_stats.tx_busy++; |
| 4197 |
return NETDEV_TX_BUSY; |
| 4198 |
} |
| 4199 |
|
| 4200 |
/* record the location of the first descriptor for this packet */ |
| 4201 |
first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; |
| 4202 |
first->skb = skb; |
| 4203 |
first->bytecount = skb->len; |
| 4204 |
first->gso_segs = 1; |
| 4205 |
|
| 4206 |
if (skb_vlan_tag_present(skb)) { |
| 4207 |
tx_flags |= skb_vlan_tag_get(skb); |
| 4208 |
tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 4209 |
tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 4210 |
} |
| 4211 |
|
| 4212 |
/* record initial flags and protocol */ |
| 4213 |
first->tx_flags = tx_flags; |
| 4214 |
first->protocol = vlan_get_protocol(skb); |
| 4215 |
|
| 4216 |
#ifdef CONFIG_IXGBEVF_IPSEC |
| 4217 |
if (xfrm_offload(skb) && !ixgbevf_ipsec_tx(tx_ring, first, &ipsec_tx)) |
| 4218 |
goto out_drop; |
| 4219 |
#endif |
| 4220 |
tso = ixgbevf_tso(tx_ring, first, &hdr_len, &ipsec_tx); |
| 4221 |
if (tso < 0) |
| 4222 |
goto out_drop; |
| 4223 |
else if (!tso) |
| 4224 |
ixgbevf_tx_csum(tx_ring, first, &ipsec_tx); |
| 4225 |
|
| 4226 |
ixgbevf_tx_map(tx_ring, first, hdr_len); |
| 4227 |
|
| 4228 |
ixgbevf_maybe_stop_tx(tx_ring, DESC_NEEDED); |
| 4229 |
|
| 4230 |
return NETDEV_TX_OK; |
| 4231 |
|
| 4232 |
out_drop: |
| 4233 |
dev_kfree_skb_any(first->skb); |
| 4234 |
first->skb = NULL; |
| 4235 |
|
| 4236 |
return NETDEV_TX_OK; |
| 4237 |
} |
| 4238 |
|
| 4239 |
static netdev_tx_t ixgbevf_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 4240 |
{ |
| 4241 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 4242 |
struct ixgbevf_ring *tx_ring; |
| 4243 |
|
| 4244 |
if (skb->len <= 0) { |
| 4245 |
dev_kfree_skb_any(skb); |
| 4246 |
return NETDEV_TX_OK; |
| 4247 |
} |
| 4248 |
|
| 4249 |
/* The minimum packet size for olinfo paylen is 17 so pad the skb |
| 4250 |
* in order to meet this minimum size requirement. |
| 4251 |
*/ |
| 4252 |
if (skb->len < 17) { |
| 4253 |
if (skb_padto(skb, 17)) |
| 4254 |
return NETDEV_TX_OK; |
| 4255 |
skb->len = 17; |
| 4256 |
} |
| 4257 |
|
| 4258 |
tx_ring = adapter->tx_ring[skb->queue_mapping]; |
| 4259 |
return ixgbevf_xmit_frame_ring(skb, tx_ring); |
| 4260 |
} |
| 4261 |
|
| 4262 |
/** |
| 4263 |
* ixgbevf_set_mac - Change the Ethernet Address of the NIC |
| 4264 |
* @netdev: network interface device structure |
| 4265 |
* @p: pointer to an address structure |
| 4266 |
* |
| 4267 |
* Returns 0 on success, negative on failure |
| 4268 |
**/ |
| 4269 |
static int ixgbevf_set_mac(struct net_device *netdev, void *p) |
| 4270 |
{ |
| 4271 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 4272 |
struct ixgbe_hw *hw = &adapter->hw; |
| 4273 |
struct sockaddr *addr = p; |
| 4274 |
int err; |
| 4275 |
|
| 4276 |
if (!is_valid_ether_addr(addr->sa_data)) |
| 4277 |
return -EADDRNOTAVAIL; |
| 4278 |
|
| 4279 |
spin_lock_bh(&adapter->mbx_lock); |
| 4280 |
|
| 4281 |
err = hw->mac.ops.set_rar(hw, 0, addr->sa_data, 0); |
| 4282 |
|
| 4283 |
spin_unlock_bh(&adapter->mbx_lock); |
| 4284 |
|
| 4285 |
if (err) |
| 4286 |
return -EPERM; |
| 4287 |
|
| 4288 |
ether_addr_copy(hw->mac.addr, addr->sa_data); |
| 4289 |
ether_addr_copy(hw->mac.perm_addr, addr->sa_data); |
| 4290 |
eth_hw_addr_set(netdev, addr->sa_data); |
| 4291 |
|
| 4292 |
return 0; |
| 4293 |
} |
| 4294 |
|
| 4295 |
/** |
| 4296 |
* ixgbevf_change_mtu - Change the Maximum Transfer Unit |
| 4297 |
* @netdev: network interface device structure |
| 4298 |
* @new_mtu: new value for maximum frame size |
| 4299 |
* |
| 4300 |
* Returns 0 on success, negative on failure |
| 4301 |
**/ |
| 4302 |
static int ixgbevf_change_mtu(struct net_device *netdev, int new_mtu) |
| 4303 |
{ |
| 4304 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 4305 |
struct ixgbe_hw *hw = &adapter->hw; |
| 4306 |
int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4307 |
int ret; |
| 4308 |
|
| 4309 |
/* prevent MTU being changed to a size unsupported by XDP */ |
| 4310 |
if (adapter->xdp_prog) { |
| 4311 |
dev_warn(&adapter->pdev->dev, "MTU cannot be changed while XDP program is loaded\n"); |
| 4312 |
return -EPERM; |
| 4313 |
} |
| 4314 |
|
| 4315 |
spin_lock_bh(&adapter->mbx_lock); |
| 4316 |
/* notify the PF of our intent to use this size of frame */ |
| 4317 |
ret = hw->mac.ops.set_rlpml(hw, max_frame); |
| 4318 |
spin_unlock_bh(&adapter->mbx_lock); |
| 4319 |
if (ret) |
| 4320 |
return -EINVAL; |
| 4321 |
|
| 4322 |
hw_dbg(hw, "changing MTU from %d to %d\n", |
| 4323 |
netdev->mtu, new_mtu); |
| 4324 |
|
| 4325 |
/* must set new MTU before calling down or up */ |
| 4326 |
WRITE_ONCE(netdev->mtu, new_mtu); |
| 4327 |
|
| 4328 |
if (netif_running(netdev)) |
| 4329 |
ixgbevf_reinit_locked(adapter); |
| 4330 |
|
| 4331 |
return 0; |
| 4332 |
} |
| 4333 |
|
| 4334 |
static int ixgbevf_suspend(struct device *dev_d) |
| 4335 |
{ |
| 4336 |
struct net_device *netdev = dev_get_drvdata(dev_d); |
| 4337 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 4338 |
|
| 4339 |
rtnl_lock(); |
| 4340 |
netif_device_detach(netdev); |
| 4341 |
|
| 4342 |
if (netif_running(netdev)) |
| 4343 |
ixgbevf_close_suspend(adapter); |
| 4344 |
|
| 4345 |
ixgbevf_clear_interrupt_scheme(adapter); |
| 4346 |
rtnl_unlock(); |
| 4347 |
|
| 4348 |
return 0; |
| 4349 |
} |
| 4350 |
|
| 4351 |
static int ixgbevf_resume(struct device *dev_d) |
| 4352 |
{ |
| 4353 |
struct pci_dev *pdev = to_pci_dev(dev_d); |
| 4354 |
struct net_device *netdev = pci_get_drvdata(pdev); |
| 4355 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 4356 |
int err; |
| 4357 |
|
| 4358 |
adapter->hw.hw_addr = adapter->io_addr; |
| 4359 |
smp_mb__before_atomic(); |
| 4360 |
clear_bit(__IXGBEVF_DISABLED, &adapter->state); |
| 4361 |
pci_set_master(pdev); |
| 4362 |
|
| 4363 |
ixgbevf_reset(adapter); |
| 4364 |
|
| 4365 |
rtnl_lock(); |
| 4366 |
err = ixgbevf_init_interrupt_scheme(adapter); |
| 4367 |
if (!err && netif_running(netdev)) |
| 4368 |
err = ixgbevf_open(netdev); |
| 4369 |
rtnl_unlock(); |
| 4370 |
if (err) |
| 4371 |
return err; |
| 4372 |
|
| 4373 |
netif_device_attach(netdev); |
| 4374 |
|
| 4375 |
return err; |
| 4376 |
} |
| 4377 |
|
| 4378 |
static void ixgbevf_shutdown(struct pci_dev *pdev) |
| 4379 |
{ |
| 4380 |
ixgbevf_suspend(&pdev->dev); |
| 4381 |
} |
| 4382 |
|
| 4383 |
static void ixgbevf_get_tx_ring_stats(struct rtnl_link_stats64 *stats, |
| 4384 |
const struct ixgbevf_ring *ring) |
| 4385 |
{ |
| 4386 |
u64 bytes, packets; |
| 4387 |
unsigned int start; |
| 4388 |
|
| 4389 |
if (ring) { |
| 4390 |
do { |
| 4391 |
start = u64_stats_fetch_begin(&ring->syncp); |
| 4392 |
bytes = ring->stats.bytes; |
| 4393 |
packets = ring->stats.packets; |
| 4394 |
} while (u64_stats_fetch_retry(&ring->syncp, start)); |
| 4395 |
stats->tx_bytes += bytes; |
| 4396 |
stats->tx_packets += packets; |
| 4397 |
} |
| 4398 |
} |
| 4399 |
|
| 4400 |
static void ixgbevf_get_stats(struct net_device *netdev, |
| 4401 |
struct rtnl_link_stats64 *stats) |
| 4402 |
{ |
| 4403 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 4404 |
unsigned int start; |
| 4405 |
u64 bytes, packets; |
| 4406 |
const struct ixgbevf_ring *ring; |
| 4407 |
int i; |
| 4408 |
|
| 4409 |
ixgbevf_update_stats(adapter); |
| 4410 |
|
| 4411 |
stats->multicast = adapter->stats.vfmprc - adapter->stats.base_vfmprc; |
| 4412 |
|
| 4413 |
rcu_read_lock(); |
| 4414 |
for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4415 |
ring = adapter->rx_ring[i]; |
| 4416 |
do { |
| 4417 |
start = u64_stats_fetch_begin(&ring->syncp); |
| 4418 |
bytes = ring->stats.bytes; |
| 4419 |
packets = ring->stats.packets; |
| 4420 |
} while (u64_stats_fetch_retry(&ring->syncp, start)); |
| 4421 |
stats->rx_bytes += bytes; |
| 4422 |
stats->rx_packets += packets; |
| 4423 |
} |
| 4424 |
|
| 4425 |
for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4426 |
ring = adapter->tx_ring[i]; |
| 4427 |
ixgbevf_get_tx_ring_stats(stats, ring); |
| 4428 |
} |
| 4429 |
|
| 4430 |
for (i = 0; i < adapter->num_xdp_queues; i++) { |
| 4431 |
ring = adapter->xdp_ring[i]; |
| 4432 |
ixgbevf_get_tx_ring_stats(stats, ring); |
| 4433 |
} |
| 4434 |
rcu_read_unlock(); |
| 4435 |
} |
| 4436 |
|
| 4437 |
#define IXGBEVF_MAX_MAC_HDR_LEN 127 |
| 4438 |
#define IXGBEVF_MAX_NETWORK_HDR_LEN 511 |
| 4439 |
|
| 4440 |
static netdev_features_t |
| 4441 |
ixgbevf_features_check(struct sk_buff *skb, struct net_device *dev, |
| 4442 |
netdev_features_t features) |
| 4443 |
{ |
| 4444 |
unsigned int network_hdr_len, mac_hdr_len; |
| 4445 |
|
| 4446 |
/* Make certain the headers can be described by a context descriptor */ |
| 4447 |
mac_hdr_len = skb_network_offset(skb); |
| 4448 |
if (unlikely(mac_hdr_len > IXGBEVF_MAX_MAC_HDR_LEN)) |
| 4449 |
return features & ~(NETIF_F_HW_CSUM | |
| 4450 |
NETIF_F_SCTP_CRC | |
| 4451 |
NETIF_F_HW_VLAN_CTAG_TX | |
| 4452 |
NETIF_F_TSO | |
| 4453 |
NETIF_F_TSO6); |
| 4454 |
|
| 4455 |
network_hdr_len = skb_checksum_start(skb) - skb_network_header(skb); |
| 4456 |
if (unlikely(network_hdr_len > IXGBEVF_MAX_NETWORK_HDR_LEN)) |
| 4457 |
return features & ~(NETIF_F_HW_CSUM | |
| 4458 |
NETIF_F_SCTP_CRC | |
| 4459 |
NETIF_F_TSO | |
| 4460 |
NETIF_F_TSO6); |
| 4461 |
|
| 4462 |
/* We can only support IPV4 TSO in tunnels if we can mangle the |
| 4463 |
* inner IP ID field, so strip TSO if MANGLEID is not supported. |
| 4464 |
*/ |
| 4465 |
if (skb->encapsulation && !(features & NETIF_F_TSO_MANGLEID)) |
| 4466 |
features &= ~NETIF_F_TSO; |
| 4467 |
|
| 4468 |
return features; |
| 4469 |
} |
| 4470 |
|
| 4471 |
static int ixgbevf_xdp_setup(struct net_device *dev, struct bpf_prog *prog) |
| 4472 |
{ |
| 4473 |
int i, frame_size = dev->mtu + ETH_HLEN + ETH_FCS_LEN + VLAN_HLEN; |
| 4474 |
struct ixgbevf_adapter *adapter = netdev_priv(dev); |
| 4475 |
struct bpf_prog *old_prog; |
| 4476 |
|
| 4477 |
/* verify ixgbevf ring attributes are sufficient for XDP */ |
| 4478 |
for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4479 |
struct ixgbevf_ring *ring = adapter->rx_ring[i]; |
| 4480 |
|
| 4481 |
if (frame_size > ixgbevf_rx_bufsz(ring)) |
| 4482 |
return -EINVAL; |
| 4483 |
} |
| 4484 |
|
| 4485 |
old_prog = xchg(&adapter->xdp_prog, prog); |
| 4486 |
|
| 4487 |
/* If transitioning XDP modes reconfigure rings */ |
| 4488 |
if (!!prog != !!old_prog) { |
| 4489 |
/* Hardware has to reinitialize queues and interrupts to |
| 4490 |
* match packet buffer alignment. Unfortunately, the |
| 4491 |
* hardware is not flexible enough to do this dynamically. |
| 4492 |
*/ |
| 4493 |
if (netif_running(dev)) |
| 4494 |
ixgbevf_close(dev); |
| 4495 |
|
| 4496 |
ixgbevf_clear_interrupt_scheme(adapter); |
| 4497 |
ixgbevf_init_interrupt_scheme(adapter); |
| 4498 |
|
| 4499 |
if (netif_running(dev)) |
| 4500 |
ixgbevf_open(dev); |
| 4501 |
} else { |
| 4502 |
for (i = 0; i < adapter->num_rx_queues; i++) |
| 4503 |
xchg(&adapter->rx_ring[i]->xdp_prog, adapter->xdp_prog); |
| 4504 |
} |
| 4505 |
|
| 4506 |
if (old_prog) |
| 4507 |
bpf_prog_put(old_prog); |
| 4508 |
|
| 4509 |
return 0; |
| 4510 |
} |
| 4511 |
|
| 4512 |
static int ixgbevf_xdp(struct net_device *dev, struct netdev_bpf *xdp) |
| 4513 |
{ |
| 4514 |
switch (xdp->command) { |
| 4515 |
case XDP_SETUP_PROG: |
| 4516 |
return ixgbevf_xdp_setup(dev, xdp->prog); |
| 4517 |
default: |
| 4518 |
return -EINVAL; |
| 4519 |
} |
| 4520 |
} |
| 4521 |
|
| 4522 |
static const struct net_device_ops ixgbevf_netdev_ops = { |
| 4523 |
.ndo_open = ixgbevf_open, |
| 4524 |
.ndo_stop = ixgbevf_close, |
| 4525 |
.ndo_start_xmit = ixgbevf_xmit_frame, |
| 4526 |
.ndo_set_rx_mode = ixgbevf_set_rx_mode, |
| 4527 |
.ndo_get_stats64 = ixgbevf_get_stats, |
| 4528 |
.ndo_validate_addr = eth_validate_addr, |
| 4529 |
.ndo_set_mac_address = ixgbevf_set_mac, |
| 4530 |
.ndo_change_mtu = ixgbevf_change_mtu, |
| 4531 |
.ndo_tx_timeout = ixgbevf_tx_timeout, |
| 4532 |
.ndo_vlan_rx_add_vid = ixgbevf_vlan_rx_add_vid, |
| 4533 |
.ndo_vlan_rx_kill_vid = ixgbevf_vlan_rx_kill_vid, |
| 4534 |
.ndo_features_check = ixgbevf_features_check, |
| 4535 |
.ndo_bpf = ixgbevf_xdp, |
| 4536 |
}; |
| 4537 |
|
| 4538 |
static void ixgbevf_assign_netdev_ops(struct net_device *dev) |
| 4539 |
{ |
| 4540 |
dev->netdev_ops = &ixgbevf_netdev_ops; |
| 4541 |
ixgbevf_set_ethtool_ops(dev); |
| 4542 |
dev->watchdog_timeo = 5 * HZ; |
| 4543 |
} |
| 4544 |
|
| 4545 |
/** |
| 4546 |
* ixgbevf_probe - Device Initialization Routine |
| 4547 |
* @pdev: PCI device information struct |
| 4548 |
* @ent: entry in ixgbevf_pci_tbl |
| 4549 |
* |
| 4550 |
* Returns 0 on success, negative on failure |
| 4551 |
* |
| 4552 |
* ixgbevf_probe initializes an adapter identified by a pci_dev structure. |
| 4553 |
* The OS initialization, configuring of the adapter private structure, |
| 4554 |
* and a hardware reset occur. |
| 4555 |
**/ |
| 4556 |
static int ixgbevf_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 4557 |
{ |
| 4558 |
struct net_device *netdev; |
| 4559 |
struct ixgbevf_adapter *adapter = NULL; |
| 4560 |
struct ixgbe_hw *hw = NULL; |
| 4561 |
const struct ixgbevf_info *ii = ixgbevf_info_tbl[ent->driver_data]; |
| 4562 |
bool disable_dev = false; |
| 4563 |
int err; |
| 4564 |
|
| 4565 |
err = pci_enable_device(pdev); |
| 4566 |
if (err) |
| 4567 |
return err; |
| 4568 |
|
| 4569 |
err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)); |
| 4570 |
if (err) { |
| 4571 |
dev_err(&pdev->dev, "No usable DMA configuration, aborting\n"); |
| 4572 |
goto err_dma; |
| 4573 |
} |
| 4574 |
|
| 4575 |
err = pci_request_regions(pdev, ixgbevf_driver_name); |
| 4576 |
if (err) { |
| 4577 |
dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err); |
| 4578 |
goto err_pci_reg; |
| 4579 |
} |
| 4580 |
|
| 4581 |
pci_set_master(pdev); |
| 4582 |
|
| 4583 |
netdev = alloc_etherdev_mq(sizeof(struct ixgbevf_adapter), |
| 4584 |
MAX_TX_QUEUES); |
| 4585 |
if (!netdev) { |
| 4586 |
err = -ENOMEM; |
| 4587 |
goto err_alloc_etherdev; |
| 4588 |
} |
| 4589 |
|
| 4590 |
SET_NETDEV_DEV(netdev, &pdev->dev); |
| 4591 |
|
| 4592 |
adapter = netdev_priv(netdev); |
| 4593 |
|
| 4594 |
adapter->netdev = netdev; |
| 4595 |
adapter->pdev = pdev; |
| 4596 |
hw = &adapter->hw; |
| 4597 |
hw->back = adapter; |
| 4598 |
adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
| 4599 |
|
| 4600 |
/* call save state here in standalone driver because it relies on |
| 4601 |
* adapter struct to exist, and needs to call netdev_priv |
| 4602 |
*/ |
| 4603 |
pci_save_state(pdev); |
| 4604 |
|
| 4605 |
hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 4606 |
pci_resource_len(pdev, 0)); |
| 4607 |
adapter->io_addr = hw->hw_addr; |
| 4608 |
if (!hw->hw_addr) { |
| 4609 |
err = -EIO; |
| 4610 |
goto err_ioremap; |
| 4611 |
} |
| 4612 |
|
| 4613 |
ixgbevf_assign_netdev_ops(netdev); |
| 4614 |
|
| 4615 |
/* Setup HW API */ |
| 4616 |
memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
| 4617 |
hw->mac.type = ii->mac; |
| 4618 |
|
| 4619 |
memcpy(&hw->mbx.ops, &ixgbevf_mbx_ops_legacy, |
| 4620 |
sizeof(struct ixgbe_mbx_operations)); |
| 4621 |
|
| 4622 |
/* setup the private structure */ |
| 4623 |
err = ixgbevf_sw_init(adapter); |
| 4624 |
if (err) |
| 4625 |
goto err_sw_init; |
| 4626 |
|
| 4627 |
/* The HW MAC address was set and/or determined in sw_init */ |
| 4628 |
if (!is_valid_ether_addr(netdev->dev_addr)) { |
| 4629 |
pr_err("invalid MAC address\n"); |
| 4630 |
err = -EIO; |
| 4631 |
goto err_sw_init; |
| 4632 |
} |
| 4633 |
|
| 4634 |
netdev->hw_features = NETIF_F_SG | |
| 4635 |
NETIF_F_TSO | |
| 4636 |
NETIF_F_TSO6 | |
| 4637 |
NETIF_F_RXCSUM | |
| 4638 |
NETIF_F_HW_CSUM | |
| 4639 |
NETIF_F_SCTP_CRC; |
| 4640 |
|
| 4641 |
#define IXGBEVF_GSO_PARTIAL_FEATURES (NETIF_F_GSO_GRE | \ |
| 4642 |
NETIF_F_GSO_GRE_CSUM | \ |
| 4643 |
NETIF_F_GSO_IPXIP4 | \ |
| 4644 |
NETIF_F_GSO_IPXIP6 | \ |
| 4645 |
NETIF_F_GSO_UDP_TUNNEL | \ |
| 4646 |
NETIF_F_GSO_UDP_TUNNEL_CSUM) |
| 4647 |
|
| 4648 |
netdev->gso_partial_features = IXGBEVF_GSO_PARTIAL_FEATURES; |
| 4649 |
netdev->hw_features |= NETIF_F_GSO_PARTIAL | |
| 4650 |
IXGBEVF_GSO_PARTIAL_FEATURES; |
| 4651 |
|
| 4652 |
netdev->features = netdev->hw_features | NETIF_F_HIGHDMA; |
| 4653 |
|
| 4654 |
netdev->vlan_features |= netdev->features | NETIF_F_TSO_MANGLEID; |
| 4655 |
netdev->mpls_features |= NETIF_F_SG | |
| 4656 |
NETIF_F_TSO | |
| 4657 |
NETIF_F_TSO6 | |
| 4658 |
NETIF_F_HW_CSUM; |
| 4659 |
netdev->mpls_features |= IXGBEVF_GSO_PARTIAL_FEATURES; |
| 4660 |
netdev->hw_enc_features |= netdev->vlan_features; |
| 4661 |
|
| 4662 |
/* set this bit last since it cannot be part of vlan_features */ |
| 4663 |
netdev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | |
| 4664 |
NETIF_F_HW_VLAN_CTAG_RX | |
| 4665 |
NETIF_F_HW_VLAN_CTAG_TX; |
| 4666 |
|
| 4667 |
netdev->priv_flags |= IFF_UNICAST_FLT; |
| 4668 |
netdev->xdp_features = NETDEV_XDP_ACT_BASIC; |
| 4669 |
|
| 4670 |
/* MTU range: 68 - 1504 or 9710 */ |
| 4671 |
netdev->min_mtu = ETH_MIN_MTU; |
| 4672 |
switch (adapter->hw.api_version) { |
| 4673 |
case ixgbe_mbox_api_11: |
| 4674 |
case ixgbe_mbox_api_12: |
| 4675 |
case ixgbe_mbox_api_13: |
| 4676 |
case ixgbe_mbox_api_14: |
| 4677 |
case ixgbe_mbox_api_15: |
| 4678 |
case ixgbe_mbox_api_16: |
| 4679 |
case ixgbe_mbox_api_17: |
| 4680 |
netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - |
| 4681 |
(ETH_HLEN + ETH_FCS_LEN); |
| 4682 |
break; |
| 4683 |
default: |
| 4684 |
if (adapter->hw.mac.type != ixgbe_mac_82599_vf) |
| 4685 |
netdev->max_mtu = IXGBE_MAX_JUMBO_FRAME_SIZE - |
| 4686 |
(ETH_HLEN + ETH_FCS_LEN); |
| 4687 |
else |
| 4688 |
netdev->max_mtu = ETH_DATA_LEN + ETH_FCS_LEN; |
| 4689 |
break; |
| 4690 |
} |
| 4691 |
|
| 4692 |
if (IXGBE_REMOVED(hw->hw_addr)) { |
| 4693 |
err = -EIO; |
| 4694 |
goto err_sw_init; |
| 4695 |
} |
| 4696 |
|
| 4697 |
timer_setup(&adapter->service_timer, ixgbevf_service_timer, 0); |
| 4698 |
|
| 4699 |
INIT_WORK(&adapter->service_task, ixgbevf_service_task); |
| 4700 |
set_bit(__IXGBEVF_SERVICE_INITED, &adapter->state); |
| 4701 |
clear_bit(__IXGBEVF_SERVICE_SCHED, &adapter->state); |
| 4702 |
|
| 4703 |
err = ixgbevf_init_interrupt_scheme(adapter); |
| 4704 |
if (err) |
| 4705 |
goto err_sw_init; |
| 4706 |
|
| 4707 |
strcpy(netdev->name, "eth%d"); |
| 4708 |
|
| 4709 |
err = register_netdev(netdev); |
| 4710 |
if (err) |
| 4711 |
goto err_register; |
| 4712 |
|
| 4713 |
pci_set_drvdata(pdev, netdev); |
| 4714 |
netif_carrier_off(netdev); |
| 4715 |
ixgbevf_init_ipsec_offload(adapter); |
| 4716 |
|
| 4717 |
ixgbevf_init_last_counter_stats(adapter); |
| 4718 |
|
| 4719 |
/* print the VF info */ |
| 4720 |
dev_info(&pdev->dev, "%pM\n", netdev->dev_addr); |
| 4721 |
dev_info(&pdev->dev, "MAC: %d\n", hw->mac.type); |
| 4722 |
|
| 4723 |
switch (hw->mac.type) { |
| 4724 |
case ixgbe_mac_X550_vf: |
| 4725 |
dev_info(&pdev->dev, "Intel(R) X550 Virtual Function\n"); |
| 4726 |
break; |
| 4727 |
case ixgbe_mac_X540_vf: |
| 4728 |
dev_info(&pdev->dev, "Intel(R) X540 Virtual Function\n"); |
| 4729 |
break; |
| 4730 |
case ixgbe_mac_e610_vf: |
| 4731 |
dev_info(&pdev->dev, "Intel(R) E610 Virtual Function\n"); |
| 4732 |
break; |
| 4733 |
case ixgbe_mac_82599_vf: |
| 4734 |
default: |
| 4735 |
dev_info(&pdev->dev, "Intel(R) 82599 Virtual Function\n"); |
| 4736 |
break; |
| 4737 |
} |
| 4738 |
|
| 4739 |
return 0; |
| 4740 |
|
| 4741 |
err_register: |
| 4742 |
ixgbevf_clear_interrupt_scheme(adapter); |
| 4743 |
err_sw_init: |
| 4744 |
ixgbevf_reset_interrupt_capability(adapter); |
| 4745 |
iounmap(adapter->io_addr); |
| 4746 |
kfree(adapter->rss_key); |
| 4747 |
err_ioremap: |
| 4748 |
disable_dev = !test_and_set_bit(__IXGBEVF_DISABLED, &adapter->state); |
| 4749 |
free_netdev(netdev); |
| 4750 |
err_alloc_etherdev: |
| 4751 |
pci_release_regions(pdev); |
| 4752 |
err_pci_reg: |
| 4753 |
err_dma: |
| 4754 |
if (!adapter || disable_dev) |
| 4755 |
pci_disable_device(pdev); |
| 4756 |
return err; |
| 4757 |
} |
| 4758 |
|
| 4759 |
/** |
| 4760 |
* ixgbevf_remove - Device Removal Routine |
| 4761 |
* @pdev: PCI device information struct |
| 4762 |
* |
| 4763 |
* ixgbevf_remove is called by the PCI subsystem to alert the driver |
| 4764 |
* that it should release a PCI device. The could be caused by a |
| 4765 |
* Hot-Plug event, or because the driver is going to be removed from |
| 4766 |
* memory. |
| 4767 |
**/ |
| 4768 |
static void ixgbevf_remove(struct pci_dev *pdev) |
| 4769 |
{ |
| 4770 |
struct net_device *netdev = pci_get_drvdata(pdev); |
| 4771 |
struct ixgbevf_adapter *adapter; |
| 4772 |
bool disable_dev; |
| 4773 |
|
| 4774 |
if (!netdev) |
| 4775 |
return; |
| 4776 |
|
| 4777 |
adapter = netdev_priv(netdev); |
| 4778 |
|
| 4779 |
set_bit(__IXGBEVF_REMOVING, &adapter->state); |
| 4780 |
cancel_work_sync(&adapter->service_task); |
| 4781 |
|
| 4782 |
if (netdev->reg_state == NETREG_REGISTERED) |
| 4783 |
unregister_netdev(netdev); |
| 4784 |
|
| 4785 |
ixgbevf_stop_ipsec_offload(adapter); |
| 4786 |
ixgbevf_clear_interrupt_scheme(adapter); |
| 4787 |
ixgbevf_reset_interrupt_capability(adapter); |
| 4788 |
|
| 4789 |
iounmap(adapter->io_addr); |
| 4790 |
pci_release_regions(pdev); |
| 4791 |
|
| 4792 |
hw_dbg(&adapter->hw, "Remove complete\n"); |
| 4793 |
|
| 4794 |
kfree(adapter->rss_key); |
| 4795 |
disable_dev = !test_and_set_bit(__IXGBEVF_DISABLED, &adapter->state); |
| 4796 |
free_netdev(netdev); |
| 4797 |
|
| 4798 |
if (disable_dev) |
| 4799 |
pci_disable_device(pdev); |
| 4800 |
} |
| 4801 |
|
| 4802 |
/** |
| 4803 |
* ixgbevf_io_error_detected - called when PCI error is detected |
| 4804 |
* @pdev: Pointer to PCI device |
| 4805 |
* @state: The current pci connection state |
| 4806 |
* |
| 4807 |
* This function is called after a PCI bus error affecting |
| 4808 |
* this device has been detected. |
| 4809 |
**/ |
| 4810 |
static pci_ers_result_t ixgbevf_io_error_detected(struct pci_dev *pdev, |
| 4811 |
pci_channel_state_t state) |
| 4812 |
{ |
| 4813 |
struct net_device *netdev = pci_get_drvdata(pdev); |
| 4814 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 4815 |
|
| 4816 |
if (!test_bit(__IXGBEVF_SERVICE_INITED, &adapter->state)) |
| 4817 |
return PCI_ERS_RESULT_DISCONNECT; |
| 4818 |
|
| 4819 |
rtnl_lock(); |
| 4820 |
netif_device_detach(netdev); |
| 4821 |
|
| 4822 |
if (netif_running(netdev)) |
| 4823 |
ixgbevf_close_suspend(adapter); |
| 4824 |
|
| 4825 |
if (state == pci_channel_io_perm_failure) { |
| 4826 |
rtnl_unlock(); |
| 4827 |
return PCI_ERS_RESULT_DISCONNECT; |
| 4828 |
} |
| 4829 |
|
| 4830 |
if (!test_and_set_bit(__IXGBEVF_DISABLED, &adapter->state)) |
| 4831 |
pci_disable_device(pdev); |
| 4832 |
rtnl_unlock(); |
| 4833 |
|
| 4834 |
/* Request a slot reset. */ |
| 4835 |
return PCI_ERS_RESULT_NEED_RESET; |
| 4836 |
} |
| 4837 |
|
| 4838 |
/** |
| 4839 |
* ixgbevf_io_slot_reset - called after the pci bus has been reset. |
| 4840 |
* @pdev: Pointer to PCI device |
| 4841 |
* |
| 4842 |
* Restart the card from scratch, as if from a cold-boot. Implementation |
| 4843 |
* resembles the first-half of the ixgbevf_resume routine. |
| 4844 |
**/ |
| 4845 |
static pci_ers_result_t ixgbevf_io_slot_reset(struct pci_dev *pdev) |
| 4846 |
{ |
| 4847 |
struct net_device *netdev = pci_get_drvdata(pdev); |
| 4848 |
struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 4849 |
|
| 4850 |
if (pci_enable_device_mem(pdev)) { |
| 4851 |
dev_err(&pdev->dev, |
| 4852 |
"Cannot re-enable PCI device after reset.\n"); |
| 4853 |
return PCI_ERS_RESULT_DISCONNECT; |
| 4854 |
} |
| 4855 |
|
| 4856 |
adapter->hw.hw_addr = adapter->io_addr; |
| 4857 |
smp_mb__before_atomic(); |
| 4858 |
clear_bit(__IXGBEVF_DISABLED, &adapter->state); |
| 4859 |
pci_set_master(pdev); |
| 4860 |
|
| 4861 |
ixgbevf_reset(adapter); |
| 4862 |
|
| 4863 |
return PCI_ERS_RESULT_RECOVERED; |
| 4864 |
} |
| 4865 |
|
| 4866 |
/** |
| 4867 |
* ixgbevf_io_resume - called when traffic can start flowing again. |
| 4868 |
* @pdev: Pointer to PCI device |
| 4869 |
* |
| 4870 |
* This callback is called when the error recovery driver tells us that |
| 4871 |
* its OK to resume normal operation. Implementation resembles the |
| 4872 |
* second-half of the ixgbevf_resume routine. |
| 4873 |
**/ |
| 4874 |
static void ixgbevf_io_resume(struct pci_dev *pdev) |
| 4875 |
{ |
| 4876 |
struct net_device *netdev = pci_get_drvdata(pdev); |
| 4877 |
|
| 4878 |
rtnl_lock(); |
| 4879 |
if (netif_running(netdev)) |
| 4880 |
ixgbevf_open(netdev); |
| 4881 |
|
| 4882 |
netif_device_attach(netdev); |
| 4883 |
rtnl_unlock(); |
| 4884 |
} |
| 4885 |
|
| 4886 |
/* PCI Error Recovery (ERS) */ |
| 4887 |
static const struct pci_error_handlers ixgbevf_err_handler = { |
| 4888 |
.error_detected = ixgbevf_io_error_detected, |
| 4889 |
.slot_reset = ixgbevf_io_slot_reset, |
| 4890 |
.resume = ixgbevf_io_resume, |
| 4891 |
}; |
| 4892 |
|
| 4893 |
static DEFINE_SIMPLE_DEV_PM_OPS(ixgbevf_pm_ops, ixgbevf_suspend, ixgbevf_resume); |
| 4894 |
|
| 4895 |
static struct pci_driver ixgbevf_driver = { |
| 4896 |
.name = ixgbevf_driver_name, |
| 4897 |
.id_table = ixgbevf_pci_tbl, |
| 4898 |
.probe = ixgbevf_probe, |
| 4899 |
.remove = ixgbevf_remove, |
| 4900 |
|
| 4901 |
/* Power Management Hooks */ |
| 4902 |
.driver.pm = pm_sleep_ptr(&ixgbevf_pm_ops), |
| 4903 |
|
| 4904 |
.shutdown = ixgbevf_shutdown, |
| 4905 |
.err_handler = &ixgbevf_err_handler |
| 4906 |
}; |
| 4907 |
|
| 4908 |
/** |
| 4909 |
* ixgbevf_init_module - Driver Registration Routine |
| 4910 |
* |
| 4911 |
* ixgbevf_init_module is the first routine called when the driver is |
| 4912 |
* loaded. All it does is register with the PCI subsystem. |
| 4913 |
**/ |
| 4914 |
static int __init ixgbevf_init_module(void) |
| 4915 |
{ |
| 4916 |
int err; |
| 4917 |
|
| 4918 |
pr_info("%s\n", ixgbevf_driver_string); |
| 4919 |
pr_info("%s\n", ixgbevf_copyright); |
| 4920 |
ixgbevf_wq = create_singlethread_workqueue(ixgbevf_driver_name); |
| 4921 |
if (!ixgbevf_wq) { |
| 4922 |
pr_err("%s: Failed to create workqueue\n", ixgbevf_driver_name); |
| 4923 |
return -ENOMEM; |
| 4924 |
} |
| 4925 |
|
| 4926 |
err = pci_register_driver(&ixgbevf_driver); |
| 4927 |
if (err) { |
| 4928 |
destroy_workqueue(ixgbevf_wq); |
| 4929 |
return err; |
| 4930 |
} |
| 4931 |
|
| 4932 |
return 0; |
| 4933 |
} |
| 4934 |
|
| 4935 |
module_init(ixgbevf_init_module); |
| 4936 |
|
| 4937 |
/** |
| 4938 |
* ixgbevf_exit_module - Driver Exit Cleanup Routine |
| 4939 |
* |
| 4940 |
* ixgbevf_exit_module is called just before the driver is removed |
| 4941 |
* from memory. |
| 4942 |
**/ |
| 4943 |
static void __exit ixgbevf_exit_module(void) |
| 4944 |
{ |
| 4945 |
pci_unregister_driver(&ixgbevf_driver); |
| 4946 |
if (ixgbevf_wq) { |
| 4947 |
destroy_workqueue(ixgbevf_wq); |
| 4948 |
ixgbevf_wq = NULL; |
| 4949 |
} |
| 4950 |
} |
| 4951 |
|
| 4952 |
#ifdef DEBUG |
| 4953 |
/** |
| 4954 |
* ixgbevf_get_hw_dev_name - return device name string |
| 4955 |
* used by hardware layer to print debugging information |
| 4956 |
* @hw: pointer to private hardware struct |
| 4957 |
**/ |
| 4958 |
char *ixgbevf_get_hw_dev_name(struct ixgbe_hw *hw) |
| 4959 |
{ |
| 4960 |
struct ixgbevf_adapter *adapter = hw->back; |
| 4961 |
|
| 4962 |
return adapter->netdev->name; |
| 4963 |
} |
| 4964 |
|
| 4965 |
#endif |
| 4966 |
module_exit(ixgbevf_exit_module); |
| 4967 |
|
| 4968 |
/* ixgbevf_main.c */ |