ixgbe_lib.c 34 KB

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