qed_cxt.c 62 KB

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