ixgbe_lib.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219
  1. /*******************************************************************************
  2. Intel 10 Gigabit PCI Express Linux driver
  3. Copyright(c) 1999 - 2013 Intel Corporation.
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. #include "ixgbe.h"
  22. #include "ixgbe_sriov.h"
  23. #ifdef CONFIG_IXGBE_DCB
  24. /**
  25. * ixgbe_cache_ring_dcb_sriov - Descriptor ring to register mapping for SR-IOV
  26. * @adapter: board private structure to initialize
  27. *
  28. * Cache the descriptor ring offsets for SR-IOV to the assigned rings. It
  29. * will also try to cache the proper offsets if RSS/FCoE are enabled along
  30. * with VMDq.
  31. *
  32. **/
  33. static bool ixgbe_cache_ring_dcb_sriov(struct ixgbe_adapter *adapter)
  34. {
  35. #ifdef IXGBE_FCOE
  36. struct ixgbe_ring_feature *fcoe = &adapter->ring_feature[RING_F_FCOE];
  37. #endif /* IXGBE_FCOE */
  38. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  39. int i;
  40. u16 reg_idx;
  41. u8 tcs = netdev_get_num_tc(adapter->netdev);
  42. /* verify we have DCB queueing enabled before proceeding */
  43. if (tcs <= 1)
  44. return false;
  45. /* verify we have VMDq enabled before proceeding */
  46. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  47. return false;
  48. /* start at VMDq register offset for SR-IOV enabled setups */
  49. reg_idx = vmdq->offset * __ALIGN_MASK(1, ~vmdq->mask);
  50. for (i = 0; i < adapter->num_rx_queues; i++, reg_idx++) {
  51. /* If we are greater than indices move to next pool */
  52. if ((reg_idx & ~vmdq->mask) >= tcs)
  53. reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask);
  54. adapter->rx_ring[i]->reg_idx = reg_idx;
  55. }
  56. reg_idx = vmdq->offset * __ALIGN_MASK(1, ~vmdq->mask);
  57. for (i = 0; i < adapter->num_tx_queues; i++, reg_idx++) {
  58. /* If we are greater than indices move to next pool */
  59. if ((reg_idx & ~vmdq->mask) >= tcs)
  60. reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask);
  61. adapter->tx_ring[i]->reg_idx = reg_idx;
  62. }
  63. #ifdef IXGBE_FCOE
  64. /* nothing to do if FCoE is disabled */
  65. if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
  66. return true;
  67. /* The work is already done if the FCoE ring is shared */
  68. if (fcoe->offset < tcs)
  69. return true;
  70. /* The FCoE rings exist separately, we need to move their reg_idx */
  71. if (fcoe->indices) {
  72. u16 queues_per_pool = __ALIGN_MASK(1, ~vmdq->mask);
  73. u8 fcoe_tc = ixgbe_fcoe_get_tc(adapter);
  74. reg_idx = (vmdq->offset + vmdq->indices) * queues_per_pool;
  75. for (i = fcoe->offset; i < adapter->num_rx_queues; i++) {
  76. reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask) + fcoe_tc;
  77. adapter->rx_ring[i]->reg_idx = reg_idx;
  78. reg_idx++;
  79. }
  80. reg_idx = (vmdq->offset + vmdq->indices) * queues_per_pool;
  81. for (i = fcoe->offset; i < adapter->num_tx_queues; i++) {
  82. reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask) + fcoe_tc;
  83. adapter->tx_ring[i]->reg_idx = reg_idx;
  84. reg_idx++;
  85. }
  86. }
  87. #endif /* IXGBE_FCOE */
  88. return true;
  89. }
  90. /* ixgbe_get_first_reg_idx - Return first register index associated with ring */
  91. static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
  92. unsigned int *tx, unsigned int *rx)
  93. {
  94. struct net_device *dev = adapter->netdev;
  95. struct ixgbe_hw *hw = &adapter->hw;
  96. u8 num_tcs = netdev_get_num_tc(dev);
  97. *tx = 0;
  98. *rx = 0;
  99. switch (hw->mac.type) {
  100. case ixgbe_mac_82598EB:
  101. /* TxQs/TC: 4 RxQs/TC: 8 */
  102. *tx = tc << 2; /* 0, 4, 8, 12, 16, 20, 24, 28 */
  103. *rx = tc << 3; /* 0, 8, 16, 24, 32, 40, 48, 56 */
  104. break;
  105. case ixgbe_mac_82599EB:
  106. case ixgbe_mac_X540:
  107. if (num_tcs > 4) {
  108. /*
  109. * TCs : TC0/1 TC2/3 TC4-7
  110. * TxQs/TC: 32 16 8
  111. * RxQs/TC: 16 16 16
  112. */
  113. *rx = tc << 4;
  114. if (tc < 3)
  115. *tx = tc << 5; /* 0, 32, 64 */
  116. else if (tc < 5)
  117. *tx = (tc + 2) << 4; /* 80, 96 */
  118. else
  119. *tx = (tc + 8) << 3; /* 104, 112, 120 */
  120. } else {
  121. /*
  122. * TCs : TC0 TC1 TC2/3
  123. * TxQs/TC: 64 32 16
  124. * RxQs/TC: 32 32 32
  125. */
  126. *rx = tc << 5;
  127. if (tc < 2)
  128. *tx = tc << 6; /* 0, 64 */
  129. else
  130. *tx = (tc + 4) << 4; /* 96, 112 */
  131. }
  132. default:
  133. break;
  134. }
  135. }
  136. /**
  137. * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
  138. * @adapter: board private structure to initialize
  139. *
  140. * Cache the descriptor ring offsets for DCB to the assigned rings.
  141. *
  142. **/
  143. static bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
  144. {
  145. struct net_device *dev = adapter->netdev;
  146. unsigned int tx_idx, rx_idx;
  147. int tc, offset, rss_i, i;
  148. u8 num_tcs = netdev_get_num_tc(dev);
  149. /* verify we have DCB queueing enabled before proceeding */
  150. if (num_tcs <= 1)
  151. return false;
  152. rss_i = adapter->ring_feature[RING_F_RSS].indices;
  153. for (tc = 0, offset = 0; tc < num_tcs; tc++, offset += rss_i) {
  154. ixgbe_get_first_reg_idx(adapter, tc, &tx_idx, &rx_idx);
  155. for (i = 0; i < rss_i; i++, tx_idx++, rx_idx++) {
  156. adapter->tx_ring[offset + i]->reg_idx = tx_idx;
  157. adapter->rx_ring[offset + i]->reg_idx = rx_idx;
  158. adapter->tx_ring[offset + i]->dcb_tc = tc;
  159. adapter->rx_ring[offset + i]->dcb_tc = tc;
  160. }
  161. }
  162. return true;
  163. }
  164. #endif
  165. /**
  166. * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
  167. * @adapter: board private structure to initialize
  168. *
  169. * SR-IOV doesn't use any descriptor rings but changes the default if
  170. * no other mapping is used.
  171. *
  172. */
  173. static bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
  174. {
  175. #ifdef IXGBE_FCOE
  176. struct ixgbe_ring_feature *fcoe = &adapter->ring_feature[RING_F_FCOE];
  177. #endif /* IXGBE_FCOE */
  178. struct ixgbe_ring_feature *vmdq = &adapter->ring_feature[RING_F_VMDQ];
  179. struct ixgbe_ring_feature *rss = &adapter->ring_feature[RING_F_RSS];
  180. int i;
  181. u16 reg_idx;
  182. /* only proceed if VMDq is enabled */
  183. if (!(adapter->flags & IXGBE_FLAG_VMDQ_ENABLED))
  184. return false;
  185. /* start at VMDq register offset for SR-IOV enabled setups */
  186. reg_idx = vmdq->offset * __ALIGN_MASK(1, ~vmdq->mask);
  187. for (i = 0; i < adapter->num_rx_queues; i++, reg_idx++) {
  188. #ifdef IXGBE_FCOE
  189. /* Allow first FCoE queue to be mapped as RSS */
  190. if (fcoe->offset && (i > fcoe->offset))
  191. break;
  192. #endif
  193. /* If we are greater than indices move to next pool */
  194. if ((reg_idx & ~vmdq->mask) >= rss->indices)
  195. reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask);
  196. adapter->rx_ring[i]->reg_idx = reg_idx;
  197. }
  198. #ifdef IXGBE_FCOE
  199. /* FCoE uses a linear block of queues so just assigning 1:1 */
  200. for (; i < adapter->num_rx_queues; i++, reg_idx++)
  201. adapter->rx_ring[i]->reg_idx = reg_idx;
  202. #endif
  203. reg_idx = vmdq->offset * __ALIGN_MASK(1, ~vmdq->mask);
  204. for (i = 0; i < adapter->num_tx_queues; i++, reg_idx++) {
  205. #ifdef IXGBE_FCOE
  206. /* Allow first FCoE queue to be mapped as RSS */
  207. if (fcoe->offset && (i > fcoe->offset))
  208. break;
  209. #endif
  210. /* If we are greater than indices move to next pool */
  211. if ((reg_idx & rss->mask) >= rss->indices)
  212. reg_idx = __ALIGN_MASK(reg_idx, ~vmdq->mask);
  213. adapter->tx_ring[i]->reg_idx = reg_idx;
  214. }
  215. #ifdef IXGBE_FCOE
  216. /* FCoE uses a linear block of queues so just assigning 1:1 */
  217. for (; i < adapter->num_tx_queues; i++, reg_idx++)
  218. adapter->tx_ring[i]->reg_idx = reg_idx;
  219. #endif
  220. return true;
  221. }
  222. /**
  223. * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
  224. * @adapter: board private structure to initialize
  225. *
  226. * Cache the descriptor ring offsets for RSS to the assigned rings.
  227. *
  228. **/
  229. static bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
  230. {
  231. int i;
  232. for (i = 0; i < adapter->num_rx_queues; i++)
  233. adapter->rx_ring[i]->reg_idx = i;
  234. for (i = 0; i < adapter->num_tx_queues; i++)
  235. adapter->tx_ring[i]->reg_idx = i;
  236. return true;
  237. }
  238. /**
  239. * ixgbe_cache_ring_register - Descriptor ring to register mapping
  240. * @adapter: board private structure to initialize
  241. *
  242. * Once we know the feature-set enabled for the device, we'll cache
  243. * the register offset the descriptor ring is assigned to.
  244. *
  245. * Note, the order the various feature calls is important. It must start with
  246. * the "most" features enabled at the same time, then trickle down to the
  247. * least amount of features turned on at once.
  248. **/
  249. static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
  250. {
  251. /* start with default case */
  252. adapter->rx_ring[0]->reg_idx = 0;
  253. adapter->tx_ring[0]->reg_idx = 0;
  254. #ifdef CONFIG_IXGBE_DCB
  255. if (ixgbe_cache_ring_dcb_sriov(adapter))
  256. return;
  257. if (ixgbe_cache_ring_dcb(adapter))
  258. return;
  259. #endif
  260. if (ixgbe_cache_ring_sriov(adapter))
  261. return;
  262. ixgbe_cache_ring_rss(adapter);
  263. }
  264. #define IXGBE_RSS_16Q_MASK 0xF
  265. #define IXGBE_RSS_8Q_MASK 0x7
  266. #define IXGBE_RSS_4Q_MASK 0x3
  267. #define IXGBE_RSS_2Q_MASK 0x1
  268. #define IXGBE_RSS_DISABLED_MASK 0x0
  269. #ifdef CONFIG_IXGBE_DCB
  270. /**
  271. * ixgbe_set_dcb_sriov_queues: Allocate queues for SR-IOV devices w/ DCB
  272. * @adapter: board private structure to initialize
  273. *
  274. * When SR-IOV (Single Root IO Virtualiztion) is enabled, allocate queues
  275. * and VM pools where appropriate. Also assign queues based on DCB
  276. * priorities and map accordingly..
  277. *
  278. **/
  279. static bool ixgbe_set_dcb_sriov_queues(struct ixgbe_adapter *adapter)
  280. {
  281. int i;
  282. u16 vmdq_i = adapter->ring_feature[RING_F_VMDQ].limit;
  283. u16 vmdq_m = 0;
  284. #ifdef IXGBE_FCOE
  285. u16 fcoe_i = 0;
  286. #endif
  287. u8 tcs = netdev_get_num_tc(adapter->netdev);
  288. /* verify we have DCB queueing enabled before proceeding */
  289. if (tcs <= 1)
  290. return false;
  291. /* verify we have VMDq enabled before proceeding */
  292. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  293. return false;
  294. /* Add starting offset to total pool count */
  295. vmdq_i += adapter->ring_feature[RING_F_VMDQ].offset;
  296. /* 16 pools w/ 8 TC per pool */
  297. if (tcs > 4) {
  298. vmdq_i = min_t(u16, vmdq_i, 16);
  299. vmdq_m = IXGBE_82599_VMDQ_8Q_MASK;
  300. /* 32 pools w/ 4 TC per pool */
  301. } else {
  302. vmdq_i = min_t(u16, vmdq_i, 32);
  303. vmdq_m = IXGBE_82599_VMDQ_4Q_MASK;
  304. }
  305. #ifdef IXGBE_FCOE
  306. /* queues in the remaining pools are available for FCoE */
  307. fcoe_i = (128 / __ALIGN_MASK(1, ~vmdq_m)) - vmdq_i;
  308. #endif
  309. /* remove the starting offset from the pool count */
  310. vmdq_i -= adapter->ring_feature[RING_F_VMDQ].offset;
  311. /* save features for later use */
  312. adapter->ring_feature[RING_F_VMDQ].indices = vmdq_i;
  313. adapter->ring_feature[RING_F_VMDQ].mask = vmdq_m;
  314. /*
  315. * We do not support DCB, VMDq, and RSS all simultaneously
  316. * so we will disable RSS since it is the lowest priority
  317. */
  318. adapter->ring_feature[RING_F_RSS].indices = 1;
  319. adapter->ring_feature[RING_F_RSS].mask = IXGBE_RSS_DISABLED_MASK;
  320. /* disable ATR as it is not supported when VMDq is enabled */
  321. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  322. adapter->num_rx_pools = vmdq_i;
  323. adapter->num_rx_queues_per_pool = tcs;
  324. adapter->num_tx_queues = vmdq_i * tcs;
  325. adapter->num_rx_queues = vmdq_i * tcs;
  326. #ifdef IXGBE_FCOE
  327. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  328. struct ixgbe_ring_feature *fcoe;
  329. fcoe = &adapter->ring_feature[RING_F_FCOE];
  330. /* limit ourselves based on feature limits */
  331. fcoe_i = min_t(u16, fcoe_i, fcoe->limit);
  332. if (fcoe_i) {
  333. /* alloc queues for FCoE separately */
  334. fcoe->indices = fcoe_i;
  335. fcoe->offset = vmdq_i * tcs;
  336. /* add queues to adapter */
  337. adapter->num_tx_queues += fcoe_i;
  338. adapter->num_rx_queues += fcoe_i;
  339. } else if (tcs > 1) {
  340. /* use queue belonging to FcoE TC */
  341. fcoe->indices = 1;
  342. fcoe->offset = ixgbe_fcoe_get_tc(adapter);
  343. } else {
  344. adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
  345. fcoe->indices = 0;
  346. fcoe->offset = 0;
  347. }
  348. }
  349. #endif /* IXGBE_FCOE */
  350. /* configure TC to queue mapping */
  351. for (i = 0; i < tcs; i++)
  352. netdev_set_tc_queue(adapter->netdev, i, 1, i);
  353. return true;
  354. }
  355. static bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
  356. {
  357. struct net_device *dev = adapter->netdev;
  358. struct ixgbe_ring_feature *f;
  359. int rss_i, rss_m, i;
  360. int tcs;
  361. /* Map queue offset and counts onto allocated tx queues */
  362. tcs = netdev_get_num_tc(dev);
  363. /* verify we have DCB queueing enabled before proceeding */
  364. if (tcs <= 1)
  365. return false;
  366. /* determine the upper limit for our current DCB mode */
  367. rss_i = dev->num_tx_queues / tcs;
  368. if (adapter->hw.mac.type == ixgbe_mac_82598EB) {
  369. /* 8 TC w/ 4 queues per TC */
  370. rss_i = min_t(u16, rss_i, 4);
  371. rss_m = IXGBE_RSS_4Q_MASK;
  372. } else if (tcs > 4) {
  373. /* 8 TC w/ 8 queues per TC */
  374. rss_i = min_t(u16, rss_i, 8);
  375. rss_m = IXGBE_RSS_8Q_MASK;
  376. } else {
  377. /* 4 TC w/ 16 queues per TC */
  378. rss_i = min_t(u16, rss_i, 16);
  379. rss_m = IXGBE_RSS_16Q_MASK;
  380. }
  381. /* set RSS mask and indices */
  382. f = &adapter->ring_feature[RING_F_RSS];
  383. rss_i = min_t(int, rss_i, f->limit);
  384. f->indices = rss_i;
  385. f->mask = rss_m;
  386. /* disable ATR as it is not supported when multiple TCs are enabled */
  387. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  388. #ifdef IXGBE_FCOE
  389. /* FCoE enabled queues require special configuration indexed
  390. * by feature specific indices and offset. Here we map FCoE
  391. * indices onto the DCB queue pairs allowing FCoE to own
  392. * configuration later.
  393. */
  394. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  395. u8 tc = ixgbe_fcoe_get_tc(adapter);
  396. f = &adapter->ring_feature[RING_F_FCOE];
  397. f->indices = min_t(u16, rss_i, f->limit);
  398. f->offset = rss_i * tc;
  399. }
  400. #endif /* IXGBE_FCOE */
  401. for (i = 0; i < tcs; i++)
  402. netdev_set_tc_queue(dev, i, rss_i, rss_i * i);
  403. adapter->num_tx_queues = rss_i * tcs;
  404. adapter->num_rx_queues = rss_i * tcs;
  405. return true;
  406. }
  407. #endif
  408. /**
  409. * ixgbe_set_sriov_queues - Allocate queues for SR-IOV devices
  410. * @adapter: board private structure to initialize
  411. *
  412. * When SR-IOV (Single Root IO Virtualiztion) is enabled, allocate queues
  413. * and VM pools where appropriate. If RSS is available, then also try and
  414. * enable RSS and map accordingly.
  415. *
  416. **/
  417. static bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
  418. {
  419. u16 vmdq_i = adapter->ring_feature[RING_F_VMDQ].limit;
  420. u16 vmdq_m = 0;
  421. u16 rss_i = adapter->ring_feature[RING_F_RSS].limit;
  422. u16 rss_m = IXGBE_RSS_DISABLED_MASK;
  423. #ifdef IXGBE_FCOE
  424. u16 fcoe_i = 0;
  425. #endif
  426. bool pools = (find_first_zero_bit(&adapter->fwd_bitmask, 32) > 1);
  427. /* only proceed if SR-IOV is enabled */
  428. if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
  429. return false;
  430. /* Add starting offset to total pool count */
  431. vmdq_i += adapter->ring_feature[RING_F_VMDQ].offset;
  432. /* double check we are limited to maximum pools */
  433. vmdq_i = min_t(u16, IXGBE_MAX_VMDQ_INDICES, vmdq_i);
  434. /* 64 pool mode with 2 queues per pool */
  435. if ((vmdq_i > 32) || (rss_i < 4) || (vmdq_i > 16 && pools)) {
  436. vmdq_m = IXGBE_82599_VMDQ_2Q_MASK;
  437. rss_m = IXGBE_RSS_2Q_MASK;
  438. rss_i = min_t(u16, rss_i, 2);
  439. /* 32 pool mode with 4 queues per pool */
  440. } else {
  441. vmdq_m = IXGBE_82599_VMDQ_4Q_MASK;
  442. rss_m = IXGBE_RSS_4Q_MASK;
  443. rss_i = 4;
  444. }
  445. #ifdef IXGBE_FCOE
  446. /* queues in the remaining pools are available for FCoE */
  447. fcoe_i = 128 - (vmdq_i * __ALIGN_MASK(1, ~vmdq_m));
  448. #endif
  449. /* remove the starting offset from the pool count */
  450. vmdq_i -= adapter->ring_feature[RING_F_VMDQ].offset;
  451. /* save features for later use */
  452. adapter->ring_feature[RING_F_VMDQ].indices = vmdq_i;
  453. adapter->ring_feature[RING_F_VMDQ].mask = vmdq_m;
  454. /* limit RSS based on user input and save for later use */
  455. adapter->ring_feature[RING_F_RSS].indices = rss_i;
  456. adapter->ring_feature[RING_F_RSS].mask = rss_m;
  457. adapter->num_rx_pools = vmdq_i;
  458. adapter->num_rx_queues_per_pool = rss_i;
  459. adapter->num_rx_queues = vmdq_i * rss_i;
  460. adapter->num_tx_queues = vmdq_i * rss_i;
  461. /* disable ATR as it is not supported when VMDq is enabled */
  462. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  463. #ifdef IXGBE_FCOE
  464. /*
  465. * FCoE can use rings from adjacent buffers to allow RSS
  466. * like behavior. To account for this we need to add the
  467. * FCoE indices to the total ring count.
  468. */
  469. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  470. struct ixgbe_ring_feature *fcoe;
  471. fcoe = &adapter->ring_feature[RING_F_FCOE];
  472. /* limit ourselves based on feature limits */
  473. fcoe_i = min_t(u16, fcoe_i, fcoe->limit);
  474. if (vmdq_i > 1 && fcoe_i) {
  475. /* alloc queues for FCoE separately */
  476. fcoe->indices = fcoe_i;
  477. fcoe->offset = vmdq_i * rss_i;
  478. } else {
  479. /* merge FCoE queues with RSS queues */
  480. fcoe_i = min_t(u16, fcoe_i + rss_i, num_online_cpus());
  481. /* limit indices to rss_i if MSI-X is disabled */
  482. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  483. fcoe_i = rss_i;
  484. /* attempt to reserve some queues for just FCoE */
  485. fcoe->indices = min_t(u16, fcoe_i, fcoe->limit);
  486. fcoe->offset = fcoe_i - fcoe->indices;
  487. fcoe_i -= rss_i;
  488. }
  489. /* add queues to adapter */
  490. adapter->num_tx_queues += fcoe_i;
  491. adapter->num_rx_queues += fcoe_i;
  492. }
  493. #endif
  494. return true;
  495. }
  496. /**
  497. * ixgbe_set_rss_queues - Allocate queues for RSS
  498. * @adapter: board private structure to initialize
  499. *
  500. * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
  501. * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
  502. *
  503. **/
  504. static bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
  505. {
  506. struct ixgbe_ring_feature *f;
  507. u16 rss_i;
  508. /* set mask for 16 queue limit of RSS */
  509. f = &adapter->ring_feature[RING_F_RSS];
  510. rss_i = f->limit;
  511. f->indices = rss_i;
  512. f->mask = IXGBE_RSS_16Q_MASK;
  513. /* disable ATR by default, it will be configured below */
  514. adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
  515. /*
  516. * Use Flow Director in addition to RSS to ensure the best
  517. * distribution of flows across cores, even when an FDIR flow
  518. * isn't matched.
  519. */
  520. if (rss_i > 1 && adapter->atr_sample_rate) {
  521. f = &adapter->ring_feature[RING_F_FDIR];
  522. rss_i = f->indices = f->limit;
  523. if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
  524. adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
  525. }
  526. #ifdef IXGBE_FCOE
  527. /*
  528. * FCoE can exist on the same rings as standard network traffic
  529. * however it is preferred to avoid that if possible. In order
  530. * to get the best performance we allocate as many FCoE queues
  531. * as we can and we place them at the end of the ring array to
  532. * avoid sharing queues with standard RSS on systems with 24 or
  533. * more CPUs.
  534. */
  535. if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
  536. struct net_device *dev = adapter->netdev;
  537. u16 fcoe_i;
  538. f = &adapter->ring_feature[RING_F_FCOE];
  539. /* merge FCoE queues with RSS queues */
  540. fcoe_i = min_t(u16, f->limit + rss_i, num_online_cpus());
  541. fcoe_i = min_t(u16, fcoe_i, dev->num_tx_queues);
  542. /* limit indices to rss_i if MSI-X is disabled */
  543. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  544. fcoe_i = rss_i;
  545. /* attempt to reserve some queues for just FCoE */
  546. f->indices = min_t(u16, fcoe_i, f->limit);
  547. f->offset = fcoe_i - f->indices;
  548. rss_i = max_t(u16, fcoe_i, rss_i);
  549. }
  550. #endif /* IXGBE_FCOE */
  551. adapter->num_rx_queues = rss_i;
  552. adapter->num_tx_queues = rss_i;
  553. return true;
  554. }
  555. /**
  556. * ixgbe_set_num_queues - Allocate queues for device, feature dependent
  557. * @adapter: board private structure to initialize
  558. *
  559. * This is the top level queue allocation routine. The order here is very
  560. * important, starting with the "most" number of features turned on at once,
  561. * and ending with the smallest set of features. This way large combinations
  562. * can be allocated if they're turned on, and smaller combinations are the
  563. * fallthrough conditions.
  564. *
  565. **/
  566. static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
  567. {
  568. /* Start with base case */
  569. adapter->num_rx_queues = 1;
  570. adapter->num_tx_queues = 1;
  571. adapter->num_rx_pools = adapter->num_rx_queues;
  572. adapter->num_rx_queues_per_pool = 1;
  573. #ifdef CONFIG_IXGBE_DCB
  574. if (ixgbe_set_dcb_sriov_queues(adapter))
  575. return;
  576. if (ixgbe_set_dcb_queues(adapter))
  577. return;
  578. #endif
  579. if (ixgbe_set_sriov_queues(adapter))
  580. return;
  581. ixgbe_set_rss_queues(adapter);
  582. }
  583. /**
  584. * ixgbe_acquire_msix_vectors - acquire MSI-X vectors
  585. * @adapter: board private structure
  586. *
  587. * Attempts to acquire a suitable range of MSI-X vector interrupts. Will
  588. * return a negative error code if unable to acquire MSI-X vectors for any
  589. * reason.
  590. */
  591. static int ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter)
  592. {
  593. struct ixgbe_hw *hw = &adapter->hw;
  594. int i, vectors, vector_threshold;
  595. /* We start by asking for one vector per queue pair */
  596. vectors = max(adapter->num_rx_queues, adapter->num_tx_queues);
  597. /* It is easy to be greedy for MSI-X vectors. However, it really
  598. * doesn't do much good if we have a lot more vectors than CPUs. We'll
  599. * be somewhat conservative and only ask for (roughly) the same number
  600. * of vectors as there are CPUs.
  601. */
  602. vectors = min_t(int, vectors, num_online_cpus());
  603. /* Some vectors are necessary for non-queue interrupts */
  604. vectors += NON_Q_VECTORS;
  605. /* Hardware can only support a maximum of hw.mac->max_msix_vectors.
  606. * With features such as RSS and VMDq, we can easily surpass the
  607. * number of Rx and Tx descriptor queues supported by our device.
  608. * Thus, we cap the maximum in the rare cases where the CPU count also
  609. * exceeds our vector limit
  610. */
  611. vectors = min_t(int, vectors, hw->mac.max_msix_vectors);
  612. /* We want a minimum of two MSI-X vectors for (1) a TxQ[0] + RxQ[0]
  613. * handler, and (2) an Other (Link Status Change, etc.) handler.
  614. */
  615. vector_threshold = MIN_MSIX_COUNT;
  616. adapter->msix_entries = kcalloc(vectors,
  617. sizeof(struct msix_entry),
  618. GFP_KERNEL);
  619. if (!adapter->msix_entries)
  620. return -ENOMEM;
  621. for (i = 0; i < vectors; i++)
  622. adapter->msix_entries[i].entry = i;
  623. vectors = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
  624. vector_threshold, vectors);
  625. if (vectors < 0) {
  626. /* A negative count of allocated vectors indicates an error in
  627. * acquiring within the specified range of MSI-X vectors
  628. */
  629. e_dev_warn("Failed to allocate MSI-X interrupts. Err: %d\n",
  630. vectors);
  631. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  632. kfree(adapter->msix_entries);
  633. adapter->msix_entries = NULL;
  634. return vectors;
  635. }
  636. /* we successfully allocated some number of vectors within our
  637. * requested range.
  638. */
  639. adapter->flags |= IXGBE_FLAG_MSIX_ENABLED;
  640. /* Adjust for only the vectors we'll use, which is minimum
  641. * of max_q_vectors, or the number of vectors we were allocated.
  642. */
  643. vectors -= NON_Q_VECTORS;
  644. adapter->num_q_vectors = min_t(int, vectors, adapter->max_q_vectors);
  645. return 0;
  646. }
  647. static void ixgbe_add_ring(struct ixgbe_ring *ring,
  648. struct ixgbe_ring_container *head)
  649. {
  650. ring->next = head->ring;
  651. head->ring = ring;
  652. head->count++;
  653. }
  654. /**
  655. * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector
  656. * @adapter: board private structure to initialize
  657. * @v_count: q_vectors allocated on adapter, used for ring interleaving
  658. * @v_idx: index of vector in adapter struct
  659. * @txr_count: total number of Tx rings to allocate
  660. * @txr_idx: index of first Tx ring to allocate
  661. * @rxr_count: total number of Rx rings to allocate
  662. * @rxr_idx: index of first Rx ring to allocate
  663. *
  664. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  665. **/
  666. static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter,
  667. int v_count, int v_idx,
  668. int txr_count, int txr_idx,
  669. int rxr_count, int rxr_idx)
  670. {
  671. struct ixgbe_q_vector *q_vector;
  672. struct ixgbe_ring *ring;
  673. int node = NUMA_NO_NODE;
  674. int cpu = -1;
  675. int ring_count, size;
  676. u8 tcs = netdev_get_num_tc(adapter->netdev);
  677. ring_count = txr_count + rxr_count;
  678. size = sizeof(struct ixgbe_q_vector) +
  679. (sizeof(struct ixgbe_ring) * ring_count);
  680. /* customize cpu for Flow Director mapping */
  681. if ((tcs <= 1) && !(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
  682. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  683. if (rss_i > 1 && adapter->atr_sample_rate) {
  684. if (cpu_online(v_idx)) {
  685. cpu = v_idx;
  686. node = cpu_to_node(cpu);
  687. }
  688. }
  689. }
  690. /* allocate q_vector and rings */
  691. q_vector = kzalloc_node(size, GFP_KERNEL, node);
  692. if (!q_vector)
  693. q_vector = kzalloc(size, GFP_KERNEL);
  694. if (!q_vector)
  695. return -ENOMEM;
  696. /* setup affinity mask and node */
  697. if (cpu != -1)
  698. cpumask_set_cpu(cpu, &q_vector->affinity_mask);
  699. q_vector->numa_node = node;
  700. #ifdef CONFIG_IXGBE_DCA
  701. /* initialize CPU for DCA */
  702. q_vector->cpu = -1;
  703. #endif
  704. /* initialize NAPI */
  705. netif_napi_add(adapter->netdev, &q_vector->napi,
  706. ixgbe_poll, 64);
  707. napi_hash_add(&q_vector->napi);
  708. #ifdef CONFIG_NET_RX_BUSY_POLL
  709. /* initialize busy poll */
  710. atomic_set(&q_vector->state, IXGBE_QV_STATE_DISABLE);
  711. #endif
  712. /* tie q_vector and adapter together */
  713. adapter->q_vector[v_idx] = q_vector;
  714. q_vector->adapter = adapter;
  715. q_vector->v_idx = v_idx;
  716. /* initialize work limits */
  717. q_vector->tx.work_limit = adapter->tx_work_limit;
  718. /* initialize pointer to rings */
  719. ring = q_vector->ring;
  720. /* intialize ITR */
  721. if (txr_count && !rxr_count) {
  722. /* tx only vector */
  723. if (adapter->tx_itr_setting == 1)
  724. q_vector->itr = IXGBE_10K_ITR;
  725. else
  726. q_vector->itr = adapter->tx_itr_setting;
  727. } else {
  728. /* rx or rx/tx vector */
  729. if (adapter->rx_itr_setting == 1)
  730. q_vector->itr = IXGBE_20K_ITR;
  731. else
  732. q_vector->itr = adapter->rx_itr_setting;
  733. }
  734. while (txr_count) {
  735. /* assign generic ring traits */
  736. ring->dev = &adapter->pdev->dev;
  737. ring->netdev = adapter->netdev;
  738. /* configure backlink on ring */
  739. ring->q_vector = q_vector;
  740. /* update q_vector Tx values */
  741. ixgbe_add_ring(ring, &q_vector->tx);
  742. /* apply Tx specific ring traits */
  743. ring->count = adapter->tx_ring_count;
  744. if (adapter->num_rx_pools > 1)
  745. ring->queue_index =
  746. txr_idx % adapter->num_rx_queues_per_pool;
  747. else
  748. ring->queue_index = txr_idx;
  749. /* assign ring to adapter */
  750. adapter->tx_ring[txr_idx] = ring;
  751. /* update count and index */
  752. txr_count--;
  753. txr_idx += v_count;
  754. /* push pointer to next ring */
  755. ring++;
  756. }
  757. while (rxr_count) {
  758. /* assign generic ring traits */
  759. ring->dev = &adapter->pdev->dev;
  760. ring->netdev = adapter->netdev;
  761. /* configure backlink on ring */
  762. ring->q_vector = q_vector;
  763. /* update q_vector Rx values */
  764. ixgbe_add_ring(ring, &q_vector->rx);
  765. /*
  766. * 82599 errata, UDP frames with a 0 checksum
  767. * can be marked as checksum errors.
  768. */
  769. if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  770. set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
  771. #ifdef IXGBE_FCOE
  772. if (adapter->netdev->features & NETIF_F_FCOE_MTU) {
  773. struct ixgbe_ring_feature *f;
  774. f = &adapter->ring_feature[RING_F_FCOE];
  775. if ((rxr_idx >= f->offset) &&
  776. (rxr_idx < f->offset + f->indices))
  777. set_bit(__IXGBE_RX_FCOE, &ring->state);
  778. }
  779. #endif /* IXGBE_FCOE */
  780. /* apply Rx specific ring traits */
  781. ring->count = adapter->rx_ring_count;
  782. if (adapter->num_rx_pools > 1)
  783. ring->queue_index =
  784. rxr_idx % adapter->num_rx_queues_per_pool;
  785. else
  786. ring->queue_index = rxr_idx;
  787. /* assign ring to adapter */
  788. adapter->rx_ring[rxr_idx] = ring;
  789. /* update count and index */
  790. rxr_count--;
  791. rxr_idx += v_count;
  792. /* push pointer to next ring */
  793. ring++;
  794. }
  795. return 0;
  796. }
  797. /**
  798. * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector
  799. * @adapter: board private structure to initialize
  800. * @v_idx: Index of vector to be freed
  801. *
  802. * This function frees the memory allocated to the q_vector. In addition if
  803. * NAPI is enabled it will delete any references to the NAPI struct prior
  804. * to freeing the q_vector.
  805. **/
  806. static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
  807. {
  808. struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
  809. struct ixgbe_ring *ring;
  810. ixgbe_for_each_ring(ring, q_vector->tx)
  811. adapter->tx_ring[ring->queue_index] = NULL;
  812. ixgbe_for_each_ring(ring, q_vector->rx)
  813. adapter->rx_ring[ring->queue_index] = NULL;
  814. adapter->q_vector[v_idx] = NULL;
  815. napi_hash_del(&q_vector->napi);
  816. netif_napi_del(&q_vector->napi);
  817. /*
  818. * ixgbe_get_stats64() might access the rings on this vector,
  819. * we must wait a grace period before freeing it.
  820. */
  821. kfree_rcu(q_vector, rcu);
  822. }
  823. /**
  824. * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
  825. * @adapter: board private structure to initialize
  826. *
  827. * We allocate one q_vector per queue interrupt. If allocation fails we
  828. * return -ENOMEM.
  829. **/
  830. static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
  831. {
  832. int q_vectors = adapter->num_q_vectors;
  833. int rxr_remaining = adapter->num_rx_queues;
  834. int txr_remaining = adapter->num_tx_queues;
  835. int rxr_idx = 0, txr_idx = 0, v_idx = 0;
  836. int err;
  837. /* only one q_vector if MSI-X is disabled. */
  838. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  839. q_vectors = 1;
  840. if (q_vectors >= (rxr_remaining + txr_remaining)) {
  841. for (; rxr_remaining; v_idx++) {
  842. err = ixgbe_alloc_q_vector(adapter, q_vectors, v_idx,
  843. 0, 0, 1, rxr_idx);
  844. if (err)
  845. goto err_out;
  846. /* update counts and index */
  847. rxr_remaining--;
  848. rxr_idx++;
  849. }
  850. }
  851. for (; v_idx < q_vectors; v_idx++) {
  852. int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
  853. int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
  854. err = ixgbe_alloc_q_vector(adapter, q_vectors, v_idx,
  855. tqpv, txr_idx,
  856. rqpv, rxr_idx);
  857. if (err)
  858. goto err_out;
  859. /* update counts and index */
  860. rxr_remaining -= rqpv;
  861. txr_remaining -= tqpv;
  862. rxr_idx++;
  863. txr_idx++;
  864. }
  865. return 0;
  866. err_out:
  867. adapter->num_tx_queues = 0;
  868. adapter->num_rx_queues = 0;
  869. adapter->num_q_vectors = 0;
  870. while (v_idx--)
  871. ixgbe_free_q_vector(adapter, v_idx);
  872. return -ENOMEM;
  873. }
  874. /**
  875. * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
  876. * @adapter: board private structure to initialize
  877. *
  878. * This function frees the memory allocated to the q_vectors. In addition if
  879. * NAPI is enabled it will delete any references to the NAPI struct prior
  880. * to freeing the q_vector.
  881. **/
  882. static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
  883. {
  884. int v_idx = adapter->num_q_vectors;
  885. adapter->num_tx_queues = 0;
  886. adapter->num_rx_queues = 0;
  887. adapter->num_q_vectors = 0;
  888. while (v_idx--)
  889. ixgbe_free_q_vector(adapter, v_idx);
  890. }
  891. static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
  892. {
  893. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  894. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  895. pci_disable_msix(adapter->pdev);
  896. kfree(adapter->msix_entries);
  897. adapter->msix_entries = NULL;
  898. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  899. adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
  900. pci_disable_msi(adapter->pdev);
  901. }
  902. }
  903. /**
  904. * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
  905. * @adapter: board private structure to initialize
  906. *
  907. * Attempt to configure the interrupts using the best available
  908. * capabilities of the hardware and the kernel.
  909. **/
  910. static void ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
  911. {
  912. int err;
  913. /* We will try to get MSI-X interrupts first */
  914. if (!ixgbe_acquire_msix_vectors(adapter))
  915. return;
  916. /* At this point, we do not have MSI-X capabilities. We need to
  917. * reconfigure or disable various features which require MSI-X
  918. * capability.
  919. */
  920. /* Disable DCB unless we only have a single traffic class */
  921. if (netdev_get_num_tc(adapter->netdev) > 1) {
  922. e_dev_warn("Number of DCB TCs exceeds number of available queues. Disabling DCB support.\n");
  923. netdev_reset_tc(adapter->netdev);
  924. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  925. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  926. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  927. adapter->temp_dcb_cfg.pfc_mode_enable = false;
  928. adapter->dcb_cfg.pfc_mode_enable = false;
  929. }
  930. adapter->dcb_cfg.num_tcs.pg_tcs = 1;
  931. adapter->dcb_cfg.num_tcs.pfc_tcs = 1;
  932. /* Disable SR-IOV support */
  933. e_dev_warn("Disabling SR-IOV support\n");
  934. ixgbe_disable_sriov(adapter);
  935. /* Disable RSS */
  936. e_dev_warn("Disabling RSS support\n");
  937. adapter->ring_feature[RING_F_RSS].limit = 1;
  938. /* recalculate number of queues now that many features have been
  939. * changed or disabled.
  940. */
  941. ixgbe_set_num_queues(adapter);
  942. adapter->num_q_vectors = 1;
  943. err = pci_enable_msi(adapter->pdev);
  944. if (err)
  945. e_dev_warn("Failed to allocate MSI interrupt, falling back to legacy. Error: %d\n",
  946. err);
  947. else
  948. adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
  949. }
  950. /**
  951. * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
  952. * @adapter: board private structure to initialize
  953. *
  954. * We determine which interrupt scheme to use based on...
  955. * - Kernel support (MSI, MSI-X)
  956. * - which can be user-defined (via MODULE_PARAM)
  957. * - Hardware queue count (num_*_queues)
  958. * - defined by miscellaneous hardware support/features (RSS, etc.)
  959. **/
  960. int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
  961. {
  962. int err;
  963. /* Number of supported queues */
  964. ixgbe_set_num_queues(adapter);
  965. /* Set interrupt mode */
  966. ixgbe_set_interrupt_capability(adapter);
  967. err = ixgbe_alloc_q_vectors(adapter);
  968. if (err) {
  969. e_dev_err("Unable to allocate memory for queue vectors\n");
  970. goto err_alloc_q_vectors;
  971. }
  972. ixgbe_cache_ring_register(adapter);
  973. e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
  974. (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
  975. adapter->num_rx_queues, adapter->num_tx_queues);
  976. set_bit(__IXGBE_DOWN, &adapter->state);
  977. return 0;
  978. err_alloc_q_vectors:
  979. ixgbe_reset_interrupt_capability(adapter);
  980. return err;
  981. }
  982. /**
  983. * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
  984. * @adapter: board private structure to clear interrupt scheme on
  985. *
  986. * We go through and clear interrupt specific resources and reset the structure
  987. * to pre-load conditions
  988. **/
  989. void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
  990. {
  991. adapter->num_tx_queues = 0;
  992. adapter->num_rx_queues = 0;
  993. ixgbe_free_q_vectors(adapter);
  994. ixgbe_reset_interrupt_capability(adapter);
  995. }
  996. void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
  997. u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
  998. {
  999. struct ixgbe_adv_tx_context_desc *context_desc;
  1000. u16 i = tx_ring->next_to_use;
  1001. context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
  1002. i++;
  1003. tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
  1004. /* set bits to identify this as an advanced context descriptor */
  1005. type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
  1006. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  1007. context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
  1008. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
  1009. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  1010. }