qed_rdma.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793
  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 <asm/byteorder.h>
  34. #include <linux/bitops.h>
  35. #include <linux/delay.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/errno.h>
  38. #include <linux/io.h>
  39. #include <linux/kernel.h>
  40. #include <linux/list.h>
  41. #include <linux/module.h>
  42. #include <linux/mutex.h>
  43. #include <linux/pci.h>
  44. #include <linux/slab.h>
  45. #include <linux/spinlock.h>
  46. #include <linux/string.h>
  47. #include "qed.h"
  48. #include "qed_cxt.h"
  49. #include "qed_hsi.h"
  50. #include "qed_hw.h"
  51. #include "qed_init_ops.h"
  52. #include "qed_int.h"
  53. #include "qed_ll2.h"
  54. #include "qed_mcp.h"
  55. #include "qed_reg_addr.h"
  56. #include <linux/qed/qed_rdma_if.h>
  57. #include "qed_rdma.h"
  58. #include "qed_roce.h"
  59. #include "qed_sp.h"
  60. int qed_rdma_bmap_alloc(struct qed_hwfn *p_hwfn,
  61. struct qed_bmap *bmap, u32 max_count, char *name)
  62. {
  63. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "max_count = %08x\n", max_count);
  64. bmap->max_count = max_count;
  65. bmap->bitmap = kcalloc(BITS_TO_LONGS(max_count), sizeof(long),
  66. GFP_KERNEL);
  67. if (!bmap->bitmap)
  68. return -ENOMEM;
  69. snprintf(bmap->name, QED_RDMA_MAX_BMAP_NAME, "%s", name);
  70. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "0\n");
  71. return 0;
  72. }
  73. int qed_rdma_bmap_alloc_id(struct qed_hwfn *p_hwfn,
  74. struct qed_bmap *bmap, u32 *id_num)
  75. {
  76. *id_num = find_first_zero_bit(bmap->bitmap, bmap->max_count);
  77. if (*id_num >= bmap->max_count)
  78. return -EINVAL;
  79. __set_bit(*id_num, bmap->bitmap);
  80. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "%s bitmap: allocated id %d\n",
  81. bmap->name, *id_num);
  82. return 0;
  83. }
  84. void qed_bmap_set_id(struct qed_hwfn *p_hwfn,
  85. struct qed_bmap *bmap, u32 id_num)
  86. {
  87. if (id_num >= bmap->max_count)
  88. return;
  89. __set_bit(id_num, bmap->bitmap);
  90. }
  91. void qed_bmap_release_id(struct qed_hwfn *p_hwfn,
  92. struct qed_bmap *bmap, u32 id_num)
  93. {
  94. bool b_acquired;
  95. if (id_num >= bmap->max_count)
  96. return;
  97. b_acquired = test_and_clear_bit(id_num, bmap->bitmap);
  98. if (!b_acquired) {
  99. DP_NOTICE(p_hwfn, "%s bitmap: id %d already released\n",
  100. bmap->name, id_num);
  101. return;
  102. }
  103. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "%s bitmap: released id %d\n",
  104. bmap->name, id_num);
  105. }
  106. int qed_bmap_test_id(struct qed_hwfn *p_hwfn,
  107. struct qed_bmap *bmap, u32 id_num)
  108. {
  109. if (id_num >= bmap->max_count)
  110. return -1;
  111. return test_bit(id_num, bmap->bitmap);
  112. }
  113. static bool qed_bmap_is_empty(struct qed_bmap *bmap)
  114. {
  115. return bmap->max_count == find_first_bit(bmap->bitmap, bmap->max_count);
  116. }
  117. u32 qed_rdma_get_sb_id(void *p_hwfn, u32 rel_sb_id)
  118. {
  119. /* First sb id for RoCE is after all the l2 sb */
  120. return FEAT_NUM((struct qed_hwfn *)p_hwfn, QED_PF_L2_QUE) + rel_sb_id;
  121. }
  122. static int qed_rdma_alloc(struct qed_hwfn *p_hwfn,
  123. struct qed_ptt *p_ptt,
  124. struct qed_rdma_start_in_params *params)
  125. {
  126. struct qed_rdma_info *p_rdma_info;
  127. u32 num_cons, num_tasks;
  128. int rc = -ENOMEM;
  129. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocating RDMA\n");
  130. /* Allocate a struct with current pf rdma info */
  131. p_rdma_info = kzalloc(sizeof(*p_rdma_info), GFP_KERNEL);
  132. if (!p_rdma_info)
  133. return rc;
  134. p_hwfn->p_rdma_info = p_rdma_info;
  135. if (QED_IS_IWARP_PERSONALITY(p_hwfn))
  136. p_rdma_info->proto = PROTOCOLID_IWARP;
  137. else
  138. p_rdma_info->proto = PROTOCOLID_ROCE;
  139. num_cons = qed_cxt_get_proto_cid_count(p_hwfn, p_rdma_info->proto,
  140. NULL);
  141. if (QED_IS_IWARP_PERSONALITY(p_hwfn))
  142. p_rdma_info->num_qps = num_cons;
  143. else
  144. p_rdma_info->num_qps = num_cons / 2; /* 2 cids per qp */
  145. num_tasks = qed_cxt_get_proto_tid_count(p_hwfn, PROTOCOLID_ROCE);
  146. /* Each MR uses a single task */
  147. p_rdma_info->num_mrs = num_tasks;
  148. /* Queue zone lines are shared between RoCE and L2 in such a way that
  149. * they can be used by each without obstructing the other.
  150. */
  151. p_rdma_info->queue_zone_base = (u16)RESC_START(p_hwfn, QED_L2_QUEUE);
  152. p_rdma_info->max_queue_zones = (u16)RESC_NUM(p_hwfn, QED_L2_QUEUE);
  153. /* Allocate a struct with device params and fill it */
  154. p_rdma_info->dev = kzalloc(sizeof(*p_rdma_info->dev), GFP_KERNEL);
  155. if (!p_rdma_info->dev)
  156. goto free_rdma_info;
  157. /* Allocate a struct with port params and fill it */
  158. p_rdma_info->port = kzalloc(sizeof(*p_rdma_info->port), GFP_KERNEL);
  159. if (!p_rdma_info->port)
  160. goto free_rdma_dev;
  161. /* Allocate bit map for pd's */
  162. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->pd_map, RDMA_MAX_PDS,
  163. "PD");
  164. if (rc) {
  165. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  166. "Failed to allocate pd_map, rc = %d\n",
  167. rc);
  168. goto free_rdma_port;
  169. }
  170. /* Allocate DPI bitmap */
  171. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->dpi_map,
  172. p_hwfn->dpi_count, "DPI");
  173. if (rc) {
  174. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  175. "Failed to allocate DPI bitmap, rc = %d\n", rc);
  176. goto free_pd_map;
  177. }
  178. /* Allocate bitmap for cq's. The maximum number of CQs is bound to
  179. * the number of connections we support. (num_qps in iWARP or
  180. * num_qps/2 in RoCE).
  181. */
  182. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->cq_map, num_cons, "CQ");
  183. if (rc) {
  184. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  185. "Failed to allocate cq bitmap, rc = %d\n", rc);
  186. goto free_dpi_map;
  187. }
  188. /* Allocate bitmap for toggle bit for cq icids
  189. * We toggle the bit every time we create or resize cq for a given icid.
  190. * Size needs to equal the size of the cq bmap.
  191. */
  192. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->toggle_bits,
  193. num_cons, "Toggle");
  194. if (rc) {
  195. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  196. "Failed to allocate toogle bits, rc = %d\n", rc);
  197. goto free_cq_map;
  198. }
  199. /* Allocate bitmap for itids */
  200. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->tid_map,
  201. p_rdma_info->num_mrs, "MR");
  202. if (rc) {
  203. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  204. "Failed to allocate itids bitmaps, rc = %d\n", rc);
  205. goto free_toggle_map;
  206. }
  207. /* Allocate bitmap for cids used for qps. */
  208. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->cid_map, num_cons,
  209. "CID");
  210. if (rc) {
  211. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  212. "Failed to allocate cid bitmap, rc = %d\n", rc);
  213. goto free_tid_map;
  214. }
  215. /* Allocate bitmap for cids used for responders/requesters. */
  216. rc = qed_rdma_bmap_alloc(p_hwfn, &p_rdma_info->real_cid_map, num_cons,
  217. "REAL_CID");
  218. if (rc) {
  219. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  220. "Failed to allocate real cid bitmap, rc = %d\n", rc);
  221. goto free_cid_map;
  222. }
  223. if (QED_IS_IWARP_PERSONALITY(p_hwfn))
  224. rc = qed_iwarp_alloc(p_hwfn);
  225. if (rc)
  226. goto free_cid_map;
  227. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocation successful\n");
  228. return 0;
  229. free_cid_map:
  230. kfree(p_rdma_info->cid_map.bitmap);
  231. free_tid_map:
  232. kfree(p_rdma_info->tid_map.bitmap);
  233. free_toggle_map:
  234. kfree(p_rdma_info->toggle_bits.bitmap);
  235. free_cq_map:
  236. kfree(p_rdma_info->cq_map.bitmap);
  237. free_dpi_map:
  238. kfree(p_rdma_info->dpi_map.bitmap);
  239. free_pd_map:
  240. kfree(p_rdma_info->pd_map.bitmap);
  241. free_rdma_port:
  242. kfree(p_rdma_info->port);
  243. free_rdma_dev:
  244. kfree(p_rdma_info->dev);
  245. free_rdma_info:
  246. kfree(p_rdma_info);
  247. return rc;
  248. }
  249. void qed_rdma_bmap_free(struct qed_hwfn *p_hwfn,
  250. struct qed_bmap *bmap, bool check)
  251. {
  252. int weight = bitmap_weight(bmap->bitmap, bmap->max_count);
  253. int last_line = bmap->max_count / (64 * 8);
  254. int last_item = last_line * 8 +
  255. DIV_ROUND_UP(bmap->max_count % (64 * 8), 64);
  256. u64 *pmap = (u64 *)bmap->bitmap;
  257. int line, item, offset;
  258. u8 str_last_line[200] = { 0 };
  259. if (!weight || !check)
  260. goto end;
  261. DP_NOTICE(p_hwfn,
  262. "%s bitmap not free - size=%d, weight=%d, 512 bits per line\n",
  263. bmap->name, bmap->max_count, weight);
  264. /* print aligned non-zero lines, if any */
  265. for (item = 0, line = 0; line < last_line; line++, item += 8)
  266. if (bitmap_weight((unsigned long *)&pmap[item], 64 * 8))
  267. DP_NOTICE(p_hwfn,
  268. "line 0x%04x: 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx 0x%016llx\n",
  269. line,
  270. pmap[item],
  271. pmap[item + 1],
  272. pmap[item + 2],
  273. pmap[item + 3],
  274. pmap[item + 4],
  275. pmap[item + 5],
  276. pmap[item + 6], pmap[item + 7]);
  277. /* print last unaligned non-zero line, if any */
  278. if ((bmap->max_count % (64 * 8)) &&
  279. (bitmap_weight((unsigned long *)&pmap[item],
  280. bmap->max_count - item * 64))) {
  281. offset = sprintf(str_last_line, "line 0x%04x: ", line);
  282. for (; item < last_item; item++)
  283. offset += sprintf(str_last_line + offset,
  284. "0x%016llx ", pmap[item]);
  285. DP_NOTICE(p_hwfn, "%s\n", str_last_line);
  286. }
  287. end:
  288. kfree(bmap->bitmap);
  289. bmap->bitmap = NULL;
  290. }
  291. static void qed_rdma_resc_free(struct qed_hwfn *p_hwfn)
  292. {
  293. struct qed_rdma_info *p_rdma_info = p_hwfn->p_rdma_info;
  294. if (QED_IS_IWARP_PERSONALITY(p_hwfn))
  295. qed_iwarp_resc_free(p_hwfn);
  296. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->cid_map, 1);
  297. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->pd_map, 1);
  298. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->dpi_map, 1);
  299. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->cq_map, 1);
  300. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->toggle_bits, 0);
  301. qed_rdma_bmap_free(p_hwfn, &p_hwfn->p_rdma_info->tid_map, 1);
  302. kfree(p_rdma_info->port);
  303. kfree(p_rdma_info->dev);
  304. kfree(p_rdma_info);
  305. }
  306. static void qed_rdma_free(struct qed_hwfn *p_hwfn)
  307. {
  308. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Freeing RDMA\n");
  309. qed_rdma_resc_free(p_hwfn);
  310. }
  311. static void qed_rdma_get_guid(struct qed_hwfn *p_hwfn, u8 *guid)
  312. {
  313. guid[0] = p_hwfn->hw_info.hw_mac_addr[0] ^ 2;
  314. guid[1] = p_hwfn->hw_info.hw_mac_addr[1];
  315. guid[2] = p_hwfn->hw_info.hw_mac_addr[2];
  316. guid[3] = 0xff;
  317. guid[4] = 0xfe;
  318. guid[5] = p_hwfn->hw_info.hw_mac_addr[3];
  319. guid[6] = p_hwfn->hw_info.hw_mac_addr[4];
  320. guid[7] = p_hwfn->hw_info.hw_mac_addr[5];
  321. }
  322. static void qed_rdma_init_events(struct qed_hwfn *p_hwfn,
  323. struct qed_rdma_start_in_params *params)
  324. {
  325. struct qed_rdma_events *events;
  326. events = &p_hwfn->p_rdma_info->events;
  327. events->unaffiliated_event = params->events->unaffiliated_event;
  328. events->affiliated_event = params->events->affiliated_event;
  329. events->context = params->events->context;
  330. }
  331. static void qed_rdma_init_devinfo(struct qed_hwfn *p_hwfn,
  332. struct qed_rdma_start_in_params *params)
  333. {
  334. struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
  335. struct qed_dev *cdev = p_hwfn->cdev;
  336. u32 pci_status_control;
  337. u32 num_qps;
  338. /* Vendor specific information */
  339. dev->vendor_id = cdev->vendor_id;
  340. dev->vendor_part_id = cdev->device_id;
  341. dev->hw_ver = 0;
  342. dev->fw_ver = (FW_MAJOR_VERSION << 24) | (FW_MINOR_VERSION << 16) |
  343. (FW_REVISION_VERSION << 8) | (FW_ENGINEERING_VERSION);
  344. qed_rdma_get_guid(p_hwfn, (u8 *)&dev->sys_image_guid);
  345. dev->node_guid = dev->sys_image_guid;
  346. dev->max_sge = min_t(u32, RDMA_MAX_SGE_PER_SQ_WQE,
  347. RDMA_MAX_SGE_PER_RQ_WQE);
  348. if (cdev->rdma_max_sge)
  349. dev->max_sge = min_t(u32, cdev->rdma_max_sge, dev->max_sge);
  350. dev->max_inline = ROCE_REQ_MAX_INLINE_DATA_SIZE;
  351. dev->max_inline = (cdev->rdma_max_inline) ?
  352. min_t(u32, cdev->rdma_max_inline, dev->max_inline) :
  353. dev->max_inline;
  354. dev->max_wqe = QED_RDMA_MAX_WQE;
  355. dev->max_cnq = (u8)FEAT_NUM(p_hwfn, QED_RDMA_CNQ);
  356. /* The number of QPs may be higher than QED_ROCE_MAX_QPS, because
  357. * it is up-aligned to 16 and then to ILT page size within qed cxt.
  358. * This is OK in terms of ILT but we don't want to configure the FW
  359. * above its abilities
  360. */
  361. num_qps = ROCE_MAX_QPS;
  362. num_qps = min_t(u64, num_qps, p_hwfn->p_rdma_info->num_qps);
  363. dev->max_qp = num_qps;
  364. /* CQs uses the same icids that QPs use hence they are limited by the
  365. * number of icids. There are two icids per QP.
  366. */
  367. dev->max_cq = num_qps * 2;
  368. /* The number of mrs is smaller by 1 since the first is reserved */
  369. dev->max_mr = p_hwfn->p_rdma_info->num_mrs - 1;
  370. dev->max_mr_size = QED_RDMA_MAX_MR_SIZE;
  371. /* The maximum CQE capacity per CQ supported.
  372. * max number of cqes will be in two layer pbl,
  373. * 8 is the pointer size in bytes
  374. * 32 is the size of cq element in bytes
  375. */
  376. if (params->cq_mode == QED_RDMA_CQ_MODE_32_BITS)
  377. dev->max_cqe = QED_RDMA_MAX_CQE_32_BIT;
  378. else
  379. dev->max_cqe = QED_RDMA_MAX_CQE_16_BIT;
  380. dev->max_mw = 0;
  381. dev->max_fmr = QED_RDMA_MAX_FMR;
  382. dev->max_mr_mw_fmr_pbl = (PAGE_SIZE / 8) * (PAGE_SIZE / 8);
  383. dev->max_mr_mw_fmr_size = dev->max_mr_mw_fmr_pbl * PAGE_SIZE;
  384. dev->max_pkey = QED_RDMA_MAX_P_KEY;
  385. dev->max_qp_resp_rd_atomic_resc = RDMA_RING_PAGE_SIZE /
  386. (RDMA_RESP_RD_ATOMIC_ELM_SIZE * 2);
  387. dev->max_qp_req_rd_atomic_resc = RDMA_RING_PAGE_SIZE /
  388. RDMA_REQ_RD_ATOMIC_ELM_SIZE;
  389. dev->max_dev_resp_rd_atomic_resc = dev->max_qp_resp_rd_atomic_resc *
  390. p_hwfn->p_rdma_info->num_qps;
  391. dev->page_size_caps = QED_RDMA_PAGE_SIZE_CAPS;
  392. dev->dev_ack_delay = QED_RDMA_ACK_DELAY;
  393. dev->max_pd = RDMA_MAX_PDS;
  394. dev->max_ah = p_hwfn->p_rdma_info->num_qps;
  395. dev->max_stats_queues = (u8)RESC_NUM(p_hwfn, QED_RDMA_STATS_QUEUE);
  396. /* Set capablities */
  397. dev->dev_caps = 0;
  398. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_RNR_NAK, 1);
  399. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_PORT_ACTIVE_EVENT, 1);
  400. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_PORT_CHANGE_EVENT, 1);
  401. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_RESIZE_CQ, 1);
  402. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_BASE_MEMORY_EXT, 1);
  403. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_BASE_QUEUE_EXT, 1);
  404. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_ZBVA, 1);
  405. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_LOCAL_INV_FENCE, 1);
  406. /* Check atomic operations support in PCI configuration space. */
  407. pci_read_config_dword(cdev->pdev,
  408. cdev->pdev->pcie_cap + PCI_EXP_DEVCTL2,
  409. &pci_status_control);
  410. if (pci_status_control & PCI_EXP_DEVCTL2_LTR_EN)
  411. SET_FIELD(dev->dev_caps, QED_RDMA_DEV_CAP_ATOMIC_OP, 1);
  412. if (QED_IS_IWARP_PERSONALITY(p_hwfn))
  413. qed_iwarp_init_devinfo(p_hwfn);
  414. }
  415. static void qed_rdma_init_port(struct qed_hwfn *p_hwfn)
  416. {
  417. struct qed_rdma_port *port = p_hwfn->p_rdma_info->port;
  418. struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
  419. port->port_state = p_hwfn->mcp_info->link_output.link_up ?
  420. QED_RDMA_PORT_UP : QED_RDMA_PORT_DOWN;
  421. port->max_msg_size = min_t(u64,
  422. (dev->max_mr_mw_fmr_size *
  423. p_hwfn->cdev->rdma_max_sge),
  424. BIT(31));
  425. port->pkey_bad_counter = 0;
  426. }
  427. static int qed_rdma_init_hw(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  428. {
  429. int rc = 0;
  430. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Initializing HW\n");
  431. p_hwfn->b_rdma_enabled_in_prs = false;
  432. if (QED_IS_IWARP_PERSONALITY(p_hwfn))
  433. qed_iwarp_init_hw(p_hwfn, p_ptt);
  434. else
  435. rc = qed_roce_init_hw(p_hwfn, p_ptt);
  436. return rc;
  437. }
  438. static int qed_rdma_start_fw(struct qed_hwfn *p_hwfn,
  439. struct qed_rdma_start_in_params *params,
  440. struct qed_ptt *p_ptt)
  441. {
  442. struct rdma_init_func_ramrod_data *p_ramrod;
  443. struct qed_rdma_cnq_params *p_cnq_pbl_list;
  444. struct rdma_init_func_hdr *p_params_header;
  445. struct rdma_cnq_params *p_cnq_params;
  446. struct qed_sp_init_data init_data;
  447. struct qed_spq_entry *p_ent;
  448. u32 cnq_id, sb_id;
  449. u16 igu_sb_id;
  450. int rc;
  451. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Starting FW\n");
  452. /* Save the number of cnqs for the function close ramrod */
  453. p_hwfn->p_rdma_info->num_cnqs = params->desired_cnq;
  454. /* Get SPQ entry */
  455. memset(&init_data, 0, sizeof(init_data));
  456. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  457. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  458. rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_FUNC_INIT,
  459. p_hwfn->p_rdma_info->proto, &init_data);
  460. if (rc)
  461. return rc;
  462. if (QED_IS_IWARP_PERSONALITY(p_hwfn)) {
  463. qed_iwarp_init_fw_ramrod(p_hwfn,
  464. &p_ent->ramrod.iwarp_init_func.iwarp);
  465. p_ramrod = &p_ent->ramrod.iwarp_init_func.rdma;
  466. } else {
  467. p_ramrod = &p_ent->ramrod.roce_init_func.rdma;
  468. }
  469. p_params_header = &p_ramrod->params_header;
  470. p_params_header->cnq_start_offset = (u8)RESC_START(p_hwfn,
  471. QED_RDMA_CNQ_RAM);
  472. p_params_header->num_cnqs = params->desired_cnq;
  473. if (params->cq_mode == QED_RDMA_CQ_MODE_16_BITS)
  474. p_params_header->cq_ring_mode = 1;
  475. else
  476. p_params_header->cq_ring_mode = 0;
  477. for (cnq_id = 0; cnq_id < params->desired_cnq; cnq_id++) {
  478. sb_id = qed_rdma_get_sb_id(p_hwfn, cnq_id);
  479. igu_sb_id = qed_get_igu_sb_id(p_hwfn, sb_id);
  480. p_ramrod->cnq_params[cnq_id].sb_num = cpu_to_le16(igu_sb_id);
  481. p_cnq_params = &p_ramrod->cnq_params[cnq_id];
  482. p_cnq_pbl_list = &params->cnq_pbl_list[cnq_id];
  483. p_cnq_params->sb_index = p_hwfn->pf_params.rdma_pf_params.gl_pi;
  484. p_cnq_params->num_pbl_pages = p_cnq_pbl_list->num_pbl_pages;
  485. DMA_REGPAIR_LE(p_cnq_params->pbl_base_addr,
  486. p_cnq_pbl_list->pbl_ptr);
  487. /* we assume here that cnq_id and qz_offset are the same */
  488. p_cnq_params->queue_zone_num =
  489. cpu_to_le16(p_hwfn->p_rdma_info->queue_zone_base +
  490. cnq_id);
  491. }
  492. return qed_spq_post(p_hwfn, p_ent, NULL);
  493. }
  494. static int qed_rdma_alloc_tid(void *rdma_cxt, u32 *itid)
  495. {
  496. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  497. int rc;
  498. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID\n");
  499. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  500. rc = qed_rdma_bmap_alloc_id(p_hwfn,
  501. &p_hwfn->p_rdma_info->tid_map, itid);
  502. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  503. if (rc)
  504. goto out;
  505. rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_TASK, *itid);
  506. out:
  507. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Allocate TID - done, rc = %d\n", rc);
  508. return rc;
  509. }
  510. static int qed_rdma_reserve_lkey(struct qed_hwfn *p_hwfn)
  511. {
  512. struct qed_rdma_device *dev = p_hwfn->p_rdma_info->dev;
  513. /* The first DPI is reserved for the Kernel */
  514. __set_bit(0, p_hwfn->p_rdma_info->dpi_map.bitmap);
  515. /* Tid 0 will be used as the key for "reserved MR".
  516. * The driver should allocate memory for it so it can be loaded but no
  517. * ramrod should be passed on it.
  518. */
  519. qed_rdma_alloc_tid(p_hwfn, &dev->reserved_lkey);
  520. if (dev->reserved_lkey != RDMA_RESERVED_LKEY) {
  521. DP_NOTICE(p_hwfn,
  522. "Reserved lkey should be equal to RDMA_RESERVED_LKEY\n");
  523. return -EINVAL;
  524. }
  525. return 0;
  526. }
  527. static int qed_rdma_setup(struct qed_hwfn *p_hwfn,
  528. struct qed_ptt *p_ptt,
  529. struct qed_rdma_start_in_params *params)
  530. {
  531. int rc;
  532. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA setup\n");
  533. spin_lock_init(&p_hwfn->p_rdma_info->lock);
  534. qed_rdma_init_devinfo(p_hwfn, params);
  535. qed_rdma_init_port(p_hwfn);
  536. qed_rdma_init_events(p_hwfn, params);
  537. rc = qed_rdma_reserve_lkey(p_hwfn);
  538. if (rc)
  539. return rc;
  540. rc = qed_rdma_init_hw(p_hwfn, p_ptt);
  541. if (rc)
  542. return rc;
  543. if (QED_IS_IWARP_PERSONALITY(p_hwfn)) {
  544. rc = qed_iwarp_setup(p_hwfn, p_ptt, params);
  545. if (rc)
  546. return rc;
  547. } else {
  548. rc = qed_roce_setup(p_hwfn);
  549. if (rc)
  550. return rc;
  551. }
  552. return qed_rdma_start_fw(p_hwfn, params, p_ptt);
  553. }
  554. int qed_rdma_stop(void *rdma_cxt)
  555. {
  556. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  557. struct rdma_close_func_ramrod_data *p_ramrod;
  558. struct qed_sp_init_data init_data;
  559. struct qed_spq_entry *p_ent;
  560. struct qed_ptt *p_ptt;
  561. u32 ll2_ethertype_en;
  562. int rc = -EBUSY;
  563. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA stop\n");
  564. p_ptt = qed_ptt_acquire(p_hwfn);
  565. if (!p_ptt) {
  566. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Failed to acquire PTT\n");
  567. return rc;
  568. }
  569. /* Disable RoCE search */
  570. qed_wr(p_hwfn, p_ptt, p_hwfn->rdma_prs_search_reg, 0);
  571. p_hwfn->b_rdma_enabled_in_prs = false;
  572. qed_wr(p_hwfn, p_ptt, PRS_REG_ROCE_DEST_QP_MAX_PF, 0);
  573. ll2_ethertype_en = qed_rd(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN);
  574. qed_wr(p_hwfn, p_ptt, PRS_REG_LIGHT_L2_ETHERTYPE_EN,
  575. (ll2_ethertype_en & 0xFFFE));
  576. if (QED_IS_IWARP_PERSONALITY(p_hwfn)) {
  577. rc = qed_iwarp_stop(p_hwfn, p_ptt);
  578. if (rc) {
  579. qed_ptt_release(p_hwfn, p_ptt);
  580. return rc;
  581. }
  582. } else {
  583. qed_roce_stop(p_hwfn);
  584. }
  585. qed_ptt_release(p_hwfn, p_ptt);
  586. /* Get SPQ entry */
  587. memset(&init_data, 0, sizeof(init_data));
  588. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  589. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  590. /* Stop RoCE */
  591. rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_FUNC_CLOSE,
  592. p_hwfn->p_rdma_info->proto, &init_data);
  593. if (rc)
  594. goto out;
  595. p_ramrod = &p_ent->ramrod.rdma_close_func;
  596. p_ramrod->num_cnqs = p_hwfn->p_rdma_info->num_cnqs;
  597. p_ramrod->cnq_start_offset = (u8)RESC_START(p_hwfn, QED_RDMA_CNQ_RAM);
  598. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  599. out:
  600. qed_rdma_free(p_hwfn);
  601. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA stop done, rc = %d\n", rc);
  602. return rc;
  603. }
  604. static int qed_rdma_add_user(void *rdma_cxt,
  605. struct qed_rdma_add_user_out_params *out_params)
  606. {
  607. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  608. u32 dpi_start_offset;
  609. u32 returned_id = 0;
  610. int rc;
  611. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Adding User\n");
  612. /* Allocate DPI */
  613. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  614. rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_hwfn->p_rdma_info->dpi_map,
  615. &returned_id);
  616. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  617. out_params->dpi = (u16)returned_id;
  618. /* Calculate the corresponding DPI address */
  619. dpi_start_offset = p_hwfn->dpi_start_offset;
  620. out_params->dpi_addr = (u64)((u8 __iomem *)p_hwfn->doorbells +
  621. dpi_start_offset +
  622. ((out_params->dpi) * p_hwfn->dpi_size));
  623. out_params->dpi_phys_addr = p_hwfn->cdev->db_phys_addr +
  624. dpi_start_offset +
  625. ((out_params->dpi) * p_hwfn->dpi_size);
  626. out_params->dpi_size = p_hwfn->dpi_size;
  627. out_params->wid_count = p_hwfn->wid_count;
  628. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Adding user - done, rc = %d\n", rc);
  629. return rc;
  630. }
  631. static struct qed_rdma_port *qed_rdma_query_port(void *rdma_cxt)
  632. {
  633. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  634. struct qed_rdma_port *p_port = p_hwfn->p_rdma_info->port;
  635. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA Query port\n");
  636. /* Link may have changed */
  637. p_port->port_state = p_hwfn->mcp_info->link_output.link_up ?
  638. QED_RDMA_PORT_UP : QED_RDMA_PORT_DOWN;
  639. p_port->link_speed = p_hwfn->mcp_info->link_output.speed;
  640. p_port->max_msg_size = RDMA_MAX_DATA_SIZE_IN_WQE;
  641. return p_port;
  642. }
  643. static struct qed_rdma_device *qed_rdma_query_device(void *rdma_cxt)
  644. {
  645. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  646. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Query device\n");
  647. /* Return struct with device parameters */
  648. return p_hwfn->p_rdma_info->dev;
  649. }
  650. static void qed_rdma_free_tid(void *rdma_cxt, u32 itid)
  651. {
  652. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  653. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", itid);
  654. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  655. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->tid_map, itid);
  656. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  657. }
  658. static void qed_rdma_cnq_prod_update(void *rdma_cxt, u8 qz_offset, u16 prod)
  659. {
  660. struct qed_hwfn *p_hwfn;
  661. u16 qz_num;
  662. u32 addr;
  663. p_hwfn = (struct qed_hwfn *)rdma_cxt;
  664. if (qz_offset > p_hwfn->p_rdma_info->max_queue_zones) {
  665. DP_NOTICE(p_hwfn,
  666. "queue zone offset %d is too large (max is %d)\n",
  667. qz_offset, p_hwfn->p_rdma_info->max_queue_zones);
  668. return;
  669. }
  670. qz_num = p_hwfn->p_rdma_info->queue_zone_base + qz_offset;
  671. addr = GTT_BAR0_MAP_REG_USDM_RAM +
  672. USTORM_COMMON_QUEUE_CONS_OFFSET(qz_num);
  673. REG_WR16(p_hwfn, addr, prod);
  674. /* keep prod updates ordered */
  675. wmb();
  676. }
  677. static int qed_fill_rdma_dev_info(struct qed_dev *cdev,
  678. struct qed_dev_rdma_info *info)
  679. {
  680. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  681. memset(info, 0, sizeof(*info));
  682. info->rdma_type = QED_IS_ROCE_PERSONALITY(p_hwfn) ?
  683. QED_RDMA_TYPE_ROCE : QED_RDMA_TYPE_IWARP;
  684. info->user_dpm_enabled = (p_hwfn->db_bar_no_edpm == 0);
  685. qed_fill_dev_info(cdev, &info->common);
  686. return 0;
  687. }
  688. static int qed_rdma_get_sb_start(struct qed_dev *cdev)
  689. {
  690. int feat_num;
  691. if (cdev->num_hwfns > 1)
  692. feat_num = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_PF_L2_QUE);
  693. else
  694. feat_num = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_PF_L2_QUE) *
  695. cdev->num_hwfns;
  696. return feat_num;
  697. }
  698. static int qed_rdma_get_min_cnq_msix(struct qed_dev *cdev)
  699. {
  700. int n_cnq = FEAT_NUM(QED_LEADING_HWFN(cdev), QED_RDMA_CNQ);
  701. int n_msix = cdev->int_params.rdma_msix_cnt;
  702. return min_t(int, n_cnq, n_msix);
  703. }
  704. static int qed_rdma_set_int(struct qed_dev *cdev, u16 cnt)
  705. {
  706. int limit = 0;
  707. /* Mark the fastpath as free/used */
  708. cdev->int_params.fp_initialized = cnt ? true : false;
  709. if (cdev->int_params.out.int_mode != QED_INT_MODE_MSIX) {
  710. DP_ERR(cdev,
  711. "qed roce supports only MSI-X interrupts (detected %d).\n",
  712. cdev->int_params.out.int_mode);
  713. return -EINVAL;
  714. } else if (cdev->int_params.fp_msix_cnt) {
  715. limit = cdev->int_params.rdma_msix_cnt;
  716. }
  717. if (!limit)
  718. return -ENOMEM;
  719. return min_t(int, cnt, limit);
  720. }
  721. static int qed_rdma_get_int(struct qed_dev *cdev, struct qed_int_info *info)
  722. {
  723. memset(info, 0, sizeof(*info));
  724. if (!cdev->int_params.fp_initialized) {
  725. DP_INFO(cdev,
  726. "Protocol driver requested interrupt information, but its support is not yet configured\n");
  727. return -EINVAL;
  728. }
  729. if (cdev->int_params.out.int_mode == QED_INT_MODE_MSIX) {
  730. int msix_base = cdev->int_params.rdma_msix_base;
  731. info->msix_cnt = cdev->int_params.rdma_msix_cnt;
  732. info->msix = &cdev->int_params.msix_table[msix_base];
  733. DP_VERBOSE(cdev, QED_MSG_RDMA, "msix_cnt = %d msix_base=%d\n",
  734. info->msix_cnt, msix_base);
  735. }
  736. return 0;
  737. }
  738. static int qed_rdma_alloc_pd(void *rdma_cxt, u16 *pd)
  739. {
  740. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  741. u32 returned_id;
  742. int rc;
  743. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Alloc PD\n");
  744. /* Allocates an unused protection domain */
  745. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  746. rc = qed_rdma_bmap_alloc_id(p_hwfn,
  747. &p_hwfn->p_rdma_info->pd_map, &returned_id);
  748. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  749. *pd = (u16)returned_id;
  750. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Alloc PD - done, rc = %d\n", rc);
  751. return rc;
  752. }
  753. static void qed_rdma_free_pd(void *rdma_cxt, u16 pd)
  754. {
  755. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  756. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "pd = %08x\n", pd);
  757. /* Returns a previously allocated protection domain for reuse */
  758. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  759. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->pd_map, pd);
  760. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  761. }
  762. static enum qed_rdma_toggle_bit
  763. qed_rdma_toggle_bit_create_resize_cq(struct qed_hwfn *p_hwfn, u16 icid)
  764. {
  765. struct qed_rdma_info *p_info = p_hwfn->p_rdma_info;
  766. enum qed_rdma_toggle_bit toggle_bit;
  767. u32 bmap_id;
  768. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", icid);
  769. /* the function toggle the bit that is related to a given icid
  770. * and returns the new toggle bit's value
  771. */
  772. bmap_id = icid - qed_cxt_get_proto_cid_start(p_hwfn, p_info->proto);
  773. spin_lock_bh(&p_info->lock);
  774. toggle_bit = !test_and_change_bit(bmap_id,
  775. p_info->toggle_bits.bitmap);
  776. spin_unlock_bh(&p_info->lock);
  777. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QED_RDMA_TOGGLE_BIT_= %d\n",
  778. toggle_bit);
  779. return toggle_bit;
  780. }
  781. static int qed_rdma_create_cq(void *rdma_cxt,
  782. struct qed_rdma_create_cq_in_params *params,
  783. u16 *icid)
  784. {
  785. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  786. struct qed_rdma_info *p_info = p_hwfn->p_rdma_info;
  787. struct rdma_create_cq_ramrod_data *p_ramrod;
  788. enum qed_rdma_toggle_bit toggle_bit;
  789. struct qed_sp_init_data init_data;
  790. struct qed_spq_entry *p_ent;
  791. u32 returned_id, start_cid;
  792. int rc;
  793. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "cq_handle = %08x%08x\n",
  794. params->cq_handle_hi, params->cq_handle_lo);
  795. /* Allocate icid */
  796. spin_lock_bh(&p_info->lock);
  797. rc = qed_rdma_bmap_alloc_id(p_hwfn, &p_info->cq_map, &returned_id);
  798. spin_unlock_bh(&p_info->lock);
  799. if (rc) {
  800. DP_NOTICE(p_hwfn, "Can't create CQ, rc = %d\n", rc);
  801. return rc;
  802. }
  803. start_cid = qed_cxt_get_proto_cid_start(p_hwfn,
  804. p_info->proto);
  805. *icid = returned_id + start_cid;
  806. /* Check if icid requires a page allocation */
  807. rc = qed_cxt_dynamic_ilt_alloc(p_hwfn, QED_ELEM_CXT, *icid);
  808. if (rc)
  809. goto err;
  810. /* Get SPQ entry */
  811. memset(&init_data, 0, sizeof(init_data));
  812. init_data.cid = *icid;
  813. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  814. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  815. /* Send create CQ ramrod */
  816. rc = qed_sp_init_request(p_hwfn, &p_ent,
  817. RDMA_RAMROD_CREATE_CQ,
  818. p_info->proto, &init_data);
  819. if (rc)
  820. goto err;
  821. p_ramrod = &p_ent->ramrod.rdma_create_cq;
  822. p_ramrod->cq_handle.hi = cpu_to_le32(params->cq_handle_hi);
  823. p_ramrod->cq_handle.lo = cpu_to_le32(params->cq_handle_lo);
  824. p_ramrod->dpi = cpu_to_le16(params->dpi);
  825. p_ramrod->is_two_level_pbl = params->pbl_two_level;
  826. p_ramrod->max_cqes = cpu_to_le32(params->cq_size);
  827. DMA_REGPAIR_LE(p_ramrod->pbl_addr, params->pbl_ptr);
  828. p_ramrod->pbl_num_pages = cpu_to_le16(params->pbl_num_pages);
  829. p_ramrod->cnq_id = (u8)RESC_START(p_hwfn, QED_RDMA_CNQ_RAM) +
  830. params->cnq_id;
  831. p_ramrod->int_timeout = params->int_timeout;
  832. /* toggle the bit for every resize or create cq for a given icid */
  833. toggle_bit = qed_rdma_toggle_bit_create_resize_cq(p_hwfn, *icid);
  834. p_ramrod->toggle_bit = toggle_bit;
  835. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  836. if (rc) {
  837. /* restore toggle bit */
  838. qed_rdma_toggle_bit_create_resize_cq(p_hwfn, *icid);
  839. goto err;
  840. }
  841. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Created CQ, rc = %d\n", rc);
  842. return rc;
  843. err:
  844. /* release allocated icid */
  845. spin_lock_bh(&p_info->lock);
  846. qed_bmap_release_id(p_hwfn, &p_info->cq_map, returned_id);
  847. spin_unlock_bh(&p_info->lock);
  848. DP_NOTICE(p_hwfn, "Create CQ failed, rc = %d\n", rc);
  849. return rc;
  850. }
  851. static int
  852. qed_rdma_destroy_cq(void *rdma_cxt,
  853. struct qed_rdma_destroy_cq_in_params *in_params,
  854. struct qed_rdma_destroy_cq_out_params *out_params)
  855. {
  856. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  857. struct rdma_destroy_cq_output_params *p_ramrod_res;
  858. struct rdma_destroy_cq_ramrod_data *p_ramrod;
  859. struct qed_sp_init_data init_data;
  860. struct qed_spq_entry *p_ent;
  861. dma_addr_t ramrod_res_phys;
  862. enum protocol_type proto;
  863. int rc = -ENOMEM;
  864. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", in_params->icid);
  865. p_ramrod_res =
  866. (struct rdma_destroy_cq_output_params *)
  867. dma_alloc_coherent(&p_hwfn->cdev->pdev->dev,
  868. sizeof(struct rdma_destroy_cq_output_params),
  869. &ramrod_res_phys, GFP_KERNEL);
  870. if (!p_ramrod_res) {
  871. DP_NOTICE(p_hwfn,
  872. "qed destroy cq failed: cannot allocate memory (ramrod)\n");
  873. return rc;
  874. }
  875. /* Get SPQ entry */
  876. memset(&init_data, 0, sizeof(init_data));
  877. init_data.cid = in_params->icid;
  878. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  879. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  880. proto = p_hwfn->p_rdma_info->proto;
  881. /* Send destroy CQ ramrod */
  882. rc = qed_sp_init_request(p_hwfn, &p_ent,
  883. RDMA_RAMROD_DESTROY_CQ,
  884. proto, &init_data);
  885. if (rc)
  886. goto err;
  887. p_ramrod = &p_ent->ramrod.rdma_destroy_cq;
  888. DMA_REGPAIR_LE(p_ramrod->output_params_addr, ramrod_res_phys);
  889. rc = qed_spq_post(p_hwfn, p_ent, NULL);
  890. if (rc)
  891. goto err;
  892. out_params->num_cq_notif = le16_to_cpu(p_ramrod_res->cnq_num);
  893. dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  894. sizeof(struct rdma_destroy_cq_output_params),
  895. p_ramrod_res, ramrod_res_phys);
  896. /* Free icid */
  897. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  898. qed_bmap_release_id(p_hwfn,
  899. &p_hwfn->p_rdma_info->cq_map,
  900. (in_params->icid -
  901. qed_cxt_get_proto_cid_start(p_hwfn, proto)));
  902. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  903. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Destroyed CQ, rc = %d\n", rc);
  904. return rc;
  905. err: dma_free_coherent(&p_hwfn->cdev->pdev->dev,
  906. sizeof(struct rdma_destroy_cq_output_params),
  907. p_ramrod_res, ramrod_res_phys);
  908. return rc;
  909. }
  910. void qed_rdma_set_fw_mac(u16 *p_fw_mac, u8 *p_qed_mac)
  911. {
  912. p_fw_mac[0] = cpu_to_le16((p_qed_mac[0] << 8) + p_qed_mac[1]);
  913. p_fw_mac[1] = cpu_to_le16((p_qed_mac[2] << 8) + p_qed_mac[3]);
  914. p_fw_mac[2] = cpu_to_le16((p_qed_mac[4] << 8) + p_qed_mac[5]);
  915. }
  916. static int qed_rdma_query_qp(void *rdma_cxt,
  917. struct qed_rdma_qp *qp,
  918. struct qed_rdma_query_qp_out_params *out_params)
  919. {
  920. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  921. int rc = 0;
  922. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
  923. /* The following fields are filled in from qp and not FW as they can't
  924. * be modified by FW
  925. */
  926. out_params->mtu = qp->mtu;
  927. out_params->dest_qp = qp->dest_qp;
  928. out_params->incoming_atomic_en = qp->incoming_atomic_en;
  929. out_params->e2e_flow_control_en = qp->e2e_flow_control_en;
  930. out_params->incoming_rdma_read_en = qp->incoming_rdma_read_en;
  931. out_params->incoming_rdma_write_en = qp->incoming_rdma_write_en;
  932. out_params->dgid = qp->dgid;
  933. out_params->flow_label = qp->flow_label;
  934. out_params->hop_limit_ttl = qp->hop_limit_ttl;
  935. out_params->traffic_class_tos = qp->traffic_class_tos;
  936. out_params->timeout = qp->ack_timeout;
  937. out_params->rnr_retry = qp->rnr_retry_cnt;
  938. out_params->retry_cnt = qp->retry_cnt;
  939. out_params->min_rnr_nak_timer = qp->min_rnr_nak_timer;
  940. out_params->pkey_index = 0;
  941. out_params->max_rd_atomic = qp->max_rd_atomic_req;
  942. out_params->max_dest_rd_atomic = qp->max_rd_atomic_resp;
  943. out_params->sqd_async = qp->sqd_async;
  944. if (QED_IS_IWARP_PERSONALITY(p_hwfn))
  945. qed_iwarp_query_qp(qp, out_params);
  946. else
  947. rc = qed_roce_query_qp(p_hwfn, qp, out_params);
  948. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Query QP, rc = %d\n", rc);
  949. return rc;
  950. }
  951. static int qed_rdma_destroy_qp(void *rdma_cxt, struct qed_rdma_qp *qp)
  952. {
  953. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  954. int rc = 0;
  955. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x\n", qp->icid);
  956. if (QED_IS_IWARP_PERSONALITY(p_hwfn))
  957. rc = qed_iwarp_destroy_qp(p_hwfn, qp);
  958. else
  959. rc = qed_roce_destroy_qp(p_hwfn, qp);
  960. /* free qp params struct */
  961. kfree(qp);
  962. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "QP destroyed\n");
  963. return rc;
  964. }
  965. static struct qed_rdma_qp *
  966. qed_rdma_create_qp(void *rdma_cxt,
  967. struct qed_rdma_create_qp_in_params *in_params,
  968. struct qed_rdma_create_qp_out_params *out_params)
  969. {
  970. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  971. struct qed_rdma_qp *qp;
  972. u8 max_stats_queues;
  973. int rc;
  974. if (!rdma_cxt || !in_params || !out_params || !p_hwfn->p_rdma_info) {
  975. DP_ERR(p_hwfn->cdev,
  976. "qed roce create qp failed due to NULL entry (rdma_cxt=%p, in=%p, out=%p, roce_info=?\n",
  977. rdma_cxt, in_params, out_params);
  978. return NULL;
  979. }
  980. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  981. "qed rdma create qp called with qp_handle = %08x%08x\n",
  982. in_params->qp_handle_hi, in_params->qp_handle_lo);
  983. /* Some sanity checks... */
  984. max_stats_queues = p_hwfn->p_rdma_info->dev->max_stats_queues;
  985. if (in_params->stats_queue >= max_stats_queues) {
  986. DP_ERR(p_hwfn->cdev,
  987. "qed rdma create qp failed due to invalid statistics queue %d. maximum is %d\n",
  988. in_params->stats_queue, max_stats_queues);
  989. return NULL;
  990. }
  991. if (QED_IS_IWARP_PERSONALITY(p_hwfn)) {
  992. if (in_params->sq_num_pages * sizeof(struct regpair) >
  993. IWARP_SHARED_QUEUE_PAGE_SQ_PBL_MAX_SIZE) {
  994. DP_NOTICE(p_hwfn->cdev,
  995. "Sq num pages: %d exceeds maximum\n",
  996. in_params->sq_num_pages);
  997. return NULL;
  998. }
  999. if (in_params->rq_num_pages * sizeof(struct regpair) >
  1000. IWARP_SHARED_QUEUE_PAGE_RQ_PBL_MAX_SIZE) {
  1001. DP_NOTICE(p_hwfn->cdev,
  1002. "Rq num pages: %d exceeds maximum\n",
  1003. in_params->rq_num_pages);
  1004. return NULL;
  1005. }
  1006. }
  1007. qp = kzalloc(sizeof(*qp), GFP_KERNEL);
  1008. if (!qp)
  1009. return NULL;
  1010. qp->cur_state = QED_ROCE_QP_STATE_RESET;
  1011. qp->qp_handle.hi = cpu_to_le32(in_params->qp_handle_hi);
  1012. qp->qp_handle.lo = cpu_to_le32(in_params->qp_handle_lo);
  1013. qp->qp_handle_async.hi = cpu_to_le32(in_params->qp_handle_async_hi);
  1014. qp->qp_handle_async.lo = cpu_to_le32(in_params->qp_handle_async_lo);
  1015. qp->use_srq = in_params->use_srq;
  1016. qp->signal_all = in_params->signal_all;
  1017. qp->fmr_and_reserved_lkey = in_params->fmr_and_reserved_lkey;
  1018. qp->pd = in_params->pd;
  1019. qp->dpi = in_params->dpi;
  1020. qp->sq_cq_id = in_params->sq_cq_id;
  1021. qp->sq_num_pages = in_params->sq_num_pages;
  1022. qp->sq_pbl_ptr = in_params->sq_pbl_ptr;
  1023. qp->rq_cq_id = in_params->rq_cq_id;
  1024. qp->rq_num_pages = in_params->rq_num_pages;
  1025. qp->rq_pbl_ptr = in_params->rq_pbl_ptr;
  1026. qp->srq_id = in_params->srq_id;
  1027. qp->req_offloaded = false;
  1028. qp->resp_offloaded = false;
  1029. qp->e2e_flow_control_en = qp->use_srq ? false : true;
  1030. qp->stats_queue = in_params->stats_queue;
  1031. if (QED_IS_IWARP_PERSONALITY(p_hwfn)) {
  1032. rc = qed_iwarp_create_qp(p_hwfn, qp, out_params);
  1033. qp->qpid = qp->icid;
  1034. } else {
  1035. rc = qed_roce_alloc_cid(p_hwfn, &qp->icid);
  1036. qp->qpid = ((0xFF << 16) | qp->icid);
  1037. }
  1038. if (rc) {
  1039. kfree(qp);
  1040. return NULL;
  1041. }
  1042. out_params->icid = qp->icid;
  1043. out_params->qp_id = qp->qpid;
  1044. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Create QP, rc = %d\n", rc);
  1045. return qp;
  1046. }
  1047. static int qed_rdma_modify_qp(void *rdma_cxt,
  1048. struct qed_rdma_qp *qp,
  1049. struct qed_rdma_modify_qp_in_params *params)
  1050. {
  1051. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  1052. enum qed_roce_qp_state prev_state;
  1053. int rc = 0;
  1054. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "icid = %08x params->new_state=%d\n",
  1055. qp->icid, params->new_state);
  1056. if (rc) {
  1057. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  1058. return rc;
  1059. }
  1060. if (GET_FIELD(params->modify_flags,
  1061. QED_RDMA_MODIFY_QP_VALID_RDMA_OPS_EN)) {
  1062. qp->incoming_rdma_read_en = params->incoming_rdma_read_en;
  1063. qp->incoming_rdma_write_en = params->incoming_rdma_write_en;
  1064. qp->incoming_atomic_en = params->incoming_atomic_en;
  1065. }
  1066. /* Update QP structure with the updated values */
  1067. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_ROCE_MODE))
  1068. qp->roce_mode = params->roce_mode;
  1069. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_PKEY))
  1070. qp->pkey = params->pkey;
  1071. if (GET_FIELD(params->modify_flags,
  1072. QED_ROCE_MODIFY_QP_VALID_E2E_FLOW_CONTROL_EN))
  1073. qp->e2e_flow_control_en = params->e2e_flow_control_en;
  1074. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_DEST_QP))
  1075. qp->dest_qp = params->dest_qp;
  1076. if (GET_FIELD(params->modify_flags,
  1077. QED_ROCE_MODIFY_QP_VALID_ADDRESS_VECTOR)) {
  1078. /* Indicates that the following parameters have changed:
  1079. * Traffic class, flow label, hop limit, source GID,
  1080. * destination GID, loopback indicator
  1081. */
  1082. qp->traffic_class_tos = params->traffic_class_tos;
  1083. qp->flow_label = params->flow_label;
  1084. qp->hop_limit_ttl = params->hop_limit_ttl;
  1085. qp->sgid = params->sgid;
  1086. qp->dgid = params->dgid;
  1087. qp->udp_src_port = 0;
  1088. qp->vlan_id = params->vlan_id;
  1089. qp->mtu = params->mtu;
  1090. qp->lb_indication = params->lb_indication;
  1091. memcpy((u8 *)&qp->remote_mac_addr[0],
  1092. (u8 *)&params->remote_mac_addr[0], ETH_ALEN);
  1093. if (params->use_local_mac) {
  1094. memcpy((u8 *)&qp->local_mac_addr[0],
  1095. (u8 *)&params->local_mac_addr[0], ETH_ALEN);
  1096. } else {
  1097. memcpy((u8 *)&qp->local_mac_addr[0],
  1098. (u8 *)&p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
  1099. }
  1100. }
  1101. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_RQ_PSN))
  1102. qp->rq_psn = params->rq_psn;
  1103. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_SQ_PSN))
  1104. qp->sq_psn = params->sq_psn;
  1105. if (GET_FIELD(params->modify_flags,
  1106. QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_REQ))
  1107. qp->max_rd_atomic_req = params->max_rd_atomic_req;
  1108. if (GET_FIELD(params->modify_flags,
  1109. QED_RDMA_MODIFY_QP_VALID_MAX_RD_ATOMIC_RESP))
  1110. qp->max_rd_atomic_resp = params->max_rd_atomic_resp;
  1111. if (GET_FIELD(params->modify_flags,
  1112. QED_ROCE_MODIFY_QP_VALID_ACK_TIMEOUT))
  1113. qp->ack_timeout = params->ack_timeout;
  1114. if (GET_FIELD(params->modify_flags, QED_ROCE_MODIFY_QP_VALID_RETRY_CNT))
  1115. qp->retry_cnt = params->retry_cnt;
  1116. if (GET_FIELD(params->modify_flags,
  1117. QED_ROCE_MODIFY_QP_VALID_RNR_RETRY_CNT))
  1118. qp->rnr_retry_cnt = params->rnr_retry_cnt;
  1119. if (GET_FIELD(params->modify_flags,
  1120. QED_ROCE_MODIFY_QP_VALID_MIN_RNR_NAK_TIMER))
  1121. qp->min_rnr_nak_timer = params->min_rnr_nak_timer;
  1122. qp->sqd_async = params->sqd_async;
  1123. prev_state = qp->cur_state;
  1124. if (GET_FIELD(params->modify_flags,
  1125. QED_RDMA_MODIFY_QP_VALID_NEW_STATE)) {
  1126. qp->cur_state = params->new_state;
  1127. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "qp->cur_state=%d\n",
  1128. qp->cur_state);
  1129. }
  1130. if (QED_IS_IWARP_PERSONALITY(p_hwfn)) {
  1131. enum qed_iwarp_qp_state new_state =
  1132. qed_roce2iwarp_state(qp->cur_state);
  1133. rc = qed_iwarp_modify_qp(p_hwfn, qp, new_state, 0);
  1134. } else {
  1135. rc = qed_roce_modify_qp(p_hwfn, qp, prev_state, params);
  1136. }
  1137. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Modify QP, rc = %d\n", rc);
  1138. return rc;
  1139. }
  1140. static int
  1141. qed_rdma_register_tid(void *rdma_cxt,
  1142. struct qed_rdma_register_tid_in_params *params)
  1143. {
  1144. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  1145. struct rdma_register_tid_ramrod_data *p_ramrod;
  1146. struct qed_sp_init_data init_data;
  1147. struct qed_spq_entry *p_ent;
  1148. enum rdma_tid_type tid_type;
  1149. u8 fw_return_code;
  1150. int rc;
  1151. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", params->itid);
  1152. /* Get SPQ entry */
  1153. memset(&init_data, 0, sizeof(init_data));
  1154. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1155. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1156. rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_REGISTER_MR,
  1157. p_hwfn->p_rdma_info->proto, &init_data);
  1158. if (rc) {
  1159. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  1160. return rc;
  1161. }
  1162. if (p_hwfn->p_rdma_info->last_tid < params->itid)
  1163. p_hwfn->p_rdma_info->last_tid = params->itid;
  1164. p_ramrod = &p_ent->ramrod.rdma_register_tid;
  1165. p_ramrod->flags = 0;
  1166. SET_FIELD(p_ramrod->flags,
  1167. RDMA_REGISTER_TID_RAMROD_DATA_TWO_LEVEL_PBL,
  1168. params->pbl_two_level);
  1169. SET_FIELD(p_ramrod->flags,
  1170. RDMA_REGISTER_TID_RAMROD_DATA_ZERO_BASED, params->zbva);
  1171. SET_FIELD(p_ramrod->flags,
  1172. RDMA_REGISTER_TID_RAMROD_DATA_PHY_MR, params->phy_mr);
  1173. /* Don't initialize D/C field, as it may override other bits. */
  1174. if (!(params->tid_type == QED_RDMA_TID_FMR) && !(params->dma_mr))
  1175. SET_FIELD(p_ramrod->flags,
  1176. RDMA_REGISTER_TID_RAMROD_DATA_PAGE_SIZE_LOG,
  1177. params->page_size_log - 12);
  1178. SET_FIELD(p_ramrod->flags,
  1179. RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_READ,
  1180. params->remote_read);
  1181. SET_FIELD(p_ramrod->flags,
  1182. RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_WRITE,
  1183. params->remote_write);
  1184. SET_FIELD(p_ramrod->flags,
  1185. RDMA_REGISTER_TID_RAMROD_DATA_REMOTE_ATOMIC,
  1186. params->remote_atomic);
  1187. SET_FIELD(p_ramrod->flags,
  1188. RDMA_REGISTER_TID_RAMROD_DATA_LOCAL_WRITE,
  1189. params->local_write);
  1190. SET_FIELD(p_ramrod->flags,
  1191. RDMA_REGISTER_TID_RAMROD_DATA_LOCAL_READ, params->local_read);
  1192. SET_FIELD(p_ramrod->flags,
  1193. RDMA_REGISTER_TID_RAMROD_DATA_ENABLE_MW_BIND,
  1194. params->mw_bind);
  1195. SET_FIELD(p_ramrod->flags1,
  1196. RDMA_REGISTER_TID_RAMROD_DATA_PBL_PAGE_SIZE_LOG,
  1197. params->pbl_page_size_log - 12);
  1198. SET_FIELD(p_ramrod->flags2,
  1199. RDMA_REGISTER_TID_RAMROD_DATA_DMA_MR, params->dma_mr);
  1200. switch (params->tid_type) {
  1201. case QED_RDMA_TID_REGISTERED_MR:
  1202. tid_type = RDMA_TID_REGISTERED_MR;
  1203. break;
  1204. case QED_RDMA_TID_FMR:
  1205. tid_type = RDMA_TID_FMR;
  1206. break;
  1207. case QED_RDMA_TID_MW_TYPE1:
  1208. tid_type = RDMA_TID_MW_TYPE1;
  1209. break;
  1210. case QED_RDMA_TID_MW_TYPE2A:
  1211. tid_type = RDMA_TID_MW_TYPE2A;
  1212. break;
  1213. default:
  1214. rc = -EINVAL;
  1215. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  1216. return rc;
  1217. }
  1218. SET_FIELD(p_ramrod->flags1,
  1219. RDMA_REGISTER_TID_RAMROD_DATA_TID_TYPE, tid_type);
  1220. p_ramrod->itid = cpu_to_le32(params->itid);
  1221. p_ramrod->key = params->key;
  1222. p_ramrod->pd = cpu_to_le16(params->pd);
  1223. p_ramrod->length_hi = (u8)(params->length >> 32);
  1224. p_ramrod->length_lo = DMA_LO_LE(params->length);
  1225. if (params->zbva) {
  1226. /* Lower 32 bits of the registered MR address.
  1227. * In case of zero based MR, will hold FBO
  1228. */
  1229. p_ramrod->va.hi = 0;
  1230. p_ramrod->va.lo = cpu_to_le32(params->fbo);
  1231. } else {
  1232. DMA_REGPAIR_LE(p_ramrod->va, params->vaddr);
  1233. }
  1234. DMA_REGPAIR_LE(p_ramrod->pbl_base, params->pbl_ptr);
  1235. /* DIF */
  1236. if (params->dif_enabled) {
  1237. SET_FIELD(p_ramrod->flags2,
  1238. RDMA_REGISTER_TID_RAMROD_DATA_DIF_ON_HOST_FLG, 1);
  1239. DMA_REGPAIR_LE(p_ramrod->dif_error_addr,
  1240. params->dif_error_addr);
  1241. DMA_REGPAIR_LE(p_ramrod->dif_runt_addr, params->dif_runt_addr);
  1242. }
  1243. rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code);
  1244. if (rc)
  1245. return rc;
  1246. if (fw_return_code != RDMA_RETURN_OK) {
  1247. DP_NOTICE(p_hwfn, "fw_return_code = %d\n", fw_return_code);
  1248. return -EINVAL;
  1249. }
  1250. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "Register TID, rc = %d\n", rc);
  1251. return rc;
  1252. }
  1253. static int qed_rdma_deregister_tid(void *rdma_cxt, u32 itid)
  1254. {
  1255. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  1256. struct rdma_deregister_tid_ramrod_data *p_ramrod;
  1257. struct qed_sp_init_data init_data;
  1258. struct qed_spq_entry *p_ent;
  1259. struct qed_ptt *p_ptt;
  1260. u8 fw_return_code;
  1261. int rc;
  1262. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "itid = %08x\n", itid);
  1263. /* Get SPQ entry */
  1264. memset(&init_data, 0, sizeof(init_data));
  1265. init_data.opaque_fid = p_hwfn->hw_info.opaque_fid;
  1266. init_data.comp_mode = QED_SPQ_MODE_EBLOCK;
  1267. rc = qed_sp_init_request(p_hwfn, &p_ent, RDMA_RAMROD_DEREGISTER_MR,
  1268. p_hwfn->p_rdma_info->proto, &init_data);
  1269. if (rc) {
  1270. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  1271. return rc;
  1272. }
  1273. p_ramrod = &p_ent->ramrod.rdma_deregister_tid;
  1274. p_ramrod->itid = cpu_to_le32(itid);
  1275. rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code);
  1276. if (rc) {
  1277. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "rc = %d\n", rc);
  1278. return rc;
  1279. }
  1280. if (fw_return_code == RDMA_RETURN_DEREGISTER_MR_BAD_STATE_ERR) {
  1281. DP_NOTICE(p_hwfn, "fw_return_code = %d\n", fw_return_code);
  1282. return -EINVAL;
  1283. } else if (fw_return_code == RDMA_RETURN_NIG_DRAIN_REQ) {
  1284. /* Bit indicating that the TID is in use and a nig drain is
  1285. * required before sending the ramrod again
  1286. */
  1287. p_ptt = qed_ptt_acquire(p_hwfn);
  1288. if (!p_ptt) {
  1289. rc = -EBUSY;
  1290. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1291. "Failed to acquire PTT\n");
  1292. return rc;
  1293. }
  1294. rc = qed_mcp_drain(p_hwfn, p_ptt);
  1295. if (rc) {
  1296. qed_ptt_release(p_hwfn, p_ptt);
  1297. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1298. "Drain failed\n");
  1299. return rc;
  1300. }
  1301. qed_ptt_release(p_hwfn, p_ptt);
  1302. /* Resend the ramrod */
  1303. rc = qed_sp_init_request(p_hwfn, &p_ent,
  1304. RDMA_RAMROD_DEREGISTER_MR,
  1305. p_hwfn->p_rdma_info->proto,
  1306. &init_data);
  1307. if (rc) {
  1308. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1309. "Failed to init sp-element\n");
  1310. return rc;
  1311. }
  1312. rc = qed_spq_post(p_hwfn, p_ent, &fw_return_code);
  1313. if (rc) {
  1314. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1315. "Ramrod failed\n");
  1316. return rc;
  1317. }
  1318. if (fw_return_code != RDMA_RETURN_OK) {
  1319. DP_NOTICE(p_hwfn, "fw_return_code = %d\n",
  1320. fw_return_code);
  1321. return rc;
  1322. }
  1323. }
  1324. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "De-registered TID, rc = %d\n", rc);
  1325. return rc;
  1326. }
  1327. static void *qed_rdma_get_rdma_ctx(struct qed_dev *cdev)
  1328. {
  1329. return QED_LEADING_HWFN(cdev);
  1330. }
  1331. bool qed_rdma_allocated_qps(struct qed_hwfn *p_hwfn)
  1332. {
  1333. bool result;
  1334. /* if rdma info has not been allocated, naturally there are no qps */
  1335. if (!p_hwfn->p_rdma_info)
  1336. return false;
  1337. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  1338. if (!p_hwfn->p_rdma_info->cid_map.bitmap)
  1339. result = false;
  1340. else
  1341. result = !qed_bmap_is_empty(&p_hwfn->p_rdma_info->cid_map);
  1342. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  1343. return result;
  1344. }
  1345. void qed_rdma_dpm_conf(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1346. {
  1347. u32 val;
  1348. val = (p_hwfn->dcbx_no_edpm || p_hwfn->db_bar_no_edpm) ? 0 : 1;
  1349. qed_wr(p_hwfn, p_ptt, DORQ_REG_PF_DPM_ENABLE, val);
  1350. DP_VERBOSE(p_hwfn, (QED_MSG_DCB | QED_MSG_RDMA),
  1351. "Changing DPM_EN state to %d (DCBX=%d, DB_BAR=%d)\n",
  1352. val, p_hwfn->dcbx_no_edpm, p_hwfn->db_bar_no_edpm);
  1353. }
  1354. void qed_rdma_dpm_bar(struct qed_hwfn *p_hwfn, struct qed_ptt *p_ptt)
  1355. {
  1356. p_hwfn->db_bar_no_edpm = true;
  1357. qed_rdma_dpm_conf(p_hwfn, p_ptt);
  1358. }
  1359. static int qed_rdma_start(void *rdma_cxt,
  1360. struct qed_rdma_start_in_params *params)
  1361. {
  1362. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  1363. struct qed_ptt *p_ptt;
  1364. int rc = -EBUSY;
  1365. DP_VERBOSE(p_hwfn, QED_MSG_RDMA,
  1366. "desired_cnq = %08x\n", params->desired_cnq);
  1367. p_ptt = qed_ptt_acquire(p_hwfn);
  1368. if (!p_ptt)
  1369. goto err;
  1370. rc = qed_rdma_alloc(p_hwfn, p_ptt, params);
  1371. if (rc)
  1372. goto err1;
  1373. rc = qed_rdma_setup(p_hwfn, p_ptt, params);
  1374. if (rc)
  1375. goto err2;
  1376. qed_ptt_release(p_hwfn, p_ptt);
  1377. return rc;
  1378. err2:
  1379. qed_rdma_free(p_hwfn);
  1380. err1:
  1381. qed_ptt_release(p_hwfn, p_ptt);
  1382. err:
  1383. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "RDMA start - error, rc = %d\n", rc);
  1384. return rc;
  1385. }
  1386. static int qed_rdma_init(struct qed_dev *cdev,
  1387. struct qed_rdma_start_in_params *params)
  1388. {
  1389. return qed_rdma_start(QED_LEADING_HWFN(cdev), params);
  1390. }
  1391. static void qed_rdma_remove_user(void *rdma_cxt, u16 dpi)
  1392. {
  1393. struct qed_hwfn *p_hwfn = (struct qed_hwfn *)rdma_cxt;
  1394. DP_VERBOSE(p_hwfn, QED_MSG_RDMA, "dpi = %08x\n", dpi);
  1395. spin_lock_bh(&p_hwfn->p_rdma_info->lock);
  1396. qed_bmap_release_id(p_hwfn, &p_hwfn->p_rdma_info->dpi_map, dpi);
  1397. spin_unlock_bh(&p_hwfn->p_rdma_info->lock);
  1398. }
  1399. static int qed_roce_ll2_set_mac_filter(struct qed_dev *cdev,
  1400. u8 *old_mac_address,
  1401. u8 *new_mac_address)
  1402. {
  1403. struct qed_hwfn *p_hwfn = QED_LEADING_HWFN(cdev);
  1404. struct qed_ptt *p_ptt;
  1405. int rc = 0;
  1406. p_ptt = qed_ptt_acquire(p_hwfn);
  1407. if (!p_ptt) {
  1408. DP_ERR(cdev,
  1409. "qed roce ll2 mac filter set: failed to acquire PTT\n");
  1410. return -EINVAL;
  1411. }
  1412. if (old_mac_address)
  1413. qed_llh_remove_mac_filter(p_hwfn, p_ptt, old_mac_address);
  1414. if (new_mac_address)
  1415. rc = qed_llh_add_mac_filter(p_hwfn, p_ptt, new_mac_address);
  1416. qed_ptt_release(p_hwfn, p_ptt);
  1417. if (rc)
  1418. DP_ERR(cdev,
  1419. "qed roce ll2 mac filter set: failed to add MAC filter\n");
  1420. return rc;
  1421. }
  1422. static const struct qed_rdma_ops qed_rdma_ops_pass = {
  1423. .common = &qed_common_ops_pass,
  1424. .fill_dev_info = &qed_fill_rdma_dev_info,
  1425. .rdma_get_rdma_ctx = &qed_rdma_get_rdma_ctx,
  1426. .rdma_init = &qed_rdma_init,
  1427. .rdma_add_user = &qed_rdma_add_user,
  1428. .rdma_remove_user = &qed_rdma_remove_user,
  1429. .rdma_stop = &qed_rdma_stop,
  1430. .rdma_query_port = &qed_rdma_query_port,
  1431. .rdma_query_device = &qed_rdma_query_device,
  1432. .rdma_get_start_sb = &qed_rdma_get_sb_start,
  1433. .rdma_get_rdma_int = &qed_rdma_get_int,
  1434. .rdma_set_rdma_int = &qed_rdma_set_int,
  1435. .rdma_get_min_cnq_msix = &qed_rdma_get_min_cnq_msix,
  1436. .rdma_cnq_prod_update = &qed_rdma_cnq_prod_update,
  1437. .rdma_alloc_pd = &qed_rdma_alloc_pd,
  1438. .rdma_dealloc_pd = &qed_rdma_free_pd,
  1439. .rdma_create_cq = &qed_rdma_create_cq,
  1440. .rdma_destroy_cq = &qed_rdma_destroy_cq,
  1441. .rdma_create_qp = &qed_rdma_create_qp,
  1442. .rdma_modify_qp = &qed_rdma_modify_qp,
  1443. .rdma_query_qp = &qed_rdma_query_qp,
  1444. .rdma_destroy_qp = &qed_rdma_destroy_qp,
  1445. .rdma_alloc_tid = &qed_rdma_alloc_tid,
  1446. .rdma_free_tid = &qed_rdma_free_tid,
  1447. .rdma_register_tid = &qed_rdma_register_tid,
  1448. .rdma_deregister_tid = &qed_rdma_deregister_tid,
  1449. .ll2_acquire_connection = &qed_ll2_acquire_connection,
  1450. .ll2_establish_connection = &qed_ll2_establish_connection,
  1451. .ll2_terminate_connection = &qed_ll2_terminate_connection,
  1452. .ll2_release_connection = &qed_ll2_release_connection,
  1453. .ll2_post_rx_buffer = &qed_ll2_post_rx_buffer,
  1454. .ll2_prepare_tx_packet = &qed_ll2_prepare_tx_packet,
  1455. .ll2_set_fragment_of_tx_packet = &qed_ll2_set_fragment_of_tx_packet,
  1456. .ll2_set_mac_filter = &qed_roce_ll2_set_mac_filter,
  1457. .ll2_get_stats = &qed_ll2_get_stats,
  1458. .iwarp_connect = &qed_iwarp_connect,
  1459. .iwarp_create_listen = &qed_iwarp_create_listen,
  1460. .iwarp_destroy_listen = &qed_iwarp_destroy_listen,
  1461. .iwarp_accept = &qed_iwarp_accept,
  1462. .iwarp_reject = &qed_iwarp_reject,
  1463. .iwarp_send_rtr = &qed_iwarp_send_rtr,
  1464. };
  1465. const struct qed_rdma_ops *qed_get_rdma_ops(void)
  1466. {
  1467. return &qed_rdma_ops_pass;
  1468. }
  1469. EXPORT_SYMBOL(qed_get_rdma_ops);