qed_cxt.c 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553
  1. /* QLogic qed NIC Driver
  2. * Copyright (c) 2015-2017 QLogic Corporation
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * OpenIB.org BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and /or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. */
  32. #include <linux/types.h>
  33. #include <linux/bitops.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/errno.h>
  36. #include <linux/kernel.h>
  37. #include <linux/list.h>
  38. #include <linux/log2.h>
  39. #include <linux/pci.h>
  40. #include <linux/slab.h>
  41. #include <linux/string.h>
  42. #include <linux/bitops.h>
  43. #include "qed.h"
  44. #include "qed_cxt.h"
  45. #include "qed_dev_api.h"
  46. #include "qed_hsi.h"
  47. #include "qed_hw.h"
  48. #include "qed_init_ops.h"
  49. #include "qed_rdma.h"
  50. #include "qed_reg_addr.h"
  51. #include "qed_sriov.h"
  52. /* Max number of connection types in HW (DQ/CDU etc.) */
  53. #define MAX_CONN_TYPES PROTOCOLID_COMMON
  54. #define NUM_TASK_TYPES 2
  55. #define NUM_TASK_PF_SEGMENTS 4
  56. #define NUM_TASK_VF_SEGMENTS 1
  57. /* QM constants */
  58. #define QM_PQ_ELEMENT_SIZE 4 /* in bytes */
  59. /* Doorbell-Queue constants */
  60. #define DQ_RANGE_SHIFT 4
  61. #define DQ_RANGE_ALIGN BIT(DQ_RANGE_SHIFT)
  62. /* Searcher constants */
  63. #define SRC_MIN_NUM_ELEMS 256
  64. /* Timers constants */
  65. #define TM_SHIFT 7
  66. #define TM_ALIGN BIT(TM_SHIFT)
  67. #define TM_ELEM_SIZE 4
  68. #define ILT_DEFAULT_HW_P_SIZE 4
  69. #define ILT_PAGE_IN_BYTES(hw_p_size) (1U << ((hw_p_size) + 12))
  70. #define ILT_CFG_REG(cli, reg) PSWRQ2_REG_ ## cli ## _ ## reg ## _RT_OFFSET
  71. /* ILT entry structure */
  72. #define ILT_ENTRY_PHY_ADDR_MASK (~0ULL >> 12)
  73. #define ILT_ENTRY_PHY_ADDR_SHIFT 0
  74. #define ILT_ENTRY_VALID_MASK 0x1ULL
  75. #define ILT_ENTRY_VALID_SHIFT 52
  76. #define ILT_ENTRY_IN_REGS 2
  77. #define ILT_REG_SIZE_IN_BYTES 4
  78. /* connection context union */
  79. union conn_context {
  80. struct e4_core_conn_context core_ctx;
  81. struct e4_eth_conn_context eth_ctx;
  82. struct e4_iscsi_conn_context iscsi_ctx;
  83. struct e4_fcoe_conn_context fcoe_ctx;
  84. struct e4_roce_conn_context roce_ctx;
  85. };
  86. /* TYPE-0 task context - iSCSI, FCOE */
  87. union type0_task_context {
  88. struct e4_iscsi_task_context iscsi_ctx;
  89. struct e4_fcoe_task_context fcoe_ctx;
  90. };
  91. /* TYPE-1 task context - ROCE */
  92. union type1_task_context {
  93. struct e4_rdma_task_context roce_ctx;
  94. };
  95. struct src_ent {
  96. u8 opaque[56];
  97. u64 next;
  98. };
  99. #define CDUT_SEG_ALIGNMET 3 /* in 4k chunks */
  100. #define CDUT_SEG_ALIGNMET_IN_BYTES BIT(CDUT_SEG_ALIGNMET + 12)
  101. #define CONN_CXT_SIZE(p_hwfn) \
  102. ALIGNED_TYPE_SIZE(union conn_context, p_hwfn)
  103. #define SRQ_CXT_SIZE (sizeof(struct rdma_srq_context))
  104. #define TYPE0_TASK_CXT_SIZE(p_hwfn) \
  105. ALIGNED_TYPE_SIZE(union type0_task_context, p_hwfn)
  106. /* Alignment is inherent to the type1_task_context structure */
  107. #define TYPE1_TASK_CXT_SIZE(p_hwfn) sizeof(union type1_task_context)
  108. /* PF per protocl configuration object */
  109. #define TASK_SEGMENTS (NUM_TASK_PF_SEGMENTS + NUM_TASK_VF_SEGMENTS)
  110. #define TASK_SEGMENT_VF (NUM_TASK_PF_SEGMENTS)
  111. struct qed_tid_seg {
  112. u32 count;
  113. u8 type;
  114. bool has_fl_mem;
  115. };
  116. struct qed_conn_type_cfg {
  117. u32 cid_count;
  118. u32 cids_per_vf;
  119. struct qed_tid_seg tid_seg[TASK_SEGMENTS];
  120. };
  121. /* ILT Client configuration, Per connection type (protocol) resources. */
  122. #define ILT_CLI_PF_BLOCKS (1 + NUM_TASK_PF_SEGMENTS * 2)
  123. #define ILT_CLI_VF_BLOCKS (1 + NUM_TASK_VF_SEGMENTS * 2)
  124. #define CDUC_BLK (0)
  125. #define SRQ_BLK (0)
  126. #define CDUT_SEG_BLK(n) (1 + (u8)(n))
  127. #define CDUT_FL_SEG_BLK(n, X) (1 + (n) + NUM_TASK_ ## X ## _SEGMENTS)
  128. enum ilt_clients {
  129. ILT_CLI_CDUC,
  130. ILT_CLI_CDUT,
  131. ILT_CLI_QM,
  132. ILT_CLI_TM,
  133. ILT_CLI_SRC,
  134. ILT_CLI_TSDM,
  135. ILT_CLI_MAX
  136. };
  137. struct ilt_cfg_pair {
  138. u32 reg;
  139. u32 val;
  140. };
  141. struct qed_ilt_cli_blk {
  142. u32 total_size; /* 0 means not active */
  143. u32 real_size_in_page;
  144. u32 start_line;
  145. u32 dynamic_line_cnt;
  146. };
  147. struct qed_ilt_client_cfg {
  148. bool active;
  149. /* ILT boundaries */
  150. struct ilt_cfg_pair first;
  151. struct ilt_cfg_pair last;
  152. struct ilt_cfg_pair p_size;
  153. /* ILT client blocks for PF */
  154. struct qed_ilt_cli_blk pf_blks[ILT_CLI_PF_BLOCKS];
  155. u32 pf_total_lines;
  156. /* ILT client blocks for VFs */
  157. struct qed_ilt_cli_blk vf_blks[ILT_CLI_VF_BLOCKS];
  158. u32 vf_total_lines;
  159. };
  160. /* Per Path -
  161. * ILT shadow table
  162. * Protocol acquired CID lists
  163. * PF start line in ILT
  164. */
  165. struct qed_dma_mem {
  166. dma_addr_t p_phys;
  167. void *p_virt;
  168. size_t size;
  169. };
  170. struct qed_cid_acquired_map {
  171. u32 start_cid;
  172. u32 max_count;
  173. unsigned long *cid_map;
  174. };
  175. struct qed_cxt_mngr {
  176. /* Per protocl configuration */
  177. struct qed_conn_type_cfg conn_cfg[MAX_CONN_TYPES];
  178. /* computed ILT structure */
  179. struct qed_ilt_client_cfg clients[ILT_CLI_MAX];
  180. /* Task type sizes */
  181. u32 task_type_size[NUM_TASK_TYPES];
  182. /* total number of VFs for this hwfn -
  183. * ALL VFs are symmetric in terms of HW resources
  184. */
  185. u32 vf_count;
  186. /* Acquired CIDs */
  187. struct qed_cid_acquired_map acquired[MAX_CONN_TYPES];
  188. struct qed_cid_acquired_map
  189. acquired_vf[MAX_CONN_TYPES][MAX_NUM_VFS];
  190. /* ILT shadow table */
  191. struct qed_dma_mem *ilt_shadow;
  192. u32 pf_start_line;
  193. /* Mutex for a dynamic ILT allocation */
  194. struct mutex mutex;
  195. /* SRC T2 */
  196. struct qed_dma_mem *t2;
  197. u32 t2_num_pages;
  198. u64 first_free;
  199. u64 last_free;
  200. /* total number of SRQ's for this hwfn */
  201. u32 srq_count;
  202. /* Maximal number of L2 steering filters */
  203. u32 arfs_count;
  204. };
  205. static bool src_proto(enum protocol_type type)
  206. {
  207. return type == PROTOCOLID_ISCSI ||
  208. type == PROTOCOLID_FCOE ||
  209. type == PROTOCOLID_IWARP;
  210. }
  211. static bool tm_cid_proto(enum protocol_type type)
  212. {
  213. return type == PROTOCOLID_ISCSI ||
  214. type == PROTOCOLID_FCOE ||
  215. type == PROTOCOLID_ROCE ||
  216. type == PROTOCOLID_IWARP;
  217. }
  218. static bool tm_tid_proto(enum protocol_type type)
  219. {
  220. return type == PROTOCOLID_FCOE;
  221. }
  222. /* counts the iids for the CDU/CDUC ILT client configuration */
  223. struct qed_cdu_iids {
  224. u32 pf_cids;
  225. u32 per_vf_cids;
  226. };
  227. static void qed_cxt_cdu_iids(struct qed_cxt_mngr *p_mngr,
  228. struct qed_cdu_iids *iids)
  229. {
  230. u32 type;
  231. for (type = 0; type < MAX_CONN_TYPES; type++) {
  232. iids->pf_cids += p_mngr->conn_cfg[type].cid_count;
  233. iids->per_vf_cids += p_mngr->conn_cfg[type].cids_per_vf;
  234. }
  235. }
  236. /* counts the iids for the Searcher block configuration */
  237. struct qed_src_iids {
  238. u32 pf_cids;
  239. u32 per_vf_cids;
  240. };
  241. static void qed_cxt_src_iids(struct qed_cxt_mngr *p_mngr,
  242. struct qed_src_iids *iids)
  243. {
  244. u32 i;
  245. for (i = 0; i < MAX_CONN_TYPES; i++) {
  246. if (!src_proto(i))
  247. continue;
  248. iids->pf_cids += p_mngr->conn_cfg[i].cid_count;
  249. iids->per_vf_cids += p_mngr->conn_cfg[i].cids_per_vf;
  250. }
  251. /* Add L2 filtering filters in addition */
  252. iids->pf_cids += p_mngr->arfs_count;
  253. }
  254. /* counts the iids for the Timers block configuration */
  255. struct qed_tm_iids {
  256. u32 pf_cids;
  257. u32 pf_tids[NUM_TASK_PF_SEGMENTS]; /* per segment */
  258. u32 pf_tids_total;
  259. u32 per_vf_cids;
  260. u32 per_vf_tids;
  261. };
  262. static void qed_cxt_tm_iids(struct qed_hwfn *p_hwfn,
  263. struct qed_cxt_mngr *p_mngr,
  264. struct qed_tm_iids *iids)
  265. {
  266. bool tm_vf_required = false;
  267. bool tm_required = false;
  268. int i, j;
  269. /* Timers is a special case -> we don't count how many cids require
  270. * timers but what's the max cid that will be used by the timer block.
  271. * therefore we traverse in reverse order, and once we hit a protocol
  272. * that requires the timers memory, we'll sum all the protocols up
  273. * to that one.
  274. */
  275. for (i = MAX_CONN_TYPES - 1; i >= 0; i--) {
  276. struct qed_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[i];
  277. if (tm_cid_proto(i) || tm_required) {
  278. if (p_cfg->cid_count)
  279. tm_required = true;
  280. iids->pf_cids += p_cfg->cid_count;
  281. }
  282. if (tm_cid_proto(i) || tm_vf_required) {
  283. if (p_cfg->cids_per_vf)
  284. tm_vf_required = true;
  285. iids->per_vf_cids += p_cfg->cids_per_vf;
  286. }
  287. if (tm_tid_proto(i)) {
  288. struct qed_tid_seg *segs = p_cfg->tid_seg;
  289. /* for each segment there is at most one
  290. * protocol for which count is not 0.
  291. */
  292. for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++)
  293. iids->pf_tids[j] += segs[j].count;
  294. /* The last array elelment is for the VFs. As for PF
  295. * segments there can be only one protocol for
  296. * which this value is not 0.
  297. */
  298. iids->per_vf_tids += segs[NUM_TASK_PF_SEGMENTS].count;
  299. }
  300. }
  301. iids->pf_cids = roundup(iids->pf_cids, TM_ALIGN);
  302. iids->per_vf_cids = roundup(iids->per_vf_cids, TM_ALIGN);
  303. iids->per_vf_tids = roundup(iids->per_vf_tids, TM_ALIGN);
  304. for (iids->pf_tids_total = 0, j = 0; j < NUM_TASK_PF_SEGMENTS; j++) {
  305. iids->pf_tids[j] = roundup(iids->pf_tids[j], TM_ALIGN);
  306. iids->pf_tids_total += iids->pf_tids[j];
  307. }
  308. }
  309. static void qed_cxt_qm_iids(struct qed_hwfn *p_hwfn,
  310. struct qed_qm_iids *iids)
  311. {
  312. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  313. struct qed_tid_seg *segs;
  314. u32 vf_cids = 0, type, j;
  315. u32 vf_tids = 0;
  316. for (type = 0; type < MAX_CONN_TYPES; type++) {
  317. iids->cids += p_mngr->conn_cfg[type].cid_count;
  318. vf_cids += p_mngr->conn_cfg[type].cids_per_vf;
  319. segs = p_mngr->conn_cfg[type].tid_seg;
  320. /* for each segment there is at most one
  321. * protocol for which count is not 0.
  322. */
  323. for (j = 0; j < NUM_TASK_PF_SEGMENTS; j++)
  324. iids->tids += segs[j].count;
  325. /* The last array elelment is for the VFs. As for PF
  326. * segments there can be only one protocol for
  327. * which this value is not 0.
  328. */
  329. vf_tids += segs[NUM_TASK_PF_SEGMENTS].count;
  330. }
  331. iids->vf_cids += vf_cids * p_mngr->vf_count;
  332. iids->tids += vf_tids * p_mngr->vf_count;
  333. DP_VERBOSE(p_hwfn, QED_MSG_ILT,
  334. "iids: CIDS %08x vf_cids %08x tids %08x vf_tids %08x\n",
  335. iids->cids, iids->vf_cids, iids->tids, vf_tids);
  336. }
  337. static struct qed_tid_seg *qed_cxt_tid_seg_info(struct qed_hwfn *p_hwfn,
  338. u32 seg)
  339. {
  340. struct qed_cxt_mngr *p_cfg = p_hwfn->p_cxt_mngr;
  341. u32 i;
  342. /* Find the protocol with tid count > 0 for this segment.
  343. * Note: there can only be one and this is already validated.
  344. */
  345. for (i = 0; i < MAX_CONN_TYPES; i++)
  346. if (p_cfg->conn_cfg[i].tid_seg[seg].count)
  347. return &p_cfg->conn_cfg[i].tid_seg[seg];
  348. return NULL;
  349. }
  350. static void qed_cxt_set_srq_count(struct qed_hwfn *p_hwfn, u32 num_srqs)
  351. {
  352. struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
  353. p_mgr->srq_count = num_srqs;
  354. }
  355. u32 qed_cxt_get_srq_count(struct qed_hwfn *p_hwfn)
  356. {
  357. struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
  358. return p_mgr->srq_count;
  359. }
  360. /* set the iids count per protocol */
  361. static void qed_cxt_set_proto_cid_count(struct qed_hwfn *p_hwfn,
  362. enum protocol_type type,
  363. u32 cid_count, u32 vf_cid_cnt)
  364. {
  365. struct qed_cxt_mngr *p_mgr = p_hwfn->p_cxt_mngr;
  366. struct qed_conn_type_cfg *p_conn = &p_mgr->conn_cfg[type];
  367. p_conn->cid_count = roundup(cid_count, DQ_RANGE_ALIGN);
  368. p_conn->cids_per_vf = roundup(vf_cid_cnt, DQ_RANGE_ALIGN);
  369. if (type == PROTOCOLID_ROCE) {
  370. u32 page_sz = p_mgr->clients[ILT_CLI_CDUC].p_size.val;
  371. u32 cxt_size = CONN_CXT_SIZE(p_hwfn);
  372. u32 elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
  373. u32 align = elems_per_page * DQ_RANGE_ALIGN;
  374. p_conn->cid_count = roundup(p_conn->cid_count, align);
  375. }
  376. }
  377. u32 qed_cxt_get_proto_cid_count(struct qed_hwfn *p_hwfn,
  378. enum protocol_type type, u32 *vf_cid)
  379. {
  380. if (vf_cid)
  381. *vf_cid = p_hwfn->p_cxt_mngr->conn_cfg[type].cids_per_vf;
  382. return p_hwfn->p_cxt_mngr->conn_cfg[type].cid_count;
  383. }
  384. u32 qed_cxt_get_proto_cid_start(struct qed_hwfn *p_hwfn,
  385. enum protocol_type type)
  386. {
  387. return p_hwfn->p_cxt_mngr->acquired[type].start_cid;
  388. }
  389. u32 qed_cxt_get_proto_tid_count(struct qed_hwfn *p_hwfn,
  390. enum protocol_type type)
  391. {
  392. u32 cnt = 0;
  393. int i;
  394. for (i = 0; i < TASK_SEGMENTS; i++)
  395. cnt += p_hwfn->p_cxt_mngr->conn_cfg[type].tid_seg[i].count;
  396. return cnt;
  397. }
  398. static void qed_cxt_set_proto_tid_count(struct qed_hwfn *p_hwfn,
  399. enum protocol_type proto,
  400. u8 seg,
  401. u8 seg_type, u32 count, bool has_fl)
  402. {
  403. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  404. struct qed_tid_seg *p_seg = &p_mngr->conn_cfg[proto].tid_seg[seg];
  405. p_seg->count = count;
  406. p_seg->has_fl_mem = has_fl;
  407. p_seg->type = seg_type;
  408. }
  409. static void qed_ilt_cli_blk_fill(struct qed_ilt_client_cfg *p_cli,
  410. struct qed_ilt_cli_blk *p_blk,
  411. u32 start_line, u32 total_size, u32 elem_size)
  412. {
  413. u32 ilt_size = ILT_PAGE_IN_BYTES(p_cli->p_size.val);
  414. /* verify thatits called only once for each block */
  415. if (p_blk->total_size)
  416. return;
  417. p_blk->total_size = total_size;
  418. p_blk->real_size_in_page = 0;
  419. if (elem_size)
  420. p_blk->real_size_in_page = (ilt_size / elem_size) * elem_size;
  421. p_blk->start_line = start_line;
  422. }
  423. static void qed_ilt_cli_adv_line(struct qed_hwfn *p_hwfn,
  424. struct qed_ilt_client_cfg *p_cli,
  425. struct qed_ilt_cli_blk *p_blk,
  426. u32 *p_line, enum ilt_clients client_id)
  427. {
  428. if (!p_blk->total_size)
  429. return;
  430. if (!p_cli->active)
  431. p_cli->first.val = *p_line;
  432. p_cli->active = true;
  433. *p_line += DIV_ROUND_UP(p_blk->total_size, p_blk->real_size_in_page);
  434. p_cli->last.val = *p_line - 1;
  435. DP_VERBOSE(p_hwfn, QED_MSG_ILT,
  436. "ILT[Client %d] - Lines: [%08x - %08x]. Block - Size %08x [Real %08x] Start line %d\n",
  437. client_id, p_cli->first.val,
  438. p_cli->last.val, p_blk->total_size,
  439. p_blk->real_size_in_page, p_blk->start_line);
  440. }
  441. static u32 qed_ilt_get_dynamic_line_cnt(struct qed_hwfn *p_hwfn,
  442. enum ilt_clients ilt_client)
  443. {
  444. u32 cid_count = p_hwfn->p_cxt_mngr->conn_cfg[PROTOCOLID_ROCE].cid_count;
  445. struct qed_ilt_client_cfg *p_cli;
  446. u32 lines_to_skip = 0;
  447. u32 cxts_per_p;
  448. if (ilt_client == ILT_CLI_CDUC) {
  449. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
  450. cxts_per_p = ILT_PAGE_IN_BYTES(p_cli->p_size.val) /
  451. (u32) CONN_CXT_SIZE(p_hwfn);
  452. lines_to_skip = cid_count / cxts_per_p;
  453. }
  454. return lines_to_skip;
  455. }
  456. static struct qed_ilt_client_cfg *qed_cxt_set_cli(struct qed_ilt_client_cfg
  457. *p_cli)
  458. {
  459. p_cli->active = false;
  460. p_cli->first.val = 0;
  461. p_cli->last.val = 0;
  462. return p_cli;
  463. }
  464. static struct qed_ilt_cli_blk *qed_cxt_set_blk(struct qed_ilt_cli_blk *p_blk)
  465. {
  466. p_blk->total_size = 0;
  467. return p_blk;
  468. }
  469. int qed_cxt_cfg_ilt_compute(struct qed_hwfn *p_hwfn, u32 *line_count)
  470. {
  471. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  472. u32 curr_line, total, i, task_size, line;
  473. struct qed_ilt_client_cfg *p_cli;
  474. struct qed_ilt_cli_blk *p_blk;
  475. struct qed_cdu_iids cdu_iids;
  476. struct qed_src_iids src_iids;
  477. struct qed_qm_iids qm_iids;
  478. struct qed_tm_iids tm_iids;
  479. struct qed_tid_seg *p_seg;
  480. memset(&qm_iids, 0, sizeof(qm_iids));
  481. memset(&cdu_iids, 0, sizeof(cdu_iids));
  482. memset(&src_iids, 0, sizeof(src_iids));
  483. memset(&tm_iids, 0, sizeof(tm_iids));
  484. p_mngr->pf_start_line = RESC_START(p_hwfn, QED_ILT);
  485. DP_VERBOSE(p_hwfn, QED_MSG_ILT,
  486. "hwfn [%d] - Set context manager starting line to be 0x%08x\n",
  487. p_hwfn->my_id, p_hwfn->p_cxt_mngr->pf_start_line);
  488. /* CDUC */
  489. p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_CDUC]);
  490. curr_line = p_mngr->pf_start_line;
  491. /* CDUC PF */
  492. p_cli->pf_total_lines = 0;
  493. /* get the counters for the CDUC and QM clients */
  494. qed_cxt_cdu_iids(p_mngr, &cdu_iids);
  495. p_blk = qed_cxt_set_blk(&p_cli->pf_blks[CDUC_BLK]);
  496. total = cdu_iids.pf_cids * CONN_CXT_SIZE(p_hwfn);
  497. qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
  498. total, CONN_CXT_SIZE(p_hwfn));
  499. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC);
  500. p_cli->pf_total_lines = curr_line - p_blk->start_line;
  501. p_blk->dynamic_line_cnt = qed_ilt_get_dynamic_line_cnt(p_hwfn,
  502. ILT_CLI_CDUC);
  503. /* CDUC VF */
  504. p_blk = qed_cxt_set_blk(&p_cli->vf_blks[CDUC_BLK]);
  505. total = cdu_iids.per_vf_cids * CONN_CXT_SIZE(p_hwfn);
  506. qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
  507. total, CONN_CXT_SIZE(p_hwfn));
  508. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_CDUC);
  509. p_cli->vf_total_lines = curr_line - p_blk->start_line;
  510. for (i = 1; i < p_mngr->vf_count; i++)
  511. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  512. ILT_CLI_CDUC);
  513. /* CDUT PF */
  514. p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_CDUT]);
  515. p_cli->first.val = curr_line;
  516. /* first the 'working' task memory */
  517. for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
  518. p_seg = qed_cxt_tid_seg_info(p_hwfn, i);
  519. if (!p_seg || p_seg->count == 0)
  520. continue;
  521. p_blk = qed_cxt_set_blk(&p_cli->pf_blks[CDUT_SEG_BLK(i)]);
  522. total = p_seg->count * p_mngr->task_type_size[p_seg->type];
  523. qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line, total,
  524. p_mngr->task_type_size[p_seg->type]);
  525. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  526. ILT_CLI_CDUT);
  527. }
  528. /* next the 'init' task memory (forced load memory) */
  529. for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
  530. p_seg = qed_cxt_tid_seg_info(p_hwfn, i);
  531. if (!p_seg || p_seg->count == 0)
  532. continue;
  533. p_blk =
  534. qed_cxt_set_blk(&p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)]);
  535. if (!p_seg->has_fl_mem) {
  536. /* The segment is active (total size pf 'working'
  537. * memory is > 0) but has no FL (forced-load, Init)
  538. * memory. Thus:
  539. *
  540. * 1. The total-size in the corrsponding FL block of
  541. * the ILT client is set to 0 - No ILT line are
  542. * provisioned and no ILT memory allocated.
  543. *
  544. * 2. The start-line of said block is set to the
  545. * start line of the matching working memory
  546. * block in the ILT client. This is later used to
  547. * configure the CDU segment offset registers and
  548. * results in an FL command for TIDs of this
  549. * segement behaves as regular load commands
  550. * (loading TIDs from the working memory).
  551. */
  552. line = p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line;
  553. qed_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0);
  554. continue;
  555. }
  556. total = p_seg->count * p_mngr->task_type_size[p_seg->type];
  557. qed_ilt_cli_blk_fill(p_cli, p_blk,
  558. curr_line, total,
  559. p_mngr->task_type_size[p_seg->type]);
  560. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  561. ILT_CLI_CDUT);
  562. }
  563. p_cli->pf_total_lines = curr_line - p_cli->pf_blks[0].start_line;
  564. /* CDUT VF */
  565. p_seg = qed_cxt_tid_seg_info(p_hwfn, TASK_SEGMENT_VF);
  566. if (p_seg && p_seg->count) {
  567. /* Stricly speaking we need to iterate over all VF
  568. * task segment types, but a VF has only 1 segment
  569. */
  570. /* 'working' memory */
  571. total = p_seg->count * p_mngr->task_type_size[p_seg->type];
  572. p_blk = qed_cxt_set_blk(&p_cli->vf_blks[CDUT_SEG_BLK(0)]);
  573. qed_ilt_cli_blk_fill(p_cli, p_blk,
  574. curr_line, total,
  575. p_mngr->task_type_size[p_seg->type]);
  576. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  577. ILT_CLI_CDUT);
  578. /* 'init' memory */
  579. p_blk =
  580. qed_cxt_set_blk(&p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)]);
  581. if (!p_seg->has_fl_mem) {
  582. /* see comment above */
  583. line = p_cli->vf_blks[CDUT_SEG_BLK(0)].start_line;
  584. qed_ilt_cli_blk_fill(p_cli, p_blk, line, 0, 0);
  585. } else {
  586. task_size = p_mngr->task_type_size[p_seg->type];
  587. qed_ilt_cli_blk_fill(p_cli, p_blk,
  588. curr_line, total, task_size);
  589. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  590. ILT_CLI_CDUT);
  591. }
  592. p_cli->vf_total_lines = curr_line -
  593. p_cli->vf_blks[0].start_line;
  594. /* Now for the rest of the VFs */
  595. for (i = 1; i < p_mngr->vf_count; i++) {
  596. p_blk = &p_cli->vf_blks[CDUT_SEG_BLK(0)];
  597. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  598. ILT_CLI_CDUT);
  599. p_blk = &p_cli->vf_blks[CDUT_FL_SEG_BLK(0, VF)];
  600. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  601. ILT_CLI_CDUT);
  602. }
  603. }
  604. /* QM */
  605. p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_QM]);
  606. p_blk = qed_cxt_set_blk(&p_cli->pf_blks[0]);
  607. qed_cxt_qm_iids(p_hwfn, &qm_iids);
  608. total = qed_qm_pf_mem_size(qm_iids.cids,
  609. qm_iids.vf_cids, qm_iids.tids,
  610. p_hwfn->qm_info.num_pqs,
  611. p_hwfn->qm_info.num_vf_pqs);
  612. DP_VERBOSE(p_hwfn,
  613. QED_MSG_ILT,
  614. "QM ILT Info, (cids=%d, vf_cids=%d, tids=%d, num_pqs=%d, num_vf_pqs=%d, memory_size=%d)\n",
  615. qm_iids.cids,
  616. qm_iids.vf_cids,
  617. qm_iids.tids,
  618. p_hwfn->qm_info.num_pqs, p_hwfn->qm_info.num_vf_pqs, total);
  619. qed_ilt_cli_blk_fill(p_cli, p_blk,
  620. curr_line, total * 0x1000,
  621. QM_PQ_ELEMENT_SIZE);
  622. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line, ILT_CLI_QM);
  623. p_cli->pf_total_lines = curr_line - p_blk->start_line;
  624. /* SRC */
  625. p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_SRC]);
  626. qed_cxt_src_iids(p_mngr, &src_iids);
  627. /* Both the PF and VFs searcher connections are stored in the per PF
  628. * database. Thus sum the PF searcher cids and all the VFs searcher
  629. * cids.
  630. */
  631. total = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
  632. if (total) {
  633. u32 local_max = max_t(u32, total,
  634. SRC_MIN_NUM_ELEMS);
  635. total = roundup_pow_of_two(local_max);
  636. p_blk = qed_cxt_set_blk(&p_cli->pf_blks[0]);
  637. qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
  638. total * sizeof(struct src_ent),
  639. sizeof(struct src_ent));
  640. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  641. ILT_CLI_SRC);
  642. p_cli->pf_total_lines = curr_line - p_blk->start_line;
  643. }
  644. /* TM PF */
  645. p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_TM]);
  646. qed_cxt_tm_iids(p_hwfn, p_mngr, &tm_iids);
  647. total = tm_iids.pf_cids + tm_iids.pf_tids_total;
  648. if (total) {
  649. p_blk = qed_cxt_set_blk(&p_cli->pf_blks[0]);
  650. qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
  651. total * TM_ELEM_SIZE, TM_ELEM_SIZE);
  652. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  653. ILT_CLI_TM);
  654. p_cli->pf_total_lines = curr_line - p_blk->start_line;
  655. }
  656. /* TM VF */
  657. total = tm_iids.per_vf_cids + tm_iids.per_vf_tids;
  658. if (total) {
  659. p_blk = qed_cxt_set_blk(&p_cli->vf_blks[0]);
  660. qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
  661. total * TM_ELEM_SIZE, TM_ELEM_SIZE);
  662. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  663. ILT_CLI_TM);
  664. p_cli->vf_total_lines = curr_line - p_blk->start_line;
  665. for (i = 1; i < p_mngr->vf_count; i++)
  666. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  667. ILT_CLI_TM);
  668. }
  669. /* TSDM (SRQ CONTEXT) */
  670. total = qed_cxt_get_srq_count(p_hwfn);
  671. if (total) {
  672. p_cli = qed_cxt_set_cli(&p_mngr->clients[ILT_CLI_TSDM]);
  673. p_blk = qed_cxt_set_blk(&p_cli->pf_blks[SRQ_BLK]);
  674. qed_ilt_cli_blk_fill(p_cli, p_blk, curr_line,
  675. total * SRQ_CXT_SIZE, SRQ_CXT_SIZE);
  676. qed_ilt_cli_adv_line(p_hwfn, p_cli, p_blk, &curr_line,
  677. ILT_CLI_TSDM);
  678. p_cli->pf_total_lines = curr_line - p_blk->start_line;
  679. }
  680. *line_count = curr_line - p_hwfn->p_cxt_mngr->pf_start_line;
  681. if (curr_line - p_hwfn->p_cxt_mngr->pf_start_line >
  682. RESC_NUM(p_hwfn, QED_ILT))
  683. return -EINVAL;
  684. return 0;
  685. }
  686. u32 qed_cxt_cfg_ilt_compute_excess(struct qed_hwfn *p_hwfn, u32 used_lines)
  687. {
  688. struct qed_ilt_client_cfg *p_cli;
  689. u32 excess_lines, available_lines;
  690. struct qed_cxt_mngr *p_mngr;
  691. u32 ilt_page_size, elem_size;
  692. struct qed_tid_seg *p_seg;
  693. int i;
  694. available_lines = RESC_NUM(p_hwfn, QED_ILT);
  695. excess_lines = used_lines - available_lines;
  696. if (!excess_lines)
  697. return 0;
  698. if (!QED_IS_RDMA_PERSONALITY(p_hwfn))
  699. return 0;
  700. p_mngr = p_hwfn->p_cxt_mngr;
  701. p_cli = &p_mngr->clients[ILT_CLI_CDUT];
  702. ilt_page_size = ILT_PAGE_IN_BYTES(p_cli->p_size.val);
  703. for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
  704. p_seg = qed_cxt_tid_seg_info(p_hwfn, i);
  705. if (!p_seg || p_seg->count == 0)
  706. continue;
  707. elem_size = p_mngr->task_type_size[p_seg->type];
  708. if (!elem_size)
  709. continue;
  710. return (ilt_page_size / elem_size) * excess_lines;
  711. }
  712. DP_NOTICE(p_hwfn, "failed computing excess ILT lines\n");
  713. return 0;
  714. }
  715. static void qed_cxt_src_t2_free(struct qed_hwfn *p_hwfn)
  716. {
  717. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  718. u32 i;
  719. if (!p_mngr->t2)
  720. return;
  721. for (i = 0; i < p_mngr->t2_num_pages; i++)
  722. if (p_mngr->t2[i].p_virt)
  723. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  724. p_mngr->t2[i].size,
  725. p_mngr->t2[i].p_virt,
  726. p_mngr->t2[i].p_phys);
  727. kfree(p_mngr->t2);
  728. p_mngr->t2 = NULL;
  729. }
  730. static int qed_cxt_src_t2_alloc(struct qed_hwfn *p_hwfn)
  731. {
  732. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  733. u32 conn_num, total_size, ent_per_page, psz, i;
  734. struct qed_ilt_client_cfg *p_src;
  735. struct qed_src_iids src_iids;
  736. struct qed_dma_mem *p_t2;
  737. int rc;
  738. memset(&src_iids, 0, sizeof(src_iids));
  739. /* if the SRC ILT client is inactive - there are no connection
  740. * requiring the searcer, leave.
  741. */
  742. p_src = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_SRC];
  743. if (!p_src->active)
  744. return 0;
  745. qed_cxt_src_iids(p_mngr, &src_iids);
  746. conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
  747. total_size = conn_num * sizeof(struct src_ent);
  748. /* use the same page size as the SRC ILT client */
  749. psz = ILT_PAGE_IN_BYTES(p_src->p_size.val);
  750. p_mngr->t2_num_pages = DIV_ROUND_UP(total_size, psz);
  751. /* allocate t2 */
  752. p_mngr->t2 = kcalloc(p_mngr->t2_num_pages, sizeof(struct qed_dma_mem),
  753. GFP_KERNEL);
  754. if (!p_mngr->t2) {
  755. rc = -ENOMEM;
  756. goto t2_fail;
  757. }
  758. /* allocate t2 pages */
  759. for (i = 0; i < p_mngr->t2_num_pages; i++) {
  760. u32 size = min_t(u32, total_size, psz);
  761. void **p_virt = &p_mngr->t2[i].p_virt;
  762. *p_virt = dma_zalloc_coherent(&p_hwfn->cdev->pdev->dev,
  763. size, &p_mngr->t2[i].p_phys,
  764. GFP_KERNEL);
  765. if (!p_mngr->t2[i].p_virt) {
  766. rc = -ENOMEM;
  767. goto t2_fail;
  768. }
  769. p_mngr->t2[i].size = size;
  770. total_size -= size;
  771. }
  772. /* Set the t2 pointers */
  773. /* entries per page - must be a power of two */
  774. ent_per_page = psz / sizeof(struct src_ent);
  775. p_mngr->first_free = (u64) p_mngr->t2[0].p_phys;
  776. p_t2 = &p_mngr->t2[(conn_num - 1) / ent_per_page];
  777. p_mngr->last_free = (u64) p_t2->p_phys +
  778. ((conn_num - 1) & (ent_per_page - 1)) * sizeof(struct src_ent);
  779. for (i = 0; i < p_mngr->t2_num_pages; i++) {
  780. u32 ent_num = min_t(u32,
  781. ent_per_page,
  782. conn_num);
  783. struct src_ent *entries = p_mngr->t2[i].p_virt;
  784. u64 p_ent_phys = (u64) p_mngr->t2[i].p_phys, val;
  785. u32 j;
  786. for (j = 0; j < ent_num - 1; j++) {
  787. val = p_ent_phys + (j + 1) * sizeof(struct src_ent);
  788. entries[j].next = cpu_to_be64(val);
  789. }
  790. if (i < p_mngr->t2_num_pages - 1)
  791. val = (u64) p_mngr->t2[i + 1].p_phys;
  792. else
  793. val = 0;
  794. entries[j].next = cpu_to_be64(val);
  795. conn_num -= ent_num;
  796. }
  797. return 0;
  798. t2_fail:
  799. qed_cxt_src_t2_free(p_hwfn);
  800. return rc;
  801. }
  802. #define for_each_ilt_valid_client(pos, clients) \
  803. for (pos = 0; pos < ILT_CLI_MAX; pos++) \
  804. if (!clients[pos].active) { \
  805. continue; \
  806. } else \
  807. /* Total number of ILT lines used by this PF */
  808. static u32 qed_cxt_ilt_shadow_size(struct qed_ilt_client_cfg *ilt_clients)
  809. {
  810. u32 size = 0;
  811. u32 i;
  812. for_each_ilt_valid_client(i, ilt_clients)
  813. size += (ilt_clients[i].last.val - ilt_clients[i].first.val + 1);
  814. return size;
  815. }
  816. static void qed_ilt_shadow_free(struct qed_hwfn *p_hwfn)
  817. {
  818. struct qed_ilt_client_cfg *p_cli = p_hwfn->p_cxt_mngr->clients;
  819. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  820. u32 ilt_size, i;
  821. ilt_size = qed_cxt_ilt_shadow_size(p_cli);
  822. for (i = 0; p_mngr->ilt_shadow && i < ilt_size; i++) {
  823. struct qed_dma_mem *p_dma = &p_mngr->ilt_shadow[i];
  824. if (p_dma->p_virt)
  825. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  826. p_dma->size, p_dma->p_virt,
  827. p_dma->p_phys);
  828. p_dma->p_virt = NULL;
  829. }
  830. kfree(p_mngr->ilt_shadow);
  831. }
  832. static int qed_ilt_blk_alloc(struct qed_hwfn *p_hwfn,
  833. struct qed_ilt_cli_blk *p_blk,
  834. enum ilt_clients ilt_client,
  835. u32 start_line_offset)
  836. {
  837. struct qed_dma_mem *ilt_shadow = p_hwfn->p_cxt_mngr->ilt_shadow;
  838. u32 lines, line, sz_left, lines_to_skip = 0;
  839. /* Special handling for RoCE that supports dynamic allocation */
  840. if (QED_IS_RDMA_PERSONALITY(p_hwfn) &&
  841. ((ilt_client == ILT_CLI_CDUT) || ilt_client == ILT_CLI_TSDM))
  842. return 0;
  843. lines_to_skip = p_blk->dynamic_line_cnt;
  844. if (!p_blk->total_size)
  845. return 0;
  846. sz_left = p_blk->total_size;
  847. lines = DIV_ROUND_UP(sz_left, p_blk->real_size_in_page) - lines_to_skip;
  848. line = p_blk->start_line + start_line_offset -
  849. p_hwfn->p_cxt_mngr->pf_start_line + lines_to_skip;
  850. for (; lines; lines--) {
  851. dma_addr_t p_phys;
  852. void *p_virt;
  853. u32 size;
  854. size = min_t(u32, sz_left, p_blk->real_size_in_page);
  855. p_virt = dma_zalloc_coherent(&p_hwfn->cdev->pdev->dev, size,
  856. &p_phys, GFP_KERNEL);
  857. if (!p_virt)
  858. return -ENOMEM;
  859. ilt_shadow[line].p_phys = p_phys;
  860. ilt_shadow[line].p_virt = p_virt;
  861. ilt_shadow[line].size = size;
  862. DP_VERBOSE(p_hwfn, QED_MSG_ILT,
  863. "ILT shadow: Line [%d] Physical 0x%llx Virtual %p Size %d\n",
  864. line, (u64)p_phys, p_virt, size);
  865. sz_left -= size;
  866. line++;
  867. }
  868. return 0;
  869. }
  870. static int qed_ilt_shadow_alloc(struct qed_hwfn *p_hwfn)
  871. {
  872. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  873. struct qed_ilt_client_cfg *clients = p_mngr->clients;
  874. struct qed_ilt_cli_blk *p_blk;
  875. u32 size, i, j, k;
  876. int rc;
  877. size = qed_cxt_ilt_shadow_size(clients);
  878. p_mngr->ilt_shadow = kcalloc(size, sizeof(struct qed_dma_mem),
  879. GFP_KERNEL);
  880. if (!p_mngr->ilt_shadow) {
  881. rc = -ENOMEM;
  882. goto ilt_shadow_fail;
  883. }
  884. DP_VERBOSE(p_hwfn, QED_MSG_ILT,
  885. "Allocated 0x%x bytes for ilt shadow\n",
  886. (u32)(size * sizeof(struct qed_dma_mem)));
  887. for_each_ilt_valid_client(i, clients) {
  888. for (j = 0; j < ILT_CLI_PF_BLOCKS; j++) {
  889. p_blk = &clients[i].pf_blks[j];
  890. rc = qed_ilt_blk_alloc(p_hwfn, p_blk, i, 0);
  891. if (rc)
  892. goto ilt_shadow_fail;
  893. }
  894. for (k = 0; k < p_mngr->vf_count; k++) {
  895. for (j = 0; j < ILT_CLI_VF_BLOCKS; j++) {
  896. u32 lines = clients[i].vf_total_lines * k;
  897. p_blk = &clients[i].vf_blks[j];
  898. rc = qed_ilt_blk_alloc(p_hwfn, p_blk, i, lines);
  899. if (rc)
  900. goto ilt_shadow_fail;
  901. }
  902. }
  903. }
  904. return 0;
  905. ilt_shadow_fail:
  906. qed_ilt_shadow_free(p_hwfn);
  907. return rc;
  908. }
  909. static void qed_cid_map_free(struct qed_hwfn *p_hwfn)
  910. {
  911. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  912. u32 type, vf;
  913. for (type = 0; type < MAX_CONN_TYPES; type++) {
  914. kfree(p_mngr->acquired[type].cid_map);
  915. p_mngr->acquired[type].max_count = 0;
  916. p_mngr->acquired[type].start_cid = 0;
  917. for (vf = 0; vf < MAX_NUM_VFS; vf++) {
  918. kfree(p_mngr->acquired_vf[type][vf].cid_map);
  919. p_mngr->acquired_vf[type][vf].max_count = 0;
  920. p_mngr->acquired_vf[type][vf].start_cid = 0;
  921. }
  922. }
  923. }
  924. static int
  925. qed_cid_map_alloc_single(struct qed_hwfn *p_hwfn,
  926. u32 type,
  927. u32 cid_start,
  928. u32 cid_count, struct qed_cid_acquired_map *p_map)
  929. {
  930. u32 size;
  931. if (!cid_count)
  932. return 0;
  933. size = DIV_ROUND_UP(cid_count,
  934. sizeof(unsigned long) * BITS_PER_BYTE) *
  935. sizeof(unsigned long);
  936. p_map->cid_map = kzalloc(size, GFP_KERNEL);
  937. if (!p_map->cid_map)
  938. return -ENOMEM;
  939. p_map->max_count = cid_count;
  940. p_map->start_cid = cid_start;
  941. DP_VERBOSE(p_hwfn, QED_MSG_CXT,
  942. "Type %08x start: %08x count %08x\n",
  943. type, p_map->start_cid, p_map->max_count);
  944. return 0;
  945. }
  946. static int qed_cid_map_alloc(struct qed_hwfn *p_hwfn)
  947. {
  948. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  949. u32 start_cid = 0, vf_start_cid = 0;
  950. u32 type, vf;
  951. for (type = 0; type < MAX_CONN_TYPES; type++) {
  952. struct qed_conn_type_cfg *p_cfg = &p_mngr->conn_cfg[type];
  953. struct qed_cid_acquired_map *p_map;
  954. /* Handle PF maps */
  955. p_map = &p_mngr->acquired[type];
  956. if (qed_cid_map_alloc_single(p_hwfn, type, start_cid,
  957. p_cfg->cid_count, p_map))
  958. goto cid_map_fail;
  959. /* Handle VF maps */
  960. for (vf = 0; vf < MAX_NUM_VFS; vf++) {
  961. p_map = &p_mngr->acquired_vf[type][vf];
  962. if (qed_cid_map_alloc_single(p_hwfn, type,
  963. vf_start_cid,
  964. p_cfg->cids_per_vf, p_map))
  965. goto cid_map_fail;
  966. }
  967. start_cid += p_cfg->cid_count;
  968. vf_start_cid += p_cfg->cids_per_vf;
  969. }
  970. return 0;
  971. cid_map_fail:
  972. qed_cid_map_free(p_hwfn);
  973. return -ENOMEM;
  974. }
  975. int qed_cxt_mngr_alloc(struct qed_hwfn *p_hwfn)
  976. {
  977. struct qed_ilt_client_cfg *clients;
  978. struct qed_cxt_mngr *p_mngr;
  979. u32 i;
  980. p_mngr = kzalloc(sizeof(*p_mngr), GFP_KERNEL);
  981. if (!p_mngr)
  982. return -ENOMEM;
  983. /* Initialize ILT client registers */
  984. clients = p_mngr->clients;
  985. clients[ILT_CLI_CDUC].first.reg = ILT_CFG_REG(CDUC, FIRST_ILT);
  986. clients[ILT_CLI_CDUC].last.reg = ILT_CFG_REG(CDUC, LAST_ILT);
  987. clients[ILT_CLI_CDUC].p_size.reg = ILT_CFG_REG(CDUC, P_SIZE);
  988. clients[ILT_CLI_QM].first.reg = ILT_CFG_REG(QM, FIRST_ILT);
  989. clients[ILT_CLI_QM].last.reg = ILT_CFG_REG(QM, LAST_ILT);
  990. clients[ILT_CLI_QM].p_size.reg = ILT_CFG_REG(QM, P_SIZE);
  991. clients[ILT_CLI_TM].first.reg = ILT_CFG_REG(TM, FIRST_ILT);
  992. clients[ILT_CLI_TM].last.reg = ILT_CFG_REG(TM, LAST_ILT);
  993. clients[ILT_CLI_TM].p_size.reg = ILT_CFG_REG(TM, P_SIZE);
  994. clients[ILT_CLI_SRC].first.reg = ILT_CFG_REG(SRC, FIRST_ILT);
  995. clients[ILT_CLI_SRC].last.reg = ILT_CFG_REG(SRC, LAST_ILT);
  996. clients[ILT_CLI_SRC].p_size.reg = ILT_CFG_REG(SRC, P_SIZE);
  997. clients[ILT_CLI_CDUT].first.reg = ILT_CFG_REG(CDUT, FIRST_ILT);
  998. clients[ILT_CLI_CDUT].last.reg = ILT_CFG_REG(CDUT, LAST_ILT);
  999. clients[ILT_CLI_CDUT].p_size.reg = ILT_CFG_REG(CDUT, P_SIZE);
  1000. clients[ILT_CLI_TSDM].first.reg = ILT_CFG_REG(TSDM, FIRST_ILT);
  1001. clients[ILT_CLI_TSDM].last.reg = ILT_CFG_REG(TSDM, LAST_ILT);
  1002. clients[ILT_CLI_TSDM].p_size.reg = ILT_CFG_REG(TSDM, P_SIZE);
  1003. /* default ILT page size for all clients is 64K */
  1004. for (i = 0; i < ILT_CLI_MAX; i++)
  1005. p_mngr->clients[i].p_size.val = ILT_DEFAULT_HW_P_SIZE;
  1006. /* Initialize task sizes */
  1007. p_mngr->task_type_size[0] = TYPE0_TASK_CXT_SIZE(p_hwfn);
  1008. p_mngr->task_type_size[1] = TYPE1_TASK_CXT_SIZE(p_hwfn);
  1009. if (p_hwfn->cdev->p_iov_info)
  1010. p_mngr->vf_count = p_hwfn->cdev->p_iov_info->total_vfs;
  1011. /* Initialize the dynamic ILT allocation mutex */
  1012. mutex_init(&p_mngr->mutex);
  1013. /* Set the cxt mangr pointer priori to further allocations */
  1014. p_hwfn->p_cxt_mngr = p_mngr;
  1015. return 0;
  1016. }
  1017. int qed_cxt_tables_alloc(struct qed_hwfn *p_hwfn)
  1018. {
  1019. int rc;
  1020. /* Allocate the ILT shadow table */
  1021. rc = qed_ilt_shadow_alloc(p_hwfn);
  1022. if (rc)
  1023. goto tables_alloc_fail;
  1024. /* Allocate the T2 table */
  1025. rc = qed_cxt_src_t2_alloc(p_hwfn);
  1026. if (rc)
  1027. goto tables_alloc_fail;
  1028. /* Allocate and initialize the acquired cids bitmaps */
  1029. rc = qed_cid_map_alloc(p_hwfn);
  1030. if (rc)
  1031. goto tables_alloc_fail;
  1032. return 0;
  1033. tables_alloc_fail:
  1034. qed_cxt_mngr_free(p_hwfn);
  1035. return rc;
  1036. }
  1037. void qed_cxt_mngr_free(struct qed_hwfn *p_hwfn)
  1038. {
  1039. if (!p_hwfn->p_cxt_mngr)
  1040. return;
  1041. qed_cid_map_free(p_hwfn);
  1042. qed_cxt_src_t2_free(p_hwfn);
  1043. qed_ilt_shadow_free(p_hwfn);
  1044. kfree(p_hwfn->p_cxt_mngr);
  1045. p_hwfn->p_cxt_mngr = NULL;
  1046. }
  1047. void qed_cxt_mngr_setup(struct qed_hwfn *p_hwfn)
  1048. {
  1049. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  1050. struct qed_cid_acquired_map *p_map;
  1051. struct qed_conn_type_cfg *p_cfg;
  1052. int type;
  1053. u32 len;
  1054. /* Reset acquired cids */
  1055. for (type = 0; type < MAX_CONN_TYPES; type++) {
  1056. u32 vf;
  1057. p_cfg = &p_mngr->conn_cfg[type];
  1058. if (p_cfg->cid_count) {
  1059. p_map = &p_mngr->acquired[type];
  1060. len = DIV_ROUND_UP(p_map->max_count,
  1061. sizeof(unsigned long) *
  1062. BITS_PER_BYTE) *
  1063. sizeof(unsigned long);
  1064. memset(p_map->cid_map, 0, len);
  1065. }
  1066. if (!p_cfg->cids_per_vf)
  1067. continue;
  1068. for (vf = 0; vf < MAX_NUM_VFS; vf++) {
  1069. p_map = &p_mngr->acquired_vf[type][vf];
  1070. len = DIV_ROUND_UP(p_map->max_count,
  1071. sizeof(unsigned long) *
  1072. BITS_PER_BYTE) *
  1073. sizeof(unsigned long);
  1074. memset(p_map->cid_map, 0, len);
  1075. }
  1076. }
  1077. }
  1078. /* CDU Common */
  1079. #define CDUC_CXT_SIZE_SHIFT \
  1080. CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE_SHIFT
  1081. #define CDUC_CXT_SIZE_MASK \
  1082. (CDU_REG_CID_ADDR_PARAMS_CONTEXT_SIZE >> CDUC_CXT_SIZE_SHIFT)
  1083. #define CDUC_BLOCK_WASTE_SHIFT \
  1084. CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE_SHIFT
  1085. #define CDUC_BLOCK_WASTE_MASK \
  1086. (CDU_REG_CID_ADDR_PARAMS_BLOCK_WASTE >> CDUC_BLOCK_WASTE_SHIFT)
  1087. #define CDUC_NCIB_SHIFT \
  1088. CDU_REG_CID_ADDR_PARAMS_NCIB_SHIFT
  1089. #define CDUC_NCIB_MASK \
  1090. (CDU_REG_CID_ADDR_PARAMS_NCIB >> CDUC_NCIB_SHIFT)
  1091. #define CDUT_TYPE0_CXT_SIZE_SHIFT \
  1092. CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE_SHIFT
  1093. #define CDUT_TYPE0_CXT_SIZE_MASK \
  1094. (CDU_REG_SEGMENT0_PARAMS_T0_TID_SIZE >> \
  1095. CDUT_TYPE0_CXT_SIZE_SHIFT)
  1096. #define CDUT_TYPE0_BLOCK_WASTE_SHIFT \
  1097. CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE_SHIFT
  1098. #define CDUT_TYPE0_BLOCK_WASTE_MASK \
  1099. (CDU_REG_SEGMENT0_PARAMS_T0_TID_BLOCK_WASTE >> \
  1100. CDUT_TYPE0_BLOCK_WASTE_SHIFT)
  1101. #define CDUT_TYPE0_NCIB_SHIFT \
  1102. CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK_SHIFT
  1103. #define CDUT_TYPE0_NCIB_MASK \
  1104. (CDU_REG_SEGMENT0_PARAMS_T0_NUM_TIDS_IN_BLOCK >> \
  1105. CDUT_TYPE0_NCIB_SHIFT)
  1106. #define CDUT_TYPE1_CXT_SIZE_SHIFT \
  1107. CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE_SHIFT
  1108. #define CDUT_TYPE1_CXT_SIZE_MASK \
  1109. (CDU_REG_SEGMENT1_PARAMS_T1_TID_SIZE >> \
  1110. CDUT_TYPE1_CXT_SIZE_SHIFT)
  1111. #define CDUT_TYPE1_BLOCK_WASTE_SHIFT \
  1112. CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE_SHIFT
  1113. #define CDUT_TYPE1_BLOCK_WASTE_MASK \
  1114. (CDU_REG_SEGMENT1_PARAMS_T1_TID_BLOCK_WASTE >> \
  1115. CDUT_TYPE1_BLOCK_WASTE_SHIFT)
  1116. #define CDUT_TYPE1_NCIB_SHIFT \
  1117. CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK_SHIFT
  1118. #define CDUT_TYPE1_NCIB_MASK \
  1119. (CDU_REG_SEGMENT1_PARAMS_T1_NUM_TIDS_IN_BLOCK >> \
  1120. CDUT_TYPE1_NCIB_SHIFT)
  1121. static void qed_cdu_init_common(struct qed_hwfn *p_hwfn)
  1122. {
  1123. u32 page_sz, elems_per_page, block_waste, cxt_size, cdu_params = 0;
  1124. /* CDUC - connection configuration */
  1125. page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val;
  1126. cxt_size = CONN_CXT_SIZE(p_hwfn);
  1127. elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
  1128. block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
  1129. SET_FIELD(cdu_params, CDUC_CXT_SIZE, cxt_size);
  1130. SET_FIELD(cdu_params, CDUC_BLOCK_WASTE, block_waste);
  1131. SET_FIELD(cdu_params, CDUC_NCIB, elems_per_page);
  1132. STORE_RT_REG(p_hwfn, CDU_REG_CID_ADDR_PARAMS_RT_OFFSET, cdu_params);
  1133. /* CDUT - type-0 tasks configuration */
  1134. page_sz = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT].p_size.val;
  1135. cxt_size = p_hwfn->p_cxt_mngr->task_type_size[0];
  1136. elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
  1137. block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
  1138. /* cxt size and block-waste are multipes of 8 */
  1139. cdu_params = 0;
  1140. SET_FIELD(cdu_params, CDUT_TYPE0_CXT_SIZE, (cxt_size >> 3));
  1141. SET_FIELD(cdu_params, CDUT_TYPE0_BLOCK_WASTE, (block_waste >> 3));
  1142. SET_FIELD(cdu_params, CDUT_TYPE0_NCIB, elems_per_page);
  1143. STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT0_PARAMS_RT_OFFSET, cdu_params);
  1144. /* CDUT - type-1 tasks configuration */
  1145. cxt_size = p_hwfn->p_cxt_mngr->task_type_size[1];
  1146. elems_per_page = ILT_PAGE_IN_BYTES(page_sz) / cxt_size;
  1147. block_waste = ILT_PAGE_IN_BYTES(page_sz) - elems_per_page * cxt_size;
  1148. /* cxt size and block-waste are multipes of 8 */
  1149. cdu_params = 0;
  1150. SET_FIELD(cdu_params, CDUT_TYPE1_CXT_SIZE, (cxt_size >> 3));
  1151. SET_FIELD(cdu_params, CDUT_TYPE1_BLOCK_WASTE, (block_waste >> 3));
  1152. SET_FIELD(cdu_params, CDUT_TYPE1_NCIB, elems_per_page);
  1153. STORE_RT_REG(p_hwfn, CDU_REG_SEGMENT1_PARAMS_RT_OFFSET, cdu_params);
  1154. }
  1155. /* CDU PF */
  1156. #define CDU_SEG_REG_TYPE_SHIFT CDU_SEG_TYPE_OFFSET_REG_TYPE_SHIFT
  1157. #define CDU_SEG_REG_TYPE_MASK 0x1
  1158. #define CDU_SEG_REG_OFFSET_SHIFT 0
  1159. #define CDU_SEG_REG_OFFSET_MASK CDU_SEG_TYPE_OFFSET_REG_OFFSET_MASK
  1160. static void qed_cdu_init_pf(struct qed_hwfn *p_hwfn)
  1161. {
  1162. struct qed_ilt_client_cfg *p_cli;
  1163. struct qed_tid_seg *p_seg;
  1164. u32 cdu_seg_params, offset;
  1165. int i;
  1166. static const u32 rt_type_offset_arr[] = {
  1167. CDU_REG_PF_SEG0_TYPE_OFFSET_RT_OFFSET,
  1168. CDU_REG_PF_SEG1_TYPE_OFFSET_RT_OFFSET,
  1169. CDU_REG_PF_SEG2_TYPE_OFFSET_RT_OFFSET,
  1170. CDU_REG_PF_SEG3_TYPE_OFFSET_RT_OFFSET
  1171. };
  1172. static const u32 rt_type_offset_fl_arr[] = {
  1173. CDU_REG_PF_FL_SEG0_TYPE_OFFSET_RT_OFFSET,
  1174. CDU_REG_PF_FL_SEG1_TYPE_OFFSET_RT_OFFSET,
  1175. CDU_REG_PF_FL_SEG2_TYPE_OFFSET_RT_OFFSET,
  1176. CDU_REG_PF_FL_SEG3_TYPE_OFFSET_RT_OFFSET
  1177. };
  1178. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
  1179. /* There are initializations only for CDUT during pf Phase */
  1180. for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
  1181. /* Segment 0 */
  1182. p_seg = qed_cxt_tid_seg_info(p_hwfn, i);
  1183. if (!p_seg)
  1184. continue;
  1185. /* Note: start_line is already adjusted for the CDU
  1186. * segment register granularity, so we just need to
  1187. * divide. Adjustment is implicit as we assume ILT
  1188. * Page size is larger than 32K!
  1189. */
  1190. offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) *
  1191. (p_cli->pf_blks[CDUT_SEG_BLK(i)].start_line -
  1192. p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES;
  1193. cdu_seg_params = 0;
  1194. SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type);
  1195. SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset);
  1196. STORE_RT_REG(p_hwfn, rt_type_offset_arr[i], cdu_seg_params);
  1197. offset = (ILT_PAGE_IN_BYTES(p_cli->p_size.val) *
  1198. (p_cli->pf_blks[CDUT_FL_SEG_BLK(i, PF)].start_line -
  1199. p_cli->first.val)) / CDUT_SEG_ALIGNMET_IN_BYTES;
  1200. cdu_seg_params = 0;
  1201. SET_FIELD(cdu_seg_params, CDU_SEG_REG_TYPE, p_seg->type);
  1202. SET_FIELD(cdu_seg_params, CDU_SEG_REG_OFFSET, offset);
  1203. STORE_RT_REG(p_hwfn, rt_type_offset_fl_arr[i], cdu_seg_params);
  1204. }
  1205. }
  1206. void qed_qm_init_pf(struct qed_hwfn *p_hwfn,
  1207. struct qed_ptt *p_ptt, bool is_pf_loading)
  1208. {
  1209. struct qed_qm_info *qm_info = &p_hwfn->qm_info;
  1210. struct qed_qm_pf_rt_init_params params;
  1211. struct qed_mcp_link_state *p_link;
  1212. struct qed_qm_iids iids;
  1213. memset(&iids, 0, sizeof(iids));
  1214. qed_cxt_qm_iids(p_hwfn, &iids);
  1215. p_link = &QED_LEADING_HWFN(p_hwfn->cdev)->mcp_info->link_output;
  1216. memset(&params, 0, sizeof(params));
  1217. params.port_id = p_hwfn->port_id;
  1218. params.pf_id = p_hwfn->rel_pf_id;
  1219. params.max_phys_tcs_per_port = qm_info->max_phys_tcs_per_port;
  1220. params.is_pf_loading = is_pf_loading;
  1221. params.num_pf_cids = iids.cids;
  1222. params.num_vf_cids = iids.vf_cids;
  1223. params.num_tids = iids.tids;
  1224. params.start_pq = qm_info->start_pq;
  1225. params.num_pf_pqs = qm_info->num_pqs - qm_info->num_vf_pqs;
  1226. params.num_vf_pqs = qm_info->num_vf_pqs;
  1227. params.start_vport = qm_info->start_vport;
  1228. params.num_vports = qm_info->num_vports;
  1229. params.pf_wfq = qm_info->pf_wfq;
  1230. params.pf_rl = qm_info->pf_rl;
  1231. params.link_speed = p_link->speed;
  1232. params.pq_params = qm_info->qm_pq_params;
  1233. params.vport_params = qm_info->qm_vport_params;
  1234. qed_qm_pf_rt_init(p_hwfn, p_ptt, &params);
  1235. }
  1236. /* CM PF */
  1237. void qed_cm_init_pf(struct qed_hwfn *p_hwfn)
  1238. {
  1239. /* XCM pure-LB queue */
  1240. STORE_RT_REG(p_hwfn, XCM_REG_CON_PHY_Q3_RT_OFFSET,
  1241. qed_get_cm_pq_idx(p_hwfn, PQ_FLAGS_LB));
  1242. }
  1243. /* DQ PF */
  1244. static void qed_dq_init_pf(struct qed_hwfn *p_hwfn)
  1245. {
  1246. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  1247. u32 dq_pf_max_cid = 0, dq_vf_max_cid = 0;
  1248. dq_pf_max_cid += (p_mngr->conn_cfg[0].cid_count >> DQ_RANGE_SHIFT);
  1249. STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_0_RT_OFFSET, dq_pf_max_cid);
  1250. dq_vf_max_cid += (p_mngr->conn_cfg[0].cids_per_vf >> DQ_RANGE_SHIFT);
  1251. STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_0_RT_OFFSET, dq_vf_max_cid);
  1252. dq_pf_max_cid += (p_mngr->conn_cfg[1].cid_count >> DQ_RANGE_SHIFT);
  1253. STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_1_RT_OFFSET, dq_pf_max_cid);
  1254. dq_vf_max_cid += (p_mngr->conn_cfg[1].cids_per_vf >> DQ_RANGE_SHIFT);
  1255. STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_1_RT_OFFSET, dq_vf_max_cid);
  1256. dq_pf_max_cid += (p_mngr->conn_cfg[2].cid_count >> DQ_RANGE_SHIFT);
  1257. STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_2_RT_OFFSET, dq_pf_max_cid);
  1258. dq_vf_max_cid += (p_mngr->conn_cfg[2].cids_per_vf >> DQ_RANGE_SHIFT);
  1259. STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_2_RT_OFFSET, dq_vf_max_cid);
  1260. dq_pf_max_cid += (p_mngr->conn_cfg[3].cid_count >> DQ_RANGE_SHIFT);
  1261. STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_3_RT_OFFSET, dq_pf_max_cid);
  1262. dq_vf_max_cid += (p_mngr->conn_cfg[3].cids_per_vf >> DQ_RANGE_SHIFT);
  1263. STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_3_RT_OFFSET, dq_vf_max_cid);
  1264. dq_pf_max_cid += (p_mngr->conn_cfg[4].cid_count >> DQ_RANGE_SHIFT);
  1265. STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_4_RT_OFFSET, dq_pf_max_cid);
  1266. dq_vf_max_cid += (p_mngr->conn_cfg[4].cids_per_vf >> DQ_RANGE_SHIFT);
  1267. STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_4_RT_OFFSET, dq_vf_max_cid);
  1268. dq_pf_max_cid += (p_mngr->conn_cfg[5].cid_count >> DQ_RANGE_SHIFT);
  1269. STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_5_RT_OFFSET, dq_pf_max_cid);
  1270. dq_vf_max_cid += (p_mngr->conn_cfg[5].cids_per_vf >> DQ_RANGE_SHIFT);
  1271. STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_5_RT_OFFSET, dq_vf_max_cid);
  1272. /* Connection types 6 & 7 are not in use, yet they must be configured
  1273. * as the highest possible connection. Not configuring them means the
  1274. * defaults will be used, and with a large number of cids a bug may
  1275. * occur, if the defaults will be smaller than dq_pf_max_cid /
  1276. * dq_vf_max_cid.
  1277. */
  1278. STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_6_RT_OFFSET, dq_pf_max_cid);
  1279. STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_6_RT_OFFSET, dq_vf_max_cid);
  1280. STORE_RT_REG(p_hwfn, DORQ_REG_PF_MAX_ICID_7_RT_OFFSET, dq_pf_max_cid);
  1281. STORE_RT_REG(p_hwfn, DORQ_REG_VF_MAX_ICID_7_RT_OFFSET, dq_vf_max_cid);
  1282. }
  1283. static void qed_ilt_bounds_init(struct qed_hwfn *p_hwfn)
  1284. {
  1285. struct qed_ilt_client_cfg *ilt_clients;
  1286. int i;
  1287. ilt_clients = p_hwfn->p_cxt_mngr->clients;
  1288. for_each_ilt_valid_client(i, ilt_clients) {
  1289. STORE_RT_REG(p_hwfn,
  1290. ilt_clients[i].first.reg,
  1291. ilt_clients[i].first.val);
  1292. STORE_RT_REG(p_hwfn,
  1293. ilt_clients[i].last.reg, ilt_clients[i].last.val);
  1294. STORE_RT_REG(p_hwfn,
  1295. ilt_clients[i].p_size.reg,
  1296. ilt_clients[i].p_size.val);
  1297. }
  1298. }
  1299. static void qed_ilt_vf_bounds_init(struct qed_hwfn *p_hwfn)
  1300. {
  1301. struct qed_ilt_client_cfg *p_cli;
  1302. u32 blk_factor;
  1303. /* For simplicty we set the 'block' to be an ILT page */
  1304. if (p_hwfn->cdev->p_iov_info) {
  1305. struct qed_hw_sriov_info *p_iov = p_hwfn->cdev->p_iov_info;
  1306. STORE_RT_REG(p_hwfn,
  1307. PSWRQ2_REG_VF_BASE_RT_OFFSET,
  1308. p_iov->first_vf_in_pf);
  1309. STORE_RT_REG(p_hwfn,
  1310. PSWRQ2_REG_VF_LAST_ILT_RT_OFFSET,
  1311. p_iov->first_vf_in_pf + p_iov->total_vfs);
  1312. }
  1313. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
  1314. blk_factor = ilog2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
  1315. if (p_cli->active) {
  1316. STORE_RT_REG(p_hwfn,
  1317. PSWRQ2_REG_CDUC_BLOCKS_FACTOR_RT_OFFSET,
  1318. blk_factor);
  1319. STORE_RT_REG(p_hwfn,
  1320. PSWRQ2_REG_CDUC_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
  1321. p_cli->pf_total_lines);
  1322. STORE_RT_REG(p_hwfn,
  1323. PSWRQ2_REG_CDUC_VF_BLOCKS_RT_OFFSET,
  1324. p_cli->vf_total_lines);
  1325. }
  1326. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
  1327. blk_factor = ilog2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
  1328. if (p_cli->active) {
  1329. STORE_RT_REG(p_hwfn,
  1330. PSWRQ2_REG_CDUT_BLOCKS_FACTOR_RT_OFFSET,
  1331. blk_factor);
  1332. STORE_RT_REG(p_hwfn,
  1333. PSWRQ2_REG_CDUT_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
  1334. p_cli->pf_total_lines);
  1335. STORE_RT_REG(p_hwfn,
  1336. PSWRQ2_REG_CDUT_VF_BLOCKS_RT_OFFSET,
  1337. p_cli->vf_total_lines);
  1338. }
  1339. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TM];
  1340. blk_factor = ilog2(ILT_PAGE_IN_BYTES(p_cli->p_size.val) >> 10);
  1341. if (p_cli->active) {
  1342. STORE_RT_REG(p_hwfn,
  1343. PSWRQ2_REG_TM_BLOCKS_FACTOR_RT_OFFSET, blk_factor);
  1344. STORE_RT_REG(p_hwfn,
  1345. PSWRQ2_REG_TM_NUMBER_OF_PF_BLOCKS_RT_OFFSET,
  1346. p_cli->pf_total_lines);
  1347. STORE_RT_REG(p_hwfn,
  1348. PSWRQ2_REG_TM_VF_BLOCKS_RT_OFFSET,
  1349. p_cli->vf_total_lines);
  1350. }
  1351. }
  1352. /* ILT (PSWRQ2) PF */
  1353. static void qed_ilt_init_pf(struct qed_hwfn *p_hwfn)
  1354. {
  1355. struct qed_ilt_client_cfg *clients;
  1356. struct qed_cxt_mngr *p_mngr;
  1357. struct qed_dma_mem *p_shdw;
  1358. u32 line, rt_offst, i;
  1359. qed_ilt_bounds_init(p_hwfn);
  1360. qed_ilt_vf_bounds_init(p_hwfn);
  1361. p_mngr = p_hwfn->p_cxt_mngr;
  1362. p_shdw = p_mngr->ilt_shadow;
  1363. clients = p_hwfn->p_cxt_mngr->clients;
  1364. for_each_ilt_valid_client(i, clients) {
  1365. /** Client's 1st val and RT array are absolute, ILT shadows'
  1366. * lines are relative.
  1367. */
  1368. line = clients[i].first.val - p_mngr->pf_start_line;
  1369. rt_offst = PSWRQ2_REG_ILT_MEMORY_RT_OFFSET +
  1370. clients[i].first.val * ILT_ENTRY_IN_REGS;
  1371. for (; line <= clients[i].last.val - p_mngr->pf_start_line;
  1372. line++, rt_offst += ILT_ENTRY_IN_REGS) {
  1373. u64 ilt_hw_entry = 0;
  1374. /** p_virt could be NULL incase of dynamic
  1375. * allocation
  1376. */
  1377. if (p_shdw[line].p_virt) {
  1378. SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL);
  1379. SET_FIELD(ilt_hw_entry, ILT_ENTRY_PHY_ADDR,
  1380. (p_shdw[line].p_phys >> 12));
  1381. DP_VERBOSE(p_hwfn, QED_MSG_ILT,
  1382. "Setting RT[0x%08x] from ILT[0x%08x] [Client is %d] to Physical addr: 0x%llx\n",
  1383. rt_offst, line, i,
  1384. (u64)(p_shdw[line].p_phys >> 12));
  1385. }
  1386. STORE_RT_REG_AGG(p_hwfn, rt_offst, ilt_hw_entry);
  1387. }
  1388. }
  1389. }
  1390. /* SRC (Searcher) PF */
  1391. static void qed_src_init_pf(struct qed_hwfn *p_hwfn)
  1392. {
  1393. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  1394. u32 rounded_conn_num, conn_num, conn_max;
  1395. struct qed_src_iids src_iids;
  1396. memset(&src_iids, 0, sizeof(src_iids));
  1397. qed_cxt_src_iids(p_mngr, &src_iids);
  1398. conn_num = src_iids.pf_cids + src_iids.per_vf_cids * p_mngr->vf_count;
  1399. if (!conn_num)
  1400. return;
  1401. conn_max = max_t(u32, conn_num, SRC_MIN_NUM_ELEMS);
  1402. rounded_conn_num = roundup_pow_of_two(conn_max);
  1403. STORE_RT_REG(p_hwfn, SRC_REG_COUNTFREE_RT_OFFSET, conn_num);
  1404. STORE_RT_REG(p_hwfn, SRC_REG_NUMBER_HASH_BITS_RT_OFFSET,
  1405. ilog2(rounded_conn_num));
  1406. STORE_RT_REG_AGG(p_hwfn, SRC_REG_FIRSTFREE_RT_OFFSET,
  1407. p_hwfn->p_cxt_mngr->first_free);
  1408. STORE_RT_REG_AGG(p_hwfn, SRC_REG_LASTFREE_RT_OFFSET,
  1409. p_hwfn->p_cxt_mngr->last_free);
  1410. }
  1411. /* Timers PF */
  1412. #define TM_CFG_NUM_IDS_SHIFT 0
  1413. #define TM_CFG_NUM_IDS_MASK 0xFFFFULL
  1414. #define TM_CFG_PRE_SCAN_OFFSET_SHIFT 16
  1415. #define TM_CFG_PRE_SCAN_OFFSET_MASK 0x1FFULL
  1416. #define TM_CFG_PARENT_PF_SHIFT 25
  1417. #define TM_CFG_PARENT_PF_MASK 0x7ULL
  1418. #define TM_CFG_CID_PRE_SCAN_ROWS_SHIFT 30
  1419. #define TM_CFG_CID_PRE_SCAN_ROWS_MASK 0x1FFULL
  1420. #define TM_CFG_TID_OFFSET_SHIFT 30
  1421. #define TM_CFG_TID_OFFSET_MASK 0x7FFFFULL
  1422. #define TM_CFG_TID_PRE_SCAN_ROWS_SHIFT 49
  1423. #define TM_CFG_TID_PRE_SCAN_ROWS_MASK 0x1FFULL
  1424. static void qed_tm_init_pf(struct qed_hwfn *p_hwfn)
  1425. {
  1426. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  1427. u32 active_seg_mask = 0, tm_offset, rt_reg;
  1428. struct qed_tm_iids tm_iids;
  1429. u64 cfg_word;
  1430. u8 i;
  1431. memset(&tm_iids, 0, sizeof(tm_iids));
  1432. qed_cxt_tm_iids(p_hwfn, p_mngr, &tm_iids);
  1433. /* @@@TBD No pre-scan for now */
  1434. /* Note: We assume consecutive VFs for a PF */
  1435. for (i = 0; i < p_mngr->vf_count; i++) {
  1436. cfg_word = 0;
  1437. SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_cids);
  1438. SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
  1439. SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id);
  1440. SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0);
  1441. rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET +
  1442. (sizeof(cfg_word) / sizeof(u32)) *
  1443. (p_hwfn->cdev->p_iov_info->first_vf_in_pf + i);
  1444. STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
  1445. }
  1446. cfg_word = 0;
  1447. SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_cids);
  1448. SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
  1449. SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0); /* n/a for PF */
  1450. SET_FIELD(cfg_word, TM_CFG_CID_PRE_SCAN_ROWS, 0); /* scan all */
  1451. rt_reg = TM_REG_CONFIG_CONN_MEM_RT_OFFSET +
  1452. (sizeof(cfg_word) / sizeof(u32)) *
  1453. (NUM_OF_VFS(p_hwfn->cdev) + p_hwfn->rel_pf_id);
  1454. STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
  1455. /* enale scan */
  1456. STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_CONN_RT_OFFSET,
  1457. tm_iids.pf_cids ? 0x1 : 0x0);
  1458. /* @@@TBD how to enable the scan for the VFs */
  1459. tm_offset = tm_iids.per_vf_cids;
  1460. /* Note: We assume consecutive VFs for a PF */
  1461. for (i = 0; i < p_mngr->vf_count; i++) {
  1462. cfg_word = 0;
  1463. SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.per_vf_tids);
  1464. SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
  1465. SET_FIELD(cfg_word, TM_CFG_PARENT_PF, p_hwfn->rel_pf_id);
  1466. SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset);
  1467. SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64) 0);
  1468. rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET +
  1469. (sizeof(cfg_word) / sizeof(u32)) *
  1470. (p_hwfn->cdev->p_iov_info->first_vf_in_pf + i);
  1471. STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
  1472. }
  1473. tm_offset = tm_iids.pf_cids;
  1474. for (i = 0; i < NUM_TASK_PF_SEGMENTS; i++) {
  1475. cfg_word = 0;
  1476. SET_FIELD(cfg_word, TM_CFG_NUM_IDS, tm_iids.pf_tids[i]);
  1477. SET_FIELD(cfg_word, TM_CFG_PRE_SCAN_OFFSET, 0);
  1478. SET_FIELD(cfg_word, TM_CFG_PARENT_PF, 0);
  1479. SET_FIELD(cfg_word, TM_CFG_TID_OFFSET, tm_offset);
  1480. SET_FIELD(cfg_word, TM_CFG_TID_PRE_SCAN_ROWS, (u64) 0);
  1481. rt_reg = TM_REG_CONFIG_TASK_MEM_RT_OFFSET +
  1482. (sizeof(cfg_word) / sizeof(u32)) *
  1483. (NUM_OF_VFS(p_hwfn->cdev) +
  1484. p_hwfn->rel_pf_id * NUM_TASK_PF_SEGMENTS + i);
  1485. STORE_RT_REG_AGG(p_hwfn, rt_reg, cfg_word);
  1486. active_seg_mask |= (tm_iids.pf_tids[i] ? BIT(i) : 0);
  1487. tm_offset += tm_iids.pf_tids[i];
  1488. }
  1489. if (QED_IS_RDMA_PERSONALITY(p_hwfn))
  1490. active_seg_mask = 0;
  1491. STORE_RT_REG(p_hwfn, TM_REG_PF_ENABLE_TASK_RT_OFFSET, active_seg_mask);
  1492. /* @@@TBD how to enable the scan for the VFs */
  1493. }
  1494. static void qed_prs_init_common(struct qed_hwfn *p_hwfn)
  1495. {
  1496. if ((p_hwfn->hw_info.personality == QED_PCI_FCOE) &&
  1497. p_hwfn->pf_params.fcoe_pf_params.is_target)
  1498. STORE_RT_REG(p_hwfn,
  1499. PRS_REG_SEARCH_RESP_INITIATOR_TYPE_RT_OFFSET, 0);
  1500. }
  1501. static void qed_prs_init_pf(struct qed_hwfn *p_hwfn)
  1502. {
  1503. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  1504. struct qed_conn_type_cfg *p_fcoe;
  1505. struct qed_tid_seg *p_tid;
  1506. p_fcoe = &p_mngr->conn_cfg[PROTOCOLID_FCOE];
  1507. /* If FCoE is active set the MAX OX_ID (tid) in the Parser */
  1508. if (!p_fcoe->cid_count)
  1509. return;
  1510. p_tid = &p_fcoe->tid_seg[QED_CXT_FCOE_TID_SEG];
  1511. if (p_hwfn->pf_params.fcoe_pf_params.is_target) {
  1512. STORE_RT_REG_AGG(p_hwfn,
  1513. PRS_REG_TASK_ID_MAX_TARGET_PF_RT_OFFSET,
  1514. p_tid->count);
  1515. } else {
  1516. STORE_RT_REG_AGG(p_hwfn,
  1517. PRS_REG_TASK_ID_MAX_INITIATOR_PF_RT_OFFSET,
  1518. p_tid->count);
  1519. }
  1520. }
  1521. void qed_cxt_hw_init_common(struct qed_hwfn *p_hwfn)
  1522. {
  1523. qed_cdu_init_common(p_hwfn);
  1524. qed_prs_init_common(p_hwfn);
  1525. }
  1526. void qed_cxt_hw_init_pf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1527. {
  1528. qed_qm_init_pf(p_hwfn, p_ptt, true);
  1529. qed_cm_init_pf(p_hwfn);
  1530. qed_dq_init_pf(p_hwfn);
  1531. qed_cdu_init_pf(p_hwfn);
  1532. qed_ilt_init_pf(p_hwfn);
  1533. qed_src_init_pf(p_hwfn);
  1534. qed_tm_init_pf(p_hwfn);
  1535. qed_prs_init_pf(p_hwfn);
  1536. }
  1537. int _qed_cxt_acquire_cid(struct qed_hwfn *p_hwfn,
  1538. enum protocol_type type, u32 *p_cid, u8 vfid)
  1539. {
  1540. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  1541. struct qed_cid_acquired_map *p_map;
  1542. u32 rel_cid;
  1543. if (type >= MAX_CONN_TYPES) {
  1544. DP_NOTICE(p_hwfn, "Invalid protocol type %d", type);
  1545. return -EINVAL;
  1546. }
  1547. if (vfid >= MAX_NUM_VFS && vfid != QED_CXT_PF_CID) {
  1548. DP_NOTICE(p_hwfn, "VF [%02x] is out of range\n", vfid);
  1549. return -EINVAL;
  1550. }
  1551. /* Determine the right map to take this CID from */
  1552. if (vfid == QED_CXT_PF_CID)
  1553. p_map = &p_mngr->acquired[type];
  1554. else
  1555. p_map = &p_mngr->acquired_vf[type][vfid];
  1556. if (!p_map->cid_map) {
  1557. DP_NOTICE(p_hwfn, "Invalid protocol type %d", type);
  1558. return -EINVAL;
  1559. }
  1560. rel_cid = find_first_zero_bit(p_map->cid_map, p_map->max_count);
  1561. if (rel_cid >= p_map->max_count) {
  1562. DP_NOTICE(p_hwfn, "no CID available for protocol %d\n", type);
  1563. return -EINVAL;
  1564. }
  1565. __set_bit(rel_cid, p_map->cid_map);
  1566. *p_cid = rel_cid + p_map->start_cid;
  1567. DP_VERBOSE(p_hwfn, QED_MSG_CXT,
  1568. "Acquired cid 0x%08x [rel. %08x] vfid %02x type %d\n",
  1569. *p_cid, rel_cid, vfid, type);
  1570. return 0;
  1571. }
  1572. int qed_cxt_acquire_cid(struct qed_hwfn *p_hwfn,
  1573. enum protocol_type type, u32 *p_cid)
  1574. {
  1575. return _qed_cxt_acquire_cid(p_hwfn, type, p_cid, QED_CXT_PF_CID);
  1576. }
  1577. static bool qed_cxt_test_cid_acquired(struct qed_hwfn *p_hwfn,
  1578. u32 cid,
  1579. u8 vfid,
  1580. enum protocol_type *p_type,
  1581. struct qed_cid_acquired_map **pp_map)
  1582. {
  1583. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  1584. u32 rel_cid;
  1585. /* Iterate over protocols and find matching cid range */
  1586. for (*p_type = 0; *p_type < MAX_CONN_TYPES; (*p_type)++) {
  1587. if (vfid == QED_CXT_PF_CID)
  1588. *pp_map = &p_mngr->acquired[*p_type];
  1589. else
  1590. *pp_map = &p_mngr->acquired_vf[*p_type][vfid];
  1591. if (!((*pp_map)->cid_map))
  1592. continue;
  1593. if (cid >= (*pp_map)->start_cid &&
  1594. cid < (*pp_map)->start_cid + (*pp_map)->max_count)
  1595. break;
  1596. }
  1597. if (*p_type == MAX_CONN_TYPES) {
  1598. DP_NOTICE(p_hwfn, "Invalid CID %d vfid %02x", cid, vfid);
  1599. goto fail;
  1600. }
  1601. rel_cid = cid - (*pp_map)->start_cid;
  1602. if (!test_bit(rel_cid, (*pp_map)->cid_map)) {
  1603. DP_NOTICE(p_hwfn, "CID %d [vifd %02x] not acquired",
  1604. cid, vfid);
  1605. goto fail;
  1606. }
  1607. return true;
  1608. fail:
  1609. *p_type = MAX_CONN_TYPES;
  1610. *pp_map = NULL;
  1611. return false;
  1612. }
  1613. void _qed_cxt_release_cid(struct qed_hwfn *p_hwfn, u32 cid, u8 vfid)
  1614. {
  1615. struct qed_cid_acquired_map *p_map = NULL;
  1616. enum protocol_type type;
  1617. bool b_acquired;
  1618. u32 rel_cid;
  1619. if (vfid != QED_CXT_PF_CID && vfid > MAX_NUM_VFS) {
  1620. DP_NOTICE(p_hwfn,
  1621. "Trying to return incorrect CID belonging to VF %02x\n",
  1622. vfid);
  1623. return;
  1624. }
  1625. /* Test acquired and find matching per-protocol map */
  1626. b_acquired = qed_cxt_test_cid_acquired(p_hwfn, cid, vfid,
  1627. &type, &p_map);
  1628. if (!b_acquired)
  1629. return;
  1630. rel_cid = cid - p_map->start_cid;
  1631. clear_bit(rel_cid, p_map->cid_map);
  1632. DP_VERBOSE(p_hwfn, QED_MSG_CXT,
  1633. "Released CID 0x%08x [rel. %08x] vfid %02x type %d\n",
  1634. cid, rel_cid, vfid, type);
  1635. }
  1636. void qed_cxt_release_cid(struct qed_hwfn *p_hwfn, u32 cid)
  1637. {
  1638. _qed_cxt_release_cid(p_hwfn, cid, QED_CXT_PF_CID);
  1639. }
  1640. int qed_cxt_get_cid_info(struct qed_hwfn *p_hwfn, struct qed_cxt_info *p_info)
  1641. {
  1642. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  1643. struct qed_cid_acquired_map *p_map = NULL;
  1644. u32 conn_cxt_size, hw_p_size, cxts_per_p, line;
  1645. enum protocol_type type;
  1646. bool b_acquired;
  1647. /* Test acquired and find matching per-protocol map */
  1648. b_acquired = qed_cxt_test_cid_acquired(p_hwfn, p_info->iid,
  1649. QED_CXT_PF_CID, &type, &p_map);
  1650. if (!b_acquired)
  1651. return -EINVAL;
  1652. /* set the protocl type */
  1653. p_info->type = type;
  1654. /* compute context virtual pointer */
  1655. hw_p_size = p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC].p_size.val;
  1656. conn_cxt_size = CONN_CXT_SIZE(p_hwfn);
  1657. cxts_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / conn_cxt_size;
  1658. line = p_info->iid / cxts_per_p;
  1659. /* Make sure context is allocated (dynamic allocation) */
  1660. if (!p_mngr->ilt_shadow[line].p_virt)
  1661. return -EINVAL;
  1662. p_info->p_cxt = p_mngr->ilt_shadow[line].p_virt +
  1663. p_info->iid % cxts_per_p * conn_cxt_size;
  1664. DP_VERBOSE(p_hwfn, (QED_MSG_ILT | QED_MSG_CXT),
  1665. "Accessing ILT shadow[%d]: CXT pointer is at %p (for iid %d)\n",
  1666. p_info->iid / cxts_per_p, p_info->p_cxt, p_info->iid);
  1667. return 0;
  1668. }
  1669. static void qed_rdma_set_pf_params(struct qed_hwfn *p_hwfn,
  1670. struct qed_rdma_pf_params *p_params,
  1671. u32 num_tasks)
  1672. {
  1673. u32 num_cons, num_qps, num_srqs;
  1674. enum protocol_type proto;
  1675. num_srqs = min_t(u32, QED_RDMA_MAX_SRQS, p_params->num_srqs);
  1676. if (p_hwfn->mcp_info->func_info.protocol == QED_PCI_ETH_RDMA) {
  1677. DP_NOTICE(p_hwfn,
  1678. "Current day drivers don't support RoCE & iWARP simultaneously on the same PF. Default to RoCE-only\n");
  1679. p_hwfn->hw_info.personality = QED_PCI_ETH_ROCE;
  1680. }
  1681. switch (p_hwfn->hw_info.personality) {
  1682. case QED_PCI_ETH_IWARP:
  1683. /* Each QP requires one connection */
  1684. num_cons = min_t(u32, IWARP_MAX_QPS, p_params->num_qps);
  1685. proto = PROTOCOLID_IWARP;
  1686. break;
  1687. case QED_PCI_ETH_ROCE:
  1688. num_qps = min_t(u32, ROCE_MAX_QPS, p_params->num_qps);
  1689. num_cons = num_qps * 2; /* each QP requires two connections */
  1690. proto = PROTOCOLID_ROCE;
  1691. break;
  1692. default:
  1693. return;
  1694. }
  1695. if (num_cons && num_tasks) {
  1696. qed_cxt_set_proto_cid_count(p_hwfn, proto, num_cons, 0);
  1697. /* Deliberatly passing ROCE for tasks id. This is because
  1698. * iWARP / RoCE share the task id.
  1699. */
  1700. qed_cxt_set_proto_tid_count(p_hwfn, PROTOCOLID_ROCE,
  1701. QED_CXT_ROCE_TID_SEG, 1,
  1702. num_tasks, false);
  1703. qed_cxt_set_srq_count(p_hwfn, num_srqs);
  1704. } else {
  1705. DP_INFO(p_hwfn->cdev,
  1706. "RDMA personality used without setting params!\n");
  1707. }
  1708. }
  1709. int qed_cxt_set_pf_params(struct qed_hwfn *p_hwfn, u32 rdma_tasks)
  1710. {
  1711. /* Set the number of required CORE connections */
  1712. u32 core_cids = 1; /* SPQ */
  1713. if (p_hwfn->using_ll2)
  1714. core_cids += 4;
  1715. qed_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_CORE, core_cids, 0);
  1716. switch (p_hwfn->hw_info.personality) {
  1717. case QED_PCI_ETH_RDMA:
  1718. case QED_PCI_ETH_IWARP:
  1719. case QED_PCI_ETH_ROCE:
  1720. {
  1721. qed_rdma_set_pf_params(p_hwfn,
  1722. &p_hwfn->
  1723. pf_params.rdma_pf_params,
  1724. rdma_tasks);
  1725. /* no need for break since RoCE coexist with Ethernet */
  1726. }
  1727. case QED_PCI_ETH:
  1728. {
  1729. struct qed_eth_pf_params *p_params =
  1730. &p_hwfn->pf_params.eth_pf_params;
  1731. if (!p_params->num_vf_cons)
  1732. p_params->num_vf_cons =
  1733. ETH_PF_PARAMS_VF_CONS_DEFAULT;
  1734. qed_cxt_set_proto_cid_count(p_hwfn, PROTOCOLID_ETH,
  1735. p_params->num_cons,
  1736. p_params->num_vf_cons);
  1737. p_hwfn->p_cxt_mngr->arfs_count = p_params->num_arfs_filters;
  1738. break;
  1739. }
  1740. case QED_PCI_FCOE:
  1741. {
  1742. struct qed_fcoe_pf_params *p_params;
  1743. p_params = &p_hwfn->pf_params.fcoe_pf_params;
  1744. if (p_params->num_cons && p_params->num_tasks) {
  1745. qed_cxt_set_proto_cid_count(p_hwfn,
  1746. PROTOCOLID_FCOE,
  1747. p_params->num_cons,
  1748. 0);
  1749. qed_cxt_set_proto_tid_count(p_hwfn, PROTOCOLID_FCOE,
  1750. QED_CXT_FCOE_TID_SEG, 0,
  1751. p_params->num_tasks, true);
  1752. } else {
  1753. DP_INFO(p_hwfn->cdev,
  1754. "Fcoe personality used without setting params!\n");
  1755. }
  1756. break;
  1757. }
  1758. case QED_PCI_ISCSI:
  1759. {
  1760. struct qed_iscsi_pf_params *p_params;
  1761. p_params = &p_hwfn->pf_params.iscsi_pf_params;
  1762. if (p_params->num_cons && p_params->num_tasks) {
  1763. qed_cxt_set_proto_cid_count(p_hwfn,
  1764. PROTOCOLID_ISCSI,
  1765. p_params->num_cons,
  1766. 0);
  1767. qed_cxt_set_proto_tid_count(p_hwfn,
  1768. PROTOCOLID_ISCSI,
  1769. QED_CXT_ISCSI_TID_SEG,
  1770. 0,
  1771. p_params->num_tasks,
  1772. true);
  1773. } else {
  1774. DP_INFO(p_hwfn->cdev,
  1775. "Iscsi personality used without setting params!\n");
  1776. }
  1777. break;
  1778. }
  1779. default:
  1780. return -EINVAL;
  1781. }
  1782. return 0;
  1783. }
  1784. int qed_cxt_get_tid_mem_info(struct qed_hwfn *p_hwfn,
  1785. struct qed_tid_mem *p_info)
  1786. {
  1787. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  1788. u32 proto, seg, total_lines, i, shadow_line;
  1789. struct qed_ilt_client_cfg *p_cli;
  1790. struct qed_ilt_cli_blk *p_fl_seg;
  1791. struct qed_tid_seg *p_seg_info;
  1792. /* Verify the personality */
  1793. switch (p_hwfn->hw_info.personality) {
  1794. case QED_PCI_FCOE:
  1795. proto = PROTOCOLID_FCOE;
  1796. seg = QED_CXT_FCOE_TID_SEG;
  1797. break;
  1798. case QED_PCI_ISCSI:
  1799. proto = PROTOCOLID_ISCSI;
  1800. seg = QED_CXT_ISCSI_TID_SEG;
  1801. break;
  1802. default:
  1803. return -EINVAL;
  1804. }
  1805. p_cli = &p_mngr->clients[ILT_CLI_CDUT];
  1806. if (!p_cli->active)
  1807. return -EINVAL;
  1808. p_seg_info = &p_mngr->conn_cfg[proto].tid_seg[seg];
  1809. if (!p_seg_info->has_fl_mem)
  1810. return -EINVAL;
  1811. p_fl_seg = &p_cli->pf_blks[CDUT_FL_SEG_BLK(seg, PF)];
  1812. total_lines = DIV_ROUND_UP(p_fl_seg->total_size,
  1813. p_fl_seg->real_size_in_page);
  1814. for (i = 0; i < total_lines; i++) {
  1815. shadow_line = i + p_fl_seg->start_line -
  1816. p_hwfn->p_cxt_mngr->pf_start_line;
  1817. p_info->blocks[i] = p_mngr->ilt_shadow[shadow_line].p_virt;
  1818. }
  1819. p_info->waste = ILT_PAGE_IN_BYTES(p_cli->p_size.val) -
  1820. p_fl_seg->real_size_in_page;
  1821. p_info->tid_size = p_mngr->task_type_size[p_seg_info->type];
  1822. p_info->num_tids_per_block = p_fl_seg->real_size_in_page /
  1823. p_info->tid_size;
  1824. return 0;
  1825. }
  1826. /* This function is very RoCE oriented, if another protocol in the future
  1827. * will want this feature we'll need to modify the function to be more generic
  1828. */
  1829. int
  1830. qed_cxt_dynamic_ilt_alloc(struct qed_hwfn *p_hwfn,
  1831. enum qed_cxt_elem_type elem_type, u32 iid)
  1832. {
  1833. u32 reg_offset, shadow_line, elem_size, hw_p_size, elems_per_p, line;
  1834. struct qed_ilt_client_cfg *p_cli;
  1835. struct qed_ilt_cli_blk *p_blk;
  1836. struct qed_ptt *p_ptt;
  1837. dma_addr_t p_phys;
  1838. u64 ilt_hw_entry;
  1839. void *p_virt;
  1840. int rc = 0;
  1841. switch (elem_type) {
  1842. case QED_ELEM_CXT:
  1843. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
  1844. elem_size = CONN_CXT_SIZE(p_hwfn);
  1845. p_blk = &p_cli->pf_blks[CDUC_BLK];
  1846. break;
  1847. case QED_ELEM_SRQ:
  1848. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM];
  1849. elem_size = SRQ_CXT_SIZE;
  1850. p_blk = &p_cli->pf_blks[SRQ_BLK];
  1851. break;
  1852. case QED_ELEM_TASK:
  1853. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
  1854. elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn);
  1855. p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(QED_CXT_ROCE_TID_SEG)];
  1856. break;
  1857. default:
  1858. DP_NOTICE(p_hwfn, "-EINVALID elem type = %d", elem_type);
  1859. return -EINVAL;
  1860. }
  1861. /* Calculate line in ilt */
  1862. hw_p_size = p_cli->p_size.val;
  1863. elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size;
  1864. line = p_blk->start_line + (iid / elems_per_p);
  1865. shadow_line = line - p_hwfn->p_cxt_mngr->pf_start_line;
  1866. /* If line is already allocated, do nothing, otherwise allocate it and
  1867. * write it to the PSWRQ2 registers.
  1868. * This section can be run in parallel from different contexts and thus
  1869. * a mutex protection is needed.
  1870. */
  1871. mutex_lock(&p_hwfn->p_cxt_mngr->mutex);
  1872. if (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_virt)
  1873. goto out0;
  1874. p_ptt = qed_ptt_acquire(p_hwfn);
  1875. if (!p_ptt) {
  1876. DP_NOTICE(p_hwfn,
  1877. "QED_TIME_OUT on ptt acquire - dynamic allocation");
  1878. rc = -EBUSY;
  1879. goto out0;
  1880. }
  1881. p_virt = dma_zalloc_coherent(&p_hwfn->cdev->pdev->dev,
  1882. p_blk->real_size_in_page, &p_phys,
  1883. GFP_KERNEL);
  1884. if (!p_virt) {
  1885. rc = -ENOMEM;
  1886. goto out1;
  1887. }
  1888. /* configuration of refTagMask to 0xF is required for RoCE DIF MR only,
  1889. * to compensate for a HW bug, but it is configured even if DIF is not
  1890. * enabled. This is harmless and allows us to avoid a dedicated API. We
  1891. * configure the field for all of the contexts on the newly allocated
  1892. * page.
  1893. */
  1894. if (elem_type == QED_ELEM_TASK) {
  1895. u32 elem_i;
  1896. u8 *elem_start = (u8 *)p_virt;
  1897. union type1_task_context *elem;
  1898. for (elem_i = 0; elem_i < elems_per_p; elem_i++) {
  1899. elem = (union type1_task_context *)elem_start;
  1900. SET_FIELD(elem->roce_ctx.tdif_context.flags1,
  1901. TDIF_TASK_CONTEXT_REF_TAG_MASK, 0xf);
  1902. elem_start += TYPE1_TASK_CXT_SIZE(p_hwfn);
  1903. }
  1904. }
  1905. p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_virt = p_virt;
  1906. p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_phys = p_phys;
  1907. p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].size =
  1908. p_blk->real_size_in_page;
  1909. /* compute absolute offset */
  1910. reg_offset = PSWRQ2_REG_ILT_MEMORY +
  1911. (line * ILT_REG_SIZE_IN_BYTES * ILT_ENTRY_IN_REGS);
  1912. ilt_hw_entry = 0;
  1913. SET_FIELD(ilt_hw_entry, ILT_ENTRY_VALID, 1ULL);
  1914. SET_FIELD(ilt_hw_entry,
  1915. ILT_ENTRY_PHY_ADDR,
  1916. (p_hwfn->p_cxt_mngr->ilt_shadow[shadow_line].p_phys >> 12));
  1917. /* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a wide-bus */
  1918. qed_dmae_host2grc(p_hwfn, p_ptt, (u64) (uintptr_t)&ilt_hw_entry,
  1919. reg_offset, sizeof(ilt_hw_entry) / sizeof(u32), 0);
  1920. if (elem_type == QED_ELEM_CXT) {
  1921. u32 last_cid_allocated = (1 + (iid / elems_per_p)) *
  1922. elems_per_p;
  1923. /* Update the relevant register in the parser */
  1924. qed_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF,
  1925. last_cid_allocated - 1);
  1926. if (!p_hwfn->b_rdma_enabled_in_prs) {
  1927. /* Enable RDMA search */
  1928. qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 1);
  1929. p_hwfn->b_rdma_enabled_in_prs = true;
  1930. }
  1931. }
  1932. out1:
  1933. qed_ptt_release(p_hwfn, p_ptt);
  1934. out0:
  1935. mutex_unlock(&p_hwfn->p_cxt_mngr->mutex);
  1936. return rc;
  1937. }
  1938. /* This function is very RoCE oriented, if another protocol in the future
  1939. * will want this feature we'll need to modify the function to be more generic
  1940. */
  1941. static int
  1942. qed_cxt_free_ilt_range(struct qed_hwfn *p_hwfn,
  1943. enum qed_cxt_elem_type elem_type,
  1944. u32 start_iid, u32 count)
  1945. {
  1946. u32 start_line, end_line, shadow_start_line, shadow_end_line;
  1947. u32 reg_offset, elem_size, hw_p_size, elems_per_p;
  1948. struct qed_ilt_client_cfg *p_cli;
  1949. struct qed_ilt_cli_blk *p_blk;
  1950. u32 end_iid = start_iid + count;
  1951. struct qed_ptt *p_ptt;
  1952. u64 ilt_hw_entry = 0;
  1953. u32 i;
  1954. switch (elem_type) {
  1955. case QED_ELEM_CXT:
  1956. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUC];
  1957. elem_size = CONN_CXT_SIZE(p_hwfn);
  1958. p_blk = &p_cli->pf_blks[CDUC_BLK];
  1959. break;
  1960. case QED_ELEM_SRQ:
  1961. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_TSDM];
  1962. elem_size = SRQ_CXT_SIZE;
  1963. p_blk = &p_cli->pf_blks[SRQ_BLK];
  1964. break;
  1965. case QED_ELEM_TASK:
  1966. p_cli = &p_hwfn->p_cxt_mngr->clients[ILT_CLI_CDUT];
  1967. elem_size = TYPE1_TASK_CXT_SIZE(p_hwfn);
  1968. p_blk = &p_cli->pf_blks[CDUT_SEG_BLK(QED_CXT_ROCE_TID_SEG)];
  1969. break;
  1970. default:
  1971. DP_NOTICE(p_hwfn, "-EINVALID elem type = %d", elem_type);
  1972. return -EINVAL;
  1973. }
  1974. /* Calculate line in ilt */
  1975. hw_p_size = p_cli->p_size.val;
  1976. elems_per_p = ILT_PAGE_IN_BYTES(hw_p_size) / elem_size;
  1977. start_line = p_blk->start_line + (start_iid / elems_per_p);
  1978. end_line = p_blk->start_line + (end_iid / elems_per_p);
  1979. if (((end_iid + 1) / elems_per_p) != (end_iid / elems_per_p))
  1980. end_line--;
  1981. shadow_start_line = start_line - p_hwfn->p_cxt_mngr->pf_start_line;
  1982. shadow_end_line = end_line - p_hwfn->p_cxt_mngr->pf_start_line;
  1983. p_ptt = qed_ptt_acquire(p_hwfn);
  1984. if (!p_ptt) {
  1985. DP_NOTICE(p_hwfn,
  1986. "QED_TIME_OUT on ptt acquire - dynamic allocation");
  1987. return -EBUSY;
  1988. }
  1989. for (i = shadow_start_line; i < shadow_end_line; i++) {
  1990. if (!p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt)
  1991. continue;
  1992. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  1993. p_hwfn->p_cxt_mngr->ilt_shadow[i].size,
  1994. p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt,
  1995. p_hwfn->p_cxt_mngr->ilt_shadow[i].p_phys);
  1996. p_hwfn->p_cxt_mngr->ilt_shadow[i].p_virt = NULL;
  1997. p_hwfn->p_cxt_mngr->ilt_shadow[i].p_phys = 0;
  1998. p_hwfn->p_cxt_mngr->ilt_shadow[i].size = 0;
  1999. /* compute absolute offset */
  2000. reg_offset = PSWRQ2_REG_ILT_MEMORY +
  2001. ((start_line++) * ILT_REG_SIZE_IN_BYTES *
  2002. ILT_ENTRY_IN_REGS);
  2003. /* Write via DMAE since the PSWRQ2_REG_ILT_MEMORY line is a
  2004. * wide-bus.
  2005. */
  2006. qed_dmae_host2grc(p_hwfn, p_ptt,
  2007. (u64) (uintptr_t) &ilt_hw_entry,
  2008. reg_offset,
  2009. sizeof(ilt_hw_entry) / sizeof(u32),
  2010. 0);
  2011. }
  2012. qed_ptt_release(p_hwfn, p_ptt);
  2013. return 0;
  2014. }
  2015. int qed_cxt_free_proto_ilt(struct qed_hwfn *p_hwfn, enum protocol_type proto)
  2016. {
  2017. int rc;
  2018. u32 cid;
  2019. /* Free Connection CXT */
  2020. rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_CXT,
  2021. qed_cxt_get_proto_cid_start(p_hwfn,
  2022. proto),
  2023. qed_cxt_get_proto_cid_count(p_hwfn,
  2024. proto, &cid));
  2025. if (rc)
  2026. return rc;
  2027. /* Free Task CXT ( Intentionally RoCE as task-id is shared between
  2028. * RoCE and iWARP )
  2029. */
  2030. proto = PROTOCOLID_ROCE;
  2031. rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_TASK, 0,
  2032. qed_cxt_get_proto_tid_count(p_hwfn, proto));
  2033. if (rc)
  2034. return rc;
  2035. /* Free TSDM CXT */
  2036. rc = qed_cxt_free_ilt_range(p_hwfn, QED_ELEM_SRQ, 0,
  2037. qed_cxt_get_srq_count(p_hwfn));
  2038. return rc;
  2039. }
  2040. int qed_cxt_get_task_ctx(struct qed_hwfn *p_hwfn,
  2041. u32 tid, u8 ctx_type, void **pp_task_ctx)
  2042. {
  2043. struct qed_cxt_mngr *p_mngr = p_hwfn->p_cxt_mngr;
  2044. struct qed_ilt_client_cfg *p_cli;
  2045. struct qed_tid_seg *p_seg_info;
  2046. struct qed_ilt_cli_blk *p_seg;
  2047. u32 num_tids_per_block;
  2048. u32 tid_size, ilt_idx;
  2049. u32 total_lines;
  2050. u32 proto, seg;
  2051. /* Verify the personality */
  2052. switch (p_hwfn->hw_info.personality) {
  2053. case QED_PCI_FCOE:
  2054. proto = PROTOCOLID_FCOE;
  2055. seg = QED_CXT_FCOE_TID_SEG;
  2056. break;
  2057. case QED_PCI_ISCSI:
  2058. proto = PROTOCOLID_ISCSI;
  2059. seg = QED_CXT_ISCSI_TID_SEG;
  2060. break;
  2061. default:
  2062. return -EINVAL;
  2063. }
  2064. p_cli = &p_mngr->clients[ILT_CLI_CDUT];
  2065. if (!p_cli->active)
  2066. return -EINVAL;
  2067. p_seg_info = &p_mngr->conn_cfg[proto].tid_seg[seg];
  2068. if (ctx_type == QED_CTX_WORKING_MEM) {
  2069. p_seg = &p_cli->pf_blks[CDUT_SEG_BLK(seg)];
  2070. } else if (ctx_type == QED_CTX_FL_MEM) {
  2071. if (!p_seg_info->has_fl_mem)
  2072. return -EINVAL;
  2073. p_seg = &p_cli->pf_blks[CDUT_FL_SEG_BLK(seg, PF)];
  2074. } else {
  2075. return -EINVAL;
  2076. }
  2077. total_lines = DIV_ROUND_UP(p_seg->total_size, p_seg->real_size_in_page);
  2078. tid_size = p_mngr->task_type_size[p_seg_info->type];
  2079. num_tids_per_block = p_seg->real_size_in_page / tid_size;
  2080. if (total_lines < tid / num_tids_per_block)
  2081. return -EINVAL;
  2082. ilt_idx = tid / num_tids_per_block + p_seg->start_line -
  2083. p_mngr->pf_start_line;
  2084. *pp_task_ctx = (u8 *)p_mngr->ilt_shadow[ilt_idx].p_virt +
  2085. (tid % num_tids_per_block) * tid_size;
  2086. return 0;
  2087. }