ixgbe_lib.c 34 KB

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