Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 82599 Virtual Function driver |
Greg Rose | 5c47a2b | 2012-01-06 02:53:30 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2012 Intel Corporation. |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
| 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | |
| 29 | /****************************************************************************** |
| 30 | Copyright (c)2006 - 2007 Myricom, Inc. for some LRO specific code |
| 31 | ******************************************************************************/ |
Jeff Kirsher | dbd9636 | 2011-10-21 19:38:18 +0000 | [diff] [blame] | 32 | |
| 33 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 34 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 35 | #include <linux/types.h> |
Jiri Pirko | dadcd65 | 2011-07-21 03:25:09 +0000 | [diff] [blame] | 36 | #include <linux/bitops.h> |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 37 | #include <linux/module.h> |
| 38 | #include <linux/pci.h> |
| 39 | #include <linux/netdevice.h> |
| 40 | #include <linux/vmalloc.h> |
| 41 | #include <linux/string.h> |
| 42 | #include <linux/in.h> |
| 43 | #include <linux/ip.h> |
| 44 | #include <linux/tcp.h> |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 45 | #include <linux/sctp.h> |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 46 | #include <linux/ipv6.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 47 | #include <linux/slab.h> |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 48 | #include <net/checksum.h> |
| 49 | #include <net/ip6_checksum.h> |
| 50 | #include <linux/ethtool.h> |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 51 | #include <linux/if.h> |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 52 | #include <linux/if_vlan.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 53 | #include <linux/prefetch.h> |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 54 | |
| 55 | #include "ixgbevf.h" |
| 56 | |
Stephen Hemminger | 3d8fe98 | 2012-01-18 22:13:34 +0000 | [diff] [blame] | 57 | const char ixgbevf_driver_name[] = "ixgbevf"; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 58 | static const char ixgbevf_driver_string[] = |
Greg Rose | 422e05d | 2011-03-12 02:01:29 +0000 | [diff] [blame] | 59 | "Intel(R) 10 Gigabit PCI Express Virtual Function Network Driver"; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 60 | |
Greg Rose | 9cd9130 | 2012-04-17 04:29:39 +0000 | [diff] [blame] | 61 | #define DRV_VERSION "2.6.0-k" |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 62 | const char ixgbevf_driver_version[] = DRV_VERSION; |
Greg Rose | 66c87bd | 2010-11-16 19:26:43 -0800 | [diff] [blame] | 63 | static char ixgbevf_copyright[] = |
Greg Rose | 5c47a2b | 2012-01-06 02:53:30 +0000 | [diff] [blame] | 64 | "Copyright (c) 2009 - 2012 Intel Corporation."; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 65 | |
| 66 | static const struct ixgbevf_info *ixgbevf_info_tbl[] = { |
Greg Rose | 2316aa2 | 2010-12-02 07:12:26 +0000 | [diff] [blame] | 67 | [board_82599_vf] = &ixgbevf_82599_vf_info, |
| 68 | [board_X540_vf] = &ixgbevf_X540_vf_info, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /* ixgbevf_pci_tbl - PCI Device ID Table |
| 72 | * |
| 73 | * Wildcard entries (PCI_ANY_ID) should come last |
| 74 | * Last entry must be all 0s |
| 75 | * |
| 76 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 77 | * Class, Class Mask, private data (not used) } |
| 78 | */ |
| 79 | static struct pci_device_id ixgbevf_pci_tbl[] = { |
| 80 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_VF), |
| 81 | board_82599_vf}, |
Greg Rose | 2316aa2 | 2010-12-02 07:12:26 +0000 | [diff] [blame] | 82 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540_VF), |
| 83 | board_X540_vf}, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 84 | |
| 85 | /* required last entry */ |
| 86 | {0, } |
| 87 | }; |
| 88 | MODULE_DEVICE_TABLE(pci, ixgbevf_pci_tbl); |
| 89 | |
| 90 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 91 | MODULE_DESCRIPTION("Intel(R) 82599 Virtual Function Driver"); |
| 92 | MODULE_LICENSE("GPL"); |
| 93 | MODULE_VERSION(DRV_VERSION); |
| 94 | |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 95 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV|NETIF_MSG_PROBE|NETIF_MSG_LINK) |
| 96 | static int debug = -1; |
| 97 | module_param(debug, int, 0); |
| 98 | MODULE_PARM_DESC(debug, "Debug level (0=none,...,16=all)"); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 99 | |
| 100 | /* forward decls */ |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 101 | static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 102 | |
| 103 | static inline void ixgbevf_release_rx_desc(struct ixgbe_hw *hw, |
| 104 | struct ixgbevf_ring *rx_ring, |
| 105 | u32 val) |
| 106 | { |
| 107 | /* |
| 108 | * Force memory writes to complete before letting h/w |
| 109 | * know there are new descriptors to fetch. (Only |
| 110 | * applicable for weak-ordered memory model archs, |
| 111 | * such as IA-64). |
| 112 | */ |
| 113 | wmb(); |
| 114 | IXGBE_WRITE_REG(hw, IXGBE_VFRDT(rx_ring->reg_idx), val); |
| 115 | } |
| 116 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 117 | /** |
Greg Rose | 65d676c | 2011-02-03 06:54:13 +0000 | [diff] [blame] | 118 | * ixgbevf_set_ivar - set IVAR registers - maps interrupt causes to vectors |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 119 | * @adapter: pointer to adapter struct |
| 120 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 121 | * @queue: queue to map the corresponding interrupt to |
| 122 | * @msix_vector: the vector to map to the corresponding queue |
| 123 | * |
| 124 | */ |
| 125 | static void ixgbevf_set_ivar(struct ixgbevf_adapter *adapter, s8 direction, |
| 126 | u8 queue, u8 msix_vector) |
| 127 | { |
| 128 | u32 ivar, index; |
| 129 | struct ixgbe_hw *hw = &adapter->hw; |
| 130 | if (direction == -1) { |
| 131 | /* other causes */ |
| 132 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 133 | ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR_MISC); |
| 134 | ivar &= ~0xFF; |
| 135 | ivar |= msix_vector; |
| 136 | IXGBE_WRITE_REG(hw, IXGBE_VTIVAR_MISC, ivar); |
| 137 | } else { |
| 138 | /* tx or rx causes */ |
| 139 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 140 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 141 | ivar = IXGBE_READ_REG(hw, IXGBE_VTIVAR(queue >> 1)); |
| 142 | ivar &= ~(0xFF << index); |
| 143 | ivar |= (msix_vector << index); |
| 144 | IXGBE_WRITE_REG(hw, IXGBE_VTIVAR(queue >> 1), ivar); |
| 145 | } |
| 146 | } |
| 147 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 148 | static void ixgbevf_unmap_and_free_tx_resource(struct ixgbevf_ring *tx_ring, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 149 | struct ixgbevf_tx_buffer |
| 150 | *tx_buffer_info) |
| 151 | { |
| 152 | if (tx_buffer_info->dma) { |
| 153 | if (tx_buffer_info->mapped_as_page) |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 154 | dma_unmap_page(tx_ring->dev, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 155 | tx_buffer_info->dma, |
| 156 | tx_buffer_info->length, |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 157 | DMA_TO_DEVICE); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 158 | else |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 159 | dma_unmap_single(tx_ring->dev, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 160 | tx_buffer_info->dma, |
| 161 | tx_buffer_info->length, |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 162 | DMA_TO_DEVICE); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 163 | tx_buffer_info->dma = 0; |
| 164 | } |
| 165 | if (tx_buffer_info->skb) { |
| 166 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 167 | tx_buffer_info->skb = NULL; |
| 168 | } |
| 169 | tx_buffer_info->time_stamp = 0; |
| 170 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 171 | } |
| 172 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 173 | #define IXGBE_MAX_TXD_PWR 14 |
| 174 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
| 175 | |
| 176 | /* Tx Descriptors needed, worst case */ |
Alexander Duyck | 3595990 | 2012-05-11 08:32:40 +0000 | [diff] [blame] | 177 | #define TXD_USE_COUNT(S) DIV_ROUND_UP((S), IXGBE_MAX_DATA_PER_TXD) |
| 178 | #define DESC_NEEDED (MAX_SKB_FRAGS + 4) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 179 | |
| 180 | static void ixgbevf_tx_timeout(struct net_device *netdev); |
| 181 | |
| 182 | /** |
| 183 | * ixgbevf_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 184 | * @q_vector: board private structure |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 185 | * @tx_ring: tx ring to clean |
| 186 | **/ |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 187 | static bool ixgbevf_clean_tx_irq(struct ixgbevf_q_vector *q_vector, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 188 | struct ixgbevf_ring *tx_ring) |
| 189 | { |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 190 | struct ixgbevf_adapter *adapter = q_vector->adapter; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 191 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 192 | struct ixgbevf_tx_buffer *tx_buffer_info; |
| 193 | unsigned int i, eop, count = 0; |
| 194 | unsigned int total_bytes = 0, total_packets = 0; |
| 195 | |
Alexander Duyck | 10cc1bd | 2012-07-16 23:44:48 +0000 | [diff] [blame] | 196 | if (test_bit(__IXGBEVF_DOWN, &adapter->state)) |
| 197 | return true; |
| 198 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 199 | i = tx_ring->next_to_clean; |
| 200 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
Alexander Duyck | 908421f | 2012-05-11 08:33:00 +0000 | [diff] [blame] | 201 | eop_desc = IXGBEVF_TX_DESC(tx_ring, eop); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 202 | |
| 203 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 204 | (count < tx_ring->count)) { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 205 | bool cleaned = false; |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 206 | rmb(); /* read buffer_info after eop_desc */ |
Greg Rose | 98b9e48 | 2011-06-03 03:53:24 +0000 | [diff] [blame] | 207 | /* eop could change between read and DD-check */ |
| 208 | if (unlikely(eop != tx_ring->tx_buffer_info[i].next_to_watch)) |
| 209 | goto cont_loop; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 210 | for ( ; !cleaned; count++) { |
| 211 | struct sk_buff *skb; |
Alexander Duyck | 908421f | 2012-05-11 08:33:00 +0000 | [diff] [blame] | 212 | tx_desc = IXGBEVF_TX_DESC(tx_ring, i); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 213 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 214 | cleaned = (i == eop); |
| 215 | skb = tx_buffer_info->skb; |
| 216 | |
| 217 | if (cleaned && skb) { |
| 218 | unsigned int segs, bytecount; |
| 219 | |
| 220 | /* gso_segs is currently only valid for tcp */ |
| 221 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 222 | /* multiply data chunks by size of headers */ |
| 223 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
| 224 | skb->len; |
| 225 | total_packets += segs; |
| 226 | total_bytes += bytecount; |
| 227 | } |
| 228 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 229 | ixgbevf_unmap_and_free_tx_resource(tx_ring, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 230 | tx_buffer_info); |
| 231 | |
| 232 | tx_desc->wb.status = 0; |
| 233 | |
| 234 | i++; |
| 235 | if (i == tx_ring->count) |
| 236 | i = 0; |
| 237 | } |
| 238 | |
Greg Rose | 98b9e48 | 2011-06-03 03:53:24 +0000 | [diff] [blame] | 239 | cont_loop: |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 240 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
Alexander Duyck | 908421f | 2012-05-11 08:33:00 +0000 | [diff] [blame] | 241 | eop_desc = IXGBEVF_TX_DESC(tx_ring, eop); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | tx_ring->next_to_clean = i; |
| 245 | |
| 246 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 247 | if (unlikely(count && netif_carrier_ok(tx_ring->netdev) && |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 248 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
| 249 | /* Make sure that anybody stopping the queue after this |
| 250 | * sees the new next_to_clean. |
| 251 | */ |
| 252 | smp_mb(); |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 253 | if (__netif_subqueue_stopped(tx_ring->netdev, |
| 254 | tx_ring->queue_index) && |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 255 | !test_bit(__IXGBEVF_DOWN, &adapter->state)) { |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 256 | netif_wake_subqueue(tx_ring->netdev, |
| 257 | tx_ring->queue_index); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 258 | ++adapter->restart_queue; |
| 259 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Eric Dumazet | 4197aa7 | 2011-06-22 05:01:35 +0000 | [diff] [blame] | 262 | u64_stats_update_begin(&tx_ring->syncp); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 263 | tx_ring->total_bytes += total_bytes; |
| 264 | tx_ring->total_packets += total_packets; |
Eric Dumazet | 4197aa7 | 2011-06-22 05:01:35 +0000 | [diff] [blame] | 265 | u64_stats_update_end(&tx_ring->syncp); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 266 | |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 267 | return count < tx_ring->count; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /** |
| 271 | * ixgbevf_receive_skb - Send a completed packet up the stack |
| 272 | * @q_vector: structure containing interrupt and ring information |
| 273 | * @skb: packet to send up |
| 274 | * @status: hardware indication of status of receive |
| 275 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 276 | * @rx_desc: rx descriptor |
| 277 | **/ |
| 278 | static void ixgbevf_receive_skb(struct ixgbevf_q_vector *q_vector, |
| 279 | struct sk_buff *skb, u8 status, |
| 280 | struct ixgbevf_ring *ring, |
| 281 | union ixgbe_adv_rx_desc *rx_desc) |
| 282 | { |
| 283 | struct ixgbevf_adapter *adapter = q_vector->adapter; |
| 284 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
Greg Rose | dd1ed3b | 2011-08-27 02:06:25 +0000 | [diff] [blame] | 285 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 286 | |
Pascal Bouchareine | 5d9a533 | 2012-06-14 02:18:18 +0000 | [diff] [blame] | 287 | if (is_vlan && test_bit(tag & VLAN_VID_MASK, adapter->active_vlans)) |
Jiri Pirko | dadcd65 | 2011-07-21 03:25:09 +0000 | [diff] [blame] | 288 | __vlan_hwaccel_put_tag(skb, tag); |
Jiri Pirko | dadcd65 | 2011-07-21 03:25:09 +0000 | [diff] [blame] | 289 | |
Alexander Duyck | 77d5dfc | 2012-05-11 08:32:19 +0000 | [diff] [blame] | 290 | napi_gro_receive(&q_vector->napi, skb); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | /** |
| 294 | * ixgbevf_rx_checksum - indicate in skb if hw indicated a good cksum |
| 295 | * @adapter: address of board private structure |
| 296 | * @status_err: hardware indication of status of receive |
| 297 | * @skb: skb currently being received and modified |
| 298 | **/ |
| 299 | static inline void ixgbevf_rx_checksum(struct ixgbevf_adapter *adapter, |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 300 | struct ixgbevf_ring *ring, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 301 | u32 status_err, struct sk_buff *skb) |
| 302 | { |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 303 | skb_checksum_none_assert(skb); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 304 | |
| 305 | /* Rx csum disabled */ |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 306 | if (!(ring->netdev->features & NETIF_F_RXCSUM)) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 307 | return; |
| 308 | |
| 309 | /* if IP and error */ |
| 310 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 311 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
| 312 | adapter->hw_csum_rx_error++; |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 317 | return; |
| 318 | |
| 319 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
| 320 | adapter->hw_csum_rx_error++; |
| 321 | return; |
| 322 | } |
| 323 | |
| 324 | /* It must be a TCP or UDP packet with a valid checksum */ |
| 325 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 326 | adapter->hw_csum_rx_good++; |
| 327 | } |
| 328 | |
| 329 | /** |
| 330 | * ixgbevf_alloc_rx_buffers - Replace used receive buffers; packet split |
| 331 | * @adapter: address of board private structure |
| 332 | **/ |
| 333 | static void ixgbevf_alloc_rx_buffers(struct ixgbevf_adapter *adapter, |
| 334 | struct ixgbevf_ring *rx_ring, |
| 335 | int cleaned_count) |
| 336 | { |
| 337 | struct pci_dev *pdev = adapter->pdev; |
| 338 | union ixgbe_adv_rx_desc *rx_desc; |
| 339 | struct ixgbevf_rx_buffer *bi; |
| 340 | struct sk_buff *skb; |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 341 | unsigned int i = rx_ring->next_to_use; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 342 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 343 | bi = &rx_ring->rx_buffer_info[i]; |
| 344 | |
| 345 | while (cleaned_count--) { |
Alexander Duyck | 908421f | 2012-05-11 08:33:00 +0000 | [diff] [blame] | 346 | rx_desc = IXGBEVF_RX_DESC(rx_ring, i); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 347 | skb = bi->skb; |
| 348 | if (!skb) { |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 349 | skb = netdev_alloc_skb_ip_align(rx_ring->netdev, |
| 350 | rx_ring->rx_buf_len); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 351 | if (!skb) { |
| 352 | adapter->alloc_rx_buff_failed++; |
| 353 | goto no_buffers; |
| 354 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 355 | bi->skb = skb; |
| 356 | } |
| 357 | if (!bi->dma) { |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 358 | bi->dma = dma_map_single(&pdev->dev, skb->data, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 359 | rx_ring->rx_buf_len, |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 360 | DMA_FROM_DEVICE); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 361 | } |
Alexander Duyck | 77d5dfc | 2012-05-11 08:32:19 +0000 | [diff] [blame] | 362 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 363 | |
| 364 | i++; |
| 365 | if (i == rx_ring->count) |
| 366 | i = 0; |
| 367 | bi = &rx_ring->rx_buffer_info[i]; |
| 368 | } |
| 369 | |
| 370 | no_buffers: |
| 371 | if (rx_ring->next_to_use != i) { |
| 372 | rx_ring->next_to_use = i; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 373 | |
| 374 | ixgbevf_release_rx_desc(&adapter->hw, rx_ring, i); |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | static inline void ixgbevf_irq_enable_queues(struct ixgbevf_adapter *adapter, |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 379 | u32 qmask) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 380 | { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 381 | struct ixgbe_hw *hw = &adapter->hw; |
| 382 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 383 | IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, qmask); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 384 | } |
| 385 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 386 | static bool ixgbevf_clean_rx_irq(struct ixgbevf_q_vector *q_vector, |
| 387 | struct ixgbevf_ring *rx_ring, |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 388 | int budget) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 389 | { |
| 390 | struct ixgbevf_adapter *adapter = q_vector->adapter; |
| 391 | struct pci_dev *pdev = adapter->pdev; |
| 392 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 393 | struct ixgbevf_rx_buffer *rx_buffer_info, *next_buffer; |
| 394 | struct sk_buff *skb; |
| 395 | unsigned int i; |
| 396 | u32 len, staterr; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 397 | int cleaned_count = 0; |
| 398 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
| 399 | |
| 400 | i = rx_ring->next_to_clean; |
Alexander Duyck | 908421f | 2012-05-11 08:33:00 +0000 | [diff] [blame] | 401 | rx_desc = IXGBEVF_RX_DESC(rx_ring, i); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 402 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 403 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 404 | |
| 405 | while (staterr & IXGBE_RXD_STAT_DD) { |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 406 | if (!budget) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 407 | break; |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 408 | budget--; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 409 | |
Jeff Kirsher | 2d0bb1c | 2010-08-08 16:02:31 +0000 | [diff] [blame] | 410 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Alexander Duyck | 77d5dfc | 2012-05-11 08:32:19 +0000 | [diff] [blame] | 411 | len = le16_to_cpu(rx_desc->wb.upper.length); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 412 | skb = rx_buffer_info->skb; |
| 413 | prefetch(skb->data - NET_IP_ALIGN); |
| 414 | rx_buffer_info->skb = NULL; |
| 415 | |
| 416 | if (rx_buffer_info->dma) { |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 417 | dma_unmap_single(&pdev->dev, rx_buffer_info->dma, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 418 | rx_ring->rx_buf_len, |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 419 | DMA_FROM_DEVICE); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 420 | rx_buffer_info->dma = 0; |
| 421 | skb_put(skb, len); |
| 422 | } |
| 423 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 424 | i++; |
| 425 | if (i == rx_ring->count) |
| 426 | i = 0; |
| 427 | |
Alexander Duyck | 908421f | 2012-05-11 08:33:00 +0000 | [diff] [blame] | 428 | next_rxd = IXGBEVF_RX_DESC(rx_ring, i); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 429 | prefetch(next_rxd); |
| 430 | cleaned_count++; |
| 431 | |
| 432 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 433 | |
| 434 | if (!(staterr & IXGBE_RXD_STAT_EOP)) { |
Alexander Duyck | 77d5dfc | 2012-05-11 08:32:19 +0000 | [diff] [blame] | 435 | skb->next = next_buffer->skb; |
| 436 | skb->next->prev = skb; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 437 | adapter->non_eop_descs++; |
| 438 | goto next_desc; |
| 439 | } |
| 440 | |
| 441 | /* ERR_MASK will only have valid bits if EOP set */ |
| 442 | if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) { |
| 443 | dev_kfree_skb_irq(skb); |
| 444 | goto next_desc; |
| 445 | } |
| 446 | |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 447 | ixgbevf_rx_checksum(adapter, rx_ring, staterr, skb); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 448 | |
| 449 | /* probably a little skewed due to removing CRC */ |
| 450 | total_rx_bytes += skb->len; |
| 451 | total_rx_packets++; |
| 452 | |
| 453 | /* |
| 454 | * Work around issue of some types of VM to VM loop back |
| 455 | * packets not getting split correctly |
| 456 | */ |
| 457 | if (staterr & IXGBE_RXD_STAT_LB) { |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 458 | u32 header_fixup_len = skb_headlen(skb); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 459 | if (header_fixup_len < 14) |
| 460 | skb_push(skb, header_fixup_len); |
| 461 | } |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 462 | skb->protocol = eth_type_trans(skb, rx_ring->netdev); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 463 | |
| 464 | ixgbevf_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 465 | |
| 466 | next_desc: |
| 467 | rx_desc->wb.upper.status_error = 0; |
| 468 | |
| 469 | /* return some buffers to hardware, one at a time is too slow */ |
| 470 | if (cleaned_count >= IXGBEVF_RX_BUFFER_WRITE) { |
| 471 | ixgbevf_alloc_rx_buffers(adapter, rx_ring, |
| 472 | cleaned_count); |
| 473 | cleaned_count = 0; |
| 474 | } |
| 475 | |
| 476 | /* use prefetched values */ |
| 477 | rx_desc = next_rxd; |
| 478 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 479 | |
| 480 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 481 | } |
| 482 | |
| 483 | rx_ring->next_to_clean = i; |
| 484 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 485 | |
| 486 | if (cleaned_count) |
| 487 | ixgbevf_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 488 | |
Eric Dumazet | 4197aa7 | 2011-06-22 05:01:35 +0000 | [diff] [blame] | 489 | u64_stats_update_begin(&rx_ring->syncp); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 490 | rx_ring->total_packets += total_rx_packets; |
| 491 | rx_ring->total_bytes += total_rx_bytes; |
Eric Dumazet | 4197aa7 | 2011-06-22 05:01:35 +0000 | [diff] [blame] | 492 | u64_stats_update_end(&rx_ring->syncp); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 493 | |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 494 | return !!budget; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | /** |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 498 | * ixgbevf_poll - NAPI polling calback |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 499 | * @napi: napi struct with our devices info in it |
| 500 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 501 | * |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 502 | * This function will clean more than one or more rings associated with a |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 503 | * q_vector. |
| 504 | **/ |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 505 | static int ixgbevf_poll(struct napi_struct *napi, int budget) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 506 | { |
| 507 | struct ixgbevf_q_vector *q_vector = |
| 508 | container_of(napi, struct ixgbevf_q_vector, napi); |
| 509 | struct ixgbevf_adapter *adapter = q_vector->adapter; |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 510 | struct ixgbevf_ring *ring; |
| 511 | int per_ring_budget; |
| 512 | bool clean_complete = true; |
| 513 | |
| 514 | ixgbevf_for_each_ring(ring, q_vector->tx) |
| 515 | clean_complete &= ixgbevf_clean_tx_irq(q_vector, ring); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 516 | |
| 517 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 518 | * the budget to go below 1 because we'll exit polling */ |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 519 | if (q_vector->rx.count > 1) |
| 520 | per_ring_budget = max(budget/q_vector->rx.count, 1); |
| 521 | else |
| 522 | per_ring_budget = budget; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 523 | |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 524 | ixgbevf_for_each_ring(ring, q_vector->rx) |
| 525 | clean_complete &= ixgbevf_clean_rx_irq(q_vector, ring, |
| 526 | per_ring_budget); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 527 | |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 528 | /* If all work not completed, return budget and keep polling */ |
| 529 | if (!clean_complete) |
| 530 | return budget; |
| 531 | /* all work done, exit the polling mode */ |
| 532 | napi_complete(napi); |
| 533 | if (adapter->rx_itr_setting & 1) |
| 534 | ixgbevf_set_itr(q_vector); |
| 535 | if (!test_bit(__IXGBEVF_DOWN, &adapter->state)) |
| 536 | ixgbevf_irq_enable_queues(adapter, |
| 537 | 1 << q_vector->v_idx); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 538 | |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 539 | return 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Greg Rose | ce42260 | 2012-05-22 02:17:49 +0000 | [diff] [blame] | 542 | /** |
| 543 | * ixgbevf_write_eitr - write VTEITR register in hardware specific way |
| 544 | * @q_vector: structure containing interrupt and ring information |
| 545 | */ |
| 546 | static void ixgbevf_write_eitr(struct ixgbevf_q_vector *q_vector) |
| 547 | { |
| 548 | struct ixgbevf_adapter *adapter = q_vector->adapter; |
| 549 | struct ixgbe_hw *hw = &adapter->hw; |
| 550 | int v_idx = q_vector->v_idx; |
| 551 | u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR; |
| 552 | |
| 553 | /* |
| 554 | * set the WDIS bit to not clear the timer bits and cause an |
| 555 | * immediate assertion of the interrupt |
| 556 | */ |
| 557 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 558 | |
| 559 | IXGBE_WRITE_REG(hw, IXGBE_VTEITR(v_idx), itr_reg); |
| 560 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 561 | |
| 562 | /** |
| 563 | * ixgbevf_configure_msix - Configure MSI-X hardware |
| 564 | * @adapter: board private structure |
| 565 | * |
| 566 | * ixgbevf_configure_msix sets up the hardware to properly generate MSI-X |
| 567 | * interrupts. |
| 568 | **/ |
| 569 | static void ixgbevf_configure_msix(struct ixgbevf_adapter *adapter) |
| 570 | { |
| 571 | struct ixgbevf_q_vector *q_vector; |
Alexander Duyck | 6b43c44 | 2012-05-11 08:32:45 +0000 | [diff] [blame] | 572 | int q_vectors, v_idx; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 573 | |
| 574 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 575 | adapter->eims_enable_mask = 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 576 | |
| 577 | /* |
| 578 | * Populate the IVAR table and set the ITR values to the |
| 579 | * corresponding register. |
| 580 | */ |
| 581 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 6b43c44 | 2012-05-11 08:32:45 +0000 | [diff] [blame] | 582 | struct ixgbevf_ring *ring; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 583 | q_vector = adapter->q_vector[v_idx]; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 584 | |
Alexander Duyck | 6b43c44 | 2012-05-11 08:32:45 +0000 | [diff] [blame] | 585 | ixgbevf_for_each_ring(ring, q_vector->rx) |
| 586 | ixgbevf_set_ivar(adapter, 0, ring->reg_idx, v_idx); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 587 | |
Alexander Duyck | 6b43c44 | 2012-05-11 08:32:45 +0000 | [diff] [blame] | 588 | ixgbevf_for_each_ring(ring, q_vector->tx) |
| 589 | ixgbevf_set_ivar(adapter, 1, ring->reg_idx, v_idx); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 590 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 591 | if (q_vector->tx.ring && !q_vector->rx.ring) { |
| 592 | /* tx only vector */ |
| 593 | if (adapter->tx_itr_setting == 1) |
| 594 | q_vector->itr = IXGBE_10K_ITR; |
| 595 | else |
| 596 | q_vector->itr = adapter->tx_itr_setting; |
| 597 | } else { |
| 598 | /* rx or rx/tx vector */ |
| 599 | if (adapter->rx_itr_setting == 1) |
| 600 | q_vector->itr = IXGBE_20K_ITR; |
| 601 | else |
| 602 | q_vector->itr = adapter->rx_itr_setting; |
| 603 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 604 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 605 | /* add q_vector eims value to global eims_enable_mask */ |
| 606 | adapter->eims_enable_mask |= 1 << v_idx; |
| 607 | |
| 608 | ixgbevf_write_eitr(q_vector); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | ixgbevf_set_ivar(adapter, -1, 1, v_idx); |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 612 | /* setup eims_other and add value to global eims_enable_mask */ |
| 613 | adapter->eims_other = 1 << v_idx; |
| 614 | adapter->eims_enable_mask |= adapter->eims_other; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | enum latency_range { |
| 618 | lowest_latency = 0, |
| 619 | low_latency = 1, |
| 620 | bulk_latency = 2, |
| 621 | latency_invalid = 255 |
| 622 | }; |
| 623 | |
| 624 | /** |
| 625 | * ixgbevf_update_itr - update the dynamic ITR value based on statistics |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 626 | * @q_vector: structure containing interrupt and ring information |
| 627 | * @ring_container: structure containing ring performance data |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 628 | * |
| 629 | * Stores a new ITR value based on packets and byte |
| 630 | * counts during the last interrupt. The advantage of per interrupt |
| 631 | * computation is faster updates and more accurate ITR for the current |
| 632 | * traffic pattern. Constants in this function were computed |
| 633 | * based on theoretical maximum wire speed and thresholds were set based |
| 634 | * on testing data as well as attempting to minimize response time |
| 635 | * while increasing bulk throughput. |
| 636 | **/ |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 637 | static void ixgbevf_update_itr(struct ixgbevf_q_vector *q_vector, |
| 638 | struct ixgbevf_ring_container *ring_container) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 639 | { |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 640 | int bytes = ring_container->total_bytes; |
| 641 | int packets = ring_container->total_packets; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 642 | u32 timepassed_us; |
| 643 | u64 bytes_perint; |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 644 | u8 itr_setting = ring_container->itr; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 645 | |
| 646 | if (packets == 0) |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 647 | return; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 648 | |
| 649 | /* simple throttlerate management |
| 650 | * 0-20MB/s lowest (100000 ints/s) |
| 651 | * 20-100MB/s low (20000 ints/s) |
| 652 | * 100-1249MB/s bulk (8000 ints/s) |
| 653 | */ |
| 654 | /* what was last interrupt timeslice? */ |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 655 | timepassed_us = q_vector->itr >> 2; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 656 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 657 | |
| 658 | switch (itr_setting) { |
| 659 | case lowest_latency: |
Alexander Duyck | e2c28ce | 2012-05-11 08:32:34 +0000 | [diff] [blame] | 660 | if (bytes_perint > 10) |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 661 | itr_setting = low_latency; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 662 | break; |
| 663 | case low_latency: |
Alexander Duyck | e2c28ce | 2012-05-11 08:32:34 +0000 | [diff] [blame] | 664 | if (bytes_perint > 20) |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 665 | itr_setting = bulk_latency; |
Alexander Duyck | e2c28ce | 2012-05-11 08:32:34 +0000 | [diff] [blame] | 666 | else if (bytes_perint <= 10) |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 667 | itr_setting = lowest_latency; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 668 | break; |
| 669 | case bulk_latency: |
Alexander Duyck | e2c28ce | 2012-05-11 08:32:34 +0000 | [diff] [blame] | 670 | if (bytes_perint <= 20) |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 671 | itr_setting = low_latency; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 672 | break; |
| 673 | } |
| 674 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 675 | /* clear work counters since we have the values we need */ |
| 676 | ring_container->total_bytes = 0; |
| 677 | ring_container->total_packets = 0; |
| 678 | |
| 679 | /* write updated itr to ring container */ |
| 680 | ring_container->itr = itr_setting; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 681 | } |
| 682 | |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 683 | static void ixgbevf_set_itr(struct ixgbevf_q_vector *q_vector) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 684 | { |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 685 | u32 new_itr = q_vector->itr; |
| 686 | u8 current_itr; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 687 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 688 | ixgbevf_update_itr(q_vector, &q_vector->tx); |
| 689 | ixgbevf_update_itr(q_vector, &q_vector->rx); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 690 | |
Alexander Duyck | 6b43c44 | 2012-05-11 08:32:45 +0000 | [diff] [blame] | 691 | current_itr = max(q_vector->rx.itr, q_vector->tx.itr); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 692 | |
| 693 | switch (current_itr) { |
| 694 | /* counts and packets in update_itr are dependent on these numbers */ |
| 695 | case lowest_latency: |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 696 | new_itr = IXGBE_100K_ITR; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 697 | break; |
| 698 | case low_latency: |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 699 | new_itr = IXGBE_20K_ITR; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 700 | break; |
| 701 | case bulk_latency: |
| 702 | default: |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 703 | new_itr = IXGBE_8K_ITR; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 704 | break; |
| 705 | } |
| 706 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 707 | if (new_itr != q_vector->itr) { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 708 | /* do an exponential smoothing */ |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 709 | new_itr = (10 * new_itr * q_vector->itr) / |
| 710 | ((9 * new_itr) + q_vector->itr); |
| 711 | |
| 712 | /* save the algorithm value here */ |
| 713 | q_vector->itr = new_itr; |
| 714 | |
| 715 | ixgbevf_write_eitr(q_vector); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 716 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | static irqreturn_t ixgbevf_msix_mbx(int irq, void *data) |
| 720 | { |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 721 | struct ixgbevf_adapter *adapter = data; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 722 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | a9ee25a | 2010-01-22 22:47:00 +0000 | [diff] [blame] | 723 | u32 msg; |
Greg Rose | 375b27c | 2012-01-18 22:13:31 +0000 | [diff] [blame] | 724 | bool got_ack = false; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 725 | |
Greg Rose | 375b27c | 2012-01-18 22:13:31 +0000 | [diff] [blame] | 726 | if (!hw->mbx.ops.check_for_ack(hw)) |
| 727 | got_ack = true; |
| 728 | |
| 729 | if (!hw->mbx.ops.check_for_msg(hw)) { |
| 730 | hw->mbx.ops.read(hw, &msg, 1); |
| 731 | |
| 732 | if ((msg & IXGBE_MBVFICR_VFREQ_MASK) == IXGBE_PF_CONTROL_MSG) |
| 733 | mod_timer(&adapter->watchdog_timer, |
| 734 | round_jiffies(jiffies + 1)); |
| 735 | |
| 736 | if (msg & IXGBE_VT_MSGTYPE_NACK) |
| 737 | pr_warn("Last Request of type %2.2x to PF Nacked\n", |
| 738 | msg & 0xFF); |
Greg Rose | 3a2c403 | 2012-02-01 01:28:15 +0000 | [diff] [blame] | 739 | /* |
| 740 | * Restore the PFSTS bit in case someone is polling for a |
| 741 | * return message from the PF |
| 742 | */ |
| 743 | hw->mbx.v2p_mailbox |= IXGBE_VFMAILBOX_PFSTS; |
Greg Rose | 0825959 | 2010-05-05 19:57:49 +0000 | [diff] [blame] | 744 | } |
| 745 | |
Greg Rose | 375b27c | 2012-01-18 22:13:31 +0000 | [diff] [blame] | 746 | /* |
| 747 | * checking for the ack clears the PFACK bit. Place |
| 748 | * it back in the v2p_mailbox cache so that anyone |
| 749 | * polling for an ack will not miss it |
| 750 | */ |
| 751 | if (got_ack) |
| 752 | hw->mbx.v2p_mailbox |= IXGBE_VFMAILBOX_PFACK; |
Greg Rose | 3a2c403 | 2012-02-01 01:28:15 +0000 | [diff] [blame] | 753 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 754 | IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, adapter->eims_other); |
| 755 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 756 | return IRQ_HANDLED; |
| 757 | } |
| 758 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 759 | |
| 760 | /** |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 761 | * ixgbevf_msix_clean_rings - single unshared vector rx clean (all queues) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 762 | * @irq: unused |
| 763 | * @data: pointer to our q_vector struct for this interrupt vector |
| 764 | **/ |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 765 | static irqreturn_t ixgbevf_msix_clean_rings(int irq, void *data) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 766 | { |
| 767 | struct ixgbevf_q_vector *q_vector = data; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 768 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 769 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 770 | if (q_vector->rx.ring || q_vector->tx.ring) |
| 771 | napi_schedule(&q_vector->napi); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 772 | |
| 773 | return IRQ_HANDLED; |
| 774 | } |
| 775 | |
| 776 | static inline void map_vector_to_rxq(struct ixgbevf_adapter *a, int v_idx, |
| 777 | int r_idx) |
| 778 | { |
| 779 | struct ixgbevf_q_vector *q_vector = a->q_vector[v_idx]; |
| 780 | |
Alexander Duyck | 6b43c44 | 2012-05-11 08:32:45 +0000 | [diff] [blame] | 781 | a->rx_ring[r_idx].next = q_vector->rx.ring; |
| 782 | q_vector->rx.ring = &a->rx_ring[r_idx]; |
| 783 | q_vector->rx.count++; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | static inline void map_vector_to_txq(struct ixgbevf_adapter *a, int v_idx, |
| 787 | int t_idx) |
| 788 | { |
| 789 | struct ixgbevf_q_vector *q_vector = a->q_vector[v_idx]; |
| 790 | |
Alexander Duyck | 6b43c44 | 2012-05-11 08:32:45 +0000 | [diff] [blame] | 791 | a->tx_ring[t_idx].next = q_vector->tx.ring; |
| 792 | q_vector->tx.ring = &a->tx_ring[t_idx]; |
| 793 | q_vector->tx.count++; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | /** |
| 797 | * ixgbevf_map_rings_to_vectors - Maps descriptor rings to vectors |
| 798 | * @adapter: board private structure to initialize |
| 799 | * |
| 800 | * This function maps descriptor rings to the queue-specific vectors |
| 801 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 802 | * one vector per ring/queue, but on a constrained vector budget, we |
| 803 | * group the rings as "efficiently" as possible. You would add new |
| 804 | * mapping configurations in here. |
| 805 | **/ |
| 806 | static int ixgbevf_map_rings_to_vectors(struct ixgbevf_adapter *adapter) |
| 807 | { |
| 808 | int q_vectors; |
| 809 | int v_start = 0; |
| 810 | int rxr_idx = 0, txr_idx = 0; |
| 811 | int rxr_remaining = adapter->num_rx_queues; |
| 812 | int txr_remaining = adapter->num_tx_queues; |
| 813 | int i, j; |
| 814 | int rqpv, tqpv; |
| 815 | int err = 0; |
| 816 | |
| 817 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 818 | |
| 819 | /* |
| 820 | * The ideal configuration... |
| 821 | * We have enough vectors to map one per queue. |
| 822 | */ |
| 823 | if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 824 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 825 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 826 | |
| 827 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 828 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 829 | goto out; |
| 830 | } |
| 831 | |
| 832 | /* |
| 833 | * If we don't have enough vectors for a 1-to-1 |
| 834 | * mapping, we'll have to group them so there are |
| 835 | * multiple queues per vector. |
| 836 | */ |
| 837 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 838 | for (i = v_start; i < q_vectors; i++) { |
| 839 | rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i); |
| 840 | for (j = 0; j < rqpv; j++) { |
| 841 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 842 | rxr_idx++; |
| 843 | rxr_remaining--; |
| 844 | } |
| 845 | } |
| 846 | for (i = v_start; i < q_vectors; i++) { |
| 847 | tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i); |
| 848 | for (j = 0; j < tqpv; j++) { |
| 849 | map_vector_to_txq(adapter, i, txr_idx); |
| 850 | txr_idx++; |
| 851 | txr_remaining--; |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | out: |
| 856 | return err; |
| 857 | } |
| 858 | |
| 859 | /** |
| 860 | * ixgbevf_request_msix_irqs - Initialize MSI-X interrupts |
| 861 | * @adapter: board private structure |
| 862 | * |
| 863 | * ixgbevf_request_msix_irqs allocates MSI-X vectors and requests |
| 864 | * interrupts from the kernel. |
| 865 | **/ |
| 866 | static int ixgbevf_request_msix_irqs(struct ixgbevf_adapter *adapter) |
| 867 | { |
| 868 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 869 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 870 | int vector, err; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 871 | int ri = 0, ti = 0; |
| 872 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 873 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 874 | struct ixgbevf_q_vector *q_vector = adapter->q_vector[vector]; |
| 875 | struct msix_entry *entry = &adapter->msix_entries[vector]; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 876 | |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 877 | if (q_vector->tx.ring && q_vector->rx.ring) { |
| 878 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 879 | "%s-%s-%d", netdev->name, "TxRx", ri++); |
| 880 | ti++; |
| 881 | } else if (q_vector->rx.ring) { |
| 882 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 883 | "%s-%s-%d", netdev->name, "rx", ri++); |
| 884 | } else if (q_vector->tx.ring) { |
| 885 | snprintf(q_vector->name, sizeof(q_vector->name) - 1, |
| 886 | "%s-%s-%d", netdev->name, "tx", ti++); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 887 | } else { |
| 888 | /* skip this unused q_vector */ |
| 889 | continue; |
| 890 | } |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 891 | err = request_irq(entry->vector, &ixgbevf_msix_clean_rings, 0, |
| 892 | q_vector->name, q_vector); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 893 | if (err) { |
| 894 | hw_dbg(&adapter->hw, |
| 895 | "request_irq failed for MSIX interrupt " |
| 896 | "Error: %d\n", err); |
| 897 | goto free_queue_irqs; |
| 898 | } |
| 899 | } |
| 900 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 901 | err = request_irq(adapter->msix_entries[vector].vector, |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 902 | &ixgbevf_msix_mbx, 0, netdev->name, adapter); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 903 | if (err) { |
| 904 | hw_dbg(&adapter->hw, |
| 905 | "request_irq for msix_mbx failed: %d\n", err); |
| 906 | goto free_queue_irqs; |
| 907 | } |
| 908 | |
| 909 | return 0; |
| 910 | |
| 911 | free_queue_irqs: |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 912 | while (vector) { |
| 913 | vector--; |
| 914 | free_irq(adapter->msix_entries[vector].vector, |
| 915 | adapter->q_vector[vector]); |
| 916 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 917 | pci_disable_msix(adapter->pdev); |
| 918 | kfree(adapter->msix_entries); |
| 919 | adapter->msix_entries = NULL; |
| 920 | return err; |
| 921 | } |
| 922 | |
| 923 | static inline void ixgbevf_reset_q_vectors(struct ixgbevf_adapter *adapter) |
| 924 | { |
| 925 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 926 | |
| 927 | for (i = 0; i < q_vectors; i++) { |
| 928 | struct ixgbevf_q_vector *q_vector = adapter->q_vector[i]; |
Alexander Duyck | 6b43c44 | 2012-05-11 08:32:45 +0000 | [diff] [blame] | 929 | q_vector->rx.ring = NULL; |
| 930 | q_vector->tx.ring = NULL; |
| 931 | q_vector->rx.count = 0; |
| 932 | q_vector->tx.count = 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | |
| 936 | /** |
| 937 | * ixgbevf_request_irq - initialize interrupts |
| 938 | * @adapter: board private structure |
| 939 | * |
| 940 | * Attempts to configure interrupts using the best available |
| 941 | * capabilities of the hardware and kernel. |
| 942 | **/ |
| 943 | static int ixgbevf_request_irq(struct ixgbevf_adapter *adapter) |
| 944 | { |
| 945 | int err = 0; |
| 946 | |
| 947 | err = ixgbevf_request_msix_irqs(adapter); |
| 948 | |
| 949 | if (err) |
| 950 | hw_dbg(&adapter->hw, |
| 951 | "request_irq failed, Error %d\n", err); |
| 952 | |
| 953 | return err; |
| 954 | } |
| 955 | |
| 956 | static void ixgbevf_free_irq(struct ixgbevf_adapter *adapter) |
| 957 | { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 958 | int i, q_vectors; |
| 959 | |
| 960 | q_vectors = adapter->num_msix_vectors; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 961 | i = q_vectors - 1; |
| 962 | |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 963 | free_irq(adapter->msix_entries[i].vector, adapter); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 964 | i--; |
| 965 | |
| 966 | for (; i >= 0; i--) { |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 967 | /* free only the irqs that were actually requested */ |
| 968 | if (!adapter->q_vector[i]->rx.ring && |
| 969 | !adapter->q_vector[i]->tx.ring) |
| 970 | continue; |
| 971 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 972 | free_irq(adapter->msix_entries[i].vector, |
| 973 | adapter->q_vector[i]); |
| 974 | } |
| 975 | |
| 976 | ixgbevf_reset_q_vectors(adapter); |
| 977 | } |
| 978 | |
| 979 | /** |
| 980 | * ixgbevf_irq_disable - Mask off interrupt generation on the NIC |
| 981 | * @adapter: board private structure |
| 982 | **/ |
| 983 | static inline void ixgbevf_irq_disable(struct ixgbevf_adapter *adapter) |
| 984 | { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 985 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 986 | int i; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 987 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 988 | IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, 0); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 989 | IXGBE_WRITE_REG(hw, IXGBE_VTEIMC, ~0); |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 990 | IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, 0); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 991 | |
| 992 | IXGBE_WRITE_FLUSH(hw); |
| 993 | |
| 994 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 995 | synchronize_irq(adapter->msix_entries[i].vector); |
| 996 | } |
| 997 | |
| 998 | /** |
| 999 | * ixgbevf_irq_enable - Enable default interrupt generation settings |
| 1000 | * @adapter: board private structure |
| 1001 | **/ |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 1002 | static inline void ixgbevf_irq_enable(struct ixgbevf_adapter *adapter) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1003 | { |
| 1004 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1005 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 1006 | IXGBE_WRITE_REG(hw, IXGBE_VTEIAM, adapter->eims_enable_mask); |
| 1007 | IXGBE_WRITE_REG(hw, IXGBE_VTEIAC, adapter->eims_enable_mask); |
| 1008 | IXGBE_WRITE_REG(hw, IXGBE_VTEIMS, adapter->eims_enable_mask); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | /** |
| 1012 | * ixgbevf_configure_tx - Configure 82599 VF Transmit Unit after Reset |
| 1013 | * @adapter: board private structure |
| 1014 | * |
| 1015 | * Configure the Tx unit of the MAC after a reset. |
| 1016 | **/ |
| 1017 | static void ixgbevf_configure_tx(struct ixgbevf_adapter *adapter) |
| 1018 | { |
| 1019 | u64 tdba; |
| 1020 | struct ixgbe_hw *hw = &adapter->hw; |
| 1021 | u32 i, j, tdlen, txctrl; |
| 1022 | |
| 1023 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1024 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1025 | struct ixgbevf_ring *ring = &adapter->tx_ring[i]; |
| 1026 | j = ring->reg_idx; |
| 1027 | tdba = ring->dma; |
| 1028 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
| 1029 | IXGBE_WRITE_REG(hw, IXGBE_VFTDBAL(j), |
| 1030 | (tdba & DMA_BIT_MASK(32))); |
| 1031 | IXGBE_WRITE_REG(hw, IXGBE_VFTDBAH(j), (tdba >> 32)); |
| 1032 | IXGBE_WRITE_REG(hw, IXGBE_VFTDLEN(j), tdlen); |
| 1033 | IXGBE_WRITE_REG(hw, IXGBE_VFTDH(j), 0); |
| 1034 | IXGBE_WRITE_REG(hw, IXGBE_VFTDT(j), 0); |
| 1035 | adapter->tx_ring[i].head = IXGBE_VFTDH(j); |
| 1036 | adapter->tx_ring[i].tail = IXGBE_VFTDT(j); |
| 1037 | /* Disable Tx Head Writeback RO bit, since this hoses |
| 1038 | * bookkeeping if things aren't delivered in order. |
| 1039 | */ |
| 1040 | txctrl = IXGBE_READ_REG(hw, IXGBE_VFDCA_TXCTRL(j)); |
| 1041 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
| 1042 | IXGBE_WRITE_REG(hw, IXGBE_VFDCA_TXCTRL(j), txctrl); |
| 1043 | } |
| 1044 | } |
| 1045 | |
| 1046 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
| 1047 | |
| 1048 | static void ixgbevf_configure_srrctl(struct ixgbevf_adapter *adapter, int index) |
| 1049 | { |
| 1050 | struct ixgbevf_ring *rx_ring; |
| 1051 | struct ixgbe_hw *hw = &adapter->hw; |
| 1052 | u32 srrctl; |
| 1053 | |
| 1054 | rx_ring = &adapter->rx_ring[index]; |
| 1055 | |
| 1056 | srrctl = IXGBE_SRRCTL_DROP_EN; |
| 1057 | |
Alexander Duyck | 77d5dfc | 2012-05-11 08:32:19 +0000 | [diff] [blame] | 1058 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1059 | |
Alexander Duyck | dd1fe11 | 2012-07-20 08:09:48 +0000 | [diff] [blame] | 1060 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 1061 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1062 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1063 | IXGBE_WRITE_REG(hw, IXGBE_VFSRRCTL(index), srrctl); |
| 1064 | } |
| 1065 | |
Alexander Duyck | dd1fe11 | 2012-07-20 08:09:48 +0000 | [diff] [blame] | 1066 | static void ixgbevf_set_rx_buffer_len(struct ixgbevf_adapter *adapter) |
| 1067 | { |
| 1068 | struct ixgbe_hw *hw = &adapter->hw; |
| 1069 | struct net_device *netdev = adapter->netdev; |
| 1070 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
| 1071 | int i; |
| 1072 | u16 rx_buf_len; |
| 1073 | |
| 1074 | /* notify the PF of our intent to use this size of frame */ |
| 1075 | ixgbevf_rlpml_set_vf(hw, max_frame); |
| 1076 | |
| 1077 | /* PF will allow an extra 4 bytes past for vlan tagged frames */ |
| 1078 | max_frame += VLAN_HLEN; |
| 1079 | |
| 1080 | /* |
| 1081 | * Make best use of allocation by using all but 1K of a |
| 1082 | * power of 2 allocation that will be used for skb->head. |
| 1083 | */ |
| 1084 | if ((hw->mac.type == ixgbe_mac_X540_vf) && |
| 1085 | (max_frame <= MAXIMUM_ETHERNET_VLAN_SIZE)) |
| 1086 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
| 1087 | else if (max_frame <= IXGBEVF_RXBUFFER_3K) |
| 1088 | rx_buf_len = IXGBEVF_RXBUFFER_3K; |
| 1089 | else if (max_frame <= IXGBEVF_RXBUFFER_7K) |
| 1090 | rx_buf_len = IXGBEVF_RXBUFFER_7K; |
| 1091 | else if (max_frame <= IXGBEVF_RXBUFFER_15K) |
| 1092 | rx_buf_len = IXGBEVF_RXBUFFER_15K; |
| 1093 | else |
| 1094 | rx_buf_len = IXGBEVF_MAX_RXBUFFER; |
| 1095 | |
| 1096 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1097 | adapter->rx_ring[i].rx_buf_len = rx_buf_len; |
| 1098 | } |
| 1099 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1100 | /** |
| 1101 | * ixgbevf_configure_rx - Configure 82599 VF Receive Unit after Reset |
| 1102 | * @adapter: board private structure |
| 1103 | * |
| 1104 | * Configure the Rx unit of the MAC after a reset. |
| 1105 | **/ |
| 1106 | static void ixgbevf_configure_rx(struct ixgbevf_adapter *adapter) |
| 1107 | { |
| 1108 | u64 rdba; |
| 1109 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1110 | int i, j; |
| 1111 | u32 rdlen; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1112 | |
Alexander Duyck | 77d5dfc | 2012-05-11 08:32:19 +0000 | [diff] [blame] | 1113 | /* PSRTYPE must be initialized in 82599 */ |
| 1114 | IXGBE_WRITE_REG(hw, IXGBE_VFPSRTYPE, 0); |
Alexander Duyck | dd1fe11 | 2012-07-20 08:09:48 +0000 | [diff] [blame] | 1115 | |
| 1116 | /* set_rx_buffer_len must be called before ring initialization */ |
| 1117 | ixgbevf_set_rx_buffer_len(adapter); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1118 | |
| 1119 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
| 1120 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 1121 | * the Base and Length of the Rx Descriptor Ring */ |
| 1122 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1123 | rdba = adapter->rx_ring[i].dma; |
| 1124 | j = adapter->rx_ring[i].reg_idx; |
| 1125 | IXGBE_WRITE_REG(hw, IXGBE_VFRDBAL(j), |
| 1126 | (rdba & DMA_BIT_MASK(32))); |
| 1127 | IXGBE_WRITE_REG(hw, IXGBE_VFRDBAH(j), (rdba >> 32)); |
| 1128 | IXGBE_WRITE_REG(hw, IXGBE_VFRDLEN(j), rdlen); |
| 1129 | IXGBE_WRITE_REG(hw, IXGBE_VFRDH(j), 0); |
| 1130 | IXGBE_WRITE_REG(hw, IXGBE_VFRDT(j), 0); |
| 1131 | adapter->rx_ring[i].head = IXGBE_VFRDH(j); |
| 1132 | adapter->rx_ring[i].tail = IXGBE_VFRDT(j); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1133 | |
| 1134 | ixgbevf_configure_srrctl(adapter, j); |
| 1135 | } |
| 1136 | } |
| 1137 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1138 | static int ixgbevf_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1139 | { |
| 1140 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 1141 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1142 | |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1143 | spin_lock(&adapter->mbx_lock); |
| 1144 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1145 | /* add VID to filter table */ |
| 1146 | if (hw->mac.ops.set_vfta) |
| 1147 | hw->mac.ops.set_vfta(hw, vid, 0, true); |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1148 | |
| 1149 | spin_unlock(&adapter->mbx_lock); |
| 1150 | |
Jiri Pirko | dadcd65 | 2011-07-21 03:25:09 +0000 | [diff] [blame] | 1151 | set_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1152 | |
| 1153 | return 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1156 | static int ixgbevf_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1157 | { |
| 1158 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 1159 | struct ixgbe_hw *hw = &adapter->hw; |
| 1160 | |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1161 | spin_lock(&adapter->mbx_lock); |
| 1162 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1163 | /* remove VID from filter table */ |
| 1164 | if (hw->mac.ops.set_vfta) |
| 1165 | hw->mac.ops.set_vfta(hw, vid, 0, false); |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1166 | |
| 1167 | spin_unlock(&adapter->mbx_lock); |
| 1168 | |
Jiri Pirko | dadcd65 | 2011-07-21 03:25:09 +0000 | [diff] [blame] | 1169 | clear_bit(vid, adapter->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1170 | |
| 1171 | return 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | static void ixgbevf_restore_vlan(struct ixgbevf_adapter *adapter) |
| 1175 | { |
Jiri Pirko | dadcd65 | 2011-07-21 03:25:09 +0000 | [diff] [blame] | 1176 | u16 vid; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1177 | |
Jiri Pirko | dadcd65 | 2011-07-21 03:25:09 +0000 | [diff] [blame] | 1178 | for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID) |
| 1179 | ixgbevf_vlan_rx_add_vid(adapter->netdev, vid); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1180 | } |
| 1181 | |
Greg Rose | 46ec20f | 2011-05-13 01:33:42 +0000 | [diff] [blame] | 1182 | static int ixgbevf_write_uc_addr_list(struct net_device *netdev) |
| 1183 | { |
| 1184 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 1185 | struct ixgbe_hw *hw = &adapter->hw; |
| 1186 | int count = 0; |
| 1187 | |
| 1188 | if ((netdev_uc_count(netdev)) > 10) { |
Jeff Kirsher | dbd9636 | 2011-10-21 19:38:18 +0000 | [diff] [blame] | 1189 | pr_err("Too many unicast filters - No Space\n"); |
Greg Rose | 46ec20f | 2011-05-13 01:33:42 +0000 | [diff] [blame] | 1190 | return -ENOSPC; |
| 1191 | } |
| 1192 | |
| 1193 | if (!netdev_uc_empty(netdev)) { |
| 1194 | struct netdev_hw_addr *ha; |
| 1195 | netdev_for_each_uc_addr(ha, netdev) { |
| 1196 | hw->mac.ops.set_uc_addr(hw, ++count, ha->addr); |
| 1197 | udelay(200); |
| 1198 | } |
| 1199 | } else { |
| 1200 | /* |
| 1201 | * If the list is empty then send message to PF driver to |
| 1202 | * clear all macvlans on this VF. |
| 1203 | */ |
| 1204 | hw->mac.ops.set_uc_addr(hw, 0, NULL); |
| 1205 | } |
| 1206 | |
| 1207 | return count; |
| 1208 | } |
| 1209 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1210 | /** |
| 1211 | * ixgbevf_set_rx_mode - Multicast set |
| 1212 | * @netdev: network interface device structure |
| 1213 | * |
| 1214 | * The set_rx_method entry point is called whenever the multicast address |
| 1215 | * list or the network interface flags are updated. This routine is |
| 1216 | * responsible for configuring the hardware for proper multicast mode. |
| 1217 | **/ |
| 1218 | static void ixgbevf_set_rx_mode(struct net_device *netdev) |
| 1219 | { |
| 1220 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 1221 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1222 | |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1223 | spin_lock(&adapter->mbx_lock); |
| 1224 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1225 | /* reprogram multicast list */ |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1226 | if (hw->mac.ops.update_mc_addr_list) |
Jiri Pirko | 5c58c47 | 2010-03-23 22:58:20 +0000 | [diff] [blame] | 1227 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
Greg Rose | 46ec20f | 2011-05-13 01:33:42 +0000 | [diff] [blame] | 1228 | |
| 1229 | ixgbevf_write_uc_addr_list(netdev); |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1230 | |
| 1231 | spin_unlock(&adapter->mbx_lock); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | static void ixgbevf_napi_enable_all(struct ixgbevf_adapter *adapter) |
| 1235 | { |
| 1236 | int q_idx; |
| 1237 | struct ixgbevf_q_vector *q_vector; |
| 1238 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1239 | |
| 1240 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1241 | q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 1242 | napi_enable(&q_vector->napi); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1243 | } |
| 1244 | } |
| 1245 | |
| 1246 | static void ixgbevf_napi_disable_all(struct ixgbevf_adapter *adapter) |
| 1247 | { |
| 1248 | int q_idx; |
| 1249 | struct ixgbevf_q_vector *q_vector; |
| 1250 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1251 | |
| 1252 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 1253 | q_vector = adapter->q_vector[q_idx]; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1254 | napi_disable(&q_vector->napi); |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | static void ixgbevf_configure(struct ixgbevf_adapter *adapter) |
| 1259 | { |
| 1260 | struct net_device *netdev = adapter->netdev; |
| 1261 | int i; |
| 1262 | |
| 1263 | ixgbevf_set_rx_mode(netdev); |
| 1264 | |
| 1265 | ixgbevf_restore_vlan(adapter); |
| 1266 | |
| 1267 | ixgbevf_configure_tx(adapter); |
| 1268 | ixgbevf_configure_rx(adapter); |
| 1269 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1270 | struct ixgbevf_ring *ring = &adapter->rx_ring[i]; |
Alexander Duyck | 18c6308 | 2012-05-11 08:33:11 +0000 | [diff] [blame] | 1271 | ixgbevf_alloc_rx_buffers(adapter, ring, |
| 1272 | IXGBE_DESC_UNUSED(ring)); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1273 | } |
| 1274 | } |
| 1275 | |
| 1276 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 1277 | static inline void ixgbevf_rx_desc_queue_enable(struct ixgbevf_adapter *adapter, |
| 1278 | int rxr) |
| 1279 | { |
| 1280 | struct ixgbe_hw *hw = &adapter->hw; |
| 1281 | int j = adapter->rx_ring[rxr].reg_idx; |
| 1282 | int k; |
| 1283 | |
| 1284 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { |
| 1285 | if (IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j)) & IXGBE_RXDCTL_ENABLE) |
| 1286 | break; |
| 1287 | else |
| 1288 | msleep(1); |
| 1289 | } |
| 1290 | if (k >= IXGBE_MAX_RX_DESC_POLL) { |
| 1291 | hw_dbg(hw, "RXDCTL.ENABLE on Rx queue %d " |
| 1292 | "not set within the polling period\n", rxr); |
| 1293 | } |
| 1294 | |
| 1295 | ixgbevf_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], |
| 1296 | (adapter->rx_ring[rxr].count - 1)); |
| 1297 | } |
| 1298 | |
Greg Rose | 33bd9f6 | 2010-03-19 02:59:52 +0000 | [diff] [blame] | 1299 | static void ixgbevf_save_reset_stats(struct ixgbevf_adapter *adapter) |
| 1300 | { |
| 1301 | /* Only save pre-reset stats if there are some */ |
| 1302 | if (adapter->stats.vfgprc || adapter->stats.vfgptc) { |
| 1303 | adapter->stats.saved_reset_vfgprc += adapter->stats.vfgprc - |
| 1304 | adapter->stats.base_vfgprc; |
| 1305 | adapter->stats.saved_reset_vfgptc += adapter->stats.vfgptc - |
| 1306 | adapter->stats.base_vfgptc; |
| 1307 | adapter->stats.saved_reset_vfgorc += adapter->stats.vfgorc - |
| 1308 | adapter->stats.base_vfgorc; |
| 1309 | adapter->stats.saved_reset_vfgotc += adapter->stats.vfgotc - |
| 1310 | adapter->stats.base_vfgotc; |
| 1311 | adapter->stats.saved_reset_vfmprc += adapter->stats.vfmprc - |
| 1312 | adapter->stats.base_vfmprc; |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | static void ixgbevf_init_last_counter_stats(struct ixgbevf_adapter *adapter) |
| 1317 | { |
| 1318 | struct ixgbe_hw *hw = &adapter->hw; |
| 1319 | |
| 1320 | adapter->stats.last_vfgprc = IXGBE_READ_REG(hw, IXGBE_VFGPRC); |
| 1321 | adapter->stats.last_vfgorc = IXGBE_READ_REG(hw, IXGBE_VFGORC_LSB); |
| 1322 | adapter->stats.last_vfgorc |= |
| 1323 | (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGORC_MSB))) << 32); |
| 1324 | adapter->stats.last_vfgptc = IXGBE_READ_REG(hw, IXGBE_VFGPTC); |
| 1325 | adapter->stats.last_vfgotc = IXGBE_READ_REG(hw, IXGBE_VFGOTC_LSB); |
| 1326 | adapter->stats.last_vfgotc |= |
| 1327 | (((u64)(IXGBE_READ_REG(hw, IXGBE_VFGOTC_MSB))) << 32); |
| 1328 | adapter->stats.last_vfmprc = IXGBE_READ_REG(hw, IXGBE_VFMPRC); |
| 1329 | |
| 1330 | adapter->stats.base_vfgprc = adapter->stats.last_vfgprc; |
| 1331 | adapter->stats.base_vfgorc = adapter->stats.last_vfgorc; |
| 1332 | adapter->stats.base_vfgptc = adapter->stats.last_vfgptc; |
| 1333 | adapter->stats.base_vfgotc = adapter->stats.last_vfgotc; |
| 1334 | adapter->stats.base_vfmprc = adapter->stats.last_vfmprc; |
| 1335 | } |
| 1336 | |
Alexander Duyck | 3118678 | 2012-07-20 08:09:58 +0000 | [diff] [blame] | 1337 | static void ixgbevf_negotiate_api(struct ixgbevf_adapter *adapter) |
| 1338 | { |
| 1339 | struct ixgbe_hw *hw = &adapter->hw; |
| 1340 | int api[] = { ixgbe_mbox_api_10, |
| 1341 | ixgbe_mbox_api_unknown }; |
| 1342 | int err = 0, idx = 0; |
| 1343 | |
| 1344 | spin_lock(&adapter->mbx_lock); |
| 1345 | |
| 1346 | while (api[idx] != ixgbe_mbox_api_unknown) { |
| 1347 | err = ixgbevf_negotiate_api_version(hw, api[idx]); |
| 1348 | if (!err) |
| 1349 | break; |
| 1350 | idx++; |
| 1351 | } |
| 1352 | |
| 1353 | spin_unlock(&adapter->mbx_lock); |
| 1354 | } |
| 1355 | |
Greg Rose | 795180d | 2012-04-17 04:29:34 +0000 | [diff] [blame] | 1356 | static void ixgbevf_up_complete(struct ixgbevf_adapter *adapter) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1357 | { |
| 1358 | struct net_device *netdev = adapter->netdev; |
| 1359 | struct ixgbe_hw *hw = &adapter->hw; |
| 1360 | int i, j = 0; |
| 1361 | int num_rx_rings = adapter->num_rx_queues; |
| 1362 | u32 txdctl, rxdctl; |
| 1363 | |
| 1364 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1365 | j = adapter->tx_ring[i].reg_idx; |
| 1366 | txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j)); |
| 1367 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 1368 | txdctl |= (8 << 16); |
| 1369 | IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl); |
| 1370 | } |
| 1371 | |
| 1372 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1373 | j = adapter->tx_ring[i].reg_idx; |
| 1374 | txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j)); |
| 1375 | txdctl |= IXGBE_TXDCTL_ENABLE; |
| 1376 | IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), txdctl); |
| 1377 | } |
| 1378 | |
| 1379 | for (i = 0; i < num_rx_rings; i++) { |
| 1380 | j = adapter->rx_ring[i].reg_idx; |
| 1381 | rxdctl = IXGBE_READ_REG(hw, IXGBE_VFRXDCTL(j)); |
Jiri Pirko | dadcd65 | 2011-07-21 03:25:09 +0000 | [diff] [blame] | 1382 | rxdctl |= IXGBE_RXDCTL_ENABLE | IXGBE_RXDCTL_VME; |
Greg Rose | 69bfbec | 2011-01-26 01:06:12 +0000 | [diff] [blame] | 1383 | if (hw->mac.type == ixgbe_mac_X540_vf) { |
| 1384 | rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK; |
| 1385 | rxdctl |= ((netdev->mtu + ETH_HLEN + ETH_FCS_LEN) | |
| 1386 | IXGBE_RXDCTL_RLPML_EN); |
| 1387 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1388 | IXGBE_WRITE_REG(hw, IXGBE_VFRXDCTL(j), rxdctl); |
| 1389 | ixgbevf_rx_desc_queue_enable(adapter, i); |
| 1390 | } |
| 1391 | |
| 1392 | ixgbevf_configure_msix(adapter); |
| 1393 | |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1394 | spin_lock(&adapter->mbx_lock); |
| 1395 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1396 | if (hw->mac.ops.set_rar) { |
| 1397 | if (is_valid_ether_addr(hw->mac.addr)) |
| 1398 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0); |
| 1399 | else |
| 1400 | hw->mac.ops.set_rar(hw, 0, hw->mac.perm_addr, 0); |
| 1401 | } |
| 1402 | |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1403 | spin_unlock(&adapter->mbx_lock); |
| 1404 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1405 | clear_bit(__IXGBEVF_DOWN, &adapter->state); |
| 1406 | ixgbevf_napi_enable_all(adapter); |
| 1407 | |
| 1408 | /* enable transmits */ |
| 1409 | netif_tx_start_all_queues(netdev); |
| 1410 | |
Greg Rose | 33bd9f6 | 2010-03-19 02:59:52 +0000 | [diff] [blame] | 1411 | ixgbevf_save_reset_stats(adapter); |
| 1412 | ixgbevf_init_last_counter_stats(adapter); |
| 1413 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1414 | mod_timer(&adapter->watchdog_timer, jiffies); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1415 | } |
| 1416 | |
Greg Rose | 795180d | 2012-04-17 04:29:34 +0000 | [diff] [blame] | 1417 | void ixgbevf_up(struct ixgbevf_adapter *adapter) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1418 | { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1419 | struct ixgbe_hw *hw = &adapter->hw; |
| 1420 | |
Alexander Duyck | 3118678 | 2012-07-20 08:09:58 +0000 | [diff] [blame] | 1421 | ixgbevf_negotiate_api(adapter); |
| 1422 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1423 | ixgbevf_configure(adapter); |
| 1424 | |
Greg Rose | 795180d | 2012-04-17 04:29:34 +0000 | [diff] [blame] | 1425 | ixgbevf_up_complete(adapter); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1426 | |
| 1427 | /* clear any pending interrupts, may auto mask */ |
| 1428 | IXGBE_READ_REG(hw, IXGBE_VTEICR); |
| 1429 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 1430 | ixgbevf_irq_enable(adapter); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | /** |
| 1434 | * ixgbevf_clean_rx_ring - Free Rx Buffers per Queue |
| 1435 | * @adapter: board private structure |
| 1436 | * @rx_ring: ring to free buffers from |
| 1437 | **/ |
| 1438 | static void ixgbevf_clean_rx_ring(struct ixgbevf_adapter *adapter, |
| 1439 | struct ixgbevf_ring *rx_ring) |
| 1440 | { |
| 1441 | struct pci_dev *pdev = adapter->pdev; |
| 1442 | unsigned long size; |
| 1443 | unsigned int i; |
| 1444 | |
Greg Rose | c0456c2 | 2010-01-22 22:47:18 +0000 | [diff] [blame] | 1445 | if (!rx_ring->rx_buffer_info) |
| 1446 | return; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1447 | |
Greg Rose | c0456c2 | 2010-01-22 22:47:18 +0000 | [diff] [blame] | 1448 | /* Free all the Rx ring sk_buffs */ |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1449 | for (i = 0; i < rx_ring->count; i++) { |
| 1450 | struct ixgbevf_rx_buffer *rx_buffer_info; |
| 1451 | |
| 1452 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 1453 | if (rx_buffer_info->dma) { |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 1454 | dma_unmap_single(&pdev->dev, rx_buffer_info->dma, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1455 | rx_ring->rx_buf_len, |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 1456 | DMA_FROM_DEVICE); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1457 | rx_buffer_info->dma = 0; |
| 1458 | } |
| 1459 | if (rx_buffer_info->skb) { |
| 1460 | struct sk_buff *skb = rx_buffer_info->skb; |
| 1461 | rx_buffer_info->skb = NULL; |
| 1462 | do { |
| 1463 | struct sk_buff *this = skb; |
| 1464 | skb = skb->prev; |
| 1465 | dev_kfree_skb(this); |
| 1466 | } while (skb); |
| 1467 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count; |
| 1471 | memset(rx_ring->rx_buffer_info, 0, size); |
| 1472 | |
| 1473 | /* Zero out the descriptor ring */ |
| 1474 | memset(rx_ring->desc, 0, rx_ring->size); |
| 1475 | |
| 1476 | rx_ring->next_to_clean = 0; |
| 1477 | rx_ring->next_to_use = 0; |
| 1478 | |
| 1479 | if (rx_ring->head) |
| 1480 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 1481 | if (rx_ring->tail) |
| 1482 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
| 1483 | } |
| 1484 | |
| 1485 | /** |
| 1486 | * ixgbevf_clean_tx_ring - Free Tx Buffers |
| 1487 | * @adapter: board private structure |
| 1488 | * @tx_ring: ring to be cleaned |
| 1489 | **/ |
| 1490 | static void ixgbevf_clean_tx_ring(struct ixgbevf_adapter *adapter, |
| 1491 | struct ixgbevf_ring *tx_ring) |
| 1492 | { |
| 1493 | struct ixgbevf_tx_buffer *tx_buffer_info; |
| 1494 | unsigned long size; |
| 1495 | unsigned int i; |
| 1496 | |
Greg Rose | c0456c2 | 2010-01-22 22:47:18 +0000 | [diff] [blame] | 1497 | if (!tx_ring->tx_buffer_info) |
| 1498 | return; |
| 1499 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1500 | /* Free all the Tx ring sk_buffs */ |
| 1501 | |
| 1502 | for (i = 0; i < tx_ring->count; i++) { |
| 1503 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 1504 | ixgbevf_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count; |
| 1508 | memset(tx_ring->tx_buffer_info, 0, size); |
| 1509 | |
| 1510 | memset(tx_ring->desc, 0, tx_ring->size); |
| 1511 | |
| 1512 | tx_ring->next_to_use = 0; |
| 1513 | tx_ring->next_to_clean = 0; |
| 1514 | |
| 1515 | if (tx_ring->head) |
| 1516 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 1517 | if (tx_ring->tail) |
| 1518 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
| 1519 | } |
| 1520 | |
| 1521 | /** |
| 1522 | * ixgbevf_clean_all_rx_rings - Free Rx Buffers for all queues |
| 1523 | * @adapter: board private structure |
| 1524 | **/ |
| 1525 | static void ixgbevf_clean_all_rx_rings(struct ixgbevf_adapter *adapter) |
| 1526 | { |
| 1527 | int i; |
| 1528 | |
| 1529 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 1530 | ixgbevf_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
| 1531 | } |
| 1532 | |
| 1533 | /** |
| 1534 | * ixgbevf_clean_all_tx_rings - Free Tx Buffers for all queues |
| 1535 | * @adapter: board private structure |
| 1536 | **/ |
| 1537 | static void ixgbevf_clean_all_tx_rings(struct ixgbevf_adapter *adapter) |
| 1538 | { |
| 1539 | int i; |
| 1540 | |
| 1541 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 1542 | ixgbevf_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
| 1543 | } |
| 1544 | |
| 1545 | void ixgbevf_down(struct ixgbevf_adapter *adapter) |
| 1546 | { |
| 1547 | struct net_device *netdev = adapter->netdev; |
| 1548 | struct ixgbe_hw *hw = &adapter->hw; |
| 1549 | u32 txdctl; |
| 1550 | int i, j; |
| 1551 | |
| 1552 | /* signal that we are down to the interrupt handler */ |
| 1553 | set_bit(__IXGBEVF_DOWN, &adapter->state); |
| 1554 | /* disable receives */ |
| 1555 | |
| 1556 | netif_tx_disable(netdev); |
| 1557 | |
| 1558 | msleep(10); |
| 1559 | |
| 1560 | netif_tx_stop_all_queues(netdev); |
| 1561 | |
| 1562 | ixgbevf_irq_disable(adapter); |
| 1563 | |
| 1564 | ixgbevf_napi_disable_all(adapter); |
| 1565 | |
| 1566 | del_timer_sync(&adapter->watchdog_timer); |
| 1567 | /* can't call flush scheduled work here because it can deadlock |
| 1568 | * if linkwatch_event tries to acquire the rtnl_lock which we are |
| 1569 | * holding */ |
| 1570 | while (adapter->flags & IXGBE_FLAG_IN_WATCHDOG_TASK) |
| 1571 | msleep(1); |
| 1572 | |
| 1573 | /* disable transmits in the hardware now that interrupts are off */ |
| 1574 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1575 | j = adapter->tx_ring[i].reg_idx; |
| 1576 | txdctl = IXGBE_READ_REG(hw, IXGBE_VFTXDCTL(j)); |
| 1577 | IXGBE_WRITE_REG(hw, IXGBE_VFTXDCTL(j), |
| 1578 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 1579 | } |
| 1580 | |
| 1581 | netif_carrier_off(netdev); |
| 1582 | |
| 1583 | if (!pci_channel_offline(adapter->pdev)) |
| 1584 | ixgbevf_reset(adapter); |
| 1585 | |
| 1586 | ixgbevf_clean_all_tx_rings(adapter); |
| 1587 | ixgbevf_clean_all_rx_rings(adapter); |
| 1588 | } |
| 1589 | |
| 1590 | void ixgbevf_reinit_locked(struct ixgbevf_adapter *adapter) |
| 1591 | { |
Greg Rose | c0456c2 | 2010-01-22 22:47:18 +0000 | [diff] [blame] | 1592 | struct ixgbe_hw *hw = &adapter->hw; |
| 1593 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1594 | WARN_ON(in_interrupt()); |
Greg Rose | c0456c2 | 2010-01-22 22:47:18 +0000 | [diff] [blame] | 1595 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1596 | while (test_and_set_bit(__IXGBEVF_RESETTING, &adapter->state)) |
| 1597 | msleep(1); |
| 1598 | |
Greg Rose | c0456c2 | 2010-01-22 22:47:18 +0000 | [diff] [blame] | 1599 | /* |
| 1600 | * Check if PF is up before re-init. If not then skip until |
| 1601 | * later when the PF is up and ready to service requests from |
| 1602 | * the VF via mailbox. If the VF is up and running then the |
| 1603 | * watchdog task will continue to schedule reset tasks until |
| 1604 | * the PF is up and running. |
| 1605 | */ |
| 1606 | if (!hw->mac.ops.reset_hw(hw)) { |
| 1607 | ixgbevf_down(adapter); |
| 1608 | ixgbevf_up(adapter); |
| 1609 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1610 | |
| 1611 | clear_bit(__IXGBEVF_RESETTING, &adapter->state); |
| 1612 | } |
| 1613 | |
| 1614 | void ixgbevf_reset(struct ixgbevf_adapter *adapter) |
| 1615 | { |
| 1616 | struct ixgbe_hw *hw = &adapter->hw; |
| 1617 | struct net_device *netdev = adapter->netdev; |
| 1618 | |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1619 | spin_lock(&adapter->mbx_lock); |
| 1620 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1621 | if (hw->mac.ops.reset_hw(hw)) |
| 1622 | hw_dbg(hw, "PF still resetting\n"); |
| 1623 | else |
| 1624 | hw->mac.ops.init_hw(hw); |
| 1625 | |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1626 | spin_unlock(&adapter->mbx_lock); |
| 1627 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1628 | if (is_valid_ether_addr(adapter->hw.mac.addr)) { |
| 1629 | memcpy(netdev->dev_addr, adapter->hw.mac.addr, |
| 1630 | netdev->addr_len); |
| 1631 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, |
| 1632 | netdev->addr_len); |
| 1633 | } |
| 1634 | } |
| 1635 | |
| 1636 | static void ixgbevf_acquire_msix_vectors(struct ixgbevf_adapter *adapter, |
| 1637 | int vectors) |
| 1638 | { |
| 1639 | int err, vector_threshold; |
| 1640 | |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 1641 | /* We'll want at least 2 (vector_threshold): |
| 1642 | * 1) TxQ[0] + RxQ[0] handler |
| 1643 | * 2) Other (Link Status Change, etc.) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1644 | */ |
| 1645 | vector_threshold = MIN_MSIX_COUNT; |
| 1646 | |
| 1647 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 1648 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 1649 | * Right now, we simply care about how many we'll get; we'll |
| 1650 | * set them up later while requesting irq's. |
| 1651 | */ |
| 1652 | while (vectors >= vector_threshold) { |
| 1653 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
| 1654 | vectors); |
| 1655 | if (!err) /* Success in acquiring all requested vectors. */ |
| 1656 | break; |
| 1657 | else if (err < 0) |
| 1658 | vectors = 0; /* Nasty failure, quit now */ |
| 1659 | else /* err == number of vectors we should try again with */ |
| 1660 | vectors = err; |
| 1661 | } |
| 1662 | |
| 1663 | if (vectors < vector_threshold) { |
| 1664 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 1665 | * This just means we'll go with either a single MSI |
| 1666 | * vector or fall back to legacy interrupts. |
| 1667 | */ |
| 1668 | hw_dbg(&adapter->hw, |
| 1669 | "Unable to allocate MSI-X interrupts\n"); |
| 1670 | kfree(adapter->msix_entries); |
| 1671 | adapter->msix_entries = NULL; |
| 1672 | } else { |
| 1673 | /* |
| 1674 | * Adjust for only the vectors we'll use, which is minimum |
| 1675 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 1676 | * vectors we were allocated. |
| 1677 | */ |
| 1678 | adapter->num_msix_vectors = vectors; |
| 1679 | } |
| 1680 | } |
| 1681 | |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 1682 | /** |
| 1683 | * ixgbevf_set_num_queues - Allocate queues for device, feature dependent |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1684 | * @adapter: board private structure to initialize |
| 1685 | * |
| 1686 | * This is the top level queue allocation routine. The order here is very |
| 1687 | * important, starting with the "most" number of features turned on at once, |
| 1688 | * and ending with the smallest set of features. This way large combinations |
| 1689 | * can be allocated if they're turned on, and smaller combinations are the |
| 1690 | * fallthrough conditions. |
| 1691 | * |
| 1692 | **/ |
| 1693 | static void ixgbevf_set_num_queues(struct ixgbevf_adapter *adapter) |
| 1694 | { |
| 1695 | /* Start with base case */ |
| 1696 | adapter->num_rx_queues = 1; |
| 1697 | adapter->num_tx_queues = 1; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | /** |
| 1701 | * ixgbevf_alloc_queues - Allocate memory for all rings |
| 1702 | * @adapter: board private structure to initialize |
| 1703 | * |
| 1704 | * We allocate one ring per queue at run-time since we don't know the |
| 1705 | * number of queues at compile-time. The polling_netdev array is |
| 1706 | * intended for Multiqueue, but should work fine with a single queue. |
| 1707 | **/ |
| 1708 | static int ixgbevf_alloc_queues(struct ixgbevf_adapter *adapter) |
| 1709 | { |
| 1710 | int i; |
| 1711 | |
| 1712 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
| 1713 | sizeof(struct ixgbevf_ring), GFP_KERNEL); |
| 1714 | if (!adapter->tx_ring) |
| 1715 | goto err_tx_ring_allocation; |
| 1716 | |
| 1717 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
| 1718 | sizeof(struct ixgbevf_ring), GFP_KERNEL); |
| 1719 | if (!adapter->rx_ring) |
| 1720 | goto err_rx_ring_allocation; |
| 1721 | |
| 1722 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1723 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
| 1724 | adapter->tx_ring[i].queue_index = i; |
| 1725 | adapter->tx_ring[i].reg_idx = i; |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 1726 | adapter->tx_ring[i].dev = &adapter->pdev->dev; |
| 1727 | adapter->tx_ring[i].netdev = adapter->netdev; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1731 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
| 1732 | adapter->rx_ring[i].queue_index = i; |
| 1733 | adapter->rx_ring[i].reg_idx = i; |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 1734 | adapter->rx_ring[i].dev = &adapter->pdev->dev; |
| 1735 | adapter->rx_ring[i].netdev = adapter->netdev; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | return 0; |
| 1739 | |
| 1740 | err_rx_ring_allocation: |
| 1741 | kfree(adapter->tx_ring); |
| 1742 | err_tx_ring_allocation: |
| 1743 | return -ENOMEM; |
| 1744 | } |
| 1745 | |
| 1746 | /** |
| 1747 | * ixgbevf_set_interrupt_capability - set MSI-X or FAIL if not supported |
| 1748 | * @adapter: board private structure to initialize |
| 1749 | * |
| 1750 | * Attempt to configure the interrupts using the best available |
| 1751 | * capabilities of the hardware and the kernel. |
| 1752 | **/ |
| 1753 | static int ixgbevf_set_interrupt_capability(struct ixgbevf_adapter *adapter) |
| 1754 | { |
| 1755 | int err = 0; |
| 1756 | int vector, v_budget; |
| 1757 | |
| 1758 | /* |
| 1759 | * It's easy to be greedy for MSI-X vectors, but it really |
| 1760 | * doesn't do us much good if we have a lot more vectors |
| 1761 | * than CPU's. So let's be conservative and only ask for |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 1762 | * (roughly) the same number of vectors as there are CPU's. |
| 1763 | * The default is to use pairs of vectors. |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1764 | */ |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 1765 | v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues); |
| 1766 | v_budget = min_t(int, v_budget, num_online_cpus()); |
| 1767 | v_budget += NON_Q_VECTORS; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1768 | |
| 1769 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 1770 | * mean we disable MSI-X capabilities of the adapter. */ |
| 1771 | adapter->msix_entries = kcalloc(v_budget, |
| 1772 | sizeof(struct msix_entry), GFP_KERNEL); |
| 1773 | if (!adapter->msix_entries) { |
| 1774 | err = -ENOMEM; |
| 1775 | goto out; |
| 1776 | } |
| 1777 | |
| 1778 | for (vector = 0; vector < v_budget; vector++) |
| 1779 | adapter->msix_entries[vector].entry = vector; |
| 1780 | |
| 1781 | ixgbevf_acquire_msix_vectors(adapter, v_budget); |
| 1782 | |
| 1783 | out: |
| 1784 | return err; |
| 1785 | } |
| 1786 | |
| 1787 | /** |
| 1788 | * ixgbevf_alloc_q_vectors - Allocate memory for interrupt vectors |
| 1789 | * @adapter: board private structure to initialize |
| 1790 | * |
| 1791 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 1792 | * return -ENOMEM. |
| 1793 | **/ |
| 1794 | static int ixgbevf_alloc_q_vectors(struct ixgbevf_adapter *adapter) |
| 1795 | { |
| 1796 | int q_idx, num_q_vectors; |
| 1797 | struct ixgbevf_q_vector *q_vector; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1798 | |
| 1799 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1800 | |
| 1801 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 1802 | q_vector = kzalloc(sizeof(struct ixgbevf_q_vector), GFP_KERNEL); |
| 1803 | if (!q_vector) |
| 1804 | goto err_out; |
| 1805 | q_vector->adapter = adapter; |
| 1806 | q_vector->v_idx = q_idx; |
Alexander Duyck | fa71ae2 | 2012-05-11 08:32:50 +0000 | [diff] [blame] | 1807 | netif_napi_add(adapter->netdev, &q_vector->napi, |
| 1808 | ixgbevf_poll, 64); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1809 | adapter->q_vector[q_idx] = q_vector; |
| 1810 | } |
| 1811 | |
| 1812 | return 0; |
| 1813 | |
| 1814 | err_out: |
| 1815 | while (q_idx) { |
| 1816 | q_idx--; |
| 1817 | q_vector = adapter->q_vector[q_idx]; |
| 1818 | netif_napi_del(&q_vector->napi); |
| 1819 | kfree(q_vector); |
| 1820 | adapter->q_vector[q_idx] = NULL; |
| 1821 | } |
| 1822 | return -ENOMEM; |
| 1823 | } |
| 1824 | |
| 1825 | /** |
| 1826 | * ixgbevf_free_q_vectors - Free memory allocated for interrupt vectors |
| 1827 | * @adapter: board private structure to initialize |
| 1828 | * |
| 1829 | * This function frees the memory allocated to the q_vectors. In addition if |
| 1830 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 1831 | * to freeing the q_vector. |
| 1832 | **/ |
| 1833 | static void ixgbevf_free_q_vectors(struct ixgbevf_adapter *adapter) |
| 1834 | { |
| 1835 | int q_idx, num_q_vectors; |
| 1836 | int napi_vectors; |
| 1837 | |
| 1838 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1839 | napi_vectors = adapter->num_rx_queues; |
| 1840 | |
| 1841 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 1842 | struct ixgbevf_q_vector *q_vector = adapter->q_vector[q_idx]; |
| 1843 | |
| 1844 | adapter->q_vector[q_idx] = NULL; |
| 1845 | if (q_idx < napi_vectors) |
| 1846 | netif_napi_del(&q_vector->napi); |
| 1847 | kfree(q_vector); |
| 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | /** |
| 1852 | * ixgbevf_reset_interrupt_capability - Reset MSIX setup |
| 1853 | * @adapter: board private structure |
| 1854 | * |
| 1855 | **/ |
| 1856 | static void ixgbevf_reset_interrupt_capability(struct ixgbevf_adapter *adapter) |
| 1857 | { |
| 1858 | pci_disable_msix(adapter->pdev); |
| 1859 | kfree(adapter->msix_entries); |
| 1860 | adapter->msix_entries = NULL; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | /** |
| 1864 | * ixgbevf_init_interrupt_scheme - Determine if MSIX is supported and init |
| 1865 | * @adapter: board private structure to initialize |
| 1866 | * |
| 1867 | **/ |
| 1868 | static int ixgbevf_init_interrupt_scheme(struct ixgbevf_adapter *adapter) |
| 1869 | { |
| 1870 | int err; |
| 1871 | |
| 1872 | /* Number of supported queues */ |
| 1873 | ixgbevf_set_num_queues(adapter); |
| 1874 | |
| 1875 | err = ixgbevf_set_interrupt_capability(adapter); |
| 1876 | if (err) { |
| 1877 | hw_dbg(&adapter->hw, |
| 1878 | "Unable to setup interrupt capabilities\n"); |
| 1879 | goto err_set_interrupt; |
| 1880 | } |
| 1881 | |
| 1882 | err = ixgbevf_alloc_q_vectors(adapter); |
| 1883 | if (err) { |
| 1884 | hw_dbg(&adapter->hw, "Unable to allocate memory for queue " |
| 1885 | "vectors\n"); |
| 1886 | goto err_alloc_q_vectors; |
| 1887 | } |
| 1888 | |
| 1889 | err = ixgbevf_alloc_queues(adapter); |
| 1890 | if (err) { |
Jeff Kirsher | dbd9636 | 2011-10-21 19:38:18 +0000 | [diff] [blame] | 1891 | pr_err("Unable to allocate memory for queues\n"); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1892 | goto err_alloc_queues; |
| 1893 | } |
| 1894 | |
| 1895 | hw_dbg(&adapter->hw, "Multiqueue %s: Rx Queue count = %u, " |
| 1896 | "Tx Queue count = %u\n", |
| 1897 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 1898 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
| 1899 | |
| 1900 | set_bit(__IXGBEVF_DOWN, &adapter->state); |
| 1901 | |
| 1902 | return 0; |
| 1903 | err_alloc_queues: |
| 1904 | ixgbevf_free_q_vectors(adapter); |
| 1905 | err_alloc_q_vectors: |
| 1906 | ixgbevf_reset_interrupt_capability(adapter); |
| 1907 | err_set_interrupt: |
| 1908 | return err; |
| 1909 | } |
| 1910 | |
| 1911 | /** |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 1912 | * ixgbevf_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 1913 | * @adapter: board private structure to clear interrupt scheme on |
| 1914 | * |
| 1915 | * We go through and clear interrupt specific resources and reset the structure |
| 1916 | * to pre-load conditions |
| 1917 | **/ |
| 1918 | static void ixgbevf_clear_interrupt_scheme(struct ixgbevf_adapter *adapter) |
| 1919 | { |
| 1920 | adapter->num_tx_queues = 0; |
| 1921 | adapter->num_rx_queues = 0; |
| 1922 | |
| 1923 | ixgbevf_free_q_vectors(adapter); |
| 1924 | ixgbevf_reset_interrupt_capability(adapter); |
| 1925 | } |
| 1926 | |
| 1927 | /** |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1928 | * ixgbevf_sw_init - Initialize general software structures |
| 1929 | * (struct ixgbevf_adapter) |
| 1930 | * @adapter: board private structure to initialize |
| 1931 | * |
| 1932 | * ixgbevf_sw_init initializes the Adapter private data structure. |
| 1933 | * Fields are initialized based on PCI device information and |
| 1934 | * OS network device settings (MTU size). |
| 1935 | **/ |
| 1936 | static int __devinit ixgbevf_sw_init(struct ixgbevf_adapter *adapter) |
| 1937 | { |
| 1938 | struct ixgbe_hw *hw = &adapter->hw; |
| 1939 | struct pci_dev *pdev = adapter->pdev; |
| 1940 | int err; |
| 1941 | |
| 1942 | /* PCI config space info */ |
| 1943 | |
| 1944 | hw->vendor_id = pdev->vendor; |
| 1945 | hw->device_id = pdev->device; |
Sergei Shtylyov | ff938e4 | 2011-02-28 11:57:33 -0800 | [diff] [blame] | 1946 | hw->revision_id = pdev->revision; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1947 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 1948 | hw->subsystem_device_id = pdev->subsystem_device; |
| 1949 | |
| 1950 | hw->mbx.ops.init_params(hw); |
| 1951 | hw->mac.max_tx_queues = MAX_TX_QUEUES; |
| 1952 | hw->mac.max_rx_queues = MAX_RX_QUEUES; |
| 1953 | err = hw->mac.ops.reset_hw(hw); |
| 1954 | if (err) { |
| 1955 | dev_info(&pdev->dev, |
| 1956 | "PF still in reset state, assigning new address\n"); |
Danny Kukawka | 1a0d6ae | 2012-02-09 09:48:54 +0000 | [diff] [blame] | 1957 | eth_hw_addr_random(adapter->netdev); |
| 1958 | memcpy(adapter->hw.mac.addr, adapter->netdev->dev_addr, |
| 1959 | adapter->netdev->addr_len); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1960 | } else { |
| 1961 | err = hw->mac.ops.init_hw(hw); |
| 1962 | if (err) { |
Jeff Kirsher | dbd9636 | 2011-10-21 19:38:18 +0000 | [diff] [blame] | 1963 | pr_err("init_shared_code failed: %d\n", err); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1964 | goto out; |
| 1965 | } |
Danny Kukawka | 1a0d6ae | 2012-02-09 09:48:54 +0000 | [diff] [blame] | 1966 | memcpy(adapter->netdev->dev_addr, adapter->hw.mac.addr, |
| 1967 | adapter->netdev->addr_len); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1968 | } |
| 1969 | |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 1970 | /* lock to protect mailbox accesses */ |
| 1971 | spin_lock_init(&adapter->mbx_lock); |
| 1972 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1973 | /* Enable dynamic interrupt throttling rates */ |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 1974 | adapter->rx_itr_setting = 1; |
| 1975 | adapter->tx_itr_setting = 1; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1976 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1977 | /* set default ring sizes */ |
| 1978 | adapter->tx_ring_count = IXGBEVF_DEFAULT_TXD; |
| 1979 | adapter->rx_ring_count = IXGBEVF_DEFAULT_RXD; |
| 1980 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1981 | set_bit(__IXGBEVF_DOWN, &adapter->state); |
Danny Kukawka | 1a0d6ae | 2012-02-09 09:48:54 +0000 | [diff] [blame] | 1982 | return 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1983 | |
| 1984 | out: |
| 1985 | return err; |
| 1986 | } |
| 1987 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 1988 | #define UPDATE_VF_COUNTER_32bit(reg, last_counter, counter) \ |
| 1989 | { \ |
| 1990 | u32 current_counter = IXGBE_READ_REG(hw, reg); \ |
| 1991 | if (current_counter < last_counter) \ |
| 1992 | counter += 0x100000000LL; \ |
| 1993 | last_counter = current_counter; \ |
| 1994 | counter &= 0xFFFFFFFF00000000LL; \ |
| 1995 | counter |= current_counter; \ |
| 1996 | } |
| 1997 | |
| 1998 | #define UPDATE_VF_COUNTER_36bit(reg_lsb, reg_msb, last_counter, counter) \ |
| 1999 | { \ |
| 2000 | u64 current_counter_lsb = IXGBE_READ_REG(hw, reg_lsb); \ |
| 2001 | u64 current_counter_msb = IXGBE_READ_REG(hw, reg_msb); \ |
| 2002 | u64 current_counter = (current_counter_msb << 32) | \ |
| 2003 | current_counter_lsb; \ |
| 2004 | if (current_counter < last_counter) \ |
| 2005 | counter += 0x1000000000LL; \ |
| 2006 | last_counter = current_counter; \ |
| 2007 | counter &= 0xFFFFFFF000000000LL; \ |
| 2008 | counter |= current_counter; \ |
| 2009 | } |
| 2010 | /** |
| 2011 | * ixgbevf_update_stats - Update the board statistics counters. |
| 2012 | * @adapter: board private structure |
| 2013 | **/ |
| 2014 | void ixgbevf_update_stats(struct ixgbevf_adapter *adapter) |
| 2015 | { |
| 2016 | struct ixgbe_hw *hw = &adapter->hw; |
| 2017 | |
| 2018 | UPDATE_VF_COUNTER_32bit(IXGBE_VFGPRC, adapter->stats.last_vfgprc, |
| 2019 | adapter->stats.vfgprc); |
| 2020 | UPDATE_VF_COUNTER_32bit(IXGBE_VFGPTC, adapter->stats.last_vfgptc, |
| 2021 | adapter->stats.vfgptc); |
| 2022 | UPDATE_VF_COUNTER_36bit(IXGBE_VFGORC_LSB, IXGBE_VFGORC_MSB, |
| 2023 | adapter->stats.last_vfgorc, |
| 2024 | adapter->stats.vfgorc); |
| 2025 | UPDATE_VF_COUNTER_36bit(IXGBE_VFGOTC_LSB, IXGBE_VFGOTC_MSB, |
| 2026 | adapter->stats.last_vfgotc, |
| 2027 | adapter->stats.vfgotc); |
| 2028 | UPDATE_VF_COUNTER_32bit(IXGBE_VFMPRC, adapter->stats.last_vfmprc, |
| 2029 | adapter->stats.vfmprc); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | /** |
| 2033 | * ixgbevf_watchdog - Timer Call-back |
| 2034 | * @data: pointer to adapter cast into an unsigned long |
| 2035 | **/ |
| 2036 | static void ixgbevf_watchdog(unsigned long data) |
| 2037 | { |
| 2038 | struct ixgbevf_adapter *adapter = (struct ixgbevf_adapter *)data; |
| 2039 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 2040 | u32 eics = 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2041 | int i; |
| 2042 | |
| 2043 | /* |
| 2044 | * Do the watchdog outside of interrupt context due to the lovely |
| 2045 | * delays that some of the newer hardware requires |
| 2046 | */ |
| 2047 | |
| 2048 | if (test_bit(__IXGBEVF_DOWN, &adapter->state)) |
| 2049 | goto watchdog_short_circuit; |
| 2050 | |
| 2051 | /* get one bit for every active tx/rx interrupt vector */ |
| 2052 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 2053 | struct ixgbevf_q_vector *qv = adapter->q_vector[i]; |
Alexander Duyck | 6b43c44 | 2012-05-11 08:32:45 +0000 | [diff] [blame] | 2054 | if (qv->rx.ring || qv->tx.ring) |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 2055 | eics |= 1 << i; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2056 | } |
| 2057 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 2058 | IXGBE_WRITE_REG(hw, IXGBE_VTEICS, eics); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2059 | |
| 2060 | watchdog_short_circuit: |
| 2061 | schedule_work(&adapter->watchdog_task); |
| 2062 | } |
| 2063 | |
| 2064 | /** |
| 2065 | * ixgbevf_tx_timeout - Respond to a Tx Hang |
| 2066 | * @netdev: network interface device structure |
| 2067 | **/ |
| 2068 | static void ixgbevf_tx_timeout(struct net_device *netdev) |
| 2069 | { |
| 2070 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 2071 | |
| 2072 | /* Do the reset outside of interrupt context */ |
| 2073 | schedule_work(&adapter->reset_task); |
| 2074 | } |
| 2075 | |
| 2076 | static void ixgbevf_reset_task(struct work_struct *work) |
| 2077 | { |
| 2078 | struct ixgbevf_adapter *adapter; |
| 2079 | adapter = container_of(work, struct ixgbevf_adapter, reset_task); |
| 2080 | |
| 2081 | /* If we're already down or resetting, just bail */ |
| 2082 | if (test_bit(__IXGBEVF_DOWN, &adapter->state) || |
| 2083 | test_bit(__IXGBEVF_RESETTING, &adapter->state)) |
| 2084 | return; |
| 2085 | |
| 2086 | adapter->tx_timeout_count++; |
| 2087 | |
| 2088 | ixgbevf_reinit_locked(adapter); |
| 2089 | } |
| 2090 | |
| 2091 | /** |
| 2092 | * ixgbevf_watchdog_task - worker thread to bring link up |
| 2093 | * @work: pointer to work_struct containing our data |
| 2094 | **/ |
| 2095 | static void ixgbevf_watchdog_task(struct work_struct *work) |
| 2096 | { |
| 2097 | struct ixgbevf_adapter *adapter = container_of(work, |
| 2098 | struct ixgbevf_adapter, |
| 2099 | watchdog_task); |
| 2100 | struct net_device *netdev = adapter->netdev; |
| 2101 | struct ixgbe_hw *hw = &adapter->hw; |
| 2102 | u32 link_speed = adapter->link_speed; |
| 2103 | bool link_up = adapter->link_up; |
| 2104 | |
| 2105 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 2106 | |
| 2107 | /* |
| 2108 | * Always check the link on the watchdog because we have |
| 2109 | * no LSC interrupt |
| 2110 | */ |
| 2111 | if (hw->mac.ops.check_link) { |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 2112 | s32 need_reset; |
| 2113 | |
| 2114 | spin_lock(&adapter->mbx_lock); |
| 2115 | |
| 2116 | need_reset = hw->mac.ops.check_link(hw, &link_speed, |
| 2117 | &link_up, false); |
| 2118 | |
| 2119 | spin_unlock(&adapter->mbx_lock); |
| 2120 | |
| 2121 | if (need_reset) { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2122 | adapter->link_up = link_up; |
| 2123 | adapter->link_speed = link_speed; |
Greg Rose | da6b333 | 2010-01-22 22:47:37 +0000 | [diff] [blame] | 2124 | netif_carrier_off(netdev); |
| 2125 | netif_tx_stop_all_queues(netdev); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2126 | schedule_work(&adapter->reset_task); |
| 2127 | goto pf_has_reset; |
| 2128 | } |
| 2129 | } else { |
| 2130 | /* always assume link is up, if no check link |
| 2131 | * function */ |
| 2132 | link_speed = IXGBE_LINK_SPEED_10GB_FULL; |
| 2133 | link_up = true; |
| 2134 | } |
| 2135 | adapter->link_up = link_up; |
| 2136 | adapter->link_speed = link_speed; |
| 2137 | |
| 2138 | if (link_up) { |
| 2139 | if (!netif_carrier_ok(netdev)) { |
Joe Perches | 300bc06 | 2010-03-22 20:08:04 -0700 | [diff] [blame] | 2140 | hw_dbg(&adapter->hw, "NIC Link is Up, %u Gbps\n", |
| 2141 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL) ? |
| 2142 | 10 : 1); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2143 | netif_carrier_on(netdev); |
| 2144 | netif_tx_wake_all_queues(netdev); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2145 | } |
| 2146 | } else { |
| 2147 | adapter->link_up = false; |
| 2148 | adapter->link_speed = 0; |
| 2149 | if (netif_carrier_ok(netdev)) { |
| 2150 | hw_dbg(&adapter->hw, "NIC Link is Down\n"); |
| 2151 | netif_carrier_off(netdev); |
| 2152 | netif_tx_stop_all_queues(netdev); |
| 2153 | } |
| 2154 | } |
| 2155 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2156 | ixgbevf_update_stats(adapter); |
| 2157 | |
Greg Rose | 33bd9f6 | 2010-03-19 02:59:52 +0000 | [diff] [blame] | 2158 | pf_has_reset: |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2159 | /* Reset the timer */ |
| 2160 | if (!test_bit(__IXGBEVF_DOWN, &adapter->state)) |
| 2161 | mod_timer(&adapter->watchdog_timer, |
| 2162 | round_jiffies(jiffies + (2 * HZ))); |
| 2163 | |
| 2164 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 2165 | } |
| 2166 | |
| 2167 | /** |
| 2168 | * ixgbevf_free_tx_resources - Free Tx Resources per Queue |
| 2169 | * @adapter: board private structure |
| 2170 | * @tx_ring: Tx descriptor ring for a specific queue |
| 2171 | * |
| 2172 | * Free all transmit software resources |
| 2173 | **/ |
| 2174 | void ixgbevf_free_tx_resources(struct ixgbevf_adapter *adapter, |
| 2175 | struct ixgbevf_ring *tx_ring) |
| 2176 | { |
| 2177 | struct pci_dev *pdev = adapter->pdev; |
| 2178 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2179 | ixgbevf_clean_tx_ring(adapter, tx_ring); |
| 2180 | |
| 2181 | vfree(tx_ring->tx_buffer_info); |
| 2182 | tx_ring->tx_buffer_info = NULL; |
| 2183 | |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 2184 | dma_free_coherent(&pdev->dev, tx_ring->size, tx_ring->desc, |
| 2185 | tx_ring->dma); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2186 | |
| 2187 | tx_ring->desc = NULL; |
| 2188 | } |
| 2189 | |
| 2190 | /** |
| 2191 | * ixgbevf_free_all_tx_resources - Free Tx Resources for All Queues |
| 2192 | * @adapter: board private structure |
| 2193 | * |
| 2194 | * Free all transmit software resources |
| 2195 | **/ |
| 2196 | static void ixgbevf_free_all_tx_resources(struct ixgbevf_adapter *adapter) |
| 2197 | { |
| 2198 | int i; |
| 2199 | |
| 2200 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2201 | if (adapter->tx_ring[i].desc) |
| 2202 | ixgbevf_free_tx_resources(adapter, |
| 2203 | &adapter->tx_ring[i]); |
| 2204 | |
| 2205 | } |
| 2206 | |
| 2207 | /** |
| 2208 | * ixgbevf_setup_tx_resources - allocate Tx resources (Descriptors) |
| 2209 | * @adapter: board private structure |
| 2210 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
| 2211 | * |
| 2212 | * Return 0 on success, negative on failure |
| 2213 | **/ |
| 2214 | int ixgbevf_setup_tx_resources(struct ixgbevf_adapter *adapter, |
| 2215 | struct ixgbevf_ring *tx_ring) |
| 2216 | { |
| 2217 | struct pci_dev *pdev = adapter->pdev; |
| 2218 | int size; |
| 2219 | |
| 2220 | size = sizeof(struct ixgbevf_tx_buffer) * tx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2221 | tx_ring->tx_buffer_info = vzalloc(size); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2222 | if (!tx_ring->tx_buffer_info) |
| 2223 | goto err; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2224 | |
| 2225 | /* round up to nearest 4K */ |
| 2226 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
| 2227 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
| 2228 | |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 2229 | tx_ring->desc = dma_alloc_coherent(&pdev->dev, tx_ring->size, |
| 2230 | &tx_ring->dma, GFP_KERNEL); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2231 | if (!tx_ring->desc) |
| 2232 | goto err; |
| 2233 | |
| 2234 | tx_ring->next_to_use = 0; |
| 2235 | tx_ring->next_to_clean = 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2236 | return 0; |
| 2237 | |
| 2238 | err: |
| 2239 | vfree(tx_ring->tx_buffer_info); |
| 2240 | tx_ring->tx_buffer_info = NULL; |
| 2241 | hw_dbg(&adapter->hw, "Unable to allocate memory for the transmit " |
| 2242 | "descriptor ring\n"); |
| 2243 | return -ENOMEM; |
| 2244 | } |
| 2245 | |
| 2246 | /** |
| 2247 | * ixgbevf_setup_all_tx_resources - allocate all queues Tx resources |
| 2248 | * @adapter: board private structure |
| 2249 | * |
| 2250 | * If this function returns with an error, then it's possible one or |
| 2251 | * more of the rings is populated (while the rest are not). It is the |
| 2252 | * callers duty to clean those orphaned rings. |
| 2253 | * |
| 2254 | * Return 0 on success, negative on failure |
| 2255 | **/ |
| 2256 | static int ixgbevf_setup_all_tx_resources(struct ixgbevf_adapter *adapter) |
| 2257 | { |
| 2258 | int i, err = 0; |
| 2259 | |
| 2260 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2261 | err = ixgbevf_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 2262 | if (!err) |
| 2263 | continue; |
| 2264 | hw_dbg(&adapter->hw, |
| 2265 | "Allocation for Tx Queue %u failed\n", i); |
| 2266 | break; |
| 2267 | } |
| 2268 | |
| 2269 | return err; |
| 2270 | } |
| 2271 | |
| 2272 | /** |
| 2273 | * ixgbevf_setup_rx_resources - allocate Rx resources (Descriptors) |
| 2274 | * @adapter: board private structure |
| 2275 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 2276 | * |
| 2277 | * Returns 0 on success, negative on failure |
| 2278 | **/ |
| 2279 | int ixgbevf_setup_rx_resources(struct ixgbevf_adapter *adapter, |
| 2280 | struct ixgbevf_ring *rx_ring) |
| 2281 | { |
| 2282 | struct pci_dev *pdev = adapter->pdev; |
| 2283 | int size; |
| 2284 | |
| 2285 | size = sizeof(struct ixgbevf_rx_buffer) * rx_ring->count; |
Eric Dumazet | 89bf67f | 2010-11-22 00:15:06 +0000 | [diff] [blame] | 2286 | rx_ring->rx_buffer_info = vzalloc(size); |
Joe Perches | e404dec | 2012-01-29 12:56:23 +0000 | [diff] [blame] | 2287 | if (!rx_ring->rx_buffer_info) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2288 | goto alloc_failed; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2289 | |
| 2290 | /* Round up to nearest 4K */ |
| 2291 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 2292 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
| 2293 | |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 2294 | rx_ring->desc = dma_alloc_coherent(&pdev->dev, rx_ring->size, |
| 2295 | &rx_ring->dma, GFP_KERNEL); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2296 | |
| 2297 | if (!rx_ring->desc) { |
| 2298 | hw_dbg(&adapter->hw, |
| 2299 | "Unable to allocate memory for " |
| 2300 | "the receive descriptor ring\n"); |
| 2301 | vfree(rx_ring->rx_buffer_info); |
| 2302 | rx_ring->rx_buffer_info = NULL; |
| 2303 | goto alloc_failed; |
| 2304 | } |
| 2305 | |
| 2306 | rx_ring->next_to_clean = 0; |
| 2307 | rx_ring->next_to_use = 0; |
| 2308 | |
| 2309 | return 0; |
| 2310 | alloc_failed: |
| 2311 | return -ENOMEM; |
| 2312 | } |
| 2313 | |
| 2314 | /** |
| 2315 | * ixgbevf_setup_all_rx_resources - allocate all queues Rx resources |
| 2316 | * @adapter: board private structure |
| 2317 | * |
| 2318 | * If this function returns with an error, then it's possible one or |
| 2319 | * more of the rings is populated (while the rest are not). It is the |
| 2320 | * callers duty to clean those orphaned rings. |
| 2321 | * |
| 2322 | * Return 0 on success, negative on failure |
| 2323 | **/ |
| 2324 | static int ixgbevf_setup_all_rx_resources(struct ixgbevf_adapter *adapter) |
| 2325 | { |
| 2326 | int i, err = 0; |
| 2327 | |
| 2328 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2329 | err = ixgbevf_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 2330 | if (!err) |
| 2331 | continue; |
| 2332 | hw_dbg(&adapter->hw, |
| 2333 | "Allocation for Rx Queue %u failed\n", i); |
| 2334 | break; |
| 2335 | } |
| 2336 | return err; |
| 2337 | } |
| 2338 | |
| 2339 | /** |
| 2340 | * ixgbevf_free_rx_resources - Free Rx Resources |
| 2341 | * @adapter: board private structure |
| 2342 | * @rx_ring: ring to clean the resources from |
| 2343 | * |
| 2344 | * Free all receive software resources |
| 2345 | **/ |
| 2346 | void ixgbevf_free_rx_resources(struct ixgbevf_adapter *adapter, |
| 2347 | struct ixgbevf_ring *rx_ring) |
| 2348 | { |
| 2349 | struct pci_dev *pdev = adapter->pdev; |
| 2350 | |
| 2351 | ixgbevf_clean_rx_ring(adapter, rx_ring); |
| 2352 | |
| 2353 | vfree(rx_ring->rx_buffer_info); |
| 2354 | rx_ring->rx_buffer_info = NULL; |
| 2355 | |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 2356 | dma_free_coherent(&pdev->dev, rx_ring->size, rx_ring->desc, |
| 2357 | rx_ring->dma); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2358 | |
| 2359 | rx_ring->desc = NULL; |
| 2360 | } |
| 2361 | |
| 2362 | /** |
| 2363 | * ixgbevf_free_all_rx_resources - Free Rx Resources for All Queues |
| 2364 | * @adapter: board private structure |
| 2365 | * |
| 2366 | * Free all receive software resources |
| 2367 | **/ |
| 2368 | static void ixgbevf_free_all_rx_resources(struct ixgbevf_adapter *adapter) |
| 2369 | { |
| 2370 | int i; |
| 2371 | |
| 2372 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2373 | if (adapter->rx_ring[i].desc) |
| 2374 | ixgbevf_free_rx_resources(adapter, |
| 2375 | &adapter->rx_ring[i]); |
| 2376 | } |
| 2377 | |
| 2378 | /** |
| 2379 | * ixgbevf_open - Called when a network interface is made active |
| 2380 | * @netdev: network interface device structure |
| 2381 | * |
| 2382 | * Returns 0 on success, negative value on failure |
| 2383 | * |
| 2384 | * The open entry point is called when a network interface is made |
| 2385 | * active by the system (IFF_UP). At this point all resources needed |
| 2386 | * for transmit and receive operations are allocated, the interrupt |
| 2387 | * handler is registered with the OS, the watchdog timer is started, |
| 2388 | * and the stack is notified that the interface is ready. |
| 2389 | **/ |
| 2390 | static int ixgbevf_open(struct net_device *netdev) |
| 2391 | { |
| 2392 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 2393 | struct ixgbe_hw *hw = &adapter->hw; |
| 2394 | int err; |
| 2395 | |
| 2396 | /* disallow open during test */ |
| 2397 | if (test_bit(__IXGBEVF_TESTING, &adapter->state)) |
| 2398 | return -EBUSY; |
| 2399 | |
| 2400 | if (hw->adapter_stopped) { |
| 2401 | ixgbevf_reset(adapter); |
| 2402 | /* if adapter is still stopped then PF isn't up and |
| 2403 | * the vf can't start. */ |
| 2404 | if (hw->adapter_stopped) { |
| 2405 | err = IXGBE_ERR_MBX; |
Jeff Kirsher | dbd9636 | 2011-10-21 19:38:18 +0000 | [diff] [blame] | 2406 | pr_err("Unable to start - perhaps the PF Driver isn't " |
| 2407 | "up yet\n"); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2408 | goto err_setup_reset; |
| 2409 | } |
| 2410 | } |
| 2411 | |
Alexander Duyck | 3118678 | 2012-07-20 08:09:58 +0000 | [diff] [blame] | 2412 | ixgbevf_negotiate_api(adapter); |
| 2413 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2414 | /* allocate transmit descriptors */ |
| 2415 | err = ixgbevf_setup_all_tx_resources(adapter); |
| 2416 | if (err) |
| 2417 | goto err_setup_tx; |
| 2418 | |
| 2419 | /* allocate receive descriptors */ |
| 2420 | err = ixgbevf_setup_all_rx_resources(adapter); |
| 2421 | if (err) |
| 2422 | goto err_setup_rx; |
| 2423 | |
| 2424 | ixgbevf_configure(adapter); |
| 2425 | |
| 2426 | /* |
| 2427 | * Map the Tx/Rx rings to the vectors we were allotted. |
| 2428 | * if request_irq will be called in this function map_rings |
| 2429 | * must be called *before* up_complete |
| 2430 | */ |
| 2431 | ixgbevf_map_rings_to_vectors(adapter); |
| 2432 | |
Greg Rose | 795180d | 2012-04-17 04:29:34 +0000 | [diff] [blame] | 2433 | ixgbevf_up_complete(adapter); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2434 | |
| 2435 | /* clear any pending interrupts, may auto mask */ |
| 2436 | IXGBE_READ_REG(hw, IXGBE_VTEICR); |
| 2437 | err = ixgbevf_request_irq(adapter); |
| 2438 | if (err) |
| 2439 | goto err_req_irq; |
| 2440 | |
Alexander Duyck | 5f3600e | 2012-05-11 08:32:55 +0000 | [diff] [blame] | 2441 | ixgbevf_irq_enable(adapter); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2442 | |
| 2443 | return 0; |
| 2444 | |
| 2445 | err_req_irq: |
| 2446 | ixgbevf_down(adapter); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2447 | ixgbevf_free_irq(adapter); |
| 2448 | err_setup_rx: |
| 2449 | ixgbevf_free_all_rx_resources(adapter); |
| 2450 | err_setup_tx: |
| 2451 | ixgbevf_free_all_tx_resources(adapter); |
| 2452 | ixgbevf_reset(adapter); |
| 2453 | |
| 2454 | err_setup_reset: |
| 2455 | |
| 2456 | return err; |
| 2457 | } |
| 2458 | |
| 2459 | /** |
| 2460 | * ixgbevf_close - Disables a network interface |
| 2461 | * @netdev: network interface device structure |
| 2462 | * |
| 2463 | * Returns 0, this is not allowed to fail |
| 2464 | * |
| 2465 | * The close entry point is called when an interface is de-activated |
| 2466 | * by the OS. The hardware is still under the drivers control, but |
| 2467 | * needs to be disabled. A global MAC reset is issued to stop the |
| 2468 | * hardware, and all transmit and receive resources are freed. |
| 2469 | **/ |
| 2470 | static int ixgbevf_close(struct net_device *netdev) |
| 2471 | { |
| 2472 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 2473 | |
| 2474 | ixgbevf_down(adapter); |
| 2475 | ixgbevf_free_irq(adapter); |
| 2476 | |
| 2477 | ixgbevf_free_all_tx_resources(adapter); |
| 2478 | ixgbevf_free_all_rx_resources(adapter); |
| 2479 | |
| 2480 | return 0; |
| 2481 | } |
| 2482 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2483 | static void ixgbevf_tx_ctxtdesc(struct ixgbevf_ring *tx_ring, |
| 2484 | u32 vlan_macip_lens, u32 type_tucmd, |
| 2485 | u32 mss_l4len_idx) |
| 2486 | { |
| 2487 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 2488 | u16 i = tx_ring->next_to_use; |
| 2489 | |
| 2490 | context_desc = IXGBEVF_TX_CTXTDESC(tx_ring, i); |
| 2491 | |
| 2492 | i++; |
| 2493 | tx_ring->next_to_use = (i < tx_ring->count) ? i : 0; |
| 2494 | |
| 2495 | /* set bits to identify this as an advanced context descriptor */ |
| 2496 | type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT; |
| 2497 | |
| 2498 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 2499 | context_desc->seqnum_seed = 0; |
| 2500 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); |
| 2501 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 2502 | } |
| 2503 | |
| 2504 | static int ixgbevf_tso(struct ixgbevf_ring *tx_ring, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2505 | struct sk_buff *skb, u32 tx_flags, u8 *hdr_len) |
| 2506 | { |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2507 | u32 vlan_macip_lens, type_tucmd; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2508 | u32 mss_l4len_idx, l4len; |
| 2509 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2510 | if (!skb_is_gso(skb)) |
| 2511 | return 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2512 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2513 | if (skb_header_cloned(skb)) { |
| 2514 | int err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 2515 | if (err) |
| 2516 | return err; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2517 | } |
| 2518 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2519 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
| 2520 | type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 2521 | |
| 2522 | if (skb->protocol == htons(ETH_P_IP)) { |
| 2523 | struct iphdr *iph = ip_hdr(skb); |
| 2524 | iph->tot_len = 0; |
| 2525 | iph->check = 0; |
| 2526 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
| 2527 | iph->daddr, 0, |
| 2528 | IPPROTO_TCP, |
| 2529 | 0); |
| 2530 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 2531 | } else if (skb_is_gso_v6(skb)) { |
| 2532 | ipv6_hdr(skb)->payload_len = 0; |
| 2533 | tcp_hdr(skb)->check = |
| 2534 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
| 2535 | &ipv6_hdr(skb)->daddr, |
| 2536 | 0, IPPROTO_TCP, 0); |
| 2537 | } |
| 2538 | |
| 2539 | /* compute header lengths */ |
| 2540 | l4len = tcp_hdrlen(skb); |
| 2541 | *hdr_len += l4len; |
| 2542 | *hdr_len = skb_transport_offset(skb) + l4len; |
| 2543 | |
| 2544 | /* mss_l4len_id: use 1 as index for TSO */ |
| 2545 | mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT; |
| 2546 | mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT; |
| 2547 | mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT; |
| 2548 | |
| 2549 | /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */ |
| 2550 | vlan_macip_lens = skb_network_header_len(skb); |
| 2551 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 2552 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 2553 | |
| 2554 | ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens, |
| 2555 | type_tucmd, mss_l4len_idx); |
| 2556 | |
| 2557 | return 1; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2558 | } |
| 2559 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2560 | static bool ixgbevf_tx_csum(struct ixgbevf_ring *tx_ring, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2561 | struct sk_buff *skb, u32 tx_flags) |
| 2562 | { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2563 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2564 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2565 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2566 | u32 vlan_macip_lens = 0; |
| 2567 | u32 mss_l4len_idx = 0; |
| 2568 | u32 type_tucmd = 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2569 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2570 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 2571 | u8 l4_hdr = 0; |
| 2572 | switch (skb->protocol) { |
| 2573 | case __constant_htons(ETH_P_IP): |
| 2574 | vlan_macip_lens |= skb_network_header_len(skb); |
| 2575 | type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 2576 | l4_hdr = ip_hdr(skb)->protocol; |
| 2577 | break; |
| 2578 | case __constant_htons(ETH_P_IPV6): |
| 2579 | vlan_macip_lens |= skb_network_header_len(skb); |
| 2580 | l4_hdr = ipv6_hdr(skb)->nexthdr; |
| 2581 | break; |
| 2582 | default: |
| 2583 | if (unlikely(net_ratelimit())) { |
| 2584 | dev_warn(tx_ring->dev, |
| 2585 | "partial checksum but proto=%x!\n", |
| 2586 | skb->protocol); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2587 | } |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2588 | break; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2589 | } |
| 2590 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2591 | switch (l4_hdr) { |
| 2592 | case IPPROTO_TCP: |
| 2593 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 2594 | mss_l4len_idx = tcp_hdrlen(skb) << |
| 2595 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 2596 | break; |
| 2597 | case IPPROTO_SCTP: |
| 2598 | type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
| 2599 | mss_l4len_idx = sizeof(struct sctphdr) << |
| 2600 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 2601 | break; |
| 2602 | case IPPROTO_UDP: |
| 2603 | mss_l4len_idx = sizeof(struct udphdr) << |
| 2604 | IXGBE_ADVTXD_L4LEN_SHIFT; |
| 2605 | break; |
| 2606 | default: |
| 2607 | if (unlikely(net_ratelimit())) { |
| 2608 | dev_warn(tx_ring->dev, |
| 2609 | "partial checksum but l4 proto=%x!\n", |
| 2610 | l4_hdr); |
| 2611 | } |
| 2612 | break; |
| 2613 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2614 | } |
| 2615 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2616 | /* vlan_macip_lens: MACLEN, VLAN tag */ |
| 2617 | vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT; |
| 2618 | vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK; |
| 2619 | |
| 2620 | ixgbevf_tx_ctxtdesc(tx_ring, vlan_macip_lens, |
| 2621 | type_tucmd, mss_l4len_idx); |
| 2622 | |
| 2623 | return (skb->ip_summed == CHECKSUM_PARTIAL); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2624 | } |
| 2625 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2626 | static int ixgbevf_tx_map(struct ixgbevf_ring *tx_ring, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2627 | struct sk_buff *skb, u32 tx_flags, |
| 2628 | unsigned int first) |
| 2629 | { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2630 | struct ixgbevf_tx_buffer *tx_buffer_info; |
| 2631 | unsigned int len; |
| 2632 | unsigned int total = skb->len; |
Kulikov Vasiliy | 2540ddb | 2010-07-15 08:45:57 +0000 | [diff] [blame] | 2633 | unsigned int offset = 0, size; |
| 2634 | int count = 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2635 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 2636 | unsigned int f; |
Greg Rose | 65deeed | 2010-03-24 09:35:42 +0000 | [diff] [blame] | 2637 | int i; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2638 | |
| 2639 | i = tx_ring->next_to_use; |
| 2640 | |
| 2641 | len = min(skb_headlen(skb), total); |
| 2642 | while (len) { |
| 2643 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 2644 | size = min(len, (unsigned int)IXGBE_MAX_DATA_PER_TXD); |
| 2645 | |
| 2646 | tx_buffer_info->length = size; |
| 2647 | tx_buffer_info->mapped_as_page = false; |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2648 | tx_buffer_info->dma = dma_map_single(tx_ring->dev, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2649 | skb->data + offset, |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 2650 | size, DMA_TO_DEVICE); |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2651 | if (dma_mapping_error(tx_ring->dev, tx_buffer_info->dma)) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2652 | goto dma_error; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2653 | tx_buffer_info->next_to_watch = i; |
| 2654 | |
| 2655 | len -= size; |
| 2656 | total -= size; |
| 2657 | offset += size; |
| 2658 | count++; |
| 2659 | i++; |
| 2660 | if (i == tx_ring->count) |
| 2661 | i = 0; |
| 2662 | } |
| 2663 | |
| 2664 | for (f = 0; f < nr_frags; f++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2665 | const struct skb_frag_struct *frag; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2666 | |
| 2667 | frag = &skb_shinfo(skb)->frags[f]; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2668 | len = min((unsigned int)skb_frag_size(frag), total); |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 2669 | offset = 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2670 | |
| 2671 | while (len) { |
| 2672 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 2673 | size = min(len, (unsigned int)IXGBE_MAX_DATA_PER_TXD); |
| 2674 | |
| 2675 | tx_buffer_info->length = size; |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 2676 | tx_buffer_info->dma = |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2677 | skb_frag_dma_map(tx_ring->dev, frag, |
Ian Campbell | 877749b | 2011-08-29 23:18:26 +0000 | [diff] [blame] | 2678 | offset, size, DMA_TO_DEVICE); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2679 | tx_buffer_info->mapped_as_page = true; |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2680 | if (dma_mapping_error(tx_ring->dev, |
| 2681 | tx_buffer_info->dma)) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2682 | goto dma_error; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2683 | tx_buffer_info->next_to_watch = i; |
| 2684 | |
| 2685 | len -= size; |
| 2686 | total -= size; |
| 2687 | offset += size; |
| 2688 | count++; |
| 2689 | i++; |
| 2690 | if (i == tx_ring->count) |
| 2691 | i = 0; |
| 2692 | } |
| 2693 | if (total == 0) |
| 2694 | break; |
| 2695 | } |
| 2696 | |
| 2697 | if (i == 0) |
| 2698 | i = tx_ring->count - 1; |
| 2699 | else |
| 2700 | i = i - 1; |
| 2701 | tx_ring->tx_buffer_info[i].skb = skb; |
| 2702 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2703 | tx_ring->tx_buffer_info[first].time_stamp = jiffies; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2704 | |
| 2705 | return count; |
| 2706 | |
| 2707 | dma_error: |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2708 | dev_err(tx_ring->dev, "TX DMA map failed\n"); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2709 | |
| 2710 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ |
| 2711 | tx_buffer_info->dma = 0; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2712 | tx_buffer_info->next_to_watch = 0; |
| 2713 | count--; |
| 2714 | |
| 2715 | /* clear timestamp and dma mappings for remaining portion of packet */ |
| 2716 | while (count >= 0) { |
| 2717 | count--; |
| 2718 | i--; |
| 2719 | if (i < 0) |
| 2720 | i += tx_ring->count; |
| 2721 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2722 | ixgbevf_unmap_and_free_tx_resource(tx_ring, tx_buffer_info); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | return count; |
| 2726 | } |
| 2727 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2728 | static void ixgbevf_tx_queue(struct ixgbevf_ring *tx_ring, int tx_flags, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2729 | int count, u32 paylen, u8 hdr_len) |
| 2730 | { |
| 2731 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 2732 | struct ixgbevf_tx_buffer *tx_buffer_info; |
| 2733 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 2734 | unsigned int i; |
| 2735 | |
| 2736 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 2737 | |
| 2738 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 2739 | |
| 2740 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 2741 | |
| 2742 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 2743 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 2744 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2745 | if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 2746 | olinfo_status |= IXGBE_ADVTXD_POPTS_TXSM; |
| 2747 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2748 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 2749 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 2750 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2751 | /* use index 1 context for tso */ |
| 2752 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 2753 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2754 | olinfo_status |= IXGBE_ADVTXD_POPTS_IXSM; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2755 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2756 | } |
| 2757 | |
| 2758 | /* |
| 2759 | * Check Context must be set if Tx switch is enabled, which it |
| 2760 | * always is for case where virtual functions are running |
| 2761 | */ |
| 2762 | olinfo_status |= IXGBE_ADVTXD_CC; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2763 | |
| 2764 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 2765 | |
| 2766 | i = tx_ring->next_to_use; |
| 2767 | while (count--) { |
| 2768 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Alexander Duyck | 908421f | 2012-05-11 08:33:00 +0000 | [diff] [blame] | 2769 | tx_desc = IXGBEVF_TX_DESC(tx_ring, i); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2770 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 2771 | tx_desc->read.cmd_type_len = |
| 2772 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
| 2773 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
| 2774 | i++; |
| 2775 | if (i == tx_ring->count) |
| 2776 | i = 0; |
| 2777 | } |
| 2778 | |
| 2779 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 2780 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2781 | tx_ring->next_to_use = i; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 2784 | static int __ixgbevf_maybe_stop_tx(struct ixgbevf_ring *tx_ring, int size) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2785 | { |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 2786 | struct ixgbevf_adapter *adapter = netdev_priv(tx_ring->netdev); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2787 | |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 2788 | netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2789 | /* Herbert's original patch had: |
| 2790 | * smp_mb__after_netif_stop_queue(); |
| 2791 | * but since that doesn't exist yet, just open code it. */ |
| 2792 | smp_mb(); |
| 2793 | |
| 2794 | /* We need to check again in a case another CPU has just |
| 2795 | * made room available. */ |
| 2796 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 2797 | return -EBUSY; |
| 2798 | |
| 2799 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 2800 | netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2801 | ++adapter->restart_queue; |
| 2802 | return 0; |
| 2803 | } |
| 2804 | |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 2805 | static int ixgbevf_maybe_stop_tx(struct ixgbevf_ring *tx_ring, int size) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2806 | { |
| 2807 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 2808 | return 0; |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 2809 | return __ixgbevf_maybe_stop_tx(tx_ring, size); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2810 | } |
| 2811 | |
| 2812 | static int ixgbevf_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 2813 | { |
| 2814 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 2815 | struct ixgbevf_ring *tx_ring; |
| 2816 | unsigned int first; |
| 2817 | unsigned int tx_flags = 0; |
| 2818 | u8 hdr_len = 0; |
| 2819 | int r_idx = 0, tso; |
Alexander Duyck | 3595990 | 2012-05-11 08:32:40 +0000 | [diff] [blame] | 2820 | u16 count = TXD_USE_COUNT(skb_headlen(skb)); |
| 2821 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 2822 | unsigned short f; |
| 2823 | #endif |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2824 | |
| 2825 | tx_ring = &adapter->tx_ring[r_idx]; |
| 2826 | |
Alexander Duyck | 3595990 | 2012-05-11 08:32:40 +0000 | [diff] [blame] | 2827 | /* |
| 2828 | * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD, |
| 2829 | * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD, |
| 2830 | * + 2 desc gap to keep tail from touching head, |
| 2831 | * + 1 desc for context descriptor, |
| 2832 | * otherwise try next time |
| 2833 | */ |
| 2834 | #if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD |
| 2835 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
| 2836 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 2837 | #else |
| 2838 | count += skb_shinfo(skb)->nr_frags; |
| 2839 | #endif |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 2840 | if (ixgbevf_maybe_stop_tx(tx_ring, count + 3)) { |
Alexander Duyck | 3595990 | 2012-05-11 08:32:40 +0000 | [diff] [blame] | 2841 | adapter->tx_busy++; |
| 2842 | return NETDEV_TX_BUSY; |
| 2843 | } |
| 2844 | |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 2845 | if (vlan_tx_tag_present(skb)) { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2846 | tx_flags |= vlan_tx_tag_get(skb); |
| 2847 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 2848 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 2849 | } |
| 2850 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2851 | first = tx_ring->next_to_use; |
| 2852 | |
| 2853 | if (skb->protocol == htons(ETH_P_IP)) |
| 2854 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2855 | tso = ixgbevf_tso(tx_ring, skb, tx_flags, &hdr_len); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2856 | if (tso < 0) { |
| 2857 | dev_kfree_skb_any(skb); |
| 2858 | return NETDEV_TX_OK; |
| 2859 | } |
| 2860 | |
| 2861 | if (tso) |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2862 | tx_flags |= IXGBE_TX_FLAGS_TSO | IXGBE_TX_FLAGS_CSUM; |
| 2863 | else if (ixgbevf_tx_csum(tx_ring, skb, tx_flags)) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2864 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 2865 | |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2866 | ixgbevf_tx_queue(tx_ring, tx_flags, |
| 2867 | ixgbevf_tx_map(tx_ring, skb, tx_flags, first), |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2868 | skb->len, hdr_len); |
Alexander Duyck | 70a10e2 | 2012-05-11 08:33:21 +0000 | [diff] [blame] | 2869 | /* |
| 2870 | * Force memory writes to complete before letting h/w |
| 2871 | * know there are new descriptors to fetch. (Only |
| 2872 | * applicable for weak-ordered memory model archs, |
| 2873 | * such as IA-64). |
| 2874 | */ |
| 2875 | wmb(); |
| 2876 | |
| 2877 | writel(tx_ring->next_to_use, adapter->hw.hw_addr + tx_ring->tail); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2878 | |
Alexander Duyck | fb40195 | 2012-05-11 08:33:16 +0000 | [diff] [blame] | 2879 | ixgbevf_maybe_stop_tx(tx_ring, DESC_NEEDED); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2880 | |
| 2881 | return NETDEV_TX_OK; |
| 2882 | } |
| 2883 | |
| 2884 | /** |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2885 | * ixgbevf_set_mac - Change the Ethernet Address of the NIC |
| 2886 | * @netdev: network interface device structure |
| 2887 | * @p: pointer to an address structure |
| 2888 | * |
| 2889 | * Returns 0 on success, negative on failure |
| 2890 | **/ |
| 2891 | static int ixgbevf_set_mac(struct net_device *netdev, void *p) |
| 2892 | { |
| 2893 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 2894 | struct ixgbe_hw *hw = &adapter->hw; |
| 2895 | struct sockaddr *addr = p; |
| 2896 | |
| 2897 | if (!is_valid_ether_addr(addr->sa_data)) |
| 2898 | return -EADDRNOTAVAIL; |
| 2899 | |
| 2900 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 2901 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
| 2902 | |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 2903 | spin_lock(&adapter->mbx_lock); |
| 2904 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2905 | if (hw->mac.ops.set_rar) |
| 2906 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0); |
| 2907 | |
Alexander Duyck | 1c55ed7 | 2012-05-11 08:33:06 +0000 | [diff] [blame] | 2908 | spin_unlock(&adapter->mbx_lock); |
| 2909 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2910 | return 0; |
| 2911 | } |
| 2912 | |
| 2913 | /** |
| 2914 | * ixgbevf_change_mtu - Change the Maximum Transfer Unit |
| 2915 | * @netdev: network interface device structure |
| 2916 | * @new_mtu: new value for maximum frame size |
| 2917 | * |
| 2918 | * Returns 0 on success, negative on failure |
| 2919 | **/ |
| 2920 | static int ixgbevf_change_mtu(struct net_device *netdev, int new_mtu) |
| 2921 | { |
| 2922 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 2923 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
Greg Rose | 69bfbec | 2011-01-26 01:06:12 +0000 | [diff] [blame] | 2924 | int max_possible_frame = MAXIMUM_ETHERNET_VLAN_SIZE; |
Greg Rose | 69bfbec | 2011-01-26 01:06:12 +0000 | [diff] [blame] | 2925 | |
| 2926 | if (adapter->hw.mac.type == ixgbe_mac_X540_vf) |
| 2927 | max_possible_frame = IXGBE_MAX_JUMBO_FRAME_SIZE; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2928 | |
| 2929 | /* MTU < 68 is an error and causes problems on some kernels */ |
Greg Rose | 69bfbec | 2011-01-26 01:06:12 +0000 | [diff] [blame] | 2930 | if ((new_mtu < 68) || (max_frame > max_possible_frame)) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2931 | return -EINVAL; |
| 2932 | |
| 2933 | hw_dbg(&adapter->hw, "changing MTU from %d to %d\n", |
| 2934 | netdev->mtu, new_mtu); |
| 2935 | /* must set new MTU before calling down or up */ |
| 2936 | netdev->mtu = new_mtu; |
| 2937 | |
| 2938 | if (netif_running(netdev)) |
| 2939 | ixgbevf_reinit_locked(adapter); |
| 2940 | |
| 2941 | return 0; |
| 2942 | } |
| 2943 | |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 2944 | static int ixgbevf_suspend(struct pci_dev *pdev, pm_message_t state) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2945 | { |
| 2946 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 2947 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 2948 | #ifdef CONFIG_PM |
| 2949 | int retval = 0; |
| 2950 | #endif |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2951 | |
| 2952 | netif_device_detach(netdev); |
| 2953 | |
| 2954 | if (netif_running(netdev)) { |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 2955 | rtnl_lock(); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2956 | ixgbevf_down(adapter); |
| 2957 | ixgbevf_free_irq(adapter); |
| 2958 | ixgbevf_free_all_tx_resources(adapter); |
| 2959 | ixgbevf_free_all_rx_resources(adapter); |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 2960 | rtnl_unlock(); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2961 | } |
| 2962 | |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 2963 | ixgbevf_clear_interrupt_scheme(adapter); |
| 2964 | |
| 2965 | #ifdef CONFIG_PM |
| 2966 | retval = pci_save_state(pdev); |
| 2967 | if (retval) |
| 2968 | return retval; |
| 2969 | |
| 2970 | #endif |
| 2971 | pci_disable_device(pdev); |
| 2972 | |
| 2973 | return 0; |
| 2974 | } |
| 2975 | |
| 2976 | #ifdef CONFIG_PM |
| 2977 | static int ixgbevf_resume(struct pci_dev *pdev) |
| 2978 | { |
| 2979 | struct ixgbevf_adapter *adapter = pci_get_drvdata(pdev); |
| 2980 | struct net_device *netdev = adapter->netdev; |
| 2981 | u32 err; |
| 2982 | |
| 2983 | pci_set_power_state(pdev, PCI_D0); |
| 2984 | pci_restore_state(pdev); |
| 2985 | /* |
| 2986 | * pci_restore_state clears dev->state_saved so call |
| 2987 | * pci_save_state to restore it. |
| 2988 | */ |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2989 | pci_save_state(pdev); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 2990 | |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 2991 | err = pci_enable_device_mem(pdev); |
| 2992 | if (err) { |
| 2993 | dev_err(&pdev->dev, "Cannot enable PCI device from suspend\n"); |
| 2994 | return err; |
| 2995 | } |
| 2996 | pci_set_master(pdev); |
| 2997 | |
| 2998 | rtnl_lock(); |
| 2999 | err = ixgbevf_init_interrupt_scheme(adapter); |
| 3000 | rtnl_unlock(); |
| 3001 | if (err) { |
| 3002 | dev_err(&pdev->dev, "Cannot initialize interrupts\n"); |
| 3003 | return err; |
| 3004 | } |
| 3005 | |
| 3006 | ixgbevf_reset(adapter); |
| 3007 | |
| 3008 | if (netif_running(netdev)) { |
| 3009 | err = ixgbevf_open(netdev); |
| 3010 | if (err) |
| 3011 | return err; |
| 3012 | } |
| 3013 | |
| 3014 | netif_device_attach(netdev); |
| 3015 | |
| 3016 | return err; |
| 3017 | } |
| 3018 | |
| 3019 | #endif /* CONFIG_PM */ |
| 3020 | static void ixgbevf_shutdown(struct pci_dev *pdev) |
| 3021 | { |
| 3022 | ixgbevf_suspend(pdev, PMSG_SUSPEND); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3023 | } |
| 3024 | |
Eric Dumazet | 4197aa7 | 2011-06-22 05:01:35 +0000 | [diff] [blame] | 3025 | static struct rtnl_link_stats64 *ixgbevf_get_stats(struct net_device *netdev, |
| 3026 | struct rtnl_link_stats64 *stats) |
| 3027 | { |
| 3028 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 3029 | unsigned int start; |
| 3030 | u64 bytes, packets; |
| 3031 | const struct ixgbevf_ring *ring; |
| 3032 | int i; |
| 3033 | |
| 3034 | ixgbevf_update_stats(adapter); |
| 3035 | |
| 3036 | stats->multicast = adapter->stats.vfmprc - adapter->stats.base_vfmprc; |
| 3037 | |
| 3038 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3039 | ring = &adapter->rx_ring[i]; |
| 3040 | do { |
| 3041 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 3042 | bytes = ring->total_bytes; |
| 3043 | packets = ring->total_packets; |
| 3044 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 3045 | stats->rx_bytes += bytes; |
| 3046 | stats->rx_packets += packets; |
| 3047 | } |
| 3048 | |
| 3049 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3050 | ring = &adapter->tx_ring[i]; |
| 3051 | do { |
| 3052 | start = u64_stats_fetch_begin_bh(&ring->syncp); |
| 3053 | bytes = ring->total_bytes; |
| 3054 | packets = ring->total_packets; |
| 3055 | } while (u64_stats_fetch_retry_bh(&ring->syncp, start)); |
| 3056 | stats->tx_bytes += bytes; |
| 3057 | stats->tx_packets += packets; |
| 3058 | } |
| 3059 | |
| 3060 | return stats; |
| 3061 | } |
| 3062 | |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 3063 | static const struct net_device_ops ixgbevf_netdev_ops = { |
Stephen Hemminger | c12db76 | 2011-06-09 02:58:39 +0000 | [diff] [blame] | 3064 | .ndo_open = ixgbevf_open, |
| 3065 | .ndo_stop = ixgbevf_close, |
| 3066 | .ndo_start_xmit = ixgbevf_xmit_frame, |
| 3067 | .ndo_set_rx_mode = ixgbevf_set_rx_mode, |
Eric Dumazet | 4197aa7 | 2011-06-22 05:01:35 +0000 | [diff] [blame] | 3068 | .ndo_get_stats64 = ixgbevf_get_stats, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3069 | .ndo_validate_addr = eth_validate_addr, |
Stephen Hemminger | c12db76 | 2011-06-09 02:58:39 +0000 | [diff] [blame] | 3070 | .ndo_set_mac_address = ixgbevf_set_mac, |
| 3071 | .ndo_change_mtu = ixgbevf_change_mtu, |
| 3072 | .ndo_tx_timeout = ixgbevf_tx_timeout, |
Stephen Hemminger | c12db76 | 2011-06-09 02:58:39 +0000 | [diff] [blame] | 3073 | .ndo_vlan_rx_add_vid = ixgbevf_vlan_rx_add_vid, |
| 3074 | .ndo_vlan_rx_kill_vid = ixgbevf_vlan_rx_kill_vid, |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3075 | }; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3076 | |
| 3077 | static void ixgbevf_assign_netdev_ops(struct net_device *dev) |
| 3078 | { |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 3079 | dev->netdev_ops = &ixgbevf_netdev_ops; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3080 | ixgbevf_set_ethtool_ops(dev); |
| 3081 | dev->watchdog_timeo = 5 * HZ; |
| 3082 | } |
| 3083 | |
| 3084 | /** |
| 3085 | * ixgbevf_probe - Device Initialization Routine |
| 3086 | * @pdev: PCI device information struct |
| 3087 | * @ent: entry in ixgbevf_pci_tbl |
| 3088 | * |
| 3089 | * Returns 0 on success, negative on failure |
| 3090 | * |
| 3091 | * ixgbevf_probe initializes an adapter identified by a pci_dev structure. |
| 3092 | * The OS initialization, configuring of the adapter private structure, |
| 3093 | * and a hardware reset occur. |
| 3094 | **/ |
| 3095 | static int __devinit ixgbevf_probe(struct pci_dev *pdev, |
| 3096 | const struct pci_device_id *ent) |
| 3097 | { |
| 3098 | struct net_device *netdev; |
| 3099 | struct ixgbevf_adapter *adapter = NULL; |
| 3100 | struct ixgbe_hw *hw = NULL; |
| 3101 | const struct ixgbevf_info *ii = ixgbevf_info_tbl[ent->driver_data]; |
| 3102 | static int cards_found; |
| 3103 | int err, pci_using_dac; |
| 3104 | |
| 3105 | err = pci_enable_device(pdev); |
| 3106 | if (err) |
| 3107 | return err; |
| 3108 | |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 3109 | if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) && |
| 3110 | !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) { |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3111 | pci_using_dac = 1; |
| 3112 | } else { |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 3113 | err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32)); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3114 | if (err) { |
Nick Nunley | 2a1f879 | 2010-04-27 13:10:50 +0000 | [diff] [blame] | 3115 | err = dma_set_coherent_mask(&pdev->dev, |
| 3116 | DMA_BIT_MASK(32)); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3117 | if (err) { |
| 3118 | dev_err(&pdev->dev, "No usable DMA " |
| 3119 | "configuration, aborting\n"); |
| 3120 | goto err_dma; |
| 3121 | } |
| 3122 | } |
| 3123 | pci_using_dac = 0; |
| 3124 | } |
| 3125 | |
| 3126 | err = pci_request_regions(pdev, ixgbevf_driver_name); |
| 3127 | if (err) { |
| 3128 | dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err); |
| 3129 | goto err_pci_reg; |
| 3130 | } |
| 3131 | |
| 3132 | pci_set_master(pdev); |
| 3133 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3134 | netdev = alloc_etherdev_mq(sizeof(struct ixgbevf_adapter), |
| 3135 | MAX_TX_QUEUES); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3136 | if (!netdev) { |
| 3137 | err = -ENOMEM; |
| 3138 | goto err_alloc_etherdev; |
| 3139 | } |
| 3140 | |
| 3141 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 3142 | |
| 3143 | pci_set_drvdata(pdev, netdev); |
| 3144 | adapter = netdev_priv(netdev); |
| 3145 | |
| 3146 | adapter->netdev = netdev; |
| 3147 | adapter->pdev = pdev; |
| 3148 | hw = &adapter->hw; |
| 3149 | hw->back = adapter; |
stephen hemminger | b3f4d59 | 2012-03-13 06:04:20 +0000 | [diff] [blame] | 3150 | adapter->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3151 | |
| 3152 | /* |
| 3153 | * call save state here in standalone driver because it relies on |
| 3154 | * adapter struct to exist, and needs to call netdev_priv |
| 3155 | */ |
| 3156 | pci_save_state(pdev); |
| 3157 | |
| 3158 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 3159 | pci_resource_len(pdev, 0)); |
| 3160 | if (!hw->hw_addr) { |
| 3161 | err = -EIO; |
| 3162 | goto err_ioremap; |
| 3163 | } |
| 3164 | |
| 3165 | ixgbevf_assign_netdev_ops(netdev); |
| 3166 | |
| 3167 | adapter->bd_number = cards_found; |
| 3168 | |
| 3169 | /* Setup hw api */ |
| 3170 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
| 3171 | hw->mac.type = ii->mac; |
| 3172 | |
| 3173 | memcpy(&hw->mbx.ops, &ixgbevf_mbx_ops, |
Greg Rose | f416dfc | 2011-06-08 07:32:38 +0000 | [diff] [blame] | 3174 | sizeof(struct ixgbe_mbx_operations)); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3175 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3176 | /* setup the private structure */ |
| 3177 | err = ixgbevf_sw_init(adapter); |
Danny Kukawka | 1a0d6ae | 2012-02-09 09:48:54 +0000 | [diff] [blame] | 3178 | if (err) |
| 3179 | goto err_sw_init; |
| 3180 | |
| 3181 | /* The HW MAC address was set and/or determined in sw_init */ |
| 3182 | memcpy(netdev->perm_addr, adapter->hw.mac.addr, netdev->addr_len); |
| 3183 | |
| 3184 | if (!is_valid_ether_addr(netdev->dev_addr)) { |
| 3185 | pr_err("invalid MAC address\n"); |
| 3186 | err = -EIO; |
| 3187 | goto err_sw_init; |
| 3188 | } |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3189 | |
Michał Mirosław | 471a76d | 2011-06-08 08:53:03 +0000 | [diff] [blame] | 3190 | netdev->hw_features = NETIF_F_SG | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3191 | NETIF_F_IP_CSUM | |
Michał Mirosław | 471a76d | 2011-06-08 08:53:03 +0000 | [diff] [blame] | 3192 | NETIF_F_IPV6_CSUM | |
| 3193 | NETIF_F_TSO | |
| 3194 | NETIF_F_TSO6 | |
| 3195 | NETIF_F_RXCSUM; |
| 3196 | |
| 3197 | netdev->features = netdev->hw_features | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3198 | NETIF_F_HW_VLAN_TX | |
| 3199 | NETIF_F_HW_VLAN_RX | |
| 3200 | NETIF_F_HW_VLAN_FILTER; |
| 3201 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3202 | netdev->vlan_features |= NETIF_F_TSO; |
| 3203 | netdev->vlan_features |= NETIF_F_TSO6; |
| 3204 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | 3bfacf9 | 2010-08-02 14:59:04 +0000 | [diff] [blame] | 3205 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3206 | netdev->vlan_features |= NETIF_F_SG; |
| 3207 | |
| 3208 | if (pci_using_dac) |
| 3209 | netdev->features |= NETIF_F_HIGHDMA; |
| 3210 | |
Jiri Pirko | 0178934 | 2011-08-16 06:29:00 +0000 | [diff] [blame] | 3211 | netdev->priv_flags |= IFF_UNICAST_FLT; |
| 3212 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3213 | init_timer(&adapter->watchdog_timer); |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 3214 | adapter->watchdog_timer.function = ixgbevf_watchdog; |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3215 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 3216 | |
| 3217 | INIT_WORK(&adapter->reset_task, ixgbevf_reset_task); |
| 3218 | INIT_WORK(&adapter->watchdog_task, ixgbevf_watchdog_task); |
| 3219 | |
| 3220 | err = ixgbevf_init_interrupt_scheme(adapter); |
| 3221 | if (err) |
| 3222 | goto err_sw_init; |
| 3223 | |
| 3224 | /* pick up the PCI bus settings for reporting later */ |
| 3225 | if (hw->mac.ops.get_bus_info) |
| 3226 | hw->mac.ops.get_bus_info(hw); |
| 3227 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3228 | strcpy(netdev->name, "eth%d"); |
| 3229 | |
| 3230 | err = register_netdev(netdev); |
| 3231 | if (err) |
| 3232 | goto err_register; |
| 3233 | |
Greg Rose | 5d426ad | 2010-11-16 19:27:19 -0800 | [diff] [blame] | 3234 | netif_carrier_off(netdev); |
| 3235 | |
Greg Rose | 33bd9f6 | 2010-03-19 02:59:52 +0000 | [diff] [blame] | 3236 | ixgbevf_init_last_counter_stats(adapter); |
| 3237 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3238 | /* print the MAC address */ |
Danny Kukawka | f794e7e | 2012-02-24 03:45:56 +0000 | [diff] [blame] | 3239 | hw_dbg(hw, "%pM\n", netdev->dev_addr); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3240 | |
| 3241 | hw_dbg(hw, "MAC: %d\n", hw->mac.type); |
| 3242 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3243 | hw_dbg(hw, "Intel(R) 82599 Virtual Function\n"); |
| 3244 | cards_found++; |
| 3245 | return 0; |
| 3246 | |
| 3247 | err_register: |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 3248 | ixgbevf_clear_interrupt_scheme(adapter); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3249 | err_sw_init: |
| 3250 | ixgbevf_reset_interrupt_capability(adapter); |
| 3251 | iounmap(hw->hw_addr); |
| 3252 | err_ioremap: |
| 3253 | free_netdev(netdev); |
| 3254 | err_alloc_etherdev: |
| 3255 | pci_release_regions(pdev); |
| 3256 | err_pci_reg: |
| 3257 | err_dma: |
| 3258 | pci_disable_device(pdev); |
| 3259 | return err; |
| 3260 | } |
| 3261 | |
| 3262 | /** |
| 3263 | * ixgbevf_remove - Device Removal Routine |
| 3264 | * @pdev: PCI device information struct |
| 3265 | * |
| 3266 | * ixgbevf_remove is called by the PCI subsystem to alert the driver |
| 3267 | * that it should release a PCI device. The could be caused by a |
| 3268 | * Hot-Plug event, or because the driver is going to be removed from |
| 3269 | * memory. |
| 3270 | **/ |
| 3271 | static void __devexit ixgbevf_remove(struct pci_dev *pdev) |
| 3272 | { |
| 3273 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3274 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 3275 | |
| 3276 | set_bit(__IXGBEVF_DOWN, &adapter->state); |
| 3277 | |
| 3278 | del_timer_sync(&adapter->watchdog_timer); |
| 3279 | |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 3280 | cancel_work_sync(&adapter->reset_task); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3281 | cancel_work_sync(&adapter->watchdog_task); |
| 3282 | |
Alexander Duyck | fd13a9a | 2012-05-11 08:32:24 +0000 | [diff] [blame] | 3283 | if (netdev->reg_state == NETREG_REGISTERED) |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3284 | unregister_netdev(netdev); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3285 | |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 3286 | ixgbevf_clear_interrupt_scheme(adapter); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3287 | ixgbevf_reset_interrupt_capability(adapter); |
| 3288 | |
| 3289 | iounmap(adapter->hw.hw_addr); |
| 3290 | pci_release_regions(pdev); |
| 3291 | |
| 3292 | hw_dbg(&adapter->hw, "Remove complete\n"); |
| 3293 | |
| 3294 | kfree(adapter->tx_ring); |
| 3295 | kfree(adapter->rx_ring); |
| 3296 | |
| 3297 | free_netdev(netdev); |
| 3298 | |
| 3299 | pci_disable_device(pdev); |
| 3300 | } |
| 3301 | |
Alexander Duyck | 9f19f31 | 2012-05-11 08:33:32 +0000 | [diff] [blame] | 3302 | /** |
| 3303 | * ixgbevf_io_error_detected - called when PCI error is detected |
| 3304 | * @pdev: Pointer to PCI device |
| 3305 | * @state: The current pci connection state |
| 3306 | * |
| 3307 | * This function is called after a PCI bus error affecting |
| 3308 | * this device has been detected. |
| 3309 | */ |
| 3310 | static pci_ers_result_t ixgbevf_io_error_detected(struct pci_dev *pdev, |
| 3311 | pci_channel_state_t state) |
| 3312 | { |
| 3313 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3314 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 3315 | |
| 3316 | netif_device_detach(netdev); |
| 3317 | |
| 3318 | if (state == pci_channel_io_perm_failure) |
| 3319 | return PCI_ERS_RESULT_DISCONNECT; |
| 3320 | |
| 3321 | if (netif_running(netdev)) |
| 3322 | ixgbevf_down(adapter); |
| 3323 | |
| 3324 | pci_disable_device(pdev); |
| 3325 | |
| 3326 | /* Request a slot slot reset. */ |
| 3327 | return PCI_ERS_RESULT_NEED_RESET; |
| 3328 | } |
| 3329 | |
| 3330 | /** |
| 3331 | * ixgbevf_io_slot_reset - called after the pci bus has been reset. |
| 3332 | * @pdev: Pointer to PCI device |
| 3333 | * |
| 3334 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 3335 | * resembles the first-half of the ixgbevf_resume routine. |
| 3336 | */ |
| 3337 | static pci_ers_result_t ixgbevf_io_slot_reset(struct pci_dev *pdev) |
| 3338 | { |
| 3339 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3340 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 3341 | |
| 3342 | if (pci_enable_device_mem(pdev)) { |
| 3343 | dev_err(&pdev->dev, |
| 3344 | "Cannot re-enable PCI device after reset.\n"); |
| 3345 | return PCI_ERS_RESULT_DISCONNECT; |
| 3346 | } |
| 3347 | |
| 3348 | pci_set_master(pdev); |
| 3349 | |
| 3350 | ixgbevf_reset(adapter); |
| 3351 | |
| 3352 | return PCI_ERS_RESULT_RECOVERED; |
| 3353 | } |
| 3354 | |
| 3355 | /** |
| 3356 | * ixgbevf_io_resume - called when traffic can start flowing again. |
| 3357 | * @pdev: Pointer to PCI device |
| 3358 | * |
| 3359 | * This callback is called when the error recovery driver tells us that |
| 3360 | * its OK to resume normal operation. Implementation resembles the |
| 3361 | * second-half of the ixgbevf_resume routine. |
| 3362 | */ |
| 3363 | static void ixgbevf_io_resume(struct pci_dev *pdev) |
| 3364 | { |
| 3365 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3366 | struct ixgbevf_adapter *adapter = netdev_priv(netdev); |
| 3367 | |
| 3368 | if (netif_running(netdev)) |
| 3369 | ixgbevf_up(adapter); |
| 3370 | |
| 3371 | netif_device_attach(netdev); |
| 3372 | } |
| 3373 | |
| 3374 | /* PCI Error Recovery (ERS) */ |
| 3375 | static struct pci_error_handlers ixgbevf_err_handler = { |
| 3376 | .error_detected = ixgbevf_io_error_detected, |
| 3377 | .slot_reset = ixgbevf_io_slot_reset, |
| 3378 | .resume = ixgbevf_io_resume, |
| 3379 | }; |
| 3380 | |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3381 | static struct pci_driver ixgbevf_driver = { |
| 3382 | .name = ixgbevf_driver_name, |
| 3383 | .id_table = ixgbevf_pci_tbl, |
| 3384 | .probe = ixgbevf_probe, |
| 3385 | .remove = __devexit_p(ixgbevf_remove), |
Alexander Duyck | 0ac1e8c | 2012-05-11 08:33:26 +0000 | [diff] [blame] | 3386 | #ifdef CONFIG_PM |
| 3387 | /* Power Management Hooks */ |
| 3388 | .suspend = ixgbevf_suspend, |
| 3389 | .resume = ixgbevf_resume, |
| 3390 | #endif |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3391 | .shutdown = ixgbevf_shutdown, |
Alexander Duyck | 9f19f31 | 2012-05-11 08:33:32 +0000 | [diff] [blame] | 3392 | .err_handler = &ixgbevf_err_handler |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3393 | }; |
| 3394 | |
| 3395 | /** |
Greg Rose | 65d676c | 2011-02-03 06:54:13 +0000 | [diff] [blame] | 3396 | * ixgbevf_init_module - Driver Registration Routine |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3397 | * |
Greg Rose | 65d676c | 2011-02-03 06:54:13 +0000 | [diff] [blame] | 3398 | * ixgbevf_init_module is the first routine called when the driver is |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3399 | * loaded. All it does is register with the PCI subsystem. |
| 3400 | **/ |
| 3401 | static int __init ixgbevf_init_module(void) |
| 3402 | { |
| 3403 | int ret; |
Jeff Kirsher | dbd9636 | 2011-10-21 19:38:18 +0000 | [diff] [blame] | 3404 | pr_info("%s - version %s\n", ixgbevf_driver_string, |
| 3405 | ixgbevf_driver_version); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3406 | |
Jeff Kirsher | dbd9636 | 2011-10-21 19:38:18 +0000 | [diff] [blame] | 3407 | pr_info("%s\n", ixgbevf_copyright); |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3408 | |
| 3409 | ret = pci_register_driver(&ixgbevf_driver); |
| 3410 | return ret; |
| 3411 | } |
| 3412 | |
| 3413 | module_init(ixgbevf_init_module); |
| 3414 | |
| 3415 | /** |
Greg Rose | 65d676c | 2011-02-03 06:54:13 +0000 | [diff] [blame] | 3416 | * ixgbevf_exit_module - Driver Exit Cleanup Routine |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3417 | * |
Greg Rose | 65d676c | 2011-02-03 06:54:13 +0000 | [diff] [blame] | 3418 | * ixgbevf_exit_module is called just before the driver is removed |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3419 | * from memory. |
| 3420 | **/ |
| 3421 | static void __exit ixgbevf_exit_module(void) |
| 3422 | { |
| 3423 | pci_unregister_driver(&ixgbevf_driver); |
| 3424 | } |
| 3425 | |
| 3426 | #ifdef DEBUG |
| 3427 | /** |
Greg Rose | 65d676c | 2011-02-03 06:54:13 +0000 | [diff] [blame] | 3428 | * ixgbevf_get_hw_dev_name - return device name string |
Greg Rose | 92915f7 | 2010-01-09 02:24:10 +0000 | [diff] [blame] | 3429 | * used by hardware layer to print debugging information |
| 3430 | **/ |
| 3431 | char *ixgbevf_get_hw_dev_name(struct ixgbe_hw *hw) |
| 3432 | { |
| 3433 | struct ixgbevf_adapter *adapter = hw->back; |
| 3434 | return adapter->netdev->name; |
| 3435 | } |
| 3436 | |
| 3437 | #endif |
| 3438 | module_exit(ixgbevf_exit_module); |
| 3439 | |
| 3440 | /* ixgbevf_main.c */ |