ixgbe_lib.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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. static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
  584. int vectors)
  585. {
  586. int vector_threshold;
  587. /* We'll want at least 2 (vector_threshold):
  588. * 1) TxQ[0] + RxQ[0] handler
  589. * 2) Other (Link Status Change, etc.)
  590. */
  591. vector_threshold = MIN_MSIX_COUNT;
  592. /*
  593. * The more we get, the more we will assign to Tx/Rx Cleanup
  594. * for the separate queues...where Rx Cleanup >= Tx Cleanup.
  595. * Right now, we simply care about how many we'll get; we'll
  596. * set them up later while requesting irq's.
  597. */
  598. vectors = pci_enable_msix_range(adapter->pdev, adapter->msix_entries,
  599. vector_threshold, vectors);
  600. if (vectors < 0) {
  601. /* Can't allocate enough MSI-X interrupts? Oh well.
  602. * This just means we'll go with either a single MSI
  603. * vector or fall back to legacy interrupts.
  604. */
  605. netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
  606. "Unable to allocate MSI-X interrupts\n");
  607. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  608. kfree(adapter->msix_entries);
  609. adapter->msix_entries = NULL;
  610. } else {
  611. adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
  612. /*
  613. * Adjust for only the vectors we'll use, which is minimum
  614. * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
  615. * vectors we were allocated.
  616. */
  617. vectors -= NON_Q_VECTORS;
  618. adapter->num_q_vectors = min(vectors, adapter->max_q_vectors);
  619. }
  620. }
  621. static void ixgbe_add_ring(struct ixgbe_ring *ring,
  622. struct ixgbe_ring_container *head)
  623. {
  624. ring->next = head->ring;
  625. head->ring = ring;
  626. head->count++;
  627. }
  628. /**
  629. * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector
  630. * @adapter: board private structure to initialize
  631. * @v_count: q_vectors allocated on adapter, used for ring interleaving
  632. * @v_idx: index of vector in adapter struct
  633. * @txr_count: total number of Tx rings to allocate
  634. * @txr_idx: index of first Tx ring to allocate
  635. * @rxr_count: total number of Rx rings to allocate
  636. * @rxr_idx: index of first Rx ring to allocate
  637. *
  638. * We allocate one q_vector. If allocation fails we return -ENOMEM.
  639. **/
  640. static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter,
  641. int v_count, int v_idx,
  642. int txr_count, int txr_idx,
  643. int rxr_count, int rxr_idx)
  644. {
  645. struct ixgbe_q_vector *q_vector;
  646. struct ixgbe_ring *ring;
  647. int node = NUMA_NO_NODE;
  648. int cpu = -1;
  649. int ring_count, size;
  650. u8 tcs = netdev_get_num_tc(adapter->netdev);
  651. ring_count = txr_count + rxr_count;
  652. size = sizeof(struct ixgbe_q_vector) +
  653. (sizeof(struct ixgbe_ring) * ring_count);
  654. /* customize cpu for Flow Director mapping */
  655. if ((tcs <= 1) && !(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)) {
  656. u16 rss_i = adapter->ring_feature[RING_F_RSS].indices;
  657. if (rss_i > 1 && adapter->atr_sample_rate) {
  658. if (cpu_online(v_idx)) {
  659. cpu = v_idx;
  660. node = cpu_to_node(cpu);
  661. }
  662. }
  663. }
  664. /* allocate q_vector and rings */
  665. q_vector = kzalloc_node(size, GFP_KERNEL, node);
  666. if (!q_vector)
  667. q_vector = kzalloc(size, GFP_KERNEL);
  668. if (!q_vector)
  669. return -ENOMEM;
  670. /* setup affinity mask and node */
  671. if (cpu != -1)
  672. cpumask_set_cpu(cpu, &q_vector->affinity_mask);
  673. q_vector->numa_node = node;
  674. #ifdef CONFIG_IXGBE_DCA
  675. /* initialize CPU for DCA */
  676. q_vector->cpu = -1;
  677. #endif
  678. /* initialize NAPI */
  679. netif_napi_add(adapter->netdev, &q_vector->napi,
  680. ixgbe_poll, 64);
  681. napi_hash_add(&q_vector->napi);
  682. /* tie q_vector and adapter together */
  683. adapter->q_vector[v_idx] = q_vector;
  684. q_vector->adapter = adapter;
  685. q_vector->v_idx = v_idx;
  686. /* initialize work limits */
  687. q_vector->tx.work_limit = adapter->tx_work_limit;
  688. /* initialize pointer to rings */
  689. ring = q_vector->ring;
  690. /* intialize ITR */
  691. if (txr_count && !rxr_count) {
  692. /* tx only vector */
  693. if (adapter->tx_itr_setting == 1)
  694. q_vector->itr = IXGBE_10K_ITR;
  695. else
  696. q_vector->itr = adapter->tx_itr_setting;
  697. } else {
  698. /* rx or rx/tx vector */
  699. if (adapter->rx_itr_setting == 1)
  700. q_vector->itr = IXGBE_20K_ITR;
  701. else
  702. q_vector->itr = adapter->rx_itr_setting;
  703. }
  704. while (txr_count) {
  705. /* assign generic ring traits */
  706. ring->dev = &adapter->pdev->dev;
  707. ring->netdev = adapter->netdev;
  708. /* configure backlink on ring */
  709. ring->q_vector = q_vector;
  710. /* update q_vector Tx values */
  711. ixgbe_add_ring(ring, &q_vector->tx);
  712. /* apply Tx specific ring traits */
  713. ring->count = adapter->tx_ring_count;
  714. if (adapter->num_rx_pools > 1)
  715. ring->queue_index =
  716. txr_idx % adapter->num_rx_queues_per_pool;
  717. else
  718. ring->queue_index = txr_idx;
  719. /* assign ring to adapter */
  720. adapter->tx_ring[txr_idx] = ring;
  721. /* update count and index */
  722. txr_count--;
  723. txr_idx += v_count;
  724. /* push pointer to next ring */
  725. ring++;
  726. }
  727. while (rxr_count) {
  728. /* assign generic ring traits */
  729. ring->dev = &adapter->pdev->dev;
  730. ring->netdev = adapter->netdev;
  731. /* configure backlink on ring */
  732. ring->q_vector = q_vector;
  733. /* update q_vector Rx values */
  734. ixgbe_add_ring(ring, &q_vector->rx);
  735. /*
  736. * 82599 errata, UDP frames with a 0 checksum
  737. * can be marked as checksum errors.
  738. */
  739. if (adapter->hw.mac.type == ixgbe_mac_82599EB)
  740. set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
  741. #ifdef IXGBE_FCOE
  742. if (adapter->netdev->features & NETIF_F_FCOE_MTU) {
  743. struct ixgbe_ring_feature *f;
  744. f = &adapter->ring_feature[RING_F_FCOE];
  745. if ((rxr_idx >= f->offset) &&
  746. (rxr_idx < f->offset + f->indices))
  747. set_bit(__IXGBE_RX_FCOE, &ring->state);
  748. }
  749. #endif /* IXGBE_FCOE */
  750. /* apply Rx specific ring traits */
  751. ring->count = adapter->rx_ring_count;
  752. if (adapter->num_rx_pools > 1)
  753. ring->queue_index =
  754. rxr_idx % adapter->num_rx_queues_per_pool;
  755. else
  756. ring->queue_index = rxr_idx;
  757. /* assign ring to adapter */
  758. adapter->rx_ring[rxr_idx] = ring;
  759. /* update count and index */
  760. rxr_count--;
  761. rxr_idx += v_count;
  762. /* push pointer to next ring */
  763. ring++;
  764. }
  765. return 0;
  766. }
  767. /**
  768. * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector
  769. * @adapter: board private structure to initialize
  770. * @v_idx: Index of vector to be freed
  771. *
  772. * This function frees the memory allocated to the q_vector. In addition if
  773. * NAPI is enabled it will delete any references to the NAPI struct prior
  774. * to freeing the q_vector.
  775. **/
  776. static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
  777. {
  778. struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
  779. struct ixgbe_ring *ring;
  780. ixgbe_for_each_ring(ring, q_vector->tx)
  781. adapter->tx_ring[ring->queue_index] = NULL;
  782. ixgbe_for_each_ring(ring, q_vector->rx)
  783. adapter->rx_ring[ring->queue_index] = NULL;
  784. adapter->q_vector[v_idx] = NULL;
  785. napi_hash_del(&q_vector->napi);
  786. netif_napi_del(&q_vector->napi);
  787. /*
  788. * ixgbe_get_stats64() might access the rings on this vector,
  789. * we must wait a grace period before freeing it.
  790. */
  791. kfree_rcu(q_vector, rcu);
  792. }
  793. /**
  794. * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
  795. * @adapter: board private structure to initialize
  796. *
  797. * We allocate one q_vector per queue interrupt. If allocation fails we
  798. * return -ENOMEM.
  799. **/
  800. static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
  801. {
  802. int q_vectors = adapter->num_q_vectors;
  803. int rxr_remaining = adapter->num_rx_queues;
  804. int txr_remaining = adapter->num_tx_queues;
  805. int rxr_idx = 0, txr_idx = 0, v_idx = 0;
  806. int err;
  807. /* only one q_vector if MSI-X is disabled. */
  808. if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
  809. q_vectors = 1;
  810. if (q_vectors >= (rxr_remaining + txr_remaining)) {
  811. for (; rxr_remaining; v_idx++) {
  812. err = ixgbe_alloc_q_vector(adapter, q_vectors, v_idx,
  813. 0, 0, 1, rxr_idx);
  814. if (err)
  815. goto err_out;
  816. /* update counts and index */
  817. rxr_remaining--;
  818. rxr_idx++;
  819. }
  820. }
  821. for (; v_idx < q_vectors; v_idx++) {
  822. int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_idx);
  823. int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_idx);
  824. err = ixgbe_alloc_q_vector(adapter, q_vectors, v_idx,
  825. tqpv, txr_idx,
  826. rqpv, rxr_idx);
  827. if (err)
  828. goto err_out;
  829. /* update counts and index */
  830. rxr_remaining -= rqpv;
  831. txr_remaining -= tqpv;
  832. rxr_idx++;
  833. txr_idx++;
  834. }
  835. return 0;
  836. err_out:
  837. adapter->num_tx_queues = 0;
  838. adapter->num_rx_queues = 0;
  839. adapter->num_q_vectors = 0;
  840. while (v_idx--)
  841. ixgbe_free_q_vector(adapter, v_idx);
  842. return -ENOMEM;
  843. }
  844. /**
  845. * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
  846. * @adapter: board private structure to initialize
  847. *
  848. * This function frees the memory allocated to the q_vectors. In addition if
  849. * NAPI is enabled it will delete any references to the NAPI struct prior
  850. * to freeing the q_vector.
  851. **/
  852. static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
  853. {
  854. int v_idx = adapter->num_q_vectors;
  855. adapter->num_tx_queues = 0;
  856. adapter->num_rx_queues = 0;
  857. adapter->num_q_vectors = 0;
  858. while (v_idx--)
  859. ixgbe_free_q_vector(adapter, v_idx);
  860. }
  861. static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
  862. {
  863. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
  864. adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
  865. pci_disable_msix(adapter->pdev);
  866. kfree(adapter->msix_entries);
  867. adapter->msix_entries = NULL;
  868. } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
  869. adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
  870. pci_disable_msi(adapter->pdev);
  871. }
  872. }
  873. /**
  874. * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
  875. * @adapter: board private structure to initialize
  876. *
  877. * Attempt to configure the interrupts using the best available
  878. * capabilities of the hardware and the kernel.
  879. **/
  880. static void ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
  881. {
  882. struct ixgbe_hw *hw = &adapter->hw;
  883. int vector, v_budget, err;
  884. /*
  885. * It's easy to be greedy for MSI-X vectors, but it really
  886. * doesn't do us much good if we have a lot more vectors
  887. * than CPU's. So let's be conservative and only ask for
  888. * (roughly) the same number of vectors as there are CPU's.
  889. * The default is to use pairs of vectors.
  890. */
  891. v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
  892. v_budget = min_t(int, v_budget, num_online_cpus());
  893. v_budget += NON_Q_VECTORS;
  894. /*
  895. * At the same time, hardware can only support a maximum of
  896. * hw.mac->max_msix_vectors vectors. With features
  897. * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
  898. * descriptor queues supported by our device. Thus, we cap it off in
  899. * those rare cases where the cpu count also exceeds our vector limit.
  900. */
  901. v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors);
  902. /* A failure in MSI-X entry allocation isn't fatal, but it does
  903. * mean we disable MSI-X capabilities of the adapter. */
  904. adapter->msix_entries = kcalloc(v_budget,
  905. sizeof(struct msix_entry), GFP_KERNEL);
  906. if (adapter->msix_entries) {
  907. for (vector = 0; vector < v_budget; vector++)
  908. adapter->msix_entries[vector].entry = vector;
  909. ixgbe_acquire_msix_vectors(adapter, v_budget);
  910. if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
  911. return;
  912. }
  913. /* disable DCB if number of TCs exceeds 1 */
  914. if (netdev_get_num_tc(adapter->netdev) > 1) {
  915. e_err(probe, "num TCs exceeds number of queues - disabling DCB\n");
  916. netdev_reset_tc(adapter->netdev);
  917. if (adapter->hw.mac.type == ixgbe_mac_82598EB)
  918. adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
  919. adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
  920. adapter->temp_dcb_cfg.pfc_mode_enable = false;
  921. adapter->dcb_cfg.pfc_mode_enable = false;
  922. }
  923. adapter->dcb_cfg.num_tcs.pg_tcs = 1;
  924. adapter->dcb_cfg.num_tcs.pfc_tcs = 1;
  925. /* disable SR-IOV */
  926. ixgbe_disable_sriov(adapter);
  927. /* disable RSS */
  928. adapter->ring_feature[RING_F_RSS].limit = 1;
  929. ixgbe_set_num_queues(adapter);
  930. adapter->num_q_vectors = 1;
  931. err = pci_enable_msi(adapter->pdev);
  932. if (err) {
  933. netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
  934. "Unable to allocate MSI interrupt, falling back to legacy. Error: %d\n",
  935. err);
  936. return;
  937. }
  938. adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
  939. }
  940. /**
  941. * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
  942. * @adapter: board private structure to initialize
  943. *
  944. * We determine which interrupt scheme to use based on...
  945. * - Kernel support (MSI, MSI-X)
  946. * - which can be user-defined (via MODULE_PARAM)
  947. * - Hardware queue count (num_*_queues)
  948. * - defined by miscellaneous hardware support/features (RSS, etc.)
  949. **/
  950. int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
  951. {
  952. int err;
  953. /* Number of supported queues */
  954. ixgbe_set_num_queues(adapter);
  955. /* Set interrupt mode */
  956. ixgbe_set_interrupt_capability(adapter);
  957. err = ixgbe_alloc_q_vectors(adapter);
  958. if (err) {
  959. e_dev_err("Unable to allocate memory for queue vectors\n");
  960. goto err_alloc_q_vectors;
  961. }
  962. ixgbe_cache_ring_register(adapter);
  963. e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
  964. (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
  965. adapter->num_rx_queues, adapter->num_tx_queues);
  966. set_bit(__IXGBE_DOWN, &adapter->state);
  967. return 0;
  968. err_alloc_q_vectors:
  969. ixgbe_reset_interrupt_capability(adapter);
  970. return err;
  971. }
  972. /**
  973. * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
  974. * @adapter: board private structure to clear interrupt scheme on
  975. *
  976. * We go through and clear interrupt specific resources and reset the structure
  977. * to pre-load conditions
  978. **/
  979. void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
  980. {
  981. adapter->num_tx_queues = 0;
  982. adapter->num_rx_queues = 0;
  983. ixgbe_free_q_vectors(adapter);
  984. ixgbe_reset_interrupt_capability(adapter);
  985. }
  986. void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
  987. u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
  988. {
  989. struct ixgbe_adv_tx_context_desc *context_desc;
  990. u16 i = tx_ring->next_to_use;
  991. context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
  992. i++;
  993. tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
  994. /* set bits to identify this as an advanced context descriptor */
  995. type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
  996. context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
  997. context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
  998. context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
  999. context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
  1000. }