ice_base.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. // SPDX-License-Identifier: GPL-2.0
  2. /* Copyright (c) 2019, Intel Corporation. */
  3. #include <net/xdp_sock_drv.h>
  4. #include "ice_base.h"
  5. #include "ice_lib.h"
  6. #include "ice_dcb_lib.h"
  7. #include "ice_sriov.h"
  8. /**
  9. * __ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI
  10. * @qs_cfg: gathered variables needed for PF->VSI queues assignment
  11. *
  12. * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
  13. */
  14. static int __ice_vsi_get_qs_contig(struct ice_qs_cfg *qs_cfg)
  15. {
  16. unsigned int offset, i;
  17. mutex_lock(qs_cfg->qs_mutex);
  18. offset = bitmap_find_next_zero_area(qs_cfg->pf_map, qs_cfg->pf_map_size,
  19. 0, qs_cfg->q_count, 0);
  20. if (offset >= qs_cfg->pf_map_size) {
  21. mutex_unlock(qs_cfg->qs_mutex);
  22. return -ENOMEM;
  23. }
  24. bitmap_set(qs_cfg->pf_map, offset, qs_cfg->q_count);
  25. for (i = 0; i < qs_cfg->q_count; i++)
  26. qs_cfg->vsi_map[i + qs_cfg->vsi_map_offset] = (u16)(i + offset);
  27. mutex_unlock(qs_cfg->qs_mutex);
  28. return 0;
  29. }
  30. /**
  31. * __ice_vsi_get_qs_sc - Assign a scattered queues from PF to VSI
  32. * @qs_cfg: gathered variables needed for pf->vsi queues assignment
  33. *
  34. * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
  35. */
  36. static int __ice_vsi_get_qs_sc(struct ice_qs_cfg *qs_cfg)
  37. {
  38. unsigned int i, index = 0;
  39. mutex_lock(qs_cfg->qs_mutex);
  40. for (i = 0; i < qs_cfg->q_count; i++) {
  41. index = find_next_zero_bit(qs_cfg->pf_map,
  42. qs_cfg->pf_map_size, index);
  43. if (index >= qs_cfg->pf_map_size)
  44. goto err_scatter;
  45. set_bit(index, qs_cfg->pf_map);
  46. qs_cfg->vsi_map[i + qs_cfg->vsi_map_offset] = (u16)index;
  47. }
  48. mutex_unlock(qs_cfg->qs_mutex);
  49. return 0;
  50. err_scatter:
  51. for (index = 0; index < i; index++) {
  52. clear_bit(qs_cfg->vsi_map[index], qs_cfg->pf_map);
  53. qs_cfg->vsi_map[index + qs_cfg->vsi_map_offset] = 0;
  54. }
  55. mutex_unlock(qs_cfg->qs_mutex);
  56. return -ENOMEM;
  57. }
  58. /**
  59. * ice_pf_rxq_wait - Wait for a PF's Rx queue to be enabled or disabled
  60. * @pf: the PF being configured
  61. * @pf_q: the PF queue
  62. * @ena: enable or disable state of the queue
  63. *
  64. * This routine will wait for the given Rx queue of the PF to reach the
  65. * enabled or disabled state.
  66. * Returns -ETIMEDOUT in case of failing to reach the requested state after
  67. * multiple retries; else will return 0 in case of success.
  68. */
  69. static int ice_pf_rxq_wait(struct ice_pf *pf, int pf_q, bool ena)
  70. {
  71. int i;
  72. for (i = 0; i < ICE_Q_WAIT_MAX_RETRY; i++) {
  73. if (ena == !!(rd32(&pf->hw, QRX_CTRL(pf_q)) &
  74. QRX_CTRL_QENA_STAT_M))
  75. return 0;
  76. usleep_range(20, 40);
  77. }
  78. return -ETIMEDOUT;
  79. }
  80. /**
  81. * ice_vsi_alloc_q_vector - Allocate memory for a single interrupt vector
  82. * @vsi: the VSI being configured
  83. * @v_idx: index of the vector in the VSI struct
  84. *
  85. * We allocate one q_vector and set default value for ITR setting associated
  86. * with this q_vector. If allocation fails we return -ENOMEM.
  87. */
  88. static int ice_vsi_alloc_q_vector(struct ice_vsi *vsi, u16 v_idx)
  89. {
  90. struct ice_pf *pf = vsi->back;
  91. struct ice_q_vector *q_vector;
  92. int err;
  93. /* allocate q_vector */
  94. q_vector = kzalloc(sizeof(*q_vector), GFP_KERNEL);
  95. if (!q_vector)
  96. return -ENOMEM;
  97. q_vector->vsi = vsi;
  98. q_vector->v_idx = v_idx;
  99. q_vector->tx.itr_setting = ICE_DFLT_TX_ITR;
  100. q_vector->rx.itr_setting = ICE_DFLT_RX_ITR;
  101. q_vector->tx.itr_mode = ITR_DYNAMIC;
  102. q_vector->rx.itr_mode = ITR_DYNAMIC;
  103. q_vector->tx.type = ICE_TX_CONTAINER;
  104. q_vector->rx.type = ICE_RX_CONTAINER;
  105. q_vector->irq.index = -ENOENT;
  106. if (vsi->type == ICE_VSI_VF) {
  107. ice_calc_vf_reg_idx(vsi->vf, q_vector);
  108. goto out;
  109. } else if (vsi->type == ICE_VSI_CTRL && vsi->vf) {
  110. struct ice_vsi *ctrl_vsi = ice_get_vf_ctrl_vsi(pf, vsi);
  111. if (ctrl_vsi) {
  112. if (unlikely(!ctrl_vsi->q_vectors)) {
  113. err = -ENOENT;
  114. goto err_free_q_vector;
  115. }
  116. q_vector->irq = ctrl_vsi->q_vectors[0]->irq;
  117. goto skip_alloc;
  118. }
  119. }
  120. q_vector->irq = ice_alloc_irq(pf, vsi->irq_dyn_alloc);
  121. if (q_vector->irq.index < 0) {
  122. err = -ENOMEM;
  123. goto err_free_q_vector;
  124. }
  125. skip_alloc:
  126. q_vector->reg_idx = q_vector->irq.index;
  127. q_vector->vf_reg_idx = q_vector->irq.index;
  128. /* only set affinity_mask if the CPU is online */
  129. if (cpu_online(v_idx))
  130. cpumask_set_cpu(v_idx, &q_vector->affinity_mask);
  131. /* This will not be called in the driver load path because the netdev
  132. * will not be created yet. All other cases with register the NAPI
  133. * handler here (i.e. resume, reset/rebuild, etc.)
  134. */
  135. if (vsi->netdev)
  136. netif_napi_add(vsi->netdev, &q_vector->napi, ice_napi_poll);
  137. out:
  138. /* tie q_vector and VSI together */
  139. vsi->q_vectors[v_idx] = q_vector;
  140. return 0;
  141. err_free_q_vector:
  142. kfree(q_vector);
  143. return err;
  144. }
  145. /**
  146. * ice_free_q_vector - Free memory allocated for a specific interrupt vector
  147. * @vsi: VSI having the memory freed
  148. * @v_idx: index of the vector to be freed
  149. */
  150. static void ice_free_q_vector(struct ice_vsi *vsi, int v_idx)
  151. {
  152. struct ice_q_vector *q_vector;
  153. struct ice_pf *pf = vsi->back;
  154. struct ice_tx_ring *tx_ring;
  155. struct ice_rx_ring *rx_ring;
  156. struct device *dev;
  157. dev = ice_pf_to_dev(pf);
  158. if (!vsi->q_vectors[v_idx]) {
  159. dev_dbg(dev, "Queue vector at index %d not found\n", v_idx);
  160. return;
  161. }
  162. q_vector = vsi->q_vectors[v_idx];
  163. ice_for_each_tx_ring(tx_ring, vsi->q_vectors[v_idx]->tx)
  164. tx_ring->q_vector = NULL;
  165. ice_for_each_rx_ring(rx_ring, vsi->q_vectors[v_idx]->rx)
  166. rx_ring->q_vector = NULL;
  167. /* only VSI with an associated netdev is set up with NAPI */
  168. if (vsi->netdev)
  169. netif_napi_del(&q_vector->napi);
  170. /* release MSIX interrupt if q_vector had interrupt allocated */
  171. if (q_vector->irq.index < 0)
  172. goto free_q_vector;
  173. /* only free last VF ctrl vsi interrupt */
  174. if (vsi->type == ICE_VSI_CTRL && vsi->vf &&
  175. ice_get_vf_ctrl_vsi(pf, vsi))
  176. goto free_q_vector;
  177. ice_free_irq(pf, q_vector->irq);
  178. free_q_vector:
  179. kfree(q_vector);
  180. vsi->q_vectors[v_idx] = NULL;
  181. }
  182. /**
  183. * ice_cfg_itr_gran - set the ITR granularity to 2 usecs if not already set
  184. * @hw: board specific structure
  185. */
  186. static void ice_cfg_itr_gran(struct ice_hw *hw)
  187. {
  188. u32 regval = rd32(hw, GLINT_CTL);
  189. /* no need to update global register if ITR gran is already set */
  190. if (!(regval & GLINT_CTL_DIS_AUTOMASK_M) &&
  191. (FIELD_GET(GLINT_CTL_ITR_GRAN_200_M, regval) == ICE_ITR_GRAN_US) &&
  192. (FIELD_GET(GLINT_CTL_ITR_GRAN_100_M, regval) == ICE_ITR_GRAN_US) &&
  193. (FIELD_GET(GLINT_CTL_ITR_GRAN_50_M, regval) == ICE_ITR_GRAN_US) &&
  194. (FIELD_GET(GLINT_CTL_ITR_GRAN_25_M, regval) == ICE_ITR_GRAN_US))
  195. return;
  196. regval = FIELD_PREP(GLINT_CTL_ITR_GRAN_200_M, ICE_ITR_GRAN_US) |
  197. FIELD_PREP(GLINT_CTL_ITR_GRAN_100_M, ICE_ITR_GRAN_US) |
  198. FIELD_PREP(GLINT_CTL_ITR_GRAN_50_M, ICE_ITR_GRAN_US) |
  199. FIELD_PREP(GLINT_CTL_ITR_GRAN_25_M, ICE_ITR_GRAN_US);
  200. wr32(hw, GLINT_CTL, regval);
  201. }
  202. /**
  203. * ice_calc_txq_handle - calculate the queue handle
  204. * @vsi: VSI that ring belongs to
  205. * @ring: ring to get the absolute queue index
  206. * @tc: traffic class number
  207. */
  208. static u16 ice_calc_txq_handle(struct ice_vsi *vsi, struct ice_tx_ring *ring, u8 tc)
  209. {
  210. WARN_ONCE(ice_ring_is_xdp(ring) && tc, "XDP ring can't belong to TC other than 0\n");
  211. if (ring->ch)
  212. return ring->q_index - ring->ch->base_q;
  213. /* Idea here for calculation is that we subtract the number of queue
  214. * count from TC that ring belongs to from it's absolute queue index
  215. * and as a result we get the queue's index within TC.
  216. */
  217. return ring->q_index - vsi->tc_cfg.tc_info[tc].qoffset;
  218. }
  219. /**
  220. * ice_cfg_xps_tx_ring - Configure XPS for a Tx ring
  221. * @ring: The Tx ring to configure
  222. *
  223. * This enables/disables XPS for a given Tx descriptor ring
  224. * based on the TCs enabled for the VSI that ring belongs to.
  225. */
  226. static void ice_cfg_xps_tx_ring(struct ice_tx_ring *ring)
  227. {
  228. if (!ring->q_vector || !ring->netdev)
  229. return;
  230. /* We only initialize XPS once, so as not to overwrite user settings */
  231. if (test_and_set_bit(ICE_TX_XPS_INIT_DONE, ring->xps_state))
  232. return;
  233. netif_set_xps_queue(ring->netdev, &ring->q_vector->affinity_mask,
  234. ring->q_index);
  235. }
  236. /**
  237. * ice_setup_tx_ctx - setup a struct ice_tlan_ctx instance
  238. * @ring: The Tx ring to configure
  239. * @tlan_ctx: Pointer to the Tx LAN queue context structure to be initialized
  240. * @pf_q: queue index in the PF space
  241. *
  242. * Configure the Tx descriptor ring in TLAN context.
  243. */
  244. static void
  245. ice_setup_tx_ctx(struct ice_tx_ring *ring, struct ice_tlan_ctx *tlan_ctx, u16 pf_q)
  246. {
  247. struct ice_vsi *vsi = ring->vsi;
  248. struct ice_hw *hw = &vsi->back->hw;
  249. tlan_ctx->base = ring->dma >> ICE_TLAN_CTX_BASE_S;
  250. tlan_ctx->port_num = vsi->port_info->lport;
  251. /* Transmit Queue Length */
  252. tlan_ctx->qlen = ring->count;
  253. ice_set_cgd_num(tlan_ctx, ring->dcb_tc);
  254. /* PF number */
  255. tlan_ctx->pf_num = hw->pf_id;
  256. /* queue belongs to a specific VSI type
  257. * VF / VM index should be programmed per vmvf_type setting:
  258. * for vmvf_type = VF, it is VF number between 0-256
  259. * for vmvf_type = VM, it is VM number between 0-767
  260. * for PF or EMP this field should be set to zero
  261. */
  262. switch (vsi->type) {
  263. case ICE_VSI_LB:
  264. case ICE_VSI_CTRL:
  265. case ICE_VSI_PF:
  266. if (ring->ch)
  267. tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_VMQ;
  268. else
  269. tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_PF;
  270. break;
  271. case ICE_VSI_VF:
  272. /* Firmware expects vmvf_num to be absolute VF ID */
  273. tlan_ctx->vmvf_num = hw->func_caps.vf_base_id + vsi->vf->vf_id;
  274. tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_VF;
  275. break;
  276. case ICE_VSI_SF:
  277. tlan_ctx->vmvf_type = ICE_TLAN_CTX_VMVF_TYPE_VMQ;
  278. break;
  279. default:
  280. return;
  281. }
  282. /* make sure the context is associated with the right VSI */
  283. if (ring->ch)
  284. tlan_ctx->src_vsi = ring->ch->vsi_num;
  285. else
  286. tlan_ctx->src_vsi = ice_get_hw_vsi_num(hw, vsi->idx);
  287. /* Restrict Tx timestamps to the PF VSI */
  288. switch (vsi->type) {
  289. case ICE_VSI_PF:
  290. tlan_ctx->tsyn_ena = 1;
  291. break;
  292. default:
  293. break;
  294. }
  295. tlan_ctx->tso_ena = ICE_TX_LEGACY;
  296. tlan_ctx->tso_qnum = pf_q;
  297. /* Legacy or Advanced Host Interface:
  298. * 0: Advanced Host Interface
  299. * 1: Legacy Host Interface
  300. */
  301. tlan_ctx->legacy_int = ICE_TX_LEGACY;
  302. }
  303. /**
  304. * ice_rx_offset - Return expected offset into page to access data
  305. * @rx_ring: Ring we are requesting offset of
  306. *
  307. * Returns the offset value for ring into the data buffer.
  308. */
  309. static unsigned int ice_rx_offset(struct ice_rx_ring *rx_ring)
  310. {
  311. if (ice_ring_uses_build_skb(rx_ring))
  312. return ICE_SKB_PAD;
  313. return 0;
  314. }
  315. /**
  316. * ice_setup_rx_ctx - Configure a receive ring context
  317. * @ring: The Rx ring to configure
  318. *
  319. * Configure the Rx descriptor ring in RLAN context.
  320. */
  321. static int ice_setup_rx_ctx(struct ice_rx_ring *ring)
  322. {
  323. struct ice_vsi *vsi = ring->vsi;
  324. u32 rxdid = ICE_RXDID_FLEX_NIC;
  325. struct ice_rlan_ctx rlan_ctx;
  326. struct ice_hw *hw;
  327. u16 pf_q;
  328. int err;
  329. hw = &vsi->back->hw;
  330. /* what is Rx queue number in global space of 2K Rx queues */
  331. pf_q = vsi->rxq_map[ring->q_index];
  332. /* clear the context structure first */
  333. memset(&rlan_ctx, 0, sizeof(rlan_ctx));
  334. /* Receive Queue Base Address.
  335. * Indicates the starting address of the descriptor queue defined in
  336. * 128 Byte units.
  337. */
  338. rlan_ctx.base = ring->dma >> ICE_RLAN_BASE_S;
  339. rlan_ctx.qlen = ring->count;
  340. /* Receive Packet Data Buffer Size.
  341. * The Packet Data Buffer Size is defined in 128 byte units.
  342. */
  343. rlan_ctx.dbuf = DIV_ROUND_UP(ring->rx_buf_len,
  344. BIT_ULL(ICE_RLAN_CTX_DBUF_S));
  345. /* use 32 byte descriptors */
  346. rlan_ctx.dsize = 1;
  347. /* Strip the Ethernet CRC bytes before the packet is posted to host
  348. * memory.
  349. */
  350. rlan_ctx.crcstrip = !(ring->flags & ICE_RX_FLAGS_CRC_STRIP_DIS);
  351. /* L2TSEL flag defines the reported L2 Tags in the receive descriptor
  352. * and it needs to remain 1 for non-DVM capable configurations to not
  353. * break backward compatibility for VF drivers. Setting this field to 0
  354. * will cause the single/outer VLAN tag to be stripped to the L2TAG2_2ND
  355. * field in the Rx descriptor. Setting it to 1 allows the VLAN tag to
  356. * be stripped in L2TAG1 of the Rx descriptor, which is where VFs will
  357. * check for the tag
  358. */
  359. if (ice_is_dvm_ena(hw))
  360. if (vsi->type == ICE_VSI_VF &&
  361. ice_vf_is_port_vlan_ena(vsi->vf))
  362. rlan_ctx.l2tsel = 1;
  363. else
  364. rlan_ctx.l2tsel = 0;
  365. else
  366. rlan_ctx.l2tsel = 1;
  367. rlan_ctx.dtype = ICE_RX_DTYPE_NO_SPLIT;
  368. rlan_ctx.hsplit_0 = ICE_RLAN_RX_HSPLIT_0_NO_SPLIT;
  369. rlan_ctx.hsplit_1 = ICE_RLAN_RX_HSPLIT_1_NO_SPLIT;
  370. /* This controls whether VLAN is stripped from inner headers
  371. * The VLAN in the inner L2 header is stripped to the receive
  372. * descriptor if enabled by this flag.
  373. */
  374. rlan_ctx.showiv = 0;
  375. /* Max packet size for this queue - must not be set to a larger value
  376. * than 5 x DBUF
  377. */
  378. rlan_ctx.rxmax = min_t(u32, ring->max_frame,
  379. ICE_MAX_CHAINED_RX_BUFS * ring->rx_buf_len);
  380. /* Rx queue threshold in units of 64 */
  381. rlan_ctx.lrxqthresh = 1;
  382. /* PF acts as uplink for switchdev; set flex descriptor with src_vsi
  383. * metadata and flags to allow redirecting to PR netdev
  384. */
  385. if (ice_is_eswitch_mode_switchdev(vsi->back)) {
  386. ring->flags |= ICE_RX_FLAGS_MULTIDEV;
  387. rxdid = ICE_RXDID_FLEX_NIC_2;
  388. }
  389. /* Enable Flexible Descriptors in the queue context which
  390. * allows this driver to select a specific receive descriptor format
  391. * increasing context priority to pick up profile ID; default is 0x01;
  392. * setting to 0x03 to ensure profile is programming if prev context is
  393. * of same priority
  394. */
  395. if (vsi->type != ICE_VSI_VF)
  396. ice_write_qrxflxp_cntxt(hw, pf_q, rxdid, 0x3, true);
  397. else
  398. ice_write_qrxflxp_cntxt(hw, pf_q, ICE_RXDID_LEGACY_1, 0x3,
  399. false);
  400. /* Absolute queue number out of 2K needs to be passed */
  401. err = ice_write_rxq_ctx(hw, &rlan_ctx, pf_q);
  402. if (err) {
  403. dev_err(ice_pf_to_dev(vsi->back), "Failed to set LAN Rx queue context for absolute Rx queue %d error: %d\n",
  404. pf_q, err);
  405. return -EIO;
  406. }
  407. if (vsi->type == ICE_VSI_VF)
  408. return 0;
  409. /* configure Rx buffer alignment */
  410. if (!vsi->netdev || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags))
  411. ice_clear_ring_build_skb_ena(ring);
  412. else
  413. ice_set_ring_build_skb_ena(ring);
  414. ring->rx_offset = ice_rx_offset(ring);
  415. /* init queue specific tail register */
  416. ring->tail = hw->hw_addr + QRX_TAIL(pf_q);
  417. writel(0, ring->tail);
  418. return 0;
  419. }
  420. static void ice_xsk_pool_fill_cb(struct ice_rx_ring *ring)
  421. {
  422. void *ctx_ptr = &ring->pkt_ctx;
  423. struct xsk_cb_desc desc = {};
  424. XSK_CHECK_PRIV_TYPE(struct ice_xdp_buff);
  425. desc.src = &ctx_ptr;
  426. desc.off = offsetof(struct ice_xdp_buff, pkt_ctx) -
  427. sizeof(struct xdp_buff);
  428. desc.bytes = sizeof(ctx_ptr);
  429. xsk_pool_fill_cb(ring->xsk_pool, &desc);
  430. }
  431. /**
  432. * ice_get_frame_sz - calculate xdp_buff::frame_sz
  433. * @rx_ring: the ring being configured
  434. *
  435. * Return frame size based on underlying PAGE_SIZE
  436. */
  437. static unsigned int ice_get_frame_sz(struct ice_rx_ring *rx_ring)
  438. {
  439. unsigned int frame_sz;
  440. #if (PAGE_SIZE >= 8192)
  441. frame_sz = rx_ring->rx_buf_len;
  442. #else
  443. frame_sz = ice_rx_pg_size(rx_ring) / 2;
  444. #endif
  445. return frame_sz;
  446. }
  447. /**
  448. * ice_vsi_cfg_rxq - Configure an Rx queue
  449. * @ring: the ring being configured
  450. *
  451. * Return 0 on success and a negative value on error.
  452. */
  453. static int ice_vsi_cfg_rxq(struct ice_rx_ring *ring)
  454. {
  455. struct device *dev = ice_pf_to_dev(ring->vsi->back);
  456. u32 num_bufs = ICE_RX_DESC_UNUSED(ring);
  457. int err;
  458. if (ring->vsi->type == ICE_VSI_PF || ring->vsi->type == ICE_VSI_SF) {
  459. if (!xdp_rxq_info_is_reg(&ring->xdp_rxq)) {
  460. err = __xdp_rxq_info_reg(&ring->xdp_rxq, ring->netdev,
  461. ring->q_index,
  462. ring->q_vector->napi.napi_id,
  463. ring->rx_buf_len);
  464. if (err)
  465. return err;
  466. }
  467. ice_rx_xsk_pool(ring);
  468. if (ring->xsk_pool) {
  469. xdp_rxq_info_unreg(&ring->xdp_rxq);
  470. ring->rx_buf_len =
  471. xsk_pool_get_rx_frame_size(ring->xsk_pool);
  472. err = __xdp_rxq_info_reg(&ring->xdp_rxq, ring->netdev,
  473. ring->q_index,
  474. ring->q_vector->napi.napi_id,
  475. ring->rx_buf_len);
  476. if (err)
  477. return err;
  478. err = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
  479. MEM_TYPE_XSK_BUFF_POOL,
  480. NULL);
  481. if (err)
  482. return err;
  483. xsk_pool_set_rxq_info(ring->xsk_pool, &ring->xdp_rxq);
  484. ice_xsk_pool_fill_cb(ring);
  485. dev_info(dev, "Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring %d\n",
  486. ring->q_index);
  487. } else {
  488. if (!xdp_rxq_info_is_reg(&ring->xdp_rxq)) {
  489. err = __xdp_rxq_info_reg(&ring->xdp_rxq, ring->netdev,
  490. ring->q_index,
  491. ring->q_vector->napi.napi_id,
  492. ring->rx_buf_len);
  493. if (err)
  494. return err;
  495. }
  496. err = xdp_rxq_info_reg_mem_model(&ring->xdp_rxq,
  497. MEM_TYPE_PAGE_SHARED,
  498. NULL);
  499. if (err)
  500. return err;
  501. }
  502. }
  503. xdp_init_buff(&ring->xdp, ice_get_frame_sz(ring), &ring->xdp_rxq);
  504. ring->xdp.data = NULL;
  505. ring->xdp_ext.pkt_ctx = &ring->pkt_ctx;
  506. err = ice_setup_rx_ctx(ring);
  507. if (err) {
  508. dev_err(dev, "ice_setup_rx_ctx failed for RxQ %d, err %d\n",
  509. ring->q_index, err);
  510. return err;
  511. }
  512. if (ring->xsk_pool) {
  513. bool ok;
  514. if (!xsk_buff_can_alloc(ring->xsk_pool, num_bufs)) {
  515. dev_warn(dev, "XSK buffer pool does not provide enough addresses to fill %d buffers on Rx ring %d\n",
  516. num_bufs, ring->q_index);
  517. dev_warn(dev, "Change Rx ring/fill queue size to avoid performance issues\n");
  518. return 0;
  519. }
  520. ok = ice_alloc_rx_bufs_zc(ring, ring->xsk_pool, num_bufs);
  521. if (!ok) {
  522. u16 pf_q = ring->vsi->rxq_map[ring->q_index];
  523. dev_info(dev, "Failed to allocate some buffers on XSK buffer pool enabled Rx ring %d (pf_q %d)\n",
  524. ring->q_index, pf_q);
  525. }
  526. return 0;
  527. }
  528. ice_alloc_rx_bufs(ring, num_bufs);
  529. return 0;
  530. }
  531. int ice_vsi_cfg_single_rxq(struct ice_vsi *vsi, u16 q_idx)
  532. {
  533. if (q_idx >= vsi->num_rxq)
  534. return -EINVAL;
  535. return ice_vsi_cfg_rxq(vsi->rx_rings[q_idx]);
  536. }
  537. /**
  538. * ice_vsi_cfg_frame_size - setup max frame size and Rx buffer length
  539. * @vsi: VSI
  540. * @ring: Rx ring to configure
  541. *
  542. * Determine the maximum frame size and Rx buffer length to use for a PF VSI.
  543. * Set these in the associated Rx ring structure.
  544. */
  545. static void ice_vsi_cfg_frame_size(struct ice_vsi *vsi, struct ice_rx_ring *ring)
  546. {
  547. if (!vsi->netdev || test_bit(ICE_FLAG_LEGACY_RX, vsi->back->flags)) {
  548. ring->max_frame = ICE_MAX_FRAME_LEGACY_RX;
  549. ring->rx_buf_len = ICE_RXBUF_1664;
  550. #if (PAGE_SIZE < 8192)
  551. } else if (!ICE_2K_TOO_SMALL_WITH_PADDING &&
  552. (vsi->netdev->mtu <= ETH_DATA_LEN)) {
  553. ring->max_frame = ICE_RXBUF_1536 - NET_IP_ALIGN;
  554. ring->rx_buf_len = ICE_RXBUF_1536 - NET_IP_ALIGN;
  555. #endif
  556. } else {
  557. ring->max_frame = ICE_AQ_SET_MAC_FRAME_SIZE_MAX;
  558. ring->rx_buf_len = ICE_RXBUF_3072;
  559. }
  560. }
  561. /**
  562. * ice_vsi_cfg_rxqs - Configure the VSI for Rx
  563. * @vsi: the VSI being configured
  564. *
  565. * Return 0 on success and a negative value on error
  566. * Configure the Rx VSI for operation.
  567. */
  568. int ice_vsi_cfg_rxqs(struct ice_vsi *vsi)
  569. {
  570. u16 i;
  571. /* set up individual rings */
  572. ice_for_each_rxq(vsi, i) {
  573. struct ice_rx_ring *ring = vsi->rx_rings[i];
  574. int err;
  575. if (vsi->type != ICE_VSI_VF)
  576. ice_vsi_cfg_frame_size(vsi, ring);
  577. err = ice_vsi_cfg_rxq(ring);
  578. if (err)
  579. return err;
  580. }
  581. return 0;
  582. }
  583. /**
  584. * __ice_vsi_get_qs - helper function for assigning queues from PF to VSI
  585. * @qs_cfg: gathered variables needed for pf->vsi queues assignment
  586. *
  587. * This function first tries to find contiguous space. If it is not successful,
  588. * it tries with the scatter approach.
  589. *
  590. * Return 0 on success and -ENOMEM in case of no left space in PF queue bitmap
  591. */
  592. int __ice_vsi_get_qs(struct ice_qs_cfg *qs_cfg)
  593. {
  594. int ret = 0;
  595. ret = __ice_vsi_get_qs_contig(qs_cfg);
  596. if (ret) {
  597. /* contig failed, so try with scatter approach */
  598. qs_cfg->mapping_mode = ICE_VSI_MAP_SCATTER;
  599. qs_cfg->q_count = min_t(unsigned int, qs_cfg->q_count,
  600. qs_cfg->scatter_count);
  601. ret = __ice_vsi_get_qs_sc(qs_cfg);
  602. }
  603. return ret;
  604. }
  605. /**
  606. * ice_vsi_ctrl_one_rx_ring - start/stop VSI's Rx ring with no busy wait
  607. * @vsi: the VSI being configured
  608. * @ena: start or stop the Rx ring
  609. * @rxq_idx: 0-based Rx queue index for the VSI passed in
  610. * @wait: wait or don't wait for configuration to finish in hardware
  611. *
  612. * Return 0 on success and negative on error.
  613. */
  614. int
  615. ice_vsi_ctrl_one_rx_ring(struct ice_vsi *vsi, bool ena, u16 rxq_idx, bool wait)
  616. {
  617. int pf_q = vsi->rxq_map[rxq_idx];
  618. struct ice_pf *pf = vsi->back;
  619. struct ice_hw *hw = &pf->hw;
  620. u32 rx_reg;
  621. rx_reg = rd32(hw, QRX_CTRL(pf_q));
  622. /* Skip if the queue is already in the requested state */
  623. if (ena == !!(rx_reg & QRX_CTRL_QENA_STAT_M))
  624. return 0;
  625. /* turn on/off the queue */
  626. if (ena)
  627. rx_reg |= QRX_CTRL_QENA_REQ_M;
  628. else
  629. rx_reg &= ~QRX_CTRL_QENA_REQ_M;
  630. wr32(hw, QRX_CTRL(pf_q), rx_reg);
  631. if (!wait)
  632. return 0;
  633. ice_flush(hw);
  634. return ice_pf_rxq_wait(pf, pf_q, ena);
  635. }
  636. /**
  637. * ice_vsi_wait_one_rx_ring - wait for a VSI's Rx ring to be stopped/started
  638. * @vsi: the VSI being configured
  639. * @ena: true/false to verify Rx ring has been enabled/disabled respectively
  640. * @rxq_idx: 0-based Rx queue index for the VSI passed in
  641. *
  642. * This routine will wait for the given Rx queue of the VSI to reach the
  643. * enabled or disabled state. Returns -ETIMEDOUT in case of failing to reach
  644. * the requested state after multiple retries; else will return 0 in case of
  645. * success.
  646. */
  647. int ice_vsi_wait_one_rx_ring(struct ice_vsi *vsi, bool ena, u16 rxq_idx)
  648. {
  649. int pf_q = vsi->rxq_map[rxq_idx];
  650. struct ice_pf *pf = vsi->back;
  651. return ice_pf_rxq_wait(pf, pf_q, ena);
  652. }
  653. /**
  654. * ice_vsi_alloc_q_vectors - Allocate memory for interrupt vectors
  655. * @vsi: the VSI being configured
  656. *
  657. * We allocate one q_vector per queue interrupt. If allocation fails we
  658. * return -ENOMEM.
  659. */
  660. int ice_vsi_alloc_q_vectors(struct ice_vsi *vsi)
  661. {
  662. struct device *dev = ice_pf_to_dev(vsi->back);
  663. u16 v_idx;
  664. int err;
  665. if (vsi->q_vectors[0]) {
  666. dev_dbg(dev, "VSI %d has existing q_vectors\n", vsi->vsi_num);
  667. return -EEXIST;
  668. }
  669. for (v_idx = 0; v_idx < vsi->num_q_vectors; v_idx++) {
  670. err = ice_vsi_alloc_q_vector(vsi, v_idx);
  671. if (err)
  672. goto err_out;
  673. }
  674. return 0;
  675. err_out:
  676. while (v_idx--)
  677. ice_free_q_vector(vsi, v_idx);
  678. dev_err(dev, "Failed to allocate %d q_vector for VSI %d, ret=%d\n",
  679. vsi->num_q_vectors, vsi->vsi_num, err);
  680. vsi->num_q_vectors = 0;
  681. return err;
  682. }
  683. /**
  684. * ice_vsi_map_rings_to_vectors - Map VSI rings to interrupt vectors
  685. * @vsi: the VSI being configured
  686. *
  687. * This function maps descriptor rings to the queue-specific vectors allotted
  688. * through the MSI-X enabling code. On a constrained vector budget, we map Tx
  689. * and Rx rings to the vector as "efficiently" as possible.
  690. */
  691. void ice_vsi_map_rings_to_vectors(struct ice_vsi *vsi)
  692. {
  693. int q_vectors = vsi->num_q_vectors;
  694. u16 tx_rings_rem, rx_rings_rem;
  695. int v_id;
  696. /* initially assigning remaining rings count to VSIs num queue value */
  697. tx_rings_rem = vsi->num_txq;
  698. rx_rings_rem = vsi->num_rxq;
  699. for (v_id = 0; v_id < q_vectors; v_id++) {
  700. struct ice_q_vector *q_vector = vsi->q_vectors[v_id];
  701. u8 tx_rings_per_v, rx_rings_per_v;
  702. u16 q_id, q_base;
  703. /* Tx rings mapping to vector */
  704. tx_rings_per_v = (u8)DIV_ROUND_UP(tx_rings_rem,
  705. q_vectors - v_id);
  706. q_vector->num_ring_tx = tx_rings_per_v;
  707. q_vector->tx.tx_ring = NULL;
  708. q_vector->tx.itr_idx = ICE_TX_ITR;
  709. q_base = vsi->num_txq - tx_rings_rem;
  710. for (q_id = q_base; q_id < (q_base + tx_rings_per_v); q_id++) {
  711. struct ice_tx_ring *tx_ring = vsi->tx_rings[q_id];
  712. tx_ring->q_vector = q_vector;
  713. tx_ring->next = q_vector->tx.tx_ring;
  714. q_vector->tx.tx_ring = tx_ring;
  715. }
  716. tx_rings_rem -= tx_rings_per_v;
  717. /* Rx rings mapping to vector */
  718. rx_rings_per_v = (u8)DIV_ROUND_UP(rx_rings_rem,
  719. q_vectors - v_id);
  720. q_vector->num_ring_rx = rx_rings_per_v;
  721. q_vector->rx.rx_ring = NULL;
  722. q_vector->rx.itr_idx = ICE_RX_ITR;
  723. q_base = vsi->num_rxq - rx_rings_rem;
  724. for (q_id = q_base; q_id < (q_base + rx_rings_per_v); q_id++) {
  725. struct ice_rx_ring *rx_ring = vsi->rx_rings[q_id];
  726. rx_ring->q_vector = q_vector;
  727. rx_ring->next = q_vector->rx.rx_ring;
  728. q_vector->rx.rx_ring = rx_ring;
  729. }
  730. rx_rings_rem -= rx_rings_per_v;
  731. }
  732. if (ice_is_xdp_ena_vsi(vsi))
  733. ice_map_xdp_rings(vsi);
  734. }
  735. /**
  736. * ice_vsi_free_q_vectors - Free memory allocated for interrupt vectors
  737. * @vsi: the VSI having memory freed
  738. */
  739. void ice_vsi_free_q_vectors(struct ice_vsi *vsi)
  740. {
  741. int v_idx;
  742. ice_for_each_q_vector(vsi, v_idx)
  743. ice_free_q_vector(vsi, v_idx);
  744. vsi->num_q_vectors = 0;
  745. }
  746. /**
  747. * ice_vsi_cfg_txq - Configure single Tx queue
  748. * @vsi: the VSI that queue belongs to
  749. * @ring: Tx ring to be configured
  750. * @qg_buf: queue group buffer
  751. */
  752. static int
  753. ice_vsi_cfg_txq(struct ice_vsi *vsi, struct ice_tx_ring *ring,
  754. struct ice_aqc_add_tx_qgrp *qg_buf)
  755. {
  756. u8 buf_len = struct_size(qg_buf, txqs, 1);
  757. struct ice_tlan_ctx tlan_ctx = { 0 };
  758. struct ice_aqc_add_txqs_perq *txq;
  759. struct ice_channel *ch = ring->ch;
  760. struct ice_pf *pf = vsi->back;
  761. struct ice_hw *hw = &pf->hw;
  762. int status;
  763. u16 pf_q;
  764. u8 tc;
  765. /* Configure XPS */
  766. ice_cfg_xps_tx_ring(ring);
  767. pf_q = ring->reg_idx;
  768. ice_setup_tx_ctx(ring, &tlan_ctx, pf_q);
  769. /* copy context contents into the qg_buf */
  770. qg_buf->txqs[0].txq_id = cpu_to_le16(pf_q);
  771. ice_set_ctx(hw, (u8 *)&tlan_ctx, qg_buf->txqs[0].txq_ctx,
  772. ice_tlan_ctx_info);
  773. /* init queue specific tail reg. It is referred as
  774. * transmit comm scheduler queue doorbell.
  775. */
  776. ring->tail = hw->hw_addr + QTX_COMM_DBELL(pf_q);
  777. if (IS_ENABLED(CONFIG_DCB))
  778. tc = ring->dcb_tc;
  779. else
  780. tc = 0;
  781. /* Add unique software queue handle of the Tx queue per
  782. * TC into the VSI Tx ring
  783. */
  784. ring->q_handle = ice_calc_txq_handle(vsi, ring, tc);
  785. if (ch)
  786. status = ice_ena_vsi_txq(vsi->port_info, ch->ch_vsi->idx, 0,
  787. ring->q_handle, 1, qg_buf, buf_len,
  788. NULL);
  789. else
  790. status = ice_ena_vsi_txq(vsi->port_info, vsi->idx, tc,
  791. ring->q_handle, 1, qg_buf, buf_len,
  792. NULL);
  793. if (status) {
  794. dev_err(ice_pf_to_dev(pf), "Failed to set LAN Tx queue context, error: %d\n",
  795. status);
  796. return status;
  797. }
  798. /* Add Tx Queue TEID into the VSI Tx ring from the
  799. * response. This will complete configuring and
  800. * enabling the queue.
  801. */
  802. txq = &qg_buf->txqs[0];
  803. if (pf_q == le16_to_cpu(txq->txq_id))
  804. ring->txq_teid = le32_to_cpu(txq->q_teid);
  805. return 0;
  806. }
  807. int ice_vsi_cfg_single_txq(struct ice_vsi *vsi, struct ice_tx_ring **tx_rings,
  808. u16 q_idx)
  809. {
  810. DEFINE_RAW_FLEX(struct ice_aqc_add_tx_qgrp, qg_buf, txqs, 1);
  811. if (q_idx >= vsi->alloc_txq || !tx_rings || !tx_rings[q_idx])
  812. return -EINVAL;
  813. qg_buf->num_txqs = 1;
  814. return ice_vsi_cfg_txq(vsi, tx_rings[q_idx], qg_buf);
  815. }
  816. /**
  817. * ice_vsi_cfg_txqs - Configure the VSI for Tx
  818. * @vsi: the VSI being configured
  819. * @rings: Tx ring array to be configured
  820. * @count: number of Tx ring array elements
  821. *
  822. * Return 0 on success and a negative value on error
  823. * Configure the Tx VSI for operation.
  824. */
  825. static int
  826. ice_vsi_cfg_txqs(struct ice_vsi *vsi, struct ice_tx_ring **rings, u16 count)
  827. {
  828. DEFINE_RAW_FLEX(struct ice_aqc_add_tx_qgrp, qg_buf, txqs, 1);
  829. int err = 0;
  830. u16 q_idx;
  831. qg_buf->num_txqs = 1;
  832. for (q_idx = 0; q_idx < count; q_idx++) {
  833. err = ice_vsi_cfg_txq(vsi, rings[q_idx], qg_buf);
  834. if (err)
  835. break;
  836. }
  837. return err;
  838. }
  839. /**
  840. * ice_vsi_cfg_lan_txqs - Configure the VSI for Tx
  841. * @vsi: the VSI being configured
  842. *
  843. * Return 0 on success and a negative value on error
  844. * Configure the Tx VSI for operation.
  845. */
  846. int ice_vsi_cfg_lan_txqs(struct ice_vsi *vsi)
  847. {
  848. return ice_vsi_cfg_txqs(vsi, vsi->tx_rings, vsi->num_txq);
  849. }
  850. /**
  851. * ice_vsi_cfg_xdp_txqs - Configure Tx queues dedicated for XDP in given VSI
  852. * @vsi: the VSI being configured
  853. *
  854. * Return 0 on success and a negative value on error
  855. * Configure the Tx queues dedicated for XDP in given VSI for operation.
  856. */
  857. int ice_vsi_cfg_xdp_txqs(struct ice_vsi *vsi)
  858. {
  859. int ret;
  860. int i;
  861. ret = ice_vsi_cfg_txqs(vsi, vsi->xdp_rings, vsi->num_xdp_txq);
  862. if (ret)
  863. return ret;
  864. ice_for_each_rxq(vsi, i)
  865. ice_tx_xsk_pool(vsi, i);
  866. return 0;
  867. }
  868. /**
  869. * ice_cfg_itr - configure the initial interrupt throttle values
  870. * @hw: pointer to the HW structure
  871. * @q_vector: interrupt vector that's being configured
  872. *
  873. * Configure interrupt throttling values for the ring containers that are
  874. * associated with the interrupt vector passed in.
  875. */
  876. void ice_cfg_itr(struct ice_hw *hw, struct ice_q_vector *q_vector)
  877. {
  878. ice_cfg_itr_gran(hw);
  879. if (q_vector->num_ring_rx)
  880. ice_write_itr(&q_vector->rx, q_vector->rx.itr_setting);
  881. if (q_vector->num_ring_tx)
  882. ice_write_itr(&q_vector->tx, q_vector->tx.itr_setting);
  883. ice_write_intrl(q_vector, q_vector->intrl);
  884. }
  885. /**
  886. * ice_cfg_txq_interrupt - configure interrupt on Tx queue
  887. * @vsi: the VSI being configured
  888. * @txq: Tx queue being mapped to MSI-X vector
  889. * @msix_idx: MSI-X vector index within the function
  890. * @itr_idx: ITR index of the interrupt cause
  891. *
  892. * Configure interrupt on Tx queue by associating Tx queue to MSI-X vector
  893. * within the function space.
  894. */
  895. void
  896. ice_cfg_txq_interrupt(struct ice_vsi *vsi, u16 txq, u16 msix_idx, u16 itr_idx)
  897. {
  898. struct ice_pf *pf = vsi->back;
  899. struct ice_hw *hw = &pf->hw;
  900. u32 val;
  901. itr_idx = FIELD_PREP(QINT_TQCTL_ITR_INDX_M, itr_idx);
  902. val = QINT_TQCTL_CAUSE_ENA_M | itr_idx |
  903. FIELD_PREP(QINT_TQCTL_MSIX_INDX_M, msix_idx);
  904. wr32(hw, QINT_TQCTL(vsi->txq_map[txq]), val);
  905. if (ice_is_xdp_ena_vsi(vsi)) {
  906. u32 xdp_txq = txq + vsi->num_xdp_txq;
  907. wr32(hw, QINT_TQCTL(vsi->txq_map[xdp_txq]),
  908. val);
  909. }
  910. ice_flush(hw);
  911. }
  912. /**
  913. * ice_cfg_rxq_interrupt - configure interrupt on Rx queue
  914. * @vsi: the VSI being configured
  915. * @rxq: Rx queue being mapped to MSI-X vector
  916. * @msix_idx: MSI-X vector index within the function
  917. * @itr_idx: ITR index of the interrupt cause
  918. *
  919. * Configure interrupt on Rx queue by associating Rx queue to MSI-X vector
  920. * within the function space.
  921. */
  922. void
  923. ice_cfg_rxq_interrupt(struct ice_vsi *vsi, u16 rxq, u16 msix_idx, u16 itr_idx)
  924. {
  925. struct ice_pf *pf = vsi->back;
  926. struct ice_hw *hw = &pf->hw;
  927. u32 val;
  928. itr_idx = FIELD_PREP(QINT_RQCTL_ITR_INDX_M, itr_idx);
  929. val = QINT_RQCTL_CAUSE_ENA_M | itr_idx |
  930. FIELD_PREP(QINT_RQCTL_MSIX_INDX_M, msix_idx);
  931. wr32(hw, QINT_RQCTL(vsi->rxq_map[rxq]), val);
  932. ice_flush(hw);
  933. }
  934. /**
  935. * ice_trigger_sw_intr - trigger a software interrupt
  936. * @hw: pointer to the HW structure
  937. * @q_vector: interrupt vector to trigger the software interrupt for
  938. */
  939. void ice_trigger_sw_intr(struct ice_hw *hw, const struct ice_q_vector *q_vector)
  940. {
  941. wr32(hw, GLINT_DYN_CTL(q_vector->reg_idx),
  942. (ICE_ITR_NONE << GLINT_DYN_CTL_ITR_INDX_S) |
  943. GLINT_DYN_CTL_SWINT_TRIG_M |
  944. GLINT_DYN_CTL_INTENA_M);
  945. }
  946. /**
  947. * ice_vsi_stop_tx_ring - Disable single Tx ring
  948. * @vsi: the VSI being configured
  949. * @rst_src: reset source
  950. * @rel_vmvf_num: Relative ID of VF/VM
  951. * @ring: Tx ring to be stopped
  952. * @txq_meta: Meta data of Tx ring to be stopped
  953. */
  954. int
  955. ice_vsi_stop_tx_ring(struct ice_vsi *vsi, enum ice_disq_rst_src rst_src,
  956. u16 rel_vmvf_num, struct ice_tx_ring *ring,
  957. struct ice_txq_meta *txq_meta)
  958. {
  959. struct ice_pf *pf = vsi->back;
  960. struct ice_q_vector *q_vector;
  961. struct ice_hw *hw = &pf->hw;
  962. int status;
  963. u32 val;
  964. /* clear cause_ena bit for disabled queues */
  965. val = rd32(hw, QINT_TQCTL(ring->reg_idx));
  966. val &= ~QINT_TQCTL_CAUSE_ENA_M;
  967. wr32(hw, QINT_TQCTL(ring->reg_idx), val);
  968. /* software is expected to wait for 100 ns */
  969. ndelay(100);
  970. /* trigger a software interrupt for the vector
  971. * associated to the queue to schedule NAPI handler
  972. */
  973. q_vector = ring->q_vector;
  974. if (q_vector && !(vsi->vf && ice_is_vf_disabled(vsi->vf)))
  975. ice_trigger_sw_intr(hw, q_vector);
  976. status = ice_dis_vsi_txq(vsi->port_info, txq_meta->vsi_idx,
  977. txq_meta->tc, 1, &txq_meta->q_handle,
  978. &txq_meta->q_id, &txq_meta->q_teid, rst_src,
  979. rel_vmvf_num, NULL);
  980. /* if the disable queue command was exercised during an
  981. * active reset flow, -EBUSY is returned.
  982. * This is not an error as the reset operation disables
  983. * queues at the hardware level anyway.
  984. */
  985. if (status == -EBUSY) {
  986. dev_dbg(ice_pf_to_dev(vsi->back), "Reset in progress. LAN Tx queues already disabled\n");
  987. } else if (status == -ENOENT) {
  988. dev_dbg(ice_pf_to_dev(vsi->back), "LAN Tx queues do not exist, nothing to disable\n");
  989. } else if (status) {
  990. dev_dbg(ice_pf_to_dev(vsi->back), "Failed to disable LAN Tx queues, error: %d\n",
  991. status);
  992. return status;
  993. }
  994. return 0;
  995. }
  996. /**
  997. * ice_fill_txq_meta - Prepare the Tx queue's meta data
  998. * @vsi: VSI that ring belongs to
  999. * @ring: ring that txq_meta will be based on
  1000. * @txq_meta: a helper struct that wraps Tx queue's information
  1001. *
  1002. * Set up a helper struct that will contain all the necessary fields that
  1003. * are needed for stopping Tx queue
  1004. */
  1005. void
  1006. ice_fill_txq_meta(const struct ice_vsi *vsi, struct ice_tx_ring *ring,
  1007. struct ice_txq_meta *txq_meta)
  1008. {
  1009. struct ice_channel *ch = ring->ch;
  1010. u8 tc;
  1011. if (IS_ENABLED(CONFIG_DCB))
  1012. tc = ring->dcb_tc;
  1013. else
  1014. tc = 0;
  1015. txq_meta->q_id = ring->reg_idx;
  1016. txq_meta->q_teid = ring->txq_teid;
  1017. txq_meta->q_handle = ring->q_handle;
  1018. if (ch) {
  1019. txq_meta->vsi_idx = ch->ch_vsi->idx;
  1020. txq_meta->tc = 0;
  1021. } else {
  1022. txq_meta->vsi_idx = vsi->idx;
  1023. txq_meta->tc = tc;
  1024. }
  1025. }