i40e_lan_hmc.c 34 KB

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