blob: 3ff5aa801a6b14fdd93d4c5e1f65d33a6c284c2d [file] [log] [blame]
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2012 Intel Corporation.
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#include "ixgbe.h"
29#include "ixgbe_sriov.h"
30
Alexander Duyck800bd602012-06-02 00:11:02 +000031#ifdef CONFIG_IXGBE_DCB
Alexander Duyck73079ea2012-07-14 06:48:49 +000032/**
33 * ixgbe_cache_ring_dcb_sriov - Descriptor ring to register mapping for SR-IOV
34 * @adapter: board private structure to initialize
35 *
36 * Cache the descriptor ring offsets for SR-IOV to the assigned rings. It
37 * will also try to cache the proper offsets if RSS/FCoE are enabled along
38 * with VMDq.
39 *
40 **/
41static bool ixgbe_cache_ring_dcb_sriov(struct ixgbe_adapter *adapter)
42{
43#ifdef IXGBE_FCOE
44 struct ixgbe_ring_feature *fcoe = &adapter->ring_feature[RING_F_FCOE];
45#endif /* IXGBE_FCOE */
46 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
47 int i;
48 u16 reg_idx;
49 u8 tcs = netdev_get_num_tc(adapter->netdev);
50
51 /* verify we have DCB queueing enabled before proceeding */
52 if (tcs <= 1)
53 return false;
54
55 /* verify we have VMDq enabled before proceeding */
56 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
57 return false;
58
59 /* start at VMDq register offset for SR-IOV enabled setups */
60 reg_idx = vmdq->offset * __ALIGN_MASK(1, ~vmdq->mask);
61 for (i = 0; i < adapter->num_rx_queues; i++, reg_idx++) {
62 /* If we are greater than indices move to next pool */
63 if ((reg_idx & ~vmdq->mask) >= tcs)
64 reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask);
65 adapter->rx_ring[i]->reg_idx = reg_idx;
66 }
67
68 reg_idx = vmdq->offset * __ALIGN_MASK(1, ~vmdq->mask);
69 for (i = 0; i < adapter->num_tx_queues; i++, reg_idx++) {
70 /* If we are greater than indices move to next pool */
71 if ((reg_idx & ~vmdq->mask) >= tcs)
72 reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask);
73 adapter->tx_ring[i]->reg_idx = reg_idx;
74 }
75
76#ifdef IXGBE_FCOE
77 /* nothing to do if FCoE is disabled */
78 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
79 return true;
80
81 /* The work is already done if the FCoE ring is shared */
82 if (fcoe->offset < tcs)
83 return true;
84
85 /* The FCoE rings exist separately, we need to move their reg_idx */
86 if (fcoe->indices) {
87 u16 queues_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
88 u8 fcoe_tc = ixgbe_fcoe_get_tc(adapter);
89
90 reg_idx = (vmdq->offset + vmdq->indices) * queues_per_pool;
91 for (i = fcoe->offset; i < adapter->num_rx_queues; i++) {
92 reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask) + fcoe_tc;
93 adapter->rx_ring[i]->reg_idx = reg_idx;
94 reg_idx++;
95 }
96
97 reg_idx = (vmdq->offset + vmdq->indices) * queues_per_pool;
98 for (i = fcoe->offset; i < adapter->num_tx_queues; i++) {
99 reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask) + fcoe_tc;
100 adapter->tx_ring[i]->reg_idx = reg_idx;
101 reg_idx++;
102 }
103 }
104
105#endif /* IXGBE_FCOE */
106 return true;
107}
108
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000109/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
110static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
111 unsigned int *tx, unsigned int *rx)
112{
113 struct net_device *dev = adapter->netdev;
114 struct ixgbe_hw *hw = &adapter->hw;
115 u8 num_tcs = netdev_get_num_tc(dev);
116
117 *tx = 0;
118 *rx = 0;
119
120 switch (hw->mac.type) {
121 case ixgbe_mac_82598EB:
Alexander Duyck4ae63732012-06-22 06:46:33 +0000122 /* TxQs/TC: 4 RxQs/TC: 8 */
123 *tx = tc << 2; /* 0, 4, 8, 12, 16, 20, 24, 28 */
124 *rx = tc << 3; /* 0, 8, 16, 24, 32, 40, 48, 56 */
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000125 break;
126 case ixgbe_mac_82599EB:
127 case ixgbe_mac_X540:
128 if (num_tcs > 4) {
Alexander Duyck4ae63732012-06-22 06:46:33 +0000129 /*
130 * TCs : TC0/1 TC2/3 TC4-7
131 * TxQs/TC: 32 16 8
132 * RxQs/TC: 16 16 16
133 */
134 *rx = tc << 4;
135 if (tc < 3)
136 *tx = tc << 5; /* 0, 32, 64 */
137 else if (tc < 5)
138 *tx = (tc + 2) << 4; /* 80, 96 */
139 else
140 *tx = (tc + 8) << 3; /* 104, 112, 120 */
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000141 } else {
Alexander Duyck4ae63732012-06-22 06:46:33 +0000142 /*
143 * TCs : TC0 TC1 TC2/3
144 * TxQs/TC: 64 32 16
145 * RxQs/TC: 32 32 32
146 */
147 *rx = tc << 5;
148 if (tc < 2)
149 *tx = tc << 6; /* 0, 64 */
150 else
151 *tx = (tc + 4) << 4; /* 96, 112 */
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000152 }
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000153 default:
154 break;
155 }
156}
157
158/**
159 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
160 * @adapter: board private structure to initialize
161 *
162 * Cache the descriptor ring offsets for DCB to the assigned rings.
163 *
164 **/
Alexander Duyck4ae63732012-06-22 06:46:33 +0000165static bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000166{
167 struct net_device *dev = adapter->netdev;
Alexander Duyck4ae63732012-06-22 06:46:33 +0000168 unsigned int tx_idx, rx_idx;
169 int tc, offset, rss_i, i;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000170 u8 num_tcs = netdev_get_num_tc(dev);
171
Alexander Duyck4ae63732012-06-22 06:46:33 +0000172 /* verify we have DCB queueing enabled before proceeding */
173 if (num_tcs <= 1)
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000174 return false;
175
Alexander Duyck4ae63732012-06-22 06:46:33 +0000176 rss_i = adapter->ring_feature[RING_F_RSS].indices;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000177
Alexander Duyck4ae63732012-06-22 06:46:33 +0000178 for (tc = 0, offset = 0; tc < num_tcs; tc++, offset += rss_i) {
179 ixgbe_get_first_reg_idx(adapter, tc, &tx_idx, &rx_idx);
180 for (i = 0; i < rss_i; i++, tx_idx++, rx_idx++) {
181 adapter->tx_ring[offset + i]->reg_idx = tx_idx;
182 adapter->rx_ring[offset + i]->reg_idx = rx_idx;
183 adapter->tx_ring[offset + i]->dcb_tc = tc;
184 adapter->rx_ring[offset + i]->dcb_tc = tc;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000185 }
186 }
187
188 return true;
189}
Alexander Duyckd411a932012-06-30 00:14:01 +0000190
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000191#endif
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000192/**
193 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
194 * @adapter: board private structure to initialize
195 *
196 * SR-IOV doesn't use any descriptor rings but changes the default if
197 * no other mapping is used.
198 *
199 */
Alexander Duyck73079ea2012-07-14 06:48:49 +0000200static bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000201{
Alexander Duyck73079ea2012-07-14 06:48:49 +0000202#ifdef IXGBE_FCOE
203 struct ixgbe_ring_feature *fcoe = &adapter->ring_feature[RING_F_FCOE];
204#endif /* IXGBE_FCOE */
205 struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
206 struct ixgbe_ring_feature *rss = &adapter->ring_feature[RING_F_RSS];
207 int i;
208 u16 reg_idx;
209
210 /* only proceed if VMDq is enabled */
211 if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED))
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000212 return false;
Alexander Duyck73079ea2012-07-14 06:48:49 +0000213
214 /* start at VMDq register offset for SR-IOV enabled setups */
215 reg_idx = vmdq->offset * __ALIGN_MASK(1, ~vmdq->mask);
216 for (i = 0; i < adapter->num_rx_queues; i++, reg_idx++) {
217#ifdef IXGBE_FCOE
218 /* Allow first FCoE queue to be mapped as RSS */
219 if (fcoe->offset && (i > fcoe->offset))
220 break;
221#endif
222 /* If we are greater than indices move to next pool */
223 if ((reg_idx & ~vmdq->mask) >= rss->indices)
224 reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask);
225 adapter->rx_ring[i]->reg_idx = reg_idx;
226 }
227
228#ifdef IXGBE_FCOE
229 /* FCoE uses a linear block of queues so just assigning 1:1 */
230 for (; i < adapter->num_rx_queues; i++, reg_idx++)
231 adapter->rx_ring[i]->reg_idx = reg_idx;
232
233#endif
234 reg_idx = vmdq->offset * __ALIGN_MASK(1, ~vmdq->mask);
235 for (i = 0; i < adapter->num_tx_queues; i++, reg_idx++) {
236#ifdef IXGBE_FCOE
237 /* Allow first FCoE queue to be mapped as RSS */
238 if (fcoe->offset && (i > fcoe->offset))
239 break;
240#endif
241 /* If we are greater than indices move to next pool */
242 if ((reg_idx & rss->mask) >= rss->indices)
243 reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask);
244 adapter->tx_ring[i]->reg_idx = reg_idx;
245 }
246
247#ifdef IXGBE_FCOE
248 /* FCoE uses a linear block of queues so just assigning 1:1 */
249 for (; i < adapter->num_tx_queues; i++, reg_idx++)
250 adapter->tx_ring[i]->reg_idx = reg_idx;
251
252#endif
253
254 return true;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000255}
256
257/**
Alexander Duyckd411a932012-06-30 00:14:01 +0000258 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
259 * @adapter: board private structure to initialize
260 *
261 * Cache the descriptor ring offsets for RSS to the assigned rings.
262 *
263 **/
264static bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
265{
266 int i;
267
Alexander Duyckd411a932012-06-30 00:14:01 +0000268 for (i = 0; i < adapter->num_rx_queues; i++)
269 adapter->rx_ring[i]->reg_idx = i;
270 for (i = 0; i < adapter->num_tx_queues; i++)
271 adapter->tx_ring[i]->reg_idx = i;
272
273 return true;
274}
275
276/**
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000277 * ixgbe_cache_ring_register - Descriptor ring to register mapping
278 * @adapter: board private structure to initialize
279 *
280 * Once we know the feature-set enabled for the device, we'll cache
281 * the register offset the descriptor ring is assigned to.
282 *
283 * Note, the order the various feature calls is important. It must start with
284 * the "most" features enabled at the same time, then trickle down to the
285 * least amount of features turned on at once.
286 **/
287static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
288{
289 /* start with default case */
290 adapter->rx_ring[0]->reg_idx = 0;
291 adapter->tx_ring[0]->reg_idx = 0;
292
Alexander Duyck73079ea2012-07-14 06:48:49 +0000293#ifdef CONFIG_IXGBE_DCB
294 if (ixgbe_cache_ring_dcb_sriov(adapter))
295 return;
296
297 if (ixgbe_cache_ring_dcb(adapter))
298 return;
299
300#endif
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000301 if (ixgbe_cache_ring_sriov(adapter))
302 return;
303
Alexander Duyckd411a932012-06-30 00:14:01 +0000304 ixgbe_cache_ring_rss(adapter);
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000305}
306
Alexander Duyckd411a932012-06-30 00:14:01 +0000307#define IXGBE_RSS_16Q_MASK 0xF
308#define IXGBE_RSS_8Q_MASK 0x7
309#define IXGBE_RSS_4Q_MASK 0x3
310#define IXGBE_RSS_2Q_MASK 0x1
311#define IXGBE_RSS_DISABLED_MASK 0x0
312
313#ifdef CONFIG_IXGBE_DCB
Alexander Duyck73079ea2012-07-14 06:48:49 +0000314/**
315 * ixgbe_set_dcb_sriov_queues: Allocate queues for SR-IOV devices w/ DCB
316 * @adapter: board private structure to initialize
317 *
318 * When SR-IOV (Single Root IO Virtualiztion) is enabled, allocate queues
319 * and VM pools where appropriate. Also assign queues based on DCB
320 * priorities and map accordingly..
321 *
322 **/
323static bool ixgbe_set_dcb_sriov_queues(struct ixgbe_adapter *adapter)
324{
325 int i;
326 u16 vmdq_i = adapter->ring_feature[RING_F_VMDQ].limit;
327 u16 vmdq_m = 0;
328#ifdef IXGBE_FCOE
329 u16 fcoe_i = 0;
330#endif
331 u8 tcs = netdev_get_num_tc(adapter->netdev);
332
333 /* verify we have DCB queueing enabled before proceeding */
334 if (tcs <= 1)
335 return false;
336
337 /* verify we have VMDq enabled before proceeding */
338 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
339 return false;
340
341 /* Add starting offset to total pool count */
342 vmdq_i += adapter->ring_feature[RING_F_VMDQ].offset;
343
344 /* 16 pools w/ 8 TC per pool */
345 if (tcs > 4) {
346 vmdq_i = min_t(u16, vmdq_i, 16);
347 vmdq_m = IXGBE_82599_VMDQ_8Q_MASK;
348 /* 32 pools w/ 4 TC per pool */
349 } else {
350 vmdq_i = min_t(u16, vmdq_i, 32);
351 vmdq_m = IXGBE_82599_VMDQ_4Q_MASK;
352 }
353
354#ifdef IXGBE_FCOE
355 /* queues in the remaining pools are available for FCoE */
356 fcoe_i = (128 / __ALIGN_MASK(1, ~vmdq_m)) - vmdq_i;
357
358#endif
359 /* remove the starting offset from the pool count */
360 vmdq_i -= adapter->ring_feature[RING_F_VMDQ].offset;
361
362 /* save features for later use */
363 adapter->ring_feature[RING_F_VMDQ].indices = vmdq_i;
364 adapter->ring_feature[RING_F_VMDQ].mask = vmdq_m;
365
366 /*
367 * We do not support DCB, VMDq, and RSS all simultaneously
368 * so we will disable RSS since it is the lowest priority
369 */
370 adapter->ring_feature[RING_F_RSS].indices = 1;
371 adapter->ring_feature[RING_F_RSS].mask = IXGBE_RSS_DISABLED_MASK;
372
373 adapter->num_rx_pools = vmdq_i;
374 adapter->num_rx_queues_per_pool = tcs;
375
376 adapter->num_tx_queues = vmdq_i * tcs;
377 adapter->num_rx_queues = vmdq_i * tcs;
378
379#ifdef IXGBE_FCOE
380 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
381 struct ixgbe_ring_feature *fcoe;
382
383 fcoe = &adapter->ring_feature[RING_F_FCOE];
384
385 /* limit ourselves based on feature limits */
386 fcoe_i = min_t(u16, fcoe_i, num_online_cpus());
387 fcoe_i = min_t(u16, fcoe_i, fcoe->limit);
388
389 if (fcoe_i) {
390 /* alloc queues for FCoE separately */
391 fcoe->indices = fcoe_i;
392 fcoe->offset = vmdq_i * tcs;
393
394 /* add queues to adapter */
395 adapter->num_tx_queues += fcoe_i;
396 adapter->num_rx_queues += fcoe_i;
397 } else if (tcs > 1) {
398 /* use queue belonging to FcoE TC */
399 fcoe->indices = 1;
400 fcoe->offset = ixgbe_fcoe_get_tc(adapter);
401 } else {
402 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
403
404 fcoe->indices = 0;
405 fcoe->offset = 0;
406 }
407 }
408
409#endif /* IXGBE_FCOE */
410 /* configure TC to queue mapping */
411 for (i = 0; i < tcs; i++)
412 netdev_set_tc_queue(adapter->netdev, i, 1, i);
413
414 return true;
415}
416
Alexander Duyckd411a932012-06-30 00:14:01 +0000417static bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
418{
419 struct net_device *dev = adapter->netdev;
420 struct ixgbe_ring_feature *f;
421 int rss_i, rss_m, i;
422 int tcs;
423
424 /* Map queue offset and counts onto allocated tx queues */
425 tcs = netdev_get_num_tc(dev);
426
427 /* verify we have DCB queueing enabled before proceeding */
428 if (tcs <= 1)
429 return false;
430
431 /* determine the upper limit for our current DCB mode */
432 rss_i = dev->num_tx_queues / tcs;
433 if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
434 /* 8 TC w/ 4 queues per TC */
435 rss_i = min_t(u16, rss_i, 4);
436 rss_m = IXGBE_RSS_4Q_MASK;
437 } else if (tcs > 4) {
438 /* 8 TC w/ 8 queues per TC */
439 rss_i = min_t(u16, rss_i, 8);
440 rss_m = IXGBE_RSS_8Q_MASK;
441 } else {
442 /* 4 TC w/ 16 queues per TC */
443 rss_i = min_t(u16, rss_i, 16);
444 rss_m = IXGBE_RSS_16Q_MASK;
445 }
446
447 /* set RSS mask and indices */
448 f = &adapter->ring_feature[RING_F_RSS];
449 rss_i = min_t(int, rss_i, f->limit);
450 f->indices = rss_i;
451 f->mask = rss_m;
452
453#ifdef IXGBE_FCOE
454 /* FCoE enabled queues require special configuration indexed
455 * by feature specific indices and offset. Here we map FCoE
456 * indices onto the DCB queue pairs allowing FCoE to own
457 * configuration later.
458 */
459 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
460 u8 tc = ixgbe_fcoe_get_tc(adapter);
461
462 f = &adapter->ring_feature[RING_F_FCOE];
463 f->indices = min_t(u16, rss_i, f->limit);
464 f->offset = rss_i * tc;
465 }
466
467#endif /* IXGBE_FCOE */
468 for (i = 0; i < tcs; i++)
469 netdev_set_tc_queue(dev, i, rss_i, rss_i * i);
470
471 adapter->num_tx_queues = rss_i * tcs;
472 adapter->num_rx_queues = rss_i * tcs;
473
474 return true;
475}
476
477#endif
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000478/**
Alexander Duyck73079ea2012-07-14 06:48:49 +0000479 * ixgbe_set_sriov_queues - Allocate queues for SR-IOV devices
480 * @adapter: board private structure to initialize
481 *
482 * When SR-IOV (Single Root IO Virtualiztion) is enabled, allocate queues
483 * and VM pools where appropriate. If RSS is available, then also try and
484 * enable RSS and map accordingly.
485 *
486 **/
487static bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
488{
489 u16 vmdq_i = adapter->ring_feature[RING_F_VMDQ].limit;
490 u16 vmdq_m = 0;
491 u16 rss_i = adapter->ring_feature[RING_F_RSS].limit;
492 u16 rss_m = IXGBE_RSS_DISABLED_MASK;
493#ifdef IXGBE_FCOE
494 u16 fcoe_i = 0;
495#endif
496
497 /* only proceed if SR-IOV is enabled */
498 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
499 return false;
500
501 /* Add starting offset to total pool count */
502 vmdq_i += adapter->ring_feature[RING_F_VMDQ].offset;
503
504 /* double check we are limited to maximum pools */
505 vmdq_i = min_t(u16, IXGBE_MAX_VMDQ_INDICES, vmdq_i);
506
507 /* 64 pool mode with 2 queues per pool */
508 if ((vmdq_i > 32) || (rss_i < 4)) {
509 vmdq_m = IXGBE_82599_VMDQ_2Q_MASK;
510 rss_m = IXGBE_RSS_2Q_MASK;
511 rss_i = min_t(u16, rss_i, 2);
512 /* 32 pool mode with 4 queues per pool */
513 } else {
514 vmdq_m = IXGBE_82599_VMDQ_4Q_MASK;
515 rss_m = IXGBE_RSS_4Q_MASK;
516 rss_i = 4;
517 }
518
519#ifdef IXGBE_FCOE
520 /* queues in the remaining pools are available for FCoE */
521 fcoe_i = 128 - (vmdq_i * __ALIGN_MASK(1, ~vmdq_m));
522
523#endif
524 /* remove the starting offset from the pool count */
525 vmdq_i -= adapter->ring_feature[RING_F_VMDQ].offset;
526
527 /* save features for later use */
528 adapter->ring_feature[RING_F_VMDQ].indices = vmdq_i;
529 adapter->ring_feature[RING_F_VMDQ].mask = vmdq_m;
530
531 /* limit RSS based on user input and save for later use */
532 adapter->ring_feature[RING_F_RSS].indices = rss_i;
533 adapter->ring_feature[RING_F_RSS].mask = rss_m;
534
535 adapter->num_rx_pools = vmdq_i;
536 adapter->num_rx_queues_per_pool = rss_i;
537
538 adapter->num_rx_queues = vmdq_i * rss_i;
539 adapter->num_tx_queues = vmdq_i * rss_i;
540
541 /* disable ATR as it is not supported when VMDq is enabled */
542 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
543
544#ifdef IXGBE_FCOE
545 /*
546 * FCoE can use rings from adjacent buffers to allow RSS
547 * like behavior. To account for this we need to add the
548 * FCoE indices to the total ring count.
549 */
550 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
551 struct ixgbe_ring_feature *fcoe;
552
553 fcoe = &adapter->ring_feature[RING_F_FCOE];
554
555 /* limit ourselves based on feature limits */
556 fcoe_i = min_t(u16, fcoe_i, fcoe->limit);
557
558 if (vmdq_i > 1 && fcoe_i) {
559 /* reserve no more than number of CPUs */
560 fcoe_i = min_t(u16, fcoe_i, num_online_cpus());
561
562 /* alloc queues for FCoE separately */
563 fcoe->indices = fcoe_i;
564 fcoe->offset = vmdq_i * rss_i;
565 } else {
566 /* merge FCoE queues with RSS queues */
567 fcoe_i = min_t(u16, fcoe_i + rss_i, num_online_cpus());
568
569 /* limit indices to rss_i if MSI-X is disabled */
570 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
571 fcoe_i = rss_i;
572
573 /* attempt to reserve some queues for just FCoE */
574 fcoe->indices = min_t(u16, fcoe_i, fcoe->limit);
575 fcoe->offset = fcoe_i - fcoe->indices;
576
577 fcoe_i -= rss_i;
578 }
579
580 /* add queues to adapter */
581 adapter->num_tx_queues += fcoe_i;
582 adapter->num_rx_queues += fcoe_i;
583 }
584
585#endif
586 return true;
587}
588
589/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000590 * ixgbe_set_rss_queues - Allocate queues for RSS
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000591 * @adapter: board private structure to initialize
592 *
593 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
594 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
595 *
596 **/
Alexander Duyck0b7f5d02012-05-05 05:31:04 +0000597static bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000598{
Alexander Duyck0b7f5d02012-05-05 05:31:04 +0000599 struct ixgbe_ring_feature *f;
600 u16 rss_i;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000601
Alexander Duyck0b7f5d02012-05-05 05:31:04 +0000602 /* set mask for 16 queue limit of RSS */
603 f = &adapter->ring_feature[RING_F_RSS];
604 rss_i = f->limit;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000605
Alexander Duyck0b7f5d02012-05-05 05:31:04 +0000606 f->indices = rss_i;
Alexander Duyckd411a932012-06-30 00:14:01 +0000607 f->mask = IXGBE_RSS_16Q_MASK;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000608
609 /*
Alexander Duyck0b7f5d02012-05-05 05:31:04 +0000610 * Use Flow Director in addition to RSS to ensure the best
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000611 * distribution of flows across cores, even when an FDIR flow
612 * isn't matched.
613 */
Alexander Duyck0b7f5d02012-05-05 05:31:04 +0000614 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
615 f = &adapter->ring_feature[RING_F_FDIR];
616
617 f->indices = min_t(u16, num_online_cpus(), f->limit);
618 rss_i = max_t(u16, rss_i, f->indices);
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000619 }
Alexander Duyck0b7f5d02012-05-05 05:31:04 +0000620
Alexander Duyckd411a932012-06-30 00:14:01 +0000621#ifdef IXGBE_FCOE
622 /*
623 * FCoE can exist on the same rings as standard network traffic
624 * however it is preferred to avoid that if possible. In order
625 * to get the best performance we allocate as many FCoE queues
626 * as we can and we place them at the end of the ring array to
627 * avoid sharing queues with standard RSS on systems with 24 or
628 * more CPUs.
629 */
630 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
631 struct net_device *dev = adapter->netdev;
632 u16 fcoe_i;
633
634 f = &adapter->ring_feature[RING_F_FCOE];
635
636 /* merge FCoE queues with RSS queues */
637 fcoe_i = min_t(u16, f->limit + rss_i, num_online_cpus());
638 fcoe_i = min_t(u16, fcoe_i, dev->num_tx_queues);
639
640 /* limit indices to rss_i if MSI-X is disabled */
641 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
642 fcoe_i = rss_i;
643
644 /* attempt to reserve some queues for just FCoE */
645 f->indices = min_t(u16, fcoe_i, f->limit);
646 f->offset = fcoe_i - f->indices;
647 rss_i = max_t(u16, fcoe_i, rss_i);
648 }
649
650#endif /* IXGBE_FCOE */
Alexander Duyck0b7f5d02012-05-05 05:31:04 +0000651 adapter->num_rx_queues = rss_i;
652 adapter->num_tx_queues = rss_i;
653
654 return true;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000655}
656
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000657/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000658 * ixgbe_set_num_queues - Allocate queues for device, feature dependent
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000659 * @adapter: board private structure to initialize
660 *
661 * This is the top level queue allocation routine. The order here is very
662 * important, starting with the "most" number of features turned on at once,
663 * and ending with the smallest set of features. This way large combinations
664 * can be allocated if they're turned on, and smaller combinations are the
665 * fallthrough conditions.
666 *
667 **/
Alexander Duyckac802f52012-07-12 05:52:53 +0000668static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000669{
670 /* Start with base case */
671 adapter->num_rx_queues = 1;
672 adapter->num_tx_queues = 1;
673 adapter->num_rx_pools = adapter->num_rx_queues;
674 adapter->num_rx_queues_per_pool = 1;
675
Alexander Duyck73079ea2012-07-14 06:48:49 +0000676#ifdef CONFIG_IXGBE_DCB
677 if (ixgbe_set_dcb_sriov_queues(adapter))
Alexander Duyckac802f52012-07-12 05:52:53 +0000678 return;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000679
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000680 if (ixgbe_set_dcb_queues(adapter))
Alexander Duyckac802f52012-07-12 05:52:53 +0000681 return;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000682
683#endif
Alexander Duyck73079ea2012-07-14 06:48:49 +0000684 if (ixgbe_set_sriov_queues(adapter))
685 return;
686
Alexander Duyckac802f52012-07-12 05:52:53 +0000687 ixgbe_set_rss_queues(adapter);
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000688}
689
690static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
691 int vectors)
692{
693 int err, vector_threshold;
694
695 /* We'll want at least 2 (vector_threshold):
696 * 1) TxQ[0] + RxQ[0] handler
697 * 2) Other (Link Status Change, etc.)
698 */
699 vector_threshold = MIN_MSIX_COUNT;
700
701 /*
702 * The more we get, the more we will assign to Tx/Rx Cleanup
703 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
704 * Right now, we simply care about how many we'll get; we'll
705 * set them up later while requesting irq's.
706 */
707 while (vectors >= vector_threshold) {
708 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
709 vectors);
710 if (!err) /* Success in acquiring all requested vectors. */
711 break;
712 else if (err < 0)
713 vectors = 0; /* Nasty failure, quit now */
714 else /* err == number of vectors we should try again with */
715 vectors = err;
716 }
717
718 if (vectors < vector_threshold) {
719 /* Can't allocate enough MSI-X interrupts? Oh well.
720 * This just means we'll go with either a single MSI
721 * vector or fall back to legacy interrupts.
722 */
723 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
724 "Unable to allocate MSI-X interrupts\n");
725 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
726 kfree(adapter->msix_entries);
727 adapter->msix_entries = NULL;
728 } else {
729 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
730 /*
731 * Adjust for only the vectors we'll use, which is minimum
732 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
733 * vectors we were allocated.
734 */
Alexander Duyck49c7ffb2012-05-05 05:30:43 +0000735 vectors -= NON_Q_VECTORS;
736 adapter->num_q_vectors = min(vectors, adapter->max_q_vectors);
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000737 }
738}
739
740static void ixgbe_add_ring(struct ixgbe_ring *ring,
741 struct ixgbe_ring_container *head)
742{
743 ring->next = head->ring;
744 head->ring = ring;
745 head->count++;
746}
747
748/**
749 * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector
750 * @adapter: board private structure to initialize
Alexander Duyckd0bfcdf2012-03-28 08:03:43 +0000751 * @v_count: q_vectors allocated on adapter, used for ring interleaving
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000752 * @v_idx: index of vector in adapter struct
Alexander Duyckd0bfcdf2012-03-28 08:03:43 +0000753 * @txr_count: total number of Tx rings to allocate
754 * @txr_idx: index of first Tx ring to allocate
755 * @rxr_count: total number of Rx rings to allocate
756 * @rxr_idx: index of first Rx ring to allocate
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000757 *
758 * We allocate one q_vector. If allocation fails we return -ENOMEM.
759 **/
Alexander Duyckd0bfcdf2012-03-28 08:03:43 +0000760static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter,
761 int v_count, int v_idx,
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000762 int txr_count, int txr_idx,
763 int rxr_count, int rxr_idx)
764{
765 struct ixgbe_q_vector *q_vector;
766 struct ixgbe_ring *ring;
767 int node = -1;
768 int cpu = -1;
769 int ring_count, size;
770
771 ring_count = txr_count + rxr_count;
772 size = sizeof(struct ixgbe_q_vector) +
773 (sizeof(struct ixgbe_ring) * ring_count);
774
775 /* customize cpu for Flow Director mapping */
776 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
777 if (cpu_online(v_idx)) {
778 cpu = v_idx;
779 node = cpu_to_node(cpu);
780 }
781 }
782
783 /* allocate q_vector and rings */
784 q_vector = kzalloc_node(size, GFP_KERNEL, node);
785 if (!q_vector)
786 q_vector = kzalloc(size, GFP_KERNEL);
787 if (!q_vector)
788 return -ENOMEM;
789
790 /* setup affinity mask and node */
791 if (cpu != -1)
792 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
793 else
794 cpumask_copy(&q_vector->affinity_mask, cpu_online_mask);
795 q_vector->numa_node = node;
796
797 /* initialize NAPI */
798 netif_napi_add(adapter->netdev, &q_vector->napi,
799 ixgbe_poll, 64);
800
801 /* tie q_vector and adapter together */
802 adapter->q_vector[v_idx] = q_vector;
803 q_vector->adapter = adapter;
804 q_vector->v_idx = v_idx;
805
806 /* initialize work limits */
807 q_vector->tx.work_limit = adapter->tx_work_limit;
808
809 /* initialize pointer to rings */
810 ring = q_vector->ring;
811
812 while (txr_count) {
813 /* assign generic ring traits */
814 ring->dev = &adapter->pdev->dev;
815 ring->netdev = adapter->netdev;
816
817 /* configure backlink on ring */
818 ring->q_vector = q_vector;
819
820 /* update q_vector Tx values */
821 ixgbe_add_ring(ring, &q_vector->tx);
822
823 /* apply Tx specific ring traits */
824 ring->count = adapter->tx_ring_count;
825 ring->queue_index = txr_idx;
826
827 /* assign ring to adapter */
828 adapter->tx_ring[txr_idx] = ring;
829
830 /* update count and index */
831 txr_count--;
Alexander Duyckd0bfcdf2012-03-28 08:03:43 +0000832 txr_idx += v_count;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000833
834 /* push pointer to next ring */
835 ring++;
836 }
837
838 while (rxr_count) {
839 /* assign generic ring traits */
840 ring->dev = &adapter->pdev->dev;
841 ring->netdev = adapter->netdev;
842
843 /* configure backlink on ring */
844 ring->q_vector = q_vector;
845
846 /* update q_vector Rx values */
847 ixgbe_add_ring(ring, &q_vector->rx);
848
849 /*
850 * 82599 errata, UDP frames with a 0 checksum
851 * can be marked as checksum errors.
852 */
853 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
854 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
855
Alexander Duyckb2db4972012-04-07 04:57:29 +0000856#ifdef IXGBE_FCOE
857 if (adapter->netdev->features & NETIF_F_FCOE_MTU) {
858 struct ixgbe_ring_feature *f;
859 f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duycke4b317e2012-05-05 05:30:53 +0000860 if ((rxr_idx >= f->offset) &&
861 (rxr_idx < f->offset + f->indices))
Alexander Duyck57efd442012-06-25 21:54:46 +0000862 set_bit(__IXGBE_RX_FCOE, &ring->state);
Alexander Duyckb2db4972012-04-07 04:57:29 +0000863 }
864
865#endif /* IXGBE_FCOE */
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000866 /* apply Rx specific ring traits */
867 ring->count = adapter->rx_ring_count;
868 ring->queue_index = rxr_idx;
869
870 /* assign ring to adapter */
871 adapter->rx_ring[rxr_idx] = ring;
872
873 /* update count and index */
874 rxr_count--;
Alexander Duyckd0bfcdf2012-03-28 08:03:43 +0000875 rxr_idx += v_count;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000876
877 /* push pointer to next ring */
878 ring++;
879 }
880
881 return 0;
882}
883
884/**
885 * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector
886 * @adapter: board private structure to initialize
887 * @v_idx: Index of vector to be freed
888 *
889 * This function frees the memory allocated to the q_vector. In addition if
890 * NAPI is enabled it will delete any references to the NAPI struct prior
891 * to freeing the q_vector.
892 **/
893static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
894{
895 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
896 struct ixgbe_ring *ring;
897
898 ixgbe_for_each_ring(ring, q_vector->tx)
899 adapter->tx_ring[ring->queue_index] = NULL;
900
901 ixgbe_for_each_ring(ring, q_vector->rx)
902 adapter->rx_ring[ring->queue_index] = NULL;
903
904 adapter->q_vector[v_idx] = NULL;
905 netif_napi_del(&q_vector->napi);
906
907 /*
908 * ixgbe_get_stats64() might access the rings on this vector,
909 * we must wait a grace period before freeing it.
910 */
911 kfree_rcu(q_vector, rcu);
912}
913
914/**
915 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
916 * @adapter: board private structure to initialize
917 *
918 * We allocate one q_vector per queue interrupt. If allocation fails we
919 * return -ENOMEM.
920 **/
921static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
922{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +0000923 int q_vectors = adapter->num_q_vectors;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000924 int rxr_remaining = adapter->num_rx_queues;
925 int txr_remaining = adapter->num_tx_queues;
926 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
927 int err;
928
929 /* only one q_vector if MSI-X is disabled. */
930 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
931 q_vectors = 1;
932
933 if (q_vectors >= (rxr_remaining + txr_remaining)) {
Alexander Duyckd0bfcdf2012-03-28 08:03:43 +0000934 for (; rxr_remaining; v_idx++) {
935 err = ixgbe_alloc_q_vector(adapter, q_vectors, v_idx,
936 0, 0, 1, rxr_idx);
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000937
938 if (err)
939 goto err_out;
940
941 /* update counts and index */
Alexander Duyckd0bfcdf2012-03-28 08:03:43 +0000942 rxr_remaining--;
943 rxr_idx++;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000944 }
945 }
946
Alexander Duyckd0bfcdf2012-03-28 08:03:43 +0000947 for (; v_idx < q_vectors; v_idx++) {
948 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
949 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
950 err = ixgbe_alloc_q_vector(adapter, q_vectors, v_idx,
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000951 tqpv, txr_idx,
952 rqpv, rxr_idx);
953
954 if (err)
955 goto err_out;
956
957 /* update counts and index */
958 rxr_remaining -= rqpv;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000959 txr_remaining -= tqpv;
Alexander Duyckd0bfcdf2012-03-28 08:03:43 +0000960 rxr_idx++;
961 txr_idx++;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000962 }
963
964 return 0;
965
966err_out:
Alexander Duyck49c7ffb2012-05-05 05:30:43 +0000967 adapter->num_tx_queues = 0;
968 adapter->num_rx_queues = 0;
969 adapter->num_q_vectors = 0;
970
971 while (v_idx--)
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000972 ixgbe_free_q_vector(adapter, v_idx);
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000973
974 return -ENOMEM;
975}
976
977/**
978 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
979 * @adapter: board private structure to initialize
980 *
981 * This function frees the memory allocated to the q_vectors. In addition if
982 * NAPI is enabled it will delete any references to the NAPI struct prior
983 * to freeing the q_vector.
984 **/
985static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
986{
Alexander Duyck49c7ffb2012-05-05 05:30:43 +0000987 int v_idx = adapter->num_q_vectors;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000988
Alexander Duyck49c7ffb2012-05-05 05:30:43 +0000989 adapter->num_tx_queues = 0;
990 adapter->num_rx_queues = 0;
991 adapter->num_q_vectors = 0;
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000992
Alexander Duyck49c7ffb2012-05-05 05:30:43 +0000993 while (v_idx--)
Jeff Kirsher8af3c332012-02-18 07:08:14 +0000994 ixgbe_free_q_vector(adapter, v_idx);
995}
996
997static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
998{
999 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
1000 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
1001 pci_disable_msix(adapter->pdev);
1002 kfree(adapter->msix_entries);
1003 adapter->msix_entries = NULL;
1004 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
1005 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
1006 pci_disable_msi(adapter->pdev);
1007 }
1008}
1009
1010/**
1011 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
1012 * @adapter: board private structure to initialize
1013 *
1014 * Attempt to configure the interrupts using the best available
1015 * capabilities of the hardware and the kernel.
1016 **/
Alexander Duyckac802f52012-07-12 05:52:53 +00001017static void ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001018{
1019 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckac802f52012-07-12 05:52:53 +00001020 int vector, v_budget, err;
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001021
1022 /*
1023 * It's easy to be greedy for MSI-X vectors, but it really
1024 * doesn't do us much good if we have a lot more vectors
1025 * than CPU's. So let's be conservative and only ask for
1026 * (roughly) the same number of vectors as there are CPU's.
1027 * The default is to use pairs of vectors.
1028 */
1029 v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
1030 v_budget = min_t(int, v_budget, num_online_cpus());
1031 v_budget += NON_Q_VECTORS;
1032
1033 /*
1034 * At the same time, hardware can only support a maximum of
1035 * hw.mac->max_msix_vectors vectors. With features
1036 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
1037 * descriptor queues supported by our device. Thus, we cap it off in
1038 * those rare cases where the cpu count also exceeds our vector limit.
1039 */
1040 v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors);
1041
1042 /* A failure in MSI-X entry allocation isn't fatal, but it does
1043 * mean we disable MSI-X capabilities of the adapter. */
1044 adapter->msix_entries = kcalloc(v_budget,
1045 sizeof(struct msix_entry), GFP_KERNEL);
1046 if (adapter->msix_entries) {
1047 for (vector = 0; vector < v_budget; vector++)
1048 adapter->msix_entries[vector].entry = vector;
1049
1050 ixgbe_acquire_msix_vectors(adapter, v_budget);
1051
1052 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyckac802f52012-07-12 05:52:53 +00001053 return;
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001054 }
1055
1056 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001057 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
1058 e_err(probe,
1059 "ATR is not supported while multiple "
1060 "queues are disabled. Disabling Flow Director\n");
1061 }
1062 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
1063 adapter->atr_sample_rate = 0;
Alexander Duyck99d74482012-05-09 08:09:25 +00001064 ixgbe_disable_sriov(adapter);
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001065
Alexander Duyckfbe7ca72012-07-14 05:42:36 +00001066 adapter->ring_feature[RING_F_RSS].limit = 1;
Alexander Duyckac802f52012-07-12 05:52:53 +00001067 ixgbe_set_num_queues(adapter);
Alexander Duyck49c7ffb2012-05-05 05:30:43 +00001068 adapter->num_q_vectors = 1;
1069
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001070 err = pci_enable_msi(adapter->pdev);
Alexander Duyckac802f52012-07-12 05:52:53 +00001071 if (err) {
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001072 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
1073 "Unable to allocate MSI interrupt, "
1074 "falling back to legacy. Error: %d\n", err);
Alexander Duyckac802f52012-07-12 05:52:53 +00001075 return;
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001076 }
Alexander Duyckac802f52012-07-12 05:52:53 +00001077 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001078}
1079
1080/**
1081 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
1082 * @adapter: board private structure to initialize
1083 *
1084 * We determine which interrupt scheme to use based on...
1085 * - Kernel support (MSI, MSI-X)
1086 * - which can be user-defined (via MODULE_PARAM)
1087 * - Hardware queue count (num_*_queues)
1088 * - defined by miscellaneous hardware support/features (RSS, etc.)
1089 **/
1090int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
1091{
1092 int err;
1093
1094 /* Number of supported queues */
Alexander Duyckac802f52012-07-12 05:52:53 +00001095 ixgbe_set_num_queues(adapter);
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001096
Alexander Duyckac802f52012-07-12 05:52:53 +00001097 /* Set interrupt mode */
1098 ixgbe_set_interrupt_capability(adapter);
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001099
1100 err = ixgbe_alloc_q_vectors(adapter);
1101 if (err) {
1102 e_dev_err("Unable to allocate memory for queue vectors\n");
1103 goto err_alloc_q_vectors;
1104 }
1105
1106 ixgbe_cache_ring_register(adapter);
1107
1108 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
1109 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
1110 adapter->num_rx_queues, adapter->num_tx_queues);
1111
1112 set_bit(__IXGBE_DOWN, &adapter->state);
1113
1114 return 0;
1115
1116err_alloc_q_vectors:
1117 ixgbe_reset_interrupt_capability(adapter);
Jeff Kirsher8af3c332012-02-18 07:08:14 +00001118 return err;
1119}
1120
1121/**
1122 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
1123 * @adapter: board private structure to clear interrupt scheme on
1124 *
1125 * We go through and clear interrupt specific resources and reset the structure
1126 * to pre-load conditions
1127 **/
1128void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
1129{
1130 adapter->num_tx_queues = 0;
1131 adapter->num_rx_queues = 0;
1132
1133 ixgbe_free_q_vectors(adapter);
1134 ixgbe_reset_interrupt_capability(adapter);
1135}
1136
1137void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
1138 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
1139{
1140 struct ixgbe_adv_tx_context_desc *context_desc;
1141 u16 i = tx_ring->next_to_use;
1142
1143 context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
1144
1145 i++;
1146 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
1147
1148 /* set bits to identify this as an advanced context descriptor */
1149 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
1150
1151 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
1152 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
1153 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
1154 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
1155}
1156