i40e_lan_hmc.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*******************************************************************************
  3. *
  4. * Intel Ethernet Controller XL710 Family Linux Driver
  5. * Copyright(c) 2013 - 2014 Intel Corporation.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. * The full GNU General Public License is included in this distribution in
  20. * the file called "COPYING".
  21. *
  22. * Contact Information:
  23. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  24. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  25. *
  26. ******************************************************************************/
  27. #include "i40e_osdep.h"
  28. #include "i40e_register.h"
  29. #include "i40e_type.h"
  30. #include "i40e_hmc.h"
  31. #include "i40e_lan_hmc.h"
  32. #include "i40e_prototype.h"
  33. /* lan specific interface functions */
  34. /**
  35. * i40e_align_l2obj_base - aligns base object pointer to 512 bytes
  36. * @offset: base address offset needing alignment
  37. *
  38. * Aligns the layer 2 function private memory so it's 512-byte aligned.
  39. **/
  40. static u64 i40e_align_l2obj_base(u64 offset)
  41. {
  42. u64 aligned_offset = offset;
  43. if ((offset % I40E_HMC_L2OBJ_BASE_ALIGNMENT) > 0)
  44. aligned_offset += (I40E_HMC_L2OBJ_BASE_ALIGNMENT -
  45. (offset % I40E_HMC_L2OBJ_BASE_ALIGNMENT));
  46. return aligned_offset;
  47. }
  48. /**
  49. * i40e_calculate_l2fpm_size - calculates layer 2 FPM memory size
  50. * @txq_num: number of Tx queues needing backing context
  51. * @rxq_num: number of Rx queues needing backing context
  52. * @fcoe_cntx_num: amount of FCoE statefull contexts needing backing context
  53. * @fcoe_filt_num: number of FCoE filters needing backing context
  54. *
  55. * Calculates the maximum amount of memory for the function required, based
  56. * on the number of resources it must provide context for.
  57. **/
  58. static u64 i40e_calculate_l2fpm_size(u32 txq_num, u32 rxq_num,
  59. u32 fcoe_cntx_num, u32 fcoe_filt_num)
  60. {
  61. u64 fpm_size = 0;
  62. fpm_size = txq_num * I40E_HMC_OBJ_SIZE_TXQ;
  63. fpm_size = i40e_align_l2obj_base(fpm_size);
  64. fpm_size += (rxq_num * I40E_HMC_OBJ_SIZE_RXQ);
  65. fpm_size = i40e_align_l2obj_base(fpm_size);
  66. fpm_size += (fcoe_cntx_num * I40E_HMC_OBJ_SIZE_FCOE_CNTX);
  67. fpm_size = i40e_align_l2obj_base(fpm_size);
  68. fpm_size += (fcoe_filt_num * I40E_HMC_OBJ_SIZE_FCOE_FILT);
  69. fpm_size = i40e_align_l2obj_base(fpm_size);
  70. return fpm_size;
  71. }
  72. /**
  73. * i40e_init_lan_hmc - initialize i40e_hmc_info struct
  74. * @hw: pointer to the HW structure
  75. * @txq_num: number of Tx queues needing backing context
  76. * @rxq_num: number of Rx queues needing backing context
  77. * @fcoe_cntx_num: amount of FCoE statefull contexts needing backing context
  78. * @fcoe_filt_num: number of FCoE filters needing backing context
  79. *
  80. * This function will be called once per physical function initialization.
  81. * It will fill out the i40e_hmc_obj_info structure for LAN objects based on
  82. * the driver's provided input, as well as information from the HMC itself
  83. * loaded from NVRAM.
  84. *
  85. * Assumptions:
  86. * - HMC Resource Profile has been selected before calling this function.
  87. **/
  88. i40e_status i40e_init_lan_hmc(struct i40e_hw *hw, u32 txq_num,
  89. u32 rxq_num, u32 fcoe_cntx_num,
  90. u32 fcoe_filt_num)
  91. {
  92. struct i40e_hmc_obj_info *obj, *full_obj;
  93. i40e_status ret_code = 0;
  94. u64 l2fpm_size;
  95. u32 size_exp;
  96. hw->hmc.signature = I40E_HMC_INFO_SIGNATURE;
  97. hw->hmc.hmc_fn_id = hw->pf_id;
  98. /* allocate memory for hmc_obj */
  99. ret_code = i40e_allocate_virt_mem(hw, &hw->hmc.hmc_obj_virt_mem,
  100. sizeof(struct i40e_hmc_obj_info) * I40E_HMC_LAN_MAX);
  101. if (ret_code)
  102. goto init_lan_hmc_out;
  103. hw->hmc.hmc_obj = (struct i40e_hmc_obj_info *)
  104. hw->hmc.hmc_obj_virt_mem.va;
  105. /* The full object will be used to create the LAN HMC SD */
  106. full_obj = &hw->hmc.hmc_obj[I40E_HMC_LAN_FULL];
  107. full_obj->max_cnt = 0;
  108. full_obj->cnt = 0;
  109. full_obj->base = 0;
  110. full_obj->size = 0;
  111. /* Tx queue context information */
  112. obj = &hw->hmc.hmc_obj[I40E_HMC_LAN_TX];
  113. obj->max_cnt = rd32(hw, I40E_GLHMC_LANQMAX);
  114. obj->cnt = txq_num;
  115. obj->base = 0;
  116. size_exp = rd32(hw, I40E_GLHMC_LANTXOBJSZ);
  117. obj->size = BIT_ULL(size_exp);
  118. /* validate values requested by driver don't exceed HMC capacity */
  119. if (txq_num > obj->max_cnt) {
  120. ret_code = I40E_ERR_INVALID_HMC_OBJ_COUNT;
  121. hw_dbg(hw, "i40e_init_lan_hmc: Tx context: asks for 0x%x but max allowed is 0x%x, returns error %d\n",
  122. txq_num, obj->max_cnt, ret_code);
  123. goto init_lan_hmc_out;
  124. }
  125. /* aggregate values into the full LAN object for later */
  126. full_obj->max_cnt += obj->max_cnt;
  127. full_obj->cnt += obj->cnt;
  128. /* Rx queue context information */
  129. obj = &hw->hmc.hmc_obj[I40E_HMC_LAN_RX];
  130. obj->max_cnt = rd32(hw, I40E_GLHMC_LANQMAX);
  131. obj->cnt = rxq_num;
  132. obj->base = hw->hmc.hmc_obj[I40E_HMC_LAN_TX].base +
  133. (hw->hmc.hmc_obj[I40E_HMC_LAN_TX].cnt *
  134. hw->hmc.hmc_obj[I40E_HMC_LAN_TX].size);
  135. obj->base = i40e_align_l2obj_base(obj->base);
  136. size_exp = rd32(hw, I40E_GLHMC_LANRXOBJSZ);
  137. obj->size = BIT_ULL(size_exp);
  138. /* validate values requested by driver don't exceed HMC capacity */
  139. if (rxq_num > obj->max_cnt) {
  140. ret_code = I40E_ERR_INVALID_HMC_OBJ_COUNT;
  141. hw_dbg(hw, "i40e_init_lan_hmc: Rx context: asks for 0x%x but max allowed is 0x%x, returns error %d\n",
  142. rxq_num, obj->max_cnt, ret_code);
  143. goto init_lan_hmc_out;
  144. }
  145. /* aggregate values into the full LAN object for later */
  146. full_obj->max_cnt += obj->max_cnt;
  147. full_obj->cnt += obj->cnt;
  148. /* FCoE context information */
  149. obj = &hw->hmc.hmc_obj[I40E_HMC_FCOE_CTX];
  150. obj->max_cnt = rd32(hw, I40E_GLHMC_FCOEMAX);
  151. obj->cnt = fcoe_cntx_num;
  152. obj->base = hw->hmc.hmc_obj[I40E_HMC_LAN_RX].base +
  153. (hw->hmc.hmc_obj[I40E_HMC_LAN_RX].cnt *
  154. hw->hmc.hmc_obj[I40E_HMC_LAN_RX].size);
  155. obj->base = i40e_align_l2obj_base(obj->base);
  156. size_exp = rd32(hw, I40E_GLHMC_FCOEDDPOBJSZ);
  157. obj->size = BIT_ULL(size_exp);
  158. /* validate values requested by driver don't exceed HMC capacity */
  159. if (fcoe_cntx_num > obj->max_cnt) {
  160. ret_code = I40E_ERR_INVALID_HMC_OBJ_COUNT;
  161. hw_dbg(hw, "i40e_init_lan_hmc: FCoE context: asks for 0x%x but max allowed is 0x%x, returns error %d\n",
  162. fcoe_cntx_num, obj->max_cnt, ret_code);
  163. goto init_lan_hmc_out;
  164. }
  165. /* aggregate values into the full LAN object for later */
  166. full_obj->max_cnt += obj->max_cnt;
  167. full_obj->cnt += obj->cnt;
  168. /* FCoE filter information */
  169. obj = &hw->hmc.hmc_obj[I40E_HMC_FCOE_FILT];
  170. obj->max_cnt = rd32(hw, I40E_GLHMC_FCOEFMAX);
  171. obj->cnt = fcoe_filt_num;
  172. obj->base = hw->hmc.hmc_obj[I40E_HMC_FCOE_CTX].base +
  173. (hw->hmc.hmc_obj[I40E_HMC_FCOE_CTX].cnt *
  174. hw->hmc.hmc_obj[I40E_HMC_FCOE_CTX].size);
  175. obj->base = i40e_align_l2obj_base(obj->base);
  176. size_exp = rd32(hw, I40E_GLHMC_FCOEFOBJSZ);
  177. obj->size = BIT_ULL(size_exp);
  178. /* validate values requested by driver don't exceed HMC capacity */
  179. if (fcoe_filt_num > obj->max_cnt) {
  180. ret_code = I40E_ERR_INVALID_HMC_OBJ_COUNT;
  181. hw_dbg(hw, "i40e_init_lan_hmc: FCoE filter: asks for 0x%x but max allowed is 0x%x, returns error %d\n",
  182. fcoe_filt_num, obj->max_cnt, ret_code);
  183. goto init_lan_hmc_out;
  184. }
  185. /* aggregate values into the full LAN object for later */
  186. full_obj->max_cnt += obj->max_cnt;
  187. full_obj->cnt += obj->cnt;
  188. hw->hmc.first_sd_index = 0;
  189. hw->hmc.sd_table.ref_cnt = 0;
  190. l2fpm_size = i40e_calculate_l2fpm_size(txq_num, rxq_num, fcoe_cntx_num,
  191. fcoe_filt_num);
  192. if (NULL == hw->hmc.sd_table.sd_entry) {
  193. hw->hmc.sd_table.sd_cnt = (u32)
  194. (l2fpm_size + I40E_HMC_DIRECT_BP_SIZE - 1) /
  195. I40E_HMC_DIRECT_BP_SIZE;
  196. /* allocate the sd_entry members in the sd_table */
  197. ret_code = i40e_allocate_virt_mem(hw, &hw->hmc.sd_table.addr,
  198. (sizeof(struct i40e_hmc_sd_entry) *
  199. hw->hmc.sd_table.sd_cnt));
  200. if (ret_code)
  201. goto init_lan_hmc_out;
  202. hw->hmc.sd_table.sd_entry =
  203. (struct i40e_hmc_sd_entry *)hw->hmc.sd_table.addr.va;
  204. }
  205. /* store in the LAN full object for later */
  206. full_obj->size = l2fpm_size;
  207. init_lan_hmc_out:
  208. return ret_code;
  209. }
  210. /**
  211. * i40e_remove_pd_page - Remove a page from the page descriptor table
  212. * @hw: pointer to the HW structure
  213. * @hmc_info: pointer to the HMC configuration information structure
  214. * @idx: segment descriptor index to find the relevant page descriptor
  215. *
  216. * This function:
  217. * 1. Marks the entry in pd table (for paged address mode) invalid
  218. * 2. write to register PMPDINV to invalidate the backing page in FV cache
  219. * 3. Decrement the ref count for pd_entry
  220. * assumptions:
  221. * 1. caller can deallocate the memory used by pd after this function
  222. * returns.
  223. **/
  224. static i40e_status i40e_remove_pd_page(struct i40e_hw *hw,
  225. struct i40e_hmc_info *hmc_info,
  226. u32 idx)
  227. {
  228. i40e_status ret_code = 0;
  229. if (!i40e_prep_remove_pd_page(hmc_info, idx))
  230. ret_code = i40e_remove_pd_page_new(hw, hmc_info, idx, true);
  231. return ret_code;
  232. }
  233. /**
  234. * i40e_remove_sd_bp - remove a backing page from a segment descriptor
  235. * @hw: pointer to our HW structure
  236. * @hmc_info: pointer to the HMC configuration information structure
  237. * @idx: the page index
  238. *
  239. * This function:
  240. * 1. Marks the entry in sd table (for direct address mode) invalid
  241. * 2. write to register PMSDCMD, PMSDDATALOW(PMSDDATALOW.PMSDVALID set
  242. * to 0) and PMSDDATAHIGH to invalidate the sd page
  243. * 3. Decrement the ref count for the sd_entry
  244. * assumptions:
  245. * 1. caller can deallocate the memory used by backing storage after this
  246. * function returns.
  247. **/
  248. static i40e_status i40e_remove_sd_bp(struct i40e_hw *hw,
  249. struct i40e_hmc_info *hmc_info,
  250. u32 idx)
  251. {
  252. i40e_status ret_code = 0;
  253. if (!i40e_prep_remove_sd_bp(hmc_info, idx))
  254. ret_code = i40e_remove_sd_bp_new(hw, hmc_info, idx, true);
  255. return ret_code;
  256. }
  257. /**
  258. * i40e_create_lan_hmc_object - allocate backing store for hmc objects
  259. * @hw: pointer to the HW structure
  260. * @info: pointer to i40e_hmc_create_obj_info struct
  261. *
  262. * This will allocate memory for PDs and backing pages and populate
  263. * the sd and pd entries.
  264. **/
  265. static i40e_status i40e_create_lan_hmc_object(struct i40e_hw *hw,
  266. struct i40e_hmc_lan_create_obj_info *info)
  267. {
  268. i40e_status ret_code = 0;
  269. struct i40e_hmc_sd_entry *sd_entry;
  270. u32 pd_idx1 = 0, pd_lmt1 = 0;
  271. u32 pd_idx = 0, pd_lmt = 0;
  272. bool pd_error = false;
  273. u32 sd_idx, sd_lmt;
  274. u64 sd_size;
  275. u32 i, j;
  276. if (NULL == info) {
  277. ret_code = I40E_ERR_BAD_PTR;
  278. hw_dbg(hw, "i40e_create_lan_hmc_object: bad info ptr\n");
  279. goto exit;
  280. }
  281. if (NULL == info->hmc_info) {
  282. ret_code = I40E_ERR_BAD_PTR;
  283. hw_dbg(hw, "i40e_create_lan_hmc_object: bad hmc_info ptr\n");
  284. goto exit;
  285. }
  286. if (I40E_HMC_INFO_SIGNATURE != info->hmc_info->signature) {
  287. ret_code = I40E_ERR_BAD_PTR;
  288. hw_dbg(hw, "i40e_create_lan_hmc_object: bad signature\n");
  289. goto exit;
  290. }
  291. if (info->start_idx >= info->hmc_info->hmc_obj[info->rsrc_type].cnt) {
  292. ret_code = I40E_ERR_INVALID_HMC_OBJ_INDEX;
  293. hw_dbg(hw, "i40e_create_lan_hmc_object: returns error %d\n",
  294. ret_code);
  295. goto exit;
  296. }
  297. if ((info->start_idx + info->count) >
  298. info->hmc_info->hmc_obj[info->rsrc_type].cnt) {
  299. ret_code = I40E_ERR_INVALID_HMC_OBJ_COUNT;
  300. hw_dbg(hw, "i40e_create_lan_hmc_object: returns error %d\n",
  301. ret_code);
  302. goto exit;
  303. }
  304. /* find sd index and limit */
  305. I40E_FIND_SD_INDEX_LIMIT(info->hmc_info, info->rsrc_type,
  306. info->start_idx, info->count,
  307. &sd_idx, &sd_lmt);
  308. if (sd_idx >= info->hmc_info->sd_table.sd_cnt ||
  309. sd_lmt > info->hmc_info->sd_table.sd_cnt) {
  310. ret_code = I40E_ERR_INVALID_SD_INDEX;
  311. goto exit;
  312. }
  313. /* find pd index */
  314. I40E_FIND_PD_INDEX_LIMIT(info->hmc_info, info->rsrc_type,
  315. info->start_idx, info->count, &pd_idx,
  316. &pd_lmt);
  317. /* This is to cover for cases where you may not want to have an SD with
  318. * the full 2M memory but something smaller. By not filling out any
  319. * size, the function will default the SD size to be 2M.
  320. */
  321. if (info->direct_mode_sz == 0)
  322. sd_size = I40E_HMC_DIRECT_BP_SIZE;
  323. else
  324. sd_size = info->direct_mode_sz;
  325. /* check if all the sds are valid. If not, allocate a page and
  326. * initialize it.
  327. */
  328. for (j = sd_idx; j < sd_lmt; j++) {
  329. /* update the sd table entry */
  330. ret_code = i40e_add_sd_table_entry(hw, info->hmc_info, j,
  331. info->entry_type,
  332. sd_size);
  333. if (ret_code)
  334. goto exit_sd_error;
  335. sd_entry = &info->hmc_info->sd_table.sd_entry[j];
  336. if (I40E_SD_TYPE_PAGED == sd_entry->entry_type) {
  337. /* check if all the pds in this sd are valid. If not,
  338. * allocate a page and initialize it.
  339. */
  340. /* find pd_idx and pd_lmt in this sd */
  341. pd_idx1 = max(pd_idx, (j * I40E_HMC_MAX_BP_COUNT));
  342. pd_lmt1 = min(pd_lmt,
  343. ((j + 1) * I40E_HMC_MAX_BP_COUNT));
  344. for (i = pd_idx1; i < pd_lmt1; i++) {
  345. /* update the pd table entry */
  346. ret_code = i40e_add_pd_table_entry(hw,
  347. info->hmc_info,
  348. i, NULL);
  349. if (ret_code) {
  350. pd_error = true;
  351. break;
  352. }
  353. }
  354. if (pd_error) {
  355. /* remove the backing pages from pd_idx1 to i */
  356. while (i && (i > pd_idx1)) {
  357. i40e_remove_pd_bp(hw, info->hmc_info,
  358. (i - 1));
  359. i--;
  360. }
  361. }
  362. }
  363. if (!sd_entry->valid) {
  364. sd_entry->valid = true;
  365. switch (sd_entry->entry_type) {
  366. case I40E_SD_TYPE_PAGED:
  367. I40E_SET_PF_SD_ENTRY(hw,
  368. sd_entry->u.pd_table.pd_page_addr.pa,
  369. j, sd_entry->entry_type);
  370. break;
  371. case I40E_SD_TYPE_DIRECT:
  372. I40E_SET_PF_SD_ENTRY(hw, sd_entry->u.bp.addr.pa,
  373. j, sd_entry->entry_type);
  374. break;
  375. default:
  376. ret_code = I40E_ERR_INVALID_SD_TYPE;
  377. goto exit;
  378. }
  379. }
  380. }
  381. goto exit;
  382. exit_sd_error:
  383. /* cleanup for sd entries from j to sd_idx */
  384. while (j && (j > sd_idx)) {
  385. sd_entry = &info->hmc_info->sd_table.sd_entry[j - 1];
  386. switch (sd_entry->entry_type) {
  387. case I40E_SD_TYPE_PAGED:
  388. pd_idx1 = max(pd_idx,
  389. ((j - 1) * I40E_HMC_MAX_BP_COUNT));
  390. pd_lmt1 = min(pd_lmt, (j * I40E_HMC_MAX_BP_COUNT));
  391. for (i = pd_idx1; i < pd_lmt1; i++)
  392. i40e_remove_pd_bp(hw, info->hmc_info, i);
  393. i40e_remove_pd_page(hw, info->hmc_info, (j - 1));
  394. break;
  395. case I40E_SD_TYPE_DIRECT:
  396. i40e_remove_sd_bp(hw, info->hmc_info, (j - 1));
  397. break;
  398. default:
  399. ret_code = I40E_ERR_INVALID_SD_TYPE;
  400. break;
  401. }
  402. j--;
  403. }
  404. exit:
  405. return ret_code;
  406. }
  407. /**
  408. * i40e_configure_lan_hmc - prepare the HMC backing store
  409. * @hw: pointer to the hw structure
  410. * @model: the model for the layout of the SD/PD tables
  411. *
  412. * - This function will be called once per physical function initialization.
  413. * - This function will be called after i40e_init_lan_hmc() and before
  414. * any LAN/FCoE HMC objects can be created.
  415. **/
  416. i40e_status i40e_configure_lan_hmc(struct i40e_hw *hw,
  417. enum i40e_hmc_model model)
  418. {
  419. struct i40e_hmc_lan_create_obj_info info;
  420. i40e_status ret_code = 0;
  421. u8 hmc_fn_id = hw->hmc.hmc_fn_id;
  422. struct i40e_hmc_obj_info *obj;
  423. /* Initialize part of the create object info struct */
  424. info.hmc_info = &hw->hmc;
  425. info.rsrc_type = I40E_HMC_LAN_FULL;
  426. info.start_idx = 0;
  427. info.direct_mode_sz = hw->hmc.hmc_obj[I40E_HMC_LAN_FULL].size;
  428. /* Build the SD entry for the LAN objects */
  429. switch (model) {
  430. case I40E_HMC_MODEL_DIRECT_PREFERRED:
  431. case I40E_HMC_MODEL_DIRECT_ONLY:
  432. info.entry_type = I40E_SD_TYPE_DIRECT;
  433. /* Make one big object, a single SD */
  434. info.count = 1;
  435. ret_code = i40e_create_lan_hmc_object(hw, &info);
  436. if (ret_code && (model == I40E_HMC_MODEL_DIRECT_PREFERRED))
  437. goto try_type_paged;
  438. else if (ret_code)
  439. goto configure_lan_hmc_out;
  440. /* else clause falls through the break */
  441. break;
  442. case I40E_HMC_MODEL_PAGED_ONLY:
  443. try_type_paged:
  444. info.entry_type = I40E_SD_TYPE_PAGED;
  445. /* Make one big object in the PD table */
  446. info.count = 1;
  447. ret_code = i40e_create_lan_hmc_object(hw, &info);
  448. if (ret_code)
  449. goto configure_lan_hmc_out;
  450. break;
  451. default:
  452. /* unsupported type */
  453. ret_code = I40E_ERR_INVALID_SD_TYPE;
  454. hw_dbg(hw, "i40e_configure_lan_hmc: Unknown SD type: %d\n",
  455. ret_code);
  456. goto configure_lan_hmc_out;
  457. }
  458. /* Configure and program the FPM registers so objects can be created */
  459. /* Tx contexts */
  460. obj = &hw->hmc.hmc_obj[I40E_HMC_LAN_TX];
  461. wr32(hw, I40E_GLHMC_LANTXBASE(hmc_fn_id),
  462. (u32)((obj->base & I40E_GLHMC_LANTXBASE_FPMLANTXBASE_MASK) / 512));
  463. wr32(hw, I40E_GLHMC_LANTXCNT(hmc_fn_id), obj->cnt);
  464. /* Rx contexts */
  465. obj = &hw->hmc.hmc_obj[I40E_HMC_LAN_RX];
  466. wr32(hw, I40E_GLHMC_LANRXBASE(hmc_fn_id),
  467. (u32)((obj->base & I40E_GLHMC_LANRXBASE_FPMLANRXBASE_MASK) / 512));
  468. wr32(hw, I40E_GLHMC_LANRXCNT(hmc_fn_id), obj->cnt);
  469. /* FCoE contexts */
  470. obj = &hw->hmc.hmc_obj[I40E_HMC_FCOE_CTX];
  471. wr32(hw, I40E_GLHMC_FCOEDDPBASE(hmc_fn_id),
  472. (u32)((obj->base & I40E_GLHMC_FCOEDDPBASE_FPMFCOEDDPBASE_MASK) / 512));
  473. wr32(hw, I40E_GLHMC_FCOEDDPCNT(hmc_fn_id), obj->cnt);
  474. /* FCoE filters */
  475. obj = &hw->hmc.hmc_obj[I40E_HMC_FCOE_FILT];
  476. wr32(hw, I40E_GLHMC_FCOEFBASE(hmc_fn_id),
  477. (u32)((obj->base & I40E_GLHMC_FCOEFBASE_FPMFCOEFBASE_MASK) / 512));
  478. wr32(hw, I40E_GLHMC_FCOEFCNT(hmc_fn_id), obj->cnt);
  479. configure_lan_hmc_out:
  480. return ret_code;
  481. }
  482. /**
  483. * i40e_delete_hmc_object - remove hmc objects
  484. * @hw: pointer to the HW structure
  485. * @info: pointer to i40e_hmc_delete_obj_info struct
  486. *
  487. * This will de-populate the SDs and PDs. It frees
  488. * the memory for PDS and backing storage. After this function is returned,
  489. * caller should deallocate memory allocated previously for
  490. * book-keeping information about PDs and backing storage.
  491. **/
  492. static i40e_status i40e_delete_lan_hmc_object(struct i40e_hw *hw,
  493. struct i40e_hmc_lan_delete_obj_info *info)
  494. {
  495. i40e_status ret_code = 0;
  496. struct i40e_hmc_pd_table *pd_table;
  497. u32 pd_idx, pd_lmt, rel_pd_idx;
  498. u32 sd_idx, sd_lmt;
  499. u32 i, j;
  500. if (NULL == info) {
  501. ret_code = I40E_ERR_BAD_PTR;
  502. hw_dbg(hw, "i40e_delete_hmc_object: bad info ptr\n");
  503. goto exit;
  504. }
  505. if (NULL == info->hmc_info) {
  506. ret_code = I40E_ERR_BAD_PTR;
  507. hw_dbg(hw, "i40e_delete_hmc_object: bad info->hmc_info ptr\n");
  508. goto exit;
  509. }
  510. if (I40E_HMC_INFO_SIGNATURE != info->hmc_info->signature) {
  511. ret_code = I40E_ERR_BAD_PTR;
  512. hw_dbg(hw, "i40e_delete_hmc_object: bad hmc_info->signature\n");
  513. goto exit;
  514. }
  515. if (NULL == info->hmc_info->sd_table.sd_entry) {
  516. ret_code = I40E_ERR_BAD_PTR;
  517. hw_dbg(hw, "i40e_delete_hmc_object: bad sd_entry\n");
  518. goto exit;
  519. }
  520. if (NULL == info->hmc_info->hmc_obj) {
  521. ret_code = I40E_ERR_BAD_PTR;
  522. hw_dbg(hw, "i40e_delete_hmc_object: bad hmc_info->hmc_obj\n");
  523. goto exit;
  524. }
  525. if (info->start_idx >= info->hmc_info->hmc_obj[info->rsrc_type].cnt) {
  526. ret_code = I40E_ERR_INVALID_HMC_OBJ_INDEX;
  527. hw_dbg(hw, "i40e_delete_hmc_object: returns error %d\n",
  528. ret_code);
  529. goto exit;
  530. }
  531. if ((info->start_idx + info->count) >
  532. info->hmc_info->hmc_obj[info->rsrc_type].cnt) {
  533. ret_code = I40E_ERR_INVALID_HMC_OBJ_COUNT;
  534. hw_dbg(hw, "i40e_delete_hmc_object: returns error %d\n",
  535. ret_code);
  536. goto exit;
  537. }
  538. I40E_FIND_PD_INDEX_LIMIT(info->hmc_info, info->rsrc_type,
  539. info->start_idx, info->count, &pd_idx,
  540. &pd_lmt);
  541. for (j = pd_idx; j < pd_lmt; j++) {
  542. sd_idx = j / I40E_HMC_PD_CNT_IN_SD;
  543. if (I40E_SD_TYPE_PAGED !=
  544. info->hmc_info->sd_table.sd_entry[sd_idx].entry_type)
  545. continue;
  546. rel_pd_idx = j % I40E_HMC_PD_CNT_IN_SD;
  547. pd_table =
  548. &info->hmc_info->sd_table.sd_entry[sd_idx].u.pd_table;
  549. if (pd_table->pd_entry[rel_pd_idx].valid) {
  550. ret_code = i40e_remove_pd_bp(hw, info->hmc_info, j);
  551. if (ret_code)
  552. goto exit;
  553. }
  554. }
  555. /* find sd index and limit */
  556. I40E_FIND_SD_INDEX_LIMIT(info->hmc_info, info->rsrc_type,
  557. info->start_idx, info->count,
  558. &sd_idx, &sd_lmt);
  559. if (sd_idx >= info->hmc_info->sd_table.sd_cnt ||
  560. sd_lmt > info->hmc_info->sd_table.sd_cnt) {
  561. ret_code = I40E_ERR_INVALID_SD_INDEX;
  562. goto exit;
  563. }
  564. for (i = sd_idx; i < sd_lmt; i++) {
  565. if (!info->hmc_info->sd_table.sd_entry[i].valid)
  566. continue;
  567. switch (info->hmc_info->sd_table.sd_entry[i].entry_type) {
  568. case I40E_SD_TYPE_DIRECT:
  569. ret_code = i40e_remove_sd_bp(hw, info->hmc_info, i);
  570. if (ret_code)
  571. goto exit;
  572. break;
  573. case I40E_SD_TYPE_PAGED:
  574. ret_code = i40e_remove_pd_page(hw, info->hmc_info, i);
  575. if (ret_code)
  576. goto exit;
  577. break;
  578. default:
  579. break;
  580. }
  581. }
  582. exit:
  583. return ret_code;
  584. }
  585. /**
  586. * i40e_shutdown_lan_hmc - Remove HMC backing store, free allocated memory
  587. * @hw: pointer to the hw structure
  588. *
  589. * This must be called by drivers as they are shutting down and being
  590. * removed from the OS.
  591. **/
  592. i40e_status i40e_shutdown_lan_hmc(struct i40e_hw *hw)
  593. {
  594. struct i40e_hmc_lan_delete_obj_info info;
  595. i40e_status ret_code;
  596. info.hmc_info = &hw->hmc;
  597. info.rsrc_type = I40E_HMC_LAN_FULL;
  598. info.start_idx = 0;
  599. info.count = 1;
  600. /* delete the object */
  601. ret_code = i40e_delete_lan_hmc_object(hw, &info);
  602. /* free the SD table entry for LAN */
  603. i40e_free_virt_mem(hw, &hw->hmc.sd_table.addr);
  604. hw->hmc.sd_table.sd_cnt = 0;
  605. hw->hmc.sd_table.sd_entry = NULL;
  606. /* free memory used for hmc_obj */
  607. i40e_free_virt_mem(hw, &hw->hmc.hmc_obj_virt_mem);
  608. hw->hmc.hmc_obj = NULL;
  609. return ret_code;
  610. }
  611. #define I40E_HMC_STORE(_struct, _ele) \
  612. offsetof(struct _struct, _ele), \
  613. FIELD_SIZEOF(struct _struct, _ele)
  614. struct i40e_context_ele {
  615. u16 offset;
  616. u16 size_of;
  617. u16 width;
  618. u16 lsb;
  619. };
  620. /* LAN Tx Queue Context */
  621. static struct i40e_context_ele i40e_hmc_txq_ce_info[] = {
  622. /* Field Width LSB */
  623. {I40E_HMC_STORE(i40e_hmc_obj_txq, head), 13, 0 },
  624. {I40E_HMC_STORE(i40e_hmc_obj_txq, new_context), 1, 30 },
  625. {I40E_HMC_STORE(i40e_hmc_obj_txq, base), 57, 32 },
  626. {I40E_HMC_STORE(i40e_hmc_obj_txq, fc_ena), 1, 89 },
  627. {I40E_HMC_STORE(i40e_hmc_obj_txq, timesync_ena), 1, 90 },
  628. {I40E_HMC_STORE(i40e_hmc_obj_txq, fd_ena), 1, 91 },
  629. {I40E_HMC_STORE(i40e_hmc_obj_txq, alt_vlan_ena), 1, 92 },
  630. {I40E_HMC_STORE(i40e_hmc_obj_txq, cpuid), 8, 96 },
  631. /* line 1 */
  632. {I40E_HMC_STORE(i40e_hmc_obj_txq, thead_wb), 13, 0 + 128 },
  633. {I40E_HMC_STORE(i40e_hmc_obj_txq, head_wb_ena), 1, 32 + 128 },
  634. {I40E_HMC_STORE(i40e_hmc_obj_txq, qlen), 13, 33 + 128 },
  635. {I40E_HMC_STORE(i40e_hmc_obj_txq, tphrdesc_ena), 1, 46 + 128 },
  636. {I40E_HMC_STORE(i40e_hmc_obj_txq, tphrpacket_ena), 1, 47 + 128 },
  637. {I40E_HMC_STORE(i40e_hmc_obj_txq, tphwdesc_ena), 1, 48 + 128 },
  638. {I40E_HMC_STORE(i40e_hmc_obj_txq, head_wb_addr), 64, 64 + 128 },
  639. /* line 7 */
  640. {I40E_HMC_STORE(i40e_hmc_obj_txq, crc), 32, 0 + (7 * 128) },
  641. {I40E_HMC_STORE(i40e_hmc_obj_txq, rdylist), 10, 84 + (7 * 128) },
  642. {I40E_HMC_STORE(i40e_hmc_obj_txq, rdylist_act), 1, 94 + (7 * 128) },
  643. { 0 }
  644. };
  645. /* LAN Rx Queue Context */
  646. static struct i40e_context_ele i40e_hmc_rxq_ce_info[] = {
  647. /* Field Width LSB */
  648. { I40E_HMC_STORE(i40e_hmc_obj_rxq, head), 13, 0 },
  649. { I40E_HMC_STORE(i40e_hmc_obj_rxq, cpuid), 8, 13 },
  650. { I40E_HMC_STORE(i40e_hmc_obj_rxq, base), 57, 32 },
  651. { I40E_HMC_STORE(i40e_hmc_obj_rxq, qlen), 13, 89 },
  652. { I40E_HMC_STORE(i40e_hmc_obj_rxq, dbuff), 7, 102 },
  653. { I40E_HMC_STORE(i40e_hmc_obj_rxq, hbuff), 5, 109 },
  654. { I40E_HMC_STORE(i40e_hmc_obj_rxq, dtype), 2, 114 },
  655. { I40E_HMC_STORE(i40e_hmc_obj_rxq, dsize), 1, 116 },
  656. { I40E_HMC_STORE(i40e_hmc_obj_rxq, crcstrip), 1, 117 },
  657. { I40E_HMC_STORE(i40e_hmc_obj_rxq, fc_ena), 1, 118 },
  658. { I40E_HMC_STORE(i40e_hmc_obj_rxq, l2tsel), 1, 119 },
  659. { I40E_HMC_STORE(i40e_hmc_obj_rxq, hsplit_0), 4, 120 },
  660. { I40E_HMC_STORE(i40e_hmc_obj_rxq, hsplit_1), 2, 124 },
  661. { I40E_HMC_STORE(i40e_hmc_obj_rxq, showiv), 1, 127 },
  662. { I40E_HMC_STORE(i40e_hmc_obj_rxq, rxmax), 14, 174 },
  663. { I40E_HMC_STORE(i40e_hmc_obj_rxq, tphrdesc_ena), 1, 193 },
  664. { I40E_HMC_STORE(i40e_hmc_obj_rxq, tphwdesc_ena), 1, 194 },
  665. { I40E_HMC_STORE(i40e_hmc_obj_rxq, tphdata_ena), 1, 195 },
  666. { I40E_HMC_STORE(i40e_hmc_obj_rxq, tphhead_ena), 1, 196 },
  667. { I40E_HMC_STORE(i40e_hmc_obj_rxq, lrxqthresh), 3, 198 },
  668. { I40E_HMC_STORE(i40e_hmc_obj_rxq, prefena), 1, 201 },
  669. { 0 }
  670. };
  671. /**
  672. * i40e_write_byte - replace HMC context byte
  673. * @hmc_bits: pointer to the HMC memory
  674. * @ce_info: a description of the struct to be read from
  675. * @src: the struct to be read from
  676. **/
  677. static void i40e_write_byte(u8 *hmc_bits,
  678. struct i40e_context_ele *ce_info,
  679. u8 *src)
  680. {
  681. u8 src_byte, dest_byte, mask;
  682. u8 *from, *dest;
  683. u16 shift_width;
  684. /* copy from the next struct field */
  685. from = src + ce_info->offset;
  686. /* prepare the bits and mask */
  687. shift_width = ce_info->lsb % 8;
  688. mask = (u8)(BIT(ce_info->width) - 1);
  689. src_byte = *from;
  690. src_byte &= mask;
  691. /* shift to correct alignment */
  692. mask <<= shift_width;
  693. src_byte <<= shift_width;
  694. /* get the current bits from the target bit string */
  695. dest = hmc_bits + (ce_info->lsb / 8);
  696. memcpy(&dest_byte, dest, sizeof(dest_byte));
  697. dest_byte &= ~mask; /* get the bits not changing */
  698. dest_byte |= src_byte; /* add in the new bits */
  699. /* put it all back */
  700. memcpy(dest, &dest_byte, sizeof(dest_byte));
  701. }
  702. /**
  703. * i40e_write_word - replace HMC context word
  704. * @hmc_bits: pointer to the HMC memory
  705. * @ce_info: a description of the struct to be read from
  706. * @src: the struct to be read from
  707. **/
  708. static void i40e_write_word(u8 *hmc_bits,
  709. struct i40e_context_ele *ce_info,
  710. u8 *src)
  711. {
  712. u16 src_word, mask;
  713. u8 *from, *dest;
  714. u16 shift_width;
  715. __le16 dest_word;
  716. /* copy from the next struct field */
  717. from = src + ce_info->offset;
  718. /* prepare the bits and mask */
  719. shift_width = ce_info->lsb % 8;
  720. mask = BIT(ce_info->width) - 1;
  721. /* don't swizzle the bits until after the mask because the mask bits
  722. * will be in a different bit position on big endian machines
  723. */
  724. src_word = *(u16 *)from;
  725. src_word &= mask;
  726. /* shift to correct alignment */
  727. mask <<= shift_width;
  728. src_word <<= shift_width;
  729. /* get the current bits from the target bit string */
  730. dest = hmc_bits + (ce_info->lsb / 8);
  731. memcpy(&dest_word, dest, sizeof(dest_word));
  732. dest_word &= ~(cpu_to_le16(mask)); /* get the bits not changing */
  733. dest_word |= cpu_to_le16(src_word); /* add in the new bits */
  734. /* put it all back */
  735. memcpy(dest, &dest_word, sizeof(dest_word));
  736. }
  737. /**
  738. * i40e_write_dword - replace HMC context dword
  739. * @hmc_bits: pointer to the HMC memory
  740. * @ce_info: a description of the struct to be read from
  741. * @src: the struct to be read from
  742. **/
  743. static void i40e_write_dword(u8 *hmc_bits,
  744. struct i40e_context_ele *ce_info,
  745. u8 *src)
  746. {
  747. u32 src_dword, mask;
  748. u8 *from, *dest;
  749. u16 shift_width;
  750. __le32 dest_dword;
  751. /* copy from the next struct field */
  752. from = src + ce_info->offset;
  753. /* prepare the bits and mask */
  754. shift_width = ce_info->lsb % 8;
  755. /* if the field width is exactly 32 on an x86 machine, then the shift
  756. * operation will not work because the SHL instructions count is masked
  757. * to 5 bits so the shift will do nothing
  758. */
  759. if (ce_info->width < 32)
  760. mask = BIT(ce_info->width) - 1;
  761. else
  762. mask = ~(u32)0;
  763. /* don't swizzle the bits until after the mask because the mask bits
  764. * will be in a different bit position on big endian machines
  765. */
  766. src_dword = *(u32 *)from;
  767. src_dword &= mask;
  768. /* shift to correct alignment */
  769. mask <<= shift_width;
  770. src_dword <<= shift_width;
  771. /* get the current bits from the target bit string */
  772. dest = hmc_bits + (ce_info->lsb / 8);
  773. memcpy(&dest_dword, dest, sizeof(dest_dword));
  774. dest_dword &= ~(cpu_to_le32(mask)); /* get the bits not changing */
  775. dest_dword |= cpu_to_le32(src_dword); /* add in the new bits */
  776. /* put it all back */
  777. memcpy(dest, &dest_dword, sizeof(dest_dword));
  778. }
  779. /**
  780. * i40e_write_qword - replace HMC context qword
  781. * @hmc_bits: pointer to the HMC memory
  782. * @ce_info: a description of the struct to be read from
  783. * @src: the struct to be read from
  784. **/
  785. static void i40e_write_qword(u8 *hmc_bits,
  786. struct i40e_context_ele *ce_info,
  787. u8 *src)
  788. {
  789. u64 src_qword, mask;
  790. u8 *from, *dest;
  791. u16 shift_width;
  792. __le64 dest_qword;
  793. /* copy from the next struct field */
  794. from = src + ce_info->offset;
  795. /* prepare the bits and mask */
  796. shift_width = ce_info->lsb % 8;
  797. /* if the field width is exactly 64 on an x86 machine, then the shift
  798. * operation will not work because the SHL instructions count is masked
  799. * to 6 bits so the shift will do nothing
  800. */
  801. if (ce_info->width < 64)
  802. mask = BIT_ULL(ce_info->width) - 1;
  803. else
  804. mask = ~(u64)0;
  805. /* don't swizzle the bits until after the mask because the mask bits
  806. * will be in a different bit position on big endian machines
  807. */
  808. src_qword = *(u64 *)from;
  809. src_qword &= mask;
  810. /* shift to correct alignment */
  811. mask <<= shift_width;
  812. src_qword <<= shift_width;
  813. /* get the current bits from the target bit string */
  814. dest = hmc_bits + (ce_info->lsb / 8);
  815. memcpy(&dest_qword, dest, sizeof(dest_qword));
  816. dest_qword &= ~(cpu_to_le64(mask)); /* get the bits not changing */
  817. dest_qword |= cpu_to_le64(src_qword); /* add in the new bits */
  818. /* put it all back */
  819. memcpy(dest, &dest_qword, sizeof(dest_qword));
  820. }
  821. /**
  822. * i40e_clear_hmc_context - zero out the HMC context bits
  823. * @hw: the hardware struct
  824. * @context_bytes: pointer to the context bit array (DMA memory)
  825. * @hmc_type: the type of HMC resource
  826. **/
  827. static i40e_status i40e_clear_hmc_context(struct i40e_hw *hw,
  828. u8 *context_bytes,
  829. enum i40e_hmc_lan_rsrc_type hmc_type)
  830. {
  831. /* clean the bit array */
  832. memset(context_bytes, 0, (u32)hw->hmc.hmc_obj[hmc_type].size);
  833. return 0;
  834. }
  835. /**
  836. * i40e_set_hmc_context - replace HMC context bits
  837. * @context_bytes: pointer to the context bit array
  838. * @ce_info: a description of the struct to be filled
  839. * @dest: the struct to be filled
  840. **/
  841. static i40e_status i40e_set_hmc_context(u8 *context_bytes,
  842. struct i40e_context_ele *ce_info,
  843. u8 *dest)
  844. {
  845. int f;
  846. for (f = 0; ce_info[f].width != 0; f++) {
  847. /* we have to deal with each element of the HMC using the
  848. * correct size so that we are correct regardless of the
  849. * endianness of the machine
  850. */
  851. switch (ce_info[f].size_of) {
  852. case 1:
  853. i40e_write_byte(context_bytes, &ce_info[f], dest);
  854. break;
  855. case 2:
  856. i40e_write_word(context_bytes, &ce_info[f], dest);
  857. break;
  858. case 4:
  859. i40e_write_dword(context_bytes, &ce_info[f], dest);
  860. break;
  861. case 8:
  862. i40e_write_qword(context_bytes, &ce_info[f], dest);
  863. break;
  864. }
  865. }
  866. return 0;
  867. }
  868. /**
  869. * i40e_hmc_get_object_va - retrieves an object's virtual address
  870. * @hmc_info: pointer to i40e_hmc_info struct
  871. * @object_base: pointer to u64 to get the va
  872. * @rsrc_type: the hmc resource type
  873. * @obj_idx: hmc object index
  874. *
  875. * This function retrieves the object's virtual address from the object
  876. * base pointer. This function is used for LAN Queue contexts.
  877. **/
  878. static
  879. i40e_status i40e_hmc_get_object_va(struct i40e_hmc_info *hmc_info,
  880. u8 **object_base,
  881. enum i40e_hmc_lan_rsrc_type rsrc_type,
  882. u32 obj_idx)
  883. {
  884. u32 obj_offset_in_sd, obj_offset_in_pd;
  885. i40e_status ret_code = 0;
  886. struct i40e_hmc_sd_entry *sd_entry;
  887. struct i40e_hmc_pd_entry *pd_entry;
  888. u32 pd_idx, pd_lmt, rel_pd_idx;
  889. u64 obj_offset_in_fpm;
  890. u32 sd_idx, sd_lmt;
  891. if (NULL == hmc_info) {
  892. ret_code = I40E_ERR_BAD_PTR;
  893. hw_dbg(hw, "i40e_hmc_get_object_va: bad hmc_info ptr\n");
  894. goto exit;
  895. }
  896. if (NULL == hmc_info->hmc_obj) {
  897. ret_code = I40E_ERR_BAD_PTR;
  898. hw_dbg(hw, "i40e_hmc_get_object_va: bad hmc_info->hmc_obj ptr\n");
  899. goto exit;
  900. }
  901. if (NULL == object_base) {
  902. ret_code = I40E_ERR_BAD_PTR;
  903. hw_dbg(hw, "i40e_hmc_get_object_va: bad object_base ptr\n");
  904. goto exit;
  905. }
  906. if (I40E_HMC_INFO_SIGNATURE != hmc_info->signature) {
  907. ret_code = I40E_ERR_BAD_PTR;
  908. hw_dbg(hw, "i40e_hmc_get_object_va: bad hmc_info->signature\n");
  909. goto exit;
  910. }
  911. if (obj_idx >= hmc_info->hmc_obj[rsrc_type].cnt) {
  912. hw_dbg(hw, "i40e_hmc_get_object_va: returns error %d\n",
  913. ret_code);
  914. ret_code = I40E_ERR_INVALID_HMC_OBJ_INDEX;
  915. goto exit;
  916. }
  917. /* find sd index and limit */
  918. I40E_FIND_SD_INDEX_LIMIT(hmc_info, rsrc_type, obj_idx, 1,
  919. &sd_idx, &sd_lmt);
  920. sd_entry = &hmc_info->sd_table.sd_entry[sd_idx];
  921. obj_offset_in_fpm = hmc_info->hmc_obj[rsrc_type].base +
  922. hmc_info->hmc_obj[rsrc_type].size * obj_idx;
  923. if (I40E_SD_TYPE_PAGED == sd_entry->entry_type) {
  924. I40E_FIND_PD_INDEX_LIMIT(hmc_info, rsrc_type, obj_idx, 1,
  925. &pd_idx, &pd_lmt);
  926. rel_pd_idx = pd_idx % I40E_HMC_PD_CNT_IN_SD;
  927. pd_entry = &sd_entry->u.pd_table.pd_entry[rel_pd_idx];
  928. obj_offset_in_pd = (u32)(obj_offset_in_fpm %
  929. I40E_HMC_PAGED_BP_SIZE);
  930. *object_base = (u8 *)pd_entry->bp.addr.va + obj_offset_in_pd;
  931. } else {
  932. obj_offset_in_sd = (u32)(obj_offset_in_fpm %
  933. I40E_HMC_DIRECT_BP_SIZE);
  934. *object_base = (u8 *)sd_entry->u.bp.addr.va + obj_offset_in_sd;
  935. }
  936. exit:
  937. return ret_code;
  938. }
  939. /**
  940. * i40e_clear_lan_tx_queue_context - clear the HMC context for the queue
  941. * @hw: the hardware struct
  942. * @queue: the queue we care about
  943. **/
  944. i40e_status i40e_clear_lan_tx_queue_context(struct i40e_hw *hw,
  945. u16 queue)
  946. {
  947. i40e_status err;
  948. u8 *context_bytes;
  949. err = i40e_hmc_get_object_va(&hw->hmc, &context_bytes,
  950. I40E_HMC_LAN_TX, queue);
  951. if (err < 0)
  952. return err;
  953. return i40e_clear_hmc_context(hw, context_bytes, I40E_HMC_LAN_TX);
  954. }
  955. /**
  956. * i40e_set_lan_tx_queue_context - set the HMC context for the queue
  957. * @hw: the hardware struct
  958. * @queue: the queue we care about
  959. * @s: the struct to be filled
  960. **/
  961. i40e_status i40e_set_lan_tx_queue_context(struct i40e_hw *hw,
  962. u16 queue,
  963. struct i40e_hmc_obj_txq *s)
  964. {
  965. i40e_status err;
  966. u8 *context_bytes;
  967. err = i40e_hmc_get_object_va(&hw->hmc, &context_bytes,
  968. I40E_HMC_LAN_TX, queue);
  969. if (err < 0)
  970. return err;
  971. return i40e_set_hmc_context(context_bytes,
  972. i40e_hmc_txq_ce_info, (u8 *)s);
  973. }
  974. /**
  975. * i40e_clear_lan_rx_queue_context - clear the HMC context for the queue
  976. * @hw: the hardware struct
  977. * @queue: the queue we care about
  978. **/
  979. i40e_status i40e_clear_lan_rx_queue_context(struct i40e_hw *hw,
  980. u16 queue)
  981. {
  982. i40e_status err;
  983. u8 *context_bytes;
  984. err = i40e_hmc_get_object_va(&hw->hmc, &context_bytes,
  985. I40E_HMC_LAN_RX, queue);
  986. if (err < 0)
  987. return err;
  988. return i40e_clear_hmc_context(hw, context_bytes, I40E_HMC_LAN_RX);
  989. }
  990. /**
  991. * i40e_set_lan_rx_queue_context - set the HMC context for the queue
  992. * @hw: the hardware struct
  993. * @queue: the queue we care about
  994. * @s: the struct to be filled
  995. **/
  996. i40e_status i40e_set_lan_rx_queue_context(struct i40e_hw *hw,
  997. u16 queue,
  998. struct i40e_hmc_obj_rxq *s)
  999. {
  1000. i40e_status err;
  1001. u8 *context_bytes;
  1002. err = i40e_hmc_get_object_va(&hw->hmc, &context_bytes,
  1003. I40E_HMC_LAN_RX, queue);
  1004. if (err < 0)
  1005. return err;
  1006. return i40e_set_hmc_context(context_bytes,
  1007. i40e_hmc_rxq_ce_info, (u8 *)s);
  1008. }