qed_cxt.c 70 KB

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